diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /vcl/source/gdi/wall.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vcl/source/gdi/wall.cxx')
-rw-r--r-- | vcl/source/gdi/wall.cxx | 271 |
1 files changed, 271 insertions, 0 deletions
diff --git a/vcl/source/gdi/wall.cxx b/vcl/source/gdi/wall.cxx new file mode 100644 index 000000000..7ca75b1b1 --- /dev/null +++ b/vcl/source/gdi/wall.cxx @@ -0,0 +1,271 @@ +/* -*- 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 . + */ + +#include <tools/stream.hxx> +#include <tools/vcompat.hxx> +#include <vcl/bitmapex.hxx> +#include <vcl/gradient.hxx> +#include <vcl/wall.hxx> +#include <vcl/svapp.hxx> +#include <vcl/dibtools.hxx> +#include <vcl/settings.hxx> +#include <vcl/TypeSerializer.hxx> + +SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rImplWallpaper ) +{ + VersionCompatRead aCompat(rIStm); + + rImplWallpaper.maRect.SetEmpty(); + rImplWallpaper.mpGradient.reset(); + rImplWallpaper.maBitmap.SetEmpty(); + + // version 1 + TypeSerializer aSerializer(rIStm); + aSerializer.readColor(rImplWallpaper.maColor); + sal_uInt16 nTmp16(0); + rIStm.ReadUInt16(nTmp16); + rImplWallpaper.meStyle = static_cast<WallpaperStyle>(nTmp16); + + // version 2 + if( aCompat.GetVersion() >= 2 ) + { + bool bRect(false), bGrad(false), bBmp(false), bDummy; + + rIStm.ReadCharAsBool( bRect ).ReadCharAsBool( bGrad ).ReadCharAsBool( bBmp ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy ); + + if( bRect ) + { + rImplWallpaper.maRect = tools::Rectangle(); + aSerializer.readRectangle(rImplWallpaper.maRect); + } + + if( bGrad ) + { + rImplWallpaper.mpGradient.emplace(); + aSerializer.readGradient(*rImplWallpaper.mpGradient); + } + + if( bBmp ) + { + rImplWallpaper.maBitmap.SetEmpty(); + ReadDIBBitmapEx(rImplWallpaper.maBitmap, rIStm); + } + + // version 3 (new color format) + if( aCompat.GetVersion() >= 3 ) + { + sal_uInt32 nTmp; + rIStm.ReadUInt32(nTmp); + rImplWallpaper.maColor = ::Color(ColorTransparency, nTmp); + } + } + + return rIStm; +} + +SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rImplWallpaper ) +{ + VersionCompatWrite aCompat(rOStm, 3); + bool bRect = !rImplWallpaper.maRect.IsEmpty(); + bool bGrad = bool(rImplWallpaper.mpGradient); + bool bBmp = !rImplWallpaper.maBitmap.IsEmpty(); + bool bDummy = false; + + // version 1 + TypeSerializer aSerializer(rOStm); + aSerializer.writeColor(rImplWallpaper.maColor); + + rOStm.WriteUInt16( static_cast<sal_uInt16>(rImplWallpaper.meStyle) ); + + // version 2 + rOStm.WriteBool( bRect ).WriteBool( bGrad ).WriteBool( bBmp ).WriteBool( bDummy ).WriteBool( bDummy ).WriteBool( bDummy ); + + if( bRect ) + { + aSerializer.writeRectangle(rImplWallpaper.maRect); + } + + if (bGrad) + { + aSerializer.writeGradient(*rImplWallpaper.mpGradient); + } + + if( bBmp ) + WriteDIBBitmapEx(rImplWallpaper.maBitmap, rOStm); + + // version 3 (new color format) + rOStm.WriteUInt32(static_cast<sal_uInt32>(rImplWallpaper.maColor)); + + return rOStm; +} + +Wallpaper::Wallpaper() : + maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE ) +{ +} + +Wallpaper::Wallpaper( const Wallpaper& ) = default; + +Wallpaper::Wallpaper( Wallpaper&& ) = default; + +Wallpaper::Wallpaper( const Color& rColor ) +{ + maColor = rColor; + meStyle = WallpaperStyle::Tile; +} + +Wallpaper::Wallpaper( const BitmapEx& rBmpEx ) +{ + maBitmap = rBmpEx; + meStyle = WallpaperStyle::Tile; +} + +Wallpaper::~Wallpaper() = default; + +void Wallpaper::ImplSetCachedBitmap( const BitmapEx& rBmp ) const +{ + maCache = rBmp; +} + +const BitmapEx* Wallpaper::ImplGetCachedBitmap() const +{ + return maCache.IsEmpty() ? nullptr : &maCache; +} + +void Wallpaper::ImplReleaseCachedBitmap() const +{ + maCache.SetEmpty(); +} + +void Wallpaper::SetColor( const Color& rColor ) +{ + maCache.SetEmpty(); + maColor = rColor; + + if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle ) + meStyle = WallpaperStyle::Tile; +} + +void Wallpaper::SetStyle( WallpaperStyle eStyle ) +{ + if( eStyle == WallpaperStyle::ApplicationGradient ) + // set a dummy gradient, the correct gradient + // will be created dynamically in GetGradient() + SetGradient( ImplGetApplicationGradient() ); + + meStyle = eStyle; +} + +void Wallpaper::SetBitmap( const BitmapEx& rBitmap ) +{ + maCache.SetEmpty(); + maBitmap = rBitmap; + + if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle) + meStyle = WallpaperStyle::Tile; +} + +const BitmapEx & Wallpaper::GetBitmap() const +{ + return maBitmap; +} + +bool Wallpaper::IsBitmap() const +{ + return !maBitmap.IsEmpty(); +} + +void Wallpaper::SetGradient( const Gradient& rGradient ) +{ + maCache.SetEmpty(); + mpGradient = rGradient; + + if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle ) + meStyle = WallpaperStyle::Tile; +} + +Gradient Wallpaper::GetGradient() const +{ + if( WallpaperStyle::ApplicationGradient == meStyle ) + return ImplGetApplicationGradient(); + else if ( mpGradient ) + return *mpGradient; + else + return Gradient(); +} + +bool Wallpaper::IsGradient() const +{ + return bool(mpGradient); +} + +Gradient Wallpaper::ImplGetApplicationGradient() +{ + Gradient g; + g.SetAngle( 900_deg10 ); + g.SetStyle( GradientStyle::Linear ); + g.SetStartColor( Application::GetSettings().GetStyleSettings().GetFaceColor() ); + // no 'extreme' gradient when high contrast + if( Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) + g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceColor() ); + else + g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceGradientColor() ); + return g; +} + +bool Wallpaper::IsRect() const +{ + return !maRect.IsEmpty(); +} + +bool Wallpaper::IsFixed() const +{ + if ( meStyle == WallpaperStyle::NONE ) + return false; + else + return (maBitmap.IsEmpty() && !mpGradient); +} + +bool Wallpaper::IsScrollable() const +{ + if ( meStyle == WallpaperStyle::NONE ) + return false; + else if ( maBitmap.IsEmpty() && !mpGradient ) + return true; + else if ( !maBitmap.IsEmpty() ) + return (meStyle == WallpaperStyle::Tile); + else + return false; +} + +Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default; + +Wallpaper& Wallpaper::operator=( Wallpaper&& ) = default; + +bool Wallpaper::operator==( const Wallpaper& rOther ) const +{ + return meStyle == rOther.meStyle && + maColor == rOther.maColor && + maRect == rOther.maRect && + maBitmap == rOther.maBitmap && + mpGradient == rOther.mpGradient; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |