Mercurial > pidgin.yaz
annotate finch/libgnt/gntwidget.c @ 32118:7675022d2312
We should not be installing libpurple/valgrind.h
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Mon, 13 Jun 2011 17:31:03 +0000 |
parents | a8cc50c2279f |
children |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18566
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
22 |
15818 | 23 /* Stuff brutally ripped from Gflib */ |
24 | |
29220
88d889b54df4
Fix building finch & libgnt using older gcc or non-gcc compilers that do
Stu Tomlinson <stu@nosnilmot.com>
parents:
22786
diff
changeset
|
25 #include "gntinternal.h" |
15818 | 26 #include "gntwidget.h" |
27 #include "gntstyle.h" | |
28 #include "gntmarshal.h" | |
29 #include "gntutils.h" | |
30 #include "gnt.h" | |
31 | |
32 enum | |
33 { | |
34 SIG_DESTROY, | |
35 SIG_DRAW, | |
36 SIG_HIDE, | |
37 SIG_GIVE_FOCUS, | |
38 SIG_LOST_FOCUS, | |
39 SIG_KEY_PRESSED, | |
40 SIG_MAP, | |
41 SIG_ACTIVATE, | |
42 SIG_EXPOSE, | |
43 SIG_SIZE_REQUEST, | |
44 SIG_CONFIRM_SIZE, | |
45 SIG_SIZE_CHANGED, | |
46 SIG_POSITION, | |
47 SIG_CLICKED, | |
48 SIG_CONTEXT_MENU, | |
49 SIGS | |
50 }; | |
51 | |
52 static GObjectClass *parent_class = NULL; | |
53 static guint signals[SIGS] = { 0 }; | |
54 | |
55 static void init_widget(GntWidget *widget); | |
56 | |
57 static void | |
58 gnt_widget_init(GTypeInstance *instance, gpointer class) | |
59 { | |
60 GntWidget *widget = GNT_WIDGET(instance); | |
61 widget->priv.name = NULL; | |
62 GNTDEBUG; | |
63 } | |
64 | |
65 static void | |
66 gnt_widget_map(GntWidget *widget) | |
67 { | |
68 /* Get some default size for the widget */ | |
69 GNTDEBUG; | |
70 g_signal_emit(widget, signals[SIG_MAP], 0); | |
71 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_MAPPED); | |
72 } | |
73 | |
74 static void | |
75 gnt_widget_dispose(GObject *obj) | |
76 { | |
77 GntWidget *self = GNT_WIDGET(obj); | |
18565
980d6e1b2d21
Fix a crash Eric found. These parameters were in reverse order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
78 g_signal_emit(self, signals[SIG_DESTROY], 0); |
15818 | 79 parent_class->dispose(obj); |
80 GNTDEBUG; | |
81 } | |
82 | |
83 static void | |
84 gnt_widget_focus_change(GntWidget *widget) | |
85 { | |
86 if (GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_MAPPED) | |
87 gnt_widget_draw(widget); | |
88 } | |
89 | |
90 static gboolean | |
91 gnt_widget_dummy_confirm_size(GntWidget *widget, int width, int height) | |
92 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
93 gboolean shadow; |
15818 | 94 if (width < widget->priv.minw || height < widget->priv.minh) |
95 return FALSE; | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
96 shadow = gnt_widget_has_shadow(widget); |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
97 if (widget->priv.width + shadow != width && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_X)) |
15818 | 98 return FALSE; |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
99 if (widget->priv.height + shadow != height && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_Y)) |
15818 | 100 return FALSE; |
101 return TRUE; | |
102 } | |
103 | |
104 static gboolean | |
105 context_menu(GntBindable *bind, GList *null) | |
106 { | |
107 gboolean ret = FALSE; | |
108 g_signal_emit(bind, signals[SIG_CONTEXT_MENU], 0, &ret); | |
109 return ret; | |
110 } | |
111 | |
112 static void | |
113 gnt_widget_class_init(GntWidgetClass *klass) | |
114 { | |
115 GObjectClass *obj_class = G_OBJECT_CLASS(klass); | |
116 | |
117 parent_class = g_type_class_peek_parent(klass); | |
118 | |
119 obj_class->dispose = gnt_widget_dispose; | |
120 | |
121 klass->destroy = gnt_widget_destroy; | |
122 klass->show = gnt_widget_show; | |
123 klass->draw = gnt_widget_draw; | |
124 klass->expose = gnt_widget_expose; | |
125 klass->map = gnt_widget_map; | |
126 klass->lost_focus = gnt_widget_focus_change; | |
127 klass->gained_focus = gnt_widget_focus_change; | |
128 klass->confirm_size = gnt_widget_dummy_confirm_size; | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
129 |
15818 | 130 klass->key_pressed = NULL; |
131 klass->activate = NULL; | |
132 klass->clicked = NULL; | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
133 |
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
134 signals[SIG_DESTROY] = |
15818 | 135 g_signal_new("destroy", |
136 G_TYPE_FROM_CLASS(klass), | |
137 G_SIGNAL_RUN_LAST, | |
138 G_STRUCT_OFFSET(GntWidgetClass, destroy), | |
139 NULL, NULL, | |
140 g_cclosure_marshal_VOID__VOID, | |
141 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
142 signals[SIG_GIVE_FOCUS] = |
15818 | 143 g_signal_new("gained-focus", |
144 G_TYPE_FROM_CLASS(klass), | |
145 G_SIGNAL_RUN_LAST, | |
146 G_STRUCT_OFFSET(GntWidgetClass, gained_focus), | |
147 NULL, NULL, | |
148 g_cclosure_marshal_VOID__VOID, | |
149 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
150 signals[SIG_LOST_FOCUS] = |
15818 | 151 g_signal_new("lost-focus", |
152 G_TYPE_FROM_CLASS(klass), | |
153 G_SIGNAL_RUN_LAST, | |
154 G_STRUCT_OFFSET(GntWidgetClass, lost_focus), | |
155 NULL, NULL, | |
156 g_cclosure_marshal_VOID__VOID, | |
157 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
158 signals[SIG_ACTIVATE] = |
15818 | 159 g_signal_new("activate", |
160 G_TYPE_FROM_CLASS(klass), | |
161 G_SIGNAL_RUN_LAST, | |
162 G_STRUCT_OFFSET(GntWidgetClass, activate), | |
163 NULL, NULL, | |
164 g_cclosure_marshal_VOID__VOID, | |
165 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
166 signals[SIG_MAP] = |
15818 | 167 g_signal_new("map", |
168 G_TYPE_FROM_CLASS(klass), | |
169 G_SIGNAL_RUN_LAST, | |
170 G_STRUCT_OFFSET(GntWidgetClass, map), | |
171 NULL, NULL, | |
172 g_cclosure_marshal_VOID__VOID, | |
173 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
174 signals[SIG_DRAW] = |
15818 | 175 g_signal_new("draw", |
176 G_TYPE_FROM_CLASS(klass), | |
177 G_SIGNAL_RUN_LAST, | |
178 G_STRUCT_OFFSET(GntWidgetClass, draw), | |
179 NULL, NULL, | |
180 g_cclosure_marshal_VOID__VOID, | |
181 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
182 signals[SIG_HIDE] = |
15818 | 183 g_signal_new("hide", |
184 G_TYPE_FROM_CLASS(klass), | |
185 G_SIGNAL_RUN_LAST, | |
186 G_STRUCT_OFFSET(GntWidgetClass, hide), | |
187 NULL, NULL, | |
188 g_cclosure_marshal_VOID__VOID, | |
189 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
190 signals[SIG_EXPOSE] = |
15818 | 191 g_signal_new("expose", |
192 G_TYPE_FROM_CLASS(klass), | |
193 G_SIGNAL_RUN_LAST, | |
194 G_STRUCT_OFFSET(GntWidgetClass, expose), | |
195 NULL, NULL, | |
196 gnt_closure_marshal_VOID__INT_INT_INT_INT, | |
197 G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
198 signals[SIG_POSITION] = |
15818 | 199 g_signal_new("position-set", |
200 G_TYPE_FROM_CLASS(klass), | |
201 G_SIGNAL_RUN_LAST, | |
202 G_STRUCT_OFFSET(GntWidgetClass, set_position), | |
203 NULL, NULL, | |
204 gnt_closure_marshal_VOID__INT_INT, | |
205 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
206 signals[SIG_SIZE_REQUEST] = |
15818 | 207 g_signal_new("size_request", |
208 G_TYPE_FROM_CLASS(klass), | |
209 G_SIGNAL_RUN_LAST, | |
210 G_STRUCT_OFFSET(GntWidgetClass, size_request), | |
211 NULL, NULL, | |
212 g_cclosure_marshal_VOID__VOID, | |
213 G_TYPE_NONE, 0); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
214 signals[SIG_SIZE_CHANGED] = |
15818 | 215 g_signal_new("size_changed", |
216 G_TYPE_FROM_CLASS(klass), | |
217 G_SIGNAL_RUN_LAST, | |
218 G_STRUCT_OFFSET(GntWidgetClass, size_changed), | |
219 NULL, NULL, | |
220 gnt_closure_marshal_VOID__INT_INT, | |
221 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
222 signals[SIG_CONFIRM_SIZE] = |
15818 | 223 g_signal_new("confirm_size", |
224 G_TYPE_FROM_CLASS(klass), | |
225 G_SIGNAL_RUN_LAST, | |
226 G_STRUCT_OFFSET(GntWidgetClass, confirm_size), | |
227 NULL, NULL, | |
228 gnt_closure_marshal_BOOLEAN__INT_INT, | |
229 G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT); | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
230 signals[SIG_KEY_PRESSED] = |
15818 | 231 g_signal_new("key_pressed", |
232 G_TYPE_FROM_CLASS(klass), | |
233 G_SIGNAL_RUN_LAST, | |
234 G_STRUCT_OFFSET(GntWidgetClass, key_pressed), | |
235 gnt_boolean_handled_accumulator, NULL, | |
236 gnt_closure_marshal_BOOLEAN__STRING, | |
237 G_TYPE_BOOLEAN, 1, G_TYPE_STRING); | |
238 | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
239 signals[SIG_CLICKED] = |
15818 | 240 g_signal_new("clicked", |
241 G_TYPE_FROM_CLASS(klass), | |
242 G_SIGNAL_RUN_LAST, | |
243 G_STRUCT_OFFSET(GntWidgetClass, clicked), | |
244 gnt_boolean_handled_accumulator, NULL, | |
245 gnt_closure_marshal_BOOLEAN__INT_INT_INT, | |
246 G_TYPE_BOOLEAN, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); | |
247 | |
31534
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
29220
diff
changeset
|
248 signals[SIG_CONTEXT_MENU] = |
15818 | 249 g_signal_new("context-menu", |
250 G_TYPE_FROM_CLASS(klass), | |
251 G_SIGNAL_RUN_LAST, | |
252 0, | |
253 gnt_boolean_handled_accumulator, NULL, | |
254 gnt_closure_marshal_BOOLEAN__VOID, | |
255 G_TYPE_BOOLEAN, 0); | |
256 | |
257 /* This is relevant for all widgets */ | |
258 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "context-menu", context_menu, | |
259 GNT_KEY_POPUP, NULL); | |
260 gnt_bindable_register_binding(GNT_BINDABLE_CLASS(klass), "context-menu", GNT_KEY_F11, NULL); | |
22786
95308e1b47d1
ctrl-x to open context menus. F11 was such a poor choice for this.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22307
diff
changeset
|
261 gnt_bindable_register_binding(GNT_BINDABLE_CLASS(klass), "context-menu", GNT_KEY_CTRL_X, NULL); |
15818 | 262 |
263 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
264 GNTDEBUG; | |
265 } | |
266 | |
267 /****************************************************************************** | |
268 * GntWidget API | |
269 *****************************************************************************/ | |
270 GType | |
271 gnt_widget_get_gtype(void) | |
272 { | |
273 static GType type = 0; | |
274 | |
275 if(type == 0) { | |
276 static const GTypeInfo info = { | |
277 sizeof(GntWidgetClass), | |
278 NULL, /* base_init */ | |
279 NULL, /* base_finalize */ | |
280 (GClassInitFunc)gnt_widget_class_init, | |
281 NULL, | |
282 NULL, /* class_data */ | |
283 sizeof(GntWidget), | |
284 0, /* n_preallocs */ | |
285 gnt_widget_init, /* instance_init */ | |
286 NULL /* value_table */ | |
287 }; | |
288 | |
289 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
290 "GntWidget", | |
291 &info, G_TYPE_FLAG_ABSTRACT); | |
292 } | |
293 | |
294 return type; | |
295 } | |
296 | |
297 void gnt_widget_set_take_focus(GntWidget *widget, gboolean can) | |
298 { | |
299 if (can) | |
300 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
301 else | |
302 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
303 } | |
304 | |
305 /** | |
306 * gnt_widget_destroy: | |
307 * @obj: The #GntWidget instance. | |
308 * | |
309 * Emits the "destroy" signal notifying all reference holders that they | |
310 * should release @obj. | |
311 */ | |
312 void | |
313 gnt_widget_destroy(GntWidget *obj) | |
314 { | |
315 g_return_if_fail(GNT_IS_WIDGET(obj)); | |
316 | |
18565
980d6e1b2d21
Fix a crash Eric found. These parameters were in reverse order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
317 if(!(GNT_WIDGET_FLAGS(obj) & GNT_WIDGET_DESTROYING)) { |
980d6e1b2d21
Fix a crash Eric found. These parameters were in reverse order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
318 GNT_WIDGET_SET_FLAGS(obj, GNT_WIDGET_DESTROYING); |
980d6e1b2d21
Fix a crash Eric found. These parameters were in reverse order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
319 gnt_widget_hide(obj); |
980d6e1b2d21
Fix a crash Eric found. These parameters were in reverse order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
320 delwin(obj->window); |
15818 | 321 g_object_run_dispose(G_OBJECT(obj)); |
18565
980d6e1b2d21
Fix a crash Eric found. These parameters were in reverse order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
322 } |
15818 | 323 GNTDEBUG; |
324 } | |
325 | |
326 void | |
327 gnt_widget_show(GntWidget *widget) | |
328 { | |
329 gnt_widget_draw(widget); | |
330 gnt_screen_occupy(widget); | |
331 } | |
332 | |
333 void | |
334 gnt_widget_draw(GntWidget *widget) | |
335 { | |
336 /* Draw the widget */ | |
337 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_DRAWING)) | |
338 return; | |
339 | |
340 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_DRAWING); | |
341 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_MAPPED)) { | |
342 gnt_widget_map(widget); | |
343 } | |
344 | |
345 if (widget->window == NULL) | |
346 { | |
347 #if 0 | |
348 int x, y, maxx, maxy, w, h; | |
349 int oldw, oldh; | |
350 gboolean shadow = TRUE; | |
351 | |
352 if (!gnt_widget_has_shadow(widget)) | |
353 shadow = FALSE; | |
354 | |
355 x = widget->priv.x; | |
356 y = widget->priv.y; | |
357 w = oldw = widget->priv.width + shadow; | |
358 h = oldh = widget->priv.height + shadow; | |
359 | |
360 getmaxyx(stdscr, maxy, maxx); | |
361 maxy -= 1; /* room for the taskbar */ | |
362 | |
363 x = MAX(0, x); | |
364 y = MAX(0, y); | |
365 if (x + w >= maxx) | |
366 x = MAX(0, maxx - w); | |
367 if (y + h >= maxy) | |
368 y = MAX(0, maxy - h); | |
369 | |
370 w = MIN(w, maxx); | |
371 h = MIN(h, maxy); | |
372 | |
373 widget->priv.x = x; | |
374 widget->priv.y = y; | |
375 if (w != oldw || h != oldh) { | |
376 widget->priv.width = w - shadow; | |
377 widget->priv.height = h - shadow; | |
378 g_signal_emit(widget, signals[SIG_SIZE_CHANGED], 0, oldw, oldh); | |
379 } | |
380 #else | |
381 widget->window = newpad(widget->priv.height + 20, widget->priv.width + 20); /* XXX: */ | |
382 #endif | |
383 init_widget(widget); | |
384 } | |
385 | |
386 g_signal_emit(widget, signals[SIG_DRAW], 0); | |
387 gnt_widget_queue_update(widget); | |
388 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_DRAWING); | |
389 } | |
390 | |
391 gboolean | |
392 gnt_widget_key_pressed(GntWidget *widget, const char *keys) | |
393 { | |
394 gboolean ret; | |
395 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
396 return FALSE; | |
397 | |
18566
3c634117a7ef
Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18565
diff
changeset
|
398 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_DISABLE_ACTIONS) && |
3c634117a7ef
Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18565
diff
changeset
|
399 gnt_bindable_perform_action_key(GNT_BINDABLE(widget), keys)) |
15818 | 400 return TRUE; |
401 | |
402 keys = gnt_bindable_remap_keys(GNT_BINDABLE(widget), keys); | |
403 g_signal_emit(widget, signals[SIG_KEY_PRESSED], 0, keys, &ret); | |
404 return ret; | |
405 } | |
406 | |
407 gboolean | |
408 gnt_widget_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
409 { | |
410 gboolean ret; | |
411 g_signal_emit(widget, signals[SIG_CLICKED], 0, event, x, y, &ret); | |
22307
d270b6aebabc
Right-clicking on a widget should trigger the context-menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21304
diff
changeset
|
412 if (!ret && event == GNT_RIGHT_MOUSE_DOWN) |
d270b6aebabc
Right-clicking on a widget should trigger the context-menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21304
diff
changeset
|
413 ret = gnt_bindable_perform_action_named(GNT_BINDABLE(widget), "context-menu", NULL); |
15818 | 414 return ret; |
415 } | |
416 | |
417 void | |
418 gnt_widget_expose(GntWidget *widget, int x, int y, int width, int height) | |
419 { | |
420 g_signal_emit(widget, signals[SIG_EXPOSE], 0, x, y, width, height); | |
421 } | |
422 | |
423 void | |
424 gnt_widget_hide(GntWidget *widget) | |
425 { | |
426 g_signal_emit(widget, signals[SIG_HIDE], 0); | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
427 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 428 #if 0 |
429 /* XXX: I have no clue why, but this seemed to be necessary. */ | |
430 if (gnt_widget_has_shadow(widget)) | |
431 mvwvline(widget->window, 1, widget->priv.width, ' ', widget->priv.height); | |
432 #endif | |
433 gnt_screen_release(widget); | |
434 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_INVISIBLE); | |
435 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_MAPPED); | |
436 } | |
437 | |
438 void | |
439 gnt_widget_set_position(GntWidget *wid, int x, int y) | |
440 { | |
441 g_signal_emit(wid, signals[SIG_POSITION], 0, x, y); | |
442 /* XXX: Need to install properties for these and g_object_notify */ | |
443 wid->priv.x = x; | |
444 wid->priv.y = y; | |
445 } | |
446 | |
447 void | |
448 gnt_widget_get_position(GntWidget *wid, int *x, int *y) | |
449 { | |
450 if (x) | |
451 *x = wid->priv.x; | |
452 if (y) | |
453 *y = wid->priv.y; | |
454 } | |
455 | |
456 void | |
457 gnt_widget_size_request(GntWidget *widget) | |
458 { | |
459 g_signal_emit(widget, signals[SIG_SIZE_REQUEST], 0); | |
460 } | |
461 | |
462 void | |
463 gnt_widget_get_size(GntWidget *wid, int *width, int *height) | |
464 { | |
465 gboolean shadow = TRUE; | |
466 if (!gnt_widget_has_shadow(wid)) | |
467 shadow = FALSE; | |
468 | |
469 if (width) | |
470 *width = wid->priv.width + shadow; | |
471 if (height) | |
472 *height = wid->priv.height + shadow; | |
473 } | |
474 | |
475 static void | |
476 init_widget(GntWidget *widget) | |
477 { | |
478 gboolean shadow = TRUE; | |
479 | |
480 if (!gnt_widget_has_shadow(widget)) | |
481 shadow = FALSE; | |
482 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
483 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 484 werase(widget->window); |
485 | |
486 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) | |
487 { | |
488 /* - This is ugly. */ | |
489 /* - What's your point? */ | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
490 mvwvline(widget->window, 0, 0, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL), widget->priv.height); |
15818 | 491 mvwvline(widget->window, 0, widget->priv.width - 1, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
492 ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL), widget->priv.height); |
15818 | 493 mvwhline(widget->window, widget->priv.height - 1, 0, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
494 ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), widget->priv.width); |
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
495 mvwhline(widget->window, 0, 0, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), widget->priv.width); |
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
496 mvwaddch(widget->window, 0, 0, ACS_ULCORNER | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 497 mvwaddch(widget->window, 0, widget->priv.width - 1, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
498 ACS_URCORNER | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 499 mvwaddch(widget->window, widget->priv.height - 1, 0, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
500 ACS_LLCORNER | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 501 mvwaddch(widget->window, widget->priv.height - 1, widget->priv.width - 1, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
502 ACS_LRCORNER | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 503 } |
504 | |
505 if (shadow) | |
506 { | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
507 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_SHADOW)); |
15818 | 508 mvwvline(widget->window, 1, widget->priv.width, ' ', widget->priv.height); |
509 mvwhline(widget->window, widget->priv.height, 1, ' ', widget->priv.width); | |
510 } | |
511 } | |
512 | |
513 gboolean | |
514 gnt_widget_set_size(GntWidget *widget, int width, int height) | |
515 { | |
516 gboolean ret = TRUE; | |
517 | |
518 if (gnt_widget_has_shadow(widget)) | |
519 { | |
520 width--; | |
521 height--; | |
522 } | |
523 if (width <= 0) | |
524 width = widget->priv.width; | |
525 if (height <= 0) | |
526 height = widget->priv.height; | |
527 | |
528 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
529 { | |
530 ret = gnt_widget_confirm_size(widget, width, height); | |
531 } | |
532 | |
533 if (ret) | |
534 { | |
535 gboolean shadow = TRUE; | |
536 int oldw, oldh; | |
537 | |
538 if (!gnt_widget_has_shadow(widget)) | |
539 shadow = FALSE; | |
540 | |
541 oldw = widget->priv.width; | |
542 oldh = widget->priv.height; | |
543 | |
544 widget->priv.width = width; | |
545 widget->priv.height = height; | |
15943
7db39d873d52
Do not crash when resizing with shadows turned on.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
546 if (width + shadow >= getmaxx(widget->window) || height + shadow >= getmaxy(widget->window)) { |
15818 | 547 delwin(widget->window); |
548 widget->window = newpad(height + 20, width + 20); | |
549 } | |
550 | |
551 g_signal_emit(widget, signals[SIG_SIZE_CHANGED], 0, oldw, oldh); | |
552 | |
553 if (widget->window) | |
554 { | |
555 init_widget(widget); | |
556 } | |
557 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
558 init_widget(widget); | |
559 else | |
560 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_MAPPED); | |
561 } | |
562 | |
563 return ret; | |
564 } | |
565 | |
566 gboolean | |
567 gnt_widget_set_focus(GntWidget *widget, gboolean set) | |
568 { | |
569 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_CAN_TAKE_FOCUS)) | |
570 return FALSE; | |
571 | |
572 if (set && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_HAS_FOCUS)) | |
573 { | |
574 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_HAS_FOCUS); | |
575 g_signal_emit(widget, signals[SIG_GIVE_FOCUS], 0); | |
576 } | |
18223
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
577 else if (!set && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_HAS_FOCUS)) |
15818 | 578 { |
579 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_HAS_FOCUS); | |
580 g_signal_emit(widget, signals[SIG_LOST_FOCUS], 0); | |
581 } | |
582 else | |
583 return FALSE; | |
584 | |
585 return TRUE; | |
586 } | |
587 | |
588 void gnt_widget_set_name(GntWidget *widget, const char *name) | |
589 { | |
590 g_free(widget->priv.name); | |
591 widget->priv.name = g_strdup(name); | |
592 } | |
593 | |
594 const char *gnt_widget_get_name(GntWidget *widget) | |
595 { | |
596 return widget->priv.name; | |
597 } | |
598 | |
599 void gnt_widget_activate(GntWidget *widget) | |
600 { | |
601 g_signal_emit(widget, signals[SIG_ACTIVATE], 0); | |
602 } | |
603 | |
604 static gboolean | |
605 update_queue_callback(gpointer data) | |
606 { | |
607 GntWidget *widget = GNT_WIDGET(data); | |
608 | |
609 if (!g_object_get_data(G_OBJECT(widget), "gnt:queue_update")) | |
610 return FALSE; | |
611 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
612 gnt_screen_update(widget); | |
613 g_object_set_data(G_OBJECT(widget), "gnt:queue_update", NULL); | |
614 return FALSE; | |
615 } | |
616 | |
617 void gnt_widget_queue_update(GntWidget *widget) | |
618 { | |
619 if (widget->window == NULL) | |
620 return; | |
621 while (widget->parent) | |
622 widget = widget->parent; | |
21161
e119edfc0fb0
applied changes from 172a59b41412c4630834d66f2e7ec3be970cc36b
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
623 |
15818 | 624 if (!g_object_get_data(G_OBJECT(widget), "gnt:queue_update")) |
625 { | |
626 int id = g_timeout_add(0, update_queue_callback, widget); | |
627 g_object_set_data_full(G_OBJECT(widget), "gnt:queue_update", GINT_TO_POINTER(id), | |
628 (GDestroyNotify)g_source_remove); | |
629 } | |
630 } | |
631 | |
632 gboolean gnt_widget_confirm_size(GntWidget *widget, int width, int height) | |
633 { | |
634 gboolean ret = FALSE; | |
635 g_signal_emit(widget, signals[SIG_CONFIRM_SIZE], 0, width, height, &ret); | |
636 return ret; | |
637 } | |
638 | |
639 void gnt_widget_set_visible(GntWidget *widget, gboolean set) | |
640 { | |
641 if (set) | |
642 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_INVISIBLE); | |
643 else | |
644 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_INVISIBLE); | |
645 } | |
646 | |
647 gboolean gnt_widget_has_shadow(GntWidget *widget) | |
648 { | |
649 return (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_SHADOW) && | |
650 gnt_style_get_bool(GNT_STYLE_SHADOW, FALSE)); | |
651 } | |
652 |