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_PIVOTCACHEFRAGMENT_HXX
25 #define OOX_XLS_PIVOTCACHEFRAGMENT_HXX
26 
27 #include "oox/xls/excelhandlers.hxx"
28 
29 namespace oox {
30 namespace xls {
31 
32 class PivotCache;
33 class PivotCacheField;
34 
35 // ============================================================================
36 
37 class PivotCacheFieldContext : public WorkbookContextBase
38 {
39 public:
40     explicit            PivotCacheFieldContext(
41                             WorkbookFragmentBase& rFragment,
42                             PivotCacheField& rCacheField );
43 
44 protected:
45     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
46     virtual void        onStartElement( const AttributeList& rAttribs );
47     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
48     virtual void        onStartRecord( SequenceInputStream& rStrm );
49 
50 private:
51     PivotCacheField&    mrCacheField;
52 };
53 
54 // ============================================================================
55 
56 class PivotCacheDefinitionFragment : public WorkbookFragmentBase
57 {
58 public:
59     explicit            PivotCacheDefinitionFragment(
60                             const WorkbookHelper& rHelper,
61                             const ::rtl::OUString& rFragmentPath,
62                             PivotCache& rPivotCache );
63 
64 protected:
65     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
66     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
67     virtual const ::oox::core::RecordInfo* getRecordInfos() const;
68     virtual void        finalizeImport();
69 
70 private:
71     PivotCache&         mrPivotCache;
72 };
73 
74 // ============================================================================
75 
76 class PivotCacheRecordsFragment : public WorksheetFragmentBase
77 {
78 public:
79     explicit            PivotCacheRecordsFragment(
80                             const WorksheetHelper& rHelper,
81                             const ::rtl::OUString& rFragmentPath,
82                             const PivotCache& rPivotCache );
83 
84 protected:
85     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
86     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
87     virtual const ::oox::core::RecordInfo* getRecordInfos() const;
88 
89 private:
90     void                startCacheRecord();
91     void                importPCRecord( SequenceInputStream& rStrm );
92     void                importPCRecordItem( sal_Int32 nRecId, SequenceInputStream& rStrm );
93 
94 private:
95     const PivotCache&   mrPivotCache;
96     sal_Int32           mnColIdx;           /// Relative column index in source data.
97     sal_Int32           mnRowIdx;           /// Relative row index in source data.
98     bool                mbInRecord;
99 };
100 
101 // ============================================================================
102 // ============================================================================
103 
104 class BiffPivotCacheFragment : public BiffWorkbookFragmentBase
105 {
106 public:
107     explicit            BiffPivotCacheFragment(
108                             const WorkbookHelper& rHelper,
109                             const ::rtl::OUString& rStrmName,
110                             PivotCache& rPivotCache );
111 
112     /** Imports the entire fragment, returns true, if EOF record has been reached. */
113     virtual bool        importFragment();
114 
115 private:
116     PivotCache&         mrPivotCache;
117 };
118 
119 // ============================================================================
120 
121 class BiffPivotCacheRecordsContext : public BiffWorksheetContextBase
122 {
123 public:
124     explicit            BiffPivotCacheRecordsContext(
125                             const WorksheetHelper& rHelper,
126                             const PivotCache& rPivotCache );
127 
128     /** Reads the current record from stream and tries to insert a cell into
129         the source data sheet. */
130     virtual void        importRecord( BiffInputStream& rStrm );
131 
132 private:
133     void                startNextRow();
134 
135 private:
136     typedef ::std::vector< sal_Int32 > ColumnIndexVector;
137 
138     const PivotCache&   mrPivotCache;
139     ColumnIndexVector   maUnsharedCols; /// Column indexes of all unshared cache fields.
140     size_t              mnColIdx;       /// Current index into maUnsharedCols.
141     sal_Int32           mnRowIdx;       /// Current row in source data (0-based).
142     bool                mbHasShared;    /// True = pivot cache contains fields with shared items.
143     bool                mbInRow;        /// True = a data row has been started.
144 };
145 
146 // ============================================================================
147 
148 } // namespace xls
149 } // namespace oox
150 
151 #endif
152