ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
43 TGApplication::TGApplication(const char *appClassName,
44  int *argc, char **argv, void*, int)
45  : TApplication(), fDisplay(0), fClient(0)
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 
69  // Enable autoloading
70  gInterpreter->EnableAutoLoading();
71 
72  LoadGraphicsLibs();
73 
74  if (!fDisplay) gSystem->SetDisplay();
75  fClient = new TGClient(fDisplay);
76 
77  if (fClient->IsZombie()) {
78  Error("TGApplication", "cannot switch to batch mode, exiting...");
79  gSystem->Exit(1);
80  }
81 
82  // a GUI application is never run in batch mode
83  gROOT->SetBatch(kFALSE);
84 
85  if (strcmp(appClassName, "proofserv")) {
86  const char *ttpath = gEnv->GetValue("Root.TTFontPath",
87 #ifdef TTFFONTDIR
88  TTFFONTDIR);
89 #else
90  "$(ROOTSYS)/fonts");
91 #endif
92 
93  char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
94  // Added by cholm for use of DFSG - fonts - based on fix by Kevin
95  if (!ttfont)
96  ttfont = gSystem->Which(ttpath, "FreeSansBold.ttf", kReadPermission);
97  if (ttfont && gEnv->GetValue("Root.UseTTFonts", 1)) {
99  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
100  if (h->LoadPlugin() == -1)
101  Info("TGApplication", "no TTF support");
102  }
103 
104  delete [] ttfont;
105  }
106 
107  // Create the canvas colors early so they are allocated before
108  // any color table expensive bitmaps get allocated in GUI routines (like
109  // creation of XPM bitmaps).
111 
112  // Set default screen factor (if not disabled in rc file)
113  if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
114  Int_t x, y;
115  UInt_t w, h;
116  if (gVirtualX) {
117  gVirtualX->GetGeometry(-1, x, y, w, h);
118  if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
119  }
120  }
121 
122  // Save current interpreter context
123  gInterpreter->SaveContext();
124  gInterpreter->SaveGlobalsContext();
125 
126  // to allow user to interact with TCanvas's under WIN32
127  gROOT->SetLineHasBeenProcessed();
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// TGApplication dtor.
132 
134 {
135  delete fDisplay;
136  delete fClient;
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Load shared libs necessary for GUI.
141 
143 {
144  TString name;
145  TString title1 = "ROOT interface to ";
146  TString nativex, title;
147 #ifndef R__WIN32
148  nativex = "x11";
149  name = "X11";
150  title = title1 + "X11";
151 #else
152  nativex = "win32gdk";
153  name = "Win32gdk";
154  title = title1 + "Win32gdk";
155 #endif
156 
157  TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
158  guiBackend.ToLower();
159  if (guiBackend == "native") {
160  guiBackend = nativex;
161  } else {
162  name = guiBackend;
163  title = title1 + guiBackend;
164  }
165 
166  TPluginHandler *h;
167  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
168  if (h->LoadPlugin() == -1)
169  return;
170  gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
171  }
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Handle command line arguments. Arguments handled are removed from the
176 /// argument array. Currently only option "-display xserver" is considered.
177 
178 void TGApplication::GetOptions(Int_t *argc, char **argv)
179 {
180  if (!argc) return;
181 
182  int i, j;
183  for (i = 0; i < *argc; i++) {
184  if (!strcmp(argv[i], "-display")) {
185  if (argv[i+1] && strlen(argv[i+1]) && argv[i+1][0] != '-') {
186  fDisplay = StrDup(argv[i+1]);
187  argv[i] = 0;
188  argv[i+1] = 0;
189  i++;
190  }
191  }
192  }
193 
194  j = 0;
195  for (i = 0; i < *argc; i++) {
196  if (argv[i]) {
197  argv[j] = argv[i];
198  j++;
199  }
200  }
201 
202  *argc = j;
203 }
204 
Semi-Abstract base class defining a generic interface to the underlying, low level, native graphics backend (X11, Win32, MacOS, OpenGL...).
Definition: TVirtualX.h:70
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Definition: TSystem.cxx:315
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
TH1 * h
Definition: legend2.C:5
#define gROOT
Definition: TROOT.h:344
virtual ~TGApplication()
TGApplication dtor.
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:137
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1075
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
#define gInterpreter
Definition: TInterpreter.h:502
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1459
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
Long_t ExecPlugin(int nargs, const T &...params)
const char * Data() const
Definition: TString.h:349
Double_t x[n]
Definition: legend1.C:17
virtual void LoadGraphicsLibs()
Load shared libs necessary for GUI.
void Info(const char *location, const char *msgfmt,...)
virtual void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
Definition: TSystem.cxx:235
TGClient * fClient
Definition: TGApplication.h:37
void Error(const char *location, const char *msgfmt,...)
virtual void GetOptions(Int_t *argc, char **argv)
Handle command line arguments.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:315
ClassImp(TGApplication) TGApplication
Create a GUI application environment.
unsigned int UInt_t
Definition: RtypesCore.h:42
tuple w
Definition: qtexample.py:51
#define gVirtualX
Definition: TVirtualX.h:362
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2500
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
Double_t y[n]
Definition: legend1.C:17
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition: TSystem.cxx:227
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:720
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:365
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:45