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: sdcgmfilter.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"
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>
43 #include "drawdoc.hxx"
44 #include "sdcgmfilter.hxx"
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
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star::task
;
67 using namespace ::com::sun::star::frame
;
73 typedef UINT32 ( __LOADONCALLAPI
*ImportCGM
)( ::rtl::OUString
&, Reference
< XModel
>&, UINT32
, Reference
< XStatusIndicator
>& );
74 typedef BOOL ( __LOADONCALLAPI
*ExportCGM
)( ::rtl::OUString
&, Reference
< XModel
>&, Reference
< XStatusIndicator
>&, void* );
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
) );
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
);
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
);
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
);
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" ) ) );
150 ::rtl::OUString
aPhysicalName( mrMedium
.GetPhysicalName() );
153 if ( pViewShell && pViewShell->GetView() )
154 pViewShell->GetView()->SdrEndTextEdit();
156 CreateStatusIndicator();
157 bRet
= FncCGMExport( aPhysicalName
, mxModel
, mxStatusIndicator
, NULL
);