Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "osl/mutex.hxx"
21 : #include "vcl/svapp.hxx"
22 : #include "vcl/msgbox.hxx"
23 :
24 : #include "com/sun/star/task/XInteractionAbort.hpp"
25 : #include "com/sun/star/task/XInteractionApprove.hpp"
26 : #include "com/sun/star/task/XInteractionDisapprove.hpp"
27 : #include "com/sun/star/task/XInteractionRetry.hpp"
28 :
29 : #include "tools/errinf.hxx"
30 : #include "svtools/svtools.hrc"
31 :
32 : #include "ids.hrc"
33 : #include "getcontinuations.hxx"
34 :
35 : #include "iahndl.hxx"
36 : #include <boost/scoped_ptr.hpp>
37 :
38 : using namespace com::sun::star;
39 :
40 : namespace {
41 :
42 : sal_uInt16
43 0 : executeErrorDialog(
44 : Window * pParent,
45 : task::InteractionClassification eClassification,
46 : OUString const & rContext,
47 : OUString const & rMessage,
48 : WinBits nButtonMask)
49 : SAL_THROW((uno::RuntimeException))
50 : {
51 0 : SolarMutexGuard aGuard;
52 :
53 0 : OUStringBuffer aText(rContext);
54 0 : if (!rContext.isEmpty() && !rMessage.isEmpty())
55 0 : aText.appendAscii(":\n");
56 : //TODO! must be internationalized
57 0 : aText.append(rMessage);
58 :
59 0 : boost::scoped_ptr< MessBox > xBox;
60 : try
61 : {
62 0 : switch (eClassification)
63 : {
64 : case task::InteractionClassification_ERROR:
65 : xBox.reset(new ErrorBox(pParent,
66 : nButtonMask,
67 0 : aText.makeStringAndClear()));
68 0 : break;
69 :
70 : case task::InteractionClassification_WARNING:
71 : xBox.reset(new WarningBox(pParent,
72 : nButtonMask,
73 0 : aText.makeStringAndClear()));
74 0 : break;
75 :
76 : case task::InteractionClassification_INFO:
77 : # define WB_DEF_BUTTONS (WB_DEF_OK | WB_DEF_CANCEL | WB_DEF_RETRY)
78 : //(want to ignore any default button settings)...
79 0 : if ((nButtonMask & WB_DEF_BUTTONS) == WB_DEF_OK)
80 : xBox.reset(new InfoBox(pParent,
81 0 : aText.makeStringAndClear()));
82 : else
83 : xBox.reset(new ErrorBox(pParent,
84 : nButtonMask,
85 0 : aText.makeStringAndClear()));
86 0 : break;
87 :
88 : case task::InteractionClassification_QUERY:
89 : xBox.reset(new QueryBox(pParent,
90 : nButtonMask,
91 0 : aText.makeStringAndClear()));
92 0 : break;
93 :
94 : default:
95 : OSL_ASSERT(false);
96 0 : break;
97 : }
98 : }
99 0 : catch (std::bad_alloc const &)
100 : {
101 : throw uno::RuntimeException("out of memory",
102 0 : uno::Reference< uno::XInterface >());
103 : }
104 :
105 0 : sal_uInt16 aResult = xBox->Execute();
106 0 : switch( aResult )
107 : {
108 : case RET_OK:
109 0 : aResult = ERRCODE_BUTTON_OK;
110 0 : break;
111 : case RET_CANCEL:
112 0 : aResult = ERRCODE_BUTTON_CANCEL;
113 0 : break;
114 : case RET_YES:
115 0 : aResult = ERRCODE_BUTTON_YES;
116 0 : break;
117 : case RET_NO:
118 0 : aResult = ERRCODE_BUTTON_NO;
119 0 : break;
120 : case RET_RETRY:
121 0 : aResult = ERRCODE_BUTTON_RETRY;
122 0 : break;
123 : }
124 :
125 0 : return aResult;
126 : }
127 :
128 : }
129 :
130 : void
131 0 : UUIInteractionHelper::handleErrorHandlerRequest(
132 : task::InteractionClassification eClassification,
133 : ErrCode nErrorCode,
134 : std::vector< OUString > const & rArguments,
135 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
136 : rContinuations,
137 : bool bObtainErrorStringOnly,
138 : bool & bHasErrorString,
139 : OUString & rErrorString)
140 : SAL_THROW((uno::RuntimeException))
141 : {
142 0 : if (bObtainErrorStringOnly)
143 : {
144 0 : bHasErrorString = isInformationalErrorMessageRequest(rContinuations);
145 0 : if (!bHasErrorString)
146 0 : return;
147 : }
148 :
149 0 : OUString aMessage;
150 : {
151 : enum Source { SOURCE_DEFAULT, SOURCE_CNT, SOURCE_SVX, SOURCE_UUI };
152 : static char const * const aManager[4] = { "ofa", "cnt", "svx", "uui" };
153 : static sal_uInt16 const aId[4]
154 : = { RID_ERRHDL,
155 : RID_CHAOS_START + 12,
156 : // cf. chaos/source/inc/cntrids.hrc, where
157 : // #define RID_CHAOS_ERRHDL (RID_CHAOS_START + 12)
158 : RID_SVX_START + 350, // RID_SVXERRCODE
159 : RID_UUI_ERRHDL };
160 0 : ErrCode nErrorId = nErrorCode & ~ERRCODE_WARNING_MASK;
161 : Source eSource = nErrorId < ERRCODE_AREA_LIB1 ?
162 : SOURCE_DEFAULT :
163 : nErrorId >= ERRCODE_AREA_CHAOS
164 0 : && nErrorId < ERRCODE_AREA_CHAOS_END ?
165 : SOURCE_CNT :
166 : nErrorId >= ERRCODE_AREA_SVX
167 0 : && nErrorId <= ERRCODE_AREA_SVX_END ?
168 : SOURCE_SVX :
169 0 : SOURCE_UUI;
170 :
171 0 : SolarMutexGuard aGuard;
172 0 : boost::scoped_ptr< ResMgr > xManager;
173 0 : xManager.reset(ResMgr::CreateResMgr(aManager[eSource]));
174 0 : if (!xManager.get())
175 0 : return;
176 0 : ResId aResId(aId[eSource], *xManager.get());
177 0 : if (!ErrorResource(aResId).getString(nErrorCode, aMessage))
178 0 : return;
179 : }
180 :
181 0 : aMessage = replaceMessageWithArguments( aMessage, rArguments );
182 :
183 0 : if (bObtainErrorStringOnly)
184 : {
185 0 : rErrorString = aMessage;
186 0 : return;
187 : }
188 : else
189 : {
190 : //TODO! It can happen that the buttons calculated below do not match
191 : // the error text from the resource (e.g., some text that is not a
192 : // question, but YES and NO buttons). Some error texts have
193 : // ExtraData that specifies a set of buttons, but that data is not
194 : // really useful, because a single error text may well make sense
195 : // both with only an OK button and with RETRY and CANCEL buttons.
196 :
197 0 : uno::Reference< task::XInteractionApprove > xApprove;
198 0 : uno::Reference< task::XInteractionDisapprove > xDisapprove;
199 0 : uno::Reference< task::XInteractionRetry > xRetry;
200 0 : uno::Reference< task::XInteractionAbort > xAbort;
201 : getContinuations(
202 0 : rContinuations, &xApprove, &xDisapprove, &xRetry, &xAbort);
203 :
204 : // The following mapping uses the bit mask
205 : // Approve = 8,
206 : // Disapprove = 4,
207 : // Retry = 2,
208 : // Abort = 1
209 :
210 : // The mapping has five properties on which the code to select the
211 : // correct continuation relies:
212 : // 1 The OK button is mapped to Approve if that is available,
213 : // otherwise to Abort if that is available, otherwise to none.
214 : // 2 The CANCEL button is always mapped to Abort.
215 : // 3 The RETRY button is always mapped to Retry.
216 : // 4 The NO button is always mapped to Disapprove.
217 : // 5 The YES button is always mapped to Approve.
218 :
219 : // Because the WinBits button combinations are quite restricted, not
220 : // every request can be served here.
221 :
222 : // Finally, it seems to be better to leave default button
223 : // determination to VCL (the favouring of CANCEL as default button
224 : // seems to not always be what the user wants)...
225 : WinBits const aButtonMask[16]
226 : = { 0,
227 : WB_OK /*| WB_DEF_OK*/, // Abort
228 : 0,
229 : WB_RETRY_CANCEL /*| WB_DEF_CANCEL*/, // Retry, Abort
230 : 0,
231 : 0,
232 : 0,
233 : 0,
234 : WB_OK /*| WB_DEF_OK*/, // Approve
235 : WB_OK_CANCEL /*| WB_DEF_CANCEL*/, // Approve, Abort
236 : 0,
237 : 0,
238 : WB_YES_NO /*| WB_DEF_NO*/, // Approve, Disapprove
239 : WB_YES_NO_CANCEL /*| WB_DEF_CANCEL*/,
240 : // Approve, Disapprove, Abort
241 : 0,
242 0 : 0 };
243 :
244 0 : WinBits nButtonMask = aButtonMask[(xApprove.is() ? 8 : 0)
245 0 : | (xDisapprove.is() ? 4 : 0)
246 0 : | (xRetry.is() ? 2 : 0)
247 0 : | (xAbort.is() ? 1 : 0)];
248 0 : if (nButtonMask == 0)
249 0 : return;
250 :
251 : //TODO! remove this backwards compatibility?
252 0 : OUString aContext(getContextProperty());
253 0 : if (aContext.isEmpty() && nErrorCode != 0)
254 : {
255 0 : SolarMutexGuard aGuard;
256 0 : ErrorContext * pContext = ErrorContext::GetContext();
257 0 : if (pContext)
258 : {
259 0 : OUString aContextString;
260 0 : if (pContext->GetString(nErrorCode, aContextString))
261 0 : aContext = aContextString;
262 0 : }
263 : }
264 :
265 : sal_uInt16 nResult = executeErrorDialog(
266 0 : getParentProperty(), eClassification, aContext, aMessage, nButtonMask );
267 :
268 0 : switch (nResult)
269 : {
270 : case ERRCODE_BUTTON_OK:
271 : OSL_ENSURE(xApprove.is() || xAbort.is(), "unexpected situation");
272 0 : if (xApprove.is())
273 0 : xApprove->select();
274 0 : else if (xAbort.is())
275 0 : xAbort->select();
276 0 : break;
277 :
278 : case ERRCODE_BUTTON_CANCEL:
279 : OSL_ENSURE(xAbort.is(), "unexpected situation");
280 0 : if (xAbort.is())
281 0 : xAbort->select();
282 0 : break;
283 :
284 : case ERRCODE_BUTTON_RETRY:
285 : OSL_ENSURE(xRetry.is(), "unexpected situation");
286 0 : if (xRetry.is())
287 0 : xRetry->select();
288 0 : break;
289 :
290 : case ERRCODE_BUTTON_NO:
291 : OSL_ENSURE(xDisapprove.is(), "unexpected situation");
292 0 : if (xDisapprove.is())
293 0 : xDisapprove->select();
294 0 : break;
295 :
296 : case ERRCODE_BUTTON_YES:
297 : OSL_ENSURE(xApprove.is(), "unexpected situation");
298 0 : if (xApprove.is())
299 0 : xApprove->select();
300 0 : break;
301 0 : }
302 :
303 0 : }
304 : }
305 :
306 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|