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_EXTERNALLINKFRAGMENT_HXX
29 #define OOX_XLS_EXTERNALLINKFRAGMENT_HXX
30 
31 #include "oox/xls/excelhandlers.hxx"
32 #include "oox/xls/externallinkbuffer.hxx"
33 
34 namespace oox {
35 namespace xls {
36 
37 class ExternalLink;
38 
39 // ============================================================================
40 // ============================================================================
41 
42 /** This class implements importing the sheetData element in external sheets.
43 
44     The sheetData element embedded in the externalBook element contains cached
45     cells from externally linked sheets.
46  */
47 class ExternalSheetDataContext : public WorkbookContextBase
48 {
49 public:
50     explicit            ExternalSheetDataContext(
51                             WorkbookFragmentBase& rFragment,
52                             const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >& rxSheetCache );
53 
54 protected:
55     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
56     virtual void        onCharacters( const ::rtl::OUString& rChars );
57 
58     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
59 
60 private:
61     /** Imports cell settings from a c element. */
62     void                importCell( const AttributeList& rAttribs );
63 
64     /** Imports the EXTCELL_BLANK from the passed stream. */
65     void                importExtCellBlank( SequenceInputStream& rStrm );
66     /** Imports the EXTCELL_BOOL from the passed stream. */
67     void                importExtCellBool( SequenceInputStream& rStrm );
68     /** Imports the EXTCELL_DOUBLE from the passed stream. */
69     void                importExtCellDouble( SequenceInputStream& rStrm );
70     /** Imports the EXTCELL_ERROR from the passed stream. */
71     void                importExtCellError( SequenceInputStream& rStrm );
72     /** Imports the EXTCELL_STRING from the passed stream. */
73     void                importExtCellString( SequenceInputStream& rStrm );
74 
75     /** Sets the passed cell value to the current position in the sheet cache. */
76     void                setCellValue( const ::com::sun::star::uno::Any& rValue );
77 
78 private:
79     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >
80                         mxSheetCache;               /// The sheet cache used to store external cell values.
81     ::com::sun::star::table::CellAddress maCurrPos; /// Position of current cell.
82     sal_Int32           mnCurrType;                 /// Data type of current cell.
83 };
84 
85 // ============================================================================
86 
87 class ExternalLinkFragment : public WorkbookFragmentBase
88 {
89 public:
90     explicit            ExternalLinkFragment(
91                             const WorkbookHelper& rHelper,
92                             const ::rtl::OUString& rFragmentPath,
93                             ExternalLink& rExtLink );
94 
95 protected:
96     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
97     virtual void        onCharacters( const ::rtl::OUString& rChars );
98     virtual void        onEndElement();
99 
100     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
101 
102     virtual const ::oox::core::RecordInfo* getRecordInfos() const;
103 
104 private:
105     ::oox::core::ContextHandlerRef createSheetDataContext( sal_Int32 nSheetId );
106 
107 private:
108     ExternalLink&       mrExtLink;
109     ExternalNameRef     mxExtName;
110     ::rtl::OUString     maResultValue;
111     sal_Int32           mnResultType;
112 };
113 
114 // ============================================================================
115 // ============================================================================
116 
117 class BiffExternalSheetDataContext : public BiffWorkbookContextBase
118 {
119 public:
120     explicit            BiffExternalSheetDataContext( const WorkbookHelper& rHelper, bool bImportDefNames );
121     virtual             ~BiffExternalSheetDataContext();
122 
123     /** Tries to import a record related to external links and defined names. */
124     virtual void        importRecord( BiffInputStream& rStrm );
125 
126 private:
127     void                importExternSheet( BiffInputStream& rStrm );
128     void                importExternalBook( BiffInputStream& rStrm );
129     void                importExternalName( BiffInputStream& rStrm );
130     void                importXct( BiffInputStream& rStrm );
131     void                importCrn( BiffInputStream& rStrm );
132     void                importDefinedName( BiffInputStream& rStrm );
133 
134     /** Sets the passed cell value to the passed position in the sheet cache. */
135     void                setCellValue( const BinAddress& rBinAddr, const ::com::sun::star::uno::Any& rValue );
136 
137 private:
138     ExternalLinkRef     mxExtLink;              /// Current external link.
139     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >
140                         mxSheetCache;           /// The sheet cache used to store external cell values.
141     bool                mbImportDefNames;
142 };
143 
144 // ============================================================================
145 
146 class BiffExternalLinkFragment : public BiffWorkbookFragmentBase
147 {
148 public:
149     explicit            BiffExternalLinkFragment( const BiffWorkbookFragmentBase& rParent );
150 
151     /** Imports all records related to external links. */
152     virtual bool        importFragment();
153 };
154 
155 // ============================================================================
156 // ============================================================================
157 
158 } // namespace xls
159 } // namespace oox
160 
161 #endif
162