merge the formfield patch from ooo-build
[ooovba.git] / sd / source / filter / cgm / sdcgmfilter.cxx
blobfdc1f3066902ab71d9bf7f16ad5cc49646a783ac
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdcgmfilter.cxx,v $
10 * $Revision: 1.9 $
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"
34 #include <osl/module.hxx>
35 #include <tools/urlobj.hxx>
36 #include <svtools/itemset.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <sfx2/docfilt.hxx>
39 #include <svx/xflclit.hxx>
40 #include <svx/xfillit0.hxx>
42 #include "sdpage.hxx"
43 #include "drawdoc.hxx"
44 #include "sdcgmfilter.hxx"
46 // -----------
47 // - Defines -
48 // -----------
50 #define CGM_IMPORT_CGM 0x00000001
51 #define CGM_IMPORT_IM 0x00000002
53 #define CGM_EXPORT_IMPRESS 0x00000100
54 #define CGM_EXPORT_META 0x00000200
55 #define CGM_EXPORT_COMMENT 0x00000400
57 #define CGM_NO_PAD_BYTE 0x00010000
58 #define CGM_BIG_ENDIAN 0x00020000
59 #define CGM_LITTLE_ENDIAN 0x00040000
61 // --------------
62 // - Namespaces -
63 // --------------
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::task;
67 using namespace ::com::sun::star::frame;
69 // ------------
70 // - Typedefs -
71 // ------------
73 typedef UINT32 ( __LOADONCALLAPI *ImportCGM )( ::rtl::OUString&, Reference< XModel >&, UINT32, Reference< XStatusIndicator >& );
74 typedef BOOL ( __LOADONCALLAPI *ExportCGM )( ::rtl::OUString&, Reference< XModel >&, Reference< XStatusIndicator >&, void* );
76 // ---------------
77 // - SdPPTFilter -
78 // ---------------
80 SdCGMFilter::SdCGMFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress ) :
81 SdFilter( rMedium, rDocShell, bShowProgress )
85 // -----------------------------------------------------------------------------
87 SdCGMFilter::~SdCGMFilter()
91 // -----------------------------------------------------------------------------
93 sal_Bool SdCGMFilter::Import()
95 ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
96 sal_Bool bRet = sal_False;
98 if( pLibrary && mxModel.is() )
100 ImportCGM FncImportCGM = reinterpret_cast< ImportCGM >( pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii( "ImportCGM" ) ) );
101 ::rtl::OUString aFileURL( mrMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
102 UINT32 nRetValue;
104 if( mrDocument.GetPageCount() == 0L )
105 mrDocument.CreateFirstPages();
107 CreateStatusIndicator();
108 nRetValue = FncImportCGM( aFileURL, mxModel, CGM_IMPORT_CGM | CGM_BIG_ENDIAN | CGM_EXPORT_IMPRESS, mxStatusIndicator );
110 if( nRetValue )
112 bRet = TRUE;
114 if( ( nRetValue &~0xff000000 ) != 0xffffff ) // maybe the backgroundcolor is already white
115 { // so we must not set a master page
116 mrDocument.StopWorkStartupDelay();
117 SdrObject* pObj = mrDocument.GetMasterSdPage(0, PK_STANDARD)->GetPresObj(PRESOBJ_BACKGROUND);
119 if( pObj )
121 SfxItemSet aSet( mrDocument.GetPool() );
122 Color aColor( (BYTE)( nRetValue >> 16 ), (BYTE)( nRetValue >> 8 ), (BYTE)( nRetValue >> 16 ) );
124 aSet.Put( XFillColorItem( String(), aColor ) );
125 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
126 pObj->SetMergedItemSetAndBroadcast( aSet );
132 delete pLibrary;
134 return bRet;
137 // -----------------------------------------------------------------------------
139 sal_Bool SdCGMFilter::Export()
141 ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
142 sal_Bool bRet = sal_False;
144 if( pLibrary && mxModel.is() )
146 ExportCGM FncCGMExport = reinterpret_cast< ExportCGM >( pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii( "ExportCGM" ) ) );
148 if( FncCGMExport )
150 ::rtl::OUString aPhysicalName( mrMedium.GetPhysicalName() );
152 /* !!!
153 if ( pViewShell && pViewShell->GetView() )
154 pViewShell->GetView()->SdrEndTextEdit();
156 CreateStatusIndicator();
157 bRet = FncCGMExport( aPhysicalName, mxModel, mxStatusIndicator, NULL );
161 delete pLibrary;
163 return bRet;