2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-21 22:06:52 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2010-04-20 15:55:51 +02:00
|
|
|
#include "svx/relfld.hxx"
|
2013-05-26 22:35:10 -03:00
|
|
|
#include "vcl/builder.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2013-05-26 22:35:10 -03:00
|
|
|
SvxRelativeField::SvxRelativeField( Window* pParent, WinBits nBits) :
|
|
|
|
MetricField( pParent, nBits)
|
|
|
|
{
|
|
|
|
bNegativeEnabled = sal_False;
|
|
|
|
bRelativeMode = sal_False;
|
|
|
|
bRelative = sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-05-26 22:35:10 -03:00
|
|
|
SetDecimalDigits( 2 );
|
|
|
|
SetMin( 0 );
|
|
|
|
SetMax( 9999 );
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxRelativeField(Window *pParent, VclBuilder::stringmap &)
|
|
|
|
{
|
|
|
|
return new SvxRelativeField(pParent, WB_BORDER | WB_SPIN | WB_REPEAT | WB_LEFT | WB_GROUP);
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SvxRelativeField::Modify()
|
|
|
|
{
|
|
|
|
MetricField::Modify();
|
|
|
|
|
|
|
|
if ( bRelativeMode )
|
|
|
|
{
|
2013-09-04 15:29:16 +02:00
|
|
|
OUString aStr = GetText();
|
2011-01-10 16:11:35 +01:00
|
|
|
sal_Bool bNewMode = bRelative;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if ( bRelative )
|
|
|
|
{
|
2013-09-04 15:29:16 +02:00
|
|
|
const sal_Unicode* pStr = aStr.getStr();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
while ( *pStr )
|
|
|
|
{
|
2013-11-13 16:32:09 +02:00
|
|
|
if( ( ( *pStr < '0' ) || ( *pStr > '9' ) ) &&
|
|
|
|
( *pStr != '%' ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-01-10 16:11:35 +01:00
|
|
|
bNewMode = sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pStr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-04 15:29:16 +02:00
|
|
|
if ( aStr.indexOf( "%" ) != -1 )
|
2011-01-10 16:11:35 +01:00
|
|
|
bNewMode = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bNewMode != bRelative )
|
|
|
|
SetRelative( bNewMode );
|
|
|
|
|
|
|
|
MetricField::Modify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2011-01-10 16:11:35 +01:00
|
|
|
void SvxRelativeField::EnableRelativeMode( sal_uInt16 nMin,
|
|
|
|
sal_uInt16 nMax, sal_uInt16 nStep )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-01-10 16:11:35 +01:00
|
|
|
bRelativeMode = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
nRelMin = nMin;
|
|
|
|
nRelMax = nMax;
|
|
|
|
nRelStep = nStep;
|
|
|
|
SetUnit( FUNIT_CM );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2011-01-10 16:11:35 +01:00
|
|
|
void SvxRelativeField::SetRelative( sal_Bool bNewRelative )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
Selection aSelection = GetSelection();
|
2013-09-04 15:29:16 +02:00
|
|
|
OUString aStr = GetText();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if ( bNewRelative )
|
|
|
|
{
|
2011-01-10 16:11:35 +01:00
|
|
|
bRelative = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
SetDecimalDigits( 0 );
|
|
|
|
SetMin( nRelMin );
|
|
|
|
SetMax( nRelMax );
|
2013-04-07 12:06:47 +02:00
|
|
|
SetCustomUnitText( OUString('%') );
|
2000-09-18 16:07:07 +00:00
|
|
|
SetUnit( FUNIT_CUSTOM );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-10 16:11:35 +01:00
|
|
|
bRelative = sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
SetDecimalDigits( 2 );
|
2001-04-20 07:54:55 +00:00
|
|
|
SetMin( bNegativeEnabled ? -9999 : 0 );
|
2000-09-18 16:07:07 +00:00
|
|
|
SetMax( 9999 );
|
|
|
|
SetUnit( FUNIT_CM );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetText( aStr );
|
|
|
|
SetSelection( aSelection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|