Cleanup: remove redundant doxygen \file argument
[blender.git] / intern / ghost / intern / GHOST_WindowWin32.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file \ingroup GHOST
21  * Declaration of GHOST_WindowWin32 class.
22  */
23
24 #ifndef __GHOST_WINDOWWIN32_H__
25 #define __GHOST_WINDOWWIN32_H__
26
27 #ifndef WIN32
28 #error WIN32 only!
29 #endif // WIN32
30
31 #include "GHOST_Window.h"
32 #include "GHOST_TaskbarWin32.h"
33 #ifdef WITH_INPUT_IME
34 #  include "GHOST_ImeWin32.h"
35 #endif
36
37 #include <wintab.h>
38 #define PACKETDATA  (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR)
39 #define PACKETMODE  PK_BUTTONS
40 #include <pktdef.h>
41
42 class GHOST_SystemWin32;
43 class GHOST_DropTargetWin32;
44
45 // typedefs for WinTab functions to allow dynamic loading
46 typedef UINT (API * GHOST_WIN32_WTInfo)(UINT, UINT, LPVOID);
47 typedef HCTX (API * GHOST_WIN32_WTOpen)(HWND, LPLOGCONTEXTA, BOOL);
48 typedef BOOL (API * GHOST_WIN32_WTClose)(HCTX);
49 typedef BOOL (API * GHOST_WIN32_WTPacket)(HCTX, UINT, LPVOID);
50 typedef BOOL (API * GHOST_WIN32_WTEnable)(HCTX, BOOL);
51 typedef BOOL (API * GHOST_WIN32_WTOverlap)(HCTX, BOOL);
52
53 // typedef to user32 functions to disable gestures on windows
54 typedef BOOL(API * GHOST_WIN32_RegisterTouchWindow)(HWND hwnd, ULONG ulFlags);
55
56 // typedefs for user32 functions to allow dynamic loading of Windows 10 DPI scaling functions
57 typedef UINT(API * GHOST_WIN32_GetDpiForWindow)(HWND);
58 #ifndef USER_DEFAULT_SCREEN_DPI
59 #define USER_DEFAULT_SCREEN_DPI 96
60 #endif // USER_DEFAULT_SCREEN_DPI
61
62 // typedefs for user32 functions to allow pointer functions
63 enum tagPOINTER_INPUT_TYPE {
64         PT_POINTER = 1,   // Generic pointer
65         PT_TOUCH = 2,   // Touch
66         PT_PEN = 3,   // Pen
67         PT_MOUSE = 4,   // Mouse
68 #if(WINVER >= 0x0603)
69         PT_TOUCHPAD = 5,   // Touchpad
70 #endif /* WINVER >= 0x0603 */
71 };
72
73 typedef enum tagPOINTER_BUTTON_CHANGE_TYPE {
74         POINTER_CHANGE_NONE,
75         POINTER_CHANGE_FIRSTBUTTON_DOWN,
76         POINTER_CHANGE_FIRSTBUTTON_UP,
77         POINTER_CHANGE_SECONDBUTTON_DOWN,
78         POINTER_CHANGE_SECONDBUTTON_UP,
79         POINTER_CHANGE_THIRDBUTTON_DOWN,
80         POINTER_CHANGE_THIRDBUTTON_UP,
81         POINTER_CHANGE_FOURTHBUTTON_DOWN,
82         POINTER_CHANGE_FOURTHBUTTON_UP,
83         POINTER_CHANGE_FIFTHBUTTON_DOWN,
84         POINTER_CHANGE_FIFTHBUTTON_UP,
85 } POINTER_BUTTON_CHANGE_TYPE;
86
87 typedef DWORD POINTER_INPUT_TYPE;
88 typedef UINT32 POINTER_FLAGS;
89
90 typedef struct tagPOINTER_INFO {
91         POINTER_INPUT_TYPE    pointerType;
92         UINT32          pointerId;
93         UINT32          frameId;
94         POINTER_FLAGS   pointerFlags;
95         HANDLE          sourceDevice;
96         HWND            hwndTarget;
97         POINT           ptPixelLocation;
98         POINT           ptHimetricLocation;
99         POINT           ptPixelLocationRaw;
100         POINT           ptHimetricLocationRaw;
101         DWORD           dwTime;
102         UINT32          historyCount;
103         INT32           InputData;
104         DWORD           dwKeyStates;
105         UINT64          PerformanceCount;
106         POINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
107 } POINTER_INFO;
108
109 typedef UINT32 PEN_FLAGS;
110 #define PEN_FLAG_NONE                   0x00000000 // Default
111 #define PEN_FLAG_BARREL                 0x00000001 // The barrel button is pressed
112 #define PEN_FLAG_INVERTED               0x00000002 // The pen is inverted
113 #define PEN_FLAG_ERASER                 0x00000004 // The eraser button is pressed
114
115 typedef UINT32 PEN_MASK;
116 #define PEN_MASK_NONE                   0x00000000 // Default - none of the optional fields are valid
117 #define PEN_MASK_PRESSURE               0x00000001 // The pressure field is valid
118 #define PEN_MASK_ROTATION               0x00000002 // The rotation field is valid
119 #define PEN_MASK_TILT_X                 0x00000004 // The tiltX field is valid
120 #define PEN_MASK_TILT_Y                 0x00000008 // The tiltY field is valid
121
122 typedef struct tagPOINTER_PEN_INFO {
123         POINTER_INFO pointerInfo;
124         PEN_FLAGS    penFlags;
125         PEN_MASK     penMask;
126         UINT32       pressure;
127         UINT32       rotation;
128         INT32        tiltX;
129         INT32        tiltY;
130 } POINTER_PEN_INFO;
131
132 typedef BOOL (API * GHOST_WIN32_GetPointerInfo)(UINT32 pointerId, POINTER_INFO *pointerInfo);
133 typedef BOOL (API * GHOST_WIN32_GetPointerPenInfo)(UINT32 pointerId, POINTER_PEN_INFO *penInfo);
134
135 /**
136  * GHOST window on M$ Windows OSs.
137  */
138 class GHOST_WindowWin32 : public GHOST_Window {
139 public:
140         /**
141          * Constructor.
142          * Creates a new window and opens it.
143          * To check if the window was created properly, use the getValid() method.
144          * \param title         The text shown in the title bar of the window.
145          * \param left          The coordinate of the left edge of the window.
146          * \param top           The coordinate of the top edge of the window.
147          * \param width         The width the window.
148          * \param height        The height the window.
149          * \param state         The state the window is initially opened with.
150          * \param type          The type of drawing context installed in this window.
151          * \param wantStereoVisual   Stereo visual for quad buffered stereo.
152          * \param wantNumOfAASamples Number of samples used for AA (zero if no AA)
153          * \param parentWindowHwnd
154          */
155         GHOST_WindowWin32(GHOST_SystemWin32 *system,
156             const STR_String& title,
157             GHOST_TInt32 left,
158             GHOST_TInt32 top,
159             GHOST_TUns32 width,
160             GHOST_TUns32 height,
161             GHOST_TWindowState state,
162             GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
163             bool wantStereoVisual = false,
164             bool alphaBackground = false,
165             GHOST_TUns16 wantNumOfAASamples = 0,
166             GHOST_TEmbedderWindowID parentWindowHwnd = 0,
167             bool is_debug = false);
168
169         /**
170          * Destructor.
171          * Closes the window and disposes resources allocated.
172          */
173         ~GHOST_WindowWin32();
174
175         /**
176          * Returns indication as to whether the window is valid.
177          * \return The validity of the window.
178          */
179         bool getValid() const;
180
181         /**
182          * Access to the handle of the window.
183          * \return The handle of the window.
184          */
185         HWND getHWND() const;
186
187         /**
188          * Sets the title displayed in the title bar.
189          * \param title The title to display in the title bar.
190          */
191         void setTitle(const STR_String& title);
192
193         /**
194          * Returns the title displayed in the title bar.
195          * \param title The title displayed in the title bar.
196          */
197         void getTitle(STR_String& title) const;
198
199         /**
200          * Returns the window rectangle dimensions.
201          * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
202          * \param bounds The bounding rectangle of the window.
203          */
204         void getWindowBounds(GHOST_Rect& bounds) const;
205
206         /**
207          * Returns the client rectangle dimensions.
208          * The left and top members of the rectangle are always zero.
209          * \param bounds The bounding rectangle of the client area of the window.
210          */
211         void getClientBounds(GHOST_Rect& bounds) const;
212
213         /**
214          * Resizes client rectangle width.
215          * \param width The new width of the client area of the window.
216          */
217         GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
218
219         /**
220          * Resizes client rectangle height.
221          * \param height The new height of the client area of the window.
222          */
223         GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
224
225         /**
226          * Resizes client rectangle.
227          * \param width         The new width of the client area of the window.
228          * \param height        The new height of the client area of the window.
229          */
230         GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
231
232         /**
233          * Returns the state of the window (normal, minimized, maximized).
234          * \return The state of the window.
235          */
236         GHOST_TWindowState getState() const;
237
238         /**
239          * Converts a point in screen coordinates to client rectangle coordinates
240          * \param inX   The x-coordinate on the screen.
241          * \param inY   The y-coordinate on the screen.
242          * \param outX  The x-coordinate in the client rectangle.
243          * \param outY  The y-coordinate in the client rectangle.
244          */
245         void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
246
247         /**
248          * Converts a point in screen coordinates to client rectangle coordinates
249          * \param inX   The x-coordinate in the client rectangle.
250          * \param inY   The y-coordinate in the client rectangle.
251          * \param outX  The x-coordinate on the screen.
252          * \param outY  The y-coordinate on the screen.
253          */
254         void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
255
256         /**
257          * Sets the state of the window (normal, minimized, maximized).
258          * \param state The state of the window.
259          * \return Indication of success.
260          */
261         GHOST_TSuccess setState(GHOST_TWindowState state);
262
263         /**
264          * Sets the order of the window (bottom, top).
265          * \param order The order of the window.
266          * \return Indication of success.
267          */
268         GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
269
270         /**
271          * Invalidates the contents of this window.
272          */
273         GHOST_TSuccess invalidate();
274
275         /**
276          * Sets the progress bar value displayed in the window/application icon
277          * \param progress The progress %
278          */
279         GHOST_TSuccess setProgressBar(float progress);
280
281         /**
282          * Hides the progress bar in the icon
283          */
284         GHOST_TSuccess endProgressBar();
285
286
287         /**
288          * Register a mouse click event (should be called
289          * for any real button press, controls mouse
290          * capturing).
291          *
292          * \param press
293          *      0 - mouse pressed
294          *      1 - mouse released
295          *      2 - operator grab
296          *      3 - operator ungrab
297          */
298         void registerMouseClickEvent(int press);
299
300         /**
301          * Inform the window that it has lost mouse capture,
302          * called in response to native window system messages.
303          */
304         void lostMouseCapture();
305
306         /**
307          * Loads the windows equivalent of a standard GHOST cursor.
308          * \param visible               Flag for cursor visibility.
309          * \param cursorShape   The cursor shape.
310          */
311         void loadCursor(bool visible, GHOST_TStandardCursor cursorShape) const;
312
313         const GHOST_TabletData *GetTabletData()
314         {
315                 return &m_tabletData;
316         }
317
318         void processWin32PointerEvent(WPARAM wParam);
319         void processWin32TabletActivateEvent(WORD state);
320         void processWin32TabletInitEvent();
321         void processWin32TabletEvent(WPARAM wParam, LPARAM lParam);
322         void bringTabletContextToFront();
323
324         GHOST_TSuccess beginFullScreen() const {return GHOST_kFailure;}
325
326         GHOST_TSuccess endFullScreen() const {return GHOST_kFailure;}
327
328         GHOST_TUns16 getDPIHint() override;
329
330         /** if the window currently resizing */
331         bool m_inLiveResize;
332
333 #ifdef WITH_INPUT_IME
334         GHOST_ImeWin32 *getImeInput() {return &m_imeInput;}
335
336         void beginIME(
337                 GHOST_TInt32 x, GHOST_TInt32 y,
338                 GHOST_TInt32 w, GHOST_TInt32 h,
339                 int completed);
340
341         void endIME();
342 #endif /* WITH_INPUT_IME */
343
344 private:
345
346         /**
347          * \param type  The type of rendering context create.
348          * \return Indication of success.
349          */
350         GHOST_Context *newDrawingContext(GHOST_TDrawingContextType type);
351
352         /**
353          * Sets the cursor visibility on the window using
354          * native window system calls.
355          */
356         GHOST_TSuccess setWindowCursorVisibility(bool visible);
357
358         /**
359          * Sets the cursor grab on the window using native window system calls.
360          * Using registerMouseClickEvent.
361          * \param mode  GHOST_TGrabCursorMode.
362          */
363         GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
364
365         /**
366          * Sets the cursor shape on the window using
367          * native window system calls.
368          */
369         GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
370
371         /**
372          * Sets the cursor shape on the window using
373          * native window system calls.
374          */
375         GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2],
376                                                           GHOST_TUns8 mask[16][2],
377                                                           int hotX, int hotY);
378
379         GHOST_TSuccess setWindowCustomCursorShape(
380             GHOST_TUns8 *bitmap,
381             GHOST_TUns8 *mask,
382             int sizex,
383             int sizey,
384             int hotX,
385             int hotY,
386             int fg_color,
387             int bg_color
388             );
389
390         /** Pointer to system */
391         GHOST_SystemWin32 *m_system;
392         /** Pointer to COM IDropTarget implementor */
393         GHOST_DropTargetWin32 *m_dropTarget;
394         /** Window handle. */
395         HWND m_hWnd;
396         /** Device context handle. */
397         HDC m_hDC;
398
399         /** Flag for if window has captured the mouse */
400         bool m_hasMouseCaptured;
401         /** Flag if an operator grabs the mouse with WM_cursor_grab_enable/ungrab()
402          * Multiple grabs must be released with a single ungrab */
403         bool m_hasGrabMouse;
404         /** Count of number of pressed buttons */
405         int m_nPressedButtons;
406         /** HCURSOR structure of the custom cursor */
407         HCURSOR m_customCursor;
408         /** request GL context aith alpha channel */
409         bool m_wantAlphaBackground;
410
411         /** ITaskbarList3 structure for progress bar*/
412         ITaskbarList3 *m_Bar;
413
414         static const wchar_t *s_windowClassName;
415         static const int s_maxTitleLength;
416
417         /** Tablet data for GHOST */
418         GHOST_TabletData m_tabletData;
419
420         /* Wintab API */
421         struct {
422                 /** WinTab dll handle */
423                 HMODULE handle;
424
425                 /** API functions */
426                 GHOST_WIN32_WTInfo info;
427                 GHOST_WIN32_WTOpen open;
428                 GHOST_WIN32_WTClose close;
429                 GHOST_WIN32_WTPacket packet;
430                 GHOST_WIN32_WTEnable enable;
431                 GHOST_WIN32_WTOverlap overlap;
432
433                 /** Stores the Tablet context if detected Tablet features using WinTab.dll */
434                 HCTX tablet;
435                 LONG maxPressure;
436                 LONG maxAzimuth, maxAltitude;
437         } m_wintab;
438
439         GHOST_TWindowState m_normal_state;
440
441         /** user32 dll handle*/
442         HMODULE m_user32;
443         GHOST_WIN32_GetPointerInfo m_fpGetPointerInfo;
444         GHOST_WIN32_GetPointerPenInfo m_fpGetPointerPenInfo;
445
446         /** Hwnd to parent window */
447         GHOST_TEmbedderWindowID m_parentWindowHwnd;
448
449 #ifdef WITH_INPUT_IME
450         /** Handle input method editors event */
451         GHOST_ImeWin32 m_imeInput;
452 #endif
453         bool m_debug_context;
454 };
455
456 #endif // __GHOST_WINDOWWIN32_H__