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_SystemWin32.h
30 * Declaration of GHOST_SystemWin32 class.
33 #ifndef _GHOST_SYSTEM_WIN32_H_
34 #define _GHOST_SYSTEM_WIN32_H_
42 #include "GHOST_System.h"
44 #if defined(__CYGWIN32__)
45 # define __int64 long long
49 class GHOST_EventButton;
50 class GHOST_EventCursor;
52 class GHOST_EventWheel;
53 class GHOST_EventWindow;
54 class GHOST_EventDragnDrop;
57 * WIN32 Implementation of GHOST_System class.
59 * @author Maarten Gribnau
62 class GHOST_SystemWin32 : public GHOST_System {
72 virtual ~GHOST_SystemWin32();
74 /***************************************************************************************
75 ** Time(r) functionality
76 ***************************************************************************************/
79 * Returns the system time.
80 * Returns the number of milliseconds since the start of the system process.
81 * This overloaded method uses the high frequency timer if available.
82 * @return The number of milliseconds.
84 virtual GHOST_TUns64 getMilliSeconds() const;
86 /***************************************************************************************
87 ** Display/window management functionality
88 ***************************************************************************************/
91 * Returns the number of displays on this system.
92 * @return The number of displays.
94 virtual GHOST_TUns8 getNumDisplays() const;
97 * Returns the dimensions of the main display on this system.
98 * @return The dimension of the main display.
100 virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
103 * Create a new window.
104 * The new window is added to the list of windows managed.
105 * Never explicitly delete the window, use disposeWindow() instead.
106 * @param title The name of the window (displayed in the title bar of the window if the OS supports it).
107 * @param left The coordinate of the left edge of the window.
108 * @param top The coordinate of the top edge of the window.
109 * @param width The width the window.
110 * @param height The height the window.
111 * @param state The state of the window when opened.
112 * @param type The type of drawing context installed in this window.
113 * @param stereoVisual Stereo visual for quad buffered stereo.
114 * @param numOfAASamples Number of samples used for AA (zero if no AA)
115 * @param parentWindow Parent (embedder) window
116 * @return The new window (or 0 if creation failed).
118 virtual GHOST_IWindow* createWindow(
119 const STR_String& title,
120 GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
121 GHOST_TWindowState state, GHOST_TDrawingContextType type,
122 const bool stereoVisual = false,
123 const GHOST_TUns16 numOfAASamples = 0,
124 const GHOST_TEmbedderWindowID parentWindow = 0 );
126 /***************************************************************************************
127 ** Event management functionality
128 ***************************************************************************************/
131 * Gets events from the system and stores them in the queue.
132 * @param waitForEvent Flag to wait for an event (or return immediately).
133 * @return Indication of the presence of events.
135 virtual bool processEvents(bool waitForEvent);
138 /***************************************************************************************
139 ** Cursor management functionality
140 ***************************************************************************************/
143 * Returns the current location of the cursor (location in screen coordinates)
144 * @param x The x-coordinate of the cursor.
145 * @param y The y-coordinate of the cursor.
146 * @return Indication of success.
148 virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
151 * Updates the location of the cursor (location in screen coordinates).
152 * @param x The x-coordinate of the cursor.
153 * @param y The y-coordinate of the cursor.
154 * @return Indication of success.
156 virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
158 /***************************************************************************************
159 ** Access to mouse button and keyboard states.
160 ***************************************************************************************/
163 * Returns the state of all modifier keys.
164 * @param keys The state of all modifier keys (true == pressed).
165 * @return Indication of success.
167 virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
170 * Returns the state of the mouse buttons (ouside the message queue).
171 * @param buttons The state of the buttons.
172 * @return Indication of success.
174 virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
177 * Returns unsinged char from CUT_BUFFER0
178 * @param selection Used by X11 only
179 * @return Returns the Clipboard
181 virtual GHOST_TUns8* getClipboard(bool selection) const;
184 * Puts buffer to system clipboard
185 * @param selection Used by X11 only
188 virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
191 * Determine the base dir in which shared resources are located. It will first try to use
192 * "unpack and run" path, then look for properly installed path, not including versioning.
193 * @return Unsigned char string pointing to system dir (eg /usr/share/).
195 virtual const GHOST_TUns8* getSystemDir() const;
198 * Determine the base dir in which user configuration is stored, not including versioning.
199 * If needed, it will create the base directory.
200 * @return Unsigned char string pointing to user dir (eg ~/).
202 virtual const GHOST_TUns8* getUserDir() const;
205 * Determine the directory of the current binary
206 * @return Unsigned char string pointing to the binary dir
208 virtual const GHOST_TUns8* getBinaryDir() const;
211 * Creates a drag'n'drop event and pushes it immediately onto the event queue.
212 * Called by GHOST_DropTargetWin32 class.
213 * @param eventType The type of drag'n'drop event
214 * @param draggedObjectType The type object concerned (currently array of file names, string, ?bitmap)
215 * @param mouseX x mouse coordinate (in window coordinates)
216 * @param mouseY y mouse coordinate
217 * @param window The window on which the event occurred
218 * @return Indication whether the event was handled.
220 static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,GHOST_IWindow* window, int mouseX, int mouseY, void* data);
224 * Initializes the system.
225 * For now, it justs registers the window class (WNDCLASS).
226 * @return A success value.
228 virtual GHOST_TSuccess init();
231 * Closes the system down.
232 * @return A success value.
234 virtual GHOST_TSuccess exit();
237 * Converts raw WIN32 key codes from the wndproc to GHOST keys.
238 * @param wParam The wParam from the wndproc
239 * @param lParam The lParam from the wndproc
240 * @return The GHOST key (GHOST_kKeyUnknown if no match).
242 virtual GHOST_TKey convertKey(WPARAM wParam, LPARAM lParam) const;
245 * Creates modifier key event(s) and updates the key data stored locally (m_modifierKeys).
246 * With the modifier keys, we want to distinguish left and right keys.
247 * Sometimes this is not possible (Windows ME for instance). Then, we want
248 * events generated for both keys.
249 * @param window The window receiving the event (the active window).
251 GHOST_EventKey* processModifierKeys(GHOST_IWindow *window);
254 * Creates mouse button event.
255 * @param type The type of event to create.
256 * @param window The window receiving the event (the active window).
257 * @param mask The button mask of this event.
258 * @return The event created.
260 static GHOST_EventButton* processButtonEvent(GHOST_TEventType type, GHOST_IWindow *window, GHOST_TButtonMask mask);
263 * Creates cursor event.
264 * @param type The type of event to create.
265 * @param window The window receiving the event (the active window).
266 * @return The event created.
268 static GHOST_EventCursor* processCursorEvent(GHOST_TEventType type, GHOST_IWindow *Iwindow);
271 * Creates a mouse wheel event.
272 * @param window The window receiving the event (the active window).
273 * @param wParam The wParam from the wndproc
274 * @param lParam The lParam from the wndproc
276 static GHOST_EventWheel* processWheelEvent(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam);
279 * Creates a key event and updates the key data stored locally (m_modifierKeys).
280 * In most cases this is a straightforward conversion of key codes.
281 * For the modifier keys however, we want to distinguish left and right keys.
282 * @param window The window receiving the event (the active window).
283 * @param wParam The wParam from the wndproc
284 * @param lParam The lParam from the wndproc
286 static GHOST_EventKey* processKeyEvent(GHOST_IWindow *window, bool keyDown, WPARAM wParam, LPARAM lParam);
289 * Creates a window event.
290 * @param type The type of event to create.
291 * @param window The window receiving the event (the active window).
292 * @return The event created.
294 static GHOST_Event* processWindowEvent(GHOST_TEventType type, GHOST_IWindow* window);
296 * Handles minimum window size.
297 * @param minmax The MINMAXINFO structure.
299 static void processMinMaxInfo(MINMAXINFO * minmax);
302 * Returns the local state of the modifier keys (from the message queue).
303 * @param keys The state of the keys.
305 inline virtual void retrieveModifierKeys(GHOST_ModifierKeys& keys) const;
308 * Stores the state of the modifier keys locally.
309 * For internal use only!
310 * @param keys The new state of the modifier keys.
312 inline virtual void storeModifierKeys(const GHOST_ModifierKeys& keys);
315 * Windows call back routine for our window class.
317 static LRESULT WINAPI s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
319 /** The current state of the modifier keys. */
320 GHOST_ModifierKeys m_modifierKeys;
321 /** State variable set at initialization. */
322 bool m_hasPerformanceCounter;
323 /** High frequency timer variable. */
325 /** High frequency timer variable. */
329 inline void GHOST_SystemWin32::retrieveModifierKeys(GHOST_ModifierKeys& keys) const
331 keys = m_modifierKeys;
334 inline void GHOST_SystemWin32::storeModifierKeys(const GHOST_ModifierKeys& keys)
336 m_modifierKeys = keys;
339 #endif // _GHOST_SYSTEM_WIN32_H_