Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / xeescher.hxx
blob62660b8e1b9e5da401aa777fc70ecd558231cc50
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_XEESCHER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XEESCHER_HXX
23 #include <vcl/graph.hxx>
24 #include <filter/msfilter/escherex.hxx>
25 #include "xcl97rec.hxx"
26 #include "xlescher.hxx"
27 #include "xlformula.hxx"
28 #include <svx/sdtaitm.hxx>
29 #include <rtl/ustring.hxx>
30 #include <memory>
32 class ScPostIt;
34 namespace utl { class TempFile; }
35 namespace com { namespace sun { namespace star { namespace chart { class XChartDocument; } } } }
37 namespace com { namespace sun { namespace star {
38 namespace script { struct ScriptEventDescriptor; }
39 } } }
41 // DFF client anchor ==========================================================
43 /** Base class for DFF client anchor atoms used in spreadsheets. */
44 class XclExpDffAnchorBase : public EscherExClientAnchor_Base, protected XclExpRoot
46 public:
47 /** Constructs a dummy client anchor. */
48 explicit XclExpDffAnchorBase( const XclExpRoot& rRoot, sal_uInt16 nFlags = 0 );
50 /** Sets the flags according to the passed SdrObject. */
51 void SetFlags( const SdrObject& rSdrObj );
52 /** Sets the anchor position and flags according to the passed SdrObject. */
53 void SetSdrObject( const SdrObject& rSdrObj );
55 /** Writes the DFF client anchor structure with the current anchor position. */
56 void WriteDffData( EscherEx& rEscherEx ) const;
58 /** Called from SVX DFF converter.
59 @param rRect The object anchor rectangle to be exported (in twips). */
60 virtual void WriteData( EscherEx& rEscherEx, const tools::Rectangle& rRect ) override;
62 private:
63 virtual void ImplSetFlags( const SdrObject& rSdrObj );
64 virtual void ImplCalcAnchorRect( const tools::Rectangle& rRect, MapUnit eMapUnit );
66 protected: // for access in derived classes
67 XclObjAnchor maAnchor; /// The client anchor data.
68 sal_uInt16 mnFlags; /// Flags for DFF stream export.
71 /** Represents the position (anchor) of an object in a Calc sheet. */
72 class XclExpDffSheetAnchor : public XclExpDffAnchorBase
74 public:
75 explicit XclExpDffSheetAnchor( const XclExpRoot& rRoot );
77 private:
78 virtual void ImplSetFlags( const SdrObject& rSdrObj ) override;
79 virtual void ImplCalcAnchorRect( const tools::Rectangle& rRect, MapUnit eMapUnit ) override;
81 private:
82 SCTAB const mnScTab; /// Calc sheet index.
85 /** Represents the position (anchor) of a shape in an embedded draw page. */
86 class XclExpDffEmbeddedAnchor : public XclExpDffAnchorBase
88 public:
89 explicit XclExpDffEmbeddedAnchor( const XclExpRoot& rRoot,
90 const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY );
92 private:
93 virtual void ImplSetFlags( const SdrObject& rSdrObj ) override;
94 virtual void ImplCalcAnchorRect( const tools::Rectangle& rRect, MapUnit eMapUnit ) override;
96 private:
97 Size const maPageSize;
98 sal_Int32 const mnScaleX;
99 sal_Int32 const mnScaleY;
102 /** Represents the position (anchor) of a note object. */
103 class XclExpDffNoteAnchor : public XclExpDffAnchorBase
105 public:
106 explicit XclExpDffNoteAnchor( const XclExpRoot& rRoot, const tools::Rectangle& rRect );
109 /** Represents the position (anchor) of a cell dropdown object. */
110 class XclExpDffDropDownAnchor : public XclExpDffAnchorBase
112 public:
113 explicit XclExpDffDropDownAnchor( const XclExpRoot& rRoot, const ScAddress& rScPos );
116 // MSODRAWING* records ========================================================
118 /** Base class for records holding DFF stream fragments. */
119 class XclExpMsoDrawingBase : public XclExpRecord
121 public:
122 explicit XclExpMsoDrawingBase( XclEscherEx& rEscherEx, sal_uInt16 nRecId );
124 private:
125 virtual void WriteBody( XclExpStream& rStrm ) override;
127 protected:
128 XclEscherEx& mrEscherEx; /// Reference to the DFF converter containing the DFF stream.
129 sal_uInt32 const mnFragmentKey; /// The key of the DFF stream fragment to be written by this record.
132 /** The MSODRAWINGGROUP record contains the DGGCONTAINER with global DFF data
133 such as the picture container.
135 class XclExpMsoDrawingGroup : public XclExpMsoDrawingBase
137 public:
138 explicit XclExpMsoDrawingGroup( XclEscherEx& rEscherEx );
141 /** One or more MSODRAWING records contain the DFF stream data for a drawing
142 shape.
144 class XclExpMsoDrawing : public XclExpMsoDrawingBase
146 public:
147 explicit XclExpMsoDrawing( XclEscherEx& rEscherEx );
150 /** Provides export of bitmap data to an IMGDATA record. */
151 class XclExpImgData : public XclExpRecordBase
153 public:
154 explicit XclExpImgData( const Graphic& rGraphic, sal_uInt16 nRecId );
156 /** Writes the BITMAP record. */
157 virtual void Save( XclExpStream& rStrm ) override;
158 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
160 private:
161 Graphic const maGraphic; /// The VCL graphic.
162 sal_uInt16 const mnRecId; /// Record identifier for the IMGDATA record.
165 /** Helper class for form controls to manage spreadsheet links . */
166 class XclExpControlHelper : protected XclExpRoot
168 public:
169 explicit XclExpControlHelper( const XclExpRoot& rRoot );
170 virtual ~XclExpControlHelper() override;
172 protected:
173 /** Tries to get spreadsheet cell link and source range link from the passed shape. */
174 void ConvertSheetLinks(
175 css::uno::Reference< css::drawing::XShape > const & xShape );
177 /** Returns the Excel token array of the cell link, or 0, if no link present. */
178 const XclTokenArray* GetCellLinkTokArr() const { return mxCellLink.get(); }
179 /** Returns the Excel token array of the source range, or 0, if no link present. */
180 const XclTokenArray* GetSourceRangeTokArr() const { return mxSrcRange.get(); }
181 /** Returns the number of entries in the source range, or 0, if no source set. */
182 sal_uInt16 GetSourceEntryCount() const { return mnEntryCount; }
184 /** Writes a formula with special style only valid in OBJ records. */
185 static void WriteFormula( XclExpStream& rStrm, const XclTokenArray& rTokArr );
186 /** Writes a formula subrecord with special style only valid in OBJ records. */
187 static void WriteFormulaSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId, const XclTokenArray& rTokArr );
189 private:
190 XclTokenArrayRef mxCellLink; /// Formula for linked cell.
191 XclTokenArrayRef mxSrcRange; /// Formula for source data range.
192 sal_uInt16 mnEntryCount; /// Number of entries in source range.
195 class XclMacroHelper : public XclExpControlHelper
197 XclTokenArrayRef mxMacroLink; /// Token array containing a link to an attached macro.
199 public:
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 );
213 class XclExpShapeObj : public XclObjAny, public XclMacroHelper
215 public:
216 explicit XclExpShapeObj( XclExpObjectManager& rRoot, css::uno::Reference< css::drawing::XShape > const & xShape, ScDocument* pDoc );
217 virtual ~XclExpShapeObj() override;
218 private:
219 virtual void WriteSubRecs( XclExpStream& rStrm ) override;
222 //delete for exporting OCX
223 //#if EXC_EXP_OCX_CTRL
225 /** Represents an OBJ record for an OCX form control. */
226 class XclExpOcxControlObj : public XclObj, public XclExpControlHelper
228 public:
229 explicit XclExpOcxControlObj(
230 XclExpObjectManager& rObjMgr,
231 css::uno::Reference< css::drawing::XShape > const & xShape,
232 const tools::Rectangle* pChildAnchor,
233 const OUString& rClassName,
234 sal_uInt32 nStrmStart, sal_uInt32 nStrmSize );
236 private:
237 virtual void WriteSubRecs( XclExpStream& rStrm ) override;
239 private:
240 OUString const maClassName; /// Class name of the control.
241 sal_uInt32 mnStrmStart; /// Start position in 'Ctls' stream.
242 sal_uInt32 mnStrmSize; /// Size in 'Ctls' stream.
245 //#else
247 /** Represents an OBJ record for a TBX form control. */
248 class XclExpTbxControlObj : public XclObj, public XclMacroHelper
250 public:
251 explicit XclExpTbxControlObj(
252 XclExpObjectManager& rObjMgr,
253 css::uno::Reference< css::drawing::XShape > const & xShape,
254 const tools::Rectangle* pChildAnchor );
256 /** Sets the name of a macro attached to this control.
257 @return true = The passed event descriptor was valid, macro name has been found. */
258 bool SetMacroLink( const css::script::ScriptEventDescriptor& rEvent );
260 private:
261 virtual void WriteSubRecs( XclExpStream& rStrm ) override;
263 /** Writes a subrecord containing a cell link, or nothing, if no link present. */
264 void WriteCellLinkSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId );
265 /** Writes the ftSbs sub structure containing scrollbar data. */
266 void WriteSbs( XclExpStream& rStrm );
268 private:
269 ScfInt16Vec maMultiSel; /// Indexes of all selected entries in a multi selection.
270 XclTbxEventType meEventType; /// Type of supported macro event.
271 sal_Int32 mnHeight; /// Height of the control.
272 sal_uInt16 mnState; /// Checked/unchecked state.
273 sal_Int16 mnLineCount; /// Combobox dropdown line count.
274 sal_Int16 mnSelEntry; /// Selected entry in combobox (1-based).
275 sal_uInt16 mnScrollValue; /// Scrollbar: Current value.
276 sal_uInt16 mnScrollMin; /// Scrollbar: Minimum value.
277 sal_uInt16 mnScrollMax; /// Scrollbar: Maximum value.
278 sal_uInt16 mnScrollStep; /// Scrollbar: Single step.
279 sal_uInt16 mnScrollPage; /// Scrollbar: Page step.
280 bool mbFlatButton; /// False = 3D button style; True = Flat button style.
281 bool mbFlatBorder; /// False = 3D border style; True = Flat border style.
282 bool mbMultiSel; /// true = Multi selection in listbox.
283 bool mbScrollHor; /// Scrollbar: true = horizontal.
286 //#endif
288 class XclExpChart;
290 /** A chart object. This is the drawing object wrapper for the chart data. */
291 class XclExpChartObj : public XclObj, protected XclExpRoot
293 public:
294 explicit XclExpChartObj(
295 XclExpObjectManager& rObjMgr,
296 css::uno::Reference< css::drawing::XShape > const & xShape,
297 const tools::Rectangle* pChildAnchor,
298 ScDocument* pDoc );
299 virtual ~XclExpChartObj() override;
301 /** Writes the OBJ record and the entire chart substream. */
302 virtual void Save( XclExpStream& rStrm ) override;
303 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
305 const css::uno::Reference<css::chart::XChartDocument>& GetChartDoc() const;
307 private:
308 typedef std::shared_ptr< XclExpChart > XclExpChartRef;
309 XclExpChartRef mxChart; /// The chart itself (BOF/EOF substream data).
310 css::uno::Reference< css::drawing::XShape > mxShape;
311 css::uno::Reference< css::chart::XChartDocument > mxChartDoc;
312 ScDocument* mpDoc;
315 /** Represents a NOTE record containing the relevant data of a cell note.
317 NOTE records differ significantly in various BIFF versions. This class
318 encapsulates all needed actions for each supported BIFF version.
319 BIFF5/BIFF7: Stores the note text and generates a single or multiple NOTE
320 records on saving.
321 BIFF8: Creates the Escher object containing the drawing information and the
322 note text.
324 class XclExpNote : public XclExpRecord
326 public:
327 /** Constructs a NOTE record from the passed note object and/or the text.
328 @descr The additional text will be separated from the note text with
329 an empty line.
330 @param rScPos The Calc cell address of the note.
331 @param pScNote The Calc note object. May be 0 to create a note from rAddText only.
332 @param rAddText Additional text appended to the note text. */
333 explicit XclExpNote(
334 const XclExpRoot& rRoot,
335 const ScAddress& rScPos,
336 const ScPostIt* pScNote,
337 const OUString& rAddText );
339 /** Writes the NOTE record, if the respective Escher object is present. */
340 virtual void Save( XclExpStream& rStrm ) override;
342 void WriteXml( sal_Int32 nAuthorId, XclExpXmlStream& rStrm );
344 const XclExpString& GetAuthor() const { return maAuthor; }
345 private:
346 /** Writes the body of the NOTE record. */
347 virtual void WriteBody( XclExpStream& rStrm ) override;
349 private:
350 const XclExpRoot& mrRoot;
351 XclExpString maAuthor; /// Name of the author.
352 OString maNoteText; /// Main text of the note (<=BIFF7).
353 XclExpStringRef mpNoteContents; /// Text and formatting data (OOXML)
354 ScAddress maScPos; /// Calc cell address of the note.
355 sal_uInt16 mnObjId; /// Escher object ID (BIFF8).
356 bool mbVisible; /// true = permanently visible.
357 SdrTextHorzAdjust meTHA; /// text horizontal adjust
358 SdrTextVertAdjust meTVA; /// text vertical adjust
359 bool mbAutoScale; /// Auto scale text
360 bool mbLocked; /// Position & Size locked
361 bool mbAutoFill; /// Auto Fill Style
362 bool mbColHidden; /// Column containing the comment is hidden
363 bool mbRowHidden; /// Row containing the comment is hidden
364 tools::Rectangle maCommentFrom; /// From and From Offset
365 tools::Rectangle maCommentTo; /// To and To Offsets
368 class XclExpComments : public XclExpRecord
370 public:
371 XclExpComments( SCTAB nTab, XclExpRecordList< XclExpNote >& rNotes );
373 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
375 private:
376 SCTAB const mnTab;
377 XclExpRecordList< XclExpNote >& mrNotes;
380 // object manager =============================================================
382 class XclExpObjectManager : public XclExpRoot
384 public:
385 explicit XclExpObjectManager( const XclExpRoot& rRoot );
386 virtual ~XclExpObjectManager() override;
388 /** Creates a new DFF client anchor object. Caller takes ownership! May be
389 overwritten in derived classes. */
390 virtual XclExpDffAnchorBase* CreateDffAnchor() const;
392 /** Creates and returns the MSODRAWINGGROUP record containing global DFF
393 data in the DGGCONTAINER. */
394 std::shared_ptr< XclExpRecordBase > CreateDrawingGroup();
396 /** Initializes the object manager for a new sheet. */
397 void StartSheet();
399 /** Processes a drawing page and returns the record block containing all
400 related records (MSODRAWING, OBJ, TXO, charts, etc.). */
401 std::shared_ptr< XclExpRecordBase > ProcessDrawing( const SdrPage* pSdrPage );
402 /** Processes a collection of UNO shapes and returns the record block
403 containing all related records (MSODRAWING, OBJ, TXO, charts, etc.). */
404 std::shared_ptr< XclExpRecordBase > ProcessDrawing( const css::uno::Reference< css::drawing::XShapes >& rxShapes );
406 /** Finalizes the object manager after conversion of all sheets. */
407 void EndDocument();
409 XclEscherEx& GetEscherEx() { return *mxEscherEx; }
410 XclExpMsoDrawing* GetMsodrawingPerSheet();
411 bool HasObj() const;
412 sal_uInt16 AddObj( std::unique_ptr<XclObj> pObjRec );
413 std::unique_ptr<XclObj> RemoveLastObj();
415 protected:
416 explicit XclExpObjectManager( const XclExpObjectManager& rParent );
418 private:
419 void InitStream( bool bTempFile );
421 private:
422 std::shared_ptr< ::utl::TempFile > mxTempFile;
423 std::shared_ptr< SvStream > mxDffStrm;
424 std::shared_ptr< XclEscherEx > mxEscherEx;
425 std::shared_ptr< XclExpObjList > mxObjList;
428 class XclExpEmbeddedObjectManager : public XclExpObjectManager
430 public:
431 explicit XclExpEmbeddedObjectManager(
432 const XclExpObjectManager& rParent,
433 const Size& rPageSize,
434 sal_Int32 nScaleX, sal_Int32 nScaleY );
436 /** Creates a new DFF client anchor object for embedded objects according
437 to the scaling data passed to the constructor. Caller takes ownership! */
438 virtual XclExpDffAnchorBase* CreateDffAnchor() const override;
440 private:
441 Size const maPageSize;
442 sal_Int32 const mnScaleX;
443 sal_Int32 const mnScaleY;
446 #endif
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */