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