xref: /trunk/main/tools/inc/tools/errinf.hxx (revision 8b851043)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __RSC
25 
26 #ifndef _EINF_HXX
27 #define _EINF_HXX
28 
29 #include <limits.h>
30 #include <tools/rtti.hxx>
31 #include <tools/errcode.hxx>
32 #include <tools/string.hxx>
33 #include "tools/toolsdllapi.h"
34 
35 class EDcr_Impl;
36 class ErrHdl_Impl;
37 class Window;
38 
39 // -------------
40 // - ErrorInfo -
41 // -------------
42 
43 class ErrorInfo
44 {
45 private:
46     sal_uIntPtr                   lUserId;
47 
48 public:
49                             TYPEINFO();
50 
ErrorInfo(sal_uIntPtr lArgUserId)51                             ErrorInfo( sal_uIntPtr lArgUserId ) :
52                                 lUserId( lArgUserId ){}
~ErrorInfo()53     virtual                 ~ErrorInfo(){}
54 
GetErrorCode() const55     sal_uIntPtr                   GetErrorCode() const { return lUserId; }
56 
57     static ErrorInfo*       GetErrorInfo(sal_uIntPtr);
58 };
59 
60 
61 // --------------------
62 // - DynamicErrorInfo -
63 // --------------------
64 
65 class TOOLS_DLLPUBLIC DynamicErrorInfo : public ErrorInfo
66 {
67     friend class EDcr_Impl;
68 
69 private:
70     EDcr_Impl*              pImpl;
71 
72 public:
73                             TYPEINFO();
74 
75                             DynamicErrorInfo(sal_uIntPtr lUserId, sal_uInt16 nMask);
76     virtual                 ~DynamicErrorInfo();
77 
78     operator                sal_uIntPtr() const;
79     sal_uInt16                  GetDialogMask() const;
80 };
81 
82 
83 // ---------------------
84 // - StandardErrorInfo -
85 // ---------------------
86 
87 class StandardErrorInfo : public DynamicErrorInfo
88 {
89 private:
90     sal_uIntPtr                   lExtId;
91 
92 public:
93                             TYPEINFO();
94 
95                             StandardErrorInfo( sal_uIntPtr lUserId, sal_uIntPtr lExtId,
96 											  sal_uInt16 nFlags = 0);
GetExtendedErrorCode() const97     sal_uIntPtr                   GetExtendedErrorCode() const { return lExtId; }
98 
99 };
100 
101 
102 // -------------------
103 // - StringErrorInfo -
104 // -------------------
105 
106 class TOOLS_DLLPUBLIC StringErrorInfo : public DynamicErrorInfo
107 {
108 private:
109     String                  aString;
110 
111 public:
112                             TYPEINFO();
113 
114                             StringErrorInfo( sal_uIntPtr lUserId,
115 											const String& aStringP,
116 											sal_uInt16 nFlags = 0);
GetErrorString() const117     const String&           GetErrorString() const { return aString; }
118 };
119 
120 //=============================================================================
121 class TOOLS_DLLPUBLIC TwoStringErrorInfo: public DynamicErrorInfo
122 {
123 private:
124 	String aArg1;
125 	String aArg2;
126 
127 public:
128 	TYPEINFO();
129 
TwoStringErrorInfo(sal_uIntPtr nUserID,const String & rTheArg1,const String & rTheArg2,sal_uInt16 nFlags=0)130 	TwoStringErrorInfo(sal_uIntPtr nUserID, const String & rTheArg1,
131 					   const String & rTheArg2, sal_uInt16 nFlags = 0):
132 	 DynamicErrorInfo(nUserID, nFlags), aArg1(rTheArg1), aArg2(rTheArg2) {}
~TwoStringErrorInfo()133 	virtual ~TwoStringErrorInfo() {}
134 
GetArg1() const135 	String GetArg1() const { return aArg1; }
GetArg2() const136 	String GetArg2() const { return aArg2; }
137 };
138 
139 // -------------------
140 // - MessageInfo -
141 // -------------------
142 
143 class TOOLS_DLLPUBLIC MessageInfo : public DynamicErrorInfo
144 {
145   public:
146 
147 	                        TYPEINFO();
MessageInfo(sal_uIntPtr UserId,sal_uInt16 nFlags=0)148 	                        MessageInfo(sal_uIntPtr UserId, sal_uInt16 nFlags = 0) :
149 							    DynamicErrorInfo(UserId, nFlags){}
MessageInfo(sal_uIntPtr UserId,const String & rArg,sal_uInt16 nFlags=0)150 					        MessageInfo(sal_uIntPtr UserId, const String &rArg,
151 										sal_uInt16 nFlags = 0 ) :
152 	                            DynamicErrorInfo(UserId, nFlags), aArg(rArg) {}
GetMessageArg() const153     const String&           GetMessageArg() const { return aArg; }
154 
155   private:
156 
157 	String           aArg;
158 };
159 
160 
161 // ----------------
162 // - ErrorContext -
163 // ----------------
164 
165 class TOOLS_DLLPUBLIC ErrorContext
166 {
167     friend class ErrorHandler;
168 
169 private:
170     ErrorContext*           pNext;
171     Window*                 pWin;
172 
173 public:
174                             ErrorContext(Window *pWin=0);
175     virtual                 ~ErrorContext();
176 
177     virtual sal_Bool            GetString( sal_uIntPtr nErrId, String& rCtxStr ) = 0;
GetParent()178     Window*                 GetParent() { return pWin; }
179 
180     static ErrorContext*    GetContext();
181 };
182 
183 
184 // ----------------
185 // - ErrorHandler -
186 // ----------------
187 
188 typedef sal_uInt16 WindowDisplayErrorFunc(
189     Window *, sal_uInt16 nMask, const String &rErr, const String &rAction);
190 
191 typedef void BasicDisplayErrorFunc(
192     const String &rErr, const String &rAction);
193 
194 class TOOLS_DLLPUBLIC ErrorHandler
195 {
196     friend class ErrHdl_Impl;
197 
198 private:
199     ErrHdl_Impl*        pImpl;
200 
201     static sal_uInt16       HandleError_Impl( sal_uIntPtr lId,
202 					  sal_uInt16 nFlags,
203 					  sal_Bool bJustCreateString,
204 					  String & rError);
205 protected:
206     virtual sal_Bool        CreateString( const ErrorInfo *,
207 				      String &, sal_uInt16& nMask ) const = 0;
208             sal_Bool        ForwCreateString( const ErrorInfo*,
209 					  String&, sal_uInt16& nMask ) const;
210 
211 public:
212                         ErrorHandler();
213     virtual             ~ErrorHandler();
214 
215     static sal_uInt16       HandleError ( sal_uIntPtr lId, sal_uInt16 nMask = USHRT_MAX );
216     static sal_Bool         GetErrorString( sal_uIntPtr lId, String& rStr );
217 
218     static void         RegisterDisplay( BasicDisplayErrorFunc* );
219     static void         RegisterDisplay( WindowDisplayErrorFunc* );
220 };
221 
222 
223 // ----------------------
224 // - SimpleErrorHandler -
225 // ----------------------
226 
227 class TOOLS_DLLPUBLIC SimpleErrorHandler : private ErrorHandler
228 {
229 protected:
230     virtual sal_Bool        CreateString( const ErrorInfo*, String &,
231 									  sal_uInt16 &nMask ) const;
232 
233 public:
234                         SimpleErrorHandler();
235 
236 };
237 
238 #endif
239 #endif
240