Files
libreoffice/vcl/source/control/field.cxx

2475 lines
70 KiB
C++
Raw Normal View History

2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:07:07 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:07:07 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:07:07 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_vcl.hxx"
#ifndef _BIGINT_HXX
2000-09-18 16:07:07 +00:00
#define _TOOLS_BIGINT
#include "tools/bigint.hxx"
#endif
2000-09-18 16:07:07 +00:00
#include "tools/debug.hxx"
2000-09-18 16:07:07 +00:00
#include "tools/rc.h"
#include "tools/resary.hxx"
#include "vcl/svids.hrc"
#include "vcl/field.hxx"
#include "vcl/event.hxx"
#include "vcl/svapp.hxx"
#include "vcl/svdata.hxx"
#include "vcl/unohelp.hxx"
2008-10-01 13:31:44 +00:00
#include "i18nutil/unicode.hxx"
2000-09-18 16:07:07 +00:00
#include "rtl/math.hxx"
#include <unotools/localedatawrapper.hxx>
using namespace ::com::sun::star;
static ResStringArray *strAllUnits = NULL;
2001-07-06 15:16:57 +00:00
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
#define FORMAT_NUMERIC 1
#define FORMAT_METRIC 2
#define FORMAT_CURRENCY 3
// -----------------------------------------------------------------------
static sal_Int64 ImplPower10( USHORT n )
2000-09-18 16:07:07 +00:00
{
USHORT i;
sal_Int64 nValue = 1;
2000-09-18 16:07:07 +00:00
for ( i=0; i < n; i++ )
nValue *= 10;
return nValue;
}
// -----------------------------------------------------------------------
static BOOL ImplNumericProcessKeyInput( Edit*, const KeyEvent& rKEvt,
BOOL bStrictFormat, BOOL bThousandSep,
const LocaleDataWrapper& rLocaleDataWrappper )
2000-09-18 16:07:07 +00:00
{
if ( !bStrictFormat )
return FALSE;
else
{
xub_Unicode cChar = rKEvt.GetCharCode();
USHORT nGroup = rKEvt.GetKeyCode().GetGroup();
if ( (nGroup == KEYGROUP_FKEYS) || (nGroup == KEYGROUP_CURSOR) ||
(nGroup == KEYGROUP_MISC) ||
((cChar >= '0') && (cChar <= '9')) ||
(cChar == rLocaleDataWrappper.getNumDecimalSep() ) ||
(bThousandSep && (cChar == rLocaleDataWrappper.getNumThousandSep())) ||
2000-09-18 16:07:07 +00:00
(cChar == '-') )
return FALSE;
else
return TRUE;
}
}
// -----------------------------------------------------------------------
static BOOL ImplNumericGetValue( const XubString& rStr, double& rValue,
USHORT nDecDigits, const LocaleDataWrapper& rLocaleDataWrappper,
2000-09-18 16:07:07 +00:00
BOOL bCurrency = FALSE )
{
XubString aStr = rStr;
XubString aStr1;
XubString aStr2;
BOOL bNegative = FALSE;
xub_StrLen nDecPos;
xub_StrLen i;
// Reaktion auf leeren String
if ( !rStr.Len() )
return FALSE;
// Fuehrende und nachfolgende Leerzeichen entfernen
aStr.EraseLeadingAndTrailingChars( ' ' );
// Position des Dezimalpunktes suchen
nDecPos = aStr.Search( rLocaleDataWrappper.getNumDecimalSep() );
2000-09-18 16:07:07 +00:00
if ( nDecPos != STRING_NOTFOUND )
{
aStr1 = aStr.Copy( 0, nDecPos );
aStr2 = aStr.Copy( nDecPos+1 );
}
else
aStr1 = aStr;
// Negativ ?
if ( bCurrency )
{
if ( (aStr.GetChar( 0 ) == '(') && (aStr.GetChar( aStr.Len()-1 ) == ')') )
bNegative = TRUE;
if ( !bNegative )
{
for ( i=0; i < aStr.Len(); i++ )
{
if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') )
break;
else if ( aStr.GetChar( i ) == '-' )
{
bNegative = TRUE;
break;
}
}
}
if ( !bNegative && bCurrency && aStr.Len() )
{
USHORT nFormat = rLocaleDataWrappper.getCurrNegativeFormat();
2000-09-18 16:07:07 +00:00
if ( (nFormat == 3) || (nFormat == 6) ||
(nFormat == 7) || (nFormat == 10) )
{
for ( i = (xub_StrLen)(aStr.Len()-1); i > 0; i++ )
{
if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') )
break;
else if ( aStr.GetChar( i ) == '-' )
{
bNegative = TRUE;
break;
}
}
}
}
}
else
{
if ( aStr1.GetChar( 0 ) == '-' )
bNegative = TRUE;
}
// Alle unerwuenschten Zeichen rauswerfen
for ( i=0; i < aStr1.Len(); )
{
if ( (aStr1.GetChar( i ) >= '0') && (aStr1.GetChar( i ) <= '9') )
i++;
else
aStr1.Erase( i, 1 );
}
for ( i=0; i < aStr2.Len(); )
{
if ( (aStr2.GetChar( i ) >= '0') && (aStr2.GetChar( i ) <= '9') )
i++;
else
aStr2.Erase( i, 1 );
}
if ( !aStr1.Len() && !aStr2.Len() )
return FALSE;
if ( !aStr1.Len() )
aStr1.Insert( '0' );
if ( bNegative )
aStr1.Insert( '-', 0 );
// Nachkommateil zurechtstutzen und dabei runden
BOOL bRound = FALSE;
if ( aStr2.Len() > nDecDigits )
{
if ( aStr2.GetChar( nDecDigits ) >= '5' )
bRound = TRUE;
aStr2.Erase( nDecDigits );
}
if ( aStr2.Len() < nDecDigits )
aStr2.Expand( nDecDigits, '0' );
aStr = aStr1;
aStr += aStr2;
// Bereichsueberpruefung
double nValue = aStr.ToDouble();
if ( bRound )
{
if ( !bNegative )
nValue++;
else
nValue--;
}
rValue = nValue;
return TRUE;
}
static void ImplUpdateSeparators( const String& rOldDecSep, const String& rNewDecSep,
const String& rOldThSep, const String& rNewThSep,
Edit* pEdit )
{
bool bChangeDec = (rOldDecSep != rNewDecSep);
bool bChangeTh = (rOldThSep != rNewThSep );
if( bChangeDec || bChangeTh )
{
BOOL bUpdateMode = pEdit->IsUpdateMode();
pEdit->SetUpdateMode( FALSE );
String aText = pEdit->GetText();
if( bChangeDec )
aText.SearchAndReplaceAll( rNewDecSep, rOldDecSep );
if( bChangeTh )
aText.SearchAndReplaceAll( rNewThSep, rOldThSep );
pEdit->SetText( aText );
ComboBox* pCombo = dynamic_cast<ComboBox*>(pEdit);
if( pCombo )
{
// update box entries
USHORT nEntryCount = pCombo->GetEntryCount();
for ( USHORT i=0; i < nEntryCount; i++ )
{
aText = pCombo->GetEntry( i );
if( bChangeDec )
aText.SearchAndReplaceAll( rNewDecSep, rOldDecSep );
if( bChangeTh )
aText.SearchAndReplaceAll( rNewThSep, rOldThSep );
pCombo->RemoveEntry( i );
pCombo->InsertEntry( aText, i );
}
}
if( bUpdateMode )
pEdit->SetUpdateMode( bUpdateMode );
}
}
2000-09-18 16:07:07 +00:00
// -----------------------------------------------------------------------
FormatterBase::FormatterBase( Edit* pField )
{
mpField = pField;
mpLocaleDataWrapper = NULL;
2000-09-18 16:07:07 +00:00
mbReformat = FALSE;
mbStrictFormat = FALSE;
mbEmptyFieldValue = FALSE;
mbEmptyFieldValueEnabled = FALSE;
mbDefaultLocale = TRUE;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
FormatterBase::~FormatterBase()
{
delete mpLocaleDataWrapper;
}
// -----------------------------------------------------------------------
2001-07-20 12:19:24 +00:00
LocaleDataWrapper& FormatterBase::ImplGetLocaleDataWrapper() const
{
if ( !mpLocaleDataWrapper )
{
((FormatterBase*)this)->mpLocaleDataWrapper = new LocaleDataWrapper( vcl::unohelper::GetMultiServiceFactory(), GetLocale() );
}
return *mpLocaleDataWrapper;
2000-09-18 16:07:07 +00:00
}
2001-07-20 12:19:24 +00:00
const LocaleDataWrapper& FormatterBase::GetLocaleDataWrapper() const
{
return ImplGetLocaleDataWrapper();
}
2000-09-18 16:07:07 +00:00
// -----------------------------------------------------------------------
void FormatterBase::Reformat()
{
}
// -----------------------------------------------------------------------
void FormatterBase::ReformatAll()
{
Reformat();
};
// -----------------------------------------------------------------------
void FormatterBase::SetStrictFormat( BOOL bStrict )
{
if ( bStrict != mbStrictFormat )
{
mbStrictFormat = bStrict;
if ( mbStrictFormat )
ReformatAll();
}
}
// -----------------------------------------------------------------------
void FormatterBase::SetLocale( const lang::Locale& rLocale )
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
ImplGetLocaleDataWrapper().setLocale( rLocale );
mbDefaultLocale = FALSE;
ReformatAll();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
const lang::Locale& FormatterBase::GetLocale() const
2000-09-18 16:07:07 +00:00
{
if ( !mpLocaleDataWrapper || mbDefaultLocale )
2000-09-18 16:07:07 +00:00
{
if ( mpField )
return mpField->GetSettings().GetLocale();
2000-09-18 16:07:07 +00:00
else
return Application::GetSettings().GetLocale();
2000-09-18 16:07:07 +00:00
}
return mpLocaleDataWrapper->getLocale();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
const AllSettings& FormatterBase::GetFieldSettings() const
{
if ( mpField )
return mpField->GetSettings();
else
return Application::GetSettings();
}
// -----------------------------------------------------------------------
void FormatterBase::SetFieldText( const XubString& rText, BOOL bKeepSelection )
{
if ( mpField )
{
Selection aNewSelection( 0xFFFF, 0xFFFF );
if ( bKeepSelection )
aNewSelection = mpField->GetSelection();
ImplSetText( rText, &aNewSelection );
}
}
// -----------------------------------------------------------------------
void FormatterBase::ImplSetText( const XubString& rText, Selection* pNewSelection )
{
if ( mpField )
{
if ( pNewSelection )
mpField->SetText( rText, *pNewSelection );
else
{
Selection aSel = mpField->GetSelection();
aSel.Min() = aSel.Max();
mpField->SetText( rText, aSel );
}
MarkToBeReformatted( FALSE );
}
}
// -----------------------------------------------------------------------
void FormatterBase::SetEmptyFieldValue()
{
if ( mpField )
mpField->SetText( ImplGetSVEmptyStr() );
mbEmptyFieldValue = TRUE;
}
// -----------------------------------------------------------------------
BOOL FormatterBase::IsEmptyFieldValue() const
{
return (!mpField || !mpField->GetText().Len());
}
// -----------------------------------------------------------------------
BOOL NumericFormatter::ImplNumericReformat( const XubString& rStr, double& rValue,
XubString& rOutStr )
{
2001-07-20 12:19:24 +00:00
if ( !ImplNumericGetValue( rStr, rValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
return TRUE;
else
{
double nTempVal = rValue;
// caution: precision loss in double cast
2000-09-18 16:07:07 +00:00
if ( nTempVal > mnMax )
nTempVal = (double)mnMax;
2000-09-18 16:07:07 +00:00
else if ( nTempVal < mnMin )
nTempVal = (double)mnMin;
2000-09-18 16:07:07 +00:00
if ( GetErrorHdl().IsSet() && (rValue != nTempVal) )
{
mnCorrectedValue = (sal_Int64)nTempVal;
2000-09-18 16:07:07 +00:00
if ( !GetErrorHdl().Call( this ) )
{
mnCorrectedValue = 0;
return FALSE;
}
else
mnCorrectedValue = 0;
}
rOutStr = CreateFieldText( (sal_Int64)nTempVal );
2000-09-18 16:07:07 +00:00
return TRUE;
}
}
// -----------------------------------------------------------------------
void NumericFormatter::ImplInit()
{
mnFieldValue = 0;
mnLastValue = 0;
mnMin = 0;
mnMax = 0x7FFFFFFFFFFFFFFFLL;
2000-09-18 16:07:07 +00:00
mnCorrectedValue = 0;
mnDecimalDigits = 2;
2000-09-18 16:07:07 +00:00
mnType = FORMAT_NUMERIC;
mbThousandSep = TRUE;
2001-07-20 13:10:33 +00:00
mbShowTrailingZeros = TRUE;
2000-09-18 16:07:07 +00:00
// for fields
2000-09-18 16:07:07 +00:00
mnSpinSize = 1;
mnFirst = mnMin;
mnLast = mnMax;
SetDecimalDigits( 0 );
}
// -----------------------------------------------------------------------
NumericFormatter::NumericFormatter()
{
ImplInit();
}
// -----------------------------------------------------------------------
void NumericFormatter::ImplLoadRes( const ResId& rResId )
2000-09-18 16:07:07 +00:00
{
ResMgr* pMgr = rResId.GetResMgr();
2000-09-18 16:07:07 +00:00
if( pMgr )
{
ULONG nMask = pMgr->ReadLong();
2000-09-18 16:07:07 +00:00
if ( NUMERICFORMATTER_MIN & nMask )
mnMin = pMgr->ReadLong();
2000-09-18 16:07:07 +00:00
if ( NUMERICFORMATTER_MAX & nMask )
mnMax = pMgr->ReadLong();
2000-09-18 16:07:07 +00:00
if ( NUMERICFORMATTER_STRICTFORMAT & nMask )
SetStrictFormat( (BOOL)pMgr->ReadShort() );
2000-09-18 16:07:07 +00:00
if ( NUMERICFORMATTER_DECIMALDIGITS & nMask )
SetDecimalDigits( pMgr->ReadShort() );
2000-09-18 16:07:07 +00:00
if ( NUMERICFORMATTER_VALUE & nMask )
{
mnFieldValue = pMgr->ReadLong();
if ( mnFieldValue > mnMax )
mnFieldValue = mnMax;
else if ( mnFieldValue < mnMin )
mnFieldValue = mnMin;
mnLastValue = mnFieldValue;
}
CWS-TOOLING: integrate CWS dba32g 2009-09-09 07:53:55 +0200 oj r275964 : replace strlen with rtl_str_getLength 2009-09-07 20:59:10 +0200 fs r275913 : disable the CopyTableWizard test until issue 104869 is fixed 2009-09-07 12:17:31 +0200 oj r275885 : #i104810# remove de as lang 2009-09-05 22:26:21 +0200 fs r275857 : protect StateChanged against re-entrance 2009-09-05 22:25:52 +0200 fs r275856 : don't attempt to classify the parent of a form as control 2009-09-05 22:25:29 +0200 fs r275855 : protect against re-entrance 2009-09-05 00:11:40 +0200 fs r275835 : #i10000# 2009-09-04 23:25:50 +0200 fs r275834 : #i10000# 2009-09-04 23:23:47 +0200 fs r275833 : #i10000# 2009-09-04 21:49:37 +0200 fs r275830 : #i10000# correct wrong conflict resolution 2009-09-04 20:59:51 +0200 fs r275829 : CWS-TOOLING: rebase CWS dba32g to trunk@275801 (milestone: DEV300:m57) 2009-09-04 11:08:32 +0200 oj r275791 : #i104780# new version 1.2.0 2009-09-03 22:29:21 +0200 fs r275775 : OSL_TRACE doesn't need \n anymore 2009-09-03 08:33:21 +0200 fs r275743 : CWS-TOOLING: rebase CWS dba32g to trunk@275331 (milestone: DEV300:m56) 2009-09-02 13:48:12 +0200 fs r275708 : removed useless include 2009-09-02 13:45:43 +0200 fs r275707 : more since tags, which are used across offapi/udkapi 2009-09-02 13:23:04 +0200 fs r275705 : should *not* have the dtor, copy ctor, and assignment operator compiler-generated, else we run into trouble as soon as the compiler creates different versions of our singleton member's static data in different libraries 2009-09-02 12:32:45 +0200 fs r275704 : AutoIncrementIsPrimaryKey is a driver setting, not a data source setting 2009-09-02 11:42:49 +0200 fs r275701 : URL meta data are meta data which are valid for all connections of this type, not per-data-source properties. Settings them as data source properties is a hack. 2009-09-02 08:43:34 +0200 fs r275696 : 3.x.x is not a valid 'since' tag 2009-09-01 16:05:24 +0200 fs r275665 : #i104686# don't treat controls bound to read-only columns as required 2009-09-01 13:10:22 +0200 fs r275657 : #i104574# use PageUp/Down to scroll through the complete page 2009-09-01 07:04:48 +0200 oj r275641 : #i104104# correct line ends 2009-08-31 15:52:34 +0200 fs r275612 : #i104410# 2009-08-31 12:29:05 +0200 fs r275596 : #i104364# 2009-08-31 12:28:56 +0200 fs r275595 : #i104364# 2009-08-31 11:43:09 +0200 fs r275593 : #i104649# JavaDriverClassPath is also a known JDBC-bridge setting 2009-08-31 11:41:37 +0200 fs r275592 : #i104649# 2009-08-28 21:48:27 +0200 fs r275552 : during #i96862#: renamed the configuration data which controls availability of certain DBA-related UI 2009-08-28 21:48:17 +0200 fs r275551 : #i96862# do not show the 'Create a new database' option when a) no embedded/dBase driver is installed or b) the configuration requests to hide the option 2009-08-28 21:47:19 +0200 fs r275550 : during #i96862#: renamed the configuration data which controls availability of certain DBA-related UI 2009-08-28 21:46:41 +0200 fs r275549 : #i96862# renamed and extended the configuration data which controls availability of certain DBA-related UI 2009-08-28 15:10:19 +0200 fs r275535 : #i96862# if no embedded driver is installed, use dBase for creating new DBs. If no dBase driver is installed, too, do not offer the 'Create new database' option 2009-08-28 14:03:04 +0200 fs r275532 : #i104454# allow multiple fields to display the same column 2009-08-28 13:14:00 +0200 fs r275528 : #i104584# driver meta data do not belong into a data source's settings 2009-08-28 13:09:57 +0200 fs r275527 : properly chech the MySQL type buttons (else next/back in the wizard leads to state with two buttons checked) 2009-08-28 13:09:17 +0200 fs r275526 : #i104584# driver meta data do not belong into a data source's settings 2009-08-28 13:07:18 +0200 fs r275525 : BooleanComparisonMode is a property, or a feature - but not a driver meta data 2009-08-28 11:00:31 +0200 fs r275521 : #i104580# 2009-08-28 10:40:05 +0200 fs r275519 : #i104577# correct assertion: If the template node type is ANY, then any value type is allowed 2009-08-28 10:09:30 +0200 fs r275518 : #i104575# implement Named Pipe UI 2009-08-28 10:09:07 +0200 fs r275517 : pass the trigger-event to IWindowOperator::operateOn / work with VclWindowEvents, not VclSimpleEvents 2009-08-27 14:27:36 +0200 fs r275484 : ImplPosTabPage: respect mbEmptyViewMargin for WINDOWALIGN_LEFT 2009-08-27 13:43:56 +0200 fs r275480 : merging latest changes from CWS dba32f herein 2009-08-27 13:23:07 +0200 fs r275475 : #i103882# 2009-08-27 11:56:55 +0200 fs r275466 : #i104544# SetState: Do not call Update at the window which we just set text for. It should (sic\!) not be needed, but causes trouble 2009-08-27 11:55:34 +0200 fs r275465 : #i104544# do not allow re-entrance for impl_ensureControl_nothrow Actually, this is part of the fix only. I also removed the code which triggered this re-entrance (from the grid control implementation), but to ensure it won't happen, again, I added some safety herein. 2009-08-27 10:14:11 +0200 fs r275459 : preparations for supporting a 'NamedPipe' parameter for the MySQL Connector/OOo 2009-08-27 10:13:21 +0200 fs r275458 : preparations for supporting a 'NamedPipe' setting for the MySQL Connector/OOo 2009-08-27 10:11:14 +0200 fs r275456 : outsourced the MySQLNative settings into a dedicated class, to not duplicate all the code in two tab page implementations 2009-08-26 14:18:13 +0200 fs r275422 : #i10000# 2009-08-26 13:26:36 +0200 fs r275419 : ignore output paths 2009-08-26 13:23:38 +0200 fs r275417 : support the LocalSocket property for the MySQL native driver 2009-08-26 13:17:05 +0200 fs r275416 : some re-factoring, to outsource the tab page for setting up the MySQLNative connection, into a dedicated class (needed later) 2009-08-26 13:15:15 +0200 fs r275415 : support a NoThousandSep property for NumericFormatters - I'm tired of correcting this at runtime, instead of controlling it in the resource 2009-08-26 11:45:08 +0200 fs r275410 : oops, 'flat' shouldn't have got lost 2009-08-26 09:38:57 +0200 fs r275398 : #i102631# when saving the document fails, ensure that the interaction handler really can handle/display the error 2009-08-26 09:37:05 +0200 fs r275397 : #i102631# don't let non-IO/RuntimeExceptions escape from DatabaseDocument::store*, wrap them into an IOException 2009-08-26 09:35:39 +0200 fs r275395 : let the default interaction handler implement XInteractionHandler2 2009-08-25 13:51:34 +0200 fs r275352 : #i102631# createTempFile: pass URL through FileHelper.getOOoCompatibleFileURL 2009-08-25 13:49:23 +0200 fs r275351 : #i102631# createTempFileURL: immediately delete the file implicitly created by createTempFile, we really only need the URL 2009-08-24 14:49:07 +0200 fs r275318 : #i10000# 2009-08-24 14:36:03 +0200 fs r275315 : properly terminate message with 0 character 2009-08-24 14:35:45 +0200 fs r275314 : trace method concepts in non-pro, if special flag is enabled 2009-08-24 14:24:17 +0200 fs r275312 : #i98973# filter some more events for grid control columns 2009-08-24 14:15:23 +0200 fs r275311 : #i98973# implement XComboBox for combo box cells 2009-08-24 13:39:24 +0200 fs r275308 : #i98973# do not display the 'actionPerformed' event for grid combo box columns 2009-08-24 12:52:03 +0200 fs r275303 : #i98973# implement XCheckBox and XButton for check box cells 2009-08-24 11:56:05 +0200 oj r275300 : #i104447# wrong default for orientation 2009-08-24 10:51:21 +0200 fs r275296 : in the script selector dialog, interpret a double click onto a function as OK 2009-08-24 10:50:56 +0200 fs r275295 : localize some to-be-displayed names, consolidate some code regarding form/control naming 2009-08-21 14:28:05 +0200 fs r275255 : #i98973# implement KeyListeners 2009-08-21 14:27:20 +0200 fs r275254 : #i98973# move the conversion VCL[Mouse|Key]Event->Awt[Mouse|Key]Event from vclxwindow.cxx to VCLUnoHelper 2009-08-21 14:08:50 +0200 fs r275248 : #i98973# implement Mouse- and MouseMotion-broadcasting 2009-08-21 13:31:08 +0200 fs r275244 : #i98973# implement text and change listeners at text cells 2009-08-21 12:47:38 +0200 fs r275234 : #i104399# some refactoring: If the MySQL Connector/OOo is installed, it registers for the sdbc:mysqlc: protocol (now known as DST_MYSQL_NATIVE_DIRECT). However, we do not want to display this in the UI, instead we display "MySQL" only, which collects DST_MYSQL_ODBC, DST_MYSQL_JDBC, and DST_MYSQL_NATIVE. 2009-08-21 12:45:18 +0200 fs r275232 : #i104399# also register for the sdbc:mysql:mysqlc protocol, decide at runtime (depending on the availability of sdbc:mysqlc:), whether it is really accepted. This prevents that the C/OOo extension needs to register *our* implementation name for the sdbc:mysql:mysqlc: protocol, which would be somewhat weird 2009-08-20 16:18:48 +0200 fs r275190 : merging the latest changes from CWS dba32f (which this CWS was created from) 2009-08-19 20:19:59 +0200 fs r275160 : add some spacing between the radios 2009-08-19 14:50:15 +0200 fs r275150 : #i98973# slightly refactoring the grid cell implementations, to prepare for proper events being fired. Implement focus events for the moment, more to come. 2009-08-19 10:53:38 +0200 fs r275142 : #i99936# initialize newly created models 2009-08-18 23:03:48 +0200 fs r275132 : merging latest changes from CWS dba32f 2009-08-18 15:14:08 +0200 fs r275110 : #i102819# SetColumnPos: SCROLL_CLIP is deadly here
2009-09-14 11:18:01 +00:00
if ( NUMERICFORMATTER_NOTHOUSANDSEP & nMask )
SetUseThousandSep( !(BOOL)pMgr->ReadShort() );
2000-09-18 16:07:07 +00:00
}
}
// -----------------------------------------------------------------------
NumericFormatter::~NumericFormatter()
{
}
// -----------------------------------------------------------------------
void NumericFormatter::SetMin( sal_Int64 nNewMin )
2000-09-18 16:07:07 +00:00
{
mnMin = nNewMin;
if ( !IsEmptyFieldValue() )
ReformatAll();
}
// -----------------------------------------------------------------------
void NumericFormatter::SetMax( sal_Int64 nNewMax )
2000-09-18 16:07:07 +00:00
{
mnMax = nNewMax;
if ( !IsEmptyFieldValue() )
ReformatAll();
}
// -----------------------------------------------------------------------
void NumericFormatter::SetUseThousandSep( BOOL b )
{
mbThousandSep = b;
ReformatAll();
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void NumericFormatter::SetDecimalDigits( USHORT nDigits )
{
mnDecimalDigits = nDigits;
ReformatAll();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
2001-07-20 13:10:33 +00:00
void NumericFormatter::SetShowTrailingZeros( BOOL bShowTrailingZeros )
{
if ( mbShowTrailingZeros != bShowTrailingZeros )
{
mbShowTrailingZeros = bShowTrailingZeros;
ReformatAll();
}
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
USHORT NumericFormatter::GetDecimalDigits() const
{
return mnDecimalDigits;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void NumericFormatter::SetValue( sal_Int64 nNewValue )
2000-09-18 16:07:07 +00:00
{
SetUserValue( nNewValue );
mnFieldValue = mnLastValue;
SetEmptyFieldValueData( FALSE );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
XubString NumericFormatter::CreateFieldText( sal_Int64 nValue ) const
2000-09-18 16:07:07 +00:00
{
2001-07-20 13:10:33 +00:00
return ImplGetLocaleDataWrapper().getNum( nValue, GetDecimalDigits(), IsUseThousandSep(), IsShowTrailingZeros() );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void NumericFormatter::ImplSetUserValue( sal_Int64 nNewValue, Selection* pNewSelection )
2000-09-18 16:07:07 +00:00
{
if ( nNewValue > mnMax )
nNewValue = mnMax;
else if ( nNewValue < mnMin )
nNewValue = mnMin;
mnLastValue = nNewValue;
if ( GetField() )
ImplSetText( CreateFieldText( nNewValue ), pNewSelection );
}
// -----------------------------------------------------------------------
void NumericFormatter::SetUserValue( sal_Int64 nNewValue )
2000-09-18 16:07:07 +00:00
{
ImplSetUserValue( nNewValue );
}
// -----------------------------------------------------------------------
sal_Int64 NumericFormatter::GetValue() const
2000-09-18 16:07:07 +00:00
{
if ( !GetField() )
return 0;
double nTempValue;
if ( ImplNumericGetValue( GetField()->GetText(), nTempValue,
2001-07-20 12:19:24 +00:00
GetDecimalDigits(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
{
// caution: precision loss in double cast
2000-09-18 16:07:07 +00:00
if ( nTempValue > mnMax )
nTempValue = (double)mnMax;
2000-09-18 16:07:07 +00:00
else if ( nTempValue < mnMin )
nTempValue = (double)mnMin;
return (sal_Int64)nTempValue;
2000-09-18 16:07:07 +00:00
}
else
return mnLastValue;
}
// -----------------------------------------------------------------------
BOOL NumericFormatter::IsValueModified() const
{
if ( ImplGetEmptyFieldValue() )
return !IsEmptyFieldValue();
else if ( GetValue() != mnFieldValue )
return TRUE;
else
return FALSE;
}
// -----------------------------------------------------------------------
Fraction NumericFormatter::ConvertToFraction( sal_Int64 nValue )
2000-09-18 16:07:07 +00:00
{
// caution: precision loss in double cast (and in fraction anyhow)
return Fraction( (double)nValue/(double)ImplPower10( GetDecimalDigits() ) );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
sal_Int64 NumericFormatter::ConvertToLong( const Fraction& rValue )
2000-09-18 16:07:07 +00:00
{
Fraction aFract = rValue;
aFract *= Fraction( (long)ImplPower10( GetDecimalDigits() ), 1 );
return (sal_Int64)(double)aFract;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
sal_Int64 NumericFormatter::Normalize( sal_Int64 nValue ) const
2000-09-18 16:07:07 +00:00
{
return (nValue * ImplPower10( GetDecimalDigits() ) );
}
// -----------------------------------------------------------------------
sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue ) const
2000-09-18 16:07:07 +00:00
{
sal_Int64 nFactor = ImplPower10( GetDecimalDigits() );
2000-09-18 16:07:07 +00:00
if( nValue < 0 )
return ((nValue-(nFactor/2)) / nFactor );
else
return ((nValue+(nFactor/2)) / nFactor );
}
// -----------------------------------------------------------------------
void NumericFormatter::Reformat()
{
if ( !GetField() )
return;
if ( !GetField()->GetText().Len() && ImplGetEmptyFieldValue() )
return;
XubString aStr;
// caution: precision loss in double cast
double nTemp = (double)mnLastValue;
2000-09-18 16:07:07 +00:00
BOOL bOK = ImplNumericReformat( GetField()->GetText(), nTemp, aStr );
mnLastValue = (sal_Int64)nTemp;
2000-09-18 16:07:07 +00:00
if ( !bOK )
return;
if ( aStr.Len() )
ImplSetText( aStr );
else
SetValue( mnLastValue );
}
// -----------------------------------------------------------------------
void NumericFormatter::FieldUp()
{
sal_Int64 nValue = GetValue();
2000-09-18 16:07:07 +00:00
nValue += mnSpinSize;
if ( nValue > mnMax )
nValue = mnMax;
ImplNewFieldValue( nValue );
}
// -----------------------------------------------------------------------
void NumericFormatter::FieldDown()
{
sal_Int64 nValue = GetValue();
2000-09-18 16:07:07 +00:00
nValue -= mnSpinSize;
if ( nValue < mnMin )
nValue = mnMin;
ImplNewFieldValue( nValue );
}
// -----------------------------------------------------------------------
void NumericFormatter::FieldFirst()
{
ImplNewFieldValue( mnFirst );
}
// -----------------------------------------------------------------------
void NumericFormatter::FieldLast()
{
ImplNewFieldValue( mnLast );
}
// -----------------------------------------------------------------------
void NumericFormatter::ImplNewFieldValue( sal_Int64 nNewValue )
2000-09-18 16:07:07 +00:00
{
if ( GetField() )
{
// !!! TH-18.2.99: Wenn wir Zeit haben sollte mal geklaert werden,
// !!! warum nicht bei ImplSetUserValue() geprueft wird, ob
// !!! sich der Wert aendert. Denn auch hier muesste dieses
// !!! gemacht werden, da ansonsten der Modify-Aufruf
// !!! nicht gemacht werden duerfte. Jedenfalls sollten die
// !!! Wege von ImplNewFieldValue, ImplSetUserValue und
// !!! ImplSetText ueberprueft und klarer gestalltet (mit Kommentar)
// !!! werden, damit wir mal wissen, was dort ablaeuft!!!
Selection aSelection = GetField()->GetSelection();
aSelection.Justify();
XubString aText = GetField()->GetText();
// Wenn bis ans Ende selektiert war, soll das auch so bleiben...
if ( (xub_StrLen)aSelection.Max() == aText.Len() )
{
if ( !aSelection.Len() )
aSelection.Min() = SELECTION_MAX;
aSelection.Max() = SELECTION_MAX;
}
sal_Int64 nOldLastValue = mnLastValue;
2000-09-18 16:07:07 +00:00
ImplSetUserValue( nNewValue, &aSelection );
mnLastValue = nOldLastValue;
// Modify am Edit wird nur bei KeyInput gesetzt...
if ( GetField()->GetText() != aText )
{
GetField()->SetModifyFlag();
GetField()->Modify();
}
}
}
// -----------------------------------------------------------------------
NumericField::NumericField( Window* pParent, WinBits nWinStyle ) :
SpinField( pParent, nWinStyle )
{
SetField( this );
Reformat();
}
// -----------------------------------------------------------------------
NumericField::NumericField( Window* pParent, const ResId& rResId ) :
SpinField( WINDOW_NUMERICFIELD )
{
rResId.SetRT( RSC_NUMERICFIELD );
WinBits nStyle = ImplInitRes( rResId ) ;
SpinField::ImplInit( pParent, nStyle );
SetField( this );
ImplLoadRes( rResId );
Reformat();
if ( !(nStyle & WB_HIDE ) )
Show();
}
// -----------------------------------------------------------------------
void NumericField::ImplLoadRes( const ResId& rResId )
{
SpinField::ImplLoadRes( rResId );
NumericFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) );
2000-09-18 16:07:07 +00:00
ULONG nMask = ReadLongRes();
2000-09-18 16:07:07 +00:00
if ( NUMERICFIELD_FIRST & nMask )
mnFirst = ReadLongRes();
if ( NUMERICFIELD_LAST & nMask )
mnLast = ReadLongRes();
if ( NUMERICFIELD_SPINSIZE & nMask )
mnSpinSize = ReadLongRes();
}
// -----------------------------------------------------------------------
NumericField::~NumericField()
{
}
// -----------------------------------------------------------------------
long NumericField::PreNotify( NotifyEvent& rNEvt )
{
if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
if ( ImplNumericProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
return 1;
}
return SpinField::PreNotify( rNEvt );
}
// -----------------------------------------------------------------------
long NumericField::Notify( NotifyEvent& rNEvt )
{
if ( rNEvt.GetType() == EVENT_GETFOCUS )
MarkToBeReformatted( FALSE );
else if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
{
if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) )
Reformat();
}
return SpinField::Notify( rNEvt );
}
// -----------------------------------------------------------------------
void NumericField::DataChanged( const DataChangedEvent& rDCEvt )
{
SpinField::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) )
{
String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
if ( IsDefaultLocale() )
2001-07-20 12:19:24 +00:00
ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() );
String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this );
2000-09-18 16:07:07 +00:00
ReformatAll();
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void NumericField::Modify()
{
MarkToBeReformatted( TRUE );
SpinField::Modify();
}
// -----------------------------------------------------------------------
void NumericField::Up()
{
FieldUp();
SpinField::Up();
}
// -----------------------------------------------------------------------
void NumericField::Down()
{
FieldDown();
SpinField::Down();
}
// -----------------------------------------------------------------------
void NumericField::First()
{
FieldFirst();
SpinField::First();
}
// -----------------------------------------------------------------------
void NumericField::Last()
{
FieldLast();
SpinField::Last();
}
// -----------------------------------------------------------------------
NumericBox::NumericBox( Window* pParent, WinBits nWinStyle ) :
ComboBox( pParent, nWinStyle )
{
SetField( this );
Reformat();
}
// -----------------------------------------------------------------------
NumericBox::NumericBox( Window* pParent, const ResId& rResId ) :
ComboBox( WINDOW_NUMERICBOX )
{
rResId.SetRT( RSC_NUMERICBOX );
WinBits nStyle = ImplInitRes( rResId );
ComboBox::ImplInit( pParent, nStyle );
SetField( this );
ComboBox::ImplLoadRes( rResId );
NumericFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) );
2000-09-18 16:07:07 +00:00
Reformat();
if ( !(nStyle & WB_HIDE ) )
Show();
}
// -----------------------------------------------------------------------
NumericBox::~NumericBox()
{
}
// -----------------------------------------------------------------------
long NumericBox::PreNotify( NotifyEvent& rNEvt )
{
if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
if ( ImplNumericProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
return 1;
}
return ComboBox::PreNotify( rNEvt );
}
// -----------------------------------------------------------------------
long NumericBox::Notify( NotifyEvent& rNEvt )
{
if ( rNEvt.GetType() == EVENT_GETFOCUS )
MarkToBeReformatted( FALSE );
else if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
{
if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) )
Reformat();
}
return ComboBox::Notify( rNEvt );
}
// -----------------------------------------------------------------------
void NumericBox::DataChanged( const DataChangedEvent& rDCEvt )
{
ComboBox::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) )
{
String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
if ( IsDefaultLocale() )
2001-07-20 12:19:24 +00:00
ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() );
String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this );
2000-09-18 16:07:07 +00:00
ReformatAll();
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void NumericBox::Modify()
{
MarkToBeReformatted( TRUE );
ComboBox::Modify();
}
// -----------------------------------------------------------------------
void NumericBox::ReformatAll()
{
double nValue;
XubString aStr;
SetUpdateMode( FALSE );
USHORT nEntryCount = GetEntryCount();
for ( USHORT i=0; i < nEntryCount; i++ )
{
ImplNumericReformat( GetEntry( i ), nValue, aStr );
RemoveEntry( i );
InsertEntry( aStr, i );
}
NumericFormatter::Reformat();
SetUpdateMode( TRUE );
}
// -----------------------------------------------------------------------
void NumericBox::InsertValue( sal_Int64 nValue, USHORT nPos )
2000-09-18 16:07:07 +00:00
{
ComboBox::InsertEntry( CreateFieldText( nValue ), nPos );
}
// -----------------------------------------------------------------------
void NumericBox::RemoveValue( sal_Int64 nValue )
2000-09-18 16:07:07 +00:00
{
ComboBox::RemoveEntry( CreateFieldText( nValue ) );
}
// -----------------------------------------------------------------------
sal_Int64 NumericBox::GetValue( USHORT nPos ) const
2000-09-18 16:07:07 +00:00
{
double nValue = 0;
2001-07-20 12:19:24 +00:00
ImplNumericGetValue( ComboBox::GetEntry( nPos ), nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() );
return (sal_Int64)nValue;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
USHORT NumericBox::GetValuePos( sal_Int64 nValue ) const
2000-09-18 16:07:07 +00:00
{
return ComboBox::GetEntryPos( CreateFieldText( nValue ) );
}
// -----------------------------------------------------------------------
static BOOL ImplMetricProcessKeyInput( Edit* pEdit, const KeyEvent& rKEvt,
BOOL, BOOL bUseThousandSep, const LocaleDataWrapper& rWrapper )
2000-09-18 16:07:07 +00:00
{
// Es gibt hier kein sinnvolles StrictFormat, also alle
// Zeichen erlauben
return ImplNumericProcessKeyInput( pEdit, rKEvt, FALSE, bUseThousandSep, rWrapper );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
static XubString ImplMetricGetUnitText( const XubString& rStr )
{
// Einheitentext holen
XubString aStr;
for ( short i = rStr.Len()-1; i >= 0; i-- )
{
xub_Unicode c = rStr.GetChar( i );
2008-10-01 13:31:44 +00:00
if ( unicode::isAlpha( c ) ||
2000-09-18 16:07:07 +00:00
(c == '\'') || (c == '\"') || (c == '%' ) )
aStr.Insert( c, 0 );
else
{
if ( aStr.Len() )
break;
}
}
return aStr;
/*
// MT: #90545# Preparation for translated strings...
String aMetricText;
for ( USHORT n = rStr.Len(); n; )
{
sal_Unicode c = rStr.GetChar( --n );
sal_Int32 nType = xCharClass->getStringType( rStr, n, 1, rLocale );
if ( CharClass::isLetterType( nType ) )
{
aMetricText.Insert( c, 0 );
}
else
{
if ( aMetricText.Len() )
break;
}
}
*/
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
// #104355# support localized mesaurements
static String ImplMetricToString( FieldUnit rUnit )
{
if( !strAllUnits )
{
ResMgr* pResMgr = ImplGetResMgr();
strAllUnits = new ResStringArray( ResId (SV_FUNIT_STRINGS, *pResMgr) );
}
// return unit's default string (ie, the first one )
for( USHORT i=0; i < strAllUnits->Count(); i++ )
if( (FieldUnit) strAllUnits->GetValue( i ) == rUnit )
return strAllUnits->GetString( i );
return String();
}
static FieldUnit ImplStringToMetric( const String &rMetricString )
{
if( !strAllUnits )
{
ResMgr* pResMgr = ImplGetResMgr();
strAllUnits = new ResStringArray( ResId (SV_FUNIT_STRINGS, *pResMgr) );
}
// return FieldUnit
String aStr( rMetricString );
aStr.ToLowerAscii();
for( USHORT i=0; i < strAllUnits->Count(); i++ )
if ( strAllUnits->GetString( i ).Equals( aStr ) )
return (FieldUnit) strAllUnits->GetValue( i );
return FUNIT_NONE;
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
static FieldUnit ImplMetricGetUnit( const XubString& rStr )
{
XubString aStr = ImplMetricGetUnitText( rStr );
return ImplStringToMetric( aStr );
2000-09-18 16:07:07 +00:00
}
#define K *1000L
#define M *1000000L
#define X *5280L
static const sal_Int64 aImplFactor[FUNIT_MILE+1][FUNIT_MILE+1] =
2000-09-18 16:07:07 +00:00
{ /*
mm/100 mm cm m km twip point pica inch foot mile */
{ 1, 100, 1 K, 100 K, 100 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X },
{ 1, 1, 10, 1 K, 1 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X },
{ 1, 1, 1, 100, 100 K, 254, 254, 254, 254, 254*12, 254*12 X },
{ 1, 1, 1, 1, 1 K, 254, 254, 254, 254, 254*12, 254*12 X },
{ 1, 1, 1, 1, 1, 0, 254, 254, 254, 254*12, 254*12 X },
{ 1440,144 K,144 K,14400 K, 0, 1, 20, 240, 1440,1440*12,1440*12 X },
{ 72, 7200, 7200, 720 K, 720 M, 1, 1, 12, 72, 72*12, 72*12 X },
{ 6, 600, 600, 60 K, 60 M, 1, 1, 1, 6, 6*12, 6*12 X },
{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 12, 12 X },
{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 X },
{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 }
};
#undef X
#undef M
#undef K
// twip in km 254/14400 M
static FieldUnit eDefaultUnit = FUNIT_NONE;
FieldUnit MetricField::GetDefaultUnit() { return eDefaultUnit; }
void MetricField::SetDefaultUnit( FieldUnit meUnit ) { eDefaultUnit = meUnit; }
static FieldUnit ImplMap2FieldUnit( MapUnit meUnit, long& nDecDigits )
{
switch( meUnit )
{
case MAP_100TH_MM :
nDecDigits -= 2;
return FUNIT_MM;
case MAP_10TH_MM :
nDecDigits -= 1;
return FUNIT_MM;
case MAP_MM :
return FUNIT_MM;
case MAP_CM :
return FUNIT_CM;
case MAP_1000TH_INCH :
nDecDigits -= 3;
return FUNIT_INCH;
case MAP_100TH_INCH :
nDecDigits -= 2;
return FUNIT_INCH;
case MAP_10TH_INCH :
nDecDigits -= 1;
return FUNIT_INCH;
case MAP_INCH :
return FUNIT_INCH;
case MAP_POINT :
return FUNIT_POINT;
case MAP_TWIP :
return FUNIT_TWIP;
default:
DBG_ERROR( "default eInUnit" );
break;
}
return FUNIT_NONE;
}
// -----------------------------------------------------------------------
static double nonValueDoubleToValueDouble( double nValue )
{
return rtl::math::isFinite( nValue ) ? nValue : 0.0;
}
sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, USHORT nDecDigits,
FieldUnit eInUnit, FieldUnit eOutUnit )
2000-09-18 16:07:07 +00:00
{
// caution: precision loss in double cast
return static_cast<sal_Int64>(
// #150733# cast double to sal_Int64 can throw a
// EXCEPTION_FLT_INVALID_OPERATION on Windows
nonValueDoubleToValueDouble(
ConvertDoubleValue( (double)nValue, mnBaseValue, nDecDigits,
eInUnit, eOutUnit ) ) );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits,
MapUnit eInUnit, FieldUnit eOutUnit )
2000-09-18 16:07:07 +00:00
{
return static_cast<sal_Int64>(
// #150733# cast double to sal_Int64 can throw a
// EXCEPTION_FLT_INVALID_OPERATION on Windows
nonValueDoubleToValueDouble(
ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits,
FieldUnit eInUnit, MapUnit eOutUnit )
2000-09-18 16:07:07 +00:00
{
return static_cast<sal_Int64>(
// #150733# cast double to sal_Int64 can throw a
// EXCEPTION_FLT_INVALID_OPERATION on Windows
nonValueDoubleToValueDouble(
ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
double MetricField::ConvertDoubleValue( double nValue, sal_Int64 mnBaseValue, USHORT nDecDigits,
2000-09-18 16:07:07 +00:00
FieldUnit eInUnit, FieldUnit eOutUnit )
{
if ( eInUnit != eOutUnit )
{
sal_Int64 nMult = 1, nDiv = 1;
2000-09-18 16:07:07 +00:00
if ( eInUnit == FUNIT_PERCENT )
{
if ( (mnBaseValue <= 0) || (nValue <= 0) )
return nValue;
nDiv = 100;
for ( USHORT i=0; i < nDecDigits; i++ )
nDiv *= 10;
nMult = mnBaseValue;
}
else if ( eOutUnit == FUNIT_PERCENT ||
eOutUnit == FUNIT_CUSTOM ||
eOutUnit == FUNIT_NONE ||
eInUnit == FUNIT_CUSTOM ||
eInUnit == FUNIT_NONE )
return nValue;
else
{
if ( eOutUnit == FUNIT_100TH_MM )
eOutUnit = FUNIT_NONE;
if ( eInUnit == FUNIT_100TH_MM )
eInUnit = FUNIT_NONE;
nDiv = aImplFactor[eInUnit][eOutUnit];
nMult = aImplFactor[eOutUnit][eInUnit];
DBG_ASSERT( nMult > 0, "illegal *" );
DBG_ASSERT( nDiv > 0, "illegal /" );
}
if ( nMult != 1 && nMult > 0 )
2000-09-18 16:07:07 +00:00
nValue *= nMult;
if ( nDiv != 1 && nDiv > 0 )
2000-09-18 16:07:07 +00:00
{
nValue += ( nValue < 0 ) ? (-nDiv/2) : (nDiv/2);
nValue /= nDiv;
}
}
return nValue;
}
// -----------------------------------------------------------------------
double MetricField::ConvertDoubleValue( double nValue, USHORT nDigits,
MapUnit eInUnit, FieldUnit eOutUnit )
{
if ( eOutUnit == FUNIT_PERCENT ||
eOutUnit == FUNIT_CUSTOM ||
eOutUnit == FUNIT_NONE ||
eInUnit == MAP_PIXEL ||
eInUnit == MAP_SYSFONT ||
eInUnit == MAP_APPFONT ||
eInUnit == MAP_RELATIVE )
{
DBG_ERROR( "invalid parameters" );
return nValue;
}
long nDecDigits = nDigits;
FieldUnit eFieldUnit = ImplMap2FieldUnit( eInUnit, nDecDigits );
if ( nDecDigits < 0 )
2000-09-18 16:07:07 +00:00
{
while ( nDecDigits )
{
nValue += 5;
nValue /= 10;
nDecDigits++;
}
}
else
{
while ( nDecDigits )
{
nValue *= 10;
nDecDigits--;
}
}
if ( eFieldUnit != eOutUnit )
{
sal_Int64 nDiv = aImplFactor[eFieldUnit][eOutUnit];
sal_Int64 nMult = aImplFactor[eOutUnit][eFieldUnit];
2000-09-18 16:07:07 +00:00
DBG_ASSERT( nMult > 0, "illegal *" );
DBG_ASSERT( nDiv > 0, "illegal /" );
if ( nMult != 1 && nMult > 0)
2000-09-18 16:07:07 +00:00
nValue *= nMult;
if ( nDiv != 1 && nDiv > 0 )
2000-09-18 16:07:07 +00:00
{
nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2);
nValue /= nDiv;
}
}
return nValue;
}
// -----------------------------------------------------------------------
double MetricField::ConvertDoubleValue( double nValue, USHORT nDigits,
FieldUnit eInUnit, MapUnit eOutUnit )
{
if ( eInUnit == FUNIT_PERCENT ||
eInUnit == FUNIT_CUSTOM ||
eInUnit == FUNIT_NONE ||
eOutUnit == MAP_PIXEL ||
eOutUnit == MAP_SYSFONT ||
eOutUnit == MAP_APPFONT ||
eOutUnit == MAP_RELATIVE )
{
DBG_ERROR( "invalid parameters" );
return nValue;
}
long nDecDigits = nDigits;
FieldUnit eFieldUnit = ImplMap2FieldUnit( eOutUnit, nDecDigits );
if ( nDecDigits < 0 )
2000-09-18 16:07:07 +00:00
{
while ( nDecDigits )
{
nValue *= 10;
nDecDigits++;
}
}
else
{
while ( nDecDigits )
{
nValue += 5;
nValue /= 10;
nDecDigits--;
}
}
if ( eFieldUnit != eInUnit )
{
sal_Int64 nDiv = aImplFactor[eInUnit][eFieldUnit];
sal_Int64 nMult = aImplFactor[eFieldUnit][eInUnit];
2000-09-18 16:07:07 +00:00
DBG_ASSERT( nMult > 0, "illegal *" );
DBG_ASSERT( nDiv > 0, "illegal /" );
if( nMult != 1 && nMult > 0 )
2000-09-18 16:07:07 +00:00
nValue *= nMult;
if( nDiv != 1 && nDiv > 0 )
2000-09-18 16:07:07 +00:00
{
nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2);
nValue /= nDiv;
}
}
return nValue;
}
// -----------------------------------------------------------------------
static BOOL ImplMetricGetValue( const XubString& rStr, double& rValue, sal_Int64 nBaseValue,
USHORT nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit )
2000-09-18 16:07:07 +00:00
{
// Zahlenwert holen
if ( !ImplNumericGetValue( rStr, rValue, nDecDigits, rLocaleDataWrapper ) )
2000-09-18 16:07:07 +00:00
return FALSE;
// Einheit rausfinden
FieldUnit eEntryUnit = ImplMetricGetUnit( rStr );
// Einheiten umrechnen
rValue = MetricField::ConvertDoubleValue( rValue, nBaseValue, nDecDigits, eEntryUnit, eUnit );
return TRUE;
}
// -----------------------------------------------------------------------
BOOL MetricFormatter::ImplMetricReformat( const XubString& rStr, double& rValue, XubString& rOutStr )
{
2001-07-20 12:19:24 +00:00
if ( !ImplMetricGetValue( rStr, rValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) )
2000-09-18 16:07:07 +00:00
return TRUE;
else
{
double nTempVal = rValue;
// caution: precision loss in double cast
2000-09-18 16:07:07 +00:00
if ( nTempVal > GetMax() )
nTempVal = (double)GetMax();
2000-09-18 16:07:07 +00:00
else if ( nTempVal < GetMin())
nTempVal = (double)GetMin();
2000-09-18 16:07:07 +00:00
if ( GetErrorHdl().IsSet() && (rValue != nTempVal) )
{
mnCorrectedValue = (sal_Int64)nTempVal;
2000-09-18 16:07:07 +00:00
if ( !GetErrorHdl().Call( this ) )
{
mnCorrectedValue = 0;
return FALSE;
}
else
mnCorrectedValue = 0;
}
rOutStr = CreateFieldText( (sal_Int64)nTempVal );
2000-09-18 16:07:07 +00:00
return TRUE;
}
}
// -----------------------------------------------------------------------
inline void MetricFormatter::ImplInit()
{
mnBaseValue = 0;
meUnit = MetricField::GetDefaultUnit();
mnType = FORMAT_METRIC;
}
// -----------------------------------------------------------------------
MetricFormatter::MetricFormatter()
{
ImplInit();
}
// -----------------------------------------------------------------------
void MetricFormatter::ImplLoadRes( const ResId& rResId )
{
NumericFormatter::ImplLoadRes( rResId );
ResMgr* pMgr = rResId.GetResMgr();
if( pMgr )
{
ULONG nMask = pMgr->ReadLong();
2000-09-18 16:07:07 +00:00
if ( METRICFORMATTER_UNIT & nMask )
meUnit = (FieldUnit)pMgr->ReadLong();
2000-09-18 16:07:07 +00:00
if ( METRICFORMATTER_CUSTOMUNITTEXT & nMask )
maCustomUnitText = pMgr->ReadString();
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
MetricFormatter::~MetricFormatter()
{
}
// -----------------------------------------------------------------------
void MetricFormatter::SetUnit( FieldUnit eNewUnit )
{
if ( eNewUnit == FUNIT_100TH_MM )
{
SetDecimalDigits( GetDecimalDigits() + 2 );
meUnit = FUNIT_MM;
}
else
meUnit = eNewUnit;
ReformatAll();
}
// -----------------------------------------------------------------------
void MetricFormatter::SetCustomUnitText( const XubString& rStr )
{
maCustomUnitText = rStr;
ReformatAll();
}
// -----------------------------------------------------------------------
void MetricFormatter::SetValue( sal_Int64 nNewValue, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
SetUserValue( nNewValue, eInUnit );
mnFieldValue = mnLastValue;
}
// -----------------------------------------------------------------------
XubString MetricFormatter::CreateFieldText( sal_Int64 nValue ) const
2000-09-18 16:07:07 +00:00
{
XubString aStr = NumericFormatter::CreateFieldText( nValue );
if( meUnit == FUNIT_CUSTOM )
aStr += maCustomUnitText;
else
aStr += ImplMetricToString( meUnit );
return aStr;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void MetricFormatter::SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf eingestellte Einheiten
nNewValue = MetricField::ConvertValue( nNewValue, mnBaseValue, GetDecimalDigits(), eInUnit, meUnit );
NumericFormatter::SetUserValue( nNewValue );
}
// -----------------------------------------------------------------------
sal_Int64 MetricFormatter::GetValue( FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
if ( !GetField() )
return 0;
double nTempValue;
// caution: precision loss in double cast
2001-07-20 12:19:24 +00:00
if ( !ImplMetricGetValue( GetField()->GetText(), nTempValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) )
nTempValue = (double)mnLastValue;
2000-09-18 16:07:07 +00:00
// caution: precision loss in double cast
2000-09-18 16:07:07 +00:00
if ( nTempValue > mnMax )
nTempValue = (double)mnMax;
2000-09-18 16:07:07 +00:00
else if ( nTempValue < mnMin )
nTempValue = (double)mnMin;
2000-09-18 16:07:07 +00:00
// Umrechnen auf gewuenschte Einheiten
return MetricField::ConvertValue( (sal_Int64)nTempValue, mnBaseValue, GetDecimalDigits(), meUnit, eOutUnit );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void MetricFormatter::SetValue( sal_Int64 nValue )
{
// Implementation not inline, because it is a virtual Function
SetValue( nValue, FUNIT_NONE );
}
// -----------------------------------------------------------------------
sal_Int64 MetricFormatter::GetValue() const
{
// Implementation not inline, because it is a virtual Function
return GetValue( FUNIT_NONE );
}
// -----------------------------------------------------------------------
void MetricFormatter::SetMin( sal_Int64 nNewMin, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf gewuenschte Einheiten
NumericFormatter::SetMin( MetricField::ConvertValue( nNewMin, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit ) );
}
// -----------------------------------------------------------------------
sal_Int64 MetricFormatter::GetMin( FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf gewuenschte Einheiten
return MetricField::ConvertValue( NumericFormatter::GetMin(), mnBaseValue,
GetDecimalDigits(), meUnit, eOutUnit );
}
// -----------------------------------------------------------------------
void MetricFormatter::SetMax( sal_Int64 nNewMax, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf gewuenschte Einheiten
NumericFormatter::SetMax( MetricField::ConvertValue( nNewMax, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit ) );
}
// -----------------------------------------------------------------------
sal_Int64 MetricFormatter::GetMax( FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf gewuenschte Einheiten
return MetricField::ConvertValue( NumericFormatter::GetMax(), mnBaseValue,
GetDecimalDigits(), meUnit, eOutUnit );
}
// -----------------------------------------------------------------------
void MetricFormatter::SetBaseValue( sal_Int64 nNewBase, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
mnBaseValue = MetricField::ConvertValue( nNewBase, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit );
}
// -----------------------------------------------------------------------
sal_Int64 MetricFormatter::GetBaseValue( FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf gewuenschte Einheiten
return MetricField::ConvertValue( mnBaseValue, mnBaseValue, GetDecimalDigits(),
meUnit, eOutUnit );
}
// -----------------------------------------------------------------------
void MetricFormatter::Reformat()
{
if ( !GetField() )
return;
XubString aText = GetField()->GetText();
if ( meUnit == FUNIT_CUSTOM )
maCurUnitText = ImplMetricGetUnitText( aText );
XubString aStr;
// caution: precision loss in double cast
double nTemp = (double)mnLastValue;
2000-09-18 16:07:07 +00:00
BOOL bOK = ImplMetricReformat( aText, nTemp, aStr );
mnLastValue = (sal_Int64)nTemp;
2000-09-18 16:07:07 +00:00
if ( !bOK )
return;
if ( aStr.Len() )
{
ImplSetText( aStr );
if ( meUnit == FUNIT_CUSTOM )
CustomConvert();
}
else
SetValue( mnLastValue );
maCurUnitText.Erase();
}
// -----------------------------------------------------------------------
sal_Int64 MetricFormatter::GetCorrectedValue( FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf gewuenschte Einheiten
return MetricField::ConvertValue( mnCorrectedValue, mnBaseValue, GetDecimalDigits(),
meUnit, eOutUnit );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
MetricField::MetricField( Window* pParent, WinBits nWinStyle ) :
SpinField( pParent, nWinStyle )
{
SetField( this );
Reformat();
}
// -----------------------------------------------------------------------
MetricField::MetricField( Window* pParent, const ResId& rResId ) :
SpinField( WINDOW_METRICFIELD )
{
rResId.SetRT( RSC_METRICFIELD );
WinBits nStyle = ImplInitRes( rResId ) ;
SpinField::ImplInit( pParent, nStyle );
SetField( this );
ImplLoadRes( rResId );
if ( !(nStyle & WB_HIDE ) )
Show();
}
// -----------------------------------------------------------------------
void MetricField::ImplLoadRes( const ResId& rResId )
{
SpinField::ImplLoadRes( rResId );
MetricFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) );
2000-09-18 16:07:07 +00:00
ULONG nMask = ReadLongRes();
2000-09-18 16:07:07 +00:00
if ( METRICFIELD_FIRST & nMask )
mnFirst = ReadLongRes();
if ( METRICFIELD_LAST & nMask )
mnLast = ReadLongRes();
if ( METRICFIELD_SPINSIZE & nMask )
mnSpinSize = ReadLongRes();
Reformat();
}
// -----------------------------------------------------------------------
MetricField::~MetricField()
{
}
// -----------------------------------------------------------------------
void MetricField::SetFirst( sal_Int64 nNewFirst, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
// convert
2000-09-18 16:07:07 +00:00
nNewFirst = MetricField::ConvertValue( nNewFirst, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit );
mnFirst = nNewFirst;
}
// -----------------------------------------------------------------------
sal_Int64 MetricField::GetFirst( FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
// convert
2000-09-18 16:07:07 +00:00
return MetricField::ConvertValue( mnFirst, mnBaseValue, GetDecimalDigits(),
meUnit, eOutUnit );
}
// -----------------------------------------------------------------------
void MetricField::SetLast( sal_Int64 nNewLast, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
// Umrechnen
nNewLast = MetricField::ConvertValue( nNewLast, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit );
mnLast = nNewLast;
}
// -----------------------------------------------------------------------
sal_Int64 MetricField::GetLast( FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
// Umrechnen
return MetricField::ConvertValue( mnLast, mnBaseValue, GetDecimalDigits(),
meUnit, eOutUnit );
}
// -----------------------------------------------------------------------
long MetricField::PreNotify( NotifyEvent& rNEvt )
{
if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
if ( ImplMetricProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
return 1;
}
return SpinField::PreNotify( rNEvt );
}
// -----------------------------------------------------------------------
long MetricField::Notify( NotifyEvent& rNEvt )
{
if ( rNEvt.GetType() == EVENT_GETFOCUS )
MarkToBeReformatted( FALSE );
else if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
{
if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) )
Reformat();
}
return SpinField::Notify( rNEvt );
}
// -----------------------------------------------------------------------
void MetricField::DataChanged( const DataChangedEvent& rDCEvt )
{
SpinField::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) )
{
String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
if ( IsDefaultLocale() )
2001-07-20 12:19:24 +00:00
ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() );
String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this );
2000-09-18 16:07:07 +00:00
ReformatAll();
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void MetricField::Modify()
{
MarkToBeReformatted( TRUE );
SpinField::Modify();
}
// -----------------------------------------------------------------------
void MetricField::Up()
{
FieldUp();
SpinField::Up();
}
// -----------------------------------------------------------------------
void MetricField::Down()
{
FieldDown();
SpinField::Down();
}
// -----------------------------------------------------------------------
void MetricField::First()
{
FieldFirst();
SpinField::First();
}
// -----------------------------------------------------------------------
void MetricField::Last()
{
FieldLast();
SpinField::Last();
}
// -----------------------------------------------------------------------
void MetricField::CustomConvert()
{
maCustomConvertLink.Call( this );
}
// -----------------------------------------------------------------------
MetricBox::MetricBox( Window* pParent, WinBits nWinStyle ) :
ComboBox( pParent, nWinStyle )
{
SetField( this );
Reformat();
}
// -----------------------------------------------------------------------
MetricBox::MetricBox( Window* pParent, const ResId& rResId ) :
ComboBox( WINDOW_METRICBOX )
{
rResId.SetRT( RSC_METRICBOX );
WinBits nStyle = ImplInitRes( rResId );
ComboBox::ImplInit( pParent, nStyle );
SetField( this );
Reformat();
ComboBox::ImplLoadRes( rResId );
MetricFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) );
2000-09-18 16:07:07 +00:00
if ( !(nStyle & WB_HIDE ) )
Show();
}
// -----------------------------------------------------------------------
MetricBox::~MetricBox()
{
}
// -----------------------------------------------------------------------
long MetricBox::PreNotify( NotifyEvent& rNEvt )
{
if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
if ( ImplMetricProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
return 1;
}
return ComboBox::PreNotify( rNEvt );
}
// -----------------------------------------------------------------------
long MetricBox::Notify( NotifyEvent& rNEvt )
{
if ( rNEvt.GetType() == EVENT_GETFOCUS )
MarkToBeReformatted( FALSE );
else if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
{
if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) )
Reformat();
}
return ComboBox::Notify( rNEvt );
}
// -----------------------------------------------------------------------
void MetricBox::DataChanged( const DataChangedEvent& rDCEvt )
{
ComboBox::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) )
{
String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
if ( IsDefaultLocale() )
2001-07-20 12:19:24 +00:00
ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() );
String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this );
2000-09-18 16:07:07 +00:00
ReformatAll();
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void MetricBox::Modify()
{
MarkToBeReformatted( TRUE );
ComboBox::Modify();
}
// -----------------------------------------------------------------------
void MetricBox::ReformatAll()
{
double nValue;
XubString aStr;
SetUpdateMode( FALSE );
USHORT nEntryCount = GetEntryCount();
for ( USHORT i=0; i < nEntryCount; i++ )
{
ImplMetricReformat( GetEntry( i ), nValue, aStr );
RemoveEntry( i );
InsertEntry( aStr, i );
}
MetricFormatter::Reformat();
SetUpdateMode( TRUE );
}
// -----------------------------------------------------------------------
void MetricBox::CustomConvert()
{
maCustomConvertLink.Call( this );
}
// -----------------------------------------------------------------------
void MetricBox::InsertValue( sal_Int64 nValue, FieldUnit eInUnit, USHORT nPos )
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf eingestellte Einheiten
nValue = MetricField::ConvertValue( nValue, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit );
ComboBox::InsertEntry( CreateFieldText( nValue ), nPos );
}
// -----------------------------------------------------------------------
void MetricBox::RemoveValue( sal_Int64 nValue, FieldUnit eInUnit )
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf eingestellte Einheiten
nValue = MetricField::ConvertValue( nValue, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit );
ComboBox::RemoveEntry( CreateFieldText( nValue ) );
}
// -----------------------------------------------------------------------
sal_Int64 MetricBox::GetValue( USHORT nPos, FieldUnit eOutUnit ) const
2000-09-18 16:07:07 +00:00
{
double nValue = 0;
ImplMetricGetValue( ComboBox::GetEntry( nPos ), nValue, mnBaseValue,
2001-07-20 12:19:24 +00:00
GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit );
2000-09-18 16:07:07 +00:00
// Umrechnen auf eingestellte Einheiten
sal_Int64 nRetValue = MetricField::ConvertValue( (sal_Int64)nValue, mnBaseValue, GetDecimalDigits(),
meUnit, eOutUnit );
2000-09-18 16:07:07 +00:00
return nRetValue;
}
// -----------------------------------------------------------------------
USHORT MetricBox::GetValuePos( sal_Int64 nValue, FieldUnit eInUnit ) const
2000-09-18 16:07:07 +00:00
{
// Umrechnen auf eingestellte Einheiten
nValue = MetricField::ConvertValue( nValue, mnBaseValue, GetDecimalDigits(),
eInUnit, meUnit );
return ComboBox::GetEntryPos( CreateFieldText( nValue ) );
}
// -----------------------------------------------------------------------
sal_Int64 MetricBox::GetValue( FieldUnit eOutUnit ) const
{
// Implementation not inline, because it is a virtual Function
return MetricFormatter::GetValue( eOutUnit );
}
// -----------------------------------------------------------------------
sal_Int64 MetricBox::GetValue() const
{
// Implementation not inline, because it is a virtual Function
return GetValue( FUNIT_NONE );
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
static BOOL ImplCurrencyProcessKeyInput( Edit* pEdit, const KeyEvent& rKEvt,
BOOL, BOOL bUseThousandSep, const LocaleDataWrapper& rWrapper )
2000-09-18 16:07:07 +00:00
{
// Es gibt hier kein sinnvolles StrictFormat, also alle
// Zeichen erlauben
return ImplNumericProcessKeyInput( pEdit, rKEvt, FALSE, bUseThousandSep, rWrapper );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
inline BOOL ImplCurrencyGetValue( const XubString& rStr, double& rValue,
USHORT nDecDigits, const LocaleDataWrapper& rWrapper )
2000-09-18 16:07:07 +00:00
{
// Zahlenwert holen
return ImplNumericGetValue( rStr, rValue, nDecDigits, rWrapper, TRUE );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
BOOL CurrencyFormatter::ImplCurrencyReformat( const XubString& rStr,
XubString& rOutStr )
{
double nValue;
2001-07-20 12:19:24 +00:00
if ( !ImplNumericGetValue( rStr, nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), TRUE ) )
2000-09-18 16:07:07 +00:00
return TRUE;
else
{
double nTempVal = nValue;
// caution: precision loss in double cast
2000-09-18 16:07:07 +00:00
if ( nTempVal > GetMax() )
nTempVal = (double)GetMax();
2000-09-18 16:07:07 +00:00
else if ( nTempVal < GetMin())
nTempVal = (double)GetMin();
2000-09-18 16:07:07 +00:00
if ( GetErrorHdl().IsSet() && (nValue != nTempVal) )
{
mnCorrectedValue = (sal_Int64)nTempVal;
2000-09-18 16:07:07 +00:00
if ( !GetErrorHdl().Call( this ) )
{
mnCorrectedValue = 0;
return FALSE;
}
else
mnCorrectedValue = 0;
}
rOutStr = CreateFieldText( (long)nTempVal );
2000-09-18 16:07:07 +00:00
return TRUE;
}
}
// -----------------------------------------------------------------------
inline void CurrencyFormatter::ImplInit()
{
mnType = FORMAT_CURRENCY;
}
// -----------------------------------------------------------------------
CurrencyFormatter::CurrencyFormatter()
{
ImplInit();
}
// -----------------------------------------------------------------------
CurrencyFormatter::~CurrencyFormatter()
{
}
// -----------------------------------------------------------------------
void CurrencyFormatter::SetCurrencySymbol( const String& rStr )
{
maCurrencySymbol= rStr;
ReformatAll();
}
// -----------------------------------------------------------------------
String CurrencyFormatter::GetCurrencySymbol() const
{
2001-07-20 12:19:24 +00:00
return maCurrencySymbol.Len() ? maCurrencySymbol : ImplGetLocaleDataWrapper().getCurrSymbol();
}
// -----------------------------------------------------------------------
void CurrencyFormatter::SetValue( sal_Int64 nNewValue )
2000-09-18 16:07:07 +00:00
{
SetUserValue( nNewValue );
mnFieldValue = mnLastValue;
SetEmptyFieldValueData( FALSE );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
XubString CurrencyFormatter::CreateFieldText( sal_Int64 nValue ) const
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
return ImplGetLocaleDataWrapper().getCurr( nValue, GetDecimalDigits(), GetCurrencySymbol(), IsUseThousandSep() );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
sal_Int64 CurrencyFormatter::GetValue() const
2000-09-18 16:07:07 +00:00
{
if ( !GetField() )
return 0;
double nTempValue;
2001-07-20 12:19:24 +00:00
if ( ImplCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
{
// caution: precision loss in double cast
2000-09-18 16:07:07 +00:00
if ( nTempValue > mnMax )
nTempValue = (double)mnMax;
2000-09-18 16:07:07 +00:00
else if ( nTempValue < mnMin )
nTempValue = (double)mnMin;
return (sal_Int64)nTempValue;
2000-09-18 16:07:07 +00:00
}
else
return mnLastValue;
}
// -----------------------------------------------------------------------
void CurrencyFormatter::Reformat()
{
if ( !GetField() )
return;
XubString aStr;
BOOL bOK = ImplCurrencyReformat( GetField()->GetText(), aStr );
if ( !bOK )
return;
if ( aStr.Len() )
{
ImplSetText( aStr );
// caution: precision loss in double cast
double nTemp = (double)mnLastValue;
2001-07-20 12:19:24 +00:00
ImplCurrencyGetValue( aStr, nTemp, GetDecimalDigits(), ImplGetLocaleDataWrapper() );
mnLastValue = (sal_Int64)nTemp;
2000-09-18 16:07:07 +00:00
}
else
SetValue( mnLastValue );
}
// -----------------------------------------------------------------------
CurrencyField::CurrencyField( Window* pParent, WinBits nWinStyle ) :
SpinField( pParent, nWinStyle )
{
SetField( this );
Reformat();
}
// -----------------------------------------------------------------------
CurrencyField::CurrencyField( Window* pParent, const ResId& rResId ) :
SpinField( WINDOW_CURRENCYFIELD )
{
rResId.SetRT( RSC_CURRENCYFIELD );
WinBits nStyle = ImplInitRes( rResId );
SpinField::ImplInit( pParent, nStyle);
SetField( this );
ImplLoadRes( rResId );
if ( !(nStyle & WB_HIDE ) )
Show();
}
// -----------------------------------------------------------------------
void CurrencyField::ImplLoadRes( const ResId& rResId )
{
SpinField::ImplLoadRes( rResId );
CurrencyFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) );
2000-09-18 16:07:07 +00:00
ULONG nMask = ReadLongRes();
2000-09-18 16:07:07 +00:00
if ( CURRENCYFIELD_FIRST & nMask )
mnFirst = ReadLongRes();
if ( CURRENCYFIELD_LAST & nMask )
mnLast = ReadLongRes();
if ( CURRENCYFIELD_SPINSIZE & nMask )
mnSpinSize = ReadLongRes();
Reformat();
}
// -----------------------------------------------------------------------
CurrencyField::~CurrencyField()
{
}
// -----------------------------------------------------------------------
long CurrencyField::PreNotify( NotifyEvent& rNEvt )
{
if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
if ( ImplCurrencyProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
return 1;
}
return SpinField::PreNotify( rNEvt );
}
// -----------------------------------------------------------------------
long CurrencyField::Notify( NotifyEvent& rNEvt )
{
if ( rNEvt.GetType() == EVENT_GETFOCUS )
MarkToBeReformatted( FALSE );
else if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
{
if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) )
Reformat();
}
return SpinField::Notify( rNEvt );
}
// -----------------------------------------------------------------------
void CurrencyField::DataChanged( const DataChangedEvent& rDCEvt )
{
SpinField::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) )
{
String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
if ( IsDefaultLocale() )
2001-07-20 12:19:24 +00:00
ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() );
String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this );
2000-09-18 16:07:07 +00:00
ReformatAll();
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void CurrencyField::Modify()
{
MarkToBeReformatted( TRUE );
SpinField::Modify();
}
// -----------------------------------------------------------------------
void CurrencyField::Up()
{
FieldUp();
SpinField::Up();
}
// -----------------------------------------------------------------------
void CurrencyField::Down()
{
FieldDown();
SpinField::Down();
}
// -----------------------------------------------------------------------
void CurrencyField::First()
{
FieldFirst();
SpinField::First();
}
// -----------------------------------------------------------------------
void CurrencyField::Last()
{
FieldLast();
SpinField::Last();
}
// -----------------------------------------------------------------------
CurrencyBox::CurrencyBox( Window* pParent, WinBits nWinStyle ) :
ComboBox( pParent, nWinStyle )
{
SetField( this );
Reformat();
}
// -----------------------------------------------------------------------
CurrencyBox::CurrencyBox( Window* pParent, const ResId& rResId ) :
ComboBox( WINDOW_CURRENCYBOX )
{
rResId.SetRT( RSC_CURRENCYBOX );
WinBits nStyle = ImplInitRes( rResId );
ComboBox::ImplInit( pParent, nStyle );
CurrencyFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) );
2000-09-18 16:07:07 +00:00
SetField( this );
ComboBox::ImplLoadRes( rResId );
Reformat();
if ( !(nStyle & WB_HIDE ) )
Show();
}
// -----------------------------------------------------------------------
CurrencyBox::~CurrencyBox()
{
}
// -----------------------------------------------------------------------
long CurrencyBox::PreNotify( NotifyEvent& rNEvt )
{
if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
2000-09-18 16:07:07 +00:00
{
2001-07-20 12:19:24 +00:00
if ( ImplCurrencyProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
2000-09-18 16:07:07 +00:00
return 1;
}
return ComboBox::PreNotify( rNEvt );
}
// -----------------------------------------------------------------------
long CurrencyBox::Notify( NotifyEvent& rNEvt )
{
if ( rNEvt.GetType() == EVENT_GETFOCUS )
MarkToBeReformatted( FALSE );
else if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
{
if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) )
Reformat();
}
return ComboBox::Notify( rNEvt );
}
// -----------------------------------------------------------------------
void CurrencyBox::DataChanged( const DataChangedEvent& rDCEvt )
{
ComboBox::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) )
{
String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
if ( IsDefaultLocale() )
2001-07-20 12:19:24 +00:00
ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() );
String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this );
2000-09-18 16:07:07 +00:00
ReformatAll();
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void CurrencyBox::Modify()
{
MarkToBeReformatted( TRUE );
ComboBox::Modify();
}
// -----------------------------------------------------------------------
void CurrencyBox::ReformatAll()
{
XubString aStr;
SetUpdateMode( FALSE );
USHORT nEntryCount = GetEntryCount();
for ( USHORT i=0; i < nEntryCount; i++ )
{
ImplCurrencyReformat( GetEntry( i ), aStr );
RemoveEntry( i );
InsertEntry( aStr, i );
}
CurrencyFormatter::Reformat();
SetUpdateMode( TRUE );
}
// -----------------------------------------------------------------------
void CurrencyBox::InsertValue( sal_Int64 nValue, USHORT nPos )
2000-09-18 16:07:07 +00:00
{
ComboBox::InsertEntry( CreateFieldText( nValue ), nPos );
}
// -----------------------------------------------------------------------
void CurrencyBox::RemoveValue( sal_Int64 nValue )
2000-09-18 16:07:07 +00:00
{
ComboBox::RemoveEntry( CreateFieldText( nValue ) );
}
// -----------------------------------------------------------------------
sal_Int64 CurrencyBox::GetValue( USHORT nPos ) const
2000-09-18 16:07:07 +00:00
{
double nValue = 0;
2001-07-20 12:19:24 +00:00
ImplCurrencyGetValue( ComboBox::GetEntry( nPos ), nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() );
return (sal_Int64)nValue;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
USHORT CurrencyBox::GetValuePos( sal_Int64 nValue ) const
2000-09-18 16:07:07 +00:00
{
return ComboBox::GetEntryPos( CreateFieldText( nValue ) );
}
// -----------------------------------------------------------------------
sal_Int64 CurrencyBox::GetValue() const
{
// Implementation not inline, because it is a virtual Function
return CurrencyFormatter::GetValue();
}