1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14/* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
15 * a guide to use of X11/GLX and copiying directly in the case of setBorder().
16 * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
19#ifndef OSGVIEWER_GRAPHICSWINDOWWIN32
20#define OSGVIEWER_GRAPHICSWINDOWWIN32 1
22#include <osgViewer/GraphicsWindow>
23#include <osgViewer/api/Win32/GraphicsHandleWin32>
28class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleWin32
32 GraphicsWindowWin32(osg::GraphicsContext::Traits* traits);
34 ~GraphicsWindowWin32();
36 virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowWin32*>(object)!=0; }
37 virtual const char* libraryName() const { return "osgViewer"; }
38 virtual const char* className() const { return "GraphicsWindowWin32"; }
40 virtual bool valid() const { return _valid; }
42 /** Realize the GraphicsContext.*/
43 virtual bool realizeImplementation();
45 /** Return true if the graphics context has been realized and is ready to use.*/
46 virtual bool isRealizedImplementation() const { return _realized; }
48 /** Close the graphics context.*/
49 virtual void closeImplementation();
51 /** Make this graphics context current.*/
52 virtual bool makeCurrentImplementation();
54 /** Release the graphics context.*/
55 virtual bool releaseContextImplementation();
57 /** Swap the front and back buffers.*/
58 virtual void swapBuffersImplementation();
60 /** Check to see if any events have been generated.*/
61 virtual bool checkEvents();
63 /** Set the window's position and size.*/
64 virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
66 /** Set Window decoration.*/
67 virtual bool setWindowDecorationImplementation(bool flag);
70 virtual void grabFocus();
72 /** Get focus on if the pointer is in this window.*/
73 virtual void grabFocusIfPointerInWindow();
75 /** Override from GUIActionAdapter.*/
76 virtual void requestWarpPointer(float x,float y);
78 /** Raise specified window */
79 virtual void raiseWindow();
81 /** Set the name of the window */
82 virtual void setWindowName(const std::string& /*name*/);
84 /** Switch on/off the cursor.*/
85 virtual void useCursor(bool /*cursorOn*/);
87 /** Set mouse cursor to a specific shape.*/
88 virtual void setCursor(MouseCursor cursor);
90 /** Set sync-to-vblank. */
91 virtual void setSyncToVBlank(bool on);
93 /** Set swap group. */
94 virtual void setSwapGroup(bool on, GLuint group, GLuint barrier);
96 /** Handle a native (Win32) windowing event as received from the system */
97 virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
99 /** WindowData is used to pass in the Win32 window handle attached the GraphicsContext::Traits structure.*/
100 struct WindowData : public osg::Referenced
102 WindowData(HWND window, bool installEventHandler = true):
103 _hwnd(window), _installEventHandler(installEventHandler) {}
106 bool _installEventHandler;
113 virtual void registerWindow();
114 virtual void unregisterWindow();
116 virtual bool registerWindowProcedure();
117 virtual bool unregisterWindowProcedure();
119 virtual HGLRC createContextImplementation();
120 virtual bool createWindow();
121 virtual bool setWindow( HWND handle );
123 virtual void destroyWindow( bool deleteNativeWindow = true );
125 virtual bool determineWindowPositionAndStyle( unsigned int screenNum,
128 unsigned int clientAreaWidth,
129 unsigned int clientAreaHeight,
136 unsigned int& extendedStyle );
138 virtual bool setPixelFormat();
140 virtual void adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask, int& unmodifiedKeySymbol );
142 virtual void transformMouseXY(float& x, float& y);
144 virtual void setCursorImpl(MouseCursor cursor);
146 virtual HCURSOR getOrCreateCursor(MouseCursor mouseShape);
148 HCURSOR _currentCursor;
150 WNDPROC _windowProcedure;
152 double _timeOfLastCheckEvents;
159 unsigned int _screenWidth;
160 unsigned int _screenHeight;
162 int _windowOriginXToRealize;
163 int _windowOriginYToRealize;
164 unsigned int _windowWidthToRealize;
165 unsigned int _windowHeightToRealize;
176 MouseCursor _mouseCursor;
178 /// Persist which mouse cursor was used before switching to the resize cursors.
179 MouseCursor _appMouseCursor;
181 std::map<MouseCursor,HCURSOR> _mouseCursorMap;
183 std::map<std::pair<int, int>, bool> _keyMap;
185 std::set<int> _capturedMouseButtons;
187 bool _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues;