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