diff options
author | Jan Holesovsky <kendy@collabora.com> | 2015-10-07 17:37:22 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-12-03 12:21:16 +0000 |
commit | bf994b210dc8166486cca622589046427bd62758 (patch) | |
tree | c65e1c714849e6a411c272b74d95688a773cc69f /svx | |
parent | a18fed7db4f4a5cd85b08dce516a38e874758be6 (diff) |
Resolves: rhbz#1277445 CalcOptimalExtraUserWidth() is slow
its a (very) expensive operation.
Don't call it ~20 times on startup, instead call it once when the user
actually opens the styles dropdown.
(cherry picked from commit e8bcffc787939294b74492527b60fe309490d5e4)
Change-Id: I7bb28d0739bf917d23041f384f60a39a7ed5cbea
Reviewed-on: https://gerrit.libreoffice.org/20349
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index b6e748749921..dd81b425cae2 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( CalcOptimalExtraUserWidth, VclWindowEvent* ); + 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( SvxStyleBox_Impl, CalcOptimalExtraUserWidth, VclWindowEvent*, event ) { + // perform the calculation only when we are opening the dropdown + if (event->GetId() != VCLEVENT_DROPDOWN_PRE_OPEN) + return 0; + long nMaxNormalFontWidth = 0; sal_Int32 nEntryCount = GetEntryCount(); for (sal_Int32 i = 0; i < nEntryCount; ++i) @@ -829,6 +838,7 @@ void SvxStyleBox_Impl::CalcOptimalExtraUserWidth() } SetUserItemSize(Size(nMaxUserDrawFontWidth - nMaxNormalFontWidth, ITEM_HEIGHT)); + return 0; } // test is the color between Font- and background-color to be identify @@ -2309,8 +2319,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(); } } } |