win32Window.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 GFXGLDevice;
  36. public:
  37. struct Accelerator
  38. {
  39. U32 mID;
  40. EventDescriptor mDescriptor;
  41. };
  42. typedef Vector<Accelerator> AcceleratorList;
  43. private:
  44. typedef Vector<ACCEL> WinAccelList;
  45. /// @name Active window list
  46. ///
  47. /// Items used to track window instances.
  48. ///
  49. /// @{
  50. /// Which manager created us?
  51. Win32WindowManager *mOwningManager;
  52. /// Which window comes next in list?
  53. Win32Window *mNextWindow;
  54. /// @}
  55. /// @name Window Information
  56. ///
  57. /// @{
  58. /// Our HWND - Win32 window handle.
  59. HWND mWindowHandle;
  60. /// Our former Parent HWND
  61. HWND mOldParent;
  62. /// The Win32 window style we want to use when windowed.
  63. DWORD mWindowedWindowStyle;
  64. /// The GFX device that we're tied to.
  65. GFXDevice *mDevice;
  66. /// Reference to the render target allocated on this window.
  67. GFXWindowTargetRef mTarget;
  68. /// Our current size/resolution/fullscreen status.
  69. GFXVideoMode mVideoMode;
  70. /// Our position on the desktop.
  71. Point2I mPosition;
  72. /// Windows HACCEL for accelerators
  73. HACCEL mAccelHandle;
  74. /// Keyboard accelerators for menus
  75. WinAccelList mWinAccelList;
  76. /// Is the mouse locked to this window?
  77. bool mMouseLocked;
  78. /// The position the cursor was at when a mouse lock occured
  79. Point2I mMouseLockPosition;
  80. /// Determines whether this window should lock the mouse when it has an opportunity
  81. bool mShouldLockMouse;
  82. /// When set, we don't trigger device resets due to sizing events.
  83. bool mSuppressReset;
  84. /// Menu associated with this window. This is a passive property of the window and is not required to be used at all.
  85. HMENU mMenuHandle;
  86. /// Do we have a fullscreen window style set?
  87. bool mFullscreen;
  88. /// @}
  89. /// Helper to allocate our Win32 window class.
  90. void _registerWindowClass();
  91. void _unregisterWindowClass();
  92. /// Windows message handler callback.
  93. static LRESULT PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  94. /// Add an accelerator to the list of accelerators for this window. Intended for use by addAccelerators()
  95. void addAccelerator(Accelerator &accel);
  96. /// Remove an accelerator from the list of accelerators for this window. Intended for use by removeAccelerators()
  97. void removeAccelerator(Accelerator &accel);
  98. public:
  99. Win32Window();
  100. ~Win32Window();
  101. /// Return the HWND (win32 window handle) for this window.
  102. HWND &getHWND()
  103. {
  104. return mWindowHandle;
  105. }
  106. virtual void* getSystemWindow(const WindowSystem system);
  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