Anonymous avatar Anonymous committed 918815f

gridcontrol_03:bug fix for #i111107#, added update methods to xgriddatamodel

Comments (0)

Files changed (13)

offapi/com/sun/star/awt/grid/UnoControlGridModel.idl

 	/** specifies the help URL of the control.
 	 */
 	[property] string HelpURL;
-		
+
 }; 
  
 //============================================================================= 

offapi/com/sun/star/awt/grid/XGridDataModel.idl

 	*/
 	void removeAll();
 
+	/**Updates the content of a given cell.
+		@param row
+			the row index
+		@param column
+			the column index
+		@param value
+			the new value of the cell.
+	*/
+	void updateCell([in] long row, [in] long column, [in] any value );
+		
+	/**Updates the content of a given row.
+		@param row
+			the row index
+		@param columns
+			column indexes of the cells, which should be updated
+		@param value
+			the new values of the cells.
+	*/
+	void updateRow([in] long row, [in] sequence< long > columns, [in] sequence< any > values);
+
 	//------------------------------------------------------------------------- 
 
 	/** Adds a listener for the <type>GridDataEvent</type> posted after the grid changes.

svtools/inc/svtools/table/abstracttablecontrol.hxx

 	/** returns selection engine*/
 	virtual SelectionEngine* getSelEngine() = 0;
 	virtual void setCursorAtCurrentCell(const Point& rPoint) = 0;
-	virtual void setTooltip(const Point& rPoint ) = 0;
+	virtual rtl::OUString& setTooltip(const Point& rPoint ) = 0;
 	virtual RowPos getCurrentRow(const Point& rPoint ) = 0;
 	virtual void resizeColumn(const Point& rPoint ) = 0;
 	virtual bool startResizeColumn(const Point& rPoint) = 0;

svtools/inc/svtools/table/tabledatawindow.hxx

 		virtual	void		SetPointer( const Pointer& rPointer );
 		virtual	void		CaptureMouse();
 		virtual	void		ReleaseMouse();
-
+		virtual long		Notify(NotifyEvent& rNEvt);
 	};
 //........................................................................
 } } // namespace svt::table

svtools/source/table/gridtablerenderer.cxx

 		else if(m_pImpl->rModel.getColumnModel(_nCol)->getHorizontalAlign() == 2)
 			nHorFlag = TEXT_DRAW_RIGHT;
 		Rectangle aRect(_rArea);
-		aRect.Left()+=4; aRect.Right()-=4;
-		aRect.Top()+=2; aRect.Bottom()-=2;
+		aRect.Left()+=4; aRect.Right()-=4; 
+		aRect.Bottom()-=2;
 			_rDevice.DrawText( aRect, sHeaderText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP);
 		_rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
         _rDevice.Pop();
 		else if(m_pImpl->rModel.getColumnModel(0)->getHorizontalAlign() == 2)
 			nHorFlag = TEXT_DRAW_RIGHT;
 		Rectangle aRect(_rArea);
-		aRect.Left()+=4; aRect.Right()-=4;
-		aRect.Top()+=2; aRect.Bottom()-=2;
+		aRect.Left()+=4; aRect.Right()-=4; 
+		aRect.Bottom()-=2;
         _rDevice.DrawText( aRect, _rText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP);
         // TODO: active? selected?
         (void)_bActive;
 	    else if(m_pImpl->rModel.getColumnModel(_nColumn)->getHorizontalAlign() == 2)
 		    nHorFlag = TEXT_DRAW_RIGHT;
 	    Rectangle textRect(_rArea);
-	    textRect.Left()+=4; textRect.Right()-=4;
-	    textRect.Top()+=2; textRect.Bottom()-=2;
+	    textRect.Left()+=4; textRect.Right()-=4; 
+		textRect.Bottom()-=2;
             _rDevice.DrawText( textRect, _rText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP);
         }
         _rDevice.Pop();

svtools/source/table/tablecontrol.cxx

         ,m_pImpl( new TableControl_Impl( *this ) )
 		,m_bSelectionChanged(false)
     {
-		m_pImpl->getDataWindow()->SetMouseButtonDownHdl( LINK( this, TableControl, ImplMouseButtonDownHdl ) );
-    	m_pImpl->getDataWindow()->SetMouseButtonUpHdl( LINK( this, TableControl, ImplMouseButtonUpHdl ) );
-		m_pImpl->getDataWindow()->SetSelectHdl( LINK( this, TableControl, ImplSelectHdl ) );
+		TableDataWindow* aTableData = m_pImpl->getDataWindow();
+		aTableData->SetMouseButtonDownHdl( LINK( this, TableControl, ImplMouseButtonDownHdl ) );
+    	aTableData->SetMouseButtonUpHdl( LINK( this, TableControl, ImplMouseButtonUpHdl ) );
+		aTableData->SetSelectHdl( LINK( this, TableControl, ImplSelectHdl ) );
 		m_pAccessTable.reset(new ::svt::table::AccessibleTableControl_Impl());
     }
 

svtools/source/table/tablecontrol_impl.cxx

 #include <vcl/seleng.hxx>
 #include <rtl/ref.hxx>
 #include <toolkit/awt/vclxwindow.hxx>
-#include <vcl/help.hxx>
 #include <vcl/image.hxx>
 #include <com/sun/star/graphic/XGraphic.hpp>
 
         DELETEZ( m_pVScroll );
         DELETEZ( m_pHScroll );
         DELETEZ( m_pScrollCorner );
-	DELETEZ( m_pTableFunctionSet );
-	DELETEZ( m_pSelEngine );
+		DELETEZ( m_pTableFunctionSet );
+		DELETEZ( m_pSelEngine );
         DELETEZ( m_pDataWindow );
     }
 
 		
         m_aColumnWidthsPixel.reserve( colCount );
         m_aAccColumnWidthsPixel.reserve( colCount );
+		std::vector<sal_Int32> aPrePixelWidths(0);
         long accumulatedPixelWidth = 0;
+		int lastResizableCol = -1;
 		double gridWidth = m_rAntiImpl.GetOutputSizePixel().Width();
 		if(m_pModel->hasRowHeaders())
 		{
 				colWidth = pColumn->getWidth();
 			long pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width();
 			if(bResizable && colPrefWidth == 0)
+			{
 				colWithoutFixedWidthsSum+=pixelWidth;
+				lastResizableCol = col;
+			}
 			colWidthsSum+=pixelWidth;
+			aPrePixelWidths.push_back(pixelWidth);
 		}
-		gridWidth = gridWidth - colWidthsSum + colWithoutFixedWidthsSum;
+		double gridWidthWithoutFixed = gridWidth - colWidthsSum + colWithoutFixedWidthsSum;
 		double scalingFactor = 1.0;
 		if(m_bResizingGrid)
 		{
-			if(gridWidth > (minColWithoutFixedSum+colWidthsSum - colWithoutFixedWidthsSum))
-				scalingFactor = gridWidth/colWithoutFixedWidthsSum;
+			if(gridWidthWithoutFixed > (minColWithoutFixedSum+colWidthsSum - colWithoutFixedWidthsSum))
+				scalingFactor = gridWidthWithoutFixed/colWithoutFixedWidthsSum;
 		}
 		else
 		{
-			if(colWidthsSum < gridWidth)
+			if(colWidthsSum < gridWidthWithoutFixed)
 			{
 				if(colWithoutFixedWidthsSum>0)
-					scalingFactor = gridWidth/colWithoutFixedWidthsSum;
+					scalingFactor = gridWidthWithoutFixed/colWithoutFixedWidthsSum;
 			}
 		} 
 		long pixelWidth = 0;
 			PColumnModel pColumn = m_pModel->getColumnModel( i );
 			DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" );
 			if ( !pColumn )
-				continue;
-			TableMetrics colWidth = pColumn->getWidth();	
+				continue;	
 			if(pColumn->isResizable() && pColumn->getPreferredWidth() == 0)
 			{
-				colWidth*=scalingFactor;
-				//colWidth+=1;
-				pColumn->setWidth(colWidth);				
+				aPrePixelWidths[i]*=scalingFactor;
+				TableMetrics logicColWidth = m_rAntiImpl.PixelToLogic( Size( aPrePixelWidths[i], 0 ), MAP_APPFONT ).Width();
+				pColumn->setWidth(logicColWidth);
 			}
-			pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width();
-			m_aColumnWidthsPixel.push_back( pixelWidth );
-			m_aAccColumnWidthsPixel.push_back( accumulatedPixelWidth += pixelWidth );
+			m_aColumnWidthsPixel.push_back( aPrePixelWidths[i] );
+			m_aAccColumnWidthsPixel.push_back( accumulatedPixelWidth += aPrePixelWidths[i] );
+		}
+		if(gridWidth > m_aAccColumnWidthsPixel[colCount-1])
+		{
+			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)
+				{
+					if(lastResizableCol == 0)
+						m_aAccColumnWidthsPixel[0] = m_aColumnWidthsPixel[lastResizableCol];
+					else
+						m_aAccColumnWidthsPixel[lastResizableCol]=m_aAccColumnWidthsPixel[lastResizableCol-1]+m_aColumnWidthsPixel[lastResizableCol];
+					++lastResizableCol;
+				}
+			}
 		}
     }
 
                 )
             {
 				bool isSelectedColumn = false;
-			//	Size siz = m_rAntiImpl.GetSizePixel();
 				::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic;
 				::com::sun::star::uno::Any rCellData = aCellContent[aRowIterator.getRow()][aCell.getColumn()];
 				if(rCellData>>=xGraphic)
     {
 		return m_pDataWindow;
     }
+	//-------------------------------------------------------------------------------
+    ScrollBar* TableControl_Impl::getHorzScrollbar()
+    {
+		return m_pHScroll;
+    }
+	//-------------------------------------------------------------------------------
+    ScrollBar* TableControl_Impl::getVertScrollbar()
+    {
+		return m_pVScroll;
+    }
     //-------------------------------------------------------------------------------
     BOOL TableControl_Impl::isRowSelected(const ::std::vector<RowPos>& selectedRows, RowPos current)
     {
 		return -1;
     }
     //-------------------------------------------------------------------------------
-    void TableControl_Impl::setTooltip(const Point& rPoint )
+	::rtl::OUString& TableControl_Impl::setTooltip(const Point& rPoint )
     {
-	    ::rtl::OUString aTooltipText;
+		::rtl::OUString& aTooltipText(::rtl::OUString::createFromAscii(""));
 	    RowPos current = getCurrentRow(rPoint);
 	    com::sun::star::uno::Sequence< sal_Int32 > cols = m_rAntiImpl.getColumnsForTooltip();
 	    com::sun::star::uno::Sequence< ::rtl::OUString > text = m_rAntiImpl.getTextForTooltip();
-	    if(text.getLength() == 0)
+		if(text.getLength()==0 && cols.getLength()==0)
+		{
+			::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][m_nCurColumn];
+			aTooltipText = convertToString(content);
+		}
+	    else if(text.getLength() == 0)
 	    {
 		    for(int i=0; i<cols.getLength(); i++)
 		    {
 			    }
 		    }
 	    }
-	    Help::ShowBalloon(m_pDataWindow, rPoint, aTooltipText);
+		return aTooltipText;
     }
     //--------------------------------------------------------------------
     void TableControl_Impl::resizeColumn(const Point& rPoint)
 		    headerRowWidth = m_rAntiImpl.LogicToPixel( Size(m_pModel->getRowHeaderWidth(), 0 ), MAP_APPFONT ).Width();
 	    int resizingColumn=m_nCurColumn-m_nLeftColumn;
 	    PColumnModel pColumn = m_pModel->getColumnModel(m_nCurColumn);
-	    sal_Int32 colWidth = pColumn->getWidth();
 	    impl_ni_getAccVisibleColWidths();
-	    int newColWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width();
+		int newColWidth = m_aColumnWidthsPixel[m_nCurColumn];
 	    //subtract 1 from m_aAccColumnWidthPixel because right border should be part of the current cell
 	    if(m_aVisibleColumnWidthsPixel[resizingColumn]-1 == rPoint.X() && pColumn->isResizable())
 		    aNewPointer = Pointer( POINTER_HSPLIT );
 	    int col = m_nLeftColumn;
 	    while(nVisCols)
 	    {
-		    PColumnModel pColumn = m_pModel->getColumnModel(col);
-		    pixelWidth = m_rAntiImpl.LogicToPixel( Size( pColumn->getWidth(), 0 ), MAP_APPFONT ).Width();
-		    m_aVisibleColumnWidthsPixel.push_back(widthsPixel+=pixelWidth);
+		   // PColumnModel pColumn = m_pModel->getColumnModel(col);
+		   // pixelWidth = m_rAntiImpl.LogicToPixel( Size( pColumn->getWidth(), 0 ), MAP_APPFONT ).Width();
+		    m_aVisibleColumnWidthsPixel.push_back(widthsPixel+=m_aColumnWidthsPixel[col]);
 		    col++;
 		    nVisCols--;
 	    }

svtools/source/table/tablecontrol_impl.hxx

         virtual void    showCursor();
         virtual bool    dispatchAction( TableControlAction _eAction );
 	virtual SelectionEngine* getSelEngine();
-	virtual void setTooltip(const Point& rPoint );
+	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);

svtools/source/table/tabledatawindow.cxx

 #include "svtools/table/tablecontrol.hxx"
 #include "svtools/table/tabledatawindow.hxx"
 #include "tablecontrol_impl.hxx"
+#include <vcl/help.hxx>
 
 //........................................................................
 namespace svt { namespace table
 		Point aPoint = rMEvt.GetPosPixel();
 		if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) )
 		{
-			if(m_rTableControl.getCurrentRow(aPoint)>=0 && 
-				(!m_rTableControl.getAntiImpl().getColumnsForTooltip().getLength()==0 || !m_rTableControl.getAntiImpl().getTextForTooltip().getLength()==0))
-			{		
-				m_rTableControl.setTooltip(aPoint);
+			if(m_rTableControl.getCurrentRow(aPoint)>=0 )
+			{	
 				SetPointer(POINTER_ARROW);
+				rtl::OUString& rHelpText = m_rTableControl.setTooltip(aPoint);
+				Help::EnableBalloonHelp();
+				Window::SetHelpText( rHelpText.getStr());
 			}
 			else if(m_rTableControl.getCurrentRow(aPoint) == -1)
 			{	
+				if(Help::IsBalloonHelpEnabled())
+					Help::DisableBalloonHelp();
 				m_rTableControl.resizeColumn(aPoint);
 			}
 			else
+			{
+				if(Help::IsBalloonHelpEnabled())
+					Help::DisableBalloonHelp();
 				Window::MouseMove( rMEvt );
+			}
 		}
     }
     //--------------------------------------------------------------------
     {
 	    Window::ReleaseMouse();
     }
+	// -----------------------------------------------------------------------
+	long TableDataWindow::Notify(NotifyEvent& rNEvt )
+	{
+		long nDone = 0;
+		if ( rNEvt.GetType() == EVENT_COMMAND )
+		{
+			const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
+			if ( rCEvt.GetCommand() == COMMAND_WHEEL )
+			{
+				const CommandWheelData* pData = rCEvt.GetWheelData();
+				if( !pData->GetModifier() && ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) )
+				{
+					nDone = HandleScrollCommand( rCEvt, m_rTableControl.getHorzScrollbar(), m_rTableControl.getVertScrollbar() );
+				}
+			}
+		}
+		return nDone ? nDone : Window::Notify( rNEvt );
+	}
 //........................................................................
 } } // namespace svt::table
 //........................................................................

svtools/source/uno/svtxgridcontrol.cxx

 								}
 								m_xColumnModel->setDefaultColumns(rawRowData.getLength());
 							}
-							if((unsigned int)rawRowData.getLength()!=(unsigned)m_pTableModel->getColumnCount())
-								throw GridInvalidDataException(rtl::OUString::createFromAscii("The column count doesn't match with the length of row data"), m_xDataModel);
+							else
+								if((unsigned int)rawRowData.getLength()!=(unsigned)m_pTableModel->getColumnCount())
+									throw GridInvalidDataException(rtl::OUString::createFromAscii("The column count doesn't match with the length of row data"), m_xDataModel);
 
 							for ( int k = 0; k < rawRowData.getLength(); k++)
 							{
 				}
 				else
 					throw GridInvalidDataException(rtl::OUString::createFromAscii("The data model isn't set!"), m_xDataModel);
-				sal_Int32 fontHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight() ), MAP_APPFONT ).Height();
+				sal_Int32 fontHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight()+3 ), MAP_APPFONT ).Height();
 				if(m_xDataModel->getRowHeight() == 0)
+				{
 					m_pTableModel->setRowHeight(fontHeight);
+					m_xDataModel->setRowHeight(fontHeight);
+				}
 				else
 					m_pTableModel->setRowHeight(m_xDataModel->getRowHeight());
 				m_pTableModel->setRowHeaderWidth(m_xDataModel->getRowHeaderWidth());
 					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() ), MAP_APPFONT ).Height();
+					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);
-						m_pTableModel->getColumnModel()[col]->setHorizontalAlign(m_xColumnModel->getColumn(col)->getHorizontalAlign());
-						m_pTableModel->getColumnModel()[col]->setWidth(m_xColumnModel->getColumn(col)->getColumnWidth());
-						m_pTableModel->getColumnModel()[col]->setResizable(m_xColumnModel->getColumn(col)->getResizeable());
+						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());
 					}
 				}
 			}
 }
 void SAL_CALL  SVTXGridControl::dataChanged(const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
 {
-	(void) Event;
+	TableControl* pTable = (TableControl*)GetWindow();
+	if(Event.valueName == rtl::OUString::createFromAscii("RowHeight"))
+	{
+		sal_Int32 rowHeight = m_pTableModel->getRowHeight();
+		Event.newValue>>=rowHeight;
+		m_pTableModel->setRowHeight(rowHeight);
+		pTable->Invalidate();
+	}
+	else if(Event.valueName == rtl::OUString::createFromAscii("RowHeaderWidth"))
+	{
+		sal_Int32 rowHeaderWidth = m_pTableModel->getRowHeaderWidth();
+		Event.newValue>>=rowHeaderWidth;
+		m_pTableModel->setRowHeaderWidth(rowHeaderWidth);
+		pTable->Invalidate();
+	}
+	else if(Event.valueName == rtl::OUString::createFromAscii("RowHeaders"))
+	{
+		Sequence< rtl::OUString > headers(0);
+		Event.newValue>>=headers;
+		std::vector< rtl::OUString > headerNames( comphelper::sequenceToContainer <std::vector< rtl::OUString > >(headers) );
+		m_pTableModel->setRowHeaderName(headerNames);
+		pTable->Invalidate();
+	}
+	else if(Event.valueName == rtl::OUString::createFromAscii("CellUpdated"))
+	{
+		std::vector< std::vector< Any > >& rowContent = m_pTableModel->getCellContent();
+		sal_Int32 col = -1;
+		Event.oldValue>>=col;
+		rowContent[Event.index][col] = Event.newValue;
+		pTable->InvalidateDataWindow(Event.index, Event.index, false);
+	}
+	else if(Event.valueName == rtl::OUString::createFromAscii("RowUpdated"))
+	{
+		std::vector<std::vector< Any > >& rowContent = m_pTableModel->getCellContent();
+		Sequence< sal_Int32 > cols(0);
+		Sequence< Any > values(0);
+		Event.oldValue>>=cols;
+		Event.newValue>>=values;
+		for(int i = 0; i< cols.getLength(); i++)
+		{
+			if(cols[i]>=0 && cols[i]<m_pTableModel->getColumnCount())
+				rowContent[Event.index][cols[i]]=values[i];
+			else
+				break;
+		}
+		pTable->InvalidateDataWindow(Event.index, Event.index, false);
+	}
 }
 
 void SAL_CALL SVTXGridControl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException)
 void SAL_CALL SVTXGridControl::selectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException)
 {	
 	TableControl* pTable = (TableControl*)GetWindow();
-	std::vector<RowPos>& selectedRows = pTable->GetSelectedRows();
-	if(!selectedRows.empty())
-		selectedRows.clear();
-	sal_Int32 start = rangeOfRows[0];
-	int seqSize = rangeOfRows.getLength();
-	sal_Int32 end = rangeOfRows[seqSize-1];
-	for(int i=0;i<seqSize;i++)
-		selectedRows.push_back(rangeOfRows[i]);
-	pTable->selectionChanged(true);
-	pTable->InvalidateDataWindow(start, end, false);
-	SetSynthesizingVCLEvent( sal_True );
-	pTable->Select();
-	SetSynthesizingVCLEvent( sal_False );
-
+	SelectionMode eSelMode = pTable->getSelEngine()->GetSelectionMode();
+	if(eSelMode != NO_SELECTION)
+	{
+		sal_Int32 start = rangeOfRows[0];
+		int seqSize = rangeOfRows.getLength();
+		sal_Int32 end = rangeOfRows[seqSize-1];
+		if((start >= 0 && start < m_pTableModel->getRowCount()) && (end >= 0 && end < m_pTableModel->getRowCount()))
+		{
+			std::vector<RowPos>& selectedRows = pTable->GetSelectedRows();
+			if(!selectedRows.empty())
+				selectedRows.clear();
+			if(eSelMode == SINGLE_SELECTION)
+			{
+				if(rangeOfRows.getLength() == 1)
+					selectedRows.push_back(start);
+				else 
+					return;
+			}
+			else
+			{
+				for(int i=0;i<seqSize;i++)
+					selectedRows.push_back(rangeOfRows[i]);
+			}
+			pTable->selectionChanged(true);
+			pTable->InvalidateDataWindow(start, end, false);
+			SetSynthesizingVCLEvent( sal_True );
+			pTable->Select();
+			SetSynthesizingVCLEvent( sal_False );
+		}
+	}
 }
 
 void SAL_CALL SVTXGridControl::selectAllRows() throw (::com::sun::star::uno::RuntimeException)
 {
 	TableControl* pTable = (TableControl*)GetWindow();
-	std::vector<RowPos>& selectedRows = pTable->GetSelectedRows();
-	if(!selectedRows.empty())
-		selectedRows.clear();
-	for(int i=0;i<m_pTableModel->getRowCount();i++)
-		selectedRows.push_back(i);
-	pTable->Invalidate();
-	SetSynthesizingVCLEvent( sal_True );
-	pTable->Select();
-	SetSynthesizingVCLEvent( sal_False );
+	SelectionMode eSelMode = pTable->getSelEngine()->GetSelectionMode();
+	if(eSelMode != NO_SELECTION)
+	{
+		std::vector<RowPos>& selectedRows = pTable->GetSelectedRows();
+		if(!selectedRows.empty())
+			selectedRows.clear();
+		for(int i=0;i<m_pTableModel->getRowCount();i++)
+			selectedRows.push_back(i);
+		pTable->Invalidate();
+		SetSynthesizingVCLEvent( sal_True );
+		pTable->Select();
+		SetSynthesizingVCLEvent( sal_False );
+	}
 }
 void SAL_CALL SVTXGridControl::deselectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException)
 {	
 	std::vector<RowPos>::iterator itEnd = selectedRows.end();
 	sal_Int32 start = rangeOfRows[0];
 	sal_Int32 end = rangeOfRows[rangeOfRows.getLength()-1];
-	std::vector<RowPos>::iterator iter = std::find(itStart, itEnd, start);
-	selectedRows.erase(iter, iter+(end-start)+1);
-	pTable->selectionChanged(true);
-	pTable->InvalidateDataWindow(start, end, false);
-	SetSynthesizingVCLEvent( sal_True );
-	pTable->Select();
-	SetSynthesizingVCLEvent( sal_False );
+	if((start >= 0 && start < m_pTableModel->getRowCount()) && (end >= 0 && end < m_pTableModel->getRowCount()))
+	{
+		std::vector<RowPos>::iterator iter = std::find(itStart, itEnd, start);
+		selectedRows.erase(iter, iter+(end-start)+1);
+		pTable->selectionChanged(true);
+		pTable->InvalidateDataWindow(start, end, false);
+		SetSynthesizingVCLEvent( sal_True );
+		pTable->Select();
+		SetSynthesizingVCLEvent( sal_False );
+	}
 }
 
 void SAL_CALL SVTXGridControl::deselectAllRows() throw (::com::sun::star::uno::RuntimeException)
 	if(index<0 || index>=m_pTableModel->getRowCount())
 		return;
 	TableControl* pTable = (TableControl*)GetWindow();
-	std::vector<RowPos>& selectedRows = pTable->GetSelectedRows();
-	if(!isSelectedIndex(index))
-		selectedRows.push_back(index);
-	pTable->selectionChanged(true);
-	pTable->InvalidateDataWindow(index, index, false);
-	SetSynthesizingVCLEvent( sal_True );
-	pTable->Select();
-	SetSynthesizingVCLEvent( sal_False );
+	SelectionMode eSelMode = pTable->getSelEngine()->GetSelectionMode();
+	if(eSelMode != NO_SELECTION)
+	{
+		std::vector<RowPos>& selectedRows = pTable->GetSelectedRows();
+		if(eSelMode == MULTIPLE_SELECTION)
+		{
+			if(!isSelectedIndex(index))
+				selectedRows.push_back(index);
+			else
+				return;
+		}
+		else if(eSelMode == SINGLE_SELECTION)
+		{	
+			if(!selectedRows.empty())
+			{
+				if(!isSelectedIndex(index))
+					deselectRows(getSelection());
+				else
+					return;
+			}
+			selectedRows.push_back(index);
+		}
+		pTable->selectionChanged(true);
+		pTable->InvalidateDataWindow(index, index, false);
+		SetSynthesizingVCLEvent( sal_True );
+		pTable->Select();
+		SetSynthesizingVCLEvent( sal_False );
+	}
 }
 
 void SAL_CALL SVTXGridControl::selectColumn(::sal_Int32 x) throw (::com::sun::star::uno::RuntimeException)

toolkit/source/controls/grid/defaultgriddatamodel.cxx

 
 #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
 {
 
 //---------------------------------------------------------------------
 
-void DefaultGridDataModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ) throw (::com::sun::star::uno::RuntimeException)
+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< Any >() );
+	GridDataEvent aEvent( xSource, name, oldValue, newValue, index, ::rtl::OUString(), Sequence< Any >());
 	broadcast( data_changed, aEvent);
 }
 
 	sal_Int32 oldValue = rowHeight;
 	rowHeight = value;
 
-	broadcast_changed( ROWHEIGHT, Any(oldValue), Any(value) );
+	broadcast_changed( ROWHEIGHT, 0, Any(oldValue), Any(value));
 }
 
 //---------------------------------------------------------------------
 		i++;
 	}
 
-	broadcast_changed( ROWHEADERS, Any(oldValue), Any(comphelper::containerToSequence(rowHeaders)) );
+	broadcast_changed( ROWHEADERS, 0, Any(oldValue), Any(comphelper::containerToSequence(rowHeaders)) );
 }
 
 //---------------------------------------------------------------------
 //---------------------------------------------------------------------
 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
 //---------------------------------------------------------------------
 

toolkit/source/controls/grid/defaultgriddatamodel.hxx

 	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);
 private:
 
 	void broadcast( broadcast_type eType, const GridDataEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
-	void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ) 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);
 

toolkit/source/controls/grid/gridcontrol.hxx

 	// ::com::sun::star::awt::grid::XGridControl 
 
 	virtual ::sal_Int32 SAL_CALL getItemIndexAtPoint(::sal_Int32 x, ::sal_Int32 y) 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);	
-	//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
 	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.