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_GRAPHICSWINDOWCARBON
20#define OSGVIEWER_GRAPHICSWINDOWCARBON 1
22#if defined (__APPLE__) && (!__LP64__)
24#include <osgViewer/GraphicsWindow>
25#include <osgViewer/api/Carbon/GraphicsHandleCarbon>
30class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleCarbon
34 GraphicsWindowCarbon(osg::GraphicsContext::Traits* traits):
39 _currentCursor(RightArrowCursor),
48 setState( new osg::State );
49 getState()->setGraphicsContext(this);
51 if (_traits.valid() && _traits->sharedContext.valid())
53 getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
54 incrementContextIDUsageCount( getState()->getContextID() );
58 getState()->setContextID( osg::GraphicsContext::createNewContextID() );
63 virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowCarbon*>(object)!=0; }
64 virtual const char* libraryName() const { return "osgViewer"; }
65 virtual const char* className() const { return "GraphicsWindowCarbon"; }
67 virtual bool valid() const { return _valid; }
69 /** Realise the GraphicsContext.*/
70 virtual bool realizeImplementation();
72 /** Return true if the graphics context has been realised and is ready to use.*/
73 virtual bool isRealizedImplementation() const { return _realized; }
75 /** Close the graphics context.*/
76 virtual void closeImplementation();
78 /** Make this graphics context current.*/
79 virtual bool makeCurrentImplementation();
81 /** Release the graphics context.*/
82 virtual bool releaseContextImplementation();
84 /** Swap the front and back buffers.*/
85 virtual void swapBuffersImplementation();
87 /** Check to see if any events have been generated.*/
88 virtual bool checkEvents();
90 /** Set the window's position and size.*/
91 virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
93 /** Set Window decoration.*/
94 virtual bool setWindowDecorationImplementation(bool flag);
96 // Override from GUIActionAdapter
97 virtual void requestWarpPointer( float x, float y);
100 virtual void grabFocus();
102 /** Get focus on if the pointer is in this window.*/
103 virtual void grabFocusIfPointerInWindow();
105 void requestClose() { _closeRequested = true; }
107 virtual void resizedImplementation(int x, int y, int width, int height);
109 virtual void setWindowName (const std::string & name);
110 virtual void useCursor(bool cursorOn);
111 virtual void setCursor(MouseCursor mouseCursor);
113 /** Set sync-to-vblank. */
114 virtual void setSyncToVBlank(bool on);
116 WindowRef getNativeWindowRef() { return _window; }
118 bool handleMouseEvent(EventRef theEvent);
119 bool handleKeyboardEvent(EventRef theEvent);
120 bool handleModifierKeys(EventRef theEvent);
122 /** WindowData is used to pass in the Carbon window handle attached the GraphicsContext::Traits structure. */
123 class WindowData : public osg::Referenced
126 WindowData(WindowRef window, AGLDrawable* drawable=NULL ): //ADEGLI
127 _window(window), _AGLDrawable(drawable) ,_installEventHandler(false) {} //ADEGLI
129 WindowRef getNativeWindowRef() { return _window; }
130 void setInstallEventHandler(bool flag) { _installEventHandler = flag; }
131 bool installEventHandler() { return _installEventHandler; }
132 AGLDrawable* getAGLDrawable() { return _AGLDrawable; } //ADEGLI
136 AGLDrawable* _AGLDrawable; //ADEGLI
137 bool _installEventHandler;
141 /// install the standard os-eventhandler
142 void installEventHandler();
144 // get the pixelformat
145 AGLPixelFormat getAGLPixelFormat() { return _pixelFormat; }
147 void adaptResize(int x, int y, int w, int h);
153 void transformMouseXY(float& x, float& y);
159 bool _useWindowDecoration;
163 AGLPixelFormat _pixelFormat;
165 int _windowTitleHeight;
167 /// computes the window attributes
168 WindowAttributes computeWindowAttributes(bool useWindowDecoration, bool supportsResize);
169 void handleModifierKey(UInt32 modifierKey, UInt32 modifierMask, osgGA::GUIEventAdapter::KeySymbol keySymbol);
172 bool _closeRequested;
173 UInt32 _lastModifierKeys;
174 MouseCursor _currentCursor;