1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svl/numformat.hxx>
21 #include <svl/zforlist.hxx>
22 #include <svl/zformat.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
25 #include <osl/diagnose.h>
27 #include <zforauto.hxx>
28 #include <tools/stream.hxx>
30 ScNumFormatAbbrev::ScNumFormatAbbrev() :
31 sFormatstring ( u
"Standard"_ustr
),
32 eLanguage (LANGUAGE_SYSTEM
),
33 eSysLanguage (LANGUAGE_GERMAN
) // otherwise "Standard" does not fit
37 ScNumFormatAbbrev::ScNumFormatAbbrev(sal_uInt32 nFormat
,
38 const SvNumberFormatter
& rFormatter
)
40 PutFormatIndex(nFormat
, rFormatter
);
43 void ScNumFormatAbbrev::Load( SvStream
& rStream
, rtl_TextEncoding eByteStrSet
)
45 sal_uInt16 nSysLang
, nLang
;
46 sFormatstring
= rStream
.ReadUniOrByteString( eByteStrSet
);
47 rStream
.ReadUInt16( nSysLang
).ReadUInt16( nLang
);
48 eLanguage
= LanguageType(nLang
);
49 eSysLanguage
= LanguageType(nSysLang
);
50 if ( eSysLanguage
== LANGUAGE_SYSTEM
) // old versions did write it
51 eSysLanguage
= Application::GetSettings().GetLanguageTag().getLanguageType();
54 void ScNumFormatAbbrev::Save( SvStream
& rStream
, rtl_TextEncoding eByteStrSet
) const
56 rStream
.WriteUniOrByteString( sFormatstring
, eByteStrSet
);
57 rStream
.WriteUInt16( static_cast<sal_uInt16
>(eSysLanguage
) ).WriteUInt16( static_cast<sal_uInt16
>(eLanguage
) );
60 void ScNumFormatAbbrev::PutFormatIndex(sal_uInt32 nFormat
,
61 const SvNumberFormatter
& rFormatter
)
63 const SvNumberformat
* pFormat
= rFormatter
.GetEntry(nFormat
);
66 eSysLanguage
= Application::GetSettings().GetLanguageTag().getLanguageType();
67 eLanguage
= pFormat
->GetLanguage();
68 sFormatstring
= pFormat
->GetFormatstring();
72 OSL_FAIL("SCNumFormatAbbrev:: unknown number format");
73 eLanguage
= LANGUAGE_SYSTEM
;
74 eSysLanguage
= LANGUAGE_GERMAN
; // otherwise "Standard" does not fit
75 sFormatstring
= "Standard";
79 sal_uInt32
ScNumFormatAbbrev::GetFormatIndex( SvNumberFormatter
& rFormatter
)
81 SvNumFormatType nType
;
84 return rFormatter
.GetIndexPuttingAndConverting( sFormatstring
, eLanguage
,
85 eSysLanguage
, nType
, bNewInserted
, nCheckPos
);
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */