summaryrefslogtreecommitdiff
path: root/src/gui/fpg_basegrid.pas
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-05-24 17:04:51 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-05-24 17:04:51 +0200
commit6978d236f5ad85a8af5c8fab72e935ffa7e40b2d (patch)
tree8139cdbed0db36c9ba045c727b155dfbc4f957ea /src/gui/fpg_basegrid.pas
parentfa365b092aad93114cc4b807e44b53cd90be8338 (diff)
downloadfpGUI-6978d236f5ad85a8af5c8fab72e935ffa7e40b2d.tar.xz
grids: 90% of smoothscrolling support is implemented.
It now needs lots of testing though!
Diffstat (limited to 'src/gui/fpg_basegrid.pas')
-rw-r--r--src/gui/fpg_basegrid.pas149
1 files changed, 117 insertions, 32 deletions
diff --git a/src/gui/fpg_basegrid.pas b/src/gui/fpg_basegrid.pas
index 26e16b64..eae2a576 100644
--- a/src/gui/fpg_basegrid.pas
+++ b/src/gui/fpg_basegrid.pas
@@ -43,7 +43,7 @@ type
TfpgDrawCellEvent = procedure(Sender: TObject; const ARow, ACol: Integer; const ARect: TfpgRect; const AFlags: TfpgGridDrawState; var ADefaultDrawing: boolean) of object;
// widget options
- TfpgGridOption = (go_HideFocusRect, go_AlternativeColor);
+ TfpgGridOption = (go_HideFocusRect, go_AlternativeColor, go_SmoothScroll);
TfpgGridOptions = set of TfpgGridOption;
// Column 2 is special just for testing purposes. Descendant classes will
@@ -66,6 +66,7 @@ type
FPrevRow: Integer;
FFirstRow: Integer;
FFirstCol: Integer;
+ FXOffset: integer; // used for go_SmoothScroll
FMargin: integer;
FFont: TfpgFont;
FHeaderFont: TfpgFont;
@@ -152,7 +153,7 @@ type
property ColumnTextColor[ACol: Integer]: TfpgColor read GetColumnTextColor write SetColumnTextColor;
property VisibleRows: Integer read VisibleLines;
property TopRow: Integer read FFirstRow write SetFirstRow;
- property Options: TfpgGridOptions read FOptions write FOptions default [];
+ property Options: TfpgGridOptions read FOptions write FOptions default [go_SmoothScroll];
property OnDrawCell: TfpgDrawCellEvent read FOnDrawCell write FOnDrawCell;
property OnFocusChange: TfpgFocusChangeNotify read FOnFocusChange write FOnFocusChange;
property OnRowChange: TfpgRowChangeNotify read FOnRowChange write FOnRowChange;
@@ -174,12 +175,25 @@ implementation
procedure TfpgBaseGrid.HScrollBarMove(Sender: TObject; position: integer);
begin
- if FFirstCol <> position then
+ if go_SmoothScroll in FOptions then
begin
- if Position < 0 then
- Position := 0;
- FFirstCol := position;
- RePaint;
+ if FXOffset <> position then
+ begin
+ if Position < 0 then
+ Position := 0;
+ FXOffset := position;
+ Repaint;
+ end;
+ end
+ else
+ begin
+ if FFirstCol <> position then
+ begin
+ if Position < 0 then
+ Position := 0;
+ FFirstCol := position;
+ RePaint;
+ end;
end;
end;
@@ -377,8 +391,11 @@ begin
Canvas.SetTextColor(clText1);
s := GetHeaderText(ACol);
x := (ARect.Left + (ARect.Width div 2)) - (FHeaderFont.TextWidth(s) div 2);
- if x < 1 then
- x := 1;
+ if not (go_SmoothScroll in FOptions) then
+ begin
+ if x < 1 then
+ x := 1;
+ end;
fpgStyle.DrawString(Canvas, x, ARect.Top+1, s, Enabled);
end;
@@ -516,6 +533,7 @@ var
vw: integer;
cw: integer;
i: integer;
+ x: integer;
begin
VHeight := Height - 4;
HWidth := Width - 4;
@@ -532,6 +550,7 @@ begin
begin
FHScrollBar.Visible := False;
FFirstCol := 0;
+ FXOffset := 0;
end;
// This needs improving while resizing
@@ -561,8 +580,16 @@ begin
Dec(VHeight, FHScrollBar.Height);
FHScrollBar.Min := 0;
FHScrollBar.SliderSize := 0.2;
- FHScrollBar.Max := ColumnCount-1;
- FHScrollBar.Position := FFirstCol;
+ if go_SmoothScroll in FOptions then
+ begin
+ FHScrollBar.Max := cw - vw;
+ FHScrollBar.Position := FXOffset;
+ end
+ else
+ begin
+ FHScrollBar.Max := ColumnCount-1;
+ FHScrollBar.Position := FFirstCol;
+ end;
FHScrollBar.RepaintSlider;
end;
@@ -591,6 +618,8 @@ var
row: Integer;
clipr: TfpgRect; // clip rectangle
drawstate: TfpgGridDrawState;
+ cLeft: integer;
+ c: integer;
begin
Canvas.BeginDraw;
// inherited HandlePaint;
@@ -607,12 +636,25 @@ begin
clipr.SetRect(FMargin, FMargin, VisibleWidth, VisibleHeight);
r := clipr;
+ cLeft := FMargin; // column starting point
+ if go_SmoothScroll in FOptions then
+ begin
+ if FHScrollBar.Visible then
+ Dec(cLeft, FHScrollBar.Position);
+ c := 0;
+ end
+ else
+ begin
+ c := FFirstCol;
+ end;
+
if (ColumnCount > 0) and ShowHeader then
begin
// Drawing horizontal headers
+ r.Left := cLeft;
r.Height := FHeaderHeight;
Canvas.SetFont(FHeaderFont);
- for col := FFirstCol to ColumnCount-1 do
+ for col := c to ColumnCount-1 do
begin
r.Width := ColumnWidth[col];
Canvas.SetClipRect(clipr);
@@ -633,8 +675,8 @@ begin
for row := FFirstRow to RowCount-1 do
begin
- r.Left := FMargin;
- for col := FFirstCol to ColumnCount-1 do
+ r.Left := cLeft;
+ for col := c to ColumnCount-1 do
begin
drawstate := [];
r.Width := ColumnWidth[col];
@@ -930,6 +972,8 @@ var
cw: integer;
n: integer;
colresize: boolean;
+ cLeft: integer;
+ c: integer;
begin
inherited HandleMouseMove(x, y, btnstate, shiftstate);
@@ -954,15 +998,27 @@ begin
colresize := False;
hh := FHeaderHeight;
+ cLeft := FMargin; // column starting point
+ if go_SmoothScroll in FOptions then
+ begin
+ if FHScrollBar.Visible then
+ Dec(cLeft, FHScrollBar.Position);
+ c := 0;
+ end
+ else
+ begin
+ c := FFirstCol;
+ end;
+
if (y <= FMargin + hh) then // we are over the Header row
begin
cw := 0;
- for n := FFirstCol to ColumnCount-1 do
+ for n := c to ColumnCount-1 do
begin
inc(cw, ColumnWidth[n]);
// Resizing is enabled 4 pixel either way of the cell border
- if ((x >= (FMargin+cw - 4)) and (x <= (FMargin+cw+4))) or
- (cw > (FMargin + VisibleWidth)) and (x >= FMargin + VisibleWidth-4) then
+ if ((x >= (cLeft+cw-4)) and (x <= (cLeft+cw+4))) {or
+ (cw > (cLeft + VisibleWidth)) and (x >= (cLeft + VisibleWidth-4))} then
begin
colresize := True;
Break;
@@ -1001,6 +1057,8 @@ var
nw: integer;
prow: Integer;
pcol: Integer;
+ c: integer;
+ cLeft: integer;
begin
inherited HandleLMouseDown(x, y, shiftstate);
@@ -1019,27 +1077,40 @@ begin
if ShowHeader and (y <= FMargin+hh) then // inside Header row
begin
{$IFDEF DEBUG} Writeln('header click...'); {$ENDIF}
+
+ cLeft := FMargin; // column starting point
+ if go_SmoothScroll in FOptions then
+ begin
+ if FHScrollBar.Visible then
+ Dec(cLeft, FHScrollBar.Position);
+ c := 0;
+ end
+ else
+ begin
+ c := FFirstCol;
+ end;
+
cw := 0;
- for n := FFirstCol to ColumnCount-1 do
+ for n := c to ColumnCount-1 do
begin
inc(cw, ColumnWidth[n]);
- if (x >= (FMargin+cw - 4)) and (x <= (FMargin+cw + 4)) then
+ if (x >= (cLeft+cw-4)) and (x <= (cLeft+cw+4)) then
begin
{$IFDEF DEBUG} Writeln('column resize...'); {$ENDIF}
FColResizing := True;
FResizedCol := n;
FDragPos := x;
Break;
- end
- else if (cw > FMargin+VisibleWidth) and (x >= FMargin+VisibleWidth-4) then
- begin
- FColResizing := True;
- FResizedCol := n;
- FDragPos := x;
- nw := ColumnWidth[FResizedCol] - (cw+FMargin-x);
- if nw > 0 then
- SetColumnWidth(FResizedCol, nw );
- Break;
+ //end
+ //else if (cw > cLeft+VisibleWidth) and (x >= cLeft+VisibleWidth-4) then
+ //begin
+ // FColResizing := True;
+ // FResizedCol := n;
+ // FDragPos := x;
+ // nw := ColumnWidth[FResizedCol] - (cw+cLeft-x);
+ // if nw > 0 then
+ // SetColumnWidth(FResizedCol, nw );
+ // Break;
end; { if/else }
if cw > VisibleWidth then
@@ -1159,7 +1230,7 @@ begin
FRowSelect := False;
FScrollBarStyle := ssAutoBoth;
FUpdateCount := 0;
- FOptions := [];
+ FOptions := [go_SmoothScroll];
FFont := fpgGetFont('#Grid');
FHeaderFont := fpgGetFont('#GridHeader');
@@ -1235,6 +1306,8 @@ var
hh: integer;
cw: integer;
n: Integer;
+ cLeft: integer;
+ c: integer;
begin
if ShowHeader then
hh := FHeaderHeight+1
@@ -1245,11 +1318,23 @@ begin
if ARow > RowCount-1 then
ARow := RowCount-1;
+ cLeft := FMargin; // column starting point
+ if go_SmoothScroll in FOptions then
+ begin
+ if FHScrollBar.Visible then
+ Dec(cLeft, FHScrollBar.Position);
+ c := 0;
+ end
+ else
+ begin
+ c := FFirstCol;
+ end;
+
cw := 0;
- for n := FFirstCol to ColumnCount-1 do
+ for n := c to ColumnCount-1 do
begin
inc(cw, ColumnWidth[n]);
- if FMargin+cw >= x then
+ if cLeft+cw >= x then
begin
ACol := n;
Break;