]> git.saurik.com Git - wxWidgets.git/blob - src/mac/msgdlg.cpp
Added wxUSE_RICHEDIT to match usage in header
[wxWidgets.git] / src / mac / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: AUTHOR
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "msgdlg.h"
14 #endif
15
16 #include "wx/app.h"
17 #include "wx/msgdlg.h"
18 #include "wx/intl.h"
19 #include "wx/mac/uma.h"
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
23 #endif
24
25 short language = 0 ;
26
27 void wxMacConvertNewlines( const char *source , char * destination ) ;
28 void wxMacConvertNewlines( const char *source , char * destination )
29 {
30 const char *s = source ;
31 char *d = destination ;
32
33 while( *s )
34 {
35 switch( *s )
36 {
37 case 0x0a :
38 *d++ = 0x0d ;
39 ++s ;
40 break ;
41 case 0x0d :
42 *d++ = 0x0d ;
43 ++s ;
44 if ( *s == 0x0a )
45 ++s ;
46 break ;
47 default :
48 *d++ = *s++ ;
49 break ;
50 }
51 }
52 *d = 0 ;
53 }
54
55 wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
56 long style, const wxPoint& pos)
57 {
58 m_caption = caption;
59 m_message = message;
60 m_dialogStyle = style;
61 m_parent = parent;
62 }
63
64 int wxMessageDialog::ShowModal()
65 {
66 int resultbutton = wxID_CANCEL ;
67
68 short result ;
69 Str255 pascalTitle ;
70 Str255 pascalText ;
71 char cText[256] ;
72
73 Str255 yesPString ;
74 Str255 noPString ;
75
76 wxMacStringToPascal( m_caption , pascalTitle ) ;
77 wxMacStringToPascal( _("Yes") , yesPString ) ;
78 wxMacStringToPascal( _("No") , noPString ) ;
79
80 if (wxApp::s_macDefaultEncodingIsPC)
81 {
82 strcpy(cText , wxMacMakeMacStringFromPC( m_message) ) ;
83 }
84 else
85 {
86 strcpy( cText , m_message ) ;
87 }
88
89 wxMacConvertNewlines( cText , cText ) ;
90 CopyCStringToPascal( cText , pascalText ) ;
91
92 wxASSERT_MSG( ( m_dialogStyle & 0x3F ) != wxYES , "this style is not supported on mac" ) ;
93
94
95 AlertStdAlertParamRec param;
96
97 param.movable = true;
98 param.filterProc = NULL ;
99
100 if (m_dialogStyle & wxYES_NO)
101 {
102 if (m_dialogStyle & wxCANCEL)
103 {
104 param.defaultText = yesPString ;
105 param.cancelText = (StringPtr) kAlertDefaultCancelText;
106 param.otherText = noPString ;
107 param.helpButton = false ;
108 param.defaultButton = kAlertStdAlertOKButton;
109 param.cancelButton = kAlertStdAlertCancelButton;
110 }
111 else
112 {
113 param.defaultText = yesPString ;
114 param.cancelText = NULL;
115 param.otherText = noPString ;
116 param.helpButton = false ;
117 param.defaultButton = kAlertStdAlertOKButton;
118 param.cancelButton = 0;
119 }
120 }
121 else if (m_dialogStyle & wxOK)
122 {
123 if (m_dialogStyle & wxCANCEL)
124 {
125 // thats a cancel missing
126 param.defaultText = (StringPtr) kAlertDefaultOKText ;
127 param.cancelText = NULL;
128 param.otherText = NULL;
129 param.helpButton = false ;
130 param.defaultButton = kAlertStdAlertOKButton;
131 param.cancelButton = 0;
132 }
133 else
134 {
135 param.defaultText = (StringPtr) kAlertDefaultOKText ;
136 param.cancelText = NULL;
137 param.otherText = NULL;
138 param.helpButton = false ;
139 param.defaultButton = kAlertStdAlertOKButton;
140 param.cancelButton = 0;
141 }
142 }
143 else
144 {
145 return resultbutton ;
146 }
147
148 param.position = 0;
149
150 if (m_dialogStyle & wxICON_EXCLAMATION)
151 StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, &param, &result );
152 else if (m_dialogStyle & wxICON_HAND)
153 StandardAlert( kAlertStopAlert, pascalTitle, pascalText, &param, &result );
154 else if (m_dialogStyle & wxICON_INFORMATION)
155 StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, &param, &result );
156 else if (m_dialogStyle & wxICON_QUESTION)
157 StandardAlert( kAlertCautionAlert, pascalTitle, pascalText, &param, &result );
158 else
159 StandardAlert( kAlertPlainAlert, pascalTitle, pascalText, &param, &result );
160
161 if (m_dialogStyle & wxOK)
162 {
163 if (m_dialogStyle & wxCANCEL)
164 {
165 //TODO add Cancelbutton
166 switch( result )
167 {
168 case 1 :
169 resultbutton = wxID_OK ;
170 break ;
171 case 2 :
172 break ;
173 case 3 :
174 break ;
175 }
176 }
177 else
178 {
179 switch( result )
180 {
181 case 1 :
182 resultbutton = wxID_OK ;
183 break ;
184 case 2 :
185 break ;
186 case 3 :
187 break ;
188 }
189 }
190 }
191 else if (m_dialogStyle & wxYES_NO)
192 {
193 if (m_dialogStyle & wxCANCEL)
194 {
195 switch( result )
196 {
197 case 1 :
198 resultbutton = wxID_YES ;
199 break ;
200 case 2 :
201 resultbutton = wxID_CANCEL ;
202 break ;
203 case 3 :
204 resultbutton = wxID_NO ;
205 break ;
206 }
207 }
208 else
209 {
210 switch( result )
211 {
212 case 1 :
213 resultbutton = wxID_YES ;
214 break ;
215 case 2 :
216 break ;
217 case 3 :
218 resultbutton = wxID_NO ;
219 break ;
220 }
221 }
222 }
223
224 return resultbutton ;
225 }
226