21#include <helper/property.hxx>
23#include <com/sun/star/awt/XVclWindowPeer.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
25#include <com/sun/star/util/NumberFormatter.hpp>
26#include <com/sun/star/util/NumberFormatsSupplier.hpp>
30#include <osl/diagnose.h>
49 std::mutex& getDefaultFormatsMutex()
51 static std::mutex s_aDefaultFormatsMutex;
52 return s_aDefaultFormatsMutex;
55 Reference< XNumberFormatsSupplier > s_xDefaultFormats;
56 bool s_bTriedCreation =
false;
57 oslInterlockedCount s_refCount(0);
59 const Reference< XNumberFormatsSupplier >& lcl_getDefaultFormats_throw()
61 std::scoped_lock aGuard( getDefaultFormatsMutex() );
63 if ( !s_xDefaultFormats.is() && !s_bTriedCreation )
65 s_bTriedCreation =
true;
66 s_xDefaultFormats = NumberFormatsSupplier::createWithDefaultLocale( ::comphelper::getProcessComponentContext() );
68 if ( !s_xDefaultFormats.is() )
71 return s_xDefaultFormats;
74 void lcl_registerDefaultFormatsClient()
76 osl_atomic_increment( &s_refCount );
79 void lcl_revokeDefaultFormatsClient()
81 Reference< XNumberFormatsSupplier > xReleasePotentialLastReference;
83 std::scoped_lock aGuard( getDefaultFormatsMutex() );
84 if ( 0 != osl_atomic_decrement( &s_refCount ) )
87 xReleasePotentialLastReference = std::move(s_xDefaultFormats);
88 s_bTriedCreation =
false;
90 xReleasePotentialLastReference.clear();
100 ,m_bRevokedAsClient( false )
101 ,m_bSettingValueAndText( false )
139 aTreatAsNumber <<=
true;
142 lcl_registerDefaultFormatsClient();
146 UnoControlFormattedFieldModel::~UnoControlFormattedFieldModel()
151 OUString UnoControlFormattedFieldModel::getServiceName()
153 return "stardiv.vcl.controlmodel.FormattedField";
157 void UnoControlFormattedFieldModel::setFastPropertyValue_NoBroadcast( std::unique_lock<std::mutex>& rGuard, sal_Int32 nHandle,
const Any& rValue )
164 if ( !m_bSettingValueAndText )
165 impl_updateTextFromValue_nothrow(rGuard);
168 impl_updateCachedFormatter_nothrow(rGuard);
169 impl_updateTextFromValue_nothrow(rGuard);
172 impl_updateCachedFormatKey_nothrow(rGuard);
173 impl_updateTextFromValue_nothrow(rGuard);
179 void UnoControlFormattedFieldModel::impl_updateTextFromValue_nothrow( std::unique_lock<std::mutex>& rGuard)
181 if ( !m_xCachedFormatter.is() )
182 impl_updateCachedFormatter_nothrow(rGuard);
183 if ( !m_xCachedFormatter.is() )
191 OUString sStringValue;
192 if ( !( aEffectiveValue >>= sStringValue ) )
194 double nDoubleValue(0);
195 if ( aEffectiveValue >>= nDoubleValue )
197 sal_Int32 nFormatKey( 0 );
198 if ( m_aCachedFormat.hasValue() )
199 m_aCachedFormat >>= nFormatKey;
200 sStringValue = m_xCachedFormatter->convertNumberToString( nFormatKey, nDoubleValue );
213 void UnoControlFormattedFieldModel::impl_updateCachedFormatter_nothrow(std::unique_lock<std::mutex>& rGuard)
215 Any aFormatsSupplier;
219 Reference< XNumberFormatsSupplier > xSupplier( aFormatsSupplier, UNO_QUERY );
220 if ( !xSupplier.is() )
221 xSupplier = lcl_getDefaultFormats_throw();
223 if ( !m_xCachedFormatter.is() )
225 m_xCachedFormatter.set(
226 NumberFormatter::create(::comphelper::getProcessComponentContext()),
230 m_xCachedFormatter->attachNumberFormatsSupplier( xSupplier );
239 void UnoControlFormattedFieldModel::impl_updateCachedFormatKey_nothrow(std::unique_lock<std::mutex>& rGuard)
243 m_aCachedFormat = aFormatKey;
247 void UnoControlFormattedFieldModel::dispose( )
251 std::unique_lock aGuard(
m_aMutex );
252 if ( !m_bRevokedAsClient )
254 lcl_revokeDefaultFormatsClient();
255 m_bRevokedAsClient =
true;
260 void UnoControlFormattedFieldModel::ImplNormalizePropertySequence(
const sal_Int32 _nCount, sal_Int32* _pHandles,
261 Any* _pValues, sal_Int32* _pValidHandles )
const
271 class ResetFlagOnExit
277 explicit ResetFlagOnExit(
bool& _rFlag )
289 void SAL_CALL UnoControlFormattedFieldModel::setPropertyValues(
const Sequence< OUString >& _rPropertyNames,
const Sequence< Any >& _rValues )
291 bool bSettingValue =
false;
292 bool bSettingText =
false;
293 for (
auto const & propertyName : _rPropertyNames )
296 bSettingValue =
true;
302 m_bSettingValueAndText = ( bSettingValue && bSettingText );
303 ResetFlagOnExit aResetFlag( m_bSettingValueAndText );
308 bool UnoControlFormattedFieldModel::convertFastPropertyValue(
309 std::unique_lock<std::mutex>& rGuard,
310 Any& rConvertedValue, Any& rOldValue, sal_Int32 nPropId,
316 bool bStreamed = (rValue >>= dVal);
319 rConvertedValue <<= dVal;
324 bStreamed = (rValue >>= nVal);
327 rConvertedValue <<= static_cast<double>(nVal);
332 bStreamed = (rValue >>= sVal);
335 rConvertedValue <<= sVal;
342 getFastPropertyValue( rGuard, rOldValue, nPropId );
346 throw IllegalArgumentException(
347 (
"Unable to convert the given value for the property "
349 +
" (double, integer, or string expected)."),
358 Any UnoControlFormattedFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId )
const
391 Reference< XPropertySetInfo > UnoControlFormattedFieldModel::getPropertySetInfo( )
393 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
397 OUString UnoControlFormattedFieldModel::getImplementationName()
399 return "stardiv.Toolkit.UnoControlFormattedFieldModel";
402 css::uno::Sequence<OUString>
403 UnoControlFormattedFieldModel::getSupportedServiceNames()
406 s.realloc(s.getLength() + 2);
407 auto ps = s.getArray();
408 ps[s.getLength() - 2] =
"com.sun.star.awt.UnoControlFormattedFieldModel";
409 ps[s.getLength() - 1] =
"stardiv.vcl.controlmodel.FormattedField";
416 UnoFormattedFieldControl::UnoFormattedFieldControl()
421 OUString UnoFormattedFieldControl::GetComponentServiceName()
const
423 return "FormattedField";
429 Reference< XVclWindowPeer > xPeer(getPeer(), UNO_QUERY);
430 OSL_ENSURE(xPeer.is(),
"UnoFormattedFieldControl::textChanged : what kind of peer do I have ?");
435 Sequence< Any > aValues{ xPeer->getProperty( aNames[0] ),
436 xPeer->getProperty( aNames[1] ) };
438 ImplSetPropertyValues( aNames, aValues,
false );
441 GetTextListeners().textChanged( e );
444 OUString UnoFormattedFieldControl::getImplementationName()
446 return "stardiv.Toolkit.UnoFormattedFieldControl";
449 css::uno::Sequence<OUString>
450 UnoFormattedFieldControl::getSupportedServiceNames()
452 auto s(UnoEditControl::getSupportedServiceNames());
453 s.realloc(s.getLength() + 2);
454 auto ps = s.getArray();
455 ps[s.getLength() - 2] =
"com.sun.star.awt.UnoControlFormattedField";
456 ps[s.getLength() - 1] =
"stardiv.vcl.control.FormattedField";
462extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
464 css::uno::XComponentContext *context,
465 css::uno::Sequence<css::uno::Any>
const &)
470extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
472 css::uno::XComponentContext *,
473 css::uno::Sequence<css::uno::Any>
const &)
void SAL_CALL dispose() override
void setFastPropertyValue_NoBroadcast(std::unique_lock< std::mutex > &rGuard, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const
void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Sequence< css::uno::Any > &Values) override
virtual void ImplNormalizePropertySequence(const sal_Int32 _nCount, sal_Int32 *_pHandles, css::uno::Any *_pValues, sal_Int32 *_pValidHandles) const
called before setting multiple properties, allows to care for property dependencies
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool convertFastPropertyValue(std::unique_lock< std::mutex > &rGuard, css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
#define DBG_UNHANDLED_EXCEPTION(...)
DECL_LISTENERMULTIPLEXER_END void SAL_CALL textChanged(const css::awt::TextEvent &rEvent) override
double getLength(const B2DPolygon &rCandidate)
class SAL_NO_VTABLE XPropertySet
bool CompareProperties(const css::uno::Any &r1, const css::uno::Any &r2)
const OUString & GetPropertyName(sal_uInt16 nPropertyId)
sal_uInt16 GetPropertyId(const OUString &rPropertyName)
#define BASEPROPERTY_BORDER
#define BASEPROPERTY_SPIN
#define BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR
#define BASEPROPERTY_HIDEINACTIVESELECTION
#define BASEPROPERTY_ENFORCE_FORMAT
#define BASEPROPERTY_CONTEXT_WRITING_MODE
#define BASEPROPERTY_HIGHLIGHT_COLOR
#define BASEPROPERTY_TEXT
#define BASEPROPERTY_READONLY
#define BASEPROPERTY_ALIGN
#define BASEPROPERTY_EFFECTIVE_MAX
#define BASEPROPERTY_HELPURL
#define BASEPROPERTY_REPEAT
#define BASEPROPERTY_BACKGROUNDCOLOR
#define BASEPROPERTY_FORMATKEY
#define BASEPROPERTY_TABSTOP
#define BASEPROPERTY_ENABLED
#define BASEPROPERTY_STRICTFORMAT
#define BASEPROPERTY_DEFAULTCONTROL
#define BASEPROPERTY_VERTICALALIGN
#define BASEPROPERTY_WRITING_MODE
#define BASEPROPERTY_HIGHLIGHT_TEXT_COLOR
#define BASEPROPERTY_EFFECTIVE_DEFAULT
#define BASEPROPERTY_BORDERCOLOR
#define BASEPROPERTY_FONTDESCRIPTOR
#define BASEPROPERTY_FORMATSSUPPLIER
#define BASEPROPERTY_MAXTEXTLEN
#define BASEPROPERTY_ENABLEVISIBLE
#define BASEPROPERTY_HELPTEXT
#define BASEPROPERTY_EFFECTIVE_VALUE
#define BASEPROPERTY_EFFECTIVE_MIN
#define BASEPROPERTY_REPEAT_DELAY
#define BASEPROPERTY_TEXTCOLOR
#define BASEPROPERTY_PRINTABLE
#define BASEPROPERTY_TREATASNUMBER