Logo ROOT   6.08/07
Reference Guide
TGPicture.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 01/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_TGPicture
13 #define ROOT_TGPicture
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGPicture, TGSelectdPicture & TGPicturePool //
19 // //
20 // The TGPicture class implements pictures and icons used in the //
21 // different GUI elements and widgets. The TGPicturePool class //
22 // implements a TGPicture cache. TGPictures are created, managed and //
23 // destroyed by the TGPicturePool. //
24 // //
25 //////////////////////////////////////////////////////////////////////////
26 
27 #ifndef ROOT_TObject
28 #include "TObject.h"
29 #endif
30 #ifndef ROOT_TRefCnt
31 #include "TRefCnt.h"
32 #endif
33 #ifndef ROOT_TString
34 #include "TString.h"
35 #endif
36 #ifndef ROOT_TGClient
37 #include "TGClient.h"
38 #endif
39 #ifndef ROOT_TGGC
40 #include "TGGC.h"
41 #endif
42 
43 class THashTable;
44 
45 
46 class TGPicture : public TObject, public TRefCnt {
47 
48 friend class TGPicturePool;
49 
50 protected:
51  TString fName; // name of picture
52  Bool_t fScaled; // kTRUE if picture is scaled
53  Pixmap_t fPic; // picture pixmap
54  Pixmap_t fMask; // picture mask pixmap
55  PictureAttributes_t fAttributes; // picture attributes
56 
57  TGPicture(const char *name, Bool_t scaled = kFALSE):
58  fName(name), fScaled(scaled), fPic(kNone), fMask(kNone), fAttributes()
59  {
60  fAttributes.fPixels = 0;
61  SetRefCount(1);
62  }
63 
64  TGPicture(const char *name, Pixmap_t pxmap, Pixmap_t mask = 0);
65 
66  // override default of TObject
67  void Draw(Option_t * = "") { MayNotUse("Draw(Option_t*)"); }
68 
69 public:
70  virtual ~TGPicture();
71 
72  const char *GetName() const { return fName; }
73  UInt_t GetWidth() const { return fAttributes.fWidth; }
74  UInt_t GetHeight() const { return fAttributes.fHeight; }
75  Pixmap_t GetPicture() const { return fPic; }
76  Pixmap_t GetMask() const { return fMask; }
77  Bool_t IsScaled() const { return fScaled; }
78  ULong_t Hash() const { return fName.Hash(); }
79  static const char *HashName(const char *name, Int_t width, Int_t height);
80 
81  virtual void Draw(Handle_t id, GContext_t gc, Int_t x, Int_t y) const;
82  void Print(Option_t *option="") const;
83 
84  ClassDef(TGPicture,0) // Pictures and icons used by the GUI classes
85 };
86 
87 
88 class TGSelectedPicture : public TGPicture {
89 
90 protected:
91  const TGClient *fClient; // client to which selected picture belongs
92 
93  static TGGC *fgSelectedGC;
94  static TGGC &GetSelectedGC();
95 
97  TGPicture(gp), fClient(gp.fClient) { }
99  {if(this!=&gp) { TGPicture::operator=(gp); fClient=gp.fClient;}
100  return *this;}
101 
102 public:
103  TGSelectedPicture(const TGClient *client, const TGPicture *p);
104  virtual ~TGSelectedPicture();
105 
106  ClassDef(TGSelectedPicture,0) // Selected looking picture
107 };
108 
109 
110 class TGPicturePool : public TObject {
111 
112 protected:
113  const TGClient *fClient; // client for which we keep icon pool
114  TString fPath; // icon search path
115  THashTable *fPicList; // hash table containing the icons
116 
119 
120 public:
121  TGPicturePool(const TGClient *client, const char *path):
122  fClient(client), fPath(path), fPicList(0) { }
123  virtual ~TGPicturePool();
124 
125  const char *GetPath() const { return fPath; }
126  const TGPicture *GetPicture(const char *name);
127  const TGPicture *GetPicture(const char *name, char **xpm);
128  const TGPicture *GetPicture(const char *name, UInt_t new_width, UInt_t new_height);
129  const TGPicture *GetPicture(const char *name, Pixmap_t pxmap, Pixmap_t mask = 0);
130  void FreePicture(const TGPicture *pic);
131 
132  void Print(Option_t *option="") const;
133 
134  ClassDef(TGPicturePool,0) // Picture and icon cache
135 };
136 
137 #endif
static const char * HashName(const char *name, Int_t width, Int_t height)
Static function returning a unique name used to look up a picture.
Definition: TGPicture.cxx:371
friend class TGPicturePool
Definition: TGPicture.h:48
const char * GetName() const
Returns name of object.
Definition: TGPicture.h:72
const char Option_t
Definition: RtypesCore.h:62
Definitions for TRefCnt, base class for reference counted objects.
Definition: TRefCnt.h:29
ULong_t * fPixels
Definition: GuiTypes.h:331
Handle_t GContext_t
Definition: GuiTypes.h:39
const char * GetPath() const
Definition: TGPicture.h:125
Bool_t IsScaled() const
Definition: TGPicture.h:77
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
PictureAttributes_t fAttributes
Definition: TGPicture.h:55
const TGClient * fClient
Definition: TGPicture.h:113
TGPicturePool(const TGClient *client, const char *path)
Definition: TGPicture.h:121
UInt_t GetHeight() const
Definition: TGPicture.h:74
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:606
TGSelectedPicture(const TGSelectedPicture &gp)
Definition: TGPicture.h:96
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:67
THashTable implements a hash table to store TObject's.
Definition: THashTable.h:39
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
static TGGC * fgSelectedGC
Definition: TGPicture.h:93
ULong_t Hash() const
Return hash value for this object.
Definition: TGPicture.h:78
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:978
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:103
TString fPath
Definition: TGPicture.h:114
Pixmap_t GetPicture() const
Definition: TGPicture.h:75
void SetRefCount(UInt_t r)
Definition: TRefCnt.h:41
virtual ~TGPicture()
Delete picture object.
Definition: TGPicture.cxx:357
unsigned int UInt_t
Definition: RtypesCore.h:42
const Handle_t kNone
Definition: GuiTypes.h:89
Bool_t fScaled
Definition: TGPicture.h:52
THashTable * fPicList
Definition: TGPicture.h:115
TGSelectedPicture & operator=(const TGSelectedPicture &gp)
Definition: TGPicture.h:98
Pixmap_t fMask
Definition: TGPicture.h:54
unsigned long ULong_t
Definition: RtypesCore.h:51
void Print(Option_t *option="") const
Print picture info.
Definition: TGPicture.cxx:382
TGPicture(const char *name, Bool_t scaled=kFALSE)
Definition: TGPicture.h:57
Double_t y[n]
Definition: legend1.C:17
UInt_t GetWidth() const
Definition: TGPicture.h:73
TString fName
Definition: TGPicture.h:51
Mother of all ROOT objects.
Definition: TObject.h:37
Handle_t Pixmap_t
Definition: GuiTypes.h:31
Pixmap_t GetMask() const
Definition: TGPicture.h:76
Pixmap_t fPic
Definition: TGPicture.h:53
Definition: TGGC.h:35
char name[80]
Definition: TGX11.cxx:109
const TGClient * fClient
Definition: TGPicture.h:91
ULong_t Handle_t
Definition: GuiTypes.h:27