Blender  V2.59
GHOST_SystemWin32.h
Go to the documentation of this file.
00001 /*
00002  * $Id: GHOST_SystemWin32.h 39110 2011-08-06 23:13:36Z merwin $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #ifndef _GHOST_SYSTEM_WIN32_H_
00035 #define _GHOST_SYSTEM_WIN32_H_
00036 
00037 #ifndef WIN32
00038 #error WIN32 only!
00039 #endif // WIN32
00040 
00041 #define _WIN32_WINNT 0x501 // require Windows XP or newer
00042 #define WIN32_LEAN_AND_MEAN
00043 #include <windows.h>
00044 #include <ole2.h> // for drag-n-drop
00045 
00046 #include "GHOST_System.h"
00047 
00048 #if defined(__CYGWIN32__)
00049 #       define __int64 long long
00050 #endif
00051 
00052 class GHOST_EventButton;
00053 class GHOST_EventCursor;
00054 class GHOST_EventKey;
00055 class GHOST_EventWheel;
00056 class GHOST_EventWindow;
00057 class GHOST_EventDragnDrop;
00058 
00065 class GHOST_SystemWin32 : public GHOST_System {
00066 public:
00070         GHOST_SystemWin32();
00071 
00075         virtual ~GHOST_SystemWin32();
00076 
00077         /***************************************************************************************
00078          ** Time(r) functionality
00079          ***************************************************************************************/
00080 
00087         virtual GHOST_TUns64 getMilliSeconds() const;
00088 
00089         /***************************************************************************************
00090          ** Display/window management functionality
00091          ***************************************************************************************/
00092 
00097         virtual GHOST_TUns8 getNumDisplays() const;
00098 
00103         virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
00104         
00121         virtual GHOST_IWindow* createWindow(
00122                 const STR_String& title,
00123                 GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
00124                 GHOST_TWindowState state, GHOST_TDrawingContextType type,
00125                 const bool stereoVisual = false,
00126                 const GHOST_TUns16 numOfAASamples = 0,
00127                 const GHOST_TEmbedderWindowID parentWindow = 0 );
00128 
00129         /***************************************************************************************
00130          ** Event management functionality
00131          ***************************************************************************************/
00132 
00138         virtual bool processEvents(bool waitForEvent);
00139         
00140 
00141         /***************************************************************************************
00142          ** Cursor management functionality
00143          ***************************************************************************************/
00144 
00151         virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
00152 
00159         virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
00160 
00161         /***************************************************************************************
00162          ** Access to mouse button and keyboard states.
00163          ***************************************************************************************/
00164 
00170         virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
00171 
00177         virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
00178 
00184         virtual GHOST_TUns8* getClipboard(bool selection) const;
00185         
00191         virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
00192 
00203         static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,GHOST_IWindow* window, int mouseX, int mouseY, void* data);
00204          
00205 protected:
00211         virtual GHOST_TSuccess init();
00212 
00217         virtual GHOST_TSuccess exit();
00218         
00227         virtual GHOST_TKey convertKey(GHOST_IWindow *window, short vKey, short ScanCode, short extend) const;
00228 
00237         virtual GHOST_TKey hardKey(GHOST_IWindow *window, RAWINPUT const& raw, int * keyDown, char * vk);
00238 
00246         GHOST_EventKey* processModifierKeys(GHOST_IWindow *window);
00247 
00255         static GHOST_EventButton* processButtonEvent(GHOST_TEventType type, GHOST_IWindow *window, GHOST_TButtonMask mask);
00256 
00263         static GHOST_EventCursor* processCursorEvent(GHOST_TEventType type, GHOST_IWindow *Iwindow);
00264 
00271         static GHOST_EventWheel* processWheelEvent(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam);
00272 
00280         static GHOST_EventKey* processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw);
00281 
00289         virtual GHOST_TKey processSpecialKey(GHOST_IWindow *window, short vKey, short scanCode) const;
00290 
00297         static GHOST_Event* processWindowEvent(GHOST_TEventType type, GHOST_IWindow* window);
00298 
00303         static void processMinMaxInfo(MINMAXINFO * minmax);
00304 
00305 #ifdef WITH_INPUT_NDOF
00306 
00313         bool processNDOF(RAWINPUT const& raw);
00314 #endif
00315 
00320         inline virtual void retrieveModifierKeys(GHOST_ModifierKeys& keys) const;
00321 
00327         inline virtual void storeModifierKeys(const GHOST_ModifierKeys& keys);
00328         
00332         inline virtual void handleKeyboardChange(void);
00333 
00337         static LRESULT WINAPI s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
00338 
00348         int toggleConsole(int action);
00349         
00351         GHOST_ModifierKeys m_modifierKeys;
00353         bool m_hasPerformanceCounter;
00355         __int64 m_freq;
00357         __int64 m_start;
00359         bool m_hasAltGr;
00361         WORD m_langId;
00363         HKL m_keylayout;
00364 
00366         int m_consoleStatus;
00367 };
00368 
00369 inline void GHOST_SystemWin32::retrieveModifierKeys(GHOST_ModifierKeys& keys) const
00370 {
00371         keys = m_modifierKeys;
00372 }
00373 
00374 inline void GHOST_SystemWin32::storeModifierKeys(const GHOST_ModifierKeys& keys)
00375 {
00376         m_modifierKeys = keys;
00377 }
00378 
00379 inline void GHOST_SystemWin32::handleKeyboardChange(void)
00380 {
00381         m_keylayout = GetKeyboardLayout(0); // get keylayout for current thread
00382         int i;
00383         SHORT s;
00384 
00385         // save the language identifier.
00386         m_langId = LOWORD(m_keylayout);
00387 
00388         for(m_hasAltGr = false, i = 32; i < 256; ++i) {
00389                 s = VkKeyScanEx((char)i, m_keylayout);
00390                 // s == -1 means no key that translates passed char code
00391                 // high byte contains shift state. bit 2 ctrl pressed, bit 4 alt pressed
00392                 // if both are pressed, we have AltGr keycombo on keylayout
00393                 if(s!=-1 && (s & 0x600) == 0x600) {
00394                         m_hasAltGr = true;
00395                         break;
00396                 }
00397         }
00398 }
00399 #endif // _GHOST_SYSTEM_WIN32_H_