From eee6441bc9eea847ba4b338baf99ab47913fcd61 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Mon, 29 Jun 2020 07:01:26 +0200 Subject: tdf#134054 toolbox: respect drop-down arrow rect When centering the text and icon on the button, the code didn't take the drop-down arrow rect width into account, resulting in an overlapped arrow. This is especially visible, if the drop-down is shown and the button is wrongly highlighted. There is supposed to be some vertical mode, which I couldn't find in the GUI, so this just adapts the width in horizontal mode. Change-Id: I194780dc32db610041ad0ee45a425e1026c7c4e3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97358 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski (cherry picked from commit 8565546ce6a04f6f243f4f60d2693b148dca5a77) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97688 Reviewed-by: Thorsten Behrens --- vcl/source/window/toolbox.cxx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'vcl') diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index 77df4fddcacb..df5aadf89243 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -2641,13 +2641,11 @@ void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::si long nBtnWidth = aBtnSize.Width()-SMALLBUTTON_HSIZE; long nBtnHeight = aBtnSize.Height()-SMALLBUTTON_VSIZE; Size aImageSize; - Size aTxtSize; - if ( bText ) - { - aTxtSize.setWidth( GetCtrlTextWidth( pItem->maText ) ); - aTxtSize.setHeight( GetTextHeight() ); - } + const bool bDropDown = (pItem->mnBits & ToolBoxItemBits::DROPDOWN) == ToolBoxItemBits::DROPDOWN; + tools::Rectangle aDropDownRect; + if (bDropDown) + aDropDownRect = pItem->GetDropDownRect(mbHorz); if ( bImage ) { @@ -2678,7 +2676,7 @@ void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::si } else { - nImageOffX += (nBtnWidth-aImageSize.Width())/2; + nImageOffX += (nBtnWidth-(bDropDown ? aDropDownRect.getWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X-aImageSize.Width())/2; if ( meTextPosition == ToolBoxTextPosition::Right ) nImageOffY += (nBtnHeight-aImageSize.Height())/2; } @@ -2705,6 +2703,7 @@ void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::si bool bRotate = false; if ( bText ) { + const Size aTxtSize(GetCtrlTextWidth(pItem->maText), GetTextHeight()); long nTextOffX = nOffX; long nTextOffY = nOffY; @@ -2742,7 +2741,7 @@ void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::si else { // center horizontally - nTextOffX += (nBtnWidth-aTxtSize.Width() - TB_IMAGETEXTOFFSET)/2; + nTextOffX += (nBtnWidth-(bDropDown ? aDropDownRect.getWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X-aTxtSize.Width() - TB_IMAGETEXTOFFSET)/2; // set vertical position nTextOffY += nBtnHeight - aTxtSize.Height(); } @@ -2768,9 +2767,8 @@ void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::si } // paint optional drop down arrow - if ( pItem->mnBits & ToolBoxItemBits::DROPDOWN ) + if (bDropDown) { - tools::Rectangle aDropDownRect( pItem->GetDropDownRect( mbHorz ) ); bool bSetColor = true; if ( !pItem->mbEnabled || !IsEnabled() ) { -- cgit v1.2.3