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