]>
Commit | Line | Data |
---|---|---|
e9871aaf DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/cocoa/dirdlg.mm | |
3 | // Purpose: wxMessageDialog for wxCocoa | |
4 | // Author: Gareth Simpson | |
5 | // Created: 2007-10-09 | |
6 | // Licence: wxWindows licence | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | // ============================================================================ | |
10 | // declarations | |
11 | // ============================================================================ | |
12 | ||
13 | // ---------------------------------------------------------------------------- | |
14 | // headers | |
15 | // ---------------------------------------------------------------------------- | |
16 | ||
17 | // For compilers that support precompilation, includes "wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #if wxUSE_MSGDLG | |
21 | ||
22 | ||
23 | #include "wx/msgdlg.h" | |
24 | ||
25 | ||
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/app.h" | |
28 | #endif | |
29 | ||
30 | ||
31 | #include "wx/cocoa/autorelease.h" | |
32 | #include "wx/cocoa/string.h" | |
691745ab | 33 | #include "wx/modalhook.h" |
e9871aaf DE |
34 | |
35 | #import <AppKit/NSAlert.h> | |
36 | // ============================================================================ | |
37 | // implementation | |
38 | // ============================================================================ | |
39 | ||
40 | IMPLEMENT_CLASS(wxCocoaMessageDialog, wxDialog) | |
41 | ||
42 | // ---------------------------------------------------------------------------- | |
43 | // wxDirDialog | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | wxCocoaMessageDialog::wxCocoaMessageDialog(wxWindow *parent, | |
23e00c55 VZ |
47 | const wxString& message, |
48 | const wxString& caption, | |
49 | long style, | |
50 | const wxPoint& pos) | |
51 | : wxMessageDialogWithCustomLabels(parent, message, caption, style) | |
e9871aaf DE |
52 | { |
53 | ||
e5633f9a | 54 | wxTopLevelWindows.Append(this); |
e9871aaf DE |
55 | |
56 | wxASSERT(CreateBase(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr)); | |
57 | ||
58 | if ( parent ) | |
59 | parent->AddChild(this); | |
60 | ||
61 | ||
62 | m_cocoaNSWindow = nil; | |
63 | m_cocoaNSView = nil; | |
e9871aaf DE |
64 | } |
65 | ||
e08931c0 | 66 | void wxCocoaMessageDialog::DoSetCustomLabel(wxString& var, const ButtonLabel& value) |
e9871aaf | 67 | { |
23e00c55 VZ |
68 | wxMessageDialogWithCustomLabels::DoSetCustomLabel(var, value); |
69 | ||
70 | var.Replace("&", ""); | |
e9871aaf DE |
71 | } |
72 | ||
73 | int wxCocoaMessageDialog::ShowModal() | |
74 | { | |
691745ab | 75 | WX_HOOK_MODAL_DIALOG(); |
643e9cf9 | 76 | |
e5633f9a DE |
77 | wxAutoNSAutoreleasePool thePool; |
78 | ||
79 | NSAlert *alert = [[[NSAlert alloc] init] autorelease]; | |
e9871aaf | 80 | |
e9871aaf DE |
81 | const long style = GetMessageDialogStyle(); |
82 | ||
83 | NSAlertStyle nsStyle = NSInformationalAlertStyle; | |
a4578b0c VZ |
84 | |
85 | switch ( GetEffectiveIcon() ) | |
86 | { | |
87 | case wxICON_ERROR: | |
88 | nsStyle = NSCriticalAlertStyle; | |
89 | break; | |
90 | ||
91 | case wxICON_WARNING: | |
92 | nsStyle = NSWarningAlertStyle; | |
93 | break; | |
94 | } | |
e9871aaf | 95 | |
e5633f9a DE |
96 | [alert setAlertStyle:nsStyle]; |
97 | ||
98 | ||
99 | ||
100 | ||
e9871aaf DE |
101 | // work out what to display |
102 | // if the extended text is empty then we use the caption as the title | |
103 | // and the message as the text (for backwards compatibility) | |
104 | // but if the extended message is not empty then we use the message as the title | |
105 | // and the extended message as the text because that makes more sense | |
e5633f9a DE |
106 | if (m_extendedMessage.empty()) |
107 | { | |
108 | [alert setMessageText:wxNSStringWithWxString(m_caption)]; | |
109 | [alert setInformativeText:wxNSStringWithWxString(m_message)]; | |
110 | } | |
111 | else | |
112 | { | |
113 | [alert setMessageText:wxNSStringWithWxString(m_message)]; | |
114 | [alert setInformativeText:wxNSStringWithWxString(m_extendedMessage)]; | |
115 | } | |
116 | ||
117 | // The wxReturn value corresponding to each button | |
118 | int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; | |
119 | if (style & wxYES_NO) | |
120 | { | |
121 | if ( style & wxNO_DEFAULT ) | |
122 | { | |
23e00c55 VZ |
123 | [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())]; |
124 | [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())]; | |
e5633f9a DE |
125 | buttonId[0] = wxID_NO; |
126 | buttonId[1] = wxID_YES; | |
127 | } | |
128 | else | |
129 | { | |
23e00c55 VZ |
130 | [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())]; |
131 | [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())]; | |
e5633f9a DE |
132 | buttonId[0] = wxID_YES; |
133 | buttonId[1] = wxID_NO; | |
134 | } | |
135 | if (style & wxCANCEL) | |
136 | { | |
23e00c55 | 137 | [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())]; |
e5633f9a DE |
138 | buttonId[2] = wxID_CANCEL; |
139 | } | |
140 | } | |
141 | else | |
142 | { | |
143 | // the MSW implementation even shows an OK button if it is not specified, we'll do the same | |
144 | buttonId[0] = wxID_OK; | |
145 | // using null as default title does not work on earlier systems | |
23e00c55 | 146 | [alert addButtonWithTitle:wxNSStringWithWxString(GetOKLabel())]; |
e5633f9a DE |
147 | if (style & wxCANCEL) |
148 | { | |
23e00c55 | 149 | [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())]; |
e5633f9a DE |
150 | buttonId[1] = wxID_CANCEL; |
151 | } | |
152 | } | |
153 | ||
154 | int ret = [alert runModal]; | |
155 | ||
156 | ||
157 | return buttonId[ret-NSAlertFirstButtonReturn]; | |
e9871aaf DE |
158 | } |
159 | ||
e9871aaf | 160 | #endif // wxUSE_DIRDLG |
dcb68102 | 161 |