Logo ROOT   6.14/05
Reference Guide
TGDNDManager.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Bertrand Bellenot 19/04/07
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TDNDManager
13 #define ROOT_TDNDManager
14 
15 #include "TGFrame.h"
16 
17 class TGMainFrame;
18 class TGDragWindow;
19 class TTimer;
20 
21 //----------------------------------------------------------------------
22 
23 class TGDragWindow : public TGFrame {
24 
25 protected:
26  static Cursor_t fgDefaultCursor; // Default Cursor
27 
28 protected:
29  virtual void DoRedraw();
30 
31  Window_t fInput; // Input Window
32  Pixmap_t fPic, fMask; // Pixmaps used as Window shape
33  UInt_t fPw, fPh; // Hot point coordinates (x and y)
34 
35 public:
36  TGDragWindow(const TGWindow *p, Pixmap_t pic, Pixmap_t mask,
37  UInt_t options = kChildFrame, Pixel_t back = GetWhitePixel());
38  virtual ~TGDragWindow();
39 
40  virtual TGDimension GetDefaultSize() const { return TGDimension(fPw, fPh); }
41 
42  virtual void MapWindow();
43  virtual void UnmapWindow();
44  virtual void RaiseWindow();
45  virtual void LowerWindow();
46  virtual void MapRaised();
47 
48  virtual void Layout();
49 
50  Window_t GetInputId() const { return fInput; }
51  Bool_t HasWindow(Window_t w) const { return (w == fId || w == fInput); }
52 
53  ClassDef(TGDragWindow, 0) // Window used for dragging
54 };
55 
56 //----------------------------------------------------------------------
57 
58 //_____________________________________________________________________________
59 //
60 // TDNDData
61 //
62 // Drag and drop data container.
63 //_____________________________________________________________________________
64 
65 class TDNDData : public TObject {
66 private:
67  TDNDData(const TDNDData&); // Not implemented
68  TDNDData& operator=(const TDNDData&); // Not implemented
69 
70 public:
71  TDNDData(Atom_t dt = kNone, void *d = 0, Int_t len = 0, Atom_t act = kNone) :
72  fDataType(dt), fAction(act), fData(d), fDataLength(len) {}
73  ~TDNDData() {}
74 
75  Atom_t fDataType; // Data type description
76  Atom_t fAction; // Action description
77  void *fData; // Actual data
78  Int_t fDataLength; // Length of data
79 
80  ClassDef(TDNDData, 0) // Drag and drop specific data
81 };
82 
83 //----------------------------------------------------------------------
84 
85 class TGDNDManager : public TObject {
86 
87 private:
88  TGDNDManager(const TGDNDManager&); // Not implemented
89  TGDNDManager& operator=(const TGDNDManager&); // Not implemented
90 
91 protected:
92  TGFrame *fMain; // pointer on TGMainFrame
93  Atom_t fVersion; // not really an Atom, but a long
94  Atom_t *fTypelist, *fDraggerTypes; // lists of DND types
95  Atom_t fDropType; // drop type
96  Atom_t fAcceptedAction, fLocalAction; // accepted and local actions
97 
98  Bool_t fDragging; // kTRUE while dragging
99  Bool_t fDropAccepted; // kTRUE if drop accepted
100  Bool_t fStatusPending; // kTRUE if status is pending
101  Bool_t fUseVersion; // kTRUE if DND version is used
102  Bool_t fProxyOurs; // kTRUE if root proxy is ours
103  Window_t fSource, fTarget; // source and target windows
104  Bool_t fTargetIsDNDAware; // kTRUE if target is DND aware
105  UInt_t fGrabEventMask; // pointer grab event mask
106  TGFrame *fLocalSource, *fLocalTarget; // local source and target
107 
108  TTimer *fDropTimeout; // drop timeout
109  TGDragWindow *fDragWin; // drag window
110 
111  Pixmap_t fPic, fMask; // pixmap used for the drag window
112  Int_t fHotx, fHoty; // hot point coordinates
113  Cursor_t fDNDNoDropCursor; // no drop cursor type
114 
115 protected:
116  static Atom_t fgDNDAware, fgDNDSelection, fgDNDProxy;
117  static Atom_t fgDNDEnter, fgDNDLeave, fgDNDPosition, fgDNDStatus;
118  static Atom_t fgDNDDrop, fgDNDFinished;
120  static Atom_t fgDNDActionCopy, fgDNDActionMove, fgDNDActionLink;
121  static Atom_t fgDNDActionAsk, fgDNDActionPrivate;
122  static Atom_t fgDNDTypeList, fgDNDActionList, fgDNDActionDescrip;
124 
125  static Bool_t fgInit;
127 
128 protected:
129  void InitAtoms();
130  Window_t GetRootProxy();
131  Window_t FindWindow(Window_t root, Int_t x, Int_t y, Int_t maxd);
132  Bool_t IsDNDAware(Window_t win, Atom_t *typelist = 0);
133  Bool_t IsTopLevel(Window_t win);
134 
135  void SendDNDEnter(Window_t target);
136  void SendDNDLeave(Window_t target);
137  void SendDNDPosition(Window_t target, int x, int y,
138  Atom_t action, Time_t timestamp);
139  void SendDNDStatus(Window_t target, Atom_t action);
140  void SendDNDDrop(Window_t target);
141  void SendDNDFinished(Window_t src);
142 
143  Bool_t HandleDNDEnter(Window_t src, long vers, Atom_t dataTypes[3]);
145  Bool_t HandleDNDPosition(Window_t src, int x_root, int y_root, Atom_t action, Time_t timestamp);
146  Bool_t HandleDNDStatus(Window_t from, int accepted,
147  Rectangle_t skip, Atom_t action);
148  Bool_t HandleDNDDrop(Window_t src, Time_t timestamp);
150 
151 public:
152  TGDNDManager(TGFrame *toplevel, Atom_t *typelist);
153  virtual ~TGDNDManager();
154 
158 
160 
161  //--- called by widgets
162 
163  TGFrame *GetMainFrame() const { return fMain; }
164  void SetMainFrame(TGFrame *main) { fMain = main; }
165  void SetDragPixmap(Pixmap_t pic, Pixmap_t mask, Int_t hot_x, Int_t hot_y);
166  Bool_t SetRootProxy();
167  Bool_t RemoveRootProxy();
168 
169  Bool_t StartDrag(TGFrame *src, Int_t x_root, Int_t y_root,
170  Window_t grabWin = kNone);
171  Bool_t Drag(Int_t x_root, Int_t y_root, Atom_t action, Time_t timestamp);
172  Bool_t Drop();
173  Bool_t EndDrag();
174 
175  Bool_t IsDragging() const { return fDragging; }
176  Window_t GetSource() const { return fSource; }
177  Window_t GetTarget() const { return fTarget; }
178  Atom_t *GetTypeList() const { return fTypelist; }
179 
180  static Atom_t GetDNDAware();
181  static Atom_t GetDNDSelection();
182  static Atom_t GetDNDProxy();
183  static Atom_t GetDNDEnter();
184  static Atom_t GetDNDLeave();
185  static Atom_t GetDNDPosition();
186  static Atom_t GetDNDStatus();
187  static Atom_t GetDNDDrop();
188  static Atom_t GetDNDFinished();
189  static Atom_t GetDNDVersion();
190  static Atom_t GetDNDActionCopy();
191  static Atom_t GetDNDActionMove();
192  static Atom_t GetDNDActionLink();
193  static Atom_t GetDNDActionAsk();
194  static Atom_t GetDNDActionPrivate();
195  static Atom_t GetDNDTypeList();
196  static Atom_t GetDNDActionList();
197  static Atom_t GetDNDActionDescrip();
198  static Atom_t GetXCDNDData();
199 
200  ClassDef(TGDNDManager, 0) // The main Drag and Drop Manager
201 };
202 
203 R__EXTERN TGDNDManager *gDNDManager; // global drag and drop manager
204 
205 #endif // ROOT_TDNDManager
206 
Bool_t HasWindow(Window_t w) const
Definition: TGDNDManager.h:51
virtual void RaiseWindow()
Raise TGDragWindow.
static Atom_t fgDNDActionMove
Definition: TGDNDManager.h:120
static Atom_t fgXCDNDData
Definition: TGDNDManager.h:123
Int_t fDataLength
Definition: TGDNDManager.h:78
static Atom_t fgDNDVersion
Definition: TGDNDManager.h:119
virtual Bool_t HandleDNDDrop(TDNDData *)
Definition: TGFrame.h:323
ULong_t Time_t
Definition: GuiTypes.h:41
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
Window_t GetSource() const
Definition: TGDNDManager.h:176
Bool_t fDropAccepted
Definition: TGDNDManager.h:99
Handle_t Cursor_t
Definition: GuiTypes.h:33
Atom_t fAction
Definition: TGDNDManager.h:76
virtual void MapRaised()
Map and Raise TGDragWindow.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void SetMainFrame(TGFrame *main)
Definition: TGDNDManager.h:164
static Atom_t fgDNDActionPrivate
Definition: TGDNDManager.h:121
static Atom_t fgDNDStatus
Definition: TGDNDManager.h:117
static Cursor_t fgDefaultCursor
Definition: TGDNDManager.h:26
Atom_t fLocalAction
Definition: TGDNDManager.h:96
virtual void MapWindow()
Map TGDragWindow.
Bool_t IsDragging() const
Definition: TGDNDManager.h:175
virtual Bool_t HandleDNDFinished()
Definition: TGFrame.h:328
Bool_t fStatusPending
Definition: TGDNDManager.h:100
virtual Bool_t HandleTimer(TTimer *)
Execute action in response of a timer timing out.
Definition: TGWindow.h:108
R__EXTERN TGDNDManager * gDNDManager
Definition: TGDNDManager.h:203
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGDNDManager.h:40
Bool_t fProxyOurs
Definition: TGDNDManager.h:102
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:320
ULong_t Pixel_t
Definition: GuiTypes.h:39
virtual Atom_t HandleDNDPosition(Int_t, Int_t, Atom_t, Int_t, Int_t)
Definition: TGFrame.h:324
virtual void UnmapWindow()
Unmap TGDragWindow.
Handle_t Atom_t
Definition: GuiTypes.h:36
void * fData
Definition: TGDNDManager.h:77
int main(int argc, char **argv)
TDNDData(Atom_t dt=kNone, void *d=0, Int_t len=0, Atom_t act=kNone)
Definition: TGDNDManager.h:71
virtual Bool_t HandleSelectionRequest(Event_t *)
Definition: TGFrame.h:216
virtual void DoRedraw()
Redraw TGDragWindow.
virtual ~TGDragWindow()
TGDragWindow destructor.
virtual Atom_t HandleDNDEnter(Atom_t *)
Definition: TGFrame.h:326
static Atom_t fgDNDSelection
Definition: TGDNDManager.h:116
static Atom_t fgDNDTypeList
Definition: TGDNDManager.h:122
Window_t GetTarget() const
Definition: TGDNDManager.h:177
static Atom_t fgXAWMState
Definition: TGDNDManager.h:126
unsigned int UInt_t
Definition: RtypesCore.h:42
const Handle_t kNone
Definition: GuiTypes.h:87
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
Bool_t fTargetIsDNDAware
Definition: TGDNDManager.h:104
Atom_t * fTypelist
Definition: TGDNDManager.h:94
Atom_t fDataType
Definition: TGDNDManager.h:75
#define d(i)
Definition: RSha256.hxx:102
TTimer * fDropTimeout
Definition: TGDNDManager.h:108
static Atom_t fgDNDFinished
Definition: TGDNDManager.h:118
Bool_t fDragging
Definition: TGDNDManager.h:98
Pixmap_t fPic
Definition: TGDNDManager.h:111
Atom_t fDropType
Definition: TGDNDManager.h:95
Pixmap_t fPic
Definition: TGDNDManager.h:32
virtual Bool_t HandleSelection(Event_t *)
Definition: TGFrame.h:215
virtual Bool_t HandleClientMessage(Event_t *event)
Handle a client message.
Definition: TGFrame.cxx:651
Double_t y[n]
Definition: legend1.C:17
Window_t GetInputId() const
Definition: TGDNDManager.h:50
Handle_t fId
Definition: TGObject.h:36
TGFrame * fLocalTarget
Definition: TGDNDManager.h:106
virtual void LowerWindow()
Lower TGDragWindow.
Mother of all ROOT objects.
Definition: TObject.h:37
#define R__EXTERN
Definition: DllImport.h:27
Handle_t Window_t
Definition: GuiTypes.h:28
static Bool_t fgInit
Definition: TGDNDManager.h:125
TGFrame & operator=(const TGFrame &)
TGFrame * GetMainFrame() const
Definition: TGDNDManager.h:163
TGDragWindow * fDragWin
Definition: TGDNDManager.h:109
Handle_t Pixmap_t
Definition: GuiTypes.h:29
TGFrame * fMain
Definition: TGDNDManager.h:92
Cursor_t fDNDNoDropCursor
Definition: TGDNDManager.h:113
Pixmap_t fMask
Definition: TGDNDManager.h:32
virtual void Layout()
Layout TGDragWindow.
Atom_t * GetTypeList() const
Definition: TGDNDManager.h:178
Window_t fInput
Definition: TGDNDManager.h:31
Window_t fTarget
Definition: TGDNDManager.h:103
TGDragWindow(const TGWindow *p, Pixmap_t pic, Pixmap_t mask, UInt_t options=kChildFrame, Pixel_t back=GetWhitePixel())
TGDragWindow constructor.
UInt_t fGrabEventMask
Definition: TGDNDManager.h:105
Bool_t fUseVersion
Definition: TGDNDManager.h:101
Atom_t fVersion
Definition: TGDNDManager.h:93
virtual Bool_t HandleDNDLeave()
Definition: TGFrame.h:327