1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10*24acc546SAndrew Rist * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*24acc546SAndrew Rist * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19*24acc546SAndrew Rist * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir #include "limitedformats.hxx" 27cdf0e10cSrcweir #include "services.hxx" 28cdf0e10cSrcweir #include <osl/diagnose.h> 29cdf0e10cSrcweir #include <comphelper/types.hxx> 30cdf0e10cSrcweir #include <comphelper/extract.hxx> 31cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir //......................................................................... 34cdf0e10cSrcweir namespace frm 35cdf0e10cSrcweir { 36cdf0e10cSrcweir //......................................................................... 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::util; 40cdf0e10cSrcweir using namespace ::com::sun::star::lang; 41cdf0e10cSrcweir using namespace ::com::sun::star::form; 42cdf0e10cSrcweir using namespace ::com::sun::star::beans; 43cdf0e10cSrcweir 44cdf0e10cSrcweir sal_Int32 OLimitedFormats::s_nInstanceCount(0); 45cdf0e10cSrcweir ::osl::Mutex OLimitedFormats::s_aMutex; 46cdf0e10cSrcweir Reference< XNumberFormatsSupplier > OLimitedFormats::s_xStandardFormats; 47cdf0e10cSrcweir 48cdf0e10cSrcweir //===================================================================== 49cdf0e10cSrcweir //= 50cdf0e10cSrcweir //===================================================================== 51cdf0e10cSrcweir //--------------------------------------------------------------------- 52cdf0e10cSrcweir enum LocaleType 53cdf0e10cSrcweir { 54cdf0e10cSrcweir ltEnglishUS, 55cdf0e10cSrcweir ltGerman, 56cdf0e10cSrcweir ltSystem 57cdf0e10cSrcweir }; 58cdf0e10cSrcweir 59cdf0e10cSrcweir //--------------------------------------------------------------------- 60cdf0e10cSrcweir static const Locale& getLocale(LocaleType _eType) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir static const Locale s_aEnglishUS( ::rtl::OUString::createFromAscii("en"), ::rtl::OUString::createFromAscii("us"), ::rtl::OUString() ); 63cdf0e10cSrcweir static const Locale s_aGerman( ::rtl::OUString::createFromAscii("de"), ::rtl::OUString::createFromAscii("DE"), ::rtl::OUString() ); 64cdf0e10cSrcweir static const ::rtl::OUString s_sEmptyString; 65cdf0e10cSrcweir static const Locale s_aSystem( s_sEmptyString, s_sEmptyString, s_sEmptyString ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir switch (_eType) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir case ltEnglishUS: 70cdf0e10cSrcweir return s_aEnglishUS; 71cdf0e10cSrcweir 72cdf0e10cSrcweir case ltGerman: 73cdf0e10cSrcweir return s_aGerman; 74cdf0e10cSrcweir 75cdf0e10cSrcweir case ltSystem: 76cdf0e10cSrcweir return s_aSystem; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir OSL_ENSURE(sal_False, "getLocale: invalid enum value!"); 80cdf0e10cSrcweir return s_aSystem; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir //--------------------------------------------------------------------- 84cdf0e10cSrcweir struct FormatEntry 85cdf0e10cSrcweir { 86cdf0e10cSrcweir const sal_Char* pDescription; 87cdf0e10cSrcweir sal_Int32 nKey; 88cdf0e10cSrcweir LocaleType eLocale; 89cdf0e10cSrcweir }; 90cdf0e10cSrcweir 91cdf0e10cSrcweir //--------------------------------------------------------------------- 92cdf0e10cSrcweir static const FormatEntry* lcl_getFormatTable(sal_Int16 nTableId) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir switch (nTableId) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir case FormComponentType::TIMEFIELD: 97cdf0e10cSrcweir { 98cdf0e10cSrcweir static FormatEntry s_aFormats[] = { 99cdf0e10cSrcweir { "HH:MM", -1, ltEnglishUS }, 100cdf0e10cSrcweir { "HH:MM:SS", -1, ltEnglishUS }, 101cdf0e10cSrcweir { "HH:MM AM/PM", -1, ltEnglishUS }, 102cdf0e10cSrcweir { "HH:MM:SS AM/PM", -1, ltEnglishUS }, 103cdf0e10cSrcweir { NULL, -1, ltSystem } 104cdf0e10cSrcweir }; 105cdf0e10cSrcweir // don't switch this table here to const. The compiler could be tempted to really place this 106cdf0e10cSrcweir // in a non-writeable segment, but we want to fill in the format keys later .... 107cdf0e10cSrcweir return s_aFormats; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir case FormComponentType::DATEFIELD: 110cdf0e10cSrcweir { 111cdf0e10cSrcweir static FormatEntry s_aFormats[] = { 112cdf0e10cSrcweir { "T-M-JJ", -1, ltGerman }, 113cdf0e10cSrcweir { "TT-MM-JJ", -1, ltGerman }, 114cdf0e10cSrcweir { "TT-MM-JJJJ", -1, ltGerman }, 115cdf0e10cSrcweir { "NNNNT. MMMM JJJJ", -1, ltGerman }, 116cdf0e10cSrcweir 117cdf0e10cSrcweir { "DD/MM/YY", -1, ltEnglishUS }, 118cdf0e10cSrcweir { "MM/DD/YY", -1, ltEnglishUS }, 119cdf0e10cSrcweir { "YY/MM/DD", -1, ltEnglishUS }, 120cdf0e10cSrcweir { "DD/MM/YYYY", -1, ltEnglishUS }, 121cdf0e10cSrcweir { "MM/DD/YYYY", -1, ltEnglishUS }, 122cdf0e10cSrcweir { "YYYY/MM/DD", -1, ltEnglishUS }, 123cdf0e10cSrcweir 124cdf0e10cSrcweir { "JJ-MM-TT", -1, ltGerman }, 125cdf0e10cSrcweir { "JJJJ-MM-TT", -1, ltGerman }, 126cdf0e10cSrcweir 127cdf0e10cSrcweir { NULL, -1, ltSystem } 128cdf0e10cSrcweir }; 129cdf0e10cSrcweir return s_aFormats; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir OSL_ENSURE(sal_False, "lcl_getFormatTable: invalid id!"); 134cdf0e10cSrcweir return NULL; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir //===================================================================== 138cdf0e10cSrcweir //= OLimitedFormats 139cdf0e10cSrcweir //===================================================================== 140cdf0e10cSrcweir //--------------------------------------------------------------------- 141cdf0e10cSrcweir OLimitedFormats::OLimitedFormats(const Reference< XMultiServiceFactory >& _rxORB, const sal_Int16 _nClassId) 142cdf0e10cSrcweir :m_nFormatEnumPropertyHandle(-1) 143cdf0e10cSrcweir ,m_nTableId(_nClassId) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir OSL_ENSURE(_rxORB.is(), "OLimitedFormats::OLimitedFormats: invalid service factory!"); 146cdf0e10cSrcweir acquireSupplier(_rxORB); 147cdf0e10cSrcweir ensureTableInitialized(m_nTableId); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir //--------------------------------------------------------------------- 151cdf0e10cSrcweir OLimitedFormats::~OLimitedFormats() 152cdf0e10cSrcweir { 153cdf0e10cSrcweir releaseSupplier(); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir //--------------------------------------------------------------------- 157cdf0e10cSrcweir void OLimitedFormats::ensureTableInitialized(const sal_Int16 _nTableId) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir const FormatEntry* pFormatTable = lcl_getFormatTable(_nTableId); 160cdf0e10cSrcweir if (-1 == pFormatTable->nKey) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir ::osl::MutexGuard aGuard(s_aMutex); 163cdf0e10cSrcweir if (-1 == pFormatTable->nKey) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir // initialize the keys 166cdf0e10cSrcweir Reference<XNumberFormats> xStandardFormats; 167cdf0e10cSrcweir if (s_xStandardFormats.is()) 168cdf0e10cSrcweir xStandardFormats = s_xStandardFormats->getNumberFormats(); 169cdf0e10cSrcweir OSL_ENSURE(xStandardFormats.is(), "OLimitedFormats::ensureTableInitialized: don't have a formats supplier!"); 170cdf0e10cSrcweir 171cdf0e10cSrcweir if (xStandardFormats.is()) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir // loop through the table 174cdf0e10cSrcweir FormatEntry* pLoopFormats = const_cast<FormatEntry*>(pFormatTable); 175cdf0e10cSrcweir while (pLoopFormats->pDescription) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir // get the key for the description 178cdf0e10cSrcweir pLoopFormats->nKey = xStandardFormats->queryKey( 179cdf0e10cSrcweir ::rtl::OUString::createFromAscii(pLoopFormats->pDescription), 180cdf0e10cSrcweir getLocale(pLoopFormats->eLocale), 181cdf0e10cSrcweir sal_False 182cdf0e10cSrcweir ); 183cdf0e10cSrcweir 184cdf0e10cSrcweir if (-1 == pLoopFormats->nKey) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir pLoopFormats->nKey = xStandardFormats->addNew( 187cdf0e10cSrcweir ::rtl::OUString::createFromAscii(pLoopFormats->pDescription), 188cdf0e10cSrcweir getLocale(pLoopFormats->eLocale) 189cdf0e10cSrcweir ); 190cdf0e10cSrcweir #ifdef DBG_UTIL 191cdf0e10cSrcweir try 192cdf0e10cSrcweir { 193cdf0e10cSrcweir xStandardFormats->getByKey(pLoopFormats->nKey); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir catch(const Exception&) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir OSL_ENSURE(sal_False, "OLimitedFormats::ensureTableInitialized: adding the key to the formats collection failed!"); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir #endif 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir // next 203cdf0e10cSrcweir ++pLoopFormats; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } 206cdf0e10cSrcweir } 207cdf0e10cSrcweir } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir //--------------------------------------------------------------------- 211cdf0e10cSrcweir void OLimitedFormats::clearTable(const sal_Int16 _nTableId) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir ::osl::MutexGuard aGuard(s_aMutex); 214cdf0e10cSrcweir const FormatEntry* pFormats = lcl_getFormatTable(_nTableId); 215cdf0e10cSrcweir FormatEntry* pResetLoop = const_cast<FormatEntry*>(pFormats); 216cdf0e10cSrcweir while (pResetLoop->pDescription) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir pResetLoop->nKey = -1; 219cdf0e10cSrcweir ++pResetLoop; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir //--------------------------------------------------------------------- 224cdf0e10cSrcweir void OLimitedFormats::setAggregateSet(const Reference< XFastPropertySet >& _rxAggregate, sal_Int32 _nOriginalPropertyHandle) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir // changes (NULL -> not NULL) and (not NULL -> NULL) are allowed 227cdf0e10cSrcweir OSL_ENSURE(!m_xAggregate.is() || !_rxAggregate.is(), "OLimitedFormats::setAggregateSet: already have an aggregate!"); 228cdf0e10cSrcweir OSL_ENSURE(_rxAggregate.is() || m_xAggregate.is(), "OLimitedFormats::setAggregateSet: invalid new aggregate!"); 229cdf0e10cSrcweir 230cdf0e10cSrcweir m_xAggregate = _rxAggregate; 231cdf0e10cSrcweir m_nFormatEnumPropertyHandle = _nOriginalPropertyHandle; 232cdf0e10cSrcweir #ifdef DBG_UTIL 233cdf0e10cSrcweir if (m_xAggregate.is()) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir try 236cdf0e10cSrcweir { 237cdf0e10cSrcweir m_xAggregate->getFastPropertyValue(m_nFormatEnumPropertyHandle); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir catch(const Exception&) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir OSL_ENSURE(sal_False, "OLimitedFormats::setAggregateSet: invalid handle!"); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir } 244cdf0e10cSrcweir #endif 245cdf0e10cSrcweir } 246cdf0e10cSrcweir 247cdf0e10cSrcweir //--------------------------------------------------------------------- 248cdf0e10cSrcweir void OLimitedFormats::getFormatKeyPropertyValue( Any& _rValue ) const 249cdf0e10cSrcweir { 250cdf0e10cSrcweir _rValue.clear(); 251cdf0e10cSrcweir 252cdf0e10cSrcweir OSL_ENSURE(m_xAggregate.is() && (-1 != m_nFormatEnumPropertyHandle), "OLimitedFormats::getFormatKeyPropertyValue: not initialized!"); 253cdf0e10cSrcweir if (m_xAggregate.is()) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir // get the aggregate's enum property value 256cdf0e10cSrcweir Any aEnumPropertyValue = m_xAggregate->getFastPropertyValue(m_nFormatEnumPropertyHandle); 257cdf0e10cSrcweir sal_Int32 nValue = -1; 258cdf0e10cSrcweir ::cppu::enum2int(nValue, aEnumPropertyValue); 259cdf0e10cSrcweir 260cdf0e10cSrcweir // get the translation table 261cdf0e10cSrcweir const FormatEntry* pFormats = lcl_getFormatTable(m_nTableId); 262cdf0e10cSrcweir 263cdf0e10cSrcweir // seek to the nValue'th entry 264cdf0e10cSrcweir sal_Int32 nLookup = 0; 265cdf0e10cSrcweir for ( ; 266cdf0e10cSrcweir (NULL != pFormats->pDescription) && (nLookup < nValue); 267cdf0e10cSrcweir ++pFormats, ++nLookup 268cdf0e10cSrcweir ) 269cdf0e10cSrcweir ; 270cdf0e10cSrcweir OSL_ENSURE(NULL != pFormats->pDescription, "OLimitedFormats::getFormatKeyPropertyValue: did not find the value!"); 271cdf0e10cSrcweir if (pFormats->pDescription) 272cdf0e10cSrcweir _rValue <<= pFormats->nKey; 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir // TODO: should use a standard format for the control type we're working for 276cdf0e10cSrcweir } 277cdf0e10cSrcweir 278cdf0e10cSrcweir //--------------------------------------------------------------------- 279cdf0e10cSrcweir sal_Bool OLimitedFormats::convertFormatKeyPropertyValue(Any& _rConvertedValue, Any& _rOldValue, const Any& _rNewValue) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir OSL_ENSURE(m_xAggregate.is() && (-1 != m_nFormatEnumPropertyHandle), "OLimitedFormats::convertFormatKeyPropertyValue: not initialized!"); 282cdf0e10cSrcweir 283cdf0e10cSrcweir if (m_xAggregate.is()) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir // the new format key to set 286cdf0e10cSrcweir sal_Int32 nNewFormat = 0; 287cdf0e10cSrcweir if (!(_rNewValue >>= nNewFormat)) 288cdf0e10cSrcweir throw IllegalArgumentException(); 289cdf0e10cSrcweir 290cdf0e10cSrcweir // get the old (enum) value from the aggregate 291cdf0e10cSrcweir Any aEnumPropertyValue = m_xAggregate->getFastPropertyValue(m_nFormatEnumPropertyHandle); 292cdf0e10cSrcweir sal_Int32 nOldEnumValue = -1; 293cdf0e10cSrcweir ::cppu::enum2int(nOldEnumValue, aEnumPropertyValue); 294cdf0e10cSrcweir 295cdf0e10cSrcweir // get the translation table 296cdf0e10cSrcweir const FormatEntry* pFormats = lcl_getFormatTable(m_nTableId); 297cdf0e10cSrcweir 298cdf0e10cSrcweir _rOldValue.clear(); 299cdf0e10cSrcweir _rConvertedValue.clear(); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // look for the entry with the given format key 302cdf0e10cSrcweir sal_Int32 nTablePosition = 0; 303cdf0e10cSrcweir for ( ; 304cdf0e10cSrcweir (NULL != pFormats->pDescription) && (nNewFormat != pFormats->nKey); 305cdf0e10cSrcweir ++pFormats, ++nTablePosition 306cdf0e10cSrcweir ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir if (nTablePosition == nOldEnumValue) 309cdf0e10cSrcweir _rOldValue <<= pFormats->nKey; 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir sal_Bool bFoundIt = (NULL != pFormats->pDescription); 313cdf0e10cSrcweir sal_Bool bModified = sal_False; 314cdf0e10cSrcweir if (bFoundIt) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir _rConvertedValue <<= (sal_Int16)nTablePosition; 317cdf0e10cSrcweir bModified = nTablePosition != nOldEnumValue; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir if (!_rOldValue.hasValue()) 321cdf0e10cSrcweir { // did not reach the end of the table (means we found nNewFormat) 322cdf0e10cSrcweir // -> go to the end to ensure that _rOldValue is set 323cdf0e10cSrcweir while (pFormats->pDescription) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir if (nTablePosition == nOldEnumValue) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir _rOldValue <<= pFormats->nKey; 328cdf0e10cSrcweir break; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir ++pFormats; 332cdf0e10cSrcweir ++nTablePosition; 333cdf0e10cSrcweir } 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir OSL_ENSURE(_rOldValue.hasValue(), "OLimitedFormats::convertFormatKeyPropertyValue: did not find the old enum value in the table!"); 337cdf0e10cSrcweir 338cdf0e10cSrcweir if (!bFoundIt) 339cdf0e10cSrcweir { // somebody gave us an format which we can't translate 340cdf0e10cSrcweir ::rtl::OUString sMessage = ::rtl::OUString::createFromAscii("This control supports only a very limited number of formats."); 341cdf0e10cSrcweir throw IllegalArgumentException(sMessage, NULL, 2); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir return bModified; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir return sal_False; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir //--------------------------------------------------------------------- 351cdf0e10cSrcweir void OLimitedFormats::setFormatKeyPropertyValue( const Any& _rNewValue ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir OSL_ENSURE(m_xAggregate.is() && (-1 != m_nFormatEnumPropertyHandle), "OLimitedFormats::setFormatKeyPropertyValue: not initialized!"); 354cdf0e10cSrcweir 355cdf0e10cSrcweir if (m_xAggregate.is()) 356cdf0e10cSrcweir { // this is to be called after convertFormatKeyPropertyValue, where 357cdf0e10cSrcweir // we translated the format key into a enum value. 358cdf0e10cSrcweir // So now we can simply forward this enum value to our aggreate 359cdf0e10cSrcweir m_xAggregate->setFastPropertyValue(m_nFormatEnumPropertyHandle, _rNewValue); 360cdf0e10cSrcweir } 361cdf0e10cSrcweir } 362cdf0e10cSrcweir 363cdf0e10cSrcweir //--------------------------------------------------------------------- 364cdf0e10cSrcweir void OLimitedFormats::acquireSupplier(const Reference< XMultiServiceFactory >& _rxORB) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir ::osl::MutexGuard aGuard(s_aMutex); 367cdf0e10cSrcweir if ((1 == ++s_nInstanceCount) && _rxORB.is()) 368cdf0e10cSrcweir { // create the standard formatter 369cdf0e10cSrcweir 370cdf0e10cSrcweir Sequence< Any > aInit(1); 371cdf0e10cSrcweir aInit[0] <<= getLocale(ltEnglishUS); 372cdf0e10cSrcweir 373cdf0e10cSrcweir Reference< XInterface > xSupplier = _rxORB->createInstanceWithArguments(FRM_NUMBER_FORMATS_SUPPLIER, aInit); 374cdf0e10cSrcweir OSL_ENSURE(xSupplier.is(), "OLimitedFormats::OLimitedFormats: could not create a formats supplier!"); 375cdf0e10cSrcweir 376cdf0e10cSrcweir s_xStandardFormats = Reference< XNumberFormatsSupplier >(xSupplier, UNO_QUERY); 377cdf0e10cSrcweir OSL_ENSURE(s_xStandardFormats.is() || !xSupplier.is(), "OLimitedFormats::OLimitedFormats: missing an interface!"); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir //--------------------------------------------------------------------- 382cdf0e10cSrcweir void OLimitedFormats::releaseSupplier() 383cdf0e10cSrcweir { 384cdf0e10cSrcweir ::osl::MutexGuard aGuard(s_aMutex); 385cdf0e10cSrcweir if (0 == --s_nInstanceCount) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir ::comphelper::disposeComponent(s_xStandardFormats); 388cdf0e10cSrcweir s_xStandardFormats = NULL; 389cdf0e10cSrcweir 390cdf0e10cSrcweir clearTable(FormComponentType::TIMEFIELD); 391cdf0e10cSrcweir clearTable(FormComponentType::DATEFIELD); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir //......................................................................... 396cdf0e10cSrcweir } // namespace frm 397cdf0e10cSrcweir //......................................................................... 398cdf0e10cSrcweir 399