From f72e8e9ca85c55208708aa065739cfc63a2fe407 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 25 Feb 2014 22:07:52 +0000 Subject: grid: introduce an overloaded GetClientRect() function. This takes into account BorderStyle and border widths from the theme manager. --- src/gui/fpg_basegrid.pas | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/fpg_basegrid.pas b/src/gui/fpg_basegrid.pas index 6f262331..aee679d0 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, @@ -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; @@ -1628,6 +1629,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. -- cgit v1.2.3-70-g09d2 From 352454c885e84ab845c3e75cc379adbd3c5275f1 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 25 Feb 2014 22:09:22 +0000 Subject: 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. --- src/gui/fpg_basegrid.pas | 71 ++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 35 deletions(-) (limited to 'src') 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 -- cgit v1.2.3-70-g09d2 From 1c322900e145714b3f20c9fe4d9a972ab4024232 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 25 Feb 2014 22:09:36 +0000 Subject: grid: minor code formatting fix. --- src/gui/fpg_grid.pas | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/fpg_grid.pas b/src/gui/fpg_grid.pas index 07183e0d..3f8b52fb 100644 --- a/src/gui/fpg_grid.pas +++ b/src/gui/fpg_grid.pas @@ -115,8 +115,7 @@ type property Columns[AIndex: Integer]: TfpgStringColumn read GetColumns; public constructor Create(AOwner: TComponent); override; - function AddColumn(ATitle: string; AWidth: integer; AAlignment: TAlignment = taLeftJustify; - AbackgroundColor: TfpgColor = clDefault; ATextColor: TfpgColor = clDefault): TfpgStringColumn; overload; + function AddColumn(ATitle: string; AWidth: integer; AAlignment: TAlignment = taLeftJustify; AbackgroundColor: TfpgColor = clDefault; ATextColor: TfpgColor = clDefault): TfpgStringColumn; overload; procedure DeleteRow(AIndex: integer); override; property Cells[ACol, ARow: Integer]: string read GetCell write SetCell; property Objects[ACol, ARow: Integer]: TObject read GetObjects write SetObjects; -- cgit v1.2.3-70-g09d2 From f404fb46f1387a4be04da03f496c82e2355aade5 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 25 Feb 2014 22:18:44 +0000 Subject: grid: Removes last traces of that pesky FMargin variable. --- src/gui/fpg_basegrid.pas | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gui/fpg_basegrid.pas b/src/gui/fpg_basegrid.pas index 953451da..847f36f1 100644 --- a/src/gui/fpg_basegrid.pas +++ b/src/gui/fpg_basegrid.pas @@ -73,7 +73,6 @@ type FFirstRow: Integer; FFirstCol: Integer; FXOffset: integer; // used for go_SmoothScroll - FMargin: integer; FFont: TfpgFont; FHeaderFont: TfpgFont; FRowSelect: boolean; @@ -1220,6 +1219,7 @@ var colresize: boolean; cLeft: integer; c: integer; + borders: TRect; begin inherited HandleMouseMove(x, y, btnstate, shiftstate); @@ -1243,8 +1243,9 @@ begin begin colresize := False; hh := FHeaderHeight; + borders := fpgStyle.GetControlFrameBorders; - cLeft := FMargin; // column starting point + cLeft := borders.Left; // column starting point if go_SmoothScroll in FOptions then begin if FHScrollBar.Visible then @@ -1256,7 +1257,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 @@ -1288,6 +1289,7 @@ var c: integer; n: integer; cw: integer; + borders: TRect; begin inherited HandleLMouseUp(x, y, shiftstate); @@ -1299,12 +1301,13 @@ begin Exit; //==> // searching for the appropriate character position hh := FHeaderHeight; + borders := fpgStyle.GetControlFrameBorders; - 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 @@ -1351,6 +1354,7 @@ var pcol: Integer; c: integer; cLeft: integer; + borders: TRect; begin inherited HandleLMouseDown(x, y, shiftstate); @@ -1359,6 +1363,7 @@ begin pcol := FFocusCol; prow := FFocusRow; + borders := fpgStyle.GetControlFrameBorders; // searching for the appropriate character position if ShowHeader then @@ -1366,11 +1371,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 @@ -1498,9 +1503,14 @@ begin end; constructor TfpgBaseGrid.Create(AOwner: TComponent); +var + borders: TRect; begin Updating; inherited Create(AOwner); + + borders := fpgStyle.GetControlFrameBorders; + Focusable := True; Width := 120; Height := 80; @@ -1518,7 +1528,6 @@ begin FOptions := []; FHeaderStyle := ghsButton; FBorderStyle := ebsDefault; - FMargin := GetClientRect.Left; FFont := fpgGetFont('#Grid'); FHeaderFont := fpgGetFont('#GridHeader'); @@ -1531,8 +1540,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; -- cgit v1.2.3-70-g09d2 From bbeff0966370c1ed48f58ab8ebe9eb93ee8b11fd Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 25 Feb 2014 22:37:38 +0000 Subject: grid: Final piece of the puzzle. BorderStyle is now fully working. --- src/gui/fpg_basegrid.pas | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/fpg_basegrid.pas b/src/gui/fpg_basegrid.pas index 847f36f1..146887b9 100644 --- a/src/gui/fpg_basegrid.pas +++ b/src/gui/fpg_basegrid.pas @@ -90,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); @@ -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; @@ -638,9 +665,9 @@ begin hideScrollbar(FVScrollBar); exit; end; - + + borders := GetAdjustedBorderSizes; // preliminary width/height calculations - borders := fpgStyle.GetControlFrameBorders; crect := GetClientRect; VHeight := crect.Height; HWidth := crect.Width; @@ -1243,7 +1270,7 @@ begin begin colresize := False; hh := FHeaderHeight; - borders := fpgStyle.GetControlFrameBorders; + borders := GetAdjustedBorderSizes; cLeft := borders.Left; // column starting point if go_SmoothScroll in FOptions then @@ -1301,7 +1328,7 @@ begin Exit; //==> // searching for the appropriate character position hh := FHeaderHeight; - borders := fpgStyle.GetControlFrameBorders; + borders := GetAdjustedBorderSizes; if (y < (borders.Top+hh)) then // inside Header row begin @@ -1363,7 +1390,7 @@ begin pcol := FFocusCol; prow := FFocusRow; - borders := fpgStyle.GetControlFrameBorders; + borders := GetAdjustedBorderSizes; // searching for the appropriate character position if ShowHeader then @@ -1508,9 +1535,6 @@ var begin Updating; inherited Create(AOwner); - - borders := fpgStyle.GetControlFrameBorders; - Focusable := True; Width := 120; Height := 80; @@ -1529,6 +1553,8 @@ begin FHeaderStyle := ghsButton; FBorderStyle := ebsDefault; + borders := GetAdjustedBorderSizes; + FFont := fpgGetFont('#Grid'); FHeaderFont := fpgGetFont('#GridHeader'); -- cgit v1.2.3-70-g09d2