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>
24 #include <vcl/errcode.hxx>
25 #include <vcl/dllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
33 namespace weld
{ class Window
; }
38 class DynamicErrorInfo
;
39 class ImplDynamicErrorInfo
;
40 enum class DialogMask
;
42 class VCL_DLLPUBLIC ErrorStringFactory
45 static bool CreateString(const ErrorInfo
*, OUString
&);
48 typedef void (* DisplayFnPtr
)();
50 typedef DialogMask
WindowDisplayErrorFunc(
51 weld::Window
*, DialogMask eMask
, const OUString
&rErr
, const OUString
&rAction
);
53 typedef void BasicDisplayErrorFunc(
54 const OUString
&rErr
, const OUString
&rAction
);
56 class VCL_DLLPUBLIC ErrorRegistry
58 friend class ErrorHandler
;
59 friend class ErrorContext
;
60 friend class ErrorStringFactory
;
61 friend class ImplDynamicErrorInfo
;
66 static void RegisterDisplay(BasicDisplayErrorFunc
*);
67 static void RegisterDisplay(WindowDisplayErrorFunc
*);
73 sal_uInt16 nNextError
;
75 std::vector
<ErrorHandler
*> errorHandlers
;
76 std::vector
<ErrorContext
*> contexts
;
78 DynamicErrorInfo
* ppDynErrInfo
[ERRCODE_DYNAMIC_COUNT
];
85 ButtonsCancel
= 0x0002,
86 ButtonsRetry
= 0x0004,
89 ButtonsYesNo
= 0x0018,
91 ButtonDefaultsOk
= 0x0100,
92 ButtonDefaultsCancel
= 0x0200,
93 ButtonDefaultsYes
= 0x0300,
94 ButtonDefaultsNo
= 0x0400,
96 MessageError
= 0x1000,
97 MessageWarning
= 0x2000,
104 template<> struct typed_flags
<DialogMask
> : is_typed_flags
<DialogMask
, 0xffff> {};
107 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorHandler
109 friend class ErrorStringFactory
;
113 virtual ~ErrorHandler();
115 /** Handles an error.
117 If nFlags is not set, the DynamicErrorInfo flags or the
118 resource flags will be used. Thus the order is:
123 4. Default ButtonsOk, MessageError
125 @param nErrCodeId error id
126 @param pParent parent window the error dialog will be modal for. nullptr for unrecommended "pick default"
127 @param nFlags error flags.
129 @return what sort of dialog to use, with what buttons
131 static DialogMask
HandleError(ErrCode nId
, weld::Window
* pParent
= nullptr, DialogMask nMask
= DialogMask::MAX
);
132 static bool GetErrorString(ErrCode nId
, OUString
& rStr
);
135 virtual bool CreateString(const ErrorInfo
*, OUString
&) const = 0;
139 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorInfo
142 ErrorInfo(ErrCode nArgUserId
) :
143 nUserId(nArgUserId
) {}
144 virtual ~ErrorInfo();
146 ErrCode
const & GetErrorCode() const { return nUserId
; }
148 static std::unique_ptr
<ErrorInfo
> GetErrorInfo(ErrCode
);
151 ErrCode
const nUserId
;
154 class SAL_WARN_UNUSED VCL_DLLPUBLIC DynamicErrorInfo
: public ErrorInfo
156 friend class ImplDynamicErrorInfo
;
159 DynamicErrorInfo(ErrCode nUserId
, DialogMask nMask
);
160 virtual ~DynamicErrorInfo() override
;
162 operator ErrCode() const;
163 DialogMask
GetDialogMask() const;
166 std::unique_ptr
<ImplDynamicErrorInfo
> pImpl
;
170 class SAL_WARN_UNUSED VCL_DLLPUBLIC StringErrorInfo final
: public DynamicErrorInfo
173 StringErrorInfo(ErrCode nUserId
,
174 const OUString
& aStringP
,
175 DialogMask nMask
= DialogMask::NONE
);
177 const OUString
& GetErrorString() const { return aString
; }
180 OUString
const aString
;
184 class SAL_WARN_UNUSED VCL_DLLPUBLIC TwoStringErrorInfo final
: public DynamicErrorInfo
187 TwoStringErrorInfo(ErrCode nUserID
, const OUString
& rTheArg1
,
188 const OUString
& rTheArg2
, DialogMask nMask
):
189 DynamicErrorInfo(nUserID
, nMask
), aArg1(rTheArg1
), aArg2(rTheArg2
) {}
191 const OUString
& GetArg1() const { return aArg1
; }
192 const OUString
& GetArg2() const { return aArg2
; }
195 OUString
const aArg1
;
196 OUString
const aArg2
;
200 struct ImplErrorContext
;
202 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorContext
204 friend class ErrorHandler
;
207 ErrorContext(weld::Window
*pWin
);
208 virtual ~ErrorContext();
210 virtual bool GetString(ErrCode nErrId
, OUString
& rCtxStr
) = 0;
211 weld::Window
* GetParent();
213 static ErrorContext
* GetContext();
216 std::unique_ptr
<ImplErrorContext
> pImpl
;
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */