1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/iphone/msgdlg.mm
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/msgdlg.h"
20 #include "wx/thread.h"
21 #include "wx/osx/private.h"
22 #include "wx/modalhook.h"
25 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
28 wxMessageDialog::wxMessageDialog(wxWindow *parent,
29 const wxString& message,
30 const wxString& caption,
32 const wxPoint& WXUNUSED(pos))
33 : wxMessageDialogBase(parent, message, caption, style)
37 int wxMessageDialog::ShowModal()
39 WX_HOOK_MODAL_DIALOG();
41 int resultbutton = wxID_CANCEL;
43 const long style = GetMessageDialogStyle();
45 // work out what to display
46 // if the extended text is empty then we use the caption as the title
47 // and the message as the text (for backwards compatibility)
48 // but if the extended message is not empty then we use the message as the title
49 // and the extended message as the text because that makes more sense
51 wxString msgtitle,msgtext;
52 if(m_extendedMessage.IsEmpty())
60 msgtext = m_extendedMessage;
63 wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
64 wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
65 wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding() );
66 wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
68 wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
69 wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
71 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:cfTitle.AsNSString() message:cfText.AsNSString() delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
73 int buttonId[3] = { 0, 0, 0 };
78 if ( style & wxNO_DEFAULT )
80 [alert addButtonWithTitle:cfNoString.AsNSString()];
81 buttonId[ buttonCount++ ] = wxID_NO;
82 [alert addButtonWithTitle:cfYesString.AsNSString()];
83 buttonId[ buttonCount++ ] = wxID_YES;
87 [alert addButtonWithTitle:cfYesString.AsNSString()];
88 buttonId[ buttonCount++ ] = wxID_YES;
89 [alert addButtonWithTitle:cfNoString.AsNSString()];
90 buttonId[ buttonCount++ ] = wxID_NO;
95 [alert addButtonWithTitle:cfCancelString.AsNSString()];
96 buttonId[ buttonCount++ ] = wxID_CANCEL;
99 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
102 [alert addButtonWithTitle:cfOKString.AsNSString()];
103 buttonId[ buttonCount++ ] = wxID_OK;
104 if (style & wxCANCEL)
106 [alert addButtonWithTitle:cfCancelString.AsNSString()];
107 buttonId[ buttonCount++ ] = wxID_CANCEL;
112 wxNonOwnedWindow* parentWindow = NULL;
117 parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
123 NSWindow* nativeParent = parentWindow->GetWXWindow();
124 ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
125 [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate
126 didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
128 [sheetDelegate waitForSheetToFinish];
129 button = [sheetDelegate code];
130 [sheetDelegate release];