1 /*
2  *  Widget group features module for Midnight Commander
3  */
4 
5 /** \file group.h
6  *  \brief Header: widget group features module
7  */
8 
9 #ifndef MC__GROUP_H
10 #define MC__GROUP_H
11 
12 #include "lib/global.h"
13 
14 /*** typedefs(not structures) and defined constants **********************************************/
15 
16 #define GROUP(x) ((WGroup *)(x))
17 #define CONST_GROUP(x) ((const WGroup *)(x))
18 
19 /*** enums ***************************************************************************************/
20 
21 /*** typedefs(not structures) ********************************************************************/
22 
23 /*** structures declarations (and typedefs of structures)*****************************************/
24 
25 struct WGroup
26 {
27     Widget widget;
28 
29     /* Group members */
30     GList *widgets;             /* widgets list */
31     GList *current;             /* Currently active widget */
32 
33     gboolean winch_pending;     /* SIGWINCH signal has been got. Resize group after rise */
34     int mouse_status;           /* For the autorepeat status of the mouse */
35 };
36 
37 /*** global variables defined in .c file *********************************************************/
38 
39 /*** declarations of public functions ************************************************************/
40 
41 void group_init (WGroup * g, int y1, int x1, int lines, int cols, widget_cb_fn callback,
42                  widget_mouse_cb_fn mouse_callback);
43 /* Default callback for groups */
44 cb_ret_t group_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
45                                  void *data);
46 cb_ret_t group_default_set_state (Widget * w, widget_state_t state, gboolean enable);
47 int group_handle_mouse_event (Widget * w, Gpm_Event * event);
48 
49 unsigned long group_add_widget_autopos (WGroup * g, void *w, widget_pos_flags_t pos_flags,
50                                         const void *before);
51 void group_remove_widget (void *w);
52 
53 void group_set_current_widget_next (WGroup * g);
54 void group_set_current_widget_prev (WGroup * g);
55 
56 GList *group_get_widget_next_of (GList * w);
57 GList *group_get_widget_prev_of (GList * w);
58 
59 void group_select_next_widget (WGroup * g);
60 void group_select_prev_widget (WGroup * g);
61 
62 void group_select_widget_by_id (const WGroup * g, unsigned long id);
63 
64 void group_send_broadcast_msg (WGroup * g, widget_msg_t message);
65 
66 /* --------------------------------------------------------------------------------------------- */
67 /*** inline functions ****************************************************************************/
68 /* --------------------------------------------------------------------------------------------- */
69 
70 /**
71  * Add widget to group before current widget.
72  *
73  * @param g WGroup object
74  * @param w widget to be added
75  *
76  * @return widget ID
77  */
78 
79 static inline unsigned long
group_add_widget(WGroup * g,void * w)80 group_add_widget (WGroup * g, void *w)
81 {
82     return group_add_widget_autopos (g, w, WPOS_KEEP_DEFAULT,
83                                      g->current != NULL ? g->current->data : NULL);
84 }
85 
86 /* --------------------------------------------------------------------------------------------- */
87 /**
88  * Add widget to group before specified widget.
89  *
90  * @param g WGroup object
91  * @param w widget to be added
92  * @param before add @w before this widget
93  *
94  * @return widget ID
95  */
96 
97 static inline unsigned long
group_add_widget_before(WGroup * g,void * w,void * before)98 group_add_widget_before (WGroup * g, void *w, void *before)
99 {
100     return group_add_widget_autopos (g, w, WPOS_KEEP_DEFAULT, before);
101 }
102 
103 /* --------------------------------------------------------------------------------------------- */
104 /**
105  * Select current widget in the Dialog.
106  *
107  * @param h WDialog object
108  */
109 
110 static inline void
group_select_current_widget(WGroup * g)111 group_select_current_widget (WGroup * g)
112 {
113     if (g->current != NULL)
114         widget_select (WIDGET (g->current->data));
115 }
116 
117 /* --------------------------------------------------------------------------------------------- */
118 
119 static inline unsigned long
group_get_current_widget_id(const WGroup * g)120 group_get_current_widget_id (const WGroup * g)
121 {
122     return WIDGET (g->current->data)->id;
123 }
124 
125 #endif /* MC__GROUP_H */
126