cxnavigator.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,873 行 · 第 1/4 页
PAS
1,873 行
function NavigatorImages: TImageList;
implementation
uses
cxEditPaintUtils, cxEditUtils, cxEditConsts, dxThemeConsts, dxUxTheme, cxGeometry;
const
cxInitRepeatPause = 400;
cxRepeatPause = 100;
type
TCustomFormAccess = class(TCustomForm);
var
FNavigatorImages: TImageList = nil;
function NavigatorImages: TImageList;
procedure LoadImageListFromResource(AImageList: TCustomImageList;
const AResName: string; AMaskColor: TColor);
begin
AImageList.GetInstRes(HInstance, rtBitmap, AResName,
AImageList.Width, [], AMaskColor);
end;
begin
if FNavigatorImages = nil then
begin
FNavigatorImages := TImageList.Create(nil);
FNavigatorImages.Height := 11;
FNavigatorImages.Width := 12;
LoadImageListFromResource(FNavigatorImages, 'CXNAVIGATORBUTTONS', clOlive);
end;
Result := FNavigatorImages;
end;
{ TcxNavigatorButton }
constructor TcxNavigatorButton.Create(AButtons: TcxCustomNavigatorButtons;
ADefaultVisible: Boolean);
begin
inherited Create;
FButtons := AButtons;
FDefaultIndex := -1;
FDefaultVisible := ADefaultVisible;
FEnabled := True;
FImageIndex := -1;
FVisible := ADefaultVisible;
end;
function TcxNavigatorButton.GetOwner: TPersistent;
begin
Result := FButtons;
end;
procedure TcxNavigatorButton.Assign(Source: TPersistent);
begin
if Source is TcxNavigatorButton then
with Source as TcxNavigatorButton do
begin
Self.Enabled := Enabled;
Self.Hint := Hint;
Self.ImageIndex := ImageIndex;
Self.Visible := Visible;
Self.FIsVisibleAssigned := FIsVisibleAssigned;
Self.OnClick := OnClick;
end
else
inherited Assign(Source);
end;
procedure TcxNavigatorButton.Click;
begin
if GetInternalEnabled then
DoClick;
end;
function TcxNavigatorButton.GetInternalEnabled: Boolean;
begin
Result := Enabled;
if Result then
Result := Buttons.GetButtonEnabled(DefaultIndex);
end;
function TcxNavigatorButton.GetInternalHint: string;
begin
Result := Hint;
if Hint = '' then
Result := Buttons.GetButtonHint(DefaultIndex);
end;
function TcxNavigatorButton.IsUserImageListUsed: Boolean;
begin
Result := (Buttons.Images <> nil) and (ImageIndex > -1);
end;
procedure TcxNavigatorButton.DoClick;
var
ADone: Boolean;
begin
if Assigned(OnClick) then
OnClick(Self)
else
begin
ADone := False;
if Assigned(Buttons.FOnButtonClick) then
Buttons.FOnButtonClick(Buttons, DefaultIndex, ADone);
if not ADone then
Buttons.DoButtonClick(DefaultIndex);
end;
end;
procedure TcxNavigatorButton.RestoreDefaultVisible(ACanBeVisible: Boolean);
begin
if not FIsVisibleAssigned then
InternalSetVisible(FDefaultVisible and ACanBeVisible);
end;
function TcxNavigatorButton.GetImageSize: TSize;
var
APainter: TcxCustomLookAndFeelPainterClass;
begin
APainter := GetNavigator.GetNavigatorLookAndFeel.SkinPainter;
if (APainter = nil) or IsUserImageListUsed then
begin
Result.cx := InternalImages.Width;
Result.cy := InternalImages.Height;
end
else
Result := APainter.NavigatorGlyphSize;
end;
function TcxNavigatorButton.GetNavigator: IcxNavigatorOwner;
begin
Result := Buttons.Navigator;
end;
procedure TcxNavigatorButton.SetEnabled(const Value: Boolean);
begin
if Enabled <> Value then
begin
FEnabled := Value;
if Visible then
Navigator.RefreshNavigator;
Navigator.NavigatorChanged(nctLayout);
end;
end;
procedure TcxNavigatorButton.SetHint(const Value: string);
begin
if AnsiCompareStr(FHint, Value) <> 0 then
begin
FHint := Value;
Navigator.NavigatorChanged(nctProperties);
end;
end;
function TcxNavigatorButton.GetInternalImageIndex: Integer;
begin
if (Buttons.Images <> nil) and (ImageIndex > -1) then
Result := ImageIndex
else
Result := DefaultIndex;
end;
function TcxNavigatorButton.GetIternalImages: TCustomImageList;
begin
if (Buttons.Images <> nil) and (ImageIndex > -1) then
Result := Buttons.Images
else
Result := Buttons.DefaultImages;
end;
procedure TcxNavigatorButton.InternalSetVisible(Value: Boolean;
AIsInternalSetting: Boolean = True);
begin
if not AIsInternalSetting then
FIsVisibleAssigned := True;
if FVisible <> Value then
begin
FVisible := Value;
Navigator.RefreshNavigator;
Navigator.NavigatorChanged(nctSize);
end;
end;
function TcxNavigatorButton.IsVisibleStored: Boolean;
begin
Result := FIsVisibleAssigned;
end;
procedure TcxNavigatorButton.SetImageIndex(Value: TImageIndex);
begin
if ImageIndex <> Value then
begin
FImageIndex := Value;
if Visible then
Navigator.RefreshNavigator;
Navigator.NavigatorChanged(nctLayout);
end;
end;
procedure TcxNavigatorButton.SetOnClick(const Value: TNotifyEvent);
begin
FOnClick := Value;
Navigator.NavigatorChanged(nctProperties);
end;
procedure TcxNavigatorButton.SetVisible(const Value: Boolean);
begin
InternalSetVisible(Value, False);
end;
{ TcxCustomNavigatorButtons }
constructor TcxCustomNavigatorButtons.Create(ANavigator: IcxNavigatorOwner);
begin
inherited Create;
FNavigator := ANavigator;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := ImageListChange;
CreateButtons;
FConfirmDelete := True;
end;
destructor TcxCustomNavigatorButtons.Destroy;
begin
FreeAndNil(FImageChangeLink);
DestroyButtons;
inherited Destroy;
end;
procedure TcxCustomNavigatorButtons.Assign(Source: TPersistent);
var
I: Integer;
begin
if Source is TcxCustomNavigatorButtons then
with TcxCustomNavigatorButtons(Source) do
begin
for I := 0 to ButtonCount - 1 do
Self.FButtons[I].Assign(FButtons[I]);
Self.ConfirmDelete := ConfirmDelete;
Self.Images := Images;
Self.OnButtonClick := OnButtonClick;
end
else
inherited Assign(Source);
end;
procedure TcxCustomNavigatorButtons.ClickButton(Index: Integer);
begin
Buttons[Index].Click;
end;
procedure TcxCustomNavigatorButtons.ReleaseBookmark;
begin
end;
procedure TcxCustomNavigatorButtons.CreateButtons;
function IsButtonVisibleByDefault(AIndex: Integer): Boolean;
begin
Result := AIndex <> NBDI_APPEND;
end;
var
I: Integer;
begin
for I := 0 to NavigatorButtonCount - 1 do
begin
FButtons[I] := TcxNavigatorButton.Create(Self, IsButtonVisibleByDefault(I));
FButtons[I].DefaultIndex := I;
end;
end;
function TcxCustomNavigatorButtons.GetOwner: TPersistent;
begin
Result := FNavigator.GetNavigatorOwner;
end;
procedure TcxCustomNavigatorButtons.DestroyButtons;
var
I: Integer;
begin
for I := 0 to NavigatorButtonCount - 1 do
FButtons[I].Free;
end;
procedure TcxCustomNavigatorButtons.DoButtonClick(ADefaultIndex: Integer);
begin
end;
function TcxCustomNavigatorButtons.GetButtonEnabled(ADefaultIndex: Integer): Boolean;
begin
Result := IsNavigatorEnabled;
end;
function TcxCustomNavigatorButtons.GetButtonHint(ADefaultIndex: Integer): string;
begin
case ADefaultIndex of
NBDI_FIRST: Result := cxGetResourceString(@cxNavigatorHint_First);
NBDI_PRIORPAGE: Result := cxGetResourceString(@cxNavigatorHint_PriorPage);
NBDI_PRIOR: Result := cxGetResourceString(@cxNavigatorHint_Prior);
NBDI_LAST: Result := cxGetResourceString(@cxNavigatorHint_Last);
NBDI_NEXT: Result := cxGetResourceString(@cxNavigatorHint_Next);
NBDI_NEXTPAGE: Result := cxGetResourceString(@cxNavigatorHint_NextPage);
NBDI_INSERT: Result := cxGetResourceString(@cxNavigatorHint_Insert);
NBDI_APPEND: Result := cxGetResourceString(@cxNavigatorHint_Append);
NBDI_DELETE: Result := cxGetResourceString(@cxNavigatorHint_Delete);
NBDI_EDIT: Result := cxGetResourceString(@cxNavigatorHint_Edit);
NBDI_POST: Result := cxGetResourceString(@cxNavigatorHint_Post);
NBDI_CANCEL: Result := cxGetResourceString(@cxNavigatorHint_Cancel);
NBDI_REFRESH: Result := cxGetResourceString(@cxNavigatorHint_Refresh);
NBDI_SAVEBOOKMARK: Result := cxGetResourceString(@cxNavigatorHint_SaveBookmark);
NBDI_GOTOBOOKMARK: Result := cxGetResourceString(@cxNavigatorHint_GotoBookmark);
NBDI_FILTER: Result := cxGetResourceString(@cxNavigatorHint_Filter);
else Result := '';
end;
end;
function TcxCustomNavigatorButtons.GetButtonImageOffset: Integer;
begin
Result := 2;
end;
function TcxCustomNavigatorButtons.IsNavigatorEnabled: Boolean;
begin
Result := Navigator.GetNavigatorControl.Enabled;
end;
function TcxCustomNavigatorButtons.GetButton(Index: Integer): TcxNavigatorButton;
begin
Result := FButtons[Index];
end;
function TcxCustomNavigatorButtons.GetButtonCount: Integer;
begin
Result := High(FButtons) - Low(FButtons) + 1;
end;
function TcxCustomNavigatorButtons.GetDefaultImages: TCustomImageList;
begin
Result := NavigatorImages;
end;
procedure TcxCustomNavigatorButtons.SetButton(Index: Integer; const Value: TcxNavigatorButton);
begin
FButtons[Index].Assign(Value);
end;
procedure TcxCustomNavigatorButtons.SetConfirmDelete(const Value: Boolean);
begin
if FConfirmDelete <> Value then
begin
FConfirmDelete := Value;
Navigator.NavigatorChanged(nctProperties);
end;
end;
procedure TcxCustomNavigatorButtons.SetImages(const Value: TCustomImageList);
begin
cxSetImageList(Value, FImages, FImageChangeLink, Navigator.GetNavigatorOwner);
Navigator.NavigatorChanged(nctLayout);
end;
procedure TcxCustomNavigatorButtons.SetOnButtonClick(
const Value: TcxNavigatorButtonClickEvent);
begin
FOnButtonClick := Value;
Navigator.NavigatorChanged(nctProperties);
end;
procedure TcxCustomNavigatorButtons.ImageListChange(Sender: TObject);
begin
Navigator.RefreshNavigator;
end;
{ TcxNavigatorViewInfo }
constructor TcxNavigatorViewInfo.Create(ANavigator: IcxNavigatorOwner;
AIsInplace: Boolean = True);
begin
inherited Create;
FNavigator := ANavigator;
FIsDirty := True;
FIsInplace := AIsInplace;
FButtons := TList.Create;
FHintWindowShowing := False;
FButtonPressTimer := TcxTimer.Create(nil);
FButtonPressTimer.Enabled := False;
FButtonPressTimer.OnTimer := DoButtonPressTimer;
FHintTimer := TcxTimer.Create(nil);
FHintTimer.Enabled := False;
FHintTimer.Interval := 500;
FHintTimer.OnTimer := DoHintTimer;
FCanvas := TcxCanvas.Create(nil);
end;
destructor TcxNavigatorViewInfo.Destroy;
begin
FreeAndNil(FCanvas);
FreeAndNil(FHintTimer);
FreeAndNil(FButtonPressTimer);
FreeAndNil(FHintWindow);
Clear;
FreeAndNil(FButtons);
inherited Destroy;
end;
procedure TcxNavigatorViewInfo.Calculate;
var
AHeight, AWidth: Integer;
I: Integer;
ANavigatorBounds: TRect;
begin
ANavigatorBounds := Navigator.GetNavigatorBounds;
with ANavigatorBounds do
begin
AWidth := Right - Left;
AHeight := Bottom - Top;
end;
CheckSize(AWidth, AHeight);
for I := 0 to ButtonCount - 1 do
begin
Buttons[I].Enabled := Buttons[I].Button.GetInternalEnabled;
Buttons[I].Hint := Buttons[I].Button.GetInternalHint;
end;
FIsDirty := False;
end;
procedure TcxNavigatorViewInfo.CheckSize(var AWidth, AHeight: Integer;
ACheckMinHeight: Boolean = False);
procedure CheckButtonCount;
var
APButtonViewInfo: TcxNavigatorButtonViewInfo;
AVisibleButtonCount, I: Integer;
begin
AVisibleButtonCount := GetVisibleButtonCount;
if AVisibleButtonCount < FButtons.Count then
for I := 1 to FButtons.Count - AVisibleButtonCount do
begin
TcxNavigatorButtonViewInfo(FButtons[AVisibleButtonCount]).Free;
FButtons.Delete(AVisibleButtonCount);
end
else
for I := FButtons.Count to AVisibleButtonCount - 1 do
begin
APButtonViewInfo := TcxNavigatorButtonViewInfo.Create;
FButtons.Add(APButtonViewInfo);
end;
end;
var
AButtonViewInfo: TcxNavigatorButtonViewInfo;
AButtonVisibleIndex: Integer;
AMinWidth, AMinHeight, ADifX: Integer;
AMinSize: TSize;
ANavigatorBounds, AButtonBounds: TRect;
ANavigatorButtons: TcxCustomNavigatorButtons;
AVisibleButtonCount: Integer;
I: Integer;
AHotTrackButton, APressedButton: TcxNavigatorButton;
begin
ANavigatorBounds := Navigator.GetNavigatorBounds;
FIsDirty := True;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?