xref: /AOO41X/main/tools/source/ref/errinf.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_tools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <limits.h>
32*cdf0e10cSrcweir #include <tools/shl.hxx>
33*cdf0e10cSrcweir #include <tools/debug.hxx>
34*cdf0e10cSrcweir #include <tools/errinf.hxx>
35*cdf0e10cSrcweir #include <tools/string.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir class ErrorHandler;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir namespace {
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir typedef void (* DisplayFnPtr)();
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir struct EDcrData
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir   public:
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     ErrorHandler               *pFirstHdl;
50*cdf0e10cSrcweir     ErrorContext               *pFirstCtx;
51*cdf0e10cSrcweir     DisplayFnPtr               pDsp;
52*cdf0e10cSrcweir     sal_Bool                       bIsWindowDsp;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     DynamicErrorInfo            *ppDcr[ERRCODE_DYNAMIC_COUNT];
56*cdf0e10cSrcweir     sal_uInt16                      nNextDcr;
57*cdf0e10cSrcweir                                 EDcrData();
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir static  EDcrData                *GetData();
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir };
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir class EDcr_Impl
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     sal_uIntPtr                       lErrId;
66*cdf0e10cSrcweir     sal_uInt16                      nMask;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     void                        RegisterEDcr(DynamicErrorInfo *);
69*cdf0e10cSrcweir     void                        UnRegisterEDcr(DynamicErrorInfo *);
70*cdf0e10cSrcweir     static ErrorInfo           *GetDynamicErrorInfo(sal_uIntPtr lId);
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir friend class DynamicErrorInfo;
73*cdf0e10cSrcweir friend class ErrorInfo;
74*cdf0e10cSrcweir };
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir EDcrData::EDcrData()
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir 	for(sal_uInt16 n=0;n<ERRCODE_DYNAMIC_COUNT;n++)
80*cdf0e10cSrcweir 		ppDcr[n]=0;
81*cdf0e10cSrcweir 	nNextDcr=0;
82*cdf0e10cSrcweir 	pFirstHdl=0;
83*cdf0e10cSrcweir 	pDsp=0;
84*cdf0e10cSrcweir 	pFirstCtx=0;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir EDcrData *EDcrData::GetData()
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir #ifdef BOOTSTRAP
91*cdf0e10cSrcweir 	return 0x0;
92*cdf0e10cSrcweir #else
93*cdf0e10cSrcweir     EDcrData **ppDat=(EDcrData **)GetAppData(SHL_ERR);
94*cdf0e10cSrcweir     if(!*ppDat)
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir         return (*ppDat=new EDcrData);
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir     else
99*cdf0e10cSrcweir         return *ppDat;
100*cdf0e10cSrcweir #endif
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir void EDcr_Impl::RegisterEDcr(DynamicErrorInfo *pDcr)
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     //Vergibt eine dynamische Id
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     EDcrData* pData=EDcrData::GetData();
108*cdf0e10cSrcweir     lErrId= (((sal_uIntPtr)pData->nNextDcr + 1) << ERRCODE_DYNAMIC_SHIFT) +
109*cdf0e10cSrcweir         pDcr->GetErrorCode();
110*cdf0e10cSrcweir     DynamicErrorInfo **ppDcr=pData->ppDcr;
111*cdf0e10cSrcweir     sal_uInt16 nNext=pData->nNextDcr;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     // bei einem Ringbuffer koennen wir uns das ASSERT wohl sparen!
114*cdf0e10cSrcweir 	// DBG_ASSERT(ppDcr[nNext]==0,"ErrHdl: Alle Errors belegt");
115*cdf0e10cSrcweir     if(ppDcr[nNext])
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir         delete ppDcr[nNext];
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir     ppDcr[nNext]=pDcr;
120*cdf0e10cSrcweir     if(++pData->nNextDcr>=ERRCODE_DYNAMIC_COUNT)
121*cdf0e10cSrcweir         pData->nNextDcr=0;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir void EDcr_Impl::UnRegisterEDcr(DynamicErrorInfo *pDcr)
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     EDcrData* pData=EDcrData::GetData();
129*cdf0e10cSrcweir     DynamicErrorInfo **ppDcr=pData->ppDcr;
130*cdf0e10cSrcweir     sal_uIntPtr lIdx=(
131*cdf0e10cSrcweir         ((sal_uIntPtr)(*pDcr) & ERRCODE_DYNAMIC_MASK)>>ERRCODE_DYNAMIC_SHIFT)-1;
132*cdf0e10cSrcweir     DBG_ASSERT(ppDcr[lIdx]==pDcr,"ErrHdl: Error nicht gefunden");
133*cdf0e10cSrcweir     if(ppDcr[lIdx]==pDcr)
134*cdf0e10cSrcweir         ppDcr[lIdx]=0;
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir TYPEINIT0(ErrorInfo);
138*cdf0e10cSrcweir TYPEINIT1(DynamicErrorInfo, ErrorInfo);
139*cdf0e10cSrcweir TYPEINIT1(StandardErrorInfo, DynamicErrorInfo);
140*cdf0e10cSrcweir TYPEINIT1(StringErrorInfo, DynamicErrorInfo);
141*cdf0e10cSrcweir TYPEINIT1(TwoStringErrorInfo, DynamicErrorInfo);
142*cdf0e10cSrcweir TYPEINIT1(MessageInfo, DynamicErrorInfo);
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir ErrorInfo *ErrorInfo::GetErrorInfo(sal_uIntPtr lId)
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     if(lId & ERRCODE_DYNAMIC_MASK)
148*cdf0e10cSrcweir         return EDcr_Impl::GetDynamicErrorInfo(lId);
149*cdf0e10cSrcweir     else
150*cdf0e10cSrcweir         return new ErrorInfo(lId);
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir DynamicErrorInfo::operator sal_uIntPtr() const
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     return pImpl->lErrId;
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir DynamicErrorInfo::DynamicErrorInfo(sal_uIntPtr lArgUserId, sal_uInt16 nMask)
159*cdf0e10cSrcweir : ErrorInfo(lArgUserId)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     pImpl=new EDcr_Impl;
162*cdf0e10cSrcweir     pImpl->RegisterEDcr(this);
163*cdf0e10cSrcweir     pImpl->nMask=nMask;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir DynamicErrorInfo::~DynamicErrorInfo()
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     pImpl->UnRegisterEDcr(this);
169*cdf0e10cSrcweir     delete pImpl;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir ErrorInfo* EDcr_Impl::GetDynamicErrorInfo(sal_uIntPtr lId)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     sal_uIntPtr lIdx=((lId & ERRCODE_DYNAMIC_MASK)>>ERRCODE_DYNAMIC_SHIFT)-1;
175*cdf0e10cSrcweir     DynamicErrorInfo* pDcr=EDcrData::GetData()->ppDcr[lIdx];
176*cdf0e10cSrcweir     if(pDcr && (sal_uIntPtr)(*pDcr)==lId)
177*cdf0e10cSrcweir         return pDcr;
178*cdf0e10cSrcweir     else
179*cdf0e10cSrcweir         return new ErrorInfo(lId & ~ERRCODE_DYNAMIC_MASK);
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir sal_uInt16 DynamicErrorInfo::GetDialogMask() const
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     return pImpl->nMask;
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir StandardErrorInfo::StandardErrorInfo(
190*cdf0e10cSrcweir 	sal_uIntPtr UserId, sal_uIntPtr lArgExtId, sal_uInt16 nFlags)
191*cdf0e10cSrcweir : DynamicErrorInfo(UserId, nFlags), lExtId(lArgExtId)
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir StringErrorInfo::StringErrorInfo(
197*cdf0e10cSrcweir 	sal_uIntPtr UserId, const String& aStringP,  sal_uInt16 nFlags)
198*cdf0e10cSrcweir : DynamicErrorInfo(UserId, nFlags), aString(aStringP)
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir class ErrHdl_Impl
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir   public:
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     ErrorHandler        *pNext;
208*cdf0e10cSrcweir     static sal_Bool         CreateString(const ErrorHandler *pStart,
209*cdf0e10cSrcweir                                      const ErrorInfo*, String&, sal_uInt16&);
210*cdf0e10cSrcweir };
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir static void aDspFunc(const String &rErr, const String &rAction)
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir     ByteString aErr("Aktion: ");
216*cdf0e10cSrcweir     aErr+= ByteString( rAction, RTL_TEXTENCODING_ASCII_US );
217*cdf0e10cSrcweir     aErr+=" Fehler: ";
218*cdf0e10cSrcweir     aErr+= ByteString( rErr, RTL_TEXTENCODING_ASCII_US );
219*cdf0e10cSrcweir     DBG_ERROR(aErr.GetBuffer());
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir ErrorContext::ErrorContext(Window *pWinP)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     EDcrData *pData=EDcrData::GetData();
226*cdf0e10cSrcweir     ErrorContext *&pHdl=pData->pFirstCtx;
227*cdf0e10cSrcweir     pWin=pWinP;
228*cdf0e10cSrcweir     pNext=pHdl;
229*cdf0e10cSrcweir     pHdl=this;
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir ErrorContext::~ErrorContext()
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     ErrorContext **ppCtx=&(EDcrData::GetData()->pFirstCtx);
235*cdf0e10cSrcweir     while(*ppCtx && *ppCtx!=this)
236*cdf0e10cSrcweir         ppCtx=&((*ppCtx)->pNext);
237*cdf0e10cSrcweir     if(*ppCtx)
238*cdf0e10cSrcweir         *ppCtx=(*ppCtx)->pNext;
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir ErrorContext *ErrorContext::GetContext()
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     return EDcrData::GetData()->pFirstCtx;
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir ErrorHandler::ErrorHandler()
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     pImpl=new ErrHdl_Impl;
249*cdf0e10cSrcweir     EDcrData *pData=EDcrData::GetData();
250*cdf0e10cSrcweir     ErrorHandler *&pHdl=pData->pFirstHdl;
251*cdf0e10cSrcweir     pImpl->pNext=pHdl;
252*cdf0e10cSrcweir     pHdl=this;
253*cdf0e10cSrcweir     if(!pData->pDsp)
254*cdf0e10cSrcweir         RegisterDisplay(&aDspFunc);
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir ErrorHandler::~ErrorHandler()
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     ErrorHandler **ppHdl=&(EDcrData::GetData()->pFirstHdl);
260*cdf0e10cSrcweir     while(*ppHdl && *ppHdl!=this)
261*cdf0e10cSrcweir         ppHdl=&((*ppHdl)->pImpl->pNext);
262*cdf0e10cSrcweir     if(*ppHdl)
263*cdf0e10cSrcweir         *ppHdl=(*ppHdl)->pImpl->pNext;
264*cdf0e10cSrcweir 	delete pImpl;
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir void ErrorHandler::RegisterDisplay(WindowDisplayErrorFunc *aDsp)
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     EDcrData *pData=EDcrData::GetData();
270*cdf0e10cSrcweir     pData->bIsWindowDsp=sal_True;
271*cdf0e10cSrcweir     pData->pDsp = reinterpret_cast< DisplayFnPtr >(aDsp);
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir void ErrorHandler::RegisterDisplay(BasicDisplayErrorFunc *aDsp)
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     EDcrData *pData=EDcrData::GetData();
277*cdf0e10cSrcweir     pData->bIsWindowDsp=sal_False;
278*cdf0e10cSrcweir     pData->pDsp = reinterpret_cast< DisplayFnPtr >(aDsp);
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir sal_uInt16 ErrorHandler::HandleError_Impl(
282*cdf0e10cSrcweir     sal_uIntPtr lId, sal_uInt16 nFlags, sal_Bool bJustCreateString, String & rError)
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir /*  [Beschreibung]
286*cdf0e10cSrcweir 	Handelt einen Fehler ab. lId ist die FehlerId, nFlags sind die
287*cdf0e10cSrcweir 	ErrorFlags. Werden nFlags nicht abgegeben, so werden die in
288*cdf0e10cSrcweir 	der DynamicErrorInfo angegebenen Flags bzw. die aus der Resource
289*cdf0e10cSrcweir 	verwendet.
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 	Also:
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 	1. nFlags,
294*cdf0e10cSrcweir 	2. Resource Flags
295*cdf0e10cSrcweir 	3. Dynamic Flags
296*cdf0e10cSrcweir 	4. Default ERRCODE_BUTTON_OK, ERRCODE_MSG_ERROR
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	*/
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir     String aErr;
302*cdf0e10cSrcweir     String aAction;
303*cdf0e10cSrcweir     if(!lId || lId == ERRCODE_ABORT)
304*cdf0e10cSrcweir         return 0;
305*cdf0e10cSrcweir     EDcrData *pData=EDcrData::GetData();
306*cdf0e10cSrcweir     ErrorInfo *pInfo=ErrorInfo::GetErrorInfo(lId);
307*cdf0e10cSrcweir     ErrorContext *pCtx=ErrorContext::GetContext();
308*cdf0e10cSrcweir     if(pCtx)
309*cdf0e10cSrcweir         pCtx->GetString(pInfo->GetErrorCode(), aAction);
310*cdf0e10cSrcweir     Window *pParent=0;
311*cdf0e10cSrcweir     //Nimm den Parent aus dem Konext
312*cdf0e10cSrcweir     for(;pCtx;pCtx=pCtx->pNext)
313*cdf0e10cSrcweir         if(pCtx->GetParent())
314*cdf0e10cSrcweir         {
315*cdf0e10cSrcweir             pParent=pCtx->GetParent();
316*cdf0e10cSrcweir             break;
317*cdf0e10cSrcweir         }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     sal_Bool bWarning = ((lId & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK);
320*cdf0e10cSrcweir 	sal_uInt16 nErrFlags = ERRCODE_BUTTON_DEF_OK | ERRCODE_BUTTON_OK;
321*cdf0e10cSrcweir     if (bWarning)
322*cdf0e10cSrcweir         nErrFlags |= ERRCODE_MSG_WARNING;
323*cdf0e10cSrcweir     else
324*cdf0e10cSrcweir 		nErrFlags |= ERRCODE_MSG_ERROR;
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     DynamicErrorInfo* pDynPtr=PTR_CAST(DynamicErrorInfo,pInfo);
327*cdf0e10cSrcweir     if(pDynPtr)
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir 		sal_uInt16 nDynFlags = pDynPtr->GetDialogMask();
330*cdf0e10cSrcweir         if( nDynFlags )
331*cdf0e10cSrcweir 			nErrFlags = nDynFlags;
332*cdf0e10cSrcweir     }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     if(ErrHdl_Impl::CreateString(pData->pFirstHdl,pInfo,aErr,nErrFlags))
335*cdf0e10cSrcweir     {
336*cdf0e10cSrcweir 	if (bJustCreateString)
337*cdf0e10cSrcweir 	{
338*cdf0e10cSrcweir 	    rError = aErr;
339*cdf0e10cSrcweir 	    return 1;
340*cdf0e10cSrcweir 	}
341*cdf0e10cSrcweir 	else
342*cdf0e10cSrcweir 	{
343*cdf0e10cSrcweir 	    if(!pData->pDsp)
344*cdf0e10cSrcweir 	    {
345*cdf0e10cSrcweir 		ByteString aStr("Action: ");
346*cdf0e10cSrcweir 		aStr += ByteString( aAction, RTL_TEXTENCODING_ASCII_US );
347*cdf0e10cSrcweir 		aStr += ByteString("\nFehler: ");
348*cdf0e10cSrcweir 		aStr += ByteString( aErr, RTL_TEXTENCODING_ASCII_US );
349*cdf0e10cSrcweir 		DBG_ERROR( aStr.GetBuffer() );
350*cdf0e10cSrcweir 	    }
351*cdf0e10cSrcweir 	    else
352*cdf0e10cSrcweir 	    {
353*cdf0e10cSrcweir 		delete pInfo;
354*cdf0e10cSrcweir 		if(!pData->bIsWindowDsp)
355*cdf0e10cSrcweir 		{
356*cdf0e10cSrcweir 		    (*(BasicDisplayErrorFunc*)pData->pDsp)(aErr,aAction);
357*cdf0e10cSrcweir 		    return 0;
358*cdf0e10cSrcweir 		}
359*cdf0e10cSrcweir 		else
360*cdf0e10cSrcweir 		{
361*cdf0e10cSrcweir 		    if( nFlags != USHRT_MAX )
362*cdf0e10cSrcweir 			nErrFlags = nFlags;
363*cdf0e10cSrcweir 		    return (*(WindowDisplayErrorFunc*)pData->pDsp)(
364*cdf0e10cSrcweir 			pParent, nErrFlags, aErr, aAction);
365*cdf0e10cSrcweir 		}
366*cdf0e10cSrcweir 	    }
367*cdf0e10cSrcweir 	}
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir     DBG_ERROR("Error nicht behandelt");
370*cdf0e10cSrcweir     // Error 1 ist General Error im Sfx
371*cdf0e10cSrcweir     if(pInfo->GetErrorCode()!=1) {
372*cdf0e10cSrcweir         HandleError_Impl(1, USHRT_MAX, bJustCreateString, rError);
373*cdf0e10cSrcweir     }
374*cdf0e10cSrcweir     else {
375*cdf0e10cSrcweir         DBG_ERROR("Error 1 nicht gehandeled");
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir     delete pInfo;
378*cdf0e10cSrcweir     return 0;
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir // static
382*cdf0e10cSrcweir sal_Bool ErrorHandler::GetErrorString(sal_uIntPtr lId, String& rStr)
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir     return (sal_Bool)HandleError_Impl( lId, USHRT_MAX, sal_True, rStr );
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir sal_uInt16 ErrorHandler::HandleError(sal_uIntPtr lId, sal_uInt16 nFlags)
388*cdf0e10cSrcweir {
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir /*  [Beschreibung]
391*cdf0e10cSrcweir 	Handelt einen Fehler ab. lId ist die FehlerId, nFlags sind die
392*cdf0e10cSrcweir 	ErrorFlags. Werden nFlags nicht abgegeben, so werden die in
393*cdf0e10cSrcweir 	der DynamicErrorInfo angegebenen Flags bzw. die aus der Resource
394*cdf0e10cSrcweir 	verwendet.
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 	Also:
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 	1. nFlags,
399*cdf0e10cSrcweir 	2. Resource Flags
400*cdf0e10cSrcweir 	3. Dynamic Flags
401*cdf0e10cSrcweir 	4. Default ERRCODE_BUTTON_OK, ERRCODE_MSG_ERROR
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	*/
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     String aDummy;
407*cdf0e10cSrcweir     return HandleError_Impl( lId, nFlags, sal_False, aDummy );
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir sal_Bool ErrorHandler::ForwCreateString(const ErrorInfo* pInfo, String& rStr, sal_uInt16 &rFlags) const
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir     return ErrHdl_Impl::CreateString(this->pImpl->pNext, pInfo, rStr, rFlags);
413*cdf0e10cSrcweir }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir sal_Bool ErrHdl_Impl::CreateString( const ErrorHandler *pStart,
416*cdf0e10cSrcweir                                 const ErrorInfo* pInfo, String& pStr,
417*cdf0e10cSrcweir 							   sal_uInt16 &rFlags)
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir     for(const ErrorHandler *pHdl=pStart;pHdl;pHdl=pHdl->pImpl->pNext)
420*cdf0e10cSrcweir     {
421*cdf0e10cSrcweir         if(pHdl->CreateString( pInfo, pStr, rFlags))
422*cdf0e10cSrcweir             return sal_True;
423*cdf0e10cSrcweir     }
424*cdf0e10cSrcweir     return sal_False;
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir sal_Bool SimpleErrorHandler::CreateString(
428*cdf0e10cSrcweir     const ErrorInfo *pInfo, String &rStr, sal_uInt16 &) const
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir 	sal_uIntPtr nId = pInfo->GetErrorCode();
431*cdf0e10cSrcweir 	ByteString aStr;
432*cdf0e10cSrcweir     aStr="Id ";
433*cdf0e10cSrcweir     aStr+=ByteString::CreateFromInt32(nId);
434*cdf0e10cSrcweir     aStr+=" only handled by SimpleErrorHandler";
435*cdf0e10cSrcweir 	aStr+="\nErrorCode: ";
436*cdf0e10cSrcweir 	aStr+=ByteString::CreateFromInt32(nId & ((1L <<  ERRCODE_CLASS_SHIFT)  - 1 ));
437*cdf0e10cSrcweir 	aStr+="\nErrorClass: ";
438*cdf0e10cSrcweir 	aStr+=ByteString::CreateFromInt32((nId & ERRCODE_CLASS_MASK) >> ERRCODE_CLASS_SHIFT);
439*cdf0e10cSrcweir 	aStr+="\nErrorArea: ";
440*cdf0e10cSrcweir 	aStr+=ByteString::CreateFromInt32((nId & ERRCODE_ERROR_MASK &
441*cdf0e10cSrcweir 			~((1 << ERRCODE_AREA_SHIFT ) -1 ) ) >> ERRCODE_AREA_SHIFT);
442*cdf0e10cSrcweir     DynamicErrorInfo *pDyn=PTR_CAST(DynamicErrorInfo,pInfo);
443*cdf0e10cSrcweir     if(pDyn)
444*cdf0e10cSrcweir     {
445*cdf0e10cSrcweir 		aStr+="\nDId ";
446*cdf0e10cSrcweir 		aStr+=ByteString::CreateFromInt32((sal_uIntPtr)*pDyn);
447*cdf0e10cSrcweir 	}
448*cdf0e10cSrcweir     StandardErrorInfo *pStd=PTR_CAST(StandardErrorInfo,pInfo);
449*cdf0e10cSrcweir     if(pStd)
450*cdf0e10cSrcweir     {
451*cdf0e10cSrcweir 		aStr+="\nXId ";
452*cdf0e10cSrcweir 		aStr+=ByteString::CreateFromInt32(pStd->GetExtendedErrorCode());
453*cdf0e10cSrcweir 	}
454*cdf0e10cSrcweir 	rStr = String( aStr, RTL_TEXTENCODING_ASCII_US );
455*cdf0e10cSrcweir     return sal_True;
456*cdf0e10cSrcweir }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir SimpleErrorHandler::SimpleErrorHandler()
459*cdf0e10cSrcweir  : ErrorHandler()
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir }
462*cdf0e10cSrcweir 
463