bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsTheme.cxx
blobd7fddd2b7d5a63f999b9ce25b4823048cabfe985
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "view/SlsTheme.hxx"
21 #include "SlsResource.hxx"
22 #include "controller/SlsProperties.hxx"
23 #include "sdresid.hxx"
24 #include <tools/color.hxx>
25 #include <vcl/outdev.hxx>
26 #include <vcl/image.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
30 #include <svtools/colorcfg.hxx>
32 namespace sd { namespace slidesorter { namespace view {
34 const static ColorData Black = 0x000000;
35 const static ColorData White = 0xffffff;
37 ColorData ChangeLuminance (const ColorData aColorData, const int nValue)
39 Color aColor (aColorData);
40 if (nValue > 0)
41 aColor.IncreaseLuminance(nValue);
42 else
43 aColor.DecreaseLuminance(-nValue);
44 return aColor.GetColor();
47 ColorData HGBAdapt (
48 const ColorData aColorData,
49 const sal_Int32 nNewSaturation,
50 const sal_Int32 nNewBrightness)
52 sal_uInt16 nHue (0);
53 sal_uInt16 nSaturation (0);
54 sal_uInt16 nBrightness (0);
55 Color(aColorData).RGBtoHSB(nHue, nSaturation, nBrightness);
56 return Color::HSBtoRGB(
57 nHue,
58 nNewSaturation>=0 ? nNewSaturation : nSaturation,
59 nNewBrightness>=0 ? nNewBrightness : nBrightness);
62 Theme::Theme (const ::boost::shared_ptr<controller::Properties>& rpProperties)
63 : maBackgroundColor(rpProperties->GetBackgroundColor().GetColor()),
64 maPageBackgroundColor(COL_WHITE),
65 maGradients(),
66 maIcons(),
67 maColor()
70 LocalResource aResource (RID_SLIDESORTER_ICONS);
72 maColor.resize(_ColorType_Size_);
73 maColor[Color_Background] = maBackgroundColor;
74 maColor[Color_PageNumberDefault] = 0x0808080;
75 maColor[Color_PageNumberHover] = 0x4c4c4c;
76 maColor[Color_PageNumberHighContrast] = White;
77 maColor[Color_PageNumberBrightBackground] = 0x333333;
78 maColor[Color_PageNumberDarkBackground] = 0xcccccc;
79 maColor[Color_PreviewBorder] = 0x949599;
82 Update(rpProperties);
85 void Theme::Update (const ::boost::shared_ptr<controller::Properties>& rpProperties)
87 // Set up colors.
88 maBackgroundColor = rpProperties->GetBackgroundColor().GetColor();
89 maPageBackgroundColor = svtools::ColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
91 maColor[Color_Background] = maBackgroundColor;
93 maGradients.resize(_GradientColorType_Size_);
95 maColor[Color_Background] = maBackgroundColor;
96 const ColorData aSelectionColor (rpProperties->GetSelectionColor().GetColor());
97 maColor[Color_Selection] = aSelectionColor;
98 if (Color(aSelectionColor).IsBright())
99 maColor[Color_PageCountFontColor] = Black;
100 else
101 maColor[Color_PageCountFontColor] = White;
103 // Set up gradients.
104 SetGradient(Gradient_MouseOverPage, aSelectionColor, 0, 60, +80,+100, +50,+25);
105 SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +80,+100, +50,+25);
106 SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75);
107 SetGradient(Gradient_MouseOverSelected, aSelectionColor, 55, 60, +80,+100, +50,+25);
108 SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +80,+100, -50,-75);
109 SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 55, 60, +80,+100, -50,-75);
111 SetGradient(Gradient_NormalPage, maBackgroundColor, -1,-1, 0,0, 0,0);
113 // The focused gradient needs special handling because its fill color is
114 // like that of the NormalPage gradient.
115 GetGradient(Gradient_FocusedPage).maFillColor1 = GetGradient(Gradient_NormalPage).maFillColor1;
116 GetGradient(Gradient_FocusedPage).maFillColor2 = GetGradient(Gradient_NormalPage).maFillColor2;
118 // Set up icons.
119 if (maIcons.empty())
121 LocalResource aResource (RID_SLIDESORTER_ICONS);
122 maIcons.resize(_IconType_Size_);
124 InitializeIcon(Icon_RawShadow, IMAGE_SHADOW);
125 InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW);
126 InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY);
127 InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER);
131 ::boost::shared_ptr<vcl::Font> Theme::GetFont (
132 const FontType eType,
133 const OutputDevice& rDevice)
135 ::boost::shared_ptr<vcl::Font> pFont;
137 switch (eType)
139 case Font_PageNumber:
140 pFont.reset(new vcl::Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
141 pFont->SetTransparent(true);
142 pFont->SetWeight(WEIGHT_BOLD);
143 break;
145 case Font_PageCount:
146 pFont.reset(new vcl::Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
147 pFont->SetTransparent(true);
148 pFont->SetWeight(WEIGHT_NORMAL);
150 const Size aSize (pFont->GetSize());
151 pFont->SetSize(Size(aSize.Width()*5/3, aSize.Height()*5/3));
153 break;
156 if (pFont)
158 // Transform the point size to pixel size.
159 const MapMode aFontMapMode (MAP_POINT);
160 const Size aFontSize (rDevice.LogicToPixel(pFont->GetSize(), aFontMapMode));
162 // Transform the font size to the logical coordinates of the device.
163 pFont->SetSize(rDevice.PixelToLogic(aFontSize));
166 return pFont;
169 ColorData Theme::GetColor (const ColorType eType)
171 if (eType>=0 && sal_uInt32(eType)<maColor.size())
172 return maColor[eType];
173 else
174 return 0;
177 ColorData Theme::GetGradientColor (
178 const GradientColorType eType,
179 const GradientColorClass eClass)
181 GradientDescriptor& rDescriptor (GetGradient(eType));
183 switch (eClass)
185 case Border1: return rDescriptor.maBorderColor1;
186 case Border2: return rDescriptor.maBorderColor2;
187 case Fill1: return rDescriptor.maFillColor1;
188 case Fill2: return rDescriptor.maFillColor2;
189 default: OSL_ASSERT(false); // fall through
190 case Base: return rDescriptor.maBaseColor;
194 void Theme::SetGradient (
195 const GradientColorType eType,
196 const ColorData aBaseColor,
197 const sal_Int32 nSaturationOverride,
198 const sal_Int32 nBrightnessOverride,
199 const sal_Int32 nFillStartOffset,
200 const sal_Int32 nFillEndOffset,
201 const sal_Int32 nBorderStartOffset,
202 const sal_Int32 nBorderEndOffset)
204 GradientDescriptor& rGradient (GetGradient(eType));
206 rGradient.maBaseColor = aBaseColor;
208 rGradient.mnSaturationOverride = nSaturationOverride;
209 rGradient.mnBrightnessOverride = nBrightnessOverride;
210 const ColorData aColor (nSaturationOverride>=0 || nBrightnessOverride>=0
211 ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride)
212 : aBaseColor);
214 rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset);
215 rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset);
216 rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset);
217 rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset);
219 rGradient.mnFillOffset1 = nFillStartOffset;
220 rGradient.mnFillOffset2 = nFillEndOffset;
221 rGradient.mnBorderOffset1 = nBorderStartOffset;
222 rGradient.mnBorderOffset2 = nBorderEndOffset;
225 const BitmapEx& Theme::GetIcon (const IconType eType)
227 if (eType>=0 && size_t(eType)<maIcons.size())
228 return maIcons[eType];
229 else
231 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
232 return maIcons[0];
236 Theme::GradientDescriptor& Theme::GetGradient (const GradientColorType eType)
238 if (eType>=0 && size_t(eType)<maGradients.size())
239 return maGradients[eType];
240 else
242 OSL_ASSERT(eType>=0 && size_t(eType)<maGradients.size());
243 return maGradients[0];
247 void Theme::InitializeIcon (const IconType eType, sal_uInt16 nResourceId)
249 if (eType>=0 && size_t(eType)<maIcons.size())
251 const BitmapEx aIcon (Image(SdResId(nResourceId)).GetBitmapEx());
252 maIcons[eType] = aIcon;
254 else
256 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
260 } } } // end of namespace ::sd::slidesorter::view
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */