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