source: trunk/source/interfaces/basic/src/G4UIXaw.cc@ 1302

Last change on this file since 1302 was 1156, checked in by garnier, 16 years ago

append qt3 fix

File size: 8.5 KB
RevLine 
[476]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: G4UIXaw.cc,v 1.6 2006/06/29 19:09:47 gunter Exp $
[1156]28// GEANT4 tag $Name: $
[476]29//
30// G.Barrand
31
32//#define DEBUG
33
34#ifdef G4UI_BUILD_XAW_SESSION
35
36#include <X11/Intrinsic.h>
37#include <X11/StringDefs.h>
38#include <X11/Shell.h>
39
40#include <Xaw/Dialog.h>
41#include <Xaw/Command.h>
42
43#include "G4UIXaw.hh"
44#include "G4UImanager.hh"
45#include "G4StateManager.hh"
46#include "G4UIcommandTree.hh"
47#include "G4UIcommandStatus.hh"
48#include "G4Xt.hh"
49
50static G4bool ConvertStringToInt(const char*,int&);
51
52static G4bool exitSession = true;
53static G4bool exitPause = true;
54static G4bool exitHelp = true;
55/***************************************************************************/
56G4UIXaw::G4UIXaw (
57 int argc
58,char** argv
59)
60:fHelp(false)
61,fHelpChoice(0)
62/***************************************************************************/
63/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
64{
65 G4UImanager* UI = G4UImanager::GetUIpointer();
66 if(UI!=NULL) UI->SetSession(this);
67
68 G4Xt* interactorManager = G4Xt::getInstance (argc,argv,(char*)"Xaw");
69 Widget top = (Widget)interactorManager->GetMainInteractor();
70
71 shell = XtAppCreateShell ("G4UIXaw","G4UIXaw",topLevelShellWidgetClass,XtDisplay(top),NULL,0);
72
73 Arg args[2];
74 XtSetArg (args[0],XtNlabel,"G4 command");
75 XtSetArg (args[1],XtNvalue,""); // Needed to have a text Area.
76 dialog = XtCreateManagedWidget ("dialog",dialogWidgetClass,shell,args,2);
77
78 XawDialogAddButton (dialog,"Ok",Callback,(XtPointer)this);
79
80 XtRealizeWidget (shell);
81}
82/***************************************************************************/
83G4UIXaw::~G4UIXaw (
84)
85/***************************************************************************/
86/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
87{
88 XtDestroyWidget (shell);
89 G4UImanager* UI = G4UImanager::GetUIpointer();
90 if(UI!=NULL) UI->SetSession(NULL);
91}
92/***************************************************************************/
93G4UIsession* G4UIXaw::SessionStart (
94)
95/***************************************************************************/
96/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
97{
98 G4Xt* interactorManager = G4Xt::getInstance ();
99 Prompt ("session");
100 exitSession = false;
101 interactorManager->DisableSecondaryLoop ();
102 void* event;
103 while((event = interactorManager->GetEvent())!=NULL) {
104 interactorManager->DispatchEvent(event);
105 if(exitSession==true) break;
106 }
107 interactorManager->EnableSecondaryLoop ();
108 return this;
109}
110/***************************************************************************/
111void G4UIXaw::Prompt (
112 G4String aPrompt
113)
114/***************************************************************************/
115/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
116{
117 Arg args[1];
118 XtSetArg (args[0],XtNlabel,aPrompt.data());
119 XtSetValues (dialog,args,1);
120}
121/***************************************************************************/
122void G4UIXaw::SessionTerminate (
123)
124/***************************************************************************/
125/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
126{
127}
128/***************************************************************************/
129void G4UIXaw::PauseSessionStart (
130 G4String a_state
131)
132/***************************************************************************/
133/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
134{
135 if(a_state=="G4_pause> ") {
136 SecondaryLoop ("Pause, type continue to exit this state");
137 }
138
139 if(a_state=="EndOfEvent") {
140 // Picking with feed back in event data Done here !!!
141 SecondaryLoop ("End of event, type continue to exit this state");
142 }
143}
144/***************************************************************************/
145void G4UIXaw::SecondaryLoop (
146 G4String a_prompt
147)
148/***************************************************************************/
149/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
150{
151 G4Xt* interactorManager = G4Xt::getInstance ();
152 Prompt (a_prompt);
153 exitPause = false;
154 void* event;
155 while((event = interactorManager->GetEvent())!=NULL) {
156 interactorManager->DispatchEvent(event);
157 if(exitPause==true) break;
158 }
159 Prompt ("session");
160}
161/***************************************************************************/
162Widget G4UIXaw::GetDialog (
163)
164/***************************************************************************/
165/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
166{
167 return dialog;
168}
169/***************************************************************************/
170G4bool G4UIXaw::GetHelpChoice(
171 G4int& aInt
172)
173/***************************************************************************/
174/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
175{
176 fHelp = true;
177 //
178 G4Xt* interactorManager = G4Xt::getInstance ();
179 Prompt("Help");
180 exitHelp = false;
181 void* event;
182 while((event = interactorManager->GetEvent())!=NULL) {
183 interactorManager->DispatchEvent(event);
184 if(exitHelp==true) break;
185 }
186 Prompt("session");
187 //
188 if(fHelp==false) return false;
189 aInt = fHelpChoice;
190 fHelp = false;
191 return true;
192}
193/***************************************************************************/
194void G4UIXaw::ExitHelp(
195)
196/***************************************************************************/
197/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
198{
199}
200/***************************************************************************/
201/***************************************************************************/
202/***************************************************************************/
203void G4UIXaw::Callback (
204 Widget a_widget
205,XtPointer a_tag
206,XtPointer a_data
207)
208/***************************************************************************/
209/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
210{
211 G4UIXaw* This = (G4UIXaw*)a_tag;
212 Widget dialog = This->GetDialog();
213 char* value = XawDialogGetValueString(dialog);
214 if(value==NULL) return;
215 G4String command (value);
216
217 if(This->fHelp==true) {
218 exitHelp = true;
219 This->fHelp = ConvertStringToInt(command.data(),This->fHelpChoice);
220 } else {
221 This->ApplyShellCommand (command,exitSession,exitPause);
222 }
223
224 Arg args[1];
225 XtSetArg (args[0],XtNvalue,"");
226 XtSetValues (dialog,args,1);
227
228 a_widget = NULL;
229 a_data = NULL;
230}
231//////////////////////////////////////////////////////////////////////////////
232G4bool ConvertStringToInt(
233 const char* aString
234,int& aInt
235)
236//////////////////////////////////////////////////////////////////////////////
237//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
238{
239 aInt = 0;
240 if(aString==NULL) return false;
241 char* s;
242 long value = strtol(aString,&s,10);
243 if(s==aString) return false;
244 aInt = value;
245 return true;
246}
247
248#endif
Note: See TracBrowser for help on using the repository browser.