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5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/toolx/Xt/zb_viewer (Version 11.3.0) and /externals/g4tools/include/toolx/Xt/zb_viewer (Version 10.4.p1)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef toolx_Xt_zb_viewer                        
  5 #define toolx_Xt_zb_viewer                        
  6                                                   
  7 #include "session"                                
  8 #include "ImageArea"                              
  9 #include "../X11/pixwin"                          
 10                                                   
 11 #include <X11/Shell.h>                            
 12 #include <X11/StringDefs.h>                       
 13 #include <X11/IntrinsicP.h>                       
 14                                                   
 15 #include <tools/sg/zb_viewer>                     
 16 #include <tools/num2s>                            
 17 #include <tools/sg/device_interactor>             
 18 #include <tools/sg/keys>                          
 19                                                   
 20 namespace toolx {                                 
 21 namespace Xt {                                    
 22                                                   
 23 class zb_viewer: public tools::sg::zb_viewer {    
 24   typedef tools::sg::zb_viewer parent;            
 25 public:                                           
 26   zb_viewer(session& a_session,                   
 27             int a_x = 0,int a_y = 0,              
 28             unsigned int a_width = 500,unsigne    
 29             const std::string& a_win_title = "    
 30   :parent(a_session.out(),a_width,a_height)       
 31   ,m_session(a_session)                           
 32   ,m_shell(0)                                     
 33   ,m_image_area(0)                                
 34   ,m_pixwin(0)                                    
 35   ,m_interactor(0)                                
 36   {                                               
 37     Widget app_widget = a_session.get_app_widg    
 38     if(!app_widget) return;                       
 39                                                   
 40     std::string sgeom;                            
 41     tools::numas(a_width,sgeom);                  
 42     sgeom += "x";                                 
 43     tools::numas(a_height,sgeom);                 
 44     sgeom += "+";                                 
 45     tools::numas(a_x,sgeom);                      
 46     sgeom += "+";                                 
 47     tools::numas(a_y,sgeom);                      
 48                                                   
 49     Arg args[2];                                  
 50     XtSetArg(args[0],XtNgeometry,XtNewString(s    
 51     XtSetArg(args[1],XtNborderWidth,0);           
 52                                                   
 53     m_shell = ::XtAppCreateShell((char*)a_win_    
 54                                  (char*)"zb_vi    
 55                                  topLevelShell    
 56     ::XtSetMappedWhenManaged(m_shell,True);       
 57                                                   
 58     m_image_area = ::XtCreateManagedWidget("im    
 59     ::XtAddCallback(m_image_area,ImageArea::Xo    
 60     ::XtAddCallback(m_image_area,ImageArea::Xo    
 61     ::XtAddCallback(m_image_area,ImageArea::Xo    
 62                                                   
 63     ::XtAddCallback(m_shell,XtNdestroyCallback    
 64                                                   
 65     ::XtRealizeWidget(m_shell);                   
 66                                                   
 67    {int iscreen;                                  
 68     Screen* screen = XtScreen(m_image_area);      
 69     iscreen = XScreenNumberOfScreen(screen);      
 70     m_pixwin = new toolx::X11::pixwin(a_sessio    
 71     m_pixwin->set_size(m_image_area->core.widt    
 72                                                   
 73   //Atom WM_DELETE_WINDOW_atom = ::XInternAtom    
 74   //::XSetWMProtocols(XtDisplay(m_shell),XtWin    
 75   }                                               
 76   virtual ~zb_viewer() {                          
 77     delete m_pixwin;                              
 78     if(m_shell) {                                 
 79       ::XtRemoveCallback(m_image_area,ImageAre    
 80       ::XtRemoveCallback(m_shell,XtNdestroyCal    
 81       ::XtDestroyWidget(m_shell);                 
 82     }                                             
 83     m_shell = 0;                                  
 84     m_image_area = 0;                             
 85   }                                               
 86 protected:                                        
 87   zb_viewer(const zb_viewer& a_from)              
 88   :parent(a_from)                                 
 89   ,m_session(a_from.m_session)                    
 90   ,m_shell(0)                                     
 91   ,m_image_area(0)                                
 92   ,m_interactor(0)                                
 93   {}                                              
 94   zb_viewer& operator=(const zb_viewer& a_from    
 95     parent::operator=(a_from);                    
 96     return *this;                                 
 97   }                                               
 98 public:                                           
 99   bool has_window() const {return m_image_area    
100                                                   
101   bool show() {                                   
102     if(!m_shell) return false;                    
103     ::XtRealizeWidget(m_shell);                   
104     ::XtMapWidget(m_shell);                       
105     // Raise window :                             
106     if(XtIsWidget(m_shell) && XtIsRealized(m_s    
107       Display* display = XtDisplay(m_shell);      
108       Atom atom = ::XInternAtom(display,"WM_DE    
109       ::XSetWMProtocols(display,XtWindow(m_she    
110       ::XRaiseWindow(display,XtWindow(m_shell)    
111     }                                             
112     return true;                                  
113   }                                               
114                                                   
115   void win_render() {                             
116     if(m_image_area) ImageArea::paint(m_image_    
117   }                                               
118                                                   
119   void set_device_interactor(tools::sg::device    
120 protected:                                        
121   static void resize_cbk(Widget a_widget,XtPoi    
122     if(!XtIsRealized(a_widget)) return;           
123     unsigned int width = a_widget->core.width;    
124     unsigned int height = a_widget->core.heigh    
125     //::printf("debug: toolx::Xt::zb_viewer::r    
126     zb_viewer* _this = (zb_viewer*)a_tag;         
127     _this->set_size(width,height);                
128     _this->m_pixwin->set_size(width,height);      
129   }                                               
130   static void paint_cbk(Widget a_widget,XtPoin    
131     if(!XtIsRealized(a_widget)) return;           
132     unsigned int width = a_widget->core.width;    
133     unsigned int height = a_widget->core.heigh    
134     //::printf("debug: toolx::Xt::zb_viewer::p    
135     zb_viewer* _this = (zb_viewer*)a_tag;         
136     if(!_this->render(tools::sg::zb_viewer::ge    
137     _this->m_pixwin->put_buffer(XtWindow(a_wid    
138    //parent::after_render();                      
139     _this->out_buffer_clear();                    
140   }                                               
141   static void event_cbk(Widget,XtPointer a_tag    
142     zb_viewer* _this = (zb_viewer*)a_tag;         
143     if(!_this->m_interactor) return;              
144     ImageArea::XoAnyCallbackStruct* data = (Im    
145     XEvent* xevent = data->event;                 
146     switch( xevent->type ) {                      
147     case KeyPress:{                               
148       KeySym key_sym;                             
149       ::XLookupString(&(xevent->xkey),NULL,0,&    
150       tools::sg::key_down_event event(_this->c    
151       _this->m_interactor->key_press(event);      
152     }return;                                      
153     case KeyRelease:{                             
154       KeySym key_sym;                             
155       ::XLookupString(&(xevent->xkey),NULL,0,&    
156       tools::sg::key_up_event event(_this->con    
157       _this->m_interactor->key_release(event);    
158     }return;                                      
159     case ButtonPress:{                            
160       if(xevent->xbutton.button==Button4) {  /    
161         tools::sg::wheel_rotate_event event(8)    
162         _this->m_interactor->wheel_rotate(even    
163       } else if(xevent->xbutton.button==Button    
164         tools::sg::wheel_rotate_event event(-8    
165         _this->m_interactor->wheel_rotate(even    
166       } else if(xevent->xbutton.button==Button    
167         tools::sg::mouse_down_event event(xeve    
168         _this->m_interactor->mouse_press(event    
169       }                                           
170     }return;                                      
171     case ButtonRelease:{                          
172       if(xevent->xbutton.button==Button1) {       
173         tools::sg::mouse_up_event event(xevent    
174         _this->m_interactor->mouse_release(eve    
175       }                                           
176     }return;                                      
177     case MotionNotify:{                           
178       if((xevent->xmotion.state & Button1Motio    
179         tools::sg::mouse_move_event event(xeve    
180         _this->m_interactor->mouse_move(event)    
181       }                                           
182     }return;                                      
183     default:return;}                              
184   }                                               
185   static void destroy_shell_callback(Widget,Xt    
186     zb_viewer* _this = (zb_viewer*)a_tag;         
187     _this->m_shell = 0;                           
188     _this->m_image_area = 0;                      
189   }                                               
190 protected:                                        
191   tools::key_code convert_key(KeySym a_key) {     
192     if(a_key==XK_Shift_L) return tools::sg::ke    
193     if(a_key==XK_Shift_R) return tools::sg::ke    
194     return (tools::key_code)a_key;                
195   }                                               
196 protected:                                        
197   session& m_session;                             
198   Widget m_shell;                                 
199   Widget m_image_area;                            
200   toolx::X11::pixwin* m_pixwin;                   
201   tools::sg::device_interactor* m_interactor;     
202 };                                                
203                                                   
204 }}                                                
205                                                   
206                                                   
207 #endif                                            
208