40const char gHelpDND[] =
"\
42Drag and Drop support is implemented on Linux via Xdnd, the\n\
43drag and drop protocol for X window system, and on Windows\n\
45Users can selects something in ROOT with a mouse press, drags\n\
46it (moves the mouse while keeping the mouse button pressed) and\n\
47releases the mouse button somewhere else. When the button is\n\
48released the selected data is \"dropped\" at that location. This\n\
49way, a histogram from an opened ROOT file in the browser can be\n\
50dragged to any TCanvas. A script file from the browser can be\n\
51dropped to a TGTextView or TGTextEdit widget in TGTextEditor.\n\
52On Linux, it is possible to drag objects between ROOT and an\n\
53external application. For example to drag a macro file from the\n\
54ROOT browser to the Kate editor. On Windows, drag and drop works\n\
55only within a single ROOT application, but it is possible to drag\n\
56from the Windows Explorer to ROOT (e.g. a picture file to a canvas\n\
57or a text file to a text editor).\n\
60const char gReadyMsg[] =
"Ready. You can drag list tree items to any \
61pad in the canvas, or to the \"Base\" folder of the list tree itself...";
68 TRootEmbeddedCanvas *fEc;
69 TGTextButton *fButtonExit;
71 TGPopupMenu *fMenuFile;
72 TGPopupMenu *fMenuHelp;
74 TGListTree *fListTree;
75 TGListTreeItem *fBaseLTI;
82 DNDMainFrame(
const TGWindow *p,
int w,
int h);
83 virtual ~DNDMainFrame();
86 void HandleMenu(
Int_t);
87 TObject *GetObject(
const char *obj);
88 void DataDropped(TGListTreeItem *item, TDNDData *data);
103const char *dnd_types[] = {
"ROOT files",
"*.root",
"ROOT macros",
"*.C",
"All files",
"*", 0, 0};
119 fMenuFile->AddEntry(
" &Open...\tCtrl+O", M_FILE_OPEN, 0,
gClient->GetPicture(
"bld_open.png"));
120 fMenuFile->AddEntry(
" &Browse...\tCtrl+B", M_FILE_BROWSE);
121 fMenuFile->AddEntry(
" &New Canvas\tCtrl+N", M_FILE_NEWCANVAS);
122 fMenuFile->AddEntry(
" &Close Window\tCtrl+W", M_FILE_CLOSEWIN);
123 fMenuFile->AddSeparator();
124 fMenuFile->AddEntry(
" E&xit\tCtrl+Q", M_FILE_EXIT, 0,
gClient->GetPicture(
"bld_exit.png"));
125 fMenuFile->Connect(
"Activated(Int_t)",
"DNDMainFrame",
this,
"HandleMenu(Int_t)");
128 fMenuHelp->AddEntry(
" &About...", M_HELP_ABOUT, 0,
gClient->GetPicture(
"about.xpm"));
129 fMenuHelp->Connect(
"Activated(Int_t)",
"DNDMainFrame",
this,
"HandleMenu(Int_t)");
140 fListTree->Associate(
this);
145 fEc->SetDNDTarget(
kTRUE);
146 fCanvas = fEc->GetCanvas();
147 fCanvas->Divide(3, 2);
148 fCanvas->SetBorderMode(0);
149 fBaseLTI = fListTree->AddItem(0,
"Base");
155 fStatus->SetTextColor(0x0000ff);
159 fButtonExit->Resize(fButtonExit->GetDefaultSize());
160 fButtonExit->SetToolTipText(
"Exit Application (ROOT)");
161 fButtonExit->Connect(
"Clicked()",
"TApplication",
gApplication,
"Terminate()");
169 pic =
gClient->GetPicture(
"f1_t.xpm");
170 item = fListTree->AddItem(fBaseLTI,
gr->GetName(),
gr, pic, pic);
171 fListTree->SetToolTipItem(item,
"Simple Graph");
175 pic =
gClient->GetPicture(
"h1_t.xpm");
176 item = fListTree->AddItem(fBaseLTI, hpx->GetName(), hpx, pic, pic);
177 fListTree->SetToolTipItem(item,
"1D Histogram");
180 TH2F *h2 = (
TH2F *)GetObject(
"2D Hist");
181 pic =
gClient->GetPicture(
"h2_t.xpm");
182 item = fListTree->AddItem(fBaseLTI, h2->
GetName(), h2, pic, pic);
183 fListTree->SetToolTipItem(item,
"2D Histogram");
189 if (link[1] ==
':' && link[2] ==
'/')
192 link.
Append(
"/visualisation/image/rose512.jpg");
201 pic =
gClient->GetPicture(
"psp_t.xpm");
204 item = fListTree->AddItem(fBaseLTI,
"Rose", ostr, pic, pic);
205 fListTree->SetToolTipItem(item, link.
Data());
210 fListTree->OpenItem(fBaseLTI);
211 fListTree->GetFirstItem()->SetDNDTarget(
kTRUE);
214 fListTree->Connect(
"DataDropped(TGListTreeItem*, TDNDData*)",
"DNDMainFrame",
this,
215 "DataDropped(TGListTreeItem*,TDNDData*)");
217 SetWindowName(
"ROOT DND Demo Application");
219 Resize(GetDefaultSize());
220 Connect(
"CloseWindow()",
"DNDMainFrame",
this,
"DoCloseWindow()");
225DNDMainFrame::~DNDMainFrame()
231void DNDMainFrame::DoCloseWindow()
247 fMenuFile->Disconnect(
"Activated(Int_t)",
this,
"HandleMenu(Int_t)");
248 fMenuHelp->Disconnect(
"Activated(Int_t)",
this,
"HandleMenu(Int_t)");
249 fButtonExit->Disconnect(
"Clicked()",
this,
"CloseWindow()");
250 fListTree->Disconnect(
"DataDropped(TGListTreeItem*, TDNDData*)",
this,
"DataDropped(TGListTreeItem*,TDNDData*)");
261 fStatus->SetTextColor(0xff0000);
262 fStatus->ChangeText(
"I received data!!!");
267 if (data->fDataType == gRootObj) {
271 sprintf(tmp,
"Received DND data : Type = \"%s\"; Length = %d bytes;", obj->
ClassName(), data->fDataLength);
273 pic =
gClient->GetPicture(
"f1_t.xpm");
275 pic =
gClient->GetPicture(
"h2_t.xpm");
277 pic =
gClient->GetPicture(
"h1_t.xpm");
278 itm = fListTree->AddItem(fBaseLTI, obj->
GetName(), obj, pic, pic);
279 fListTree->SetToolTipItem(itm, obj->
GetName());
281 sprintf(tmp,
"Received DND data: \"%s\"", (
char *)data->fData);
291 pic =
gClient->GetPicture(
"doc_t.xpm");
292 itm = fListTree->AddItem(fBaseLTI,
"Link...", ostr, pic, pic);
293 fListTree->SetToolTipItem(itm, (
const char *)data->fData);
297 fStatus->ChangeText(tmp);
303TObject *DNDMainFrame::GetObject(
const char *obj)
308 if (!strcmp(obj,
"Graph")) {
312 for (
Int_t i = 0; i <
n; i++) {
314 y[i] = 10 *
sin(
x[i] + 0.2);
319 }
else if (!strcmp(obj,
"1D Hist")) {
321 fHist1D =
new TH1F(
"1D Hist",
"This is the px distribution", 100, -4, 4);
323 for (
Int_t i = 0; i < 10000; i++) {
329 }
else if (!strcmp(obj,
"2D Hist")) {
331 Double_t params[] = {130, -1.4, 1.8, 1.5, 1, 150, 2, 0.5, -2, 0.5, 3600, -2, 0.7, -3, 0.3};
332 TF2 *f2 =
new TF2(
"f2",
"xygaus + xygaus(5) + xylandau(10)", -4, 4, -4, 4);
334 fHist2D =
new TH2F(
"2D Hist",
"xygaus+xygaus(5)+xylandau(10)", 20, -4, 4, 20, -4, 4);
335 fHist2D->FillRandom(
"f2", 40000);
343void DNDMainFrame::HandleMenu(
Int_t menu_id)
368 case M_FILE_NEWCANVAS:
370 gROOT->MakeDefCanvas();
372 case M_FILE_CLOSEWIN: DoCloseWindow();
break;
382void DNDMainFrame::ResetStatus()
386 fStatus->SetTextColor(0x0000ff);
387 fStatus->ChangeText(gReadyMsg);
395 DNDMainFrame *mainWindow =
new DNDMainFrame(
gClient->GetRoot(), 700, 400);
396 mainWindow->MapWindow();
int Int_t
Signed integer 4 bytes (int).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
externTApplication * gApplication
Using a TBrowser one can browse all ROOT objects.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Drag and drop data container.
virtual void SetParameters(const Double_t *params)
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
This class creates a file selection dialog.
const char ** fFileTypes
file types used to filter selectable files
char * fIniDir
on input: initial directory, on output: new directory
void SetIniDir(const char *inidir)
Set directory name.
A composite frame that layout their children in horizontal way.
TGHotString is a string with a "hot" character underlined.
This class handles GUI labels.
This class describes layout hints used by the layout classes.
void SetDNDSource(Bool_t onoff)
A list tree is a widget that can contain a number of items arranged in a tree structure.
Defines top level windows that interact with the system Window Manager.
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Yield an action as soon as it is clicked.
ROOT GUI Window base class.
1-D histogram with a float per channel (see TH1 documentation)
2-D histogram with a float per channel (see TH1 documentation)
An abstract interface to image processing library.
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
virtual void Scale(UInt_t, UInt_t)
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
virtual Pixmap_t GetPixmap()
virtual Pixmap_t GetMask()
const char * GetName() const override
Returns name of object.
Collectable string class.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
This class creates a TGCanvas in which a TCanvas is created.
A TRootHelpDialog is used to display help text (or any text in a dialog window).
void SetText(const char *helpText)
Set help text from helpText buffer in TGTextView.
void Popup()
Show help dialog.
const char * Data() const
TString & Prepend(const char *cs)
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
This static function calls a slot after a given time interval.
RVec< PromoteType< T > > sin(const RVec< T > &v)