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