1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // include --------------------------------------------------------------- 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <tools/ref.hxx> 30cdf0e10cSrcweir #include "svx/relfld.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir // ----------------------------------------------------------------------- 33cdf0e10cSrcweir 34cdf0e10cSrcweir SvxRelativeField::SvxRelativeField( Window* pParent, WinBits nWinSize ) : 35cdf0e10cSrcweir MetricField( pParent, nWinSize ) 36cdf0e10cSrcweir { 37cdf0e10cSrcweir bNegativeEnabled = sal_False; 38cdf0e10cSrcweir bRelativeMode = sal_False; 39cdf0e10cSrcweir bRelative = sal_False; 40cdf0e10cSrcweir 41cdf0e10cSrcweir SetDecimalDigits( 2 ); 42cdf0e10cSrcweir SetMin( 0 ); 43cdf0e10cSrcweir SetMax( 9999 ); 44cdf0e10cSrcweir } 45cdf0e10cSrcweir 46cdf0e10cSrcweir // ----------------------------------------------------------------------- 47cdf0e10cSrcweir 48cdf0e10cSrcweir SvxRelativeField::SvxRelativeField( Window* pParent, const ResId& rResId ) : 49cdf0e10cSrcweir MetricField( pParent, rResId ) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir bNegativeEnabled = sal_False; 52cdf0e10cSrcweir bRelativeMode = sal_False; 53cdf0e10cSrcweir bRelative = sal_False; 54cdf0e10cSrcweir 55cdf0e10cSrcweir SetDecimalDigits( 2 ); 56cdf0e10cSrcweir SetMin( 0 ); 57cdf0e10cSrcweir SetMax( 9999 ); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir // ----------------------------------------------------------------------- 61cdf0e10cSrcweir 62cdf0e10cSrcweir void SvxRelativeField::Modify() 63cdf0e10cSrcweir { 64cdf0e10cSrcweir MetricField::Modify(); 65cdf0e10cSrcweir 66cdf0e10cSrcweir if ( bRelativeMode ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir String aStr = GetText(); 69cdf0e10cSrcweir sal_Bool bNewMode = bRelative; 70cdf0e10cSrcweir 71cdf0e10cSrcweir if ( bRelative ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir const sal_Unicode* pStr = aStr.GetBuffer(); 74cdf0e10cSrcweir 75cdf0e10cSrcweir while ( *pStr ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir if( ( ( *pStr < sal_Unicode( '0' ) ) || ( *pStr > sal_Unicode( '9' ) ) ) && 78cdf0e10cSrcweir ( *pStr != sal_Unicode( '%' ) ) ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir bNewMode = sal_False; 81cdf0e10cSrcweir break; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir pStr++; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir else 87cdf0e10cSrcweir { 88cdf0e10cSrcweir xub_StrLen nPos = aStr.Search( sal_Unicode( '%' ) ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir if ( nPos != STRING_NOTFOUND ) 91cdf0e10cSrcweir bNewMode = sal_True; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( bNewMode != bRelative ) 95cdf0e10cSrcweir SetRelative( bNewMode ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir MetricField::Modify(); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir // ----------------------------------------------------------------------- 102cdf0e10cSrcweir 103cdf0e10cSrcweir void SvxRelativeField::EnableRelativeMode( sal_uInt16 nMin, 104cdf0e10cSrcweir sal_uInt16 nMax, sal_uInt16 nStep ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir bRelativeMode = sal_True; 107cdf0e10cSrcweir nRelMin = nMin; 108cdf0e10cSrcweir nRelMax = nMax; 109cdf0e10cSrcweir nRelStep = nStep; 110cdf0e10cSrcweir SetUnit( FUNIT_CM ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // ----------------------------------------------------------------------- 114cdf0e10cSrcweir 115cdf0e10cSrcweir void SvxRelativeField::SetRelative( sal_Bool bNewRelative ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir Selection aSelection = GetSelection(); 118cdf0e10cSrcweir String aStr = GetText(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir if ( bNewRelative ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir bRelative = sal_True; 123cdf0e10cSrcweir SetDecimalDigits( 0 ); 124cdf0e10cSrcweir SetMin( nRelMin ); 125cdf0e10cSrcweir SetMax( nRelMax ); 126cdf0e10cSrcweir SetCustomUnitText( String( sal_Unicode( '%' ) ) ); 127cdf0e10cSrcweir SetUnit( FUNIT_CUSTOM ); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir else 130cdf0e10cSrcweir { 131cdf0e10cSrcweir bRelative = sal_False; 132cdf0e10cSrcweir SetDecimalDigits( 2 ); 133cdf0e10cSrcweir SetMin( bNegativeEnabled ? -9999 : 0 ); 134cdf0e10cSrcweir SetMax( 9999 ); 135cdf0e10cSrcweir SetUnit( FUNIT_CM ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir SetText( aStr ); 139cdf0e10cSrcweir SetSelection( aSelection ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir 143