Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / errinf.hxx
blobc55011dd0b5d37251fd735618aca4e0daa5cd1f5
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 __RSC
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>
30 #include <vector>
31 #include <memory>
33 #include <limits.h>
35 namespace vcl { class Window; }
37 class ErrorHandler;
38 class ErrorContext;
39 class ErrorStringFactory;
40 class ErrorInfo;
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;
60 public:
61 ErrorRegistry();
63 static void RegisterDisplay(BasicDisplayErrorFunc*);
64 static void RegisterDisplay(WindowDisplayErrorFunc*);
66 private:
67 DisplayFnPtr pDsp;
68 bool bIsWindowDsp;
69 sal_uInt16 nNextError;
71 std::vector<ErrorHandler*> errorHandlers;
72 std::vector<ErrorContext*> contexts;
74 DynamicErrorInfo* ppDynErrInfo[ERRCODE_DYNAMIC_COUNT];
77 enum class DialogMask
79 NONE = 0x0000,
80 ButtonsOk = 0x0001,
81 ButtonsCancel = 0x0002,
82 ButtonsRetry = 0x0004,
83 ButtonsOkCancel = 0x0003,
84 ButtonsNo = 0x0008,
85 ButtonsYes = 0x0010,
86 ButtonsYesNo = 0x0018,
87 ButtonsYesNoCancel = 0x001a,
89 ButtonDefaultsOk = 0x0100,
90 ButtonDefaultsCancel = 0x0200,
91 ButtonDefaultsYes = 0x0300,
92 ButtonDefaultsNo = 0x0400,
94 MessageError = 0x1000,
95 MessageWarning = 0x2000,
96 MessageInfo = 0x3000,
98 MAX = USHRT_MAX,
100 namespace o3tl
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;
115 public:
116 ErrorHandler();
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:
124 1. nFlags,
125 2. Resource Flags
126 3. Dynamic Flags
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);
137 protected:
138 virtual bool CreateString(const ErrorInfo*, OUString &) const = 0;
142 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorInfo
144 public:
145 ErrorInfo(sal_uInt32 nArgUserId) :
146 nUserId(nArgUserId) {}
147 virtual ~ErrorInfo();
149 sal_uInt32 GetErrorCode() const { return nUserId; }
151 static ErrorInfo* GetErrorInfo(sal_uInt32);
153 private:
154 sal_uInt32 nUserId;
157 class SAL_WARN_UNUSED VCL_DLLPUBLIC DynamicErrorInfo : public ErrorInfo
159 friend class ImplDynamicErrorInfo;
161 public:
162 DynamicErrorInfo(sal_uInt32 nUserId, DialogMask nMask);
163 virtual ~DynamicErrorInfo() override;
165 operator sal_uInt32() const;
166 DialogMask GetDialogMask() const;
168 private:
169 std::unique_ptr<ImplDynamicErrorInfo> pImpl;
173 class SAL_WARN_UNUSED VCL_DLLPUBLIC StringErrorInfo : public DynamicErrorInfo
175 public:
176 StringErrorInfo(sal_uInt32 nUserId,
177 const OUString& aStringP,
178 DialogMask nMask = DialogMask::NONE);
180 const OUString& GetErrorString() const { return aString; }
182 private:
183 OUString aString;
187 class SAL_WARN_UNUSED VCL_DLLPUBLIC TwoStringErrorInfo: public DynamicErrorInfo
189 public:
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; }
197 private:
198 OUString aArg1;
199 OUString aArg2;
203 struct ImplErrorContext;
205 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorContext
207 friend class ErrorHandler;
209 public:
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();
218 private:
219 std::unique_ptr<ImplErrorContext> pImpl;
223 #endif
224 #endif
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */