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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /interfaces/implementation/src/G4UIXm.cc (Version 11.3.0) and /interfaces/implementation/src/G4UIXm.cc (Version 10.7.p2)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27 //                                                
 28 // G.Barrand                                      
 29                                                   
 30 // #define DEBUG                                  
 31                                                   
 32 #include "G4UIXm.hh"                              
 33                                                   
 34 #include "G4StateManager.hh"                      
 35 #include "G4Types.hh"                             
 36 #include "G4UIcommandStatus.hh"                   
 37 #include "G4UIcommandTree.hh"                     
 38 #include "G4UImanager.hh"                         
 39 #include "G4Xt.hh"                                
 40                                                   
 41 #include <X11/Intrinsic.h>                        
 42 #include <X11/Shell.h>                            
 43 #include <X11/keysym.h>                           
 44 #include <Xm/CascadeB.h>                          
 45 #include <Xm/Command.h>                           
 46 #include <Xm/Form.h>                              
 47 #include <Xm/PushB.h>                             
 48 #include <Xm/RowColumn.h>                         
 49 #include <Xm/Text.h>                              
 50 #include <Xm/Xm.h>                                
 51 #include <stdlib.h>                               
 52 #include <string.h>                               
 53                                                   
 54 static void XmTextAppendString(Widget, char*);    
 55                                                   
 56 static void clearButtonCallback(Widget, XtPoin    
 57                                                   
 58 static char* XmConvertCompoundStringToString(X    
 59 static G4bool ConvertStringToInt(const char*,     
 60 static void ExecuteChangeSizeFunction(Widget);    
 61                                                   
 62 static G4bool exitSession = true;                 
 63 static G4bool exitPause = true;                   
 64 static G4bool exitHelp = true;                    
 65 /*********************************************    
 66 G4UIXm::G4UIXm(G4int argc, char** argv)           
 67   : shell(NULL), command(NULL), menuBar(NULL),    
 68 /*********************************************    
 69 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
 70 {                                                 
 71   G4UImanager* UI = G4UImanager::GetUIpointer(    
 72   if (UI != NULL) UI->SetSession(this);           
 73                                                   
 74   G4Xt* interactorManager = G4Xt::getInstance(    
 75                                                   
 76   Widget top = (Widget)interactorManager->GetM    
 77                                                   
 78   if (std::getenv("XENVIRONMENT") == NULL) {      
 79     XrmDatabase database = XrmGetDatabase(XtDi    
 80     if (database != NULL) {                       
 81       XrmPutLineResource(&database, "*topShado    
 82       XrmPutLineResource(&database, "*bottomSh    
 83       XrmPutLineResource(&database, "*foregrou    
 84       XrmPutLineResource(&database, "*backgrou    
 85       XrmPutLineResource(&database, "*borderCo    
 86       XrmPutLineResource(&database, "*fontList    
 87       XrmPutLineResource(&database, "*text.bac    
 88       XrmPutLineResource(&database, "*text.fon    
 89       XrmPutLineResource(&database, "*text.max    
 90     }                                             
 91   }                                               
 92                                                   
 93   Arg args[9];                                    
 94   XtSetArg(args[0], XmNkeyboardFocusPolicy, Xm    
 95   shell = XtAppCreateShell("G4UIXm", "G4UIXm",    
 96   form = XmCreateForm(shell, (char*)menu_str[0    
 97   XtManageChild(form);                            
 98                                                   
 99   XtSetArg(args[0], XmNtopAttachment, XmATTACH    
100   XtSetArg(args[1], XmNleftAttachment, XmATTAC    
101   XtSetArg(args[2], XmNrightAttachment, XmATTA    
102   menuBar = XmCreateMenuBar(form, (char*)menu_    
103                                                   
104   XtSetArg(args[0], XmNtopAttachment, XmATTACH    
105   XtSetArg(args[1], XmNleftAttachment, XmATTAC    
106   XtSetArg(args[2], XmNrightAttachment, XmATTA    
107   XtSetArg(args[3], XmNbottomAttachment, XmATT    
108   command = XmCreateCommand(form, (char*)menu_    
109   XtManageChild(command);                         
110                                                   
111   XtSetArg(args[0], XmNtopAttachment, XmATTACH    
112   XtSetArg(args[1], XmNleftAttachment, XmATTAC    
113   XtSetArg(args[2], XmNrightAttachment, XmATTA    
114   XtSetArg(args[3], XmNbottomAttachment, XmATT    
115   XtSetArg(args[4], XmNbottomWidget, command);    
116   XmString cps = XmStringLtoRCreate((char*)men    
117   XtSetArg(args[5], XmNlabelString, cps);         
118   Widget clearButton = XmCreatePushButton(form    
119   XmStringFree(cps);                              
120   XtManageChild(clearButton);                     
121                                                   
122   XtSetArg(args[0], XmNtopAttachment, XmATTACH    
123   XtSetArg(args[1], XmNtopWidget, menuBar);       
124   XtSetArg(args[2], XmNleftAttachment, XmATTAC    
125   XtSetArg(args[3], XmNrightAttachment, XmATTA    
126   XtSetArg(args[4], XmNbottomAttachment, XmATT    
127   XtSetArg(args[5], XmNbottomWidget, clearButt    
128   XtSetArg(args[6], XmNeditMode, XmMULTI_LINE_    
129   XtSetArg(args[7], XmNrows, 12);                 
130   XtSetArg(args[8], XmNcolumns, 80);              
131   text = XmCreateScrolledText(form, (char*)men    
132   XtManageChild(text);                            
133                                                   
134   XtAddCallback(clearButton, XmNactivateCallba    
135   XtAddCallback(command, XmNcommandEnteredCall    
136                                                   
137   Widget commandText = XmCommandGetChild(comma    
138   XtAddEventHandler(commandText, KeyPressMask,    
139                                                   
140   XtRealizeWidget(shell);                         
141   XtMapWidget(shell);                             
142                                                   
143   if (UI != NULL) UI->SetCoutDestination(this)    
144 }                                                 
145 /*********************************************    
146 G4UIXm::~G4UIXm()                                 
147 /*********************************************    
148 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
149 {                                                 
150   G4UImanager* UI = G4UImanager::GetUIpointer(    
151   if (UI != NULL) {                               
152     UI->SetSession(NULL);                         
153     UI->SetCoutDestination(NULL);                 
154   }                                               
155   XtDestroyWidget(shell);                         
156 }                                                 
157 /*********************************************    
158 G4UIsession* G4UIXm::SessionStart()               
159 /*********************************************    
160 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
161 {                                                 
162   G4Xt* interactorManager = G4Xt::getInstance(    
163   Prompt("session");                              
164   exitSession = false;                            
165   interactorManager->DisableSecondaryLoop();      
166   void* event;                                    
167   while ((event = interactorManager->GetEvent(    
168     interactorManager->DispatchEvent(event);      
169     if (exitSession == true) break;               
170   }                                               
171   interactorManager->EnableSecondaryLoop();       
172   return this;                                    
173 }                                                 
174 /*********************************************    
175 void G4UIXm::Prompt(const G4String& aPrompt)      
176 /*********************************************    
177 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
178 {                                                 
179   Arg args[1];                                    
180   char* str = (char*)XtNewString(aPrompt.data(    
181   XmString cps = XmStringLtoRCreate(str, (char    
182   XtFree(str);                                    
183   XtSetArg(args[0], XmNpromptString, cps);        
184   XtSetValues(command, args, 1);                  
185   XmStringFree(cps);                              
186 }                                                 
187 /*********************************************    
188 void G4UIXm::SessionTerminate()                   
189 /*********************************************    
190 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
191 {}                                                
192 /*********************************************    
193 void G4UIXm::PauseSessionStart(const G4String&    
194 /*********************************************    
195 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
196 {                                                 
197   if (a_state == "G4_pause> ") {                  
198     SecondaryLoop("Pause, type continue to exi    
199   }                                               
200                                                   
201   if (a_state == "EndOfEvent") {                  
202     // Picking with feed back in event data Do    
203     SecondaryLoop("End of event, type continue    
204   }                                               
205 }                                                 
206 /*********************************************    
207 void G4UIXm::SecondaryLoop(const G4String& a_p    
208 /*********************************************    
209 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
210 {                                                 
211   G4Xt* interactorManager = G4Xt::getInstance(    
212   Prompt(a_prompt);                               
213   exitPause = false;                              
214   void* event;                                    
215   while ((event = interactorManager->GetEvent(    
216     interactorManager->DispatchEvent(event);      
217     if (exitPause == true) break;                 
218   }                                               
219   Prompt("session");                              
220 }                                                 
221 /*********************************************    
222 G4int G4UIXm::ReceiveG4debug(const G4String& a    
223 /*********************************************    
224 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
225 {                                                 
226   XmTextAppendString(text, (char*)a_string.dat    
227   return 0;                                       
228 } /*******************************************    
229 G4int G4UIXm::ReceiveG4cout(const G4String& a_    
230 /*********************************************    
231 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
232 {                                                 
233   XmTextAppendString(text, (char*)a_string.dat    
234   return 0;                                       
235 }                                                 
236 /*********************************************    
237 G4int G4UIXm::ReceiveG4cerr(const G4String& a_    
238 /*********************************************    
239 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
240 {                                                 
241   XmTextAppendString(text, (char*)a_string.dat    
242   return 0;                                       
243 }                                                 
244 /*********************************************    
245 G4bool G4UIXm::GetHelpChoice(G4int& aInt)         
246 /*********************************************    
247 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
248 {                                                 
249   fHelp = true;                                   
250   // SecondaryLoop :                              
251   G4Xt* interactorManager = G4Xt::getInstance(    
252   Prompt("Help");                                 
253   exitHelp = false;                               
254   void* event;                                    
255   while ((event = interactorManager->GetEvent(    
256     interactorManager->DispatchEvent(event);      
257     if (exitHelp == true) break;                  
258   }                                               
259   Prompt("session");                              
260   //                                              
261   if (fHelp == false) return false;               
262   aInt = fHelpChoice;                             
263   fHelp = false;                                  
264   return true;                                    
265 }                                                 
266 /*********************************************    
267 void G4UIXm::ExitHelp() const                     
268 /*********************************************    
269 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
270 {}                                                
271 /*********************************************    
272 void G4UIXm::AddMenu(const char* a_name, const    
273 /*********************************************    
274 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
275 {                                                 
276   if (menuBar == NULL) return;                    
277   if (a_name == NULL) return;                     
278   if (a_label == NULL) return;                    
279   XtManageChild(menuBar);                         
280   // Pulldown menu :                              
281   Widget widget;                                  
282   widget = XmCreatePulldownMenu(menuBar, (char    
283   AddInteractor(a_name, (G4Interactor)widget);    
284   // Cascade button :                             
285   Arg args[2];                                    
286   XmString cps = XmStringLtoRCreate((char*)a_l    
287   XtSetArg(args[0], XmNlabelString, cps);         
288   XtSetArg(args[1], XmNsubMenuId, widget);        
289   widget = XmCreateCascadeButton(menuBar, (cha    
290   XmStringFree(cps);                              
291   XtManageChild(widget);                          
292   ExecuteChangeSizeFunction(form);                
293 }                                                 
294 /*********************************************    
295 void G4UIXm::AddButton(const char* a_menu, con    
296 /*********************************************    
297 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
298 {                                                 
299   if (a_menu == NULL) return;                     
300   if (a_label == NULL) return;                    
301   if (a_command == NULL) return;                  
302   Widget parent = (Widget)GetInteractor(a_menu    
303   if (parent == NULL) return;                     
304   Widget widget = XmCreatePushButton(parent, (    
305   XtManageChild(widget);                          
306   XtAddCallback(widget, XmNactivateCallback, B    
307   commands[widget] = a_command;                   
308 }                                                 
309 /*********************************************    
310 G4String G4UIXm::GetCommand(Widget a_widget)      
311 /*********************************************    
312 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
313 {                                                 
314   return commands[a_widget];                      
315 }                                                 
316 /*********************************************    
317 /*********************************************    
318 /*********************************************    
319 void G4UIXm::CommandEnteredCallback(Widget, Xt    
320 /*********************************************    
321 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
322 {                                                 
323   G4UIXm* This = (G4UIXm*)a_tag;                  
324                                                   
325   XmString cps = ((XmCommandCallbackStruct*)a_    
326   char* ss = XmConvertCompoundStringToString(c    
327   G4String scommand(ss);                          
328   XtFree(ss);                                     
329                                                   
330   if (This->fHelp == true) {                      
331     exitHelp = true;                              
332     This->fHelp = ConvertStringToInt(scommand.    
333   }                                               
334   else {                                          
335     This->ApplyShellCommand(scommand, exitSess    
336   }                                               
337                                                   
338   a_tag = NULL;                                   
339 }                                                 
340 /*********************************************    
341 void G4UIXm::keyHandler(Widget a_widget, XtPoi    
342 /*********************************************    
343 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
344 {                                                 
345   KeySym keySym;                                  
346   XLookupString(&(a_event->xkey), NULL, 0, &ke    
347   if (keySym != XK_Tab) return;                   
348   G4UIXm* This = (G4UIXm*)a_tag;                  
349   char* s = XmTextGetString(a_widget);            
350   G4String ss = This->Complete(s);                
351   XmTextSetString(a_widget, (char*)ss.data());    
352   XtFree(s);                                      
353   XmTextSetInsertionPosition(a_widget, XmTextG    
354 }                                                 
355 /*********************************************    
356 void clearButtonCallback(Widget, XtPointer a_t    
357 /*********************************************    
358 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
359 {                                                 
360   static const G4String empty_str = "";           
361   XmTextSetString((Widget)a_tag, (char*)empty_    
362 }                                                 
363 /*********************************************    
364 void G4UIXm::ButtonCallback(Widget a_widget, X    
365 /*********************************************    
366 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
367 {                                                 
368   G4UIXm* This = (G4UIXm*)a_tag;                  
369   if (This->fHelp == true) return;  // Disable    
370   G4String ss = This->GetCommand(a_widget);       
371   This->ApplyShellCommand(ss, exitSession, exi    
372 }                                                 
373 /*********************************************    
374 /*********************************************    
375 /*********************************************    
376 char* XmConvertCompoundStringToString(XmString    
377 /*********************************************    
378 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
379 {                                                 
380   if (a_cps == NULL) return NULL;                 
381   char* ss = NULL;                                
382   XmStringContext context;                        
383   XmStringInitContext(&context, a_cps);           
384   G4int icount = 0;                               
385   Boolean Done = False;                           
386   while (Done == False) {                         
387     char* text = NULL;                            
388     XmStringCharSet charset = NULL;               
389     XmStringDirection direct;                     
390     Boolean sep;                                  
391     if (XmStringGetNextSegment(context, &text,    
392       XtFree(charset);                            
393       if (sep == True) Done = True;               
394       if (icount == a_number) {                   
395         ss = text;                                
396         break;                                    
397       }                                           
398       icount++;                                   
399       XtFree(text);                               
400     }                                             
401     else                                          
402       Done = True;                                
403   }                                               
404   XmStringFreeContext(context);                   
405   return ss;                                      
406 }                                                 
407 /*********************************************    
408 void XmTextAppendString(Widget This, char* a_s    
409 /*********************************************    
410 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
411 {                                                 
412   if (This == NULL) return;                       
413   if (! XtIsSubclass(This, xmTextWidgetClass))    
414   if (a_string == NULL) return;                   
415   XmTextPosition lastpos = XmTextGetLastPositi    
416   XmTextReplace(This, lastpos, lastpos, a_stri    
417   XmTextSetInsertionPosition(This, XmTextGetLa    
418 }                                                 
419 //////////////////////////////////////////////    
420 G4bool ConvertStringToInt(const char* aString,    
421 //////////////////////////////////////////////    
422 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
423 {                                                 
424   aInt = 0;                                       
425   if (aString == NULL) return false;              
426   char* s;                                        
427   G4long value = strtol(aString, &s, 10);         
428   if (s == aString) return false;                 
429   aInt = (G4int)value;                            
430   return true;                                    
431 }                                                 
432 #include <X11/IntrinsicP.h>                       
433 //////////////////////////////////////////////    
434 void ExecuteChangeSizeFunction(Widget aWidget)    
435 //////////////////////////////////////////////    
436 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
437 {                                                 
438   if (aWidget == NULL) return;                    
439   if (aWidget->core.widget_class->core_class.r    
440   (aWidget->core.widget_class->core_class.resi    
441 }                                                 
442