forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TQtClientGuard.cxx
329 lines (303 loc) · 9.74 KB
/
TQtClientGuard.cxx
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// @(#)root/qt:$Id$
// Author: Valeri Fine 21/01/2002
/*************************************************************************
* Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
* Copyright (C) 2002 by Valeri Fine. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include <assert.h>
#include "TQtClientGuard.h"
#include "TGQt.h"
#include <QPixmap>
#include <QBitmap>
////////////////////////////////////////////////////////////////////////////////
/// add the widget to list of the "guarded" widget
void TQtClientGuard::Add(QWidget *w)
{
fQClientGuard.prepend(w);
// fprintf(stderr," TQtClientGuard::Add %d %lp %p \n", TGQt::rootwid(w), TGQt::rootwid(w),w );
connect(w,SIGNAL(destroyed()),this,SLOT(Disconnect()));
}
////////////////////////////////////////////////////////////////////////////////
/// TQtClientWidget object factory
TQtClientWidget *TQtClientGuard::Create(QWidget* mother, const char* name, Qt::WFlags f)
{
TQtClientWidget *w = new TQtClientWidget(this,mother,name,f);
// w->setBackgroundMode(Qt::NoBackground);
Add(w);
return w;
}
////////////////////////////////////////////////////////////////////////////////
/// Delete and unregister the object
void TQtClientGuard::Delete(QWidget *w)
{
int found = -1;
#if QT_VERSION < 0x40000
if (w && ( (found = fQClientGuard.find(w))>=0))
#else
if (w && ( (found = fQClientGuard.indexOf(w))>=0) )
#endif
{
w->hide();
Disconnect(w,found);
//((TQtClientWidget *)w)->SetClosing();
//w->close(true);
w->deleteLater();
assert( w != QWidget::mouseGrabber() );
}
}
////////////////////////////////////////////////////////////////////////////////
/// Disconnect and unregister the object
/// fprintf(stderr, "TQtClientGuard::Disconnecting widget %p\n", w);
void TQtClientGuard::Disconnect(QWidget *w, int found)
{
if ( (found>=0) ||
#if QT_VERSION < 0x40000
( w && ( (found = fQClientGuard.find(w)) >=0 ) ) ) {
#else
( w && ((found = fQClientGuard.indexOf(w)) >=0 ) ) ) {
#endif
// ungrab the poiner just in case
QWidget *grabber = QWidget::mouseGrabber();
#if QT_VERSION < 0x40000
fQClientGuard.remove();
#else
fQClientGuard.removeAt(found);
#endif
disconnect(w,SIGNAL(destroyed()),this,SLOT(Disconnect()));
if (grabber == w && gQt->IsRegistered(w) )
gVirtualX->GrabPointer(TGQt::iwid(w), 0, 0, 0, kFALSE);
} else {
fDeadCounter++;
#ifdef QTDEBUG
printf(" %d Attempt to delete the dead widget %p\n",fDeadCounter, w);
#endif
}
}
////////////////////////////////////////////////////////////////////////////////
/// Disconnect all children of the registered widget
void TQtClientGuard::DisconnectChildren(TQtClientWidget *w)
{
if (w) {
#if QT_VERSION < 0x40000
const QObjectList *childList = w->children();
#else /* QT_VERSION */
const QObjectList &childList = w->children();
#endif /* QT_VERSION */
#if QT_VERSION < 0x40000
if (childList) {
QObjectListIterator next(*childList);
next.toLast();
#else /* QT_VERSION */
if (!childList.isEmpty()) {
QListIterator<QObject *> next(childList);
next.toBack();
#endif /* QT_VERSION */
QObject *widget = 0;
// while ( (widget = *next) )
#if QT_VERSION < 0x40000
for (widget=next.toLast(); (widget = next.current()); --next)
#else /* QT_VERSION */
while( next.hasPrevious() )
#endif /* QT_VERSION */
{
#if QT_VERSION >= 0x40000
widget = next.previous();
#endif /* QT_VERSION */
if (dynamic_cast<TQtClientWidget*>(widget)) {
DisconnectChildren((TQtClientWidget*)widget);
} else {
// assert(0);// Layout here
}
}
}
Disconnect(w);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Find the object by ROOT id
QWidget *TQtClientGuard::Find(Window_t id)
{
// fprintf(stderr," TQtClientGuard::Find %d %lp %p\n", id, id, TGQt::wid(id));
int found = -1;
#if QT_VERSION < 0x40000
found = fQClientGuard.find(TGQt::wid(id));
#else
found = fQClientGuard.indexOf(TGQt::wid(id));
#endif
return found >=0 ? fQClientGuard.at(found) : 0;
}
// protected slots:
////////////////////////////////////////////////////////////////////////////////
/// Disconnect object Qt slot
void TQtClientGuard::Disconnect()
{
QWidget *w = (QWidget *)sender();
// fprintf(stderr, "Disconnecting SLOT widget %p\n", w);
int found = -1;
#if QT_VERSION < 0x40000
found = fQClientGuard.find(w);
#else
found = fQClientGuard.indexOf(w);
#endif
if ( found >= 0 ) {
if ( w == QWidget::mouseGrabber())
fprintf(stderr," mouse is still grabbed by the dead wigdet !!!\n");
#if QT_VERSION < 0x40000
fQClientGuard.remove();
#else
fQClientGuard.removeAt(found);
#endif
disconnect(w,SIGNAL(destroyed()),this,SLOT(Disconnect()));
}
}
//______________________________________________________________________________
//
// TQtPixmapGuard
////////////////////////////////////////////////////////////////////////////////
/// add the widget to list of the "guarded" widget
void TQtPixmapGuard::Add(QPixmap *w)
{
fQClientGuard.prepend(w);
SetCurrent(0);
// fprintf(stderr," TQtPixmapGuard::Add %d %lp %p \n", TGQt::iwid(w), TGQt::iwid(w),w );
}
////////////////////////////////////////////////////////////////////////////////
QPixmap* TQtPixmapGuard::Create(int w, int h, const uchar *bits, bool isXbitmap)
{
QPixmap *p = new QBitmap(
QBitmap::fromData (QSize(w,h), bits, isXbitmap ? QImage::Format_MonoLSB : QImage::Format_Mono));
Add(p);
return p;
}
////////////////////////////////////////////////////////////////////////////////
QPixmap* TQtPixmapGuard::Create(int width, int height, int depth)
// , Optimization optimization)
{
if (depth) {/* fool the compiler with Qt4 */ }
QPixmap *w = new QPixmap(width,height); // ,optimization);
Add(w);
return w;
}
////////////////////////////////////////////////////////////////////////////////
QPixmap* TQtPixmapGuard::Create(const QString &fileName, const char *format)
//, ColorMode mode)
{
// QPixmap object factory
// Constructs a pixmap from the file fileName.
QPixmap *w = new QPixmap(fileName,format); //,mode);
Add(w);
return w;
}
////////////////////////////////////////////////////////////////////////////////
/// QPixmap object factory
/// Constructs a pixmap that is a copy of pixmap.
QPixmap* TQtPixmapGuard::Create(const QPixmap &src)
{
QPixmap *w = new QPixmap(src);
Add(w);
return w;
}
////////////////////////////////////////////////////////////////////////////////
/// QBitmap object factory
QBitmap* TQtPixmapGuard::Create(const QBitmap &src)
{
QBitmap *w = new QBitmap(src);
Add(w);
return w;
}
////////////////////////////////////////////////////////////////////////////////
/// QPixmap object factory
/// Constructs a pixmap from xpm
QPixmap* TQtPixmapGuard::Create (const char* xpm[])
{
QPixmap *w = new QPixmap(xpm);
Add(w);
return w;
}
////////////////////////////////////////////////////////////////////////////////
/// Delete and unregister QPixmap
void TQtPixmapGuard::Delete(QPixmap *w)
{
if (w)
{
Disconnect(w);
delete w;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Disconnect QPixmap
void TQtPixmapGuard::Disconnect(QPixmap *w, int found)
{
if (found <0) found =
#if QT_VERSION < 0x40000
fQClientGuard.find(w);
#else
fQClientGuard.indexOf(w);
#endif
if ( found >=0 ) {
#if QT_VERSION < 0x40000
fQClientGuard.remove();
#else
fQClientGuard.removeAt(found);
#endif
} else {
fDeadCounter++;
#ifdef QTDEBUG
printf(" %d Attempt to delete the dead pixmap %p\n",fDeadCounter, w);
#endif
}
SetCurrent(found);
}
////////////////////////////////////////////////////////////////////////////////
/// Find QPixmap by ROOT pixmap id
QPixmap *TQtPixmapGuard::Pixmap(Pixmap_t id, bool needBitmap)
{
(void)needBitmap;
QPixmap *thisPix = 0;
int found = -1;
if (id) {
#if QT_VERSION < 0x40000
found = fQClientGuard.find((QPixmap *)id);
assert( (thisPix = fQClientGuard.current()) && (!needBitmap || thisPix->isQBitmap()) ) ;
#else
found = fQClientGuard.indexOf((QPixmap *)id);
thisPix = found>=0 ? fQClientGuard[found] : 0;
assert( thisPix && (!needBitmap || thisPix->isQBitmap()) ) ;
#endif
(void)needBitmap; // used in asserts above.
}
SetCurrent(found);
return thisPix;
}
////////////////////////////////////////////////////////////////////////////////
/// return the current QPixmap object
QPixmap *TQtPixmapGuard::Find(Window_t /*id*/ )
{
// fprintf(stderr," TQtPixmapGuard::Find %d %lp %p index=%d\n", id, id, TGQt::wid(id),
// fQClientGuard.find(TGQt::wid(id));
#if QT_VERSION < 0x40000
return fQClientGuard.current();
#else
return fLastFound >=0 ? fQClientGuard[fLastFound] : 0;
#endif
}
// protected slots:
////////////////////////////////////////////////////////////////////////////////
/// Disconnect Qt slot
void TQtPixmapGuard::Disconnect()
{
QPixmap *w = (QPixmap *)sender();
int found = -1;
#if QT_VERSION < 0x40000
found = fQClientGuard.find(w);
if ( found >=0 ) fQClientGuard.remove();
#else
found = fQClientGuard.indexOf(w);
if ( found >=0 ) fQClientGuard.removeAt(found);
#endif
SetCurrent(found);
}