]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/msgdlg.mm
Implement wxIcon::LoadFile by defering to wxBitmap implementation instead of creating...
[wxWidgets.git] / src / cocoa / msgdlg.mm
CommitLineData
e9871aaf
DE
1 /////////////////////////////////////////////////////////////////////////////
2// Name: src/cocoa/dirdlg.mm
3// Purpose: wxMessageDialog for wxCocoa
4// Author: Gareth Simpson
5// Created: 2007-10-09
e5633f9a 6// RCS-ID: $Id$
e9871aaf
DE
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// ============================================================================
11// declarations
12// ============================================================================
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
18// For compilers that support precompilation, includes "wx.h".
19#include "wx/wxprec.h"
20
21#if wxUSE_MSGDLG
22
23
24#include "wx/msgdlg.h"
25
26
27#ifndef WX_PRECOMP
28 #include "wx/app.h"
29#endif
30
31
32#include "wx/cocoa/autorelease.h"
33#include "wx/cocoa/string.h"
34
35#import <AppKit/NSAlert.h>
36// ============================================================================
37// implementation
38// ============================================================================
39
40IMPLEMENT_CLASS(wxCocoaMessageDialog, wxDialog)
41
42// ----------------------------------------------------------------------------
43// wxDirDialog
44// ----------------------------------------------------------------------------
45
46wxCocoaMessageDialog::wxCocoaMessageDialog(wxWindow *parent,
47 const wxString& message,
48 const wxString& caption,
49 long style,
e5633f9a 50 const wxPoint& pos) : wxMessageDialogBase(parent,message,caption,style)
e9871aaf
DE
51{
52
e5633f9a
DE
53 //m_caption = caption;
54 //m_message = message;
e9871aaf
DE
55
56 //wxTopLevelWindows.Append((wxWindowBase*)this);
e5633f9a 57 wxTopLevelWindows.Append(this);
e9871aaf
DE
58
59 wxASSERT(CreateBase(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
60
61 if ( parent )
62 parent->AddChild(this);
63
64
65 m_cocoaNSWindow = nil;
66 m_cocoaNSView = nil;
e5633f9a 67
e9871aaf
DE
68 m_yes = _("Yes");
69 m_no = _("No");
70 m_ok = _("OK");
71 m_cancel = _("Cancel");
72
73}
74
75wxCocoaMessageDialog::~wxCocoaMessageDialog()
76{
77}
78
79int wxCocoaMessageDialog::ShowModal()
80{
e5633f9a
DE
81 wxAutoNSAutoreleasePool thePool;
82
83 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
e9871aaf 84
e9871aaf
DE
85 const long style = GetMessageDialogStyle();
86
87 NSAlertStyle nsStyle = NSInformationalAlertStyle;
88 if (style & wxICON_EXCLAMATION)
89 nsStyle = NSWarningAlertStyle;
90 else if (style & wxICON_HAND)
91 nsStyle = NSCriticalAlertStyle;
92 else if (style & wxICON_INFORMATION)
93 nsStyle = NSInformationalAlertStyle;
94 else if (style & wxICON_QUESTION)
95 nsStyle = NSInformationalAlertStyle;
e9871aaf 96
e5633f9a
DE
97 [alert setAlertStyle:nsStyle];
98
99
100
101
e9871aaf
DE
102 // work out what to display
103 // if the extended text is empty then we use the caption as the title
104 // and the message as the text (for backwards compatibility)
105 // but if the extended message is not empty then we use the message as the title
106 // and the extended message as the text because that makes more sense
e5633f9a
DE
107 if (m_extendedMessage.empty())
108 {
109 [alert setMessageText:wxNSStringWithWxString(m_caption)];
110 [alert setInformativeText:wxNSStringWithWxString(m_message)];
111 }
112 else
113 {
114 [alert setMessageText:wxNSStringWithWxString(m_message)];
115 [alert setInformativeText:wxNSStringWithWxString(m_extendedMessage)];
116 }
117
118 // The wxReturn value corresponding to each button
119 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
120 if (style & wxYES_NO)
121 {
122 if ( style & wxNO_DEFAULT )
123 {
124 [alert addButtonWithTitle:wxNSStringWithWxString(m_no)];
125 [alert addButtonWithTitle:wxNSStringWithWxString(m_yes)];
126 buttonId[0] = wxID_NO;
127 buttonId[1] = wxID_YES;
128 }
129 else
130 {
131 [alert addButtonWithTitle:wxNSStringWithWxString(m_yes)];
132 [alert addButtonWithTitle:wxNSStringWithWxString(m_no)];
133 buttonId[0] = wxID_YES;
134 buttonId[1] = wxID_NO;
135 }
136 if (style & wxCANCEL)
137 {
138 [alert addButtonWithTitle:wxNSStringWithWxString(m_cancel)];
139 buttonId[2] = wxID_CANCEL;
140 }
141 }
142 else
143 {
144 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
145 buttonId[0] = wxID_OK;
146 // using null as default title does not work on earlier systems
147 [alert addButtonWithTitle:wxNSStringWithWxString(m_ok)];
148 if (style & wxCANCEL)
149 {
150 [alert addButtonWithTitle:wxNSStringWithWxString(m_cancel)];
151 buttonId[1] = wxID_CANCEL;
152 }
153 }
154
155 int ret = [alert runModal];
156
157
158 return buttonId[ret-NSAlertFirstButtonReturn];
e9871aaf
DE
159}
160
161bool wxCocoaMessageDialog::SetYesNoLabels(const wxString& yes,const wxString& no)
162{
e5633f9a
DE
163 m_yes = yes;
164 m_yes.Replace(_("&"),_(""));
165 m_no = no;
166 m_no.Replace(_("&"),_(""));
167 return true;
e9871aaf
DE
168}
169bool wxCocoaMessageDialog::SetYesNoCancelLabels(const wxString& yes, const wxString& no, const wxString& cancel)
170{
e5633f9a
DE
171 m_yes = yes;
172 m_yes.Replace(_("&"),_(""));
173 m_no = no;
174 m_no.Replace(_("&"),_(""));
175 m_cancel = cancel;
176 m_cancel.Replace(_("&"),_(""));
177 return true;
e9871aaf
DE
178}
179bool wxCocoaMessageDialog::SetOKLabel(const wxString& ok)
180{
e5633f9a
DE
181 m_ok = ok;
182 m_ok.Replace(_("&"),_(""));
183 return true;
e9871aaf
DE
184}
185bool wxCocoaMessageDialog::SetOKCancelLabels(const wxString& ok, const wxString& cancel)
186{
e5633f9a
DE
187 m_ok = ok;
188 m_ok.Replace(_("&"),_(""));
189 m_cancel = cancel;
190 m_cancel.Replace(_("&"),_(""));
191 return true;
e9871aaf
DE
192}
193
194#endif // wxUSE_DIRDLG
dcb68102 195