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,v 1.11 2006/06/29 19:10:28 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-08-01 $ |
---|
29 | // |
---|
30 | // G.Barrand |
---|
31 | |
---|
32 | #if defined(G4INTY_BUILD_XT) || defined(G4INTY_USE_XT) |
---|
33 | |
---|
34 | #include <stdlib.h> |
---|
35 | #include <string.h> |
---|
36 | |
---|
37 | #include <X11/Intrinsic.h> |
---|
38 | #include <X11/Shell.h> |
---|
39 | |
---|
40 | #include "G4ios.hh" |
---|
41 | |
---|
42 | #include "G4Xt.hh" |
---|
43 | |
---|
44 | #define NewString(str) \ |
---|
45 | ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL) |
---|
46 | |
---|
47 | //static void XWidgetIconify (Widget); |
---|
48 | //static void XWidgetUniconify (Widget); |
---|
49 | //static void XDisplaySetWindowToNormalState (Display*,Window); |
---|
50 | |
---|
51 | G4Xt* G4Xt::instance = NULL; |
---|
52 | |
---|
53 | static G4bool XtInited = FALSE; |
---|
54 | static int argn = 0; |
---|
55 | static char** args = NULL; |
---|
56 | static XtAppContext appContext = NULL; |
---|
57 | static Widget topWidget = NULL; |
---|
58 | /***************************************************************************/ |
---|
59 | G4Xt* G4Xt::getInstance ( |
---|
60 | ) |
---|
61 | /***************************************************************************/ |
---|
62 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
63 | { |
---|
64 | return G4Xt::getInstance (0,NULL,(char*)"Geant4"); |
---|
65 | } |
---|
66 | /***************************************************************************/ |
---|
67 | G4Xt* G4Xt::getInstance ( |
---|
68 | int a_argn |
---|
69 | ,char** a_args |
---|
70 | ,char* a_class |
---|
71 | ) |
---|
72 | /***************************************************************************/ |
---|
73 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
74 | { |
---|
75 | if (instance==NULL) { |
---|
76 | instance = new G4Xt(a_argn,a_args,a_class); |
---|
77 | } |
---|
78 | return instance; |
---|
79 | } |
---|
80 | /***************************************************************************/ |
---|
81 | G4Xt::G4Xt ( |
---|
82 | int a_argn |
---|
83 | ,char** a_args |
---|
84 | ,char* a_class |
---|
85 | ) |
---|
86 | /***************************************************************************/ |
---|
87 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
88 | { |
---|
89 | if(XtInited==FALSE) { //Xt should be Inited once ! |
---|
90 | if(a_argn!=0) { //Save args. |
---|
91 | args = (char**)malloc(a_argn * sizeof(char*)); |
---|
92 | if(args!=NULL) { |
---|
93 | argn = a_argn; |
---|
94 | for(int argi=0;argi<a_argn;argi++) { |
---|
95 | args[argi] = (char*)NewString (a_args[argi]); |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | #if XtSpecificationRelease == 4 |
---|
100 | Cardinal narg; |
---|
101 | narg = (Cardinal)a_argn; |
---|
102 | #else |
---|
103 | int narg; |
---|
104 | narg = a_argn; |
---|
105 | #endif |
---|
106 | Arg xargs[1]; |
---|
107 | XtSetArg (xargs[0],XtNgeometry,"100x100"); |
---|
108 | topWidget = XtAppInitialize (&appContext,a_class, |
---|
109 | NULL,(Cardinal)0, |
---|
110 | &narg,a_args,NULL, |
---|
111 | xargs,1); |
---|
112 | if(topWidget==NULL) { |
---|
113 | G4cout << "G4Xt : Unable to init Xt." << G4endl; |
---|
114 | } |
---|
115 | // Restore a_args. XtAppInitialize corrupts the given ones !!! |
---|
116 | if( (a_argn!=0) && (args!=NULL)) { |
---|
117 | for(int argi=0;argi<a_argn;argi++) { |
---|
118 | if(args[argi]!=NULL) |
---|
119 | strcpy(a_args[argi],args[argi]); |
---|
120 | else |
---|
121 | a_args[argi] = NULL; |
---|
122 | } |
---|
123 | } |
---|
124 | // If topWidget not realized, pbs with Inventor shells. |
---|
125 | XtSetMappedWhenManaged (topWidget,False); |
---|
126 | XtRealizeWidget (topWidget); |
---|
127 | XtInited = TRUE; |
---|
128 | } |
---|
129 | SetArguments (argn,args); |
---|
130 | SetMainInteractor (topWidget); |
---|
131 | AddDispatcher ((G4DispatchFunction)XtDispatchEvent); |
---|
132 | } |
---|
133 | /***************************************************************************/ |
---|
134 | G4Xt::~G4Xt ( |
---|
135 | ) |
---|
136 | /***************************************************************************/ |
---|
137 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
138 | { |
---|
139 | if(this==instance) { |
---|
140 | instance = NULL; |
---|
141 | } |
---|
142 | } |
---|
143 | /***************************************************************************/ |
---|
144 | G4bool G4Xt::Inited ( |
---|
145 | ) |
---|
146 | /***************************************************************************/ |
---|
147 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
148 | { |
---|
149 | return XtInited; |
---|
150 | } |
---|
151 | /***************************************************************************/ |
---|
152 | void* G4Xt::GetEvent ( |
---|
153 | ) |
---|
154 | /***************************************************************************/ |
---|
155 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
156 | { |
---|
157 | static XEvent event; |
---|
158 | if(appContext==NULL) return NULL; |
---|
159 | if(topWidget==NULL) return NULL; |
---|
160 | XtAppNextEvent (appContext, &event); |
---|
161 | return &event; |
---|
162 | } |
---|
163 | /***************************************************************************/ |
---|
164 | void G4Xt::PutStringInResourceDatabase ( |
---|
165 | char* a_string |
---|
166 | ) |
---|
167 | /***************************************************************************/ |
---|
168 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
169 | { |
---|
170 | if(topWidget==NULL) return; |
---|
171 | if(a_string==NULL) return; |
---|
172 | Display* dpy = XtDisplay(topWidget); |
---|
173 | XrmDatabase dbres = XrmGetStringDatabase (a_string); |
---|
174 | if(dbres==NULL) return; |
---|
175 | XrmDatabase database = XrmGetDatabase (dpy); |
---|
176 | if(database!=NULL) { |
---|
177 | XrmMergeDatabases (dbres,&database); |
---|
178 | } else { |
---|
179 | XrmSetDatabase (dpy,dbres); |
---|
180 | } |
---|
181 | } |
---|
182 | /***************************************************************************/ |
---|
183 | void G4Xt::FlushAndWaitExecution ( |
---|
184 | ) |
---|
185 | /***************************************************************************/ |
---|
186 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
187 | { |
---|
188 | if(topWidget==NULL) return; |
---|
189 | XSync(XtDisplay(topWidget),False); |
---|
190 | } |
---|
191 | |
---|
192 | #endif |
---|
193 | |
---|
194 | |
---|
195 | |
---|