Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4Xt.cc
이 파일의 문서화 페이지로 가기
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 // $Id: G4Xt.cc 110808 2018-06-15 06:58:36Z gcosmo $
28 //
29 // G.Barrand
30 
31 #if defined(G4INTY_BUILD_XT) || defined(G4INTY_USE_XT)
32 
33 #include <stdlib.h>
34 #include <string.h>
35 
36 #include <X11/Intrinsic.h>
37 #include <X11/Shell.h>
38 
39 #include "G4ios.hh"
40 
41 #include "G4Xt.hh"
42 
43 #define NewString(str) \
44  ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
45 
46 //static void XWidgetIconify (Widget);
47 //static void XWidgetUniconify (Widget);
48 //static void XDisplaySetWindowToNormalState (Display*,Window);
49 
50 G4Xt* G4Xt::instance = NULL;
51 
52 static G4bool XtInited = FALSE;
53 static int argn = 0;
54 static char** args = NULL;
55 static XtAppContext appContext = NULL;
56 static Widget topWidget = NULL;
57 /***************************************************************************/
58 G4Xt* G4Xt::getInstance (
59 )
60 /***************************************************************************/
62 {
63  return G4Xt::getInstance (0,NULL,(char*)"Geant4");
64 }
65 /***************************************************************************/
66 G4Xt* G4Xt::getInstance (
67  int a_argn
68 ,char** a_args
69 ,char* a_class
70 )
71 /***************************************************************************/
73 {
74  if (instance==NULL) {
75  instance = new G4Xt(a_argn,a_args,a_class);
76  }
77  return instance;
78 }
79 /***************************************************************************/
80 G4Xt::G4Xt (
81  int a_argn
82 ,char** a_args
83 ,char* a_class
84 )
85 /***************************************************************************/
87 {
88  if(XtInited==FALSE) { //Xt should be Inited once !
89  if(a_argn!=0) { //Save args.
90  args = (char**)malloc(a_argn * sizeof(char*));
91  if(args!=NULL) {
92  argn = a_argn;
93  for(int argi=0;argi<a_argn;argi++) {
94  args[argi] = (char*)NewString (a_args[argi]);
95  }
96  }
97  }
98 #if XtSpecificationRelease == 4
99  Cardinal narg;
100  narg = (Cardinal)a_argn;
101 #else
102  int narg;
103  narg = a_argn;
104 #endif
105  Arg xargs[1];
106  XtSetArg (xargs[0],XtNgeometry,"100x100");
107  topWidget = XtAppInitialize (&appContext,a_class,
108  NULL,(Cardinal)0,
109  &narg,a_args,NULL,
110  xargs,1);
111  if(topWidget==NULL) {
112  G4cout << "G4Xt : Unable to init Xt." << G4endl;
113  }
114  // Restore a_args. XtAppInitialize corrupts the given ones !!!
115  if( (a_argn!=0) && (args!=NULL)) {
116  for(int argi=0;argi<a_argn;argi++) {
117  if(args[argi]!=NULL)
118  strcpy(a_args[argi],args[argi]);
119  else
120  a_args[argi] = NULL;
121  }
122  }
123  // If topWidget not realized, pbs with Inventor shells.
124  XtSetMappedWhenManaged (topWidget,False);
125  XtRealizeWidget (topWidget);
126  XtInited = TRUE;
127  }
128  SetArguments (argn,args);
129  SetMainInteractor (topWidget);
130  AddDispatcher(xt_dispatch_event);
131  // Coverity gcc8 cast warning
132  // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
133 }
134 /***************************************************************************/
135 G4Xt::~G4Xt (
136 )
137 /***************************************************************************/
139 {
140  if(this==instance) {
141  instance = NULL;
142  }
143 }
144 /***************************************************************************/
145 G4bool G4Xt::Inited (
146 )
147 /***************************************************************************/
149 {
150  return XtInited;
151 }
152 /***************************************************************************/
153 void* G4Xt::GetEvent (
154 )
155 /***************************************************************************/
157 {
158  static XEvent event;
159  if(appContext==NULL) return NULL;
160  if(topWidget==NULL) return NULL;
161  XtAppNextEvent (appContext, &event);
162  return &event;
163 }
164 /***************************************************************************/
165 void G4Xt::PutStringInResourceDatabase (
166  char* a_string
167 )
168 /***************************************************************************/
170 {
171  if(topWidget==NULL) return;
172  if(a_string==NULL) return;
173  Display* dpy = XtDisplay(topWidget);
174  XrmDatabase dbres = XrmGetStringDatabase (a_string);
175  if(dbres==NULL) return;
176  XrmDatabase database = XrmGetDatabase (dpy);
177  if(database!=NULL) {
178  XrmMergeDatabases (dbres,&database);
179  } else {
180  XrmSetDatabase (dpy,dbres);
181  }
182 }
183 /***************************************************************************/
184 void G4Xt::FlushAndWaitExecution (
185 )
186 /***************************************************************************/
188 {
189  if(topWidget==NULL) return;
190  XSync(XtDisplay(topWidget),False);
191 }
192 
193 #endif
194 
195 
196 
#define G4endl
Definition: G4ios.hh:61
#define NewString(str)
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
static MCTruthManager * instance
G4GLOB_DLL std::ostream G4cout