Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
splitterHorizontal.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 horizontal splitter.
4/// To run it do either:
5/// ~~~
6/// .x splitterHorizontal.C
7/// .x splitterHorizontal.C++
8/// ~~~
9///
10/// \macro_code
11///
12/// \author Ilka Antcheva 1/12/2006
13
14#include <TGClient.h>
15#include <TGButton.h>
16#include <TGLabel.h>
17#include <TGFrame.h>
18#include <TGLayout.h>
19#include <TGSplitter.h>
20
21class MyMainFrame : public TGMainFrame {
22
23public:
24 MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
25 ~MyMainFrame() override;
26 void DoSave();
27 void CloseWindow() override;
28
29 ClassDefOverride(MyMainFrame, 0)
30};
31
32void MyMainFrame::DoSave()
33{
34 //------ TGMainFrame::SaveSource() --------
35 Printf("Save in progress...");
36 SaveSource("", "");
37}
38
39MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
40{
41 // Create horizontal splitter
42 TGVerticalFrame *fVf = new TGVerticalFrame(this, 10, 10);
43
44 TGHorizontalFrame *fH1 = new TGHorizontalFrame(fVf, 10, 50, kFixedHeight);
45 TGHorizontalFrame *fH2 = new TGHorizontalFrame(fVf, 10, 10);
46 TGCompositeFrame *fFtop = new TGCompositeFrame(fH1, 10, 10, kSunkenFrame);
47 TGCompositeFrame *fFbottom = new TGCompositeFrame(fH2, 10, 10, kSunkenFrame);
48
49 TGLabel *fLtop = new TGLabel(fFtop, "Top Frame");
50 TGLabel *fLbottom = new TGLabel(fFbottom, "Bottom Frame");
51
52 fFtop->AddFrame(fLtop, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 0, 0));
53 fFbottom->AddFrame(fLbottom, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 0, 0));
54
55 fH1->AddFrame(fFtop, new TGLayoutHints(kLHintsTop | kLHintsExpandY | kLHintsExpandX, 0, 0, 1, 2));
56 fH2->AddFrame(fFbottom, new TGLayoutHints(kLHintsTop | kLHintsExpandY | kLHintsExpandX, 0, 0, 1, 2));
57
58 fH1->Resize(fFtop->GetDefaultWidth(), fH1->GetDefaultHeight() + 20);
59 fH2->Resize(fFbottom->GetDefaultWidth(), fH2->GetDefaultHeight() + 20);
61
62 TGHSplitter *hsplitter = new TGHSplitter(fVf, 2, 2);
63 hsplitter->SetFrame(fH1, kTRUE);
64 fVf->AddFrame(hsplitter, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
65
67
68 // button frame
69 TGVerticalFrame *hframe = new TGVerticalFrame(this, 10, 10);
70 TGCompositeFrame *cframe2 = new TGCompositeFrame(hframe, 170, 50, kHorizontalFrame | kFixedWidth);
71 TGTextButton *save = new TGTextButton(cframe2, "&Save");
72 cframe2->AddFrame(save, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 3, 2, 2, 2));
73 save->Connect("Clicked()", "MyMainFrame", this, "DoSave()");
74 save->SetToolTipText("Click on the button to save the application as C++ macro");
75
76 TGTextButton *exit = new TGTextButton(cframe2, "&Exit ", "gApplication->Terminate(0)");
77 cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 2, 2));
78 hframe->AddFrame(cframe2, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
79
81 AddFrame(hframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
82
83 // What to clean up in dtor
84 SetCleanup(kDeepCleanup);
85
86 // Set a name to the main frame
87 SetWindowName("Horizontal Splitter");
88 SetWMSizeHints(300, 250, 600, 600, 0, 0);
90 Resize(GetDefaultSize());
91 MapWindow();
92}
93
94MyMainFrame::~MyMainFrame()
95{
96 // Clean up all widgets, frames and layouthints that were used
97 Cleanup();
98}
99
100//______________________________________________________________________________
101void MyMainFrame::CloseWindow()
102{
103 // Called when window is closed via the window manager.
104
105 delete this;
106}
107
108void splitterHorizontal()
109{
110 // Popup the GUI...
111
112 new MyMainFrame(gClient->GetRoot(), 300, 250);
113}
@ kSunkenFrame
Definition GuiTypes.h:383
@ kFixedWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kFixedHeight
Definition GuiTypes.h:389
#define h(i)
Definition RSha256.hxx:106
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:445
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:312
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:314
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
void SetFrame(TGFrame *frame, Bool_t above) override
Set frame to be resized.
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
virtual void CloseWindow()
Close and delete main frame.
Definition TGFrame.cxx:1770
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
ROOT GUI Window base class.
Definition TGWindow.h:23
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:869