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