LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - PreviewValueSet.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 64 1.6 %
Date: 2014-11-03 Functions: 2 14 14.3 %
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 "PreviewValueSet.hxx"
      21             : #include <vcl/image.hxx>
      22             : 
      23             : namespace sd { namespace sidebar {
      24             : 
      25           0 : PreviewValueSet::PreviewValueSet (vcl::Window* pParent)
      26             :     : ValueSet (pParent, WB_TABSTOP),
      27             :       maPreviewSize(10,10),
      28             :       mnBorderWidth(3),
      29             :       mnBorderHeight(3),
      30           0 :       mnMaxColumnCount(-1)
      31             : {
      32             :     SetStyle (
      33           0 :         GetStyle()
      34             :         & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET)
      35             :         //        | WB_FLATVALUESET);
      36           0 :         );
      37           0 :     SetColCount(2);
      38           0 :     SetExtraSpacing (2);
      39           0 : }
      40             : 
      41           0 : PreviewValueSet::~PreviewValueSet (void)
      42             : {
      43           0 : }
      44             : 
      45           0 : void PreviewValueSet::SetPreviewSize (const Size& rSize)
      46             : {
      47           0 :     maPreviewSize = rSize;
      48           0 : }
      49             : 
      50           0 : void PreviewValueSet::SetRightMouseClickHandler (const Link& rLink)
      51             : {
      52           0 :     maRightMouseClickHandler = rLink;
      53           0 : }
      54             : 
      55           0 : void PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent)
      56             : {
      57           0 :     if (rEvent.IsRight())
      58             :         maRightMouseClickHandler.Call(reinterpret_cast<void*>(
      59           0 :             &const_cast<MouseEvent&>(rEvent)));
      60             :     else
      61           0 :         ValueSet::MouseButtonDown (rEvent);
      62             : 
      63           0 : }
      64             : 
      65           0 : void PreviewValueSet::Resize (void)
      66             : {
      67           0 :     ValueSet::Resize ();
      68             : 
      69           0 :     Size aWindowSize (GetOutputSizePixel());
      70           0 :     if (aWindowSize.Width()>0 && aWindowSize.Height()>0)
      71             :     {
      72           0 :         Rearrange();
      73             :     }
      74           0 : }
      75             : 
      76           0 : void PreviewValueSet::Rearrange (bool /*bForceRequestResize*/)
      77             : {
      78             :     sal_uInt16 nNewColumnCount (CalculateColumnCount (
      79           0 :         GetOutputSizePixel().Width()));
      80           0 :     sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount));
      81             : 
      82           0 :     SetColCount(nNewColumnCount);
      83           0 :     SetLineCount(nNewRowCount);
      84           0 : }
      85             : 
      86           0 : sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const
      87             : {
      88           0 :     int nColumnCount = 0;
      89           0 :     if (nWidth > 0)
      90             :     {
      91           0 :         nColumnCount = nWidth / (maPreviewSize.Width() + 2*mnBorderWidth);
      92           0 :         if (nColumnCount < 1)
      93           0 :             nColumnCount = 1;
      94           0 :         else if (mnMaxColumnCount>0 && nColumnCount>mnMaxColumnCount)
      95           0 :             nColumnCount = mnMaxColumnCount;
      96             :     }
      97           0 :     return (sal_uInt16)nColumnCount;
      98             : }
      99             : 
     100           0 : sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const
     101             : {
     102           0 :     int nRowCount = 0;
     103           0 :     int nItemCount = GetItemCount();
     104           0 :     if (nColumnCount > 0)
     105             :     {
     106           0 :         nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
     107           0 :         if (nRowCount < 1)
     108           0 :             nRowCount = 1;
     109             :     }
     110             : 
     111           0 :     return (sal_uInt16)nRowCount;
     112             : }
     113             : 
     114           0 : sal_Int32 PreviewValueSet::GetPreferredWidth (sal_Int32 nHeight)
     115             : {
     116           0 :     int nPreferredWidth (maPreviewSize.Width() + 2*mnBorderWidth);
     117             : 
     118             :     // Get height of each row.
     119           0 :     int nItemHeight (maPreviewSize.Height() + 2*mnBorderHeight);
     120             : 
     121             :     // Calculate the row- and column count and from the later the preferred
     122             :     // width.
     123           0 :     int nRowCount = nHeight / nItemHeight;
     124           0 :     if (nRowCount > 0)
     125             :     {
     126           0 :         int nColumnCount = (GetItemCount()+nRowCount-1) / nRowCount;
     127           0 :         if (nColumnCount > 0)
     128           0 :             nPreferredWidth = (maPreviewSize.Width() + 2*mnBorderWidth)
     129           0 :                 * nColumnCount;
     130             :     }
     131             : 
     132           0 :     return nPreferredWidth;
     133             : }
     134             : 
     135           0 : sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth)
     136             : {
     137           0 :     int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth)));
     138           0 :     int nItemHeight (maPreviewSize.Height());
     139             : 
     140           0 :     return nRowCount * (nItemHeight + 2*mnBorderHeight);
     141             : }
     142             : 
     143         114 : } } // end of namespace sd::sidebar
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10