guilabels.C

Go to the documentation of this file.
00001 //
00002 // Author: Ilka Antcheva   1/12/2006
00003 
00004 // This macro gives an example of how to create different kind of labels
00005 // and the possibility to enable/disable them.
00006 // To run it do either:
00007 // .x guilabels.C
00008 // .x guilabels.C++
00009 
00010 #include <TApplication.h>
00011 #include <TGClient.h>
00012 #include <TGButton.h>
00013 #include <TGLabel.h>
00014 #include <TGResourcePool.h>
00015 
00016 class MyMainFrame : public TGMainFrame {
00017 
00018 private:
00019    TGLabel       *fLbl1, *fLbl2, *fLbl3, *fLbl4;
00020    TGTextButton  *fToggle;
00021 public:
00022    MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
00023    virtual ~MyMainFrame();
00024    void DoExit();
00025    void DoSwitch();
00026 
00027    ClassDef(MyMainFrame, 0)
00028 };
00029 
00030 void MyMainFrame::DoSwitch()
00031 {
00032    if (fLbl1->IsDisabled()) {
00033    printf("Enabled labels\n");
00034       fLbl1->Enable();
00035       fLbl2->Enable();
00036       fLbl3->Enable();
00037       fLbl4->Enable();
00038    } else {
00039    printf("Disabled labels\n");
00040       fLbl1->Disable();
00041       fLbl2->Disable();
00042       fLbl3->Disable();
00043       fLbl4->Disable();
00044    }
00045 }
00046 
00047 void MyMainFrame::DoExit()
00048 {
00049    Printf("Slot DoExit()");
00050    gApplication->Terminate(0);
00051 }
00052 
00053 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
00054   TGMainFrame(p, w, h)
00055 {
00056 
00057    // label + horizontal line
00058     TGGC *fTextGC;
00059     const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-18-*-*-*-*-*-*-*");
00060     if (!font)
00061        font = gClient->GetResourcePool()->GetDefaultFont();
00062     FontStruct_t labelfont = font->GetFontStruct();
00063     GCValues_t   gval;
00064     gval.fMask = kGCBackground | kGCFont | kGCForeground;
00065     gval.fFont = font->GetFontHandle();
00066     gClient->GetColorByName("yellow", gval.fBackground);
00067     fTextGC = gClient->GetGC(&gval, kTRUE);
00068    
00069    
00070    ULong_t bcolor, ycolor;
00071    gClient->GetColorByName("yellow", ycolor);
00072    gClient->GetColorByName("blue", bcolor);
00073 
00074    // Create a main frame
00075    fLbl1 = new TGLabel(this, "OwnFont & Bck/ForgrColor", fTextGC->GetGC(),
00076                        labelfont, kChildFrame, bcolor);
00077    AddFrame(fLbl1, new TGLayoutHints(kLHintsNormal, 5, 5, 3, 4));
00078    fLbl1->SetTextColor(ycolor);
00079 
00080    fLbl2 = new TGLabel(this, "Own Font & ForegroundColor", fTextGC->GetGC(),
00081                        labelfont);
00082    AddFrame(fLbl2,  new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
00083    fLbl2->SetTextColor(ycolor);
00084    
00085    fLbl3 = new TGLabel(this, "Normal Label");
00086    AddFrame(fLbl3,  new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
00087 
00088    fLbl4 = new TGLabel(this, "Multi-line label, resized\nto 300x80 pixels", 
00089                        fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
00090    AddFrame(fLbl4, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
00091    fLbl4->SetTextColor(ycolor);
00092    fLbl4->ChangeOptions(fLbl4->GetOptions() | kFixedSize);
00093    fLbl4->Resize(350, 80);
00094 
00095    // Create a horizontal frame containing two buttons
00096    TGTextButton *toggle = new TGTextButton(this, "&Toggle Labels");
00097    toggle->Connect("Clicked()", "MyMainFrame", this, "DoSwitch()");
00098    toggle->SetToolTipText("Click on the button to toggle label's state (enable/disable)");
00099    AddFrame(toggle, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
00100    TGTextButton *exit = new TGTextButton(this, "&Exit ");
00101    exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
00102    AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
00103 
00104    // Set a name to the main frame
00105    SetWindowName("Labels");
00106    MapSubwindows();
00107 
00108    // Initialize the layout algorithm via Resize()
00109    Resize(GetDefaultSize());
00110 
00111    // Map main frame
00112    MapWindow();
00113 }
00114 
00115 MyMainFrame::~MyMainFrame()
00116 {
00117    // Clean up main frame...
00118    Cleanup();
00119 }
00120 
00121 void guilabels()
00122 {
00123    // Popup the GUI...
00124    new MyMainFrame(gClient->GetRoot(), 200, 200);
00125 }

Generated on Tue Jul 5 15:44:23 2011 for ROOT_528-00b_version by  doxygen 1.5.1