Files
libreoffice/sw/source/core/fields/fldbas.cxx

780 lines
22 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 23:08:29 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 23:08:29 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:08:29 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 23:08:29 +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 23:08:29 +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 23:08:29 +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 23:08:29 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
2000-09-18 23:08:29 +00:00
#include <float.h>
#include <rtl/math.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
#include <editeng/unolingu.hxx>
#include <unofldmid.h>
2000-09-18 23:08:29 +00:00
#include <doc.hxx>
#include <editsh.hxx>
#include <frame.hxx>
#include <fldbas.hxx>
#include <flddat.hxx>
#include <ndtxt.hxx>
#include <fmtfld.hxx>
#include <txtfld.hxx>
#include <pam.hxx>
#include <docfld.hxx>
#include <swtable.hxx>
#include <docufld.hxx>
#include <expfld.hxx>
#include <shellres.hxx>
#include <calc.hxx>
#include <comcore.hrc>
#include <math.h>
#ifdef MAC
#include <stdlib.h>
#endif
2000-09-18 23:08:29 +00:00
using namespace ::com::sun::star;
using namespace nsSwDocInfoSubType;
2000-09-18 23:08:29 +00:00
USHORT lcl_GetLanguageOfFormat( USHORT nLng, ULONG nFmt,
const SvNumberFormatter& rFormatter )
{
if( nLng == LANGUAGE_NONE ) // wegen Bug #60010
nLng = LANGUAGE_SYSTEM;
else if( nLng == ::GetAppLanguage() )
2000-09-18 23:08:29 +00:00
switch( rFormatter.GetIndexTableOffset( nFmt ))
{
case NF_NUMBER_SYSTEM:
case NF_DATE_SYSTEM_SHORT:
case NF_DATE_SYSTEM_LONG:
case NF_DATETIME_SYSTEM_SHORT_HHMM:
nLng = LANGUAGE_SYSTEM;
break;
default: break;
2000-09-18 23:08:29 +00:00
}
return nLng;
}
/*--------------------------------------------------------------------
Beschreibung: Globals
--------------------------------------------------------------------*/
// Array der Feldname
SvStringsDtor* SwFieldType::pFldNames = 0;
DBG_NAME(SwFieldType)
2000-09-18 23:08:29 +00:00
2010-12-06 10:36:22 +00:00
USHORT aTypeTab[] = {
2000-09-18 23:08:29 +00:00
/* RES_DBFLD */ TYP_DBFLD,
/* RES_USERFLD */ TYP_USERFLD,
/* RES_FILENAMEFLD */ TYP_FILENAMEFLD,
/* RES_DBNAMEFLD */ TYP_DBNAMEFLD,
/* RES_DATEFLD */ TYP_DATEFLD,
/* RES_TIMEFLD */ TYP_TIMEFLD,
/* RES_PAGENUMBERFLD */ TYP_PAGENUMBERFLD, // dynamisch
/* RES_AUTHORFLD */ TYP_AUTHORFLD,
/* RES_CHAPTERFLD */ TYP_CHAPTERFLD,
/* RES_DOCSTATFLD */ TYP_DOCSTATFLD,
/* RES_GETEXPFLD */ TYP_GETFLD, // dynamisch
/* RES_SETEXPFLD */ TYP_SETFLD, // dynamisch
/* RES_GETREFFLD */ TYP_GETREFFLD,
/* RES_HIDDENTXTFLD */ TYP_HIDDENTXTFLD,
/* RES_POSTITFLD */ TYP_POSTITFLD,
/* RES_FIXDATEFLD */ TYP_FIXDATEFLD,
/* RES_FIXTIMEFLD */ TYP_FIXTIMEFLD,
/* RES_REGFLD */ 0, // alt
/* RES_VARREGFLD */ 0, // alt
/* RES_SETREFFLD */ TYP_SETREFFLD,
/* RES_INPUTFLD */ TYP_INPUTFLD,
/* RES_MACROFLD */ TYP_MACROFLD,
/* RES_DDEFLD */ TYP_DDEFLD,
/* RES_TABLEFLD */ TYP_FORMELFLD,
/* RES_HIDDENPARAFLD */ TYP_HIDDENPARAFLD,
/* RES_DOCINFOFLD */ TYP_DOCINFOFLD,
/* RES_TEMPLNAMEFLD */ TYP_TEMPLNAMEFLD,
/* RES_DBNEXTSETFLD */ TYP_DBNEXTSETFLD,
/* RES_DBNUMSETFLD */ TYP_DBNUMSETFLD,
/* RES_DBSETNUMBERFLD */ TYP_DBSETNUMBERFLD,
/* RES_EXTUSERFLD */ TYP_EXTUSERFLD,
/* RES_REFPAGESETFLD */ TYP_SETREFPAGEFLD,
/* RES_REFPAGEGETFLD */ TYP_GETREFPAGEFLD,
/* RES_INTERNETFLD */ TYP_INTERNETFLD,
/* RES_JUMPEDITFLD */ TYP_JUMPEDITFLD,
/* RES_SCRIPTFLD */ TYP_SCRIPTFLD,
/* RES_DATETIMEFLD */ 0, // dynamisch
2001-01-18 13:08:36 +00:00
/* RES_AUTHORITY */ TYP_AUTHORITY,
/* RES_COMBINED_CHARS */ TYP_COMBINED_CHARS,
/* RES_DROPDOWN */ TYP_DROPDOWN
2000-09-18 23:08:29 +00:00
};
// ????? TYP_USRINPFLD,
const String& SwFieldType::GetTypeStr(USHORT nTypeId)
{
if( !pFldNames )
_GetFldName();
if( nTypeId < SwFieldType::pFldNames->Count() )
return *SwFieldType::pFldNames->GetObject( nTypeId );
else
return aEmptyStr;
}
2000-09-18 23:08:29 +00:00
/*---------------------------------------------------
Jedes Feld referenziert einen Feldtypen, der fuer
jedes Dokument einmalig ist.
--------------------------------------------------*/
SwFieldType::SwFieldType( USHORT nWhichId )
: SwModify(0),
nWhich( nWhichId )
{
DBG_CTOR( SwFieldType, 0 );
}
#if OSL_DEBUG_LEVEL > 1
2000-09-18 23:08:29 +00:00
SwFieldType::~SwFieldType()
{
DBG_DTOR( SwFieldType, 0 );
}
#endif
const String& SwFieldType::GetName() const
{
return aEmptyStr;
}
2010-10-04 15:23:52 +01:00
bool SwFieldType::QueryValue( uno::Any&, USHORT ) const
2000-09-18 23:08:29 +00:00
{
2010-10-04 15:23:52 +01:00
return false;
2000-09-18 23:08:29 +00:00
}
2010-10-04 15:23:52 +01:00
bool SwFieldType::PutValue( const uno::Any& , USHORT )
2000-09-18 23:08:29 +00:00
{
2010-10-04 15:23:52 +01:00
return false;
2000-09-18 23:08:29 +00:00
}
/*--------------------------------------------------------------------
Beschreibung: Basisklasse aller Felder
Felder referenzieren einen Feldtyp
Felder sind n-mal vorhanden, Feldtypen nur einmal
--------------------------------------------------------------------*/
SwField::SwField(SwFieldType* pTyp, sal_uInt32 nFmt, USHORT nLng) :
nLang(nLng),
bIsAutomaticLanguage(TRUE),
nFormat(nFmt)
2000-09-18 23:08:29 +00:00
{
OSL_ENSURE( pTyp, "SwField: ungueltiger SwFieldType" );
2000-09-18 23:08:29 +00:00
pType = pTyp;
}
SwField::~SwField()
{
}
/*--------------------------------------------------------------------
Beschreibung: Statt Umweg ueber den Typ
--------------------------------------------------------------------*/
#if OSL_DEBUG_LEVEL > 1
2000-09-18 23:08:29 +00:00
USHORT SwField::Which() const
{
OSL_ENSURE(pType, "Kein Typ vorhanden");
2000-09-18 23:08:29 +00:00
return pType->Which();
}
#endif
USHORT SwField::GetTypeId() const
{
USHORT nRet;
switch( pType->Which() )
{
case RES_DATETIMEFLD:
if (GetSubType() & FIXEDFLD)
nRet = static_cast<USHORT>(GetSubType() & DATEFLD ? TYP_FIXDATEFLD : TYP_FIXTIMEFLD);
2000-09-18 23:08:29 +00:00
else
nRet = static_cast<USHORT>(GetSubType() & DATEFLD ? TYP_DATEFLD : TYP_TIMEFLD);
2000-09-18 23:08:29 +00:00
break;
case RES_GETEXPFLD:
nRet = static_cast<USHORT>(nsSwGetSetExpType::GSE_FORMULA & GetSubType() ? TYP_FORMELFLD : TYP_GETFLD);
2000-09-18 23:08:29 +00:00
break;
case RES_HIDDENTXTFLD:
nRet = GetSubType();
break;
case RES_SETEXPFLD:
if( nsSwGetSetExpType::GSE_SEQ & GetSubType() )
2000-09-18 23:08:29 +00:00
nRet = TYP_SEQFLD;
else if( ((SwSetExpField*)this)->GetInputFlag() )
nRet = TYP_SETINPFLD;
else
nRet = TYP_SETFLD;
break;
case RES_PAGENUMBERFLD:
nRet = GetSubType();
if( PG_NEXT == nRet )
nRet = TYP_NEXTPAGEFLD;
else if( PG_PREV == nRet )
nRet = TYP_PREVPAGEFLD;
else
nRet = TYP_PAGENUMBERFLD;
break;
default:
nRet = aTypeTab[ pType->Which() ];
}
return nRet;
}
/*--------------------------------------------------------------------
Beschreibung: liefert den Namen oder den Inhalt
--------------------------------------------------------------------*/
String SwField::GetCntnt( BOOL bName ) const
{
String sRet;
if( bName )
{
USHORT nTypeId = GetTypeId();
if( RES_DATETIMEFLD == GetTyp()->Which() )
nTypeId = static_cast<USHORT>(GetSubType() & DATEFLD ? TYP_DATEFLD : TYP_TIMEFLD);
2000-09-18 23:08:29 +00:00
sRet = SwFieldType::GetTypeStr( nTypeId );
if( IsFixed() )
( sRet += ' ' ) += ViewShell::GetShellRes()->aFixedStr;
}
else
sRet = Expand();
return sRet;
}
/*--------------------------------------------------------------------
Beschreibung: Parameter setzen auslesen
--------------------------------------------------------------------*/
const String& SwField::GetPar1() const
{
return aEmptyStr;
}
String SwField::GetPar2() const
{
return aEmptyStr;
}
String SwField::GetFormula() const
{
return GetPar2();
}
void SwField::SetPar1(const String& )
2000-09-18 23:08:29 +00:00
{}
void SwField::SetPar2(const String& )
2000-09-18 23:08:29 +00:00
{}
USHORT SwField::GetSubType() const
{
return 0;
}
void SwField::SetSubType(USHORT )
2000-09-18 23:08:29 +00:00
{
}
2010-10-04 15:23:52 +01:00
bool SwField::QueryValue( uno::Any& rVal, USHORT nWhichId ) const
2000-09-18 23:08:29 +00:00
{
switch( nWhichId )
{
case FIELD_PROP_BOOL4:
{
BOOL bFixed = !bIsAutomaticLanguage;
rVal.setValue(&bFixed, ::getCppuBooleanType());
}
break;
default:
DBG_ERROR("illegal property");
}
2010-10-04 15:23:52 +01:00
return true;
2000-09-18 23:08:29 +00:00
}
2010-10-04 15:23:52 +01:00
bool SwField::PutValue( const uno::Any& rVal, USHORT nWhichId )
2000-09-18 23:08:29 +00:00
{
switch( nWhichId )
{
case FIELD_PROP_BOOL4:
{
BOOL bFixed = FALSE;
if(rVal >>= bFixed)
bIsAutomaticLanguage = !bFixed;
2002-11-15 10:43:50 +00:00
}
break;
default:
DBG_ERROR("illegal property");
}
2010-10-04 15:23:52 +01:00
return true;
2000-09-18 23:08:29 +00:00
}
/*--------------------------------------------------------------------
Beschreibung: neuen Typ setzen
(wird fuer das Kopieren zwischen Dokumenten benutzt)
muss immer vom gleichen Typ sein.
--------------------------------------------------------------------*/
SwFieldType* SwField::ChgTyp( SwFieldType* pNewType )
{
OSL_ENSURE( pNewType && pNewType->Which() == pType->Which(),
2000-09-18 23:08:29 +00:00
"kein Typ oder ungleiche Typen" );
SwFieldType* pOld = pType;
pType = pNewType;
return pOld;
}
// hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..)
BOOL SwField::HasClickHdl() const
2000-09-18 23:08:29 +00:00
{
BOOL bRet = FALSE;
2000-09-18 23:08:29 +00:00
switch( pType->Which() )
{
case RES_INTERNETFLD:
case RES_JUMPEDITFLD:
case RES_GETREFFLD:
case RES_MACROFLD:
case RES_INPUTFLD:
case RES_DROPDOWN :
2000-09-18 23:08:29 +00:00
bRet = TRUE;
break;
case RES_SETEXPFLD:
bRet = ((SwSetExpField*)this)->GetInputFlag();
break;
}
return bRet;
}
void SwField::SetLanguage(USHORT nLng)
{
nLang = nLng;
}
void SwField::ChangeFormat(sal_uInt32 n)
2000-09-18 23:08:29 +00:00
{
nFormat = n;
}
BOOL SwField::IsFixed() const
2000-09-18 23:08:29 +00:00
{
BOOL bRet = FALSE;
2000-09-18 23:08:29 +00:00
switch( pType->Which() )
{
case RES_FIXDATEFLD:
case RES_FIXTIMEFLD:
bRet = TRUE;
break;
case RES_DATETIMEFLD:
bRet = 0 != (GetSubType() & FIXEDFLD);
break;
case RES_EXTUSERFLD:
case RES_AUTHORFLD:
bRet = 0 != (GetFormat() & AF_FIXED);
break;
case RES_FILENAMEFLD:
bRet = 0 != (GetFormat() & FF_FIXED);
break;
case RES_DOCINFOFLD:
bRet = 0 != (GetSubType() & DI_SUB_FIXED);
break;
}
return bRet;
}
String SwField::ExpandField(bool const bInClipboard) const
{
if (!bInClipboard) // #i85766# do not expand fields in clipboard documents
{
m_Cache = Expand();
}
return m_Cache;
}
SwField * SwField::CopyField() const
{
SwField *const pNew = Copy();
// #i85766# cache expansion of source (for clipboard)
pNew->m_Cache = Expand();
return pNew;
}
2000-09-18 23:08:29 +00:00
/*--------------------------------------------------------------------
Beschreibung: Numerierung expandieren
--------------------------------------------------------------------*/
String FormatNumber(USHORT nNum, sal_uInt32 nFormat)
2000-09-18 23:08:29 +00:00
{
2001-04-26 06:03:27 +00:00
if(SVX_NUM_PAGEDESC == nFormat)
return String::CreateFromInt32( nNum );
SvxNumberType aNumber;
2000-09-18 23:08:29 +00:00
OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "Falsches Nummern-Format" );
2000-09-18 23:08:29 +00:00
aNumber.SetNumberingType((sal_Int16)nFormat);
2000-09-18 23:08:29 +00:00
return aNumber.GetNumStr(nNum);
}
/*--------------------------------------------------------------------
Beschreibung: CTOR SwValueFieldType
--------------------------------------------------------------------*/
SwValueFieldType::SwValueFieldType( SwDoc* pDocPtr, USHORT nWhichId )
: SwFieldType(nWhichId),
pDoc(pDocPtr),
bUseFormat(TRUE)
{
}
SwValueFieldType::SwValueFieldType( const SwValueFieldType& rTyp )
: SwFieldType(rTyp.Which()),
pDoc(rTyp.GetDoc()),
bUseFormat(rTyp.UseFormat())
{
}
/*--------------------------------------------------------------------
Beschreibung: Wert formatiert als String zurueckgeben
--------------------------------------------------------------------*/
String SwValueFieldType::ExpandValue( const double& rVal,
sal_uInt32 nFmt, USHORT nLng) const
2000-09-18 23:08:29 +00:00
{
if (rVal >= DBL_MAX) // FehlerString fuer Calculator
return ViewShell::GetShellRes()->aCalc_Error;
String sExpand;
SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
Color* pCol = 0;
// wegen Bug #60010
USHORT nFmtLng = ::lcl_GetLanguageOfFormat( nLng, nFmt, *pFormatter );
if( nFmt < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFmtLng )
{
short nType = NUMBERFORMAT_DEFINED;
xub_StrLen nDummy;
const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
if (pEntry && nLng != pEntry->GetLanguage())
{
sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFmt,
2000-09-18 23:08:29 +00:00
(LanguageType)nFmtLng);
if (nNewFormat == nFmt)
{
// Warscheinlich benutzerdefiniertes Format
String sFmt(pEntry->GetFormatstring());
pFormatter->PutandConvertEntry(sFmt, nDummy, nType, nFmt,
pEntry->GetLanguage(), nFmtLng );
}
else
nFmt = nNewFormat;
}
OSL_ENSURE(pEntry, "Unbekanntes Zahlenformat!");
2000-09-18 23:08:29 +00:00
}
if( pFormatter->IsTextFormat( nFmt ) )
{
String sValue;
DoubleToString(sValue, rVal, nFmtLng);
pFormatter->GetOutputString(sValue, nFmt, sExpand, &pCol);
}
else
pFormatter->GetOutputString(rVal, nFmt, sExpand, &pCol);
return sExpand;
}
void SwValueFieldType::DoubleToString( String &rValue, const double &rVal,
sal_uInt32 nFmt) const
2000-09-18 23:08:29 +00:00
{
SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
if (pEntry)
DoubleToString(rValue, rVal, pEntry->GetLanguage());
}
void SwValueFieldType::DoubleToString( String &rValue, const double &rVal,
USHORT nLng ) const
{
SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
// wegen Bug #60010
if( nLng == LANGUAGE_NONE ) // wegen Bug #60010
nLng = LANGUAGE_SYSTEM;
pFormatter->ChangeIntl( nLng ); // Separator in der richtigen Sprache besorgen
rValue = ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
pFormatter->GetDecSep(), true );
2000-09-18 23:08:29 +00:00
}
/*--------------------------------------------------------------------
Beschreibung: CTOR SwValueField
--------------------------------------------------------------------*/
SwValueField::SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt,
USHORT nLng, const double fVal )
: SwField(pFldType, nFmt, nLng),
2000-09-18 23:08:29 +00:00
fValue(fVal)
{
}
SwValueField::SwValueField( const SwValueField& rFld )
: SwField(rFld),
fValue(rFld.GetValue())
{
}
2001-02-02 10:47:24 +00:00
SwValueField::~SwValueField()
{
}
2000-09-18 23:08:29 +00:00
/*--------------------------------------------------------------------
Beschreibung: neuen Typ setzen
(wird fuer das Kopieren zwischen Dokumenten benutzt)
muss immer vom gleichen Typ sein.
--------------------------------------------------------------------*/
SwFieldType* SwValueField::ChgTyp( SwFieldType* pNewType )
{
SwDoc* pNewDoc = ((SwValueFieldType *)pNewType)->GetDoc();
SwDoc* pDoc = GetDoc();
if( pNewDoc && pDoc && pDoc != pNewDoc)
{
SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
if( pFormatter && pFormatter->HasMergeFmtTbl() &&
((SwValueFieldType *)GetTyp())->UseFormat() )
SetFormat(pFormatter->GetMergeFmtIndex( GetFormat() ));
}
return SwField::ChgTyp(pNewType);
}
/*--------------------------------------------------------------------
Beschreibung: Format in Office-Sprache ermitteln
--------------------------------------------------------------------*/
sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt)
2000-09-18 23:08:29 +00:00
{
const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
CWS-TOOLING: integrate CWS oj18 2009-08-21 15:08:49 +0200 oj r275263 : wrong check 2009-08-21 08:56:01 +0200 oj r275215 : missing not 2009-08-20 07:27:13 +0200 oj r275164 : use new method from global 2009-08-19 10:22:35 +0200 oj r275138 : call GetLocale instead of pLocale 2009-08-18 10:39:32 +0200 oj r275082 : missing header include 2009-08-18 10:09:44 +0200 oj r275081 : new methods at global 2009-08-18 10:09:00 +0200 oj r275080 : unused var 2009-08-18 08:59:04 +0200 oj r275078 : move files from classes to xml 2009-08-17 14:58:16 +0200 oj r275056 : CWS-TOOLING: rebase CWS oj18 to trunk@275001 (milestone: DEV300:m55) 2009-08-17 13:29:44 +0200 oj r275047 : compile error 2009-08-17 13:27:47 +0200 oj r275045 : compile error 2009-08-17 11:44:54 +0200 oj r275040 : add dep 2009-07-22 14:26:05 +0200 oj r274240 : move unused services into fwl 2009-07-22 14:25:35 +0200 oj r274239 : move unused services into fwl 2009-07-22 13:47:45 +0200 oj r274233 : remove some unused code 2009-07-22 09:06:20 +0200 oj r274219 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 08:48:58 +0200 oj r274218 : create NumberFormatter on demand 2009-07-22 08:39:23 +0200 oj r274217 : change char to sal_Char 2009-07-22 07:33:34 +0200 oj r274214 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 07:30:04 +0200 oj r274213 : late init of numberformatter and breakiterator 2009-07-22 07:28:55 +0200 oj r274212 : export dbtoolsclient dbcharsethelper for sc 2009-07-21 13:43:28 +0200 oj r274196 : check if quick start is enbaled 2009-07-21 13:40:09 +0200 oj r274195 : check config entry for UiEventsLogger 2009-07-21 13:37:40 +0200 oj r274194 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:35:38 +0200 oj r274193 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:33:41 +0200 oj r274192 : doc meta data will now be created on demand 2009-07-21 13:13:40 +0200 oj r274187 : load ldap functions on demand 2009-07-21 13:03:17 +0200 oj r274183 : late init of TransliterationImpl 2009-07-21 12:36:10 +0200 oj r274180 : late init of charClass
2009-09-08 04:57:32 +00:00
USHORT nLng = SvxLocaleToLanguage( SvtSysLocale().GetLocaleData().getLocale() );
2000-09-18 23:08:29 +00:00
if (pEntry && nLng != pEntry->GetLanguage())
{
sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFmt,
2000-09-18 23:08:29 +00:00
(LanguageType)nLng);
if (nNewFormat == nFmt)
{
// Warscheinlich benutzerdefiniertes Format
short nType = NUMBERFORMAT_DEFINED;
xub_StrLen nDummy;
String sFmt(pEntry->GetFormatstring());
sal_uInt32 nFormat = nFmt;
2000-09-18 23:08:29 +00:00
pFormatter->PutandConvertEntry(sFmt, nDummy, nType,
nFormat, pEntry->GetLanguage(), nLng);
nFmt = nFormat;
}
else
nFmt = nNewFormat;
}
return nFmt;
}
/*--------------------------------------------------------------------
Beschreibung: Sprache im Format anpassen
--------------------------------------------------------------------*/
void SwValueField::SetLanguage( USHORT nLng )
{
if( IsAutomaticLanguage() &&
((SwValueFieldType *)GetTyp())->UseFormat() &&
GetFormat() != SAL_MAX_UINT32 )
2000-09-18 23:08:29 +00:00
{
// wegen Bug #60010
SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
USHORT nFmtLng = ::lcl_GetLanguageOfFormat( nLng, GetFormat(),
*pFormatter );
if( (GetFormat() >= SV_COUNTRY_LANGUAGE_OFFSET ||
LANGUAGE_SYSTEM != nFmtLng ) &&
!(Which() == RES_USERFLD && (GetSubType()&nsSwExtendedSubType::SUB_CMD) ) )
2000-09-18 23:08:29 +00:00
{
const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
if( pEntry && nFmtLng != pEntry->GetLanguage() )
{
sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
2000-09-18 23:08:29 +00:00
GetFormat(), (LanguageType)nFmtLng );
if( nNewFormat == GetFormat() )
{
// Warscheinlich benutzerdefiniertes Format
short nType = NUMBERFORMAT_DEFINED;
xub_StrLen nDummy;
String sFmt( pEntry->GetFormatstring() );
pFormatter->PutandConvertEntry( sFmt, nDummy, nType,
nNewFormat,
pEntry->GetLanguage(),
nFmtLng );
}
SetFormat( nNewFormat );
}
OSL_ENSURE(pEntry, "Unbekanntes Zahlenformat!");
2000-09-18 23:08:29 +00:00
}
}
SwField::SetLanguage(nLng);
}
double SwValueField::GetValue() const
{
return fValue;
}
void SwValueField::SetValue( const double& rVal )
{
fValue = rVal;
}
/*--------------------------------------------------------------------
Beschreibung: SwFormulaField
--------------------------------------------------------------------*/
SwFormulaField::SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt, const double fVal)
2000-09-18 23:08:29 +00:00
: SwValueField(pFldType, nFmt, LANGUAGE_SYSTEM, fVal)
{
}
SwFormulaField::SwFormulaField( const SwFormulaField& rFld )
: SwValueField((SwValueFieldType *)rFld.GetTyp(), rFld.GetFormat(),
rFld.GetLanguage(), rFld.GetValue())
{
}
String SwFormulaField::GetFormula() const
{
return sFormula;
}
void SwFormulaField::SetFormula(const String& rStr)
{
sFormula = rStr;
ULONG nFmt(GetFormat());
if( nFmt && SAL_MAX_UINT32 != nFmt )
2000-09-18 23:08:29 +00:00
{
xub_StrLen nPos = 0;
double fTmpValue;
if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
SwValueField::SetValue( fTmpValue );
2000-09-18 23:08:29 +00:00
}
}
void SwFormulaField::SetExpandedFormula( const String& rStr )
{
sal_uInt32 nFmt(GetFormat());
2000-09-18 23:08:29 +00:00
if (nFmt && nFmt != SAL_MAX_UINT32 && ((SwValueFieldType *)GetTyp())->UseFormat())
2000-09-18 23:08:29 +00:00
{
double fTmpValue;
2000-09-18 23:08:29 +00:00
SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
if (pFormatter->IsNumberFormat(rStr, nFmt, fTmpValue))
2000-09-18 23:08:29 +00:00
{
SwValueField::SetValue(fTmpValue);
2000-09-18 23:08:29 +00:00
sFormula.Erase();
((SwValueFieldType *)GetTyp())->DoubleToString(sFormula, fTmpValue, nFmt);
2000-09-18 23:08:29 +00:00
return;
}
}
sFormula = rStr;
}
String SwFormulaField::GetExpandedFormula() const
{
sal_uInt32 nFmt(GetFormat());
2000-09-18 23:08:29 +00:00
if (nFmt && nFmt != SAL_MAX_UINT32 && ((SwValueFieldType *)GetTyp())->UseFormat())
2000-09-18 23:08:29 +00:00
{
String sFormattedValue;
Color* pCol = 0;
SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
if (pFormatter->IsTextFormat(nFmt))
{
String sValue;
((SwValueFieldType *)GetTyp())->DoubleToString(sValue, GetValue(), nFmt);
pFormatter->GetOutputString(sValue, nFmt, sFormattedValue, &pCol);
}
else
pFormatter->GetOutputString(GetValue(), nFmt, sFormattedValue, &pCol);
return sFormattedValue;
}
else
return GetFormula();
}
String SwField::GetDescription() const
{
return SW_RES(STR_FIELD);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */