Logo ROOT  
Reference Guide
splitterVertical.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// This macro gives an example of how to create a vertical splitter.
4 /// To run it do either:
5 /// ~~~
6 /// .x splitterVertical.C
7 /// .x splitterVertical.C++
8 /// ~~~
9 ///
10 /// \macro_code
11 ///
12 /// \author Ilka Antcheva 1/12/2006
13 
14 
15 #include <TGClient.h>
16 #include <TGButton.h>
17 #include <TGLabel.h>
18 #include <TGFrame.h>
19 #include <TGLayout.h>
20 #include <TGSplitter.h>
21 
22 
23 class MyMainFrame : public TGMainFrame {
24 
25 public:
26  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
27  virtual ~MyMainFrame();
28  void DoSave();
29  void CloseWindow();
30 
31  ClassDef(MyMainFrame, 0)
32 };
33 
34 //______________________________________________________________________________
35 void MyMainFrame::DoSave()
36 {
37  Printf("Save in progress...");
38  SaveSource("","");
39 }
40 
41 //______________________________________________________________________________
42 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
43  TGMainFrame(p, w, h)
44 {
45  // Create vertical splitter
46 
47  TGHorizontalFrame *fHf = new TGHorizontalFrame(this, 50, 50);
48 
49  TGVerticalFrame *fV1 = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
50  TGVerticalFrame *fV2 = new TGVerticalFrame(fHf, 10, 10);
51  TGCompositeFrame *fFleft = new TGCompositeFrame(fV1, 10, 10, kSunkenFrame);
52  TGCompositeFrame *fFright = new TGCompositeFrame(fV2, 10, 10, kSunkenFrame);
53 
54  TGLabel *fLleft = new TGLabel(fFleft, "Left Frame");
55  TGLabel *fLright = new TGLabel(fFright, "Right Frame");
56 
57  fFleft->AddFrame(fLleft, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
58  3, 0, 0, 0));
59  fFright->AddFrame(fLright, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
60  3, 0, 0, 0));
61 
63  0, 0, 5, 10));
65  0, 0, 5, 10));
66 
67  fV1->Resize(fFleft->GetDefaultWidth()+20, fV1->GetDefaultHeight());
68  fV2->Resize(fFright->GetDefaultWidth(), fV1->GetDefaultHeight());
70 
71  TGVSplitter *splitter = new TGVSplitter(fHf,2,2);
72  splitter->SetFrame(fV1, kTRUE);
74 
77  AddFrame(fHf, new TGLayoutHints(kLHintsRight | kLHintsExpandX |
79 
80  // button frame
81  TGVerticalFrame *vframe = new TGVerticalFrame(this, 10, 10);
82  TGCompositeFrame *cframe2 = new TGCompositeFrame(vframe, 170, 20,
84  TGTextButton *save = new TGTextButton(cframe2, "&Save");
85  cframe2->AddFrame(save, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
86  3, 2, 2, 2));
87  save->Connect("Clicked()", "MyMainFrame", this, "DoSave()");
88  save->SetToolTipText("Click on the button to save the application as C++ macro");
89 
90  TGTextButton *exit = new TGTextButton(cframe2, "&Exit ","gApplication->Terminate(0)");
91  cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
92  2, 0, 2, 2));
93  vframe->AddFrame(cframe2, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
94  AddFrame(vframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
95 
96  // What to clean up in destructor
97  SetCleanup(kDeepCleanup);
98 
99  // Set a name to the main frame
100  SetWindowName("Vertical Splitter");
101  SetWMSizeHints(350, 200, 600, 400, 0, 0);
102  MapSubwindows();
103  Resize(GetDefaultSize());
104  MapWindow();
105 }
106 
107 
108 //______________________________________________________________________________
109 MyMainFrame::~MyMainFrame()
110 {
111  // Clean up all widgets, frames and layouthints that were used
112  Cleanup();
113 }
114 
115 //______________________________________________________________________________
116 void MyMainFrame::CloseWindow()
117 {
118  // Called when window is closed via the window manager.
119 
120  delete this;
121 }
122 
123 void splitterVertical()
124 {
125  // Popup the GUI...
126  new MyMainFrame(gClient->GetRoot(), 350, 200);
127 }
TGButton::SetToolTipText
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:398
TGWindow
Definition: TGWindow.h:31
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
kFixedWidth
@ kFixedWidth
Definition: GuiTypes.h:387
TGMainFrame
Definition: TGFrame.h:443
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:34
TGLayout.h
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:31
TGLabel
Definition: TGLabel.h:32
TGTextButton
Definition: TGButton.h:142
TGHorizontalFrame
Definition: TGFrame.h:422
gClient
#define gClient
Definition: TGClient.h:166
kSunkenFrame
@ kSunkenFrame
Definition: GuiTypes.h:383
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:35
h
#define h(i)
Definition: RSha256.hxx:106
TGVerticalFrame
Definition: TGFrame.h:411
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TGFrame.h
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:33
TGLayoutHints
Definition: TGLayout.h:57
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:38
TGClient.h
TGMainFrame::CloseWindow
virtual void CloseWindow()
Close and delete main frame.
Definition: TGFrame.cxx:1731
TGCompositeFrame::GetDefaultHeight
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:350
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
Printf
void Printf(const char *fmt,...)
TGLabel.h
TQObject::Connect
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:866
TGSplitter.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:50
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:37
TGCompositeFrame::GetDefaultWidth
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:348
TGVSplitter
Definition: TGSplitter.h:63
TGCompositeFrame
Definition: TGFrame.h:323
splitter
REAL splitter
Definition: triangle.c:616
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102