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 
42 typedef void (* DisplayFnPtr)();
43 
45  weld::Window*, DialogMask eMask, const OUString &rErr, const OUString &rAction);
46 
47 typedef void BasicDisplayErrorFunc(
48  const OUString &rErr, const OUString &rAction);
49 
51 {
52  friend class ErrorHandler;
53  friend class ErrorContext;
54  friend class ErrorStringFactory;
55  friend class ImplDynamicErrorInfo;
56 
57 public:
58  ErrorRegistry();
59 
60  static void RegisterDisplay(BasicDisplayErrorFunc*);
61  static void RegisterDisplay(WindowDisplayErrorFunc*);
62 
63 private:
66  sal_uInt16 nNextError;
67 
68  std::vector<ErrorHandler*> errorHandlers;
69  std::vector<ErrorContext*> contexts;
70 
72 };
73 
74 enum class DialogMask
75 {
76  NONE = 0x0000,
77  ButtonsOk = 0x0001,
78  ButtonsCancel = 0x0002,
79  ButtonsRetry = 0x0004,
80  ButtonsNo = 0x0008,
81  ButtonsYes = 0x0010,
82  ButtonsYesNo = 0x0018,
83 
84  ButtonDefaultsOk = 0x0100,
85  ButtonDefaultsCancel = 0x0200,
86  ButtonDefaultsYes = 0x0300,
87  ButtonDefaultsNo = 0x0400,
88 
89  MessageError = 0x1000,
90  MessageWarning = 0x2000,
91  MessageInfo = 0x3000,
92 
93  MAX = USHRT_MAX,
94 };
95 namespace o3tl
96 {
97  template<> struct typed_flags<DialogMask> : is_typed_flags<DialogMask, 0xffff> {};
98 }
99 
101 {
102  friend class ErrorStringFactory;
103 
104 public:
105  ErrorHandler();
106  virtual ~ErrorHandler();
107 
124  static DialogMask HandleError(ErrCode nId, weld::Window* pParent = nullptr, DialogMask nMask = DialogMask::MAX);
125  static bool GetErrorString(ErrCode nId, OUString& rStr);
126 
127 protected:
128  virtual bool CreateString(const ErrorInfo*, OUString &) const = 0;
129 
130 };
131 
133 {
134 public:
135  ErrorInfo(ErrCode nArgUserId) :
136  nUserId(nArgUserId) {}
137  virtual ~ErrorInfo();
138 
139  ErrCode const & GetErrorCode() const { return nUserId; }
140 
141  static std::unique_ptr<ErrorInfo> GetErrorInfo(ErrCode);
142 
143 private:
145 };
146 
148 {
149  friend class ImplDynamicErrorInfo;
150 
151 public:
153  virtual ~DynamicErrorInfo() override;
154 
155  operator ErrCode() const;
156  DialogMask GetDialogMask() const;
157 
158 private:
159  std::unique_ptr<ImplDynamicErrorInfo> pImpl;
160 
161 };
162 
164 {
165 public:
166  StringErrorInfo(ErrCode nUserId,
167  const OUString& aStringP,
168  DialogMask nMask = DialogMask::NONE);
169 
170  const OUString& GetErrorString() const { return aString; }
171 
172 private:
173  OUString const aString;
174 
175 };
176 
178 {
179 public:
180  TwoStringErrorInfo(ErrCode nUserID, const OUString & rTheArg1,
181  const OUString & rTheArg2, DialogMask nMask):
182  DynamicErrorInfo(nUserID, nMask), aArg1(rTheArg1), aArg2(rTheArg2) {}
183 
184  const OUString& GetArg1() const { return aArg1; }
185  const OUString& GetArg2() const { return aArg2; }
186 
187 private:
188  OUString const aArg1;
189  OUString const aArg2;
190 
191 };
192 
193 struct ImplErrorContext;
194 
196 {
197  friend class ErrorHandler;
198 
199 public:
200  ErrorContext(weld::Window *pWin);
201  virtual ~ErrorContext();
202 
203  virtual bool GetString(ErrCode nErrId, OUString& rCtxStr) = 0;
204  weld::Window* GetParent();
205 
206  static ErrorContext* GetContext();
207 
208 private:
209  std::unique_ptr<ImplErrorContext> pImpl;
210 
211 };
212 
213 #endif
214 
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool CreateString(const ErrorInfo *, OUString &)
Definition: errinf.cxx:39
DisplayFnPtr pDsp
Definition: errinf.hxx:64
friend class DynamicErrorInfo
Definition: errinf.cxx:214
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
DialogMask const nMask
Definition: errinf.cxx:227
std::vector< ErrorHandler * > errorHandlers
Definition: errinf.hxx:68
TwoStringErrorInfo(ErrCode nUserID, const OUString &rTheArg1, const OUString &rTheArg2, DialogMask nMask)
Definition: errinf.hxx:180
bool bIsWindowDsp
Definition: errinf.hxx:65
DialogMask
Definition: errinf.hxx:74
OUString GetString(int nId)
const OUString & GetErrorString() const
Definition: errinf.hxx:170
const OUString & GetArg1() const
Definition: errinf.hxx:184
OUString const aString
Definition: errinf.hxx:173
DialogMask WindowDisplayErrorFunc(weld::Window *, DialogMask eMask, const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:44
std::unique_ptr< ImplDynamicErrorInfo > pImpl
Definition: errinf.hxx:159
ErrCode const nUserId
Definition: errinf.hxx:144
std::unique_ptr< ImplErrorContext > pImpl
Definition: errinf.hxx:209
void BasicDisplayErrorFunc(const OUString &rErr, const OUString &rAction)
Definition: errinf.hxx:47
OUString const aArg1
Definition: errinf.hxx:188
#define SAL_WARN_UNUSED
ErrCode const & GetErrorCode() const
Definition: errinf.hxx:139
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
void(* DisplayFnPtr)()
Definition: errinf.hxx:42
std::vector< ErrorContext * > contexts
Definition: errinf.hxx:69
#define ERRCODE_DYNAMIC_COUNT
Definition: errcode.hxx:55
sal_uInt16 nNextError
Definition: errinf.hxx:66
ErrorInfo(ErrCode nArgUserId)
Definition: errinf.hxx:135
const OUString & GetArg2() const
Definition: errinf.hxx:185
OUString const aArg2
Definition: errinf.hxx:189
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo