diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-22 15:07:28 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-22 15:07:28 +0000 |
commit | 220f4bb067887a8c7dadcf2c56ee1aa24032b195 (patch) | |
tree | d7a7acf5385c6c5deb9753e954ed76262c26a914 /src/gui | |
parent | 9dcbacc1b11c874d3e1ec3ee864418478ec9e00e (diff) | |
download | fpGUI-220f4bb067887a8c7dadcf2c56ee1aa24032b195.tar.xz |
* Started the implementation of a StringGrid. It is
not complete yet.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui_customgrid.pas | 38 | ||||
-rw-r--r-- | src/gui/gui_dialogs.pas | 1 | ||||
-rw-r--r-- | src/gui/gui_grid.pas | 288 |
3 files changed, 307 insertions, 20 deletions
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. |