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