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"
53 #include "GHOST_TaskbarWin32.h"
57 #define PACKETDATA (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR)
58 #define PACKETMODE PK_BUTTONS
61 class GHOST_SystemWin32;
62 class GHOST_DropTargetWin32;
64 // typedefs for WinTab functions to allow dynamic loading
65 typedef UINT (API * GHOST_WIN32_WTInfo) ( UINT, UINT, LPVOID );
66 typedef HCTX (API * GHOST_WIN32_WTOpen) (HWND, LPLOGCONTEXTA, BOOL);
67 typedef BOOL (API * GHOST_WIN32_WTClose) (HCTX);
68 typedef BOOL (API * GHOST_WIN32_WTPacket) (HCTX, UINT, LPVOID);
71 * GHOST window on M$ Windows OSs.
72 * @author Maarten Gribnau
75 class GHOST_WindowWin32 : public GHOST_Window {
79 * Creates a new window and opens it.
80 * To check if the window was created properly, use the getValid() method.
81 * @param title The text shown in the title bar of the window.
82 * @param left The coordinate of the left edge of the window.
83 * @param top The coordinate of the top edge of the window.
84 * @param width The width the window.
85 * @param height The height the window.
86 * @param state The state the window is initially opened with.
87 * @param type The type of drawing context installed in this window.
88 * @param stereoVisual Stereo visual for quad buffered stereo.
89 * @param numOfAASamples Number of samples used for AA (zero if no AA)
92 GHOST_SystemWin32 * system,
93 const STR_String& title,
98 GHOST_TWindowState state,
99 GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
100 const bool stereoVisual = false,
101 const GHOST_TUns16 numOfAASamples = 0,
102 GHOST_TSuccess msEnabled = GHOST_kFailure,
103 int msPixelFormat = 0
108 * Closes the window and disposes resources allocated.
110 virtual ~GHOST_WindowWin32();
113 * Returns the window to replace this one if it's getting replaced
114 * @return The window replacing this one.
117 GHOST_Window *getNextWindow();
120 * Returns indication as to whether the window is valid.
121 * @return The validity of the window.
123 virtual bool getValid() const;
126 * Access to the handle of the window.
127 * @return The handle of the window.
129 virtual HWND getHWND() const;
132 * Sets the title displayed in the title bar.
133 * @param title The title to display in the title bar.
135 virtual void setTitle(const STR_String& title);
138 * Returns the title displayed in the title bar.
139 * @param title The title displayed in the title bar.
141 virtual void getTitle(STR_String& title) const;
144 * Returns the window rectangle dimensions.
145 * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
146 * @param bounds The bounding rectangle of the window.
148 virtual void getWindowBounds(GHOST_Rect& bounds) const;
151 * Returns the client rectangle dimensions.
152 * The left and top members of the rectangle are always zero.
153 * @param bounds The bounding rectangle of the cleient area of the window.
155 virtual void getClientBounds(GHOST_Rect& bounds) const;
158 * Resizes client rectangle width.
159 * @param width The new width of the client area of the window.
161 virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
164 * Resizes client rectangle height.
165 * @param height The new height of the client area of the window.
167 virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
170 * Resizes client rectangle.
171 * @param width The new width of the client area of the window.
172 * @param height The new height of the client area of the window.
174 virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
177 * Returns the state of the window (normal, minimized, maximized).
178 * @return The state of the window.
180 virtual GHOST_TWindowState getState() const;
183 * Converts a point in screen coordinates to client rectangle coordinates
184 * @param inX The x-coordinate on the screen.
185 * @param inY The y-coordinate on the screen.
186 * @param outX The x-coordinate in the client rectangle.
187 * @param outY The y-coordinate in the client rectangle.
189 virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
192 * Converts a point in screen coordinates to client rectangle coordinates
193 * @param inX The x-coordinate in the client rectangle.
194 * @param inY The y-coordinate in the client rectangle.
195 * @param outX The x-coordinate on the screen.
196 * @param outY The y-coordinate on the screen.
198 virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
201 * Sets the state of the window (normal, minimized, maximized).
202 * @param state The state of the window.
203 * @return Indication of success.
205 virtual GHOST_TSuccess setState(GHOST_TWindowState state);
208 * Sets the order of the window (bottom, top).
209 * @param order The order of the window.
210 * @return Indication of success.
212 virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
215 * Swaps front and back buffers of a window.
216 * @return Indication of success.
218 virtual GHOST_TSuccess swapBuffers();
221 * Activates the drawing context of this window.
222 * @return Indication of success.
224 virtual GHOST_TSuccess activateDrawingContext();
227 * Invalidates the contents of this window.
229 virtual GHOST_TSuccess invalidate();
232 * Sets the progress bar value displayed in the window/application icon
233 * @param progress The progress %
235 virtual GHOST_TSuccess setProgressBar(float progress);
238 * Hides the progress bar in the icon
240 virtual GHOST_TSuccess endProgressBar();
243 * Returns the name of the window class.
244 * @return The name of the window class.
246 static LPCSTR getWindowClassName() { return s_windowClassName; }
249 * Register a mouse click event (should be called
250 * for any real button press, controls mouse
253 * @param press True the event was a button press.
255 void registerMouseClickEvent(bool press);
258 * Inform the window that it has lost mouse capture,
259 * called in response to native window system messages.
261 void lostMouseCapture();
264 * Loads the windows equivalent of a standard GHOST cursor.
265 * @param visible Flag for cursor visibility.
266 * @param cursorShape The cursor shape.
268 void loadCursor(bool visible, GHOST_TStandardCursor cursorShape) const;
270 const GHOST_TabletData* GetTabletData()
271 { return m_tabletData; }
273 void processWin32TabletInitEvent();
274 void processWin32TabletEvent(WPARAM wParam, LPARAM lParam);
277 GHOST_TSuccess initMultisample(PIXELFORMATDESCRIPTOR pfd);
280 * Tries to install a rendering context in this window.
281 * @param type The type of rendering context installed.
282 * @return Indication of success.
284 virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
287 * Removes the current drawing context.
288 * @return Indication of success.
290 virtual GHOST_TSuccess removeDrawingContext();
293 * Sets the cursor visibility on the window using
294 * native window system calls.
296 virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
299 * Sets the cursor grab on the window using native window system calls.
300 * Using registerMouseClickEvent.
301 * @param mode GHOST_TGrabCursorMode.
303 virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
306 * Sets the cursor shape on the window using
307 * native window system calls.
309 virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
312 * Sets the cursor shape on the window using
313 * native window system calls.
315 virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
317 virtual GHOST_TSuccess setWindowCustomCursorShape(
328 /** Pointer to system */
329 GHOST_SystemWin32 * m_system;
330 /** Pointer to COM IDropTarget implementor */
331 GHOST_DropTargetWin32 * m_dropTarget;
332 /** Window handle. */
334 /** Device context handle. */
336 /** OpenGL rendering context. */
338 /** The first created OpenGL context (for sharing display lists) */
339 static HGLRC s_firsthGLRc;
340 /** The first created device context handle. */
341 static HDC s_firstHDC;
342 /** Flag for if window has captured the mouse */
343 bool m_hasMouseCaptured;
344 /** Count of number of pressed buttons */
345 int m_nPressedButtons;
346 /** HCURSOR structure of the custom cursor */
347 HCURSOR m_customCursor;
349 /** ITaskbarList3 structure for progress bar*/
350 ITaskbarList3 * m_Bar;
352 static LPCSTR s_windowClassName;
353 static const int s_maxTitleLength;
355 /** WinTab dll handle */
358 /** Tablet data for GHOST */
359 GHOST_TabletData* m_tabletData;
361 /** Stores the Tablet context if detected Tablet features using WinTab.dll */
364 LONG m_maxAzimuth, m_maxAltitude;
366 /** Preferred number of samples */
367 GHOST_TUns16 m_multisample;
369 /** Check if multisample is supported */
370 GHOST_TSuccess m_multisampleEnabled;
372 /** The pixelFormat to use for multisample */
375 /** We need to following to recreate the window */
376 const STR_String& m_title;
379 GHOST_TUns32 m_width;
380 GHOST_TUns32 m_height;
381 GHOST_TWindowState m_normal_state;
384 /** The GHOST_System passes this to wm if this window is being replaced */
385 GHOST_Window *m_nextWindow;
388 #endif // _GHOST_WINDOW_WIN32_H_