1 /********************************************************************************
2 *                                                                               *
3 *                       T o o l B a r G r i p   W i d g e t                     *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2000,2005 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXToolBarGrip.cpp,v 1.23 2005/02/04 03:41:00 fox Exp $                   *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "fxkeys.h"
28 #include "FXHash.h"
29 #include "FXThread.h"
30 #include "FXStream.h"
31 #include "FXString.h"
32 #include "FXSize.h"
33 #include "FXPoint.h"
34 #include "FXRectangle.h"
35 #include "FXRegistry.h"
36 #include "FXApp.h"
37 #include "FXDCWindow.h"
38 #include "FXToolBar.h"
39 #include "FXToolBarGrip.h"
40 
41 
42 /*
43   Notes:
44   - Tool bar grip is a small grabber contained in the toolbar which lets
45     a user move the toolbar around, dock and undock it, and so on.
46   - The convention is to let single-rebar tool bar grips rearrange the
47     bars in a dock site, and double-rebar grips dock and undock.
48     This convention is recommended but not enforced.
49 */
50 
51 
52 // Size
53 #define GRIP_SINGLE  3          // Single grip for arrangable toolbars
54 #define GRIP_DOUBLE  7          // Double grip for dockable toolbars
55 
56 #define JUSTIFY_MASK (JUSTIFY_HZ_APART|JUSTIFY_VT_APART)
57 
58 
59 using namespace FX;
60 
61 /*******************************************************************************/
62 
63 namespace FX {
64 
65 // Map
66 FXDEFMAP(FXToolBarGrip) FXToolBarGripMap[]={
67   FXMAPFUNC(SEL_PAINT,0,FXToolBarGrip::onPaint),
68   FXMAPFUNC(SEL_ENTER,0,FXToolBarGrip::onEnter),
69   FXMAPFUNC(SEL_LEAVE,0,FXToolBarGrip::onLeave),
70   FXMAPFUNC(SEL_MOTION,0,FXToolBarGrip::onMotion),
71   FXMAPFUNC(SEL_LEFTBUTTONPRESS,0,FXToolBarGrip::onLeftBtnPress),
72   FXMAPFUNC(SEL_LEFTBUTTONRELEASE,0,FXToolBarGrip::onLeftBtnRelease),
73   FXMAPFUNC(SEL_KEYPRESS,0,FXToolBarGrip::onKeyPress),
74   FXMAPFUNC(SEL_KEYRELEASE,0,FXToolBarGrip::onKeyRelease),
75   FXMAPFUNC(SEL_QUERY_TIP,0,FXToolBarGrip::onQueryTip),
76   FXMAPFUNC(SEL_QUERY_HELP,0,FXToolBarGrip::onQueryHelp),
77   FXMAPFUNC(SEL_COMMAND,FXToolBarGrip::ID_SETHELPSTRING,FXToolBarGrip::onCmdSetHelp),
78   FXMAPFUNC(SEL_COMMAND,FXToolBarGrip::ID_GETHELPSTRING,FXToolBarGrip::onCmdGetHelp),
79   FXMAPFUNC(SEL_COMMAND,FXToolBarGrip::ID_SETTIPSTRING,FXToolBarGrip::onCmdSetTip),
80   FXMAPFUNC(SEL_COMMAND,FXToolBarGrip::ID_GETTIPSTRING,FXToolBarGrip::onCmdGetTip),
81   };
82 
83 
84 // Object implementation
FXIMPLEMENT(FXToolBarGrip,FXDockHandler,FXToolBarGripMap,ARRAYNUMBER (FXToolBarGripMap))85 FXIMPLEMENT(FXToolBarGrip,FXDockHandler,FXToolBarGripMap,ARRAYNUMBER(FXToolBarGripMap))
86 
87 
88 // Deserialization
89 FXToolBarGrip::FXToolBarGrip(){
90   activeColor=0;
91   }
92 
93 
94 // Construct and init
FXToolBarGrip(FXComposite * p,FXObject * tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)95 FXToolBarGrip::FXToolBarGrip(FXComposite* p,FXObject* tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
96   FXDockHandler(p,tgt,sel,opts,x,y,w,h,pl,pr,pt,pb){
97   activeColor=FXRGB(0,0,255);
98   }
99 
100 
101 
102 // Get default width
getDefaultWidth()103 FXint FXToolBarGrip::getDefaultWidth(){
104   return padleft+padright+(border<<1)+((options&TOOLBARGRIP_DOUBLE)?GRIP_DOUBLE:GRIP_SINGLE);
105   }
106 
107 
108 // Get default height
getDefaultHeight()109 FXint FXToolBarGrip::getDefaultHeight(){
110   return padtop+padbottom+(border<<1)+((options&TOOLBARGRIP_DOUBLE)?GRIP_DOUBLE:GRIP_SINGLE);
111   }
112 
113 
114 // Change toolbar orientation
setDoubleBar(FXbool dbl)115 void FXToolBarGrip::setDoubleBar(FXbool dbl){
116   FXuint opts=dbl?(options|TOOLBARGRIP_DOUBLE):(options&~TOOLBARGRIP_DOUBLE);
117   if(opts!=options){
118     options=opts;
119     recalc();
120     }
121   }
122 
123 
124 // Return TRUE if toolbar grip is displayed as a double bar
isDoubleBar() const125 FXbool FXToolBarGrip::isDoubleBar() const {
126   return (options&TOOLBARGRIP_DOUBLE)!=0;
127   }
128 
129 
130 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)131 long FXToolBarGrip::onPaint(FXObject*,FXSelector,void* ptr){
132   FXEvent* event=static_cast<FXEvent*>(ptr);
133   FXDCWindow dc(this,event);
134   FXint xx,yy,ww,hh;
135   dc.setForeground(backColor);
136   dc.fillRectangle(border,border,width-(border<<1),height-(border<<1));
137   ww=width-padleft-padright-(border<<1);
138   hh=height-padtop-padbottom-(border<<1);
139   if(width>height){
140     xx=border+padleft;
141     if(options&TOOLBARGRIP_DOUBLE){     // =
142       yy=border+padtop+(hh-GRIP_DOUBLE)/2;
143       dc.setForeground(hiliteColor);
144       dc.fillRectangle(xx,yy,1,2);
145       dc.fillRectangle(xx,yy+4,1,2);
146       dc.fillRectangle(xx,yy,ww-1,1);
147       dc.fillRectangle(xx,yy+4,ww-1,1);
148       dc.setForeground(shadowColor);
149       dc.fillRectangle(xx+ww-1,yy,1,3);
150       dc.fillRectangle(xx+ww-1,yy+4,1,3);
151       dc.fillRectangle(xx,yy+2,ww-1,1);
152       dc.fillRectangle(xx,yy+6,ww-1,1);
153       if(flags&(FLAG_ACTIVE|FLAG_TRYDRAG|FLAG_DODRAG)){
154         dc.setForeground(activeColor);
155         dc.fillRectangle(xx+1,yy+1,ww-2,1);
156         dc.fillRectangle(xx+1,yy+5,ww-2,1);
157         }
158       }
159     else{                               // -
160       yy=border+padtop+(hh-GRIP_SINGLE)/2;
161       dc.setForeground(hiliteColor);
162       dc.fillRectangle(xx,yy,1,2);
163       dc.fillRectangle(xx,yy,ww-1,1);
164       dc.setForeground(shadowColor);
165       dc.fillRectangle(xx+ww-1,yy,1,3);
166       dc.fillRectangle(xx,yy+2,ww-1,1);
167       if(flags&(FLAG_ACTIVE|FLAG_TRYDRAG|FLAG_DODRAG)){
168         dc.setForeground(activeColor);
169         dc.fillRectangle(xx+1,yy+1,ww-2,1);
170         }
171       }
172     }
173   else{
174     yy=border+padtop;
175     if(options&TOOLBARGRIP_DOUBLE){     // ||
176       xx=border+padleft+(ww-GRIP_DOUBLE)/2;
177       dc.setForeground(hiliteColor);
178       dc.fillRectangle(xx,yy,2,1);
179       dc.fillRectangle(xx+4,yy,2,1);
180       dc.fillRectangle(xx,yy,1,hh-1);
181       dc.fillRectangle(xx+4,yy,1,hh-1);
182       dc.setForeground(shadowColor);
183       dc.fillRectangle(xx,yy+hh-1,3,1);
184       dc.fillRectangle(xx+4,yy+hh-1,3,1);
185       dc.fillRectangle(xx+2,yy,1,hh-1);
186       dc.fillRectangle(xx+6,yy,1,hh-1);
187       if(flags&(FLAG_ACTIVE|FLAG_TRYDRAG|FLAG_DODRAG)){
188         dc.setForeground(activeColor);
189         dc.fillRectangle(xx+1,yy+1,1,hh-2);
190         dc.fillRectangle(xx+5,yy+1,1,hh-2);
191         }
192       }
193     else{                               // |
194       xx=border+padleft+(ww-GRIP_SINGLE)/2;
195       dc.setForeground(hiliteColor);
196       dc.fillRectangle(xx,yy,2,1);
197       dc.fillRectangle(xx,yy,1,hh-1);
198       dc.setForeground(shadowColor);
199       dc.fillRectangle(xx,yy+hh-1,3,1);
200       dc.fillRectangle(xx+2,yy,1,hh-1);
201       if(flags&(FLAG_ACTIVE|FLAG_TRYDRAG|FLAG_DODRAG)){
202         dc.setForeground(activeColor);
203         dc.fillRectangle(xx+1,yy+1,1,hh-2);
204         }
205       }
206     }
207   drawFrame(dc,0,0,width,height);
208   return 1;
209   }
210 
211 
212 // Entered button
onEnter(FXObject * sender,FXSelector sel,void * ptr)213 long FXToolBarGrip::onEnter(FXObject* sender,FXSelector sel,void* ptr){
214   FXDockHandler::onEnter(sender,sel,ptr);
215   if(isEnabled()){ flags|=FLAG_ACTIVE; update(); }
216   return 1;
217   }
218 
219 
220 // Leave button
onLeave(FXObject * sender,FXSelector sel,void * ptr)221 long FXToolBarGrip::onLeave(FXObject* sender,FXSelector sel,void* ptr){
222   FXDockHandler::onLeave(sender,sel,ptr);
223   if(isEnabled()){ flags&=~FLAG_ACTIVE; update(); }
224   return 1;
225   }
226 
227 
228 
229 // Set active color
setActiveColor(FXColor clr)230 void FXToolBarGrip::setActiveColor(FXColor clr){
231   if(clr!=activeColor){
232     activeColor=clr;
233     update();
234     }
235   }
236 
237 
238 // Save data
save(FXStream & store) const239 void FXToolBarGrip::save(FXStream& store) const {
240   FXDockHandler::save(store);
241   store << activeColor;
242   }
243 
244 
245 // Load data
load(FXStream & store)246 void FXToolBarGrip::load(FXStream& store){
247   FXDockHandler::load(store);
248   store >> activeColor;
249   }
250 
251 
252 }
253