/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
switch (eValType)
{ case SvxNumberValueType::String:
aValStr = rNumStr; break; case SvxNumberValueType::Number: if (pFormatter)
{
nValNum = GetDefaultValNum(pFormatter->GetType(nCurFormatKey));
}
[[fallthrough]]; case SvxNumberValueType::Undefined: default:
aValStr.clear();
}
}
SvxNumberFormatShell::SvxNumberFormatShell(SvNumberFormatter* pNumFormatter, sal_uInt32 nFormatKey,
SvxNumberValueType eNumValType, double nNumVal, const OUString* pNumStr)
: pFormatter(pNumFormatter)
, pCurFmtTable(nullptr)
, eValType(eNumValType)
, bUndoAddList(true)
, nCurFormatKey(nFormatKey)
, nCurCategory(SvNumFormatType::ALL)
, eCurLanguage(LANGUAGE_NONE)
, pCurCurrencyEntry(nullptr)
, bBankingSymbol(false)
, nCurCurrencyEntryPos(sal_uInt16(SELPOS_NONE))
, bUseStarFormat(false)
, bIsDefaultValNum(false)
{ // #50441# When used in Writer, the SvxNumberInfoItem contains the // original string in addition to the value
if (pNumStr)
aValStr = *pNumStr;
switch (eValType)
{ case SvxNumberValueType::Number:
nValNum = nNumVal; break; case SvxNumberValueType::String: case SvxNumberValueType::Undefined: default:
nValNum = 0;
bIsDefaultValNum = true;
}
}
SvxNumberFormatShell::~SvxNumberFormatShell()
{ /* * At this point, depending on whether the added user-defined were * validated (ValidateNewEntries()), the add list is removed from * the number formatter again. * * Deleting formats from the formatter happens for Undo reasons * only in the calling instance.
*/
if (bUndoAddList)
{ // Added formats are invalid => remove them
for (constauto& rItem : aAddList)
pFormatter->DeleteEntry(rItem);
}
}
if (bInserted)
{ // May be sorted under a different locale if LCID was parsed. const SvNumberformat* pEntry = pFormatter->GetEntry(nAddKey); if (pEntry)
{
LanguageType nLang = pEntry->GetLanguage(); if (eCurLanguage != nLang)
{ // Current language's list would not show entry, adapt.
eCurLanguage = nLang;
}
}
}
}
sal_uInt32 nExistingFormat = pFormatter->GetEntryKey(rFormatStr, eCurLanguage); if (nExistingFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
{ // real preview - not implemented in NumberFormatter for text formats
pFormatter->GetPreviewString(rFormatStr, nValNum, rPreviewStr, &rpFontColor, eCurLanguage,
bUseStarFormat);
} else
{ // format exists
// #50441# if a string was set in addition to the value, use it for text formats bool bUseText = (eValType == SvxNumberValueType::String
|| (!aValStr.isEmpty()
&& (pFormatter->GetType(nExistingFormat) & SvNumFormatType::TEXT)));
sal_uInt32 nFound = NUMBERFORMAT_ENTRY_NOT_FOUND; // There may be multiple builtin entries with the same format code, first // try if the current key matches. const SvNumberformat* pEntry = pFormatter->GetEntry(nCurFormatKey); if (pEntry && pEntry->GetLanguage() == eCurLanguage && pEntry->GetFormatstring() == rFmtString)
nFound = nCurFormatKey;
if (nFound == NUMBERFORMAT_ENTRY_NOT_FOUND) // Find the first matching format code.
nFound = pFormatter->TestNewString(rFmtString, eCurLanguage);
short SvxNumberFormatShell::FillEntryList_Impl(std::vector<OUString>& rList)
{ /* Create a current list of format entries. The return value is * the list position of the current format. If the list is empty * or if there is no current format, SELPOS_NONE is delivered.
*/ short nSelPos = SELPOS_NONE;
FillEListWithStd_Impl(rList, SvNumFormatType::CURRENCY, nSelPos); // No FillEListWithUsD_Impl() here, user defined currency formats // were already added.
void SvxNumberFormatShell::FillEListWithStd_Impl(std::vector<OUString>& rList,
SvNumFormatType eCategory, short& nSelPos, bool bSuppressDuplicates)
{ /* Create a current list of format entries. The return value is * the list position of the current format. If the list is empty * or if there is no current format, SELPOS_NONE is delivered.
*/
short SvxNumberFormatShell::FillEListWithFormats_Impl(std::vector<OUString>& rList, short nSelPos,
NfIndexTableOffset eOffsetStart,
NfIndexTableOffset eOffsetEnd, bool bSuppressDuplicates)
{ /* Create a current list of format entries. The return value is * the list position of the current format. If the list is empty * or if there is no current format, SELPOS_NONE is delivered.
*/ for (tools::Long nIndex = eOffsetStart; nIndex <= eOffsetEnd; ++nIndex)
{
FillEListWithOneFormat_Impl(rList, nSelPos, bSuppressDuplicates, static_cast<NfIndexTableOffset>(nIndex), false);
}
return nSelPos;
}
short SvxNumberFormatShell::FillEListWithDateTime_Impl(std::vector<OUString>& rList, short nSelPos, bool bSuppressDuplicates)
{ // Append a list of date+time formats.
// Add first, so a NF_DATETIME_SYSTEM_SHORT_HHMM may be suppressed in // locales that do not use 2-digit years there and this here is the // default.
FillEListWithOneFormat_Impl(rList, nSelPos, bSuppressDuplicates, NF_DATETIME_SYS_DDMMYYYY_HHMM, true);
// Ugly hack to suppress an ISO date+time format that is the default // date+time format of the locale and identical to the internally generated // one always to be added after/below. constbool bSupIso
= bSuppressIsoDateTime && bSuppressDuplicates
&& (aNewFormNInfo == "YYYY-MM-DD HH:MM:SS" || aNewFormNInfo == "YYYY-MM-DD\"T\"HH:MM:SS");
const NfIndexTableOffset nIndex = SvNumberFormatter::GetIndexTableOffset(nKey); switch (nIndex)
{ // These are preferred or edit formats. case NF_DATE_SYS_DDMMYYYY: case NF_DATE_ISO_YYYYMMDD: case NF_TIME_HH_MMSS: case NF_TIME_MMSS00: case NF_TIME_HH_MMSS00: case NF_DATETIME_SYS_DDMMYYYY_HHMM: case NF_DATETIME_SYS_DDMMYYYY_HHMMSS: case NF_DATETIME_ISO_YYYYMMDD_HHMMSS: case NF_DATETIME_ISO_YYYYMMDD_HHMMSS000: case NF_DATETIME_ISO_YYYYMMDDTHHMMSS: case NF_DATETIME_ISO_YYYYMMDDTHHMMSS000: returntrue; default: break;
}
short SvxNumberFormatShell::FillEListWithCurrency_Impl(std::vector<OUString>& rList, short nSelPos)
{ /* Create a current list of format entries. The return value is * the list position of the current format. If the list is empty * or if there is no current format, SELPOS_NONE is delivered.
*/
DBG_ASSERT(pCurFmtTable != nullptr, "unknown NumberFormat");
short SvxNumberFormatShell::FillEListWithSysCurrencys(std::vector<OUString>& rList, short nSelPos)
{ /* Create a current list of format entries. The return value is * the list position of the current format. If the list is empty * or if there is no current format, SELPOS_NONE is delivered.
*/
sal_uInt16 nMyType;
if (nCurCategory == SvNumFormatType::ALL && nNFEntry != nCurFormatKey) // Deprecated old currency entries, for ALL add only if used as // current format key. continue;
short SvxNumberFormatShell::FillEListWithUserCurrencys(std::vector<OUString>& rList, short nSelPos)
{ /* Create a current list of format entries. The return value is * the list position of the current format. If the list is empty * or if there is no current format, SELPOS_NONE is delivered.
*/
sal_uInt16 nMyType;
if (pCurCurrencyEntry == nullptr)
{ // #110398# If no currency format was previously selected (we're not // about to add another currency), try to select the initial currency // format (nCurFormatKey) that was set in FormatChanged() after // matching the format string entered in the dialog.
bAdaptSelPos = true;
pCurCurrencyEntry = const_cast<NfCurrencyEntry*>(pTmpCurrencyEntry);
bBankingSymbol = bTmpBanking;
nCurCurrencyEntryPos = FindCurrencyFormat(pTmpCurrencyEntry, bTmpBanking);
} else
{ if (pTmpCurrencyEntry == pCurCurrencyEntry)
bAdaptSelPos = true; else
{
bAdaptSelPos = false;
pTmpCurrencyEntry = pCurCurrencyEntry;
}
bTmpBanking = bBankingSymbol;
}
for (size_t i = 0; i < aKeyList.size(); ++i)
{ if (aKeyList[i] != NUMBERFORMAT_ENTRY_NOT_FOUND)
{
rList.push_back(aList[i]);
aCurEntryList.push_back(aKeyList[i]);
}
}
for (size_t i = nOldListCount; i < rList.size(); ++i)
{
aCurrencyFormatList.push_back(rList[i]);
short SvxNumberFormatShell::FillEListWithUsD_Impl(std::vector<OUString>& rList,
SvNumFormatType eCategory, short nSelPos)
{ /* Create a current list of format entries. The return value is * the list position of the current format. If the list is empty * or if there is no current format, SELPOS_NONE is delivered.
*/
if (bCategoryMatch && (pNumEntry->GetMaskedType() & eCategory) != eCategory) continue; // for; type does not match category if not ALL
constbool bUserDefined = bool(pNumEntry->GetType() & SvNumFormatType::DEFINED); if (!bUserDefined && bCatDefined) continue; // for; not user defined in DEFINED category
if (!(bUserDefined || (!bCatDefined && pNumEntry->IsAdditionalBuiltin()))) continue; // for; does not match criteria at all
if (bNatNumCurrency && (aNewFormNInfo.indexOf("NatNum12") < 0 || bUserDefined)) continue; // for; extra CURRENCY must be not user-defined NatNum12 type
// #50441# if a string was set in addition to the value, use it for text formats bool bUseText
= (eValType == SvxNumberValueType::String
|| (!aValStr.isEmpty() && (pFormatter->GetType(nCurFormatKey) & SvNumFormatType::TEXT)));
// Conversion routines: void SvxNumberFormatShell::PosToCategory_Impl(sal_uInt16 nPos, SvNumFormatType& rCategory)
{ // map category css::form positions (->resource) switch (nPos)
{ case CAT_USERDEFINED:
rCategory = SvNumFormatType::DEFINED; break; case CAT_NUMBER:
rCategory = SvNumFormatType::NUMBER; break; case CAT_PERCENT:
rCategory = SvNumFormatType::PERCENT; break; case CAT_CURRENCY:
rCategory = SvNumFormatType::CURRENCY; break; case CAT_DATE:
rCategory = SvNumFormatType::DATE; break; case CAT_TIME:
rCategory = SvNumFormatType::TIME; break; case CAT_SCIENTIFIC:
rCategory = SvNumFormatType::SCIENTIFIC; break; case CAT_FRACTION:
rCategory = SvNumFormatType::FRACTION; break; case CAT_BOOLEAN:
rCategory = SvNumFormatType::LOGICAL; break; case CAT_TEXT:
rCategory = SvNumFormatType::TEXT; break; case CAT_ALL: default:
rCategory = SvNumFormatType::ALL; break;
}
}
void SvxNumberFormatShell::CategoryToPos_Impl(SvNumFormatType nCategory, sal_uInt16& rPos)
{ // map category to css::form positions (->resource) switch (nCategory)
{ case SvNumFormatType::DEFINED:
rPos = CAT_USERDEFINED; break; case SvNumFormatType::NUMBER:
rPos = CAT_NUMBER; break; case SvNumFormatType::PERCENT:
rPos = CAT_PERCENT; break; case SvNumFormatType::CURRENCY:
rPos = CAT_CURRENCY; break; case SvNumFormatType::DATETIME: case SvNumFormatType::DATE:
rPos = CAT_DATE; break; case SvNumFormatType::TIME:
rPos = CAT_TIME; break; case SvNumFormatType::SCIENTIFIC:
rPos = CAT_SCIENTIFIC; break; case SvNumFormatType::FRACTION:
rPos = CAT_FRACTION; break; case SvNumFormatType::LOGICAL:
rPos = CAT_BOOLEAN; break; case SvNumFormatType::TEXT:
rPos = CAT_TEXT; break; case SvNumFormatType::ALL: default:
rPos = CAT_ALL;
}
}
/* * Function: Formats the number nValue dependent on rFormatStr * and stores the result in rPreviewStr. * Input: FormatString, color, number to format * Output: Output string rPreviewStr
*/ void SvxNumberFormatShell::MakePrevStringFromVal(const OUString& rFormatStr, OUString& rPreviewStr, const Color*& rpFontColor, double nValue)
{
rpFontColor = nullptr;
pFormatter->GetPreviewString(rFormatStr, nValue, rPreviewStr, &rpFontColor, eCurLanguage);
}
/* * Function: Returns the comment for a given entry. * Input: Number of the entry * Output: Comment string
*/ void SvxNumberFormatShell::SetComment4Entry(short nEntry, const OUString& aEntStr)
{
SvNumberformat* pNumEntry; if (nEntry < 0) return;
sal_uInt32 nMyNfEntry = aCurEntryList[nEntry];
pNumEntry = const_cast<SvNumberformat*>(pFormatter->GetEntry(nMyNfEntry)); if (pNumEntry != nullptr)
pNumEntry->SetComment(aEntStr);
}
/* * Function: Returns the comment for a given entry. * Input: Number of the entry * Output: Comment string
*/
OUString SvxNumberFormatShell::GetComment4Entry(short nEntry)
{ if (nEntry < 0) return OUString();
/* * Function: Returns the category number for a given entry. * Input: Number of the entry * Output: Category number
*/ short SvxNumberFormatShell::GetCategory4Entry(short nEntry) const
{ if (nEntry < 0) return 0; if (o3tl::make_unsigned(nEntry) < aCurEntryList.size())
{
sal_uInt32 nMyNfEntry = aCurEntryList[nEntry];
/* * Function: Returns the information about whether an entry is user-specific. * Input: Number of the entry * Output: User-specific?
*/ bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
{ if (nEntry < 0) returnfalse; if (o3tl::make_unsigned(nEntry) < aCurEntryList.size())
{
sal_uInt32 nMyNfEntry = aCurEntryList[nEntry]; const SvNumberformat* pNumEntry = pFormatter->GetEntry(nMyNfEntry);
if (pNumEntry != nullptr)
{ if (pNumEntry->GetType() & SvNumFormatType::DEFINED)
{ returntrue;
}
}
} returnfalse;
}
/* * Function: Returns the format string for a given entry. * Input: Number of the entry * Output: Format string
*/
OUString SvxNumberFormatShell::GetFormat4Entry(short nEntry)
{ if (nEntry < 0) return OUString();
if (pNumEntry != nullptr) return pNumEntry->GetFormatstring();
} return OUString();
}
/* * Function: Returns the list number for a given format index. * Input: Number of the entry * Output: Category number
*/ short SvxNumberFormatShell::GetListPos4Entry(sal_uInt32 nIdx, std::u16string_view rFmtString)
{ short nSelP = SELPOS_NONE; if (nIdx != NUMBERFORMAT_ENTRY_NEW_CURRENCY)
{ // Check list size against return type limit. if (aCurEntryList.size() <= o3tl::make_unsigned(::std::numeric_limits<short>::max()))
{ for (size_t i = 0; i < aCurEntryList.size(); ++i)
{ if (aCurEntryList[i] == nIdx)
{
nSelP = i; break;
}
}
} else
{
OSL_FAIL("svx::SvxNumberFormatShell::GetListPos4Entry(), list got too large!");
}
} else
{ // A second list holds the generated currency formats. for (size_t i = 0; i < aCurrencyFormatList.size(); ++i)
{ if (rFmtString == aCurrencyFormatList[i])
{
nSelP = static_cast<short>(i); break;
}
}
} return nSelP;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.