Enabling multithreaded compilation.
[debian/lxpanel.git] / src / plugins / separator.c
1 /**
2 * Copyright (c) 2006 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 "panel.h"
20 #include "misc.h"
21 #include "plugin.h"
22
23 #include <glib/gi18n.h>
24
25 #include "dbg.h"
26
27 static int separator_constructor(Plugin * p, char ** fp);
28 static void separator_destructor(Plugin * p);
29 static void separator_panel_configuration_changed(Plugin * p);
30
31 /* Plugin constructor. */
32 static int separator_constructor(Plugin * p, char ** fp)
33 {
34 /* Load parameters from the configuration file. */
35 line s;
36 s.len = 256;
37 if (fp != NULL)
38 {
39 while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END)
40 {
41 ERR( "separator: illegal in this context %s\n", s.str);
42 return 0;
43 }
44 }
45
46 /* Allocate top level widget and set into Plugin widget pointer. */
47 p->pwid = gtk_event_box_new();
48 #if GTK_CHECK_VERSION(2,18,0)
49 gtk_widget_set_has_window(p->pwid, FALSE);
50 #else
51 GTK_WIDGET_SET_FLAGS(p->pwid, GTK_NO_WINDOW);
52 #endif
53 gtk_widget_add_events(p->pwid, GDK_BUTTON_PRESS_MASK);
54 gtk_container_set_border_width(GTK_CONTAINER(p->pwid), 1);
55
56 /* Allocate separator as a child of top level. */
57 GtkWidget * sep = p->panel->my_separator_new();
58 gtk_container_add(GTK_CONTAINER(p->pwid), sep);
59
60 /* Connect signals. */
61 g_signal_connect(p->pwid, "button-press-event", G_CALLBACK(plugin_button_press_event), p);
62
63 /* Show the widget and return. */
64 gtk_widget_show_all(p->pwid);
65 return 1;
66 }
67
68 /* Plugin destructor. */
69 static void separator_destructor(Plugin * p)
70 {
71 }
72
73 /* Callback when panel configuration changes. */
74 static void separator_panel_configuration_changed(Plugin * p)
75 {
76 /* Determine if the orientation changed in a way that requires action. */
77 GtkWidget * sep = gtk_bin_get_child(GTK_BIN(p->pwid));
78 if (GTK_IS_VSEPARATOR(sep))
79 {
80 if (p->panel->orientation == GTK_ORIENTATION_HORIZONTAL)
81 return;
82 }
83 else
84 {
85 if (p->panel->orientation == GTK_ORIENTATION_VERTICAL)
86 return;
87 }
88
89 /* If the orientation changed, recreate the separator. */
90 gtk_widget_destroy(sep);
91 sep = p->panel->my_separator_new();
92 gtk_widget_show(sep);
93 gtk_container_add(GTK_CONTAINER(p->pwid), sep);
94 }
95
96 /* Plugin descriptor. */
97 PluginClass separator_plugin_class = {
98
99 PLUGINCLASS_VERSIONING,
100
101 type : "separator",
102 name : N_("Separator"),
103 version: "1.0",
104 description : N_("Add a separator to the panel"),
105
106 constructor : separator_constructor,
107 destructor : separator_destructor,
108 config : NULL,
109 save : NULL,
110 panel_configuration_changed : separator_panel_configuration_changed
111 };