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  static void Reset();
69 
70 private:
73  sal_uInt16 nNextError;
74 
75  std::vector<ErrorHandler*> errorHandlers;
76  std::vector<ErrorContext*> contexts;
77 
79 };
80 
81 enum class DialogMask
82 {
83  NONE = 0x0000,
84  ButtonsOk = 0x0001,
85  ButtonsCancel = 0x0002,
86  ButtonsRetry = 0x0004,
87  ButtonsNo = 0x0008,
88  ButtonsYes = 0x0010,
89  ButtonsYesNo = 0x0018,
90 
91  ButtonDefaultsOk = 0x0100,
92  ButtonDefaultsCancel = 0x0200,
93  ButtonDefaultsYes = 0x0300,
94  ButtonDefaultsNo = 0x0400,
95 
96  MessageError = 0x1000,
97  MessageWarning = 0x2000,
98  MessageInfo = 0x3000,
99 
100  MAX = USHRT_MAX,
101 };
102 namespace o3tl
103 {
104  template<> struct typed_flags<DialogMask> : is_typed_flags<DialogMask, 0xffff> {};
105 }
106 
108 {
109  friend class ErrorStringFactory;
110 
111 public:
112  ErrorHandler();
113  virtual ~ErrorHandler();
114 
131  static DialogMask HandleError(ErrCode nId, weld::Window* pParent = nullptr, DialogMask nMask = DialogMask::MAX);
132  static bool GetErrorString(ErrCode nId, OUString& rStr);
133 
134 protected:
135  virtual bool CreateString(const ErrorInfo*, OUString &) const = 0;
136 
137 };
138 
140 {
141 public:
142  ErrorInfo(ErrCode nArgUserId) :
143  nUserId(nArgUserId) {}
144  virtual ~ErrorInfo();
145 
146  ErrCode const & GetErrorCode() const { return nUserId; }
147 
148  static std::unique_ptr<ErrorInfo> GetErrorInfo(ErrCode);
149 
150 private:
152 };
153 
155 {
156  friend class ImplDynamicErrorInfo;
157 
158 public:
160  virtual ~DynamicErrorInfo() override;
161 
162  operator ErrCode() const;
163  DialogMask GetDialogMask() const;
164 
165 private:
166  std::unique_ptr<ImplDynamicErrorInfo> pImpl;
167 
168 };
169 
171 {
172 public:
173  StringErrorInfo(ErrCode nUserId,
174  const OUString& aStringP,
175  DialogMask nMask = DialogMask::NONE);
176 
177  const OUString& GetErrorString() const { return aString; }
178 
179 private:
180  OUString aString;
181 
182 };
183 
185 {
186 public:
187  TwoStringErrorInfo(ErrCode nUserID, const OUString & rTheArg1,
188  const OUString & rTheArg2, DialogMask nMask):
189  DynamicErrorInfo(nUserID, nMask), aArg1(rTheArg1), aArg2(rTheArg2) {}
190 
191  const OUString& GetArg1() const { return aArg1; }
192  const OUString& GetArg2() const { return aArg2; }
193 
194 private:
195  OUString aArg1;
196  OUString aArg2;
197 
198 };
199 
200 struct ImplErrorContext;
201 
203 {
204  friend class ErrorHandler;
205 
206 public:
207  ErrorContext(weld::Window *pWin);
208  virtual ~ErrorContext();
209 
210  virtual bool GetString(ErrCode nErrId, OUString& rCtxStr) = 0;
211  weld::Window* GetParent();
212 
213  static ErrorContext* GetContext();
214 
215 private:
216  std::unique_ptr<ImplErrorContext> pImpl;
217 
218 };
219 
220 #endif
221 
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool CreateString(const ErrorInfo *, OUString &)
Definition: errinf.cxx:38
DisplayFnPtr pDsp
Definition: errinf.hxx:71
friend class DynamicErrorInfo
Definition: errinf.cxx:219
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
std::vector< ErrorHandler * > errorHandlers
Definition: errinf.hxx:75
TwoStringErrorInfo(ErrCode nUserID, const OUString &rTheArg1, const OUString &rTheArg2, DialogMask nMask)
Definition: errinf.hxx:187
bool bIsWindowDsp
Definition: errinf.hxx:72
DialogMask
Definition: errinf.hxx:81
OUString GetString(int nId)
const OUString & GetErrorString() const
Definition: errinf.hxx:177
const OUString & GetArg1() const
Definition: errinf.hxx:191
OUString aString
Definition: errinf.hxx:180
DialogMask WindowDisplayErrorFunc(weld::Window *, DialogMask eMask, const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:50
std::unique_ptr< ImplDynamicErrorInfo > pImpl
Definition: errinf.hxx:166
std::unique_ptr< ImplErrorContext > pImpl
Definition: errinf.hxx:216
void BasicDisplayErrorFunc(const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:53
OUString aArg2
Definition: errinf.hxx:196
#define SAL_WARN_UNUSED
ErrCode const & GetErrorCode() const
Definition: errinf.hxx:146
DialogMask nMask
Definition: errinf.cxx:232
OUString aArg1
Definition: errinf.hxx:195
ErrCode nUserId
Definition: errinf.hxx:151
void(* DisplayFnPtr)()
Definition: errinf.hxx:48
std::vector< ErrorContext * > contexts
Definition: errinf.hxx:76
#define ERRCODE_DYNAMIC_COUNT
Definition: errcode.hxx:55
sal_uInt16 nNextError
Definition: errinf.hxx:73
ErrorInfo(ErrCode nArgUserId)
Definition: errinf.hxx:142
const OUString & GetArg2() const
Definition: errinf.hxx:192
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo