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 <boost/shared_ptr.hpp>
30 : #include <rtl/ustring.hxx>
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 30 : 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 48 : 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 6 : 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 194 : 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 128 : 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 260 : 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 : void WriteFormula( XclExpStream& rStrm, const XclTokenArray& rTokArr ) const;
183 : /** Writes a formula subrecord with special style only valid in OBJ records. */
184 : void WriteFormulaSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId, const XclTokenArray& rTokArr ) const;
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 );
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 : virtual void WriteChartObj( sax_fastparser::FSHelperPtr pDrawing, XclExpXmlStream& rStrm );
304 : void WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS, const XShapeRef& rXShape, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0 );
305 :
306 : const css::uno::Reference<css::chart::XChartDocument>& GetChartDoc() const;
307 :
308 : private:
309 : typedef boost::shared_ptr< XclExpChart > XclExpChartRef;
310 : XclExpChartRef mxChart; /// The chart itself (BOF/EOF substream data).
311 : XShapeRef mxShape;
312 : XChartDocRef mxChartDoc;
313 : };
314 :
315 : /** Represents a NOTE record containing the relevant data of a cell note.
316 :
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.
323 : */
324 12 : class XclExpNote : public XclExpRecord
325 : {
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 );
338 :
339 : /** Writes the NOTE record, if the respective Escher object is present. */
340 : virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
341 :
342 : void WriteXml( sal_Int32 nAuthorId, XclExpXmlStream& rStrm );
343 :
344 0 : const XclExpString& GetAuthor() const { return maAuthor; }
345 : private:
346 : /** Writes the body of the NOTE record. */
347 : virtual void WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
348 :
349 : private:
350 : XclExpString maAuthor; /// Name of the author.
351 : OUString maOrigNoteText; /// Original main text of the note.
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 mbAutoLine; /// Auto Line Style
363 : bool mbColHidden; /// Column containing the comment is hidden
364 : bool mbRowHidden; /// Row containing the comment is hidden
365 : Rectangle maCommentFrom; /// From and From Offset
366 : Rectangle maCommentTo; /// To and To Offsets
367 : };
368 :
369 0 : class XclExpComments : public XclExpRecord
370 : {
371 : public:
372 : typedef XclExpRecordList< XclExpNote >
373 : XclExpNoteList;
374 :
375 : XclExpComments( SCTAB nTab, XclExpNoteList& rNotes );
376 :
377 : virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
378 :
379 : private:
380 : SCTAB mnTab;
381 : XclExpNoteList& mrNotes;
382 : };
383 :
384 : // object manager =============================================================
385 :
386 : class XclExpObjectManager : public XclExpRoot
387 : {
388 : public:
389 : explicit XclExpObjectManager( const XclExpRoot& rRoot );
390 : virtual ~XclExpObjectManager();
391 :
392 : /** Creates a new DFF client anchor object. Caller takes ownership! May be
393 : overwritten in derived classes. */
394 : virtual XclExpDffAnchorBase* CreateDffAnchor() const;
395 :
396 : /** Creates and returns the MSODRAWINGGROUP record containing global DFF
397 : data in the DGGCONTAINER. */
398 : boost::shared_ptr< XclExpRecordBase > CreateDrawingGroup();
399 :
400 : /** Initializes the object manager for a new sheet. */
401 : void StartSheet();
402 :
403 : /** Processes a drawing page and returns the record block containing all
404 : related records (MSODRAWING, OBJ, TXO, charts, etc.). */
405 : boost::shared_ptr< XclExpRecordBase > ProcessDrawing( SdrPage* pSdrPage );
406 : /** Processes a collection of UNO shapes and returns the record block
407 : containing all related records (MSODRAWING, OBJ, TXO, charts, etc.). */
408 : boost::shared_ptr< XclExpRecordBase > ProcessDrawing( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes );
409 :
410 : /** Finalizes the object manager after conversion of all sheets. */
411 : void EndDocument();
412 :
413 30 : inline XclEscherEx& GetEscherEx() { return *mxEscherEx; }
414 : XclExpMsoDrawing* GetMsodrawingPerSheet();
415 : bool HasObj() const;
416 : sal_uInt16 AddObj( XclObj* pObjRec );
417 : XclObj* RemoveLastObj();
418 :
419 : protected:
420 : explicit XclExpObjectManager( const XclExpObjectManager& rParent );
421 :
422 : private:
423 : void InitStream( bool bTempFile );
424 :
425 : private:
426 : boost::shared_ptr< ::utl::TempFile > mxTempFile;
427 : boost::shared_ptr< SvStream > mxDffStrm;
428 : boost::shared_ptr< XclEscherEx > mxEscherEx;
429 : boost::shared_ptr< XclExpObjList > mxObjList;
430 : };
431 :
432 0 : class XclExpEmbeddedObjectManager : public XclExpObjectManager
433 : {
434 : public:
435 : explicit XclExpEmbeddedObjectManager(
436 : const XclExpObjectManager& rParent,
437 : const Size& rPageSize,
438 : sal_Int32 nScaleX, sal_Int32 nScaleY );
439 :
440 : /** Creates a new DFF client anchor object for embedded objects according
441 : to the scaling data passed to the constructor. Caller takes ownership! */
442 : virtual XclExpDffAnchorBase* CreateDffAnchor() const SAL_OVERRIDE;
443 :
444 : private:
445 : Size maPageSize;
446 : sal_Int32 mnScaleX;
447 : sal_Int32 mnScaleY;
448 : };
449 :
450 : #endif
451 :
452 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|