1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26
27 #include <toolkit/controls/geometrycontrolmodel.hxx>
28 #include <toolkit/controls/tabpagecontainer.hxx>
29 #include <toolkit/controls/tabpagemodel.hxx>
30 #include <toolkit/helper/property.hxx>
31 #include <toolkit/helper/unopropertyarrayhelper.hxx>
32
33 #include <com/sun/star/awt/XControlModel.hpp>
34 #include <com/sun/star/awt/XVclWindowPeer.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36
37 #include <comphelper/processfactory.hxx>
38 #include <osl/diagnose.h>
39 #include <tools/diagnose_ex.h>
40 #include <vcl/svapp.hxx>
41 #include <vos/mutex.hxx>
42
43 using ::rtl::OUString;
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::view;
50 using ::com::sun::star::awt::tab::XTabPageModel;
51
52 #define WRONG_TYPE_EXCEPTION "Type must be ::com::sun::star::awt::tab::XTabPageModel!"
53 // ----------------------------------------------------
54 // class UnoControlTabPageContainerModel
55 // ----------------------------------------------------
UnoControlTabPageContainerModel(const Reference<XMultiServiceFactory> & i_factory)56 UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference< XMultiServiceFactory >& i_factory )
57 :UnoControlTabPageContainerModel_Base( i_factory )
58 ,maContainerListeners( *this )
59 {
60 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
61 ImplRegisterProperty( BASEPROPERTY_BORDER );
62 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
63 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
64 ImplRegisterProperty( BASEPROPERTY_ENABLED );
65 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
66 ImplRegisterProperty( BASEPROPERTY_HELPURL );
67 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
68 ImplRegisterProperty( BASEPROPERTY_TEXT );
69 }
70
getServiceName()71 ::rtl::OUString UnoControlTabPageContainerModel::getServiceName() throw(RuntimeException)
72 {
73 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainerModel );
74 }
75
ImplGetDefaultValue(sal_uInt16 nPropId) const76 uno::Any UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
77 {
78 switch(nPropId)
79 {
80 case BASEPROPERTY_DEFAULTCONTROL:
81 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainer ) );
82 case BASEPROPERTY_BORDER:
83 return uno::makeAny((sal_Int16) 0); // No Border
84 default:
85 return UnoControlModel::ImplGetDefaultValue( nPropId );
86 }
87 }
88
getInfoHelper()89 ::cppu::IPropertyArrayHelper& UnoControlTabPageContainerModel::getInfoHelper()
90 {
91 static UnoPropertyArrayHelper* pHelper = NULL;
92 if ( !pHelper )
93 {
94 com::sun::star::uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
95 pHelper = new UnoPropertyArrayHelper( aIDs );
96 }
97 return *pHelper;
98 }
getPropertySetInfo()99 Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlTabPageContainerModel::getPropertySetInfo( ) throw(RuntimeException)
100 {
101 static Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
102 return xInfo;
103 }
104
105 namespace
106 {
lcl_createTabPageModel(::comphelper::ComponentContext const & i_context,Sequence<Any> const & i_initArguments,Reference<XPropertySet> const & i_parentModel)107 Reference< XTabPageModel > lcl_createTabPageModel( ::comphelper::ComponentContext const & i_context,
108 Sequence< Any > const & i_initArguments, Reference< XPropertySet > const & i_parentModel )
109 {
110 try
111 {
112 Reference< XPropertySet > const xParentDelegator( i_parentModel, UNO_QUERY_THROW );
113 Reference< XPropertySetInfo > const xPSI( xParentDelegator->getPropertySetInfo() );
114 bool const isGeometryControlModel = xPSI.is() && xPSI->hasPropertyByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ) );
115
116 Reference< XInterface > xInstance;
117 if ( isGeometryControlModel )
118 xInstance = *( new OGeometryControlModel< UnoControlTabPageModel >( i_context.getLegacyServiceFactory() ) );
119 else
120 xInstance = *( new UnoControlTabPageModel( i_context.getLegacyServiceFactory() ) );
121
122 Reference< XTabPageModel > const xTabPageModel( xInstance, UNO_QUERY_THROW );
123 Reference< XInitialization > const xInit( xTabPageModel, UNO_QUERY_THROW );
124 xInit->initialize( i_initArguments );
125
126 return xTabPageModel;
127 }
128 catch( const RuntimeException& )
129 {
130 throw;
131 }
132 catch( const Exception& )
133 {
134 DBG_UNHANDLED_EXCEPTION();
135 }
136 return NULL;
137 }
138 }
139
createTabPage(::sal_Int16 i_tabPageID)140 Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID ) throw (RuntimeException)
141 {
142 Sequence< Any > aInitArgs(1);
143 aInitArgs[0] <<= i_tabPageID;
144 return lcl_createTabPageModel( maContext, aInitArgs, this );
145 }
146
loadTabPage(::sal_Int16 i_tabPageID,const::rtl::OUString & i_resourceURL)147 Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::loadTabPage( ::sal_Int16 i_tabPageID, const ::rtl::OUString& i_resourceURL ) throw (RuntimeException)
148 {
149 Sequence< Any > aInitArgs(2);
150 aInitArgs[0] <<= i_tabPageID;
151 aInitArgs[1] <<= i_resourceURL;
152 return lcl_createTabPageModel( maContext, aInitArgs, this );
153 }
154
insertByIndex(::sal_Int32 nIndex,const com::sun::star::uno::Any & aElement)155 void SAL_CALL UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex, const com::sun::star::uno::Any& aElement) throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, uno::RuntimeException)
156 {
157 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
158 uno::Reference < XTabPageModel > xTabPageModel;
159 if(aElement >>= xTabPageModel)
160 {
161 if ( sal_Int32( m_aTabPageVector.size()) ==nIndex )
162 m_aTabPageVector.push_back( xTabPageModel );
163 else if ( sal_Int32( m_aTabPageVector.size()) > nIndex )
164 {
165 std::vector< uno::Reference< XTabPageModel > >::iterator aIter = m_aTabPageVector.begin();
166 aIter += nIndex;
167 m_aTabPageVector.insert( aIter, xTabPageModel );
168 }
169 else
170 throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
171 ContainerEvent aEvent;
172 aEvent.Source = *this;
173 aEvent.Element <<= aElement;
174 aEvent.Accessor <<= ::rtl::OUString::valueOf(nIndex);
175 maContainerListeners.elementInserted( aEvent );
176 }
177 else
178 throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
179 (OWeakObject *)this, 2 );
180 }
181 // -----------------------------------------------------------------------------
removeByIndex(::sal_Int32)182 void SAL_CALL UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
183 {
184 }
185 // XIndexReplace
replaceByIndex(::sal_Int32,const uno::Any &)186 void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Index*/, const uno::Any& /*Element*/ ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
187 {
188 }
189 // -----------------------------------------------------------------------------
190 // XIndexAccess
getCount()191 ::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount( ) throw (uno::RuntimeException)
192 {
193 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
194 return sal_Int32( m_aTabPageVector.size());
195 }
196 // -----------------------------------------------------------------------------
getByIndex(::sal_Int32 nIndex)197 uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
198 {
199 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
200 if ( nIndex < 0 || nIndex > sal_Int32(m_aTabPageVector.size()) )
201 throw lang::IndexOutOfBoundsException();
202 return uno::makeAny(m_aTabPageVector[nIndex]);
203 }
204 // -----------------------------------------------------------------------------
205 // XElementAccess
getElementType()206 uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType( ) throw (uno::RuntimeException)
207 {
208 return ::getCppuType(static_cast< Reference< com::sun::star::awt::XControlModel>* >(NULL));
209 }
210 // -----------------------------------------------------------------------------
hasElements()211 ::sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements( ) throw (uno::RuntimeException)
212 {
213 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
214 return !m_aTabPageVector.empty();
215 }
216 // XContainer
addContainerListener(const Reference<XContainerListener> & l)217 void UnoControlTabPageContainerModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
218 {
219 maContainerListeners.addInterface( l );
220 }
221
removeContainerListener(const Reference<XContainerListener> & l)222 void UnoControlTabPageContainerModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
223 {
224 maContainerListeners.removeInterface( l );
225 }
226
227 // ----------------------------------------------------
228 // class UnoControlTabPageContainer
229 // ----------------------------------------------------
UnoControlTabPageContainer(const Reference<XMultiServiceFactory> & i_factory)230 UnoControlTabPageContainer::UnoControlTabPageContainer( const Reference< XMultiServiceFactory >& i_factory )
231 :UnoControlTabPageContainer_Base( i_factory )
232 ,m_aTabPageListeners( *this )
233 {
234 }
235
GetComponentServiceName()236 OUString UnoControlTabPageContainer::GetComponentServiceName()
237 {
238 return OUString::createFromAscii( "TabPageContainer" );
239 }
240
dispose()241 void SAL_CALL UnoControlTabPageContainer::dispose( ) throw(RuntimeException)
242 {
243 lang::EventObject aEvt;
244 aEvt.Source = (::cppu::OWeakObject*)this;
245 m_aTabPageListeners.disposeAndClear( aEvt );
246 UnoControl::dispose();
247 }
248
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)249 void UnoControlTabPageContainer::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException)
250 {
251 UnoControlBase::createPeer( rxToolkit, rParentPeer );
252
253 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
254 if ( m_aTabPageListeners.getLength() )
255 xTPContainer->addTabPageContainerListener(&m_aTabPageListeners);
256 }
257
258 // -------------------------------------------------------------------
259 // XTabPageContainer
260
getActiveTabPageID()261 ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getActiveTabPageID() throw (RuntimeException)
262 {
263 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
264 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
265 return xTPContainer->getActiveTabPageID();
266 }
setActiveTabPageID(::sal_Int16 _activetabpageid)267 void SAL_CALL UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException)
268 {
269 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
270 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
271 xTPContainer->setActiveTabPageID(_activetabpageid);
272 }
getTabPageCount()273 ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getTabPageCount( ) throw (RuntimeException)
274 {
275 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
276 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
277 return xTPContainer->getTabPageCount();
278 }
isTabPageActive(::sal_Int16 tabPageIndex)279 ::sal_Bool SAL_CALL UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
280 {
281 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
282 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
283 return xTPContainer->isTabPageActive(tabPageIndex);
284 }
getTabPage(::sal_Int16 tabPageIndex)285 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
286 {
287 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
288 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
289 return xTPContainer->getTabPage(tabPageIndex);
290 }
getTabPageByID(::sal_Int16 tabPageID)291 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException)
292 {
293 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
294 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
295 return xTPContainer->getTabPageByID(tabPageID);
296 }
addTabPageContainerListener(const Reference<::com::sun::star::awt::tab::XTabPageContainerListener> & listener)297 void SAL_CALL UnoControlTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
298 {
299 m_aTabPageListeners.addInterface( listener );
300 if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
301 {
302 uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
303 xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
304 }
305 }
removeTabPageContainerListener(const Reference<::com::sun::star::awt::tab::XTabPageContainerListener> & listener)306 void SAL_CALL UnoControlTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
307 {
308 if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
309 {
310 uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
311 xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
312 }
313 m_aTabPageListeners.removeInterface( listener );
314 }
315
updateFromModel()316 void UnoControlTabPageContainer::updateFromModel()
317 {
318 UnoControlTabPageContainer_Base::updateFromModel();
319 Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
320 ENSURE_OR_RETURN_VOID( xContainerListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
321
322 ContainerEvent aEvent;
323 aEvent.Source = getModel();
324 Sequence< Reference< XControl > > aControls = getControls();
325 const Reference< XControl >* pCtrls = aControls.getConstArray();
326 const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
327
328 for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
329 {
330 aEvent.Element <<= *pCtrls;
331 xContainerListener->elementInserted( aEvent );
332 }
333 }
addControl(const::rtl::OUString & Name,const Reference<::com::sun::star::awt::XControl> & Control)334 void SAL_CALL UnoControlTabPageContainer::addControl( const ::rtl::OUString& Name, const Reference< ::com::sun::star::awt::XControl >& Control ) throw (RuntimeException)
335 {
336 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
337 ControlContainerBase::addControl(Name,Control);
338 Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
339 ContainerEvent aEvent;
340 aEvent.Source = getModel();
341 aEvent.Element <<= Control;
342 xContainerListener->elementInserted( aEvent );
343 }
344
345