diff options
author | Armin Le Grand <alg@apache.org> | 2012-12-07 17:15:12 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-10 17:04:38 +0100 |
commit | bbc58f2043eb0787f498f62ac54500bd31d8c89c (patch) | |
tree | 832b790c92eb07c3b38ed746f31831a6b1b891f6 /svx | |
parent | 94298db96fa14f6c7c8eb67b2faab3ac01bd5ccd (diff) |
Resolves: #i121445# Added transparency support to the gallery
(cherry picked from commit cf417aec41decab94b5f1e82f6409e97a6c02fb5)
Conflicts:
extras/source/gallery/gallery_system/sg2.sdg
extras/source/gallery/gallery_system/sg2.thm
svx/inc/galtheme.hrc
svx/inc/svx/fontworkgallery.hxx
svx/inc/svx/gallery.hxx
svx/inc/svx/galtheme.hxx
svx/source/gallery2/galctrl.cxx
svx/source/gallery2/galexpl.cxx
svx/source/gallery2/galobj.cxx
svx/source/tbxctrls/fontworkgallery.cxx
vcl/inc/vcl/outdev.hxx
vcl/source/gdi/outdev6.cxx
Change-Id: I519a2cf4e16bb42ecfd9c4b48094e65adcc35599
(cherry picked from commit ddec662e8dc234b7196c1b3c28db5da743557ec6)
Diffstat (limited to 'svx')
-rw-r--r-- | svx/inc/galobj.hxx | 10 | ||||
-rw-r--r-- | svx/inc/galtheme.hrc | 8 | ||||
-rw-r--r-- | svx/source/gallery2/galctrl.cxx | 61 | ||||
-rw-r--r-- | svx/source/gallery2/galexpl.cxx | 8 | ||||
-rw-r--r-- | svx/source/gallery2/galobj.cxx | 102 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 9 | ||||
-rw-r--r-- | svx/source/tbxctrls/fontworkgallery.cxx | 35 |
7 files changed, 134 insertions, 99 deletions
diff --git a/svx/inc/galobj.hxx b/svx/inc/galobj.hxx index fed858cba3e6..09e038267002 100644 --- a/svx/inc/galobj.hxx +++ b/svx/inc/galobj.hxx @@ -57,7 +57,7 @@ private: protected: - Bitmap aThumbBmp; + BitmapEx aThumbBmp; // Allow transparence to survive GDIMetaFile aThumbMtf; INetURLObject aURL; String aUserName; @@ -78,7 +78,7 @@ public: virtual SgaObjKind GetObjKind() const = 0; virtual sal_uInt16 GetVersion() const = 0; - virtual Bitmap GetThumbBmp() const { return aThumbBmp; } + virtual BitmapEx GetThumbBmp() const { return aThumbBmp; } const GDIMetaFile& GetThumbMtf() const { return aThumbMtf; } const INetURLObject& GetURL() const { return aURL; } sal_Bool IsValid() const { return bIsValid; } @@ -109,7 +109,7 @@ public: virtual ~SgaObjectSound(); virtual SgaObjKind GetObjKind() const { return SGA_OBJ_SOUND; } - virtual Bitmap GetThumbBmp() const; + virtual BitmapEx GetThumbBmp() const; GalSoundType GetSoundType() const { return eSoundType; } }; @@ -136,10 +136,6 @@ public: virtual ~SgaObjectSvDraw() {}; virtual SgaObjKind GetObjKind() const { return SGA_OBJ_SVDRAW; } - -public: - - static sal_Bool DrawCentered( OutputDevice* pOut, const FmFormModel& rModel ); }; class SgaObjectBmp: public SgaObject diff --git a/svx/inc/galtheme.hrc b/svx/inc/galtheme.hrc index 2ecb5268c460..48aa05450ec5 100644 --- a/svx/inc/galtheme.hrc +++ b/svx/inc/galtheme.hrc @@ -22,8 +22,14 @@ #define RID_GALLERYSTR_THEME_START (6000) // ATTENTION: This list has to be in sync with -// * svx/inc/svx/gallery.hxx +// * include/svx/gallery.hxx // * share/gallery (theme files are identified by id) +// +// These defines are used to map gallery names to translated string ressources. Since +// galleries may be copied from older offices to newer, do *never* change this +// IDs except adding new ones (and adapting RID_GALLERYSTR_THEME_LAST). The ID +// *is* written into the binary file *.thm (which is a galler theme combined of +// three files, *.thm, *.sdv and *.sdg) #define RID_GALLERYSTR_THEME_3D (RID_GALLERYSTR_THEME_START + 1) #define RID_GALLERYSTR_THEME_ANIMATIONS (RID_GALLERYSTR_THEME_START + 2) diff --git a/svx/source/gallery2/galctrl.cxx b/svx/source/gallery2/galctrl.cxx index 848a230509c4..6811e95b2bdb 100644 --- a/svx/source/gallery2/galctrl.cxx +++ b/svx/source/gallery2/galctrl.cxx @@ -258,6 +258,16 @@ void GalleryPreview::PreviewMedia( const INetURLObject& rURL ) } } +void drawCheckered(OutputDevice& rOut, const Point& rPos, const Size& rSize) +{ + // draw checkered background + static const sal_uInt32 nLen(8); + static const Color aW(COL_WHITE); + static const Color aG(0xef, 0xef, 0xef); + + rOut.DrawCheckered(rPos, rSize, nLen, aW, aG); +} + DBG_NAME(GalleryIconView) GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) : @@ -311,21 +321,37 @@ void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt ) const Rectangle& rRect = rUDEvt.GetRect(); OutputDevice* pDev = rUDEvt.GetDevice(); Graphic aGraphic; + bool bTransparent(false); if( pObj->IsThumbBitmap() ) { - Bitmap aBmp( pObj->GetThumbBmp() ); + BitmapEx aBitmapEx; if( pObj->GetObjKind() == SGA_OBJ_SOUND ) - aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); + { + Bitmap aTemp = pObj->GetThumbBmp().GetBitmap(); + + aTemp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); + aBitmapEx = BitmapEx(aTemp); + } + else + { + aBitmapEx = pObj->GetThumbBmp(); + bTransparent = aBitmapEx.IsTransparent(); + } - if( ( pDev->GetBitCount() <= 8 ) && ( aBmp.GetBitCount() >= 8 ) ) - aBmp.Dither( BMP_DITHER_FLOYD ); + if( ( pDev->GetBitCount() <= 8 ) && ( aBitmapEx.GetBitCount() >= 8 ) ) + { + aBitmapEx.Dither( BMP_DITHER_FLOYD ); + } - aGraphic = aBmp; + aGraphic = aBitmapEx; } else + { aGraphic = pObj->GetThumbMtf(); + bTransparent = true; + } Size aSize( aGraphic.GetSizePixel( pDev ) ); @@ -352,6 +378,12 @@ void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt ) const Point aPos( ( ( rRect.GetWidth() - aSize.Width() ) >> 1 ) + rRect.Left(), ( ( rRect.GetHeight() - aSize.Height() ) >> 1 ) + rRect.Top() ); + if(bTransparent) + { + // draw checkered background + drawCheckered(*pDev, aPos, aSize); + } + aGraphic.Draw( pDev, aPos, aSize ); } @@ -517,13 +549,24 @@ void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sa { Rectangle aOutputRect( rRect.TopLeft(), Size( rRect.GetHeight(), rRect.GetHeight() ) ); GraphicObject aGrfObj; + bool bTransparent(false); if( pObj->GetObjKind() == SGA_OBJ_SOUND ) + { aGrfObj = Graphic( BitmapEx( GAL_RES( RID_SVXBMP_GALLERY_MEDIA ) ) ); + } else if( pObj->IsThumbBitmap() ) - aGrfObj = Graphic( pObj->GetThumbBmp() ); + { + const BitmapEx aBitmapEx(pObj->GetThumbBmp()); + + bTransparent = aBitmapEx.IsTransparent(); + aGrfObj = Graphic(aBitmapEx); + } else + { aGrfObj = Graphic( pObj->GetThumbMtf() ); + bTransparent = true; + } Size aSize( rDev.LogicToPixel( aGrfObj.GetPrefSize(), aGrfObj.GetPrefMapMode() ) ); @@ -553,6 +596,12 @@ void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sa const Point aPos( ( ( aOutputRect.GetWidth() - aSize.Width() ) >> 1 ) + aOutputRect.Left(), ( ( aOutputRect.GetHeight() - aSize.Height() ) >> 1 ) + aOutputRect.Top() ); + if(bTransparent) + { + // draw checkered background + drawCheckered(rDev, aPos, aSize); + } + aGrfObj.Draw( &rDev, aPos, aSize ); } diff --git a/svx/source/gallery2/galexpl.cxx b/svx/source/gallery2/galexpl.cxx index 1c505c797c81..13899ad21197 100644 --- a/svx/source/gallery2/galexpl.cxx +++ b/svx/source/gallery2/galexpl.cxx @@ -237,7 +237,7 @@ sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL, c // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos, - Graphic* pGraphic, Bitmap* pThumb, + Graphic* pGraphic, BitmapEx* pThumb, sal_Bool bProgress ) { Gallery* pGal = ImplGetGallery(); @@ -266,7 +266,7 @@ sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr n // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos, - Graphic* pGraphic, Bitmap* pThumb, + Graphic* pGraphic, BitmapEx* pThumb, sal_Bool bProgress ) { Gallery* pGal = ImplGetGallery(); @@ -309,7 +309,7 @@ sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId ) // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos, - SdrModel* pModel, Bitmap* pThumb ) + SdrModel* pModel, BitmapEx* pThumb ) { Gallery* pGal = ImplGetGallery(); sal_Bool bRet = sal_False; @@ -346,7 +346,7 @@ sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrM // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos, - SdrModel* pModel, Bitmap* pThumb ) + SdrModel* pModel, BitmapEx* pThumb ) { Gallery* pGal = ImplGetGallery(); return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False ); diff --git a/svx/source/gallery2/galobj.cxx b/svx/source/gallery2/galobj.cxx index ec88e83c18b6..29791da82d05 100644 --- a/svx/source/gallery2/galobj.cxx +++ b/svx/source/gallery2/galobj.cxx @@ -88,7 +88,8 @@ sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic ) } } - aThumbBmp = aBmpEx.GetBitmap( &aWhite ); + // take over BitmapEx + aThumbBmp = aBmpEx; if( ( aBmpSize.Width() <= S_THUMB ) && ( aBmpSize.Height() <= S_THUMB ) ) { @@ -123,7 +124,7 @@ sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic ) aSize.Height() = (sal_Int32)( S_THUMB / fFactor ); const GraphicConversionParameters aParameters(aSize, false, true, true /*TODO: extra ", true" post-#i121194#*/); - aThumbBmp = rGraphic.GetBitmap(aParameters); + aThumbBmp = rGraphic.GetBitmapEx(aParameters); if( !aThumbBmp.IsEmpty() ) { @@ -341,7 +342,7 @@ SgaObjectSound::~SgaObjectSound() // ------------------------------------------------------------------------ -Bitmap SgaObjectSound::GetThumbBmp() const +BitmapEx SgaObjectSound::GetThumbBmp() const { sal_uInt16 nId; @@ -362,9 +363,8 @@ Bitmap SgaObjectSound::GetThumbBmp() const } const BitmapEx aBmpEx( GAL_RES( nId ) ); - const Color aTransColor( COL_WHITE ); - return aBmpEx.GetBitmap( &aTransColor ); + return aBmpEx; } // ------------------------------------------------------------------------ @@ -506,76 +506,50 @@ sal_Bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel ) sal_Bool bRet = sal_False; if ( CreateIMapGraphic( rModel, aGraphic, aImageMap ) ) + { bRet = SgaObject::CreateThumb( aGraphic ); + } else { - VirtualDevice aVDev; + const FmFormPage* pPage = static_cast< const FmFormPage* >(rModel.GetPage(0)); - aVDev.SetOutputSizePixel( Size( S_THUMB*2, S_THUMB*2 ) ); - - bRet = DrawCentered( &aVDev, rModel ); - if( bRet ) + if(pPage) { - aThumbBmp = aVDev.GetBitmap( Point(), aVDev.GetOutputSizePixel() ); - - Size aMS( 2, 2 ); - BmpFilterParam aParam( aMS ); - aThumbBmp.Filter( BMP_FILTER_MOSAIC, &aParam ); - aThumbBmp.Scale( Size( S_THUMB, S_THUMB ) ); + const Rectangle aObjRect(pPage->GetAllObjBoundRect()); - aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); - } - } - - return bRet; -} + if(aObjRect.GetWidth() && aObjRect.GetHeight()) + { + VirtualDevice aVDev; + FmFormView aView(const_cast< FmFormModel* >(&rModel), &aVDev); -// ------------------------------------------------------------------------ + aView.ShowSdrPage(const_cast< FmFormPage* >(pPage)); + aView.MarkAllObj(); + aThumbBmp = aView.GetMarkedObjBitmapEx(); -sal_Bool SgaObjectSvDraw::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel ) -{ - const FmFormPage* pPage = static_cast< const FmFormPage* >( rModel.GetPage( 0 ) ); - sal_Bool bRet = sal_False; + const Size aDiscreteSize(aThumbBmp.GetSizePixel()); - if( pOut && pPage ) - { - const Rectangle aObjRect( pPage->GetAllObjBoundRect() ); - const Size aOutSizePix( pOut->GetOutputSizePixel() ); + if(aDiscreteSize.Width() && aDiscreteSize.Height()) + { + sal_uInt32 nTargetSizeX(S_THUMB); + sal_uInt32 nTargetSizeY(S_THUMB); - if( aObjRect.GetWidth() && aObjRect.GetHeight() && aOutSizePix.Width() > 2 && aOutSizePix.Height() > 2 ) - { - FmFormView aView( const_cast< FmFormModel* >( &rModel ), pOut ); - MapMode aMap( rModel.GetScaleUnit() ); - Rectangle aDrawRectPix( Point( 1, 1 ), Size( aOutSizePix.Width() - 2, aOutSizePix.Height() - 2 ) ); - const double fFactor = (double) aObjRect.GetWidth() / aObjRect.GetHeight(); - Fraction aFrac( FRound( fFactor < 1. ? aDrawRectPix.GetWidth() * fFactor : aDrawRectPix.GetWidth() ), - pOut->LogicToPixel( aObjRect.GetSize(), aMap ).Width() ); - - aMap.SetScaleX( aFrac ); - aMap.SetScaleY( aFrac ); - - const Size aDrawSize( pOut->PixelToLogic( aDrawRectPix.GetSize(), aMap ) ); - Point aOrigin( pOut->PixelToLogic( aDrawRectPix.TopLeft(), aMap ) ); - - aOrigin.X() += ( ( aDrawSize.Width() - aObjRect.GetWidth() ) >> 1 ) - aObjRect.Left(); - aOrigin.Y() += ( ( aDrawSize.Height() - aObjRect.GetHeight() ) >> 1 ) - aObjRect.Top(); - aMap.SetOrigin( aOrigin ); - - aView.SetPageVisible( sal_False ); - aView.SetBordVisible( sal_False ); - aView.SetGridVisible( sal_False ); - aView.SetHlplVisible( sal_False ); - aView.SetGlueVisible( sal_False ); - - pOut->Push(); - pOut->SetMapMode( aMap ); - aView.ShowSdrPage( const_cast< FmFormPage* >( pPage )); - aView.CompleteRedraw( pOut, - Region(Rectangle(pOut->PixelToLogic(Point()), - pOut->GetOutputSize()))); - pOut->Pop(); + if(aDiscreteSize.Width() > aDiscreteSize.Height()) + { + nTargetSizeY = (aDiscreteSize.Height() * nTargetSizeX) / aDiscreteSize.Width(); + } + else + { + nTargetSizeX = (aDiscreteSize.Width() * nTargetSizeY) / aDiscreteSize.Height(); + } - bRet = sal_True; + if(!!aThumbBmp) + { + aThumbBmp.Scale(Size(nTargetSizeX, nTargetSizeY), BMP_SCALE_BESTQUALITY); + aThumbBmp.Convert(BMP_CONVERSION_8BIT_COLORS); + bRet = true; + } + } + } } } diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 35bb9218d8fb..a7624a02fe9d 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -769,7 +769,7 @@ GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sa // ----------------------------------------------------------------------------- -sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, Bitmap& rBmp, sal_Bool ) +sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, BitmapEx& rBmp, sal_Bool ) { SgaObject* pObj = AcquireObject( nPos ); sal_Bool bRet = sal_False; @@ -841,9 +841,10 @@ sal_Bool GalleryTheme::GetGraphic( sal_uIntPtr nPos, Graphic& rGraphic, sal_Bool if( pObj ) { - Bitmap aBmp( pObj->GetThumbBmp() ); - aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); - rGraphic = aBmp; + rGraphic = pObj->GetThumbBmp(); + //Bitmap aBmp( pObj->GetThumbBmp() ); + //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); + //rGraphic = aBmp; ReleaseObject( pObj ); bRet = sal_True; } diff --git a/svx/source/tbxctrls/fontworkgallery.cxx b/svx/source/tbxctrls/fontworkgallery.cxx index b639f539882e..4fb418a40758 100644 --- a/svx/source/tbxctrls/fontworkgallery.cxx +++ b/svx/source/tbxctrls/fontworkgallery.cxx @@ -93,21 +93,18 @@ FontWorkGalleryDialog::FontWorkGalleryDialog( SdrView* pSdrView, Window* pParent maCtlFavorites.SetLineCount( nLineCount ); maCtlFavorites.SetExtraSpacing( 3 ); - initfavorites( GALLERY_THEME_FONTWORK, maFavoritesHorizontal ); - fillFavorites( GALLERY_THEME_FONTWORK, maFavoritesHorizontal ); + initFavorites( GALLERY_THEME_FONTWORK ); + fillFavorites( GALLERY_THEME_FONTWORK ); } -static void delete_bitmap( Bitmap* p ) { delete p; } - // ----------------------------------------------------------------------- FontWorkGalleryDialog::~FontWorkGalleryDialog() { - std::for_each( maFavoritesHorizontal.begin(), maFavoritesHorizontal.end(), delete_bitmap ); } // ----------------------------------------------------------------------- -void FontWorkGalleryDialog::initfavorites(sal_uInt16 nThemeId, std::vector< Bitmap * >& rFavorites) +void FontWorkGalleryDialog::initFavorites(sal_uInt16 nThemeId) { // Ueber die Gallery werden die Favoriten eingelesen sal_uIntPtr nFavCount = GalleryExplorer::GetSdrObjCount( nThemeId ); @@ -119,20 +116,32 @@ void FontWorkGalleryDialog::initfavorites(sal_uInt16 nThemeId, std::vector< Bitm FmFormModel *pModel = NULL; for( nModelPos = 0; nModelPos < nFavCount; nModelPos++ ) { - Bitmap* pThumb = new Bitmap; + BitmapEx aThumb; + + GalleryExplorer::GetSdrObj(nThemeId, nModelPos, pModel, &aThumb); - if( GalleryExplorer::GetSdrObj( nThemeId, nModelPos, pModel, pThumb ) ) + if(!!aThumb) { + static const sal_uInt32 nLen(8); + static const Color aW(COL_WHITE); + static const Color aG(0xef, 0xef, 0xef); + VirtualDevice aVDev; + const Point aNull(0, 0); + const Size aSize(aThumb.GetSizePixel()); + + aVDev.SetOutputSizePixel(aSize); + aVDev.DrawCheckered(aNull, aSize, nLen, aW, aG); + aVDev.DrawBitmapEx(aNull, aThumb); + + maFavoritesHorizontal.push_back(aVDev.GetBitmap(aNull, aSize)); } - - rFavorites.push_back( pThumb ); } // Gallery thema freigeben GalleryExplorer::EndLocking(nThemeId); } -void FontWorkGalleryDialog::fillFavorites( sal_uInt16 nThemeId, std::vector< Bitmap * >& rFavorites ) +void FontWorkGalleryDialog::fillFavorites(sal_uInt16 nThemeId) { mnThemeId = nThemeId; @@ -142,7 +151,7 @@ void FontWorkGalleryDialog::fillFavorites( sal_uInt16 nThemeId, std::vector< Bit aThumbSize.Width() -= 12; aThumbSize.Height() -= 12; - std::vector< Bitmap * >::size_type nFavCount = rFavorites.size(); + std::vector< Bitmap * >::size_type nFavCount = maFavoritesHorizontal.size(); // ValueSet Favoriten if( nFavCount > (nColCount * nLineCount) ) @@ -160,7 +169,7 @@ void FontWorkGalleryDialog::fillFavorites( sal_uInt16 nThemeId, std::vector< Bit String aStr(SVX_RES(RID_SVXFLOAT3D_FAVORITE)); aStr += sal_Unicode(' '); aStr += OUString::number((sal_Int32)nFavorite); - Image aThumbImage( *rFavorites[nFavorite-1] ); + Image aThumbImage( maFavoritesHorizontal[nFavorite-1] ); maCtlFavorites.InsertItem( (sal_uInt16)nFavorite, aThumbImage, aStr ); } } |