/* * toolbox.c * * Toolbox handling * * © 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 */ /* * Steel headers */ #define _STDAPP #include "steel/Steel.h" #include "steel/sculptrix.h" #include "steel/pointer.h" #include "steel/bbc.h" /* * Glass headers */ #include "gIcons.h" #include "glass.h" #include "toolbox.h" /*----- Constants ---------------------------------------------------------*/ /*----- Static global variables -------------------------------------------*/ static BOOL toolbox__opened; static dbox toolbox__dbox; static dbox_field toolbox__selected=-1; static BOOL toolbox__released; static int toolbox__oldCol; /*----- Function prototypes -----------------------------------------------*/ static void toolbox__idles(void *handle); void toolSupprt_doDrag(wimp_dragstr *d); /*----- Low-level routines ------------------------------------------------*/ /* * void toolbox__deselect(void) * * Use * Deselects the current tool (if any) */ static void toolbox__deselect(void) { wimpt_noerr(sculptrix_doSlab(dbox_syshandle(toolbox__dbox), toolbox__selected, toolbox__oldCol, 0)); win_removeIdleClaimer(toolbox__idles,0); pointer_reset_shape(); toolbox__selected=-1; } /* * void toolbox__selectTool(dbox_field f) * * Use * Selects the given tool, and sets up event handlers and things as * necessary. * * Parameters * dbox_field f == the field to select */ static void toolbox__selectTool(dbox_field f) { if (toolbox__selected!=-1) { if (toolbox__selected==f) { toolbox__deselect(); return; } else { wimpt_noerr(sculptrix_doSlab(dbox_syshandle(toolbox__dbox), toolbox__selected, toolbox__oldCol, 0)); win_removeIdleClaimer(toolbox__idles,0); } } wimpt_noerr(sculptrix_doSlab(dbox_syshandle(toolbox__dbox), f, sculptrix_slabColour(), &toolbox__oldCol)); win_addIdleClaimer(toolbox__idles,2,0); toolbox__selected=f; toolbox__released=FALSE; } /*----- Event handlers ----------------------------------------------------*/ /* * void toolbox__idles(void *handle) * * Use * Handles polling while the toolbox is active. * * Parameters * void *handle == 0 */ static void toolbox__idles(void *handle) { wimp_mousestr m; wimp_wstate s; wimp_dragstr d; int sel; static sprite_id id={"ptr_tbx",0}; static int trans[6]={0,0,2,3,4,1}; wimp_eventstr e; unused(handle); wimpt_noerr(pointer_set_shape(resspr_area(),&id,0,0)); wimpt_noerr(wimp_get_point_info(&m)); if (!m.bbits) toolbox__released=TRUE; if ((m.bbits==4 || m.bbits==1) && m.w!=dbox_syshandle(toolbox__dbox) && toolbox__released) { sel=toolbox__selected; toolbox__released=FALSE; if (m.bbits==4) toolbox__deselect(); e.e=wimp_EUSERDRAG; wimpt_fake_event(&e); event_process(); /* Stop any drags in rest of program */ switch (sel) { case glass_TBCLOSE: s.o.w=m.w; wimp_sendwmessage(wimp_ECLOSE,(wimp_msgstr *)&s.o,m.w,m.i); break; case glass_TBBACK: wimp_get_wind_state(m.w,&s); s.o.behind=-2; wimp_sendwmessage(wimp_EOPEN,(wimp_msgstr *)&s.o,m.w,m.i); break; default: d.window=m.w; d.type=trans[sel]; d.box.x0=d.box.x1=m.x; d.box.y0=d.box.y1=m.y; toolSupprt_doDrag(&d); break; } toolbox__released=FALSE; if (m.bbits==4) toolbox__deselect(); } else if (bbc_inkey(-113)) toolbox__deselect(); } /* * void toolbox__events(dbox d,dbox_field f,void *handle) * * Use * Handles events for the toolbox window. * * Parameters * dbox d == toolbox__dbox * dbox_field f == the event to handle (icon handle or special code) * void *handle == 0 */ static void toolbox__events(dbox d,dbox_field f,void *handle) { unused(d); unused(handle); switch (f) { case dbox_CLOSE: dbox_hide(toolbox__dbox); if (toolbox__selected!=-1) toolbox__deselect(); dbox_delete(toolbox__dbox); toolbox__dbox=0; break; case dbox_HELP: help_startHelp(); help_addLine(msgs_lookup("tbhTB")); help_readFromIcon(); help_endHelp(); break; case glass_TBCLOSE: case glass_TBBACK: case glass_TBSIZE: case glass_TBHSCR: case glass_TBVSCR: case glass_TBMOVE: toolbox__selectTool(f); break; } } /*----- External routines -------------------------------------------------*/ /* * BOOL toolbox_toolSelected(void) * * Returns * TRUE if there is a tool selected. This is useful for handlers thinking * of starting drag events. */ BOOL toolbox_toolSelected(void) { return (toolbox__selected!=-1); } /* * void toolbox(void) * * Use * Opens the toolbox window. */ void toolbox(void) { wimp_wstate s; int xoff,yoff; if (!toolbox__dbox) /* Is it open yet? */ { if (toolbox__dbox=dbox_create("toolbox"),!toolbox__dbox) return; if (!toolbox__opened) /* Move to top-right corner to start off */ { wimpt_noerr(wimp_get_wind_state(dbox_syshandle(toolbox__dbox),&s)); xoff=wimpt_scwidth()-s.o.box.x1; yoff=wimpt_scheight()-s.o.box.y1; s.o.box.x0+=xoff; s.o.box.x1+=xoff; s.o.box.y0+=yoff; s.o.box.y1+=yoff; wimpt_noerr(wimp_open_wind(&s.o)); toolbox__opened=TRUE; } dbox_eventHandler(toolbox__dbox,toolbox__events,0); } dbox_display(toolbox__dbox,TRUE); }