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 <wall2.hxx>
27 #include <vcl/dibtools.hxx>
28 #include <vcl/settings.hxx>
29 
30 #include <TypeSerializer.hxx>
31 
34 {
35 }
36 
37 ImplWallpaper::ImplWallpaper( const ImplWallpaper& rImplWallpaper ) :
38  maColor( rImplWallpaper.maColor ), meStyle(rImplWallpaper.meStyle)
39 {
40  if ( rImplWallpaper.mpBitmap )
41  mpBitmap = std::make_unique<BitmapEx>( *rImplWallpaper.mpBitmap );
42 
43  if( rImplWallpaper.mpCache )
44  mpCache = std::make_unique<BitmapEx>( *rImplWallpaper.mpCache );
45 
46  if ( rImplWallpaper.mpGradient )
47  mpGradient = std::make_unique<Gradient>( *rImplWallpaper.mpGradient );
48 
49  if ( rImplWallpaper.mpRect )
50  mpRect = *rImplWallpaper.mpRect;
51 }
52 
54 {
55 }
56 
57 SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper )
58 {
59  VersionCompat aCompat( rIStm, StreamMode::READ );
60 
61  rImplWallpaper.mpRect.reset();
62  rImplWallpaper.mpGradient.reset();
63  rImplWallpaper.mpBitmap.reset();
64 
65  // version 1
66  TypeSerializer aSerializer(rIStm);
67  aSerializer.readColor(rImplWallpaper.maColor);
68  sal_uInt16 nTmp16(0);
69  rIStm.ReadUInt16(nTmp16);
70  rImplWallpaper.meStyle = static_cast<WallpaperStyle>(nTmp16);
71 
72  // version 2
73  if( aCompat.GetVersion() >= 2 )
74  {
75  bool bRect(false), bGrad(false), bBmp(false), bDummy;
76 
77  rIStm.ReadCharAsBool( bRect ).ReadCharAsBool( bGrad ).ReadCharAsBool( bBmp ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy );
78 
79  if( bRect )
80  {
81  rImplWallpaper.mpRect = tools::Rectangle();
82  aSerializer.readRectangle(*rImplWallpaper.mpRect);
83  }
84 
85  if( bGrad )
86  {
87  rImplWallpaper.mpGradient = std::make_unique<Gradient>();
88  aSerializer.readGradient(*rImplWallpaper.mpGradient);
89  }
90 
91  if( bBmp )
92  {
93  rImplWallpaper.mpBitmap = std::make_unique<BitmapEx>();
94  ReadDIBBitmapEx(*rImplWallpaper.mpBitmap, rIStm);
95  }
96 
97  // version 3 (new color format)
98  if( aCompat.GetVersion() >= 3 )
99  {
100  rIStm.ReadUInt32(rImplWallpaper.maColor.mValue);
101  }
102  }
103 
104  return rIStm;
105 }
106 
107 SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpaper )
108 {
109  VersionCompat aCompat( rOStm, StreamMode::WRITE, 3 );
110  bool bRect = bool(rImplWallpaper.mpRect);
111  bool bGrad = bool(rImplWallpaper.mpGradient);
112  bool bBmp = bool(rImplWallpaper.mpBitmap);
113  bool bDummy = false;
114 
115  // version 1
116  TypeSerializer aSerializer(rOStm);
117  aSerializer.writeColor(rImplWallpaper.maColor);
118 
119  rOStm.WriteUInt16( static_cast<sal_uInt16>(rImplWallpaper.meStyle) );
120 
121  // version 2
122  rOStm.WriteBool( bRect ).WriteBool( bGrad ).WriteBool( bBmp ).WriteBool( bDummy ).WriteBool( bDummy ).WriteBool( bDummy );
123 
124  if( bRect )
125  {
126  aSerializer.writeRectangle(*rImplWallpaper.mpRect);
127  }
128 
129  if (bGrad)
130  {
131  aSerializer.writeGradient(*rImplWallpaper.mpGradient);
132  }
133 
134  if( bBmp )
135  WriteDIBBitmapEx(*rImplWallpaper.mpBitmap, rOStm);
136 
137  // version 3 (new color format)
138  rOStm.WriteUInt32(rImplWallpaper.maColor.mValue);
139 
140  return rOStm;
141 }
142 
143 namespace
144 {
145  struct theGlobalDefault :
146  public rtl::Static< Wallpaper::ImplType, theGlobalDefault > {};
147 }
148 
149 Wallpaper::Wallpaper() : mpImplWallpaper(theGlobalDefault::get())
150 {
151 }
152 
153 Wallpaper::Wallpaper( const Wallpaper& ) = default;
154 
155 Wallpaper::Wallpaper( Wallpaper&& ) = default;
156 
157 Wallpaper::Wallpaper( const Color& rColor ) : mpImplWallpaper()
158 {
159  mpImplWallpaper->maColor = rColor;
161 }
162 
163 Wallpaper::Wallpaper( const BitmapEx& rBmpEx ) : mpImplWallpaper()
164 {
165  mpImplWallpaper->mpBitmap = std::make_unique<BitmapEx>( rBmpEx );
167 }
168 
169 Wallpaper::~Wallpaper() = default;
170 
172 {
173  if( !mpImplWallpaper->mpCache )
174  const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = std::make_unique<BitmapEx>( rBmp );
175  else
176  *const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = rBmp;
177 }
178 
180 {
181  return mpImplWallpaper->mpCache.get();
182 }
183 
185 {
186  const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache.reset();
187 }
188 
189 void Wallpaper::SetColor( const Color& rColor )
190 {
192  mpImplWallpaper->maColor = rColor;
193 
196 }
197 
199 {
200  return mpImplWallpaper->maColor;
201 }
202 
204 {
206  // set a dummy gradient, the correct gradient
207  // will be created dynamically in GetGradient()
209 
210  mpImplWallpaper->meStyle = eStyle;
211 }
212 
214 {
215  return mpImplWallpaper->meStyle;
216 }
217 
218 void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
219 {
220  if ( !rBitmap )
221  {
222  if ( mpImplWallpaper->mpBitmap )
223  {
225  mpImplWallpaper->mpBitmap.reset();
226  }
227  }
228  else
229  {
231  if ( mpImplWallpaper->mpBitmap )
232  *(mpImplWallpaper->mpBitmap) = rBitmap;
233  else
234  mpImplWallpaper->mpBitmap = std::make_unique<BitmapEx>( rBitmap );
235  }
236 
239 }
240 
242 {
243  if ( mpImplWallpaper->mpBitmap )
244  return *(mpImplWallpaper->mpBitmap);
245  else
246  return BitmapEx();
247 }
248 
250 {
251  return bool(mpImplWallpaper->mpBitmap);
252 }
253 
254 void Wallpaper::SetGradient( const Gradient& rGradient )
255 {
257 
259  *(mpImplWallpaper->mpGradient) = rGradient;
260  else
261  mpImplWallpaper->mpGradient = std::make_unique<Gradient>( rGradient );
262 
265 }
266 
268 {
271  else if ( mpImplWallpaper->mpGradient )
272  return *(mpImplWallpaper->mpGradient);
273  else
274  return Gradient();
275 }
276 
278 {
279  return bool(mpImplWallpaper->mpGradient);
280 }
281 
283 {
284  Gradient g;
285  g.SetAngle( Degree10(900) );
286  g.SetStyle( GradientStyle::Linear );
287  g.SetStartColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
288  // no 'extreme' gradient when high contrast
289  if( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
290  g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
291  else
292  g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceGradientColor() );
293  return g;
294 }
295 
297 {
298  if ( rRect.IsEmpty() )
299  {
300  mpImplWallpaper->mpRect.reset();
301  }
302  else
303  {
304  mpImplWallpaper->mpRect = rRect;
305  }
306 }
307 
309 {
310  if ( mpImplWallpaper->mpRect )
311  return *mpImplWallpaper->mpRect;
312  else
313  return tools::Rectangle();
314 }
315 
316 bool Wallpaper::IsRect() const
317 {
318  return bool(mpImplWallpaper->mpRect);
319 }
320 
321 bool Wallpaper::IsFixed() const
322 {
324  return false;
325  else
327 }
328 
330 {
332  return false;
334  return true;
335  else if ( mpImplWallpaper->mpBitmap )
337  else
338  return false;
339 }
340 
341 Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default;
342 
344 
345 bool Wallpaper::operator==( const Wallpaper& rWallpaper ) const
346 {
347  return mpImplWallpaper.same_object(rWallpaper.mpImplWallpaper);
348 }
349 
350 SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rWallpaper )
351 {
352  return ReadImplWallpaper( rIStm, *rWallpaper.mpImplWallpaper );
353 }
354 
355 SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rWallpaper )
356 {
357  return WriteImplWallpaper( rOStm, *rWallpaper.mpImplWallpaper );
358 }
359 
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
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:184
WallpaperStyle meStyle
Definition: wall2.hxx:35
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
void writeRectangle(const Rectangle &rRectangle)
void readRectangle(Rectangle &rRectangle)
~ImplWallpaper()
Definition: wall.cxx:53
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:707
static SAL_DLLPRIVATE Gradient ImplGetApplicationGradient()
Definition: wall.cxx:282
SvStream & ReadCharAsBool(bool &rBool)
void SetColor(const Color &rColor)
Definition: wall.cxx:189
WallpaperStyle GetStyle() const
Definition: wall.cxx:213
basegfx::BColor maColor
sal_uInt32 mValue
NONE
SvStream & WriteWallpaper(SvStream &rOStm, const Wallpaper &rWallpaper)
Definition: wall.cxx:355
bool operator==(const Wallpaper &rWallpaper) const
Definition: wall.cxx:345
bool IsEmpty() const
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
bool ReadDIBBitmapEx(BitmapEx &rTarget, SvStream &rIStm, bool bFileHeader, bool bMSOFormat)
Definition: dibtools.cxx:1743
SvStream & ReadWallpaper(SvStream &rIStm, Wallpaper &rWallpaper)
Definition: wall.cxx:350
ImplWallpaper()
Definition: wall.cxx:32
void SetStartColor(const Color &rColor)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SAL_DLLPRIVATE const BitmapEx * ImplGetCachedBitmap() const
Definition: wall.cxx:179
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
std::optional< tools::Rectangle > mpRect
Definition: wall2.hxx:30
tools::Rectangle GetRect() const
Definition: wall.cxx:308
bool WriteDIBBitmapEx(const BitmapEx &rSource, SvStream &rOStm)
Definition: dibtools.cxx:1874
void SetRect(const tools::Rectangle &rRect)
Definition: wall.cxx:296
bool IsRect() const
Definition: wall.cxx:316
std::unique_ptr< Gradient > mpGradient
Definition: wall2.hxx:32
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:203
void SetBitmap(const BitmapEx &rBitmap)
Definition: wall.cxx:218
const Color & GetColor() const
Definition: wall.cxx:198
bool same_object(const cow_wrapper &rOther) const
SvStream & ReadImplWallpaper(SvStream &rIStm, ImplWallpaper &rImplWallpaper)
Definition: wall.cxx:57
void writeGradient(const Gradient &rGradient)
Color maColor
Definition: wall2.hxx:34
Wallpaper()
Definition: wall.cxx:149
bool IsFixed() const
Definition: wall.cxx:321
Gradient GetGradient() const
Definition: wall.cxx:267
void SetAngle(Degree10 nAngle)
BitmapEx GetBitmap() const
Definition: wall.cxx:241
bool IsGradient() const
Definition: wall.cxx:277
ImplType mpImplWallpaper
Definition: wall.hxx:60
WallpaperStyle
Definition: wall.hxx:32
bool IsScrollable() const
Definition: wall.cxx:329
bool IsBitmap() const
Definition: wall.cxx:249
SvStream & WriteImplWallpaper(SvStream &rOStm, const ImplWallpaper &rImplWallpaper)
Definition: wall.cxx:107
void writeColor(const Color &rColor)
void SetStyle(GradientStyle eStyle)
void readGradient(Gradient &rGradient)
std::unique_ptr< BitmapEx > mpCache
Definition: wall2.hxx:33
SAL_DLLPRIVATE void ImplSetCachedBitmap(BitmapEx &rBmp) const
Definition: wall.cxx:171
void readColor(Color &rColor)
std::unique_ptr< BitmapEx > mpBitmap
Definition: wall2.hxx:31
void SetGradient(const Gradient &rGradient)
Definition: wall.cxx:254