LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/dialog - relfld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 56 1.8 %
Date: 2013-07-09 Functions: 2 7 28.6 %
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           0 : SvxRelativeField::SvxRelativeField( Window* pParent, WinBits nBits) :
      26           0 :     MetricField( pParent, nBits)
      27             : {
      28           0 :     bNegativeEnabled = sal_False;
      29           0 :     bRelativeMode = sal_False;
      30           0 :     bRelative     = sal_False;
      31             : 
      32           0 :     SetDecimalDigits( 2 );
      33           0 :     SetMin( 0 );
      34           0 :     SetMax( 9999 );
      35           0 : }
      36             : 
      37           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxRelativeField(Window *pParent, VclBuilder::stringmap &)
      38             : {
      39           0 :     return new SvxRelativeField(pParent, WB_BORDER | WB_SPIN | WB_REPEAT | WB_LEFT | WB_GROUP);
      40             : }
      41             : // -----------------------------------------------------------------------
      42             : 
      43           0 : void SvxRelativeField::Modify()
      44             : {
      45           0 :     MetricField::Modify();
      46             : 
      47           0 :     if ( bRelativeMode )
      48             :     {
      49           0 :         String  aStr = GetText();
      50           0 :         sal_Bool    bNewMode = bRelative;
      51             : 
      52           0 :         if ( bRelative )
      53             :         {
      54           0 :             const sal_Unicode* pStr = aStr.GetBuffer();
      55             : 
      56           0 :             while ( *pStr )
      57             :             {
      58           0 :                 if( ( ( *pStr < sal_Unicode( '0' ) ) || ( *pStr > sal_Unicode( '9' ) ) ) &&
      59           0 :                     ( *pStr != sal_Unicode( '%' ) ) )
      60             :                 {
      61           0 :                     bNewMode = sal_False;
      62           0 :                     break;
      63             :                 }
      64           0 :                 pStr++;
      65             :             }
      66             :         }
      67             :         else
      68             :         {
      69           0 :             xub_StrLen nPos = aStr.Search( sal_Unicode( '%' ) );
      70             : 
      71           0 :             if ( nPos != STRING_NOTFOUND )
      72           0 :                 bNewMode = sal_True;
      73             :         }
      74             : 
      75           0 :         if ( bNewMode != bRelative )
      76           0 :             SetRelative( bNewMode );
      77             : 
      78           0 :         MetricField::Modify();
      79             :     }
      80           0 : }
      81             : 
      82             : // -----------------------------------------------------------------------
      83             : 
      84           0 : void SvxRelativeField::EnableRelativeMode( sal_uInt16 nMin,
      85             :                                            sal_uInt16 nMax, sal_uInt16 nStep )
      86             : {
      87           0 :     bRelativeMode = sal_True;
      88           0 :     nRelMin       = nMin;
      89           0 :     nRelMax       = nMax;
      90           0 :     nRelStep      = nStep;
      91           0 :     SetUnit( FUNIT_CM );
      92           0 : }
      93             : 
      94             : // -----------------------------------------------------------------------
      95             : 
      96           0 : void SvxRelativeField::SetRelative( sal_Bool bNewRelative )
      97             : {
      98           0 :     Selection aSelection = GetSelection();
      99           0 :     String aStr = GetText();
     100             : 
     101           0 :     if ( bNewRelative )
     102             :     {
     103           0 :         bRelative = sal_True;
     104           0 :         SetDecimalDigits( 0 );
     105           0 :         SetMin( nRelMin );
     106           0 :         SetMax( nRelMax );
     107           0 :         SetCustomUnitText( OUString('%') );
     108           0 :         SetUnit( FUNIT_CUSTOM );
     109             :     }
     110             :     else
     111             :     {
     112           0 :         bRelative = sal_False;
     113           0 :         SetDecimalDigits( 2 );
     114           0 :         SetMin( bNegativeEnabled ? -9999 : 0 );
     115           0 :         SetMax( 9999 );
     116           0 :         SetUnit( FUNIT_CM );
     117             :     }
     118             : 
     119           0 :     SetText( aStr );
     120           0 :     SetSelection( aSelection );
     121         216 : }
     122             : 
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10