buttonsLayout.C

Go to the documentation of this file.
00001 //
00002 // Author: Ilka Antcheva   1/12/2006
00003 
00004 // This macro gives an example of different buttons' layout.
00005 // To run it do either:
00006 // .x buttonsLayout.C
00007 // .x buttonsLayout.C++
00008 
00009 #include <TGClient.h>
00010 #include <TGButton.h>
00011 
00012 class MyMainFrame : public TGMainFrame {
00013 
00014 private:
00015    TGTextButton *test, *draw, *help, *ok, *cancel, *exit;
00016 
00017 public:
00018    MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
00019    virtual ~MyMainFrame();
00020 
00021    ClassDef(MyMainFrame, 0)
00022 };
00023 
00024 
00025 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
00026   TGMainFrame(p, w, h)
00027 {
00028    // Create a container frames containing buttons
00029 
00030    // one button is resized up to the parent width.
00031    // Note! this width should be fixed!
00032    TGVerticalFrame *hframe1 = new TGVerticalFrame(this, 170, 50, kFixedWidth);
00033    test = new TGTextButton(hframe1, "&Test ");
00034    // to take whole space we need to use kLHintsExpandX layout hints
00035    hframe1->AddFrame(test, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00036                                              2, 0, 2, 2));
00037    AddFrame(hframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
00038 
00039    // two buttons are resized up to the parent width.
00040    // Note! this width should be fixed!
00041    TGCompositeFrame *cframe1 = new TGCompositeFrame(this, 170, 20, 
00042                                              kHorizontalFrame | kFixedWidth);
00043    draw = new TGTextButton(cframe1, "&Draw");
00044    // to share whole parent space we need to use kLHintsExpandX layout hints
00045    cframe1->AddFrame(draw, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00046                                              2, 2, 2, 2));
00047    
00048    // button background will be set to yellow
00049    ULong_t yellow;
00050    gClient->GetColorByName("yellow", yellow);
00051    help = new TGTextButton(cframe1, "&Help");
00052    help->ChangeBackground(yellow);
00053    cframe1->AddFrame(help, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00054                                              2, 2, 2, 2));   
00055    AddFrame(cframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
00056    
00057    // three buttons are resized up to the parent width.
00058    // Note! this width should be fixed!
00059    TGCompositeFrame *cframe2 = new TGCompositeFrame(this, 170, 20, 
00060                                              kHorizontalFrame | kFixedWidth);
00061    ok = new TGTextButton(cframe2, "OK");
00062    // to share whole parent space we need to use kLHintsExpandX layout hints
00063    cframe2->AddFrame(ok, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00064                                            3, 2, 2, 2));
00065    
00066    cancel = new TGTextButton(cframe2, "Cancel ");
00067    cframe2->AddFrame(cancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00068                                                3, 2, 2, 2));
00069    
00070    exit = new TGTextButton(cframe2, "&Exit ","gApplication->Terminate(0)");
00071    cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00072                                              2, 0, 2, 2));
00073    
00074    AddFrame(cframe2, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
00075    
00076    SetWindowName("Buttons' Layout");
00077    
00078    // gives min/max window size + a step of x,y incrementing 
00079    // between the given sizes
00080    SetWMSizeHints(200, 80, 320, 320, 1, 1);
00081    MapSubwindows();
00082    // important for layout algorithm
00083    Resize(GetDefaultSize());
00084    MapWindow();
00085 }
00086 
00087 
00088 MyMainFrame::~MyMainFrame()
00089 {
00090    // Clean up all widgets, frames and layouthints that were used
00091    Cleanup();
00092 }
00093 
00094 void buttonsLayout()
00095 {
00096    // Popup the GUI...
00097    new MyMainFrame(gClient->GetRoot(), 350, 80);
00098 }

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