splitterVertical.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 vertical splitter
00005 // To run it do either:
00006 // .x splitterVertical.C
00007 // .x splitterVertical.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 //______________________________________________________________________________
00029 void MyMainFrame::DoSave()
00030 {
00031   Printf("Save in progress...");
00032   SaveSource("","");
00033 }
00034 
00035 //______________________________________________________________________________
00036 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
00037   TGMainFrame(p, w, h)
00038 {
00039    // Create vertical splitter
00040    
00041    TGHorizontalFrame *fHf = new TGHorizontalFrame(this, 50, 50);
00042 
00043    TGVerticalFrame *fV1 = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
00044    TGVerticalFrame *fV2 = new TGVerticalFrame(fHf, 10, 10);
00045    TGCompositeFrame *fFleft = new TGCompositeFrame(fV1, 10, 10, kSunkenFrame);
00046    TGCompositeFrame *fFright = new TGCompositeFrame(fV2, 10, 10, kSunkenFrame);
00047 
00048    TGLabel *fLleft = new TGLabel(fFleft, "Left Frame");
00049    TGLabel *fLright = new TGLabel(fFright, "Right Frame");
00050 
00051    fFleft->AddFrame(fLleft, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 
00052                                               3, 0, 0, 0));
00053    fFright->AddFrame(fLright, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
00054                                                 3, 0, 0, 0));
00055 
00056    fV1->AddFrame(fFleft, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
00057                                            0, 0, 5, 10));
00058    fV2->AddFrame(fFright, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
00059                                             0, 0, 5, 10));
00060 
00061    fV1->Resize(fFleft->GetDefaultWidth()+20, fV1->GetDefaultHeight());
00062    fV2->Resize(fFright->GetDefaultWidth(), fV1->GetDefaultHeight());
00063    fHf->AddFrame(fV1, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00064 
00065    TGVSplitter *splitter = new TGVSplitter(fHf,2,2);
00066    splitter->SetFrame(fV1, kTRUE);
00067    fHf->AddFrame(splitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00068 
00069    fHf->AddFrame(fV2, new TGLayoutHints(kLHintsRight | kLHintsExpandX |
00070                                         kLHintsExpandY));
00071    AddFrame(fHf, new TGLayoutHints(kLHintsRight | kLHintsExpandX |
00072                                    kLHintsExpandY));
00073    
00074    // button frame
00075    TGVerticalFrame *vframe = new TGVerticalFrame(this, 10, 10);
00076    TGCompositeFrame *cframe2 = new TGCompositeFrame(vframe, 170, 20,
00077                                              kHorizontalFrame | kFixedWidth);
00078    TGTextButton *save = new TGTextButton(cframe2, "&Save");
00079    cframe2->AddFrame(save, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00080                                              3, 2, 2, 2));
00081    save->Connect("Clicked()", "MyMainFrame", this, "DoSave()");
00082    save->SetToolTipText("Click on the button to save the application as C++ macro");
00083    
00084    TGTextButton *exit = new TGTextButton(cframe2, "&Exit ","gApplication->Terminate(0)");
00085    cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00086                                              2, 0, 2, 2));
00087    vframe->AddFrame(cframe2, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
00088    AddFrame(vframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
00089    
00090    // What to clean up in destructor
00091    SetCleanup(kDeepCleanup);
00092 
00093    // Set a name to the main frame   
00094    SetWindowName("Vertical Splitter");
00095    SetWMSizeHints(350, 200, 600, 400, 0, 0);
00096    MapSubwindows();
00097    Resize(GetDefaultSize());
00098    MapWindow();
00099 }
00100 
00101 
00102 //______________________________________________________________________________
00103 MyMainFrame::~MyMainFrame()
00104 {
00105    // Clean up all widgets, frames and layouthints that were used
00106    Cleanup();
00107 }
00108 
00109 //______________________________________________________________________________
00110 void MyMainFrame::CloseWindow()
00111 {
00112    // Called when window is closed via the window manager.
00113 
00114    delete this;
00115 }
00116 
00117 void splitterVertical()
00118 {
00119    // Popup the GUI...
00120    new MyMainFrame(gClient->GetRoot(), 350, 200);
00121 }

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