Geant4 Cross Reference |
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 #include "G4Xt.hh" 31 32 #include "G4ios.hh" 33 34 #include <X11/Intrinsic.h> 35 #include <X11/Shell.h> 36 #include <stdlib.h> 37 #include <string.h> 38 39 #define NewString(str) \ 40 ((str) != NULL ? (strcpy((char*)malloc((unsi 41 42 // static void XWidgetIconify 43 // static void XWidgetUniconify 44 // static void XDisplaySetWindowToNormalState 45 46 G4Xt* G4Xt::instance = NULL; 47 48 static G4bool XtInited = false; 49 static int argn = 0; 50 static char** args = NULL; 51 static XtAppContext appContext = NULL; 52 static Widget topWidget = NULL; 53 /********************************************* 54 G4Xt* G4Xt::getInstance() 55 /********************************************* 56 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 57 { 58 return G4Xt::getInstance(0, NULL, (char*)"Ge 59 } 60 /********************************************* 61 G4Xt* G4Xt::getInstance(int a_argn, char** a_a 62 /********************************************* 63 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 64 { 65 if (instance == NULL) { 66 instance = new G4Xt(a_argn, a_args, a_clas 67 } 68 return instance; 69 } 70 /********************************************* 71 G4Xt::G4Xt(int a_argn, char** a_args, char* a_ 72 /********************************************* 73 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 74 { 75 if (XtInited == false) { // Xt should be In 76 if (a_argn != 0) { // Save args. 77 args = (char**)malloc(a_argn * sizeof(ch 78 if (args != NULL) { 79 argn = a_argn; 80 for (int argi = 0; argi < a_argn; argi 81 args[argi] = (char*)NewString(a_args 82 } 83 } 84 } 85 #if XtSpecificationRelease == 4 86 Cardinal narg; 87 narg = (Cardinal)a_argn; 88 #else 89 int narg; 90 narg = a_argn; 91 #endif 92 Arg xargs[1]; 93 XtSetArg(xargs[0], XtNgeometry, "100x100") 94 topWidget = 95 XtAppInitialize(&appContext, a_class, NU 96 if (topWidget == NULL) { 97 G4cout << "G4Xt : Unable to init Xt." << 98 } 99 // Restore a_args. XtAppInitialize corrupt 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]); 104 else 105 a_args[argi] = NULL; 106 } 107 } 108 // If topWidget not realized, pbs with Inv 109 XtSetMappedWhenManaged(topWidget, False); 110 XtRealizeWidget(topWidget); 111 XtInited = true; 112 } 113 SetArguments(argn, args); 114 SetMainInteractor(topWidget); 115 AddDispatcher(xt_dispatch_event); 116 // Coverity gcc8 cast warning 117 // AddDispatcher ((G4DispatchFunction)X 118 } 119 /********************************************* 120 G4Xt::~G4Xt() 121 /********************************************* 122 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 123 { 124 if (this == instance) { 125 instance = NULL; 126 } 127 } 128 /********************************************* 129 G4bool G4Xt::Inited() 130 /********************************************* 131 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 132 { 133 return XtInited; 134 } 135 /********************************************* 136 void* G4Xt::GetEvent() 137 /********************************************* 138 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 139 { 140 static XEvent event; 141 if (appContext == NULL) return NULL; 142 if (topWidget == NULL) return NULL; 143 XtAppNextEvent(appContext, &event); 144 return &event; 145 } 146 /********************************************* 147 void G4Xt::PutStringInResourceDatabase(char* a 148 /********************************************* 149 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 150 { 151 if (topWidget == NULL) return; 152 if (a_string == NULL) return; 153 Display* dpy = XtDisplay(topWidget); 154 XrmDatabase dbres = XrmGetStringDatabase(a_s 155 if (dbres == NULL) return; 156 XrmDatabase database = XrmGetDatabase(dpy); 157 if (database != NULL) { 158 XrmMergeDatabases(dbres, &database); 159 } 160 else { 161 XrmSetDatabase(dpy, dbres); 162 } 163 } 164 /********************************************* 165 void G4Xt::FlushAndWaitExecution() 166 /********************************************* 167 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 168 { 169 if (topWidget == NULL) return; 170 XSync(XtDisplay(topWidget), False); 171 } 172