LCOV - code coverage report
Current view: top level - svx/source/sidebar/tools - ColorControl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 77 0.0 %
Date: 2014-04-11 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * This file incorporates work covered by the following license notice:
       9             :  *
      10             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      11             :  *   contributor license agreements. See the NOTICE file distributed
      12             :  *   with this work for additional information regarding copyright
      13             :  *   ownership. The ASF licenses this file to you under the Apache
      14             :  *   License, Version 2.0 (the "License"); you may not use this file
      15             :  *   except in compliance with the License. You may obtain a copy of
      16             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      17             :  */
      18             : 
      19             : #include <svx/sidebar/ColorControl.hxx>
      20             : #include "svx/svxids.hrc"
      21             : #include "svx/drawitem.hxx"
      22             : #include "svx/xtable.hxx"
      23             : #include "svx/dialmgr.hxx"
      24             : #include "svx/xflclit.hxx"
      25             : #include <tools/resid.hxx>
      26             : #include <sfx2/sidebar/Theme.hxx>
      27             : #include <sfx2/objsh.hxx>
      28             : #include <sfx2/bindings.hxx>
      29             : #include <sfx2/dispatch.hxx>
      30             : #include <vcl/floatwin.hxx>
      31             : #include <unotools/pathoptions.hxx>
      32             : #include <editeng/editrids.hrc>
      33             : 
      34             : using ::sfx2::sidebar::Theme;
      35             : 
      36             : namespace svx { namespace sidebar {
      37             : 
      38             : namespace {
      39           0 :     short GetItemId_Imp( ValueSet& rValueSet, const Color& rCol )
      40             :     {
      41           0 :         if(rCol == COL_AUTO)
      42           0 :             return 0;
      43             : 
      44           0 :         bool    bFound = false;
      45           0 :         sal_uInt16  nCount = rValueSet.GetItemCount();
      46           0 :         sal_uInt16  n      = 1;
      47             : 
      48           0 :         while ( !bFound && n <= nCount )
      49             :         {
      50           0 :             Color aValCol = rValueSet.GetItemColor(n);
      51             : 
      52           0 :             bFound = (   aValCol.GetRed()   == rCol.GetRed()
      53           0 :                 && aValCol.GetGreen() == rCol.GetGreen()
      54           0 :                 && aValCol.GetBlue()  == rCol.GetBlue() );
      55             : 
      56           0 :             if ( !bFound )
      57           0 :                 n++;
      58             :         }
      59           0 :         return bFound ? n : -1;
      60             :     }
      61           0 :     XColorListRef GetColorTable (void)
      62             :     {
      63           0 :         SfxObjectShell* pDocSh = SfxObjectShell::Current();
      64             :         DBG_ASSERT(pDocSh!=NULL, "DocShell not found!");
      65           0 :         if (pDocSh != NULL)
      66             :         {
      67           0 :             const SfxPoolItem* pItem = pDocSh->GetItem(SID_COLOR_TABLE);
      68           0 :             if (pItem != NULL)
      69             :             {
      70           0 :                 XColorListRef xTable = ((SvxColorListItem*)pItem)->GetColorList();
      71           0 :                 if (xTable.is())
      72           0 :                     return xTable;
      73             :             }
      74             :         }
      75             : 
      76           0 :         return XColorList::GetStdColorList();
      77             :     }
      78             : } // end of anonymous namespace
      79             : 
      80             : 
      81             : 
      82             : 
      83           0 : ColorControl::ColorControl (
      84             :     Window* pParent,
      85             :     SfxBindings* /* pBindings */,
      86             :     const ResId& rControlResId,
      87             :     const ResId& rValueSetResId,
      88             :     const ::boost::function<Color(void)>& rNoColorGetter,
      89             :     const ::boost::function<void(OUString&,Color)>& rColorSetter,
      90             :     FloatingWindow* pFloatingWindow,
      91             :     const ResId* pNoColorStringResId) // const sal_uInt32 nNoColorStringResId)
      92             :     : PopupControl(pParent, rControlResId),
      93             :       maVSColor(this, rValueSetResId),
      94             :       mpFloatingWindow(pFloatingWindow),
      95             :       msNoColorString(
      96             :           pNoColorStringResId
      97             :               ? pNoColorStringResId->toString()
      98             :               : OUString()),
      99             :       maNoColorGetter(rNoColorGetter),
     100           0 :       maColorSetter(rColorSetter)
     101             : {
     102           0 :     FreeResource();
     103           0 :     FillColors();
     104           0 : }
     105             : 
     106             : 
     107             : 
     108           0 : ColorControl::~ColorControl (void)
     109             : {
     110           0 : }
     111             : 
     112             : 
     113             : 
     114             : 
     115           0 : void ColorControl::FillColors (void)
     116             : {
     117           0 :     XColorListRef xColorTable (GetColorTable());
     118             : 
     119           0 :     if (xColorTable.is())
     120             :     {
     121           0 :         const long nColorCount(xColorTable->Count());
     122           0 :         if (nColorCount <= 0)
     123           0 :             return;
     124             : 
     125           0 :         const WinBits aWinBits(maVSColor.GetStyle() | WB_TABSTOP | WB_ITEMBORDER | WB_NAMEFIELD |
     126           0 :             WB_NO_DIRECTSELECT | WB_MENUSTYLEVALUESET);
     127             : 
     128           0 :         maVSColor.SetStyle(aWinBits);
     129             : 
     130             :         // neds to be done *before* layouting
     131           0 :         if(!msNoColorString.isEmpty())
     132             :         {
     133           0 :             maVSColor.SetStyle(maVSColor.GetStyle() | WB_NONEFIELD);
     134           0 :             maVSColor.SetText(msNoColorString);
     135             :         }
     136             : 
     137           0 :         const Size aNewSize(maVSColor.layoutAllVisible(nColorCount));
     138           0 :         maVSColor.SetOutputSizePixel(aNewSize);
     139           0 :         const sal_Int32 nAdd = 4;
     140             : 
     141           0 :         SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd));
     142           0 :         Link aLink = LINK(this, ColorControl, VSSelectHdl);
     143           0 :         maVSColor.SetSelectHdl(aLink);
     144             : 
     145             :         // Now, after all calls to SetStyle, we can change the
     146             :         // background color.
     147           0 :         maVSColor.SetBackground(Theme::GetWallpaper(Theme::Paint_DropDownBackground));
     148             : 
     149             :         // add entrties
     150           0 :         maVSColor.Clear();
     151           0 :         maVSColor.addEntriesForXColorList(*xColorTable);
     152             :     }
     153             : 
     154           0 :     maVSColor.Show();
     155             : }
     156             : 
     157             : 
     158             : 
     159             : 
     160           0 : void ColorControl::GetFocus (void)
     161             : {
     162           0 :     maVSColor.GrabFocus();
     163           0 : }
     164             : 
     165             : 
     166             : 
     167             : 
     168           0 : void ColorControl::SetCurColorSelect (Color aCol, bool bAvailable)
     169             : {
     170             : //  FillColors();
     171           0 :     short nCol = GetItemId_Imp( maVSColor, aCol );
     172           0 :     if(! bAvailable)
     173             :     {
     174           0 :         maVSColor.SetNoSelection();
     175           0 :         return;
     176             :     }
     177             : 
     178             :     //if not found
     179           0 :     if( nCol == -1)
     180             :     {
     181           0 :         maVSColor.SetNoSelection();
     182             :     }
     183             :     else
     184             :     {
     185             :         // remove selection first to force evtl. scroll when scroll is needed
     186           0 :         maVSColor.SetNoSelection();
     187           0 :         maVSColor.SelectItem(nCol);
     188             :     }
     189             : }
     190             : 
     191             : 
     192             : 
     193             : 
     194           0 : IMPL_LINK(ColorControl, VSSelectHdl, void *, pControl)
     195             : {
     196           0 :     if(pControl == &maVSColor)
     197             :     {
     198           0 :         sal_uInt16 iPos = maVSColor.GetSelectItemId();
     199           0 :         Color aColor = maVSColor.GetItemColor( iPos );
     200           0 :         OUString aTmpStr = maVSColor.GetItemText( iPos );
     201             : 
     202             :         // react when the WB_NONEFIELD created entry is selected
     203           0 :         if (aColor.GetColor() == 0 && aTmpStr.isEmpty())
     204             :         {
     205           0 :             if (maNoColorGetter)
     206           0 :                 aColor = maNoColorGetter();
     207             :         }
     208           0 :         if (maColorSetter)
     209           0 :             maColorSetter(aTmpStr, aColor);
     210             : 
     211           0 :         if (mpFloatingWindow!=NULL && mpFloatingWindow->IsInPopupMode())
     212           0 :             mpFloatingWindow->EndPopupMode();
     213             :     }
     214             : 
     215           0 :     return 0;
     216             : }
     217             : 
     218             : 
     219             : } } // end of namespace svx::sidebar

Generated by: LCOV version 1.10