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