Replace all other lxpanel_image_* calls with new ones to make code simpler.
[lxde/lxpanel.git] / plugins / separator.c
CommitLineData
5d344669 1/**
8c9c4b55 2 * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
5d344669
AL
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
10b7f93c 19#include "plugin.h"
a52c2257 20
239cb032 21#include <glib/gi18n.h>
a52c2257 22
2918994e 23/* Plugin constructor. */
a7bd16a4 24static GtkWidget *separator_constructor(LXPanel *panel, config_setting_t *settings)
a52c2257 25{
10b7f93c 26 GtkWidget *instance, *sep;
9dd114c4 27
2918994e 28 /* Allocate top level widget and set into Plugin widget pointer. */
10b7f93c 29 instance = gtk_event_box_new();
10b7f93c 30 gtk_widget_set_has_window(instance, FALSE);
10b7f93c
AG
31 gtk_widget_add_events(instance, GDK_BUTTON_PRESS_MASK);
32 gtk_container_set_border_width(GTK_CONTAINER(instance), 1);
4542c20d 33
2918994e 34 /* Allocate separator as a child of top level. */
10b7f93c
AG
35 sep = panel_separator_new(panel);
36 gtk_container_add(GTK_CONTAINER(instance), sep);
761af06c 37 gtk_widget_show(sep);
4542c20d 38
2918994e 39 /* Show the widget and return. */
10b7f93c 40 return instance;
a52c2257
HJYP
41}
42
2918994e 43/* Callback when panel configuration changes. */
a7bd16a4 44static void separator_reconfigure(LXPanel *panel, GtkWidget *instance)
a97d06a6 45{
2918994e 46 /* Determine if the orientation changed in a way that requires action. */
10b7f93c 47 GtkWidget * sep = gtk_bin_get_child(GTK_BIN(instance));
2918994e 48 if (GTK_IS_VSEPARATOR(sep))
49 {
cfde283a 50 if (panel_get_orientation(panel) == GTK_ORIENTATION_HORIZONTAL)
a97d06a6
HJYP
51 return;
52 }
2918994e 53 else
54 {
cfde283a 55 if (panel_get_orientation(panel) == GTK_ORIENTATION_VERTICAL)
a97d06a6
HJYP
56 return;
57 }
2918994e 58
59 /* If the orientation changed, recreate the separator. */
60 gtk_widget_destroy(sep);
10b7f93c 61 sep = panel_separator_new(panel);
a97d06a6 62 gtk_widget_show(sep);
10b7f93c 63 gtk_container_add(GTK_CONTAINER(instance), sep);
a97d06a6 64}
a52c2257 65
2918994e 66/* Plugin descriptor. */
10b7f93c 67LXPanelPluginInit lxpanel_static_plugin_separator = {
3c3e9c9e 68 .name = N_("Separator"),
3c3e9c9e
HG
69 .description = N_("Add a separator to the panel"),
70
10b7f93c
AG
71 .new_instance = separator_constructor,
72 .reconfigure = separator_reconfigure
a52c2257 73};