Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / vcl / errinf.hxx
blob0f4d8d781de7679d5bbf5d827770b3234498f85f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_ERRINF_HXX
21 #define INCLUDED_VCL_ERRINF_HXX
23 #include <rtl/ustring.hxx>
24 #include <utility>
25 #include <comphelper/errcode.hxx>
26 #include <vcl/dllapi.h>
28 #include <vector>
29 #include <memory>
31 #include <limits.h>
33 namespace weld { class Window; }
35 class ErrorHandler;
36 class ErrorContext;
37 enum class DialogMask;
39 class VCL_DLLPUBLIC ErrorStringFactory
41 public:
42 static bool CreateString(const ErrCodeMsg&, OUString&);
45 typedef void (* DisplayFnPtr)();
47 typedef DialogMask WindowDisplayErrorFunc(
48 weld::Window*, DialogMask eMask, const OUString &rErr, const OUString &rAction);
50 typedef void BasicDisplayErrorFunc(
51 const OUString &rErr, const OUString &rAction);
53 class VCL_DLLPUBLIC ErrorRegistry
55 friend class ErrorHandler;
56 friend class ErrorContext;
57 friend class ErrorStringFactory;
59 public:
60 ErrorRegistry();
62 static void RegisterDisplay(BasicDisplayErrorFunc*);
63 static void RegisterDisplay(WindowDisplayErrorFunc*);
65 static void SetLock(bool bLock);
66 static bool GetLock();
68 static void Reset();
70 private:
71 DisplayFnPtr pDsp;
72 bool bIsWindowDsp;
74 bool m_bLock;
76 std::vector<ErrorHandler*> errorHandlers;
77 std::vector<ErrorContext*> contexts;
80 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorHandler
82 friend class ErrorStringFactory;
84 public:
85 ErrorHandler();
86 virtual ~ErrorHandler();
88 /** Handles an error.
90 If nFlags is not set, the DynamicErrorInfo flags or the
91 resource flags will be used. Thus the order is:
93 1. nFlags,
94 2. Resource Flags
95 3. Dynamic Flags
96 4. Default ButtonsOk, MessageError
98 @param nErrCodeId error id
99 @param pParent parent window the error dialog will be modal for. nullptr for unrecommended "pick default"
100 @param nFlags error flags.
102 @return what sort of dialog to use, with what buttons
104 static DialogMask HandleError(const ErrCodeMsg& nId, weld::Window* pParent = nullptr, DialogMask nMask = DialogMask::MAX);
105 static bool GetErrorString(const ErrCodeMsg& nId, OUString& rStr);
107 protected:
108 virtual bool CreateString(const ErrCodeMsg&, OUString &) const = 0;
112 struct ImplErrorContext;
114 class SAL_WARN_UNUSED VCL_DLLPUBLIC ErrorContext
116 friend class ErrorHandler;
118 public:
119 ErrorContext(weld::Window *pWin);
120 virtual ~ErrorContext();
122 virtual bool GetString(const ErrCodeMsg& nErrId, OUString& rCtxStr) = 0;
123 weld::Window* GetParent();
125 static ErrorContext* GetContext();
127 private:
128 std::unique_ptr<ImplErrorContext> pImpl;
132 #endif
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */