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