bd220c31e0229b86e35ae6c1e5e47c98224d7f46
[lxde/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 gboolean on_btn_press( GtkWidget* w, GdkEventButton* evt, Plugin* plugin )
28 {
29 if( evt->button == 3 )
30 {
31 GtkMenu* popup = lxpanel_get_panel_menu( plugin->panel, plugin, FALSE );
32 gtk_menu_popup( popup, NULL, NULL, NULL, NULL, evt->button, evt->time );
33 }
34 return TRUE;
35 }
36
37 static int
38 separator_constructor(Plugin *p, char **fp)
39 {
40 GtkWidget *sep, *eb;
41 line s;
42
43 ENTER;
44 s.len = 256;
45 if( fp )
46 {
47 while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) {
48 ERR( "separator: illegal in this context %s\n", s.str);
49 RET(0);
50 }
51 }
52 eb = gtk_event_box_new();
53 GTK_WIDGET_SET_FLAGS( eb, GTK_NO_WINDOW );
54 gtk_widget_add_events( p->pwid, GDK_BUTTON_PRESS_MASK );
55 g_signal_connect( p->pwid, "button-press-event", G_CALLBACK( on_btn_press ), p );
56
57 gtk_container_set_border_width(GTK_CONTAINER(eb), 1);
58 gtk_widget_show(eb);
59
60 sep = p->panel->my_separator_new();
61 gtk_widget_show(sep);
62 gtk_container_add (GTK_CONTAINER (eb), sep);
63 p->priv = eb; /* just to alloc smth */
64
65 p->pwid = eb;
66 RET(1);
67 }
68
69 static void
70 separator_destructor(Plugin *p)
71 {
72 ENTER;
73 /* The widget is destroyed in plugin_stop().
74 GtkWidget* eb = GTK_WIDGET((GtkEventBox*)p->priv);
75 gtk_widget_destroy( eb );
76 */
77 RET();
78 }
79
80 static void orientation_changed( Plugin* p )
81 {
82 GtkWidget* eb = GTK_WIDGET((GtkEventBox*)p->priv);
83 GtkWidget* sep = gtk_bin_get_child( GTK_BIN(eb) );
84 if( GTK_IS_VSEPARATOR(sep) ) {
85 if( p->panel->orientation == GTK_ORIENTATION_HORIZONTAL )
86 return;
87 }
88 else {
89 if( p->panel->orientation == GTK_ORIENTATION_VERTICAL )
90 return;
91 }
92 gtk_widget_destroy( sep );
93 sep = p->panel->my_separator_new();
94 gtk_widget_show(sep);
95 gtk_container_add (GTK_CONTAINER (eb), sep);
96 }
97
98 PluginClass separator_plugin_class = {
99 fname: NULL,
100 count: 0,
101
102 type : "separator",
103 name : N_("Separator"),
104 version: "1.0",
105 description : N_("Add a separator to the panel"),
106
107 constructor : separator_constructor,
108 destructor : separator_destructor,
109 config : NULL,
110 save : NULL,
111 orientation : orientation_changed
112 };