[Libreoffice-commits] core.git: Branch 'feature/fixes11' - svx/source
Jan Holesovsky
kendy at collabora.com
Wed Oct 7 09:14:50 PDT 2015
svx/source/tbxctrls/tbcontrl.cxx | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
New commits:
commit 79f087ce394a0ae5eaeb8f7a226754b91e990ee7
Author: Jan Holesovsky <kendy at collabora.com>
Date: Wed Oct 7 17:37:22 2015 +0200
SvxStyleBox_Impl::CalcOptimalExtraUserWidth() is a (very) expensive operation.
Don't call it ~20 times on startup, instead call it once when the user
actually opens the styles dropdown.
Change-Id: I7bb28d0739bf917d23041f384f60a39a7ed5cbea
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 5e15ccd6..0c756d6 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -136,9 +136,10 @@ public:
void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
- void CalcOptimalExtraUserWidth();
-
protected:
+ /// Calculate the optimal width of the dropdown. Very expensive operation, triggers lots of font measurement.
+ DECL_DLLPRIVATE_LINK_TYPED(CalcOptimalExtraUserWidth, VclWindowEvent&, void);
+
virtual void Select() SAL_OVERRIDE;
private:
@@ -338,6 +339,7 @@ SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
SetOptimalSize();
EnableAutocomplete( true );
EnableUserDraw( true );
+ AddEventListener(LINK(this, SvxStyleBox_Impl, CalcOptimalExtraUserWidth));
SetUserItemSize( Size( 0, ITEM_HEIGHT ) );
}
@@ -348,10 +350,13 @@ SvxStyleBox_Impl::~SvxStyleBox_Impl()
void SvxStyleBox_Impl::dispose()
{
- for(int i = 0; i < MAX_STYLES_ENTRIES; i++)
+ RemoveEventListener(LINK(this, SvxStyleBox_Impl, CalcOptimalExtraUserWidth));
+
+ for (int i = 0; i < MAX_STYLES_ENTRIES; i++)
{
m_pButtons[i].disposeAndClear();
}
+
ComboBox::dispose();
}
@@ -792,8 +797,12 @@ void SvxStyleBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
DrawEntry( rUDEvt, false, false );
}
-void SvxStyleBox_Impl::CalcOptimalExtraUserWidth()
+IMPL_LINK_TYPED(SvxStyleBox_Impl, CalcOptimalExtraUserWidth, VclWindowEvent&, event, void)
{
+ // perform the calculation only when we are opening the dropdown
+ if (event.GetId() != VCLEVENT_DROPDOWN_PRE_OPEN)
+ return;
+
long nMaxNormalFontWidth = 0;
sal_Int32 nEntryCount = GetEntryCount();
for (sal_Int32 i = 0; i < nEntryCount; ++i)
@@ -2308,8 +2317,6 @@ void SvxStyleToolBoxControl::FillStyleBox()
sal_uInt16 nLines = static_cast<sal_uInt16>(
std::min( pBox->GetEntryCount(), static_cast<sal_Int32>(MAX_STYLES_ENTRIES)));
pBox->SetDropDownLineCount( nLines );
-
- pBox->CalcOptimalExtraUserWidth();
}
}
}
More information about the Libreoffice-commits
mailing list