Kaydet (Commit) e8bcffc7 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

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
üst c8a795c9
...@@ -137,9 +137,10 @@ public: ...@@ -137,9 +137,10 @@ public:
void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; } void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
void CalcOptimalExtraUserWidth();
protected: 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; virtual void Select() SAL_OVERRIDE;
private: private:
...@@ -337,6 +338,7 @@ SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent, ...@@ -337,6 +338,7 @@ SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
SetOptimalSize(); SetOptimalSize();
EnableAutocomplete( true ); EnableAutocomplete( true );
EnableUserDraw( true ); EnableUserDraw( true );
AddEventListener(LINK(this, SvxStyleBox_Impl, CalcOptimalExtraUserWidth));
SetUserItemSize( Size( 0, ITEM_HEIGHT ) ); SetUserItemSize( Size( 0, ITEM_HEIGHT ) );
} }
...@@ -347,10 +349,13 @@ SvxStyleBox_Impl::~SvxStyleBox_Impl() ...@@ -347,10 +349,13 @@ SvxStyleBox_Impl::~SvxStyleBox_Impl()
void SvxStyleBox_Impl::dispose() 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(); m_pButtons[i].disposeAndClear();
} }
ComboBox::dispose(); ComboBox::dispose();
} }
...@@ -789,8 +794,12 @@ void SvxStyleBox_Impl::UserDraw( const UserDrawEvent& rUDEvt ) ...@@ -789,8 +794,12 @@ void SvxStyleBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
DrawEntry( rUDEvt, false, false ); 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; long nMaxNormalFontWidth = 0;
sal_Int32 nEntryCount = GetEntryCount(); sal_Int32 nEntryCount = GetEntryCount();
for (sal_Int32 i = 0; i < nEntryCount; ++i) for (sal_Int32 i = 0; i < nEntryCount; ++i)
...@@ -2309,8 +2318,6 @@ void SvxStyleToolBoxControl::FillStyleBox() ...@@ -2309,8 +2318,6 @@ void SvxStyleToolBoxControl::FillStyleBox()
sal_uInt16 nLines = static_cast<sal_uInt16>( sal_uInt16 nLines = static_cast<sal_uInt16>(
std::min( pBox->GetEntryCount(), static_cast<sal_Int32>(MAX_STYLES_ENTRIES))); std::min( pBox->GetEntryCount(), static_cast<sal_Int32>(MAX_STYLES_ENTRIES)));
pBox->SetDropDownLineCount( nLines ); pBox->SetDropDownLineCount( nLines );
pBox->CalcOptimalExtraUserWidth();
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment