diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-23 10:31:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-23 12:34:51 +0100 |
commit | aea9d9b054a59ccb53b7160daba808de9db7d814 (patch) | |
tree | 4bdc11d16bc329d86c858a315af2c65f46dc3f1c | |
parent | 144bc302b8e610422f0bdbfceb1726822454dfbc (diff) |
use boost::optional in vcl
instead of allocating small objects on the heap via std::unique_ptr
Change-Id: Iba1d9ad90dc5a31908027336f85046a9de6f5bc4
Reviewed-on: https://gerrit.libreoffice.org/51769
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | vcl/inc/bitmapwriteaccess.hxx | 5 | ||||
-rw-r--r-- | vcl/inc/wall2.hxx | 4 | ||||
-rw-r--r-- | vcl/inc/window.h | 13 | ||||
-rw-r--r-- | vcl/source/gdi/bmpacc.cxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/bmpacc3.cxx | 18 | ||||
-rw-r--r-- | vcl/source/gdi/wall.cxx | 12 | ||||
-rw-r--r-- | vcl/source/window/accessibility.cxx | 6 | ||||
-rw-r--r-- | vcl/source/window/paint.cxx | 12 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 15 | ||||
-rw-r--r-- | vcl/source/window/window2.cxx | 22 | ||||
-rw-r--r-- | vcl/source/window/winproc.cxx | 2 |
11 files changed, 46 insertions, 65 deletions
diff --git a/vcl/inc/bitmapwriteaccess.hxx b/vcl/inc/bitmapwriteaccess.hxx index 0223ad778f10..b2aba128381d 100644 --- a/vcl/inc/bitmapwriteaccess.hxx +++ b/vcl/inc/bitmapwriteaccess.hxx @@ -14,6 +14,7 @@ #include <vcl/alpha.hxx> #include <vcl/bitmap.hxx> #include <vcl/bitmapaccess.hxx> +#include <boost/optional.hpp> typedef vcl::ScopedBitmapAccess<BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess> BitmapScopedWriteAccess; @@ -82,8 +83,8 @@ public: void DrawRect(const tools::Rectangle& rRect); private: - std::unique_ptr<BitmapColor> mpLineColor; - std::unique_ptr<BitmapColor> mpFillColor; + boost::optional<BitmapColor> mpLineColor; + boost::optional<BitmapColor> mpFillColor; BitmapWriteAccess() = delete; BitmapWriteAccess(const BitmapWriteAccess&) = delete; diff --git a/vcl/inc/wall2.hxx b/vcl/inc/wall2.hxx index cce5d03919ec..cad63ee4332d 100644 --- a/vcl/inc/wall2.hxx +++ b/vcl/inc/wall2.hxx @@ -20,6 +20,8 @@ #ifndef INCLUDED_VCL_INC_WALL2_HXX #define INCLUDED_VCL_INC_WALL2_HXX +#include <boost/optional.hpp> + class ImplWallpaper { friend class Wallpaper; @@ -28,7 +30,7 @@ private: Color maColor; std::unique_ptr<BitmapEx> mpBitmap; std::unique_ptr<Gradient> mpGradient; - std::unique_ptr<tools::Rectangle> mpRect; + boost::optional<tools::Rectangle> mpRect; WallpaperStyle meStyle; std::unique_ptr<BitmapEx> mpCache; diff --git a/vcl/inc/window.h b/vcl/inc/window.h index 648143e96545..da11f0bc514e 100644 --- a/vcl/inc/window.h +++ b/vcl/inc/window.h @@ -28,6 +28,7 @@ #include <vcl/window.hxx> #include <o3tl/typed_flags_set.hxx> +#include <boost/optional.hpp> #include <list> #include <memory> #include <vector> @@ -90,20 +91,20 @@ bool ImplWindowFrameProc( vcl::Window* pInst, SalEvent nEvent, const void* pEven struct ImplWinData { - std::unique_ptr<OUString> + boost::optional<OUString> mpExtOldText; std::unique_ptr<ExtTextInputAttr[]> mpExtOldAttrAry; - std::unique_ptr<tools::Rectangle> + boost::optional<tools::Rectangle> mpCursorRect; long mnCursorExtWidth; bool mbVertical; std::unique_ptr<tools::Rectangle[]> mpCompositionCharRects; long mnCompositionCharRects; - std::unique_ptr<tools::Rectangle> + boost::optional<tools::Rectangle> mpFocusRect; - std::unique_ptr<tools::Rectangle> + boost::optional<tools::Rectangle> mpTrackRect; ShowTrackFlags mnTrackFlags; sal_uInt16 mnIsTopWindow; @@ -175,9 +176,9 @@ struct ImplFrameData struct ImplAccessibleInfos { sal_uInt16 nAccessibleRole; - std::unique_ptr<OUString> + boost::optional<OUString> pAccessibleName; - std::unique_ptr<OUString> + boost::optional<OUString> pAccessibleDescription; VclPtr<vcl::Window> pLabeledByWindow; VclPtr<vcl::Window> pLabelForWindow; diff --git a/vcl/source/gdi/bmpacc.cxx b/vcl/source/gdi/bmpacc.cxx index e5134c5019b5..34919a3149bf 100644 --- a/vcl/source/gdi/bmpacc.cxx +++ b/vcl/source/gdi/bmpacc.cxx @@ -323,8 +323,6 @@ BitmapColor BitmapReadAccess::GetColorWithFallback( double fY, double fX, const BitmapWriteAccess::BitmapWriteAccess(Bitmap& rBitmap) : BitmapReadAccess(rBitmap, BitmapAccessMode::Write) - , mpLineColor() - , mpFillColor() { } diff --git a/vcl/source/gdi/bmpacc3.cxx b/vcl/source/gdi/bmpacc3.cxx index e1d382ba4114..bdaf8e889c80 100644 --- a/vcl/source/gdi/bmpacc3.cxx +++ b/vcl/source/gdi/bmpacc3.cxx @@ -37,11 +37,11 @@ void BitmapWriteAccess::SetLineColor( const Color& rColor ) { if (HasPalette()) { - mpLineColor.reset(new BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor)))); + mpLineColor = BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor))); } else { - mpLineColor.reset(new BitmapColor(rColor)); + mpLineColor = BitmapColor(rColor); } } } @@ -61,11 +61,11 @@ void BitmapWriteAccess::SetFillColor( const Color& rColor ) { if (HasPalette()) { - mpFillColor.reset(new BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor)))); + mpFillColor = BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor))); } else { - mpFillColor.reset(new BitmapColor(rColor)); + mpFillColor = BitmapColor(rColor); } } } @@ -84,21 +84,21 @@ void BitmapWriteAccess::Erase( const Color& rColor ) return; // use the canonical method to clear the bitmap - BitmapColor* pOldFillColor = mpFillColor ? new BitmapColor(*mpFillColor) : nullptr; + boost::optional<BitmapColor> pOldFillColor(mpFillColor); const Point aPoint; const tools::Rectangle aRect(aPoint, maBitmap.GetSizePixel()); SetFillColor(rColor); FillRect(aRect); - mpFillColor.reset(pOldFillColor); + mpFillColor = pOldFillColor; } void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) { if (mpLineColor) { - const BitmapColor& rLineColor = *mpLineColor.get(); + const BitmapColor& rLineColor = *mpLineColor; long nX, nY; if (rStart.X() == rEnd.X()) @@ -234,7 +234,7 @@ void BitmapWriteAccess::FillRect( const tools::Rectangle& rRect ) { if (mpFillColor) { - const BitmapColor& rFillColor = *mpFillColor.get(); + const BitmapColor& rFillColor = *mpFillColor; tools::Rectangle aRect(Point(), maBitmap.GetSizePixel()); aRect.Intersection(rRect); @@ -263,7 +263,7 @@ void BitmapWriteAccess::DrawRect( const tools::Rectangle& rRect ) if (mpFillColor) FillRect(rRect); - if (mpLineColor && (!mpFillColor || ( *mpFillColor.get() != *mpLineColor.get()))) + if (mpLineColor && (!mpFillColor || ( *mpFillColor != *mpLineColor))) { DrawLine(rRect.TopLeft(), rRect.TopRight()); DrawLine(rRect.TopRight(), rRect.BottomRight()); diff --git a/vcl/source/gdi/wall.cxx b/vcl/source/gdi/wall.cxx index 11861f784ab6..8898ec5f6ca3 100644 --- a/vcl/source/gdi/wall.cxx +++ b/vcl/source/gdi/wall.cxx @@ -46,8 +46,7 @@ ImplWallpaper::ImplWallpaper( const ImplWallpaper& rImplWallpaper ) : mpGradient = o3tl::make_unique<Gradient>( *rImplWallpaper.mpGradient ); if ( rImplWallpaper.mpRect ) - mpRect = o3tl::make_unique<tools::Rectangle>( *rImplWallpaper.mpRect ); - + mpRect = *rImplWallpaper.mpRect; } ImplWallpaper::~ImplWallpaper() @@ -77,7 +76,7 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper ) if( bRect ) { - rImplWallpaper.mpRect = o3tl::make_unique<tools::Rectangle>(); + rImplWallpaper.mpRect = tools::Rectangle(); ReadRectangle( rIStm, *rImplWallpaper.mpRect ); } @@ -308,17 +307,14 @@ void Wallpaper::SetRect( const tools::Rectangle& rRect ) } else { - if ( mpImplWallpaper->mpRect ) - *(mpImplWallpaper->mpRect) = rRect; - else - mpImplWallpaper->mpRect = o3tl::make_unique<tools::Rectangle>( rRect ); + mpImplWallpaper->mpRect = rRect; } } tools::Rectangle Wallpaper::GetRect() const { if ( mpImplWallpaper->mpRect ) - return *(mpImplWallpaper->mpRect); + return *mpImplWallpaper->mpRect; else return tools::Rectangle(); } diff --git a/vcl/source/window/accessibility.cxx b/vcl/source/window/accessibility.cxx index 098044899898..ac9703fd5e2d 100644 --- a/vcl/source/window/accessibility.cxx +++ b/vcl/source/window/accessibility.cxx @@ -98,8 +98,6 @@ using namespace ::com::sun::star; ImplAccessibleInfos::ImplAccessibleInfos() { nAccessibleRole = 0xFFFF; - pAccessibleName = nullptr; - pAccessibleDescription = nullptr; pLabeledByWindow = nullptr; pLabelForWindow = nullptr; pMemberOfWindow = nullptr; @@ -422,7 +420,7 @@ void Window::SetAccessibleName( const OUString& rName ) OUString oldName = GetAccessibleName(); - mpWindowImpl->mpAccessibleInfos->pAccessibleName.reset( new OUString( rName ) ); + mpWindowImpl->mpAccessibleInfos->pAccessibleName = rName; CallEventListeners( VclEventId::WindowFrameTitleChanged, &oldName ); } @@ -503,7 +501,7 @@ void Window::SetAccessibleDescription( const OUString& rDescription ) mpWindowImpl->mpAccessibleInfos.reset( new ImplAccessibleInfos ); SAL_WARN_IF( mpWindowImpl->mpAccessibleInfos->pAccessibleDescription, "vcl", "AccessibleDescription already set!" ); - mpWindowImpl->mpAccessibleInfos->pAccessibleDescription.reset( new OUString( rDescription ) ); + mpWindowImpl->mpAccessibleInfos->pAccessibleDescription = rDescription; } OUString Window::GetAccessibleDescription() const diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx index 6817ff45c485..aaebe10c871d 100644 --- a/vcl/source/window/paint.cxx +++ b/vcl/source/window/paint.cxx @@ -510,7 +510,7 @@ void Window::PopPaintHelper(PaintHelper const *pHelper) if (mpWindowImpl->mpWinData) { if (mpWindowImpl->mbFocusVisible) - ImplInvertFocus(*(mpWindowImpl->mpWinData->mpFocusRect)); + ImplInvertFocus(*mpWindowImpl->mpWinData->mpFocusRect); } mpWindowImpl->mbInPaint = false; mbInitClipRegion = true; @@ -546,7 +546,7 @@ PaintHelper::~PaintHelper() /* #98602# need to invert the tracking rect AFTER * the children have painted */ - m_pWindow->InvertTracking( *(pWindowImpl->mpWinData->mpTrackRect), pWindowImpl->mpWinData->mnTrackFlags ); + m_pWindow->InvertTracking( *pWindowImpl->mpWinData->mpTrackRect, pWindowImpl->mpWinData->mnTrackFlags ); // double-buffering: paint in case we created the buffer, the children are // already painted inside @@ -1635,9 +1635,9 @@ void Window::ImplScroll( const tools::Rectangle& rRect, if ( mpWindowImpl->mpWinData ) { if ( mpWindowImpl->mbFocusVisible ) - ImplInvertFocus( *(mpWindowImpl->mpWinData->mpFocusRect) ); + ImplInvertFocus( *mpWindowImpl->mpWinData->mpFocusRect ); if ( mpWindowImpl->mbTrackVisible && (mpWindowImpl->mpWinData->mnTrackFlags & ShowTrackFlags::TrackWindow) ) - InvertTracking( *(mpWindowImpl->mpWinData->mpTrackRect), mpWindowImpl->mpWinData->mnTrackFlags ); + InvertTracking( *mpWindowImpl->mpWinData->mpTrackRect, mpWindowImpl->mpWinData->mnTrackFlags ); } #ifndef IOS // This seems completely unnecessary with tiled rendering, and @@ -1670,9 +1670,9 @@ void Window::ImplScroll( const tools::Rectangle& rRect, if ( mpWindowImpl->mpWinData ) { if ( mpWindowImpl->mbFocusVisible ) - ImplInvertFocus( *(mpWindowImpl->mpWinData->mpFocusRect) ); + ImplInvertFocus( *mpWindowImpl->mpWinData->mpFocusRect ); if ( mpWindowImpl->mbTrackVisible && (mpWindowImpl->mpWinData->mnTrackFlags & ShowTrackFlags::TrackWindow) ) - InvertTracking( *(mpWindowImpl->mpWinData->mpTrackRect), mpWindowImpl->mpWinData->mnTrackFlags ); + InvertTracking( *mpWindowImpl->mpWinData->mpTrackRect, mpWindowImpl->mpWinData->mnTrackFlags ); } } diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index e02328d17938..73f14f2dafb3 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -751,15 +751,11 @@ WindowImpl::~WindowImpl() } ImplWinData::ImplWinData() : - mpExtOldText(nullptr), mpExtOldAttrAry(nullptr), - mpCursorRect(nullptr), mnCursorExtWidth(0), mbVertical(false), mpCompositionCharRects(nullptr), mnCompositionCharRects(0), - mpFocusRect(nullptr), - mpTrackRect(nullptr), mnTrackFlags(ShowTrackFlags::NONE), mnIsTopWindow(sal_uInt16(~0)), // not initialized yet, 0/1 will indicate TopWindow (see IsTopWindow()) mbMouseOver(false), @@ -769,10 +765,7 @@ ImplWinData::ImplWinData() : ImplWinData::~ImplWinData() { - mpCursorRect.reset(); mpCompositionCharRects.reset(); - mpFocusRect.reset(); - mpTrackRect.reset(); } ImplFrameData::ImplFrameData( vcl::Window *pWindow ) @@ -2111,16 +2104,14 @@ void Window::SetCursorRect( const tools::Rectangle* pRect, long nExtTextInputWid if ( pWinData->mpCursorRect ) { if ( pRect ) - *pWinData->mpCursorRect = *pRect; + pWinData->mpCursorRect = *pRect; else - { pWinData->mpCursorRect.reset(); - } } else { if ( pRect ) - pWinData->mpCursorRect.reset( new tools::Rectangle( *pRect ) ); + pWinData->mpCursorRect = *pRect; } pWinData->mnCursorExtWidth = nExtTextInputWidth; @@ -2131,7 +2122,7 @@ const tools::Rectangle* Window::GetCursorRect() const { ImplWinData* pWinData = ImplGetWinData(); - return pWinData->mpCursorRect.get(); + return pWinData->mpCursorRect ? &*pWinData->mpCursorRect : nullptr; } long Window::GetCursorExtTextInputWidth() const diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx index 937eda35e013..b01defb887f0 100644 --- a/vcl/source/window/window2.cxx +++ b/vcl/source/window/window2.cxx @@ -64,21 +64,18 @@ void Window::ShowFocus( const tools::Rectangle& rRect ) { if ( mpWindowImpl->mbFocusVisible ) { - if ( *(pWinData->mpFocusRect) == rRect ) + if ( *pWinData->mpFocusRect == rRect ) { mpWindowImpl->mbInShowFocus = false; return; } - ImplInvertFocus( *(pWinData->mpFocusRect) ); + ImplInvertFocus( *pWinData->mpFocusRect ); } ImplInvertFocus( rRect ); } - if ( !pWinData->mpFocusRect ) - pWinData->mpFocusRect.reset( new tools::Rectangle( rRect ) ); - else - *(pWinData->mpFocusRect) = rRect; + pWinData->mpFocusRect = rRect; mpWindowImpl->mbFocusVisible = true; } else @@ -111,7 +108,7 @@ void Window::HideFocus() } if ( !mpWindowImpl->mbInPaint ) - ImplInvertFocus( *(ImplGetWinData()->mpFocusRect) ); + ImplInvertFocus( *ImplGetWinData()->mpFocusRect ); mpWindowImpl->mbFocusVisible = false; } else @@ -134,20 +131,17 @@ void Window::ShowTracking( const tools::Rectangle& rRect, ShowTrackFlags nFlags { if ( mpWindowImpl->mbTrackVisible ) { - if ( (*(pWinData->mpTrackRect) == rRect) && + if ( (*pWinData->mpTrackRect == rRect) && (pWinData->mnTrackFlags == nFlags) ) return; - InvertTracking( *(pWinData->mpTrackRect), pWinData->mnTrackFlags ); + InvertTracking( *pWinData->mpTrackRect, pWinData->mnTrackFlags ); } InvertTracking( rRect, nFlags ); } - if ( !pWinData->mpTrackRect ) - pWinData->mpTrackRect.reset(new tools::Rectangle( rRect )); - else - *(pWinData->mpTrackRect) = rRect; + pWinData->mpTrackRect = rRect; pWinData->mnTrackFlags = nFlags; mpWindowImpl->mbTrackVisible = true; } @@ -158,7 +152,7 @@ void Window::HideTracking() { ImplWinData* pWinData = ImplGetWinData(); if ( !mpWindowImpl->mbInPaint || !(pWinData->mnTrackFlags & ShowTrackFlags::TrackWindow) ) - InvertTracking( *(pWinData->mpTrackRect), pWinData->mnTrackFlags ); + InvertTracking( *pWinData->mpTrackRect, pWinData->mnTrackFlags ); mpWindowImpl->mbTrackVisible = false; } } diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index d7fb245500e8..b838f08f848b 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -1141,7 +1141,7 @@ static bool ImplHandleExtTextInput( vcl::Window* pWindow, if ( !pChild->ImplGetWindowImpl()->mbExtTextInput ) { pChild->ImplGetWindowImpl()->mbExtTextInput = true; - pWinData->mpExtOldText.reset( new OUString ); + pWinData->mpExtOldText = OUString(); pWinData->mpExtOldAttrAry.reset(); pSVData->maWinData.mpExtTextInputWin = pChild; ImplCallCommand( pChild, CommandEventId::StartExtTextInput ); |