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 "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
);
41 aColor
.IncreaseLuminance(nValue
);
43 aColor
.DecreaseLuminance(-nValue
);
44 return aColor
.GetColor();
48 const ColorData aColorData
,
49 const sal_Int32 nNewSaturation
,
50 const sal_Int32 nNewBrightness
)
53 sal_uInt16
nSaturation (0);
54 sal_uInt16
nBrightness (0);
55 Color(aColorData
).RGBtoHSB(nHue
, nSaturation
, nBrightness
);
56 return Color::HSBtoRGB(
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
),
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;
85 void Theme::Update (const ::boost::shared_ptr
<controller::Properties
>& rpProperties
)
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
;
101 maColor
[Color_PageCountFontColor
] = White
;
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
;
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
;
139 case Font_PageNumber
:
140 pFont
.reset(new vcl::Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
141 pFont
->SetTransparent(true);
142 pFont
->SetWeight(WEIGHT_BOLD
);
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));
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
));
169 ColorData
Theme::GetColor (const ColorType eType
)
171 if (eType
>=0 && sal_uInt32(eType
)<maColor
.size())
172 return maColor
[eType
];
177 ColorData
Theme::GetGradientColor (
178 const GradientColorType eType
,
179 const GradientColorClass eClass
)
181 GradientDescriptor
& rDescriptor (GetGradient(eType
));
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
)
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
];
231 OSL_ASSERT(eType
>=0 && size_t(eType
)<maIcons
.size());
236 Theme::GradientDescriptor
& Theme::GetGradient (const GradientColorType eType
)
238 if (eType
>=0 && size_t(eType
)<maGradients
.size())
239 return maGradients
[eType
];
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
;
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: */