LCOV - code coverage report
Current view: top level - svx/source/sidebar/tools - ColorControl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 79 1.3 %
Date: 2014-11-03 Functions: 2 12 16.7 %
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 <svx/sidebar/ColorControl.hxx>
      21             : #include "svx/svxids.hrc"
      22             : #include "svx/drawitem.hxx"
      23             : #include "svx/xtable.hxx"
      24             : #include "svx/dialmgr.hxx"
      25             : #include "svx/xflclit.hxx"
      26             : #include <tools/resid.hxx>
      27             : #include <sfx2/sidebar/Theme.hxx>
      28             : #include <sfx2/objsh.hxx>
      29             : #include <sfx2/bindings.hxx>
      30             : #include <sfx2/dispatch.hxx>
      31             : #include <vcl/floatwin.hxx>
      32             : #include <unotools/pathoptions.hxx>
      33             : #include <editeng/editrids.hrc>
      34             : 
      35             : using ::sfx2::sidebar::Theme;
      36             : 
      37             : namespace svx { namespace sidebar {
      38             : 
      39             : namespace {
      40           0 :     short GetItemId_Imp( ValueSet& rValueSet, const Color& rCol )
      41             :     {
      42           0 :         if(rCol == COL_AUTO)
      43           0 :             return 0;
      44             : 
      45           0 :         bool    bFound = false;
      46           0 :         sal_uInt16  nCount = rValueSet.GetItemCount();
      47           0 :         sal_uInt16  n      = 1;
      48             : 
      49           0 :         while ( !bFound && n <= nCount )
      50             :         {
      51           0 :             Color aValCol = rValueSet.GetItemColor(n);
      52             : 
      53           0 :             bFound = (   aValCol.GetRed()   == rCol.GetRed()
      54           0 :                 && aValCol.GetGreen() == rCol.GetGreen()
      55           0 :                 && aValCol.GetBlue()  == rCol.GetBlue() );
      56             : 
      57           0 :             if ( !bFound )
      58           0 :                 n++;
      59             :         }
      60           0 :         return bFound ? n : -1;
      61             :     }
      62           0 :     XColorListRef GetColorTable (void)
      63             :     {
      64           0 :         SfxObjectShell* pDocSh = SfxObjectShell::Current();
      65             :         DBG_ASSERT(pDocSh!=NULL, "DocShell not found!");
      66           0 :         if (pDocSh != NULL)
      67             :         {
      68           0 :             const SfxPoolItem* pItem = pDocSh->GetItem(SID_COLOR_TABLE);
      69           0 :             if (pItem != NULL)
      70             :             {
      71           0 :                 XColorListRef xTable = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
      72           0 :                 if (xTable.is())
      73           0 :                     return xTable;
      74             :             }
      75             :         }
      76             : 
      77           0 :         return XColorList::GetStdColorList();
      78             :     }
      79             : } // end of anonymous namespace
      80             : 
      81             : 
      82             : 
      83             : 
      84           0 : ColorControl::ColorControl (
      85             :     vcl::Window* pParent,
      86             :     SfxBindings* /* pBindings */,
      87             :     const ResId& rControlResId,
      88             :     const ResId& rValueSetResId,
      89             :     const ::boost::function<Color(void)>& rNoColorGetter,
      90             :     const ::boost::function<void(OUString&,Color)>& rColorSetter,
      91             :     FloatingWindow* pFloatingWindow,
      92             :     const ResId* pNoColorStringResId) // const sal_uInt32 nNoColorStringResId)
      93             :     : PopupControl(pParent, rControlResId),
      94             :       maVSColor(this, rValueSetResId),
      95             :       mpFloatingWindow(pFloatingWindow),
      96             :       msNoColorString(
      97             :           pNoColorStringResId
      98             :               ? pNoColorStringResId->toString()
      99             :               : OUString()),
     100             :       maNoColorGetter(rNoColorGetter),
     101           0 :       maColorSetter(rColorSetter)
     102             : {
     103           0 :     FreeResource();
     104           0 :     FillColors();
     105           0 : }
     106             : 
     107             : 
     108             : 
     109           0 : ColorControl::~ColorControl (void)
     110             : {
     111           0 : }
     112             : 
     113             : 
     114             : 
     115             : 
     116           0 : void ColorControl::FillColors (void)
     117             : {
     118           0 :     XColorListRef xColorTable (GetColorTable());
     119             : 
     120           0 :     if (xColorTable.is())
     121             :     {
     122           0 :         const long nColorCount(xColorTable->Count());
     123           0 :         if (nColorCount <= 0)
     124           0 :             return;
     125             : 
     126           0 :         const WinBits aWinBits(maVSColor.GetStyle() | WB_TABSTOP | WB_ITEMBORDER | WB_NAMEFIELD |
     127           0 :             WB_NO_DIRECTSELECT | WB_MENUSTYLEVALUESET);
     128             : 
     129           0 :         maVSColor.SetStyle(aWinBits);
     130             : 
     131             :         // neds to be done *before* layouting
     132           0 :         if(!msNoColorString.isEmpty())
     133             :         {
     134           0 :             maVSColor.SetStyle(maVSColor.GetStyle() | WB_NONEFIELD);
     135           0 :             maVSColor.SetText(msNoColorString);
     136             :         }
     137             : 
     138           0 :         const Size aNewSize(maVSColor.layoutAllVisible(nColorCount));
     139           0 :         maVSColor.SetOutputSizePixel(aNewSize);
     140           0 :         const sal_Int32 nAdd = 4;
     141             : 
     142           0 :         SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd));
     143           0 :         Link aLink = LINK(this, ColorControl, VSSelectHdl);
     144           0 :         maVSColor.SetSelectHdl(aLink);
     145             : 
     146             :         // Now, after all calls to SetStyle, we can change the
     147             :         // background color.
     148           0 :         maVSColor.SetBackground(Theme::GetWallpaper(Theme::Paint_DropDownBackground));
     149             : 
     150             :         // add entrties
     151           0 :         maVSColor.Clear();
     152           0 :         maVSColor.addEntriesForXColorList(*xColorTable);
     153             :     }
     154             : 
     155           0 :     maVSColor.Show();
     156             : }
     157             : 
     158             : 
     159             : 
     160             : 
     161           0 : void ColorControl::GetFocus (void)
     162             : {
     163           0 :     maVSColor.GrabFocus();
     164           0 : }
     165             : 
     166             : 
     167             : 
     168             : 
     169           0 : void ColorControl::SetCurColorSelect(Color aCol,bool bAvailable)
     170             : {
     171             :     //UUUU When transparent use transparent entry (entry 0)
     172           0 :     const bool bIsTransparent(0xff == aCol.GetTransparency());
     173           0 :     short nCol = bIsTransparent ? 0 : GetItemId_Imp(maVSColor,aCol);
     174             : 
     175           0 :     if(!bAvailable)
     176             :     {
     177           0 :         maVSColor.SetNoSelection();
     178           0 :         return;
     179             :     }
     180             : 
     181             :     //if not found
     182           0 :     if(nCol == -1)
     183             :     {
     184           0 :         maVSColor.SetNoSelection();
     185             :     }
     186             :     else
     187             :     {
     188             :         // remove selection first to force evtl. scroll when scroll is needed
     189           0 :         maVSColor.SetNoSelection();
     190           0 :         maVSColor.SelectItem(nCol);
     191             :     }
     192             : }
     193             : 
     194             : 
     195             : 
     196             : 
     197           0 : IMPL_LINK(ColorControl, VSSelectHdl, void *, pControl)
     198             : {
     199           0 :     if(pControl == &maVSColor)
     200             :     {
     201           0 :         sal_uInt16 iPos = maVSColor.GetSelectItemId();
     202           0 :         Color aColor = maVSColor.GetItemColor( iPos );
     203           0 :         OUString aTmpStr = maVSColor.GetItemText( iPos );
     204             : 
     205             :         // react when the WB_NONEFIELD created entry is selected
     206           0 :         if (aColor.GetColor() == 0 && aTmpStr.isEmpty())
     207             :         {
     208           0 :             if (maNoColorGetter)
     209           0 :                 aColor = maNoColorGetter();
     210             :         }
     211           0 :         if (maColorSetter)
     212           0 :             maColorSetter(aTmpStr, aColor);
     213             : 
     214           0 :         if (mpFloatingWindow!=NULL && mpFloatingWindow->IsInPopupMode())
     215           0 :             mpFloatingWindow->EndPopupMode();
     216             :     }
     217             : 
     218           0 :     return 0;
     219             : }
     220             : 
     221             : 
     222         594 : } } // end of namespace svx::sidebar
     223             : 
     224             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10