vcl: 'horizontically'
[LibreOffice.git] / include / vcl / errinf.hxx
blob88f4a3bb2390bb1fe55beb53019141854b7b516b
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 <vcl/errcode.hxx>
25 #include <vcl/dllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
28 #include <vector>
29 #include <memory>
31 #include <limits.h>
33 namespace weld { class Window; }
35 class ErrorHandler;
36 class ErrorContext;
37 class ErrorInfo;
38 class DynamicErrorInfo;
39 class ImplDynamicErrorInfo;
40 enum class DialogMask;
42 class VCL_DLLPUBLIC ErrorStringFactory
44 public:
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;
63 public:
64 ErrorRegistry();
66 static void RegisterDisplay(BasicDisplayErrorFunc*);
67 static void RegisterDisplay(WindowDisplayErrorFunc*);
68 static void Reset();
70 private:
71 DisplayFnPtr pDsp;
72 bool bIsWindowDsp;
73 sal_uInt16 nNextError;
75 std::vector<ErrorHandler*> errorHandlers;
76 std::vector<ErrorContext*> contexts;
78 DynamicErrorInfo* ppDynErrInfo[ERRCODE_DYNAMIC_COUNT];
81 enum class DialogMask
83 NONE = 0x0000,
84 ButtonsOk = 0x0001,
85 ButtonsCancel = 0x0002,
86 ButtonsRetry = 0x0004,
87 ButtonsNo = 0x0008,
88 ButtonsYes = 0x0010,
89 ButtonsYesNo = 0x0018,
91 ButtonDefaultsOk = 0x0100,
92 ButtonDefaultsCancel = 0x0200,
93 ButtonDefaultsYes = 0x0300,
94 ButtonDefaultsNo = 0x0400,
96 MessageError = 0x1000,
97 MessageWarning = 0x2000,
98 MessageInfo = 0x3000,
100 MAX = USHRT_MAX,
102 namespace o3tl
104 template<> struct typed_flags<DialogMask> : is_typed_flags<DialogMask, 0xffff> {};
107 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorHandler
109 friend class ErrorStringFactory;
111 public:
112 ErrorHandler();
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:
120 1. nFlags,
121 2. Resource Flags
122 3. Dynamic Flags
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);
134 protected:
135 virtual bool CreateString(const ErrorInfo*, OUString &) const = 0;
139 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorInfo
141 public:
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);
150 private:
151 ErrCode nUserId;
154 class SAL_WARN_UNUSED VCL_DLLPUBLIC DynamicErrorInfo : public ErrorInfo
156 friend class ImplDynamicErrorInfo;
158 public:
159 DynamicErrorInfo(ErrCode nUserId, DialogMask nMask);
160 virtual ~DynamicErrorInfo() override;
162 operator ErrCode() const;
163 DialogMask GetDialogMask() const;
165 private:
166 std::unique_ptr<ImplDynamicErrorInfo> pImpl;
170 class SAL_WARN_UNUSED VCL_DLLPUBLIC StringErrorInfo final : public DynamicErrorInfo
172 public:
173 StringErrorInfo(ErrCode nUserId,
174 const OUString& aStringP,
175 DialogMask nMask = DialogMask::NONE);
177 const OUString& GetErrorString() const { return aString; }
179 private:
180 OUString aString;
184 class SAL_WARN_UNUSED VCL_DLLPUBLIC TwoStringErrorInfo final : public DynamicErrorInfo
186 public:
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; }
194 private:
195 OUString aArg1;
196 OUString aArg2;
200 struct ImplErrorContext;
202 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorContext
204 friend class ErrorHandler;
206 public:
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();
215 private:
216 std::unique_ptr<ImplErrorContext> pImpl;
220 #endif
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */