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 #ifndef INCLUDED_VCL_ERRINF_HXX
23 #define INCLUDED_VCL_ERRINF_HXX
25 #include <rtl/ustring.hxx>
26 #include <vcl/errcode.hxx>
27 #include <vcl/dllapi.h>
28 #include <o3tl/typed_flags_set.hxx>
35 namespace vcl
{ class Window
; }
39 class ErrorStringFactory
;
41 class DynamicErrorInfo
;
42 class ImplDynamicErrorInfo
;
43 enum class DialogMask
;
45 typedef void (* DisplayFnPtr
)();
47 typedef DialogMask
WindowDisplayErrorFunc(
48 vcl::Window
*, DialogMask eMask
, const OUString
&rErr
, const OUString
&rAction
);
50 typedef void BasicDisplayErrorFunc(
51 const OUString
&rErr
, const OUString
&rAction
);
53 class VCL_DLLPUBLIC ErrorRegistry
55 friend class ErrorHandler
;
56 friend class ErrorContext
;
57 friend class ErrorStringFactory
;
58 friend class ImplDynamicErrorInfo
;
63 static void RegisterDisplay(BasicDisplayErrorFunc
*);
64 static void RegisterDisplay(WindowDisplayErrorFunc
*);
69 sal_uInt16 nNextError
;
71 std::vector
<ErrorHandler
*> errorHandlers
;
72 std::vector
<ErrorContext
*> contexts
;
74 DynamicErrorInfo
* ppDynErrInfo
[ERRCODE_DYNAMIC_COUNT
];
81 ButtonsCancel
= 0x0002,
82 ButtonsRetry
= 0x0004,
83 ButtonsOkCancel
= 0x0003,
86 ButtonsYesNo
= 0x0018,
87 ButtonsYesNoCancel
= 0x001a,
89 ButtonDefaultsOk
= 0x0100,
90 ButtonDefaultsCancel
= 0x0200,
91 ButtonDefaultsYes
= 0x0300,
92 ButtonDefaultsNo
= 0x0400,
94 MessageError
= 0x1000,
95 MessageWarning
= 0x2000,
102 template<> struct typed_flags
<DialogMask
> : is_typed_flags
<DialogMask
, 0xffff> {};
105 typedef DialogMask
WindowDisplayErrorFunc(
106 vcl::Window
*, DialogMask nMask
, const OUString
&rErr
, const OUString
&rAction
);
108 typedef void BasicDisplayErrorFunc(
109 const OUString
&rErr
, const OUString
&rAction
);
111 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorHandler
113 friend class ErrorStringFactory
;
117 virtual ~ErrorHandler();
119 /** Handles an error.
121 If nFlags is not set, the DynamicErrorInfo flags or the
122 resource flags will be used. Thus the order is:
127 4. Default ButtonsOk, MessageError
129 @param nErrCodeId error id
130 @param nFlags error flags.
132 @return what sort of dialog to use, with what buttons
134 static DialogMask
HandleError(sal_uInt32 nId
, DialogMask nMask
= DialogMask::MAX
);
135 static bool GetErrorString(sal_uInt32 nId
, OUString
& rStr
);
138 virtual bool CreateString(const ErrorInfo
*, OUString
&) const = 0;
142 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorInfo
145 ErrorInfo(sal_uInt32 nArgUserId
) :
146 nUserId(nArgUserId
) {}
147 virtual ~ErrorInfo();
149 sal_uInt32
GetErrorCode() const { return nUserId
; }
151 static ErrorInfo
* GetErrorInfo(sal_uInt32
);
157 class SAL_WARN_UNUSED VCL_DLLPUBLIC DynamicErrorInfo
: public ErrorInfo
159 friend class ImplDynamicErrorInfo
;
162 DynamicErrorInfo(sal_uInt32 nUserId
, DialogMask nMask
);
163 virtual ~DynamicErrorInfo() override
;
165 operator sal_uInt32() const;
166 DialogMask
GetDialogMask() const;
169 std::unique_ptr
<ImplDynamicErrorInfo
> pImpl
;
173 class SAL_WARN_UNUSED VCL_DLLPUBLIC StringErrorInfo
: public DynamicErrorInfo
176 StringErrorInfo(sal_uInt32 nUserId
,
177 const OUString
& aStringP
,
178 DialogMask nMask
= DialogMask::NONE
);
180 const OUString
& GetErrorString() const { return aString
; }
187 class SAL_WARN_UNUSED VCL_DLLPUBLIC TwoStringErrorInfo
: public DynamicErrorInfo
190 TwoStringErrorInfo(sal_uInt32 nUserID
, const OUString
& rTheArg1
,
191 const OUString
& rTheArg2
, DialogMask nMask
):
192 DynamicErrorInfo(nUserID
, nMask
), aArg1(rTheArg1
), aArg2(rTheArg2
) {}
194 const OUString
& GetArg1() const { return aArg1
; }
195 const OUString
& GetArg2() const { return aArg2
; }
203 struct ImplErrorContext
;
205 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorContext
207 friend class ErrorHandler
;
210 ErrorContext(vcl::Window
*pWin
);
211 virtual ~ErrorContext();
213 virtual bool GetString(sal_uInt32 nErrId
, OUString
& rCtxStr
) = 0;
214 vcl::Window
* GetParent();
216 static ErrorContext
* GetContext();
219 std::unique_ptr
<ImplErrorContext
> pImpl
;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */