{********************************************************************}
{                                                                    }
{ written by TMS Software                                            }
{            copyright © 2013                                        }
{            Email : info@tmssoftware.com                            }
{            Web : http://www.tmssoftware.com                        }
{                                                                    }
{ The source code is given as is. The author is not responsible      }
{ for any possible damage done due to the use of this code.          }
{ The complete source code remains property of the author and may    }
{ not be distributed, published, given or sold in any form as such.  }
{ No parts of the source code can be included in any other component }
{ or application without written authorization of the author.        }
{********************************************************************}

unit FMX.TMSTableViewEx;

interface

{$I TMSDEFS.INC}

uses
  Classes, FMX.TMSTableView, FMX.Objects, FMX.TMSBaseControl;


type
  TTMSFMXTableViewItemEx = class(TTMSFMXTableViewItem)
  private
    FExtra: string;
    procedure SetExtra(const Value: string);
  protected
    procedure UpdateExtra;
    procedure ApplyEx; override;
  public
    procedure Assign(Source: TPersistent); override;
    function ShapeExtra: TText;
  published
    property Extra: string read FExtra write SetExtra;
  end;

  TTMSFMXTableViewItemsEx = class(TTMSFMXTableViewItems)
  public
    function CreateItemClass: TCollectionItemClass; override;
  end;

  [ComponentPlatformsAttribute(TMSPlatforms)]
  TTMSFMXTableViewEx = class(TTMSFMXTableView)
  protected
    function GetClassStyleName: String; override;
  public
    function CreateItems: TTMSFMXTableViewItems; override;
  end;


implementation

{ TTMSFMXTableViewItemsEx }

function TTMSFMXTableViewItemsEx.CreateItemClass: TCollectionItemClass;
begin
  Result := TTMSFMXTableViewItemEx;
end;

{ TTMSFMXTableViewEx }

function TTMSFMXTableViewEx.CreateItems: TTMSFMXTableViewItems;
begin
  Result := TTMSFMXTableViewItemsEx.Create(Self);
end;

function TTMSFMXTableViewEx.GetClassStyleName: String;
begin
  Result := ClassParent.ClassName + 'style';
  Delete(Result, 1, 1);
end;

{ TTMSFMXTableViewItemEx }

procedure TTMSFMXTableViewItemEx.ApplyEx;
begin
  inherited;
  UpdateExtra;
end;

procedure TTMSFMXTableViewItemEx.Assign(Source: TPersistent);
begin
  inherited;
  if (Source is TTMSFMXTableViewItemEx) then
    FExtra := (Source as TTMSFMXTableViewItemEx).Extra;
end;

procedure TTMSFMXTableViewItemEx.SetExtra(const Value: string);
begin
  if FExtra <> Value then
  begin
    FExtra := Value;
    if TableView.GetUpdateCount = 0 then
      UpdateExtra;
  end;
end;

function TTMSFMXTableViewItemEx.ShapeExtra: TText;
var
  shp: TTMSFMXTableViewItemShape;
begin
  Result := nil;
  shp := Shape;
  if Assigned(shp) then
    Result := shp.FindStyleResource('itemextra') as TText;
end;

procedure TTMSFMXTableViewItemEx.UpdateExtra;
var
  shp: TText;
begin
  shp := ShapeExtra;
  if Assigned(shp) then
    shp.Text := Extra;
end;

end.
