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" /* mouse_h */
11 /*** typedefs(not structures) and defined constants **********************************************/
13 #define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
14 /* Sets/clear the specified flag in the options field */
15 #define widget_option(w,f,i) \
16 w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f))))
17 #define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i))
18 #define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i))
19 #define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
21 /*** enums ***************************************************************************************/
26 WIDGET_INIT
, /* Initialize widget */
27 WIDGET_FOCUS
, /* Draw widget in focused state */
28 WIDGET_UNFOCUS
, /* Draw widget in unfocused state */
29 WIDGET_DRAW
, /* Sent to widget to draw themselves */
30 WIDGET_KEY
, /* Sent to widgets on key press */
31 WIDGET_HOTKEY
, /* Sent to widget to catch preprocess key */
32 WIDGET_COMMAND
, /* Send to widget to handle command */
33 WIDGET_DESTROY
, /* Sent to widget at destruction time */
34 WIDGET_CURSOR
, /* Sent to widget to position the cursor */
35 WIDGET_IDLE
, /* Sent to widgets with options & W_WANT_IDLE */
36 WIDGET_RESIZED
/* Sent after a widget has been resized */
39 /* Widgets are expected to answer to the following messages:
41 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
42 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
43 WIDGET_KEY: 1 if they actually used the key, 0 if not.
44 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
56 W_WANT_HOTKEY
= (1 << 1),
57 W_WANT_CURSOR
= (1 << 2),
58 W_WANT_IDLE
= (1 << 3),
59 W_IS_INPUT
= (1 << 4),
60 W_DISABLED
= (1 << 5) /* Widget cannot be selected */
63 /* Flags for widget repositioning on dialog resize */
66 WPOS_KEEP_LEFT
= (1 << 0), /* keep widget distance to left border of dialog */
67 WPOS_KEEP_RIGHT
= (1 << 1), /* keep widget distance to right border of dialog */
68 WPOS_KEEP_TOP
= (1 << 2), /* keep widget distance to top border of dialog */
69 WPOS_KEEP_BOTTOM
= (1 << 3), /* keep widget distance to bottom border of dialog */
70 WPOS_KEEP_HORZ
= WPOS_KEEP_LEFT
| WPOS_KEEP_RIGHT
,
71 WPOS_KEEP_VERT
= WPOS_KEEP_TOP
| WPOS_KEEP_BOTTOM
,
72 WPOS_KEEP_ALL
= WPOS_KEEP_HORZ
| WPOS_KEEP_VERT
75 /*** structures declarations (and typedefs of structures)*****************************************/
78 typedef cb_ret_t (*callback_fn
) (struct Widget
* widget
, widget_msg_t msg
, int parm
);
80 /* Every Widget must have this as its first element */
85 widget_options_t options
;
86 widget_pos_flags_t pos_flags
; /* repositioning flags */
87 unsigned int id
; /* Number of the widget, starting with 0 */
90 struct Dlg_head
*owner
;
93 /* structure for label (caption) with hotkey, if original text does not contain
94 * hotkey, only start is valid and is equal to original text
95 * hotkey is defined as char*, but mc support only singlebyte hotkey
97 typedef struct hotkey_t
104 /*** global variables defined in .c file *********************************************************/
106 /*** declarations of public functions ************************************************************/
108 /* create hotkey from text */
109 hotkey_t
parse_hotkey (const char *text
);
110 /* release hotkey, free all mebers of hotkey_t */
111 void release_hotkey (const hotkey_t hotkey
);
112 /* return width on terminal of hotkey */
113 int hotkey_width (const hotkey_t hotkey
);
114 /* draw hotkey of widget */
115 void hotkey_draw (struct Widget
*w
, const hotkey_t hotkey
, gboolean focused
);
117 /* widget initialization */
118 void init_widget (Widget
* w
, int y
, int x
, int lines
, int cols
,
119 callback_fn callback
, mouse_h mouse_handler
);
120 /* Default callback for widgets */
121 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
122 void widget_set_size (Widget
* widget
, int y
, int x
, int lines
, int cols
);
123 /* select color for widget in dependance of state */
124 void widget_selectcolor (struct Widget
*w
, gboolean focused
, gboolean hotkey
);
125 void widget_erase (Widget
* w
);
127 /*** inline functions ****************************************************************************/
129 static inline cb_ret_t
130 send_message (Widget
* w
, widget_msg_t msg
, int parm
)
132 return w
->callback (w
, msg
, parm
);
135 #endif /* MC__WIDGET_INTERNAL_H */