ROOT logo
//
// Author: Ilka Antcheva   1/12/2006

// This macro gives an example of how to create different kind of labels
// and the possibility to enable/disable them.
// To run it do either:
// .x guilabels.C
// .x guilabels.C++

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGLabel.h>
#include <TGResourcePool.h>

class MyMainFrame : public TGMainFrame {

private:
   TGLabel       *fLbl1, *fLbl2, *fLbl3, *fLbl4;
   TGTextButton  *fToggle;
public:
   MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyMainFrame();
   void DoExit();
   void DoSwitch();

   ClassDef(MyMainFrame, 0)
};

void MyMainFrame::DoSwitch()
{
   if (fLbl1->IsDisabled()) {
   printf("Enabled labels\n");
      fLbl1->Enable();
      fLbl2->Enable();
      fLbl3->Enable();
      fLbl4->Enable();
   } else {
   printf("Disabled labels\n");
      fLbl1->Disable();
      fLbl2->Disable();
      fLbl3->Disable();
      fLbl4->Disable();
   }
}

void MyMainFrame::DoExit()
{
   Printf("Slot DoExit()");
   gApplication->Terminate(0);
}

MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
  TGMainFrame(p, w, h)
{

   // label + horizontal line
    TGGC *fTextGC;
    const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-18-*-*-*-*-*-*-*");
    if (!font)
       font = gClient->GetResourcePool()->GetDefaultFont();
    FontStruct_t labelfont = font->GetFontStruct();
    GCValues_t   gval;
    gval.fMask = kGCBackground | kGCFont | kGCForeground;
    gval.fFont = font->GetFontHandle();
    gClient->GetColorByName("yellow", gval.fBackground);
    fTextGC = gClient->GetGC(&gval, kTRUE);
   
   
   ULong_t bcolor, ycolor;
   gClient->GetColorByName("yellow", ycolor);
   gClient->GetColorByName("blue", bcolor);

   // Create a main frame
   fLbl1 = new TGLabel(this, "OwnFont & Bck/ForgrColor", fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
   AddFrame(fLbl1, new TGLayoutHints(kLHintsNormal, 5, 5, 3, 4));
   fLbl1->SetTextColor(ycolor);

   fLbl2 = new TGLabel(this, "Own Font & ForegroundColor", fTextGC->GetGC(), labelfont);
   AddFrame(fLbl2,  new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
   fLbl2->SetTextColor(ycolor);
   
   fLbl3 = new TGLabel(this, "Normal Label");
   AddFrame(fLbl3,  new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));

   fLbl4 = new TGLabel(this, "Multi-line label, resized\nto 300x80 pixels", 
                       fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
   AddFrame(fLbl4, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
   fLbl4->SetTextColor(ycolor);
   fLbl4->ChangeOptions(fLbl4->GetOptions() | kFixedSize);
   fLbl4->Resize(350, 80);

   // Create a horizontal frame containing two buttons
   TGTextButton *toggle = new TGTextButton(this, "&Toggle Labels");
   toggle->Connect("Clicked()", "MyMainFrame", this, "DoSwitch()");
   toggle->SetToolTipText("Click on the button to toggle label's state (enable/disable)");
   AddFrame(toggle, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
   TGTextButton *exit = new TGTextButton(this, "&Exit ");
   exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
   AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));

   // Set a name to the main frame
   SetWindowName("Labels");
   MapSubwindows();

   // Initialize the layout algorithm via Resize()
   Resize(GetDefaultSize());

   // Map main frame
   MapWindow();
}

MyMainFrame::~MyMainFrame()
{
   // Clean up main frame...
   Cleanup();
}

void guilabels()
{
   // Popup the GUI...
   new MyMainFrame(gClient->GetRoot(), 200, 200);
}
 guilabels.C:1
 guilabels.C:2
 guilabels.C:3
 guilabels.C:4
 guilabels.C:5
 guilabels.C:6
 guilabels.C:7
 guilabels.C:8
 guilabels.C:9
 guilabels.C:10
 guilabels.C:11
 guilabels.C:12
 guilabels.C:13
 guilabels.C:14
 guilabels.C:15
 guilabels.C:16
 guilabels.C:17
 guilabels.C:18
 guilabels.C:19
 guilabels.C:20
 guilabels.C:21
 guilabels.C:22
 guilabels.C:23
 guilabels.C:24
 guilabels.C:25
 guilabels.C:26
 guilabels.C:27
 guilabels.C:28
 guilabels.C:29
 guilabels.C:30
 guilabels.C:31
 guilabels.C:32
 guilabels.C:33
 guilabels.C:34
 guilabels.C:35
 guilabels.C:36
 guilabels.C:37
 guilabels.C:38
 guilabels.C:39
 guilabels.C:40
 guilabels.C:41
 guilabels.C:42
 guilabels.C:43
 guilabels.C:44
 guilabels.C:45
 guilabels.C:46
 guilabels.C:47
 guilabels.C:48
 guilabels.C:49
 guilabels.C:50
 guilabels.C:51
 guilabels.C:52
 guilabels.C:53
 guilabels.C:54
 guilabels.C:55
 guilabels.C:56
 guilabels.C:57
 guilabels.C:58
 guilabels.C:59
 guilabels.C:60
 guilabels.C:61
 guilabels.C:62
 guilabels.C:63
 guilabels.C:64
 guilabels.C:65
 guilabels.C:66
 guilabels.C:67
 guilabels.C:68
 guilabels.C:69
 guilabels.C:70
 guilabels.C:71
 guilabels.C:72
 guilabels.C:73
 guilabels.C:74
 guilabels.C:75
 guilabels.C:76
 guilabels.C:77
 guilabels.C:78
 guilabels.C:79
 guilabels.C:80
 guilabels.C:81
 guilabels.C:82
 guilabels.C:83
 guilabels.C:84
 guilabels.C:85
 guilabels.C:86
 guilabels.C:87
 guilabels.C:88
 guilabels.C:89
 guilabels.C:90
 guilabels.C:91
 guilabels.C:92
 guilabels.C:93
 guilabels.C:94
 guilabels.C:95
 guilabels.C:96
 guilabels.C:97
 guilabels.C:98
 guilabels.C:99
 guilabels.C:100
 guilabels.C:101
 guilabels.C:102
 guilabels.C:103
 guilabels.C:104
 guilabels.C:105
 guilabels.C:106
 guilabels.C:107
 guilabels.C:108
 guilabels.C:109
 guilabels.C:110
 guilabels.C:111
 guilabels.C:112
 guilabels.C:113
 guilabels.C:114
 guilabels.C:115
 guilabels.C:116
 guilabels.C:117
 guilabels.C:118
 guilabels.C:119
 guilabels.C:120
 guilabels.C:121
 guilabels.C:122
 guilabels.C:123
 guilabels.C:124