/src/libreoffice/vcl/source/gdi/wall.cxx
Line | Count | Source |
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/bitmap.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> |
29 | | |
30 | | #include <com/sun/star/awt/GradientStyle.hpp> |
31 | | |
32 | | SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rImplWallpaper ) |
33 | 2.95k | { |
34 | 2.95k | VersionCompatRead aCompat(rIStm); |
35 | | |
36 | 2.95k | rImplWallpaper.maRect.SetEmpty(); |
37 | 2.95k | rImplWallpaper.mpGradient.reset(); |
38 | 2.95k | rImplWallpaper.maBitmap.SetEmpty(); |
39 | | |
40 | | // version 1 |
41 | 2.95k | TypeSerializer aSerializer(rIStm); |
42 | 2.95k | aSerializer.readColor(rImplWallpaper.maColor); |
43 | 2.95k | sal_uInt16 nTmp16(0); |
44 | 2.95k | rIStm.ReadUInt16(nTmp16); |
45 | 2.95k | rImplWallpaper.meStyle = static_cast<WallpaperStyle>(nTmp16); |
46 | | |
47 | | // version 2 |
48 | 2.95k | if( aCompat.GetVersion() >= 2 ) |
49 | 2.00k | { |
50 | 2.00k | bool bRect(false), bGrad(false), bBmp(false), bDummy; |
51 | | |
52 | 2.00k | rIStm.ReadCharAsBool( bRect ).ReadCharAsBool( bGrad ).ReadCharAsBool( bBmp ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy ).ReadCharAsBool( bDummy ); |
53 | | |
54 | 2.00k | if( bRect ) |
55 | 647 | { |
56 | 647 | rImplWallpaper.maRect = tools::Rectangle(); |
57 | 647 | aSerializer.readRectangle(rImplWallpaper.maRect); |
58 | 647 | } |
59 | | |
60 | 2.00k | if( bGrad ) |
61 | 636 | { |
62 | 636 | rImplWallpaper.mpGradient.emplace(); |
63 | 636 | aSerializer.readGradient(*rImplWallpaper.mpGradient); |
64 | 636 | } |
65 | | |
66 | 2.00k | if( bBmp ) |
67 | 5 | { |
68 | 5 | rImplWallpaper.maBitmap.SetEmpty(); |
69 | 5 | ReadDIBBitmapEx(rImplWallpaper.maBitmap, rIStm); |
70 | 5 | } |
71 | | |
72 | | // version 3 (new color format) |
73 | 2.00k | if( aCompat.GetVersion() >= 3 ) |
74 | 1.41k | { |
75 | 1.41k | sal_uInt32 nTmp; |
76 | 1.41k | rIStm.ReadUInt32(nTmp); |
77 | 1.41k | rImplWallpaper.maColor = ::Color(ColorTransparency, nTmp); |
78 | 1.41k | } |
79 | 2.00k | } |
80 | | |
81 | 2.95k | return rIStm; |
82 | 2.95k | } |
83 | | |
84 | | SvStream& WriteWallpaper( SvStream& rOStm, const Wallpaper& rImplWallpaper ) |
85 | 0 | { |
86 | 0 | VersionCompatWrite aCompat(rOStm, 3); |
87 | 0 | bool bRect = !rImplWallpaper.maRect.IsEmpty(); |
88 | 0 | bool bGrad = bool(rImplWallpaper.mpGradient); |
89 | 0 | bool bBmp = !rImplWallpaper.maBitmap.IsEmpty(); |
90 | 0 | bool bDummy = false; |
91 | | |
92 | | // version 1 |
93 | 0 | TypeSerializer aSerializer(rOStm); |
94 | 0 | aSerializer.writeColor(rImplWallpaper.maColor); |
95 | |
|
96 | 0 | rOStm.WriteUInt16( static_cast<sal_uInt16>(rImplWallpaper.meStyle) ); |
97 | | |
98 | | // version 2 |
99 | 0 | rOStm.WriteBool( bRect ).WriteBool( bGrad ).WriteBool( bBmp ).WriteBool( bDummy ).WriteBool( bDummy ).WriteBool( bDummy ); |
100 | |
|
101 | 0 | if( bRect ) |
102 | 0 | { |
103 | 0 | aSerializer.writeRectangle(rImplWallpaper.maRect); |
104 | 0 | } |
105 | |
|
106 | 0 | if (bGrad) |
107 | 0 | { |
108 | 0 | aSerializer.writeGradient(*rImplWallpaper.mpGradient); |
109 | 0 | } |
110 | |
|
111 | 0 | if( bBmp ) |
112 | 0 | WriteDIBBitmapEx(rImplWallpaper.maBitmap, rOStm); |
113 | | |
114 | | // version 3 (new color format) |
115 | 0 | rOStm.WriteUInt32(static_cast<sal_uInt32>(rImplWallpaper.maColor)); |
116 | |
|
117 | 0 | return rOStm; |
118 | 0 | } |
119 | | |
120 | | Wallpaper::Wallpaper() : |
121 | 1.68M | maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE ) |
122 | 1.68M | { |
123 | 1.68M | } |
124 | | |
125 | 6.56k | Wallpaper::Wallpaper( const Wallpaper& ) = default; |
126 | | |
127 | 0 | Wallpaper::Wallpaper( Wallpaper&& ) = default; |
128 | | |
129 | | Wallpaper::Wallpaper( const Color& rColor ) |
130 | 1.54M | { |
131 | 1.54M | maColor = rColor; |
132 | 1.54M | meStyle = WallpaperStyle::Tile; |
133 | 1.54M | } |
134 | | |
135 | | Wallpaper::Wallpaper( const Bitmap& rBmp ) |
136 | 3.61k | { |
137 | 3.61k | maBitmap = rBmp; |
138 | 3.61k | meStyle = WallpaperStyle::Tile; |
139 | 3.61k | } |
140 | | |
141 | 3.20M | Wallpaper::~Wallpaper() = default; |
142 | | |
143 | | void Wallpaper::ImplSetCachedBitmap( const Bitmap& rBmp ) const |
144 | 0 | { |
145 | 0 | maCache = rBmp; |
146 | 0 | } |
147 | | |
148 | | const Bitmap* Wallpaper::ImplGetCachedBitmap() const |
149 | 0 | { |
150 | 0 | return maCache.IsEmpty() ? nullptr : &maCache; |
151 | 0 | } |
152 | | |
153 | | void Wallpaper::ImplReleaseCachedBitmap() const |
154 | 0 | { |
155 | 0 | maCache.SetEmpty(); |
156 | 0 | } |
157 | | |
158 | | void Wallpaper::SetColor( const Color& rColor ) |
159 | 0 | { |
160 | 0 | maCache.SetEmpty(); |
161 | 0 | maColor = rColor; |
162 | |
|
163 | 0 | if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle ) |
164 | 0 | meStyle = WallpaperStyle::Tile; |
165 | 0 | } |
166 | | |
167 | | void Wallpaper::SetStyle( WallpaperStyle eStyle ) |
168 | 3.61k | { |
169 | 3.61k | if( eStyle == WallpaperStyle::ApplicationGradient ) |
170 | | // set a dummy gradient, the correct gradient |
171 | | // will be created dynamically in GetGradient() |
172 | 0 | SetGradient( ImplGetApplicationGradient() ); |
173 | | |
174 | 3.61k | meStyle = eStyle; |
175 | 3.61k | } |
176 | | |
177 | | void Wallpaper::SetBitmap( const Bitmap& rBitmap ) |
178 | 0 | { |
179 | 0 | maCache.SetEmpty(); |
180 | 0 | maBitmap = rBitmap; |
181 | |
|
182 | 0 | if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle) |
183 | 0 | meStyle = WallpaperStyle::Tile; |
184 | 0 | } |
185 | | |
186 | | const Bitmap & Wallpaper::GetBitmap() const |
187 | 0 | { |
188 | 0 | return maBitmap; |
189 | 0 | } |
190 | | |
191 | | bool Wallpaper::IsBitmap() const |
192 | 14.0k | { |
193 | 14.0k | return !maBitmap.IsEmpty(); |
194 | 14.0k | } |
195 | | |
196 | | void Wallpaper::SetGradient( const Gradient& rGradient ) |
197 | 0 | { |
198 | 0 | maCache.SetEmpty(); |
199 | 0 | mpGradient = rGradient; |
200 | |
|
201 | 0 | if( WallpaperStyle::NONE == meStyle || WallpaperStyle::ApplicationGradient == meStyle ) |
202 | 0 | meStyle = WallpaperStyle::Tile; |
203 | 0 | } |
204 | | |
205 | | Gradient Wallpaper::GetGradient() const |
206 | 0 | { |
207 | 0 | if( WallpaperStyle::ApplicationGradient == meStyle ) |
208 | 0 | return ImplGetApplicationGradient(); |
209 | 0 | else if ( mpGradient ) |
210 | 0 | return *mpGradient; |
211 | 0 | else |
212 | 0 | return Gradient(); |
213 | 0 | } |
214 | | |
215 | | bool Wallpaper::IsGradient() const |
216 | 34.0k | { |
217 | 34.0k | return bool(mpGradient); |
218 | 34.0k | } |
219 | | |
220 | | Gradient Wallpaper::ImplGetApplicationGradient() |
221 | 0 | { |
222 | 0 | Gradient g; |
223 | 0 | g.SetAngle( 900_deg10 ); |
224 | 0 | g.SetStyle( css::awt::GradientStyle_LINEAR ); |
225 | 0 | g.SetStartColor( Application::GetSettings().GetStyleSettings().GetFaceColor() ); |
226 | | // no 'extreme' gradient when high contrast |
227 | 0 | if( Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) |
228 | 0 | g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceColor() ); |
229 | 0 | else |
230 | 0 | g.SetEndColor( Application::GetSettings().GetStyleSettings().GetFaceGradientColor() ); |
231 | 0 | return g; |
232 | 0 | } |
233 | | |
234 | | bool Wallpaper::IsRect() const |
235 | 0 | { |
236 | 0 | return !maRect.IsEmpty(); |
237 | 0 | } |
238 | | |
239 | | bool Wallpaper::IsFixed() const |
240 | 0 | { |
241 | 0 | if ( meStyle == WallpaperStyle::NONE ) |
242 | 0 | return false; |
243 | 0 | else |
244 | 0 | return (maBitmap.IsEmpty() && !mpGradient); |
245 | 0 | } |
246 | | |
247 | | bool Wallpaper::IsScrollable() const |
248 | 0 | { |
249 | 0 | if ( meStyle == WallpaperStyle::NONE ) |
250 | 0 | return false; |
251 | 0 | else if ( maBitmap.IsEmpty() && !mpGradient ) |
252 | 0 | return true; |
253 | 0 | else if ( !maBitmap.IsEmpty() ) |
254 | 0 | return (meStyle == WallpaperStyle::Tile); |
255 | 0 | else |
256 | 0 | return false; |
257 | 0 | } |
258 | | |
259 | 1.55M | Wallpaper& Wallpaper::operator=( const Wallpaper& ) = default; |
260 | | |
261 | 16.4k | Wallpaper& Wallpaper::operator=( Wallpaper&& ) = default; |
262 | | |
263 | | bool Wallpaper::operator==( const Wallpaper& rOther ) const |
264 | 0 | { |
265 | 0 | return meStyle == rOther.meStyle && |
266 | 0 | maColor == rOther.maColor && |
267 | 0 | maRect == rOther.maRect && |
268 | 0 | maBitmap == rOther.maBitmap && |
269 | 0 | mpGradient == rOther.mpGradient; |
270 | 0 | } |
271 | | |
272 | | |
273 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |