cxnavigator.pas

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

PAS
1,873
字号
end;

procedure TcxNavigatorViewInfo.UpdateSelected;
var
  AIsSelected: Boolean;
  ANavigatorControl: TWinControl;
  R1, R2: TRect;
begin
  if not Navigator.GetNavigatorLookAndFeel.Painter.IsButtonHotTrack then
    Exit;
  ANavigatorControl := Navigator.GetNavigatorControl;
  AIsSelected := (HotTrackButtonViewInfo <> nil) or (PressedButtonViewInfo <> nil) or
    Navigator.GetNavigatorFocused;
  if (AIsSelected <> FIsSelected) and ANavigatorControl.HandleAllocated then
  begin
    FIsSelected := AIsSelected;
    R1 := Navigator.GetNavigatorBounds;
    R2 := R1;
    InflateRect(R2, -1, -1);
    InternalInvalidate(ANavigatorControl.Handle, R1, R2, False);
  end;
end;

{ TcxCustomNavigator }

constructor TcxCustomNavigator.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csAcceptsControls, csSetCaption] + [csOpaque];
  FButtons := CreateButtons;
  FViewInfo := GetViewInfoClass.Create(Self, False);
  TabStop := False;
  Height := 25;
end;

destructor TcxCustomNavigator.Destroy;
begin
  EndMouseTracking(Self);
  FreeAndNil(FViewInfo);
  FreeAndNil(FButtons);
  inherited Destroy;
end;

procedure TcxCustomNavigator.ClickButton(Index: Integer);
begin
  CustomButtons.ClickButton(Index);
end;

procedure TcxCustomNavigator.RestoreButtons;
var
  I: Integer;
begin
  with CustomButtons do
    for I := 0 to ButtonCount - 1 do
      FButtons[I].FIsVisibleAssigned := False;
  InitButtons;
end;

function TcxCustomNavigator.CanFocusOnClick: Boolean;
begin
  Result := inherited CanFocusOnClick and TabStop;
end;

function TcxCustomNavigator.CanResize(var NewWidth, NewHeight: Integer): Boolean;
begin
  Result := inherited CanResize(NewWidth, NewHeight);
  if Result and (FViewInfo <> nil) and HandleAllocated then
    FViewInfo.CheckSize(NewWidth, NewHeight);
end;

function TcxCustomNavigator.CreateButtons: TcxCustomNavigatorButtons;
begin
  Result := TcxCustomNavigatorButtons.Create(Self);
end;

procedure TcxCustomNavigator.Paint;
begin
  FViewInfo.Paint;
end;

procedure TcxCustomNavigator.DoEnter;
begin
  inherited DoEnter;
  FViewInfo.DoEnter;
end;

procedure TcxCustomNavigator.DoExit;
begin
  inherited DoExit;
  FViewInfo.DoExit;
end;

procedure TcxCustomNavigator.EnabledChanged;
begin
  RefreshNavigator;
end;

procedure TcxCustomNavigator.KeyDown(var Key: Word; Shift: TShiftState);
begin
  inherited KeyDown(Key, Shift);
  if (Key = VK_LEFT) or (Key = VK_RIGHT) then
    FViewInfo.PressArrowKey(Key = VK_LEFT);
  if (Key = VK_SPACE) and (FViewInfo.FocusedButton <> nil)
    and FViewInfo.FocusedButton.Enabled then
    FViewInfo.FocusedButton.Button.DoClick;
end;

procedure TcxCustomNavigator.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseDown(Button, Shift, X, Y);
  if Button = mbLeft then
    FViewInfo.MouseDown(X, Y);
end;

procedure TcxCustomNavigator.MouseEnter(AControl: TControl);
begin
  inherited MouseEnter(AControl);
{$IFDEF DELPHI7}
  if IsDesigning then
    Exit;
{$ENDIF}
  BeginMouseTracking(Self, Bounds, Self);
end;

procedure TcxCustomNavigator.MouseLeave(AControl: TControl);
begin
  inherited MouseLeave(AControl);
{$IFDEF DELPHI7}
  if IsDesigning then
    Exit;
{$ENDIF}
  EndMouseTracking(Self);
  FViewInfo.MouseMove(-1, -1);
end;

procedure TcxCustomNavigator.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseMove(Shift, X, Y);
  FViewInfo.MouseMove(X, Y);
  BeginMouseTracking(Self, Bounds, Self);
end;

procedure TcxCustomNavigator.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseUp(Button, Shift, X, Y);
  FViewInfo.MouseUp(X, Y);
end;

procedure TcxCustomNavigator.LookAndFeelChanged(Sender: TcxLookAndFeel;
  AChangedValues: TcxLookAndFeelValues);
begin
  inherited LookAndFeelChanged(Sender, AChangedValues);
  RecreateWnd
end;

procedure TcxCustomNavigator.NavigatorMouseLeave;
begin
  FViewInfo.MouseMove(-1, -1);
//  FViewInfo.FHintWindow.Free;
//  FViewInfo.FHintWindow := THintWindow.Create(nil);
end;

procedure TcxCustomNavigator.NavigatorChanged(AChangeType: TcxNavigatorChangeType);
begin
end;

function TcxCustomNavigator.GetNavigatorBounds: TRect;
begin
  Result := Rect(0, 0, ClientWidth, ClientHeight);
end;

function TcxCustomNavigator.GetNavigatorButtons: TcxCustomNavigatorButtons;
begin
  Result := CustomButtons;
end;

function TcxCustomNavigator.GetNavigatorCanvas: TCanvas;
begin
  Result := Canvas.Canvas;
end;

function TcxCustomNavigator.GetNavigatorControl: TWinControl;
begin
  Result := Self;
end;

function TcxCustomNavigator.GetNavigatorLookAndFeel: TcxLookAndFeel;
begin
  Result := LookAndFeel;
end;

function TcxCustomNavigator.GetNavigatorFocused: Boolean;
begin
  Result := Focused;
end;

function TcxCustomNavigator.GetNavigatorShowHint: Boolean;
begin
  Result := ShowHint;
end;

function TcxCustomNavigator.GetNavigatorTabStop: Boolean;
begin
  Result := TabStop;
end;

function TcxCustomNavigator.GetViewInfoClass: TcxNavigatorViewInfoClass;
begin
  Result := TcxNavigatorViewInfo;
end;

procedure TcxCustomNavigator.InitButtons;
var
  I: Integer;
begin
  for I := 0 to FButtons.ButtonCount - 1 do
    FButtons[I].RestoreDefaultVisible(True);
end;

function TcxCustomNavigator.GetNavigatorOwner: TComponent;
begin
  Result := Self;
end;

procedure TcxCustomNavigator.NavigatorButtonsStateChanged;
begin
  FViewInfo.UpdateButtonsEnabled;
end;

procedure TcxCustomNavigator.RefreshNavigator;
var
  AWidth, AHeight: Integer;
begin
  if not HandleAllocated then
    Exit;
  AWidth := Width;
  AHeight := Height;
  FViewInfo.CheckSize(AWidth, AHeight);
  if (AWidth <> Width) or (Height <> AHeight) then
    SetBounds(Left, Top, AWidth, AHeight)
  else
    Invalidate;
end;

procedure TcxCustomNavigator.CreateWnd;
begin
  inherited CreateWnd;
  RefreshNavigator;
end;

procedure TcxCustomNavigator.WndProc(var Message: TMessage);
begin
  if (FViewInfo <> nil) and (FViewInfo.FHintWindowShowing) then
    with Message do
      if ((Msg >= WM_KEYFIRST) and (Msg <= WM_KEYLAST)) or
        ((Msg = CM_ACTIVATE) or (Msg = CM_DEACTIVATE)) or
        (Msg = CM_APPKEYDOWN) or (Msg = CM_APPSYSCOMMAND) or
        (Msg = WM_COMMAND) or ((Msg > WM_MOUSEMOVE) and
        (Msg <= WM_MOUSELAST)) or (Msg = WM_NCMOUSEMOVE) then
         FViewInfo.HintActivate(False);
  inherited WndProc(Message);
end;

procedure TcxCustomNavigator.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  Message.Result := DLGC_WANTARROWS;
end;

procedure TcxCustomNavigator.CMEnabledChanged(var Message: TMessage);
begin
  inherited;
  EnabledChanged;
end;

procedure TcxCustomNavigator.CMHintShow(var Message: TCMHintShow);
begin
  Message.Result := 1;
end;

{ TcxNavigatorControlNotifier }

constructor TcxNavigatorControlNotifier.Create;
begin
  inherited Create;
  FList := TList.Create;
end;

destructor TcxNavigatorControlNotifier.Destroy;
begin
  FreeAndNil(FList);
  inherited Destroy;
end;

procedure TcxNavigatorControlNotifier.AddNavigator(ANavigator: IcxNavigatorOwner);
begin
  if FList.IndexOf(Pointer(ANavigator)) < 0 then
    FList.Add(Pointer(ANavigator));
end;

procedure TcxNavigatorControlNotifier.RemoveNavigator(ANavigator: IcxNavigatorOwner);
begin
  FList.Remove(Pointer(ANavigator));
end;

procedure TcxNavigatorControlNotifier.RefreshNavigatorButtons;
var
  I: Integer;
begin
  for I := 0 to FList.Count - 1 do
    IcxNavigatorOwner(FList[I]).NavigatorButtonsStateChanged;
end;

{ TcxNavigatorControlButtons }
procedure TcxNavigatorControlButtons.ReleaseBookmark;
var
  ANavigatorControl: IcxNavigator;
begin
  ANavigatorControl := Control;
  if (ANavigatorControl <> nil) and ANavigatorControl.IsBookmarkAvailable then
    ANavigatorControl.ClearBookmark;
end;

function TcxNavigatorControlButtons.GetControl: IcxNavigator;
begin
  if Assigned(FOnGetControl) then
    Result := FOnGetControl
  else
    Result := nil;
end;

procedure TcxNavigatorControlButtons.DoButtonClick(ADefaultIndex: Integer);
var
  ANavigatorControl: IcxNavigator;
begin
  ANavigatorControl := Control;
  if ANavigatorControl <> nil then
    ANavigatorControl.DoAction(ADefaultIndex);
  FNavigator.NavigatorButtonsStateChanged;
end;

function TcxNavigatorControlButtons.GetButtonEnabled(ADefaultIndex: Integer): Boolean;
var
  ANavigatorControl: IcxNavigator;
begin
  ANavigatorControl := Control;
  Result := (ANavigatorControl <> nil) and IsNavigatorEnabled and
    (ANavigatorControl.IsActive or (ADefaultIndex = NBDI_FILTER));
  if Result then
    case ADefaultIndex of
      NBDI_FIRST, NBDI_PRIOR, NBDI_PRIORPAGE:
        Result := not ANavigatorControl.IsBof;
      NBDI_LAST, NBDI_NEXT, NBDI_NEXTPAGE:
        Result := not ANavigatorControl.IsEof;
      NBDI_INSERT:
        Result := ANavigatorControl.CanInsert;
      NBDI_APPEND:
        Result := ANavigatorControl.CanAppend;
      NBDI_DELETE:
        Result := ANavigatorControl.CanDelete;
      NBDI_EDIT:
        Result := ANavigatorControl.CanEdit and not ANavigatorControl.IsEditing;
      NBDI_POST, NBDI_CANCEL:
        Result := ANavigatorControl.IsEditing;
      NBDI_GOTOBOOKMARK:
        Result := ANavigatorControl.IsBookmarkAvailable;
    end;
end;

{ TcxCustomNavigatorControl }

destructor TcxCustomNavigatorControl.Destroy;
begin
  Control := nil;
  inherited Destroy;
end;

function TcxCustomNavigatorControl.CreateButtons: TcxCustomNavigatorButtons;
begin
  Result := GetButtonsClass.Create(Self);
  TcxNavigatorControlButtons(Result).OnGetControl := GetControl;
end;

function TcxCustomNavigatorControl.GetButtonsClass: TcxNavigatorControlButtonsClass;
begin
  Result := TcxNavigatorControlButtons;
end;

procedure TcxCustomNavigatorControl.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (AComponent = Control) then
    Control := nil;
end;

procedure TcxCustomNavigatorControl.InitButtons;
var
  ANavigator: IcxNavigator;
  I: Integer;
begin
  if FControl = nil then
  begin
    for I := 0 to FButtons.ButtonCount - 1 do
      FButtons[I].RestoreDefaultVisible(True);
  end
  else
  begin
    Supports(FControl, IcxNavigator, ANavigator);
    for I := 0 to FButtons.ButtonCount - 1 do
      FButtons[I].RestoreDefaultVisible(ANavigator.IsActionSupported(FButtons[I].DefaultIndex));
  end;
end;

function TcxCustomNavigatorControl.GetButtons: TcxNavigatorControlButtons;
begin
  Result := TcxNavigatorControlButtons(CustomButtons);
end;

function TcxCustomNavigatorControl.GetControl: IcxNavigator;
begin
  if Control <> nil then
    Supports(Control, IcxNavigator, Result)
  else
    Result := nil;
end;

procedure TcxCustomNavigatorControl.SetButtons(Value: TcxNavigatorControlButtons);
begin
  CustomButtons.Assign(Value);
end;

procedure TcxCustomNavigatorControl.SetControl(Value: TComponent);
var
  ANavigator: IcxNavigator;
begin
  if (Value <> FControl) and ((Value = nil) or Supports(Value, IcxNavigator,
    ANavigator)) then
  begin
    if FControl <> nil then
    begin
    {$IFDEF DELPHI5}
      FControl.RemoveFreeNotification(Self);
    {$ENDIF}
      Supports(FControl, IcxNavigator, ANavigator);
      if ANavigator.GetNotifier <> nil then
        ANavigator.GetNotifier.RemoveNavigator(Self);
    end;
    FControl := Value;
    if (FControl <> nil) then
    begin
      FControl.FreeNotification(Self);
      Supports(FControl, IcxNavigator, ANavigator);
      if ANavigator.GetNotifier <> nil then
        ANavigator.GetNotifier.AddNavigator(Self);
    end;
    InitButtons;
    RefreshNavigator;
  end;
end;

initialization

finalization
  FreeAndNil(FNavigatorImages);

end.

⌨️ 快捷键说明

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