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>
29
30SvStream& 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
82SvStream& 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
123Wallpaper::Wallpaper( const Wallpaper& ) = default;
124
125Wallpaper::Wallpaper( Wallpaper&& ) = default;
126
128{
129 maColor = rColor;
131}
132
134{
135 maBitmap = rBmpEx;
137}
138
139Wallpaper::~Wallpaper() = default;
140
142{
143 maCache = rBmp;
144}
145
147{
148 return maCache.IsEmpty() ? nullptr : &maCache;
149}
150
152{
154}
155
156void Wallpaper::SetColor( const Color& rColor )
157{
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
175void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
176{
178 maBitmap = rBitmap;
179
182}
183
185{
186 return maBitmap;
187}
188
190{
191 return !maBitmap.IsEmpty();
192}
193
194void Wallpaper::SetGradient( const Gradient& rGradient )
195{
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( css::awt::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
233{
234 return !maRect.IsEmpty();
235}
236
238{
240 return false;
241 else
242 return (maBitmap.IsEmpty() && !mpGradient);
243}
244
246{
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
257Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default;
258
260
261bool 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: */
basegfx::BColor maColor
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:638
bool IsEmpty() const
Definition: BitmapEx.cxx:186
void SetEmpty()
Definition: BitmapEx.cxx:191
void SetStyle(css::awt::GradientStyle eStyle)
void SetStartColor(const Color &rColor)
void SetAngle(Degree10 nAngle)
void SetEndColor(const Color &rColor)
SvStream & ReadCharAsBool(bool &rBool)
SvStream & WriteBool(bool b)
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
void writeGradient(const Gradient &rGradient)
void readGradient(Gradient &rGradient)
sal_uInt16 GetVersion() const
SAL_DLLPRIVATE void ImplSetCachedBitmap(const BitmapEx &rBmp) const
Definition: wall.cxx:141
bool IsRect() const
Definition: wall.cxx:232
Wallpaper()
Definition: wall.cxx:118
tools::Rectangle maRect
Definition: wall.hxx:107
static SAL_DLLPRIVATE Gradient ImplGetApplicationGradient()
Definition: wall.cxx:218
Color maColor
Definition: wall.hxx:111
const BitmapEx & GetBitmap() const
Definition: wall.cxx:184
SAL_DLLPRIVATE void ImplReleaseCachedBitmap() const
Definition: wall.cxx:151
BitmapEx maBitmap
Definition: wall.hxx:108
bool IsScrollable() const
Definition: wall.cxx:245
void SetGradient(const Gradient &rGradient)
Definition: wall.cxx:194
bool IsBitmap() const
Definition: wall.cxx:189
void SetBitmap(const BitmapEx &rBitmap)
Definition: wall.cxx:175
std::optional< Gradient > mpGradient
Definition: wall.hxx:110
Wallpaper & operator=(const Wallpaper &rWallpaper)
SAL_DLLPRIVATE const BitmapEx * ImplGetCachedBitmap() const
Definition: wall.cxx:146
bool IsGradient() const
Definition: wall.cxx:213
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:165
bool IsFixed() const
Definition: wall.cxx:237
bool operator==(const Wallpaper &rWallpaper) const
Definition: wall.cxx:261
WallpaperStyle meStyle
Definition: wall.hxx:112
Gradient GetGradient() const
Definition: wall.cxx:203
BitmapEx maCache
Definition: wall.hxx:109
void SetColor(const Color &rColor)
Definition: wall.cxx:156
void writeColor(const Color &rColor)
void readRectangle(Rectangle &rRectangle)
void writeRectangle(const Rectangle &rRectangle)
void readColor(Color &rColor)
constexpr bool IsEmpty() const
ColorTransparency
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
bool WriteDIBBitmapEx(const BitmapEx &rSource, SvStream &rOStm)
Definition: dibtools.cxx:1742
bool ReadDIBBitmapEx(BitmapEx &rTarget, SvStream &rIStm, bool bFileHeader, bool bMSOFormat)
Definition: dibtools.cxx:1623
NONE
SvStream & ReadWallpaper(SvStream &rIStm, Wallpaper &rImplWallpaper)
Definition: wall.cxx:30
SvStream & WriteWallpaper(SvStream &rOStm, const Wallpaper &rImplWallpaper)
Definition: wall.cxx:82
WallpaperStyle
Definition: wall.hxx:35