1*e3508121SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e3508121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e3508121SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e3508121SAndrew Rist * distributed with this work for additional information 6*e3508121SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e3508121SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e3508121SAndrew Rist * "License"); you may not use this file except in compliance 9*e3508121SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*e3508121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*e3508121SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e3508121SAndrew Rist * software distributed under the License is distributed on an 15*e3508121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e3508121SAndrew Rist * KIND, either express or implied. See the License for the 17*e3508121SAndrew Rist * specific language governing permissions and limitations 18*e3508121SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*e3508121SAndrew Rist *************************************************************/ 21*e3508121SAndrew Rist 22*e3508121SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef OOX_XLS_PIVOTCACHEFRAGMENT_HXX 25cdf0e10cSrcweir #define OOX_XLS_PIVOTCACHEFRAGMENT_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "oox/xls/excelhandlers.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace oox { 30cdf0e10cSrcweir namespace xls { 31cdf0e10cSrcweir 32cdf0e10cSrcweir class PivotCache; 33cdf0e10cSrcweir class PivotCacheField; 34cdf0e10cSrcweir 35cdf0e10cSrcweir // ============================================================================ 36cdf0e10cSrcweir 37cdf0e10cSrcweir class PivotCacheFieldContext : public WorkbookContextBase 38cdf0e10cSrcweir { 39cdf0e10cSrcweir public: 40cdf0e10cSrcweir explicit PivotCacheFieldContext( 41cdf0e10cSrcweir WorkbookFragmentBase& rFragment, 42cdf0e10cSrcweir PivotCacheField& rCacheField ); 43cdf0e10cSrcweir 44cdf0e10cSrcweir protected: 45cdf0e10cSrcweir virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); 46cdf0e10cSrcweir virtual void onStartElement( const AttributeList& rAttribs ); 47cdf0e10cSrcweir virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); 48cdf0e10cSrcweir virtual void onStartRecord( SequenceInputStream& rStrm ); 49cdf0e10cSrcweir 50cdf0e10cSrcweir private: 51cdf0e10cSrcweir PivotCacheField& mrCacheField; 52cdf0e10cSrcweir }; 53cdf0e10cSrcweir 54cdf0e10cSrcweir // ============================================================================ 55cdf0e10cSrcweir 56cdf0e10cSrcweir class PivotCacheDefinitionFragment : public WorkbookFragmentBase 57cdf0e10cSrcweir { 58cdf0e10cSrcweir public: 59cdf0e10cSrcweir explicit PivotCacheDefinitionFragment( 60cdf0e10cSrcweir const WorkbookHelper& rHelper, 61cdf0e10cSrcweir const ::rtl::OUString& rFragmentPath, 62cdf0e10cSrcweir PivotCache& rPivotCache ); 63cdf0e10cSrcweir 64cdf0e10cSrcweir protected: 65cdf0e10cSrcweir virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); 66cdf0e10cSrcweir virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); 67cdf0e10cSrcweir virtual const ::oox::core::RecordInfo* getRecordInfos() const; 68cdf0e10cSrcweir virtual void finalizeImport(); 69cdf0e10cSrcweir 70cdf0e10cSrcweir private: 71cdf0e10cSrcweir PivotCache& mrPivotCache; 72cdf0e10cSrcweir }; 73cdf0e10cSrcweir 74cdf0e10cSrcweir // ============================================================================ 75cdf0e10cSrcweir 76cdf0e10cSrcweir class PivotCacheRecordsFragment : public WorksheetFragmentBase 77cdf0e10cSrcweir { 78cdf0e10cSrcweir public: 79cdf0e10cSrcweir explicit PivotCacheRecordsFragment( 80cdf0e10cSrcweir const WorksheetHelper& rHelper, 81cdf0e10cSrcweir const ::rtl::OUString& rFragmentPath, 82cdf0e10cSrcweir const PivotCache& rPivotCache ); 83cdf0e10cSrcweir 84cdf0e10cSrcweir protected: 85cdf0e10cSrcweir virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); 86cdf0e10cSrcweir virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); 87cdf0e10cSrcweir virtual const ::oox::core::RecordInfo* getRecordInfos() const; 88cdf0e10cSrcweir 89cdf0e10cSrcweir private: 90cdf0e10cSrcweir void startCacheRecord(); 91cdf0e10cSrcweir void importPCRecord( SequenceInputStream& rStrm ); 92cdf0e10cSrcweir void importPCRecordItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir private: 95cdf0e10cSrcweir const PivotCache& mrPivotCache; 96cdf0e10cSrcweir sal_Int32 mnColIdx; /// Relative column index in source data. 97cdf0e10cSrcweir sal_Int32 mnRowIdx; /// Relative row index in source data. 98cdf0e10cSrcweir bool mbInRecord; 99cdf0e10cSrcweir }; 100cdf0e10cSrcweir 101cdf0e10cSrcweir // ============================================================================ 102cdf0e10cSrcweir // ============================================================================ 103cdf0e10cSrcweir 104cdf0e10cSrcweir class BiffPivotCacheFragment : public BiffWorkbookFragmentBase 105cdf0e10cSrcweir { 106cdf0e10cSrcweir public: 107cdf0e10cSrcweir explicit BiffPivotCacheFragment( 108cdf0e10cSrcweir const WorkbookHelper& rHelper, 109cdf0e10cSrcweir const ::rtl::OUString& rStrmName, 110cdf0e10cSrcweir PivotCache& rPivotCache ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir /** Imports the entire fragment, returns true, if EOF record has been reached. */ 113cdf0e10cSrcweir virtual bool importFragment(); 114cdf0e10cSrcweir 115cdf0e10cSrcweir private: 116cdf0e10cSrcweir PivotCache& mrPivotCache; 117cdf0e10cSrcweir }; 118cdf0e10cSrcweir 119cdf0e10cSrcweir // ============================================================================ 120cdf0e10cSrcweir 121cdf0e10cSrcweir class BiffPivotCacheRecordsContext : public BiffWorksheetContextBase 122cdf0e10cSrcweir { 123cdf0e10cSrcweir public: 124cdf0e10cSrcweir explicit BiffPivotCacheRecordsContext( 125cdf0e10cSrcweir const WorksheetHelper& rHelper, 126cdf0e10cSrcweir const PivotCache& rPivotCache ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir /** Reads the current record from stream and tries to insert a cell into 129cdf0e10cSrcweir the source data sheet. */ 130cdf0e10cSrcweir virtual void importRecord( BiffInputStream& rStrm ); 131cdf0e10cSrcweir 132cdf0e10cSrcweir private: 133cdf0e10cSrcweir void startNextRow(); 134cdf0e10cSrcweir 135cdf0e10cSrcweir private: 136cdf0e10cSrcweir typedef ::std::vector< sal_Int32 > ColumnIndexVector; 137cdf0e10cSrcweir 138cdf0e10cSrcweir const PivotCache& mrPivotCache; 139cdf0e10cSrcweir ColumnIndexVector maUnsharedCols; /// Column indexes of all unshared cache fields. 140cdf0e10cSrcweir size_t mnColIdx; /// Current index into maUnsharedCols. 141cdf0e10cSrcweir sal_Int32 mnRowIdx; /// Current row in source data (0-based). 142cdf0e10cSrcweir bool mbHasShared; /// True = pivot cache contains fields with shared items. 143cdf0e10cSrcweir bool mbInRow; /// True = a data row has been started. 144cdf0e10cSrcweir }; 145cdf0e10cSrcweir 146cdf0e10cSrcweir // ============================================================================ 147cdf0e10cSrcweir 148cdf0e10cSrcweir } // namespace xls 149cdf0e10cSrcweir } // namespace oox 150cdf0e10cSrcweir 151cdf0e10cSrcweir #endif 152