1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/iphone/msgdlg.mm
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/msgdlg.h"
21 #include "wx/thread.h"
22 #include "wx/osx/private.h"
23 #include "wx/modalhook.h"
26 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
29 wxMessageDialog::wxMessageDialog(wxWindow *parent,
30 const wxString& message,
31 const wxString& caption,
33 const wxPoint& WXUNUSED(pos))
34 : wxMessageDialogBase(parent, message, caption, style)
38 int wxMessageDialog::ShowModal()
40 WX_HOOK_MODAL_DIALOG();
42 int resultbutton = wxID_CANCEL;
44 const long style = GetMessageDialogStyle();
46 // work out what to display
47 // if the extended text is empty then we use the caption as the title
48 // and the message as the text (for backwards compatibility)
49 // but if the extended message is not empty then we use the message as the title
50 // and the extended message as the text because that makes more sense
52 wxString msgtitle,msgtext;
53 if(m_extendedMessage.IsEmpty())
61 msgtext = m_extendedMessage;
64 wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
65 wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
66 wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding() );
67 wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
69 wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
70 wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
72 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:cfTitle.AsNSString() message:cfText.AsNSString() delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
74 int buttonId[3] = { 0, 0, 0 };
79 if ( style & wxNO_DEFAULT )
81 [alert addButtonWithTitle:cfNoString.AsNSString()];
82 buttonId[ buttonCount++ ] = wxID_NO;
83 [alert addButtonWithTitle:cfYesString.AsNSString()];
84 buttonId[ buttonCount++ ] = wxID_YES;
88 [alert addButtonWithTitle:cfYesString.AsNSString()];
89 buttonId[ buttonCount++ ] = wxID_YES;
90 [alert addButtonWithTitle:cfNoString.AsNSString()];
91 buttonId[ buttonCount++ ] = wxID_NO;
96 [alert addButtonWithTitle:cfCancelString.AsNSString()];
97 buttonId[ buttonCount++ ] = wxID_CANCEL;
100 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
103 [alert addButtonWithTitle:cfOKString.AsNSString()];
104 buttonId[ buttonCount++ ] = wxID_OK;
105 if (style & wxCANCEL)
107 [alert addButtonWithTitle:cfCancelString.AsNSString()];
108 buttonId[ buttonCount++ ] = wxID_CANCEL;
113 wxNonOwnedWindow* parentWindow = NULL;
118 parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
124 NSWindow* nativeParent = parentWindow->GetWXWindow();
125 ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
126 [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate
127 didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
129 [sheetDelegate waitForSheetToFinish];
130 button = [sheetDelegate code];
131 [sheetDelegate release];