diff options
Diffstat (limited to 'toolkit/source/controls/grid')
-rw-r--r-- | toolkit/source/controls/grid/defaultgridcolumnmodel.cxx | 121 | ||||
-rw-r--r-- | toolkit/source/controls/grid/defaultgridcolumnmodel.hxx | 37 | ||||
-rw-r--r-- | toolkit/source/controls/grid/defaultgriddatamodel.cxx | 99 | ||||
-rw-r--r-- | toolkit/source/controls/grid/defaultgriddatamodel.hxx | 23 | ||||
-rw-r--r-- | toolkit/source/controls/grid/gridcolumn.cxx | 148 | ||||
-rw-r--r-- | toolkit/source/controls/grid/gridcolumn.hxx | 29 | ||||
-rw-r--r-- | toolkit/source/controls/grid/gridcontrol.cxx | 112 | ||||
-rw-r--r-- | toolkit/source/controls/grid/gridcontrol.hxx | 18 |
8 files changed, 390 insertions, 197 deletions
diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx index fdf91d6a6593..011f3502cdd8 100644 --- a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx @@ -30,6 +30,7 @@ #include "defaultgridcolumnmodel.hxx" #include <comphelper/sequence.hxx> #include <toolkit/helper/servicenames.hxx> +#include <com/sun/star/awt/XVclWindowPeer.hpp> #include <rtl/ref.hxx> using ::rtl::OUString; @@ -38,8 +39,7 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt; using namespace ::com::sun::star::awt::grid; using namespace ::com::sun::star::lang; - -#define COLUMNSELECTIONALLOWED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnSelectionAllowed" )) +using namespace ::com::sun::star::style; namespace toolkit { @@ -48,8 +48,10 @@ namespace toolkit // class DefaultGridColumnModel /////////////////////////////////////////////////////////////////////// -DefaultGridColumnModel::DefaultGridColumnModel() +DefaultGridColumnModel::DefaultGridColumnModel(const Reference< XMultiServiceFactory >& xFactory) : columns(std::vector< Reference< XGridColumn > >()) + ,m_nColumnHeaderHeight(0) + ,m_xFactory(xFactory) { } @@ -61,71 +63,6 @@ DefaultGridColumnModel::~DefaultGridColumnModel() //--------------------------------------------------------------------- -void DefaultGridColumnModel::broadcast( broadcast_type eType, const GridColumnEvent& aEvent ) -{ - ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridColumnListener::static_type() ); - if( pIter ) - { - ::cppu::OInterfaceIteratorHelper aListIter(*pIter); - while(aListIter.hasMoreElements()) - { - XGridColumnListener* pListener = static_cast<XGridColumnListener*>(aListIter.next()); - switch( eType ) - { - case column_added: pListener->columnAdded(aEvent); break; - case column_removed: pListener->columnRemoved(aEvent); break; - case column_changed: pListener->columnChanged(aEvent); break; - } - } - } -} - -//--------------------------------------------------------------------- - -void DefaultGridColumnModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ) -{ - Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridColumnEvent aEvent( xSource, name, oldValue, newValue, 0, NULL ); - broadcast( column_changed, aEvent); -} - -//--------------------------------------------------------------------- - -void DefaultGridColumnModel::broadcast_add( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) -{ - Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); - broadcast( column_added, aEvent); -} - -//--------------------------------------------------------------------- - -void DefaultGridColumnModel::broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) -{ - Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); - broadcast( column_changed, aEvent); -} - -//--------------------------------------------------------------------- -// XDefaultGridColumnModel -//--------------------------------------------------------------------- -::sal_Bool SAL_CALL DefaultGridColumnModel::getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException) -{ - return selectionAllowed; -} - -//--------------------------------------------------------------------- - -void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value) throw (::com::sun::star::uno::RuntimeException) -{ - sal_Bool oldValue = selectionAllowed; - selectionAllowed = value; - broadcast_changed( COLUMNSELECTIONALLOWED, Any(oldValue) , Any(selectionAllowed)); -} - -//--------------------------------------------------------------------- - ::sal_Int32 SAL_CALL DefaultGridColumnModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException) { return columns.size(); @@ -136,11 +73,10 @@ void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value ::sal_Int32 SAL_CALL DefaultGridColumnModel::addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException) { ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); - - columns.push_back(column); - + Reference<XGridColumn> xColumn(column); + columns.push_back(xColumn); sal_Int32 index = columns.size() - 1; - broadcast_add(index, column ); + xColumn->setIndex(index); return index; } @@ -156,23 +92,48 @@ void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL DefaultGridColumnModel::getColumn(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException) { if ( index >=0 && index < ((sal_Int32)columns.size())) + { return columns[index]; + } else return Reference< XGridColumn >(); } - -void SAL_CALL DefaultGridColumnModel::addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +//--------------------------------------------------------------------- +void SAL_CALL DefaultGridColumnModel::setColumnHeaderHeight(sal_Int32 _value) throw (::com::sun::star::uno::RuntimeException) +{ + m_nColumnHeaderHeight = _value; +} +//--------------------------------------------------------------------- +sal_Int32 SAL_CALL DefaultGridColumnModel::getColumnHeaderHeight() throw (::com::sun::star::uno::RuntimeException) { - BrdcstHelper.addListener( XGridColumnListener::static_type(), xListener ); + return m_nColumnHeaderHeight; } //--------------------------------------------------------------------- +void SAL_CALL DefaultGridColumnModel::setDefaultColumns(sal_Int32 rowElements) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); -void SAL_CALL DefaultGridColumnModel::removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) + for(sal_Int32 i=0;i<rowElements;i++) + { + Reference<XGridColumn> xColumn( m_xFactory->createInstance ( OUString::createFromAscii( "com.sun.star.awt.grid.GridColumn" ) ), UNO_QUERY ); + columns.push_back(xColumn); + xColumn->setIndex(i); + } +} +::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL DefaultGridColumnModel::copyColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException) { - BrdcstHelper.removeListener( XGridColumnListener::static_type(), xListener ); + Reference<XGridColumn> xColumn( m_xFactory->createInstance ( OUString::createFromAscii( "com.sun.star.awt.grid.GridColumn" ) ), UNO_QUERY ); + xColumn->setColumnWidth(column->getColumnWidth()); + xColumn->setPreferredWidth(column->getPreferredWidth()); + xColumn->setMaxWidth(column->getMaxWidth()); + xColumn->setMinWidth(column->getMinWidth()); + xColumn->setPreferredWidth(column->getPreferredWidth()); + xColumn->setResizeable(column->getResizeable()); + xColumn->setTitle(column->getTitle()); + xColumn->setHorizontalAlign(column->getHorizontalAlign()); + return xColumn; } - //--------------------------------------------------------------------- // XComponent //--------------------------------------------------------------------- @@ -232,8 +193,8 @@ sal_Bool SAL_CALL DefaultGridColumnModel::supportsService( const ::rtl::OUString } -Reference< XInterface > SAL_CALL DefaultGridColumnModel_CreateInstance( const Reference< XMultiServiceFactory >& ) +Reference< XInterface > SAL_CALL DefaultGridColumnModel_CreateInstance( const Reference< XMultiServiceFactory >& _rFactory) { - return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridColumnModel ); + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridColumnModel( _rFactory ) ); } diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx index 896427ce3e2b..8b8c8bfc795c 100644 --- a/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx @@ -29,7 +29,7 @@ #include "precompiled_toolkit.hxx" #include <com/sun/star/awt/grid/XGridColumnModel.hpp> #include <com/sun/star/awt/grid/XGridColumn.hpp> -#include <com/sun/star/awt/grid/GridColumnEvent.hpp> +//#include <com/sun/star/awt/grid/GridColumnEvent.hpp> #include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> @@ -38,6 +38,9 @@ #include <rtl/ref.hxx> #include <vector> #include <toolkit/helper/mutexandbroadcasthelper.hxx> +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/style/VerticalAlignment.hpp> +#include <com/sun/star/awt/grid/XGridColumnListener.hpp> using ::rtl::OUString; using namespace ::com::sun::star; @@ -49,45 +52,49 @@ using namespace ::com::sun::star::lang; namespace toolkit { -enum broadcast_type { column_added, column_removed, column_changed}; +//enum broadcast_type { column_added, column_removed, column_changed}; class DefaultGridColumnModel : public ::cppu::WeakImplHelper2< XGridColumnModel, XServiceInfo >, public MutexAndBroadcastHelper { public: - DefaultGridColumnModel(); + DefaultGridColumnModel(const Reference< XMultiServiceFactory >& xFactory); virtual ~DefaultGridColumnModel(); // XGridColumnModel - virtual ::sal_Bool SAL_CALL getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setColumnSelectionAllowed(::sal_Bool the_value) throw (::com::sun::star::uno::RuntimeException); + //virtual ::sal_Bool SAL_CALL getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException); + //virtual void SAL_CALL setColumnSelectionAllowed(::sal_Bool the_value) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > > SAL_CALL getColumns() throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL getColumn(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); - virtual void SAL_CALL removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); - + //virtual void SAL_CALL addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); + //virtual void SAL_CALL removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL setColumnHeaderHeight( sal_Int32 _value) throw (com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getColumnHeaderHeight() throw (com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDefaultColumns(sal_Int32 rowElements) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL copyColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException); // XComponent virtual void SAL_CALL dispose( ) throw (RuntimeException); virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException); // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException); - virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); - + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); private: - void broadcast( broadcast_type eType, const GridColumnEvent& aEvent ); - void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ); + /*void broadcast( broadcast_type eType, const GridColumnEvent& aEvent ); + void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue, sal_Int32 index,const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); void broadcast_add( sal_Int32 index,const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); - void broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); + void broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn );*/ std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > > columns; sal_Bool selectionAllowed; + sal_Int32 m_nColumnHeaderHeight; + Reference< XMultiServiceFactory > m_xFactory; }; } diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx index 70c79e0bcbfa..7ffafdf0ddb6 100644 --- a/toolkit/source/controls/grid/defaultgriddatamodel.cxx +++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx @@ -41,6 +41,9 @@ using namespace ::com::sun::star::lang; #define ROWHEIGHT ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowHeight" )) #define ROWHEADERS ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowHeaders" )) +#define CELLUPDATED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CellUpdated" )) +#define ROWUPDATED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowUpdated" )) +#define ROWHEADERWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowHeaderWidth" )) namespace toolkit { @@ -51,7 +54,8 @@ namespace toolkit DefaultGridDataModel::DefaultGridDataModel() : rowHeight(0), - rowHeaders(std::vector< ::rtl::OUString >()) + rowHeaders(std::vector< ::rtl::OUString >()), + m_nRowHeaderWidth(10) { } @@ -61,7 +65,7 @@ DefaultGridDataModel::~DefaultGridDataModel() { } -void DefaultGridDataModel::broadcast( broadcast_type eType, const GridDataEvent& aEvent ) +void DefaultGridDataModel::broadcast( broadcast_type eType, const GridDataEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException) { ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridDataListener::static_type() ); if( pIter ) @@ -82,25 +86,27 @@ void DefaultGridDataModel::broadcast( broadcast_type eType, const GridDataEvent& //--------------------------------------------------------------------- -void DefaultGridDataModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ) +void DefaultGridDataModel::broadcast_changed( ::rtl::OUString name, sal_Int32 index, Any oldValue, Any newValue) throw (::com::sun::star::uno::RuntimeException) { Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridDataEvent aEvent( xSource, name, oldValue, newValue, 0, ::rtl::OUString(), Sequence< ::rtl::OUString>() ); + GridDataEvent aEvent( xSource, name, oldValue, newValue, index, ::rtl::OUString(), Sequence< Any >()); broadcast( data_changed, aEvent); } //--------------------------------------------------------------------- -void DefaultGridDataModel::broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ) +void DefaultGridDataModel::broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName, + ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException) { Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridDataEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, headerName, rowData ); + GridDataEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, headerName, (const ::com::sun::star::uno::Sequence< Any >&)rowData ); broadcast( row_added, aEvent); } //--------------------------------------------------------------------- -void DefaultGridDataModel::broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ) +void DefaultGridDataModel::broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName, + ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException) { Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); GridDataEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, headerName, rowData ); @@ -124,7 +130,7 @@ void SAL_CALL DefaultGridDataModel::setRowHeight(::sal_Int32 value) throw (::com sal_Int32 oldValue = rowHeight; rowHeight = value; - broadcast_changed( ROWHEIGHT, Any(oldValue), Any(value) ); + broadcast_changed( ROWHEIGHT, 0, Any(oldValue), Any(value)); } //--------------------------------------------------------------------- @@ -160,24 +166,26 @@ void SAL_CALL DefaultGridDataModel::setRowHeaders(const ::com::sun::star::uno::S i++; } - broadcast_changed( ROWHEADERS, Any(oldValue), Any(comphelper::containerToSequence(rowHeaders)) ); + broadcast_changed( ROWHEADERS, 0, Any(oldValue), Any(comphelper::containerToSequence(rowHeaders)) ); } //--------------------------------------------------------------------- -void SAL_CALL DefaultGridDataModel::addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rRowdata) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL DefaultGridDataModel::addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< Any > & rRowdata) throw (::com::sun::star::uno::RuntimeException) { // store header name rowHeaders.push_back(headername); - // store row data - std::vector< rtl::OUString > newRow( - comphelper::sequenceToContainer< std::vector<rtl::OUString > >(rRowdata)); + std::vector< Any > newRow; + for ( int i = 0; i < rRowdata.getLength();i++) + { + newRow.push_back(rRowdata[i]); + } data.push_back( newRow ); - broadcast_add( data.size()-1, headername, rRowdata); + broadcast_add( data.size()-1, headername, comphelper::containerToSequence(newRow)); } @@ -187,16 +195,10 @@ void SAL_CALL DefaultGridDataModel::removeRow(::sal_Int32 index) throw (::com::s { if ( index >= 0 && index <= getRowCount()-1) { - /* if(Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->isSelectedIndex( index )) - { - ::com::sun::star::uno::Sequence<::sal_Int32> selectedRows = Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getSelection(); - selectedRow.erase(selectedRows.begin()+index); - }*/ - ::rtl::OUString headerName( (::rtl::OUString) rowHeaders[index] ); rowHeaders.erase(rowHeaders.begin() + index); - Sequence< ::rtl::OUString >& rowData ( (Sequence< ::rtl::OUString >&)data[index] ); + Sequence< Any >& rowData ( (Sequence< Any >&)data[index] ); data.erase(data.begin() + index); broadcast_remove( index, headerName, rowData); } @@ -204,19 +206,19 @@ void SAL_CALL DefaultGridDataModel::removeRow(::sal_Int32 index) throw (::com::s return; } //--------------------------------------------------------------------- -::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL DefaultGridDataModel::getData() throw (::com::sun::star::uno::RuntimeException) +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< Any > > SAL_CALL DefaultGridDataModel::getData() throw (::com::sun::star::uno::RuntimeException) { - std::vector< std::vector< ::rtl::OUString > >::iterator iterator; - std::vector< Sequence< ::rtl::OUString > > dummyContainer(0); + std::vector< std::vector< Any > >::iterator iterator; + std::vector< Sequence< Any > > dummyContainer(0); for(iterator = data.begin(); iterator != data.end(); iterator++) { - Sequence< ::rtl::OUString > cols(comphelper::containerToSequence(*iterator)); + Sequence< Any > cols(comphelper::containerToSequence(*iterator)); dummyContainer.push_back( cols ); } - Sequence< Sequence< ::rtl::OUString > > dataSequence(comphelper::containerToSequence(dummyContainer)); + Sequence< Sequence< Any > > dataSequence(comphelper::containerToSequence(dummyContainer)); return dataSequence; } @@ -234,14 +236,52 @@ void SAL_CALL DefaultGridDataModel::removeDataListener( const Reference< XGridDa { BrdcstHelper.removeListener( XGridDataListener::static_type(), xListener ); } - +//--------------------------------------------------------------------- void SAL_CALL DefaultGridDataModel::removeAll() throw (RuntimeException) { rowHeaders.clear(); data.clear(); broadcast_remove( -1, ::rtl::OUString(), 0); } - +//--------------------------------------------------------------------- +void SAL_CALL DefaultGridDataModel::setRowHeaderWidth(sal_Int32 _value) throw (::com::sun::star::uno::RuntimeException) +{ + sal_Int32 oldValue = m_nRowHeaderWidth; + m_nRowHeaderWidth = _value; + broadcast_changed( ROWHEADERWIDTH, 0, Any(oldValue), Any(_value) ); +} +//--------------------------------------------------------------------- +sal_Int32 SAL_CALL DefaultGridDataModel::getRowHeaderWidth() throw (::com::sun::star::uno::RuntimeException) +{ + return m_nRowHeaderWidth; +} +//--------------------------------------------------------------------- +void SAL_CALL DefaultGridDataModel::updateCell(::sal_Int32 row, ::sal_Int32 column, const Any& value) throw (::com::sun::star::uno::RuntimeException) +{ + if(row >= 0 && row < (signed)data.size()) + { + if(column >= 0 && column < (signed)data[0].size()) + { + data[row][column] = value; + Sequence< Any >dataSeq(comphelper::containerToSequence(data[row])); + broadcast_changed( CELLUPDATED, row, Any(column), value ); + } + } +} +//--------------------------------------------------------------------- +void SAL_CALL DefaultGridDataModel::updateRow(::sal_Int32 row, const ::com::sun::star::uno::Sequence< ::sal_Int32 > & columns, const ::com::sun::star::uno::Sequence< Any > & values) throw (::com::sun::star::uno::RuntimeException) +{ + if(row >= 0 && row < (signed)data.size()) + { + if(columns.getLength() == values.getLength()) + { + for(int i = 0; i < columns.getLength(); i++) + data[row][i] = values[i]; + Sequence< Any >dataSeq(comphelper::containerToSequence(data[row])); + broadcast_changed( ROWUPDATED, row, Any(columns), Any(values) ); + } + } +} //--------------------------------------------------------------------- // XComponent //--------------------------------------------------------------------- @@ -302,6 +342,5 @@ sal_Bool SAL_CALL DefaultGridDataModel::supportsService( const ::rtl::OUString& Reference< XInterface > SAL_CALL DefaultGridDataModel_CreateInstance( const Reference< XMultiServiceFactory >& ) { - return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridDataModel ); + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridDataModel() ); } - diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.hxx b/toolkit/source/controls/grid/defaultgriddatamodel.hxx index 1aebc07bc2a8..ea11a8a9a00a 100644 --- a/toolkit/source/controls/grid/defaultgriddatamodel.hxx +++ b/toolkit/source/controls/grid/defaultgriddatamodel.hxx @@ -30,6 +30,7 @@ #include <com/sun/star/awt/grid/XGridDataModel.hpp> #include <com/sun/star/awt/grid/GridDataEvent.hpp> #include <com/sun/star/awt/grid/XGridDataListener.hpp> +#include <com/sun/star/awt/XControl.hpp> #include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> @@ -64,13 +65,16 @@ public: virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRowHeaders() throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setRowHeaders(const ::com::sun::star::uno::Sequence< ::rtl::OUString > & value) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL getData() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & data) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeRow(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< Any > > SAL_CALL getData() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< Any > & data) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeRow(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL addDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException); virtual void SAL_CALL removeDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException); virtual void SAL_CALL removeAll() throw (RuntimeException); - + virtual void SAL_CALL setRowHeaderWidth(sal_Int32 _value) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getRowHeaderWidth() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL updateCell( ::sal_Int32 row, ::sal_Int32 column, const ::com::sun::star::uno::Any& value ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL updateRow( ::sal_Int32 row, const ::com::sun::star::uno::Sequence< ::sal_Int32 >& columns, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& values ) throw (::com::sun::star::uno::RuntimeException); // XComponent virtual void SAL_CALL dispose( ) throw (RuntimeException); virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); @@ -83,14 +87,15 @@ public: private: - void broadcast( broadcast_type eType, const GridDataEvent& aEvent ); - void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ); - void broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ); - void broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ); + void broadcast( broadcast_type eType, const GridDataEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException); + void broadcast_changed( ::rtl::OUString name, sal_Int32 index, Any oldValue, Any newValue ) throw (::com::sun::star::uno::RuntimeException); + void broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException); + void broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException); sal_Int32 rowHeight; - std::vector< std::vector < ::rtl::OUString > > data; + std::vector< std::vector < Any > > data; std::vector< ::rtl::OUString > rowHeaders; + sal_Int32 m_nRowHeaderWidth; }; } diff --git a/toolkit/source/controls/grid/gridcolumn.cxx b/toolkit/source/controls/grid/gridcolumn.cxx index 39c4960351d3..6720d639f5c1 100644 --- a/toolkit/source/controls/grid/gridcolumn.cxx +++ b/toolkit/source/controls/grid/gridcolumn.cxx @@ -38,6 +38,16 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt; using namespace ::com::sun::star::awt::grid; using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::style; + +#define COLWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColWidth" )) +#define MAXWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MaxWidth" )) +#define MINWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MinWidth" )) +#define PREFWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PrefWidth" )) +#define HALIGN ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HAlign" )) +#define TITLE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Title" )) +#define COLRESIZE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnResize" )) +#define UPDATE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UpdateWidth" )) namespace toolkit { @@ -48,6 +58,13 @@ namespace toolkit GridColumn::GridColumn() : identifier(Any()) +,index(0) +,columnWidth(4) +,preferredWidth(0) +,maxWidth(0) +,minWidth(0) +,bResizeable(true) +,horizontalAlign(HorizontalAlignment(0)) { } @@ -59,6 +76,39 @@ GridColumn::~GridColumn() //--------------------------------------------------------------------- +void GridColumn::broadcast( broadcast_column_type eType, const GridColumnEvent& aEvent ) +{ + ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridColumnListener::static_type() ); + if( pIter ) + { + ::cppu::OInterfaceIteratorHelper aListIter(*pIter); + while(aListIter.hasMoreElements()) + { + XGridColumnListener* pListener = static_cast<XGridColumnListener*>(aListIter.next()); + switch( eType ) + { + case column_attribute_changed: pListener->columnChanged(aEvent); break; + } + } + } +} + +//--------------------------------------------------------------------- + +void GridColumn::broadcast_changed(::rtl::OUString name, Any oldValue, Any newValue) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridColumnEvent aEvent( xSource, name, oldValue, newValue, index); + broadcast( column_attribute_changed, aEvent); +} + +void SAL_CALL GridColumn::updateColumn(const ::rtl::OUString& name, sal_Int32 width) throw (::com::sun::star::uno::RuntimeException) +{ + if(PREFWIDTH == name) + preferredWidth = width; + else if (COLWIDTH == name) + columnWidth = width; +} //--------------------------------------------------------------------- // XGridColumn //--------------------------------------------------------------------- @@ -79,6 +129,7 @@ void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value ::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException) { + broadcast_changed(UPDATE, Any(columnWidth), Any()); return columnWidth; } @@ -87,6 +138,50 @@ void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) { columnWidth = value; + broadcast_changed(COLWIDTH, Any(columnWidth),Any(value)); +} +//-------------------------------------------------------------------- + +::sal_Int32 SAL_CALL GridColumn::getPreferredWidth() throw (::com::sun::star::uno::RuntimeException) +{ + broadcast_changed(UPDATE, Any(preferredWidth), Any()); + return preferredWidth; +} + +//-------------------------------------------------------------------- + +void SAL_CALL GridColumn::setPreferredWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) +{ + preferredWidth = value; + broadcast_changed(PREFWIDTH, Any(preferredWidth),Any(value)); +} +//-------------------------------------------------------------------- + +::sal_Int32 SAL_CALL GridColumn::getMaxWidth() throw (::com::sun::star::uno::RuntimeException) +{ + return maxWidth; +} + +//-------------------------------------------------------------------- + +void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) +{ + maxWidth = value; + broadcast_changed(MAXWIDTH, Any(maxWidth),Any(value)); +} +//-------------------------------------------------------------------- + +::sal_Int32 SAL_CALL GridColumn::getMinWidth() throw (::com::sun::star::uno::RuntimeException) +{ + return minWidth; +} + +//-------------------------------------------------------------------- + +void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) +{ + minWidth = value; + broadcast_changed(MINWIDTH, Any(minWidth),Any(value)); } //-------------------------------------------------------------------- @@ -101,6 +196,45 @@ void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::s void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException) { title = value; + broadcast_changed(TITLE, Any(title),Any(value)); +} +//-------------------------------------------------------------------- + +sal_Bool SAL_CALL GridColumn::getResizeable() throw (::com::sun::star::uno::RuntimeException) +{ + return bResizeable; +} + +//-------------------------------------------------------------------- + +void SAL_CALL GridColumn::setResizeable(sal_Bool value) throw (::com::sun::star::uno::RuntimeException) +{ + bResizeable = value; + broadcast_changed(COLRESIZE, Any(bResizeable),Any(value)); +} +//--------------------------------------------------------------------- +HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException) +{ + return horizontalAlign; +} +//--------------------------------------------------------------------- + +void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException) +{ + horizontalAlign = align; + broadcast_changed(HALIGN, Any(horizontalAlign),Any(align)); +} +//--------------------------------------------------------------------- +void SAL_CALL GridColumn::addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XGridColumnListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL GridColumn::removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XGridColumnListener::static_type(), xListener ); } //--------------------------------------------------------------------- @@ -109,22 +243,30 @@ void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com:: void SAL_CALL GridColumn::dispose() throw (RuntimeException) { + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) ); + BrdcstHelper.aLC.disposeAndClear( aEvent ); } //--------------------------------------------------------------------- void SAL_CALL GridColumn::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) { - (void) xListener; + BrdcstHelper.addListener( XEventListener::static_type(), xListener ); } //--------------------------------------------------------------------- void SAL_CALL GridColumn::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) { - (void) xListener; + BrdcstHelper.removeListener( XEventListener::static_type(), xListener ); +} +void SAL_CALL GridColumn::setIndex(sal_Int32 _nIndex) throw (::com::sun::star::uno::RuntimeException) +{ + index = _nIndex; } - //--------------------------------------------------------------------- // XServiceInfo //--------------------------------------------------------------------- diff --git a/toolkit/source/controls/grid/gridcolumn.hxx b/toolkit/source/controls/grid/gridcolumn.hxx index 7f6d104127ec..38d43d55a07b 100644 --- a/toolkit/source/controls/grid/gridcolumn.hxx +++ b/toolkit/source/controls/grid/gridcolumn.hxx @@ -28,6 +28,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_toolkit.hxx" #include <com/sun/star/awt/grid/XGridColumn.hpp> +#include <com/sun/star/awt/grid/XGridColumnListener.hpp> +#include <com/sun/star/awt/grid/GridColumnEvent.hpp> #include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> @@ -36,6 +38,7 @@ #include <rtl/ref.hxx> #include <vector> #include <toolkit/helper/mutexandbroadcasthelper.hxx> +#include <com/sun/star/style/HorizontalAlignment.hpp> using ::rtl::OUString; using namespace ::com::sun::star; @@ -47,6 +50,7 @@ using namespace ::com::sun::star::lang; namespace toolkit { +enum broadcast_column_type { column_attribute_changed}; class GridColumn : public ::cppu::WeakImplHelper2< XGridColumn, XServiceInfo >, public MutexAndBroadcastHelper { @@ -59,9 +63,21 @@ public: virtual void SAL_CALL setIdentifier(const ::com::sun::star::uno::Any & value) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getColumnWidth() throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setColumnWidth(::sal_Int32 the_value) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getPreferredWidth() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPreferredWidth(::sal_Int32 the_value) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMaxWidth() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMaxWidth(::sal_Int32 the_value) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMinWidth() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMinWidth(::sal_Int32 the_value) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getResizeable() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setResizeable(::sal_Bool the_value) throw (::com::sun::star::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getTitle() throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException); - + virtual ::com::sun::star::style::HorizontalAlignment SAL_CALL getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setHorizontalAlign(::com::sun::star::style::HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL updateColumn( const ::rtl::OUString& name, ::sal_Int32 width ) throw (::com::sun::star::uno::RuntimeException); // XComponent virtual void SAL_CALL dispose( ) throw (RuntimeException); virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); @@ -72,11 +88,20 @@ public: virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException); virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); - + virtual void SAL_CALL setIndex(sal_Int32 _nIndex)throw (::com::sun::star::uno::RuntimeException); private: + void broadcast( broadcast_column_type eType, const GridColumnEvent& aEvent ); + void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue); + Any identifier; + sal_Int32 index; sal_Int32 columnWidth; + sal_Int32 preferredWidth; + sal_Int32 maxWidth; + sal_Int32 minWidth; + sal_Bool bResizeable; ::rtl::OUString title; + ::com::sun::star::style::HorizontalAlignment horizontalAlign; }; } diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx index f19648ab0af2..5125c1349ade 100644 --- a/toolkit/source/controls/grid/gridcontrol.cxx +++ b/toolkit/source/controls/grid/gridcontrol.cxx @@ -33,6 +33,7 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/view/SelectionType.hpp> #include <com/sun/star/awt/grid/XGridDataModel.hpp> +#include <com/sun/star/awt/grid/XGridColumnModel.hpp> #include <com/sun/star/awt/grid/ScrollBarMode.hpp> #include <toolkit/helper/unopropertyarrayhelper.hxx> #include <toolkit/helper/property.hxx> @@ -68,12 +69,21 @@ UnoGridModel::UnoGridModel() ImplRegisterProperty( BASEPROPERTY_SIZEABLE ); // resizeable ImplRegisterProperty( BASEPROPERTY_HSCROLL ); ImplRegisterProperty( BASEPROPERTY_VSCROLL ); + ImplRegisterProperty( BASEPROPERTY_TABSTOP ); ImplRegisterProperty( BASEPROPERTY_GRID_SHOWROWHEADER ); ImplRegisterProperty( BASEPROPERTY_GRID_SHOWCOLUMNHEADER ); ImplRegisterProperty( BASEPROPERTY_GRID_DATAMODEL ); ImplRegisterProperty( BASEPROPERTY_GRID_COLUMNMODEL ); ImplRegisterProperty( BASEPROPERTY_GRID_SELECTIONMODE ); - + ImplRegisterProperty( BASEPROPERTY_FONTRELIEF ); + ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK ); + ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); + ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR ); + ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN ); + ImplRegisterProperty( BASEPROPERTY_GRID_EVEN_ROW_BACKGROUND ); + ImplRegisterProperty( BASEPROPERTY_GRID_HEADER_BACKGROUND ); + ImplRegisterProperty( BASEPROPERTY_GRID_LINE_COLOR ); + ImplRegisterProperty( BASEPROPERTY_GRID_ROW_BACKGROUND ); } UnoGridModel::UnoGridModel( const UnoGridModel& rModel ) @@ -99,6 +109,22 @@ Any UnoGridModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_GridControl ) ); case BASEPROPERTY_GRID_SELECTIONMODE: return uno::makeAny( SelectionType(1) ); + case BASEPROPERTY_GRID_SHOWROWHEADER: + return uno::makeAny( (sal_Bool)sal_False ); + case BASEPROPERTY_GRID_SHOWCOLUMNHEADER: + return uno::makeAny( (sal_Bool)sal_False ); + case BASEPROPERTY_GRID_DATAMODEL: + return uno::makeAny( Reference<XGridDataModel> ()); + case BASEPROPERTY_GRID_COLUMNMODEL: + return uno::makeAny(Reference<XGridColumnModel>() ); + case BASEPROPERTY_GRID_EVEN_ROW_BACKGROUND: + return uno::makeAny( com::sun::star::util::Color(0xFFFFFF) ); + case BASEPROPERTY_GRID_HEADER_BACKGROUND: + return uno::makeAny( com::sun::star::util::Color(0xFFFFFF) ); + case BASEPROPERTY_GRID_LINE_COLOR: + return uno::makeAny( com::sun::star::util::Color(0xFFFFFF) ); + case BASEPROPERTY_GRID_ROW_BACKGROUND: + return uno::makeAny(com::sun::star::util::Color(0xFFFFFF) ); default: return UnoControlModel::ImplGetDefaultValue( nPropId ); } @@ -128,7 +154,8 @@ Reference< XPropertySetInfo > UnoGridModel::getPropertySetInfo( ) throw(Runtime // class UnoGridControl // ---------------------------------------------------- UnoGridControl::UnoGridControl() -: mSelectionMode(SelectionType(1)) +: mSelectionMode(SelectionType(1)), + m_aSelectionListeners( *this ) { } @@ -139,6 +166,9 @@ OUString UnoGridControl::GetComponentServiceName() void SAL_CALL UnoGridControl::dispose( ) throw(RuntimeException) { + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + m_aSelectionListeners.disposeAndClear( aEvt ); UnoControl::dispose(); } @@ -147,63 +177,39 @@ void UnoGridControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolk UnoControlBase::createPeer( rxToolkit, rParentPeer ); Reference< XGridControl > xGrid( getPeer(), UNO_QUERY_THROW ); + xGrid->addSelectionListener(&m_aSelectionListeners); Reference<XGridDataListener> xListener ( getPeer(), UNO_QUERY_THROW ); + Reference<XGridColumnListener> xColListener ( getPeer(), UNO_QUERY_THROW ); Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); Reference<XGridDataModel> xGridDataModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "GridDataModel" )), UNO_QUERY_THROW ); - xGridDataModel->addDataListener(xListener); + if(xGridDataModel != NULL) + xGridDataModel->addDataListener(xListener); + Reference<XGridColumnModel> xGridColumnModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "ColumnModel" )), UNO_QUERY_THROW ); + if(xGridColumnModel != NULL) + { + for(int i = 0;i<xGridColumnModel->getColumnCount();i++) + { + xGridColumnModel->getColumn(i)->addColumnListener(xColListener); + } + } } // ------------------------------------------------------------------- // XGridControl -// ------------------------------------------------------------------- - -::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > SAL_CALL UnoGridControl::getColumnModel() throw (::com::sun::star::uno::RuntimeException) -{ - Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); - Reference<XGridColumnModel> xGridColumnModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "ColumnModel" )), UNO_QUERY_THROW ); - - return xGridColumnModel; -} - -void SAL_CALL UnoGridControl::setColumnModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > & model) throw (::com::sun::star::uno::RuntimeException) -{ - Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); - xPropSet->setPropertyValue(OUString::createFromAscii( "ColumnModel" ), Any (model)); -} - -::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > SAL_CALL UnoGridControl::getDataModel() throw (::com::sun::star::uno::RuntimeException) -{ - Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); - Reference<XGridDataModel> xGridDataModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "GridDataModel" )), UNO_QUERY_THROW ); - - return xGridDataModel; -} - -void SAL_CALL UnoGridControl::setDataModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > & model) throw (::com::sun::star::uno::RuntimeException) -{ - Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); - xPropSet->setPropertyValue(OUString::createFromAscii( "GridDataModel" ), Any(model)); -} ::sal_Int32 UnoGridControl::getItemIndexAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException) { - return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getItemIndexAtPoint( x, y ); + Reference< XGridControl > xGrid ( getPeer(), UNO_QUERY_THROW ); + return xGrid->getItemIndexAtPoint( x, y ); } -/* -void SAL_CALL UnoGridControl::addMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL UnoGridControl::setToolTip(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& text, const ::com::sun::star::uno::Sequence< ::sal_Int32 >& columns) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->addMouseListener( listener ); + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->setToolTip( text, columns ); } - -void SAL_CALL UnoGridControl::removeMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException) -{ - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeMouseListener( listener ); -} -*/ // ------------------------------------------------------------------- // XGridSelection // ------------------------------------------------------------------- @@ -218,16 +224,24 @@ void SAL_CALL UnoGridControl::removeMouseListener(const ::com::sun::star::uno::R return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getMaxSelectionIndex(); } -void SAL_CALL UnoGridControl::insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL UnoGridControl::selectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->insertIndexIntervall( start, length); + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->selectRows( rangeOfRows); } -void SAL_CALL UnoGridControl::removeIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL UnoGridControl::selectAllRows() throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->selectAllRows(); +} +void SAL_CALL UnoGridControl::deselectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeIndexIntervall( start, length ); + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->deselectRows( rangeOfRows); } +void SAL_CALL UnoGridControl::deselectAllRows() throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->deselectAllRows(); +} ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL UnoGridControl::getSelection() throw (::com::sun::star::uno::RuntimeException) { return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getSelection(); @@ -250,14 +264,14 @@ void SAL_CALL UnoGridControl::selectRow(::sal_Int32 y) throw (::com::sun::star:: void SAL_CALL UnoGridControl::addSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->addSelectionListener( listener ); + m_aSelectionListeners.addInterface( listener ); } void SAL_CALL UnoGridControl::removeSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeSelectionListener( listener ); -} + m_aSelectionListeners.removeInterface( listener ); } +}//namespace toolkit Reference< XInterface > SAL_CALL GridControl_CreateInstance( const Reference< XMultiServiceFactory >& ) { diff --git a/toolkit/source/controls/grid/gridcontrol.hxx b/toolkit/source/controls/grid/gridcontrol.hxx index 4195a1f624e5..0c8ddb1c02b6 100644 --- a/toolkit/source/controls/grid/gridcontrol.hxx +++ b/toolkit/source/controls/grid/gridcontrol.hxx @@ -30,10 +30,11 @@ #include <com/sun/star/awt/grid/XGridControl.hpp> #include <com/sun/star/view/SelectionType.hpp> -#include <toolkit/controls/unocontrols.hxx> +#include <toolkit/controls/unocontrolbase.hxx> #include <toolkit/controls/unocontrolmodel.hxx> #include <toolkit/helper/servicenames.hxx> #include <cppuhelper/implbase1.hxx> +#include <comphelper/sequence.hxx> #include <toolkit/helper/listenermultiplexer.hxx> @@ -87,20 +88,18 @@ public: void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& Toolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& Parent ) throw(::com::sun::star::uno::RuntimeException); // ::com::sun::star::awt::grid::XGridControl - virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > SAL_CALL getColumnModel() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setColumnModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > & model) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > SAL_CALL getDataModel() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setDataModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > & model) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getItemIndexAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException); - //virtual void SAL_CALL addMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException); - //virtual void SAL_CALL removeMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setToolTip(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& text, const ::com::sun::star::uno::Sequence< ::sal_Int32 >& columns) throw (::com::sun::star::uno::RuntimeException); // ::com::sun::star::awt::grid::XGridSelection virtual ::sal_Int32 SAL_CALL getMinSelectionIndex() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getMaxSelectionIndex() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectAllRows() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deselectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deselectAllRows() throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL getSelection() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isSelectedIndex(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); @@ -114,6 +113,7 @@ public: using UnoControl::getPeer; private: ::com::sun::star::view::SelectionType mSelectionMode; + SelectionListenerMultiplexer m_aSelectionListeners; }; } // toolkit |