Mercurial > pidgin
annotate finch/libgnt/gntwindow.c @ 21283:406aa3be6b32
Minor adjustments to prevent a crash, correct a data type and fix drawing.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 10 Nov 2007 01:18:15 +0000 |
parents | b65f1bff6412 |
children | d78e440584e0 |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18069
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
22 |
15817 | 23 #include "gntstyle.h" |
24 #include "gntwindow.h" | |
25 | |
26 #include <string.h> | |
27 | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
28 struct _GntWindowPriv |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
29 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
30 GHashTable *accels; /* key => menuitem-id */ |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
31 }; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
32 |
15817 | 33 enum |
34 { | |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
35 SIG_WORKSPACE_HIDE, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
36 SIG_WORKSPACE_SHOW, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
37 SIGS, |
15817 | 38 }; |
39 | |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
40 static guint signals[SIGS] = { 0 }; |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
41 |
15817 | 42 static GntBoxClass *parent_class = NULL; |
43 | |
44 static void (*org_destroy)(GntWidget *widget); | |
45 | |
46 static gboolean | |
47 show_menu(GntBindable *bind, GList *null) | |
48 { | |
49 GntWindow *win = GNT_WINDOW(bind); | |
50 if (win->menu) { | |
51 gnt_screen_menu_show(win->menu); | |
52 return TRUE; | |
53 } | |
54 return FALSE; | |
55 } | |
56 | |
57 static void | |
58 gnt_window_destroy(GntWidget *widget) | |
59 { | |
60 GntWindow *window = GNT_WINDOW(widget); | |
61 if (window->menu) | |
62 gnt_widget_destroy(GNT_WIDGET(window->menu)); | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
63 if (window->priv) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
64 g_hash_table_destroy(window->priv->accels); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
65 g_free(window->priv); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
66 } |
15817 | 67 org_destroy(widget); |
68 } | |
69 | |
70 static void | |
71 gnt_window_class_init(GntWindowClass *klass) | |
72 { | |
73 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); | |
74 GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass); | |
75 parent_class = GNT_BOX_CLASS(klass); | |
76 | |
77 org_destroy = wid_class->destroy; | |
78 wid_class->destroy = gnt_window_destroy; | |
79 | |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
80 signals[SIG_WORKSPACE_HIDE] = |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
81 g_signal_new("workspace-hidden", |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
82 G_TYPE_FROM_CLASS(klass), |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
83 G_SIGNAL_RUN_LAST, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
84 0, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
85 NULL, NULL, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
86 g_cclosure_marshal_VOID__VOID, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
87 G_TYPE_NONE, 0); |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
88 |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
89 signals[SIG_WORKSPACE_SHOW] = |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
90 g_signal_new("workspace-shown", |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
91 G_TYPE_FROM_CLASS(klass), |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
92 G_SIGNAL_RUN_LAST, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
93 0, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
94 NULL, NULL, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
95 g_cclosure_marshal_VOID__VOID, |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
96 G_TYPE_NONE, 0); |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
97 |
15817 | 98 gnt_bindable_class_register_action(bindable, "show-menu", show_menu, |
99 GNT_KEY_CTRL_O, NULL); | |
100 gnt_bindable_register_binding(bindable, "show-menu", GNT_KEY_F10, NULL); | |
101 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); | |
102 | |
103 GNTDEBUG; | |
104 } | |
105 | |
106 static void | |
107 gnt_window_init(GTypeInstance *instance, gpointer class) | |
108 { | |
109 GntWidget *widget = GNT_WIDGET(instance); | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
110 GntWindow *win = GNT_WINDOW(widget); |
15817 | 111 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); |
112 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
113 win->priv = g_new0(GntWindowPriv, 1); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
114 win->priv->accels = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
15817 | 115 GNTDEBUG; |
116 } | |
117 | |
118 /****************************************************************************** | |
119 * GntWindow API | |
120 *****************************************************************************/ | |
121 GType | |
122 gnt_window_get_gtype(void) | |
123 { | |
124 static GType type = 0; | |
125 | |
126 if(type == 0) | |
127 { | |
128 static const GTypeInfo info = { | |
129 sizeof(GntWindowClass), | |
130 NULL, /* base_init */ | |
131 NULL, /* base_finalize */ | |
132 (GClassInitFunc)gnt_window_class_init, | |
133 NULL, /* class_finalize */ | |
134 NULL, /* class_data */ | |
135 sizeof(GntWindow), | |
136 0, /* n_preallocs */ | |
137 gnt_window_init, /* instance_init */ | |
138 NULL /* value_table */ | |
139 }; | |
140 | |
141 type = g_type_register_static(GNT_TYPE_BOX, | |
142 "GntWindow", | |
143 &info, 0); | |
144 } | |
145 | |
146 return type; | |
147 } | |
148 | |
149 GntWidget *gnt_window_new() | |
150 { | |
151 GntWidget *widget = g_object_new(GNT_TYPE_WINDOW, NULL); | |
152 | |
153 return widget; | |
154 } | |
155 | |
156 GntWidget *gnt_window_box_new(gboolean homo, gboolean vert) | |
157 { | |
158 GntWidget *wid = gnt_window_new(); | |
159 GntBox *box = GNT_BOX(wid); | |
160 | |
161 box->homogeneous = homo; | |
162 box->vertical = vert; | |
163 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; | |
164 | |
165 return wid; | |
166 } | |
167 | |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
168 void |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
169 gnt_window_workspace_hiding(GntWindow *window) |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
170 { |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
171 if (window->menu) |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
172 gnt_widget_hide(GNT_WIDGET(window->menu)); |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
173 g_signal_emit(window, signals[SIG_WORKSPACE_HIDE], 0); |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
174 } |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
175 |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
176 void |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
177 gnt_window_workspace_showing(GntWindow *window) |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
178 { |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
179 g_signal_emit(window, signals[SIG_WORKSPACE_SHOW], 0); |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
180 } |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15817
diff
changeset
|
181 |
15817 | 182 void gnt_window_set_menu(GntWindow *window, GntMenu *menu) |
183 { | |
184 /* If a menu already existed, then destroy that first. */ | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
185 const char *name = gnt_widget_get_name(GNT_WIDGET(window)); |
15817 | 186 if (window->menu) |
187 gnt_widget_destroy(GNT_WIDGET(window->menu)); | |
188 window->menu = menu; | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
189 if (name && window->priv) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
190 if (!gnt_style_read_menu_accels(name, window->priv->accels)) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
191 g_hash_table_destroy(window->priv->accels); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
192 g_free(window->priv); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
193 window->priv = NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
194 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
195 } |
15817 | 196 } |
197 | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
198 const char * gnt_window_get_accel_item(GntWindow *window, const char *key) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
199 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
200 if (window->priv) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
201 return g_hash_table_lookup(window->priv->accels, key); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
202 return NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
203 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
204 |