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