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 SC_XMLEXPORTITERATOR_HXX 25 #define SC_XMLEXPORTITERATOR_HXX 26 27 #include <vector> 28 #include <list> 29 #include <com/sun/star/sheet/XSpreadsheet.hpp> 30 #include <com/sun/star/table/CellAddress.hpp> 31 #include <com/sun/star/table/CellRangeAddress.hpp> 32 #include <com/sun/star/table/XCell.hpp> 33 #include <com/sun/star/text/XText.hpp> 34 #include <com/sun/star/sheet/XSheetAnnotation.hpp> 35 #include <com/sun/star/drawing/XShape.hpp> 36 #include "global.hxx" 37 #include "detfunc.hxx" 38 #include "detdata.hxx" 39 40 class ScHorizontalCellIterator; 41 struct ScMyCell; 42 class ScXMLExport; 43 class ScFormatRangeStyles; 44 class ScBaseCell; 45 46 //============================================================================== 47 48 class ScMyIteratorBase 49 { 50 protected: 51 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ) = 0; 52 53 public: 54 ScMyIteratorBase(); 55 virtual ~ScMyIteratorBase(); 56 57 virtual void SetCellData( ScMyCell& rMyCell ) = 0; 58 virtual void Sort() = 0; 59 60 virtual void UpdateAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 61 }; 62 63 //============================================================================== 64 65 struct ScMyShape 66 { 67 ScAddress aAddress; 68 ScAddress aEndAddress; 69 com::sun::star::uno::Reference<com::sun::star::drawing::XShape> xShape; 70 71 sal_Bool operator<(const ScMyShape& aShape) const; 72 }; 73 74 typedef std::list<ScMyShape> ScMyShapeList; 75 76 class ScMyShapesContainer : ScMyIteratorBase 77 { 78 private: 79 ScMyShapeList aShapeList; 80 protected: 81 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 82 public: 83 ScMyShapesContainer(); 84 virtual ~ScMyShapesContainer(); 85 86 using ScMyIteratorBase::UpdateAddress; 87 void AddNewShape(const ScMyShape& aShape); HasShapes()88 sal_Bool HasShapes() { return !aShapeList.empty(); } GetShapes()89 const ScMyShapeList* GetShapes() { return &aShapeList; } 90 virtual void SetCellData( ScMyCell& rMyCell ); 91 virtual void Sort(); 92 void SkipTable(SCTAB nSkip); 93 }; 94 95 struct ScMyNoteShape 96 { 97 com::sun::star::uno::Reference<com::sun::star::drawing::XShape> xShape; 98 ScAddress aPos; 99 100 sal_Bool operator<(const ScMyNoteShape& aNote) const; 101 }; 102 103 typedef std::list<ScMyNoteShape> ScMyNoteShapeList; 104 105 class ScMyNoteShapesContainer : ScMyIteratorBase 106 { 107 private: 108 ScMyNoteShapeList aNoteShapeList; 109 protected: 110 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 111 public: 112 ScMyNoteShapesContainer(); 113 virtual ~ScMyNoteShapesContainer(); 114 115 using ScMyIteratorBase::UpdateAddress; 116 void AddNewNote(const ScMyNoteShape& aNote); HasNotes()117 sal_Bool HasNotes() { return !aNoteShapeList.empty(); } GetNotes()118 const ScMyNoteShapeList* GetNotes() { return &aNoteShapeList; } 119 virtual void SetCellData( ScMyCell& rMyCell ); 120 virtual void Sort(); 121 void SkipTable(SCTAB nSkip); 122 }; 123 124 //============================================================================== 125 126 struct ScMyMergedRange 127 { 128 com::sun::star::table::CellRangeAddress aCellRange; 129 sal_Int32 nRows; 130 sal_Bool bIsFirst; 131 sal_Bool operator<(const ScMyMergedRange& aRange) const; 132 }; 133 134 typedef std::list<ScMyMergedRange> ScMyMergedRangeList; 135 136 class ScMyMergedRangesContainer : ScMyIteratorBase 137 { 138 private: 139 ScMyMergedRangeList aRangeList; 140 protected: 141 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 142 public: 143 ScMyMergedRangesContainer(); 144 virtual ~ScMyMergedRangesContainer(); 145 void AddRange(const com::sun::star::table::CellRangeAddress aMergedRange); 146 147 using ScMyIteratorBase::UpdateAddress; 148 virtual void SetCellData( ScMyCell& rMyCell ); 149 virtual void Sort(); // + remove doublets 150 void SkipTable(SCTAB nSkip); 151 }; 152 153 //============================================================================== 154 155 struct ScMyAreaLink 156 { 157 ::rtl::OUString sFilter; 158 ::rtl::OUString sFilterOptions; 159 ::rtl::OUString sURL; 160 ::rtl::OUString sSourceStr; 161 ::com::sun::star::table::CellRangeAddress aDestRange; 162 sal_Int32 nRefresh; 163 ScMyAreaLinkScMyAreaLink164 inline ScMyAreaLink() : nRefresh( 0 ) {} 165 GetColCountScMyAreaLink166 inline sal_Int32 GetColCount() const { return aDestRange.EndColumn - aDestRange.StartColumn + 1; } GetRowCountScMyAreaLink167 inline sal_Int32 GetRowCount() const { return aDestRange.EndRow - aDestRange.StartRow + 1; } 168 169 sal_Bool Compare( const ScMyAreaLink& rAreaLink ) const; 170 sal_Bool operator<(const ScMyAreaLink& rAreaLink ) const; 171 }; 172 173 typedef ::std::list< ScMyAreaLink > ScMyAreaLinkList; 174 175 class ScMyAreaLinksContainer : ScMyIteratorBase 176 { 177 private: 178 ScMyAreaLinkList aAreaLinkList; 179 protected: 180 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 181 public: 182 ScMyAreaLinksContainer(); 183 virtual ~ScMyAreaLinksContainer(); 184 AddNewAreaLink(const ScMyAreaLink & rAreaLink)185 inline void AddNewAreaLink( const ScMyAreaLink& rAreaLink ) 186 { aAreaLinkList.push_back( rAreaLink ); } 187 188 using ScMyIteratorBase::UpdateAddress; 189 virtual void SetCellData( ScMyCell& rMyCell ); 190 virtual void Sort(); 191 void SkipTable(SCTAB nSkip); 192 }; 193 194 //============================================================================== 195 196 struct ScMyCellRangeAddress : com::sun::star::table::CellRangeAddress 197 { 198 ScMyCellRangeAddress(const com::sun::star::table::CellRangeAddress& rRange); 199 sal_Bool operator<(const ScMyCellRangeAddress& rCellRangeAddress ) const; 200 }; 201 202 typedef std::list<ScMyCellRangeAddress> ScMyEmptyDatabaseRangeList; 203 204 class ScMyEmptyDatabaseRangesContainer : ScMyIteratorBase 205 { 206 private: 207 ScMyEmptyDatabaseRangeList aDatabaseList; 208 protected: 209 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 210 public: 211 ScMyEmptyDatabaseRangesContainer(); 212 virtual ~ScMyEmptyDatabaseRangesContainer(); 213 void AddNewEmptyDatabaseRange(const com::sun::star::table::CellRangeAddress& aCellRangeAddress); 214 215 using ScMyIteratorBase::UpdateAddress; 216 virtual void SetCellData( ScMyCell& rMyCell ); 217 virtual void Sort(); 218 void SkipTable(SCTAB nSkip); 219 }; 220 221 //============================================================================== 222 223 struct ScMyDetectiveObj 224 { 225 ::com::sun::star::table::CellAddress aPosition; 226 ::com::sun::star::table::CellRangeAddress aSourceRange; 227 ScDetectiveObjType eObjType; 228 sal_Bool bHasError; 229 sal_Bool operator<(const ScMyDetectiveObj& rDetObj) const; 230 }; 231 232 typedef ::std::list< ScMyDetectiveObj > ScMyDetectiveObjList; 233 typedef ::std::vector< ScMyDetectiveObj > ScMyDetectiveObjVec; 234 235 class ScMyDetectiveObjContainer : ScMyIteratorBase 236 { 237 private: 238 ScMyDetectiveObjList aDetectiveObjList; 239 protected: 240 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 241 public: 242 ScMyDetectiveObjContainer(); 243 virtual ~ScMyDetectiveObjContainer(); 244 245 void AddObject( 246 ScDetectiveObjType eObjType, 247 const SCTAB nSheet, 248 const ScAddress& rPosition, 249 const ScRange& rSourceRange, 250 sal_Bool bHasError ); 251 252 using ScMyIteratorBase::UpdateAddress; 253 virtual void SetCellData( ScMyCell& rMyCell ); 254 virtual void Sort(); 255 void SkipTable(SCTAB nSkip); 256 }; 257 258 //============================================================================== 259 260 struct ScMyDetectiveOp 261 { 262 ::com::sun::star::table::CellAddress aPosition; 263 ScDetOpType eOpType; 264 sal_Int32 nIndex; 265 sal_Bool operator<(const ScMyDetectiveOp& rDetOp) const; 266 }; 267 268 typedef ::std::list< ScMyDetectiveOp > ScMyDetectiveOpList; 269 typedef ::std::vector< ScMyDetectiveOp > ScMyDetectiveOpVec; 270 271 class ScMyDetectiveOpContainer : ScMyIteratorBase 272 { 273 private: 274 ScMyDetectiveOpList aDetectiveOpList; 275 protected: 276 virtual sal_Bool GetFirstAddress( ::com::sun::star::table::CellAddress& rCellAddress ); 277 public: 278 ScMyDetectiveOpContainer(); 279 virtual ~ScMyDetectiveOpContainer(); 280 281 void AddOperation( ScDetOpType eOpType, const ScAddress& rPosition, sal_uInt32 nIndex ); 282 283 using ScMyIteratorBase::UpdateAddress; 284 virtual void SetCellData( ScMyCell& rMyCell ); 285 virtual void Sort(); 286 void SkipTable(SCTAB nSkip); 287 }; 288 289 //============================================================================== 290 291 // contains data to export for the current cell position 292 struct ScMyCell 293 { 294 // com::sun::star::uno::Reference<com::sun::star::table::XCell> xCell; 295 // com::sun::star::uno::Reference<com::sun::star::text::XText> xText; 296 com::sun::star::uno::Reference<com::sun::star::sheet::XSheetAnnotation> xAnnotation; 297 com::sun::star::uno::Reference<com::sun::star::drawing::XShape> xNoteShape; 298 com::sun::star::table::CellAddress aCellAddress; 299 com::sun::star::table::CellRangeAddress aMergeRange; 300 com::sun::star::table::CellRangeAddress aMatrixRange; 301 302 rtl::OUString sStringValue; 303 rtl::OUString sAnnotationText; 304 305 ScMyAreaLink aAreaLink; 306 ScMyShapeList aShapeList; 307 ScMyDetectiveObjVec aDetectiveObjVec; 308 ScMyDetectiveOpVec aDetectiveOpVec; 309 310 double fValue; 311 sal_Int32 nValidationIndex; 312 sal_Int32 nStyleIndex; 313 sal_Int32 nNumberFormat; 314 com::sun::star::table::CellContentType nType; 315 316 ScBaseCell* pBaseCell; 317 318 sal_Bool bIsAutoStyle; 319 320 sal_Bool bHasShape; 321 sal_Bool bIsMergedBase; 322 sal_Bool bIsCovered; 323 sal_Bool bHasAreaLink; 324 sal_Bool bHasEmptyDatabase; 325 sal_Bool bHasDetectiveObj; 326 sal_Bool bHasDetectiveOp; 327 328 sal_Bool bIsEditCell; 329 sal_Bool bKnowWhetherIsEditCell; 330 sal_Bool bHasStringValue; 331 sal_Bool bHasDoubleValue; 332 sal_Bool bHasXText; 333 334 sal_Bool bIsMatrixBase; 335 sal_Bool bIsMatrixCovered; 336 sal_Bool bHasAnnotation; 337 338 ScMyCell(); 339 ~ScMyCell(); 340 }; 341 342 //============================================================================== 343 344 struct ScMyExportAnnotation 345 { 346 com::sun::star::uno::Reference<com::sun::star::sheet::XSheetAnnotation> xAnnotation; 347 com::sun::star::table::CellAddress aCellAddress; 348 sal_Bool operator<(const ScMyExportAnnotation& rAnno) const; 349 }; 350 351 typedef ::std::list< ScMyExportAnnotation > ScMyExportAnnotationList; 352 353 class ScMyNotEmptyCellsIterator 354 { 355 com::sun::star::uno::Reference<com::sun::star::sheet::XSpreadsheet> xTable; 356 com::sun::star::uno::Reference<com::sun::star::table::XCellRange> xCellRange; 357 com::sun::star::table::CellAddress aLastAddress; 358 ScMyExportAnnotationList aAnnotations; 359 360 ScMyShapesContainer* pShapes; 361 ScMyNoteShapesContainer* pNoteShapes; 362 ScMyEmptyDatabaseRangesContainer* pEmptyDatabaseRanges; 363 ScMyMergedRangesContainer* pMergedRanges; 364 ScMyAreaLinksContainer* pAreaLinks; 365 ScMyDetectiveObjContainer* pDetectiveObj; 366 ScMyDetectiveOpContainer* pDetectiveOp; 367 368 ScXMLExport& rExport; 369 ScHorizontalCellIterator* pCellItr; 370 371 SCCOL nCellCol; 372 SCROW nCellRow; 373 SCTAB nCurrentTable; 374 375 void UpdateAddress( ::com::sun::star::table::CellAddress& rAddress ); 376 void SetCellData( ScMyCell& rMyCell, ::com::sun::star::table::CellAddress& rAddress ); 377 378 void SetMatrixCellData( ScMyCell& rMyCell ); 379 void HasAnnotation( ScMyCell& aCell ); 380 public: 381 ScMyNotEmptyCellsIterator(ScXMLExport& rExport); 382 ~ScMyNotEmptyCellsIterator(); 383 384 void Clear(); 385 SetShapes(ScMyShapesContainer * pNewShapes)386 inline void SetShapes(ScMyShapesContainer* pNewShapes) 387 { pShapes = pNewShapes; } SetNoteShapes(ScMyNoteShapesContainer * pNewNoteShapes)388 inline void SetNoteShapes(ScMyNoteShapesContainer* pNewNoteShapes) 389 { pNoteShapes = pNewNoteShapes; } SetEmptyDatabaseRanges(ScMyEmptyDatabaseRangesContainer * pNewEmptyDatabaseRanges)390 inline void SetEmptyDatabaseRanges(ScMyEmptyDatabaseRangesContainer* pNewEmptyDatabaseRanges) 391 { pEmptyDatabaseRanges = pNewEmptyDatabaseRanges; } SetMergedRanges(ScMyMergedRangesContainer * pNewMergedRanges)392 inline void SetMergedRanges(ScMyMergedRangesContainer* pNewMergedRanges) 393 { pMergedRanges = pNewMergedRanges; } SetAreaLinks(ScMyAreaLinksContainer * pNewAreaLinks)394 inline void SetAreaLinks(ScMyAreaLinksContainer* pNewAreaLinks) 395 { pAreaLinks = pNewAreaLinks; } SetDetectiveObj(ScMyDetectiveObjContainer * pNewDetectiveObj)396 inline void SetDetectiveObj(ScMyDetectiveObjContainer* pNewDetectiveObj) 397 { pDetectiveObj = pNewDetectiveObj; } SetDetectiveOp(ScMyDetectiveOpContainer * pNewDetectiveOp)398 inline void SetDetectiveOp(ScMyDetectiveOpContainer* pNewDetectiveOp) 399 { pDetectiveOp = pNewDetectiveOp; } 400 401 void SetCurrentTable(const SCTAB nTable, 402 com::sun::star::uno::Reference<com::sun::star::sheet::XSpreadsheet>& rxTable); 403 void SkipTable(SCTAB nSkip); 404 405 sal_Bool GetNext(ScMyCell& aCell, ScFormatRangeStyles* pCellStyles); 406 }; 407 408 #endif 409 410