]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/osx/iphone/msgdlg.mm | |
3 | // Purpose: wxMessageDialog | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
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" | |
23 | #include "wx/testing.h" | |
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)) | |
34 | : wxMessageDialogBase(parent, message, caption, style) | |
35 | { | |
36 | } | |
37 | ||
38 | int wxMessageDialog::ShowModal() | |
39 | { | |
40 | WX_TESTING_SHOW_MODAL_HOOK(); | |
41 | ||
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 | } | |
63 | ||
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]; | |
73 | ||
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; | |
115 | ||
116 | if (GetParent()) | |
117 | { | |
118 | parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent())); | |
119 | } | |
120 | ||
121 | /* | |
122 | if (parentWindow) | |
123 | { | |
124 | NSWindow* nativeParent = parentWindow->GetWXWindow(); | |
125 | ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init]; | |
126 | [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate | |
127 | didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) | |
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]; | |
139 | ||
140 | return wxID_CANCEL; | |
141 | } |