Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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 :
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>
30 :
31 : #include <osl/diagnose.h>
32 : #include <tools/diagnose_ex.h>
33 : #include <vcl/svapp.hxx>
34 :
35 : #include "helper/unopropertyarrayhelper.hxx"
36 :
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;
44 :
45 : #define WRONG_TYPE_EXCEPTION "Type must be ::com::sun::star::awt::tab::XTabPageModel!"
46 :
47 : // class UnoControlTabPageContainerModel
48 :
49 2 : UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference< XComponentContext >& i_factory )
50 : :UnoControlTabPageContainerModel_Base( i_factory )
51 2 : ,maContainerListeners( *this )
52 : {
53 2 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
54 2 : ImplRegisterProperty( BASEPROPERTY_BORDER );
55 2 : ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
56 2 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
57 2 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
58 2 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
59 2 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
60 2 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
61 2 : ImplRegisterProperty( BASEPROPERTY_TEXT );
62 2 : }
63 :
64 0 : OUString UnoControlTabPageContainerModel::getServiceName() throw(RuntimeException, std::exception)
65 : {
66 0 : return OUString("com.sun.star.awt.tab.UnoControlTabPageContainerModel");
67 : }
68 :
69 18 : uno::Any UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
70 : {
71 18 : switch(nPropId)
72 : {
73 : case BASEPROPERTY_DEFAULTCONTROL:
74 2 : return uno::makeAny( OUString("com.sun.star.awt.tab.UnoControlTabPageContainer") );
75 : case BASEPROPERTY_BORDER:
76 2 : return uno::makeAny((sal_Int16) 0); // No Border
77 : default:
78 14 : return UnoControlModel::ImplGetDefaultValue( nPropId );
79 : }
80 : }
81 :
82 0 : ::cppu::IPropertyArrayHelper& UnoControlTabPageContainerModel::getInfoHelper()
83 : {
84 : static UnoPropertyArrayHelper* pHelper = NULL;
85 0 : if ( !pHelper )
86 : {
87 0 : com::sun::star::uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
88 0 : pHelper = new UnoPropertyArrayHelper( aIDs );
89 : }
90 0 : return *pHelper;
91 : }
92 0 : Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlTabPageContainerModel::getPropertySetInfo( ) throw(RuntimeException, std::exception)
93 : {
94 0 : static Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
95 0 : return xInfo;
96 : }
97 :
98 : namespace
99 : {
100 0 : Reference< XTabPageModel > lcl_createTabPageModel( Reference<XComponentContext> const & i_context,
101 : Sequence< Any > const & i_initArguments, Reference< XPropertySet > const & i_parentModel )
102 : {
103 : try
104 : {
105 0 : Reference< XPropertySetInfo > const xPSI( i_parentModel->getPropertySetInfo() );
106 0 : bool const isGeometryControlModel = xPSI.is() && xPSI->hasPropertyByName("PositionX");
107 :
108 0 : Reference< XInterface > xInstance;
109 0 : if ( isGeometryControlModel )
110 0 : xInstance = *( new OGeometryControlModel< UnoControlTabPageModel >( i_context ) );
111 : else
112 0 : xInstance = *( new UnoControlTabPageModel( i_context ) );
113 :
114 0 : Reference< XTabPageModel > const xTabPageModel( xInstance, UNO_QUERY_THROW );
115 0 : Reference< XInitialization > const xInit( xTabPageModel, UNO_QUERY_THROW );
116 0 : xInit->initialize( i_initArguments );
117 :
118 0 : return xTabPageModel;
119 : }
120 0 : catch( const RuntimeException& )
121 : {
122 0 : throw;
123 : }
124 0 : catch( const Exception& )
125 : {
126 : DBG_UNHANDLED_EXCEPTION();
127 : }
128 0 : return NULL;
129 : }
130 : }
131 :
132 0 : Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID ) throw (RuntimeException, std::exception)
133 : {
134 0 : Sequence< Any > aInitArgs(1);
135 0 : aInitArgs[0] <<= i_tabPageID;
136 0 : return lcl_createTabPageModel( m_xContext, aInitArgs, this );
137 : }
138 :
139 0 : Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::loadTabPage( ::sal_Int16 i_tabPageID, const OUString& i_resourceURL ) throw (RuntimeException, std::exception)
140 : {
141 0 : Sequence< Any > aInitArgs(2);
142 0 : aInitArgs[0] <<= i_tabPageID;
143 0 : aInitArgs[1] <<= i_resourceURL;
144 0 : return lcl_createTabPageModel( m_xContext, aInitArgs, this );
145 : }
146 :
147 0 : void SAL_CALL UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex, const com::sun::star::uno::Any& aElement) throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, uno::RuntimeException, std::exception)
148 : {
149 0 : SolarMutexGuard aSolarGuard;
150 0 : uno::Reference < XTabPageModel > xTabPageModel;
151 0 : if(aElement >>= xTabPageModel)
152 : {
153 0 : if ( sal_Int32( m_aTabPageVector.size()) ==nIndex )
154 0 : m_aTabPageVector.push_back( xTabPageModel );
155 0 : else if ( sal_Int32( m_aTabPageVector.size()) > nIndex )
156 : {
157 0 : std::vector< uno::Reference< XTabPageModel > >::iterator aIter = m_aTabPageVector.begin();
158 0 : aIter += nIndex;
159 0 : m_aTabPageVector.insert( aIter, xTabPageModel );
160 : }
161 : else
162 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
163 0 : ContainerEvent aEvent;
164 0 : aEvent.Source = *this;
165 0 : aEvent.Element <<= aElement;
166 0 : aEvent.Accessor <<= OUString::number(nIndex);
167 0 : maContainerListeners.elementInserted( aEvent );
168 : }
169 : else
170 0 : throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, (OWeakObject *)this, 2 );
171 0 : }
172 :
173 0 : void SAL_CALL UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
174 : {
175 0 : }
176 : // XIndexReplace
177 0 : void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Index*/, const uno::Any& /*Element*/ ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
178 : {
179 0 : }
180 :
181 : // XIndexAccess
182 0 : ::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount( ) throw (uno::RuntimeException, std::exception)
183 : {
184 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
185 0 : return sal_Int32( m_aTabPageVector.size());
186 : }
187 :
188 0 : uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
189 : {
190 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
191 0 : if ( nIndex < 0 || nIndex > sal_Int32(m_aTabPageVector.size()) )
192 0 : throw lang::IndexOutOfBoundsException();
193 0 : return uno::makeAny(m_aTabPageVector[nIndex]);
194 : }
195 :
196 : // XElementAccess
197 0 : uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType( ) throw (uno::RuntimeException, std::exception)
198 : {
199 0 : return cppu::UnoType<com::sun::star::awt::XControlModel>::get();
200 : }
201 :
202 0 : sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements( ) throw (uno::RuntimeException, std::exception)
203 : {
204 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
205 0 : return !m_aTabPageVector.empty();
206 : }
207 : // XContainer
208 0 : void UnoControlTabPageContainerModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException, std::exception)
209 : {
210 0 : maContainerListeners.addInterface( l );
211 0 : }
212 :
213 0 : void UnoControlTabPageContainerModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException, std::exception)
214 : {
215 0 : maContainerListeners.removeInterface( l );
216 0 : }
217 :
218 :
219 : // class UnoControlTabPageContainer
220 :
221 0 : UnoControlTabPageContainer::UnoControlTabPageContainer( const uno::Reference< uno::XComponentContext >& rxContext )
222 : :UnoControlTabPageContainer_Base(rxContext)
223 0 : ,m_aTabPageListeners( *this )
224 : {
225 0 : }
226 :
227 0 : OUString UnoControlTabPageContainer::GetComponentServiceName()
228 : {
229 0 : return OUString("TabPageContainer");
230 : }
231 :
232 0 : void SAL_CALL UnoControlTabPageContainer::dispose( ) throw(RuntimeException, std::exception)
233 : {
234 0 : lang::EventObject aEvt;
235 0 : aEvt.Source = (::cppu::OWeakObject*)this;
236 0 : m_aTabPageListeners.disposeAndClear( aEvt );
237 0 : UnoControl::dispose();
238 0 : }
239 :
240 0 : void UnoControlTabPageContainer::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException, std::exception)
241 : {
242 0 : UnoControlBase::createPeer( rxToolkit, rParentPeer );
243 :
244 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
245 0 : if ( m_aTabPageListeners.getLength() )
246 0 : xTPContainer->addTabPageContainerListener(&m_aTabPageListeners);
247 0 : }
248 :
249 :
250 : // XTabPageContainer
251 :
252 0 : ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getActiveTabPageID() throw (RuntimeException, std::exception)
253 : {
254 0 : SolarMutexGuard aSolarGuard;
255 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
256 0 : return xTPContainer->getActiveTabPageID();
257 : }
258 0 : void SAL_CALL UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException, std::exception)
259 : {
260 0 : SolarMutexGuard aSolarGuard;
261 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
262 0 : xTPContainer->setActiveTabPageID(_activetabpageid);
263 0 : }
264 0 : ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getTabPageCount( ) throw (RuntimeException, std::exception)
265 : {
266 0 : SolarMutexGuard aSolarGuard;
267 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
268 0 : return xTPContainer->getTabPageCount();
269 : }
270 0 : sal_Bool SAL_CALL UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException, std::exception)
271 : {
272 0 : SolarMutexGuard aSolarGuard;
273 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
274 0 : return xTPContainer->isTabPageActive(tabPageIndex);
275 : }
276 0 : Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException, std::exception)
277 : {
278 0 : SolarMutexGuard aSolarGuard;
279 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
280 0 : return xTPContainer->getTabPage(tabPageIndex);
281 : }
282 0 : Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException, std::exception)
283 : {
284 0 : SolarMutexGuard aSolarGuard;
285 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
286 0 : return xTPContainer->getTabPageByID(tabPageID);
287 : }
288 0 : void SAL_CALL UnoControlTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException, std::exception)
289 : {
290 0 : m_aTabPageListeners.addInterface( listener );
291 0 : if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
292 : {
293 0 : uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
294 0 : xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
295 : }
296 0 : }
297 0 : void SAL_CALL UnoControlTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException, std::exception)
298 : {
299 0 : if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
300 : {
301 0 : uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
302 0 : xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
303 : }
304 0 : m_aTabPageListeners.removeInterface( listener );
305 0 : }
306 :
307 0 : void UnoControlTabPageContainer::updateFromModel()
308 : {
309 0 : UnoControlTabPageContainer_Base::updateFromModel();
310 0 : Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
311 0 : ENSURE_OR_RETURN_VOID( xContainerListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
312 :
313 0 : ContainerEvent aEvent;
314 0 : aEvent.Source = getModel();
315 0 : Sequence< Reference< XControl > > aControls = getControls();
316 0 : const Reference< XControl >* pCtrls = aControls.getConstArray();
317 0 : const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
318 :
319 0 : for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
320 : {
321 0 : aEvent.Element <<= *pCtrls;
322 0 : xContainerListener->elementInserted( aEvent );
323 0 : }
324 : }
325 0 : void SAL_CALL UnoControlTabPageContainer::addControl( const OUString& Name, const Reference< ::com::sun::star::awt::XControl >& Control ) throw (RuntimeException, std::exception)
326 : {
327 0 : SolarMutexGuard aSolarGuard;
328 0 : ControlContainerBase::addControl(Name,Control);
329 0 : Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
330 0 : ContainerEvent aEvent;
331 0 : aEvent.Source = getModel();
332 0 : aEvent.Element <<= Control;
333 0 : xContainerListener->elementInserted( aEvent );
334 0 : }
335 :
336 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
337 0 : stardiv_Toolkit_UnoControlTabPageContainerModel_get_implementation(
338 : css::uno::XComponentContext *context,
339 : css::uno::Sequence<css::uno::Any> const &)
340 : {
341 0 : return cppu::acquire(new UnoControlTabPageContainerModel(context));
342 : }
343 :
344 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
345 0 : stardiv_Toolkit_UnoControlTabPageContainer_get_implementation(
346 : css::uno::XComponentContext *context,
347 : css::uno::Sequence<css::uno::Any> const &)
348 : {
349 0 : return cppu::acquire(new UnoControlTabPageContainer(context));
350 1227 : }
351 :
352 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|