]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/msgdlg.mm
fixed typo in XRC error message
[wxWidgets.git] / src / osx / cocoa / msgdlg.mm
index bf82c5c9565ffea58b71f36cac94ad03768e726a..255576afd133f258529c75aa178252b19ff9300c 100644 (file)
@@ -30,40 +30,8 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent,
                                  const wxString& caption,
                                  long style,
                                  const wxPoint& WXUNUSED(pos))
-               : wxMessageDialogBase(parent, message, caption, style)
+               : wxMessageDialogWithCustomLabels(parent, message, caption, style)
 {
-    m_yes = _("Yes");
-    m_no  = _("No");
-    m_ok  = _("OK");
-    m_cancel = _("Cancel");
-}
-
-bool wxMessageDialog::SetYesNoLabels(const wxString& yes,const wxString& no)
-{
-    m_yes = yes;
-    m_no = no;
-    return true;
-}
-
-bool wxMessageDialog::SetYesNoCancelLabels(const wxString& yes, const wxString& no, const wxString& cancel)
-{
-    m_yes = yes;
-    m_no = no;
-    m_cancel = cancel;
-    return true;
-}
-
-bool wxMessageDialog::SetOKLabel(const wxString& ok)
-{
-    m_ok = ok;
-    return true;
-}
-
-bool wxMessageDialog::SetOKCancelLabels(const wxString& ok, const wxString& cancel)
-{
-    m_ok = ok;
-    m_cancel = cancel;
-    return true;
 }
 
 int wxMessageDialog::ShowModal()
@@ -74,15 +42,15 @@ int wxMessageDialog::ShowModal()
 
     wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
 
-    AlertType alertType = kAlertPlainAlert;
+    NSAlertStyle alertType = NSWarningAlertStyle;
     if (style & wxICON_EXCLAMATION)
-        alertType = kAlertCautionAlert;
+        alertType = NSCriticalAlertStyle;
     else if (style & wxICON_HAND)
-        alertType = kAlertStopAlert;
+        alertType = NSWarningAlertStyle;
     else if (style & wxICON_INFORMATION)
-        alertType = kAlertNoteAlert;
+        alertType = NSInformationalAlertStyle;
     else if (style & wxICON_QUESTION)
-        alertType = kAlertNoteAlert;
+        alertType = NSInformationalAlertStyle;
 
 
     // work out what to display
@@ -113,10 +81,10 @@ int wxMessageDialog::ShowModal()
         wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
         wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
 
-        wxCFStringRef cfNoString( m_no.c_str(), GetFont().GetEncoding() );
-        wxCFStringRef cfYesString( m_yes.c_str(), GetFont().GetEncoding() );
-        wxCFStringRef cfOKString( m_ok.c_str() , GetFont().GetEncoding()) ;
-        wxCFStringRef cfCancelString( m_cancel.c_str(), GetFont().GetEncoding() );
+        wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
+        wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
+        wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding()) ;
+        wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
 
         int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
 
@@ -164,119 +132,69 @@ int wxMessageDialog::ShowModal()
     }
     else
     {
-        short result;
-
-        AlertStdCFStringAlertParamRec param;
-        wxCFStringRef cfNoString( m_no.c_str(), GetFont().GetEncoding() );
-        wxCFStringRef cfYesString( m_yes.c_str(), GetFont().GetEncoding() );
-        wxCFStringRef cfOKString( m_ok.c_str(), GetFont().GetEncoding() );
-        wxCFStringRef cfCancelString( m_cancel.c_str(), GetFont().GetEncoding() );
+        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() );
 
-        param.movable = true;
-        param.flags = 0;
-        param.version = kStdCFStringAlertVersionOne;
-
-        bool skipDialog = false;
+        [alert setMessageText:cfTitle.AsNSString()];
+        [alert setInformativeText:cfText.AsNSString()];
+        
+        int buttonId[3] = { 0, 0, 0 };
+        int buttonCount = 0;
 
         if (style & wxYES_NO)
         {
-            if (style & wxCANCEL)
+            if ( style & wxNO_DEFAULT )
             {
-                param.defaultText = cfYesString;
-                param.cancelText = cfCancelString;
-                param.otherText = cfNoString;
-                param.helpButton = false;
-                param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
-                param.cancelButton = kAlertStdAlertCancelButton;
+                [alert addButtonWithTitle:cfNoString.AsNSString()];
+                buttonId[ buttonCount++ ] = wxID_NO;
+                [alert addButtonWithTitle:cfYesString.AsNSString()];
+                buttonId[ buttonCount++ ] = wxID_YES;
             }
             else
             {
-                param.defaultText = cfYesString;
-                param.cancelText = NULL;
-                param.otherText = cfNoString;
-                param.helpButton = false;
-                param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
-                param.cancelButton = 0;
+                [alert addButtonWithTitle:cfYesString.AsNSString()];
+                buttonId[ buttonCount++ ] = wxID_YES;
+                [alert addButtonWithTitle:cfNoString.AsNSString()];
+                buttonId[ buttonCount++ ] = wxID_NO;
+            }
+
+            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
         else
         {
+            [alert addButtonWithTitle:cfOKString.AsNSString()];
+            buttonId[ buttonCount++ ] = wxID_OK;
             if (style & wxCANCEL)
             {
-                // that's a cancel missing
-                param.defaultText = cfOKString;
-                param.cancelText = cfCancelString;
-                param.otherText = NULL;
-                param.helpButton = false;
-                param.defaultButton = kAlertStdAlertOKButton;
-                param.cancelButton = 0;
-            }
-            else
-            {
-                param.defaultText = cfOKString;
-                param.cancelText = NULL;
-                param.otherText = NULL;
-                param.helpButton = false;
-                param.defaultButton = kAlertStdAlertOKButton;
-                param.cancelButton = 0;
+                [alert addButtonWithTitle:cfCancelString.AsNSString()];
+                buttonId[ buttonCount++ ] = wxID_CANCEL;
             }
         }
 
-        param.position = kWindowDefaultPosition;
-        if ( !skipDialog )
-        {
-            DialogRef alertRef;
-            CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
-            RunStandardAlert( alertRef, NULL, &result );
-        }
+        int button = [alert runModal];
+        
+        [alert release];
+        
+        if ( button < NSAlertFirstButtonReturn )
+            resultbutton = wxID_CANCEL;
         else
         {
-            return wxID_CANCEL;
-        }
-
-        if (style & wxOK)
-        {
-            switch ( result )
-            {
-            case 1:
-                resultbutton = wxID_OK;
-                break;
-
-            case 2:
-                // TODO: add Cancel button
-                // if (style & wxCANCEL)
-                //     resultbutton = wxID_CANCEL;
-                break;
-
-            case 3:
-            default:
-                break;
-            }
-        }
-        else if (style & wxYES_NO)
-        {
-            switch ( result )
-            {
-            case 1:
-                resultbutton = wxID_YES;
-                break;
-
-            case 2:
-                if (!(style & wxCANCEL))
-                    resultbutton = wxID_CANCEL;
-                break;
-
-            case 3:
-                resultbutton = wxID_NO;
-                break;
-
-            default:
-                break;
-            }
+            if ( button - NSAlertFirstButtonReturn < buttonCount )
+                resultbutton = buttonId[ button - NSAlertFirstButtonReturn ];
+            else
+                resultbutton = wxID_CANCEL;
         }
     }