fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / filter / eppt / pptx-epptbase.cxx
blob8e9ff5c4fbc79c8ef9a42d22e68cc1b7c8996793
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "eppt.hxx"
22 #include "epptdef.hxx"
24 #include <comphelper/extract.hxx>
25 #include <tools/globname.hxx>
26 #include <tools/datetime.hxx>
27 #include <tools/poly.hxx>
28 #include <tools/stream.hxx>
29 #include <vcl/graph.hxx>
30 #include <vcl/bmpacc.hxx>
31 #include <vcl/gradient.hxx>
32 #include <vcl/virdev.hxx>
33 #include <rtl/ustring.hxx>
34 #include <rtl/strbuf.hxx>
35 #include <vcl/fltcall.hxx>
36 #include <vcl/wmf.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <sfx2/docinf.hxx>
39 #include <svx/unoapi.hxx>
40 #include <svx/svdobj.hxx>
41 #include <svx/svdoole2.hxx>
42 #include <svx/svdmodel.hxx>
43 #include <svx/svdpage.hxx>
44 #include <com/sun/star/view/PaperOrientation.hpp>
45 #include <com/sun/star/view/PaperFormat.hpp>
46 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
47 #include <com/sun/star/office/XAnnotation.hpp>
48 #include <com/sun/star/office/XAnnotationAccess.hpp>
49 #include <com/sun/star/office/XAnnotationEnumeration.hpp>
50 #include <com/sun/star/geometry/RealPoint2D.hpp>
51 #include <com/sun/star/util/DateTime.hpp>
52 #include <com/sun/star/animations/TransitionType.hpp>
53 #include <com/sun/star/animations/TransitionSubType.hpp>
54 #include <com/sun/star/awt/FontDescriptor.hpp>
55 #include <com/sun/star/awt/FontFamily.hpp>
56 #include <com/sun/star/awt/FontPitch.hpp>
57 #include <com/sun/star/container/XNamed.hpp>
58 #include <com/sun/star/container/XNameAccess.hpp>
59 #include <com/sun/star/presentation/XPresentationPage.hpp>
60 #include <com/sun/star/text/XSimpleText.hpp>
61 #include <com/sun/star/style/XStyle.hpp>
62 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
63 #include <editeng/svxenum.hxx>
64 #include <editeng/flditem.hxx>
65 #include <sot/storinfo.hxx>
66 #include <filter/msfilter/msoleexp.hxx>
67 #include <filter/msfilter/msdffimp.hxx>
68 #include <filter/msfilter/svxmsbas.hxx>
70 #ifdef DEBUG
71 #define DBG(x) x
72 #include <stdio.h>
73 #else
74 #define DBG(x)
75 #endif
77 using namespace com::sun::star;
79 using namespace ::com::sun::star::animations;
80 using namespace ::com::sun::star::awt::FontFamily;
81 using namespace ::com::sun::star::awt::FontPitch;
82 using namespace ::com::sun::star::presentation;
84 using ::com::sun::star::awt::FontDescriptor;
85 using ::com::sun::star::beans::XPropertySet;
86 using ::com::sun::star::container::XNameAccess;
87 using ::com::sun::star::container::XNamed;
88 using ::com::sun::star::drawing::XDrawPagesSupplier;
89 using ::com::sun::star::drawing::XMasterPagesSupplier;
90 using ::com::sun::star::drawing::XShapes;
91 using ::com::sun::star::drawing::XMasterPageTarget;
92 using ::com::sun::star::drawing::XDrawPage;
93 using ::com::sun::star::frame::XModel;
94 using ::com::sun::star::style::XStyleFamiliesSupplier;
95 using ::com::sun::star::style::XStyle;
96 using ::com::sun::star::task::XStatusIndicator;
97 using ::com::sun::star::text::XSimpleText;
98 using ::com::sun::star::uno::Any;
99 using ::com::sun::star::uno::Exception;
100 using ::com::sun::star::uno::Reference;
101 using ::com::sun::star::uno::UNO_QUERY;
103 static PHLayout pPHLayout[] =
105 { EPP_LAYOUT_TITLESLIDE, { 0x0d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x10, sal_True, sal_True, sal_False },
106 { EPP_LAYOUT_TITLEANDBODYSLIDE, { 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, sal_True, sal_True, sal_False },
107 { EPP_LAYOUT_TITLEANDBODYSLIDE, { 0x0d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, sal_True, sal_True, sal_False },
108 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, sal_True, sal_True, sal_True },
109 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x0e, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, sal_True, sal_True, sal_False },
110 { EPP_LAYOUT_BLANCSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, sal_False, sal_False, sal_False },
111 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x0e, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, sal_True, sal_True, sal_False },
112 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x14, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, sal_True, sal_True, sal_False },
113 { EPP_LAYOUT_TITLEANDBODYSLIDE, { 0x0d, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x15, 0x0d, 0x0e, sal_True, sal_False, sal_False },
114 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x16, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, sal_True, sal_True, sal_False },
115 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_True, sal_False },
116 { EPP_LAYOUT_TITLEANDBODYSLIDE, { 0x0d, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_False, sal_False },
117 { EPP_LAYOUT_RIGHTCOLUMN2ROWS, { 0x0d, 0x0e, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_True, sal_False },
118 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_True, sal_False },
119 { EPP_LAYOUT_2ROWSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_True, sal_False },
120 { EPP_LAYOUT_LEFTCOLUMN2ROWS, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_True, sal_False },
121 { EPP_LAYOUT_TOPROW2COLUMN, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_True, sal_False },
122 { EPP_LAYOUT_2ROWSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_True, sal_False },
123 { EPP_LAYOUT_4OBJECTS, { 0x0d, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, sal_True, sal_False, sal_False },
124 { EPP_LAYOUT_ONLYTITLE, { 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, sal_True, sal_False, sal_False },
125 { EPP_LAYOUT_BLANCSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, sal_False, sal_False, sal_False },
126 { EPP_LAYOUT_TITLERIGHT2BODIESLEFT, { 0x11, 0x12, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x11, 0x12, sal_True, sal_True, sal_False },
127 { EPP_LAYOUT_TITLERIGHTBODYLEFT, { 0x11, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x11, 0x12, sal_True, sal_True, sal_False },
128 { EPP_LAYOUT_TITLEANDBODYSLIDE, { 0x0d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x12, sal_True, sal_True, sal_False },
129 { EPP_LAYOUT_2COLUMNSANDTITLE, { 0x0d, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x12, sal_True, sal_True, sal_False }
132 #define PPT_WRITER_BASE_INIT_VALUES \
133 maFraction ( 1, 576 ), \
134 maMapModeSrc ( MAP_100TH_MM ), \
135 maMapModeDest ( MAP_INCH, Point(), maFraction, maFraction ), \
136 meLatestPageType ( NORMAL )
138 PPTWriterBase::PPTWriterBase() :
139 PPT_WRITER_BASE_INIT_VALUES
141 DBG(printf ("PPTWriterBase::PPTWriterBase()\n"));
144 PPTWriterBase::PPTWriterBase( const Reference< XModel > & rXModel,
145 const Reference< XStatusIndicator > & rXStatInd ) :
146 mXModel ( rXModel ),
147 mXStatusIndicator ( rXStatInd ),
148 mbStatusIndicator ( false ),
149 PPT_WRITER_BASE_INIT_VALUES
153 // ---------------------------------------------------------------------------------------------
155 PPTWriterBase::~PPTWriterBase()
157 // Possibly unnecessary sanity check for mXStatusIndicator.is().
158 // In 3.3 we had a bug report of a crash where it was null,
159 // https://bugzilla.novell.com/show_bug.cgi?id=694119 (non-public,
160 // bug report, sorry).
161 if ( mbStatusIndicator && mXStatusIndicator.is() )
162 mXStatusIndicator->end();
165 // ---------------------------------------------------------------------------------------------
167 void PPTWriterBase::exportPPT( const std::vector< com::sun::star::beans::PropertyValue >& rMediaData )
169 if ( !InitSOIface() )
170 return;
172 FontCollectionEntry aDefaultFontDesc( OUString( "Times New Roman" ),
173 ROMAN,
174 awt::FontPitch::VARIABLE,
175 RTL_TEXTENCODING_MS_1252 );
176 maFontCollection.GetId( aDefaultFontDesc ); // default is always times new roman
178 if ( !GetPageByIndex( 0, NOTICE ) )
179 return;
181 sal_Int32 nWidth = 21000;
182 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Width" ) ) )
183 mAny >>= nWidth;
184 sal_Int32 nHeight = 29700;
185 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Height" ) ) )
186 mAny >>= nHeight;
188 maNotesPageSize = MapSize( awt::Size( nWidth, nHeight ) );
190 if ( !GetPageByIndex( 0, MASTER ) )
191 return;
193 nWidth = 28000;
194 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Width" ) ) )
195 mAny >>= nWidth;
196 nHeight = 21000;
197 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Height" ) ) )
198 mAny >>= nHeight;
199 maDestPageSize = MapSize( awt::Size( nWidth, nHeight ) );
201 DBG(printf( "call exportDocumentPre()\n"));
202 exportPPTPre(rMediaData);
204 if ( !GetStyleSheets() )
205 return;
207 if ( !ImplCreateDocument() )
208 return;
210 sal_uInt32 i;
212 for ( i = 0; i < mnPages; i++ )
214 if ( GetPageByIndex( i, NORMAL ) ) {
215 sal_uInt32 nMasterNum = GetMasterIndex( NORMAL );
216 ImplWriteLayout( GetLayoutOffset( mXPagePropSet ), nMasterNum );
220 for ( i = 0; i < mnMasterPages; i++ )
222 if ( !CreateSlideMaster( i ) )
223 return;
225 if ( !CreateMainNotes() )
226 return;
228 for ( i = 0; i < mnPages; i++ )
230 DBG(printf( "call ImplCreateSlide( %" SAL_PRIuUINT32 " )\n", i));
231 if ( !CreateSlide( i ) )
232 return;
235 for ( i = 0; i < mnPages; i++ )
237 if ( !CreateNotes( i ) )
238 return;
241 DBG(printf( "call exportDocumentPost()\n"));
242 exportPPTPost();
245 // ---------------------------------------------------------------------------------------------
247 sal_Bool PPTWriterBase::InitSOIface()
249 while( true )
251 mXDrawPagesSupplier = Reference< XDrawPagesSupplier >( mXModel, UNO_QUERY );
252 if ( !mXDrawPagesSupplier.is() )
253 break;
255 mXMasterPagesSupplier = Reference< XMasterPagesSupplier >( mXModel, UNO_QUERY );
256 if ( !mXMasterPagesSupplier.is() )
257 break;
258 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
259 if ( !mXDrawPages.is() )
260 break;
261 mnMasterPages = mXDrawPages->getCount();
262 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
263 if( !mXDrawPages.is() )
264 break;
265 mnPages = mXDrawPages->getCount();
266 if ( !GetPageByIndex( 0, NORMAL ) )
267 break;
269 return sal_True;
271 return sal_False;
274 // ---------------------------------------------------------------------------------------------
276 sal_Bool PPTWriterBase::GetPageByIndex( sal_uInt32 nIndex, PageType ePageType )
278 while( true )
280 if ( ePageType != meLatestPageType )
282 switch( ePageType )
284 case NORMAL :
285 case NOTICE :
287 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
288 if( !mXDrawPages.is() )
289 return sal_False;
291 break;
293 case MASTER :
295 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
296 if( !mXDrawPages.is() )
297 return sal_False;
299 break;
300 default:
301 break;
303 meLatestPageType = ePageType;
305 Any aAny( mXDrawPages->getByIndex( nIndex ) );
306 aAny >>= mXDrawPage;
307 if ( !mXDrawPage.is() )
308 break;
309 if ( ePageType == NOTICE )
311 Reference< XPresentationPage > aXPresentationPage( mXDrawPage, UNO_QUERY );
312 if ( !aXPresentationPage.is() )
313 break;
314 mXDrawPage = aXPresentationPage->getNotesPage();
315 if ( !mXDrawPage.is() )
316 break;
318 mXPagePropSet = Reference< XPropertySet >( mXDrawPage, UNO_QUERY );
319 if ( !mXPagePropSet.is() )
320 break;
322 mXShapes = Reference< XShapes >( mXDrawPage, UNO_QUERY );
323 if ( !mXShapes.is() )
324 break;
326 /* try to get the "real" background PropertySet. If the normal page is not supporting this property, it is
327 taken the property from the master */
328 sal_Bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, OUString( "Background" ), sal_True );
329 if ( bHasBackground )
330 bHasBackground = ( aAny >>= mXBackgroundPropSet );
331 if ( !bHasBackground )
333 Reference< XMasterPageTarget > aXMasterPageTarget( mXDrawPage, UNO_QUERY );
334 if ( aXMasterPageTarget.is() )
336 Reference< XDrawPage > aXMasterDrawPage;
337 aXMasterDrawPage = aXMasterPageTarget->getMasterPage();
338 if ( aXMasterDrawPage.is() )
340 Reference< XPropertySet > aXMasterPagePropSet;
341 aXMasterPagePropSet = Reference< XPropertySet >
342 ( aXMasterDrawPage, UNO_QUERY );
343 if ( aXMasterPagePropSet.is() )
345 sal_Bool bBackground = GetPropertyValue( aAny, aXMasterPagePropSet, OUString( "Background" ) );
346 if ( bBackground )
348 aAny >>= mXBackgroundPropSet;
354 return sal_True;
356 return sal_False;
359 // ---------------------------------------------------------------------------------------------
361 sal_Bool PPTWriterBase::CreateSlide( sal_uInt32 nPageNum )
363 Any aAny;
365 if ( !GetPageByIndex( nPageNum, NORMAL ) )
366 return sal_False;
368 sal_uInt32 nMasterNum = GetMasterIndex( NORMAL );
369 SetCurrentStyleSheet( nMasterNum );
371 Reference< XPropertySet > aXBackgroundPropSet;
372 sal_Bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, OUString( "Background" ) );
373 if ( bHasBackground )
374 bHasBackground = ( aAny >>= aXBackgroundPropSet );
376 sal_uInt16 nMode = 7; // Bit 1: Follow master objects, Bit 2: Follow master scheme, Bit 3: Follow master background
377 if ( bHasBackground )
378 nMode &=~4;
380 /* sj: Don't know what's IsBackgroundVisible for, have to ask cl
381 if ( GetPropertyValue( aAny, mXPagePropSet, String( RTL_CONSTASCII_USTRINGPARAM( "IsBackgroundVisible" ) ) ) )
383 sal_Bool bBackgroundVisible;
384 if ( aAny >>= bBackgroundVisible )
386 if ( bBackgroundVisible )
387 nMode &= ~4;
391 if ( GetPropertyValue( aAny, mXPagePropSet, OUString( "IsBackgroundObjectsVisible" ) ) )
393 sal_Bool bBackgroundObjectsVisible = sal_False;
394 if ( aAny >>= bBackgroundObjectsVisible )
396 if ( !bBackgroundObjectsVisible )
397 nMode &= ~1;
401 ImplWriteSlide( nPageNum, nMasterNum, nMode, bHasBackground, aXBackgroundPropSet );
403 return sal_True;
406 // ---------------------------------------------------------------------------------------------
408 sal_Bool PPTWriterBase::CreateNotes( sal_uInt32 nPageNum )
410 if ( !GetPageByIndex( nPageNum, NOTICE ) )
411 return sal_False;
412 SetCurrentStyleSheet( GetMasterIndex( NORMAL ) );
414 ImplWriteNotes( nPageNum );
416 return sal_True;
419 // ---------------------------------------------------------------------------------------------
421 sal_Bool PPTWriterBase::CreateSlideMaster( sal_uInt32 nPageNum )
423 if ( !GetPageByIndex( nPageNum, MASTER ) )
424 return sal_False;
425 SetCurrentStyleSheet( nPageNum );
427 if ( !ImplGetPropertyValue( mXPagePropSet, OUString( "Background" ) ) ) // load background shape
428 return sal_False;
429 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > aXBackgroundPropSet;
430 if ( !( mAny >>= aXBackgroundPropSet ) )
431 return sal_False;
433 ImplWriteSlideMaster( nPageNum, aXBackgroundPropSet );
435 return sal_True;
438 // ---------------------------------------------------------------------------------------------
440 sal_Int32 PPTWriterBase::GetLayoutOffset( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rXPropSet ) const
442 ::com::sun::star::uno::Any aAny;
443 sal_Int32 nLayout = 20;
444 if ( GetPropertyValue( aAny, rXPropSet, OUString( "Layout" ) ), sal_True )
445 aAny >>= nLayout;
447 DBG(printf("GetLayoutOffset %" SAL_PRIdINT32 "\n", nLayout));
449 return nLayout;
452 sal_Int32 PPTWriterBase::GetLayoutOffsetFixed( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rXPropSet ) const
454 sal_Int32 nLayout = GetLayoutOffset( rXPropSet );
456 if ( ( nLayout >= 21 ) && ( nLayout <= 26 ) ) // NOTES _> HANDOUT6
457 nLayout = 20;
458 if ( ( nLayout >= 27 ) && ( nLayout <= 30 ) ) // VERTICAL LAYOUT
459 nLayout -= 6;
460 else if ( nLayout > 30 )
461 nLayout = 20;
463 return nLayout;
466 PHLayout& PPTWriterBase::GetLayout( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rXPropSet ) const
468 return pPHLayout[ GetLayoutOffsetFixed( rXPropSet ) ];
471 // ---------------------------------------------------------------------------------------------
473 PHLayout& PPTWriterBase::GetLayout( sal_Int32 nOffset ) const
475 if( nOffset >= 0 && nOffset < EPP_LAYOUT_SIZE )
476 return pPHLayout[ nOffset ];
478 DBG(printf("asked %" SAL_PRIdINT32 " for layout outside of 0,%d array scope\n", nOffset, EPP_LAYOUT_SIZE ));
480 return pPHLayout[ 0 ];
483 // ---------------------------------------------------------------------------------------------
485 sal_uInt32 PPTWriterBase::GetMasterIndex( PageType ePageType )
487 sal_uInt32 nRetValue = 0;
488 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XMasterPageTarget >
489 aXMasterPageTarget( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
491 if ( aXMasterPageTarget.is() )
493 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
494 aXDrawPage = aXMasterPageTarget->getMasterPage();
495 if ( aXDrawPage.is() )
497 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
498 aXPropertySet( aXDrawPage, ::com::sun::star::uno::UNO_QUERY );
500 if ( aXPropertySet.is() )
502 if ( ImplGetPropertyValue( aXPropertySet, OUString( "Number" ) ) )
503 nRetValue |= *(sal_Int16*)mAny.getValue();
504 if ( nRetValue & 0xffff ) // avoid overflow
505 nRetValue--;
509 if ( ePageType == NOTICE )
510 nRetValue += mnMasterPages;
511 return nRetValue;
514 // -----------------------------------------------------------------------
516 sal_Bool PPTWriterBase::SetCurrentStyleSheet( sal_uInt32 nPageNum )
518 sal_Bool bRet = sal_False;
519 if ( nPageNum >= maStyleSheetList.size() )
520 nPageNum = 0;
521 else
522 bRet = sal_True;
523 mpStyleSheet = maStyleSheetList[ nPageNum ];
524 return bRet;
527 // ---------------------------------------------------------------------------------------------
529 sal_Bool PPTWriterBase::GetStyleSheets()
531 int nInstance, nLevel;
532 sal_Bool bRetValue = sal_False;
533 sal_uInt32 nPageNum;
535 for ( nPageNum = 0; nPageNum < mnMasterPages; nPageNum++ )
537 Reference< XNamed >
538 aXNamed;
540 Reference< XNameAccess >
541 aXNameAccess;
543 Reference< XStyleFamiliesSupplier >
544 aXStyleFamiliesSupplier( mXModel, UNO_QUERY );
546 Reference< XPropertySet >
547 aXPropSet( mXModel, UNO_QUERY );
549 sal_uInt16 nDefaultTab = ( aXPropSet.is() && ImplGetPropertyValue( aXPropSet, OUString( "TabStop" ) ) )
550 ? (sal_uInt16)( *(sal_Int32*)mAny.getValue() / 4.40972 )
551 : 1250;
553 maStyleSheetList.push_back( new PPTExStyleSheet( nDefaultTab, (PPTExBulletProvider&)*this ) );
554 SetCurrentStyleSheet( nPageNum );
555 if ( GetPageByIndex( nPageNum, MASTER ) )
556 aXNamed = Reference< XNamed >
557 ( mXDrawPage, UNO_QUERY );
559 if ( aXStyleFamiliesSupplier.is() )
560 aXNameAccess = aXStyleFamiliesSupplier->getStyleFamilies();
562 bRetValue = aXNamed.is() && aXNameAccess.is() && aXStyleFamiliesSupplier.is();
563 if ( bRetValue )
565 for ( nInstance = EPP_TEXTTYPE_Title; nInstance <= EPP_TEXTTYPE_CenterTitle; nInstance++ )
567 String aStyle;
568 String aFamily;
569 switch ( nInstance )
571 case EPP_TEXTTYPE_CenterTitle :
572 case EPP_TEXTTYPE_Title :
574 aStyle = OUString( "title" );
575 aFamily = aXNamed->getName();
577 break;
578 case EPP_TEXTTYPE_Body :
580 aStyle = OUString( "outline1" ); // SD_LT_SEPARATOR
581 aFamily = aXNamed->getName();
583 break;
584 case EPP_TEXTTYPE_Other :
586 aStyle = OUString( "standard" );
587 aFamily = OUString( "graphics" );
589 break;
590 case EPP_TEXTTYPE_CenterBody :
592 aStyle = OUString( "subtitle" );
593 aFamily = aXNamed->getName();
595 break;
597 if ( aStyle.Len() && aFamily.Len() )
601 Reference< XNameAccess >xNameAccess;
602 if ( aXNameAccess->hasByName( aFamily ) )
604 Any aAny( aXNameAccess->getByName( aFamily ) );
605 if( aAny.getValue() && ::cppu::extractInterface( xNameAccess, aAny ) )
607 Reference< XNameAccess > aXFamily;
608 if ( aAny >>= aXFamily )
610 if ( aXFamily->hasByName( aStyle ) )
612 Reference< XStyle > xStyle;
613 aAny = aXFamily->getByName( aStyle );
614 if( aAny.getValue() && ::cppu::extractInterface( xStyle, aAny ) )
616 Reference< XStyle > aXStyle;
617 aAny >>= aXStyle;
618 Reference< XPropertySet >
619 xPropSet( aXStyle, UNO_QUERY );
620 if( xPropSet.is() )
621 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, 0 );
622 for ( nLevel = 1; nLevel < 5; nLevel++ )
624 if ( nInstance == EPP_TEXTTYPE_Body )
626 sal_Unicode cTemp = aStyle.GetChar( aStyle.Len() - 1 );
627 aStyle.SetChar( aStyle.Len() - 1, ++cTemp );
628 if ( aXFamily->hasByName( aStyle ) )
630 aXFamily->getByName( aStyle ) >>= xStyle;
631 if( xStyle.is() )
633 Reference< XPropertySet >
634 xPropertySet( xStyle, UNO_QUERY );
635 if ( xPropertySet.is() )
636 mpStyleSheet->SetStyleSheet( xPropertySet, maFontCollection, nInstance, nLevel );
640 else
641 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, nLevel );
649 catch( Exception& )
655 for ( ; nInstance <= EPP_TEXTTYPE_QuarterBody; nInstance++ )
661 return bRetValue;
664 // -----------------------------------------------------------------------
666 sal_Bool PPTWriterBase::CreateMainNotes()
668 if ( !GetPageByIndex( 0, NOTICE ) )
669 return sal_False;
670 SetCurrentStyleSheet( 0 );
672 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XMasterPageTarget >
673 aXMasterPageTarget( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
675 if ( !aXMasterPageTarget.is() )
676 return sal_False;
678 mXDrawPage = aXMasterPageTarget->getMasterPage();
679 if ( !mXDrawPage.is() )
680 return sal_False;
682 mXPropSet = ::com::sun::star::uno::Reference<
683 ::com::sun::star::beans::XPropertySet >
684 ( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
685 if ( !mXPropSet.is() )
686 return sal_False;
688 mXShapes = ::com::sun::star::uno::Reference<
689 ::com::sun::star::drawing::XShapes >
690 ( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
691 if ( !mXShapes.is() )
692 return sal_False;
694 return ImplCreateMainNotes();
697 // -----------------------------------------------------------------------
699 awt::Size PPTWriterBase::MapSize( const awt::Size& rSize )
701 Size aRetSize( OutputDevice::LogicToLogic( Size( rSize.Width, rSize.Height ), maMapModeSrc, maMapModeDest ) );
703 if ( !aRetSize.Width() )
704 aRetSize.Width()++;
705 if ( !aRetSize.Height() )
706 aRetSize.Height()++;
707 return awt::Size( aRetSize.Width(), aRetSize.Height() );
710 // -----------------------------------------------------------------------
712 awt::Point PPTWriterBase::MapPoint( const awt::Point& rPoint )
714 Point aRet( OutputDevice::LogicToLogic( Point( rPoint.X, rPoint.Y ), maMapModeSrc, maMapModeDest ) );
715 return awt::Point( aRet.X(), aRet.Y() );
718 // -----------------------------------------------------------------------
720 Rectangle PPTWriterBase::MapRectangle( const awt::Rectangle& rRect )
722 ::com::sun::star::awt::Point aPoint( rRect.X, rRect.Y );
723 ::com::sun::star::awt::Size aSize( rRect.Width, rRect.Height );
724 ::com::sun::star::awt::Point aP( MapPoint( aPoint ) );
725 ::com::sun::star::awt::Size aS( MapSize( aSize ) );
726 return Rectangle( Point( aP.X, aP.Y ), Size( aS.Width, aS.Height ) );
729 // -----------------------------------------------------------------------
731 sal_Bool PPTWriterBase::GetShapeByIndex( sal_uInt32 nIndex, sal_Bool bGroup )
733 while(true)
735 if ( ( bGroup == sal_False ) || ( GetCurrentGroupLevel() == 0 ) )
737 Any aAny( mXShapes->getByIndex( nIndex ) );
738 aAny >>= mXShape;
740 else
742 Any aAny( GetCurrentGroupAccess()->getByIndex( GetCurrentGroupIndex() ) );
743 aAny >>= mXShape;
745 if ( !mXShape.is() )
746 break;
748 Any aAny( mXShape->queryInterface( ::getCppuType( (const Reference< XPropertySet >*) 0 ) ));
749 aAny >>= mXPropSet;
751 if ( !mXPropSet.is() )
752 break;
753 maPosition = MapPoint( mXShape->getPosition() );
754 maSize = MapSize( mXShape->getSize() );
755 maRect = Rectangle( Point( maPosition.X, maPosition.Y ), Size( maSize.Width, maSize.Height ) );
757 OStringBuffer aTypeBuffer(OUStringToOString(
758 mXShape->getShapeType(), RTL_TEXTENCODING_UTF8));
759 // remove "com.sun.star."
760 aTypeBuffer.remove(0, RTL_CONSTASCII_LENGTH("com.sun.star."));
762 sal_Int32 nPos = aTypeBuffer.toString().indexOf("Shape");
763 aTypeBuffer.remove(nPos, RTL_CONSTASCII_LENGTH("Shape"));
764 mType = aTypeBuffer.makeStringAndClear();
766 mbPresObj = mbEmptyPresObj = sal_False;
767 if ( ImplGetPropertyValue( OUString( "IsPresentationObject" ) ) )
768 mAny >>= mbPresObj;
770 if ( mbPresObj && ImplGetPropertyValue( OUString( "IsEmptyPresentationObject" ) ) )
771 mAny >>= mbEmptyPresObj;
773 mnAngle = ( PropValue::GetPropertyValue( aAny,
774 mXPropSet, OUString( "RotateAngle" ), sal_True ) )
775 ? *((sal_Int32*)aAny.getValue() )
776 : 0;
778 return sal_True;
780 return sal_False;
783 // -----------------------------------------------------------------------
785 sal_Int8 PPTWriterBase::GetTransition( sal_Int16 nTransitionType, sal_Int16 nTransitionSubtype, FadeEffect eEffect, sal_uInt8& nDirection )
787 sal_Int8 nPPTTransitionType = 0;
788 nDirection = 0;
790 switch( nTransitionType )
792 case TransitionType::FADE :
794 if ( nTransitionSubtype == TransitionSubType::CROSSFADE )
795 nPPTTransitionType = PPT_TRANSITION_TYPE_SMOOTHFADE;
796 else if ( nTransitionSubtype == TransitionSubType::FADEOVERCOLOR )
797 nPPTTransitionType = PPT_TRANSITION_TYPE_FADE;
799 break;
800 case PPT_TRANSITION_TYPE_COMB :
802 nPPTTransitionType = PPT_TRANSITION_TYPE_COMB;
803 if ( nTransitionSubtype == TransitionSubType::COMBVERTICAL )
804 nDirection++;
806 break;
807 case TransitionType::PUSHWIPE :
809 nPPTTransitionType = PPT_TRANSITION_TYPE_PUSH;
810 switch( nTransitionSubtype )
812 case TransitionSubType::FROMRIGHT: nDirection = 0; break;
813 case TransitionSubType::FROMBOTTOM: nDirection = 1; break;
814 case TransitionSubType::FROMLEFT: nDirection = 2; break;
815 case TransitionSubType::FROMTOP: nDirection = 3; break;
818 break;
819 case TransitionType::PINWHEELWIPE :
821 nPPTTransitionType = PPT_TRANSITION_TYPE_WHEEL;
822 switch( nTransitionSubtype )
824 case TransitionSubType::ONEBLADE: nDirection = 1; break;
825 case TransitionSubType::TWOBLADEVERTICAL : nDirection = 2; break;
826 case TransitionSubType::THREEBLADE : nDirection = 3; break;
827 case TransitionSubType::FOURBLADE: nDirection = 4; break;
828 case TransitionSubType::EIGHTBLADE: nDirection = 8; break;
831 break;
832 case TransitionType::FANWIPE :
834 nPPTTransitionType = PPT_TRANSITION_TYPE_WEDGE;
836 break;
837 case TransitionType::ELLIPSEWIPE :
839 nPPTTransitionType = PPT_TRANSITION_TYPE_CIRCLE;
841 break;
842 case TransitionType::FOURBOXWIPE :
844 nPPTTransitionType = PPT_TRANSITION_TYPE_PLUS;
846 break;
847 case TransitionType::IRISWIPE :
849 switch( nTransitionSubtype ) {
850 case TransitionSubType::RECTANGLE:
851 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
852 nDirection = (eEffect == FadeEffect_FADE_FROM_CENTER) ? 0 : 1;
853 break;
854 default:
855 nPPTTransitionType = PPT_TRANSITION_TYPE_DIAMOND;
856 break;
859 break;
862 return nPPTTransitionType;
865 sal_Int8 PPTWriterBase::GetTransition( FadeEffect eEffect, sal_uInt8& nDirection )
867 sal_Int8 nPPTTransitionType = 0;
869 switch ( eEffect )
871 default :
872 case FadeEffect_RANDOM :
873 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM;
874 break;
876 case FadeEffect_HORIZONTAL_STRIPES :
877 nDirection++;
878 case FadeEffect_VERTICAL_STRIPES :
879 nPPTTransitionType = PPT_TRANSITION_TYPE_BLINDS;
880 break;
882 case FadeEffect_VERTICAL_CHECKERBOARD :
883 nDirection++;
884 case FadeEffect_HORIZONTAL_CHECKERBOARD :
885 nPPTTransitionType = PPT_TRANSITION_TYPE_CHECKER;
886 break;
888 case FadeEffect_MOVE_FROM_UPPERLEFT :
889 nDirection++;
890 case FadeEffect_MOVE_FROM_UPPERRIGHT :
891 nDirection++;
892 case FadeEffect_MOVE_FROM_LOWERLEFT :
893 nDirection++;
894 case FadeEffect_MOVE_FROM_LOWERRIGHT :
895 nDirection++;
896 case FadeEffect_MOVE_FROM_TOP :
897 nDirection++;
898 case FadeEffect_MOVE_FROM_LEFT :
899 nDirection++;
900 case FadeEffect_MOVE_FROM_BOTTOM :
901 nDirection++;
902 case FadeEffect_MOVE_FROM_RIGHT :
903 nPPTTransitionType = PPT_TRANSITION_TYPE_COVER;
904 break;
906 case FadeEffect_DISSOLVE :
907 nPPTTransitionType = PPT_TRANSITION_TYPE_DISSOLVE;
908 break;
910 case FadeEffect_VERTICAL_LINES :
911 nDirection++;
912 case FadeEffect_HORIZONTAL_LINES :
913 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM_BARS;
914 break;
916 case FadeEffect_CLOSE_HORIZONTAL :
917 nDirection++;
918 case FadeEffect_OPEN_HORIZONTAL :
919 nDirection++;
920 case FadeEffect_CLOSE_VERTICAL :
921 nDirection++;
922 case FadeEffect_OPEN_VERTICAL :
923 nPPTTransitionType = PPT_TRANSITION_TYPE_SPLIT;
924 break;
926 case FadeEffect_FADE_FROM_UPPERLEFT :
927 nDirection++;
928 case FadeEffect_FADE_FROM_UPPERRIGHT :
929 nDirection++;
930 case FadeEffect_FADE_FROM_LOWERLEFT :
931 nDirection++;
932 case FadeEffect_FADE_FROM_LOWERRIGHT :
933 nDirection += 4;
934 nPPTTransitionType = PPT_TRANSITION_TYPE_STRIPS;
935 break;
937 case FadeEffect_UNCOVER_TO_LOWERRIGHT :
938 nDirection++;
939 case FadeEffect_UNCOVER_TO_LOWERLEFT :
940 nDirection++;
941 case FadeEffect_UNCOVER_TO_UPPERRIGHT :
942 nDirection++;
943 case FadeEffect_UNCOVER_TO_UPPERLEFT :
944 nDirection++;
945 case FadeEffect_UNCOVER_TO_BOTTOM :
946 nDirection++;
947 case FadeEffect_UNCOVER_TO_RIGHT :
948 nDirection++;
949 case FadeEffect_UNCOVER_TO_TOP :
950 nDirection++;
951 case FadeEffect_UNCOVER_TO_LEFT :
952 nPPTTransitionType = PPT_TRANSITION_TYPE_PULL;
953 break;
955 case FadeEffect_FADE_FROM_TOP :
956 nDirection++;
957 case FadeEffect_FADE_FROM_LEFT :
958 nDirection++;
959 case FadeEffect_FADE_FROM_BOTTOM :
960 nDirection++;
961 case FadeEffect_FADE_FROM_RIGHT :
962 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
963 break;
965 case FadeEffect_ROLL_FROM_TOP :
966 nDirection++;
967 case FadeEffect_ROLL_FROM_LEFT :
968 nDirection++;
969 case FadeEffect_ROLL_FROM_BOTTOM :
970 nDirection++;
971 case FadeEffect_ROLL_FROM_RIGHT :
972 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
973 break;
975 case FadeEffect_FADE_TO_CENTER :
976 nDirection++;
977 case FadeEffect_FADE_FROM_CENTER :
978 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
979 break;
981 case FadeEffect_NONE :
982 nDirection = 2;
983 break;
986 return nPPTTransitionType;
989 // -----------------------------------------------------------------------
991 sal_Bool PPTWriterBase::ContainsOtherShapeThanPlaceholders( sal_Bool bForOOMLX )
993 sal_uInt32 nShapes = mXShapes->getCount();
994 sal_Bool bOtherThanPlaceHolders = sal_False;
996 if ( nShapes )
997 for ( sal_uInt32 nIndex = 0; ( nIndex < nShapes ) && ( bOtherThanPlaceHolders == sal_False ); nIndex++ )
999 if ( GetShapeByIndex( nIndex ) && mType != "drawing.Page" )
1001 if( bForOOMLX &&
1002 ( mType == "presentation.Page" ||
1003 mType == "presentation.Notes" ) ) {
1004 Reference< XSimpleText > rXText( mXShape, UNO_QUERY );
1006 if( rXText.is() && !rXText->getString().isEmpty() )
1007 bOtherThanPlaceHolders = sal_True;
1009 else
1010 bOtherThanPlaceHolders = sal_True;
1012 DBG(printf("mType == %s\n", mType.getStr()));
1015 return bOtherThanPlaceHolders;
1018 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */