19e0fc027SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
39e0fc027SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
49e0fc027SAndrew Rist * or more contributor license agreements. See the NOTICE file
59e0fc027SAndrew Rist * distributed with this work for additional information
69e0fc027SAndrew Rist * regarding copyright ownership. The ASF licenses this file
79e0fc027SAndrew Rist * to you under the Apache License, Version 2.0 (the
89e0fc027SAndrew Rist * "License"); you may not use this file except in compliance
99e0fc027SAndrew Rist * with the License. You may obtain a copy of the License at
109e0fc027SAndrew Rist *
119e0fc027SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
129e0fc027SAndrew Rist *
139e0fc027SAndrew Rist * Unless required by applicable law or agreed to in writing,
149e0fc027SAndrew Rist * software distributed under the License is distributed on an
159e0fc027SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169e0fc027SAndrew Rist * KIND, either express or implied. See the License for the
179e0fc027SAndrew Rist * specific language governing permissions and limitations
189e0fc027SAndrew Rist * under the License.
199e0fc027SAndrew Rist *
209e0fc027SAndrew Rist *************************************************************/
219e0fc027SAndrew Rist
229e0fc027SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_filter.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <cstdio>
28cdf0e10cSrcweir #include "svgfilter.hxx"
29cdf0e10cSrcweir #include <vos/mutex.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
32cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawView.hpp>
33cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hdl>
34cdf0e10cSrcweir #include <com/sun/star/frame/XController.hdl>
35*33f678ddSArmin Le Grand #include <com/sun/star/view/XSelectionSupplier.hpp>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #define SVG_FILTER_SERVICE_NAME "com.sun.star.comp.Draw.SVGFilter"
38cdf0e10cSrcweir #define SVG_FILTER_IMPLEMENTATION_NAME SVG_FILTER_SERVICE_NAME
39cdf0e10cSrcweir
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir
43cdf0e10cSrcweir // -------------
44cdf0e10cSrcweir // - SVGFilter -
45cdf0e10cSrcweir // -------------
46cdf0e10cSrcweir
SVGFilter(const Reference<XMultiServiceFactory> & rxMSF)47cdf0e10cSrcweir SVGFilter::SVGFilter( const Reference< XMultiServiceFactory > &rxMSF ) :
48cdf0e10cSrcweir mxMSF( rxMSF ),
49cdf0e10cSrcweir mpSVGDoc( NULL ),
50cdf0e10cSrcweir mpSVGExport( NULL ),
51cdf0e10cSrcweir mpSVGFontExport( NULL ),
52cdf0e10cSrcweir mpSVGWriter( NULL ),
53cdf0e10cSrcweir mpDefaultSdrPage( NULL ),
54cdf0e10cSrcweir mpSdrModel( NULL ),
55*33f678ddSArmin Le Grand mbPresentation( sal_False ),
56*33f678ddSArmin Le Grand mpObjects( NULL ),
57*33f678ddSArmin Le Grand mxSrcDoc(),
58*33f678ddSArmin Le Grand #ifdef SOLAR_JAVA
59*33f678ddSArmin Le Grand mxDstDoc(),
60*33f678ddSArmin Le Grand #endif
61*33f678ddSArmin Le Grand mxDefaultPage(),
62*33f678ddSArmin Le Grand maFilterData(),
63*33f678ddSArmin Le Grand maShapeSelection(),
64*33f678ddSArmin Le Grand mbExportSelection(false),
65*33f678ddSArmin Le Grand maUniqueIdVector(),
66*33f678ddSArmin Le Grand mnMasterSlideId(0),
67*33f678ddSArmin Le Grand mnSlideId(0),
68*33f678ddSArmin Le Grand mnDrawingGroupId(0),
69*33f678ddSArmin Le Grand mnDrawingId(0),
70*33f678ddSArmin Le Grand maOldFieldHdl()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir // -----------------------------------------------------------------------------
75cdf0e10cSrcweir
~SVGFilter()76cdf0e10cSrcweir SVGFilter::~SVGFilter()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir DBG_ASSERT( mpSVGDoc == NULL, "mpSVGDoc not destroyed" );
79cdf0e10cSrcweir DBG_ASSERT( mpSVGExport == NULL, "mpSVGExport not destroyed" );
80cdf0e10cSrcweir DBG_ASSERT( mpSVGFontExport == NULL, "mpSVGFontExport not destroyed" );
81cdf0e10cSrcweir DBG_ASSERT( mpSVGWriter == NULL, "mpSVGWriter not destroyed" );
82cdf0e10cSrcweir DBG_ASSERT( mpObjects == NULL, "mpObjects not destroyed" );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir // -----------------------------------------------------------------------------
86cdf0e10cSrcweir
filter(const Sequence<PropertyValue> & rDescriptor)87cdf0e10cSrcweir sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescriptor )
88cdf0e10cSrcweir throw (RuntimeException)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() );
91cdf0e10cSrcweir Window* pFocusWindow = Application::GetFocusWindow();
92cdf0e10cSrcweir sal_Int16 nCurrentPageNumber = -1;
93cdf0e10cSrcweir sal_Bool bRet;
94cdf0e10cSrcweir
95cdf0e10cSrcweir if( pFocusWindow )
96cdf0e10cSrcweir pFocusWindow->EnterWait();
97cdf0e10cSrcweir
98cdf0e10cSrcweir #ifdef SOLAR_JAVA
99cdf0e10cSrcweir if( mxDstDoc.is() )
100cdf0e10cSrcweir bRet = sal_False;//implImport( rDescriptor );
101cdf0e10cSrcweir else
102cdf0e10cSrcweir #endif
103cdf0e10cSrcweir if( mxSrcDoc.is() )
104cdf0e10cSrcweir {
105*33f678ddSArmin Le Grand // #124608# detext selection
106*33f678ddSArmin Le Grand sal_Bool bSelectionOnly = sal_False;
107*33f678ddSArmin Le Grand bool bGotSelection(false);
108*33f678ddSArmin Le Grand Reference< drawing::XShapes > xShapes;
109*33f678ddSArmin Le Grand
110*33f678ddSArmin Le Grand // #124608# extract Single selection wanted from dialog return values
111*33f678ddSArmin Le Grand for ( sal_Int32 nInd = 0; nInd < rDescriptor.getLength(); nInd++ )
112*33f678ddSArmin Le Grand {
113*33f678ddSArmin Le Grand if ( rDescriptor[nInd].Name.equalsAscii( "SelectionOnly" ) )
114*33f678ddSArmin Le Grand {
115*33f678ddSArmin Le Grand rDescriptor[nInd].Value >>= bSelectionOnly;
116*33f678ddSArmin Le Grand }
117*33f678ddSArmin Le Grand }
118*33f678ddSArmin Le Grand
119*33f678ddSArmin Le Grand uno::Reference< frame::XDesktop > xDesktop( mxMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
120cdf0e10cSrcweir uno::UNO_QUERY);
121cdf0e10cSrcweir if( xDesktop.is() )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( xDesktop->getCurrentFrame() );
124cdf0e10cSrcweir
125cdf0e10cSrcweir if( xFrame.is() )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir uno::Reference< frame::XController > xController( xFrame->getController() );
128cdf0e10cSrcweir
129cdf0e10cSrcweir if( xController.is() )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY );
132cdf0e10cSrcweir
133cdf0e10cSrcweir if( xDrawView.is() )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > xDrawPage( xDrawView->getCurrentPage() );
136cdf0e10cSrcweir
137cdf0e10cSrcweir if( xDrawPage.is() )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir uno::Reference< beans::XPropertySet >( xDrawPage, uno::UNO_QUERY )->
140cdf0e10cSrcweir getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Number" ) ) ) >>= nCurrentPageNumber;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir }
143*33f678ddSArmin Le Grand
144*33f678ddSArmin Le Grand if(bSelectionOnly)
145*33f678ddSArmin Le Grand {
146*33f678ddSArmin Le Grand // #124608# when selection only is wanted, get the current object selection
147*33f678ddSArmin Le Grand // from the DrawView
148*33f678ddSArmin Le Grand Reference< view::XSelectionSupplier > xSelection (xController, UNO_QUERY);
149*33f678ddSArmin Le Grand
150*33f678ddSArmin Le Grand if (xSelection.is())
151*33f678ddSArmin Le Grand {
152*33f678ddSArmin Le Grand uno::Any aSelection;
153*33f678ddSArmin Le Grand
154*33f678ddSArmin Le Grand if(xSelection->getSelection() >>= aSelection)
155*33f678ddSArmin Le Grand {
156*33f678ddSArmin Le Grand bGotSelection = (sal_True == ( aSelection >>= xShapes ));
157*33f678ddSArmin Le Grand }
158*33f678ddSArmin Le Grand }
159*33f678ddSArmin Le Grand }
160*33f678ddSArmin Le Grand }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163*33f678ddSArmin Le Grand
164*33f678ddSArmin Le Grand if(bSelectionOnly && bGotSelection && 0 == xShapes->getCount())
165*33f678ddSArmin Le Grand {
166*33f678ddSArmin Le Grand // #124608# export selection, got xShapes but no shape selected -> nothing
167*33f678ddSArmin Le Grand // to export, we are done (maybe return true, but a hint that nothing was done
168*33f678ddSArmin Le Grand // may be useful; it may have happened by error)
169*33f678ddSArmin Le Grand bRet = sal_False;
170*33f678ddSArmin Le Grand }
171*33f678ddSArmin Le Grand else
172*33f678ddSArmin Le Grand {
173*33f678ddSArmin Le Grand Sequence< PropertyValue > aNewDescriptor(rDescriptor);
174*33f678ddSArmin Le Grand const bool bSinglePage(nCurrentPageNumber > 0);
175*33f678ddSArmin Le Grand
176*33f678ddSArmin Le Grand if(bSinglePage || bGotSelection)
177*33f678ddSArmin Le Grand {
178*33f678ddSArmin Le Grand const sal_uInt32 nOldLength = rDescriptor.getLength();
179*33f678ddSArmin Le Grand sal_uInt32 nInsert(nOldLength);
180*33f678ddSArmin Le Grand
181*33f678ddSArmin Le Grand aNewDescriptor.realloc(nOldLength + (bSinglePage ? 1 : 0) + (bGotSelection ? 1 : 0));
182*33f678ddSArmin Le Grand
183*33f678ddSArmin Le Grand if(bSinglePage)
184*33f678ddSArmin Le Grand {
185*33f678ddSArmin Le Grand aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PagePos"));
186*33f678ddSArmin Le Grand aNewDescriptor[nInsert].Value <<= static_cast<sal_Int16>(nCurrentPageNumber - 1);
187*33f678ddSArmin Le Grand nInsert++;
188*33f678ddSArmin Le Grand }
189*33f678ddSArmin Le Grand
190*33f678ddSArmin Le Grand if(bGotSelection)
191*33f678ddSArmin Le Grand {
192*33f678ddSArmin Le Grand // #124608# add retrieved ShapeSelection if export of only selected shapes is wanted
193*33f678ddSArmin Le Grand // so that the filter implementation can use it
194*33f678ddSArmin Le Grand aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShapeSelection"));
195*33f678ddSArmin Le Grand aNewDescriptor[nInsert].Value <<= xShapes;
196*33f678ddSArmin Le Grand // reactivate this when you add other properties to aNewDescriptor
197*33f678ddSArmin Le Grand // nInsert++;
198*33f678ddSArmin Le Grand }
199*33f678ddSArmin Le Grand }
200*33f678ddSArmin Le Grand
201*33f678ddSArmin Le Grand bRet = implExport(aNewDescriptor);
202*33f678ddSArmin Le Grand }
203*33f678ddSArmin Le Grand }
204cdf0e10cSrcweir else
205cdf0e10cSrcweir bRet = sal_False;
206cdf0e10cSrcweir
207cdf0e10cSrcweir if( pFocusWindow )
208cdf0e10cSrcweir pFocusWindow->LeaveWait();
209cdf0e10cSrcweir
210cdf0e10cSrcweir return bRet;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir // -----------------------------------------------------------------------------
214cdf0e10cSrcweir
cancel()215cdf0e10cSrcweir void SAL_CALL SVGFilter::cancel( ) throw (RuntimeException)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
219cdf0e10cSrcweir // -----------------------------------------------------------------------------
220cdf0e10cSrcweir
setSourceDocument(const Reference<XComponent> & xDoc)221cdf0e10cSrcweir void SAL_CALL SVGFilter::setSourceDocument( const Reference< XComponent >& xDoc )
222cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir mxSrcDoc = xDoc;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir // -----------------------------------------------------------------------------
228cdf0e10cSrcweir
229cdf0e10cSrcweir #ifdef SOLAR_JAVA
setTargetDocument(const Reference<XComponent> & xDoc)230cdf0e10cSrcweir void SAL_CALL SVGFilter::setTargetDocument( const Reference< XComponent >& xDoc )
231cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir mxDstDoc = xDoc;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir #endif
236cdf0e10cSrcweir
237cdf0e10cSrcweir // -----------------------------------------------------------------------------
238cdf0e10cSrcweir
initialize(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> &)239cdf0e10cSrcweir void SAL_CALL SVGFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& /* aArguments */ )
240cdf0e10cSrcweir throw (Exception, RuntimeException)
241cdf0e10cSrcweir {
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir // -----------------------------------------------------------------------------
245cdf0e10cSrcweir
SVGFilter_getImplementationName()246cdf0e10cSrcweir OUString SVGFilter_getImplementationName ()
247cdf0e10cSrcweir throw (RuntimeException)
248cdf0e10cSrcweir {
249cdf0e10cSrcweir return OUString ( RTL_CONSTASCII_USTRINGPARAM ( SVG_FILTER_IMPLEMENTATION_NAME ) );
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir // -----------------------------------------------------------------------------
253cdf0e10cSrcweir
SVGFilter_supportsService(const OUString & rServiceName)254cdf0e10cSrcweir sal_Bool SAL_CALL SVGFilter_supportsService( const OUString& rServiceName )
255cdf0e10cSrcweir throw (RuntimeException)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir return( rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SVG_FILTER_SERVICE_NAME ) ) );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir // -----------------------------------------------------------------------------
261cdf0e10cSrcweir
SVGFilter_getSupportedServiceNames()262cdf0e10cSrcweir Sequence< OUString > SAL_CALL SVGFilter_getSupportedServiceNames( ) throw (RuntimeException)
263cdf0e10cSrcweir {
264cdf0e10cSrcweir Sequence < OUString > aRet(1);
265cdf0e10cSrcweir OUString* pArray = aRet.getArray();
266cdf0e10cSrcweir pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SVG_FILTER_SERVICE_NAME ) );
267cdf0e10cSrcweir return aRet;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270cdf0e10cSrcweir // -----------------------------------------------------------------------------
271cdf0e10cSrcweir
SVGFilter_createInstance(const Reference<XMultiServiceFactory> & rSMgr)272cdf0e10cSrcweir Reference< XInterface > SAL_CALL SVGFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir return (cppu::OWeakObject*) new SVGFilter( rSMgr );
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir // -----------------------------------------------------------------------------
278cdf0e10cSrcweir
getImplementationName()279cdf0e10cSrcweir OUString SAL_CALL SVGFilter::getImplementationName( )
280cdf0e10cSrcweir throw (RuntimeException)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir return SVGFilter_getImplementationName();
283cdf0e10cSrcweir }
284cdf0e10cSrcweir
285cdf0e10cSrcweir // -----------------------------------------------------------------------------
286cdf0e10cSrcweir
supportsService(const OUString & rServiceName)287cdf0e10cSrcweir sal_Bool SAL_CALL SVGFilter::supportsService( const OUString& rServiceName )
288cdf0e10cSrcweir throw (RuntimeException)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir return SVGFilter_supportsService( rServiceName );
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
293cdf0e10cSrcweir // -----------------------------------------------------------------------------
294cdf0e10cSrcweir
getSupportedServiceNames()295cdf0e10cSrcweir ::com::sun::star::uno::Sequence< OUString > SAL_CALL SVGFilter::getSupportedServiceNames( ) throw (RuntimeException)
296cdf0e10cSrcweir {
297cdf0e10cSrcweir return SVGFilter_getSupportedServiceNames();
298cdf0e10cSrcweir }
299