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