Changeset 10208

Show
Ignore:
Timestamp:
05/14/09 17:34:15 (6 years ago)
Author:
robert
Message:

From Stephan Huber, "attached you'll find some bugfixes and enhancements for the Cocoa
implementation of GraoicsWindowCocoa?:

Enhancements/Bugfixes:

+ now it's possible to integrate osgViewer better into existing
cocoa-applications:
* create one or more NSOpenGLView(s) and add these to your window(s)
* create one or more NSWindows
* disable the integrated event-polling of osgViewer, and let the work be
done by Cocoa / NSApplicationRun. You'll have to run the osgViewer's
runloop in a separate thread

+ missing menu-event-handling implemented

+ added NSAutoReleasePools where necessary, this fixes some memory-leaks
+ fixed some crashes and thread-issues"

Location:
OpenSceneGraph/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/GraphicsWindowCocoa

    r9879 r10208  
    2424#ifdef __OBJC__ 
    2525@class GraphicsWindowCocoaWindow; 
     26@class GraphicsWindowCocoaGLView; 
    2627@class NSOpenGLContext; 
    2728@class NSWindow; 
     29@class NSView; 
    2830#else 
     31class GraphicsWindowCocoaGLView; 
    2932class GraphicsWindowCocoaWindow; 
    3033class NSOpenGLContext; 
    3134class NSWindow; 
     35class NSView; 
    3236#endif 
    3337 
     
    4246{ 
    4347    public: 
    44         class Implementation; 
     48    class Implementation; 
    4549 
    4650        GraphicsWindowCocoa(osg::GraphicsContext::Traits* traits): 
     
    4852            _initialized(false), 
    4953            _realized(false), 
     54            _closeRequested(false), 
     55            _checkForEvents(true), 
    5056            _ownsWindow(true), 
    51             _currentCursor(RightArrowCursor) 
     57            _currentCursor(RightArrowCursor), 
     58            _window(NULL), 
     59            _context(NULL) 
    5260        { 
    5361            _traits = traits; 
     
    122130        { 
    123131            public: 
    124                 WindowData(NSWindow* window) 
    125                                 :       _window(window)  
    126                                 { 
    127                                 } 
    128                  
    129                 inline NSWindow* getNativeWindowRef() { return _window; } 
    130                                  
     132                enum Options { CreateOnlyView = 1, CheckForEvents = 2, PoseAsStandaloneApp = 4}; 
     133                WindowData(unsigned int options) 
     134                :    _createOnlyView(options & CreateOnlyView), 
     135                    _checkForEvents(options & CheckForEvents), 
     136                    _poseAsStandaloneApp(options & PoseAsStandaloneApp), 
     137                    _view(NULL) 
     138                { 
     139                } 
     140                             
     141                inline NSView* getCreatedNSView() { return _view; } 
     142                bool createOnlyView() const { return _createOnlyView; } 
     143                bool checkForEvents() const { return _checkForEvents; } 
     144                bool poseAsStandaloneApp() const { return _poseAsStandaloneApp; } 
     145             
     146            protected: 
     147                inline void setCreatedNSView(NSView* view) { _view = view; } 
     148             
    131149            private: 
    132                 NSWindow*    _window; 
    133                 bool         _installEventHandler; 
     150                bool         _createOnlyView, _checkForEvents, _poseAsStandaloneApp; 
     151                NSView*         _view; 
    134152             
     153            friend class GraphicsWindowCocoa; 
     154 
    135155        }; 
    136156         
     
    139159                 
    140160        void setVSync(bool f); 
    141                  
    142                 /** adapts a resize / move of the window, coords in global screen space */ 
    143                 void adaptResize(int x, int y, int w, int h); 
     161         
     162        /** adapts a resize / move of the window, coords in global screen space */ 
     163        void adaptResize(int x, int y, int w, int h); 
    144164         
    145165    protected: 
     
    158178        bool            _realized; 
    159179        bool            _useWindowDecoration; 
    160         bool            _ownsWindow; 
    161180 
    162          
     181     
    163182          
    164183    private:         
    165184        
    166185         
    167         bool                            _closeRequested; 
    168         MouseCursor                     _currentCursor; 
    169                 GraphicsWindowCocoaWindow* _window; 
    170                 NSOpenGLContext*        _context; 
     186        bool                _closeRequested, _checkForEvents,_ownsWindow; 
     187        MouseCursor            _currentCursor; 
     188        GraphicsWindowCocoaWindow* _window; 
     189        GraphicsWindowCocoaGLView*    _view; 
     190        NSOpenGLContext*    _context; 
    171191}; 
    172192 
  • OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.h

    r9895 r10208  
    7979 
    8080        virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList); 
     81         
     82        virtual bool setScreenSettings (const osg::GraphicsContext::ScreenIdentifier & si, const osg::GraphicsContext::ScreenSettings & settings); 
    8183 
    8284        /** return the top left coord of a specific screen in global screen space */ 
    8385        void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y); 
    8486 
    85         /** implementation of setScreenResolution */ 
    86         virtual bool setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ; 
    87  
    88         /** implementation of setScreenRefreshRate */ 
    89         virtual bool setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate); 
    90  
     87         
    9188 
    9289        /** returns screen-ndx containing rect x,y,w,h */ 
     
    9491     
    9592    protected: 
     93     
     94        /** implementation of setScreenResolution */ 
     95        bool setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ; 
     96 
     97        /** implementation of setScreenRefreshRate */ 
     98        bool setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate); 
     99 
    96100     
    97101        template<class PixelBufferImplementation, class GraphicsWindowImplementation> 
  • OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.mm

    r9895 r10208  
    249249 
    250250 
     251bool DarwinWindowingSystemInterface::setScreenSettings(const osg::GraphicsContext::ScreenIdentifier &si, const osg::GraphicsContext::ScreenSettings & settings) 
     252{ 
     253    bool result = setScreenResolutionImpl(si, settings.width, settings.height); 
     254    if (result) 
     255        setScreenRefreshRateImpl(si, settings.refreshRate); 
     256     
     257    return result; 
     258} 
     259 
     260 
    251261 
    252262/** implementation of setScreenResolution */ 
    253 bool DarwinWindowingSystemInterface::setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height)  
     263bool DarwinWindowingSystemInterface::setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height)  
    254264{  
    255265    CGDirectDisplayID displayID = getDisplayID(screenIdentifier); 
     
    271281 
    272282/** implementation of setScreenRefreshRate */ 
    273 bool DarwinWindowingSystemInterface::setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate) {  
     283bool DarwinWindowingSystemInterface::setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate) {  
    274284     
    275285    boolean_t  success(false); 
  • OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm

    r9895 r10208  
    88 *  Some code borrowed from the implementation of CocoaViewer,  
    99 *  Created by Eric Wing on 11/12/06. and ported by Martin Lavery 7/06/07 
     10 * 
     11 *  Other snippets are borrowed from the Cocoa-implementation of the SDL-lib 
    1012 */ 
    1113 
     
    1820#include "DarwinUtils.h" 
    1921 
     22//#define DEBUG_OUT(s) std::cout << "GraphicsWindowCocoa :: " << s << std::endl; 
     23 
     24#define DEBUG_OUT(s) ; 
    2025 
    2126static bool s_quit_requested = false; 
     27 
     28#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 
     29@interface NSApplication(NSAppleMenu) 
     30- (void)setAppleMenu:(NSMenu *)menu; 
     31@end 
     32#endif 
    2233 
    2334 
     
    188199 
    189200- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; 
     201- (void)applicationDidFinishLaunching:(NSNotification *)aNotification; 
    190202@end 
    191203 
     
    194206{ 
    195207    s_quit_requested = true; 
    196     // std::cout << "quit requested " << std::endl; 
    197     return NSTerminateNow; 
     208    DEBUG_OUT("quit requested "); 
     209    return NSTerminateCancel; 
     210} 
     211 
     212- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
     213{ 
     214    DEBUG_OUT("applicationDidFinishLaunching"); 
    198215} 
    199216 
     
    323340- (void) handleModifiers: (NSEvent*)theEvent 
    324341{ 
     342    DEBUG_OUT("handling modifiers"); 
     343     
     344    if ((!_win) || (!_win->getEventQueue()))  
     345        return; // no event    queue in place 
     346     
    325347    unsigned int flags = [theEvent modifierFlags]; 
    326348     
     
    367389- (void) mouseMoved:(NSEvent*)theEvent  
    368390{ 
     391    DEBUG_OUT("Mouse moved"); 
    369392    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    370393    _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); 
     
    375398- (void) mouseDown:(NSEvent*)theEvent 
    376399{ 
     400    DEBUG_OUT("Mouse down"); 
    377401    // Because many Mac users have only a 1-button mouse, we should provide ways 
    378402    // to access the button 2 and 3 actions of osgViewer. 
     
    403427- (void) mouseDragged:(NSEvent*)theEvent 
    404428{ 
     429    if (!_win) return; 
     430     
    405431    NSPoint converted_point = [self getLocalPoint: theEvent];     
    406432    _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); 
     
    441467- (void) rightMouseDragged:(NSEvent*)theEvent 
    442468{ 
    443     
     469    if (!_win) return; 
     470     
    444471    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    445472    _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); 
     
    473500- (void) otherMouseDragged:(NSEvent*)theEvent 
    474501{ 
     502    if (!_win) return; 
     503     
    475504    NSPoint converted_point = [self getLocalPoint: theEvent];     
    476505    _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); 
     
    524553- (void) doLeftMouseButtonDown:(NSEvent*)theEvent 
    525554{ 
     555    if (!_win) return; 
     556     
    526557    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    527558     
     
    538569- (void) doLeftMouseButtonUp:(NSEvent*)theEvent 
    539570{ 
     571    if (!_win) return; 
     572     
    540573    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    541574     
     
    546579- (void) doRightMouseButtonDown:(NSEvent*)theEvent 
    547580{ 
     581    if (!_win) return; 
     582     
    548583    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    549584    if([theEvent clickCount] == 1) 
     
    561596- (void) doRightMouseButtonUp:(NSEvent*)theEvent 
    562597{ 
     598    if (!_win) return; 
     599     
    563600    NSPoint converted_point = [self getLocalPoint: theEvent];     
    564601    _win->getEventQueue()->mouseButtonRelease(converted_point.x, converted_point.y, 3); 
     
    567604- (void) doMiddleMouseButtonDown:(NSEvent*)theEvent 
    568605{ 
     606    if (!_win) return; 
     607     
    569608    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    570609     
     
    581620- (void) doExtraMouseButtonDown:(NSEvent*)theEvent buttonNumber:(int)button_number 
    582621{ 
     622    if (!_win) return; 
     623     
    583624    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    584625    if([theEvent clickCount] == 1) 
     
    595636- (void) doMiddleMouseButtonUp:(NSEvent*)theEvent 
    596637{ 
     638    if (!_win) return; 
     639     
    597640    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    598641    _win->getEventQueue()->mouseButtonRelease(converted_point.x, converted_point.y, 2); 
     
    602645- (void) doExtraMouseButtonUp:(NSEvent*)theEvent buttonNumber:(int)button_number 
    603646{ 
     647    if (!_win) return; 
     648     
    604649    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    605650    _win->getEventQueue()->mouseButtonRelease(converted_point.x, converted_point.y, button_number+1); 
     
    610655- (void) scrollWheel:(NSEvent*)theEvent 
    611656{ 
     657    if (!_win) return; 
     658     
    612659    // Unfortunately, it turns out mouseScroll2D doesn't actually do anything. 
    613660    // The camera manipulators don't seem to implement any code that utilize the scroll values. 
     
    620667- (void)keyDown:(NSEvent *)theEvent  
    621668{ 
     669    if (!_win) return; 
     670     
    622671    NSString* chars = [theEvent charactersIgnoringModifiers];  
    623672    unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask) ); 
     
    629678- (void)keyUp:(NSEvent *)theEvent  
    630679{    
     680    if (!_win) return; 
     681     
    631682    NSString* chars = [theEvent charactersIgnoringModifiers];  
    632683    unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask)); 
     
    644695-(void)handleTabletEvents:(NSEvent *)theEvent 
    645696{ 
     697    if (!_win) return; 
     698     
    646699    float pressure = [theEvent pressure]; 
    647700    _win->getEventQueue()->penPressure(pressure); 
     
    654707- (void)tabletProximity:(NSEvent *)theEvent 
    655708{ 
     709    if (!_win) return; 
     710     
    656711    osgGA::GUIEventAdapter::TabletPointerType pt(osgGA::GUIEventAdapter::UNKNOWN); 
    657712    switch ([theEvent pointingDeviceType]) { 
     
    845900    NSRect rect = NSMakeRect(_traits->x + screenLeft, _traits->y + screenTop, _traits->width, _traits->height); 
    846901     
    847     _window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; 
    848      
    849     if (!_window) { 
    850         osg::notify(osg::WARN) << "GraphicsWindowCocoa::realizeImplementation :: could not create window" << std::endl; 
    851         return false; 
    852     } 
    853      
    854     rect = convertFromQuartzCoordinates(rect); 
    855     [_window setFrameOrigin: rect.origin]; 
    856       
     902    _ownsWindow = true; 
     903     
     904    // should we create a NSView only?? 
     905    WindowData* windowData = _traits->inheritedWindowData ? dynamic_cast<WindowData*>(_traits->inheritedWindowData.get()) : NULL; 
     906    if (windowData)  
     907    { 
     908        if (windowData->createOnlyView()) 
     909            _ownsWindow = false; 
     910        _checkForEvents = windowData->checkForEvents(); 
     911         
     912    }  
     913     
     914 
     915    osg::notify(osg::DEBUG_INFO) << "GraphicsWindowCocoa::realizeImplementation / ownsWindow: " << _ownsWindow << " checkForEvents: " << _checkForEvents << std::endl; 
     916 
     917    if (_ownsWindow)  
     918    { 
     919        _window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; 
     920         
     921        if (!_window) { 
     922            osg::notify(osg::WARN) << "GraphicsWindowCocoa::realizeImplementation :: could not create window" << std::endl; 
     923            return false; 
     924        } 
     925 
     926        rect = convertFromQuartzCoordinates(rect); 
     927        [_window setFrameOrigin: rect.origin]; 
     928    }  
     929             
    857930    NSOpenGLPixelFormatAttribute attr[32]; 
    858931    int i = 0; 
     
    914987    [theView setGraphicsWindowCocoa: this]; 
    915988    [theView setOpenGLContext:_context]; 
    916     [_window setContentView: theView]; 
    917      
    918     setupNSWindow(_window); 
    919      
    920     [theView release]; 
     989    _view = theView; 
     990    osg::notify(osg::DEBUG_INFO) << "GraphicsWindowCocoa::realizeImplementation / view: " << theView << std::endl; 
     991 
     992    if (_ownsWindow) { 
     993        [_window setContentView: theView]; 
     994        setupNSWindow(_window); 
     995        [theView release]; 
     996         
     997        MenubarController::instance()->attachWindow( new CocoaWindowAdapter(this) ); 
     998    } 
     999    else  
     1000    { 
     1001        windowData->setCreatedNSView(theView); 
     1002    } 
     1003 
    9211004    [pool release]; 
    9221005     
    923     MenubarController::instance()->attachWindow( new CocoaWindowAdapter(this) ); 
    9241006     
    9251007    useCursor(_traits->useCursor); 
     
    9511033    if (mbc) mbc->detachWindow(this); 
    9521034     
    953     [_window close]; 
    954     [_window release]; 
     1035    if (_window) { 
     1036        [_window close]; 
     1037        [_window release]; 
     1038    } 
     1039     
     1040    if (_view) { 
     1041        [_view setGraphicsWindowCocoa: NULL]; 
     1042    } 
     1043     
     1044    _window = NULL; 
     1045    _view = NULL; 
     1046     
    9551047} 
    9561048 
     
    9941086void GraphicsWindowCocoa::checkEvents() 
    9951087{ 
     1088    if (!_checkForEvents) 
     1089        return; 
     1090     
    9961091    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    9971092     
     
    10051100            so it may not effectively make much of a difference. 
    10061101         */ 
    1007         NSEvent *event = [ [NSApplication sharedApplication] 
     1102        NSEvent *event = [ NSApp 
    10081103                nextEventMatchingMask:NSAnyEventMask 
    10091104                untilDate:[NSDate distantPast] 
     
    10121107        if(!event) 
    10131108            break; 
    1014         [[NSApplication sharedApplication] sendEvent: event]; 
     1109        [NSApp sendEvent: event]; 
    10151110    }     
    10161111     
     
    10371132bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag) 
    10381133{ 
    1039     if (!_realized) return false; 
     1134    if (!_realized || !_ownsWindow) return false; 
     1135     
     1136    NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; 
    10401137     
    10411138    unsigned int style(NSBorderlessWindowMask); 
     
    10621159    } 
    10631160     
     1161    [localPool release]; 
     1162     
    10641163    return true; 
    10651164} 
     
    10711170void GraphicsWindowCocoa::grabFocus() 
    10721171{ 
    1073     [_window makeKeyAndOrderFront: nil]; 
     1172    if (_ownsWindow) 
     1173        [_window makeKeyAndOrderFront: nil]; 
    10741174} 
    10751175 
     
    10901190void GraphicsWindowCocoa::resizedImplementation(int x, int y, int width, int height) 
    10911191{ 
    1092     std::cout << "resized implementation" << x << " " << y << " " << width << " " << height << std::endl;  
     1192    DEBUG_OUT("resized implementation" << x << " " << y << " " << width << " " << height);  
    10931193    GraphicsContext::resizedImplementation(x, y, width, height); 
     1194     
     1195    NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; 
    10941196    
    1095     [_context update]; 
     1197    if (_context) 
     1198        [_context update]; 
    10961199    MenubarController::instance()->update(); 
    10971200    getEventQueue()->windowResize(x,y,width, height, getEventQueue()->getTime()); 
     1201    [localPool release]; 
    10981202} 
    10991203 
     
    11061210bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int width, int height) 
    11071211{ 
     1212    if (!_ownsWindow) 
     1213        return false; 
     1214         
     1215    NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; 
     1216         
    11081217    DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 
    11091218    int screenLeft(0), screenTop(0); 
     
    11201229    MenubarController::instance()->update(); 
    11211230     
     1231    [localPool release]; 
     1232     
    11221233    return true; 
    11231234} 
     
    11551266void GraphicsWindowCocoa::setWindowName (const std::string & name) 
    11561267{ 
     1268    if (_traits.valid()) _traits->windowName = name; 
     1269     
     1270    if (!_ownsWindow) 
     1271        return; 
     1272         
    11571273    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    11581274     
     
    12011317void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor) 
    12021318{ 
     1319    NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; 
     1320     
    12031321    switch (mouseCursor)  
    12041322    { 
     
    12231341            osg::notify(osg::INFO) << "GraphicsWindowCocoa::setCursor :: unsupported MouseCursor: " << mouseCursor << std::endl;     
    12241342    } 
     1343     
     1344    [localPool release]; 
    12251345} 
    12261346 
     
    12431363GraphicsWindowCocoa::~GraphicsWindowCocoa()  
    12441364{ 
     1365    close(); 
    12451366} 
    12461367 
     
    12561377     
    12571378    CocoaWindowingSystemInterface() 
    1258     :    DarwinWindowingSystemInterface()  
    1259     { 
    1260         localPool = [[NSAutoreleasePool alloc] init]; 
    1261         [[NSApplication sharedApplication] setDelegate: [[CocoaAppDelegate alloc] init] ]; 
     1379    :    DarwinWindowingSystemInterface() 
     1380     
     1381    {         
     1382    } 
     1383     
     1384    void initAsStandaloneApplication()  
     1385    { 
     1386        static bool s_inited = false; 
     1387        if (s_inited) return; 
     1388        s_inited = true; 
     1389         
     1390        osg::notify(osg::INFO) << "CocoaWindowingSystemInterface::initAsStandaloneApplication " << std::endl; 
     1391         
     1392        ProcessSerialNumber psn; 
     1393        if (!GetCurrentProcess(&psn)) { 
     1394            TransformProcessType(&psn, kProcessTransformToForegroundApplication); 
     1395            SetFrontProcess(&psn); 
     1396        } 
     1397         
     1398        NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; 
     1399         
     1400        if (NSApp == nil) { 
     1401            [NSApplication sharedApplication]; 
     1402        } 
     1403         
     1404        [NSApp setDelegate: [[CocoaAppDelegate alloc] init] ]; 
     1405         
     1406        createApplicationMenus(); 
     1407         
     1408        [NSApp finishLaunching]; 
     1409         
     1410        [localPool release]; 
    12621411    } 
    12631412     
    12641413    virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits)  
    12651414    { 
     1415        if (!traits->pbuffer)  
     1416        { 
     1417            GraphicsWindowCocoa::WindowData* windowData = traits->inheritedWindowData ? dynamic_cast<GraphicsWindowCocoa::WindowData*>(traits->inheritedWindowData.get()) : NULL; 
     1418         
     1419            if (!windowData || (windowData && windowData->poseAsStandaloneApp()))  
     1420            { 
     1421                initAsStandaloneApplication(); 
     1422            } 
     1423        } 
     1424         
    12661425        return createGraphicsContextImplementation<PixelBufferCocoa, GraphicsWindowCocoa>(traits); 
    12671426    } 
     
    12691428    virtual ~CocoaWindowingSystemInterface()  
    12701429    { 
    1271         [localPool release]; 
    1272     } 
    1273      
    1274     NSAutoreleasePool *localPool; 
     1430    } 
     1431     
     1432private: 
     1433    NSString *getApplicationName(void) 
     1434    { 
     1435        NSDictionary *dict; 
     1436        NSString *appName = 0; 
     1437 
     1438        /* Determine the application name */ 
     1439        dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); 
     1440        if (dict) 
     1441            appName = [dict objectForKey: @"CFBundleName"]; 
     1442         
     1443        if (![appName length]) 
     1444            appName = [[NSProcessInfo processInfo] processName]; 
     1445 
     1446        return appName; 
     1447    } 
     1448     
     1449     void createApplicationMenus(void) 
     1450    { 
     1451        NSString *appName; 
     1452        NSString *title; 
     1453        NSMenu *appleMenu; 
     1454        NSMenuItem *menuItem; 
     1455         
     1456        /* Create the main menu bar */ 
     1457        [NSApp setMainMenu:[[NSMenu alloc] init]]; 
     1458 
     1459        /* Create the application menu */ 
     1460        appName = getApplicationName(); 
     1461        appleMenu = [[NSMenu alloc] initWithTitle:@""]; 
     1462         
     1463        /* Add menu items */ 
     1464        title = [@"About " stringByAppendingString:appName]; 
     1465        [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; 
     1466 
     1467        [appleMenu addItem:[NSMenuItem separatorItem]]; 
     1468         
     1469        NSMenu* service_menu = [[NSMenu alloc] init]; 
     1470        NSMenuItem* service_menu_item = [[NSMenuItem alloc] initWithTitle:@"Services" action:nil keyEquivalent:@""]; 
     1471        [service_menu_item setSubmenu: service_menu]; 
     1472        [appleMenu addItem: service_menu_item]; 
     1473        [NSApp setServicesMenu: service_menu]; 
     1474         
     1475        [appleMenu addItem:[NSMenuItem separatorItem]]; 
     1476 
     1477        title = [@"Hide " stringByAppendingString:appName]; 
     1478        [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@/*"h"*/"h"]; 
     1479 
     1480        menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@/*"h"*/""]; 
     1481        [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; 
     1482 
     1483        [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; 
     1484 
     1485        [appleMenu addItem:[NSMenuItem separatorItem]]; 
     1486 
     1487        title = [@"Quit " stringByAppendingString:appName]; 
     1488        [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@/*"q"*/"q"]; 
     1489         
     1490        /* Put menu into the menubar */ 
     1491        menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; 
     1492        [menuItem setSubmenu:appleMenu]; 
     1493        [[NSApp mainMenu] addItem:menuItem]; 
     1494        [menuItem release]; 
     1495 
     1496        /* Tell the application object that this is now the application menu */ 
     1497        [NSApp setAppleMenu:appleMenu]; 
     1498        [appleMenu release]; 
     1499 
     1500 
     1501    } 
    12751502 
    12761503}; 
    1277  
    12781504 
    12791505}