{*******************************************************}
{                                                       }
{       Administración de puntos de venta               }
{                                                       }
{       Copyright (C) 2006 Rodax Software S.L.          }
{                                                       }
{*******************************************************}

unit uViewGrid;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewBase, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, uDADataTable, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGrid, Menus, ActnList, Grids,
  DBGrids, JvComponent, JvFormAutoSize, dxPSGlbl, dxPSUtl, dxPSEngn,
  dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider, dxPSFillPatterns,
  dxPSEdgePatterns, dxPSCore, dxPScxCommon, dxPScxGridLnk, dxPrnDlg,
  cxIntlPrintSys3, dxPSPrvwAdv, uViewGridBase, cxGridCustomPopupMenu,
  cxGridPopupMenu;

type
  IViewGrid = interface(IViewGridBase)
  ['{7EA40980-AD73-4590-A53A-932316C7B121}']
  end;

  TfrViewGrid = class(TfrViewGridBase, IViewGrid)
    cxGrid: TcxGrid;
    cxGridLevel: TcxGridLevel;
    cxGridView: TcxGridDBTableView;
    dxComponentPrinter: TdxComponentPrinter;
    dxPSEngineController1: TdxPSEngineController;
    cxStyleRepository1: TcxStyleRepository;
    cxStyleEven: TcxStyle;
    cxStyleOdd: TcxStyle;
    cxStyleSelection: TcxStyle;
    cxStyleSinOrden: TcxStyle;
    cxStyleConOrden: TcxStyle;
    cxViewGridPopupMenu: TcxGridPopupMenu;
    dxComponentPrinterLink: TdxGridReportLink;
    cxStyleFiltered: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    dxGridReportLinkStyleSheet1: TdxGridReportLinkStyleSheet;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle3: TcxStyle;
    cxStyle4: TcxStyle;
    cxStyle5: TcxStyle;
    cxStyle6: TcxStyle;
    cxStyle7: TcxStyle;
    cxStyle8: TcxStyle;
    cxStyle9: TcxStyle;
    cxStyle10: TcxStyle;
    cxStyle11: TcxStyle;
    cxStyle12: TcxStyle;
    cxStyle13: TcxStyle;
    procedure cxGridViewStylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure cxGridViewDblClick(Sender: TObject);
  protected
    function GetGrid : TcxGrid; override;
    function GetFocusedView : TcxGridDBTableView; override;
    procedure SetPopupMenu(const Value: TPopupMenu); override;
    procedure FilterChanged(Sender : TObject); override;
  public
    procedure Preview; override;
    procedure Print; override;
    procedure PrintSetup; override;
  end;

implementation

uses
  uDataModuleBase, uDBSelectionListUtils;

{$R *.dfm}

{
********************************* TfrViewGrid **********************************
}

{ TfrViewGrid }
function TfrViewGrid.GetFocusedView: TcxGridDBTableView;
begin
  Result := cxGridView;
end;

function TfrViewGrid.GetGrid: TcxGrid;
begin
  Result := cxGrid;
end;

procedure TfrViewGrid.Preview;
begin
  inherited;
  dxComponentPrinter.Preview;
end;

procedure TfrViewGrid.Print;
begin
  inherited;
  dxComponentPrinter.Print(True, nil, nil);
end;

procedure TfrViewGrid.PrintSetup;
begin
  inherited;
  dxComponentPrinter.PageSetup(nil);  
end;

procedure TfrViewGrid.SetPopupMenu(const Value: TPopupMenu);
begin
  inherited;
  cxViewGridPopupMenu.PopupMenus[0].PopupMenu := FPopupMenu;
end;

procedure TfrViewGrid.cxGridViewDblClick(Sender: TObject);
begin
  inherited;
  if Assigned(FOnDblClick) then
    FOnDblClick(Sender);
end;

procedure TfrViewGrid.cxGridViewStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
  inherited;
  if Assigned(AItem) then
  begin
    if AItem.SortOrder = soNone then
      AStyle := cxStyleSinOrden
    else
      AStyle := cxStyleConOrden;
  end;
end;

procedure TfrViewGrid.FilterChanged(Sender: TObject);
begin
  inherited;
  if Filtered then
    _FocusedView.Styles.Content := cxStyleFiltered
  else
    _FocusedView.Styles.Content := nil;
end;

end.

