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
39 #include "steel/Steel.h"
41 #include "steel/sculptrix.h"
42 #include "steel/pointer.h"
43 #include "steel/bbc.h"
54 /*----- Constants ---------------------------------------------------------*/
56 /*----- Static global variables -------------------------------------------*/
58 static BOOL toolbox__opened;
59 static dbox toolbox__dbox;
60 static dbox_field toolbox__selected=-1;
61 static BOOL toolbox__released;
62 static int toolbox__oldCol;
64 /*----- Function prototypes -----------------------------------------------*/
66 static void toolbox__idles(void *handle);
67 void toolSupprt_doDrag(wimp_dragstr *d);
69 /*----- Low-level routines ------------------------------------------------*/
72 * void toolbox__deselect(void)
75 * Deselects the current tool (if any)
78 static void toolbox__deselect(void)
80 wimpt_noerr(sculptrix_doSlab(dbox_syshandle(toolbox__dbox),
84 win_removeIdleClaimer(toolbox__idles,0);
85 pointer_reset_shape();
90 * void toolbox__selectTool(dbox_field f)
93 * Selects the given tool, and sets up event handlers and things as
97 * dbox_field f == the field to select
100 static void toolbox__selectTool(dbox_field f)
102 if (toolbox__selected!=-1)
104 if (toolbox__selected==f)
111 wimpt_noerr(sculptrix_doSlab(dbox_syshandle(toolbox__dbox),
115 win_removeIdleClaimer(toolbox__idles,0);
118 wimpt_noerr(sculptrix_doSlab(dbox_syshandle(toolbox__dbox),
120 sculptrix_slabColour(),
122 win_addIdleClaimer(toolbox__idles,2,0);
124 toolbox__released=FALSE;
127 /*----- Event handlers ----------------------------------------------------*/
130 * void toolbox__idles(void *handle)
133 * Handles polling while the toolbox is active.
139 static void toolbox__idles(void *handle)
145 static sprite_id id={"ptr_tbx",0};
146 static int trans[6]={0,0,2,3,4,1};
149 wimpt_noerr(pointer_set_shape(resspr_area(),&id,0,0));
150 wimpt_noerr(wimp_get_point_info(&m));
152 toolbox__released=TRUE;
153 if ((m.bbits==4 || m.bbits==1) && m.w!=dbox_syshandle(toolbox__dbox)
154 && toolbox__released)
156 sel=toolbox__selected;
157 toolbox__released=FALSE;
161 wimpt_fake_event(&e);
162 event_process(); /* Stop any drags in rest of program */
167 wimp_sendwmessage(wimp_ECLOSE,(wimp_msgstr *)&s.o,m.w,m.i);
170 wimp_get_wind_state(m.w,&s);
172 wimp_sendwmessage(wimp_EOPEN,(wimp_msgstr *)&s.o,m.w,m.i);
177 d.box.x0=d.box.x1=m.x;
178 d.box.y0=d.box.y1=m.y;
179 toolSupprt_doDrag(&d);
182 toolbox__released=FALSE;
186 else if (bbc_inkey(-113))
191 * void toolbox__events(dbox d,dbox_field f,void *handle)
194 * Handles events for the toolbox window.
197 * dbox d == toolbox__dbox
198 * dbox_field f == the event to handle (icon handle or special code)
202 static void toolbox__events(dbox d,dbox_field f,void *handle)
209 dbox_hide(toolbox__dbox);
210 if (toolbox__selected!=-1)
212 dbox_delete(toolbox__dbox);
217 help_addLine(msgs_lookup("tbhTB"));
227 toolbox__selectTool(f);
232 /*----- External routines -------------------------------------------------*/
235 * BOOL toolbox_toolSelected(void)
238 * TRUE if there is a tool selected. This is useful for handlers thinking
239 * of starting drag events.
242 BOOL toolbox_toolSelected(void)
244 return (toolbox__selected!=-1);
251 * Opens the toolbox window.
258 if (!toolbox__dbox) /* Is it open yet? */
260 if (toolbox__dbox=dbox_create("toolbox"),!toolbox__dbox)
262 if (!toolbox__opened) /* Move to top-right corner to start off */
264 wimpt_noerr(wimp_get_wind_state(dbox_syshandle(toolbox__dbox),&s));
265 xoff=wimpt_scwidth()-s.o.box.x1;
266 yoff=wimpt_scheight()-s.o.box.y1;
271 wimpt_noerr(wimp_open_wind(&s.o));
272 toolbox__opened=TRUE;
274 dbox_eventHandler(toolbox__dbox,toolbox__events,0);
276 dbox_display(toolbox__dbox,TRUE);