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