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#include "RConfigure.h"
33
34#include "TGResourcePool.h"
35#include "TGWindow.h"
36#include "TROOT.h"
37#include "TSystem.h"
38#include "TEnv.h"
39#include "TVirtualX.h"
40#include "TGGC.h"
41#include "TGPicture.h"
42#include "TGFont.h"
43#include "TGMimeTypes.h"
44
45
46const int gray_width = 8;
47const int gray_height = 8;
48static unsigned char gray_bits[] = {
49 0x55, 0xaa, 0x55, 0xaa,
50 0x55, 0xaa, 0x55, 0xaa
51};
52
53
55
56////////////////////////////////////////////////////////////////////////////////
57/// Create the global GUI resource pool manager.
58
60{
61 fClient = client;
62 fDefaultColormap = gVirtualX->GetColormap();
63
64 // Get GUI defaults from [system].rootrc
65 TString default_font = gEnv->GetValue("Gui.DefaultFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
66 TString menu_font = gEnv->GetValue("Gui.MenuFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
67 TString menu_hi_font = gEnv->GetValue("Gui.MenuHiFont", "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
68 TString doc_fixed_font = gEnv->GetValue("Gui.DocFixedFont", "-*-courier-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
69 TString doc_prop_font = gEnv->GetValue("Gui.DocPropFont", "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
70 TString icon_font = gEnv->GetValue("Gui.IconFont", "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
71 TString status_font = gEnv->GetValue("Gui.StatusFont", "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
72 TString backcolor = gEnv->GetValue("Gui.BackgroundColor", "#e0e0e0");
73 TString forecolor = gEnv->GetValue("Gui.ForegroundColor", "black");
74 TString highlightcolor = gEnv->GetValue("Gui.HighLightColor", "#d0d0d0");
75 TString selbackcolor = gEnv->GetValue("Gui.SelectBackgroundColor", "#86abd9");
76 TString selforecolor = gEnv->GetValue("Gui.SelectForegroundColor", "white");
77 TString docbackcolor = gEnv->GetValue("Gui.DocumentBackgroundColor", "white");
78 TString docforecolor = gEnv->GetValue("Gui.DocumentForegroundColor", "black");
79 TString tipbackcolor = gEnv->GetValue("Gui.TooltipBackgroundColor", "LightYellow");
80 TString tipforecolor = gEnv->GetValue("Gui.TooltipForegroundColor", "black");
81 TString framebgpixmap = gEnv->GetValue("Gui.FrameBackgroundPixmap", "");
82 TString docbgpixmap = gEnv->GetValue("Gui.DocumentBackgroundPixmap", "");
83
84 TString icon_path = gEnv->GetValue("Gui.IconPath", "");
85 if (icon_path.IsNull()) {
86 icon_path = "icons";
88#ifndef R__WIN32
89 icon_path = ".:" + icon_path + ":" + TROOT::GetIconPath() + ":" + EXTRAICONPATH;
90#else
91 icon_path = ".;" + icon_path + ";" + TROOT::GetIconPath() + ";" + EXTRAICONPATH;
92#endif
93 }
94
95 TString mime_file = ".root.mimes";
97 mime_file = gEnv->GetValue("Gui.MimeTypeFile", mime_file.Data());
98 gSystem->ExpandPathName(mime_file);
99
100 if (gSystem->AccessPathName(mime_file, kReadPermission)) {
101 mime_file = "root.mimes";
103 }
104
105 // Setup colors...
106 fClient->GetColorByName("white", fWhite); // white and black always exist
107 fClient->GetColorByName("black", fBlack);
112 if (!fClient->GetColorByName(highlightcolor, fHighLightColor))
116 if (!fClient->GetColorByName(selbackcolor, fSelBackColor))
118 if (!fClient->GetColorByName(selforecolor, fSelForeColor))
120 if (!fClient->GetColorByName(docbackcolor, fDocBackColor))
122 if (!fClient->GetColorByName(docforecolor, fDocForeColor))
124 if (!fClient->GetColorByName(tipbackcolor, fTipBackColor))
126 if (!fClient->GetColorByName(tipforecolor, fTipForeColor))
128
129 // Setup checkered pix/bit-maps...
130 fCheckered = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
131 (const char *)gray_bits,
133 fBackColor, fWhite /*fHilite*/,
134 gVirtualX->GetDepth());
136 (const char *)gray_bits,
138 1, 0, 1);
139
140 // Create picture pool, GC pool, font pool, mime type list, etc.
141
142 // Create picture pool and pre-load some pictures...
143 fPicturePool = new TGPicturePool(fClient, icon_path);
144
147 if (!framebgpixmap.IsNull())
149 if (!docbgpixmap.IsNull())
151
152 // Create font pool and pre-load some fonts...
154 fDefaultFont = fFontPool->GetFont(default_font);
155 fMenuFont = fFontPool->GetFont(menu_font);
156 fMenuHiFont = fFontPool->GetFont(menu_hi_font);
157 fDocFixedFont = fFontPool->GetFont(doc_fixed_font);
158 fDocPropFont = fFontPool->GetFont(doc_prop_font);
159 fIconFont = fFontPool->GetFont(icon_font);
160 fStatusFont = fFontPool->GetFont(status_font);
161
162 // Create GC pool and pre-load some GCs...
163 fGCPool = new TGGCPool(fClient);
164
168 gval.fGraphicsExposures = kFALSE;
169 gval.fFillStyle = kFillSolid;
171 gval.fBackground = fBackColor;
172 gval.fForeground = fBlack;
174
175 gval.fForeground = fWhite;
177
178 gval.fForeground = fHilite;
180
181 gval.fForeground = fShadow;
183
184 gval.fForeground = fBackColor;
186
187 gval.fForeground = fForeColor;
189
190 gval.fForeground = fSelBackColor;
192
193 gval.fForeground = fSelForeColor;
194 gval.fBackground = fSelBackColor;
196
198 gval.fForeground = fDocForeColor;
199 gval.fBackground = fDocBackColor;
201
202 gval.fForeground = fDocBackColor;
204
206 gval.fForeground = fTipForeColor;
207 gval.fBackground = fTipBackColor;
209
213 gval.fForeground = fBlack;
214 gval.fBackground = fSelBackColor;
215 gval.fLineWidth = 0;
216 gval.fFillStyle = kFillStippled;
217 gval.fSubwindowMode = kIncludeInferiors;
218 gval.fGraphicsExposures = kFALSE;
219 gval.fStipple = fCheckeredBitmap;
221
222 // Setup cursors...
224 fGrabCursor = gVirtualX->CreateCursor(kArrowRight);
225 fTextCursor = gVirtualX->CreateCursor(kCaret);
226 fWaitCursor = gVirtualX->CreateCursor(kWatch);
227
228 // Read in mime type...
229 fMimeTypeList = new TGMimeTypes(fClient, mime_file);
230
231 // Clipboard handle...
232#ifndef R__WIN32
233 fClipboardAtom = gVirtualX->InternAtom("_ROOT_CLIPBOARD", kFALSE);
234#else
235 fClipboardAtom = gVirtualX->InternAtom("CLIPBOARD", kFALSE);
236#endif
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Cleanup the resource pool...
241
243{
244 delete fPicturePool;
245 delete fFontPool;
246 delete fGCPool;
247 delete fMimeTypeList;
248
249 gVirtualX->DeletePixmap(fCheckered);
250 gVirtualX->DeletePixmap(fCheckeredBitmap);
251}
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
@ kArrowRight
Definition GuiTypes.h:375
@ kCaret
Definition GuiTypes.h:375
@ kWatch
Definition GuiTypes.h:375
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
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:382
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
const int gray_height
const int gray_width
static unsigned char gray_bits[]
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char forecolor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char backcolor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t gval
@ kReadPermission
Definition TSystem.h:45
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
#define gVirtualX
Definition TVirtualX.h:337
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:25
Handle_t GetId() const
Definition TGObject.h:41
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
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.
~TGResourcePool() override
Cleanup the resource pool...
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:3171
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition TROOT.cxx:3055
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
Bool_t IsNull() const
Definition TString.h:414
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:887
Graphics context structure.
Definition GuiTypes.h:224