xref: /AOO41X/main/svx/source/gallery2/galobj.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
34*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
35*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <comphelper/classids.hxx>
38*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <tools/rcid.h>
41*cdf0e10cSrcweir #include <tools/vcompat.hxx>
42*cdf0e10cSrcweir #include <vcl/virdev.hxx>
43*cdf0e10cSrcweir #include <svl/itempool.hxx>
44*cdf0e10cSrcweir #include <svx/fmmodel.hxx>
45*cdf0e10cSrcweir #include <svx/fmview.hxx>
46*cdf0e10cSrcweir #include <svx/fmpage.hxx>
47*cdf0e10cSrcweir #include "gallery.hrc"
48*cdf0e10cSrcweir #include "svx/galmisc.hxx"
49*cdf0e10cSrcweir #include "galobj.hxx"
50*cdf0e10cSrcweir #include <vcl/salbtype.hxx>		// FRound
51*cdf0e10cSrcweir #include <vcl/svapp.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include "gallerydrawmodel.hxx"
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir using namespace ::com::sun::star;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir // -------------
58*cdf0e10cSrcweir // - SgaObject -
59*cdf0e10cSrcweir // -------------
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir SgaObject::SgaObject() :
62*cdf0e10cSrcweir 		bIsValid    ( sal_False ),
63*cdf0e10cSrcweir 		bIsThumbBmp	( sal_True )
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir // ------------------------------------------------------------------------
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	if( rGraphic.GetType() == GRAPHIC_BITMAP )
74*cdf0e10cSrcweir 	{
75*cdf0e10cSrcweir 		BitmapEx    aBmpEx( rGraphic.GetBitmapEx() );
76*cdf0e10cSrcweir 		Size        aBmpSize( aBmpEx.GetSizePixel() );
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		if( aBmpSize.Width() && aBmpSize.Height() )
79*cdf0e10cSrcweir 		{
80*cdf0e10cSrcweir 			const Color	aWhite( COL_WHITE );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 		    if( aBmpEx.GetPrefMapMode().GetMapUnit() != MAP_PIXEL &&
83*cdf0e10cSrcweir 		        aBmpEx.GetPrefSize().Width() > 0 &&
84*cdf0e10cSrcweir 		        aBmpEx.GetPrefSize().Height() > 0 )
85*cdf0e10cSrcweir 		    {
86*cdf0e10cSrcweir 		        Size aLogSize( OutputDevice::LogicToLogic( aBmpEx.GetPrefSize(), aBmpEx.GetPrefMapMode(), MAP_100TH_MM ) );
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 		        if( aLogSize.Width() > 0 && aLogSize.Height() > 0 )
89*cdf0e10cSrcweir 		        {
90*cdf0e10cSrcweir 		            double  fFactorLog = static_cast< double >( aLogSize.Width() ) / aLogSize.Height();
91*cdf0e10cSrcweir 		            double  fFactorPix = static_cast< double >( aBmpSize.Width() ) / aBmpSize.Height();
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 		            if( fFactorPix > fFactorLog )
94*cdf0e10cSrcweir 		                aBmpSize.Width() = FRound( aBmpSize.Height() * fFactorLog );
95*cdf0e10cSrcweir 		            else
96*cdf0e10cSrcweir 		                aBmpSize.Height() = FRound( aBmpSize.Width() / fFactorLog );
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 		            aBmpEx.SetSizePixel( aBmpSize );
99*cdf0e10cSrcweir 		        }
100*cdf0e10cSrcweir 		    }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 			aThumbBmp = aBmpEx.GetBitmap( &aWhite );
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 			if( ( aBmpSize.Width() <= S_THUMB ) && ( aBmpSize.Height() <= S_THUMB ) )
105*cdf0e10cSrcweir 			{
106*cdf0e10cSrcweir 				aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
107*cdf0e10cSrcweir 				bRet = sal_True;
108*cdf0e10cSrcweir 			}
109*cdf0e10cSrcweir 			else
110*cdf0e10cSrcweir 			{
111*cdf0e10cSrcweir 				const float	fFactor  = (float) aBmpSize.Width() / aBmpSize.Height();
112*cdf0e10cSrcweir 				const Size	aNewSize( Max( (long) (fFactor < 1. ? S_THUMB * fFactor : S_THUMB), 8L ),
113*cdf0e10cSrcweir 									  Max( (long) (fFactor < 1. ? S_THUMB : S_THUMB / fFactor), 8L ) );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 				if( aThumbBmp.Scale( (double) aNewSize.Width() / aBmpSize.Width(),
116*cdf0e10cSrcweir 									 (double) aNewSize.Height() / aBmpSize.Height(), BMP_SCALE_INTERPOLATE ) )
117*cdf0e10cSrcweir 				{
118*cdf0e10cSrcweir 					aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
119*cdf0e10cSrcweir 					bRet = sal_True;
120*cdf0e10cSrcweir 				}
121*cdf0e10cSrcweir 			}
122*cdf0e10cSrcweir 		}
123*cdf0e10cSrcweir 	}
124*cdf0e10cSrcweir 	else if( rGraphic.GetType() == GRAPHIC_GDIMETAFILE )
125*cdf0e10cSrcweir 	{
126*cdf0e10cSrcweir 		const Size aPrefSize( rGraphic.GetPrefSize() );
127*cdf0e10cSrcweir 		const double fFactor  = (double)aPrefSize.Width() / (double)aPrefSize.Height();
128*cdf0e10cSrcweir         Size aSize( S_THUMB, S_THUMB );
129*cdf0e10cSrcweir 		if ( fFactor < 1.0 )
130*cdf0e10cSrcweir 			aSize.Width() = (sal_Int32)( S_THUMB * fFactor );
131*cdf0e10cSrcweir 		else
132*cdf0e10cSrcweir 			aSize.Height() = (sal_Int32)( S_THUMB / fFactor );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         const GraphicConversionParameters aParameters(aSize);
135*cdf0e10cSrcweir         aThumbBmp = rGraphic.GetBitmap(aParameters);
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 		if( !aThumbBmp.IsEmpty() )
138*cdf0e10cSrcweir 		{
139*cdf0e10cSrcweir 			aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
140*cdf0e10cSrcweir 			bRet = sal_True;
141*cdf0e10cSrcweir 		}
142*cdf0e10cSrcweir 	}
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	return bRet;
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir // ------------------------------------------------------------------------
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir void SgaObject::WriteData( SvStream& rOut, const String& rDestDir ) const
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir 	static const sal_uInt32 nInventor = COMPAT_FORMAT( 'S', 'G', 'A', '3' );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	rOut << nInventor << (sal_uInt16) 0x0004 << GetVersion() << (sal_uInt16) GetObjKind();
154*cdf0e10cSrcweir 	rOut << bIsThumbBmp;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	if( bIsThumbBmp )
157*cdf0e10cSrcweir 	{
158*cdf0e10cSrcweir 		const sal_uInt16	nOldCompressMode = rOut.GetCompressMode();
159*cdf0e10cSrcweir 		const sal_uIntPtr		nOldVersion = rOut.GetVersion();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 		rOut.SetCompressMode( COMPRESSMODE_ZBITMAP );
162*cdf0e10cSrcweir 		rOut.SetVersion( SOFFICE_FILEFORMAT_50 );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 		rOut << aThumbBmp;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 		rOut.SetVersion( nOldVersion );
167*cdf0e10cSrcweir 		rOut.SetCompressMode( nOldCompressMode );
168*cdf0e10cSrcweir 	}
169*cdf0e10cSrcweir 	else
170*cdf0e10cSrcweir 		rOut << aThumbMtf;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	String aURLWithoutDestDir = String(aURL.GetMainURL( INetURLObject::NO_DECODE ));
173*cdf0e10cSrcweir 	aURLWithoutDestDir.SearchAndReplace(rDestDir, String());
174*cdf0e10cSrcweir 	rOut << ByteString( aURLWithoutDestDir, RTL_TEXTENCODING_UTF8 );
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir // ------------------------------------------------------------------------
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir void SgaObject::ReadData(SvStream& rIn, sal_uInt16& rReadVersion )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	ByteString	aTmpStr;
182*cdf0e10cSrcweir 	sal_uInt32		nTmp32;
183*cdf0e10cSrcweir 	sal_uInt16		nTmp16;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	rIn >> nTmp32 >> nTmp16 >> rReadVersion >> nTmp16 >> bIsThumbBmp;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	if( bIsThumbBmp )
188*cdf0e10cSrcweir 		rIn >> aThumbBmp;
189*cdf0e10cSrcweir 	else
190*cdf0e10cSrcweir 		rIn >> aThumbMtf;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	rIn >> aTmpStr; aURL = INetURLObject( String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 ) );
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // ------------------------------------------------------------------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir const String SgaObject::GetTitle() const
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	String aReturnValue( aTitle );
200*cdf0e10cSrcweir 	if ( !getenv( "GALLERY_SHOW_PRIVATE_TITLE" ) )
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		if ( aReturnValue.GetTokenCount( ':' ) == 3 )
203*cdf0e10cSrcweir 		{
204*cdf0e10cSrcweir 			String		aPrivateInd  ( aReturnValue.GetToken( 0, ':' ) );
205*cdf0e10cSrcweir 			String		aResourceName( aReturnValue.GetToken( 1, ':' ) );
206*cdf0e10cSrcweir 			sal_Int32	nResId		 ( aReturnValue.GetToken( 2, ':' ).ToInt32() );
207*cdf0e10cSrcweir 			if ( aReturnValue.GetToken( 0, ':' ).EqualsAscii( "private" ) &&
208*cdf0e10cSrcweir 				aResourceName.Len() && ( nResId > 0 ) && ( nResId < 0x10000 ) )
209*cdf0e10cSrcweir 			{
210*cdf0e10cSrcweir 				ByteString aMgrName( aResourceName, RTL_TEXTENCODING_UTF8 );
211*cdf0e10cSrcweir 				ResMgr* pResMgr = ResMgr::CreateResMgr( aMgrName.GetBuffer(),
212*cdf0e10cSrcweir 							Application::GetSettings().GetUILocale() );
213*cdf0e10cSrcweir 				if ( pResMgr )
214*cdf0e10cSrcweir 				{
215*cdf0e10cSrcweir 					ResId aResId( (sal_uInt16)nResId, *pResMgr );
216*cdf0e10cSrcweir 					aResId.SetRT( RSC_STRING );
217*cdf0e10cSrcweir 					if ( pResMgr->IsAvailable( aResId ) )
218*cdf0e10cSrcweir 					{
219*cdf0e10cSrcweir 						aReturnValue = String( aResId );
220*cdf0e10cSrcweir 					}
221*cdf0e10cSrcweir 					delete pResMgr;
222*cdf0e10cSrcweir 				}
223*cdf0e10cSrcweir 			}
224*cdf0e10cSrcweir 		}
225*cdf0e10cSrcweir 	}
226*cdf0e10cSrcweir 	return aReturnValue;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir // ------------------------------------------------------------------------
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir void SgaObject::SetTitle( const String& rTitle )
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir 	aTitle = rTitle;
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir // ------------------------------------------------------------------------
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOut, const SgaObject& rObj )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	rObj.WriteData( rOut, String() );
241*cdf0e10cSrcweir 	return rOut;
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir // ------------------------------------------------------------------------
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIn, SgaObject& rObj )
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir 	sal_uInt16 nReadVersion;
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	rObj.ReadData( rIn, nReadVersion );
251*cdf0e10cSrcweir 	rObj.bIsValid = ( rIn.GetError() == ERRCODE_NONE );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 	return rIn;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir // ----------------
257*cdf0e10cSrcweir // - SgaObjectBmp -
258*cdf0e10cSrcweir // ----------------
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp()
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir // ------------------------------------------------------------------------
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp( const INetURLObject& rURL )
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir 	Graphic aGraphic;
269*cdf0e10cSrcweir 	String	aFilter;
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 	if ( SGA_IMPORT_NONE != GalleryGraphicImport( rURL, aGraphic, aFilter ) )
272*cdf0e10cSrcweir 		Init( aGraphic, rURL );
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir // ------------------------------------------------------------------------
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp( const Graphic& rGraphic, const INetURLObject& rURL, const String& )
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir 	if( FileExists( rURL ) )
280*cdf0e10cSrcweir 		Init( rGraphic, rURL );
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir // ------------------------------------------------------------------------
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir void SgaObjectBmp::Init( const Graphic& rGraphic, const INetURLObject& rURL )
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir 	aURL = rURL;
288*cdf0e10cSrcweir 	bIsValid = CreateThumb( rGraphic );
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir // ------------------------------------------------------------------------
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir void SgaObjectBmp::WriteData( SvStream& rOut, const String& rDestDir ) const
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir 	String	aDummyStr;
296*cdf0e10cSrcweir 	char	aDummy[ 10 ];
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	// Version setzen
299*cdf0e10cSrcweir 	SgaObject::WriteData( rOut, rDestDir );
300*cdf0e10cSrcweir 	rOut.Write( aDummy, 10 );
301*cdf0e10cSrcweir 	rOut << ByteString( aDummyStr, RTL_TEXTENCODING_UTF8 ) << ByteString( aTitle, RTL_TEXTENCODING_UTF8 );
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir // ------------------------------------------------------------------------
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir void SgaObjectBmp::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir 	ByteString aTmpStr;
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 	SgaObject::ReadData( rIn, rReadVersion );
311*cdf0e10cSrcweir 	rIn.SeekRel( 10 ); // 16, 16, 32, 16
312*cdf0e10cSrcweir 	rIn >> aTmpStr; // dummy
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	if( rReadVersion >= 5 )
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
317*cdf0e10cSrcweir 	}
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir // ------------------
321*cdf0e10cSrcweir // - SgaObjectSound -
322*cdf0e10cSrcweir // ------------------
323*cdf0e10cSrcweir DBG_NAME(SgaObjectSound)
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir SgaObjectSound::SgaObjectSound() :
326*cdf0e10cSrcweir 	eSoundType( SOUND_STANDARD )
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     DBG_CTOR(SgaObjectSound,NULL);
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir // ------------------------------------------------------------------------
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir SgaObjectSound::SgaObjectSound( const INetURLObject& rURL ) :
335*cdf0e10cSrcweir 	eSoundType( SOUND_STANDARD )
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir     DBG_CTOR(SgaObjectSound,NULL);
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	if( FileExists( rURL ) )
340*cdf0e10cSrcweir 	{
341*cdf0e10cSrcweir 		aURL = rURL;
342*cdf0e10cSrcweir 		aThumbBmp = Bitmap( Size( 1, 1 ), 1 );
343*cdf0e10cSrcweir 		bIsValid = sal_True;
344*cdf0e10cSrcweir 	}
345*cdf0e10cSrcweir 	else
346*cdf0e10cSrcweir 		bIsValid = sal_False;
347*cdf0e10cSrcweir }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir // ------------------------------------------------------------------------
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir SgaObjectSound::~SgaObjectSound()
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     DBG_DTOR(SgaObjectSound,NULL);
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir // ------------------------------------------------------------------------
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir Bitmap SgaObjectSound::GetThumbBmp() const
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir 	sal_uInt16 nId;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 	switch( eSoundType )
364*cdf0e10cSrcweir 	{
365*cdf0e10cSrcweir 		case( SOUND_COMPUTER ): nId = RID_SVXBMP_GALLERY_SOUND_1; break;
366*cdf0e10cSrcweir 		case( SOUND_MISC ): nId = RID_SVXBMP_GALLERY_SOUND_2; break;
367*cdf0e10cSrcweir 		case( SOUND_MUSIC ): nId = RID_SVXBMP_GALLERY_SOUND_3; break;
368*cdf0e10cSrcweir 		case( SOUND_NATURE ): nId = RID_SVXBMP_GALLERY_SOUND_4; break;
369*cdf0e10cSrcweir 		case( SOUND_SPEECH ): nId = RID_SVXBMP_GALLERY_SOUND_5; break;
370*cdf0e10cSrcweir 		case( SOUND_TECHNIC ): nId = RID_SVXBMP_GALLERY_SOUND_6; break;
371*cdf0e10cSrcweir 		case( SOUND_ANIMAL ): nId = RID_SVXBMP_GALLERY_SOUND_7; break;
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 		// standard
374*cdf0e10cSrcweir 		default:
375*cdf0e10cSrcweir 			 nId = RID_SVXBMP_GALLERY_MEDIA;
376*cdf0e10cSrcweir 		break;
377*cdf0e10cSrcweir 	}
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	const BitmapEx  aBmpEx( GAL_RESID( nId ) );
380*cdf0e10cSrcweir 	const Color     aTransColor( COL_WHITE );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	return aBmpEx.GetBitmap( &aTransColor );
383*cdf0e10cSrcweir }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir // ------------------------------------------------------------------------
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir void SgaObjectSound::WriteData( SvStream& rOut, const String& rDestDir ) const
388*cdf0e10cSrcweir {
389*cdf0e10cSrcweir 	SgaObject::WriteData( rOut, rDestDir );
390*cdf0e10cSrcweir 	rOut << (sal_uInt16) eSoundType << ByteString( aTitle, RTL_TEXTENCODING_UTF8 );
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir // ------------------------------------------------------------------------
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir void SgaObjectSound::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir 	SgaObject::ReadData( rIn, rReadVersion );
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	if( rReadVersion >= 5 )
400*cdf0e10cSrcweir 	{
401*cdf0e10cSrcweir 		ByteString	aTmpStr;
402*cdf0e10cSrcweir 		sal_uInt16		nTmp16;
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 		rIn >> nTmp16; eSoundType = (GalSoundType) nTmp16;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 		if( rReadVersion >= 6 )
407*cdf0e10cSrcweir 		{
408*cdf0e10cSrcweir 			rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
409*cdf0e10cSrcweir 		}
410*cdf0e10cSrcweir 	}
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir // -----------------
414*cdf0e10cSrcweir // - SgaObjectAnim -
415*cdf0e10cSrcweir // -----------------
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir SgaObjectAnim::SgaObjectAnim()
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir // ------------------------------------------------------------------------
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir SgaObjectAnim::SgaObjectAnim( const Graphic& rGraphic,
424*cdf0e10cSrcweir 							  const INetURLObject& rURL,
425*cdf0e10cSrcweir 							  const String& )
426*cdf0e10cSrcweir {
427*cdf0e10cSrcweir 	aURL = rURL;
428*cdf0e10cSrcweir 	bIsValid = CreateThumb( rGraphic );
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir // -----------------
432*cdf0e10cSrcweir // - SgaObjectINet -
433*cdf0e10cSrcweir // -----------------
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir SgaObjectINet::SgaObjectINet()
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir // ------------------------------------------------------------------------
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir SgaObjectINet::SgaObjectINet( const Graphic& rGraphic, const INetURLObject& rURL, const String& rFormatName ) :
442*cdf0e10cSrcweir 			SgaObjectAnim	( rGraphic, rURL, rFormatName )
443*cdf0e10cSrcweir {
444*cdf0e10cSrcweir }
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir // -------------------
447*cdf0e10cSrcweir // - SgaObjectSvDraw -
448*cdf0e10cSrcweir // -------------------
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw()
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir // ------------------------------------------------------------------------
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw( const FmFormModel& rModel, const INetURLObject& rURL )
457*cdf0e10cSrcweir {
458*cdf0e10cSrcweir 	aURL = rURL;
459*cdf0e10cSrcweir 	bIsValid = CreateThumb( rModel );
460*cdf0e10cSrcweir }
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir // ------------------------------------------------------------------------
463*cdf0e10cSrcweir DBG_NAME(SvxGalleryDrawModel)
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir SvxGalleryDrawModel::SvxGalleryDrawModel()
466*cdf0e10cSrcweir : mpFormModel( 0 )
467*cdf0e10cSrcweir {
468*cdf0e10cSrcweir     DBG_CTOR(SvxGalleryDrawModel,NULL);
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir     const String sFactoryURL(RTL_CONSTASCII_USTRINGPARAM("sdraw"));
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir     mxDoc = SfxObjectShell::CreateObjectByFactoryName( sFactoryURL );
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     if( mxDoc.Is() )
475*cdf0e10cSrcweir     {
476*cdf0e10cSrcweir         mxDoc->DoInitNew(0);
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir         uno::Reference< lang::XUnoTunnel > xTunnel( mxDoc->GetModel(), uno::UNO_QUERY );
479*cdf0e10cSrcweir         if( xTunnel.is() )
480*cdf0e10cSrcweir         {
481*cdf0e10cSrcweir             mpFormModel = dynamic_cast< FmFormModel* >(
482*cdf0e10cSrcweir                 reinterpret_cast<SdrModel*>(xTunnel->getSomething(SdrModel::getUnoTunnelImplementationId())));
483*cdf0e10cSrcweir             if( mpFormModel )
484*cdf0e10cSrcweir             {
485*cdf0e10cSrcweir                 mpFormModel->InsertPage( mpFormModel->AllocPage( false ) );
486*cdf0e10cSrcweir             }
487*cdf0e10cSrcweir         }
488*cdf0e10cSrcweir     }
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir // ------------------------------------------------------------------------
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir SvxGalleryDrawModel::~SvxGalleryDrawModel()
494*cdf0e10cSrcweir {
495*cdf0e10cSrcweir     if( mxDoc.Is() )
496*cdf0e10cSrcweir         mxDoc->DoClose();
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir     DBG_DTOR(SvxGalleryDrawModel,NULL);
499*cdf0e10cSrcweir }
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir // ------------------------------------------------------------------------
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw( SvStream& rIStm, const INetURLObject& rURL )
504*cdf0e10cSrcweir {
505*cdf0e10cSrcweir     SvxGalleryDrawModel aModel;
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir     if( aModel.GetModel() )
508*cdf0e10cSrcweir     {
509*cdf0e10cSrcweir         if( GallerySvDrawImport( rIStm, *aModel.GetModel()  ) )
510*cdf0e10cSrcweir         {
511*cdf0e10cSrcweir             aURL = rURL;
512*cdf0e10cSrcweir             bIsValid = CreateThumb( *aModel.GetModel()  );
513*cdf0e10cSrcweir         }
514*cdf0e10cSrcweir     }
515*cdf0e10cSrcweir }
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir // ------------------------------------------------------------------------
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir sal_Bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel )
520*cdf0e10cSrcweir {
521*cdf0e10cSrcweir 	Graphic		aGraphic;
522*cdf0e10cSrcweir 	ImageMap	aImageMap;
523*cdf0e10cSrcweir 	sal_Bool		bRet = sal_False;
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir 	if ( CreateIMapGraphic( rModel, aGraphic, aImageMap ) )
526*cdf0e10cSrcweir 		bRet = SgaObject::CreateThumb( aGraphic );
527*cdf0e10cSrcweir 	else
528*cdf0e10cSrcweir 	{
529*cdf0e10cSrcweir         VirtualDevice aVDev;
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir         aVDev.SetOutputSizePixel( Size( S_THUMB*2, S_THUMB*2 ) );
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir         bRet = DrawCentered( &aVDev, rModel );
534*cdf0e10cSrcweir         if( bRet )
535*cdf0e10cSrcweir         {
536*cdf0e10cSrcweir             aThumbBmp = aVDev.GetBitmap( Point(), aVDev.GetOutputSizePixel() );
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 			Size aMS( 2, 2 );
539*cdf0e10cSrcweir 			BmpFilterParam aParam( aMS );
540*cdf0e10cSrcweir 			aThumbBmp.Filter( BMP_FILTER_MOSAIC, &aParam );
541*cdf0e10cSrcweir 			aThumbBmp.Scale( Size( S_THUMB, S_THUMB ) );
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir 	        aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
544*cdf0e10cSrcweir         }
545*cdf0e10cSrcweir 	}
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 	return bRet;
548*cdf0e10cSrcweir }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir // ------------------------------------------------------------------------
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir sal_Bool SgaObjectSvDraw::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel )
553*cdf0e10cSrcweir {
554*cdf0e10cSrcweir     const FmFormPage*   pPage = static_cast< const FmFormPage* >( rModel.GetPage( 0 ) );
555*cdf0e10cSrcweir     sal_Bool                bRet = sal_False;
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     if( pOut && pPage )
558*cdf0e10cSrcweir     {
559*cdf0e10cSrcweir         const Rectangle aObjRect( pPage->GetAllObjBoundRect() );
560*cdf0e10cSrcweir         const Size      aOutSizePix( pOut->GetOutputSizePixel() );
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir         if( aObjRect.GetWidth() && aObjRect.GetHeight() && aOutSizePix.Width() > 2 && aOutSizePix.Height() > 2 )
563*cdf0e10cSrcweir         {
564*cdf0e10cSrcweir             FmFormView      aView( const_cast< FmFormModel* >( &rModel ), pOut );
565*cdf0e10cSrcweir             MapMode	        aMap( rModel.GetScaleUnit() );
566*cdf0e10cSrcweir             Rectangle       aDrawRectPix( Point( 1, 1 ), Size( aOutSizePix.Width() - 2, aOutSizePix.Height() - 2 ) );
567*cdf0e10cSrcweir             const double    fFactor  = (double) aObjRect.GetWidth() / aObjRect.GetHeight();
568*cdf0e10cSrcweir             Fraction        aFrac( FRound( fFactor < 1. ? aDrawRectPix.GetWidth() * fFactor : aDrawRectPix.GetWidth() ),
569*cdf0e10cSrcweir                                    pOut->LogicToPixel( aObjRect.GetSize(), aMap ).Width() );
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir             aMap.SetScaleX( aFrac );
572*cdf0e10cSrcweir             aMap.SetScaleY( aFrac );
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir             const Size aDrawSize( pOut->PixelToLogic( aDrawRectPix.GetSize(), aMap ) );
575*cdf0e10cSrcweir             Point aOrigin( pOut->PixelToLogic( aDrawRectPix.TopLeft(), aMap ) );
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir             aOrigin.X() += ( ( aDrawSize.Width() - aObjRect.GetWidth() ) >> 1 ) - aObjRect.Left();
578*cdf0e10cSrcweir             aOrigin.Y() += ( ( aDrawSize.Height() - aObjRect.GetHeight() ) >> 1 ) - aObjRect.Top();
579*cdf0e10cSrcweir             aMap.SetOrigin( aOrigin );
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir             aView.SetPageVisible( sal_False );
582*cdf0e10cSrcweir             aView.SetBordVisible( sal_False );
583*cdf0e10cSrcweir             aView.SetGridVisible( sal_False );
584*cdf0e10cSrcweir             aView.SetHlplVisible( sal_False );
585*cdf0e10cSrcweir             aView.SetGlueVisible( sal_False );
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir             pOut->Push();
588*cdf0e10cSrcweir             pOut->SetMapMode( aMap );
589*cdf0e10cSrcweir             aView.ShowSdrPage( const_cast< FmFormPage* >( pPage ));
590*cdf0e10cSrcweir             aView.CompleteRedraw( pOut, Rectangle( pOut->PixelToLogic( Point() ), pOut->GetOutputSize() ) );
591*cdf0e10cSrcweir             pOut->Pop();
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir             bRet = sal_True;
594*cdf0e10cSrcweir         }
595*cdf0e10cSrcweir     }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir     return bRet;
598*cdf0e10cSrcweir }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir // ------------------------------------------------------------------------
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir void SgaObjectSvDraw::WriteData( SvStream& rOut, const String& rDestDir ) const
603*cdf0e10cSrcweir {
604*cdf0e10cSrcweir 	SgaObject::WriteData( rOut, rDestDir );
605*cdf0e10cSrcweir 	rOut << ByteString( aTitle, RTL_TEXTENCODING_UTF8 );
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir // ------------------------------------------------------------------------
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir void SgaObjectSvDraw::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
611*cdf0e10cSrcweir {
612*cdf0e10cSrcweir 	SgaObject::ReadData( rIn, rReadVersion );
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir 	if( rReadVersion >= 5 )
615*cdf0e10cSrcweir 	{
616*cdf0e10cSrcweir 		ByteString aTmpStr;
617*cdf0e10cSrcweir 		rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
618*cdf0e10cSrcweir 	}
619*cdf0e10cSrcweir }
620