bump product version to 5.0.4.1
[LibreOffice.git] / toolkit / source / controls / tabpagecontainer.cxx
blobfac6cc0a6a4b8b91532ce391b28a7e9dc7d01ace
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>
26 #include <com/sun/star/awt/XControlModel.hpp>
27 #include <com/sun/star/awt/XVclWindowPeer.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <osl/diagnose.h>
32 #include <tools/diagnose_ex.h>
33 #include <vcl/svapp.hxx>
35 #include "helper/unopropertyarrayhelper.hxx"
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::view;
43 using ::com::sun::star::awt::tab::XTabPageModel;
45 #define WRONG_TYPE_EXCEPTION "Type must be ::com::sun::star::awt::tab::XTabPageModel!"
47 // class UnoControlTabPageContainerModel
49 UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference< XComponentContext >& i_factory )
50 :UnoControlTabPageContainerModel_Base( i_factory )
51 ,maContainerListeners( *this )
53 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
54 ImplRegisterProperty( BASEPROPERTY_BORDER );
55 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
56 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
57 ImplRegisterProperty( BASEPROPERTY_ENABLED );
58 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
59 ImplRegisterProperty( BASEPROPERTY_HELPURL );
60 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
61 ImplRegisterProperty( BASEPROPERTY_TEXT );
64 OUString UnoControlTabPageContainerModel::getServiceName() throw(RuntimeException, std::exception)
66 return OUString("com.sun.star.awt.tab.UnoControlTabPageContainerModel");
69 uno::Any UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
71 switch(nPropId)
73 case BASEPROPERTY_DEFAULTCONTROL:
74 return uno::makeAny( OUString("com.sun.star.awt.tab.UnoControlTabPageContainer") );
75 case BASEPROPERTY_BORDER:
76 return uno::makeAny((sal_Int16) 0); // No Border
77 default:
78 return UnoControlModel::ImplGetDefaultValue( nPropId );
82 ::cppu::IPropertyArrayHelper& UnoControlTabPageContainerModel::getInfoHelper()
84 static UnoPropertyArrayHelper* pHelper = NULL;
85 if ( !pHelper )
87 com::sun::star::uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
88 pHelper = new UnoPropertyArrayHelper( aIDs );
90 return *pHelper;
92 Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlTabPageContainerModel::getPropertySetInfo( ) throw(RuntimeException, std::exception)
94 static Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
95 return xInfo;
98 namespace
100 Reference< XTabPageModel > lcl_createTabPageModel( Reference<XComponentContext> const & i_context,
101 Sequence< Any > const & i_initArguments, Reference< XPropertySet > const & i_parentModel )
105 Reference< XPropertySetInfo > const xPSI( i_parentModel->getPropertySetInfo() );
106 bool const isGeometryControlModel = xPSI.is() && xPSI->hasPropertyByName("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, std::exception)
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, std::exception)
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, std::exception)
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::number(nIndex);
167 maContainerListeners.elementInserted( aEvent );
169 else
170 throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, (OWeakObject *)this, 2 );
173 void SAL_CALL UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
176 // XIndexReplace
177 void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Index*/, const uno::Any& /*Element*/ ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
181 // XIndexAccess
182 ::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount( ) throw (uno::RuntimeException, std::exception)
184 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
185 return sal_Int32( m_aTabPageVector.size());
188 uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
190 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
191 if ( nIndex < 0 || nIndex > sal_Int32(m_aTabPageVector.size()) )
192 throw lang::IndexOutOfBoundsException();
193 return uno::makeAny(m_aTabPageVector[nIndex]);
196 // XElementAccess
197 uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType( ) throw (uno::RuntimeException, std::exception)
199 return cppu::UnoType<com::sun::star::awt::XControlModel>::get();
202 sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements( ) throw (uno::RuntimeException, std::exception)
204 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
205 return !m_aTabPageVector.empty();
207 // XContainer
208 void UnoControlTabPageContainerModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException, std::exception)
210 maContainerListeners.addInterface( l );
213 void UnoControlTabPageContainerModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException, std::exception)
215 maContainerListeners.removeInterface( l );
219 // class UnoControlTabPageContainer
221 UnoControlTabPageContainer::UnoControlTabPageContainer( const uno::Reference< uno::XComponentContext >& rxContext )
222 :UnoControlTabPageContainer_Base(rxContext)
223 ,m_aTabPageListeners( *this )
227 OUString UnoControlTabPageContainer::GetComponentServiceName()
229 return OUString("TabPageContainer");
232 void SAL_CALL UnoControlTabPageContainer::dispose( ) throw(RuntimeException, std::exception)
234 lang::EventObject aEvt;
235 aEvt.Source = (::cppu::OWeakObject*)this;
236 m_aTabPageListeners.disposeAndClear( aEvt );
237 UnoControl::dispose();
240 void UnoControlTabPageContainer::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException, std::exception)
242 UnoControlBase::createPeer( rxToolkit, rParentPeer );
244 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
245 if ( m_aTabPageListeners.getLength() )
246 xTPContainer->addTabPageContainerListener(&m_aTabPageListeners);
250 // XTabPageContainer
252 ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getActiveTabPageID() throw (RuntimeException, std::exception)
254 SolarMutexGuard aSolarGuard;
255 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
256 return xTPContainer->getActiveTabPageID();
258 void SAL_CALL UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException, std::exception)
260 SolarMutexGuard aSolarGuard;
261 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
262 xTPContainer->setActiveTabPageID(_activetabpageid);
264 ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getTabPageCount( ) throw (RuntimeException, std::exception)
266 SolarMutexGuard aSolarGuard;
267 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
268 return xTPContainer->getTabPageCount();
270 sal_Bool SAL_CALL UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException, std::exception)
272 SolarMutexGuard aSolarGuard;
273 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
274 return xTPContainer->isTabPageActive(tabPageIndex);
276 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException, std::exception)
278 SolarMutexGuard aSolarGuard;
279 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
280 return xTPContainer->getTabPage(tabPageIndex);
282 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException, std::exception)
284 SolarMutexGuard aSolarGuard;
285 Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
286 return xTPContainer->getTabPageByID(tabPageID);
288 void SAL_CALL UnoControlTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException, std::exception)
290 m_aTabPageListeners.addInterface( listener );
291 if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
293 uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
294 xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
297 void SAL_CALL UnoControlTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException, std::exception)
299 if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
301 uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
302 xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
304 m_aTabPageListeners.removeInterface( listener );
307 void UnoControlTabPageContainer::updateFromModel()
309 UnoControlTabPageContainer_Base::updateFromModel();
310 Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
311 ENSURE_OR_RETURN_VOID( xContainerListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
313 ContainerEvent aEvent;
314 aEvent.Source = getModel();
315 Sequence< Reference< XControl > > aControls = getControls();
316 const Reference< XControl >* pCtrls = aControls.getConstArray();
317 const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
319 for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
321 aEvent.Element <<= *pCtrls;
322 xContainerListener->elementInserted( aEvent );
325 void SAL_CALL UnoControlTabPageContainer::addControl( const OUString& Name, const Reference< ::com::sun::star::awt::XControl >& Control ) throw (RuntimeException, std::exception)
327 SolarMutexGuard aSolarGuard;
328 ControlContainerBase::addControl(Name,Control);
329 Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
330 ContainerEvent aEvent;
331 aEvent.Source = getModel();
332 aEvent.Element <<= Control;
333 xContainerListener->elementInserted( aEvent );
336 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
337 stardiv_Toolkit_UnoControlTabPageContainerModel_get_implementation(
338 css::uno::XComponentContext *context,
339 css::uno::Sequence<css::uno::Any> const &)
341 return cppu::acquire(new UnoControlTabPageContainerModel(context));
344 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
345 stardiv_Toolkit_UnoControlTabPageContainer_get_implementation(
346 css::uno::XComponentContext *context,
347 css::uno::Sequence<css::uno::Any> const &)
349 return cppu::acquire(new UnoControlTabPageContainer(context));
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */