LCOV - code coverage report
Current view: top level - svx/source/dialog - relfld.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 13 55 23.6 %
Date: 2014-11-03 Functions: 4 7 57.1 %
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/relfld.hxx"
      21             : #include "vcl/builder.hxx"
      22             : 
      23             : 
      24             : 
      25        3690 : SvxRelativeField::SvxRelativeField(
      26             :         vcl::Window *const pParent, WinBits const nBits, FieldUnit const eUnit)
      27             :     : MetricField( pParent, nBits)
      28             :     , nRelMin(0)
      29             :     , nRelMax(0)
      30             :     , nRelStep(0)
      31             :     , bRelativeMode(false)
      32             :     , bRelative(false)
      33        3690 :     , bNegativeEnabled(false)
      34             : 
      35             : {
      36        3690 :     SetUnit(eUnit);
      37        3690 :     SetDecimalDigits( 2 );
      38        3690 :     SetMin( 0 );
      39        3690 :     SetMax( 9999 );
      40        3690 : }
      41             : 
      42             : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL
      43        3690 : makeSvxRelativeField(vcl::Window *const pParent, VclBuilder::stringmap & rMap)
      44             : {
      45        3690 :     OString const custom(VclBuilder::extractCustomProperty(rMap));
      46        3690 :     FieldUnit const eUnit(VclBuilder::detectUnit(custom));
      47             :     SvxRelativeField *const pRet = new SvxRelativeField(pParent,
      48        3690 :             WB_BORDER | WB_SPIN | WB_REPEAT | WB_LEFT | WB_GROUP, eUnit);
      49        3690 :     return pRet;
      50             : }
      51             : 
      52             : 
      53           0 : void SvxRelativeField::Modify()
      54             : {
      55           0 :     MetricField::Modify();
      56             : 
      57           0 :     if ( bRelativeMode )
      58             :     {
      59           0 :         OUString  aStr = GetText();
      60           0 :         bool      bNewMode = bRelative;
      61             : 
      62           0 :         if ( bRelative )
      63             :         {
      64           0 :             const sal_Unicode* pStr = aStr.getStr();
      65             : 
      66           0 :             while ( *pStr )
      67             :             {
      68           0 :                 if( ( ( *pStr < '0' ) || ( *pStr > '9' ) ) &&
      69           0 :                     ( *pStr != '%' ) )
      70             :                 {
      71           0 :                     bNewMode = false;
      72           0 :                     break;
      73             :                 }
      74           0 :                 pStr++;
      75             :             }
      76             :         }
      77             :         else
      78             :         {
      79           0 :             if ( aStr.indexOf( "%" ) != -1 )
      80           0 :                 bNewMode = true;
      81             :         }
      82             : 
      83           0 :         if ( bNewMode != bRelative )
      84           0 :             SetRelative( bNewMode );
      85             : 
      86           0 :         MetricField::Modify();
      87             :     }
      88           0 : }
      89             : 
      90             : 
      91             : 
      92           0 : void SvxRelativeField::EnableRelativeMode( sal_uInt16 nMin,
      93             :                                            sal_uInt16 nMax, sal_uInt16 nStep )
      94             : {
      95           0 :     bRelativeMode = true;
      96           0 :     nRelMin       = nMin;
      97           0 :     nRelMax       = nMax;
      98           0 :     nRelStep      = nStep;
      99           0 :     SetUnit( FUNIT_CM );
     100           0 : }
     101             : 
     102             : 
     103             : 
     104           0 : void SvxRelativeField::SetRelative( bool bNewRelative )
     105             : {
     106           0 :     Selection aSelection = GetSelection();
     107           0 :     OUString aStr = GetText();
     108             : 
     109           0 :     if ( bNewRelative )
     110             :     {
     111           0 :         bRelative = true;
     112           0 :         SetDecimalDigits( 0 );
     113           0 :         SetMin( nRelMin );
     114           0 :         SetMax( nRelMax );
     115           0 :         SetUnit( FUNIT_PERCENT );
     116             :     }
     117             :     else
     118             :     {
     119           0 :         bRelative = false;
     120           0 :         SetDecimalDigits( 2 );
     121           0 :         SetMin( bNegativeEnabled ? -9999 : 0 );
     122           0 :         SetMax( 9999 );
     123           0 :         SetUnit( FUNIT_CM );
     124             :     }
     125             : 
     126           0 :     SetText( aStr );
     127           0 :     SetSelection( aSelection );
     128         594 : }
     129             : 
     130             : 
     131             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10