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>
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 ::rtl::OUString
;
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!"
46 // ----------------------------------------------------
47 // class UnoControlTabPageContainerModel
48 // ----------------------------------------------------
49 UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference
< XMultiServiceFactory
>& 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 ::rtl::OUString
UnoControlTabPageContainerModel::getServiceName() throw(RuntimeException
)
66 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainerModel
);
69 uno::Any
UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
73 case BASEPROPERTY_DEFAULTCONTROL
:
74 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_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
= NULL
;
87 com::sun::star::uno::Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
88 pHelper
= new UnoPropertyArrayHelper( aIDs
);
92 Reference
< ::com::sun::star::beans::XPropertySetInfo
> UnoControlTabPageContainerModel::getPropertySetInfo( ) throw(RuntimeException
)
94 static Reference
< ::com::sun::star::beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
100 Reference
< XTabPageModel
> lcl_createTabPageModel( ::comphelper::ComponentContext
const & i_context
,
101 Sequence
< Any
> const & i_initArguments
, Reference
< XPropertySet
> const & i_parentModel
)
105 Reference
< XPropertySet
> const xParentDelegator( i_parentModel
, UNO_QUERY_THROW
);
106 Reference
< XPropertySetInfo
> const xPSI( xParentDelegator
->getPropertySetInfo() );
107 bool const isGeometryControlModel
= xPSI
.is() && xPSI
->hasPropertyByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ) );
109 Reference
< XInterface
> xInstance
;
110 if ( isGeometryControlModel
)
111 xInstance
= *( new OGeometryControlModel
< UnoControlTabPageModel
>( i_context
.getLegacyServiceFactory() ) );
113 xInstance
= *( new UnoControlTabPageModel( i_context
.getLegacyServiceFactory() ) );
115 Reference
< XTabPageModel
> const xTabPageModel( xInstance
, UNO_QUERY_THROW
);
116 Reference
< XInitialization
> const xInit( xTabPageModel
, UNO_QUERY_THROW
);
117 xInit
->initialize( i_initArguments
);
119 return xTabPageModel
;
121 catch( const RuntimeException
& )
125 catch( const Exception
& )
127 DBG_UNHANDLED_EXCEPTION();
133 Reference
< XTabPageModel
> SAL_CALL
UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID
) throw (RuntimeException
)
135 Sequence
< Any
> aInitArgs(1);
136 aInitArgs
[0] <<= i_tabPageID
;
137 return lcl_createTabPageModel( maContext
, aInitArgs
, this );
140 Reference
< XTabPageModel
> SAL_CALL
UnoControlTabPageContainerModel::loadTabPage( ::sal_Int16 i_tabPageID
, const ::rtl::OUString
& i_resourceURL
) throw (RuntimeException
)
142 Sequence
< Any
> aInitArgs(2);
143 aInitArgs
[0] <<= i_tabPageID
;
144 aInitArgs
[1] <<= i_resourceURL
;
145 return lcl_createTabPageModel( maContext
, aInitArgs
, this );
148 void SAL_CALL
UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex
, const com::sun::star::uno::Any
& aElement
) throw (IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, uno::RuntimeException
)
150 SolarMutexGuard aSolarGuard
;
151 uno::Reference
< XTabPageModel
> xTabPageModel
;
152 if(aElement
>>= xTabPageModel
)
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( ::rtl::OUString(), (OWeakObject
*)this );
164 ContainerEvent aEvent
;
165 aEvent
.Source
= *this;
166 aEvent
.Element
<<= aElement
;
167 aEvent
.Accessor
<<= ::rtl::OUString::valueOf(nIndex
);
168 maContainerListeners
.elementInserted( aEvent
);
171 throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION
)),
172 (OWeakObject
*)this, 2 );
174 // -----------------------------------------------------------------------------
175 void SAL_CALL
UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32
/*Index*/ ) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
179 void SAL_CALL
UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32
/*Index*/, const uno::Any
& /*Element*/ ) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
182 // -----------------------------------------------------------------------------
184 ::sal_Int32 SAL_CALL
UnoControlTabPageContainerModel::getCount( ) throw (uno::RuntimeException
)
186 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
187 return sal_Int32( m_aTabPageVector
.size());
189 // -----------------------------------------------------------------------------
190 uno::Any SAL_CALL
UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
192 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
193 if ( nIndex
< 0 || nIndex
> sal_Int32(m_aTabPageVector
.size()) )
194 throw lang::IndexOutOfBoundsException();
195 return uno::makeAny(m_aTabPageVector
[nIndex
]);
197 // -----------------------------------------------------------------------------
199 uno::Type SAL_CALL
UnoControlTabPageContainerModel::getElementType( ) throw (uno::RuntimeException
)
201 return ::getCppuType(static_cast< Reference
< com::sun::star::awt::XControlModel
>* >(NULL
));
203 // -----------------------------------------------------------------------------
204 ::sal_Bool SAL_CALL
UnoControlTabPageContainerModel::hasElements( ) throw (uno::RuntimeException
)
206 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
207 return !m_aTabPageVector
.empty();
210 void UnoControlTabPageContainerModel::addContainerListener( const Reference
< XContainerListener
>& l
) throw(RuntimeException
)
212 maContainerListeners
.addInterface( l
);
215 void UnoControlTabPageContainerModel::removeContainerListener( const Reference
< XContainerListener
>& l
) throw(RuntimeException
)
217 maContainerListeners
.removeInterface( l
);
220 // ----------------------------------------------------
221 // class UnoControlTabPageContainer
222 // ----------------------------------------------------
223 UnoControlTabPageContainer::UnoControlTabPageContainer( const Reference
< XMultiServiceFactory
>& i_factory
)
224 :UnoControlTabPageContainer_Base( i_factory
)
225 ,m_aTabPageListeners( *this )
229 OUString
UnoControlTabPageContainer::GetComponentServiceName()
231 return OUString(RTL_CONSTASCII_USTRINGPARAM("TabPageContainer"));
234 void SAL_CALL
UnoControlTabPageContainer::dispose( ) throw(RuntimeException
)
236 lang::EventObject aEvt
;
237 aEvt
.Source
= (::cppu::OWeakObject
*)this;
238 m_aTabPageListeners
.disposeAndClear( aEvt
);
239 UnoControl::dispose();
242 void UnoControlTabPageContainer::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
) throw(uno::RuntimeException
)
244 UnoControlBase::createPeer( rxToolkit
, rParentPeer
);
246 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
247 if ( m_aTabPageListeners
.getLength() )
248 xTPContainer
->addTabPageContainerListener(&m_aTabPageListeners
);
251 // -------------------------------------------------------------------
254 ::sal_Int16 SAL_CALL
UnoControlTabPageContainer::getActiveTabPageID() throw (RuntimeException
)
256 SolarMutexGuard aSolarGuard
;
257 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
258 return xTPContainer
->getActiveTabPageID();
260 void SAL_CALL
UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid
) throw (RuntimeException
)
262 SolarMutexGuard aSolarGuard
;
263 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
264 xTPContainer
->setActiveTabPageID(_activetabpageid
);
266 ::sal_Int16 SAL_CALL
UnoControlTabPageContainer::getTabPageCount( ) throw (RuntimeException
)
268 SolarMutexGuard aSolarGuard
;
269 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
270 return xTPContainer
->getTabPageCount();
272 ::sal_Bool SAL_CALL
UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex
) throw (RuntimeException
)
274 SolarMutexGuard aSolarGuard
;
275 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
276 return xTPContainer
->isTabPageActive(tabPageIndex
);
278 Reference
< ::com::sun::star::awt::tab::XTabPage
> SAL_CALL
UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex
) throw (RuntimeException
)
280 SolarMutexGuard aSolarGuard
;
281 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
282 return xTPContainer
->getTabPage(tabPageIndex
);
284 Reference
< ::com::sun::star::awt::tab::XTabPage
> SAL_CALL
UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID
) throw (RuntimeException
)
286 SolarMutexGuard aSolarGuard
;
287 Reference
< XTabPageContainer
> xTPContainer( getPeer(), UNO_QUERY_THROW
);
288 return xTPContainer
->getTabPageByID(tabPageID
);
290 void SAL_CALL
UnoControlTabPageContainer::addTabPageContainerListener( const Reference
< ::com::sun::star::awt::tab::XTabPageContainerListener
>& listener
) throw (RuntimeException
)
292 m_aTabPageListeners
.addInterface( 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
);
299 void SAL_CALL
UnoControlTabPageContainer::removeTabPageContainerListener( const Reference
< ::com::sun::star::awt::tab::XTabPageContainerListener
>& listener
) throw (RuntimeException
)
301 if( getPeer().is() && m_aTabPageListeners
.getLength() == 1 )
303 uno::Reference
< awt::tab::XTabPageContainer
> xTabPageContainer( getPeer(), uno::UNO_QUERY
);
304 xTabPageContainer
->addTabPageContainerListener( &m_aTabPageListeners
);
306 m_aTabPageListeners
.removeInterface( listener
);
309 void UnoControlTabPageContainer::updateFromModel()
311 UnoControlTabPageContainer_Base::updateFromModel();
312 Reference
< XContainerListener
> xContainerListener( getPeer(), UNO_QUERY
);
313 ENSURE_OR_RETURN_VOID( xContainerListener
.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
315 ContainerEvent aEvent
;
316 aEvent
.Source
= getModel();
317 Sequence
< Reference
< XControl
> > aControls
= getControls();
318 const Reference
< XControl
>* pCtrls
= aControls
.getConstArray();
319 const Reference
< XControl
>* pCtrlsEnd
= pCtrls
+ aControls
.getLength();
321 for ( ; pCtrls
< pCtrlsEnd
; ++pCtrls
)
323 aEvent
.Element
<<= *pCtrls
;
324 xContainerListener
->elementInserted( aEvent
);
327 void SAL_CALL
UnoControlTabPageContainer::addControl( const ::rtl::OUString
& Name
, const Reference
< ::com::sun::star::awt::XControl
>& Control
) throw (RuntimeException
)
329 SolarMutexGuard aSolarGuard
;
330 ControlContainerBase::addControl(Name
,Control
);
331 Reference
< XContainerListener
> xContainerListener( getPeer(), UNO_QUERY
);
332 ContainerEvent aEvent
;
333 aEvent
.Source
= getModel();
334 aEvent
.Element
<<= Control
;
335 xContainerListener
->elementInserted( aEvent
);
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */