Logo ROOT   6.14/05
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 "TGClient.h"
37 #include "TGWindow.h"
38 #include "TROOT.h"
39 #include "TSystem.h"
40 #include "TEnv.h"
41 #include "TVirtualX.h"
42 #include "TGGC.h"
43 #include "TGPicture.h"
44 #include "TGFont.h"
45 #include "TGMimeTypes.h"
46 
47 
48 const int gray_width = 8;
49 const int gray_height = 8;
50 static unsigned char gray_bits[] = {
51  0x55, 0xaa, 0x55, 0xaa,
52  0x55, 0xaa, 0x55, 0xaa
53 };
54 
55 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Create the global GUI resource pool manager.
60 
62 {
63  fClient = client;
64  fDefaultColormap = gVirtualX->GetColormap();
65 
66  // Get GUI defaults from [system].rootrc
67  TString default_font = gEnv->GetValue("Gui.DefaultFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
68  TString menu_font = gEnv->GetValue("Gui.MenuFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
69  TString menu_hi_font = gEnv->GetValue("Gui.MenuHiFont", "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
70  TString doc_fixed_font = gEnv->GetValue("Gui.DocFixedFont", "-*-courier-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
71  TString doc_prop_font = gEnv->GetValue("Gui.DocPropFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
72  TString icon_font = gEnv->GetValue("Gui.IconFont", "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
73  TString status_font = gEnv->GetValue("Gui.StatusFont", "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
74  TString backcolor = gEnv->GetValue("Gui.BackgroundColor", "#e0e0e0");
75  TString forecolor = gEnv->GetValue("Gui.ForegroundColor", "black");
76  TString highlightcolor = gEnv->GetValue("Gui.HighLightColor", "#d0d0d0");
77  TString selbackcolor = gEnv->GetValue("Gui.SelectBackgroundColor", "#86abd9");
78  TString selforecolor = gEnv->GetValue("Gui.SelectForegroundColor", "white");
79  TString docbackcolor = gEnv->GetValue("Gui.DocumentBackgroundColor", "white");
80  TString docforecolor = gEnv->GetValue("Gui.DocumentForegroundColor", "black");
81  TString tipbackcolor = gEnv->GetValue("Gui.TooltipBackgroundColor", "LightYellow");
82  TString tipforecolor = gEnv->GetValue("Gui.TooltipForegroundColor", "black");
83  TString framebgpixmap = gEnv->GetValue("Gui.FrameBackgroundPixmap", "");
84  TString docbgpixmap = gEnv->GetValue("Gui.DocumentBackgroundPixmap", "");
85 
86  TString icon_path = gEnv->GetValue("Gui.IconPath", "");
87  if (icon_path.IsNull()) {
88  icon_path = "icons";
90 #ifndef R__WIN32
91  icon_path = ".:" + icon_path + ":" + TROOT::GetIconPath() + ":" + EXTRAICONPATH;
92 #else
93  icon_path = ".;" + icon_path + ";" + TROOT::GetIconPath() + ";" + EXTRAICONPATH;
94 #endif
95  }
96 
97  TString mime_file = ".root.mimes";
99  mime_file = gEnv->GetValue("Gui.MimeTypeFile", mime_file.Data());
100  char *mf = gSystem->ExpandPathName(mime_file.Data());
101  if (mf) {
102  mime_file = mf;
103  delete [] mf;
104  }
105  if (gSystem->AccessPathName(mime_file, kReadPermission)) {
106  mime_file = "root.mimes";
108  }
109 
110  // Setup colors...
111  fClient->GetColorByName("white", fWhite); // white and black always exist
112  fClient->GetColorByName("black", fBlack);
113  if (!fClient->GetColorByName(backcolor, fBackColor))
114  fBackColor = fWhite;
115  if (!fClient->GetColorByName(forecolor, fForeColor))
116  fForeColor = fBlack;
117  if (!fClient->GetColorByName(highlightcolor, fHighLightColor))
121  if (!fClient->GetColorByName(selbackcolor, fSelBackColor))
123  if (!fClient->GetColorByName(selforecolor, fSelForeColor))
125  if (!fClient->GetColorByName(docbackcolor, fDocBackColor))
127  if (!fClient->GetColorByName(docforecolor, fDocForeColor))
129  if (!fClient->GetColorByName(tipbackcolor, fTipBackColor))
131  if (!fClient->GetColorByName(tipforecolor, fTipForeColor))
133 
134  // Setup checkered pix/bit-maps...
135  fCheckered = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
136  (const char *)gray_bits,
138  fBackColor, fWhite /*fHilite*/,
139  gVirtualX->GetDepth());
140  fCheckeredBitmap = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
141  (const char *)gray_bits,
143  1, 0, 1);
144 
145  // Create picture pool, GC pool, font pool, mime type list, etc.
146 
147  // Create picture pool and pre-load some pictures...
148  fPicturePool = new TGPicturePool(fClient, icon_path);
149 
152  if (!framebgpixmap.IsNull())
153  fDefaultBackPicture = fPicturePool->GetPicture(framebgpixmap);
154  if (!docbgpixmap.IsNull())
156 
157  // Create font pool and pre-load some fonts...
159  fDefaultFont = fFontPool->GetFont(default_font);
160  fMenuFont = fFontPool->GetFont(menu_font);
161  fMenuHiFont = fFontPool->GetFont(menu_hi_font);
162  fDocFixedFont = fFontPool->GetFont(doc_fixed_font);
163  fDocPropFont = fFontPool->GetFont(doc_prop_font);
164  fIconFont = fFontPool->GetFont(icon_font);
165  fStatusFont = fFontPool->GetFont(status_font);
166 
167  // Create GC pool and pre-load some GCs...
168  fGCPool = new TGGCPool(fClient);
169 
170  GCValues_t gval;
173  gval.fGraphicsExposures = kFALSE;
174  gval.fFillStyle = kFillSolid;
175  gval.fFont = fDefaultFont->GetFontHandle();
176  gval.fBackground = fBackColor;
177  gval.fForeground = fBlack;
178  fBlackGC = fGCPool->GetGC(&gval, kTRUE);
179 
180  gval.fForeground = fWhite;
181  fWhiteGC = fGCPool->GetGC(&gval, kTRUE);
182 
183  gval.fForeground = fHilite;
184  fHiliteGC = fGCPool->GetGC(&gval, kTRUE);
185 
186  gval.fForeground = fShadow;
187  fShadowGC = fGCPool->GetGC(&gval, kTRUE);
188 
189  gval.fForeground = fBackColor;
190  fBckgndGC = fGCPool->GetGC(&gval, kTRUE);
191 
192  gval.fForeground = fForeColor;
193  fFrameGC = fGCPool->GetGC(&gval, kTRUE);
194 
195  gval.fForeground = fSelBackColor;
196  fSelbgndGC = fGCPool->GetGC(&gval, kTRUE);
197 
198  gval.fForeground = fSelForeColor;
199  gval.fBackground = fSelBackColor;
200  fSelGC = fGCPool->GetGC(&gval, kTRUE);
201 
202  gval.fFont = fDocPropFont->GetFontHandle();
203  gval.fForeground = fDocForeColor;
204  gval.fBackground = fDocBackColor;
205  fDocGC = fGCPool->GetGC(&gval, kTRUE);
206 
207  gval.fForeground = fDocBackColor;
208  fDocbgndGC = fGCPool->GetGC(&gval, kTRUE);
209 
210  gval.fFont = fStatusFont->GetFontHandle();
211  gval.fForeground = fTipForeColor;
212  gval.fBackground = fTipBackColor;
213  fTipGC = fGCPool->GetGC(&gval, kTRUE);
214 
218  gval.fForeground = fBlack;
219  gval.fBackground = fSelBackColor;
220  gval.fLineWidth = 0;
221  gval.fFillStyle = kFillStippled;
223  gval.fGraphicsExposures = kFALSE;
224  gval.fStipple = fCheckeredBitmap;
225  fFocusGC = fGCPool->GetGC(&gval, kTRUE);
226 
227  // Setup cursors...
229  fGrabCursor = gVirtualX->CreateCursor(kArrowRight);
230  fTextCursor = gVirtualX->CreateCursor(kCaret);
231  fWaitCursor = gVirtualX->CreateCursor(kWatch);
232 
233  // Read in mime type...
234  fMimeTypeList = new TGMimeTypes(fClient, mime_file);
235 
236  // Clipboard handle...
237 #ifndef R__WIN32
238  fClipboardAtom = gVirtualX->InternAtom("_ROOT_CLIPBOARD", kFALSE);
239 #else
240  fClipboardAtom = gVirtualX->InternAtom("CLIPBOARD", kFALSE);
241 #endif
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 /// Cleanup the resource pool...
246 
248 {
249  delete fPicturePool;
250  delete fFontPool;
251  delete fGCPool;
252  delete fMimeTypeList;
253 
254  gVirtualX->DeletePixmap(fCheckered);
255  gVirtualX->DeletePixmap(fCheckeredBitmap);
256 }
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:1276
Pixel_t fForeColor
Pixmap_t fCheckered
Cursor_t fDefaultCursor
FontH_t fFont
Definition: GuiTypes.h:241
Pixel_t fDocForeColor
const TGPicture * fDefaultBackPicture
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
Definition: TROOT.cxx:3107
virtual ~TGResourcePool()
Cleanup the resource pool...
TGPicturePool * fPicturePool
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
Definition: TSystem.cxx:885
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition: TGClient.cxx:478
Pixel_t fDocBackColor
TGFontPool * fFontPool
Basic string class.
Definition: TString.h:131
Pixel_t fHighLightColor
TGFont * fIconFont
Bool_t GetColorByName(const char *name, Pixel_t &pixel) const
Get a color by name.
Definition: TGClient.cxx:392
Int_t fFillStyle
Definition: GuiTypes.h:233
TGResourcePool(TGClient *client)
Create the global GUI resource pool manager.
Handle_t GetId() const
Definition: TGObject.h:47
Definition: TGGC.h:112
TGGCPool * fGCPool
TGFont * fMenuFont
ULong_t fForeground
Definition: GuiTypes.h:226
const Mask_t kGCFont
Definition: GuiTypes.h:299
static unsigned char gray_bits[]
const Mask_t kGCLineWidth
Definition: GuiTypes.h:289
Pixel_t fSelBackColor
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1062
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:301
TGFont * fStatusFont
TGMimeTypes * fMimeTypeList
TGFont * fMenuHiFont
Pixel_t fTipForeColor
const int gray_height
Cursor_t fGrabCursor
Bool_t fGraphicsExposures
Definition: GuiTypes.h:243
Pixmap_t fCheckeredBitmap
Pixel_t fTipBackColor
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
const TGPicture * fDefaultDocBackPicture
TGFont * fDefaultFont
const Handle_t kNone
Definition: GuiTypes.h:87
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
Atom_t fClipboardAtom
#define gVirtualX
Definition: TVirtualX.h:350
Pixmap_t fStipple
Definition: GuiTypes.h:238
const Bool_t kFALSE
Definition: RtypesCore.h:88
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get the specified font.
Definition: TGFont.cxx:1543
Pixel_t GetHilite(Pixel_t base_color) const
Return pixel value of hilite color based on base_color.
Definition: TGClient.cxx:447
ULong_t fBackground
Definition: GuiTypes.h:227
#define ClassImp(name)
Definition: Rtypes.h:359
const Mask_t kGCFillStyle
Definition: GuiTypes.h:293
Cursor_t fTextCursor
const int gray_width
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:2991
const Mask_t kGCForeground
Definition: GuiTypes.h:287
Bool_t IsNull() const
Definition: TString.h:402
const Mask_t kGCStipple
Definition: GuiTypes.h:296
Mask_t fMask
Definition: GuiTypes.h:250
const Mask_t kGCSubwindowMode
Definition: GuiTypes.h:300
TGClient * fClient
Definition: TGObject.h:37
const Mask_t kGCBackground
Definition: GuiTypes.h:288
Pixel_t fSelForeColor
Int_t fLineWidth
Definition: GuiTypes.h:228
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
Int_t fSubwindowMode
Definition: GuiTypes.h:242
Colormap_t fDefaultColormap
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1254
TGFont * fDocFixedFont
TGFont * fDocPropFont
Cursor_t fWaitCursor
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
const Bool_t kTRUE
Definition: RtypesCore.h:87
Pixel_t fBackColor
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition: TGGC.cxx:985
const char * Data() const
Definition: TString.h:364
FontH_t GetFontHandle() const
Definition: TGFont.h:192