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