summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-07-23 11:29:40 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2024-07-24 05:45:13 +0200
commit7b645998e691c3a6279f5e5a7452981d77d29e20 (patch)
treede869fd04af83932e8f5ad7388c66ea2d8ed16ae /vcl
parent14e1f10793d1ec994ab70f928feeecdb384a307e (diff)
tdf#161501 icon choice ctrl: Use a single member for entry rect
`SvxIconChoiceCtrlEntry` has two members for maintaining the bound rect: * `aRect`, used almost everywhere * `aGridRect`, used very rarely `SvxIconChoiceCtrl_Impl::FindBoundingRect` calculates a new bounding rect and assigns it to `pEntry->aGridRect`, then calls `SvxIconChoiceCtrl_Impl::Center`, which at first assigns the same value to `pEntry->aRect`, so both are the same there. The other place using the `aGridRect` member is `SvxIconChoiceCtrl_Impl::CalcMaxTextRect` where it's used as a fallback if `aRect` has not been assigned a proper value yet. However, since `aGridRect` is never assigned a useful value apart from `aRect`, there doesn't seem to be much value in doing that, so use `aRect` there, too, and drop the `aGridRect` member altogether and assign directly to `aRect` in `SvxIconChoiceCtrl_Impl::FindBoundingRect` instead. Instead of falling back to `aGridRect` in `SvxIconChoiceCtrl_Impl::CalcMaxTextRect`, add an assert that `aRect` is valid instead, which never triggered in my tests with the "Insert" -> "Hyperlink" and "Format" -> "Page Style" dialogs, so should presumably be fine already. Change-Id: I99f368672523279f530b937a73c3afb655f7853e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170894 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/imivctl1.cxx13
1 files changed, 4 insertions, 9 deletions
diff --git a/vcl/source/control/imivctl1.cxx b/vcl/source/control/imivctl1.cxx
index 8046dc54caf8..f5f1767ba019 100644
--- a/vcl/source/control/imivctl1.cxx
+++ b/vcl/source/control/imivctl1.cxx
@@ -1264,7 +1264,7 @@ void SvxIconChoiceCtrl_Impl::FindBoundingRect( SvxIconChoiceCtrlEntry* pEntry )
Point aPos(pGridMap->GetGridRect(pGridMap->GetUnoccupiedGrid()).TopLeft());
tools::Rectangle aGridRect(aPos, Size(nGridDX, nGridDY));
- pEntry->aGridRect = aGridRect;
+ pEntry->aRect = aGridRect;
Center( pEntry );
AdjustVirtSize( pEntry->aRect );
pGridMap->OccupyGrids( pEntry );
@@ -1574,12 +1574,8 @@ void SvxIconChoiceCtrl_Impl::SetGrid( const Size& rSize )
tools::Rectangle SvxIconChoiceCtrl_Impl::CalcMaxTextRect( const SvxIconChoiceCtrlEntry* pEntry ) const
{
- tools::Rectangle aBoundRect;
- // avoid infinite recursion: don't calculate the bounding rectangle here
- if( IsBoundingRectValid( pEntry->aRect ) )
- aBoundRect = pEntry->aRect;
- else
- aBoundRect = pEntry->aGridRect;
+ assert(IsBoundingRectValid(pEntry->aRect) && "Bounding rect for entry hasn't been calculated yet.");
+ tools::Rectangle aBoundRect = pEntry->aRect;
tools::Rectangle aBmpRect( const_cast<SvxIconChoiceCtrl_Impl*>(this)->CalcBmpRect(
const_cast<SvxIconChoiceCtrlEntry*>(pEntry) ) );
@@ -1641,12 +1637,11 @@ void SvxIconChoiceCtrl_Impl::SetDefaultTextSize()
void SvxIconChoiceCtrl_Impl::Center( SvxIconChoiceCtrlEntry* pEntry ) const
{
- pEntry->aRect = pEntry->aGridRect;
Size aSize( CalcBoundingSize() );
if( nWinBits & WB_ICON )
{
// center horizontally
- tools::Long nBorder = pEntry->aGridRect.GetWidth() - aSize.Width();
+ tools::Long nBorder = pEntry->aRect.GetWidth() - aSize.Width();
pEntry->aRect.AdjustLeft(nBorder / 2 );
pEntry->aRect.AdjustRight( -(nBorder / 2) );
}