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