Line data Source code
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 :
21 : #include "view/SlsTheme.hxx"
22 : #include "SlsResource.hxx"
23 : #include "controller/SlsProperties.hxx"
24 : #include "sdresid.hxx"
25 : #include <tools/color.hxx>
26 : #include <vcl/outdev.hxx>
27 : #include <vcl/image.hxx>
28 : #include <vcl/svapp.hxx>
29 : #include <vcl/settings.hxx>
30 :
31 : #include <svtools/colorcfg.hxx>
32 :
33 : namespace sd { namespace slidesorter { namespace view {
34 :
35 : const static ColorData Black = 0x000000;
36 : const static ColorData White = 0xffffff;
37 :
38 :
39 :
40 1512 : ColorData ChangeLuminance (const ColorData aColorData, const int nValue)
41 : {
42 1512 : Color aColor (aColorData);
43 1512 : if (nValue > 0)
44 756 : aColor.IncreaseLuminance(nValue);
45 : else
46 756 : aColor.DecreaseLuminance(-nValue);
47 1512 : return aColor.GetColor();
48 : }
49 :
50 252 : ColorData HGBAdapt (
51 : const ColorData aColorData,
52 : const sal_Int32 nNewSaturation,
53 : const sal_Int32 nNewBrightness)
54 : {
55 252 : sal_uInt16 nHue (0);
56 252 : sal_uInt16 nSaturation (0);
57 252 : sal_uInt16 nBrightness (0);
58 252 : Color(aColorData).RGBtoHSB(nHue, nSaturation, nBrightness);
59 : return Color::HSBtoRGB(
60 : nHue,
61 : nNewSaturation>=0 ? nNewSaturation : nSaturation,
62 252 : nNewBrightness>=0 ? nNewBrightness : nBrightness);
63 : }
64 :
65 :
66 :
67 :
68 63 : Theme::Theme (const ::boost::shared_ptr<controller::Properties>& rpProperties)
69 126 : : maBackgroundColor(rpProperties->GetBackgroundColor().GetColor()),
70 : maPageBackgroundColor(COL_WHITE),
71 : maGradients(),
72 : maIcons(),
73 126 : maColor()
74 : {
75 : {
76 63 : LocalResource aResource (RID_SLIDESORTER_ICONS);
77 :
78 63 : maColor.resize(_ColorType_Size_);
79 63 : maColor[Color_Background] = maBackgroundColor;
80 63 : maColor[Color_PageNumberDefault] = 0x0808080;
81 63 : maColor[Color_PageNumberHover] = 0x4c4c4c;
82 63 : maColor[Color_PageNumberHighContrast] = White;
83 63 : maColor[Color_PageNumberBrightBackground] = 0x333333;
84 63 : maColor[Color_PageNumberDarkBackground] = 0xcccccc;
85 63 : maColor[Color_PreviewBorder] = 0x949599;
86 : }
87 :
88 63 : Update(rpProperties);
89 63 : }
90 :
91 :
92 :
93 :
94 63 : void Theme::Update (const ::boost::shared_ptr<controller::Properties>& rpProperties)
95 : {
96 : // Set up colors.
97 63 : maBackgroundColor = rpProperties->GetBackgroundColor().GetColor();
98 63 : maPageBackgroundColor = svtools::ColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
99 :
100 63 : maColor[Color_Background] = maBackgroundColor;
101 :
102 63 : maGradients.resize(_GradientColorType_Size_);
103 :
104 63 : maColor[Color_Background] = maBackgroundColor;
105 63 : const ColorData aSelectionColor (rpProperties->GetSelectionColor().GetColor());
106 63 : maColor[Color_Selection] = aSelectionColor;
107 63 : if (Color(aSelectionColor).IsBright())
108 0 : maColor[Color_PageCountFontColor] = Black;
109 : else
110 63 : maColor[Color_PageCountFontColor] = White;
111 :
112 : // Set up gradients.
113 63 : SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +100,+100, +50,+25);
114 63 : SetGradient(Gradient_MouseOverPage, aSelectionColor, 75, 75, +100,+100, +50,+25);
115 63 : SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +100,+100, -50,-75);
116 63 : SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 75, 75, +100,+100, -50,-75);
117 63 : SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75);
118 :
119 63 : SetGradient(Gradient_NormalPage, maBackgroundColor, -1,-1, 0,0, 0,0);
120 :
121 : // The focused gradient needs special handling because its fill color is
122 : // like that of the NormalPage gradient.
123 63 : GetGradient(Gradient_FocusedPage).maFillColor1 = GetGradient(Gradient_NormalPage).maFillColor1;
124 63 : GetGradient(Gradient_FocusedPage).maFillColor2 = GetGradient(Gradient_NormalPage).maFillColor2;
125 :
126 : // Set up icons.
127 63 : if (maIcons.empty())
128 : {
129 63 : LocalResource aResource (RID_SLIDESORTER_ICONS);
130 63 : maIcons.resize(_IconType_Size_);
131 :
132 63 : InitializeIcon(Icon_RawShadow, IMAGE_SHADOW);
133 63 : InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW);
134 63 : InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY);
135 63 : InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER);
136 : }
137 63 : }
138 :
139 :
140 :
141 :
142 384 : ::boost::shared_ptr<Font> Theme::GetFont (
143 : const FontType eType,
144 : const OutputDevice& rDevice)
145 : {
146 384 : ::boost::shared_ptr<Font> pFont;
147 :
148 384 : switch (eType)
149 : {
150 : case Font_PageNumber:
151 384 : pFont.reset(new Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
152 384 : pFont->SetTransparent(true);
153 384 : pFont->SetWeight(WEIGHT_BOLD);
154 384 : break;
155 :
156 : case Font_PageCount:
157 0 : pFont.reset(new Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
158 0 : pFont->SetTransparent(true);
159 0 : pFont->SetWeight(WEIGHT_NORMAL);
160 : {
161 0 : const Size aSize (pFont->GetSize());
162 0 : pFont->SetSize(Size(aSize.Width()*5/3, aSize.Height()*5/3));
163 : }
164 0 : break;
165 : }
166 :
167 384 : if (pFont)
168 : {
169 : // Transform the point size to pixel size.
170 384 : const MapMode aFontMapMode (MAP_POINT);
171 384 : const Size aFontSize (rDevice.LogicToPixel(pFont->GetSize(), aFontMapMode));
172 :
173 : // Transform the font size to the logical coordinates of the device.
174 384 : pFont->SetSize(rDevice.PixelToLogic(aFontSize));
175 : }
176 :
177 384 : return pFont;
178 : }
179 :
180 :
181 :
182 :
183 892 : ColorData Theme::GetColor (const ColorType eType)
184 : {
185 892 : if (eType>=0 && sal_uInt32(eType)<maColor.size())
186 892 : return maColor[eType];
187 : else
188 0 : return 0;
189 : }
190 :
191 :
192 :
193 :
194 296 : ColorData Theme::GetGradientColor (
195 : const GradientColorType eType,
196 : const GradientColorClass eClass)
197 : {
198 296 : GradientDescriptor& rDescriptor (GetGradient(eType));
199 :
200 296 : switch (eClass)
201 : {
202 74 : case Border1: return rDescriptor.maBorderColor1;
203 74 : case Border2: return rDescriptor.maBorderColor2;
204 74 : case Fill1: return rDescriptor.maFillColor1;
205 74 : case Fill2: return rDescriptor.maFillColor2;
206 : default: OSL_ASSERT(false); // fall through
207 0 : case Base: return rDescriptor.maBaseColor;
208 : }
209 : }
210 :
211 :
212 :
213 :
214 378 : void Theme::SetGradient (
215 : const GradientColorType eType,
216 : const ColorData aBaseColor,
217 : const sal_Int32 nSaturationOverride,
218 : const sal_Int32 nBrightnessOverride,
219 : const sal_Int32 nFillStartOffset,
220 : const sal_Int32 nFillEndOffset,
221 : const sal_Int32 nBorderStartOffset,
222 : const sal_Int32 nBorderEndOffset)
223 : {
224 378 : GradientDescriptor& rGradient (GetGradient(eType));
225 :
226 378 : rGradient.maBaseColor = aBaseColor;
227 :
228 378 : rGradient.mnSaturationOverride = nSaturationOverride;
229 378 : rGradient.mnBrightnessOverride = nBrightnessOverride;
230 126 : const ColorData aColor (nSaturationOverride>=0 || nBrightnessOverride>=0
231 : ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride)
232 630 : : aBaseColor);
233 :
234 378 : rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset);
235 378 : rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset);
236 378 : rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset);
237 378 : rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset);
238 :
239 378 : rGradient.mnFillOffset1 = nFillStartOffset;
240 378 : rGradient.mnFillOffset2 = nFillEndOffset;
241 378 : rGradient.mnBorderOffset1 = nBorderStartOffset;
242 378 : rGradient.mnBorderOffset2 = nBorderEndOffset;
243 378 : }
244 :
245 :
246 :
247 :
248 189 : const BitmapEx& Theme::GetIcon (const IconType eType)
249 : {
250 189 : if (eType>=0 && size_t(eType)<maIcons.size())
251 189 : return maIcons[eType];
252 : else
253 : {
254 : OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
255 0 : return maIcons[0];
256 : }
257 : }
258 :
259 :
260 :
261 :
262 926 : Theme::GradientDescriptor& Theme::GetGradient (const GradientColorType eType)
263 : {
264 926 : if (eType>=0 && size_t(eType)<maGradients.size())
265 926 : return maGradients[eType];
266 : else
267 : {
268 : OSL_ASSERT(eType>=0 && size_t(eType)<maGradients.size());
269 0 : return maGradients[0];
270 : }
271 : }
272 :
273 :
274 :
275 :
276 252 : void Theme::InitializeIcon (const IconType eType, sal_uInt16 nResourceId)
277 : {
278 252 : if (eType>=0 && size_t(eType)<maIcons.size())
279 : {
280 252 : const BitmapEx aIcon (Image(SdResId(nResourceId)).GetBitmapEx());
281 252 : maIcons[eType] = aIcon;
282 : }
283 : else
284 : {
285 : OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
286 : }
287 252 : }
288 :
289 :
290 :
291 :
292 : } } } // end of namespace ::sd::slidesorter::view
293 :
294 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|