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