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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
/********************************************************************************
* *
* D o c k H a n d l e r W i d g e t *
* *
*********************************************************************************
* Copyright (C) 2005,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 "fxmath.h"
#include "fxkeys.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 "FXApp.h"
#include "FXDockHandler.h"
/*
Notes:
- On MS-Windows, this works just fine, without fanfare.
- On X11, some quaintness in the X-Server causes havoc if reparent()
is called on a window while it was grabbed.
- Not to be deterred, we implement here the following workaround:
1) We create a temporary dummy window, just 1x1 pixels in size, in the
upper left corner of the screen [yes, that was not a dead pixel
after all!].
2) We add this to the hash table, so now events from the "true" window
as well those from the dummy window are dispatched to the toolbar grip.
3) We temporarily replace the xid of the true window with the dummy one,
then invoke grab() to grab the mouse, then restore the original xid.
4) Now you can wave your mouse around and dock or undock toolbars.
5) When we're done, we replace the xid again with the dummy window,
call ungrab(), then restore the original xid again.
6) Then, delete the dummy window.
- The only downside of this method is that the win_x and win_y member
data in FXEvent is unreliable; fortunately, the standard toolbar docking
algorithms do not use these members.
- Of course, we'd rather not have to do all this; so don't hesitate
to inform us if you have a better way!
*/
using namespace FX;
/*******************************************************************************/
namespace FX {
// Map
FXDEFMAP(FXDockHandler) FXDockHandlerMap[]={
FXMAPFUNC(SEL_MOTION,0,FXDockHandler::onMotion),
FXMAPFUNC(SEL_LEFTBUTTONPRESS,0,FXDockHandler::onLeftBtnPress),
FXMAPFUNC(SEL_LEFTBUTTONRELEASE,0,FXDockHandler::onLeftBtnRelease),
FXMAPFUNC(SEL_KEYPRESS,0,FXDockHandler::onKeyPress),
FXMAPFUNC(SEL_KEYRELEASE,0,FXDockHandler::onKeyRelease),
FXMAPFUNC(SEL_QUERY_TIP,0,FXDockHandler::onQueryTip),
FXMAPFUNC(SEL_QUERY_HELP,0,FXDockHandler::onQueryHelp),
FXMAPFUNC(SEL_COMMAND,FXDockHandler::ID_SETHELPSTRING,FXDockHandler::onCmdSetHelp),
FXMAPFUNC(SEL_COMMAND,FXDockHandler::ID_GETHELPSTRING,FXDockHandler::onCmdGetHelp),
FXMAPFUNC(SEL_COMMAND,FXDockHandler::ID_SETTIPSTRING,FXDockHandler::onCmdSetTip),
FXMAPFUNC(SEL_COMMAND,FXDockHandler::ID_GETTIPSTRING,FXDockHandler::onCmdGetTip),
};
// Object implementation
FXIMPLEMENT_ABSTRACT(FXDockHandler,FXFrame,FXDockHandlerMap,ARRAYNUMBER(FXDockHandlerMap))
// Deserialization
FXDockHandler::FXDockHandler(){
flags|=FLAG_ENABLED|FLAG_SHOWN;
xxx=0;
}
// Construct and init
FXDockHandler::FXDockHandler(FXComposite* p,FXObject* tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):FXFrame(p,opts,x,y,w,h,pl,pr,pt,pb){
flags|=FLAG_SHOWN|FLAG_ENABLED;
dragCursor=getApp()->getDefaultCursor(DEF_MOVE_CURSOR);
target=tgt;
message=sel;
xxx=0;
}
// Can have focus
FXbool FXDockHandler::canFocus() const { return true; }
// Moved
long FXDockHandler::onMotion(FXObject*,FXSelector,void* ptr){
if(flags&FLAG_DODRAG){
handle(this,FXSEL(SEL_DRAGGED,0),ptr);
return 1;
}
if((flags&FLAG_TRYDRAG) && ((FXEvent*)ptr)->moved){
if(handle(this,FXSEL(SEL_BEGINDRAG,0),ptr)) flags|=FLAG_DODRAG;
flags&=~FLAG_TRYDRAG;
return 1;
}
return 0;
}
// Pressed LEFT button
long FXDockHandler::onLeftBtnPress(FXObject*,FXSelector,void* ptr){
flags&=~FLAG_TIP;
handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr);
if(isEnabled()){
flags=(flags&~(FLAG_UPDATE|FLAG_DODRAG))|FLAG_TRYDRAG;
#ifdef WIN32
grab();
#else
Display *display=(Display*)getApp()->getDisplay();
const unsigned long mask=CWBackPixmap|CWWinGravity|CWBitGravity|CWBorderPixel|CWOverrideRedirect|CWSaveUnder|CWEventMask|CWDontPropagate|CWColormap|CWCursor;
XSetWindowAttributes wattr;
FXID tempxid=xid;
wattr.background_pixmap=None;
wattr.background_pixel=0;
wattr.border_pixmap=None;
wattr.border_pixel=0;
wattr.bit_gravity=ForgetGravity;
wattr.win_gravity=NorthWestGravity;
wattr.backing_store=NotUseful;
wattr.backing_planes=0;
wattr.backing_pixel=0;
wattr.save_under=false;
wattr.event_mask=ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|FocusChangeMask|StructureNotifyMask|ExposureMask|PropertyChangeMask|EnterWindowMask|LeaveWindowMask;
wattr.do_not_propagate_mask=KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|ButtonMotionMask;
wattr.override_redirect=true;
wattr.colormap=DefaultColormap(display,DefaultScreen(display));
wattr.cursor=None;
xxx=XCreateWindow(display,RootWindow(display,DefaultScreen(display)),0,0,1,1,0,DefaultDepth(display,DefaultScreen(display)),InputOutput,DefaultVisual(display,DefaultScreen(display)),mask,&wattr);
getApp()->hash.insert((void*)xxx,this);
XMapWindow(display,xxx);
xid=xxx;
grab();
xid=tempxid;
#endif
update();
}
return 1;
}
// Released LEFT button
long FXDockHandler::onLeftBtnRelease(FXObject*,FXSelector,void* ptr){
if(isEnabled()){
FXuint flg=flags;
flags=(flags&~(FLAG_TRYDRAG|FLAG_DODRAG))|FLAG_UPDATE;
if(flg&(FLAG_DODRAG|FLAG_TRYDRAG)){
#ifdef WIN32
ungrab();
#else
Display *display=(Display*)getApp()->getDisplay();
FXID tempxid=xid;
xid=xxx;
ungrab();
xid=tempxid;
getApp()->hash.remove((void*)xxx);
XDestroyWindow(display,xxx);
xxx=0;
#endif
}
if(flg&FLAG_DODRAG){handle(this,FXSEL(SEL_ENDDRAG,0),ptr);}
update();
}
return 1;
}
// Key Press
long FXDockHandler::onKeyPress(FXObject*,FXSelector,void* ptr){
FXEvent* event=static_cast<FXEvent*>(ptr);
if(isEnabled()){
if(target && target->tryHandle(this,FXSEL(SEL_KEYPRESS,message),ptr)) return 1;
if(event->code==KEY_Control_L || event->code==KEY_Control_R){
if(flags&FLAG_DODRAG){handle(this,FXSEL(SEL_DRAGGED,0),ptr);}
return 1;
}
}
return 0;
}
// Key Release
long FXDockHandler::onKeyRelease(FXObject*,FXSelector,void* ptr){
FXEvent* event=static_cast<FXEvent*>(ptr);
if(isEnabled()){
if(target && target->tryHandle(this,FXSEL(SEL_KEYRELEASE,message),ptr)) return 1;
if(event->code==KEY_Control_L || event->code==KEY_Control_R){
if(flags&FLAG_DODRAG){handle(this,FXSEL(SEL_DRAGGED,0),ptr);}
return 1;
}
}
return 0;
}
// We were asked about tip text
long FXDockHandler::onQueryTip(FXObject* sender,FXSelector sel,void* ptr){
if(FXFrame::onQueryTip(sender,sel,ptr)) return 1;
if((flags&FLAG_TIP) && !tip.empty()){
sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&tip);
return 1;
}
return 0;
}
// We were asked about status text
long FXDockHandler::onQueryHelp(FXObject* sender,FXSelector sel,void* ptr){
if(FXFrame::onQueryHelp(sender,sel,ptr)) return 1;
if((flags&FLAG_HELP) && !help.empty()){
sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&help);
return 1;
}
return 0;
}
// Set tip using a message
long FXDockHandler::onCmdSetTip(FXObject*,FXSelector,void* ptr){
setTipText(*((FXString*)ptr));
return 1;
}
// Get tip using a message
long FXDockHandler::onCmdGetTip(FXObject*,FXSelector,void* ptr){
*((FXString*)ptr)=getTipText();
return 1;
}
// Set help using a message
long FXDockHandler::onCmdSetHelp(FXObject*,FXSelector,void* ptr){
setHelpText(*((FXString*)ptr));
return 1;
}
// Get help using a message
long FXDockHandler::onCmdGetHelp(FXObject*,FXSelector,void* ptr){
*((FXString*)ptr)=getHelpText();
return 1;
}
// Save data
void FXDockHandler::save(FXStream& store) const {
FXFrame::save(store);
store << tip;
store << help;
}
// Load data
void FXDockHandler::load(FXStream& store){
FXFrame::load(store);
store >> tip;
store >> help;
}
}
|