LibreOffice Module vcl (master) 1
errinf.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_VCL_ERRINF_HXX
21#define INCLUDED_VCL_ERRINF_HXX
22
23#include <rtl/ustring.hxx>
24#include <utility>
25#include <vcl/errcode.hxx>
26#include <vcl/dllapi.h>
28
29#include <vector>
30#include <memory>
31
32#include <limits.h>
33
34namespace weld { class Window; }
35
36class ErrorHandler;
37class ErrorContext;
38class ErrorInfo;
41enum class DialogMask;
42
44{
45public:
46 static bool CreateString(const ErrorInfo*, OUString&);
47};
48
49typedef void (* DisplayFnPtr)();
50
52 weld::Window*, DialogMask eMask, const OUString &rErr, const OUString &rAction);
53
55 const OUString &rErr, const OUString &rAction);
56
58{
59 friend class ErrorHandler;
60 friend class ErrorContext;
61 friend class ErrorStringFactory;
63
64public:
66
67 static void RegisterDisplay(BasicDisplayErrorFunc*);
68 static void RegisterDisplay(WindowDisplayErrorFunc*);
69
70 static void SetLock(bool bLock);
71 static bool GetLock();
72
73 static void Reset();
74
75private:
78
79 bool m_bLock;
80
81 sal_uInt16 nNextError;
82
83 std::vector<ErrorHandler*> errorHandlers;
84 std::vector<ErrorContext*> contexts;
85
87};
88
89enum class DialogMask
90{
91 NONE = 0x0000,
92 ButtonsOk = 0x0001,
93 ButtonsCancel = 0x0002,
94 ButtonsRetry = 0x0004,
95 ButtonsNo = 0x0008,
96 ButtonsYes = 0x0010,
97 ButtonsYesNo = 0x0018,
98
99 ButtonDefaultsOk = 0x0100,
100 ButtonDefaultsCancel = 0x0200,
101 ButtonDefaultsYes = 0x0300,
102 ButtonDefaultsNo = 0x0400,
103
104 MessageError = 0x1000,
105 MessageWarning = 0x2000,
106 MessageInfo = 0x3000,
107
108 MAX = USHRT_MAX,
109};
110namespace o3tl
111{
112 template<> struct typed_flags<DialogMask> : is_typed_flags<DialogMask, 0xffff> {};
113}
114
116{
117 friend class ErrorStringFactory;
118
119public:
120 ErrorHandler();
121 virtual ~ErrorHandler();
122
139 static DialogMask HandleError(ErrCode nId, weld::Window* pParent = nullptr, DialogMask nMask = DialogMask::MAX);
140 static bool GetErrorString(ErrCode nId, OUString& rStr);
141
142protected:
143 virtual bool CreateString(const ErrorInfo*, OUString &) const = 0;
144
145};
146
148{
149public:
150 ErrorInfo(ErrCode nArgUserId) :
151 nUserId(nArgUserId) {}
152 virtual ~ErrorInfo();
153
154 ErrCode const & GetErrorCode() const { return nUserId; }
155
156 static std::unique_ptr<ErrorInfo> GetErrorInfo(ErrCode);
157
158private:
160};
161
163{
165
166public:
168 virtual ~DynamicErrorInfo() override;
169
170 operator ErrCode() const;
171 DialogMask GetDialogMask() const;
172
173private:
174 std::unique_ptr<ImplDynamicErrorInfo> pImpl;
175
176};
177
179{
180public:
181 StringErrorInfo(ErrCode nUserId,
182 OUString aStringP,
184
185 const OUString& GetErrorString() const { return aString; }
186
187private:
188 OUString aString;
189
190};
191
193{
194public:
195 TwoStringErrorInfo(ErrCode nUserID, OUString aTheArg1,
196 OUString aTheArg2, DialogMask nMask):
197 DynamicErrorInfo(nUserID, nMask), aArg1(std::move(aTheArg1)), aArg2(std::move(aTheArg2)) {}
198
199 const OUString& GetArg1() const { return aArg1; }
200 const OUString& GetArg2() const { return aArg2; }
201
202private:
203 OUString aArg1;
204 OUString aArg2;
205
206};
207
208struct ImplErrorContext;
209
211{
212 friend class ErrorHandler;
213
214public:
216 virtual ~ErrorContext();
217
218 virtual bool GetString(ErrCode nErrId, OUString& rCtxStr) = 0;
219 weld::Window* GetParent();
220
221 static ErrorContext* GetContext();
222
223private:
224 std::unique_ptr<ImplErrorContext> pImpl;
225
226};
227
228#endif
229
230/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< ImplDynamicErrorInfo > pImpl
Definition: errinf.hxx:174
virtual bool GetString(ErrCode nErrId, OUString &rCtxStr)=0
std::unique_ptr< ImplErrorContext > pImpl
Definition: errinf.hxx:224
virtual bool CreateString(const ErrorInfo *, OUString &) const =0
ErrCode nUserId
Definition: errinf.hxx:159
ErrorInfo(ErrCode nArgUserId)
Definition: errinf.hxx:150
ErrCode const & GetErrorCode() const
Definition: errinf.hxx:154
bool bIsWindowDsp
Definition: errinf.hxx:77
std::vector< ErrorHandler * > errorHandlers
Definition: errinf.hxx:83
bool m_bLock
Definition: errinf.hxx:79
DisplayFnPtr pDsp
Definition: errinf.hxx:76
sal_uInt16 nNextError
Definition: errinf.hxx:81
std::vector< ErrorContext * > contexts
Definition: errinf.hxx:84
friend class DynamicErrorInfo
Definition: errinf.cxx:236
DialogMask nMask
Definition: errinf.cxx:249
OUString aString
Definition: errinf.hxx:188
const OUString & GetErrorString() const
Definition: errinf.hxx:185
const OUString & GetArg1() const
Definition: errinf.hxx:199
OUString aArg1
Definition: errinf.hxx:203
const OUString & GetArg2() const
Definition: errinf.hxx:200
OUString aArg2
Definition: errinf.hxx:204
TwoStringErrorInfo(ErrCode nUserID, OUString aTheArg1, OUString aTheArg2, DialogMask nMask)
Definition: errinf.hxx:195
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define ERRCODE_DYNAMIC_COUNT
Definition: errcode.hxx:55
DialogMask WindowDisplayErrorFunc(weld::Window *, DialogMask eMask, const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:51
void BasicDisplayErrorFunc(const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:54
DialogMask
Definition: errinf.hxx:90
@ ButtonDefaultsCancel
void(* DisplayFnPtr)()
Definition: errinf.hxx:49
NONE
#define SAL_WARN_UNUSED