Warning, /include/Geant4/toolx/Xt/session is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef toolx_Xt_session
0005 #define toolx_Xt_session
0006
0007 #include <X11/Intrinsic.h>
0008 #include <X11/Shell.h>
0009 #include <X11/StringDefs.h>
0010
0011 #include <ostream>
0012
0013 namespace toolx {
0014 namespace Xt {
0015
0016 class session {
0017 public:
0018 session(std::ostream& a_out)
0019 :m_out(a_out),m_app_context(0),m_app_widget(0),m_app_owner(false)
0020 {}
0021 session(std::ostream& a_out,XtAppContext a_app_context,Widget a_app_widget)
0022 :m_out(a_out),m_app_context(a_app_context),m_app_widget(a_app_widget),m_app_owner(false)
0023 {}
0024 session(std::ostream& a_out,int& a_argc,char** a_argv)
0025 :m_out(a_out),m_app_context(0),m_app_widget(0),m_app_owner(false)
0026 {
0027 //LookDSM_Problem();
0028 Arg args[1];
0029 XtSetArg(args[0],XtNgeometry,XtNewString("100x100"));
0030 m_app_widget = ::XtAppInitialize(&m_app_context,"toolx::Xt::session",NULL,(Cardinal)0,&a_argc,a_argv,NULL,args,1);
0031 if(!m_app_context || !m_app_widget) {
0032 m_app_context = 0;
0033 m_app_widget = 0;
0034 m_app_owner = false;
0035 return;
0036 }
0037 m_app_owner = true;
0038 }
0039 virtual ~session() {
0040 if(m_app_owner) {
0041 if(m_app_widget) {::XtDestroyWidget(m_app_widget);m_app_widget = 0;}
0042 if(m_app_context) {::XtDestroyApplicationContext(m_app_context);m_app_context = 0;}
0043 }
0044 }
0045 protected:
0046 session(const session& a_from)
0047 :m_out(a_from.m_out),m_app_context(0),m_app_widget(0),m_app_owner(false)
0048 {}
0049 session& operator=(const session&){return *this;}
0050 public:
0051 std::ostream& out() const {return m_out;}
0052 bool is_valid() {return m_app_context && m_app_widget?true:false;}
0053 bool steer() {
0054 if(!m_app_context) return false;
0055 while(true) {
0056 XEvent event;
0057 ::XtAppNextEvent(m_app_context,&event);
0058 ::XtDispatchEvent(&event);
0059 //if(m_exit) break;
0060 }
0061 return true;
0062 }
0063 bool sync() {
0064 //if(!m_app_widget) return false;
0065 //Display* display = XtDisplay(m_app_widget);
0066 //::XSync(display,False);
0067 if(!m_app_context) return false;
0068 while(true) {
0069 XtInputMask input = ::XtAppPending(m_app_context);
0070 if(input==0) break;
0071 XEvent event;
0072 ::XtAppNextEvent(m_app_context,&event);
0073 ::XtDispatchEvent(&event);
0074 }
0075 return true;
0076 }
0077 public:
0078 Widget get_app_widget() {return m_app_widget;}
0079 protected:
0080 std::ostream& m_out;
0081 XtAppContext m_app_context;
0082 Widget m_app_widget;
0083 bool m_app_owner;
0084 };
0085
0086 }}
0087
0088
0089 #endif