xref: /trunk/main/tools/inc/tools/errinf.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __RSC
29 
30 #ifndef _EINF_HXX
31 #define _EINF_HXX
32 
33 #include <limits.h>
34 #include <tools/rtti.hxx>
35 #include <tools/errcode.hxx>
36 #include <tools/string.hxx>
37 #include "tools/toolsdllapi.h"
38 
39 class EDcr_Impl;
40 class ErrHdl_Impl;
41 class Window;
42 
43 // -------------
44 // - ErrorInfo -
45 // -------------
46 
47 class ErrorInfo
48 {
49 private:
50     sal_uIntPtr                   lUserId;
51 
52 public:
53                             TYPEINFO();
54 
55                             ErrorInfo( sal_uIntPtr lArgUserId ) :
56                                 lUserId( lArgUserId ){}
57     virtual                 ~ErrorInfo(){}
58 
59     sal_uIntPtr                   GetErrorCode() const { return lUserId; }
60 
61     static ErrorInfo*       GetErrorInfo(sal_uIntPtr);
62 };
63 
64 
65 // --------------------
66 // - DynamicErrorInfo -
67 // --------------------
68 
69 class TOOLS_DLLPUBLIC DynamicErrorInfo : public ErrorInfo
70 {
71     friend class EDcr_Impl;
72 
73 private:
74     EDcr_Impl*              pImpl;
75 
76 public:
77                             TYPEINFO();
78 
79                             DynamicErrorInfo(sal_uIntPtr lUserId, sal_uInt16 nMask);
80     virtual                 ~DynamicErrorInfo();
81 
82     operator                sal_uIntPtr() const;
83     sal_uInt16                  GetDialogMask() const;
84 };
85 
86 
87 // ---------------------
88 // - StandardErrorInfo -
89 // ---------------------
90 
91 class StandardErrorInfo : public DynamicErrorInfo
92 {
93 private:
94     sal_uIntPtr                   lExtId;
95 
96 public:
97                             TYPEINFO();
98 
99                             StandardErrorInfo( sal_uIntPtr lUserId, sal_uIntPtr lExtId,
100 											  sal_uInt16 nFlags = 0);
101     sal_uIntPtr                   GetExtendedErrorCode() const { return lExtId; }
102 
103 };
104 
105 
106 // -------------------
107 // - StringErrorInfo -
108 // -------------------
109 
110 class TOOLS_DLLPUBLIC StringErrorInfo : public DynamicErrorInfo
111 {
112 private:
113     String                  aString;
114 
115 public:
116                             TYPEINFO();
117 
118                             StringErrorInfo( sal_uIntPtr lUserId,
119 											const String& aStringP,
120 											sal_uInt16 nFlags = 0);
121     const String&           GetErrorString() const { return aString; }
122 };
123 
124 //=============================================================================
125 class TOOLS_DLLPUBLIC TwoStringErrorInfo: public DynamicErrorInfo
126 {
127 private:
128 	String aArg1;
129 	String aArg2;
130 
131 public:
132 	TYPEINFO();
133 
134 	TwoStringErrorInfo(sal_uIntPtr nUserID, const String & rTheArg1,
135 					   const String & rTheArg2, sal_uInt16 nFlags = 0):
136 	 DynamicErrorInfo(nUserID, nFlags), aArg1(rTheArg1), aArg2(rTheArg2) {}
137 	virtual ~TwoStringErrorInfo() {}
138 
139 	String GetArg1() const { return aArg1; }
140 	String GetArg2() const { return aArg2; }
141 };
142 
143 // -------------------
144 // - MessageInfo -
145 // -------------------
146 
147 class TOOLS_DLLPUBLIC MessageInfo : public DynamicErrorInfo
148 {
149   public:
150 
151 	                        TYPEINFO();
152 	                        MessageInfo(sal_uIntPtr UserId, sal_uInt16 nFlags = 0) :
153 							    DynamicErrorInfo(UserId, nFlags){}
154 					        MessageInfo(sal_uIntPtr UserId, const String &rArg,
155 										sal_uInt16 nFlags = 0 ) :
156 	                            DynamicErrorInfo(UserId, nFlags), aArg(rArg) {}
157     const String&           GetMessageArg() const { return aArg; }
158 
159   private:
160 
161 	String           aArg;
162 };
163 
164 
165 // ----------------
166 // - ErrorContext -
167 // ----------------
168 
169 class TOOLS_DLLPUBLIC ErrorContext
170 {
171     friend class ErrorHandler;
172 
173 private:
174     ErrorContext*           pNext;
175     Window*                 pWin;
176 
177 public:
178                             ErrorContext(Window *pWin=0);
179     virtual                 ~ErrorContext();
180 
181     virtual sal_Bool            GetString( sal_uIntPtr nErrId, String& rCtxStr ) = 0;
182     Window*                 GetParent() { return pWin; }
183 
184     static ErrorContext*    GetContext();
185 };
186 
187 
188 // ----------------
189 // - ErrorHandler -
190 // ----------------
191 
192 typedef sal_uInt16 WindowDisplayErrorFunc(
193     Window *, sal_uInt16 nMask, const String &rErr, const String &rAction);
194 
195 typedef void BasicDisplayErrorFunc(
196     const String &rErr, const String &rAction);
197 
198 class TOOLS_DLLPUBLIC ErrorHandler
199 {
200     friend class ErrHdl_Impl;
201 
202 private:
203     ErrHdl_Impl*        pImpl;
204 
205     static sal_uInt16       HandleError_Impl( sal_uIntPtr lId,
206 					  sal_uInt16 nFlags,
207 					  sal_Bool bJustCreateString,
208 					  String & rError);
209 protected:
210     virtual sal_Bool        CreateString( const ErrorInfo *,
211 				      String &, sal_uInt16& nMask ) const = 0;
212             sal_Bool        ForwCreateString( const ErrorInfo*,
213 					  String&, sal_uInt16& nMask ) const;
214 
215 public:
216                         ErrorHandler();
217     virtual             ~ErrorHandler();
218 
219     static sal_uInt16       HandleError ( sal_uIntPtr lId, sal_uInt16 nMask = USHRT_MAX );
220     static sal_Bool         GetErrorString( sal_uIntPtr lId, String& rStr );
221 
222     static void         RegisterDisplay( BasicDisplayErrorFunc* );
223     static void         RegisterDisplay( WindowDisplayErrorFunc* );
224 };
225 
226 
227 // ----------------------
228 // - SimpleErrorHandler -
229 // ----------------------
230 
231 class TOOLS_DLLPUBLIC SimpleErrorHandler : private ErrorHandler
232 {
233 protected:
234     virtual sal_Bool        CreateString( const ErrorInfo*, String &,
235 									  sal_uInt16 &nMask ) const;
236 
237 public:
238                         SimpleErrorHandler();
239 
240 };
241 
242 #endif
243 #endif
244