00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #if defined(G4INTY_BUILD_XT) || defined(G4INTY_USE_XT)
00033
00034 #include <stdlib.h>
00035 #include <string.h>
00036
00037 #include <X11/Intrinsic.h>
00038 #include <X11/Shell.h>
00039
00040 #include "G4ios.hh"
00041
00042 #include "G4Xt.hh"
00043
00044 #define NewString(str) \
00045 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
00046
00047
00048
00049
00050
00051 G4Xt* G4Xt::instance = NULL;
00052
00053 static G4bool XtInited = FALSE;
00054 static int argn = 0;
00055 static char** args = NULL;
00056 static XtAppContext appContext = NULL;
00057 static Widget topWidget = NULL;
00058
00059 G4Xt* G4Xt::getInstance (
00060 )
00061
00063 {
00064 return G4Xt::getInstance (0,NULL,(char*)"Geant4");
00065 }
00066
00067 G4Xt* G4Xt::getInstance (
00068 int a_argn
00069 ,char** a_args
00070 ,char* a_class
00071 )
00072
00074 {
00075 if (instance==NULL) {
00076 instance = new G4Xt(a_argn,a_args,a_class);
00077 }
00078 return instance;
00079 }
00080
00081 G4Xt::G4Xt (
00082 int a_argn
00083 ,char** a_args
00084 ,char* a_class
00085 )
00086
00088 {
00089 if(XtInited==FALSE) {
00090 if(a_argn!=0) {
00091 args = (char**)malloc(a_argn * sizeof(char*));
00092 if(args!=NULL) {
00093 argn = a_argn;
00094 for(int argi=0;argi<a_argn;argi++) {
00095 args[argi] = (char*)NewString (a_args[argi]);
00096 }
00097 }
00098 }
00099 #if XtSpecificationRelease == 4
00100 Cardinal narg;
00101 narg = (Cardinal)a_argn;
00102 #else
00103 int narg;
00104 narg = a_argn;
00105 #endif
00106 Arg xargs[1];
00107 XtSetArg (xargs[0],XtNgeometry,"100x100");
00108 topWidget = XtAppInitialize (&appContext,a_class,
00109 NULL,(Cardinal)0,
00110 &narg,a_args,NULL,
00111 xargs,1);
00112 if(topWidget==NULL) {
00113 G4cout << "G4Xt : Unable to init Xt." << G4endl;
00114 }
00115
00116 if( (a_argn!=0) && (args!=NULL)) {
00117 for(int argi=0;argi<a_argn;argi++) {
00118 if(args[argi]!=NULL)
00119 strcpy(a_args[argi],args[argi]);
00120 else
00121 a_args[argi] = NULL;
00122 }
00123 }
00124
00125 XtSetMappedWhenManaged (topWidget,False);
00126 XtRealizeWidget (topWidget);
00127 XtInited = TRUE;
00128 }
00129 SetArguments (argn,args);
00130 SetMainInteractor (topWidget);
00131 AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
00132 }
00133
00134 G4Xt::~G4Xt (
00135 )
00136
00138 {
00139 if(this==instance) {
00140 instance = NULL;
00141 }
00142 }
00143
00144 G4bool G4Xt::Inited (
00145 )
00146
00148 {
00149 return XtInited;
00150 }
00151
00152 void* G4Xt::GetEvent (
00153 )
00154
00156 {
00157 static XEvent event;
00158 if(appContext==NULL) return NULL;
00159 if(topWidget==NULL) return NULL;
00160 XtAppNextEvent (appContext, &event);
00161 return &event;
00162 }
00163
00164 void G4Xt::PutStringInResourceDatabase (
00165 char* a_string
00166 )
00167
00169 {
00170 if(topWidget==NULL) return;
00171 if(a_string==NULL) return;
00172 Display* dpy = XtDisplay(topWidget);
00173 XrmDatabase dbres = XrmGetStringDatabase (a_string);
00174 if(dbres==NULL) return;
00175 XrmDatabase database = XrmGetDatabase (dpy);
00176 if(database!=NULL) {
00177 XrmMergeDatabases (dbres,&database);
00178 } else {
00179 XrmSetDatabase (dpy,dbres);
00180 }
00181 }
00182
00183 void G4Xt::FlushAndWaitExecution (
00184 )
00185
00187 {
00188 if(topWidget==NULL) return;
00189 XSync(XtDisplay(topWidget),False);
00190 }
00191
00192 #endif
00193
00194
00195