LibreOffice Module vcl (master)  1
wall.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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>
29 
30 SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rImplWallpaper )
31 {
32  VersionCompatRead aCompat(rIStm);
33 
34  rImplWallpaper.maRect.SetEmpty();
35  rImplWallpaper.mpGradient.reset();
36  rImplWallpaper.maBitmap.SetEmpty();
37 
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);
44 
45  // version 2
46  if( aCompat.GetVersion() >= 2 )
47  {
48  bool bRect(false), bGrad(false), bBmp(false), bDummy;
49 
50  rIStm.ReadCharAsBool( bRect ).ReadCharAsBool( bGrad ).ReadCharAsBool( bBmp ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy );
51 
52  if( bRect )
53  {
54  rImplWallpaper.maRect = tools::Rectangle();
55  aSerializer.readRectangle(rImplWallpaper.maRect);
56  }
57 
58  if( bGrad )
59  {
60  rImplWallpaper.mpGradient.emplace();
61  aSerializer.readGradient(*rImplWallpaper.mpGradient);
62  }
63 
64  if( bBmp )
65  {
66  rImplWallpaper.maBitmap.SetEmpty();
67  ReadDIBBitmapEx(rImplWallpaper.maBitmap, rIStm);
68  }
69 
70  // version 3 (new color format)
71  if( aCompat.GetVersion() >= 3 )
72  {
73  sal_uInt32 nTmp;
74  rIStm.ReadUInt32(nTmp);
75  rImplWallpaper.maColor = ::Color(ColorTransparency, nTmp);
76  }
77  }
78 
79  return rIStm;
80 }
81 
82 SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rImplWallpaper )
83 {
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;
89 
90  // version 1
91  TypeSerializer aSerializer(rOStm);
92  aSerializer.writeColor(rImplWallpaper.maColor);
93 
94  rOStm.WriteUInt16( static_cast<sal_uInt16>(rImplWallpaper.meStyle) );
95 
96  // version 2
97  rOStm.WriteBool( bRect ).WriteBool( bGrad ).WriteBool( bBmp ).WriteBool( bDummy ).WriteBool( bDummy ).WriteBool( bDummy );
98 
99  if( bRect )
100  {
101  aSerializer.writeRectangle(rImplWallpaper.maRect);
102  }
103 
104  if (bGrad)
105  {
106  aSerializer.writeGradient(*rImplWallpaper.mpGradient);
107  }
108 
109  if( bBmp )
110  WriteDIBBitmapEx(rImplWallpaper.maBitmap, rOStm);
111 
112  // version 3 (new color format)
113  rOStm.WriteUInt32(static_cast<sal_uInt32>(rImplWallpaper.maColor));
114 
115  return rOStm;
116 }
117 
120 {
121 }
122 
123 Wallpaper::Wallpaper( const Wallpaper& ) = default;
124 
125 Wallpaper::Wallpaper( Wallpaper&& ) = default;
126 
127 Wallpaper::Wallpaper( const Color& rColor )
128 {
129  maColor = rColor;
131 }
132 
134 {
135  maBitmap = rBmpEx;
137 }
138 
139 Wallpaper::~Wallpaper() = default;
140 
142 {
143  maCache = rBmp;
144 }
145 
147 {
148  return maCache.IsEmpty() ? nullptr : &maCache;
149 }
150 
152 {
153  maCache.SetEmpty();
154 }
155 
156 void Wallpaper::SetColor( const Color& rColor )
157 {
158  maCache.SetEmpty();
159  maColor = rColor;
160 
163 }
164 
166 {
168  // set a dummy gradient, the correct gradient
169  // will be created dynamically in GetGradient()
171 
172  meStyle = eStyle;
173 }
174 
175 void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
176 {
177  maCache.SetEmpty();
178  maBitmap = rBitmap;
179 
182 }
183 
185 {
186  return maBitmap;
187 }
188 
190 {
191  return !maBitmap.IsEmpty();
192 }
193 
194 void Wallpaper::SetGradient( const Gradient& rGradient )
195 {
196  maCache.SetEmpty();
197  mpGradient = rGradient;
198 
201 }
202 
204 {
207  else if ( mpGradient )
208  return *mpGradient;
209  else
210  return Gradient();
211 }
212 
214 {
215  return bool(mpGradient);
216 }
217 
219 {
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;
230 }
231 
232 bool Wallpaper::IsRect() const
233 {
234  return !maRect.IsEmpty();
235 }
236 
237 bool Wallpaper::IsFixed() const
238 {
239  if ( meStyle == WallpaperStyle::NONE )
240  return false;
241  else
242  return (maBitmap.IsEmpty() && !mpGradient);
243 }
244 
246 {
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;
255 }
256 
257 Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default;
258 
260 
261 bool Wallpaper::operator==( const Wallpaper& rOther ) const
262 {
263  return meStyle == rOther.meStyle &&
264  maColor == rOther.maColor &&
265  maRect == rOther.maRect &&
266  maBitmap == rOther.maBitmap &&
267  mpGradient == rOther.mpGradient;
268 }
269 
270 
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetEndColor(const Color &rColor)
SvStream & WriteBool(bool b)
Wallpaper & operator=(const Wallpaper &rWallpaper)
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SAL_DLLPRIVATE void ImplReleaseCachedBitmap() const
Definition: wall.cxx:151
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
void writeRectangle(const Rectangle &rRectangle)
void readRectangle(Rectangle &rRectangle)
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:733
static SAL_DLLPRIVATE Gradient ImplGetApplicationGradient()
Definition: wall.cxx:218
SvStream & ReadCharAsBool(bool &rBool)
void SetColor(const Color &rColor)
Definition: wall.cxx:156
basegfx::BColor maColor
SvStream & ReadWallpaper(SvStream &rIStm, Wallpaper &rImplWallpaper)
Definition: wall.cxx:30
SvStream & WriteWallpaper(SvStream &rOStm, const Wallpaper &rImplWallpaper)
Definition: wall.cxx:82
NONE
bool operator==(const Wallpaper &rWallpaper) const
Definition: wall.cxx:261
bool ReadDIBBitmapEx(BitmapEx &rTarget, SvStream &rIStm, bool bFileHeader, bool bMSOFormat)
Definition: dibtools.cxx:1709
WallpaperStyle meStyle
Definition: wall.hxx:112
void SetStartColor(const Color &rColor)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
tools::Rectangle maRect
Definition: wall.hxx:107
SAL_DLLPRIVATE const BitmapEx * ImplGetCachedBitmap() const
Definition: wall.cxx:146
Color maColor
Definition: wall.hxx:111
constexpr bool IsEmpty() const
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
void SetEmpty()
Definition: BitmapEx.cxx:182
bool IsEmpty() const
Definition: BitmapEx.cxx:177
bool WriteDIBBitmapEx(const BitmapEx &rSource, SvStream &rOStm)
Definition: dibtools.cxx:1840
bool IsRect() const
Definition: wall.cxx:232
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:165
void SetBitmap(const BitmapEx &rBitmap)
Definition: wall.cxx:175
void writeGradient(const Gradient &rGradient)
Wallpaper()
Definition: wall.cxx:118
ColorTransparency
bool IsFixed() const
Definition: wall.cxx:237
Gradient GetGradient() const
Definition: wall.cxx:203
void SetAngle(Degree10 nAngle)
bool IsGradient() const
Definition: wall.cxx:213
const BitmapEx & GetBitmap() const
Definition: wall.cxx:184
WallpaperStyle
Definition: wall.hxx:34
BitmapEx maBitmap
Definition: wall.hxx:108
bool IsScrollable() const
Definition: wall.cxx:245
bool IsBitmap() const
Definition: wall.cxx:189
void writeColor(const Color &rColor)
void SetStyle(GradientStyle eStyle)
std::optional< Gradient > mpGradient
Definition: wall.hxx:110
void readGradient(Gradient &rGradient)
SAL_DLLPRIVATE void ImplSetCachedBitmap(BitmapEx &rBmp) const
Definition: wall.cxx:141
void readColor(Color &rColor)
void SetGradient(const Gradient &rGradient)
Definition: wall.cxx:194
BitmapEx maCache
Definition: wall.hxx:109