b6ce9b35bf1039db59637b1369a83475cf10029a
[debian/lxpanel.git] / plugins / separator.c
1 /**
2 * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
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
19 #include "plugin.h"
20
21 #include <glib/gi18n.h>
22
23 /* Plugin constructor. */
24 static GtkWidget *separator_constructor(LXPanel *panel, config_setting_t *settings)
25 {
26 GtkWidget *instance, *sep;
27
28 /* Allocate top level widget and set into Plugin widget pointer. */
29 instance = gtk_event_box_new();
30 gtk_widget_set_has_window(instance, FALSE);
31 gtk_widget_add_events(instance, GDK_BUTTON_PRESS_MASK);
32 gtk_container_set_border_width(GTK_CONTAINER(instance), 1);
33
34 /* Allocate separator as a child of top level. */
35 sep = panel_separator_new(panel);
36 gtk_container_add(GTK_CONTAINER(instance), sep);
37 gtk_widget_show(sep);
38
39 /* Show the widget and return. */
40 return instance;
41 }
42
43 /* Callback when panel configuration changes. */
44 static void separator_reconfigure(LXPanel *panel, GtkWidget *instance)
45 {
46 /* Determine if the orientation changed in a way that requires action. */
47 GtkWidget * sep = gtk_bin_get_child(GTK_BIN(instance));
48 if (GTK_IS_VSEPARATOR(sep))
49 {
50 if (panel_get_orientation(panel) == GTK_ORIENTATION_HORIZONTAL)
51 return;
52 }
53 else
54 {
55 if (panel_get_orientation(panel) == GTK_ORIENTATION_VERTICAL)
56 return;
57 }
58
59 /* If the orientation changed, recreate the separator. */
60 gtk_widget_destroy(sep);
61 sep = panel_separator_new(panel);
62 gtk_widget_show(sep);
63 gtk_container_add(GTK_CONTAINER(instance), sep);
64 }
65
66 /* Plugin descriptor. */
67 LXPanelPluginInit lxpanel_static_plugin_separator = {
68 .name = N_("Separator"),
69 .description = N_("Add a separator to the panel"),
70
71 .new_instance = separator_constructor,
72 .reconfigure = separator_reconfigure
73 };