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