Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / vcl / errinf.hxx
blob7f2976e23cee97bd72db0102c9fa735ffd6b1e03
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <utility>
25 #include <comphelper/errcode.hxx>
26 #include <vcl/dllapi.h>
27 #include <o3tl/typed_flags_set.hxx>
29 #include <vector>
30 #include <memory>
32 #include <limits.h>
34 namespace weld { class Window; }
36 class ErrorHandler;
37 class ErrorContext;
38 class ErrorInfo;
39 class DynamicErrorInfo;
40 class ImplDynamicErrorInfo;
41 enum class DialogMask;
43 class VCL_DLLPUBLIC ErrorStringFactory
45 public:
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;
64 public:
65 ErrorRegistry();
67 static void RegisterDisplay(BasicDisplayErrorFunc*);
68 static void RegisterDisplay(WindowDisplayErrorFunc*);
70 static void SetLock(bool bLock);
71 static bool GetLock();
73 static void Reset();
75 private:
76 DisplayFnPtr pDsp;
77 bool bIsWindowDsp;
79 bool m_bLock;
81 sal_uInt16 nNextError;
83 std::vector<ErrorHandler*> errorHandlers;
84 std::vector<ErrorContext*> contexts;
86 DynamicErrorInfo* ppDynErrInfo[ERRCODE_DYNAMIC_COUNT];
89 enum class DialogMask
91 NONE = 0x0000,
92 ButtonsOk = 0x0001,
93 ButtonsCancel = 0x0002,
94 ButtonsRetry = 0x0004,
95 ButtonsNo = 0x0008,
96 ButtonsYes = 0x0010,
97 ButtonsYesNo = 0x0018,
99 ButtonDefaultsOk = 0x0100,
100 ButtonDefaultsCancel = 0x0200,
101 ButtonDefaultsYes = 0x0300,
102 ButtonDefaultsNo = 0x0400,
104 MessageError = 0x1000,
105 MessageWarning = 0x2000,
106 MessageInfo = 0x3000,
108 MAX = USHRT_MAX,
110 namespace o3tl
112 template<> struct typed_flags<DialogMask> : is_typed_flags<DialogMask, 0xffff> {};
115 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorHandler
117 friend class ErrorStringFactory;
119 public:
120 ErrorHandler();
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:
128 1. nFlags,
129 2. Resource Flags
130 3. Dynamic Flags
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);
142 protected:
143 virtual bool CreateString(const ErrorInfo*, OUString &) const = 0;
147 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorInfo
149 public:
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);
158 private:
159 ErrCode nUserId;
162 class SAL_WARN_UNUSED VCL_DLLPUBLIC DynamicErrorInfo : public ErrorInfo
164 friend class ImplDynamicErrorInfo;
166 public:
167 DynamicErrorInfo(ErrCode nUserId, DialogMask nMask);
168 virtual ~DynamicErrorInfo() override;
170 operator ErrCode() const;
171 DialogMask GetDialogMask() const;
173 private:
174 std::unique_ptr<ImplDynamicErrorInfo> pImpl;
178 class SAL_WARN_UNUSED VCL_DLLPUBLIC StringErrorInfo final : public DynamicErrorInfo
180 public:
181 StringErrorInfo(ErrCode nUserId,
182 OUString aStringP,
183 DialogMask nMask = DialogMask::NONE);
185 const OUString& GetErrorString() const { return aString; }
187 private:
188 OUString aString;
192 class SAL_WARN_UNUSED VCL_DLLPUBLIC TwoStringErrorInfo final : public DynamicErrorInfo
194 public:
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; }
202 private:
203 OUString aArg1;
204 OUString aArg2;
208 struct ImplErrorContext;
210 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorContext
212 friend class ErrorHandler;
214 public:
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();
223 private:
224 std::unique_ptr<ImplErrorContext> pImpl;
228 #endif
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */