Debian Codegraph @

src/af/xap/cocoa/xap_CocoaDlg_MessageBox.cpp

raw
1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2
3 /* AbiSource Application Framework
4 * Copyright (C) 1998 AbiSource, Inc.
5 * Copyright (C) 2001-2003 Hubert Figuiere
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA.
21 */
22
23 #import <Cocoa/Cocoa.h>
24
25 #include "ut_assert.h"
26 #include "xap_CocoaDlg_MessageBox.h"
27 #include "xap_CocoaApp.h"
28 #include "xap_CocoaFrame.h"
29
30 #include "xap_CocoaDialog_Utilities.h"
31
32
33 /*****************************************************************/
34 XAP_Dialog * XAP_CocoaDialog_MessageBox::static_constructor(XAP_DialogFactory * pFactory,
35 XAP_Dialog_Id dlgid)
36 {
37 XAP_CocoaDialog_MessageBox * p = new XAP_CocoaDialog_MessageBox(pFactory, dlgid);
38 return p;
39 }
40
41 XAP_CocoaDialog_MessageBox::XAP_CocoaDialog_MessageBox(XAP_DialogFactory * pDlgFactory,
42 XAP_Dialog_Id dlgid)
43 : XAP_Dialog_MessageBox(pDlgFactory, dlgid)
44 {
45 }
46
47 XAP_CocoaDialog_MessageBox::~XAP_CocoaDialog_MessageBox(void)
48 {
49 }
50
51 /*****************************************************************/
52
53 void XAP_CocoaDialog_MessageBox::runModal(XAP_Frame * /*pFrame*/)
54 {
55 XAP_App * pApp = XAP_App::getApp();
56
57 const XAP_StringSet * pSS = pApp->getStringSet();
58
59 NSString * title = [NSString stringWithUTF8String:m_szMessage];
60 NSString * message = @"";
61
62 if (m_szSecondaryMessage)
63 message = [NSString stringWithUTF8String:m_szSecondaryMessage];
64
65 switch (m_buttons) {
66 case b_O:
67 {
68 NSRunAlertPanel(title, message,
69 LocalizedString(pSS, XAP_STRING_ID_DLG_OK),
70 nil,
71 nil);
72
73 m_answer = a_OK;
74 }
75 break;
76
77 case b_OC:
78 if (m_defaultAnswer == XAP_Dialog_MessageBox::a_OK)
79 {
80 int btn = NSRunAlertPanel(title, message,
81 LocalizedString(pSS, XAP_STRING_ID_DLG_OK),
82 LocalizedString(pSS, XAP_STRING_ID_DLG_Cancel),
83 nil);
84
85 switch (btn)
86 {
87 case NSAlertDefaultReturn:
88 m_answer = a_OK;
89 break;
90 case NSAlertAlternateReturn:
91 m_answer = a_CANCEL;
92 break;
93 default:
94 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
95 break;
96 }
97 }
98 else
99 {
100 int btn = NSRunAlertPanel(title, message,
101 LocalizedString(pSS, XAP_STRING_ID_DLG_Cancel),
102 LocalizedString(pSS, XAP_STRING_ID_DLG_OK),
103 nil);
104
105 switch (btn)
106 {
107 case NSAlertDefaultReturn:
108 m_answer = a_CANCEL;
109 break;
110 case NSAlertAlternateReturn:
111 m_answer = a_OK;
112 break;
113 default:
114 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
115 break;
116 }
117 }
118 break;
119
120 case b_YN:
121 if (m_defaultAnswer == XAP_Dialog_MessageBox::a_YES)
122 {
123 int btn = NSRunAlertPanel(title, message,
124 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_Yes),
125 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_No),
126 nil);
127
128 switch (btn)
129 {
130 case NSAlertDefaultReturn:
131 m_answer = a_YES;
132 break;
133 case NSAlertAlternateReturn:
134 m_answer = a_NO;
135 break;
136 default:
137 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
138 break;
139 }
140 }
141 else
142 {
143 int btn = NSRunAlertPanel(title, message,
144 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_No),
145 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_Yes),
146 nil);
147
148 switch (btn)
149 {
150 case NSAlertDefaultReturn:
151 m_answer = a_NO;
152 break;
153 case NSAlertAlternateReturn:
154 m_answer = a_YES;
155 break;
156 default:
157 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
158 break;
159 }
160 }
161 break;
162
163 case b_YNC:
164 if (m_defaultAnswer == XAP_Dialog_MessageBox::a_YES)
165 {
166 int btn = NSRunAlertPanel(title, message,
167 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_Yes),
168 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_No),
169 LocalizedString(pSS, XAP_STRING_ID_DLG_Cancel));
170
171 switch (btn)
172 {
173 case NSAlertDefaultReturn:
174 m_answer = a_YES;
175 break;
176 case NSAlertAlternateReturn:
177 m_answer = a_NO;
178 break;
179 case NSAlertOtherReturn:
180 m_answer = a_CANCEL;
181 break;
182 default:
183 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
184 break;
185 }
186 }
187 else
188 {
189 int btn = NSRunAlertPanel(title, message,
190 LocalizedString(pSS, XAP_STRING_ID_DLG_Cancel),
191 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_No),
192 LocalizedString(pSS, XAP_STRING_ID_DLG_MB_Yes));
193
194 switch (btn)
195 {
196 case NSAlertDefaultReturn:
197 m_answer = a_CANCEL;
198 break;
199 case NSAlertAlternateReturn:
200 m_answer = a_NO;
201 break;
202 case NSAlertOtherReturn:
203 m_answer = a_YES;
204 break;
205 default:
206 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
207 break;
208 }
209 }
210 break;
211
212 default:
213 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
214 break;
215 }
216 }
217