xref: /AOO41X/main/sc/source/core/tool/zforauto.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include <svl/zforlist.hxx>
32 #include <svl/zformat.hxx>
33 #include <vcl/svapp.hxx>
34 #include <tools/debug.hxx>
35 
36 #include "zforauto.hxx"
37 #include "global.hxx"
38 
39 static const sal_Char __FAR_DATA pStandardName[] = "Standard";
40 
41 //------------------------------------------------------------------------
42 
43 ScNumFormatAbbrev::ScNumFormatAbbrev() :
44 	sFormatstring	( RTL_CONSTASCII_USTRINGPARAM( pStandardName ) ),
45 	eLnge			(LANGUAGE_SYSTEM),
46 	eSysLnge		(LANGUAGE_GERMAN)		// sonst passt "Standard" nicht
47 {
48 }
49 
50 ScNumFormatAbbrev::ScNumFormatAbbrev(const ScNumFormatAbbrev& aFormat) :
51 	sFormatstring	(aFormat.sFormatstring),
52 	eLnge			(aFormat.eLnge),
53 	eSysLnge		(aFormat.eSysLnge)
54 {
55 }
56 
57 ScNumFormatAbbrev::ScNumFormatAbbrev(sal_uLong nFormat,
58 									 SvNumberFormatter& rFormatter)
59 {
60 	PutFormatIndex(nFormat, rFormatter);
61 }
62 
63 void ScNumFormatAbbrev::Load( SvStream& rStream, CharSet eByteStrSet )
64 {
65 	sal_uInt16 nSysLang, nLang;
66     rStream.ReadByteString( sFormatstring, eByteStrSet );
67 	rStream >> nSysLang >> nLang;
68 	eLnge = (LanguageType) nLang;
69 	eSysLnge = (LanguageType) nSysLang;
70     if ( eSysLnge == LANGUAGE_SYSTEM )          // old versions did write it
71         eSysLnge = Application::GetSettings().GetLanguage();
72 }
73 
74 void ScNumFormatAbbrev::Save( SvStream& rStream, CharSet eByteStrSet ) const
75 {
76     rStream.WriteByteString( sFormatstring, eByteStrSet );
77 	rStream << (sal_uInt16) eSysLnge << (sal_uInt16) eLnge;
78 }
79 
80 void ScNumFormatAbbrev::PutFormatIndex(sal_uLong nFormat,
81 									   SvNumberFormatter& rFormatter)
82 {
83 	const SvNumberformat* pFormat = rFormatter.GetEntry(nFormat);
84 	if (pFormat)
85 	{
86         eSysLnge = Application::GetSettings().GetLanguage();
87 		eLnge = pFormat->GetLanguage();
88 		sFormatstring = ((SvNumberformat*)pFormat)->GetFormatstring();
89 	}
90 	else
91 	{
92 		DBG_ERROR("SCNumFormatAbbrev:: unbekanntes Zahlformat");
93 		eLnge = LANGUAGE_SYSTEM;
94 		eSysLnge = LANGUAGE_GERMAN;		// sonst passt "Standard" nicht
95 		sFormatstring.AssignAscii( RTL_CONSTASCII_STRINGPARAM( pStandardName ) );
96 	}
97 }
98 
99 sal_uLong ScNumFormatAbbrev::GetFormatIndex( SvNumberFormatter& rFormatter)
100 {
101     short nType;
102     sal_Bool bNewInserted;
103     xub_StrLen nCheckPos;
104     return rFormatter.GetIndexPuttingAndConverting( sFormatstring, eLnge,
105             eSysLnge, nType, bNewInserted, nCheckPos);
106 }
107