xref: /AOO41X/main/svtools/source/misc/ehdl.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_svtools.hxx"
30*cdf0e10cSrcweir #include <vos/mutex.hxx>
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <tools/rcid.h>
33*cdf0e10cSrcweir #include <tools/wintypes.hxx>
34*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
35*cdf0e10cSrcweir #include <vcl/svapp.hxx>
36*cdf0e10cSrcweir #if defined(OS2)
37*cdf0e10cSrcweir #include <vcl/sound.hxx>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #ifndef GCC
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <svtools/ehdl.hxx>
44*cdf0e10cSrcweir #include <svtools/svtdata.hxx>
45*cdf0e10cSrcweir #include <svtools/svtools.hrc>
46*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //=========================================================================
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir static sal_uInt16 aWndFunc(
51*cdf0e10cSrcweir 	Window *pWin,            // Parent des Dialoges
52*cdf0e10cSrcweir 	sal_uInt16 nFlags,
53*cdf0e10cSrcweir 	const String &rErr,	     // Fehlertext
54*cdf0e10cSrcweir 	const String &rAction)   // Actiontext
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir /*  [Beschreibung]
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	Bringt eine Fehlerbox auf den Schirm. Je nach nFlags werden
59*cdf0e10cSrcweir 	Error/ Info usw. Boxen mit den gewuenschten Buttons angezeigt
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	Rueckgabewert ist der gedrueckte Button
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	*/
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	vos:: OGuard  aGuard( Application::GetSolarMutex() );
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	// aus den Flags die benoetigten WinBits ermitteln
70*cdf0e10cSrcweir 	WinBits eBits=0;
71*cdf0e10cSrcweir 	if ( (ERRCODE_BUTTON_CANCEL|ERRCODE_BUTTON_RETRY) == (nFlags & (ERRCODE_BUTTON_CANCEL|ERRCODE_BUTTON_RETRY)) )
72*cdf0e10cSrcweir 		eBits = WB_RETRY_CANCEL;
73*cdf0e10cSrcweir 	else if ( ERRCODE_BUTTON_OK_CANCEL == (nFlags & ERRCODE_BUTTON_OK_CANCEL) )
74*cdf0e10cSrcweir 		eBits = WB_OK_CANCEL;
75*cdf0e10cSrcweir 	else if ( ERRCODE_BUTTON_OK == (nFlags & ERRCODE_BUTTON_OK) )
76*cdf0e10cSrcweir 		eBits = WB_OK;
77*cdf0e10cSrcweir 	else if ( ERRCODE_BUTTON_YES_NO_CANCEL == (nFlags & ERRCODE_BUTTON_YES_NO_CANCEL) )
78*cdf0e10cSrcweir 		eBits = WB_YES_NO_CANCEL;
79*cdf0e10cSrcweir 	else if ( ERRCODE_BUTTON_YES_NO == (nFlags & ERRCODE_BUTTON_YES_NO) )
80*cdf0e10cSrcweir 		eBits = WB_YES_NO;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	switch(nFlags & 0x0f00)
83*cdf0e10cSrcweir 	{
84*cdf0e10cSrcweir 	  case ERRCODE_BUTTON_DEF_OK:
85*cdf0e10cSrcweir 			eBits |= WB_DEF_OK;
86*cdf0e10cSrcweir 			break;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	  case ERRCODE_BUTTON_DEF_CANCEL:
89*cdf0e10cSrcweir 			eBits |= WB_DEF_CANCEL;
90*cdf0e10cSrcweir 			break;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	  case ERRCODE_BUTTON_DEF_YES:
93*cdf0e10cSrcweir 			eBits |= WB_DEF_YES;
94*cdf0e10cSrcweir 			break;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	  case ERRCODE_BUTTON_DEF_NO:
97*cdf0e10cSrcweir 			eBits |= WB_DEF_NO;
98*cdf0e10cSrcweir 			break;
99*cdf0e10cSrcweir 	}
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	String aErr(SvtResId(STR_ERR_HDLMESS));
102*cdf0e10cSrcweir 	String aAction(rAction);
103*cdf0e10cSrcweir 	if ( aAction.Len() )
104*cdf0e10cSrcweir         aAction += String::CreateFromAscii( ":\n" );
105*cdf0e10cSrcweir     aErr.SearchAndReplace(String::CreateFromAscii( "$(ACTION)" ), aAction);
106*cdf0e10cSrcweir     aErr.SearchAndReplace(String::CreateFromAscii( "$(ERROR)" ), rErr);
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	MessBox* pBox;
109*cdf0e10cSrcweir 	switch ( nFlags & 0xf000 )
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		case ERRCODE_MSG_ERROR:
112*cdf0e10cSrcweir 			pBox = new ErrorBox(pWin, eBits, aErr);
113*cdf0e10cSrcweir 			break;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 		case ERRCODE_MSG_WARNING:
116*cdf0e10cSrcweir 			pBox = new WarningBox(pWin, eBits, aErr);
117*cdf0e10cSrcweir 			break;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 		case ERRCODE_MSG_INFO:
120*cdf0e10cSrcweir 			pBox = new InfoBox(pWin, aErr);
121*cdf0e10cSrcweir 			break;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 		case ERRCODE_MSG_QUERY:
124*cdf0e10cSrcweir 			pBox = new QueryBox(pWin, eBits, aErr);
125*cdf0e10cSrcweir 			break;
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 		default:
128*cdf0e10cSrcweir 		{
129*cdf0e10cSrcweir 			DBG_ERRORFILE( "no MessBox type");
130*cdf0e10cSrcweir 			pBox = NULL;
131*cdf0e10cSrcweir 			return ERRCODE_BUTTON_OK;
132*cdf0e10cSrcweir 		}
133*cdf0e10cSrcweir 	}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	sal_uInt16 nRet = RET_CANCEL;
136*cdf0e10cSrcweir 	switch ( pBox->Execute() )
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		case RET_OK:
139*cdf0e10cSrcweir 			nRet = ERRCODE_BUTTON_OK;
140*cdf0e10cSrcweir 			break;
141*cdf0e10cSrcweir 		case RET_CANCEL:
142*cdf0e10cSrcweir 			nRet = ERRCODE_BUTTON_CANCEL;
143*cdf0e10cSrcweir 			break;
144*cdf0e10cSrcweir 		case RET_RETRY:
145*cdf0e10cSrcweir 			nRet = ERRCODE_BUTTON_RETRY;
146*cdf0e10cSrcweir 			break;
147*cdf0e10cSrcweir 		case RET_YES:
148*cdf0e10cSrcweir 			nRet = ERRCODE_BUTTON_YES;
149*cdf0e10cSrcweir 			break;
150*cdf0e10cSrcweir 		case RET_NO:
151*cdf0e10cSrcweir 			nRet = ERRCODE_BUTTON_NO;
152*cdf0e10cSrcweir 			break;
153*cdf0e10cSrcweir 		default:
154*cdf0e10cSrcweir 			DBG_ERRORFILE( "Unknown MessBox return value" );
155*cdf0e10cSrcweir 			break;
156*cdf0e10cSrcweir 	}
157*cdf0e10cSrcweir 	delete pBox;
158*cdf0e10cSrcweir 	return nRet;
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir //-------------------------------------------------------------------------
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir SfxErrorHandler::SfxErrorHandler(sal_uInt16 nIdP, sal_uLong lStartP, sal_uLong lEndP, ResMgr *pMgrP) :
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     lStart(lStartP), lEnd(lEndP), nId(nIdP), pMgr(pMgrP), pFreeMgr( NULL )
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir 	RegisterDisplay(&aWndFunc);
169*cdf0e10cSrcweir     if( ! pMgr )
170*cdf0e10cSrcweir     {
171*cdf0e10cSrcweir         com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
172*cdf0e10cSrcweir         pFreeMgr = pMgr = ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(ofa), aLocale );
173*cdf0e10cSrcweir     }
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir //-------------------------------------------------------------------------
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir SfxErrorHandler::~SfxErrorHandler()
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir     if( pFreeMgr )
181*cdf0e10cSrcweir         delete pFreeMgr;
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir //-------------------------------------------------------------------------
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir sal_Bool SfxErrorHandler::CreateString(
187*cdf0e10cSrcweir 	const ErrorInfo *pErr, String &rStr, sal_uInt16& nFlags) const
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir /*  [Beschreibung]
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	Der Fehlerstring fuer die ErrorInfo pErr wird zusammengesetzt.
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	*/
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	sal_uLong nErrCode = pErr->GetErrorCode() & ERRCODE_ERROR_MASK;
197*cdf0e10cSrcweir 	if( nErrCode>=lEnd || nErrCode<=lStart )
198*cdf0e10cSrcweir 		return sal_False;
199*cdf0e10cSrcweir 	MessageInfo *pMsgInfo=PTR_CAST(MessageInfo,pErr);
200*cdf0e10cSrcweir 	if(pMsgInfo)
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		if(GetMessageString(nErrCode, rStr, nFlags))
203*cdf0e10cSrcweir 		{
204*cdf0e10cSrcweir 			for (xub_StrLen i = 0; i < rStr.Len();)
205*cdf0e10cSrcweir 			{
206*cdf0e10cSrcweir                 i = rStr.SearchAndReplace(String::CreateFromAscii( "$(ARG1)" ),
207*cdf0e10cSrcweir 										  pMsgInfo->GetMessageArg(), i);
208*cdf0e10cSrcweir 				if (i == STRING_NOTFOUND)
209*cdf0e10cSrcweir 					break;
210*cdf0e10cSrcweir 				i = i + pMsgInfo->GetMessageArg().Len();
211*cdf0e10cSrcweir 			}
212*cdf0e10cSrcweir 			return sal_True;
213*cdf0e10cSrcweir 		}
214*cdf0e10cSrcweir 	}
215*cdf0e10cSrcweir 	else if(GetErrorString(nErrCode, rStr, nFlags))
216*cdf0e10cSrcweir 	{
217*cdf0e10cSrcweir 		StringErrorInfo *pStringInfo=PTR_CAST(StringErrorInfo,pErr);
218*cdf0e10cSrcweir 		if(pStringInfo)
219*cdf0e10cSrcweir 			for (xub_StrLen i = 0; i < rStr.Len();)
220*cdf0e10cSrcweir 			{
221*cdf0e10cSrcweir                 i = rStr.SearchAndReplace(String::CreateFromAscii( "$(ARG1)" ),
222*cdf0e10cSrcweir 										  pStringInfo->GetErrorString(), i);
223*cdf0e10cSrcweir 				if (i == STRING_NOTFOUND)
224*cdf0e10cSrcweir 					break;
225*cdf0e10cSrcweir 				i = i + pStringInfo->GetErrorString().Len();
226*cdf0e10cSrcweir 			}
227*cdf0e10cSrcweir 		else
228*cdf0e10cSrcweir 		{
229*cdf0e10cSrcweir 			TwoStringErrorInfo * pTwoStringInfo = PTR_CAST(TwoStringErrorInfo,
230*cdf0e10cSrcweir 														   pErr);
231*cdf0e10cSrcweir 			if (pTwoStringInfo)
232*cdf0e10cSrcweir 				for (sal_uInt16 i = 0; i < rStr.Len();)
233*cdf0e10cSrcweir 				{
234*cdf0e10cSrcweir                     sal_uInt16 nArg1Pos = rStr.Search(String::CreateFromAscii( "$(ARG1)" ), i);
235*cdf0e10cSrcweir                     sal_uInt16 nArg2Pos = rStr.Search(String::CreateFromAscii( "$(ARG2)" ), i);
236*cdf0e10cSrcweir 					if (nArg1Pos < nArg2Pos)
237*cdf0e10cSrcweir 					{
238*cdf0e10cSrcweir 						rStr.Replace(nArg1Pos, 7, pTwoStringInfo->GetArg1());
239*cdf0e10cSrcweir 						i = nArg1Pos + pTwoStringInfo->GetArg1().Len();
240*cdf0e10cSrcweir 					}
241*cdf0e10cSrcweir 					else if (nArg2Pos < nArg1Pos)
242*cdf0e10cSrcweir 					{
243*cdf0e10cSrcweir 						rStr.Replace(nArg2Pos, 7, pTwoStringInfo->GetArg2());
244*cdf0e10cSrcweir 						i = nArg2Pos + pTwoStringInfo->GetArg2().Len();
245*cdf0e10cSrcweir 					}
246*cdf0e10cSrcweir 					else break;
247*cdf0e10cSrcweir 				}
248*cdf0e10cSrcweir 		}
249*cdf0e10cSrcweir 		return sal_True;
250*cdf0e10cSrcweir 	}
251*cdf0e10cSrcweir 	return sal_False;
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir //-------------------------------------------------------------------------
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir class ResString: public String
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir /*  [Beschreibung]
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 	Hilfsklasse zum Auslesen eines Strings und optionaler ExtraData aus
261*cdf0e10cSrcweir 	einer String Resource.
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 	*/
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	sal_uInt16 nFlags;
267*cdf0e10cSrcweir   public:
268*cdf0e10cSrcweir 	sal_uInt16 GetFlags() const {return nFlags;}
269*cdf0e10cSrcweir 	const String & GetString() const {return *this;}
270*cdf0e10cSrcweir 	ResString( ResId &rId);
271*cdf0e10cSrcweir };
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir //-------------------------------------------------------------------------
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir ResString::ResString(ResId & rId):
276*cdf0e10cSrcweir 	String(rId.SetAutoRelease(sal_False)),
277*cdf0e10cSrcweir 	nFlags(0)
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir     ResMgr * pResMgr = rId.GetResMgr();
280*cdf0e10cSrcweir 	 // String ctor temporarily sets global ResManager
281*cdf0e10cSrcweir 	if (pResMgr->GetRemainSize())
282*cdf0e10cSrcweir 		nFlags = sal_uInt16(pResMgr->ReadShort());
283*cdf0e10cSrcweir 	rId.SetAutoRelease(sal_True);
284*cdf0e10cSrcweir 	pResMgr->PopContext();
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir //-------------------------------------------------------------------------
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir struct ErrorResource_Impl : private Resource
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir /*  [Beschreibung]
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 	Hilfsklasse zum Zugriff auf String SubResourcen einer Resource
294*cdf0e10cSrcweir 	*/
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	ResId aResId;
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 	ErrorResource_Impl(ResId& rErrIdP, sal_uInt16 nId)
301*cdf0e10cSrcweir         : Resource(rErrIdP),aResId(nId,*rErrIdP.GetResMgr()){}
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	~ErrorResource_Impl() { FreeResource(); }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	operator ResString(){ return ResString( aResId ); }
306*cdf0e10cSrcweir 	operator sal_Bool(){return IsAvailableRes(aResId.SetRT(RSC_STRING));}
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir };
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir sal_Bool SfxErrorHandler::GetClassString(sal_uLong lClassId, String &rStr) const
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir /*  [Beschreibung]
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	Erzeugt den String fuer die Klasse des Fehlers. Wird immer aus der
316*cdf0e10cSrcweir 	Resource des Sfx gelesen
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 	*/
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
322*cdf0e10cSrcweir 	com::sun::star::lang::Locale aLocale( Application::GetSettings().GetUILocale() );
323*cdf0e10cSrcweir 	ResMgr* pResMgr = ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(ofa), aLocale );
324*cdf0e10cSrcweir 	if( pResMgr )
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir 		ResId aId(RID_ERRHDL, *pResMgr );
327*cdf0e10cSrcweir 		ErrorResource_Impl aEr(aId, (sal_uInt16)lClassId);
328*cdf0e10cSrcweir 		if(aEr)
329*cdf0e10cSrcweir 		{
330*cdf0e10cSrcweir 			rStr=((ResString)aEr).GetString();
331*cdf0e10cSrcweir 			bRet = sal_True;
332*cdf0e10cSrcweir 		}
333*cdf0e10cSrcweir 	}
334*cdf0e10cSrcweir     delete pResMgr;
335*cdf0e10cSrcweir 	return bRet;
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir //-------------------------------------------------------------------------
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir sal_Bool SfxErrorHandler::GetMessageString(
341*cdf0e10cSrcweir 	sal_uLong lErrId, String &rStr, sal_uInt16 &nFlags) const
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir /*  [Beschreibung]
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	Erzeugt den String fuer die Ausgabe in einer MessageBox
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 	*/
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
351*cdf0e10cSrcweir     ResId *pResId= new ResId(nId, *pMgr);
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 	ErrorResource_Impl aEr(*pResId, (sal_uInt16)lErrId);
354*cdf0e10cSrcweir 	if(aEr)
355*cdf0e10cSrcweir 	{
356*cdf0e10cSrcweir 		ResString aErrorString(aEr);
357*cdf0e10cSrcweir 		sal_uInt16 nResFlags = aErrorString.GetFlags();
358*cdf0e10cSrcweir 		if( nResFlags )
359*cdf0e10cSrcweir 			nFlags=aErrorString.GetFlags();
360*cdf0e10cSrcweir 		rStr = aErrorString.GetString();
361*cdf0e10cSrcweir 		bRet = sal_True;
362*cdf0e10cSrcweir 	}
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 	delete pResId;
365*cdf0e10cSrcweir 	return bRet;
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir //-------------------------------------------------------------------------
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir sal_Bool SfxErrorHandler::GetErrorString(
371*cdf0e10cSrcweir 	sal_uLong lErrId, String &rStr, sal_uInt16 &nFlags) const
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir /*  [Beschreibung]
374*cdf0e10cSrcweir 	Erzeugt den Fehlerstring fuer den eigentlichen Fehler ohne
375*cdf0e10cSrcweir 	dessen Klasse
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	*/
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir 	vos:: OGuard  aGuard( Application::GetSolarMutex() );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
383*cdf0e10cSrcweir 	rStr=String(SvtResId(RID_ERRHDL_CLASS));
384*cdf0e10cSrcweir     ResId aResId(nId, *pMgr);
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir 		ErrorResource_Impl aEr(aResId, (sal_uInt16)lErrId);
388*cdf0e10cSrcweir 		if(aEr)
389*cdf0e10cSrcweir 		{
390*cdf0e10cSrcweir 			ResString aErrorString(aEr);
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 			sal_uInt16 nResFlags = aErrorString.GetFlags();
393*cdf0e10cSrcweir 			if ( nResFlags )
394*cdf0e10cSrcweir 				nFlags = nResFlags;
395*cdf0e10cSrcweir             rStr.SearchAndReplace(
396*cdf0e10cSrcweir                 String::CreateFromAscii("$(ERROR)"), aErrorString.GetString());
397*cdf0e10cSrcweir 			bRet = sal_True;
398*cdf0e10cSrcweir 		}
399*cdf0e10cSrcweir 		else
400*cdf0e10cSrcweir 			bRet = sal_False;
401*cdf0e10cSrcweir 	}
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 	if( bRet )
404*cdf0e10cSrcweir 	{
405*cdf0e10cSrcweir 		String aErrStr;
406*cdf0e10cSrcweir 		GetClassString(lErrId & ERRCODE_CLASS_MASK,
407*cdf0e10cSrcweir 					   aErrStr);
408*cdf0e10cSrcweir         if(aErrStr.Len())
409*cdf0e10cSrcweir             aErrStr+=String::CreateFromAscii( ".\n" );
410*cdf0e10cSrcweir         rStr.SearchAndReplace(String::CreateFromAscii( "$(CLASS)" ),aErrStr);
411*cdf0e10cSrcweir 	}
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	return bRet;
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir //-------------------------------------------------------------------------
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir SfxErrorContext::SfxErrorContext(
419*cdf0e10cSrcweir 	sal_uInt16 nCtxIdP, Window *pWindow, sal_uInt16 nResIdP, ResMgr *pMgrP)
420*cdf0e10cSrcweir :   ErrorContext(pWindow), nCtxId(nCtxIdP), nResId(nResIdP), pMgr(pMgrP)
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir 	if( nResId==USHRT_MAX )
423*cdf0e10cSrcweir 		nResId=RID_ERRCTX;
424*cdf0e10cSrcweir }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir //-------------------------------------------------------------------------
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir SfxErrorContext::SfxErrorContext(
429*cdf0e10cSrcweir 	sal_uInt16 nCtxIdP, const String &aArg1P, Window *pWindow,
430*cdf0e10cSrcweir 	sal_uInt16 nResIdP, ResMgr *pMgrP)
431*cdf0e10cSrcweir :   ErrorContext(pWindow), nCtxId(nCtxIdP), nResId(nResIdP), pMgr(pMgrP),
432*cdf0e10cSrcweir 	aArg1(aArg1P)
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir 	if( nResId==USHRT_MAX )
435*cdf0e10cSrcweir 		nResId=RID_ERRCTX;
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir //-------------------------------------------------------------------------
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir sal_Bool SfxErrorContext::GetString(sal_uLong nErrId, String &rStr)
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir /*  [Beschreibung]
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 	Baut die Beschreibung eines ErrorContextes auf
445*cdf0e10cSrcweir 	*/
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir     bool bRet = false;
449*cdf0e10cSrcweir     ResMgr* pFreeMgr = NULL;
450*cdf0e10cSrcweir     if( ! pMgr )
451*cdf0e10cSrcweir     {
452*cdf0e10cSrcweir         com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
453*cdf0e10cSrcweir         pFreeMgr = pMgr = ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(ofa), aLocale );
454*cdf0e10cSrcweir     }
455*cdf0e10cSrcweir     if( pMgr )
456*cdf0e10cSrcweir     {
457*cdf0e10cSrcweir         vos:: OGuard  aGuard( Application::GetSolarMutex() );
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir         ResId aResId( nResId, *pMgr );
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir         ErrorResource_Impl aTestEr( aResId, nCtxId );
462*cdf0e10cSrcweir         if ( aTestEr )
463*cdf0e10cSrcweir         {
464*cdf0e10cSrcweir             rStr = ( (ResString)aTestEr ).GetString();
465*cdf0e10cSrcweir             rStr.SearchAndReplace( String::CreateFromAscii( "$(ARG1)" ), aArg1 );
466*cdf0e10cSrcweir             bRet = true;
467*cdf0e10cSrcweir         }
468*cdf0e10cSrcweir         else
469*cdf0e10cSrcweir         {
470*cdf0e10cSrcweir             DBG_ERRORFILE( "ErrorContext cannot find the resource" );
471*cdf0e10cSrcweir             bRet = false;
472*cdf0e10cSrcweir         }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir         if ( bRet )
475*cdf0e10cSrcweir         {
476*cdf0e10cSrcweir             sal_uInt16 nId = ( nErrId & ERRCODE_WARNING_MASK ) ? ERRCTX_WARNING : ERRCTX_ERROR;
477*cdf0e10cSrcweir             ResId aSfxResId( RID_ERRCTX, *pMgr );
478*cdf0e10cSrcweir             ErrorResource_Impl aEr( aSfxResId, nId );
479*cdf0e10cSrcweir             rStr.SearchAndReplace( String::CreateFromAscii( "$(ERR)" ), ( (ResString)aEr ).GetString() );
480*cdf0e10cSrcweir         }
481*cdf0e10cSrcweir     }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir     if( pFreeMgr )
484*cdf0e10cSrcweir     {
485*cdf0e10cSrcweir         delete pFreeMgr;
486*cdf0e10cSrcweir         pMgr = NULL;
487*cdf0e10cSrcweir     }
488*cdf0e10cSrcweir     return bRet;
489*cdf0e10cSrcweir }
490