#include "TROOT.h" #include "TApplication.h" #include "TSystem.h" #include "TGFrame.h" #include "TGButton.h" #include "TGLabel.h" #include "TGMenu.h" #include "TGFileDialog.h" #include "TBrowser.h" #include "TRootEmbeddedCanvas.h" #include "TRootHelpDialog.h" #include "TCanvas.h" #include "TH1F.h" #include "TH2F.h" #include "TF2.h" #include "TGraph.h" #include "TImage.h" #include "TRandom.h" #include "TGMsgBox.h" #include "TGPicture.h" #include "TGListTree.h" #include "TObjString.h" #include "TMessage.h" #include "TTimer.h" #include "TGDNDManager.h" #include const char gHelpDND[] = "\ Drag & Drop (DnD)\n\ Drag and Drop support is implemented on Linux via Xdnd, the\n\ drag and drop protocol for X window system, and on Windows\n\ via the Clipboard.\n\ Users can selects something in ROOT with a mouse press, drags\n\ it (moves the mouse while keeping the mouse button pressed) and\n\ releases the mouse button somewhere else. When the button is\n\ released the selected data is \"dropped\" at that location. This\n\ way, a histogram from an opened ROOT file in the browser can be\n\ dragged to any TCanvas. A script file from the browser can be\n\ dropped to a TGTextView or TGTextEdit widget in TGTextEditor.\n\ On Linux, it is possible to drag objects between ROOT and an\n\ external application. For example to drag a macro file from the\n\ ROOT browser to the Kate editor. On Windows, drag and drop works\n\ only within a single ROOT application, but it is possible to drag\n\ from the Windows Explorer to ROOT (e.g. a picture file to a canvas\n\ or a text file to a text editor).\n\ "; const char gReadyMsg[] = "Ready. You can drag list tree items to any \ pad in the canvas, or to the \"Base\" folder of the list tree itself..."; //---------------------------------------------------------------------- class DNDMainFrame : public TGMainFrame { protected: TRootEmbeddedCanvas *fEc; // embedded canvas TGTextButton *fButtonExit, *fBE; // "Exit" text button TGMenuBar *fMenuBar; // main menu bar TGPopupMenu *fMenuFile; // "File" popup menu entry TGPopupMenu *fMenuHelp; // "Help" popup menu entry TCanvas *fCanvas; // canvas TGListTree *fListTree; // left list tree TGListTreeItem *fBaseLTI; // base (root) list tree item TGLabel *fStatus; // label used to display status TGraph *fGraph; // TGraph object TH1F *fHist1D; // 1D histogram TH2F *fHist2D; // 2D histogram TGVerticalFrame *fVerticalFrame; TGDoubleHSlider *fDoubleSlider; TGGroupFrame *fGroupFrameInputs, *fGroupFrameOutputs; TGShutter *fShutter; TGShutterItem *fShutterItemTasks, *fShutterItemIStalls; public: DNDMainFrame(const TGWindow *p, int w, int h); virtual ~DNDMainFrame(); void DoCloseWindow(); void HandleMenu(Int_t); TObject *GetObject(const char *obj); void DataDropped(TGListTreeItem* item, TDNDData* data); void ResetStatus(); //ClassDef(DNDMainFrame, 0); // Mainframe for Drag and Drop demo }; enum EMyMessageTypes { M_FILE_OPEN, M_FILE_BROWSE, M_FILE_NEWCANVAS, M_FILE_CLOSEWIN, M_FILE_EXIT, M_HELP_ABOUT }; const char *dnd_types[] = { "ROOT files", "*.root", "ROOT macros", "*.C", "All files", "*", 0, 0 }; static Atom_t gRootObj = kNone; //______________________________________________________________________________ DNDMainFrame::DNDMainFrame(const TGWindow *p, int w, int h) : TGMainFrame(p, w, h) { // Constructor. SetCleanup(kDeepCleanup); fMenuBar = new TGMenuBar(this, 35, 50, kHorizontalFrame); fMenuFile = new TGPopupMenu(gClient->GetRoot()); fMenuFile->AddEntry(" &Open...\tCtrl+O", M_FILE_OPEN, 0, gClient->GetPicture("bld_open.png")); fMenuFile->AddEntry(" &Browse...\tCtrl+B", M_FILE_BROWSE); fMenuFile->AddEntry(" &New Canvas\tCtrl+N", M_FILE_NEWCANVAS); fMenuFile->AddEntry(" &Close Window\tCtrl+W", M_FILE_CLOSEWIN); fMenuFile->AddSeparator(); fMenuFile->AddEntry(" E&xit\tCtrl+Q", M_FILE_EXIT, 0, gClient->GetPicture("bld_exit.png")); fMenuFile->Connect("Activated(Int_t)", "DNDMainFrame", this, "HandleMenu(Int_t)"); fMenuHelp = new TGPopupMenu(gClient->GetRoot()); fMenuHelp->AddEntry(" &About...", M_HELP_ABOUT, 0, gClient->GetPicture("about.xpm")); fMenuHelp->Connect("Activated(Int_t)", "DNDMainFrame", this, "HandleMenu(Int_t)"); fMenuBar->AddPopup("&File", fMenuFile, new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0)); fMenuBar->AddPopup("&Help", fMenuHelp, new TGLayoutHints(kLHintsTop|kLHintsRight)); AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 5)); // Separator TGHorizontal3DLine *separator = new TGHorizontal3DLine(this); AddFrame(separator, new TGLayoutHints(kLHintsLeft | kLHintsExpandX)); TGHorizontalFrame *fHf = new TGHorizontalFrame(this, 50, 50); TGVerticalFrame *fV1 = new TGVerticalFrame(fHf, 200, 240, kFixedWidth); TGVerticalFrame *fV2 = new TGVerticalFrame(fHf, 400, 480); fHf->AddFrame(fV1, new TGLayoutHints(kLHintsLeft | kLHintsExpandY)); TGVSplitter *splitter = new TGVSplitter(fHf,2,20); splitter->SetFrame(fV1, kTRUE); fHf->AddFrame(splitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY)); fHf->AddFrame(fV2, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY)); AddFrame(fHf, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY)); // shutter fShutter = new TGShutter(fV1,kSunkenFrame); fV1->AddFrame(fShutter, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY | kLHintsExpandX,2,2,2,2)); fShutter->SetName("Inputs"); // "Tasks" shutter item fShutterItemTasks = new TGShutterItem(fShutter, new TGHotString("Tasks"),100,kVerticalFrame); TGCompositeFrame *fVerticalFrameTasks1 = (TGCompositeFrame *)fShutterItemTasks->GetContainer(); TGCheckButton *task = new TGCheckButton(fVerticalFrameTasks1, "Task 1"); fShutter->AddItem(fShutterItemTasks); fVerticalFrameTasks1->SetBackgroundColor(TColor::Number2Pixel(18)); // "I_Stalls" shutter item fShutterItemIStalls = new TGShutterItem(fShutter, new TGHotString("I_Stalls"),200,kVerticalFrame); TGCompositeFrame *fVerticalFrameIStalls1 = (TGCompositeFrame *)fShutterItemIStalls->GetContainer(); TGCheckButton *iStallsEnableDisable = new TGCheckButton(fVerticalFrameIStalls1, "Show/Hide I_Stalls"); fShutter->AddItem(fShutterItemIStalls); //This is how to add an empty Shutter Item TGShutterItem *item = new TGShutterItem(fShutter, new TGHotString("Empty"),100,kVerticalFrame); TGCompositeFrame *cont = (TGCompositeFrame *)item->GetContainer(); cont->SetBackgroundColor(TColor::Number2Pixel(18)); fShutter->AddItem(item); fShutter->SetSelectedItem(fShutterItemIStalls); fShutter->Resize(200,240); // embedded canvas TRootEmbeddedCanvas *embeddedCanvas = new TRootEmbeddedCanvas("My Embedded Canvas", fV2, 200, 240, kDoubleBorder); fV2->AddFrame(embeddedCanvas, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY | kLHintsExpandX,2,2,2,2)); TGStatusBar *fStatusBar = new TGStatusBar(this, 40, 10); AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 0, 3, 0)); SetWindowName("Test"); MapSubwindows(); Resize(GetDefaultSize()); Connect("CloseWindow()", "DNDMainFrame", this, "DoCloseWindow()"); DontCallClose(); // to avoid double deletions. } //______________________________________________________________________________ DNDMainFrame::~DNDMainFrame() { // Destructor. Doesnt't do much here. } //______________________________________________________________________________ void DNDMainFrame::DoCloseWindow() { // Do some cleanup, disconnect signals and then really close the main window. fMenuFile->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)"); fMenuHelp->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)"); CloseWindow(); } void DNDMainFrame::HandleMenu(Int_t menu_id) { // Handle menu events. TRootHelpDialog *hd; static TString dir("."); TGFileInfo fi; fi.fFileTypes = dnd_types; fi.fIniDir = StrDup(dir); switch (menu_id) { case M_FILE_EXIT: // close the window and quit application DoCloseWindow(); gApplication->Terminate(0); break; case M_FILE_OPEN: new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi); dir = fi.fIniDir; // doesn't do much, but can be used to open a root file... break; case M_FILE_BROWSE: // start a root object browser new TBrowser(); break; case M_FILE_NEWCANVAS: // open a root canvas gROOT->MakeDefCanvas(); break; case M_FILE_CLOSEWIN: DoCloseWindow(); break; case M_HELP_ABOUT: hd = new TRootHelpDialog(this, "About Drag and Drop...", 550, 250); hd->SetText(gHelpDND); hd->Popup(); break; } } //------------------------------------------------------------------------------ void drag_and_drop() { // Main function (entry point) DNDMainFrame *mainWindow = new DNDMainFrame(gClient->GetRoot(), 700, 400); mainWindow->MapWindow(); }