Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / framework / source / helper / uielementwrapperbase.cxx
blob5eea7c8a61254da48b6d8a34c4dc1e6b1e4f9bb3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <helper/uielementwrapperbase.hxx>
21 #include <general.h>
22 #include <properties.h>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <vcl/svapp.hxx>
29 #include <comphelper/sequence.hxx>
31 const int UIELEMENT_PROPHANDLE_RESOURCEURL = 1;
32 const int UIELEMENT_PROPHANDLE_TYPE = 2;
33 const int UIELEMENT_PROPHANDLE_FRAME = 3;
34 const char UIELEMENT_PROPNAME_RESOURCEURL[] = "ResourceURL";
35 const char UIELEMENT_PROPNAME_TYPE[] = "Type";
36 const char UIELEMENT_PROPNAME_FRAME[] = "Frame";
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::frame;
42 namespace framework
45 UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType )
46 : ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aMutex )
47 , ::cppu::OPropertySetHelper ( *static_cast< ::cppu::OBroadcastHelper* >(this) )
48 , m_aListenerContainer ( m_aMutex )
49 , m_nType ( nType )
50 , m_bInitialized ( false )
51 , m_bDisposed ( false )
55 UIElementWrapperBase::~UIElementWrapperBase()
59 Any SAL_CALL UIElementWrapperBase::queryInterface( const Type& _rType )
61 Any aRet = UIElementWrapperBase_BASE::queryInterface( _rType );
62 if ( !aRet.hasValue() )
63 aRet = OPropertySetHelper::queryInterface( _rType );
64 return aRet;
67 Sequence< Type > SAL_CALL UIElementWrapperBase::getTypes( )
69 return comphelper::concatSequences(
70 UIElementWrapperBase_BASE::getTypes(),
71 ::cppu::OPropertySetHelper::getTypes()
75 void SAL_CALL UIElementWrapperBase::addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
77 m_aListenerContainer.addInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
80 void SAL_CALL UIElementWrapperBase::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
82 m_aListenerContainer.removeInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
85 void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments )
87 SolarMutexGuard g;
89 if ( !m_bInitialized )
91 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
93 PropertyValue aPropValue;
94 if ( aArguments[n] >>= aPropValue )
96 if ( aPropValue.Name == "ResourceURL" )
97 aPropValue.Value >>= m_aResourceURL;
98 else if ( aPropValue.Name == "Frame" )
100 Reference< XFrame > xFrame;
101 aPropValue.Value >>= xFrame;
102 m_xWeakFrame = xFrame;
107 m_bInitialized = true;
111 // XUIElement
112 css::uno::Reference< css::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame()
114 css::uno::Reference< css::frame::XFrame > xFrame( m_xWeakFrame );
115 return xFrame;
118 OUString SAL_CALL UIElementWrapperBase::getResourceURL()
120 return m_aResourceURL;
123 ::sal_Int16 SAL_CALL UIElementWrapperBase::getType()
125 return m_nType;
128 // XUpdatable
129 void SAL_CALL UIElementWrapperBase::update()
131 // can be implemented by derived class
134 // XPropertySet helper
135 sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any& /*aConvertedValue*/ ,
136 Any& /*aOldValue*/ ,
137 sal_Int32 /*nHandle*/ ,
138 const Any& /*aValue*/ )
140 // Initialize state with sal_False !!!
141 // (Handle can be invalid)
142 return false;
145 void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 /*nHandle*/ ,
146 const css::uno::Any& /*aValue*/ )
150 void SAL_CALL UIElementWrapperBase::getFastPropertyValue( css::uno::Any& aValue ,
151 sal_Int32 nHandle ) const
153 switch( nHandle )
155 case UIELEMENT_PROPHANDLE_RESOURCEURL:
156 aValue <<= m_aResourceURL;
157 break;
158 case UIELEMENT_PROPHANDLE_TYPE:
159 aValue <<= m_nType;
160 break;
161 case UIELEMENT_PROPHANDLE_FRAME:
162 Reference< XFrame > xFrame( m_xWeakFrame );
163 aValue <<= xFrame;
164 break;
168 ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper()
170 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
171 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
172 // "true" say: Table is sorted by name.
173 static ::cppu::OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true );
175 return ourInfoHelper;
178 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo()
180 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
181 // (Use method "getInfoHelper()".)
182 static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
184 return xInfo;
187 css::uno::Sequence< css::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor()
189 // Create a property array to initialize sequence!
190 // Table of all predefined properties of this class. It's used from OPropertySetHelper-class!
191 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
192 // It's necessary for methods of OPropertySetHelper.
193 // ATTENTION:
194 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
196 return
198 css::beans::Property( UIELEMENT_PROPNAME_FRAME, UIELEMENT_PROPHANDLE_FRAME , cppu::UnoType<XFrame>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ),
199 css::beans::Property( UIELEMENT_PROPNAME_RESOURCEURL, UIELEMENT_PROPHANDLE_RESOURCEURL , cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ),
200 css::beans::Property( UIELEMENT_PROPNAME_TYPE, UIELEMENT_PROPHANDLE_TYPE , cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY )
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */