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>
33 namespace utl
{ class TempFile
; }
34 namespace com::sun::star::chart
{ class XChartDocument
; }
35 namespace com::sun::star::script
{ struct ScriptEventDescriptor
; }
38 // DFF client anchor ==========================================================
40 /** Base class for DFF client anchor atoms used in spreadsheets. */
41 class XclExpDffAnchorBase
: public EscherExClientAnchor_Base
, protected XclExpRoot
44 /** Constructs a dummy client anchor. */
45 explicit XclExpDffAnchorBase( const XclExpRoot
& rRoot
, sal_uInt16 nFlags
= 0 );
47 /** Sets the flags according to the passed SdrObject. */
48 void SetFlags( const SdrObject
& rSdrObj
);
49 /** Sets the anchor position and flags according to the passed SdrObject. */
50 void SetSdrObject( const SdrObject
& rSdrObj
);
52 /** Writes the DFF client anchor structure with the current anchor position. */
53 void WriteDffData( EscherEx
& rEscherEx
) const;
55 /** Called from SVX DFF converter.
56 @param rRect The object anchor rectangle to be exported (in twips). */
57 virtual void WriteData( EscherEx
& rEscherEx
, const tools::Rectangle
& rRect
) override
;
60 virtual void ImplSetFlags( const SdrObject
& rSdrObj
);
61 virtual void ImplCalcAnchorRect( const tools::Rectangle
& rRect
, MapUnit eMapUnit
);
63 protected: // for access in derived classes
64 XclObjAnchor maAnchor
; /// The client anchor data.
65 sal_uInt16 mnFlags
; /// Flags for DFF stream export.
68 /** Represents the position (anchor) of an object in a Calc sheet. */
69 class XclExpDffSheetAnchor
: public XclExpDffAnchorBase
72 explicit XclExpDffSheetAnchor( const XclExpRoot
& rRoot
);
75 virtual void ImplSetFlags( const SdrObject
& rSdrObj
) override
;
76 virtual void ImplCalcAnchorRect( const tools::Rectangle
& rRect
, MapUnit eMapUnit
) override
;
79 SCTAB mnScTab
; /// Calc sheet index.
82 /** Represents the position (anchor) of a shape in an embedded draw page. */
83 class XclExpDffEmbeddedAnchor
: public XclExpDffAnchorBase
86 explicit XclExpDffEmbeddedAnchor( const XclExpRoot
& rRoot
,
87 const Size
& rPageSize
, sal_Int32 nScaleX
, sal_Int32 nScaleY
);
90 virtual void ImplSetFlags( const SdrObject
& rSdrObj
) override
;
91 virtual void ImplCalcAnchorRect( const tools::Rectangle
& rRect
, MapUnit eMapUnit
) override
;
99 /** Represents the position (anchor) of a note object. */
100 class XclExpDffNoteAnchor
: public XclExpDffAnchorBase
103 explicit XclExpDffNoteAnchor( const XclExpRoot
& rRoot
, const tools::Rectangle
& rRect
);
106 /** Represents the position (anchor) of a cell dropdown object. */
107 class XclExpDffDropDownAnchor
: public XclExpDffAnchorBase
110 explicit XclExpDffDropDownAnchor( const XclExpRoot
& rRoot
, const ScAddress
& rScPos
);
113 // MSODRAWING* records ========================================================
115 /** Base class for records holding DFF stream fragments. */
116 class XclExpMsoDrawingBase
: public XclExpRecord
119 explicit XclExpMsoDrawingBase( XclEscherEx
& rEscherEx
, sal_uInt16 nRecId
);
122 virtual void WriteBody( XclExpStream
& rStrm
) override
;
125 XclEscherEx
& mrEscherEx
; /// Reference to the DFF converter containing the DFF stream.
126 sal_uInt32 mnFragmentKey
; /// The key of the DFF stream fragment to be written by this record.
129 /** The MSODRAWINGGROUP record contains the DGGCONTAINER with global DFF data
130 such as the picture container.
132 class XclExpMsoDrawingGroup
: public XclExpMsoDrawingBase
135 explicit XclExpMsoDrawingGroup( XclEscherEx
& rEscherEx
);
138 /** One or more MSODRAWING records contain the DFF stream data for a drawing
141 class XclExpMsoDrawing
: public XclExpMsoDrawingBase
144 explicit XclExpMsoDrawing( XclEscherEx
& rEscherEx
);
147 /** Provides export of bitmap data to an IMGDATA record. */
148 class XclExpImgData
: public XclExpRecordBase
151 explicit XclExpImgData( const Graphic
& rGraphic
, sal_uInt16 nRecId
);
153 /** Writes the BITMAP record. */
154 virtual void Save( XclExpStream
& rStrm
) override
;
155 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
158 Graphic maGraphic
; /// The VCL graphic.
159 sal_uInt16 mnRecId
; /// Record identifier for the IMGDATA record.
162 /** Helper class for form controls to manage spreadsheet links . */
163 class XclExpControlHelper
: protected XclExpRoot
166 explicit XclExpControlHelper( const XclExpRoot
& rRoot
);
167 virtual ~XclExpControlHelper() override
;
170 /** Tries to get spreadsheet cell link and source range link from the passed shape. */
171 void ConvertSheetLinks(
172 css::uno::Reference
< css::drawing::XShape
> const & xShape
);
174 /** Returns the Excel token array of the cell link, or 0, if no link present. */
175 const XclTokenArray
* GetCellLinkTokArr() const { return mxCellLink
.get(); }
176 /** Returns the Excel token array of the source range, or 0, if no link present. */
177 const XclTokenArray
* GetSourceRangeTokArr() const { return mxSrcRange
.get(); }
178 /** Returns the number of entries in the source range, or 0, if no source set. */
179 sal_uInt16
GetSourceEntryCount() const { return mnEntryCount
; }
181 /** Writes a formula with special style only valid in OBJ records. */
182 static void WriteFormula( XclExpStream
& rStrm
, const XclTokenArray
& rTokArr
);
183 /** Writes a formula subrecord with special style only valid in OBJ records. */
184 static void WriteFormulaSubRec( XclExpStream
& rStrm
, sal_uInt16 nSubRecId
, const XclTokenArray
& rTokArr
);
187 XclTokenArrayRef mxCellLink
; /// Formula for linked cell.
188 XclTokenArrayRef mxSrcRange
; /// Formula for source data range.
189 sal_uInt16 mnEntryCount
; /// Number of entries in source range.
191 ScAddress mxCellLinkAddress
;
194 class XclMacroHelper
: public XclExpControlHelper
196 XclTokenArrayRef mxMacroLink
; /// Token array containing a link to an attached macro.
197 OUString maMacroName
;
200 explicit XclMacroHelper( const XclExpRoot
& rRoot
);
201 virtual ~XclMacroHelper() override
;
202 /** Writes an ftMacro subrecord containing a macro link, or nothing, if no macro present. */
203 void WriteMacroSubRec( XclExpStream
& rStrm
);
204 /** Sets the name of a macro for object of passed type
205 @return true = The passed event descriptor was valid, macro name has been found. */
206 bool SetMacroLink( const css::script::ScriptEventDescriptor
& rEvent
, const XclTbxEventType
& nEventType
);
208 /** Sets the name of a macro
209 @return true = The passed macro name has been found. */
210 bool SetMacroLink( const OUString
& rMacro
);
211 const OUString
& GetMacroName() const;
214 class XclExpShapeObj
: public XclObjAny
, public XclMacroHelper
217 explicit XclExpShapeObj( XclExpObjectManager
& rRoot
, css::uno::Reference
< css::drawing::XShape
> const & xShape
, ScDocument
* pDoc
);
218 virtual ~XclExpShapeObj() override
;
220 virtual void WriteSubRecs( XclExpStream
& rStrm
) override
;
223 //delete for exporting OCX
224 //#if EXC_EXP_OCX_CTRL
226 /** Represents an OBJ record for an OCX form control. */
227 class XclExpOcxControlObj
: public XclObj
, public XclExpControlHelper
230 explicit XclExpOcxControlObj(
231 XclExpObjectManager
& rObjMgr
,
232 css::uno::Reference
< css::drawing::XShape
> const & xShape
,
233 const tools::Rectangle
* pChildAnchor
,
234 const OUString
& rClassName
,
235 sal_uInt32 nStrmStart
, sal_uInt32 nStrmSize
);
238 virtual void WriteSubRecs( XclExpStream
& rStrm
) override
;
241 OUString maClassName
; /// Class name of the control.
242 sal_uInt32 mnStrmStart
; /// Start position in 'Ctls' stream.
243 sal_uInt32 mnStrmSize
; /// Size in 'Ctls' stream.
248 /** Represents an OBJ record for a TBX form control. */
249 class XclExpTbxControlObj
: public XclObj
, public XclMacroHelper
252 explicit XclExpTbxControlObj(
253 XclExpObjectManager
& rObjMgr
,
254 css::uno::Reference
< css::drawing::XShape
> const & xShape
,
255 const tools::Rectangle
* pChildAnchor
);
257 /** Sets the name of a macro attached to this control.
258 @return true = The passed event descriptor was valid, macro name has been found. */
259 bool SetMacroLink( const css::script::ScriptEventDescriptor
& rEvent
);
261 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
263 void SaveVml(XclExpXmlStream
& rStrm
);
265 OUString
SaveControlPropertiesXml(XclExpXmlStream
& rStrm
) const;
266 void SaveSheetXml(XclExpXmlStream
& rStrm
, const OUString
& aIdFormControlPr
) const;
268 void setShapeId(sal_Int32 aShapeId
);
271 virtual void WriteSubRecs( XclExpStream
& rStrm
) override
;
273 /** Writes a subrecord containing a cell link, or nothing, if no link present. */
274 void WriteCellLinkSubRec( XclExpStream
& rStrm
, sal_uInt16 nSubRecId
);
275 /** Writes the ftSbs sub structure containing scrollbar data. */
276 void WriteSbs( XclExpStream
& rStrm
);
279 const css::uno::Reference
< css::drawing::XShape
> mxShape
;
280 ScfInt16Vec maMultiSel
; /// Indexes of all selected entries in a multi selection.
281 XclTbxEventType meEventType
; /// Type of supported macro event.
282 sal_Int32 mnHeight
; /// Height of the control.
283 sal_uInt16 mnState
; /// Checked/unchecked state.
284 sal_Int16 mnLineCount
; /// Combobox dropdown line count.
285 sal_Int16 mnSelEntry
; /// Selected entry in combobox (1-based).
286 sal_uInt16 mnScrollValue
; /// Scrollbar: Current value.
287 sal_uInt16 mnScrollMin
; /// Scrollbar: Minimum value.
288 sal_uInt16 mnScrollMax
; /// Scrollbar: Maximum value.
289 sal_uInt16 mnScrollStep
; /// Scrollbar: Single step.
290 sal_uInt16 mnScrollPage
; /// Scrollbar: Page step.
291 bool mbFlatButton
; /// False = 3D button style; True = Flat button style.
292 bool mbFlatBorder
; /// False = 3D border style; True = Flat border style.
293 bool mbMultiSel
; /// true = Multi selection in listbox.
294 bool mbScrollHor
; /// Scrollbar: true = horizontal.
300 tools::Rectangle maAreaFrom
;
301 tools::Rectangle maAreaTo
;
302 XclExpObjectManager
& mrRoot
;
309 /** A chart object. This is the drawing object wrapper for the chart data. */
310 class XclExpChartObj
: public XclObj
, protected XclExpRoot
313 explicit XclExpChartObj(
314 XclExpObjectManager
& rObjMgr
,
315 css::uno::Reference
< css::drawing::XShape
> const & xShape
,
316 const tools::Rectangle
* pChildAnchor
,
318 virtual ~XclExpChartObj() override
;
320 /** Writes the OBJ record and the entire chart substream. */
321 virtual void Save( XclExpStream
& rStrm
) override
;
322 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
324 css::uno::Reference
<css::chart::XChartDocument
> GetChartDoc() const;
327 typedef std::shared_ptr
< XclExpChart
> XclExpChartRef
;
328 XclExpChartRef mxChart
; /// The chart itself (BOF/EOF substream data).
329 css::uno::Reference
< css::drawing::XShape
> mxShape
;
333 /** Represents a NOTE record containing the relevant data of a cell note.
335 NOTE records differ significantly in various BIFF versions. This class
336 encapsulates all needed actions for each supported BIFF version.
337 BIFF5/BIFF7: Stores the note text and generates a single or multiple NOTE
339 BIFF8: Creates the Escher object containing the drawing information and the
342 class XclExpNote
: public XclExpRecord
345 /** Constructs a NOTE record from the passed note object and/or the text.
346 @descr The additional text will be separated from the note text with
348 @param rScPos The Calc cell address of the note.
349 @param pScNote The Calc note object. May be 0 to create a note from rAddText only.
350 @param rAddText Additional text appended to the note text. */
352 const XclExpRoot
& rRoot
,
353 const ScAddress
& rScPos
,
354 const ScPostIt
* pScNote
,
355 std::u16string_view rAddText
);
357 /** Writes the NOTE record, if the respective Escher object is present. */
358 virtual void Save( XclExpStream
& rStrm
) override
;
360 void WriteXml( sal_Int32 nAuthorId
, XclExpXmlStream
& rStrm
);
362 const XclExpString
& GetAuthor() const { return maAuthor
; }
364 /** Writes the body of the NOTE record. */
365 virtual void WriteBody( XclExpStream
& rStrm
) override
;
368 const XclExpRoot
& mrRoot
;
369 XclExpString maAuthor
; /// Name of the author.
370 OString maNoteText
; /// Main text of the note (<=BIFF7).
371 XclExpStringRef mpNoteContents
; /// Text and formatting data (OOXML)
372 ScAddress maScPos
; /// Calc cell address of the note.
373 sal_uInt16 mnObjId
; /// Escher object ID (BIFF8).
374 bool mbVisible
; /// true = permanently visible.
375 SdrTextHorzAdjust meTHA
; /// text horizontal adjust
376 SdrTextVertAdjust meTVA
; /// text vertical adjust
377 bool mbAutoScale
; /// Auto scale text
378 bool mbLocked
; /// Position & Size locked
379 bool mbAutoFill
; /// Auto Fill Style
380 bool mbColHidden
; /// Column containing the comment is hidden
381 bool mbRowHidden
; /// Row containing the comment is hidden
382 tools::Rectangle maCommentFrom
; /// From and From Offset
383 tools::Rectangle maCommentTo
; /// To and To Offsets
386 class XclExpComments
: public XclExpRecord
389 XclExpComments( SCTAB nTab
, XclExpRecordList
< XclExpNote
>& rNotes
);
391 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
395 XclExpRecordList
< XclExpNote
>& mrNotes
;
398 // object manager =============================================================
400 class XclExpObjectManager
: public XclExpRoot
403 explicit XclExpObjectManager( const XclExpRoot
& rRoot
);
404 virtual ~XclExpObjectManager() override
;
406 /** Creates a new DFF client anchor object. Caller takes ownership! May be
407 overwritten in derived classes. */
408 virtual XclExpDffAnchorBase
* CreateDffAnchor() const;
410 /** Creates and returns the MSODRAWINGGROUP record containing global DFF
411 data in the DGGCONTAINER. */
412 rtl::Reference
< XclExpRecordBase
> CreateDrawingGroup();
414 /** Initializes the object manager for a new sheet. */
417 /** Processes a drawing page and returns the record block containing all
418 related records (MSODRAWING, OBJ, TXO, charts, etc.). */
419 rtl::Reference
< XclExpRecordBase
> ProcessDrawing( const SdrPage
* pSdrPage
);
420 /** Processes a collection of UNO shapes and returns the record block
421 containing all related records (MSODRAWING, OBJ, TXO, charts, etc.). */
422 rtl::Reference
< XclExpRecordBase
> ProcessDrawing( const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
);
424 /** Finalizes the object manager after conversion of all sheets. */
427 XclEscherEx
& GetEscherEx() { return *mxEscherEx
; }
428 XclExpMsoDrawing
* GetMsodrawingPerSheet();
430 sal_uInt16
AddObj( std::unique_ptr
<XclObj
> pObjRec
);
431 std::unique_ptr
<XclObj
> RemoveLastObj();
434 explicit XclExpObjectManager( const XclExpObjectManager
& rParent
);
437 void InitStream( bool bTempFile
);
440 std::shared_ptr
< ::utl::TempFile
> mxTempFile
;
441 std::unique_ptr
< SvStream
> mxDffStrm
;
442 std::shared_ptr
< XclEscherEx
> mxEscherEx
;
443 rtl::Reference
< XclExpObjList
> mxObjList
;
446 class XclExpEmbeddedObjectManager
: public XclExpObjectManager
449 explicit XclExpEmbeddedObjectManager(
450 const XclExpObjectManager
& rParent
,
451 const Size
& rPageSize
,
452 sal_Int32 nScaleX
, sal_Int32 nScaleY
);
454 /** Creates a new DFF client anchor object for embedded objects according
455 to the scaling data passed to the constructor. Caller takes ownership! */
456 virtual XclExpDffAnchorBase
* CreateDffAnchor() const override
;
464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */