1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0724fc6SAndrew Rist  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19*b0724fc6SAndrew Rist  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "gridcontrol.hxx"
28cdf0e10cSrcweir #include "grideventforwarder.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/view/SelectionType.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/grid/XGridDataModel.hpp>
33cdf0e10cSrcweir #include <com/sun/star/awt/grid/XMutableGridDataModel.hpp>
34cdf0e10cSrcweir #include <com/sun/star/awt/grid/DefaultGridDataModel.hpp>
35cdf0e10cSrcweir #include <com/sun/star/awt/grid/SortableGridDataModel.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/grid/XGridColumnModel.hpp>
37cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx>
38cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
39cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir #include <tools/diagnose_ex.h>
42cdf0e10cSrcweir #include <tools/color.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using ::rtl::OUString;
45cdf0e10cSrcweir using namespace ::com::sun::star;
46cdf0e10cSrcweir using namespace ::com::sun::star::uno;
47cdf0e10cSrcweir using namespace ::com::sun::star::awt;
48cdf0e10cSrcweir using namespace ::com::sun::star::awt::grid;
49cdf0e10cSrcweir using namespace ::com::sun::star::lang;
50cdf0e10cSrcweir using namespace ::com::sun::star::beans;
51cdf0e10cSrcweir using namespace ::com::sun::star::container;
52cdf0e10cSrcweir using namespace ::com::sun::star::view;
53cdf0e10cSrcweir using namespace ::com::sun::star::util;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir namespace toolkit
56cdf0e10cSrcweir {
57cdf0e10cSrcweir //======================================================================================================================
58cdf0e10cSrcweir //= UnoGridModel
59cdf0e10cSrcweir //======================================================================================================================
60cdf0e10cSrcweir namespace
61cdf0e10cSrcweir {
lcl_getDefaultDataModel_throw(::comphelper::ComponentContext const & i_context)62cdf0e10cSrcweir     Reference< XGridDataModel > lcl_getDefaultDataModel_throw( ::comphelper::ComponentContext const & i_context )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         Reference< XMutableGridDataModel > const xDelegatorModel( DefaultGridDataModel::create( i_context.getUNOContext() ), UNO_QUERY_THROW );
65cdf0e10cSrcweir         Reference< XGridDataModel > const xDataModel( SortableGridDataModel::create( i_context.getUNOContext(), xDelegatorModel ), UNO_QUERY_THROW );
66cdf0e10cSrcweir         return xDataModel;
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir 
lcl_getDefaultColumnModel_throw(::comphelper::ComponentContext const & i_context)69cdf0e10cSrcweir     Reference< XGridColumnModel > lcl_getDefaultColumnModel_throw( ::comphelper::ComponentContext const & i_context )
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         Reference< XGridColumnModel > const xColumnModel( i_context.createComponent( "com.sun.star.awt.grid.DefaultGridColumnModel" ), UNO_QUERY_THROW );
72cdf0e10cSrcweir         return xColumnModel;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
UnoGridModel(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & i_factory)77cdf0e10cSrcweir UnoGridModel::UnoGridModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory )
78cdf0e10cSrcweir         :UnoControlModel( i_factory )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
81cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_BORDER );
82cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
83cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
84cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_ENABLED );
85cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_FILLCOLOR );
86cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
87cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_HELPURL );
88cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
89cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_SIZEABLE ); // resizeable
90cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_HSCROLL );
91cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_VSCROLL );
92cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_TABSTOP );
93cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_GRID_SHOWROWHEADER );
94cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_ROW_HEADER_WIDTH );
95cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_GRID_SHOWCOLUMNHEADER );
96cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_COLUMN_HEADER_HEIGHT );
97cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_ROW_HEIGHT );
98cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_GRID_DATAMODEL, makeAny( lcl_getDefaultDataModel_throw( maContext ) ) );
99cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_GRID_COLUMNMODEL, makeAny( lcl_getDefaultColumnModel_throw( maContext ) ) );
100cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_GRID_SELECTIONMODE );
101cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_FONTRELIEF );
102cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK );
103cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
104cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR );
105cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_TEXTLINECOLOR );
106cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_USE_GRID_LINES );
107cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_GRID_LINE_COLOR );
108cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_GRID_HEADER_BACKGROUND );
109cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_GRID_HEADER_TEXT_COLOR );
110cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_GRID_ROW_BACKGROUND_COLORS );
111cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_ACTIVE_SEL_BACKGROUND_COLOR );
112cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_INACTIVE_SEL_BACKGROUND_COLOR );
113cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_ACTIVE_SEL_TEXT_COLOR );
114cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_INACTIVE_SEL_TEXT_COLOR );
115cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN );
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
UnoGridModel(const UnoGridModel & rModel)119cdf0e10cSrcweir UnoGridModel::UnoGridModel( const UnoGridModel& rModel )
120cdf0e10cSrcweir     :UnoControlModel( rModel )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         Reference< XGridDataModel > xDataModel;
125cdf0e10cSrcweir         // clone the data model
126cdf0e10cSrcweir         const Reference< XFastPropertySet > xCloneSource( &const_cast< UnoGridModel& >( rModel ) );
127cdf0e10cSrcweir         try
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             const Reference< XCloneable > xCloneable( xCloneSource->getFastPropertyValue( BASEPROPERTY_GRID_DATAMODEL ), UNO_QUERY_THROW );
130cdf0e10cSrcweir             xDataModel.set( xCloneable->createClone(), UNO_QUERY_THROW );
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir         catch( const Exception& )
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir         if ( !xDataModel.is() )
137cdf0e10cSrcweir             xDataModel = lcl_getDefaultDataModel_throw( maContext );
138cdf0e10cSrcweir         UnoControlModel::setFastPropertyValue_NoBroadcast( BASEPROPERTY_GRID_DATAMODEL, makeAny( xDataModel ) );
139cdf0e10cSrcweir             // do *not* use setFastPropertyValue here: The UnoControlModel ctor did a simple copy of all property values,
140cdf0e10cSrcweir             // so before this call here, we share our data model with the own of the clone source. setFastPropertyValue,
141cdf0e10cSrcweir             // then, disposes the old data model - which means the data model which in fact belongs to the clone source.
142cdf0e10cSrcweir             // so, call the UnoControlModel's impl-method for setting the value.
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         // clone the column model
145cdf0e10cSrcweir         Reference< XGridColumnModel > xColumnModel;
146cdf0e10cSrcweir         try
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             const Reference< XCloneable > xCloneable( xCloneSource->getFastPropertyValue( BASEPROPERTY_GRID_COLUMNMODEL ), UNO_QUERY_THROW );
149cdf0e10cSrcweir             xColumnModel.set( xCloneable->createClone(), UNO_QUERY_THROW );
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir         catch( const Exception& )
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir         if ( !xColumnModel.is() )
156cdf0e10cSrcweir             xColumnModel = lcl_getDefaultColumnModel_throw( maContext );
157cdf0e10cSrcweir         UnoControlModel::setFastPropertyValue_NoBroadcast( BASEPROPERTY_GRID_COLUMNMODEL, makeAny( xColumnModel ) );
158cdf0e10cSrcweir             // same comment as above: do not use our own setPropertyValue here.
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
Clone() const164cdf0e10cSrcweir UnoControlModel* UnoGridModel::Clone() const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	return new UnoGridModel( *this );
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
170cdf0e10cSrcweir namespace
171cdf0e10cSrcweir {
lcl_dispose_nothrow(const Any & i_component)172cdf0e10cSrcweir     void lcl_dispose_nothrow( const Any& i_component )
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         try
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir             const Reference< XComponent > xComponent( i_component, UNO_QUERY_THROW );
177cdf0e10cSrcweir             xComponent->dispose();
178cdf0e10cSrcweir         }
179cdf0e10cSrcweir         catch( const Exception& )
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir     }
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
dispose()187cdf0e10cSrcweir void SAL_CALL UnoGridModel::dispose(  ) throw(RuntimeException)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     lcl_dispose_nothrow( getFastPropertyValue( BASEPROPERTY_GRID_COLUMNMODEL ) );
190cdf0e10cSrcweir     lcl_dispose_nothrow( getFastPropertyValue( BASEPROPERTY_GRID_DATAMODEL ) );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     UnoControlModel::dispose();
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)196cdf0e10cSrcweir void SAL_CALL UnoGridModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     Any aOldSubModel;
199cdf0e10cSrcweir     if ( ( nHandle == BASEPROPERTY_GRID_COLUMNMODEL ) || ( nHandle == BASEPROPERTY_GRID_DATAMODEL ) )
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         aOldSubModel = getFastPropertyValue( nHandle );
202cdf0e10cSrcweir         if ( aOldSubModel == rValue )
203cdf0e10cSrcweir         {
204cdf0e10cSrcweir             OSL_ENSURE( false, "UnoGridModel::setFastPropertyValue_NoBroadcast: setting the same value, again!" );
205cdf0e10cSrcweir                 // shouldn't this have been caught by convertFastPropertyValue?
206cdf0e10cSrcweir             aOldSubModel.clear();
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     if ( aOldSubModel.hasValue() )
213cdf0e10cSrcweir         lcl_dispose_nothrow( aOldSubModel );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
getServiceName()217cdf0e10cSrcweir OUString UnoGridModel::getServiceName() throw(RuntimeException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	return OUString::createFromAscii( szServiceName_GridControlModel );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
ImplGetDefaultValue(sal_uInt16 nPropId) const223cdf0e10cSrcweir Any UnoGridModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	switch( nPropId )
226cdf0e10cSrcweir 	{
227cdf0e10cSrcweir 		case BASEPROPERTY_DEFAULTCONTROL:
228cdf0e10cSrcweir 			return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_GridControl ) );
229cdf0e10cSrcweir 		case BASEPROPERTY_GRID_SELECTIONMODE:
230cdf0e10cSrcweir 			return uno::makeAny( SelectionType(1) );
231cdf0e10cSrcweir 		case BASEPROPERTY_GRID_SHOWROWHEADER:
232cdf0e10cSrcweir         case BASEPROPERTY_USE_GRID_LINES:
233cdf0e10cSrcweir 			return uno::makeAny( (sal_Bool)sal_False );
234cdf0e10cSrcweir         case BASEPROPERTY_ROW_HEADER_WIDTH:
235cdf0e10cSrcweir             return uno::makeAny( sal_Int32( 10 ) );
236cdf0e10cSrcweir 		case BASEPROPERTY_GRID_SHOWCOLUMNHEADER:
237cdf0e10cSrcweir 			return uno::makeAny( (sal_Bool)sal_True );
238cdf0e10cSrcweir         case BASEPROPERTY_COLUMN_HEADER_HEIGHT:
239cdf0e10cSrcweir         case BASEPROPERTY_ROW_HEIGHT:
240cdf0e10cSrcweir 		case BASEPROPERTY_GRID_HEADER_BACKGROUND:
241cdf0e10cSrcweir         case BASEPROPERTY_GRID_HEADER_TEXT_COLOR:
242cdf0e10cSrcweir 		case BASEPROPERTY_GRID_LINE_COLOR:
243cdf0e10cSrcweir         case BASEPROPERTY_GRID_ROW_BACKGROUND_COLORS:
244cdf0e10cSrcweir         case BASEPROPERTY_ACTIVE_SEL_BACKGROUND_COLOR:
245cdf0e10cSrcweir         case BASEPROPERTY_INACTIVE_SEL_BACKGROUND_COLOR:
246cdf0e10cSrcweir         case BASEPROPERTY_ACTIVE_SEL_TEXT_COLOR:
247cdf0e10cSrcweir         case BASEPROPERTY_INACTIVE_SEL_TEXT_COLOR:
248cdf0e10cSrcweir             return Any();
249cdf0e10cSrcweir 		default:
250cdf0e10cSrcweir 			return UnoControlModel::ImplGetDefaultValue( nPropId );
251cdf0e10cSrcweir 	}
252cdf0e10cSrcweir 
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
getInfoHelper()256cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoGridModel::getInfoHelper()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir 	static UnoPropertyArrayHelper* pHelper = NULL;
259cdf0e10cSrcweir 	if ( !pHelper )
260cdf0e10cSrcweir 	{
261cdf0e10cSrcweir 		Sequence<sal_Int32>	aIDs = ImplGetPropertyIds();
262cdf0e10cSrcweir 		pHelper = new UnoPropertyArrayHelper( aIDs );
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 	return *pHelper;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
268cdf0e10cSrcweir // XMultiPropertySet
getPropertySetInfo()269cdf0e10cSrcweir Reference< XPropertySetInfo > UnoGridModel::getPropertySetInfo(  ) throw(RuntimeException)
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
272cdf0e10cSrcweir 	return xInfo;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 
276cdf0e10cSrcweir //======================================================================================================================
277cdf0e10cSrcweir //= UnoGridControl
278cdf0e10cSrcweir //======================================================================================================================
UnoGridControl(const Reference<XMultiServiceFactory> & i_factory)279cdf0e10cSrcweir UnoGridControl::UnoGridControl( const Reference< XMultiServiceFactory >& i_factory )
280cdf0e10cSrcweir     :UnoGridControl_Base( i_factory )
281cdf0e10cSrcweir     ,mSelectionMode(SelectionType(1))
282cdf0e10cSrcweir 	,m_aSelectionListeners( *this )
283cdf0e10cSrcweir     ,m_pEventForwarder( new GridEventForwarder( *this ) )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
~UnoGridControl()288cdf0e10cSrcweir UnoGridControl::~UnoGridControl()
289cdf0e10cSrcweir {
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
GetComponentServiceName()293cdf0e10cSrcweir OUString UnoGridControl::GetComponentServiceName()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	return OUString::createFromAscii( "Grid" );
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
dispose()299cdf0e10cSrcweir void SAL_CALL UnoGridControl::dispose(  ) throw(RuntimeException)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	lang::EventObject aEvt;
302cdf0e10cSrcweir 	aEvt.Source = (::cppu::OWeakObject*)this;
303cdf0e10cSrcweir 	m_aSelectionListeners.disposeAndClear( aEvt );
304cdf0e10cSrcweir 	UnoControl::dispose();
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)308cdf0e10cSrcweir void SAL_CALL UnoGridControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer >  & rParentPeer ) throw(uno::RuntimeException)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir 	UnoControlBase::createPeer( rxToolkit, rParentPeer );
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 	const Reference< XGridRowSelection > xGrid( getPeer(), UNO_QUERY_THROW );
313cdf0e10cSrcweir 	xGrid->addSelectionListener( &m_aSelectionListeners );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
317cdf0e10cSrcweir namespace
318cdf0e10cSrcweir {
lcl_setEventForwarding(const Reference<XControlModel> & i_gridControlModel,const::boost::scoped_ptr<GridEventForwarder> & i_listener,bool const i_add)319cdf0e10cSrcweir     void lcl_setEventForwarding( const Reference< XControlModel >& i_gridControlModel, const ::boost::scoped_ptr< GridEventForwarder >& i_listener,
320cdf0e10cSrcweir         bool const i_add )
321cdf0e10cSrcweir     {
322cdf0e10cSrcweir         const Reference< XPropertySet > xModelProps( i_gridControlModel, UNO_QUERY );
323cdf0e10cSrcweir         if ( !xModelProps.is() )
324cdf0e10cSrcweir             return;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir         try
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             Reference< XContainer > const xColModel(
329cdf0e10cSrcweir                 xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ColumnModel" ) ) ),
330cdf0e10cSrcweir                 UNO_QUERY_THROW );
331cdf0e10cSrcweir             if ( i_add )
332cdf0e10cSrcweir                 xColModel->addContainerListener( i_listener.get() );
333cdf0e10cSrcweir             else
334cdf0e10cSrcweir                 xColModel->removeContainerListener( i_listener.get() );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir             Reference< XGridDataModel > const xDataModel(
337cdf0e10cSrcweir                 xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GridDataModel" ) ) ),
338cdf0e10cSrcweir                 UNO_QUERY_THROW
339cdf0e10cSrcweir             );
340cdf0e10cSrcweir             Reference< XMutableGridDataModel > const xMutableDataModel( xDataModel, UNO_QUERY );
341cdf0e10cSrcweir             if ( xMutableDataModel.is() )
342cdf0e10cSrcweir             {
343cdf0e10cSrcweir                 if ( i_add )
344cdf0e10cSrcweir                     xMutableDataModel->addGridDataListener( i_listener.get() );
345cdf0e10cSrcweir                 else
346cdf0e10cSrcweir                     xMutableDataModel->removeGridDataListener( i_listener.get() );
347cdf0e10cSrcweir             }
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir         catch( const Exception& )
350cdf0e10cSrcweir         {
351cdf0e10cSrcweir 	        DBG_UNHANDLED_EXCEPTION();
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
setModel(const Reference<XControlModel> & i_model)357cdf0e10cSrcweir sal_Bool SAL_CALL UnoGridControl::setModel( const Reference< XControlModel >& i_model ) throw(RuntimeException)
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     lcl_setEventForwarding( getModel(), m_pEventForwarder, false );
360cdf0e10cSrcweir     if ( !UnoGridControl_Base::setModel( i_model ) )
361cdf0e10cSrcweir         return sal_False;
362cdf0e10cSrcweir     lcl_setEventForwarding( getModel(), m_pEventForwarder, true );
363cdf0e10cSrcweir     return sal_True;
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
getRowAtPoint(::sal_Int32 x,::sal_Int32 y)367cdf0e10cSrcweir ::sal_Int32 UnoGridControl::getRowAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException)
368cdf0e10cSrcweir {
369cdf0e10cSrcweir 	Reference< XGridControl > const xGrid ( getPeer(), UNO_QUERY_THROW );
370cdf0e10cSrcweir 	return xGrid->getRowAtPoint( x, y );
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
getColumnAtPoint(::sal_Int32 x,::sal_Int32 y)374cdf0e10cSrcweir ::sal_Int32 UnoGridControl::getColumnAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException)
375cdf0e10cSrcweir {
376cdf0e10cSrcweir 	Reference< XGridControl > const xGrid ( getPeer(), UNO_QUERY_THROW );
377cdf0e10cSrcweir 	return xGrid->getColumnAtPoint( x, y );
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
getCurrentColumn()381cdf0e10cSrcweir ::sal_Int32 SAL_CALL UnoGridControl::getCurrentColumn(  ) throw (RuntimeException)
382cdf0e10cSrcweir {
383cdf0e10cSrcweir 	Reference< XGridControl > const xGrid ( getPeer(), UNO_QUERY_THROW );
384cdf0e10cSrcweir 	return xGrid->getCurrentColumn();
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
getCurrentRow()388cdf0e10cSrcweir ::sal_Int32 SAL_CALL UnoGridControl::getCurrentRow(  ) throw (RuntimeException)
389cdf0e10cSrcweir {
390cdf0e10cSrcweir 	Reference< XGridControl > const xGrid ( getPeer(), UNO_QUERY_THROW );
391cdf0e10cSrcweir 	return xGrid->getCurrentRow();
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
goToCell(::sal_Int32 i_columnIndex,::sal_Int32 i_rowIndex)395cdf0e10cSrcweir void SAL_CALL UnoGridControl::goToCell( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException, VetoException)
396cdf0e10cSrcweir {
397cdf0e10cSrcweir 	Reference< XGridControl > const xGrid ( getPeer(), UNO_QUERY_THROW );
398cdf0e10cSrcweir 	xGrid->goToCell( i_columnIndex, i_rowIndex );
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
selectRow(::sal_Int32 i_rowIndex)402cdf0e10cSrcweir void SAL_CALL UnoGridControl::selectRow( ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir 	Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->selectRow( i_rowIndex );
405cdf0e10cSrcweir }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
selectAllRows()408cdf0e10cSrcweir void SAL_CALL UnoGridControl::selectAllRows() throw (::com::sun::star::uno::RuntimeException)
409cdf0e10cSrcweir {
410cdf0e10cSrcweir 	Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->selectAllRows();
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
deselectRow(::sal_Int32 i_rowIndex)414cdf0e10cSrcweir void SAL_CALL UnoGridControl::deselectRow( ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir 	Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->deselectRow( i_rowIndex );
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
deselectAllRows()420cdf0e10cSrcweir void SAL_CALL UnoGridControl::deselectAllRows() throw (::com::sun::star::uno::RuntimeException)
421cdf0e10cSrcweir {
422cdf0e10cSrcweir 	Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->deselectAllRows();
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
getSelectedRows()426cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL UnoGridControl::getSelectedRows() throw (::com::sun::star::uno::RuntimeException)
427cdf0e10cSrcweir {
428cdf0e10cSrcweir 	return Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->getSelectedRows();
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
hasSelectedRows()432cdf0e10cSrcweir ::sal_Bool SAL_CALL UnoGridControl::hasSelectedRows() throw (::com::sun::star::uno::RuntimeException)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir 	return Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->hasSelectedRows();
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
isRowSelected(::sal_Int32 index)438cdf0e10cSrcweir ::sal_Bool SAL_CALL UnoGridControl::isRowSelected(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir 	return Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->isRowSelected( index );
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
addSelectionListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::grid::XGridSelectionListener> & listener)444cdf0e10cSrcweir void SAL_CALL UnoGridControl::addSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException)
445cdf0e10cSrcweir {
446cdf0e10cSrcweir 	m_aSelectionListeners.addInterface( listener );
447cdf0e10cSrcweir }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------------------
removeSelectionListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::grid::XGridSelectionListener> & listener)450cdf0e10cSrcweir void SAL_CALL UnoGridControl::removeSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException)
451cdf0e10cSrcweir {
452cdf0e10cSrcweir 	m_aSelectionListeners.removeInterface( listener );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir }//namespace toolkit
456cdf0e10cSrcweir 
GridControl_CreateInstance(const Reference<XMultiServiceFactory> & i_factory)457cdf0e10cSrcweir Reference< XInterface > SAL_CALL GridControl_CreateInstance( const Reference< XMultiServiceFactory >& i_factory )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir 	return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoGridControl( i_factory ) );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
GridControlModel_CreateInstance(const Reference<XMultiServiceFactory> & i_factory)462cdf0e10cSrcweir Reference< XInterface > SAL_CALL GridControlModel_CreateInstance( const Reference< XMultiServiceFactory >& i_factory )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir 	return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoGridModel( i_factory ) );
465cdf0e10cSrcweir }
466