]> Creatis software - bbtk.git/blob - packages/wxvtk/src/wxVTKRenderWindowInteractor.cxx
a7ac807a4e679172df220de4ea2741b44626e524
[bbtk.git] / packages / wxvtk / src / wxVTKRenderWindowInteractor.cxx
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: wxVTKRenderWindowInteractor.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/03/03 13:14:28 $
7   Version:   $Revision: 1.1 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even 
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15      PURPOSE.  See the above copyright notice for more information.
16
17 =========================================================================*/
18
19 #include "wxVTKRenderWindowInteractor.h"
20
21 //This is needed for vtk 3.1 :
22 #ifndef VTK_MAJOR_VERSION
23 #  include "vtkVersion.h"
24 #endif
25
26 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
27 #  include "vtkCommand.h"
28 #else
29 #  include "vtkInteractorStyle.h"
30 #endif
31
32 //=======================================================================
33 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
34 namespace bbwxvtk
35 {
36
37   //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
38 #if (!wxCHECK_VERSION(2, 4, 0))
39   wxWindow* wxGetTopLevelParent(wxWindow *win)
40   {
41     while ( win && !win->IsTopLevel() )
42       win = win->GetParent();
43     return win;
44   }
45 #endif
46 }
47 // LG : EO namespace bbwxvtk
48 //=======================================================================
49
50 // To access objc calls on cocoa
51 #ifdef __WXCOCOA__
52 #ifdef VTK_USE_COCOA
53 #import <Cocoa/Cocoa.h>
54 // This trick is no longer need in VTK CVS, should get rid of that:
55 #define id Id
56 #else
57 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
58 #endif //VTK_USE_COCOA
59 #endif //__WXCOCOA__
60
61 #ifdef __WXGTK__
62 #    include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
63 #    include "gdk/gdkprivate.h"
64 #ifdef __WXGTK20__
65 #include <wx/gtk/win_gtk.h>
66 #else
67 #include <wx/gtk1/win_gtk.h>
68 #endif
69 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
70                           GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
71                           GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
72 #endif
73
74 #ifdef __WXX11__
75 #include "wx/x11/privx.h"
76 #define GetXWindow(wxwin)   ((Window)(wxwin)->GetHandle())
77 #endif
78
79
80 //For more info on this class please go to:
81 //http://wxvtk.sf.net
82 //This hack is for some buggy wxGTK version:
83 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
84 #  define WX_USE_X_CAPTURE 0
85 #else
86 #  define WX_USE_X_CAPTURE 1
87 #endif
88
89 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
90
91 //=======================================================================
92 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
93 namespace bbwxvtk
94 {
95
96 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
97 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
98 #else
99 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
100 #endif  //__WXGTK__
101
102 //---------------------------------------------------------------------------
103 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
104 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
105 #else
106 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
107 #endif //__WXGTK__
108   //refresh window by doing a Render
109   EVT_PAINT       (wxVTKRenderWindowInteractor::OnPaint)
110   EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
111   EVT_MOTION      (wxVTKRenderWindowInteractor::OnMotion)
112
113   //Bind the events to the event converters
114   EVT_LEFT_DOWN   (wxVTKRenderWindowInteractor::OnButtonDown)
115   EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
116   EVT_RIGHT_DOWN  (wxVTKRenderWindowInteractor::OnButtonDown)
117   EVT_LEFT_UP     (wxVTKRenderWindowInteractor::OnButtonUp)
118   EVT_MIDDLE_UP   (wxVTKRenderWindowInteractor::OnButtonUp)
119   EVT_RIGHT_UP    (wxVTKRenderWindowInteractor::OnButtonUp)
120 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
121   EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
122   EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
123   EVT_MOUSEWHEEL  (wxVTKRenderWindowInteractor::OnMouseWheel)
124 // If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions
125 // of all characters are always returned.  EVT_CHAR also performs
126 // other necessary keyboard-dependent translations.
127   //EVT_KEY_DOWN    (wxVTKRenderWindowInteractor::OnKeyDown)
128   EVT_CHAR        (wxVTKRenderWindowInteractor::OnKeyDown)
129   EVT_KEY_UP      (wxVTKRenderWindowInteractor::OnKeyUp)
130 #endif
131   EVT_TIMER       (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
132   EVT_SIZE        (wxVTKRenderWindowInteractor::OnSize)
133 END_EVENT_TABLE()
134
135 //---------------------------------------------------------------------------
136 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
137 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxGLCanvas()
138 #else
139 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxWindow()
140 #endif //__WXGTK__
141       , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
142       , ActiveButton(wxEVT_NULL)
143       , RenderAllowed(0)
144       , Stereo(0)
145       , Handle(0)
146       , Created(true)
147       , RenderWhenDisabled(1)
148       , UseCaptureMouse(0)
149 {
150   
151   this->RenderWindow = NULL;
152   this->SetRenderWindow(vtkRenderWindow::New());
153   this->RenderWindow->Delete();
154   
155   //this->SetBackgroundColour( wxColour(255,0,255) );
156 }
157 //---------------------------------------------------------------------------
158 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
159                                                          wxWindowID id,
160                                                          const wxPoint &pos,
161                                                          const wxSize &size,
162                                                          long style,
163                                                          const wxString &name)
164 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
165       : vtkRenderWindowInteractor(), wxGLCanvas(parent, id, pos, size, style, name)
166 #else
167       : vtkRenderWindowInteractor(), wxWindow(parent, id, pos, size, style, name)
168 #endif //__WXGTK__
169       , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
170       , ActiveButton(wxEVT_NULL)
171       , RenderAllowed(0)
172       , Stereo(0)
173       , Handle(0)
174       , Created(true)
175       , RenderWhenDisabled(1)
176       , UseCaptureMouse(0)
177 {
178   
179   this->RenderWindow = NULL;
180   this->SetRenderWindow(vtkRenderWindow::New());
181   this->RenderWindow->Delete();
182   
183   // this->SetBackgroundColour( wxColour(255,0,0) );
184 }
185 //---------------------------------------------------------------------------
186 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
187 {   
188   // LG : trompe la mort !
189   SetReferenceCount(0);
190 }
191 //---------------------------------------------------------------------------
192 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
193 {
194   // we don't make use of the objectfactory, because we're not registered
195   return new wxVTKRenderWindowInteractor;
196 }
197 //---------------------------------------------------------------------------
198 void wxVTKRenderWindowInteractor::Initialize()
199 {
200   int *size = RenderWindow->GetSize();
201   // enable everything and start rendering
202   Enable();
203   //RenderWindow->Start();
204
205   // set the size in the render window interactor
206   Size[0] = size[0];
207   Size[1] = size[1];
208
209   // this is initialized
210   Initialized = 1;
211 }
212 //---------------------------------------------------------------------------
213 void wxVTKRenderWindowInteractor::Enable()
214 {
215   // if already enabled then done
216   if (Enabled)
217     return;
218
219   // that's it
220   Enabled = 1;
221 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
222   SetCurrent();
223 #endif
224   Modified();
225 }
226 //---------------------------------------------------------------------------
227 bool wxVTKRenderWindowInteractor::Enable(bool enable)
228 {
229 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
230   return wxGLCanvas::Enable(enable);
231 #else
232   return wxWindow::Enable(enable);
233 #endif
234 }
235 //---------------------------------------------------------------------------
236 void wxVTKRenderWindowInteractor::Disable()
237 {
238   // if already disabled then done
239   if (!Enabled)
240     return;
241
242   // that's it (we can't remove the event handler like it should be...)
243   Enabled = 0;
244   Modified();
245 }
246 //---------------------------------------------------------------------------
247 void wxVTKRenderWindowInteractor::Start()
248 {
249   // the interactor cannot control the event loop
250   vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
251     "interactor cannot control event loop.");
252 }
253 //---------------------------------------------------------------------------
254 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
255 {
256   if( RenderWindow )
257   {
258     // if the size changed tell render window
259     if ( x != Size[0] || y != Size[1] )
260     {
261       // adjust our (vtkRenderWindowInteractor size)
262       Size[0] = x;
263       Size[1] = y;
264       // and our RenderWindow's size
265       RenderWindow->SetSize(x, y);
266     }
267   }
268 }
269 //---------------------------------------------------------------------------
270 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
271 {
272   // it's a one shot timer
273   if (!timer.Start(10, TRUE))
274     assert(false);
275
276   return 1;
277   
278 }
279 //---------------------------------------------------------------------------
280 int wxVTKRenderWindowInteractor::DestroyTimer()
281 {
282   // do nothing
283   return 1;
284 }
285 //---------------------------------------------------------------------------
286 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
287 {
288   if (!Enabled)
289     return;
290     
291 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
292     // new style
293     InvokeEvent(vtkCommand::TimerEvent, NULL);
294 #else
295     // old style
296     InteractorStyle->OnTimer();
297 #endif
298 }
299
300 //---------------------------------------------------------------------------
301 // NOTE on implementation:
302 // Bad luck you ended up in the only tricky place of this code.
303 // A few note, wxWidgets still refuse to provide such convenient method
304 // so I have to maintain it myself, eventhough this is completely integrated
305 // in wxPython...
306 // Anyway if this happen to break for you then compare to a recent version of wxPython
307 // and look for the function long wxPyGetWinHandle(wxWindow* win)
308 // in wxPython/src/helpers.cpp
309 long wxVTKRenderWindowInteractor::GetHandleHack()
310 {
311   //helper function to hide the MSW vs GTK stuff
312   long handle_tmp = 0;
313
314 // __WXMSW__ is for Win32
315 //__WXMAX__ stands for using Carbon C-headers, using either the CarbonLib/CFM or the native Mach-O builds (which then also use the latest features available)
316 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
317 #if defined(__WXMSW__) || defined(__WXMAC__)
318     handle_tmp = (long)this->GetHandle();
319 #endif //__WXMSW__
320
321 //__WXCOCOA__ stands for using the objective-c Cocoa API
322 #ifdef __WXCOCOA__
323    // Here is how to find the NSWindow
324    wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
325      wxGetTopLevelParent( this ) );
326    if (toplevel != NULL )    
327    {
328      handle_tmp = (long)toplevel->GetNSWindow();
329    }
330    // The NSView will be deducted from 
331    // [(NSWindow*)Handle contentView]
332    // if only I knew how to write that in c++
333 #endif //__WXCOCOA__
334
335     // Find and return the actual X-Window.
336 #if defined(__WXGTK__) || defined(__WXX11__)
337     return (long)GetXWindow(this);
338 #endif
339
340 //#ifdef __WXMOTIF__
341 //    handle_tmp = (long)this->GetXWindow();
342 //#endif
343
344   return handle_tmp;
345 }
346 //---------------------------------------------------------------------------
347 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
348 {
349
350   //must always be here
351   wxPaintDC pDC(this);
352
353   //do it here rather than in the cstor: this is safer.
354   if(!Handle)
355   {
356     Handle = GetHandleHack();
357     RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
358 #ifdef __WXMSW__
359     RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
360 #endif //__WXMSW__
361   }
362   // get vtk to render to the wxWindows
363   //bbtkDebugMessage("Wx",9,"wxVTKRenderWindowInteractor::OnPaint"<<std::endl);
364   //std::cout << "wxVTKRenderWindowInteractor::OnPaint"<<std::endl;
365   Render();
366
367 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
368   //  bbtkDebugMessage("Core",9,"wxVTKRenderWindowInteractor::OnPaint   public wxGLCanvas, virtual public vtkRenderWindowInteractor  \n");
369 #else
370   //  bbtkDebugMessage("Core",9,"wxVTKRenderWindowInteractor::OnPaint public wxWindow, virtual public vtkRenderWindowInteractor     \n");
371 #endif //__WXGTK__
372
373 }
374 //---------------------------------------------------------------------------
375 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
376 {
377   //printf("EED wxVTKRenderWindowInteractor::OnEraseBackground \n");
378   //turn off background erase to reduce flickering on MSW
379   event.Skip(false);
380 }
381 //---------------------------------------------------------------------------
382 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
383 {
384   int w, h;
385   GetClientSize(&w, &h);
386   UpdateSize(w, h);
387
388   if (!Enabled) 
389     {
390     return;
391     }
392
393 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
394   InvokeEvent(vtkCommand::ConfigureEvent, NULL);
395 #endif
396   //this will check for Handle
397   //Render();
398 }
399 //---------------------------------------------------------------------------
400 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
401 {
402  if (!Enabled) 
403     {
404    return;
405     }
406
407 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
408   SetEventInformationFlipY(event.GetX(), event.GetY(), 
409     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
410
411   InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
412 #else
413   InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
414     event.GetX(), Size[1] - event.GetY() - 1);
415 #endif
416 }
417 //---------------------------------------------------------------------------
418 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
419 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
420 {
421   if (!Enabled) 
422     {
423     return;
424     }
425
426 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
427     // new style
428   SetEventInformationFlipY(event.GetX(), event.GetY(), 
429       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
430
431   InvokeEvent(vtkCommand::EnterEvent, NULL);
432 #else
433     // old style
434   InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
435       event.GetX(), Size[1] - event.GetY() - 1);  
436 #endif
437 }
438 //---------------------------------------------------------------------------
439 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
440 {
441   if (!Enabled) 
442     {
443     return;
444     }
445
446 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
447     // new style
448   SetEventInformationFlipY(event.GetX(), event.GetY(), 
449       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
450
451   InvokeEvent(vtkCommand::LeaveEvent, NULL);
452 #else
453     // old style
454   InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
455       event.GetX(), Size[1] - event.GetY() - 1);  
456 #endif
457 }
458 //---------------------------------------------------------------------------
459 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
460 {
461   if (!Enabled) 
462     {
463     return;
464     }
465
466 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
467     // new style
468   int keycode = event.GetKeyCode();
469   char key = '\0';
470   if (keycode < 256)
471   {
472     // TODO: Unicode in non-Unicode mode ??
473     key = (char)keycode;
474   }
475
476   SetEventInformationFlipY(event.GetX(), event.GetY(), 
477     event.ControlDown(), event.ShiftDown(), key, 0, NULL);
478
479   InvokeEvent(vtkCommand::KeyPressEvent, NULL);
480   InvokeEvent(vtkCommand::CharEvent, NULL);
481 #else
482   InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(), 
483     event.GetKeyCode(), 1);
484 #endif
485   event.Skip();
486 }
487 //---------------------------------------------------------------------------
488 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
489 {
490   if (!Enabled) 
491     {
492     return;
493     }
494
495 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
496     // new style
497   int keycode = event.GetKeyCode();
498   char key = '\0';
499   if (keycode < 256)
500   {
501     // TODO: Unicode in non-Unicode mode ??
502     key = (char)keycode;
503   }
504
505   SetEventInformationFlipY(event.GetX(), event.GetY(), 
506     event.ControlDown(), event.ShiftDown(), key, 0, NULL);
507   InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
508 #else
509   InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(), 
510     event.GetKeyCode(), 1);
511 #endif
512   event.Skip();
513 }
514 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
515 //---------------------------------------------------------------------------
516 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
517 {
518   if (!Enabled || (ActiveButton != wxEVT_NULL))
519     {
520     return;
521     }
522   ActiveButton = event.GetEventType();
523
524 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
525   SetEventInformationFlipY(event.GetX(), event.GetY(), 
526     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
527 #endif
528
529   if(event.RightDown())
530   {
531 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
532     // new style
533     InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
534 #else            
535     // old style
536     InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
537       event.GetX(), Size[1] - event.GetY() - 1);
538 #endif
539   }
540   else if(event.LeftDown())
541   {
542 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
543     // new style
544     InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
545 #else            
546     // old style
547     InteractorStyle->OnLeftButtonDown(event.ControlDown(),  event.ShiftDown(),
548       event.GetX(), Size[1] - event.GetY() - 1);
549 #endif
550   }
551   else if(event.MiddleDown())
552   {
553 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
554     // new style
555     InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
556 #else            
557     // old style
558     InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
559       event.GetX(), Size[1] - event.GetY() - 1);
560 #endif
561   }
562   //save the button and capture mouse until the button is released
563   //Only if :
564   //1. it is possible (WX_USE_X_CAPTURE)
565   //2. user decided to.
566   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
567   {
568     CaptureMouse();
569   }
570 }
571 //---------------------------------------------------------------------------
572 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
573 {
574   //EVT_xxx_DOWN == EVT_xxx_UP - 1
575   //This is only needed if two mouse buttons are pressed at the same time.
576   //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or 
577   //wxEVT_COMMAND_RIGHT_CLICK
578   if (!Enabled || (ActiveButton != (event.GetEventType()-1))) 
579     {
580     return;
581     }
582
583 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
584   SetEventInformationFlipY(event.GetX(), event.GetY(), 
585     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
586 #endif
587   
588   if(ActiveButton == wxEVT_RIGHT_DOWN)
589   {
590 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
591     // new style
592     InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
593 #else            
594     // old style
595     InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
596       event.GetX(), Size[1] - event.GetY() - 1);
597 #endif
598   }
599   else if(ActiveButton == wxEVT_LEFT_DOWN)
600   {
601 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
602     // new style
603     InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
604 #else            
605     // old style
606     InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
607       event.GetX(), Size[1] - event.GetY() - 1);
608 #endif
609   }
610   else if(ActiveButton == wxEVT_MIDDLE_DOWN)
611   {
612 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
613     // new style
614     InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
615 #else            
616     // old style
617     InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
618       event.GetX(), Size[1] - event.GetY() - 1);
619 #endif
620   }
621   //if the ActiveButton is realeased, then release mouse capture
622   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
623   {
624     ReleaseMouse();
625   }
626   ActiveButton = wxEVT_NULL;
627 }
628 //---------------------------------------------------------------------------
629 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
630 {
631 // Mouse wheel was only added after VTK 4.4 (I think...)
632 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
633   // new style
634   //Set vtk event information ... The numebr of wheel rotations is stored in
635   //the x varible.  y varible is zero
636   SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0, 
637                            event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
638   if(event.GetWheelRotation() > 0)
639     {
640       //Send event to VTK
641 // EED
642 //      InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
643     }
644   else
645     {
646       //Send event to VTK
647 // EED
648 //      InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
649     }
650 #endif
651     
652 }
653
654 //---------------------------------------------------------------------------
655 void wxVTKRenderWindowInteractor::Render()
656 {
657   RenderAllowed = 1;
658   if (!RenderWhenDisabled)
659     {
660     //the user doesn't want us to render when the toplevel frame
661     //is disabled - first find the top level parent
662     wxWindow *topParent = wxGetTopLevelParent(this);
663     if (topParent)
664       {
665       //if it exists, check whether it's enabled
666       //if it's not enabeld, RenderAllowed will be false
667       RenderAllowed = topParent->IsEnabled();
668       }
669     }
670
671   if (RenderAllowed)
672     {
673     if(Handle && (Handle == GetHandleHack()) )
674       {
675       RenderWindow->Render();
676       }
677 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
678     else if(GetHandleHack())
679       {
680       //this means the user has reparented us; let's adapt to the
681       //new situation by doing the WindowRemap dance
682       //store the new situation
683       Handle = GetHandleHack();
684       RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
685       RenderWindow->WindowRemap();
686       RenderWindow->Render();
687       }
688 #endif
689     }
690 }
691 //---------------------------------------------------------------------------
692 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
693 {
694   //Change value of __RenderWhenDisabled ivar.
695   //If __RenderWhenDisabled is false (the default), this widget will not
696   //call Render() on the RenderWindow if the top level frame (i.e. the
697   //containing frame) has been disabled.
698
699   //This prevents recursive rendering during wxSafeYield() calls.
700   //wxSafeYield() can be called during the ProgressMethod() callback of
701   //a VTK object to have progress bars and other GUI elements updated -
702   //it does this by disabling all windows (disallowing user-input to
703   //prevent re-entrancy of code) and then handling all outstanding
704   //GUI events.
705         
706   //However, this often triggers an OnPaint() method for wxVTKRWIs,
707   //resulting in a Render(), resulting in Update() being called whilst
708   //still in progress.
709
710   RenderWhenDisabled = (bool)newValue;
711 }
712 //---------------------------------------------------------------------------
713 //
714 // Set the variable that indicates that we want a stereo capable window
715 // be created. This method can only be called before a window is realized.
716 //
717 void wxVTKRenderWindowInteractor::SetStereo(int capable)
718 {
719   if (Stereo != capable)
720     {
721     Stereo = capable;
722     RenderWindow->StereoCapableWindowOn();
723     RenderWindow->SetStereoTypeToCrystalEyes();
724     Modified();
725     }
726 }
727
728 //---------------------------------------------------------------------------
729 //
730 //
731 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
732 {
733   this->Superclass::PrintSelf(os, indent);
734 }
735
736
737 #if defined(_WIN32)
738 const char * wxVTKRenderWindowInteractor::GetClassName() const
739 {
740   return "wxVTKRenderWindowInteractor";
741 }
742 #endif //_WIN32
743
744 }
745 // LG : EO namespace bbwxvtk
746 //=======================================================================
747