LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsTheme.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 112 0.0 %
Date: 2014-04-14 Functions: 0 11 0.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             : 
      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           0 : ColorData ChangeLuminance (const ColorData aColorData, const int nValue)
      41             : {
      42           0 :     Color aColor (aColorData);
      43           0 :     if (nValue > 0)
      44           0 :         aColor.IncreaseLuminance(nValue);
      45             :     else
      46           0 :         aColor.DecreaseLuminance(-nValue);
      47           0 :     return aColor.GetColor();
      48             : }
      49             : 
      50           0 : ColorData HGBAdapt (
      51             :     const ColorData aColorData,
      52             :     const sal_Int32 nNewSaturation,
      53             :     const sal_Int32 nNewBrightness)
      54             : {
      55           0 :     sal_uInt16 nHue (0);
      56           0 :     sal_uInt16 nSaturation (0);
      57           0 :     sal_uInt16 nBrightness (0);
      58           0 :     Color(aColorData).RGBtoHSB(nHue, nSaturation, nBrightness);
      59             :     return Color::HSBtoRGB(
      60             :         nHue,
      61             :         nNewSaturation>=0 ? nNewSaturation : nSaturation,
      62           0 :         nNewBrightness>=0 ? nNewBrightness : nBrightness);
      63             : }
      64             : 
      65             : 
      66             : 
      67             : 
      68           0 : Theme::Theme (const ::boost::shared_ptr<controller::Properties>& rpProperties)
      69           0 :     : maBackgroundColor(rpProperties->GetBackgroundColor().GetColor()),
      70             :       maPageBackgroundColor(COL_WHITE),
      71             :       maGradients(),
      72             :       maIcons(),
      73           0 :       maColor()
      74             : {
      75             :     {
      76           0 :         LocalResource aResource (RID_SLIDESORTER_ICONS);
      77             : 
      78           0 :         maColor.resize(_ColorType_Size_);
      79           0 :         maColor[Color_Background] = maBackgroundColor;
      80           0 :         maColor[Color_PageNumberDefault] = 0x0808080;
      81           0 :         maColor[Color_PageNumberHover] = 0x4c4c4c;
      82           0 :         maColor[Color_PageNumberHighContrast] = White;
      83           0 :         maColor[Color_PageNumberBrightBackground] = 0x333333;
      84           0 :         maColor[Color_PageNumberDarkBackground] = 0xcccccc;
      85           0 :         maColor[Color_PreviewBorder] = 0x949599;
      86             :     }
      87             : 
      88           0 :     Update(rpProperties);
      89           0 : }
      90             : 
      91             : 
      92             : 
      93             : 
      94           0 : void Theme::Update (const ::boost::shared_ptr<controller::Properties>& rpProperties)
      95             : {
      96             :     // Set up colors.
      97           0 :     maBackgroundColor = rpProperties->GetBackgroundColor().GetColor();
      98           0 :     maPageBackgroundColor = svtools::ColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
      99             : 
     100           0 :     maColor[Color_Background] = maBackgroundColor;
     101             : 
     102           0 :     maGradients.resize(_GradientColorType_Size_);
     103             : 
     104           0 :     maColor[Color_Background] = maBackgroundColor;
     105           0 :     const ColorData aSelectionColor (rpProperties->GetSelectionColor().GetColor());
     106           0 :     maColor[Color_Selection] = aSelectionColor;
     107           0 :     if (Color(aSelectionColor).IsBright())
     108           0 :         maColor[Color_PageCountFontColor] = Black;
     109             :     else
     110           0 :         maColor[Color_PageCountFontColor] = White;
     111             : 
     112             :     // Set up gradients.
     113           0 :     SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +100,+100, +50,+25);
     114           0 :     SetGradient(Gradient_MouseOverPage, aSelectionColor, 75, 75, +100,+100, +50,+25);
     115           0 :     SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +100,+100, -50,-75);
     116           0 :     SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 75, 75, +100,+100, -50,-75);
     117           0 :     SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75);
     118             : 
     119           0 :     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           0 :     GetGradient(Gradient_FocusedPage).maFillColor1 = GetGradient(Gradient_NormalPage).maFillColor1;
     124           0 :     GetGradient(Gradient_FocusedPage).maFillColor2 = GetGradient(Gradient_NormalPage).maFillColor2;
     125             : 
     126             :     // Set up icons.
     127           0 :     if (maIcons.empty())
     128             :     {
     129           0 :         LocalResource aResource (RID_SLIDESORTER_ICONS);
     130           0 :         maIcons.resize(_IconType_Size_);
     131             : 
     132           0 :         InitializeIcon(Icon_RawShadow, IMAGE_SHADOW);
     133           0 :         InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW);
     134           0 :         InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY);
     135           0 :         InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER);
     136             :     }
     137           0 : }
     138             : 
     139             : 
     140             : 
     141             : 
     142           0 : ::boost::shared_ptr<Font> Theme::GetFont (
     143             :     const FontType eType,
     144             :     const OutputDevice& rDevice)
     145             : {
     146           0 :     ::boost::shared_ptr<Font> pFont;
     147             : 
     148           0 :     switch (eType)
     149             :     {
     150             :         case Font_PageNumber:
     151           0 :             pFont.reset(new Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
     152           0 :             pFont->SetTransparent(true);
     153           0 :             pFont->SetWeight(WEIGHT_BOLD);
     154           0 :             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           0 :     if (pFont)
     168             :     {
     169             :         // Transform the point size to pixel size.
     170           0 :         const MapMode aFontMapMode (MAP_POINT);
     171           0 :         const Size aFontSize (rDevice.LogicToPixel(pFont->GetSize(), aFontMapMode));
     172             : 
     173             :         // Transform the font size to the logical coordinates of the device.
     174           0 :         pFont->SetSize(rDevice.PixelToLogic(aFontSize));
     175             :     }
     176             : 
     177           0 :     return pFont;
     178             : }
     179             : 
     180             : 
     181             : 
     182             : 
     183           0 : ColorData Theme::GetColor (const ColorType eType)
     184             : {
     185           0 :     if (eType>=0 && sal_uInt32(eType)<maColor.size())
     186           0 :         return maColor[eType];
     187             :     else
     188           0 :         return 0;
     189             : }
     190             : 
     191             : 
     192             : 
     193             : 
     194           0 : ColorData Theme::GetGradientColor (
     195             :     const GradientColorType eType,
     196             :     const GradientColorClass eClass)
     197             : {
     198           0 :     GradientDescriptor& rDescriptor (GetGradient(eType));
     199             : 
     200           0 :     switch (eClass)
     201             :     {
     202           0 :         case Border1: return rDescriptor.maBorderColor1;
     203           0 :         case Border2: return rDescriptor.maBorderColor2;
     204           0 :         case Fill1: return rDescriptor.maFillColor1;
     205           0 :         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           0 : 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           0 :     GradientDescriptor& rGradient (GetGradient(eType));
     225             : 
     226           0 :     rGradient.maBaseColor = aBaseColor;
     227             : 
     228           0 :     rGradient.mnSaturationOverride = nSaturationOverride;
     229           0 :     rGradient.mnBrightnessOverride = nBrightnessOverride;
     230           0 :     const ColorData aColor (nSaturationOverride>=0 || nBrightnessOverride>=0
     231             :         ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride)
     232           0 :         : aBaseColor);
     233             : 
     234           0 :     rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset);
     235           0 :     rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset);
     236           0 :     rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset);
     237           0 :     rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset);
     238             : 
     239           0 :     rGradient.mnFillOffset1 = nFillStartOffset;
     240           0 :     rGradient.mnFillOffset2 = nFillEndOffset;
     241           0 :     rGradient.mnBorderOffset1 = nBorderStartOffset;
     242           0 :     rGradient.mnBorderOffset2 = nBorderEndOffset;
     243           0 : }
     244             : 
     245             : 
     246             : 
     247             : 
     248           0 : const BitmapEx& Theme::GetIcon (const IconType eType)
     249             : {
     250           0 :     if (eType>=0 && size_t(eType)<maIcons.size())
     251           0 :         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           0 : Theme::GradientDescriptor& Theme::GetGradient (const GradientColorType eType)
     263             : {
     264           0 :     if (eType>=0 && size_t(eType)<maGradients.size())
     265           0 :         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           0 : void Theme::InitializeIcon (const IconType eType, sal_uInt16 nResourceId)
     277             : {
     278           0 :     if (eType>=0 && size_t(eType)<maIcons.size())
     279             :     {
     280           0 :         const BitmapEx aIcon (Image(SdResId(nResourceId)).GetBitmapEx());
     281           0 :         maIcons[eType] = aIcon;
     282             :     }
     283             :     else
     284             :     {
     285             :         OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
     286             :     }
     287           0 : }
     288             : 
     289             : 
     290             : 
     291             : 
     292             : } } } // end of namespace ::sd::slidesorter::view
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10