Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_SOURCE_FILTER_INC_NUMBERFORMATSBUFFER_HXX
21 : #define INCLUDED_SC_SOURCE_FILTER_INC_NUMBERFORMATSBUFFER_HXX
22 :
23 : #include <com/sun/star/lang/Locale.hpp>
24 : #include <svl/itemset.hxx>
25 : #include "workbookhelper.hxx"
26 :
27 : namespace com { namespace sun { namespace star {
28 : namespace util { class XNumberFormats; }
29 : } } }
30 :
31 : namespace oox { class PropertyMap; }
32 :
33 : namespace oox {
34 : namespace xls {
35 :
36 15057 : struct NumFmtModel
37 : {
38 : ::com::sun::star::lang::Locale maLocale;
39 : OUString maFmtCode;
40 : sal_Int16 mnPredefId;
41 :
42 : explicit NumFmtModel();
43 : };
44 :
45 : /** Contains all API number format attributes. */
46 : struct ApiNumFmtData
47 : {
48 : sal_Int32 mnIndex; /// API number format index.
49 :
50 : explicit ApiNumFmtData();
51 : };
52 :
53 : /** Contains all data for a number format code. */
54 30114 : class NumberFormat : public WorkbookHelper
55 : {
56 : public:
57 : explicit NumberFormat( const WorkbookHelper& rHelper );
58 :
59 : /** Sets the passed format code. */
60 : void setFormatCode( const OUString& rFmtCode );
61 : /** Sets the passed format code, encoded in UTF-8. */
62 : void setFormatCode(
63 : const ::com::sun::star::lang::Locale& rLocale,
64 : const sal_Char* pcFmtCode );
65 : /** Sets the passed predefined format code identifier. */
66 : void setPredefinedId(
67 : const ::com::sun::star::lang::Locale& rLocale,
68 : sal_Int16 nPredefId );
69 :
70 : /** Final processing after import of all style settings. Returns the API format index. */
71 : sal_Int32 finalizeImport(
72 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& rxNumFmts,
73 : const ::com::sun::star::lang::Locale& rFromLocale );
74 : sal_uLong fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
75 : /** Writes the number format to the passed property map. */
76 : void writeToPropertyMap( PropertyMap& rPropMap ) const;
77 :
78 : private:
79 : NumFmtModel maModel;
80 : ApiNumFmtData maApiData;
81 : };
82 :
83 : typedef std::shared_ptr< NumberFormat > NumberFormatRef;
84 :
85 145 : class NumberFormatsBuffer : public WorkbookHelper
86 : {
87 : public:
88 : explicit NumberFormatsBuffer( const WorkbookHelper& rHelper );
89 :
90 : /** Inserts a new number format. */
91 : NumberFormatRef createNumFmt( sal_Int32 nNumFmtId, const OUString& rFmtCode );
92 :
93 : /** Inserts a new number format code. */
94 : NumberFormatRef importNumFmt( const AttributeList& rAttribs );
95 : /** Inserts a new number format code from a NUMFMT record. */
96 : void importNumFmt( SequenceInputStream& rStrm );
97 :
98 : /** Final processing after import of all style settings. */
99 : void finalizeImport();
100 :
101 : sal_uLong fillToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs = false ) const;
102 :
103 : /** Writes the specified number format to the passed property map. */
104 : void writeToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const;
105 38 : sal_Int32 nextFreeId(){ return ++mnHighestId; }
106 : private:
107 : /** Inserts built-in number formats for the current system language. */
108 : void insertBuiltinFormats();
109 :
110 : private:
111 : typedef RefMap< sal_Int32, NumberFormat > NumberFormatMap;
112 :
113 : NumberFormatMap maNumFmts; /// List of number formats.
114 : OUString maLocaleStr; /// Current office locale.
115 : sal_Int32 mnHighestId;
116 : };
117 :
118 : } // namespace xls
119 : } // namespace oox
120 :
121 : #endif
122 :
123 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|