xref: /trunk/main/svx/source/gallery2/galobj.cxx (revision 21b36550)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
30cdf0e10cSrcweir #include <sfx2/objsh.hxx>
31cdf0e10cSrcweir #include <sfx2/docfac.hxx>
32cdf0e10cSrcweir #include <comphelper/classids.hxx>
33cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
34cdf0e10cSrcweir #include <tools/rcid.h>
35cdf0e10cSrcweir #include <tools/vcompat.hxx>
36cdf0e10cSrcweir #include <vcl/virdev.hxx>
37cdf0e10cSrcweir #include <svl/itempool.hxx>
38cdf0e10cSrcweir #include <svx/fmmodel.hxx>
39cdf0e10cSrcweir #include <svx/fmview.hxx>
40cdf0e10cSrcweir #include <svx/fmpage.hxx>
41cdf0e10cSrcweir #include "gallery.hrc"
42cdf0e10cSrcweir #include "svx/galmisc.hxx"
43cdf0e10cSrcweir #include "galobj.hxx"
44cdf0e10cSrcweir #include <vcl/salbtype.hxx>		// FRound
45cdf0e10cSrcweir #include <vcl/svapp.hxx>
4645fd3b9aSArmin Le Grand #include <vcl/dibtools.hxx>
47cdf0e10cSrcweir #include "gallerydrawmodel.hxx"
48cdf0e10cSrcweir 
49cdf0e10cSrcweir using namespace ::com::sun::star;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // -------------
52cdf0e10cSrcweir // - SgaObject -
53cdf0e10cSrcweir // -------------
54cdf0e10cSrcweir 
SgaObject()55*21b36550SArmin Le Grand SgaObject::SgaObject()
56*21b36550SArmin Le Grand :   bIsValid    ( sal_False ),
57*21b36550SArmin Le Grand     bIsThumbBmp	( sal_True )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
createPreviewBitmapEx(const Size & rSizePixel) const61*21b36550SArmin Le Grand BitmapEx SgaObject::createPreviewBitmapEx(const Size& rSizePixel) const
62*21b36550SArmin Le Grand {
63*21b36550SArmin Le Grand     BitmapEx aRetval;
64*21b36550SArmin Le Grand 
65*21b36550SArmin Le Grand     if(rSizePixel.Width() && rSizePixel.Height())
66*21b36550SArmin Le Grand     {
67*21b36550SArmin Le Grand         if(SGA_OBJ_SOUND == GetObjKind())
68*21b36550SArmin Le Grand         {
69*21b36550SArmin Le Grand             aRetval = GAL_RESID(RID_SVXBMP_GALLERY_MEDIA);
70*21b36550SArmin Le Grand         }
71*21b36550SArmin Le Grand         else if(IsThumbBitmap())
72*21b36550SArmin Le Grand         {
73*21b36550SArmin Le Grand             aRetval = GetThumbBmp();
74*21b36550SArmin Le Grand         }
75*21b36550SArmin Le Grand         else
76*21b36550SArmin Le Grand         {
77*21b36550SArmin Le Grand             const Graphic aGraphic(GetThumbMtf());
78*21b36550SArmin Le Grand 
79*21b36550SArmin Le Grand             aRetval = aGraphic.GetBitmapEx();
80*21b36550SArmin Le Grand         }
81*21b36550SArmin Le Grand 
82*21b36550SArmin Le Grand         if(!aRetval.IsEmpty())
83*21b36550SArmin Le Grand         {
84*21b36550SArmin Le Grand             const Size aCurrentSizePixel(aRetval.GetSizePixel());
85*21b36550SArmin Le Grand             const double fScaleX((double)rSizePixel.Width() / (double)aCurrentSizePixel.Width());
86*21b36550SArmin Le Grand             const double fScaleY((double)rSizePixel.Height() / (double)aCurrentSizePixel.Height());
87*21b36550SArmin Le Grand             const double fScale(std::min(fScaleX, fScaleY));
88*21b36550SArmin Le Grand 
89*21b36550SArmin Le Grand             // only scale when need to decrease, no need to make bigger as original. Also
90*21b36550SArmin Le Grand             // prevent scaling close to 1.0 which is not needed for pixel graphics
91*21b36550SArmin Le Grand             if(fScale < 1.0 && fabs(1.0 - fScale) > 0.005)
92*21b36550SArmin Le Grand             {
93*21b36550SArmin Le Grand                 static sal_uInt32 nScaleFlag = BMP_SCALE_FASTESTINTERPOLATE;
94*21b36550SArmin Le Grand 
95*21b36550SArmin Le Grand                 aRetval.Scale(fScale, fScale, nScaleFlag);
96*21b36550SArmin Le Grand             }
97*21b36550SArmin Le Grand         }
98*21b36550SArmin Le Grand     }
99*21b36550SArmin Le Grand 
100*21b36550SArmin Le Grand     return aRetval;
101*21b36550SArmin Le Grand }
102*21b36550SArmin Le Grand 
103cdf0e10cSrcweir // ------------------------------------------------------------------------
104cdf0e10cSrcweir 
CreateThumb(const Graphic & rGraphic)105cdf0e10cSrcweir sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	if( rGraphic.GetType() == GRAPHIC_BITMAP )
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		BitmapEx    aBmpEx( rGraphic.GetBitmapEx() );
112cdf0e10cSrcweir 		Size        aBmpSize( aBmpEx.GetSizePixel() );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 		if( aBmpSize.Width() && aBmpSize.Height() )
115cdf0e10cSrcweir 		{
116cdf0e10cSrcweir 			const Color	aWhite( COL_WHITE );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 		    if( aBmpEx.GetPrefMapMode().GetMapUnit() != MAP_PIXEL &&
119cdf0e10cSrcweir 		        aBmpEx.GetPrefSize().Width() > 0 &&
120cdf0e10cSrcweir 		        aBmpEx.GetPrefSize().Height() > 0 )
121cdf0e10cSrcweir 		    {
122cdf0e10cSrcweir 		        Size aLogSize( OutputDevice::LogicToLogic( aBmpEx.GetPrefSize(), aBmpEx.GetPrefMapMode(), MAP_100TH_MM ) );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 		        if( aLogSize.Width() > 0 && aLogSize.Height() > 0 )
125cdf0e10cSrcweir 		        {
126cdf0e10cSrcweir 		            double  fFactorLog = static_cast< double >( aLogSize.Width() ) / aLogSize.Height();
127cdf0e10cSrcweir 		            double  fFactorPix = static_cast< double >( aBmpSize.Width() ) / aBmpSize.Height();
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		            if( fFactorPix > fFactorLog )
130cdf0e10cSrcweir 		                aBmpSize.Width() = FRound( aBmpSize.Height() * fFactorLog );
131cdf0e10cSrcweir 		            else
132cdf0e10cSrcweir 		                aBmpSize.Height() = FRound( aBmpSize.Width() / fFactorLog );
133cdf0e10cSrcweir 
13454628ca4SArmin Le Grand 		            aBmpEx.SetSizePixel( aBmpSize, BMP_SCALE_BESTQUALITY );
135cdf0e10cSrcweir 		        }
136cdf0e10cSrcweir 		    }
137cdf0e10cSrcweir 
1386dd94783SArmin Le Grand             // take over BitmapEx
1396dd94783SArmin Le Grand 			aThumbBmp = aBmpEx;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 			if( ( aBmpSize.Width() <= S_THUMB ) && ( aBmpSize.Height() <= S_THUMB ) )
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
144cdf0e10cSrcweir 				bRet = sal_True;
145cdf0e10cSrcweir 			}
146cdf0e10cSrcweir 			else
147cdf0e10cSrcweir 			{
148cdf0e10cSrcweir 				const float	fFactor  = (float) aBmpSize.Width() / aBmpSize.Height();
149cdf0e10cSrcweir 				const Size	aNewSize( Max( (long) (fFactor < 1. ? S_THUMB * fFactor : S_THUMB), 8L ),
150cdf0e10cSrcweir 									  Max( (long) (fFactor < 1. ? S_THUMB : S_THUMB / fFactor), 8L ) );
151cdf0e10cSrcweir 
15254628ca4SArmin Le Grand 				if(aThumbBmp.Scale(
15354628ca4SArmin Le Grand                     (double) aNewSize.Width() / aBmpSize.Width(),
15454628ca4SArmin Le Grand                     (double) aNewSize.Height() / aBmpSize.Height(),
15554628ca4SArmin Le Grand                     BMP_SCALE_BESTQUALITY ) )
156cdf0e10cSrcweir 				{
157cdf0e10cSrcweir 					aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
158cdf0e10cSrcweir 					bRet = sal_True;
159cdf0e10cSrcweir 				}
160cdf0e10cSrcweir 			}
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir 	else if( rGraphic.GetType() == GRAPHIC_GDIMETAFILE )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		const Size aPrefSize( rGraphic.GetPrefSize() );
166cdf0e10cSrcweir 		const double fFactor  = (double)aPrefSize.Width() / (double)aPrefSize.Height();
167cdf0e10cSrcweir         Size aSize( S_THUMB, S_THUMB );
168cdf0e10cSrcweir 		if ( fFactor < 1.0 )
169cdf0e10cSrcweir 			aSize.Width() = (sal_Int32)( S_THUMB * fFactor );
170cdf0e10cSrcweir 		else
171cdf0e10cSrcweir 			aSize.Height() = (sal_Int32)( S_THUMB / fFactor );
172cdf0e10cSrcweir 
17354628ca4SArmin Le Grand         const GraphicConversionParameters aParameters(aSize, false, true, true, true);
1746dd94783SArmin Le Grand         aThumbBmp = rGraphic.GetBitmapEx(aParameters);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		if( !aThumbBmp.IsEmpty() )
177cdf0e10cSrcweir 		{
178cdf0e10cSrcweir 			aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
179cdf0e10cSrcweir 			bRet = sal_True;
180cdf0e10cSrcweir 		}
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	return bRet;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir // ------------------------------------------------------------------------
187cdf0e10cSrcweir 
WriteData(SvStream & rOut,const String & rDestDir) const188cdf0e10cSrcweir void SgaObject::WriteData( SvStream& rOut, const String& rDestDir ) const
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	static const sal_uInt32 nInventor = COMPAT_FORMAT( 'S', 'G', 'A', '3' );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	rOut << nInventor << (sal_uInt16) 0x0004 << GetVersion() << (sal_uInt16) GetObjKind();
193cdf0e10cSrcweir 	rOut << bIsThumbBmp;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	if( bIsThumbBmp )
196cdf0e10cSrcweir 	{
197cdf0e10cSrcweir 		const sal_uInt16	nOldCompressMode = rOut.GetCompressMode();
198cdf0e10cSrcweir 		const sal_uIntPtr		nOldVersion = rOut.GetVersion();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 		rOut.SetCompressMode( COMPRESSMODE_ZBITMAP );
201cdf0e10cSrcweir 		rOut.SetVersion( SOFFICE_FILEFORMAT_50 );
202cdf0e10cSrcweir 
20345fd3b9aSArmin Le Grand         WriteDIBBitmapEx(aThumbBmp, rOut);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 		rOut.SetVersion( nOldVersion );
206cdf0e10cSrcweir 		rOut.SetCompressMode( nOldCompressMode );
207cdf0e10cSrcweir 	}
208cdf0e10cSrcweir 	else
209cdf0e10cSrcweir 		rOut << aThumbMtf;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	String aURLWithoutDestDir = String(aURL.GetMainURL( INetURLObject::NO_DECODE ));
212cdf0e10cSrcweir 	aURLWithoutDestDir.SearchAndReplace(rDestDir, String());
213cdf0e10cSrcweir 	rOut << ByteString( aURLWithoutDestDir, RTL_TEXTENCODING_UTF8 );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // ------------------------------------------------------------------------
217cdf0e10cSrcweir 
ReadData(SvStream & rIn,sal_uInt16 & rReadVersion)218cdf0e10cSrcweir void SgaObject::ReadData(SvStream& rIn, sal_uInt16& rReadVersion )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	ByteString	aTmpStr;
221cdf0e10cSrcweir 	sal_uInt32		nTmp32;
222cdf0e10cSrcweir 	sal_uInt16		nTmp16;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	rIn >> nTmp32 >> nTmp16 >> rReadVersion >> nTmp16 >> bIsThumbBmp;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	if( bIsThumbBmp )
22745fd3b9aSArmin Le Grand     {
22845fd3b9aSArmin Le Grand         ReadDIBBitmapEx(aThumbBmp, rIn);
22945fd3b9aSArmin Le Grand     }
230cdf0e10cSrcweir 	else
23145fd3b9aSArmin Le Grand     {
232cdf0e10cSrcweir 		rIn >> aThumbMtf;
23345fd3b9aSArmin Le Grand     }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	rIn >> aTmpStr; aURL = INetURLObject( String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 ) );
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir // ------------------------------------------------------------------------
239cdf0e10cSrcweir 
GetTitle() const240cdf0e10cSrcweir const String SgaObject::GetTitle() const
241cdf0e10cSrcweir {
242cdf0e10cSrcweir 	String aReturnValue( aTitle );
243cdf0e10cSrcweir 	if ( !getenv( "GALLERY_SHOW_PRIVATE_TITLE" ) )
244cdf0e10cSrcweir 	{
245cdf0e10cSrcweir 		if ( aReturnValue.GetTokenCount( ':' ) == 3 )
246cdf0e10cSrcweir 		{
247cdf0e10cSrcweir 			String		aPrivateInd  ( aReturnValue.GetToken( 0, ':' ) );
248cdf0e10cSrcweir 			String		aResourceName( aReturnValue.GetToken( 1, ':' ) );
249cdf0e10cSrcweir 			sal_Int32	nResId		 ( aReturnValue.GetToken( 2, ':' ).ToInt32() );
250cdf0e10cSrcweir 			if ( aReturnValue.GetToken( 0, ':' ).EqualsAscii( "private" ) &&
251cdf0e10cSrcweir 				aResourceName.Len() && ( nResId > 0 ) && ( nResId < 0x10000 ) )
252cdf0e10cSrcweir 			{
253cdf0e10cSrcweir 				ByteString aMgrName( aResourceName, RTL_TEXTENCODING_UTF8 );
254cdf0e10cSrcweir 				ResMgr* pResMgr = ResMgr::CreateResMgr( aMgrName.GetBuffer(),
255cdf0e10cSrcweir 							Application::GetSettings().GetUILocale() );
256cdf0e10cSrcweir 				if ( pResMgr )
257cdf0e10cSrcweir 				{
258cdf0e10cSrcweir 					ResId aResId( (sal_uInt16)nResId, *pResMgr );
259cdf0e10cSrcweir 					aResId.SetRT( RSC_STRING );
260cdf0e10cSrcweir 					if ( pResMgr->IsAvailable( aResId ) )
261cdf0e10cSrcweir 					{
262cdf0e10cSrcweir 						aReturnValue = String( aResId );
263cdf0e10cSrcweir 					}
264cdf0e10cSrcweir 					delete pResMgr;
265cdf0e10cSrcweir 				}
266cdf0e10cSrcweir 			}
267cdf0e10cSrcweir 		}
268cdf0e10cSrcweir 	}
269cdf0e10cSrcweir 	return aReturnValue;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir // ------------------------------------------------------------------------
273cdf0e10cSrcweir 
SetTitle(const String & rTitle)274cdf0e10cSrcweir void SgaObject::SetTitle( const String& rTitle )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir 	aTitle = rTitle;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir // ------------------------------------------------------------------------
280cdf0e10cSrcweir 
operator <<(SvStream & rOut,const SgaObject & rObj)281cdf0e10cSrcweir SvStream& operator<<( SvStream& rOut, const SgaObject& rObj )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir 	rObj.WriteData( rOut, String() );
284cdf0e10cSrcweir 	return rOut;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir // ------------------------------------------------------------------------
288cdf0e10cSrcweir 
operator >>(SvStream & rIn,SgaObject & rObj)289cdf0e10cSrcweir SvStream& operator>>( SvStream& rIn, SgaObject& rObj )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir 	sal_uInt16 nReadVersion;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 	rObj.ReadData( rIn, nReadVersion );
294cdf0e10cSrcweir 	rObj.bIsValid = ( rIn.GetError() == ERRCODE_NONE );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	return rIn;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir // ----------------
300cdf0e10cSrcweir // - SgaObjectBmp -
301cdf0e10cSrcweir // ----------------
302cdf0e10cSrcweir 
SgaObjectBmp()303cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp()
304cdf0e10cSrcweir {
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir // ------------------------------------------------------------------------
308cdf0e10cSrcweir 
SgaObjectBmp(const INetURLObject & rURL)309cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp( const INetURLObject& rURL )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir 	Graphic aGraphic;
312cdf0e10cSrcweir 	String	aFilter;
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 	if ( SGA_IMPORT_NONE != GalleryGraphicImport( rURL, aGraphic, aFilter ) )
315cdf0e10cSrcweir 		Init( aGraphic, rURL );
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir // ------------------------------------------------------------------------
319cdf0e10cSrcweir 
SgaObjectBmp(const Graphic & rGraphic,const INetURLObject & rURL,const String &)320cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp( const Graphic& rGraphic, const INetURLObject& rURL, const String& )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir 	if( FileExists( rURL ) )
323cdf0e10cSrcweir 		Init( rGraphic, rURL );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir // ------------------------------------------------------------------------
327cdf0e10cSrcweir 
Init(const Graphic & rGraphic,const INetURLObject & rURL)328cdf0e10cSrcweir void SgaObjectBmp::Init( const Graphic& rGraphic, const INetURLObject& rURL )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 	aURL = rURL;
331cdf0e10cSrcweir 	bIsValid = CreateThumb( rGraphic );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir // ------------------------------------------------------------------------
335cdf0e10cSrcweir 
WriteData(SvStream & rOut,const String & rDestDir) const336cdf0e10cSrcweir void SgaObjectBmp::WriteData( SvStream& rOut, const String& rDestDir ) const
337cdf0e10cSrcweir {
338cdf0e10cSrcweir 	String	aDummyStr;
339cdf0e10cSrcweir 	char	aDummy[ 10 ];
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	// Version setzen
342cdf0e10cSrcweir 	SgaObject::WriteData( rOut, rDestDir );
343cdf0e10cSrcweir 	rOut.Write( aDummy, 10 );
344cdf0e10cSrcweir 	rOut << ByteString( aDummyStr, RTL_TEXTENCODING_UTF8 ) << ByteString( aTitle, RTL_TEXTENCODING_UTF8 );
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir // ------------------------------------------------------------------------
348cdf0e10cSrcweir 
ReadData(SvStream & rIn,sal_uInt16 & rReadVersion)349cdf0e10cSrcweir void SgaObjectBmp::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	ByteString aTmpStr;
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 	SgaObject::ReadData( rIn, rReadVersion );
354cdf0e10cSrcweir 	rIn.SeekRel( 10 ); // 16, 16, 32, 16
355cdf0e10cSrcweir 	rIn >> aTmpStr; // dummy
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	if( rReadVersion >= 5 )
358cdf0e10cSrcweir 	{
359cdf0e10cSrcweir 		rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir // ------------------
364cdf0e10cSrcweir // - SgaObjectSound -
365cdf0e10cSrcweir // ------------------
DBG_NAME(SgaObjectSound)366cdf0e10cSrcweir DBG_NAME(SgaObjectSound)
367cdf0e10cSrcweir 
368cdf0e10cSrcweir SgaObjectSound::SgaObjectSound() :
369cdf0e10cSrcweir 	eSoundType( SOUND_STANDARD )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     DBG_CTOR(SgaObjectSound,NULL);
372cdf0e10cSrcweir 
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir // ------------------------------------------------------------------------
376cdf0e10cSrcweir 
SgaObjectSound(const INetURLObject & rURL)377cdf0e10cSrcweir SgaObjectSound::SgaObjectSound( const INetURLObject& rURL ) :
378cdf0e10cSrcweir 	eSoundType( SOUND_STANDARD )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir     DBG_CTOR(SgaObjectSound,NULL);
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 	if( FileExists( rURL ) )
383cdf0e10cSrcweir 	{
384cdf0e10cSrcweir 		aURL = rURL;
385cdf0e10cSrcweir 		aThumbBmp = Bitmap( Size( 1, 1 ), 1 );
386cdf0e10cSrcweir 		bIsValid = sal_True;
387cdf0e10cSrcweir 	}
388cdf0e10cSrcweir 	else
389cdf0e10cSrcweir 		bIsValid = sal_False;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir // ------------------------------------------------------------------------
393cdf0e10cSrcweir 
~SgaObjectSound()394cdf0e10cSrcweir SgaObjectSound::~SgaObjectSound()
395cdf0e10cSrcweir {
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     DBG_DTOR(SgaObjectSound,NULL);
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir // ------------------------------------------------------------------------
401cdf0e10cSrcweir 
GetThumbBmp() const4026dd94783SArmin Le Grand BitmapEx SgaObjectSound::GetThumbBmp() const
403cdf0e10cSrcweir {
404cdf0e10cSrcweir 	sal_uInt16 nId;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 	switch( eSoundType )
407cdf0e10cSrcweir 	{
408cdf0e10cSrcweir 		case( SOUND_COMPUTER ): nId = RID_SVXBMP_GALLERY_SOUND_1; break;
409cdf0e10cSrcweir 		case( SOUND_MISC ): nId = RID_SVXBMP_GALLERY_SOUND_2; break;
410cdf0e10cSrcweir 		case( SOUND_MUSIC ): nId = RID_SVXBMP_GALLERY_SOUND_3; break;
411cdf0e10cSrcweir 		case( SOUND_NATURE ): nId = RID_SVXBMP_GALLERY_SOUND_4; break;
412cdf0e10cSrcweir 		case( SOUND_SPEECH ): nId = RID_SVXBMP_GALLERY_SOUND_5; break;
413cdf0e10cSrcweir 		case( SOUND_TECHNIC ): nId = RID_SVXBMP_GALLERY_SOUND_6; break;
414cdf0e10cSrcweir 		case( SOUND_ANIMAL ): nId = RID_SVXBMP_GALLERY_SOUND_7; break;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 		// standard
417cdf0e10cSrcweir 		default:
418cdf0e10cSrcweir 			 nId = RID_SVXBMP_GALLERY_MEDIA;
419cdf0e10cSrcweir 		break;
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 	const BitmapEx  aBmpEx( GAL_RESID( nId ) );
4236dd94783SArmin Le Grand 
4246dd94783SArmin Le Grand     return aBmpEx;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir // ------------------------------------------------------------------------
428cdf0e10cSrcweir 
WriteData(SvStream & rOut,const String & rDestDir) const429cdf0e10cSrcweir void SgaObjectSound::WriteData( SvStream& rOut, const String& rDestDir ) const
430cdf0e10cSrcweir {
431cdf0e10cSrcweir 	SgaObject::WriteData( rOut, rDestDir );
432cdf0e10cSrcweir 	rOut << (sal_uInt16) eSoundType << ByteString( aTitle, RTL_TEXTENCODING_UTF8 );
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir // ------------------------------------------------------------------------
436cdf0e10cSrcweir 
ReadData(SvStream & rIn,sal_uInt16 & rReadVersion)437cdf0e10cSrcweir void SgaObjectSound::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	SgaObject::ReadData( rIn, rReadVersion );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 	if( rReadVersion >= 5 )
442cdf0e10cSrcweir 	{
443cdf0e10cSrcweir 		ByteString	aTmpStr;
444cdf0e10cSrcweir 		sal_uInt16		nTmp16;
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 		rIn >> nTmp16; eSoundType = (GalSoundType) nTmp16;
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 		if( rReadVersion >= 6 )
449cdf0e10cSrcweir 		{
450cdf0e10cSrcweir 			rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
451cdf0e10cSrcweir 		}
452cdf0e10cSrcweir 	}
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir // -----------------
456cdf0e10cSrcweir // - SgaObjectAnim -
457cdf0e10cSrcweir // -----------------
458cdf0e10cSrcweir 
SgaObjectAnim()459cdf0e10cSrcweir SgaObjectAnim::SgaObjectAnim()
460cdf0e10cSrcweir {
461cdf0e10cSrcweir }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir // ------------------------------------------------------------------------
464cdf0e10cSrcweir 
SgaObjectAnim(const Graphic & rGraphic,const INetURLObject & rURL,const String &)465cdf0e10cSrcweir SgaObjectAnim::SgaObjectAnim( const Graphic& rGraphic,
466cdf0e10cSrcweir 							  const INetURLObject& rURL,
467cdf0e10cSrcweir 							  const String& )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	aURL = rURL;
470cdf0e10cSrcweir 	bIsValid = CreateThumb( rGraphic );
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir // -----------------
474cdf0e10cSrcweir // - SgaObjectINet -
475cdf0e10cSrcweir // -----------------
476cdf0e10cSrcweir 
SgaObjectINet()477cdf0e10cSrcweir SgaObjectINet::SgaObjectINet()
478cdf0e10cSrcweir {
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir // ------------------------------------------------------------------------
482cdf0e10cSrcweir 
SgaObjectINet(const Graphic & rGraphic,const INetURLObject & rURL,const String & rFormatName)483cdf0e10cSrcweir SgaObjectINet::SgaObjectINet( const Graphic& rGraphic, const INetURLObject& rURL, const String& rFormatName ) :
484cdf0e10cSrcweir 			SgaObjectAnim	( rGraphic, rURL, rFormatName )
485cdf0e10cSrcweir {
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir // -------------------
489cdf0e10cSrcweir // - SgaObjectSvDraw -
490cdf0e10cSrcweir // -------------------
491cdf0e10cSrcweir 
SgaObjectSvDraw()492cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw()
493cdf0e10cSrcweir {
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir // ------------------------------------------------------------------------
497cdf0e10cSrcweir 
SgaObjectSvDraw(const FmFormModel & rModel,const INetURLObject & rURL)498cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw( const FmFormModel& rModel, const INetURLObject& rURL )
499cdf0e10cSrcweir {
500cdf0e10cSrcweir 	aURL = rURL;
501cdf0e10cSrcweir 	bIsValid = CreateThumb( rModel );
502cdf0e10cSrcweir }
503cdf0e10cSrcweir 
504cdf0e10cSrcweir // ------------------------------------------------------------------------
DBG_NAME(SvxGalleryDrawModel)505cdf0e10cSrcweir DBG_NAME(SvxGalleryDrawModel)
506cdf0e10cSrcweir 
507cdf0e10cSrcweir SvxGalleryDrawModel::SvxGalleryDrawModel()
508cdf0e10cSrcweir : mpFormModel( 0 )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir     DBG_CTOR(SvxGalleryDrawModel,NULL);
511cdf0e10cSrcweir 
512cdf0e10cSrcweir     const String sFactoryURL(RTL_CONSTASCII_USTRINGPARAM("sdraw"));
513cdf0e10cSrcweir 
514cdf0e10cSrcweir     mxDoc = SfxObjectShell::CreateObjectByFactoryName( sFactoryURL );
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     if( mxDoc.Is() )
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         mxDoc->DoInitNew(0);
519cdf0e10cSrcweir 
520cdf0e10cSrcweir         uno::Reference< lang::XUnoTunnel > xTunnel( mxDoc->GetModel(), uno::UNO_QUERY );
521cdf0e10cSrcweir         if( xTunnel.is() )
522cdf0e10cSrcweir         {
523cdf0e10cSrcweir             mpFormModel = dynamic_cast< FmFormModel* >(
524cdf0e10cSrcweir                 reinterpret_cast<SdrModel*>(xTunnel->getSomething(SdrModel::getUnoTunnelImplementationId())));
525cdf0e10cSrcweir             if( mpFormModel )
526cdf0e10cSrcweir             {
527cdf0e10cSrcweir                 mpFormModel->InsertPage( mpFormModel->AllocPage( false ) );
528cdf0e10cSrcweir             }
529cdf0e10cSrcweir         }
530cdf0e10cSrcweir     }
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir // ------------------------------------------------------------------------
534cdf0e10cSrcweir 
~SvxGalleryDrawModel()535cdf0e10cSrcweir SvxGalleryDrawModel::~SvxGalleryDrawModel()
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     if( mxDoc.Is() )
538cdf0e10cSrcweir         mxDoc->DoClose();
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     DBG_DTOR(SvxGalleryDrawModel,NULL);
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir // ------------------------------------------------------------------------
544cdf0e10cSrcweir 
SgaObjectSvDraw(SvStream & rIStm,const INetURLObject & rURL)545cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw( SvStream& rIStm, const INetURLObject& rURL )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir     SvxGalleryDrawModel aModel;
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     if( aModel.GetModel() )
550cdf0e10cSrcweir     {
551cdf0e10cSrcweir         if( GallerySvDrawImport( rIStm, *aModel.GetModel()  ) )
552cdf0e10cSrcweir         {
553cdf0e10cSrcweir             aURL = rURL;
554cdf0e10cSrcweir             bIsValid = CreateThumb( *aModel.GetModel()  );
555cdf0e10cSrcweir         }
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir // ------------------------------------------------------------------------
560cdf0e10cSrcweir 
CreateThumb(const FmFormModel & rModel)561cdf0e10cSrcweir sal_Bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir 	Graphic		aGraphic;
564cdf0e10cSrcweir 	ImageMap	aImageMap;
565cdf0e10cSrcweir 	sal_Bool		bRet = sal_False;
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	if ( CreateIMapGraphic( rModel, aGraphic, aImageMap ) )
5686dd94783SArmin Le Grand     {
569cdf0e10cSrcweir 		bRet = SgaObject::CreateThumb( aGraphic );
5706dd94783SArmin Le Grand     }
571cdf0e10cSrcweir 	else
572cdf0e10cSrcweir 	{
5736dd94783SArmin Le Grand         const FmFormPage* pPage = static_cast< const FmFormPage* >(rModel.GetPage(0));
574cdf0e10cSrcweir 
5756dd94783SArmin Le Grand         if(pPage)
576cdf0e10cSrcweir         {
5776dd94783SArmin Le Grand             const Rectangle aObjRect(pPage->GetAllObjBoundRect());
578cdf0e10cSrcweir 
5796dd94783SArmin Le Grand             if(aObjRect.GetWidth() && aObjRect.GetHeight())
5806dd94783SArmin Le Grand             {
5816dd94783SArmin Le Grand                 VirtualDevice aVDev;
5826dd94783SArmin Le Grand                 FmFormView aView(const_cast< FmFormModel* >(&rModel), &aVDev);
5836dd94783SArmin Le Grand 
5846dd94783SArmin Le Grand                 aView.ShowSdrPage(const_cast< FmFormPage* >(pPage));
5856dd94783SArmin Le Grand                 aView.MarkAllObj();
5866dd94783SArmin Le Grand                 aThumbBmp = aView.GetMarkedObjBitmapEx();
5876dd94783SArmin Le Grand 
5886dd94783SArmin Le Grand                 const Size aDiscreteSize(aThumbBmp.GetSizePixel());
5896dd94783SArmin Le Grand 
5906dd94783SArmin Le Grand                 if(aDiscreteSize.Width() && aDiscreteSize.Height())
5916dd94783SArmin Le Grand                 {
5926dd94783SArmin Le Grand                     sal_uInt32 nTargetSizeX(S_THUMB);
5936dd94783SArmin Le Grand                     sal_uInt32 nTargetSizeY(S_THUMB);
5946dd94783SArmin Le Grand 
5956dd94783SArmin Le Grand                     if(aDiscreteSize.Width() > aDiscreteSize.Height())
5966dd94783SArmin Le Grand                     {
5976dd94783SArmin Le Grand                         nTargetSizeY = (aDiscreteSize.Height() * nTargetSizeX) / aDiscreteSize.Width();
5986dd94783SArmin Le Grand                     }
5996dd94783SArmin Le Grand                     else
6006dd94783SArmin Le Grand                     {
6016dd94783SArmin Le Grand                         nTargetSizeX = (aDiscreteSize.Width() * nTargetSizeY) / aDiscreteSize.Height();
6026dd94783SArmin Le Grand                     }
6036dd94783SArmin Le Grand 
6046dd94783SArmin Le Grand                     if(!!aThumbBmp)
6056dd94783SArmin Le Grand                     {
6066dd94783SArmin Le Grand                         aThumbBmp.Scale(Size(nTargetSizeX, nTargetSizeY), BMP_SCALE_BESTQUALITY);
6076dd94783SArmin Le Grand                         aThumbBmp.Convert(BMP_CONVERSION_8BIT_COLORS);
6086dd94783SArmin Le Grand                         bRet = true;
6096dd94783SArmin Le Grand                     }
6106dd94783SArmin Le Grand                 }
6116dd94783SArmin Le Grand             }
612cdf0e10cSrcweir         }
613cdf0e10cSrcweir 	}
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 	return bRet;
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir // ------------------------------------------------------------------------
619cdf0e10cSrcweir 
WriteData(SvStream & rOut,const String & rDestDir) const620cdf0e10cSrcweir void SgaObjectSvDraw::WriteData( SvStream& rOut, const String& rDestDir ) const
621cdf0e10cSrcweir {
622cdf0e10cSrcweir 	SgaObject::WriteData( rOut, rDestDir );
623cdf0e10cSrcweir 	rOut << ByteString( aTitle, RTL_TEXTENCODING_UTF8 );
624cdf0e10cSrcweir }
625cdf0e10cSrcweir 
626cdf0e10cSrcweir // ------------------------------------------------------------------------
627cdf0e10cSrcweir 
ReadData(SvStream & rIn,sal_uInt16 & rReadVersion)628cdf0e10cSrcweir void SgaObjectSvDraw::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
629cdf0e10cSrcweir {
630cdf0e10cSrcweir 	SgaObject::ReadData( rIn, rReadVersion );
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 	if( rReadVersion >= 5 )
633cdf0e10cSrcweir 	{
634cdf0e10cSrcweir 		ByteString aTmpStr;
635cdf0e10cSrcweir 		rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
636cdf0e10cSrcweir 	}
637cdf0e10cSrcweir }
6386dd94783SArmin Le Grand 
6396dd94783SArmin Le Grand // eof
640