Correctly close plugin config window on plugin or panel destroy.
[lxde/lxpanel.git] / src / plugins / separator.c
CommitLineData
5d344669
AL
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
a52c2257
HJYP
19#include "panel.h"
20#include "misc.h"
b31cb1d2 21#include "private.h"
a52c2257 22
239cb032 23#include <glib/gi18n.h>
a52c2257 24
a52c2257
HJYP
25#include "dbg.h"
26
2918994e 27static int separator_constructor(Plugin * p, char ** fp);
28static void separator_destructor(Plugin * p);
29static void separator_panel_configuration_changed(Plugin * p);
30
31/* Plugin constructor. */
32static int separator_constructor(Plugin * p, char ** fp)
a52c2257 33{
2918994e 34 /* Load parameters from the configuration file. */
a52c2257 35 line s;
a52c2257 36 s.len = 256;
2918994e 37 if (fp != NULL)
db449f6e 38 {
2918994e 39 while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END)
40 {
db449f6e 41 ERR( "separator: illegal in this context %s\n", s.str);
2918994e 42 return 0;
db449f6e 43 }
a52c2257 44 }
9dd114c4 45
2918994e 46 /* Allocate top level widget and set into Plugin widget pointer. */
47 p->pwid = gtk_event_box_new();
d5c46ffc
JL
48#if GTK_CHECK_VERSION(2,18,0)
49 gtk_widget_set_has_window(p->pwid, FALSE);
50#else
2918994e 51 GTK_WIDGET_SET_FLAGS(p->pwid, GTK_NO_WINDOW);
d5c46ffc 52#endif
2918994e 53 gtk_widget_add_events(p->pwid, GDK_BUTTON_PRESS_MASK);
54 gtk_container_set_border_width(GTK_CONTAINER(p->pwid), 1);
4542c20d 55
2918994e 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);
4542c20d 59
2918994e 60 /* Connect signals. */
61 g_signal_connect(p->pwid, "button-press-event", G_CALLBACK(plugin_button_press_event), p);
a52c2257 62
2918994e 63 /* Show the widget and return. */
64 gtk_widget_show_all(p->pwid);
9dd114c4 65 return 1;
a52c2257
HJYP
66}
67
2918994e 68/* Plugin destructor. */
69static void separator_destructor(Plugin * p)
a52c2257 70{
a52c2257
HJYP
71}
72
2918994e 73/* Callback when panel configuration changes. */
74static void separator_panel_configuration_changed(Plugin * p)
a97d06a6 75{
2918994e 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)
a97d06a6
HJYP
81 return;
82 }
2918994e 83 else
84 {
85 if (p->panel->orientation == GTK_ORIENTATION_VERTICAL)
a97d06a6
HJYP
86 return;
87 }
2918994e 88
89 /* If the orientation changed, recreate the separator. */
90 gtk_widget_destroy(sep);
a97d06a6
HJYP
91 sep = p->panel->my_separator_new();
92 gtk_widget_show(sep);
2918994e 93 gtk_container_add(GTK_CONTAINER(p->pwid), sep);
a97d06a6 94}
a52c2257 95
2918994e 96/* Plugin descriptor. */
22242ed4 97PluginClass separator_plugin_class = {
a52c2257 98
2918994e 99 PLUGINCLASS_VERSIONING,
100
3c3e9c9e
HG
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
a52c2257 111};