]> git.saurik.com Git - wxWidgets.git/commitdiff
Get ShowWindowModal behavior working under OS X Cocoa for file, dir and message dialogs.
authorKevin Ollivier <kevino@theolliviers.com>
Thu, 28 Jan 2010 04:06:23 +0000 (04:06 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Thu, 28 Jan 2010 04:06:23 +0000 (04:06 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63291 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/cocoa/private.h
include/wx/osx/dialog.h
include/wx/osx/dirdlg.h
include/wx/osx/filedlg.h
include/wx/osx/msgdlg.h
src/osx/cocoa/dirdlg.mm
src/osx/cocoa/filedlg.mm
src/osx/cocoa/msgdlg.mm
src/osx/cocoa/utils.mm
src/osx/dialog_osx.cpp

index e7ce32fa9a007161db05850fe5a80100eb394aa5..f7ee0900a47d1e9f7e7da46fdf8ff62b4bb36c97 100644 (file)
@@ -55,6 +55,8 @@ WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef add
 WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
 WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
 
+class WXDLLIMPEXP_FWD_CORE wxDialog;
+
 //
 //
 //
@@ -346,8 +348,10 @@ protected :
     {
         BOOL sheetFinished;
         int resultCode;
+        wxDialog* impl;
     }
 
+    - (void)setImplementation: (wxDialog *)dialog;
     - (BOOL)finished;
     - (int)code;
     - (void)waitForSheetToFinish;
index 17195a318a8db9b168fbdd08c61b6d9da3003eac..77427be8b4a2a05da66bdd56e07d564e340785f9 100644 (file)
@@ -66,6 +66,10 @@ public:
 
     wxDialogModality GetModality() const;
     
+#if wxOSX_USE_COCOA
+    virtual void ModalFinishedCallback(void* WXUNUSED(panel), int WXUNUSED(returnCode)) {}
+#endif
+
 protected:
     // show modal dialog and enter modal loop
     void DoShowModal();
@@ -79,10 +83,10 @@ protected:
     // needed for cleanup on the Cocoa side.
     void EndWindowModal();
 
+    wxDialogModality m_modality;
+
 private:
     void Init();
-
-    wxDialogModality m_modality;
 };
 
 #endif
index 7a40c8524cafbebad2df6b70125da97da76c9bb6..5cb641617ae6d9560260f4102d2dd3fe4c74972d 100644 (file)
@@ -24,6 +24,11 @@ public:
                 const wxString& name = wxDirDialogNameStr);
 
     virtual int ShowModal();
+    
+#if wxOSX_USE_COCOA
+    virtual void ShowWindowModal();
+    virtual void ModalFinishedCallback(void* panel, int returnCode);
+#endif    
 
 protected:
 
index cd2d7c911180236f0e2348d8eaf353d51bdc46bf..d5c17681df1ee39c163c88f0487a2630ff6ef3a8 100644 (file)
@@ -38,6 +38,11 @@ public:
     virtual void GetFilenames(wxArrayString& files) const { files = m_fileNames ; }
 
     virtual int ShowModal();
+    
+#if wxOSX_USE_COCOA
+    virtual void ShowWindowModal();
+    virtual void ModalFinishedCallback(void* panel, int resultCode);
+#endif
 
 protected:
     // not supported for file dialog, RR
index 4ec95ea4a6d3e2791192f2b6a272881dc62d1944..00b54b7df0962291b5ba5452b698bf1e11e2e199 100644 (file)
@@ -23,6 +23,11 @@ public:
                     const wxPoint& pos = wxDefaultPosition);
 
     virtual int ShowModal();
+    
+#if wxOSX_USE_COCOA
+    virtual void ShowWindowModal();
+    virtual void ModalFinishedCallback(void* panel, int resultCode);
+#endif
 
 protected:
     // not supported for message dialog
@@ -30,6 +35,13 @@ protected:
                            int WXUNUSED(width), int WXUNUSED(height),
                            int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
 
+#if wxOSX_USE_COCOA
+    void* ConstructNSAlert();
+#endif
+
+    int m_buttonId[3];
+    int m_buttonCount;
+
     DECLARE_DYNAMIC_CLASS(wxMessageDialog)
 };
 
index 9baab201ae0cfedb2888e407bb438374c71df973..37e32fe813af66a6de1da23c8e292ec01844bbe9 100644 (file)
@@ -47,11 +47,12 @@ wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
     SetPath(defaultPath);
 }
 
-
-int wxDirDialog::ShowModal()
+void wxDirDialog::ShowWindowModal()
 {
-    int result = wxID_CANCEL;
-
+    wxCFStringRef dir( m_path );
+    
+    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
+    
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
@@ -62,47 +63,65 @@ int wxDirDialog::ShowModal()
 
     if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
         [oPanel setCanCreateDirectories:YES];
-
-    wxCFStringRef dir( m_path );
-
-    m_path = wxEmptyString;
-
+    
     wxNonOwnedWindow* parentWindow = NULL;
-    int returnCode = -1;
-
+    
     if (GetParent())
-    {
         parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
-    }
-    else
-    {
-        fprintf(stderr, "No parent!\n");
-    }
-
-/*
+    
+    wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
+    
     if (parentWindow)
     {
         NSWindow* nativeParent = parentWindow->GetWXWindow();
         ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
+        [sheetDelegate setImplementation: this];
         [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
             modalForWindow: nativeParent modalDelegate: sheetDelegate
             didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
             contextInfo: nil];
-        [sheetDelegate waitForSheetToFinish];
-        returnCode = [sheetDelegate code];
-        [sheetDelegate release];
-    }
-    else
-*/
-    {
-        returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil];
     }
+}
+
+int wxDirDialog::ShowModal()
+{
+    NSOpenPanel *oPanel = [NSOpenPanel openPanel];
+    [oPanel setCanChooseDirectories:YES];
+    [oPanel setResolvesAliases:YES];
+    [oPanel setCanChooseFiles:NO];
+
+    wxCFStringRef cf( m_message );
+    [oPanel setMessage:cf.AsNSString()];
+
+    if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
+        [oPanel setCanCreateDirectories:YES];
+
+    wxCFStringRef dir( m_path );
+
+    m_path = wxEmptyString;
+
+    int returnCode = -1;
+
+    returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil];
+    ModalFinishedCallback(oPanel, returnCode);
+
+    return GetReturnCode();
+}
+
+void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
+{
+    int result = wxID_CANCEL;
+
     if (returnCode == NSOKButton )
     {
+        NSOpenPanel* oPanel = (NSOpenPanel*)panel;
         SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
         result = wxID_OK;
     }
-    return result;
+    SetReturnCode(result);
+    
+    if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+        SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }
 
 #endif // wxUSE_DIRDLG
index 916b4e8b7a677880203d9d86de7250b4e27319b7..b4decc5dcd16a48ec2d467141ec57f5c90067b73 100644 (file)
@@ -140,10 +140,63 @@ NSArray* GetTypesFromFilter( const wxString filter )
     return types;
 }
 
-int wxFileDialog::ShowModal()
+void wxFileDialog::ShowWindowModal()
 {
-    int result = wxID_CANCEL;
+    wxCFStringRef cf( m_message );
+    wxCFStringRef dir( m_dir );
+    wxCFStringRef file( m_fileName );
+
+    wxNonOwnedWindow* parentWindow = NULL;
+    
+    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
+
+    if (GetParent())
+        parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
+
+    wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
+    
+    if (HasFlag(wxFD_SAVE))
+    {
+        NSSavePanel* sPanel = [NSSavePanel savePanel];
+        // makes things more convenient:
+        [sPanel setCanCreateDirectories:YES];
+        [sPanel setMessage:cf.AsNSString()];
+        // if we should be able to descend into pacakges we must somehow
+        // be able to pass this in
+        [sPanel setTreatsFilePackagesAsDirectories:NO];
+        [sPanel setCanSelectHiddenExtension:YES];
+        
+        NSWindow* nativeParent = parentWindow->GetWXWindow();
+        ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
+        [sheetDelegate setImplementation: this];
+        [sPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
+            modalForWindow: nativeParent modalDelegate: sheetDelegate
+            didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
+            contextInfo: nil];
+    }
+    else 
+    {
+        NSArray* types = GetTypesFromFilter( m_wildCard ) ;
+        NSOpenPanel* oPanel = [NSOpenPanel openPanel];
+        [oPanel setTreatsFilePackagesAsDirectories:NO];
+        [oPanel setCanChooseDirectories:NO];
+        [oPanel setResolvesAliases:YES];
+        [oPanel setCanChooseFiles:YES];
+        [oPanel setMessage:cf.AsNSString()];
+    
+        NSWindow* nativeParent = parentWindow->GetWXWindow();
+        ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
+        [sheetDelegate setImplementation: this];
+        [oPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
+            types: types modalForWindow: nativeParent
+            modalDelegate: sheetDelegate
+            didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
+            contextInfo: nil];
+    }
+}
 
+int wxFileDialog::ShowModal()
+{
     NSSavePanel *panel = nil;
 
     wxCFStringRef cf( m_message );
@@ -180,34 +233,8 @@ int wxFileDialog::ShowModal()
         {
         }
 
-/*
-        if (parentWindow)
-        {
-            NSWindow* nativeParent = parentWindow->GetWXWindow();
-            ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
-            [sPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
-                modalForWindow: nativeParent modalDelegate: sheetDelegate
-                didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
-                contextInfo: nil];
-            [sheetDelegate waitForSheetToFinish];
-            returnCode = [sheetDelegate code];
-            [sheetDelegate release];
-        }
-        else
-*/
-        {
-            returnCode = [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ];
-        }
-
-        if (returnCode == NSOKButton )
-        {
-            panel = sPanel;
-            result = wxID_OK;
-
-            m_path = wxCFStringRef::AsString([sPanel filename]);
-            m_fileName = wxFileNameFromPath(m_path);
-            m_dir = wxPathOnly( m_path );
-        }
+        returnCode = [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ];
+        ModalFinishedCallback(sPanel, returnCode);
     }
     else
     {
@@ -219,26 +246,36 @@ int wxFileDialog::ShowModal()
         [oPanel setCanChooseFiles:YES];
         [oPanel setMessage:cf.AsNSString()];
 
-/*
-        if (parentWindow)
-        {
-            NSWindow* nativeParent = parentWindow->GetWXWindow();
-            ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
-            [oPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
-                types: types modalForWindow: nativeParent
-                modalDelegate: sheetDelegate
-                didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
-                contextInfo: nil];
-            [sheetDelegate waitForSheetToFinish];
-            returnCode = [sheetDelegate code];
-            [sheetDelegate release];
-        }
-        else
-*/
-        {
-            returnCode = [oPanel runModalForDirectory:dir.AsNSString()
+        returnCode = [oPanel runModalForDirectory:dir.AsNSString()
                         file:file.AsNSString() types:types];
+
+        ModalFinishedCallback(oPanel, returnCode);
+        
+        if ( types != nil )
+            [types release];
+    }
+
+    return GetReturnCode();
+}
+
+void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
+{
+    int result = wxID_CANCEL;
+    if (HasFlag(wxFD_SAVE))
+    {
+        if (returnCode == NSOKButton )
+        {
+            NSSavePanel* sPanel = (NSSavePanel*)panel;
+            result = wxID_OK;
+
+            m_path = wxCFStringRef::AsString([sPanel filename]);
+            m_fileName = wxFileNameFromPath(m_path);
+            m_dir = wxPathOnly( m_path );
         }
+    }
+    else
+    {
+        NSOpenPanel* oPanel = (NSOpenPanel*)panel;
         if (returnCode == NSOKButton )
         {
             panel = oPanel;
@@ -257,11 +294,11 @@ int wxFileDialog::ShowModal()
                 }
             }
         }
-        if ( types != nil )
-            [types release];
     }
-
-    return result;
+    SetReturnCode(result);
+    
+    if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+        SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }
 
 #endif // wxUSE_FILEDLG
index 504e019070a81bdb081363cf6416054c792ad00e..75557ec715a784b34ac276ee3d2415daab57ef39 100644 (file)
@@ -86,7 +86,7 @@ int wxMessageDialog::ShowModal()
         wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding()) ;
         wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
 
-        int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
+        int m_buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
 
         if (style & wxYES_NO)
         {
@@ -94,32 +94,32 @@ int wxMessageDialog::ShowModal()
             {
                 defaultButtonTitle = cfNoString;
                 alternateButtonTitle = cfYesString;
-                buttonId[0] = wxID_NO;
-                buttonId[1] = wxID_YES;
+                m_buttonId[0] = wxID_NO;
+                m_buttonId[1] = wxID_YES;
             }
             else
             {
                 defaultButtonTitle = cfYesString;
                 alternateButtonTitle = cfNoString;
-                buttonId[0] = wxID_YES;
-                buttonId[1] = wxID_NO;
+                m_buttonId[0] = wxID_YES;
+                m_buttonId[1] = wxID_NO;
             }
             if (style & wxCANCEL)
             {
                 otherButtonTitle = cfCancelString;
-                buttonId[2] = wxID_CANCEL;
+                m_buttonId[2] = wxID_CANCEL;
             }
         }
         else
         {
             // the MSW implementation even shows an OK button if it is not specified, we'll do the same
-            buttonId[0] = wxID_OK;
+            m_buttonId[0] = wxID_OK;
             // using null as default title does not work on earlier systems
             defaultButtonTitle = cfOKString;
             if (style & wxCANCEL)
             {
                 alternateButtonTitle = cfCancelString;
-                buttonId[1] = wxID_CANCEL;
+                m_buttonId[1] = wxID_CANCEL;
             }
         }
 
@@ -128,99 +128,135 @@ int wxMessageDialog::ShowModal()
             0, alertType, NULL, NULL, NULL, cfTitle, cfText,
             defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton );
         if (err == noErr)
-            resultbutton = buttonId[exitButton];
+            resultbutton = m_buttonId[exitButton];
     }
     else
     {
-        NSAlert* alert = [[NSAlert alloc] init];
+        NSAlert* alert = (NSAlert*)ConstructNSAlert();
 
-        wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
-        wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
-        wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding() );
-        wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
+        int button = -1;
+        button = [alert runModal];
+        [alert release];
+        ModalFinishedCallback(alert, button);
+    }
 
-        wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
-        wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
+    return GetReturnCode();
+}
 
-        [alert setMessageText:cfTitle.AsNSString()];
-        [alert setInformativeText:cfText.AsNSString()];
+void wxMessageDialog::ShowWindowModal()
+{
+    NSAlert* alert = (NSAlert*)ConstructNSAlert();
 
-        int buttonId[3] = { 0, 0, 0 };
-        int buttonCount = 0;
+    wxNonOwnedWindow* parentWindow = NULL;
 
-        if (style & wxYES_NO)
-        {
-            if ( style & wxNO_DEFAULT )
-            {
-                [alert addButtonWithTitle:cfNoString.AsNSString()];
-                buttonId[ buttonCount++ ] = wxID_NO;
-                [alert addButtonWithTitle:cfYesString.AsNSString()];
-                buttonId[ buttonCount++ ] = wxID_YES;
-            }
-            else
-            {
-                [alert addButtonWithTitle:cfYesString.AsNSString()];
-                buttonId[ buttonCount++ ] = wxID_YES;
-                [alert addButtonWithTitle:cfNoString.AsNSString()];
-                buttonId[ buttonCount++ ] = wxID_NO;
-            }
+    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
 
-            if (style & wxCANCEL)
-            {
-                [alert addButtonWithTitle:cfCancelString.AsNSString()];
-                buttonId[ buttonCount++ ] = wxID_CANCEL;
-            }
-        }
-        // the MSW implementation even shows an OK button if it is not specified, we'll do the same
+    if (GetParent())
+        parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
+
+    wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
+
+    if (parentWindow)
+    {
+        NSWindow* nativeParent = parentWindow->GetWXWindow();
+        ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
+        [sheetDelegate setImplementation: this];
+        [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate
+            didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
+            contextInfo: nil];
+    }
+}
+
+void wxMessageDialog::ModalFinishedCallback(void* panel, int resultCode)
+{
+    int resultbutton = wxID_CANCEL;
+    if ( resultCode < NSAlertFirstButtonReturn )
+        resultbutton = wxID_CANCEL;
+    else
+    {
+        if ( resultCode - NSAlertFirstButtonReturn < m_buttonCount )
+            resultbutton = m_buttonId[ resultCode - NSAlertFirstButtonReturn ];
         else
-        {
-            [alert addButtonWithTitle:cfOKString.AsNSString()];
-            buttonId[ buttonCount++ ] = wxID_OK;
-            if (style & wxCANCEL)
-            {
-                [alert addButtonWithTitle:cfCancelString.AsNSString()];
-                buttonId[ buttonCount++ ] = wxID_CANCEL;
-            }
-        }
+            resultbutton = wxID_CANCEL;
+    }
+    SetReturnCode(resultbutton);
+    
+    if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+        SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
+}
 
+void* wxMessageDialog::ConstructNSAlert()
+{
+    const long style = GetMessageDialogStyle();
 
-        wxNonOwnedWindow* parentWindow = NULL;
-        int button = -1;
+    wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
 
-        if (GetParent())
-        {
-            parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
-        }
+    // work out what to display
+    // if the extended text is empty then we use the caption as the title
+    // and the message as the text (for backwards compatibility)
+    // but if the extended message is not empty then we use the message as the title
+    // and the extended message as the text because that makes more sense
 
- /*
-        if (parentWindow)
+    wxString msgtitle,msgtext;
+    if(m_extendedMessage.IsEmpty())
+    {
+        msgtitle = m_caption;
+        msgtext  = m_message;
+    }
+    else
+    {
+        msgtitle = m_message;
+        msgtext  = m_extendedMessage;
+    }
+
+    NSAlert* alert = [[NSAlert alloc] init];
+
+    wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
+    wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
+    wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding() );
+    wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
+
+    wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
+    wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
+
+    [alert setMessageText:cfTitle.AsNSString()];
+    [alert setInformativeText:cfText.AsNSString()];
+
+    m_buttonCount = 0;
+
+    if (style & wxYES_NO)
+    {
+        if ( style & wxNO_DEFAULT )
         {
-            NSWindow* nativeParent = parentWindow->GetWXWindow();
-            ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
-            [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate
-                didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
-                contextInfo: nil];
-            [sheetDelegate waitForSheetToFinish];
-            button = [sheetDelegate code];
-            [sheetDelegate release];
+            [alert addButtonWithTitle:cfNoString.AsNSString()];
+            m_buttonId[ m_buttonCount++ ] = wxID_NO;
+            [alert addButtonWithTitle:cfYesString.AsNSString()];
+            m_buttonId[ m_buttonCount++ ] = wxID_YES;
         }
         else
-*/
         {
-            button = [alert runModal];
+            [alert addButtonWithTitle:cfYesString.AsNSString()];
+            m_buttonId[ m_buttonCount++ ] = wxID_YES;
+            [alert addButtonWithTitle:cfNoString.AsNSString()];
+            m_buttonId[ m_buttonCount++ ] = wxID_NO;
         }
-        [alert release];
 
-        if ( button < NSAlertFirstButtonReturn )
-            resultbutton = wxID_CANCEL;
-        else
+        if (style & wxCANCEL)
         {
-            if ( button - NSAlertFirstButtonReturn < buttonCount )
-                resultbutton = buttonId[ button - NSAlertFirstButtonReturn ];
-            else
-                resultbutton = wxID_CANCEL;
+            [alert addButtonWithTitle:cfCancelString.AsNSString()];
+            m_buttonId[ m_buttonCount++ ] = wxID_CANCEL;
         }
     }
-
-    return resultbutton;
+    // the MSW implementation even shows an OK button if it is not specified, we'll do the same
+    else
+    {
+        [alert addButtonWithTitle:cfOKString.AsNSString()];
+        m_buttonId[ m_buttonCount++ ] = wxID_OK;
+        if (style & wxCANCEL)
+        {
+            [alert addButtonWithTitle:cfCancelString.AsNSString()];
+            m_buttonId[ m_buttonCount++ ] = wxID_CANCEL;
+        }
+    }
+    return alert;
 }
index 36ce2bb0d4fe99836b4f427ce55e8ad3c0555bd6..53abbfcf5761ba1668b7daf3ec3056727de0e770 100644 (file)
 
 #include "wx/wxprec.h"
 
-#include "wx/wxprec.h"
-
 #include "wx/utils.h"
 
 #ifndef WX_PRECOMP
     #include "wx/intl.h"
     #include "wx/app.h"
     #if wxUSE_GUI
+        #include "wx/dialog.h"
         #include "wx/toplevel.h"
         #include "wx/font.h"
     #endif
@@ -176,9 +175,15 @@ void wxMacWakeUp()
     [super init];
     sheetFinished = NO;
     resultCode = -1;
+    impl = 0;
     return self;
 }
 
+- (void)setImplementation: (wxDialog *)dialog
+{
+    impl = dialog;
+}
+
 - (BOOL)finished
 {
     return sheetFinished;
@@ -205,6 +210,9 @@ void wxMacWakeUp()
     // NSAlerts don't need nor respond to orderOut
     if ([sheet respondsToSelector:@selector(orderOut:)])
         [sheet orderOut: self];
+        
+    if (impl)
+        impl->ModalFinishedCallback(sheet, returnCode);
 }
 @end
 
index 02bde473d33da25fcdd5e222a92a2f214d013031..1408ea0fb305cc43b64a0348e2a672897145e926 100644 (file)
@@ -122,7 +122,7 @@ bool wxDialog::Show(bool show)
 // Replacement for Show(true) for modal dialogs - returns return code
 int wxDialog::ShowModal()
 {
-    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
+    m_modality = wxDIALOG_MODALITY_APP_MODAL;
     
     Show();