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

Generated by: LCOV version 1.10