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

Generated by: LCOV version 1.11