update dev300-m58
[ooovba.git] / sw / source / filter / xml / xmltbli.hxx
blobb6477044ac3a937faa51ae4eb004e5f4a63341ee
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmltbli.hxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _XMLTBLI_HXX
32 #define _XMLTBLI_HXX
34 #include <xmloff/XMLTextTableContext.hxx>
36 // STL include
37 #include <hash_map>
39 #if !defined(_SVSTDARR_USHORTS_DECL) || !defined(_SVSTDARR_BOOLS_DECL) || !defined(_SVSTDARR_STRINGSDTOR_DECL)
40 #define _SVSTDARR_USHORTS
41 #define _SVSTDARR_BOOLS
42 #define _SVSTDARR_STRINGSDTOR
43 #include <svtools/svstdarr.hxx>
44 #endif
46 class SwXMLImport;
47 class SwTableNode;
48 class SwTableBox;
49 class SwTableLine;
50 class SwStartNode;
51 class SwTableBoxFmt;
52 class SwTableLineFmt;
53 class SwXMLTableCell_Impl;
54 class SwXMLTableRows_Impl;
55 class SwXMLDDETableContext_Impl;
56 class TableBoxIndexHasher;
57 class TableBoxIndex;
59 namespace com { namespace sun { namespace star {
60 namespace text { class XTextContent; }
61 namespace text { class XTextCursor; }
62 } } }
66 class SwXMLTableContext : public XMLTextTableContext
68 ::rtl::OUString aStyleName;
69 ::rtl::OUString aDfltCellStyleName;
70 /// NB: this contains the xml:id only if this table is a subtable!
71 ::rtl::OUString mXmlId;
73 SvUShorts aColumnWidths;
74 SvBools aColumnRelWidths;
75 SvStringsDtor *pColumnDefaultCellStyleNames;
77 ::com::sun::star::uno::Reference <
78 ::com::sun::star::text::XTextCursor > xOldCursor;
79 ::com::sun::star::uno::Reference <
80 ::com::sun::star::text::XTextContent > xTextContent;
82 SwXMLTableRows_Impl *pRows;
84 SwTableNode *pTableNode;
85 SwTableBox *pBox1;
86 const SwStartNode *pSttNd1;
88 SwTableBoxFmt *pBoxFmt;
89 SwTableLineFmt *pLineFmt;
91 // hash map of shared format, indexed by the (XML) style name,
92 // the column width, and protection flag
93 typedef std::hash_map<TableBoxIndex,SwTableBoxFmt*,
94 TableBoxIndexHasher> map_BoxFmt;
95 map_BoxFmt* pSharedBoxFormats;
97 SvXMLImportContextRef xParentTable; // if table is a sub table
99 SwXMLDDETableContext_Impl *pDDESource;
101 sal_Bool bFirstSection : 1;
102 sal_Bool bRelWidth : 1;
103 sal_Bool bHasSubTables : 1;
105 USHORT nHeaderRows;
106 sal_uInt32 nCurRow;
107 sal_uInt32 nCurCol;
108 sal_Int32 nWidth;
110 SwTableBox *NewTableBox( const SwStartNode *pStNd,
111 SwTableLine *pUpper );
112 SwTableBox *MakeTableBox( SwTableLine *pUpper,
113 const SwXMLTableCell_Impl *pStartNode,
114 sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
115 sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
116 SwTableBox *MakeTableBox( SwTableLine *pUpper,
117 sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
118 sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
119 SwTableLine *MakeTableLine( SwTableBox *pUpper,
120 sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
121 sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
123 void _MakeTable( SwTableBox *pBox=0 );
124 void MakeTable( SwTableBox *pBox, sal_Int32 nWidth );
125 void MakeTable();
127 inline SwXMLTableContext *GetParentTable() const;
129 const SwStartNode *GetPrevStartNode( sal_uInt32 nRow,
130 sal_uInt32 nCol ) const;
131 inline const SwStartNode *GetLastStartNode() const;
132 void FixRowSpan( sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan );
133 void ReplaceWithEmptyCell( sal_uInt32 nRow, sal_uInt32 nCol, bool bRows );
135 /** sets the appropriate SwTblBoxFmt at pBox. */
136 SwTableBoxFmt* GetSharedBoxFormat(
137 SwTableBox* pBox, /// the table box
138 const ::rtl::OUString& rStyleName, /// XML style name
139 sal_Int32 nColumnWidth, /// width of column
140 sal_Bool bProtected, /// is cell protected?
141 sal_Bool bMayShare, /// may the format be shared (no value, formula...)
142 sal_Bool& bNew, /// true, if the format it not from the cache
143 sal_Bool* pModifyLocked ); /// if set, call pBox->LockModify() and return old lock status
145 public:
147 TYPEINFO();
149 SwXMLTableContext( SwXMLImport& rImport, sal_uInt16 nPrfx,
150 const ::rtl::OUString& rLName,
151 const ::com::sun::star::uno::Reference<
152 ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
153 SwXMLTableContext( SwXMLImport& rImport, sal_uInt16 nPrfx,
154 const ::rtl::OUString& rLName,
155 const ::com::sun::star::uno::Reference<
156 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
157 SwXMLTableContext *pTable,
158 const ::rtl::OUString& i_rXmlId );
160 virtual ~SwXMLTableContext();
162 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
163 const ::rtl::OUString& rLocalName,
164 const ::com::sun::star::uno::Reference<
165 ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
167 SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
169 void InsertColumn( sal_Int32 nWidth, sal_Bool bRelWidth,
170 const ::rtl::OUString *pDfltCellStyleName = 0 );
171 sal_Int32 GetColumnWidth( sal_uInt32 nCol, sal_uInt32 nColSpan=1UL ) const;
172 ::rtl::OUString GetColumnDefaultCellStyleName( sal_uInt32 nCol ) const;
173 inline sal_uInt32 GetColumnCount() const;
174 inline sal_Bool HasColumnDefaultCellStyleNames() const;
176 sal_Bool IsInsertCellPossible() const { return nCurCol < GetColumnCount(); }
177 sal_Bool IsInsertColPossible() const { return nCurCol < USHRT_MAX; }
178 sal_Bool IsInsertRowPossible() const { return nCurRow < USHRT_MAX; }
179 sal_Bool IsValid() const { return pTableNode != 0; }
181 void InsertCell( const ::rtl::OUString& rStyleName,
182 sal_uInt32 nRowSpan=1U, sal_uInt32 nColSpan=1U,
183 const SwStartNode *pStNd=0,
184 const ::rtl::OUString & i_rXmlId = ::rtl::OUString(),
185 SwXMLTableContext *pTable=0,
186 sal_Bool bIsProtected = sal_False,
187 const ::rtl::OUString *pFormula=0,
188 sal_Bool bHasValue = sal_False,
189 double fValue = 0.0,
190 sal_Bool bTextValue = sal_False );
191 void InsertRow( const ::rtl::OUString& rStyleName,
192 const ::rtl::OUString& rDfltCellStyleName,
193 sal_Bool bInHead,
194 const ::rtl::OUString & i_rXmlId = ::rtl::OUString() );
195 void FinishRow();
196 void InsertRepRows( sal_uInt32 nCount );
197 SwXMLTableCell_Impl *GetCell( sal_uInt32 nRow, sal_uInt32 nCol ) const;
198 const SwStartNode *InsertTableSection( const SwStartNode *pPrevSttNd=0 );
200 virtual void EndElement();
202 virtual ::com::sun::star::uno::Reference <
203 ::com::sun::star::text::XTextContent > GetXTextContent() const;
205 void SetHasSubTables( sal_Bool bNew ) { bHasSubTables = bNew; }
208 inline SwXMLTableContext *SwXMLTableContext::GetParentTable() const
210 return (SwXMLTableContext *)&xParentTable;
213 inline sal_uInt32 SwXMLTableContext::GetColumnCount() const
215 return aColumnWidths.Count();
218 inline const SwStartNode *SwXMLTableContext::GetLastStartNode() const
220 return GetPrevStartNode( 0UL, GetColumnCount() );
223 inline sal_Bool SwXMLTableContext::HasColumnDefaultCellStyleNames() const
225 return pColumnDefaultCellStyleNames != 0;
228 #endif