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