1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkWin32RenderWindowInteractor.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkWin32RenderWindowInteractor - implements Win32 specific functions
16 // required by vtkRenderWindowInteractor.
17 //
18 // .SECTION Description
19 // By default the interactor installs a MessageProc callback which
20 // intercepts windows' messages to the window and controls interactions by
21 // routing them to the InteractoStyle classes.
22 // MFC or BCB programs can prevent this and instead directly route any mouse/key
23 // messages into the event bindings by setting InstallMessageProc to false.
24 // This provides a minimal "Mapped" mode of interaction
25 //
26 #ifndef vtkWin32RenderWindowInteractor_h
27 #define vtkWin32RenderWindowInteractor_h
28 
29 #include "vtkRenderingOpenGLModule.h" // For export macro
30 #include "vtkRenderWindowInteractor.h"
31 #include "vtkWindows.h" // For windows API.
32 
33 #include "vtkTDxConfigure.h" // defines VTK_USE_TDX
34 #ifdef VTK_USE_TDX
35 class vtkTDxWinDevice;
36 #endif
37 
38 class VTKRENDERINGOPENGL_EXPORT vtkWin32RenderWindowInteractor : public vtkRenderWindowInteractor
39 {
40 public:
41   // Description:
42   // Construct object so that light follows camera motion.
43   static vtkWin32RenderWindowInteractor *New();
44 
45   vtkTypeMacro(vtkWin32RenderWindowInteractor,vtkRenderWindowInteractor);
46   void PrintSelf(ostream& os, vtkIndent indent);
47 
48   // Description:
49   // Initialize the event handler
50   virtual void Initialize();
51 
52   // Description:
53   // Enable/Disable interactions.  By default interactors are enabled when
54   // initialized.  Initialize() must be called prior to enabling/disabling
55   // interaction. These methods are used when a window/widget is being
56   // shared by multiple renderers and interactors.  This allows a "modal"
57   // display where one interactor is active when its data is to be displayed
58   // and all other interactors associated with the widget are disabled
59   // when their data is not displayed.
60   virtual void Enable();
61   virtual void Disable();
62 
63   // Description:
64   // By default the interactor installs a MessageProc callback which
65   // intercepts windows messages to the window and controls interactions.
66   // MFC or BCB programs can prevent this and instead directly route any mouse/key
67   // messages into the event bindings by setting InstallMessgeProc to false.
68   vtkSetMacro(InstallMessageProc,int);
69   vtkGetMacro(InstallMessageProc,int);
70   vtkBooleanMacro(InstallMessageProc,int);
71 
72   // Description:
73   // Win32 specific application terminate, calls ClassExitMethod then
74   // calls PostQuitMessage(0) to terminate the application. An application can Specify
75   // ExitMethod for alternative behavior (i.e. suppression of keyboard exit)
76   void TerminateApp(void);
77 
78   //BTX
79   friend VTKRENDERINGOPENGL_EXPORT LRESULT CALLBACK vtkHandleMessage(HWND hwnd,UINT uMsg, WPARAM w, LPARAM l);
80   friend VTKRENDERINGOPENGL_EXPORT LRESULT CALLBACK vtkHandleMessage2(HWND hwnd,UINT uMsg, WPARAM w, LPARAM l, vtkWin32RenderWindowInteractor *me);
81 
82   // Description:
83   // Various methods that a Win32 window can redirect to this class to be
84   // handled.
85   virtual void OnMouseMove  (HWND wnd, UINT nFlags, int X, int Y);
86   virtual void OnNCMouseMove(HWND wnd, UINT nFlags, int X, int Y);
87   virtual void OnRButtonDown(HWND wnd, UINT nFlags, int X, int Y, int repeat=0);
88   virtual void OnRButtonUp  (HWND wnd, UINT nFlags, int X, int Y);
89   virtual void OnMButtonDown(HWND wnd, UINT nFlags, int X, int Y, int repeat=0);
90   virtual void OnMButtonUp  (HWND wnd, UINT nFlags, int X, int Y);
91   virtual void OnLButtonDown(HWND wnd, UINT nFlags, int X, int Y, int repeat=0);
92   virtual void OnLButtonUp  (HWND wnd, UINT nFlags, int X, int Y);
93   virtual void OnSize       (HWND wnd, UINT nType,  int X, int Y);
94   virtual void OnTimer      (HWND wnd, UINT nIDEvent);
95   virtual void OnKeyDown    (HWND wnd, UINT nChar, UINT nRepCnt, UINT nFlags);
96   virtual void OnKeyUp      (HWND wnd, UINT nChar, UINT nRepCnt, UINT nFlags);
97   virtual void OnChar       (HWND wnd, UINT nChar, UINT nRepCnt, UINT nFlags);
98   virtual void OnMouseWheelForward (HWND wnd, UINT nFlags, int X, int Y);
99   virtual void OnMouseWheelBackward(HWND wnd, UINT nFlags, int X, int Y);
100   virtual void OnFocus(HWND wnd, UINT nFlags);
101   virtual void OnKillFocus(HWND wnd, UINT nFlags);
102   //ETX
103 
104   // Description:
105   // Methods to set the default exit method for the class. This method is
106   // only used if no instance level ExitMethod has been defined.  It is
107   // provided as a means to control how an interactor is exited given
108   // the various language bindings (tcl, Win32, etc.).
109   static void SetClassExitMethod(void (*f)(void *), void *arg);
110   static void SetClassExitMethodArgDelete(void (*f)(void *));
111 
112   // Description:
113   // These methods correspond to the the Exit, User and Pick
114   // callbacks. They allow for the Style to invoke them.
115   virtual void ExitCallback();
116 
117 protected:
118   vtkWin32RenderWindowInteractor();
119   ~vtkWin32RenderWindowInteractor();
120 
121   HWND    WindowId;
122   WNDPROC OldProc;
123   int     InstallMessageProc;
124   int     MouseInWindow;
125   int     StartedMessageLoop;
126 
127   //BTX
128   // Description:
129   // Class variables so an exit method can be defined for this class
130   // (used to set different exit methods for various language bindings,
131   // i.e. tcl, java, Win32)
132   static void (*ClassExitMethod)(void *);
133   static void (*ClassExitMethodArgDelete)(void *);
134   static void *ClassExitMethodArg;
135   //ETX
136 
137   // Description:
138   // Win32-specific internal timer methods. See the superclass for detailed
139   // documentation.
140   virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
141   virtual int InternalDestroyTimer(int platformTimerId);
142 
143   // Description:
144   // This will start up the event loop and never return. If you
145   // call this method it will loop processing events until the
146   // application is exited.
147   virtual void StartEventLoop();
148 
149 #ifdef VTK_USE_TDX
150   vtkTDxWinDevice *Device;
151 #endif
152 
153 private:
154   vtkWin32RenderWindowInteractor(const vtkWin32RenderWindowInteractor&);  // Not implemented.
155   void operator=(const vtkWin32RenderWindowInteractor&);  // Not implemented.
156 };
157 
158 #endif
159 
160