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
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_t *argc, char **argv, void*, Int_t)
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
67 gSystem->NotifyApplicationCreated();
68
70
71 if (fDisplay.IsNull()) gSystem->SetDisplay();
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 // Create the canvas colors early so they are allocated before
83 // any color table expensive bitmaps get allocated in GUI routines (like
84 // creation of XPM bitmaps).
86
87 // Set default screen factor (if not disabled in rc file)
88 if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
89 Int_t x, y;
90 UInt_t w, h;
91 if (gVirtualX) {
92 gVirtualX->GetGeometry(-1, x, y, w, h);
93 if (h > 0)
94 gStyle->SetScreenFactor(0.001 * h);
95 }
96 }
97
98 // Save current interpreter context
99 gInterpreter->SaveContext();
100 gInterpreter->SaveGlobalsContext();
101
102 // to allow user to interact with TCanvas's under WIN32
103 gROOT->SetLineHasBeenProcessed();
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// TGApplication dtor.
108
113
114////////////////////////////////////////////////////////////////////////////////
115/// Load shared libs necessary for GUI.
116
118{
120 TString title1 = "ROOT interface to ";
121 TString nativex, title;
122#ifndef R__WIN32
123 nativex = "x11";
124 name = "X11";
125 title = title1 + "X11";
126#else
127 nativex = "win32gdk";
128 name = "Win32gdk";
129 title = title1 + "Win32gdk";
130#endif
131
132 TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
133 guiBackend.ToLower();
134 if (guiBackend == "native") {
135 guiBackend = nativex;
136 } else {
137 name = guiBackend;
138 title = title1 + guiBackend;
139 }
140
142 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
143 if (h->LoadPlugin() == -1)
144 return;
145 gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
146 }
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Handle command line arguments. Arguments handled are removed from the
151/// argument array. Currently only option "-display xserver" is considered.
152
153void TGApplication::GetOptions(Int_t *argc, char **argv)
154{
155 if (!argc) return;
156
157 int i, j;
158 for (i = 0; i < *argc; i++) {
159 if (argv[i] && !strcmp(argv[i], "-display")) {
160 if (argv[i+1] && strlen(argv[i+1]) && argv[i+1][0] != '-') {
161 fDisplay = argv[i+1];
162 argv[i] = nullptr;
163 argv[i+1] = nullptr;
164 i++;
165 }
166 }
167 }
168
169 j = 0;
170 for (i = 0; i < *argc; i++) {
171 if (argv[i]) {
172 argv[j] = argv[i];
173 j++;
174 }
175 }
176
177 *argc = j;
178}
179
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
externTApplication * gApplication
externTEnv * gEnv
Definition TEnv.h:170
char name[80]
Definition TGX11.cxx:148
#define gInterpreter
#define gROOT
Definition TROOT.h:417
externTStyle * gStyle
Definition TStyle.h:442
externTSystem * gSystem
Definition TSystem.h:582
#define gVirtualX
Definition TVirtualX.h:375
TApplication(const TApplication &)=delete
static void InitializeColors()
TGClient * fClient
pointer to the client environment
void GetOptions(Int_t *argc, char **argv) override
Handle command line arguments.
~TGApplication() override
TGApplication dtor.
void LoadGraphicsLibs() override
Load shared libs necessary for GUI.
TString fDisplay
display server to connect to
Window client.
Definition TGClient.h:37
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1098
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1126
Basic string class.
Definition TString.h:138
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
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