1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_XLS_NUMBERFORMATSBUFFER_HXX 25 #define OOX_XLS_NUMBERFORMATSBUFFER_HXX 26 27 #include <com/sun/star/lang/Locale.hpp> 28 #include "oox/xls/workbookhelper.hxx" 29 30 namespace com { namespace sun { namespace star { 31 namespace util { class XNumberFormats; } 32 } } } 33 34 namespace oox { class PropertyMap; } 35 36 namespace oox { 37 namespace xls { 38 39 // ============================================================================ 40 41 struct NumFmtModel 42 { 43 ::com::sun::star::lang::Locale maLocale; 44 ::rtl::OUString maFmtCode; 45 sal_Int16 mnPredefId; 46 47 explicit NumFmtModel(); 48 }; 49 50 // ---------------------------------------------------------------------------- 51 52 /** Contains all API number format attributes. */ 53 struct ApiNumFmtData 54 { 55 sal_Int32 mnIndex; /// API number format index. 56 57 explicit ApiNumFmtData(); 58 }; 59 60 // ---------------------------------------------------------------------------- 61 62 /** Contains all data for a number format code. */ 63 class NumberFormat : public WorkbookHelper 64 { 65 public: 66 explicit NumberFormat( const WorkbookHelper& rHelper ); 67 68 /** Sets the passed format code. */ 69 void setFormatCode( const ::rtl::OUString& rFmtCode ); 70 /** Sets the passed format code, encoded in UTF-8. */ 71 void setFormatCode( 72 const ::com::sun::star::lang::Locale& rLocale, 73 const sal_Char* pcFmtCode ); 74 /** Sets the passed predefined format code identifier. */ 75 void setPredefinedId( 76 const ::com::sun::star::lang::Locale& rLocale, 77 sal_Int16 nPredefId ); 78 79 /** Final processing after import of all style settings. Returns the API format index. */ 80 sal_Int32 finalizeImport( 81 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& rxNumFmts, 82 const ::com::sun::star::lang::Locale& rFromLocale ); 83 84 /** Writes the number format to the passed property map. */ 85 void writeToPropertyMap( PropertyMap& rPropMap ) const; 86 87 private: 88 NumFmtModel maModel; 89 ApiNumFmtData maApiData; 90 }; 91 92 typedef ::boost::shared_ptr< NumberFormat > NumberFormatRef; 93 94 // ============================================================================ 95 96 class NumberFormatsBuffer : public WorkbookHelper 97 { 98 public: 99 explicit NumberFormatsBuffer( const WorkbookHelper& rHelper ); 100 101 /** Inserts a new number format. */ 102 NumberFormatRef createNumFmt( sal_Int32 nNumFmtId, const ::rtl::OUString& rFmtCode ); 103 104 /** Inserts a new number format code. */ 105 NumberFormatRef importNumFmt( const AttributeList& rAttribs ); 106 /** Inserts a new number format code from a NUMFMT record. */ 107 void importNumFmt( SequenceInputStream& rStrm ); 108 /** Inserts a new number format code from a FORMAT record. */ 109 void importFormat( BiffInputStream& rStrm ); 110 111 /** Final processing after import of all style settings. */ 112 void finalizeImport(); 113 114 /** Writes the specified number format to the passed property map. */ 115 void writeToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const; 116 117 private: 118 /** Inserts built-in number formats for the current system language. */ 119 void insertBuiltinFormats(); 120 121 private: 122 typedef RefMap< sal_Int32, NumberFormat > NumberFormatMap; 123 124 NumberFormatMap maNumFmts; /// List of number formats. 125 ::rtl::OUString maLocaleStr; /// Current office locale. 126 sal_Int32 mnNextBiffIndex; /// Format id counter for BIFF2-BIFF4. 127 }; 128 129 // ============================================================================ 130 131 } // namespace xls 132 } // namespace oox 133 134 #endif 135