00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <assert.h>
00013
00014 #include "TQtClientGuard.h"
00015 #include "TGQt.h"
00016 #include <QPixmap>
00017 #include <QBitmap>
00018
00019
00020 void TQtClientGuard::Add(QWidget *w)
00021 {
00022
00023 fQClientGuard.prepend(w);
00024
00025 connect(w,SIGNAL(destroyed()),this,SLOT(Disconnect()));
00026 }
00027
00028 TQtClientWidget *TQtClientGuard::Create(QWidget* mother, const char* name, Qt::WFlags f)
00029 {
00030
00031 TQtClientWidget *w = new TQtClientWidget(this,mother,name,f);
00032
00033 Add(w);
00034 return w;
00035 }
00036
00037 void TQtClientGuard::Delete(QWidget *w)
00038 {
00039
00040 int found = -1;
00041 #if QT_VERSION < 0x40000
00042 if (w && ( (found = fQClientGuard.find(w))>=0))
00043 #else
00044 if (w && ( (found = fQClientGuard.indexOf(w))>=0) )
00045 #endif
00046 {
00047 w->hide();
00048 Disconnect(w,found);
00049
00050
00051 w->deleteLater();
00052 assert( w != QWidget::mouseGrabber() );
00053 }
00054 }
00055
00056 void TQtClientGuard::Disconnect(QWidget *w, int found)
00057 {
00058
00059
00060 if ( (found>=0) ||
00061 #if QT_VERSION < 0x40000
00062 ( w && ( (found = fQClientGuard.find(w)) >=0 ) ) ) {
00063 #else
00064 ( w && ((found = fQClientGuard.indexOf(w)) >=0 ) ) ) {
00065 #endif
00066
00067 QWidget *grabber = QWidget::mouseGrabber();
00068 #if QT_VERSION < 0x40000
00069 fQClientGuard.remove();
00070 #else
00071 fQClientGuard.removeAt(found);
00072 #endif
00073 disconnect(w,SIGNAL(destroyed()),this,SLOT(Disconnect()));
00074 if (grabber == w && gQt->IsRegistered(w) )
00075 gVirtualX->GrabPointer(TGQt::iwid(w), 0, 0, 0, kFALSE);
00076 } else {
00077 fDeadCounter++;
00078 #ifdef QTDEBUG
00079 printf(" %d Attempt to delete the dead widget %p\n",fDeadCounter, w);
00080 #endif
00081 }
00082 }
00083
00084 void TQtClientGuard::DisconnectChildren(TQtClientWidget *w)
00085 {
00086
00087 if (w) {
00088 #if QT_VERSION < 0x40000
00089 const QObjectList *childList = w->children();
00090 #else
00091 const QObjectList &childList = w->children();
00092 #endif
00093 int nChild = 0;
00094 #if QT_VERSION < 0x40000
00095 if (childList) {
00096 nChild = childList->count();
00097 QObjectListIterator next(*childList);
00098 next.toLast();
00099 #else
00100 if (!childList.isEmpty()) {
00101 nChild = childList.count();
00102 QListIterator<QObject *> next(childList);
00103 next.toBack();
00104 #endif
00105 QObject *widget = 0;
00106
00107 #if QT_VERSION < 0x40000
00108 for (widget=next.toLast(); (widget = next.current()); --next)
00109 #else
00110 while( next.hasPrevious() )
00111 #endif
00112 {
00113 #if QT_VERSION >= 0x40000
00114 widget = next.previous();
00115 #endif
00116 if (dynamic_cast<TQtClientWidget*>(widget)) {
00117 DisconnectChildren((TQtClientWidget*)widget);
00118 } else {
00119
00120 }
00121 }
00122 }
00123 Disconnect(w);
00124 }
00125 }
00126
00127
00128 QWidget *TQtClientGuard::Find(Window_t id)
00129 {
00130
00131
00132
00133 int found = -1;
00134 #if QT_VERSION < 0x40000
00135 found = fQClientGuard.find(TGQt::wid(id));
00136 #else
00137 found = fQClientGuard.indexOf(TGQt::wid(id));
00138 #endif
00139 return found >=0 ? fQClientGuard.at(found) : 0;
00140 }
00141
00142
00143 void TQtClientGuard::Disconnect()
00144 {
00145
00146 QWidget *w = (QWidget *)sender();
00147
00148 int found = -1;
00149 #if QT_VERSION < 0x40000
00150 found = fQClientGuard.find(w);
00151 #else
00152 found = fQClientGuard.indexOf(w);
00153 #endif
00154 if ( found >= 0 ) {
00155 if ( w == QWidget::mouseGrabber())
00156 fprintf(stderr," mouse is still grabbed by the dead wigdet !!!\n");
00157 #if QT_VERSION < 0x40000
00158 fQClientGuard.remove();
00159 #else
00160 fQClientGuard.removeAt(found);
00161 #endif
00162 disconnect(w,SIGNAL(destroyed()),this,SLOT(Disconnect()));
00163 }
00164 }
00165
00166
00167
00168
00169
00170 void TQtPixmapGuard::Add(QPixmap *w)
00171 {
00172
00173 fQClientGuard.prepend(w);
00174 SetCurrent(0);
00175
00176 }
00177
00178 QPixmap* TQtPixmapGuard::Create(int w, int h, const uchar *bits, bool isXbitmap)
00179 {
00180 QPixmap *p = new QBitmap(
00181 QBitmap::fromData (QSize(w,h), bits, isXbitmap ? QImage::Format_MonoLSB : QImage::Format_Mono));
00182 Add(p);
00183 return p;
00184 }
00185
00186 QPixmap* TQtPixmapGuard::Create(int width, int height, int depth)
00187
00188 {
00189 if (depth) { }
00190 QPixmap *w = new QPixmap(width,height);
00191 Add(w);
00192 return w;
00193 }
00194
00195 QPixmap* TQtPixmapGuard::Create(const QString &fileName, const char *format)
00196
00197 {
00198
00199
00200
00201 QPixmap *w = new QPixmap(fileName,format);
00202 Add(w);
00203 return w;
00204 }
00205
00206 QPixmap* TQtPixmapGuard::Create(const QPixmap &src)
00207 {
00208
00209
00210 QPixmap *w = new QPixmap(src);
00211 Add(w);
00212 return w;
00213 }
00214
00215
00216 QBitmap* TQtPixmapGuard::Create(const QBitmap &src)
00217 {
00218
00219
00220 QBitmap *w = new QBitmap(src);
00221 Add(w);
00222 return w;
00223 }
00224
00225 QPixmap* TQtPixmapGuard::Create (const char* xpm[])
00226 {
00227
00228
00229 QPixmap *w = new QPixmap(xpm);
00230 Add(w);
00231 return w;
00232 }
00233
00234 void TQtPixmapGuard::Delete(QPixmap *w)
00235 {
00236
00237 if (w)
00238 {
00239 Disconnect(w);
00240 delete w;
00241 }
00242 }
00243
00244 void TQtPixmapGuard::Disconnect(QPixmap *w, int found)
00245 {
00246
00247
00248 if (found <0) found =
00249 #if QT_VERSION < 0x40000
00250 fQClientGuard.find(w);
00251 #else
00252 fQClientGuard.indexOf(w);
00253 #endif
00254 if ( found >=0 ) {
00255 #if QT_VERSION < 0x40000
00256 fQClientGuard.remove();
00257 #else
00258 fQClientGuard.removeAt(found);
00259 #endif
00260 } else {
00261 fDeadCounter++;
00262 #ifdef QTDEBUG
00263 printf(" %d Attempt to delete the dead pixmap %p\n",fDeadCounter, w);
00264 #endif
00265 }
00266 SetCurrent(found);
00267 }
00268
00269 QPixmap *TQtPixmapGuard::Pixmap(Pixmap_t id, bool needBitmap)
00270 {
00271
00272 QPixmap *thisPix = 0;
00273 int found = -1;
00274 if (id) {
00275 #if QT_VERSION < 0x40000
00276 found = fQClientGuard.find((QPixmap *)id);
00277 assert( (thisPix = fQClientGuard.current()) && (!needBitmap || thisPix->isQBitmap()) ) ;
00278 #else
00279 found = fQClientGuard.indexOf((QPixmap *)id);
00280 thisPix = found>=0 ? fQClientGuard[found] : 0;
00281 assert( thisPix && (!needBitmap || thisPix->isQBitmap()) ) ;
00282 #endif
00283 }
00284 SetCurrent(found);
00285 return thisPix;
00286 }
00287
00288 QPixmap *TQtPixmapGuard::Find(Window_t )
00289 {
00290
00291
00292
00293
00294 #if QT_VERSION < 0x40000
00295 return fQClientGuard.current();
00296 #else
00297 return fLastFound >=0 ? fQClientGuard[fLastFound] : 0;
00298 #endif
00299 }
00300
00301
00302 void TQtPixmapGuard::Disconnect()
00303 {
00304
00305 QPixmap *w = (QPixmap *)sender();
00306 int found = -1;
00307 #if QT_VERSION < 0x40000
00308 found = fQClientGuard.find(w);
00309 if ( found >=0 ) fQClientGuard.remove();
00310 #else
00311 found = fQClientGuard.indexOf(w);
00312 if ( found >=0 ) fQClientGuard.removeAt(found);
00313 #endif
00314 SetCurrent(found);
00315 }