LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - PreviewValueSet.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 53 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 11 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 "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()
      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           0 :         maRightMouseClickHandler.Call(&const_cast<MouseEvent&>(rEvent));
      59             :     else
      60           0 :         ValueSet::MouseButtonDown (rEvent);
      61             : 
      62           0 : }
      63             : 
      64           0 : void PreviewValueSet::Resize()
      65             : {
      66           0 :     ValueSet::Resize ();
      67             : 
      68           0 :     Size aWindowSize (GetOutputSizePixel());
      69           0 :     if (aWindowSize.Width()>0 && aWindowSize.Height()>0)
      70             :     {
      71           0 :         Rearrange();
      72             :     }
      73           0 : }
      74             : 
      75           0 : void PreviewValueSet::Rearrange (bool /*bForceRequestResize*/)
      76             : {
      77             :     sal_uInt16 nNewColumnCount (CalculateColumnCount (
      78           0 :         GetOutputSizePixel().Width()));
      79           0 :     sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount));
      80             : 
      81           0 :     SetColCount(nNewColumnCount);
      82           0 :     SetLineCount(nNewRowCount);
      83           0 : }
      84             : 
      85           0 : sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const
      86             : {
      87           0 :     int nColumnCount = 0;
      88           0 :     if (nWidth > 0)
      89             :     {
      90           0 :         nColumnCount = nWidth / (maPreviewSize.Width() + 2*mnBorderWidth);
      91           0 :         if (nColumnCount < 1)
      92           0 :             nColumnCount = 1;
      93           0 :         else if (mnMaxColumnCount>0 && nColumnCount>mnMaxColumnCount)
      94           0 :             nColumnCount = mnMaxColumnCount;
      95             :     }
      96           0 :     return (sal_uInt16)nColumnCount;
      97             : }
      98             : 
      99           0 : sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const
     100             : {
     101           0 :     int nRowCount = 0;
     102           0 :     int nItemCount = GetItemCount();
     103           0 :     if (nColumnCount > 0)
     104             :     {
     105           0 :         nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
     106           0 :         if (nRowCount < 1)
     107           0 :             nRowCount = 1;
     108             :     }
     109             : 
     110           0 :     return (sal_uInt16)nRowCount;
     111             : }
     112             : 
     113           0 : sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth)
     114             : {
     115           0 :     int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth)));
     116           0 :     int nItemHeight (maPreviewSize.Height());
     117             : 
     118           0 :     return nRowCount * (nItemHeight + 2*mnBorderHeight);
     119             : }
     120             : 
     121             : } } // end of namespace sd::sidebar
     122             : 
     123             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11