bump product version to 7.2.5.1
[LibreOffice.git] / vcl / source / gdi / wall.cxx
bloba0abd9876da4898e5dc9708c3f4f90949414136b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/stream.hxx>
21 #include <tools/vcompat.hxx>
22 #include <vcl/bitmapex.hxx>
23 #include <vcl/gradient.hxx>
24 #include <vcl/wall.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/dibtools.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/TypeSerializer.hxx>
30 SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rImplWallpaper )
32 VersionCompatRead aCompat(rIStm);
34 rImplWallpaper.maRect.SetEmpty();
35 rImplWallpaper.mpGradient.reset();
36 rImplWallpaper.maBitmap.SetEmpty();
38 // version 1
39 TypeSerializer aSerializer(rIStm);
40 aSerializer.readColor(rImplWallpaper.maColor);
41 sal_uInt16 nTmp16(0);
42 rIStm.ReadUInt16(nTmp16);
43 rImplWallpaper.meStyle = static_cast<WallpaperStyle>(nTmp16);
45 // version 2
46 if( aCompat.GetVersion() >= 2 )
48 bool bRect(false), bGrad(false), bBmp(false), bDummy;
50 rIStm.ReadCharAsBool( bRect ).ReadCharAsBool( bGrad ).ReadCharAsBool( bBmp ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy );
52 if( bRect )
54 rImplWallpaper.maRect = tools::Rectangle();
55 aSerializer.readRectangle(rImplWallpaper.maRect);
58 if( bGrad )
60 rImplWallpaper.mpGradient.emplace();
61 aSerializer.readGradient(*rImplWallpaper.mpGradient);
64 if( bBmp )
66 rImplWallpaper.maBitmap.SetEmpty();
67 ReadDIBBitmapEx(rImplWallpaper.maBitmap, rIStm);
70 // version 3 (new color format)
71 if( aCompat.GetVersion() >= 3 )
73 sal_uInt32 nTmp;
74 rIStm.ReadUInt32(nTmp);
75 rImplWallpaper.maColor = ::Color(ColorTransparency, nTmp);
79 return rIStm;
82 SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rImplWallpaper )
84 VersionCompatWrite aCompat(rOStm, 3);
85 bool bRect = !rImplWallpaper.maRect.IsEmpty();
86 bool bGrad = bool(rImplWallpaper.mpGradient);
87 bool bBmp = !rImplWallpaper.maBitmap.IsEmpty();
88 bool bDummy = false;
90 // version 1
91 TypeSerializer aSerializer(rOStm);
92 aSerializer.writeColor(rImplWallpaper.maColor);
94 rOStm.WriteUInt16( static_cast<sal_uInt16>(rImplWallpaper.meStyle) );
96 // version 2
97 rOStm.WriteBool( bRect ).WriteBool( bGrad ).WriteBool( bBmp ).WriteBool( bDummy ).WriteBool( bDummy ).WriteBool( bDummy );
99 if( bRect )
101 aSerializer.writeRectangle(rImplWallpaper.maRect);
104 if (bGrad)
106 aSerializer.writeGradient(*rImplWallpaper.mpGradient);
109 if( bBmp )
110 WriteDIBBitmapEx(rImplWallpaper.maBitmap, rOStm);
112 // version 3 (new color format)
113 rOStm.WriteUInt32(static_cast<sal_uInt32>(rImplWallpaper.maColor));
115 return rOStm;
118 Wallpaper::Wallpaper() :
119 maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE )
123 Wallpaper::Wallpaper( const Wallpaper& ) = default;
125 Wallpaper::Wallpaper( Wallpaper&& ) = default;
127 Wallpaper::Wallpaper( const Color& rColor )
129 maColor = rColor;
130 meStyle = WallpaperStyle::Tile;
133 Wallpaper::Wallpaper( const BitmapEx& rBmpEx )
135 maBitmap = rBmpEx;
136 meStyle = WallpaperStyle::Tile;
139 Wallpaper::~Wallpaper() = default;
141 void Wallpaper::ImplSetCachedBitmap( BitmapEx& rBmp ) const
143 maCache = rBmp;
146 const BitmapEx* Wallpaper::ImplGetCachedBitmap() const
148 return maCache.IsEmpty() ? nullptr : &maCache;
151 void Wallpaper::ImplReleaseCachedBitmap() const
153 maCache.SetEmpty();
156 void Wallpaper::SetColor( const Color& rColor )
158 maCache.SetEmpty();
159 maColor = rColor;
161 if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle )
162 meStyle = WallpaperStyle::Tile;
165 void Wallpaper::SetStyle( WallpaperStyle eStyle )
167 if( eStyle == WallpaperStyle::ApplicationGradient )
168 // set a dummy gradient, the correct gradient
169 // will be created dynamically in GetGradient()
170 SetGradient( ImplGetApplicationGradient() );
172 meStyle = eStyle;
175 void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
177 maCache.SetEmpty();
178 maBitmap = rBitmap;
180 if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle)
181 meStyle = WallpaperStyle::Tile;
184 const BitmapEx & Wallpaper::GetBitmap() const
186 return maBitmap;
189 bool Wallpaper::IsBitmap() const
191 return !maBitmap.IsEmpty();
194 void Wallpaper::SetGradient( const Gradient& rGradient )
196 maCache.SetEmpty();
197 mpGradient = rGradient;
199 if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle )
200 meStyle = WallpaperStyle::Tile;
203 Gradient Wallpaper::GetGradient() const
205 if( WallpaperStyle::ApplicationGradient == meStyle )
206 return ImplGetApplicationGradient();
207 else if ( mpGradient )
208 return *mpGradient;
209 else
210 return Gradient();
213 bool Wallpaper::IsGradient() const
215 return bool(mpGradient);
218 Gradient Wallpaper::ImplGetApplicationGradient()
220 Gradient g;
221 g.SetAngle( 900_deg10 );
222 g.SetStyle( GradientStyle::Linear );
223 g.SetStartColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
224 // no 'extreme' gradient when high contrast
225 if( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
226 g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
227 else
228 g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceGradientColor() );
229 return g;
232 bool Wallpaper::IsRect() const
234 return !maRect.IsEmpty();
237 bool Wallpaper::IsFixed() const
239 if ( meStyle == WallpaperStyle::NONE )
240 return false;
241 else
242 return (maBitmap.IsEmpty() && !mpGradient);
245 bool Wallpaper::IsScrollable() const
247 if ( meStyle == WallpaperStyle::NONE )
248 return false;
249 else if ( maBitmap.IsEmpty() && !mpGradient )
250 return true;
251 else if ( !maBitmap.IsEmpty() )
252 return (meStyle == WallpaperStyle::Tile);
253 else
254 return false;
257 Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default;
259 Wallpaper& Wallpaper::operator=( Wallpaper&& ) = default;
261 bool Wallpaper::operator==( const Wallpaper& rOther ) const
263 return meStyle == rOther.meStyle &&
264 maColor == rOther.maColor &&
265 maRect == rOther.maRect &&
266 maBitmap == rOther.maBitmap &&
267 mpGradient == rOther.mpGradient;
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */