win32Window.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. /// Implementation of a window on Win32.
  31. class Win32Window : public PlatformWindow
  32. {
  33. friend class Win32WindowManager;
  34. friend class GFXPCD3D9Device;
  35. friend class GFXPCD3D9WindowTarget;
  36. friend class GFXD3D8WindowTarget;
  37. public:
  38. struct Accelerator
  39. {
  40. U32 mID;
  41. EventDescriptor mDescriptor;
  42. };
  43. typedef Vector<Accelerator> AcceleratorList;
  44. private:
  45. typedef Vector<ACCEL> WinAccelList;
  46. /// @name Active window list
  47. ///
  48. /// Items used to track window instances.
  49. ///
  50. /// @{
  51. /// Which manager created us?
  52. Win32WindowManager *mOwningManager;
  53. /// Which window comes next in list?
  54. Win32Window *mNextWindow;
  55. /// @}
  56. /// @name Window Information
  57. ///
  58. /// @{
  59. /// Our HWND - Win32 window handle.
  60. HWND mWindowHandle;
  61. /// Our former Parent HWND
  62. HWND mOldParent;
  63. /// The Win32 window style we want to use when windowed.
  64. DWORD mWindowedWindowStyle;
  65. /// The GFX device that we're tied to.
  66. GFXDevice *mDevice;
  67. /// Reference to the render target allocated on this window.
  68. GFXWindowTargetRef mTarget;
  69. /// Our current size/resolution/fullscreen status.
  70. GFXVideoMode mVideoMode;
  71. /// Our position on the desktop.
  72. Point2I mPosition;
  73. /// Windows HACCEL for accelerators
  74. HACCEL mAccelHandle;
  75. /// Keyboard accelerators for menus
  76. WinAccelList mWinAccelList;
  77. /// Is the mouse locked to this window?
  78. bool mMouseLocked;
  79. /// The position the cursor was at when a mouse lock occured
  80. Point2I mMouseLockPosition;
  81. /// Determines whether this window should lock the mouse when it has an opportunity
  82. bool mShouldLockMouse;
  83. /// When set, we don't trigger device resets due to sizing events.
  84. bool mSuppressReset;
  85. /// Menu associated with this window. This is a passive property of the window and is not required to be used at all.
  86. HMENU mMenuHandle;
  87. /// Do we have a fullscreen window style set?
  88. bool mFullscreen;
  89. /// @}
  90. /// Helper to allocate our Win32 window class.
  91. void _registerWindowClass();
  92. void _unregisterWindowClass();
  93. /// Windows message handler callback.
  94. static LRESULT PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  95. /// Add an accelerator to the list of accelerators for this window. Intended for use by addAccelerators()
  96. void addAccelerator(Accelerator &accel);
  97. /// Remove an accelerator from the list of accelerators for this window. Intended for use by removeAccelerators()
  98. void removeAccelerator(Accelerator &accel);
  99. public:
  100. Win32Window();
  101. ~Win32Window();
  102. /// Return the HWND (win32 window handle) for this window.
  103. HWND &getHWND()
  104. {
  105. return mWindowHandle;
  106. }
  107. HMENU &getMenuHandle()
  108. {
  109. return mMenuHandle;
  110. }
  111. void setMenuHandle( HMENU menuHandle )
  112. {
  113. mMenuHandle = menuHandle;
  114. if(!mFullscreen)
  115. SetMenu(mWindowHandle, mMenuHandle);
  116. }
  117. /// Add a list of accelerators to this window
  118. void addAccelerators(AcceleratorList &list);
  119. /// Remove a list of accelerators from this window
  120. void removeAccelerators(AcceleratorList &list);
  121. /// Returns true if @p info matches an accelerator
  122. bool isAccelerator(const InputEventInfo &info);
  123. /// Allow windows to translate messages. Used for accelerators.
  124. bool translateMessage(MSG &msg);
  125. virtual GFXDevice *getGFXDevice();
  126. virtual GFXWindowTarget *getGFXTarget();
  127. virtual void setVideoMode(const GFXVideoMode &mode);
  128. virtual const GFXVideoMode &getVideoMode();
  129. virtual bool clearFullscreen();
  130. virtual bool isFullscreen();
  131. virtual void _setFullscreen(const bool fullscreen);
  132. virtual bool setCaption(const char *cap);
  133. virtual const char *getCaption();
  134. // Window Client Area Extent
  135. virtual void setClientExtent( const Point2I newExtent );
  136. virtual const Point2I getClientExtent();
  137. // Window Bounds
  138. virtual void setBounds(const RectI &newBounds);
  139. virtual const RectI getBounds() const;
  140. // Window Position
  141. virtual void setPosition( const Point2I newPosition );
  142. virtual const Point2I getPosition();
  143. virtual void centerWindow();
  144. virtual bool setSize(const Point2I &newSize);
  145. // Coordinate space conversion.
  146. virtual Point2I clientToScreen( const Point2I& pos );
  147. virtual Point2I screenToClient( const Point2I& pos );
  148. virtual bool isOpen();
  149. virtual bool isVisible();
  150. virtual bool isFocused();
  151. virtual bool isMinimized();
  152. virtual bool isMaximized();
  153. virtual void minimize();
  154. virtual void maximize();
  155. virtual void hide();
  156. virtual void show();
  157. virtual void close();
  158. virtual void restore();
  159. virtual void setFocus();
  160. virtual void setMouseLocked(bool enable);
  161. virtual bool isMouseLocked() const { return mMouseLocked; };
  162. virtual bool shouldLockMouse() const { return mShouldLockMouse; };
  163. virtual WindowId getWindowId();
  164. virtual PlatformWindow * getNextWindow() const
  165. {
  166. return mNextWindow;
  167. }
  168. /// Provide a simple GDI-based render for when the game is not rendering.
  169. virtual void defaultRender();
  170. /// Return the class name for the windows we create with this class.
  171. static const UTF16 *getWindowClassName();
  172. /// Return the class name for the curtain window class.
  173. static const UTF16 *getCurtainWindowClassName();
  174. /// Return the platform specific object needed to create or attach an
  175. /// accelerated graohics drawing context on or to the window
  176. virtual void* getPlatformDrawable() const { return mWindowHandle; }
  177. };
  178. #endif