Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
47const int gray_width = 8;
48const int gray_height = 8;
49static 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))
111 if (!fClient->GetColorByName(forecolor, fForeColor))
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());
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())
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;
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
192 fSelbgndGC = fGCPool->GetGC(&gval, kTRUE);
193
196 fSelGC = fGCPool->GetGC(&gval, kTRUE);
197
201 fDocGC = fGCPool->GetGC(&gval, kTRUE);
202
204 fDocbgndGC = fGCPool->GetGC(&gval, kTRUE);
205
209 fTipGC = fGCPool->GetGC(&gval, kTRUE);
210
214 gval.fForeground = fBlack;
216 gval.fLineWidth = 0;
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}
const Mask_t kGCBackground
Definition GuiTypes.h:289
const Mask_t kGCForeground
Definition GuiTypes.h:288
const Mask_t kGCSubwindowMode
Definition GuiTypes.h:301
const Mask_t kGCLineWidth
Definition GuiTypes.h:290
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition GuiTypes.h:35
const Mask_t kGCFillStyle
Definition GuiTypes.h:294
const Mask_t kGCFont
Definition GuiTypes.h:300
const Handle_t kNone
Definition GuiTypes.h:88
@ kIncludeInferiors
Definition GuiTypes.h:53
@ kFillStippled
Definition GuiTypes.h:51
@ kFillSolid
Definition GuiTypes.h:51
const Mask_t kGCStipple
Definition GuiTypes.h:297
const Mask_t kGCGraphicsExposures
Definition GuiTypes.h:302
@ kArrowRight
Definition GuiTypes.h:375
@ kCaret
Definition GuiTypes.h:375
@ kWatch
Definition GuiTypes.h:375
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
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:47
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define gVirtualX
Definition TVirtualX.h:338
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:233
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:1545
FontH_t GetFontHandle() const
Definition TGFont.h:192
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition TGGC.cxx:986
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 fTipBackColor
Pixel_t fTipForeColor
Cursor_t fWaitCursor
virtual ~TGResourcePool()
Cleanup the resource pool...
TGFont * fStatusFont
Pixel_t fHighLightColor
const TGPicture * fDefaultBackPicture
TGPicturePool * fPicturePool
Cursor_t fTextCursor
TGFont * fDocPropFont
TGFontPool * fFontPool
TGMimeTypes * fMimeTypeList
Cursor_t fGrabCursor
Pixel_t fDocBackColor
Pixmap_t fCheckered
TGFont * fMenuHiFont
TGResourcePool(TGClient *client)
Create the global GUI resource pool manager.
TGGCPool * fGCPool
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:3085
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition TROOT.cxx:2969
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
Bool_t IsNull() const
Definition TString.h:407
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1272
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1079
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
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
Definition TSystem.cxx:886
Graphics context structure.
Definition GuiTypes.h:224
ULong_t fBackground
background pixel
Definition GuiTypes.h:228
Int_t fLineWidth
line width
Definition GuiTypes.h:229
Pixmap_t fStipple
stipple 1 plane pixmap for stippling
Definition GuiTypes.h:239
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:251
Bool_t fGraphicsExposures
boolean, should exposures be generated
Definition GuiTypes.h:244
ULong_t fForeground
foreground pixel
Definition GuiTypes.h:227
Int_t fFillStyle
kFillSolid, kFillTiled, kFillStippled, kFillOpaeueStippled
Definition GuiTypes.h:234
FontH_t fFont
default text font for text operations
Definition GuiTypes.h:242
Int_t fSubwindowMode
kClipByChildren, kIncludeInferiors
Definition GuiTypes.h:243