summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-03-21 11:30:16 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-03-21 11:30:16 +0000
commit5c5a7e85d0a4042d70aaa0289851f94a54a9c2f1 (patch)
tree3308838784f581c88015a694dee58185c1985976
parent299d0cb1d2157bc6cac3061862ea1a429e460977 (diff)
downloadfpGUI-5c5a7e85d0a4042d70aaa0289851f94a54a9c2f1.tar.xz
* Applied grid patch from Jean-Marc
* Fixed some bugs in Jean-Marc's patch. Grid.TextColor and Grid.BackgroundColor had no affect. * Extended the GridTest example showing the new features and OnCellDraw example.
-rw-r--r--examples/gui/gridtest/gridtest.lpr31
-rw-r--r--src/gui/gui_basegrid.pas33
-rw-r--r--src/gui/gui_customgrid.pas70
-rw-r--r--src/gui/gui_edit.pas2
-rw-r--r--src/gui/gui_grid.pas18
5 files changed, 149 insertions, 5 deletions
diff --git a/examples/gui/gridtest/gridtest.lpr b/examples/gui/gridtest/gridtest.lpr
index 81534eec..2b6c891e 100644
--- a/examples/gui/gridtest/gridtest.lpr
+++ b/examples/gui/gridtest/gridtest.lpr
@@ -8,6 +8,7 @@ uses
{$ENDIF}{$ENDIF}
Classes,
SysUtils,
+ gfxbase,
fpgfx,
gui_form,
gui_grid,
@@ -18,6 +19,8 @@ uses
type
+ { TMainForm }
+
TMainForm = class(TfpgForm)
private
btnQuit: TfpgButton;
@@ -35,6 +38,8 @@ type
procedure chkShowHeaderChange(Sender: TObject);
procedure chkShowGridChange(Sender: TObject);
procedure btnQuitClick(Sender: TObject);
+ procedure stringgridDrawCell(Sender: TObject; const ARow, ACol: integer;
+ const ARect: TfpgRect; AFlags: integer; var ADefaultDrawing: boolean);
protected
procedure HandleShow; override;
public
@@ -72,6 +77,21 @@ begin
Close;
end;
+procedure TMainForm.stringgridDrawCell(Sender: TObject; const ARow,
+ ACol: integer; const ARect: TfpgRect; AFlags: integer;
+ var ADefaultDrawing: boolean);
+begin
+ if (ACol = 1) and (ARow = 3) then
+ begin
+ ADefaultDrawing := False;
+ StringGrid.Canvas.SetColor(clGreen);
+ fpgStyle.DrawDirectionArrow(StringGrid.Canvas, ARect.Left, ARect.Top,
+ ARect.Height, ARect.Height, 3);
+ StringGrid.Canvas.SetTextColor(clTeal);
+ StringGrid.Canvas.DrawString(ARect.Height + ARect.Left + 2, ARect.Top, StringGrid.Cells[ACol, ARow]);
+ end;
+end;
+
procedure TMainForm.HandleShow;
begin
inherited HandleShow;
@@ -117,6 +137,8 @@ begin
stringgrid.ColumnTitle[1] := 'Column 1';
stringgrid.Columns[2].Title := 'Col 2';
// add some text
+ stringgrid.Cells[1, 1] := '(r1,c1)';
+ stringgrid.Cells[1, 3] := 'Custom';
stringgrid.Cells[2, 3] := 'Hello';
stringgrid.Cells[3, 1] := '(r1,c3)';
@@ -127,6 +149,15 @@ begin
stringgrid.Cells[2, 2] := 'center';
stringgrid.columns[3].Alignment := taRightJustify;
stringgrid.Cells[3, 2] := 'right';
+
+ // override default colors
+ stringgrid.BackgroundColor:= clKhaki;
+ stringgrid.ColumnBackgroundColor[2] := clLightGrey;
+ stringgrid.TextColor:= clBlue;
+ stringgrid.ColumnTextColor[1] := clRed;
+
+ // Add custom painting
+ stringgrid.OnDrawCell:=@stringgridDrawCell;
pagecontrol.ActivePageIndex := 0;
diff --git a/src/gui/gui_basegrid.pas b/src/gui/gui_basegrid.pas
index b18c7673..c4457814 100644
--- a/src/gui/gui_basegrid.pas
+++ b/src/gui/gui_basegrid.pas
@@ -46,6 +46,9 @@ type
// Column 2 is special just for testing purposes. Descendant classes will
// override that special behavior anyway.
+
+ { TfpgBaseGrid }
+
TfpgBaseGrid = class(TfpgWidget)
private
FColResizing: boolean;
@@ -98,6 +101,10 @@ type
function GetHeaderText(ACol: integer): string; virtual;
function GetColumnWidth(ACol: integer): integer; virtual;
procedure SetColumnWidth(ACol: integer; const AValue: integer); virtual;
+ function GetColumnBackgroundColor(ACol: integer): TfpgColor; virtual;
+ procedure SetColumnBackgroundColor(ACol: integer; const AValue: TfpgColor); virtual;
+ function GetColumnTextColor(ACol: integer): TfpgColor; virtual;
+ procedure SetColumnTextColor(ACol: integer; const AValue: TfpgColor); virtual;
function GetColumnCount: integer; virtual;
function GetRowCount: integer; virtual;
function CanSelectCell(const ARow, ACol: integer): boolean;
@@ -132,6 +139,8 @@ type
property HeaderHeight: integer read FHeaderHeight;
// property ColResizing: boolean read FColResizing write FColResizing;
property ColumnWidth[ACol: integer]: integer read GetColumnWidth write SetColumnWidth;
+ property ColumnBackgroundColor[ACol: integer]: TfpgColor read GetColumnBackgroundColor write SetColumnBackgroundColor;
+ property ColumnTextColor[ACol: integer]: TfpgColor read GetColumnTextColor write SetColumnTextColor;
property TopRow: integer read FFirstRow write SetFirstRow;
property OnDrawCell: TfpgDrawCellEvent read FOnDrawCell write FOnDrawCell;
property OnFocusChange: TfpgFocusChangeNotify read FOnFocusChange write FOnFocusChange;
@@ -250,6 +259,26 @@ begin
end;
end;
+function TfpgBaseGrid.GetColumnBackgroundColor(ACol: integer): TfpgColor;
+begin
+ // implemented in descendant
+end;
+
+procedure TfpgBaseGrid.SetColumnBackgroundColor(ACol: integer; const AValue: TfpgColor);
+begin
+ // implemented in descendant
+end;
+
+function TfpgBaseGrid.GetColumnTextColor(ACol: integer): TfpgColor;
+begin
+ // implemented in descendant
+end;
+
+procedure TfpgBaseGrid.SetColumnTextColor(ACol: integer; const AValue: TfpgColor);
+begin
+ // implemented in descendant
+end;
+
function TfpgBaseGrid.GetColumnCount: integer;
begin
Result := 7;
@@ -577,8 +606,8 @@ begin
end
else
begin
- Canvas.SetColor(BackgroundColor);
- Canvas.SetTextColor(clText1);
+ Canvas.SetColor(ColumnBackgroundColor[col]);
+ Canvas.SetTextColor(ColumnTextColor[col]);
end;
Canvas.AddClipRect(r);
Canvas.FillRectangle(r);
diff --git a/src/gui/gui_customgrid.pas b/src/gui/gui_customgrid.pas
index c1fb1272..c7189554 100644
--- a/src/gui/gui_customgrid.pas
+++ b/src/gui/gui_customgrid.pas
@@ -32,6 +32,7 @@ interface
uses
Classes,
SysUtils,
+ gfxbase,
fpgfx,
gui_basegrid;
@@ -43,18 +44,25 @@ type
FAlignment: TAlignment;
FTitle: string;
FWidth: integer;
+ FBackgroundColor: TfpgColor;
+ FTextColor: TfpgColor;
public
constructor Create; virtual;
property Width: integer read FWidth write FWidth;
property Title: string read FTitle write FTitle;
property Alignment: TAlignment read FAlignment write FAlignment;
+ property BackgroundColor: TfpgColor read FBackgroundColor write FBackgroundColor;
+ property TextColor: TfpgColor read FTextColor write FTextColor;
end;
+ { TfpgCustomGrid }
+
TfpgCustomGrid = class(TfpgBaseGrid)
protected
FRowCount: integer;
FColumns: TList;
+ procedure SetTextColor(const AValue: TfpgColor); override;
function GetColumns(AIndex: integer): TfpgGridColumn; virtual;
procedure DoDeleteColumn(ACol: integer); virtual;
procedure DoSetRowCount(AValue: integer); virtual;
@@ -65,6 +73,10 @@ type
procedure SetRowCount(const AValue: integer); virtual;
function GetColumnWidth(ACol: integer): integer; override;
procedure SetColumnWidth(ACol: integer; const AValue: integer); override;
+ function GetColumnBackgroundColor(ACol: integer): TfpgColor; override;
+ procedure SetColumnBackgroundColor(ACol: integer; const AValue: TfpgColor); override;
+ function GetColumnTextColor(ACol: integer): TfpgColor; override;
+ procedure SetColumnTextColor(ACol: integer; const AValue: TfpgColor); override;
function GetHeaderText(ACol: integer): string; override;
property RowCount: integer read GetRowCount write SetRowCount;
property ColumnCount: integer read GetColumnCount write SetColumnCount;
@@ -99,6 +111,18 @@ begin
Result := FRowCount;
end;
+procedure TfpgCustomGrid.SetTextColor(const AValue: TfpgColor);
+var
+ i: integer;
+begin
+ inherited SetTextColor(AValue);
+ for i := 0 to ColumnCount-1 do
+ begin
+ TfpgGridColumn(FColumns.Items[i]).TextColor := AValue;
+ end;
+ Repaint;
+end;
+
function TfpgCustomGrid.GetColumns(AIndex: integer): TfpgGridColumn;
begin
if (AIndex < 1) or (AIndex > FColumns.Count) then
@@ -195,6 +219,50 @@ begin
end;
end;
+function TfpgCustomGrid.GetColumnBackgroundColor(ACol: integer): TfpgColor;
+begin
+ if (ACol > 0) and (ACol <= ColumnCount) then
+ Result := TfpgGridColumn(FColumns[ACol-1]).FBackgroundColor
+ else
+ result := BackgroundColor;
+end;
+
+procedure TfpgCustomGrid.SetColumnBackgroundColor(ACol: integer; const AValue: TfpgColor);
+var
+ lCol: TfpgGridColumn;
+begin
+ lCol := TfpgGridColumn(FColumns[ACol-1]);
+
+ if lCol.FBackgroundColor <> AValue then
+ begin
+ lCol.FBackgroundColor := AValue;
+// UpdateScrollBars;
+ Repaint;
+ end;
+end;
+
+function TfpgCustomGrid.GetColumnTextColor(ACol: integer): TfpgColor;
+begin
+ if (ACol > 0) and (ACol <= ColumnCount) then
+ Result := TfpgGridColumn(FColumns[ACol-1]).FTextColor
+ else
+ result := TextColor;
+end;
+
+procedure TfpgCustomGrid.SetColumnTextColor(ACol: integer; const AValue: TfpgColor);
+var
+ lCol: TfpgGridColumn;
+begin
+ lCol := TfpgGridColumn(FColumns[ACol-1]);
+
+ if lCol.FTextColor <> AValue then
+ begin
+ lCol.FTextColor := AValue;
+// UpdateScrollBars;
+ Repaint;
+ end;
+end;
+
function TfpgCustomGrid.GetHeaderText(ACol: integer): string;
begin
Result := TfpgGridColumn(FColumns[ACol-1]).Title;
@@ -225,6 +293,8 @@ begin
Result := DoCreateColumnClass;
Result.Title := ATitle;
Result.Width := AWidth;
+ Result.Backgroundcolor := clBoxcolor;
+ Result.TextColor := TextColor;
FColumns.Add(Result);
if csUpdating in ComponentState then
diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas
index 39b7c111..6591ff4e 100644
--- a/src/gui/gui_edit.pas
+++ b/src/gui/gui_edit.pas
@@ -331,7 +331,7 @@ begin
begin
// Handle only printable characters
// Note: This is now UTF-8 compliant!
- if (Ord(AText[1]) > 31) and (Ord(AText[1]) < 127) or (Length(AText) > 1) then
+ if ((Ord(AText[1]) > 31) and (Ord(AText[1]) < 127)) or (Length(AText) > 1) then
begin
if (FMaxLength <= 0) or (UTF8Length(FText) < FMaxLength) then
begin
diff --git a/src/gui/gui_grid.pas b/src/gui/gui_grid.pas
index 90d8d04b..40b1c83a 100644
--- a/src/gui/gui_grid.pas
+++ b/src/gui/gui_grid.pas
@@ -129,12 +129,15 @@ type
property Columns[AIndex: integer]: TfpgStringColumn read GetColumns;
public
constructor Create(AOwner: TComponent); override;
- function AddColumn(ATitle: string; AWidth: integer; AAlignment: TAlignment = taLeftJustify): TfpgStringColumn; overload;
+ function AddColumn(ATitle: string; AWidth: integer; AAlignment: TAlignment = taLeftJustify;
+ AbackgroundColor: TfpgColor= clDefault; ATextColor: TfpgColor= clDefault): TfpgStringColumn; overload;
{ ACol and ARow is 1-based. }
property Cells[ACol, ARow: LongWord]: string read GetCell write SetCell;
property Objects[ACol, ARow: LongWord]: TObject read GetObjects write SetObjects;
property ColumnTitle[ACol: integer]: string read GetColumnTitle write SetColumnTitle;
property ColumnWidth[ACol: integer]: integer read GetColumnWidth write SetColumnWidth;
+ property ColumnBackgroundColor[ACol: integer]: TfpgColor read GetColumnBackgroundColor write SetColumnBackgroundColor;
+ property ColumnTextColor[ACol: integer]: TfpgColor read GetColumnTextColor write SetColumnTextColor;
// property Cols[index: Integer]: TStrings read GetCols write SetCols;
// property Rows[index: Integer]: TStrings read GetRows write SetRows;
end;
@@ -557,13 +560,24 @@ begin
end;
function TfpgCustomStringGrid.AddColumn(ATitle: string; AWidth: integer;
- AAlignment: TAlignment): TfpgStringColumn;
+ AAlignment: TAlignment; ABackgroundColor: TfpgColor; ATextColor: TfpgColor): TfpgStringColumn;
var
r: integer;
begin
Include(ComponentState, csUpdating);
Result := TfpgStringColumn(inherited AddColumn(ATitle, AWidth));
Result.Alignment := AAlignment;
+
+ if ABackgroundColor = clDefault then
+ Result.BackgroundColor := clBoxColor
+ else
+ Result.BackgroundColor:= ABackgroundColor;
+
+ if ATextColor = clDefault then
+ Result.TextColor := TextColor
+ else
+ Result.TextColor:= ATextColor;
+
for r := 1 to RowCount do
Result.Cells.Append('');
Exclude(ComponentState, csUpdating);