Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XEESCHER_HXX
21 : #define INCLUDED_SC_SOURCE_FILTER_INC_XEESCHER_HXX
22 :
23 : #include <vcl/graph.hxx>
24 : #include <filter/msfilter/escherex.hxx>
25 : #include "xcl97rec.hxx"
26 : #include "xlescher.hxx"
27 : #include <com/sun/star/chart/XChartDocument.hpp>
28 : #include <svx/sdtaitm.hxx>
29 : #include <rtl/ustring.hxx>
30 : #include <memory>
31 :
32 : class ScPostIt;
33 :
34 : namespace com { namespace sun { namespace star {
35 : namespace script { struct ScriptEventDescriptor; }
36 : } } }
37 :
38 : // DFF client anchor ==========================================================
39 :
40 : /** Base class for DFF client anchor atoms used in spreadsheets. */
41 58 : class XclExpDffAnchorBase : public EscherExClientAnchor_Base, protected XclExpRoot
42 : {
43 : public:
44 : /** Constructs a dummy client anchor. */
45 : explicit XclExpDffAnchorBase( const XclExpRoot& rRoot, sal_uInt16 nFlags = 0 );
46 :
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 );
51 :
52 : /** Writes the DFF client anchor structure with the current anchor position. */
53 : void WriteDffData( EscherEx& rEscherEx ) const;
54 :
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 Rectangle& rRect ) SAL_OVERRIDE;
58 :
59 : private:
60 : virtual void ImplSetFlags( const SdrObject& rSdrObj );
61 : virtual void ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit );
62 :
63 : protected: // for access in derived classes
64 : XclObjAnchor maAnchor; /// The client anchor data.
65 : sal_uInt16 mnFlags; /// Flags for DFF stream export.
66 : };
67 :
68 : /** Represents the position (anchor) of an object in a Calc sheet. */
69 110 : class XclExpDffSheetAnchor : public XclExpDffAnchorBase
70 : {
71 : public:
72 : explicit XclExpDffSheetAnchor( const XclExpRoot& rRoot );
73 :
74 : private:
75 : virtual void ImplSetFlags( const SdrObject& rSdrObj ) SAL_OVERRIDE;
76 : virtual void ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit ) SAL_OVERRIDE;
77 :
78 : private:
79 : SCTAB mnScTab; /// Calc sheet index.
80 : };
81 :
82 : /** Represents the position (anchor) of a shape in an embedded draw page. */
83 0 : class XclExpDffEmbeddedAnchor : public XclExpDffAnchorBase
84 : {
85 : public:
86 : explicit XclExpDffEmbeddedAnchor( const XclExpRoot& rRoot,
87 : const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY );
88 :
89 : private:
90 : virtual void ImplSetFlags( const SdrObject& rSdrObj ) SAL_OVERRIDE;
91 : virtual void ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit ) SAL_OVERRIDE;
92 :
93 : private:
94 : Size maPageSize;
95 : sal_Int32 mnScaleX;
96 : sal_Int32 mnScaleY;
97 : };
98 :
99 : /** Represents the position (anchor) of a note object. */
100 3 : class XclExpDffNoteAnchor : public XclExpDffAnchorBase
101 : {
102 : public:
103 : explicit XclExpDffNoteAnchor( const XclExpRoot& rRoot, const Rectangle& rRect );
104 : };
105 :
106 : /** Represents the position (anchor) of a cell dropdown object. */
107 0 : class XclExpDffDropDownAnchor : public XclExpDffAnchorBase
108 : {
109 : public:
110 : explicit XclExpDffDropDownAnchor( const XclExpRoot& rRoot, const ScAddress& rScPos );
111 : };
112 :
113 : // MSODRAWING* records ========================================================
114 :
115 : /** Base class for records holding DFF stream fragments. */
116 219 : class XclExpMsoDrawingBase : public XclExpRecord
117 : {
118 : public:
119 : explicit XclExpMsoDrawingBase( XclEscherEx& rEscherEx, sal_uInt16 nRecId );
120 :
121 : private:
122 : virtual void WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
123 :
124 : protected:
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.
127 : };
128 :
129 : /** The MSODRAWINGGROUP record contains the DGGCONTAINER with global DFF data
130 : such as the picture container.
131 : */
132 144 : class XclExpMsoDrawingGroup : public XclExpMsoDrawingBase
133 : {
134 : public:
135 : explicit XclExpMsoDrawingGroup( XclEscherEx& rEscherEx );
136 : };
137 :
138 : /** One or more MSODRAWING records contain the DFF stream data for a drawing
139 : shape.
140 : */
141 294 : class XclExpMsoDrawing : public XclExpMsoDrawingBase
142 : {
143 : public:
144 : explicit XclExpMsoDrawing( XclEscherEx& rEscherEx );
145 : };
146 :
147 : /** Provides export of bitmap data to an IMGDATA record. */
148 0 : class XclExpImgData : public XclExpRecordBase
149 : {
150 : public:
151 : explicit XclExpImgData( const Graphic& rGraphic, sal_uInt16 nRecId );
152 :
153 : /** Writes the BITMAP record. */
154 : virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
155 : virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
156 :
157 : private:
158 : Graphic maGraphic; /// The VCL graphic.
159 : sal_uInt16 mnRecId; /// Record identifier for the IMGDATA record.
160 : };
161 :
162 : /** Helper class for form controils to manage spreadsheet links . */
163 : class XclExpControlHelper : protected XclExpRoot
164 : {
165 : public:
166 : explicit XclExpControlHelper( const XclExpRoot& rRoot );
167 : virtual ~XclExpControlHelper();
168 :
169 : protected:
170 : /** Tries to get spreadsheet cell link and source range link from the passed shape. */
171 : void ConvertSheetLinks(
172 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
173 :
174 : /** Returns the Excel token array of the cell link, or 0, if no link present. */
175 0 : inline const XclTokenArray* GetCellLinkTokArr() const { return mxCellLink.get(); }
176 : /** Returns the Excel token array of the source range, or 0, if no link present. */
177 0 : inline const XclTokenArray* GetSourceRangeTokArr() const { return mxSrcRange.get(); }
178 : /** Returns the number of entries in the source range, or 0, if no source set. */
179 0 : inline sal_uInt16 GetSourceEntryCount() const { return mnEntryCount; }
180 :
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 );
185 :
186 : private:
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.
190 : };
191 :
192 : class XclMacroHelper : public XclExpControlHelper
193 : {
194 : protected:
195 : XclTokenArrayRef mxMacroLink; /// Token array containing a link to an attached macro.
196 :
197 : public:
198 : explicit XclMacroHelper( const XclExpRoot& rRoot );
199 : virtual ~XclMacroHelper();
200 : /** Writes an ftMacro subrecord containing a macro link, or nothing, if no macro present. */
201 : void WriteMacroSubRec( XclExpStream& rStrm );
202 : /** Sets the name of a macro for object of passed type
203 : @return true = The passed event descriptor was valid, macro name has been found. */
204 : bool SetMacroLink( const ::com::sun::star::script::ScriptEventDescriptor& rEvent, const XclTbxEventType& nEventType );
205 :
206 : /** Sets the name of a macro
207 : @return true = The passed macro name has been found. */
208 : bool SetMacroLink( const OUString& rMacro );
209 : };
210 :
211 : class XclExpShapeObj : public XclObjAny, public XclMacroHelper
212 : {
213 : public:
214 : explicit XclExpShapeObj( XclExpObjectManager& rRoot, ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape, ScDocument* pDoc );
215 : virtual ~XclExpShapeObj();
216 : private:
217 : virtual void WriteSubRecs( XclExpStream& rStrm ) SAL_OVERRIDE;
218 : };
219 :
220 : //delete for exporting OCX
221 : //#if EXC_EXP_OCX_CTRL
222 :
223 : /** Represents an OBJ record for an OCX form control. */
224 0 : class XclExpOcxControlObj : public XclObj, public XclExpControlHelper
225 : {
226 : public:
227 : explicit XclExpOcxControlObj(
228 : XclExpObjectManager& rObjMgr,
229 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape,
230 : const Rectangle* pChildAnchor,
231 : const OUString& rClassName,
232 : sal_uInt32 nStrmStart, sal_uInt32 nStrmSize );
233 :
234 : private:
235 : virtual void WriteSubRecs( XclExpStream& rStrm ) SAL_OVERRIDE;
236 :
237 : private:
238 : OUString maClassName; /// Class name of the control.
239 : sal_uInt32 mnStrmStart; /// Start position in 'Ctls' stream.
240 : sal_uInt32 mnStrmSize; /// Size in 'Ctls' stream.
241 : };
242 :
243 : //#else
244 :
245 : /** Represents an OBJ record for an TBX form control. */
246 0 : class XclExpTbxControlObj : public XclObj, public XclMacroHelper
247 : {
248 : public:
249 : explicit XclExpTbxControlObj(
250 : XclExpObjectManager& rObjMgr,
251 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape,
252 : const Rectangle* pChildAnchor );
253 :
254 : /** Sets the name of a macro attached to this control.
255 : @return true = The passed event descriptor was valid, macro name has been found. */
256 : bool SetMacroLink( const ::com::sun::star::script::ScriptEventDescriptor& rEvent );
257 :
258 : private:
259 : virtual void WriteSubRecs( XclExpStream& rStrm ) SAL_OVERRIDE;
260 :
261 : /** Writes a subrecord containing a cell link, or nothing, if no link present. */
262 : void WriteCellLinkSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId );
263 : /** Writes the ftSbs sub structure containing scrollbar data. */
264 : void WriteSbs( XclExpStream& rStrm );
265 :
266 : private:
267 : ScfInt16Vec maMultiSel; /// Indexes of all selected entries in a multi selection.
268 : XclTbxEventType meEventType; /// Type of supported macro event.
269 : sal_Int32 mnHeight; /// Height of the control.
270 : sal_uInt16 mnState; /// Checked/unchecked state.
271 : sal_Int16 mnLineCount; /// Combobox dropdown line count.
272 : sal_Int16 mnSelEntry; /// Selected entry in combobox (1-based).
273 : sal_uInt16 mnScrollValue; /// Scrollbar: Current value.
274 : sal_uInt16 mnScrollMin; /// Scrollbar: Minimum value.
275 : sal_uInt16 mnScrollMax; /// Scrollbar: Maximum value.
276 : sal_uInt16 mnScrollStep; /// Scrollbar: Single step.
277 : sal_uInt16 mnScrollPage; /// Scrollbar: Page step.
278 : bool mbFlatButton; /// False = 3D button style; True = Flat button style.
279 : bool mbFlatBorder; /// False = 3D border style; True = Flat border style.
280 : bool mbMultiSel; /// true = Multi selection in listbox.
281 : bool mbScrollHor; /// Scrollbar: true = horizontal.
282 : };
283 :
284 : //#endif
285 :
286 : class XclExpChart;
287 :
288 : /** A chart object. This is the drawing object wrapper for the chart data. */
289 : class XclExpChartObj : public XclObj, protected XclExpRoot
290 : {
291 : public:
292 : typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDocument > XChartDocRef;
293 : typedef ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > XShapeRef;
294 : explicit XclExpChartObj(
295 : XclExpObjectManager& rObjMgr,
296 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape,
297 : const Rectangle* pChildAnchor );
298 : virtual ~XclExpChartObj();
299 :
300 : /** Writes the OBJ record and the entire chart substream. */
301 : virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
302 : virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
303 :
304 : const css::uno::Reference<css::chart::XChartDocument>& GetChartDoc() const;
305 :
306 : private:
307 : typedef std::shared_ptr< XclExpChart > XclExpChartRef;
308 : XclExpChartRef mxChart; /// The chart itself (BOF/EOF substream data).
309 : XShapeRef mxShape;
310 : XChartDocRef mxChartDoc;
311 : };
312 :
313 : /** Represents a NOTE record containing the relevant data of a cell note.
314 :
315 : NOTE records differ significantly in various BIFF versions. This class
316 : encapsulates all needed actions for each supported BIFF version.
317 : BIFF5/BIFF7: Stores the note text and generates a single or multiple NOTE
318 : records on saving.
319 : BIFF8: Creates the Escher object containing the drawing information and the
320 : note text.
321 : */
322 6 : class XclExpNote : public XclExpRecord
323 : {
324 : public:
325 : /** Constructs a NOTE record from the passed note object and/or the text.
326 : @descr The additional text will be separated from the note text with
327 : an empty line.
328 : @param rScPos The Calc cell address of the note.
329 : @param pScNote The Calc note object. May be 0 to create a note from rAddText only.
330 : @param rAddText Additional text appended to the note text. */
331 : explicit XclExpNote(
332 : const XclExpRoot& rRoot,
333 : const ScAddress& rScPos,
334 : const ScPostIt* pScNote,
335 : const OUString& rAddText );
336 :
337 : /** Writes the NOTE record, if the respective Escher object is present. */
338 : virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
339 :
340 : void WriteXml( sal_Int32 nAuthorId, XclExpXmlStream& rStrm );
341 :
342 0 : const XclExpString& GetAuthor() const { return maAuthor; }
343 : private:
344 : /** Writes the body of the NOTE record. */
345 : virtual void WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
346 :
347 : private:
348 : XclExpString maAuthor; /// Name of the author.
349 : OUString maOrigNoteText; /// Original main text of the note.
350 : OString maNoteText; /// Main text of the note (<=BIFF7).
351 : XclExpStringRef mpNoteContents; /// Text and formatting data (OOXML)
352 : ScAddress maScPos; /// Calc cell address of the note.
353 : sal_uInt16 mnObjId; /// Escher object ID (BIFF8).
354 : bool mbVisible; /// true = permanently visible.
355 : SdrTextHorzAdjust meTHA; /// text horizontal adjust
356 : SdrTextVertAdjust meTVA; /// text vertical adjust
357 : bool mbAutoScale; /// Auto scale text
358 : bool mbLocked; /// Position & Size locked
359 : bool mbAutoFill; /// Auto Fill Style
360 : bool mbAutoLine; /// Auto Line Style
361 : bool mbColHidden; /// Column containing the comment is hidden
362 : bool mbRowHidden; /// Row containing the comment is hidden
363 : Rectangle maCommentFrom; /// From and From Offset
364 : Rectangle maCommentTo; /// To and To Offsets
365 : };
366 :
367 0 : class XclExpComments : public XclExpRecord
368 : {
369 : public:
370 : typedef XclExpRecordList< XclExpNote >
371 : XclExpNoteList;
372 :
373 : XclExpComments( SCTAB nTab, XclExpNoteList& rNotes );
374 :
375 : virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
376 :
377 : private:
378 : SCTAB mnTab;
379 : XclExpNoteList& mrNotes;
380 : };
381 :
382 : // object manager =============================================================
383 :
384 : class XclExpObjectManager : public XclExpRoot
385 : {
386 : public:
387 : explicit XclExpObjectManager( const XclExpRoot& rRoot );
388 : virtual ~XclExpObjectManager();
389 :
390 : /** Creates a new DFF client anchor object. Caller takes ownership! May be
391 : overwritten in derived classes. */
392 : virtual XclExpDffAnchorBase* CreateDffAnchor() const;
393 :
394 : /** Creates and returns the MSODRAWINGGROUP record containing global DFF
395 : data in the DGGCONTAINER. */
396 : std::shared_ptr< XclExpRecordBase > CreateDrawingGroup();
397 :
398 : /** Initializes the object manager for a new sheet. */
399 : void StartSheet();
400 :
401 : /** Processes a drawing page and returns the record block containing all
402 : related records (MSODRAWING, OBJ, TXO, charts, etc.). */
403 : std::shared_ptr< XclExpRecordBase > ProcessDrawing( SdrPage* pSdrPage );
404 : /** Processes a collection of UNO shapes and returns the record block
405 : containing all related records (MSODRAWING, OBJ, TXO, charts, etc.). */
406 : std::shared_ptr< XclExpRecordBase > ProcessDrawing( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes );
407 :
408 : /** Finalizes the object manager after conversion of all sheets. */
409 : void EndDocument();
410 :
411 58 : inline XclEscherEx& GetEscherEx() { return *mxEscherEx; }
412 : XclExpMsoDrawing* GetMsodrawingPerSheet();
413 : bool HasObj() const;
414 : sal_uInt16 AddObj( XclObj* pObjRec );
415 : XclObj* RemoveLastObj();
416 :
417 : protected:
418 : explicit XclExpObjectManager( const XclExpObjectManager& rParent );
419 :
420 : private:
421 : void InitStream( bool bTempFile );
422 :
423 : private:
424 : std::shared_ptr< ::utl::TempFile > mxTempFile;
425 : std::shared_ptr< SvStream > mxDffStrm;
426 : std::shared_ptr< XclEscherEx > mxEscherEx;
427 : std::shared_ptr< XclExpObjList > mxObjList;
428 : };
429 :
430 0 : class XclExpEmbeddedObjectManager : public XclExpObjectManager
431 : {
432 : public:
433 : explicit XclExpEmbeddedObjectManager(
434 : const XclExpObjectManager& rParent,
435 : const Size& rPageSize,
436 : sal_Int32 nScaleX, sal_Int32 nScaleY );
437 :
438 : /** Creates a new DFF client anchor object for embedded objects according
439 : to the scaling data passed to the constructor. Caller takes ownership! */
440 : virtual XclExpDffAnchorBase* CreateDffAnchor() const SAL_OVERRIDE;
441 :
442 : private:
443 : Size maPageSize;
444 : sal_Int32 mnScaleX;
445 : sal_Int32 mnScaleY;
446 : };
447 :
448 : #endif
449 :
450 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|