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