1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sddll.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <svx/eeitem.hxx>
35 #include <svx/editeng.hxx>
36 #include <svx/svdobj.hxx>
37 #include <svtools/moduleoptions.hxx>
38 #ifndef _FM_FMOBJFAC_HXX
39 #include <svx/fmobjfac.hxx>
41 #include <svx/svdfield.hxx>
42 #include <svx/objfac3d.hxx>
46 #include "DrawDocShell.hxx"
47 #include "GraphicDocShell.hxx"
48 #include "sdresid.hxx"
49 #include "sdobjfac.hxx"
52 #include "SdShapeTypes.hxx"
54 #include <svx/SvxShapeTypes.hxx>
55 #include <sfx2/docfilt.hxx>
56 #include <sfx2/docfile.hxx>
57 #include <sfx2/fcontnr.hxx>
58 #include <tools/urlobj.hxx>
59 #include <svx/impgrf.hxx>
60 #include <svtools/FilterConfigItem.hxx>
61 #include <com/sun/star/util/XArchiver.hpp>
62 #include <comphelper/processfactory.hxx>
64 using namespace ::rtl
;
65 using namespace ::com::sun::star
;
68 /*************************************************************************
72 \************************************************************************/
79 SfxObjectFactory
* pDrawFact
= NULL
;
80 SfxObjectFactory
* pImpressFact
= NULL
;
82 if (SvtModuleOptions().IsImpress())
83 pImpressFact
= &::sd::DrawDocShell::Factory();
85 if (SvtModuleOptions().IsDraw())
86 pDrawFact
= &::sd::GraphicDocShell::Factory();
88 // the SdModule must be created
89 SdModule
** ppShlPtr
= (SdModule
**) GetAppData(SHL_DRAW
);
92 // The SfxModule::SfxModule stops when the first given factory
93 // is 0, so we must not give a 0 as first factory
96 (*ppShlPtr
) = new SdModule( pImpressFact
, pDrawFact
);
100 (*ppShlPtr
) = new SdModule( pDrawFact
, pImpressFact
);
103 if (SvtModuleOptions().IsImpress())
105 // Register the Impress shape types in order to make the shapes accessible.
106 ::accessibility::RegisterImpressShapeTypes ();
107 ::sd::DrawDocShell::Factory().SetDocumentServiceName( String( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) );
110 if (SvtModuleOptions().IsDraw())
112 ::sd::GraphicDocShell::Factory().SetDocumentServiceName( String( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) );
115 // register your view-factories here
118 // register your shell-interfaces here
119 RegisterInterfaces();
121 // register your controllers here
122 RegisterControllers();
124 // SvDraw-Felder registrieren
125 SdrRegisterFieldClasses();
127 // 3D-Objekt-Factory eintragen
130 // ::com::sun::star::form::component::Form-Objekt-Factory eintragen
133 // Objekt-Factory eintragen
134 SdrObjFactory::InsertMakeUserDataHdl(LINK(&aSdObjectFactory
, SdObjectFactory
, MakeUserData
));
139 /*************************************************************************
143 \************************************************************************/
147 // called directly befor unloading the DLL
148 // do whatever you want, Sd-DLL is accessible
150 // Objekt-Factory austragen
151 SdrObjFactory::RemoveMakeUserDataHdl(LINK(&aSdObjectFactory
, SdObjectFactory
, MakeUserData
));
153 // the SdModule must be destroyed
154 SdModule
** ppShlPtr
= (SdModule
**) GetAppData(SHL_DRAW
);
160 ULONG SdDLL::DetectFilter(SfxMedium& rMedium, const SfxFilter** ppFilter,
161 SfxFilterFlags nMust, SfxFilterFlags nDont)
163 ULONG nReturn = ERRCODE_ABORT; // Erkennung fehlgeschlagen, Filter ungueltig
164 BOOL bStorage = FALSE;
166 if( *ppFilter && (*ppFilter)->GetFilterFlags() & SFX_FILTER_PACKED )
168 uno::Reference< lang::XMultiServiceFactory > xSMgr( ::comphelper::getProcessServiceFactory() );
169 uno::Reference< util::XArchiver > xPacker( xSMgr->createInstance( OUString::createFromAscii( "com.sun.star.util.Archiver" ) ), uno::UNO_QUERY );
172 // extract extra data
173 OUString aPath( rMedium.GetOrigURL() );
174 OUString aExtraData( xPacker->getExtraData( aPath ) );
175 const OUString aSig1= OUString::createFromAscii( "private:" );
177 aTmp += sal_Unicode( '?' );
178 aTmp += String::CreateFromAscii("simpress");
179 const OUString aSig2( aTmp );
180 INT32 nIndex1 = aExtraData.indexOf( aSig1 );
181 INT32 nIndex2 = aExtraData.indexOf( aSig2 );
182 if( nIndex1 == 0 && nIndex2 != -1 )
186 else if (rMedium.GetError() == SVSTREAM_OK)
188 if ( rMedium.IsStorage() )
191 SotStorageRef xStorage = rMedium.GetStorage();
192 if ( !xStorage.Is() )
195 if( SvtModuleOptions().IsImpress() )
197 // Erkennung ueber contained streams (PowerPoint 97-Filter)
198 String aStreamName = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PowerPoint Document" ) );
199 if ( xStorage->IsContained( aStreamName ) && xStorage->IsStream( aStreamName ) )
201 String aFileName(rMedium.GetName());
202 aFileName.ToUpperAscii();
204 if( aFileName.SearchAscii( ".POT" ) == STRING_NOTFOUND )
205 *ppFilter = SfxFilter::GetFilterByName( pFilterPowerPoint97);
207 *ppFilter = SfxFilter::GetFilterByName( pFilterPowerPoint97Template );
213 const SfxFilter* pFilter = *ppFilter;
216 if ( (*ppFilter)->GetFormat() == xStorage->GetFormat() )
220 if( !pFilter && SvtModuleOptions().IsImpress() )
222 SfxFilterMatcher aMatcher( String::CreateFromAscii("simpress") );
223 pFilter = aMatcher.GetFilter4ClipBoardId( xStorage->GetFormat() );
228 if( !pFilter && SvtModuleOptions().IsDraw() )
230 SfxFilterMatcher aMatcher( String::CreateFromAscii("sdraw") );
231 pFilter = aMatcher.GetFilter4ClipBoardId( xStorage->GetFormat() );
237 ( pFilter->GetFilterFlags() & nMust ) == nMust &&
238 ( pFilter->GetFilterFlags() & nDont ) == 0 )
241 nReturn = ERRCODE_NONE;
246 nReturn = ERRCODE_NONE;
250 String aFileName( rMedium.GetName() );
251 aFileName.ToUpperAscii();
253 if ( nReturn == ERRCODE_ABORT )
255 if( bStorage ) // aber keine Clipboard-Id #55337#
262 SvStream* pStm = rMedium.GetInStream();
265 nReturn = ERRCODE_IO_GENERAL;
268 pStm->Seek( STREAM_SEEK_TO_BEGIN );
270 const String aFileName( rMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
271 GraphicDescriptor aDesc( *pStm, &aFileName );
272 GraphicFilter* pGrfFilter = GetGrfFilter();
274 if( !aDesc.Detect( FALSE ) )
276 if( SvtModuleOptions().IsImpress() )
279 nReturn = ERRCODE_ABORT;
280 INetURLObject aURL( aFileName );
281 if( aURL.getExtension().equalsIgnoreAsciiCaseAscii( "cgm" ) )
284 pStm->Seek( STREAM_SEEK_TO_BEGIN );
286 if ( ( n8 & 0xf0 ) == 0 ) // we are supporting binary cgm format only, so
287 { // this is a small test to exclude cgm text
288 const String aName = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "CGM - Computer Graphics Metafile" ) );
289 SfxFilterMatcher aMatch( String::CreateFromAscii("simpress") );
290 *ppFilter = aMatch.GetFilter4FilterName( aName );
291 nReturn = ERRCODE_NONE;
298 if( SvtModuleOptions().IsDraw() )
300 String aShortName( aDesc.GetImportFormatShortName( aDesc.GetFileFormat() ) );
301 const String aName( pGrfFilter->GetImportFormatTypeName( pGrfFilter->GetImportFormatNumberForShortName( aShortName ) ) );
303 if ( *ppFilter && aShortName.EqualsIgnoreCaseAscii( "PCD" ) ) // there is a multiple pcd selection possible
305 sal_Int32 nBase = 2; // default Base0
306 String aFilterTypeName( (*ppFilter)->GetRealTypeName() );
307 if ( aFilterTypeName.CompareToAscii( "pcd_Photo_CD_Base4" ) == COMPARE_EQUAL )
309 else if ( aFilterTypeName.CompareToAscii( "pcd_Photo_CD_Base16" ) == COMPARE_EQUAL )
311 String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Import/PCD" ) );
312 FilterConfigItem aFilterConfigItem( aFilterConfigPath );
313 aFilterConfigItem.WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Resolution" ) ), nBase );
316 SfxFilterMatcher aMatch( String::CreateFromAscii("draw") );
317 *ppFilter = aMatch.GetFilter4FilterName( aName );
318 nReturn = ERRCODE_NONE;
322 nReturn = ERRCODE_ABORT;
332 nReturn = rMedium.GetError();