34#include <X11/Intrinsic.h>
39#define NewString(str) \
40 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
46G4Xt* G4Xt::instance = NULL;
48static G4bool XtInited =
false;
50static char** args = NULL;
51static XtAppContext appContext = NULL;
52static Widget topWidget = NULL;
65 if (instance == NULL) {
66 instance =
new G4Xt(a_argn, a_args, a_class);
71G4Xt::G4Xt(
int a_argn,
char** a_args,
char* a_class)
75 if (XtInited ==
false) {
77 args = (
char**)malloc(a_argn *
sizeof(
char*));
80 for (
int argi = 0; argi < a_argn; argi++) {
81 args[argi] = (
char*)
NewString(a_args[argi]);
85#if XtSpecificationRelease == 4
87 narg = (Cardinal)a_argn;
93 XtSetArg(xargs[0], XtNgeometry,
"100x100");
95 XtAppInitialize(&appContext, a_class, NULL, (Cardinal)0, &narg, a_args, NULL, xargs, 1);
96 if (topWidget == NULL) {
100 if ((a_argn != 0) && (args != NULL)) {
101 for (
int argi = 0; argi < a_argn; argi++) {
102 if (args[argi] != NULL)
103 strcpy(a_args[argi], args[argi]);
109 XtSetMappedWhenManaged(topWidget, False);
110 XtRealizeWidget(topWidget);
124 if (
this == instance) {
141 if (appContext == NULL)
return NULL;
142 if (topWidget == NULL)
return NULL;
143 XtAppNextEvent(appContext, &event);
151 if (topWidget == NULL)
return;
152 if (a_string == NULL)
return;
153 Display* dpy = XtDisplay(topWidget);
154 XrmDatabase dbres = XrmGetStringDatabase(a_string);
155 if (dbres == NULL)
return;
156 XrmDatabase database = XrmGetDatabase(dpy);
157 if (database != NULL) {
158 XrmMergeDatabases(dbres, &database);
161 XrmSetDatabase(dpy, dbres);
169 if (topWidget == NULL)
return;
170 XSync(XtDisplay(topWidget), False);
G4GLOB_DLL std::ostream G4cout
void AddDispatcher(G4DispatchFunction)
void SetMainInteractor(G4Interactor)
void SetArguments(int, char **)
static G4Xt * getInstance()
void FlushAndWaitExecution()
void PutStringInResourceDatabase(char *)
static bool xt_dispatch_event(void *a_event)