1 /*  MikMod module player
2 	(c) 1998 - 2000 Miodrag Vallat and others - see file AUTHORS for
3 	complete list.
4 
5 	This program is free software; you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation; either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program; if not, write to the Free Software
17 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 	02111-1307, USA.
19 */
20 
21 /*==============================================================================
22 
23   $Id: mwidget.h,v 1.1.1.1 2004/01/16 02:07:33 raph Exp $
24 
25   Widget and Dialog creation functions
26 
27 ==============================================================================*/
28 
29 #ifndef MWIDGET_H
30 #define MWIDGET_H
31 
32 #include "mwindow.h"
33 
34 #define EVENT_HANDLED	100
35 
36 #define FOCUS_NEXT		(1)			/* next widget gets focus */
37 #define FOCUS_PREV		(-1)		/* prev widget gets focus */
38 #define FOCUS_ACTIVATE	(EVENT_HANDLED+1)	/* button select, return in input field */
39 #define FOCUS_DONT		(EVENT_HANDLED+2)	/* on hotkey: action is done (e.g. toggle */
40 											/* button is toggled), focus is not changed */
41 typedef enum {
42 	WID_SEL_SINGLE,
43 	WID_SEL_BROWSE
44 } WID_SEL_MODE;
45 
46 typedef enum {
47 	WID_GET_FOCUS,
48 	WID_HOTKEY,
49 	WID_KEY
50 } WID_EVENT;
51 
52 typedef enum {
53 	TYPE_LABEL,
54 	TYPE_STR,
55 	TYPE_INT,
56 	TYPE_BUTTON,
57 	TYPE_LIST,
58 	TYPE_CHECK,
59 	TYPE_TOGGLE,
60 	TYPE_COLORSEL
61 } WID_TYPE;
62 
63 typedef struct WIDGET WIDGET;
64 
65 typedef struct {
66 	int active;					/* active widget */
67 	int cnt;					/* Nuber of widgets */
68 	ATTRS attrs;				/* >=0: use it for DLG_FRAME and DLG_LABEL */
69 	MWINDOW *win;
70 	WIDGET **widget;		/* the widgets */
71 } DIALOG;
72 
73 struct WIDGET {
74 	WID_TYPE type;
75 	BOOL can_focus;				/* can the widget have the focus? */
76 	BOOL has_focus;				/* has this widget the focus? */
77 	int x, y, width, height;	/* pos and size of widget (calculated) */
78 	int def_width, def_height;	/* size set by wid_set_size(), can be used */
79 								/* by the widget as a default size */
80 
81 	/* >0 : Number of free lines to last widget
82 	   =0 : Start of a new column of widget
83 	   <0 : Start of a new row of columns of widgets, value is spacing
84             between this and the previous row */
85 	int spacing;
86 	DIALOG *d;
87 
88 	void (*w_free) (WIDGET *w);
89 	void (*w_paint) (WIDGET *w);
90 	int (*w_handle_event) (WIDGET *w, WID_EVENT event, int ch);
91 	void (*w_get_size) (WIDGET *w, int *width, int *height);
92 
93 	int (*handle_key) (WIDGET *w, int ch);
94 	int (*handle_focus) (WIDGET *w, int focus);
95 
96 	void *data;					/* not used by widget functions */
97 };
98 
99 /* called on key press, back:
100 	+/-n : Widget n entries before/behind Widget w gets the focus
101 	EVENT_HANDLED: Key is not processed any more
102 	0 : key is processed by the widgets own handleEventFunc */
103 typedef int (*handleKeyFunc) (WIDGET *w, int ch);
104 /* called on focus loose with FOCUS_NEXT, FOCUS_PREV, or FOCUS_ACTIVATE,
105    back: EVENT_HANDLED, FOCUS_ACTIVATE, +/-n, or 0 */
106 typedef int (*handleFocusFunc) (WIDGET *w, int focus);
107 
108 /* Free substructs of w and w itself */
109 typedef void (*freeFunc) (WIDGET *w);
110 /* Display widget w */
111 typedef void (*paintFunc) (WIDGET *w);
112 /*
113    GET_FOCUS: Widget w gets the focus
114      ch: -1: Last active widget was behind the new one
115           1: Last active widget was before the new one
116    HOTKEY:
117      ch: The Key which was pressed
118      back:
119        FOCUS_ACTIVATE: Widget w gets the focus
120        EVENT_HANDLED : Focus is not changed, Key is not processed any more,
121                        e.g. necessary if function closes the dialog
122    KEY: Key ch was pressed
123      back:
124        +/-n : Widget n entries before/behind Widget w gets the focus
125        EVENT_HANDLED: Key is not processed any more
126        0 : event HOTKEY is send to the widgets
127 */
128 typedef int (*handleEventFunc) (WIDGET *w, WID_EVENT event, int ch);
129 /* Return the size of widget w
130    Input: preferred maximal size */
131 typedef void (*getSizeFunc) (WIDGET *w, int *width, int *height);
132 
133 typedef struct {
134 	WIDGET w;
135 	char *msg;
136 } WID_LABEL;
137 
138 typedef struct {
139 	WIDGET w;
140 	char *input;
141 	int cur_pos;				/* cursor position */
142 	int start;					/* first visible char */
143 	int length;					/* max length of input */
144 } WID_STR;
145 
146 typedef struct {
147 	WIDGET w;
148 	char *input;
149 	int cur_pos;				/* cursor position */
150 	int start;					/* first visible char */
151 	int length;					/* max length of input */
152 } WID_INT;
153 
154 typedef struct {
155 	WIDGET w;
156 	char *button;				/* &but1|but2|... */
157 	int cnt;					/* number of buttons */
158 	int active;					/* active button */
159 } WID_BUTTON;
160 
161 typedef struct {
162 	WIDGET w;
163 	int cur;					/* selected entry */
164 	int first;					/* first line of list which is displayed */
165 	int cnt;					/* number of list entries */
166 	char **entries;				/* the list entries */
167 	char *title;
168 	WID_SEL_MODE sel_mode;		/* SINGLE: call of handle_focus() only on return */
169 } WID_LIST;						/* BROWSE: call of handle_focus() when cur changes */
170 
171 typedef struct {
172 	WIDGET w;
173 	char *button;				/* &but1|but2\nbu&t3\n... */
174 	int cnt;					/* number of buttons */
175 	int selected;				/* selected buttons */
176 	int active;					/* active button */
177 } WID_CHECK;
178 
179 typedef struct {
180 	WIDGET w;
181 	char *button;				/* &but1|but2\nbu&t3\n... */
182 	int cnt;					/* number of buttons */
183 	int selected;				/* selected buttons */
184 	int active;					/* active button */
185 } WID_TOGGLE;
186 
187 typedef struct {
188 	WIDGET w;
189 	int active;					/* selected color */
190 	char hkeys[5];				/* hotkeys to move the selector <>^v */
191 	WID_SEL_MODE sel_mode;		/* SINGLE: call of handle_focus() only on return */
192 } WID_COLORSEL;					/* BROWSE: call of handle_focus() when cur changes */
193 
194 /* spacing:
195      >0 : Number of free lines to last widget
196      =0 : Start of a new column of widget
197      <0 : Start of a new row of columns of widgets, value is spacing
198           between this and the previous row */
199 WIDGET *wid_label_add(DIALOG *d, int spacing, const char *msg);
200 void wid_label_set_label (WID_LABEL *w, const char *label);
201 
202 WIDGET *wid_str_add(DIALOG *d, int spacing, const char *input, int length);
203 void wid_str_set_input (WID_STR *w, const char *input, int length);
204 
205 WIDGET *wid_int_add(DIALOG *d, int spacing, int value, int length);
206 void wid_int_set_input(WID_INT *w, int value, int length);
207 
208 WIDGET *wid_button_add(DIALOG *d, int spacing, const char *button, int active);
209 
210 WIDGET *wid_list_add(DIALOG *d, int spacing, const char **entries, int cnt);
211 void wid_list_set_title(WID_LIST *w, const char *title);
212 void wid_list_set_entries(WID_LIST *w, const char **entries, int cur, int cnt);
213 void wid_list_set_active(WID_LIST *w, int cur);
214 void wid_list_set_selection_mode (WID_LIST *w, WID_SEL_MODE mode);
215 
216 WIDGET *wid_check_add(DIALOG *d, int spacing, const char *button,
217 					  int selected, int active);
218 void wid_check_set_selected(WID_CHECK *w, int selected);
219 
220 WIDGET *wid_toggle_add(DIALOG *d, int spacing, const char *button,
221 					   int selected, int active);
222 void wid_toggle_set_selected(WID_TOGGLE *w, int selected);
223 
224 WIDGET *wid_colorsel_add(DIALOG *d, int spacing, const char *hotkeys, int active);
225 void wid_colorsel_set_active(WID_COLORSEL *w, int active);
226 
227 /* Set default size of widget, -1: ignore value */
228 void wid_set_size (WIDGET *w, int width, int height);
229 void wid_set_func(WIDGET *w, handleKeyFunc key, handleFocusFunc focus,
230 				  void *data);
231 
232 void wid_repaint (WIDGET *w);
233 
234 DIALOG *dialog_new(void);
235 void dialog_open(DIALOG *d, const char *title);
236 
237 /* set attribute which is used for DLG_FRAME and DLG_LABEL,
238    works only before dialog_open() */
239 void dialog_set_attr (DIALOG *d, ATTRS attrs);
240 BOOL dialog_repaint(MWINDOW *win);
241 void dialog_close(DIALOG *d);
242 
243 #endif /* MWIDGET_H */
244 
245 /* ex:set ts=4: */
246