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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XIESCHER_HXX 21 #define INCLUDED_SC_SOURCE_FILTER_INC_XIESCHER_HXX 22 23 #include <filter/msfilter/msdffimp.hxx> 24 #include <vcl/graph.hxx> 25 #include "xlescher.hxx" 26 #include "xiroot.hxx" 27 #include <oox/ole/olehelper.hxx> 28 #include <rtl/ustring.hxx> 29 #include <svx/svdobj.hxx> 30 #include <map> 31 #include <memory> 32 #include <vector> 33 34 namespace com { namespace sun { namespace star { 35 namespace drawing { class XShape; } 36 namespace form { class XForm; } 37 } } } 38 39 namespace com { namespace sun { namespace star { namespace container { class XNameContainer; } } } } 40 41 class SdrObjList; 42 class ScfProgressBar; 43 class ScfPropertySet; 44 class ScRangeList; 45 class XclImpChart; 46 class XclImpDffConverter; 47 class XclImpDrawing; 48 49 // Drawing objects ============================================================ 50 51 class XclImpDrawObjBase; 52 typedef std::shared_ptr< XclImpDrawObjBase > XclImpDrawObjRef; 53 54 /** Base class for drawing objects (OBJ records). */ 55 class XclImpDrawObjBase : protected XclImpRoot 56 { 57 public: 58 explicit XclImpDrawObjBase( const XclImpRoot& rRoot ); 59 virtual ~XclImpDrawObjBase() override; 60 61 /** Reads the BIFF3 OBJ record, returns a new drawing object. */ 62 static XclImpDrawObjRef ReadObj3( const XclImpRoot& rRoot, XclImpStream& rStrm ); 63 /** Reads the BIFF4 OBJ record, returns a new drawing object. */ 64 static XclImpDrawObjRef ReadObj4( const XclImpRoot& rRoot, XclImpStream& rStrm ); 65 /** Reads the BIFF5 OBJ record, returns a new drawing object. */ 66 static XclImpDrawObjRef ReadObj5( const XclImpRoot& rRoot, XclImpStream& rStrm ); 67 /** Reads the BIFF8 OBJ record, returns a new drawing object. */ 68 static XclImpDrawObjRef ReadObj8( const XclImpRoot& rRoot, XclImpStream& rStrm ); 69 70 /** Sets whether this is an area object (then its width and height must be greater than 0). */ SetAreaObj(bool bAreaObj)71 void SetAreaObj( bool bAreaObj ) { mbAreaObj = bAreaObj; } 72 /** If set to true, a new SdrObject will be created while in DFF import. */ SetSimpleMacro(bool bMacro)73 void SetSimpleMacro( bool bMacro ) { mbSimpleMacro = bMacro; } 74 75 /** Sets the object anchor explicitly. */ 76 void SetAnchor( const XclObjAnchor& rAnchor ); 77 /** Sets shape data from DFF stream. */ 78 void SetDffData( 79 const DffObjData& rDffObjData, const OUString& rObjName, const OUString& rHyperlink, 80 bool bVisible, bool bAutoMargin ); 81 82 /** If set to false, the SdrObject will not be created, processed, or inserted into the draw page. */ SetProcessSdrObj(bool bProcess)83 void SetProcessSdrObj( bool bProcess ) { mbProcessSdr = bProcess; } 84 /** If set to false, the SdrObject will be created or processed, but not be inserted into the draw page. */ SetInsertSdrObj(bool bInsert)85 void SetInsertSdrObj( bool bInsert ) { mbInsertSdr = bInsert; } 86 /** If set to true, a new SdrObject will be created while in DFF import. */ SetCustomDffObj(bool bCustom)87 void SetCustomDffObj( bool bCustom ) { mbCustomDff = bCustom; } 88 89 /** Returns the sheet index and Excel object identifier from OBJ record. */ GetObjId() const90 sal_uInt16 GetObjId() const { return mnObjId; } 91 /** Returns the Excel object type from OBJ record. */ GetObjType() const92 sal_uInt16 GetObjType() const { return mnObjType; } 93 /** Returns the name of this object, may generate a default name. */ 94 virtual OUString GetObjName() const; 95 /** Returns associated macro name, if set, otherwise zero length string. */ GetMacroName() const96 const OUString& GetMacroName() const { return maMacroName; } 97 98 /** Returns the shape identifier used in the DFF stream. */ GetDffShapeId() const99 sal_uInt32 GetDffShapeId() const { return mnDffShapeId; } 100 /** Returns the shape flags from the DFF stream. */ GetDffFlags() const101 ShapeFlag GetDffFlags() const { return mnDffFlags; } 102 103 /** Returns true, if the object is hidden. */ IsHidden() const104 bool IsHidden() const { return mbHidden; } 105 /** Returns true, if the object is visible. */ IsVisible() const106 bool IsVisible() const { return mbVisible; } 107 /** Returns true, if the object is printable. */ IsPrintable() const108 bool IsPrintable() const { return mbPrintable; } 109 110 /** Returns the object anchor if existing, null otherwise. */ 111 const XclObjAnchor* GetAnchor() const; 112 /** Returns true, if the passed size is valid for this object. */ 113 bool IsValidSize( const tools::Rectangle& rAnchorRect ) const; 114 /** Returns the range in the sheet covered by this object. */ 115 ScRange GetUsedArea( SCTAB nScTab ) const; 116 117 /** Returns true, if the object is valid and will be processed. */ IsProcessSdrObj() const118 bool IsProcessSdrObj() const { return mbProcessSdr && !mbHidden; } 119 /** Returns true, if the SdrObject will be created or processed, but not be inserted into the draw page. */ IsInsertSdrObj() const120 bool IsInsertSdrObj() const { return mbInsertSdr; } 121 122 /** Returns the needed size on the progress bar (calls virtual DoGetProgressSize() function). */ 123 std::size_t GetProgressSize() const; 124 /** Creates and returns an SdrObject from the contained data. Caller takes ownership! */ 125 SdrObjectUniquePtr CreateSdrObject( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect, bool bIsDff ) const; 126 /** Additional processing for the passed SdrObject before insertion into 127 the drawing page (calls virtual DoPreProcessSdrObj() function). */ 128 void PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ); 129 /** Additional processing for the passed SdrObject after insertion into the 130 drawing page (calls virtual DoPostProcessSdrObj() function). */ 131 void PostProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const; GetTab() const132 SCTAB GetTab() const { return mnTab; } 133 134 protected: 135 /** Reads the object name in a BIFF5 OBJ record. */ 136 void ReadName5( XclImpStream& rStrm, sal_uInt16 nNameLen ); 137 /** Reads the macro link in a BIFF3 OBJ record. */ 138 void ReadMacro3( XclImpStream& rStrm, sal_uInt16 nMacroSize ); 139 /** Reads the macro link in a BIFF4 OBJ record. */ 140 void ReadMacro4( XclImpStream& rStrm, sal_uInt16 nMacroSize ); 141 /** Reads the macro link in a BIFF5 OBJ record. */ 142 void ReadMacro5( XclImpStream& rStrm, sal_uInt16 nMacroSize ); 143 /** Reads the contents of the ftMacro sub structure in an OBJ record. */ 144 void ReadMacro8( XclImpStream& rStrm ); 145 146 /** Converts the passed line formatting to the passed SdrObject. */ 147 void ConvertLineStyle( SdrObject& rSdrObj, const XclObjLineData& rLineData ) const; 148 /** Converts the passed fill formatting to the passed SdrObject. */ 149 void ConvertFillStyle( SdrObject& rSdrObj, const XclObjFillData& rFillData ) const; 150 /** Converts the passed frame flags to the passed SdrObject. */ 151 void ConvertFrameStyle( SdrObject& rSdrObj, sal_uInt16 nFrameFlags ) const; 152 153 /** Returns a solid line color from the passed line data struct. */ 154 Color GetSolidLineColor( const XclObjLineData& rLineData ) const; 155 /** Returns a solid fill color from the passed fill data struct. */ 156 Color GetSolidFillColor( const XclObjFillData& rFillData ) const; 157 158 /** Derived classes read the contents of the a BIFF3 OBJ record from the passed stream. */ 159 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ); 160 /** Derived classes read the contents of the a BIFF4 OBJ record from the passed stream. */ 161 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ); 162 /** Derived classes read the contents of the a BIFF5 OBJ record from the passed stream. */ 163 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ); 164 /** Derived classes read the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 165 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ); 166 167 /** Derived classes may return a progress bar size different from 1. */ 168 virtual std::size_t DoGetProgressSize() const; 169 /** Derived classes create and return a new SdrObject from the contained data. Caller takes ownership! */ 170 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const; 171 /** Derived classes may perform additional processing for the passed SdrObject before insertion. */ 172 virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const; 173 /** Derived classes may perform additional processing for the passed SdrObject after insertion. */ 174 virtual void DoPostProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const; 175 176 /** Notify that the document contains a macro event handler */ 177 void NotifyMacroEventRead(); 178 private: 179 /** Reads the contents of a BIFF3 OBJ record. */ 180 void ImplReadObj3( XclImpStream& rStrm ); 181 /** Reads the contents of a BIFF4 OBJ record. */ 182 void ImplReadObj4( XclImpStream& rStrm ); 183 /** Reads the contents of a BIFF5 OBJ record. */ 184 void ImplReadObj5( XclImpStream& rStrm ); 185 /** Reads the contents of a BIFF8 OBJ record. */ 186 void ImplReadObj8( XclImpStream& rStrm ); 187 188 private: 189 XclObjAnchor maAnchor; /// The position of the object in its parent. 190 sal_uInt16 mnObjId; /// The object identifier (unique per drawing). 191 SCTAB mnTab; /// Location of object 192 sal_uInt16 mnObjType; /// The Excel object type from OBJ record. 193 sal_uInt32 mnDffShapeId; /// Shape ID from DFF stream. 194 ShapeFlag mnDffFlags; /// Shape flags from DFF stream. 195 OUString maObjName; /// Name of the object. 196 OUString maMacroName; /// Name of an attached macro. 197 OUString maHyperlink; /// On-click hyperlink URL. 198 bool mbHasAnchor; /// true = maAnchor is initialized. 199 bool mbHidden; /// true = Object is hidden. 200 bool mbVisible; /// true = Object is visible. 201 bool mbPrintable; /// true = Object is printable. 202 bool mbAreaObj; /// true = Width and height must be greater than 0. 203 bool mbAutoMargin; /// true = Set automatic text margin. 204 bool mbSimpleMacro; /// true = Create simple macro link and hyperlink. 205 bool mbProcessSdr; /// true = Object is valid, do processing and insertion. 206 bool mbInsertSdr; /// true = Insert the SdrObject into draw page. 207 bool mbCustomDff; /// true = Recreate SdrObject in DFF import. 208 bool mbNotifyMacroEventRead; /// true == If we have already seen a macro event 209 }; 210 211 class XclImpDrawObjVector 212 { 213 private: 214 std::vector< XclImpDrawObjRef > mObjs; 215 216 public: XclImpDrawObjVector()217 explicit XclImpDrawObjVector() : mObjs() {} 218 begin() const219 std::vector< XclImpDrawObjRef >::const_iterator begin() const { return mObjs.begin(); } end() const220 std::vector< XclImpDrawObjRef >::const_iterator end() const { return mObjs.end(); } push_back(const XclImpDrawObjRef & rObj)221 void push_back(const XclImpDrawObjRef& rObj) { mObjs.push_back(rObj); } 222 223 /** Tries to insert the passed object into the last group or appends it. */ 224 void InsertGrouped( XclImpDrawObjRef const & xDrawObj ); 225 226 /** Returns the needed size on the progress bar for all contained objects. */ 227 std::size_t GetProgressSize() const; 228 }; 229 230 /** A placeholder object for unknown object types. */ 231 class XclImpPhObj : public XclImpDrawObjBase 232 { 233 public: 234 explicit XclImpPhObj( const XclImpRoot& rRoot ); 235 }; 236 237 /** A group object. */ 238 class XclImpGroupObj final : public XclImpDrawObjBase 239 { 240 public: 241 explicit XclImpGroupObj( const XclImpRoot& rRoot ); 242 243 /** Tries to insert the drawing object into this or a nested group. */ 244 bool TryInsert( XclImpDrawObjRef const & xDrawObj ); 245 246 private: 247 /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ 248 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 249 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 250 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 251 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 252 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 253 /** Returns a progress bar size that takes all group children into account. */ 254 virtual std::size_t DoGetProgressSize() const override; 255 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 256 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 257 258 XclImpDrawObjVector maChildren; /// Grouped objects. 259 sal_uInt16 mnFirstUngrouped; /// Object identifier of first object not grouped into this group. 260 }; 261 262 /** A line object. */ 263 class XclImpLineObj final : public XclImpDrawObjBase 264 { 265 public: 266 explicit XclImpLineObj( const XclImpRoot& rRoot ); 267 268 private: 269 /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ 270 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 271 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 272 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 273 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 274 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 275 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 276 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 277 278 XclObjLineData maLineData; /// BIFF5 line formatting. 279 sal_uInt16 mnArrows; /// Line arrows. 280 sal_uInt8 mnStartPoint; /// Starting point. 281 }; 282 283 /** A rectangle or oval object. */ 284 class XclImpRectObj : public XclImpDrawObjBase 285 { 286 public: 287 explicit XclImpRectObj( const XclImpRoot& rRoot ); 288 289 protected: 290 /** Reads fil data, line data, and frame flags. */ 291 void ReadFrameData( XclImpStream& rStrm ); 292 293 /** Converts fill formatting, line formatting, and frame style. */ 294 void ConvertRectStyle( SdrObject& rSdrObj ) const; 295 296 /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ 297 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 298 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 299 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 300 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 301 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 302 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 303 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 304 305 protected: 306 XclObjFillData maFillData; /// BIFF5 fill formatting. 307 XclObjLineData maLineData; /// BIFF5 line formatting. 308 sal_uInt16 mnFrameFlags; /// Additional flags. 309 }; 310 311 /** An oval object. */ 312 class XclImpOvalObj : public XclImpRectObj 313 { 314 public: 315 explicit XclImpOvalObj( const XclImpRoot& rRoot ); 316 317 protected: 318 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 319 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 320 }; 321 322 /** An arc object. */ 323 class XclImpArcObj final : public XclImpDrawObjBase 324 { 325 public: 326 explicit XclImpArcObj( const XclImpRoot& rRoot ); 327 328 private: 329 /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ 330 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 331 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 332 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 333 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 334 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 335 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 336 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 337 338 XclObjFillData maFillData; /// BIFF5 fill formatting. 339 XclObjLineData maLineData; /// BIFF5 line formatting. 340 sal_uInt8 mnQuadrant; /// Visible quadrant of the circle. 341 }; 342 343 /** A polygon object. */ 344 class XclImpPolygonObj final : public XclImpRectObj 345 { 346 public: 347 explicit XclImpPolygonObj( const XclImpRoot& rRoot ); 348 349 private: 350 /** Reads the COORDLIST record following the OBJ record. */ 351 void ReadCoordList( XclImpStream& rStrm ); 352 353 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 354 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 355 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 356 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 357 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 358 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 359 360 typedef std::vector< Point > PointVector; 361 PointVector maCoords; /// Coordinates relative to bounding rectangle. 362 sal_uInt16 mnPolyFlags; /// Additional flags. 363 sal_uInt16 mnPointCount; /// Polygon point count. 364 }; 365 366 struct XclImpObjTextData 367 { 368 XclObjTextData maData; /// BIFF5 text data. 369 XclImpStringRef mxString; /// Plain or rich string. 370 371 /** Reads a byte string from the passed stream. */ 372 void ReadByteString( XclImpStream& rStrm ); 373 /** Reads text formatting from the passed stream. */ 374 void ReadFormats( XclImpStream& rStrm ); 375 }; 376 377 /** A drawing object supporting text contents. Used for all simple objects in BIFF8. */ 378 class XclImpTextObj : public XclImpRectObj 379 { 380 public: 381 explicit XclImpTextObj( const XclImpRoot& rRoot ); 382 383 /** Stores the passed textbox data. */ SetTextData(const XclImpObjTextData & rTextData)384 void SetTextData( const XclImpObjTextData& rTextData ) { maTextData = rTextData; } 385 386 protected: 387 /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ 388 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 389 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 390 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 391 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 392 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 393 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 394 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 395 /** Inserts the contained text data at the passed object. */ 396 virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const override; 397 398 protected: 399 XclImpObjTextData maTextData; /// Textbox data from BIFF5 OBJ or BIFF8 TXO record. 400 }; 401 402 /** A chart object. This is the drawing object wrapper for the chart data. */ 403 class XclImpChartObj : public XclImpRectObj 404 { 405 public: 406 /** @param bOwnTab True = chart is on an own sheet; false = chart is an embedded object. */ 407 explicit XclImpChartObj( const XclImpRoot& rRoot, bool bOwnTab = false ); 408 409 /** Reads the complete chart substream (BOF/EOF block). */ 410 void ReadChartSubStream( XclImpStream& rStrm ); 411 412 protected: 413 /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ 414 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 415 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 416 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 417 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 418 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 419 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 420 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 421 /** Returns the needed size on the progress bar. */ 422 virtual std::size_t DoGetProgressSize() const override; 423 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 424 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 425 /** Converts the chart document. */ 426 virtual void DoPostProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const override; 427 428 private: 429 /** Calculates the object anchor of a sheet chart (chart fills one page). */ 430 void FinalizeTabChart(); 431 432 private: 433 typedef std::shared_ptr< XclImpChart > XclImpChartRef; 434 435 XclImpChartRef mxChart; /// The chart itself (BOF/EOF substream data). 436 bool const mbOwnTab; /// true = own sheet; false = embedded object. 437 }; 438 439 /** A note object, which is a specialized text box object. */ 440 class XclImpNoteObj : public XclImpTextObj 441 { 442 public: 443 explicit XclImpNoteObj( const XclImpRoot& rRoot ); 444 445 /** Sets note flags and the note position in the Calc sheet. */ 446 void SetNoteData( const ScAddress& rScPos, sal_uInt16 nNoteFlags ); 447 448 protected: 449 /** Inserts the note into the document, sets visibility. */ 450 virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const override; 451 452 private: 453 ScAddress maScPos; /// Cell position of the note object. 454 sal_uInt16 mnNoteFlags; /// Flags from NOTE record. 455 }; 456 457 /** Helper base class for TBX and OCX form controls to manage spreadsheet links. */ 458 class XclImpControlHelper 459 { 460 public: 461 explicit XclImpControlHelper( const XclImpRoot& rRoot, XclCtrlBindMode eBindMode ); 462 virtual ~XclImpControlHelper(); 463 464 /** Returns true, if a linked cell address is present. */ HasCellLink() const465 bool HasCellLink() const { return mxCellLink != nullptr; } 466 467 /** Returns the SdrObject from the passed control shape and sets the bounding rectangle. */ 468 SdrObjectUniquePtr CreateSdrObjectFromShape( 469 const css::uno::Reference< css::drawing::XShape >& rxShape, 470 const tools::Rectangle& rAnchorRect ) const; 471 472 /** Sets additional properties to the form control model, calls virtual DoProcessControl(). */ 473 void ProcessControl( const XclImpDrawObjBase& rDrawObj ) const; 474 475 protected: 476 /** Reads the formula for the linked cell from the current position of the stream. */ 477 void ReadCellLinkFormula( XclImpStream& rStrm, bool bWithBoundSize ); 478 /** Reads the formula for the source range from the current position of the stream. */ 479 void ReadSourceRangeFormula( XclImpStream& rStrm, bool bWithBoundSize ); 480 481 /** Derived classes will set additional properties for the current form control. */ 482 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const; 483 484 void ApplySheetLinkProps() const; 485 mutable css::uno::Reference< css::drawing::XShape > 486 mxShape; /// The UNO wrapper of the control shape. 487 std::shared_ptr< ScAddress > mxCellLink; /// Linked cell in the Calc document. 488 private: 489 /** Reads a list of cell ranges from a formula at the current stream position. */ 490 void ReadRangeList( ScRangeList& rScRanges, XclImpStream& rStrm ); 491 /** Reads leading formula size and a list of cell ranges from a formula if the leading size is not zero. */ 492 void ReadRangeList( ScRangeList& rScRanges, XclImpStream& rStrm, bool bWithBoundSize ); 493 494 private: 495 const XclImpRoot& mrRoot; /// Not derived from XclImpRoot to allow multiple inheritance. 496 std::shared_ptr< ScRange > mxSrcRange; /// Source data range in the Calc document. 497 XclCtrlBindMode const meBindMode; /// Value binding mode. 498 }; 499 500 /** Base class for textbox based form controls. */ 501 class XclImpTbxObjBase : public XclImpTextObj, public XclImpControlHelper 502 { 503 public: 504 explicit XclImpTbxObjBase( const XclImpRoot& rRoot ); 505 506 /** Sets line and fill formatting from the passed DFF property set. */ 507 void SetDffProperties( const DffPropSet& rDffPropSet ); 508 509 /** Returns the service name of the control component to be created. */ GetServiceName() const510 OUString GetServiceName() const { return DoGetServiceName(); } 511 /** Fills the passed macro event descriptor. */ 512 bool FillMacroDescriptor( 513 css::script::ScriptEventDescriptor& rDescriptor ) const; 514 515 protected: 516 /** Sets control text formatting. */ 517 void ConvertFont( ScfPropertySet& rPropSet ) const; 518 /** Sets control label and text formatting. */ 519 void ConvertLabel( ScfPropertySet& rPropSet ) const; 520 521 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 522 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 523 /** Additional processing on the SdrObject, calls new virtual function DoProcessControl(). */ 524 virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const override; 525 526 /** Derived classes return the service name of the control component to be created. */ 527 virtual OUString DoGetServiceName() const = 0; 528 /** Derived classes return the type of the macro event to be created. */ 529 virtual XclTbxEventType DoGetEventType() const = 0; 530 }; 531 532 /** A button control. */ 533 class XclImpButtonObj : public XclImpTbxObjBase 534 { 535 public: 536 explicit XclImpButtonObj( const XclImpRoot& rRoot ); 537 538 protected: 539 /** Sets additional properties for the current form control. */ 540 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 541 /** Returns the service name of the control component to be created. */ 542 virtual OUString DoGetServiceName() const override; 543 /** Returns the type of the macro event to be created. */ 544 virtual XclTbxEventType DoGetEventType() const override; 545 }; 546 547 /** A checkbox control. */ 548 class XclImpCheckBoxObj : public XclImpTbxObjBase 549 { 550 public: 551 explicit XclImpCheckBoxObj( const XclImpRoot& rRoot ); 552 553 protected: 554 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 555 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 556 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 557 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 558 /** Sets additional properties for the current form control. */ 559 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 560 /** Returns the service name of the control component to be created. */ 561 virtual OUString DoGetServiceName() const override; 562 /** Returns the type of the macro event to be created. */ 563 virtual XclTbxEventType DoGetEventType() const override; 564 565 protected: 566 sal_uInt16 mnState; 567 sal_uInt16 mnCheckBoxFlags; 568 }; 569 570 /** An option button control. */ 571 class XclImpOptionButtonObj final : public XclImpCheckBoxObj 572 { 573 public: 574 explicit XclImpOptionButtonObj( const XclImpRoot& rRoot ); 575 576 private: 577 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 578 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 579 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 580 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 581 /** Sets additional properties for the current form control. */ 582 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 583 /** Returns the service name of the control component to be created. */ 584 virtual OUString DoGetServiceName() const override; 585 /** Returns the type of the macro event to be created. */ 586 virtual XclTbxEventType DoGetEventType() const override; 587 588 sal_uInt16 mnNextInGroup; /// Next option button in a group. 589 sal_uInt16 mnFirstInGroup; /// 1 = Button is the first in a group. 590 }; 591 592 /** A label control. */ 593 class XclImpLabelObj : public XclImpTbxObjBase 594 { 595 public: 596 explicit XclImpLabelObj( const XclImpRoot& rRoot ); 597 598 protected: 599 /** Sets additional properties for the current form control. */ 600 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 601 /** Returns the service name of the control component to be created. */ 602 virtual OUString DoGetServiceName() const override; 603 /** Returns the type of the macro event to be created. */ 604 virtual XclTbxEventType DoGetEventType() const override; 605 }; 606 607 /** A groupbox control. */ 608 class XclImpGroupBoxObj final : public XclImpTbxObjBase 609 { 610 public: 611 explicit XclImpGroupBoxObj( const XclImpRoot& rRoot ); 612 613 private: 614 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 615 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 616 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 617 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 618 /** Sets additional properties for the current form control. */ 619 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 620 /** Returns the service name of the control component to be created. */ 621 virtual OUString DoGetServiceName() const override; 622 /** Returns the type of the macro event to be created. */ 623 virtual XclTbxEventType DoGetEventType() const override; 624 625 sal_uInt16 mnGroupBoxFlags; 626 }; 627 628 /** A dialog control. */ 629 class XclImpDialogObj : public XclImpTbxObjBase 630 { 631 public: 632 explicit XclImpDialogObj( const XclImpRoot& rRoot ); 633 634 protected: 635 /** Sets additional properties for the current form control. */ 636 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 637 /** Returns the service name of the control component to be created. */ 638 virtual OUString DoGetServiceName() const override; 639 /** Returns the type of the macro event to be created. */ 640 virtual XclTbxEventType DoGetEventType() const override; 641 }; 642 643 /** An edit control. */ 644 class XclImpEditObj final : public XclImpTbxObjBase 645 { 646 public: 647 explicit XclImpEditObj( const XclImpRoot& rRoot ); 648 649 private: 650 /** REturns true, if the field type is numeric. */ 651 bool IsNumeric() const; 652 653 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 654 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 655 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 656 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 657 /** Sets additional properties for the current form control. */ 658 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 659 /** Returns the service name of the control component to be created. */ 660 virtual OUString DoGetServiceName() const override; 661 /** Returns the type of the macro event to be created. */ 662 virtual XclTbxEventType DoGetEventType() const override; 663 664 sal_uInt16 mnContentType; 665 sal_uInt16 mnMultiLine; 666 sal_uInt16 mnScrollBar; 667 sal_uInt16 mnListBoxObjId; 668 }; 669 670 /** Base class of scrollable form controls (spin button, scrollbar, listbox, dropdown). */ 671 class XclImpTbxObjScrollableBase : public XclImpTbxObjBase 672 { 673 public: 674 explicit XclImpTbxObjScrollableBase( const XclImpRoot& rRoot ); 675 676 protected: 677 /** Reads scrollbar data. */ 678 void ReadSbs( XclImpStream& rStrm ); 679 680 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 681 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 682 683 protected: 684 sal_uInt16 mnValue; 685 sal_uInt16 mnMin; 686 sal_uInt16 mnMax; 687 sal_uInt16 mnStep; 688 sal_uInt16 mnPageStep; 689 sal_uInt16 mnOrient; 690 sal_uInt16 mnThumbWidth; 691 sal_uInt16 mnScrollFlags; 692 }; 693 694 /** A spinbutton control. */ 695 class XclImpSpinButtonObj : public XclImpTbxObjScrollableBase 696 { 697 public: 698 explicit XclImpSpinButtonObj( const XclImpRoot& rRoot ); 699 700 protected: 701 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 702 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 703 /** Sets additional properties for the current form control. */ 704 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 705 /** Returns the service name of the control component to be created. */ 706 virtual OUString DoGetServiceName() const override; 707 /** Returns the type of the macro event to be created. */ 708 virtual XclTbxEventType DoGetEventType() const override; 709 }; 710 711 /** A scrollbar control. */ 712 class XclImpScrollBarObj : public XclImpTbxObjScrollableBase 713 { 714 public: 715 explicit XclImpScrollBarObj( const XclImpRoot& rRoot ); 716 717 protected: 718 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 719 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 720 /** Sets additional properties for the current form control. */ 721 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 722 /** Returns the service name of the control component to be created. */ 723 virtual OUString DoGetServiceName() const override; 724 /** Returns the type of the macro event to be created. */ 725 virtual XclTbxEventType DoGetEventType() const override; 726 }; 727 728 /** Base class for list controls (listbox, dropdown). */ 729 class XclImpTbxObjListBase : public XclImpTbxObjScrollableBase 730 { 731 public: 732 explicit XclImpTbxObjListBase( const XclImpRoot& rRoot ); 733 734 protected: 735 /** Reads common listbox settings. */ 736 void ReadLbsData( XclImpStream& rStrm ); 737 /** Sets common listbox/dropdown formatting attributes. */ 738 void SetBoxFormatting( ScfPropertySet& rPropSet ) const; 739 740 protected: 741 sal_uInt16 mnEntryCount; 742 sal_uInt16 mnSelEntry; 743 sal_uInt16 mnListFlags; 744 sal_uInt16 mnEditObjId; 745 bool mbHasDefFontIdx; 746 }; 747 748 /** A listbox control. */ 749 class XclImpListBoxObj final : public XclImpTbxObjListBase 750 { 751 public: 752 explicit XclImpListBoxObj( const XclImpRoot& rRoot ); 753 754 private: 755 /** Reads listbox settings and selection. */ 756 void ReadFullLbsData( XclImpStream& rStrm, std::size_t nRecLeft ); 757 758 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 759 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 760 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 761 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 762 /** Sets additional properties for the current form control. */ 763 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 764 /** Returns the service name of the control component to be created. */ 765 virtual OUString DoGetServiceName() const override; 766 /** Returns the type of the macro event to be created. */ 767 virtual XclTbxEventType DoGetEventType() const override; 768 769 ScfUInt8Vec maSelection; 770 }; 771 772 /** A dropdown listbox control. */ 773 class XclImpDropDownObj final : public XclImpTbxObjListBase 774 { 775 public: 776 explicit XclImpDropDownObj( const XclImpRoot& rRoot ); 777 778 private: 779 /** Returns the type of the dropdown control. */ 780 sal_uInt16 GetDropDownType() const; 781 782 /** Reads dropdown box settings. */ 783 void ReadFullLbsData( XclImpStream& rStrm ); 784 785 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 786 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 787 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 788 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 789 /** Sets additional properties for the current form control. */ 790 virtual void DoProcessControl( ScfPropertySet& rPropSet ) const override; 791 /** Returns the service name of the control component to be created. */ 792 virtual OUString DoGetServiceName() const override; 793 /** Returns the type of the macro event to be created. */ 794 virtual XclTbxEventType DoGetEventType() const override; 795 796 sal_uInt16 mnLeft; 797 sal_uInt16 mnTop; 798 sal_uInt16 mnRight; 799 sal_uInt16 mnBottom; 800 sal_uInt16 mnDropDownFlags; 801 sal_uInt16 mnLineCount; 802 sal_uInt16 mnMinWidth; 803 }; 804 805 /** A picture, an embedded or linked OLE object, or an OCX form control. */ 806 class XclImpPictureObj : public XclImpRectObj, public XclImpControlHelper 807 { 808 public: 809 explicit XclImpPictureObj( const XclImpRoot& rRoot ); 810 /** Returns the ObjectName - can use non-obvious lookup for override in the associated vba document module stream**/ 811 virtual OUString GetObjName() const override; 812 /** Returns the graphic imported from the IMGDATA record. */ GetGraphic() const813 const Graphic& GetGraphic() const { return maGraphic; } 814 815 /** Returns true, if the OLE object will be shown as symbol. */ IsSymbol() const816 bool IsSymbol() const { return mbSymbol; } 817 /** Returns the storage name for the OLE object. */ 818 OUString GetOleStorageName() const; 819 820 /** Returns true, if this object is an OCX form control. */ IsOcxControl() const821 bool IsOcxControl() const { return mbEmbedded && mbControl && mbUseCtlsStrm; } 822 /** Returns the position in the 'Ctls' stream for additional form control data. */ GetCtlsStreamPos() const823 std::size_t GetCtlsStreamPos() const { return mnCtlsStrmPos; } 824 /** Returns the size in the 'Ctls' stream for additional form control data. */ GetCtlsStreamSize() const825 std::size_t GetCtlsStreamSize() const { return mnCtlsStrmSize; } 826 827 protected: 828 /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ 829 virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 830 /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ 831 virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize ) override; 832 /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ 833 virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ) override; 834 /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ 835 virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ) override; 836 /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */ 837 virtual SdrObjectUniquePtr DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const override; 838 /** Override to do additional processing on the SdrObject. */ 839 virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const override; 840 841 private: 842 /** Reads and sets the picture flags from a BIFF3-BIFF5 OBJ picture record. */ 843 void ReadFlags3( XclImpStream& rStrm ); 844 /** Reads the contents of the OBJFLAGS subrecord. */ 845 void ReadFlags8( XclImpStream& rStrm ); 846 /** Reads the contents of the OBJPICTFMLA subrecord. */ 847 void ReadPictFmla( XclImpStream& rStrm, sal_uInt16 nLinkSize ); 848 849 private: 850 Graphic maGraphic; /// Picture or OLE placeholder graphic. 851 OUString maClassName; /// Class name of embedded OLE object. 852 sal_uInt32 mnStorageId; /// Identifier of the storage for this object. 853 std::size_t mnCtlsStrmPos; /// Position in 'Ctls' stream for this control. 854 std::size_t mnCtlsStrmSize; /// Size in 'Ctls' stream for this control. 855 bool mbEmbedded; /// true = Embedded OLE object. 856 bool mbLinked; /// true = Linked OLE object. 857 bool mbSymbol; /// true = Show as symbol. 858 bool mbControl; /// true = Form control, false = OLE object. 859 bool mbUseCtlsStrm; /// true = Form control data in 'Ctls' stream, false = Own storage. 860 }; 861 862 // DFF stream conversion ====================================================== 863 864 /** The solver container collects all connector rules for connected objects. */ 865 class XclImpSolverContainer : public SvxMSDffSolverContainer 866 { 867 public: 868 869 /** Inserts information about a new SdrObject. */ 870 void InsertSdrObjectInfo( SdrObject& rSdrObj, sal_uInt32 nDffShapeId, ShapeFlag nDffFlags ); 871 /** Removes information of an SdrObject (and all child objects if it is a group). */ 872 void RemoveSdrObjectInfo( SdrObject& rSdrObj ); 873 874 /** Inserts the SdrObject pointers into all connector rules. */ 875 void UpdateConnectorRules(); 876 /** Removes all contained connector rules. */ 877 void RemoveConnectorRules(); 878 879 private: 880 /** Updates the data of a connected shape in a connector rule. */ 881 void UpdateConnection( sal_uInt32 nDffShapeId, SdrObject*& rpSdrObj, ShapeFlag* pnDffFlags = nullptr ); 882 883 private: 884 /** Stores data about an SdrObject processed during import. */ 885 struct XclImpSdrInfo 886 { 887 SdrObject* mpSdrObj; /// Pointer to an SdrObject. 888 ShapeFlag mnDffFlags; /// Shape flags from DFF stream. XclImpSdrInfoXclImpSolverContainer::XclImpSdrInfo889 explicit XclImpSdrInfo() : mpSdrObj( nullptr ), mnDffFlags( ShapeFlag::NONE ) {} SetXclImpSolverContainer::XclImpSdrInfo890 void Set( SdrObject* pSdrObj, ShapeFlag nDffFlags ) 891 { mpSdrObj = pSdrObj; mnDffFlags = nDffFlags; } 892 }; 893 typedef std::map< sal_uInt32, XclImpSdrInfo > XclImpSdrInfoMap; 894 typedef std::map< SdrObject*, sal_uInt32 > XclImpSdrObjMap; 895 896 XclImpSdrInfoMap maSdrInfoMap; /// Maps shape IDs to SdrObjects and flags. 897 XclImpSdrObjMap maSdrObjMap; /// Maps SdrObjects to shape IDs. 898 }; 899 900 /** Simple implementation of the SVX DFF manager. Implements resolving palette 901 colors. Used by XclImpDffPropSet (as is), extended by XclImpDffConverter. 902 */ 903 class XclImpSimpleDffConverter : public SvxMSDffManager, protected XclImpRoot 904 { 905 public: 906 explicit XclImpSimpleDffConverter( const XclImpRoot& rRoot, SvStream& rDffStrm ); 907 virtual ~XclImpSimpleDffConverter() override; 908 909 protected: 910 /** Returns a color from the Excel color palette. */ 911 virtual bool GetColorFromPalette( sal_uInt16 nIndex, Color& rColor ) const override; 912 }; 913 914 /** This is the central instance for converting binary DFF data into shape 915 objects. Used for all sheet shapes and shapes embedded in chart objects. 916 917 The class derives from SvxMSDffManager and SvxMSConvertOCXControls and 918 contains core implementation of DFF stream import and OCX form control 919 import. 920 */ 921 class XclImpDffConverter : public XclImpSimpleDffConverter, private oox::ole::MSConvertOCXControls 922 { 923 public: 924 explicit XclImpDffConverter( const XclImpRoot& rRoot, SvStream& rDffStrm ); 925 virtual ~XclImpDffConverter() override; 926 927 /** Initializes the internal progress bar with the passed size and starts it. */ 928 void StartProgressBar( std::size_t nProgressSize ); 929 /** Increase the progress bar by the passed value. */ 930 void Progress( std::size_t nDelta = 1 ); 931 932 /** Initially called before the objects of the passed drawing manager are converted. */ 933 void InitializeDrawing( XclImpDrawing& rDrawing, SdrModel& rSdrModel, SdrPage& rSdrPage ); 934 /** Processes BIFF5 drawing objects without DFF data, inserts into the passed object list. */ 935 void ProcessObject( SdrObjList& rObjList, XclImpDrawObjBase& rDrawObj ); 936 /** Processes all objects in the passed list. */ 937 void ProcessDrawing( const XclImpDrawObjVector& rDrawObjs ); 938 /** Processes a drawing container in the passed DFF stream, converts all objects. */ 939 void ProcessDrawing( SvStream& rDffStrm ); 940 /** Finally called after the objects of the passed drawing manager have been converted. */ 941 void FinalizeDrawing(); 942 943 /** Creates the SdrObject for the passed Excel TBX form control object. */ 944 SdrObjectUniquePtr CreateSdrObject( const XclImpTbxObjBase& rTbxObj, const tools::Rectangle& rAnchorRect ); 945 /** Creates the SdrObject for the passed Excel OLE object or OCX form control object. */ 946 SdrObjectUniquePtr CreateSdrObject( const XclImpPictureObj& rPicObj, const tools::Rectangle& rAnchorRect ); 947 948 /** Returns true, if the conversion of OLE objects is supported. */ 949 bool SupportsOleObjects() const; 950 /** Returns the default text margin in drawing layer units. */ GetDefaultTextMargin() const951 sal_Int32 GetDefaultTextMargin() const { return mnDefTextMargin; } 952 953 private: 954 // virtual functions of SvxMSDffManager 955 956 /** Reads the client anchor from the DFF stream and sets it at the correct object. */ 957 virtual void ProcessClientAnchor2( 958 SvStream& rDffStrm, 959 DffRecordHeader& rHeader, 960 DffObjData& rObjData ) override; 961 /** Processes a DFF object, reads properties from DFF stream. */ 962 virtual SdrObject* ProcessObj( 963 SvStream& rDffStrm, 964 DffObjData& rDffObjData, 965 SvxMSDffClientData& rClientData, 966 tools::Rectangle& rTextRect, 967 SdrObject* pOldSdrObj ) override; 968 969 /** Finalize a DFF object, sets anchor after nested objs have been loaded. */ 970 virtual SdrObject* FinalizeObj( 971 DffObjData& rDffObjData, 972 SdrObject* pOldSdrObj ) override; 973 974 // virtual functions of SvxMSConvertOCXControls 975 976 /** Inserts the passed control rxFComp into the form. Needs call to SetCurrentForm() before. */ 977 virtual bool InsertControl( 978 const css::uno::Reference< 979 css::form::XFormComponent >& rxFormComp, 980 const css::awt::Size& rSize, 981 css::uno::Reference< 982 css::drawing::XShape >* pxShape, 983 bool bFloatingCtrl ) override; 984 985 private: 986 /** Data per registered drawing manager, will be stacked for recursive calls. */ 987 struct XclImpDffConvData 988 { 989 XclImpDrawing& mrDrawing; /// Current drawing container with all drawing objects. 990 SdrModel& mrSdrModel; /// The SdrModel of the drawing manager. 991 SdrPage& mrSdrPage; /// The SdrPage of the drawing manager. 992 XclImpSolverContainer maSolverCont; /// The solver container for connector rules. 993 css::uno::Reference< css::form::XForm > 994 mxCtrlForm; /// Controls form of current drawing page. 995 sal_Int32 mnLastCtrlIndex; /// Last insertion index of a form control (for macro events). 996 bool mbHasCtrlForm; /// True = mxCtrlForm is initialized (but maybe still null). 997 998 explicit XclImpDffConvData( XclImpDrawing& rDrawing, 999 SdrModel& rSdrModel, SdrPage& rSdrPage ); 1000 }; 1001 1002 /** Returns the current drawing manager data struct from top of the stack. */ 1003 XclImpDffConvData& GetConvData(); 1004 /** Returns the current drawing manager data struct from top of the stack. */ 1005 const XclImpDffConvData& GetConvData() const; 1006 1007 /** Reads contents of a hyperlink property and returns the extracted URL. */ 1008 OUString ReadHlinkProperty( SvStream& rDffStrm ) const; 1009 1010 /** Processes a drawing container (all drawing data of a sheet). */ 1011 bool ProcessDgContainer( SvStream& rDffStrm, const DffRecordHeader& rDgHeader ); 1012 /** Processes the global shape group container (all shapes of a sheet). */ 1013 bool ProcessShGrContainer( SvStream& rDffStrm, const DffRecordHeader& rShGrHeader ); 1014 /** Processes the solver container (connectors of a sheet). */ 1015 bool ProcessSolverContainer( SvStream& rDffStrm, const DffRecordHeader& rSolverHeader ); 1016 /** Processes a shape or shape group container (one top-level shape). */ 1017 bool ProcessShContainer( SvStream& rDffStrm, const DffRecordHeader& rShHeader ); 1018 1019 /** Inserts the passed SdrObject into the document. This function takes ownership of pSdrObj! */ 1020 void InsertSdrObject( SdrObjList& rObjList, const XclImpDrawObjBase& rDrawObj, SdrObject* pSdrObj ); 1021 /** Initializes the mxCtrlForm referring to the standard controls form. */ 1022 void InitControlForm(); 1023 /** Notify that this document contains a macro event handler */ 1024 void NotifyMacroEventRead(); 1025 1026 private: 1027 typedef std::shared_ptr< ScfProgressBar > ScfProgressBarRef; 1028 typedef std::shared_ptr< XclImpDffConvData > XclImpDffConvDataRef; 1029 typedef std::vector< XclImpDffConvDataRef > XclImpDffConvDataStack; 1030 1031 tools::SvRef<SotStorageStream> mxCtlsStrm; /// The 'Ctls' stream for OCX form controls. 1032 ScfProgressBarRef mxProgress; /// The progress bar used in ProcessObj(). 1033 XclImpDffConvDataStack maDataStack; /// Stack for registered drawing managers. 1034 sal_uInt32 mnOleImpFlags; /// Application OLE import settings. 1035 sal_Int32 mnDefTextMargin; /// Default margin in text boxes. 1036 bool mbNotifyMacroEventRead; /// If we have already seen a macro event 1037 }; 1038 1039 // Drawing manager ============================================================ 1040 1041 /** Base class for a container for all objects on a drawing (spreadsheet or 1042 embedded chart object). */ 1043 class XclImpDrawing : protected XclImpRoot 1044 { 1045 public: 1046 explicit XclImpDrawing( const XclImpRoot& rRoot, bool bOleObjects ); 1047 virtual ~XclImpDrawing() override; 1048 1049 /** Reads and returns a bitmap from the IMGDATA record. */ 1050 static Graphic ReadImgData( const XclImpRoot& rRoot, XclImpStream& rStrm ); 1051 1052 /** Reads a plain OBJ record (without leading DFF data). */ 1053 void ReadObj( XclImpStream& rStrm ); 1054 /** Reads the MSODRAWING or MSODRAWINGSELECTION record. */ 1055 void ReadMsoDrawing( XclImpStream& rStrm ); 1056 1057 /** Returns true, if the conversion of OLE objects is supported. */ SupportsOleObjects() const1058 bool SupportsOleObjects() const { return mbOleObjs; } 1059 /** Finds the OBJ record data related to the DFF shape at the passed position. */ 1060 XclImpDrawObjRef FindDrawObj( const DffRecordHeader& rHeader ) const; 1061 /** Finds the OBJ record data specified by the passed object identifier. */ 1062 XclImpDrawObjRef FindDrawObj( sal_uInt16 nObjId ) const; 1063 /** Finds the textbox data related to the DFF shape at the passed position. */ 1064 const XclImpObjTextData* FindTextData( const DffRecordHeader& rHeader ) const; 1065 1066 /** Sets the object with the passed identification to be skipped on import. */ 1067 void SetSkipObj( sal_uInt16 nObjId ); 1068 /** Returns the size of the progress bar shown while processing all objects. */ 1069 std::size_t GetProgressSize() const; 1070 1071 /** Derived classes calculate the resulting rectangle of the passed anchor. */ 1072 virtual tools::Rectangle CalcAnchorRect( const XclObjAnchor& rAnchor, bool bDffAnchor ) const = 0; 1073 /** Called whenever an object has been inserted into the draw page. */ 1074 virtual void OnObjectInserted( const XclImpDrawObjBase& rDrawObj ) = 0; 1075 1076 protected: 1077 /** Appends a new drawing object to the list of raw objects (without DFF data). */ 1078 void AppendRawObject( const XclImpDrawObjRef& rxDrawObj ); 1079 /** Converts all objects and inserts them into the current drawing page. */ 1080 void ImplConvertObjects( XclImpDffConverter& rDffConv, SdrModel& rSdrModel, SdrPage& rSdrPage ); 1081 1082 private: 1083 /** Reads and returns a bitmap from WMF/PICT format. */ 1084 static void ReadWmf( Graphic& rGraphic, XclImpStream& rStrm ); 1085 /** Reads and returns a bitmap from BMP format. */ 1086 static void ReadBmp( Graphic& rGraphic, const XclImpRoot& rRoot, XclImpStream& rStrm ); 1087 1088 /** Reads contents of a DFF record and append data to internal DFF stream. */ 1089 void ReadDffRecord( XclImpStream& rStrm ); 1090 /** Reads a BIFF8 OBJ record following an MSODRAWING record. */ 1091 void ReadObj8( XclImpStream& rStrm ); 1092 /** Reads the TXO record and following CONTINUE records containing string and formatting. */ 1093 void ReadTxo( XclImpStream& rStrm ); 1094 1095 private: 1096 typedef std::map< std::size_t, XclImpDrawObjRef > XclImpObjMap; 1097 typedef std::map< sal_uInt16, XclImpDrawObjRef > XclImpObjMapById; 1098 typedef std::shared_ptr< XclImpObjTextData > XclImpObjTextRef; 1099 typedef std::map< std::size_t, XclImpObjTextRef > XclImpObjTextMap; 1100 1101 XclImpDrawObjVector maRawObjs; /// BIFF5 objects without DFF data. 1102 SvMemoryStream maDffStrm; /// Copy of the DFF page stream in memory. 1103 XclImpObjMap maObjMap; /// Maps BIFF8 drawing objects to DFF stream position. 1104 XclImpObjMapById maObjMapId; /// Maps BIFF8 drawing objects to object ID. 1105 XclImpObjTextMap maTextMap; /// Maps BIFF8 TXO textbox data to DFF stream position. 1106 ScfUInt16Vec maSkipObjs; /// IDs of all objects to be skipped. 1107 bool const mbOleObjs; /// True = draw model supports OLE objects. 1108 }; 1109 1110 /** Drawing manager of a single sheet. */ 1111 class XclImpSheetDrawing : public XclImpDrawing 1112 { 1113 public: 1114 explicit XclImpSheetDrawing( const XclImpRoot& rRoot, SCTAB nScTab ); 1115 1116 /** Reads the NOTE record. */ 1117 void ReadNote( XclImpStream& rStrm ); 1118 /** Inserts a new chart object and reads the chart substream (BOF/EOF block). 1119 @descr Used to import chart sheets, which do not have a corresponding OBJ record. */ 1120 void ReadTabChart( XclImpStream& rStrm ); 1121 1122 /** Returns the total cell range covered by any shapes in the sheet. */ GetUsedArea() const1123 const ScRange& GetUsedArea() const { return maScUsedArea; } 1124 /** Converts all objects and inserts them into the sheet drawing page. */ 1125 void ConvertObjects( XclImpDffConverter& rDffConv ); 1126 1127 /** Calculate the resulting rectangle of the passed anchor. */ 1128 virtual tools::Rectangle CalcAnchorRect( const XclObjAnchor& rAnchor, bool bDffAnchor ) const override; 1129 /** On call, updates the used area of the sheet. */ 1130 virtual void OnObjectInserted( const XclImpDrawObjBase& rDrawObj ) override; 1131 1132 private: 1133 /** Reads a BIFF3-BIFF5 NOTE record. */ 1134 void ReadNote3( XclImpStream& rStrm ); 1135 /** Reads a BIFF8 NOTE record. */ 1136 void ReadNote8( XclImpStream& rStrm ); 1137 1138 private: 1139 ScRange maScUsedArea; /// Sheet index and used area in this sheet. 1140 }; 1141 1142 // The object manager ========================================================= 1143 1144 /** Stores all drawing and OLE objects and additional data related to these objects. */ 1145 class XclImpObjectManager : protected XclImpRoot 1146 { 1147 public: 1148 explicit XclImpObjectManager( const XclImpRoot& rRoot ); 1149 virtual ~XclImpObjectManager() override; 1150 1151 /** Reads the MSODRAWINGGROUP record. */ 1152 void ReadMsoDrawingGroup( XclImpStream& rStrm ); 1153 1154 /** Returns (initially creates) the drawing manager of the specified sheet. */ 1155 XclImpSheetDrawing& GetSheetDrawing( SCTAB nScTab ); 1156 /** Inserts all objects into the Calc document. */ 1157 void ConvertObjects(); 1158 1159 /** Returns the default name for the passed object. */ 1160 OUString GetDefaultObjName( const XclImpDrawObjBase& rDrawObj ) const; 1161 /** Returns the used area in the sheet with the passed index. */ 1162 ScRange GetUsedArea( SCTAB nScTab ) const; 1163 /** Sets the container to receive overridden shape/ctrl names from 1164 the filter. */ SetOleNameOverrideInfo(const css::uno::Reference<css::container::XNameContainer> & rxOverrideInfo)1165 void SetOleNameOverrideInfo( const css::uno::Reference< css::container::XNameContainer >& rxOverrideInfo ) { mxOleCtrlNameOverride = rxOverrideInfo; } 1166 /** Returns the name of overridden name ( or zero length string ) for 1167 associated object id. */ 1168 OUString GetOleNameOverride( SCTAB nTab, sal_uInt16 nObjId ); 1169 1170 private: 1171 typedef std::map< sal_uInt16, OUString > DefObjNameMap; 1172 typedef std::shared_ptr< XclImpSheetDrawing > XclImpSheetDrawingRef; 1173 typedef std::map< SCTAB, XclImpSheetDrawingRef > XclImpSheetDrawingMap; 1174 1175 css::uno::Reference< css::container::XNameContainer > mxOleCtrlNameOverride; 1176 DefObjNameMap maDefObjNames; /// Default base names for all object types. 1177 SvMemoryStream maDggStrm; /// Copy of global DFF data (DGG container) in memory. 1178 XclImpSheetDrawingMap maSheetDrawings; /// Drawing managers of all sheets. 1179 }; 1180 1181 // DFF property set helper ==================================================== 1182 1183 /** This class reads a DFF property set (msofbtOPT record). 1184 1185 It can return separate property values or an item set which contains items 1186 translated from these properties. 1187 */ 1188 class XclImpDffPropSet : protected XclImpRoot 1189 { 1190 public: 1191 explicit XclImpDffPropSet( const XclImpRoot& rRoot ); 1192 1193 /** Reads a DFF property set from the stream. 1194 @descr The stream must point to the start of a DFF record containing properties. */ 1195 void Read( XclImpStream& rStrm ); 1196 1197 /** Returns the specified property or zero, if not extant. */ 1198 sal_uInt32 GetPropertyValue( sal_uInt16 nPropId ) const; 1199 1200 /** Translates the properties and fills the item set. */ 1201 void FillToItemSet( SfxItemSet& rItemSet ) const; 1202 1203 private: 1204 typedef std::unique_ptr<SvMemoryStream> SvMemoryStreamPtr; 1205 1206 SvMemoryStream maDummyStrm; /// Dummy DGG stream for DFF manager. 1207 XclImpSimpleDffConverter const maDffConv; /// DFF converter used to resolve palette colors. 1208 SvMemoryStreamPtr mxMemStrm; /// Helper stream. 1209 }; 1210 1211 XclImpStream& operator>>( XclImpStream& rStrm, XclImpDffPropSet& rPropSet ); 1212 1213 #endif 1214 1215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 1216