From 2899709d66c5d72af84a9359d7cfb8402ab56b36 Mon Sep 17 00:00:00 2001 From: graemeg Date: Tue, 1 Apr 2008 09:26:19 +0000 Subject: * Added a MouseToCell function to BaseGrid. --- src/gui/gui_basegrid.pas | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/gui/gui_basegrid.pas b/src/gui/gui_basegrid.pas index 39b9067a..ecccf8ef 100644 --- a/src/gui/gui_basegrid.pas +++ b/src/gui/gui_basegrid.pas @@ -147,6 +147,7 @@ type procedure Update; procedure BeginUpdate; procedure EndUpdate; + procedure MouseToCell(X, Y: Integer; var ACol, ARow: Longword); end; implementation @@ -992,19 +993,7 @@ begin end else begin // Selecting a Cell via mouse - FFocusRow := FFirstRow + Longword((y - FMargin - hh) div FDefaultRowHeight); - if FFocusRow > RowCount then - FFocusRow := RowCount; - cw := 0; - for n := FFirstCol to ColumnCount do - begin - inc(cw, ColumnWidth[n]); - if FMargin+cw >= x then - begin - FFocusCol := n; - Break; - end; - end; + MouseToCell(x, y, FFocusCol, FFocusRow); end; { if/else } if not CanSelectCell(FFocusRow, FFocusCol) then @@ -1151,5 +1140,33 @@ begin end; end; +procedure TfpgBaseGrid.MouseToCell(X, Y: Integer; var ACol, ARow: Longword); +var + hh: integer; + cw: integer; + n: Longword; +begin + if ShowHeader then + hh := FHeaderHeight+1 + else + hh := 0; + + ARow := FFirstRow + Longword((y - FMargin - hh) div FDefaultRowHeight); + if ARow > RowCount then + ARow := RowCount; + + cw := 0; + for n := FFirstCol to ColumnCount do + begin + inc(cw, ColumnWidth[n]); + if FMargin+cw >= x then + begin + ACol := n; + Break; + end; + end; +end; + + end. -- cgit v1.2.3-70-g09d2