1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridcontrol.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
34 #include <gridcontrol.hxx>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/view/SelectionType.hpp>
38 #include <com/sun/star/awt/grid/XGridDataModel.hpp>
39 #include <com/sun/star/awt/grid/ScrollBarMode.hpp>
40 #include <toolkit/helper/unopropertyarrayhelper.hxx>
41 #include <toolkit/helper/property.hxx>
42 #include <com/sun/star/awt/XVclWindowPeer.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <osl/diagnose.h>
46 using ::rtl::OUString
;
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::awt::grid
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::container
;
53 using namespace ::com::sun::star::view
;
57 // ----------------------------------------------------
59 // ----------------------------------------------------
60 UnoGridModel::UnoGridModel()
62 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR
);
63 ImplRegisterProperty( BASEPROPERTY_BORDER
);
64 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR
);
65 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL
);
66 ImplRegisterProperty( BASEPROPERTY_ENABLED
);
67 ImplRegisterProperty( BASEPROPERTY_FILLCOLOR
);
68 ImplRegisterProperty( BASEPROPERTY_HELPTEXT
);
69 ImplRegisterProperty( BASEPROPERTY_HELPURL
);
70 ImplRegisterProperty( BASEPROPERTY_PRINTABLE
);
71 ImplRegisterProperty( BASEPROPERTY_SIZEABLE
); // resizeable
72 ImplRegisterProperty( BASEPROPERTY_HSCROLL
);
73 ImplRegisterProperty( BASEPROPERTY_VSCROLL
);
74 ImplRegisterProperty( BASEPROPERTY_GRID_SHOWROWHEADER
);
75 ImplRegisterProperty( BASEPROPERTY_GRID_SHOWCOLUMNHEADER
);
76 ImplRegisterProperty( BASEPROPERTY_GRID_DATAMODEL
);
77 ImplRegisterProperty( BASEPROPERTY_GRID_COLUMNMODEL
);
78 ImplRegisterProperty( BASEPROPERTY_GRID_SELECTIONMODE
);
82 UnoGridModel::UnoGridModel( const UnoGridModel
& rModel
)
83 : UnoControlModel( rModel
)
87 UnoControlModel
* UnoGridModel::Clone() const
89 return new UnoGridModel( *this );
92 OUString
UnoGridModel::getServiceName() throw(RuntimeException
)
94 return OUString::createFromAscii( szServiceName_GridControlModel
);
97 Any
UnoGridModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
101 case BASEPROPERTY_DEFAULTCONTROL
:
102 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_GridControl
) );
103 case BASEPROPERTY_GRID_SELECTIONMODE
:
104 return uno::makeAny( SelectionType(1) );
106 return UnoControlModel::ImplGetDefaultValue( nPropId
);
111 ::cppu::IPropertyArrayHelper
& UnoGridModel::getInfoHelper()
113 static UnoPropertyArrayHelper
* pHelper
= NULL
;
116 Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
117 pHelper
= new UnoPropertyArrayHelper( aIDs
);
123 Reference
< XPropertySetInfo
> UnoGridModel::getPropertySetInfo( ) throw(RuntimeException
)
125 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
130 // ----------------------------------------------------
131 // class UnoGridControl
132 // ----------------------------------------------------
133 UnoGridControl::UnoGridControl()
134 : mSelectionMode(SelectionType(1))
138 OUString
UnoGridControl::GetComponentServiceName()
140 return OUString::createFromAscii( "Grid" );
143 void SAL_CALL
UnoGridControl::dispose( ) throw(RuntimeException
)
145 UnoControl::dispose();
148 void UnoGridControl::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
) throw(uno::RuntimeException
)
150 UnoControlBase::createPeer( rxToolkit
, rParentPeer
);
152 Reference
< XGridControl
> xGrid( getPeer(), UNO_QUERY_THROW
);
154 Reference
<XGridDataListener
> xListener ( getPeer(), UNO_QUERY_THROW
);
155 Reference
<XPropertySet
> xPropSet ( getModel(), UNO_QUERY_THROW
);
157 Reference
<XGridDataModel
> xGridDataModel ( xPropSet
->getPropertyValue(OUString::createFromAscii( "GridDataModel" )), UNO_QUERY_THROW
);
158 xGridDataModel
->addDataListener(xListener
);
162 // -------------------------------------------------------------------
164 // -------------------------------------------------------------------
166 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridColumnModel
> SAL_CALL
UnoGridControl::getColumnModel() throw (::com::sun::star::uno::RuntimeException
)
168 Reference
<XPropertySet
> xPropSet ( getModel(), UNO_QUERY_THROW
);
169 Reference
<XGridColumnModel
> xGridColumnModel ( xPropSet
->getPropertyValue(OUString::createFromAscii( "ColumnModel" )), UNO_QUERY_THROW
);
171 return xGridColumnModel
;
174 void SAL_CALL
UnoGridControl::setColumnModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridColumnModel
> & model
) throw (::com::sun::star::uno::RuntimeException
)
176 Reference
<XPropertySet
> xPropSet ( getModel(), UNO_QUERY_THROW
);
177 xPropSet
->setPropertyValue(OUString::createFromAscii( "ColumnModel" ), Any (model
));
180 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridDataModel
> SAL_CALL
UnoGridControl::getDataModel() throw (::com::sun::star::uno::RuntimeException
)
182 Reference
<XPropertySet
> xPropSet ( getModel(), UNO_QUERY_THROW
);
183 Reference
<XGridDataModel
> xGridDataModel ( xPropSet
->getPropertyValue(OUString::createFromAscii( "GridDataModel" )), UNO_QUERY_THROW
);
185 return xGridDataModel
;
188 void SAL_CALL
UnoGridControl::setDataModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridDataModel
> & model
) throw (::com::sun::star::uno::RuntimeException
)
190 Reference
<XPropertySet
> xPropSet ( getModel(), UNO_QUERY_THROW
);
191 xPropSet
->setPropertyValue(OUString::createFromAscii( "GridDataModel" ), Any(model
));
194 ::sal_Int32
UnoGridControl::getItemIndexAtPoint(::sal_Int32 x
, ::sal_Int32 y
) throw (::com::sun::star::uno::RuntimeException
)
196 return Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->getItemIndexAtPoint( x
, y
);
200 void SAL_CALL UnoGridControl::addMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException)
202 Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->addMouseListener( listener );
205 void SAL_CALL UnoGridControl::removeMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException)
207 Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeMouseListener( listener );
210 // -------------------------------------------------------------------
212 // -------------------------------------------------------------------
214 ::sal_Int32 SAL_CALL
UnoGridControl::getMinSelectionIndex() throw (::com::sun::star::uno::RuntimeException
)
216 return Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->getMinSelectionIndex();
219 ::sal_Int32 SAL_CALL
UnoGridControl::getMaxSelectionIndex() throw (::com::sun::star::uno::RuntimeException
)
221 return Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->getMaxSelectionIndex();
224 void SAL_CALL
UnoGridControl::insertIndexIntervall(::sal_Int32 start
, ::sal_Int32 length
) throw (::com::sun::star::uno::RuntimeException
)
226 Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->insertIndexIntervall( start
, length
);
229 void SAL_CALL
UnoGridControl::removeIndexIntervall(::sal_Int32 start
, ::sal_Int32 length
) throw (::com::sun::star::uno::RuntimeException
)
231 Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->removeIndexIntervall( start
, length
);
234 ::com::sun::star::uno::Sequence
< ::sal_Int32
> SAL_CALL
UnoGridControl::getSelection() throw (::com::sun::star::uno::RuntimeException
)
236 return Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->getSelection();
239 ::sal_Bool SAL_CALL
UnoGridControl::isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException
)
241 return Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->isSelectionEmpty();
244 ::sal_Bool SAL_CALL
UnoGridControl::isSelectedIndex(::sal_Int32 index
) throw (::com::sun::star::uno::RuntimeException
)
246 return Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->isSelectedIndex( index
);
249 void SAL_CALL
UnoGridControl::selectRow(::sal_Int32 y
) throw (::com::sun::star::uno::RuntimeException
)
251 Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->selectRow( y
);
254 void SAL_CALL
UnoGridControl::addSelectionListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridSelectionListener
> & listener
) throw (::com::sun::star::uno::RuntimeException
)
256 Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->addSelectionListener( listener
);
259 void SAL_CALL
UnoGridControl::removeSelectionListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridSelectionListener
> & listener
) throw (::com::sun::star::uno::RuntimeException
)
261 Reference
< XGridControl
>( getPeer(), UNO_QUERY_THROW
)->removeSelectionListener( listener
);
265 Reference
< XInterface
> SAL_CALL
GridControl_CreateInstance( const Reference
< XMultiServiceFactory
>& )
267 return Reference
< XInterface
>( ( ::cppu::OWeakObject
* ) new ::toolkit::UnoGridControl
);
270 Reference
< XInterface
> SAL_CALL
GridControlModel_CreateInstance( const Reference
< XMultiServiceFactory
>& )
272 return Reference
< XInterface
>( ( ::cppu::OWeakObject
* ) new ::toolkit::UnoGridModel
);