summaryrefslogtreecommitdiff
path: root/src/gui/fpg_basegrid.pas
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2014-02-25 22:41:39 +0000
committerGraeme Geldenhuys <graemeg@gmail.com>2014-02-25 22:41:39 +0000
commitb090e8d016b7efde90ef6d320190d3edc0e90701 (patch)
treec69134344995f037fdf267c32a0368d207fcae87 /src/gui/fpg_basegrid.pas
parente6150509b873e83376c5f1adbaebd401334f07fa (diff)
parentbbeff0966370c1ed48f58ab8ebe9eb93ee8b11fd (diff)
downloadfpGUI-b090e8d016b7efde90ef6d320190d3edc0e90701.tar.xz
Merge branch 'gridborderstyle' into develop
Diffstat (limited to 'src/gui/fpg_basegrid.pas')
-rw-r--r--src/gui/fpg_basegrid.pas142
1 files changed, 96 insertions, 46 deletions
diff --git a/src/gui/fpg_basegrid.pas b/src/gui/fpg_basegrid.pas
index 6f262331..146887b9 100644
--- a/src/gui/fpg_basegrid.pas
+++ b/src/gui/fpg_basegrid.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Toolkit
- Copyright (C) 2006 - 2013 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2014 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -73,7 +73,6 @@ type
FFirstRow: Integer;
FFirstCol: Integer;
FXOffset: integer; // used for go_SmoothScroll
- FMargin: integer;
FFont: TfpgFont;
FHeaderFont: TfpgFont;
FRowSelect: boolean;
@@ -91,6 +90,7 @@ type
function GetFontDesc: string;
function GetHeaderFontDesc: string;
function GetTotalColumnWidth: integer;
+ function GetAdjustedBorderSizes: TRect;
procedure HScrollBarMove(Sender: TObject; position: integer);
procedure SetFontDesc(const AValue: string);
procedure SetHeaderFontDesc(const AValue: string);
@@ -179,6 +179,7 @@ type
procedure BeginUpdate;
procedure EndUpdate;
procedure MouseToCell(X, Y: Integer; var ACol, ARow: Integer);
+ function GetClientRect: TfpgRect; override;
function VisibleWidth: integer;
function VisibleHeight: integer;
end;
@@ -231,6 +232,32 @@ begin
Result := Result + ColumnWidth[i];
end;
+// Adjust theme borders based on BorderStyle property
+function TfpgBaseGrid.GetAdjustedBorderSizes: TRect;
+begin
+ Result := fpgStyle.GetControlFrameBorders;
+ case BorderStyle of
+ ebsNone:
+ begin
+ Result.Left := 0;
+ Result.Right := 0;
+ Result.Top := 0;
+ Result.Bottom := 0;
+ end;
+ ebsDefault:
+ begin
+ // do nothing - the theme values are correct
+ end;
+ ebsSingle:
+ begin
+ Result.Left := 1;
+ Result.Right := 1;
+ Result.Top := 1;
+ Result.Bottom := 1;
+ end;
+ end;
+end;
+
procedure TfpgBaseGrid.SetFontDesc(const AValue: string);
begin
FFont.Free;
@@ -533,7 +560,7 @@ begin
hh := 0;
if ShowHeader then
hh := hh + FHeaderHeight+1;
- Result := (Height - (2*FMargin) - hh) div FDefaultRowHeight;
+ Result := (GetClientRect.Height - hh) div FDefaultRowHeight;
end;
function TfpgBaseGrid.VisibleWidth: integer;
@@ -541,10 +568,10 @@ var
sw: integer;
begin
if FVScrollBar.Visible then
- sw := FVScrollBar.Width-1
+ sw := FVScrollBar.Width
else
sw := 0;
- Result := Width - (FMargin*2) - sw;
+ Result := GetClientRect.Width - sw
end;
function TfpgBaseGrid.VisibleHeight: integer;
@@ -552,10 +579,10 @@ var
sw: integer;
begin
if FHScrollBar.Visible then
- sw := FHScrollBar.Height-1
+ sw := FHScrollBar.Height
else
sw := 0;
- Result := Height - (FMargin*2) - sw;
+ Result := GetClientRect.Height - sw;
end;
procedure TfpgBaseGrid.SetFirstRow(const AValue: Integer);
@@ -593,8 +620,10 @@ var
vl: integer;
i: integer;
x: integer;
- Hfits, showH : boolean;
- Vfits, showV : boolean;
+ Hfits, showH: boolean;
+ Vfits, showV: boolean;
+ crect: TfpgRect;
+ borders: TRect;
procedure hideScrollbar (sb : TfpgScrollBar);
begin
@@ -620,8 +649,10 @@ var
hh : integer; // header height
begin
hh := 0;
- if ShowHeader then inc (hh, FHeaderHeight+1);
- if showH then inc (hh, FHScrollBar.Height);
+ if ShowHeader then
+ inc (hh, FHeaderHeight+1);
+ if showH then
+ inc (hh, FHScrollBar.Height);
vl := (VHeight - hh) div FDefaultRowHeight;
Vfits := vl >= RowCount;
end;
@@ -634,10 +665,12 @@ begin
hideScrollbar(FVScrollBar);
exit;
end;
-
+
+ borders := GetAdjustedBorderSizes;
// preliminary width/height calculations
- VHeight := Height - 4;
- HWidth := Width - 4;
+ crect := GetClientRect;
+ VHeight := crect.Height;
+ HWidth := crect.Width;
cw := 0;
for i := 0 to ColumnCount-1 do
cw := cw + ColumnWidth[i];
@@ -702,17 +735,17 @@ begin
if showV then
begin
FVScrollBar.Visible := true;
- FVScrollBar.Min := 0;
+ FVScrollBar.Min := 0;
if RowCount > 0 then
FVScrollBar.SliderSize := VisibleLines / RowCount
else
FVScrollBar.SliderSize := 0;
- FVScrollBar.Max := RowCount-VisibleLines;
- FVScrollBar.Position := FFirstRow;
+ FVScrollBar.Max := RowCount-VisibleLines;
+ FVScrollBar.Position := FFirstRow;
FVScrollBar.RepaintSlider;
- FVScrollBar.Top := 2;
- FVScrollBar.Left := Width - FVScrollBar.Width - 2;
- FVScrollBar.Height := VHeight;
+ FVScrollBar.Top := borders.Top;
+ FVScrollBar.Left := Width - FVScrollBar.Width - borders.Right;
+ FVScrollBar.Height := VHeight;
end
else
begin
@@ -737,17 +770,17 @@ begin
begin
FHScrollBar.Max := ColumnCount-1;
FHScrollBar.Position := FFirstCol;
- FHScrollBar.SliderSize := 1 / ColumnCount;
+ FHScrollBar.SliderSize := 1 / ColumnCount;
FHScrollBar.PageSize := 1;
end;
FHScrollBar.RepaintSlider;
- FHScrollBar.Top := Height -FHScrollBar.Height - 2;
- FHScrollBar.Left := 2;
+ FHScrollBar.Top := Height - FHScrollBar.Height - borders.Bottom;
+ FHScrollBar.Left := borders.Left;
FHScrollBar.Width := HWidth;
end
else
begin
- FHScrollBar.Visible := false;
+ FHScrollBar.Visible := False;
if Hfits then
begin
FFirstCol := 0;
@@ -780,7 +813,6 @@ var
rect: TRect;
begin
Canvas.ClearClipRect;
-
r.SetRect(0, 0, Width, Height);
case BorderStyle of
ebsNone:
@@ -790,26 +822,22 @@ begin
ebsDefault:
begin
fpgStyle.DrawControlFrame(Canvas, r);
- rect := fpgStyle.GetControlFrameBorders;
- InflateRect(r, -rect.Left, -rect.Top); { assuming borders are even on opposite sides }
end;
ebsSingle:
begin
Canvas.SetColor(clShadow2);
Canvas.DrawRectangle(r);
- InflateRect(r, -1, -1);
end;
end;
- Canvas.SetClipRect(r);
+ r := GetClientRect;
+ clipr := r;
+ Canvas.SetClipRect(clipr);
Canvas.SetColor(FBackgroundColor);
Canvas.FillRectangle(r);
- clipr.SetRect(FMargin, FMargin, VisibleWidth, VisibleHeight);
- r := clipr;
-
- cLeft := FMargin; // column starting point
- rTop := FMargin; // row starting point
+ cLeft := r.Left; // column starting point
+ rTop := r.Top; // row starting point
if go_SmoothScroll in FOptions then
begin
@@ -1218,6 +1246,7 @@ var
colresize: boolean;
cLeft: integer;
c: integer;
+ borders: TRect;
begin
inherited HandleMouseMove(x, y, btnstate, shiftstate);
@@ -1241,8 +1270,9 @@ begin
begin
colresize := False;
hh := FHeaderHeight;
+ borders := GetAdjustedBorderSizes;
- cLeft := FMargin; // column starting point
+ cLeft := borders.Left; // column starting point
if go_SmoothScroll in FOptions then
begin
if FHScrollBar.Visible then
@@ -1254,7 +1284,7 @@ begin
c := FFirstCol;
end;
- if (y <= FMargin + hh) then // we are over the Header row
+ if (y <= (borders.Top + hh)) then // we are over the Header row
begin
cw := 0;
for n := c to ColumnCount-1 do
@@ -1286,6 +1316,7 @@ var
c: integer;
n: integer;
cw: integer;
+ borders: TRect;
begin
inherited HandleLMouseUp(x, y, shiftstate);
@@ -1297,12 +1328,13 @@ begin
Exit; //==>
// searching for the appropriate character position
hh := FHeaderHeight;
+ borders := GetAdjustedBorderSizes;
- if (y < FMargin+hh) then // inside Header row
+ if (y < (borders.Top+hh)) then // inside Header row
begin
{$IFDEF DEBUG} Writeln('header click...'); {$ENDIF}
- cLeft := FMargin; // column starting point
+ cLeft := borders.Left; // column starting point
if go_SmoothScroll in FOptions then
begin
if FHScrollBar.Visible then
@@ -1349,6 +1381,7 @@ var
pcol: Integer;
c: integer;
cLeft: integer;
+ borders: TRect;
begin
inherited HandleLMouseDown(x, y, shiftstate);
@@ -1357,6 +1390,7 @@ begin
pcol := FFocusCol;
prow := FFocusRow;
+ borders := GetAdjustedBorderSizes;
// searching for the appropriate character position
if ShowHeader then
@@ -1364,11 +1398,11 @@ begin
else
hh := 0;
- if ShowHeader and (y < FMargin+hh) then // inside Header row
+ if ShowHeader and (y < (borders.Top+hh)) then // inside Header row
begin
{$IFDEF DEBUG} Writeln('header click...'); {$ENDIF}
- cLeft := FMargin; // column starting point
+ cLeft := borders.Left; // column starting point
if go_SmoothScroll in FOptions then
begin
if FHScrollBar.Visible then
@@ -1433,7 +1467,7 @@ begin
else
hh := 0;
- if ShowHeader and (y > FMargin+hh) then // not in Header row
+ if ShowHeader and (y > (fpgStyle.GetControlFrameBorders.Top + hh)) then // not in Header row
begin
PopupMenu.ShowAt(self, x, y);
end;
@@ -1496,6 +1530,8 @@ begin
end;
constructor TfpgBaseGrid.Create(AOwner: TComponent);
+var
+ borders: TRect;
begin
Updating;
inherited Create(AOwner);
@@ -1508,7 +1544,6 @@ begin
FPrevRow := -1;
FFirstRow := 0;
FFirstCol := 0;
- FMargin := 2;
FShowHeader := True;
FShowGrid := True;
FRowSelect := False;
@@ -1518,6 +1553,8 @@ begin
FHeaderStyle := ghsButton;
FBorderStyle := ebsDefault;
+ borders := GetAdjustedBorderSizes;
+
FFont := fpgGetFont('#Grid');
FHeaderFont := fpgGetFont('#GridHeader');
@@ -1529,8 +1566,8 @@ begin
FAlternativeBGColor := clHilite1;
FColResizing := False;
- MinHeight := HeaderHeight + DefaultRowHeight + FMargin;
- MinWidth := DefaultColWidth + FMargin;
+ MinHeight := HeaderHeight + DefaultRowHeight + borders.Top + borders.Bottom;
+ MinWidth := DefaultColWidth + borders.Left + borders.Right;
FVScrollBar := TfpgScrollBar.Create(self);
FVScrollBar.Orientation := orVertical;
@@ -1600,11 +1637,11 @@ begin
else
hh := 0;
- ARow := FFirstRow + ((y - FMargin - hh) div FDefaultRowHeight);
+ ARow := FFirstRow + ((y - fpgStyle.GetControlFrameBorders.Top - hh) div FDefaultRowHeight);
if ARow > RowCount-1 then
ARow := RowCount-1;
- cLeft := FMargin; // column starting point
+ cLeft := fpgStyle.GetControlFrameBorders.Left; // column starting point
if go_SmoothScroll in FOptions then
begin
if FHScrollBar.Visible then
@@ -1628,6 +1665,19 @@ begin
end;
end;
+function TfpgBaseGrid.GetClientRect: TfpgRect;
+var
+ rect: TRect;
+begin
+ Result := inherited GetClientRect;
+ rect := fpgStyle.GetControlFrameBorders;
+ case BorderStyle of
+// ebsNone: // nothing to do
+ ebsDefault: InflateRect(Result, -rect.Left, -rect.Top); { assuming borders are even on opposite sides }
+ ebsSingle: InflateRect(Result, -1, -1);
+ end;
+end;
+
end.