/src/libreoffice/framework/source/helper/uielementwrapperbase.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <helper/uielementwrapperbase.hxx> |
21 | | |
22 | | #include <com/sun/star/beans/PropertyAttribute.hpp> |
23 | | #include <com/sun/star/beans/PropertyValue.hpp> |
24 | | |
25 | | #include <vcl/svapp.hxx> |
26 | | #include <comphelper/sequence.hxx> |
27 | | |
28 | | const int UIELEMENT_PROPHANDLE_RESOURCEURL = 1; |
29 | | const int UIELEMENT_PROPHANDLE_TYPE = 2; |
30 | | const int UIELEMENT_PROPHANDLE_FRAME = 3; |
31 | | constexpr OUString UIELEMENT_PROPNAME_RESOURCEURL = u"ResourceURL"_ustr; |
32 | | constexpr OUString UIELEMENT_PROPNAME_TYPE = u"Type"_ustr; |
33 | | constexpr OUString UIELEMENT_PROPNAME_FRAME = u"Frame"_ustr; |
34 | | |
35 | | using namespace ::com::sun::star::uno; |
36 | | using namespace ::com::sun::star::beans; |
37 | | using namespace ::com::sun::star::frame; |
38 | | |
39 | | namespace framework |
40 | | { |
41 | | |
42 | | UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType ) |
43 | 8.54k | : ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aMutex ) |
44 | 8.54k | , ::cppu::OPropertySetHelper ( *static_cast< ::cppu::OBroadcastHelper* >(this) ) |
45 | 8.54k | , m_aListenerContainer ( m_aMutex ) |
46 | 8.54k | , m_nType ( nType ) |
47 | 8.54k | , m_bInitialized ( false ) |
48 | 8.54k | , m_bDisposed ( false ) |
49 | 8.54k | { |
50 | 8.54k | } |
51 | | |
52 | | UIElementWrapperBase::~UIElementWrapperBase() |
53 | 4.16k | { |
54 | 4.16k | } |
55 | | |
56 | | Any SAL_CALL UIElementWrapperBase::queryInterface( const Type& _rType ) |
57 | 0 | { |
58 | 0 | Any aRet = UIElementWrapperBase_BASE::queryInterface( _rType ); |
59 | 0 | if ( !aRet.hasValue() ) |
60 | 0 | aRet = OPropertySetHelper::queryInterface( _rType ); |
61 | 0 | return aRet; |
62 | 0 | } |
63 | | |
64 | | Sequence< Type > SAL_CALL UIElementWrapperBase::getTypes( ) |
65 | 0 | { |
66 | 0 | return comphelper::concatSequences( |
67 | 0 | UIElementWrapperBase_BASE::getTypes(), |
68 | 0 | ::cppu::OPropertySetHelper::getTypes() |
69 | 0 | ); |
70 | 0 | } |
71 | | |
72 | | void SAL_CALL UIElementWrapperBase::addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) |
73 | 0 | { |
74 | 0 | m_aListenerContainer.addInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener ); |
75 | 0 | } |
76 | | |
77 | | void SAL_CALL UIElementWrapperBase::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) |
78 | 0 | { |
79 | 0 | m_aListenerContainer.removeInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener ); |
80 | 0 | } |
81 | | |
82 | | void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments ) |
83 | 0 | { |
84 | 0 | SolarMutexGuard g; |
85 | |
|
86 | 0 | if ( m_bInitialized ) |
87 | 0 | return; |
88 | | |
89 | 0 | for ( const Any& rArg : aArguments ) |
90 | 0 | { |
91 | 0 | PropertyValue aPropValue; |
92 | 0 | if ( rArg >>= aPropValue ) |
93 | 0 | { |
94 | 0 | if ( aPropValue.Name == "ResourceURL" ) |
95 | 0 | aPropValue.Value >>= m_aResourceURL; |
96 | 0 | else if ( aPropValue.Name == "Frame" ) |
97 | 0 | { |
98 | 0 | Reference< XFrame > xFrame; |
99 | 0 | aPropValue.Value >>= xFrame; |
100 | 0 | m_xWeakFrame = xFrame; |
101 | 0 | } |
102 | 0 | } |
103 | 0 | } |
104 | |
|
105 | 0 | m_bInitialized = true; |
106 | 0 | } |
107 | | |
108 | | // XUIElement |
109 | | css::uno::Reference< css::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame() |
110 | 0 | { |
111 | 0 | css::uno::Reference< css::frame::XFrame > xFrame( m_xWeakFrame ); |
112 | 0 | return xFrame; |
113 | 0 | } |
114 | | |
115 | | OUString SAL_CALL UIElementWrapperBase::getResourceURL() |
116 | 0 | { |
117 | 0 | return m_aResourceURL; |
118 | 0 | } |
119 | | |
120 | | ::sal_Int16 SAL_CALL UIElementWrapperBase::getType() |
121 | 0 | { |
122 | 0 | return m_nType; |
123 | 0 | } |
124 | | |
125 | | // XUpdatable |
126 | | void SAL_CALL UIElementWrapperBase::update() |
127 | 0 | { |
128 | | // can be implemented by derived class |
129 | 0 | } |
130 | | |
131 | | // XPropertySet helper |
132 | | sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any& /*aConvertedValue*/ , |
133 | | Any& /*aOldValue*/ , |
134 | | sal_Int32 /*nHandle*/ , |
135 | | const Any& /*aValue*/ ) |
136 | 0 | { |
137 | | // Initialize state with sal_False !!! |
138 | | // (Handle can be invalid) |
139 | 0 | return false; |
140 | 0 | } |
141 | | |
142 | | void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 /*nHandle*/ , |
143 | | const css::uno::Any& /*aValue*/ ) |
144 | 0 | { |
145 | 0 | } |
146 | | |
147 | | void SAL_CALL UIElementWrapperBase::getFastPropertyValue( css::uno::Any& aValue , |
148 | | sal_Int32 nHandle ) const |
149 | 0 | { |
150 | 0 | switch( nHandle ) |
151 | 0 | { |
152 | 0 | case UIELEMENT_PROPHANDLE_RESOURCEURL: |
153 | 0 | aValue <<= m_aResourceURL; |
154 | 0 | break; |
155 | 0 | case UIELEMENT_PROPHANDLE_TYPE: |
156 | 0 | aValue <<= m_nType; |
157 | 0 | break; |
158 | 0 | case UIELEMENT_PROPHANDLE_FRAME: |
159 | 0 | Reference< XFrame > xFrame( m_xWeakFrame ); |
160 | 0 | aValue <<= xFrame; |
161 | 0 | break; |
162 | 0 | } |
163 | 0 | } |
164 | | |
165 | | ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper() |
166 | 0 | { |
167 | | // Define static member to give structure of properties to baseclass "OPropertySetHelper". |
168 | | // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable. |
169 | | // "true" say: Table is sorted by name. |
170 | 0 | static ::cppu::OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true ); |
171 | |
|
172 | 0 | return ourInfoHelper; |
173 | 0 | } |
174 | | |
175 | | css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo() |
176 | 0 | { |
177 | | // Create structure of propertysetinfo for baseclass "OPropertySetHelper". |
178 | | // (Use method "getInfoHelper()".) |
179 | 0 | static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); |
180 | |
|
181 | 0 | return xInfo; |
182 | 0 | } |
183 | | |
184 | | css::uno::Sequence< css::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor() |
185 | 0 | { |
186 | | // Create a property array to initialize sequence! |
187 | | // Table of all predefined properties of this class. It's used from OPropertySetHelper-class! |
188 | | // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!! |
189 | | // It's necessary for methods of OPropertySetHelper. |
190 | | // ATTENTION: |
191 | | // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!! |
192 | |
|
193 | 0 | return |
194 | 0 | { |
195 | 0 | css::beans::Property( UIELEMENT_PROPNAME_FRAME, UIELEMENT_PROPHANDLE_FRAME , cppu::UnoType<XFrame>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ), |
196 | 0 | css::beans::Property( UIELEMENT_PROPNAME_RESOURCEURL, UIELEMENT_PROPHANDLE_RESOURCEURL , cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ), |
197 | 0 | css::beans::Property( UIELEMENT_PROPNAME_TYPE, UIELEMENT_PROPHANDLE_TYPE , cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ) |
198 | 0 | }; |
199 | 0 | } |
200 | | |
201 | | } |
202 | | |
203 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |