/[james]/archive/guilib/main_gtk.c
ViewVC logotype

Annotation of /archive/guilib/main_gtk.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (hide annotations) (download) (as text)
Mon Feb 10 22:56:40 2003 UTC (21 years, 10 months ago) by james
File MIME type: text/x-csrc
File size: 9873 byte(s)
Initial import.

1 james 16 /*
2     * main_gtk.c -- portable gui library, GTK
3     */
4    
5     #include "gui.h"
6    
7     /*wimp_t gui_wimp_task; /* wimp task handle */
8     /*os_error *gui_error; /* last error block pointer */
9     const char *gui_error_message; /* last error message */
10     int gui_error_line; /* last error line */
11     jmp_buf gui_error_jump; /* longjmp buffer for error handling */
12     bool quit = 0;
13    
14     char **gui_message;
15    
16     struct gui_window_data *gui_window_list; /* array of window details */
17     unsigned int gui_window_list_items; /* length of windows list */
18     signed int gui_window_origin_x, gui_window_origin_y;
19    
20     /* static void redraw_window_request(wimp_draw *redraw);
21     * static void open_window_request(wimp_open *open);
22     * static void close_window_request(wimp_close *close);
23     * static void mouse_click(wimp_pointer *pointer);
24     * static void key_pressed(wimp_key *key);
25     * static void menu_selection(wimp_selection *selection);
26     * static void user_message(wimp_message *message);
27     * static void help_request(wimp_message *message, help_message_request *request);
28     */
29    
30    
31     /****************************************************************************************/
32     /* main() */
33     /****************************************************************************************/
34    
35     int main(int argc, char *argv[])
36     {
37     gtk_set_locale();
38     gtk_init(&argc, &argv);
39    
40     gui_initialise();
41     task_initialise();
42    
43     gui_event_loop();
44    
45     task_finalise();
46    
47     gtk_exit(0);
48    
49     return 0;
50     }
51    
52    
53     /****************************************************************************************/
54     /* Initialisation */
55     /****************************************************************************************/
56    
57     /*
58     * gui_initialise -- initialise the program with the os or window manager
59     *
60     * => name -- program name to pass to the os if applicable
61     *
62     * <= nothing
63     */
64    
65     void gui_initialise()
66     {
67     char file_name[30];
68    
69     gui_log("gui_initialise: task_name = '%s'\n", task_name);
70    
71     if (setjmp(gui_error_jump))
72     {
73     gui_log("gui_initialise: *** error %i: %s ***\n", gui_error_line, gui_error_message);
74    
75     printf("%s (%i)\n", gui_error_message, gui_error_line);
76     fflush(stdout);
77     exit(1);
78     }
79    
80     gui_window_list = NULL;
81     gui_window_list_items = 0;
82    
83     sprintf(file_name, "%s_Messages", task_name);
84     gui_message = gui_messages_read(getenv(file_name));
85    
86     gui_log("gui_initialise: finished\n");
87     }
88    
89    
90     /****************************************************************************************/
91     /* Event handling */
92     /****************************************************************************************/
93    
94     /*
95     * gui_event_loop -- receive and handle os or window manager events
96     *
97     * => nothing
98     *
99     * <= does not return directly, except on exit
100     */
101    
102     static gui_window_id menu_window_id;
103    
104     void gui_event_loop(void)
105     {
106     /* if (setjmp(gui_error_jump))
107     * {
108     * gui_log("gui_event_loop: *** error %i: %s ***\n", gui_error_line, gui_error_message);
109     *
110     * err.errnum = 1;
111     * sprintf(err.errmess, "%s (%i)\n", gui_error_message, gui_error_line);
112     * xwimp_report_error(&err, wimp_ERROR_BOX_OK_ICON, task_name, NULL);
113     * }
114     */
115    
116     gtk_main();
117     }
118    
119    
120     /*
121     * redraw window request
122     */
123    
124     /* void redraw_window_request(wimp_draw *redraw)
125     * {
126     * bool more;
127     * signed int invalid[4];
128     * gui_window_id window_id = gui_handle_to_window_id(redraw->w);
129     *
130     * assert(window_id == gui_WINDOW_UNKNOWN ||
131     * (window_id < gui_window_list_items && gui_window_list[window_id].used));
132     *
133     * gui_error = xwimp_redraw_window(redraw, &more);
134     * gui_check_error();
135     *
136     * gui_window_origin_x = redraw->box.x0 - redraw->xscroll;
137     * gui_window_origin_y = redraw->box.y1 - redraw->yscroll;
138     *
139     * gui_log("gui_event_loop: redraw origin %i %i\n", gui_window_origin_x, gui_window_origin_y);
140     *
141     * while (more)
142     * {
143     * if (window_id != gui_WINDOW_UNKNOWN && gui_window_list[window_id].redraw_fn)
144     * {
145     * invalid[0] = redraw->clip.x0 - gui_window_origin_x;
146     * invalid[1] = gui_window_origin_y - redraw->clip.y1;
147     * invalid[2] = redraw->clip.x1 - gui_window_origin_x;
148     * invalid[3] = gui_window_origin_y - redraw->clip.y0;
149     *
150     * gui_log("gui_event_loop: redraw invalid %i %i %i %i\n",
151     * invalid[0], invalid[1], invalid[2], invalid[3]);
152     *
153     * gui_window_list[window_id].redraw_fn(window_id, invalid);
154     * }
155     * gui_error = xwimp_get_rectangle(redraw, &more);
156     * gui_check_error();
157     * }
158     * }
159     */
160    
161    
162     /*
163     * open window request
164     */
165    
166     /* void open_window_request(wimp_open *open)
167     * {
168     * gui_window_id window_id = gui_handle_to_window_id(open->w);
169     *
170     * gui_error = xwimp_open_window(open);
171     * gui_check_error();
172     *
173     * if (window_id != gui_WINDOW_UNKNOWN)
174     * {
175     * assert(window_id < gui_window_list_items && gui_window_list[window_id].used);
176     * if (open->visible.x1 - open->visible.x0 != gui_window_list[window_id].width ||
177     * open->visible.y1 - open->visible.y0 != gui_window_list[window_id].height)
178     * {
179     * gui_window_list[window_id].width = open->visible.x1 - open->visible.x0;
180     * gui_window_list[window_id].height = open->visible.y1 - open->visible.y0;
181     * if (gui_window_list[window_id].resize_fn)
182     * gui_window_list[window_id].resize_fn(window_id,
183     * gui_window_list[window_id].width, gui_window_list[window_id].height);
184     * }
185     * }
186     * }
187     */
188    
189    
190     /*
191     * close window request
192     */
193    
194     /* void close_window_request(wimp_close *close)
195     * {
196     * gui_window_id window_id = gui_handle_to_window_id(close->w);
197     *
198     * gui_log("gui_event_loop: window_id = 0x%x\n", window_id);
199     *
200     * if (window_id != gui_WINDOW_UNKNOWN)
201     * {
202     * assert(window_id < gui_window_list_items && gui_window_list[window_id].used);
203     * gui_window_list[window_id].close_fn(window_id);
204     * }
205     * }
206     */
207    
208    
209     /*
210     * mouse click
211     */
212    
213     /* void mouse_click(wimp_pointer *pointer)
214     * {
215     * gui_window_id window_id = gui_handle_to_window_id(pointer->w);
216     *
217     * gui_log("gui_event_loop: window_id = 0x%x\n", window_id);
218     *
219     * if (window_id != gui_WINDOW_UNKNOWN)
220     * {
221     * assert(window_id < gui_window_list_items && gui_window_list[window_id].used);
222     * if (gui_window_list[window_id].menu && (pointer->buttons & wimp_CLICK_MENU))
223     * {
224     * gui_error = xwimp_create_menu(gui_window_list[window_id].menu,
225     * pointer->pos.x - 64, pointer->pos.y);
226     * gui_check_error();
227     * menu_window_id = window_id;
228     * }
229     * else if (gui_window_list[window_id].click_fn)
230     * {
231     * unsigned int x, y, z;
232     * wimp_window_state state;
233     *
234     * state.w = pointer->w;
235     * gui_error = xwimp_get_window_state(&state);
236     * gui_check_error();
237     *
238     * x = pointer->pos.x - (state.visible.x0 - state.xscroll);
239     * y = (state.visible.y1 - state.yscroll) - pointer->pos.y;
240     * z = (pointer->buttons & wimp_CLICK_SELECT ? gui_CLICK :
241     * (pointer->buttons & wimp_CLICK_ADJUST ? gui_CLICK_RIGHT :
242     * (pointer->buttons & wimp_DRAG_SELECT ? gui_DRAG :
243     * (pointer->buttons & wimp_DRAG_ADJUST ? gui_DRAG_RIGHT : 0))));
244     * gui_window_list[window_id].click_fn(window_id, x, y, z);
245     * }
246     * }
247     * }
248     */
249    
250    
251     /*
252     * key pressed
253     */
254    
255     /* void key_pressed(wimp_key *key)
256     * {
257     * gui_window_id window_id = gui_handle_to_window_id(key->w);
258     *
259     * gui_log("gui_event_loop: window_id = 0x%x\n", window_id);
260     *
261     * if (window_id != gui_WINDOW_UNKNOWN)
262     * {
263     * assert(window_id < gui_window_list_items && gui_window_list[window_id].used);
264     *
265     * if ((key->c & (1<<31)) || (key->c < 256))
266     * {
267     * if (gui_window_list[window_id].input_fn)
268     * gui_window_list[window_id].input_fn(window_id, (wchar_t) (key->c & 0xffff));
269     * }
270     * else
271     * {
272     * if (gui_window_list[window_id].key_fn)
273     * gui_window_list[window_id].key_fn(window_id, (unsigned int) key->c);
274     * }
275     * }
276     * }
277     */
278    
279    
280     /*
281     * menu selection
282     */
283    
284     /* void menu_selection(wimp_selection *selection)
285     * {
286     * wimp_pointer pointer;
287     *
288     * gui_error = xwimp_get_pointer_info(&pointer);
289     * gui_check_error();
290     *
291     * gui_window_list[menu_window_id].menu_fn(menu_window_id, selection->items);
292     *
293     * if (pointer.buttons == wimp_CLICK_ADJUST)
294     * {
295     * gui_error = xwimp_create_menu(gui_window_list[menu_window_id].menu, 0, 0);
296     * gui_check_error();
297     * }
298     * }
299     */
300    
301    
302     /*
303     * user message, user message recorded
304     */
305    
306     /* void user_message(wimp_message *message)
307     * {
308     * gui_log("gui_event_loop: block.message.action = 0x%x\n", message->action);
309     *
310     * switch (message->action)
311     * {
312     * case message_QUIT:
313     * quit = 1;
314     * break;
315     * case message_HELP_REQUEST:
316     * help_request(message, (help_message_request *) &message->data);
317     * break;
318     * }
319     * }
320     */
321    
322     /*
323     * interactive help request
324     */
325    
326     /* void help_request(wimp_message *message, help_message_request *request)
327     * {
328     * const char *help;
329     * wimp_message reply;
330     * gui_window_id window_id = gui_handle_to_window_id(request->w);
331     *
332     * if (window_id != gui_WINDOW_UNKNOWN)
333     * {
334     * if (gui_window_list[window_id].used == DIALOG && request->i >= 0)
335     * help = gui_window_list[window_id].icon[request->i].help;
336     * else
337     * help = gui_window_list[window_id].help;
338     *
339     * gui_log(help);
340     * reply.size = (20 + strlen(help) + 3) & ~3;
341     * reply.your_ref = message->my_ref;
342     * reply.action = message_HELP_REPLY;
343     * strcpy(&reply.data.reserved, help);
344     * gui_error = xwimp_send_message(wimp_USER_MESSAGE, &reply, message->sender);
345     * gui_check_error();
346     * }
347     * }
348     */

  ViewVC Help
Powered by ViewVC 1.1.26