Logo ROOT   6.12/07
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 
21 class MyMainFrame : public TGMainFrame {
22 
23 private:
24  TGLabel *fLbl1, *fLbl2, *fLbl3, *fLbl4;
25  TGTextButton *fToggle;
26 public:
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 
35 void 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 
52 void MyMainFrame::DoExit()
53 {
54  Printf("Slot DoExit()");
56 }
57 
58 MyMainFrame::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 
120 MyMainFrame::~MyMainFrame()
121 {
122  // Clean up main frame...
123  Cleanup();
124 }
125 
126 void guilabels()
127 {
128  // Popup the GUI...
129  new MyMainFrame(gClient->GetRoot(), 200, 200);
130 }
Handle_t FontStruct_t
Definition: GuiTypes.h:38
FontH_t fFont
Definition: GuiTypes.h:241
TH1 * h
Definition: legend2.C:5
#define gClient
Definition: TGClient.h:166
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
#define ClassDef(name, id)
Definition: Rtypes.h:320
const Mask_t kGCFont
Definition: GuiTypes.h:299
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
unsigned int UInt_t
Definition: RtypesCore.h:42
#define Printf
Definition: TGeoToOCC.h:18
ULong_t fBackground
Definition: GuiTypes.h:227
GContext_t GetGC() const
Definition: TGGC.h:50
Definition: TGFont.h:149
unsigned long ULong_t
Definition: RtypesCore.h:51
FontStruct_t GetFontStruct() const
Definition: TGFont.h:193
const Mask_t kGCForeground
Definition: GuiTypes.h:287
Mask_t fMask
Definition: GuiTypes.h:250
const Mask_t kGCBackground
Definition: GuiTypes.h:288
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
Definition: TGGC.h:31
FontH_t GetFontHandle() const
Definition: TGFont.h:192