]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/utils.mm
Fix discrepancy between different ways of measuring text extents under Mac.
[wxWidgets.git] / src / osx / cocoa / utils.mm
index 173df9c046c06a9a76fb1afeac80222c8823f8dc..8d74b22883bea2e67eeb82301d8593aaa3fb5176 100644 (file)
@@ -52,7 +52,27 @@ void wxBell()
 
 void wxMacWakeUp()
 {
-    // TODO
+    // ensure that we have an auto release pool in place because the event will
+    // be autoreleased from NSEvent:otherEventWithType and we might not have a
+    // global pool during startup or shutdown and we actually never have it if
+    // we're called from another thread
+    //
+    // FIXME: we can't use wxMacAutoreleasePool here because it's in core and
+    //        we're in base
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    NSEvent* wakeupEvent = [NSEvent otherEventWithType:NSApplicationDefined
+                                    location:NSZeroPoint
+                                    modifierFlags:NSAnyEventMask
+                                    timestamp:0
+                                    windowNumber:0
+                                    context:nil
+                                    subtype:0
+                                    data1:0
+                                    data2:0];
+    [NSApp postEvent:wakeupEvent atStart:NO];
+
+    [pool release];
 }
 
 #endif // wxUSE_BASE
@@ -76,12 +96,14 @@ void wxMacWakeUp()
 
 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
 {
+    wxUnusedVar(sender);
     // let wx do this, not cocoa
     return NO;
 }
 
 - (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename;
 {
+    wxUnusedVar(sender);
     wxCFStringRef cf(wxCFRetain(filename));
     wxTheApp->MacOpenFile(cf.AsString()) ;
     return YES;
@@ -89,12 +111,14 @@ void wxMacWakeUp()
 
 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender;
 {
+    wxUnusedVar(sender);
     wxTheApp->MacNewFile() ;
     return NO;
 }
 
 - (BOOL)application:(NSApplication *)sender printFile:(NSString *)filename
 {
+    wxUnusedVar(sender);
     wxCFStringRef cf(wxCFRetain(filename));
     wxTheApp->MacPrintFile(cf.AsString()) ;
     return YES;
@@ -109,6 +133,7 @@ void wxMacWakeUp()
 */
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
 {
+    wxUnusedVar(sender);
     wxWindow* win = wxTheApp->GetTopWindow() ;
     if ( win )
     {
@@ -125,6 +150,8 @@ void wxMacWakeUp()
 
 - (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
 {
+    wxUnusedVar(flag);
+    wxUnusedVar(sender);
     wxTheApp->MacReopenApp() ;
     return NO;
 }
@@ -132,15 +159,16 @@ void wxMacWakeUp()
 - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
     withReplyEvent:(NSAppleEventDescriptor *)replyEvent
 {
+    wxUnusedVar(replyEvent);
     NSString* url = [[event descriptorAtIndex:1] stringValue];
     wxCFStringRef cf(wxCFRetain(url));
     wxTheApp->MacOpenURL(cf.AsString()) ;
 }
 @end
 
-/* 
+/*
     allows ShowModal to work when using sheets.
-    see include/wx/osx/cocoa/private.h for more info 
+    see include/wx/osx/cocoa/private.h for more info
 */
 @implementation ModalDialogDelegate
 - (id)init
@@ -151,7 +179,7 @@ void wxMacWakeUp()
     return self;
 }
 
-- (BOOL)finished 
+- (BOOL)finished
 {
     return sheetFinished;
 }
@@ -171,6 +199,7 @@ void wxMacWakeUp()
 
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
 {
+    wxUnusedVar(contextInfo);
     resultCode = returnCode;
     sheetFinished = YES;
     // NSAlerts don't need nor respond to orderOut
@@ -192,8 +221,8 @@ bool wxApp::DoInitGui()
         NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
         [appleEventManager setEventHandler:controller andSelector:@selector(handleGetURLEvent:withReplyEvent:)
             forEventClass:kInternetEventClass andEventID:kAEGetURL];
+        [NSApp finishLaunching];
     }
-    [NSApp finishLaunching];
     return true;
 }
 
@@ -268,14 +297,6 @@ bool wxIsBusy()
     return (gs_wxBusyCursorCount > 0);
 }
 
-void wxMacGlobalToLocal( WindowRef window , Point*pt )
-{
-}
-
-void wxMacLocalToGlobal( WindowRef window , Point*pt )
-{
-}
-
 wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
 {
     // wxScreenDC is derived from wxWindowDC, so a screen dc will
@@ -298,14 +319,21 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
     NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] retain];
     [view unlockFocus];
 
-    CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
+    wxBitmap bitmap(width, height);
+    if ( [rep respondsToSelector:@selector(CGImage)] )
+    {
+        CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
 
-    wxBitmap bitmap(CGImageGetWidth(cgImageRef)  , CGImageGetHeight(cgImageRef) );
-    CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef)  , CGImageGetHeight(cgImageRef) );
-    // since our context is upside down we dont use CGContextDrawImage
-    wxMacDrawCGImage( (CGContextRef) bitmap.GetHBITMAP() , &r, cgImageRef ) ;
-    CGImageRelease(cgImageRef);
-    cgImageRef = NULL;
+        CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef)  , CGImageGetHeight(cgImageRef) );
+        // since our context is upside down we dont use CGContextDrawImage
+        wxMacDrawCGImage( (CGContextRef) bitmap.GetHBITMAP() , &r, cgImageRef ) ;
+        CGImageRelease(cgImageRef);
+        cgImageRef = NULL;
+    }
+    else
+    {
+        // TODO for 10.4 in case we can support this for osx_cocoa
+    }
     [rep release];
 
     return bitmap;
@@ -313,4 +341,4 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
 
 #endif // wxUSE_GUI
 
-#endif // wxOSX_USE_COCOA
\ No newline at end of file
+#endif // wxOSX_USE_COCOA