3 * Provides handling for list boxes
5 * v. 1.00 (27 July 1991)
7 * © 1991-1998 Straylight
10 /*----- Licensing note ----------------------------------------------------*
12 * This file is part of Straylight's Steel library.
14 * Steel is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * Steel is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Steel. If not, write to the Free Software Foundation,
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 * Abstract listbox handle
39 typedef struct list__liststr *list;
46 * An abstraction for list items
48 typedef struct list__item *list_item;
50 #define list_NOITEM ((list_item)0)
51 #define list_CLOSE ((list_item)-2)
52 #define list_HELP ((list_item)-3)
54 typedef void (*list_eventhandler)(list l,list_item item,void *handle);
55 typedef BOOL (*list_raweventhandler)(list l,wimp_eventstr *e,void *handle);
56 typedef void (*list_redrawhandler)(list l,
74 * void list_isPane(list l,pane p)
77 * This routine is part of the private interface between the listbox and
78 * pane segments. Do *NOT* try to call it in your own code.
81 void list_isPane(list l,pane p);
84 * list list_create(char *name,BOOL alterSize)
87 * Creates a new list box window, and returns a handle to it. Initially,
88 * there are no items, and the list box is not shown. The function returns
89 * 0 if the call fails for one reason or another (not enough windows or
93 * char *name == the name to match in the template file
94 * BOOL alterSize == TRUE if we are allowed to change the box's visible
98 * An abstract handle for the list box.
101 list list_create(char *name,BOOL alterSize);
104 * void list_selectItem(list l,list_item item)
107 * Makes the item the currently selected one.
110 * list l == the list handle
111 * list_item item == the item number
114 void list_selectItem(list l,list_item item);
117 * list_item list_selected(list l)
120 * Returns the currently selected item of the list.
123 * list l == the list handle
126 * The item number of the currently selected item.
129 list_item list_selected(list l);
132 * char *list_itemData(list l,list_item i)
135 * Returns the string for an item
138 * list l == the list handle
139 * list_item i == the item's handle
142 * A pointer to the item's data
145 char *list_itemData(list l,list_item i);
148 * list_item list_addItem(list l,char *data,BOOL inOrder)
151 * Adds a new piece of data into the list.
154 * list l == the list handle
155 * char *data == the data (as a char *, because most of the time you'll
156 * want to be using character strings).
159 * A handle for the list item.
162 list_item list_addItem(list l,char *data,BOOL inOrder);
165 * list_item list_findItem(list l,char *data)
168 * Searches through a list and returns the item number of the item whose
169 * data matches that given in the function.
172 * list l == the list handle
173 * char *data == the data to compare with
176 * The item number of the item, or list_NOITEM if no match.
179 list_item list_findItem(list l,char *data);
182 * void list_removeItem(list l,list_item i)
185 * Removes an item from the list.
188 * list l == the list's handle
189 * list_item i == the item number
192 void list_removeItem(list l,list_item i);
195 * void list_delete(list l)
198 * Destroys a list totally.
201 * list l == the list handle
204 void list_delete(list l);
207 * void list_updatePosition(list l)
210 * Writes the position of the listbox back into the template, so any new
211 * list boxes created from the template open at that position.
214 * list l == the list handle
217 void list_updatePosition(list l);
220 * BOOL list_link(list l)
223 * Links a list box to a WIMP window. If the list is already linked,
224 * nothing happens. The list box is not displayed.
227 * list l == the list handle
230 * TRUE if the link succeeded (may run out of windows!)
233 BOOL list_link(list l);
236 * void list_unlink(list l)
239 * Unlinks the list box from its window and deletes the window.
242 * list l == the list handle
245 void list_unlink(list l);
248 * void list_unlinkNoUpdate(list l)
251 * Unlinks a list from its window without storing its final position back
252 * in memory. Note that list_delete() calls list_unlink(), so make sure
253 * you call this routine before deleting the listbox it you want to prevent
254 * the position being written back.
257 * list l == the list handle
260 void list_unlinkNoUpdate(list l);
263 * void list_update(list l,BOOL really)
266 * Enables or disables list updating (i.e. whether the listbox resizes and
267 * redraws itself between every operation). If you're going to do some
268 * lengthy operation, it would be a good idea to turn update off first,
269 * and then turn it on again afterwards.
271 * Note that this is an all-or-nothing thing -- no counter is kept.
274 * list l == the listbox which we're messing about with
275 * BOOL really == whether to turn the update on or off
278 void list_update(list l,BOOL really);
281 * void list_display(list l)
284 * Displays a list box on-screen
290 void list_display(list l);
293 * void list_openDisplaced(list l)
296 * Opens the listbox on-screen displaced from its previous position by
297 * the normal 48 OS units. It must be unlinked using list_unlinkNoUpdate()
301 * list l == the list handle.
304 void list_openDisplaced(list l);
307 * void list_hide(list l)
310 * Stops the list box being displayed
313 * list l == the list handle
316 void list_hide(list l);
319 * wimp_w list_syshandle(list l)
322 * Returns the WIMP window handle being used for the list box.
328 * The window handle (a wimp_w).
331 wimp_w list_syshandle(list l);
335 * void list_eventHandler(list l,list_eventhandler proc,void *handle)
338 * Attaches an event handler to the list box. Most won't actually need
339 * this, just the stand-alone ones, or ones that do clever-dick things.
342 * list l == the list handle
343 * list_eventhandler proc == the procedure to handle events
344 * void *handle == the jolly olde pointer to the user-defined data
347 void list_eventHandler(list l,list_eventhandler proc,void *handle);
350 * void list_rawEventHandler(list l,list_raweventhandler proc,void *handle)
353 * Attaches the raw event handler procedure to the list box. You can then
354 * vet any events coming into the list box and have your wicked way with
358 * list l == the list handle
359 * list_raweventhandler proc == the raw event handler routine
360 * void *handle == the (now-famous) caller defined handle.
363 void list_rawEventHandler(list l,list_raweventhandler proc,void *handle);
366 * void list_redrawHandler(list l,list_redrawhandler rdr,void *handle)
369 * Attaches a replacement redraw handler to the list box. The new handler
370 * redraws individual items in the list. It must fill in the box it is
371 * passed, because the WIMP does not fill in the background. The part of
372 * the list box not populated by items is filled in the window background
373 * colour automatically. Using this, you can achieve quite a pleasing
374 * effect by making the background grey (colour 1) and the actual item
375 * backgrounds white (colour 0), indicating clearly the bottom of the list.
377 * You can also implement other things like items being shaded etc.
380 * list l == the list to which the redraw handler is to be attached
381 * list_redrawhandler == the replacement redraw routine (or 0 to cancel)
382 * void *handle == a pointer to pass the redraw routine
385 void list_redrawHandler(list l,list_redrawhandler rdr,void *handle);
388 * void list_widthAdd(list l,int extra)
391 * Since redraw handlers can basically do whatever they want to for each
392 * items, the list manager no longer really has any idea about how wide an
393 * item is. Since the main thing displayed in lists is text, it is assumed
394 * that the width of an item is the width of the longest piece of text plus
395 * a constant (e.g. for a sprite on the side). If this is not so, I'll
396 * have to rethink this bit...
399 * list l == the list we're setting the width of
400 * int extra == the constant to add to each item
403 void list_widthAdd(list l,int extra);
406 * void list_setItemHeight(list l,int height)
409 * Sets the height of items in the specified list box. By default, the
410 * height is 44 OS units (the height of menu items). This should be
411 * sufficient for most purposes.
414 * list l == the list to set
415 * int height == the new height of each item, in OS units
418 void list_setItemHeight(list l,int height);
421 * int list_items(list l)
424 * Informs the caller how many items there are in a list
427 * list l == the list handle
430 * The number of items in a list
433 int list_items(list l);
436 * void list_doForItems
439 * void (*proc)(list l,list_item i,void *handle),
444 * Performs an operation on all of the items in a list box.
447 * list l == the list handle
448 * void (*proc)(list l,list_item i,void *handle) == the procedure to use
449 * void *handle == a handle to pass to the procedure.
455 void (*proc)(list l,list_item i,void *handle),
460 * void list_attachData(list l,list_item i,void *data)
463 * Attaches a data structure to a list item. This is a bit of an
464 * afterthought really.
468 * list_item i == the list item
469 * void *data == a pointer to the data structure
472 void list_attachData(list l,list_item i,void *data);
475 * void *list_getData(list l,list_item i)
478 * Returns the data attached to a list item. The item number
479 * may have changed etc. with items deleted and added.
483 * list_item i == the list item number
486 * A pointer to the data structure attached using list_attachData().
489 void *list_getData(list l,list_item i);
492 * void list_multipleSelection(list l)
495 * Makes a list able to handle a multiple selection.
498 * list l == the list handle
501 void list_multipleSelection(list l);
504 * BOOL list_addToSelection(list l,list_item i,list_action a)
507 * Adds an item to the current selection.
511 * list_item i == the list item
512 * list_action a == what to do with the state
515 * The previous state of the item
518 BOOL list_addToSelection(list l,list_item i,list_action a);
521 * void list_doForSelected
524 * void (*proc)(list l,list_item i,void *handle),
529 * Performs a user-specified action for each selected list item.
532 * list l == the list box
533 * void (*proc)(list l,list_item i,void *handle) == the procedure to do the
535 * void *handle == a handle to pass to the routine.
538 void list_doForSelected
541 void (*proc)(list l,list_item i,void *handle),
547 * void list_selectAll(list l,list_action a)
550 * Selects all the items in a list.
554 * list_action a == what to do with the icons (list_READSTATE ain't all
555 * that useful, and list_TOGGLESTATE is downright wierd).
558 void list_selectAll(list l,list_action a);
561 * int list_numSelected(list l)
564 * Informs the caller how many items are selected.
567 * list l == the list handle
570 * An integer indicating the number of selected items
573 int list_numSelected(list l);
576 * int list_itemToIndex(list l,list_item i)
579 * Translates a list_item into the index of the item. This avoids
580 * assumptions about the mapping of indices to item numbers. In the
581 * future, for example, the list_item data type may be used as a pointer to
582 * the list item data structure in memory. Most of the time this will be
586 * list l == the list handle
587 * list_item i == the list item to translate
590 * An integer giving the index of the item. The first item has index 0, as
594 int list_itemToIndex(list l,list_item i);
597 * list_item list_indexToItem(list l,int index)
600 * Performs the reverse operation to the previous routine. It will
601 * translate an index to a list_item.
604 * list l == the list handle
605 * int index == the index of the item required
608 * The equivalent list_item for the item.
611 list_item list_indexToItem(list l,int index);
614 * list_item list_helpItem(list l)
617 * Returns the item that Help is interested in.
620 * list l == the list's handle
626 list_item list_helpItem(list l);