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