Logo ROOT  
Reference Guide
TGResourcePool.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 19/5/2003
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2003, 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 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 
24 //////////////////////////////////////////////////////////////////////////
25 // //
26 // TGResourcePool //
27 // //
28 // This class implements a pool for the default GUI resource set, //
29 // like GC's, colors, fonts, etc.. //
30 // //
31 //////////////////////////////////////////////////////////////////////////
32 
33 #include "RConfigure.h"
34 
35 #include "TGResourcePool.h"
36 #include "TGWindow.h"
37 #include "TROOT.h"
38 #include "TSystem.h"
39 #include "TEnv.h"
40 #include "TVirtualX.h"
41 #include "TGGC.h"
42 #include "TGPicture.h"
43 #include "TGFont.h"
44 #include "TGMimeTypes.h"
45 
46 
47 const int gray_width = 8;
48 const int gray_height = 8;
49 static unsigned char gray_bits[] = {
50  0x55, 0xaa, 0x55, 0xaa,
51  0x55, 0xaa, 0x55, 0xaa
52 };
53 
54 
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Create the global GUI resource pool manager.
59 
61 {
62  fClient = client;
63  fDefaultColormap = gVirtualX->GetColormap();
64 
65  // Get GUI defaults from [system].rootrc
66  TString default_font = gEnv->GetValue("Gui.DefaultFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
67  TString menu_font = gEnv->GetValue("Gui.MenuFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
68  TString menu_hi_font = gEnv->GetValue("Gui.MenuHiFont", "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
69  TString doc_fixed_font = gEnv->GetValue("Gui.DocFixedFont", "-*-courier-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
70  TString doc_prop_font = gEnv->GetValue("Gui.DocPropFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
71  TString icon_font = gEnv->GetValue("Gui.IconFont", "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
72  TString status_font = gEnv->GetValue("Gui.StatusFont", "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
73  TString backcolor = gEnv->GetValue("Gui.BackgroundColor", "#e0e0e0");
74  TString forecolor = gEnv->GetValue("Gui.ForegroundColor", "black");
75  TString highlightcolor = gEnv->GetValue("Gui.HighLightColor", "#d0d0d0");
76  TString selbackcolor = gEnv->GetValue("Gui.SelectBackgroundColor", "#86abd9");
77  TString selforecolor = gEnv->GetValue("Gui.SelectForegroundColor", "white");
78  TString docbackcolor = gEnv->GetValue("Gui.DocumentBackgroundColor", "white");
79  TString docforecolor = gEnv->GetValue("Gui.DocumentForegroundColor", "black");
80  TString tipbackcolor = gEnv->GetValue("Gui.TooltipBackgroundColor", "LightYellow");
81  TString tipforecolor = gEnv->GetValue("Gui.TooltipForegroundColor", "black");
82  TString framebgpixmap = gEnv->GetValue("Gui.FrameBackgroundPixmap", "");
83  TString docbgpixmap = gEnv->GetValue("Gui.DocumentBackgroundPixmap", "");
84 
85  TString icon_path = gEnv->GetValue("Gui.IconPath", "");
86  if (icon_path.IsNull()) {
87  icon_path = "icons";
89 #ifndef R__WIN32
90  icon_path = ".:" + icon_path + ":" + TROOT::GetIconPath() + ":" + EXTRAICONPATH;
91 #else
92  icon_path = ".;" + icon_path + ";" + TROOT::GetIconPath() + ";" + EXTRAICONPATH;
93 #endif
94  }
95 
96  TString mime_file = ".root.mimes";
98  mime_file = gEnv->GetValue("Gui.MimeTypeFile", mime_file.Data());
99  gSystem->ExpandPathName(mime_file);
100 
101  if (gSystem->AccessPathName(mime_file, kReadPermission)) {
102  mime_file = "root.mimes";
104  }
105 
106  // Setup colors...
107  fClient->GetColorByName("white", fWhite); // white and black always exist
108  fClient->GetColorByName("black", fBlack);
109  if (!fClient->GetColorByName(backcolor, fBackColor))
110  fBackColor = fWhite;
111  if (!fClient->GetColorByName(forecolor, fForeColor))
112  fForeColor = fBlack;
113  if (!fClient->GetColorByName(highlightcolor, fHighLightColor))
117  if (!fClient->GetColorByName(selbackcolor, fSelBackColor))
119  if (!fClient->GetColorByName(selforecolor, fSelForeColor))
121  if (!fClient->GetColorByName(docbackcolor, fDocBackColor))
123  if (!fClient->GetColorByName(docforecolor, fDocForeColor))
125  if (!fClient->GetColorByName(tipbackcolor, fTipBackColor))
127  if (!fClient->GetColorByName(tipforecolor, fTipForeColor))
129 
130  // Setup checkered pix/bit-maps...
131  fCheckered = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
132  (const char *)gray_bits,
134  fBackColor, fWhite /*fHilite*/,
135  gVirtualX->GetDepth());
136  fCheckeredBitmap = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
137  (const char *)gray_bits,
139  1, 0, 1);
140 
141  // Create picture pool, GC pool, font pool, mime type list, etc.
142 
143  // Create picture pool and pre-load some pictures...
144  fPicturePool = new TGPicturePool(fClient, icon_path);
145 
148  if (!framebgpixmap.IsNull())
149  fDefaultBackPicture = fPicturePool->GetPicture(framebgpixmap);
150  if (!docbgpixmap.IsNull())
152 
153  // Create font pool and pre-load some fonts...
155  fDefaultFont = fFontPool->GetFont(default_font);
156  fMenuFont = fFontPool->GetFont(menu_font);
157  fMenuHiFont = fFontPool->GetFont(menu_hi_font);
158  fDocFixedFont = fFontPool->GetFont(doc_fixed_font);
159  fDocPropFont = fFontPool->GetFont(doc_prop_font);
160  fIconFont = fFontPool->GetFont(icon_font);
161  fStatusFont = fFontPool->GetFont(status_font);
162 
163  // Create GC pool and pre-load some GCs...
164  fGCPool = new TGGCPool(fClient);
165 
166  GCValues_t gval;
169  gval.fGraphicsExposures = kFALSE;
170  gval.fFillStyle = kFillSolid;
172  gval.fBackground = fBackColor;
173  gval.fForeground = fBlack;
174  fBlackGC = fGCPool->GetGC(&gval, kTRUE);
175 
176  gval.fForeground = fWhite;
177  fWhiteGC = fGCPool->GetGC(&gval, kTRUE);
178 
179  gval.fForeground = fHilite;
180  fHiliteGC = fGCPool->GetGC(&gval, kTRUE);
181 
182  gval.fForeground = fShadow;
183  fShadowGC = fGCPool->GetGC(&gval, kTRUE);
184 
185  gval.fForeground = fBackColor;
186  fBckgndGC = fGCPool->GetGC(&gval, kTRUE);
187 
188  gval.fForeground = fForeColor;
189  fFrameGC = fGCPool->GetGC(&gval, kTRUE);
190 
191  gval.fForeground = fSelBackColor;
192  fSelbgndGC = fGCPool->GetGC(&gval, kTRUE);
193 
194  gval.fForeground = fSelForeColor;
195  gval.fBackground = fSelBackColor;
196  fSelGC = fGCPool->GetGC(&gval, kTRUE);
197 
199  gval.fForeground = fDocForeColor;
200  gval.fBackground = fDocBackColor;
201  fDocGC = fGCPool->GetGC(&gval, kTRUE);
202 
203  gval.fForeground = fDocBackColor;
204  fDocbgndGC = fGCPool->GetGC(&gval, kTRUE);
205 
207  gval.fForeground = fTipForeColor;
208  gval.fBackground = fTipBackColor;
209  fTipGC = fGCPool->GetGC(&gval, kTRUE);
210 
214  gval.fForeground = fBlack;
215  gval.fBackground = fSelBackColor;
216  gval.fLineWidth = 0;
217  gval.fFillStyle = kFillStippled;
219  gval.fGraphicsExposures = kFALSE;
220  gval.fStipple = fCheckeredBitmap;
221  fFocusGC = fGCPool->GetGC(&gval, kTRUE);
222 
223  // Setup cursors...
225  fGrabCursor = gVirtualX->CreateCursor(kArrowRight);
226  fTextCursor = gVirtualX->CreateCursor(kCaret);
227  fWaitCursor = gVirtualX->CreateCursor(kWatch);
228 
229  // Read in mime type...
230  fMimeTypeList = new TGMimeTypes(fClient, mime_file);
231 
232  // Clipboard handle...
233 #ifndef R__WIN32
234  fClipboardAtom = gVirtualX->InternAtom("_ROOT_CLIPBOARD", kFALSE);
235 #else
236  fClipboardAtom = gVirtualX->InternAtom("CLIPBOARD", kFALSE);
237 #endif
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Cleanup the resource pool...
242 
244 {
245  delete fPicturePool;
246  delete fFontPool;
247  delete fGCPool;
248  delete fMimeTypeList;
249 
250  gVirtualX->DeletePixmap(fCheckered);
251  gVirtualX->DeletePixmap(fCheckeredBitmap);
252 }
TGResourcePool::fFontPool
TGFontPool * fFontPool
Definition: TGResourcePool.h:53
TGClient::GetDefaultRoot
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:235
TGFontPool::GetFont
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get the specified font.
Definition: TGFont.cxx:1545
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGResourcePool::fSelBackColor
Pixel_t fSelBackColor
Definition: TGResourcePool.h:44
TGResourcePool::fPicturePool
TGPicturePool * fPicturePool
Definition: TGResourcePool.h:63
TGResourcePool::fStatusFont
TGFont * fStatusFont
Definition: TGResourcePool.h:61
TGResourcePool::fDocbgndGC
TGGC * fDocbgndGC
Definition: TGResourcePool.h:78
gEnv
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TGResourcePool::fBackColor
Pixel_t fBackColor
Definition: TGResourcePool.h:39
TGResourcePool::fSelGC
TGGC * fSelGC
Definition: TGResourcePool.h:79
TGClient::GetShadow
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition: TGClient.cxx:482
TString::Data
const char * Data() const
Definition: TString.h:369
GCValues_t::fStipple
Pixmap_t fStipple
Definition: GuiTypes.h:238
FontH_t
Handle_t FontH_t
Definition: GuiTypes.h:34
kFillStippled
@ kFillStippled
Definition: GuiTypes.h:50
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGPicture.h
TGResourcePool::fBckgndGC
TGGC * fBckgndGC
Definition: TGResourcePool.h:73
TGResourcePool::fFrameGC
TGGC * fFrameGC
Definition: TGResourcePool.h:72
TROOT::GetIconPath
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
Definition: TROOT.cxx:3080
TGResourcePool::fSelbgndGC
TGGC * fSelbgndGC
Definition: TGResourcePool.h:80
TGResourcePool::fDocForeColor
Pixel_t fDocForeColor
Definition: TGResourcePool.h:47
GCValues_t
Definition: GuiTypes.h:223
TGResourcePool::fShadow
Pixel_t fShadow
Definition: TGResourcePool.h:42
TGResourcePool::fDocPropFont
TGFont * fDocPropFont
Definition: TGResourcePool.h:59
TGResourcePool::fTipGC
TGGC * fTipGC
Definition: TGResourcePool.h:81
kFillSolid
@ kFillSolid
Definition: GuiTypes.h:50
TGResourcePool::fTipBackColor
Pixel_t fTipBackColor
Definition: TGResourcePool.h:48
GCValues_t::fFillStyle
Int_t fFillStyle
Definition: GuiTypes.h:233
TGResourcePool::fDefaultDocBackPicture
const TGPicture * fDefaultDocBackPicture
Definition: TGResourcePool.h:66
TGMimeTypes.h
TEnv::GetValue
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
TGClient::GetHilite
Pixel_t GetHilite(Pixel_t base_color) const
Return pixel value of hilite color based on base_color.
Definition: TGClient.cxx:451
TVirtualX.h
TSystem::PrependPathName
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1079
TEnv.h
TString
Basic string class.
Definition: TString.h:136
TSystem::AccessPathName
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1294
TGObject::GetId
Handle_t GetId() const
Definition: TGObject.h:47
TGWindow.h
TGGCPool::GetGC
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition: TGGC.cxx:986
TGResourcePool
Definition: TGResourcePool.h:36
TGResourcePool::fHiliteGC
TGGC * fHiliteGC
Definition: TGResourcePool.h:74
TGFontPool
Definition: TGFont.h:226
kArrowRight
@ kArrowRight
Definition: GuiTypes.h:374
kWatch
@ kWatch
Definition: GuiTypes.h:374
TROOT.h
TGResourcePool::fForeColor
Pixel_t fForeColor
Definition: TGResourcePool.h:40
TGResourcePool::fGCPool
TGGCPool * fGCPool
Definition: TGResourcePool.h:68
GCValues_t::fSubwindowMode
Int_t fSubwindowMode
Definition: GuiTypes.h:242
kNone
const Handle_t kNone
Definition: GuiTypes.h:87
TGResourcePool::fWhiteGC
TGGC * fWhiteGC
Definition: TGResourcePool.h:70
TGResourcePool::fIconFont
TGFont * fIconFont
Definition: TGResourcePool.h:60
TGClient::GetColorByName
Bool_t GetColorByName(const char *name, Pixel_t &pixel) const
Get a color by name.
Definition: TGClient.cxx:396
TGPicturePool::GetPicture
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
TGResourcePool::fDocBackColor
Pixel_t fDocBackColor
Definition: TGResourcePool.h:46
TSystem.h
kGCFillStyle
const Mask_t kGCFillStyle
Definition: GuiTypes.h:293
TGResourcePool::fDefaultColormap
Colormap_t fDefaultColormap
Definition: TGResourcePool.h:91
TGGC.h
TGResourcePool::fTipForeColor
Pixel_t fTipForeColor
Definition: TGResourcePool.h:49
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGResourcePool::fCheckeredBitmap
Pixmap_t fCheckeredBitmap
Definition: TGResourcePool.h:84
kGCForeground
const Mask_t kGCForeground
Definition: GuiTypes.h:287
TGResourcePool::fGrabCursor
Cursor_t fGrabCursor
Definition: TGResourcePool.h:87
TGResourcePool::fDefaultFont
TGFont * fDefaultFont
Definition: TGResourcePool.h:55
kGCGraphicsExposures
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:301
TGResourcePool::fMenuFont
TGFont * fMenuFont
Definition: TGResourcePool.h:56
TGResourcePool::fFocusGC
TGGC * fFocusGC
Definition: TGResourcePool.h:76
GCValues_t::fFont
FontH_t fFont
Definition: GuiTypes.h:241
TGFont::GetFontHandle
FontH_t GetFontHandle() const
Definition: TGFont.h:192
TGPicturePool
Definition: TGPicture.h:100
kGCFont
const Mask_t kGCFont
Definition: GuiTypes.h:299
GCValues_t::fBackground
ULong_t fBackground
Definition: GuiTypes.h:227
kGCLineWidth
const Mask_t kGCLineWidth
Definition: GuiTypes.h:289
TGResourcePool::fCheckered
Pixmap_t fCheckered
Definition: TGResourcePool.h:83
TGResourcePool::fBlack
Pixel_t fBlack
Definition: TGResourcePool.h:51
TSystem::ExpandPathName
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1272
GCValues_t::fGraphicsExposures
Bool_t fGraphicsExposures
Definition: GuiTypes.h:243
kGCBackground
const Mask_t kGCBackground
Definition: GuiTypes.h:288
TGMimeTypes
Definition: TGMimeTypes.h:50
TGResourcePool::fDefaultCursor
Cursor_t fDefaultCursor
Definition: TGResourcePool.h:86
TROOT::GetEtcDir
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:2964
TGResourcePool::fSelForeColor
Pixel_t fSelForeColor
Definition: TGResourcePool.h:45
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
gray_height
const int gray_height
Definition: TGResourcePool.cxx:48
TGResourcePool::fMenuHiFont
TGFont * fMenuHiFont
Definition: TGResourcePool.h:57
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
TGResourcePool::fMimeTypeList
TGMimeTypes * fMimeTypeList
Definition: TGResourcePool.h:95
TGResourcePool::fDocGC
TGGC * fDocGC
Definition: TGResourcePool.h:77
TGResourcePool::fDocFixedFont
TGFont * fDocFixedFont
Definition: TGResourcePool.h:58
kCaret
@ kCaret
Definition: GuiTypes.h:374
GCValues_t::fMask
Mask_t fMask
Definition: GuiTypes.h:250
TGObject::fClient
TGClient * fClient
Definition: TGObject.h:37
TGGCPool
Definition: TGGC.h:112
TGResourcePool::TGResourcePool
TGResourcePool(TGClient *client)
Create the global GUI resource pool manager.
Definition: TGResourcePool.cxx:60
TGResourcePool::fWhite
Pixel_t fWhite
Definition: TGResourcePool.h:50
TGResourcePool::fShadowGC
TGGC * fShadowGC
Definition: TGResourcePool.h:75
GCValues_t::fForeground
ULong_t fForeground
Definition: GuiTypes.h:226
gray_width
const int gray_width
Definition: TGResourcePool.cxx:47
TGResourcePool.h
TGResourcePool::fHilite
Pixel_t fHilite
Definition: TGResourcePool.h:41
TGResourcePool::fBlackGC
TGGC * fBlackGC
Definition: TGResourcePool.h:71
TGResourcePool::fTextCursor
Cursor_t fTextCursor
Definition: TGResourcePool.h:88
TGResourcePool::fWaitCursor
Cursor_t fWaitCursor
Definition: TGResourcePool.h:89
kIncludeInferiors
@ kIncludeInferiors
Definition: GuiTypes.h:52
kReadPermission
@ kReadPermission
Definition: TSystem.h:47
TGResourcePool::fHighLightColor
Pixel_t fHighLightColor
Definition: TGResourcePool.h:43
TSystem::HomeDirectory
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
Definition: TSystem.cxx:886
TGResourcePool::fDefaultBackPicture
const TGPicture * fDefaultBackPicture
Definition: TGResourcePool.h:65
TGClient
Definition: TGClient.h:46
TGResourcePool::fClipboardAtom
Atom_t fClipboardAtom
Definition: TGResourcePool.h:93
TGResourcePool::~TGResourcePool
virtual ~TGResourcePool()
Cleanup the resource pool...
Definition: TGResourcePool.cxx:243
kGCStipple
const Mask_t kGCStipple
Definition: GuiTypes.h:296
TGFont.h
GCValues_t::fLineWidth
Int_t fLineWidth
Definition: GuiTypes.h:228
kGCSubwindowMode
const Mask_t kGCSubwindowMode
Definition: GuiTypes.h:300
gray_bits
static unsigned char gray_bits[]
Definition: TGResourcePool.cxx:49