chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Steel / h / viewer
1 /*
2  * viewer
3  *  Allows creation of Filer-like windows which rearrange themselves.
4  *
5  * v. 1.00 (13 August 1991)
6  *
7  * © 1991-1998 Straylight
8  */
9
10 /*----- Licensing note ----------------------------------------------------*
11  *
12  * This file is part of Straylight's Steel library.
13  *
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)
17  * any later version.
18  *
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.
23  *
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.
27  */
28
29 #ifndef __viewer_h
30 #define __viewer_h
31
32 #ifndef __wimp_h
33 #include "wimp.h"
34 #endif
35
36 #ifndef __sprite_h
37 #include "sprite.h"
38 #endif
39
40 #ifndef __menu_h
41 #include "menu.h"
42 #endif
43
44 /*
45  * The handle types for the viewer segment
46  */
47 typedef struct viewer__viewerstr *viewer;
48 typedef struct viewer__iconstr *viewer_icon;
49
50 /*
51  * Event handler types
52  *
53  * The whole viewer can have a caller-defined handle, and each icon in it
54  * also has one.  The standard event handler gets both.  If no ico was 
55  * clicked, the icon handle is 0.  You should have a handle to your viewer 
56  * global data in the icon structure.  The raw event handler passes only the
57  * global handle.
58  */
59
60 typedef void (*viewer_eventhandler)
61 (
62   viewer v,
63   viewer_icon i,
64   wimp_bbits b,
65   void *vhandle,
66   void *ihandle
67 );
68
69 typedef BOOL (*viewer_raweventhandler)
70 (
71   viewer v,
72   wimp_eventstr *e,
73   void *handle
74 );
75
76 typedef void (*viewer_redrawhandler)
77 (
78   viewer_icon i,
79   wimp_redrawstr *r,
80   wimp_box *box,
81   char *text,
82   char *sprite,
83   BOOL selected,
84   void *handle
85 );
86
87 /*
88  * Types for data export.
89  */
90
91 typedef BOOL (*viewer_saveproc)(viewer_icon i,char *filename, void *handle);
92 typedef BOOL (*viewer_sendproc)(viewer_icon i,void *handle, int *maxbuf);
93 typedef int (*viewer_printproc)(viewer_icon i,char *filename, void *handle);
94
95 /*
96  * For sorting icons
97  */
98
99 typedef int (*viewer_compare)(void *a,void *b);
100
101 /*
102  * A macro for telling the event handler about a close event.  I know it's 
103  * not the same, but...
104  */
105 #define viewer_CLOSE ((viewer_icon)-1)
106
107 /*
108  * A macro for telling the event handler about a help request
109  */
110 #define viewer_HELP ((viewer_icon)-2)
111
112 /*
113  * A macro representing no icon being clicked.
114  */
115 #define viewer_NOICON ((viewer_icon)0)
116
117 /*
118  * void viewer_drawFileIcons
119  * (
120  *   viewer_icon icn,
121  *   wimp_redrawstr *r,
122  *   wimp_box *box,
123  *   char *text,
124  *   char *sprite,
125  *   BOOL selected,
126  *   void *handle
127  * )
128  *
129  * Use
130  *  Redraw handler which takes into account filetypes of icons.  The icons
131  *  automatically get new sprites if the sprites for their filetypes change.
132  *  For applications, the text is considered to be a filename.  Register
133  *  this function using viewer_redrawHandler().
134  *
135  * Parameters
136  *  viewer_icon icn == the icon to paint
137  *  wimp_redrawstr *r == information about this redraw
138  *  wimp_box *box == the box to draw the icon in
139  *  char *text == the text to display
140  *  char *sprite == the sprite to display
141  *  BOOL selected == is the icon selected?
142  *  void *handle == a caller defined handle (ignored)
143  */
144
145 void viewer_drawFileIcons
146 (
147   viewer_icon icn,
148   wimp_redrawstr *r,
149   wimp_box *box,
150   char *text,
151   char *sprite,
152   BOOL selected,
153   void *handle
154 );
155
156 /*
157  * viewer viewer_create
158  * (
159  *   int x,
160  *   int y,
161  *   int width,
162  *   int height,
163  *   sprite_area *spr,
164  *   char *title,
165  *   char *banner
166  * )
167  *
168  * Use
169  *  Creates a viewer window.  Note that viewer windows don't need templates,
170  *  and don't contain real wimp icons, just yer normal redrawn-by-
171  *  application things (which can be handled by a caller-defined function if
172  *  necessary).  The banner along the top is optional - if a null pointer is
173  *  passed, no banner is included.  The sprite area passed applies to all
174  *  the icons in the window, although if  you want to, you can use your own
175  *  redraw routine to handle different sprite areas for them.
176  *
177  * Parameters
178  *  int x,int y == the coordinates of the top-left corner of the window
179  *    (file windows for editors need good positioning here).
180  *  int width == the width of an icon
181  *  int height == the height of an icon
182  *  sprite_area *spr == the sprite area for the window
183  *  char *title == the title of the window
184  *  char *banner == the banner heading along the top (like 'Sprite file
185  *    window' or something)
186  *
187  * Returns
188  *  A handle to the viewer window.  As usual, a NULL pointer indicates
189  *   something went wrong.
190  */
191
192 viewer viewer_create
193 (
194   int x,
195   int y,
196   int width,
197   int height,
198   sprite_area *spr,
199   char *title,
200   char *banner
201 );
202
203 /*
204  * void viewer_display(viewer v)
205  *
206  * Use
207  *  Displays a viewer on the screen.
208  *
209  * Parameters
210  *  viewer v == the viewer handle
211  */
212
213 void viewer_display(viewer v);
214
215 /*
216  * void viewer_hide(viewer v)
217  *
218  * Use
219  *  Hides an open viewer.
220  *
221  * Parameters
222  *  viewer v == the handle
223  */
224
225 void viewer_hide(viewer v);
226
227 /*
228  * void viewer_delete(viewer v,void (*freeProc)(void *handle))
229  *
230  * Use
231  *  Zaps a viewer and everything in it.  The function you pass to this
232  *  routine is called with every icon handle the viewer has associated with
233  *  it, so you don't need to link all the structures together - I've already
234  *  done that here!
235  *
236  * Parameters
237  *  viewer v == the viewer to destroy
238  *  void (*freeProc)(void *handle) == a function to free one of the caller-
239  *    defined viewer icon structures.
240  */
241
242 void viewer_delete(viewer v,void (*freeProc)(void *handle));
243
244 /*
245  * void viewer_eventHandler(viewer v,viewer_eventhandler proc,void *handle)
246  *
247  * Use
248  *  Attaches an event handler to the viewer.  The handle passed to this
249  *  function is only used for close events, so you can take appropriate
250  *  action at the other end.  Otherwise, the handle for the icon concerned
251  *  is used.  Suggested code:
252  *
253  * void user_viewer(viewer v,viewer_icon i,wimp_bbits b,void *handle)
254  * {
255  *   user_fileStructure *file=(user_fileStructure *)handle;
256  *   user_itemStructure *item=(user_itemStructure *)handle;
257  *   switch ((int)i)
258  *   {
259  *     case (int)viewer_CLOSE:
260  *       ... use 'file' for this bit of code ...
261  *       break;
262  *     case viewer_NOICON:
263  *       ... use 'file' for this bit as well ...
264  *       break;
265  *     default:
266  *       ... use 'item' for this bit of code ...
267  *       break;
268  *   }  
269  * }
270  *
271  * Parameters
272  *  viewer v == the viewer to attach the handler to
273  *  viewer_eventhandler proc == the event handler
274  *  void *handle == the handle
275  */
276
277 void viewer_eventHandler(viewer v,viewer_eventhandler proc,void *handle);
278
279 /*
280  * void viewer_rawEventHandler
281  * (
282  *   viewer v,
283  *   viewer_raweventhandler proc,
284  *   void *handle
285  * )
286  *
287  * Use
288  *  Attaches a raw event handler to a viewer.  Same as always, this one.
289  *
290  * Parameters
291  *  viewer v == the viewer handle
292  *  viewer_raweventhandler proc == the handler routine
293  *  void *handle == the handle for the user's data
294  */
295
296 void viewer_rawEventHandler
297 (
298   viewer v,
299   viewer_raweventhandler proc,
300   void *handle
301 );
302
303 /*
304  * void viewer_redrawHandler(viewer v,viewer_redrawhandler proc,void *handle)
305  *
306  * Use
307  *  Adds in a user-defined routine for redrawing icons in the window.
308  *
309  * Parameters
310  *  viewer v == the viewer handle
311  *  viewer_redrawhandler proc == the routine for doing the redraw
312  *  void *handle == a handle to be passed to the routine (a sprite area or
313  *    something)
314  */
315
316 void viewer_redrawHandler(viewer v,viewer_redrawhandler proc,void *handle);
317
318 /*
319  * void viewer_setIconSize(viewer v,int width,int height)
320  *
321  * Use
322  *  Sets a new icon size for the viewer.  This would normally be
323  *  accompanied by a chnge in redraw handler.  It would be used e.g. when
324  *  using a menu option giving a choice between 'Large icons' and 'Small
325  *  icons'.
326  *
327  * Parameters
328  *  viewer v == the viewer which is to receive this change
329  *  int width == the new width
330  *  int height == the new height
331  */
332  
333 void viewer_setIconSize(viewer v,int width,int height);
334
335 /*
336  * void viewer_setCompare(viewer v,viewer_compare cmp)
337  *
338  * Use
339  *  Registers a compare function for the viewer specified.  The function
340  *  is passed the caller-defined handles of two icons.  The function must
341  *  return <0 if a<b, >0 if a>b, or ==0 if a==b (like strcmp does).  The
342  *  viewer's icons are then resorted.  Pass 0 to use the default sorting
343  *  system (a caseless compare on the icon text)
344  *
345  * Parameters
346  *  viewer v == the viewer we're going to set the comparer up for
347  *  viewer_compare cmp == the function to do comparing
348  */
349
350 void viewer_setCompare(viewer v,viewer_compare cmp);
351
352 /*
353  * viewer_icon viewer_addIcon
354  * (
355  *   viewer v,
356  *   char *text,
357  *   char *sprite,
358  *   BOOL inOrder,
359  *   void *handle
360  * )
361  *
362  * Use
363  *  Adds a new icon to a viewer window.  
364  *
365  * Parameters
366  *  viewer v == the handle of the viewer to use.
367  *  char *text == the text to put under the icon (may be null)
368  *  char *sprite == the sprite to use (may be null)
369  *  BOOL inOrder == whether you want the icons sorted into order according
370  *   to the text fields
371  *  void *handle == the handle you want to pass to the event handler routine
372  *
373  * Returns
374  *  A handle to the icon.  If this is NULL, something went majorly wrong 
375  *  (sorry, John)
376  */
377
378 viewer_icon viewer_addIcon
379 (
380   viewer v,
381   char *text,
382   char *sprite,
383   BOOL inOrder,
384   void *handle
385 );
386
387 /*
388  * void viewer_setFiletype(viewer_icon i,int type)
389  *
390  * Use
391  *  Sets the filetype of the icon - useful for bins and things.  This
392  *  filetype overrides the setting given to viewer_exportSelected().  It can
393  *  also be used to display the correct icon in the viewer by changing the
394  *  redraw handler to viewer_drawFileIcons().
395  *
396  * Parameters
397  *  viewer_icon i == the icon to change
398  *  int type == the filetype to give it (any valid WIMP filetype will do)
399  */
400
401 void viewer_setFiletype(viewer_icon i,int type);
402
403 /*
404  * int viewer_readFiletype(viewer_icon i)
405  *
406  * Use
407  *  Returns the filetype attached to an icon.
408  *
409  * Parameters
410  *  viewer_icon i == the icon handle
411  *
412  * Returns
413  *  The type attached using viewer_setFiletype(), or -1 if none.
414  */
415
416 int viewer_readFiletype(viewer_icon i);
417
418 /*
419  * viewer_icon viewer_findIcon(viewer v,char *text)
420  *
421  * Use
422  *  Searches through a viewer to find an icon with the same text as 'text'.
423  *  The search is case-insensitive.
424  *
425  * Parameters
426  *  viewer v == the viewer handle
427  *  char *text == text to search for
428  *
429  * Returns
430  *  The icon handle, or viewer_NOICON if unsuccessful.
431  */
432
433 viewer_icon viewer_findIcon(viewer v,char *text);
434
435 /*
436  * void viewer_removeIcon(viewer_icon i)
437  *
438  * Use
439  *  Removes the icon specified.  This routine is real easy!
440  *
441  * Parameters
442  *  viewer_icon i == the icon to remove (they ALL have unique handles, so
443  *    this is OK)
444  */
445
446 void viewer_removeIcon(viewer_icon i);
447
448 /*
449  * wimp_w viewer_syshandle(viewer v)
450  *
451  * Use
452  *  Returns the WIMP window handle used for the viewer (and much use may it
453  *  do you!)
454  *
455  * Parameters
456  *  viewer v == the viewer handle
457  *
458  * Returns
459  *  The wimp_w window handle
460  */
461
462 wimp_w viewer_syshandle(viewer v);
463
464 /*
465  * viewer_icon viewer_iconFromCoords(viewer v,int x,int y)
466  *
467  * Use
468  *  Given a set of (absolute) coordinates, this returns the icon in the
469  *  viewer specified that the point is on.  This is mainly useful for menu 
470  *  maker routines, which will want to be able to select items and so on.
471  *
472  * Parameters
473  *  viewer v == the viewer handle
474  *  int x == the x-coordinate of the point
475  *  int y == the y-coordinate of the point
476  *
477  * Returns
478  *  The icon handle, or viewer__NOICON if there isn't one.
479  */
480
481 viewer_icon viewer_iconFromCoords(viewer v,int x,int y);
482
483 /*
484  * void viewer_iconToCoords(viewer_icon i,wimp_box *box)
485  *
486  * Use
487  *  Calculates the bounding box of the icon given.  If there is an error,
488  *  nothing is written in the block.
489  *
490  * Parameters
491  *  viewer_icon i == the icon we're interested in
492  *  wimp_box *box == where to store the coordinates
493  */
494
495 void viewer_iconToCoords(viewer_icon i,wimp_box *box);
496
497 /*
498  * BOOL viewer_isSelected(viewer_icon i)
499  *
500  * Use
501  *  Returns whether an icon is selected or not.
502  *
503  * Parameters
504  *  viewer_icon i == the icon handle
505  *
506  * Returns
507  *  TRUE if the icon is selected, or FALSE otherwise.
508  */
509
510 BOOL viewer_isSelected(viewer_icon i);
511
512 /*
513  * void viewer_selectIcon(viewer_icon i,BOOL onOrOff)
514  *
515  * Use
516  *  Selects or deselects the icon specified.
517  *
518  * Parameters
519  *  viewer_icon i == the icon handle
520  *  BOOL onOrOff == TRUE to select, FALSE to deselect
521  */
522
523 void viewer_selectIcon(viewer_icon i,BOOL onOrOff);
524
525 /*
526  * viewer viewer_iconToViewer(viewer_icon i)
527  * 
528  * Use
529  *  Returns the viewer in which an icon is contained.
530  *
531  * Parameters
532  *  viewer_icon i == the icon handle
533  *
534  * Returns
535  *  The viewer handle.
536  */
537
538 viewer viewer_iconToViewer(viewer_icon i);
539
540 /*
541  * void *viewer_iconHandle(viewer_icon i)
542  *
543  * Use
544  *  Returns the handle attached to the icon when it was created
545  *
546  * Parameters
547  *  viewer_icon i == the icon in question
548  *
549  * Returns
550  *  The handle attached
551  */
552
553 void *viewer_iconHandle(viewer_icon i);
554
555 /*
556  * char *viewer_textOfIcon(viewer_icon i)
557  *
558  * Use
559  *  Returns the text of the icon given.
560  *
561  * Parameters
562  *  viewer_icon i == the icon
563  *
564  * Returns
565  *  Pointer to the string (read only!).
566  */
567
568 char *viewer_textOfIcon(viewer_icon i);
569
570 /*
571  * int viewer_selected(viewer v)
572  *
573  * Use
574  *  Informs caller how many icons are selected.
575  *
576  * Parameters
577  *  viewer v == the viewer handle
578  *
579  * Returns
580  *  The number of icons selected.
581  */
582
583 int viewer_selected(viewer v);
584
585 /*
586  * int viewer_icons(viewer v)
587  *
588  * Use
589  *  Returns the number of icons in a viewer.
590  *
591  * Parameters
592  *  viewer v == the viewer
593  *
594  * Returns
595  *  The number of icons.
596  */
597
598 int viewer_icons(viewer v);
599
600 /*
601  * void viewer_doForIcons
602  * (
603  *   viewer v,
604  *   BOOL onlySelected,
605  *   void (*proc)(viewer_icon i,void *handle)
606  * )
607  *
608  * Use
609  *  Does the same thing for either all the icons in a viewer, or just the
610  *  selected ones.
611  *
612  * Parameters
613  *  viewer v == the viewer handle
614  *  BOOL onlySelected == whether you want to handle just the selected ones,
615  *    or the whole lot.
616  *  void (*proc)(viewer_icon i,void *handle) == the routine to do whatever
617  *    it is you want to do.
618  */
619
620 void viewer_doForIcons
621 (
622   viewer v,
623   BOOL onlySelected,
624   void (*proc)(viewer_icon i,void *handle)
625 );
626
627 /*
628  * void viewer_selectAll(viewer v,BOOL onOrOff)
629  *
630  * Use
631  *  Selects or deselects all the icons in a viewer.
632  *
633  * Parameters
634  *  viewer v == the viewer handle
635  *  BOOL onOrOff == whether you want the icons to be on or off
636  */
637
638 void viewer_selectAll(viewer v,BOOL onOrOff);
639
640 /*
641  * void viewer_clickSelect(viewer v,viewer_icon i,wimp_bbits b)
642  *
643  * Use
644  *  Handles a click on an icon just like clicks in Filer windows.
645  *
646  * Parameters
647  *  viewer v == the viewer handle
648  *  viewer_icon i == the icon that was clicked
649  *  wimp_bbits b == the mouse button status
650  */
651
652 void viewer_clickSelect(viewer v,viewer_icon i,wimp_bbits b);
653
654 /*
655  * char *viewer_menuItem(viewer v,char *header)
656  *
657  * Use
658  *  Returns a menu item of the form either "~<header> ''", 
659  *  "<header> '<icon name>'", or "Selection", for inclusion in a menu 
660  *  string.
661  *
662  * Parameters
663  *  viewer v == the viewer handle
664  *  char *header == the header for the menu item
665  *
666  * Returns
667  *  A pointer to a read-only string.
668  */
669
670 char *viewer_menuItem(viewer v,char *header);
671
672 /*
673  * void viewer_setupMenu(viewer v,char *header,menu m,int i,char *buff)
674  *
675  * Use
676  *  Writes a menu item out as for the previous routine, but implants it
677  *  directly into the menu, so you don't need to fiddle about with things
678  *  like that, and also means that the menu pointer changes.  The menu item
679  *  must have been previously set up with menu_redirectItem.  This call will
680  *  also set the menu to the correct width.  However, ensure that you call
681  *  menu_minWidth(m,0) before fiddling with the width!
682  *
683  * Parameters
684  *  viewer v == the viewer handle pertaining to this request
685  *  menu m == the menu to doctor
686  *  int i == the menu item
687  *  char *buff == where the menu item wants the data
688  */
689
690 void viewer_setupMenu(viewer v,char *header,menu m,int i,char *buff);
691
692 /*
693  * viewer_icon viewer_firstSelected(viewer v)
694  *
695  * Use
696  *  Returns the handle of the first selected icon.
697  *
698  * Parameters
699  *  viewer v == the viewer handle
700  *
701  * Returns
702  *  A handle to the first one, or viewer_NOICON.
703  */
704
705 viewer_icon viewer_firstSelected(viewer v);
706
707 /*
708  * void viewer_settitle(viewer v,char *title)
709  *
710  * Use
711  *  Changes a viewer's title, so that the extent is updated as well.
712  *
713  * Parameters
714  *  viewer v == the viewer handle
715  *  char *title == the new title string
716  */
717
718 void viewer_settitle(viewer v,char *title);
719
720 /*
721  * void viewer_dragSelected(viewer_icon icn,wimp_bbits b)
722  *
723  * Use
724  *  Drags a set of icons around a window.
725  *
726  * Parameters
727  *  viewer_icon icn == the viewer icon handle
728  *  wimp_bbits b == the button types that started this lot off
729  */
730
731 void viewer_dragSelected(viewer_icon icn,wimp_bbits b);
732
733 /*
734  * void viewer_exportSelected
735  * (
736  *   viewer_icon icn,
737  *   wimp_bbits b,
738  *   int filetype,
739  *   viewer_saveproc save,
740  *   viewer_sendproc send,
741  *   viewer_printproc print
742  * )
743  *
744  * Use
745  *  Allows you to export the data connected with each selected icon to 
746  *  another application.  The filename used is the icon's text.
747  *
748  * Parameters
749  *  viewer_icon icn == the icon on which the user clicked to start the drag
750  *    operation.
751  *  wimp_bbits b == the mouse buttons which started this up.
752  *  int filetype == the filetype of the data.
753  *  viewer_saveproc save == the save routine (saving and <Wimp$Scrap> 
754  *    transfer.
755  *  viewer_sendproc send == the send routine (RAM transfer).
756  *  viewer_printproc print == the print routine (printing etc.)
757  */
758
759 void viewer_exportSelected
760 (
761   viewer_icon icn,
762   wimp_bbits b,
763   int filetype,
764   viewer_saveproc save,
765   viewer_sendproc send,
766   viewer_printproc print
767 );
768
769 /*
770  * viewer_icon viewer_helpIcon(viewer v)
771  *
772  * Use
773  *  Informs the caller which icon the Help system is interested in.
774  *
775  * Parameters
776  *  viewer v == the viewer handle
777  *
778  * Returns
779  *  The icon's handle (or maybe viewer_NOICON)
780  */
781
782 viewer_icon viewer_helpIcon(viewer v);
783
784 #endif