| 1 | unit Dpi.Grids;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Grids, Controls, StdCtrls, Dpi.Controls;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | { TDpiCustomDrawGrid }
|
|---|
| 10 |
|
|---|
| 11 | TDpiCustomDrawGrid = class(TWinControl)
|
|---|
| 12 | private
|
|---|
| 13 | NativeCustomDrawGrid: TCustomDrawGrid;
|
|---|
| 14 | function GetEditor: TWinControl;
|
|---|
| 15 | procedure SetEditor(AValue: TWinControl);
|
|---|
| 16 | public
|
|---|
| 17 | function GetNativeCustomDrawGrid: TCustomDrawGrid;
|
|---|
| 18 | constructor Create(TheOwner: TComponent); override;
|
|---|
| 19 | destructor Destroy; override;
|
|---|
| 20 | property Editor: TWinControl read GetEditor write SetEditor;
|
|---|
| 21 | end;
|
|---|
| 22 |
|
|---|
| 23 | { TDpiStringGrid }
|
|---|
| 24 |
|
|---|
| 25 | TDpiStringGrid = class(TWinControl)
|
|---|
| 26 | private
|
|---|
| 27 | NativeStringGrid: TStringGrid;
|
|---|
| 28 | function DefaultRowHeightIsStored: Boolean;
|
|---|
| 29 | function GetCells(ACol, ARow: Integer): string;
|
|---|
| 30 | function GetColCount: Integer;
|
|---|
| 31 | function GetColumns: TGridColumns;
|
|---|
| 32 | function GetDefRowHeight: Integer;
|
|---|
| 33 | function GetEditor: Controls.TWinControl;
|
|---|
| 34 | function GetFixedCols: Integer;
|
|---|
| 35 | function GetFixedRows: Integer;
|
|---|
| 36 | function GetOptions: TGridOptions;
|
|---|
| 37 | function GetRowCount: Integer;
|
|---|
| 38 | function GetScrollBars: TScrollStyle;
|
|---|
| 39 | function GetSelection: TGridRect;
|
|---|
| 40 | function IsColumnsStored: Boolean;
|
|---|
| 41 | procedure SetCells(ACol, ARow: Integer; AValue: string);
|
|---|
| 42 | procedure SetColCount(AValue: Integer);
|
|---|
| 43 | procedure SetColumns(AValue: TGridColumns);
|
|---|
| 44 | procedure SetDefRowHeight(AValue: Integer);
|
|---|
| 45 | procedure SetEditor(AValue: Controls.TWinControl);
|
|---|
| 46 | procedure SetFixedCols(AValue: Integer);
|
|---|
| 47 | procedure SetFixedRows(AValue: Integer);
|
|---|
| 48 | procedure SetOptions(AValue: TGridOptions);
|
|---|
| 49 | procedure SetRowCount(AValue: Integer);
|
|---|
| 50 | procedure SetScrollBars(AValue: TScrollStyle);
|
|---|
| 51 | procedure SetSelection(AValue: TGridRect);
|
|---|
| 52 | public
|
|---|
| 53 | function GetNativeStringGrid: TStringGrid;
|
|---|
| 54 | function CellRect(ACol, ARow: Integer): TRect;
|
|---|
| 55 | constructor Create(TheOwner: TComponent); override;
|
|---|
| 56 | destructor Destroy; override;
|
|---|
| 57 | property Selection: TGridRect read GetSelection write SetSelection;
|
|---|
| 58 | property Cells[ACol, ARow: Integer]: string read GetCells write SetCells;
|
|---|
| 59 | published
|
|---|
| 60 | property DefaultRowHeight: Integer read GetDefRowHeight write SetDefRowHeight stored DefaultRowHeightIsStored;
|
|---|
| 61 | property ScrollBars: TScrollStyle read GetScrollBars write SetScrollBars default ssAutoBoth;
|
|---|
| 62 | property FixedCols: Integer read GetFixedCols write SetFixedCols default 1;
|
|---|
| 63 | property FixedRows: Integer read GetFixedRows write SetFixedRows default 1;
|
|---|
| 64 | property RowCount: Integer read GetRowCount write SetRowCount default 5;
|
|---|
| 65 | property ColCount: Integer read GetColCount write SetColCount default 5;
|
|---|
| 66 | property Options: TGridOptions read GetOptions write SetOptions default DefaultGridOptions;
|
|---|
| 67 | property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored;
|
|---|
| 68 | property Editor: Controls.TWinControl read GetEditor write SetEditor;
|
|---|
| 69 | end;
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | implementation
|
|---|
| 73 |
|
|---|
| 74 | { TDpiStringGrid }
|
|---|
| 75 |
|
|---|
| 76 | function TDpiStringGrid.DefaultRowHeightIsStored: Boolean;
|
|---|
| 77 | begin
|
|---|
| 78 | Result := GetDefRowHeight >= 0;
|
|---|
| 79 | end;
|
|---|
| 80 |
|
|---|
| 81 | function TDpiStringGrid.GetCells(ACol, ARow: Integer): string;
|
|---|
| 82 | begin
|
|---|
| 83 | Result := GetNativeStringGrid.Cells[ACol, ARow];
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 | function TDpiStringGrid.GetColCount: Integer;
|
|---|
| 87 | begin
|
|---|
| 88 | Result := GetNativeStringGrid.ColCount;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | function TDpiStringGrid.GetColumns: TGridColumns;
|
|---|
| 92 | begin
|
|---|
| 93 | Result := GetNativeStringGrid.Columns;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | function TDpiStringGrid.GetDefRowHeight: Integer;
|
|---|
| 97 | begin
|
|---|
| 98 | Result := GetNativeStringGrid.DefaultRowHeight;
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 | function TDpiStringGrid.GetEditor: Controls.TWinControl;
|
|---|
| 102 | begin
|
|---|
| 103 | Result := GetNativeStringGrid.Editor;
|
|---|
| 104 | end;
|
|---|
| 105 |
|
|---|
| 106 | function TDpiStringGrid.GetFixedCols: Integer;
|
|---|
| 107 | begin
|
|---|
| 108 | Result := GetNativeStringGrid.FixedCols;
|
|---|
| 109 | end;
|
|---|
| 110 |
|
|---|
| 111 | function TDpiStringGrid.GetFixedRows: Integer;
|
|---|
| 112 | begin
|
|---|
| 113 | Result := GetNativeStringGrid.FixedRows;
|
|---|
| 114 | end;
|
|---|
| 115 |
|
|---|
| 116 | function TDpiStringGrid.GetOptions: TGridOptions;
|
|---|
| 117 | begin
|
|---|
| 118 | Result := GetNativeStringGrid.Options;
|
|---|
| 119 | end;
|
|---|
| 120 |
|
|---|
| 121 | function TDpiStringGrid.GetRowCount: Integer;
|
|---|
| 122 | begin
|
|---|
| 123 | Result := GetNativeStringGrid.RowCount;
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | function TDpiStringGrid.GetScrollBars: TScrollStyle;
|
|---|
| 127 | begin
|
|---|
| 128 | Result := GetNativeStringGrid.ScrollBars;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | function TDpiStringGrid.GetSelection: TGridRect;
|
|---|
| 132 | begin
|
|---|
| 133 | Result := GetNativeStringGrid.Selection;
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 | function TDpiStringGrid.IsColumnsStored: Boolean;
|
|---|
| 137 | begin
|
|---|
| 138 | Result := GetNativeStringGrid.Columns.Enabled;
|
|---|
| 139 | end;
|
|---|
| 140 |
|
|---|
| 141 | procedure TDpiStringGrid.SetCells(ACol, ARow: Integer; AValue: string);
|
|---|
| 142 | begin
|
|---|
| 143 | GetNativeStringGrid.Cells[ACol, ARow] := AValue;
|
|---|
| 144 | end;
|
|---|
| 145 |
|
|---|
| 146 | procedure TDpiStringGrid.SetColCount(AValue: Integer);
|
|---|
| 147 | begin
|
|---|
| 148 | GetNativeStringGrid.ColCount := AValue;
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | procedure TDpiStringGrid.SetColumns(AValue: TGridColumns);
|
|---|
| 152 | begin
|
|---|
| 153 | GetNativeStringGrid.Columns := AValue;
|
|---|
| 154 | end;
|
|---|
| 155 |
|
|---|
| 156 | procedure TDpiStringGrid.SetDefRowHeight(AValue: Integer);
|
|---|
| 157 | begin
|
|---|
| 158 | GetNativeStringGrid.DefaultRowHeight := AValue;
|
|---|
| 159 | end;
|
|---|
| 160 |
|
|---|
| 161 | procedure TDpiStringGrid.SetEditor(AValue: Controls.TWinControl);
|
|---|
| 162 | begin
|
|---|
| 163 | GetNativeStringGrid.Editor := AValue;
|
|---|
| 164 | end;
|
|---|
| 165 |
|
|---|
| 166 | procedure TDpiStringGrid.SetFixedCols(AValue: Integer);
|
|---|
| 167 | begin
|
|---|
| 168 | GetNativeStringGrid.FixedCols := AValue;
|
|---|
| 169 | end;
|
|---|
| 170 |
|
|---|
| 171 | procedure TDpiStringGrid.SetFixedRows(AValue: Integer);
|
|---|
| 172 | begin
|
|---|
| 173 | GetNativeStringGrid.FixedRows := AValue;
|
|---|
| 174 | end;
|
|---|
| 175 |
|
|---|
| 176 | procedure TDpiStringGrid.SetOptions(AValue: TGridOptions);
|
|---|
| 177 | begin
|
|---|
| 178 | GetNativeStringGrid.Options := AValue;
|
|---|
| 179 | end;
|
|---|
| 180 |
|
|---|
| 181 | procedure TDpiStringGrid.SetRowCount(AValue: Integer);
|
|---|
| 182 | begin
|
|---|
| 183 | GetNativeStringGrid.RowCount := AValue;
|
|---|
| 184 | end;
|
|---|
| 185 |
|
|---|
| 186 | procedure TDpiStringGrid.SetScrollBars(AValue: TScrollStyle);
|
|---|
| 187 | begin
|
|---|
| 188 | GetNativeStringGrid.ScrollBars := AValue;
|
|---|
| 189 | end;
|
|---|
| 190 |
|
|---|
| 191 | procedure TDpiStringGrid.SetSelection(AValue: TGridRect);
|
|---|
| 192 | begin
|
|---|
| 193 | GetNativeStringGrid.Selection := AValue;
|
|---|
| 194 | end;
|
|---|
| 195 |
|
|---|
| 196 | function TDpiStringGrid.GetNativeStringGrid: TStringGrid;
|
|---|
| 197 | begin
|
|---|
| 198 | if not Assigned(NativeStringGrid) then NativeStringGrid := TStringGrid.Create(nil);
|
|---|
| 199 | Result := NativeStringGrid;
|
|---|
| 200 | end;
|
|---|
| 201 |
|
|---|
| 202 | function TDpiStringGrid.CellRect(ACol, ARow: Integer): TRect;
|
|---|
| 203 | begin
|
|---|
| 204 | Result := GetNativeStringGrid.CellRect(ACol, ARow);
|
|---|
| 205 | end;
|
|---|
| 206 |
|
|---|
| 207 | constructor TDpiStringGrid.Create(TheOwner: TComponent);
|
|---|
| 208 | begin
|
|---|
| 209 | inherited Create(TheOwner);
|
|---|
| 210 | end;
|
|---|
| 211 |
|
|---|
| 212 | destructor TDpiStringGrid.Destroy;
|
|---|
| 213 | begin
|
|---|
| 214 | FreeAndNil(NativeStringGrid);
|
|---|
| 215 | inherited;
|
|---|
| 216 | end;
|
|---|
| 217 |
|
|---|
| 218 | { TDpiCustomDrawGrid }
|
|---|
| 219 |
|
|---|
| 220 | function TDpiCustomDrawGrid.GetEditor: TWinControl;
|
|---|
| 221 | begin
|
|---|
| 222 | //Result := GetNativeCustomDrawGrid.Editor;
|
|---|
| 223 | end;
|
|---|
| 224 |
|
|---|
| 225 | procedure TDpiCustomDrawGrid.SetEditor(AValue: TWinControl);
|
|---|
| 226 | begin
|
|---|
| 227 | //GetNativeCustomDrawGrid.Editor := AValue
|
|---|
| 228 | end;
|
|---|
| 229 |
|
|---|
| 230 | function TDpiCustomDrawGrid.GetNativeCustomDrawGrid: TCustomDrawGrid;
|
|---|
| 231 | begin
|
|---|
| 232 | if not Assigned(NativeCustomDrawGrid) then NativeCustomDrawGrid := TCustomDrawGrid.Create(nil);
|
|---|
| 233 | Result := NativeCustomDrawGrid;
|
|---|
| 234 | end;
|
|---|
| 235 |
|
|---|
| 236 | constructor TDpiCustomDrawGrid.Create(TheOwner: TComponent);
|
|---|
| 237 | begin
|
|---|
| 238 | inherited Create(TheOwner);
|
|---|
| 239 | end;
|
|---|
| 240 |
|
|---|
| 241 | destructor TDpiCustomDrawGrid.Destroy;
|
|---|
| 242 | begin
|
|---|
| 243 | FreeAndNil(NativeCustomDrawGrid);
|
|---|
| 244 | inherited;
|
|---|
| 245 | end;
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 | end.
|
|---|
| 250 |
|
|---|