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