diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-03-01 17:04:54 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-03-03 10:07:58 +0100 |
commit | 9bebf9c676f88c67c04ca4f96d88ee2543c5b9e9 (patch) | |
tree | 6e9509300443160088b79ee72224fc9365128aa8 /extensions | |
parent | f34e8ab3e7e7138c2ffe4bd61516f43a2d297d3a (diff) |
move BubbleWindow to vcl
Change-Id: I2481a9882dc66337b35b758fb4f73978df5af541
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111797
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/source/update/ui/updatecheckui.cxx | 235 |
1 files changed, 1 insertions, 234 deletions
diff --git a/extensions/source/update/ui/updatecheckui.cxx b/extensions/source/update/ui/updatecheckui.cxx index 3a177327d256e..c73db90d4a4fe 100644 --- a/extensions/source/update/ui/updatecheckui.cxx +++ b/extensions/source/update/ui/updatecheckui.cxx @@ -32,7 +32,7 @@ #include <unotools/resmgr.hxx> #include <vcl/image.hxx> #include <vcl/window.hxx> -#include <vcl/floatwin.hxx> +#include <vcl/bubblewindow.hxx> #include <vcl/timer.hxx> #include <vcl/idle.hxx> #include <vcl/lineinfo.hxx> @@ -76,37 +76,6 @@ Image GetMenuBarIcon( MenuBar const * pMBar ) return Image(StockImage::Yes, sResID); } -class BubbleWindow : public FloatingWindow -{ - Point maTipPos; - vcl::Region maBounds; - tools::Polygon maRectPoly; - tools::Polygon maTriPoly; - OUString maBubbleTitle; - OUString maBubbleText; - Image maBubbleImage; - Size maMaxTextSize; - tools::Rectangle maTitleRect; - tools::Rectangle maTextRect; - tools::Long mnTipOffset; - -private: - void RecalcTextRects(); - -public: - BubbleWindow( vcl::Window* pParent, const OUString& rTitle, - const OUString& rText, const Image& rImage ); - - virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; - virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; - void Resize() override; - void Show( bool bVisible = true ); - void SetTipPosPixel( const Point& rTipPos ) { maTipPos = rTipPos; } - void SetTitleAndText( const OUString& rTitle, const OUString& rText, - const Image& rImage ); -}; - - class UpdateCheckUI : public ::cppu::WeakImplHelper < lang::XServiceInfo, document::XDocumentEventListener, beans::XPropertySet > { @@ -673,208 +642,6 @@ IMPL_LINK( UpdateCheckUI, ApplicationEventHdl, VclSimpleEvent&, rEvent, void) } } - -#define TIP_HEIGHT 15 -#define TIP_WIDTH 7 -#define TIP_RIGHT_OFFSET 18 -#define BUBBLE_BORDER 10 -#define TEXT_MAX_WIDTH 300 -#define TEXT_MAX_HEIGHT 200 - - -BubbleWindow::BubbleWindow( vcl::Window* pParent, const OUString& rTitle, - const OUString& rText, const Image& rImage ) - : FloatingWindow( pParent, WB_SYSTEMWINDOW - | WB_OWNERDRAWDECORATION - | WB_NOBORDER - ) - , maBubbleTitle( rTitle ) - , maBubbleText( rText ) - , maBubbleImage( rImage ) - , maMaxTextSize( TEXT_MAX_WIDTH, TEXT_MAX_HEIGHT ) - , mnTipOffset( 0 ) -{ - SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetHelpColor() ) ); -} - -void BubbleWindow::Resize() -{ - SolarMutexGuard aGuard; - - FloatingWindow::Resize(); - - Size aSize = GetSizePixel(); - - if ( ( aSize.Height() < 20 ) || ( aSize.Width() < 60 ) ) - return; - - tools::Rectangle aRect( 0, TIP_HEIGHT, aSize.Width(), aSize.Height() - TIP_HEIGHT ); - maRectPoly = tools::Polygon( aRect, 6, 6 ); - vcl::Region aRegion( maRectPoly ); - tools::Long nTipOffset = aSize.Width() - TIP_RIGHT_OFFSET + mnTipOffset; - - Point aPointArr[4]; - aPointArr[0] = Point( nTipOffset, TIP_HEIGHT ); - aPointArr[1] = Point( nTipOffset, 0 ); - aPointArr[2] = Point( nTipOffset + TIP_WIDTH , TIP_HEIGHT ); - aPointArr[3] = Point( nTipOffset, TIP_HEIGHT ); - maTriPoly = tools::Polygon( 4, aPointArr ); - vcl::Region aTriRegion( maTriPoly ); - - aRegion.Union( aTriRegion); - maBounds = aRegion; - - SetWindowRegionPixel( maBounds ); -} - - -void BubbleWindow::SetTitleAndText( const OUString& rTitle, - const OUString& rText, - const Image& rImage ) -{ - maBubbleTitle = rTitle; - maBubbleText = rText; - maBubbleImage = rImage; - - Resize(); -} - - -void BubbleWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& /*rRect*/) -{ - SolarMutexGuard aGuard; - - LineInfo aThickLine( LineStyle::Solid, 2 ); - - DrawPolyLine( maRectPoly, aThickLine ); - DrawPolyLine( maTriPoly ); - - Color aOldLine = GetLineColor(); - Size aSize = GetSizePixel(); - tools::Long nTipOffset = aSize.Width() - TIP_RIGHT_OFFSET + mnTipOffset; - - SetLineColor( GetSettings().GetStyleSettings().GetHelpColor() ); - DrawLine( Point( nTipOffset+2, TIP_HEIGHT ), - Point( nTipOffset + TIP_WIDTH -1 , TIP_HEIGHT ), - aThickLine ); - SetLineColor( aOldLine ); - - Size aImgSize = maBubbleImage.GetSizePixel(); - - DrawImage( Point( BUBBLE_BORDER, BUBBLE_BORDER + TIP_HEIGHT ), maBubbleImage ); - - vcl::Font aOldFont = GetFont(); - vcl::Font aBoldFont = aOldFont; - aBoldFont.SetWeight( WEIGHT_BOLD ); - - SetFont( aBoldFont ); - tools::Rectangle aTitleRect = maTitleRect; - aTitleRect.Move( aImgSize.Width(), 0 ); - DrawText( aTitleRect, maBubbleTitle, DrawTextFlags::MultiLine | DrawTextFlags::WordBreak ); - - SetFont( aOldFont ); - tools::Rectangle aTextRect = maTextRect; - aTextRect.Move( aImgSize.Width(), 0 ); - DrawText( aTextRect, maBubbleText, DrawTextFlags::MultiLine | DrawTextFlags::WordBreak ); -} - - -void BubbleWindow::MouseButtonDown( const MouseEvent& ) -{ - Show( false ); -} - - -void BubbleWindow::Show( bool bVisible ) -{ - SolarMutexGuard aGuard; - - if ( !bVisible ) - { - FloatingWindow::Show( bVisible ); - return; - } - - // don't show bubbles without a text - if ( ( maBubbleTitle.isEmpty() ) && ( maBubbleText.isEmpty() ) ) - return; - - Size aWindowSize = GetSizePixel(); - - Size aImgSize = maBubbleImage.GetSizePixel(); - - RecalcTextRects(); - - aWindowSize.setHeight( maTitleRect.GetHeight() * 7 / 4+ maTextRect.GetHeight() + - 3 * BUBBLE_BORDER + TIP_HEIGHT ); - - if ( maTitleRect.GetWidth() > maTextRect.GetWidth() ) - aWindowSize.setWidth( maTitleRect.GetWidth() ); - else - aWindowSize.setWidth( maTextRect.GetWidth() ); - - aWindowSize.setWidth( aWindowSize.Width() + 3 * BUBBLE_BORDER + aImgSize.Width() ); - - if ( aWindowSize.Height() < aImgSize.Height() + TIP_HEIGHT + 2 * BUBBLE_BORDER ) - aWindowSize.setHeight( aImgSize.Height() + TIP_HEIGHT + 2 * BUBBLE_BORDER ); - - Point aPos; - aPos.setX( maTipPos.X() - aWindowSize.Width() + TIP_RIGHT_OFFSET ); - aPos.setY( maTipPos.Y() ); - Point aScreenPos = GetParent()->OutputToAbsoluteScreenPixel( aPos ); - if ( aScreenPos.X() < 0 ) - { - mnTipOffset = aScreenPos.X(); - aPos.AdjustX( -mnTipOffset ); - } - SetPosSizePixel( aPos, aWindowSize ); - - FloatingWindow::Show( bVisible, ShowFlags::NoActivate ); -} - - -void BubbleWindow::RecalcTextRects() -{ - Size aTotalSize; - bool bFinished = false; - vcl::Font aOldFont = GetFont(); - vcl::Font aBoldFont = aOldFont; - - aBoldFont.SetWeight( WEIGHT_BOLD ); - - while ( !bFinished ) - { - SetFont( aBoldFont ); - - maTitleRect = GetTextRect( tools::Rectangle( Point( 0, 0 ), maMaxTextSize ), - maBubbleTitle, - DrawTextFlags::MultiLine | DrawTextFlags::WordBreak ); - - SetFont( aOldFont ); - maTextRect = GetTextRect( tools::Rectangle( Point( 0, 0 ), maMaxTextSize ), - maBubbleText, - DrawTextFlags::MultiLine | DrawTextFlags::WordBreak ); - - if ( maTextRect.GetHeight() < 10 ) - maTextRect.setHeight( 10 ); - - aTotalSize.setHeight( maTitleRect.GetHeight() + - aBoldFont.GetFontHeight() * 3 / 4 + - maTextRect.GetHeight() + - 3 * BUBBLE_BORDER + TIP_HEIGHT ); - if ( aTotalSize.Height() > maMaxTextSize.Height() ) - { - maMaxTextSize.setWidth( maMaxTextSize.Width() * 3 / 2 ); - maMaxTextSize.setHeight( maMaxTextSize.Height() * 3 / 2 ); - } - else - bFinished = true; - } - maTitleRect.Move( 2*BUBBLE_BORDER, BUBBLE_BORDER + TIP_HEIGHT ); - maTextRect.Move( 2*BUBBLE_BORDER, BUBBLE_BORDER + TIP_HEIGHT + maTitleRect.GetHeight() + aBoldFont.GetFontHeight() * 3 / 4 ); -} - - } // anonymous namespace |