unit uViewControlBase;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewBase, TBXDkPanels, StdCtrls, ComCtrls, TB2Dock,
  uViewAgrupaciones, uCustomView, uViewColumnas, ImgList, PngImageList,
  ActnList, uViewControlGrid, uBizControlesBase, uViewSumarios,
  uViewParametrosControlGrid, uViewFiltros, cxStyles;

type
  IViewControlBase = interface(IViewBase)
  ['{A9892225-82DB-41AF-B69D-821E0663B3EF}']
    function GetModificable: Boolean;
    procedure SetModificable(const Value: Boolean);
    property Modificable : Boolean read GetModificable write SetModificable;

    function GetControl: IBizControlBase;
    procedure SetControl(const Value: IBizControlBase);
    property Control: IBizControlBase read GetControl write SetControl;

    function GetOnViewChanged : TNotifyEvent;
    procedure SetOnViewChanged(const Value : TNotifyEvent);
    property OnViewChanged: TNotifyEvent read GetOnViewChanged write SetOnViewChanged;
  end;

  TfrViewControlBase = class(TfrViewBase, IViewControlBase)
    TBXMultiDock1: TTBXMultiDock;
    pnlParametros: TTBXDockablePanel;
    TBXAlignmentPanel2: TTBXAlignmentPanel;
    TBXLink1: TTBXLink;
    TBXLink5: TTBXLink;
    TBXLink2: TTBXLink;
    pcParametros: TPageControl;
    TabSheet5: TTabSheet;
    tsColumnas: TTabSheet;
    tsAgrupacion: TTabSheet;
    TBXAlignmentPanel3: TTBXAlignmentPanel;
    bRefrescar: TButton;
    pnlTareas: TTBXDockablePanel;
    TBXPageScroller1: TTBXPageScroller;
    TBXAlignmentPanel1: TTBXAlignmentPanel;
    bFiltros: TTBXLink;
    bSumarios: TTBXLink;
    pcTareas: TPageControl;
    tsSumarios: TTabSheet;
    tsFiltros: TTabSheet;
    frViewColumnas1: TfrViewColumnas;
    frViewAgrupaciones1: TfrViewAgrupaciones;
    SmallImages: TPngImageList;
    LargeImages: TPngImageList;
    EditorActionList: TActionList;
    actAgrupaciones: TAction;
    actColumnas: TAction;
    actSumarios: TAction;
    actFiltros: TAction;
    frViewSumarios1: TfrViewSumarios;
    actRefrescar: TAction;
    frViewFiltros1: TfrViewFiltros;
    procedure actColumnasExecute(Sender: TObject);
    procedure actSumariosExecute(Sender: TObject);
    procedure actFiltrosExecute(Sender: TObject);
    procedure actAgrupacionesExecute(Sender: TObject);
  protected
    FControl : IBizControlBase;
    FOnViewChanged : TNotifyEvent;
    FModificable : Boolean;
    procedure ActivarTarea (const ATarea : Integer); virtual;
    function GetControl: IBizControlBase; virtual;
    procedure SetControl(const Value: IBizControlBase); virtual;
    function GetOnViewChanged : TNotifyEvent; virtual;
    procedure SetOnViewChanged(const Value : TNotifyEvent); virtual;
    function GetModificable: Boolean; virtual;
    procedure SetModificable(const Value: Boolean); virtual;
  public
    property Modificable : Boolean read GetModificable write SetModificable;
    property OnViewChanged: TNotifyEvent read GetOnViewChanged write SetOnViewChanged;
    property Control: IBizControlBase read GetControl write SetControl;
    constructor Create(AOwner: TComponent); override;
  end;

implementation

{$R *.dfm}

const
  COLUMNAS = 1;
  AGRUPACIONES = 2;
  SUMARIOS = 3;
  FILTROS = 4;


procedure TfrViewControlBase.actColumnasExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(COLUMNAS);
  frViewColumnas1.Refresh;
end;

procedure TfrViewControlBase.ActivarTarea(const ATarea: Integer);
begin
  case ATarea of
    COLUMNAS    : pcParametros.ActivePage := tsColumnas;
    AGRUPACIONES  : pcParametros.ActivePage := tsAgrupacion;
    SUMARIOS    : pcTareas.ActivePage := tsSumarios;
    FILTROS     : pcTareas.ActivePage := tsFiltros;
  end;
end;

function TfrViewControlBase.GetControl: IBizControlBase;
begin
  Result := FControl;
end;

procedure TfrViewControlBase.SetControl(const Value: IBizControlBase);
begin
  FControl := Value;
  frViewColumnas1.Refresh;
  frViewAgrupaciones1.Refresh;

  // żEs modificable el control?
  Self.Modificable := FControl.EsModificable;
end;

procedure TfrViewControlBase.actSumariosExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(SUMARIOS);
  frViewSumarios1.Refresh;
end;

procedure TfrViewControlBase.actFiltrosExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(FILTROS);
  frViewFiltros1.Refresh;
 end;

procedure TfrViewControlBase.actAgrupacionesExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(AGRUPACIONES);
  frViewAgrupaciones1.Refresh;
end;

function TfrViewControlBase.GetOnViewChanged: TNotifyEvent;
begin
  Result := FOnViewChanged;
end;

procedure TfrViewControlBase.SetOnViewChanged(const Value: TNotifyEvent);
begin
  FOnViewChanged := Value;
end;

constructor TfrViewControlBase.Create(AOwner: TComponent);
begin
  inherited;
  FModificable := False;
  pcParametros.ActivePage := tsColumnas;
  pcTareas.ActivePage := tsSumarios;
  FOnViewChanged := nil;
end;

function TfrViewControlBase.GetModificable: Boolean;
begin
  Result := FModificable;
end;

procedure TfrViewControlBase.SetModificable(const Value: Boolean);
begin
  FModificable := Value;

  frViewColumnas1.Modificable := FModificable;
  frViewAgrupaciones1.Modificable := FModificable;
end;

end.
