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 
33  maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE )
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( const Gradient& rGradient ) : mpImplWallpaper()
170 {
171  mpImplWallpaper->mpGradient = std::make_unique<Gradient>( rGradient );
173 }
174 
175 Wallpaper::~Wallpaper() = default;
176 
178 {
179  if( !mpImplWallpaper->mpCache )
180  const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = std::make_unique<BitmapEx>( rBmp );
181  else
182  *const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = rBmp;
183 }
184 
186 {
187  return mpImplWallpaper->mpCache.get();
188 }
189 
191 {
192  const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache.reset();
193 }
194 
195 void Wallpaper::SetColor( const Color& rColor )
196 {
198  mpImplWallpaper->maColor = rColor;
199 
202 }
203 
205 {
206  return mpImplWallpaper->maColor;
207 }
208 
210 {
212  // set a dummy gradient, the correct gradient
213  // will be created dynamically in GetGradient()
215 
216  mpImplWallpaper->meStyle = eStyle;
217 }
218 
220 {
221  return mpImplWallpaper->meStyle;
222 }
223 
224 void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
225 {
226  if ( !rBitmap )
227  {
228  if ( mpImplWallpaper->mpBitmap )
229  {
231  mpImplWallpaper->mpBitmap.reset();
232  }
233  }
234  else
235  {
237  if ( mpImplWallpaper->mpBitmap )
238  *(mpImplWallpaper->mpBitmap) = rBitmap;
239  else
240  mpImplWallpaper->mpBitmap = std::make_unique<BitmapEx>( rBitmap );
241  }
242 
245 }
246 
248 {
249  if ( mpImplWallpaper->mpBitmap )
250  return *(mpImplWallpaper->mpBitmap);
251  else
252  return BitmapEx();
253 }
254 
256 {
257  return bool(mpImplWallpaper->mpBitmap);
258 }
259 
260 void Wallpaper::SetGradient( const Gradient& rGradient )
261 {
263 
265  *(mpImplWallpaper->mpGradient) = rGradient;
266  else
267  mpImplWallpaper->mpGradient = std::make_unique<Gradient>( rGradient );
268 
271 }
272 
274 {
277  else if ( mpImplWallpaper->mpGradient )
278  return *(mpImplWallpaper->mpGradient);
279  else
280  return Gradient();
281 }
282 
284 {
285  return bool(mpImplWallpaper->mpGradient);
286 }
287 
289 {
290  Gradient g;
291  g.SetAngle( 900 );
292  g.SetStyle( GradientStyle::Linear );
293  g.SetStartColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
294  // no 'extreme' gradient when high contrast
295  if( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
296  g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
297  else
298  g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceGradientColor() );
299  return g;
300 }
301 
303 {
304  if ( rRect.IsEmpty() )
305  {
306  mpImplWallpaper->mpRect.reset();
307  }
308  else
309  {
310  mpImplWallpaper->mpRect = rRect;
311  }
312 }
313 
315 {
316  if ( mpImplWallpaper->mpRect )
317  return *mpImplWallpaper->mpRect;
318  else
319  return tools::Rectangle();
320 }
321 
322 bool Wallpaper::IsRect() const
323 {
324  return bool(mpImplWallpaper->mpRect);
325 }
326 
327 bool Wallpaper::IsFixed() const
328 {
330  return false;
331  else
333 }
334 
336 {
338  return false;
340  return true;
341  else if ( mpImplWallpaper->mpBitmap )
343  else
344  return false;
345 }
346 
347 Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default;
348 
350 
351 bool Wallpaper::operator==( const Wallpaper& rWallpaper ) const
352 {
353  return mpImplWallpaper.same_object(rWallpaper.mpImplWallpaper);
354 }
355 
356 SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rWallpaper )
357 {
358  return ReadImplWallpaper( rIStm, *rWallpaper.mpImplWallpaper );
359 }
360 
361 SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rWallpaper )
362 {
363  return WriteImplWallpaper( rOStm, *rWallpaper.mpImplWallpaper );
364 }
365 
366 /* 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:190
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:704
static SAL_DLLPRIVATE Gradient ImplGetApplicationGradient()
Definition: wall.cxx:288
SvStream & ReadCharAsBool(bool &rBool)
void SetColor(const Color &rColor)
Definition: wall.cxx:195
WallpaperStyle GetStyle() const
Definition: wall.cxx:219
sal_uInt32 mValue
NONE
SvStream & WriteWallpaper(SvStream &rOStm, const Wallpaper &rWallpaper)
Definition: wall.cxx:361
bool operator==(const Wallpaper &rWallpaper) const
Definition: wall.cxx:351
bool IsEmpty() const
boost::optional< tools::Rectangle > mpRect
Definition: wall2.hxx:30
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
bool ReadDIBBitmapEx(BitmapEx &rTarget, SvStream &rIStm, bool bFileHeader, bool bMSOFormat)
Definition: dibtools.cxx:1740
SvStream & ReadWallpaper(SvStream &rIStm, Wallpaper &rWallpaper)
Definition: wall.cxx:356
ImplWallpaper()
Definition: wall.cxx:32
void SetStartColor(const Color &rColor)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SAL_DLLPRIVATE const BitmapEx * ImplGetCachedBitmap() const
Definition: wall.cxx:185
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
tools::Rectangle GetRect() const
Definition: wall.cxx:314
bool WriteDIBBitmapEx(const BitmapEx &rSource, SvStream &rOStm)
Definition: dibtools.cxx:1871
sal_uInt16 GetVersion() const
void SetRect(const tools::Rectangle &rRect)
Definition: wall.cxx:302
bool IsRect() const
Definition: wall.cxx:322
std::unique_ptr< Gradient > mpGradient
Definition: wall2.hxx:32
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:209
void SetBitmap(const BitmapEx &rBitmap)
Definition: wall.cxx:224
const Color & GetColor() const
Definition: wall.cxx:204
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:327
Gradient GetGradient() const
Definition: wall.cxx:273
BitmapEx GetBitmap() const
Definition: wall.cxx:247
bool IsGradient() const
Definition: wall.cxx:283
ImplType mpImplWallpaper
Definition: wall.hxx:60
void SetAngle(sal_uInt16 nAngle)
WallpaperStyle
Definition: wall.hxx:32
bool IsScrollable() const
Definition: wall.cxx:335
bool IsBitmap() const
Definition: wall.cxx:255
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:177
void readColor(Color &rColor)
std::unique_ptr< BitmapEx > mpBitmap
Definition: wall2.hxx:31
void SetGradient(const Gradient &rGradient)
Definition: wall.cxx:260