Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef toolx_Xt_session 4 #ifndef toolx_Xt_session 5 #define toolx_Xt_session 5 #define toolx_Xt_session 6 6 7 #include <X11/Intrinsic.h> 7 #include <X11/Intrinsic.h> 8 #include <X11/Shell.h> 8 #include <X11/Shell.h> 9 #include <X11/StringDefs.h> 9 #include <X11/StringDefs.h> 10 10 11 #include <ostream> 11 #include <ostream> 12 12 13 namespace toolx { 13 namespace toolx { 14 namespace Xt { 14 namespace Xt { 15 15 16 class session { 16 class session { 17 public: 17 public: 18 session(std::ostream& a_out) 18 session(std::ostream& a_out) 19 :m_out(a_out),m_app_context(0),m_app_widget( 19 :m_out(a_out),m_app_context(0),m_app_widget(0),m_app_owner(false) 20 {} 20 {} 21 session(std::ostream& a_out,XtAppContext a_a 21 session(std::ostream& a_out,XtAppContext a_app_context,Widget a_app_widget) 22 :m_out(a_out),m_app_context(a_app_context),m 22 :m_out(a_out),m_app_context(a_app_context),m_app_widget(a_app_widget),m_app_owner(false) 23 {} 23 {} 24 session(std::ostream& a_out,int& a_argc,char 24 session(std::ostream& a_out,int& a_argc,char** a_argv) 25 :m_out(a_out),m_app_context(0),m_app_widget( 25 :m_out(a_out),m_app_context(0),m_app_widget(0),m_app_owner(false) 26 { 26 { 27 //LookDSM_Problem(); 27 //LookDSM_Problem(); 28 Arg args[1]; 28 Arg args[1]; 29 XtSetArg(args[0],XtNgeometry,XtNewString(" 29 XtSetArg(args[0],XtNgeometry,XtNewString("100x100")); 30 m_app_widget = ::XtAppInitialize(&m_app_co 30 m_app_widget = ::XtAppInitialize(&m_app_context,"toolx::Xt::session",NULL,(Cardinal)0,&a_argc,a_argv,NULL,args,1); 31 if(!m_app_context || !m_app_widget) { 31 if(!m_app_context || !m_app_widget) { 32 m_app_context = 0; 32 m_app_context = 0; 33 m_app_widget = 0; 33 m_app_widget = 0; 34 m_app_owner = false; 34 m_app_owner = false; 35 return; 35 return; 36 } 36 } 37 m_app_owner = true; 37 m_app_owner = true; 38 } 38 } 39 virtual ~session() { 39 virtual ~session() { 40 if(m_app_owner) { 40 if(m_app_owner) { 41 if(m_app_widget) {::XtDestroyWidget(m_ap 41 if(m_app_widget) {::XtDestroyWidget(m_app_widget);m_app_widget = 0;} 42 if(m_app_context) {::XtDestroyApplicatio 42 if(m_app_context) {::XtDestroyApplicationContext(m_app_context);m_app_context = 0;} 43 } 43 } 44 } 44 } 45 protected: 45 protected: 46 session(const session& a_from) 46 session(const session& a_from) 47 :m_out(a_from.m_out),m_app_context(0),m_app_ 47 :m_out(a_from.m_out),m_app_context(0),m_app_widget(0),m_app_owner(false) 48 {} 48 {} 49 session& operator=(const session&){return *t 49 session& operator=(const session&){return *this;} 50 public: 50 public: 51 std::ostream& out() const {return m_out;} 51 std::ostream& out() const {return m_out;} 52 bool is_valid() {return m_app_context && m_a 52 bool is_valid() {return m_app_context && m_app_widget?true:false;} 53 bool steer() { 53 bool steer() { 54 if(!m_app_context) return false; 54 if(!m_app_context) return false; 55 while(true) { 55 while(true) { 56 XEvent event; 56 XEvent event; 57 ::XtAppNextEvent(m_app_context,&event); 57 ::XtAppNextEvent(m_app_context,&event); 58 ::XtDispatchEvent(&event); 58 ::XtDispatchEvent(&event); 59 //if(m_exit) break; 59 //if(m_exit) break; 60 } 60 } 61 return true; 61 return true; 62 } 62 } 63 bool sync() { 63 bool sync() { 64 //if(!m_app_widget) return false; 64 //if(!m_app_widget) return false; 65 //Display* display = XtDisplay(m_app_widget) 65 //Display* display = XtDisplay(m_app_widget); 66 //::XSync(display,False); 66 //::XSync(display,False); 67 if(!m_app_context) return false; 67 if(!m_app_context) return false; 68 while(true) { 68 while(true) { 69 XtInputMask input = ::XtAppPending(m_app 69 XtInputMask input = ::XtAppPending(m_app_context); 70 if(input==0) break; 70 if(input==0) break; 71 XEvent event; 71 XEvent event; 72 ::XtAppNextEvent(m_app_context,&event); 72 ::XtAppNextEvent(m_app_context,&event); 73 ::XtDispatchEvent(&event); 73 ::XtDispatchEvent(&event); 74 } 74 } 75 return true; 75 return true; 76 } 76 } 77 public: 77 public: 78 Widget get_app_widget() {return m_app_widget 78 Widget get_app_widget() {return m_app_widget;} 79 protected: 79 protected: 80 std::ostream& m_out; 80 std::ostream& m_out; 81 XtAppContext m_app_context; 81 XtAppContext m_app_context; 82 Widget m_app_widget; 82 Widget m_app_widget; 83 bool m_app_owner; 83 bool m_app_owner; 84 }; 84 }; 85 85 86 }} 86 }} 87 87 88 88 89 #endif 89 #endif