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_XIESCHER_HXX
21 : #define SC_XIESCHER_HXX
22 :
23 : #include <vector>
24 : #include <map>
25 : #include <filter/msfilter/msdffimp.hxx>
26 : #include <vcl/graph.hxx>
27 : #include "xlescher.hxx"
28 : #include "xiroot.hxx"
29 : #include "xistring.hxx"
30 : #include <boost/shared_ptr.hpp>
31 : #include <oox/ole/olehelper.hxx>
32 : namespace com { namespace sun { namespace star {
33 : namespace drawing { class XShape; }
34 : namespace form { class XForm; }
35 : } } }
36 :
37 : class SdrObjList;
38 : class ScfProgressBar;
39 : class ScfPropertySet;
40 : class ScRangeList;
41 : class XclImpChart;
42 : class XclImpDffConverter;
43 : class XclImpDrawing;
44 :
45 : // Drawing objects ============================================================
46 :
47 : class XclImpDrawObjBase;
48 : typedef boost::shared_ptr< XclImpDrawObjBase > XclImpDrawObjRef;
49 :
50 : /** Base class for drawing objects (OBJ records). */
51 : class XclImpDrawObjBase : protected XclImpRoot
52 : {
53 : public:
54 : explicit XclImpDrawObjBase( const XclImpRoot& rRoot );
55 : virtual ~XclImpDrawObjBase();
56 :
57 : /** Reads the BIFF3 OBJ record, returns a new drawing object. */
58 : static XclImpDrawObjRef ReadObj3( const XclImpRoot& rRoot, XclImpStream& rStrm );
59 : /** Reads the BIFF4 OBJ record, returns a new drawing object. */
60 : static XclImpDrawObjRef ReadObj4( const XclImpRoot& rRoot, XclImpStream& rStrm );
61 : /** Reads the BIFF5 OBJ record, returns a new drawing object. */
62 : static XclImpDrawObjRef ReadObj5( const XclImpRoot& rRoot, XclImpStream& rStrm );
63 : /** Reads the BIFF8 OBJ record, returns a new drawing object. */
64 : static XclImpDrawObjRef ReadObj8( const XclImpRoot& rRoot, XclImpStream& rStrm );
65 :
66 : /** Sets whether this is an area object (then its width and height must be greater than 0). */
67 86 : inline void SetAreaObj( bool bAreaObj ) { mbAreaObj = bAreaObj; }
68 : /** If set to true, a new SdrObject will be created while in DFF import. */
69 71 : inline void SetSimpleMacro( bool bMacro ) { mbSimpleMacro = bMacro; }
70 :
71 : /** Sets the object anchor explicitly. */
72 : void SetAnchor( const XclObjAnchor& rAnchor );
73 : /** Sets shape data from DFF stream. */
74 : void SetDffData(
75 : const DffObjData& rDffObjData, const rtl::OUString& rObjName, const rtl::OUString& rHyperlink,
76 : bool bVisible, bool bAutoMargin );
77 :
78 : /** If set to false, the SdrObject will not be created, processed, or inserted into the draw page. */
79 26 : inline void SetProcessSdrObj( bool bProcess ) { mbProcessSdr = bProcess; }
80 : /** If set to false, the SdrObject will be created or processed, but not be inserted into the draw page. */
81 1 : inline void SetInsertSdrObj( bool bInsert ) { mbInsertSdr = bInsert; }
82 : /** If set to true, a new SdrObject will be created while in DFF import. */
83 70 : inline void SetCustomDffObj( bool bCustom ) { mbCustomDff = bCustom; }
84 :
85 : /** Returns the sheet index and Excel object identifier from OBJ record. */
86 116 : inline sal_uInt16 GetObjId() const { return mnObjId; }
87 : /** Returns the Excel object type from OBJ record. */
88 28 : inline sal_uInt16 GetObjType() const { return mnObjType; }
89 : /** Returns the name of this object, may generate a default name. */
90 : virtual rtl::OUString GetObjName() const;
91 : /** Returns associated macro name, if set, otherwise zero length string. */
92 5 : inline const rtl::OUString& GetMacroName() const { return maMacroName; }
93 :
94 : /** Returns the shape identifier used in the DFF stream. */
95 65 : inline sal_uInt32 GetDffShapeId() const { return mnDffShapeId; }
96 : /** Returns the shape flags from the DFF stream. */
97 61 : inline sal_uInt32 GetDffFlags() const { return mnDffFlags; }
98 :
99 : /** Returns true, if the object is hidden. */
100 0 : inline bool IsHidden() const { return mbHidden; }
101 : /** Returns true, if the object is visible. */
102 8 : inline bool IsVisible() const { return mbVisible; }
103 : /** Returns true, if the object is printable. */
104 61 : inline bool IsPrintable() const { return mbPrintable; }
105 :
106 : /** Returns the object anchor if existing, null otherwise. */
107 : const XclObjAnchor* GetAnchor() const;
108 : /** Returns true, if the passed size is valid for this object. */
109 : bool IsValidSize( const Rectangle& rAnchorRect ) const;
110 : /** Returns the range in the sheet covered by this object. */
111 : ScRange GetUsedArea( SCTAB nScTab ) const;
112 :
113 : /** Returns true, if the object is valid and will be processed. */
114 83 : inline bool IsProcessSdrObj() const { return mbProcessSdr && !mbHidden; }
115 : /** Returns true, if the SdrObject will be created or processed, but not be inserted into the draw page. */
116 123 : inline bool IsInsertSdrObj() const { return mbInsertSdr; }
117 :
118 : /** Returns the needed size on the progress bar (calls virtual DoGetProgressSize() function). */
119 : sal_Size GetProgressSize() const;
120 : /** Creates and returns an SdrObject from the contained data. Caller takes ownership! */
121 : SdrObject* CreateSdrObject( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect, bool bIsDff ) const;
122 : /** Additional processing for the passed SdrObject before insertion into
123 : the drawing page (calls virtual DoPreProcessSdrObj() function). */
124 : void PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
125 : /** Additional processing for the passed SdrObject after insertion into the
126 : drawing page (calls virtual DoPostProcessSdrObj() function). */
127 : void PostProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
128 :
129 : protected:
130 : /** Reads the object name in a BIFF5 OBJ record. */
131 : void ReadName5( XclImpStream& rStrm, sal_uInt16 nNameLen );
132 : /** Reads the macro link in a BIFF3 OBJ record. */
133 : void ReadMacro3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
134 : /** Reads the macro link in a BIFF4 OBJ record. */
135 : void ReadMacro4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
136 : /** Reads the macro link in a BIFF5 OBJ record. */
137 : void ReadMacro5( XclImpStream& rStrm, sal_uInt16 nMacroSize );
138 : /** Reads the contents of the ftMacro sub structure in an OBJ record. */
139 : void ReadMacro8( XclImpStream& rStrm );
140 :
141 : /** Converts the passed line formatting to the passed SdrObject. */
142 : void ConvertLineStyle( SdrObject& rSdrObj, const XclObjLineData& rLineData ) const;
143 : /** Converts the passed fill formatting to the passed SdrObject. */
144 : void ConvertFillStyle( SdrObject& rSdrObj, const XclObjFillData& rFillData ) const;
145 : /** Converts the passed frame flags to the passed SdrObject. */
146 : void ConvertFrameStyle( SdrObject& rSdrObj, sal_uInt16 nFrameFlags ) const;
147 :
148 : /** Returns a solid line color from the passed line data struct. */
149 : Color GetSolidLineColor( const XclObjLineData& rLineData ) const;
150 : /** Returns a solid fill color from the passed fill data struct. */
151 : Color GetSolidFillColor( const XclObjFillData& rFillData ) const;
152 :
153 : /** Derived classes read the contents of the a BIFF3 OBJ record from the passed stream. */
154 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
155 : /** Derived classes read the contents of the a BIFF4 OBJ record from the passed stream. */
156 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
157 : /** Derived classes read the contents of the a BIFF5 OBJ record from the passed stream. */
158 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
159 : /** Derived classes read the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
160 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
161 :
162 : /** Derived classes may return a progress bar size different from 1. */
163 : virtual sal_Size DoGetProgressSize() const;
164 : /** Derived classes create and return a new SdrObject from the contained data. Caller takes ownership! */
165 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
166 : /** Derived classes may perform additional processing for the passed SdrObject before insertion. */
167 : virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
168 : /** Derived classes may perform additional processing for the passed SdrObject after insertion. */
169 : virtual void DoPostProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
170 17 : SCTAB GetTab() const { return mnTab; }
171 : private:
172 : /** Reads the contents of a BIFF3 OBJ record. */
173 : void ImplReadObj3( XclImpStream& rStrm );
174 : /** Reads the contents of a BIFF4 OBJ record. */
175 : void ImplReadObj4( XclImpStream& rStrm );
176 : /** Reads the contents of a BIFF5 OBJ record. */
177 : void ImplReadObj5( XclImpStream& rStrm );
178 : /** Reads the contents of a BIFF8 OBJ record. */
179 : void ImplReadObj8( XclImpStream& rStrm );
180 :
181 : private:
182 : XclObjAnchor maAnchor; /// The position of the object in its parent.
183 : sal_uInt16 mnObjId; /// The object identifier (unique per drawing).
184 : SCTAB mnTab; /// Location of object
185 : sal_uInt16 mnObjType; /// The Excel object type from OBJ record.
186 : sal_uInt32 mnDffShapeId; /// Shape ID from DFF stream.
187 : sal_uInt32 mnDffFlags; /// Shape flags from DFF stream.
188 : rtl::OUString maObjName; /// Name of the object.
189 : rtl::OUString maMacroName; /// Name of an attached macro.
190 : rtl::OUString maHyperlink; /// On-click hyperlink URL.
191 : bool mbHasAnchor; /// true = maAnchor is initialized.
192 : bool mbHidden; /// true = Object is hidden.
193 : bool mbVisible; /// true = Object is visible.
194 : bool mbPrintable; /// true = Object is printable.
195 : bool mbAreaObj; /// true = Width and height must be greater than 0.
196 : bool mbAutoMargin; /// true = Set automatic text margin.
197 : bool mbSimpleMacro; /// true = Create simple macro link and hyperlink.
198 : bool mbProcessSdr; /// true = Object is valid, do processing and insertion.
199 : bool mbInsertSdr; /// true = Insert the SdrObject into draw page.
200 : bool mbCustomDff; /// true = Recreate SdrObject in DFF import.
201 : };
202 :
203 : // ----------------------------------------------------------------------------
204 :
205 88 : class XclImpDrawObjVector : public ::std::vector< XclImpDrawObjRef >
206 : {
207 : public:
208 88 : inline explicit XclImpDrawObjVector() {}
209 :
210 : /** Tries to insert the passed object into the last group or appends it. */
211 : void InsertGrouped( XclImpDrawObjRef xDrawObj );
212 :
213 : /** Returns the needed size on the progress bar for all contained objects. */
214 : sal_Size GetProgressSize() const;
215 : };
216 :
217 : // ----------------------------------------------------------------------------
218 :
219 : /** A placeholder object for unknown object types. */
220 2 : class XclImpPhObj : public XclImpDrawObjBase
221 : {
222 : public:
223 : explicit XclImpPhObj( const XclImpRoot& rRoot );
224 : };
225 :
226 : // ----------------------------------------------------------------------------
227 :
228 : /** A group object. */
229 0 : class XclImpGroupObj : public XclImpDrawObjBase
230 : {
231 : public:
232 : explicit XclImpGroupObj( const XclImpRoot& rRoot );
233 :
234 : /** Tries to insert the drawing object into this or a nested group. */
235 : bool TryInsert( XclImpDrawObjRef xDrawObj );
236 :
237 : protected:
238 : /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */
239 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
240 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
241 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
242 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
243 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
244 : /** Returns a progress bar size that takes all group children into account. */
245 : virtual sal_Size DoGetProgressSize() const;
246 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
247 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
248 :
249 : protected:
250 : XclImpDrawObjVector maChildren; /// Grouped objects.
251 : sal_uInt16 mnFirstUngrouped; /// Object identfier of first object not grouped into this group.
252 : };
253 :
254 : // ----------------------------------------------------------------------------
255 :
256 : /** A line object. */
257 0 : class XclImpLineObj : public XclImpDrawObjBase
258 : {
259 : public:
260 : explicit XclImpLineObj( const XclImpRoot& rRoot );
261 :
262 : protected:
263 : /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */
264 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
265 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
266 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
267 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
268 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
269 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
270 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
271 :
272 : protected:
273 : XclObjLineData maLineData; /// BIFF5 line formatting.
274 : sal_uInt16 mnArrows; /// Line arrows.
275 : sal_uInt8 mnStartPoint; /// Starting point.
276 : };
277 :
278 : // ----------------------------------------------------------------------------
279 :
280 : /** A rectangle or oval object. */
281 82 : class XclImpRectObj : public XclImpDrawObjBase
282 : {
283 : public:
284 : explicit XclImpRectObj( const XclImpRoot& rRoot );
285 :
286 : protected:
287 : /** Reads fil data, line data, and frame flags. */
288 : void ReadFrameData( XclImpStream& rStrm );
289 :
290 : /** Converts fill formatting, line formattind, and frame style. */
291 : void ConvertRectStyle( SdrObject& rSdrObj ) const;
292 :
293 : /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */
294 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
295 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
296 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
297 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
298 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
299 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
300 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
301 :
302 : protected:
303 : XclObjFillData maFillData; /// BIFF5 fill formatting.
304 : XclObjLineData maLineData; /// BIFF5 line formatting.
305 : sal_uInt16 mnFrameFlags; /// Additional flags.
306 : };
307 :
308 : // ----------------------------------------------------------------------------
309 :
310 : /** An oval object. */
311 0 : class XclImpOvalObj : public XclImpRectObj
312 : {
313 : public:
314 : explicit XclImpOvalObj( const XclImpRoot& rRoot );
315 :
316 : protected:
317 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
318 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
319 : };
320 :
321 : // ----------------------------------------------------------------------------
322 :
323 : /** An arc object. */
324 0 : class XclImpArcObj : public XclImpDrawObjBase
325 : {
326 : public:
327 : explicit XclImpArcObj( const XclImpRoot& rRoot );
328 :
329 : protected:
330 : /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */
331 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
332 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
333 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
334 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
335 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
336 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
337 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
338 :
339 : protected:
340 : XclObjFillData maFillData; /// BIFF5 fill formatting.
341 : XclObjLineData maLineData; /// BIFF5 line formatting.
342 : sal_uInt8 mnQuadrant; /// Visible quadrant of the circle.
343 : };
344 :
345 : // ----------------------------------------------------------------------------
346 :
347 : /** A polygon object. */
348 0 : class XclImpPolygonObj : public XclImpRectObj
349 : {
350 : public:
351 : explicit XclImpPolygonObj( const XclImpRoot& rRoot );
352 :
353 : protected:
354 : /** Reads the COORDLIST record following the OBJ record. */
355 : void ReadCoordList( XclImpStream& rStrm );
356 :
357 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
358 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
359 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
360 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
361 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
362 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
363 :
364 : protected:
365 : typedef ::std::vector< Point > PointVector;
366 : PointVector maCoords; /// Coordinates relative to bounding rectangle.
367 : sal_uInt16 mnPolyFlags; /// Additional flags.
368 : sal_uInt16 mnPointCount; /// Polygon point count.
369 : };
370 :
371 : // ----------------------------------------------------------------------------
372 :
373 122 : struct XclImpObjTextData
374 : {
375 : XclObjTextData maData; /// BIFF5 text data.
376 : XclImpStringRef mxString; /// Plain or rich string.
377 :
378 : /** Reads a byte string from the passed stream. */
379 : void ReadByteString( XclImpStream& rStrm );
380 : /** Reads text formatting from the passed stream. */
381 : void ReadFormats( XclImpStream& rStrm );
382 : };
383 :
384 : // ----------------------------------------------------------------------------
385 :
386 : /** A drawing object supporting text contents. Used for all simple objects in BIFF8. */
387 48 : class XclImpTextObj : public XclImpRectObj
388 : {
389 : public:
390 : explicit XclImpTextObj( const XclImpRoot& rRoot );
391 :
392 : /** Stores the passed textbox data. */
393 16 : inline void SetTextData( const XclImpObjTextData& rTextData ) { maTextData = rTextData; }
394 :
395 : protected:
396 : /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */
397 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
398 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
399 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
400 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
401 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
402 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
403 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
404 : /** Inserts the contained text data at the passed object. */
405 : virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
406 :
407 : protected:
408 : XclImpObjTextData maTextData; /// Textbox data from BIFF5 OBJ or BIFF8 TXO record.
409 : };
410 :
411 : // ----------------------------------------------------------------------------
412 :
413 : /** A chart object. This is the drawing object wrapper for the chart data. */
414 82 : class XclImpChartObj : public XclImpRectObj
415 : {
416 : public:
417 : /** @param bOwnTab True = chart is on an own sheet; false = chart is an embedded object. */
418 : explicit XclImpChartObj( const XclImpRoot& rRoot, bool bOwnTab = false );
419 :
420 : /** Reads the complete chart substream (BOF/EOF block). */
421 : void ReadChartSubStream( XclImpStream& rStrm );
422 :
423 : protected:
424 : /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */
425 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
426 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
427 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
428 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
429 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
430 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
431 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
432 : /** Returns the needed size on the progress bar. */
433 : virtual sal_Size DoGetProgressSize() const;
434 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
435 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
436 : /** Converts the chart document. */
437 : virtual void DoPostProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
438 :
439 : private:
440 : /** Calculates the object anchor of a sheet chart (chart fills one page). */
441 : void FinalizeTabChart();
442 :
443 : private:
444 : typedef boost::shared_ptr< XclImpChart > XclImpChartRef;
445 :
446 : XclImpChartRef mxChart; /// The chart itself (BOF/EOF substream data).
447 : bool mbOwnTab; /// true = own sheet; false = embedded object.
448 : };
449 :
450 : // ----------------------------------------------------------------------------
451 :
452 : /** A note object, which is a specialized text box objext. */
453 2 : class XclImpNoteObj : public XclImpTextObj
454 : {
455 : public:
456 : explicit XclImpNoteObj( const XclImpRoot& rRoot );
457 :
458 : /** Sets note flags and the note position in the Calc sheet. */
459 : void SetNoteData( const ScAddress& rScPos, sal_uInt16 nNoteFlags );
460 :
461 : protected:
462 : /** Inserts the note into the document, sets visibility. */
463 : virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
464 :
465 : private:
466 : ScAddress maScPos; /// Cell position of the note object.
467 : sal_uInt16 mnNoteFlags; /// Flags from NOTE record.
468 : };
469 :
470 : // ----------------------------------------------------------------------------
471 :
472 : /** Helper base class for TBX and OCX form controls to manage spreadsheet links. */
473 : class XclImpControlHelper
474 : {
475 : public:
476 : explicit XclImpControlHelper( const XclImpRoot& rRoot, XclCtrlBindMode eBindMode );
477 : virtual ~XclImpControlHelper();
478 :
479 : /** Returns true, if a linked cell address is present. */
480 8 : inline bool HasCellLink() const { return mxCellLink != 0; }
481 : /** Returns true, if a linked source cell range is present. */
482 : inline bool HasSourceRange() const { return mxSrcRange != 0; }
483 :
484 : /** Returns the SdrObject from the passed control shape and sets the bounding rectangle. */
485 : SdrObject* CreateSdrObjectFromShape(
486 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape,
487 : const Rectangle& rAnchorRect ) const;
488 :
489 : /** Sets additional properties to the form control model, calls virtual DoProcessControl(). */
490 : void ProcessControl( const XclImpDrawObjBase& rDrawObj ) const;
491 :
492 : protected:
493 : /** Reads the formula for the linked cell from the current position of the stream. */
494 : void ReadCellLinkFormula( XclImpStream& rStrm, bool bWithBoundSize );
495 : /** Reads the formula for the source range from the current position of the stream. */
496 : void ReadSourceRangeFormula( XclImpStream& rStrm, bool bWithBoundSize );
497 :
498 : /** Derived classes will set additional properties for the current form control. */
499 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
500 :
501 : void ApplySheetLinkProps() const;
502 : mutable ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
503 : mxShape; /// The UNO wrapper of the control shape.
504 : boost::shared_ptr< ScAddress > mxCellLink; /// Linked cell in the Calc document.
505 : private:
506 : /** Reads a list of cell ranges from a formula at the current stream position. */
507 : void ReadRangeList( ScRangeList& rScRanges, XclImpStream& rStrm );
508 : /** Reads leading formula size and a list of cell ranges from a formula if the leading size is not zero. */
509 : void ReadRangeList( ScRangeList& rScRanges, XclImpStream& rStrm, bool bWithBoundSize );
510 :
511 : private:
512 : const XclImpRoot& mrRoot; /// Not derived from XclImpRoot to allow multiple inheritance.
513 : boost::shared_ptr< ScRange > mxSrcRange; /// Source data range in the Calc document.
514 : XclCtrlBindMode meBindMode; /// Value binding mode.
515 : };
516 :
517 : // ----------------------------------------------------------------------------
518 :
519 : /** Base class for textbox based form controls. */
520 25 : class XclImpTbxObjBase : public XclImpTextObj, public XclImpControlHelper
521 : {
522 : public:
523 : explicit XclImpTbxObjBase( const XclImpRoot& rRoot );
524 :
525 : /** Sets line and fill formatting from the passed DFF property set. */
526 : void SetDffProperties( const DffPropSet& rDffPropSet );
527 :
528 : /** Returns the service name of the control component to be created. */
529 5 : inline ::rtl::OUString GetServiceName() const { return DoGetServiceName(); }
530 : /** Fills the passed macro event descriptor. */
531 : bool FillMacroDescriptor(
532 : ::com::sun::star::script::ScriptEventDescriptor& rDescriptor ) const;
533 :
534 : protected:
535 : /** Sets control text formatting. */
536 : void ConvertFont( ScfPropertySet& rPropSet ) const;
537 : /** Sets control label and text formatting. */
538 : void ConvertLabel( ScfPropertySet& rPropSet ) const;
539 :
540 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
541 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
542 : /** Additional processing on the SdrObject, calls new virtual function DoProcessControl(). */
543 : virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
544 :
545 : /** Derived classes return the service name of the control component to be created. */
546 : virtual ::rtl::OUString DoGetServiceName() const = 0;
547 : /** Derived classes return the type of the macro event to be created. */
548 : virtual XclTbxEventType DoGetEventType() const = 0;
549 : };
550 :
551 : // ----------------------------------------------------------------------------
552 :
553 : /** A button control. */
554 0 : class XclImpButtonObj : public XclImpTbxObjBase
555 : {
556 : public:
557 : explicit XclImpButtonObj( const XclImpRoot& rRoot );
558 :
559 : protected:
560 : /** Sets additional properties for the current form control. */
561 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
562 : /** Returns the service name of the control component to be created. */
563 : virtual ::rtl::OUString DoGetServiceName() const;
564 : /** Returns the type of the macro event to be created. */
565 : virtual XclTbxEventType DoGetEventType() const;
566 : };
567 :
568 : // ----------------------------------------------------------------------------
569 :
570 : /** A checkbox control. */
571 4 : class XclImpCheckBoxObj : public XclImpTbxObjBase
572 : {
573 : public:
574 : explicit XclImpCheckBoxObj( const XclImpRoot& rRoot );
575 :
576 : protected:
577 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
578 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
579 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
580 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
581 : /** Sets additional properties for the current form control. */
582 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
583 : /** Returns the service name of the control component to be created. */
584 : virtual ::rtl::OUString DoGetServiceName() const;
585 : /** Returns the type of the macro event to be created. */
586 : virtual XclTbxEventType DoGetEventType() const;
587 :
588 : protected:
589 : sal_uInt16 mnState;
590 : sal_uInt16 mnCheckBoxFlags;
591 : };
592 :
593 : // ----------------------------------------------------------------------------
594 :
595 : /** An option button control. */
596 8 : class XclImpOptionButtonObj : public XclImpCheckBoxObj
597 : {
598 : public:
599 : explicit XclImpOptionButtonObj( const XclImpRoot& rRoot );
600 :
601 : protected:
602 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
603 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
604 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
605 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
606 : /** Sets additional properties for the current form control. */
607 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
608 : /** Returns the service name of the control component to be created. */
609 : virtual ::rtl::OUString DoGetServiceName() const;
610 : /** Returns the type of the macro event to be created. */
611 : virtual XclTbxEventType DoGetEventType() const;
612 :
613 : protected:
614 : void ApplyGrouping( XclImpOptionButtonObj& rLeader, sal_Int32 nRefVal );
615 : sal_uInt16 mnNextInGroup; /// Next option button in a group.
616 : sal_uInt16 mnFirstInGroup; /// 1 = Button is the first in a group.
617 : };
618 :
619 : // ----------------------------------------------------------------------------
620 :
621 : /** A label control. */
622 0 : class XclImpLabelObj : public XclImpTbxObjBase
623 : {
624 : public:
625 : explicit XclImpLabelObj( const XclImpRoot& rRoot );
626 :
627 : protected:
628 : /** Sets additional properties for the current form control. */
629 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
630 : /** Returns the service name of the control component to be created. */
631 : virtual ::rtl::OUString DoGetServiceName() const;
632 : /** Returns the type of the macro event to be created. */
633 : virtual XclTbxEventType DoGetEventType() const;
634 : };
635 :
636 : // ----------------------------------------------------------------------------
637 :
638 : /** A groupbox control. */
639 2 : class XclImpGroupBoxObj : public XclImpTbxObjBase
640 : {
641 : public:
642 : explicit XclImpGroupBoxObj( const XclImpRoot& rRoot );
643 :
644 : protected:
645 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
646 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
647 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
648 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
649 : /** Sets additional properties for the current form control. */
650 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
651 : /** Returns the service name of the control component to be created. */
652 : virtual ::rtl::OUString DoGetServiceName() const;
653 : /** Returns the type of the macro event to be created. */
654 : virtual XclTbxEventType DoGetEventType() const;
655 :
656 : protected:
657 : sal_uInt16 mnGroupBoxFlags;
658 : };
659 :
660 : // ----------------------------------------------------------------------------
661 :
662 : /** A dialog control. */
663 0 : class XclImpDialogObj : public XclImpTbxObjBase
664 : {
665 : public:
666 : explicit XclImpDialogObj( const XclImpRoot& rRoot );
667 :
668 : protected:
669 : /** Sets additional properties for the current form control. */
670 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
671 : /** Returns the service name of the control component to be created. */
672 : virtual ::rtl::OUString DoGetServiceName() const;
673 : /** Returns the type of the macro event to be created. */
674 : virtual XclTbxEventType DoGetEventType() const;
675 : };
676 :
677 : // ----------------------------------------------------------------------------
678 :
679 : /** An edit control. */
680 0 : class XclImpEditObj : public XclImpTbxObjBase
681 : {
682 : public:
683 : explicit XclImpEditObj( const XclImpRoot& rRoot );
684 :
685 : protected:
686 : /** REturns true, if the field type is numeric. */
687 : bool IsNumeric() const;
688 :
689 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
690 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
691 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
692 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
693 : /** Sets additional properties for the current form control. */
694 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
695 : /** Returns the service name of the control component to be created. */
696 : virtual ::rtl::OUString DoGetServiceName() const;
697 : /** Returns the type of the macro event to be created. */
698 : virtual XclTbxEventType DoGetEventType() const;
699 :
700 : protected:
701 : sal_uInt16 mnContentType;
702 : sal_uInt16 mnMultiLine;
703 : sal_uInt16 mnScrollBar;
704 : sal_uInt16 mnListBoxObjId;
705 : };
706 :
707 : // ----------------------------------------------------------------------------
708 :
709 : /** Base class of scrollable form controls (spin button, scrollbar, listbox, dropdown). */
710 20 : class XclImpTbxObjScrollableBase : public XclImpTbxObjBase
711 : {
712 : public:
713 : explicit XclImpTbxObjScrollableBase( const XclImpRoot& rRoot );
714 :
715 : protected:
716 : /** Reads scrollbar data. */
717 : void ReadSbs( XclImpStream& rStrm );
718 :
719 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
720 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
721 :
722 : protected:
723 : sal_uInt16 mnValue;
724 : sal_uInt16 mnMin;
725 : sal_uInt16 mnMax;
726 : sal_uInt16 mnStep;
727 : sal_uInt16 mnPageStep;
728 : sal_uInt16 mnOrient;
729 : sal_uInt16 mnThumbWidth;
730 : sal_uInt16 mnScrollFlags;
731 : };
732 :
733 : // ----------------------------------------------------------------------------
734 :
735 : /** A spinbutton control. */
736 0 : class XclImpSpinButtonObj : public XclImpTbxObjScrollableBase
737 : {
738 : public:
739 : explicit XclImpSpinButtonObj( const XclImpRoot& rRoot );
740 :
741 : protected:
742 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
743 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
744 : /** Sets additional properties for the current form control. */
745 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
746 : /** Returns the service name of the control component to be created. */
747 : virtual ::rtl::OUString DoGetServiceName() const;
748 : /** Returns the type of the macro event to be created. */
749 : virtual XclTbxEventType DoGetEventType() const;
750 : };
751 :
752 : // ----------------------------------------------------------------------------
753 :
754 : /** A scrollbar control. */
755 0 : class XclImpScrollBarObj : public XclImpTbxObjScrollableBase
756 : {
757 : public:
758 : explicit XclImpScrollBarObj( const XclImpRoot& rRoot );
759 :
760 : protected:
761 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
762 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
763 : /** Sets additional properties for the current form control. */
764 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
765 : /** Returns the service name of the control component to be created. */
766 : virtual ::rtl::OUString DoGetServiceName() const;
767 : /** Returns the type of the macro event to be created. */
768 : virtual XclTbxEventType DoGetEventType() const;
769 : };
770 :
771 : // ----------------------------------------------------------------------------
772 :
773 : /** Base class for list controls (listbox, dropdown). */
774 20 : class XclImpTbxObjListBase : public XclImpTbxObjScrollableBase
775 : {
776 : public:
777 : explicit XclImpTbxObjListBase( const XclImpRoot& rRoot );
778 :
779 : protected:
780 : /** Reads common listbox settings. */
781 : void ReadLbsData( XclImpStream& rStrm );
782 : /** Sets common listbox/dropdown formatting attributes. */
783 : void SetBoxFormatting( ScfPropertySet& rPropSet ) const;
784 :
785 : protected:
786 : sal_uInt16 mnEntryCount;
787 : sal_uInt16 mnSelEntry;
788 : sal_uInt16 mnListFlags;
789 : sal_uInt16 mnEditObjId;
790 : bool mbHasDefFontIdx;
791 : };
792 :
793 : // ----------------------------------------------------------------------------
794 :
795 : /** A listbox control. */
796 0 : class XclImpListBoxObj : public XclImpTbxObjListBase
797 : {
798 : public:
799 : explicit XclImpListBoxObj( const XclImpRoot& rRoot );
800 :
801 : protected:
802 : /** Reads listbox settings and selection. */
803 : void ReadFullLbsData( XclImpStream& rStrm, sal_Size nRecLeft );
804 :
805 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
806 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
807 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
808 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
809 : /** Sets additional properties for the current form control. */
810 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
811 : /** Returns the service name of the control component to be created. */
812 : virtual ::rtl::OUString DoGetServiceName() const;
813 : /** Returns the type of the macro event to be created. */
814 : virtual XclTbxEventType DoGetEventType() const;
815 :
816 : protected:
817 : ScfUInt8Vec maSelection;
818 : };
819 :
820 : // ----------------------------------------------------------------------------
821 :
822 : /** A dropdown listbox control. */
823 40 : class XclImpDropDownObj : public XclImpTbxObjListBase
824 : {
825 : public:
826 : explicit XclImpDropDownObj( const XclImpRoot& rRoot );
827 :
828 : protected:
829 : /** Returns the type of the dropdown control. */
830 : sal_uInt16 GetDropDownType() const;
831 :
832 : /** Reads dropdown box settings. */
833 : void ReadFullLbsData( XclImpStream& rStrm );
834 :
835 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
836 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
837 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
838 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
839 : /** Sets additional properties for the current form control. */
840 : virtual void DoProcessControl( ScfPropertySet& rPropSet ) const;
841 : /** Returns the service name of the control component to be created. */
842 : virtual ::rtl::OUString DoGetServiceName() const;
843 : /** Returns the type of the macro event to be created. */
844 : virtual XclTbxEventType DoGetEventType() const;
845 :
846 : protected:
847 : sal_uInt16 mnLeft;
848 : sal_uInt16 mnTop;
849 : sal_uInt16 mnRight;
850 : sal_uInt16 mnBottom;
851 : sal_uInt16 mnDropDownFlags;
852 : sal_uInt16 mnLineCount;
853 : sal_uInt16 mnMinWidth;
854 : };
855 :
856 : // ----------------------------------------------------------------------------
857 :
858 : /** A picture, an embedded or linked OLE object, or an OCX form control. */
859 8 : class XclImpPictureObj : public XclImpRectObj, public XclImpControlHelper
860 : {
861 : public:
862 : explicit XclImpPictureObj( const XclImpRoot& rRoot );
863 : /** Returns the ObjectName - can use non-obvious lookup for override in the associated vba document module stream**/
864 : virtual rtl::OUString GetObjName() const;
865 : /** Returns the graphic imported from the IMGDATA record. */
866 0 : inline const Graphic& GetGraphic() const { return maGraphic; }
867 :
868 : /** Returns the visible area of the imported graphic. */
869 0 : inline const Rectangle& GetVisArea() const { return maVisArea; }
870 :
871 : /** Returns true, if the OLE object will be shown as symbol. */
872 0 : inline bool IsSymbol() const { return mbSymbol; }
873 : /** Returns the storage name for the OLE object. */
874 : String GetOleStorageName() const;
875 :
876 : /** Returns true, if this object is an OCX form control. */
877 22 : inline bool IsOcxControl() const { return mbEmbedded && mbControl && mbUseCtlsStrm; }
878 : /** Returns the position in the 'Ctls' stream for additional form control data. */
879 3 : inline sal_Size GetCtlsStreamPos() const { return mnCtlsStrmPos; }
880 : /** Returns the size in the 'Ctls' stream for additional form control data. */
881 3 : inline sal_Size GetCtlsStreamSize() const { return mnCtlsStrmSize; }
882 :
883 : protected:
884 : /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */
885 : virtual void DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize );
886 : /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */
887 : virtual void DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize );
888 : /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */
889 : virtual void DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize );
890 : /** Reads the contents of the specified subrecord of a BIFF8 OBJ record from stream. */
891 : virtual void DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize );
892 : /** Creates and returns a new SdrObject from the contained data. Caller takes ownership! */
893 : virtual SdrObject* DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const;
894 : /** Overloaded to do additional processing on the SdrObject. */
895 : virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
896 :
897 : private:
898 : /** Reads and sets the picture flags from a BIFF3-BIFF5 OBJ picture record. */
899 : void ReadFlags3( XclImpStream& rStrm );
900 : /** Reads the contents of the OBJFLAGS subrecord. */
901 : void ReadFlags8( XclImpStream& rStrm );
902 : /** Reads the contents of the OBJPICTFMLA subrecord. */
903 : void ReadPictFmla( XclImpStream& rStrm, sal_uInt16 nLinkSize );
904 :
905 : private:
906 : Graphic maGraphic; /// Picture or OLE placeholder graphic.
907 : Rectangle maVisArea; /// Size of graphic.
908 : String maClassName; /// Class name of embedded OLE object.
909 : sal_uInt32 mnStorageId; /// Identifier of the storage for this object.
910 : sal_Size mnCtlsStrmPos; /// Position in 'Ctls' stream for this control.
911 : sal_Size mnCtlsStrmSize; /// Size in 'Ctls' stream for this control.
912 : bool mbEmbedded; /// true = Embedded OLE object.
913 : bool mbLinked; /// true = Linked OLE object.
914 : bool mbSymbol; /// true = Show as symbol.
915 : bool mbControl; /// true = Form control, false = OLE object.
916 : bool mbUseCtlsStrm; /// true = Form control data in 'Ctls' stream, false = Own storage.
917 : };
918 :
919 : // DFF stream conversion ======================================================
920 :
921 : /** The solver container collects all connector rules for connected objects. */
922 158 : class XclImpSolverContainer : public SvxMSDffSolverContainer
923 : {
924 : public:
925 :
926 : /** Inserts information about a new SdrObject. */
927 : void InsertSdrObjectInfo( SdrObject& rSdrObj, sal_uInt32 nDffShapeId, sal_uInt32 nDffFlags );
928 : /** Removes inforamtion of an SdrObject (and all child objects if it is a group). */
929 : void RemoveSdrObjectInfo( SdrObject& rSdrObj );
930 :
931 : /** Inserts the SdrObject pointers into all connector rules. */
932 : void UpdateConnectorRules();
933 : /** Removes all contained connector rules. */
934 : void RemoveConnectorRules();
935 :
936 : private:
937 : /** Updates the data of a connected shape in a connector rule. */
938 : void UpdateConnection( sal_uInt32 nDffShapeId, SdrObject*& rpSdrObj, sal_uInt32* pnDffFlags = 0 );
939 :
940 : private:
941 : /** Stores data about an SdrObject processed during import. */
942 : struct XclImpSdrInfo
943 : {
944 : SdrObject* mpSdrObj; /// Pointer to an SdrObject.
945 : sal_uInt32 mnDffFlags; /// Shape flags from DFF stream.
946 61 : inline explicit XclImpSdrInfo() : mpSdrObj( 0 ), mnDffFlags( 0 ) {}
947 61 : inline void Set( SdrObject* pSdrObj, sal_uInt32 nDffFlags )
948 61 : { mpSdrObj = pSdrObj; mnDffFlags = nDffFlags; }
949 : };
950 : typedef ::std::map< sal_uInt32, XclImpSdrInfo > XclImpSdrInfoMap;
951 : typedef ::std::map< SdrObject*, sal_uInt32 > XclImpSdrObjMap;
952 :
953 : XclImpSdrInfoMap maSdrInfoMap; /// Maps shape IDs to SdrObjects and flags.
954 : XclImpSdrObjMap maSdrObjMap; /// Maps SdrObjects to shape IDs.
955 : };
956 :
957 : // ----------------------------------------------------------------------------
958 :
959 : /** Simple implementation of the SVX DFF manager. Implements resolving palette
960 : colors. Used by XclImpDffPropSet (as is), extended by XclImpDffConverter.
961 : */
962 : class XclImpSimpleDffConverter : public SvxMSDffManager, protected XclImpRoot
963 : {
964 : public:
965 : explicit XclImpSimpleDffConverter( const XclImpRoot& rRoot, SvStream& rDffStrm );
966 : virtual ~XclImpSimpleDffConverter();
967 :
968 : protected:
969 : /** Returns a color from the Excel color palette. */
970 : virtual bool GetColorFromPalette( sal_uInt16 nIndex, Color& rColor ) const;
971 : };
972 :
973 : // ----------------------------------------------------------------------------
974 :
975 : /** This is the central instance for converting binary DFF data into shape
976 : objects. Used for all sheet shapes and shapes embedded in chart objects.
977 :
978 : The class derives from SvxMSDffManager and SvxMSConvertOCXControls and
979 : contains core implementation of DFF stream import and OCX form control
980 : import.
981 : */
982 : class XclImpDffConverter : public XclImpSimpleDffConverter, private oox::ole::MSConvertOCXControls
983 : {
984 : public:
985 : explicit XclImpDffConverter( const XclImpRoot& rRoot, SvStream& rDffStrm );
986 : virtual ~XclImpDffConverter();
987 :
988 : /** Initializes the internal progress bar with the passed size and starts it. */
989 : void StartProgressBar( sal_Size nProgressSize );
990 : /** Increase the progress bar by the passed value. */
991 : void Progress( sal_Size nDelta = 1 );
992 :
993 : /** Initially called before the objects of the passed drawing manager are converted. */
994 : void InitializeDrawing( XclImpDrawing& rDrawing, SdrModel& rSdrModel, SdrPage& rSdrPage );
995 : /** Processes BIFF5 drawing objects without DFF data, inserts into the passed object list. */
996 : void ProcessObject( SdrObjList& rObjList, const XclImpDrawObjBase& rDrawObj );
997 : /** Processes all objects in the passed list. */
998 : void ProcessDrawing( const XclImpDrawObjVector& rDrawObjs );
999 : /** Processes a drawing container in the passed DFF stream, converts all objects. */
1000 : void ProcessDrawing( SvStream& rDffStrm );
1001 : /** Finally called after the objects of the passed drawing manager have been converted. */
1002 : void FinalizeDrawing();
1003 :
1004 : /** Creates the SdrObject for the passed Excel TBX form control object. */
1005 : SdrObject* CreateSdrObject( const XclImpTbxObjBase& rTbxObj, const Rectangle& rAnchorRect );
1006 : /** Creates the SdrObject for the passed Excel OLE object or OCX form control object. */
1007 : SdrObject* CreateSdrObject( const XclImpPictureObj& rPicObj, const Rectangle& rAnchorRect );
1008 :
1009 : /** Returns true, if the conversion of OLE objects is supported. */
1010 : bool SupportsOleObjects() const;
1011 : /** Returns the default text margin in drawing layer units. */
1012 61 : inline sal_Int32 GetDefaultTextMargin() const { return mnDefTextMargin; }
1013 :
1014 : private:
1015 : // virtual functions of SvxMSDffManager
1016 :
1017 : /** Reads the client anchor from the DFF stream and sets it at the correct object. */
1018 : virtual void ProcessClientAnchor2(
1019 : SvStream& rDffStrm,
1020 : DffRecordHeader& rHeader,
1021 : void* pClientData,
1022 : DffObjData& rObjData );
1023 : /** Processes an DFF object, reads properties from DFF stream. */
1024 : virtual SdrObject* ProcessObj(
1025 : SvStream& rDffStrm,
1026 : DffObjData& rDffObjData,
1027 : void* pClientData,
1028 : Rectangle& rTextRect,
1029 : SdrObject* pOldSdrObj = 0 );
1030 : /** Returns the BLIP stream position, based on the passed DFF stream position. */
1031 : virtual sal_uLong Calc_nBLIPPos( sal_uLong nOrgVal, sal_uLong nStreamPos ) const;
1032 :
1033 : // virtual functions of SvxMSConvertOCXControls
1034 :
1035 : /** Inserts the passed control rxFComp into the form. Needs call to SetCurrentForm() before. */
1036 : virtual sal_Bool InsertControl(
1037 : const ::com::sun::star::uno::Reference<
1038 : ::com::sun::star::form::XFormComponent >& rxFormComp,
1039 : const ::com::sun::star::awt::Size& rSize,
1040 : ::com::sun::star::uno::Reference<
1041 : ::com::sun::star::drawing::XShape >* pxShape,
1042 : sal_Bool bFloatingCtrl );
1043 :
1044 : private:
1045 : /** Data per registered drawing manager, will be stacked for recursive calls. */
1046 79 : struct XclImpDffConvData
1047 : {
1048 : XclImpDrawing& mrDrawing; /// Current drawing container with all drawing objects.
1049 : SdrModel& mrSdrModel; /// The SdrModel of the drawing manager.
1050 : SdrPage& mrSdrPage; /// The SdrPage of the drawing manager.
1051 : XclImpSolverContainer maSolverCont; /// The solver container for connector rules.
1052 : ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >
1053 : mxCtrlForm; /// Controls form of current drawing page.
1054 : sal_Int32 mnLastCtrlIndex; /// Last insertion index of a form control (for macro events).
1055 : bool mbHasCtrlForm; /// True = mxCtrlForm is initialized (but maybe still null).
1056 :
1057 : explicit XclImpDffConvData( XclImpDrawing& rDrawing,
1058 : SdrModel& rSdrModel, SdrPage& rSdrPage );
1059 : };
1060 :
1061 : /** Returns the current drawing manager data struct from top of the stack. */
1062 : XclImpDffConvData& GetConvData();
1063 : /** Returns the current drawing manager data struct from top of the stack. */
1064 : const XclImpDffConvData& GetConvData() const;
1065 :
1066 : /** Reads contents of a hyperlink property and returns the extracted URL. */
1067 : String ReadHlinkProperty( SvStream& rDffStrm ) const;
1068 :
1069 : /** Processes a drawing container (all drawing data of a sheet). */
1070 : void ProcessDgContainer( SvStream& rDffStrm, const DffRecordHeader& rDgHeader );
1071 : /** Processes the global shape group container (all shapes of a sheet). */
1072 : void ProcessShGrContainer( SvStream& rDffStrm, const DffRecordHeader& rShGrHeader );
1073 : /** Processes the solver container (connectors of a sheet). */
1074 : void ProcessSolverContainer( SvStream& rDffStrm, const DffRecordHeader& rSolverHeader );
1075 : /** Processes a shape or shape group container (one top-level shape). */
1076 : void ProcessShContainer( SvStream& rDffStrm, const DffRecordHeader& rShHeader );
1077 :
1078 : /** Inserts the passed SdrObject into the document. This function takes ownership of pSdrObj! */
1079 : void InsertSdrObject( SdrObjList& rObjList, const XclImpDrawObjBase& rDrawObj, SdrObject* pSdrObj );
1080 : /** Initializes the mxCtrlForm referring to the standard controls form. */
1081 : void InitControlForm();
1082 :
1083 : private:
1084 : typedef boost::shared_ptr< ScfProgressBar > ScfProgressBarRef;
1085 : typedef boost::shared_ptr< XclImpDffConvData > XclImpDffConvDataRef;
1086 : typedef ::std::vector< XclImpDffConvDataRef > XclImpDffConvDataStack;
1087 :
1088 : const ::rtl::OUString maStdFormName; /// Standard name of control forms.
1089 : SotStorageStreamRef mxCtlsStrm; /// The 'Ctls' stream for OCX form controls.
1090 : ScfProgressBarRef mxProgress; /// The progress bar used in ProcessObj().
1091 : XclImpDffConvDataStack maDataStack; /// Stack for registered drawing managers.
1092 : sal_uInt32 mnOleImpFlags; /// Application OLE import settings.
1093 : sal_Int32 mnDefTextMargin; /// Default margin in text boxes.
1094 : };
1095 :
1096 : // Drawing manager ============================================================
1097 :
1098 : /** Base class for a container for all objects on a drawing (spreadsheet or
1099 : embedded chart object). */
1100 : class XclImpDrawing : protected XclImpRoot
1101 : {
1102 : public:
1103 : explicit XclImpDrawing( const XclImpRoot& rRoot, bool bOleObjects );
1104 : virtual ~XclImpDrawing();
1105 :
1106 : /** Reads and returns a bitmap from the IMGDATA record. */
1107 : static Graphic ReadImgData( const XclImpRoot& rRoot, XclImpStream& rStrm );
1108 :
1109 : /** Reads a plain OBJ record (without leading DFF data). */
1110 : void ReadObj( XclImpStream& rStrm );
1111 : /** Reads the MSODRAWING or MSODRAWINGSELECTION record. */
1112 : void ReadMsoDrawing( XclImpStream& rStrm );
1113 :
1114 : /** Returns true, if the conversion of OLE objects is supported. */
1115 51 : inline bool SupportsOleObjects() const { return mbOleObjs; }
1116 : /** Finds the OBJ record data related to the DFF shape at the passed position. */
1117 : XclImpDrawObjRef FindDrawObj( const DffRecordHeader& rHeader ) const;
1118 : /** Finds the OBJ record data specified by the passed object identifier. */
1119 : XclImpDrawObjRef FindDrawObj( sal_uInt16 nObjId ) const;
1120 : /** Finds the textbox data related to the DFF shape at the passed position. */
1121 : const XclImpObjTextData* FindTextData( const DffRecordHeader& rHeader ) const;
1122 :
1123 : /** Sets the object with the passed identification to be skipped on import. */
1124 : void SetSkipObj( sal_uInt16 nObjId );
1125 : /** Returns the size of the progress bar shown while processing all objects. */
1126 : sal_Size GetProgressSize() const;
1127 :
1128 : /** Derived classes calculate the resulting rectangle of the passed anchor. */
1129 : virtual Rectangle CalcAnchorRect( const XclObjAnchor& rAnchor, bool bDffAnchor ) const = 0;
1130 : /** Called whenever an object has been inserted into the draw page. */
1131 : virtual void OnObjectInserted( const XclImpDrawObjBase& rDrawObj ) = 0;
1132 :
1133 : protected:
1134 : /** Appends a new drawing object to the list of raw objects (without DFF data). */
1135 : void AppendRawObject( const XclImpDrawObjRef& rxDrawObj );
1136 : /** Converts all objects and inserts them into the current drawing page. */
1137 : void ImplConvertObjects( XclImpDffConverter& rDffConv, SdrModel& rSdrModel, SdrPage& rSdrPage );
1138 :
1139 : private:
1140 : /** Reads and returns a bitmap from WMF/PICT format. */
1141 : static void ReadWmf( Graphic& rGraphic, const XclImpRoot& rRoot, XclImpStream& rStrm );
1142 : /** Reads and returns a bitmap from BMP format. */
1143 : static void ReadBmp( Graphic& rGraphic, const XclImpRoot& rRoot, XclImpStream& rStrm );
1144 :
1145 : /** Reads contents of an DFF record and append data to internal DFF stream. */
1146 : void ReadDffRecord( XclImpStream& rStrm );
1147 : /** Reads a BIFF8 OBJ record following an MSODRAWING record. */
1148 : void ReadObj8( XclImpStream& rStrm );
1149 : /** Reads the TXO record and following CONTINUE records containing string and formatting. */
1150 : void ReadTxo( XclImpStream& rStrm );
1151 :
1152 : private:
1153 : typedef ::std::map< sal_Size, XclImpDrawObjRef > XclImpObjMap;
1154 : typedef ::std::map< sal_uInt16, XclImpDrawObjRef > XclImpObjMapById;
1155 : typedef boost::shared_ptr< XclImpObjTextData > XclImpObjTextRef;
1156 : typedef ::std::map< sal_Size, XclImpObjTextRef > XclImpObjTextMap;
1157 :
1158 : XclImpDrawObjVector maRawObjs; /// BIFF5 objects without DFF data.
1159 : SvMemoryStream maDffStrm; /// Copy of the DFF page stream in memory.
1160 : XclImpObjMap maObjMap; /// Maps BIFF8 drawing objects to DFF stream position.
1161 : XclImpObjMapById maObjMapId; /// Maps BIFF8 drawing objects to object ID.
1162 : XclImpObjTextMap maTextMap; /// Maps BIFF8 TXO textbox data to DFF stream position.
1163 : ScfUInt16Vec maSkipObjs; /// IDs of all objects to be skipped.
1164 : bool mbOleObjs; /// True = draw model supports OLE objects.
1165 : };
1166 :
1167 : // ----------------------------------------------------------------------------
1168 :
1169 : /** Drawing manager of a single sheet. */
1170 100 : class XclImpSheetDrawing : public XclImpDrawing
1171 : {
1172 : public:
1173 : explicit XclImpSheetDrawing( const XclImpRoot& rRoot, SCTAB nScTab );
1174 :
1175 : /** Reads the NOTE record. */
1176 : void ReadNote( XclImpStream& rStrm );
1177 : /** Inserts a new chart object and reads the chart substream (BOF/EOF block).
1178 : @descr Used to import chart sheets, which do not have a corresponding OBJ record. */
1179 : void ReadTabChart( XclImpStream& rStrm );
1180 :
1181 : /** Returns the total cell range covered by any shapes in the sheet. */
1182 12 : inline const ScRange& GetUsedArea() const { return maScUsedArea; }
1183 : /** Converts all objects and inserts them into the sheet drawing page. */
1184 : void ConvertObjects( XclImpDffConverter& rDffConv );
1185 :
1186 : /** Calculate the resulting rectangle of the passed anchor. */
1187 : virtual Rectangle CalcAnchorRect( const XclObjAnchor& rAnchor, bool bDffAnchor ) const;
1188 : /** On call, updates the used area of the sheet. */
1189 : virtual void OnObjectInserted( const XclImpDrawObjBase& rDrawObj );
1190 :
1191 : private:
1192 : /** Reads a BIFF3-BIFF5 NOTE record. */
1193 : void ReadNote3( XclImpStream& rStrm );
1194 : /** Reads a BIFF8 NOTE record. */
1195 : void ReadNote8( XclImpStream& rStrm );
1196 :
1197 : private:
1198 : ScRange maScUsedArea; /// Sheet index and used area in this sheet.
1199 : };
1200 :
1201 : // The object manager =========================================================
1202 :
1203 : /** Stores all drawing and OLE objects and additional data related to these objects. */
1204 : class XclImpObjectManager : protected XclImpRoot
1205 : {
1206 : public:
1207 : explicit XclImpObjectManager( const XclImpRoot& rRoot );
1208 : virtual ~XclImpObjectManager();
1209 :
1210 : /** Reads the MSODRAWINGGROUP record. */
1211 : void ReadMsoDrawingGroup( XclImpStream& rStrm );
1212 :
1213 : /** Returns (initially creates) the drawing manager of the specified sheet. */
1214 : XclImpSheetDrawing& GetSheetDrawing( SCTAB nScTab );
1215 : /** Inserts all objects into the Calc document. */
1216 : void ConvertObjects();
1217 :
1218 : /** Returns the default name for the passed object. */
1219 : rtl::OUString GetDefaultObjName( const XclImpDrawObjBase& rDrawObj ) const;
1220 : /** Returns the used area in the sheet with the passed index. */
1221 : ScRange GetUsedArea( SCTAB nScTab ) const;
1222 : /** Sets the container to receive overridden shape/ctrl names from
1223 : the filter. */
1224 3 : void SetOleNameOverrideInfo( const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& rxOverrideInfo ) { mxOleCtrlNameOverride = rxOverrideInfo; }
1225 : /** Returns the name of overridden name ( or zero length string ) for
1226 : associated object id. */
1227 : String GetOleNameOverride( SCTAB nTab, sal_uInt16 nObjId );
1228 : // ------------------------------------------------------------------------
1229 : private:
1230 :
1231 : /** Reads and returns a bitmap from WMF/PICT format. */
1232 : static void ReadWmf( Graphic& rGraphic, XclImpStream& rStrm );
1233 : /** Reads and returns a bitmap from BMP format. */
1234 : static void ReadBmp( Graphic& rGraphic, XclImpStream& rStrm );
1235 :
1236 : /** Reads contents of an DFF record and append data to internal DFF stream. */
1237 : void ReadDffRecord( XclImpStream& rStrm );
1238 : /** Reads a BIFF8 OBJ record following an MSODRAWING record. */
1239 : void ReadObj8( XclImpStream& rStrm );
1240 : /** Reads the TXO record and following CONTINUE records containing string and formatting. */
1241 : void ReadTxo( XclImpStream& rStrm );
1242 :
1243 : /** Reads a BIFF3-BIFF5 NOTE record. */
1244 : void ReadNote3( XclImpStream& rStrm );
1245 : /** Reads a BIFF8 NOTE record. */
1246 : void ReadNote8( XclImpStream& rStrm );
1247 :
1248 : /** Returns the size of the progress bar shown while processing all objects. */
1249 : sal_Size GetProgressSize() const;
1250 :
1251 : // ------------------------------------------------------------------------
1252 : private:
1253 : typedef ::std::map< sal_uInt16, String > DefObjNameMap;
1254 : typedef boost::shared_ptr< XclImpSheetDrawing > XclImpSheetDrawingRef;
1255 : typedef ::std::map< SCTAB, XclImpSheetDrawingRef > XclImpSheetDrawingMap;
1256 :
1257 : com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > mxOleCtrlNameOverride;
1258 : DefObjNameMap maDefObjNames; /// Default base names for all object types.
1259 : SvMemoryStream maDggStrm; /// Copy of global DFF data (DGG container) in memory.
1260 : XclImpSheetDrawingMap maSheetDrawings; /// Drawing managers of all sheets.
1261 : };
1262 :
1263 : // DFF property set helper ====================================================
1264 :
1265 : /** This class reads an DFF property set (msofbtOPT record).
1266 :
1267 : It can return separate property values or an item set which contains items
1268 : translated from these properties.
1269 : */
1270 95 : class XclImpDffPropSet : protected XclImpRoot
1271 : {
1272 : public:
1273 : explicit XclImpDffPropSet( const XclImpRoot& rRoot );
1274 :
1275 : /** Reads an DFF property set from the stream.
1276 : @descr The stream must point to the start of an DFF record containing properties. */
1277 : void Read( XclImpStream& rStrm );
1278 :
1279 : /** Returns the specified property or the default value, if not extant. */
1280 : sal_uInt32 GetPropertyValue( sal_uInt16 nPropId, sal_uInt32 nDefault = 0 ) const;
1281 :
1282 : /** Translates the properties and fills the item set. */
1283 : void FillToItemSet( SfxItemSet& rItemSet ) const;
1284 :
1285 : private:
1286 : typedef ::std::auto_ptr< SvMemoryStream > SvMemoryStreamPtr;
1287 :
1288 : SvMemoryStream maDummyStrm; /// Dummy DGG stream for DFF manager.
1289 : XclImpSimpleDffConverter maDffConv; /// DFF converter used to resolve palette colors.
1290 : SvMemoryStreamPtr mxMemStrm; /// Helper stream.
1291 : };
1292 :
1293 : XclImpStream& operator>>( XclImpStream& rStrm, XclImpDffPropSet& rPropSet );
1294 :
1295 : // ============================================================================
1296 :
1297 : #endif
1298 :
1299 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|