cxgrid.pas

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

PAS
2,183
字号
end;

{ TcxGridRootLevelOptions }

constructor TcxGridRootLevelOptions.Create(ALevel: TcxGridLevel);
begin
  inherited;
  DetailFrameWidth := cxGridRootLevelDefaultDetailFrameWidth;
end;

{ TcxGridRootLevel }

function TcxGridRootLevel.GetOptionsClass: TcxGridLevelOptionsClass;
begin
  Result := TcxGridRootLevelOptions;
end;

{ TcxCustomGrid }

constructor TcxCustomGrid.Create(AOwner: TComponent);
begin
  inherited;
  BorderStyle := cxcbsDefault;
  ControlStyle := ControlStyle + [csDisplayDragImage];
  FDragOpening := True;
  FDragOpeningWaitTime := cxGridDefaultDragOpeningWaitTime;
  FLevelTabs := GetLevelTabsClass.Create(Self);
  FNotifications := TList.Create;
  FViews := TList.Create;
  FChanges := TList.Create;
  FChangesStack := TList.Create;
  FTabStop := True;
  Levels := GetLevelsClass.Create(nil);
  CreateHandlers;
  Width := 250;
  Height := 200;
end;

destructor TcxCustomGrid.Destroy;

  procedure HideRootViews;
  var
    I: Integer;
  begin
    for I := 0 to Levels.VisibleCount - 1 do
      with Levels.VisibleItems[I] do
        if GridView <> nil then GridView.ViewInfo.DoVisibilityChanged(False);
  end;

begin
  HideRootViews;
  //Levels := nil;
  DestroyHandlers;
  Levels := nil;
  DestroyViews;
  FViews.Free;
  FreeAndNil(FNotifications);
  FreeAndNil(FLevelTabs);
  DestroyChanges(FChangesStack);
  FreeAndNil(FChangesStack);
  FreeAndNil(FChanges);
  inherited;
end;

function TcxCustomGrid.GetActiveView: TcxCustomGridView;
begin
  if FActiveLevel = nil then
    Result := nil
  else
    Result := FActiveLevel.GridView;
end;

function TcxCustomGrid.GetFocusedViewNavigator: IcxNavigator;
begin
  if (FocusedView = nil) or not Supports(FocusedView, IcxNavigator) then
    Result := nil
  else
    Result := FocusedView as IcxNavigator;
end;

function TcxCustomGrid.GetView(Index: Integer): TcxCustomGridView;
begin
  Result := TcxCustomGridView(FViews[Index]);
end;

function TcxCustomGrid.GetViewCount: Integer;
begin
  Result := FViews.Count;
end;

function TcxCustomGrid.GetRootLevelOptions: TcxGridLevelOptions;
begin
  Result := FLevels.Options;
end;

function TcxCustomGrid.GetRootLevelStyles: TcxGridLevelStyles;
begin
  Result := FLevels.Styles;
end;

function TcxCustomGrid.GetStructureNavigator: TcxCustomGridStructureNavigator;
begin
  CreateStructureNavigator;
  Result := FStructureNavigator;
end;

function TcxCustomGrid.GetUpdateLocked: Boolean;
{
  function DataControllerLocked: Boolean;                    //!!!!!!!!!!!!!!!!!!!!
  var
    I, J: Integer;

    function CheckDataController(AView: TcxCustomGridView; out ALocked: Boolean): Boolean;
    begin
      ALocked := AView.DataController.LockCount <> 0;
      Result := ALocked;
    end;

  begin
    for I := 0 to ViewCount - 1 do
    begin
      if CheckDataController(Views[I], Result) then Exit;
      for J := 0 to Views[I].CloneCount - 1 do
        if CheckDataController(Views[I].Clones[J], Result) then Exit;
    end;
    Result := False;
  end;
}
begin
  Result := (FUpdateLockCount <> 0) {or DataControllerLocked};
end;

procedure TcxCustomGrid.SetActiveLevel(Value: TcxGridLevel);
begin
  if FActiveLevel <> Value then
  begin
    if Value = nil then
      Value := FLevels.GetAvailableItem
    else
      if not Value.Visible then
        Exit;
    FActiveLevel := Value;
    SizeChanged;
    if not IsLoading and (FActiveLevel <> nil) then
      DoActiveTabChanged(FActiveLevel);
    if FActiveLevel <> nil then
      FocusedView := FActiveLevel.GridView
    else
      FocusedView := nil;
  end;
end;

procedure TcxCustomGrid.SetDragOpeningWaitTime(Value: Integer);
begin
  if Value < 0 then Value := 0;
  FDragOpeningWaitTime := Value;
end;

procedure TcxCustomGrid.SetFocusedView(Value: TcxCustomGridView);
var
  APrevFocusedView: TcxCustomGridView;
  APrevFocused: Boolean;

  function GetAvailableView: TcxCustomGridView;
  var
    I: Integer;

    function CheckMasterView(AView: TcxCustomGridView): TcxCustomGridView;
    begin
      Result := AView;
      repeat
        Result := Result.MasterGridView;
      until (Result = nil) or not Result.IsDestroying;
    end;

  begin
    Result := CheckMasterView(FFocusedView);
    if Result = nil then
    begin
      for I := 0 to Levels.Count - 1 do
      begin
        Result := Levels[I].GridView;
        if (Result <> nil) and not Result.IsDestroying then Exit;
      end;
      Result := nil;
    end;
  end;

begin
  if (Value <> nil) and not TcxCustomGridViewAccess.CanFocus(Value) then Exit;
  if FFocusedView <> Value then
  begin
    APrevFocusedView := FFocusedView;
    if not IsDestroying and not IsDesigning and
      ((Value = nil) and (ActiveLevel <> nil) and (ActiveLevel.GridView <> nil) or
       (Value <> nil) and Value.IsDestroying) then
      Value := GetAvailableView;
    FFocusedView := Value;
    if APrevFocusedView <> nil then
    begin
      APrevFocused := IsFocused;
      try
        TcxCustomGridViewAccess.FocusChanged(APrevFocusedView, False);
      except
        FocusedView := APrevFocusedView;
        raise;
      end;
      if APrevFocused and not IsFocused then
        SetFocus;
    end;
    if FFocusedView <> nil then
    begin
      TcxCustomGridViewAccess.FocusChanged(FFocusedView, True);
      TcxGridLevel(FFocusedView.Level).Active := True;
    end
    else
      if IsFocused and CanFocusEx then
        SetFocus;
    FocusedViewChanged(APrevFocusedView, FFocusedView);
  end;
end;

procedure TcxCustomGrid.SetLevels(Value: TcxGridLevel);
begin
  FLevels.Free;
  FLevels := Value;
  if FLevels <> nil then
    FLevels.Control := Self;
end;

procedure TcxCustomGrid.SetLevelTabs(Value: TcxGridLevelTabs);
begin
  FLevelTabs.Assign(Value);
end;

procedure TcxCustomGrid.SetRootLevelOptions(Value: TcxGridLevelOptions);
begin
end;

procedure TcxCustomGrid.SetRootLevelStyles(Value: TcxGridLevelStyles);
begin
end;

procedure TcxCustomGrid.SetTabStop(Value: Boolean);
begin
  if FTabStop <> Value then
  begin
    FTabStop := Value;
    if FocusedView <> nil then
      FocusedView.TabStop := FTabStop;
  end;
end;

procedure TcxCustomGrid.AddView(AView: TcxCustomGridView);
begin
  FViews.Add(AView);
  AView.DataController.SetMasterMode(nil, True);
end;

procedure TcxCustomGrid.RemoveView(AView: TcxCustomGridView);
begin
  FViews.Remove(AView);
  DestroyViewChanges(AView);
  //ViewChanged(AView, vsRemoved);
end;

procedure TcxCustomGrid.DestroyViews;
var
  I: Integer;
begin
  for I := ViewCount - 1 downto 0 do
    Views[I].Free;
end;

procedure TcxCustomGrid.DestroyChanges(AChanges: TList);
var
  I: Integer;
begin
  for I := 0 to AChanges.Count - 1 do
    TObject(AChanges[I]).Free;
  AChanges.Clear;
end;

procedure TcxCustomGrid.DestroyViewChanges(AView: TcxCustomGridView);

  procedure ClearViewChanges(AChanges: TList);
  var
    I: Integer;
  begin
    for I := AChanges.Count - 1 downto 0 do
      if (TcxCustomGridChange(AChanges[I]) is TcxCustomGridViewChange) and
        (TcxCustomGridViewChange(AChanges[I]).GridView = AView) then
      begin
        TObject(AChanges[I]).Free;
        AChanges.Delete(I);
      end;
  end;

begin
  ClearViewChanges(FChanges);
  ClearViewChanges(FChangesStack);
end;

procedure TcxCustomGrid.CreateStructureNavigator;
begin
  if (FStructureNavigator = nil) and
    IsDesigning and (cxGridStructureNavigatorClass <> nil) and
    (FController <> nil) and not FCreatingStructureNavigator then
  begin
    FCreatingStructureNavigator := True;
    try
      FStructureNavigator := cxGridStructureNavigatorClass.Create(Self);
    finally
      FCreatingStructureNavigator := False;
    end;
  end;
end;

{procedure TcxCustomGrid.CMDeferUpdates(var Message: TMessage);
begin
  DoProcessChangesStack;
end;}

procedure TcxCustomGrid.CMDialogChar(var Message: TCMDialogChar);
begin
  if TcxGridTopDetailsSiteViewInfo(ViewInfo.DetailsSiteViewInfo).ProcessDialogChar(Message.CharCode) then
    Message.Result := 1
  else
    inherited;
end;

function TcxCustomGrid.NavigatorIsActive: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.IsActive;
end;

function TcxCustomGrid.NavigatorIsBof: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.IsBof;
end;

function TcxCustomGrid.NavigatorIsEof: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.IsEof;
end;

function TcxCustomGrid.NavigatorCanAppend: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.CanAppend;
end;

function TcxCustomGrid.NavigatorCanEdit: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.CanEdit;
end;

function TcxCustomGrid.NavigatorCanDelete: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.CanDelete;
end;

function TcxCustomGrid.NavigatorCanInsert: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.CanInsert;
end;

function TcxCustomGrid.NavigatorIsEditing: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.IsEditing;
end;

procedure TcxCustomGrid.NavigatorClearBookmark;
begin
  if FocusedViewNavigator <> nil then
    FocusedViewNavigator.ClearBookmark;
end;

function TcxCustomGrid.NavigatorIsBookmarkAvailable: Boolean;
begin
  if FocusedViewNavigator = nil then
    Result := False
  else
    Result := FocusedViewNavigator.IsBookmarkAvailable;
end;

procedure TcxCustomGrid.NavigatorDoAction(AButtonIndex: Integer);
begin
  if FocusedViewNavigator <> nil then
    FocusedViewNavigator.DoAction(AButtonIndex);
end;

function TcxCustomGrid.NavigatorGetNotifier: TcxNavigatorControlNotifier;
begin
  Result := FNavigatorNotifier;
end;

function TcxCustomGrid.NavigatorIsActionSupported(AButtonIndex: Integer): Boolean;
begin
  Result := True;
end;

procedure TcxCustomGrid.AddChildComponent(AComponent: TcxControlChildComponent);
begin
  inherited;
  if AComponent is TcxCustomGridView then
    AddView(TcxCustomGridView(AComponent));
end;

procedure TcxCustomGrid.RemoveChildComponent(AComponent: TcxControlChildComponent);
begin
  inherited;
  if AComponent is TcxCustomGridView then
    RemoveView(TcxCustomGridView(AComponent));

⌨️ 快捷键说明

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