diff options
-rw-r--r-- | include/vcl/button.hxx | 7 | ||||
-rw-r--r-- | include/vcl/toolkit/button.hxx | 2 | ||||
-rw-r--r-- | vcl/source/control/button.cxx | 142 |
3 files changed, 62 insertions, 89 deletions
diff --git a/include/vcl/button.hxx b/include/vcl/button.hxx index 58cb4c1f81fd..6faf8dadc5b7 100644 --- a/include/vcl/button.hxx +++ b/include/vcl/button.hxx @@ -61,6 +61,13 @@ public: protected: explicit Button( WindowType nType ); + // for drawing RadioButton or CheckButton that has Text and/or Image + SAL_DLLPRIVATE void ImplDrawRadioCheck(OutputDevice* pDev, WinBits nWinStyle, DrawFlags nDrawFlags, + const Point& rPos, const Size& rSize, + const Size& rImageSize, tools::Rectangle& rStateRect, + tools::Rectangle& rMouseRect); + SAL_DLLPRIVATE tools::Long ImplGetImageToTextDistance() const; + public: virtual ~Button() override; virtual void dispose() override; diff --git a/include/vcl/toolkit/button.hxx b/include/vcl/toolkit/button.hxx index 58000cf7b705..2ff1bdf40c6c 100644 --- a/include/vcl/toolkit/button.hxx +++ b/include/vcl/toolkit/button.hxx @@ -95,7 +95,6 @@ private: const Size& rImageSize, tools::Rectangle& rStateRect, tools::Rectangle& rMouseRect ); SAL_DLLPRIVATE void ImplDrawCheckBox(vcl::RenderContext& rRenderContext ); - SAL_DLLPRIVATE tools::Long ImplGetImageToTextDistance() const; SAL_DLLPRIVATE Size ImplGetCheckImageSize() const; CheckBox(const CheckBox &) = delete; @@ -191,7 +190,6 @@ private: SAL_DLLPRIVATE void ImplDrawRadioButton(vcl::RenderContext& rRenderContext ); SAL_DLLPRIVATE void ImplUncheckAllOther(); SAL_DLLPRIVATE Size ImplGetRadioImageSize() const; - SAL_DLLPRIVATE tools::Long ImplGetImageToTextDistance() const; RadioButton(const RadioButton &) = delete; RadioButton& operator= (const RadioButton &) = delete; diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index 77d28a6ead49..6f0da1194208 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -1980,6 +1980,54 @@ void RadioButton::ImplDrawRadioButtonState(vcl::RenderContext& rRenderContext) } } +// for drawing RadioButton or CheckButton that has Text and/or Image +void Button::ImplDrawRadioCheck(OutputDevice* pDev, WinBits nWinStyle, DrawFlags nDrawFlags, + const Point& rPos, const Size& rSize, + const Size& rImageSize, tools::Rectangle& rStateRect, + tools::Rectangle& rMouseRect) +{ + DrawTextFlags nTextStyle = Button::ImplGetTextStyle( nWinStyle, nDrawFlags ); + + const tools::Long nImageSep = GetDrawPixel( pDev, ImplGetImageToTextDistance() ); + Size aSize( rSize ); + Point aPos( rPos ); + aPos.AdjustX(rImageSize.Width() + nImageSep ); + aSize.AdjustWidth( -(rImageSize.Width() + nImageSep) ); + + // if the text rect height is smaller than the height of the image + // then for single lines the default should be centered text + if( (nWinStyle & (WB_TOP|WB_VCENTER|WB_BOTTOM)) == 0 && + (rImageSize.Height() > rSize.Height() || ! (nWinStyle & WB_WORDBREAK) ) ) + { + nTextStyle &= ~DrawTextFlags(DrawTextFlags::Top|DrawTextFlags::Bottom); + nTextStyle |= DrawTextFlags::VCenter; + aSize.setHeight( rImageSize.Height() ); + } + + ImplDrawAlignedImage( pDev, aPos, aSize, 1, nTextStyle ); + + rMouseRect = tools::Rectangle( aPos, aSize ); + rMouseRect.SetLeft( rPos.X() ); + + rStateRect.SetLeft( rPos.X() ); + rStateRect.SetTop( rMouseRect.Top() ); + + if ( aSize.Height() > rImageSize.Height() ) + rStateRect.AdjustTop(( aSize.Height() - rImageSize.Height() ) / 2 ); + else + { + rStateRect.AdjustTop( -(( rImageSize.Height() - aSize.Height() ) / 2) ); + if( rStateRect.Top() < 0 ) + rStateRect.SetTop( 0 ); + } + + rStateRect.SetRight( rStateRect.Left()+rImageSize.Width()-1 ); + rStateRect.SetBottom( rStateRect.Top()+rImageSize.Height()-1 ); + + if ( rStateRect.Bottom() > rMouseRect.Bottom() ) + rMouseRect.SetBottom( rStateRect.Bottom() ); +} + void RadioButton::ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags, const Point& rPos, const Size& rSize, const Size& rImageSize, tools::Rectangle& rStateRect, @@ -1996,46 +2044,9 @@ void RadioButton::ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags, { if (!aText.isEmpty() || HasImage()) { - DrawTextFlags nTextStyle = Button::ImplGetTextStyle( nWinStyle, nDrawFlags ); - - const tools::Long nImageSep = GetDrawPixel( pDev, ImplGetImageToTextDistance() ); - Size aSize( rSize ); - Point aPos( rPos ); - aPos.AdjustX(rImageSize.Width() + nImageSep ); - aSize.AdjustWidth( -(rImageSize.Width() + nImageSep) ); - - // if the text rect height is smaller than the height of the image - // then for single lines the default should be centered text - if( (nWinStyle & (WB_TOP|WB_VCENTER|WB_BOTTOM)) == 0 && - (rImageSize.Height() > rSize.Height() || ! (nWinStyle & WB_WORDBREAK) ) ) - { - nTextStyle &= ~DrawTextFlags(DrawTextFlags::Top|DrawTextFlags::Bottom); - nTextStyle |= DrawTextFlags::VCenter; - aSize.setHeight( rImageSize.Height() ); - } - - ImplDrawAlignedImage( pDev, aPos, aSize, 1, nTextStyle ); - - rMouseRect = tools::Rectangle(aPos, aSize); - rMouseRect.SetLeft(rPos.X()); - - rStateRect.SetLeft( rPos.X() ); - rStateRect.SetTop( rMouseRect.Top() ); - - if ( aSize.Height() > rImageSize.Height() ) - rStateRect.AdjustTop(( aSize.Height() - rImageSize.Height() ) / 2 ); - else - { - rStateRect.AdjustTop( -(( rImageSize.Height() - aSize.Height() ) / 2) ); - if( rStateRect.Top() < 0 ) - rStateRect.SetTop( 0 ); - } - - rStateRect.SetRight( rStateRect.Left() + rImageSize.Width()-1 ); - rStateRect.SetBottom( rStateRect.Top() + rImageSize.Height()-1 ); - - if ( rStateRect.Bottom() > rMouseRect.Bottom() ) - rMouseRect.SetBottom( rStateRect.Bottom() ); + Button::ImplDrawRadioCheck(pDev, nWinStyle, nDrawFlags, + rPos, rSize, rImageSize, + rStateRect, rMouseRect); } else { @@ -2650,7 +2661,7 @@ void RadioButton::Check( bool bCheck ) Toggle(); } -tools::Long RadioButton::ImplGetImageToTextDistance() const +tools::Long Button::ImplGetImageToTextDistance() const { // 4 pixels, but take zoom into account, so the text doesn't "jump" relative to surrounding elements, // which might have been aligned with the text of the check box @@ -3018,45 +3029,9 @@ void CheckBox::ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags, if (!aText.isEmpty() || HasImage()) { - DrawTextFlags nTextStyle = Button::ImplGetTextStyle( nWinStyle, nDrawFlags ); - - const tools::Long nImageSep = GetDrawPixel( pDev, ImplGetImageToTextDistance() ); - Size aSize( rSize ); - Point aPos( rPos ); - aPos.AdjustX(rImageSize.Width() + nImageSep ); - aSize.AdjustWidth( -(rImageSize.Width() + nImageSep) ); - - // if the text rect height is smaller than the height of the image - // then for single lines the default should be centered text - if( (nWinStyle & (WB_TOP|WB_VCENTER|WB_BOTTOM)) == 0 && - (rImageSize.Height() > rSize.Height() || ! (nWinStyle & WB_WORDBREAK) ) ) - { - nTextStyle &= ~DrawTextFlags(DrawTextFlags::Top|DrawTextFlags::Bottom); - nTextStyle |= DrawTextFlags::VCenter; - aSize.setHeight( rImageSize.Height() ); - } - - ImplDrawAlignedImage( pDev, aPos, aSize, 1, nTextStyle ); - - rMouseRect = tools::Rectangle( aPos, aSize ); - rMouseRect.SetLeft( rPos.X() ); - - rStateRect.SetLeft( rPos.X() ); - rStateRect.SetTop( rMouseRect.Top() ); - - if ( aSize.Height() > rImageSize.Height() ) - rStateRect.AdjustTop(( aSize.Height() - rImageSize.Height() ) / 2 ); - else - { - rStateRect.AdjustTop( -(( rImageSize.Height() - aSize.Height() ) / 2) ); - if( rStateRect.Top() < 0 ) - rStateRect.SetTop( 0 ); - } - - rStateRect.SetRight( rStateRect.Left()+rImageSize.Width()-1 ); - rStateRect.SetBottom( rStateRect.Top()+rImageSize.Height()-1 ); - if ( rStateRect.Bottom() > rMouseRect.Bottom() ) - rMouseRect.SetBottom( rStateRect.Bottom() ); + Button::ImplDrawRadioCheck(pDev, nWinStyle, nDrawFlags, + rPos, rSize, rImageSize, + rStateRect, rMouseRect); } else { @@ -3499,13 +3474,6 @@ void CheckBox::EnableTriState( bool bTriState ) } } -tools::Long CheckBox::ImplGetImageToTextDistance() const -{ - // 4 pixels, but take zoom into account, so the text doesn't "jump" relative to surrounding elements, - // which might have been aligned with the text of the check box - return CalcZoom( 4 ); -} - Size CheckBox::ImplGetCheckImageSize() const { Size aSize; |