📄 jvqxpbar.pas
字号:
procedure Click; override;
property Height default 46;
property VisibleItems: TJvXPBarVisibleItems read FVisibleItems;
property Width default 153;
procedure InitiateAction; override;
end;
TJvXPBar = class(TJvXPCustomWinXPBar)
published
property Caption;
property Collapsed;
property Colors;
property Items;
property RollImages;
property Font;
property Grouped;
property HeaderFont;
property HeaderHeight;
property HeaderRounded;
property HotTrack;
property HotTrackColor;
property OwnerDraw;
property Icon;
property ImageList;
property ItemHeight;
property RollDelay;
property RollMode;
property RollStep;
property ShowLinkCursor;
property ShowRollButton;
property ShowItemFrame;
property RoundedItemFrame;
property TopSpace;
property AfterCollapsedChange;
property BeforeCollapsedChange;
property OnCollapsedChange;
property OnCanChange;
property OnDrawItem;
property OnDrawBackground;
property OnDrawHeader;
property OnItemClick;
//property BevelInner;
//property BevelOuter;
//property BevelWidth;
//property BiDiMode;
//property Ctl3D;
//property DockSite;
//property ParentBiDiMode;
//property ParentCtl3D;
//property TabOrder;
//property TabStop;
//property UseDockManager default True;
property Align;
property Anchors;
//property AutoSize;
property Constraints;
property DragMode;
//property Enabled;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Visible;
//property OnDockDrop;
//property OnDockOver;
//property OnEndDock;
//property OnGetSiteInfo;
//property OnStartDock;
//property OnUnDock;
property OnClick;
property OnDblClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
procedure RoundedFrame(Canvas: TCanvas; ARect: TRect; AColor: TColor; R: Integer);
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
JvQJCLUtils, JvQResources,
QMenus;
{$IFDEF MSWINDOWS}
{$R ..\Resources\JvXPBar.res}
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
{$R ../Resources/JvXPBar.res}
{$ENDIF UNIX}
const
FC_HEADER_MARGIN = 6;
FC_ITEM_MARGIN = 8;
function SortByIndex(Item1, Item2: Pointer): Integer;
var
Idx1, Idx2: Integer;
begin
Idx1 := TCollectionItem(Item1).Index;
Idx2 := TCollectionItem(Item2).Index;
if Idx1 < Idx2 then
Result := -1
else
if Idx1 = Idx2 then
Result := 0
else
Result := 1;
end;
//=== { TJvXPBarItemActionLink } =============================================
procedure TJvXPBarItemActionLink.AssignClient(AClient: TObject);
begin
Client := AClient as TJvXPBarItem;
end;
function TJvXPBarItemActionLink.IsCaptionLinked: Boolean;
begin
Result := inherited IsCaptionLinked and
(Client.Caption = (Action as TCustomAction).Caption);
end;
function TJvXPBarItemActionLink.IsCheckedLinked: Boolean;
begin
Result := inherited IsCheckedLinked and
(Client.Checked = (Action as TCustomAction).Checked);
end;
function TJvXPBarItemActionLink.IsEnabledLinked: Boolean;
begin
Result := inherited IsEnabledLinked and
(Client.Enabled = (Action as TCustomAction).Enabled);
end;
function TJvXPBarItemActionLink.IsHintLinked: Boolean;
begin
Result := inherited IsHintLinked and
(Client.Hint = (Action as TCustomAction).Hint);
end;
function TJvXPBarItemActionLink.IsImageIndexLinked: Boolean;
begin
Result := inherited IsImageIndexLinked and
(Client.ImageIndex = (Action as TCustomAction).ImageIndex);
end;
function TJvXPBarItemActionLink.IsVisibleLinked: Boolean;
begin
Result := inherited IsVisibleLinked and
(Client.Visible = (Action as TCustomAction).Visible);
end;
function TJvXPBarItemActionLink.IsOnExecuteLinked: Boolean;
begin
Result := inherited IsOnExecuteLinked and
JvXPMethodsEqual(TMethod(Client.OnClick), TMethod(Action.OnExecute));
end;
procedure TJvXPBarItemActionLink.SetCaption(const Value: TCaption);
begin
if IsCaptionLinked then
Client.Caption := Value;
end;
procedure TJvXPBarItemActionLink.SetEnabled(Value: Boolean);
begin
if IsEnabledLinked then
Client.Enabled := Value;
end;
procedure TJvXPBarItemActionLink.SetChecked(Value: Boolean);
begin
if IsCheckedLinked then
Client.Checked := Value;
end;
procedure TJvXPBarItemActionLink.SetHint(const Value: WideString);
begin
if IsHintLinked then
Client.Hint := Value;
end;
procedure TJvXPBarItemActionLink.SetImageIndex(Value: Integer);
begin
if IsImageIndexLinked then
Client.ImageIndex := Value;
end;
procedure TJvXPBarItemActionLink.SetVisible(Value: Boolean);
begin
if IsVisibleLinked then
Client.Visible := Value;
end;
procedure TJvXPBarItemActionLink.SetOnExecute(Value: TNotifyEvent);
begin
if IsOnExecuteLinked then
Client.OnClick := Value;
end;
//===TJvXPBarItem ============================================================
constructor TJvXPBarItem.Create(Collection: TCollection);
begin
inherited Create(Collection);
FCollection := TJvXPBarItems(Collection);
FCaption := '';
FData := nil;
FDataObject := nil;
FEnabled := True;
FImageIndex := -1;
FImageList := nil;
FHint := '';
FName := '';
FWinXPBar := FCollection.FWinXPBar;
FTag := 0;
FVisible := True;
FChecked := False;
FGroupIndex := 0;
FWinXPBar.ItemVisibilityChanged(Self);
FWinXPBar.ResizeToMaxHeight;
end;
destructor TJvXPBarItem.Destroy;
begin
FVisible := False; // required to remove from visible list!
FWinXPBar.ItemVisibilityChanged(Self);
FActionLink.Free;
FActionLink := nil;
inherited Destroy;
FWinXPBar.ResizeToMaxHeight;
end;
procedure TJvXPBarItem.Notification(AComponent: TComponent);
begin
if AComponent = Action then
Action := nil;
if AComponent = FImageList then
FImageList := nil;
end;
function TJvXPBarItem.GetDisplayName: string;
var
DisplayName, ItemName: string;
begin
DisplayName := FCaption;
if DisplayName = '' then
DisplayName := RsUntitled;
ItemName := FName;
if ItemName <> '' then
DisplayName := DisplayName + ' [' + ItemName + ']';
if not FVisible then
DisplayName := DisplayName + '*';
Result := DisplayName;
end;
function TJvXPBarItem.GetImages: TCustomImageList;
begin
Result := nil;
if Assigned(FImageList) then
Result := FImageList
else
if Assigned(Action) and Assigned(TAction(Action).ActionList.Images) then
Result := TAction(Action).ActionList.Images
else
if Assigned(FWinXPBar.FImageList) then
Result := FWinXPBar.FImageList;
end;
procedure TJvXPBarItem.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
if Sender is TCustomAction then
with TCustomAction(Sender) do
begin
if not (csLoading in ComponentState) then
Update;
if not CheckDefaults or (Self.Caption = '') or (Self.Caption = Self.Name) then
Self.Caption := Caption;
if not CheckDefaults or (Self.Checked = False) then
Self.Checked := Checked;
if not CheckDefaults or Self.Enabled then
Self.Enabled := Enabled;
if not CheckDefaults or (Self.Hint = '') then
Self.Hint := Hint;
if not CheckDefaults or (Self.ImageIndex = -1) then
Self.ImageIndex := ImageIndex;
if not CheckDefaults or Self.Visible then
Self.Visible := Visible;
if not CheckDefaults or not Assigned(Self.OnClick) then
Self.OnClick := OnExecute;
end;
end;
procedure TJvXPBarItem.DrawItem(AWinXPBar: TJvXPCustomWinXPBar; ACanvas: TCanvas;
Rect: TRect; State: TJvXPDrawState; ShowItemFrame: Boolean; Bitmap: TBitmap);
var
ItemCaption: TCaption;
HasImages: Boolean;
LBar: TJvXPCustomWinXPBar;
begin
LBar := (AWinXPBar as TJvXPCustomWinXPBar);
HasImages := Self.Images <> nil;
with ACanvas do
begin
Font.Assign(LBar.Font);
Brush.Color := LBar.Colors.BodyColor;
if not ShowItemFrame then
FillRect(Rect);
if not Self.Enabled then
Font.Color := clGray
else
begin
if dsFocused in State then
begin
if LBar.HotTrack then
begin
if LBar.FHotTrackColor <> clNone then
Font.Color := LBar.FHotTrackColor;
Font.Style := Font.Style + [fsUnderline];
end;
if ShowItemFrame then
begin
Brush.Color := LBar.Colors.FocusedColor;
if LBar.RoundedItemFrame > 0 then
RoundedFrame(ACanvas, Rect, LBar.Colors.FocusedFrameColor, LBar.RoundedItemFrame)
else
begin
FillRect(Rect);
JvXPFrame3D(ACanvas, Rect, LBar.Colors.FocusedFrameColor, LBar.Colors.FocusedFrameColor);
end;
end;
end
else
if dsClicked in State then
begin
if ShowItemFrame then
begin
Brush.Color := LBar.Colors.CheckedColor;
if LBar.RoundedItemFrame > 0 then
RoundedFrame(ACanvas, Rect, LBar.Colors.CheckedFrameColor, LBar.RoundedItemFrame)
else
begin
FillRect(Rect);
JvXPFrame3D(ACanvas, Rect, LBar.Colors.CheckedFrameColor, LBar.Colors.CheckedFrameColor);
end;
end;
end
else
FillRect(Rect);
end;
if HasImages then
begin
Draw(Rect.Left + 1, Rect.Top + (LBar.FItemHeight - Bitmap.Height) div 2, Bitmap);
Inc(Rect.Left, Self.Images.Width + 4);
end
else
Inc(Rect.Left, 4);
ItemCaption := Self.Caption;
if (ItemCaption = '') and ((csDesigning in LBar.ComponentState) or (LBar.ControlCount = 0)) then
ItemCaption := Format(RsUntitledFmt, [RsUntitled, Index]);
SetBkMode(ACanvas.Handle, QWindows.TRANSPARENT);
DrawText(ACanvas, ItemCaption, -1, Rect,
DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS);
end;
end;
function TJvXPBarItem.GetActionLinkClass: TJvXPBarItemActionLinkClass;
begin
Result := TJvXPBarItemActionLink;
end;
procedure TJvXPBarItem.Assign(Source: TPersistent);
begin
if Source is TJvXPBarItem then
with TJvXPBarItem(Source) do
begin
Self.Action.Assign(Action);
Self.Caption := Caption;
Self.Data := Data;
Self.DataObject := DataObject;
Self.Enabled := Enabled;
Self.Hint := Hint;
Self.ImageList.Assign(ImageList);
Self.ImageIndex := ImageIndex;
Self.Name := Name;
Self.Tag := Tag;
Self.Visible := Visible;
Self.OnClick := OnClick;
Self.Checked := Checked;
Self.GroupIndex := GroupIndex;
Self.OnDblClick := OnDblClick;
end
else
inherited Assign(Source);
end;
function TJvXPBarItem.IsCaptionStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsCaptionLinked;
end;
function TJvXPBarItem.IsEnabledStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsEnabledLinked;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -