ROOT  6.06/09
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;
87  TString mime_file;
88  TString line;
89 
90 #ifndef R__WIN32
91 # ifdef ROOTICONPATH
92  icon_path = TString::Format("%s/icons:%s:.:", gSystem->HomeDirectory(),
93  ROOTICONPATH);
94 # ifdef EXTRAICONPATH
95  icon_path += gEnv->GetValue("Gui.IconPath", EXTRAICONPATH);
96 # else
97  icon_path += gEnv->GetValue("Gui.IconPath", "");
98 # endif
99 # else
100  icon_path = TString::Format("%s/icons:%s/icons:.:", gSystem->HomeDirectory(),
101  gSystem->Getenv("ROOTSYS"));
102  icon_path += gEnv->GetValue("Gui.IconPath", "");
103 # endif
104  line = TString::Format("%s/.root.mimes", gSystem->HomeDirectory());
105 
106  mime_file = gEnv->GetValue("Gui.MimeTypeFile", line.Data());
107  char *mf = gSystem->ExpandPathName(mime_file.Data());
108  if (mf) {
109  mime_file = mf;
110  delete [] mf;
111  }
112  if (gSystem->AccessPathName(mime_file, kReadPermission))
113 #ifdef ROOTETCDIR
114  mime_file = TString::Format("%s/root.mimes", ROOTETCDIR);
115 #else
116  mime_file = TString::Format("%s/etc/root.mimes", gSystem->Getenv("ROOTSYS"));
117 #endif
118 #else // R__WIN32
119  icon_path = TString::Format("%s\\icons:.:\\", gSystem->Getenv("ROOTSYS"));
120  icon_path += gEnv->GetValue("Gui.IconPath", "");
121  line = TString::Format("%s\\root.mimes", gSystem->HomeDirectory());
122  mime_file = gEnv->GetValue("Gui.MimeTypeFile", line.Data());
123  if (gSystem->AccessPathName(mime_file, kReadPermission))
124  mime_file = TString::Format("%s\\etc\\root.mimes", gSystem->Getenv("ROOTSYS"));
125 #endif
126 
127  // Setup colors...
128  fClient->GetColorByName("white", fWhite); // white and black always exist
129  fClient->GetColorByName("black", fBlack);
130  if (!fClient->GetColorByName(backcolor, fBackColor))
131  fBackColor = fWhite;
132  if (!fClient->GetColorByName(forecolor, fForeColor))
133  fForeColor = fBlack;
134  if (!fClient->GetColorByName(highlightcolor, fHighLightColor))
135  fHighLightColor = fWhite;
136  fHilite = fClient->GetHilite(fBackColor);
137  fShadow = fClient->GetShadow(fBackColor);
138  if (!fClient->GetColorByName(selbackcolor, fSelBackColor))
139  fSelBackColor = fBlack;
140  if (!fClient->GetColorByName(selforecolor, fSelForeColor))
141  fSelForeColor = fWhite;
142  if (!fClient->GetColorByName(docbackcolor, fDocBackColor))
143  fDocBackColor = fWhite;
144  if (!fClient->GetColorByName(docforecolor, fDocForeColor))
145  fDocForeColor = fBlack;
146  if (!fClient->GetColorByName(tipbackcolor, fTipBackColor))
147  fTipBackColor = fWhite;
148  if (!fClient->GetColorByName(tipforecolor, fTipForeColor))
149  fTipForeColor = fBlack;
150 
151  // Setup checkered pix/bit-maps...
152  fCheckered = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
153  (const char *)gray_bits,
155  fBackColor, fWhite /*fHilite*/,
156  gVirtualX->GetDepth());
157  fCheckeredBitmap = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
158  (const char *)gray_bits,
160  1, 0, 1);
161 
162  // Create picture pool, GC pool, font pool, mime type list, etc.
163 
164  // Create picture pool and pre-load some pictures...
165  fPicturePool = new TGPicturePool(fClient, icon_path);
166 
167  fDefaultBackPicture = 0;
168  fDefaultDocBackPicture = 0;
169  if (!framebgpixmap.IsNull())
170  fDefaultBackPicture = fPicturePool->GetPicture(framebgpixmap);
171  if (!docbgpixmap.IsNull())
172  fDefaultDocBackPicture = fPicturePool->GetPicture(docbgpixmap);
173 
174  // Create font pool and pre-load some fonts...
175  fFontPool = new TGFontPool(fClient);
176  fDefaultFont = fFontPool->GetFont(default_font);
177  fMenuFont = fFontPool->GetFont(menu_font);
178  fMenuHiFont = fFontPool->GetFont(menu_hi_font);
179  fDocFixedFont = fFontPool->GetFont(doc_fixed_font);
180  fDocPropFont = fFontPool->GetFont(doc_prop_font);
181  fIconFont = fFontPool->GetFont(icon_font);
182  fStatusFont = fFontPool->GetFont(status_font);
183 
184  // Create GC pool and pre-load some GCs...
185  fGCPool = new TGGCPool(fClient);
186 
187  GCValues_t gval;
190  gval.fGraphicsExposures = kFALSE;
191  gval.fFillStyle = kFillSolid;
192  gval.fFont = fDefaultFont->GetFontHandle();
193  gval.fBackground = fBackColor;
194  gval.fForeground = fBlack;
195  fBlackGC = fGCPool->GetGC(&gval, kTRUE);
196 
197  gval.fForeground = fWhite;
198  fWhiteGC = fGCPool->GetGC(&gval, kTRUE);
199 
200  gval.fForeground = fHilite;
201  fHiliteGC = fGCPool->GetGC(&gval, kTRUE);
202 
203  gval.fForeground = fShadow;
204  fShadowGC = fGCPool->GetGC(&gval, kTRUE);
205 
206  gval.fForeground = fBackColor;
207  fBckgndGC = fGCPool->GetGC(&gval, kTRUE);
208 
209  gval.fForeground = fForeColor;
210  fFrameGC = fGCPool->GetGC(&gval, kTRUE);
211 
212  gval.fForeground = fSelBackColor;
213  fSelbgndGC = fGCPool->GetGC(&gval, kTRUE);
214 
215  gval.fForeground = fSelForeColor;
216  gval.fBackground = fSelBackColor;
217  fSelGC = fGCPool->GetGC(&gval, kTRUE);
218 
219  gval.fFont = fDocPropFont->GetFontHandle();
220  gval.fForeground = fDocForeColor;
221  gval.fBackground = fDocBackColor;
222  fDocGC = fGCPool->GetGC(&gval, kTRUE);
223 
224  gval.fForeground = fDocBackColor;
225  fDocbgndGC = fGCPool->GetGC(&gval, kTRUE);
226 
227  gval.fFont = fStatusFont->GetFontHandle();
228  gval.fForeground = fTipForeColor;
229  gval.fBackground = fTipBackColor;
230  fTipGC = fGCPool->GetGC(&gval, kTRUE);
231 
235  gval.fForeground = fBlack;
236  gval.fBackground = fSelBackColor;
237  gval.fLineWidth = 0;
238  gval.fFillStyle = kFillStippled;
240  gval.fGraphicsExposures = kFALSE;
241  gval.fStipple = fCheckeredBitmap;
242  fFocusGC = fGCPool->GetGC(&gval, kTRUE);
243 
244  // Setup cursors...
245  fDefaultCursor = kNone;
246  fGrabCursor = gVirtualX->CreateCursor(kArrowRight);
247  fTextCursor = gVirtualX->CreateCursor(kCaret);
248  fWaitCursor = gVirtualX->CreateCursor(kWatch);
249 
250  // Read in mime type...
251  fMimeTypeList = new TGMimeTypes(fClient, mime_file);
252 
253  // Clipboard handle...
254 #ifndef R__WIN32
255  fClipboardAtom = gVirtualX->InternAtom("_ROOT_CLIPBOARD", kFALSE);
256 #else
257  fClipboardAtom = gVirtualX->InternAtom("CLIPBOARD", kFALSE);
258 #endif
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Cleanup the resource pool...
263 
265 {
266  delete fPicturePool;
267  delete fFontPool;
268  delete fGCPool;
269  delete fMimeTypeList;
270 
271  gVirtualX->DeletePixmap(fCheckered);
272  gVirtualX->DeletePixmap(fCheckeredBitmap);
273 }
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:1265
Pixmap_t fCheckered
TLine * line
FontH_t fFont
Definition: GuiTypes.h:243
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:881
TGFontPool * fFontPool
Basic string class.
Definition: TString.h:137
const Bool_t kFALSE
Definition: Rtypes.h:92
Int_t fFillStyle
Definition: GuiTypes.h:235
Definition: TGGC.h:116
const char * Data() const
Definition: TString.h:349
TGGCPool * fGCPool
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
ClassImp(TGResourcePool) TGResourcePool
Create the global GUI resource pool manager.
ULong_t fForeground
Definition: GuiTypes.h:228
const Mask_t kGCFont
Definition: GuiTypes.h:301
static unsigned char gray_bits[]
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1627
const Mask_t kGCLineWidth
Definition: GuiTypes.h:291
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:303
TGMimeTypes * fMimeTypeList
const int gray_height
Bool_t fGraphicsExposures
Definition: GuiTypes.h:245
Pixmap_t fCheckeredBitmap
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
const Handle_t kNone
Definition: GuiTypes.h:89
Bool_t IsNull() const
Definition: TString.h:387
#define gVirtualX
Definition: TVirtualX.h:362
Pixmap_t fStipple
Definition: GuiTypes.h:240
ULong_t fBackground
Definition: GuiTypes.h:229
const Mask_t kGCFillStyle
Definition: GuiTypes.h:295
const int gray_width
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
const Mask_t kGCForeground
Definition: GuiTypes.h:289
const Mask_t kGCStipple
Definition: GuiTypes.h:298
Mask_t fMask
Definition: GuiTypes.h:252
const Mask_t kGCSubwindowMode
Definition: GuiTypes.h:302
const Mask_t kGCBackground
Definition: GuiTypes.h:290
Int_t fLineWidth
Definition: GuiTypes.h:230
Int_t fSubwindowMode
Definition: GuiTypes.h:244
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1243
const Bool_t kTRUE
Definition: Rtypes.h:91