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 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 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 94*54628ca4SArmin Le Grand aBmpEx.SetSizePixel( aBmpSize, BMP_SCALE_BESTQUALITY ); 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 111*54628ca4SArmin Le Grand if(aThumbBmp.Scale( 112*54628ca4SArmin Le Grand (double) aNewSize.Width() / aBmpSize.Width(), 113*54628ca4SArmin Le Grand (double) aNewSize.Height() / aBmpSize.Height(), 114*54628ca4SArmin Le Grand BMP_SCALE_BESTQUALITY ) ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); 117cdf0e10cSrcweir bRet = sal_True; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir } 122cdf0e10cSrcweir else if( rGraphic.GetType() == GRAPHIC_GDIMETAFILE ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir const Size aPrefSize( rGraphic.GetPrefSize() ); 125cdf0e10cSrcweir const double fFactor = (double)aPrefSize.Width() / (double)aPrefSize.Height(); 126cdf0e10cSrcweir Size aSize( S_THUMB, S_THUMB ); 127cdf0e10cSrcweir if ( fFactor < 1.0 ) 128cdf0e10cSrcweir aSize.Width() = (sal_Int32)( S_THUMB * fFactor ); 129cdf0e10cSrcweir else 130cdf0e10cSrcweir aSize.Height() = (sal_Int32)( S_THUMB / fFactor ); 131cdf0e10cSrcweir 132*54628ca4SArmin Le Grand const GraphicConversionParameters aParameters(aSize, false, true, true, true); 133cdf0e10cSrcweir aThumbBmp = rGraphic.GetBitmap(aParameters); 134cdf0e10cSrcweir 135cdf0e10cSrcweir if( !aThumbBmp.IsEmpty() ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); 138cdf0e10cSrcweir bRet = sal_True; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir return bRet; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir // ------------------------------------------------------------------------ 146cdf0e10cSrcweir 147cdf0e10cSrcweir void SgaObject::WriteData( SvStream& rOut, const String& rDestDir ) const 148cdf0e10cSrcweir { 149cdf0e10cSrcweir static const sal_uInt32 nInventor = COMPAT_FORMAT( 'S', 'G', 'A', '3' ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir rOut << nInventor << (sal_uInt16) 0x0004 << GetVersion() << (sal_uInt16) GetObjKind(); 152cdf0e10cSrcweir rOut << bIsThumbBmp; 153cdf0e10cSrcweir 154cdf0e10cSrcweir if( bIsThumbBmp ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir const sal_uInt16 nOldCompressMode = rOut.GetCompressMode(); 157cdf0e10cSrcweir const sal_uIntPtr nOldVersion = rOut.GetVersion(); 158cdf0e10cSrcweir 159cdf0e10cSrcweir rOut.SetCompressMode( COMPRESSMODE_ZBITMAP ); 160cdf0e10cSrcweir rOut.SetVersion( SOFFICE_FILEFORMAT_50 ); 161cdf0e10cSrcweir 162cdf0e10cSrcweir rOut << aThumbBmp; 163cdf0e10cSrcweir 164cdf0e10cSrcweir rOut.SetVersion( nOldVersion ); 165cdf0e10cSrcweir rOut.SetCompressMode( nOldCompressMode ); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir else 168cdf0e10cSrcweir rOut << aThumbMtf; 169cdf0e10cSrcweir 170cdf0e10cSrcweir String aURLWithoutDestDir = String(aURL.GetMainURL( INetURLObject::NO_DECODE )); 171cdf0e10cSrcweir aURLWithoutDestDir.SearchAndReplace(rDestDir, String()); 172cdf0e10cSrcweir rOut << ByteString( aURLWithoutDestDir, RTL_TEXTENCODING_UTF8 ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir // ------------------------------------------------------------------------ 176cdf0e10cSrcweir 177cdf0e10cSrcweir void SgaObject::ReadData(SvStream& rIn, sal_uInt16& rReadVersion ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir ByteString aTmpStr; 180cdf0e10cSrcweir sal_uInt32 nTmp32; 181cdf0e10cSrcweir sal_uInt16 nTmp16; 182cdf0e10cSrcweir 183cdf0e10cSrcweir rIn >> nTmp32 >> nTmp16 >> rReadVersion >> nTmp16 >> bIsThumbBmp; 184cdf0e10cSrcweir 185cdf0e10cSrcweir if( bIsThumbBmp ) 186cdf0e10cSrcweir rIn >> aThumbBmp; 187cdf0e10cSrcweir else 188cdf0e10cSrcweir rIn >> aThumbMtf; 189cdf0e10cSrcweir 190cdf0e10cSrcweir rIn >> aTmpStr; aURL = INetURLObject( String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 ) ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir // ------------------------------------------------------------------------ 194cdf0e10cSrcweir 195cdf0e10cSrcweir const String SgaObject::GetTitle() const 196cdf0e10cSrcweir { 197cdf0e10cSrcweir String aReturnValue( aTitle ); 198cdf0e10cSrcweir if ( !getenv( "GALLERY_SHOW_PRIVATE_TITLE" ) ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir if ( aReturnValue.GetTokenCount( ':' ) == 3 ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir String aPrivateInd ( aReturnValue.GetToken( 0, ':' ) ); 203cdf0e10cSrcweir String aResourceName( aReturnValue.GetToken( 1, ':' ) ); 204cdf0e10cSrcweir sal_Int32 nResId ( aReturnValue.GetToken( 2, ':' ).ToInt32() ); 205cdf0e10cSrcweir if ( aReturnValue.GetToken( 0, ':' ).EqualsAscii( "private" ) && 206cdf0e10cSrcweir aResourceName.Len() && ( nResId > 0 ) && ( nResId < 0x10000 ) ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir ByteString aMgrName( aResourceName, RTL_TEXTENCODING_UTF8 ); 209cdf0e10cSrcweir ResMgr* pResMgr = ResMgr::CreateResMgr( aMgrName.GetBuffer(), 210cdf0e10cSrcweir Application::GetSettings().GetUILocale() ); 211cdf0e10cSrcweir if ( pResMgr ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir ResId aResId( (sal_uInt16)nResId, *pResMgr ); 214cdf0e10cSrcweir aResId.SetRT( RSC_STRING ); 215cdf0e10cSrcweir if ( pResMgr->IsAvailable( aResId ) ) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir aReturnValue = String( aResId ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir delete pResMgr; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir } 224cdf0e10cSrcweir return aReturnValue; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir // ------------------------------------------------------------------------ 228cdf0e10cSrcweir 229cdf0e10cSrcweir void SgaObject::SetTitle( const String& rTitle ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir aTitle = rTitle; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir // ------------------------------------------------------------------------ 235cdf0e10cSrcweir 236cdf0e10cSrcweir SvStream& operator<<( SvStream& rOut, const SgaObject& rObj ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir rObj.WriteData( rOut, String() ); 239cdf0e10cSrcweir return rOut; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir // ------------------------------------------------------------------------ 243cdf0e10cSrcweir 244cdf0e10cSrcweir SvStream& operator>>( SvStream& rIn, SgaObject& rObj ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir sal_uInt16 nReadVersion; 247cdf0e10cSrcweir 248cdf0e10cSrcweir rObj.ReadData( rIn, nReadVersion ); 249cdf0e10cSrcweir rObj.bIsValid = ( rIn.GetError() == ERRCODE_NONE ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir return rIn; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir // ---------------- 255cdf0e10cSrcweir // - SgaObjectBmp - 256cdf0e10cSrcweir // ---------------- 257cdf0e10cSrcweir 258cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp() 259cdf0e10cSrcweir { 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir // ------------------------------------------------------------------------ 263cdf0e10cSrcweir 264cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp( const INetURLObject& rURL ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir Graphic aGraphic; 267cdf0e10cSrcweir String aFilter; 268cdf0e10cSrcweir 269cdf0e10cSrcweir if ( SGA_IMPORT_NONE != GalleryGraphicImport( rURL, aGraphic, aFilter ) ) 270cdf0e10cSrcweir Init( aGraphic, rURL ); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir // ------------------------------------------------------------------------ 274cdf0e10cSrcweir 275cdf0e10cSrcweir SgaObjectBmp::SgaObjectBmp( const Graphic& rGraphic, const INetURLObject& rURL, const String& ) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir if( FileExists( rURL ) ) 278cdf0e10cSrcweir Init( rGraphic, rURL ); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir // ------------------------------------------------------------------------ 282cdf0e10cSrcweir 283cdf0e10cSrcweir void SgaObjectBmp::Init( const Graphic& rGraphic, const INetURLObject& rURL ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir aURL = rURL; 286cdf0e10cSrcweir bIsValid = CreateThumb( rGraphic ); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir // ------------------------------------------------------------------------ 290cdf0e10cSrcweir 291cdf0e10cSrcweir void SgaObjectBmp::WriteData( SvStream& rOut, const String& rDestDir ) const 292cdf0e10cSrcweir { 293cdf0e10cSrcweir String aDummyStr; 294cdf0e10cSrcweir char aDummy[ 10 ]; 295cdf0e10cSrcweir 296cdf0e10cSrcweir // Version setzen 297cdf0e10cSrcweir SgaObject::WriteData( rOut, rDestDir ); 298cdf0e10cSrcweir rOut.Write( aDummy, 10 ); 299cdf0e10cSrcweir rOut << ByteString( aDummyStr, RTL_TEXTENCODING_UTF8 ) << ByteString( aTitle, RTL_TEXTENCODING_UTF8 ); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir // ------------------------------------------------------------------------ 303cdf0e10cSrcweir 304cdf0e10cSrcweir void SgaObjectBmp::ReadData( SvStream& rIn, sal_uInt16& rReadVersion ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir ByteString aTmpStr; 307cdf0e10cSrcweir 308cdf0e10cSrcweir SgaObject::ReadData( rIn, rReadVersion ); 309cdf0e10cSrcweir rIn.SeekRel( 10 ); // 16, 16, 32, 16 310cdf0e10cSrcweir rIn >> aTmpStr; // dummy 311cdf0e10cSrcweir 312cdf0e10cSrcweir if( rReadVersion >= 5 ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 ); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir // ------------------ 319cdf0e10cSrcweir // - SgaObjectSound - 320cdf0e10cSrcweir // ------------------ 321cdf0e10cSrcweir DBG_NAME(SgaObjectSound) 322cdf0e10cSrcweir 323cdf0e10cSrcweir SgaObjectSound::SgaObjectSound() : 324cdf0e10cSrcweir eSoundType( SOUND_STANDARD ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir DBG_CTOR(SgaObjectSound,NULL); 327cdf0e10cSrcweir 328cdf0e10cSrcweir } 329cdf0e10cSrcweir 330cdf0e10cSrcweir // ------------------------------------------------------------------------ 331cdf0e10cSrcweir 332cdf0e10cSrcweir SgaObjectSound::SgaObjectSound( const INetURLObject& rURL ) : 333cdf0e10cSrcweir eSoundType( SOUND_STANDARD ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir DBG_CTOR(SgaObjectSound,NULL); 336cdf0e10cSrcweir 337cdf0e10cSrcweir if( FileExists( rURL ) ) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir aURL = rURL; 340cdf0e10cSrcweir aThumbBmp = Bitmap( Size( 1, 1 ), 1 ); 341cdf0e10cSrcweir bIsValid = sal_True; 342cdf0e10cSrcweir } 343cdf0e10cSrcweir else 344cdf0e10cSrcweir bIsValid = sal_False; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir // ------------------------------------------------------------------------ 348cdf0e10cSrcweir 349cdf0e10cSrcweir SgaObjectSound::~SgaObjectSound() 350cdf0e10cSrcweir { 351cdf0e10cSrcweir 352cdf0e10cSrcweir DBG_DTOR(SgaObjectSound,NULL); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir // ------------------------------------------------------------------------ 356cdf0e10cSrcweir 357cdf0e10cSrcweir Bitmap SgaObjectSound::GetThumbBmp() const 358cdf0e10cSrcweir { 359cdf0e10cSrcweir sal_uInt16 nId; 360cdf0e10cSrcweir 361cdf0e10cSrcweir switch( eSoundType ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir case( SOUND_COMPUTER ): nId = RID_SVXBMP_GALLERY_SOUND_1; break; 364cdf0e10cSrcweir case( SOUND_MISC ): nId = RID_SVXBMP_GALLERY_SOUND_2; break; 365cdf0e10cSrcweir case( SOUND_MUSIC ): nId = RID_SVXBMP_GALLERY_SOUND_3; break; 366cdf0e10cSrcweir case( SOUND_NATURE ): nId = RID_SVXBMP_GALLERY_SOUND_4; break; 367cdf0e10cSrcweir case( SOUND_SPEECH ): nId = RID_SVXBMP_GALLERY_SOUND_5; break; 368cdf0e10cSrcweir case( SOUND_TECHNIC ): nId = RID_SVXBMP_GALLERY_SOUND_6; break; 369cdf0e10cSrcweir case( SOUND_ANIMAL ): nId = RID_SVXBMP_GALLERY_SOUND_7; break; 370cdf0e10cSrcweir 371cdf0e10cSrcweir // standard 372cdf0e10cSrcweir default: 373cdf0e10cSrcweir nId = RID_SVXBMP_GALLERY_MEDIA; 374cdf0e10cSrcweir break; 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir const BitmapEx aBmpEx( GAL_RESID( nId ) ); 378cdf0e10cSrcweir const Color aTransColor( COL_WHITE ); 379cdf0e10cSrcweir 380cdf0e10cSrcweir return aBmpEx.GetBitmap( &aTransColor ); 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir // ------------------------------------------------------------------------ 384cdf0e10cSrcweir 385cdf0e10cSrcweir void SgaObjectSound::WriteData( SvStream& rOut, const String& rDestDir ) const 386cdf0e10cSrcweir { 387cdf0e10cSrcweir SgaObject::WriteData( rOut, rDestDir ); 388cdf0e10cSrcweir rOut << (sal_uInt16) eSoundType << ByteString( aTitle, RTL_TEXTENCODING_UTF8 ); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir // ------------------------------------------------------------------------ 392cdf0e10cSrcweir 393cdf0e10cSrcweir void SgaObjectSound::ReadData( SvStream& rIn, sal_uInt16& rReadVersion ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir SgaObject::ReadData( rIn, rReadVersion ); 396cdf0e10cSrcweir 397cdf0e10cSrcweir if( rReadVersion >= 5 ) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir ByteString aTmpStr; 400cdf0e10cSrcweir sal_uInt16 nTmp16; 401cdf0e10cSrcweir 402cdf0e10cSrcweir rIn >> nTmp16; eSoundType = (GalSoundType) nTmp16; 403cdf0e10cSrcweir 404cdf0e10cSrcweir if( rReadVersion >= 6 ) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 ); 407cdf0e10cSrcweir } 408cdf0e10cSrcweir } 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir // ----------------- 412cdf0e10cSrcweir // - SgaObjectAnim - 413cdf0e10cSrcweir // ----------------- 414cdf0e10cSrcweir 415cdf0e10cSrcweir SgaObjectAnim::SgaObjectAnim() 416cdf0e10cSrcweir { 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir // ------------------------------------------------------------------------ 420cdf0e10cSrcweir 421cdf0e10cSrcweir SgaObjectAnim::SgaObjectAnim( const Graphic& rGraphic, 422cdf0e10cSrcweir const INetURLObject& rURL, 423cdf0e10cSrcweir const String& ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir aURL = rURL; 426cdf0e10cSrcweir bIsValid = CreateThumb( rGraphic ); 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir // ----------------- 430cdf0e10cSrcweir // - SgaObjectINet - 431cdf0e10cSrcweir // ----------------- 432cdf0e10cSrcweir 433cdf0e10cSrcweir SgaObjectINet::SgaObjectINet() 434cdf0e10cSrcweir { 435cdf0e10cSrcweir } 436cdf0e10cSrcweir 437cdf0e10cSrcweir // ------------------------------------------------------------------------ 438cdf0e10cSrcweir 439cdf0e10cSrcweir SgaObjectINet::SgaObjectINet( const Graphic& rGraphic, const INetURLObject& rURL, const String& rFormatName ) : 440cdf0e10cSrcweir SgaObjectAnim ( rGraphic, rURL, rFormatName ) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir } 443cdf0e10cSrcweir 444cdf0e10cSrcweir // ------------------- 445cdf0e10cSrcweir // - SgaObjectSvDraw - 446cdf0e10cSrcweir // ------------------- 447cdf0e10cSrcweir 448cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw() 449cdf0e10cSrcweir { 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir // ------------------------------------------------------------------------ 453cdf0e10cSrcweir 454cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw( const FmFormModel& rModel, const INetURLObject& rURL ) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir aURL = rURL; 457cdf0e10cSrcweir bIsValid = CreateThumb( rModel ); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir // ------------------------------------------------------------------------ 461cdf0e10cSrcweir DBG_NAME(SvxGalleryDrawModel) 462cdf0e10cSrcweir 463cdf0e10cSrcweir SvxGalleryDrawModel::SvxGalleryDrawModel() 464cdf0e10cSrcweir : mpFormModel( 0 ) 465cdf0e10cSrcweir { 466cdf0e10cSrcweir DBG_CTOR(SvxGalleryDrawModel,NULL); 467cdf0e10cSrcweir 468cdf0e10cSrcweir const String sFactoryURL(RTL_CONSTASCII_USTRINGPARAM("sdraw")); 469cdf0e10cSrcweir 470cdf0e10cSrcweir mxDoc = SfxObjectShell::CreateObjectByFactoryName( sFactoryURL ); 471cdf0e10cSrcweir 472cdf0e10cSrcweir if( mxDoc.Is() ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir mxDoc->DoInitNew(0); 475cdf0e10cSrcweir 476cdf0e10cSrcweir uno::Reference< lang::XUnoTunnel > xTunnel( mxDoc->GetModel(), uno::UNO_QUERY ); 477cdf0e10cSrcweir if( xTunnel.is() ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir mpFormModel = dynamic_cast< FmFormModel* >( 480cdf0e10cSrcweir reinterpret_cast<SdrModel*>(xTunnel->getSomething(SdrModel::getUnoTunnelImplementationId()))); 481cdf0e10cSrcweir if( mpFormModel ) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir mpFormModel->InsertPage( mpFormModel->AllocPage( false ) ); 484cdf0e10cSrcweir } 485cdf0e10cSrcweir } 486cdf0e10cSrcweir } 487cdf0e10cSrcweir } 488cdf0e10cSrcweir 489cdf0e10cSrcweir // ------------------------------------------------------------------------ 490cdf0e10cSrcweir 491cdf0e10cSrcweir SvxGalleryDrawModel::~SvxGalleryDrawModel() 492cdf0e10cSrcweir { 493cdf0e10cSrcweir if( mxDoc.Is() ) 494cdf0e10cSrcweir mxDoc->DoClose(); 495cdf0e10cSrcweir 496cdf0e10cSrcweir DBG_DTOR(SvxGalleryDrawModel,NULL); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir 499cdf0e10cSrcweir // ------------------------------------------------------------------------ 500cdf0e10cSrcweir 501cdf0e10cSrcweir SgaObjectSvDraw::SgaObjectSvDraw( SvStream& rIStm, const INetURLObject& rURL ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir SvxGalleryDrawModel aModel; 504cdf0e10cSrcweir 505cdf0e10cSrcweir if( aModel.GetModel() ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir if( GallerySvDrawImport( rIStm, *aModel.GetModel() ) ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir aURL = rURL; 510cdf0e10cSrcweir bIsValid = CreateThumb( *aModel.GetModel() ); 511cdf0e10cSrcweir } 512cdf0e10cSrcweir } 513cdf0e10cSrcweir } 514cdf0e10cSrcweir 515cdf0e10cSrcweir // ------------------------------------------------------------------------ 516cdf0e10cSrcweir 517cdf0e10cSrcweir sal_Bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel ) 518cdf0e10cSrcweir { 519cdf0e10cSrcweir Graphic aGraphic; 520cdf0e10cSrcweir ImageMap aImageMap; 521cdf0e10cSrcweir sal_Bool bRet = sal_False; 522cdf0e10cSrcweir 523cdf0e10cSrcweir if ( CreateIMapGraphic( rModel, aGraphic, aImageMap ) ) 524cdf0e10cSrcweir bRet = SgaObject::CreateThumb( aGraphic ); 525cdf0e10cSrcweir else 526cdf0e10cSrcweir { 527cdf0e10cSrcweir VirtualDevice aVDev; 528cdf0e10cSrcweir 529cdf0e10cSrcweir aVDev.SetOutputSizePixel( Size( S_THUMB*2, S_THUMB*2 ) ); 530cdf0e10cSrcweir 531cdf0e10cSrcweir bRet = DrawCentered( &aVDev, rModel ); 532cdf0e10cSrcweir if( bRet ) 533cdf0e10cSrcweir { 534cdf0e10cSrcweir aThumbBmp = aVDev.GetBitmap( Point(), aVDev.GetOutputSizePixel() ); 535cdf0e10cSrcweir 536cdf0e10cSrcweir Size aMS( 2, 2 ); 537cdf0e10cSrcweir BmpFilterParam aParam( aMS ); 538cdf0e10cSrcweir aThumbBmp.Filter( BMP_FILTER_MOSAIC, &aParam ); 539cdf0e10cSrcweir aThumbBmp.Scale( Size( S_THUMB, S_THUMB ) ); 540cdf0e10cSrcweir 541cdf0e10cSrcweir aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); 542cdf0e10cSrcweir } 543cdf0e10cSrcweir } 544cdf0e10cSrcweir 545cdf0e10cSrcweir return bRet; 546cdf0e10cSrcweir } 547cdf0e10cSrcweir 548cdf0e10cSrcweir // ------------------------------------------------------------------------ 549cdf0e10cSrcweir 550cdf0e10cSrcweir sal_Bool SgaObjectSvDraw::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel ) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir const FmFormPage* pPage = static_cast< const FmFormPage* >( rModel.GetPage( 0 ) ); 553cdf0e10cSrcweir sal_Bool bRet = sal_False; 554cdf0e10cSrcweir 555cdf0e10cSrcweir if( pOut && pPage ) 556cdf0e10cSrcweir { 557cdf0e10cSrcweir const Rectangle aObjRect( pPage->GetAllObjBoundRect() ); 558cdf0e10cSrcweir const Size aOutSizePix( pOut->GetOutputSizePixel() ); 559cdf0e10cSrcweir 560cdf0e10cSrcweir if( aObjRect.GetWidth() && aObjRect.GetHeight() && aOutSizePix.Width() > 2 && aOutSizePix.Height() > 2 ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir FmFormView aView( const_cast< FmFormModel* >( &rModel ), pOut ); 563cdf0e10cSrcweir MapMode aMap( rModel.GetScaleUnit() ); 564cdf0e10cSrcweir Rectangle aDrawRectPix( Point( 1, 1 ), Size( aOutSizePix.Width() - 2, aOutSizePix.Height() - 2 ) ); 565cdf0e10cSrcweir const double fFactor = (double) aObjRect.GetWidth() / aObjRect.GetHeight(); 566cdf0e10cSrcweir Fraction aFrac( FRound( fFactor < 1. ? aDrawRectPix.GetWidth() * fFactor : aDrawRectPix.GetWidth() ), 567cdf0e10cSrcweir pOut->LogicToPixel( aObjRect.GetSize(), aMap ).Width() ); 568cdf0e10cSrcweir 569cdf0e10cSrcweir aMap.SetScaleX( aFrac ); 570cdf0e10cSrcweir aMap.SetScaleY( aFrac ); 571cdf0e10cSrcweir 572cdf0e10cSrcweir const Size aDrawSize( pOut->PixelToLogic( aDrawRectPix.GetSize(), aMap ) ); 573cdf0e10cSrcweir Point aOrigin( pOut->PixelToLogic( aDrawRectPix.TopLeft(), aMap ) ); 574cdf0e10cSrcweir 575cdf0e10cSrcweir aOrigin.X() += ( ( aDrawSize.Width() - aObjRect.GetWidth() ) >> 1 ) - aObjRect.Left(); 576cdf0e10cSrcweir aOrigin.Y() += ( ( aDrawSize.Height() - aObjRect.GetHeight() ) >> 1 ) - aObjRect.Top(); 577cdf0e10cSrcweir aMap.SetOrigin( aOrigin ); 578cdf0e10cSrcweir 579cdf0e10cSrcweir aView.SetPageVisible( sal_False ); 580cdf0e10cSrcweir aView.SetBordVisible( sal_False ); 581cdf0e10cSrcweir aView.SetGridVisible( sal_False ); 582cdf0e10cSrcweir aView.SetHlplVisible( sal_False ); 583cdf0e10cSrcweir aView.SetGlueVisible( sal_False ); 584cdf0e10cSrcweir 585cdf0e10cSrcweir pOut->Push(); 586cdf0e10cSrcweir pOut->SetMapMode( aMap ); 587cdf0e10cSrcweir aView.ShowSdrPage( const_cast< FmFormPage* >( pPage )); 588cdf0e10cSrcweir aView.CompleteRedraw( pOut, Rectangle( pOut->PixelToLogic( Point() ), pOut->GetOutputSize() ) ); 589cdf0e10cSrcweir pOut->Pop(); 590cdf0e10cSrcweir 591cdf0e10cSrcweir bRet = sal_True; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir } 594cdf0e10cSrcweir 595cdf0e10cSrcweir return bRet; 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir // ------------------------------------------------------------------------ 599cdf0e10cSrcweir 600cdf0e10cSrcweir void SgaObjectSvDraw::WriteData( SvStream& rOut, const String& rDestDir ) const 601cdf0e10cSrcweir { 602cdf0e10cSrcweir SgaObject::WriteData( rOut, rDestDir ); 603cdf0e10cSrcweir rOut << ByteString( aTitle, RTL_TEXTENCODING_UTF8 ); 604cdf0e10cSrcweir } 605cdf0e10cSrcweir 606cdf0e10cSrcweir // ------------------------------------------------------------------------ 607cdf0e10cSrcweir 608cdf0e10cSrcweir void SgaObjectSvDraw::ReadData( SvStream& rIn, sal_uInt16& rReadVersion ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir SgaObject::ReadData( rIn, rReadVersion ); 611cdf0e10cSrcweir 612cdf0e10cSrcweir if( rReadVersion >= 5 ) 613cdf0e10cSrcweir { 614cdf0e10cSrcweir ByteString aTmpStr; 615cdf0e10cSrcweir rIn >> aTmpStr; aTitle = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 ); 616cdf0e10cSrcweir } 617cdf0e10cSrcweir } 618