Logo ROOT   6.16/01
Reference Guide
guilabels.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This macro gives an example of how to create different kind of labels and the possibility to enable/disable them.
4/// To run it do either:
5/// ~~~
6/// .x guilabels.C
7/// .x guilabels.C++
8/// ~~~
9///
10/// \macro_code
11///
12/// \author Ilka Antcheva 1/12/2006
13
14
15#include <TApplication.h>
16#include <TGClient.h>
17#include <TGButton.h>
18#include <TGLabel.h>
19#include <TGResourcePool.h>
20
21class MyMainFrame : public TGMainFrame {
22
23private:
24 TGLabel *fLbl1, *fLbl2, *fLbl3, *fLbl4;
25 TGTextButton *fToggle;
26public:
27 MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
28 virtual ~MyMainFrame();
29 void DoExit();
30 void DoSwitch();
31
32 ClassDef(MyMainFrame, 0)
33};
34
35void MyMainFrame::DoSwitch()
36{
37 if (fLbl1->IsDisabled()) {
38 printf("Enabled labels\n");
39 fLbl1->Enable();
40 fLbl2->Enable();
41 fLbl3->Enable();
42 fLbl4->Enable();
43 } else {
44 printf("Disabled labels\n");
45 fLbl1->Disable();
46 fLbl2->Disable();
47 fLbl3->Disable();
48 fLbl4->Disable();
49 }
50}
51
52void MyMainFrame::DoExit()
53{
54 Printf("Slot DoExit()");
56}
57
58MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
59 TGMainFrame(p, w, h)
60{
61
62 // label + horizontal line
63 TGGC *fTextGC;
64 const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-18-*-*-*-*-*-*-*");
65 if (!font)
66 font = gClient->GetResourcePool()->GetDefaultFont();
67 FontStruct_t labelfont = font->GetFontStruct();
68 GCValues_t gval;
70 gval.fFont = font->GetFontHandle();
71 gClient->GetColorByName("yellow", gval.fBackground);
72 fTextGC = gClient->GetGC(&gval, kTRUE);
73
74
75 ULong_t bcolor, ycolor;
76 gClient->GetColorByName("yellow", ycolor);
77 gClient->GetColorByName("blue", bcolor);
78
79 // Create a main frame
80 fLbl1 = new TGLabel(this, "OwnFont & Bck/ForgrColor", fTextGC->GetGC(),
81 labelfont, kChildFrame, bcolor);
82 AddFrame(fLbl1, new TGLayoutHints(kLHintsNormal, 5, 5, 3, 4));
83 fLbl1->SetTextColor(ycolor);
84
85 fLbl2 = new TGLabel(this, "Own Font & ForegroundColor", fTextGC->GetGC(),
86 labelfont);
87 AddFrame(fLbl2, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
88 fLbl2->SetTextColor(ycolor);
89
90 fLbl3 = new TGLabel(this, "Normal Label");
91 AddFrame(fLbl3, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
92
93 fLbl4 = new TGLabel(this, "Multi-line label, resized\nto 300x80 pixels",
94 fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
95 AddFrame(fLbl4, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
96 fLbl4->SetTextColor(ycolor);
97 fLbl4->ChangeOptions(fLbl4->GetOptions() | kFixedSize);
98 fLbl4->Resize(350, 80);
99
100 // Create a horizontal frame containing two buttons
101 TGTextButton *toggle = new TGTextButton(this, "&Toggle Labels");
102 toggle->Connect("Clicked()", "MyMainFrame", this, "DoSwitch()");
103 toggle->SetToolTipText("Click on the button to toggle label's state (enable/disable)");
104 AddFrame(toggle, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
105 TGTextButton *exit = new TGTextButton(this, "&Exit ");
106 exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
107 AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
108
109 // Set a name to the main frame
110 SetWindowName("Labels");
111 MapSubwindows();
112
113 // Initialize the layout algorithm via Resize()
114 Resize(GetDefaultSize());
115
116 // Map main frame
117 MapWindow();
118}
119
120MyMainFrame::~MyMainFrame()
121{
122 // Clean up main frame...
123 Cleanup();
124}
125
126void guilabels()
127{
128 // Popup the GUI...
129 new MyMainFrame(gClient->GetRoot(), 200, 200);
130}
const Mask_t kGCBackground
Definition: GuiTypes.h:288
const Mask_t kGCForeground
Definition: GuiTypes.h:287
const Mask_t kGCFont
Definition: GuiTypes.h:299
Handle_t FontStruct_t
Definition: GuiTypes.h:38
#define h(i)
Definition: RSha256.hxx:106
unsigned int UInt_t
Definition: RtypesCore.h:42
unsigned long ULong_t
Definition: RtypesCore.h:51
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:324
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
#define gClient
Definition: TGClient.h:166
@ kChildFrame
Definition: TGFrame.h:57
@ kFixedSize
Definition: TGFrame.h:68
@ kLHintsNormal
Definition: TGLayout.h:39
@ kLHintsCenterX
Definition: TGLayout.h:32
@ kLHintsExpandX
Definition: TGLayout.h:37
#define Printf
Definition: TGeoToOCC.h:18
virtual void Terminate(Int_t status=0)
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
Definition: TGFont.h:149
FontStruct_t GetFontStruct() const
Definition: TGFont.h:193
FontH_t GetFontHandle() const
Definition: TGFont.h:192
Definition: TGGC.h:31
GContext_t GetGC() const
Definition: TGGC.h:50
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:867
ULong_t fBackground
Definition: GuiTypes.h:227
Mask_t fMask
Definition: GuiTypes.h:250
FontH_t fFont
Definition: GuiTypes.h:241