Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLabel.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 06/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGLabel
13 #define ROOT_TGLabel
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGLabel //
19 // //
20 // This class handles GUI labels. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TGFrame.h"
25 #include "TGDimension.h"
26 #include "TGString.h"
27 
28 class TColor;
29 class TGTextLayout;
30 class TGFont;
31 
32 class TGLabel : public TGFrame {
33 
34 protected:
35  TGString *fText; // label text
36  UInt_t fTWidth; // text width
37  UInt_t fTHeight; // text height
38  Int_t fMLeft; // margin left
39  Int_t fMRight; // margin right
40  Int_t fMTop; // margin top
41  Int_t fMBottom; // margin bottom
42  Int_t fTMode; // text alignment
43  Int_t f3DStyle; // 3D style (0 - normal, kRaisedFrame - raised, kSunkenFrame - sunken)
44  Int_t fWrapLength; // wrap length
45  Int_t fTFlags; // text flags (see TGFont.h ETextLayoutFlags)
46  Bool_t fTextChanged; // has text changed
47  GContext_t fNormGC; // graphics context used for drawing label
48  TGFont *fFont; // font to draw label
49  TGTextLayout *fTLayout; // text layout
50  Bool_t fHasOwnFont; // kTRUE - font defined locally, kFALSE - globally
51  Bool_t fDisabled; // if kTRUE label looks disabled (shaded text)
52 
53  virtual void DoRedraw();
54  virtual void DrawText(GContext_t gc, Int_t x, Int_t y);
55 
56  static const TGFont *fgDefaultFont;
57  static const TGGC *fgDefaultGC;
58 
59 private:
60  TGLabel(const TGLabel&); // not implemented
61  TGLabel& operator=(const TGLabel&); // not implemented
62 
63 public:
64  static FontStruct_t GetDefaultFontStruct();
65  static const TGGC &GetDefaultGC();
66 
67  TGLabel(const TGWindow *p, TGString *text,
68  GContext_t norm = GetDefaultGC()(),
69  FontStruct_t font = GetDefaultFontStruct(),
70  UInt_t options = kChildFrame,
71  Pixel_t back = GetDefaultFrameBackground());
72  TGLabel(const TGWindow *p = 0, const char *text = 0,
73  GContext_t norm = GetDefaultGC()(),
74  FontStruct_t font = GetDefaultFontStruct(),
75  UInt_t options = kChildFrame,
76  Pixel_t back = GetDefaultFrameBackground());
77 
78  virtual ~TGLabel();
79 
80  virtual TGDimension GetDefaultSize() const;
81 
82  const TGString *GetText() const { return fText; }
83  virtual const char *GetTitle() const { return fText->Data(); }
84  virtual void SetText(TGString *newText);
85  void SetText(const char *newText) { SetText(new TGString(newText)); }
86  virtual void ChangeText(const char *newText) { SetText(newText); } //*MENU*icon=bld_rename.png*
87  virtual void SetTitle(const char *label) { SetText(label); }
88  void SetText(Int_t number) { SetText(new TGString(number)); }
89  void SetTextJustify(Int_t tmode);
90  Int_t GetTextJustify() const { return fTMode; }
91  virtual void SetTextFont(TGFont *font, Bool_t global = kFALSE);
92  virtual void SetTextFont(FontStruct_t font, Bool_t global = kFALSE);
93  virtual void SetTextFont(const char *fontName, Bool_t global = kFALSE);
94  virtual void SetTextColor(Pixel_t color, Bool_t global = kFALSE);
95  virtual void SetTextColor(TColor *color, Bool_t global = kFALSE);
96  virtual void SetForegroundColor(Pixel_t fore) { SetTextColor(fore); }
97  virtual void Disable(Bool_t on = kTRUE)
98  { fDisabled = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=IsDisabled
99  virtual void Enable() { fDisabled = kFALSE; fClient->NeedRedraw(this); }
100  Bool_t IsDisabled() const { return fDisabled; }
101  Bool_t HasOwnFont() const;
102 
103  void SetWrapLength(Int_t wl) { fWrapLength = wl; Layout(); }
104  Int_t GetWrapLength() const { return fWrapLength; }
105 
106  void Set3DStyle(Int_t style) { f3DStyle = style; fClient->NeedRedraw(this); }
107  Int_t Get3DStyle() const { return f3DStyle; }
108 
109  void SetMargins(Int_t left=0, Int_t right=0, Int_t top=0, Int_t bottom=0)
110  { fMLeft = left; fMRight = right; fMTop = top; fMBottom = bottom; }
111  Int_t GetLeftMargin() const { return fMLeft; }
112  Int_t GetRightMargin() const { return fMRight; }
113  Int_t GetTopMargin() const { return fMTop; }
114  Int_t GetBottomMargin() const { return fMBottom; }
115 
116  GContext_t GetNormGC() const { return fNormGC; }
117  FontStruct_t GetFontStruct() const { return fFont->GetFontStruct(); }
118  TGFont *GetFont() const { return fFont; }
119 
120  virtual void Layout();
121  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
122 
123  ClassDef(TGLabel,0) // A label GUI element
124 };
125 
126 #endif