xref: /aoo42x/main/sc/source/core/tool/zforauto.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include <svl/zforlist.hxx>
28 #include <svl/zformat.hxx>
29 #include <vcl/svapp.hxx>
30 #include <tools/debug.hxx>
31 
32 #include "zforauto.hxx"
33 #include "global.hxx"
34 
35 static const sal_Char __FAR_DATA pStandardName[] = "Standard";
36 
37 //------------------------------------------------------------------------
38 
ScNumFormatAbbrev()39 ScNumFormatAbbrev::ScNumFormatAbbrev() :
40 	sFormatstring	( RTL_CONSTASCII_USTRINGPARAM( pStandardName ) ),
41 	eLnge			(LANGUAGE_SYSTEM),
42 	eSysLnge		(LANGUAGE_GERMAN)		// sonst passt "Standard" nicht
43 {
44 }
45 
ScNumFormatAbbrev(const ScNumFormatAbbrev & aFormat)46 ScNumFormatAbbrev::ScNumFormatAbbrev(const ScNumFormatAbbrev& aFormat) :
47 	sFormatstring	(aFormat.sFormatstring),
48 	eLnge			(aFormat.eLnge),
49 	eSysLnge		(aFormat.eSysLnge)
50 {
51 }
52 
ScNumFormatAbbrev(sal_uLong nFormat,SvNumberFormatter & rFormatter)53 ScNumFormatAbbrev::ScNumFormatAbbrev(sal_uLong nFormat,
54 									 SvNumberFormatter& rFormatter)
55 {
56 	PutFormatIndex(nFormat, rFormatter);
57 }
58 
Load(SvStream & rStream,CharSet eByteStrSet)59 void ScNumFormatAbbrev::Load( SvStream& rStream, CharSet eByteStrSet )
60 {
61 	sal_uInt16 nSysLang, nLang;
62     rStream.ReadByteString( sFormatstring, eByteStrSet );
63 	rStream >> nSysLang >> nLang;
64 	eLnge = (LanguageType) nLang;
65 	eSysLnge = (LanguageType) nSysLang;
66     if ( eSysLnge == LANGUAGE_SYSTEM )          // old versions did write it
67         eSysLnge = Application::GetSettings().GetLanguage();
68 }
69 
Save(SvStream & rStream,CharSet eByteStrSet) const70 void ScNumFormatAbbrev::Save( SvStream& rStream, CharSet eByteStrSet ) const
71 {
72     rStream.WriteByteString( sFormatstring, eByteStrSet );
73 	rStream << (sal_uInt16) eSysLnge << (sal_uInt16) eLnge;
74 }
75 
PutFormatIndex(sal_uLong nFormat,SvNumberFormatter & rFormatter)76 void ScNumFormatAbbrev::PutFormatIndex(sal_uLong nFormat,
77 									   SvNumberFormatter& rFormatter)
78 {
79 	const SvNumberformat* pFormat = rFormatter.GetEntry(nFormat);
80 	if (pFormat)
81 	{
82         eSysLnge = Application::GetSettings().GetLanguage();
83 		eLnge = pFormat->GetLanguage();
84 		sFormatstring = ((SvNumberformat*)pFormat)->GetFormatstring();
85 	}
86 	else
87 	{
88 		DBG_ERROR("SCNumFormatAbbrev:: unbekanntes Zahlformat");
89 		eLnge = LANGUAGE_SYSTEM;
90 		eSysLnge = LANGUAGE_GERMAN;		// sonst passt "Standard" nicht
91 		sFormatstring.AssignAscii( RTL_CONSTASCII_STRINGPARAM( pStandardName ) );
92 	}
93 }
94 
GetFormatIndex(SvNumberFormatter & rFormatter)95 sal_uLong ScNumFormatAbbrev::GetFormatIndex( SvNumberFormatter& rFormatter)
96 {
97     short nType;
98     sal_Bool bNewInserted;
99     xub_StrLen nCheckPos;
100     return rFormatter.GetIndexPuttingAndConverting( sFormatstring, eLnge,
101             eSysLnge, nType, bNewInserted, nCheckPos);
102 }
103