TGDNDManager.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGDNDManager.h 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Bertrand Bellenot   19/04/07
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TDNDManager
00013 #define ROOT_TDNDManager
00014 
00015 #ifndef ROOT_TGFrame
00016 #include "TGFrame.h"
00017 #endif
00018 
00019 class TGMainFrame;
00020 class TGDragWindow;
00021 class TTimer;
00022 
00023 //----------------------------------------------------------------------
00024 
00025 class TGDragWindow : public TGFrame {
00026 
00027 protected:
00028    static Cursor_t fgDefaultCursor; // Default Cursor
00029 
00030 protected:
00031    virtual void DoRedraw();
00032 
00033    Window_t fInput;                 // Input Window
00034    Pixmap_t fPic, fMask;            // Pixmaps used as Window shape
00035    UInt_t   fPw, fPh;               // Hot point coordinates (x and y)
00036 
00037 public:
00038    TGDragWindow(const TGWindow *p, Pixmap_t pic, Pixmap_t mask,
00039                 UInt_t options = kChildFrame, Pixel_t back = GetWhitePixel());
00040    virtual ~TGDragWindow();
00041 
00042    virtual TGDimension GetDefaultSize() const { return TGDimension(fPw, fPh); }
00043 
00044    virtual void MapWindow();
00045    virtual void UnmapWindow();
00046    virtual void RaiseWindow();
00047    virtual void LowerWindow();
00048    virtual void MapRaised();
00049 
00050    virtual void Layout();
00051 
00052    Window_t GetInputId() const { return fInput; }
00053    Bool_t HasWindow(Window_t w) const { return (w == fId || w == fInput); }
00054 
00055    ClassDef(TGDragWindow, 0) // Window used for dragging
00056 };
00057 
00058 //----------------------------------------------------------------------
00059 
00060 //_____________________________________________________________________________
00061 //
00062 // TDNDData
00063 //
00064 // Drag and drop data container.
00065 //_____________________________________________________________________________
00066 
00067 class TDNDData : public TObject {
00068 private:
00069    TDNDData(const TDNDData&);            // Not implemented
00070    TDNDData& operator=(const TDNDData&); // Not implemented
00071 
00072 public:
00073    TDNDData(Atom_t dt = kNone, void *d = 0, Int_t len = 0, Atom_t act = kNone) :
00074       fDataType(dt), fAction(act), fData(d), fDataLength(len) {}
00075    ~TDNDData() {}
00076 
00077    Atom_t    fDataType;       // Data type description
00078    Atom_t    fAction;         // Action description
00079    void     *fData;           // Actual data
00080    Int_t     fDataLength;     // Length of data
00081 
00082    ClassDef(TDNDData, 0) // Drag and drop specific data
00083 };
00084 
00085 //----------------------------------------------------------------------
00086 
00087 class TGDNDManager : public TObject {
00088 
00089 private:
00090    TGDNDManager(const TGDNDManager&);            // Not implemented
00091    TGDNDManager& operator=(const TGDNDManager&); // Not implemented
00092 
00093 protected:
00094    TGFrame       *fMain;                         // pointer on TGMainFrame
00095    Atom_t         fVersion;                      // not really an Atom, but a long
00096    Atom_t        *fTypelist, *fDraggerTypes;     // lists of DND types
00097    Atom_t         fDropType;                     // drop type
00098    Atom_t         fAcceptedAction, fLocalAction; // accepted and local actions
00099 
00100    Bool_t         fDragging;                     // kTRUE while dragging
00101    Bool_t         fDropAccepted;                 // kTRUE if drop accepted
00102    Bool_t         fStatusPending;                // kTRUE if status is pending
00103    Bool_t         fUseVersion;                   // kTRUE if DND version is used
00104    Bool_t         fProxyOurs;                    // kTRUE if root proxy is ours
00105    Window_t       fSource, fTarget;              // source and target windows
00106    Bool_t         fTargetIsDNDAware;             // kTRUE if target is DND aware
00107    UInt_t         fGrabEventMask;                // pointer grab event mask
00108    TGFrame       *fLocalSource, *fLocalTarget;   // local source and target
00109 
00110    TTimer        *fDropTimeout;                  // drop timeout
00111    TGDragWindow  *fDragWin;                      // drag window
00112 
00113    Pixmap_t       fPic, fMask;                   // pixmap used for the drag window
00114    Int_t          fHotx, fHoty;                  // hot point coordinates
00115    Cursor_t       fDNDNoDropCursor;              // no drop cursor type
00116 
00117 protected:
00118    static Atom_t  fgDNDAware, fgDNDSelection, fgDNDProxy;
00119    static Atom_t  fgDNDEnter, fgDNDLeave, fgDNDPosition, fgDNDStatus;
00120    static Atom_t  fgDNDDrop, fgDNDFinished;
00121    static Atom_t  fgDNDVersion;
00122    static Atom_t  fgDNDActionCopy, fgDNDActionMove, fgDNDActionLink;
00123    static Atom_t  fgDNDActionAsk, fgDNDActionPrivate;
00124    static Atom_t  fgDNDTypeList, fgDNDActionList, fgDNDActionDescrip;
00125    static Atom_t  fgXCDNDData;
00126 
00127    static Bool_t  fgInit;
00128    static Atom_t  fgXAWMState;
00129 
00130 protected:
00131    void           InitAtoms();
00132    Window_t       GetRootProxy();
00133    Window_t       FindWindow(Window_t root, Int_t x, Int_t y, Int_t maxd);
00134    Bool_t         IsDNDAware(Window_t win, Atom_t *typelist = 0);
00135    Bool_t         IsTopLevel(Window_t win);
00136 
00137    void           SendDNDEnter(Window_t target);
00138    void           SendDNDLeave(Window_t target);
00139    void           SendDNDPosition(Window_t target, int x, int y,
00140                                   Atom_t action, Time_t timestamp);
00141    void           SendDNDStatus(Window_t target, Atom_t action);
00142    void           SendDNDDrop(Window_t target);
00143    void           SendDNDFinished(Window_t src);
00144 
00145    Bool_t         HandleDNDEnter(Window_t src, long vers, Atom_t dataTypes[3]);
00146    Bool_t         HandleDNDLeave(Window_t src);
00147    Bool_t         HandleDNDPosition(Window_t src, int x_root, int y_root, Atom_t action, Time_t timestamp);
00148    Bool_t         HandleDNDStatus(Window_t from, int accepted,
00149                                   Rectangle_t skip, Atom_t action);
00150    Bool_t         HandleDNDDrop(Window_t src, Time_t timestamp);
00151    Bool_t         HandleDNDFinished(Window_t target);
00152 
00153 public:
00154    TGDNDManager(TGFrame *toplevel, Atom_t *typelist);
00155    virtual ~TGDNDManager();
00156 
00157    Bool_t         HandleClientMessage(Event_t *event);
00158    Bool_t         HandleSelectionRequest(Event_t *event);
00159    Bool_t         HandleSelection(Event_t *event);
00160 
00161    Bool_t         HandleTimer(TTimer *t);
00162 
00163   //--- called by widgets
00164 
00165    TGFrame       *GetMainFrame() const { return fMain; }
00166    void           SetMainFrame(TGFrame *main) { fMain = main; }
00167    void           SetDragPixmap(Pixmap_t pic, Pixmap_t mask, Int_t hot_x, Int_t hot_y);
00168    Bool_t         SetRootProxy();
00169    Bool_t         RemoveRootProxy();
00170 
00171    Bool_t         StartDrag(TGFrame *src, Int_t x_root, Int_t y_root,
00172                             Window_t grabWin = kNone);
00173    Bool_t         Drag(Int_t x_root, Int_t y_root, Atom_t action, Time_t timestamp);
00174    Bool_t         Drop();
00175    Bool_t         EndDrag();
00176 
00177    Bool_t         IsDragging() const { return fDragging; }
00178    Window_t       GetSource() const { return fSource; }
00179    Window_t       GetTarget() const { return fTarget; }
00180    Atom_t        *GetTypeList() const { return fTypelist; }
00181 
00182    static Atom_t  GetDNDAware();
00183    static Atom_t  GetDNDSelection();
00184    static Atom_t  GetDNDProxy();
00185    static Atom_t  GetDNDEnter();
00186    static Atom_t  GetDNDLeave();
00187    static Atom_t  GetDNDPosition();
00188    static Atom_t  GetDNDStatus();
00189    static Atom_t  GetDNDDrop();
00190    static Atom_t  GetDNDFinished();
00191    static Atom_t  GetDNDVersion();
00192    static Atom_t  GetDNDActionCopy();
00193    static Atom_t  GetDNDActionMove();
00194    static Atom_t  GetDNDActionLink();
00195    static Atom_t  GetDNDActionAsk();
00196    static Atom_t  GetDNDActionPrivate();
00197    static Atom_t  GetDNDTypeList();
00198    static Atom_t  GetDNDActionList();
00199    static Atom_t  GetDNDActionDescrip();
00200    static Atom_t  GetXCDNDData();
00201 
00202    ClassDef(TGDNDManager, 0) // The main Drag and Drop Manager
00203 };
00204 
00205 R__EXTERN TGDNDManager *gDNDManager; // global drag and drop manager
00206 
00207 #endif  // ROOT_TDNDManager
00208 

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