Logo ROOT  
Reference Guide
TGApplication.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Guy Barrand 30/05/2001
3
4/*************************************************************************
5 * Copyright (C) 2001, Guy Barrand. *
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// //
14// TGApplication //
15// //
16// This class initialize the ROOT GUI toolkit. //
17// This class must be instantiated exactly once in any given //
18// application. //
19// //
20//////////////////////////////////////////////////////////////////////////
21
22#include "RConfigure.h"
23
24#include "TGApplication.h"
25#include "TROOT.h"
26#include "TSystem.h"
27#include "TGClient.h"
28#include "TPluginManager.h"
29#include "TError.h"
30#include "TEnv.h"
31#include "TVirtualX.h"
32#include "TStyle.h"
33#include "TInterpreter.h"
34#include "TColor.h"
35
37
38////////////////////////////////////////////////////////////////////////////////
39/// Create a GUI application environment. Use this class if you only
40/// want to use the ROOT GUI and no other services. In all other cases
41/// use either TApplication or TRint.
42
43TGApplication::TGApplication(const char *appClassName,
44 int *argc, char **argv, void*, int)
45 : TApplication()
46{
47 if (gApplication) {
48 Error("TGApplication", "only one instance of TGApplication allowed");
49 return;
50 }
51
52 if (!gROOT)
53 ::Fatal("TGApplication::TGApplication", "ROOT system not initialized");
54
55 if (!gSystem)
56 ::Fatal("TGApplication::TGApplication", "gSystem not initialized");
57
58 gApplication = this;
59 gROOT->SetApplication(this);
60 gROOT->SetName(appClassName);
61
62 GetOptions(argc, argv);
63 if (argv && argv[0])
64 gSystem->SetProgname(argv[0]);
65
66 // Tell TSystem the TApplication has been created
68
70
73
74 if (fClient->IsZombie()) {
75 Error("TGApplication", "cannot switch to batch mode, exiting...");
76 gSystem->Exit(1);
77 }
78
79 // a GUI application is never run in batch mode
80 gROOT->SetBatch(kFALSE);
81
82 if (strcmp(appClassName, "proofserv")) {
83 const char *ttpath = gEnv->GetValue("Root.TTFontPath",
85 char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
86 // Added by cholm for use of DFSG - fonts - based on fix by Kevin
87 if (!ttfont)
88 ttfont = gSystem->Which(ttpath, "FreeSansBold.ttf", kReadPermission);
89 if (ttfont && gEnv->GetValue("Root.UseTTFonts", 1)) {
91 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
92 if (h->LoadPlugin() == -1)
93 Info("TGApplication", "no TTF support");
94 }
95
96 delete [] ttfont;
97 }
98
99 // Create the canvas colors early so they are allocated before
100 // any color table expensive bitmaps get allocated in GUI routines (like
101 // creation of XPM bitmaps).
103
104 // Set default screen factor (if not disabled in rc file)
105 if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
106 Int_t x, y;
107 UInt_t w, h;
108 if (gVirtualX) {
109 gVirtualX->GetGeometry(-1, x, y, w, h);
110 if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
111 }
112 }
113
114 // Save current interpreter context
115 gInterpreter->SaveContext();
116 gInterpreter->SaveGlobalsContext();
117
118 // to allow user to interact with TCanvas's under WIN32
119 gROOT->SetLineHasBeenProcessed();
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// TGApplication dtor.
124
126{
127 delete fClient;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Load shared libs necessary for GUI.
132
134{
136 TString title1 = "ROOT interface to ";
137 TString nativex, title;
138#ifndef R__WIN32
139 nativex = "x11";
140 name = "X11";
141 title = title1 + "X11";
142#else
143 nativex = "win32gdk";
144 name = "Win32gdk";
145 title = title1 + "Win32gdk";
146#endif
147
148 TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
149 guiBackend.ToLower();
150 if (guiBackend == "native") {
151 guiBackend = nativex;
152 } else {
153 name = guiBackend;
154 title = title1 + guiBackend;
155 }
156
158 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
159 if (h->LoadPlugin() == -1)
160 return;
161 gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
162 }
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Handle command line arguments. Arguments handled are removed from the
167/// argument array. Currently only option "-display xserver" is considered.
168
169void TGApplication::GetOptions(Int_t *argc, char **argv)
170{
171 if (!argc) return;
172
173 int i, j;
174 for (i = 0; i < *argc; i++) {
175 if (!strcmp(argv[i], "-display")) {
176 if (argv[i+1] && strlen(argv[i+1]) && argv[i+1][0] != '-') {
177 fDisplay = argv[i+1];
178 argv[i] = nullptr;
179 argv[i+1] = nullptr;
180 i++;
181 }
182 }
183 }
184
185 j = 0;
186 for (i = 0; i < *argc; i++) {
187 if (argv[i]) {
188 argv[j] = argv[i];
189 j++;
190 }
191 }
192
193 *argc = j;
194}
195
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kFALSE
Definition: RtypesCore.h:90
#define ClassImp(name)
Definition: Rtypes.h:361
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
char name[80]
Definition: TGX11.cxx:109
#define gInterpreter
Definition: TInterpreter.h:556
#define gROOT
Definition: TROOT.h:406
R__EXTERN TStyle * gStyle
Definition: TStyle.h:410
@ kReadPermission
Definition: TSystem.h:46
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
#define gVirtualX
Definition: TVirtualX.h:338
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:39
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:1086
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
virtual void LoadGraphicsLibs()
Load shared libs necessary for GUI.
virtual void GetOptions(Int_t *argc, char **argv)
Handle command line arguments.
TGClient * fClient
Definition: TGApplication.h:35
virtual ~TGApplication()
TGApplication dtor.
TString fDisplay
Definition: TGApplication.h:34
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition: TObject.h:149
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:919
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:865
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
Definition: TROOT.cxx:3076
Basic string class.
Definition: TString.h:131
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
const char * Data() const
Definition: TString.h:364
Bool_t IsNull() const
Definition: TString.h:402
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:301
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Definition: TSystem.cxx:309
virtual void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
Definition: TSystem.cxx:229
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:714
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1541
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition: TSystem.cxx:220
Semi-Abstract base class defining a generic interface to the underlying, low level,...
Definition: TVirtualX.h:46
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17