Logo ROOT   6.16/01
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
48const int gray_width = 8;
49const int gray_height = 8;
50static 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))
115 if (!fClient->GetColorByName(forecolor, fForeColor))
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());
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())
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;
174 gval.fFillStyle = kFillSolid;
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
196 fSelbgndGC = fGCPool->GetGC(&gval, kTRUE);
197
200 fSelGC = fGCPool->GetGC(&gval, kTRUE);
201
205 fDocGC = fGCPool->GetGC(&gval, kTRUE);
206
208 fDocbgndGC = fGCPool->GetGC(&gval, kTRUE);
209
213 fTipGC = fGCPool->GetGC(&gval, kTRUE);
214
218 gval.fForeground = fBlack;
220 gval.fLineWidth = 0;
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}
const Mask_t kGCBackground
Definition: GuiTypes.h:288
const Mask_t kGCForeground
Definition: GuiTypes.h:287
const Mask_t kGCSubwindowMode
Definition: GuiTypes.h:300
const Mask_t kGCLineWidth
Definition: GuiTypes.h:289
const Mask_t kGCFillStyle
Definition: GuiTypes.h:293
const Mask_t kGCFont
Definition: GuiTypes.h:299
const Handle_t kNone
Definition: GuiTypes.h:87
@ kIncludeInferiors
Definition: GuiTypes.h:52
@ kFillStippled
Definition: GuiTypes.h:50
@ kFillSolid
Definition: GuiTypes.h:50
const Mask_t kGCStipple
Definition: GuiTypes.h:296
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:301
const Bool_t kFALSE
Definition: RtypesCore.h:88
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
const int gray_height
const int gray_width
static unsigned char gray_bits[]
@ kReadPermission
Definition: TSystem.h:48
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
#define gVirtualX
Definition: TVirtualX.h:345
@ kArrowRight
Definition: TVirtualX.h:47
@ kCaret
Definition: TVirtualX.h:47
@ kWatch
Definition: TVirtualX.h:47
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:234
Bool_t GetColorByName(const char *name, Pixel_t &pixel) const
Get a color by name.
Definition: TGClient.cxx:394
Pixel_t GetHilite(Pixel_t base_color) const
Return pixel value of hilite color based on base_color.
Definition: TGClient.cxx:449
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition: TGClient.cxx:480
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get the specified font.
Definition: TGFont.cxx:1543
FontH_t GetFontHandle() const
Definition: TGFont.h:192
Definition: TGGC.h:112
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition: TGGC.cxx:985
TGClient * fClient
Definition: TGObject.h:37
Handle_t GetId() const
Definition: TGObject.h:47
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
TGFont * fDocFixedFont
TGFont * fDefaultFont
Pixel_t fDocForeColor
Pixel_t fForeColor
Pixel_t fTipBackColor
Pixel_t fTipForeColor
Cursor_t fWaitCursor
virtual ~TGResourcePool()
Cleanup the resource pool...
TGFont * fStatusFont
Pixel_t fHighLightColor
const TGPicture * fDefaultBackPicture
TGPicturePool * fPicturePool
Pixel_t fBackColor
Cursor_t fTextCursor
TGFont * fDocPropFont
TGFont * fIconFont
TGFontPool * fFontPool
TGMimeTypes * fMimeTypeList
Cursor_t fGrabCursor
Pixel_t fDocBackColor
TGFont * fMenuFont
Pixmap_t fCheckered
TGFont * fMenuHiFont
TGResourcePool(TGClient *client)
Create the global GUI resource pool manager.
TGGCPool * fGCPool
Atom_t fClipboardAtom
Pixel_t fSelForeColor
Pixmap_t fCheckeredBitmap
Cursor_t fDefaultCursor
Colormap_t fDefaultColormap
const TGPicture * fDefaultDocBackPicture
Pixel_t fSelBackColor
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
Definition: TROOT.cxx:3126
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:3010
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
Bool_t IsNull() const
Definition: TString.h:402
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1264
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
Definition: TSystem.cxx:894
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1071
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:1286
ULong_t fBackground
Definition: GuiTypes.h:227
Int_t fLineWidth
Definition: GuiTypes.h:228
Pixmap_t fStipple
Definition: GuiTypes.h:238
Mask_t fMask
Definition: GuiTypes.h:250
Bool_t fGraphicsExposures
Definition: GuiTypes.h:243
ULong_t fForeground
Definition: GuiTypes.h:226
Int_t fFillStyle
Definition: GuiTypes.h:233
FontH_t fFont
Definition: GuiTypes.h:241
Int_t fSubwindowMode
Definition: GuiTypes.h:242