1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/iphone/msgdlg.mm
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: msgdlg.cpp 54129 2008-06-11 19:30:52Z SC $
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"
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 int resultbutton = wxID_CANCEL;
41 const long style = GetMessageDialogStyle();
43 // work out what to display
44 // if the extended text is empty then we use the caption as the title
45 // and the message as the text (for backwards compatibility)
46 // but if the extended message is not empty then we use the message as the title
47 // and the extended message as the text because that makes more sense
49 wxString msgtitle,msgtext;
50 if(m_extendedMessage.IsEmpty())
58 msgtext = m_extendedMessage;
61 wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
62 wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
63 wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding() );
64 wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
66 wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
67 wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
69 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:cfTitle.AsNSString() message:cfText.AsNSString() delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
71 int buttonId[3] = { 0, 0, 0 };
76 if ( style & wxNO_DEFAULT )
78 [alert addButtonWithTitle:cfNoString.AsNSString()];
79 buttonId[ buttonCount++ ] = wxID_NO;
80 [alert addButtonWithTitle:cfYesString.AsNSString()];
81 buttonId[ buttonCount++ ] = wxID_YES;
85 [alert addButtonWithTitle:cfYesString.AsNSString()];
86 buttonId[ buttonCount++ ] = wxID_YES;
87 [alert addButtonWithTitle:cfNoString.AsNSString()];
88 buttonId[ buttonCount++ ] = wxID_NO;
93 [alert addButtonWithTitle:cfCancelString.AsNSString()];
94 buttonId[ buttonCount++ ] = wxID_CANCEL;
97 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
100 [alert addButtonWithTitle:cfOKString.AsNSString()];
101 buttonId[ buttonCount++ ] = wxID_OK;
102 if (style & wxCANCEL)
104 [alert addButtonWithTitle:cfCancelString.AsNSString()];
105 buttonId[ buttonCount++ ] = wxID_CANCEL;
110 wxNonOwnedWindow* parentWindow = NULL;
115 parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
121 NSWindow* nativeParent = parentWindow->GetWXWindow();
122 ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
123 [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate
124 didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
126 [sheetDelegate waitForSheetToFinish];
127 button = [sheetDelegate code];
128 [sheetDelegate release];