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