diff options
Diffstat (limited to 'toolkit/source/controls')
-rw-r--r-- | toolkit/source/controls/dialogcontrol.cxx | 40 | ||||
-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 | ||||
-rw-r--r-- | toolkit/source/controls/tksimpleanimation.cxx | 5 | ||||
-rw-r--r-- | toolkit/source/controls/tkthrobber.cxx | 19 | ||||
-rw-r--r-- | toolkit/source/controls/tree/treecontrol.cxx | 8 | ||||
-rw-r--r-- | toolkit/source/controls/tree/treecontrol.hxx | 1 | ||||
-rw-r--r-- | toolkit/source/controls/unocontrol.cxx | 52 | ||||
-rw-r--r-- | toolkit/source/controls/unocontrolmodel.cxx | 23 | ||||
-rw-r--r-- | toolkit/source/controls/unocontrols.cxx | 610 |
16 files changed, 1070 insertions, 275 deletions
diff --git a/toolkit/source/controls/dialogcontrol.cxx b/toolkit/source/controls/dialogcontrol.cxx index db9634fb44a1..405356c2b7ac 100644 --- a/toolkit/source/controls/dialogcontrol.cxx +++ b/toolkit/source/controls/dialogcontrol.cxx @@ -43,6 +43,9 @@ #include "toolkit/controls/tkscrollbar.hxx" #endif #include <toolkit/controls/stdtabcontroller.hxx> +#include <toolkit/controls/tksimpleanimation.hxx> +#include <toolkit/controls/tkthrobber.hxx> + #include <com/sun/star/awt/PosSize.hpp> #include <com/sun/star/awt/WindowAttribute.hpp> #include <com/sun/star/resource/XStringResourceResolver.hpp> @@ -453,6 +456,10 @@ Reference< XInterface > UnoControlDialogModel::createInstance( const ::rtl::OUSt pNewModel = new OGeometryControlModel< UnoTreeModel >; else if ( aServiceSpecifier.compareToAscii( szServiceName_GridControlModel ) == 0 ) pNewModel = new OGeometryControlModel< UnoGridModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoSimpleAnimationControlModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoSimpleAnimationControlModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoThrobberControlModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoThrobberControlModel >; if ( !pNewModel ) { @@ -492,7 +499,7 @@ Sequence< ::rtl::OUString > UnoControlDialogModel::getAvailableServiceNames() th static Sequence< ::rtl::OUString >* pNamesSeq = NULL; if ( !pNamesSeq ) { - pNamesSeq = new Sequence< ::rtl::OUString >( 21 ); + pNamesSeq = new Sequence< ::rtl::OUString >( 24 ); ::rtl::OUString* pNames = pNamesSeq->getArray(); pNames[0] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlEditModel ); pNames[1] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFormattedFieldModel ); @@ -515,8 +522,9 @@ Sequence< ::rtl::OUString > UnoControlDialogModel::getAvailableServiceNames() th pNames[18] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFixedLineModel ); pNames[19] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRoadmapModel ); pNames[20] = ::rtl::OUString::createFromAscii( szServiceName_TreeControlModel ); - pNames[20] = ::rtl::OUString::createFromAscii( szServiceName_GridControlModel ); - + pNames[21] = ::rtl::OUString::createFromAscii( szServiceName_GridControlModel ); + pNames[22] = ::rtl::OUString::createFromAscii( szServiceName2_UnoSimpleAnimationControlModel ); + pNames[23] = ::rtl::OUString::createFromAscii( szServiceName2_UnoThrobberControlModel ); } return *pNamesSeq; } @@ -1975,6 +1983,20 @@ void UnoDialogControl::ImplUpdateResourceResolver() } } +void SAL_CALL UnoDialogControl::endDialog( ::sal_Int32 i_result ) throw (RuntimeException) +{ + Reference< XDialog2 > xPeerDialog( getPeer(), UNO_QUERY ); + if ( xPeerDialog.is() ) + xPeerDialog->endDialog( i_result ); +} + +void SAL_CALL UnoDialogControl::setHelpId( ::sal_Int32 i_id ) throw (RuntimeException) +{ + Reference< XDialog2 > xPeerDialog( getPeer(), UNO_QUERY ); + if ( xPeerDialog.is() ) + xPeerDialog->setHelpId( i_id ); +} + void UnoDialogControl::setTitle( const ::rtl::OUString& Title ) throw(RuntimeException) { vos::OGuard aSolarGuard( Application::GetSolarMutex() ); @@ -2081,24 +2103,24 @@ throw (RuntimeException) ::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl ) { - - - ::rtl::OUString ret; - ::rtl::OUString baseLocation; ::rtl::OUString url; rbase >>= baseLocation; rUrl >>= url; + ::rtl::OUString absoluteURL( url ); if ( url.getLength() > 0 ) { INetURLObject urlObj(baseLocation); urlObj.removeSegment(); baseLocation = urlObj.GetMainURL( INetURLObject::NO_DECODE ); - ::osl::FileBase::getAbsoluteFileURL( baseLocation, url, ret ); + + ::rtl::OUString testAbsoluteURL; + if ( ::osl::FileBase::E_None == ::osl::FileBase::getAbsoluteFileURL( baseLocation, url, testAbsoluteURL ) ) + absoluteURL = testAbsoluteURL; } - return ret; + return absoluteURL; } 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 diff --git a/toolkit/source/controls/tksimpleanimation.cxx b/toolkit/source/controls/tksimpleanimation.cxx index 9c32ba500407..3d89bf59af82 100644 --- a/toolkit/source/controls/tksimpleanimation.cxx +++ b/toolkit/source/controls/tksimpleanimation.cxx @@ -109,8 +109,9 @@ namespace toolkit throw( uno::RuntimeException ) { uno::Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() ); - aServices.realloc( aServices.getLength() + 1 ); - aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSimpleAnimationControlModel ); + aServices.realloc( aServices.getLength() + 2 ); + aServices[ aServices.getLength() - 2 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSimpleAnimationControlModel ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName2_UnoSimpleAnimationControlModel ); return aServices; } diff --git a/toolkit/source/controls/tkthrobber.cxx b/toolkit/source/controls/tkthrobber.cxx index 978d3183fe23..1dc83f860e34 100644 --- a/toolkit/source/controls/tkthrobber.cxx +++ b/toolkit/source/controls/tkthrobber.cxx @@ -46,8 +46,13 @@ namespace toolkit //-------------------------------------------------------------------- UnoThrobberControlModel::UnoThrobberControlModel() { - ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); } //-------------------------------------------------------------------- @@ -63,6 +68,8 @@ namespace toolkit { case BASEPROPERTY_DEFAULTCONTROL: return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControl ) ); + case BASEPROPERTY_BORDER: + return uno::makeAny( (sal_Int16) 0 ); default: return UnoControlModel::ImplGetDefaultValue( nPropId ); } @@ -100,8 +107,9 @@ namespace toolkit throw( uno::RuntimeException ) { uno::Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() ); - aServices.realloc( aServices.getLength() + 1 ); - aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControlModel ); + aServices.realloc( aServices.getLength() + 2 ); + aServices[ aServices.getLength() - 2 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControlModel ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName2_UnoThrobberControlModel ); return aServices; } @@ -151,8 +159,9 @@ namespace toolkit throw( uno::RuntimeException ) { uno::Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() ); - aServices.realloc( aServices.getLength() + 1 ); - aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControl ); + aServices.realloc( aServices.getLength() + 2 ); + aServices[ aServices.getLength() - 2 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControl ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName2_UnoThrobberControl ); return aServices; } diff --git a/toolkit/source/controls/tree/treecontrol.cxx b/toolkit/source/controls/tree/treecontrol.cxx index 5655e4e10abc..8606792fdf2f 100644 --- a/toolkit/source/controls/tree/treecontrol.cxx +++ b/toolkit/source/controls/tree/treecontrol.cxx @@ -67,6 +67,7 @@ UnoTreeModel::UnoTreeModel() ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); ImplRegisterProperty( BASEPROPERTY_HELPURL ); ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_TABSTOP ); ImplRegisterProperty( BASEPROPERTY_TREE_SELECTIONTYPE ); ImplRegisterProperty( BASEPROPERTY_TREE_EDITABLE ); ImplRegisterProperty( BASEPROPERTY_TREE_DATAMODEL ); @@ -361,6 +362,13 @@ Reference< XTreeNode > SAL_CALL UnoTreeControl::getClosestNodeForLocation( sal_I // ------------------------------------------------------------------- +awt::Rectangle SAL_CALL UnoTreeControl::getNodeRect( const Reference< XTreeNode >& Node ) throw (IllegalArgumentException, RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getNodeRect( Node ); +} + +// ------------------------------------------------------------------- + sal_Bool SAL_CALL UnoTreeControl::isEditing( ) throw (RuntimeException) { return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isEditing(); diff --git a/toolkit/source/controls/tree/treecontrol.hxx b/toolkit/source/controls/tree/treecontrol.hxx index 0cae86616aa4..e646664c4a64 100644 --- a/toolkit/source/controls/tree/treecontrol.hxx +++ b/toolkit/source/controls/tree/treecontrol.hxx @@ -114,6 +114,7 @@ public: virtual void SAL_CALL removeTreeExpansionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeExpansionListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getClosestNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL getNodeRect( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isEditing( ) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL stopEditing( ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL cancelEditing( ) throw (::com::sun::star::uno::RuntimeException); diff --git a/toolkit/source/controls/unocontrol.cxx b/toolkit/source/controls/unocontrol.cxx index 1abe0b34004f..d91077823495 100644 --- a/toolkit/source/controls/unocontrol.cxx +++ b/toolkit/source/controls/unocontrol.cxx @@ -1535,3 +1535,55 @@ void SAL_CALL UnoControl::removeModeChangeApproveListener( const Reference< XMod throw NoSupportException( ); } +//---------------------------------------------------------------------------------------------------------------------- +awt::Point SAL_CALL UnoControl::convertPointToLogic( const awt::Point& i_Point, ::sal_Int16 i_TargetUnit ) throw (IllegalArgumentException, RuntimeException) +{ + Reference< XUnitConversion > xPeerConversion; + { + ::osl::MutexGuard aGuard( GetMutex() ); + xPeerConversion = xPeerConversion.query( getPeer() ); + } + if ( xPeerConversion.is() ) + return xPeerConversion->convertPointToLogic( i_Point, i_TargetUnit ); + return awt::Point( ); +} + +//---------------------------------------------------------------------------------------------------------------------- +awt::Point SAL_CALL UnoControl::convertPointToPixel( const awt::Point& i_Point, ::sal_Int16 i_SourceUnit ) throw (IllegalArgumentException, RuntimeException) +{ + Reference< XUnitConversion > xPeerConversion; + { + ::osl::MutexGuard aGuard( GetMutex() ); + xPeerConversion = xPeerConversion.query( getPeer() ); + } + if ( xPeerConversion.is() ) + return xPeerConversion->convertPointToPixel( i_Point, i_SourceUnit ); + return awt::Point( ); +} + +//---------------------------------------------------------------------------------------------------------------------- +awt::Size SAL_CALL UnoControl::convertSizeToLogic( const awt::Size& i_Size, ::sal_Int16 i_TargetUnit ) throw (IllegalArgumentException, RuntimeException) +{ + Reference< XUnitConversion > xPeerConversion; + { + ::osl::MutexGuard aGuard( GetMutex() ); + xPeerConversion = xPeerConversion.query( getPeer() ); + } + if ( xPeerConversion.is() ) + return xPeerConversion->convertSizeToLogic( i_Size, i_TargetUnit ); + return awt::Size( ); +} + +//---------------------------------------------------------------------------------------------------------------------- +awt::Size SAL_CALL UnoControl::convertSizeToPixel( const awt::Size& i_Size, ::sal_Int16 i_SourceUnit ) throw (IllegalArgumentException, RuntimeException) +{ + Reference< XUnitConversion > xPeerConversion; + { + ::osl::MutexGuard aGuard( GetMutex() ); + xPeerConversion = xPeerConversion.query( getPeer() ); + } + if ( xPeerConversion.is() ) + return xPeerConversion->convertSizeToPixel( i_Size, i_SourceUnit ); + return awt::Size( ); +} + diff --git a/toolkit/source/controls/unocontrolmodel.cxx b/toolkit/source/controls/unocontrolmodel.cxx index 29b683a5ed40..91d202409e86 100644 --- a/toolkit/source/controls/unocontrolmodel.cxx +++ b/toolkit/source/controls/unocontrolmodel.cxx @@ -216,10 +216,6 @@ sal_Bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId ) const return mpData->Get( nPropId ) ? sal_True : sal_False; } -void UnoControlModel::ImplPropertyChanged( sal_uInt16 ) -{ -} - ::com::sun::star::uno::Any UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const { ::com::sun::star::uno::Any aDefault; @@ -267,6 +263,7 @@ void UnoControlModel::ImplPropertyChanged( sal_uInt16 ) aDefault <<= Reference< awt::XDevice >(); break; + case BASEPROPERTY_ITEM_SEPARATOR_POS: case BASEPROPERTY_VERTICALALIGN: case BASEPROPERTY_BORDERCOLOR: case BASEPROPERTY_SYMBOL_COLOR: @@ -342,6 +339,7 @@ void UnoControlModel::ImplPropertyChanged( sal_uInt16 ) case BASEPROPERTY_HARDLINEBREAKS: case BASEPROPERTY_NOLABEL: aDefault <<= (sal_Bool) sal_False; break; + case BASEPROPERTY_MULTISELECTION_SIMPLEMODE: case BASEPROPERTY_HIDEINACTIVESELECTION: case BASEPROPERTY_ENFORCE_FORMAT: case BASEPROPERTY_AUTOCOMPLETE: @@ -1259,22 +1257,13 @@ sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); - // Fehlt: Die gefakten Einzelproperties des FontDescriptors... ImplControlProperty* pProp = mpData->Get( nPropId ); - if ( pProp ) - { - DBG_ASSERT( ( rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID ) || ( GetPropertyAttribs( (sal_uInt16)nPropId ) & ::com::sun::star::beans::PropertyAttribute::MAYBEVOID ), "Property darf nicht VOID sein!" ); - ImplPropertyChanged( (sal_uInt16)nPropId ); - pProp->SetValue( rValue ); - } - else - { - // exception... - DBG_ERROR( "SetPropertyValues: Invalid Property!" ); - } + ENSURE_OR_RETURN_VOID( pProp, "UnoControlModel::setFastPropertyValue_NoBroadcast: invalid property id!" ); + + DBG_ASSERT( ( rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID ) || ( GetPropertyAttribs( (sal_uInt16)nPropId ) & ::com::sun::star::beans::PropertyAttribute::MAYBEVOID ), "Property darf nicht VOID sein!" ); + pProp->SetValue( rValue ); } void UnoControlModel::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nPropId ) const diff --git a/toolkit/source/controls/unocontrols.cxx b/toolkit/source/controls/unocontrols.cxx index ae9e59d045e7..cfb71111e3dc 100644 --- a/toolkit/source/controls/unocontrols.cxx +++ b/toolkit/source/controls/unocontrols.cxx @@ -73,8 +73,11 @@ #include <tools/time.hxx> #include <algorithm> +#include <functional> using namespace ::com::sun::star; +using ::com::sun::star::graphic::XGraphic; +using ::com::sun::star::uno::Reference; using namespace ::toolkit; @@ -1841,19 +1844,130 @@ sal_Bool UnoGroupBoxControl::isTransparent() throw(uno::RuntimeException) return sal_True; } -// ---------------------------------------------------- -// class UnoControlListBoxModel -// ---------------------------------------------------- +// ===================================================================================================================== +// = UnoControlListBoxModel_Data +// ===================================================================================================================== +struct ListItem +{ + ::rtl::OUString ItemText; + ::rtl::OUString ItemImageURL; + Any ItemData; + + ListItem() + :ItemText() + ,ItemImageURL() + ,ItemData() + { + } + + ListItem( const ::rtl::OUString& i_rItemText ) + :ItemText( i_rItemText ) + ,ItemImageURL() + ,ItemData() + { + } +}; + +typedef beans::Pair< ::rtl::OUString, ::rtl::OUString > UnoListItem; + +struct StripItemData : public ::std::unary_function< ListItem, UnoListItem > +{ + UnoListItem operator()( const ListItem& i_rItem ) + { + return UnoListItem( i_rItem.ItemText, i_rItem.ItemImageURL ); + } +}; + +struct UnoControlListBoxModel_Data +{ + UnoControlListBoxModel_Data( UnoControlListBoxModel& i_rAntiImpl ) + :m_bSettingLegacyProperty( false ) + ,m_rAntiImpl( i_rAntiImpl ) + ,m_aListItems() + { + } + + sal_Int32 getItemCount() const { return sal_Int32( m_aListItems.size() ); } + + const ListItem& getItem( const sal_Int32 i_nIndex ) const + { + if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() ) ) ) + throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl ); + return m_aListItems[ i_nIndex ]; + } + + ListItem& getItem( const sal_Int32 i_nIndex ) + { + return const_cast< ListItem& >( static_cast< const UnoControlListBoxModel_Data* >( this )->getItem( i_nIndex ) ); + } + + ListItem& insertItem( const sal_Int32 i_nIndex ) + { + if ( ( i_nIndex < 0 ) || ( i_nIndex > sal_Int32( m_aListItems.size() ) ) ) + throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl ); + return *m_aListItems.insert( m_aListItems.begin() + i_nIndex, ListItem() ); + } + + Sequence< UnoListItem > getAllItems() const + { + Sequence< UnoListItem > aItems( sal_Int32( m_aListItems.size() ) ); + ::std::transform( m_aListItems.begin(), m_aListItems.end(), aItems.getArray(), StripItemData() ); + return aItems; + } + + void setAllItems( const ::std::vector< ListItem >& i_rItems ) + { + m_aListItems = i_rItems; + } + + void removeItem( const sal_Int32 i_nIndex ) + { + if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() ) ) ) + throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl ); + m_aListItems.erase( m_aListItems.begin() + i_nIndex ); + } + + void removeAllItems() + { + ::std::vector< ListItem > aEmpty; + m_aListItems.swap( aEmpty ); + } + +public: + bool m_bSettingLegacyProperty; + +private: + UnoControlListBoxModel& m_rAntiImpl; + ::std::vector< ListItem > m_aListItems; +}; + +// ===================================================================================================================== +// = UnoControlListBoxModel +// ===================================================================================================================== +// --------------------------------------------------------------------------------------------------------------------- UnoControlListBoxModel::UnoControlListBoxModel() + :UnoControlListBoxModel_Base() + ,m_pData( new UnoControlListBoxModel_Data( *this ) ) + ,m_aItemListListeners( GetMutex() ) { UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXListBox ); } +// --------------------------------------------------------------------------------------------------------------------- +UnoControlListBoxModel::UnoControlListBoxModel( const UnoControlListBoxModel& i_rSource ) + :UnoControlListBoxModel_Base( i_rSource ) + ,m_pData( new UnoControlListBoxModel_Data( *this ) ) + ,m_aItemListListeners( GetMutex() ) +{ +} + +// --------------------------------------------------------------------------------------------------------------------- ::rtl::OUString UnoControlListBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) { return ::rtl::OUString::createFromAscii( szServiceName_UnoControlListBoxModel ); } +// --------------------------------------------------------------------------------------------------------------------- uno::Any UnoControlListBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const { if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) @@ -1865,6 +1979,7 @@ uno::Any UnoControlListBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const return UnoControlModel::ImplGetDefaultValue( nPropId ); } +// --------------------------------------------------------------------------------------------------------------------- ::cppu::IPropertyArrayHelper& UnoControlListBoxModel::getInfoHelper() { static UnoPropertyArrayHelper* pHelper = NULL; @@ -1876,6 +1991,7 @@ uno::Any UnoControlListBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const return *pHelper; } +// --------------------------------------------------------------------------------------------------------------------- // beans::XMultiPropertySet uno::Reference< beans::XPropertySetInfo > UnoControlListBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) { @@ -1883,19 +1999,61 @@ uno::Reference< beans::XPropertySetInfo > UnoControlListBoxModel::getPropertySet return xInfo; } -void UnoControlListBoxModel::ImplPropertyChanged( sal_uInt16 nPropId ) +// --------------------------------------------------------------------------------------------------------------------- +namespace +{ + struct CreateListItem : public ::std::unary_function< ::rtl::OUString, ListItem > + { + ListItem operator()( const ::rtl::OUString& i_rItemText ) + { + return ListItem( i_rItemText ); + } + }; +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) throw (uno::Exception) { - if ( nPropId == BASEPROPERTY_STRINGITEMLIST ) + UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + + if ( nHandle == BASEPROPERTY_STRINGITEMLIST ) { + // reset selection uno::Sequence<sal_Int16> aSeq; uno::Any aAny; aAny <<= aSeq; setPropertyValue( GetPropertyName( BASEPROPERTY_SELECTEDITEMS ), aAny ); - } - UnoControlModel::ImplPropertyChanged( nPropId ); + if ( !m_pData->m_bSettingLegacyProperty ) + { + // synchronize the legacy StringItemList property with our list items + Sequence< ::rtl::OUString > aStringItemList; + Any aPropValue; + getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST ); + OSL_VERIFY( aPropValue >>= aStringItemList ); + + ::std::vector< ListItem > aItems( aStringItemList.getLength() ); + ::std::transform( + aStringItemList.getConstArray(), + aStringItemList.getConstArray() + aStringItemList.getLength(), + aItems.begin(), + CreateListItem() + ); + m_pData->setAllItems( aItems ); + + // since an XItemListListener does not have a "all items modified" or some such method, + // we simulate this by notifying removal of all items, followed by insertion of all new + // items + lang::EventObject aEvent; + aEvent.Source = *this; + m_aItemListListeners.notifyEach( &XItemListListener::itemListChanged, aEvent ); + // TODO: OPropertySetHelper calls into this method with the mutex locked ... + // which is wrong for the above notifications ... + } + } } +// --------------------------------------------------------------------------------------------------------------------- void UnoControlListBoxModel::ImplNormalizePropertySequence( const sal_Int32 _nCount, sal_Int32* _pHandles, uno::Any* _pValues, sal_Int32* _pValidHandles ) const SAL_THROW(()) { @@ -1906,12 +2064,327 @@ void UnoControlListBoxModel::ImplNormalizePropertySequence( const sal_Int32 _nCo UnoControlModel::ImplNormalizePropertySequence( _nCount, _pHandles, _pValues, _pValidHandles ); } +// --------------------------------------------------------------------------------------------------------------------- +::sal_Int32 SAL_CALL UnoControlListBoxModel::getItemCount() throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + return m_pData->getItemCount(); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::insertItem( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + ListItem& rItem( m_pData->insertItem( i_nPosition ) ); + rItem.ItemText = i_rItemText; + rItem.ItemImageURL = i_rItemImageURL; + + impl_handleInsert( i_nPosition, i_rItemText, i_rItemImageURL, aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::insertItemText( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + ListItem& rItem( m_pData->insertItem( i_nPosition ) ); + rItem.ItemText = i_rItemText; + + impl_handleInsert( i_nPosition, i_rItemText, ::boost::optional< ::rtl::OUString >(), aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::insertItemImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + ListItem& rItem( m_pData->insertItem( i_nPosition ) ); + rItem.ItemImageURL = i_rItemImageURL; + + impl_handleInsert( i_nPosition, ::boost::optional< ::rtl::OUString >(), i_rItemImageURL, aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::removeItem( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + m_pData->removeItem( i_nPosition ); + + impl_handleRemove( i_nPosition, aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::removeAllItems( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + m_pData->removeAllItems(); + + impl_handleRemove( -1, aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::setItemText( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + ListItem& rItem( m_pData->getItem( i_nPosition ) ); + rItem.ItemText = i_rItemText; + + impl_handleModify( i_nPosition, i_rItemText, ::boost::optional< ::rtl::OUString >(), aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::setItemImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + ListItem& rItem( m_pData->getItem( i_nPosition ) ); + rItem.ItemImageURL = i_rItemImageURL; + + impl_handleModify( i_nPosition, ::boost::optional< ::rtl::OUString >(), i_rItemImageURL, aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::setItemTextAndImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // SYNCHRONIZED -----> + ListItem& rItem( m_pData->getItem( i_nPosition ) ); + rItem.ItemText = i_rItemText; + rItem.ItemImageURL = i_rItemImageURL; + + impl_handleModify( i_nPosition, i_rItemText, i_rItemImageURL, aGuard ); + // <----- SYNCHRONIZED +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::setItemData( ::sal_Int32 i_nPosition, const Any& i_rDataValue ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + ListItem& rItem( m_pData->getItem( i_nPosition ) ); + rItem.ItemData = i_rDataValue; +} + +// --------------------------------------------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL UnoControlListBoxModel::getItemText( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + const ListItem& rItem( m_pData->getItem( i_nPosition ) ); + return rItem.ItemText; +} + +// --------------------------------------------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL UnoControlListBoxModel::getItemImage( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + const ListItem& rItem( m_pData->getItem( i_nPosition ) ); + return rItem.ItemImageURL; +} + +// --------------------------------------------------------------------------------------------------------------------- +beans::Pair< ::rtl::OUString, ::rtl::OUString > SAL_CALL UnoControlListBoxModel::getItemTextAndImage( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + const ListItem& rItem( m_pData->getItem( i_nPosition ) ); + return beans::Pair< ::rtl::OUString, ::rtl::OUString >( rItem.ItemText, rItem.ItemImageURL ); +} + +// --------------------------------------------------------------------------------------------------------------------- +Any SAL_CALL UnoControlListBoxModel::getItemData( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + const ListItem& rItem( m_pData->getItem( i_nPosition ) ); + return rItem.ItemData; +} + +// --------------------------------------------------------------------------------------------------------------------- +Sequence< beans::Pair< ::rtl::OUString, ::rtl::OUString > > SAL_CALL UnoControlListBoxModel::getAllItems( ) throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + return m_pData->getAllItems(); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::addItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener ) throw (uno::RuntimeException) +{ + if ( i_Listener.is() ) + m_aItemListListeners.addInterface( i_Listener ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UnoControlListBoxModel::removeItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener ) throw (uno::RuntimeException) +{ + if ( i_Listener.is() ) + m_aItemListListeners.removeInterface( i_Listener ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void UnoControlListBoxModel::impl_getStringItemList( ::std::vector< ::rtl::OUString >& o_rStringItems ) const +{ + Sequence< ::rtl::OUString > aStringItemList; + Any aPropValue; + getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST ); + OSL_VERIFY( aPropValue >>= aStringItemList ); + + o_rStringItems.resize( size_t( aStringItemList.getLength() ) ); + ::std::copy( + aStringItemList.getConstArray(), + aStringItemList.getConstArray() + aStringItemList.getLength(), + o_rStringItems.begin() + ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void UnoControlListBoxModel::impl_setStringItemList_nolck( const ::std::vector< ::rtl::OUString >& i_rStringItems ) +{ + Sequence< ::rtl::OUString > aStringItems( i_rStringItems.size() ); + ::std::copy( + i_rStringItems.begin(), + i_rStringItems.end(), + aStringItems.getArray() + ); + m_pData->m_bSettingLegacyProperty = true; + try + { + setFastPropertyValue( BASEPROPERTY_STRINGITEMLIST, uno::makeAny( aStringItems ) ); + } + catch( const Exception& ) + { + m_pData->m_bSettingLegacyProperty = false; + throw; + } + m_pData->m_bSettingLegacyProperty = false; +} + +// --------------------------------------------------------------------------------------------------------------------- +void UnoControlListBoxModel::impl_handleInsert( const sal_Int32 i_nItemPosition, const ::boost::optional< ::rtl::OUString >& i_rItemText, + const ::boost::optional< ::rtl::OUString >& i_rItemImageURL, ::osl::ClearableMutexGuard& i_rClearBeforeNotify ) +{ + // SYNCHRONIZED -----> + // sync with legacy StringItemList property + ::std::vector< ::rtl::OUString > aStringItems; + impl_getStringItemList( aStringItems ); + OSL_ENSURE( size_t( i_nItemPosition ) <= aStringItems.size(), "UnoControlListBoxModel::impl_handleInsert" ); + if ( size_t( i_nItemPosition ) <= aStringItems.size() ) + { + const ::rtl::OUString sItemText( !!i_rItemText ? *i_rItemText : ::rtl::OUString() ); + aStringItems.insert( aStringItems.begin() + i_nItemPosition, sItemText ); + } + + i_rClearBeforeNotify.clear(); + // <----- SYNCHRONIZED + impl_setStringItemList_nolck( aStringItems ); + + // notify ItemListListeners + impl_notifyItemListEvent_nolck( i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemInserted ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void UnoControlListBoxModel::impl_handleRemove( const sal_Int32 i_nItemPosition, ::osl::ClearableMutexGuard& i_rClearBeforeNotify ) +{ + // SYNCHRONIZED -----> + const bool bAllItems = ( i_nItemPosition < 0 ); + // sync with legacy StringItemList property + ::std::vector< ::rtl::OUString > aStringItems; + impl_getStringItemList( aStringItems ); + if ( !bAllItems ) + { + OSL_ENSURE( size_t( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleRemove" ); + if ( size_t( i_nItemPosition ) < aStringItems.size() ) + { + aStringItems.erase( aStringItems.begin() + i_nItemPosition ); + } + } + else + { + aStringItems.resize(0); + } + + i_rClearBeforeNotify.clear(); + // <----- SYNCHRONIZED + impl_setStringItemList_nolck( aStringItems ); + + // notify ItemListListeners + if ( bAllItems ) + { + EventObject aEvent( *this ); + m_aItemListListeners.notifyEach( &XItemListListener::allItemsRemoved, aEvent ); + } + else + { + impl_notifyItemListEvent_nolck( i_nItemPosition, ::boost::optional< ::rtl::OUString >(), ::boost::optional< ::rtl::OUString >(), + &XItemListListener::listItemRemoved ); + } +} + +// --------------------------------------------------------------------------------------------------------------------- +void UnoControlListBoxModel::impl_handleModify( const sal_Int32 i_nItemPosition, const ::boost::optional< ::rtl::OUString >& i_rItemText, + const ::boost::optional< ::rtl::OUString >& i_rItemImageURL, ::osl::ClearableMutexGuard& i_rClearBeforeNotify ) +{ + // SYNCHRONIZED -----> + if ( !!i_rItemText ) + { + // sync with legacy StringItemList property + ::std::vector< ::rtl::OUString > aStringItems; + impl_getStringItemList( aStringItems ); + OSL_ENSURE( size_t( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleModify" ); + if ( size_t( i_nItemPosition ) < aStringItems.size() ) + { + aStringItems[ i_nItemPosition] = *i_rItemText; + } + + i_rClearBeforeNotify.clear(); + // <----- SYNCHRONIZED + impl_setStringItemList_nolck( aStringItems ); + } + else + { + i_rClearBeforeNotify.clear(); + // <----- SYNCHRONIZED + } + + // notify ItemListListeners + impl_notifyItemListEvent_nolck( i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemModified ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void UnoControlListBoxModel::impl_notifyItemListEvent_nolck( const sal_Int32 i_nItemPosition, const ::boost::optional< ::rtl::OUString >& i_rItemText, + const ::boost::optional< ::rtl::OUString >& i_rItemImageURL, + void ( SAL_CALL XItemListListener::*NotificationMethod )( const ItemListEvent& ) ) +{ + ItemListEvent aEvent; + aEvent.Source = *this; + aEvent.ItemPosition = i_nItemPosition; + if ( !!i_rItemText ) + { + aEvent.ItemText.IsPresent = sal_True; + aEvent.ItemText.Value = *i_rItemText; + } + if ( !!i_rItemImageURL ) + { + aEvent.ItemImageURL.IsPresent = sal_True; + aEvent.ItemImageURL.Value = *i_rItemImageURL; + } + + m_aItemListListeners.notifyEach( NotificationMethod, aEvent ); +} + // ---------------------------------------------------- // class UnoListBoxControl // ---------------------------------------------------- UnoListBoxControl::UnoListBoxControl() - : maActionListeners( *this ), - maItemListeners( *this ) + :maActionListeners( *this ) + ,maItemListeners( *this ) { maComponentInfos.nWidth = 100; maComponentInfos.nHeight = 12; @@ -1922,27 +2395,6 @@ UnoListBoxControl::UnoListBoxControl() return ::rtl::OUString::createFromAscii( "listbox" ); } -// uno::XInterface -uno::Any UnoListBoxControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) -{ - uno::Any aRet = ::cppu::queryInterface( rType, - SAL_STATIC_CAST( awt::XListBox*, this ), - SAL_STATIC_CAST( awt::XItemListener*, this ), - SAL_STATIC_CAST( lang::XEventListener*, SAL_STATIC_CAST( awt::XItemListener*, this ) ), - SAL_STATIC_CAST( awt::XLayoutConstrains*, this ), - SAL_STATIC_CAST( awt::XTextLayoutConstrains*, this ) ); - return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); -} - -// lang::XTypeProvider -IMPL_XTYPEPROVIDER_START( UnoListBoxControl ) - getCppuType( ( uno::Reference< awt::XListBox>* ) NULL ), - getCppuType( ( uno::Reference< awt::XItemListener>* ) NULL ), - getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ), - getCppuType( ( uno::Reference< awt::XTextLayoutConstrains>* ) NULL ), - UnoControlBase::getTypes() -IMPL_XTYPEPROVIDER_END - void UnoListBoxControl::dispose() throw(uno::RuntimeException) { lang::EventObject aEvt; @@ -1966,24 +2418,32 @@ void UnoListBoxControl::ImplUpdateSelectedItemsProperty() } } -void UnoListBoxControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal ) +void UnoListBoxControl::updateFromModel() { - UnoControl::ImplSetPeerProperty( rPropName, rVal ); + UnoControlBase::updateFromModel(); - // Wenn die SelectedItems vor der StringItemList gesetzt werden, - // hat das keine Auswirkung... + Reference< XItemListListener > xItemListListener( getPeer(), UNO_QUERY ); + ENSURE_OR_RETURN_VOID( xItemListListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" ); + + EventObject aEvent( getModel() ); + xItemListListener->itemListChanged( aEvent ); + + // notify the change of the SelectedItems property, again. While our base class, in updateFromModel, + // already did this, our peer(s) can only legitimately set the selection after they have the string + // item list, which we just notified with the itemListChanged call. + const ::rtl::OUString sSelectedItemsPropName( GetPropertyName( BASEPROPERTY_SELECTEDITEMS ) ); + ImplSetPeerProperty( sSelectedItemsPropName, ImplGetPropertyValue( sSelectedItemsPropName ) ); +} + +void UnoListBoxControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal ) +{ if ( rPropName == GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ) - { - ::rtl::OUString aSelPropName = GetPropertyName( BASEPROPERTY_SELECTEDITEMS ); - uno::Any aVal = ImplGetPropertyValue( aSelPropName ); - if ( !( aVal.getValueType().getTypeClass() == uno::TypeClass_VOID ) ) - { - uno::Reference< awt::XVclWindowPeer > xW( getPeer(), uno::UNO_QUERY ); - if (xW.is()) - // same comment as in UnoControl::ImplSetPeerProperty - see there - xW->setProperty( aSelPropName, aVal ); - } - } + // do not forward this to our peer. We are a XItemListListener at our model, and changes in the string item + // list (which is a legacy property) will, later, arrive as changes in the ItemList. Those latter changes + // will be forwarded to the peer, which will update itself accordingly. + return; + + UnoControl::ImplSetPeerProperty( rPropName, rVal ); } void UnoListBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) @@ -2281,6 +2741,66 @@ void UnoListBoxControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines Impl_getColumnsAndLines( nCols, nLines ); } +sal_Bool SAL_CALL UnoListBoxControl::setModel( const uno::Reference< awt::XControlModel >& i_rModel ) throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + const Reference< XItemList > xOldItems( getModel(), UNO_QUERY ); + OSL_ENSURE( xOldItems.is() || !getModel().is(), "UnoListBoxControl::setModel: illegal old model!" ); + const Reference< XItemList > xNewItems( i_rModel, UNO_QUERY ); + OSL_ENSURE( xNewItems.is() || !i_rModel.is(), "UnoListBoxControl::setModel: illegal new model!" ); + + if ( !UnoListBoxControl_Base::setModel( i_rModel ) ) + return sal_False; + + if ( xOldItems.is() ) + xOldItems->removeItemListListener( this ); + if ( xNewItems.is() ) + xNewItems->addItemListListener( this ); + + return sal_True; +} + +void SAL_CALL UnoListBoxControl::listItemInserted( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) +{ + const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY ); + OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::listItemInserted: invalid peer!" ); + if ( xPeerListener.is() ) + xPeerListener->listItemInserted( i_rEvent ); +} + +void SAL_CALL UnoListBoxControl::listItemRemoved( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) +{ + const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY ); + OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::listItemRemoved: invalid peer!" ); + if ( xPeerListener.is() ) + xPeerListener->listItemRemoved( i_rEvent ); +} + +void SAL_CALL UnoListBoxControl::listItemModified( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) +{ + const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY ); + OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::listItemModified: invalid peer!" ); + if ( xPeerListener.is() ) + xPeerListener->listItemModified( i_rEvent ); +} + +void SAL_CALL UnoListBoxControl::allItemsRemoved( const lang::EventObject& i_rEvent ) throw (uno::RuntimeException) +{ + const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY ); + OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::allItemsRemoved: invalid peer!" ); + if ( xPeerListener.is() ) + xPeerListener->allItemsRemoved( i_rEvent ); +} + +void SAL_CALL UnoListBoxControl::itemListChanged( const lang::EventObject& i_rEvent ) throw (uno::RuntimeException) +{ + const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY ); + OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::itemListChanged: invalid peer!" ); + if ( xPeerListener.is() ) + xPeerListener->itemListChanged( i_rEvent ); +} + // ---------------------------------------------------- // class UnoControlComboBoxModel // ---------------------------------------------------- |