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/** \class TGResourcePool
25 \ingroup guiwidgets
26
27This class implements a pool for the default GUI resource set,
28like GC's, colors, fonts, etc..
29
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:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
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
Window client.
Definition TGClient.h:37
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:395
Pixel_t GetHilite(Pixel_t base_color) const
Return pixel value of hilite color based on base_color.
Definition TGClient.cxx:450
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition TGClient.cxx:481
Provides a pool of fonts.
Definition TGFont.h:217
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get the specified font.
Definition TGFont.cxx:1558
FontH_t GetFontHandle() const
Definition TGFont.h:183
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition TGGC.cxx:987
This class handles mime types, used by browsers to map file types to applications and icons.
Definition TGMimeTypes.h:47
TGClient * fClient
Connection to display server.
Definition TGObject.h:27
Handle_t GetId() const
Definition TGObject.h:37
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:82
This class implements a pool for the default GUI resource set, like GC's, colors, fonts,...
TGFont * fDocFixedFont
document fixed font
TGFont * fDefaultFont
default font
Pixel_t fDocForeColor
default document foreground color
Pixel_t fForeColor
default foreground color
TGGC * fDocGC
document gc
TGGC * fBlackGC
black gc
Pixel_t fTipBackColor
default tip background color
Pixel_t fTipForeColor
default tip foreground color
Cursor_t fWaitCursor
wait cursor
virtual ~TGResourcePool()
Cleanup the resource pool...
Pixel_t fWhite
white color index
TGFont * fStatusFont
status bar font
TGGC * fHiliteGC
frame hilite gc
TGGC * fShadowGC
frame shadow gc
Pixel_t fHighLightColor
highlight color
const TGPicture * fDefaultBackPicture
default background picture
TGPicturePool * fPicturePool
picture pool manager
Pixel_t fBackColor
default background color
Cursor_t fTextCursor
text cursor
TGGC * fSelbgndGC
selection background gc
TGFont * fDocPropFont
document proportional font
TGGC * fFocusGC
frame focus gc
TGFont * fIconFont
icon font
TGFontPool * fFontPool
font pool manager
TGMimeTypes * fMimeTypeList
list of mime types
Cursor_t fGrabCursor
grab cursor
TGGC * fDocbgndGC
document background gc
Pixel_t fDocBackColor
default document background color
TGFont * fMenuFont
menu font
TGGC * fFrameGC
frame gc
Pixmap_t fCheckered
checkered pixmap
TGFont * fMenuHiFont
menu highlight font
TGResourcePool(TGClient *client)
Create the global GUI resource pool manager.
TGGCPool * fGCPool
graphics drawing context pool manager
Pixel_t fBlack
black color index
Atom_t fClipboardAtom
handle to clipboard
Pixel_t fSelForeColor
default selection foreground color
Pixel_t fShadow
default shadow color
Pixmap_t fCheckeredBitmap
checkered bitmap
TGGC * fTipGC
tooltip gc
Cursor_t fDefaultCursor
default cursor
Colormap_t fDefaultColormap
default colormap
const TGPicture * fDefaultDocBackPicture
default document background picture
TGGC * fSelGC
selection gc
Pixel_t fHilite
default highlight color
Pixel_t fSelBackColor
default selection background color
TGGC * fBckgndGC
frame background gc
TGGC * fWhiteGC
white gc
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:1274
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1081
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:1296
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
Definition TSystem.cxx:888
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