]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/msgdlg.mm
Fix history in wxWebViewIE when using a custom file scheme.
[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,
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 66void wxCocoaMessageDialog::DoSetCustomLabel(wxString& var, const ButtonLabel& value)
e9871aaf 67{
23e00c55
VZ
68 wxMessageDialogWithCustomLabels::DoSetCustomLabel(var, value);
69
70 var.Replace("&", "");
e9871aaf
DE
71}
72
73int wxCocoaMessageDialog::ShowModal()
74{
e5633f9a
DE
75 wxAutoNSAutoreleasePool thePool;
76
77 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
e9871aaf 78
e9871aaf
DE
79 const long style = GetMessageDialogStyle();
80
81 NSAlertStyle nsStyle = NSInformationalAlertStyle;
a4578b0c
VZ
82
83 switch ( GetEffectiveIcon() )
84 {
85 case wxICON_ERROR:
86 nsStyle = NSCriticalAlertStyle;
87 break;
88
89 case wxICON_WARNING:
90 nsStyle = NSWarningAlertStyle;
91 break;
92 }
e9871aaf 93
e5633f9a
DE
94 [alert setAlertStyle:nsStyle];
95
96
97
98
e9871aaf
DE
99 // work out what to display
100 // if the extended text is empty then we use the caption as the title
101 // and the message as the text (for backwards compatibility)
102 // but if the extended message is not empty then we use the message as the title
103 // and the extended message as the text because that makes more sense
e5633f9a
DE
104 if (m_extendedMessage.empty())
105 {
106 [alert setMessageText:wxNSStringWithWxString(m_caption)];
107 [alert setInformativeText:wxNSStringWithWxString(m_message)];
108 }
109 else
110 {
111 [alert setMessageText:wxNSStringWithWxString(m_message)];
112 [alert setInformativeText:wxNSStringWithWxString(m_extendedMessage)];
113 }
114
115 // The wxReturn value corresponding to each button
116 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
117 if (style & wxYES_NO)
118 {
119 if ( style & wxNO_DEFAULT )
120 {
23e00c55
VZ
121 [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())];
122 [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())];
e5633f9a
DE
123 buttonId[0] = wxID_NO;
124 buttonId[1] = wxID_YES;
125 }
126 else
127 {
23e00c55
VZ
128 [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())];
129 [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())];
e5633f9a
DE
130 buttonId[0] = wxID_YES;
131 buttonId[1] = wxID_NO;
132 }
133 if (style & wxCANCEL)
134 {
23e00c55 135 [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())];
e5633f9a
DE
136 buttonId[2] = wxID_CANCEL;
137 }
138 }
139 else
140 {
141 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
142 buttonId[0] = wxID_OK;
143 // using null as default title does not work on earlier systems
23e00c55 144 [alert addButtonWithTitle:wxNSStringWithWxString(GetOKLabel())];
e5633f9a
DE
145 if (style & wxCANCEL)
146 {
23e00c55 147 [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())];
e5633f9a
DE
148 buttonId[1] = wxID_CANCEL;
149 }
150 }
151
152 int ret = [alert runModal];
153
154
155 return buttonId[ret-NSAlertFirstButtonReturn];
e9871aaf
DE
156}
157
e9871aaf 158#endif // wxUSE_DIRDLG
dcb68102 159