cxgriddetailssite.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 2,042 行 · 第 1/5 页

PAS
2,042
字号
    FFullyVisible: Boolean;
    FLevel: TcxGridLevel;
    FNormalHeight: Integer;
    FTabsViewInfo: TcxCustomGridDetailsSiteTabsViewInfo;
    function GetClientHeight: Integer;
    function GetClientWidth: Integer;
    function GetControl: TcxControl;
    function GetFrameBounds: TRect;
    function GetInternalHeight: Integer;
    function GetInternalWidth: Integer;
    function GetIsActiveGridViewDestroying: Boolean;
    function GetLookAndFeel: TcxLookAndFeel;
    function GetLookAndFeelPainter: TcxCustomLookAndFeelPainterClass;
    function GetMaxDetailHeight: Integer;
    function GetMaxDetailSize: TPoint;
    function GetMaxDetailWidth: Integer;
    function GetNonClientHeight: Integer;
    function GetNonClientWidth: Integer;
    function GetTabsPosition: TcxGridDetailTabsPosition;
  protected
    procedure Notification(AComponent: TComponent; AOperation: TOperation); override;

    function CalculateHeight: Integer; virtual;
    function CalculateWidth: Integer; virtual;
    function GetBkColor: TColor; virtual;
    function GetCanvas: TcxCanvas; virtual; abstract;
    function GetClientBounds: TRect; virtual;
    function GetContainer: TcxControl; virtual; abstract;
    function GetDesignController: TcxCustomGridDesignController; virtual; abstract;
    function GetEmptyClientHeight: Integer; virtual;
    function GetEmptyClientWidth: Integer; virtual;
    function GetFrameColor: TColor; virtual;
    function GetFrameWidth: Integer; virtual;
    function GetFullyVisible: Boolean; virtual;
    function GetHeight: Integer; virtual;
    function GetMasterRecord: TObject; virtual; abstract;  // TcxCustomGridRecord
    function GetMaxHeight: Integer; virtual; abstract;
    function GetMaxNormalHeight: Integer; virtual;
    function GetMaxWidth: Integer; virtual; abstract;
    function GetMinWidth: Integer; virtual;
    function GetNormalHeight: Integer; virtual;
    function GetWidth: Integer; virtual;

    function GetPainterClass: TcxGridDetailsSitePainterClass; virtual;
    function GetTabsViewInfoClass: TcxCustomGridDetailsSiteTabsViewInfoClass; virtual;

    function GetActiveGridView: TcxCustomGridView; virtual; abstract;
    function GetActiveGridViewExists: Boolean; virtual;
    function GetActiveGridViewValue: TcxCustomGridView; virtual;
    function GetActiveLevel: TcxGridLevel; virtual; abstract;
    function GetVisible: Boolean; virtual;

    procedure GetLevelTabDefaultParams(var AParams: TcxViewParams); virtual;
    procedure GetLevelTabParams(ALevel: TcxGridLevel; var AParams: TcxViewParams); virtual;
    procedure InitTabHitTest(AHitTest: TcxGridDetailsSiteTabHitTest); virtual; abstract;

    procedure GetCachedInfo(var AInfo: TcxCustomGridDetailsSiteViewInfoCachedInfo); virtual;
    function GetCachedInfoClass: TcxCustomGridDetailsSiteViewInfoCachedInfoClass; virtual;
    procedure SetCachedInfo(var AInfo: TcxCustomGridDetailsSiteViewInfoCachedInfo); virtual;

    property ActiveGridView: TcxCustomGridView read GetActiveGridViewValue;
    property ActiveGridViewExists: Boolean read GetActiveGridViewExists;
    property Canvas: TcxCanvas read GetCanvas;
    property ClientHeight: Integer read GetClientHeight;
    property ClientWidth: Integer read GetClientWidth;
    property Container: TcxControl read GetContainer;  // grid or site
    property Control: TcxControl read GetControl;  // grid
    property DesignController: TcxCustomGridDesignController read GetDesignController;
    property EmptyClientHeight: Integer read GetEmptyClientHeight;
    property EmptyClientWidth: Integer read GetEmptyClientWidth;
    property InternalHeight: Integer read GetInternalHeight;
    property InternalWidth: Integer read GetInternalWidth;
    property IsActiveGridViewDestroying: Boolean read GetIsActiveGridViewDestroying;
    property LookAndFeel: TcxLookAndFeel read GetLookAndFeel;
    property LookAndFeelPainter: TcxCustomLookAndFeelPainterClass read GetLookAndFeelPainter;
    property MaxDetailHeight: Integer read GetMaxDetailHeight;
    property MaxDetailSize: TPoint read GetMaxDetailSize;
    property MaxDetailWidth: Integer read GetMaxDetailWidth;
    property MaxHeight: Integer read GetMaxHeight;
    property MaxNormalHeight: Integer read GetMaxNormalHeight;
    property MaxWidth: Integer read GetMaxWidth;
    property MinWidth: Integer read GetMinWidth;
    property NonClientHeight: Integer read GetNonClientHeight;
    property NonClientWidth: Integer read GetNonClientWidth;
    property TabsPosition: TcxGridDetailTabsPosition read GetTabsPosition;
  public
    Bounds: TRect;
    constructor Create(ALevel: TcxGridLevel); reintroduce; virtual;
    destructor Destroy; override;
    procedure BeforeRecalculation; virtual;
    procedure Calculate(ALeftBound, ATopBound: Integer); virtual;
    procedure ChangeActiveTab(ALevel: TcxGridLevel; AFocusView: Boolean = False); virtual; abstract;
    function DetailHasData(ALevel: TcxGridLevel): Boolean; virtual; abstract;
    function GetHitTest(const P: TPoint): TcxCustomGridHitTest; virtual;
    function IsTabVisible(ALevel: TcxGridLevel): Boolean; virtual;
    procedure Paint(ACanvas: TcxCanvas);
    function ProcessDialogChar(ACharCode: Word): Boolean;
    function SupportsTabAccelerators: Boolean; virtual;
    procedure VisibilityChanged(AVisible: Boolean); virtual;

    property ActiveLevel: TcxGridLevel read GetActiveLevel;
    property BkColor: TColor read GetBkColor;
    property ClientBounds: TRect read GetClientBounds;
    property FrameBounds: TRect read GetFrameBounds;
    property FrameColor: TColor read GetFrameColor;
    property FrameWidth: Integer read GetFrameWidth;
    property FullyVisible: Boolean read GetFullyVisible;
    property Height: Integer read GetHeight;
    property Level: TcxGridLevel read FLevel;
    property MasterRecord: TObject read GetMasterRecord;
    property NormalHeight: Integer read GetNormalHeight;
    property TabsViewInfo: TcxCustomGridDetailsSiteTabsViewInfo read FTabsViewInfo;
    property Visible: Boolean read GetVisible;
    property Width: Integer read GetWidth;
  end;

implementation

uses
  SysUtils, Math, Forms, Menus, cxPCPainters, cxGrid, cxGridCustomTableView;

const
  ActiveLeftTabOffset = 3;
  ActiveTopTabOffset = 2;
  TabsAreaOffset = 2;
  TabTextOffset = 5;

type
  TWinControlAccess = class(TWinControl);

{ TcxGridDetailsSiteTabHitTest }

class function TcxGridDetailsSiteTabHitTest.GetHitTestCode: Integer;
begin
  Result := htTab;
end;

{$IFNDEF USETABCONTROL}

{ TcxGridDetailsSiteTabPainter }

function TcxGridDetailsSiteTabPainter.GetViewInfo: TcxCustomGridDetailsSiteTabViewInfo;
begin
  Result := TcxCustomGridDetailsSiteTabViewInfo(inherited ViewInfo);
end;

procedure TcxGridDetailsSiteTabPainter.DrawBorder(ABorder: TcxBorder);
begin
  with ViewInfo do
    LookAndFeelPainter.DrawTabBorder(Self.Canvas, BorderBounds[ABorder], ABorder,
      Borders, IsVertical);
end;

procedure TcxGridDetailsSiteTabPainter.DrawContent;
begin
  with ViewInfo do
    if LookAndFeelPainter.IsDrawTabImplemented(IsVertical) then
      LookAndFeelPainter.DrawTab(Self.Canvas, Bounds, Borders,
        TextForPainting, GridCellStateToButtonState(StateForPaint), IsVertical, Params.Font,
        Params.TextColor, Params.Color, cxGridTabAccelSupport and SiteViewInfo.SupportsTabAccelerators)
    else
      inherited;
end;

{$ENDIF}

{ TcxGridDetailsSiteTabsPainter }

constructor TcxGridDetailsSiteTabsPainter.Create(ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridDetailsSiteTabsViewInfo);
begin
  inherited Create;
  FCanvas := ACanvas;
  FViewInfo := AViewInfo;
end;

{$IFNDEF USETABCONTROL}

procedure TcxGridDetailsSiteTabsPainter.DrawBackground;
begin
  Canvas.Brush.Color := ViewInfo.BkColor;
  Canvas.FillRect(ViewInfo.Bounds);
end;

procedure TcxGridDetailsSiteTabsPainter.DrawItems;
var
  I: Integer;
begin
  for I := 0 to FViewInfo.Count - 1 do
    FViewInfo.Items[I].Paint;
end;

procedure TcxGridDetailsSiteTabsPainter.DrawRoot;
begin
  with ViewInfo do
    LookAndFeelPainter.DrawTabsRoot(Self.Canvas, RootBounds, RootBorders, IsVertical);
end;

{$ENDIF}

procedure TcxGridDetailsSiteTabsPainter.Paint;
begin
{$IFDEF USETABCONTROL}
  // to create handle and show control if it was recreated during form loading
  ViewInfo.TabControl.UpdateControlState;
{$ELSE}
  DrawBackground;
  DrawRoot;
  DrawItems;
{$ENDIF}  
end;

procedure TcxGridDetailsSiteTabsPainter.MainPaint;
var
  AClipRegion, ARegion: TcxRegion;
begin
  AClipRegion := Canvas.GetClipRegion;
  ARegion := TcxRegion.Create(ViewInfo.Bounds);
  Canvas.SetClipRegion(ARegion, roIntersect);
  try
    Paint;
  finally
    Canvas.SetClipRegion(AClipRegion, roSet);
  end;
end;

{ TcxGridDetailsSitePainter }

constructor TcxGridDetailsSitePainter.Create(ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridDetailsSiteViewInfo);
begin
  inherited Create;
  FCanvas := ACanvas;
  FViewInfo := AViewInfo;
end;

procedure TcxGridDetailsSitePainter.DrawBackground;
begin
  Canvas.Brush.Color := ViewInfo.BkColor;
  Canvas.FillRect(ViewInfo.ClientBounds);
end;

procedure TcxGridDetailsSitePainter.DrawFrame;
begin
  with ViewInfo do
    Self.Canvas.FrameRect(FrameBounds, FrameColor, FrameWidth);
end;

procedure TcxGridDetailsSitePainter.DrawTabs;
var
  AViewInfo: TcxCustomGridDetailsSiteTabsViewInfo;
begin
  AViewInfo := ViewInfo.TabsViewInfo;
  if AViewInfo <> nil then
    with AViewInfo.GetPainterClass.Create(Canvas, AViewInfo) do
      try
        MainPaint;
      finally
        Free;
      end;
end;

procedure TcxGridDetailsSitePainter.Paint;
begin
  if ViewInfo.FrameWidth <> 0 then
    DrawFrame;
  DrawTabs;
  DrawBackground;
  //Canvas.ExcludeClipRect(ViewInfo.Bounds);
end;

{$IFNDEF USETABCONTROL}

{ TcxCustomGridDetailsSiteTabViewInfo }

constructor TcxCustomGridDetailsSiteTabViewInfo.Create(ATabsViewInfo: TcxCustomGridDetailsSiteTabsViewInfo;
  ALevel: TcxGridLevel);
begin
  inherited Create;
  FTabsViewInfo := ATabsViewInfo;
  FLevel := ALevel;
  FIndex := FLevel.VisibleIndex;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetActive: Boolean;
begin
  Result := FTabsViewInfo.ActiveLevel = FLevel;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetCaption: string;
begin
  Result := FLevel.Caption;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetGrid: TcxControl;
begin
  Result := FLevel.Control;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetIsVertical: Boolean;
begin
  Result := FTabsViewInfo.IsVertical;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetLookAndFeelPainter: TcxCustomLookAndFeelPainterClass;
begin
  Result := FTabsViewInfo.LookAndFeelPainter;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetSiteViewInfo: TcxCustomGridDetailsSiteViewInfo;
begin
  Result := FTabsViewInfo.SiteViewInfo;
end;

function TcxCustomGridDetailsSiteTabViewInfo.CalculateHeight: Integer;
begin
  Result := TextHeightWithOffset;
end;

function TcxCustomGridDetailsSiteTabViewInfo.CalculateWidth: Integer;
begin
  Result := 2 * TabTextOffset + TextWidthWithOffset;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetBorderWidth(AIndex: TcxBorder): Integer;
begin
  Result := LookAndFeelPainter.TabBorderSize(IsVertical);
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetCanvas: TcxCanvas;
begin
  Result := FTabsViewInfo.Canvas;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetHitTestClass: TcxCustomGridHitTestClass;
begin
  Result := TcxGridDetailsSiteTabHitTest;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetHotTrack: Boolean;
begin
  Result := LookAndFeelPainter.IsTabHotTrack(IsVertical);
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetIsDesignSelected: Boolean;
begin
  Result := Grid.IsDesigning and
    TcxCustomGrid(Grid).StructureNavigator.IsObjectSelected(FLevel);
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetPainterClass: TcxCustomGridCellPainterClass;
begin
  Result := TcxGridDetailsSiteTabPainter;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetStateForPaint: TcxGridCellState;
begin
  if Active then
    Result := gcsPressed
  else
    Result := State;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetText: string;
begin
  Result := Caption;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetTextAreaBounds: TRect;
begin
  Result := inherited GetTextAreaBounds;
  InflateRect(Result, -TabTextOffset, 0);
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetTextAttributes(AForPainting: Boolean): Integer;
begin
  Result := inherited GetTextAttributes(AForPainting);
  if cxGridTabAccelSupport and SiteViewInfo.SupportsTabAccelerators then
    Result := Result or cxShowPrefix;
end;

function TcxCustomGridDetailsSiteTabViewInfo.GetTextForPainting: string;
begin
  if cxGridTabAccelSupport and not SiteViewInfo.SupportsTabAccelerators then
    Result := FLevel.DisplayCaption
  else
    Result := inherited GetTextForPainting;
end;

procedure TcxCustomGridDetailsSiteTabViewInfo.GetViewParams(var AParams: TcxViewParams);
begin
  FTabsViewInfo.Level.Styles.GetTabParams(TcxCustomGridRecord(SiteViewInfo.MasterRecord),
    Level, AParams);
end;

function TcxCustomGridDetailsSiteTabViewInfo.HasFirstBorder: Boolean;
begin
  Result := (Index = 0) or not TabsViewInfo.Items[Index - 1].Active;
end;

function TcxCustomGridDetailsSiteTabViewInfo.HasLastBorder: Boolean;
begin
  Result := (Index = TabsViewInfo.Count - 1) or not TabsViewInfo.Items[Index + 1].Active;
end;

procedure TcxCustomGridDetailsSiteTabViewInfo.InitHitTest(AHitTest: TcxCustomGridHitTest);
begin
  inherited;
  TcxGridDetailsSiteTabHitTest(AHitTest).Level := FLevel;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?