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