21#include <osl/diagnose.h>
24#include <com/sun/star/form/FormComponentType.hpp>
25#include <com/sun/star/util/NumberFormatsSupplier.hpp>
58 static const Locale s_aEnglishUS(
"en",
"us", OUString() );
59 static const Locale s_aGerman(
"de",
"DE", OUString() );
60 static const Locale s_aSystem(
"",
"",
"" );
74 OSL_FAIL(
"getLocale: invalid enum value!");
82 const char* pDescription;
93 case FormComponentType::TIMEFIELD:
95 static FormatEntry s_aFormats[] = {
96 {
"HH:MM", -1, ltEnglishUS },
97 {
"HH:MM:SS", -1, ltEnglishUS },
98 {
"HH:MM AM/PM", -1, ltEnglishUS },
99 {
"HH:MM:SS AM/PM", -1, ltEnglishUS },
100 {
nullptr, -1, ltSystem }
104 case FormComponentType::DATEFIELD:
106 static FormatEntry s_aFormats[] = {
107 {
"T-M-JJ", -1, ltGerman },
108 {
"TT-MM-JJ", -1, ltGerman },
109 {
"TT-MM-JJJJ", -1, ltGerman },
110 {
"NNNNT. MMMM JJJJ", -1, ltGerman },
112 {
"DD/MM/YY", -1, ltEnglishUS },
113 {
"MM/DD/YY", -1, ltEnglishUS },
114 {
"YY/MM/DD", -1, ltEnglishUS },
115 {
"DD/MM/YYYY", -1, ltEnglishUS },
116 {
"MM/DD/YYYY", -1, ltEnglishUS },
117 {
"YYYY/MM/DD", -1, ltEnglishUS },
119 {
"JJ-MM-TT", -1, ltGerman },
120 {
"JJJJ-MM-TT", -1, ltGerman },
122 {
nullptr, -1, ltSystem }
128 OSL_FAIL(
"lcl_getFormatTable: invalid id!");
133 :m_nFormatEnumPropertyHandle(-1)
134 ,m_nTableId(_nClassId)
136 OSL_ENSURE(_rxContext.is(),
"OLimitedFormats::OLimitedFormats: invalid service factory!");
151 if (-1 != pFormatTable->nKey)
155 if (-1 != pFormatTable->nKey)
159 Reference<XNumberFormats> xStandardFormats;
162 OSL_ENSURE(xStandardFormats.is(),
"OLimitedFormats::ensureTableInitialized: don't have a formats supplier!");
164 if (!xStandardFormats.is())
168 FormatEntry* pLoopFormats = pFormatTable;
169 while (pLoopFormats->pDescription)
172 pLoopFormats->nKey = xStandardFormats->queryKey(
173 OUString::createFromAscii(pLoopFormats->pDescription),
178 if (-1 == pLoopFormats->nKey)
180 pLoopFormats->nKey = xStandardFormats->addNew(
181 OUString::createFromAscii(pLoopFormats->pDescription),
187 xStandardFormats->getByKey(pLoopFormats->nKey);
191 OSL_FAIL(
"OLimitedFormats::ensureTableInitialized: adding the key to the formats collection failed!");
206 FormatEntry* pResetLoop = pFormats;
207 while (pResetLoop->pDescription)
209 pResetLoop->nKey = -1;
218 OSL_ENSURE(!
m_xAggregate.is() || !_rxAggregate.is(),
"OLimitedFormats::setAggregateSet: already have an aggregate!");
219 OSL_ENSURE(_rxAggregate.is() ||
m_xAggregate.is(),
"OLimitedFormats::setAggregateSet: invalid new aggregate!");
232 OSL_FAIL(
"OLimitedFormats::setAggregateSet: invalid handle!");
250 ::cppu::enum2int(
nValue, aEnumPropertyValue);
256 sal_Int32 nLookup = 0;
258 (
nullptr != pFormats->pDescription) && (nLookup <
nValue);
259 ++pFormats, ++nLookup
262 OSL_ENSURE(
nullptr != pFormats->pDescription,
"OLimitedFormats::getFormatKeyPropertyValue: did not find the value!");
263 if (pFormats->pDescription)
264 _rValue <<= pFormats->nKey;
278 sal_Int32 nNewFormat = 0;
279 if (!(_rNewValue >>= nNewFormat))
280 throw IllegalArgumentException();
284 sal_Int32 nOldEnumValue = -1;
285 ::cppu::enum2int(nOldEnumValue, aEnumPropertyValue);
291 _rConvertedValue.clear();
294 sal_Int32 nTablePosition = 0;
296 (
nullptr != pFormats->pDescription) && (nNewFormat != pFormats->nKey);
297 ++pFormats, ++nTablePosition
300 if (nTablePosition == nOldEnumValue)
301 _rOldValue <<= pFormats->nKey;
304 bool bFoundIt = (
nullptr != pFormats->pDescription);
305 bool bModified =
false;
308 _rConvertedValue <<= static_cast<sal_Int16>(nTablePosition);
309 bModified = nTablePosition != nOldEnumValue;
312 if (!_rOldValue.hasValue())
315 while (pFormats->pDescription)
317 if (nTablePosition == nOldEnumValue)
319 _rOldValue <<= pFormats->nKey;
328 OSL_ENSURE(_rOldValue.hasValue(),
"OLimitedFormats::convertFormatKeyPropertyValue: did not find the old enum value in the table!");
332 throw IllegalArgumentException(
"This control supports only a very limited number of formats.",
nullptr, 2);
ListBox is a bit confusing / different from other form components, so here are a few notes:
static FormatEntry * lcl_getFormatTable(sal_Int16 nTableId)
static const Locale & getLocale(LocaleType _eType)