LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsTheme.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 102 113 90.3 %
Date: 2015-06-13 12:38:46 Functions: 11 11 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        1792 : ColorData ChangeLuminance (const ColorData aColorData, const int nValue)
      38             : {
      39        1792 :     Color aColor (aColorData);
      40        1792 :     if (nValue > 0)
      41        1024 :         aColor.IncreaseLuminance(nValue);
      42             :     else
      43         768 :         aColor.DecreaseLuminance(-nValue);
      44        1792 :     return aColor.GetColor();
      45             : }
      46             : 
      47         320 : ColorData HGBAdapt (
      48             :     const ColorData aColorData,
      49             :     const sal_Int32 nNewSaturation,
      50             :     const sal_Int32 nNewBrightness)
      51             : {
      52         320 :     sal_uInt16 nHue (0);
      53         320 :     sal_uInt16 nSaturation (0);
      54         320 :     sal_uInt16 nBrightness (0);
      55         320 :     Color(aColorData).RGBtoHSB(nHue, nSaturation, nBrightness);
      56             :     return Color::HSBtoRGB(
      57             :         nHue,
      58             :         nNewSaturation>=0 ? nNewSaturation : nSaturation,
      59         320 :         nNewBrightness>=0 ? nNewBrightness : nBrightness);
      60             : }
      61             : 
      62          64 : Theme::Theme (const ::boost::shared_ptr<controller::Properties>& rpProperties)
      63         128 :     : maBackgroundColor(rpProperties->GetBackgroundColor().GetColor()),
      64             :       maPageBackgroundColor(COL_WHITE),
      65             :       maGradients(),
      66             :       maIcons(),
      67         128 :       maColor()
      68             : {
      69             :     {
      70          64 :         LocalResource aResource (RID_SLIDESORTER_ICONS);
      71             : 
      72          64 :         maColor.resize(_ColorType_Size_);
      73          64 :         maColor[Color_Background] = maBackgroundColor;
      74          64 :         maColor[Color_PageNumberDefault] = 0x0808080;
      75          64 :         maColor[Color_PageNumberHover] = 0x4c4c4c;
      76          64 :         maColor[Color_PageNumberHighContrast] = White;
      77          64 :         maColor[Color_PageNumberBrightBackground] = 0x333333;
      78          64 :         maColor[Color_PageNumberDarkBackground] = 0xcccccc;
      79          64 :         maColor[Color_PreviewBorder] = 0x949599;
      80             :     }
      81             : 
      82          64 :     Update(rpProperties);
      83          64 : }
      84             : 
      85          64 : void Theme::Update (const ::boost::shared_ptr<controller::Properties>& rpProperties)
      86             : {
      87             :     // Set up colors.
      88          64 :     maBackgroundColor = rpProperties->GetBackgroundColor().GetColor();
      89          64 :     maPageBackgroundColor = svtools::ColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
      90             : 
      91          64 :     maColor[Color_Background] = maBackgroundColor;
      92             : 
      93          64 :     maGradients.resize(_GradientColorType_Size_);
      94             : 
      95          64 :     maColor[Color_Background] = maBackgroundColor;
      96          64 :     const ColorData aSelectionColor (rpProperties->GetSelectionColor().GetColor());
      97          64 :     maColor[Color_Selection] = aSelectionColor;
      98          64 :     if (Color(aSelectionColor).IsBright())
      99           0 :         maColor[Color_PageCountFontColor] = Black;
     100             :     else
     101          64 :         maColor[Color_PageCountFontColor] = White;
     102             : 
     103             :     // Set up gradients.
     104          64 :     SetGradient(Gradient_MouseOverPage, aSelectionColor, 0, 60, +80,+100, +50,+25);
     105          64 :     SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +80,+100, +50,+25);
     106          64 :     SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75);
     107          64 :     SetGradient(Gradient_MouseOverSelected, aSelectionColor, 55, 60, +80,+100, +50,+25);
     108          64 :     SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +80,+100, -50,-75);
     109          64 :     SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 55, 60, +80,+100, -50,-75);
     110             : 
     111          64 :     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          64 :     GetGradient(Gradient_FocusedPage).maFillColor1 = GetGradient(Gradient_NormalPage).maFillColor1;
     116          64 :     GetGradient(Gradient_FocusedPage).maFillColor2 = GetGradient(Gradient_NormalPage).maFillColor2;
     117             : 
     118             :     // Set up icons.
     119          64 :     if (maIcons.empty())
     120             :     {
     121          64 :         LocalResource aResource (RID_SLIDESORTER_ICONS);
     122          64 :         maIcons.resize(_IconType_Size_);
     123             : 
     124          64 :         InitializeIcon(Icon_RawShadow, IMAGE_SHADOW);
     125          64 :         InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW);
     126          64 :         InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY);
     127          64 :         InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER);
     128             :     }
     129          64 : }
     130             : 
     131         390 : ::boost::shared_ptr<vcl::Font> Theme::GetFont (
     132             :     const FontType eType,
     133             :     const OutputDevice& rDevice)
     134             : {
     135         390 :     ::boost::shared_ptr<vcl::Font> pFont;
     136             : 
     137         390 :     switch (eType)
     138             :     {
     139             :         case Font_PageNumber:
     140         390 :             pFont.reset(new vcl::Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
     141         390 :             pFont->SetTransparent(true);
     142         390 :             pFont->SetWeight(WEIGHT_BOLD);
     143         390 :             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         390 :     if (pFont)
     157             :     {
     158             :         // Transform the point size to pixel size.
     159         390 :         const MapMode aFontMapMode (MAP_POINT);
     160         390 :         const Size aFontSize (rDevice.LogicToPixel(pFont->GetSize(), aFontMapMode));
     161             : 
     162             :         // Transform the font size to the logical coordinates of the device.
     163         390 :         pFont->SetSize(rDevice.PixelToLogic(aFontSize));
     164             :     }
     165             : 
     166         390 :     return pFont;
     167             : }
     168             : 
     169        1088 : ColorData Theme::GetColor (const ColorType eType)
     170             : {
     171        1088 :     if (eType>=0 && sal_uInt32(eType)<maColor.size())
     172        1088 :         return maColor[eType];
     173             :     else
     174           0 :         return 0;
     175             : }
     176             : 
     177        1280 : ColorData Theme::GetGradientColor (
     178             :     const GradientColorType eType,
     179             :     const GradientColorClass eClass)
     180             : {
     181        1280 :     GradientDescriptor& rDescriptor (GetGradient(eType));
     182             : 
     183        1280 :     switch (eClass)
     184             :     {
     185         320 :         case Border1: return rDescriptor.maBorderColor1;
     186         320 :         case Border2: return rDescriptor.maBorderColor2;
     187         320 :         case Fill1: return rDescriptor.maFillColor1;
     188         320 :         case Fill2: return rDescriptor.maFillColor2;
     189             :         default: OSL_ASSERT(false); // fall through
     190           0 :         case Base: return rDescriptor.maBaseColor;
     191             :     }
     192             : }
     193             : 
     194         448 : 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         448 :     GradientDescriptor& rGradient (GetGradient(eType));
     205             : 
     206         448 :     rGradient.maBaseColor = aBaseColor;
     207             : 
     208         448 :     rGradient.mnSaturationOverride = nSaturationOverride;
     209         448 :     rGradient.mnBrightnessOverride = nBrightnessOverride;
     210         128 :     const ColorData aColor (nSaturationOverride>=0 || nBrightnessOverride>=0
     211             :         ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride)
     212         768 :         : aBaseColor);
     213             : 
     214         448 :     rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset);
     215         448 :     rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset);
     216         448 :     rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset);
     217         448 :     rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset);
     218             : 
     219         448 :     rGradient.mnFillOffset1 = nFillStartOffset;
     220         448 :     rGradient.mnFillOffset2 = nFillEndOffset;
     221         448 :     rGradient.mnBorderOffset1 = nBorderStartOffset;
     222         448 :     rGradient.mnBorderOffset2 = nBorderEndOffset;
     223         448 : }
     224             : 
     225         192 : const BitmapEx& Theme::GetIcon (const IconType eType)
     226             : {
     227         192 :     if (eType>=0 && size_t(eType)<maIcons.size())
     228         192 :         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        1984 : Theme::GradientDescriptor& Theme::GetGradient (const GradientColorType eType)
     237             : {
     238        1984 :     if (eType>=0 && size_t(eType)<maGradients.size())
     239        1984 :         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         256 : void Theme::InitializeIcon (const IconType eType, sal_uInt16 nResourceId)
     248             : {
     249         256 :     if (eType>=0 && size_t(eType)<maIcons.size())
     250             :     {
     251         256 :         const BitmapEx aIcon (Image(SdResId(nResourceId)).GetBitmapEx());
     252         256 :         maIcons[eType] = aIcon;
     253             :     }
     254             :     else
     255             :     {
     256             :         OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
     257             :     }
     258         256 : }
     259             : 
     260             : } } } // end of namespace ::sd::slidesorter::view
     261             : 
     262             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11