diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2017-06-08 19:56:28 +0200 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2017-06-09 16:29:40 +0200 |
commit | f0821f9a347c7752a3c741c3451a2f1630173720 (patch) | |
tree | cbc76e9d40d1490af1595556b2c6f877a90f3eb8 /vcl/source/window/status.cxx | |
parent | c8e3fea4996436d1fd608cf5ef0fdc18f5a8fd7f (diff) |
Cache text layout of statusbar items
Extend lifecycle of SalLayout created by the output device.
A layout is stored for each status bar item and used as a cache.
The layout may be updated through output device method parameters.
This way it's no longer necessary to calculate the layout again and again when
painting the status bar item multiple times, provided that its text does not
change.
Change-Id: I6494c2d6b676e8f4fdda2cde6165ff0755fd4fa2
Reviewed-on: https://gerrit.libreoffice.org/38578
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Tested-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'vcl/source/window/status.cxx')
-rw-r--r-- | vcl/source/window/status.cxx | 80 |
1 files changed, 61 insertions, 19 deletions
diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx index aa5c1f59f6e6..c4f44d8e1a4b 100644 --- a/vcl/source/window/status.cxx +++ b/vcl/source/window/status.cxx @@ -32,6 +32,8 @@ #include <svdata.hxx> #include <window.h> +#include "sallayout.hxx" + #define STATUSBAR_OFFSET_X STATUSBAR_OFFSET #define STATUSBAR_OFFSET_Y 2 #define STATUSBAR_OFFSET_TEXTY 3 @@ -59,20 +61,21 @@ StatusBar::ImplData::ImplData() struct ImplStatusItem { - sal_uInt16 mnId; - StatusBarItemBits mnBits; - long mnWidth; - long mnOffset; - long mnExtraWidth; - long mnX; - OUString maText; - OUString maHelpText; - OUString maQuickHelpText; - OString maHelpId; - void* mpUserData; - bool mbVisible; - OUString maAccessibleName; - OUString maCommand; + sal_uInt16 mnId; + StatusBarItemBits mnBits; + long mnWidth; + long mnOffset; + long mnExtraWidth; + long mnX; + OUString maText; + OUString maHelpText; + OUString maQuickHelpText; + OString maHelpId; + void* mpUserData; + bool mbVisible; + OUString maAccessibleName; + OUString maCommand; + std::unique_ptr<SalLayout> mxLayoutCache; }; inline long ImplCalcProgressWidth( sal_uInt16 nMax, long nSize ) @@ -369,20 +372,38 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen rRenderContext.SetClipRegion(aRegion); } - // print text - Size aTextSize(rRenderContext.GetTextWidth(pItem->maText), rRenderContext.GetTextHeight()); + SalLayout* pLayoutCache = pItem->mxLayoutCache.get(); + Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,&pLayoutCache), rRenderContext.GetTextHeight()); + + // update cache if necessary + if(pLayoutCache != pItem->mxLayoutCache.get() ) + pItem->mxLayoutCache.reset(pLayoutCache); + Point aTextPos = ImplGetItemTextPos(aTextRectSize, aTextSize, pItem->mnBits); + if (bOffScreen) { - mpImplData->mpVirDev->DrawText(aTextPos, pItem->maText); + mpImplData->mpVirDev->DrawText( + aTextPos, + pItem->maText, + 0, -1, nullptr, nullptr, + &pLayoutCache ); } else { aTextPos.X() += aTextRect.Left(); aTextPos.Y() += aTextRect.Top(); - rRenderContext.DrawText(aTextPos, pItem->maText); + rRenderContext.DrawText( + aTextPos, + pItem->maText, + 0, -1, nullptr, nullptr, + &pLayoutCache ); } + // update cache if necessary + if(pLayoutCache != pItem->mxLayoutCache.get() ) + pItem->mxLayoutCache.reset(pLayoutCache); + // call DrawItem if necessary if (pItem->mnBits & StatusBarItemBits::UserDraw) { @@ -830,6 +851,13 @@ void StatusBar::StateChanged( StateChangedType nType ) ImplInitSettings(); Invalidate(); } + + //invalidate layout cache + for (ImplStatusItem* pItem : mpItemList) + { + pItem->mxLayoutCache.reset(); + } + } void StatusBar::DataChanged( const DataChangedEvent& rDCEvt ) @@ -852,6 +880,8 @@ void StatusBar::DataChanged( const DataChangedEvent& rDCEvt ) long nWidth = GetTextWidth( pItem->maText ) + nFudge; if( nWidth > pItem->mnWidth + STATUSBAR_OFFSET ) pItem->mnWidth = nWidth + STATUSBAR_OFFSET; + + pItem->mxLayoutCache.reset(); } Size aSize = GetSizePixel(); // do not disturb current width, since @@ -1133,11 +1163,21 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText ) if ( pItem->maText != rText ) { + // invalidate cache + pItem->mxLayoutCache.reset(); + pItem->maText = rText; // adjust item width - see also DataChanged() long nFudge = GetTextHeight()/4; - long nWidth = GetTextWidth( pItem->maText ) + nFudge; + + SalLayout* pLayoutCache = nullptr; + + long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,&pLayoutCache ) + nFudge; + + // update cache + pItem->mxLayoutCache.reset(pLayoutCache); + if( (nWidth > pItem->mnWidth + STATUSBAR_OFFSET) || ((nWidth < pItem->mnWidth) && (mnDX - STATUSBAR_OFFSET) < mnItemsWidth )) { @@ -1196,6 +1236,8 @@ void StatusBar::SetItemData( sal_uInt16 nItemId, void* pNewData ) if ( nPos != STATUSBAR_ITEM_NOTFOUND ) { ImplStatusItem* pItem = mpItemList[ nPos ]; + // invalidate cache + pItem->mxLayoutCache.reset(); pItem->mpUserData = pNewData; // call Draw-Item if it's a User-Item |