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 #ifndef OOX_XLS_NUMBERFORMATSBUFFER_HXX
29 #define OOX_XLS_NUMBERFORMATSBUFFER_HXX
30 
31 #include <com/sun/star/lang/Locale.hpp>
32 #include "oox/xls/workbookhelper.hxx"
33 
34 namespace com { namespace sun { namespace star {
35     namespace util { class XNumberFormats; }
36 } } }
37 
38 namespace oox { class PropertyMap; }
39 
40 namespace oox {
41 namespace xls {
42 
43 // ============================================================================
44 
45 struct NumFmtModel
46 {
47     ::com::sun::star::lang::Locale maLocale;
48     ::rtl::OUString     maFmtCode;
49     sal_Int16           mnPredefId;
50 
51     explicit            NumFmtModel();
52 };
53 
54 // ----------------------------------------------------------------------------
55 
56 /** Contains all API number format attributes. */
57 struct ApiNumFmtData
58 {
59     sal_Int32           mnIndex;            /// API number format index.
60 
61     explicit            ApiNumFmtData();
62 };
63 
64 // ----------------------------------------------------------------------------
65 
66 /** Contains all data for a number format code. */
67 class NumberFormat : public WorkbookHelper
68 {
69 public:
70     explicit            NumberFormat( const WorkbookHelper& rHelper );
71 
72     /** Sets the passed format code. */
73     void                setFormatCode( const ::rtl::OUString& rFmtCode );
74     /** Sets the passed format code, encoded in UTF-8. */
75     void                setFormatCode(
76                             const ::com::sun::star::lang::Locale& rLocale,
77                             const sal_Char* pcFmtCode );
78     /** Sets the passed predefined format code identifier. */
79     void                setPredefinedId(
80                             const ::com::sun::star::lang::Locale& rLocale,
81                             sal_Int16 nPredefId );
82 
83     /** Final processing after import of all style settings. Returns the API format index. */
84     sal_Int32           finalizeImport(
85                             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& rxNumFmts,
86                             const ::com::sun::star::lang::Locale& rFromLocale );
87 
88     /** Writes the number format to the passed property map. */
89     void                writeToPropertyMap( PropertyMap& rPropMap ) const;
90 
91 private:
92     NumFmtModel         maModel;
93     ApiNumFmtData       maApiData;
94 };
95 
96 typedef ::boost::shared_ptr< NumberFormat > NumberFormatRef;
97 
98 // ============================================================================
99 
100 class NumberFormatsBuffer : public WorkbookHelper
101 {
102 public:
103     explicit            NumberFormatsBuffer( const WorkbookHelper& rHelper );
104 
105     /** Inserts a new number format. */
106     NumberFormatRef     createNumFmt( sal_Int32 nNumFmtId, const ::rtl::OUString& rFmtCode );
107 
108     /** Inserts a new number format code. */
109     NumberFormatRef     importNumFmt( const AttributeList& rAttribs );
110     /** Inserts a new number format code from a NUMFMT record. */
111     void                importNumFmt( SequenceInputStream& rStrm );
112     /** Inserts a new number format code from a FORMAT record. */
113     void                importFormat( BiffInputStream& rStrm );
114 
115     /** Final processing after import of all style settings. */
116     void                finalizeImport();
117 
118     /** Writes the specified number format to the passed property map. */
119     void                writeToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const;
120 
121 private:
122     /** Inserts built-in number formats for the current system language. */
123     void                insertBuiltinFormats();
124 
125 private:
126     typedef RefMap< sal_Int32, NumberFormat > NumberFormatMap;
127 
128     NumberFormatMap     maNumFmts;          /// List of number formats.
129     ::rtl::OUString     maLocaleStr;        /// Current office locale.
130     sal_Int32           mnNextBiffIndex;    /// Format id counter for BIFF2-BIFF4.
131 };
132 
133 // ============================================================================
134 
135 } // namespace xls
136 } // namespace oox
137 
138 #endif
139