1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #pragma once 21 22 #include <vector> 23 #include <list> 24 #include <com/sun/star/table/CellContentType.hpp> 25 #include <detfunc.hxx> 26 #include <detdata.hxx> 27 #include <cellvalue.hxx> 28 29 #include <memory> 30 31 namespace com::sun::star::drawing { class XShape; } 32 namespace com::sun::star::sheet { class XSpreadsheet; } 33 namespace com::sun::star::table { class XCellRange; } 34 namespace com::sun::star::table { struct CellRangeAddress; } 35 36 class ScPostIt; 37 class ScHorizontalCellIterator; 38 struct ScMyCell; 39 class ScXMLExport; 40 class ScFormatRangeStyles; 41 42 class ScMyIteratorBase 43 { 44 protected: 45 virtual bool GetFirstAddress( ScAddress& rCellAddress ) = 0; 46 47 public: 48 ScMyIteratorBase(); 49 virtual ~ScMyIteratorBase(); 50 51 ScMyIteratorBase(ScMyIteratorBase const &) = default; 52 ScMyIteratorBase(ScMyIteratorBase &&) = default; 53 ScMyIteratorBase & operator =(ScMyIteratorBase const &) = default; 54 ScMyIteratorBase & operator =(ScMyIteratorBase &&) = default; 55 56 virtual void SetCellData( ScMyCell& rMyCell ) = 0; 57 virtual void Sort() = 0; 58 59 void UpdateAddress( ScAddress& rCellAddress ); 60 }; 61 62 struct ScMyShape 63 { 64 ScAddress aAddress; 65 ScAddress aEndAddress; 66 sal_Int32 nEndX; 67 sal_Int32 nEndY; 68 bool bResizeWithCell; 69 css::uno::Reference<css::drawing::XShape> xShape; 70 71 bool operator<(const ScMyShape& aShape) const; 72 }; 73 74 typedef std::list<ScMyShape> ScMyShapeList; 75 76 class ScMyShapesContainer : public ScMyIteratorBase 77 { 78 private: 79 ScMyShapeList aShapeList; 80 protected: 81 virtual bool GetFirstAddress( ScAddress& rCellAddress ) override; 82 public: 83 ScMyShapesContainer(); 84 virtual ~ScMyShapesContainer() override; 85 86 using ScMyIteratorBase::UpdateAddress; 87 void AddNewShape(const ScMyShape& aShape); HasShapes() const88 bool HasShapes() const { return !aShapeList.empty(); } GetShapes() const89 const ScMyShapeList& GetShapes() const { return aShapeList; } 90 virtual void SetCellData( ScMyCell& rMyCell ) override; 91 virtual void Sort() override; 92 void SkipTable(SCTAB nSkip); 93 }; 94 95 struct ScMyNoteShape 96 { 97 css::uno::Reference<css::drawing::XShape> xShape; 98 ScAddress aPos; 99 100 bool operator<(const ScMyNoteShape& aNote) const; 101 }; 102 103 typedef std::list<ScMyNoteShape> ScMyNoteShapeList; 104 105 class ScMyNoteShapesContainer : public ScMyIteratorBase 106 { 107 private: 108 ScMyNoteShapeList aNoteShapeList; 109 protected: 110 virtual bool GetFirstAddress( ScAddress& rCellAddress ) override; 111 public: 112 ScMyNoteShapesContainer(); 113 virtual ~ScMyNoteShapesContainer() override; 114 115 using ScMyIteratorBase::UpdateAddress; 116 void AddNewNote(const ScMyNoteShape& aNote); GetNotes() const117 const ScMyNoteShapeList& GetNotes() const { return aNoteShapeList; } 118 virtual void SetCellData( ScMyCell& rMyCell ) override; 119 virtual void Sort() override; 120 void SkipTable(SCTAB nSkip); 121 }; 122 123 struct ScMyMergedRange 124 { 125 ScRange aCellRange; 126 sal_Int32 nRows; 127 bool bIsFirst; 128 bool operator<(const ScMyMergedRange& aRange) const; 129 }; 130 131 typedef std::list<ScMyMergedRange> ScMyMergedRangeList; 132 133 class ScMyMergedRangesContainer : public ScMyIteratorBase 134 { 135 private: 136 ScMyMergedRangeList aRangeList; 137 protected: 138 virtual bool GetFirstAddress( ScAddress& rCellAddress ) override; 139 public: 140 ScMyMergedRangesContainer(); 141 virtual ~ScMyMergedRangesContainer() override; 142 void AddRange(const ScRange& rMergedRange); 143 144 using ScMyIteratorBase::UpdateAddress; 145 virtual void SetCellData( ScMyCell& rMyCell ) override; 146 virtual void Sort() override; // + remove doublets 147 void SkipTable(SCTAB nSkip); 148 }; 149 150 struct ScMyAreaLink 151 { 152 OUString sFilter; 153 OUString sFilterOptions; 154 OUString sURL; 155 OUString sSourceStr; 156 ScRange aDestRange; 157 sal_Int32 nRefresh; 158 ScMyAreaLinkScMyAreaLink159 ScMyAreaLink() : nRefresh( 0 ) {} 160 GetColCountScMyAreaLink161 sal_Int32 GetColCount() const { return aDestRange.aEnd.Col() - aDestRange.aStart.Col() + 1; } GetRowCountScMyAreaLink162 sal_Int32 GetRowCount() const { return aDestRange.aEnd.Row() - aDestRange.aStart.Row() + 1; } 163 164 bool Compare( const ScMyAreaLink& rAreaLink ) const; 165 bool operator<(const ScMyAreaLink& rAreaLink ) const; 166 }; 167 168 typedef ::std::list< ScMyAreaLink > ScMyAreaLinkList; 169 170 class ScMyAreaLinksContainer : public ScMyIteratorBase 171 { 172 private: 173 ScMyAreaLinkList aAreaLinkList; 174 protected: 175 virtual bool GetFirstAddress( ScAddress& rCellAddress ) override; 176 public: 177 ScMyAreaLinksContainer(); 178 virtual ~ScMyAreaLinksContainer() override; 179 AddNewAreaLink(const ScMyAreaLink & rAreaLink)180 void AddNewAreaLink( const ScMyAreaLink& rAreaLink ) 181 { aAreaLinkList.push_back( rAreaLink ); } 182 183 using ScMyIteratorBase::UpdateAddress; 184 virtual void SetCellData( ScMyCell& rMyCell ) override; 185 virtual void Sort() override; 186 void SkipTable(SCTAB nSkip); 187 }; 188 189 typedef std::list<ScRange> ScMyEmptyDatabaseRangeList; 190 191 class ScMyEmptyDatabaseRangesContainer : public ScMyIteratorBase 192 { 193 private: 194 ScMyEmptyDatabaseRangeList aDatabaseList; 195 protected: 196 virtual bool GetFirstAddress( ScAddress& rCellAddress ) override; 197 public: 198 ScMyEmptyDatabaseRangesContainer(); 199 virtual ~ScMyEmptyDatabaseRangesContainer() override; 200 201 ScMyEmptyDatabaseRangesContainer(ScMyEmptyDatabaseRangesContainer const &) = default; 202 ScMyEmptyDatabaseRangesContainer(ScMyEmptyDatabaseRangesContainer &&) = default; 203 ScMyEmptyDatabaseRangesContainer & operator =(ScMyEmptyDatabaseRangesContainer const &) = default; 204 ScMyEmptyDatabaseRangesContainer & operator =(ScMyEmptyDatabaseRangesContainer &&) = default; 205 206 void AddNewEmptyDatabaseRange(const css::table::CellRangeAddress& aCellRangeAddress); 207 208 using ScMyIteratorBase::UpdateAddress; 209 virtual void SetCellData( ScMyCell& rMyCell ) override; 210 virtual void Sort() override; 211 void SkipTable(SCTAB nSkip); 212 }; 213 214 struct ScMyDetectiveObj 215 { 216 ScAddress aPosition; 217 ScRange aSourceRange; 218 ScDetectiveObjType eObjType; 219 bool bHasError; 220 bool operator<(const ScMyDetectiveObj& rDetObj) const; 221 }; 222 223 typedef ::std::list< ScMyDetectiveObj > ScMyDetectiveObjList; 224 typedef ::std::vector< ScMyDetectiveObj > ScMyDetectiveObjVec; 225 226 class ScMyDetectiveObjContainer : public ScMyIteratorBase 227 { 228 private: 229 ScMyDetectiveObjList aDetectiveObjList; 230 protected: 231 virtual bool GetFirstAddress( ScAddress& rCellAddress ) override; 232 public: 233 ScMyDetectiveObjContainer(); 234 virtual ~ScMyDetectiveObjContainer() override; 235 236 void AddObject( 237 ScDetectiveObjType eObjType, 238 const SCTAB nSheet, 239 const ScAddress& rPosition, 240 const ScRange& rSourceRange, 241 bool bHasError ); 242 243 using ScMyIteratorBase::UpdateAddress; 244 virtual void SetCellData( ScMyCell& rMyCell ) override; 245 virtual void Sort() override; 246 void SkipTable(SCTAB nSkip); 247 }; 248 249 struct ScMyDetectiveOp 250 { 251 ScAddress aPosition; 252 ScDetOpType eOpType; 253 sal_Int32 nIndex; 254 bool operator<(const ScMyDetectiveOp& rDetOp) const; 255 }; 256 257 typedef ::std::list< ScMyDetectiveOp > ScMyDetectiveOpList; 258 typedef ::std::vector< ScMyDetectiveOp > ScMyDetectiveOpVec; 259 260 class ScMyDetectiveOpContainer : public ScMyIteratorBase 261 { 262 private: 263 ScMyDetectiveOpList aDetectiveOpList; 264 protected: 265 virtual bool GetFirstAddress( ScAddress& rCellAddress ) override; 266 public: 267 ScMyDetectiveOpContainer(); 268 virtual ~ScMyDetectiveOpContainer() override; 269 270 void AddOperation( ScDetOpType eOpType, const ScAddress& rPosition, sal_uInt32 nIndex ); 271 272 using ScMyIteratorBase::UpdateAddress; 273 virtual void SetCellData( ScMyCell& rMyCell ) override; 274 virtual void Sort() override; 275 void SkipTable(SCTAB nSkip); 276 }; 277 278 // contains data to export for the current cell position 279 struct ScMyCell 280 { 281 ScAddress maCellAddress; /// Use this instead of the UNO one. 282 283 ScAddress aCellAddress; 284 ScRange aMergeRange; 285 ScRange aMatrixRange; 286 287 ScMyAreaLink aAreaLink; 288 ScMyShapeList aShapeList; 289 ScMyDetectiveObjVec aDetectiveObjVec; 290 ScMyDetectiveOpVec aDetectiveOpVec; 291 292 ScPostIt* pNote; 293 294 sal_Int32 nValidationIndex; 295 sal_Int32 nStyleIndex; 296 sal_Int32 nNumberFormat; 297 css::table::CellContentType nType; 298 299 ScRefCellValue maBaseCell; 300 301 bool bIsAutoStyle; 302 303 bool bHasShape; 304 bool bIsMergedBase; 305 bool bIsCovered; 306 bool bHasAreaLink; 307 bool bHasEmptyDatabase; 308 bool bHasDetectiveObj; 309 bool bHasDetectiveOp; 310 311 bool bIsMatrixBase; 312 bool bIsMatrixCovered; 313 bool bHasAnnotation; 314 315 ScMyCell(); 316 }; 317 318 class ScMyNotEmptyCellsIterator 319 { 320 ScMyNotEmptyCellsIterator(const ScMyNotEmptyCellsIterator&) = delete; 321 const ScMyNotEmptyCellsIterator& operator=(const ScMyNotEmptyCellsIterator&) = delete; 322 323 css::uno::Reference<css::sheet::XSpreadsheet> xTable; 324 css::uno::Reference<css::table::XCellRange> xCellRange; 325 ScAddress aLastAddress; 326 327 ScMyShapesContainer* pShapes; 328 ScMyNoteShapesContainer* pNoteShapes; 329 ScMyEmptyDatabaseRangesContainer* pEmptyDatabaseRanges; 330 ScMyMergedRangesContainer* pMergedRanges; 331 ScMyAreaLinksContainer* pAreaLinks; 332 ScMyDetectiveObjContainer* pDetectiveObj; 333 ScMyDetectiveOpContainer* pDetectiveOp; 334 335 ScXMLExport& rExport; 336 std::unique_ptr<ScHorizontalCellIterator> mpCellItr; 337 338 SCCOL nCellCol; 339 SCROW nCellRow; 340 SCTAB nCurrentTable; 341 342 void UpdateAddress( ScAddress& rAddress ); 343 void SetCellData( ScMyCell& rMyCell, const ScAddress& rAddress ); 344 345 void HasAnnotation( ScMyCell& aCell ); 346 public: 347 explicit ScMyNotEmptyCellsIterator(ScXMLExport& rExport); 348 ~ScMyNotEmptyCellsIterator(); 349 350 void Clear(); 351 SetShapes(ScMyShapesContainer * pNewShapes)352 void SetShapes(ScMyShapesContainer* pNewShapes) 353 { pShapes = pNewShapes; } SetNoteShapes(ScMyNoteShapesContainer * pNewNoteShapes)354 void SetNoteShapes(ScMyNoteShapesContainer* pNewNoteShapes) 355 { pNoteShapes = pNewNoteShapes; } SetEmptyDatabaseRanges(ScMyEmptyDatabaseRangesContainer * pNewEmptyDatabaseRanges)356 void SetEmptyDatabaseRanges(ScMyEmptyDatabaseRangesContainer* pNewEmptyDatabaseRanges) 357 { pEmptyDatabaseRanges = pNewEmptyDatabaseRanges; } SetMergedRanges(ScMyMergedRangesContainer * pNewMergedRanges)358 void SetMergedRanges(ScMyMergedRangesContainer* pNewMergedRanges) 359 { pMergedRanges = pNewMergedRanges; } SetAreaLinks(ScMyAreaLinksContainer * pNewAreaLinks)360 void SetAreaLinks(ScMyAreaLinksContainer* pNewAreaLinks) 361 { pAreaLinks = pNewAreaLinks; } SetDetectiveObj(ScMyDetectiveObjContainer * pNewDetectiveObj)362 void SetDetectiveObj(ScMyDetectiveObjContainer* pNewDetectiveObj) 363 { pDetectiveObj = pNewDetectiveObj; } SetDetectiveOp(ScMyDetectiveOpContainer * pNewDetectiveOp)364 void SetDetectiveOp(ScMyDetectiveOpContainer* pNewDetectiveOp) 365 { pDetectiveOp = pNewDetectiveOp; } 366 367 void SetCurrentTable(const SCTAB nTable, 368 const css::uno::Reference<css::sheet::XSpreadsheet>& rxTable); 369 void SkipTable(SCTAB nSkip); 370 371 bool GetNext(ScMyCell& aCell, ScFormatRangeStyles* pCellStyles); 372 }; 373 374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 375