WindowImplWin32.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef SFML_WINDOWIMPLWIN32_HPP
26 #define SFML_WINDOWIMPLWIN32_HPP
27 
29 // Headers
31 #include <SFML/Window/Event.hpp>
32 #include <SFML/Window/WindowImpl.hpp>
33 #include <windows.h>
34 #include <string>
35 
36 
37 namespace sf
38 {
39 namespace priv
40 {
44 class WindowImplWin32 : public WindowImpl
45 {
46 public :
47 
53  WindowImplWin32();
54 
62  WindowImplWin32(WindowHandle Handle, WindowSettings& Params);
63 
73  WindowImplWin32(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params);
74 
79  ~WindowImplWin32();
80 
87  static bool IsContextActive();
88 
89 private :
90 
95  virtual void ProcessEvents();
96 
101  virtual void Display();
102 
107  virtual void SetActive(bool Active = true) const;
108 
113  virtual void UseVerticalSync(bool Enabled);
114 
119  virtual void ShowMouseCursor(bool Show);
120 
125  virtual void SetCursorPosition(unsigned int Left, unsigned int Top);
126 
131  virtual void SetPosition(int Left, int Top);
132 
137  virtual void SetSize(unsigned int Width, unsigned int Height);
138 
143  virtual void Show(bool State);
144 
149  virtual void EnableKeyRepeat(bool Enabled);
150 
155  virtual void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
156 
161  void RegisterWindowClass();
162 
169  void SwitchToFullscreen(const VideoMode& Mode);
170 
178  void CreateContext(const VideoMode& Mode, WindowSettings& Params);
179 
184  void Cleanup();
185 
194  void ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam);
195 
205  static Key::Code VirtualKeyCodeToSF(WPARAM VirtualKey, LPARAM Flags);
206 
215  static bool HasUnicodeSupport();
216 
228  static LRESULT CALLBACK GlobalOnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam);
229 
231  // Static member data
233  static unsigned int ourWindowCount;
234  static const char* ourClassNameA;
235  static const wchar_t* ourClassNameW;
236  static WindowImplWin32* ourFullscreenWindow;
237 
239  // Member data
241  HWND myHandle;
242  long myCallback;
243  HCURSOR myCursor;
244  HICON myIcon;
245  bool myKeyRepeatEnabled;
246  bool myIsCursorIn;
247  HDC myDeviceContext;
248  HGLRC myGLContext;
249 };
250 
251 } // namespace priv
252 
253 } // namespace sf
254 
255 #endif // SFML_WINDOWIMPLWIN32_HPP