::osl::MutexGuard aGuard(s_aMutex); if (-1 != pFormatTable[0].nKey) return;
// initialize the keys
Reference<XNumberFormats> xStandardFormats; if (s_xStandardFormats.is())
xStandardFormats = s_xStandardFormats->getNumberFormats();
OSL_ENSURE(xStandardFormats.is(), "OLimitedFormats::ensureTableInitialized: don't have a formats supplier!");
if (!xStandardFormats.is()) return;
// loop through the table for (FormatEntry & rLoopFormats : pFormatTable)
{ // get the key for the description
rLoopFormats.nKey = xStandardFormats->queryKey(
rLoopFormats.aDescription,
getLocale(rLoopFormats.eLocale), false
);
if (-1 == rLoopFormats.nKey)
{
rLoopFormats.nKey = xStandardFormats->addNew(
rLoopFormats.aDescription,
getLocale(rLoopFormats.eLocale)
); #ifdef DBG_UTIL try
{
xStandardFormats->getByKey(rLoopFormats.nKey);
} catch(const Exception&)
{
OSL_FAIL("OLimitedFormats::ensureTableInitialized: adding the key to the formats collection failed!");
} #endif
}
}
}
OSL_ENSURE(m_xAggregate.is() && (-1 != m_nFormatEnumPropertyHandle), "OLimitedFormats::getFormatKeyPropertyValue: not initialized!"); if (!m_xAggregate.is()) return;
// get the aggregate's enum property value
Any aEnumPropertyValue = m_xAggregate->getFastPropertyValue(m_nFormatEnumPropertyHandle);
sal_Int32 nValue = -1;
::cppu::enum2int(nValue, aEnumPropertyValue);
// get the translation table
std::span<FormatEntry> pFormats = lcl_getFormatTable(m_nTableId);
// seek to the nValue'th entry
OSL_ENSURE(o3tl::make_unsigned(nValue) < pFormats.size(), "OLimitedFormats::getFormatKeyPropertyValue: did not find the value!"); if (o3tl::make_unsigned(nValue) < pFormats.size())
_rValue <<= pFormats[nValue].nKey;
// TODO: should use a standard format for the control type we're working for
}
// the new format key to set
sal_Int32 nNewFormat = 0; if (!(_rNewValue >>= nNewFormat)) throw IllegalArgumentException();
// get the old (enum) value from the aggregate
Any aEnumPropertyValue = m_xAggregate->getFastPropertyValue(m_nFormatEnumPropertyHandle);
sal_Int32 nOldEnumValue = -1;
::cppu::enum2int(nOldEnumValue, aEnumPropertyValue); if (nOldEnumValue < 0)
{
SAL_WARN("forms.misc", "Negative OldEnumValue!"); returnfalse;
}
// get the translation table
std::span<FormatEntry> pFormats = lcl_getFormatTable(m_nTableId);
_rOldValue.clear();
_rConvertedValue.clear();
_rOldValue <<= pFormats[nOldEnumValue].nKey;
bool bModified = false; bool bFoundIt = false; // look for the entry with the given format key
sal_Int32 nTablePosition = 0; for (FormatEntry & rEntry : pFormats)
{ if (nNewFormat == rEntry.nKey)
{
bFoundIt = true;
_rConvertedValue <<= static_cast<sal_Int16>(nTablePosition);
bModified = nTablePosition != nOldEnumValue; break;
}
++nTablePosition;
}
OSL_ENSURE(_rOldValue.hasValue(), "OLimitedFormats::convertFormatKeyPropertyValue: did not find the old enum value in the table!");
if (!bFoundIt)
{ // somebody gave us a format which we can't translate throw IllegalArgumentException(u"This control supports only a very limited number of formats."_ustr, nullptr, 2);
}
if (m_xAggregate.is())
{ // this is to be called after convertFormatKeyPropertyValue, where // we translated the format key into an enum value. // So now we can simply forward this enum value to our aggregate
m_xAggregate->setFastPropertyValue(m_nFormatEnumPropertyHandle, _rNewValue);
}
}
void OLimitedFormats::acquireSupplier(const Reference< XComponentContext >& _rxContext)
{
::osl::MutexGuard aGuard(s_aMutex); if (1 == ++s_nInstanceCount)
{ // create the standard formatter
s_xStandardFormats = NumberFormatsSupplier::createWithLocale(_rxContext, getLocale(ltEnglishUS));
}
}
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.