3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
29 * @file GHOST_WindowWin32.h
30 * Declaration of GHOST_WindowWin32 class.
33 #ifndef _GHOST_WINDOW_WIN32_H_
34 #define _GHOST_WINDOW_WIN32_H_
40 #include "GHOST_Window.h"
46 #define PACKETDATA (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR)
47 #define PACKETMODE PK_BUTTONS
50 class GHOST_SystemWin32;
51 class GHOST_DropTargetWin32;
53 // typedefs for WinTab functions to allow dynamic loading
54 typedef UINT (API * GHOST_WIN32_WTInfo) ( UINT, UINT, LPVOID );
55 typedef HCTX (API * GHOST_WIN32_WTOpen) (HWND, LPLOGCONTEXTA, BOOL);
56 typedef BOOL (API * GHOST_WIN32_WTClose) (HCTX);
57 typedef BOOL (API * GHOST_WIN32_WTPacket) (HCTX, UINT, LPVOID);
60 * GHOST window on M$ Windows OSs.
61 * @author Maarten Gribnau
64 class GHOST_WindowWin32 : public GHOST_Window {
68 * Creates a new window and opens it.
69 * To check if the window was created properly, use the getValid() method.
70 * @param title The text shown in the title bar of the window.
71 * @param left The coordinate of the left edge of the window.
72 * @param top The coordinate of the top edge of the window.
73 * @param width The width the window.
74 * @param height The height the window.
75 * @param state The state the window is initially opened with.
76 * @param type The type of drawing context installed in this window.
77 * @param stereoVisual Stereo visual for quad buffered stereo.
78 * @param numOfAASamples Number of samples used for AA (zero if no AA)
81 GHOST_SystemWin32 * system,
82 const STR_String& title,
87 GHOST_TWindowState state,
88 GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
89 const bool stereoVisual = false,
90 const GHOST_TUns16 numOfAASamples = 0,
91 GHOST_TSuccess msEnabled = GHOST_kFailure,
97 * Closes the window and disposes resources allocated.
99 virtual ~GHOST_WindowWin32();
102 * Returns the window to replace this one if it's getting replaced
103 * @return The window replacing this one.
106 GHOST_Window *getNextWindow();
109 * Returns indication as to whether the window is valid.
110 * @return The validity of the window.
112 virtual bool getValid() const;
115 * Access to the handle of the window.
116 * @return The handle of the window.
118 virtual HWND getHWND() const;
121 * Sets the title displayed in the title bar.
122 * @param title The title to display in the title bar.
124 virtual void setTitle(const STR_String& title);
127 * Returns the title displayed in the title bar.
128 * @param title The title displayed in the title bar.
130 virtual void getTitle(STR_String& title) const;
133 * Returns the window rectangle dimensions.
134 * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
135 * @param bounds The bounding rectangle of the window.
137 virtual void getWindowBounds(GHOST_Rect& bounds) const;
140 * Returns the client rectangle dimensions.
141 * The left and top members of the rectangle are always zero.
142 * @param bounds The bounding rectangle of the cleient area of the window.
144 virtual void getClientBounds(GHOST_Rect& bounds) const;
147 * Resizes client rectangle width.
148 * @param width The new width of the client area of the window.
150 virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
153 * Resizes client rectangle height.
154 * @param height The new height of the client area of the window.
156 virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
159 * Resizes client rectangle.
160 * @param width The new width of the client area of the window.
161 * @param height The new height of the client area of the window.
163 virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
166 * Returns the state of the window (normal, minimized, maximized).
167 * @return The state of the window.
169 virtual GHOST_TWindowState getState() const;
172 * Converts a point in screen coordinates to client rectangle coordinates
173 * @param inX The x-coordinate on the screen.
174 * @param inY The y-coordinate on the screen.
175 * @param outX The x-coordinate in the client rectangle.
176 * @param outY The y-coordinate in the client rectangle.
178 virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
181 * Converts a point in screen coordinates to client rectangle coordinates
182 * @param inX The x-coordinate in the client rectangle.
183 * @param inY The y-coordinate in the client rectangle.
184 * @param outX The x-coordinate on the screen.
185 * @param outY The y-coordinate on the screen.
187 virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
190 * Sets the state of the window (normal, minimized, maximized).
191 * @param state The state of the window.
192 * @return Indication of success.
194 virtual GHOST_TSuccess setState(GHOST_TWindowState state);
197 * Sets the order of the window (bottom, top).
198 * @param order The order of the window.
199 * @return Indication of success.
201 virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
204 * Swaps front and back buffers of a window.
205 * @return Indication of success.
207 virtual GHOST_TSuccess swapBuffers();
210 * Activates the drawing context of this window.
211 * @return Indication of success.
213 virtual GHOST_TSuccess activateDrawingContext();
216 * Invalidates the contents of this window.
218 virtual GHOST_TSuccess invalidate();
221 * Returns the name of the window class.
222 * @return The name of the window class.
224 static LPCSTR getWindowClassName() { return s_windowClassName; }
227 * Register a mouse click event (should be called
228 * for any real button press, controls mouse
231 * @param press True the event was a button press.
233 void registerMouseClickEvent(bool press);
236 * Inform the window that it has lost mouse capture,
237 * called in response to native window system messages.
239 void lostMouseCapture();
242 * Loads the windows equivalent of a standard GHOST cursor.
243 * @param visible Flag for cursor visibility.
244 * @param cursorShape The cursor shape.
246 void loadCursor(bool visible, GHOST_TStandardCursor cursorShape) const;
248 const GHOST_TabletData* GetTabletData()
249 { return m_tabletData; }
251 void processWin32TabletInitEvent();
252 void processWin32TabletEvent(WPARAM wParam, LPARAM lParam);
255 GHOST_TSuccess initMultisample(PIXELFORMATDESCRIPTOR pfd);
258 * Tries to install a rendering context in this window.
259 * @param type The type of rendering context installed.
260 * @return Indication of success.
262 virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
265 * Removes the current drawing context.
266 * @return Indication of success.
268 virtual GHOST_TSuccess removeDrawingContext();
271 * Sets the cursor visibility on the window using
272 * native window system calls.
274 virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
277 * Sets the cursor grab on the window using native window system calls.
278 * Using registerMouseClickEvent.
279 * @param mode GHOST_TGrabCursorMode.
281 virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
284 * Sets the cursor shape on the window using
285 * native window system calls.
287 virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
290 * Sets the cursor shape on the window using
291 * native window system calls.
293 virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
295 virtual GHOST_TSuccess setWindowCustomCursorShape(
306 /** Pointer to system */
307 GHOST_SystemWin32 * m_system;
308 /** Pointer to COM IDropTarget implementor */
309 GHOST_DropTargetWin32 * m_dropTarget;
310 /** Window handle. */
312 /** Device context handle. */
314 /** OpenGL rendering context. */
316 /** The first created OpenGL context (for sharing display lists) */
317 static HGLRC s_firsthGLRc;
318 /** The first created device context handle. */
319 static HDC s_firstHDC;
320 /** Flag for if window has captured the mouse */
321 bool m_hasMouseCaptured;
322 /** Count of number of pressed buttons */
323 int m_nPressedButtons;
324 /** HCURSOR structure of the custom cursor */
325 HCURSOR m_customCursor;
327 static LPCSTR s_windowClassName;
328 static const int s_maxTitleLength;
330 /** WinTab dll handle */
333 /** Tablet data for GHOST */
334 GHOST_TabletData* m_tabletData;
336 /** Stores the Tablet context if detected Tablet features using WinTab.dll */
339 LONG m_maxAzimuth, m_maxAltitude;
341 /** Preferred number of samples */
342 GHOST_TUns16 m_multisample;
344 /** Check if multisample is supported */
345 GHOST_TSuccess m_multisampleEnabled;
347 /** The pixelFormat to use for multisample */
350 /** We need to following to recreate the window */
351 const STR_String& m_title;
354 GHOST_TUns32 m_width;
355 GHOST_TUns32 m_height;
356 GHOST_TWindowState m_normal_state;
359 /** The GHOST_System passes this to wm if this window is being replaced */
360 GHOST_Window *m_nextWindow;
363 #endif // _GHOST_WINDOW_WIN32_H_