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 #ifndef INCLUDED_VCL_ERRINF_HXX
21 #define INCLUDED_VCL_ERRINF_HXX
23 #include <rtl/ustring.hxx>
25 #include <comphelper/errcode.hxx>
26 #include <vcl/dllapi.h>
27 #include <o3tl/typed_flags_set.hxx>
34 namespace weld
{ class Window
; }
39 class DynamicErrorInfo
;
40 class ImplDynamicErrorInfo
;
41 enum class DialogMask
;
43 class VCL_DLLPUBLIC ErrorStringFactory
46 static bool CreateString(const ErrorInfo
*, OUString
&);
49 typedef void (* DisplayFnPtr
)();
51 typedef DialogMask
WindowDisplayErrorFunc(
52 weld::Window
*, DialogMask eMask
, const OUString
&rErr
, const OUString
&rAction
);
54 typedef void BasicDisplayErrorFunc(
55 const OUString
&rErr
, const OUString
&rAction
);
57 class VCL_DLLPUBLIC ErrorRegistry
59 friend class ErrorHandler
;
60 friend class ErrorContext
;
61 friend class ErrorStringFactory
;
62 friend class ImplDynamicErrorInfo
;
67 static void RegisterDisplay(BasicDisplayErrorFunc
*);
68 static void RegisterDisplay(WindowDisplayErrorFunc
*);
70 static void SetLock(bool bLock
);
71 static bool GetLock();
81 sal_uInt16 nNextError
;
83 std::vector
<ErrorHandler
*> errorHandlers
;
84 std::vector
<ErrorContext
*> contexts
;
86 DynamicErrorInfo
* ppDynErrInfo
[ERRCODE_DYNAMIC_COUNT
];
93 ButtonsCancel
= 0x0002,
94 ButtonsRetry
= 0x0004,
97 ButtonsYesNo
= 0x0018,
99 ButtonDefaultsOk
= 0x0100,
100 ButtonDefaultsCancel
= 0x0200,
101 ButtonDefaultsYes
= 0x0300,
102 ButtonDefaultsNo
= 0x0400,
104 MessageError
= 0x1000,
105 MessageWarning
= 0x2000,
106 MessageInfo
= 0x3000,
112 template<> struct typed_flags
<DialogMask
> : is_typed_flags
<DialogMask
, 0xffff> {};
115 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorHandler
117 friend class ErrorStringFactory
;
121 virtual ~ErrorHandler();
123 /** Handles an error.
125 If nFlags is not set, the DynamicErrorInfo flags or the
126 resource flags will be used. Thus the order is:
131 4. Default ButtonsOk, MessageError
133 @param nErrCodeId error id
134 @param pParent parent window the error dialog will be modal for. nullptr for unrecommended "pick default"
135 @param nFlags error flags.
137 @return what sort of dialog to use, with what buttons
139 static DialogMask
HandleError(ErrCode nId
, weld::Window
* pParent
= nullptr, DialogMask nMask
= DialogMask::MAX
);
140 static bool GetErrorString(ErrCode nId
, OUString
& rStr
);
143 virtual bool CreateString(const ErrorInfo
*, OUString
&) const = 0;
147 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorInfo
150 ErrorInfo(ErrCode nArgUserId
) :
151 nUserId(nArgUserId
) {}
152 virtual ~ErrorInfo();
154 ErrCode
const & GetErrorCode() const { return nUserId
; }
156 static std::unique_ptr
<ErrorInfo
> GetErrorInfo(ErrCode
);
162 class SAL_WARN_UNUSED VCL_DLLPUBLIC DynamicErrorInfo
: public ErrorInfo
164 friend class ImplDynamicErrorInfo
;
167 DynamicErrorInfo(ErrCode nUserId
, DialogMask nMask
);
168 virtual ~DynamicErrorInfo() override
;
170 operator ErrCode() const;
171 DialogMask
GetDialogMask() const;
174 std::unique_ptr
<ImplDynamicErrorInfo
> pImpl
;
178 class SAL_WARN_UNUSED VCL_DLLPUBLIC StringErrorInfo final
: public DynamicErrorInfo
181 StringErrorInfo(ErrCode nUserId
,
183 DialogMask nMask
= DialogMask::NONE
);
185 const OUString
& GetErrorString() const { return aString
; }
192 class SAL_WARN_UNUSED VCL_DLLPUBLIC TwoStringErrorInfo final
: public DynamicErrorInfo
195 TwoStringErrorInfo(ErrCode nUserID
, OUString aTheArg1
,
196 OUString aTheArg2
, DialogMask nMask
):
197 DynamicErrorInfo(nUserID
, nMask
), aArg1(std::move(aTheArg1
)), aArg2(std::move(aTheArg2
)) {}
199 const OUString
& GetArg1() const { return aArg1
; }
200 const OUString
& GetArg2() const { return aArg2
; }
208 struct ImplErrorContext
;
210 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorContext
212 friend class ErrorHandler
;
215 ErrorContext(weld::Window
*pWin
);
216 virtual ~ErrorContext();
218 virtual bool GetString(ErrCode nErrId
, OUString
& rCtxStr
) = 0;
219 weld::Window
* GetParent();
221 static ErrorContext
* GetContext();
224 std::unique_ptr
<ImplErrorContext
> pImpl
;
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */