+ 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 (parentWindow)
+ {
+ NSWindow* nativeParent = parentWindow->GetWXWindow();
+ [alert beginSheetModalForWindow: nativeParent modalDelegate: m_sheetDelegate
+ didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo: nil];
+ }
+}
+
+void wxMessageDialog::ModalFinishedCallback(void* WXUNUSED(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
+ resultbutton = wxID_CANCEL;
+ }
+ SetReturnCode(resultbutton);
+
+ if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+ SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
+}
+
+void* wxMessageDialog::ConstructNSAlert()
+{
+ const long style = GetMessageDialogStyle();
+
+ wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
+
+ // 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
+
+ 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];
+ NSAlertStyle alertType = GetAlertStyleFromWXStyle(style);
+
+ wxCFStringRef cfNoString( wxControl::GetLabelText(GetNoLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfYesString( wxControl::GetLabelText(GetYesLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfOKString( wxControl::GetLabelText(GetOKLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfCancelString( wxControl::GetLabelText(GetCancelLabel()), GetFont().GetEncoding() );
+
+ wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
+ wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
+
+ [alert setMessageText:cfTitle.AsNSString()];
+ [alert setInformativeText:cfText.AsNSString()];
+ [alert setAlertStyle:alertType];
+
+ m_buttonCount = 0;
+
+ if (style & wxYES_NO)
+ {
+ if ( style & wxNO_DEFAULT )
+ {
+ [alert addButtonWithTitle:cfNoString.AsNSString()];
+ m_buttonId[ m_buttonCount++ ] = wxID_NO;
+ [alert addButtonWithTitle:cfYesString.AsNSString()];
+ m_buttonId[ m_buttonCount++ ] = wxID_YES;