GQtGUI.cxx

Go to the documentation of this file.
00001 // @(#)root/qt:$Id: GQtGUI.cxx 36344 2010-10-13 17:21:32Z brun $
00002 // Author: Valeri Fine   23/01/2003
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * Copyright (C) 2003 by Valeri Fine.                                    *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 #include <assert.h>
00014 #include "TGQt.h"
00015 #include "TQUserEvent.h"
00016 #include "TQtClientFilter.h"
00017 #include "TQtWidget.h"
00018 #include "TQtClientWidget.h"
00019 #include "TQtEventQueue.h"
00020 #include "TQtEventQueue.h"
00021 #include "TGWindow.h"
00022 
00023 
00024 #include "TROOT.h"
00025 #include "TEnv.h"
00026 
00027 #include <qapplication.h>
00028 #include <qcursor.h>
00029 #include <qpixmap.h>
00030 #include <qbitmap.h>
00031 #include <qregion.h>
00032 #include <qclipboard.h>
00033 
00034 #if QT_VERSION < 0x40000
00035 #  include <qpaintdevicemetrics.h>
00036 #  include <qobjectlist.h>
00037 #  include <qcstring.h>
00038 #else /* QT_VERSION */
00039 #  include <QByteArray>
00040 #  include <QBoxLayout>
00041 #  include <QKeyEvent>
00042 #  include <QEvent>
00043 #  include <QList>
00044 #  include <QVBoxLayout>
00045 #  include <QPolygon>
00046 #  include <QDesktopWidget>
00047 #  include <QDebug>
00048 #  include <QPalette>
00049 #  include <QColormap>
00050 #  include <QIcon>
00051 #  include <QSize>
00052 #  include <QImage>
00053 #  include <QLine>
00054 #  include <QVector>
00055 #ifdef R__QTX11
00056 #  include <QX11Info>
00057 #endif
00058 #endif /* QT_VERSION */
00059 
00060 #include <qfontmetrics.h>
00061 #include <qpoint.h>
00062 #include <qpainter.h>
00063 
00064 #include <qlayout.h>
00065 #include <qdatetime.h>
00066 #include <qtextcodec.h>
00067 
00068 #include "TMath.h"
00069 #include "TQtBrush.h"
00070 
00071 #include "TSystem.h"
00072 #include "KeySymbols.h"
00073 
00074 #ifdef R__QTWIN32
00075 #  include "TWinNTSystem.h"
00076 #else
00077 # ifdef  R__QTX11
00078 #  include <X11/Xlib.h>
00079 # endif
00080 #endif
00081 
00082 
00083 #include "TError.h"
00084 
00085 #include "TGFrame.h"
00086 #include "TQtClientWidget.h"
00087 
00088 static Window_t fgDefaultRootWindows = Window_t(-1);
00089 // static const unsigned int kDefault=2;
00090 
00091 static TQtClientWidget* cwid(Window_t id) { return ((TQtClientWidget*)TGQt::wid(id)); }
00092 //static int GetRValue(ULong_t color){return (int)color;}
00093 //static int GetGValue(ULong_t color){return (int)color;}
00094 //static int GetBValue(ULong_t color){return (int)color;}
00095 //______________________________________________________________________________
00096 //
00097 //     class QtGContext
00098 //
00099 class QtGContext : public QWidget {
00100    friend class TGQt;
00101    friend class TQtPainter;
00102    QtGContext(const QtGContext & /*src*/);
00103 protected:
00104    Mask_t       fMask;       // mask the active values
00105 #if QT_VERSION < 0x40000
00106    Qt::RasterOp fROp;        // raster operation
00107 #else /* QT_VERSION */
00108    QPainter::CompositionMode  fROp;   // composition mode
00109 #endif /* QT_VERSION */
00110    QPen         fPen;        // line styles
00111    QBrush       fBrush;      // fill styles
00112    QPixmap     *fTilePixmap; // tile pixmap for tiling operations
00113    QPixmap     *fStipple;    // tile pixmap for tiling operations
00114    QPoint       fTileRect;   // The origin for the tile operation
00115    QPoint       fClipOrigin; // The origin for clipping
00116    QBitmap     *fClipMask;   // bitmap clipping; other calls for rects
00117    QRegion      fClipRegion; // Clip region
00118    QFont       *fFont;       // A copy of the font pointer
00119 public:
00120    enum EContext { kROp  =1, kPen,     kBrush,     kTilePixmap
00121                  , kStipple, kTileRect,kClipOrigin,kClipMask,kClipRegion
00122                  , kFont
00123                  , kAllFields
00124                  };
00125    QtGContext() : QWidget(0) ,fMask(0),fROp(),  fPen(), fBrush(Qt::SolidPattern), fTilePixmap(0),fStipple(0),fClipMask(0),fFont(0) {}
00126    QtGContext(const GCValues_t &gval) : QWidget(0) ,fMask(0),fROp(), fPen(), fBrush(),fTilePixmap(0),fStipple(0),fClipMask(0),fFont(0){Copy(gval);}
00127    void              Copy(const QtGContext &dst,Mask_t rootMask = 0xff);
00128    const QtGContext &Copy(const GCValues_t &gval);
00129    void              DumpMask() const;
00130    bool              HasValid(EContext bit) const { return TESTBIT (fMask , bit); }
00131    Mask_t            Mask() const { return fMask; }
00132    void              SetBackground(ULong_t background);
00133    void              SetMask(Mask_t rootMask){ fMask = rootMask;}
00134    void              SetForeground(ULong_t foreground);
00135    GContext_t        gc() const { return (GContext_t)this; }
00136    operator          GContext_t() const { return gc(); }
00137    const QtGContext &operator=(const GCValues_t &gval){ return Copy(gval);}
00138    QColor QtColor(ULong_t pixel) {return gQt->QtColor(pixel);}
00139 
00140 };
00141 
00142 //______________________________________________________________________________
00143 static QtGContext   &qtcontext(GContext_t context) { return *(QtGContext *)context;}
00144 //______________________________________________________________________________
00145 QColor TGQt::QtColor(ULong_t pixel)
00146 {
00147    // Return  the QColor object by platform depended "pixel" value
00148    // (see: TGQt::AllocColor  and  QColormap::pixel )
00149    // Add the special treatment for the pixel "0"
00150    static QColor black("black");
00151 #ifndef OLD
00152    return pixel  ? QColormap::instance().colorAt(pixel) : black;
00153 #else
00154    if (pixel == 0) {
00155       QColormap cmap = QColormap::instance();
00156       pixel = cmap.pixel(black);
00157    }
00158    COLORMAP::iterator colorIterator;
00159    //   QColor *color = fColorMap[pixel];
00160    if ((colorIterator = fColorMap.find(pixel)) != fColorMap.end()) {
00161       QColor *c =  (*colorIterator).second;
00162       return *c;
00163    } else {
00164       // this is a new color (red x green x blue)
00165       // this is a new color (blue x green x red)
00166       
00167       ColorStruct_t newColor;
00168 #ifdef R__WIN32
00169       newColor.fRed  =  (pixel & 255);
00170       pixel = pixel >> 8;
00171       newColor.fGreen = (pixel & 255);
00172       pixel = pixel >> 8;
00173       newColor.fBlue   = (pixel & 255);
00174 #else      
00175       newColor.fBlue  =  (pixel & 255);
00176       pixel = pixel >> 8;
00177       newColor.fGreen = (pixel & 255);
00178       pixel = pixel >> 8;
00179       newColor.fRed   = (pixel & 255);
00180 #endif
00181       Colormap_t cmap=0; // fake map
00182       gVirtualX->AllocColor(cmap, newColor);
00183       return QtColor(newColor.fPixel);
00184    }
00185 #endif
00186 }
00187 //______________________________________________________________________________
00188 #ifdef CopyQTContext
00189 #define __saveCopyQTContext__  CopyQTContext
00190 #undef  CopyQTContext
00191 #endif
00192 
00193 #define CopyQTContext(member)                                                 \
00194    if (dst.HasValid(_NAME2_(k,member))&&TESTBIT(rootMask, _NAME2_(k,member))) {   \
00195       SETBIT( fMask, _NAME2_(k,member));                                      \
00196       _NAME2_(f,member) = dst._NAME2_(f,member);                              \
00197    }
00198 //______________________________________________________________________________
00199 #if QT_VERSION < 0x40000
00200 void DumpROp(Qt::RasterOp op) {
00201 #else /* QT_VERSION */
00202 void DumpROp(QPainter::CompositionMode op) {
00203 #endif /* QT_VERSION */
00204    // Dump QT Raster Operation Code
00205    QString s;
00206    switch (op) {
00207 #if QT_VERSION < 0x40000
00208         case Qt::ClearROP:  s = "Qt::ClearROP -> dst = 0 ";               break;
00209         case Qt::AndROP:    s = "Qt::AndROP dst = src AND dst ";          break;
00210         case Qt::AndNotROP: s = "Qt::AndNotROP dst = src AND (NOT dst) "; break;
00211         case Qt::CopyROP:   s = "Qt::CopyROP dst = src ";                 break;
00212         case Qt::NotAndROP: s = "Qt::NotAndROP dst = (NOT src) AND dst";  break;
00213         case Qt::NorROP:    s = "Qt::NorROP dst = NOT (src OR dst) ";     break;
00214         case Qt::NopROP:    s = "Qt::NopROP dst = dst ";                  break;
00215         case Qt::XorROP:    s = "Qt::XorROP dst = src XOR dst ";          break;
00216         case Qt::OrROP:     s = "Qt::OrROP dst = src OR dst ";            break;
00217         case Qt::NotXorROP: s = "Qt::NotXorROP dst = (NOT src) XOR dst  // Qt::NotOrROP);  // !!! This is not a GDK_EQUIV; !!!";  break;
00218         case Qt::NotROP:    s = "Qt::NotROP dst = NOT dst ";              break;
00219         case Qt::OrNotROP:  s = "Qt::OrNotROP dst = src OR (NOT dst) ";   break;
00220         case Qt::NotCopyROP:s = "Qt::NotCopyROP dst = NOT src ";          break;
00221         case Qt::NotOrROP:  s = "Qt::NotOrROP dst = (NOT src) OR dst ";   break;
00222         case Qt::NandROP:   s = "Qt::NandROP dst = NOT (src AND dst)";    break;
00223         case Qt::SetROP:    s = "Qt::SetROP dst = 1";                     break;
00224         default: s = "UNKNOWN";                                           break;
00225 #else /* QT_VERSION */
00226         case QPainter::CompositionMode_Clear:     s = "Qt::ClearROP   dst = 0 ";                break; // ClearROP
00227   //    case QPainter::CompositionMode_AndROP:    s = "Qt::AndROP     dst = src AND dst ";      break;
00228   //    case QPainter::CompositionMode_AndNotROP: s = "Qt::AndNotROP  dst = src AND (NOT dst) ";break;
00229         case QPainter::CompositionMode_Source:    s = "Qt::CopyROP    dst = src ";              break; // CopyROP
00230   //    case QPainter::CompositionMode_NotAndROP: s = "Qt::NotAndROP  dst = (NOT src) AND dst"; break;
00231   //    case QPainter::CompositionMode_NorROP:    s = "Qt::NorROP     dst = NOT (src OR dst) "; break;
00232         case QPainter::CompositionMode_Destination:s= "Qt::NopROP     dst = dst ";              break; // NopROP
00233         case QPainter::CompositionMode_Xor:       s = "Qt::XorROP     dst = src XOR dst ";      break; // Qt::XorROP
00234   //    case QPainter::CompositionMode_OrROP:     s = "Qt::OrROP      dst = src OR dst ";       break;
00235   //    case QPainter::CompositionMode_NotXorROP: s = "Qt::NotXorROP  dst = (NOT src) XOR dst  // Qt::NotOrROP);  // !!! This is not a GDK_EQUIV; !!!";  break;
00236   //    case QPainter::CompositionMode_NotROP:    s = "Qt::NotROP     dst = NOT dst ";          break;
00237   //    case QPainter::CompositionMode_OrNotROP:  s = "Qt::OrNotROP   dst = src OR (NOT dst) "; break;
00238   //    case QPainter::CompositionMode_NotCopyROP:s = "Qt::NotCopyROP dst = NOT src ";          break;
00239   //    case QPainter::CompositionMode_NotOrROP:  s = "Qt::NotOrROP   dst = (NOT src) OR dst "; break;
00240   //    case QPainter::CompositionMode_NandROP:   s = "Qt::NandROP    dst = NOT (src AND dst)"; break;
00241   //    case QPainter::CompositionMode_SetROP:    s = "Qt::SetROP     dst = 1";                 break;
00242         default: s = "UNKNOWN";                                                                 break;
00243 #endif /* QT_VERSION */
00244    }
00245    qDebug() << " Dump QT Composition mode Code: "
00246             <<op << " \""<< s << "\"";
00247 }
00248 
00249 //______________________________________________________________________________
00250 #ifdef DumpGCMask
00251 #define __saveDumpGCMask__
00252 #undef DumpGCMask
00253 #endif
00254 
00255 #define DumpGCMask(member)                                                    \
00256  if (HasValid(_NAME2_(k,member))) {                                           \
00257    fprintf(stderr," mask bit : ");                                            \
00258    fprintf(stderr, _QUOTE_(_NAME2_(k,member)));                               \
00259    fprintf(stderr," is defined\n"); }
00260 inline void QtGContext::DumpMask() const
00261 {
00262    fprintf(stderr,"  Dump QtGContext mask %x \n", fMask);
00263    DumpROp(fROp);
00264    DumpGCMask(ROp);       DumpGCMask(Pen);     DumpGCMask(Brush);     DumpGCMask(TilePixmap);
00265    DumpGCMask(Stipple);   DumpGCMask(TileRect);DumpGCMask(ClipOrigin);DumpGCMask(ClipMask);
00266    DumpGCMask(ClipRegion);DumpGCMask(Font);
00267 }
00268 #ifdef __saveDumpGCMask__
00269 #undef DumpGCMask
00270 #define DumpGCMask __saveDumpGCMask__
00271 #undef __saveDumpGCMask__
00272 #endif
00273 
00274 //______________________________________________________________________________
00275 inline void QtGContext::Copy(const QtGContext &dst, Mask_t rootMask)
00276 {
00277    // fprintf(stderr,"&QtGContext::Copy(const QtGContext &dst, Mask_t mask=%x)\n",mask);
00278    CopyQTContext(ROp);
00279    CopyQTContext(Pen);
00280    CopyQTContext(Brush);
00281    CopyQTContext(TilePixmap);
00282    CopyQTContext(Stipple);
00283    CopyQTContext(TileRect);
00284    CopyQTContext(ClipOrigin);
00285    CopyQTContext(ClipMask);
00286    CopyQTContext(ClipRegion);
00287    CopyQTContext(Font);
00288 
00289 }
00290 #ifdef __saveCopyQTContext__
00291 #undef  CopyQTContext
00292 #define CopyQTContext __saveCopyQTContext__
00293 #undef __saveCopyQTContext__
00294 #endif
00295 //______________________________________________________________________________
00296 const QtGContext  &QtGContext::Copy(const GCValues_t &gval)
00297 {
00298    if (!&gval) return *this;
00299    // Fill this object from the "GCValues_t" structure
00300    // map GCValues_t to QtGContext
00301    Mask_t rootMask = gval.fMask;
00302    // fprintf(stderr,"&QtGContext::Copy(const GCValues_t &gval) this=%p rootMask=%x function=%x\n",this, rootMask,kGCFunction);
00303    if ((rootMask & kGCFunction)) {
00304       // fprintf(stderr," QtGContext::Copy this=%p, kGCFunction,%x, %d\n",this,  rootMask, gval.fFunction);
00305       SETBIT(fMask, kROp);
00306       switch (gval.fFunction)
00307       {
00308 #if QT_VERSION < 0x40000
00309       case kGXclear:
00310          fROp = Qt::ClearROP;  // dst = 0
00311          break;
00312       case kGXand:
00313          fROp = Qt::AndROP;    // dst = src AND dst
00314          break;
00315       case kGXandReverse:
00316          fROp = Qt::AndNotROP; // dst = src AND (NOT dst) //
00317          break;
00318       case kGXcopy:
00319          fROp = Qt::CopyROP;   // dst = src
00320          break;
00321       case kGXandInverted:
00322          fROp = Qt::NotAndROP; // dst = (NOT src) AND dst
00323          break;
00324       case kGXnor:
00325          fROp = Qt::NorROP;   //  dst = NOT (src OR dst)
00326          break;
00327       case kGXnoop:
00328          fROp = Qt::NopROP;    // dst = dst
00329          break;
00330       case kGXxor:
00331          fROp = Qt::XorROP;     // dst = src XOR dst
00332          break;
00333       case kGXor:
00334          fROp = Qt::OrROP;     // dst = src OR dst
00335          break;
00336       case kGXequiv:
00337          fROp = Qt::NotXorROP; // dst = (NOT src) XOR dst  // Qt::NotOrROP);  // !!! This is not a GDK_EQUIV; !!!
00338          break;
00339       case kGXinvert:
00340          fROp = Qt::NotROP;    // dst = NOT dst
00341          break;
00342       case kGXorReverse:
00343          fROp = Qt::OrNotROP;  // dst = src OR (NOT dst)
00344          break;
00345       case kGXcopyInverted:
00346          fROp = Qt::NotCopyROP; // dst = NOT src
00347          break;
00348       case kGXorInverted:
00349          fROp = Qt::NotOrROP;   // dst = (NOT src) OR dst
00350          break;
00351       case kGXnand:
00352          fROp = Qt::NandROP;   // dst = NOT (src AND dst)
00353          break;
00354       case kGXset:
00355          fROp = Qt::SetROP;     // dst = 1
00356          break;
00357 #else
00358       case 0: // to make VC++ compiler happy
00359 #endif /* not QT_VERSION */
00360       default:
00361 #if QT_VERSION < 0x40000
00362               fROp = Qt::CopyROP;
00363               break;
00364 #else /* QT_VERSION */
00365         fROp = QPainter::CompositionMode_Source; //Qt::CopyROP;
00366         break;
00367 #endif /* QT_VERSION */
00368       }
00369       // DumpROp(fROp);
00370 //      fprintf(stderr," kGCFunction: fROp = %x\n",fROp );
00371    } else {
00372         // Fons said this must be like this. 4/07/2003 Valeri Fine
00373         SETBIT(fMask, kROp);
00374 #if QT_VERSION < 0x40000
00375         fROp = Qt::CopyROP;
00376 #else /* QT_VERSION */
00377         fROp = QPainter::CompositionMode_Source; // Qt::CopyROP;
00378 #endif /* QT_VERSION */
00379    };
00380 
00381    if (rootMask & kGCSubwindowMode) {
00382 #if 0
00383       SETBIT(fMask,kXXX
00384       if (gval.fSubwindowMode == kIncludeInferiors)
00385          fSubwindow_mode = GDK_INCLUDE_INFERIORS;
00386       else
00387          fSubwindow_mode = GDK_CLIP_BY_CHILDREN
00388 #endif
00389    }
00390    if ((rootMask & kGCForeground)) {
00391       // xmask |= GDK_GC_FOREGROUND;
00392       // QColor paletteBackgroundColor - the background color of the widget
00393        SetForeground(gval.fForeground);
00394          // fprintf(stderr," kGCForeground %s \root.exen", (const char*)QtColor(gval.fForeground).name());
00395    }
00396    if ((rootMask & kGCBackground)) {
00397        SetBackground(gval.fBackground);
00398         // fprintf(stderr," kGCBackgroun %s \n", (const char*)QtColor(gval.fBackground).name());
00399    }
00400    if ((rootMask & kGCLineWidth)) {
00401       SETBIT(fMask,kPen);
00402       fPen.setWidth(gval.fLineWidth);
00403    }
00404    if ((rootMask & kGCLineStyle)) {
00405       SETBIT(fMask,kPen);
00406       Qt::PenStyle nextStyle = Qt::NoPen;
00407       switch (gval.fLineStyle)
00408       {
00409         case kLineSolid:      nextStyle = Qt::SolidLine;   break;
00410         case kLineOnOffDash:  nextStyle = Qt::DashLine;    break;
00411         case kLineDoubleDash: nextStyle = Qt::DashDotLine; break;
00412       };
00413       fPen.setStyle(nextStyle);
00414    }
00415    if ((rootMask & kGCCapStyle)) {
00416       SETBIT(fMask,kPen);
00417       Qt::PenCapStyle nextStyle = Qt::FlatCap;
00418       switch (gval.fCapStyle)
00419       {
00420          case kCapNotLast:    nextStyle = Qt::FlatCap;   break;
00421          case kCapButt:       nextStyle = Qt::FlatCap;   break;
00422          case kCapRound:      nextStyle = Qt::RoundCap;  break;
00423          case kCapProjecting: nextStyle = Qt::SquareCap; break;  // no idea what this does mean
00424       };
00425       fPen.setCapStyle(nextStyle);
00426    }
00427    if ((rootMask & kGCJoinStyle)) {
00428       SETBIT(fMask,kPen);
00429       Qt::PenJoinStyle nextStyle = Qt::MiterJoin;
00430       switch (gval.fJoinStyle)
00431       {
00432          case kJoinMiter: nextStyle = Qt::MiterJoin; break;
00433          case kJoinBevel: nextStyle = Qt::BevelJoin; break;
00434          case kJoinRound: nextStyle = Qt::RoundJoin; break;
00435       };
00436       fPen.setJoinStyle(nextStyle);
00437    }
00438    if ((rootMask & kGCFillStyle)) {
00439       SETBIT(fMask,kBrush);
00440       Qt::BrushStyle nextStyle = Qt::SolidPattern;
00441       switch (gval.fFillStyle)
00442       {
00443          case kFillTiled:          nextStyle = Qt::Dense1Pattern; break;
00444          case kFillStippled:       nextStyle = Qt::Dense6Pattern; break;
00445          case kFillOpaqueStippled: nextStyle = Qt::Dense7Pattern; break;
00446          case kFillSolid: default: nextStyle = Qt::SolidPattern;  break;
00447       };
00448       fBrush.setStyle(nextStyle);
00449    }
00450    if ((rootMask & kGCTile)) {
00451 #ifdef QTDEBUG
00452       fprintf(stderr," kGCTile,%x, %p\n",rootMask,(QPixmap *) gval.fTile);
00453 #endif
00454       if ( gval.fTile  != 0xFFFFFFFF ) {
00455          SETBIT(fMask,kTilePixmap);
00456          fTilePixmap = (QPixmap *) gval.fTile;
00457       }
00458    }
00459    if ((rootMask & kGCStipple)) {
00460       // fprintf(stderr," kGCStipple,%x, %p\n",rootMask,(QPixmap *) gval.fStipple);
00461       SETBIT(fMask,kStipple);
00462       fStipple = (QPixmap *) gval.fStipple;
00463       // setPaletteBackgroundPixmap (*fStipple);
00464       fBrush.setTexture(*fStipple);
00465       SETBIT(fMask, kROp);
00466       fROp = QPainter::CompositionMode_Xor; // Qt::XorROP;
00467    }
00468    if ((rootMask & kGCTileStipXOrigin)) {
00469       SETBIT(fMask,kTileRect);
00470       fTileRect.setX(gval.fTsXOrigin);
00471    }
00472    if ((rootMask & kGCTileStipYOrigin)) {
00473       SETBIT(fMask,kTileRect);
00474       fTileRect.setY(gval.fTsYOrigin);
00475    }
00476    if ((rootMask & kGCFont)) {
00477       SETBIT(fMask,kFont);
00478       setFont(*(QFont *) gval.fFont);
00479       fFont = (QFont *) gval.fFont;
00480       // fprintf(stderr,"kGCFont font=0x%p\n", fFont);
00481    }
00482    if ((rootMask & kGCGraphicsExposures)) {
00483 #if 0
00484       xmask |= GDK_GC_EXPOSURES;
00485       fGraphics_exposures = gval.fGraphicsExposures;
00486 #endif
00487    }
00488    if ((rootMask & kGCClipXOrigin)) {
00489       // fprintf(stderr," kGCClipXOrigin,%x, %p\n",rootMask,(QPixmap *) gval.fClipXOrigin);
00490       SETBIT(fMask,kClipOrigin);
00491       fClipOrigin.setX(gval.fClipXOrigin);
00492    }
00493    if ((rootMask & kGCClipYOrigin)) {
00494       SETBIT(fMask,kClipOrigin);
00495       fClipOrigin.setY(gval.fClipYOrigin);
00496    }
00497    if ((rootMask & kGCClipMask)) {
00498       SETBIT(fMask,kClipMask);
00499       fClipMask = (QBitmap *) gval.fClipMask;
00500    }
00501    return *this;
00502 }
00503 //______________________________________________________________________________
00504 void   QtGContext::SetBackground(ULong_t background)
00505 {
00506     // reset the context background color
00507     SETBIT(fMask,kBrush);
00508     QColor bg = QtColor(background);
00509 #if QT_VERSION < 0x40000    
00510     setPaletteBackgroundColor(bg);
00511     setEraseColor(bg);
00512 #else    
00513     QPalette pp=palette();
00514     pp.setColor(QPalette::Window,bg);
00515     setPalette(pp);
00516 #endif 
00517 }
00518 //______________________________________________________________________________
00519 void   QtGContext::SetForeground(ULong_t foreground)
00520 {
00521    // xmask |= GDK_GC_FOREGROUND;
00522    // QColor paletteBackgroundColor - the background color of the widget
00523    SETBIT(fMask,kBrush);
00524    SETBIT(fMask,kPen);
00525    QColor bg = QtColor(foreground);
00526    QPalette pp = palette();
00527    pp.setColor(QPalette::WindowText, bg);
00528    setPalette(pp);
00529    fBrush.setColor(bg);
00530    fPen.setColor(bg); 
00531 }
00532 //______________________________________________________________________________
00533 //
00534 //     class TQtPainter
00535 //
00536 class TQtPainter : public QPainter {
00537 public:
00538 #if QT_VERSION < 0x40000
00539    TQtPainter(const QPaintDevice * pd,const QtGContext &rootContext, Mask_t rootMask=0xff,bool unclipped = FALSE):
00540       QPainter(pd,unclipped){
00541 #else /* QT_VERSION */
00542    TQtPainter(QPaintDevice * pd,const QtGContext &rootContext, Mask_t rootMask=0xff,bool unclipped = FALSE):
00543       QPainter(pd){
00544          setClipping(!unclipped);
00545 #endif /* QT_VERSION */
00546          if (rootMask){}
00547          if (rootContext.HasValid(QtGContext::kROp)) {
00548 #if QT_VERSION < 0x40000
00549             setRasterOp (rootContext.fROp);
00550 #else /* QT_VERSION */
00551 //           if (device()->devType() !=  QInternal::Widget ) 
00552            if (pd->devType() ==  QInternal::Image ) 
00553                setCompositionMode(rootContext.fROp);
00554 #endif /* QT_VERSION */
00555          }
00556          if (rootContext.HasValid(QtGContext::kPen)) {
00557             setPen(rootContext.fPen);
00558          }
00559          if (rootContext.HasValid(QtGContext::kBrush)) {
00560             setBrush(rootContext.fBrush);
00561          }
00562          if (rootContext.HasValid(QtGContext::kTilePixmap)) {
00563             setBrush(rootContext.fBrush);
00564 #ifdef QTDEBUG
00565             fprintf(stderr," NO special painter Qt implementation for TilePixmap option yet\n");
00566 #endif
00567          }
00568          if (rootContext.HasValid(QtGContext::kStipple)) {
00569             setBrush(rootContext.fBrush);
00570          }
00571          if (rootContext.HasValid(QtGContext::kTileRect)) {
00572             setBrush(rootContext.fBrush);
00573 #ifdef QTDEBUG
00574             fprintf(stderr," NO special painter  Qt implementation for TileRect option yet\n");
00575 #endif
00576          }
00577          if (rootContext.HasValid(QtGContext::kClipOrigin)) {
00578             // fprintf(stderr," NO special painter  Qt implementation for ClipOrigin option yet\n");
00579             // setClipRect ( fClipOrigin , int w, int h, CoordinateMode m = CoordDevice )
00580          }
00581          if (rootContext.HasValid(QtGContext::kClipMask)) {
00582             // fprintf(stderr," NO special painter  Qt implementation for ClipMask option yet\n");
00583          }
00584          if (rootContext.HasValid(QtGContext::kClipRegion)) {
00585             setClipRegion (rootContext.fClipRegion);
00586          }
00587       }
00588 };
00589 //______________________________________________________________________________
00590 //
00591 //     class TQtGrabPointerFilter
00592 //
00593 class TQtGrabPointerFilter : public QObject {
00594 protected:
00595    bool eventFilter( QObject *o, QEvent *e );
00596 };
00597 //______________________________________________________________________________
00598 bool TQtGrabPointerFilter::eventFilter( QObject *, QEvent *e)
00599 {
00600    // if ( e->type() == QEvent::KeyPress )
00601    {
00602       // special processing for key press
00603       QKeyEvent *k = (QKeyEvent *)e;
00604       qDebug( "Ate key press %d", k->key() );
00605       return TRUE; // eat event
00606    }
00607    // standard event processing
00608    return FALSE;
00609 }
00610 //______________________________________________________________________________
00611 class TXlfd {
00612    // Naive parsing and comparision of XLDF font descriptors
00613    public:
00614          QString fFontFoundry;
00615          QString fFontFamily;
00616          Int_t   fIsFontBold;
00617          Int_t   fIsFontItalic;
00618          Int_t   fPointSize;
00619          Int_t   fPixelSize;
00620    //______________________________________________________________________________
00621    TXlfd (const char* fontName)    { Init(QString(fontName)); }
00622 
00623    //______________________________________________________________________________
00624    TXlfd (const char* fontFamily, Int_t isFontBold, Int_t isFontItalic=-1)
00625    { Init(QString(fontFamily), isFontBold, isFontItalic);       }
00626 
00627    //______________________________________________________________________________
00628    TXlfd (const QString &fontFamily, Int_t isFontBold, Int_t isFontItalic)
00629    { Init(fontFamily, isFontBold, isFontItalic);                }
00630 
00631       //______________________________________________________________________________
00632    TXlfd (const QString &fontName) { Init(fontName);          }
00633 
00634    //______________________________________________________________________________
00635    inline void Init(const QString &fontName) {
00636       // Undefine all values;
00637       fIsFontBold  = fIsFontItalic = fPointSize = fPixelSize = -1;
00638       fFontFoundry = "*";
00639       fFontFamily  = fontName.section('-',2,2);
00640 
00641       QString fontWeight  = fontName.section('-',3,3);
00642       if (fontWeight != "*") 
00643          fIsFontBold = fontWeight.startsWith("bold") ? 1 : 0;
00644 
00645       QString fontSlant = fontName.section('-',4,4);
00646       if (fontSlant != "*" ) 
00647          fIsFontItalic = ((fontSlant[0] == 'i') || (fontSlant[0] == 'o')) ? 1 : 0;
00648       
00649       bool ok=true;
00650       QString fontPointSize = fontName.section('-',8,8);
00651       if (fontPointSize != "*") 
00652         fPointSize = fontPointSize.toInt(&ok);
00653       if (!ok) fPointSize = -1;
00654 
00655       QString fontPixelSize = fontName.section('-',7,7);
00656       if (fontPixelSize != "*") 
00657         fPixelSize = fontPixelSize .toInt(&ok);
00658       if (!ok) fPixelSize = -1;
00659    }
00660     //______________________________________________________________________________
00661     inline void Init(const QString &fontFamily, Int_t isFontBold
00662                    ,Int_t isFontItalic=-1, Int_t pointSize=-1, Int_t pixelSize=-1)
00663     {
00664        fFontFoundry = "*";
00665        fFontFamily  = fontFamily;
00666        fIsFontBold  = isFontBold;  fIsFontItalic = isFontItalic;
00667        fPointSize   = pointSize;   fPixelSize    = pixelSize;
00668        // ROOT doesn't want to see the point size.
00669        // To make it happy let calculate it
00670        fPixelSize = SetPointSize(pointSize);
00671        if (fPixelSize == -1) fPixelSize = pixelSize;
00672    }
00673    //______________________________________________________________________________
00674    inline Int_t SetPointSize(Int_t pointSize)
00675    {
00676      // Set the point size and return the pixel size of the font
00677        Int_t pixelSize = -1;
00678        fPointSize = pointSize;
00679        if (fPointSize > 0) {
00680           QFont sizeFont( fFontFamily, fPointSize, QFont::Normal, FALSE );
00681           pixelSize = sizeFont.pixelSize();
00682        }
00683        return pixelSize;
00684    }
00685    //______________________________________________________________________________
00686    inline bool operator==(const TXlfd &xlfd) const {
00687       return    ( (fFontFamily  == "*") || (xlfd.fFontFamily  == "*") || ( fFontFamily   == xlfd.fFontFamily)   )
00688              && ( (fFontFoundry == "*") || (xlfd.fFontFoundry == "*") || ( fFontFoundry  == xlfd.fFontFoundry)  )
00689              && ( (fIsFontBold  == -1 ) || (xlfd.fIsFontBold  == -1 ) || ( fIsFontBold   == xlfd.fIsFontBold)  )
00690              && ( (fIsFontItalic== -1 ) || (xlfd.fIsFontItalic== -1 ) || ( fIsFontItalic == xlfd.fIsFontItalic))
00691              && ( (fPointSize   == -1 ) || (xlfd.fPointSize   == -1 ) || ( fPointSize    == xlfd.fPointSize)   )
00692              && ( (fPixelSize   == -1 ) || (xlfd.fPixelSize   == -1 ) || ( fPixelSize    == xlfd.fPixelSize)   );
00693    }
00694    //______________________________________________________________________________
00695    inline bool operator!=(const TXlfd  &xlfd) const { return !operator==(xlfd); }
00696    //______________________________________________________________________________
00697    inline QString ToString() const 
00698    {
00699       QString xLDF = "-";
00700       xLDF += fFontFoundry + "-";  // text name of font creator
00701       xLDF += fFontFamily  + "-";  // name of the font. 
00702                                    // Related fonts generally have the same base names; 
00703                                    // i.e. helvetica, helvetica narrow , etc.
00704       QString weight_name = "*";   // usually one of [light|medium|demibold|bold] but other types may exist
00705       if (fIsFontBold > -1) 
00706          weight_name = fIsFontBold ? "bold" : "medium";
00707       xLDF += weight_name  + "-";
00708       
00709       QString slant_name = "*";   // one of [r|i|o]. i and o are used similarly, AFAIK
00710       if (fIsFontItalic  > -1) 
00711          slant_name = fIsFontItalic ? "i" : "r";
00712       xLDF += slant_name  + "-";
00713       
00714       // SETWIDTH_NAME    - [normal|condensed|narrow|double wide] 
00715       // ADD_STYLE_NAME   - not a classification field, used only for additional differentiation 
00716       xLDF += "*-*-";  // we do not crae (yet) about SETWIDTH and ADD_STYLE
00717       
00718       QString pixelsize = "*";   // 0 = scalable font; integer typicially height of bounding box  
00719       if (fPixelSize   > -1) 
00720          pixelsize  = QString::number(fPixelSize);
00721       xLDF += pixelsize  + "-";
00722 
00723       QString pointsize = "*";   // 0 = scalable font; integer typicially height of bounding box  
00724       if (fPointSize   > -1) 
00725          pointsize  = QString::number(fPointSize);
00726       xLDF += pointsize  + "-";
00727 
00728       // RESOLUTION_X - horizontal dots per inch 
00729       // RESOLUTION_Y - vertical dots per inch 
00730       // SPACING      - [p|m|c] p = proportional, m = monospaced, c = charcell. Charcell is 
00731       //                 a special case of monospaced where no glyphs have pixels outside 
00732       //                 the character cell; i.e. there is no kerning (no negative metrics). 
00733       // AVERAGE_WIDTH  - unweighted arithmetic mean of absolute value of width of each glyph 
00734       //                  in tenths of pixels
00735       
00736       xLDF += "*-*-*-*-";  // we do not create (yet) about  RESOLUTION_X RESOLUTION_Y  SPACING  AVERAGE_WIDTH
00737 
00738       // CHARSET_REGISTRY and CHARSET_ENCODING 
00739       //                         the chararterset used to encode the font; ISO8859-1 for Latin 1 fonts 
00740       xLDF += "ISO8859-1";
00741       return xLDF;
00742    }
00743 };
00744 
00745 //______________________________________________________________________________
00746 void  TGQt::SetOpacity(Int_t) { }
00747 //______________________________________________________________________________
00748 Window_t TGQt::GetWindowID(Int_t id) {
00749    // Create a "client" wrapper for the "canvas" widget to make Fons happy
00750    QPaintDevice *widDev = iwid(id);
00751    TQtWidget *canvasWidget = dynamic_cast<TQtWidget *>(iwid(id));
00752    if (widDev && !canvasWidget) {
00753       // The workaround for V.Onuchine ASImage - extremely error prone and dangerous
00754       // MUST be fixed later
00755      return rootwid(widDev);
00756    }
00757    assert(canvasWidget);
00758    TQtClientWidget  *client = 0;
00759    // Only one wrapper per "Canvas Qt Widget" is allowed
00760    if (! (client = (TQtClientWidget  *)canvasWidget->GetRootID() )  ) {
00761       //   QWidget *canvasWidget = (QWidget *)wid(id);
00762       QWidget *parent  = canvasWidget->parentWidget();
00763       client  = (TQtClientWidget  *)wid(CreateWindow(rootwid(parent)
00764          ,0,0,canvasWidget->width(),canvasWidget->height()
00765          ,0,0,0,0,0,0));
00766       // reparent the canvas
00767       canvasWidget->setParent(client);
00768       QBoxLayout * l = new QVBoxLayout( client );
00769       l->addWidget( canvasWidget );
00770       l->setContentsMargins(0,0,0,0);
00771       canvasWidget->SetRootID(client);
00772       client->SetCanvasWidget(canvasWidget);
00773       canvasWidget->setMouseTracking(kFALSE);
00774    }
00775    return rootwid(client);
00776 }
00777 //______________________________________________________________________________
00778 Window_t  TGQt::GetDefaultRootWindow() const
00779 {
00780    return kDefault;
00781 }
00782 //______________________________________________________________________________
00783 void TGQt::GetWindowAttributes(Window_t id, WindowAttributes_t &attr)
00784 {
00785    // Get window attributes and return filled in attributes structure.
00786    if (id == kNone) return;
00787    const QWidget &thisWindow = *wid(id);
00788  //  const QWidget &thisWindow = *(QWidget *)(TGQt::iwid(id));
00789    assert(&thisWindow);
00790    memset(&attr,0,sizeof(WindowAttributes_t));
00791    attr.fX        = thisWindow.x();
00792    attr.fY        = thisWindow.y();
00793    attr.fWidth    = thisWindow.width ();
00794    attr.fHeight   = thisWindow.height ();
00795    attr.fBorderWidth =  (thisWindow.frameGeometry().width() - thisWindow.width())/2;
00796    attr.fClass    = kInputOutput;
00797    attr.fRoot     = Window_t(thisWindow.topLevelWidget () );
00798 #ifdef R__QTX11
00799    const QX11Info &info =  thisWindow.x11Info();
00800    attr.fVisual   = info.visual(); // = gdk_window_get_visual((GdkWindow *) id);
00801 #else
00802    attr.fVisual   = 0; // = gdk_window_get_visual((GdkWindow *) id);
00803 #endif
00804    // QPaintDeviceMetrics pdm(&thisWindow);
00805    attr.fDepth    = QPixmap::defaultDepth();
00806    attr.fColormap = 0; // (Colormap_t)&thisWindow.palette ();
00807    if (!thisWindow.isHidden()) {
00808       attr.fMapState = thisWindow.isVisible() ? kIsViewable : kIsUnviewable;
00809    } else {
00810       attr.fMapState = kIsUnmapped;
00811    }
00812    attr.fBackingStore     = kNotUseful;
00813    attr.fSaveUnder        = kFALSE;
00814    attr.fMapInstalled     = kTRUE;
00815    attr.fOverrideRedirect = kFALSE;   // boolean value for override-redirect
00816    attr.fScreen   = QApplication::desktop()->screen() ;
00817 
00818 
00819    //fprintf(stderr, "GetWindowAttributes: %s: w=%d h=%d\n"
00820    //      ,(const char *)thisWindow.name()
00821    //      ,attr.fWidth ,attr.fHeight);
00822    attr.fYourEventMask = 0;
00823    // I have no idea what these bits mean
00824 
00825    attr.fBitGravity = 0;           // one of bit gravity values
00826    attr.fWinGravity = 0;           // one of the window gravity values
00827    attr.fAllEventMasks = 0;        // set of events all people have interest in
00828    attr.fDoNotPropagateMask = 0;   // set of events that should not propagate
00829 }
00830 //______________________________________________________________________________
00831 Bool_t TGQt::ParseColor(Colormap_t /*cmap*/, const char *cname, ColorStruct_t &color)
00832 {
00833    // Parse string cname containing color name, like "green" or "#00FF00".
00834    // It returns a filled in ColorStruct_t. Returns kFALSE in case parsing
00835    // failed, kTRUE in case of success. On success, the ColorStruct_t
00836    // fRed, fGreen and fBlue fields are all filled in and the mask is set
00837    // for all three colors, but fPixel is not set.
00838 
00839    // Set ColorStruct_t structure to default. Let system think we could
00840    // parse color.
00841    color.fPixel = 0;
00842    color.fRed   = 0;
00843    color.fGreen = 0;
00844    color.fBlue  = 0;
00845    color.fMask  = kDoRed | kDoGreen | kDoBlue;
00846 
00847    QColor thisColor(cname);
00848    if (thisColor.isValid() ) {
00849       QColormap cmap = QColormap::instance();
00850       color.fPixel = cmap.pixel(thisColor);
00851       color.fRed   = thisColor.red();
00852       color.fGreen = thisColor.green();
00853       color.fBlue  = thisColor.blue();
00854    }
00855 
00856    return thisColor.isValid();
00857 }
00858 
00859 //______________________________________________________________________________
00860 Bool_t TGQt::AllocColor(Colormap_t /*cmap*/, ColorStruct_t &color)
00861 {
00862    // Find and allocate a color cell according to the color values specified
00863    // in the ColorStruct_t. If no cell could be allocated it returns kFALSE,
00864    // otherwise kTRUE.
00865 
00866    // Set pixel value. Let system think we could allocate color.
00867 
00868    // Fons thinks they must be 65535  (see TColor::RGB2Pixel and TColor::RGB2Pixel)
00869    int cFactor=1;
00870    if (color.fRed>256 || color.fGreen>256 || color.fBlue>256 ){
00871       cFactor = 257;
00872    }
00873    QColor *thisColor = new QColor(
00874           (color.fRed   >> (cFactor > 1? 8:0))  & 255
00875          ,(color.fGreen >> (cFactor > 1? 8:0))  & 255     // /cFactor
00876          ,(color.fBlue  >> (cFactor > 1? 8:0))  & 255);   // /cFactor);
00877    QColormap cmap = QColormap::instance();
00878    color.fPixel = cmap.pixel(*thisColor);
00879 //   color.fPixel = (ULong_t)new QColor(color.fRed/257,color.fGreen,color.fBlue);
00880    // Add the color to the cash
00881 #ifdef OLD
00882    fColorMap[color.fPixel] = thisColor;
00883 #endif
00884    return kTRUE;
00885 }
00886 //______________________________________________________________________________
00887 void TGQt::QueryColor(Colormap_t /*cmap*/, ColorStruct_t &color)
00888 {
00889    // Fill in the primary color components for a specific pixel value.
00890    // On input fPixel  the pointer to the QColor object should be set
00891    // on  return the fRed, fGreen and fBlue components will be set.
00892    // Thsi method should not be called (vf 16/01/2003) at all.
00893    // Set color components to default.
00894 
00895    // fprintf(stderr,"QueryColor(Colormap_t cmap, ColorStruct_t &color)\n");
00896    QColor c  = QtColor(color.fPixel);
00897    // Fons thinks they must be 65535  (see TColor::RGB2Pixel and TColor::RGB2Pixel)
00898    color.fRed   = c.red()  <<8;
00899    color.fGreen = c.green()<<8;
00900    color.fBlue  = c.blue() <<8;
00901 }
00902 //______________________________________________________________________________
00903 void TGQt::NextEvent(Event_t &event)
00904 {
00905    // Copies first pending event from event queue to Event_t structure
00906    // and removes event from queue. Not all of the event fields are valid
00907    // for each event type, except fType and fWindow.
00908 
00909    // Map the accumulated Qt events to the ROOT one to process:
00910    qApp->processEvents ();
00911    if (qApp->hasPendingEvents ())  QCoreApplication::sendPostedEvents();
00912    fQtEventHasBeenProcessed = 1;
00913 
00914    memset(&event,0,sizeof(Event_t));
00915    event.fType   = kOtherEvent;
00916 #ifndef R__QTGUITHREAD
00917    if (!fQClientFilterBuffer)
00918       fQClientFilterBuffer = fQClientFilter->Queue();
00919    // qApp->processEvents ();
00920 #endif
00921 //--
00922 
00923    //   if (qApp->hasPendingEvents())  qApp->processOneEvent ();
00924    //   qApp->processEvents (5000);
00925    if (fQClientFilterBuffer) {
00926       const Event_t *ev = fQClientFilterBuffer->dequeue ();
00927       if (ev) {
00928          // There is a danger of artifacts at this point.
00929          // For example the mouse pointer had left some screen area but
00930          // event keeps reporting it is still there
00931          event = *ev; delete ev;
00932          if (gDebug > 3) fprintf(stderr," TGQt::NextEvent event type=%d win=%p\n", event.fType,(void *)event.fWindow);
00933       }
00934    }
00935 }
00936 //______________________________________________________________________________
00937 void TGQt::GetPasteBuffer(Window_t /*id*/, Atom_t /*atom*/, TString &text, Int_t &nchar,
00938                            Bool_t del)
00939 {
00940    // Get contents of paste buffer atom into string. If del is true delete
00941    // the paste buffer afterwards.
00942    // Get paste buffer. By default always empty.
00943 
00944    text = "";
00945    nchar = 0;
00946    QClipboard *cb = QApplication::clipboard();
00947    QClipboard::Mode mode =
00948       cb->supportsSelection() ? QClipboard::Selection :QClipboard::Clipboard;
00949    text = cb->text(mode).toStdString().c_str();
00950    nchar = text.Length();
00951    if (del) cb->clear(mode);
00952 }
00953 
00954 // ---- Methods used for GUI -----
00955 //______________________________________________________________________________
00956 void         TGQt::MapWindow(Window_t id)
00957 {
00958    // Map window on screen.
00959    if (id == kNone || wid(fgDefaultRootWindows) == wid(id) || id == kDefault ) return;
00960 
00961    // QWidget *nextWg = 0;
00962    QWidget *wg = wid(id);
00963    if ( wg ) {
00964       if  ( wg->isTopLevel () ){ 
00965          wg->showNormal();
00966       } else wg->show();
00967       // wg->update();
00968    }
00969 }
00970 //______________________________________________________________________________
00971 void         TGQt::MapSubwindows(Window_t id)
00972 {
00973    // Map sub (unhide) windows.
00974    // The XMapSubwindows function maps all subwindows for a specified window
00975    // in top-to-bottom stacking order.
00976    // In other words this method does reverese the Z-order of the child widgets
00977 
00978    if (id == kNone || id == kDefault) return;
00979 //   return;
00980    const QObjectList &childList = wid(id)->children();
00981    int nSubWindows = 0;
00982    int nChild = 0;
00983    if (!childList.isEmpty () ) {
00984       nChild = childList.count();
00985       QListIterator<QObject *> next(childList);
00986       QObject *widget = 0;
00987       int childCounter = 0; // to debug;
00988       // while ( (widget = *next) )
00989       Bool_t updateUnable;
00990       if ( (updateUnable = wid(id)->updatesEnabled()) && nChild >0 )
00991             wid(id)->setUpdatesEnabled(FALSE);
00992       next.toBack();
00993       while (next.hasPrevious())
00994       {
00995          widget = next.previous();
00996          childCounter++;
00997          if (widget->isWidgetType ())
00998          {
00999             ((QWidget *)widget)->show();
01000             nSubWindows++;
01001          } else {
01002             // It is "QVBoxLayout" instantiated by TGQt::GetWindowID method. it is Ok.
01003             // fprintf(stderr," *****  TGQt::MapSubwindow the object %d is NOT a widget !!! %p %p %s \n"
01004             // , childCounter, id, widget, (const char *)widget->name(),(const char *)widget->className());
01005          }
01006       }
01007       if (updateUnable  && nChild >0 )
01008            wid(id)->setUpdatesEnabled(TRUE);
01009    }
01010 }
01011 //______________________________________________________________________________
01012 void         TGQt::MapRaised(Window_t id)
01013 {
01014    // Map window on screen and put on top of all windows.
01015    //
01016    //   Here we have to mimic the XMapRaised X11 function
01017    //   The XMapRaised function essentially is similar to XMapWindow in that it
01018    //   maps the window and all of its subwindows that have had map requests.
01019    //   However, it also raises the specified window to the top of the stack.
01020 
01021    if (id == kNone || id == kDefault) return;
01022 #ifndef OLDQT25042003
01023    // fprintf(stderr, "   TGQt::MapRaised id = %p \n", id);
01024    QWidget *wg = wid(id);
01025    Bool_t updateUnable;
01026    if ( (updateUnable = wg->updatesEnabled()) )
01027             wg->setUpdatesEnabled(FALSE);
01028    RaiseWindow(id);
01029    MapWindow(id);
01030    do {
01031 ////      wg->show();
01032       wg->setHidden (false);
01033       wg = wg->parentWidget();
01034    }  while ( wg && (!wg->isVisible()) );
01035    if (updateUnable)
01036        wid(id)->setUpdatesEnabled(TRUE);
01037 
01038    if (wid(id)->isTopLevel()) {
01039       // fprintf(stderr, "   TGQt::MapRaised top level id = %p \n", id);
01040       // wid(id)->update();
01041    }
01042 #else
01043 #if 0
01044      QWidget *wg = winid(id);
01045      wg->setHidden(false);
01046      wg->raise();
01047      wg->show();
01048 #ifdef R__QTWIN32
01049    // raising the window under MS Windows needs some extra effort.
01050    HWND h = wg->winId();
01051    SetWindowPos(h,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
01052    SetWindowPos(h,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE );
01053 #endif
01054    wg->showNormal();
01055    MapSubwindows(id);
01056 
01057 #else
01058    // Put the top window on the top top of desktop
01059    // fprintf(stderr, "\n  -1- TGQt::MapRaised id = %p vis=%d\n", id, wid(id)->isVisible());
01060    MapWindow(id);
01061    // fprintf(stderr, "  -2- TGQt::MapRaised id = %p vis=%d \n", id, wid(id)->isVisible());
01062    QWidget *wg = wid(id);
01063    if ( wg->isTopLevel() )  {
01064       // wg->setHidden(false);
01065 #ifdef R__QTWIN32
01066       // raising the window under MS Windows needs some extra effort.
01067       HWND h = wg->winId();
01068       SetWindowPos(h,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
01069       SetWindowPos(h,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE );
01070 #endif
01071       wg->showNormal();
01072    } else {
01073       do {
01074          wg->raise();
01075          // fprintf(stderr, "  -%d- TGQt::MapRaised visible = %d x=%d, y=%d w=%d; counter = %d \n", ii++, wg->isVisible(),wg->x(),wg->y(),wg->width(),fileCounter);
01076       } while ( (! wg->isVisible() )  && (wg = wg->parentWidget()) );
01077    }
01078 #endif
01079 #endif
01080    // wg->showNormal();
01081 }
01082 //______________________________________________________________________________
01083 void         TGQt::UnmapWindow(Window_t id)
01084 {
01085    // Unmap window from screen.
01086 
01087    if (id == kNone) return;
01088    // fprintf(stderr, "\n 1.  TGQt::%s  %d %p visible = %d \n", __FUNCTION__, id, id, wid(id)->isVisible());
01089    if (!wid(id)->isHidden()) wid(id)->hide();
01090    // fprintf(stderr, "  2. TGQt::%s  %d %p visible = %d \n",  __FUNCTION__, id, id, wid(id)->isVisible());
01091 }
01092 //______________________________________________________________________________
01093 void         TGQt::DestroyWindow(Window_t id)
01094 {
01095    // Destroy the window
01096 
01097    if (id == kNone || id == kDefault ) return;
01098    fQClientGuard.Delete(wid(id));
01099    // wid(id)->close(true);
01100 }
01101 //______________________________________________________________________________
01102 void  TGQt::LowerWindow(Window_t id)
01103 {
01104    // Lower window so it lays below all its siblings.
01105    if (id == kNone || id == kDefault ) return;
01106    wid(id)-> lower();
01107 }
01108 //______________________________________________________________________________
01109 void  TGQt::MoveWindow(Window_t id, Int_t x, Int_t y)
01110 {
01111    // Move a window.
01112    //  fprintf(stderr," TGQt::MoveWindow %d %d \n",x,y);
01113    if (id == kNone || id == kDefault ) return;
01114    wid(id)->move(x,y);
01115 }
01116 //______________________________________________________________________________
01117 void  TGQt::MoveResizeWindow(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h)
01118 {
01119    // Move and resize a window.
01120    // fprintf(stderr," TGQt::MoveResizeWindow %d %d %d %d\n",x,y,w,h);
01121    if (id == kNone || id == kDefault ) return;
01122 //   if (0 <= x < 3000 && 0 <= y < 3000 && w < 3000 && h < 3000)
01123    {
01124    wid(id)->setGeometry(x,y,w,h);
01125    //wid(id)->setFixedSize(w,h);
01126 }
01127 }
01128 //______________________________________________________________________________
01129 void  TGQt::ResizeWindow(Window_t id, UInt_t w, UInt_t h)
01130 {
01131    // Resize the window.
01132    //  fprintf(stderr," TGQt::ResizeWindow w,h=%d %d\n",w,h);
01133    if (id == kNone || id == kDefault ) return;
01134    //   if ( w < 3000 && h < 3000)
01135    {
01136       wid(id)->resize(w,h);
01137       //   wid(id)->setFixedSize(w,h);
01138    }
01139 }
01140 //______________________________________________________________________________
01141 void  TGQt::IconifyWindow(Window_t id)
01142 {
01143    // Shows the widget minimized, as an icon
01144    if ( id == kNone || id == kDefault ) return;
01145    wid(id)->showMinimized();
01146 }
01147 
01148 //______________________________________________________________________________
01149 Bool_t TGQt::NeedRedraw(ULong_t w, Bool_t force)
01150 {
01151    // Notify the low level GUI layer ROOT requires "w" to be updated
01152    // Return kTRUE if the notification was desirable and it was sent
01153    //
01154    // At the moment only Qt4 layer needs that
01155    //
01156    // One needs to process the notification to confine 
01157    // all paint operations within "expose" / "paint" like low level event
01158    // or equivalent
01159 #if ROOT_VERSION_CODE >= ROOT_VERSION(9,15,9)
01160    if (!force)
01161    {
01162      assert(0);
01163       TGWindow *www =(TGWindow *)w;
01164       Window_t id = www->GetId();
01165       if (id) wid(id)->update();
01166    }
01167    return !force;
01168 #else
01169   if (w||force) {}
01170    return kFALSE;   
01171 #endif     
01172 }
01173 //______________________________________________________________________________
01174 void  TGQt::RaiseWindow(Window_t id)
01175 {
01176   // Put window on top of window stack.
01177   //X11 says: The XRaiseWindow function raises the specified window to the top of the
01178   //  stack so that no sibling window obscures it.
01179   // OLD: Put the top window on the top top of desktop
01180    if ( id == kNone || id == kDefault ) return;
01181 #ifndef OLDQT23042004
01182    QWidget *wg = wid(id);
01183    wg->raise();
01184 #else
01185    MapWindow(id);
01186    QWidget *wg = wid(id);
01187    // fprintf(stderr, " 1.  TGQt::RaiseWindow id = %p IsTop=%d; parent = %p visible = %d \n", id,wg->isTopLevel(),iwid(wg->parentWidget()),wg->isVisible());
01188    if ( wg->isTopLevel() )  {
01189       QWidget *wg = ((TQtClientWidget *)wid(id))->topLevelWidget();
01190 #ifdef R__QTWIN32
01191       // raising the window under MS Windows needs some extra effort.
01192       HWND h = wg->winId();
01193       SetWindowPos(h,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
01194       SetWindowPos(h,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE );
01195 #endif
01196       wg->showNormal();
01197    } else {
01198       do {
01199          wg->raise();
01200       } while ( (!wg->isVisible()) && (wg = wg->parentWidget()) );
01201       wid(id)->show();
01202       // fprintf(stderr, " 2.  TGQt::RaiseWindow id = %p  visible = %d \n", id,wid(id)->isVisible());
01203    }
01204 #endif
01205 }
01206 //______________________________________________________________________________
01207 void         TGQt::SetIconPixmap(Window_t id, Pixmap_t pix)
01208 {
01209    // Set pixmap the WM can use when the window is iconized.
01210    if (id == kNone || id == kDefault || (pix==0) ) return;
01211    wid(id)->setWindowIcon(QIcon(*fQPixmapGuard.Pixmap(pix)));
01212 }
01213 //______________________________________________________________________________
01214 void         TGQt::ReparentWindow(Window_t id, Window_t pid, Int_t x, Int_t y)
01215 {
01216    // If the specified window is mapped, ReparentWindow automatically
01217    // performs an UnmapWindow request on it, removes it from its current
01218    // position in the hierarchy, and inserts it as the child of the specified
01219    // parent. The window is placed in the stacking order on top with respect
01220    // to sibling windows.
01221   
01222       wid(id)->setParent(wid(pid));
01223       if (x || y) wid(id)->move(x,y);
01224 }
01225 
01226 //______________________________________________________________________________
01227 void         TGQt::SetWindowBackground(Window_t id, ULong_t color)
01228 {
01229    // Set the window background color.
01230    if (id == kNone || id == kDefault ) return;
01231    TQtClientWidget *wd =  dynamic_cast<TQtClientWidget*>(wid(id));
01232    if (wd) wd->setEraseColor(QtColor(color));
01233 }
01234 //______________________________________________________________________________
01235 void         TGQt::SetWindowBackgroundPixmap(Window_t id, Pixmap_t pxm)
01236 {
01237    // Set pixmap as window background.
01238    if (pxm  != kNone && id != kNone && id != kDefault ) {
01239       TQtClientWidget *wd =  dynamic_cast<TQtClientWidget*>(wid(id));
01240       if (wd) wd->setErasePixmap (*fQPixmapGuard.Pixmap(pxm));
01241    }
01242  }
01243 //______________________________________________________________________________
01244 Window_t TGQt::CreateWindow(Window_t parent, Int_t x, Int_t y,
01245                                     UInt_t w, UInt_t h, UInt_t border,
01246                                     Int_t , UInt_t ,
01247                                     void *, SetWindowAttributes_t *attr,
01248                                     UInt_t wtype)
01249 {
01250    // Create QWidget to back TGWindow ROOT GUI object
01251 
01252    QWidget *pWidget = parent ? wid(parent):0;
01253 //   if ( !pWidget) pWidget = QApplication::desktop();
01254    if (pWidget == QApplication::desktop())  pWidget = 0;
01255    TQtClientWidget *win = 0;
01256       // we don't want to introduce the high level class depedency at this point yet.
01257       // Alas ROOT design does require us to do the dirt thing
01258    if (        wtype & kTransientFrame) {
01259       win =  fQClientGuard.Create(pWidget,"TransientFrame");
01260 #if QT_VERSION < 0x40000
01261       win->setFrameShape(QFrame::Box);      //  xattr.window_type = GDK_WINDOW_DIALOG;
01262    }  else if (wtype & kMainFrame)  {
01263       win =  fQClientGuard.Create(pWidget,"MainFrame"); //,Qt::WDestructiveClose);
01264       win->setFrameShape(QFrame::WinPanel); // xattr.window_type   = GDK_WINDOW_TOPLEVEL;
01265    }  else if (wtype & kTempFrame) {
01266       win =  fQClientGuard.Create(pWidget,"tooltip", Qt::WStyle_StaysOnTop | Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WX11BypassWM );
01267       win->setFrameStyle(QFrame::PopupPanel | QFrame::Plain);
01268    } else {
01269       win =  fQClientGuard.Create(pWidget,"Other", Qt::WStyle_StaysOnTop | Qt::WStyle_Customize | Qt::WX11BypassWM | (wtype & kOwnBackground ? Qt::WNoAutoErase : 0));
01270       if (!pWidget) {
01271            win->setFrameStyle( QFrame::PopupPanel | QFrame::Plain );
01272 //         printf(" 2 TGQt::CreateWindow %p parent = %p \n", win,pWidget);
01273       }
01274 #else
01275       win->setFrameShape(QFrame::Box);      //  xattr.window_type = GDK_WINDOW_DIALOG;
01276    }  else if (wtype & kMainFrame)  {
01277       win =  fQClientGuard.Create(pWidget,"MainFrame"); //,Qt::WDestructiveClose);
01278       win->setFrameShape(QFrame::WinPanel); // xattr.window_type   = GDK_WINDOW_TOPLEVEL;
01279    }  else if (wtype & kTempFrame) {
01280       win =  fQClientGuard.Create(pWidget,"tooltip"
01281             , Qt::ToolTip 
01282             | Qt::Tool
01283             | Qt::X11BypassWindowManagerHint
01284             | Qt::FramelessWindowHint
01285             | Qt::WindowStaysOnTopHint );
01286 #if QT_VERSION >= 0x040400
01287       win->setAttribute(Qt::WA_X11NetWmWindowTypeToolTip);
01288 #endif
01289       win->setFrameStyle(QFrame::Box | QFrame::Plain);
01290    } else {
01291       win =  fQClientGuard.Create(pWidget,"Other"
01292             , Qt::WindowStaysOnTopHint
01293             | Qt::X11BypassWindowManagerHint );
01294       if (!pWidget) {
01295          win->setFrameStyle(QFrame::WinPanel | QFrame::Plain);
01296        //   printf(" TGQt::CreateWindow %p parent = %p \n", win,pWidget);
01297       }
01298 #endif
01299   }
01300 
01301   //  fprintf(stderr," TQt::CreateWindow %p parent = %p  %s \n", win,pWidget,(const char*)win->name());
01302 
01303    if (QClientFilter()) {
01304       win->installEventFilter(QClientFilter());
01305    }
01306    if (border > 0)
01307       win->setContentsMargins((int)border,(int)border,(int)border,(int)border);
01308    if (attr) {
01309       if ((attr->fMask & kWABackPixmap))
01310          if (attr->fBackgroundPixmap != kNone && attr->fBackgroundPixmap != kParentRelative )
01311          {
01312             QPalette palette= win->palette();
01313             palette.setBrush(QPalette::Window, QBrush(*(QPixmap *)attr->fBackgroundPixmap));
01314             win->setErasePixmap(*(QPixmap *)attr->fBackgroundPixmap);
01315             win->setPalette(palette);
01316             win->setBackgroundRole(QPalette::Window);
01317          }
01318       if ((attr->fMask & kWABackPixel)) {
01319             QPalette palette= win->palette();
01320             palette.setColor(QPalette::Window, QtColor(attr->fBackgroundPixel));
01321             win->setEraseColor(QtColor(attr->fBackgroundPixel));
01322             win->setPalette(palette);
01323             win->setBackgroundRole(QPalette::Window);
01324        }
01325       if ( attr->fMask & kWAEventMask) {
01326           // Long_t     fEventMask;            // set of events that should be saved
01327           win->SetAttributeEventMask(attr->fEventMask);
01328       }
01329    }
01330    MoveResizeWindow(rootwid(win),x,y,w,h);
01331    return rootwid(win);
01332 }
01333 //______________________________________________________________________________
01334 Int_t        TGQt::OpenDisplay(const char *dpyName)
01335 {
01336   // The dummy method to fit the X11-like interface
01337   if (dpyName){}
01338 #ifdef R__QTX11
01339   return ConnectionNumber( GetDisplay() );
01340 #else
01341   return 1;
01342 #endif
01343 }
01344 //______________________________________________________________________________
01345 void    TGQt::CloseDisplay()
01346 {
01347    // The close all remaining QWidgets
01348    qApp->closeAllWindows();
01349 }
01350 //______________________________________________________________________________
01351 Display_t  TGQt::GetDisplay() const
01352 {
01353    // Returns handle to display (might be usefull in some cases where
01354    // direct X11 manipulation outside of TVirtualX is needed, e.g. GL
01355    // interface).
01356 
01357    // Calling implies the direct X11 manipulation
01358    // Using this method makes the rest of the ROOT X11 depended
01359 
01360 #ifdef R__QTX11
01361    return (Display_t)QX11Info::display();
01362 #else
01363    // The dummy method to fit the X11-like interface
01364    return 0;
01365 #endif
01366 }
01367 //______________________________________________________________________________
01368 Visual_t   TGQt::GetVisual() const
01369 {
01370    // Returns handle to visual (might be usefull in some cases where
01371    // direct X11 manipulation outside of TVirtualX is needed, e.g. GL
01372    // interface).
01373 
01374    // Calling implies the direct X11 manipulation
01375    // Using this method makes the rest of the ROOT X11 depended
01376 
01377 #ifdef R__QTX11
01378    return (Visual_t) QX11Info::appVisual();
01379 #else
01380    // The dummy method to fit the X11-like interface
01381    return 0;
01382 #endif
01383 }
01384 //______________________________________________________________________________
01385 Int_t      TGQt::GetScreen() const
01386 {
01387    // Returns screen number (might be usefull in some cases where
01388    // direct X11 manipulation outside of TVirtualX is needed, e.g. GL
01389    // interface).
01390 
01391    // Calling implies the direct X11 manipulation
01392    // Using this method makes the rest of the ROOT X11 depended
01393 
01394 #ifdef R__QTX11
01395    return   QX11Info::appScreen();
01396 #else
01397    // The dummy method to fit the X11-like interface
01398    return 0;
01399 #endif
01400 }
01401 //______________________________________________________________________________
01402 Int_t      TGQt::GetDepth() const
01403 {
01404    // Returns depth of screen (number of bit planes).
01405 #ifdef R__QTX11
01406    return  QX11Info::appDepth();
01407 #else
01408    return QPixmap::defaultDepth();
01409 #endif
01410 }
01411 //______________________________________________________________________________
01412 Colormap_t TGQt::GetColormap() const { return 0; }
01413 
01414 //______________________________________________________________________________
01415 Atom_t     TGQt::InternAtom(const char *atom_name, Bool_t /*only_if_exist*/)
01416 {
01417    // Return atom handle for atom_name. If it does not exist
01418    // create it if only_if_exist is false. Atoms are used to communicate
01419    // between different programs (i.e. window manager) via the X server.
01420 
01421    const char *rootAtoms[] = {  "WM_DELETE_WINDOW"
01422                               , "_MOTIF_WM_HINTS"
01423                               , "_ROOT_MESSAGE"
01424                               , "_ROOT_CLIPBOARD"
01425                               , "CLIPBOARD"
01426                               , ""  };
01427   int nSize = sizeof(rootAtoms)/sizeof(char *);
01428   nSize --;
01429   int i;
01430   for (i=0; (i<nSize)  && ( strcmp(atom_name,rootAtoms[i])) ;i++){;}
01431   // printf("  TGQt::InternAtom %d <%s>:<%s> \n",i, rootAtoms[i],atom_name );
01432   return i;
01433 }
01434 //______________________________________________________________________________
01435 Window_t     TGQt::GetParent(Window_t id) const
01436 {
01437    // Return the parent of the window.
01438    if ( id == kNone || id == kDefault ) return id;
01439    QWidget *dadWidget = wid(id)->parentWidget();
01440    assert(dynamic_cast<TQtClientWidget*>(dadWidget));
01441    return rootwid(dadWidget);
01442 }
01443 //______________________________________________________________________________
01444 FontStruct_t TGQt::LoadQueryFont(const char *font_name)
01445 {
01446    // Load font and query font. If font is not found 0 is returned,
01447    // otherwise a opaque pointer to the FontStruct_t.
01448    // Parse X11-like font definition to QFont parameters:
01449    // -adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1
01450    // -adobe-helvetica-medium-r-*-*-*-12-*-*-*-*-iso8859-1
01451    QString fontName(QString(font_name).trimmed());
01452    QFont *newFont = 0;
01453    if (fontName.toLower() == "qt-default") newFont = new QFont(QApplication::font());
01454    else {
01455 #ifdef R__UNIX
01456    newFont = new QFont();
01457    newFont->setRawName(fontName);
01458 #else
01459    QString fontFamily = fontName.section('-',1,2);
01460    int weight = QFont::Normal;
01461 
01462    QString fontWeight = fontName.section('-',3,3);
01463    if (fontWeight.startsWith("bold")) weight = QFont::Bold;
01464 
01465    bool italic = (fontName.section('-',4,4)[0] == 'i');
01466 
01467 
01468    bool ok;
01469    int fontSize=12;
01470    int fontPointSize   = fontName.section('-',8,8).toInt(&ok);
01471    if (ok) fontSize = fontPointSize;
01472    newFont = new QFont(fontFamily,fontSize,weight,italic);
01473    if (!ok) {
01474       int fontPixelSize   = fontName.section('-',7,7).toInt(&ok);
01475       if (ok)
01476          newFont->setPixelSize(int(TMath::Max(fontPixelSize,1)));
01477    }
01478 #endif
01479    newFont->setStyleHint(QFont::System,QFont::PreferDevice);
01480    }
01481    //fprintf(stderr, " 0x%p = LoadQueryFont(const char *%s) = family=%s, w=%s, size=%d (pt), pixel size=%d\n",
01482    //        newFont, font_name,(const char *)fontFamily,(const char *)fontWeight,fontSize,newFont->pixelSize());
01483    return FontStruct_t(newFont);
01484 }
01485 //______________________________________________________________________________
01486 FontH_t      TGQt::GetFontHandle(FontStruct_t fs)
01487 {
01488    // Return handle to font described by font structure.
01489    // This is adummy operation.
01490    //  There is no reason to use any handle
01491    // fprintf(stderr," TGQt::GetFontHandle(FontStruct_t fs) %s\n",(const char *) ((QFont *)fs)->toString());
01492    return (FontH_t)fs;
01493 }
01494 //______________________________________________________________________________
01495 void         TGQt::DeleteFont(FontStruct_t fs)
01496 {
01497    // Explicitely delete font structure.
01498    delete (QFont *)fs;
01499 }
01500 //______________________________________________________________________________
01501 GContext_t   TGQt::CreateGC(Drawable_t /*id*/, GCValues_t *gval)
01502 {
01503   // Create a graphics context using the values set in gval (but only for
01504   // those entries that are in the mask).
01505    QtGContext *context = 0;
01506    if (gval) 
01507       context =  new QtGContext(*gval);
01508    else 
01509       context =  new QtGContext();      
01510 //   MapGCValues(*gval, context)
01511   return GContext_t(context);
01512 }
01513 //______________________________________________________________________________
01514 void         TGQt::ChangeGC(GContext_t gc, GCValues_t *gval)
01515 {
01516    // Change entries in an existing graphics context, gc, by values from gval.
01517    qtcontext(gc) = *gval;
01518 }
01519 //______________________________________________________________________________
01520 void         TGQt::CopyGC(GContext_t org, GContext_t dest, Mask_t mask)
01521 {
01522   // Copies graphics context from org to dest. Only the values specified
01523   // in mask are copied. Both org and dest must exist.
01524    qtcontext(dest).Copy(qtcontext(org),mask);
01525 }
01526 //______________________________________________________________________________
01527 void         TGQt::DeleteGC(GContext_t gc)
01528 {
01529    // Explicitely delete a graphics context.
01530    delete &qtcontext(gc);
01531 }
01532 //______________________________________________________________________________
01533 Cursor_t     TGQt::CreateCursor(ECursor cursor)
01534 {
01535    // Create cursor handle (just return cursor from cursor pool fCursors).
01536   return Cursor_t(fCursors[cursor]);
01537 }
01538 //______________________________________________________________________________
01539 void         TGQt::SetCursor(Window_t id, Cursor_t curid)
01540 {
01541    // Set the specified cursor.
01542   if (id && id != Window_t(-1)) cwid(id)->SetCursor(curid);
01543 
01544 }
01545 //______________________________________________________________________________
01546 Pixmap_t     TGQt::CreatePixmap(Drawable_t /*id*/, UInt_t w, UInt_t h)
01547 {
01548    // Creates a pixmap of the width and height you specified
01549    // and returns a pixmap ID that identifies it.
01550    QPixmap *p = fQPixmapGuard.Create(w, h);
01551    return Pixmap_t(rootwid(p));
01552 }
01553 //______________________________________________________________________________
01554 Pixmap_t     TGQt::CreatePixmap(Drawable_t /*id*/, const char *bitmap, UInt_t width,
01555                                UInt_t height, ULong_t forecolor, ULong_t backcolor,
01556                                Int_t depth)
01557 {
01558    // Create a pixmap from bitmap data. Ones will get foreground color and
01559    // zeroes background color.
01560    QPixmap *p = 0;
01561    if (depth >1) {
01562       QBitmap bp = QBitmap::fromData(QSize(width, height),(const uchar*)bitmap);
01563       QBrush  fillBrush(QtColor(backcolor), bp);
01564       p =  fQPixmapGuard.Create(width,height,depth);
01565       QPainter pixFill(p);
01566       pixFill.setBackground(QtColor(backcolor));
01567       pixFill.setPen(QtColor(forecolor));
01568       pixFill.fillRect(0,0,width, height,fillBrush);
01569    } else {
01570       p = fQPixmapGuard.Create(width, height,(const uchar*)bitmap);
01571    }
01572    return Pixmap_t(rootwid(p));
01573 }
01574 //______________________________________________________________________________
01575 Pixmap_t     TGQt::CreateBitmap(Drawable_t id, const char *bitmap,
01576                                UInt_t width, UInt_t height)
01577 {
01578    // Create a bitmap (i.e. pixmap with depth 1) from the bitmap data.
01579    return CreatePixmap(id,bitmap,width,height, 1,0,1);
01580 }
01581 //______________________________________________________________________________
01582 void         TGQt::DeletePixmap(Pixmap_t pmap)
01583 {
01584    // Explicitely delete pixmap resource.
01585    if (pmap  != kNone )
01586       fQPixmapGuard.Delete((QPixmap *)iwid(pmap));
01587    // delete (QPixmap *)pmap;
01588 }
01589 //______________________________________________________________________________
01590 static inline void FillPixmapAttribute(QPixmap &pixmap, Pixmap_t &pict_mask
01591                                        , PictureAttributes_t & attr,TQtPixmapGuard &guard)
01592 {
01593    // static method to avoid a access to the died objects
01594    attr.fWidth  = pixmap.width();
01595    attr.fHeight = pixmap.height();
01596    // Let's see whether the file brought us any mask.
01597    if  ( !pixmap.mask().isNull() ) {
01598       QBitmap *pixmask = (QBitmap *)guard.Pixmap(pict_mask,kTRUE);
01599       if (pixmask) { // fill it with the new value
01600          *pixmask = pixmap.mask();
01601       } else {
01602          pixmask   = guard.Create(pixmap.mask());
01603          pict_mask = Pixmap_t(TGQt::rootwid(pixmask));
01604       }
01605    } else {
01606       pict_mask = kNone;
01607    }
01608 }
01609 //______________________________________________________________________________
01610 Bool_t       TGQt::CreatePictureFromFile( Drawable_t /*id*/, const char *filename,
01611                                         Pixmap_t & pict,
01612                                         Pixmap_t &pict_mask,
01613                                         PictureAttributes_t & attr)
01614 {
01615    // Create a picture pixmap from data on file. The picture attributes
01616    // are used for input and output. Returns kTRUE in case of success,
01617    // kFALSE otherwise. If mask does not exist it is set to kNone.
01618    QPixmap *pixmap = 0;
01619    if (pict  != kNone )
01620       pixmap = fQPixmapGuard.Pixmap(pict);
01621    if (!pixmap) {
01622       // Create the new pixmap
01623       pixmap = fQPixmapGuard.Create(QString(filename));
01624       // pixmap = new QPixmap (QString(filename));
01625       pict = Pixmap_t(rootwid(pixmap));
01626    } else {
01627       // reload the old one
01628       pixmap->load(QString(filename));
01629    }
01630    if (! pixmap->isNull() ) {
01631       FillPixmapAttribute(*pixmap,pict_mask,attr,fQPixmapGuard);
01632    } else {
01633       fQPixmapGuard.Delete(pixmap);
01634       pict= kNone;
01635       pixmap = 0;
01636    }
01637    return pixmap;
01638 }
01639 
01640 //______________________________________________________________________________
01641 Bool_t       TGQt::CreatePictureFromData(Drawable_t /*id*/, char **data,
01642                                         Pixmap_t & pict,
01643                                         Pixmap_t &pict_mask,
01644                                         PictureAttributes_t & attr)
01645 {
01646    // Create a pixture pixmap from data. The picture attributes
01647    // are used for input and output. Returns kTRUE in case of success,
01648    // kFALSE otherwise. If mask does not exist it is set to kNone.
01649    QPixmap *pixmap = fQPixmapGuard.Pixmap(pict);
01650    if (!pixmap) {
01651       pixmap = fQPixmapGuard.Create((const char **)data);
01652       pict = Pixmap_t(rootwid(pixmap));
01653    }  else {
01654       *pixmap = QPixmap ( (const char **)data);
01655    }
01656 
01657    if (! pixmap->isNull() ) {
01658       FillPixmapAttribute(*pixmap,pict_mask,attr,fQPixmapGuard);
01659    } else {
01660       fQPixmapGuard.Delete(pixmap);
01661       pict= kNone;
01662       pixmap = 0;
01663    }
01664    return pixmap;
01665 }
01666 //______________________________________________________________________________
01667 Bool_t       TGQt::ReadPictureDataFromFile(const char *fileName, char ***data)
01668 {
01669    // Read picture data from file and store in ret_data. Returns kTRUE in
01670    // case of success, kFALSE otherwise.
01671    QPixmap *pictureBuffer = fQPixmapGuard.Create(QString(fileName));
01672    if (pictureBuffer->isNull()){
01673       fQPixmapGuard.Delete(pictureBuffer);
01674    }  else {
01675       // &data = (char **)pictureBuffer;
01676    }
01677    if (!data)
01678       return gSystem->Load(fileName);
01679    else {
01680       fprintf(stderr, "I got no idea why do we need this trick yet!\n");
01681    }
01682    return kFALSE;
01683 }
01684 //______________________________________________________________________________
01685  void         TGQt::DeletePictureData(void *data)
01686  {
01687     // Delete the QPixmap
01688     fQPixmapGuard.Delete((QPixmap *)data);
01689  }
01690 //______________________________________________________________________________
01691 void         TGQt::SetDashes(GContext_t /*gc*/, Int_t /*offset*/, const char * /*dash_list*/,
01692                         Int_t /*n*/)
01693 {
01694    // Specify a dash pattertn. Offset defines the phase of the pattern.
01695    // Each element in the dash_list array specifies the length (in pixels)
01696    // of a segment of the pattern. N defines the length of the list.
01697 
01698    //  QT has no built-in "user defined dashes"
01699 }
01700 //______________________________________________________________________________
01701 Int_t  TGQt::EventsPending() {
01702 #ifndef R__QTGUITHREAD
01703     // to avoid the race condition
01704     Int_t retCode = fQClientFilterBuffer ? fQClientFilterBuffer->count(): 0;
01705     if (fQtEventHasBeenProcessed) {
01706        fQtEventHasBeenProcessed++;
01707        if (fQtEventHasBeenProcessed > 2) fQtEventHasBeenProcessed = 0;
01708     } else retCode = qApp->hasPendingEvents();
01709     return  retCode;
01710 #endif
01711 
01712    if (fQClientFilterBuffer && fQClientFilterBuffer->isEmpty())
01713    {
01714       // We do not need the empty buffer, Let's delete it
01715 #ifndef R__QTGUITHREAD
01716       if (qApp->hasPendingEvents ()) qApp->processEvents ();
01717 #else
01718       delete fQClientFilterBuffer;
01719       fQClientFilterBuffer = 0;
01720 #endif
01721 //      return 0;
01722    }
01723    if (!fQClientFilterBuffer)
01724       fQClientFilterBuffer = fQClientFilter->Queue();
01725    return fQClientFilterBuffer ? fQClientFilterBuffer->count(): 0;
01726 }
01727 //______________________________________________________________________________
01728 void TGQt::Bell(Int_t percent)
01729 {
01730    // Sound bell
01731 #ifdef R__QTWIN32
01732    DWORD dwFreq     = 1000L;         // sound frequency, in hertz
01733    DWORD dwDuration = 100L+percent;  // sound frequency, in hertz
01734    Beep(dwFreq,dwDuration);
01735 #else
01736    if (percent) {}
01737    QApplication::beep ();
01738 #endif
01739 }
01740 //______________________________________________________________________________
01741 void         TGQt::CopyArea(Drawable_t src, Drawable_t dest, GContext_t gc,
01742                            Int_t src_x, Int_t src_y, UInt_t width,
01743                            UInt_t height, Int_t dest_x, Int_t dest_y)
01744 {
01745    // Copy a drawable (i.e. QPaintDevice  ) to another drawable (pixmap, widget).
01746    // The graphics context gc will be used and the source will be copied
01747    // from src_x,src_y,src_x+width,src_y+height to dest_x,dest_y.
01748    assert(qtcontext(gc).HasValid(QtGContext::kROp));
01749    // fprintf(stderr," TQt::CopyArea this=%p, fROp=%x\n", this, qtcontext(gc).fROp);
01750    if ( dest && src) {
01751       // QtGContext qgc = qtcontext(gc);
01752       QPixmap *pix = dynamic_cast<QPixmap*>(iwid(src));
01753       QBitmap *mask = qtcontext(gc).fClipMask;
01754       if (pix && mask && (qtcontext(gc).fMask & QtGContext::kClipMask)) {         
01755          if ((pix->width() != mask->width()) || (pix->height() != mask->height())) 
01756          {
01757             // TASImage::GetMask() creates mask with the width rounded to 8
01758             // pix->resize(mask->width(), mask->height());
01759             QBitmap rightMask = mask->copy(pix->rect());
01760             pix->setMask(rightMask);
01761          } else {
01762              pix->setMask(*mask);
01763          }
01764          TQtPainter copyArea(iwid(dest),qtcontext(gc));
01765          if (src==dest) {
01766             QPixmap tmp = pix->copy(src_x,src_y,width,height);
01767             copyArea.drawPixmap(dest_x,dest_y, tmp);
01768          } else {
01769             copyArea.drawPixmap(dest_x,dest_y, *pix, src_x,src_y,width,height);
01770          }
01771       } else {
01772          if (pix) {
01773            TQtPainter copyArea(iwid(dest),qtcontext(gc));
01774             if (src==dest) {
01775                QPixmap tmp = pix->copy(src_x,src_y,width,height);
01776                copyArea.drawPixmap(dest_x,dest_y, tmp);
01777             } else {
01778                 copyArea.drawPixmap(dest_x,dest_y,*pix, src_x,src_y,width,height);
01779             }
01780          } else {
01781             QImage *im = dynamic_cast<QImage*>(iwid(src)); 
01782             if (im) {
01783                TQtPainter copyArea(iwid(dest),qtcontext(gc));
01784                copyArea.drawImage(dest_x,dest_y,*im, src_x,src_y,width,height);
01785             } else {
01786                QWidget *qw = dynamic_cast<QWidget*>(iwid(src)); 
01787                if (qw) {
01788                   QPixmap pixw = QPixmap::grabWidget(qw, QRect(src_x,src_y,width,height));
01789                   TQtPainter copyArea(iwid(dest),qtcontext(gc));
01790                   copyArea.drawPixmap(dest_x,dest_y,pixw, src_x,src_y,width,height);
01791                } else { 
01792                   qDebug() << " TGQt::CopyArea: illegal image source. Should be either QPixmap or QImage";
01793                }
01794             }
01795          }
01796       }
01797    }
01798 }
01799 //______________________________________________________________________________
01800 void         TGQt::ChangeWindowAttributes(Window_t id, SetWindowAttributes_t *attr)
01801 {
01802    // Change window attributes.
01803 
01804    if (!attr || (id == kNone) || (id == kDefault) )  return;
01805 
01806    TQtClientWidget *p = dynamic_cast<TQtClientWidget *>(wid(id));
01807    assert(p);
01808    TQtClientWidget &f = *p;
01809    //   fMask;   // bit mask specifying which fields are valid
01810    if ( attr->fMask & kWABackPixmap) {
01811       switch (attr->fBackgroundPixmap) {
01812           case kNone:
01813           case kParentRelative:
01814              break;
01815           default:
01816                 f.setErasePixmap (*(QPixmap *)attr->fBackgroundPixmap);
01817                 break;
01818       };
01819    }
01820    if ( attr->fMask & kWABackPixel) {
01821       // background pixel
01822       f.setEraseColor(QtColor(attr->fBackgroundPixel));
01823    }
01824    if ( attr->fMask & kWABorderPixmap) {
01825       // fBorderPixmap;         // border of the window
01826    }
01827    if ( attr->fMask & kWABorderPixel) {
01828       // ULong_t    fBorderPixel;          // border pixel value
01829        // f.setFrameShape( QFrame::PopupPanel );
01830 #if QT_VERSION < 0x40000
01831        f.setFrameStyle( QFrame::Box | QFrame::Plain );
01832 #else /* QT_VERSION */
01833        f.setFrameStyle( QFrame::Box );
01834 #endif /* QT_VERSION */
01835        // printf("TGQt::ChangeWindowAttributes  kWABorderPixel %p name = %s; shape = %d; margin = %d width=%d \n",&f,(const char*)f.name(),f.frameShape(),f.margin(),f.lineWidth() );
01836    }
01837    if ( attr->fMask & kWABorderWidth) {
01838       // border width in pixels)
01839        f.setLineWidth(attr->fBorderWidth);
01840        // printf("TGQt::ChangeWindowAttributes  kWABorderWidth %p %d margin=%d\n",&f, attr->fBorderWidth,f.margin());
01841    }
01842    if ( attr->fMask & kWABitGravity) {
01843       //  Int_t      fBitGravity;           // one of bit gravity values
01844    }
01845    if ( attr->fMask & kWAWinGravity) {
01846       // Int_t      fWinGravity;           // one of the window gravity values
01847    }
01848    if ( attr->fMask & kWABackingStore) {
01849       //  Int_t      fBackingStore;         // kNotUseful, kWhenMapped, kAlways
01850    }
01851    if ( attr->fMask & kWABackingPlanes) {
01852       // ULong_t    fBackingPlanes;        // planes to be preseved if possible
01853    }
01854    if ( attr->fMask & kWABackingPixel) {
01855       // ULong_t    fBackingPixel;         // value to use in restoring planes
01856    }
01857    if ( attr->fMask & kWAOverrideRedirect) {
01858       // Bool_t     fOverrideRedirect;     // boolean value for override-redirect
01859    }
01860    if ( attr->fMask & kWASaveUnder) {
01861       // Bool_t     fSaveUnder;            // should bits under be saved (popups)?
01862    }
01863    if ( attr->fMask & kWAEventMask) {
01864       // Long_t     fEventMask;            // set of events that should be saved
01865       f.SetAttributeEventMask(attr->fEventMask);
01866    }
01867    if ( attr->fMask & kWADontPropagate) {
01868       // Long_t     fDoNotPropagateMask;   // set of events that should not propagate
01869    }
01870    if ( attr->fMask & kWAColormap) {
01871       // Colormap_t fColormap;             // color map to be associated with window
01872    }
01873    if ( attr->fMask & kWACursor) {
01874       // cursor to be displayed (or kNone)
01875       if (fCursor != kNone) f.setCursor(*fCursors[fCursor]);
01876       else f.setCursor(QCursor(Qt::BlankCursor));
01877    }
01878 }
01879 //______________________________________________________________________________
01880 void         TGQt::ChangeProperty(Window_t, Atom_t, Atom_t, UChar_t *, Int_t) { }
01881 //______________________________________________________________________________
01882 void TGQt::DrawLine(Drawable_t id, GContext_t gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
01883 {
01884    // Draw a line.
01885    TQtPainter p(iwid(id),qtcontext(gc));
01886    p.drawLine ( x1, y1, x2, y2 );
01887 }
01888 //______________________________________________________________________________
01889 void         TGQt::ClearArea(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h)
01890 {
01891    // Clear a window area to the background color.
01892    if (id == kNone || id == kDefault ) return;
01893    QPainter paint(iwid(id));  
01894    paint.setBackgroundMode( Qt::OpaqueMode); // Qt::TransparentMode
01895    TQtClientWidget *wd =  dynamic_cast<TQtClientWidget*>(wid(id));
01896    const QColor  *c = 0;
01897    const QPixmap *p = 0;
01898 #if QT_VERSION < 0x50000
01899    c = wd ? wd->fEraseColor  : 0;
01900    p = wd ? wd->fErasePixmap : 0;
01901    const QColor  &cr = *c;
01902    const QPixmap &pr = *p;
01903 #else
01904    const QColor  &cr = wd ? wd->palette().color(QPalette::Window) : *c;
01905    c = wd ? &cr : 0;
01906    const QPixmap &pr = *p;
01907 #endif
01908    if (int(w) <=0) {
01909       qDebug() << "TGQt::ClearArea: ***   wrong client are size: " << w <<" : " << Int_t(w);
01910       return;
01911    }
01912    if (p && c) 
01913          paint.fillRect ( x, y, w, h, QBrush(cr,pr));
01914    else if (p)
01915          paint.fillRect ( x, y, w, h, QBrush(pr));
01916    else if (c)
01917          paint.fillRect ( x, y, w, h, cr);
01918    else {
01919        const QBrush  &crw = wd->palette().brush(QPalette::Window);
01920        paint.fillRect ( x, y, w, h, crw);
01921    }
01922   //  qDebug() << " TGQt::ClearArea " << (void *)id << p << c;
01923 }
01924 //______________________________________________________________________________
01925 Bool_t       TGQt::CheckEvent(Window_t, EGEventType, Event_t &) 
01926 {
01927    // Check if there is for window "id" an event of type "type". If there
01928    // is fill in the event structure and return true. If no such event
01929    // return false.
01930   
01931     return kFALSE; 
01932 }
01933 //______________________________________________________________________________
01934 void         TGQt::SendEvent(Window_t id, Event_t *ev)
01935 {
01936    // Send event ev to window id.
01937 
01938    if (ev &&  (ev->fType  == kClientMessage || ev->fType  == kDestroyNotify) &&  id != kNone )
01939    {
01940       TQUserEvent qEvent(*ev);
01941       static TQtClientWidget *gMessageDispatcherWidget = 0;
01942       if (!gMessageDispatcherWidget) {
01943          gMessageDispatcherWidget = fQClientGuard.Create(0,"messager");
01944          if (QClientFilter()) {
01945             gMessageDispatcherWidget->installEventFilter(QClientFilter());
01946          }
01947       }
01948       QObject * receiver = 0;
01949       if ( id != kDefault) {
01950          receiver = wid(id);
01951       } else {
01952          receiver = gMessageDispatcherWidget;
01953          // fprintf(stderr, "  TGQt::SendEvent(Window_t id=%d, Event_t *ev=%d) to %p\n", id, ev->fType,  receiver);
01954       }
01955 
01956       // fprintf(stderr, "  TGQt::SendEvent(Window_t id, Event_t *ev) %p type=%d\n", wid(id), ev->fType);
01957       QApplication::postEvent(receiver,new TQUserEvent(*ev));
01958    } else {
01959       if (ev) fprintf(stderr,"TQt::SendEvent:: unknown event %d for widget: %p\n",ev->fType,wid(id));
01960    }
01961 }
01962 //______________________________________________________________________________
01963  void         TGQt::WMDeleteNotify(Window_t id)
01964  {
01965     // WMDeleteNotify causes the filter to treat QEventClose event
01966     if (id == kNone || id == kDefault ) return;
01967     ((TQtClientWidget *)wid(id))->SetDeleteNotify();
01968     // fprintf(stderr,"TGQt::WMDeleteNotify %p\n",id);
01969  }
01970 //______________________________________________________________________________
01971  void         TGQt::SetKeyAutoRepeat(Bool_t) { }
01972 //______________________________________________________________________________
01973  void         TGQt::GrabKey(Window_t id, Int_t keycode, UInt_t modifier, Bool_t grab)
01974  {
01975    // Establish passive grab on a certain key. That is, when a certain key
01976    // keycode is hit while certain modifier's (Shift, Control, Meta, Alt)
01977    // are active then the keyboard will be grabed for window id.
01978    // When grab is false, ungrab the keyboard for this key and modifier.
01979    // A modifiers argument of AnyModifier is equivalent to issuing the
01980    // request for all possible modifier combinations (including the combination of no modifiers).
01981 
01982     if (id == kNone) return;
01983 
01984     if (grab ) {
01985       ((TQtClientWidget*)wid(id))->SetKeyMask(keycode,modifier);
01986     } else {
01987        ((TQtClientWidget*)wid(id))->UnSetKeyMask(keycode,modifier);
01988     }
01989  }
01990 //______________________________________________________________________________
01991  void         TGQt::GrabButton(Window_t id, EMouseButton button, UInt_t modifier,
01992                        UInt_t evmask, Window_t confine, Cursor_t cursor,
01993                        Bool_t grab)
01994  {
01995    // Establish passive grab on a certain mouse button. That is, when a
01996    // certain mouse button is hit while certain modifier's (Shift, Control,
01997    // Meta, Alt) are active then the mouse will be grabed for window id.
01998    // When grab is false, ungrab the mouse button for this button and modifier.
01999 
02000     //X11: ButtonPress event is reported if all of the following conditions are true:
02001     //   ·    The pointer is not grabbed, and the specified button is logically
02002     //        pressed when the specified modifier keys are logically down,
02003     //        and no other buttons or modifier keys are logically down.
02004     //   ·    The grab_window contains the pointer.
02005     //   ·    The confine_to window (if any) is viewable.
02006     //   ·    A passive grab on the same button/key combination does not exist
02007     //        on any ancestor of grab_window.
02008 
02009 //    fprintf(stderr,"TGQt::GrabButton \"0x%x\" id=%x QWidget = %p\n"
02010 //       ,evmask,id,((TQtClientWidget*)wid(id)));
02011     if (id == kNone) return;
02012     assert(confine==kNone);
02013     if (grab ) {
02014 //       if (cursor == kNone) {
02015           ((TQtClientWidget*)wid(id))->SetButtonMask(modifier,button); 
02016           ((TQtClientWidget*)wid(id))->SetButtonEventMask(evmask,cursor);
02017     } else {
02018           ((TQtClientWidget*)wid(id))->UnSetButtonMask();
02019     }
02020 }
02021 
02022  //______________________________________________________________________________
02023  void         TGQt::GrabPointer(Window_t id, UInt_t evmask, Window_t confine,
02024                         Cursor_t cursor, Bool_t grab, Bool_t owner_events)
02025  {
02026     // Establish an active pointer grab. While an active pointer grab is in
02027     // effect, further pointer events are only reported to the grabbing
02028     // client window.
02029 
02030     // XGrabPointer(3X11):
02031        // The XGrabPointer function actively grabs control of the
02032        // pointer and returns GrabSuccess if the grab was success­
02033        // ful.  Further pointer events are reported only to the
02034        // grabbing client.  XGrabPointer overrides any active
02035        // pointer grab by this client.  If owner_events is False,
02036        // all generated pointer events are reported with respect to
02037        // grab_window and are reported only if selected by
02038        // event_mask.  If owner_events is True and if a generated
02039        // pointer event would normally be reported to this client,
02040        // it is reported as usual.  Otherwise, the event is reported
02041        // with respect to the grab_window and is reported only if
02042        // selected by event_mask.
02043        //-------------------------------------------------------------------
02044        // For either value of owner_events, unreported events are discarded.
02045        //-------------------------------------------------------------------
02046 
02047     assert(confine==kNone);
02048     TQtClientWidget *gw = (id == kNone) ?  0: cwid(id);
02049     // Do we still grabbing anything ?
02050     if (grab) {
02051        if ( !gw )  return;
02052        fPointerGrabber = gw;
02053        // fprintf(stderr,"TGQt::GrabPointer grabbing with the cursor: owner=%d wid = %x %p\n", owner_events, id, gw);
02054     } else {
02055        if (!gw) gw = fPointerGrabber;
02056        // fprintf(stderr,"TGQt::GrabPointer ungrabbing with the cursor: owner=%d wid =  %x grabber =%p \n"
02057        //      , owner_events, id, gw );
02058        fPointerGrabber = 0;
02059     }
02060     TQtClientFilter *f = QClientFilter();
02061     if (f) 
02062         f->GrabPointer(gw, evmask,0,(QCursor *)cursor, grab, owner_events);
02063  }
02064 //______________________________________________________________________________
02065  void         TGQt::SetWindowName(Window_t id, char *name)
02066  {
02067     // Set window name.
02068     if (id == kNone || id == kDefault ) return;
02069     winid(id)->setWindowTitle(name);
02070  }
02071  //______________________________________________________________________________
02072  void         TGQt::SetIconName(Window_t id, char *name)
02073  {
02074     // Set window icon name.
02075     if (id == kNone || id == kDefault ) return;
02076     winid(id)-> setWindowIconText(name);
02077  }
02078 //______________________________________________________________________________
02079 void  TGQt::Warp(Int_t ix, Int_t iy, Window_t id) {
02080    // Set pointer position.
02081    // ix       : New X coordinate of pointer
02082    // iy       : New Y coordinate of pointer
02083    // Coordinates are relative to the origin of the window id
02084    // or to the origin of the current window if id == 0.
02085    if (id == kNone) {}
02086    else {
02087        QCursor::setPos(wid(id)->mapToGlobal(QPoint(ix,iy)));
02088    }
02089 }
02090 //______________________________________________________________________________
02091  void         TGQt::SetClassHints(Window_t, char *, char *)
02092  {
02093     // Sets the windows class and resource name.
02094 #ifdef QTDEBUG
02095     fprintf(stderr,"No implementation: TGQt::SetClassHints(Window_t, char *, char *)\n");
02096 #endif
02097  }
02098 //______________________________________________________________________________
02099  void         TGQt::SetMWMHints(Window_t id, UInt_t /*value*/, UInt_t /*funcs*/,
02100                             UInt_t /*input*/)
02101  {
02102     // Sets decoration style.
02103     // Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
02104 //---- MWM hints stuff
02105 // These constants werer broowed from TGFrame.h to avoid circular depemdency.
02106 // The right place for them is sopmewhere in "base" (guitype.h for example)
02107 enum EMWMHints {
02108    // functions
02109    kMWMFuncAll      = BIT(0),
02110    kMWMFuncResize   = BIT(1),
02111    kMWMFuncMove     = BIT(2),
02112    kMWMFuncMinimize = BIT(3),
02113    kMWMFuncMaximize = BIT(4),
02114    kMWMFuncClose    = BIT(5),
02115 
02116    // input mode
02117    kMWMInputModeless                = 0,
02118    kMWMInputPrimaryApplicationModal = 1,
02119    kMWMInputSystemModal             = 2,
02120    kMWMInputFullApplicationModal    = 3,
02121 
02122    // decorations
02123    kMWMDecorAll      = BIT(0),
02124    kMWMDecorBorder   = BIT(1),
02125    kMWMDecorResizeH  = BIT(2),
02126    kMWMDecorTitle    = BIT(3),
02127    kMWMDecorMenu     = BIT(4),
02128    kMWMDecorMinimize = BIT(5),
02129    kMWMDecorMaximize = BIT(6)
02130 };
02131 
02132    //MWMHintsProperty_t prop;
02133 
02134    //prop.fDecorations = value;
02135    //prop.fFunctions   = funcs;
02136    //prop.fInputMode   = input;
02137    //prop.fFlags       = kMWMHintsDecorations |
02138    //                    kMWMHintsFunctions   |
02139    //                    kMWMHintsInputMode;
02140 
02141    //XChangeProperty(fDisplay, (Window) id, gMOTIF_WM_HINTS, gMOTIF_WM_HINTS, 32,
02142    //                PropModeReplace, (UChar_t *)&prop, kPropMWMHintElements);
02143 
02144     if (id == kNone || id == kDefault ) return;
02145     // QSizePolicy  thisPolicy = wid(id)->sizePolicy ();
02146     // wid(id)->setSizePolicy ( thisPolicy );
02147 #ifdef QTDEBUG
02148     fprintf(stderr,"No implementation: TGQt::SetMWMHints(Window_t, UInt_t, UInt_t, UInt_t)\n");
02149 #endif
02150  }
02151 //______________________________________________________________________________
02152 void TGQt::SetWMPosition(Window_t id, Int_t x, Int_t y)
02153 {
02154    // Tells the window manager the desired position [x,y] of window "id".
02155    if (id == kNone || id == kDefault ) return;
02156 #ifdef QTDEBUG
02157    fprintf(stderr,"No implementation: TGQt::SetWMPosition(Window_t id, Int_t x=%d, Int_t y=%d\n",x,y);
02158 #endif
02159    wid(id)->move(x,y);
02160 }
02161 //______________________________________________________________________________
02162 void TGQt::SetWMSize(Window_t id, UInt_t w, UInt_t h)
02163 {
02164    // Tells window manager the desired size of window "id".
02165    //
02166    // w - the width
02167    // h - the height
02168    if (id == kNone || id == kDefault ) return;
02169   // vf to review QSizePolicy  thisPolicy = wid(id)->sizePolicy ();
02170    wid(id)->setBaseSize(int(w),int(h));
02171   // fprintf(stderr,"No implementation: TGQt::SetWMSize(Window_t id, UInt_t w=%d, UInt_t h=%d\n",w,h);
02172   // SafeCallW32(id)->W32_Rescale(id,w, h);
02173   // wid(id)->setSizePolicy(thisPolicy);
02174 }
02175 //______________________________________________________________________________
02176  void         TGQt::SetWMSizeHints(Window_t id, UInt_t wmin, UInt_t hmin,
02177                                UInt_t wmax, UInt_t hmax,
02178                                UInt_t winc, UInt_t hinc)
02179 {
02180    // Gives the window manager minimum and maximum size hints of the window
02181    // "id". Also specify via "winc" and "hinc" the resize increments.
02182    //
02183    // wmin, hmin - specify the minimum window size
02184    // wmax, hmax - specify the maximum window size
02185    // winc, hinc - define an arithmetic progression of sizes into which
02186    //              the window to be resized (minimum to maximum)
02187     if (id == kNone || id == kDefault ) return;
02188     QWidget &w = *wid(id);
02189     w.setMinimumSize  ( int(wmin), int(hmin) );
02190     w.setMaximumSize  ( int(wmax), int(hmax) );
02191     w.setSizeIncrement( int(winc), int(hinc) );
02192  }
02193 //______________________________________________________________________________
02194  void         TGQt::SetWMState(Window_t id, EInitialState /*state*/)
02195 {
02196    // Sets the initial state of the window "id": either kNormalState
02197    // or kIconicState.
02198     if (id == kNone || id == kDefault ) return;
02199 #ifdef QTDEBUG
02200         fprintf(stderr,"No implementation: TGQt::SetWMState( . . . )\n");
02201 #endif
02202  }
02203 //______________________________________________________________________________
02204 void   TGQt::SetWMTransientHint(Window_t id, Window_t /*main_id*/ )
02205 {
02206    // Tells window manager that the window "id" is a transient window
02207    // of the window "main_id". A window manager may decide not to decorate
02208    // a transient window or may treat it differently in other ways.
02209     if (id == kNone || id == kDefault ) return;
02210 #ifdef QTDEBUG
02211     fprintf(stderr,"No implementation: TGQt::SetWMTransientHint( . . . )\n");
02212 #endif
02213  }
02214 //______________________________________________________________________________
02215 void  TGQt::DrawString(Drawable_t id, GContext_t gc, Int_t x, Int_t y,
02216                                    const char *s, Int_t len)
02217 {
02218    // Draw a string using a specific graphics context in position (x,y)
02219    if (id == kNone) return;
02220 
02221    if (s && s[0] && len) {
02222       TQtPainter paint(iwid(id),qtcontext(gc));
02223       //   Pick the font from the context 
02224       QPalette pl =  qtcontext(gc).palette();
02225       const QColor &fontColor = pl.color(QPalette::WindowText);
02226       paint.setPen(fontColor);
02227       paint.setBrush(fontColor);
02228       if (qtcontext(gc).fFont)  paint.setFont(*qtcontext(gc).fFont);
02229       // fprintf(stderr,"TGQt::DrawString  \"%s\":%d with color %s\n",s,len,(const char *)fontColor.name());
02230       paint.drawText (x, y,  GetTextDecoder()->toUnicode(s).left(len));
02231    }
02232 }
02233 //______________________________________________________________________________
02234 Int_t TGQt::TextWidth(FontStruct_t font, const char *s, Int_t len)
02235 {
02236    // Return lenght of string in pixels. Size depends on font.
02237 
02238    Int_t textWidth = 0;
02239    if (len >0 && s && s[0] != 0 ) {
02240       QFontMetrics metric(*(QFont *)font);
02241       char* str = new char[len+1];
02242       memcpy(str,s,len); str[len]=0;
02243       QString qstr(s);
02244       delete [] str;
02245       textWidth = metric.width(qstr,len);
02246       // fprintf(stderr," TGQt::TextWidth  %d %d <%s> \n", textWidth, len, (const char *)qstr);
02247    }
02248    return textWidth;
02249 }
02250 //______________________________________________________________________________
02251 void TGQt::GetFontProperties(FontStruct_t fs, Int_t &max_ascent, Int_t &max_descent)
02252 {
02253    // The ascent of a font is the distance from the baseline
02254    //            to the highest position characters extend to.
02255    // The descent is the distance from the base line to the
02256    //             lowest point characters extend to
02257    //             (Note that this is different from X, which adds 1 pixel.)
02258    QFontMetrics metrics(*(QFont *)fs);
02259    max_ascent  = metrics.ascent ();
02260    max_descent = metrics.descent();
02261 }
02262 //______________________________________________________________________________
02263  void TGQt::GetGCValues(GContext_t  gc, GCValues_t &gval)
02264  {
02265     // Get current values from graphics context gc. Which values of the
02266     // context to get is encoded in the GCValues::fMask member. If fMask = 0
02267     // then copy all fields.
02268 
02269     assert(gval.fMask == kGCFont);
02270     gval.fFont = (FontStruct_t)qtcontext(gc).fFont;
02271  }
02272 //______________________________________________________________________________
02273  FontStruct_t TGQt::GetFontStruct(FontH_t fh) { return (FontStruct_t)fh; }
02274 //______________________________________________________________________________
02275 void         TGQt::ClearWindow(Window_t id)
02276 {
02277    // Clear window.
02278    if (id == kNone || id == kDefault ) return;
02279    QPainter paint(iwid(id));   
02280    paint.setBackgroundMode( Qt::OpaqueMode); // Qt::TransparentMode
02281    TQtClientWidget *wd =  dynamic_cast<TQtClientWidget*>(wid(id));
02282    const QColor  *c = 0;
02283    const QPixmap *p = 0;
02284 #if QT_VERSION < 0x50000
02285    c = wd ? wd->fEraseColor  : 0;
02286    p = wd ? wd->fErasePixmap : 0;
02287    const QColor  &cr = *c;
02288    const QPixmap &pr = *p;
02289 #else
02290    const QColor  &cr = wd ? wd->palette().color(QPalette::Window) : *c;
02291    c = wd ? &cr : 0;
02292    const QPixmap &pr = *p;
02293 #endif      
02294    if (p && c ) 
02295       paint.fillRect(wd->rect(),QBrush(cr,pr));
02296    else if (p)
02297       paint.fillRect(wd->rect(),QBrush(pr));
02298    else if (c)
02299       paint.fillRect(wd->rect(), cr);
02300    else {
02301       const QBrush  &brw = wd->palette().brush(QPalette::Window);
02302       paint.fillRect ( wd->rect(), brw);
02303    }
02304 }
02305 
02306 //---- Key symbol mapping
02307 struct KeyQSymbolMap_t {
02308    Qt::Key fQKeySym;
02309    EKeySym fKeySym;
02310 };
02311 
02312 //---- Mapping table of all non-trivial mappings (the ASCII keys map
02313 //---- one to one so are not included)
02314 
02315 static KeyQSymbolMap_t gKeyQMap[] = {
02316    {Qt::Key_Escape,    kKey_Escape},
02317    {Qt::Key_Tab,       kKey_Tab},
02318    {Qt::Key_Backtab,   kKey_Backtab},
02319    {Qt::Key_Backspace, kKey_Backspace},
02320    {Qt::Key_Return,    kKey_Return},
02321    {Qt::Key_Insert,    kKey_Insert},
02322    {Qt::Key_Delete,    kKey_Delete},
02323    {Qt::Key_Pause,     kKey_Pause},
02324    {Qt::Key_Print,     kKey_Print},
02325    {Qt::Key_SysReq,    kKey_SysReq},
02326    {Qt::Key_Home,      kKey_Home},       // cursor movement
02327    {Qt::Key_End,       kKey_End},
02328    {Qt::Key_Left,      kKey_Left},
02329    {Qt::Key_Up,        kKey_Up},
02330    {Qt::Key_Right,     kKey_Right},
02331    {Qt::Key_Down,      kKey_Down},
02332    {Qt::Key_PageUp,    kKey_Prior},
02333    {Qt::Key_PageDown,  kKey_Next},
02334    {Qt::Key_Shift,     kKey_Shift},
02335    {Qt::Key_Control,   kKey_Control},
02336    {Qt::Key_Meta,      kKey_Meta},
02337    {Qt::Key_Alt,       kKey_Alt},
02338    {Qt::Key_CapsLock,  kKey_CapsLock},
02339    {Qt::Key_NumLock ,  kKey_NumLock},
02340    {Qt::Key_ScrollLock, kKey_ScrollLock},
02341    {Qt::Key_Space,     kKey_Space},  // numeric keypad
02342    {Qt::Key_Tab,       kKey_Tab},
02343    {Qt::Key_Enter,     kKey_Enter},
02344    {Qt::Key_Equal,     kKey_Equal},
02345    {Qt::Key_F1,        kKey_F1 },
02346    {Qt::Key_F2,        kKey_F2 },
02347    {Qt::Key_F3,        kKey_F3 },
02348    {Qt::Key_F4,        kKey_F4 },
02349    {Qt::Key_PageUp,    kKey_PageUp },
02350    {Qt::Key_PageDown,  kKey_PageDown },
02351    {Qt::Key(0), (EKeySym) 0}   
02352 };
02353 //______________________________________________________________________________________
02354 static inline Int_t MapKeySym(int key, bool toQt=true)
02355 {
02356    for (int i = 0; gKeyQMap[i].fKeySym; i++) {  // any other keys
02357       if (toQt) {
02358         if (key ==  gKeyQMap[i].fKeySym ) {
02359            return   UInt_t(gKeyQMap[i].fQKeySym);
02360         }
02361       } else {
02362         if (key ==  gKeyQMap[i].fQKeySym) {
02363            return   UInt_t(gKeyQMap[i].fKeySym);
02364         }
02365       }
02366    }
02367 #if 0
02368    UInt_t text;
02369    QByteArray r = gQt->GetTextDecoder()->fromUnicode(qev.text());
02370    qstrlcpy((char *)&text, (const char *)r,1);
02371    return text;
02372 #else
02373    return key;
02374 #endif
02375 }
02376 //______________________________________________________________________________
02377  Int_t        TGQt::KeysymToKeycode(UInt_t keysym) {
02378     // Convert a keysym to the appropriate keycode. For example keysym is
02379     // a letter and keycode is the matching keyboard key (which is dependend
02380     // on the current keyboard mapping).
02381     return Int_t(MapKeySym(keysym));
02382  }
02383  //______________________________________________________________________________
02384  void TGQt::FillRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y,
02385     UInt_t w, UInt_t h)
02386  {
02387     if (id == kNone) return;
02388     // Draw a filled rectangle. Filling is done according to the gc.
02389     TQtPainter paint(iwid(id),qtcontext(gc));
02390     if (qtcontext(gc).HasValid(QtGContext::kTileRect) ) {
02391        paint.drawTiledPixmap(x,y,w,h,*qtcontext(gc).fTilePixmap);
02392     } else {
02393        if (qtcontext(gc).HasValid(QtGContext::kStipple)) {
02394           // qtcontext(gc).fBrush.setStyle(Qt::FDiagPattern);
02395           if (qtcontext(gc).HasValid(QtGContext::kBrush) ) {
02396              // paint.setPen(Qt::black);
02397              //paint.setBackgroundColor(qtcontext(gc).paletteBackgroundColor());
02398              QPalette pl =  qtcontext(gc).palette();
02399              const QColor &fontColor = pl.color(QPalette::WindowText);
02400              paint.setPen(fontColor);
02401           } else {
02402              paint.setBackground(Qt::white);
02403              paint.setPen(Qt::black);
02404           }
02405           paint.setBackgroundMode( Qt::OpaqueMode); // Qt::TransparentMode
02406        }
02407        // Workaround of the bug in the TGContainer::DrawRegion
02408        if (qtcontext(gc).fBrush.style() == Qt::NoBrush) qtcontext(gc).fBrush.setStyle(Qt::SolidPattern);
02409        paint.fillRect ( x, y, w, h, qtcontext(gc).fBrush );
02410     }
02411  }
02412  //______________________________________________________________________________
02413  void TGQt::DrawRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y,
02414     UInt_t w, UInt_t h)
02415  {
02416     if (id == kNone) return;
02417     // Draw a rectangle outline.
02418     TQtPainter paint(iwid(id),qtcontext(gc));
02419     paint.setBrush(Qt::NoBrush);
02420     paint.drawRect ( x, y, w, h);
02421  }
02422  //______________________________________________________________________________
02423  void TGQt::DrawSegments(Drawable_t id, GContext_t gc, Segment_t * seg, Int_t nseg)
02424  {
02425     // Draws multiple line segments. Each line is specified by a pair of points.
02426     if (id == kNone) return;
02427     TQtPainter paint(iwid(id),qtcontext(gc));
02428     QVector<QLine> segments(nseg);
02429     for (int i=0;i<nseg;i++)
02430        segments.push_back(QLine(seg[i].fX1, seg[i].fY1,seg[i].fX2, seg[i].fY2));
02431     paint.drawLines (segments);
02432  }
02433 //______________________________________________________________________________
02434  void         TGQt::SelectInput(Window_t id, UInt_t evmask)
02435  {
02436    // Defines which input events the window is interested in. By default
02437    // events are propageted up the window stack. This mask can also be
02438    // set at window creation time via the SetWindowAttributes_t::fEventMask
02439    // attribute.
02440 
02441    // UInt_t xevmask;
02442 
02443    //MapEventMask(evmask, xevmask);
02444 
02445    //XSelectInput(fDisplay, (Window) id, xevmask);
02446 
02447        //The XSelectInput function requests that the X server
02448        //report the events associated with the specified event
02449        //mask.  Initially, X will not report any of these events.
02450        //Events are reported relative to a window.  If a window is
02451        //not interested in a device event, it usually propagates to
02452        //the closest ancestor that is interested, unless the
02453        //do_not_propagate mask prohibits it.
02454 
02455        //Setting the event-mask attribute of a window overrides any
02456        //previous call for the same window but not for other
02457        //clients.  Multiple clients can select for the same events
02458        //on the same window with the following restrictions:
02459 
02460        //·    Multiple clients can select events on the same window
02461        //     because their event masks are disjoint.  When the X
02462        //     server generates an event, it reports it to all
02463        //     interested clients.
02464 
02465        //·    Only one client at a time can select Circu­
02466        //     lateRequest, ConfigureRequest, or MapRequest events,
02467        //     which are associated with the event mask Substructur­
02468        //     eRedirectMask.
02469 
02470        //·    Only one client at a time can select a ResizeRequest
02471        //     event, which is associated with the event mask Resiz­
02472        //     eRedirectMask.
02473 
02474        //·    Only one client at a time can select a ButtonPress
02475        //     event, which is associated with the event mask But­
02476        //     tonPressMask.
02477 
02478        //The server reports the event to all interested clients.
02479 
02480 //       QClientFilter()->RemovePointerGrab(0);
02481     ((TQtClientWidget*)wid(id))->SelectInput(evmask);
02482 }
02483 //______________________________________________________________________________
02484 Window_t  TGQt::GetInputFocus()
02485 {
02486    // Returns the window id of the window having the input focus.
02487    TQtClientWidget *focus = 0;
02488    QWidget *f = qApp->focusWidget ();
02489    if (f) {
02490      focus = dynamic_cast<TQtClientWidget*>(f);
02491      if (!focus) return 0;
02492    }
02493    return wid(focus);
02494 }
02495 //______________________________________________________________________________
02496  void         TGQt::SetInputFocus(Window_t id)
02497  {
02498    // Set keyboard input focus to window id.
02499     if (id == kNone || id == kDefault ) return;
02500     wid(id)->setFocus ();
02501  }
02502 //______________________________________________________________________________
02503 void         TGQt::LookupString(Event_t *ev, char *tmp, Int_t /*n*/, UInt_t &keysym)
02504 {
02505     // Convert the keycode from the event structure to a key symbol (according
02506     // to the modifiers specified in the event structure and the current
02507     // keyboard mapping). In buf a null terminated ASCII string is returned
02508     // representing the string that is currently mapped to the key code.
02509 
02510     keysym = ev->fCode;
02511     // we have to accomodate the new ROOT GUI logic.
02512     // the information about the "ctrl" key should provided TWICE nowadays 12.04.2005 vf.
02513     if (ev->fState & kKeyControlMask) keysym -= keysym > 'Z' ? 96 :64;
02514 //    if (ev->fState & kKeyControlMask) if (isupper(keysym)) keysym += 32;
02515     *tmp = keysym; tmp++;
02516     *tmp = '\0';
02517 }
02518 //______________________________________________________________________________
02519 void         TGQt::TranslateCoordinates(Window_t src, Window_t dest,
02520                                    Int_t src_x, Int_t src_y,
02521                                    Int_t & dest_x, Int_t & dest_y,
02522                                    Window_t & child)
02523 {
02524    // TranslateCoordinates translates coordinates from the frame of
02525    // reference of one window to another. If the point is contained
02526    // in a mapped child of the destination, the id of that child is
02527    // returned as well.
02528    QWidget *wSrc = wid(src);
02529    QWidget *wDst = wid(dest);
02530    child = kNone;
02531    //Local variables to keep the dest coordinates
02532    Int_t  destX;
02533    Int_t  destY;
02534 
02535    if (!wSrc) wSrc = QApplication::desktop();
02536    if (!wDst) wDst = QApplication::desktop();
02537    assert(wSrc && wDst);
02538    if (src == dest) {
02539       destX = src_x; destY= src_y;
02540    } else {
02541       QPoint mapped = wDst->mapFromGlobal(wSrc->mapToGlobal(QPoint(src_x,src_y)));
02542       destX = mapped.x(); destY = mapped.y();
02543    }
02544    TQtClientWidget* tmpW = dynamic_cast<TQtClientWidget*>(wDst->childAt ( destX, destY));
02545    if (tmpW) {
02546       child = wid(tmpW);
02547    }
02548    dest_x = destX; dest_y = destY;
02549    // fprintf(stderr," Translate the  coordinate src %d %d, dst %d %d; child = %d \n", src_x, src_y, dest_x, dest_y, child);
02550  }
02551 //______________________________________________________________________________
02552 void         TGQt::GetWindowSize(Drawable_t id, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
02553 {
02554    // Return geometry of window (should be called GetGeometry but signature
02555    // already used).
02556    
02557    x =  y = 0;
02558    if (id == kNone || id == kDefault )
02559    {
02560       QDesktopWidget *d = QApplication::desktop();
02561       w = d->width();   // returns desktop width
02562       h = d->height();  // returns desktop height
02563    } else {
02564          QPixmap *thePix = dynamic_cast<QPixmap*>(iwid(id) );
02565          if (thePix) {
02566 //            *fQPixmapGuard.Pixmap(pix)
02567             w = thePix->width();     // returns pixmap width
02568             h = thePix->height();    // returns pixmap height
02569          } else {
02570             TQtClientWidget* theWidget = dynamic_cast<TQtClientWidget*>( wid(id) );
02571             if (theWidget) {
02572                const QRect &gWidget=theWidget->frameGeometry ();
02573                // theWidget->dumpObjectInfo () ;
02574                x = gWidget.x();
02575                y = gWidget.y();
02576                w = gWidget.width();
02577                h = gWidget.height();
02578             } else {         
02579                QDesktopWidget *d = QApplication::desktop();
02580                w = d->width();     // returns desktop width
02581                h = d->height();    // returns desktop height
02582             }
02583          }
02584      }
02585  }
02586 //______________________________________________________________________________
02587 void  TGQt::FillPolygon(Window_t id, GContext_t gc, Point_t *points, Int_t npnt)
02588 {
02589    // FillPolygon fills the region closed by the specified path.
02590    // The path is closed automatically if the last point in the list does
02591    // not coincide with the first point. All point coordinates are
02592    // treated as relative to the origin. For every pair of points
02593    // inside the polygon, the line segment connecting them does not
02594    // intersect the path.
02595    if (id == kNone) return;
02596    if (npnt > 1) {
02597       TQtPainter paint(iwid(id),qtcontext(gc));
02598 #if QT_VERSION < 0x40000
02599       QPointArray pa(npnt);
02600 #else /* QT_VERSION */
02601       QPolygon pa(npnt);
02602 #endif /* QT_VERSION */
02603       Int_t x = points[0].fX;
02604       Int_t y = points[0].fY;
02605       pa.setPoint(0,x,y);
02606       for (int i=1;i<npnt;i++)  pa.setPoint(i,points[i].fX,points[i].fY);
02607       paint.drawConvexPolygon (pa);
02608    }
02609 }
02610 //______________________________________________________________________________
02611 void  TGQt::QueryPointer(Window_t id, Window_t &rootw, Window_t &childw,
02612                         Int_t &root_x, Int_t &root_y, Int_t &win_x,
02613                         Int_t &win_y, UInt_t &mask)
02614 {
02615    //Returns the position of the cursor (hot spot) in global screen coordinates
02616    if (id == kNone) return;
02617 
02618    QPoint position     = QCursor::pos();
02619    QWidget *thisWidget = wid(id);
02620    QWidget *topWiget   = thisWidget->topLevelWidget();
02621 
02622    // Returns the root window the pointer is logically on and the pointer
02623    // coordinates relative to the root window's origin.
02624    QPoint rootPosition = topWiget->mapFromGlobal( position );
02625    root_x = rootPosition.x(); root_y = rootPosition.y();
02626    rootw  = rootwid(topWiget);
02627 
02628    // The pointer coordinates returned to win_x and win_y are relative to
02629    // the origin of the specified window.
02630    QPoint win_pos = thisWidget->mapFromGlobal( position );
02631    win_x = win_pos.x(); win_y = win_pos.y();
02632 
02633    TQtClientWidget *ch = (TQtClientWidget * )thisWidget->childAt (win_x,win_y);
02634    childw = ch ? wid(ch): kNone;
02635 
02636    // QueryPointer returns the current logical state of the
02637    // keyboard buttons and the modifier keys in mask.
02638 
02639 //> Can you say whether it is possible to query the current button state
02640 //> (Qt::ButtonState ) with no QMouseEvent?
02641 //
02642 //I am afraid that this is not possible using Qt, you will need to use
02643 //platform dependent code to do this I am afraid.
02644 //
02645 //Have a nice day!
02646 //
02647 //Andy
02648 //--
02649 //Technicial Support Technician
02650 //Trolltech AS, Waldemar Thranes gate 98, NO-0175 Oslo, Norway
02651 
02652    mask = 0;
02653 }
02654 //______________________________________________________________________________
02655 void         TGQt::SetBackground(GContext_t gc, ULong_t background)
02656 {
02657    // Set foreground color in graphics context (shortcut for ChangeGC with
02658    // only foreground mask set).
02659    // The interface is confusing . This function MUST be not here (VF 07/07/2003)
02660    
02661    qtcontext(gc).SetBackground(background);
02662 }
02663 
02664 //______________________________________________________________________________
02665 void         TGQt::SetForeground(GContext_t gc, ULong_t foreground)
02666 {
02667    // Set foreground color in graphics context (shortcut for ChangeGC with
02668    // only foreground mask set).
02669    // The interface is confusing . This function MUST be not here (VF 07/07/2003)
02670    
02671    qtcontext(gc).SetForeground(foreground);
02672 }
02673 //______________________________________________________________________________
02674 void         TGQt::SetClipRectangles(GContext_t gc, Int_t x, Int_t y,
02675                                     Rectangle_t * recs, Int_t n)
02676 {
02677    // Set clipping rectangles in graphics context. X, Y specify the origin
02678    // of the rectangles. Recs specifies an array of rectangles that define
02679    // the clipping mask and n is the number of rectangles.
02680    // Rectangle structure (maps to the X11 XRectangle structure)
02681    if (n <=0 ) return;
02682    Region_t clip  = CreateRegion();
02683    for (int i=0;i<n;i++)
02684       UnionRectWithRegion(recs,clip,clip);
02685    ((QRegion *)clip)->translate(x,y);
02686    qtcontext(gc).fClipRegion = *(QRegion *)clip;
02687    SETBIT(qtcontext(gc).fMask,QtGContext::kClipRegion);
02688    DestroyRegion(clip);
02689 }
02690 //______________________________________________________________________________
02691 void         TGQt::Update(Int_t mode)
02692 {
02693    // Flush (mode = 0, default) or synchronize (mode = 1) X output buffer.
02694    // Flush flushes output buffer. Sync flushes buffer and waits till all
02695    // requests have been processed by X server.
02696    if (mode)
02697 #ifdef R__QTX11
02698       QApplication::syncX (); else
02699 #else
02700       {}
02701 #endif
02702       QApplication::flush ();
02703 }
02704 //------------------------------------------------------------------------------
02705 //
02706 //  Region functions. Using QRegion instead of X-Window regions.
02707 //  Event though they are static "by nature".
02708 //  We can not make them static because they are virtual ones.
02709 //  Written by Yuri
02710 
02711 //______________________________________________________________________________
02712 Region_t TGQt::CreateRegion()
02713 {
02714    // Create a new empty region.
02715 
02716    QRegion *reg = new QRegion();
02717    return (Region_t) reg;
02718 }
02719 //______________________________________________________________________________
02720 void TGQt::DestroyRegion(Region_t reg)
02721 {
02722    // Destroy region.
02723 
02724    delete (QRegion*) reg;
02725 }
02726 //______________________________________________________________________________
02727 void TGQt::UnionRectWithRegion(Rectangle_t *rect, Region_t src, Region_t dest)
02728 {
02729    // Union of rectangle with a region.
02730 
02731    if( !rect || src == 0 || dest == 0 )
02732       return;
02733 
02734    QRegion rc(QRect( rect->fX, rect->fY, rect->fWidth, rect->fHeight ));
02735    QRegion &rSrc  = *(QRegion*) src;
02736    QRegion &rDest = *(QRegion*) dest;
02737 
02738    rDest = rSrc + rc;
02739 }
02740 //______________________________________________________________________________
02741 Region_t TGQt::PolygonRegion(Point_t *points, Int_t np, Bool_t winding)
02742 {
02743    // Create region for the polygon defined by the points array.
02744    // If winding is true use WindingRule else EvenOddRule as fill rule.
02745    if( np<0 || !points )
02746       return 0;
02747 
02748    QPolygon pa;
02749    pa.resize( np );
02750    for(int i=0; i<np; i++)
02751       pa.setPoint( i, points[i].fX, points[i].fY );
02752 
02753    return (Region_t) new QRegion( pa, winding?Qt::WindingFill:Qt::OddEvenFill  );
02754 }
02755 //______________________________________________________________________________
02756 void TGQt::UnionRegion(Region_t rega, Region_t regb, Region_t result)
02757 {
02758    // Compute the union of rega and regb and return result region.
02759    // The output region may be the same result region.
02760 
02761    if( !rega || !regb || !result )
02762       return;
02763 
02764    QRegion& a = *(QRegion*) rega;
02765    QRegion& b = *(QRegion*) regb;
02766    QRegion& r = *(QRegion*) result;
02767 
02768    r = a + b;
02769 }
02770 //______________________________________________________________________________
02771 void TGQt::IntersectRegion(Region_t rega, Region_t regb, Region_t result)
02772 {
02773    // Compute the intersection of rega and regb and return result region.
02774    // The output region may be the same as the result region.
02775 
02776         if( !rega || !regb || !result )
02777                 return;
02778 
02779         QRegion& a = *(QRegion*) rega;
02780         QRegion& b = *(QRegion*) regb;
02781         QRegion& r = *(QRegion*) result;
02782 
02783         r = a & b;
02784 }
02785 //______________________________________________________________________________
02786 void TGQt::SubtractRegion(Region_t rega, Region_t regb, Region_t result)
02787 {
02788    // Subtract rega from regb.
02789 
02790    if( !rega || !regb || !result )
02791       return;
02792 
02793    QRegion& a = *(QRegion*) rega;
02794    QRegion& b = *(QRegion*) regb;
02795    QRegion& r = *(QRegion*) result;
02796 
02797    r = a - b;
02798 }
02799 //______________________________________________________________________________
02800 void TGQt::XorRegion(Region_t rega, Region_t regb, Region_t result)
02801 {
02802    // Calculate the difference between the union and intersection of
02803    // two regions.
02804    if( !rega || !regb || !result )
02805       return;
02806 
02807    QRegion& a = *(QRegion*) rega;
02808    QRegion& b = *(QRegion*) regb;
02809    QRegion& r = *(QRegion*) result;
02810 
02811    r = a ^ b;
02812 }
02813 //______________________________________________________________________________
02814 Bool_t TGQt::EmptyRegion(Region_t reg)
02815 {
02816    // Return true if the region is empty.
02817 
02818    if( !reg )
02819                 return true;
02820 
02821         QRegion& r = *(QRegion*) reg;
02822 
02823         return r.isEmpty();
02824 }
02825 //______________________________________________________________________________
02826 Bool_t TGQt::PointInRegion(Int_t x, Int_t y, Region_t reg)
02827 {
02828    // Returns true if the point x,y is in the region.
02829         if( !reg )
02830                 return false;
02831 
02832         QRegion& r = *(QRegion*) reg;
02833         return r.contains( QPoint(x, y) );
02834 }
02835 //______________________________________________________________________________
02836 Bool_t TGQt::EqualRegion(Region_t rega, Region_t regb)
02837 {
02838    // Returns true if two regions are equal.
02839 
02840    if( !rega || !regb )
02841       return false;
02842 
02843    QRegion& a = *(QRegion*) rega;
02844    QRegion& b = *(QRegion*) regb;
02845 
02846    return (a == b);
02847 }
02848 //______________________________________________________________________________
02849 void TGQt::GetRegionBox(Region_t reg, Rectangle_t *rect)
02850 {
02851    // Return smallest enclosing rectangle.
02852 
02853         if( !reg || !rect )
02854                 return;
02855 
02856         QRegion& r = *(QRegion*) reg;
02857         QRect rc   = r.boundingRect();
02858 
02859         rect->fX      = rc.x();
02860         rect->fY      = rc.y();
02861         rect->fWidth  = rc.width();
02862         rect->fHeight = rc.height();
02863 }
02864 //______________________________________________________________________________
02865 char **TGQt::ListFonts(const char *fontname, Int_t max, Int_t &count)
02866 {
02867    // Returns list of font names matching fontname regexp, like "-*-times-*".
02868    // The pattern string can contain any characters, but each asterisk (*)
02869    // is a wildcard for any number of characters, and each question mark (?)
02870    // is a wildcard for a single character. If the pattern string is not in
02871    // the Host Portable Character Encoding, the result is implementation
02872    // dependent. Use of uppercase or lowercase does not matter. Each returned
02873    // string is null-terminated.
02874    //
02875    // fontname - specifies the null-terminated pattern string that can
02876    //            contain wildcard characters
02877    // max      - specifies the maximum number of names to be returned
02878    // count    - returns the actual number of font names
02879 
02880    // ------------------------------------------------------
02881    //  ROOT uses non-portable XLDF font description:
02882    //  XLFD 
02883    // ------------------------------------------------------
02884 
02885    // The X Logical Font Descriptor (XLFD) is a text string made up of 13 parts 
02886    // separated by a minus sign, i.e.: 
02887    // 
02888    // -Misc -Fixed    -Medium-R-Normal-13-120-75-75-C-70-ISO8859-1 
02889    // -Adobe-Helvetica-Medium-R-Normal-12-120-75-75-P-67-ISO8859-1 
02890    // ------------------------------------------------------------
02891    // 
02892    // FOUNDRY 
02893    // text name of font creator 
02894    // 
02895    // FAMILY_NAME 
02896    // name of the font. Related fonts generally have the same base names; i.e. helvetica, helvetica narrow , etc. 
02897    
02898    // WEIGHT_NAME 
02899    // usually one of [light|medium|demibold|bold] but other types may exist 
02900    // 
02901    // SLANT 
02902    // one of [r|i|o]. i and o are used similarly, AFAIK 
02903    // 
02904    // SETWIDTH_NAME 
02905    // [normal|condensed|narrow|double wide] 
02906    // 
02907    // ADD_STYLE_NAME 
02908    // not a classification field, used only for additional differentiation 
02909    //
02910    // PIXEL_SIZE 
02911    // 0 = scalable font; integer typicially height of bounding box 
02912    //
02913    // POINT_SIZE 
02914    // typically height of bounding box in tenths of pixels 
02915    // 
02916    // RESOLUTION_X 
02917    // horizontal dots per inch 
02918    // 
02919    // RESOLUTION_Y 
02920    // vertical dots per inch 
02921    // 
02922    // SPACING 
02923    // [p|m|c] p = proportional, m = monospaced, c = charcell. Charcell is a special case of monospaced where no glyphs have pixels outside the character cell; i.e. there is no kerning (no negative metrics). 
02924    // 
02925    // AVERAGE_WIDTH 
02926    // unweighted arithmetic mean of absolute value of width of each glyph in tenths of pixels 
02927    // CHARSET_REGISTRY and CHARSET_ENCODING 
02928    // the chararterset used to encode the font; ISO8859-1 for Latin 1 fonts
02929    
02930    //  Check whether "Symbol" font is available
02931     count = 0;
02932     TXlfd  patternFont(fontname);
02933     QFontDatabase fdb;
02934     QStringList xlFonts;
02935     QStringList families = fdb.families();
02936     for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
02937         QString family = *f;
02938         QStringList styles = fdb.styles( family );
02939         for ( QStringList::Iterator s = styles.begin(); s != styles.end(); ++s ) {
02940             QString style = *s;
02941             // fprintf(stderr," family %s style = %s\n", (const char *)family, (const char *) style);
02942             Int_t bold   = fdb.bold  (family, style);
02943             Int_t italic = fdb.italic(family, style);
02944             TXlfd currentFont(family,bold,italic);
02945             if (currentFont != patternFont) continue;
02946             
02947             QList<int> sizes = fdb.pointSizes( family, style );
02948             for ( int points=0 ;  points < sizes.size()
02949                                  && (Int_t)xlFonts.size() < max; ++points ) 
02950             {
02951               currentFont.SetPointSize(sizes[points]);
02952               if (currentFont ==  patternFont )  xlFonts.push_back(currentFont.ToString());
02953             }
02954         }
02955     }
02956     count = xlFonts.size();
02957     char **listFont = 0;
02958     if (count) {
02959        char **list = listFont = new char*[count+1];  list[count] = 0;
02960        for ( QStringList::Iterator it = xlFonts.begin(); it != xlFonts.end(); ++it ) {
02961           int fntln = (*it).length();
02962           char *nextFont = new char[fntln+1];
02963           *list = nextFont; list++;
02964           memcpy(nextFont,(*it).toStdString().c_str(),fntln);
02965           nextFont[fntln]=0;
02966        }
02967     }
02968     return listFont;
02969 }
02970 
02971 //______________________________________________________________________________
02972 void TGQt::FreeFontNames(char ** fontlist)
02973 {
02974    // Frees the specified the array of strings "fontlist".
02975 //   fprintf(stderr,"No implementation: TGQt::FreeFontNames\n");
02976    char ** list =  fontlist;
02977    while (*list) {  delete [] *list; list++;  }
02978    delete [] fontlist;
02979 }
02980 
02981 //______________________________________________________________________________
02982 Drawable_t TGQt::CreateImage(UInt_t width, UInt_t height)
02983 {
02984    // Allocates the memory needed for an drawable.
02985    //
02986    // width  - the width of the image, in pixels
02987    // height - the height of the image, in pixels
02988 
02989    QImage *image = new QImage(width,height,QImage::Format_ARGB32);
02990    return Drawable_t(image);
02991 }
02992 
02993 //______________________________________________________________________________
02994 void TGQt::GetImageSize(Drawable_t id, UInt_t &width, UInt_t &height)
02995 {
02996    // Returns the width and height of the image id
02997    QImage *image = (QImage *)id;
02998    if (image) {
02999       width  = image->width();
03000       height = image->height();
03001    }
03002 }
03003 
03004 //______________________________________________________________________________
03005 void TGQt::PutPixel(Drawable_t id, Int_t x, Int_t y, ULong_t pixel)
03006 {
03007    // Overwrites the pixel in the image with the specified pixel value.
03008    // The image must contain the x and y coordinates.
03009    //
03010    // id    - specifies the image
03011    // x, y  - coordinates
03012    // pixel - the new pixel value
03013    //
03014    QImage *image = (QImage *)id;
03015    if (image) image->setPixel(x,y,QtColor(pixel).rgb());
03016 }
03017 
03018 //______________________________________________________________________________
03019 void TGQt::PutImage(Drawable_t id, GContext_t gc,Drawable_t img, Int_t dx, Int_t dy,
03020                          Int_t x, Int_t y, UInt_t w, UInt_t h)
03021 {
03022    // Combines an image with a rectangle of the specified drawable. The
03023    // section of the image defined by the x, y, width, and height arguments
03024    // is drawn on the specified part of the drawable.
03025    //
03026    // id   - the drawable
03027    // gc   - the GC
03028    // img  - the image you want combined with the rectangle
03029    // dx   - the offset in X from the left edge of the image
03030    // dy   - the offset in Y from the top edge of the image
03031    // x, y - coordinates, which are relative to the origin of the
03032    //        drawable and are the coordinates of the subimage
03033    // w, h - the width and height of the subimage, which define the
03034    //        rectangle dimensions
03035    //
03036    // GC components in use: function, plane-mask, subwindow-mode,
03037    // clip-x-origin, clip-y-origin, and clip-mask.
03038    // GC mode-dependent components: foreground and background.
03039    // (see also the GCValues_t structure)
03040     const QImage *image = (QImage *)img;
03041     if (image) {
03042        TQtPainter pnt(iwid(id),qtcontext(gc));
03043        Qt::ImageConversionFlag conversionFlags=Qt::AutoColor;
03044        pnt.drawImage(dx,dy, *image, x,y,w,h,conversionFlags);
03045        //   Qt::ImageConversionFlags
03046        //   The conversion flag is a bitwise-OR of the following values.
03047        //   The options marked "(default)" are set if no other values
03048        //   from the list are included (since the defaults are zero):
03049        //  --  Color/Mono preference (ignored for QBitmap)  --
03050        //      Qt::AutoColor - (default) - If the image has depth 1 and
03051        //                      contains only black and white pixels, the
03052        //                      pixmap becomes monochrome.
03053        //      Qt::ColorOnly - The pixmap is dithered/converted to the native
03054        //                      display depth.
03055        //      Qt::MonoOnly -  The pixmap becomes monochrome. If necessary, it
03056        //                      is dithered using the chosen dithering algorithm.
03057        //
03058        //  --  Dithering mode preference for RGB channels  --
03059        //      Qt::DiffuseDither   - (default) - A high-quality dither.
03060        //      Qt::OrderedDither   - A faster, more ordered dither.
03061        //      Qt::ThresholdDither - No dithering; closest color is used.
03062        //
03063        //  --  Dithering mode preference for alpha channel
03064        //      Qt::ThresholdAlphaDither - (default) - No dithering.
03065        //      Qt::OrderedAlphaDither   - A faster, more ordered dither.
03066        //      Qt::DiffuseAlphaDither   - A high-quality dither.
03067        //      Qt::NoAlpha              - Not supported.
03068        //
03069        //  --  Color matching versus dithering preference
03070        //      Qt::PreferDither - (default when converting to a pixmap)
03071        //                         - Always dither 32-bit images when the image
03072        //                           is converted to 8 bits.
03073        //      Qt::AvoidDither  - (default when converting for the purpose of saving to file)
03074        //                         - Dither 32-bit images only if the image
03075        //                           has more than 256 colors and it is being converted to 8 bits.
03076        //      Qt::AutoDither   - Not supported.
03077        //
03078        //  --  The following are not values that are used directly, but masks for the above classes:
03079        //      Qt::ColorMode_Mask   - Mask for the color mode.
03080        //      Qt::Dither_Mask      - Mask for the dithering mode for RGB channels.
03081        //      Qt::AlphaDither_Mask - Mask for the dithering mode for the alpha channel.
03082        //      Qt::DitherMode_Mask  - Mask for the mode that determines the preference of color
03083        //                             matching versus dithering.
03084        //
03085        //Using 0 as the conversion flag sets all the default options.
03086     }
03087 }
03088 
03089 //______________________________________________________________________________
03090 void TGQt::DeleteImage(Drawable_t img)
03091 {
03092    // Deallocates the memory associated with the image img
03093    delete (QImage *)img;
03094 }
03095 
03096 #if ROOT_VERSION_CODE < ROOT_VERSION(4,01,02)
03097 //______________________________________________________________________________
03098 ULong_t TGQt::GetWinDC(Window_t wind)
03099 {
03100    // Returns HDC.
03101    return (wind == kNone) ? 0 :  ULong_t(wid(wind)->handle());
03102 }
03103 #endif
03104 
03105 //______________________________________________________________________________
03106 Bool_t  TGQt::IsHandleValid(Window_t /*id*/)
03107 {
03108    return true;
03109 //    Bool_t ok = (id == 0) || (id == kDefault) || (Bool_t)fQClientGuard.Find(id);
03110 //    if (!ok) fprintf(stderr,"TGObject::GetId() = %ld\n",id);
03111 //    return ok;
03112 }
03113 
03114 //______________________________________________________________________________
03115 void  TGQt::SendDestroyEvent(TQtClientWidget *widget) const
03116 {
03117       // Send the ROOT kDestroyEvent via Qt event loop
03118    Event_t destroyEvent;
03119    memset(&destroyEvent,0,sizeof(Event_t));
03120    destroyEvent.fType      = kDestroyNotify;
03121    destroyEvent.fWindow    = rootwid(widget);
03122    destroyEvent.fSendEvent = kTRUE;
03123    destroyEvent.fTime      = QTime::currentTime().msec();
03124 
03125    // fprintf(stderr,"---- - - > TGQt::SendDestroyEvent %p  %ld \n", widget, wid(widget) );
03126    ((TGQt *)this)->SendEvent(TGQt::kDefault,&destroyEvent);
03127 }
03128 
03129 
03130 // -- V.Onuchine's method to back ASIMage
03131 
03132 
03133 //______________________________________________________________________________
03134 unsigned char *TGQt::GetColorBits(Drawable_t rootWid, Int_t x, Int_t y, UInt_t w, UInt_t h)
03135 {
03136    // Returns an array of pixels created from a part of drawable (defined by x, y, w, h)
03137    // in format:
03138    // b1, g1, r1, 0,  b2, g2, r2, 0 ... bn, gn, rn, 0 ..
03139    //
03140    // Pixels are numbered from left to right and from top to bottom.
03141    // By default all pixels from the whole drawable are returned.
03142    //
03143    // Note that return array is 32-bit aligned
03144 
03145    if (!rootWid  || (int(rootWid) == -1) ) return 0;
03146 
03147    QPaintDevice &dev = *iwid(rootWid);
03148    QPixmap *pix=0;
03149    switch (dev.devType()) {
03150    case QInternal::Widget:
03151      pix = ((TQtWidget*)&dev)->GetOffScreenBuffer();
03152      break;
03153 
03154    case QInternal::Pixmap: {
03155       pix = (QPixmap *)&dev;
03156       break;
03157                           }
03158    case QInternal::Picture:
03159    case QInternal::Printer:
03160    // case QInternal::UndefinedDevice:
03161    default: assert(0);
03162      break;
03163    };
03164 
03165    if (pix) {
03166       // Create intermediate pixmap to stretch the original one if any
03167       QSize imageSize;
03168       if ( (h == w) && (w == UInt_t(-1) ) ) { 
03169          w = pix->size().width(); 
03170          h = pix->size().height(); 
03171       }
03172       imageSize.setWidth(w); 
03173       imageSize.setHeight(h); 
03174       
03175       QImage img(w,h,QImage::Format_ARGB32);
03176       QPainter p(&img);
03177       p.drawPixmap(QPoint(0,0),*pix,QRect(x,y,w,h));
03178       if (!img.isNull()) {
03179          UInt_t *bits = new UInt_t[w*h];
03180          UInt_t *ibits = (UInt_t *)img.bits();
03181 
03182          int idx = y;
03183          int iii = 0;
03184          for (UInt_t j = 0; j < h; j++) {
03185             for (UInt_t i = 0; i < w; i++) {
03186                bits[iii + i] = ibits[idx + x + i];
03187             }
03188             idx += w;
03189             iii += w;
03190          }
03191          return (unsigned char *)bits;
03192       }
03193    }
03194 
03195    return 0;
03196 }
03197 
03198 
03199 //______________________________________________________________________________
03200 Pixmap_t TGQt::CreatePixmapFromData(unsigned char * bits, UInt_t width,
03201                                        UInt_t height)
03202 {
03203    // create pixmap from RGB data. RGB data is in format :
03204    // b1, g1, r1, 0,  b2, g2, r2, 0 ... bn, gn, rn, 0 ..
03205    //
03206    // Pixels are numbered from left to right and from top to bottom.
03207    // Note that data must be 32-bit aligned
03208 
03209    QImage img(bits, width, height, QImage::Format_ARGB32);
03210    QPixmap *p = new QPixmap(QPixmap::fromImage (img));
03211    fQPixmapGuard.Add(p);
03212    return Pixmap_t(rootwid(p));
03213 }
03214 
03215 //______________________________________________________________________________
03216 Window_t TGQt::GetCurrentWindow() const
03217 {
03218    // Return current/selected window pointer.
03219    fprintf(stderr, " Qt layer is not ready for GetCurrentWindow \n");
03220    assert(0);
03221 
03222    return (Window_t)(fSelectedWindow);
03223 }
03224 
03225 //______________________________________________________________________________
03226 Int_t TGQt::SupportsExtension(const char *extensionName) const 
03227  { 
03228     // Returns 1 if window system server supports extension given by the 
03229     // argument, returns 0 in case extension is not supported and returns -1 
03230     // in case of error (like server not initialized). 
03231 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,1)
03232     return   TVirtualX::SupportsExtension(extensionName);
03233 #else
03234     if (extensionName) {}
03235     return -1;
03236 #endif
03237 }
03238 
03239 //______________________________________________________________________________
03240 void TGQt::DeleteProperty(Window_t, Atom_t&)
03241 {
03242    // Deletes the specified property only if the property was defined on the 
03243    // specified window and causes the X server to generate a PropertyNotify 
03244    // event on the window unless the property does not exist.
03245 
03246 }
03247 
03248 //______________________________________________________________________________
03249 Int_t TGQt::GetProperty(Window_t, Atom_t, Long_t, Long_t, Bool_t, Atom_t,
03250                              Atom_t*, Int_t*, ULong_t*, ULong_t*, unsigned char**)
03251 {
03252    // Returns the actual type of the property; the actual format of the property; 
03253    // the number of 8-bit, 16-bit, or 32-bit items transferred; the number of 
03254    // bytes remaining to be read in the property; and a pointer to the data 
03255    // actually returned.
03256 
03257    return 0;
03258 }
03259 
03260 //______________________________________________________________________________
03261 void TGQt::ChangeActivePointerGrab(Window_t, UInt_t, Cursor_t)
03262 {
03263    // Changes the specified dynamic parameters if the pointer is actively 
03264    // grabbed by the client and if the specified time is no earlier than the 
03265    // last-pointer-grab time and no later than the current X server time.
03266 
03267 }
03268 
03269 //______________________________________________________________________________
03270 void TGQt::ConvertSelection(Window_t, Atom_t&, Atom_t&, Atom_t&, Time_t&)
03271 {
03272    // Requests that the specified selection be converted to the specified 
03273    // target type.
03274 
03275 }
03276 
03277 //______________________________________________________________________________
03278 Bool_t TGQt::SetSelectionOwner(Window_t, Atom_t&)
03279 {
03280    // Changes the owner and last-change time for the specified selection.
03281 
03282    return kFALSE;
03283 }
03284 
03285 //______________________________________________________________________________
03286 void TGQt::ChangeProperties(Window_t, Atom_t, Atom_t, Int_t, UChar_t *, Int_t)
03287 {
03288    // Alters the property for the specified window and causes the X server 
03289    // to generate a PropertyNotify event on that window.
03290 
03291 }
03292 
03293 //______________________________________________________________________________
03294 void TGQt::SetDNDAware(Window_t, Atom_t *)
03295 {
03296    // Add XdndAware property and the list of drag and drop types to the 
03297    // Window win.
03298 
03299 }
03300 
03301 //______________________________________________________________________________
03302 void TGQt::SetTypeList(Window_t, Atom_t, Atom_t *)
03303 {
03304    // Add the list of drag and drop types to the Window win.
03305 
03306 }
03307 
03308 //______________________________________________________________________________
03309 Window_t TGQt::FindRWindow(Window_t, Window_t, Window_t, int, int, int)
03310 {
03311    // Recursively search in the children of Window for a Window which is at 
03312    // location x, y and is DND aware, with a maximum depth of maxd.
03313 
03314    return kNone;
03315 }
03316 
03317 //______________________________________________________________________________
03318 Bool_t TGQt::IsDNDAware(Window_t, Atom_t *)
03319 {
03320    // Checks if the Window is DND aware, and knows any of the DND formats
03321    // passed in argument.
03322 
03323    return kFALSE;
03324 }
03325 
03326       
03327 

Generated on Tue Jul 5 14:14:34 2011 for ROOT_528-00b_version by  doxygen 1.5.1