diff options
author | Mark Page <aptitude@btconnect.com> | 2016-12-06 07:55:14 +0000 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-12-08 05:57:16 +0000 |
commit | c54eb45230ef54c10e7a86d1c249ea42b07881fe (patch) | |
tree | 77bea288ada244da2552a6fce823e3ec0d63f276 | |
parent | bcdaa1ffb5d8a107d687c797425550ab859d9041 (diff) |
ImplWallpaper to use std::unique_ptr
Also remove ImplWallpaper::operator==, that does not
make sense since members are unique
Change-Id: I69d32d91ba33691eb1f86e70ce3c53fa2761e34b
Reviewed-on: https://gerrit.libreoffice.org/31666
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/vcl/wall.hxx | 1 | ||||
-rw-r--r-- | svtools/source/contnr/ivctrl.cxx | 7 | ||||
-rw-r--r-- | vcl/inc/wall2.hxx | 12 | ||||
-rw-r--r-- | vcl/source/gdi/wall.cxx | 121 |
4 files changed, 49 insertions, 92 deletions
diff --git a/include/vcl/wall.hxx b/include/vcl/wall.hxx index ac1d3d27c224..bd9fa295a693 100644 --- a/include/vcl/wall.hxx +++ b/include/vcl/wall.hxx @@ -93,6 +93,7 @@ public: Wallpaper& operator=( const Wallpaper& rWallpaper ); Wallpaper& operator=( Wallpaper&& rWallpaper ); + bool operator==( const Wallpaper& rWallpaper ) const; bool operator!=( const Wallpaper& rWallpaper ) const { return !(Wallpaper::operator==( rWallpaper )); } diff --git a/svtools/source/contnr/ivctrl.cxx b/svtools/source/contnr/ivctrl.cxx index 41f2296978e6..198184505a1e 100644 --- a/svtools/source/contnr/ivctrl.cxx +++ b/svtools/source/contnr/ivctrl.cxx @@ -338,9 +338,12 @@ void SvtIconChoiceCtrl::SetBackground( const Wallpaper& rPaper ) if( rPaper != GetBackground() ) { const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); - Wallpaper aEmpty; - if( rPaper == aEmpty ) + // if it is the default (empty) wallpaper + if( rPaper.GetStyle() == WallpaperStyle::NONE && rPaper.GetColor() == COL_TRANSPARENT && + !rPaper.IsBitmap() && !rPaper.IsGradient() && !rPaper.IsRect()) + { Control::SetBackground( rStyleSettings.GetFieldColor() ); + } else { Wallpaper aBackground( rPaper ); diff --git a/vcl/inc/wall2.hxx b/vcl/inc/wall2.hxx index 59f2ebb2bc66..52393dd937a4 100644 --- a/vcl/inc/wall2.hxx +++ b/vcl/inc/wall2.hxx @@ -25,19 +25,19 @@ class ImplWallpaper friend class Wallpaper; private: - Color maColor; - BitmapEx* mpBitmap; - Gradient* mpGradient; - Rectangle* mpRect; + Color maColor; + std::unique_ptr<BitmapEx> mpBitmap; + std::unique_ptr<Gradient> mpGradient; + std::unique_ptr<Rectangle> mpRect; WallpaperStyle meStyle; - BitmapEx* mpCache; + std::unique_ptr<BitmapEx> mpCache; public: ImplWallpaper(); ImplWallpaper( const ImplWallpaper& rImplWallpaper ); ~ImplWallpaper(); - bool operator==( const ImplWallpaper& rImplWallpaper ) const; + bool operator==( const ImplWallpaper& rImplWallpaper ) const = delete; friend SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper ); friend SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpaper ); diff --git a/vcl/source/gdi/wall.cxx b/vcl/source/gdi/wall.cxx index 30cba8948cd9..b3f6fa2fa0b0 100644 --- a/vcl/source/gdi/wall.cxx +++ b/vcl/source/gdi/wall.cxx @@ -27,57 +27,32 @@ #include <wall2.hxx> #include <vcl/dibtools.hxx> #include <vcl/settings.hxx> +#include <o3tl/make_unique.hxx> ImplWallpaper::ImplWallpaper() : - maColor( COL_TRANSPARENT ) + maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE ) { - mpBitmap = nullptr; - mpCache = nullptr; - mpGradient = nullptr; - mpRect = nullptr; - meStyle = WallpaperStyle::NONE; } ImplWallpaper::ImplWallpaper( const ImplWallpaper& rImplWallpaper ) : - maColor( rImplWallpaper.maColor ) + maColor( rImplWallpaper.maColor ), meStyle(rImplWallpaper.meStyle) { - meStyle = rImplWallpaper.meStyle; - if ( rImplWallpaper.mpBitmap ) - mpBitmap = new BitmapEx( *rImplWallpaper.mpBitmap ); - else - mpBitmap = nullptr; + mpBitmap = o3tl::make_unique<BitmapEx>( *rImplWallpaper.mpBitmap ); + if( rImplWallpaper.mpCache ) - mpCache = new BitmapEx( *rImplWallpaper.mpCache ); - else - mpCache = nullptr; + mpCache = o3tl::make_unique<BitmapEx>( *rImplWallpaper.mpCache ); + if ( rImplWallpaper.mpGradient ) - mpGradient = new Gradient( *rImplWallpaper.mpGradient ); - else - mpGradient = nullptr; + mpGradient = o3tl::make_unique<Gradient>( *rImplWallpaper.mpGradient ); + if ( rImplWallpaper.mpRect ) - mpRect = new Rectangle( *rImplWallpaper.mpRect ); - else - mpRect = nullptr; -} + mpRect = o3tl::make_unique<Rectangle>( *rImplWallpaper.mpRect ); -ImplWallpaper::~ImplWallpaper() -{ - delete mpBitmap; - delete mpCache; - delete mpGradient; - delete mpRect; } -bool ImplWallpaper::operator==( const ImplWallpaper& rImplWallpaper ) const +ImplWallpaper::~ImplWallpaper() { - if ( meStyle == rImplWallpaper.meStyle && - maColor == rImplWallpaper.maColor && - mpRect == rImplWallpaper.mpRect && - mpBitmap == rImplWallpaper.mpBitmap && - mpGradient == rImplWallpaper.mpGradient ) - return true; - return false; } SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper ) @@ -85,14 +60,9 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper ) VersionCompat aCompat( rIStm, StreamMode::READ ); sal_uInt16 nTmp16; - delete rImplWallpaper.mpRect; - rImplWallpaper.mpRect = nullptr; - - delete rImplWallpaper.mpGradient; - rImplWallpaper.mpGradient = nullptr; - - delete rImplWallpaper.mpBitmap; - rImplWallpaper.mpBitmap = nullptr; + rImplWallpaper.mpRect.reset(); + rImplWallpaper.mpGradient.reset(); + rImplWallpaper.mpBitmap.reset(); // version 1 ReadColor( rIStm, rImplWallpaper.maColor ); @@ -107,19 +77,19 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper ) if( bRect ) { - rImplWallpaper.mpRect = new Rectangle; + rImplWallpaper.mpRect = o3tl::make_unique<Rectangle>(); ReadRectangle( rIStm, *rImplWallpaper.mpRect ); } if( bGrad ) { - rImplWallpaper.mpGradient = new Gradient; + rImplWallpaper.mpGradient = o3tl::make_unique<Gradient>(); ReadGradient( rIStm, *rImplWallpaper.mpGradient ); } if( bBmp ) { - rImplWallpaper.mpBitmap = new BitmapEx; + rImplWallpaper.mpBitmap = o3tl::make_unique<BitmapEx>(); ReadDIBBitmapEx(*rImplWallpaper.mpBitmap, rIStm); } @@ -136,9 +106,9 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper ) SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpaper ) { VersionCompat aCompat( rOStm, StreamMode::WRITE, 3 ); - bool bRect = ( rImplWallpaper.mpRect != nullptr ); - bool bGrad = ( rImplWallpaper.mpGradient != nullptr ); - bool bBmp = ( rImplWallpaper.mpBitmap != nullptr ); + bool bRect = bool(rImplWallpaper.mpRect); + bool bGrad = bool(rImplWallpaper.mpGradient); + bool bBmp = bool(rImplWallpaper.mpBitmap); bool bDummy = false; // version 1 @@ -191,13 +161,13 @@ Wallpaper::Wallpaper( const Color& rColor ) : mpImplWallpaper() Wallpaper::Wallpaper( const BitmapEx& rBmpEx ) : mpImplWallpaper() { - mpImplWallpaper->mpBitmap = new BitmapEx( rBmpEx ); + mpImplWallpaper->mpBitmap = o3tl::make_unique<BitmapEx>( rBmpEx ); mpImplWallpaper->meStyle = WallpaperStyle::Tile; } Wallpaper::Wallpaper( const Gradient& rGradient ) : mpImplWallpaper() { - mpImplWallpaper->mpGradient = new Gradient( rGradient ); + mpImplWallpaper->mpGradient = o3tl::make_unique<Gradient>( rGradient ); mpImplWallpaper->meStyle = WallpaperStyle::Tile; } @@ -208,23 +178,21 @@ Wallpaper::~Wallpaper() void Wallpaper::ImplSetCachedBitmap( BitmapEx& rBmp ) const { if( !mpImplWallpaper->mpCache ) - const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = new BitmapEx( rBmp ); + const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = o3tl::make_unique<BitmapEx>( rBmp ); else *const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = rBmp; } const BitmapEx* Wallpaper::ImplGetCachedBitmap() const { - return mpImplWallpaper->mpCache; + return mpImplWallpaper->mpCache.get(); } void Wallpaper::ImplReleaseCachedBitmap() const { - delete mpImplWallpaper->mpCache; - const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = nullptr; + const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache.reset(); } - void Wallpaper::SetColor( const Color& rColor ) { ImplReleaseCachedBitmap(); @@ -261,8 +229,7 @@ void Wallpaper::SetBitmap( const BitmapEx& rBitmap ) if ( mpImplWallpaper->mpBitmap ) { ImplReleaseCachedBitmap(); - delete mpImplWallpaper->mpBitmap; - mpImplWallpaper->mpBitmap = nullptr; + mpImplWallpaper->mpBitmap.reset(); } } else @@ -271,7 +238,7 @@ void Wallpaper::SetBitmap( const BitmapEx& rBitmap ) if ( mpImplWallpaper->mpBitmap ) *(mpImplWallpaper->mpBitmap) = rBitmap; else - mpImplWallpaper->mpBitmap = new BitmapEx( rBitmap ); + mpImplWallpaper->mpBitmap = o3tl::make_unique<BitmapEx>( rBitmap ); } if( WallpaperStyle::NONE == mpImplWallpaper->meStyle || WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle) @@ -283,15 +250,12 @@ BitmapEx Wallpaper::GetBitmap() const if ( mpImplWallpaper->mpBitmap ) return *(mpImplWallpaper->mpBitmap); else - { - BitmapEx aBmp; - return aBmp; - } + return BitmapEx(); } bool Wallpaper::IsBitmap() const { - return (mpImplWallpaper->mpBitmap != nullptr); + return bool(mpImplWallpaper->mpBitmap); } void Wallpaper::SetGradient( const Gradient& rGradient ) @@ -301,7 +265,7 @@ void Wallpaper::SetGradient( const Gradient& rGradient ) if ( mpImplWallpaper->mpGradient ) *(mpImplWallpaper->mpGradient) = rGradient; else - mpImplWallpaper->mpGradient = new Gradient( rGradient ); + mpImplWallpaper->mpGradient = o3tl::make_unique<Gradient>( rGradient ); if( WallpaperStyle::NONE == mpImplWallpaper->meStyle || WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle ) mpImplWallpaper->meStyle = WallpaperStyle::Tile; @@ -314,15 +278,12 @@ Gradient Wallpaper::GetGradient() const else if ( mpImplWallpaper->mpGradient ) return *(mpImplWallpaper->mpGradient); else - { - Gradient aGradient; - return aGradient; - } + return Gradient(); } bool Wallpaper::IsGradient() const { - return (mpImplWallpaper->mpGradient != nullptr); + return bool(mpImplWallpaper->mpGradient); } Gradient Wallpaper::ImplGetApplicationGradient() @@ -343,18 +304,14 @@ void Wallpaper::SetRect( const Rectangle& rRect ) { if ( rRect.IsEmpty() ) { - if ( mpImplWallpaper->mpRect ) - { - delete mpImplWallpaper->mpRect; - mpImplWallpaper->mpRect = nullptr; - } + mpImplWallpaper->mpRect.reset(); } else { if ( mpImplWallpaper->mpRect ) *(mpImplWallpaper->mpRect) = rRect; else - mpImplWallpaper->mpRect = new Rectangle( rRect ); + mpImplWallpaper->mpRect = o3tl::make_unique<Rectangle>( rRect ); } } @@ -363,16 +320,12 @@ Rectangle Wallpaper::GetRect() const if ( mpImplWallpaper->mpRect ) return *(mpImplWallpaper->mpRect); else - { - Rectangle aRect; - return aRect; - } + return Rectangle(); } bool Wallpaper::IsRect() const { - - return (mpImplWallpaper->mpRect != nullptr); + return bool(mpImplWallpaper->mpRect); } bool Wallpaper::IsFixed() const @@ -409,7 +362,7 @@ Wallpaper& Wallpaper::operator=( Wallpaper&& rWallpaper ) bool Wallpaper::operator==( const Wallpaper& rWallpaper ) const { - return mpImplWallpaper == rWallpaper.mpImplWallpaper; + return mpImplWallpaper.same_object(rWallpaper.mpImplWallpaper); } SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rWallpaper ) |