summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2014-02-25 22:09:22 +0000
committerGraeme Geldenhuys <graemeg@gmail.com>2014-02-25 22:09:22 +0000
commit352454c885e84ab845c3e75cc379adbd3c5275f1 (patch)
tree63639ef2fbc77d5a7ff9654a3aab68e9a661b111 /src/gui
parentf72e8e9ca85c55208708aa065739cfc63a2fe407 (diff)
downloadfpGUI-352454c885e84ab845c3e75cc379adbd3c5275f1.tar.xz
grid: First run through code removing hard-coded border widths.
This was mostly the replacement of FMargin field variable usage. Tested and grid still works like before.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/fpg_basegrid.pas71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/gui/fpg_basegrid.pas b/src/gui/fpg_basegrid.pas
index aee679d0..953451da 100644
--- a/src/gui/fpg_basegrid.pas
+++ b/src/gui/fpg_basegrid.pas
@@ -534,7 +534,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;
@@ -542,10 +542,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;
@@ -553,10 +553,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);
@@ -594,8 +594,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
@@ -621,8 +623,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;
@@ -637,8 +641,10 @@ begin
end;
// preliminary width/height calculations
- VHeight := Height - 4;
- HWidth := Width - 4;
+ borders := fpgStyle.GetControlFrameBorders;
+ crect := GetClientRect;
+ VHeight := crect.Height;
+ HWidth := crect.Width;
cw := 0;
for i := 0 to ColumnCount-1 do
cw := cw + ColumnWidth[i];
@@ -703,17 +709,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
@@ -738,17 +744,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;
@@ -781,7 +787,6 @@ var
rect: TRect;
begin
Canvas.ClearClipRect;
-
r.SetRect(0, 0, Width, Height);
case BorderStyle of
ebsNone:
@@ -791,26 +796,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
@@ -1434,7 +1435,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;
@@ -1509,7 +1510,6 @@ begin
FPrevRow := -1;
FFirstRow := 0;
FFirstCol := 0;
- FMargin := 2;
FShowHeader := True;
FShowGrid := True;
FRowSelect := False;
@@ -1518,6 +1518,7 @@ begin
FOptions := [];
FHeaderStyle := ghsButton;
FBorderStyle := ebsDefault;
+ FMargin := GetClientRect.Left;
FFont := fpgGetFont('#Grid');
FHeaderFont := fpgGetFont('#GridHeader');
@@ -1601,11 +1602,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