/* * tfile.c * * Control of template files * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Glass. * * Glass is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Glass is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Glass. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ /* * ANSI standard headers */ #include #include #include /* * Steel headers */ #define _STDAPP #define _XFER #define _LOWLVL #include "steel/Steel.h" #include "steel/viewer.h" #include "steel/mem.h" #include "steel/nopoll.h" #include "steel/flex.h" #include "steel/akbd.h" #include "steel/alarm.h" #include "steel/bbc.h" #include "steel/buffer.h" #include "steel/font.h" /* * Glass headers */ #include "gStruct.h" #include "gIcons.h" #include "gMenus.h" #include "glass.h" #include "toolbox.h" #include "intMsgs.h" #include "tfile.h" #include "gPrefs.h" #include "gSprite.h" #include "indir.h" #include "window.h" #include "editWin.h" #include "iconData.h" /*----- Constants ---------------------------------------------------------*/ #define tfile__FILEHEIGHT 892 /* Height to open first template window */ #define tfile__FILEX 200 /* x position of template file windows */ #define tfile__FILETOP 940 /* Height after files wrap around */ #define tfile__WINDHEIGHT 872 /* Height to create first window */ #define tfile__WINDX 450 /* x position of template windows */ #define tfile__WINDTOP 920 /* Height after windows wrap around */ /*----- Static global variables -------------------------------------------*/ static int tfile__unsavedFiles; /* Number of files not saved */ static int tfile__fileHeight=tfile__FILEHEIGHT; /* Height to open next template window */ static int tfile__windHeight=tfile__WINDHEIGHT; static int tfile__selectSize; /* Size in bytes of current selection */ static int tfile__selectIcons; /* Number of icons in current selection */ static int tfile__selectIndSz; /* Indirected data size for selection */ static char tfile__grabName[15]; /* Name for the grabbed window */static glass_tfile *tfile__selOwner; /* Owner of the current selection */ /*----- Support routines --------------------------------------------------*/ /* * void tfile__tidyFonts(viewer_icon i,void *handle) * * Use * Closes down the fonts on a particular template file. * * Parameters * viewer_icon i == the icon (ignored) * void *handle == the file to close */ static void tfile__tidyFonts(viewer_icon ic,void *handle) { int i,j; glass_windPointer *w=handle; unused(ic); if (w->antiAliased) { for (i=0;i<256;i++) { for (j=0;jfonts[i];j++) wimpt_noerr(font_lose(i)); } } w->antiAliased=FALSE; } /* * void tfile__reFindFonts(viewer_icon ic,void *handle) * * Use * Scans the given window, refinding all the fonts it used. This is * because (at present) on a mode change, the aspect ratio can become * utterly trashed. I can't afford to wait until the Font Manager gets * rewritten to work properly, so I have to do it myself... * * After this call, the window needs recreating if it's being displayed. * It will pick up the Open_Window_Request, and recreate on that if it * finds it has some fonts in it. * * This call also resets the antiAliased flag if it finds no fonts in a * window. * * Parameters * viewer_icon ic == the viewer icon of the window to rescan (ignored) * void *handle == an undercover glass_windPointer * to the window */ static void tfile__reFindFonts(viewer_icon ic,void *handle) { glass_windPointer *w=handle; int i; int icf; os_regset r; int fhand; int newhand; BOOL usedAFont=FALSE; char buff[50]; unused(ic); if (!w->antiAliased) return; icf=w->def->desc.w.titleflags; if (icf & wimp_IFONT) { usedAFont=TRUE; fhand=(icf>>24) & 0xff; r.r[0]=fhand; r.r[1]=(int)buff; wimpt_noerr(os_swix(XFont_ReadDefn,&r)); r.r[4]=r.r[5]=0; if (!wimpt_complain(os_swix(XFont_FindFont,&r))) { newhand=r.r[0]; r.r[0]=fhand; wimpt_noerr(os_swix(XFont_LoseFont,&r)); w->fonts[fhand]--; w->fonts[newhand]++; w->def->desc.w.titleflags=(icf & 0x00ffffff) | (newhand<<24); } } for (i=0;idef->desc.w.nicons;i++) { icf=w->def->i[i].i.flags; if (icf & wimp_IFONT) { usedAFont=TRUE; fhand=(icf>>24) & 0xff; r.r[0]=fhand; r.r[1]=(int)buff; wimpt_noerr(os_swix(XFont_ReadDefn,&r)); r.r[4]=r.r[5]=0; if (!wimpt_complain(os_swix(XFont_FindFont,&r))) { newhand=r.r[0]; r.r[0]=fhand; wimpt_noerr(os_swix(XFont_LoseFont,&r)); w->fonts[fhand]--; w->fonts[newhand]++; w->def->i[i].i.flags=(icf & 0x00ffffff) | (newhand<<24); } } } w->antiAliased=usedAFont; } /* * void tfile__gainSelection(glass_tfile *t) * * Use * Hands the current tfile selection and the input focus to the specified * template file. * * Note that the selection model here is more complex than it is in window, * since the focus tfile may not coincide with the selection owner (since * menu clicks move the selection owner, but not the focus). * * Parameters * glass_tfile *t == the template to which we give the focus */ static void tfile__gainSelection(glass_tfile *t) { wimp_caretstr c; if (t!=tfile__selOwner) { if (tfile__selOwner) viewer_selectAll(tfile__selOwner->v,FALSE); tfile__selOwner=t; } if (t) { c.w=viewer_syshandle(t->v); c.i=-1; c.x=-250; c.y=0; c.index=-1; c.height=0x02000000; wimpt_noerr(wimp_set_caret_pos(&c)); } } /* * void tfile__doDeleteWindow(void *handle) * * Use * Deletes, trashes and exterminates a window. * * Parameters * void *handle == the window to eliminate */ static void tfile__doDeleteWindow(void *handle) { int i; glass_windPointer *w=handle; window_hasBeenDeleted(w); if (w->def->desc.w.titleflags & wimp_INDIRECT) { indir_free(w->def->desc.w.title.indirecttext.buffer); if ((w->def->desc.w.titleflags & wimp_ITEXT) && (w->def->desc.w.title.indirecttext.validstring!=(char *)-1)) indir_free(w->def->desc.w.title.indirecttext.validstring); } for (i=0;idef->desc.w.nicons;i++) { if (w->def->i[i].i.flags & wimp_INDIRECT) { indir_free(w->def->i[i].i.data.indirecttext.buffer); if ((w->def->i[i].i.flags & wimp_ITEXT) && (w->def->i[i].i.data.indirecttext.validstring!=(char *)-1)) indir_free(w->def->i[i].i.data.indirecttext.validstring); } } if (w->def) flex_free((flex_ptr)&w->def); if (w->h) { win_register_event_handler(w->h,0,0); win_activedec(); wimpt_noerr(wimp_delete_wind(w->h)); } tfile__tidyFonts(0,w); mem_free(w); } /* * void tfile__deleteTemplateFile(void *handle) * * Use * Trashes the named template file. * * Parameters * void *handle == the template file to murder */ static void tfile__deleteTemplateFile(void *handle) { glass_tfile *t=handle; intMsgs_send(glass_DELETEFILE,t); if (t==tfile__selOwner) tfile__selOwner=0; gSprite_kill(t); if (t->alts) tfile__unsavedFiles--; viewer_delete(t->v,tfile__doDeleteWindow); if (t->autod) dbox_delete(t->autod); if (t->autoAlarm) alarm_remove(t->autoAlarm,t); mem_free(t); flex_compact(); } /* * glass_windPointer *tfile__newWindow(glass_tfile *t,char *name) * * Use * Creates a new window entry in the template file specified. It is up to * the caller to write the window definition. * * Parameters * glass_tfile *t == the template file to add the window to * char *name == the name of the window * * Returns * A pointer to the window structure */ static glass_windPointer *tfile__newWindow(glass_tfile *t,char *name) { glass_windPointer *w; int i; static int serial; /* Serial number - monotonic increasing */ mem_useUser(indir_alloc,indir_free); w=mem_alloc(sizeof(glass_windPointer)); if (!w) { werr(FALSE,msgs_lookup("tfNEMCRT")); mem_useMalloc(); return (0); } strcpy(w->id,name); w->def=0; w->t=t; w->h=0; w->edit=0; w->size=0; w->gridx=gPrefs_current()->gWidth; w->gridy=gPrefs_current()->gHeight; w->gridShow=gPrefs_current()->gDisp; w->gridLock=gPrefs_current()->gLock; w->serial=serial++; /* Increment serial number count */ for (i=0;iguide[i].active=FALSE; w->antiAliased=FALSE; for (i=0;i<256;i++) w->fonts[i]=0; if (w->i=viewer_addIcon(t->v,name,"tmpltvicon",TRUE,w),!w->i) { mem_free(w); mem_useMalloc(); return (0); } viewer_setFiletype(w->i,0xfec); mem_useMalloc(); return (w); } /* * void tfile__size(viewer_icon i,void *handle) * * Use * Adds the size of the window given by handle to the global variables * tfile__selectSize and tfile__selectIndSz. * * Parameters * viewer_icon i == the viewer icon handle (ignored) * void *handle == the window to count */ static void tfile__size(viewer_icon i,void *handle) { glass_windPointer *w=handle; unused(i); tfile__selectSize+=w->size; tfile__selectIndSz+=w->size- sizeof(glass_window)- (w->def->desc.w.nicons-1)* sizeof(glass_iconDescription); } /* * void tfile__icons(viewer_icon i,void *handle) * * Use * Adds the number of icons in the window given by handle to the global * variable tfile__selectIcons. * * Parameters * viewer_icon i == the viewer icon handle (ignored) * void *handle == the window to count */ static void tfile__icons(viewer_icon i,void *handle) { glass_windPointer *w=handle; unused(i); tfile__selectIcons+=w->def->desc.w.nicons; } /* * BOOL tfile__create(char *new,void *handle) * * Use * Creates a new window. * * Parameters * char *new == the name for the new window * void *handle == pointer to the tfile */ static BOOL tfile__create(char *new,void *handle) { glass_tfile *t=handle; viewer_icon icn; glass_windPointer *wnew; wimp_wind *w=&template_find("default")->window; icn=viewer_findIcon(t->v,new); if (icn==viewer_NOICON) { wnew=tfile__newWindow(t,new); if (!wnew) return (FALSE); tfile_markAsAltered(t); wnew->size=sizeof(glass_window)-sizeof(glass_iconDescription); if (!flex_alloc((flex_ptr)&wnew->def,wnew->size)) { viewer_removeIcon(wnew->i); mem_free(wnew); werr(FALSE,msgs_lookup("tfNEMCRT")); return (FALSE); } wnew->def->desc.w=*w; wnew->def->desc.w.nicons=0; if (!iconData_handleFont(wnew,&wnew->def->desc.w.titleflags)) werr(FALSE,msgs_lookup("tfFERC")); if (wnew->def->desc.w.titleflags & wimp_IFONT) { wnew->antiAliased=TRUE; wnew->fonts[(wnew->def->desc.w.titleflags>>24) & 0xff]++; } if (!iconData_processIcon(wnew,-1,0,TRUE,0)) { werr(FALSE,msgs_lookup("tfNEMCRT")); tfile_deleteWindow(0,wnew); return (FALSE); } wnew->def->desc.w.box.y1=tfile__windHeight; wnew->def->desc.w.box.y0=tfile__windHeight + wnew->def->desc.w.ex.y0 - wnew->def->desc.w.ex.y1; wnew->def->desc.w.box.x0=tfile__WINDX; wnew->def->desc.w.box.x1=tfile__WINDX - wnew->def->desc.w.ex.x0 + wnew->def->desc.w.ex.x1; if (wnew->def->desc.w.box.y0def->desc.w.box.y0=tfile__windHeight-500; if (wnew->def->desc.w.box.x1>tfile__WINDX+700) wnew->def->desc.w.box.x1=tfile__WINDX+700; wnew->def->desc.w.scx=wnew->def->desc.w.ex.x0; wnew->def->desc.w.scy=wnew->def->desc.w.ex.y1; tfile__windHeight-=48; if (tfile__windHeight<632) tfile__windHeight=tfile__WINDTOP; return (TRUE); } note(msgs_lookup("tfNAE"),viewer_textOfIcon(icn)); return (FALSE); } /* * char *tfile__grabData(char *ptr,void *handle) * * Use * Grabs data from the destination task, as required when setting up a * grabbed window. * * Parameters * char *ptr == pointer to data string (in other task's workspace) * void *handle == not a pointer at all, actually the source task's handle * * Returns * A pointer to a string in my own workspace (static char array) */ static char *tfile__grabData(char *ptr,void *handle) { char *buff=buffer_find(); wimp_t t=(int)handle; if (t) { if (wimp_transferblock(t,ptr,wimpt_task(),buff,256)) return (""); } else return (""); return (buff); } /* * void tfile__grab(wimp_mousestr *m,void *handle) * * Use * Grabs a window definition, inserting it neatly into the template file. * * Parameters * wimp_mousestr *m == info about the window * void *handle == pointer to destination template file */ static void tfile__grab(wimp_mousestr *m,void *handle) { glass_tfile *t=handle; glass_windPointer *wnew; wimp_winfo *w; os_regset r; int numicons; wimp_t task; wimp_msgstr msg; int i; int ioff; BOOL fonterr=FALSE; wnew=tfile__newWindow(t,tfile__grabName); if (!wnew) return; tfile_markAsAltered(t); if (wimpt_getVersion()>=300) /* RISC OS 3 allows 'safe' GetWindowInfos */ w=mem_alloc(sizeof(wimp_winfo)); else w=mem_alloc(sizeof(wimp_winfo)+200*sizeof(wimp_icon)); if (!w) { werr(FALSE,msgs_lookup("tfNEMGW")); viewer_removeIcon(wnew->i); mem_free(wnew); return; } w->w=m->w; r.r[1]=(int)w; if (wimpt_getVersion()>=300) r.r[1]++; /* RO3 - only window header, not icons */ wimpt_noerr(os_swix(XWimp_GetWindowInfo,&r)); /* Get the information */ numicons=w->info.nicons; mem_free(w); wnew->size=sizeof(glass_window)+ (numicons-1)*sizeof(glass_iconDescription); if (!flex_alloc((flex_ptr)&w, sizeof(wimp_winfo)+numicons*sizeof(wimp_icon))) { viewer_removeIcon(wnew->i); mem_free(wnew); werr(FALSE,msgs_lookup("tfNEMGW")); return; } if (!flex_alloc((flex_ptr)&wnew->def,wnew->size)) { flex_free((flex_ptr)&w); viewer_removeIcon(wnew->i); mem_free(wnew); werr(FALSE,msgs_lookup("tfNEMGW")); return; } w->w=m->w; r.r[1]=(int)w; wimpt_noerr(os_swix(XWimp_GetWindowInfo,&r)); /* Read the window properly*/ msg.hdr.size=20; msg.hdr.your_ref=0; msg.hdr.action=0; r.r[0]=19; r.r[1]=(int)&msg; r.r[2]=m->w; r.r[3]=m->i; if (os_swix(XWimp_SendMessage,&r)) task=0; else task=r.r[2]; wnew->def->desc.w=w->info; wnew->def->desc.w.nicons=0; if (!iconData_handleFont(wnew,&wnew->def->desc.w.titleflags) && !fonterr) { werr(FALSE,msgs_lookup("tfFERG")); fonterr=TRUE; } if (!iconData_processIcon(wnew,-1,tfile__grabData,TRUE,(void *)task)) { flex_free((flex_ptr)&w); tfile_deleteWindow(0,wnew); werr(FALSE,msgs_lookup("tfNEMGW")); return; } ioff=sizeof(wimp_winfo); for (i=0;idef->i[i].i=*_ptr(wimp_icon,w,ioff); wnew->def->i[i].edit=0; if (!iconData_handleFont(wnew,&wnew->def->i[i].i.flags) && !fonterr) { werr(FALSE,msgs_lookup("tfFERG")); fonterr=TRUE; } if (!iconData_processIcon(wnew,i,tfile__grabData,TRUE,(void *)task)) { flex_free((flex_ptr)&w); tfile_deleteWindow(0,wnew); werr(FALSE,msgs_lookup("tfNEMGW")); return; } wnew->def->desc.w.nicons++; ioff+=sizeof(wimp_icon); } flex_free((flex_ptr)&w); } /* * BOOL tfile__grabGetName(char *name,void *handle) * * Use * Handles the writable box for a grab window job and starts the grab op * * Parameters * char *name == the user's name for the window * void *handle == the template file to grab to * * Returns * TRUE if the name was valid and the grab has been set up */ static BOOL tfile__grabGetName(char *name,void *handle) { glass_tfile *t=handle; viewer_icon icn; icn=viewer_findIcon(t->v,name); if (icn==viewer_NOICON) { strcpy(tfile__grabName,name); event_clear_current_menu(); window_grab(tfile__grab,t); return (TRUE); } note(msgs_lookup("tfNAE"), viewer_textOfIcon(icn)); return (FALSE); } /* * BOOL tfile__copy(char *new,void *handle) * * Use * Copies the specified window * * Parameters * char *new == the name for the new window * void *handle == pointer to the window structure */ static BOOL tfile__copy(char *new,void *handle) { glass_windPointer *w=handle; viewer_icon icn; glass_windPointer *wnew; int i; int numicons; BOOL fonterr=FALSE; icn=viewer_findIcon(w->t->v,new); if (icn==viewer_NOICON) { wnew=tfile__newWindow(w->t,new); if (!wnew) return (FALSE); tfile_markAsAltered(w->t); wnew->size=w->size; numicons=w->def->desc.w.nicons; if (!flex_alloc((flex_ptr)&wnew->def, sizeof(glass_window) +(numicons-1)*sizeof(glass_iconDescription))) { viewer_removeIcon(wnew->i); mem_free(wnew); werr(FALSE,msgs_lookup("tfNEMCW")); return (FALSE); } memcpy ( wnew->def, w->def, sizeof(glass_window)+(numicons-1)*sizeof(glass_iconDescription) ); wnew->def->desc.w.nicons=0; if (!iconData_handleFont(wnew,&wnew->def->desc.w.titleflags) && !fonterr) { werr(FALSE,msgs_lookup("tfFERCP")); fonterr=TRUE; } if (!iconData_processIcon(wnew,-1,0,FALSE,0)) { werr(FALSE,msgs_lookup("tfNEMCW")); tfile_deleteWindow(0,wnew); return (FALSE); } for (i=0;idef->i[i].i.flags) && !fonterr) { werr(FALSE,msgs_lookup("tfFERCP")); fonterr=TRUE; } if (!iconData_processIcon(wnew,i,0,FALSE,0)) { werr(FALSE,msgs_lookup("tfNEMCW")); tfile_deleteWindow(0,wnew); return (FALSE); } wnew->def->desc.w.nicons++; } return (TRUE); } note(msgs_lookup("tfNAE"), viewer_textOfIcon(icn)); return (FALSE); } /* * void tfile__openWindows(viewer_icon i,void *handle) * * Use * Opens a window. This is called when the user drags icons to the icon * bar and expects them to be displayed. * * Parameters * viewer_icon i == the icon handle of the icon representing the window * (ignored) * void *handle == pointer to the window's static information */ static void tfile__openWindows(viewer_icon i,void *handle) { glass_windPointer *w=handle; unused(i); window_open(w,FALSE); } /*----- Variables used during the save process ----------------------------*/ #ifndef glass_DEMO static void **tfile__flex; /* A flex block for saving data */ static int tfile__flexSize; /* Size of the flex block */ static int tfile__flexUsed; /* How much of the block has been used */ static BOOL tfile__abortSave; /* If TRUE, abort the save process */ static int tfile__nextIndex; /* Offset to next free index entry */ static char tfile__fontbinding[256]; /* Conversion realh -> internh */ static char tfile__backbinding[256]; /* Reverse font binding */ static char tfile__nextFont; /* The next free internal font handle */ /*----- Save templates support routines -----------------------------------*/ /* * This section contains the actual code to save a template file or * selection. */ /* * BOOL tfile__saveAlloc(int size) * * Use * Ensures that a certain quantity of space is present in the save flex * block. * * Parameters * int size == the size required in bytes * * Returns * TRUE if successful, or FALSE if allocation failed. An error is also * reported. */ static BOOL tfile__saveAlloc(int size) { int szreqd; if (tfile__flexSize-tfile__flexUsed>size) return (TRUE); szreqd=(tfile__flexUsed+size+8191) & ~8191; if (!flex_extend(tfile__flex,szreqd)) { werr(FALSE,msgs_lookup("tfNEMST")); return (FALSE); } tfile__flexSize=szreqd; return (TRUE); } /* * BOOL tfile__addBlock(void *p,size_t sz) * * Use * Adds a block of data to the end of the save block. * * Parameters * void *p == pointer to the block * size_t sz == the size of the block * * Returns * TRUE if successful */ static BOOL tfile__addBlock(void *p,size_t sz) { if (!tfile__saveAlloc(sz)) return (FALSE); memcpy(_ptr(void,*tfile__flex,tfile__flexUsed),p,sz); tfile__flexUsed+=sz; return (TRUE); } #define tfile__writeString(s,off) \ { \ strcpy(charptr(*tfile__flex,off),s); \ charptr(*tfile__flex,off)[strlen(s)]=13; \ } /* * BOOL tfile__addString(char *s) * * Use * Adds a ctrl-terminated string to the end of the save block. * * Parameters * char *s == pointer to the string to store * * Returns * TRUE if successful */ static BOOL tfile__addString(char *s) { int len; utils_ctermToNterm(s); len=strlen(s); if (!tfile__saveAlloc(len+1)) return (FALSE); tfile__writeString(s,tfile__flexUsed); tfile__flexUsed+=len+1; return (TRUE); } /* * void tfile__processWindow(viewer_icon icn,void *handle) * * Use * Saves the window given onto the end of the flex block being used for * such a purpose. A save may be aborted by setting the variable * tfile__abortSave. * * Parameters * viewer_icon icn == the icon representing the window to be saved (ignored) * void *handle == pointer to the window structure in memory */ static void tfile__processWindow(viewer_icon icn,void *handle) { int start; int i; int idef; int ifont,rfont; glass_windPointer *w=handle; unused(icn); if (tfile__abortSave) return; while (tfile__flexUsed & 3) *charptr(*tfile__flex,tfile__flexUsed++)=0; /* --- Start on the index --- */ intptr(*tfile__flex,tfile__nextIndex)[0]=start=tfile__flexUsed; intptr(*tfile__flex,tfile__nextIndex)[2]=1; tfile__writeString(w->id,tfile__nextIndex+12); /* --- Now copy the window and icons --- */ if (!tfile__addBlock(&w->def->desc.w,sizeof(wimp_wind))) { tfile__abortSave=TRUE; return; } for (i=0;idef->desc.w.nicons;i++) { if (!tfile__addBlock(&w->def->i[i].i,sizeof(wimp_icon))) { tfile__abortSave=TRUE; return; } } /* --- Process window def for indirection and fonts --- */ _ptr(wimp_wind,*tfile__flex,start)->spritearea=(void *)1; if (w->def->desc.w.titleflags & wimp_IFONT) { rfont=w->def->desc.w.titleflags >> 24; if (tfile__fontbinding[rfont]) ifont=tfile__fontbinding[rfont]; else { ifont=tfile__fontbinding[rfont]=tfile__nextFont++; tfile__backbinding[ifont]=rfont; } _ptr(wimp_wind,*tfile__flex,start) -> titleflags= (w->def->desc.w.titleflags & 0x00ffffff) | (ifont << 24); } if (w->def->desc.w.titleflags & wimp_INDIRECT) { _ptr(wimp_wind,*tfile__flex,start) -> title.indirecttext.buffer= (char *)(tfile__flexUsed-start); if (!tfile__addString(w->def->desc.w.title.indirecttext.buffer)) { tfile__abortSave=TRUE; return; } if (w->def->desc.w.titleflags & wimp_ITEXT) { if (w->def->desc.w.title.indirecttext.validstring!=(char *)-1) { _ptr(wimp_wind,*tfile__flex,start)->title.indirecttext.validstring= (char *)(tfile__flexUsed-start); if (!tfile__addString(w->def->desc.w.title.indirecttext.validstring)) { tfile__abortSave=TRUE; return; } } } else if (w->def->desc.w.titleflags & wimp_ISPRITE) { _ptr(wimp_wind,*tfile__flex,start)->title.indirectsprite.spritearea= (void *)1; } } /* --- Now the same for the icons --- */ idef=start+sizeof(wimp_wind); for (i=0;idef->desc.w.nicons;i++) { if (w->def->i[i].i.flags & wimp_IFONT) { rfont=w->def->i[i].i.flags >> 24; if (tfile__fontbinding[rfont]) ifont=tfile__fontbinding[rfont]; else { ifont=tfile__fontbinding[rfont]=tfile__nextFont++; tfile__backbinding[ifont]=rfont; } _ptr(wimp_icon,*tfile__flex,idef)->flags= (w->def->i[i].i.flags & 0x00ffffff) | (ifont << 24); } if (w->def->i[i].i.flags & wimp_INDIRECT) { _ptr(wimp_icon,*tfile__flex,idef)->data.indirecttext.buffer= (char *)(tfile__flexUsed-start); if (!tfile__addString(w->def->i[i].i.data.indirecttext.buffer)) { tfile__abortSave=TRUE; return; } if (w->def->i[i].i.flags & wimp_ITEXT) { if (w->def->i[i].i.data.indirecttext.validstring!=(char *)-1) { _ptr(wimp_icon,*tfile__flex,idef)->data.indirecttext.validstring= (char *)(tfile__flexUsed-start); if (!tfile__addString(w->def->i[i].i.data. indirecttext.validstring)) { tfile__abortSave=TRUE; return; } } } else if (w->def->i[i].i.flags & wimp_ISPRITE) { _ptr(wimp_icon,*tfile__flex,idef)->data.indirectsprite.spritearea= (void *)1; } } idef+=sizeof(wimp_icon); } intptr(*tfile__flex,tfile__nextIndex)[1]=tfile__flexUsed-start; tfile__nextIndex+=24; } /* * BOOL tfile__setupSave(glass_tfile *t, * glass_windPointer *w, * void **p, * BOOL onlySelected) * * Use * Sets up a flex block for saving a template file, selection or single * window. To save a template file or selection, set t==tfile, w==0. To * save a window, set t==0, w==window. * * Parameters * glass_tfile *t == the template file that we're saving * glass_windPointer *w == the window we're saving * void **p == pointer used as flex anchor (free after use yourself) * BOOL onlySelected == do we only save the selected templates? * * Returns * TRUE if operation completed successfully */ static BOOL tfile__setupSave(glass_tfile *t, glass_windPointer *w, void **p, BOOL onlySelected) { int i; int numwin; os_regset r; char buff[40]; if (!flex_alloc(p,tfile__selectSize)) { werr(FALSE,msgs_lookup("tfNEMST")); return (FALSE); } tfile__flex=p; tfile__flexSize=tfile__selectSize; tfile__flexUsed=0; tfile__abortSave=FALSE; for (i=0;i<256;i++) { tfile__fontbinding[i]=0; tfile__backbinding[i]=0; } tfile__nextFont=1; /* --- Header --- */ if (!tfile__saveAlloc(16)) { flex_free(p); return (FALSE); } intptr(*tfile__flex,0)[0]=-1; intptr(*tfile__flex,0)[1]=0; intptr(*tfile__flex,0)[2]=0; intptr(*tfile__flex,0)[3]=0; tfile__flexUsed+=16; /* --- Set up index entries --- */ if (t) { if (onlySelected) numwin=viewer_selected(t->v); else numwin=viewer_icons(t->v); } else numwin=1; if (!tfile__saveAlloc(24*numwin+4)) { flex_free(p); return (FALSE); } /* --- Now insert window and icon definitions --- */ tfile__nextIndex=16; tfile__flexUsed+=24*numwin+4; if (t) viewer_doForIcons(t->v,onlySelected,tfile__processWindow); else tfile__processWindow(0,w); if (tfile__abortSave) { flex_free(p); return (FALSE); } /* --- Terminate the index and fill in the fonts --- */ intptr(*tfile__flex,tfile__nextIndex)[0]=0; if (tfile__nextFont!=1) { tfile__flexUsed=(tfile__flexUsed+3) & (~3); if (!tfile__saveAlloc(48*(tfile__nextFont-1))) { flex_free(p); return (FALSE); } intptr(*tfile__flex,0)[0]=tfile__flexUsed; for (i=1;icSave && saveas_file_is_safe() && utils_caselessCmp(filename,t->filename)!=0 && res_fileExists(filename) ) { if (!warning(msgs_lookup("tfSOFP"),msgs_lookup("tfSOF"),filename)) return (FALSE); } if (!tfile__setupSave(t,0,&p,FALSE)) return (FALSE); f.action=10; f.name=filename; f.loadaddr=0xfec; f.start=(int)p; f.end=f.start+tfile__flexUsed; if (utils_complain(os_file(&f),msgs_lookup("tfERT"))) { flex_free(&p); return (FALSE); } else { flex_free(&p); if (saveas_file_is_safe()) tfile_markAsSaved(t,filename); return (TRUE); } } /* * BOOL tfile__sendTemplates(void *handle,int *maxbuf) * * Use * Saves a template file to another application via RAM transfer * * Parameters * void *handle == pointer to the template file * int *maxbuf == pointer to receiving app's buffer size * * Returns * TRUE if successful */ static BOOL tfile__sendTemplates(void *handle,int *maxbuf) { void *p; glass_tfile *t=handle; if (!tfile__setupSave(t,0,&p,FALSE)) return (FALSE); if (xfersend_sendBlock(p,tfile__flexUsed,maxbuf)) { flex_free(&p); return (TRUE); } else { flex_free(&p); return (FALSE); } } /* * BOOL tfile__saveSelection(char *filename,void *handle) * * Use * Saves a template selection to disk * * Parameters * char *filename == the file to save to * void *handle == pointer to the template file * * Returns * TRUE if successful */ static BOOL tfile__saveSelection(char *filename,void *handle) { void *p; os_filestr f; glass_tfile *t=handle; if ( gPrefs_current()->cSave && saveas_file_is_safe() && res_fileExists(filename) ) { if (!warning(msgs_lookup("tfSOFP"),msgs_lookup("tfSOF"),filename)) return (FALSE); } if (!tfile__setupSave(t,0,&p,TRUE)) return (FALSE); f.action=10; f.name=filename; f.loadaddr=0xfec; f.start=(int)p; f.end=f.start+tfile__flexUsed; if (utils_complain(os_file(&f),msgs_lookup("tfERT"))) { flex_free(&p); return (FALSE); } else { flex_free(&p); return (TRUE); } } /* * BOOL tfile__sendSelection(void *handle,int *maxbuf) * * Use * Saves a template selection to another application via RAM transfer * * Parameters * void *handle == pointer to the template file * int *maxbuf == pointer to receiving app's buffer size * * Returns * TRUE if successful */ static BOOL tfile__sendSelection(void *handle,int *maxbuf) { void *p; glass_tfile *t=handle; if (!tfile__setupSave(t,0,&p,TRUE)) return (FALSE); if (xfersend_sendBlock(p,tfile__flexUsed,maxbuf)) { flex_free(&p); return (TRUE); } else { flex_free(&p); return (FALSE); } } /* * BOOL tfile__saveWindow(char *filename,void *handle) * * Use * Saves a template selection to disk * * Parameters * char *filename == the file to save to * void *handle == pointer to the window * * Returns * TRUE if successful */ static BOOL tfile__saveWindow(char *filename,void *handle) { void *p; os_filestr f; glass_windPointer *w=handle; if ( gPrefs_current()->cSave && saveas_file_is_safe() && res_fileExists(filename) ) { if (!warning(msgs_lookup("tfSOFP"),msgs_lookup("tfSOF"),filename)) return (FALSE); } if (!tfile__setupSave(0,w,&p,TRUE)) return (FALSE); f.action=10; f.name=filename; f.loadaddr=0xfec; f.start=(int)p; f.end=f.start+tfile__flexUsed; if (utils_complain(os_file(&f),msgs_lookup("tfERT"))) { flex_free(&p); return (FALSE); } else { flex_free(&p); return (TRUE); } } /* * BOOL tfile__sendWindow(void *handle,int *maxbuf) * * Use * Saves a template selection to another application via RAM transfer * * Parameters * void *handle == pointer to the window * int *maxbuf == pointer to receiving app's buffer size * * Returns * TRUE if successful */ static BOOL tfile__sendWindow(void *handle,int *maxbuf) { void *p; glass_windPointer *w=handle; if (!tfile__setupSave(0,w,&p,TRUE)) return (FALSE); if (xfersend_sendBlock(p,tfile__flexUsed,maxbuf)) { flex_free(&p); return (TRUE); } else { flex_free(&p); return (FALSE); } } #else static BOOL tfile__demoSave(void) { note(msgs_lookup("tfCSID")); } static BOOL tfile__saveTemplates(char *filename,void *handle) { unused(filename); unused(handle); return (tfile__demoSave()); } static BOOL tfile__sendTemplates(void *handle,int *maxbuf) { unused(handle); unused(maxbuf); return (tfile__demoSave()); } static BOOL tfile__saveSelection(char *filename,void *handle) { unused(filename); unused(handle); return (tfile__demoSave()); } static BOOL tfile__sendSelection(void *handle,int *maxbuf) { unused(handle); unused(maxbuf); return (tfile__demoSave()); } static BOOL tfile__saveWindow(char *filename,void *handle) { unused(filename); unused(handle); return (tfile__demoSave()); } static BOOL tfile__sendWindow(void *handle,int *maxbuf) { unused(handle); unused(maxbuf); return (tfile__demoSave()); } #endif /*----- Autosave handling -------------------------------------------------* * * This is here to avoid having to prototype the save code */ /* * void tfile__closeQbox(int now,void *handle) * * Use * Closes the autosave message dialogue box. * * Parameters * int now == the time now (ignored) * void *handle == dialogue box handle */ static void tfile__closeQbox(int now,void *handle) { unused(now); dbox_delete((dbox)handle); } /* * void tfile__autoHandler(dbox d,dbox_field f,void *handle) * * Use * Handles events for the autosave prompt box * * Parameters * dbox d == the dbox's handle * dbox_field f == what happened * void *handle == pointer to the template file */ static void tfile__autoHandler(dbox d,dbox_field f,void *handle) { glass_tfile *t=handle; wimp_wstate s; switch (f) { case glass_APSAVE: if (strchr(t->filename,'.')) { dbox_clickicon(d,f); wimpt_noerr(wimp_get_wind_state(dbox_syshandle(d),&s)); dbox_hide(d); if (!tfile__saveTemplates(t->filename,t)) wimpt_noerr(wimp_open_wind(&s.o)); dbox_unclick(); break; } /* If no path, drop through to saveas... */ case glass_APSAVEAS: dbox_clickicon(d,glass_APSAVEAS); dbox_unclick(); tfile_saveTemplates(t); break; case glass_APCANCEL: dbox_clickicon(d,f); dbox_hide(d); dbox_unclick(); /* Intentional drop through */ case dbox_CLOSE: dbox_delete(d); t->autod=0; break; } } /* * void tfile__doAutosave(glass_tfile *t) * * Use * Starts an autosave for the given template file. Multiple autosaves * are permitted simultaneously. Stick that in Impression's pipeline and * process it... * * Parameters * glass_tfile *t == the template file to autosave */ static void tfile__doAutosave(int now,void *handle) { BOOL useDbox; dbox qwin; int at; glass_tfile *t=handle; unused(now); useDbox=gPrefs_current()->aPrompt; if (t->loaded==FALSE || t->autoSaved==FALSE) useDbox=TRUE; if (t->autoAlarm) alarm_remove(t->autoAlarm,t); t->autoAlarm=0; t->autoTime=0; t->alts=-1; if (useDbox) { if (t->autod) return; t->autod=dbox_create("autoPrompt"); if (!t->autod) { if (at=gPrefs_autoTiming(),at) { t->autoTime=alarm_timenow(); t->autoAlarm=t->autoTime+at; alarm_set(t->autoAlarm,tfile__doAutosave,t); } return; } dbox_setfield(t->autod,glass_APNAME,"%.%s",t->filename); dbox_shadeicon(t->autod,glass_APSAVE,!strchr(t->filename,'.')); dbox_eventHandler(t->autod,tfile__autoHandler,t); dbox_openDisplaced(t->autod); } else { qwin=dbox_create("autoMessage"); if (qwin) { dbox_setfield(qwin,glass_AMNAME,"%.%s",t->filename); dbox_display(qwin,dbox_MENU_CENTRE); nopoll_showDbox(qwin,nopoll_CENTRE); alarm_set(alarm_timenow()+100,tfile__closeQbox,qwin); } tfile__saveTemplates(t->filename,t); } } /*----- Event handlers ----------------------------------------------------*/ /* * void tfile__close(glass_tfile *t,BOOL checkMouse) * * Use * Closes a template file, asking user for confirmation etc. * * Parameters * glass_tfile *t == the template file to kill * BOOL checkMouse == whether to check the mouse buttons to open the parent */ static void tfile__close(glass_tfile *t,BOOL checkMouse) { wimp_mousestr m; char buff[256]; char *name; event_clear_current_menu(); /* The menu will be closed - it will try */ /* to deselect an non-existant item... */ if (checkMouse) { wimpt_noerr(wimp_get_point_info(&m)); if (m.bbits==wimp_BRIGHT && t->loaded) { sprintf(buff,"Filer_OpenDir %s",t->filename); utils_leafname(buff)[-1]=0; os_cli(buff); } if (m.bbits==wimp_BRIGHT && akbd_pollsh()) return; } if (t->alts && gPrefs_current()->cClose) { if (t->loaded) name=t->filename; else name=msgs_lookup("tfTMP"); tfile__selectSize=0; viewer_doForIcons(t->v,FALSE,tfile__size); viewer_clickSelect(t->v,viewer_NOICON,wimp_BMID); saveWarn(t->loaded, tfile__deleteTemplateFile, msgs_lookup("tfSVTIT"), name,0xfec, tfile__selectSize, tfile__saveTemplates, tfile__sendTemplates, 0, t); } else tfile__deleteTemplateFile(t); /* Destroy the underlying data */ } /* * void tfile__redrawViewer(viewer_icon i,wimp_redrawstr *r, * wimp_box *box,char *text,char *sprite,BOOL selected,void *handle) * * Use * Redraws a small icon in the viewer window. * * Parameters * viewer_icon i == the icon I'm redrawing * wimp_redrawstr *r == the redraw structure * wimp_box *box == the box to fit it in * char *text == the text to draw * char *sprite == the sprite to draw (ignored) * BOOL selected == whether the icon is selected * void *handle == pointer to the template file */ static void tfile__redrawViewer(viewer_icon i, wimp_redrawstr *r, wimp_box *box, char *text, char *sprite, BOOL selected, void *handle) { wimp_icon icn={0,0,0,0,0x17000113,""}; unused(i); unused(r); unused(sprite); unused(handle); icn.box=*box; icn.flags|=(selected<<21); icn.data.indirecttext.buffer=text; icn.data.indirecttext.validstring="Ssmtmpltvicon"; icn.data.indirecttext.bufflen=13; wimpt_noerr(wimp_ploticon(&icn)); } /* * int tfile__sort(void *a,void *b) * * Use * Compares two windows in the current sorting method. * * Parameters * void *a == pointer to the first window * void *b == pointer to the second window * * Returns * Somehow 'a-b'. */ static int tfile__sort(void *a,void *b) { glass_windPointer *x=a; glass_windPointer *y=b; int result=0; switch (x->t->sort) { case gPrefs_NAME: result=utils_caselessCmp(x->id,y->id); break; case gPrefs_SIZE: result=y->size-x->size; break; case gPrefs_ICONS: result=y->def->desc.w.nicons-x->def->desc.w.nicons; break; case gPrefs_NOSORT: result=x->serial-y->serial; break; } if (!result) result=utils_caselessCmp(x->id,y->id); return (result); } /* * void tfile__tfileMenuHelp(int hit[],void *handle) * * Use * Responds to help requests for template file menu. * * Parameters * int hit[] == array of menu selections * void *handle == pointer to template file control block */ static void tfile__tfileMenuHelp(int hit[],void *handle) { unused(handle); help_startHelp(); help_readFromMenu("tfmhTF",hit); help_endHelp(); } /* * void tfile__tfileMenuHandler(int hit[],void *handle) * * Use * Responds to menu events for template file menu. * * Parameters * int hit[] == array of menu selections * void *handle == pointer to template file control block */ static void tfile__tfileMenuHandler(int hit[],void *handle) { glass_tfile *t=handle; char buff[15]; dbox d; unused(t); switch (hit[0]) { case 0: viewer_clickSelect(t->v,viewer_NOICON,wimp_BMID); break; case glass_TFINFO: if (d=dbox_create("fileInfo"),d) { dbox_setfield(d,glass_FINAME,"%.%s",t->filename); tfile__selectSize=0; tfile__selectIndSz=0; viewer_doForIcons(t->v,FALSE,tfile__size); dbox_setfield(d, glass_FISIZE, "%s", utils_cvtSize(tfile__selectSize)); dbox_setfield(d, glass_FIINDSZ, "%s", utils_cvtSize(tfile__selectIndSz)); dbox_setfield(d,glass_FIWINDOWS,"%i",viewer_icons(t->v)); dbox_setfield(d, glass_FIMODIFIED, "%s", msgs_lookup(t->alts ? "yes" : "no")); mbox(d,"tfhFI"); } break; case glass_TFDISP: switch (hit[1]) { case glass_TFDLARGE: if (t->isz!=gPrefs_LARGE) { t->isz=gPrefs_LARGE; viewer_setIconSize(t->v,200,112); viewer_redrawHandler(t->v,0,t); } break; case glass_TFDSMALL: if (t->isz!=gPrefs_SMALL) { t->isz=gPrefs_SMALL; viewer_setIconSize(t->v,248,36); viewer_redrawHandler(t->v,tfile__redrawViewer,t); } break; case glass_TFDSORTNAME: if (t->sort!=gPrefs_NAME) { t->sort=gPrefs_NAME; viewer_setCompare(t->v,tfile__sort); } break; case glass_TFDSORTSIZE: if (t->sort!=gPrefs_SIZE) { t->sort=gPrefs_SIZE; viewer_setCompare(t->v,tfile__sort); } break; case glass_TFDSORTICONS: if (t->sort!=gPrefs_ICONS) { t->sort=gPrefs_ICONS; viewer_setCompare(t->v,tfile__sort); } break; case glass_TFDNOSORT: if (t->sort!=gPrefs_NOSORT) { t->sort=gPrefs_NOSORT; viewer_setCompare(t->v,tfile__sort); } break; } break; case glass_TFSEL: switch (hit[1]) { case glass_TFSELINFO: if (viewer_selected(t->v)==1) tfile_windowInfo((glass_windPointer *) viewer_iconHandle(viewer_firstSelected(t->v))); else { if (d=dbox_create("selInfo"),d) { tfile__selectSize=0; tfile__selectIndSz=0; viewer_doForIcons(t->v,TRUE,tfile__size); dbox_setfield(d, glass_SISIZE, "%s", utils_cvtSize(tfile__selectSize)); dbox_setfield(d, glass_SIINDSZ, "%s", utils_cvtSize(tfile__selectIndSz)); tfile__selectIcons=0; viewer_doForIcons(t->v,TRUE,tfile__icons); dbox_setfield(d,glass_SIICONS,"%i",tfile__selectIcons); dbox_setfield(d,glass_SINUM,"%i",viewer_selected(t->v)); mbox(d,"tfhSI"); } } break; case glass_TFSELEDIT: editWindow(viewer_iconHandle(viewer_firstSelected(t->v))); break; case glass_TFSELCOPY: writable ( msgs_lookup("tfCOPY"), viewer_textOfIcon(viewer_firstSelected(t->v)), buff, tfile__copy, viewer_iconHandle(viewer_firstSelected(t->v)) ); break; case glass_TFSELRENAME: writable ( msgs_lookup("tfREN"), viewer_textOfIcon(viewer_firstSelected(t->v)), buff, tfile_rename, viewer_iconHandle(viewer_firstSelected(t->v)) ); break; case glass_TFSELSAVE: tfile__selectSize=0; viewer_doForIcons(t->v,TRUE,tfile__size); saveas(msgs_lookup("tfSVSEL"), msgs_lookup("tfSEL"), 0xfec, tfile__selectSize, tfile__saveSelection, tfile__sendSelection, 0, t); break; case glass_TFSELDELETE: if (gPrefs_current()->cDelWind) { if (!warning(msgs_lookup("tfDELWP"),msgs_lookup("tfDELW"))) break; } viewer_doForIcons(t->v,TRUE,tfile_deleteWindow); tfile_markAsAltered(t); break; } break; case glass_TFSELALL: tfile__gainSelection(t); viewer_selectAll(t->v,TRUE); break; case glass_TFCLRSEL: viewer_selectAll(t->v,FALSE); break; case glass_TFSAVE: tfile_saveTemplates(t); break; case glass_TFCREATE: writable(msgs_lookup("tfCRT"),"",buff,tfile__create,t); break; case glass_TFGRAB: writable(msgs_lookup("tfGRAB"),"",buff,tfile__grabGetName,t); break; case glass_TFSHWSPR: gSprite_display(t); break; default: break; } } /* * menu tfile__tfileMenuMaker(void *handle) * * Use * Generates the menu for a template file window. * * Parameters * void *handle == the template file window to deal with * * Returns * A pointer to the menu structure to display. */ static menu tfile__tfileMenuMaker(void *handle) { static menu m; /* The main menu pointer */ static menu disp; /* Submenu for display options */ static menu windsm; /* Submenu for window options */ #ifdef glass_NOTLAZY static menu stylesm; /* Submenu for styles options */ #endif static char windName[50]; /* Buffer for window name */ glass_tfile *t=handle; glass_windPointer *w; if (!m) /* Do we have to create the menu? */ { m=menu_new("Glass",msgs_lookup("tfM")); disp=menu_new(msgs_lookup("tfDSPT"), msgs_lookup("tfDSPM")); windsm=menu_new("_",msgs_lookup("tfWS")); #ifdef glass_NOTLAZY stylesm=menu_new(msgs_lookup("tfISST:Icon styles"), msgs_lookup("tfISS:" "Edit style...," "New style...," ">Save...")); #endif menu_submenu(m,glass_TFSEL,windsm); #ifdef glass_NOTLAZY menu_submenu(m,glass_TFSTYLES,stylesm); #endif menu_submenu(m,glass_TFDISP,disp); menu_redirectItem(m,glass_TFSEL,windName,50,0); } menu_minWidth(m,0); viewer_setupMenu(t->v, msgs_lookup("tfWIN"), m, glass_TFSEL, windName); switch (viewer_selected(t->v)) { case 0: menu_setflags(m,glass_TFCLRSEL,FALSE,TRUE); menu_setflags(m,glass_TFSELALL,FALSE,!viewer_icons(t->v)); menu_settitle(windsm,msgs_lookup("tfWIN")); menu_setflags(windsm,glass_TFSELINFO,FALSE,TRUE); menu_setflags(windsm,glass_TFSELEDIT,FALSE,TRUE); menu_setflags(windsm,glass_TFSELCOPY,FALSE,TRUE); menu_setflags(windsm,glass_TFSELRENAME,FALSE,TRUE); menu_setflags(windsm,glass_TFSELSAVE,FALSE,TRUE); menu_setflags(windsm,glass_TFSELDELETE,FALSE,TRUE); break; case 1: w=viewer_iconHandle(viewer_firstSelected(t->v)); menu_setflags(m,glass_TFCLRSEL,FALSE,FALSE); menu_setflags(m,glass_TFSELALL,FALSE,FALSE); menu_settitle(windsm,msgs_lookup("tfWIN")); menu_setflags(windsm,glass_TFSELINFO,FALSE,FALSE); #ifndef glass_DEMO menu_setflags(windsm,glass_TFSELEDIT,FALSE,w->testMode); #else menu_setflags(windsm,glass_TFSELEDIT,FALSE,FALSE); #endif menu_setflags(windsm,glass_TFSELCOPY,FALSE,FALSE); menu_setflags(windsm,glass_TFSELRENAME,FALSE,FALSE); menu_setflags(windsm,glass_TFSELSAVE,FALSE,FALSE); menu_setflags(windsm,glass_TFSELDELETE,FALSE,FALSE); break; default: menu_setflags(m,glass_TFCLRSEL,FALSE,FALSE); menu_setflags(m,glass_TFSELALL,FALSE,FALSE); menu_settitle(windsm,msgs_lookup("tfSEL")); menu_setflags(windsm,glass_TFSELINFO,FALSE,FALSE); menu_setflags(windsm,glass_TFSELEDIT,FALSE,TRUE); menu_setflags(windsm,glass_TFSELCOPY,FALSE,TRUE); menu_setflags(windsm,glass_TFSELRENAME,FALSE,TRUE); menu_setflags(windsm,glass_TFSELSAVE,FALSE,FALSE); menu_setflags(windsm,glass_TFSELDELETE,FALSE,FALSE); break; } menu_setflags(m,glass_TFSHWSPR,FALSE,!t->vs); menu_setflags(m,glass_TFGRAB,FALSE,window_grabbing()); menu_setflags(disp,glass_TFDLARGE,t->isz==gPrefs_LARGE,FALSE); menu_setflags(disp,glass_TFDSMALL,t->isz==gPrefs_SMALL,FALSE); menu_setflags(disp,glass_TFDSORTNAME,t->sort==gPrefs_NAME,FALSE); menu_setflags(disp,glass_TFDSORTSIZE,t->sort==gPrefs_SIZE,FALSE); menu_setflags(disp,glass_TFDSORTICONS,t->sort==gPrefs_ICONS,FALSE); menu_setflags(disp,glass_TFDNOSORT,t->sort==gPrefs_NOSORT,FALSE); return (m); } /* * void tfile__simMenu(glass_tfile *t,int hit1,int hit2) * * Use * Simulates a menu hit on a template file window * * Parameters * glass_tfile *t == the template file the event is destined for * int hit1 == the main menu entry number * int hit2 == the submenu entry number */ static void tfile__simMenu(glass_tfile *t,int hit1,int hit2) { wimp_menustr *m=menu_syshandle(tfile__tfileMenuMaker(t)); wimp_menuitem *i=(wimp_menuitem *)(m+1)+(hit1-1); int mnu[3]; mnu[0]=hit1; mnu[1]=hit2; mnu[2]=0; if ((int)i->submenu==-1 || hit2==0) { if (i->iconflags & wimp_INOSELECT) { bbc_vdu(7); return; } else mnu[1]=0; } else { i=(wimp_menuitem *)(i->submenu+1)+(hit2-1); if (i->iconflags & wimp_INOSELECT) { bbc_vdu(7); return; } } tfile__tfileMenuHandler(mnu,t); } /* * BOOL tfile__dragUnknowns(wimp_eventstr *e,void *handle) * * Use * Handles unknown events during the period of dragging viewer icons * around. It will respond to the following drags: * * A drag to a blank area of icon bar will open the windows. * * Otherwise, a selection save will be started, and the windows packaged * off to another application. * * Parameters * wimp_eventstr *e == the event to look at * void *handle == the template file we're dragging from * * Returns * TRUE if the drag has been processed */ static BOOL tfile__dragUnknowns(wimp_eventstr *e,void *handle) { glass_tfile *t=handle; wimp_mousestr m; BOOL handled=FALSE; switch (e->e) { case wimp_EUSERDRAG: handled=TRUE; win_remove_unknown_event_processor(tfile__dragUnknowns,t); wimpt_noerr(wimp_get_point_info(&m)); if (m.w==viewer_syshandle(t->v)) break; if (m.w==-2 && m.i==-1) viewer_doForIcons(t->v,TRUE,tfile__openWindows); else { tfile__selectSize=0; viewer_doForIcons(t->v,TRUE,tfile__size); wimpt_fake_event(e); /* Fool xfersend to send data */ xfersend(0xFEC, msgs_lookup("tfSEL"), tfile__selectSize, tfile__saveSelection, tfile__sendSelection, 0, e, t); } viewer_selectAll(t->v,FALSE); break; } return (handled); } /* * BOOL tfile__raw(viewer v,wimp_eventstr *e,void *handle) * * Use * Handles intMsgs from other parts of the system * * Parameters * viewer v == the handle for the viewer window * wimp_eventstr *e == the event to process * void *handle == the template file * * Returns * TRUE if event was processed */ static BOOL tfile__raw(viewer v,wimp_eventstr *e,void *handle) { BOOL handled=FALSE; char *filename; int estsize; int filetype; void *p; glass_tfile *t=handle; int at; switch (e->e) { case wimp_EKEY: switch (e->data.key.chcode) { case akbd_Fn+1+akbd_Sh: /* sF1 */ tfile__simMenu(t,glass_TFINFO,0); handled=TRUE; break; case 1: /* ^A */ tfile__simMenu(t,glass_TFSELALL,0); handled=TRUE; break; case 26: /* ^Z */ tfile__simMenu(t,glass_TFCLRSEL,0); handled=TRUE; break; case akbd_Fn+3: /* F3 */ tfile__simMenu(t,glass_TFSAVE,0); handled=TRUE; break; case 14: /* ^N */ tfile__simMenu(t,glass_TFCREATE,0); handled=TRUE; break; case 7: /* ^G */ tfile__simMenu(t,glass_TFGRAB,0); handled=TRUE; break; case 19: /* ^S */ tfile__simMenu(t,glass_TFSHWSPR,0); handled=TRUE; break; case akbd_Fn+5: /* F5 */ tfile__simMenu(t,glass_TFDISP,glass_TFDLARGE); handled=TRUE; break; case akbd_Fn+5+akbd_Sh: /* sF5 */ tfile__simMenu(t,glass_TFDISP,glass_TFDSMALL); handled=TRUE; break; case akbd_Fn+6: /* F6 */ tfile__simMenu(t,glass_TFDISP,glass_TFDSORTNAME); handled=TRUE; break; case akbd_Fn+6+akbd_Sh: /* sF6 */ tfile__simMenu(t,glass_TFDISP,glass_TFDSORTSIZE); handled=TRUE; break; case akbd_Fn+6+akbd_Ctl:/* ^F6 */ tfile__simMenu(t,glass_TFDISP,glass_TFDSORTICONS); handled=TRUE; break; case akbd_Fn+6+akbd_Ctl+akbd_Sh:/* s^F6 */ tfile__simMenu(t,glass_TFDISP,glass_TFDNOSORT); handled=TRUE; break; case akbd_Fn+1+akbd_Ctl:/* ^F1 */ tfile__simMenu(t,glass_TFSEL,glass_TFSELINFO); handled=TRUE; break; case 5: /* ^E */ tfile__simMenu(t,glass_TFSEL,glass_TFSELEDIT); handled=TRUE; break; case 3: /* ^C */ tfile__simMenu(t,glass_TFSEL,glass_TFSELCOPY); handled=TRUE; break; case 18: /* ^R */ tfile__simMenu(t,glass_TFSEL,glass_TFSELRENAME); handled=TRUE; break; case akbd_Fn+3+akbd_Sh: /* sF3 */ tfile__simMenu(t,glass_TFSEL,glass_TFSELSAVE); handled=TRUE; break; case 24: /* ^X */ tfile__simMenu(t,glass_TFSEL,glass_TFSELDELETE); handled=TRUE; break; case akbd_Fn+2+akbd_Ctl:/* ^F2 */ tfile__close(t,FALSE); handled=TRUE; break; } break; case wimp_ESEND: case wimp_ESENDWANTACK: switch (e->data.msg.hdr.action) { case wimp_MDATASAVE: filetype=xferrecv_checkimport(&estsize); switch (filetype) { case 0xfec: /* Template files */ if (xferrecv_returnImportedBlock(&p)!=-1) { tfile_markAsAltered(t); tfile_mergeFromMemory(&p,t); flex_free(&p); } break; case 0xff9: /* Sprite files (I think) */ if (t->vs) { if (xferrecv_returnImportedBlock(&p)!=-1) { gSprite_mergeFromMemory(t,&p); flex_free(&p); } } break; } break; case wimp_MDATALOAD: filetype=xferrecv_checkinsert(&filename); switch (filetype) { case 0xfec: /* Template files */ tfile_mergeFromFile(filename,t); tfile_markAsAltered(t); xferrecv_insertfileok(); break; case 0xff9: /* Sprite files (I think) */ if (t->vs) { gSprite_mergeFromFile(t,filename); xferrecv_insertfileok(); } break; } break; case wimp_MINTERNAL: switch (e->data.msg.data.words[0]) { case glass_KILLFILES: tfile__deleteTemplateFile(t); break; case glass_CLOSEDOWN: viewer_doForIcons(v,FALSE,tfile__tidyFonts); handled=TRUE; break; case glass_MODECHANGE: viewer_doForIcons(v,FALSE,tfile__reFindFonts); handled=TRUE; break; case glass_AUTOSAVE: if (t->autoAlarm) alarm_remove(t->autoAlarm,t); t->autoAlarm=0; if (t->autoTime) { if (at=gPrefs_autoTiming(),at) { t->autoAlarm=t->autoTime+at; alarm_set(t->autoAlarm,tfile__doAutosave,t); } } if (gPrefs_current()->aAlts!=0 && t->alts>=gPrefs_current()->aAlts) tfile__doAutosave(0,t); break; } break; } break; } return (handled); } /* * void tfile__tfileHandler(viewer v, * viewer_icon i, * wimp_bbits b, * void *vhandle, * void *ihandle) * * Use * Handles events for a template file window (including things like menu * clicks). * * Parameters * viewer v == the viewer that the event happened to * viewer_icon i == the icon it happened to * wimp_bbits b == the mouse button status * void *vhandle == pointer to the template file structure * void *ihandle == pointer to the window pointer structure */ static void tfile__tfileHandler(viewer v, viewer_icon i, wimp_bbits b, void *vhandle, void *ihandle) { glass_tfile *t=vhandle; glass_windPointer *wp=ihandle; switch ((int)i) { case (int)viewer_CLOSE: /* If the user closes the window */ tfile__close(t,TRUE); /* Try to close it :-) */ break; case (int)viewer_HELP: /* Help request for the window */ help_startHelp(); /* Prepare a reply */ help_addLine(msgs_lookup("tfhTF")); help_endHelp(); /* Send the message to Help application */ break; default: if (b!=wimp_BMID) { tfile__gainSelection(t); viewer_clickSelect(v,i,b); } switch (b) { case wimp_BMID: if (t==tfile__selOwner || !tfile__selOwner || !viewer_selected(tfile__selOwner->v) ) { tfile__selOwner=t; viewer_clickSelect(v,i,b); } menu_make(tfile__tfileMenuMaker, tfile__tfileMenuHandler, tfile__tfileMenuHelp, t); break; case wimp_BLEFT: if (i!=viewer_NOICON) { if (akbd_pollsh() && wp->h) window_close(wp); else window_open(wp,FALSE); /* Open the window on-screen */ viewer_selectIcon(i,FALSE); /* And deslect the icon */ } break; case wimp_BRIGHT: if (i!=viewer_NOICON) { if (akbd_pollsh() && wp->h) window_close(wp); else window_open(wp,TRUE); /* Open the window on-screen */ viewer_selectIcon(i,FALSE); /* And deslect the icon */ } break; case wimp_BDRAGLEFT: case wimp_BDRAGRIGHT: if (i!=viewer_NOICON) { tfile_dragSelected(i,b,"tpackage"); win_add_unknown_event_processor(tfile__dragUnknowns,t); } break; } break; } } /*----- External routines -------------------------------------------------*/ /* * BOOL tfile_okToQuit(BOOL ask) * * Use * Ensures that it is 'safe' for Glass to quit. * * Parameters * BOOL ask == should I open a dialogue to ask the user? * * Returns * TRUE if it is safe to quit, or FALSE if not. */ BOOL tfile_okToQuit(BOOL ask) { char *q; if (tfile__unsavedFiles==0 || !gPrefs_current()->cQuit) return (TRUE); else if (ask==FALSE) return (FALSE); else if (tfile__unsavedFiles==1) q=msgs_lookup("tfOTQ1"); else q=msgs_lookup("tfOTQM"); return (warning(msgs_lookup("tfOTQP"),q,tfile__unsavedFiles)); } /* * void tfile_markAsAltered(glass_tfile *t) * * Use * Marks down another alteration for the template file, changing the window * title if required etc. Also handles stuff for autosave etc. * * Parameters * glass_tfile *t == the template file to alter */ void tfile_markAsAltered(glass_tfile *t) { char buff[256]; int at; t->alts++; if (t->alts==1 || t->alts==0) { sprintf(buff,"%s *",t->filename); viewer_settitle(t->v,buff); if (t->alts==1) tfile__unsavedFiles++; t->alts=1; } if (t->sort==gPrefs_SIZE || t->sort==gPrefs_ICONS) viewer_setCompare(t->v,tfile__sort); if (!t->autoTime) { t->autoTime=alarm_timenow(); if (at=gPrefs_autoTiming(),at) { t->autoAlarm=t->autoTime+at; alarm_set(t->autoAlarm,tfile__doAutosave,t); } else t->autoAlarm=0; } if (gPrefs_current()->aAlts!=0 && t->alts>=gPrefs_current()->aAlts) tfile__doAutosave(0,t); } /* * void tfile_markAsSaved(glass_tfile *t,char *newTitle) * * Use * Marks a template file as having been saved. Turns off autosave and * things. * * Parameters * glass_tfile *t == the file to mark * char *newtitle == the new title to give to the window */ void tfile_markAsSaved(glass_tfile *t,char *newTitle) { char buff[256]; if (t->alts) { t->alts=0; tfile__unsavedFiles--; } t->loaded=TRUE; strcpy(t->filename,newTitle); viewer_settitle(t->v,newTitle); intMsgs_send(glass_SAVEFILE,t); if (t->vs) { sprintf(buff,msgs_lookup("spVT"),newTitle); viewer_settitle(t->vs,buff); } if (t->autoAlarm) alarm_remove(t->autoAlarm,t); t->autoAlarm=0; t->autoTime=0; if (t->autod) { dbox_deleteNoUpdate(t->autod); t->autoSaved=TRUE; t->autod=0; } } /* * void tfile_windowInfo(glass_windPointer *w) * * Use * Displays an info box for a single window * * Parameters * glass_windPointer *w == the window to display info on */ void tfile_windowInfo(glass_windPointer *w) { dbox d=dbox_create("windInfo"); if (!d) return; dbox_setfield(d,glass_WINAME,"%s",w->id); dbox_setfield(d,glass_WISIZE,"%s",utils_cvtSize(w->size)); dbox_setfield(d, glass_WIINDSZ, "%s", utils_cvtSize(w->size- sizeof(glass_window)- (w->def->desc.w.nicons-1)* sizeof(glass_iconDescription))); dbox_setfield(d,glass_WIICONS,"%i",w->def->desc.w.nicons); mbox(d,"tfhWI"); } /* * void tfile_deleteWindow(glass_windPointer *w) * * Use * Deletes a single window. * * Parameters * viewer_icon i == the icon to get * void *handle == the window to eliminate (as a glass_windPointer *) */ void tfile_deleteWindow(viewer_icon i,void *handle) { glass_windPointer *w=handle; unused(i); intMsgs_send(glass_DELETEWINDOW,w); viewer_removeIcon(w->i); tfile__doDeleteWindow(w); } /* * BOOL tfile_rename(char *newName,void *handle) * * Use * Renames the specified window * * Parameters * char *newName == the new name of the window * void *handle == pointer to the window structure */ BOOL tfile_rename(char *newName,void *handle) { glass_windPointer *w=handle; viewer_icon i; if (strcmp(newName,w->id)==0) return (TRUE); i=viewer_findIcon(w->t->v,newName); if (i==viewer_NOICON || i==w->i) { viewer_removeIcon(w->i); mem_useUser(indir_alloc,indir_free); strcpy(w->id,newName); i=viewer_addIcon(w->t->v,newName,"tmpltvicon",TRUE,w); viewer_setFiletype(i,0xfec); mem_useMalloc(); w->i=i; intMsgs_send(glass_RENAME,w); tfile_markAsAltered(w->t); event_clear_current_menu(); return (TRUE); } note(msgs_lookup("tfNAE"), viewer_textOfIcon(i)); return (FALSE); } /* * void tfile_saveTemplates(glass_tfile *t) * * Use * Saves a template file using a standard dialogue box * * Parameters * glass_tfile *t == the template file to save */ void tfile_saveTemplates(glass_tfile *t) { char *name; if (t->loaded) name=t->filename; else name=msgs_lookup("tfTMP"); tfile__selectSize=0; viewer_doForIcons(t->v,FALSE,tfile__size); saveas(msgs_lookup("tfSVTIT"), name, 0xfec, tfile__selectSize, tfile__saveTemplates, tfile__sendTemplates, 0, t); } /* * void tfile_saveWindow(glass_windPointer *w) * * Use * Saves a single window using a standard dialogue box * * Parameters * glass_windPointer *w == pointer to the window to save */ void tfile_saveWindow(glass_windPointer *w) { tfile__selectSize=w->size; saveas(msgs_lookup("tfSVWTIT"), msgs_lookup("tfWIN"), 0xfec, w->size, tfile__saveWindow, tfile__sendWindow, 0, w); } /* * BOOL tfile_mergeFromMemory(void **p,glass_tfile *t) * * Use * Actually does a merge operation. The target file is a glass_tfile in * memory (internal format) and the source file is a memory image of a * normal template file. * * Parameters * void **p == a flex anchor pointer to the source file * glass_tfile *t == a pointer to the destination file * * Returns * TRUE for success */ typedef struct { char **p; int offset; } tfile__datPackage; static char *tfile__dataProc(char *data,void *handle) { tfile__datPackage *p=handle; return (((int)data)+*(p->p)+p->offset); } BOOL tfile_mergeFromMemory(void **p,glass_tfile *t) { int fontData; /* Offset of font ata from start of file */ glass_windPointer *w; /* For each window we come across */ int index; /* Current index entry we're looking at */ int objoff; /* Offset of window we're looking at */ int iconoff; /* Offset of icon we're looking at */ wimp_iconflags icf; /* Icon flags for something or other */ int fheight; /* Height of a font required */ int fwidth; /* Width of a font required */ int fhandle; /* Font handle */ int fptr; /* Offset of font name */ char name[13]; /* For the name of the template */ int objtype; /* Type of current template entry */ BOOL foundOdd=FALSE; /* Found an odd type of data yet? */ int numicons; /* Number of icons in a window */ int i; /* A loop counter */ viewer_icon icn; /* Icon for checking for duplicates */ BOOL fquiet=FALSE; /* Shut up about font failures. */ tfile__datPackage pk; fontData=*intptr(*p,0); /* Offset of font data from *p */ for (index=16;*intptr(*p,index);index+=24) /* Go through index entries */ { objoff=*intptr(*p,index); /* Offset of this entry */ objtype=*intptr(*p,index+8); /* Type of this entry */ switch (objtype) /* Which type is it? */ { case 1: /* Window */ pk.p=(char **)p; pk.offset=objoff; memcpy(name,charptr(*p,index+12),12); name[12]=0; utils_ctermToNterm(name); if (icn=viewer_findIcon(t->v,name),icn) tfile_deleteWindow(icn,viewer_iconHandle(icn)); if (w=tfile__newWindow(t,name),!w) return (FALSE); /* Failed to create the window */ memcpy(&numicons,intptr(*p,objoff+84),sizeof(int)); w->size=sizeof(glass_window)+ (numicons-1)*sizeof(glass_iconDescription); if (!flex_alloc((flex_ptr)&w->def,w->size)) { viewer_removeIcon(w->i); mem_free(w); werr(FALSE,msgs_lookup("tfNEMTL")); return (FALSE); } memcpy(&w->def->desc.w,_ptr(void,*p,objoff),sizeof(wimp_wind)); icf=w->def->desc.w.titleflags; /* Get title icon flags */ if (icf & wimp_IFONT) /* Handle anti-aliased fonts */ { fhandle=(icf & 0xff000000) >> 24; /* Get internal font handle */ fptr=fontData+(fhandle-1)*48; /* Get pointer */ /* Bug fix - not word aligned!! */ memcpy(&fwidth,intptr(*p,fptr)+0,sizeof(int)); memcpy(&fheight,intptr(*p,fptr)+1,sizeof(int)); utils_ctermToNterm(charptr(*p,fptr+8)); /* Font name */ if (font_find(charptr(*p,fptr+8),fwidth,fheight,0,0,&fhandle)) { if (!fquiet) { werr(FALSE,msgs_lookup("tfCFF")); fquiet=TRUE; } icf&=~wimp_IFONT; /* Stop anti-aliasing (gives odd colours) */ } else { icf=(icf & 0x00ffffff) | (fhandle << 24); w->antiAliased=TRUE; w->fonts[fhandle]++; } w->def->desc.w.titleflags=icf; } w->def->desc.w.nicons=0; /* Don't want deletion routine dying */ if (!iconData_processIcon(w,-1,tfile__dataProc,TRUE,&pk)) { werr(FALSE,msgs_lookup("tfNEMTL")); tfile_deleteWindow(0,w); return (FALSE); } iconoff=objoff+88; /* Point to first icon definition */ for (i=0;idef->i[i].i,charptr(*p,iconoff),sizeof(wimp_icon)); w->def->i[i].selected=FALSE; w->def->i[i].edit=0; icf=w->def->i[i].i.flags; /* Get title icon flags */ if (icf & wimp_IFONT) /* Handle anti-aliased fonts */ { fhandle=(icf & 0xff000000) >> 24; /* Get internal font handle */ fptr=fontData+(fhandle-1)*48; /* Get pointer */ /* Bug fix - not word aligned!! */ memcpy(&fwidth,intptr(*p,fptr)+0,sizeof(int)); memcpy(&fheight,intptr(*p,fptr)+1,sizeof(int)); utils_ctermToNterm(charptr(*p,fptr+8)); /* Font name */ if (font_find(charptr(*p,fptr+8),fwidth,fheight,0,0,&fhandle)) { if (!fquiet) { werr(FALSE,msgs_lookup("tfCFF")); fquiet=TRUE; } icf&=~wimp_IFONT; /* Stop anti-aliasing */ } else { icf=(icf & 0x00ffffff) | (fhandle << 24); w->antiAliased=TRUE; w->fonts[fhandle]++; } w->def->i[i].i.flags=icf; } if (!iconData_processIcon(w,i,tfile__dataProc,TRUE,&pk)) { werr(FALSE,msgs_lookup("tfNEMTL")); tfile_deleteWindow(0,w); return (FALSE); } w->def->desc.w.nicons++; /* Tidy up next icon along */ iconoff+=sizeof(wimp_icon); /* Move pointer along */ } break; default: /* Anything we don't know - tell the user */ if (!foundOdd) /* Don't generate the message again */ { werr(FALSE,msgs_lookup("tfUTEC")); foundOdd=TRUE; /* Stop message repeating */ } break; } } return (TRUE); } /* * BOOL tfile_mergeFromFile(char *file,glass_tfile *t) * * Use * Merges the template file given into the given template file structure. * * Parameters * char *file == the file to load * glass_tfile *t == the template file structure to merge with */ BOOL tfile_mergeFromFile(char *file,glass_tfile *t) { os_filestr f; /* Going to make some OS_File calls */ void *p; /* p will point to the file in memory */ f.action=17; /* Read catalogue information for file */ f.name=file; /* Point to file name to find out about */ if (utils_complain(os_file(&f), msgs_lookup("tfELF"))) { return (FALSE); } if (!flex_alloc(&p,f.start)) { werr(FALSE,msgs_lookup("tfNEMTL")); return (FALSE); } f.action=16; /* Load the file */ f.loadaddr=(int)p; /* Where to load the file */ f.execaddr=0; /* Load it there!!! */ if (utils_complain(os_file(&f), msgs_lookup("tfELF"))) { flex_free(&p); flex_compact(); return (FALSE); } tfile_mergeFromMemory(&p,t); /* Now do the merge */ flex_free(&p); flex_compact(); return (TRUE); } /* * glass_tfile *tfile_createTemplateFile(char *name) * * Use * Creates a template file with the given name, but doesn't open its viewer. * * Returns * A pointer to the file structure, or zero as failure. */ glass_tfile *tfile_createTemplateFile(char *name) { glass_tfile *t; int ix,iy; mem_useUser(indir_alloc,indir_free); t=mem_alloc(sizeof(glass_tfile)); if (!t) /* Allocates memory for file structure */ { werr(FALSE,msgs_lookup("tfNEMTF")); mem_useMalloc(); return (0); } ix=(gPrefs_current()->fIcons==gPrefs_LARGE) ? 200 : 248; iy=(gPrefs_current()->fIcons==gPrefs_LARGE) ? 112 : 36; if ( t->v=viewer_create /* Now create the viewer window */ ( tfile__FILEX, /* Coords to open window */ tfile__fileHeight, ix, /* Width of 'icons' */ iy, /* Height of 'icons' */ resspr_area(), /* Sprite area for 'icons' */ name, /* What to display in the title bar */ msgs_lookup("tfBANR") /* Viewer banner line */ ), !t->v /* TRUE if creation failed */ ) { mem_free(t); /* Dispose of unwanted file structure */ mem_useMalloc(); return (0); /* Inform caller we buggered it up */ } mem_useMalloc(); strcpy(t->filename,name); /* Remember the name */ t->alts=0; /* No alterations yet */ t->loaded=FALSE; /* They can change this if they need to */ t->autoSaved=FALSE; /* Not been autosaved yet */ t->autod=0; /* No autosave dialogue box */ t->autoTime=0; /* No autosave time */ t->autoAlarm=0; /* No autosave alarm */ t->isz=gPrefs_current()->fIcons; t->sort=gPrefs_current()->fSort; viewer_eventHandler(t->v,tfile__tfileHandler,t); /* Add event handler */ viewer_rawEventHandler(t->v,tfile__raw,t); /* Raw, for broadcasts */ viewer_redrawHandler(t->v, t->isz==gPrefs_LARGE ? 0 : tfile__redrawViewer, t); viewer_setCompare(t->v,tfile__sort); tfile__fileHeight-=48; /* Displace the next file window */ if (tfile__fileHeight<652) /* Start at the top again if too low */ tfile__fileHeight=tfile__FILETOP; gSprite_new(t); return (t); } /* * glass_tfile *tfile_loadFromMemory(void **p,char *name) * * Use * Loads a file from memory, i.e. from another application via RAM * transfer. * * Parameters * void **p == the memory block that contains the file to load. * char *name == the name to give to the file. * * Returns * A pointer to the template file, or 0 */ glass_tfile *tfile_loadFromMemory(void **p,char *name) { glass_tfile *t=tfile_createTemplateFile(name); if (!t) return (0); t->loaded=TRUE; if (!tfile_mergeFromMemory(p,t)) { tfile__deleteTemplateFile(t); return (0); } if (t->sort==gPrefs_SIZE || t->sort==gPrefs_ICONS) viewer_setCompare(t->v,tfile__sort); viewer_display(t->v); /* Show the viewer window in its glory */ return (t); } /* * glass_tfile *tfile_loadFromFile(char *file,char *name) * * Use * Loads a template file into memory, translating the file into Glass's * internal format. It does not create any windows, although it does * allocate font handles. * * Parameters * char *file == the name of the file to load * char *name == the name to insert in the title bar * * Returns * A pointer to the structure definition, or 0 for failure. Note that this * will only occur if no windows could be loaded. */ glass_tfile *tfile_loadFromFile(char *file,char *name) { glass_tfile *t=tfile_createTemplateFile(name); char buff[256]; char fbuff[256]; char *parent; if (!t) return (0); t->loaded=TRUE; if (!tfile_mergeFromFile(file,t)) { tfile__deleteTemplateFile(t); return (0); } strcpy(fbuff,name); utils_leafname(fbuff)[-1]=0; parent=utils_leafname(fbuff); parent[-1]=0; if (gPrefs_current()->sLoadPSpr) { sprintf(buff,"%s.%s.!Sprites",fbuff,parent); if (res_fileExists(buff)) gSprite_mergeFromFile(t,buff); else { sprintf(buff,"%s.!Sprites",fbuff); if (res_fileExists(buff)) gSprite_mergeFromFile(t,buff); } } if (gPrefs_current()->sLoadSpr) { sprintf(buff,"%s.%s.Sprites",fbuff,parent); if (res_fileExists(buff)) gSprite_mergeFromFile(t,buff); } viewer_display(t->v); /* Show the viewer window in its glory */ return (t); } /* * void tfile_dragSelected(viewer_icon i,wimp_bbits b,char *package) * * Use * As for viewer_dragSelected, but uses the specified sprite as the * 'package' sprite is solid sprite drags are enabled. * * Parameters * viewer_icon i == the icon to drag * wimp_bbits b == the button status that started it off * char *package == the sprite to use for a package drag */ void tfile_dragSelected(viewer_icon i,wimp_bbits b,char *package) { sprite_id sid; sid.s.name=package; sid.tag=0; sprite_rename(resspr_area(),&sid,"package"); viewer_dragSelected(i,b); sid.s.name="package"; sprite_rename(resspr_area(),&sid,package); }