The rounded corners look really dumb at this size.
[wxWidgets.git] / src / osx / iphone / msgdlg.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/osx/iphone/msgdlg.mm
3 // Purpose:     wxMessageDialog
4 // Author:      Stefan Csomor
5 // Modified by:
6 // Created:     04/01/98
7 // Copyright:   (c) Stefan Csomor
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #include "wx/msgdlg.h"
14
15 #ifndef WX_PRECOMP
16     #include "wx/intl.h"
17     #include "wx/app.h"
18 #endif
19
20 #include "wx/thread.h"
21 #include "wx/osx/private.h"
22 #include "wx/modalhook.h"
23
24
25 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
26
27
28 wxMessageDialog::wxMessageDialog(wxWindow *parent,
29                                  const wxString& message,
30                                  const wxString& caption,
31                                  long style,
32                                  const wxPoint& WXUNUSED(pos))
33                : wxMessageDialogBase(parent, message, caption, style)
34 {
35 }
36
37 int wxMessageDialog::ShowModal()
38 {
39     WX_HOOK_MODAL_DIALOG();
40
41     int resultbutton = wxID_CANCEL;
42
43     const long style = GetMessageDialogStyle();
44
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
50
51     wxString msgtitle,msgtext;
52     if(m_extendedMessage.IsEmpty())
53     {
54         msgtitle = m_caption;
55         msgtext  = m_message;
56     }
57     else
58     {
59         msgtitle = m_message;
60         msgtext  = m_extendedMessage;
61     }
62
63     wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
64     wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
65     wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding() );
66     wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
67
68     wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
69     wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
70
71     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:cfTitle.AsNSString() message:cfText.AsNSString() delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
72
73     int buttonId[3] = { 0, 0, 0 };
74     int buttonCount = 0;
75
76     if (style & wxYES_NO)
77     {
78         if ( style & wxNO_DEFAULT )
79         {
80             [alert addButtonWithTitle:cfNoString.AsNSString()];
81             buttonId[ buttonCount++ ] = wxID_NO;
82             [alert addButtonWithTitle:cfYesString.AsNSString()];
83             buttonId[ buttonCount++ ] = wxID_YES;
84         }
85         else
86         {
87             [alert addButtonWithTitle:cfYesString.AsNSString()];
88             buttonId[ buttonCount++ ] = wxID_YES;
89             [alert addButtonWithTitle:cfNoString.AsNSString()];
90             buttonId[ buttonCount++ ] = wxID_NO;
91         }
92
93         if (style & wxCANCEL)
94         {
95             [alert addButtonWithTitle:cfCancelString.AsNSString()];
96             buttonId[ buttonCount++ ] = wxID_CANCEL;
97         }
98     }
99     // the MSW implementation even shows an OK button if it is not specified, we'll do the same
100     else
101     {
102         [alert addButtonWithTitle:cfOKString.AsNSString()];
103         buttonId[ buttonCount++ ] = wxID_OK;
104         if (style & wxCANCEL)
105         {
106             [alert addButtonWithTitle:cfCancelString.AsNSString()];
107             buttonId[ buttonCount++ ] = wxID_CANCEL;
108         }
109     }
110
111
112     wxNonOwnedWindow* parentWindow = NULL;
113     int button = -1;
114
115     if (GetParent())
116     {
117         parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
118     }
119
120 /*
121     if (parentWindow)
122     {
123         NSWindow* nativeParent = parentWindow->GetWXWindow();
124         ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
125         [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate
126             didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
127             contextInfo: nil];
128         [sheetDelegate waitForSheetToFinish];
129         button = [sheetDelegate code];
130         [sheetDelegate release];
131     }
132     else
133 */
134     {
135         [alert show];
136     }
137     // [alert release];
138
139     return wxID_CANCEL;
140 }