Quellcode-Bibliothek unocontrolmodel.cxx
Sprache: C
/* -*- 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 .
*/
usingnamespace ::com::sun::star; usingnamespace ::com::sun::star::uno; usingnamespace ::com::sun::star::lang; usingnamespace ::com::sun::star::i18n; using ::com::sun::star::awt::FontDescriptor;
#define UNOCONTROL_STREAMVERSION short(2)
staticvoid lcl_ImplMergeFontProperty( FontDescriptor& rFD, sal_uInt16 nPropId, const Any& rValue )
{ // some props are defined with other types than the matching FontDescriptor members have // (e.g. FontWidth, FontSlant) // 78474 - 09/19/2000 - FS float nExtractFloat = 0;
sal_Int16 nExtractShort = 0;
switch ( nPropId )
{ case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue >>= rFD.Name; break; case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue >>= rFD.StyleName; break; case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue >>= rFD.Family; break; case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue >>= rFD.CharSet; break; case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue >>= nExtractFloat; rFD.Height = static_cast<sal_Int16>(nExtractFloat); break; case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue >>= rFD.Weight; break; case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: if ( rValue >>= nExtractShort )
rFD.Slant = static_cast<css::awt::FontSlant>(nExtractShort); else
rValue >>= rFD.Slant; break; case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue >>= rFD.Underline; break; case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue >>= rFD.Strikeout; break; case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue >>= rFD.Width; break; case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue >>= rFD.Pitch; break; case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue >>= rFD.CharacterWidth; break; case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue >>= rFD.Orientation; break; case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue >>= rFD.Kerning; break; case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue >>= rFD.WordLineMode; break; case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue >>= rFD.Type; break; default: OSL_FAIL( "FontProperty?!" );
}
}
UnoControlModel::UnoControlModel( const Reference< XComponentContext >& rxContext )
:UnoControlModel_Base()
,maDisposeListeners( *this )
,m_xContext( rxContext )
{ // Insert properties from Model into table, // only existing properties are valid, even if they're VOID
}
if (
(nPropId == BASEPROPERTY_FONTDESCRIPTOR) ||
(
(nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START) &&
(nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END)
)
)
{
EmptyFontDescriptor aFD; switch ( nPropId )
{ case BASEPROPERTY_FONTDESCRIPTOR: aDefault <<= aFD; break; case BASEPROPERTY_FONTDESCRIPTORPART_NAME: aDefault <<= aFD.Name; break; case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: aDefault <<= aFD.StyleName; break; case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: aDefault <<= aFD.Family; break; case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: aDefault <<= aFD.CharSet; break; case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: aDefault <<= static_cast<float>(aFD.Height); break; case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: aDefault <<= aFD.Weight; break; case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: aDefault <<= static_cast<sal_Int16>(aFD.Slant); break; case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: aDefault <<= aFD.Underline; break; case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: aDefault <<= aFD.Strikeout; break; case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: aDefault <<= aFD.Width; break; case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: aDefault <<= aFD.Pitch; break; case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: aDefault <<= aFD.CharacterWidth; break; case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: aDefault <<= aFD.Orientation; break; case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: aDefault <<= aFD.Kerning; break; case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: aDefault <<= aFD.WordLineMode; break; case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: aDefault <<= aFD.Type; break; default: OSL_FAIL( "FontProperty?!" );
}
} else
{ switch ( nPropId )
{ case BASEPROPERTY_GRAPHIC:
aDefault <<= Reference< graphic::XGraphic >(); break;
case BASEPROPERTY_REFERENCE_DEVICE:
aDefault <<= Reference< awt::XDevice >(); break;
case BASEPROPERTY_ITEM_SEPARATOR_POS: case BASEPROPERTY_VERTICALALIGN: case BASEPROPERTY_BORDERCOLOR: case BASEPROPERTY_SYMBOL_COLOR: case BASEPROPERTY_TABSTOP: case BASEPROPERTY_TEXTCOLOR: case BASEPROPERTY_TEXTLINECOLOR: case BASEPROPERTY_DATE: case BASEPROPERTY_DATESHOWCENTURY: case BASEPROPERTY_TIME: case BASEPROPERTY_VALUE_DOUBLE: case BASEPROPERTY_PROGRESSVALUE: case BASEPROPERTY_SCROLLVALUE: case BASEPROPERTY_VISIBLESIZE: case BASEPROPERTY_BACKGROUNDCOLOR: case BASEPROPERTY_FILLCOLOR: case BASEPROPERTY_HIGHLIGHT_COLOR: case BASEPROPERTY_HIGHLIGHT_TEXT_COLOR: break; // Void
case BASEPROPERTY_FONTRELIEF: case BASEPROPERTY_FONTEMPHASISMARK: case BASEPROPERTY_MAXTEXTLEN: case BASEPROPERTY_STATE: case BASEPROPERTY_EXTDATEFORMAT: case BASEPROPERTY_EXTTIMEFORMAT: case BASEPROPERTY_ECHOCHAR: aDefault <<= sal_Int16(0); break; case BASEPROPERTY_BORDER: aDefault <<= sal_Int16(1); break; case BASEPROPERTY_DECIMALACCURACY: aDefault <<= sal_Int16(2); break; case BASEPROPERTY_LINECOUNT: aDefault <<= sal_Int16(5); break; case BASEPROPERTY_ALIGN: aDefault <<= sal_Int16(PROPERTY_ALIGN_LEFT); break; case BASEPROPERTY_IMAGEALIGN: aDefault <<= sal_Int16(1) /*ImageAlign::Top*/; break; case BASEPROPERTY_IMAGEPOSITION: aDefault <<= sal_Int16(12) /*ImagePosition::Centered*/; break; case BASEPROPERTY_PUSHBUTTONTYPE: aDefault <<= sal_Int16(0) /*PushButtonType::STANDARD*/; break; case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:aDefault <<= sal_Int16(awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY); break;
case BASEPROPERTY_DATEMAX: aDefault <<= util::Date( 31, 12, 2200 ); break; case BASEPROPERTY_DATEMIN: aDefault <<= util::Date( 1, 1, 1900 ); break; case BASEPROPERTY_TIMEMAX: aDefault <<= util::Time(0, 0, 59, 23, false); break; case BASEPROPERTY_TIMEMIN: aDefault <<= util::Time(); break; case BASEPROPERTY_VALUEMAX_DOUBLE: aDefault <<= double(1000000); break; case BASEPROPERTY_VALUEMIN_DOUBLE: aDefault <<= double(-1000000); break; case BASEPROPERTY_VALUESTEP_DOUBLE: aDefault <<= double(1); break; case BASEPROPERTY_PROGRESSVALUE_MAX: aDefault <<= sal_Int32(100); break; case BASEPROPERTY_PROGRESSVALUE_MIN: aDefault <<= sal_Int32(0); break; case BASEPROPERTY_SCROLLVALUE_MAX: aDefault <<= sal_Int32(100); break; case BASEPROPERTY_SCROLLVALUE_MIN: aDefault <<= sal_Int32(0); break; case BASEPROPERTY_LINEINCREMENT: aDefault <<= sal_Int32(1); break; case BASEPROPERTY_BLOCKINCREMENT: aDefault <<= sal_Int32(10); break; case BASEPROPERTY_ORIENTATION: aDefault <<= sal_Int32(0); break; case BASEPROPERTY_SPINVALUE: aDefault <<= sal_Int32(0); break; case BASEPROPERTY_SPININCREMENT: aDefault <<= sal_Int32(1); break; case BASEPROPERTY_SPINVALUE_MIN: aDefault <<= sal_Int32(0); break; case BASEPROPERTY_SPINVALUE_MAX: aDefault <<= sal_Int32(100); break; case BASEPROPERTY_REPEAT_DELAY: aDefault <<= sal_Int32(50); break; // 50 milliseconds case BASEPROPERTY_DEFAULTCONTROL: aDefault <<= const_cast<UnoControlModel*>(this)->getServiceName(); break;
case BASEPROPERTY_AUTOHSCROLL: case BASEPROPERTY_AUTOVSCROLL: case BASEPROPERTY_MOVEABLE: case BASEPROPERTY_CLOSEABLE: case BASEPROPERTY_SIZEABLE: case BASEPROPERTY_HSCROLL: case BASEPROPERTY_DEFAULTBUTTON: case BASEPROPERTY_MULTILINE: case BASEPROPERTY_MULTISELECTION: case BASEPROPERTY_TRISTATE: case BASEPROPERTY_DROPDOWN: case BASEPROPERTY_SPIN: case BASEPROPERTY_READONLY: case BASEPROPERTY_VSCROLL: case BASEPROPERTY_NUMSHOWTHOUSANDSEP: case BASEPROPERTY_STRICTFORMAT: case BASEPROPERTY_REPEAT: case BASEPROPERTY_PAINTTRANSPARENT: case BASEPROPERTY_DESKTOP_AS_PARENT: case BASEPROPERTY_HARDLINEBREAKS: case BASEPROPERTY_NOLABEL: aDefault <<= false; break;
case BASEPROPERTY_MULTISELECTION_SIMPLEMODE: case BASEPROPERTY_HIDEINACTIVESELECTION: case BASEPROPERTY_ENFORCE_FORMAT: case BASEPROPERTY_AUTOCOMPLETE: case BASEPROPERTY_SCALEIMAGE: case BASEPROPERTY_ENABLED: case BASEPROPERTY_PRINTABLE: case BASEPROPERTY_ENABLEVISIBLE: case BASEPROPERTY_DECORATION: aDefault <<= true; break;
case BASEPROPERTY_GROUPNAME: case BASEPROPERTY_HELPTEXT: case BASEPROPERTY_HELPURL: case BASEPROPERTY_IMAGEURL: case BASEPROPERTY_DIALOGSOURCEURL: case BASEPROPERTY_EDITMASK: case BASEPROPERTY_LITERALMASK: case BASEPROPERTY_LABEL: case BASEPROPERTY_TITLE: case BASEPROPERTY_TEXT: aDefault <<= OUString(); break;
case BASEPROPERTY_WRITING_MODE: case BASEPROPERTY_CONTEXT_WRITING_MODE:
aDefault <<= text::WritingMode2::CONTEXT; break;
case BASEPROPERTY_STRINGITEMLIST:
{
css::uno::Sequence< OUString> aStringSeq;
aDefault <<= aStringSeq;
} break; case BASEPROPERTY_SELECTEDITEMS:
{
css::uno::Sequence<sal_Int16> aINT16Seq;
aDefault <<= aINT16Seq;
} break; case BASEPROPERTY_CURRENCYSYMBOL:
{
OUString sDefaultCurrency(
utl::ConfigManager::getDefaultCurrency() );
// extract the bank symbol
sal_Int32 nSepPos = sDefaultCurrency.indexOf( '-' );
OUString sBankSymbol; if ( nSepPos >= 0 )
{
sBankSymbol = sDefaultCurrency.copy( 0, nSepPos );
sDefaultCurrency = sDefaultCurrency.copy( nSepPos + 1 );
}
// the remaining is the locale const LocaleDataWrapper* pLocaleInfo = LocaleDataWrapper::get( LanguageTag(sDefaultCurrency) ); if ( sBankSymbol.isEmpty() )
sBankSymbol = pLocaleInfo->getCurrBankSymbol();
// look for the currency entry (for this language) which has the given bank symbol const Sequence< Currency2 > aAllCurrencies = pLocaleInfo->getAllCurrencies();
OUString sCurrencySymbol = pLocaleInfo->getCurrSymbol(); if ( sBankSymbol.isEmpty() )
{
DBG_ASSERT( aAllCurrencies.hasElements(), "UnoControlModel::ImplGetDefaultValue: no currencies at all!" ); if ( aAllCurrencies.hasElements() )
{
sBankSymbol = aAllCurrencies[0].BankSymbol;
sCurrencySymbol = aAllCurrencies[0].Symbol;
}
}
if ( !sBankSymbol.isEmpty() )
{ bool bLegacy = false; bool bFound = false; for ( const Currency2& rCurrency : aAllCurrencies ) if ( rCurrency.BankSymbol == sBankSymbol )
{
sCurrencySymbol = rCurrency.Symbol; if ( rCurrency.LegacyOnly )
bLegacy = true; else
{
bFound = true; break;
}
}
DBG_ASSERT( bLegacy || bFound, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" );
}
if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
{ // some properties are not included in the FontDescriptor, but every time // when we have a FontDescriptor we want to have these properties too. // => Easier to register the here, instead everywhere where I register the FontDescriptor...
// Unfortunately, there's no mark for the whole block, thus only properties may be changed. // No data for the model may be added following the properties
// Used for import of old parts in css::awt::FontDescriptor
std::unique_ptr<css::awt::FontDescriptor> pFD;
for ( sal_uInt32 i = 0; i < nProps; i++ )
{
sal_Int32 nPropDataBeginMark = xMark->createMark();
sal_Int32 nPropDataLen = InStream->readLong();
// Skip rest of input if there is more data in stream than this version can handle
xMark->jumpToMark( nPropDataBeginMark );
InStream->skipBytes( nPropDataLen );
xMark->deleteMark(nPropDataBeginMark);
} if ( bInvalidEntries )
{ for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
{ if ( aProps.getConstArray()[i].isEmpty() )
{
::comphelper::removeElementAt( aProps, i );
::comphelper::removeElementAt( aValues, i );
i--;
}
}
}
switch (pDestType->getTypeClass())
{ case TypeClass_DOUBLE:
{ // try as double double nAsDouble = 0;
bConverted = ( rValue >>= nAsDouble ); if ( bConverted )
rConvertedValue <<= nAsDouble; else
{ // try as integer
sal_Int32 nAsInteger = 0;
bConverted = ( rValue >>= nAsInteger ); if ( bConverted )
rConvertedValue <<= static_cast<double>(nAsInteger);
}
} break; case TypeClass_SHORT:
{
sal_Int16 n;
bConverted = ( rValue >>= n ); if ( bConverted )
rConvertedValue <<= n;
} break; case TypeClass_UNSIGNED_SHORT:
{
sal_uInt16 n;
bConverted = ( rValue >>= n ); if ( bConverted )
rConvertedValue <<= n;
} break; case TypeClass_LONG:
{
sal_Int32 n;
bConverted = ( rValue >>= n ); if ( bConverted )
rConvertedValue <<= n;
} break; case TypeClass_UNSIGNED_LONG:
{
sal_uInt32 n;
bConverted = ( rValue >>= n ); if ( bConverted )
rConvertedValue <<= n;
} break; case TypeClass_INTERFACE:
{ if ( rValue.getValueTypeClass() == TypeClass_INTERFACE )
{
Reference< XInterface > xPure( rValue, UNO_QUERY ); if ( xPure.is() )
rConvertedValue = xPure->queryInterface( *pDestType ); else
rConvertedValue.setValue( nullptr, *pDestType );
bConverted = true;
}
} break; case TypeClass_ENUM:
{
sal_Int32 nValue = 0;
bConverted = ( rValue >>= nValue ); if ( bConverted )
rConvertedValue = ::cppu::int2enum( nValue, *pDestType );
} break; default: ; // avoid compiler warning
}
if (!bConverted)
{ throw css::lang::IllegalArgumentException( "Unable to convert the given value for the property "
+ GetPropertyName( static_cast<sal_uInt16>(nPropId) )
+ ".\nExpected type: " + pDestType->getTypeName()
+ "\nFound type: " + rValue.getValueTypeName(), static_cast< css::beans::XPropertySet* >(this),
1);
}
}
}
}
// the current value
getFastPropertyValue( rGuard, rOldValue, nPropId ); return !CompareProperties( rConvertedValue, rOldValue );
}
void UnoControlModel::setFastPropertyValue_NoBroadcast( std::unique_lock<std::mutex>& /*rGuard*/, sal_Int32 nPropId, const css::uno::Any& rValue )
{ // Missing: the fake solo properties of the FontDescriptor
Any aNewValue;
aNewValue <<= aFontDescriptor;
sal_Int32 nDescriptorId = BASEPROPERTY_FONTDESCRIPTOR;
// also, we need fire a propertyChange event for the single property, since with // the above line, only an event for the FontDescriptor property will be fired
Any aNewSingleValue;
getFastPropertyValue( rGuard, aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
// sal_Int32* pHandles = new sal_Int32[nProps]; // don't do this - it leaks in case of an exception
Sequence< sal_Int32 > aHandles( nProps );
sal_Int32* pHandles = aHandles.getArray();
// may need to change the order in the sequence, for this we need a non-const value sequence
uno::Sequence< uno::Any > aValues( Values );
uno::Any* pValues = aValues.getArray();
// Don't merge FD property into array, as it is sorted if (pFD)
{
css::uno::Any aValue;
aValue <<= *pFD;
sal_Int32 nHandle = BASEPROPERTY_FONTDESCRIPTOR;
setFastPropertyValues( rGuard, 1, &nHandle, &aValue, 1 );
}
}
void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32, sal_Int32*,
uno::Any*, sal_Int32* ) const
{ // nothing to do here
}
void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount, sal_Int32* _pHandles,
uno::Any* _pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle )
{ for ( sal_Int32 i=0; i < _nCount; ++_pHandles, ++_pValues, ++i )
{ if ( _nSecondHandle == *_pHandles )
{
sal_Int32* pLaterHandles = _pHandles + 1;
uno::Any* pLaterValues = _pValues + 1; for ( sal_Int32 j = i + 1; j < _nCount; ++j, ++pLaterHandles, ++pLaterValues )
{ if ( _nFirstHandle == *pLaterHandles )
{ // indeed it is -> exchange the both places in the sequences
std::swap(*_pHandles, *pLaterHandles);
std::swap(*_pValues, *pLaterValues); break; // this will leave the inner loop, and continue with the outer loop. // Note that this means we will encounter the _nSecondHandle handle, again, once we reached // (in the outer loop) the place where we just put it.
}
}
}
}
}
¤ 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.0.22Bemerkung:
(vorverarbeitet)
¤
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.