Initial revision
[ssr] / StraySrc / Libraries / Steel / h / win
CommitLineData
2ee739cc 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. *
6 * *
7 ***************************************************************************/
8
9/*----- Licensing note ----------------------------------------------------*
10 *
11 * This file is part of Straylight's Steel library.
12 *
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)
16 * any later version.
17 *
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.
22 *
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.
26 */
27
28/* Title: win.h
29 * Purpose: central management of RISC OS windows
30 *
31 */
32
33# ifndef __win_h
34# define __win_h
35
36# ifndef __wimp_h
37# include "wimp.h"
38# endif
39
40#ifndef BOOL
41#define BOOL int
42#define TRUE 1
43#define FALSE 0
44#endif
45
46
47/* This module constructs a very simple idea of "window class" within RISCOS.
48 * RISCOS window class implementations register the existence of each window
49 * with this module.
50 */
51
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.
56 */
57
58typedef void (*win_event_handler)(wimp_eventstr*, void *handle);
59
60typedef void (*win_idle_claimer)(void *handle);
61
62/* ************************** Claiming Events. *************************** */
63
64
65/* ------------------------- win_register_event_handler --------------------
66 * Description: Install an event handler function for a given window.
67 *
68 * Parameters: wimp_w -- the window's handle
69 * win_event_handler -- the event handler function
70 * void *handle -- caller-defined handle
71 * Returns: void.
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).
83 *
84 */
85
86#define win_ICONBAR (-3)
87#define win_ICONBARLOAD (-99)
88void win_register_event_handler(wimp_w, win_event_handler, void *handle);
89
90/* ------------------------- win_read_event_handler ------------------------
91 * Description: Read current event handler for a given window, and the
92 * handle which it is passed.
93 *
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
100 * handler.
101 *
102 */
103
104BOOL win_read_eventhandler(wimp_w w, win_event_handler *p, void **handle);
105
106/*
107 * void win_idleTime(int time)
108 *
109 * Use
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).
113 *
114 * Parameters
115 * int time == approximate time in centiseconds between idle claimer calls
116 */
117
118void win_idleTime(int time);
119
120/*
121 * void win_addIdleClaimer(win_idle_claimer proc,void *handle)
122 *
123 * Use
124 * Allows a list of idle event claimers to be set up, as opposed to just
125 * one.
126 *
127 * Parameters
128 * win_idle_claimer proc == the procedure to add
129 * int speed == requested number centiseconds between calls, or
130 * win_DONTCARE
131 * void *handle == the jolly old handle (again!)
132 */
133
134#define win_DONTCARE (-1)
135
136void win_addIdleClaimer(win_idle_claimer proc,int speed,void *handle);
137
138/*
139 * BOOL win_any_idles(void)
140 *
141 * Use
142 * Returns TRUE if there are any routines using the idle claimer system
143 */
144
145BOOL win_any_idles(void);
146
147/*
148 * void win_removeIdleClaimer(win_idle_claimer proc,void *handle)
149 *
150 * Use
151 * Removes a procedure from the list.
152 *
153 * Parameters
154 * win_idle_claimer proc == the procedure to remove
155 * void *handle == the procedure's handle
156 */
157
158void win_removeIdleClaimer(win_idle_claimer proc,void *handle);
159
160/* --- Macros for the old versions --- */
161
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)
164
165/* ------------------------- win_claim_idle_events -------------------------
166 * Description: Cause "idle" events to be delivered to a given window.
167 *
168 * Parameters: wimp_w -- the window's handle
169 * Returns: void.
170 * Other Info: To cancel this, call with window handle (wimp_w)-1.
171 *
172 */
173
174void win_claim_idle_events(wimp_w);
175
176
177
178typedef 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
181 event.
182*/
183
184
185/* --------------------- win_add_unknown_event_processor -------------------
186 * Description: Add a handler for unknown events onto the front of the
187 * queue of such handlers.
188 *
189 * Parameters: win_unknown_event_processor -- handler function
190 * void *handle -- passed to handler on call
191 * Returns: void.
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
208 * ignored.
209 *
210 */
211
212void win_add_unknown_event_processor(win_unknown_event_processor,
213 void *handle) ;
214
215
216/* ------------------ win_remove_unknown_event_processor -------------------
217 * Description: Removes the given unknown event handler with the given
218 * handle from the stack of handlers.
219 *
220 * Parameters: win_unknown_event_processor -- the handler to be removed
221 * void *handle -- its handle
222 * Returns: void.
223 * Other Info: The handler to be removed can be anyway in the stack
224 * (not necessarily at the top).
225 *
226 */
227
228void win_remove_unknown_event_processor(win_unknown_event_processor,
229 void *handle) ;
230
231
232/* ---------------------- win_idle_event_claimer ---------------------------
233 * Description: Informs caller of which window is claiming idle events.
234 *
235 * Parameters: void
236 * Returns: Handle of window claiming idle events.
237 * Other Info: Returns (wimp_w)-1, if no window is claiming idle events.
238 *
239 */
240
241wimp_w win_idle_event_claimer(void);
242
243
244/* ---------------------- win_claim_unknown_events -------------------------
245 * Description: Cause any unknown, or non-window-specific events to be
246 * delivered to a given window.
247 *
248 * Parameters: wimp_w -- handle of window to which unknown events should
249 * be delivered
250 * Returns: void.
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".
254 *
255 */
256
257void win_claim_unknown_events(wimp_w);
258
259
260/* ------------------------- win_unknown_event_claimer ---------------------
261 * Description: Informs caller of which window is claiming unknown events.
262 *
263 * Parameters: void
264 * Returns: Handle of window claiming unknown events.
265 * Other Info: Return of (wimp_w)-1 means no claimer registered.
266 *
267 */
268
269wimp_w win_unknown_event_claimer(void);
270
271
272
273/* ********************************* Menus. ****************************** */
274
275
276/* ---------------------------- win_setmenuh -------------------------------
277 * Description: Attaches the given menu structure to the given window
278 *
279 * Parameters: wimp_w -- handle of window
280 * void *handle -- pointer to menu structure
281 * Returns: void.
282 * Other Info: Mainly used by higher level RISC_OSlib routines to attach
283 * menus to windows (eg. event_attachmenu()).
284 *
285 */
286
287void win_setmenuh(wimp_w, void *handle);
288
289
290/* --------------------------- win_getmenuh --------------------------------
291 * Description: Returns a pointer to the menu structure attached to given
292 * window.
293 *
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()).
298 *
299 */
300
301void *win_getmenuh(wimp_w);
302
303
304/* ************************** Event Processing. ************************** */
305
306/*
307 * void win_broadcast(wimp_eventstr *e)
308 *
309 * Use
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.
315 *
316 * Parameters
317 * wimp_eventstr *e == the event to broadcast.
318 */
319
320void win_broadcast(wimp_eventstr *e);
321
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()).
326 *
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
333 * caret.
334 *
335 */
336
337BOOL win_processevent(wimp_eventstr*);
338
339
340/* ****************************** Termination. *************************** */
341
342
343/* --------------------------- win_activeinc -------------------------------
344 * Description: Increment by one the win module's idea of the number of
345 * active windows owned by a program.
346 *
347 * Parameters: void
348 * Returns: void.
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
356 * iconbar.
357 *
358 */
359
360void win_activeinc(void);
361
362
363/* ---------------------------- win_activedec ------------------------------
364 * Description: Decrements by one the win module's idea of the number of
365 * active windows owned by a program.
366 *
367 * Parameters: void
368 * Returns: void.
369 * Other Info: See note in win_activeinc() regarding program termination.
370 *
371 */
372
373void win_activedec(void);
374
375
376/* ---------------------------- win_activeno -------------------------------
377 * Description: Informs the caller of the number of active windows owned
378 * by your program.
379 *
380 * Parameters: void
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().
386 *
387 */
388
389int win_activeno(void);
390
391
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
395 * program).
396 *
397 * Parameters: void
398 * Returns: void.
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
403 * like: while (TRUE)
404 * event_process();
405 *
406 */
407
408void win_give_away_caret(void);
409
410/* ------------------------------ win_settitle -----------------------------
411 * Description: changes the title displayed in a given window
412 *
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
417 *
418 * Returns: void.
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);
427 *
428 */
429
430void win_settitle(wimp_w w, char *newtitle,...);
431
432/*
433 * void win_gadgetWidths(wimp_wflags f,wimp_box *b)
434 *
435 * Use
436 * Returns a box giving the width of the system area around a window with
437 * window flags f.
438 */
439
440void win_gadgetWidths(wimp_wflags f,wimp_box *b);
441
442/*
443 * void win_adjustBox(wimp_openstr *o)
444 *
445 * Use
446 * Adjusts a window so that it fits on the screen.
447 *
448 * Parameters
449 * wimp_openstr *o == pointer to the block to fiddle
450 */
451
452void win_adjustBox(wimp_openstr *o);
453
454/*
455 * BOOL win_anyWindows(void)
456 *
457 * Use
458 * Informs the caller if there are any windows left.
459 *
460 * Returns
461 * TRUE if there are
462 */
463
464BOOL win_anyWindows(void);
465
466
467
468#endif
469
470/* end win.h */