diff options
author | Kurt Zenker <kz@openoffice.org> | 2008-03-06 10:47:20 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2008-03-06 10:47:20 +0000 |
commit | e17ddba9755523f757f624e58fdbc86fe3c07844 (patch) | |
tree | 64ea8207bd562be30521fd0495cca4d6cc0b9b7d /toolkit | |
parent | c4a9531d2dfaaca9a7b664b2a75233738808c45b (diff) |
INTEGRATION: CWS layout_DEV300 (1.1.2); FILE ADDED
2008/02/12 11:05:46 jcn 1.1.2.2: Annotate classes with TOOLKIT_DLLPUBLIC.
Remove -fvisibility=default, -fno-visibility-inlines-hidden hack.
2008/02/08 18:44:44 jcn 1.1.2.1: Initial toolkit import from ee9a2fcc29d7e2f01cc80ef7c13bf7bc7d55ae7e.
layout/source/awt -> toolkit/source/awt
layout/source/core -> toolkit/source/layout
layout/source/wrapper -> toolkit/source/vclcompat
layout/inc/layout -> toolkit/inc/layout
layout/source/inc -> toolkit/inc/layout
layout/workben -> toolkit/workben/layout
That's ooo-build trunk r11539 @ ooh680-m5/src680-m245.
Diffstat (limited to 'toolkit')
-rw-r--r-- | toolkit/source/layout/factory.hxx | 47 | ||||
-rw-r--r-- | toolkit/source/layout/helper.hxx | 123 | ||||
-rw-r--r-- | toolkit/source/layout/proplist.cxx | 423 |
3 files changed, 593 insertions, 0 deletions
diff --git a/toolkit/source/layout/factory.hxx b/toolkit/source/layout/factory.hxx new file mode 100644 index 000000000000..927486984e26 --- /dev/null +++ b/toolkit/source/layout/factory.hxx @@ -0,0 +1,47 @@ +#ifndef FACTORY_HXX_ +#define FACTORY_HXX_ + +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase2.hxx> +#include <toolkit/dllapi.h> + +namespace layoutimpl +{ +class Layout; +} + +class TOOLKIT_DLLPUBLIC LayoutFactory : public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XSingleServiceFactory, + ::com::sun::star::lang::XServiceInfo > +{ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; + +public: + LayoutFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ) + : m_xFactory( xFactory ) + { + OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" ); + } + + static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + impl_staticGetSupportedServiceNames(); + + static ::rtl::OUString SAL_CALL impl_staticGetImplementationName(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + impl_staticCreateSelfInstance( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ); + + + // XSingleServiceFactory + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException); + +}; + +#endif /* FACTORY_HXX */ diff --git a/toolkit/source/layout/helper.hxx b/toolkit/source/layout/helper.hxx new file mode 100644 index 000000000000..e8e958123512 --- /dev/null +++ b/toolkit/source/layout/helper.hxx @@ -0,0 +1,123 @@ +#ifndef HELPER_HXX +#define HELPER_HXX + +#include <toolkit/dllapi.h> +#include <vector> + +#include <com/sun/star/awt/XLayoutConstrains.hpp> +#include <com/sun/star/awt/XLayoutContainer.hpp> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <com/sun/star/xml/input/XRoot.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/propshlp.hxx> +#include <rtl/ustring.hxx> + +namespace layoutimpl +{ + +namespace css = ::com::sun::star; + +/* ChildProps -- a helper to set child properties for the XLayoutContainer interface. */ + +class LockHelper +{ +public: + osl::Mutex maGuard; + cppu::OBroadcastHelper maBrdcstHelper; + LockHelper() : maBrdcstHelper( maGuard ) + { + } +}; + +class PropHelper : public LockHelper + , public cppu::OPropertySetHelper + , public cppu::OWeakObject +{ + cppu::OPropertyArrayHelper *pHelper; + + struct PropDetails + { + rtl::OUString aName; + css::uno::Type aType; + void *pValue; + }; + std::vector< PropDetails > maDetails; + +protected: + void addProp( char const *pName, sal_Int32 nNameLen, rtl_TextEncoding e, + css::uno::Type aType, void *pPtr ); + +public: + PropHelper(); + + // com::sun::star::uno::XInterface + void SAL_CALL acquire() throw() { OWeakObject::acquire(); } + void SAL_CALL release() throw() { OWeakObject::release(); } + ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); + + // cppu::OPropertySetHelper + virtual cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any &, + css::uno::Any &, sal_Int32 nHandle, const css::uno::Any & ) + throw(css::lang::IllegalArgumentException); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, + const css::uno::Any& rValue ) throw (css::uno::Exception); + virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue, + sal_Int32 nHandle ) const; + + // you -must- use this macro in sub-classes that define new properties. + // NB. 'static' ... + // com::sun::star::beans::XMultiPropertySet +#define PROPHELPER_SET_INFO \ + css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL \ + getPropertySetInfo() throw(css::uno::RuntimeException) \ + { \ + static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( \ + createPropertySetInfo( getInfoHelper() ) ); \ + return xInfo; \ + } + PROPHELPER_SET_INFO + + struct Listener + { + virtual void propertiesChanged() = 0; + }; + void setChangeListener( Listener *pListener ) + { + mpListener = pListener; + } + +protected: + Listener *mpListener; +}; + +css::uno::Any anyFromString (const rtl::OUString &value, const css::uno::Type &type); + +// The native widgets wrapper hierarchy may not reflect that of the layout +// hierarchy as some containers don't have an associated native widget. +// Use this function to get the native parent of the given peer. +css::uno::Reference< css::awt::XWindowPeer > +getParent( css::uno::Reference< css::uno::XInterface > xPeer ); + + +struct WidgetFactory +{ + virtual css::uno::Reference< css::awt::XLayoutConstrains > + createWidget( css::uno::Reference< css::awt::XToolkit > xToolkit, + css::uno::Reference< css::uno::XInterface > xParent, + const rtl::OUString &rName, long nProps ); +}; + +// A local factory method - should use UNO services in due course +css::uno::Reference< css::awt::XLayoutConstrains > TOOLKIT_DLLPUBLIC +createWidget( css::uno::Reference< css::awt::XToolkit > xToolkit, + css::uno::Reference< css::uno::XInterface > xParent, + const rtl::OUString &rName, long nProps ); + +// Factory for containers (not visible ones) +css::uno::Reference< css::awt::XLayoutContainer > +createContainer( const rtl::OUString &rName ); + +} // namespace layoutimpl + +#endif /* HELPER_HXX */ diff --git a/toolkit/source/layout/proplist.cxx b/toolkit/source/layout/proplist.cxx new file mode 100644 index 000000000000..dca325bd09bc --- /dev/null +++ b/toolkit/source/layout/proplist.cxx @@ -0,0 +1,423 @@ +#include "proplist.hxx" + +#include <rtl/ustrbuf.hxx> +#include <toolkit/dllapi.h> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <com/sun/star/awt/VclWindowPeerAttribute.hpp> +#include <tools/debug.hxx> + +#if TEST_LAYOUT && !defined( DBG_UTIL ) +#include <stdio.h> +#undef DBG_ERROR +#define DBG_ERROR printf +#undef DBG_ERROR1 +#define DBG_ERROR1 printf +#undef DBG_ERROR2 +#define DBG_ERROR2 printf +#endif /* TEST_LAYOUT && !DBG_UTIL */ + +namespace layoutimpl +{ + +using namespace com::sun::star; +using rtl::OString; +using rtl::OUString; +using rtl::OUStringBuffer; + +namespace prophlp +{ + +bool TOOLKIT_DLLPUBLIC +canHandleProps( const uno::Reference< uno::XInterface > &xPeer ) +{ + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + if ( xPropSet.is() ) + return true; + uno::Reference< beans::XPropertySetInfo > xInfo( xPeer, uno::UNO_QUERY ); + uno::Reference< awt::XVclWindowPeer> xVclPeer( xPeer, uno::UNO_QUERY ); + return xInfo.is() && xVclPeer.is(); +} + +uno::Reference< beans::XPropertySetInfo > TOOLKIT_DLLPUBLIC +queryPropertyInfo( + const uno::Reference< uno::XInterface > &xPeer ) +{ + uno::Reference< beans::XPropertySetInfo > xInfo( xPeer, uno::UNO_QUERY ); + if ( !xInfo.is() ) + { + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + if ( xPropSet.is() ) + xInfo = xPropSet->getPropertySetInfo(); + } + return xInfo; +} + +void TOOLKIT_DLLPUBLIC +setProperty( const uno::Reference< uno::XInterface > &xPeer, + const OUString &rName, uno::Any aValue ) +{ + uno::Reference< awt::XVclWindowPeer> xVclPeer( xPeer, uno::UNO_QUERY ); + if ( xVclPeer.is() ) + xVclPeer->setProperty( rName, aValue ); + else + { + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + xPropSet->setPropertyValue( rName, aValue ); + } +} + +uno::Any TOOLKIT_DLLPUBLIC +getProperty( const uno::Reference< uno::XInterface > &xPeer, + const OUString &rName ) +{ + uno::Reference< awt::XVclWindowPeer> xVclPeer( xPeer, uno::UNO_QUERY ); + if ( xVclPeer.is() ) + return xVclPeer->getProperty( rName ); + + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + return xPropSet->getPropertyValue( rName ); +} + +} // namespace prophlp + + +/* Given a string and a type, it converts the string to the type, and returns + it encapsulated in Any. */ +uno::Any anyFromString( const OUString &value, const uno::Type &type ) +{ + switch ( type.getTypeClass() ) + { + case uno::TypeClass_CHAR: + return uno::makeAny( value.toChar() ); + case uno::TypeClass_BOOLEAN: + if ( value == OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) ) + return uno::makeAny( true ); + else if ( value == OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) ) + return uno::makeAny( false ); + break; // ends switch, throws exception + case uno::TypeClass_BYTE: + return uno::makeAny( ( sal_uInt8 ) value.toInt32() ); + case uno::TypeClass_SHORT: + return uno::makeAny( ( sal_Int16 ) value.toInt32() ); + case uno::TypeClass_UNSIGNED_SHORT: + return uno::makeAny( ( sal_uInt16 ) value.toInt32() ); + case uno::TypeClass_ENUM: + return uno::makeAny( ( sal_Int16 ) value.toInt32() ); + case uno::TypeClass_LONG: + return uno::makeAny( ( sal_Int32 ) value.toInt32() ); + case uno::TypeClass_UNSIGNED_LONG: + return uno::makeAny( ( sal_uInt32 ) value.toInt32() ); + case uno::TypeClass_HYPER: + return uno::makeAny( ( sal_Int64 ) value.toInt64() ); + case uno::TypeClass_UNSIGNED_HYPER: + return uno::makeAny( ( sal_uInt16 ) value.toInt64() ); + case uno::TypeClass_FLOAT: + return uno::makeAny( value.toFloat() ); + case uno::TypeClass_DOUBLE: + return uno::makeAny( value.toDouble() ); + case uno::TypeClass_STRING: + return uno::makeAny( value ); + case uno::TypeClass_CONSTANT: + if ( value.getLength() > 2 && value[0] == '0' && value[1] == 'x' ) + return uno::makeAny( value.copy( 2 ).toInt32( 16 ) ); + return uno::makeAny( value.toInt32() ); + case uno::TypeClass_SEQUENCE: + { + sal_Int32 i = 0; + bool escaped = false, first = true; + OUString item, token; + std::list< OUString > values; + do + { + token = value.getToken( 0, ':', i ); + + if ( !token.getLength() && !escaped ) + { + escaped = true; + item += OUString( ':' ); + } + else if ( escaped ) + { + escaped = false; + item += token; + } + else + { + if ( !first ) + values.push_back( item ); + item = token; + } + first = false; + } + while ( i >= 0 ); + if ( item.getLength() ) + values.push_back( item ); + + uno::Sequence< OUString > seq( values.size() ); + i = 0; + for( std::list< OUString >::const_iterator it = values.begin(); + it != values.end(); it++, i++ ) + seq[ i ] = *it; + + return uno::makeAny( seq ); + } + break; + + default: + DBG_ERROR1( "ERROR: unknown property type of value: `%s'", OUSTRING_CSTR( value ) ); + break; + } + throw uno::RuntimeException(); +} + +/* Converts the XML naming scheme to UNO's, for legacy compatibility + (so, ergo, "one-two-three-four" -> "OneTwoThreeFour"). */ +static OUString toUnoNaming ( OUString const &string ) +{ + OUStringBuffer buffer( string.getLength() ); + sal_Unicode *str = string.pData->buffer; + bool capitalize = true; + + for ( int i = 0; i < string.getLength(); i++ ) + { + if ( i == 0 && str[0] == '_' ) + /* Skip translate-me prefix. */ + continue; + if ( str[i] == '-' ) + capitalize = true; + else + { + if ( capitalize && str[i] >= 'a' && str[i] <= 'z' ) + buffer.append( (sal_Unicode ) ( str[i] - 'a' + 'A' ) ); + else + buffer.append( (sal_Unicode ) str[i] ); + capitalize = false; + } + } + + return buffer.makeStringAndClear(); +} + +/* + * convert incoming XML style property names, to AWT style property names. + * convert the values based on introspection information. + * apply to either an XPropertySet or an XPropertySetInfo | XVclWindowPeer + * aggregate. + */ +void +setProperties( uno::Reference< uno::XInterface > const& xPeer, + PropList const& rProps ) +{ + if ( !prophlp::canHandleProps( xPeer ) ) + { + DBG_ERROR( "Error: setProperties - bad handle ignoring props:" ); + PropList::const_iterator cur; + for( cur = rProps.begin(); cur != rProps.end(); cur++ ) + { + OString attr = OUStringToOString( cur->first, RTL_TEXTENCODING_UTF8 ); + OString value = OUStringToOString( cur->second, RTL_TEXTENCODING_UTF8 ); + } + return; + } + + PropList::const_iterator cur; + for( cur = rProps.begin(); cur != rProps.end(); cur++ ) + setProperty( xPeer, cur->first, cur->second ); +} + +void +setProperty( uno::Reference< uno::XInterface > const& xPeer, + OUString const& attr, OUString const& value ) +{ + OUString unoAttr = toUnoNaming( attr ); + + // get a Property object + beans::Property prop; + try + { + uno::Reference< beans::XPropertySetInfo > xInfo + = prophlp::queryPropertyInfo( xPeer ); + prop = xInfo->getPropertyByName( unoAttr ); + } + catch( beans::UnknownPropertyException &ex ) + { + DBG_ERROR1( "Warning: unknown attribute: `%s'", OUSTRING_CSTR( unoAttr ) ); + return; + } + + if ( prop.Name.getLength() <= 0 ) + { + DBG_ERROR1( "Warning: missing prop: `%s'", OUSTRING_CSTR( unoAttr ) ); + return; + } + + // encapsulates value in an uno::Any + uno::Any any; + try + { + any = anyFromString( value, prop.Type ); + } + catch( uno::RuntimeException &ex ) + { + DBG_ERROR5( "Warning: %s( %s )( %s ) attribute is of type %s( rejected: %s )", OUSTRING_CSTR( unoAttr ), OUSTRING_CSTR( value ), OUSTRING_CSTR( prop.Name ), OUSTRING_CSTR( prop.Type.getTypeName() ), OUSTRING_CSTR( value ) ); + return; + } + + // sets value on property + try + { + prophlp::setProperty( xPeer, unoAttr, any ); + } + catch( ... ) + { + DBG_ERROR2( "Warning: cannot set attribute %s to %s ", OUSTRING_CSTR( unoAttr ), OUSTRING_CSTR( value ) ); + } +} + + + + +struct AttributesMap +{ + const char *name; + long value; + bool windowAttr; +}; +static const AttributesMap attribsMap[] = +{ + { "autohscroll", awt::VclWindowPeerAttribute::AUTOHSCROLL, false }, + { "autovscroll", awt::VclWindowPeerAttribute::AUTOVSCROLL, false }, + { "center", awt::VclWindowPeerAttribute::CENTER, false }, + { "clipchildren", awt::VclWindowPeerAttribute::CLIPCHILDREN, false }, + { "closeable", awt::WindowAttribute::CLOSEABLE, true }, + { "defbutton", awt::VclWindowPeerAttribute::DEFBUTTON, false }, + { "dropdown", awt::VclWindowPeerAttribute::DROPDOWN, false }, + { "fullsize", awt::WindowAttribute::FULLSIZE, true }, //FIXME? + { "group", awt::VclWindowPeerAttribute::GROUP, false }, + { "has_border", awt::WindowAttribute::BORDER, true }, + { "hscroll", awt::VclWindowPeerAttribute::HSCROLL, false }, + { "left", awt::VclWindowPeerAttribute::LEFT, false }, + { "moveable", awt::WindowAttribute::MOVEABLE, true }, + { "noborder", awt::VclWindowPeerAttribute::NOBORDER, false }, +// Comment-out for <= m237 +// { "nolabel", awt::VclWindowPeerAttribute::NOLABEL, false }, + { "optimumsize", awt::WindowAttribute::OPTIMUMSIZE, false }, + { "readonly", awt::VclWindowPeerAttribute::READONLY, false }, + { "right", awt::VclWindowPeerAttribute::RIGHT, false }, + { "show", awt::WindowAttribute::SHOW, true }, + { "sizeable", awt::WindowAttribute::SIZEABLE, true }, + { "sort", awt::VclWindowPeerAttribute::SORT, false }, + { "spin", awt::VclWindowPeerAttribute::SPIN, false }, + { "vscroll", awt::VclWindowPeerAttribute::VSCROLL, false }, + + // cutting on OK, YES_NO_CANCEL and related obscure attributes... +}; +static const int attribsMapLen = sizeof( attribsMap ) / sizeof( AttributesMap ); + +#if 0 +long getAttribute( const OUString &rName, bool bTopWindow ) +{ + + int min = 0, max = attribsMapLen - 1, mid, cmp; + do + { + mid = min +( max - min )/2; + cmp = rName.compareToAscii( attribsMap[ mid ].name ); + if ( cmp > 0 ) + min = mid+1; + else if ( cmp < 0 ) + max = mid-1; + else + { + if ( bTopWindow || attribsMap[ mid ].value ) + return attribsMap[ mid ].windowAttr; + return 0; + } + } + while ( min <= max ); + return 0; +} +#endif + +void propsFromAttributes( const uno::Reference<xml::input::XAttributes> & xAttributes, + PropList &rProps, sal_Int32 nNamespace ) +{ + + + sal_Int32 nAttrs = xAttributes->getLength(); + for( sal_Int32 i = 0; i < nAttrs; i++ ) + { + if ( nNamespace != xAttributes->getUidByIndex( i ) ) + continue; + + std::pair< OUString, OUString > aElem + ( xAttributes->getLocalNameByIndex( i ), + xAttributes->getValueByIndex( i ) ); + + if ( aElem.first.getLength() > 0 ) // namespace bits .. + rProps.push_back( aElem ); + } +} + +bool +findAndRemove( const char *pAttr, PropList &rProps, OUString &rValue ) +{ + PropList::iterator cur; + OUString aName = OUString::createFromAscii( pAttr ); + + for( cur = rProps.begin(); cur != rProps.end(); cur++ ) + { + if ( cur->first.equalsIgnoreAsciiCase( aName ) ) + { + rValue = cur->second; + rProps.erase( cur ); + return true; + } + } + rValue = OUString(); + return false; +} + +long +getAttributeProps( PropList &rProps ) +{ + long nAttrs = 0; + OUString aValue; + + OUString trueStr( RTL_CONSTASCII_USTRINGPARAM( "true" ) ); + + if ( findAndRemove( "show", rProps, aValue ) && + aValue.equalsIgnoreAsciiCase( + OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) ) ) + ; + else + nAttrs |= awt::WindowAttribute::SHOW; + + for( int i = 0; i < attribsMapLen; i++ ) + { + if ( findAndRemove( attribsMap[i].name, rProps, aValue ) ) + { + if ( aValue.equalsIgnoreAsciiCase( trueStr ) ) + nAttrs |= attribsMap[i].value; + } + } + + if ( findAndRemove( "align", rProps, aValue ) ) + { + sal_Int32 nVal = aValue.toInt32(); + + if ( nVal == 0 /* PROPERTY_ALIGN_LEFT */ ) + nAttrs |= awt::VclWindowPeerAttribute::LEFT; + else if ( nVal == 1 /* PROPERTY_ALIGN_CENTER */ ) + nAttrs |= awt::VclWindowPeerAttribute::CENTER; + else if ( nVal == 2 ) + nAttrs |= awt::VclWindowPeerAttribute::RIGHT; + } + + return nAttrs; +} + +} + |