1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <vcl/graph.hxx>
23 #include <filter/msfilter/escherex.hxx>
24 #include "xcl97rec.hxx"
25 #include "xlescher.hxx"
26 #include "xlformula.hxx"
27 #include <svx/sdtaitm.hxx>
28 #include <rtl/ustring.hxx>
29 #include <unotools/securityoptions.hxx>
30 #include <unotools/tempfile.hxx>
36 namespace com::sun::star::chart
{ class XChartDocument
; }
37 namespace com::sun::star::script
{ struct ScriptEventDescriptor
; }
40 // DFF client anchor ==========================================================
42 /** Base class for DFF client anchor atoms used in spreadsheets. */
43 class XclExpDffAnchorBase
: public EscherExClientAnchor_Base
, protected XclExpRoot
46 /** Constructs a dummy client anchor. */
47 explicit XclExpDffAnchorBase( const XclExpRoot
& rRoot
, sal_uInt16 nFlags
= 0 );
49 /** Sets the flags according to the passed SdrObject. */
50 void SetFlags( const SdrObject
& rSdrObj
);
51 /** Sets the anchor position and flags according to the passed SdrObject. */
52 void SetSdrObject( const SdrObject
& rSdrObj
);
54 /** Writes the DFF client anchor structure with the current anchor position. */
55 void WriteDffData( EscherEx
& rEscherEx
) const;
57 /** Called from SVX DFF converter.
58 @param rRect The object anchor rectangle to be exported (in twips). */
59 virtual void WriteData( EscherEx
& rEscherEx
, const tools::Rectangle
& rRect
) override
;
62 virtual void ImplSetFlags( const SdrObject
& rSdrObj
);
63 virtual void ImplCalcAnchorRect( const tools::Rectangle
& rRect
, MapUnit eMapUnit
);
65 protected: // for access in derived classes
66 XclObjAnchor maAnchor
; /// The client anchor data.
67 sal_uInt16 mnFlags
; /// Flags for DFF stream export.
70 /** Represents the position (anchor) of an object in a Calc sheet. */
71 class XclExpDffSheetAnchor
: public XclExpDffAnchorBase
74 explicit XclExpDffSheetAnchor( const XclExpRoot
& rRoot
);
77 virtual void ImplSetFlags( const SdrObject
& rSdrObj
) override
;
78 virtual void ImplCalcAnchorRect( const tools::Rectangle
& rRect
, MapUnit eMapUnit
) override
;
81 SCTAB mnScTab
; /// Calc sheet index.
84 /** Represents the position (anchor) of a shape in an embedded draw page. */
85 class XclExpDffEmbeddedAnchor
: public XclExpDffAnchorBase
88 explicit XclExpDffEmbeddedAnchor( const XclExpRoot
& rRoot
,
89 const Size
& rPageSize
, sal_Int32 nScaleX
, sal_Int32 nScaleY
);
92 virtual void ImplSetFlags( const SdrObject
& rSdrObj
) override
;
93 virtual void ImplCalcAnchorRect( const tools::Rectangle
& rRect
, MapUnit eMapUnit
) override
;
101 /** Represents the position (anchor) of a note object. */
102 class XclExpDffNoteAnchor
: public XclExpDffAnchorBase
105 explicit XclExpDffNoteAnchor( const XclExpRoot
& rRoot
, const tools::Rectangle
& rRect
);
108 /** Represents the position (anchor) of a cell dropdown object. */
109 class XclExpDffDropDownAnchor
: public XclExpDffAnchorBase
112 explicit XclExpDffDropDownAnchor( const XclExpRoot
& rRoot
, const ScAddress
& rScPos
);
115 // MSODRAWING* records ========================================================
117 /** Base class for records holding DFF stream fragments. */
118 class XclExpMsoDrawingBase
: public XclExpRecord
121 explicit XclExpMsoDrawingBase( XclEscherEx
& rEscherEx
, sal_uInt16 nRecId
);
124 virtual void WriteBody( XclExpStream
& rStrm
) override
;
127 XclEscherEx
& mrEscherEx
; /// Reference to the DFF converter containing the DFF stream.
128 sal_uInt32 mnFragmentKey
; /// The key of the DFF stream fragment to be written by this record.
131 /** The MSODRAWINGGROUP record contains the DGGCONTAINER with global DFF data
132 such as the picture container.
134 class XclExpMsoDrawingGroup
: public XclExpMsoDrawingBase
137 explicit XclExpMsoDrawingGroup( XclEscherEx
& rEscherEx
);
140 /** One or more MSODRAWING records contain the DFF stream data for a drawing
143 class XclExpMsoDrawing
: public XclExpMsoDrawingBase
146 explicit XclExpMsoDrawing( XclEscherEx
& rEscherEx
);
149 /** Provides export of bitmap data to an IMGDATA record. */
150 class XclExpImgData
: public XclExpRecordBase
153 explicit XclExpImgData( Graphic aGraphic
, sal_uInt16 nRecId
);
155 /** Writes the BITMAP record. */
156 virtual void Save( XclExpStream
& rStrm
) override
;
157 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
160 Graphic maGraphic
; /// The VCL graphic.
161 sal_uInt16 mnRecId
; /// Record identifier for the IMGDATA record.
164 /** Helper class for form controls to manage spreadsheet links . */
165 class XclExpControlHelper
: protected XclExpRoot
168 explicit XclExpControlHelper( const XclExpRoot
& rRoot
);
169 virtual ~XclExpControlHelper() override
;
172 /** Tries to get spreadsheet cell link and source range link from the passed shape. */
173 void ConvertSheetLinks(
174 css::uno::Reference
< css::drawing::XShape
> const & xShape
);
176 /** Returns the Excel token array of the cell link, or 0, if no link present. */
177 const XclTokenArray
* GetCellLinkTokArr() const { return mxCellLink
.get(); }
178 /** Returns the Excel token array of the source range, or 0, if no link present. */
179 const XclTokenArray
* GetSourceRangeTokArr() const { return mxSrcRange
.get(); }
180 /** Returns the number of entries in the source range, or 0, if no source set. */
181 sal_uInt16
GetSourceEntryCount() const { return mnEntryCount
; }
183 /** Writes a formula with special style only valid in OBJ records. */
184 static void WriteFormula( XclExpStream
& rStrm
, const XclTokenArray
& rTokArr
);
185 /** Writes a formula subrecord with special style only valid in OBJ records. */
186 static void WriteFormulaSubRec( XclExpStream
& rStrm
, sal_uInt16 nSubRecId
, const XclTokenArray
& rTokArr
);
189 XclTokenArrayRef mxCellLink
; /// Formula for linked cell.
190 XclTokenArrayRef mxSrcRange
; /// Formula for source data range.
191 sal_uInt16 mnEntryCount
; /// Number of entries in source range.
193 ScAddress mxCellLinkAddress
;
196 class XclMacroHelper
: public XclExpControlHelper
198 XclTokenArrayRef mxMacroLink
; /// Token array containing a link to an attached macro.
199 OUString maMacroName
;
202 explicit XclMacroHelper( const XclExpRoot
& rRoot
);
203 virtual ~XclMacroHelper() override
;
204 /** Writes an ftMacro subrecord containing a macro link, or nothing, if no macro present. */
205 void WriteMacroSubRec( XclExpStream
& rStrm
);
206 /** Sets the name of a macro for object of passed type
207 @return true = The passed event descriptor was valid, macro name has been found. */
208 bool SetMacroLink( const css::script::ScriptEventDescriptor
& rEvent
, const XclTbxEventType
& nEventType
);
210 /** Sets the name of a macro
211 @return true = The passed macro name has been found. */
212 bool SetMacroLink( const OUString
& rMacro
);
213 const OUString
& GetMacroName() const;
216 class XclExpShapeObj
: public XclObjAny
, public XclMacroHelper
219 explicit XclExpShapeObj( XclExpObjectManager
& rRoot
, css::uno::Reference
< css::drawing::XShape
> const & xShape
, ScDocument
* pDoc
);
220 virtual ~XclExpShapeObj() override
;
222 virtual void WriteSubRecs( XclExpStream
& rStrm
) override
;
225 //delete for exporting OCX
226 //#if EXC_EXP_OCX_CTRL
228 /** Represents an OBJ record for an OCX form control. */
229 class XclExpOcxControlObj
: public XclObj
, public XclExpControlHelper
232 explicit XclExpOcxControlObj(
233 XclExpObjectManager
& rObjMgr
,
234 css::uno::Reference
< css::drawing::XShape
> const & xShape
,
235 const tools::Rectangle
* pChildAnchor
,
237 sal_uInt32 nStrmStart
, sal_uInt32 nStrmSize
);
240 virtual void WriteSubRecs( XclExpStream
& rStrm
) override
;
243 OUString maClassName
; /// Class name of the control.
244 sal_uInt32 mnStrmStart
; /// Start position in 'Ctls' stream.
245 sal_uInt32 mnStrmSize
; /// Size in 'Ctls' stream.
250 /** Represents an OBJ record for a TBX form control. */
251 class XclExpTbxControlObj
: public XclObj
, public XclMacroHelper
254 explicit XclExpTbxControlObj(
255 XclExpObjectManager
& rObjMgr
,
256 css::uno::Reference
< css::drawing::XShape
> const & xShape
,
257 const tools::Rectangle
* pChildAnchor
);
259 /** Sets the name of a macro attached to this control.
260 @return true = The passed event descriptor was valid, macro name has been found. */
261 bool SetMacroLink( const css::script::ScriptEventDescriptor
& rEvent
);
263 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
265 void SaveVml(XclExpXmlStream
& rStrm
);
267 OUString
SaveControlPropertiesXml(XclExpXmlStream
& rStrm
) const;
268 void SaveSheetXml(XclExpXmlStream
& rStrm
, const OUString
& aIdFormControlPr
) const;
270 void setShapeId(sal_Int32 aShapeId
);
273 virtual void WriteSubRecs( XclExpStream
& rStrm
) override
;
275 /** Writes a subrecord containing a cell link, or nothing, if no link present. */
276 void WriteCellLinkSubRec( XclExpStream
& rStrm
, sal_uInt16 nSubRecId
);
277 /** Writes the ftSbs sub structure containing scrollbar data. */
278 void WriteSbs( XclExpStream
& rStrm
);
281 const css::uno::Reference
< css::drawing::XShape
> mxShape
;
282 ScfInt16Vec maMultiSel
; /// Indexes of all selected entries in a multi selection.
283 XclTbxEventType meEventType
; /// Type of supported macro event.
284 sal_Int32 mnHeight
; /// Height of the control.
285 sal_uInt16 mnState
; /// Checked/unchecked state.
286 sal_Int16 mnLineCount
; /// Combobox dropdown line count.
287 sal_Int16 mnSelEntry
; /// Selected entry in combobox (1-based).
288 sal_uInt16 mnScrollValue
; /// Scrollbar: Current value.
289 sal_uInt16 mnScrollMin
; /// Scrollbar: Minimum value.
290 sal_uInt16 mnScrollMax
; /// Scrollbar: Maximum value.
291 sal_uInt16 mnScrollStep
; /// Scrollbar: Single step.
292 sal_uInt16 mnScrollPage
; /// Scrollbar: Page step.
293 bool mbFlatButton
; /// False = 3D button style; True = Flat button style.
294 bool mbFlatBorder
; /// False = 3D border style; True = Flat border style.
295 bool mbMultiSel
; /// true = Multi selection in listbox.
296 bool mbScrollHor
; /// Scrollbar: true = horizontal.
302 tools::Rectangle maAreaFrom
;
303 tools::Rectangle maAreaTo
;
304 XclExpObjectManager
& mrRoot
;
311 /** A chart object. This is the drawing object wrapper for the chart data. */
312 class XclExpChartObj
: public XclObj
, protected XclExpRoot
315 explicit XclExpChartObj(
316 XclExpObjectManager
& rObjMgr
,
317 css::uno::Reference
< css::drawing::XShape
> const & xShape
,
318 const tools::Rectangle
* pChildAnchor
,
320 virtual ~XclExpChartObj() override
;
322 /** Writes the OBJ record and the entire chart substream. */
323 virtual void Save( XclExpStream
& rStrm
) override
;
324 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
326 css::uno::Reference
<css::chart::XChartDocument
> GetChartDoc() const;
329 typedef std::shared_ptr
< XclExpChart
> XclExpChartRef
;
330 XclExpChartRef mxChart
; /// The chart itself (BOF/EOF substream data).
331 css::uno::Reference
< css::drawing::XShape
> mxShape
;
335 /** Represents a NOTE record containing the relevant data of a cell note.
337 NOTE records differ significantly in various BIFF versions. This class
338 encapsulates all needed actions for each supported BIFF version.
339 BIFF5/BIFF7: Stores the note text and generates a single or multiple NOTE
341 BIFF8: Creates the Escher object containing the drawing information and the
344 class XclExpNote
: public XclExpRecord
347 /** Constructs a NOTE record from the passed note object and/or the text.
348 @descr The additional text will be separated from the note text with
350 @param rScPos The Calc cell address of the note.
351 @param pScNote The Calc note object. May be 0 to create a note from rAddText only.
352 @param rAddText Additional text appended to the note text. */
354 const XclExpRoot
& rRoot
,
355 const ScAddress
& rScPos
,
356 const ScPostIt
* pScNote
,
357 std::u16string_view rAddText
);
359 /** Writes the NOTE record, if the respective Escher object is present. */
360 virtual void Save( XclExpStream
& rStrm
) override
;
362 void WriteXml( sal_Int32 nAuthorId
, XclExpXmlStream
& rStrm
);
364 const XclExpString
& GetAuthor() const { return maAuthor
; }
366 /** Writes the body of the NOTE record. */
367 virtual void WriteBody( XclExpStream
& rStrm
) override
;
370 const XclExpRoot
& mrRoot
;
371 XclExpString maAuthor
; /// Name of the author.
372 OString maNoteText
; /// Main text of the note (<=BIFF7).
373 XclExpStringRef mpNoteContents
; /// Text and formatting data (OOXML)
374 ScAddress maScPos
; /// Calc cell address of the note.
375 sal_uInt16 mnObjId
; /// Escher object ID (BIFF8).
376 bool mbVisible
; /// true = permanently visible.
377 SdrTextHorzAdjust meTHA
; /// text horizontal adjust
378 SdrTextVertAdjust meTVA
; /// text vertical adjust
379 bool mbAutoScale
; /// Auto scale text
380 bool mbLocked
; /// Position & Size locked
381 bool mbAutoFill
; /// Auto Fill Style
382 bool mbColHidden
; /// Column containing the comment is hidden
383 bool mbRowHidden
; /// Row containing the comment is hidden
384 tools::Rectangle maCommentFrom
; /// From and From Offset
385 tools::Rectangle maCommentTo
; /// To and To Offsets
386 /// map authors to remove personal info
387 std::unique_ptr
<SvtSecurityMapPersonalInfo
> mpAuthorIDs
;
390 class XclExpComments
: public XclExpRecord
393 XclExpComments( SCTAB nTab
, XclExpRecordList
< XclExpNote
>& rNotes
);
395 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
399 XclExpRecordList
< XclExpNote
>& mrNotes
;
402 // object manager =============================================================
404 class XclExpObjectManager
: public XclExpRoot
407 explicit XclExpObjectManager( const XclExpRoot
& rRoot
);
408 virtual ~XclExpObjectManager() override
;
410 /** Creates a new DFF client anchor object. Caller takes ownership! May be
411 overwritten in derived classes. */
412 virtual XclExpDffAnchorBase
* CreateDffAnchor() const;
414 /** Creates and returns the MSODRAWINGGROUP record containing global DFF
415 data in the DGGCONTAINER. */
416 rtl::Reference
< XclExpRecordBase
> CreateDrawingGroup();
418 /** Initializes the object manager for a new sheet. */
421 /** Processes a drawing page and returns the record block containing all
422 related records (MSODRAWING, OBJ, TXO, charts, etc.). */
423 rtl::Reference
< XclExpRecordBase
> ProcessDrawing( const SdrPage
* pSdrPage
);
424 /** Processes a collection of UNO shapes and returns the record block
425 containing all related records (MSODRAWING, OBJ, TXO, charts, etc.). */
426 rtl::Reference
< XclExpRecordBase
> ProcessDrawing( const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
);
428 /** Finalizes the object manager after conversion of all sheets. */
431 XclEscherEx
& GetEscherEx() { return *mxEscherEx
; }
432 XclExpMsoDrawing
* GetMsodrawingPerSheet();
434 sal_uInt16
AddObj( std::unique_ptr
<XclObj
> pObjRec
);
435 std::unique_ptr
<XclObj
> RemoveLastObj();
438 explicit XclExpObjectManager( const XclExpObjectManager
& rParent
);
441 void InitStream( bool bTempFile
);
444 std::optional
< ::utl::TempFileFast
> moTempFile
;
445 SvStream
* mpDffStrm
= nullptr;
446 std::unique_ptr
<SvMemoryStream
> mpBackupStrm
;
447 std::shared_ptr
< XclEscherEx
> mxEscherEx
;
448 rtl::Reference
< XclExpObjList
> mxObjList
;
451 class XclExpEmbeddedObjectManager
: public XclExpObjectManager
454 explicit XclExpEmbeddedObjectManager(
455 const XclExpObjectManager
& rParent
,
456 const Size
& rPageSize
,
457 sal_Int32 nScaleX
, sal_Int32 nScaleY
);
459 /** Creates a new DFF client anchor object for embedded objects according
460 to the scaling data passed to the constructor. Caller takes ownership! */
461 virtual XclExpDffAnchorBase
* CreateDffAnchor() const override
;
469 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */