G4Xt.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // G.Barrand
00030 
00031 #if defined(G4INTY_BUILD_XT) || defined(G4INTY_USE_XT)
00032 
00033 #include <stdlib.h>
00034 #include <string.h>
00035 
00036 #include <X11/Intrinsic.h>
00037 #include <X11/Shell.h>
00038 
00039 #include "G4ios.hh"
00040 
00041 #include "G4Xt.hh"
00042 
00043 #define NewString(str)  \
00044  ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
00045 
00046 //static void XWidgetIconify                 (Widget);
00047 //static void XWidgetUniconify               (Widget);
00048 //static void XDisplaySetWindowToNormalState (Display*,Window);
00049 
00050 G4Xt* G4Xt::instance    = NULL;
00051 
00052 static G4bool XtInited  = FALSE;
00053 static int    argn      = 0;
00054 static char** args      = NULL;
00055 static XtAppContext appContext = NULL;
00056 static Widget topWidget = NULL;
00057 /***************************************************************************/
00058 G4Xt* G4Xt::getInstance (
00059 ) 
00060 /***************************************************************************/
00062 {
00063   return G4Xt::getInstance (0,NULL,(char*)"Geant4");
00064 }
00065 /***************************************************************************/
00066 G4Xt* G4Xt::getInstance (
00067  int    a_argn
00068 ,char** a_args
00069 ,char*  a_class
00070 ) 
00071 /***************************************************************************/
00073 {
00074   if (instance==NULL) {
00075     instance = new G4Xt(a_argn,a_args,a_class);
00076   }
00077   return instance;
00078 }
00079 /***************************************************************************/
00080 G4Xt::G4Xt (
00081  int    a_argn
00082 ,char** a_args
00083 ,char*  a_class
00084 )
00085 /***************************************************************************/
00087 {
00088   if(XtInited==FALSE) {  //Xt should be Inited once !
00089     if(a_argn!=0) {  //Save args.
00090       args = (char**)malloc(a_argn * sizeof(char*));
00091       if(args!=NULL) {
00092         argn = a_argn;
00093         for(int argi=0;argi<a_argn;argi++) {
00094           args[argi] = (char*)NewString (a_args[argi]);
00095         }
00096       }
00097     }
00098 #if XtSpecificationRelease == 4
00099     Cardinal     narg;
00100     narg         = (Cardinal)a_argn;
00101 #else
00102     int          narg;
00103     narg         = a_argn;
00104 #endif
00105     Arg          xargs[1];
00106     XtSetArg     (xargs[0],XtNgeometry,"100x100"); 
00107     topWidget    = XtAppInitialize (&appContext,a_class,
00108                                     NULL,(Cardinal)0,
00109                                     &narg,a_args,NULL,
00110                                     xargs,1);
00111     if(topWidget==NULL) {
00112       G4cout        << "G4Xt : Unable to init Xt." << G4endl;
00113     }
00114     // Restore a_args. XtAppInitialize corrupts the given ones !!!
00115     if( (a_argn!=0) && (args!=NULL)) {
00116       for(int argi=0;argi<a_argn;argi++) {
00117         if(args[argi]!=NULL)
00118           strcpy(a_args[argi],args[argi]);
00119         else
00120           a_args[argi] = NULL;
00121       }
00122     }
00123     // If topWidget not realized, pbs with Inventor shells.
00124     XtSetMappedWhenManaged (topWidget,False);
00125     XtRealizeWidget (topWidget);
00126     XtInited = TRUE;
00127   }
00128   SetArguments      (argn,args);
00129   SetMainInteractor (topWidget);
00130   AddDispatcher     ((G4DispatchFunction)XtDispatchEvent);
00131 }
00132 /***************************************************************************/
00133 G4Xt::~G4Xt (
00134 ) 
00135 /***************************************************************************/
00137 {
00138   if(this==instance) {
00139     instance = NULL;
00140   }
00141 }
00142 /***************************************************************************/
00143 G4bool G4Xt::Inited (
00144 )
00145 /***************************************************************************/
00147 {
00148   return XtInited;
00149 }
00150 /***************************************************************************/
00151 void* G4Xt::GetEvent (
00152 ) 
00153 /***************************************************************************/
00155 {
00156   static XEvent  event;
00157   if(appContext==NULL) return NULL;
00158   if(topWidget==NULL) return NULL;
00159   XtAppNextEvent (appContext, &event);
00160   return         &event;
00161 }
00162 /***************************************************************************/
00163 void G4Xt::PutStringInResourceDatabase (
00164  char* a_string 
00165 )
00166 /***************************************************************************/
00168 {
00169   if(topWidget==NULL)  return;
00170   if(a_string==NULL)   return;
00171   Display*             dpy   = XtDisplay(topWidget);
00172   XrmDatabase          dbres = XrmGetStringDatabase (a_string);
00173   if(dbres==NULL)      return;
00174   XrmDatabase          database = XrmGetDatabase (dpy);
00175   if(database!=NULL)  {
00176     XrmMergeDatabases  (dbres,&database);
00177   } else {
00178     XrmSetDatabase     (dpy,dbres);
00179   }
00180 }
00181 /***************************************************************************/
00182 void G4Xt::FlushAndWaitExecution (
00183 )
00184 /***************************************************************************/
00186 {
00187   if(topWidget==NULL) return;
00188   XSync(XtDisplay(topWidget),False);
00189 }
00190 
00191 #endif
00192 
00193 
00194 

Generated on Mon May 27 17:50:27 2013 for Geant4 by  doxygen 1.4.7