/* * glass.c * * Main control section and user interface * * © 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 #include #include #include "dll.h" /* * Steel headers */ #define _STDAPP #define _XFER #define _LOWLVL #include "steel/Steel.h" #include "steel/viewer.h" #include "steel/mem.h" #include "steel/caretptr.h" #include "steel/buttons.h" #include "steel/sculptrix.h" #include "steel/flex.h" /* * Glass headers */ #include "gStruct.h" #include "gIcons.h" #include "gMenus.h" #include "glass.h" #include "toolbox.h" #include "tfile.h" #include "intMsgs.h" #include "gPrefs.h" #include "gSprite.h" #include "indir.h" #include "window.h" #include "tearEdit.h" /*----- External dependencies ---------------------------------------------*/ extern char date[], cright[]; #define VERSION 100 /*----- Static global variables -------------------------------------------*/ static BOOL glass_genDump; /* Send timings to dump (stderr) */ static BOOL glass_noWindow; /* Turn off the nice intro window */ /*----- Icon bar handlers -------------------------------------------------*/ /* * BOOL glass_unknowns(wimp_eventstr *e,void *handle) * * Use * Vets unknown events. The important ones at the moment are * Message_DataOpen and Message_PreQuit. Glass 1.xx supports the RISC * OS 3 prequit convention to avoid the old misunderstanding. This may * cause problems under RISC OS 2. If so, they'll just have to upgrade... * * Parameters * wimp_eventstr *e == the event in question * void *handle == 0 * * Returns * TRUE if the event has now been processed. */ static BOOL glass_unknowns(wimp_eventstr *e,void *handle) { BOOL handled=FALSE; int filetype; char *filename; char buff[256]; os_regset r; unused(handle); switch (e->e) { case wimp_ESEND: case wimp_ESENDWANTACK: switch (e->data.msg.hdr.action) { case wimp_MDATAOPEN: filetype=xferrecv_checkinsert(&filename); switch (filetype) { case 0xfec: /* Template file */ xferrecv_insertfileok(); tfile_loadFromFile(filename,xferrecv_nameToImport()); handled=TRUE; break; } break; case wimp_MPREQUIT: if (tfile_okToQuit(TRUE)) intMsgs_send(glass_KILLFILES); else { e->data.msg.hdr.your_ref=e->data.msg.hdr.my_ref; wimpt_noerr(wimp_sendmessage(wimp_EACK, &e->data.msg, e->data.msg.hdr.task)); } handled=TRUE; break; case wimp_MMODECHANGE: intMsgs_send(glass_MODECHANGE); break; case wimp_SAVEDESK: sprintf(buff,"Run %s\n",getenv("Glass$Dir")); r.r[0]=2; r.r[1]=e->data.msg.data.savedesk.filehandle; r.r[2]=(int)buff; r.r[3]=strlen(buff); wimpt_noerr(os_swix(XOS_GBPB,&r)); handled=TRUE; break; } break; } return (handled); } /* * void glass_ibarHandler(ibicon i,ibicon_eventType e,void *handle) * * Use * Handles events for the icon bar icon (such as help requests, load and * save messages, and of course mouse clicks). * * Parameters * ibicon i == the handle of the icon * ibicon_eventType e == what has happened * void *handle == a dummy handle */ static void glass_ibarHandler(ibicon i,ibicon_eventType e,void *handle) { int filetype; /* Filetype of a file to import */ char *filename; /* Filename of a file */ int estsize; /* Estimated size of a file to import */ void *p; /* Pointer to loaded file */ unused(i); /* Not actually interested in the icon */ unused(handle); /* Not at all interested in the handle */ switch (e) /* Find out what's going on */ { case ibicon_LEFTCLICK: /* Clicked with select */ { glass_tfile *t; if (t=tfile_createTemplateFile(msgs_lookup("tfUNT")),t) viewer_display(t->v); } break; case ibicon_RIGHTCLICK: /* Clicked with adjust */ break; /* Ignore it and hope it goes away */ case ibicon_LOAD: /* Load request from Filer */ filetype=xferrecv_checkinsert(&filename); /* Get information */ switch (filetype) { case 0xfec: /* Template file */ tfile_loadFromFile(filename,xferrecv_nameToImport()); xferrecv_insertfileok(); break; } break; case ibicon_SAVE: /* Save from another application */ filetype=xferrecv_checkimport(&estsize); /* Get information */ switch (filetype) { case 0xfec: /* Template file */ if (xferrecv_returnImportedBlock(&p)!=-1) { tfile_loadFromMemory(&p,xferrecv_nameToImport()); flex_free(&p); flex_compact(); } break; } break; case ibicon_HELP: /* Help request */ help_startHelp(); /* Start a help reply */ help_addLine(msgs_lookup("wehIB")); help_endHelp(); /* Send the message back */ break; } } /* * void glass_ibarMenuHandler(int hit[],void *handle) * * Use * Processes menu clicks for the icon bar menu. * * Parameters * int hit[] == array of menu hits * void *handle == 0 (dummy handle) */ static void glass_ibarMenuHandler(int hit[],void *handle) { unused(handle); /* This menu not attached to data struct */ switch (hit[0]) /* Check which item was chosen */ { case glass_IBARINFO: /* About this program */ progInfo("Glass", msgs_lookup("wePUR"), cright, VERSION, date); break; case glass_IBARPREFS: /* Preferences dialogue */ gPrefs_edit(); /* Edit the preferences... */ break; case glass_IBARTBOX: /* Toolbox (window manipulation) */ toolbox(); /* Handles it all... */ break; case glass_IBARHEAPINFO: /* Heap info display */ indir_heapInfo(); /* Display */ break; case glass_IBARQUIT: /* Quit program */ if (tfile_okToQuit(TRUE)) /* Check the user is sure about this */ exit(0); /* End Glass and announce success */ break; } } /* * void glass_ibarMenuHelp(int hit[],void *handle) * * Use * Help processor for icon bar menu. * * Parameters * int hit[] == the item to give help for * void *handle == a dummy handle */ static void glass_ibarMenuHelp(int hit[],void *handle) { unused(handle); help_startHelp(); help_readFromMenu("wemhIB",hit); help_endHelp(); } /*----- Initialisation ----------------------------------------------------*/ /* * void glass_exit(void) * * Use * Exit handler, creates internal broadcast to close down everything. */ static void glass_exit(void) { intMsgs_send(glass_CLOSEDOWN); } /* * void glass_iconbar(void) * * Use * Sets up the icon bar during Glass initialisation. Essentially, it * installs an icon bar, attaches a menu to it, and gives it a handler. * It also establishes a handler for loading and mouse clicks. */ static void glass_iconbar(void) { ibicon i; /* Handle for the icon we will create */ menu m; /* The menu to attach to the icon */ m=menu_new("Glass",msgs_lookup("weIBM")); i=ibicon_create(ibicon_RIGHT,"!glass",ibicon_WIMPAREA,0,0); ibicon_attachMenu(i,m,glass_ibarMenuHandler,glass_ibarMenuHelp,0); ibicon_eventHandler(i,glass_ibarHandler,0); } /* * void glass_scanCLI(int argc,char *argv[],BOOL inited) * * Use * Scans command line string and loads relevant files * * Parameters * int argc == the number of words in the string * char *argv[] == the words, as an array of strings * BOOL inited == whether we have initialised the WIMP */ static void glass_scanCLI(int argc,char *argv[],BOOL inited) { int i; for (i=1;i | ]...\n" "\n" " == file name to load\n" "