1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/IndexOutOfBoundsException.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
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 css::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()
66 return OUString("com.sun.star.awt.tab.UnoControlTabPageContainerModel");
69 uno::Any
UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
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
78 return UnoControlModel::ImplGetDefaultValue( nPropId
);
82 ::cppu::IPropertyArrayHelper
& UnoControlTabPageContainerModel::getInfoHelper()
84 static UnoPropertyArrayHelper
aHelper( ImplGetPropertyIds() );
87 Reference
< css::beans::XPropertySetInfo
> UnoControlTabPageContainerModel::getPropertySetInfo( )
89 static Reference
< css::beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
95 Reference
< XTabPageModel
> lcl_createTabPageModel( Reference
<XComponentContext
> const & i_context
,
96 Sequence
< Any
> const & i_initArguments
, Reference
< XPropertySet
> const & i_parentModel
)
100 Reference
< XPropertySetInfo
> const xPSI( i_parentModel
->getPropertySetInfo() );
101 bool const isGeometryControlModel
= xPSI
.is() && xPSI
->hasPropertyByName("PositionX");
103 Reference
< XInterface
> xInstance
;
104 if ( isGeometryControlModel
)
105 xInstance
= *( new OGeometryControlModel
< UnoControlTabPageModel
>( i_context
) );
107 xInstance
= *( new UnoControlTabPageModel( i_context
) );
109 Reference
< XTabPageModel
> const xTabPageModel( xInstance
, UNO_QUERY_THROW
);
110 Reference
< XInitialization
> const xInit( xTabPageModel
, UNO_QUERY_THROW
);
111 xInit
->initialize( i_initArguments
);
113 return xTabPageModel
;
115 catch( const RuntimeException
& )
119 catch( const Exception
& )
121 DBG_UNHANDLED_EXCEPTION("toolkit.controls");
127 Reference
< XTabPageModel
> SAL_CALL
UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID
)
129 Sequence
< Any
> aInitArgs(1);
130 aInitArgs
[0] <<= i_tabPageID
;
131 return lcl_createTabPageModel( m_xContext
, aInitArgs
, this );
134 Reference
< XTabPageModel
> SAL_CALL
UnoControlTabPageContainerModel::loadTabPage( ::sal_Int16 i_tabPageID
, const OUString
& i_resourceURL
)
136 Sequence
< Any
> aInitArgs(2);
137 aInitArgs
[0] <<= i_tabPageID
;
138 aInitArgs
[1] <<= i_resourceURL
;
139 return lcl_createTabPageModel( m_xContext
, aInitArgs
, this );
142 void SAL_CALL
UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex
, const css::uno::Any
& aElement
)
144 SolarMutexGuard aSolarGuard
;
145 uno::Reference
< XTabPageModel
> xTabPageModel
;
146 if(!(aElement
>>= xTabPageModel
))
147 throw IllegalArgumentException( WRONG_TYPE_EXCEPTION
, static_cast<OWeakObject
*>(this), 2 );
149 if ( sal_Int32( m_aTabPageVector
.size()) ==nIndex
)
150 m_aTabPageVector
.push_back( xTabPageModel
);
151 else if ( sal_Int32( m_aTabPageVector
.size()) > nIndex
)
153 std::vector
< uno::Reference
< XTabPageModel
> >::iterator aIter
= m_aTabPageVector
.begin();
155 m_aTabPageVector
.insert( aIter
, xTabPageModel
);
158 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject
*>(this) );
159 ContainerEvent aEvent
;
160 aEvent
.Source
= *this;
161 aEvent
.Element
= aElement
;
162 aEvent
.Accessor
<<= OUString::number(nIndex
);
163 maContainerListeners
.elementInserted( aEvent
);
167 void SAL_CALL
UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32
/*Index*/ )
171 void SAL_CALL
UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32
/*Index*/, const uno::Any
& /*Element*/ )
176 ::sal_Int32 SAL_CALL
UnoControlTabPageContainerModel::getCount( )
178 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
179 return sal_Int32( m_aTabPageVector
.size());
182 uno::Any SAL_CALL
UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex
)
184 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
185 if ( nIndex
< 0 || nIndex
> sal_Int32(m_aTabPageVector
.size()) )
186 throw lang::IndexOutOfBoundsException();
187 return uno::makeAny(m_aTabPageVector
[nIndex
]);
191 uno::Type SAL_CALL
UnoControlTabPageContainerModel::getElementType( )
193 return cppu::UnoType
<css::awt::XControlModel
>::get();
196 sal_Bool SAL_CALL
UnoControlTabPageContainerModel::hasElements( )
198 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
199 return !m_aTabPageVector
.empty();
202 void UnoControlTabPageContainerModel::addContainerListener( const Reference
< XContainerListener
>& l
)
204 maContainerListeners
.addInterface( l
);
207 void UnoControlTabPageContainerModel::removeContainerListener( const Reference
< XContainerListener
>& l
)
209 maContainerListeners
.removeInterface( l
);
213 // class UnoControlTabPageContainer
215 UnoControlTabPageContainer::UnoControlTabPageContainer( const uno::Reference
< uno::XComponentContext
>& rxContext
)
216 :UnoControlTabPageContainer_Base(rxContext
)
217 ,m_aTabPageListeners( *this )
221 OUString
UnoControlTabPageContainer::GetComponentServiceName()
223 return OUString("TabPageContainer");
226 void SAL_CALL
UnoControlTabPageContainer::dispose( )
228 lang::EventObject aEvt
;
229 aEvt
.Source
= static_cast<cppu::OWeakObject
*>(this);
230 m_aTabPageListeners
.disposeAndClear( aEvt
);
231 UnoControl::dispose();
234 void UnoControlTabPageContainer::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
)
236 UnoControlBase::createPeer( rxToolkit
, rParentPeer
);
238 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
239 if ( m_aTabPageListeners
.getLength() )
240 xTPContainer
->addTabPageContainerListener(&m_aTabPageListeners
);
246 ::sal_Int16 SAL_CALL
UnoControlTabPageContainer::getActiveTabPageID()
248 SolarMutexGuard aSolarGuard
;
249 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
250 return xTPContainer
->getActiveTabPageID();
252 void SAL_CALL
UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid
)
254 SolarMutexGuard aSolarGuard
;
255 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
256 xTPContainer
->setActiveTabPageID(_activetabpageid
);
258 ::sal_Int16 SAL_CALL
UnoControlTabPageContainer::getTabPageCount( )
260 SolarMutexGuard aSolarGuard
;
261 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
262 return xTPContainer
->getTabPageCount();
264 sal_Bool SAL_CALL
UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex
)
266 SolarMutexGuard aSolarGuard
;
267 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
268 return xTPContainer
->isTabPageActive(tabPageIndex
);
270 Reference
< css::awt::tab::XTabPage
> SAL_CALL
UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex
)
272 SolarMutexGuard aSolarGuard
;
273 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
274 return xTPContainer
->getTabPage(tabPageIndex
);
276 Reference
< css::awt::tab::XTabPage
> SAL_CALL
UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID
)
278 SolarMutexGuard aSolarGuard
;
279 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
280 return xTPContainer
->getTabPageByID(tabPageID
);
282 void SAL_CALL
UnoControlTabPageContainer::addTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
284 m_aTabPageListeners
.addInterface( listener
);
285 if( getPeer().is() && m_aTabPageListeners
.getLength() == 1 )
287 uno::Reference
< awt::tab::XTabPageContainer
> xTabPageContainer( getPeer(), uno::UNO_QUERY
);
288 xTabPageContainer
->addTabPageContainerListener( &m_aTabPageListeners
);
291 void SAL_CALL
UnoControlTabPageContainer::removeTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
293 if( getPeer().is() && m_aTabPageListeners
.getLength() == 1 )
295 uno::Reference
< awt::tab::XTabPageContainer
> xTabPageContainer( getPeer(), uno::UNO_QUERY
);
296 xTabPageContainer
->addTabPageContainerListener( &m_aTabPageListeners
);
298 m_aTabPageListeners
.removeInterface( listener
);
301 void UnoControlTabPageContainer::updateFromModel()
303 UnoControlTabPageContainer_Base::updateFromModel();
305 throw RuntimeException("No peer for tabpage container!");
306 Reference
< XContainerListener
> xContainerListener( getPeer(), UNO_QUERY
);
307 ENSURE_OR_RETURN_VOID( xContainerListener
.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
309 ContainerEvent aEvent
;
310 aEvent
.Source
= getModel();
311 Sequence
< Reference
< XControl
> > aControls
= getControls();
312 const Reference
< XControl
>* pCtrls
= aControls
.getConstArray();
313 const Reference
< XControl
>* pCtrlsEnd
= pCtrls
+ aControls
.getLength();
315 for ( ; pCtrls
< pCtrlsEnd
; ++pCtrls
)
317 aEvent
.Element
<<= *pCtrls
;
318 xContainerListener
->elementInserted( aEvent
);
321 void SAL_CALL
UnoControlTabPageContainer::addControl( const OUString
& Name
, const Reference
< css::awt::XControl
>& Control
)
323 SolarMutexGuard aSolarGuard
;
324 ControlContainerBase::addControl(Name
,Control
);
326 throw RuntimeException("No peer for tabpage container!");
327 Reference
< XContainerListener
> xContainerListener( getPeer(), UNO_QUERY
);
328 ContainerEvent aEvent
;
329 aEvent
.Source
= getModel();
330 aEvent
.Element
<<= Control
;
331 xContainerListener
->elementInserted( aEvent
);
334 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
335 stardiv_Toolkit_UnoControlTabPageContainerModel_get_implementation(
336 css::uno::XComponentContext
*context
,
337 css::uno::Sequence
<css::uno::Any
> const &)
339 return cppu::acquire(new UnoControlTabPageContainerModel(context
));
342 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
343 stardiv_Toolkit_UnoControlTabPageContainer_get_implementation(
344 css::uno::XComponentContext
*context
,
345 css::uno::Sequence
<css::uno::Any
> const &)
347 return cppu::acquire(new UnoControlTabPageContainer(context
));
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */