1 /****************************************************************************
2 * This source file was written by Acorn Computers Limited. It is part of *
3 * the RISCOS library for writing applications in C for RISC OS. It may be *
4 * used freely in the creation of programs for Archimedes. It should be *
5 * used with Acorn's C Compiler Release 3 or later. *
7 ***************************************************************************/
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Steel library.
13 * Steel is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Steel is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with Steel. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 * Purpose: central management of RISC OS windows
47 /* This module constructs a very simple idea of "window class" within RISCOS.
48 * RISCOS window class implementations register the existence of each window
52 /* This structure allows event-processing loops to be constructed that
53 * have no knowledge of what other modules are present in the program.
54 * For instance, the dialogue box module can contain an event-processing loop
55 * without reference to what other window types are present in the program.
58 typedef void (*win_event_handler)(wimp_eventstr*, void *handle);
60 typedef void (*win_idle_claimer)(void *handle);
62 /* ************************** Claiming Events. *************************** */
65 /* ------------------------- win_register_event_handler --------------------
66 * Description: Install an event handler function for a given window.
68 * Parameters: wimp_w -- the window's handle
69 * win_event_handler -- the event handler function
70 * void *handle -- caller-defined handle
72 * Other Info: This call has no effect on the window itself -- it just
73 * informs the win module that the supplied function should
74 * be called when events are delivered to the window.
75 * To remove a handler, call with a null function pointer,
76 * ie. win_register_event_handler(w,(win_event_handler)0,0)
77 * To catch key events for an icon on the icon bar register
78 * a handler for win_ICONBAR,
79 * ie. win_event_handler(win_ICONBAR, handler_func, handle)
80 * To catch load event for an icon on the icon bar register
81 * a handler for win_ICONBARLOAD,
82 * ie. win_event_handler(win_ICONBARLOAD, load_func, handle).
86 #define win_ICONBAR (-3)
87 #define win_ICONBARLOAD (-99)
88 void win_register_event_handler(wimp_w, win_event_handler, void *handle);
90 /* ------------------------- win_read_event_handler ------------------------
91 * Description: Read current event handler for a given window, and the
92 * handle which it is passed.
94 * Parameters: wimp_w w -- the window's handle
95 * win_event_handler *p -- the handler function
96 * void **handle -- the handle passed to the handler function
97 * Returns: TRUE if given window is registered, FALSE otherwise
98 * Other Info: This is useful for registering an alternative event handler
99 * which can vet events, before passing them on to the original
104 BOOL win_read_eventhandler(wimp_w w, win_event_handler *p, void **handle);
107 * void win_idleTime(int time)
110 * Sets the approximate time requested between calls of idle claimer
111 * routines. The actual time may be more (e.g. if other tasks are busy) or
112 * less (if idle claimers with a lower time are specified).
115 * int time == approximate time in centiseconds between idle claimer calls
118 void win_idleTime(int time);
121 * void win_addIdleClaimer(win_idle_claimer proc,void *handle)
124 * Allows a list of idle event claimers to be set up, as opposed to just
128 * win_idle_claimer proc == the procedure to add
129 * int speed == requested number centiseconds between calls, or
131 * void *handle == the jolly old handle (again!)
134 #define win_DONTCARE (-1)
136 void win_addIdleClaimer(win_idle_claimer proc,int speed,void *handle);
139 * BOOL win_any_idles(void)
142 * Returns TRUE if there are any routines using the idle claimer system
145 BOOL win_any_idles(void);
148 * void win_removeIdleClaimer(win_idle_claimer proc,void *handle)
151 * Removes a procedure from the list.
154 * win_idle_claimer proc == the procedure to remove
155 * void *handle == the procedure's handle
158 void win_removeIdleClaimer(win_idle_claimer proc,void *handle);
160 /* --- Macros for the old versions --- */
162 #define win_add_idle_claimer(p,h) win_addIdleClaimer(p,win_DONTCARE,h)
163 #define win_remove_idle_claimer(p,h) win_removeIdleClaimer(p,h)
165 /* ------------------------- win_claim_idle_events -------------------------
166 * Description: Cause "idle" events to be delivered to a given window.
168 * Parameters: wimp_w -- the window's handle
170 * Other Info: To cancel this, call with window handle (wimp_w)-1.
174 void win_claim_idle_events(wimp_w);
178 typedef BOOL (*win_unknown_event_processor)(wimp_eventstr*, void *handle);
179 /* You can ask to vet unknown events, before they are passed to the default
180 unknown event handler. These procs return TRUE if they have dealt with the
185 /* --------------------- win_add_unknown_event_processor -------------------
186 * Description: Add a handler for unknown events onto the front of the
187 * queue of such handlers.
189 * Parameters: win_unknown_event_processor -- handler function
190 * void *handle -- passed to handler on call
192 * Other Info: The win module maintains a list of unknown event handlers.
193 * An unknown event results in the "head of the list" function
194 * being called; if this function doesn't deal with the event
195 * it is passed on to the next in the list, and so on.
196 * Handler functios should return a Boolean result to show
197 * if they dealt with the event, or if it should be passed on.
198 * "Known" events are as follows:
199 * ENULL, EREDRAW, ECLOSE, EOPEN, EPTRLEAVE,
200 * EPTRENTER, EKEY, ESCROLL, EBUT
201 * and ESEND/ESENDWANTACK for the following msg types
202 * MCLOSEDOWN, MDATASAVE, MDATALOAD, MHELPREQUEST
203 * All other events are considered "unknown"
204 * Note: if none of the unknown event handlers deals with the
205 * event, then it is passed on to the unknown event claiming
206 * window (registered by win_claim_unknown_events()). If
207 * there is no such claimer, then the unknown event is
212 void win_add_unknown_event_processor(win_unknown_event_processor,
216 /* ------------------ win_remove_unknown_event_processor -------------------
217 * Description: Removes the given unknown event handler with the given
218 * handle from the stack of handlers.
220 * Parameters: win_unknown_event_processor -- the handler to be removed
221 * void *handle -- its handle
223 * Other Info: The handler to be removed can be anyway in the stack
224 * (not necessarily at the top).
228 void win_remove_unknown_event_processor(win_unknown_event_processor,
232 /* ---------------------- win_idle_event_claimer ---------------------------
233 * Description: Informs caller of which window is claiming idle events.
236 * Returns: Handle of window claiming idle events.
237 * Other Info: Returns (wimp_w)-1, if no window is claiming idle events.
241 wimp_w win_idle_event_claimer(void);
244 /* ---------------------- win_claim_unknown_events -------------------------
245 * Description: Cause any unknown, or non-window-specific events to be
246 * delivered to a given window.
248 * Parameters: wimp_w -- handle of window to which unknown events should
251 * Other Info: Calling with (wimp_w)-1 cancels this
252 * See win_add_unknown_event_processor() for details of which
253 * events are "known".
257 void win_claim_unknown_events(wimp_w);
260 /* ------------------------- win_unknown_event_claimer ---------------------
261 * Description: Informs caller of which window is claiming unknown events.
264 * Returns: Handle of window claiming unknown events.
265 * Other Info: Return of (wimp_w)-1 means no claimer registered.
269 wimp_w win_unknown_event_claimer(void);
273 /* ********************************* Menus. ****************************** */
276 /* ---------------------------- win_setmenuh -------------------------------
277 * Description: Attaches the given menu structure to the given window
279 * Parameters: wimp_w -- handle of window
280 * void *handle -- pointer to menu structure
282 * Other Info: Mainly used by higher level RISC_OSlib routines to attach
283 * menus to windows (eg. event_attachmenu()).
287 void win_setmenuh(wimp_w, void *handle);
290 /* --------------------------- win_getmenuh --------------------------------
291 * Description: Returns a pointer to the menu structure attached to given
294 * Parameters: wimp_w -- handle of window
295 * Returns: pointer to the attached menu (0 if no menu attached).
296 * Other Info: As for win_setmenuh(), this is used mainly by higher level
297 * RISC_OSlib routines (eg. event_attachmenu()).
301 void *win_getmenuh(wimp_w);
304 /* ************************** Event Processing. ************************** */
307 * void win_broadcast(wimp_eventstr *e)
310 * Broadcasts the given event to ALL windows currently active. Note: this
311 * works in a similar way to module service calls - a broadcast can be
312 * 'claimed' by changing it to a null event. This is most useful for
313 * informing other windows about events (such as a parent window being
314 * closed), and thus message broadcasts should be used.
317 * wimp_eventstr *e == the event to broadcast.
320 void win_broadcast(wimp_eventstr *e);
322 /* -------------------------- win_processevent -----------------------------
323 * Description: Delivers an event to its relevant window, if such a window
324 * has been registered with this module (via
325 * win_register_event_handler()).
327 * Parameters: wimp_eventstr* -- pointer to the event which has occurred
328 * Returns: true if an event handler (registered with this module)
329 * has dealt with the event, false otherwise.
330 * Other Info: the main client for this routine is event_process(), which
331 * uses it to deliver an event to its appropriate window.
332 * Keyboard events are delivered to the current owner of the
337 BOOL win_processevent(wimp_eventstr*);
340 /* ****************************** Termination. *************************** */
343 /* --------------------------- win_activeinc -------------------------------
344 * Description: Increment by one the win module's idea of the number of
345 * active windows owned by a program.
349 * Other Info: Note: event_process() calls exit() on behalf of the program
350 * when the number of active windows reaches zero
351 * Programs which wish to remain running even when they have
352 * no active windows, should ensure that win_activeinc() is
353 * called once before creating any windows, so that the no.
354 * of active windows is always >= 1. This is done for you
355 * if you use baricon() to install your program's icon on the
360 void win_activeinc(void);
363 /* ---------------------------- win_activedec ------------------------------
364 * Description: Decrements by one the win module's idea of the number of
365 * active windows owned by a program.
369 * Other Info: See note in win_activeinc() regarding program termination.
373 void win_activedec(void);
376 /* ---------------------------- win_activeno -------------------------------
377 * Description: Informs the caller of the number of active windows owned
381 * Returns: no. of active windows owned by program.
382 * Other Info: This is given by (no. of calls to win_activeinc()) minus
383 * (no. of calls to win_activedec())
384 * Note that modules in RISCOSlib itself may have made calls
385 * to win_activeinc() and win_activedec().
389 int win_activeno(void);
392 /* -------------------------- win_give_away_caret --------------------------
393 * Description: gives the caret away to the open window at the top of the
394 * WIMP's window stack (if that window is owned by your
399 * Other Info: If the top window is interested it will take the caret
400 * If not then nothing happens.
401 * Note: only works if polling is done using the wimpt module,
402 * which is the case if your main inner loop goes something
408 void win_give_away_caret(void);
410 /* ------------------------------ win_settitle -----------------------------
411 * Description: changes the title displayed in a given window
413 * Parameters: wimp_w w -- given window's handle
414 * char *newtitle -- null-terminated printf-type string
415 * giving new title for window
416 * ... -- more parameters
419 * Other Info: The title icon of the given window must be indirected text
420 * This will change the title used by all windows created
421 * from the given window's template if you have used the
422 * template module (since the Window manager uses your address
423 * space to hold indirected text icons). To avoid this the
424 * window can be created from a copy of the template, ie.
425 * template *t = template_copy(template_find("name"));
426 * wimp_create_wind(t->window, &w);
430 void win_settitle(wimp_w w, char *newtitle,...);
433 * void win_gadgetWidths(wimp_wflags f,wimp_box *b)
436 * Returns a box giving the width of the system area around a window with
440 void win_gadgetWidths(wimp_wflags f,wimp_box *b);
443 * void win_adjustBox(wimp_openstr *o)
446 * Adjusts a window so that it fits on the screen.
449 * wimp_openstr *o == pointer to the block to fiddle
452 void win_adjustBox(wimp_openstr *o);
455 * BOOL win_anyWindows(void)
458 * Informs the caller if there are any windows left.
464 BOOL win_anyWindows(void);