This source file includes following definitions.
- send_message
- widget_get_options
- widget_get_state
- widget_make_global
- widget_make_local
- widget_find
- widget_find_by_type
- widget_find_by_id
- widget_set_state
- widget_destroy
- widget_get_colors
- widget_update_cursor
- widget_show
- widget_hide
- widget_overlapped
1
2
3
4
5
6 #ifndef MC__WIDGET_COMMON_H
7 #define MC__WIDGET_COMMON_H
8
9 #include "lib/keybind.h"
10 #include "lib/tty/mouse.h"
11 #include "lib/widget/mouse.h"
12
13
14
15 #define WIDGET(x) ((Widget *)(x))
16 #define CONST_WIDGET(x) ((const Widget *)(x))
17
18 #define widget_gotoyx(w, _y, _x) tty_gotoyx (CONST_WIDGET(w)->rect.y + (_y), CONST_WIDGET(w)->rect.x + (_x))
19
20 #define widget_want_cursor(w,i) widget_set_options(w, WOP_WANT_CURSOR, i)
21 #define widget_want_hotkey(w,i) widget_set_options(w, WOP_WANT_HOTKEY, i)
22 #define widget_want_tab(w,i) widget_set_options(w, WOP_WANT_TAB, i)
23 #define widget_idle(w,i) widget_set_state(w, WST_IDLE, i)
24 #define widget_disable(w,i) widget_set_state(w, WST_DISABLED, i)
25
26
27
28
29 typedef enum
30 {
31 MSG_INIT = 0,
32 MSG_FOCUS,
33 MSG_UNFOCUS,
34 MSG_CHANGED_FOCUS,
35 MSG_ENABLE,
36 MSG_DISABLE,
37 MSG_DRAW,
38 MSG_KEY,
39 MSG_HOTKEY,
40 MSG_HOTKEY_HANDLED,
41 MSG_UNHANDLED_KEY,
42 MSG_POST_KEY,
43 MSG_ACTION,
44 MSG_NOTIFY,
45
46 MSG_CURSOR,
47 MSG_IDLE,
48 MSG_RESIZE,
49 MSG_VALIDATE,
50 MSG_END,
51 MSG_DESTROY
52 } widget_msg_t;
53
54
55
56
57
58
59
60
61 typedef enum
62 {
63 MSG_NOT_HANDLED = 0,
64 MSG_HANDLED = 1
65 } cb_ret_t;
66
67
68 typedef enum
69 {
70 WOP_DEFAULT = (0 << 0),
71 WOP_WANT_HOTKEY = (1 << 0),
72 WOP_WANT_CURSOR = (1 << 1),
73 WOP_WANT_TAB = (1 << 2),
74 WOP_IS_INPUT = (1 << 3),
75 WOP_SELECTABLE = (1 << 4),
76 WOP_TOP_SELECT = (1 << 5)
77 } widget_options_t;
78
79
80 typedef enum
81 {
82 WST_DEFAULT = (0 << 0),
83 WST_VISIBLE = (1 << 0),
84 WST_DISABLED = (1 << 1),
85 WST_IDLE = (1 << 2),
86 WST_MODAL = (1 << 3),
87 WST_FOCUSED = (1 << 4),
88
89 WST_CONSTRUCT = (1 << 15),
90 WST_ACTIVE = (1 << 16),
91 WST_SUSPENDED = (1 << 17),
92 WST_CLOSED = (1 << 18)
93 } widget_state_t;
94
95
96 typedef enum
97 {
98 WPOS_FULLSCREEN = (1 << 0),
99 WPOS_CENTER_HORZ = (1 << 1),
100 WPOS_CENTER_VERT = (1 << 2),
101 WPOS_CENTER = WPOS_CENTER_HORZ | WPOS_CENTER_VERT,
102 WPOS_TRYUP = (1 << 3),
103 WPOS_KEEP_LEFT = (1 << 4),
104 WPOS_KEEP_RIGHT = (1 << 5),
105 WPOS_KEEP_TOP = (1 << 6),
106 WPOS_KEEP_BOTTOM = (1 << 7),
107 WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT,
108 WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM,
109 WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT,
110 WPOS_KEEP_DEFAULT = WPOS_KEEP_LEFT | WPOS_KEEP_TOP
111 } widget_pos_flags_t;
112
113
114
115
116
117
118
119
120
121
122
123 typedef cb_ret_t (*widget_cb_fn) (Widget * widget, Widget * sender, widget_msg_t msg, int parm,
124 void *data);
125
126 typedef void (*widget_mouse_cb_fn) (Widget * w, mouse_msg_t msg, mouse_event_t * event);
127
128 typedef int (*widget_mouse_handle_fn) (Widget * w, Gpm_Event * event);
129
130
131 struct Widget
132 {
133 WRect rect;
134
135
136 widget_pos_flags_t pos_flags;
137 widget_options_t options;
138 widget_state_t state;
139 unsigned long id;
140 widget_cb_fn callback;
141 widget_mouse_cb_fn mouse_callback;
142 WGroup *owner;
143
144
145 const global_keymap_t *keymap;
146 const global_keymap_t *ext_keymap;
147 gboolean ext_mode;
148
149
150 widget_mouse_handle_fn mouse_handler;
151 struct
152 {
153
154 gboolean forced_capture;
155
156
157 gboolean capture;
158 mouse_msg_t last_msg;
159 int last_buttons_down;
160 } mouse;
161
162 void (*make_global) (Widget * w, const WRect * delta);
163 void (*make_local) (Widget * w, const WRect * delta);
164
165 GList *(*find) (const Widget * w, const Widget * what);
166 Widget *(*find_by_type) (const Widget * w, widget_cb_fn cb);
167 Widget *(*find_by_id) (const Widget * w, unsigned long id);
168
169
170 cb_ret_t (*set_state) (Widget * w, widget_state_t state, gboolean enable);
171
172 void (*destroy) (Widget * w);
173
174 const int *(*get_colors) (const Widget * w);
175 };
176
177
178
179
180
181 typedef struct hotkey_t
182 {
183 char *start;
184 char *hotkey;
185 char *end;
186 } hotkey_t;
187
188
189
190
191
192
193 hotkey_t hotkey_new (const char *text);
194
195 void hotkey_free (const hotkey_t hotkey);
196
197 int hotkey_width (const hotkey_t hotkey);
198
199 gboolean hotkey_equal (const hotkey_t hotkey1, const hotkey_t hotkey2);
200
201 void hotkey_draw (const Widget * w, const hotkey_t hotkey, gboolean focused);
202
203 char *hotkey_get_text (const hotkey_t hotkey);
204
205
206 void widget_init (Widget * w, const WRect * r, widget_cb_fn callback,
207 widget_mouse_cb_fn mouse_callback);
208
209 cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
210 void *data);
211 void widget_set_options (Widget * w, widget_options_t options, gboolean enable);
212 void widget_adjust_position (widget_pos_flags_t pos_flags, WRect * r);
213 void widget_set_size (Widget * w, int y, int x, int lines, int cols);
214 void widget_set_size_rect (Widget * w, WRect * r);
215
216 void widget_selectcolor (const Widget * w, gboolean focused, gboolean hotkey);
217 cb_ret_t widget_draw (Widget * w);
218 void widget_erase (Widget * w);
219 void widget_set_visibility (Widget * w, gboolean make_visible);
220 gboolean widget_is_active (const void *w);
221 void widget_replace (Widget * old, Widget * new);
222 gboolean widget_is_focusable (const Widget * w);
223 void widget_select (Widget * w);
224 void widget_set_bottom (Widget * w);
225
226 long widget_lookup_key (Widget * w, int key);
227
228 void widget_default_make_global (Widget * w, const WRect * delta);
229 void widget_default_make_local (Widget * w, const WRect * delta);
230
231 GList *widget_default_find (const Widget * w, const Widget * what);
232 Widget *widget_default_find_by_type (const Widget * w, widget_cb_fn cb);
233 Widget *widget_default_find_by_id (const Widget * w, unsigned long id);
234
235 cb_ret_t widget_default_set_state (Widget * w, widget_state_t state, gboolean enable);
236
237 void widget_default_destroy (Widget * w);
238
239
240 Gpm_Event mouse_get_local (const Gpm_Event * global, const Widget * w);
241 gboolean mouse_global_in_widget (const Gpm_Event * event, const Widget * w);
242
243
244
245
246
247 static inline cb_ret_t
248 send_message (void *w, void *sender, widget_msg_t msg, int parm, void *data)
249 {
250 cb_ret_t ret = MSG_NOT_HANDLED;
251
252 #if 1
253 if (w != NULL)
254 #endif
255 ret = WIDGET (w)->callback (WIDGET (w), WIDGET (sender), msg, parm, data);
256
257 return ret;
258 }
259
260
261
262
263
264
265
266
267
268
269 static inline gboolean
270 widget_get_options (const Widget *w, widget_options_t options)
271 {
272 return ((w->options & options) == options);
273 }
274
275
276
277
278
279
280
281
282
283
284
285 static inline gboolean
286 widget_get_state (const Widget *w, widget_state_t state)
287 {
288 return ((w->state & state) == state);
289 }
290
291
292
293
294
295
296
297
298
299 static inline void
300 widget_make_global (Widget *w)
301 {
302 w->make_global (w, NULL);
303 }
304
305
306
307
308
309
310
311
312
313 static inline void
314 widget_make_local (Widget *w)
315 {
316 w->make_local (w, NULL);
317 }
318
319
320
321
322
323
324
325
326
327
328
329
330 static inline GList *
331 widget_find (const Widget *w, const Widget *what)
332 {
333 return w->find (w, what);
334 }
335
336
337
338
339
340
341
342
343
344
345
346
347 static inline Widget *
348 widget_find_by_type (const Widget *w, widget_cb_fn cb)
349 {
350 return w->find_by_type (w, cb);
351 }
352
353
354
355
356
357
358
359
360
361
362
363 static inline Widget *
364 widget_find_by_id (const Widget *w, unsigned long id)
365 {
366 return w->find_by_id (w, id);
367 }
368
369
370
371
372
373
374
375
376
377
378
379
380 static inline cb_ret_t
381 widget_set_state (Widget *w, widget_state_t state, gboolean enable)
382 {
383 return w->set_state (w, state, enable);
384 }
385
386
387
388
389
390
391
392
393 static inline void
394 widget_destroy (Widget *w)
395 {
396 w->destroy (w);
397 }
398
399
400
401
402
403
404
405
406
407 static inline const int *
408 widget_get_colors (const Widget *w)
409 {
410 return w->get_colors (w);
411 }
412
413
414
415
416
417
418
419
420
421
422 static inline gboolean
423 widget_update_cursor (Widget *w)
424 {
425 return (send_message (w, NULL, MSG_CURSOR, 0, NULL) == MSG_HANDLED);
426 }
427
428
429
430 static inline void
431 widget_show (Widget *w)
432 {
433 widget_set_visibility (w, TRUE);
434 }
435
436
437
438 static inline void
439 widget_hide (Widget *w)
440 {
441 widget_set_visibility (w, FALSE);
442 }
443
444
445
446
447
448
449
450
451
452
453
454 static inline gboolean
455 widget_overlapped (const Widget *a, const Widget *b)
456 {
457 return rects_are_overlapped (&a->rect, &b->rect);
458 }
459
460
461
462 #endif