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 : #include "xeescher.hxx"
21 :
22 : #include <com/sun/star/lang/XServiceInfo.hpp>
23 : #include <com/sun/star/frame/XModel.hpp>
24 : #include <com/sun/star/form/FormComponentType.hpp>
25 : #include <com/sun/star/awt/VisualEffect.hpp>
26 : #include <com/sun/star/awt/ScrollBarOrientation.hpp>
27 : #include <com/sun/star/drawing/XShape.hpp>
28 : #include <com/sun/star/form/binding/XBindableValue.hpp>
29 : #include <com/sun/star/form/binding/XValueBinding.hpp>
30 : #include <com/sun/star/form/binding/XListEntrySink.hpp>
31 : #include <com/sun/star/form/binding/XListEntrySource.hpp>
32 : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
33 : #include <com/sun/star/chart2/XChartDocument.hpp>
34 : #include <com/sun/star/awt/Point.hpp>
35 : #include <com/sun/star/awt/Size.hpp>
36 : #include <com/sun/star/container/XNamed.hpp>
37 :
38 : #include <set>
39 : #include <rtl/ustrbuf.h>
40 : #include <vcl/bmpacc.hxx>
41 : #include <svx/svdoole2.hxx>
42 : #include <svx/svdocapt.hxx>
43 : #include <editeng/outlobj.hxx>
44 : #include <editeng/editobj.hxx>
45 : #include <unotools/tempfile.hxx>
46 : #include <unotools/ucbstreamhelper.hxx>
47 : #include <svtools/embedhlp.hxx>
48 :
49 : #include "editutil.hxx"
50 : #include "unonames.hxx"
51 : #include "convuno.hxx"
52 : #include "postit.hxx"
53 :
54 : #include "fapihelper.hxx"
55 : #include "xechart.hxx"
56 : #include "xeformula.hxx"
57 : #include "xelink.hxx"
58 : #include "xename.hxx"
59 : #include "xestyle.hxx"
60 : #include "userdat.hxx"
61 : #include "drwlayer.hxx"
62 : #include <svx/unoapi.hxx>
63 : #include <svx/algitem.hxx>
64 : #include "scitems.hxx"
65 : #include <editeng/justifyitem.hxx>
66 : #include <svx/sdtaitm.hxx>
67 : #include "attrib.hxx"
68 : #include "document.hxx"
69 : #include <svx/svdattr.hxx>
70 : #include <svx/sdr/properties/properties.hxx>
71 : #include "detfunc.hxx"
72 : #include <svx/xflclit.hxx>
73 : #include <svx/xlnstwit.hxx>
74 : #include <svx/xlnstit.hxx>
75 : #include <svx/sxmspitm.hxx>
76 :
77 : #include <oox/token/tokens.hxx>
78 : #include <oox/export/drawingml.hxx>
79 : #include <oox/export/chartexport.hxx>
80 : #include <oox/export/utils.hxx>
81 : #include <boost/shared_ptr.hpp>
82 :
83 : using namespace com::sun::star;
84 : using ::com::sun::star::uno::UNO_QUERY;
85 : using ::com::sun::star::uno::Reference;
86 : using ::com::sun::star::uno::Sequence;
87 : using ::com::sun::star::lang::XServiceInfo;
88 : using ::com::sun::star::beans::XPropertySet;
89 : using ::com::sun::star::drawing::XShape;
90 : using ::com::sun::star::drawing::XShapes;
91 : using ::com::sun::star::frame::XModel;
92 : using ::com::sun::star::embed::XEmbeddedObject;
93 : using ::com::sun::star::awt::XControlModel;
94 : using ::com::sun::star::form::binding::XBindableValue;
95 : using ::com::sun::star::form::binding::XValueBinding;
96 : using ::com::sun::star::form::binding::XListEntrySink;
97 : using ::com::sun::star::form::binding::XListEntrySource;
98 : using ::com::sun::star::script::ScriptEventDescriptor;
99 : using ::com::sun::star::table::CellAddress;
100 : using ::com::sun::star::table::CellRangeAddress;
101 : using ::com::sun::star::chart2::XChartDocument;
102 : using ::com::sun::star::container::XNamed;
103 : using ::oox::drawingml::DrawingML;
104 : using ::oox::drawingml::ChartExport;
105 : using namespace oox;
106 :
107 : #define HMM2XL(x) ((x)/26.5)+0.5
108 :
109 : #if 1//def XLSX_OOXML_FUTURE
110 : // these function are only used within that context
111 : // Static Function Helpers
112 0 : static const char *ToHorizAlign( SdrTextHorzAdjust eAdjust )
113 : {
114 0 : switch( eAdjust )
115 : {
116 : case SDRTEXTHORZADJUST_CENTER:
117 0 : return "center";
118 : case SDRTEXTHORZADJUST_RIGHT:
119 0 : return "right";
120 : case SDRTEXTHORZADJUST_BLOCK:
121 0 : return "justify";
122 : case SDRTEXTHORZADJUST_LEFT:
123 : default:
124 0 : return "left";
125 : }
126 : }
127 :
128 0 : static const char *ToVertAlign( SdrTextVertAdjust eAdjust )
129 : {
130 0 : switch( eAdjust )
131 : {
132 : case SDRTEXTVERTADJUST_CENTER:
133 0 : return "center";
134 : case SDRTEXTVERTADJUST_BOTTOM:
135 0 : return "bottom";
136 : case SDRTEXTVERTADJUST_BLOCK:
137 0 : return "justify";
138 : case SDRTEXTVERTADJUST_TOP:
139 : default:
140 0 : return "top";
141 : }
142 : }
143 :
144 0 : static void lcl_WriteAnchorVertex( sax_fastparser::FSHelperPtr rComments, Rectangle &aRect )
145 : {
146 0 : rComments->startElement( FSNS( XML_xdr, XML_col ), FSEND );
147 0 : rComments->writeEscaped( OUString::number( aRect.Left() ) );
148 0 : rComments->endElement( FSNS( XML_xdr, XML_col ) );
149 0 : rComments->startElement( FSNS( XML_xdr, XML_colOff ), FSEND );
150 0 : rComments->writeEscaped( OUString::number( aRect.Top() ) );
151 0 : rComments->endElement( FSNS( XML_xdr, XML_colOff ) );
152 0 : rComments->startElement( FSNS( XML_xdr, XML_row ), FSEND );
153 0 : rComments->writeEscaped( OUString::number( aRect.Right() ) );
154 0 : rComments->endElement( FSNS( XML_xdr, XML_row ) );
155 0 : rComments->startElement( FSNS( XML_xdr, XML_rowOff ), FSEND );
156 0 : rComments->writeEscaped( OUString::number( aRect.Bottom() ) );
157 0 : rComments->endElement( FSNS( XML_xdr, XML_rowOff ) );
158 0 : }
159 : #endif
160 :
161 6 : static void lcl_GetFromTo( const XclExpRoot& rRoot, const Rectangle &aRect, sal_Int32 nTab, Rectangle &aFrom, Rectangle &aTo )
162 : {
163 6 : bool bTo = false;
164 6 : sal_Int32 nCol = 0, nRow = 0;
165 6 : sal_Int32 nColOff = 0, nRowOff= 0;
166 :
167 : while(true)
168 : {
169 18 : Rectangle r = rRoot.GetDocPtr()->GetMMRect( nCol,nRow,nCol,nRow,nTab );
170 18 : if( !bTo )
171 : {
172 18 : if( r.Left() <= aRect.Left() )
173 : {
174 12 : nCol++;
175 12 : nColOff = aRect.Left() - r.Left();
176 : }
177 18 : if( r.Top() <= aRect.Top() )
178 : {
179 6 : nRow++;
180 6 : nRowOff = aRect.Top() - r.Top();
181 : }
182 18 : if( r.Left() > aRect.Left() && r.Top() > aRect.Top() )
183 : {
184 12 : aFrom = Rectangle( nCol-1, static_cast<long>(HMM2XL( nColOff )),
185 18 : nRow-1, static_cast<long>(HMM2XL( nRowOff )) );
186 6 : bTo=true;
187 : }
188 : }
189 18 : if( bTo )
190 : {
191 6 : if( r.Right() < aRect.Right() )
192 0 : nCol++;
193 6 : if( r.Bottom() < aRect.Bottom() )
194 0 : nRow++;
195 6 : if( r.Right() >= aRect.Right() && r.Bottom() >= aRect.Bottom() )
196 : {
197 6 : aTo = Rectangle( nCol, static_cast<long>(HMM2XL( aRect.Right() - r.Left() )),
198 12 : nRow, static_cast<long>(HMM2XL( aRect.Bottom() - r.Top() )));
199 6 : break;
200 : }
201 : }
202 : }
203 6 : return;
204 : }
205 :
206 : // Escher client anchor =======================================================
207 :
208 30 : XclExpDffAnchorBase::XclExpDffAnchorBase( const XclExpRoot& rRoot, sal_uInt16 nFlags ) :
209 : XclExpRoot( rRoot ),
210 30 : mnFlags( nFlags )
211 : {
212 30 : }
213 :
214 8 : void XclExpDffAnchorBase::SetFlags( const SdrObject& rSdrObj )
215 : {
216 8 : ImplSetFlags( rSdrObj );
217 8 : }
218 :
219 16 : void XclExpDffAnchorBase::SetSdrObject( const SdrObject& rSdrObj )
220 : {
221 16 : ImplSetFlags( rSdrObj );
222 16 : ImplCalcAnchorRect( rSdrObj.GetCurrentBoundRect(), MAP_100TH_MM );
223 16 : }
224 :
225 30 : void XclExpDffAnchorBase::WriteDffData( EscherEx& rEscherEx ) const
226 : {
227 30 : rEscherEx.AddAtom( 18, ESCHER_ClientAnchor );
228 30 : rEscherEx.GetStream().WriteUInt16( mnFlags );
229 30 : WriteXclObjAnchor( rEscherEx.GetStream(), maAnchor );
230 30 : }
231 :
232 8 : void XclExpDffAnchorBase::WriteData( EscherEx& rEscherEx, const Rectangle& rRect )
233 : {
234 : // the passed rectangle is in twips
235 8 : ImplCalcAnchorRect( rRect, MAP_TWIP );
236 8 : WriteDffData( rEscherEx );
237 8 : }
238 :
239 0 : void XclExpDffAnchorBase::ImplSetFlags( const SdrObject& )
240 : {
241 : OSL_FAIL( "XclExpDffAnchorBase::ImplSetFlags - not implemented" );
242 0 : }
243 :
244 0 : void XclExpDffAnchorBase::ImplCalcAnchorRect( const Rectangle&, MapUnit )
245 : {
246 : OSL_FAIL( "XclExpDffAnchorBase::ImplCalcAnchorRect - not implemented" );
247 0 : }
248 :
249 24 : XclExpDffSheetAnchor::XclExpDffSheetAnchor( const XclExpRoot& rRoot ) :
250 : XclExpDffAnchorBase( rRoot ),
251 24 : mnScTab( rRoot.GetCurrScTab() )
252 : {
253 24 : }
254 :
255 24 : void XclExpDffSheetAnchor::ImplSetFlags( const SdrObject& rSdrObj )
256 : {
257 : // set flags for cell/page anchoring
258 24 : if ( ScDrawLayer::GetAnchorType( rSdrObj ) == SCA_CELL )
259 14 : mnFlags = 0;
260 : else
261 10 : mnFlags = EXC_ESC_ANCHOR_LOCKED;
262 24 : }
263 :
264 24 : void XclExpDffSheetAnchor::ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit )
265 : {
266 24 : maAnchor.SetRect( GetRoot(), mnScTab, rRect, eMapUnit );
267 24 : }
268 :
269 0 : XclExpDffEmbeddedAnchor::XclExpDffEmbeddedAnchor( const XclExpRoot& rRoot,
270 : const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY ) :
271 : XclExpDffAnchorBase( rRoot ),
272 : maPageSize( rPageSize ),
273 : mnScaleX( nScaleX ),
274 0 : mnScaleY( nScaleY )
275 : {
276 0 : }
277 :
278 0 : void XclExpDffEmbeddedAnchor::ImplSetFlags( const SdrObject& /*rSdrObj*/ )
279 : {
280 : // TODO (unsupported feature): fixed size
281 0 : }
282 :
283 0 : void XclExpDffEmbeddedAnchor::ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit )
284 : {
285 0 : maAnchor.SetRect( maPageSize, mnScaleX, mnScaleY, rRect, eMapUnit, true );
286 0 : }
287 :
288 6 : XclExpDffNoteAnchor::XclExpDffNoteAnchor( const XclExpRoot& rRoot, const Rectangle& rRect ) :
289 6 : XclExpDffAnchorBase( rRoot, EXC_ESC_ANCHOR_SIZELOCKED )
290 : {
291 6 : maAnchor.SetRect( rRoot, rRoot.GetCurrScTab(), rRect, MAP_100TH_MM );
292 6 : }
293 :
294 0 : XclExpDffDropDownAnchor::XclExpDffDropDownAnchor( const XclExpRoot& rRoot, const ScAddress& rScPos ) :
295 0 : XclExpDffAnchorBase( rRoot, EXC_ESC_ANCHOR_POSLOCKED )
296 : {
297 0 : GetAddressConverter().ConvertAddress( maAnchor.maFirst, rScPos, true );
298 0 : maAnchor.maLast.mnCol = maAnchor.maFirst.mnCol + 1;
299 0 : maAnchor.maLast.mnRow = maAnchor.maFirst.mnRow + 1;
300 0 : maAnchor.mnLX = maAnchor.mnTY = maAnchor.mnRX = maAnchor.mnBY = 0;
301 0 : }
302 :
303 : // MSODRAWING* records ========================================================
304 :
305 194 : XclExpMsoDrawingBase::XclExpMsoDrawingBase( XclEscherEx& rEscherEx, sal_uInt16 nRecId ) :
306 : XclExpRecord( nRecId ),
307 : mrEscherEx( rEscherEx ),
308 194 : mnFragmentKey( rEscherEx.InitNextDffFragment() )
309 : {
310 194 : }
311 :
312 82 : void XclExpMsoDrawingBase::WriteBody( XclExpStream& rStrm )
313 : {
314 : OSL_ENSURE( mrEscherEx.GetStreamPos() == mrEscherEx.GetDffFragmentPos( mnFragmentKey ),
315 : "XclExpMsoDrawingBase::WriteBody - DFF stream position mismatch" );
316 82 : rStrm.CopyFromStream( mrEscherEx.GetStream(), mrEscherEx.GetDffFragmentSize( mnFragmentKey ) );
317 82 : }
318 :
319 64 : XclExpMsoDrawingGroup::XclExpMsoDrawingGroup( XclEscherEx& rEscherEx ) :
320 64 : XclExpMsoDrawingBase( rEscherEx, EXC_ID_MSODRAWINGGROUP )
321 : {
322 64 : SvStream& rDffStrm = mrEscherEx.GetStream();
323 :
324 : // write the DGGCONTAINER with some default settings
325 64 : mrEscherEx.OpenContainer( ESCHER_DggContainer );
326 :
327 : // TODO: stuff the OPT atom with our own document defaults?
328 : static const sal_uInt8 spnDffOpt[] = {
329 : 0xBF, 0x00, 0x08, 0x00, 0x08, 0x00, 0x81, 0x01,
330 : 0x09, 0x00, 0x00, 0x08, 0xC0, 0x01, 0x40, 0x00,
331 : 0x00, 0x08
332 : };
333 64 : mrEscherEx.AddAtom( sizeof( spnDffOpt ), ESCHER_OPT, 3, 3 );
334 64 : rDffStrm.Write( spnDffOpt, sizeof( spnDffOpt ) );
335 :
336 : // SPLITMENUCOLORS contains colors in toolbar
337 : static const sal_uInt8 spnDffSplitMenuColors[] = {
338 : 0x0D, 0x00, 0x00, 0x08, 0x0C, 0x00, 0x00, 0x08,
339 : 0x17, 0x00, 0x00, 0x08, 0xF7, 0x00, 0x00, 0x10
340 : };
341 64 : mrEscherEx.AddAtom( sizeof( spnDffSplitMenuColors ), ESCHER_SplitMenuColors, 0, 4 );
342 64 : rDffStrm.Write( spnDffSplitMenuColors, sizeof( spnDffSplitMenuColors ) );
343 :
344 : // close the DGGCONTAINER
345 64 : mrEscherEx.CloseContainer();
346 64 : mrEscherEx.UpdateDffFragmentEnd();
347 64 : }
348 :
349 130 : XclExpMsoDrawing::XclExpMsoDrawing( XclEscherEx& rEscherEx ) :
350 130 : XclExpMsoDrawingBase( rEscherEx, EXC_ID_MSODRAWING )
351 : {
352 130 : }
353 :
354 0 : XclExpImgData::XclExpImgData( const Graphic& rGraphic, sal_uInt16 nRecId ) :
355 : maGraphic( rGraphic ),
356 0 : mnRecId( nRecId )
357 : {
358 0 : }
359 :
360 0 : void XclExpImgData::Save( XclExpStream& rStrm )
361 : {
362 0 : Bitmap aBmp = maGraphic.GetBitmap();
363 0 : if( aBmp.GetBitCount() != 24 )
364 0 : aBmp.Convert( BMP_CONVERSION_24BIT );
365 :
366 0 : if( BitmapReadAccess* pAccess = aBmp.AcquireReadAccess() )
367 : {
368 0 : sal_Int32 nWidth = ::std::min< sal_Int32 >( pAccess->Width(), 0xFFFF );
369 0 : sal_Int32 nHeight = ::std::min< sal_Int32 >( pAccess->Height(), 0xFFFF );
370 0 : if( (nWidth > 0) && (nHeight > 0) )
371 : {
372 0 : sal_uInt8 nPadding = static_cast< sal_uInt8 >( nWidth & 0x03 );
373 0 : sal_uInt32 nTmpSize = static_cast< sal_uInt32 >( (nWidth * 3 + nPadding) * nHeight + 12 );
374 :
375 0 : rStrm.StartRecord( mnRecId, nTmpSize + 4 );
376 :
377 0 : rStrm << EXC_IMGDATA_BMP // BMP format
378 0 : << EXC_IMGDATA_WIN // Windows
379 0 : << nTmpSize // size after _this_ field
380 0 : << sal_uInt32( 12 ) // BITMAPCOREHEADER size
381 0 : << static_cast< sal_uInt16 >( nWidth ) // width
382 0 : << static_cast< sal_uInt16 >( nHeight ) // height
383 0 : << sal_uInt16( 1 ) // planes
384 0 : << sal_uInt16( 24 ); // bits per pixel
385 :
386 0 : for( sal_Int32 nY = nHeight - 1; nY >= 0; --nY )
387 : {
388 0 : for( sal_Int32 nX = 0; nX < nWidth; ++nX )
389 : {
390 0 : const BitmapColor& rBmpColor = pAccess->GetPixel( nY, nX );
391 0 : rStrm << rBmpColor.GetBlue() << rBmpColor.GetGreen() << rBmpColor.GetRed();
392 0 : }
393 0 : rStrm.WriteZeroBytes( nPadding );
394 : }
395 :
396 0 : rStrm.EndRecord();
397 : }
398 0 : aBmp.ReleaseAccess( pAccess );
399 0 : }
400 0 : }
401 :
402 0 : void XclExpImgData::SaveXml( XclExpXmlStream& rStrm )
403 : {
404 0 : sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetCurrentStream();
405 :
406 0 : DrawingML aDML( pWorksheet, &rStrm, DrawingML::DOCUMENT_XLSX );
407 0 : OUString rId = aDML.WriteImage( maGraphic );
408 : pWorksheet->singleElement( XML_picture,
409 : FSNS( XML_r, XML_id ), XclXmlUtils::ToOString( rId ).getStr(),
410 0 : FSEND );
411 0 : }
412 :
413 8 : XclExpControlHelper::XclExpControlHelper( const XclExpRoot& rRoot ) :
414 : XclExpRoot( rRoot ),
415 8 : mnEntryCount( 0 )
416 : {
417 8 : }
418 :
419 8 : XclExpControlHelper::~XclExpControlHelper()
420 : {
421 8 : }
422 :
423 0 : void XclExpControlHelper::ConvertSheetLinks( Reference< XShape > xShape )
424 : {
425 0 : mxCellLink.reset();
426 0 : mxSrcRange.reset();
427 0 : mnEntryCount = 0;
428 :
429 : // get control model
430 0 : Reference< XControlModel > xCtrlModel = XclControlHelper::GetControlModel( xShape );
431 0 : if( !xCtrlModel.is() )
432 0 : return;
433 :
434 : // *** cell link *** ------------------------------------------------------
435 :
436 0 : Reference< XBindableValue > xBindable( xCtrlModel, UNO_QUERY );
437 0 : if( xBindable.is() )
438 : {
439 0 : Reference< XServiceInfo > xServInfo( xBindable->getValueBinding(), UNO_QUERY );
440 0 : if( xServInfo.is() && xServInfo->supportsService( SC_SERVICENAME_VALBIND ) )
441 : {
442 0 : ScfPropertySet aBindProp( xServInfo );
443 0 : CellAddress aApiAddress;
444 0 : if( aBindProp.GetProperty( aApiAddress, SC_UNONAME_BOUNDCELL ) )
445 : {
446 0 : ScAddress aCellLink;
447 0 : ScUnoConversion::FillScAddress( aCellLink, aApiAddress );
448 0 : if( GetTabInfo().IsExportTab( aCellLink.Tab() ) )
449 0 : mxCellLink = GetFormulaCompiler().CreateFormula( EXC_FMLATYPE_CONTROL, aCellLink );
450 0 : }
451 0 : }
452 : }
453 :
454 : // *** source range *** ---------------------------------------------------
455 :
456 0 : Reference< XListEntrySink > xEntrySink( xCtrlModel, UNO_QUERY );
457 0 : if( xEntrySink.is() )
458 : {
459 0 : Reference< XServiceInfo > xServInfo( xEntrySink->getListEntrySource(), UNO_QUERY );
460 0 : if( xServInfo.is() && xServInfo->supportsService( SC_SERVICENAME_LISTSOURCE ) )
461 : {
462 0 : ScfPropertySet aSinkProp( xServInfo );
463 0 : CellRangeAddress aApiRange;
464 0 : if( aSinkProp.GetProperty( aApiRange, SC_UNONAME_CELLRANGE ) )
465 : {
466 0 : ScRange aSrcRange;
467 0 : ScUnoConversion::FillScRange( aSrcRange, aApiRange );
468 0 : if( (aSrcRange.aStart.Tab() == aSrcRange.aEnd.Tab()) && GetTabInfo().IsExportTab( aSrcRange.aStart.Tab() ) )
469 0 : mxSrcRange = GetFormulaCompiler().CreateFormula( EXC_FMLATYPE_CONTROL, aSrcRange );
470 0 : mnEntryCount = static_cast< sal_uInt16 >( aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1 );
471 0 : }
472 0 : }
473 0 : }
474 : }
475 :
476 0 : void XclExpControlHelper::WriteFormula( XclExpStream& rStrm, const XclTokenArray& rTokArr ) const
477 : {
478 0 : sal_uInt16 nFmlaSize = rTokArr.GetSize();
479 0 : rStrm << nFmlaSize << sal_uInt32( 0 );
480 0 : rTokArr.WriteArray( rStrm );
481 0 : if( nFmlaSize & 1 ) // pad to 16-bit
482 0 : rStrm << sal_uInt8( 0 );
483 0 : }
484 :
485 0 : void XclExpControlHelper::WriteFormulaSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId, const XclTokenArray& rTokArr ) const
486 : {
487 0 : rStrm.StartRecord( nSubRecId, (rTokArr.GetSize() + 5) & ~1 );
488 0 : WriteFormula( rStrm, rTokArr );
489 0 : rStrm.EndRecord();
490 0 : }
491 :
492 : //delete for exporting OCX
493 : //#if EXC_EXP_OCX_CTRL
494 :
495 0 : XclExpOcxControlObj::XclExpOcxControlObj( XclExpObjectManager& rObjMgr, Reference< XShape > xShape,
496 : const Rectangle* pChildAnchor, const OUString& rClassName, sal_uInt32 nStrmStart, sal_uInt32 nStrmSize ) :
497 : XclObj( rObjMgr, EXC_OBJTYPE_PICTURE, true ),
498 0 : XclExpControlHelper( rObjMgr.GetRoot() ),
499 : maClassName( rClassName ),
500 : mnStrmStart( nStrmStart ),
501 0 : mnStrmSize( nStrmSize )
502 : {
503 0 : ScfPropertySet aCtrlProp( XclControlHelper::GetControlModel( xShape ) );
504 :
505 : // OBJ record flags
506 0 : SetLocked( true );
507 0 : SetPrintable( aCtrlProp.GetBoolProperty( "Printable" ) );
508 0 : SetAutoFill( false );
509 0 : SetAutoLine( false );
510 :
511 : // fill DFF property set
512 0 : mrEscherEx.OpenContainer( ESCHER_SpContainer );
513 0 : mrEscherEx.AddShape( ESCHER_ShpInst_HostControl, SHAPEFLAG_HAVESPT | SHAPEFLAG_HAVEANCHOR | SHAPEFLAG_OLESHAPE );
514 0 : Rectangle aDummyRect;
515 0 : EscherPropertyContainer aPropOpt( mrEscherEx.GetGraphicProvider(), mrEscherEx.QueryPictureStream(), aDummyRect );
516 0 : aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape, 0x00080008 ); // bool field
517 0 : aPropOpt.AddOpt( ESCHER_Prop_lineColor, 0x08000040 );
518 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x00080000 ); // bool field
519 :
520 : // #i51348# name of the control, may overwrite shape name
521 0 : OUString aCtrlName;
522 0 : if( aCtrlProp.GetProperty( aCtrlName, "Name" ) && !aCtrlName.isEmpty() )
523 0 : aPropOpt.AddOpt( ESCHER_Prop_wzName, aCtrlName );
524 :
525 : // meta file
526 : //! TODO - needs check
527 0 : Reference< XPropertySet > xShapePS( xShape, UNO_QUERY );
528 0 : if( xShapePS.is() && aPropOpt.CreateGraphicProperties( xShapePS, OUString( "MetaFile" ), false ) )
529 : {
530 : sal_uInt32 nBlipId;
531 0 : if( aPropOpt.GetOpt( ESCHER_Prop_pib, nBlipId ) )
532 0 : aPropOpt.AddOpt( ESCHER_Prop_pictureId, nBlipId );
533 : }
534 :
535 : // write DFF property set to stream
536 0 : aPropOpt.Commit( mrEscherEx.GetStream() );
537 :
538 : // anchor
539 0 : ImplWriteAnchor( GetRoot(), SdrObject::getSdrObjectFromXShape( xShape ), pChildAnchor );
540 :
541 0 : mrEscherEx.AddAtom( 0, ESCHER_ClientData ); // OBJ record
542 0 : mrEscherEx.CloseContainer(); // ESCHER_SpContainer
543 0 : mrEscherEx.UpdateDffFragmentEnd();
544 :
545 : // spreadsheet links
546 0 : ConvertSheetLinks( xShape );
547 0 : }
548 :
549 0 : void XclExpOcxControlObj::WriteSubRecs( XclExpStream& rStrm )
550 : {
551 : // OBJCF - clipboard format
552 0 : rStrm.StartRecord( EXC_ID_OBJCF, 2 );
553 0 : rStrm << sal_uInt16( 2 );
554 0 : rStrm.EndRecord();
555 :
556 : // OBJFLAGS
557 0 : rStrm.StartRecord( EXC_ID_OBJFLAGS, 2 );
558 0 : rStrm << sal_uInt16( 0x0031 );
559 0 : rStrm.EndRecord();
560 :
561 : // OBJPICTFMLA
562 0 : XclExpString aClass( maClassName );
563 0 : sal_uInt16 nClassNameSize = static_cast< sal_uInt16 >( aClass.GetSize() );
564 0 : sal_uInt16 nClassNamePad = nClassNameSize & 1;
565 0 : sal_uInt16 nFirstPartSize = 12 + nClassNameSize + nClassNamePad;
566 :
567 0 : const XclTokenArray* pCellLink = GetCellLinkTokArr();
568 0 : sal_uInt16 nCellLinkSize = pCellLink ? ((pCellLink->GetSize() + 7) & 0xFFFE) : 0;
569 :
570 0 : const XclTokenArray* pSrcRange = GetSourceRangeTokArr();
571 0 : sal_uInt16 nSrcRangeSize = pSrcRange ? ((pSrcRange->GetSize() + 7) & 0xFFFE) : 0;
572 :
573 0 : sal_uInt16 nPictFmlaSize = nFirstPartSize + nCellLinkSize + nSrcRangeSize + 18;
574 0 : rStrm.StartRecord( EXC_ID_OBJPICTFMLA, nPictFmlaSize );
575 :
576 0 : rStrm << sal_uInt16( nFirstPartSize ) // size of first part
577 0 : << sal_uInt16( 5 ) // formula size
578 0 : << sal_uInt32( 0 ) // unknown ID
579 0 : << sal_uInt8( 0x02 ) << sal_uInt32( 0 ) // tTbl token with unknown ID
580 0 : << sal_uInt8( 3 ) // pad to word
581 0 : << aClass; // "Forms.***.1"
582 0 : rStrm.WriteZeroBytes( nClassNamePad ); // pad to word
583 0 : rStrm << mnStrmStart // start in 'Ctls' stream
584 0 : << mnStrmSize // size in 'Ctls' stream
585 0 : << sal_uInt32( 0 ); // class ID size
586 : // cell link
587 0 : rStrm << nCellLinkSize;
588 0 : if( pCellLink )
589 0 : WriteFormula( rStrm, *pCellLink );
590 : // list source range
591 0 : rStrm << nSrcRangeSize;
592 0 : if( pSrcRange )
593 0 : WriteFormula( rStrm, *pSrcRange );
594 :
595 0 : rStrm.EndRecord();
596 0 : }
597 :
598 : //#else
599 :
600 0 : XclExpTbxControlObj::XclExpTbxControlObj( XclExpObjectManager& rRoot, Reference< XShape > xShape , const Rectangle* pChildAnchor ) :
601 : XclObj( rRoot, EXC_OBJTYPE_UNKNOWN, true ),
602 : XclMacroHelper( rRoot ),
603 : meEventType( EXC_TBX_EVENT_ACTION ),
604 : mnHeight( 0 ),
605 : mnState( 0 ),
606 : mnLineCount( 0 ),
607 : mnSelEntry( 0 ),
608 : mnScrollValue( 0 ),
609 : mnScrollMin( 0 ),
610 : mnScrollMax( 100 ),
611 : mnScrollStep( 1 ),
612 : mnScrollPage( 10 ),
613 : mbFlatButton( false ),
614 : mbFlatBorder( false ),
615 : mbMultiSel( false ),
616 0 : mbScrollHor( false )
617 : {
618 : namespace FormCompType = ::com::sun::star::form::FormComponentType;
619 : namespace AwtVisualEffect = ::com::sun::star::awt::VisualEffect;
620 : namespace AwtScrollOrient = ::com::sun::star::awt::ScrollBarOrientation;
621 :
622 0 : ScfPropertySet aCtrlProp( XclControlHelper::GetControlModel( xShape ) );
623 0 : if( !xShape.is() || !aCtrlProp.Is() )
624 0 : return;
625 :
626 0 : mnHeight = xShape->getSize().Height;
627 0 : if( mnHeight <= 0 )
628 0 : return;
629 :
630 : // control type
631 0 : sal_Int16 nClassId = 0;
632 0 : if( aCtrlProp.GetProperty( nClassId, "ClassId" ) )
633 : {
634 0 : switch( nClassId )
635 : {
636 0 : case FormCompType::COMMANDBUTTON: mnObjType = EXC_OBJTYPE_BUTTON; meEventType = EXC_TBX_EVENT_ACTION; break;
637 0 : case FormCompType::RADIOBUTTON: mnObjType = EXC_OBJTYPE_OPTIONBUTTON; meEventType = EXC_TBX_EVENT_ACTION; break;
638 0 : case FormCompType::CHECKBOX: mnObjType = EXC_OBJTYPE_CHECKBOX; meEventType = EXC_TBX_EVENT_ACTION; break;
639 0 : case FormCompType::LISTBOX: mnObjType = EXC_OBJTYPE_LISTBOX; meEventType = EXC_TBX_EVENT_CHANGE; break;
640 0 : case FormCompType::COMBOBOX: mnObjType = EXC_OBJTYPE_DROPDOWN; meEventType = EXC_TBX_EVENT_CHANGE; break;
641 0 : case FormCompType::GROUPBOX: mnObjType = EXC_OBJTYPE_GROUPBOX; meEventType = EXC_TBX_EVENT_MOUSE; break;
642 0 : case FormCompType::FIXEDTEXT: mnObjType = EXC_OBJTYPE_LABEL; meEventType = EXC_TBX_EVENT_MOUSE; break;
643 0 : case FormCompType::SCROLLBAR: mnObjType = EXC_OBJTYPE_SCROLLBAR; meEventType = EXC_TBX_EVENT_VALUE; break;
644 0 : case FormCompType::SPINBUTTON: mnObjType = EXC_OBJTYPE_SPIN; meEventType = EXC_TBX_EVENT_VALUE; break;
645 : }
646 : }
647 0 : if( mnObjType == EXC_OBJTYPE_UNKNOWN )
648 0 : return;
649 :
650 : // OBJ record flags
651 0 : SetLocked( true );
652 0 : SetPrintable( aCtrlProp.GetBoolProperty( "Printable" ) );
653 0 : SetAutoFill( false );
654 0 : SetAutoLine( false );
655 :
656 : // fill DFF property set
657 0 : mrEscherEx.OpenContainer( ESCHER_SpContainer );
658 0 : mrEscherEx.AddShape( ESCHER_ShpInst_HostControl, SHAPEFLAG_HAVEANCHOR | SHAPEFLAG_HAVESPT );
659 0 : EscherPropertyContainer aPropOpt;
660 0 : bool bVisible = aCtrlProp.GetBoolProperty( "EnableVisible" );
661 0 : aPropOpt.AddOpt( ESCHER_Prop_fPrint, bVisible ? 0x00080000 : 0x00080002 ); // visible flag
662 :
663 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x01000100 ); // bool field
664 0 : aPropOpt.AddOpt( ESCHER_Prop_lTxid, 0 ); // Text ID
665 0 : aPropOpt.AddOpt( ESCHER_Prop_WrapText, 0x00000001 );
666 0 : aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape, 0x001A0008 ); // bool field
667 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x00100000 ); // bool field
668 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x00080000 ); // bool field
669 :
670 : // #i51348# name of the control, may overwrite shape name
671 0 : OUString aCtrlName;
672 0 : if( aCtrlProp.GetProperty( aCtrlName, "Name" ) && !aCtrlName.isEmpty() )
673 0 : aPropOpt.AddOpt( ESCHER_Prop_wzName, aCtrlName );
674 :
675 : //Export description as alt text
676 0 : if( SdrObject* pSdrObj = SdrObject::getSdrObjectFromXShape( xShape ) )
677 : {
678 0 : OUString aAltTxt;
679 0 : OUString aDescrText = pSdrObj->GetDescription();
680 0 : if(!aDescrText.isEmpty())
681 0 : aAltTxt = aDescrText.copy( 0, std::min<sal_Int32>(MSPROP_DESCRIPTION_MAX_LEN, aDescrText.getLength()) );
682 0 : aPropOpt.AddOpt( ESCHER_Prop_wzDescription, aAltTxt );
683 : }
684 :
685 : // write DFF property set to stream
686 0 : aPropOpt.Commit( mrEscherEx.GetStream() );
687 :
688 : // anchor
689 0 : ImplWriteAnchor( GetRoot(), SdrObject::getSdrObjectFromXShape( xShape ), pChildAnchor );
690 :
691 0 : mrEscherEx.AddAtom( 0, ESCHER_ClientData ); // OBJ record
692 0 : mrEscherEx.UpdateDffFragmentEnd();
693 :
694 : // control label
695 0 : OUString aString;
696 0 : if( aCtrlProp.GetProperty( aString, "Label" ) )
697 : {
698 : /* Be sure to construct the MSODRAWING record containing the
699 : ClientTextbox atom after the base OBJ's MSODRAWING record data is
700 : completed. */
701 0 : pClientTextbox = new XclExpMsoDrawing( mrEscherEx );
702 0 : mrEscherEx.AddAtom( 0, ESCHER_ClientTextbox ); // TXO record
703 0 : mrEscherEx.UpdateDffFragmentEnd();
704 :
705 0 : sal_uInt16 nXclFont = EXC_FONT_APP;
706 0 : if( !aString.isEmpty() )
707 : {
708 0 : XclFontData aFontData;
709 0 : GetFontPropSetHelper().ReadFontProperties( aFontData, aCtrlProp, EXC_FONTPROPSET_CONTROL );
710 0 : if( (!aFontData.maName.isEmpty() ) && (aFontData.mnHeight > 0) )
711 0 : nXclFont = GetFontBuffer().Insert( aFontData, EXC_COLOR_CTRLTEXT );
712 : }
713 :
714 0 : pTxo = new XclTxo( aString, nXclFont );
715 0 : pTxo->SetHorAlign( (mnObjType == EXC_OBJTYPE_BUTTON) ? EXC_OBJ_HOR_CENTER : EXC_OBJ_HOR_LEFT );
716 0 : pTxo->SetVerAlign( EXC_OBJ_VER_CENTER );
717 : }
718 :
719 0 : mrEscherEx.CloseContainer(); // ESCHER_SpContainer
720 :
721 : // other properties
722 0 : aCtrlProp.GetProperty( mnLineCount, "LineCount" );
723 :
724 : // border style
725 0 : sal_Int16 nApiButton = AwtVisualEffect::LOOK3D;
726 0 : sal_Int16 nApiBorder = AwtVisualEffect::LOOK3D;
727 0 : switch( nClassId )
728 : {
729 : case FormCompType::LISTBOX:
730 : case FormCompType::COMBOBOX:
731 0 : aCtrlProp.GetProperty( nApiBorder, "Border" );
732 0 : break;
733 : case FormCompType::CHECKBOX:
734 : case FormCompType::RADIOBUTTON:
735 0 : aCtrlProp.GetProperty( nApiButton, "VisualEffect" );
736 0 : nApiBorder = AwtVisualEffect::NONE;
737 0 : break;
738 : // Push button cannot be set to flat in Excel
739 : case FormCompType::COMMANDBUTTON:
740 0 : nApiBorder = AwtVisualEffect::LOOK3D;
741 0 : break;
742 : // Label does not support a border in Excel
743 : case FormCompType::FIXEDTEXT:
744 0 : nApiBorder = AwtVisualEffect::NONE;
745 0 : break;
746 : /* Scroll bar and spin button have a "Border" property, but it is
747 : really used for a border, and not for own 3D/flat look (#i34712#). */
748 : case FormCompType::SCROLLBAR:
749 : case FormCompType::SPINBUTTON:
750 0 : nApiButton = AwtVisualEffect::LOOK3D;
751 0 : nApiBorder = AwtVisualEffect::NONE;
752 0 : break;
753 : // Group box does not support flat style (#i34712#)
754 : case FormCompType::GROUPBOX:
755 0 : nApiBorder = AwtVisualEffect::LOOK3D;
756 0 : break;
757 : }
758 0 : mbFlatButton = nApiButton != AwtVisualEffect::LOOK3D;
759 0 : mbFlatBorder = nApiBorder != AwtVisualEffect::LOOK3D;
760 :
761 : // control state
762 0 : sal_Int16 nApiState = 0;
763 0 : if( aCtrlProp.GetProperty( nApiState, "State" ) )
764 : {
765 0 : switch( nApiState )
766 : {
767 0 : case 0: mnState = EXC_OBJ_CHECKBOX_UNCHECKED; break;
768 0 : case 1: mnState = EXC_OBJ_CHECKBOX_CHECKED; break;
769 0 : case 2: mnState = EXC_OBJ_CHECKBOX_TRISTATE; break;
770 : }
771 : }
772 :
773 : // special control contents
774 0 : switch( nClassId )
775 : {
776 : case FormCompType::LISTBOX:
777 : {
778 0 : mbMultiSel = aCtrlProp.GetBoolProperty( "MultiSelection" );
779 0 : Sequence< sal_Int16 > aSelection;
780 0 : if( aCtrlProp.GetProperty( aSelection, "SelectedItems" ) )
781 : {
782 0 : sal_Int32 nLen = aSelection.getLength();
783 0 : if( nLen > 0 )
784 : {
785 0 : mnSelEntry = aSelection[ 0 ] + 1;
786 0 : maMultiSel.resize( nLen );
787 0 : const sal_Int16* pnBegin = aSelection.getConstArray();
788 0 : ::std::copy( pnBegin, pnBegin + nLen, maMultiSel.begin() );
789 : }
790 : }
791 :
792 : // convert listbox with dropdown button to Excel dropdown
793 0 : if( aCtrlProp.GetBoolProperty( "Dropdown" ) )
794 0 : mnObjType = EXC_OBJTYPE_DROPDOWN;
795 : }
796 0 : break;
797 :
798 : case FormCompType::COMBOBOX:
799 : {
800 0 : Sequence< OUString > aStringList;
801 0 : OUString aDefText;
802 0 : if( aCtrlProp.GetProperty( aStringList, "StringItemList" ) &&
803 0 : aCtrlProp.GetProperty( aDefText, "Text" ) &&
804 0 : aStringList.getLength() && !aDefText.isEmpty() )
805 : {
806 0 : const OUString* pBegin = aStringList.getConstArray();
807 0 : const OUString* pEnd = pBegin + aStringList.getLength();
808 0 : const OUString* pString = ::std::find( pBegin, pEnd, aDefText );
809 0 : if( pString != pEnd )
810 0 : mnSelEntry = static_cast< sal_Int16 >( pString - pBegin + 1 ); // 1-based
811 0 : if( mnSelEntry > 0 )
812 0 : maMultiSel.resize( 1, mnSelEntry - 1 );
813 : }
814 :
815 : // convert combobox without dropdown button to Excel listbox
816 0 : if( !aCtrlProp.GetBoolProperty( "Dropdown" ) )
817 0 : mnObjType = EXC_OBJTYPE_LISTBOX;
818 : }
819 0 : break;
820 :
821 : case FormCompType::SCROLLBAR:
822 : {
823 0 : sal_Int32 nApiValue = 0;
824 0 : if( aCtrlProp.GetProperty( nApiValue, "ScrollValueMin" ) )
825 0 : mnScrollMin = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
826 0 : if( aCtrlProp.GetProperty( nApiValue, "ScrollValueMax" ) )
827 0 : mnScrollMax = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, EXC_OBJ_SCROLLBAR_MIN );
828 0 : if( aCtrlProp.GetProperty( nApiValue, "ScrollValue" ) )
829 0 : mnScrollValue = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, mnScrollMax );
830 0 : if( aCtrlProp.GetProperty( nApiValue, "LineIncrement" ) )
831 0 : mnScrollStep = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
832 0 : if( aCtrlProp.GetProperty( nApiValue, "BlockIncrement" ) )
833 0 : mnScrollPage = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
834 0 : if( aCtrlProp.GetProperty( nApiValue, "Orientation" ) )
835 0 : mbScrollHor = nApiValue == AwtScrollOrient::HORIZONTAL;
836 : }
837 0 : break;
838 :
839 : case FormCompType::SPINBUTTON:
840 : {
841 0 : sal_Int32 nApiValue = 0;
842 0 : if( aCtrlProp.GetProperty( nApiValue, "SpinValueMin" ) )
843 0 : mnScrollMin = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
844 0 : if( aCtrlProp.GetProperty( nApiValue, "SpinValueMax" ) )
845 0 : mnScrollMax = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, EXC_OBJ_SCROLLBAR_MAX );
846 0 : if( aCtrlProp.GetProperty( nApiValue, "SpinValue" ) )
847 0 : mnScrollValue = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, mnScrollMax );
848 0 : if( aCtrlProp.GetProperty( nApiValue, "SpinIncrement" ) )
849 0 : mnScrollStep = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
850 0 : if( aCtrlProp.GetProperty( nApiValue, "Orientation" ) )
851 0 : mbScrollHor = nApiValue == AwtScrollOrient::HORIZONTAL;
852 : }
853 0 : break;
854 : }
855 :
856 : // spreadsheet links
857 0 : ConvertSheetLinks( xShape );
858 : }
859 :
860 0 : bool XclExpTbxControlObj::SetMacroLink( const ScriptEventDescriptor& rEvent )
861 : {
862 0 : return XclMacroHelper::SetMacroLink( rEvent, meEventType );
863 : }
864 :
865 0 : void XclExpTbxControlObj::WriteSubRecs( XclExpStream& rStrm )
866 : {
867 0 : switch( mnObjType )
868 : {
869 : // *** Push buttons, labels ***
870 :
871 : case EXC_OBJTYPE_BUTTON:
872 : case EXC_OBJTYPE_LABEL:
873 : // ftMacro - macro link
874 0 : WriteMacroSubRec( rStrm );
875 0 : break;
876 :
877 : // *** Check boxes, option buttons ***
878 :
879 : case EXC_OBJTYPE_CHECKBOX:
880 : case EXC_OBJTYPE_OPTIONBUTTON:
881 : {
882 : // ftCbls - box properties
883 0 : sal_uInt16 nStyle = 0;
884 0 : ::set_flag( nStyle, EXC_OBJ_CHECKBOX_FLAT, mbFlatButton );
885 :
886 0 : rStrm.StartRecord( EXC_ID_OBJCBLS, 12 );
887 0 : rStrm << mnState;
888 0 : rStrm.WriteZeroBytes( 8 );
889 0 : rStrm << nStyle;
890 0 : rStrm.EndRecord();
891 :
892 : // ftMacro - macro link
893 0 : WriteMacroSubRec( rStrm );
894 : // ftCblsFmla subrecord - cell link
895 0 : WriteCellLinkSubRec( rStrm, EXC_ID_OBJCBLSFMLA );
896 :
897 : // ftCblsData subrecord - box properties, again
898 0 : rStrm.StartRecord( EXC_ID_OBJCBLS, 8 );
899 0 : rStrm << mnState;
900 0 : rStrm.WriteZeroBytes( 4 );
901 0 : rStrm << nStyle;
902 0 : rStrm.EndRecord();
903 : }
904 0 : break;
905 :
906 : // *** List boxes, combo boxes ***
907 :
908 : case EXC_OBJTYPE_LISTBOX:
909 : case EXC_OBJTYPE_DROPDOWN:
910 : {
911 0 : sal_uInt16 nEntryCount = GetSourceEntryCount();
912 :
913 : // ftSbs subrecord - Scroll bars
914 0 : sal_Int32 nLineHeight = XclTools::GetHmmFromTwips( 200 ); // always 10pt
915 0 : if( mnObjType == EXC_OBJTYPE_LISTBOX )
916 0 : mnLineCount = static_cast< sal_uInt16 >( mnHeight / nLineHeight );
917 0 : mnScrollValue = 0;
918 0 : mnScrollMin = 0;
919 0 : sal_uInt16 nInvisLines = (nEntryCount >= mnLineCount) ? (nEntryCount - mnLineCount) : 0;
920 0 : mnScrollMax = limit_cast< sal_uInt16 >( nInvisLines, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
921 0 : mnScrollStep = 1;
922 0 : mnScrollPage = limit_cast< sal_uInt16 >( mnLineCount, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
923 0 : mbScrollHor = false;
924 0 : WriteSbs( rStrm );
925 :
926 : // ftMacro - macro link
927 0 : WriteMacroSubRec( rStrm );
928 : // ftSbsFmla subrecord - cell link
929 0 : WriteCellLinkSubRec( rStrm, EXC_ID_OBJSBSFMLA );
930 :
931 : // ftLbsData - source data range and box properties
932 0 : sal_uInt16 nStyle = 0;
933 0 : ::insert_value( nStyle, mbMultiSel ? EXC_OBJ_LISTBOX_MULTI : EXC_OBJ_LISTBOX_SINGLE, 4, 2 );
934 0 : ::set_flag( nStyle, EXC_OBJ_LISTBOX_FLAT, mbFlatBorder );
935 :
936 0 : rStrm.StartRecord( EXC_ID_OBJLBSDATA, 0 );
937 :
938 0 : if( const XclTokenArray* pSrcRange = GetSourceRangeTokArr() )
939 : {
940 0 : rStrm << static_cast< sal_uInt16 >( (pSrcRange->GetSize() + 7) & 0xFFFE );
941 0 : WriteFormula( rStrm, *pSrcRange );
942 : }
943 : else
944 0 : rStrm << sal_uInt16( 0 );
945 :
946 0 : rStrm << nEntryCount << mnSelEntry << nStyle << sal_uInt16( 0 );
947 0 : if( mnObjType == EXC_OBJTYPE_LISTBOX )
948 : {
949 0 : if( nEntryCount )
950 : {
951 0 : ScfUInt8Vec aSelEx( nEntryCount, 0 );
952 0 : for( ScfInt16Vec::const_iterator aIt = maMultiSel.begin(), aEnd = maMultiSel.end(); aIt != aEnd; ++aIt )
953 0 : if( *aIt < nEntryCount )
954 0 : aSelEx[ *aIt ] = 1;
955 0 : rStrm.Write( &aSelEx[ 0 ], aSelEx.size() );
956 : }
957 : }
958 0 : else if( mnObjType == EXC_OBJTYPE_DROPDOWN )
959 : {
960 0 : rStrm << sal_uInt16( 0 ) << mnLineCount << sal_uInt16( 0 ) << sal_uInt16( 0 );
961 : }
962 :
963 0 : rStrm.EndRecord();
964 : }
965 0 : break;
966 :
967 : // *** Spin buttons, scrollbars ***
968 :
969 : case EXC_OBJTYPE_SPIN:
970 : case EXC_OBJTYPE_SCROLLBAR:
971 : {
972 : // ftSbs subrecord - scroll bars
973 0 : WriteSbs( rStrm );
974 : // ftMacro - macro link
975 0 : WriteMacroSubRec( rStrm );
976 : // ftSbsFmla subrecord - cell link
977 0 : WriteCellLinkSubRec( rStrm, EXC_ID_OBJSBSFMLA );
978 : }
979 0 : break;
980 :
981 : // *** Group boxes ***
982 :
983 : case EXC_OBJTYPE_GROUPBOX:
984 : {
985 : // ftMacro - macro link
986 0 : WriteMacroSubRec( rStrm );
987 :
988 : // ftGboData subrecord - group box properties
989 0 : sal_uInt16 nStyle = 0;
990 0 : ::set_flag( nStyle, EXC_OBJ_GROUPBOX_FLAT, mbFlatBorder );
991 :
992 0 : rStrm.StartRecord( EXC_ID_OBJGBODATA, 6 );
993 0 : rStrm << sal_uInt32( 0 )
994 0 : << nStyle;
995 0 : rStrm.EndRecord();
996 : }
997 0 : break;
998 : }
999 0 : }
1000 :
1001 0 : void XclExpTbxControlObj::WriteCellLinkSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId )
1002 : {
1003 0 : if( const XclTokenArray* pCellLink = GetCellLinkTokArr() )
1004 0 : WriteFormulaSubRec( rStrm, nSubRecId, *pCellLink );
1005 0 : }
1006 :
1007 0 : void XclExpTbxControlObj::WriteSbs( XclExpStream& rStrm )
1008 : {
1009 0 : sal_uInt16 nOrient = 0;
1010 0 : ::set_flag( nOrient, EXC_OBJ_SCROLLBAR_HOR, mbScrollHor );
1011 0 : sal_uInt16 nStyle = EXC_OBJ_SCROLLBAR_DEFFLAGS;
1012 0 : ::set_flag( nStyle, EXC_OBJ_SCROLLBAR_FLAT, mbFlatButton );
1013 :
1014 0 : rStrm.StartRecord( EXC_ID_OBJSBS, 20 );
1015 0 : rStrm << sal_uInt32( 0 ) // reserved
1016 0 : << mnScrollValue // thumb position
1017 0 : << mnScrollMin // thumb min pos
1018 0 : << mnScrollMax // thumb max pos
1019 0 : << mnScrollStep // line increment
1020 0 : << mnScrollPage // page increment
1021 0 : << nOrient // 0 = vertical, 1 = horizontal
1022 0 : << sal_uInt16( 15 ) // thumb width
1023 0 : << nStyle; // flags/style
1024 0 : rStrm.EndRecord();
1025 0 : }
1026 :
1027 : //#endif
1028 :
1029 16 : XclExpChartObj::XclExpChartObj( XclExpObjectManager& rObjMgr, Reference< XShape > xShape, const Rectangle* pChildAnchor ) :
1030 : XclObj( rObjMgr, EXC_OBJTYPE_CHART ),
1031 16 : XclExpRoot( rObjMgr.GetRoot() ), mxShape( xShape )
1032 : {
1033 : // create the MSODRAWING record contents for the chart object
1034 16 : mrEscherEx.OpenContainer( ESCHER_SpContainer );
1035 16 : mrEscherEx.AddShape( ESCHER_ShpInst_HostControl, SHAPEFLAG_HAVEANCHOR | SHAPEFLAG_HAVESPT );
1036 16 : EscherPropertyContainer aPropOpt;
1037 16 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x01040104 );
1038 16 : aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape, 0x00080008 );
1039 16 : aPropOpt.AddOpt( ESCHER_Prop_fillColor, 0x0800004E );
1040 16 : aPropOpt.AddOpt( ESCHER_Prop_fillBackColor, 0x0800004D );
1041 16 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x00110010 );
1042 16 : aPropOpt.AddOpt( ESCHER_Prop_lineColor, 0x0800004D );
1043 16 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x00080008 );
1044 16 : aPropOpt.AddOpt( ESCHER_Prop_fshadowObscured, 0x00020000 );
1045 16 : aPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x00080000 );
1046 16 : aPropOpt.Commit( mrEscherEx.GetStream() );
1047 :
1048 : // anchor
1049 16 : SdrObject* pSdrObj = SdrObject::getSdrObjectFromXShape( xShape );
1050 16 : ImplWriteAnchor( GetRoot(), pSdrObj, pChildAnchor );
1051 :
1052 : // client data (the following OBJ record)
1053 16 : mrEscherEx.AddAtom( 0, ESCHER_ClientData );
1054 16 : mrEscherEx.CloseContainer(); // ESCHER_SpContainer
1055 16 : mrEscherEx.UpdateDffFragmentEnd();
1056 :
1057 : // load the chart OLE object
1058 16 : if( SdrOle2Obj* pSdrOleObj = dynamic_cast< SdrOle2Obj* >( pSdrObj ) )
1059 16 : svt::EmbeddedObjectRef::TryRunningState( pSdrOleObj->GetObjRef() );
1060 :
1061 : // create the chart substream object
1062 32 : ScfPropertySet aShapeProp( xShape );
1063 32 : Reference< XModel > xModel;
1064 16 : aShapeProp.GetProperty( xModel, "Model" );
1065 16 : mxChartDoc.set( xModel,UNO_QUERY );
1066 16 : ::com::sun::star::awt::Rectangle aBoundRect;
1067 16 : aShapeProp.GetProperty( aBoundRect, "BoundRect" );
1068 16 : Rectangle aChartRect( Point( aBoundRect.X, aBoundRect.Y ), Size( aBoundRect.Width, aBoundRect.Height ) );
1069 32 : mxChart.reset( new XclExpChart( GetRoot(), xModel, aChartRect ) );
1070 16 : }
1071 :
1072 32 : XclExpChartObj::~XclExpChartObj()
1073 : {
1074 32 : }
1075 :
1076 4 : void XclExpChartObj::Save( XclExpStream& rStrm )
1077 : {
1078 : // content of OBJ record
1079 4 : XclObj::Save( rStrm );
1080 : // chart substream
1081 4 : mxChart->Save( rStrm );
1082 4 : }
1083 :
1084 12 : void XclExpChartObj::SaveXml( XclExpXmlStream& rStrm )
1085 : {
1086 : OSL_TRACE("XclExpChartObj::SaveXml -- Entry point to export chart");
1087 12 : sax_fastparser::FSHelperPtr pDrawing = rStrm.GetCurrentStream();
1088 :
1089 : // FIXME: two cell? it seems the two cell anchor is incorrect.
1090 : pDrawing->startElement( FSNS( XML_xdr, XML_twoCellAnchor ), // OOXTODO: oneCellAnchor, absoluteAnchor
1091 : XML_editAs, "oneCell",
1092 12 : FSEND );
1093 24 : Reference< XPropertySet > xPropSet( mxShape, UNO_QUERY );
1094 12 : if (xPropSet.is())
1095 : {
1096 12 : XclObjAny::WriteFromTo( rStrm, mxShape, GetTab() );
1097 12 : Reference< XModel > xModel( mxChartDoc, UNO_QUERY );
1098 24 : ChartExport aChartExport( XML_xdr, pDrawing, xModel, &rStrm, DrawingML::DOCUMENT_XLSX );
1099 : static sal_Int32 nChartCount = 0;
1100 12 : nChartCount++;
1101 24 : aChartExport.WriteChartObj( mxShape, nChartCount );
1102 : // TODO: get the correcto chart number
1103 : }
1104 :
1105 : pDrawing->singleElement( FSNS( XML_xdr, XML_clientData),
1106 : // OOXTODO: XML_fLocksWithSheet
1107 : // OOXTODO: XML_fPrintsWithSheet
1108 12 : FSEND );
1109 24 : pDrawing->endElement( FSNS( XML_xdr, XML_twoCellAnchor ) );
1110 12 : }
1111 :
1112 0 : void XclExpChartObj::WriteChartObj( sax_fastparser::FSHelperPtr pDrawing, XclExpXmlStream& rStrm )
1113 : {
1114 0 : pDrawing->startElement( FSNS( XML_xdr, XML_graphicFrame ), FSEND );
1115 :
1116 0 : pDrawing->startElement( FSNS( XML_xdr, XML_nvGraphicFramePr ), FSEND );
1117 :
1118 : // TODO: get the correct chart name chart id
1119 0 : OUString sName = "Object 1";
1120 0 : Reference< XNamed > xNamed( mxShape, UNO_QUERY );
1121 0 : if (xNamed.is())
1122 : {
1123 0 : sName = xNamed->getName();
1124 : }
1125 0 : sal_Int32 nID = rStrm.GetUniqueId();
1126 :
1127 : pDrawing->singleElement( FSNS( XML_xdr, XML_cNvPr ),
1128 : XML_id, I32S( nID ),
1129 : XML_name, USS( sName ),
1130 0 : FSEND );
1131 :
1132 : pDrawing->singleElement( FSNS( XML_xdr, XML_cNvGraphicFramePr ),
1133 0 : FSEND );
1134 :
1135 0 : pDrawing->endElement( FSNS( XML_xdr, XML_nvGraphicFramePr ) );
1136 :
1137 : // visual chart properties
1138 0 : WriteShapeTransformation( pDrawing, mxShape );
1139 :
1140 : // writer chart object
1141 0 : pDrawing->startElement( FSNS( XML_a, XML_graphic ), FSEND );
1142 : pDrawing->startElement( FSNS( XML_a, XML_graphicData ),
1143 : XML_uri, "http://schemas.openxmlformats.org/drawingml/2006/chart",
1144 0 : FSEND );
1145 0 : OUString sId;
1146 : // TODO:
1147 : static sal_Int32 nChartCount = 0;
1148 0 : nChartCount++;
1149 : sax_fastparser::FSHelperPtr pChart = rStrm.CreateOutputStream(
1150 : XclXmlUtils::GetStreamName( "xl/", "charts/chart", nChartCount ),
1151 : XclXmlUtils::GetStreamName( "../", "charts/chart", nChartCount ),
1152 0 : rStrm.GetCurrentStream()->getOutputStream(),
1153 : "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
1154 : "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
1155 0 : &sId );
1156 :
1157 : pDrawing->singleElement( FSNS( XML_c, XML_chart ),
1158 : FSNS( XML_xmlns, XML_c ), "http://schemas.openxmlformats.org/drawingml/2006/chart",
1159 : FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
1160 : FSNS( XML_r, XML_id ), XclXmlUtils::ToOString( sId ).getStr(),
1161 0 : FSEND );
1162 :
1163 0 : rStrm.PushStream( pChart );
1164 0 : Reference< XModel > xModel( mxChartDoc, UNO_QUERY );
1165 0 : ChartExport aChartExport( XML_xdr, pChart, xModel, &rStrm, DrawingML::DOCUMENT_XLSX );
1166 0 : aChartExport.ExportContent();
1167 :
1168 0 : rStrm.PopStream();
1169 :
1170 0 : pDrawing->endElement( FSNS( XML_a, XML_graphicData ) );
1171 0 : pDrawing->endElement( FSNS( XML_a, XML_graphic ) );
1172 0 : pDrawing->endElement( FSNS( XML_xdr, XML_graphicFrame ) );
1173 :
1174 0 : }
1175 :
1176 0 : void XclExpChartObj::WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS, const XShapeRef& rXShape, bool bFlipH, bool bFlipV, sal_Int32 nRotation )
1177 : {
1178 0 : ::com::sun::star::awt::Point aPos = rXShape->getPosition();
1179 0 : ::com::sun::star::awt::Size aSize = rXShape->getSize();
1180 :
1181 : pFS->startElementNS( XML_xdr, XML_xfrm,
1182 : XML_flipH, bFlipH ? "1" : NULL,
1183 : XML_flipV, bFlipV ? "1" : NULL,
1184 0 : XML_rot, nRotation ? I32S( nRotation ) : NULL,
1185 0 : FSEND );
1186 :
1187 0 : pFS->singleElementNS( XML_a, XML_off, XML_x, IS( MM100toEMU( aPos.X ) ), XML_y, IS( MM100toEMU( aPos.Y ) ), FSEND );
1188 0 : pFS->singleElementNS( XML_a, XML_ext, XML_cx, IS( MM100toEMU( aSize.Width ) ), XML_cy, IS( MM100toEMU( aSize.Height ) ), FSEND );
1189 :
1190 0 : pFS->endElementNS( XML_xdr, XML_xfrm );
1191 0 : }
1192 :
1193 12 : const css::uno::Reference<css::chart::XChartDocument>& XclExpChartObj::GetChartDoc() const
1194 : {
1195 12 : return mxChartDoc;
1196 : }
1197 :
1198 6 : XclExpNote::XclExpNote( const XclExpRoot& rRoot, const ScAddress& rScPos,
1199 : const ScPostIt* pScNote, const OUString& rAddText ) :
1200 : XclExpRecord( EXC_ID_NOTE ),
1201 : maScPos( rScPos ),
1202 : mnObjId( EXC_OBJ_INVALID_ID ),
1203 6 : mbVisible( pScNote && pScNote->IsCaptionShown() )
1204 : {
1205 : // get the main note text
1206 6 : OUString aNoteText;
1207 6 : if( pScNote )
1208 : {
1209 6 : aNoteText = pScNote->GetText();
1210 6 : const EditTextObject *pEditObj = pScNote->GetEditTextObject();
1211 6 : if( pEditObj )
1212 6 : mpNoteContents = XclExpStringHelper::CreateString( rRoot, *pEditObj );
1213 : }
1214 : // append additional text
1215 6 : aNoteText = ScGlobal::addToken( aNoteText, rAddText, '\n', 2 );
1216 6 : maOrigNoteText = aNoteText;
1217 :
1218 : // initialize record dependent on BIFF type
1219 6 : switch( rRoot.GetBiff() )
1220 : {
1221 : case EXC_BIFF5:
1222 0 : maNoteText = OUStringToOString(aNoteText, rRoot.GetTextEncoding());
1223 0 : break;
1224 :
1225 : case EXC_BIFF8:
1226 : {
1227 : // TODO: additional text
1228 6 : if( pScNote )
1229 6 : if( SdrCaptionObj* pCaption = pScNote->GetOrCreateCaption( maScPos ) )
1230 : {
1231 6 : lcl_GetFromTo( rRoot, pCaption->GetLogicRect(), maScPos.Tab(), maCommentFrom, maCommentTo );
1232 6 : if( const OutlinerParaObject* pOPO = pCaption->GetOutlinerParaObject() )
1233 6 : mnObjId = rRoot.GetObjectManager().AddObj( new XclObjComment( rRoot.GetObjectManager(), pCaption->GetLogicRect(), pOPO->GetTextObject(), pCaption, mbVisible, maScPos, maCommentFrom, maCommentTo ) );
1234 :
1235 6 : SfxItemSet aItemSet = pCaption->GetMergedItemSet();
1236 6 : meTVA = pCaption->GetTextVerticalAdjust();
1237 6 : meTHA = pCaption->GetTextHorizontalAdjust();
1238 6 : mbAutoScale = pCaption->GetFitToSize() ? true : false;
1239 6 : mbLocked = pCaption->IsMoveProtect() || pCaption->IsResizeProtect();
1240 :
1241 : // AutoFill style would change if Postit.cxx object creation values are changed
1242 12 : OUString aCol(((XFillColorItem &)GETITEM(aItemSet, XFillColorItem , XATTR_FILLCOLOR)).GetValue());
1243 6 : mbAutoFill = aCol.isEmpty() && (GETITEMVALUE(aItemSet, XFillStyleItem, XATTR_FILLSTYLE, sal_uLong) == drawing::FillStyle_SOLID);
1244 6 : mbAutoLine = true;
1245 6 : mbRowHidden = (rRoot.GetDoc().RowHidden(maScPos.Row(),maScPos.Tab()));
1246 12 : mbColHidden = (rRoot.GetDoc().ColHidden(maScPos.Col(),maScPos.Tab()));
1247 : }
1248 :
1249 6 : SetRecSize( 9 + maAuthor.GetSize() );
1250 : }
1251 6 : break;
1252 :
1253 : default: DBG_ERROR_BIFF();
1254 6 : }
1255 6 : }
1256 :
1257 6 : void XclExpNote::Save( XclExpStream& rStrm )
1258 : {
1259 6 : switch( rStrm.GetRoot().GetBiff() )
1260 : {
1261 : case EXC_BIFF5:
1262 : {
1263 : // write the NOTE record directly, there may be the need to create more than one
1264 0 : const sal_Char* pcBuffer = maNoteText.getStr();
1265 0 : sal_uInt16 nCharsLeft = static_cast< sal_uInt16 >( maNoteText.getLength() );
1266 :
1267 0 : while( nCharsLeft )
1268 : {
1269 0 : sal_uInt16 nWriteChars = ::std::min( nCharsLeft, EXC_NOTE5_MAXLEN );
1270 :
1271 0 : rStrm.StartRecord( EXC_ID_NOTE, 6 + nWriteChars );
1272 0 : if( pcBuffer == maNoteText.getStr() )
1273 : {
1274 : // first record: row, col, length of complete text
1275 0 : rStrm << static_cast< sal_uInt16 >( maScPos.Row() )
1276 0 : << static_cast< sal_uInt16 >( maScPos.Col() )
1277 0 : << nCharsLeft; // still contains full length
1278 : }
1279 : else
1280 : {
1281 : // next records: -1, 0, length of current text segment
1282 0 : rStrm << sal_uInt16( 0xFFFF )
1283 0 : << sal_uInt16( 0 )
1284 0 : << nWriteChars;
1285 : }
1286 0 : rStrm.Write( pcBuffer, nWriteChars );
1287 0 : rStrm.EndRecord();
1288 :
1289 0 : pcBuffer += nWriteChars;
1290 0 : nCharsLeft = nCharsLeft - nWriteChars;
1291 : }
1292 : }
1293 0 : break;
1294 :
1295 : case EXC_BIFF8:
1296 6 : if( mnObjId != EXC_OBJ_INVALID_ID )
1297 6 : XclExpRecord::Save( rStrm );
1298 6 : break;
1299 :
1300 : default: DBG_ERROR_BIFF();
1301 : }
1302 6 : }
1303 :
1304 6 : void XclExpNote::WriteBody( XclExpStream& rStrm )
1305 : {
1306 : // BIFF5/BIFF7 is written separately
1307 : OSL_ENSURE_BIFF( rStrm.GetRoot().GetBiff() == EXC_BIFF8 );
1308 :
1309 6 : sal_uInt16 nFlags = 0;
1310 6 : ::set_flag( nFlags, EXC_NOTE_VISIBLE, mbVisible );
1311 :
1312 6 : rStrm << static_cast< sal_uInt16 >( maScPos.Row() )
1313 12 : << static_cast< sal_uInt16 >( maScPos.Col() )
1314 12 : << nFlags
1315 12 : << mnObjId
1316 12 : << maAuthor
1317 6 : << sal_uInt8( 0 );
1318 6 : }
1319 :
1320 0 : void XclExpNote::WriteXml( sal_Int32 nAuthorId, XclExpXmlStream& rStrm )
1321 : {
1322 0 : sax_fastparser::FSHelperPtr rComments = rStrm.GetCurrentStream();
1323 :
1324 : rComments->startElement( XML_comment,
1325 : XML_ref, XclXmlUtils::ToOString( maScPos ).getStr(),
1326 : XML_authorId, OString::number( nAuthorId ).getStr(),
1327 : // OOXTODO: XML_guid,
1328 0 : FSEND );
1329 0 : rComments->startElement( XML_text, FSEND );
1330 : // OOXTODO: phoneticPr, rPh, r
1331 0 : if( mpNoteContents )
1332 0 : mpNoteContents->WriteXml( rStrm );
1333 0 : rComments->endElement( XML_text );
1334 :
1335 : /*
1336 : Export of commentPr is disabled, since the current (Oct 2010)
1337 : version of MSO 2010 doesn't yet support commentPr
1338 : */
1339 : #if 1//def XLSX_OOXML_FUTURE
1340 0 : if( rStrm.getVersion() == oox::core::ISOIEC_29500_2008 )
1341 : {
1342 0 : rComments->startElement( FSNS( XML_mc, XML_AlternateContent ), FSEND );
1343 0 : rComments->startElement( FSNS( XML_mc, XML_Choice ), XML_Requires, "v2", FSEND );
1344 : rComments->startElement( XML_commentPr,
1345 : XML_autoFill, XclXmlUtils::ToPsz( mbAutoFill ),
1346 : XML_autoScale, XclXmlUtils::ToPsz( mbAutoScale ),
1347 : XML_colHidden, XclXmlUtils::ToPsz( mbColHidden ),
1348 : XML_locked, XclXmlUtils::ToPsz( mbLocked ),
1349 : XML_rowHidden, XclXmlUtils::ToPsz( mbRowHidden ),
1350 : XML_textHAlign, ToHorizAlign( meTHA ),
1351 : XML_textVAlign, ToVertAlign( meTVA ) ,
1352 0 : FSEND );
1353 : rComments->startElement( XML_anchor,
1354 : XML_moveWithCells, "false",
1355 : XML_sizeWithCells, "false",
1356 0 : FSEND );
1357 0 : rComments->startElement( FSNS( XML_xdr, XML_from ), FSEND );
1358 0 : lcl_WriteAnchorVertex( rComments, maCommentFrom );
1359 0 : rComments->endElement( FSNS( XML_xdr, XML_from ) );
1360 0 : rComments->startElement( FSNS( XML_xdr, XML_to ), FSEND );
1361 0 : lcl_WriteAnchorVertex( rComments, maCommentTo );
1362 0 : rComments->endElement( FSNS( XML_xdr, XML_to ) );
1363 0 : rComments->endElement( XML_anchor );
1364 0 : rComments->endElement( XML_commentPr );
1365 :
1366 0 : rComments->endElement( FSNS( XML_mc, XML_Choice ) );
1367 0 : rComments->startElement( FSNS( XML_mc, XML_Fallback ), FSEND );
1368 : // Any fallback code ?
1369 0 : rComments->endElement( FSNS( XML_mc, XML_Fallback ) );
1370 0 : rComments->endElement( FSNS( XML_mc, XML_AlternateContent ) );
1371 : }
1372 : #endif
1373 0 : rComments->endElement( XML_comment );
1374 0 : }
1375 :
1376 8 : XclMacroHelper::XclMacroHelper( const XclExpRoot& rRoot ) :
1377 8 : XclExpControlHelper( rRoot )
1378 : {
1379 8 : }
1380 :
1381 8 : XclMacroHelper::~XclMacroHelper()
1382 : {
1383 8 : }
1384 :
1385 4 : void XclMacroHelper::WriteMacroSubRec( XclExpStream& rStrm )
1386 : {
1387 4 : if( mxMacroLink )
1388 0 : WriteFormulaSubRec( rStrm, EXC_ID_OBJMACRO, *mxMacroLink );
1389 4 : }
1390 :
1391 : bool
1392 0 : XclMacroHelper::SetMacroLink( const ScriptEventDescriptor& rEvent, const XclTbxEventType& nEventType )
1393 : {
1394 0 : OUString aMacroName = XclControlHelper::ExtractFromMacroDescriptor( rEvent, nEventType, GetDocShell() );
1395 0 : if( !aMacroName.isEmpty() )
1396 : {
1397 0 : return SetMacroLink( aMacroName );
1398 : }
1399 0 : return false;
1400 : }
1401 :
1402 : bool
1403 0 : XclMacroHelper::SetMacroLink( const OUString& rMacroName )
1404 : {
1405 : OSL_TRACE("SetMacroLink( macroname:=%s )", OUStringToOString( rMacroName, RTL_TEXTENCODING_UTF8 ).getStr() );
1406 0 : if( !rMacroName.isEmpty() )
1407 : {
1408 0 : sal_uInt16 nExtSheet = GetLocalLinkManager().FindExtSheet( EXC_EXTSH_OWNDOC );
1409 0 : sal_uInt16 nNameIdx = GetNameManager().InsertMacroCall( rMacroName, true, false );
1410 0 : mxMacroLink = GetFormulaCompiler().CreateNameXFormula( nExtSheet, nNameIdx );
1411 0 : return true;
1412 : }
1413 0 : return false;
1414 : }
1415 :
1416 8 : XclExpShapeObj::XclExpShapeObj( XclExpObjectManager& rRoot, ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ) :
1417 : XclObjAny( rRoot, xShape ),
1418 8 : XclMacroHelper( rRoot )
1419 : {
1420 8 : if( SdrObject* pSdrObj = ::GetSdrObjectFromXShape( xShape ) )
1421 : {
1422 8 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pSdrObj );
1423 8 : if ( pInfo && !pInfo->GetMacro().isEmpty() )
1424 : // FIXME ooo330-m2: XclControlHelper::GetXclMacroName was removed in upstream sources; they started to call XclTools::GetXclMacroName instead; is this enough? it has only one parameter
1425 : // SetMacroLink( XclControlHelper::GetXclMacroName( pInfo->GetMacro(), rRoot.GetDocShell() ) );
1426 0 : SetMacroLink( XclTools::GetXclMacroName( pInfo->GetMacro() ) );
1427 : }
1428 8 : }
1429 :
1430 16 : XclExpShapeObj::~XclExpShapeObj()
1431 : {
1432 16 : }
1433 :
1434 4 : void XclExpShapeObj::WriteSubRecs( XclExpStream& rStrm )
1435 : {
1436 4 : XclObjAny::WriteSubRecs( rStrm );
1437 4 : WriteMacroSubRec( rStrm );
1438 4 : }
1439 :
1440 0 : XclExpComments::XclExpComments( SCTAB nTab, XclExpRecordList< XclExpNote >& rNotes )
1441 0 : : mnTab( nTab ), mrNotes( rNotes )
1442 : {
1443 0 : }
1444 :
1445 : struct OUStringLess : public std::binary_function<OUString, OUString, bool>
1446 : {
1447 0 : bool operator()(const OUString& x, const OUString& y) const
1448 : {
1449 0 : return x.compareTo( y ) < 0;
1450 : }
1451 : };
1452 :
1453 0 : void XclExpComments::SaveXml( XclExpXmlStream& rStrm )
1454 : {
1455 0 : if( mrNotes.IsEmpty() )
1456 0 : return;
1457 :
1458 : sax_fastparser::FSHelperPtr rComments = rStrm.CreateOutputStream(
1459 : XclXmlUtils::GetStreamName( "xl/", "comments", mnTab + 1 ),
1460 : XclXmlUtils::GetStreamName( "../", "comments", mnTab + 1 ),
1461 0 : rStrm.GetCurrentStream()->getOutputStream(),
1462 : "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
1463 0 : "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" );
1464 0 : rStrm.PushStream( rComments );
1465 :
1466 0 : if( rStrm.getVersion() == oox::core::ISOIEC_29500_2008 )
1467 : rComments->startElement( XML_comments,
1468 : XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
1469 : FSNS( XML_xmlns, XML_mc ), "http://schemas.openxmlformats.org/markup-compatibility/2006",
1470 : FSNS( XML_xmlns, XML_xdr ), "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
1471 : FSNS( XML_xmlns, XML_v2 ), "http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2",
1472 : FSNS( XML_mc, XML_Ignorable ), "v2",
1473 0 : FSEND );
1474 : else
1475 : rComments->startElement( XML_comments,
1476 : XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
1477 : FSNS( XML_xmlns, XML_xdr ), "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
1478 0 : FSEND );
1479 :
1480 0 : rComments->startElement( XML_authors, FSEND );
1481 :
1482 : typedef std::set< OUString, OUStringLess > Authors;
1483 0 : Authors aAuthors;
1484 :
1485 0 : size_t nNotes = mrNotes.GetSize();
1486 0 : for( size_t i = 0; i < nNotes; ++i )
1487 : {
1488 0 : aAuthors.insert( XclXmlUtils::ToOUString( mrNotes.GetRecord( i )->GetAuthor() ) );
1489 : }
1490 :
1491 0 : for( Authors::const_iterator b = aAuthors.begin(), e = aAuthors.end(); b != e; ++b )
1492 : {
1493 0 : rComments->startElement( XML_author, FSEND );
1494 0 : rComments->writeEscaped( *b );
1495 0 : rComments->endElement( XML_author );
1496 : }
1497 :
1498 0 : rComments->endElement( XML_authors );
1499 0 : rComments->startElement( XML_commentList, FSEND );
1500 :
1501 0 : Authors::const_iterator aAuthorsBegin = aAuthors.begin();
1502 0 : for( size_t i = 0; i < nNotes; ++i )
1503 : {
1504 0 : XclExpNoteList::RecordRefType xNote = mrNotes.GetRecord( i );
1505 : Authors::const_iterator aAuthor = aAuthors.find(
1506 0 : XclXmlUtils::ToOUString( xNote->GetAuthor() ) );
1507 0 : sal_Int32 nAuthorId = distance( aAuthorsBegin, aAuthor );
1508 0 : xNote->WriteXml( nAuthorId, rStrm );
1509 0 : }
1510 :
1511 0 : rComments->endElement( XML_commentList );
1512 0 : rComments->endElement( XML_comments );
1513 :
1514 0 : rStrm.PopStream();
1515 : }
1516 :
1517 : // object manager =============================================================
1518 :
1519 64 : XclExpObjectManager::XclExpObjectManager( const XclExpRoot& rRoot ) :
1520 64 : XclExpRoot( rRoot )
1521 : {
1522 64 : InitStream( true );
1523 64 : mxEscherEx.reset( new XclEscherEx( GetRoot(), *this, *mxDffStrm ) );
1524 64 : }
1525 :
1526 0 : XclExpObjectManager::XclExpObjectManager( const XclExpObjectManager& rParent ) :
1527 0 : XclExpRoot( rParent.GetRoot() )
1528 : {
1529 0 : InitStream( false );
1530 0 : mxEscherEx.reset( new XclEscherEx( GetRoot(), *this, *mxDffStrm, rParent.mxEscherEx.get() ) );
1531 0 : }
1532 :
1533 128 : XclExpObjectManager::~XclExpObjectManager()
1534 : {
1535 128 : }
1536 :
1537 24 : XclExpDffAnchorBase* XclExpObjectManager::CreateDffAnchor() const
1538 : {
1539 24 : return new XclExpDffSheetAnchor( GetRoot() );
1540 : }
1541 :
1542 64 : boost::shared_ptr< XclExpRecordBase > XclExpObjectManager::CreateDrawingGroup()
1543 : {
1544 64 : return boost::shared_ptr< XclExpRecordBase >( new XclExpMsoDrawingGroup( *mxEscherEx ) );
1545 : }
1546 :
1547 124 : void XclExpObjectManager::StartSheet()
1548 : {
1549 124 : mxObjList.reset( new XclExpObjList( GetRoot(), *mxEscherEx ) );
1550 124 : }
1551 :
1552 124 : boost::shared_ptr< XclExpRecordBase > XclExpObjectManager::ProcessDrawing( SdrPage* pSdrPage )
1553 : {
1554 124 : if( pSdrPage )
1555 120 : mxEscherEx->AddSdrPage( *pSdrPage );
1556 : // the first dummy object may still be open
1557 : OSL_ENSURE( mxEscherEx->GetGroupLevel() <= 1, "XclExpObjectManager::ProcessDrawing - still groups open?" );
1558 252 : while( mxEscherEx->GetGroupLevel() )
1559 4 : mxEscherEx->LeaveGroup();
1560 124 : mxObjList->EndSheet();
1561 124 : return mxObjList;
1562 : }
1563 :
1564 0 : boost::shared_ptr< XclExpRecordBase > XclExpObjectManager::ProcessDrawing( const Reference< XShapes >& rxShapes )
1565 : {
1566 0 : if( rxShapes.is() )
1567 0 : mxEscherEx->AddUnoShapes( rxShapes );
1568 : // the first dummy object may still be open
1569 : OSL_ENSURE( mxEscherEx->GetGroupLevel() <= 1, "XclExpObjectManager::ProcessDrawing - still groups open?" );
1570 0 : while( mxEscherEx->GetGroupLevel() )
1571 0 : mxEscherEx->LeaveGroup();
1572 0 : mxObjList->EndSheet();
1573 0 : return mxObjList;
1574 : }
1575 :
1576 64 : void XclExpObjectManager::EndDocument()
1577 : {
1578 64 : mxEscherEx->EndDocument();
1579 64 : }
1580 :
1581 30 : XclExpMsoDrawing* XclExpObjectManager::GetMsodrawingPerSheet()
1582 : {
1583 30 : return mxObjList->GetMsodrawingPerSheet();
1584 : }
1585 :
1586 30 : bool XclExpObjectManager::HasObj() const
1587 : {
1588 30 : return !mxObjList->empty();
1589 : }
1590 :
1591 30 : sal_uInt16 XclExpObjectManager::AddObj( XclObj* pObjRec )
1592 : {
1593 30 : return mxObjList->Add( pObjRec );
1594 : }
1595 :
1596 0 : XclObj* XclExpObjectManager::RemoveLastObj()
1597 : {
1598 0 : XclObj* pLastObj = mxObjList->back();
1599 0 : mxObjList->pop_back();
1600 0 : return pLastObj;
1601 : }
1602 :
1603 64 : void XclExpObjectManager::InitStream( bool bTempFile )
1604 : {
1605 64 : if( bTempFile )
1606 : {
1607 64 : mxTempFile.reset( new ::utl::TempFile );
1608 64 : if( mxTempFile->IsValid() )
1609 : {
1610 64 : mxTempFile->EnableKillingFile();
1611 64 : mxDffStrm.reset( ::utl::UcbStreamHelper::CreateStream( mxTempFile->GetURL(), STREAM_STD_READWRITE ) );
1612 : }
1613 : }
1614 :
1615 64 : if( !mxDffStrm.get() )
1616 0 : mxDffStrm.reset( new SvMemoryStream );
1617 :
1618 64 : mxDffStrm->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1619 64 : }
1620 :
1621 0 : XclExpEmbeddedObjectManager::XclExpEmbeddedObjectManager(
1622 : const XclExpObjectManager& rParent, const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY ) :
1623 : XclExpObjectManager( rParent ),
1624 : maPageSize( rPageSize ),
1625 : mnScaleX( nScaleX ),
1626 0 : mnScaleY( nScaleY )
1627 : {
1628 0 : }
1629 :
1630 0 : XclExpDffAnchorBase* XclExpEmbeddedObjectManager::CreateDffAnchor() const
1631 : {
1632 0 : return new XclExpDffEmbeddedAnchor( GetRoot(), maPageSize, mnScaleX, mnScaleY );
1633 48 : }
1634 :
1635 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|