Added a primitive guess of the executable's language.
[kdbg.git] / DockWidget / dockmovemanager.cpp
blobe3b11fd381c69e994b966adb81632096605fcaed
1 /*
2 Modify from KTolBoxManager
3 novaprint@mtu-net.ru
4 Judin Max
5 **********************************/
7 /*
8 This file is part of the KDE libraries
9 Copyright (C) 1998 Sven Radej (radej@kde.org)
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
21 You should have received a copy of the GNU Library General Public License
22 along with this library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA.
27 #include <qcursor.h>
28 #include <qapplication.h>
29 #include <qwindowdefs.h>
30 #include <qwidget.h>
31 #include <qtimer.h>
32 #include <qrect.h>
34 #include "dockmovemanager.h"
36 DockMoveManager::DockMoveManager(QWidget *_widget) : QObject ()
38 XGCValues gv;
40 working=false;
41 noLast=true;
42 widget = _widget;
44 scr = qt_xscreen();
45 root = qt_xrootwin();
47 gv.function = GXxor;
48 gv.line_width = 0;
49 gv.foreground = WhitePixel(qt_xdisplay(), scr)^BlackPixel(qt_xdisplay(), scr);
50 gv.subwindow_mode = IncludeInferiors;
51 long mask = GCForeground | GCFunction | GCLineWidth | GCSubwindowMode;
52 rootgc = XCreateGC(qt_xdisplay(), qt_xrootwin(), mask, &gv);
54 timer = new QTimer(this);
57 DockMoveManager::~DockMoveManager()
59 stop();
62 void DockMoveManager::doMove (bool hot_static, bool _dynamic, bool dontmove)
64 if (working) return;
66 Window wroot, wchild;
67 int trash;
69 working=true;
71 QRect rr = QRect( widget->mapToGlobal(QPoint(0,0)), widget->size() );
72 QPoint p(rr.topLeft());
74 offX = QCursor::pos().x() - p.x();
75 offY = QCursor::pos().y() - p.y();
77 xp = p.x();
78 yp = p.y();
79 w = rr.width();
80 h = rr.height();
82 orig_x = p.x();
83 orig_y = p.y();
84 orig_w = w;
85 orig_h = h;
87 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &wroot, &wchild,
88 &sx, &sy, &trash, &trash, &active_button);
90 rx = sx;
91 ry = sy;
93 xp=sx-offX;
94 yp=sy-offY;
96 QApplication::setOverrideCursor(QCursor(sizeAllCursor));
97 connect (timer, SIGNAL(timeout()), this, SLOT (doMoveInternal()));
99 drawRectangle(xp, yp, w, h);
101 pauseMove = false;
102 timer->start(0);
105 void DockMoveManager::doMoveInternal()
107 if ( pauseMove ) return;
109 Window wroot, wchild;
110 int trash;
111 unsigned int buttons;
113 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &wroot, &wchild,
114 &rx, &ry, &trash, &trash, &buttons );
116 if (buttons != active_button)
118 stop();
119 return;
122 if (rx == sx && ry == sy) return;
124 sx=rx;
125 sy=ry;
127 xp=rx-offX;
128 yp=ry-offY;
130 deleteLastRectangle();
131 drawRectangle(xp, yp, w, h);
133 XFlush(qt_xdisplay());
134 XSync(qt_xdisplay(), False);
137 void DockMoveManager::stop ()
139 if (!working) return;
141 timer->stop();
142 disconnect (timer, SIGNAL(timeout()));
143 QApplication::restoreOverrideCursor();
145 deleteLastRectangle();
146 XFlush(qt_xdisplay());
147 QApplication::restoreOverrideCursor();
149 QPoint p(xp, yp);
150 if (widget->parent() != 0) p=widget->parentWidget()->mapFromGlobal(p);
152 working = false;
155 void DockMoveManager::setGeometry (int _x, int _y, int _w, int _h)
157 if (!working) return;
158 xp=_x;
159 yp=_y;
160 w=_w;
161 h=_h;
162 deleteLastRectangle();
163 drawRectangle( _x, _y, _w, _h);
166 void DockMoveManager::drawRectangle(int _x, int _y, int _w, int _h)
168 ox = _x;
169 oy = _y;
170 ow = _w;
171 oh = _h;
173 XDrawRectangle(qt_xdisplay(), root, rootgc, _x, _y, _w, _h);
174 if (_w > 2)
175 _w -= 2;
176 if (_h > 2)
177 _h -= 2;
178 XDrawRectangle(qt_xdisplay(), root, rootgc, _x+1, _y+1, _w, _h);
179 if (_w > 2)
180 _w -= 2;
181 if (_h > 2)
182 _h -= 2;
183 XDrawRectangle(qt_xdisplay(), root, rootgc, _x+2, _y+2, _w, _h);
185 noLast = false;
188 void DockMoveManager::deleteLastRectangle()
190 if (noLast) return;
192 XDrawRectangle(qt_xdisplay(), root, rootgc, ox, oy, ow, oh);
193 if (ow > 2)
194 ow -= 2;
195 if (oh > 2)
196 oh -= 2;
197 XDrawRectangle(qt_xdisplay(), root, rootgc, ox+1, oy+1, ow, oh);
198 if (ow > 2)
199 ow -= 2;
200 if (oh > 2)
201 oh -= 2;
202 XDrawRectangle(qt_xdisplay(), root, rootgc, ox+2, oy+2, ow, oh);
204 noLast = true;