1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| type
TGridRow = class(TCollectionItem)
private
FTop: Integer;
FHeight: Integer;
FText: String;
protected
function GetBottom: Integer;
function GetHeight: Integer;
procedure SetHeight(const Value: Integer);
function GetText: String;
procedure SetText(const Value: String);
function GetDisplayName: String; override;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
published
property Top: Integer read FTop;
property Bottom: Integer read GetBottom;
property Height: Integer read GetHeight write SetHeight;
property Text: String read GetText write SetText;
end;
TGridRows = class(TOwnedCollection)
private
function GetItem(Index: Integer): TGridRow;
procedure SetItem(Index: Integer; Value: TGridRow);
protected
procedure Update(Item: TCollectionItem); override;
public
constructor Create(AOwner: TPersistent);
destructor Destroy; override;
function Add: TGridRow;
function AddItem(Item: TGridRow; Index: Integer): TGridRow;
function Insert(Index: Integer): TGridRow;
procedure Delete(Index: Integer);
property Items[Index: Integer]: TGridRow read GetItem write SetItem; default;
end;
TGridColumn = class(TCollectionItem)
private
FLeft: Integer;
FWidth: Integer;
FText: String;
protected
function GetRight: Integer;
function GetWidth: Integer;
procedure SetWidth(const Value: Integer);
function GetText: String;
procedure SetText(const Value: String);
function GetDisplayName: String; override;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
published
property Left: Integer read FLeft;
property Right: Integer read GetRight;
property Width: Integer read GetWidth write SetWidth;
property Text: String read GetText write SetText;
end;
TGridColumns = class(TOwnedCollection)
private
function GetItem(Index: Integer): TGridColumn;
procedure SetItem(Index: Integer; Value: TGridColumn);
protected
procedure Update(Item: TCollectionItem); override;
public
constructor Create(AOwner: TPersistent);
destructor Destroy; override;
function Add: TGridColumn;
function AddItem(Item: TGridColumn; Index: Integer): TGridColumn;
function Insert(Index: Integer): TGridColumn;
procedure Delete(Index: Integer);
property Items[Index: Integer]: TGridColumn read GetItem write SetItem; default;
end;
TGridCell = class(TObject)
private
FValue: String;
public
property Value: String read FValue write FValue;
end;
TGridCells = class(TObjectGrid<TGridCell>);
TGridHeader = class(TPersistent)
private
FOwner: TComponent;
FFont: TFont;
FColor: TColor;
FShowColumnHeader: Boolean;
FShowRowHeader: Boolean;
FColHeaderHeight: Integer;
FRowHeaderWidth: Integer;
function GetColHeaderHeight: Integer;
function GetRowHeaderWidth: Integer;
procedure SetColHeaderHeight(const Value: Integer);
procedure SetRowHeaderWidth(const Value: Integer);
protected
function GetFont: TFont;
function GetColor: TColor;
function GetShowColHeader: Boolean;
function GetShowRowHeader: Boolean;
procedure SetFont(const Value: TFont);
procedure SetColor(const Value: TColor);
procedure SetShowColHeader(const Value: Boolean);
procedure SetShowRowHeader(const Value: Boolean);
public
constructor Create(AOwner: TComponent);
destructor Destroy; override;
published
property Font: TFont read GetFont write SetFont;
property Color: TColor read GetColor write SetColor;
property ShowColumnHeader: Boolean read GetShowColHeader write SetShowColHeader;
property ShowRowHeader: Boolean read GetShowRowHeader write SetShowRowHeader;
property ColumnHeaderHeight: Integer read GetColHeaderHeight write SetColHeaderHeight;
property RowHeaderWidth: Integer read GetRowHeaderWidth write SetRowHeaderWidth;
end;
TCoolGrid = class(TCustomControl)
private
FCols: TGridColumns;
FRows: TGridRows;
FHeaders: TGridHeader;
FCells: TGridCells;
FSelectedCell: TGridCell;
procedure SetCols(const Value: TGridColumns);
procedure SetRows(const Value: TGridRows);
procedure SetHeaders(const Value: TGridHeader);
protected
procedure Loaded; override;
procedure Paint; override;
procedure PaintBackground;
procedure PaintCell(const ColIndex, RowIndex: Integer);
procedure PaintGrid;
procedure PaintHeaders;
procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AddCol;
procedure AddRow;
published
property Cols: TGridColumns read FCols write SetCols;
property Headers: TGridHeader read FHeaders write SetHeaders;
property Rows: TGridRows read FRows write SetRows;
end; |
Partager