summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-08-22 15:07:28 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-08-22 15:07:28 +0000
commit220f4bb067887a8c7dadcf2c56ee1aa24032b195 (patch)
treed7a7acf5385c6c5deb9753e954ed76262c26a914
parent9dcbacc1b11c874d3e1ec3ee864418478ec9e00e (diff)
downloadfpGUI-220f4bb067887a8c7dadcf2c56ee1aa24032b195.tar.xz
* Started the implementation of a StringGrid. It is
not complete yet.
-rw-r--r--examples/gui/filedialog/filedialog.lpr1
-rw-r--r--examples/gui/gridtest/gridtest.lpr278
-rw-r--r--src/gui/gui_customgrid.pas38
-rw-r--r--src/gui/gui_dialogs.pas1
-rw-r--r--src/gui/gui_grid.pas288
5 files changed, 464 insertions, 142 deletions
diff --git a/examples/gui/filedialog/filedialog.lpr b/examples/gui/filedialog/filedialog.lpr
index d7b1f176..01793a6f 100644
--- a/examples/gui/filedialog/filedialog.lpr
+++ b/examples/gui/filedialog/filedialog.lpr
@@ -42,6 +42,7 @@ var
begin
dlg := TfpgFileDialog.Create(nil);
try
+ // defines 3 filters (All Files, Object Pascal and Lazarus Project)
dlg.Filter := 'All Files (*)|*|Object Pascal (*.pas;*.lpr;*.pp)|*.pas;*.lpr;*.pp|Lazarus Project (*.lpi)|*.lpi';
if dlg.RunOpenFile then
edFilename.Text := dlg.FileName;
diff --git a/examples/gui/gridtest/gridtest.lpr b/examples/gui/gridtest/gridtest.lpr
index 60d75cdc..66802e7c 100644
--- a/examples/gui/gridtest/gridtest.lpr
+++ b/examples/gui/gridtest/gridtest.lpr
@@ -1,122 +1,156 @@
-program gridtest;
-
-{$mode objfpc}{$H+}
-
-uses
- {$IFDEF UNIX}{$IFDEF UseCThreads}
- cthreads,
- {$ENDIF}{$ENDIF}
- Classes,
- SysUtils,
- fpgfx,
- gui_form,
- gui_grid,
- gui_button,
- gui_checkbox;
-
-
-type
-
- TMainForm = class(TfpgForm)
- private
- btnQuit: TfpgButton;
- grdMain: TfpgGrid;
- chkShowHeader: TfpgCheckBox;
- chkShowGrid: TfpgCheckBox;
- chkRowSelect: TfpgCheckBox;
- chkDisabled: TfpgCheckBox;
- procedure chkDisabledChange(Sender: TObject);
- procedure chkRowSelectChange(Sender: TObject);
- procedure chkShowHeaderChange(Sender: TObject);
- procedure chkShowGridChange(Sender: TObject);
- procedure btnQuitClick(Sender: TObject);
- public
- constructor Create(AOwner: TComponent); override;
- end;
-
-{ TMainForm }
-
-procedure TMainForm.chkDisabledChange(Sender: TObject);
-begin
- grdMain.Enabled := not chkDisabled.Checked;
-end;
-
-procedure TMainForm.chkRowSelectChange(Sender: TObject);
-begin
- grdMain.RowSelect := chkRowSelect.Checked;
-end;
-
-procedure TMainForm.chkShowHeaderChange(Sender: TObject);
-begin
- grdMain.ShowHeader := chkShowHeader.Checked;
-end;
-
-procedure TMainForm.chkShowGridChange(Sender: TObject);
-begin
- grdMain.ShowGrid := chkShowGrid.Checked;
-end;
-
-procedure TMainForm.btnQuitClick(Sender: TObject);
-begin
- Close;
-end;
-
-constructor TMainForm.Create(AOwner: TComponent);
-var
- c: integer;
-begin
- inherited Create(AOwner);
- WindowTitle := 'Grid control test';
- SetPosition(100, 100, 566, 350);
-
- btnQuit := CreateButton(self, 476, 320, 80, 'Quit', @btnQuitClick);
- btnQuit.ImageName := 'stdimg.Quit';
- btnQuit.ShowImage := True;
- btnQuit.Anchors := [anRight, anBottom];
-
- grdMain := TfpgGrid.Create(self);
- grdMain.Top := 10;
- grdMain.Left := 10;
- grdMain.Width := Width - 20;
- grdMain.Height := 300;
- grdMain.Anchors := [anLeft, anTop, anRight, anBottom];
- grdMain.RowCount := 25;
- for c := 1 to grdMain.ColumnCount do
- grdMain.Columns[c-1].Title := 'Title ' + IntToStr(c);
-
- chkShowHeader := CreateCheckBox(self, 10, 320, 'Show Header');
- chkShowHeader.Checked := True;
- chkShowHeader.OnChange := @chkShowHeaderChange;
- chkShowHeader.Anchors := [anLeft, anBottom];
-
- chkShowGrid := CreateCheckBox(self, chkShowHeader.Right+10, 320, 'Show Grid');
- chkShowGrid.Checked := True;
- chkShowGrid.OnChange := @chkShowGridChange;
- chkShowGrid.Anchors := [anLeft, anBottom];
-
- chkRowSelect := CreateCheckBox(self, chkShowGrid.Right+10, 320, 'Row Select');
- chkRowSelect.Checked := False;
- chkRowSelect.OnChange := @chkRowSelectChange;
- chkRowSelect.Anchors := [anLeft, anBottom];
-
- chkDisabled := CreateCheckBox(self, chkRowSelect.Right+10, 320, 'Disabled');
- chkDisabled.Checked := False;
- chkDisabled.OnChange := @chkDisabledChange;
- chkDisabled.Anchors := [anLeft, anBottom];
-end;
-
-
-procedure MainProc;
-var
- frm: TMainForm;
-begin
- fpgApplication.Initialize;
- frm := TMainForm.Create(nil);
- frm.Show;
- fpgApplication.Run;
-end;
-
-begin
- MainProc;
-end.
-
+program gridtest;
+
+{$mode objfpc}{$H+}
+
+uses
+ {$IFDEF UNIX}{$IFDEF UseCThreads}
+ cthreads,
+ {$ENDIF}{$ENDIF}
+ Classes,
+ SysUtils,
+ fpgfx,
+ gui_form,
+ gui_grid,
+ gui_button,
+ gui_checkbox,
+ gui_tab;
+
+
+type
+
+ TMainForm = class(TfpgForm)
+ private
+ btnQuit: TfpgButton;
+ pagecontrol: TfpgPageControl;
+ tsTab1: TfpgTabSheet;
+ tsTab2: TfpgTabSheet;
+ grdMain: TfpgGrid;
+ stringgrid: TfpgStringGrid;
+ chkShowHeader: TfpgCheckBox;
+ chkShowGrid: TfpgCheckBox;
+ chkRowSelect: TfpgCheckBox;
+ chkDisabled: TfpgCheckBox;
+ procedure chkDisabledChange(Sender: TObject);
+ procedure chkRowSelectChange(Sender: TObject);
+ procedure chkShowHeaderChange(Sender: TObject);
+ procedure chkShowGridChange(Sender: TObject);
+ procedure btnQuitClick(Sender: TObject);
+ protected
+ procedure HandleShow; override;
+ public
+ constructor Create(AOwner: TComponent); override;
+ end;
+
+{ TMainForm }
+
+procedure TMainForm.chkDisabledChange(Sender: TObject);
+begin
+ grdMain.Enabled := not chkDisabled.Checked;
+end;
+
+procedure TMainForm.chkRowSelectChange(Sender: TObject);
+begin
+ grdMain.RowSelect := chkRowSelect.Checked;
+end;
+
+procedure TMainForm.chkShowHeaderChange(Sender: TObject);
+begin
+ grdMain.ShowHeader := chkShowHeader.Checked;
+end;
+
+procedure TMainForm.chkShowGridChange(Sender: TObject);
+begin
+ grdMain.ShowGrid := chkShowGrid.Checked;
+end;
+
+procedure TMainForm.btnQuitClick(Sender: TObject);
+begin
+ Close;
+end;
+
+procedure TMainForm.HandleShow;
+begin
+ inherited HandleShow;
+end;
+
+constructor TMainForm.Create(AOwner: TComponent);
+var
+ c: integer;
+ r: integer;
+begin
+ inherited Create(AOwner);
+ WindowTitle := 'Grid control test';
+ SetPosition(100, 100, 566, 350);
+
+ btnQuit := CreateButton(self, 476, 320, 80, 'Quit', @btnQuitClick);
+ btnQuit.ImageName := 'stdimg.Quit';
+ btnQuit.ShowImage := True;
+ btnQuit.Anchors := [anRight, anBottom];
+
+ pagecontrol := TfpgPageControl.Create(self);
+ pagecontrol.SetPosition(10, 10, Width-20, 300);
+ pagecontrol.Anchors := [anLeft, anTop, anRight, anBottom];
+
+ tsTab1 := TfpgTabSheet.Create(pagecontrol);
+ tsTab1.Text := 'Base Grid';
+ grdMain := TfpgGrid.Create(tsTab1);
+ grdMain.SetPosition(10, 10, Width-50, 250);
+// grdMain.Anchors := [anLeft, anTop, anRight, anBottom];
+ grdMain.RowCount := 25;
+ for c := 1 to grdMain.ColumnCount do
+ grdMain.Columns[c-1].Title := 'Title ' + IntToStr(c);
+
+
+ tsTab2 := pagecontrol.AppendTabSheet('String Grid');
+ stringgrid := TfpgStringGrid.Create(tsTab2);
+ stringgrid.SetPosition(10, 10, Width-50, 250);
+ stringgrid.ColumnCount := 2;
+ stringgrid.RowCount := 5;
+ stringgrid.Cells[2, 1] := 'hello';
+ stringgrid.Cells[5, 2] := 'hello';
+ stringgrid.ColumnTitle[1] := 'Column 1';
+// stringgrid.Columns[1].Title := 'Column 1';
+// stringgrid.Columns[2].Title := 'Col2';
+ //for r := 1 to stringgrid.RowCount do
+ //for c := 1 to stringgrid.ColumnCount do
+ //stringgrid.Cells[r, c] := IntToStr(r) + ',' + IntToStr(c);
+// stringgrid.Anchors := [anLeft, anTop, anRight, anBottom];
+
+ pagecontrol.ActivePageIndex := 0;
+
+ chkShowHeader := CreateCheckBox(self, 10, 320, 'Show Header');
+ chkShowHeader.Checked := True;
+ chkShowHeader.OnChange := @chkShowHeaderChange;
+ chkShowHeader.Anchors := [anLeft, anBottom];
+
+ chkShowGrid := CreateCheckBox(self, chkShowHeader.Right+10, 320, 'Show Grid');
+ chkShowGrid.Checked := True;
+ chkShowGrid.OnChange := @chkShowGridChange;
+ chkShowGrid.Anchors := [anLeft, anBottom];
+
+ chkRowSelect := CreateCheckBox(self, chkShowGrid.Right+10, 320, 'Row Select');
+ chkRowSelect.Checked := False;
+ chkRowSelect.OnChange := @chkRowSelectChange;
+ chkRowSelect.Anchors := [anLeft, anBottom];
+
+ chkDisabled := CreateCheckBox(self, chkRowSelect.Right+10, 320, 'Disabled');
+ chkDisabled.Checked := False;
+ chkDisabled.OnChange := @chkDisabledChange;
+ chkDisabled.Anchors := [anLeft, anBottom];
+end;
+
+
+procedure MainProc;
+var
+ frm: TMainForm;
+begin
+ fpgApplication.Initialize;
+ frm := TMainForm.Create(nil);
+ frm.Show;
+ fpgApplication.Run;
+end;
+
+begin
+ MainProc;
+end.
+
diff --git a/src/gui/gui_customgrid.pas b/src/gui/gui_customgrid.pas
index 1cda07ef..05a7a5a7 100644
--- a/src/gui/gui_customgrid.pas
+++ b/src/gui/gui_customgrid.pas
@@ -21,13 +21,13 @@ uses
type
// data object for grid columns
- TGridColumn = class(TObject)
+ TfpgGridColumn = class(TObject)
private
FAlignment: TAlignment;
FTitle: string;
FWidth: integer;
public
- constructor Create;
+ constructor Create; virtual;
property Width: integer read FWidth write FWidth;
property Title: string read FTitle write FTitle;
property Alignment: TAlignment read FAlignment write FAlignment;
@@ -36,12 +36,12 @@ type
TfpgCustomGrid = class(TfpgBaseGrid)
private
- FRowCount: integer;
- function GetColumns(AIndex: integer): TGridColumn;
+ function GetColumns(AIndex: integer): TfpgGridColumn;
protected
+ FRowCount: integer;
FColumns: TList;
function GetColumnCount: integer; override;
- procedure SetColumnCount(const AValue: integer);
+ procedure SetColumnCount(const AValue: integer); virtual;
function GetRowCount: integer; override;
procedure SetRowCount(const AValue: integer); virtual;
function GetColumnWidth(ACol: integer): integer; override;
@@ -49,19 +49,19 @@ type
function GetHeaderText(ACol: integer): string; override;
property RowCount: integer read GetRowCount write SetRowCount;
property ColumnCount: integer read GetColumnCount write SetColumnCount;
- property Columns[AIndex: integer]: TGridColumn read GetColumns;
+ property Columns[AIndex: integer]: TfpgGridColumn read GetColumns;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
- function AddColumn(ATitle: string; AWidth: integer): TGridColumn;
+ function AddColumn(ATitle: string; AWidth: integer): TfpgGridColumn;
end;
implementation
-{ TGridColumn }
+{ TfpgGridColumn }
-constructor TGridColumn.Create;
+constructor TfpgGridColumn.Create;
begin
Width := 64;
Title := '';
@@ -75,12 +75,12 @@ begin
Result := FRowCount;
end;
-function TfpgCustomGrid.GetColumns(AIndex: integer): TGridColumn;
+function TfpgCustomGrid.GetColumns(AIndex: integer): TfpgGridColumn;
begin
if (AIndex < 0) or (AIndex > FColumns.Count-1) then
Result := nil
else
- Result := TGridColumn(FColumns[AIndex]);
+ Result := TfpgGridColumn(FColumns[AIndex]);
end;
function TfpgCustomGrid.GetColumnCount: integer;
@@ -109,7 +109,7 @@ begin
begin
while n > AValue do
begin
- TGridColumn(FColumns.Items[n-1]).Free;
+ TfpgGridColumn(FColumns.Items[n-1]).Free;
FColumns.Delete(n-1);
dec(n);
end;
@@ -133,16 +133,16 @@ end;
function TfpgCustomGrid.GetColumnWidth(ACol: integer): integer;
begin
if (ACol > 0) and (ACol <= ColumnCount) then
- Result := TGridColumn(FColumns[ACol-1]).Width
+ Result := TfpgGridColumn(FColumns[ACol-1]).Width
else
result := DefaultColWidth;
end;
procedure TfpgCustomGrid.SetColumnWidth(ACol: integer; const AValue: integer);
var
- lCol: TGridColumn;
+ lCol: TfpgGridColumn;
begin
- lCol := TGridColumn(FColumns[ACol-1]);
+ lCol := TfpgGridColumn(FColumns[ACol-1]);
if lCol.Width <> AValue then
begin
@@ -157,7 +157,7 @@ end;
function TfpgCustomGrid.GetHeaderText(ACol: integer): string;
begin
- Result := TGridColumn(FColumns[ACol-1]).Title;
+ Result := TfpgGridColumn(FColumns[ACol-1]).Title;
end;
constructor TfpgCustomGrid.Create(AOwner: TComponent);
@@ -172,7 +172,7 @@ destructor TfpgCustomGrid.Destroy;
begin
while FColumns.Count > 0 do
begin
- TGridColumn(FColumns.Items[0]).Free;
+ TfpgGridColumn(FColumns.Items[0]).Free;
FColumns.Delete(0);
end;
@@ -180,9 +180,9 @@ begin
inherited Destroy;
end;
-function TfpgCustomGrid.AddColumn(ATitle: string; AWidth: integer): TGridColumn;
+function TfpgCustomGrid.AddColumn(ATitle: string; AWidth: integer): TfpgGridColumn;
begin
- Result := TGridColumn.Create;
+ Result := TfpgGridColumn.Create;
Result.Title := ATitle;
Result.Width := AWidth;
FColumns.Add(Result);
diff --git a/src/gui/gui_dialogs.pas b/src/gui/gui_dialogs.pas
index a2a7b072..98004ee9 100644
--- a/src/gui/gui_dialogs.pas
+++ b/src/gui/gui_dialogs.pas
@@ -959,6 +959,7 @@ var
drvs: string;
{$endif}
begin
+ ds := '';
GetDir(0, ds);
fsel := ExtractFileName(ds);
diff --git a/src/gui/gui_grid.pas b/src/gui/gui_grid.pas
index b678d5ae..aa0a471a 100644
--- a/src/gui/gui_grid.pas
+++ b/src/gui/gui_grid.pas
@@ -9,6 +9,7 @@ uses
SysUtils,
gfxbase,
fpgfx,
+ gui_basegrid,
gui_customgrid;
type
@@ -111,6 +112,66 @@ type
end;
+ TfpgStringColumn = class(TfpgGridColumn)
+ private
+ FCells: TStringList;
+ public
+ constructor Create; override;
+ destructor Destroy; override;
+ property Cells: TStringList read FCells write FCells;
+ end;
+
+
+ TfpgStringGrid = class(TfpgBaseGrid)
+ private
+ FDoPaint: boolean; // used in destructor
+ FColumns: TList;
+ FDefaultColumnWidth: TfpgCoord;
+ FRowCount: integer;
+ FColumnCount: integer;
+ function GetCell(ARow, ACol: Longword): string;
+ function GetColumnCount: integer;
+ function GetColumnTitle(ACol: integer): string;
+ function GetColumns(AIndex: integer): TfpgStringColumn;
+ function GetRowCount: integer;
+ procedure SetCell(ARow, ACol: Longword; const AValue: string);
+ procedure SetColumnCount(const AValue: integer);
+ procedure SetColumnTitle(ACol: integer; const AValue: string);
+ procedure SetRowCount(const AValue: integer);
+ protected
+ procedure DrawCell(ARow, ACol: integer; ARect: TfpgRect; AFlags: integer); override;
+ function GetHeaderText(ACol: integer): string; override;
+ function GetColumnWidth(ACol: integer): integer; override;
+ procedure SetColumnWidth(ACol: integer; const AValue: integer); override;
+ public
+ constructor Create(AOwner: TComponent); override;
+ destructor Destroy; override;
+ property Cells[ARow, ACol: Longword]: string read GetCell write SetCell;
+ property RowCount: integer read GetRowCount write SetRowCount;
+ property ColumnCount: integer read GetColumnCount write SetColumnCount;
+ property Columns[AIndex: integer]: TfpgStringColumn read GetColumns;
+ property ColumnTitle[ACol: integer]: string read GetColumnTitle write SetColumnTitle;
+ property ColumnWidth[ACol: integer]: integer read GetColumnWidth write SetColumnWidth;
+ published
+ property DefaultColWidth;
+ property DefaultRowHeight;
+ property Font;
+ property HeaderFont;
+ property BackgroundColor;
+ property FocusCol;
+ property FocusRow;
+ property RowSelect;
+// property ColumnCount;
+// property RowCount;
+ property ShowHeader;
+ property ShowGrid;
+ property HeaderHeight;
+ property ColResizing;
+// property ColumnWidth;
+ property OnFocusChange;
+ property OnRowChange;
+ property OnDoubleClick;
+ end;
implementation
@@ -120,7 +181,7 @@ uses
,Windows // Graeme: temporary, just to see how the grid looks under Windows.
{$ENDIF}
{$IFDEF UNIX}
- ,libc // Graeme: temporary, just to see how the grid looks under Windows.
+ ,libc // Graeme: temporary
,baseunix
{$ENDIF}
;
@@ -551,5 +612,230 @@ begin
Result := FFileList.Entry[FocusRow];
end;
+{ TfpgStringColumn }
+
+constructor TfpgStringColumn.Create;
+begin
+ inherited Create;
+ FCells := TStringList.Create;
+// writeln(Classname, ' .Create');
+end;
+
+destructor TfpgStringColumn.Destroy;
+begin
+ FCells.Free;
+ inherited Destroy;
+end;
+
+
+{ TfpgStringGrid }
+
+function TfpgStringGrid.GetCell(ARow, ACol: Longword): string;
+var
+ diff: integer;
+begin
+ if ACol > FColumns.Count - 1 then
+ result := ''
+ else
+ begin
+ diff := (TfpgStringColumn(FColumns[ACol]).Cells.Count - 1) - integer(ARow);
+ if diff < 0 then
+ result := ''
+ else
+ result := TfpgStringColumn(FColumns[ACol]).Cells[ARow];
+ end;
+end;
+
+function TfpgStringGrid.GetColumnCount: integer;
+begin
+ result := FColumnCount;
+end;
+
+function TfpgStringGrid.GetColumnTitle(ACol: integer): string;
+begin
+ if FColumns.Count - 1 < ACol then
+ result := ''
+ else
+ result := TfpgStringColumn(FColumns[ACol]).Title;
+end;
+
+function TfpgStringGrid.GetColumns(AIndex: integer): TfpgStringColumn;
+begin
+ if (AIndex < 0) or (AIndex > FColumns.Count-1) then
+ Result := nil
+ else
+ Result := TfpgStringColumn(FColumns[AIndex]);
+end;
+
+function TfpgStringGrid.GetRowCount: integer;
+begin
+ result := FRowCount;
+end;
+
+procedure TfpgStringGrid.SetCell(ARow, ACol: Longword; const AValue: string);
+var
+ aCalc: integer;
+ TmpCol: TfpgStringColumn;
+ i: Longword;
+begin
+ aCalc := ACol - FColumns.Count + 1;
+ if aCalc > 0 then
+ begin
+ for i := 1 to aCalc do
+ begin
+ TmpCol := TfpgStringColumn.Create;
+ TmpCol.Width := DefaultColWidth;
+ FColumns.Add(TmpCol);
+ end;
+ end;
+ aCalc := ARow - TfpgStringColumn(FColumns[ACol]).Cells.Count + 1;
+ if aCalc > 0 then
+ begin
+ for i := 1 to aCalc do
+ TfpgStringColumn(FColumns[ACol]).Cells.Append('');
+ end;
+ TfpgStringColumn(FColumns[ACol]).Cells[ARow] := AValue;
+ if ACol > FColumnCount - 1 then
+ FColumnCount := ACol + 1;
+ if ARow > FRowCount - 1 then
+ FRowCount := ARow + 1;
+end;
+
+procedure TfpgStringGrid.SetColumnCount(const AValue: integer);
+var
+ i: integer;
+ aCalc: integer;
+begin
+ if AValue <> FColumnCount then
+ begin
+ if AValue < FColumnCount then
+ begin
+ aCalc := FColumns.Count - AValue;
+ if aCalc > 0 then
+ begin
+ for i := 1 to aCalc do
+ begin
+ TfpgStringColumn(FColumns[i]).Destroy;
+ FColumns.Delete(FColumns.Count-1);
+ end;
+ end;
+ end;
+ FColumnCount := AValue;
+ if FDoPaint then
+ RePaint;
+ end;
+end;
+
+procedure TfpgStringGrid.SetColumnTitle(ACol: integer; const AValue: string);
+var
+ aCalc: integer;
+begin
+ aCalc := ACol - FColumns.Count + 1;
+ if aCalc > 0 then
+ Cells[ACol, 0] := '';
+ if AValue <> TfpgStringColumn(FColumns[ACol]).Title then
+ begin
+ if ACol+1 > FColumnCount then
+ FColumnCount := ACol + 1;
+ TfpgStringColumn(FColumns[ACol]).Title := aValue;
+ RePaint;
+ end;
+end;
+
+procedure TfpgStringGrid.SetRowCount(const AValue: integer);
+var
+ i, i1: integer;
+ aCalc: integer;
+ SL: TStringList;
+begin
+ if AValue <> FRowCount then
+ begin
+ if AValue < FRowCount then
+ begin
+ for i := 0 to FColumns.Count - 1 do
+ begin
+ aCalc := TfpgStringColumn(FColumns[i]).Cells.Count - AValue;
+ if aCalc > 0 then
+ begin
+ sl := TfpgStringColumn(FColumns[i]).Cells;
+ for i1 := 1 to aCalc do
+ sl.Delete(sl.Count-1);
+ end;
+ end;
+ end;
+ FRowCount := aValue;
+ if FDoPaint then
+ RePaint;
+ end;
+end;
+
+procedure TfpgStringGrid.DrawCell(ARow, ACol: integer; ARect: TfpgRect; AFlags: integer);
+var
+ s: string;
+begin
+// inherited DrawCell(ARow, ACol, ARect, AFlags);
+ s := Cells[ACol-1, ARow-1];
+ if s <> '' then
+ Canvas.DrawString(aRect.Left + 1, aRect.top + 1, s);
+end;
+
+function TfpgStringGrid.GetHeaderText(ACol: integer): string;
+begin
+ Result := ColumnTitle[ACol-1];
+end;
+
+function TfpgStringGrid.GetColumnWidth(ACol: integer): integer;
+begin
+ if ACol > FColumns.Count - 1 then
+ result := DefaultColWidth
+ else
+ result := TfpgStringColumn(FColumns[ACol]).Width;
+end;
+
+procedure TfpgStringGrid.SetColumnWidth(ACol: integer; const AValue: integer);
+var
+ aCalc: integer;
+ i: integer;
+ TmpCol: TfpgStringColumn;
+begin
+ aCalc := ACol - FColumns.Count;
+ if aCalc > 0 then
+ begin
+ for i := 1 to aCalc do
+ begin
+ TmpCol := TfpgStringColumn.Create;
+ TmpCol.Width := DefaultColWidth;
+ TmpCol.Cells := TStringList.Create;
+ FColumns.Add(TmpCol);
+ end;
+ end;
+ if TfpgStringColumn(FColumns[ACol]).Width <> AValue then
+ begin
+ TfpgStringColumn(FColumns[ACol]).Width := AValue;
+ RePaint;
+ end;
+end;
+
+constructor TfpgStringGrid.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ FDoPaint := True;
+ FColumns := TList.Create;
+ FColumnCount := 0;
+ FRowCount := 0;
+ DefaultColWidth := 100;
+ ColumnCount := 5;
+ RowCount := 5;
+end;
+
+destructor TfpgStringGrid.Destroy;
+begin
+ FDoPaint := False;
+ ColumnCount := 0;
+ RowCount := 0;
+ FColumns.Free;
+ inherited Destroy;
+end;
+
end.