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