xref: /aoo42x/main/sw/source/filter/xml/xmltbli.hxx (revision 1d2dbeb0)
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 _XMLTBLI_HXX
25 #define _XMLTBLI_HXX
26 
27 #include <xmloff/XMLTextTableContext.hxx>
28 
29 // STL include
30 #include <hash_map>
31 
32 #if !defined(_SVSTDARR_USHORTS_DECL) || !defined(_SVSTDARR_BOOLS_DECL) || !defined(_SVSTDARR_STRINGSDTOR_DECL)
33 #define _SVSTDARR_USHORTS
34 #define _SVSTDARR_BOOLS
35 #define _SVSTDARR_STRINGSDTOR
36 #include <svl/svstdarr.hxx>
37 #endif
38 
39 class SwXMLImport;
40 class SwTableNode;
41 class SwTableBox;
42 class SwTableLine;
43 class SwStartNode;
44 class SwTableBoxFmt;
45 class SwTableLineFmt;
46 class SwXMLTableCell_Impl;
47 class SwXMLTableRows_Impl;
48 class SwXMLDDETableContext_Impl;
49 class TableBoxIndexHasher;
50 class TableBoxIndex;
51 
52 namespace com { namespace sun { namespace star {
53 	namespace text { class XTextContent; }
54 	namespace text { class XTextCursor; }
55 } } }
56 
57 
58 
59 class SwXMLTableContext : public XMLTextTableContext
60 {
61 	::rtl::OUString		aStyleName;
62 	::rtl::OUString		aDfltCellStyleName;
63     /// NB: this contains the xml:id only if this table is a subtable!
64     ::rtl::OUString     mXmlId;
65 
66 	SvUShorts			aColumnWidths;
67 	SvBools				aColumnRelWidths;
68 	SvStringsDtor		*pColumnDefaultCellStyleNames;
69 
70 	::com::sun::star::uno::Reference <
71 		::com::sun::star::text::XTextCursor > xOldCursor;
72 	::com::sun::star::uno::Reference <
73 		::com::sun::star::text::XTextContent > xTextContent;
74 
75 	SwXMLTableRows_Impl *pRows;
76 
77 	SwTableNode			*pTableNode;
78 	SwTableBox 			*pBox1;
79 	const SwStartNode	*pSttNd1;
80 
81 	SwTableBoxFmt		*pBoxFmt;
82 	SwTableLineFmt 		*pLineFmt;
83 
84     // hash map of shared format, indexed by the (XML) style name,
85     // the column width, and protection flag
86     typedef std::hash_map<TableBoxIndex,SwTableBoxFmt*,
87                           TableBoxIndexHasher> map_BoxFmt;
88     map_BoxFmt* pSharedBoxFormats;
89 
90 	SvXMLImportContextRef	xParentTable;	// if table is a sub table
91 
92 	SwXMLDDETableContext_Impl	*pDDESource;
93 
94 	sal_Bool			bFirstSection : 1;
95 	sal_Bool			bRelWidth : 1;
96     sal_Bool            bHasSubTables : 1;
97 
98 	sal_uInt16              nHeaderRows;
99 	sal_uInt32 			nCurRow;
100 	sal_uInt32			nCurCol;
101 	sal_Int32			nWidth;
102 
103 	SwTableBox *NewTableBox( const SwStartNode *pStNd,
104 							 SwTableLine *pUpper );
105     SwTableBox *MakeTableBox( SwTableLine *pUpper,
106                               const SwXMLTableCell_Impl *pStartNode,
107                               sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
108                               sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
109     SwTableBox *MakeTableBox( SwTableLine *pUpper,
110                               sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
111                               sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
112     SwTableLine *MakeTableLine( SwTableBox *pUpper,
113                                 sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
114                                 sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
115 
116 	void _MakeTable( SwTableBox *pBox=0 );
117 	void MakeTable( SwTableBox *pBox, sal_Int32 nWidth );
118 	void MakeTable();
119 
120 	inline SwXMLTableContext *GetParentTable() const;
121 
122 	const SwStartNode *GetPrevStartNode( sal_uInt32 nRow,
123 										 sal_uInt32 nCol ) const;
124 	inline const SwStartNode *GetLastStartNode() const;
125 	void FixRowSpan( sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan );
126     void ReplaceWithEmptyCell( sal_uInt32 nRow, sal_uInt32 nCol, bool bRows );
127 
128     /** sets the appropriate SwTblBoxFmt at pBox. */
129     SwTableBoxFmt* GetSharedBoxFormat(
130         SwTableBox* pBox,   /// the table box
131         const ::rtl::OUString& rStyleName, /// XML style name
132         sal_Int32 nColumnWidth,     /// width of column
133         sal_Bool bProtected,        /// is cell protected?
134         sal_Bool bMayShare, /// may the format be shared (no value, formula...)
135         sal_Bool& bNew,     /// true, if the format it not from the cache
136         sal_Bool* pModifyLocked );  /// if set, call pBox->LockModify() and return old lock status
137 
138 public:
139 
140 	TYPEINFO();
141 
142 	SwXMLTableContext( SwXMLImport& rImport, sal_uInt16 nPrfx,
143 			   	const ::rtl::OUString& rLName,
144 				const ::com::sun::star::uno::Reference<
145 					::com::sun::star::xml::sax::XAttributeList > & xAttrList );
146 	SwXMLTableContext( SwXMLImport& rImport, sal_uInt16 nPrfx,
147 			   	const ::rtl::OUString& rLName,
148 			  	const ::com::sun::star::uno::Reference<
149 					::com::sun::star::xml::sax::XAttributeList > & xAttrList,
150 				SwXMLTableContext *pTable,
151 				const ::rtl::OUString& i_rXmlId );
152 
153 	virtual ~SwXMLTableContext();
154 
155 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
156 				const ::rtl::OUString& rLocalName,
157 				const ::com::sun::star::uno::Reference<
158 					::com::sun::star::xml::sax::XAttributeList > & xAttrList );
159 
GetSwImport()160 	SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
161 
162 	void InsertColumn( sal_Int32 nWidth, sal_Bool bRelWidth,
163 					   const ::rtl::OUString *pDfltCellStyleName = 0 );
164 	sal_Int32 GetColumnWidth( sal_uInt32 nCol, sal_uInt32 nColSpan=1UL ) const;
165 	::rtl::OUString GetColumnDefaultCellStyleName( sal_uInt32 nCol ) const;
166 	inline sal_uInt32 GetColumnCount() const;
167 	inline sal_Bool HasColumnDefaultCellStyleNames() const;
168 
IsInsertCellPossible() const169 	sal_Bool IsInsertCellPossible() const { return nCurCol < GetColumnCount(); }
IsInsertColPossible() const170 	sal_Bool IsInsertColPossible() const { return nCurCol < USHRT_MAX; }
IsInsertRowPossible() const171 	sal_Bool IsInsertRowPossible() const { return nCurRow < USHRT_MAX; }
IsValid() const172 	sal_Bool IsValid() const { return pTableNode != 0; }
173 
174 	void InsertCell( const ::rtl::OUString& rStyleName,
175 					 sal_uInt32 nRowSpan=1U, sal_uInt32 nColSpan=1U,
176 					 const SwStartNode *pStNd=0,
177                      const ::rtl::OUString & i_rXmlId = ::rtl::OUString(),
178 					 SwXMLTableContext *pTable=0,
179 					 sal_Bool bIsProtected = sal_False,
180 					 const ::rtl::OUString *pFormula=0,
181 					 sal_Bool bHasValue = sal_False,
182 					 double fValue = 0.0,
183                      sal_Bool bTextValue = sal_False );
184 	void InsertRow( const ::rtl::OUString& rStyleName,
185 					const ::rtl::OUString& rDfltCellStyleName,
186 					sal_Bool bInHead,
187                     const ::rtl::OUString & i_rXmlId = ::rtl::OUString() );
188 	void FinishRow();
189 	void InsertRepRows( sal_uInt32 nCount );
190 	SwXMLTableCell_Impl *GetCell( sal_uInt32 nRow, sal_uInt32 nCol ) const;
191 	const SwStartNode *InsertTableSection( const SwStartNode *pPrevSttNd=0 );
192 
193 	virtual void EndElement();
194 
195 	virtual ::com::sun::star::uno::Reference <
196 			::com::sun::star::text::XTextContent > GetXTextContent() const;
197 
SetHasSubTables(sal_Bool bNew)198     void SetHasSubTables( sal_Bool bNew ) { bHasSubTables = bNew; }
199 };
200 
GetParentTable() const201 inline SwXMLTableContext *SwXMLTableContext::GetParentTable() const
202 {
203 	return (SwXMLTableContext *)&xParentTable;
204 }
205 
GetColumnCount() const206 inline sal_uInt32 SwXMLTableContext::GetColumnCount() const
207 {
208 	return aColumnWidths.Count();
209 }
210 
GetLastStartNode() const211 inline const SwStartNode *SwXMLTableContext::GetLastStartNode() const
212 {
213 	return GetPrevStartNode( 0UL, GetColumnCount() );
214 }
215 
HasColumnDefaultCellStyleNames() const216 inline sal_Bool SwXMLTableContext::HasColumnDefaultCellStyleNames() const
217 {
218 	return pColumnDefaultCellStyleNames != 0;
219 }
220 
221 #endif
222