From 62623f7604df0437316c101803098760f4fe4651 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 28 Nov 2018 16:52:14 +0000 Subject: weld GalleryFilesPage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5fa399144fb12bb19c3b88bf99f99dad6a64e052 Reviewed-on: https://gerrit.libreoffice.org/64188 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- svx/source/gallery2/galctrl.cxx | 86 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'svx/source') diff --git a/svx/source/gallery2/galctrl.cxx b/svx/source/gallery2/galctrl.cxx index af00c3fd15e0..6e68f49cb644 100644 --- a/svx/source/gallery2/galctrl.cxx +++ b/svx/source/gallery2/galctrl.cxx @@ -51,8 +51,6 @@ GalleryPreview::GalleryPreview(vcl::Window* pParent, WinBits nStyle, GalleryThem InitSettings(); } -VCL_BUILDER_FACTORY_CONSTRUCTOR(GalleryPreview, WB_TABSTOP) - Size GalleryPreview::GetOptimalSize() const { return LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont)); @@ -257,6 +255,90 @@ void GalleryPreview::PreviewMedia( const INetURLObject& rURL ) #endif } +SvxGalleryPreview::SvxGalleryPreview() +{ +} + +void SvxGalleryPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea) +{ + CustomWidgetController::SetDrawingArea(pDrawingArea); + Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont))); + pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); + pDrawingArea->set_help_id(HID_GALLERY_WINDOW); +} + +bool SvxGalleryPreview::SetGraphic( const INetURLObject& _aURL ) +{ + bool bRet = true; + Graphic aGraphic; +#if HAVE_FEATURE_AVMEDIA + if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ), "" ) ) + { + aGraphic = BitmapEx(RID_SVXBMP_GALLERY_MEDIA); + } + else +#endif + { + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + GalleryProgress aProgress( &rFilter ); + if( rFilter.ImportGraphic( aGraphic, _aURL ) ) + bRet = false; + } + + SetGraphic( aGraphic ); + Invalidate(); + return bRet; +} + +bool SvxGalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const +{ + const Size aWinSize(GetOutputSizePixel()); + Size aNewSize(GetDrawingArea()->get_ref_device().LogicToPixel(rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode())); + bool bRet = false; + + if( aNewSize.Width() && aNewSize.Height() ) + { + // scale to fit window + const double fGrfWH = static_cast(aNewSize.Width()) / aNewSize.Height(); + const double fWinWH = static_cast(aWinSize.Width()) / aWinSize.Height(); + + if ( fGrfWH < fWinWH ) + { + aNewSize.setWidth( static_cast( aWinSize.Height() * fGrfWH ) ); + aNewSize.setHeight( aWinSize.Height() ); + } + else + { + aNewSize.setWidth( aWinSize.Width() ); + aNewSize.setHeight( static_cast( aWinSize.Width() / fGrfWH) ); + } + + const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1, + ( aWinSize.Height() - aNewSize.Height() ) >> 1 ); + + rResultRect = tools::Rectangle( aNewPos, aNewSize ); + bRet = true; + } + + return bRet; +} + +void SvxGalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) +{ + rRenderContext.SetBackground(Wallpaper(GALLERY_BG_COLOR)); + + if (ImplGetGraphicCenterRect(aGraphicObj.GetGraphic(), aPreviewRect)) + { + const Point aPos( aPreviewRect.TopLeft() ); + const Size aSize( aPreviewRect.GetSize() ); + + if( aGraphicObj.IsAnimated() ) + aGraphicObj.StartAnimation(&rRenderContext, aPos, aSize); + else + aGraphicObj.Draw(&rRenderContext, aPos, aSize); + } +} + static void drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rPos, const Size& rSize) { -- cgit