win32Window.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _WINDOWMANAGER_WIN32_WIN32WINDOW_
  23. #define _WINDOWMANAGER_WIN32_WIN32WINDOW_
  24. #include <windows.h>
  25. #include "windowManager/platformWindowMgr.h"
  26. #include "gfx/gfxTarget.h"
  27. #include "gfx/gfxStructs.h"
  28. #include "sim/actionMap.h"
  29. class Win32WindowManager;
  30. class GFXGLDevice;
  31. /// Implementation of a window on Win32.
  32. class Win32Window : public PlatformWindow
  33. {
  34. friend class Win32WindowManager;
  35. friend class GFXPCD3D9Device;
  36. friend class GFXGLDevice;
  37. friend class GFXPCD3D9WindowTarget;
  38. friend class GFXD3D8WindowTarget;
  39. public:
  40. struct Accelerator
  41. {
  42. U32 mID;
  43. EventDescriptor mDescriptor;
  44. };
  45. typedef Vector<Accelerator> AcceleratorList;
  46. private:
  47. typedef Vector<ACCEL> WinAccelList;
  48. /// @name Active window list
  49. ///
  50. /// Items used to track window instances.
  51. ///
  52. /// @{
  53. /// Which manager created us?
  54. Win32WindowManager *mOwningManager;
  55. /// Which window comes next in list?
  56. Win32Window *mNextWindow;
  57. /// @}
  58. /// @name Window Information
  59. ///
  60. /// @{
  61. /// Our HWND - Win32 window handle.
  62. HWND mWindowHandle;
  63. /// Our former Parent HWND
  64. HWND mOldParent;
  65. /// The Win32 window style we want to use when windowed.
  66. DWORD mWindowedWindowStyle;
  67. /// The GFX device that we're tied to.
  68. GFXDevice *mDevice;
  69. /// Reference to the render target allocated on this window.
  70. GFXWindowTargetRef mTarget;
  71. /// Our current size/resolution/fullscreen status.
  72. GFXVideoMode mVideoMode;
  73. /// Our position on the desktop.
  74. Point2I mPosition;
  75. /// Windows HACCEL for accelerators
  76. HACCEL mAccelHandle;
  77. /// Keyboard accelerators for menus
  78. WinAccelList mWinAccelList;
  79. /// Is the mouse locked to this window?
  80. bool mMouseLocked;
  81. /// The position the cursor was at when a mouse lock occured
  82. Point2I mMouseLockPosition;
  83. /// Determines whether this window should lock the mouse when it has an opportunity
  84. bool mShouldLockMouse;
  85. /// When set, we don't trigger device resets due to sizing events.
  86. bool mSuppressReset;
  87. /// Menu associated with this window. This is a passive property of the window and is not required to be used at all.
  88. HMENU mMenuHandle;
  89. /// Do we have a fullscreen window style set?
  90. bool mFullscreen;
  91. /// @}
  92. /// Helper to allocate our Win32 window class.
  93. void _registerWindowClass();
  94. void _unregisterWindowClass();
  95. /// Windows message handler callback.
  96. static LRESULT PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  97. /// Add an accelerator to the list of accelerators for this window. Intended for use by addAccelerators()
  98. void addAccelerator(Accelerator &accel);
  99. /// Remove an accelerator from the list of accelerators for this window. Intended for use by removeAccelerators()
  100. void removeAccelerator(Accelerator &accel);
  101. public:
  102. Win32Window();
  103. ~Win32Window();
  104. /// Return the HWND (win32 window handle) for this window.
  105. HWND &getHWND()
  106. {
  107. return mWindowHandle;
  108. }
  109. virtual void* getSystemWindow(const WindowSystem system);
  110. HMENU &getMenuHandle()
  111. {
  112. return mMenuHandle;
  113. }
  114. void setMenuHandle( HMENU menuHandle )
  115. {
  116. mMenuHandle = menuHandle;
  117. if(!mFullscreen)
  118. SetMenu(mWindowHandle, mMenuHandle);
  119. }
  120. /// Add a list of accelerators to this window
  121. void addAccelerators(AcceleratorList &list);
  122. /// Remove a list of accelerators from this window
  123. void removeAccelerators(AcceleratorList &list);
  124. /// Returns true if @p info matches an accelerator
  125. bool isAccelerator(const InputEventInfo &info);
  126. /// Allow windows to translate messages. Used for accelerators.
  127. bool translateMessage(MSG &msg);
  128. virtual GFXDevice *getGFXDevice();
  129. virtual GFXWindowTarget *getGFXTarget();
  130. virtual void setVideoMode(const GFXVideoMode &mode);
  131. virtual const GFXVideoMode &getVideoMode();
  132. virtual bool clearFullscreen();
  133. virtual bool isFullscreen();
  134. virtual void _setFullscreen(const bool fullscreen);
  135. virtual bool setCaption(const char *cap);
  136. virtual const char *getCaption();
  137. // Window Client Area Extent
  138. virtual void setClientExtent( const Point2I newExtent );
  139. virtual const Point2I getClientExtent();
  140. // Window Bounds
  141. virtual void setBounds(const RectI &newBounds);
  142. virtual const RectI getBounds() const;
  143. // Window Position
  144. virtual void setPosition( const Point2I newPosition );
  145. virtual const Point2I getPosition();
  146. virtual void centerWindow();
  147. virtual bool setSize(const Point2I &newSize);
  148. // Coordinate space conversion.
  149. virtual Point2I clientToScreen( const Point2I& pos );
  150. virtual Point2I screenToClient( const Point2I& pos );
  151. virtual bool isOpen();
  152. virtual bool isVisible();
  153. virtual bool isFocused();
  154. virtual bool isMinimized();
  155. virtual bool isMaximized();
  156. virtual void minimize();
  157. virtual void maximize();
  158. virtual void hide();
  159. virtual void show();
  160. virtual void close();
  161. virtual void restore();
  162. virtual void setFocus();
  163. virtual void setMouseLocked(bool enable);
  164. virtual bool isMouseLocked() const { return mMouseLocked; };
  165. virtual bool shouldLockMouse() const { return mShouldLockMouse; };
  166. virtual WindowId getWindowId();
  167. virtual PlatformWindow * getNextWindow() const
  168. {
  169. return mNextWindow;
  170. }
  171. /// Provide a simple GDI-based render for when the game is not rendering.
  172. virtual void defaultRender();
  173. /// Return the class name for the windows we create with this class.
  174. static const UTF16 *getWindowClassName();
  175. /// Return the class name for the curtain window class.
  176. static const UTF16 *getCurtainWindowClassName();
  177. /// Return the platform specific object needed to create or attach an
  178. /// accelerated graohics drawing context on or to the window
  179. virtual void* getPlatformDrawable() const { return mWindowHandle; }
  180. };
  181. #endif