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