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
* pHelper
= nullptr;
87 css::uno::Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
88 pHelper
= new UnoPropertyArrayHelper( aIDs
);
92 Reference
< css::beans::XPropertySetInfo
> UnoControlTabPageContainerModel::getPropertySetInfo( )
94 static Reference
< css::beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
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
) );
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
& )
124 catch( const Exception
& )
126 DBG_UNHANDLED_EXCEPTION("toolkit.controls");
132 Reference
< XTabPageModel
> SAL_CALL
UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID
)
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
)
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 css::uno::Any
& aElement
)
149 SolarMutexGuard aSolarGuard
;
150 uno::Reference
< XTabPageModel
> xTabPageModel
;
151 if(!(aElement
>>= xTabPageModel
))
152 throw IllegalArgumentException( WRONG_TYPE_EXCEPTION
, static_cast<OWeakObject
*>(this), 2 );
154 if ( sal_Int32( m_aTabPageVector
.size()) ==nIndex
)
155 m_aTabPageVector
.push_back( xTabPageModel
);
156 else if ( sal_Int32( m_aTabPageVector
.size()) > nIndex
)
158 std::vector
< uno::Reference
< XTabPageModel
> >::iterator aIter
= m_aTabPageVector
.begin();
160 m_aTabPageVector
.insert( aIter
, xTabPageModel
);
163 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject
*>(this) );
164 ContainerEvent aEvent
;
165 aEvent
.Source
= *this;
166 aEvent
.Element
= aElement
;
167 aEvent
.Accessor
<<= OUString::number(nIndex
);
168 maContainerListeners
.elementInserted( aEvent
);
172 void SAL_CALL
UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32
/*Index*/ )
176 void SAL_CALL
UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32
/*Index*/, const uno::Any
& /*Element*/ )
181 ::sal_Int32 SAL_CALL
UnoControlTabPageContainerModel::getCount( )
183 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
184 return sal_Int32( m_aTabPageVector
.size());
187 uno::Any SAL_CALL
UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex
)
189 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
190 if ( nIndex
< 0 || nIndex
> sal_Int32(m_aTabPageVector
.size()) )
191 throw lang::IndexOutOfBoundsException();
192 return uno::makeAny(m_aTabPageVector
[nIndex
]);
196 uno::Type SAL_CALL
UnoControlTabPageContainerModel::getElementType( )
198 return cppu::UnoType
<css::awt::XControlModel
>::get();
201 sal_Bool SAL_CALL
UnoControlTabPageContainerModel::hasElements( )
203 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
204 return !m_aTabPageVector
.empty();
207 void UnoControlTabPageContainerModel::addContainerListener( const Reference
< XContainerListener
>& l
)
209 maContainerListeners
.addInterface( l
);
212 void UnoControlTabPageContainerModel::removeContainerListener( const Reference
< XContainerListener
>& l
)
214 maContainerListeners
.removeInterface( l
);
218 // class UnoControlTabPageContainer
220 UnoControlTabPageContainer::UnoControlTabPageContainer( const uno::Reference
< uno::XComponentContext
>& rxContext
)
221 :UnoControlTabPageContainer_Base(rxContext
)
222 ,m_aTabPageListeners( *this )
226 OUString
UnoControlTabPageContainer::GetComponentServiceName()
228 return OUString("TabPageContainer");
231 void SAL_CALL
UnoControlTabPageContainer::dispose( )
233 lang::EventObject aEvt
;
234 aEvt
.Source
= static_cast<cppu::OWeakObject
*>(this);
235 m_aTabPageListeners
.disposeAndClear( aEvt
);
236 UnoControl::dispose();
239 void UnoControlTabPageContainer::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
)
241 UnoControlBase::createPeer( rxToolkit
, rParentPeer
);
243 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
244 if ( m_aTabPageListeners
.getLength() )
245 xTPContainer
->addTabPageContainerListener(&m_aTabPageListeners
);
251 ::sal_Int16 SAL_CALL
UnoControlTabPageContainer::getActiveTabPageID()
253 SolarMutexGuard aSolarGuard
;
254 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
255 return xTPContainer
->getActiveTabPageID();
257 void SAL_CALL
UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid
)
259 SolarMutexGuard aSolarGuard
;
260 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
261 xTPContainer
->setActiveTabPageID(_activetabpageid
);
263 ::sal_Int16 SAL_CALL
UnoControlTabPageContainer::getTabPageCount( )
265 SolarMutexGuard aSolarGuard
;
266 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
267 return xTPContainer
->getTabPageCount();
269 sal_Bool SAL_CALL
UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex
)
271 SolarMutexGuard aSolarGuard
;
272 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
273 return xTPContainer
->isTabPageActive(tabPageIndex
);
275 Reference
< css::awt::tab::XTabPage
> SAL_CALL
UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex
)
277 SolarMutexGuard aSolarGuard
;
278 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
279 return xTPContainer
->getTabPage(tabPageIndex
);
281 Reference
< css::awt::tab::XTabPage
> SAL_CALL
UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID
)
283 SolarMutexGuard aSolarGuard
;
284 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
285 return xTPContainer
->getTabPageByID(tabPageID
);
287 void SAL_CALL
UnoControlTabPageContainer::addTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
289 m_aTabPageListeners
.addInterface( listener
);
290 if( getPeer().is() && m_aTabPageListeners
.getLength() == 1 )
292 uno::Reference
< awt::tab::XTabPageContainer
> xTabPageContainer( getPeer(), uno::UNO_QUERY
);
293 xTabPageContainer
->addTabPageContainerListener( &m_aTabPageListeners
);
296 void SAL_CALL
UnoControlTabPageContainer::removeTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
298 if( getPeer().is() && m_aTabPageListeners
.getLength() == 1 )
300 uno::Reference
< awt::tab::XTabPageContainer
> xTabPageContainer( getPeer(), uno::UNO_QUERY
);
301 xTabPageContainer
->addTabPageContainerListener( &m_aTabPageListeners
);
303 m_aTabPageListeners
.removeInterface( listener
);
306 void UnoControlTabPageContainer::updateFromModel()
308 UnoControlTabPageContainer_Base::updateFromModel();
309 Reference
< XContainerListener
> xContainerListener( getPeer(), UNO_QUERY
);
310 ENSURE_OR_RETURN_VOID( xContainerListener
.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
312 ContainerEvent aEvent
;
313 aEvent
.Source
= getModel();
314 Sequence
< Reference
< XControl
> > aControls
= getControls();
315 const Reference
< XControl
>* pCtrls
= aControls
.getConstArray();
316 const Reference
< XControl
>* pCtrlsEnd
= pCtrls
+ aControls
.getLength();
318 for ( ; pCtrls
< pCtrlsEnd
; ++pCtrls
)
320 aEvent
.Element
<<= *pCtrls
;
321 xContainerListener
->elementInserted( aEvent
);
324 void SAL_CALL
UnoControlTabPageContainer::addControl( const OUString
& Name
, const Reference
< css::awt::XControl
>& Control
)
326 SolarMutexGuard aSolarGuard
;
327 ControlContainerBase::addControl(Name
,Control
);
328 Reference
< XContainerListener
> xContainerListener( getPeer(), UNO_QUERY
);
329 ContainerEvent aEvent
;
330 aEvent
.Source
= getModel();
331 aEvent
.Element
<<= Control
;
332 xContainerListener
->elementInserted( aEvent
);
335 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
336 stardiv_Toolkit_UnoControlTabPageContainerModel_get_implementation(
337 css::uno::XComponentContext
*context
,
338 css::uno::Sequence
<css::uno::Any
> const &)
340 return cppu::acquire(new UnoControlTabPageContainerModel(context
));
343 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
344 stardiv_Toolkit_UnoControlTabPageContainer_get_implementation(
345 css::uno::XComponentContext
*context
,
346 css::uno::Sequence
<css::uno::Any
> const &)
348 return cppu::acquire(new UnoControlTabPageContainer(context
));
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */