Commits

Mihaela Kedikova  committed 22a9cfc

gridcontrol_03:improvements

  • Participants
  • Parent commits 180c49a

Comments (0)

Files changed (6)

File svtools/inc/svtools/table/tablecontrol.hxx

 	DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* );
 
         TableControl_Impl*  m_pImpl;
-	::com::sun::star::uno::Sequence< sal_Int32 >& m_nCols;
-	::com::sun::star::uno::Sequence< ::rtl::OUString >& m_aText;
+	::com::sun::star::uno::Sequence< sal_Int32 > m_nCols;
+	::com::sun::star::uno::Sequence< ::rtl::OUString > m_aText;
 	Link m_aSelectHdl;
 	bool m_bSelectionChanged;
     public:

File svtools/source/table/tablecontrol.cxx

     TableControl::TableControl( Window* _pParent, WinBits _nStyle )
         :Control( _pParent, _nStyle )
         ,m_pImpl( new TableControl_Impl( *this ) )
-		,m_nCols(*( new ::com::sun::star::uno::Sequence< sal_Int32 >(0) ))
-		,m_aText(*( new ::com::sun::star::uno::Sequence< ::rtl::OUString >(0) ))
 		,m_bSelectionChanged(false)
     {
 		m_pImpl->getDataWindow()->SetSelectHdl( LINK( this, TableControl, ImplSelectHdl ) );
 	::com::sun::star::uno::Any cellContent = ::com::sun::star::uno::Any(::rtl::OUString::createFromAscii(""));
 	std::vector<std::vector< ::com::sun::star::uno::Any > >& aTableContent = GetModel()->getCellContent();
 	if(&aTableContent)
-	{
-		std::vector< ::com::sun::star::uno::Any >& aRowContent = aTableContent[_nRowPos];
-		if(&aRowContent)
-			cellContent = aRowContent[_nColPos];
-	}
+		cellContent = aTableContent[_nRowPos][_nColPos];
 	return cellContent;
 }
 // -----------------------------------------------------------------------------
 ::rtl::OUString TableControl::GetAccessibleCellText( sal_Int32 _nRowPos, sal_Int32 _nColPos)
 {
 	::com::sun::star::uno::Any cellContent = GetCellContent(_nRowPos, _nColPos);
-	return m_pImpl->impl_convertToString(cellContent);
+	return m_pImpl->convertToString(cellContent);
 }
 // -----------------------------------------------------------------------------
 
 Rectangle TableControl::calcHeaderRect(sal_Bool _bIsColumnBar,BOOL _bOnScreen)
 {
 	(void)_bOnScreen;
-	Rectangle aRectTable, aRectTableWithHeaders;
-	m_pImpl->impl_getAllVisibleDataCellArea(aRectTable);
-	m_pImpl->impl_getAllVisibleCellsArea(aRectTableWithHeaders);
-	Size aSizeTable(aRectTable.GetSize());
-	Size aSizeTableWithHeaders(aRectTableWithHeaders.GetSize());
-	if(_bIsColumnBar)
-		return Rectangle(aRectTableWithHeaders.TopLeft(),Size(aSizeTableWithHeaders.Width()-aSizeTable.Width(), aSizeTableWithHeaders.Height()));
-	else
-		return Rectangle(aRectTableWithHeaders.TopLeft(),Size(aSizeTableWithHeaders.Width(), aSizeTableWithHeaders.Height()-aSizeTable.Height()));
+	return m_pImpl->calcHeaderRect(_bIsColumnBar);
 }
 // -----------------------------------------------------------------------------
 Rectangle TableControl::calcTableRect(BOOL _bOnScreen)
 {
 	(void)_bOnScreen;
-	Rectangle aRect;
-	m_pImpl->impl_getAllVisibleDataCellArea(aRect);
-	return aRect;
+	return m_pImpl->calcTableRect();
 }
 //--------------------------------------------------------------------
 ::com::sun::star::uno::Sequence< sal_Int32 >& TableControl::getColumnsForTooltip()

File svtools/source/table/tablecontrol_impl.cxx

 	}
 	virtual std::vector<std::vector< ::com::sun::star::uno::Any > >& getCellContent() 
 	{
-		return *( new std::vector<std::vector< ::com::sun::star::uno::Any > >);
+		return m_aCellContent;
 	}
 	virtual void setRowHeaderName(const std::vector<rtl::OUString>& )
 	{
 	}
 	private:
 		std::vector<rtl::OUString> aRowHeaderNames;
+		std::vector<std::vector< ::com::sun::star::uno::Any > > m_aCellContent;
     };
 
 
 		    }
 		    else
 		    {
-			    ::rtl::OUString sContent = impl_convertToString(rCellData);
+			    ::rtl::OUString sContent = convertToString(rCellData);
 			    pRenderer->PaintCellString( aCell.getColumn(), isSelectedRow || isSelectedColumn, isActiveRow, 
 					    *m_pDataWindow, aCell.getRect(), rStyle, sContent );
 		    }	
 	return m_pDataWindow;
     }
     //-------------------------------------------------------------------------------
-    BOOL TableControl_Impl::isRowSelected(::std::vector<RowPos> selectedRows, RowPos current)
+    BOOL TableControl_Impl::isRowSelected(const ::std::vector<RowPos>& selectedRows, RowPos current)
     {
-	    for(::std::vector<RowPos>::iterator it=selectedRows.begin();
-				it!=selectedRows.end();++it)
-	    {
-		    if(*it == current)
-			    return TRUE;
-	    }
-	    return FALSE;
+		return ::std::find(selectedRows.begin(),selectedRows.end(),current) != selectedRows.end();
     }
     //-------------------------------------------------------------------------------
-    int TableControl_Impl::getRowSelectedNumber(::std::vector<RowPos> selectedRows, RowPos current)
+    int TableControl_Impl::getRowSelectedNumber(const ::std::vector<RowPos>& selectedRows, RowPos current)
     {
-	    int pos = -1;
-	    int i = 0;
-	    for(std::vector<RowPos>::iterator it=selectedRows.begin();it!=selectedRows.end();++it)
-	    {
-		    if(*it == current)
-			    return pos = i;
-		    ++i;
-	    }
-	    return pos;
+		std::vector<RowPos>::const_iterator it = ::std::find(selectedRows.begin(),selectedRows.end(),current);
+		if ( it != selectedRows.end() )
+		{
+			return it - selectedRows.begin();
+		}
+		return -1;
     }
     //-------------------------------------------------------------------------------
     void TableControl_Impl::setTooltip(const Point& rPoint )
 			    if(i==0)
 			    {
 				    ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]];
-				    ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic;
-				    if(content>>=xGraphic)
-					    aTooltipText=::rtl::OUString::createFromAscii("");
-				    else
-					    aTooltipText = impl_convertToString(content);
+					aTooltipText = convertToString(content);
 			    }
 			    else
 			    {
 				    aTooltipText+= ::rtl::OUString::createFromAscii("\n");
 				    ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]];
-				    ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic;
-				    if(content>>=xGraphic)
-					    aTooltipText += ::rtl::OUString::createFromAscii("");
-				    else
-					    aTooltipText += impl_convertToString(content);
+					aTooltipText += convertToString(content);
 			    }
 		    }
 	    }
 			    if(i==0)
 			    {
 				    ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]];
-				    ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic;
-				    if(content>>=xGraphic)
-					    aTooltipText = ::rtl::OUString::createFromAscii("");
-				    else
-					    aTooltipText = text[i] + impl_convertToString(content);
+					aTooltipText = text[i] + convertToString(content);
 			    }
 			    else
 			    {
 				    {
 					    ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]];
 					    ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic;
-					    if(content>>=xGraphic)
-						    aTooltipText +=::rtl::OUString::createFromAscii("");
-					    else
-						    aTooltipText += impl_convertToString(content);
+						aTooltipText += convertToString(content);
 				    }
 			    }
 		    }
 		    m_nLeftColumn--;
     }
     //--------------------------------------------------------------------
-    rtl::OUString TableControl_Impl::impl_convertToString(::com::sun::star::uno::Any value)
+    rtl::OUString TableControl_Impl::convertToString(const ::com::sun::star::uno::Any& value)
     {
 	    sal_Int32 nInt = 0;
 	    sal_Bool bBool = false;
 		    sNewString = sConvertString.valueOf(fDouble);
 	    return sNewString;
     }
+	Rectangle TableControl_Impl::calcHeaderRect(bool bColHeader)
+	{
+		Rectangle aRectTable, aRectTableWithHeaders;
+		impl_getAllVisibleDataCellArea(aRectTable);
+		impl_getAllVisibleCellsArea(aRectTableWithHeaders);
+		Size aSizeTable(aRectTable.GetSize());
+		Size aSizeTableWithHeaders(aRectTableWithHeaders.GetSize());
+		if(bColHeader)
+			return Rectangle(aRectTableWithHeaders.TopLeft(),Size(aSizeTableWithHeaders.Width()-aSizeTable.Width(), aSizeTableWithHeaders.Height()));
+		else
+			return Rectangle(aRectTableWithHeaders.TopLeft(),Size(aSizeTableWithHeaders.Width(), aSizeTableWithHeaders.Height()-aSizeTable.Height()));
+	}
+	Rectangle TableControl_Impl::calcTableRect()
+	{
+		Rectangle aRect;
+		impl_getAllVisibleDataCellArea(aRect);
+		return aRect;
+	}
     //--------------------------------------------------------------------
     IMPL_LINK( TableControl_Impl, OnScroll, ScrollBar*, _pScrollbar )
     {

File svtools/source/table/tablecontrol_impl.hxx

 
 	void setCursorAtCurrentCell(const Point& rPoint);
 	/** checks whether the vector with the selected rows contains the current row*/
-	BOOL    isRowSelected(::std::vector<RowPos> selectedRows, RowPos current);
+	BOOL    isRowSelected(const ::std::vector<RowPos>& selectedRows, RowPos current);
 	/** returns the position of the current row in the selection vector */
-	int	getRowSelectedNumber(::std::vector<RowPos> selectedRows, RowPos current);
+	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*/
 	virtual bool endResizeColumn(const Point& rPoint);
 
 	TableDataWindow* getDataWindow();
-	/** retrieves the area occupied by the totality of (at least partially) visible cells
 
-            The returned area includes row and column headers. Also, it takes into
-            account the the fact that there might be less columns than would normally
-            find room in the control.
-
-            As a result of respecting the partial visibility of rows and columns,
-            the returned area might be larger than the data window's output size.
-        */
-        void        impl_getAllVisibleCellsArea( Rectangle& _rCellArea ) const;
-
-        /** retrieves the area occupied by all (at least partially) visible data cells.
-
-            Effectively, the returned area is the same as returned by ->impl_getAllVisibleCellsArea,
-            minus the row and column header areas.
-        */
-        void        impl_getAllVisibleDataCellArea( Rectangle& _rCellArea ) const;
-
-	::rtl::OUString impl_convertToString(::com::sun::star::uno::Any _value);
+	::rtl::OUString convertToString(const ::com::sun::star::uno::Any& _value);
+	Rectangle calcHeaderRect(bool bColHeader);
+	Rectangle calcTableRect();
     private:
         /** toggles the cursor visibility
 
                 column range were reached.
         */
         TableSize   impl_ni_ScrollColumns( TableSize _nRowDelta );
+			/** retrieves the area occupied by the totality of (at least partially) visible cells
+
+            The returned area includes row and column headers. Also, it takes into
+            account the the fact that there might be less columns than would normally
+            find room in the control.
+
+            As a result of respecting the partial visibility of rows and columns,
+            the returned area might be larger than the data window's output size.
+        */
+        void        impl_getAllVisibleCellsArea( Rectangle& _rCellArea ) const;
+
+        /** retrieves the area occupied by all (at least partially) visible data cells.
+
+            Effectively, the returned area is the same as returned by ->impl_getAllVisibleCellsArea,
+            minus the row and column header areas.
+        */
+        void        impl_getAllVisibleDataCellArea( Rectangle& _rCellArea ) const;
 
 		void impl_ni_getAccVisibleColWidths();
 		void impl_updateLeftColumn();

File svtools/source/uno/svtxgridcontrol.cxx

 				return Any ( m_xDataModel );
 			case BASEPROPERTY_GRID_COLUMNMODEL:
 				return Any ( m_xColumnModel);
-			case BASEPROPERTY_TABSTOP:
 			case BASEPROPERTY_HSCROLL:
 				return Any ( m_bHScroll);
 			case BASEPROPERTY_VSCROLL:
 	TableControl* pTable = (TableControl*)GetWindow();
 	if(Event.index == -1)
 	{
+		if(!isSelectionEmpty())
+			deselectAllRows();
 		if(m_pTableModel->hasRowHeaders())
 			m_pTableModel->getRowHeaderName().clear();
 		m_pTableModel->getCellContent().clear();
 	}
 	else if(Event.index >= 0 && Event.index < m_pTableModel->getRowCount())
 	{
-		pTable->RemoveSelectedRow(Event.index);
-
+		if(isSelectedIndex(Event.index))
+		{
+			Sequence<sal_Int32> selected(1);
+			selected[0]=Event.index;
+			deselectRows(selected);
+		}
 		if(m_pTableModel->hasRowHeaders())
 			m_pTableModel->getRowHeaderName().erase(m_pTableModel->getRowHeaderName().begin()+Event.index);
 		std::vector<std::vector<Any> >::iterator rowPos =m_pTableModel->getCellContent().begin() + Event.index;

File svtools/source/uno/unocontroltablemodel.cxx

 	//====================================================================
     struct UnoControlTableModel_Impl
     {
-        ::std::vector< PColumnModel >&  aColumns;
+        ::std::vector< PColumnModel >  aColumns;
         TableSize                       nRowCount;
         bool                            bHasColumnHeaders;
         bool                            bHasRowHeaders;
         TableMetrics                    nRowHeight;
         TableMetrics                    nColumnHeaderHeight;
         TableMetrics                    nRowHeaderWidth;
-	std::vector<rtl::OUString>&		aRowHeadersTitle;
-	std::vector<std::vector< Any > >&	aCellContent;
+	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::style::VerticalAlignment m_xVerticalAlign;
 
         UnoControlTableModel_Impl()
-            :aColumns		( *(new std::vector< PColumnModel> (0)))
+            :aColumns		( )
 	    ,nRowCount          ( 0         )
             ,bHasColumnHeaders  ( false     )
             ,bHasRowHeaders     ( false     )
             ,nRowHeight         ( 0 )  
             ,nColumnHeaderHeight( 0 )  
             ,nRowHeaderWidth    ( 10 )   
-	    ,aRowHeadersTitle   ( *(new std::vector<rtl::OUString>(0)))
-	    ,aCellContent	( *(new std::vector<std::vector< Any > >(0))	)
+	    ,aRowHeadersTitle   ( )
+	    ,aCellContent	( )
 	    ,m_xLineColor	( 0xFFFFFF )	
 	    ,m_xHeaderColor	( 0xFFFFFF )
 	    ,m_xTextColor	( 0 )//black as default