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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 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((unsigned)strlen(str) + 1), str)) : NULL)
 41 
 42 // static void XWidgetIconify                 (Widget);
 43 // static void XWidgetUniconify               (Widget);
 44 // static void XDisplaySetWindowToNormalState (Display*,Window);
 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*)"Geant4");
 59 }
 60 /***************************************************************************/
 61 G4Xt* G4Xt::getInstance(int a_argn, char** a_args, char* a_class)
 62 /***************************************************************************/
 63 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
 64 {
 65   if (instance == NULL) {
 66     instance = new G4Xt(a_argn, a_args, a_class);
 67   }
 68   return instance;
 69 }
 70 /***************************************************************************/
 71 G4Xt::G4Xt(int a_argn, char** a_args, char* a_class)
 72 /***************************************************************************/
 73 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
 74 {
 75   if (XtInited == false) {  // Xt should be Inited once !
 76     if (a_argn != 0) {  // Save args.
 77       args = (char**)malloc(a_argn * sizeof(char*));
 78       if (args != NULL) {
 79         argn = a_argn;
 80         for (int argi = 0; argi < a_argn; argi++) {
 81           args[argi] = (char*)NewString(a_args[argi]);
 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, NULL, (Cardinal)0, &narg, a_args, NULL, xargs, 1);
 96     if (topWidget == NULL) {
 97       G4cout << "G4Xt : Unable to init Xt." << G4endl;
 98     }
 99     // Restore a_args. XtAppInitialize corrupts the given ones !!!
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 Inventor shells.
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)XtDispatchEvent);
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_string)
148 /***************************************************************************/
149 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
150 {
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);
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