]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/msgdlg.mm
call event.Enable(true) in OnUpdateFileOpen and OnUpdateFileNew only if there are...
[wxWidgets.git] / src / cocoa / msgdlg.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dirdlg.mm
3 // Purpose: wxMessageDialog for wxCocoa
4 // Author: Gareth Simpson
5 // Created: 2007-10-09
6 // RCS-ID: $Id$
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
40 IMPLEMENT_CLASS(wxCocoaMessageDialog, wxDialog)
41
42 // ----------------------------------------------------------------------------
43 // wxDirDialog
44 // ----------------------------------------------------------------------------
45
46 wxCocoaMessageDialog::wxCocoaMessageDialog(wxWindow *parent,
47 const wxString& message,
48 const wxString& caption,
49 long style,
50 const wxPoint& pos)
51 : wxMessageDialogWithCustomLabels(parent, message, caption, style)
52 {
53
54 wxTopLevelWindows.Append(this);
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;
64 }
65
66 void wxCocoaMessageDialog::DoSetCustomLabel(wxString& var, const ButtonLabel& value)
67 {
68 wxMessageDialogWithCustomLabels::DoSetCustomLabel(var, value);
69
70 var.Replace("&", "");
71 }
72
73 int wxCocoaMessageDialog::ShowModal()
74 {
75 wxAutoNSAutoreleasePool thePool;
76
77 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
78
79 const long style = GetMessageDialogStyle();
80
81 NSAlertStyle nsStyle = NSInformationalAlertStyle;
82 if (style & wxICON_EXCLAMATION)
83 nsStyle = NSWarningAlertStyle;
84 else if (style & wxICON_HAND)
85 nsStyle = NSCriticalAlertStyle;
86 else if (style & wxICON_INFORMATION)
87 nsStyle = NSInformationalAlertStyle;
88 else if (style & wxICON_QUESTION)
89 nsStyle = NSInformationalAlertStyle;
90
91 [alert setAlertStyle:nsStyle];
92
93
94
95
96 // work out what to display
97 // if the extended text is empty then we use the caption as the title
98 // and the message as the text (for backwards compatibility)
99 // but if the extended message is not empty then we use the message as the title
100 // and the extended message as the text because that makes more sense
101 if (m_extendedMessage.empty())
102 {
103 [alert setMessageText:wxNSStringWithWxString(m_caption)];
104 [alert setInformativeText:wxNSStringWithWxString(m_message)];
105 }
106 else
107 {
108 [alert setMessageText:wxNSStringWithWxString(m_message)];
109 [alert setInformativeText:wxNSStringWithWxString(m_extendedMessage)];
110 }
111
112 // The wxReturn value corresponding to each button
113 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
114 if (style & wxYES_NO)
115 {
116 if ( style & wxNO_DEFAULT )
117 {
118 [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())];
119 [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())];
120 buttonId[0] = wxID_NO;
121 buttonId[1] = wxID_YES;
122 }
123 else
124 {
125 [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())];
126 [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())];
127 buttonId[0] = wxID_YES;
128 buttonId[1] = wxID_NO;
129 }
130 if (style & wxCANCEL)
131 {
132 [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())];
133 buttonId[2] = wxID_CANCEL;
134 }
135 }
136 else
137 {
138 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
139 buttonId[0] = wxID_OK;
140 // using null as default title does not work on earlier systems
141 [alert addButtonWithTitle:wxNSStringWithWxString(GetOKLabel())];
142 if (style & wxCANCEL)
143 {
144 [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())];
145 buttonId[1] = wxID_CANCEL;
146 }
147 }
148
149 int ret = [alert runModal];
150
151
152 return buttonId[ret-NSAlertFirstButtonReturn];
153 }
154
155 #endif // wxUSE_DIRDLG
156