LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsTheme.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 103 114 90.4 %
Date: 2014-11-03 Functions: 13 13 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10