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