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 .
22 #include "osl/mutex.hxx"
23 #include "vcl/svapp.hxx"
24 #include "vcl/msgbox.hxx"
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"
31 #include "tools/errinf.hxx" // ErrorHandler, ErrorContext, ...
32 #include "svtools/svtools.hrc" // RID_ERRHDL
35 #include "getcontinuations.hxx"
39 using namespace com::sun::star
;
46 task::InteractionClassification eClassification
,
47 OUString
const & rContext
,
48 OUString
const & rMessage
,
50 SAL_THROW((uno::RuntimeException
))
52 SolarMutexGuard aGuard
;
54 OUStringBuffer
aText(rContext
);
55 if (!rContext
.isEmpty() && !rMessage
.isEmpty())
56 aText
.appendAscii(":\n");
57 //TODO! must be internationalized
58 aText
.append(rMessage
);
60 std::auto_ptr
< MessBox
> xBox
;
63 switch (eClassification
)
65 case task::InteractionClassification_ERROR
:
66 xBox
.reset(new ErrorBox(pParent
,
68 aText
.makeStringAndClear()));
71 case task::InteractionClassification_WARNING
:
72 xBox
.reset(new WarningBox(pParent
,
74 aText
.makeStringAndClear()));
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()));
84 xBox
.reset(new ErrorBox(pParent
,
86 aText
.makeStringAndClear()));
89 case task::InteractionClassification_QUERY
:
90 xBox
.reset(new QueryBox(pParent
,
92 aText
.makeStringAndClear()));
100 catch (std::bad_alloc
const &)
102 throw uno::RuntimeException(OUString("out of memory"),
103 uno::Reference
< uno::XInterface
>());
106 sal_uInt16 aResult
= xBox
->Execute();
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
)
141 SAL_THROW((uno::RuntimeException
))
143 if (bObtainErrorStringOnly
)
145 bHasErrorString
= isInformationalErrorMessageRequest(rContinuations
);
146 if (!bHasErrorString
)
152 enum Source
{ SOURCE_DEFAULT
, SOURCE_CNT
, SOURCE_SVX
, SOURCE_UUI
};
153 static char const * const aManager
[4] = { "ofa", "cnt", "svx", "uui" };
154 static sal_uInt16
const aId
[4]
156 RID_CHAOS_START
+ 12,
157 // cf. chaos/source/inc/cntrids.hrc, where
158 // #define RID_CHAOS_ERRHDL (RID_CHAOS_START + 12)
159 RID_SVX_START
+ 350, // RID_SVXERRCODE
161 ErrCode nErrorId
= nErrorCode
& ~ERRCODE_WARNING_MASK
;
162 Source eSource
= nErrorId
< ERRCODE_AREA_LIB1
?
164 nErrorId
>= ERRCODE_AREA_CHAOS
165 && nErrorId
< ERRCODE_AREA_CHAOS_END
?
167 nErrorId
>= ERRCODE_AREA_SVX
168 && nErrorId
<= ERRCODE_AREA_SVX_END
?
172 SolarMutexGuard aGuard
;
173 std::auto_ptr
< ResMgr
> xManager
;
174 xManager
.reset(ResMgr::CreateResMgr(aManager
[eSource
]));
177 ResId
aResId(aId
[eSource
], *xManager
.get());
178 if (!ErrorResource(aResId
).getString(nErrorCode
, aMessage
))
182 aMessage
= replaceMessageWithArguments( aMessage
, rArguments
);
184 if (bObtainErrorStringOnly
)
186 rErrorString
= aMessage
;
191 //TODO! It can happen that the buttons calculated below do not match
192 // the error text from the resource (e.g., some text that is not a
193 // question, but YES and NO buttons). Some error texts have
194 // ExtraData that specifies a set of buttons, but that data is not
195 // really useful, because a single error text may well make sense
196 // both with only an OK button and with RETRY and CANCEL buttons.
198 uno::Reference
< task::XInteractionApprove
> xApprove
;
199 uno::Reference
< task::XInteractionDisapprove
> xDisapprove
;
200 uno::Reference
< task::XInteractionRetry
> xRetry
;
201 uno::Reference
< task::XInteractionAbort
> xAbort
;
203 rContinuations
, &xApprove
, &xDisapprove
, &xRetry
, &xAbort
);
205 // The following mapping uses the bit mask
211 // The mapping has five properties on which the code to select the
212 // correct continuation relies:
213 // 1 The OK button is mapped to Approve if that is available,
214 // otherwise to Abort if that is available, otherwise to none.
215 // 2 The CANCEL button is always mapped to Abort.
216 // 3 The RETRY button is always mapped to Retry.
217 // 4 The NO button is always mapped to Disapprove.
218 // 5 The YES button is always mapped to Approve.
220 // Because the WinBits button combinations are quite restricted, not
221 // every request can be served here.
223 // Finally, it seems to be better to leave default button
224 // determination to VCL (the favouring of CANCEL as default button
225 // seems to not always be what the user wants)...
226 WinBits
const aButtonMask
[16]
228 WB_OK
/*| WB_DEF_OK*/, // Abort
230 WB_RETRY_CANCEL
/*| WB_DEF_CANCEL*/, // Retry, Abort
235 WB_OK
/*| WB_DEF_OK*/, // Approve
236 WB_OK_CANCEL
/*| WB_DEF_CANCEL*/, // Approve, Abort
239 WB_YES_NO
/*| WB_DEF_NO*/, // Approve, Disapprove
240 WB_YES_NO_CANCEL
/*| WB_DEF_CANCEL*/,
241 // Approve, Disapprove, Abort
245 WinBits nButtonMask
= aButtonMask
[(xApprove
.is() ? 8 : 0)
246 | (xDisapprove
.is() ? 4 : 0)
247 | (xRetry
.is() ? 2 : 0)
248 | (xAbort
.is() ? 1 : 0)];
249 if (nButtonMask
== 0)
252 //TODO! remove this backwards compatibility?
253 OUString
aContext(getContextProperty());
254 if (aContext
.isEmpty() && nErrorCode
!= 0)
256 SolarMutexGuard aGuard
;
257 ErrorContext
* pContext
= ErrorContext::GetContext();
260 OUString aContextString
;
261 if (pContext
->GetString(nErrorCode
, aContextString
))
262 aContext
= aContextString
;
266 sal_uInt16 nResult
= executeErrorDialog(
267 getParentProperty(), eClassification
, aContext
, aMessage
, nButtonMask
);
271 case ERRCODE_BUTTON_OK
:
272 OSL_ENSURE(xApprove
.is() || xAbort
.is(), "unexpected situation");
275 else if (xAbort
.is())
279 case ERRCODE_BUTTON_CANCEL
:
280 OSL_ENSURE(xAbort
.is(), "unexpected situation");
285 case ERRCODE_BUTTON_RETRY
:
286 OSL_ENSURE(xRetry
.is(), "unexpected situation");
291 case ERRCODE_BUTTON_NO
:
292 OSL_ENSURE(xDisapprove
.is(), "unexpected situation");
293 if (xDisapprove
.is())
294 xDisapprove
->select();
297 case ERRCODE_BUTTON_YES
:
298 OSL_ENSURE(xApprove
.is(), "unexpected situation");
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */