Import Geant4 11.2.0.beta source tree
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// L. Garnier
|
||||
|
||||
#include "G4Qt.hh"
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef G4VIS_USE_VTK_QT
|
||||
# include "QVTKOpenGLNativeWidget.h"
|
||||
# include <qsurfaceformat.h>
|
||||
#endif
|
||||
|
||||
G4Qt* G4Qt::instance = nullptr;
|
||||
|
||||
static G4bool QtInited = false;
|
||||
|
||||
/***************************************************************************/
|
||||
G4Qt* G4Qt::getInstance()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return G4Qt::getInstance(0, nullptr, (char*)"Geant4");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Qt* G4Qt::getInstance(int a_argn, char** a_args, char* a_class)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (instance == nullptr) {
|
||||
instance = new G4Qt(a_argn, a_args, a_class);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Qt::G4Qt(int a_argn, char** a_args, char* /*a_class */
|
||||
)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
argn = 0;
|
||||
args = nullptr;
|
||||
externalApp = false;
|
||||
|
||||
// Check if Qt already init in another external app
|
||||
if (qApp) {
|
||||
externalApp = true;
|
||||
QtInited = true;
|
||||
SetMainInteractor(qApp);
|
||||
SetArguments(a_argn, a_args);
|
||||
}
|
||||
else {
|
||||
if (! QtInited) { // Qt should be Inited once !
|
||||
// Then two cases :
|
||||
// - It is the first time we create G4UI (argc!=0)
|
||||
// -> Inited and register
|
||||
// - It is the first time we create G4VIS (argc == 0)
|
||||
// -> Inited and NOT register
|
||||
|
||||
if (a_argn != 0) {
|
||||
argn = a_argn;
|
||||
args = a_args;
|
||||
}
|
||||
else { // argc = 0
|
||||
|
||||
// FIXME : That's not the good arguments, but I don't know how to get args from other
|
||||
// Interactor. Ex: How to get them from G4Xt ?
|
||||
argn = 1;
|
||||
args = (char**)malloc(1 * sizeof(char*));
|
||||
args[0] = (char*)malloc(10 * sizeof(char));
|
||||
strncpy(args[0], "my_app \0", 9);
|
||||
}
|
||||
|
||||
int* p_argn = (int*)malloc(sizeof(int));
|
||||
*p_argn = argn;
|
||||
#ifdef WIN32
|
||||
qApp->setAttribute(Qt::AA_UseDesktopOpenGL);
|
||||
#endif
|
||||
|
||||
#ifdef G4VIS_USE_VTK_QT
|
||||
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
|
||||
#endif
|
||||
new QApplication(*p_argn, args);
|
||||
if (! qApp) {
|
||||
G4UImanager* UImanager = G4UImanager::GetUIpointer();
|
||||
G4int verbose = UImanager->GetVerboseLevel();
|
||||
if (verbose >= 2) {
|
||||
G4cout << "G4Qt : Unable to init Qt." << G4endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
QtInited = true;
|
||||
if (a_argn != 0) {
|
||||
SetMainInteractor(qApp);
|
||||
}
|
||||
SetArguments(a_argn, a_args);
|
||||
}
|
||||
}
|
||||
}
|
||||
// AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
|
||||
|
||||
/*
|
||||
* On some non-English locale, comma is used for the decimal separator instead of dot
|
||||
* bringing to weird behavior of strtod (string to double) function in user application.
|
||||
* This is "by design" from Qt, see https://bugreports.qt-project.org/browse/QTBUG-10994
|
||||
*
|
||||
* $ LC_NUMERIC=fr_FR.UTF-8 ./qtstrtod
|
||||
* strtod(0.1) = 0
|
||||
* $ LC_NUMERIC=C ./qtstrtod
|
||||
* strtod(0.1) = 0.1
|
||||
*
|
||||
* Jerome Suhard, jerome@suhard.fr
|
||||
*/
|
||||
|
||||
// explicitly set the LC_NUMBERIC locale to "C"
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Qt::~G4Qt()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (this == instance) {
|
||||
instance = nullptr;
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Qt::Inited()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return QtInited;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void* G4Qt::GetEvent()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Qt::FlushAndWaitExecution()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (! qApp) return;
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
bool G4Qt::IsExternalApp()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return externalApp;
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
|
||||
#include "G4UIExecutive.hh"
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIsession.hh"
|
||||
|
||||
#if defined(G4UI_BUILD_QT_SESSION)
|
||||
# include "G4Qt.hh"
|
||||
# include "G4UIQt.hh"
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_XM_SESSION)
|
||||
# include "G4UIXm.hh"
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_WIN32_SESSION)
|
||||
# include "G4UIWin32.hh"
|
||||
#endif
|
||||
|
||||
#include "G4TiMemory.hh"
|
||||
#include "G4UIcsh.hh"
|
||||
#include "G4UItcsh.hh"
|
||||
#include "G4UIterminal.hh"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// build flags as variables
|
||||
|
||||
#if defined(G4UI_BUILD_QT_SESSION)
|
||||
static const G4bool qt_build = true;
|
||||
#else
|
||||
static const G4bool qt_build = false;
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_XM_SESSION)
|
||||
static const G4bool xm_build = true;
|
||||
#else
|
||||
static const G4bool xm_build = false;
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_WIN32_SESSION)
|
||||
static const G4bool win32_build = true;
|
||||
#else
|
||||
static const G4bool win32_build = false;
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
static const G4bool tcsh_build = true;
|
||||
#else
|
||||
static const G4bool tcsh_build = false;
|
||||
#endif
|
||||
|
||||
#define DISCARD_PARAMETER(p) (void)p
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
G4UIExecutive::G4UIExecutive(G4int argc, char** argv, const G4String& type)
|
||||
: selected(kNone), session(nullptr), shell(nullptr), isGUI(false), verbose(true)
|
||||
{
|
||||
if (verbose) {
|
||||
G4cout << "Available UI session types: [ ";
|
||||
if (qt_build) G4cout << "Qt, ";
|
||||
if (xm_build) G4cout << "Xm, ";
|
||||
if (win32_build) G4cout << "Win32, ";
|
||||
if (tcsh_build) G4cout << "tcsh, ";
|
||||
G4cout << "csh ]" << G4endl;
|
||||
}
|
||||
|
||||
// selecting session type...
|
||||
// 1st priority : in case argumant specified
|
||||
G4String stype = G4StrUtil::to_lower_copy(type); // session type is case-insensitive.
|
||||
if (! type.empty()) SelectSessionByArg(stype);
|
||||
|
||||
// 2nd priority : refer environment variables (as backword compatibility)
|
||||
if (selected == kNone) SelectSessionByEnv();
|
||||
|
||||
// 3rd priority : refer $HOME/.g4session
|
||||
if (selected == kNone) {
|
||||
G4String appinput = argv[0];
|
||||
G4String appname = "";
|
||||
size_t islash = appinput.find_last_of("/\\");
|
||||
if (islash == G4String::npos)
|
||||
appname = appinput;
|
||||
else
|
||||
appname = appinput.substr(islash + 1, appinput.size() - islash - 1);
|
||||
|
||||
SelectSessionByFile(appname);
|
||||
}
|
||||
|
||||
// 4th, best guess of session type
|
||||
if (selected == kNone) SelectSessionByBestGuess();
|
||||
|
||||
// instantiate a session...
|
||||
switch (selected) {
|
||||
case kQt:
|
||||
#if defined(G4UI_BUILD_QT_SESSION)
|
||||
session = new G4UIQt(argc, argv);
|
||||
isGUI = true;
|
||||
#endif
|
||||
break;
|
||||
case kXm:
|
||||
#if defined(G4UI_BUILD_XM_SESSION)
|
||||
session = new G4UIXm(argc, argv);
|
||||
isGUI = true;
|
||||
#endif
|
||||
break;
|
||||
case kWin32:
|
||||
#if defined(G4UI_BUILD_WIN32_SESSION)
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
session = new G4UIWin32();
|
||||
isGUI = true;
|
||||
#endif
|
||||
break;
|
||||
case kTcsh:
|
||||
#if ! (defined(WIN32) || defined(__MINGW32__))
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
shell = new G4UItcsh;
|
||||
session = new G4UIterminal(shell);
|
||||
#endif
|
||||
break;
|
||||
case kCsh:
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
shell = new G4UIcsh;
|
||||
session = new G4UIterminal(shell);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// fallback (csh)
|
||||
if (session == nullptr) {
|
||||
G4Exception("G4UIExecutive::G4UIExecutive()", "UI0002", JustWarning,
|
||||
"Specified session type is not build in your system,\n"
|
||||
"or no session type is specified.\n"
|
||||
"A fallback session type is used.");
|
||||
|
||||
selected = kCsh;
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
shell = new G4UIcsh;
|
||||
session = new G4UIterminal(shell);
|
||||
}
|
||||
|
||||
TIMEMORY_INIT(argc, argv);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
G4UIExecutive::~G4UIExecutive() { delete session; }
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByArg(const G4String& stype)
|
||||
{
|
||||
if (qt_build && stype == "qt")
|
||||
selected = kQt;
|
||||
else if (xm_build && stype == "xm")
|
||||
selected = kXm;
|
||||
else if (win32_build && stype == "win32")
|
||||
selected = kWin32;
|
||||
else if (tcsh_build && stype == "tcsh")
|
||||
selected = kTcsh;
|
||||
else if (stype == "csh")
|
||||
selected = kCsh;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByEnv()
|
||||
{
|
||||
if (qt_build && (std::getenv("G4UI_USE_QT") != nullptr))
|
||||
selected = kQt;
|
||||
else if (xm_build && (std::getenv("G4UI_USE_XM") != nullptr))
|
||||
selected = kXm;
|
||||
else if (win32_build && (std::getenv("G4UI_USE_WIN32") != nullptr))
|
||||
selected = kWin32;
|
||||
else if (tcsh_build && (std::getenv("G4UI_USE_TCSH") != nullptr))
|
||||
selected = kTcsh;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByFile(const G4String& appname)
|
||||
{
|
||||
const char* path = std::getenv("HOME");
|
||||
if (path == nullptr) return;
|
||||
G4String homedir = path;
|
||||
|
||||
#ifndef WIN32
|
||||
G4String fname = homedir + "/.g4session";
|
||||
#else
|
||||
G4String fname = homedir + "\\.g4session";
|
||||
#endif
|
||||
|
||||
std::ifstream fsession;
|
||||
enum
|
||||
{
|
||||
BUFSIZE = 1024
|
||||
};
|
||||
char linebuf[BUFSIZE];
|
||||
|
||||
fsession.open(fname, std::ios::in);
|
||||
|
||||
G4String default_session = "";
|
||||
G4int iline = 1;
|
||||
sessionMap.clear();
|
||||
while (fsession.good()) {
|
||||
if (fsession.eof()) break;
|
||||
fsession.getline(linebuf, BUFSIZE);
|
||||
G4String aline = G4StrUtil::strip_copy(linebuf);
|
||||
if (aline[0] == '#') continue;
|
||||
if (aline.empty()) continue;
|
||||
if (iline == 1)
|
||||
default_session = aline;
|
||||
else {
|
||||
size_t idx = aline.find_first_of(' ');
|
||||
if (idx == G4String::npos) break;
|
||||
G4String aname = aline.substr(0, idx);
|
||||
idx = aline.find_first_not_of(' ', idx);
|
||||
if (idx == G4String::npos) break;
|
||||
G4String sname = aline.substr(idx, aline.size() - idx);
|
||||
sessionMap[aname] = sname;
|
||||
}
|
||||
iline++;
|
||||
}
|
||||
fsession.close();
|
||||
|
||||
G4String stype = "";
|
||||
auto it = sessionMap.find(appname);
|
||||
if (it != sessionMap.end())
|
||||
stype = sessionMap[appname];
|
||||
else
|
||||
stype = default_session;
|
||||
G4StrUtil::to_lower(stype);
|
||||
|
||||
// select session...
|
||||
if (qt_build && stype == "qt")
|
||||
selected = kQt;
|
||||
else if (xm_build && stype == "xm")
|
||||
selected = kXm;
|
||||
else if (win32_build && stype == "win32")
|
||||
selected = kWin32;
|
||||
else if (tcsh_build && stype == "tcsh")
|
||||
selected = kTcsh;
|
||||
else if (stype == "csh")
|
||||
selected = kCsh;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByBestGuess()
|
||||
{
|
||||
if (qt_build)
|
||||
selected = kQt;
|
||||
else if (win32_build)
|
||||
selected = kWin32;
|
||||
else if (tcsh_build)
|
||||
selected = kTcsh;
|
||||
else if (xm_build)
|
||||
selected = kXm;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SetPrompt(const G4String& prompt)
|
||||
{
|
||||
if (shell != nullptr) shell->SetPrompt(prompt);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
|
||||
{
|
||||
if (shell != nullptr) shell->SetLsColor(dirColor, cmdColor);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SessionStart() { session->SessionStart(); }
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,441 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// G.Barrand
|
||||
|
||||
// #define DEBUG
|
||||
|
||||
#include "G4UIXm.hh"
|
||||
|
||||
#include "G4StateManager.hh"
|
||||
#include "G4Types.hh"
|
||||
#include "G4UIcommandStatus.hh"
|
||||
#include "G4UIcommandTree.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4Xt.hh"
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/Shell.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <Xm/CascadeB.h>
|
||||
#include <Xm/Command.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/RowColumn.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void XmTextAppendString(Widget, char*);
|
||||
|
||||
static void clearButtonCallback(Widget, XtPointer, XtPointer);
|
||||
|
||||
static char* XmConvertCompoundStringToString(XmString, G4int);
|
||||
static G4bool ConvertStringToInt(const char*, G4int&);
|
||||
static void ExecuteChangeSizeFunction(Widget);
|
||||
|
||||
static G4bool exitSession = true;
|
||||
static G4bool exitPause = true;
|
||||
static G4bool exitHelp = true;
|
||||
/***************************************************************************/
|
||||
G4UIXm::G4UIXm(G4int argc, char** argv)
|
||||
: shell(NULL), command(NULL), menuBar(NULL), text(NULL), fHelp(false), fHelpChoice(0)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UImanager* UI = G4UImanager::GetUIpointer();
|
||||
if (UI != NULL) UI->SetSession(this);
|
||||
|
||||
G4Xt* interactorManager = G4Xt::getInstance(argc, argv, (char*)"Xm");
|
||||
|
||||
Widget top = (Widget)interactorManager->GetMainInteractor();
|
||||
|
||||
if (std::getenv("XENVIRONMENT") == NULL) {
|
||||
XrmDatabase database = XrmGetDatabase(XtDisplay(top));
|
||||
if (database != NULL) {
|
||||
XrmPutLineResource(&database, "*topShadowColor:white");
|
||||
XrmPutLineResource(&database, "*bottomShadowColor:black");
|
||||
XrmPutLineResource(&database, "*foreground:black");
|
||||
XrmPutLineResource(&database, "*background:lightgrey");
|
||||
XrmPutLineResource(&database, "*borderColor:lightgrey");
|
||||
XrmPutLineResource(&database, "*fontList:-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1");
|
||||
XrmPutLineResource(&database, "*text.background:white");
|
||||
XrmPutLineResource(&database, "*text.fontList:*courier*-r-*--14-*");
|
||||
XrmPutLineResource(&database, "*text.maxLength:8000");
|
||||
}
|
||||
}
|
||||
|
||||
Arg args[9];
|
||||
XtSetArg(args[0], XmNkeyboardFocusPolicy, XmPOINTER); // For completion.
|
||||
shell = XtAppCreateShell("G4UIXm", "G4UIXm", topLevelShellWidgetClass, XtDisplay(top), args, 1);
|
||||
form = XmCreateForm(shell, (char*)menu_str[0].c_str(), NULL, 0);
|
||||
XtManageChild(form);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
|
||||
menuBar = XmCreateMenuBar(form, (char*)menu_str[1].c_str(), args, 3);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_NONE);
|
||||
XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
|
||||
command = XmCreateCommand(form, (char*)menu_str[2].c_str(), args, 4);
|
||||
XtManageChild(command);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_NONE);
|
||||
XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[3], XmNbottomAttachment, XmATTACH_WIDGET);
|
||||
XtSetArg(args[4], XmNbottomWidget, command);
|
||||
XmString cps = XmStringLtoRCreate((char*)menu_str[3].c_str(), (char*)XmSTRING_DEFAULT_CHARSET);
|
||||
XtSetArg(args[5], XmNlabelString, cps);
|
||||
Widget clearButton = XmCreatePushButton(form, (char*)menu_str[4].c_str(), args, 6);
|
||||
XmStringFree(cps);
|
||||
XtManageChild(clearButton);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
|
||||
XtSetArg(args[1], XmNtopWidget, menuBar);
|
||||
XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[4], XmNbottomAttachment, XmATTACH_WIDGET);
|
||||
XtSetArg(args[5], XmNbottomWidget, clearButton);
|
||||
XtSetArg(args[6], XmNeditMode, XmMULTI_LINE_EDIT);
|
||||
XtSetArg(args[7], XmNrows, 12);
|
||||
XtSetArg(args[8], XmNcolumns, 80);
|
||||
text = XmCreateScrolledText(form, (char*)menu_str[5].c_str(), args, 9);
|
||||
XtManageChild(text);
|
||||
|
||||
XtAddCallback(clearButton, XmNactivateCallback, clearButtonCallback, (XtPointer)text);
|
||||
XtAddCallback(command, XmNcommandEnteredCallback, CommandEnteredCallback, (XtPointer)this);
|
||||
|
||||
Widget commandText = XmCommandGetChild(command, XmDIALOG_COMMAND_TEXT);
|
||||
XtAddEventHandler(commandText, KeyPressMask, False, keyHandler, (XtPointer)this);
|
||||
|
||||
XtRealizeWidget(shell);
|
||||
XtMapWidget(shell);
|
||||
|
||||
if (UI != NULL) UI->SetCoutDestination(this);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4UIXm::~G4UIXm()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UImanager* UI = G4UImanager::GetUIpointer();
|
||||
if (UI != NULL) {
|
||||
UI->SetSession(NULL);
|
||||
UI->SetCoutDestination(NULL);
|
||||
}
|
||||
XtDestroyWidget(shell);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4UIsession* G4UIXm::SessionStart()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4Xt* interactorManager = G4Xt::getInstance();
|
||||
Prompt("session");
|
||||
exitSession = false;
|
||||
interactorManager->DisableSecondaryLoop();
|
||||
void* event;
|
||||
while ((event = interactorManager->GetEvent()) != NULL) {
|
||||
interactorManager->DispatchEvent(event);
|
||||
if (exitSession == true) break;
|
||||
}
|
||||
interactorManager->EnableSecondaryLoop();
|
||||
return this;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::Prompt(G4String aPrompt)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
Arg args[1];
|
||||
char* str = (char*)XtNewString(aPrompt.data());
|
||||
XmString cps = XmStringLtoRCreate(str, (char*)XmSTRING_DEFAULT_CHARSET);
|
||||
XtFree(str);
|
||||
XtSetArg(args[0], XmNpromptString, cps);
|
||||
XtSetValues(command, args, 1);
|
||||
XmStringFree(cps);
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::SessionTerminate()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::PauseSessionStart(const G4String& a_state)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (a_state == "G4_pause> ") {
|
||||
SecondaryLoop("Pause, type continue to exit this state");
|
||||
}
|
||||
|
||||
if (a_state == "EndOfEvent") {
|
||||
// Picking with feed back in event data Done here !!!
|
||||
SecondaryLoop("End of event, type continue to exit this state");
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::SecondaryLoop(G4String a_prompt)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4Xt* interactorManager = G4Xt::getInstance();
|
||||
Prompt(a_prompt);
|
||||
exitPause = false;
|
||||
void* event;
|
||||
while ((event = interactorManager->GetEvent()) != NULL) {
|
||||
interactorManager->DispatchEvent(event);
|
||||
if (exitPause == true) break;
|
||||
}
|
||||
Prompt("session");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4int G4UIXm::ReceiveG4debug(const G4String& a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
XmTextAppendString(text, (char*)a_string.data());
|
||||
return 0;
|
||||
} /***************************************************************************/
|
||||
G4int G4UIXm::ReceiveG4cout(const G4String& a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
XmTextAppendString(text, (char*)a_string.data());
|
||||
return 0;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4int G4UIXm::ReceiveG4cerr(const G4String& a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
XmTextAppendString(text, (char*)a_string.data());
|
||||
return 0;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4UIXm::GetHelpChoice(G4int& aInt)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
fHelp = true;
|
||||
// SecondaryLoop :
|
||||
G4Xt* interactorManager = G4Xt::getInstance();
|
||||
Prompt("Help");
|
||||
exitHelp = false;
|
||||
void* event;
|
||||
while ((event = interactorManager->GetEvent()) != NULL) {
|
||||
interactorManager->DispatchEvent(event);
|
||||
if (exitHelp == true) break;
|
||||
}
|
||||
Prompt("session");
|
||||
//
|
||||
if (fHelp == false) return false;
|
||||
aInt = fHelpChoice;
|
||||
fHelp = false;
|
||||
return true;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::ExitHelp() const
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::AddMenu(const char* a_name, const char* a_label)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (menuBar == NULL) return;
|
||||
if (a_name == NULL) return;
|
||||
if (a_label == NULL) return;
|
||||
XtManageChild(menuBar);
|
||||
// Pulldown menu :
|
||||
Widget widget;
|
||||
widget = XmCreatePulldownMenu(menuBar, (char*)a_name, NULL, 0);
|
||||
AddInteractor(a_name, (G4Interactor)widget);
|
||||
// Cascade button :
|
||||
Arg args[2];
|
||||
XmString cps = XmStringLtoRCreate((char*)a_label, (char*)XmSTRING_DEFAULT_CHARSET);
|
||||
XtSetArg(args[0], XmNlabelString, cps);
|
||||
XtSetArg(args[1], XmNsubMenuId, widget);
|
||||
widget = XmCreateCascadeButton(menuBar, (char*)a_name, args, 2);
|
||||
XmStringFree(cps);
|
||||
XtManageChild(widget);
|
||||
ExecuteChangeSizeFunction(form);
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::AddButton(const char* a_menu, const char* a_label, const char* a_command)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (a_menu == NULL) return;
|
||||
if (a_label == NULL) return;
|
||||
if (a_command == NULL) return;
|
||||
Widget parent = (Widget)GetInteractor(a_menu);
|
||||
if (parent == NULL) return;
|
||||
Widget widget = XmCreatePushButton(parent, (char*)a_label, NULL, 0);
|
||||
XtManageChild(widget);
|
||||
XtAddCallback(widget, XmNactivateCallback, ButtonCallback, (XtPointer)this);
|
||||
commands[widget] = a_command;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4String G4UIXm::GetCommand(Widget a_widget)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return commands[a_widget];
|
||||
}
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
void G4UIXm::CommandEnteredCallback(Widget, XtPointer a_tag, XtPointer a_data)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UIXm* This = (G4UIXm*)a_tag;
|
||||
|
||||
XmString cps = ((XmCommandCallbackStruct*)a_data)->value;
|
||||
char* ss = XmConvertCompoundStringToString(cps, 0);
|
||||
G4String scommand(ss);
|
||||
XtFree(ss);
|
||||
|
||||
if (This->fHelp == true) {
|
||||
exitHelp = true;
|
||||
This->fHelp = ConvertStringToInt(scommand.data(), This->fHelpChoice);
|
||||
}
|
||||
else {
|
||||
This->ApplyShellCommand(scommand, exitSession, exitPause);
|
||||
}
|
||||
|
||||
a_tag = NULL;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::keyHandler(Widget a_widget, XtPointer a_tag, XEvent* a_event, Boolean*)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
KeySym keySym;
|
||||
XLookupString(&(a_event->xkey), NULL, 0, &keySym, NULL);
|
||||
if (keySym != XK_Tab) return;
|
||||
G4UIXm* This = (G4UIXm*)a_tag;
|
||||
char* s = XmTextGetString(a_widget);
|
||||
G4String ss = This->Complete(s);
|
||||
XmTextSetString(a_widget, (char*)ss.data());
|
||||
XtFree(s);
|
||||
XmTextSetInsertionPosition(a_widget, XmTextGetLastPosition(a_widget));
|
||||
}
|
||||
/***************************************************************************/
|
||||
void clearButtonCallback(Widget, XtPointer a_tag, XtPointer)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
static const G4String empty_str = "";
|
||||
XmTextSetString((Widget)a_tag, (char*)empty_str.c_str());
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::ButtonCallback(Widget a_widget, XtPointer a_tag, XtPointer)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UIXm* This = (G4UIXm*)a_tag;
|
||||
if (This->fHelp == true) return; // Disabled when in help.
|
||||
G4String ss = This->GetCommand(a_widget);
|
||||
This->ApplyShellCommand(ss, exitSession, exitPause);
|
||||
}
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
char* XmConvertCompoundStringToString(XmString a_cps, G4int a_number)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (a_cps == NULL) return NULL;
|
||||
char* ss = NULL;
|
||||
XmStringContext context;
|
||||
XmStringInitContext(&context, a_cps);
|
||||
G4int icount = 0;
|
||||
Boolean Done = False;
|
||||
while (Done == False) {
|
||||
char* text = NULL;
|
||||
XmStringCharSet charset = NULL;
|
||||
XmStringDirection direct;
|
||||
Boolean sep;
|
||||
if (XmStringGetNextSegment(context, &text, &charset, &direct, &sep) == True) {
|
||||
XtFree(charset);
|
||||
if (sep == True) Done = True;
|
||||
if (icount == a_number) {
|
||||
ss = text;
|
||||
break;
|
||||
}
|
||||
icount++;
|
||||
XtFree(text);
|
||||
}
|
||||
else
|
||||
Done = True;
|
||||
}
|
||||
XmStringFreeContext(context);
|
||||
return ss;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void XmTextAppendString(Widget This, char* a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (This == NULL) return;
|
||||
if (! XtIsSubclass(This, xmTextWidgetClass)) return;
|
||||
if (a_string == NULL) return;
|
||||
XmTextPosition lastpos = XmTextGetLastPosition(This);
|
||||
XmTextReplace(This, lastpos, lastpos, a_string);
|
||||
XmTextSetInsertionPosition(This, XmTextGetLastPosition(This));
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
G4bool ConvertStringToInt(const char* aString, G4int& aInt)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
aInt = 0;
|
||||
if (aString == NULL) return false;
|
||||
char* s;
|
||||
G4long value = strtol(aString, &s, 10);
|
||||
if (s == aString) return false;
|
||||
aInt = (G4int)value;
|
||||
return true;
|
||||
}
|
||||
#include <X11/IntrinsicP.h>
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void ExecuteChangeSizeFunction(Widget aWidget)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if (aWidget == NULL) return;
|
||||
if (aWidget->core.widget_class->core_class.resize == NULL) return;
|
||||
(aWidget->core.widget_class->core_class.resize)(aWidget);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Win32 implementation
|
||||
//
|
||||
// Original author: G.Barrand, 1998
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// this :
|
||||
#include "G4Win32.hh"
|
||||
|
||||
#include "G4ios.hh"
|
||||
|
||||
static char className[] = "G4Win32";
|
||||
|
||||
G4Win32* G4Win32::instance = NULL;
|
||||
|
||||
static G4bool Win32Inited = false;
|
||||
static HWND topWindow = NULL;
|
||||
/***************************************************************************/
|
||||
G4Win32* G4Win32::getInstance()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (instance == NULL) {
|
||||
instance = new G4Win32();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Win32::G4Win32()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (Win32Inited == false) { // Should be Done once.
|
||||
|
||||
WNDCLASS wc;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = (WNDPROC)DefWindowProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = ::GetModuleHandle(NULL);
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
|
||||
wc.lpszMenuName = className;
|
||||
wc.lpszClassName = className;
|
||||
::RegisterClass(&wc);
|
||||
|
||||
topWindow =
|
||||
::CreateWindowEx(WS_EX_CLIENTEDGE, className, "Test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, ::GetModuleHandle(NULL), NULL);
|
||||
|
||||
if (topWindow == NULL) {
|
||||
G4cout << "G4Win32: Unable to create Win32 window." << G4endl;
|
||||
}
|
||||
|
||||
Win32Inited = true;
|
||||
}
|
||||
|
||||
AddDispatcher((G4DispatchFunction)G4Win32::DispatchWin32Event);
|
||||
SetMainInteractor(topWindow);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Win32::~G4Win32()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (this == instance) {
|
||||
instance = NULL;
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Win32::Inited()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return Win32Inited;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void* G4Win32::GetEvent()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
static MSG event;
|
||||
BOOL status = ::GetMessage(&event, NULL, 0, 0);
|
||||
if (status == FALSE) return NULL;
|
||||
return &event;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Win32::FlushAndWaitExecution()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
MSG event;
|
||||
while (::PeekMessage(&event, NULL, 0, 0, PM_REMOVE)) {
|
||||
::TranslateMessage(&event);
|
||||
::DispatchMessage(&event);
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Win32::DispatchWin32Event(void* a_event)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
::TranslateMessage((MSG*)a_event);
|
||||
::DispatchMessage((MSG*)a_event);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// G.Barrand
|
||||
|
||||
#include "G4Xt.hh"
|
||||
|
||||
#include "G4ios.hh"
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/Shell.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NewString(str) \
|
||||
((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
|
||||
|
||||
// static void XWidgetIconify (Widget);
|
||||
// static void XWidgetUniconify (Widget);
|
||||
// static void XDisplaySetWindowToNormalState (Display*,Window);
|
||||
|
||||
G4Xt* G4Xt::instance = NULL;
|
||||
|
||||
static G4bool XtInited = false;
|
||||
static int argn = 0;
|
||||
static char** args = NULL;
|
||||
static XtAppContext appContext = NULL;
|
||||
static Widget topWidget = NULL;
|
||||
/***************************************************************************/
|
||||
G4Xt* G4Xt::getInstance()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return G4Xt::getInstance(0, NULL, (char*)"Geant4");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Xt* G4Xt::getInstance(int a_argn, char** a_args, char* a_class)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (instance == NULL) {
|
||||
instance = new G4Xt(a_argn, a_args, a_class);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Xt::G4Xt(int a_argn, char** a_args, char* a_class)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (XtInited == false) { // Xt should be Inited once !
|
||||
if (a_argn != 0) { // Save args.
|
||||
args = (char**)malloc(a_argn * sizeof(char*));
|
||||
if (args != NULL) {
|
||||
argn = a_argn;
|
||||
for (int argi = 0; argi < a_argn; argi++) {
|
||||
args[argi] = (char*)NewString(a_args[argi]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if XtSpecificationRelease == 4
|
||||
Cardinal narg;
|
||||
narg = (Cardinal)a_argn;
|
||||
#else
|
||||
int narg;
|
||||
narg = a_argn;
|
||||
#endif
|
||||
Arg xargs[1];
|
||||
XtSetArg(xargs[0], XtNgeometry, "100x100");
|
||||
topWidget =
|
||||
XtAppInitialize(&appContext, a_class, NULL, (Cardinal)0, &narg, a_args, NULL, xargs, 1);
|
||||
if (topWidget == NULL) {
|
||||
G4cout << "G4Xt : Unable to init Xt." << G4endl;
|
||||
}
|
||||
// Restore a_args. XtAppInitialize corrupts the given ones !!!
|
||||
if ((a_argn != 0) && (args != NULL)) {
|
||||
for (int argi = 0; argi < a_argn; argi++) {
|
||||
if (args[argi] != NULL)
|
||||
strcpy(a_args[argi], args[argi]);
|
||||
else
|
||||
a_args[argi] = NULL;
|
||||
}
|
||||
}
|
||||
// If topWidget not realized, pbs with Inventor shells.
|
||||
XtSetMappedWhenManaged(topWidget, False);
|
||||
XtRealizeWidget(topWidget);
|
||||
XtInited = true;
|
||||
}
|
||||
SetArguments(argn, args);
|
||||
SetMainInteractor(topWidget);
|
||||
AddDispatcher(xt_dispatch_event);
|
||||
// Coverity gcc8 cast warning
|
||||
// AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Xt::~G4Xt()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (this == instance) {
|
||||
instance = NULL;
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Xt::Inited()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return XtInited;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void* G4Xt::GetEvent()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
static XEvent event;
|
||||
if (appContext == NULL) return NULL;
|
||||
if (topWidget == NULL) return NULL;
|
||||
XtAppNextEvent(appContext, &event);
|
||||
return &event;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Xt::PutStringInResourceDatabase(char* a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (topWidget == NULL) return;
|
||||
if (a_string == NULL) return;
|
||||
Display* dpy = XtDisplay(topWidget);
|
||||
XrmDatabase dbres = XrmGetStringDatabase(a_string);
|
||||
if (dbres == NULL) return;
|
||||
XrmDatabase database = XrmGetDatabase(dpy);
|
||||
if (database != NULL) {
|
||||
XrmMergeDatabases(dbres, &database);
|
||||
}
|
||||
else {
|
||||
XrmSetDatabase(dpy, dbres);
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Xt::FlushAndWaitExecution()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (topWidget == NULL) return;
|
||||
XSync(XtDisplay(topWidget), False);
|
||||
}
|
||||
Reference in New Issue
Block a user