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 <vcl/errcode.hxx>
25 #include <vcl/dllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
27 
28 #include <vector>
29 #include <memory>
30 
31 #include <limits.h>
32 
33 namespace weld { class Window; }
34 
35 class ErrorHandler;
36 class ErrorContext;
37 class ErrorInfo;
38 class DynamicErrorInfo;
40 enum class DialogMask;
41 
43 {
44 public:
45  static bool CreateString(const ErrorInfo*, OUString&);
46 };
47 
48 typedef void (* DisplayFnPtr)();
49 
51  weld::Window*, DialogMask eMask, const OUString &rErr, const OUString &rAction);
52 
53 typedef void BasicDisplayErrorFunc(
54  const OUString &rErr, const OUString &rAction);
55 
57 {
58  friend class ErrorHandler;
59  friend class ErrorContext;
60  friend class ErrorStringFactory;
61  friend class ImplDynamicErrorInfo;
62 
63 public:
64  ErrorRegistry();
65 
66  static void RegisterDisplay(BasicDisplayErrorFunc*);
67  static void RegisterDisplay(WindowDisplayErrorFunc*);
68 
69  static void SetLock(bool bLock);
70  static bool GetLock();
71 
72  static void Reset();
73 
74 private:
77 
78  bool m_bLock;
79 
80  sal_uInt16 nNextError;
81 
82  std::vector<ErrorHandler*> errorHandlers;
83  std::vector<ErrorContext*> contexts;
84 
86 };
87 
88 enum class DialogMask
89 {
90  NONE = 0x0000,
91  ButtonsOk = 0x0001,
92  ButtonsCancel = 0x0002,
93  ButtonsRetry = 0x0004,
94  ButtonsNo = 0x0008,
95  ButtonsYes = 0x0010,
96  ButtonsYesNo = 0x0018,
97 
98  ButtonDefaultsOk = 0x0100,
99  ButtonDefaultsCancel = 0x0200,
100  ButtonDefaultsYes = 0x0300,
101  ButtonDefaultsNo = 0x0400,
102 
103  MessageError = 0x1000,
104  MessageWarning = 0x2000,
105  MessageInfo = 0x3000,
106 
107  MAX = USHRT_MAX,
108 };
109 namespace o3tl
110 {
111  template<> struct typed_flags<DialogMask> : is_typed_flags<DialogMask, 0xffff> {};
112 }
113 
115 {
116  friend class ErrorStringFactory;
117 
118 public:
119  ErrorHandler();
120  virtual ~ErrorHandler();
121 
138  static DialogMask HandleError(ErrCode nId, weld::Window* pParent = nullptr, DialogMask nMask = DialogMask::MAX);
139  static bool GetErrorString(ErrCode nId, OUString& rStr);
140 
141 protected:
142  virtual bool CreateString(const ErrorInfo*, OUString &) const = 0;
143 
144 };
145 
147 {
148 public:
149  ErrorInfo(ErrCode nArgUserId) :
150  nUserId(nArgUserId) {}
151  virtual ~ErrorInfo();
152 
153  ErrCode const & GetErrorCode() const { return nUserId; }
154 
155  static std::unique_ptr<ErrorInfo> GetErrorInfo(ErrCode);
156 
157 private:
159 };
160 
162 {
163  friend class ImplDynamicErrorInfo;
164 
165 public:
167  virtual ~DynamicErrorInfo() override;
168 
169  operator ErrCode() const;
170  DialogMask GetDialogMask() const;
171 
172 private:
173  std::unique_ptr<ImplDynamicErrorInfo> pImpl;
174 
175 };
176 
178 {
179 public:
180  StringErrorInfo(ErrCode nUserId,
181  const OUString& aStringP,
182  DialogMask nMask = DialogMask::NONE);
183 
184  const OUString& GetErrorString() const { return aString; }
185 
186 private:
187  OUString aString;
188 
189 };
190 
192 {
193 public:
194  TwoStringErrorInfo(ErrCode nUserID, const OUString & rTheArg1,
195  const OUString & rTheArg2, DialogMask nMask):
196  DynamicErrorInfo(nUserID, nMask), aArg1(rTheArg1), aArg2(rTheArg2) {}
197 
198  const OUString& GetArg1() const { return aArg1; }
199  const OUString& GetArg2() const { return aArg2; }
200 
201 private:
202  OUString aArg1;
203  OUString aArg2;
204 
205 };
206 
207 struct ImplErrorContext;
208 
210 {
211  friend class ErrorHandler;
212 
213 public:
214  ErrorContext(weld::Window *pWin);
215  virtual ~ErrorContext();
216 
217  virtual bool GetString(ErrCode nErrId, OUString& rCtxStr) = 0;
218  weld::Window* GetParent();
219 
220  static ErrorContext* GetContext();
221 
222 private:
223  std::unique_ptr<ImplErrorContext> pImpl;
224 
225 };
226 
227 #endif
228 
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool CreateString(const ErrorInfo *, OUString &)
Definition: errinf.cxx:41
DisplayFnPtr pDsp
Definition: errinf.hxx:75
friend class DynamicErrorInfo
Definition: errinf.cxx:235
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
std::vector< ErrorHandler * > errorHandlers
Definition: errinf.hxx:82
TwoStringErrorInfo(ErrCode nUserID, const OUString &rTheArg1, const OUString &rTheArg2, DialogMask nMask)
Definition: errinf.hxx:194
bool bIsWindowDsp
Definition: errinf.hxx:76
DialogMask
Definition: errinf.hxx:88
OUString GetString(int nId)
const OUString & GetErrorString() const
Definition: errinf.hxx:184
const OUString & GetArg1() const
Definition: errinf.hxx:198
bool m_bLock
Definition: errinf.hxx:78
OUString aString
Definition: errinf.hxx:187
DialogMask WindowDisplayErrorFunc(weld::Window *, DialogMask eMask, const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:50
std::unique_ptr< ImplDynamicErrorInfo > pImpl
Definition: errinf.hxx:173
std::unique_ptr< ImplErrorContext > pImpl
Definition: errinf.hxx:223
void BasicDisplayErrorFunc(const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:53
OUString aArg2
Definition: errinf.hxx:203
#define SAL_WARN_UNUSED
ErrCode const & GetErrorCode() const
Definition: errinf.hxx:153
DialogMask nMask
Definition: errinf.cxx:248
OUString aArg1
Definition: errinf.hxx:202
ErrCode nUserId
Definition: errinf.hxx:158
void(* DisplayFnPtr)()
Definition: errinf.hxx:48
std::vector< ErrorContext * > contexts
Definition: errinf.hxx:83
#define ERRCODE_DYNAMIC_COUNT
Definition: errcode.hxx:55
sal_uInt16 nNextError
Definition: errinf.hxx:80
ErrorInfo(ErrCode nArgUserId)
Definition: errinf.hxx:149
const OUString & GetArg2() const
Definition: errinf.hxx:199
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo