4 * Control of template files
6 * © 1994-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Glass.
13 * Glass 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 * Glass 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 Glass. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /*----- Header files ------------------------------------------------------*/
31 * ANSI standard headers
45 #include "steel/Steel.h"
47 #include "steel/viewer.h"
48 #include "steel/mem.h"
49 #include "steel/nopoll.h"
50 #include "steel/flex.h"
51 #include "steel/akbd.h"
52 #include "steel/alarm.h"
53 #include "steel/bbc.h"
54 #include "steel/buffer.h"
55 #include "steel/font.h"
76 /*----- Constants ---------------------------------------------------------*/
78 #define tfile__FILEHEIGHT 892 /* Height to open first template window */
79 #define tfile__FILEX 200 /* x position of template file windows */
80 #define tfile__FILETOP 940 /* Height after files wrap around */
82 #define tfile__WINDHEIGHT 872 /* Height to create first window */
83 #define tfile__WINDX 450 /* x position of template windows */
84 #define tfile__WINDTOP 920 /* Height after windows wrap around */
86 /*----- Static global variables -------------------------------------------*/
88 static int tfile__unsavedFiles; /* Number of files not saved */
89 static int tfile__fileHeight=tfile__FILEHEIGHT;
90 /* Height to open next template window */
91 static int tfile__windHeight=tfile__WINDHEIGHT;
92 static int tfile__selectSize; /* Size in bytes of current selection */
93 static int tfile__selectIcons; /* Number of icons in current selection */
94 static int tfile__selectIndSz; /* Indirected data size for selection */
95 static char tfile__grabName[15]; /* Name for the grabbed window */static glass_tfile *tfile__selOwner; /* Owner of the current selection */
97 /*----- Support routines --------------------------------------------------*/
100 * void tfile__tidyFonts(viewer_icon i,void *handle)
103 * Closes down the fonts on a particular template file.
106 * viewer_icon i == the icon (ignored)
107 * void *handle == the file to close
110 static void tfile__tidyFonts(viewer_icon ic,void *handle)
113 glass_windPointer *w=handle;
119 for (j=0;j<w->fonts[i];j++)
120 wimpt_noerr(font_lose(i));
123 w->antiAliased=FALSE;
127 * void tfile__reFindFonts(viewer_icon ic,void *handle)
130 * Scans the given window, refinding all the fonts it used. This is
131 * because (at present) on a mode change, the aspect ratio can become
132 * utterly trashed. I can't afford to wait until the Font Manager gets
133 * rewritten to work properly, so I have to do it myself...
135 * After this call, the window needs recreating if it's being displayed.
136 * It will pick up the Open_Window_Request, and recreate on that if it
137 * finds it has some fonts in it.
139 * This call also resets the antiAliased flag if it finds no fonts in a
143 * viewer_icon ic == the viewer icon of the window to rescan (ignored)
144 * void *handle == an undercover glass_windPointer * to the window
147 static void tfile__reFindFonts(viewer_icon ic,void *handle)
149 glass_windPointer *w=handle;
155 BOOL usedAFont=FALSE;
161 icf=w->def->desc.w.titleflags;
162 if (icf & wimp_IFONT)
165 fhand=(icf>>24) & 0xff;
168 wimpt_noerr(os_swix(XFont_ReadDefn,&r));
170 if (!wimpt_complain(os_swix(XFont_FindFont,&r)))
174 wimpt_noerr(os_swix(XFont_LoseFont,&r));
177 w->def->desc.w.titleflags=(icf & 0x00ffffff) | (newhand<<24);
180 for (i=0;i<w->def->desc.w.nicons;i++)
182 icf=w->def->i[i].i.flags;
183 if (icf & wimp_IFONT)
186 fhand=(icf>>24) & 0xff;
189 wimpt_noerr(os_swix(XFont_ReadDefn,&r));
191 if (!wimpt_complain(os_swix(XFont_FindFont,&r)))
195 wimpt_noerr(os_swix(XFont_LoseFont,&r));
198 w->def->i[i].i.flags=(icf & 0x00ffffff) | (newhand<<24);
202 w->antiAliased=usedAFont;
206 * void tfile__gainSelection(glass_tfile *t)
209 * Hands the current tfile selection and the input focus to the specified
212 * Note that the selection model here is more complex than it is in window,
213 * since the focus tfile may not coincide with the selection owner (since
214 * menu clicks move the selection owner, but not the focus).
217 * glass_tfile *t == the template to which we give the focus
220 static void tfile__gainSelection(glass_tfile *t)
223 if (t!=tfile__selOwner)
226 viewer_selectAll(tfile__selOwner->v,FALSE);
231 c.w=viewer_syshandle(t->v);
237 wimpt_noerr(wimp_set_caret_pos(&c));
242 * void tfile__doDeleteWindow(void *handle)
245 * Deletes, trashes and exterminates a window.
248 * void *handle == the window to eliminate
251 static void tfile__doDeleteWindow(void *handle)
254 glass_windPointer *w=handle;
255 window_hasBeenDeleted(w);
256 if (w->def->desc.w.titleflags & wimp_INDIRECT)
258 indir_free(w->def->desc.w.title.indirecttext.buffer);
259 if ((w->def->desc.w.titleflags & wimp_ITEXT) &&
260 (w->def->desc.w.title.indirecttext.validstring!=(char *)-1))
261 indir_free(w->def->desc.w.title.indirecttext.validstring);
263 for (i=0;i<w->def->desc.w.nicons;i++)
265 if (w->def->i[i].i.flags & wimp_INDIRECT)
267 indir_free(w->def->i[i].i.data.indirecttext.buffer);
268 if ((w->def->i[i].i.flags & wimp_ITEXT) &&
269 (w->def->i[i].i.data.indirecttext.validstring!=(char *)-1))
270 indir_free(w->def->i[i].i.data.indirecttext.validstring);
274 flex_free((flex_ptr)&w->def);
277 win_register_event_handler(w->h,0,0);
279 wimpt_noerr(wimp_delete_wind(w->h));
281 tfile__tidyFonts(0,w);
286 * void tfile__deleteTemplateFile(void *handle)
289 * Trashes the named template file.
292 * void *handle == the template file to murder
295 static void tfile__deleteTemplateFile(void *handle)
297 glass_tfile *t=handle;
298 intMsgs_send(glass_DELETEFILE,t);
299 if (t==tfile__selOwner)
303 tfile__unsavedFiles--;
304 viewer_delete(t->v,tfile__doDeleteWindow);
306 dbox_delete(t->autod);
308 alarm_remove(t->autoAlarm,t);
314 * glass_windPointer *tfile__newWindow(glass_tfile *t,char *name)
317 * Creates a new window entry in the template file specified. It is up to
318 * the caller to write the window definition.
321 * glass_tfile *t == the template file to add the window to
322 * char *name == the name of the window
325 * A pointer to the window structure
328 static glass_windPointer *tfile__newWindow(glass_tfile *t,char *name)
330 glass_windPointer *w;
332 static int serial; /* Serial number - monotonic increasing */
333 mem_useUser(indir_alloc,indir_free);
334 w=mem_alloc(sizeof(glass_windPointer));
337 werr(FALSE,msgs_lookup("tfNEMCRT"));
347 w->gridx=gPrefs_current()->gWidth;
348 w->gridy=gPrefs_current()->gHeight;
349 w->gridShow=gPrefs_current()->gDisp;
350 w->gridLock=gPrefs_current()->gLock;
351 w->serial=serial++; /* Increment serial number count */
352 for (i=0;i<glass_GUIDELIMIT;i++)
353 w->guide[i].active=FALSE;
354 w->antiAliased=FALSE;
357 if (w->i=viewer_addIcon(t->v,name,"tmpltvicon",TRUE,w),!w->i)
363 viewer_setFiletype(w->i,0xfec);
369 * void tfile__size(viewer_icon i,void *handle)
372 * Adds the size of the window given by handle to the global variables
373 * tfile__selectSize and tfile__selectIndSz.
376 * viewer_icon i == the viewer icon handle (ignored)
377 * void *handle == the window to count
380 static void tfile__size(viewer_icon i,void *handle)
382 glass_windPointer *w=handle;
384 tfile__selectSize+=w->size;
385 tfile__selectIndSz+=w->size-
386 sizeof(glass_window)-
387 (w->def->desc.w.nicons-1)*
388 sizeof(glass_iconDescription);
392 * void tfile__icons(viewer_icon i,void *handle)
395 * Adds the number of icons in the window given by handle to the global
396 * variable tfile__selectIcons.
399 * viewer_icon i == the viewer icon handle (ignored)
400 * void *handle == the window to count
403 static void tfile__icons(viewer_icon i,void *handle)
405 glass_windPointer *w=handle;
407 tfile__selectIcons+=w->def->desc.w.nicons;
411 * BOOL tfile__create(char *new,void *handle)
414 * Creates a new window.
417 * char *new == the name for the new window
418 * void *handle == pointer to the tfile
421 static BOOL tfile__create(char *new,void *handle)
423 glass_tfile *t=handle;
425 glass_windPointer *wnew;
426 wimp_wind *w=&template_find("default")->window;
428 icn=viewer_findIcon(t->v,new);
429 if (icn==viewer_NOICON)
431 wnew=tfile__newWindow(t,new);
434 tfile_markAsAltered(t);
435 wnew->size=sizeof(glass_window)-sizeof(glass_iconDescription);
436 if (!flex_alloc((flex_ptr)&wnew->def,wnew->size))
438 viewer_removeIcon(wnew->i);
440 werr(FALSE,msgs_lookup("tfNEMCRT"));
443 wnew->def->desc.w=*w;
444 wnew->def->desc.w.nicons=0;
445 if (!iconData_handleFont(wnew,&wnew->def->desc.w.titleflags))
446 werr(FALSE,msgs_lookup("tfFERC"));
447 if (wnew->def->desc.w.titleflags & wimp_IFONT)
449 wnew->antiAliased=TRUE;
450 wnew->fonts[(wnew->def->desc.w.titleflags>>24) & 0xff]++;
452 if (!iconData_processIcon(wnew,-1,0,TRUE,0))
454 werr(FALSE,msgs_lookup("tfNEMCRT"));
455 tfile_deleteWindow(0,wnew);
458 wnew->def->desc.w.box.y1=tfile__windHeight;
459 wnew->def->desc.w.box.y0=tfile__windHeight +
460 wnew->def->desc.w.ex.y0 -
461 wnew->def->desc.w.ex.y1;
462 wnew->def->desc.w.box.x0=tfile__WINDX;
463 wnew->def->desc.w.box.x1=tfile__WINDX -
464 wnew->def->desc.w.ex.x0 +
465 wnew->def->desc.w.ex.x1;
466 if (wnew->def->desc.w.box.y0<tfile__windHeight-500)
467 wnew->def->desc.w.box.y0=tfile__windHeight-500;
468 if (wnew->def->desc.w.box.x1>tfile__WINDX+700)
469 wnew->def->desc.w.box.x1=tfile__WINDX+700;
470 wnew->def->desc.w.scx=wnew->def->desc.w.ex.x0;
471 wnew->def->desc.w.scy=wnew->def->desc.w.ex.y1;
472 tfile__windHeight-=48;
473 if (tfile__windHeight<632)
474 tfile__windHeight=tfile__WINDTOP;
478 note(msgs_lookup("tfNAE"),viewer_textOfIcon(icn));
483 * char *tfile__grabData(char *ptr,void *handle)
486 * Grabs data from the destination task, as required when setting up a
490 * char *ptr == pointer to data string (in other task's workspace)
491 * void *handle == not a pointer at all, actually the source task's handle
494 * A pointer to a string in my own workspace (static char array)
497 static char *tfile__grabData(char *ptr,void *handle)
499 char *buff=buffer_find();
500 wimp_t t=(int)handle;
503 if (wimp_transferblock(t,ptr,wimpt_task(),buff,256))
507 return ("<indirected>");
512 * void tfile__grab(wimp_mousestr *m,void *handle)
515 * Grabs a window definition, inserting it neatly into the template file.
518 * wimp_mousestr *m == info about the window
519 * void *handle == pointer to destination template file
522 static void tfile__grab(wimp_mousestr *m,void *handle)
524 glass_tfile *t=handle;
525 glass_windPointer *wnew;
535 wnew=tfile__newWindow(t,tfile__grabName);
538 tfile_markAsAltered(t);
539 if (wimpt_getVersion()>=300) /* RISC OS 3 allows 'safe' GetWindowInfos */
540 w=mem_alloc(sizeof(wimp_winfo));
542 w=mem_alloc(sizeof(wimp_winfo)+200*sizeof(wimp_icon));
545 werr(FALSE,msgs_lookup("tfNEMGW"));
546 viewer_removeIcon(wnew->i);
552 if (wimpt_getVersion()>=300)
553 r.r[1]++; /* RO3 - only window header, not icons */
554 wimpt_noerr(os_swix(XWimp_GetWindowInfo,&r)); /* Get the information */
555 numicons=w->info.nicons;
557 wnew->size=sizeof(glass_window)+
558 (numicons-1)*sizeof(glass_iconDescription);
559 if (!flex_alloc((flex_ptr)&w,
560 sizeof(wimp_winfo)+numicons*sizeof(wimp_icon)))
562 viewer_removeIcon(wnew->i);
564 werr(FALSE,msgs_lookup("tfNEMGW"));
567 if (!flex_alloc((flex_ptr)&wnew->def,wnew->size))
569 flex_free((flex_ptr)&w);
570 viewer_removeIcon(wnew->i);
572 werr(FALSE,msgs_lookup("tfNEMGW"));
577 wimpt_noerr(os_swix(XWimp_GetWindowInfo,&r)); /* Read the window properly*/
586 if (os_swix(XWimp_SendMessage,&r))
591 wnew->def->desc.w=w->info;
592 wnew->def->desc.w.nicons=0;
593 if (!iconData_handleFont(wnew,&wnew->def->desc.w.titleflags) && !fonterr)
595 werr(FALSE,msgs_lookup("tfFERG"));
598 if (!iconData_processIcon(wnew,-1,tfile__grabData,TRUE,(void *)task))
600 flex_free((flex_ptr)&w);
601 tfile_deleteWindow(0,wnew);
602 werr(FALSE,msgs_lookup("tfNEMGW"));
606 ioff=sizeof(wimp_winfo);
607 for (i=0;i<numicons;i++)
609 wnew->def->i[i].i=*_ptr(wimp_icon,w,ioff);
610 wnew->def->i[i].edit=0;
611 if (!iconData_handleFont(wnew,&wnew->def->i[i].i.flags) && !fonterr)
613 werr(FALSE,msgs_lookup("tfFERG"));
616 if (!iconData_processIcon(wnew,i,tfile__grabData,TRUE,(void *)task))
618 flex_free((flex_ptr)&w);
619 tfile_deleteWindow(0,wnew);
620 werr(FALSE,msgs_lookup("tfNEMGW"));
623 wnew->def->desc.w.nicons++;
624 ioff+=sizeof(wimp_icon);
626 flex_free((flex_ptr)&w);
630 * BOOL tfile__grabGetName(char *name,void *handle)
633 * Handles the writable box for a grab window job and starts the grab op
636 * char *name == the user's name for the window
637 * void *handle == the template file to grab to
640 * TRUE if the name was valid and the grab has been set up
643 static BOOL tfile__grabGetName(char *name,void *handle)
645 glass_tfile *t=handle;
648 icn=viewer_findIcon(t->v,name);
649 if (icn==viewer_NOICON)
651 strcpy(tfile__grabName,name);
652 event_clear_current_menu();
653 window_grab(tfile__grab,t);
656 note(msgs_lookup("tfNAE"),
657 viewer_textOfIcon(icn));
662 * BOOL tfile__copy(char *new,void *handle)
665 * Copies the specified window
668 * char *new == the name for the new window
669 * void *handle == pointer to the window structure
672 static BOOL tfile__copy(char *new,void *handle)
674 glass_windPointer *w=handle;
676 glass_windPointer *wnew;
681 icn=viewer_findIcon(w->t->v,new);
682 if (icn==viewer_NOICON)
684 wnew=tfile__newWindow(w->t,new);
687 tfile_markAsAltered(w->t);
689 numicons=w->def->desc.w.nicons;
690 if (!flex_alloc((flex_ptr)&wnew->def,
692 +(numicons-1)*sizeof(glass_iconDescription)))
694 viewer_removeIcon(wnew->i);
696 werr(FALSE,msgs_lookup("tfNEMCW"));
703 sizeof(glass_window)+(numicons-1)*sizeof(glass_iconDescription)
705 wnew->def->desc.w.nicons=0;
706 if (!iconData_handleFont(wnew,&wnew->def->desc.w.titleflags) && !fonterr)
708 werr(FALSE,msgs_lookup("tfFERCP"));
711 if (!iconData_processIcon(wnew,-1,0,FALSE,0))
713 werr(FALSE,msgs_lookup("tfNEMCW"));
714 tfile_deleteWindow(0,wnew);
717 for (i=0;i<numicons;i++)
719 if (!iconData_handleFont(wnew,&wnew->def->i[i].i.flags) && !fonterr)
721 werr(FALSE,msgs_lookup("tfFERCP"));
724 if (!iconData_processIcon(wnew,i,0,FALSE,0))
726 werr(FALSE,msgs_lookup("tfNEMCW"));
727 tfile_deleteWindow(0,wnew);
730 wnew->def->desc.w.nicons++;
734 note(msgs_lookup("tfNAE"),
735 viewer_textOfIcon(icn));
740 * void tfile__openWindows(viewer_icon i,void *handle)
743 * Opens a window. This is called when the user drags icons to the icon
744 * bar and expects them to be displayed.
747 * viewer_icon i == the icon handle of the icon representing the window
749 * void *handle == pointer to the window's static information
752 static void tfile__openWindows(viewer_icon i,void *handle)
754 glass_windPointer *w=handle;
756 window_open(w,FALSE);
759 /*----- Variables used during the save process ----------------------------*/
763 static void **tfile__flex; /* A flex block for saving data */
764 static int tfile__flexSize; /* Size of the flex block */
765 static int tfile__flexUsed; /* How much of the block has been used */
766 static BOOL tfile__abortSave; /* If TRUE, abort the save process */
767 static int tfile__nextIndex; /* Offset to next free index entry */
768 static char tfile__fontbinding[256]; /* Conversion realh -> internh */
769 static char tfile__backbinding[256]; /* Reverse font binding */
770 static char tfile__nextFont; /* The next free internal font handle */
772 /*----- Save templates support routines -----------------------------------*/
775 * This section contains the actual code to save a template file or
780 * BOOL tfile__saveAlloc(int size)
783 * Ensures that a certain quantity of space is present in the save flex
787 * int size == the size required in bytes
790 * TRUE if successful, or FALSE if allocation failed. An error is also
794 static BOOL tfile__saveAlloc(int size)
797 if (tfile__flexSize-tfile__flexUsed>size)
799 szreqd=(tfile__flexUsed+size+8191) & ~8191;
800 if (!flex_extend(tfile__flex,szreqd))
802 werr(FALSE,msgs_lookup("tfNEMST"));
805 tfile__flexSize=szreqd;
810 * BOOL tfile__addBlock(void *p,size_t sz)
813 * Adds a block of data to the end of the save block.
816 * void *p == pointer to the block
817 * size_t sz == the size of the block
823 static BOOL tfile__addBlock(void *p,size_t sz)
825 if (!tfile__saveAlloc(sz))
827 memcpy(_ptr(void,*tfile__flex,tfile__flexUsed),p,sz);
832 #define tfile__writeString(s,off) \
834 strcpy(charptr(*tfile__flex,off),s); \
835 charptr(*tfile__flex,off)[strlen(s)]=13; \
839 * BOOL tfile__addString(char *s)
842 * Adds a ctrl-terminated string to the end of the save block.
845 * char *s == pointer to the string to store
851 static BOOL tfile__addString(char *s)
854 utils_ctermToNterm(s);
856 if (!tfile__saveAlloc(len+1))
858 tfile__writeString(s,tfile__flexUsed);
859 tfile__flexUsed+=len+1;
864 * void tfile__processWindow(viewer_icon icn,void *handle)
867 * Saves the window given onto the end of the flex block being used for
868 * such a purpose. A save may be aborted by setting the variable
872 * viewer_icon icn == the icon representing the window to be saved (ignored)
873 * void *handle == pointer to the window structure in memory
876 static void tfile__processWindow(viewer_icon icn,void *handle)
882 glass_windPointer *w=handle;
884 if (tfile__abortSave)
886 while (tfile__flexUsed & 3)
887 *charptr(*tfile__flex,tfile__flexUsed++)=0;
889 /* --- Start on the index --- */
890 intptr(*tfile__flex,tfile__nextIndex)[0]=start=tfile__flexUsed;
891 intptr(*tfile__flex,tfile__nextIndex)[2]=1;
892 tfile__writeString(w->id,tfile__nextIndex+12);
894 /* --- Now copy the window and icons --- */
895 if (!tfile__addBlock(&w->def->desc.w,sizeof(wimp_wind)))
897 tfile__abortSave=TRUE;
900 for (i=0;i<w->def->desc.w.nicons;i++)
902 if (!tfile__addBlock(&w->def->i[i].i,sizeof(wimp_icon)))
904 tfile__abortSave=TRUE;
909 /* --- Process window def for indirection and fonts --- */
910 _ptr(wimp_wind,*tfile__flex,start)->spritearea=(void *)1;
911 if (w->def->desc.w.titleflags & wimp_IFONT)
913 rfont=w->def->desc.w.titleflags >> 24;
914 if (tfile__fontbinding[rfont])
915 ifont=tfile__fontbinding[rfont];
918 ifont=tfile__fontbinding[rfont]=tfile__nextFont++;
919 tfile__backbinding[ifont]=rfont;
921 _ptr(wimp_wind,*tfile__flex,start) -> titleflags=
922 (w->def->desc.w.titleflags & 0x00ffffff) | (ifont << 24);
924 if (w->def->desc.w.titleflags & wimp_INDIRECT)
926 _ptr(wimp_wind,*tfile__flex,start) -> title.indirecttext.buffer=
927 (char *)(tfile__flexUsed-start);
928 if (!tfile__addString(w->def->desc.w.title.indirecttext.buffer))
930 tfile__abortSave=TRUE;
933 if (w->def->desc.w.titleflags & wimp_ITEXT)
935 if (w->def->desc.w.title.indirecttext.validstring!=(char *)-1)
937 _ptr(wimp_wind,*tfile__flex,start)->title.indirecttext.validstring=
938 (char *)(tfile__flexUsed-start);
939 if (!tfile__addString(w->def->desc.w.title.indirecttext.validstring))
941 tfile__abortSave=TRUE;
946 else if (w->def->desc.w.titleflags & wimp_ISPRITE)
948 _ptr(wimp_wind,*tfile__flex,start)->title.indirectsprite.spritearea=
953 /* --- Now the same for the icons --- */
954 idef=start+sizeof(wimp_wind);
955 for (i=0;i<w->def->desc.w.nicons;i++)
957 if (w->def->i[i].i.flags & wimp_IFONT)
959 rfont=w->def->i[i].i.flags >> 24;
960 if (tfile__fontbinding[rfont])
961 ifont=tfile__fontbinding[rfont];
964 ifont=tfile__fontbinding[rfont]=tfile__nextFont++;
965 tfile__backbinding[ifont]=rfont;
967 _ptr(wimp_icon,*tfile__flex,idef)->flags=
968 (w->def->i[i].i.flags & 0x00ffffff) | (ifont << 24);
970 if (w->def->i[i].i.flags & wimp_INDIRECT)
972 _ptr(wimp_icon,*tfile__flex,idef)->data.indirecttext.buffer=
973 (char *)(tfile__flexUsed-start);
974 if (!tfile__addString(w->def->i[i].i.data.indirecttext.buffer))
976 tfile__abortSave=TRUE;
979 if (w->def->i[i].i.flags & wimp_ITEXT)
981 if (w->def->i[i].i.data.indirecttext.validstring!=(char *)-1)
983 _ptr(wimp_icon,*tfile__flex,idef)->data.indirecttext.validstring=
984 (char *)(tfile__flexUsed-start);
985 if (!tfile__addString(w->def->i[i].i.data.
986 indirecttext.validstring))
988 tfile__abortSave=TRUE;
993 else if (w->def->i[i].i.flags & wimp_ISPRITE)
995 _ptr(wimp_icon,*tfile__flex,idef)->data.indirectsprite.spritearea=
999 idef+=sizeof(wimp_icon);
1001 intptr(*tfile__flex,tfile__nextIndex)[1]=tfile__flexUsed-start;
1002 tfile__nextIndex+=24;
1006 * BOOL tfile__setupSave(glass_tfile *t,
1007 * glass_windPointer *w,
1009 * BOOL onlySelected)
1012 * Sets up a flex block for saving a template file, selection or single
1013 * window. To save a template file or selection, set t==tfile, w==0. To
1014 * save a window, set t==0, w==window.
1017 * glass_tfile *t == the template file that we're saving
1018 * glass_windPointer *w == the window we're saving
1019 * void **p == pointer used as flex anchor (free after use yourself)
1020 * BOOL onlySelected == do we only save the selected templates?
1023 * TRUE if operation completed successfully
1026 static BOOL tfile__setupSave(glass_tfile *t,
1027 glass_windPointer *w,
1035 if (!flex_alloc(p,tfile__selectSize))
1037 werr(FALSE,msgs_lookup("tfNEMST"));
1041 tfile__flexSize=tfile__selectSize;
1043 tfile__abortSave=FALSE;
1046 tfile__fontbinding[i]=0;
1047 tfile__backbinding[i]=0;
1051 /* --- Header --- */
1052 if (!tfile__saveAlloc(16))
1057 intptr(*tfile__flex,0)[0]=-1;
1058 intptr(*tfile__flex,0)[1]=0;
1059 intptr(*tfile__flex,0)[2]=0;
1060 intptr(*tfile__flex,0)[3]=0;
1061 tfile__flexUsed+=16;
1063 /* --- Set up index entries --- */
1067 numwin=viewer_selected(t->v);
1069 numwin=viewer_icons(t->v);
1073 if (!tfile__saveAlloc(24*numwin+4))
1079 /* --- Now insert window and icon definitions --- */
1080 tfile__nextIndex=16;
1081 tfile__flexUsed+=24*numwin+4;
1083 viewer_doForIcons(t->v,onlySelected,tfile__processWindow);
1085 tfile__processWindow(0,w);
1086 if (tfile__abortSave)
1092 /* --- Terminate the index and fill in the fonts --- */
1093 intptr(*tfile__flex,tfile__nextIndex)[0]=0;
1094 if (tfile__nextFont!=1)
1096 tfile__flexUsed=(tfile__flexUsed+3) & (~3);
1097 if (!tfile__saveAlloc(48*(tfile__nextFont-1)))
1102 intptr(*tfile__flex,0)[0]=tfile__flexUsed;
1103 for (i=1;i<tfile__nextFont;i++)
1105 r.r[0]=tfile__backbinding[i];
1107 wimpt_noerr(os_swix(XFont_ReadDefn,&r));
1108 intptr(*tfile__flex,tfile__flexUsed)[0]=r.r[2];
1109 intptr(*tfile__flex,tfile__flexUsed)[1]=r.r[3];
1110 tfile__writeString(buff,tfile__flexUsed+8);
1111 tfile__flexUsed+=48;
1118 * BOOL tfile__saveTemplates(char *filename,void *handle)
1121 * Saves a template file to disk
1124 * char *filename == the file to save to
1125 * void *handle == pointer to the template file
1128 * TRUE if successful
1131 static BOOL tfile__saveTemplates(char *filename,void *handle)
1135 glass_tfile *t=handle;
1138 gPrefs_current()->cSave &&
1139 saveas_file_is_safe() &&
1140 utils_caselessCmp(filename,t->filename)!=0 &&
1141 res_fileExists(filename)
1144 if (!warning(msgs_lookup("tfSOFP"),msgs_lookup("tfSOF"),filename))
1147 if (!tfile__setupSave(t,0,&p,FALSE))
1153 f.end=f.start+tfile__flexUsed;
1154 if (utils_complain(os_file(&f),msgs_lookup("tfERT")))
1162 if (saveas_file_is_safe())
1163 tfile_markAsSaved(t,filename);
1169 * BOOL tfile__sendTemplates(void *handle,int *maxbuf)
1172 * Saves a template file to another application via RAM transfer
1175 * void *handle == pointer to the template file
1176 * int *maxbuf == pointer to receiving app's buffer size
1179 * TRUE if successful
1182 static BOOL tfile__sendTemplates(void *handle,int *maxbuf)
1185 glass_tfile *t=handle;
1186 if (!tfile__setupSave(t,0,&p,FALSE))
1188 if (xfersend_sendBlock(p,tfile__flexUsed,maxbuf))
1201 * BOOL tfile__saveSelection(char *filename,void *handle)
1204 * Saves a template selection to disk
1207 * char *filename == the file to save to
1208 * void *handle == pointer to the template file
1211 * TRUE if successful
1214 static BOOL tfile__saveSelection(char *filename,void *handle)
1218 glass_tfile *t=handle;
1221 gPrefs_current()->cSave &&
1222 saveas_file_is_safe() &&
1223 res_fileExists(filename)
1226 if (!warning(msgs_lookup("tfSOFP"),msgs_lookup("tfSOF"),filename))
1229 if (!tfile__setupSave(t,0,&p,TRUE))
1235 f.end=f.start+tfile__flexUsed;
1236 if (utils_complain(os_file(&f),msgs_lookup("tfERT")))
1249 * BOOL tfile__sendSelection(void *handle,int *maxbuf)
1252 * Saves a template selection to another application via RAM transfer
1255 * void *handle == pointer to the template file
1256 * int *maxbuf == pointer to receiving app's buffer size
1259 * TRUE if successful
1262 static BOOL tfile__sendSelection(void *handle,int *maxbuf)
1265 glass_tfile *t=handle;
1266 if (!tfile__setupSave(t,0,&p,TRUE))
1268 if (xfersend_sendBlock(p,tfile__flexUsed,maxbuf))
1281 * BOOL tfile__saveWindow(char *filename,void *handle)
1284 * Saves a template selection to disk
1287 * char *filename == the file to save to
1288 * void *handle == pointer to the window
1291 * TRUE if successful
1294 static BOOL tfile__saveWindow(char *filename,void *handle)
1298 glass_windPointer *w=handle;
1301 gPrefs_current()->cSave &&
1302 saveas_file_is_safe() &&
1303 res_fileExists(filename)
1306 if (!warning(msgs_lookup("tfSOFP"),msgs_lookup("tfSOF"),filename))
1309 if (!tfile__setupSave(0,w,&p,TRUE))
1315 f.end=f.start+tfile__flexUsed;
1316 if (utils_complain(os_file(&f),msgs_lookup("tfERT")))
1329 * BOOL tfile__sendWindow(void *handle,int *maxbuf)
1332 * Saves a template selection to another application via RAM transfer
1335 * void *handle == pointer to the window
1336 * int *maxbuf == pointer to receiving app's buffer size
1339 * TRUE if successful
1342 static BOOL tfile__sendWindow(void *handle,int *maxbuf)
1345 glass_windPointer *w=handle;
1346 if (!tfile__setupSave(0,w,&p,TRUE))
1348 if (xfersend_sendBlock(p,tfile__flexUsed,maxbuf))
1362 static BOOL tfile__demoSave(void)
1364 note(msgs_lookup("tfCSID"));
1367 static BOOL tfile__saveTemplates(char *filename,void *handle)
1371 return (tfile__demoSave());
1374 static BOOL tfile__sendTemplates(void *handle,int *maxbuf)
1378 return (tfile__demoSave());
1381 static BOOL tfile__saveSelection(char *filename,void *handle)
1385 return (tfile__demoSave());
1388 static BOOL tfile__sendSelection(void *handle,int *maxbuf)
1392 return (tfile__demoSave());
1395 static BOOL tfile__saveWindow(char *filename,void *handle)
1399 return (tfile__demoSave());
1402 static BOOL tfile__sendWindow(void *handle,int *maxbuf)
1406 return (tfile__demoSave());
1411 /*----- Autosave handling -------------------------------------------------*
1413 * This is here to avoid having to prototype the save code
1417 * void tfile__closeQbox(int now,void *handle)
1420 * Closes the autosave message dialogue box.
1423 * int now == the time now (ignored)
1424 * void *handle == dialogue box handle
1427 static void tfile__closeQbox(int now,void *handle)
1430 dbox_delete((dbox)handle);
1434 * void tfile__autoHandler(dbox d,dbox_field f,void *handle)
1437 * Handles events for the autosave prompt box
1440 * dbox d == the dbox's handle
1441 * dbox_field f == what happened
1442 * void *handle == pointer to the template file
1445 static void tfile__autoHandler(dbox d,dbox_field f,void *handle)
1447 glass_tfile *t=handle;
1452 if (strchr(t->filename,'.'))
1454 dbox_clickicon(d,f);
1455 wimpt_noerr(wimp_get_wind_state(dbox_syshandle(d),&s));
1457 if (!tfile__saveTemplates(t->filename,t))
1458 wimpt_noerr(wimp_open_wind(&s.o));
1462 /* If no path, drop through to saveas... */
1463 case glass_APSAVEAS:
1464 dbox_clickicon(d,glass_APSAVEAS);
1466 tfile_saveTemplates(t);
1468 case glass_APCANCEL:
1469 dbox_clickicon(d,f);
1472 /* Intentional drop through */
1481 * void tfile__doAutosave(glass_tfile *t)
1484 * Starts an autosave for the given template file. Multiple autosaves
1485 * are permitted simultaneously. Stick that in Impression's pipeline and
1489 * glass_tfile *t == the template file to autosave
1492 static void tfile__doAutosave(int now,void *handle)
1497 glass_tfile *t=handle;
1499 useDbox=gPrefs_current()->aPrompt;
1500 if (t->loaded==FALSE || t->autoSaved==FALSE)
1503 alarm_remove(t->autoAlarm,t);
1511 t->autod=dbox_create("autoPrompt");
1514 if (at=gPrefs_autoTiming(),at)
1516 t->autoTime=alarm_timenow();
1517 t->autoAlarm=t->autoTime+at;
1518 alarm_set(t->autoAlarm,tfile__doAutosave,t);
1522 dbox_setfield(t->autod,glass_APNAME,"%.%s",t->filename);
1523 dbox_shadeicon(t->autod,glass_APSAVE,!strchr(t->filename,'.'));
1524 dbox_eventHandler(t->autod,tfile__autoHandler,t);
1525 dbox_openDisplaced(t->autod);
1529 qwin=dbox_create("autoMessage");
1532 dbox_setfield(qwin,glass_AMNAME,"%.%s",t->filename);
1533 dbox_display(qwin,dbox_MENU_CENTRE);
1534 nopoll_showDbox(qwin,nopoll_CENTRE);
1535 alarm_set(alarm_timenow()+100,tfile__closeQbox,qwin);
1537 tfile__saveTemplates(t->filename,t);
1541 /*----- Event handlers ----------------------------------------------------*/
1544 * void tfile__close(glass_tfile *t,BOOL checkMouse)
1547 * Closes a template file, asking user for confirmation etc.
1550 * glass_tfile *t == the template file to kill
1551 * BOOL checkMouse == whether to check the mouse buttons to open the parent
1554 static void tfile__close(glass_tfile *t,BOOL checkMouse)
1559 event_clear_current_menu(); /* The menu will be closed - it will try */
1560 /* to deselect an non-existant item... */
1563 wimpt_noerr(wimp_get_point_info(&m));
1564 if (m.bbits==wimp_BRIGHT && t->loaded)
1566 sprintf(buff,"Filer_OpenDir %s",t->filename);
1567 utils_leafname(buff)[-1]=0;
1570 if (m.bbits==wimp_BRIGHT && akbd_pollsh())
1573 if (t->alts && gPrefs_current()->cClose)
1578 name=msgs_lookup("tfTMP");
1579 tfile__selectSize=0;
1580 viewer_doForIcons(t->v,FALSE,tfile__size);
1581 viewer_clickSelect(t->v,viewer_NOICON,wimp_BMID);
1583 tfile__deleteTemplateFile,
1584 msgs_lookup("tfSVTIT"),
1587 tfile__saveTemplates,
1588 tfile__sendTemplates,
1593 tfile__deleteTemplateFile(t); /* Destroy the underlying data */
1597 * void tfile__redrawViewer(viewer_icon i,wimp_redrawstr *r,
1598 * wimp_box *box,char *text,char *sprite,BOOL selected,void *handle)
1601 * Redraws a small icon in the viewer window.
1604 * viewer_icon i == the icon I'm redrawing
1605 * wimp_redrawstr *r == the redraw structure
1606 * wimp_box *box == the box to fit it in
1607 * char *text == the text to draw
1608 * char *sprite == the sprite to draw (ignored)
1609 * BOOL selected == whether the icon is selected
1610 * void *handle == pointer to the template file
1613 static void tfile__redrawViewer(viewer_icon i,
1621 wimp_icon icn={0,0,0,0,0x17000113,""};
1627 icn.flags|=(selected<<21);
1628 icn.data.indirecttext.buffer=text;
1629 icn.data.indirecttext.validstring="Ssmtmpltvicon";
1630 icn.data.indirecttext.bufflen=13;
1631 wimpt_noerr(wimp_ploticon(&icn));
1635 * int tfile__sort(void *a,void *b)
1638 * Compares two windows in the current sorting method.
1641 * void *a == pointer to the first window
1642 * void *b == pointer to the second window
1648 static int tfile__sort(void *a,void *b)
1650 glass_windPointer *x=a;
1651 glass_windPointer *y=b;
1656 result=utils_caselessCmp(x->id,y->id);
1659 result=y->size-x->size;
1662 result=y->def->desc.w.nicons-x->def->desc.w.nicons;
1665 result=x->serial-y->serial;
1669 result=utils_caselessCmp(x->id,y->id);
1674 * void tfile__tfileMenuHelp(int hit[],void *handle)
1677 * Responds to help requests for template file menu.
1680 * int hit[] == array of menu selections
1681 * void *handle == pointer to template file control block
1684 static void tfile__tfileMenuHelp(int hit[],void *handle)
1688 help_readFromMenu("tfmhTF",hit);
1693 * void tfile__tfileMenuHandler(int hit[],void *handle)
1696 * Responds to menu events for template file menu.
1699 * int hit[] == array of menu selections
1700 * void *handle == pointer to template file control block
1703 static void tfile__tfileMenuHandler(int hit[],void *handle)
1705 glass_tfile *t=handle;
1712 viewer_clickSelect(t->v,viewer_NOICON,wimp_BMID);
1715 if (d=dbox_create("fileInfo"),d)
1717 dbox_setfield(d,glass_FINAME,"%.%s",t->filename);
1718 tfile__selectSize=0;
1719 tfile__selectIndSz=0;
1720 viewer_doForIcons(t->v,FALSE,tfile__size);
1724 utils_cvtSize(tfile__selectSize));
1728 utils_cvtSize(tfile__selectIndSz));
1729 dbox_setfield(d,glass_FIWINDOWS,"%i",viewer_icons(t->v));
1733 msgs_lookup(t->alts ? "yes" : "no"));
1740 case glass_TFDLARGE:
1741 if (t->isz!=gPrefs_LARGE)
1743 t->isz=gPrefs_LARGE;
1744 viewer_setIconSize(t->v,200,112);
1745 viewer_redrawHandler(t->v,0,t);
1748 case glass_TFDSMALL:
1749 if (t->isz!=gPrefs_SMALL)
1751 t->isz=gPrefs_SMALL;
1752 viewer_setIconSize(t->v,248,36);
1753 viewer_redrawHandler(t->v,tfile__redrawViewer,t);
1756 case glass_TFDSORTNAME:
1757 if (t->sort!=gPrefs_NAME)
1759 t->sort=gPrefs_NAME;
1760 viewer_setCompare(t->v,tfile__sort);
1763 case glass_TFDSORTSIZE:
1764 if (t->sort!=gPrefs_SIZE)
1766 t->sort=gPrefs_SIZE;
1767 viewer_setCompare(t->v,tfile__sort);
1770 case glass_TFDSORTICONS:
1771 if (t->sort!=gPrefs_ICONS)
1773 t->sort=gPrefs_ICONS;
1774 viewer_setCompare(t->v,tfile__sort);
1777 case glass_TFDNOSORT:
1778 if (t->sort!=gPrefs_NOSORT)
1780 t->sort=gPrefs_NOSORT;
1781 viewer_setCompare(t->v,tfile__sort);
1789 case glass_TFSELINFO:
1790 if (viewer_selected(t->v)==1)
1791 tfile_windowInfo((glass_windPointer *)
1792 viewer_iconHandle(viewer_firstSelected(t->v)));
1795 if (d=dbox_create("selInfo"),d)
1797 tfile__selectSize=0;
1798 tfile__selectIndSz=0;
1799 viewer_doForIcons(t->v,TRUE,tfile__size);
1803 utils_cvtSize(tfile__selectSize));
1807 utils_cvtSize(tfile__selectIndSz));
1808 tfile__selectIcons=0;
1809 viewer_doForIcons(t->v,TRUE,tfile__icons);
1810 dbox_setfield(d,glass_SIICONS,"%i",tfile__selectIcons);
1811 dbox_setfield(d,glass_SINUM,"%i",viewer_selected(t->v));
1816 case glass_TFSELEDIT:
1817 editWindow(viewer_iconHandle(viewer_firstSelected(t->v)));
1819 case glass_TFSELCOPY:
1822 msgs_lookup("tfCOPY"),
1823 viewer_textOfIcon(viewer_firstSelected(t->v)),
1826 viewer_iconHandle(viewer_firstSelected(t->v))
1829 case glass_TFSELRENAME:
1832 msgs_lookup("tfREN"),
1833 viewer_textOfIcon(viewer_firstSelected(t->v)),
1836 viewer_iconHandle(viewer_firstSelected(t->v))
1839 case glass_TFSELSAVE:
1840 tfile__selectSize=0;
1841 viewer_doForIcons(t->v,TRUE,tfile__size);
1842 saveas(msgs_lookup("tfSVSEL"),
1843 msgs_lookup("tfSEL"),
1846 tfile__saveSelection,
1847 tfile__sendSelection,
1851 case glass_TFSELDELETE:
1852 if (gPrefs_current()->cDelWind)
1854 if (!warning(msgs_lookup("tfDELWP"),msgs_lookup("tfDELW")))
1857 viewer_doForIcons(t->v,TRUE,tfile_deleteWindow);
1858 tfile_markAsAltered(t);
1862 case glass_TFSELALL:
1863 tfile__gainSelection(t);
1864 viewer_selectAll(t->v,TRUE);
1866 case glass_TFCLRSEL:
1867 viewer_selectAll(t->v,FALSE);
1870 tfile_saveTemplates(t);
1872 case glass_TFCREATE:
1873 writable(msgs_lookup("tfCRT"),"",buff,tfile__create,t);
1876 writable(msgs_lookup("tfGRAB"),"",buff,tfile__grabGetName,t);
1878 case glass_TFSHWSPR:
1887 * menu tfile__tfileMenuMaker(void *handle)
1890 * Generates the menu for a template file window.
1893 * void *handle == the template file window to deal with
1896 * A pointer to the menu structure to display.
1899 static menu tfile__tfileMenuMaker(void *handle)
1901 static menu m; /* The main menu pointer */
1902 static menu disp; /* Submenu for display options */
1903 static menu windsm; /* Submenu for window options */
1904 #ifdef glass_NOTLAZY
1905 static menu stylesm; /* Submenu for styles options */
1907 static char windName[50]; /* Buffer for window name */
1908 glass_tfile *t=handle;
1909 glass_windPointer *w;
1911 if (!m) /* Do we have to create the menu? */
1913 m=menu_new("Glass",msgs_lookup("tfM"));
1914 disp=menu_new(msgs_lookup("tfDSPT"),
1915 msgs_lookup("tfDSPM"));
1916 windsm=menu_new("_",msgs_lookup("tfWS"));
1917 #ifdef glass_NOTLAZY
1918 stylesm=menu_new(msgs_lookup("tfISST:Icon styles"),
1919 msgs_lookup("tfISS:"
1924 menu_submenu(m,glass_TFSEL,windsm);
1925 #ifdef glass_NOTLAZY
1926 menu_submenu(m,glass_TFSTYLES,stylesm);
1928 menu_submenu(m,glass_TFDISP,disp);
1929 menu_redirectItem(m,glass_TFSEL,windName,50,0);
1932 viewer_setupMenu(t->v,
1933 msgs_lookup("tfWIN"),
1937 switch (viewer_selected(t->v))
1940 menu_setflags(m,glass_TFCLRSEL,FALSE,TRUE);
1941 menu_setflags(m,glass_TFSELALL,FALSE,!viewer_icons(t->v));
1942 menu_settitle(windsm,msgs_lookup("tfWIN"));
1943 menu_setflags(windsm,glass_TFSELINFO,FALSE,TRUE);
1944 menu_setflags(windsm,glass_TFSELEDIT,FALSE,TRUE);
1945 menu_setflags(windsm,glass_TFSELCOPY,FALSE,TRUE);
1946 menu_setflags(windsm,glass_TFSELRENAME,FALSE,TRUE);
1947 menu_setflags(windsm,glass_TFSELSAVE,FALSE,TRUE);
1948 menu_setflags(windsm,glass_TFSELDELETE,FALSE,TRUE);
1951 w=viewer_iconHandle(viewer_firstSelected(t->v));
1952 menu_setflags(m,glass_TFCLRSEL,FALSE,FALSE);
1953 menu_setflags(m,glass_TFSELALL,FALSE,FALSE);
1954 menu_settitle(windsm,msgs_lookup("tfWIN"));
1955 menu_setflags(windsm,glass_TFSELINFO,FALSE,FALSE);
1957 menu_setflags(windsm,glass_TFSELEDIT,FALSE,w->testMode);
1959 menu_setflags(windsm,glass_TFSELEDIT,FALSE,FALSE);
1961 menu_setflags(windsm,glass_TFSELCOPY,FALSE,FALSE);
1962 menu_setflags(windsm,glass_TFSELRENAME,FALSE,FALSE);
1963 menu_setflags(windsm,glass_TFSELSAVE,FALSE,FALSE);
1964 menu_setflags(windsm,glass_TFSELDELETE,FALSE,FALSE);
1967 menu_setflags(m,glass_TFCLRSEL,FALSE,FALSE);
1968 menu_setflags(m,glass_TFSELALL,FALSE,FALSE);
1969 menu_settitle(windsm,msgs_lookup("tfSEL"));
1970 menu_setflags(windsm,glass_TFSELINFO,FALSE,FALSE);
1971 menu_setflags(windsm,glass_TFSELEDIT,FALSE,TRUE);
1972 menu_setflags(windsm,glass_TFSELCOPY,FALSE,TRUE);
1973 menu_setflags(windsm,glass_TFSELRENAME,FALSE,TRUE);
1974 menu_setflags(windsm,glass_TFSELSAVE,FALSE,FALSE);
1975 menu_setflags(windsm,glass_TFSELDELETE,FALSE,FALSE);
1978 menu_setflags(m,glass_TFSHWSPR,FALSE,!t->vs);
1979 menu_setflags(m,glass_TFGRAB,FALSE,window_grabbing());
1980 menu_setflags(disp,glass_TFDLARGE,t->isz==gPrefs_LARGE,FALSE);
1981 menu_setflags(disp,glass_TFDSMALL,t->isz==gPrefs_SMALL,FALSE);
1982 menu_setflags(disp,glass_TFDSORTNAME,t->sort==gPrefs_NAME,FALSE);
1983 menu_setflags(disp,glass_TFDSORTSIZE,t->sort==gPrefs_SIZE,FALSE);
1984 menu_setflags(disp,glass_TFDSORTICONS,t->sort==gPrefs_ICONS,FALSE);
1985 menu_setflags(disp,glass_TFDNOSORT,t->sort==gPrefs_NOSORT,FALSE);
1990 * void tfile__simMenu(glass_tfile *t,int hit1,int hit2)
1993 * Simulates a menu hit on a template file window
1996 * glass_tfile *t == the template file the event is destined for
1997 * int hit1 == the main menu entry number
1998 * int hit2 == the submenu entry number
2001 static void tfile__simMenu(glass_tfile *t,int hit1,int hit2)
2003 wimp_menustr *m=menu_syshandle(tfile__tfileMenuMaker(t));
2004 wimp_menuitem *i=(wimp_menuitem *)(m+1)+(hit1-1);
2010 if ((int)i->submenu==-1 || hit2==0)
2012 if (i->iconflags & wimp_INOSELECT)
2022 i=(wimp_menuitem *)(i->submenu+1)+(hit2-1);
2023 if (i->iconflags & wimp_INOSELECT)
2029 tfile__tfileMenuHandler(mnu,t);
2033 * BOOL tfile__dragUnknowns(wimp_eventstr *e,void *handle)
2036 * Handles unknown events during the period of dragging viewer icons
2037 * around. It will respond to the following drags:
2039 * A drag to a blank area of icon bar will open the windows.
2041 * Otherwise, a selection save will be started, and the windows packaged
2042 * off to another application.
2045 * wimp_eventstr *e == the event to look at
2046 * void *handle == the template file we're dragging from
2049 * TRUE if the drag has been processed
2052 static BOOL tfile__dragUnknowns(wimp_eventstr *e,void *handle)
2054 glass_tfile *t=handle;
2059 case wimp_EUSERDRAG:
2061 win_remove_unknown_event_processor(tfile__dragUnknowns,t);
2062 wimpt_noerr(wimp_get_point_info(&m));
2063 if (m.w==viewer_syshandle(t->v))
2065 if (m.w==-2 && m.i==-1)
2066 viewer_doForIcons(t->v,TRUE,tfile__openWindows);
2069 tfile__selectSize=0;
2070 viewer_doForIcons(t->v,TRUE,tfile__size);
2071 wimpt_fake_event(e); /* Fool xfersend to send data */
2073 msgs_lookup("tfSEL"),
2075 tfile__saveSelection,
2076 tfile__sendSelection,
2081 viewer_selectAll(t->v,FALSE);
2088 * BOOL tfile__raw(viewer v,wimp_eventstr *e,void *handle)
2091 * Handles intMsgs from other parts of the system
2094 * viewer v == the handle for the viewer window
2095 * wimp_eventstr *e == the event to process
2096 * void *handle == the template file
2099 * TRUE if event was processed
2102 static BOOL tfile__raw(viewer v,wimp_eventstr *e,void *handle)
2109 glass_tfile *t=handle;
2114 switch (e->data.key.chcode)
2116 case akbd_Fn+1+akbd_Sh: /* sF1 */
2117 tfile__simMenu(t,glass_TFINFO,0);
2121 tfile__simMenu(t,glass_TFSELALL,0);
2125 tfile__simMenu(t,glass_TFCLRSEL,0);
2128 case akbd_Fn+3: /* F3 */
2129 tfile__simMenu(t,glass_TFSAVE,0);
2133 tfile__simMenu(t,glass_TFCREATE,0);
2137 tfile__simMenu(t,glass_TFGRAB,0);
2141 tfile__simMenu(t,glass_TFSHWSPR,0);
2145 case akbd_Fn+5: /* F5 */
2146 tfile__simMenu(t,glass_TFDISP,glass_TFDLARGE);
2149 case akbd_Fn+5+akbd_Sh: /* sF5 */
2150 tfile__simMenu(t,glass_TFDISP,glass_TFDSMALL);
2153 case akbd_Fn+6: /* F6 */
2154 tfile__simMenu(t,glass_TFDISP,glass_TFDSORTNAME);
2157 case akbd_Fn+6+akbd_Sh: /* sF6 */
2158 tfile__simMenu(t,glass_TFDISP,glass_TFDSORTSIZE);
2161 case akbd_Fn+6+akbd_Ctl:/* ^F6 */
2162 tfile__simMenu(t,glass_TFDISP,glass_TFDSORTICONS);
2165 case akbd_Fn+6+akbd_Ctl+akbd_Sh:/* s^F6 */
2166 tfile__simMenu(t,glass_TFDISP,glass_TFDNOSORT);
2170 case akbd_Fn+1+akbd_Ctl:/* ^F1 */
2171 tfile__simMenu(t,glass_TFSEL,glass_TFSELINFO);
2175 tfile__simMenu(t,glass_TFSEL,glass_TFSELEDIT);
2179 tfile__simMenu(t,glass_TFSEL,glass_TFSELCOPY);
2183 tfile__simMenu(t,glass_TFSEL,glass_TFSELRENAME);
2186 case akbd_Fn+3+akbd_Sh: /* sF3 */
2187 tfile__simMenu(t,glass_TFSEL,glass_TFSELSAVE);
2191 tfile__simMenu(t,glass_TFSEL,glass_TFSELDELETE);
2195 case akbd_Fn+2+akbd_Ctl:/* ^F2 */
2196 tfile__close(t,FALSE);
2202 case wimp_ESENDWANTACK:
2203 switch (e->data.msg.hdr.action)
2205 case wimp_MDATASAVE:
2206 filetype=xferrecv_checkimport(&estsize);
2209 case 0xfec: /* Template files */
2210 if (xferrecv_returnImportedBlock(&p)!=-1)
2212 tfile_markAsAltered(t);
2213 tfile_mergeFromMemory(&p,t);
2217 case 0xff9: /* Sprite files (I think) */
2220 if (xferrecv_returnImportedBlock(&p)!=-1)
2222 gSprite_mergeFromMemory(t,&p);
2229 case wimp_MDATALOAD:
2230 filetype=xferrecv_checkinsert(&filename);
2233 case 0xfec: /* Template files */
2234 tfile_mergeFromFile(filename,t);
2235 tfile_markAsAltered(t);
2236 xferrecv_insertfileok();
2238 case 0xff9: /* Sprite files (I think) */
2241 gSprite_mergeFromFile(t,filename);
2242 xferrecv_insertfileok();
2247 case wimp_MINTERNAL:
2248 switch (e->data.msg.data.words[0])
2250 case glass_KILLFILES:
2251 tfile__deleteTemplateFile(t);
2253 case glass_CLOSEDOWN:
2254 viewer_doForIcons(v,FALSE,tfile__tidyFonts);
2257 case glass_MODECHANGE:
2258 viewer_doForIcons(v,FALSE,tfile__reFindFonts);
2261 case glass_AUTOSAVE:
2263 alarm_remove(t->autoAlarm,t);
2267 if (at=gPrefs_autoTiming(),at)
2269 t->autoAlarm=t->autoTime+at;
2270 alarm_set(t->autoAlarm,tfile__doAutosave,t);
2273 if (gPrefs_current()->aAlts!=0 &&
2274 t->alts>=gPrefs_current()->aAlts)
2275 tfile__doAutosave(0,t);
2286 * void tfile__tfileHandler(viewer v,
2293 * Handles events for a template file window (including things like menu
2297 * viewer v == the viewer that the event happened to
2298 * viewer_icon i == the icon it happened to
2299 * wimp_bbits b == the mouse button status
2300 * void *vhandle == pointer to the template file structure
2301 * void *ihandle == pointer to the window pointer structure
2304 static void tfile__tfileHandler(viewer v,
2310 glass_tfile *t=vhandle;
2311 glass_windPointer *wp=ihandle;
2314 case (int)viewer_CLOSE: /* If the user closes the window */
2315 tfile__close(t,TRUE); /* Try to close it :-) */
2317 case (int)viewer_HELP: /* Help request for the window */
2318 help_startHelp(); /* Prepare a reply */
2319 help_addLine(msgs_lookup("tfhTF"));
2320 help_endHelp(); /* Send the message to Help application */
2325 tfile__gainSelection(t);
2326 viewer_clickSelect(v,i,b);
2331 if (t==tfile__selOwner ||
2333 !viewer_selected(tfile__selOwner->v) )
2336 viewer_clickSelect(v,i,b);
2338 menu_make(tfile__tfileMenuMaker,
2339 tfile__tfileMenuHandler,
2340 tfile__tfileMenuHelp,
2344 if (i!=viewer_NOICON)
2346 if (akbd_pollsh() && wp->h)
2349 window_open(wp,FALSE); /* Open the window on-screen */
2350 viewer_selectIcon(i,FALSE); /* And deslect the icon */
2354 if (i!=viewer_NOICON)
2356 if (akbd_pollsh() && wp->h)
2359 window_open(wp,TRUE); /* Open the window on-screen */
2360 viewer_selectIcon(i,FALSE); /* And deslect the icon */
2363 case wimp_BDRAGLEFT:
2364 case wimp_BDRAGRIGHT:
2365 if (i!=viewer_NOICON)
2367 tfile_dragSelected(i,b,"tpackage");
2368 win_add_unknown_event_processor(tfile__dragUnknowns,t);
2376 /*----- External routines -------------------------------------------------*/
2379 * BOOL tfile_okToQuit(BOOL ask)
2382 * Ensures that it is 'safe' for Glass to quit.
2385 * BOOL ask == should I open a dialogue to ask the user?
2388 * TRUE if it is safe to quit, or FALSE if not.
2391 BOOL tfile_okToQuit(BOOL ask)
2394 if (tfile__unsavedFiles==0 || !gPrefs_current()->cQuit)
2396 else if (ask==FALSE)
2398 else if (tfile__unsavedFiles==1)
2399 q=msgs_lookup("tfOTQ1");
2401 q=msgs_lookup("tfOTQM");
2402 return (warning(msgs_lookup("tfOTQP"),q,tfile__unsavedFiles));
2406 * void tfile_markAsAltered(glass_tfile *t)
2409 * Marks down another alteration for the template file, changing the window
2410 * title if required etc. Also handles stuff for autosave etc.
2413 * glass_tfile *t == the template file to alter
2416 void tfile_markAsAltered(glass_tfile *t)
2421 if (t->alts==1 || t->alts==0)
2423 sprintf(buff,"%s *",t->filename);
2424 viewer_settitle(t->v,buff);
2426 tfile__unsavedFiles++;
2429 if (t->sort==gPrefs_SIZE || t->sort==gPrefs_ICONS)
2430 viewer_setCompare(t->v,tfile__sort);
2433 t->autoTime=alarm_timenow();
2434 if (at=gPrefs_autoTiming(),at)
2436 t->autoAlarm=t->autoTime+at;
2437 alarm_set(t->autoAlarm,tfile__doAutosave,t);
2442 if (gPrefs_current()->aAlts!=0 && t->alts>=gPrefs_current()->aAlts)
2443 tfile__doAutosave(0,t);
2447 * void tfile_markAsSaved(glass_tfile *t,char *newTitle)
2450 * Marks a template file as having been saved. Turns off autosave and
2454 * glass_tfile *t == the file to mark
2455 * char *newtitle == the new title to give to the window
2458 void tfile_markAsSaved(glass_tfile *t,char *newTitle)
2464 tfile__unsavedFiles--;
2467 strcpy(t->filename,newTitle);
2468 viewer_settitle(t->v,newTitle);
2469 intMsgs_send(glass_SAVEFILE,t);
2472 sprintf(buff,msgs_lookup("spVT"),newTitle);
2473 viewer_settitle(t->vs,buff);
2476 alarm_remove(t->autoAlarm,t);
2481 dbox_deleteNoUpdate(t->autod);
2488 * void tfile_windowInfo(glass_windPointer *w)
2491 * Displays an info box for a single window
2494 * glass_windPointer *w == the window to display info on
2497 void tfile_windowInfo(glass_windPointer *w)
2499 dbox d=dbox_create("windInfo");
2502 dbox_setfield(d,glass_WINAME,"%s",w->id);
2503 dbox_setfield(d,glass_WISIZE,"%s",utils_cvtSize(w->size));
2507 utils_cvtSize(w->size-
2508 sizeof(glass_window)-
2509 (w->def->desc.w.nicons-1)*
2510 sizeof(glass_iconDescription)));
2511 dbox_setfield(d,glass_WIICONS,"%i",w->def->desc.w.nicons);
2516 * void tfile_deleteWindow(glass_windPointer *w)
2519 * Deletes a single window.
2522 * viewer_icon i == the icon to get
2523 * void *handle == the window to eliminate (as a glass_windPointer *)
2526 void tfile_deleteWindow(viewer_icon i,void *handle)
2528 glass_windPointer *w=handle;
2530 intMsgs_send(glass_DELETEWINDOW,w);
2531 viewer_removeIcon(w->i);
2532 tfile__doDeleteWindow(w);
2536 * BOOL tfile_rename(char *newName,void *handle)
2539 * Renames the specified window
2542 * char *newName == the new name of the window
2543 * void *handle == pointer to the window structure
2546 BOOL tfile_rename(char *newName,void *handle)
2548 glass_windPointer *w=handle;
2550 if (strcmp(newName,w->id)==0)
2552 i=viewer_findIcon(w->t->v,newName);
2553 if (i==viewer_NOICON || i==w->i)
2555 viewer_removeIcon(w->i);
2556 mem_useUser(indir_alloc,indir_free);
2557 strcpy(w->id,newName);
2558 i=viewer_addIcon(w->t->v,newName,"tmpltvicon",TRUE,w);
2559 viewer_setFiletype(i,0xfec);
2562 intMsgs_send(glass_RENAME,w);
2563 tfile_markAsAltered(w->t);
2564 event_clear_current_menu();
2567 note(msgs_lookup("tfNAE"),
2568 viewer_textOfIcon(i));
2573 * void tfile_saveTemplates(glass_tfile *t)
2576 * Saves a template file using a standard dialogue box
2579 * glass_tfile *t == the template file to save
2582 void tfile_saveTemplates(glass_tfile *t)
2588 name=msgs_lookup("tfTMP");
2589 tfile__selectSize=0;
2590 viewer_doForIcons(t->v,FALSE,tfile__size);
2591 saveas(msgs_lookup("tfSVTIT"),
2595 tfile__saveTemplates,
2596 tfile__sendTemplates,
2602 * void tfile_saveWindow(glass_windPointer *w)
2605 * Saves a single window using a standard dialogue box
2608 * glass_windPointer *w == pointer to the window to save
2611 void tfile_saveWindow(glass_windPointer *w)
2613 tfile__selectSize=w->size;
2614 saveas(msgs_lookup("tfSVWTIT"),
2615 msgs_lookup("tfWIN"),
2625 * BOOL tfile_mergeFromMemory(void **p,glass_tfile *t)
2628 * Actually does a merge operation. The target file is a glass_tfile in
2629 * memory (internal format) and the source file is a memory image of a
2630 * normal template file.
2633 * void **p == a flex anchor pointer to the source file
2634 * glass_tfile *t == a pointer to the destination file
2640 typedef struct { char **p; int offset; } tfile__datPackage;
2642 static char *tfile__dataProc(char *data,void *handle)
2644 tfile__datPackage *p=handle;
2645 return (((int)data)+*(p->p)+p->offset);
2648 BOOL tfile_mergeFromMemory(void **p,glass_tfile *t)
2650 int fontData; /* Offset of font ata from start of file */
2651 glass_windPointer *w; /* For each window we come across */
2652 int index; /* Current index entry we're looking at */
2653 int objoff; /* Offset of window we're looking at */
2654 int iconoff; /* Offset of icon we're looking at */
2655 wimp_iconflags icf; /* Icon flags for something or other */
2656 int fheight; /* Height of a font required */
2657 int fwidth; /* Width of a font required */
2658 int fhandle; /* Font handle */
2659 int fptr; /* Offset of font name */
2660 char name[13]; /* For the name of the template */
2662 int objtype; /* Type of current template entry */
2663 BOOL foundOdd=FALSE; /* Found an odd type of data yet? */
2664 int numicons; /* Number of icons in a window */
2665 int i; /* A loop counter */
2666 viewer_icon icn; /* Icon for checking for duplicates */
2667 BOOL fquiet=FALSE; /* Shut up about font failures. */
2668 tfile__datPackage pk;
2670 fontData=*intptr(*p,0); /* Offset of font data from *p */
2671 for (index=16;*intptr(*p,index);index+=24) /* Go through index entries */
2673 objoff=*intptr(*p,index); /* Offset of this entry */
2674 objtype=*intptr(*p,index+8); /* Type of this entry */
2675 switch (objtype) /* Which type is it? */
2677 case 1: /* Window */
2681 memcpy(name,charptr(*p,index+12),12);
2683 utils_ctermToNterm(name);
2684 if (icn=viewer_findIcon(t->v,name),icn)
2685 tfile_deleteWindow(icn,viewer_iconHandle(icn));
2686 if (w=tfile__newWindow(t,name),!w)
2687 return (FALSE); /* Failed to create the window */
2688 memcpy(&numicons,intptr(*p,objoff+84),sizeof(int));
2689 w->size=sizeof(glass_window)+
2690 (numicons-1)*sizeof(glass_iconDescription);
2691 if (!flex_alloc((flex_ptr)&w->def,w->size))
2693 viewer_removeIcon(w->i);
2695 werr(FALSE,msgs_lookup("tfNEMTL"));
2698 memcpy(&w->def->desc.w,_ptr(void,*p,objoff),sizeof(wimp_wind));
2699 icf=w->def->desc.w.titleflags; /* Get title icon flags */
2700 if (icf & wimp_IFONT) /* Handle anti-aliased fonts */
2702 fhandle=(icf & 0xff000000) >> 24; /* Get internal font handle */
2703 fptr=fontData+(fhandle-1)*48; /* Get pointer */
2704 /* Bug fix - not word aligned!! */
2705 memcpy(&fwidth,intptr(*p,fptr)+0,sizeof(int));
2706 memcpy(&fheight,intptr(*p,fptr)+1,sizeof(int));
2707 utils_ctermToNterm(charptr(*p,fptr+8)); /* Font name */
2708 if (font_find(charptr(*p,fptr+8),fwidth,fheight,0,0,&fhandle))
2712 werr(FALSE,msgs_lookup("tfCFF"));
2715 icf&=~wimp_IFONT; /* Stop anti-aliasing (gives odd colours) */
2719 icf=(icf & 0x00ffffff) | (fhandle << 24);
2720 w->antiAliased=TRUE;
2721 w->fonts[fhandle]++;
2723 w->def->desc.w.titleflags=icf;
2725 w->def->desc.w.nicons=0; /* Don't want deletion routine dying */
2726 if (!iconData_processIcon(w,-1,tfile__dataProc,TRUE,&pk))
2728 werr(FALSE,msgs_lookup("tfNEMTL"));
2729 tfile_deleteWindow(0,w);
2732 iconoff=objoff+88; /* Point to first icon definition */
2733 for (i=0;i<numicons;i++)
2735 memcpy(&w->def->i[i].i,charptr(*p,iconoff),sizeof(wimp_icon));
2736 w->def->i[i].selected=FALSE;
2737 w->def->i[i].edit=0;
2738 icf=w->def->i[i].i.flags; /* Get title icon flags */
2739 if (icf & wimp_IFONT) /* Handle anti-aliased fonts */
2741 fhandle=(icf & 0xff000000) >> 24; /* Get internal font handle */
2742 fptr=fontData+(fhandle-1)*48; /* Get pointer */
2743 /* Bug fix - not word aligned!! */
2744 memcpy(&fwidth,intptr(*p,fptr)+0,sizeof(int));
2745 memcpy(&fheight,intptr(*p,fptr)+1,sizeof(int));
2746 utils_ctermToNterm(charptr(*p,fptr+8)); /* Font name */
2747 if (font_find(charptr(*p,fptr+8),fwidth,fheight,0,0,&fhandle))
2751 werr(FALSE,msgs_lookup("tfCFF"));
2754 icf&=~wimp_IFONT; /* Stop anti-aliasing */
2758 icf=(icf & 0x00ffffff) | (fhandle << 24);
2759 w->antiAliased=TRUE;
2760 w->fonts[fhandle]++;
2762 w->def->i[i].i.flags=icf;
2764 if (!iconData_processIcon(w,i,tfile__dataProc,TRUE,&pk))
2766 werr(FALSE,msgs_lookup("tfNEMTL"));
2767 tfile_deleteWindow(0,w);
2770 w->def->desc.w.nicons++; /* Tidy up next icon along */
2771 iconoff+=sizeof(wimp_icon); /* Move pointer along */
2774 default: /* Anything we don't know - tell the user */
2775 if (!foundOdd) /* Don't generate the message again */
2777 werr(FALSE,msgs_lookup("tfUTEC"));
2778 foundOdd=TRUE; /* Stop message repeating */
2787 * BOOL tfile_mergeFromFile(char *file,glass_tfile *t)
2790 * Merges the template file given into the given template file structure.
2793 * char *file == the file to load
2794 * glass_tfile *t == the template file structure to merge with
2797 BOOL tfile_mergeFromFile(char *file,glass_tfile *t)
2799 os_filestr f; /* Going to make some OS_File calls */
2800 void *p; /* p will point to the file in memory */
2801 f.action=17; /* Read catalogue information for file */
2802 f.name=file; /* Point to file name to find out about */
2803 if (utils_complain(os_file(&f),
2804 msgs_lookup("tfELF")))
2808 if (!flex_alloc(&p,f.start))
2810 werr(FALSE,msgs_lookup("tfNEMTL"));
2813 f.action=16; /* Load the file */
2814 f.loadaddr=(int)p; /* Where to load the file */
2815 f.execaddr=0; /* Load it there!!! */
2816 if (utils_complain(os_file(&f),
2817 msgs_lookup("tfELF")))
2823 tfile_mergeFromMemory(&p,t); /* Now do the merge */
2830 * glass_tfile *tfile_createTemplateFile(char *name)
2833 * Creates a template file with the given name, but doesn't open its viewer.
2836 * A pointer to the file structure, or zero as failure.
2839 glass_tfile *tfile_createTemplateFile(char *name)
2843 mem_useUser(indir_alloc,indir_free);
2844 t=mem_alloc(sizeof(glass_tfile));
2845 if (!t) /* Allocates memory for file structure */
2847 werr(FALSE,msgs_lookup("tfNEMTF"));
2851 ix=(gPrefs_current()->fIcons==gPrefs_LARGE) ? 200 : 248;
2852 iy=(gPrefs_current()->fIcons==gPrefs_LARGE) ? 112 : 36;
2855 t->v=viewer_create /* Now create the viewer window */
2857 tfile__FILEX, /* Coords to open window */
2859 ix, /* Width of 'icons' */
2860 iy, /* Height of 'icons' */
2861 resspr_area(), /* Sprite area for 'icons' */
2862 name, /* What to display in the title bar */
2863 msgs_lookup("tfBANR") /* Viewer banner line */
2865 !t->v /* TRUE if creation failed */
2868 mem_free(t); /* Dispose of unwanted file structure */
2870 return (0); /* Inform caller we buggered it up */
2873 strcpy(t->filename,name); /* Remember the name */
2874 t->alts=0; /* No alterations yet */
2875 t->loaded=FALSE; /* They can change this if they need to */
2876 t->autoSaved=FALSE; /* Not been autosaved yet */
2877 t->autod=0; /* No autosave dialogue box */
2878 t->autoTime=0; /* No autosave time */
2879 t->autoAlarm=0; /* No autosave alarm */
2880 t->isz=gPrefs_current()->fIcons;
2881 t->sort=gPrefs_current()->fSort;
2882 viewer_eventHandler(t->v,tfile__tfileHandler,t); /* Add event handler */
2883 viewer_rawEventHandler(t->v,tfile__raw,t); /* Raw, for broadcasts */
2884 viewer_redrawHandler(t->v,
2885 t->isz==gPrefs_LARGE ? 0 : tfile__redrawViewer,
2887 viewer_setCompare(t->v,tfile__sort);
2888 tfile__fileHeight-=48; /* Displace the next file window */
2889 if (tfile__fileHeight<652) /* Start at the top again if too low */
2890 tfile__fileHeight=tfile__FILETOP;
2896 * glass_tfile *tfile_loadFromMemory(void **p,char *name)
2899 * Loads a file from memory, i.e. from another application via RAM
2903 * void **p == the memory block that contains the file to load.
2904 * char *name == the name to give to the file.
2907 * A pointer to the template file, or 0
2910 glass_tfile *tfile_loadFromMemory(void **p,char *name)
2912 glass_tfile *t=tfile_createTemplateFile(name);
2916 if (!tfile_mergeFromMemory(p,t))
2918 tfile__deleteTemplateFile(t);
2921 if (t->sort==gPrefs_SIZE || t->sort==gPrefs_ICONS)
2922 viewer_setCompare(t->v,tfile__sort);
2923 viewer_display(t->v); /* Show the viewer window in its glory */
2928 * glass_tfile *tfile_loadFromFile(char *file,char *name)
2931 * Loads a template file into memory, translating the file into Glass's
2932 * internal format. It does not create any windows, although it does
2933 * allocate font handles.
2936 * char *file == the name of the file to load
2937 * char *name == the name to insert in the title bar
2940 * A pointer to the structure definition, or 0 for failure. Note that this
2941 * will only occur if no windows could be loaded.
2944 glass_tfile *tfile_loadFromFile(char *file,char *name)
2946 glass_tfile *t=tfile_createTemplateFile(name);
2953 if (!tfile_mergeFromFile(file,t))
2955 tfile__deleteTemplateFile(t);
2959 utils_leafname(fbuff)[-1]=0;
2960 parent=utils_leafname(fbuff);
2962 if (gPrefs_current()->sLoadPSpr)
2964 sprintf(buff,"%s.%s.!Sprites",fbuff,parent);
2965 if (res_fileExists(buff))
2966 gSprite_mergeFromFile(t,buff);
2969 sprintf(buff,"%s.!Sprites",fbuff);
2970 if (res_fileExists(buff))
2971 gSprite_mergeFromFile(t,buff);
2974 if (gPrefs_current()->sLoadSpr)
2976 sprintf(buff,"%s.%s.Sprites",fbuff,parent);
2977 if (res_fileExists(buff))
2978 gSprite_mergeFromFile(t,buff);
2980 viewer_display(t->v); /* Show the viewer window in its glory */
2985 * void tfile_dragSelected(viewer_icon i,wimp_bbits b,char *package)
2988 * As for viewer_dragSelected, but uses the specified sprite as the
2989 * 'package' sprite is solid sprite drags are enabled.
2992 * viewer_icon i == the icon to drag
2993 * wimp_bbits b == the button status that started it off
2994 * char *package == the sprite to use for a package drag
2997 void tfile_dragSelected(viewer_icon i,wimp_bbits b,char *package)
3002 sprite_rename(resspr_area(),&sid,"package");
3003 viewer_dragSelected(i,b);
3004 sid.s.name="package";
3005 sprite_rename(resspr_area(),&sid,package);