splitterHorizontal.C

Go to the documentation of this file.
00001 //
00002 // Author: Ilka Antcheva   1/12/2006
00003 
00004 // This macro gives an example of how to create a horizontal splitter
00005 // To run it do either:
00006 // .x splitterHorizontal.C
00007 // .x splitterHorizontal.C++
00008 
00009 #include <TGClient.h>
00010 #include <TGButton.h>
00011 #include <TGLabel.h>
00012 #include <TGFrame.h>
00013 #include <TGLayout.h>
00014 #include <TGSplitter.h>
00015 
00016 
00017 class MyMainFrame : public TGMainFrame {
00018 
00019 public:
00020    MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
00021    virtual ~MyMainFrame();
00022    void     DoSave();
00023    void     CloseWindow();
00024    
00025    ClassDef(MyMainFrame, 0)
00026 };
00027 
00028 void MyMainFrame::DoSave()
00029 {
00030 //------      TGMainFrame::SaveSource()       --------
00031   Printf("Save in progress...");
00032   SaveSource("","");
00033 }
00034 
00035 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
00036   TGMainFrame(p, w, h)
00037 {
00038    // Create horizontal splitter
00039    TGVerticalFrame *fVf = new TGVerticalFrame(this, 10, 10);
00040 
00041    TGHorizontalFrame *fH1 = new TGHorizontalFrame(fVf, 10, 50, kFixedHeight);
00042    TGHorizontalFrame *fH2 = new TGHorizontalFrame(fVf, 10, 10);
00043    TGCompositeFrame *fFtop = new TGCompositeFrame(fH1, 10, 10, kSunkenFrame);
00044    TGCompositeFrame *fFbottom = new TGCompositeFrame(fH2, 10, 10, kSunkenFrame);
00045 
00046    TGLabel *fLtop = new TGLabel(fFtop, "Top Frame");
00047    TGLabel *fLbottom = new TGLabel(fFbottom, "Bottom Frame");
00048 
00049    fFtop->AddFrame(fLtop, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
00050                                             3, 0, 0, 0));
00051    fFbottom->AddFrame(fLbottom, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
00052                                                   3, 0, 0, 0));
00053 
00054    fH1->AddFrame(fFtop, new TGLayoutHints(kLHintsTop | kLHintsExpandY | 
00055                                           kLHintsExpandX, 0, 0, 1, 2));
00056    fH2->AddFrame(fFbottom, new TGLayoutHints(kLHintsTop | kLHintsExpandY | 
00057                                              kLHintsExpandX, 0, 0, 1, 2));
00058 
00059    fH1->Resize(fFtop->GetDefaultWidth(), fH1->GetDefaultHeight()+20);
00060    fH2->Resize(fFbottom->GetDefaultWidth(), fH2->GetDefaultHeight()+20);
00061    fVf->AddFrame(fH1, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
00062 
00063    TGHSplitter *hsplitter = new TGHSplitter(fVf,2,2);
00064    hsplitter->SetFrame(fH1, kTRUE);
00065    fVf->AddFrame(hsplitter, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
00066 
00067    fVf->AddFrame(fH2, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));   
00068    
00069    // button frame
00070    TGVerticalFrame *hframe = new TGVerticalFrame(this, 10, 10);
00071    TGCompositeFrame *cframe2 = new TGCompositeFrame(hframe, 170, 50, 
00072                                              kHorizontalFrame | kFixedWidth);
00073    TGTextButton *save = new TGTextButton(cframe2, "&Save");
00074    cframe2->AddFrame(save, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00075                                              3, 2, 2, 2));
00076    save->Connect("Clicked()", "MyMainFrame", this, "DoSave()");
00077    save->SetToolTipText("Click on the button to save the application as C++ macro");
00078    
00079    TGTextButton *exit = new TGTextButton(cframe2, "&Exit ","gApplication->Terminate(0)");
00080    cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00081                                              2, 0, 2, 2));
00082    hframe->AddFrame(cframe2, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
00083    
00084    AddFrame(fVf, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY));
00085    AddFrame(hframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
00086    
00087    // What to clean up in dtor
00088    SetCleanup(kDeepCleanup);
00089      
00090    // Set a name to the main frame   
00091    SetWindowName("Horizontal Splitter");
00092    SetWMSizeHints(300, 250, 600, 600, 0, 0);
00093    MapSubwindows();
00094    Resize(GetDefaultSize());
00095    MapWindow();
00096 }
00097 
00098 MyMainFrame::~MyMainFrame()
00099 {
00100    // Clean up all widgets, frames and layouthints that were used
00101    Cleanup();
00102 }
00103 
00104 //______________________________________________________________________________
00105 void MyMainFrame::CloseWindow()
00106 {
00107    // Called when window is closed via the window manager.
00108 
00109    delete this;
00110 }
00111 
00112 void splitterHorizontal()
00113 {
00114    // Popup the GUI...
00115 
00116    new MyMainFrame(gClient->GetRoot(), 300, 250);
00117 }

Generated on Tue Jul 5 15:44:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1