summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-04-30 15:32:32 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-04-30 21:42:31 +0200
commit25b0f8787946b1627ea6ac0324d871a70cc5d9dd (patch)
tree3e6cc44406d6024e7fc1e835b31a949b6e90fad0 /vcl
parent61386aa03cd166473a58dbb4be0dd5e0ce82195c (diff)
simplify Wallpaper
All of it's member fields are already COW types, so it doesn't need the complication Change-Id: I44e402e8e80fe96462fc4e1aa06b9ec6815e3cd0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114933 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/wall2.hxx50
-rw-r--r--vcl/source/control/combobox.cxx2
-rw-r--r--vcl/source/gdi/wall.cxx204
3 files changed, 58 insertions, 198 deletions
diff --git a/vcl/inc/wall2.hxx b/vcl/inc/wall2.hxx
deleted file mode 100644
index 401593b3ff8b..000000000000
--- a/vcl/inc/wall2.hxx
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef INCLUDED_VCL_INC_WALL2_HXX
-#define INCLUDED_VCL_INC_WALL2_HXX
-
-#include <optional>
-
-class ImplWallpaper
-{
- friend class Wallpaper;
-
-private:
- std::optional<tools::Rectangle> mpRect;
- std::unique_ptr<BitmapEx> mpBitmap;
- std::unique_ptr<Gradient> mpGradient;
- std::unique_ptr<BitmapEx> mpCache;
- Color maColor;
- WallpaperStyle meStyle;
-
-public:
- ImplWallpaper();
- ImplWallpaper( const ImplWallpaper& rImplWallpaper );
- ~ImplWallpaper();
-
- bool operator==( const ImplWallpaper& rImplWallpaper ) const = delete;
-
- friend SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper );
- friend SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpaper );
-};
-
-#endif // INCLUDED_VCL_INC_WALL2_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx
index cf6e0cfec9eb..f749e7ab9d36 100644
--- a/vcl/source/control/combobox.cxx
+++ b/vcl/source/control/combobox.cxx
@@ -1345,7 +1345,7 @@ const Wallpaper& ComboBox::GetDisplayBackground() const
const Wallpaper& rBack = m_pImpl->m_pSubEdit->GetBackground();
if( ! rBack.IsBitmap() &&
! rBack.IsGradient() &&
- rBack == COL_TRANSPARENT
+ rBack == Wallpaper(COL_TRANSPARENT)
)
return Control::GetDisplayBackground();
return rBack;
diff --git a/vcl/source/gdi/wall.cxx b/vcl/source/gdi/wall.cxx
index 3fb7acaaff1b..a0abd9876da4 100644
--- a/vcl/source/gdi/wall.cxx
+++ b/vcl/source/gdi/wall.cxx
@@ -23,43 +23,17 @@
#include <vcl/gradient.hxx>
#include <vcl/wall.hxx>
#include <vcl/svapp.hxx>
-#include <wall2.hxx>
#include <vcl/dibtools.hxx>
#include <vcl/settings.hxx>
#include <vcl/TypeSerializer.hxx>
-ImplWallpaper::ImplWallpaper() :
- maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE )
-{
-}
-
-ImplWallpaper::ImplWallpaper( const ImplWallpaper& rImplWallpaper ) :
- maColor( rImplWallpaper.maColor ), meStyle(rImplWallpaper.meStyle)
-{
- if ( rImplWallpaper.mpBitmap )
- mpBitmap = std::make_unique<BitmapEx>( *rImplWallpaper.mpBitmap );
-
- if( rImplWallpaper.mpCache )
- mpCache = std::make_unique<BitmapEx>( *rImplWallpaper.mpCache );
-
- if ( rImplWallpaper.mpGradient )
- mpGradient = std::make_unique<Gradient>( *rImplWallpaper.mpGradient );
-
- if ( rImplWallpaper.mpRect )
- mpRect = *rImplWallpaper.mpRect;
-}
-
-ImplWallpaper::~ImplWallpaper()
-{
-}
-
-SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper )
+SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rImplWallpaper )
{
VersionCompatRead aCompat(rIStm);
- rImplWallpaper.mpRect.reset();
+ rImplWallpaper.maRect.SetEmpty();
rImplWallpaper.mpGradient.reset();
- rImplWallpaper.mpBitmap.reset();
+ rImplWallpaper.maBitmap.SetEmpty();
// version 1
TypeSerializer aSerializer(rIStm);
@@ -77,20 +51,20 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper )
if( bRect )
{
- rImplWallpaper.mpRect = tools::Rectangle();
- aSerializer.readRectangle(*rImplWallpaper.mpRect);
+ rImplWallpaper.maRect = tools::Rectangle();
+ aSerializer.readRectangle(rImplWallpaper.maRect);
}
if( bGrad )
{
- rImplWallpaper.mpGradient = std::make_unique<Gradient>();
+ rImplWallpaper.mpGradient.emplace();
aSerializer.readGradient(*rImplWallpaper.mpGradient);
}
if( bBmp )
{
- rImplWallpaper.mpBitmap = std::make_unique<BitmapEx>();
- ReadDIBBitmapEx(*rImplWallpaper.mpBitmap, rIStm);
+ rImplWallpaper.maBitmap.SetEmpty();
+ ReadDIBBitmapEx(rImplWallpaper.maBitmap, rIStm);
}
// version 3 (new color format)
@@ -105,12 +79,12 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper )
return rIStm;
}
-SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpaper )
+SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rImplWallpaper )
{
VersionCompatWrite aCompat(rOStm, 3);
- bool bRect = bool(rImplWallpaper.mpRect);
+ bool bRect = !rImplWallpaper.maRect.IsEmpty();
bool bGrad = bool(rImplWallpaper.mpGradient);
- bool bBmp = bool(rImplWallpaper.mpBitmap);
+ bool bBmp = !rImplWallpaper.maBitmap.IsEmpty();
bool bDummy = false;
// version 1
@@ -124,7 +98,7 @@ SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpap
if( bRect )
{
- aSerializer.writeRectangle(*rImplWallpaper.mpRect);
+ aSerializer.writeRectangle(rImplWallpaper.maRect);
}
if (bGrad)
@@ -133,7 +107,7 @@ SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpap
}
if( bBmp )
- WriteDIBBitmapEx(*rImplWallpaper.mpBitmap, rOStm);
+ WriteDIBBitmapEx(rImplWallpaper.maBitmap, rOStm);
// version 3 (new color format)
rOStm.WriteUInt32(static_cast<sal_uInt32>(rImplWallpaper.maColor));
@@ -141,13 +115,8 @@ SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpap
return rOStm;
}
-namespace
-{
- struct theGlobalDefault :
- public rtl::Static< Wallpaper::ImplType, theGlobalDefault > {};
-}
-
-Wallpaper::Wallpaper() : mpImplWallpaper(theGlobalDefault::get())
+Wallpaper::Wallpaper() :
+ maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE )
{
}
@@ -155,50 +124,42 @@ Wallpaper::Wallpaper( const Wallpaper& ) = default;
Wallpaper::Wallpaper( Wallpaper&& ) = default;
-Wallpaper::Wallpaper( const Color& rColor ) : mpImplWallpaper()
+Wallpaper::Wallpaper( const Color& rColor )
{
- mpImplWallpaper->maColor = rColor;
- mpImplWallpaper->meStyle = WallpaperStyle::Tile;
+ maColor = rColor;
+ meStyle = WallpaperStyle::Tile;
}
-Wallpaper::Wallpaper( const BitmapEx& rBmpEx ) : mpImplWallpaper()
+Wallpaper::Wallpaper( const BitmapEx& rBmpEx )
{
- mpImplWallpaper->mpBitmap = std::make_unique<BitmapEx>( rBmpEx );
- mpImplWallpaper->meStyle = WallpaperStyle::Tile;
+ maBitmap = rBmpEx;
+ meStyle = WallpaperStyle::Tile;
}
Wallpaper::~Wallpaper() = default;
void Wallpaper::ImplSetCachedBitmap( BitmapEx& rBmp ) const
{
- if( !mpImplWallpaper->mpCache )
- const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = std::make_unique<BitmapEx>( rBmp );
- else
- *const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = rBmp;
+ maCache = rBmp;
}
const BitmapEx* Wallpaper::ImplGetCachedBitmap() const
{
- return mpImplWallpaper->mpCache.get();
+ return maCache.IsEmpty() ? nullptr : &maCache;
}
void Wallpaper::ImplReleaseCachedBitmap() const
{
- const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache.reset();
+ maCache.SetEmpty();
}
void Wallpaper::SetColor( const Color& rColor )
{
- ImplReleaseCachedBitmap();
- mpImplWallpaper->maColor = rColor;
-
- if( WallpaperStyle::NONE == mpImplWallpaper->meStyle || WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle )
- mpImplWallpaper->meStyle = WallpaperStyle::Tile;
-}
+ maCache.SetEmpty();
+ maColor = rColor;
-const Color& Wallpaper::GetColor() const
-{
- return mpImplWallpaper->maColor;
+ if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle )
+ meStyle = WallpaperStyle::Tile;
}
void Wallpaper::SetStyle( WallpaperStyle eStyle )
@@ -208,76 +169,50 @@ void Wallpaper::SetStyle( WallpaperStyle eStyle )
// will be created dynamically in GetGradient()
SetGradient( ImplGetApplicationGradient() );
- mpImplWallpaper->meStyle = eStyle;
-}
-
-WallpaperStyle Wallpaper::GetStyle() const
-{
- return mpImplWallpaper->meStyle;
+ meStyle = eStyle;
}
void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
{
- if ( rBitmap.IsEmpty() )
- {
- if ( mpImplWallpaper->mpBitmap )
- {
- ImplReleaseCachedBitmap();
- mpImplWallpaper->mpBitmap.reset();
- }
- }
- else
- {
- ImplReleaseCachedBitmap();
- if ( mpImplWallpaper->mpBitmap )
- *(mpImplWallpaper->mpBitmap) = rBitmap;
- else
- mpImplWallpaper->mpBitmap = std::make_unique<BitmapEx>( rBitmap );
- }
+ maCache.SetEmpty();
+ maBitmap = rBitmap;
- if( WallpaperStyle::NONE == mpImplWallpaper->meStyle || WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle)
- mpImplWallpaper->meStyle = WallpaperStyle::Tile;
+ if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle)
+ meStyle = WallpaperStyle::Tile;
}
-BitmapEx Wallpaper::GetBitmap() const
+const BitmapEx & Wallpaper::GetBitmap() const
{
- if ( mpImplWallpaper->mpBitmap )
- return *(mpImplWallpaper->mpBitmap);
- else
- return BitmapEx();
+ return maBitmap;
}
bool Wallpaper::IsBitmap() const
{
- return bool(mpImplWallpaper->mpBitmap);
+ return !maBitmap.IsEmpty();
}
void Wallpaper::SetGradient( const Gradient& rGradient )
{
- ImplReleaseCachedBitmap();
+ maCache.SetEmpty();
+ mpGradient = rGradient;
- if ( mpImplWallpaper->mpGradient )
- *(mpImplWallpaper->mpGradient) = rGradient;
- else
- mpImplWallpaper->mpGradient = std::make_unique<Gradient>( rGradient );
-
- if( WallpaperStyle::NONE == mpImplWallpaper->meStyle || WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle )
- mpImplWallpaper->meStyle = WallpaperStyle::Tile;
+ if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle )
+ meStyle = WallpaperStyle::Tile;
}
Gradient Wallpaper::GetGradient() const
{
- if( WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle )
+ if( WallpaperStyle::ApplicationGradient == meStyle )
return ImplGetApplicationGradient();
- else if ( mpImplWallpaper->mpGradient )
- return *(mpImplWallpaper->mpGradient);
+ else if ( mpGradient )
+ return *mpGradient;
else
return Gradient();
}
bool Wallpaper::IsGradient() const
{
- return bool(mpImplWallpaper->mpGradient);
+ return bool(mpGradient);
}
Gradient Wallpaper::ImplGetApplicationGradient()
@@ -294,47 +229,27 @@ Gradient Wallpaper::ImplGetApplicationGradient()
return g;
}
-void Wallpaper::SetRect( const tools::Rectangle& rRect )
-{
- if ( rRect.IsEmpty() )
- {
- mpImplWallpaper->mpRect.reset();
- }
- else
- {
- mpImplWallpaper->mpRect = rRect;
- }
-}
-
-tools::Rectangle Wallpaper::GetRect() const
-{
- if ( mpImplWallpaper->mpRect )
- return *mpImplWallpaper->mpRect;
- else
- return tools::Rectangle();
-}
-
bool Wallpaper::IsRect() const
{
- return bool(mpImplWallpaper->mpRect);
+ return !maRect.IsEmpty();
}
bool Wallpaper::IsFixed() const
{
- if ( mpImplWallpaper->meStyle == WallpaperStyle::NONE )
+ if ( meStyle == WallpaperStyle::NONE )
return false;
else
- return (!mpImplWallpaper->mpBitmap && !mpImplWallpaper->mpGradient);
+ return (maBitmap.IsEmpty() && !mpGradient);
}
bool Wallpaper::IsScrollable() const
{
- if ( mpImplWallpaper->meStyle == WallpaperStyle::NONE )
+ if ( meStyle == WallpaperStyle::NONE )
return false;
- else if ( !mpImplWallpaper->mpBitmap && !mpImplWallpaper->mpGradient )
+ else if ( maBitmap.IsEmpty() && !mpGradient )
return true;
- else if ( mpImplWallpaper->mpBitmap )
- return (mpImplWallpaper->meStyle == WallpaperStyle::Tile);
+ else if ( !maBitmap.IsEmpty() )
+ return (meStyle == WallpaperStyle::Tile);
else
return false;
}
@@ -343,19 +258,14 @@ Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default;
Wallpaper& Wallpaper::operator=( Wallpaper&& ) = default;
-bool Wallpaper::operator==( const Wallpaper& rWallpaper ) const
-{
- return mpImplWallpaper.same_object(rWallpaper.mpImplWallpaper);
-}
-
-SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rWallpaper )
+bool Wallpaper::operator==( const Wallpaper& rOther ) const
{
- return ReadImplWallpaper( rIStm, *rWallpaper.mpImplWallpaper );
+ return meStyle == rOther.meStyle &&
+ maColor == rOther.maColor &&
+ maRect == rOther.maRect &&
+ maBitmap == rOther.maBitmap &&
+ mpGradient == rOther.mpGradient;
}
-SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rWallpaper )
-{
- return WriteImplWallpaper( rOStm, *rWallpaper.mpImplWallpaper );
-}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */