diff options
-rw-r--r-- | svtools/inc/svtools/table/tablecontrol.hxx | 139 | ||||
-rwxr-xr-x[-rw-r--r--] | svtools/inc/svtools/table/tablemodel.hxx | 71 | ||||
-rw-r--r-- | svtools/source/table/tablecontrol.cxx | 7 | ||||
-rwxr-xr-x | svtools/source/table/tablecontrol_impl.cxx | 402 | ||||
-rwxr-xr-x[-rw-r--r--] | svtools/source/table/tablecontrol_impl.hxx | 123 | ||||
-rw-r--r-- | svtools/source/uno/svtxgridcontrol.cxx | 182 | ||||
-rw-r--r-- | svtools/source/uno/svtxgridcontrol.hxx | 11 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.cxx | 214 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.hxx | 109 | ||||
-rw-r--r-- | toolkit/source/controls/grid/defaultgridcolumnmodel.cxx | 6 | ||||
-rw-r--r-- | toolkit/source/controls/grid/gridcontrol.cxx | 4 |
11 files changed, 724 insertions, 544 deletions
diff --git a/svtools/inc/svtools/table/tablecontrol.hxx b/svtools/inc/svtools/table/tablecontrol.hxx index f3b7ed88b565..07384540261b 100644 --- a/svtools/inc/svtools/table/tablecontrol.hxx +++ b/svtools/inc/svtools/table/tablecontrol.hxx @@ -33,8 +33,10 @@ #include <vcl/seleng.hxx> #include <svtools/table/tabledatawindow.hxx> #include <svtools/accessibletable.hxx> -#include <com/sun/star/util/Color.hpp> #include <svtools/accessiblefactory.hxx> + +#include <boost/shared_ptr.hpp> + //........................................................................ namespace svt { namespace table @@ -69,17 +71,18 @@ namespace svt { namespace table class SVT_DLLPUBLIC TableControl : public Control, public IAccessibleTable { private: - DECL_DLLPRIVATE_LINK( ImplMouseButtonDownHdl, MouseEvent* ); - DECL_DLLPRIVATE_LINK( ImplMouseButtonUpHdl, MouseEvent* ); + DECL_DLLPRIVATE_LINK( ImplMouseButtonDownHdl, MouseEvent* ); + DECL_DLLPRIVATE_LINK( ImplMouseButtonUpHdl, MouseEvent* ); - DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* ); + DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* ); - TableControl_Impl* m_pImpl; + ::boost::shared_ptr< TableControl_Impl > m_pImpl; ::com::sun::star::uno::Sequence< sal_Int32 > m_nCols; ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aText; Link m_aSelectHdl; bool m_bSelectionChanged; bool m_bTooltip; + public: ::std::auto_ptr< AccessibleTableControl_Impl > m_pAccessTable; @@ -157,22 +160,25 @@ namespace svt { namespace table { return GoTo( GetCurrentColumn(), _nRow ); } - SVT_DLLPRIVATE virtual void Resize(); - virtual void Select(); - SVT_DLLPRIVATE void SetSelectHdl( const Link& rLink ) { m_aSelectHdl = rLink; } - const Link& GetSelectHdl() const { return m_aSelectHdl; } - /**invalidates the table if table has been changed e.g. new row added - */ - void InvalidateDataWindow(RowPos _nRowStart, RowPos _nRowEnd, bool _bRemoved); - /**gets the vector, which contains the selected rows - */ - std::vector<sal_Int32>& GetSelectedRows(); - /**after removing a row, updates the vector which contains the selected rows - if the row, which should be removed, is selected, it will be erased from the vector - */ - SelectionEngine* getSelEngine(); - TableDataWindow* getDataWindow(); + SVT_DLLPRIVATE virtual void Resize(); + virtual void Select(); + SVT_DLLPRIVATE void SetSelectHdl( const Link& rLink ) { m_aSelectHdl = rLink; } + const Link& GetSelectHdl() const { return m_aSelectHdl; } + + /**invalidates the table if table has been changed e.g. new row added + */ + void InvalidateDataWindow(RowPos _nRowStart, RowPos _nRowEnd, bool _bRemoved); + + /**gets the vector, which contains the selected rows + */ + std::vector<sal_Int32>& GetSelectedRows(); + + /**after removing a row, updates the vector which contains the selected rows + if the row, which should be removed, is selected, it will be erased from the vector + */ + SelectionEngine* getSelEngine(); + TableDataWindow* getDataWindow(); // Window overridables virtual void GetFocus(); @@ -180,55 +186,54 @@ namespace svt { namespace table virtual void KeyInput( const KeyEvent& rKEvt ); virtual void StateChanged( StateChangedType i_nStateChange ); - /** Creates and returns the accessible object of the whole GridControl. */ - SVT_DLLPRIVATE virtual XACC CreateAccessible(); - SVT_DLLPRIVATE virtual XACC CreateAccessibleControl( sal_Int32 _nIndex ); - SVT_DLLPRIVATE virtual ::rtl::OUString GetAccessibleObjectName(AccessibleTableControlObjType eObjType, sal_Int32 _nRow, sal_Int32 _nCol) const; - SVT_DLLPRIVATE virtual sal_Bool GoToCell( sal_Int32 _nColumnPos, sal_Int32 _nRow ); - SVT_DLLPRIVATE virtual ::rtl::OUString GetAccessibleObjectDescription(AccessibleTableControlObjType eObjType, sal_Int32 _nPosition = -1) const; - virtual void FillAccessibleStateSet( - ::utl::AccessibleStateSetHelper& rStateSet, - AccessibleTableControlObjType eObjType ) const; - //// Window - virtual Rectangle GetWindowExtentsRelative( Window *pRelativeWindow ) const; - virtual void GrabFocus(); - virtual XACC GetAccessible( BOOL bCreate = TRUE ); - virtual Window* GetAccessibleParentWindow() const; - virtual Window* GetWindowInstance(); - virtual sal_Int32 GetAccessibleControlCount() const; - virtual sal_Bool ConvertPointToControlIndex( sal_Int32& _rnIndex, const Point& _rPoint ); - virtual long GetRowCount() const; - virtual long GetColumnCount() const; - virtual sal_Bool HasRowHeader() const; - virtual sal_Int32 GetSelectedRowCount() const; - virtual bool IsRowSelected( long _nRow ) const; - virtual sal_Bool ConvertPointToCellAddress( sal_Int32& _rnRow, sal_Int32& _rnColPos, const Point& _rPoint ); - virtual Rectangle calcHeaderRect( sal_Bool _bIsColumnBar, BOOL _bOnScreen = TRUE ); - virtual Rectangle calcTableRect( BOOL _bOnScreen = TRUE ); - virtual Rectangle GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex); - virtual sal_Int32 GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint); - virtual void FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper& _rStateSet, sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const; - virtual ::rtl::OUString GetRowDescription( sal_Int32 _nRow ) const; - virtual ::rtl::OUString GetRowName(sal_Int32 _nIndex) const; - virtual ::rtl::OUString GetColumnDescription( sal_uInt16 _nColumnPos ) const; - virtual ::rtl::OUString GetColumnName( sal_Int32 _nIndex ) const; - virtual ::com::sun::star::uno::Any GetCellContent( sal_Int32 _nRowPos, sal_Int32 _nColPos) const; - virtual sal_Bool HasRowHeader(); - virtual sal_Bool HasColHeader(); - virtual sal_Bool isAccessibleAlive( ) const; - virtual void commitGridControlEvent( sal_Int16 _nEventId, const com::sun::star::uno::Any& _rNewValue, const com::sun::star::uno::Any& _rOldValue ); - virtual void RemoveSelectedRow(RowPos _nRowPos); - virtual ::rtl::OUString GetAccessibleCellText(sal_Int32 _nRowPos, sal_Int32 _nColPos) const; - ::com::sun::star::uno::Sequence< sal_Int32 >& getColumnsForTooltip(); - ::com::sun::star::uno::Sequence< ::rtl::OUString >& getTextForTooltip(); - void setTooltip(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aText, const ::com::sun::star::uno::Sequence< sal_Int32 >& nCols); - void clearSelection(); - void selectionChanged(bool _bChanged); - bool isTooltip(); + /** Creates and returns the accessible object of the whole GridControl. */ + SVT_DLLPRIVATE virtual XACC CreateAccessible(); + SVT_DLLPRIVATE virtual XACC CreateAccessibleControl( sal_Int32 _nIndex ); + SVT_DLLPRIVATE virtual ::rtl::OUString GetAccessibleObjectName(AccessibleTableControlObjType eObjType, sal_Int32 _nRow, sal_Int32 _nCol) const; + SVT_DLLPRIVATE virtual sal_Bool GoToCell( sal_Int32 _nColumnPos, sal_Int32 _nRow ); + SVT_DLLPRIVATE virtual ::rtl::OUString GetAccessibleObjectDescription(AccessibleTableControlObjType eObjType, sal_Int32 _nPosition = -1) const; + virtual void FillAccessibleStateSet( + ::utl::AccessibleStateSetHelper& rStateSet, + AccessibleTableControlObjType eObjType ) const; + //// Window + virtual Rectangle GetWindowExtentsRelative( Window *pRelativeWindow ) const; + virtual void GrabFocus(); + virtual XACC GetAccessible( BOOL bCreate = TRUE ); + virtual Window* GetAccessibleParentWindow() const; + virtual Window* GetWindowInstance(); + virtual sal_Int32 GetAccessibleControlCount() const; + virtual sal_Bool ConvertPointToControlIndex( sal_Int32& _rnIndex, const Point& _rPoint ); + virtual long GetRowCount() const; + virtual long GetColumnCount() const; + virtual sal_Bool HasRowHeader() const; + virtual sal_Int32 GetSelectedRowCount() const; + virtual bool IsRowSelected( long _nRow ) const; + virtual sal_Bool ConvertPointToCellAddress( sal_Int32& _rnRow, sal_Int32& _rnColPos, const Point& _rPoint ); + virtual Rectangle calcHeaderRect( sal_Bool _bIsColumnBar, BOOL _bOnScreen = TRUE ); + virtual Rectangle calcTableRect( BOOL _bOnScreen = TRUE ); + virtual Rectangle GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex); + virtual sal_Int32 GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint); + virtual void FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper& _rStateSet, sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const; + virtual ::rtl::OUString GetRowDescription( sal_Int32 _nRow ) const; + virtual ::rtl::OUString GetRowName(sal_Int32 _nIndex) const; + virtual ::rtl::OUString GetColumnDescription( sal_uInt16 _nColumnPos ) const; + virtual ::rtl::OUString GetColumnName( sal_Int32 _nIndex ) const; + virtual ::com::sun::star::uno::Any GetCellContent( sal_Int32 _nRowPos, sal_Int32 _nColPos) const; + virtual sal_Bool HasRowHeader(); + virtual sal_Bool HasColHeader(); + virtual sal_Bool isAccessibleAlive( ) const; + virtual void commitGridControlEvent( sal_Int16 _nEventId, const com::sun::star::uno::Any& _rNewValue, const com::sun::star::uno::Any& _rOldValue ); + virtual void RemoveSelectedRow(RowPos _nRowPos); + virtual ::rtl::OUString GetAccessibleCellText(sal_Int32 _nRowPos, sal_Int32 _nColPos) const; + ::com::sun::star::uno::Sequence< sal_Int32 >& getColumnsForTooltip(); + ::com::sun::star::uno::Sequence< ::rtl::OUString >& getTextForTooltip(); + void setTooltip(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aText, const ::com::sun::star::uno::Sequence< sal_Int32 >& nCols); + void clearSelection(); + void selectionChanged(bool _bChanged); + bool isTooltip(); protected: - /// retrieves the XAccessible implementation associated with the GridControl instance - ::svt::IAccessibleFactory& getAccessibleFactory(); + ::svt::IAccessibleFactory& getAccessibleFactory(); private: TableControl(); // never implemented diff --git a/svtools/inc/svtools/table/tablemodel.hxx b/svtools/inc/svtools/table/tablemodel.hxx index f67bfe72b05b..a9d6c7325e65 100644..100755 --- a/svtools/inc/svtools/table/tablemodel.hxx +++ b/svtools/inc/svtools/table/tablemodel.hxx @@ -28,16 +28,20 @@ #define SVTOOLS_INC_TABLE_TABLEMODEL_HXX #include "svtools/svtdllapi.h" -#include <svtools/table/tabletypes.hxx> -#include <svtools/table/tablerenderer.hxx> -#include <svtools/table/tableinputhandler.hxx> -#include <rtl/ref.hxx> -#include <sal/types.h> +#include "svtools/table/tabletypes.hxx" +#include "svtools/table/tablerenderer.hxx" +#include "svtools/table/tableinputhandler.hxx" + #include <com/sun/star/util/Color.hpp> -#include <boost/shared_ptr.hpp> #include <com/sun/star/style/VerticalAlignment.hpp> #include <com/sun/star/style/HorizontalAlignment.hpp> +#include <rtl/ref.hxx> +#include <sal/types.h> + +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> + //........................................................................ namespace svt { namespace table { @@ -81,10 +85,9 @@ namespace svt { namespace table /** declares an interface to be implemented by components interested in changes in an ->ITableModel */ - class SAL_NO_VTABLE ITableModelListener + class SAL_NO_VTABLE ITableModelListener : public ::boost::enable_shared_from_this< ITableModelListener > { public: - //virtual void onTableModelChanged(PTableModel pTableModel) = 0; /** notifies the listener that one or more rows have been inserted into the table @@ -122,9 +125,9 @@ namespace svt { namespace table the table @param first - the old index of the first removed row + the old index of the first removed column @param last - the old index of the last removed row. Must not be smaller + the old index of the last removed column. Must not be smaller than ->first */ virtual void columnsRemoved( ColPos first, ColPos last ) = 0; @@ -355,21 +358,9 @@ namespace svt { namespace table @return the model of the column in question. Must not be <NULL/> - - @see getColumnModelByID */ virtual PColumnModel getColumnModel( ColPos column ) = 0; - /** finds a column model by ID - - @param id - the id of the column which is to be looked up - @return - the column model with the given ID, or <NULL/> if there is - no such column - */ - virtual PColumnModel getColumnModelByID( ColumnID id ) = 0; - /** returns a renderer which is able to paint the table represented by this table model @@ -423,22 +414,30 @@ namespace svt { namespace table */ virtual ScrollbarVisibility getHorizontalScrollbarVisibility(int overAllWidth, int actWidth) const = 0; - virtual bool hasVerticalScrollbar() = 0; - virtual bool hasHorizontalScrollbar() = 0; + /** adds a listener to be notified of changes in the table model + */ + virtual void addTableModelListener( const PTableModelListener& i_listener ) = 0; - /** gets the content of the cells - */ - virtual std::vector< std::vector< ::com::sun::star::uno::Any > >& getCellContent() = 0; + /** remove a listener to be notified of changes in the table model + */ + virtual void removeTableModelListener( const PTableModelListener& i_listener ) = 0; - /** gets title of header rows - */ - virtual std::vector<rtl::OUString>& getRowHeaderName() = 0; - SVT_DLLPRIVATE virtual ::com::sun::star::util::Color getLineColor() = 0; - SVT_DLLPRIVATE virtual ::com::sun::star::util::Color getHeaderBackgroundColor() = 0; - SVT_DLLPRIVATE virtual ::com::sun::star::util::Color getTextColor() = 0; - SVT_DLLPRIVATE virtual ::com::sun::star::util::Color getOddRowBackgroundColor() = 0; - SVT_DLLPRIVATE virtual ::com::sun::star::util::Color getEvenRowBackgroundColor() = 0; - SVT_DLLPRIVATE virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign() = 0; + virtual bool hasVerticalScrollbar() = 0; + virtual bool hasHorizontalScrollbar() = 0; + + /** gets the content of the cells + */ + virtual std::vector< std::vector< ::com::sun::star::uno::Any > >& getCellContent() = 0; + + /** gets title of header rows + */ + virtual std::vector<rtl::OUString>& getRowHeaderName() = 0; + virtual ::com::sun::star::util::Color getLineColor() = 0; + virtual ::com::sun::star::util::Color getHeaderBackgroundColor() = 0; + virtual ::com::sun::star::util::Color getTextColor() = 0; + virtual ::com::sun::star::util::Color getOddRowBackgroundColor() = 0; + virtual ::com::sun::star::util::Color getEvenRowBackgroundColor() = 0; + virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign() = 0; /// destroys the table model instance virtual ~ITableModel() { } diff --git a/svtools/source/table/tablecontrol.cxx b/svtools/source/table/tablecontrol.cxx index 33c80e642118..cde198a92a6e 100644 --- a/svtools/source/table/tablecontrol.cxx +++ b/svtools/source/table/tablecontrol.cxx @@ -88,11 +88,12 @@ namespace svt { namespace table TableControl::~TableControl() { ImplCallEventListeners( VCLEVENT_OBJECT_DYING ); - DELETEZ( m_pImpl ); + + m_pImpl->setModel( PTableModel() ); + m_pImpl.reset(); + if ( m_pAccessTable->m_pAccessible ) - { m_pAccessTable->m_pAccessible->dispose(); - } } //-------------------------------------------------------------------- diff --git a/svtools/source/table/tablecontrol_impl.cxx b/svtools/source/table/tablecontrol_impl.cxx index acb8f9e691a9..46ebda453b10 100755 --- a/svtools/source/table/tablecontrol_impl.cxx +++ b/svtools/source/table/tablecontrol_impl.cxx @@ -30,19 +30,20 @@ #include "svtools/table/tablecontrol.hxx" #include "svtools/table/defaultinputhandler.hxx" #include "svtools/table/tablemodel.hxx" +#include "svtools/table/tabledatawindow.hxx" + #include "tablecontrol_impl.hxx" #include "tablegeometry.hxx" -#include "svtools/table/tabledatawindow.hxx" -#include <com/sun/star/awt/XControl.hpp> + +#include <com/sun/star/graphic/XGraphic.hpp> + #include <vcl/scrbar.hxx> #include <vcl/seleng.hxx> #include <rtl/ref.hxx> -#include <toolkit/awt/vclxwindow.hxx> #include <vcl/image.hxx> -#include <com/sun/star/graphic/XGraphic.hpp> +#include <tools/diagnose_ex.h> #include <functional> -#include <stdlib.h> //........................................................................ namespace svt { namespace table @@ -108,28 +109,12 @@ namespace svt { namespace table (void)row; return false; } - virtual void addTableModelListener( const PTableModelListener& listener ) - { - (void)listener; - // ignore - } - virtual void removeTableModelListener( const PTableModelListener& listener ) - { - (void)listener; - // ignore - } virtual PColumnModel getColumnModel( ColPos column ) { DBG_ERROR( "EmptyTableModel::getColumnModel: invalid call!" ); (void)column; return PColumnModel(); } - virtual PColumnModel getColumnModelByID( ColumnID id ) - { - DBG_ERROR( "EmptyTableModel::getColumnModel: invalid call!" ); - (void)id; - return PColumnModel(); - } virtual PTableRenderer getRenderer() const { return PTableRenderer(); @@ -154,56 +139,64 @@ namespace svt { namespace table { return 0; } - virtual ScrollbarVisibility getVerticalScrollbarVisibility(int , int ) const + virtual ScrollbarVisibility getVerticalScrollbarVisibility(int , int ) const { - return ScrollbarShowNever; + return ScrollbarShowNever; } virtual ScrollbarVisibility getHorizontalScrollbarVisibility(int , int ) const { - return ScrollbarShowNever; + return ScrollbarShowNever; + } + virtual void addTableModelListener( const PTableModelListener& i_listener ) + { + (void)i_listener; + } + virtual void removeTableModelListener( const PTableModelListener& i_listener ) + { + (void)i_listener; + } + virtual bool hasVerticalScrollbar() + { + return false; + } + virtual bool hasHorizontalScrollbar() + { + return false; + } + virtual ::com::sun::star::util::Color getLineColor() + { + return 0; + } + virtual ::com::sun::star::util::Color getHeaderBackgroundColor() + { + return -1; + } + virtual ::com::sun::star::util::Color getTextColor() + { + return 0; + } + virtual ::com::sun::star::util::Color getOddRowBackgroundColor() + { + return -1; + } + virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign() + { + return com::sun::star::style::VerticalAlignment(0); + } + virtual ::com::sun::star::util::Color getEvenRowBackgroundColor() + { + return -1; + } + virtual std::vector<std::vector< ::com::sun::star::uno::Any > >& getCellContent() + { + return m_aCellContent; + } + virtual std::vector<rtl::OUString>& getRowHeaderName() + { + aRowHeaderNames.clear(); + aRowHeaderNames.push_back(rtl::OUString::createFromAscii("")); + return aRowHeaderNames; } - virtual bool hasVerticalScrollbar() - { - return false; - } - virtual bool hasHorizontalScrollbar() - { - return false; - } - virtual ::com::sun::star::util::Color getLineColor() - { - return 0; - } - virtual ::com::sun::star::util::Color getHeaderBackgroundColor() - { - return -1; - } - virtual ::com::sun::star::util::Color getTextColor() - { - return 0; - } - virtual ::com::sun::star::util::Color getOddRowBackgroundColor() - { - return -1; - } - virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign() - { - return com::sun::star::style::VerticalAlignment(0); - } - virtual ::com::sun::star::util::Color getEvenRowBackgroundColor() - { - return -1; - } - virtual std::vector<std::vector< ::com::sun::star::uno::Any > >& getCellContent() - { - return m_aCellContent; - } - virtual std::vector<rtl::OUString>& getRowHeaderName() - { - aRowHeaderNames.clear(); - aRowHeaderNames.push_back(rtl::OUString::createFromAscii("")); - return aRowHeaderNames; - } private: std::vector<rtl::OUString> aRowHeaderNames; std::vector<std::vector< ::com::sun::star::uno::Any > > m_aCellContent; @@ -376,33 +369,33 @@ namespace svt { namespace table ,m_pModel ( new EmptyTableModel ) ,m_pInputHandler ( ) ,m_nRowHeightPixel ( 15 ) - ,m_nColHeaderHeightPixel( 0 ) + ,m_nColHeaderHeightPixel( 0 ) ,m_nRowHeaderWidthPixel ( 0 ) ,m_nColumnCount ( 0 ) ,m_nRowCount ( 0 ) ,m_nCurColumn ( COL_INVALID ) ,m_nCurRow ( ROW_INVALID ) ,m_nLeftColumn ( 0 ) - ,m_nTopRow ( 0 ) + ,m_nTopRow ( 0 ) ,m_nCursorHidden ( 1 ) ,m_pDataWindow ( new TableDataWindow( *this ) ) - ,m_pVScroll ( NULL ) + ,m_pVScroll ( NULL ) ,m_pHScroll ( NULL ) ,m_pScrollCorner ( NULL ) - ,m_pSelEngine ( ) - ,m_nRowSelected ( ) - ,m_pTableFunctionSet ( new TableFunctionSet(this ) ) - ,m_nAnchor (-1 ) - ,m_bResizing ( false ) - ,m_nResizingColumn ( 0 ) - ,m_bResizingGrid ( false ) + ,m_pSelEngine ( ) + ,m_nRowSelected ( ) + ,m_pTableFunctionSet ( new TableFunctionSet( this ) ) + ,m_nAnchor (-1 ) + ,m_bResizing ( false ) + ,m_nResizingColumn ( 0 ) + ,m_bResizingGrid ( false ) #if DBG_UTIL ,m_nRequiredInvariants ( INV_SCROLL_POSITION ) #endif { DBG_CTOR( TableControl_Impl, TableControl_Impl_checkInvariants ); - m_pSelEngine = new SelectionEngine(m_pDataWindow, m_pTableFunctionSet); - m_pSelEngine->SetSelectionMode(SINGLE_SELECTION); + m_pSelEngine = new SelectionEngine(m_pDataWindow, m_pTableFunctionSet); + m_pSelEngine->SetSelectionMode(SINGLE_SELECTION); m_pDataWindow->SetPosPixel( Point( 0, 0 ) ); m_pDataWindow->Show(); } @@ -437,15 +430,21 @@ namespace svt { namespace table TempHideCursor aHideCursor( *this ); + if ( !!m_pModel ) + m_pModel->removeTableModelListener( shared_from_this() ); + m_pModel = _pModel; if ( !m_pModel) m_pModel.reset( new EmptyTableModel ); + m_pModel->addTableModelListener( shared_from_this() ); + m_nCurRow = ROW_INVALID; m_nCurColumn = COL_INVALID; // recalc some model-dependent cached info impl_ni_updateCachedModelValues(); + impl_ni_updateScrollbars(); // completely invalidate m_rAntiImpl.Invalidate(); @@ -456,6 +455,60 @@ namespace svt { namespace table } //-------------------------------------------------------------------- + void TableControl_Impl::rowsInserted( RowPos first, RowPos last ) + { + OSL_ENSURE( false, "TableControl_Impl::rowsInserted: not implemented!" ); + // there's no known implementation (yet) which calls this method + OSL_UNUSED( first ); + OSL_UNUSED( last ); + } + + //-------------------------------------------------------------------- + void TableControl_Impl::rowsRemoved( RowPos first, RowPos last ) + { + OSL_ENSURE( false, "TableControl_Impl::rowsRemoved: not implemented!" ); + // there's no known implementation (yet) which calls this method + OSL_UNUSED( first ); + OSL_UNUSED( last ); + } + + //-------------------------------------------------------------------- + void TableControl_Impl::columnsInserted( ColPos first, ColPos last ) + { + impl_ni_updateColumnWidths(); + (void)first; + (void)last; + } + + //-------------------------------------------------------------------- + void TableControl_Impl::columnsRemoved( ColPos first, ColPos last ) + { + impl_ni_updateColumnWidths(); + (void)first; + (void)last; + } + + //-------------------------------------------------------------------- + void TableControl_Impl::columnMoved( ColPos oldIndex, ColPos newIndex ) + { + OSL_ENSURE( false, "TableControl_Impl::columnMoved: not implemented!" ); + // there's no known implementation (yet) which calls this method + OSL_UNUSED( oldIndex ); + OSL_UNUSED( newIndex ); + } + + //-------------------------------------------------------------------- + void TableControl_Impl::cellsUpdated( ColPos firstCol, ColPos lastCol, RowPos firstRow, RowPos lastRow ) + { + OSL_ENSURE( false, "TableControl_Impl::cellsUpdated: not implemented!" ); + // there's no known implementation (yet) which calls this method + OSL_UNUSED( firstCol ); + OSL_UNUSED( lastCol ); + OSL_UNUSED( firstRow ); + OSL_UNUSED( lastRow ); + } + + //-------------------------------------------------------------------- void TableControl_Impl::impl_getAllVisibleCellsArea( Rectangle& _rCellArea ) const { DBG_CHECK_ME(); @@ -510,8 +563,8 @@ namespace svt { namespace table m_pInputHandler.reset(); m_nColumnCount = m_nRowCount = 0; - m_nRowHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getRowHeight() ), MAP_APPFONT ).Height(); - if ( m_pModel->hasColumnHeaders() ) + m_nRowHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getRowHeight() ), MAP_APPFONT ).Height(); + if ( m_pModel->hasColumnHeaders() ) m_nColHeaderHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getColumnHeaderHeight() ), MAP_APPFONT ).Height(); if ( m_pModel->hasRowHeaders() ) m_nRowHeaderWidthPixel = m_rAntiImpl.LogicToPixel( Size( m_pModel->getRowHeaderWidth(), 0 ), MAP_APPFONT).Width(); @@ -535,114 +588,114 @@ namespace svt { namespace table return; TableSize colCount = m_pModel->getColumnCount(); + if ( colCount == 0 ) + return; m_aColumnWidthsPixel.reserve( colCount ); m_aAccColumnWidthsPixel.reserve( colCount ); - if(colCount>0) + + std::vector<sal_Int32> aPrePixelWidths(0); + long accumulatedPixelWidth = 0; + int lastResizableCol = -1; + double gridWidth = m_rAntiImpl.GetOutputSizePixel().Width(); + if(m_pModel->hasRowHeaders()) { - std::vector<sal_Int32> aPrePixelWidths(0); - long accumulatedPixelWidth = 0; - int lastResizableCol = -1; - double gridWidth = m_rAntiImpl.GetOutputSizePixel().Width(); - if(m_pModel->hasRowHeaders()) - { - TableMetrics rowHeaderWidth = m_pModel->getRowHeaderWidth(); - gridWidth-= m_rAntiImpl.LogicToPixel( Size( rowHeaderWidth, 0 ), MAP_APPFONT ).Width(); - } - if(m_pModel->hasVerticalScrollbar()) + TableMetrics rowHeaderWidth = m_pModel->getRowHeaderWidth(); + gridWidth-= m_rAntiImpl.LogicToPixel( Size( rowHeaderWidth, 0 ), MAP_APPFONT ).Width(); + } + if(m_pModel->hasVerticalScrollbar()) + { + sal_Int32 scrollbarWidth = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize(); + gridWidth-=scrollbarWidth; + } + double colWidthsSum = 0.0; + double colWithoutFixedWidthsSum = 0.0; + double minColWithoutFixedSum = 0.0; + for ( ColPos col = 0; col < colCount; ++col ) + { + PColumnModel pColumn = m_pModel->getColumnModel( col ); + DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" ); + if ( !pColumn ) + continue; + TableMetrics colWidth = 0; + TableMetrics colPrefWidth = pColumn->getPreferredWidth(); + bool bResizable = pColumn->isResizable(); + if(pColumn->getMinWidth() == 0 && bResizable) { - sal_Int32 scrollbarWidth = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize(); - gridWidth-=scrollbarWidth; + pColumn->setMinWidth(1); + minColWithoutFixedSum+=m_rAntiImpl.PixelToLogic( Size( 1, 0 ), MAP_APPFONT ).Width(); } - double colWidthsSum = 0.0; - double colWithoutFixedWidthsSum = 0.0; - double minColWithoutFixedSum = 0.0; - for ( ColPos col = 0; col < colCount; ++col ) + if(pColumn->getMaxWidth() == 0 && bResizable) + pColumn->setMaxWidth(m_rAntiImpl.PixelToLogic( Size( (int)gridWidth, 0 ), MAP_APPFONT ).Width()); + if( colPrefWidth != 0) { - PColumnModel pColumn = m_pModel->getColumnModel( col ); - DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" ); - if ( !pColumn ) - continue; - TableMetrics colWidth = 0; - TableMetrics colPrefWidth = pColumn->getPreferredWidth(); - bool bResizable = pColumn->isResizable(); - if(pColumn->getMinWidth() == 0 && bResizable) - { - pColumn->setMinWidth(1); - minColWithoutFixedSum+=m_rAntiImpl.PixelToLogic( Size( 1, 0 ), MAP_APPFONT ).Width(); - } - if(pColumn->getMaxWidth() == 0 && bResizable) - pColumn->setMaxWidth(m_rAntiImpl.PixelToLogic( Size( (int)gridWidth, 0 ), MAP_APPFONT ).Width()); - if( colPrefWidth != 0) + if(m_bResizingGrid) { - if(m_bResizingGrid) - { - colWidth = pColumn->getWidth(); - pColumn->setPreferredWidth(0); - } - else - { - colWidth = colPrefWidth; - pColumn->setWidth(colPrefWidth); - } + colWidth = pColumn->getWidth(); + pColumn->setPreferredWidth(0); } else - colWidth = pColumn->getWidth(); - long pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width(); - if(bResizable && colPrefWidth == 0) { - colWithoutFixedWidthsSum+=pixelWidth; - lastResizableCol = col; + colWidth = colPrefWidth; + pColumn->setWidth(colPrefWidth); } - colWidthsSum+=pixelWidth; - aPrePixelWidths.push_back(pixelWidth); } - double gridWidthWithoutFixed = gridWidth - colWidthsSum + colWithoutFixedWidthsSum; - double scalingFactor = 1.0; - if(m_bResizingGrid) + else + colWidth = pColumn->getWidth(); + long pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width(); + if(bResizable && colPrefWidth == 0) { - if(gridWidthWithoutFixed > (minColWithoutFixedSum+colWidthsSum - colWithoutFixedWidthsSum)) - scalingFactor = gridWidthWithoutFixed/colWithoutFixedWidthsSum; + colWithoutFixedWidthsSum+=pixelWidth; + lastResizableCol = col; } - else + colWidthsSum+=pixelWidth; + aPrePixelWidths.push_back(pixelWidth); + } + double gridWidthWithoutFixed = gridWidth - colWidthsSum + colWithoutFixedWidthsSum; + double scalingFactor = 1.0; + if(m_bResizingGrid) + { + if(gridWidthWithoutFixed > (minColWithoutFixedSum+colWidthsSum - colWithoutFixedWidthsSum)) + scalingFactor = gridWidthWithoutFixed/colWithoutFixedWidthsSum; + } + else + { + if(colWidthsSum < gridWidthWithoutFixed) { - if(colWidthsSum < gridWidthWithoutFixed) - { - if(colWithoutFixedWidthsSum>0) - scalingFactor = gridWidthWithoutFixed/colWithoutFixedWidthsSum; - } + if(colWithoutFixedWidthsSum>0) + scalingFactor = gridWidthWithoutFixed/colWithoutFixedWidthsSum; } - for ( ColPos i = 0; i < colCount; ++i ) + } + for ( ColPos i = 0; i < colCount; ++i ) + { + PColumnModel pColumn = m_pModel->getColumnModel( i ); + DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" ); + if ( !pColumn ) + continue; + if(pColumn->isResizable() && pColumn->getPreferredWidth() == 0) { - PColumnModel pColumn = m_pModel->getColumnModel( i ); - DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" ); - if ( !pColumn ) - continue; - if(pColumn->isResizable() && pColumn->getPreferredWidth() == 0) - { - aPrePixelWidths[i]*=scalingFactor; - TableMetrics logicColWidth = m_rAntiImpl.PixelToLogic( Size( aPrePixelWidths[i], 0 ), MAP_APPFONT ).Width(); - pColumn->setWidth(logicColWidth); - } - m_aColumnWidthsPixel.push_back( aPrePixelWidths[i] ); - m_aAccColumnWidthsPixel.push_back( accumulatedPixelWidth += aPrePixelWidths[i] ); + aPrePixelWidths[i]*=scalingFactor; + TableMetrics logicColWidth = m_rAntiImpl.PixelToLogic( Size( aPrePixelWidths[i], 0 ), MAP_APPFONT ).Width(); + pColumn->setWidth(logicColWidth); } - if(gridWidth > m_aAccColumnWidthsPixel[colCount-1]) + m_aColumnWidthsPixel.push_back( aPrePixelWidths[i] ); + m_aAccColumnWidthsPixel.push_back( accumulatedPixelWidth += aPrePixelWidths[i] ); + } + if(gridWidth > m_aAccColumnWidthsPixel[colCount-1]) + { + if(lastResizableCol >= 0) { - if(lastResizableCol >= 0) + PColumnModel pColumn = m_pModel->getColumnModel(lastResizableCol); + m_aColumnWidthsPixel[lastResizableCol]+=gridWidth-m_aAccColumnWidthsPixel[colCount-1]; + TableMetrics logicColWidth1 = m_rAntiImpl.PixelToLogic( Size( m_aColumnWidthsPixel[lastResizableCol], 0 ), MAP_APPFONT ).Width(); + pColumn->setWidth(logicColWidth1); + while(lastResizableCol < colCount) { - PColumnModel pColumn = m_pModel->getColumnModel(lastResizableCol); - m_aColumnWidthsPixel[lastResizableCol]+=gridWidth-m_aAccColumnWidthsPixel[colCount-1]; - TableMetrics logicColWidth1 = m_rAntiImpl.PixelToLogic( Size( m_aColumnWidthsPixel[lastResizableCol], 0 ), MAP_APPFONT ).Width(); - pColumn->setWidth(logicColWidth1); - while(lastResizableCol < colCount) - { - if(lastResizableCol == 0) - m_aAccColumnWidthsPixel[0] = m_aColumnWidthsPixel[lastResizableCol]; - else - m_aAccColumnWidthsPixel[lastResizableCol]=m_aAccColumnWidthsPixel[lastResizableCol-1]+m_aColumnWidthsPixel[lastResizableCol]; - ++lastResizableCol; - } + if(lastResizableCol == 0) + m_aAccColumnWidthsPixel[0] = m_aColumnWidthsPixel[lastResizableCol]; + else + m_aAccColumnWidthsPixel[lastResizableCol]=m_aAccColumnWidthsPixel[lastResizableCol-1]+m_aColumnWidthsPixel[lastResizableCol]; + ++lastResizableCol; } } } @@ -769,10 +822,10 @@ namespace svt { namespace table m_nRowCount = m_pModel->getRowCount(); m_nColumnCount = m_pModel->getColumnCount(); - if(m_aAccColumnWidthsPixel.empty()) - { + if ( m_aAccColumnWidthsPixel.empty() ) impl_ni_updateColumnWidths(); - } + OSL_ENSURE( m_aAccColumnWidthsPixel.size() == m_nColumnCount, "TableControl_Impl::impl_ni_updateScrollbars: inconsistency!" ); + const long nAllColumnsWidth = m_aAccColumnWidthsPixel.empty() ? 0 : m_aAccColumnWidthsPixel[ m_nColumnCount - 1 ]; // do we need a vertical scrollbar? bool bFirstRoundVScrollNeed = false; @@ -786,7 +839,7 @@ namespace svt { namespace table } // do we need a horizontal scrollbar? if ( lcl_determineScrollbarNeed( - m_pModel->getHorizontalScrollbarVisibility(aDataCellPlayground.GetWidth(), m_aAccColumnWidthsPixel[m_nColumnCount-1]), + m_pModel->getHorizontalScrollbarVisibility(aDataCellPlayground.GetWidth(), nAllColumnsWidth), lcl_getColumnsVisibleWithin( aDataCellPlayground, m_nLeftColumn, *this, false ), m_nColumnCount ) ) { @@ -832,7 +885,7 @@ namespace svt { namespace table lcl_updateScrollbar( m_rAntiImpl, m_pHScroll, - m_pModel->getHorizontalScrollbarVisibility(aDataCellPlayground.GetWidth(), m_aAccColumnWidthsPixel[m_nColumnCount-1]), + m_pModel->getHorizontalScrollbarVisibility(aDataCellPlayground.GetWidth(), nAllColumnsWidth), lcl_getColumnsVisibleWithin( aDataCellPlayground, m_nLeftColumn, *this, false ), // visible units m_nLeftColumn, // current position @@ -918,8 +971,7 @@ namespace svt { namespace table m_bResizingGrid = true; } } - if(m_nColumnCount != 0) - impl_ni_updateScrollbars(); + impl_ni_updateScrollbars(); } } @@ -931,7 +983,7 @@ namespace svt { namespace table if ( !getModel() ) return; PTableRenderer pRenderer = getModel()->getRenderer(); - DBG_ASSERT( !!pRenderer, "TableDataWindow::Paint: invalid renderer!" ); + DBG_ASSERT( !!pRenderer, "TableDataWindow::doPaintContent: invalid renderer!" ); if ( !pRenderer ) return; diff --git a/svtools/source/table/tablecontrol_impl.hxx b/svtools/source/table/tablecontrol_impl.hxx index 053766d92841..b456cf248bed 100644..100755 --- a/svtools/source/table/tablecontrol_impl.hxx +++ b/svtools/source/table/tablecontrol_impl.hxx @@ -27,18 +27,13 @@ #ifndef SVTOOLS_TABLECONTROL_IMPL_HXX #define SVTOOLS_TABLECONTROL_IMPL_HXX -#ifndef SVTOOLS_INC_TABLE_TABLEMODEL_HXX #include <svtools/table/tablemodel.hxx> -#endif - -#ifndef SVTOOLS_INC_TABLE_ABSTRACTTABLECONTROL_HXX #include <svtools/table/abstracttablecontrol.hxx> -#endif - #include <svtools/table/tablemodel.hxx> -#include <vector> + #include <vcl/seleng.hxx> +#include <vector> class ScrollBar; class ScrollBarBox; @@ -57,7 +52,8 @@ namespace svt { namespace table //==================================================================== //= TableControl_Impl //==================================================================== - class TableControl_Impl : public IAbstractTableControl + class TableControl_Impl :public IAbstractTableControl + ,public ITableModelListener { friend class TableGeometry; friend class TableRowGeometry; @@ -78,7 +74,7 @@ namespace svt { namespace table */ ArrayOfLong m_aAccColumnWidthsPixel; - ArrayOfLong m_aVisibleColumnWidthsPixel; + ArrayOfLong m_aVisibleColumnWidthsPixel; /// the height of a single row in the table, measured in pixels long m_nRowHeightPixel; /// the height of the column header row in the table, measured in pixels @@ -109,18 +105,18 @@ namespace svt { namespace table /// the horizontal scrollbar, if any ScrollBar* m_pHScroll; ScrollBarBox* m_pScrollCorner; - //selection engine - for determining selection range, e.g. single, multiple - SelectionEngine* m_pSelEngine; - //vector which contains the selected rows - std::vector<RowPos> m_nRowSelected; - //part of selection engine - TableFunctionSet* m_pTableFunctionSet; - //part of selection engine - RowPos m_nAnchor; - bool m_bResizing; - ColPos m_nResizingColumn; - bool m_bResizingGrid; - rtl::OUString m_aTooltipText; + //selection engine - for determining selection range, e.g. single, multiple + SelectionEngine* m_pSelEngine; + //vector which contains the selected rows + std::vector<RowPos> m_nRowSelected; + //part of selection engine + TableFunctionSet* m_pTableFunctionSet; + //part of selection engine + RowPos m_nAnchor; + bool m_bResizing; + ColPos m_nResizingColumn; + bool m_bResizingGrid; + rtl::OUString m_aTooltipText; #if DBG_UTIL #define INV_SCROLL_POSITION 1 @@ -185,44 +181,53 @@ namespace svt { namespace table <TRUE/> if it's okay that the given cooordinate is only partially visible */ void ensureVisible( ColPos _nColumn, RowPos _nRow, bool _bAcceptPartialVisibility ); - /** returns the row, which contains the input point*/ - virtual RowPos getCurrentRow (const Point& rPoint); - - void setCursorAtCurrentCell(const Point& rPoint); - /** checks whether the vector with the selected rows contains the current row*/ - BOOL isRowSelected(const ::std::vector<RowPos>& selectedRows, RowPos current); - - bool isRowSelected(RowPos current); - /** returns the position of the current row in the selection vector */ - int getRowSelectedNumber(const ::std::vector<RowPos>& selectedRows, RowPos current); - /** _rCellRect contains the region, which should be invalidate after some action e.g. selecting row*/ - void invalidateSelectedRegion(RowPos _nPrevRow, RowPos _nCurRow, Rectangle& _rCellRect ); - /** to be called when a new row is added to the control*/ - void invalidateRow(RowPos _nRowPos, Rectangle& _rCellRect ); - /** returns the vector, which contains the selected rows*/ - std::vector<RowPos>& getSelectedRows(); - /** updates the vector, which contains the selected rows after removing the row nRowPos*/ - void removeSelectedRow(RowPos _nRowPos); - void invalidateRows(); - void clearSelection(); - // IAbstractTableControl - virtual void hideCursor(); - virtual void showCursor(); - virtual bool dispatchAction( TableControlAction _eAction ); - virtual SelectionEngine* getSelEngine(); - virtual bool isTooltipActive(); - virtual rtl::OUString& setTooltip(const Point& rPoint ); - virtual void resizeColumn(const Point& rPoint); - virtual bool startResizeColumn(const Point& rPoint); - virtual bool endResizeColumn(const Point& rPoint); - - TableDataWindow* getDataWindow(); - ScrollBar* getHorzScrollbar(); - ScrollBar* getVertScrollbar(); - - ::rtl::OUString convertToString(const ::com::sun::star::uno::Any& _value); - Rectangle calcHeaderRect(bool bColHeader); - Rectangle calcTableRect(); + /** returns the row, which contains the input point*/ + virtual RowPos getCurrentRow (const Point& rPoint); + + void setCursorAtCurrentCell(const Point& rPoint); + /** checks whether the vector with the selected rows contains the current row*/ + BOOL isRowSelected(const ::std::vector<RowPos>& selectedRows, RowPos current); + + bool isRowSelected(RowPos current); + /** returns the position of the current row in the selection vector */ + int getRowSelectedNumber(const ::std::vector<RowPos>& selectedRows, RowPos current); + /** _rCellRect contains the region, which should be invalidate after some action e.g. selecting row*/ + void invalidateSelectedRegion(RowPos _nPrevRow, RowPos _nCurRow, Rectangle& _rCellRect ); + /** to be called when a new row is added to the control*/ + void invalidateRow(RowPos _nRowPos, Rectangle& _rCellRect ); + /** returns the vector, which contains the selected rows*/ + std::vector<RowPos>& getSelectedRows(); + /** updates the vector, which contains the selected rows after removing the row nRowPos*/ + void removeSelectedRow(RowPos _nRowPos); + void invalidateRows(); + void clearSelection(); + // IAbstractTableControl + virtual void hideCursor(); + virtual void showCursor(); + virtual bool dispatchAction( TableControlAction _eAction ); + virtual SelectionEngine* getSelEngine(); + virtual bool isTooltipActive(); + virtual rtl::OUString& setTooltip(const Point& rPoint ); + virtual void resizeColumn(const Point& rPoint); + virtual bool startResizeColumn(const Point& rPoint); + virtual bool endResizeColumn(const Point& rPoint); + + TableDataWindow* getDataWindow(); + ScrollBar* getHorzScrollbar(); + ScrollBar* getVertScrollbar(); + + ::rtl::OUString convertToString(const ::com::sun::star::uno::Any& _value); + Rectangle calcHeaderRect(bool bColHeader); + Rectangle calcTableRect(); + + // ITableModelListener + virtual void rowsInserted( RowPos first, RowPos last ); + virtual void rowsRemoved( RowPos first, RowPos last ); + virtual void columnsInserted( ColPos first, ColPos last ); + virtual void columnsRemoved( ColPos first, ColPos last ); + virtual void columnMoved( ColPos oldIndex, ColPos newIndex ); + virtual void cellsUpdated( ColPos firstCol, ColPos lastCol, RowPos firstRow, RowPos lastRow ); + private: /** toggles the cursor visibility diff --git a/svtools/source/uno/svtxgridcontrol.cxx b/svtools/source/uno/svtxgridcontrol.cxx index 765a37e90495..050e938d2487 100644 --- a/svtools/source/uno/svtxgridcontrol.cxx +++ b/svtools/source/uno/svtxgridcontrol.cxx @@ -81,6 +81,18 @@ SVTXGridControl::~SVTXGridControl() } // --------------------------------------------------------------------------------------------------------------------- +void SVTXGridControl::SetWindow( Window* pWindow ) +{ + TableControl* pTable = dynamic_cast< TableControl* >( pWindow ); + ENSURE_OR_THROW( ( pTable != NULL ) || ( pWindow == NULL ), "SVTXGridControl::SetWindow: illegal window!" ); + + SVTXGridControl_Base::SetWindow( pWindow ); + + if ( pTable ) + pTable->SetModel( PTableModel( m_pTableModel ) ); +} + +// --------------------------------------------------------------------------------------------------------------------- sal_Int32 SAL_CALL SVTXGridControl::getItemIndexAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException) { ::vos::OGuard aGuard( GetMutex() ); @@ -269,7 +281,7 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An for ( ::svt::table::ColPos col = 0; col < rawRowData.getLength(); ++col ) { UnoControlTableColumn* tableColumn = new UnoControlTableColumn(); - m_pTableModel->getColumnModel().push_back((PColumnModel)tableColumn); + m_pTableModel->appendColumn( PColumnModel( tableColumn ) ); } m_xColumnModel->setDefaultColumns(rawRowData.getLength()); } @@ -302,36 +314,14 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An } case BASEPROPERTY_GRID_COLUMNMODEL: { + // remove all old columns + m_pTableModel->removeAllColumns(); + + // obtain new col model m_xColumnModel = Reference< XGridColumnModel >( aValue, UNO_QUERY_THROW ); - if(m_xColumnModel->getColumnCount() != 0) - { - Sequence<Reference< XGridColumn > > columns = m_xColumnModel->getColumns(); - std::vector<Reference< XGridColumn > > aNewColumns( - comphelper::sequenceToContainer<std::vector<Reference< XGridColumn > > >(columns)); - sal_Int32 fontHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight()+3 ), MAP_APPFONT ).Height(); - if(m_xColumnModel->getColumnHeaderHeight() == 0) - { - m_pTableModel->setColumnHeaderHeight(fontHeight); - m_xColumnModel->setColumnHeaderHeight(fontHeight); - } - else - m_pTableModel->setColumnHeaderHeight(m_xColumnModel->getColumnHeaderHeight()); - for ( ::svt::table::ColPos col = 0; col < m_xColumnModel->getColumnCount(); ++col ) - { - UnoControlTableColumn* tableColumn = new UnoControlTableColumn(aNewColumns[col]); - Reference< XGridColumn > xGridColumn = m_xColumnModel->getColumn(col); - m_pTableModel->getColumnModel().push_back((PColumnModel)tableColumn); - tableColumn->setHorizontalAlign(xGridColumn->getHorizontalAlign()); - tableColumn->setWidth(xGridColumn->getColumnWidth()); - if(xGridColumn->getPreferredWidth() != 0) - tableColumn->setPreferredWidth(xGridColumn->getPreferredWidth()); - if(xGridColumn->getMaxWidth() != 0) - tableColumn->setMaxWidth(xGridColumn->getMaxWidth()); - if(xGridColumn->getMinWidth() != 0) - tableColumn->setMinWidth(xGridColumn->getMinWidth()); - tableColumn->setResizable(xGridColumn->getResizeable()); - } - } + + // remove new columns + impl_updateColumnsFromModel_nothrow(); break; } @@ -400,16 +390,6 @@ void SVTXGridControl::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) ); VCLXWindow::ImplGetPropertyIds( rIds, true ); } -void SAL_CALL SVTXGridControl::setVisible( sal_Bool bVisible ) throw(::com::sun::star::uno::RuntimeException) -{ - ::vos::OGuard aGuard( GetMutex() ); - TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); - ENSURE_OR_RETURN_VOID( pTable != NULL, "SVTXGridControl::setVisible: no control (anymore)!" ); - - pTable->SetModel( PTableModel( m_pTableModel ) ); - // TODO: what's this SetModel call good for? Looks like a hack to me, to work around some other bug. - pTable->Show( bVisible ); -} void SAL_CALL SVTXGridControl::rowAdded(const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException) { @@ -425,7 +405,7 @@ void SAL_CALL SVTXGridControl::rowAdded(const ::com::sun::star::awt::grid::GridD for ( ::svt::table::ColPos col = 0; col < rawRowData.getLength(); ++col ) { UnoControlTableColumn* tableColumn = new UnoControlTableColumn(); - m_pTableModel->getColumnModel().push_back((PColumnModel)tableColumn); + m_pTableModel->appendColumn( PColumnModel( tableColumn ) ); m_xColumnModel->getColumn(col)->addColumnListener(listener); } @@ -516,45 +496,59 @@ void SAL_CALL SVTXGridControl::columnChanged(const ::com::sun::star::awt::grid: if(Event.valueName == rtl::OUString::createFromAscii("ColumnResize")) { - bool resizable = m_pTableModel->getColumnModel()[Event.index]->isResizable(); + bool resizable = m_pTableModel->getColumnModel( Event.index )->isResizable(); Event.newValue>>=resizable; - m_pTableModel->getColumnModel()[Event.index]->setResizable(resizable); + m_pTableModel->getColumnModel( Event.index )->setResizable(resizable); } else if(Event.valueName == rtl::OUString::createFromAscii("ColWidth")) { - sal_Int32 colWidth = m_pTableModel->getColumnModel()[Event.index]->getWidth(); + sal_Int32 colWidth = m_pTableModel->getColumnModel( Event.index )->getWidth(); Event.newValue>>=colWidth; - m_pTableModel->getColumnModel()[Event.index]->setWidth(colWidth); + m_pTableModel->getColumnModel( Event.index )->setWidth(colWidth); } else if(Event.valueName == rtl::OUString::createFromAscii("MaxWidth")) { - sal_Int32 maxWidth = m_pTableModel->getColumnModel()[Event.index]->getMaxWidth(); + sal_Int32 maxWidth = m_pTableModel->getColumnModel( Event.index )->getMaxWidth(); Event.newValue>>=maxWidth; - m_pTableModel->getColumnModel()[Event.index]->setMaxWidth(maxWidth); + m_pTableModel->getColumnModel( Event.index )->setMaxWidth(maxWidth); } else if(Event.valueName == rtl::OUString::createFromAscii("MinWidth")) { - sal_Int32 minWidth = m_pTableModel->getColumnModel()[Event.index]->getMinWidth(); + sal_Int32 minWidth = m_pTableModel->getColumnModel( Event.index )->getMinWidth(); Event.newValue>>=minWidth; - m_pTableModel->getColumnModel()[Event.index]->setMinWidth(minWidth); + m_pTableModel->getColumnModel( Event.index )->setMinWidth(minWidth); } else if(Event.valueName == rtl::OUString::createFromAscii("PrefWidth")) { - sal_Int32 prefWidth = m_pTableModel->getColumnModel()[Event.index]->getPreferredWidth(); + sal_Int32 prefWidth = m_pTableModel->getColumnModel( Event.index )->getPreferredWidth(); Event.newValue>>=prefWidth; - m_pTableModel->getColumnModel()[Event.index]->setPreferredWidth(prefWidth); + m_pTableModel->getColumnModel( Event.index )->setPreferredWidth(prefWidth); } else if(Event.valueName == rtl::OUString::createFromAscii("HAlign")) { - ::com::sun::star::style::HorizontalAlignment hAlign = m_pTableModel->getColumnModel()[Event.index]->getHorizontalAlign(); + ::com::sun::star::style::HorizontalAlignment hAlign = m_pTableModel->getColumnModel( Event.index )->getHorizontalAlign(); Event.newValue>>=hAlign; - m_pTableModel->getColumnModel()[Event.index]->setHorizontalAlign(hAlign); + m_pTableModel->getColumnModel( Event.index )->setHorizontalAlign(hAlign); } else if(Event.valueName == rtl::OUString::createFromAscii("UpdateWidth")) { - if(m_pTableModel->getColumnModel()[Event.index]->getPreferredWidth() != 0) - m_xColumnModel->getColumn(Event.index)->updateColumn(rtl::OUString::createFromAscii("PrefWidth"), m_pTableModel->getColumnModel()[Event.index]->getPreferredWidth()); - m_xColumnModel->getColumn(Event.index)->updateColumn(rtl::OUString::createFromAscii("ColWidth"), m_pTableModel->getColumnModel()[Event.index]->getWidth()); + const PColumnModel pTableColumn( m_pTableModel->getColumnModel( Event.index ) ); + ENSURE_OR_RETURN_VOID( !!pTableColumn, "invalid table column!" ); + + Reference< XGridColumn > xColumn; + try + { + xColumn.set( m_xColumnModel->getColumn( Event.index ), UNO_SET_THROW ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + return; + } + + if ( pTableColumn->getPreferredWidth() != 0 ) + xColumn->updateColumn(rtl::OUString::createFromAscii("PrefWidth"), pTableColumn->getPreferredWidth()); + xColumn->updateColumn(rtl::OUString::createFromAscii("ColWidth"), pTableColumn->getWidth() ); } pTable->Invalidate(); } @@ -616,28 +610,29 @@ void SAL_CALL SVTXGridControl::dataChanged(const ::com::sun::star::awt::grid::G //---------------------------------------------------------------------------------------------------------------------- void SAL_CALL SVTXGridControl::elementInserted( const ContainerEvent& i_event ) throw (RuntimeException) { - (void)i_event; + const Reference< XGridColumn > xGridColumn( i_event.Element, UNO_QUERY ); + const PColumnModel tableColumn( new UnoControlTableColumn( xGridColumn ) ); + // will throw if this is not a valid grid column + m_pTableModel->appendColumn( tableColumn ); - // TODO: add as XGridColumnListener - // TODO: update our TableControl + impl_setColumnListening( Reference< XGridColumn >( i_event.Element, UNO_QUERY ), true ); } //---------------------------------------------------------------------------------------------------------------------- void SAL_CALL SVTXGridControl::elementRemoved( const ContainerEvent& i_event ) throw (RuntimeException) { - (void)i_event; + impl_setColumnListening( Reference< XGridColumn >( i_event.Element, UNO_QUERY ), false ); - // TODO: remove as XGridColumnListener - // TODO: update our TableControl + // TODO: remove the respective column from our table model } //---------------------------------------------------------------------------------------------------------------------- void SAL_CALL SVTXGridControl::elementReplaced( const ContainerEvent& i_event ) throw (RuntimeException) { - (void)i_event; + impl_setColumnListening( Reference< XGridColumn >( i_event.ReplacedElement, UNO_QUERY ), false ); + impl_setColumnListening( Reference< XGridColumn >( i_event.Element, UNO_QUERY ), true ); - // TODO: add/remove as XGridColumnListener - // TODO: update our TableControl + // TODO: replace the respective column in our table model } @@ -946,3 +941,60 @@ void SVTXGridControl::ImplCallItemListeners() m_aSelectionListeners.selectionChanged( aEvent ); } } + +void SVTXGridControl::impl_updateColumnsFromModel_nothrow() +{ + ENSURE_OR_RETURN_VOID( m_xColumnModel.is(), "no model!" ); + TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); + ENSURE_OR_RETURN_VOID( pTable != NULL, "no table!" ); + + try + { + if ( m_xColumnModel->getColumnCount() != 0 ) + { + if ( m_xColumnModel->getColumnHeaderHeight() == 0 ) + { + sal_Int32 fontHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight() + 3 ), MAP_APPFONT ).Height(); + m_pTableModel->setColumnHeaderHeight( fontHeight ); + } + else + m_pTableModel->setColumnHeaderHeight( m_xColumnModel->getColumnHeaderHeight() ); + + const Sequence< Reference< XGridColumn > > columns = m_xColumnModel->getColumns(); + for ( const Reference< XGridColumn >* colRef = columns.getConstArray(); + colRef != columns.getConstArray() + columns.getLength(); + ++colRef + ) + { + ENSURE_OR_CONTINUE( colRef->is(), "illegal column!" ); + + impl_setColumnListening( *colRef, true ); + + UnoControlTableColumn* tableColumn = new UnoControlTableColumn( *colRef ); + m_pTableModel->appendColumn( PColumnModel( tableColumn ) ); + + tableColumn->setHorizontalAlign( (*colRef)->getHorizontalAlign() ); + tableColumn->setWidth( (*colRef)->getColumnWidth() ); + tableColumn->setResizable( (*colRef)->getResizeable() ); + tableColumn->setPreferredWidth( (*colRef)->getPreferredWidth() ); + tableColumn->setMaxWidth( (*colRef)->getMaxWidth() ); + tableColumn->setMinWidth( (*colRef)->getMinWidth() ); + } + } + + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + +void SVTXGridControl::impl_setColumnListening( const Reference< XGridColumn >& i_column, bool const i_start ) +{ + ENSURE_OR_RETURN_VOID( i_column.is(), "SVTXGridControl::impl_setColumnListening: illegal column!" ); + + if ( i_start ) + i_column->addColumnListener( this ); + else + i_column->removeColumnListener( this ); +} diff --git a/svtools/source/uno/svtxgridcontrol.hxx b/svtools/source/uno/svtxgridcontrol.hxx index 3197b4b8e23b..ef4dc7225bf5 100644 --- a/svtools/source/uno/svtxgridcontrol.hxx +++ b/svtools/source/uno/svtxgridcontrol.hxx @@ -113,11 +113,18 @@ public: void SAL_CALL setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException); ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException); static void ImplGetPropertyIds( std::list< sal_uInt16 > &aIds ); - void SAL_CALL setVisible(sal_Bool bVisible) throw(::com::sun::star::uno::RuntimeException); // ::com::sun::star::lang::XComponent void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException); - // XContainertListener +protected: + // VCLXWindow + virtual void SetWindow( Window* pWindow ); + +private: + void impl_removeAllColumns_nothrow(); + void impl_updateColumnsFromModel_nothrow(); + + void impl_setColumnListening( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn >& i_column, bool const i_start ); }; #endif // _SVT_GRIDCONTROL_HXX_ diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx index d239ee3c740d..e8ebd029884c 100644 --- a/svtools/source/uno/unocontroltablemodel.cxx +++ b/svtools/source/uno/unocontroltablemodel.cxx @@ -38,6 +38,7 @@ #include <toolkit/helper/property.hxx> #include <comphelper/processfactory.hxx> #include <com/sun/star/awt/grid/XGridColumn.hpp> +#include <tools/diagnose_ex.h> using ::rtl::OUString; using namespace ::svt::table; @@ -45,18 +46,31 @@ using namespace ::com::sun::star::uno; //-------------------------------------------------------------------- - UnoControlTableColumn::UnoControlTableColumn(Reference<XGridColumn> m_xGridColumn) + UnoControlTableColumn::UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ) :m_nID( 0 ) ,m_sName() ,m_bIsResizable( true ) ,m_nWidth( 4 ) ,m_nMinWidth( 0 ) ,m_nMaxWidth( 0 ) - ,m_nPrefWidth ( 0 ) - ,m_xHorizontalAlign(com::sun::star::style::HorizontalAlignment(0)) + ,m_nPrefWidth ( 0 ) + ,m_eHorizontalAlign( com::sun::star::style::HorizontalAlignment_LEFT ) { - m_sName = m_xGridColumn->getTitle(); + ENSURE_OR_THROW( i_gridColumn.is(), "illegal column" ); + m_sName = i_gridColumn->getTitle(); + + // don't do this here. The attribute getters at the XGridColumn implementation do some notifications, + // which is absolutely weird. Sadly, this also means that we can't call the getters while we're + // being constructed, and not yet inserted into the column model. +// m_eHorizontalAlign = i_gridColumn->getHorizontalAlign(); +// m_nWidth = i_gridColumn->getColumnWidth(); +// m_bIsResizable = i_gridColumn->getResizeable(); +// +// m_nPrefWidth = i_gridColumn->getPreferredWidth(); +// m_nMaxWidth = i_gridColumn->getMaxWidth(); +// m_nMinWidth = i_gridColumn->getMinWidth(); } + //-------------------------------------------------------------------- UnoControlTableColumn::UnoControlTableColumn() :m_nID( 0 ) @@ -65,8 +79,8 @@ using namespace ::com::sun::star::uno; ,m_nWidth( 4 ) ,m_nMinWidth( 0 ) ,m_nMaxWidth( 0 ) - ,m_nPrefWidth ( 0 ) - ,m_xHorizontalAlign(com::sun::star::style::HorizontalAlignment(0)) + ,m_nPrefWidth ( 0 ) + ,m_eHorizontalAlign(com::sun::star::style::HorizontalAlignment(0)) { } @@ -155,60 +169,62 @@ using namespace ::com::sun::star::uno; //-------------------------------------------------------------------- ::com::sun::star::style::HorizontalAlignment UnoControlTableColumn::getHorizontalAlign() { - return m_xHorizontalAlign; + return m_eHorizontalAlign; } //-------------------------------------------------------------------- void UnoControlTableColumn::setHorizontalAlign( com::sun::star::style::HorizontalAlignment _align ) { - m_xHorizontalAlign = _align; + m_eHorizontalAlign = _align; } //==================================================================== //= DefaultTableModel_Impl //==================================================================== + typedef ::std::vector< PTableModelListener > ModellListeners; struct UnoControlTableModel_Impl { - ::std::vector< PColumnModel > aColumns; - TableSize nRowCount; - bool bHasColumnHeaders; - bool bHasRowHeaders; - bool bVScroll; - bool bHScroll; - PTableRenderer pRenderer; - PTableInputHandler pInputHandler; - TableMetrics nRowHeight; - TableMetrics nColumnHeaderHeight; - TableMetrics nRowHeaderWidth; - std::vector<rtl::OUString> aRowHeadersTitle; - std::vector<std::vector< Any > > aCellContent; - ::com::sun::star::util::Color m_xLineColor; - ::com::sun::star::util::Color m_xHeaderColor; - ::com::sun::star::util::Color m_xTextColor; - ::com::sun::star::util::Color m_xRowColor1; - ::com::sun::star::util::Color m_xRowColor2; - ::com::sun::star::style::VerticalAlignment m_xVerticalAlign; + ::std::vector< PColumnModel > aColumns; + TableSize nRowCount; + bool bHasColumnHeaders; + bool bHasRowHeaders; + bool bVScroll; + bool bHScroll; + PTableRenderer pRenderer; + PTableInputHandler pInputHandler; + TableMetrics nRowHeight; + TableMetrics nColumnHeaderHeight; + TableMetrics nRowHeaderWidth; + ::std::vector<rtl::OUString > aRowHeadersTitle; + ::std::vector<std::vector< Any > > aCellContent; + ::com::sun::star::util::Color m_nLineColor; + ::com::sun::star::util::Color m_nHeaderColor; + ::com::sun::star::util::Color m_nTextColor; + ::com::sun::star::util::Color m_nRowColor1; + ::com::sun::star::util::Color m_nRowColor2; + ::com::sun::star::style::VerticalAlignment m_eVerticalAlign; + ModellListeners m_aListeners; UnoControlTableModel_Impl() - :aColumns ( ) - ,nRowCount ( 0 ) - ,bHasColumnHeaders ( false ) - ,bHasRowHeaders ( false ) - ,bVScroll ( false ) - ,bHScroll ( false ) + :aColumns ( ) + ,nRowCount ( 0 ) + ,bHasColumnHeaders ( true ) + ,bHasRowHeaders ( true ) + ,bVScroll ( false ) + ,bHScroll ( false ) ,pRenderer ( ) ,pInputHandler ( ) - ,nRowHeight ( 0 ) - ,nColumnHeaderHeight( 0 ) + ,nRowHeight ( 10 ) + ,nColumnHeaderHeight( 10 ) ,nRowHeaderWidth ( 10 ) - ,aRowHeadersTitle ( ) - ,aCellContent ( ) - ,m_xLineColor ( 0xFFFFFF ) - ,m_xHeaderColor ( 0xFFFFFF ) - ,m_xTextColor ( 0 )//black as default - ,m_xRowColor1 ( 0xFFFFFF ) - ,m_xRowColor2 ( 0xFFFFFF ) - ,m_xVerticalAlign (com::sun::star::style::VerticalAlignment(0)) + ,aRowHeadersTitle ( ) + ,aCellContent ( ) + ,m_nLineColor ( 0xFFFFFF ) + ,m_nHeaderColor ( 0xFFFFFF ) + ,m_nTextColor ( 0 )//black as default + ,m_nRowColor1 ( 0xFFFFFF ) + ,m_nRowColor2 ( 0xFFFFFF ) + ,m_eVerticalAlign ( com::sun::star::style::VerticalAlignment_TOP ) { } }; @@ -220,8 +236,8 @@ using namespace ::com::sun::star::uno; UnoControlTableModel::UnoControlTableModel() :m_pImpl( new UnoControlTableModel_Impl ) { - m_pImpl->bHasColumnHeaders = false; - m_pImpl->bHasRowHeaders = false; + m_pImpl->bHasColumnHeaders = true; + m_pImpl->bHasRowHeaders = true; m_pImpl->pRenderer.reset( new GridTableRenderer( *this ) ); m_pImpl->pInputHandler.reset( new DefaultInputHandler ); } @@ -285,41 +301,50 @@ using namespace ::com::sun::star::uno; } //-------------------------------------------------------------------- - void UnoControlTableModel::addTableModelListener( const PTableModelListener& listener ) - { - (void) listener; - // TODO - DBG_ERROR( "DefaultTableModel::addTableModelListener: not yet implemented!" ); - } - - //-------------------------------------------------------------------- - void UnoControlTableModel::removeTableModelListener( const PTableModelListener& listener ) - { - (void)listener; - // TODO - DBG_ERROR( "DefaultTableModel::removeTableModelListener: not yet implemented!" ); - } - - //-------------------------------------------------------------------- PColumnModel UnoControlTableModel::getColumnModel( ColPos column ) { - DBG_ASSERT( ( column >= 0 ) && ( column < getColumnCount() ), - "DefaultTableModel::getColumnModel: invalid index!" ); + ENSURE_OR_RETURN( ( column >= 0 ) && ( column < getColumnCount() ), + "DefaultTableModel::getColumnModel: invalid index!", PColumnModel() ); return m_pImpl->aColumns[ column ]; } //-------------------------------------------------------------------- - std::vector<PColumnModel>& UnoControlTableModel::getColumnModel() + void UnoControlTableModel::appendColumn( const PColumnModel& i_column ) { - return m_pImpl->aColumns; + ENSURE_OR_RETURN_VOID( !!i_column, "illegal column" ); + + const ColPos nInsertPosition = m_pImpl->aColumns.size(); + m_pImpl->aColumns.push_back( i_column ); + + // notify listeners + ModellListeners aListeners( m_pImpl->m_aListeners ); + for ( ModellListeners::const_iterator loop = aListeners.begin(); + loop != aListeners.end(); + ++loop + ) + { + (*loop)->columnsInserted( nInsertPosition, nInsertPosition ); + } } + //-------------------------------------------------------------------- - PColumnModel UnoControlTableModel::getColumnModelByID( ColumnID id ) + void UnoControlTableModel::removeAllColumns() { - (void)id; - // TODO - DBG_ERROR( "DefaultTableModel::getColumnModelByID: not yet implemented!" ); - return PColumnModel(); + if ( m_pImpl->aColumns.empty() ) + return; + + const ColPos nLastIndex = m_pImpl->aColumns.size() - 1; + m_pImpl->aColumns.clear(); + + // notify listeners + ModellListeners aListeners( m_pImpl->m_aListeners ); + for ( ModellListeners::const_iterator loop = aListeners.begin(); + loop != aListeners.end(); + ++loop + ) + { + (*loop)->columnsRemoved( 0, nLastIndex ); + } } //-------------------------------------------------------------------- @@ -403,6 +428,31 @@ using namespace ::com::sun::star::uno; else return ScrollbarShowAlways; } + + //-------------------------------------------------------------------- + void UnoControlTableModel::addTableModelListener( const PTableModelListener& i_listener ) + { + ENSURE_OR_RETURN_VOID( !!i_listener, "illegal NULL listener" ); + m_pImpl->m_aListeners.push_back( i_listener ); + } + + //-------------------------------------------------------------------- + void UnoControlTableModel::removeTableModelListener( const PTableModelListener& i_listener ) + { + for ( ModellListeners::iterator lookup = m_pImpl->m_aListeners.begin(); + lookup != m_pImpl->m_aListeners.end(); + ++lookup + ) + { + if ( *lookup == i_listener ) + { + m_pImpl->m_aListeners.erase( lookup ); + return; + } + } + OSL_ENSURE( false, "UnoControlTableModel::removeTableModelListener: listener is not registered - sure you're doing the right thing here?" ); + } + //-------------------------------------------------------------------- void UnoControlTableModel::setVerticalScrollbarVisibility(bool _bVScroll) const { @@ -447,67 +497,67 @@ using namespace ::com::sun::star::uno; //-------------------------------------------------------------------- ::com::sun::star::util::Color UnoControlTableModel::getLineColor() { - return m_pImpl->m_xLineColor; + return m_pImpl->m_nLineColor; } //-------------------------------------------------------------------- void UnoControlTableModel::setLineColor( ::com::sun::star::util::Color _rColor ) { - m_pImpl->m_xLineColor = _rColor; + m_pImpl->m_nLineColor = _rColor; } //-------------------------------------------------------------------- ::com::sun::star::util::Color UnoControlTableModel::getHeaderBackgroundColor() { - return m_pImpl->m_xHeaderColor; + return m_pImpl->m_nHeaderColor; } //-------------------------------------------------------------------- void UnoControlTableModel::setHeaderBackgroundColor( ::com::sun::star::util::Color _rColor ) { - m_pImpl->m_xHeaderColor = _rColor; + m_pImpl->m_nHeaderColor = _rColor; } //-------------------------------------------------------------------- ::com::sun::star::util::Color UnoControlTableModel::getTextColor() { - return m_pImpl->m_xTextColor; + return m_pImpl->m_nTextColor; } //-------------------------------------------------------------------- void UnoControlTableModel::setTextColor( ::com::sun::star::util::Color _rColor ) { - m_pImpl->m_xTextColor = _rColor; + m_pImpl->m_nTextColor = _rColor; } //-------------------------------------------------------------------- ::com::sun::star::util::Color UnoControlTableModel::getOddRowBackgroundColor() { - return m_pImpl->m_xRowColor1; + return m_pImpl->m_nRowColor1; } //-------------------------------------------------------------------- void UnoControlTableModel::setOddRowBackgroundColor( ::com::sun::star::util::Color _rColor ) { - m_pImpl->m_xRowColor1 = _rColor; + m_pImpl->m_nRowColor1 = _rColor; } //-------------------------------------------------------------------- ::com::sun::star::util::Color UnoControlTableModel::getEvenRowBackgroundColor() { - return m_pImpl->m_xRowColor2; + return m_pImpl->m_nRowColor2; } //-------------------------------------------------------------------- void UnoControlTableModel::setEvenRowBackgroundColor( ::com::sun::star::util::Color _rColor ) { - m_pImpl->m_xRowColor2 = _rColor; + m_pImpl->m_nRowColor2 = _rColor; } //-------------------------------------------------------------------- ::com::sun::star::style::VerticalAlignment UnoControlTableModel::getVerticalAlign() { - return m_pImpl->m_xVerticalAlign; + return m_pImpl->m_eVerticalAlign; } //-------------------------------------------------------------------- void UnoControlTableModel::setVerticalAlign( com::sun::star::style::VerticalAlignment _xAlign ) { - m_pImpl->m_xVerticalAlign = _xAlign; + m_pImpl->m_eVerticalAlign = _xAlign; } diff --git a/svtools/source/uno/unocontroltablemodel.hxx b/svtools/source/uno/unocontroltablemodel.hxx index c00642448f79..18f20043d1be 100644 --- a/svtools/source/uno/unocontroltablemodel.hxx +++ b/svtools/source/uno/unocontroltablemodel.hxx @@ -53,18 +53,18 @@ using namespace ::com::sun::star::awt::grid; class UnoControlTableColumn : public IColumnModel { private: - ColumnID m_nID; - String m_sName; - bool m_bIsResizable; - TableMetrics m_nWidth; - TableMetrics m_nMinWidth; - TableMetrics m_nMaxWidth; - TableMetrics m_nPrefWidth; - ::com::sun::star::style::HorizontalAlignment m_xHorizontalAlign; + ColumnID m_nID; + String m_sName; + bool m_bIsResizable; + TableMetrics m_nWidth; + TableMetrics m_nMinWidth; + TableMetrics m_nMaxWidth; + TableMetrics m_nPrefWidth; + ::com::sun::star::style::HorizontalAlignment m_eHorizontalAlign; public: - UnoControlTableColumn(Reference<XGridColumn>); - UnoControlTableColumn(); + UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ); + UnoControlTableColumn(); // IColumnModel overridables virtual ColumnID getID() const; @@ -79,10 +79,10 @@ class UnoControlTableColumn : public IColumnModel virtual void setMinWidth( TableMetrics _nMinWidth ); virtual TableMetrics getMaxWidth() const; virtual void setMaxWidth( TableMetrics _nMaxWidth ); - virtual TableMetrics getPreferredWidth() const; + virtual TableMetrics getPreferredWidth() const; virtual void setPreferredWidth( TableMetrics _nPrefWidth ); - virtual ::com::sun::star::style::HorizontalAlignment getHorizontalAlign(); - virtual void setHorizontalAlign(::com::sun::star::style::HorizontalAlignment _xAlign); + virtual ::com::sun::star::style::HorizontalAlignment getHorizontalAlign(); + virtual void setHorizontalAlign(::com::sun::star::style::HorizontalAlignment _xAlign); }; struct UnoControlTableModel_Impl; @@ -122,52 +122,55 @@ class UnoControlTableModel : public ITableModel public: // ITableModel overridables - virtual TableSize getColumnCount() const; - virtual TableSize getRowCount() const; - virtual void setColumnCount(TableSize _nColCount); - virtual void setRowCount(TableSize _nRowCount); - virtual bool hasColumnHeaders() const; - virtual bool hasRowHeaders() const; - virtual void setRowHeaders(bool _bRowHeaders); - virtual void setColumnHeaders(bool _bColumnHeaders); - virtual bool isCellEditable( ColPos col, RowPos row ) const; - virtual void addTableModelListener( const PTableModelListener& listener ); - virtual void removeTableModelListener( const PTableModelListener& listener ); - virtual PColumnModel getColumnModel( ColPos column ); - virtual std::vector<PColumnModel>& getColumnModel(); - virtual PColumnModel getColumnModelByID( ColumnID id ); - virtual PTableRenderer getRenderer() const; + virtual TableSize getColumnCount() const; + virtual TableSize getRowCount() const; + virtual bool hasColumnHeaders() const; + virtual bool hasRowHeaders() const; + virtual bool isCellEditable( ColPos col, RowPos row ) const; + virtual PColumnModel getColumnModel( ColPos column ); + virtual PTableRenderer getRenderer() const; virtual PTableInputHandler getInputHandler() const; - virtual TableMetrics getRowHeight() const; - virtual TableMetrics getColumnHeaderHeight() const; - virtual TableMetrics getRowHeaderWidth() const; - virtual ScrollbarVisibility getVerticalScrollbarVisibility(int overAllHeight, int actHeight) const; + virtual TableMetrics getRowHeight() const; + virtual TableMetrics getColumnHeaderHeight() const; + virtual TableMetrics getRowHeaderWidth() const; + virtual ScrollbarVisibility getVerticalScrollbarVisibility(int overAllHeight,int actHeight) const; virtual ScrollbarVisibility getHorizontalScrollbarVisibility(int overAllWidth, int actWidth) const; - virtual void setVerticalScrollbarVisibility(bool _bVScroll) const; - virtual void setHorizontalScrollbarVisibility(bool _bHScroll) const; - virtual void setCellContent(const std::vector<std::vector< Any > >& cellContent); - virtual std::vector<std::vector< Any > >& getCellContent(); - virtual void setRowHeaderName(const std::vector<rtl::OUString>& cellColumnContent); - virtual std::vector<rtl::OUString>& getRowHeaderName(); - virtual ::com::sun::star::util::Color getLineColor(); - virtual void setLineColor(::com::sun::star::util::Color _rColor); - virtual ::com::sun::star::util::Color getHeaderBackgroundColor(); - virtual void setHeaderBackgroundColor(::com::sun::star::util::Color _rColor); - virtual ::com::sun::star::util::Color getTextColor(); - virtual void setTextColor(::com::sun::star::util::Color _rColor); - virtual ::com::sun::star::util::Color getOddRowBackgroundColor(); - virtual void setOddRowBackgroundColor(::com::sun::star::util::Color _rColor); - virtual ::com::sun::star::util::Color getEvenRowBackgroundColor(); - virtual void setEvenRowBackgroundColor(::com::sun::star::util::Color _rColor); - virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign(); - virtual void setVerticalAlign(::com::sun::star::style::VerticalAlignment _rAlign); - virtual bool hasVerticalScrollbar(); - virtual bool hasHorizontalScrollbar(); + virtual void addTableModelListener( const PTableModelListener& i_listener ); + virtual void removeTableModelListener( const PTableModelListener& i_listener ); + virtual bool hasVerticalScrollbar(); + virtual bool hasHorizontalScrollbar(); + virtual std::vector< std::vector< ::com::sun::star::uno::Any > >& getCellContent(); + virtual std::vector<rtl::OUString>& getRowHeaderName(); + virtual ::com::sun::star::util::Color getLineColor(); + virtual ::com::sun::star::util::Color getHeaderBackgroundColor(); + virtual ::com::sun::star::util::Color getTextColor(); + virtual ::com::sun::star::util::Color getOddRowBackgroundColor(); + virtual ::com::sun::star::util::Color getEvenRowBackgroundColor(); + virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign(); + + + // other operations + void setRowCount(TableSize _nRowCount); + void setRowHeaderName(const std::vector<rtl::OUString>& cellColumnContent); + void setVerticalScrollbarVisibility(bool _bVScroll) const; + void setHorizontalScrollbarVisibility(bool _bHScroll) const; + void setCellContent(const std::vector<std::vector< Any > >& cellContent); + void setColumnCount(TableSize _nColCount); + void setRowHeaders(bool _bRowHeaders); + void setColumnHeaders(bool _bColumnHeaders); + void setLineColor(::com::sun::star::util::Color _rColor); + void setHeaderBackgroundColor(::com::sun::star::util::Color _rColor); + void setTextColor(::com::sun::star::util::Color _rColor); + void setOddRowBackgroundColor(::com::sun::star::util::Color _rColor); + void setEvenRowBackgroundColor(::com::sun::star::util::Color _rColor); + void setVerticalAlign(::com::sun::star::style::VerticalAlignment _rAlign); + void appendColumn( const PColumnModel& i_column ); + void removeAllColumns(); }; inline void UnoControlTableModel::SetColumnWidth( ColPos _nColumn, TableMetrics _nWidth100thMM ) { - getColumnModel( _nColumn )->setWidth( _nWidth100thMM ); + getColumnModel( _nColumn )->setWidth( _nWidth100thMM ); } inline TableMetrics UnoControlTableModel::GetColumnWidth( ColPos _nColumn ) diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx index a48f75966bde..2a5b5683efad 100644 --- a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx @@ -36,6 +36,7 @@ #include <comphelper/sequence.hxx> #include <toolkit/helper/servicenames.hxx> +#include <rtl/ustrbuf.hxx> #include <tools/diagnose_ex.h> //...................................................................................................................... @@ -156,6 +157,11 @@ namespace toolkit for ( sal_Int32 i=0; i<rowElements; ++i ) { const Reference< XGridColumn > xColumn( m_aContext.createComponent( "com.sun.star.awt.grid.GridColumn" ), UNO_QUERY_THROW ); + ::rtl::OUStringBuffer colTitle; + colTitle.appendAscii( "Column " ); + colTitle.append( i ); + xColumn->setTitle( colTitle.makeStringAndClear() ); + xColumn->setPreferredWidth( 80 /* APPFONT */ ); ContainerEvent aEvent; aEvent.Source = *this; diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx index 57b5086e2272..cc16d1f2c355 100644 --- a/toolkit/source/controls/grid/gridcontrol.cxx +++ b/toolkit/source/controls/grid/gridcontrol.cxx @@ -127,9 +127,9 @@ Any UnoGridModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const case BASEPROPERTY_GRID_SELECTIONMODE: return uno::makeAny( SelectionType(1) ); case BASEPROPERTY_GRID_SHOWROWHEADER: - return uno::makeAny( (sal_Bool)sal_False ); + return uno::makeAny( (sal_Bool)sal_True ); case BASEPROPERTY_GRID_SHOWCOLUMNHEADER: - return uno::makeAny( (sal_Bool)sal_False ); + return uno::makeAny( (sal_Bool)sal_True ); case BASEPROPERTY_GRID_DATAMODEL: return uno::makeAny( Reference<XGridDataModel> ()); case BASEPROPERTY_GRID_COLUMNMODEL: |