6 #define FOCUSC h->color[1]
7 #define NORMALC h->color[0]
8 #define HOT_NORMALC h->color[2]
9 #define HOT_FOCUSC h->color[3]
11 /* Possible directions */
13 #define DIR_BACKWARD 0
15 /* Common return values */
24 WIDGET_INIT
, /* Initialize widget */
25 WIDGET_FOCUS
, /* Draw widget in focused state */
26 WIDGET_UNFOCUS
, /* Draw widget in unfocused state */
27 WIDGET_DRAW
, /* Sent to widget to draw themselves */
28 WIDGET_KEY
, /* Sent to widgets on key press */
29 WIDGET_HOTKEY
, /* Sent to widget to catch preprocess key */
30 WIDGET_DESTROY
, /* Sent to widget at destruction time */
31 WIDGET_CURSOR
, /* Sent to widget to position the cursor */
32 WIDGET_IDLE
, /* Send to widgets with options & W_WANT_IDLE*/
33 WIDGET_USER
= 0x100000
35 } /* Widget_Messages */;
42 /* Widgets are expected to answer to the following messages:
44 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
45 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
46 WIDGET_KEY: 1 if they actually used the key, 0 if not.
47 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
52 DLG_KEY
, /* Sent on keypress before sending to widget */
53 DLG_INIT
, /* Sent on init */
54 DLG_END
, /* Sent on shutdown */
56 DLG_DRAW
, /* Sent for updating dialog managed area */
57 DLG_FOCUS
, /* Sent on give focus to a widget */
58 DLG_UNFOCUS
, /* Sent on remove focus from widget */
59 DLG_ONE_UP
, /* Sent on selecting next */
60 DLG_ONE_DOWN
, /* Sent on selecting prev */
61 DLG_POST_KEY
, /* Sent after key has been sent */
62 DLG_IDLE
, /* Sent if idle is active */
63 DLG_UNHANDLED_KEY
, /* Send if no widget wanted the key */
64 DLG_HOTKEY_HANDLED
, /* Send if a child got the hotkey */
65 DLG_PRE_EVENT
/* Send before calling get_event */
66 } /* Dialog_Messages */;
68 typedef unsigned long widget_data
;
69 typedef struct Dlg_head
{
70 int *color
; /* color set */
71 int count
; /* number of widgets */
75 int mouse_status
; /* For the autorepeat status of the mouse */
77 void *previous_dialog
; /* Pointer to the previously running Dlg_head */
78 int refresh_pushed
; /* Did the dialog actually run? */
81 int x
, y
; /* Position relative to screen origin */
90 /* Internal variables */
91 struct Widget_Item
*current
, *first
, *last
;
92 int (*callback
) (struct Dlg_head
*, int, int);
94 struct Widget_Item
*initfocus
;
96 char *title
; /* Title of the dialog */
102 int flags
; /* Different flags, specified in create_dlg() */
105 /* Every Widget must have this as it's first element */
106 typedef struct Widget
{
110 int (*callback
)(Dlg_head
*, void *, int, int); /* The callback function */
111 void (*destroy
)(void *);
113 struct Dlg_head
*parent
;
114 char *tkname
; /* name used for history saving */
117 /* The options for the widgets */
118 #define W_WANT_POST_KEY 1
119 #define W_WANT_HOTKEY 2
120 #define W_WANT_CURSOR 4
121 #define W_WANT_IDLE 8
122 #define W_IS_INPUT 16
123 #define W_PANEL_HIDDEN 32
125 typedef struct Widget_Item
{
127 struct Widget_Item
*next
; /* next in circle buffer */
128 struct Widget_Item
*prev
; /* previous in circle buffer */
129 Widget
*widget
; /* point to the component */
132 /* draw box in window */
133 void draw_box (Dlg_head
*h
, int y
, int x
, int ys
, int xs
);
135 /* doubled line if possible */
136 void draw_double_box (Dlg_head
*h
, int y
, int x
, int ys
, int xs
);
138 /* Creates a dialog head */
139 Dlg_head
*create_dlg (int y1
, int x1
, int lines
, int cols
,
141 int (*callback
) (struct Dlg_head
*, int, int),
142 char *help_ctx
, char *name
, int flags
);
145 #define DLG_WANT_TAB 16 /* Should the tab key be sent to the dialog? */
146 #define DLG_HAS_MENUBAR 8 /* GrossHack: Send events on row 1 to a menubar? */
147 #define DLG_COMPACT 4 /* Suppress spaces around the frame */
148 #define DLG_TRYUP 2 /* Try to move two lines up the dialog */
149 #define DLG_CENTER 1 /* Center the dialog */
150 #define DLG_NONE 0 /* No options */
152 int add_widget (Dlg_head
*dest
, void *Widget
);
153 int remove_widget (Dlg_head
*dest
, void *Widget
);
154 int destroy_widget (Widget
*w
);
157 void run_dlg (Dlg_head
*d
);
159 void dlg_run_done (Dlg_head
*h
);
160 void dlg_process_event (Dlg_head
*h
, int key
, Gpm_Event
*event
);
161 void init_dlg (Dlg_head
*h
);
163 /* To activate/deactivate the idle message generation */
164 void set_idle_proc (Dlg_head
*d
, int state
);
166 void dlg_redraw (Dlg_head
*h
);
167 void dlg_refresh (void *parameter
);
168 void destroy_dlg (Dlg_head
*h
);
170 void widget_set_size (Widget
*widget
, int x1
, int y1
, int x2
, int y2
);
172 void dlg_broadcast_msg_to (Dlg_head
*h
, int message
, int reverse
, int flags
);
173 void dlg_broadcast_msg (Dlg_head
*h
, int message
, int reverse
);
174 void dlg_mouse (Dlg_head
*h
, Gpm_Event
*event
);
176 typedef void (*destroy_fn
)(void *);
177 typedef int (*callback_fn
)(Dlg_head
*, void *, int, int);
179 void init_widget (Widget
*w
, int y
, int x
, int lines
, int cols
,
180 callback_fn callback
, destroy_fn destroy
,
181 mouse_h mouse_handler
, char *tkname
);
183 /* Various default service provision */
184 int default_dlg_callback (Dlg_head
*h
, int id
, int msg
);
185 int std_callback (Dlg_head
*h
, int Msg
, int Par
);
186 int default_proc (Dlg_head
*h
, int Msg
, int Par
);
188 #define real_widget_move(w, _y, _x) move((w)->y + _y, (w)->x + _x)
189 #define dlg_move(h, _y, _x) move(((Dlg_head *) h)->y + _y, \
190 ((Dlg_head *) h)->x + _x)
192 #define widget_move(w,y,x) real_widget_move((Widget*)w,y,x)
194 extern Dlg_head
*current_dlg
;
196 int send_message (Dlg_head
*h
, Widget
*w
, int msg
, int par
);
197 int send_message_to (Dlg_head
*h
, Widget
*w
, int msg
, int par
);
198 void dlg_replace_widget (Dlg_head
*h
, Widget
*old
, Widget
*new);
199 void widget_redraw (Dlg_head
*h
, Widget_Item
*w
);
200 int dlg_overlap (Widget
*a
, Widget
*b
);
201 void widget_erase (Widget
*);
202 void dlg_erase (Dlg_head
*h
);
203 void dlg_stop (Dlg_head
*h
);
205 /* Widget selection */
206 int dlg_select_widget (Dlg_head
*h
, void *widget
);
207 void dlg_one_up (Dlg_head
*h
);
208 void dlg_one_down (Dlg_head
*h
);
209 int dlg_focus (Dlg_head
*h
);
210 int dlg_unfocus (Dlg_head
*h
);
211 int dlg_select_nth_widget (Dlg_head
*h
, int n
);
212 int dlg_item_number (Dlg_head
*h
);
213 Widget
*find_widget_type (Dlg_head
*h
, callback_fn signature
);
215 /* Sets/clear the specified flag in the options field */
216 #define widget_option(w,f,i) \
217 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
219 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
220 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
221 #define widget_want_postkey(w,i) widget_option(w, W_WANT_POSTKEY, i)
223 typedef void (*movefn
)(void *, int);
225 /* Layout definitions */
227 void x_set_dialog_title (Dlg_head
*h
, const char *title
);
229 /* The inner workings of run_dlg, exported for the Tk and XView toolkits */
230 int dlg_key_event (Dlg_head
*h
, int d_key
);
231 void update_cursor (Dlg_head
*h
);
233 #endif /* MC_DLG_H */