4 * Handling of the tool and info bars
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
44 #include "steel/Steel.h"
46 #include "steel/interface.h"
47 #include "steel/sculptrix.h"
48 #include "steel/buttons.h"
49 #include "steel/caretPtr.h"
50 #include "steel/flex.h"
51 #include "steel/akbd.h"
52 #include "steel/coords.h"
53 #include "steel/pointer.h"
54 #include "steel/bbc.h"
55 #include "steel/colourtran.h"
56 #include "steel/font.h"
80 /*----- Private variables -------------------------------------------------*/
82 static dbox window__toolbar; /* Dialogue box handle for the tool bar */
83 static dbox window__infobar; /* Dialogue box handle for the info bar */
84 static window__infoWidth; /* The natural width of the info bar */
85 static window__infoMax; /* The maximum width of the info bar */
86 static int window__toolX=98;
87 static int window__toolY=912;
88 static int window__infoX=234;
89 static int window__infoY=260;
91 /*----- Main code ---------------------------------------------------------*/
94 * void window__setToolBarPositions(wimp_openstr *o)
97 * Displays the tool and info bars according to current settings etc.
100 * wimp_openstr *o == the position of the selection owner window, or 0.
101 * This is updated to put the window somewhere nice without flicker.
104 void window__setToolBarPositions(wimp_openstr *o)
111 int tgap,bgap,lgap,rgap;
112 glass_windPointer *w=window_selectionOwner();
114 /* --- More WindowManager cunningness --- *
116 * When you click on the scroll arrows, the Wimp decides it'd be a good
117 * plan to ask you to open the window behind *itself*. This gets nobbled
118 * here, and so the whole window frame flickes disgustingly. We bodge.
119 * We also try to do absolutely nothing if the window isn't going anywhere.
123 !wimpt_justChangedMode() &&
125 (!memcmp(&o->box,&w->def->desc.w.box,sizeof(wimp_box)) &&
126 o->behind==w->def->desc.w.behind)))
128 wimpt_noerr(wimp_open_wind(o));
132 wimpt_noerr(wimp_get_wind_state(w->h,&t));
134 wimpt_noerr(wimp_getwindowoutline(&r));
135 lgap=t.o.box.x0-r.box.x0;
136 rgap=r.box.x1-t.o.box.x1;
137 tgap=r.box.y1-t.o.box.y1;
138 bgap=t.o.box.y0-r.box.y0;
144 wimpt_noerr(wimp_open_wind(o));
145 wimpt_noerr(wimp_get_wind_state(w->h,&t));
148 if (window__infobar && !gPrefs_current()->iFloating)
150 if (t.o.behind==dbox_syshandle(window__infobar))
152 wimpt_noerr(wimp_get_wind_state(dbox_syshandle(window__infobar),&s));
153 t.o.behind=s.o.behind;
156 if (window__toolbar && !gPrefs_current()->tFloating)
158 if (t.o.behind==dbox_syshandle(window__toolbar))
160 wimpt_noerr(wimp_get_wind_state(dbox_syshandle(window__toolbar),&s));
161 t.o.behind=s.o.behind;
164 if (t.flags & wimp_WCLICK_TOGGLE && o)
166 wimpt_noerr(wimp_open_wind(o));
167 wimpt_noerr(wimp_get_wind_state(w->h,&t));
172 wimpt_noerr(wimp_get_wind_state(dbox_syshandle(window__toolbar),&s));
173 width=s.o.box.x1-s.o.box.x0;
174 height=s.o.box.y1-s.o.box.y0;
175 if (!gPrefs_current()->tFloating)
177 if (gPrefs_current()->tLeft)
178 s.o.box.x0=gPrefs_current()->tPosn.x-width+t.o.box.x0-lgap;
180 s.o.box.x0=gPrefs_current()->tPosn.x-width+t.o.box.x1+rgap;
181 s.o.box.x1=s.o.box.x0+width;
182 s.o.box.y1=gPrefs_current()->tPosn.y+t.o.box.y1+tgap-wimpt_dy();
183 s.o.box.y0=s.o.box.y1-height;
184 window__toolX=s.o.box.x1;
185 window__toolY=s.o.box.y1;
186 s.o.behind=t.o.behind;
191 s.o.box.x0=window__toolX-width;
192 s.o.box.x1=s.o.box.x0+width;
193 s.o.box.y1=window__toolY;
194 s.o.box.y0=s.o.box.y1-height;
197 wimpt_noerr(wimp_open_wind(&s.o));
201 wimpt_noerr(wimp_get_wind_state(dbox_syshandle(window__infobar),&s));
202 height=s.o.box.y1-s.o.box.y0;
203 width=(w->renumber ? window__infoMax : window__infoWidth);
204 if (!gPrefs_current()->iFloating)
206 s.o.box.x0=gPrefs_current()->iPosn.x+t.o.box.x0-lgap+wimpt_dx();
207 s.o.box.x1=s.o.box.x0+width;
208 if (gPrefs_current()->iUnder)
209 s.o.box.y1=gPrefs_current()->iPosn.y+t.o.box.y0-bgap;
211 s.o.box.y1=gPrefs_current()->iPosn.y+t.o.box.y1+tgap;
212 s.o.box.y0=s.o.box.y1-height;
213 window__infoX=s.o.box.x0;
214 window__infoY=s.o.box.y1;
215 s.o.behind=t.o.behind;
220 s.o.box.x0=window__infoX;
221 s.o.box.x1=s.o.box.x0+width;
222 s.o.box.y1=window__infoY;
223 s.o.box.y0=s.o.box.y1-height;
226 wimpt_noerr(wimp_open_wind(&s.o));
230 o->behind=t.o.behind;
231 wimpt_noerr(wimp_open_wind(o));
236 * void window__updateInfoBar(void)
239 * Updates the settings on the info bar. If a setting hasn't changed, then
240 * it isn't updated (reducing flicker).
243 * BOOL force == whether to force an update of everything.
246 void window__updateInfoBar(BOOL force)
250 static glass_windPointer *ow;
252 static int orenum=-1;
255 glass_windPointer *wso=window_selectionOwner();
267 if (!window__infobar)
270 dbox_setfield(window__infobar,glass_IBWIND,"%s",wso->id);
272 wimpt_noerr(wimp_get_point_info(&m));
273 x=ow->def->desc.w.box.x0-ow->def->desc.w.scx;
274 y=ow->def->desc.w.box.y1-ow->def->desc.w.scy;
277 if (m.w!=ow->h || m.i<-1)
287 dbox_setfield(window__infobar,glass_IBX,"");
290 dbox_setfield(window__infobar,glass_IBX,"%i",m.x);
299 dbox_setfield(window__infobar,glass_IBY,"");
302 dbox_setfield(window__infobar,glass_IBY,"%i",m.y);
311 else if (wso->testMode)
316 ni=window__pointerInfo(ow,-1,FALSE);
317 if (ni & window__ZONEMASK)
325 dbox_setfield(window__infobar,glass_IBICON,"");
328 dbox_setfield(window__infobar,glass_IBICON,msgs_lookup("wdBACKG"));
331 dbox_setfield(window__infobar,glass_IBICON,"%i",ni);
339 * BOOL window__toolRaw(dbox d,wimp_eventstr *e,void *handle)
342 * Handles odd events for tool and info boxes (mainly moves - getting the
343 * positioning right, updating the preferences entries and so on).
346 * dbox d == the dialogue box handle
347 * wimp_eventstr *e == the event that happened
348 * void *handle == a pointer (ignored)
351 * TRUE if the event has been processed.
354 static BOOL window__toolRaw(dbox d,wimp_eventstr *e,void *handle)
360 int tgap,bgap,lgap,rgap;
362 glass_windPointer *wso=window_selectionOwner();
368 if (d==window__infobar)
371 wimpt_noerr(wimp_redraw_wind(&r,&more));
374 wimp_setcolour(0x81);
376 sculptrix_redrawWindow(&r);
377 wimpt_noerr(wimp_get_rectangle(&r,&more));
383 if (wimpt_justChangedMode()) /* We've already moved them with the */
384 { /* main window, so the WIMP just messes */
385 handled=TRUE; /* it all up */
388 win_adjustBox(&e->data.o);
389 wimpt_noerr(wimp_get_wind_state(wso->h,&s));
391 wimpt_noerr(wimp_getwindowoutline(&r));
392 lgap=s.o.box.x0-r.box.x0;
393 rgap=r.box.x1-s.o.box.x1;
394 tgap=r.box.y1-s.o.box.y1;
395 bgap=s.o.box.y0-r.box.y0;
396 wimpt_noerr(wimp_get_wind_state(e->data.o.w,&t));
397 if (d==window__toolbar)
399 if (!gPrefs_current()->tFloating)
401 gPrefs_current()->tLeft=abs(e->data.o.box.x1-s.o.box.x0)<
402 abs(e->data.o.box.x0-s.o.box.x1);
403 if (gPrefs_current()->tLeft)
404 gPrefs_current()->tPosn.x=e->data.o.box.x1-s.o.box.x0+lgap;
406 gPrefs_current()->tPosn.x=e->data.o.box.x1-s.o.box.x1-rgap;
407 gPrefs_current()->tPosn.y=e->data.o.box.y1-s.o.box.y1-tgap+
409 e->data.o.behind=t.o.behind;
411 window__toolX=e->data.o.box.x1;
412 window__toolY=e->data.o.box.y1;
414 else if (d==window__infobar)
416 if (!gPrefs_current()->iFloating)
418 gPrefs_current()->iUnder=abs(e->data.o.box.y1-s.o.box.y0)<
419 abs(e->data.o.box.y0-s.o.box.y1);
420 gPrefs_current()->iPosn.x=e->data.o.box.x0-s.o.box.x0;
421 if (gPrefs_current()->iUnder)
422 gPrefs_current()->iPosn.y=e->data.o.box.y1-s.o.box.y0+bgap;
424 gPrefs_current()->iPosn.y=e->data.o.box.y1-s.o.box.y1-tgap;
425 e->data.o.behind=t.o.behind;
427 window__infoX=e->data.o.box.x0;
428 window__infoY=e->data.o.box.y1;
430 wimpt_noerr(wimp_open_wind(&e->data.o));
438 * void window__infoEvents(dbox d,dbox_field f,void *handle)
441 * Handles events on the info bar.
444 * dbox d == the dialogue box handle
445 * dbox_field f == the event that happened
446 * void *handle == a pointer (ignored)
449 static void window__infoEvents(dbox d,dbox_field f,void *handle)
453 glass_windPointer *wso=window_selectionOwner();
460 dr.window=dbox_syshandle(d);
461 dr.type=wimp_MOVE_WIND;
467 window__simMenu(wso,glass_TWMISC,glass_TWMTEST);
471 window__simMenu(wso,glass_TWMISC,glass_TWMTEST);
476 help_addLine(msgs_lookup("wdhIB"));
484 * void window__toolEvents(dbox d,dbox_field f,void *handle)
487 * Handles events on the tool bar.
490 * dbox d == the dialogue box handle
491 * dbox_field f == the event that happened
492 * void *handle == a pointer (ignored)
495 static void window__toolEvents(dbox d,dbox_field f,void *handle)
498 glass_windPointer *wso=window_selectionOwner();
526 dr.window=dbox_syshandle(d);
527 dr.type=wimp_MOVE_WIND;
532 help_addLine(msgs_lookup("wdhTB"));
537 if (f>=0 && f<=(sizeof(hit1)/sizeof(int)))
540 window__simMenu(wso,hit1[f],hit2[f]);
548 * void window_updateToolbar(void)
551 * Updates the display of toolbars as necessary in line with new
552 * Preferences settings. It is assumed that Preferences is intelligent
553 * enough to only call this if something actually needs to be done!
556 void window_updateToolbar(void)
558 glass_windPointer *wso=window_selectionOwner();
559 if (!wso) /* Nothing doing if no current window */
561 if (gPrefs_current()->tDisplay)
563 if (!window__toolbar)
565 window__toolbar=dbox_create("toolbar");
568 dbox_eventHandler(window__toolbar,window__toolEvents,0);
569 dbox_rawEventHandler(window__toolbar,window__toolRaw,0);
576 dbox_delete(window__toolbar);
579 if (gPrefs_current()->iDisplay)
581 if (!window__infobar)
583 window__infobar=dbox_create("infobar");
586 dbox_eventHandler(window__infobar,window__infoEvents,0);
587 dbox_rawEventHandler(window__infobar,window__toolRaw,0);
589 dbox_shadeicon(window__infobar,glass_IBEDIT,TRUE);
590 dbox_shadeicon(window__infobar,glass_IBTEST,TRUE);
591 dbox_selecticon(window__infobar,glass_IBEDIT,TRUE);
592 dbox_selecticon(window__infobar,glass_IBTEST,FALSE);
594 dbox_selecticon(window__infobar,glass_IBEDIT,!wso->testMode);
595 dbox_selecticon(window__infobar, glass_IBTEST,wso->testMode);
596 dbox_shadeicon(window__infobar,glass_IBEDIT,wso->renumber);
597 dbox_shadeicon(window__infobar,glass_IBTEST,wso->renumber);
601 dbox_setfield(window__infobar,
603 window__lowestSelected(wso));
607 window__updateInfoBar(TRUE);
612 dbox_delete(window__infobar);
615 window__setToolBarPositions(0);
619 * void window__toggleRenumber(glass_windPointer *w)
622 * Updates the info bar after entering or leaving renumber-mode. w is
623 * the currently selected window.
626 void window__toggleRenumber(glass_windPointer *w)
632 dbox_setfield(window__infobar,
635 window__lowestSelected(w));
639 dbox_shadeicon(window__infobar,glass_IBEDIT,w->renumber);
640 dbox_shadeicon(window__infobar,glass_IBTEST,w->renumber);
642 dbox_shadeicon(window__infobar,glass_IBEDIT,TRUE);
643 dbox_shadeicon(window__infobar,glass_IBTEST,TRUE);
646 window__setToolBarPositions(0);
651 * void window__toggleTest(glass_windPointer *w)
654 * Updates the info bar after entering or leaving test-mode. w is the
655 * currently selected window.
659 void window__toggleTest(glass_windPointer *w)
663 dbox_selecticon(window__infobar,glass_IBEDIT,!w->testMode);
664 dbox_selecticon(window__infobar,glass_IBTEST,w->testMode);
670 * void window__updateInfoName(char *newname)
673 * Updates the name in the info bar
676 void window__updateInfoName(char *newname)
679 dbox_setfield(window__infobar,glass_IBWIND,"%s",newname);
683 * void window__nextRenumber(glass_windPointer *w)
686 * Updates the next renumber icon number display.
689 void window__nextRenumber(glass_windPointer *w)
693 dbox_setfield(window__infobar,glass_IBRENUM,"%i",
694 window__lowestSelected(w));
699 * void window__moveToolbars(glass_windPointer *w)
702 * Moves the toolbars and attaches them to a new window
705 * glass_windPointer *w == the window to attach the bars to
708 void window__moveToolbars(glass_windPointer *w)
712 if (!window__toolbar && gPrefs_current()->tDisplay)
714 window__toolbar=dbox_create("toolbar");
717 dbox_eventHandler(window__toolbar,window__toolEvents,0);
718 dbox_rawEventHandler(window__toolbar,window__toolRaw,0);
721 if (!window__infobar && gPrefs_current()->iDisplay)
723 window__infobar=dbox_create("infobar");
726 dbox_eventHandler(window__infobar,window__infoEvents,0);
727 dbox_rawEventHandler(window__infobar,window__toolRaw,0);
730 window__updateInfoBar(TRUE);
731 window__setToolBarPositions(0);
735 dbox_shadeicon(window__infobar,glass_IBEDIT,TRUE);
736 dbox_shadeicon(window__infobar,glass_IBTEST,TRUE);
737 dbox_selecticon(window__infobar,glass_IBEDIT,TRUE);
738 dbox_selecticon(window__infobar,glass_IBTEST,FALSE);
740 dbox_selecticon(window__infobar,glass_IBEDIT,!w->testMode);
741 dbox_selecticon(window__infobar,glass_IBTEST,w->testMode);
742 dbox_shadeicon(window__infobar,glass_IBEDIT,w->renumber);
743 dbox_shadeicon(window__infobar,glass_IBTEST,w->renumber);
747 dbox_setfield(window__infobar,
750 window__lowestSelected(w));
757 dbox_delete(window__toolbar);
759 dbox_delete(window__infobar);
766 * void window__tbarInit(void)
769 * Initialises the toolbar system
772 void window__tbarInit(void)
775 wdef=&template_find("infobar")->window;
776 window__infoWidth=wdef->box.x1-wdef->box.x0;
777 window__infoMax=wdef->ex.x1-wdef->ex.x0;