[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 30 19:43:08 UTC 2021


 include/vcl/wall.hxx            |   25 ++--
 vcl/inc/wall2.hxx               |   50 ---------
 vcl/source/control/combobox.cxx |    2 
 vcl/source/gdi/wall.cxx         |  204 +++++++++++-----------------------------
 4 files changed, 73 insertions(+), 208 deletions(-)

New commits:
commit 25b0f8787946b1627ea6ac0324d871a70cc5d9dd
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Apr 30 15:32:32 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Apr 30 21:42:31 2021 +0200

    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 at collabora.co.uk>

diff --git a/include/vcl/wall.hxx b/include/vcl/wall.hxx
index 6a8c179d2e01..53c8efb7080c 100644
--- a/include/vcl/wall.hxx
+++ b/include/vcl/wall.hxx
@@ -22,8 +22,10 @@
 
 #include <tools/color.hxx>
 #include <tools/gen.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/gradient.hxx>
 #include <vcl/dllapi.h>
-#include <o3tl/cow_wrapper.hxx>
+#include <optional>
 
 class Gradient;
 class BitmapEx;
@@ -50,15 +52,11 @@ enum class WallpaperStyle
 class VCL_DLLPUBLIC Wallpaper
 {
 public:
-    typedef o3tl::cow_wrapper<ImplWallpaper> ImplType;
-
     SAL_DLLPRIVATE void             ImplSetCachedBitmap( BitmapEx& rBmp ) const;
     SAL_DLLPRIVATE const BitmapEx*  ImplGetCachedBitmap() const;
     SAL_DLLPRIVATE void             ImplReleaseCachedBitmap() const;
 
 private:
-    ImplType  mpImplWallpaper;
-
     SAL_DLLPRIVATE static Gradient  ImplGetApplicationGradient();
 
 public:
@@ -70,21 +68,21 @@ public:
                     ~Wallpaper();
 
     void            SetColor( const Color& rColor );
-    const Color&    GetColor() const;
+    const Color&    GetColor() const { return maColor; }
 
     void            SetStyle( WallpaperStyle eStyle );
-    WallpaperStyle  GetStyle() const;
+    WallpaperStyle  GetStyle() const { return meStyle; }
 
     void            SetBitmap( const BitmapEx& rBitmap );
-    BitmapEx        GetBitmap() const;
+    const BitmapEx & GetBitmap() const;
     bool            IsBitmap() const;
 
     void            SetGradient( const Gradient& rGradient );
     Gradient        GetGradient() const;
     bool            IsGradient() const;
 
-    void            SetRect( const tools::Rectangle& rRect );
-    tools::Rectangle       GetRect() const;
+    void            SetRect( const tools::Rectangle& rRect ) { maRect = rRect; }
+    const tools::Rectangle & GetRect() const { return maRect; }
     bool            IsRect() const;
 
     bool            IsFixed() const;
@@ -105,6 +103,13 @@ public:
 
     friend SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rWallpaper );
     friend SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rWallpaper );
+private:
+    tools::Rectangle            maRect;
+    BitmapEx                    maBitmap;
+    mutable BitmapEx            maCache;
+    std::optional<Gradient>     mpGradient;
+    Color                       maColor;
+    WallpaperStyle              meStyle;
 };
 
 #endif // INCLUDED_VCL_WALL_HXX
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: */


More information about the Libreoffice-commits mailing list