2 /** \file widget-common.h
3 * \brief Header: shared stuff of widgets
6 #ifndef MC__WIDGET_INTERNAL_H
7 #define MC__WIDGET_INTERNAL_H
9 #include "lib/tty/mouse.h"
11 /*** typedefs(not structures) and defined constants **********************************************/
13 #define WIDGET(x) ((Widget *)(x))
15 #define widget_move(w, _y, _x) tty_gotoyx (WIDGET(w)->y + (_y), WIDGET(w)->x + (_x))
16 /* Sets/clear the specified flag in the options field */
17 #define widget_option(w,f,i) \
18 (w)->options = ((i) ? ((w)->options | (f)) : ((w)->options & (~(f))))
19 #define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i))
20 #define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i))
21 #define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
23 /*** enums ***************************************************************************************/
28 WIDGET_INIT
, /* Initialize widget */
29 WIDGET_FOCUS
, /* Draw widget in focused state */
30 WIDGET_UNFOCUS
, /* Draw widget in unfocused state */
31 WIDGET_DRAW
, /* Sent to widget to draw themselves */
32 WIDGET_KEY
, /* Sent to widgets on key press */
33 WIDGET_HOTKEY
, /* Sent to widget to catch preprocess key */
34 WIDGET_COMMAND
, /* Send to widget to handle command */
35 WIDGET_DESTROY
, /* Sent to widget at destruction time */
36 WIDGET_CURSOR
, /* Sent to widget to position the cursor */
37 WIDGET_IDLE
, /* Sent to widgets with options & W_WANT_IDLE */
38 WIDGET_RESIZED
/* Sent after a widget has been resized */
41 /* Widgets are expected to answer to the following messages:
43 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
44 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
45 WIDGET_KEY: 1 if they actually used the key, 0 if not.
46 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
58 W_WANT_HOTKEY
= (1 << 1),
59 W_WANT_CURSOR
= (1 << 2),
60 W_WANT_IDLE
= (1 << 3),
61 W_IS_INPUT
= (1 << 4),
62 W_DISABLED
= (1 << 5) /* Widget cannot be selected */
65 /* Flags for widget repositioning on dialog resize */
68 WPOS_KEEP_LEFT
= (1 << 0), /* keep widget distance to left border of dialog */
69 WPOS_KEEP_RIGHT
= (1 << 1), /* keep widget distance to right border of dialog */
70 WPOS_KEEP_TOP
= (1 << 2), /* keep widget distance to top border of dialog */
71 WPOS_KEEP_BOTTOM
= (1 << 3), /* keep widget distance to bottom border of dialog */
72 WPOS_KEEP_HORZ
= WPOS_KEEP_LEFT
| WPOS_KEEP_RIGHT
,
73 WPOS_KEEP_VERT
= WPOS_KEEP_TOP
| WPOS_KEEP_BOTTOM
,
74 WPOS_KEEP_ALL
= WPOS_KEEP_HORZ
| WPOS_KEEP_VERT
77 /*** structures declarations (and typedefs of structures)*****************************************/
80 typedef cb_ret_t (*widget_cb_fn
) (struct Widget
* widget
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
);
82 /* Every Widget must have this as its first element */
87 widget_options_t options
;
88 widget_pos_flags_t pos_flags
; /* repositioning flags */
89 unsigned int id
; /* Number of the widget, starting with 0 */
90 widget_cb_fn callback
;
92 struct Dlg_head
*owner
;
95 /* structure for label (caption) with hotkey, if original text does not contain
96 * hotkey, only start is valid and is equal to original text
97 * hotkey is defined as char*, but mc support only singlebyte hotkey
99 typedef struct hotkey_t
106 /*** global variables defined in .c file *********************************************************/
108 /*** declarations of public functions ************************************************************/
110 /* create hotkey from text */
111 hotkey_t
parse_hotkey (const char *text
);
112 /* release hotkey, free all mebers of hotkey_t */
113 void release_hotkey (const hotkey_t hotkey
);
114 /* return width on terminal of hotkey */
115 int hotkey_width (const hotkey_t hotkey
);
116 /* draw hotkey of widget */
117 void hotkey_draw (struct Widget
*w
, const hotkey_t hotkey
, gboolean focused
);
119 /* widget initialization */
120 void init_widget (Widget
* w
, int y
, int x
, int lines
, int cols
,
121 widget_cb_fn callback
, mouse_h mouse_handler
);
122 /* Default callback for widgets */
123 cb_ret_t
default_widget_callback (Widget
* sender
, widget_msg_t msg
, int parm
, void *data
);
124 void widget_set_size (Widget
* widget
, int y
, int x
, int lines
, int cols
);
125 /* select color for widget in dependance of state */
126 void widget_selectcolor (struct Widget
*w
, gboolean focused
, gboolean hotkey
);
127 void widget_erase (Widget
* w
);
129 /* get mouse pointer location within widget */
130 Gpm_Event
mouse_get_local (const Gpm_Event
* global
, const Widget
* w
);
131 gboolean
mouse_global_in_widget (const Gpm_Event
* event
, const Widget
* w
);
133 /*** inline functions ****************************************************************************/
135 static inline cb_ret_t
136 send_message (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
138 return w
->callback (w
, sender
, msg
, parm
, data
);
141 #endif /* MC__WIDGET_INTERNAL_H */