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
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
63 if (argv && 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 // 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") {
136 } else {
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
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
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
char name[80]
Definition TGX11.cxx:110
#define gInterpreter
#define gROOT
Definition TROOT.h:411
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define gVirtualX
Definition TVirtualX.h:337
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:1172
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:490
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
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:159
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1099
Longptr_t ExecPlugin(int nargs)
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Bool_t IsNull() const
Definition TString.h:422
void SetScreenFactor(Float_t factor=1)
Definition TStyle.h:321
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:233
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:725
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition TSystem.cxx:224
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