1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 #include <vcl/TypeSerializer.hxx>
30 SvStream
& ReadWallpaper( SvStream
& rIStm
, Wallpaper
& rImplWallpaper
)
32 VersionCompatRead
aCompat(rIStm
);
34 rImplWallpaper
.maRect
.SetEmpty();
35 rImplWallpaper
.mpGradient
.reset();
36 rImplWallpaper
.maBitmap
.SetEmpty();
39 TypeSerializer
aSerializer(rIStm
);
40 aSerializer
.readColor(rImplWallpaper
.maColor
);
42 rIStm
.ReadUInt16(nTmp16
);
43 rImplWallpaper
.meStyle
= static_cast<WallpaperStyle
>(nTmp16
);
46 if( aCompat
.GetVersion() >= 2 )
48 bool bRect(false), bGrad(false), bBmp(false), bDummy
;
50 rIStm
.ReadCharAsBool( bRect
).ReadCharAsBool( bGrad
).ReadCharAsBool( bBmp
).ReadCharAsBool( bDummy
).ReadCharAsBool( bDummy
).ReadCharAsBool( bDummy
);
54 rImplWallpaper
.maRect
= tools::Rectangle();
55 aSerializer
.readRectangle(rImplWallpaper
.maRect
);
60 rImplWallpaper
.mpGradient
.emplace();
61 aSerializer
.readGradient(*rImplWallpaper
.mpGradient
);
66 rImplWallpaper
.maBitmap
.SetEmpty();
67 ReadDIBBitmapEx(rImplWallpaper
.maBitmap
, rIStm
);
70 // version 3 (new color format)
71 if( aCompat
.GetVersion() >= 3 )
74 rIStm
.ReadUInt32(nTmp
);
75 rImplWallpaper
.maColor
= ::Color(ColorTransparency
, nTmp
);
82 SvStream
& WriteWallpaper( SvStream
& rOStm
, const Wallpaper
& rImplWallpaper
)
84 VersionCompatWrite
aCompat(rOStm
, 3);
85 bool bRect
= !rImplWallpaper
.maRect
.IsEmpty();
86 bool bGrad
= bool(rImplWallpaper
.mpGradient
);
87 bool bBmp
= !rImplWallpaper
.maBitmap
.IsEmpty();
91 TypeSerializer
aSerializer(rOStm
);
92 aSerializer
.writeColor(rImplWallpaper
.maColor
);
94 rOStm
.WriteUInt16( static_cast<sal_uInt16
>(rImplWallpaper
.meStyle
) );
97 rOStm
.WriteBool( bRect
).WriteBool( bGrad
).WriteBool( bBmp
).WriteBool( bDummy
).WriteBool( bDummy
).WriteBool( bDummy
);
101 aSerializer
.writeRectangle(rImplWallpaper
.maRect
);
106 aSerializer
.writeGradient(*rImplWallpaper
.mpGradient
);
110 WriteDIBBitmapEx(rImplWallpaper
.maBitmap
, rOStm
);
112 // version 3 (new color format)
113 rOStm
.WriteUInt32(static_cast<sal_uInt32
>(rImplWallpaper
.maColor
));
118 Wallpaper::Wallpaper() :
119 maColor( COL_TRANSPARENT
), meStyle( WallpaperStyle::NONE
)
123 Wallpaper::Wallpaper( const Wallpaper
& ) = default;
125 Wallpaper::Wallpaper( Wallpaper
&& ) = default;
127 Wallpaper::Wallpaper( const Color
& rColor
)
130 meStyle
= WallpaperStyle::Tile
;
133 Wallpaper::Wallpaper( const BitmapEx
& rBmpEx
)
136 meStyle
= WallpaperStyle::Tile
;
139 Wallpaper::~Wallpaper() = default;
141 void Wallpaper::ImplSetCachedBitmap( BitmapEx
& rBmp
) const
146 const BitmapEx
* Wallpaper::ImplGetCachedBitmap() const
148 return maCache
.IsEmpty() ? nullptr : &maCache
;
151 void Wallpaper::ImplReleaseCachedBitmap() const
156 void Wallpaper::SetColor( const Color
& rColor
)
161 if( WallpaperStyle::NONE
== meStyle
|| WallpaperStyle::ApplicationGradient
== meStyle
)
162 meStyle
= WallpaperStyle::Tile
;
165 void Wallpaper::SetStyle( WallpaperStyle eStyle
)
167 if( eStyle
== WallpaperStyle::ApplicationGradient
)
168 // set a dummy gradient, the correct gradient
169 // will be created dynamically in GetGradient()
170 SetGradient( ImplGetApplicationGradient() );
175 void Wallpaper::SetBitmap( const BitmapEx
& rBitmap
)
180 if( WallpaperStyle::NONE
== meStyle
|| WallpaperStyle::ApplicationGradient
== meStyle
)
181 meStyle
= WallpaperStyle::Tile
;
184 const BitmapEx
& Wallpaper::GetBitmap() const
189 bool Wallpaper::IsBitmap() const
191 return !maBitmap
.IsEmpty();
194 void Wallpaper::SetGradient( const Gradient
& rGradient
)
197 mpGradient
= rGradient
;
199 if( WallpaperStyle::NONE
== meStyle
|| WallpaperStyle::ApplicationGradient
== meStyle
)
200 meStyle
= WallpaperStyle::Tile
;
203 Gradient
Wallpaper::GetGradient() const
205 if( WallpaperStyle::ApplicationGradient
== meStyle
)
206 return ImplGetApplicationGradient();
207 else if ( mpGradient
)
213 bool Wallpaper::IsGradient() const
215 return bool(mpGradient
);
218 Gradient
Wallpaper::ImplGetApplicationGradient()
221 g
.SetAngle( 900_deg10
);
222 g
.SetStyle( 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() );
228 g
.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceGradientColor() );
232 bool Wallpaper::IsRect() const
234 return !maRect
.IsEmpty();
237 bool Wallpaper::IsFixed() const
239 if ( meStyle
== WallpaperStyle::NONE
)
242 return (maBitmap
.IsEmpty() && !mpGradient
);
245 bool Wallpaper::IsScrollable() const
247 if ( meStyle
== WallpaperStyle::NONE
)
249 else if ( maBitmap
.IsEmpty() && !mpGradient
)
251 else if ( !maBitmap
.IsEmpty() )
252 return (meStyle
== WallpaperStyle::Tile
);
257 Wallpaper
& Wallpaper::operator=( const Wallpaper
& ) = default;
259 Wallpaper
& Wallpaper::operator=( Wallpaper
&& ) = default;
261 bool Wallpaper::operator==( const Wallpaper
& rOther
) const
263 return meStyle
== rOther
.meStyle
&&
264 maColor
== rOther
.maColor
&&
265 maRect
== rOther
.maRect
&&
266 maBitmap
== rOther
.maBitmap
&&
267 mpGradient
== rOther
.mpGradient
;
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */