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