36#include <X11/Intrinsic.h>
38#include <X11/keysym.h>
41#include <Xm/Command.h>
42#include <Xm/RowColumn.h>
45#include <Xm/CascadeB.h>
58static void XmTextAppendString (Widget,
char*);
60static void clearButtonCallback (Widget,XtPointer,XtPointer);
62static char* XmConvertCompoundStringToString (XmString,
G4int);
63static G4bool ConvertStringToInt(
const char*,
G4int&);
64static void ExecuteChangeSizeFunction(Widget);
66static G4bool exitSession =
true;
67static G4bool exitPause =
true;
68static G4bool exitHelp =
true;
90 if(std::getenv(
"XENVIRONMENT")==NULL) {
91 XrmDatabase database = XrmGetDatabase(XtDisplay(top));
93 XrmPutLineResource(&database,
"*topShadowColor:white");
94 XrmPutLineResource(&database,
"*bottomShadowColor:black");
95 XrmPutLineResource(&database,
"*foreground:black");
96 XrmPutLineResource(&database,
"*background:lightgrey");
97 XrmPutLineResource(&database,
"*borderColor:lightgrey");
98 XrmPutLineResource(&database,
"*fontList:-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1");
99 XrmPutLineResource(&database,
"*text.background:white");
100 XrmPutLineResource(&database,
"*text.fontList:*courier*-r-*--14-*");
101 XrmPutLineResource(&database,
"*text.maxLength:8000");
106 XtSetArg(args[0],XmNkeyboardFocusPolicy,XmPOINTER);
107 shell = XtAppCreateShell (
"G4UIXm",
"G4UIXm",
108 topLevelShellWidgetClass,XtDisplay(top),
110 form = XmCreateForm (shell,(
char*)menu_str[0].c_str(),NULL,0);
111 XtManageChild (form);
113 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
114 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
115 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
116 menuBar = XmCreateMenuBar (form,(
char*)menu_str[1].c_str(),args,3);
118 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE);
119 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
120 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
121 XtSetArg(args[3],XmNbottomAttachment ,XmATTACH_FORM);
122 command = XmCreateCommand (form,(
char*)menu_str[2].c_str(),args,4);
123 XtManageChild (command);
125 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE);
126 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
127 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
128 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
129 XtSetArg(args[4],XmNbottomWidget ,command);
130 XmString cps = XmStringLtoRCreate((
char*)menu_str[3].c_str(),(
char*)XmSTRING_DEFAULT_CHARSET);
131 XtSetArg (args[5],XmNlabelString,cps);
132 Widget clearButton = XmCreatePushButton(form,(
char*)menu_str[4].c_str(),args,6);
134 XtManageChild (clearButton);
136 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
137 XtSetArg(args[1],XmNtopWidget ,menuBar);
138 XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
139 XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
140 XtSetArg(args[4],XmNbottomAttachment,XmATTACH_WIDGET);
141 XtSetArg(args[5],XmNbottomWidget ,clearButton);
142 XtSetArg(args[6],XmNeditMode ,XmMULTI_LINE_EDIT);
143 XtSetArg(args[7],XmNrows ,12);
144 XtSetArg(args[8],XmNcolumns ,80);
145 text = XmCreateScrolledText (form,(
char*)menu_str[5].c_str(),args,9);
146 XtManageChild (text);
148 XtAddCallback(clearButton,XmNactivateCallback,
149 clearButtonCallback,(XtPointer)text);
150 XtAddCallback(command,XmNcommandEnteredCallback,
151 CommandEnteredCallback,(XtPointer)
this);
153 Widget commandText = XmCommandGetChild(command,XmDIALOG_COMMAND_TEXT);
154 XtAddEventHandler(commandText,KeyPressMask,False,keyHandler,(XtPointer)
this);
156 XtRealizeWidget(shell);
172 XtDestroyWidget(shell);
185 while((event = interactorManager->
GetEvent())!=NULL) {
187 if(exitSession==
true)
break;
200 char* str = (
char*)XtNewString(aPrompt.data());
201 XmString cps = XmStringLtoRCreate(str,(
char*)XmSTRING_DEFAULT_CHARSET);
203 XtSetArg(args[0],XmNpromptString,cps);
204 XtSetValues(command,args,1);
221 if(a_state==
"G4_pause> ") {
222 SecondaryLoop (
"Pause, type continue to exit this state");
225 if(a_state==
"EndOfEvent") {
227 SecondaryLoop (
"End of event, type continue to exit this state");
231void G4UIXm::SecondaryLoop (
241 while((event = interactorManager->
GetEvent())!=NULL) {
243 if(exitPause==
true)
break;
254 XmTextAppendString(text,(
char*)a_string.data());
264 XmTextAppendString(text,(
char*)a_string.data());
268G4bool G4UIXm::GetHelpChoice(
280 while((event = interactorManager->
GetEvent())!=NULL) {
282 if(exitHelp==
true)
break;
286 if(fHelp==
false)
return false;
292void G4UIXm::ExitHelp(
306 if(menuBar==NULL)
return;
307 if(a_name==NULL)
return;
308 if(a_label==NULL)
return;
309 XtManageChild (menuBar);
312 widget = XmCreatePulldownMenu (menuBar,(
char*)a_name,NULL,0);
316 XmString cps = XmStringLtoRCreate((
char*)a_label,(
char*)XmSTRING_DEFAULT_CHARSET);
317 XtSetArg (args[0],XmNlabelString,cps);
318 XtSetArg (args[1],XmNsubMenuId,widget);
319 widget = XmCreateCascadeButton (menuBar,(
char*)a_name,args,2);
321 XtManageChild (widget);
322 ExecuteChangeSizeFunction(form);
328,
const char* a_command
333 if(a_menu==NULL)
return;
334 if(a_label==NULL)
return;
335 if(a_command==NULL)
return;
337 if(parent==NULL)
return;
338 Widget widget = XmCreatePushButton(parent,(
char*)a_label,NULL,0);
339 XtManageChild (widget);
340 XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)
this);
341 commands[widget] = a_command;
350 return commands[a_widget];
355void G4UIXm::CommandEnteredCallback (
365 XmString cps = ((XmCommandCallbackStruct*)a_data)->value;
366 char* ss = XmConvertCompoundStringToString(cps,0);
370 if(This->fHelp==
true) {
372 This->fHelp = ConvertStringToInt(scommand.data(),This->fHelpChoice);
380void G4UIXm::keyHandler (
390 XLookupString(&(a_event->xkey),NULL,0,&keySym,NULL);
391 if(keySym!=XK_Tab)
return;
393 char* s = XmTextGetString(a_widget);
395 XmTextSetString(a_widget,(
char*)ss.data());
397 XmTextSetInsertionPosition(a_widget,XmTextGetLastPosition(a_widget));
400void clearButtonCallback (
408 static const G4String empty_str =
"";
409 XmTextSetString((Widget)a_tag,(
char*)empty_str.c_str());
412void G4UIXm::ButtonCallback (
421 if(This->fHelp==
true)
return;
428char* XmConvertCompoundStringToString (
435 if(a_cps==NULL)
return NULL;
437 XmStringContext context;
438 XmStringInitContext(&context,a_cps);
440 Boolean Done = False;
443 XmStringCharSet charset = NULL;
444 XmStringDirection direct;
446 if(XmStringGetNextSegment(context,&text,&charset,&direct,&sep)==True) {
448 if(sep==True) Done = True;
449 if(icount==a_number) {
459 XmStringFreeContext(context);
463void XmTextAppendString (
470 if(This==NULL)
return;
471 if(!XtIsSubclass(This,xmTextWidgetClass))
return;
472 if(a_string==NULL)
return;
473 XmTextPosition lastpos = XmTextGetLastPosition(This);
474 XmTextReplace(This,lastpos,lastpos,a_string);
475 XmTextSetInsertionPosition(This,XmTextGetLastPosition(This));
486 if(aString==NULL)
return false;
488 G4long value = strtol(aString,&s,10);
489 if(s==aString)
return false;
493#include <X11/IntrinsicP.h>
495void ExecuteChangeSizeFunction (
501 if(aWidget==NULL)
return;
502 if(aWidget->core.widget_class->core_class.resize==NULL)
return;
503 (aWidget->core.widget_class->core_class.resize)(aWidget);
void AddMenu(const char *, const char *)
G4String GetCommand(Widget)
virtual void PauseSessionStart(const G4String &)
virtual G4int ReceiveG4cout(const G4String &)
virtual G4int ReceiveG4cerr(const G4String &)
G4UIsession * SessionStart()
void AddButton(const char *, const char *, const char *)
void SetCoutDestination(G4UIsession *const value)
static G4UImanager * GetUIpointer()
void SetSession(G4UIsession *const value)
G4String Complete(const G4String &)
void ApplyShellCommand(const G4String &, G4bool &, G4bool &)
void AddInteractor(G4String, G4Interactor)
G4Interactor GetInteractor(G4String)
void EnableSecondaryLoop()
G4Interactor GetMainInteractor()
void DisableSecondaryLoop()
void DispatchEvent(void *)
static G4Xt * getInstance()