unit Dpi.Grids;

interface

uses
  Classes, SysUtils, Grids, Controls, StdCtrls, Dpi.Controls;

type
  { TDpiCustomDrawGrid }

  TDpiCustomDrawGrid = class(TWinControl)
  private
    NativeCustomDrawGrid: TCustomDrawGrid;
    function GetEditor: TWinControl;
    procedure SetEditor(AValue: TWinControl);
  public
    function GetNativeCustomDrawGrid: TCustomDrawGrid;
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    property Editor: TWinControl read GetEditor write SetEditor;
  end;

  { TDpiStringGrid }

  TDpiStringGrid = class(TWinControl)
  private
    NativeStringGrid: TStringGrid;
    function DefaultRowHeightIsStored: Boolean;
    function GetCells(ACol, ARow: Integer): string;
    function GetColCount: Integer;
    function GetColumns: TGridColumns;
    function GetDefRowHeight: Integer;
    function GetEditor: Controls.TWinControl;
    function GetFixedCols: Integer;
    function GetFixedRows: Integer;
    function GetOptions: TGridOptions;
    function GetRowCount: Integer;
    function GetScrollBars: TScrollStyle;
    function GetSelection: TGridRect;
    function IsColumnsStored: Boolean;
    procedure SetCells(ACol, ARow: Integer; AValue: string);
    procedure SetColCount(AValue: Integer);
    procedure SetColumns(AValue: TGridColumns);
    procedure SetDefRowHeight(AValue: Integer);
    procedure SetEditor(AValue: Controls.TWinControl);
    procedure SetFixedCols(AValue: Integer);
    procedure SetFixedRows(AValue: Integer);
    procedure SetOptions(AValue: TGridOptions);
    procedure SetRowCount(AValue: Integer);
    procedure SetScrollBars(AValue: TScrollStyle);
    procedure SetSelection(AValue: TGridRect);
  public
    function GetNativeStringGrid: TStringGrid;
    function CellRect(ACol, ARow: Integer): TRect;
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    property Selection: TGridRect read GetSelection write SetSelection;
    property Cells[ACol, ARow: Integer]: string read GetCells write SetCells;
  published
    property DefaultRowHeight: Integer read GetDefRowHeight write SetDefRowHeight stored DefaultRowHeightIsStored;
    property ScrollBars: TScrollStyle read GetScrollBars write SetScrollBars default ssAutoBoth;
    property FixedCols: Integer read GetFixedCols write SetFixedCols default 1;
    property FixedRows: Integer read GetFixedRows write SetFixedRows default 1;
    property RowCount: Integer read GetRowCount write SetRowCount default 5;
    property ColCount: Integer read GetColCount write SetColCount default 5;
    property Options: TGridOptions read GetOptions write SetOptions default DefaultGridOptions;
    property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored;
    property Editor: Controls.TWinControl read GetEditor write SetEditor;
  end;


implementation

{ TDpiStringGrid }

function TDpiStringGrid.DefaultRowHeightIsStored: Boolean;
begin
  Result := GetDefRowHeight >= 0;
end;

function TDpiStringGrid.GetCells(ACol, ARow: Integer): string;
begin
  Result := GetNativeStringGrid.Cells[ACol, ARow];
end;

function TDpiStringGrid.GetColCount: Integer;
begin
  Result := GetNativeStringGrid.ColCount;
end;

function TDpiStringGrid.GetColumns: TGridColumns;
begin
  Result := GetNativeStringGrid.Columns;
end;

function TDpiStringGrid.GetDefRowHeight: Integer;
begin
  Result := GetNativeStringGrid.DefaultRowHeight;
end;

function TDpiStringGrid.GetEditor: Controls.TWinControl;
begin
  Result := GetNativeStringGrid.Editor;
end;

function TDpiStringGrid.GetFixedCols: Integer;
begin
  Result := GetNativeStringGrid.FixedCols;
end;

function TDpiStringGrid.GetFixedRows: Integer;
begin
  Result := GetNativeStringGrid.FixedRows;
end;

function TDpiStringGrid.GetOptions: TGridOptions;
begin
  Result := GetNativeStringGrid.Options;
end;

function TDpiStringGrid.GetRowCount: Integer;
begin
  Result := GetNativeStringGrid.RowCount;
end;

function TDpiStringGrid.GetScrollBars: TScrollStyle;
begin
  Result := GetNativeStringGrid.ScrollBars;
end;

function TDpiStringGrid.GetSelection: TGridRect;
begin
  Result := GetNativeStringGrid.Selection;
end;

function TDpiStringGrid.IsColumnsStored: Boolean;
begin
  Result := GetNativeStringGrid.Columns.Enabled;
end;

procedure TDpiStringGrid.SetCells(ACol, ARow: Integer; AValue: string);
begin
  GetNativeStringGrid.Cells[ACol, ARow] := AValue;
end;

procedure TDpiStringGrid.SetColCount(AValue: Integer);
begin
  GetNativeStringGrid.ColCount := AValue;
end;

procedure TDpiStringGrid.SetColumns(AValue: TGridColumns);
begin
  GetNativeStringGrid.Columns := AValue;
end;

procedure TDpiStringGrid.SetDefRowHeight(AValue: Integer);
begin
  GetNativeStringGrid.DefaultRowHeight := AValue;
end;

procedure TDpiStringGrid.SetEditor(AValue: Controls.TWinControl);
begin
  GetNativeStringGrid.Editor := AValue;
end;

procedure TDpiStringGrid.SetFixedCols(AValue: Integer);
begin
  GetNativeStringGrid.FixedCols := AValue;
end;

procedure TDpiStringGrid.SetFixedRows(AValue: Integer);
begin
  GetNativeStringGrid.FixedRows := AValue;
end;

procedure TDpiStringGrid.SetOptions(AValue: TGridOptions);
begin
  GetNativeStringGrid.Options := AValue;
end;

procedure TDpiStringGrid.SetRowCount(AValue: Integer);
begin
  GetNativeStringGrid.RowCount := AValue;
end;

procedure TDpiStringGrid.SetScrollBars(AValue: TScrollStyle);
begin
  GetNativeStringGrid.ScrollBars := AValue;
end;

procedure TDpiStringGrid.SetSelection(AValue: TGridRect);
begin
  GetNativeStringGrid.Selection := AValue;
end;

function TDpiStringGrid.GetNativeStringGrid: TStringGrid;
begin
  if not Assigned(NativeStringGrid) then NativeStringGrid := TStringGrid.Create(nil);
    Result := NativeStringGrid;
end;

function TDpiStringGrid.CellRect(ACol, ARow: Integer): TRect;
begin
  Result := GetNativeStringGrid.CellRect(ACol, ARow);
end;

constructor TDpiStringGrid.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
end;

destructor TDpiStringGrid.Destroy;
begin
  FreeAndNil(NativeStringGrid);
  inherited;
end;

{ TDpiCustomDrawGrid }

function TDpiCustomDrawGrid.GetEditor: TWinControl;
begin
  //Result := GetNativeCustomDrawGrid.Editor;
end;

procedure TDpiCustomDrawGrid.SetEditor(AValue: TWinControl);
begin
  //GetNativeCustomDrawGrid.Editor := AValue
end;

function TDpiCustomDrawGrid.GetNativeCustomDrawGrid: TCustomDrawGrid;
begin
  if not Assigned(NativeCustomDrawGrid) then NativeCustomDrawGrid := TCustomDrawGrid.Create(nil);
    Result := NativeCustomDrawGrid;
end;

constructor TDpiCustomDrawGrid.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
end;

destructor TDpiCustomDrawGrid.Destroy;
begin
  FreeAndNil(NativeCustomDrawGrid);
  inherited;
end;



end.

