Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <toolkit/controls/tabpagecontainer.hxx>
31 : :
32 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 : : #include <toolkit/helper/unopropertyarrayhelper.hxx>
34 : : #include <toolkit/helper/property.hxx>
35 : : #include <toolkit/controls/geometrycontrolmodel.hxx>
36 : : #include <com/sun/star/awt/XVclWindowPeer.hpp>
37 : : #include <comphelper/processfactory.hxx>
38 : : #include <osl/diagnose.h>
39 : : #include <vcl/svapp.hxx>
40 : : #include <com/sun/star/awt/XControlModel.hpp>
41 : : #include <tools/diagnose_ex.h>
42 : :
43 : : using ::rtl::OUString;
44 : : using namespace ::com::sun::star;
45 : : using namespace ::com::sun::star::uno;
46 : : using namespace ::com::sun::star::lang;
47 : : using namespace ::com::sun::star::beans;
48 : : using namespace ::com::sun::star::container;
49 : : using namespace ::com::sun::star::view;
50 : :
51 : : #define WRONG_TYPE_EXCEPTION "Type must be ::com::sun::star::awt::tab::XTabPageModel!"
52 : : // ----------------------------------------------------
53 : : // class UnoControlTabPageContainerModel
54 : : // ----------------------------------------------------
55 : 2 : UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference< XMultiServiceFactory >& i_factory )
56 : : :UnoControlTabPageContainerModel_Base( i_factory )
57 [ + - ][ + - ]: 2 : ,maContainerListeners( *this )
58 : : {
59 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
60 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_BORDER );
61 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
62 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
63 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
64 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
65 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
66 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
67 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_TEXT );
68 : 2 : }
69 : :
70 : 0 : ::rtl::OUString UnoControlTabPageContainerModel::getServiceName() throw(RuntimeException)
71 : : {
72 : 0 : return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainerModel );
73 : : }
74 : :
75 : 18 : uno::Any UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
76 : : {
77 [ + + + ]: 18 : switch(nPropId)
78 : : {
79 : : case BASEPROPERTY_DEFAULTCONTROL:
80 [ + - ]: 2 : return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainer ) );
81 : : case BASEPROPERTY_BORDER:
82 [ + - ]: 2 : return uno::makeAny((sal_Int16) 0); // No Border
83 : : default:
84 : 18 : return UnoControlModel::ImplGetDefaultValue( nPropId );
85 : : }
86 : : }
87 : :
88 : 0 : ::cppu::IPropertyArrayHelper& UnoControlTabPageContainerModel::getInfoHelper()
89 : : {
90 : : static UnoPropertyArrayHelper* pHelper = NULL;
91 [ # # ]: 0 : if ( !pHelper )
92 : : {
93 [ # # ]: 0 : com::sun::star::uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
94 [ # # ][ # # ]: 0 : pHelper = new UnoPropertyArrayHelper( aIDs );
95 : : }
96 : 0 : return *pHelper;
97 : : }
98 : 0 : Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlTabPageContainerModel::getPropertySetInfo( ) throw(RuntimeException)
99 : : {
100 [ # # ][ # # ]: 0 : static Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
[ # # ][ # # ]
[ # # ]
101 : 0 : return xInfo;
102 : : }
103 : :
104 : 0 : void SAL_CALL UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex, const com::sun::star::uno::Any& aElement) throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, uno::RuntimeException)
105 : : {
106 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
107 : 0 : uno::Reference < ::awt::tab::XTabPageModel > xTabPageModel;
108 [ # # ][ # # ]: 0 : if(aElement >>= xTabPageModel)
109 : : {
110 [ # # ]: 0 : if ( sal_Int32( m_aTabPageVector.size()) ==nIndex )
111 [ # # ]: 0 : m_aTabPageVector.push_back( xTabPageModel );
112 [ # # ]: 0 : else if ( sal_Int32( m_aTabPageVector.size()) > nIndex )
113 : : {
114 : 0 : std::vector< uno::Reference< ::awt::tab::XTabPageModel > >::iterator aIter = m_aTabPageVector.begin();
115 : 0 : aIter += nIndex;
116 [ # # ]: 0 : m_aTabPageVector.insert( aIter, xTabPageModel );
117 : : }
118 : : else
119 [ # # ][ # # ]: 0 : throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
120 [ # # ]: 0 : ContainerEvent aEvent;
121 [ # # ][ # # ]: 0 : aEvent.Source = *this;
122 [ # # ]: 0 : aEvent.Element <<= aElement;
123 [ # # ]: 0 : aEvent.Accessor <<= ::rtl::OUString::valueOf(nIndex);
124 [ # # ][ # # ]: 0 : maContainerListeners.elementInserted( aEvent );
125 : : }
126 : : else
127 : : throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
128 [ # # ][ # # ]: 0 : (OWeakObject *)this, 2 );
[ # # ][ # # ]
129 : 0 : }
130 : : // -----------------------------------------------------------------------------
131 : 0 : void SAL_CALL UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
132 : : {
133 : 0 : }
134 : : // XIndexReplace
135 : 0 : void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Index*/, const uno::Any& /*Element*/ ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
136 : : {
137 : 0 : }
138 : : // -----------------------------------------------------------------------------
139 : : // XIndexAccess
140 : 0 : ::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount( ) throw (uno::RuntimeException)
141 : : {
142 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
143 [ # # ]: 0 : return sal_Int32( m_aTabPageVector.size());
144 : : }
145 : : // -----------------------------------------------------------------------------
146 : 0 : uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
147 : : {
148 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
149 [ # # ][ # # ]: 0 : if ( nIndex < 0 || nIndex > sal_Int32(m_aTabPageVector.size()) )
[ # # ]
150 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
151 [ # # ][ # # ]: 0 : return uno::makeAny(m_aTabPageVector[nIndex]);
152 : : }
153 : : // -----------------------------------------------------------------------------
154 : : // XElementAccess
155 : 0 : uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType( ) throw (uno::RuntimeException)
156 : : {
157 : 0 : return ::getCppuType(static_cast< Reference< com::sun::star::awt::XControlModel>* >(NULL));
158 : : }
159 : : // -----------------------------------------------------------------------------
160 : 0 : ::sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements( ) throw (uno::RuntimeException)
161 : : {
162 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
163 [ # # ]: 0 : return !m_aTabPageVector.empty();
164 : : }
165 : : // XContainer
166 : 0 : void UnoControlTabPageContainerModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
167 : : {
168 : 0 : maContainerListeners.addInterface( l );
169 : 0 : }
170 : :
171 : 0 : void UnoControlTabPageContainerModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
172 : : {
173 : 0 : maContainerListeners.removeInterface( l );
174 : 0 : }
175 : :
176 : : // ----------------------------------------------------
177 : : // class UnoControlTabPageContainer
178 : : // ----------------------------------------------------
179 : 0 : UnoControlTabPageContainer::UnoControlTabPageContainer( const Reference< XMultiServiceFactory >& i_factory )
180 : : :UnoControlTabPageContainer_Base( i_factory )
181 [ # # ]: 0 : ,m_aTabPageListeners( *this )
182 : : {
183 : 0 : }
184 : :
185 : 0 : OUString UnoControlTabPageContainer::GetComponentServiceName()
186 : : {
187 : 0 : return OUString(RTL_CONSTASCII_USTRINGPARAM("TabPageContainer"));
188 : : }
189 : :
190 : 0 : void SAL_CALL UnoControlTabPageContainer::dispose( ) throw(RuntimeException)
191 : : {
192 [ # # ]: 0 : lang::EventObject aEvt;
193 [ # # ]: 0 : aEvt.Source = (::cppu::OWeakObject*)this;
194 [ # # ]: 0 : m_aTabPageListeners.disposeAndClear( aEvt );
195 [ # # ][ # # ]: 0 : UnoControl::dispose();
196 : 0 : }
197 : :
198 : 0 : void UnoControlTabPageContainer::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException)
199 : : {
200 [ # # ]: 0 : UnoControlBase::createPeer( rxToolkit, rParentPeer );
201 : :
202 [ # # ][ # # ]: 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
203 [ # # ][ # # ]: 0 : if ( m_aTabPageListeners.getLength() )
204 [ # # ][ # # ]: 0 : xTPContainer->addTabPageListener(&m_aTabPageListeners);
[ # # ]
205 : 0 : }
206 : :
207 : : // -------------------------------------------------------------------
208 : : // XTabPageContainer
209 : :
210 : 0 : ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getActiveTabPageID() throw (RuntimeException)
211 : : {
212 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
213 [ # # ][ # # ]: 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
214 [ # # ][ # # ]: 0 : return xTPContainer->getActiveTabPageID();
[ # # ]
215 : : }
216 : 0 : void SAL_CALL UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException)
217 : : {
218 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
219 [ # # ][ # # ]: 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
220 [ # # ][ # # ]: 0 : xTPContainer->setActiveTabPageID(_activetabpageid);
[ # # ]
221 : 0 : }
222 : 0 : ::sal_Int32 SAL_CALL UnoControlTabPageContainer::getTabPageCount( ) throw (RuntimeException)
223 : : {
224 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
225 [ # # ][ # # ]: 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
226 [ # # ][ # # ]: 0 : return xTPContainer->getTabPageCount();
[ # # ]
227 : : }
228 : 0 : ::sal_Bool SAL_CALL UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
229 : : {
230 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
231 [ # # ][ # # ]: 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
232 [ # # ][ # # ]: 0 : return xTPContainer->isTabPageActive(tabPageIndex);
[ # # ]
233 : : }
234 : 0 : Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
235 : : {
236 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
237 [ # # ][ # # ]: 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
238 [ # # ][ # # ]: 0 : return xTPContainer->getTabPage(tabPageIndex);
[ # # ]
239 : : }
240 : 0 : Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException)
241 : : {
242 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
243 [ # # ][ # # ]: 0 : Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
244 [ # # ][ # # ]: 0 : return xTPContainer->getTabPageByID(tabPageID);
[ # # ]
245 : : }
246 : 0 : void SAL_CALL UnoControlTabPageContainer::addTabPageListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
247 : : {
248 : 0 : m_aTabPageListeners.addInterface( listener );
249 [ # # ][ # # ]: 0 : if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
[ # # ][ # # ]
[ # # # # ]
[ # # ]
250 : : {
251 [ # # ][ # # ]: 0 : uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
252 [ # # ][ # # ]: 0 : xTabPageContainer->addTabPageListener( &m_aTabPageListeners );
[ # # ]
253 : : }
254 : 0 : }
255 : 0 : void SAL_CALL UnoControlTabPageContainer::removeTabPageListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
256 : : {
257 [ # # ][ # # ]: 0 : if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
258 : : {
259 [ # # ][ # # ]: 0 : uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
260 [ # # ][ # # ]: 0 : xTabPageContainer->addTabPageListener( &m_aTabPageListeners );
[ # # ]
261 : : }
262 : 0 : m_aTabPageListeners.removeInterface( listener );
263 : 0 : }
264 : :
265 : 0 : void UnoControlTabPageContainer::updateFromModel()
266 : : {
267 [ # # ]: 0 : UnoControlTabPageContainer_Base::updateFromModel();
268 [ # # ][ # # ]: 0 : Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
269 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( xContainerListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
270 : :
271 [ # # ]: 0 : ContainerEvent aEvent;
272 [ # # ][ # # ]: 0 : aEvent.Source = getModel();
273 [ # # ]: 0 : Sequence< Reference< XControl > > aControls = getControls();
274 : 0 : const Reference< XControl >* pCtrls = aControls.getConstArray();
275 : 0 : const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
276 : :
277 [ # # ]: 0 : for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
278 : : {
279 [ # # ]: 0 : aEvent.Element <<= *pCtrls;
280 [ # # ][ # # ]: 0 : xContainerListener->elementInserted( aEvent );
281 [ # # ][ # # ]: 0 : }
[ # # ]
282 : : }
283 : 0 : void SAL_CALL UnoControlTabPageContainer::addControl( const ::rtl::OUString& Name, const Reference< ::com::sun::star::awt::XControl >& Control ) throw (RuntimeException)
284 : : {
285 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
286 [ # # ]: 0 : ControlContainerBase::addControl(Name,Control);
287 [ # # ][ # # ]: 0 : Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
288 [ # # ]: 0 : ContainerEvent aEvent;
289 [ # # ][ # # ]: 0 : aEvent.Source = getModel();
290 [ # # ]: 0 : aEvent.Element <<= Control;
291 [ # # ][ # # ]: 0 : xContainerListener->elementInserted( aEvent );
[ # # ][ # # ]
292 : 0 : }
293 : :
294 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|