xref: /AOO41X/main/sw/source/ui/utlui/numfmtlb.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_sw.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <hintids.hxx>
33*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
35*cdf0e10cSrcweir #include <editeng/unolingu.hxx>
36*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
37*cdf0e10cSrcweir #include <i18npool/lang.h>
38*cdf0e10cSrcweir #ifndef _ZFORMAT_HXX //autogen
39*cdf0e10cSrcweir #define _ZFORLIST_DECLARE_TABLE
40*cdf0e10cSrcweir #include <svl/zformat.hxx>
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #include <svl/eitem.hxx>
43*cdf0e10cSrcweir #include <svx/svxids.hrc>
44*cdf0e10cSrcweir #include <svx/numinf.hxx>
45*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
46*cdf0e10cSrcweir #include <svx/flagsdef.hxx>
47*cdf0e10cSrcweir #include <svl/itemset.hxx>
48*cdf0e10cSrcweir #include <docsh.hxx>
49*cdf0e10cSrcweir #include <swtypes.hxx>
50*cdf0e10cSrcweir #include <swmodule.hxx>
51*cdf0e10cSrcweir #include <view.hxx>
52*cdf0e10cSrcweir #include <wrtsh.hxx>
53*cdf0e10cSrcweir #include <numfmtlb.hxx>
54*cdf0e10cSrcweir #include <utlui.hrc>
55*cdf0e10cSrcweir #include "swabstdlg.hxx"
56*cdf0e10cSrcweir #include "dialog.hrc"
57*cdf0e10cSrcweir #include <unomid.h>
58*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
61*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir /*--------------------------------------------------------------------
67*cdf0e10cSrcweir 	Beschreibung:
68*cdf0e10cSrcweir 					nFormatType: Formate dieses Typs anzeigen
69*cdf0e10cSrcweir 					nDefFmt:     Dieses Format selektieren und ggf vorher
70*cdf0e10cSrcweir 								 einfuegen
71*cdf0e10cSrcweir  --------------------------------------------------------------------*/
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir NumFormatListBox::NumFormatListBox( Window* pWin, const ResId& rResId,
74*cdf0e10cSrcweir 									short nFormatType, sal_uLong nDefFmt,
75*cdf0e10cSrcweir 									sal_Bool bUsrFmts ) :
76*cdf0e10cSrcweir 	ListBox				( pWin, rResId ),
77*cdf0e10cSrcweir 	nCurrFormatType 	(-1),
78*cdf0e10cSrcweir 	nStdEntry			(0),
79*cdf0e10cSrcweir 	bOneArea			(sal_False),
80*cdf0e10cSrcweir 	nDefFormat			(nDefFmt),
81*cdf0e10cSrcweir 	pVw					(0),
82*cdf0e10cSrcweir     pOwnFormatter       (0),
83*cdf0e10cSrcweir     bShowLanguageControl(sal_False),
84*cdf0e10cSrcweir     bUseAutomaticLanguage(sal_True)
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	Init(nFormatType, bUsrFmts);
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir /*--------------------------------------------------------------------
90*cdf0e10cSrcweir 	Beschreibung:
91*cdf0e10cSrcweir  --------------------------------------------------------------------*/
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir NumFormatListBox::NumFormatListBox( Window* pWin, SwView* pView,
94*cdf0e10cSrcweir 									const ResId& rResId, short nFormatType,
95*cdf0e10cSrcweir 									sal_uLong nDefFmt, sal_Bool bUsrFmts ) :
96*cdf0e10cSrcweir 	ListBox				( pWin, rResId ),
97*cdf0e10cSrcweir 	nCurrFormatType 	(-1),
98*cdf0e10cSrcweir 	nStdEntry			(0),
99*cdf0e10cSrcweir 	bOneArea			(sal_False),
100*cdf0e10cSrcweir 	nDefFormat			(nDefFmt),
101*cdf0e10cSrcweir 	pVw					(pView),
102*cdf0e10cSrcweir     pOwnFormatter       (0),
103*cdf0e10cSrcweir     bShowLanguageControl(sal_False),
104*cdf0e10cSrcweir     bUseAutomaticLanguage(sal_True)
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	Init(nFormatType, bUsrFmts);
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir /* -----------------15.06.98 11:29-------------------
110*cdf0e10cSrcweir  *
111*cdf0e10cSrcweir  * --------------------------------------------------*/
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir void NumFormatListBox::Init(short nFormatType, sal_Bool bUsrFmts)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	SwView *pView = GetView();
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	if (pView)
118*cdf0e10cSrcweir 		eCurLanguage = pView->GetWrtShell().GetCurLang();
119*cdf0e10cSrcweir 	else
120*cdf0e10cSrcweir 		eCurLanguage = SvxLocaleToLanguage( SvtSysLocale().GetLocaleData().getLocale() );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	if (bUsrFmts == sal_False)
123*cdf0e10cSrcweir    	{
124*cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
125*cdf0e10cSrcweir 		pOwnFormatter = new SvNumberFormatter(xMSF, eCurLanguage);
126*cdf0e10cSrcweir 	}
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 	SetFormatType(nFormatType);
129*cdf0e10cSrcweir 	SetDefFormat(nDefFormat);
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	SetSelectHdl(LINK(this, NumFormatListBox, SelectHdl));
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir /*--------------------------------------------------------------------
135*cdf0e10cSrcweir 	Beschreibung:
136*cdf0e10cSrcweir  --------------------------------------------------------------------*/
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir NumFormatListBox::~NumFormatListBox()
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir 	if (pOwnFormatter)
141*cdf0e10cSrcweir 		delete pOwnFormatter;
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir /*--------------------------------------------------------------------
144*cdf0e10cSrcweir 	Beschreibung:
145*cdf0e10cSrcweir  --------------------------------------------------------------------*/
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir SwView* NumFormatListBox::GetView()
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	if( pVw )
150*cdf0e10cSrcweir 		return pVw;
151*cdf0e10cSrcweir 	return ::GetActiveView();
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir /*--------------------------------------------------------------------
155*cdf0e10cSrcweir 	Beschreibung:
156*cdf0e10cSrcweir  --------------------------------------------------------------------*/
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir void NumFormatListBox::SetFormatType(const short nFormatType)
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir 	if (nCurrFormatType == -1 ||
161*cdf0e10cSrcweir 		(nCurrFormatType & nFormatType) == 0)	// Es gibt Mischformate, wie z.B. DateTime
162*cdf0e10cSrcweir 	{
163*cdf0e10cSrcweir 		SvNumberFormatter* pFormatter;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 		if( pOwnFormatter )
166*cdf0e10cSrcweir 			pFormatter = pOwnFormatter;
167*cdf0e10cSrcweir 		else
168*cdf0e10cSrcweir 		{
169*cdf0e10cSrcweir 			SwView *pView = GetView();
170*cdf0e10cSrcweir             DBG_ASSERT(pView, "no view found");
171*cdf0e10cSrcweir             if(!pView)
172*cdf0e10cSrcweir                 return;
173*cdf0e10cSrcweir 			SwWrtShell &rSh = pView->GetWrtShell();
174*cdf0e10cSrcweir 			pFormatter = rSh.GetNumberFormatter();
175*cdf0e10cSrcweir 		}
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 		Clear();	// Alle Eintraege in der Listbox entfernen
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 		NfIndexTableOffset eOffsetStart = NF_NUMBER_START;
180*cdf0e10cSrcweir 		NfIndexTableOffset eOffsetEnd = NF_NUMBER_START;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 		switch( nFormatType )
183*cdf0e10cSrcweir 		{
184*cdf0e10cSrcweir 		case NUMBERFORMAT_NUMBER:
185*cdf0e10cSrcweir 			eOffsetStart=NF_NUMBER_START;
186*cdf0e10cSrcweir 			eOffsetEnd=NF_NUMBER_END;
187*cdf0e10cSrcweir 			break;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 		case NUMBERFORMAT_PERCENT:
190*cdf0e10cSrcweir 			eOffsetStart=NF_PERCENT_START;
191*cdf0e10cSrcweir 			eOffsetEnd=NF_PERCENT_END;
192*cdf0e10cSrcweir 			break;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 		case NUMBERFORMAT_CURRENCY:
195*cdf0e10cSrcweir 			eOffsetStart=NF_CURRENCY_START;
196*cdf0e10cSrcweir 			eOffsetEnd=NF_CURRENCY_END;
197*cdf0e10cSrcweir 			break;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 		case NUMBERFORMAT_DATETIME:
200*cdf0e10cSrcweir 			eOffsetStart=NF_DATE_START;
201*cdf0e10cSrcweir 			eOffsetEnd=NF_TIME_END;
202*cdf0e10cSrcweir 			break;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		case NUMBERFORMAT_DATE:
205*cdf0e10cSrcweir 			eOffsetStart=NF_DATE_START;
206*cdf0e10cSrcweir 			eOffsetEnd=NF_DATE_END;
207*cdf0e10cSrcweir 			break;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 		case NUMBERFORMAT_TIME:
210*cdf0e10cSrcweir 			eOffsetStart=NF_TIME_START;
211*cdf0e10cSrcweir 			eOffsetEnd=NF_TIME_END;
212*cdf0e10cSrcweir 			break;
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 		case NUMBERFORMAT_SCIENTIFIC:
215*cdf0e10cSrcweir 			eOffsetStart=NF_SCIENTIFIC_START;
216*cdf0e10cSrcweir 			eOffsetEnd=NF_SCIENTIFIC_END;
217*cdf0e10cSrcweir 			break;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 		case NUMBERFORMAT_FRACTION:
220*cdf0e10cSrcweir 			eOffsetStart=NF_FRACTION_START;
221*cdf0e10cSrcweir 			eOffsetEnd=NF_FRACTION_END;
222*cdf0e10cSrcweir 			break;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 		case NUMBERFORMAT_LOGICAL:
225*cdf0e10cSrcweir 			eOffsetStart=NF_BOOLEAN;
226*cdf0e10cSrcweir 			eOffsetEnd=NF_BOOLEAN;
227*cdf0e10cSrcweir 			break;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 		case NUMBERFORMAT_TEXT:
230*cdf0e10cSrcweir 			eOffsetStart=NF_TEXT;
231*cdf0e10cSrcweir 			eOffsetEnd=NF_TEXT;
232*cdf0e10cSrcweir 			break;
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 		case NUMBERFORMAT_ALL:
235*cdf0e10cSrcweir 			eOffsetStart=NF_NUMERIC_START;
236*cdf0e10cSrcweir 			eOffsetEnd = NfIndexTableOffset( NF_INDEX_TABLE_ENTRIES - 1 );
237*cdf0e10cSrcweir 			break;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 		default:
240*cdf0e10cSrcweir 			DBG_ERROR("what a format?");
241*cdf0e10cSrcweir 			break;
242*cdf0e10cSrcweir 		}
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 		const SvNumberformat* pFmt;
245*cdf0e10cSrcweir 		sal_uInt16 nPos, i = 0;
246*cdf0e10cSrcweir 		sal_uLong  nFormat;
247*cdf0e10cSrcweir 		Color* pCol;
248*cdf0e10cSrcweir         double fVal = GetDefValue( nFormatType );
249*cdf0e10cSrcweir 		String sValue;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 		sal_uLong nSysNumFmt = pFormatter->GetFormatIndex(
252*cdf0e10cSrcweir 										NF_NUMBER_SYSTEM, eCurLanguage );
253*cdf0e10cSrcweir 		sal_uLong nSysShortDateFmt = pFormatter->GetFormatIndex(
254*cdf0e10cSrcweir 										NF_DATE_SYSTEM_SHORT, eCurLanguage );
255*cdf0e10cSrcweir 		sal_uLong nSysLongDateFmt = pFormatter->GetFormatIndex(
256*cdf0e10cSrcweir 										NF_DATE_SYSTEM_LONG, eCurLanguage );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 		for( long nIndex = eOffsetStart; nIndex <= eOffsetEnd; ++nIndex )
259*cdf0e10cSrcweir 		{
260*cdf0e10cSrcweir 			nFormat = pFormatter->GetFormatIndex(
261*cdf0e10cSrcweir 							(NfIndexTableOffset)nIndex, eCurLanguage );
262*cdf0e10cSrcweir 			pFmt = pFormatter->GetEntry( nFormat );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 			if( nFormat == pFormatter->GetFormatIndex( NF_NUMBER_STANDARD,
265*cdf0e10cSrcweir 														eCurLanguage )
266*cdf0e10cSrcweir 				|| ((SvNumberformat*)pFmt)->GetOutputString( fVal, sValue, &pCol )
267*cdf0e10cSrcweir 				|| nFormatType == NUMBERFORMAT_UNDEFINED )
268*cdf0e10cSrcweir 					sValue = pFmt->GetFormatstring();
269*cdf0e10cSrcweir 			else if( nFormatType == NUMBERFORMAT_TEXT )
270*cdf0e10cSrcweir 			{
271*cdf0e10cSrcweir 				String sTxt(C2S("\"ABC\""));
272*cdf0e10cSrcweir 				pFormatter->GetOutputString( sTxt, nFormat, sValue, &pCol);
273*cdf0e10cSrcweir 			}
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 			if (nFormat != nSysNumFmt		&&
276*cdf0e10cSrcweir 				nFormat != nSysShortDateFmt	&&
277*cdf0e10cSrcweir 				nFormat != nSysLongDateFmt)
278*cdf0e10cSrcweir 			{
279*cdf0e10cSrcweir 				nPos = InsertEntry( sValue );
280*cdf0e10cSrcweir 				SetEntryData( nPos, (void*)nFormat );
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 				if( nFormat == pFormatter->GetStandardFormat(
283*cdf0e10cSrcweir 										nFormatType, eCurLanguage ) )
284*cdf0e10cSrcweir 					nStdEntry = i;
285*cdf0e10cSrcweir 				++i;
286*cdf0e10cSrcweir 			}
287*cdf0e10cSrcweir 		}
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 		if (!pOwnFormatter)
290*cdf0e10cSrcweir 		{
291*cdf0e10cSrcweir 			nPos = InsertEntry(SW_RESSTR( STR_DEFINE_NUMBERFORMAT ));
292*cdf0e10cSrcweir 			SetEntryData( nPos, NULL );
293*cdf0e10cSrcweir 		}
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 		SelectEntryPos( nStdEntry );
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 		nCurrFormatType = nFormatType;
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir /*--------------------------------------------------------------------
302*cdf0e10cSrcweir 	Beschreibung:
303*cdf0e10cSrcweir  --------------------------------------------------------------------*/
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir void NumFormatListBox::SetDefFormat(const sal_uLong nDefFmt)
306*cdf0e10cSrcweir {
307*cdf0e10cSrcweir 	if (nDefFmt == ULONG_MAX)
308*cdf0e10cSrcweir 	{
309*cdf0e10cSrcweir 		nDefFormat = nDefFmt;
310*cdf0e10cSrcweir 		return;
311*cdf0e10cSrcweir 	}
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     SvNumberFormatter* pFormatter;
314*cdf0e10cSrcweir     if (pOwnFormatter)
315*cdf0e10cSrcweir         pFormatter = pOwnFormatter;
316*cdf0e10cSrcweir     else
317*cdf0e10cSrcweir     {
318*cdf0e10cSrcweir         SwView *pView = GetView();
319*cdf0e10cSrcweir         DBG_ASSERT(pView, "no view found");
320*cdf0e10cSrcweir         if(!pView)
321*cdf0e10cSrcweir             return;
322*cdf0e10cSrcweir         SwWrtShell &rSh = pView->GetWrtShell();
323*cdf0e10cSrcweir         pFormatter = rSh.GetNumberFormatter();
324*cdf0e10cSrcweir     }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     short nType = pFormatter->GetType(nDefFmt);
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     SetFormatType(nType);
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     sal_uLong nFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nDefFmt, eCurLanguage);
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < GetEntryCount(); i++)
333*cdf0e10cSrcweir     {
334*cdf0e10cSrcweir         if (nFormat == (sal_uLong)GetEntryData(i))
335*cdf0e10cSrcweir         {
336*cdf0e10cSrcweir             SelectEntryPos(i);
337*cdf0e10cSrcweir             nStdEntry = i;
338*cdf0e10cSrcweir             nDefFormat = GetFormat();
339*cdf0e10cSrcweir             return;
340*cdf0e10cSrcweir         }
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     // Kein Eintrag gefunden:
344*cdf0e10cSrcweir     double fValue = GetDefValue(nType);
345*cdf0e10cSrcweir     String sValue;
346*cdf0e10cSrcweir     Color* pCol = 0;
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir     if (nType == NUMBERFORMAT_TEXT)
349*cdf0e10cSrcweir     {
350*cdf0e10cSrcweir         String sTxt(C2S("\"ABC\""));
351*cdf0e10cSrcweir         pFormatter->GetOutputString(sTxt, nDefFmt, sValue, &pCol);
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir     else
354*cdf0e10cSrcweir         pFormatter->GetOutputString(fValue, nDefFmt, sValue, &pCol);
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir     sal_uInt16 nPos = 0;
357*cdf0e10cSrcweir     while ((sal_uLong)GetEntryData(nPos) == ULONG_MAX)
358*cdf0e10cSrcweir         nPos++;
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir //
361*cdf0e10cSrcweir     sal_uLong nSysNumFmt = pFormatter->GetFormatIndex( NF_NUMBER_SYSTEM, eCurLanguage);
362*cdf0e10cSrcweir     sal_uLong nSysShortDateFmt = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_SHORT, eCurLanguage);
363*cdf0e10cSrcweir     sal_uLong nSysLongDateFmt = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_LONG, eCurLanguage);
364*cdf0e10cSrcweir     sal_Bool bSysLang = sal_False;
365*cdf0e10cSrcweir     if( eCurLanguage == GetAppLanguage() )
366*cdf0e10cSrcweir         bSysLang = sal_True;
367*cdf0e10cSrcweir     sal_uLong nNumFormatForLanguage = pFormatter->GetFormatForLanguageIfBuiltIn(nSysNumFmt, LANGUAGE_SYSTEM );
368*cdf0e10cSrcweir     sal_uLong nShortDateFormatForLanguage = pFormatter->GetFormatForLanguageIfBuiltIn(nSysShortDateFmt, LANGUAGE_SYSTEM );
369*cdf0e10cSrcweir     sal_uLong nLongDateFormatForLanguage = pFormatter->GetFormatForLanguageIfBuiltIn(nSysLongDateFmt, LANGUAGE_SYSTEM );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir     if (
372*cdf0e10cSrcweir          nDefFmt == nSysNumFmt ||
373*cdf0e10cSrcweir          nDefFmt == nSysShortDateFmt ||
374*cdf0e10cSrcweir          nDefFmt == nSysLongDateFmt ||
375*cdf0e10cSrcweir          (
376*cdf0e10cSrcweir            bSysLang &&
377*cdf0e10cSrcweir            (
378*cdf0e10cSrcweir              nDefFmt == nNumFormatForLanguage ||
379*cdf0e10cSrcweir              nDefFmt == nShortDateFormatForLanguage ||
380*cdf0e10cSrcweir              nDefFmt == nLongDateFormatForLanguage
381*cdf0e10cSrcweir            )
382*cdf0e10cSrcweir          )
383*cdf0e10cSrcweir        )
384*cdf0e10cSrcweir     {
385*cdf0e10cSrcweir         sValue += String(SW_RES(RID_STR_SYSTEM));
386*cdf0e10cSrcweir     }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     nPos = InsertEntry(sValue, nPos);   // Als ersten numerischen Eintrag einfuegen
389*cdf0e10cSrcweir     SetEntryData(nPos, (void*)nDefFmt);
390*cdf0e10cSrcweir     SelectEntryPos(nPos);
391*cdf0e10cSrcweir 	nDefFormat = GetFormat();
392*cdf0e10cSrcweir }
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir /*--------------------------------------------------------------------
395*cdf0e10cSrcweir 	Beschreibung:
396*cdf0e10cSrcweir  --------------------------------------------------------------------*/
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir sal_uLong NumFormatListBox::GetFormat() const
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir 	sal_uInt16 nPos = GetSelectEntryPos();
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 	return (sal_uLong)GetEntryData(nPos);
403*cdf0e10cSrcweir }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir /*--------------------------------------------------------------------
406*cdf0e10cSrcweir 	Beschreibung:
407*cdf0e10cSrcweir  --------------------------------------------------------------------*/
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir IMPL_LINK( NumFormatListBox, SelectHdl, ListBox *, pBox )
410*cdf0e10cSrcweir {
411*cdf0e10cSrcweir 	sal_uInt16 nPos = pBox->GetSelectEntryPos();
412*cdf0e10cSrcweir 	String sDefine(SW_RES( STR_DEFINE_NUMBERFORMAT ));
413*cdf0e10cSrcweir 	SwView *pView = GetView();
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	if( pView && nPos == pBox->GetEntryCount() - 1 &&
416*cdf0e10cSrcweir 		pBox->GetEntry( nPos ) == sDefine )
417*cdf0e10cSrcweir 	{
418*cdf0e10cSrcweir 		SwWrtShell &rSh = pView->GetWrtShell();
419*cdf0e10cSrcweir 		SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 		SfxItemSet aCoreSet( rSh.GetAttrPool(),
422*cdf0e10cSrcweir 			SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_VALUE,
423*cdf0e10cSrcweir 			SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
424*cdf0e10cSrcweir 			SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
425*cdf0e10cSrcweir 			SID_ATTR_NUMBERFORMAT_NOLANGUAGE, SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
426*cdf0e10cSrcweir             SID_ATTR_NUMBERFORMAT_ADD_AUTO, SID_ATTR_NUMBERFORMAT_ADD_AUTO,
427*cdf0e10cSrcweir 			0 );
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir         double fValue = GetDefValue( nCurrFormatType);
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir 		sal_uLong nFormat = pFormatter->GetStandardFormat( nCurrFormatType, eCurLanguage);
432*cdf0e10cSrcweir 		aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, nFormat ));
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 		aCoreSet.Put( SvxNumberInfoItem( pFormatter, fValue,
435*cdf0e10cSrcweir 											SID_ATTR_NUMBERFORMAT_INFO ) );
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir 		if( (NUMBERFORMAT_DATE | NUMBERFORMAT_TIME) & nCurrFormatType )
438*cdf0e10cSrcweir 			aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, bOneArea));
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir         aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_NOLANGUAGE, !bShowLanguageControl));
441*cdf0e10cSrcweir         aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO, bUseAutomaticLanguage));
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
444*cdf0e10cSrcweir         DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir         SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aCoreSet,
447*cdf0e10cSrcweir 			GetView()->GetViewFrame()->GetFrame().GetFrameInterface(),
448*cdf0e10cSrcweir 			RC_DLG_SWNUMFMTDLG );
449*cdf0e10cSrcweir         DBG_ASSERT(pDlg, "Dialogdiet fail!");
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 		if (RET_OK == pDlg->Execute())
452*cdf0e10cSrcweir 		{
453*cdf0e10cSrcweir 			const SfxPoolItem* pItem = pView->GetDocShell()->
454*cdf0e10cSrcweir 							GetItem( SID_ATTR_NUMBERFORMAT_INFO );
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir 			if( pItem && 0 != ((SvxNumberInfoItem*)pItem)->GetDelCount() )
457*cdf0e10cSrcweir 			{
458*cdf0e10cSrcweir 				const sal_uInt32* pDelArr = ((SvxNumberInfoItem*)pItem)->GetDelArray();
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 				for ( sal_uInt16 i = 0; i < ((SvxNumberInfoItem*)pItem)->GetDelCount(); i++ )
461*cdf0e10cSrcweir 					pFormatter->DeleteEntry( pDelArr[i] );
462*cdf0e10cSrcweir 			}
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir             const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
465*cdf0e10cSrcweir             if( SFX_ITEM_SET == pOutSet->GetItemState(
466*cdf0e10cSrcweir 				SID_ATTR_NUMBERFORMAT_VALUE, sal_False, &pItem ))
467*cdf0e10cSrcweir 			{
468*cdf0e10cSrcweir                 sal_uInt32 nNumberFormat = ((SfxUInt32Item*)pItem)->GetValue();
469*cdf0e10cSrcweir 				// oj #105473# change order of calls
470*cdf0e10cSrcweir                 const SvNumberformat* pFmt = pFormatter->GetEntry(nNumberFormat);
471*cdf0e10cSrcweir 				if( pFmt )
472*cdf0e10cSrcweir 					eCurLanguage = pFmt->GetLanguage();
473*cdf0e10cSrcweir 				// SetDefFormat uses eCurLanguage to look for if this format already in the list
474*cdf0e10cSrcweir                 SetDefFormat(nNumberFormat);
475*cdf0e10cSrcweir 			}
476*cdf0e10cSrcweir             if( bShowLanguageControl && SFX_ITEM_SET == pOutSet->GetItemState(
477*cdf0e10cSrcweir                 SID_ATTR_NUMBERFORMAT_ADD_AUTO, sal_False, &pItem ))
478*cdf0e10cSrcweir             {
479*cdf0e10cSrcweir                 bUseAutomaticLanguage = ((const SfxBoolItem*)pItem)->GetValue();
480*cdf0e10cSrcweir             }
481*cdf0e10cSrcweir         }
482*cdf0e10cSrcweir 		else
483*cdf0e10cSrcweir 			SetDefFormat(nFormat);
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 		delete pDlg;
486*cdf0e10cSrcweir 	}
487*cdf0e10cSrcweir 	return 0;
488*cdf0e10cSrcweir }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir /*--------------------------------------------------------------------
491*cdf0e10cSrcweir 	Beschreibung:
492*cdf0e10cSrcweir  --------------------------------------------------------------------*/
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir double NumFormatListBox::GetDefValue(const short nFormatType) const
495*cdf0e10cSrcweir {
496*cdf0e10cSrcweir 	double fDefValue = 0.0;
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir 	switch (nFormatType)
499*cdf0e10cSrcweir 	{
500*cdf0e10cSrcweir 		case NUMBERFORMAT_DATE:
501*cdf0e10cSrcweir 		case NUMBERFORMAT_DATE|NUMBERFORMAT_TIME:
502*cdf0e10cSrcweir 			fDefValue = SVX_NUMVAL_DATE;
503*cdf0e10cSrcweir 			break;
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 		case NUMBERFORMAT_TIME:
506*cdf0e10cSrcweir 			fDefValue = SVX_NUMVAL_TIME;
507*cdf0e10cSrcweir 			break;
508*cdf0e10cSrcweir /*		{
509*cdf0e10cSrcweir 			String sValue("31.8.1997 16:57:34");
510*cdf0e10cSrcweir 			sal_uLong nFormat = pFormatter->GetStandardFormat(nFormatType, LANGUAGE_GERMAN);
511*cdf0e10cSrcweir 			pFormatter->IsNumberFormat( sValue, nFormat, fDefValue );
512*cdf0e10cSrcweir 		}
513*cdf0e10cSrcweir 		break;*/
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 		case NUMBERFORMAT_TEXT:
516*cdf0e10cSrcweir 		case NUMBERFORMAT_UNDEFINED:
517*cdf0e10cSrcweir 			fDefValue = 0;
518*cdf0e10cSrcweir 			break;
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 		case NUMBERFORMAT_CURRENCY:
521*cdf0e10cSrcweir 			fDefValue = SVX_NUMVAL_CURRENCY;
522*cdf0e10cSrcweir 			break;
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 		case NUMBERFORMAT_PERCENT:
525*cdf0e10cSrcweir 			fDefValue = SVX_NUMVAL_PERCENT;
526*cdf0e10cSrcweir 			break;
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 		case NUMBERFORMAT_LOGICAL:
529*cdf0e10cSrcweir 			fDefValue = SVX_NUMVAL_BOOLEAN;
530*cdf0e10cSrcweir 			break;
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 		default:
533*cdf0e10cSrcweir 			fDefValue = SVX_NUMVAL_STANDARD;
534*cdf0e10cSrcweir 			break;
535*cdf0e10cSrcweir 	}
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 	return fDefValue;
538*cdf0e10cSrcweir }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir /*--------------------------------------------------------------------
541*cdf0e10cSrcweir 	Beschreibung:
542*cdf0e10cSrcweir  --------------------------------------------------------------------*/
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir void NumFormatListBox::Clear()
545*cdf0e10cSrcweir {
546*cdf0e10cSrcweir 	ListBox::Clear();
547*cdf0e10cSrcweir 	nCurrFormatType = -1;
548*cdf0e10cSrcweir }
549*cdf0e10cSrcweir 
550