LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/tbxctrls - SvxColorValueSet.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 77 1.3 %
Date: 2013-07-09 Functions: 2 12 16.7 %
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/SvxColorValueSet.hxx>
      20             : #include <svx/xtable.hxx>
      21             : #include <vcl/builder.hxx>
      22             : #include <vcl/svapp.hxx>
      23             : 
      24             : //////////////////////////////////////////////////////////////////////////////
      25             : 
      26           0 : SvxColorValueSet::SvxColorValueSet(Window* _pParent, WinBits nWinStyle)
      27           0 : :   ValueSet(_pParent, nWinStyle)
      28             : {
      29           0 :     SetEdgeBlending(true);
      30           0 : }
      31             : 
      32           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxColorValueSet(Window *pParent, VclBuilder::stringmap &rMap)
      33             : {
      34           0 :     WinBits nWinBits = WB_TABSTOP;
      35             : 
      36           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("border"));
      37           0 :     if (aFind != rMap.end())
      38             :     {
      39           0 :         if (toBool(aFind->second))
      40           0 :             nWinBits |= WB_BORDER;
      41           0 :         rMap.erase(aFind);
      42             :     }
      43             : 
      44           0 :     return new SvxColorValueSet(pParent, nWinBits);
      45             : }
      46             : 
      47           0 : SvxColorValueSet::SvxColorValueSet(Window* _pParent, const ResId& rResId)
      48           0 : :   ValueSet(_pParent, rResId)
      49             : {
      50           0 :     SetEdgeBlending(true);
      51           0 : }
      52             : 
      53           0 : sal_uInt32 SvxColorValueSet::getMaxRowCount() const
      54             : {
      55           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
      56             : 
      57           0 :     return rStyleSettings.GetColorValueSetMaximumRowCount();
      58             : }
      59             : 
      60           0 : sal_uInt32 SvxColorValueSet::getEntryEdgeLength() const
      61             : {
      62           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
      63             : 
      64           0 :     return rStyleSettings.GetListBoxPreviewDefaultPixelSize().Height() + 1;
      65             : }
      66             : 
      67           0 : sal_uInt32 SvxColorValueSet::getColumnCount() const
      68             : {
      69           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
      70             : 
      71           0 :     return rStyleSettings.GetColorValueSetColumnCount();
      72             : }
      73             : 
      74           0 : void SvxColorValueSet::addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 nStartIndex)
      75             : {
      76           0 :     const sal_uInt32 nColorCount(rXColorList.Count());
      77             : 
      78           0 :     for(sal_uInt32 nIndex(0); nIndex < nColorCount; nIndex++, nStartIndex++)
      79             :     {
      80           0 :         const XColorEntry* pEntry = rXColorList.GetColor(nIndex);
      81             : 
      82           0 :         if(pEntry)
      83             :         {
      84           0 :             InsertItem(nStartIndex, pEntry->GetColor(), pEntry->GetName());
      85             :         }
      86             :         else
      87             :         {
      88             :             OSL_ENSURE(false, "OOps, XColorList with empty entries (!)");
      89             :         }
      90             :     }
      91           0 : }
      92             : 
      93           0 : Size SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount)
      94             : {
      95           0 :     if(!nEntryCount)
      96             :     {
      97           0 :         nEntryCount++;
      98             :     }
      99             : 
     100           0 :     const sal_uInt32 nRowCount(ceil(double(nEntryCount)/getColumnCount()));
     101           0 :     const Size aItemSize(getEntryEdgeLength() - 2, getEntryEdgeLength() - 2);
     102           0 :     const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
     103             : 
     104           0 :     if(nRowCount > getMaxRowCount())
     105             :     {
     106           0 :         SetStyle(aWinBits|WB_VSCROLL);
     107             :     }
     108             :     else
     109             :     {
     110           0 :         SetStyle(aWinBits);
     111             :     }
     112             : 
     113           0 :     SetColCount(getColumnCount());
     114           0 :     SetLineCount(std::min(nRowCount, getMaxRowCount()));
     115           0 :     SetItemWidth(aItemSize.Width());
     116           0 :     SetItemHeight(aItemSize.Height());
     117             : 
     118           0 :     return CalcWindowSizePixel(aItemSize);
     119             : }
     120             : 
     121           0 : void SvxColorValueSet::Resize()
     122             : {
     123           0 :     Window *pParent = GetParent();
     124             :     //don't do this for the drop down color palettes
     125           0 :     if (pParent && pParent->GetType() != WINDOW_FLOATINGWINDOW)
     126           0 :         layoutToGivenHeight(GetOutputSizePixel().Height(), GetItemCount());
     127           0 :     ValueSet::Resize();
     128           0 : }
     129             : 
     130           0 : Size SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount)
     131             : {
     132           0 :     if(!nEntryCount)
     133             :     {
     134           0 :         nEntryCount++;
     135             :     }
     136             : 
     137           0 :     const Size aItemSize(getEntryEdgeLength(), getEntryEdgeLength());
     138           0 :     const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
     139             : 
     140             :     // get size whith all fields disabled
     141           0 :     const WinBits aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL|WB_NAMEFIELD|WB_NONEFIELD));
     142           0 :     SetStyle(aWinBitsNoScrollNoFields);
     143           0 :     const Size aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize, getColumnCount()));
     144             : 
     145             :     // get size with all needed fields
     146           0 :     SetStyle(aWinBits);
     147           0 :     Size aNewSize(CalcWindowSizePixel(aItemSize, getColumnCount()));
     148             : 
     149             :     // evtl. activate vertical scroll
     150           0 :     const bool bAdaptHeight(static_cast< sal_uInt32 >(aNewSize.Height()) > nHeight);
     151             : 
     152           0 :     if(bAdaptHeight)
     153             :     {
     154           0 :         SetStyle(aWinBits|WB_VSCROLL);
     155           0 :         aNewSize = CalcWindowSizePixel(aItemSize, getColumnCount());
     156             :     }
     157             : 
     158             :     // calculate field height and available height for requested height
     159           0 :     const sal_uInt32 nFieldHeight(aNewSize.Height() - aSizeNoScrollNoFields.Height());
     160           0 :     const sal_uInt32 nAvailableHeight(nHeight >= nFieldHeight ? nHeight - nFieldHeight : 0);
     161             : 
     162             :     // calculate how many lines can be shown there
     163           0 :     const Size aItemSizePixel(CalcItemSizePixel(aItemSize));
     164           0 :     const sal_uInt32 nLineCount((nAvailableHeight + aItemSizePixel.Height() - 1) / aItemSizePixel.Height());
     165             : 
     166             :     // set height to wanted height
     167           0 :     aNewSize.Height() = nHeight;
     168             : 
     169           0 :     SetItemWidth(aItemSize.Width());
     170           0 :     SetItemHeight(aItemSize.Height());
     171           0 :     SetColCount(getColumnCount());
     172           0 :     SetLineCount(nLineCount);
     173             : 
     174           0 :     return aNewSize;
     175         258 : }
     176             : 

Generated by: LCOV version 1.10