1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/mutex.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/msgbox.hxx>
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>
29 #include <tools/errinf.hxx>
30 #include <svtools/svtools.hrc>
33 #include "getcontinuations.hxx"
36 #include <boost/scoped_ptr.hpp>
38 using namespace com::sun::star
;
44 vcl::Window
* pParent
,
45 task::InteractionClassification eClassification
,
46 OUString
const & rContext
,
47 OUString
const & rMessage
,
50 SolarMutexGuard aGuard
;
52 OUStringBuffer
aText(rContext
);
53 if (!rContext
.isEmpty() && !rMessage
.isEmpty())
54 aText
.appendAscii(":\n");
55 //TODO! must be internationalized
56 aText
.append(rMessage
);
58 VclPtr
< MessBox
> xBox
;
61 switch (eClassification
)
63 case task::InteractionClassification_ERROR
:
64 xBox
.reset(VclPtr
<ErrorBox
>::Create(pParent
,
66 aText
.makeStringAndClear()));
69 case task::InteractionClassification_WARNING
:
70 xBox
.reset(VclPtr
<WarningBox
>::Create(pParent
,
72 aText
.makeStringAndClear()));
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 if ((nButtonMask
& WB_DEF_BUTTONS
) == WB_DEF_OK
)
79 xBox
.reset(VclPtr
<InfoBox
>::Create(pParent
,
80 aText
.makeStringAndClear()));
82 xBox
.reset(VclPtr
<ErrorBox
>::Create(pParent
,
84 aText
.makeStringAndClear()));
87 case task::InteractionClassification_QUERY
:
88 xBox
.reset(VclPtr
<QueryBox
>::Create(pParent
,
90 aText
.makeStringAndClear()));
98 catch (std::bad_alloc
const &)
100 throw uno::RuntimeException("out of memory");
103 sal_uInt16 aResult
= xBox
->Execute();
105 xBox
.disposeAndClear();
110 aResult
= ERRCODE_BUTTON_OK
;
113 aResult
= ERRCODE_BUTTON_CANCEL
;
116 aResult
= ERRCODE_BUTTON_YES
;
119 aResult
= ERRCODE_BUTTON_NO
;
122 aResult
= ERRCODE_BUTTON_RETRY
;
132 UUIInteractionHelper::handleErrorHandlerRequest(
133 task::InteractionClassification eClassification
,
135 std::vector
< OUString
> const & rArguments
,
136 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
138 bool bObtainErrorStringOnly
,
139 bool & bHasErrorString
,
140 OUString
& rErrorString
)
142 if (bObtainErrorStringOnly
)
144 bHasErrorString
= isInformationalErrorMessageRequest(rContinuations
);
145 if (!bHasErrorString
)
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]
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
160 ErrCode nErrorId
= nErrorCode
& ~ERRCODE_WARNING_MASK
;
161 Source eSource
= nErrorId
< ERRCODE_AREA_LIB1
?
163 nErrorId
>= ERRCODE_AREA_CHAOS
164 && nErrorId
< ERRCODE_AREA_CHAOS_END
?
166 nErrorId
>= ERRCODE_AREA_SVX
167 && nErrorId
<= ERRCODE_AREA_SVX_END
?
171 SolarMutexGuard aGuard
;
172 boost::scoped_ptr
< ResMgr
> xManager
;
173 xManager
.reset(ResMgr::CreateResMgr(aManager
[eSource
]));
176 ResId
aResId(aId
[eSource
], *xManager
.get());
177 if (!ErrorResource(aResId
).getString(nErrorCode
, aMessage
))
181 aMessage
= replaceMessageWithArguments( aMessage
, rArguments
);
183 if (bObtainErrorStringOnly
)
185 rErrorString
= aMessage
;
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.
197 uno::Reference
< task::XInteractionApprove
> xApprove
;
198 uno::Reference
< task::XInteractionDisapprove
> xDisapprove
;
199 uno::Reference
< task::XInteractionRetry
> xRetry
;
200 uno::Reference
< task::XInteractionAbort
> xAbort
;
202 rContinuations
, &xApprove
, &xDisapprove
, &xRetry
, &xAbort
);
204 // The following mapping uses the bit mask
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.
219 // Because the WinBits button combinations are quite restricted, not
220 // every request can be served here.
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]
227 WB_OK
/*| WB_DEF_OK*/, // Abort
229 WB_RETRY_CANCEL
/*| WB_DEF_CANCEL*/, // Retry, Abort
234 WB_OK
/*| WB_DEF_OK*/, // Approve
235 WB_OK_CANCEL
/*| WB_DEF_CANCEL*/, // Approve, Abort
238 WB_YES_NO
/*| WB_DEF_NO*/, // Approve, Disapprove
239 WB_YES_NO_CANCEL
/*| WB_DEF_CANCEL*/,
240 // Approve, Disapprove, Abort
244 WinBits nButtonMask
= aButtonMask
[(xApprove
.is() ? 8 : 0)
245 | (xDisapprove
.is() ? 4 : 0)
246 | (xRetry
.is() ? 2 : 0)
247 | (xAbort
.is() ? 1 : 0)];
248 if (nButtonMask
== 0)
251 //TODO! remove this backwards compatibility?
252 OUString
aContext(getContextProperty());
253 if (aContext
.isEmpty() && nErrorCode
!= 0)
255 SolarMutexGuard aGuard
;
256 ErrorContext
* pContext
= ErrorContext::GetContext();
259 OUString aContextString
;
260 if (pContext
->GetString(nErrorCode
, aContextString
))
261 aContext
= aContextString
;
265 sal_uInt16 nResult
= executeErrorDialog(
266 getParentProperty(), eClassification
, aContext
, aMessage
, nButtonMask
);
270 case ERRCODE_BUTTON_OK
:
271 OSL_ENSURE(xApprove
.is() || xAbort
.is(), "unexpected situation");
274 else if (xAbort
.is())
278 case ERRCODE_BUTTON_CANCEL
:
279 OSL_ENSURE(xAbort
.is(), "unexpected situation");
284 case ERRCODE_BUTTON_RETRY
:
285 OSL_ENSURE(xRetry
.is(), "unexpected situation");
290 case ERRCODE_BUTTON_NO
:
291 OSL_ENSURE(xDisapprove
.is(), "unexpected situation");
292 if (xDisapprove
.is())
293 xDisapprove
->select();
296 case ERRCODE_BUTTON_YES
:
297 OSL_ENSURE(xApprove
.is(), "unexpected situation");
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */