📄 jvqoutlookbar.pas
字号:
public
constructor CreateInternal(AOwner: TComponent; AParent: TWinControl; AObject: TObject);
destructor Destroy; override;
procedure ShowEdit(const AText: string; R: TRect);
property Canvas: TCanvas read GetCanvas;
end;
constructor TJvOutlookBarEdit.CreateInternal(AOwner: TComponent;
AParent: TWinControl; AObject: TObject);
begin
inherited Create(AOwner);
FCanvas := TControlCanvas.Create;
FCanvas.Control := Self;
AutoSize := True;
Visible := False;
Parent := AParent;
BorderStyle := bsNone;
ParentFont := False;
Tag := Integer(AObject);
end;
destructor TJvOutlookBarEdit.Destroy;
begin
inherited Destroy;
// (rom) destroy Canvas AFTER inherited Destroy
FCanvas.Free;
end;
procedure TJvOutlookBarEdit.EditAccept;
begin
Perform(Parent, CM_CAPTION_EDIT_ACCEPT, Integer(Self), Tag);
Hide;
end;
procedure TJvOutlookBarEdit.EditCancel;
begin
Perform(Parent, CM_CAPTION_EDIT_CANCEL, Integer(Self), Tag);
Hide;
end;
function TJvOutlookBarEdit.GetCanvas: TCanvas;
begin
Result := FCanvas;
end;
procedure TJvOutlookBarEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
case Key of
VK_RETURN:
begin
Key := 0;
EditAccept;
if Handle = GetCapture then
ReleaseCapture;
// Hide;
// Free;
// Screen.Cursor := crDefault;
end;
VK_ESCAPE:
begin
Key := 0;
if Handle = GetCapture then
ReleaseCapture;
EditCancel;
// Hide;
// Free;
// Screen.Cursor := crDefault;
end;
end;
inherited KeyDown(Key, Shift);
end;
procedure TJvOutlookBarEdit.KeyPress(var Key: Char);
begin
if Key = Cr then
Key := #0; // remove beep
inherited KeyPress(Key);
end;
procedure TJvOutlookBarEdit.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if not PtInRect(ClientRect, Point(X, Y)) or ((Button = mbRight) and Visible) then
begin
if Handle = GetCapture then
ReleaseCapture;
EditCancel;
// Screen.Cursor := crDefault;
// FEdit.Hide;
// FEdit.Free;
// FEdit := nil;
end
else
begin
ReleaseCapture;
// Screen.Cursor := crIBeam;
SetCapture(Handle);
end;
end;
procedure TJvOutlookBarEdit.ShowEdit(const AText: string; R: TRect);
begin
Hide;
Text := AText;
SetBounds(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
Show;
SetCapture(Handle);
SelStart := 0;
SelLength := Length(Text);
SetFocus;
end;
//=== { TJvRepeatButton } ====================================================
type
// auto-repeating button using a timer (stolen from Borland's Spin.pas sample component)
TJvRepeatButton = class(TJvExSpeedButton)
private
FRepeatTimer: TTimer;
procedure TimerExpired(Sender: TObject);
protected
procedure VisibleChanged; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
public
destructor Destroy; override;
end;
procedure TJvRepeatButton.VisibleChanged;
begin
inherited VisibleChanged;
if not Visible then
FreeAndNil(FRepeatTimer);
end;
destructor TJvRepeatButton.Destroy;
begin
inherited Destroy;
end;
procedure TJvRepeatButton.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if FRepeatTimer = nil then
FRepeatTimer := TTimer.Create(Self);
FRepeatTimer.OnTimer := TimerExpired;
FRepeatTimer.Interval := cInitRepeatPause;
FRepeatTimer.Enabled := True;
end;
procedure TJvRepeatButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
FreeAndNil(FRepeatTimer);
end;
procedure TJvRepeatButton.TimerExpired(Sender: TObject);
begin
FRepeatTimer.Interval := cRepeatPause;
if (FState = bsDown) and MouseCapture then
try
Click;
except
FRepeatTimer.Enabled := False;
raise;
end;
end;
//=== { TJvOutlookBarButtonActionLink } ======================================
procedure TJvOutlookBarButtonActionLink.AssignClient(AClient: TObject);
begin
Client := AClient as TJvOutlookBarButton;
end;
function TJvOutlookBarButtonActionLink.IsCaptionLinked: Boolean;
begin
Result := inherited IsCaptionLinked and
(Client.Caption = (Action as TCustomAction).Caption);
end;
function TJvOutlookBarButtonActionLink.IsEnabledLinked: Boolean;
begin
Result := inherited IsEnabledLinked and
(Client.Enabled = (Action as TCustomAction).Enabled);
end;
function TJvOutlookBarButtonActionLink.IsImageIndexLinked: Boolean;
begin
Result := inherited IsImageIndexLinked and
(Client.ImageIndex = (Action as TCustomAction).ImageIndex);
end;
function TJvOutlookBarButtonActionLink.IsOnExecuteLinked: Boolean;
begin
Result := inherited IsOnExecuteLinked and
MethodsEqual(TMethod(Client.OnClick), TMethod(Action.OnExecute));
end;
procedure TJvOutlookBarButtonActionLink.SetCaption(const Value: TCaption);
begin
if IsCaptionLinked then
Client.Caption := Value;
end;
procedure TJvOutlookBarButtonActionLink.SetEnabled(Value: Boolean);
begin
if IsEnabledLinked then
Client.Enabled := Value;
end;
procedure TJvOutlookBarButtonActionLink.SetImageIndex(Value: Integer);
begin
if IsImageIndexLinked then
Client.ImageIndex := Value;
end;
procedure TJvOutlookBarButtonActionLink.SetOnExecute(Value: TNotifyEvent);
begin
if IsOnExecuteLinked then
Client.OnClick := Value;
end;
//=== { TJvOutlookBarButton } ================================================
constructor TJvOutlookBarButton.Create(Collection: TCollection);
begin
inherited Create(Collection);
FEnabled := True;
end;
destructor TJvOutlookBarButton.Destroy;
var
OBPage: TJvOutlookBarPage;
OB: TJvOutlookBar;
begin
OBPage := TJvOutlookBarPage(TJvOutlookBarButtons(Self.Collection).Owner);
OB := TJvOutlookBar(TJvOutlookBarPages(OBPage.Collection).Owner);
if Assigned(OB) then
begin
if OB.FPressedButtonIndex = Index then
OB.FPressedButtonIndex := -1;
if OB.FLastButtonIndex = Index then
OB.FLastButtonIndex := -1;
OB.Invalidate;
end;
inherited Destroy;
end;
procedure TJvOutlookBarButton.Assign(Source: TPersistent);
begin
if Source is TJvOutlookBarButton then
begin
Caption := TJvOutlookBarButton(Source).Caption;
ImageIndex := TJvOutlookBarButton(Source).ImageIndex;
Down := TJvOutlookBarButton(Source).Down;
AutoToggle := TJvOutlookBarButton(Source).AutoToggle;
Tag := TJvOutlookBarButton(Source).Tag;
Enabled := TJvOutlookBarButton(Source).Enabled;
Change;
end
else
inherited Assign(Source);
end;
procedure TJvOutlookBarButton.Change;
begin
if (Collection <> nil) and (TJvOutlookBarButtons(Collection).Owner <> nil) and
(TCollectionItem(TJvOutlookBarButtons(Collection).Owner).Collection <> nil) and
(TCustomControl(TJvOutlookBarPages(TCollectionItem(TJvOutlookBarButtons(Collection).Owner).Collection).Owner) <> nil) then
TCustomControl(TJvOutlookBarPages(TCollectionItem(TJvOutlookBarButtons(Collection).Owner).Collection).Owner).Invalidate;
end;
procedure TJvOutlookBarButton.EditCaption;
begin
SendMessage(TCustomControl(TJvOutlookBarPages(TCollectionItem(TJvOutlookBarButtons(Collection).Owner).Collection).Owner).Handle,
CM_CAPTION_EDITING, Integer(Self), 0);
end;
function TJvOutlookBarButton.GetDisplayName: string;
begin
if Caption <> '' then
Result := Caption
else
Result := inherited GetDisplayName;
end;
procedure TJvOutlookBarButton.SetCaption(const Value: TCaption);
begin
if FCaption <> Value then
begin
FCaption := Value;
Change;
end;
end;
procedure TJvOutlookBarButton.SetImageIndex(const Value: TImageIndex);
begin
if FImageIndex <> Value then
begin
FImageIndex := Value;
Change;
end;
end;
procedure TJvOutlookBarButton.SetDown(const Value: Boolean);
var
I: Integer;
begin
if Value <> FDown then
begin
FDown := Value;
if FDown then
for I := 0 to TJvOutlookBarButtons(Collection).Count - 1 do
if TJvOutlookBarButtons(Collection).Items[I] <> Self then
TJvOutlookBarButtons(Collection).Items[I].Down := False;
Change;
end;
end;
procedure TJvOutlookBarButton.SetEnabled(const Value: Boolean);
begin
if FEnabled <> Value then
begin
FEnabled := Value;
Change;
end;
end;
procedure TJvOutlookBarButton.Click;
begin
if Assigned(FOnClick) then
FOnClick(Self);
end;
function TJvOutlookBarButton.GetAction: TBasicAction;
begin
if FActionLink <> nil then
Result := FActionLink.Action
else
Result := nil;
end;
function TJvOutlookBarButton.GetActionLinkClass: TJvOutlookBarButtonActionLinkClass;
begin
Result := TJvOutlookBarButtonActionLink;
end;
procedure TJvOutlookBarButton.ActionChange(Sender: TObject;
CheckDefaults: Boolean);
begin
if Sender is TCustomAction then
with TCustomAction(Sender) do
begin
if not CheckDefaults or (Self.Caption = '') then
Self.Caption := Caption;
if not CheckDefaults or Self.Enabled then
Self.Enabled := Enabled;
if not CheckDefaults or (Self.ImageIndex = -1) then
Self.ImageIndex := ImageIndex;
if not CheckDefaults or not Assigned(Self.OnClick) then
Self.OnClick := OnExecute;
end;
end;
procedure TJvOutlookBarButton.DoActionChange(Sender: TObject);
begin
if Sender = Action then
ActionChange(Sender, False);
end;
type
THackOwnedCollection = class(TOwnedCollection);
procedure TJvOutlookBarButton.SetAction(Value: TBasicAction);
begin
if Value = nil then
begin
FActionLink.Free;
FActionLink := nil;
end
else
begin
if FActionLink = nil then
FActionLink := GetActionLinkClass.Create(Self);
FActionLink.Action := Value;
FActionLink.OnChange := DoActionChange;
ActionChange(Value, csLoading in Value.ComponentState);
if GetOutlookBar <> nil then
Value.FreeNotification(GetOutlookBar); // delegates notification to owner!
end;
end;
function TJvOutlookBarButton.GetOutlookBar: TJvCustomOutlookBar;
begin
if TJvOutlookBarButtons(Collection).Owner is TJvOutlookBarPage then
Result := TJvOutlookBarPage(TJvOutlookBarButtons(Collection).Owner).GetOutlookBar
else
Result := nil;
end;
//=== { TJvOutlookBarButtons } ===============================================
constructor TJvOutlookBarButtons.Create(AOwner: TPersistent);
begin
inherited Create(AOwner, TJvOutlookBarButton);
end;
function TJvOutlookBarButtons.Add: TJvOutlookBarButton;
begin
Result := TJvOutlookBarButton(inherited Add);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -