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

Generated by: LCOV version 1.11