Geant4-11
G4Xt.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28// G.Barrand
29
30#include <stdlib.h>
31#include <string.h>
32
33#include <X11/Intrinsic.h>
34#include <X11/Shell.h>
35
36#include "G4ios.hh"
37
38#include "G4Xt.hh"
39
40#define NewString(str) \
41 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
42
43//static void XWidgetIconify (Widget);
44//static void XWidgetUniconify (Widget);
45//static void XDisplaySetWindowToNormalState (Display*,Window);
46
47G4Xt* G4Xt::instance = NULL;
48
50static int argn = 0;
51static char** args = NULL;
52static XtAppContext appContext = NULL;
53static Widget topWidget = NULL;
54/***************************************************************************/
56)
57/***************************************************************************/
59{
60 return G4Xt::getInstance (0,NULL,(char*)"Geant4");
61}
62/***************************************************************************/
64 int a_argn
65,char** a_args
66,char* a_class
67)
68/***************************************************************************/
70{
71 if (instance==NULL) {
72 instance = new G4Xt(a_argn,a_args,a_class);
73 }
74 return instance;
75}
76/***************************************************************************/
78 int a_argn
79,char** a_args
80,char* a_class
81)
82/***************************************************************************/
84{
85 if(XtInited==FALSE) { //Xt should be Inited once !
86 if(a_argn!=0) { //Save args.
87 args = (char**)malloc(a_argn * sizeof(char*));
88 if(args!=NULL) {
89 argn = a_argn;
90 for(int argi=0;argi<a_argn;argi++) {
91 args[argi] = (char*)NewString (a_args[argi]);
92 }
93 }
94 }
95#if XtSpecificationRelease == 4
96 Cardinal narg;
97 narg = (Cardinal)a_argn;
98#else
99 int narg;
100 narg = a_argn;
101#endif
102 Arg xargs[1];
103 XtSetArg (xargs[0],XtNgeometry,"100x100");
104 topWidget = XtAppInitialize (&appContext,a_class,
105 NULL,(Cardinal)0,
106 &narg,a_args,NULL,
107 xargs,1);
108 if(topWidget==NULL) {
109 G4cout << "G4Xt : Unable to init Xt." << G4endl;
110 }
111 // Restore a_args. XtAppInitialize corrupts the given ones !!!
112 if( (a_argn!=0) && (args!=NULL)) {
113 for(int argi=0;argi<a_argn;argi++) {
114 if(args[argi]!=NULL)
115 strcpy(a_args[argi],args[argi]);
116 else
117 a_args[argi] = NULL;
118 }
119 }
120 // If topWidget not realized, pbs with Inventor shells.
121 XtSetMappedWhenManaged (topWidget,False);
122 XtRealizeWidget (topWidget);
123 XtInited = TRUE;
124 }
128 // Coverity gcc8 cast warning
129 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
130}
131/***************************************************************************/
133)
134/***************************************************************************/
136{
137 if(this==instance) {
138 instance = NULL;
139 }
140}
141/***************************************************************************/
143)
144/***************************************************************************/
146{
147 return XtInited;
148}
149/***************************************************************************/
151)
152/***************************************************************************/
154{
155 static XEvent event;
156 if(appContext==NULL) return NULL;
157 if(topWidget==NULL) return NULL;
158 XtAppNextEvent (appContext, &event);
159 return &event;
160}
161/***************************************************************************/
163 char* a_string
164)
165/***************************************************************************/
167{
168 if(topWidget==NULL) return;
169 if(a_string==NULL) return;
170 Display* dpy = XtDisplay(topWidget);
171 XrmDatabase dbres = XrmGetStringDatabase (a_string);
172 if(dbres==NULL) return;
173 XrmDatabase database = XrmGetDatabase (dpy);
174 if(database!=NULL) {
175 XrmMergeDatabases (dbres,&database);
176 } else {
177 XrmSetDatabase (dpy,dbres);
178 }
179}
180/***************************************************************************/
182)
183/***************************************************************************/
185{
186 if(topWidget==NULL) return;
187 XSync(XtDisplay(topWidget),False);
188}
bool G4bool
Definition: G4Types.hh:86
static Widget topWidget
Definition: G4Xt.cc:53
static G4bool XtInited
Definition: G4Xt.cc:49
#define NewString(str)
Definition: G4Xt.cc:40
static XtAppContext appContext
Definition: G4Xt.cc:52
static int argn
Definition: G4Xt.cc:50
static char ** args
Definition: G4Xt.cc:51
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
void AddDispatcher(G4DispatchFunction)
void SetMainInteractor(G4Interactor)
void SetArguments(int, char **)
Definition: G4Xt.hh:48
virtual ~G4Xt()
Definition: G4Xt.cc:132
void * GetEvent()
Definition: G4Xt.cc:150
G4bool Inited()
Definition: G4Xt.cc:142
static G4Xt * getInstance()
Definition: G4Xt.cc:55
static G4Xt * instance
Definition: G4Xt.hh:65
void FlushAndWaitExecution()
Definition: G4Xt.cc:181
void PutStringInResourceDatabase(char *)
Definition: G4Xt.cc:162
G4Xt(const G4Xt &)
static bool xt_dispatch_event(void *a_event)
Definition: G4Xt.hh:58