fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / toolkit / source / controls / tabpagecontainer.cxx
blobefbac8b28b54f8923222c0ebea3452be870a3577
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 .
21 #include <toolkit/controls/geometrycontrolmodel.hxx>
22 #include <toolkit/controls/tabpagecontainer.hxx>
23 #include <toolkit/controls/tabpagemodel.hxx>
24 #include <toolkit/helper/property.hxx>
25 #include <toolkit/helper/unopropertyarrayhelper.hxx>
27 #include <com/sun/star/awt/XControlModel.hpp>
28 #include <com/sun/star/awt/XVclWindowPeer.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <comphelper/processfactory.hxx>
32 #include <osl/diagnose.h>
33 #include <tools/diagnose_ex.h>
34 #include <vcl/svapp.hxx>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::view;
42 using ::com::sun::star::awt::tab::XTabPageModel;
44 #define WRONG_TYPE_EXCEPTION "Type must be ::com::sun::star::awt::tab::XTabPageModel!"
45 // ----------------------------------------------------
46 // class UnoControlTabPageContainerModel
47 // ----------------------------------------------------
48 UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference< XComponentContext >& i_factory )
49 :UnoControlTabPageContainerModel_Base( i_factory )
50 ,maContainerListeners( *this )
52 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
53 ImplRegisterProperty( BASEPROPERTY_BORDER );
54 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
55 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
56 ImplRegisterProperty( BASEPROPERTY_ENABLED );
57 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
58 ImplRegisterProperty( BASEPROPERTY_HELPURL );
59 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
60 ImplRegisterProperty( BASEPROPERTY_TEXT );
63 OUString UnoControlTabPageContainerModel::getServiceName() throw(RuntimeException)
65 return OUString::createFromAscii( szServiceName_UnoControlTabPageContainerModel );
68 uno::Any UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
70 switch(nPropId)
72 case BASEPROPERTY_DEFAULTCONTROL:
73 return uno::makeAny( OUString::createFromAscii( szServiceName_UnoControlTabPageContainer ) );
74 case BASEPROPERTY_BORDER:
75 return uno::makeAny((sal_Int16) 0); // No Border
76 default:
77 return UnoControlModel::ImplGetDefaultValue( nPropId );
81 ::cppu::IPropertyArrayHelper& UnoControlTabPageContainerModel::getInfoHelper()
83 static UnoPropertyArrayHelper* pHelper = NULL;
84 if ( !pHelper )
86 com::sun::star::uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
87 pHelper = new UnoPropertyArrayHelper( aIDs );
89 return *pHelper;
91 Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlTabPageContainerModel::getPropertySetInfo( ) throw(RuntimeException)
93 static Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
94 return xInfo;
97 namespace
99 Reference< XTabPageModel > lcl_createTabPageModel( Reference<XComponentContext> const & i_context,
100 Sequence< Any > const & i_initArguments, Reference< XPropertySet > const & i_parentModel )
104 Reference< XPropertySet > const xParentDelegator( i_parentModel, UNO_QUERY_THROW );
105 Reference< XPropertySetInfo > const xPSI( xParentDelegator->getPropertySetInfo() );
106 bool const isGeometryControlModel = xPSI.is() && xPSI->hasPropertyByName( OUString( "PositionX" ) );
108 Reference< XInterface > xInstance;
109 if ( isGeometryControlModel )
110 xInstance = *( new OGeometryControlModel< UnoControlTabPageModel >( i_context ) );
111 else
112 xInstance = *( new UnoControlTabPageModel( i_context ) );
114 Reference< XTabPageModel > const xTabPageModel( xInstance, UNO_QUERY_THROW );
115 Reference< XInitialization > const xInit( xTabPageModel, UNO_QUERY_THROW );
116 xInit->initialize( i_initArguments );
118 return xTabPageModel;
120 catch( const RuntimeException& )
122 throw;
124 catch( const Exception& )
126 DBG_UNHANDLED_EXCEPTION();
128 return NULL;
132 Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID ) throw (RuntimeException)
134 Sequence< Any > aInitArgs(1);
135 aInitArgs[0] <<= i_tabPageID;
136 return lcl_createTabPageModel( m_xContext, aInitArgs, this );
139 Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::loadTabPage( ::sal_Int16 i_tabPageID, const OUString& i_resourceURL ) throw (RuntimeException)
141 Sequence< Any > aInitArgs(2);
142 aInitArgs[0] <<= i_tabPageID;
143 aInitArgs[1] <<= i_resourceURL;
144 return lcl_createTabPageModel( m_xContext, aInitArgs, this );
147 void SAL_CALL UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex, const com::sun::star::uno::Any& aElement) throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, uno::RuntimeException)
149 SolarMutexGuard aSolarGuard;
150 uno::Reference < XTabPageModel > xTabPageModel;
151 if(aElement >>= xTabPageModel)
153 if ( sal_Int32( m_aTabPageVector.size()) ==nIndex )
154 m_aTabPageVector.push_back( xTabPageModel );
155 else if ( sal_Int32( m_aTabPageVector.size()) > nIndex )
157 std::vector< uno::Reference< XTabPageModel > >::iterator aIter = m_aTabPageVector.begin();
158 aIter += nIndex;
159 m_aTabPageVector.insert( aIter, xTabPageModel );
161 else
162 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
163 ContainerEvent aEvent;
164 aEvent.Source = *this;
165 aEvent.Element <<= aElement;
166 aEvent.Accessor <<= OUString::valueOf(nIndex);
167 maContainerListeners.elementInserted( aEvent );
169 else
170 throw IllegalArgumentException( OUString( WRONG_TYPE_EXCEPTION ),
171 (OWeakObject *)this, 2 );
173 // -----------------------------------------------------------------------------
174 void SAL_CALL UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
177 // XIndexReplace
178 void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Index*/, const uno::Any& /*Element*/ ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
181 // -----------------------------------------------------------------------------
182 // XIndexAccess
183 ::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount( ) throw (uno::RuntimeException)
185 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
186 return sal_Int32( m_aTabPageVector.size());
188 // -----------------------------------------------------------------------------
189 uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
191 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
192 if ( nIndex < 0 || nIndex > sal_Int32(m_aTabPageVector.size()) )
193 throw lang::IndexOutOfBoundsException();
194 return uno::makeAny(m_aTabPageVector[nIndex]);
196 // -----------------------------------------------------------------------------
197 // XElementAccess
198 uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType( ) throw (uno::RuntimeException)
200 return ::getCppuType(static_cast< Reference< com::sun::star::awt::XControlModel>* >(NULL));
202 // -----------------------------------------------------------------------------
203 ::sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements( ) throw (uno::RuntimeException)
205 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
206 return !m_aTabPageVector.empty();
208 // XContainer
209 void UnoControlTabPageContainerModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
211 maContainerListeners.addInterface( l );
214 void UnoControlTabPageContainerModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
216 maContainerListeners.removeInterface( l );
219 // ----------------------------------------------------
220 // class UnoControlTabPageContainer
221 // ----------------------------------------------------
222 UnoControlTabPageContainer::UnoControlTabPageContainer( const uno::Reference< uno::XComponentContext >& rxContext )
223 :UnoControlTabPageContainer_Base(rxContext)
224 ,m_aTabPageListeners( *this )
228 OUString UnoControlTabPageContainer::GetComponentServiceName()
230 return OUString("TabPageContainer");
233 void SAL_CALL UnoControlTabPageContainer::dispose( ) throw(RuntimeException)
235 lang::EventObject aEvt;
236 aEvt.Source = (::cppu::OWeakObject*)this;
237 m_aTabPageListeners.disposeAndClear( aEvt );
238 UnoControl::dispose();
241 void UnoControlTabPageContainer::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException)
243 UnoControlBase::createPeer( rxToolkit, rParentPeer );
245 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
246 if ( m_aTabPageListeners.getLength() )
247 xTPContainer->addTabPageContainerListener(&m_aTabPageListeners);
250 // -------------------------------------------------------------------
251 // XTabPageContainer
253 ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getActiveTabPageID() throw (RuntimeException)
255 SolarMutexGuard aSolarGuard;
256 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
257 return xTPContainer->getActiveTabPageID();
259 void SAL_CALL UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException)
261 SolarMutexGuard aSolarGuard;
262 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
263 xTPContainer->setActiveTabPageID(_activetabpageid);
265 ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getTabPageCount( ) throw (RuntimeException)
267 SolarMutexGuard aSolarGuard;
268 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
269 return xTPContainer->getTabPageCount();
271 ::sal_Bool SAL_CALL UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
273 SolarMutexGuard aSolarGuard;
274 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
275 return xTPContainer->isTabPageActive(tabPageIndex);
277 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
279 SolarMutexGuard aSolarGuard;
280 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
281 return xTPContainer->getTabPage(tabPageIndex);
283 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException)
285 SolarMutexGuard aSolarGuard;
286 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
287 return xTPContainer->getTabPageByID(tabPageID);
289 void SAL_CALL UnoControlTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
291 m_aTabPageListeners.addInterface( listener );
292 if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
294 uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
295 xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
298 void SAL_CALL UnoControlTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
300 if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
302 uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
303 xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
305 m_aTabPageListeners.removeInterface( listener );
308 void UnoControlTabPageContainer::updateFromModel()
310 UnoControlTabPageContainer_Base::updateFromModel();
311 Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
312 ENSURE_OR_RETURN_VOID( xContainerListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
314 ContainerEvent aEvent;
315 aEvent.Source = getModel();
316 Sequence< Reference< XControl > > aControls = getControls();
317 const Reference< XControl >* pCtrls = aControls.getConstArray();
318 const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
320 for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
322 aEvent.Element <<= *pCtrls;
323 xContainerListener->elementInserted( aEvent );
326 void SAL_CALL UnoControlTabPageContainer::addControl( const OUString& Name, const Reference< ::com::sun::star::awt::XControl >& Control ) throw (RuntimeException)
328 SolarMutexGuard aSolarGuard;
329 ControlContainerBase::addControl(Name,Control);
330 Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
331 ContainerEvent aEvent;
332 aEvent.Source = getModel();
333 aEvent.Element <<= Control;
334 xContainerListener->elementInserted( aEvent );
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */