Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

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: G4Xt.cc,v 1.11 2006/06/29 19:10:28 gunter Exp $
00028 // GEANT4 tag $Name: geant4-08-01-patch-01 $
00029 //
00030 // G.Barrand
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 //static void XWidgetIconify                 (Widget);
00048 //static void XWidgetUniconify               (Widget);
00049 //static void XDisplaySetWindowToNormalState (Display*,Window);
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) {  //Xt should be Inited once !
00090     if(a_argn!=0) {  //Save args.
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     // Restore a_args. XtAppInitialize corrupts the given ones !!!
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     // If topWidget not realized, pbs with Inventor shells.
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 

Generated on Fri Jun 22 11:07:03 2007 by doxygen 1.3.4