📄 jvqxpbar.pas
字号:
procedure TJvXPBarColors.SetSeparatorColor(const Value: TColor);
begin
if FSeparatorColor <> Value then
begin
FSeparatorColor := Value;
Change;
end;
end;
procedure TJvXPBarColors.SetCheckedColor(const Value: TColor);
begin
if FCheckedColor <> Value then
begin
FCheckedColor := Value;
Change;
end;
end;
procedure TJvXPBarColors.SetBorderColor(const Value: TColor);
begin
if FBorderColor <> Value then
begin
FBorderColor := Value;
Change;
end;
end;
procedure TJvXPBarColors.SetFocusedColor(const Value: TColor);
begin
if FFocusedColor <> Value then
begin
FFocusedColor := Value;
Change;
end;
end;
procedure TJvXPBarColors.SetCheckedFrameColor(const Value: TColor);
begin
if FCheckedFrameColor <> Value then
begin
FCheckedFrameColor := Value;
Change;
end;
end;
procedure TJvXPBarColors.SetFocusedFrameColor(const Value: TColor);
begin
if FFocusedFrameColor <> Value then
begin
FFocusedFrameColor := Value;
Change;
end;
end;
//=== { TJvXPCustomWinXPBar } ================================================
constructor TJvXPCustomWinXPBar.Create(AOwner: TComponent);
const
MouseEvents: TJvXPControlStyle = [csRedrawMouseEnter, csRedrawMouseLeave];
begin
inherited Create(AOwner);
FStoredHint := '|'; // no one in their right mind uses a pipe as the only character in a hint...
ControlStyle := ControlStyle - [csDoubleClicks] + [csAcceptsControls, csActionClient];
ExControlStyle := [csRedrawCaptionChanged];
ExControlStyle := ExControlStyle + MouseEvents;
Height := 46;
HotTrack := True; // initialize mouse events
Width := 153;
FColors := TJvXPBarColors.Create;
FColors.OnChange := DoColorsChange;
FCollapsed := False;
FFadeThread := nil;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := DoColorsChange;
FRollChangeLink := TChangeLink.Create;
FRollChangeLink.OnChange := DoColorsChange;
FTopSpace := 5;
FFont := TFont.Create;
FFont.Color := $00840000;
FFont.Size := 8;
FFont.OnChange := FontChange;
FGradient := TBitmap.Create;
FHeaderHeight := 28;
FHeaderRounded := True;
FGradientWidth := 0;
FHeaderFont := TFont.Create;
FHeaderFont.Color := $00840000;
FHeaderFont.Size := 8;
FHeaderFont.Style := [fsBold];
FHeaderFont.OnChange := FontChange;
FHitTest := htNone;
FHotTrackColor := $00FF7C35;
FHoverIndex := -1;
FIcon := TIcon.Create;
FItemHeight := 20;
FItems := GetBarItemsClass.Create(Self);
FRollDelay := 25;
FRolling := False;
FRollMode := rmShrink;
FRollOffset := FItemHeight;
FRollStep := 3;
FShowLinkCursor := True;
FShowRollButton := True;
FVisibleItems := TJvXPBarVisibleItems.Create(Self);
end;
destructor TJvXPCustomWinXPBar.Destroy;
begin
FFont.Free;
FHeaderFont.Free;
FGradient.Free;
FIcon.Free;
FItems.Free;
FVisibleItems.Free;
FColors.Free;
FImageChangeLink.Free;
FRollChangeLink.Free;
inherited Destroy;
end;
procedure TJvXPCustomWinXPBar.Notification(AComponent: TComponent;
Operation: TOperation);
var
I: Integer;
begin
if not (csDestroying in ComponentState) and (Operation = opRemove) then
begin
if AComponent = FImageList then
ImageList := nil;
if AComponent = FRollImages then
RollImages := nil;
for I := 0 to FItems.Count - 1 do
FItems[I].Notification(AComponent);
end;
inherited Notification(AComponent, Operation);
end;
function TJvXPCustomWinXPBar.IsFontStored: Boolean;
begin
Result := not ParentFont ;
end;
procedure TJvXPCustomWinXPBar.FontChange(Sender: TObject);
begin
if (not FFontChanging) and not (csLoading in ComponentState) then
ParentFont := False;
InternalRedraw;
end;
procedure TJvXPCustomWinXPBar.ResizeToMaxHeight;
var
NewHeight: Integer;
begin
{ TODO: Check this!!! }
if IsLocked then
Exit;
NewHeight := FC_HEADER_MARGIN + HeaderHeight + FVisibleItems.Count * FRollOffset + FC_ITEM_MARGIN + 1;
{ full collapsing }
if ((FRolling and not FCollapsed) or (not FRolling and FCollapsed) or
(FVisibleItems.Count = 0)) then
Dec(NewHeight, FC_ITEM_MARGIN);
// if Height <> NewHeight then
Height := NewHeight - 5 + FTopSpace;
end;
function TJvXPCustomWinXPBar.GetHitTestAt(X, Y: Integer): TJvXPBarHitTest;
begin
Result := htNone;
if PtInRect(GetHitTestRect(htHeader), Point(X, Y)) then
Result := htHeader;
if PtInRect(GetHitTestRect(htRollButton), Point(X, Y)) then
Result := htRollButton;
end;
function TJvXPCustomWinXPBar.GetItemRect(Index: Integer): TRect;
begin
Result.Left := 3;
Result.Right := Width - 3;
if FRollMode = rmShrink then
Result.Top := FC_HEADER_MARGIN + HeaderHeight + FC_ITEM_MARGIN div 2 +
Index * FRollOffset - 4 + FTopSpace
else
Result.Top := FC_HEADER_MARGIN + HeaderHeight + FC_ITEM_MARGIN div 2 +
Index * FItemHeight - 4 + FTopSpace;
Result.Bottom := Result.Top + FItemHeight;
end;
function TJvXPCustomWinXPBar.GetRollHeight: Integer;
begin
if Assigned(FRollImages) then
Result := FRollImages.Height
else
Result := 18;
end;
function TJvXPCustomWinXPBar.GetRollWidth: Integer;
begin
if Assigned(FRollImages) then
Result := FRollImages.Width
else
Result := 18;
end;
function TJvXPCustomWinXPBar.GetHitTestRect(const HitTest: TJvXPBarHitTest): TRect;
begin
case HitTest of
htHeader:
Result := Bounds(0, 5, Width, FHeaderHeight);
htRollButton:
Result := Bounds(Width - 24, (FHeaderHeight - GetRollHeight) div 2, GetRollWidth, GetRollHeight);
end;
end;
procedure TJvXPCustomWinXPBar.SortVisibleItems(const Redraw: Boolean);
begin
if (csLoading in ComponentState) or (csDestroying in ComponentState) then
Exit;
FVisibleItems.FItems.Sort(@SortByIndex);
if Redraw then
InternalRedraw;
end;
procedure TJvXPCustomWinXPBar.ItemVisibilityChanged(Item: TJvXPBarItem);
begin
// update visible-item list
if Item.Visible then
FVisibleItems.Add(Item)
else
FVisibleItems.Delete(Item);
end;
procedure TJvXPCustomWinXPBar.HookMouseDown;
var
Rect: TRect;
begin
inherited HookMouseDown; // update drawstate
if FHitTest = htRollButton then
begin
Rect := GetHitTestRect(htRollButton);
QWindows.InvalidateRect(Handle, @Rect, False);
end;
end;
procedure TJvXPCustomWinXPBar.HookMouseEnter;
begin
inherited HookMouseEnter;
if FHoverIndex <> -1 then
DoDrawItem(FHoverIndex, [dsFocused]);
end;
procedure TJvXPCustomWinXPBar.HookMouseLeave;
begin
inherited HookMouseLeave;
if (FHoverIndex <> -1) and (FVisibleItems[FHoverIndex] <> nil) and
(not FVisibleItems[FHoverIndex].Checked) then
DoDrawItem(FHoverIndex, []);
end;
procedure TJvXPCustomWinXPBar.HookMouseMove(X, Y: Integer);
const
cPipe = '|';
var
Rect: TRect;
OldHitTest: TJvXPBarHitTest;
NewIndex, Header: Integer;
begin
OldHitTest := FHitTest;
FHitTest := GetHitTestAt(X, Y);
if FHitTest <> OldHitTest then
begin
Rect := Bounds(0, 5, Width, FHeaderHeight); // header
QWindows.InvalidateRect(Handle, @Rect, False);
if FShowLinkCursor then
if FHitTest <> htNone then
Cursor := crHandPoint
else
Cursor := crDefault;
end;
Header := FC_HEADER_MARGIN + HeaderHeight + FC_ITEM_MARGIN;
if (Y < Header) or (Y > Height - FC_ITEM_MARGIN) then
NewIndex := -1
else
NewIndex := (Y - Header) div ((Height - Header + 4 - FTopSpace) div FVisibleItems.Count);
if (NewIndex >= 0) and (NewIndex < VisibleItems.Count) then
begin
if FStoredHint = cPipe then
FStoredHint := Hint;
if Action is TCustomAction then
inherited Hint := TCustomAction(Action).Hint
else
inherited Hint := VisibleItems[NewIndex].Hint;
end
else
begin
if FStoredHint <> cPipe then
inherited Hint := FStoredHint;
FStoredHint := cPipe;
end;
if NewIndex <> FHoverIndex then
begin
if (FHoverIndex <> -1) and (FVisibleItems[FHoverIndex] <> nil) then
if FVisibleItems[FHoverIndex].Checked then
DoDrawItem(FHoverIndex, [dsClicked])
else
DoDrawItem(FHoverIndex, []);
FHoverIndex := NewIndex;
if (FHoverIndex <> -1) and (FVisibleItems[FHoverIndex] <> nil) and
(FVisibleItems[FHoverIndex].Enabled) then
begin
DoDrawItem(FHoverIndex, [dsFocused]);
if FShowLinkCursor then
Cursor := crHandPoint;
end
else
if FShowLinkCursor then
Cursor := crDefault;
end;
inherited HookMouseMove(X, Y);
end;
procedure TJvXPCustomWinXPBar.HookParentFontChanged;
begin
if ParentFont then
begin
FFontChanging := True;
try
FFont.Color := $00E75100;
FFont.Name := inherited Font.Name;
FFont.Size := 8;
FFont.Style := inherited Font.Style;
FHeaderFont.Color := $00E75100;
FHeaderFont.Name := Font.Name;
FHeaderFont.Size := 8;
FHeaderFont.Style := [fsBold];
finally
FFontChanging := False;
end;
inherited HookParentFontChanged;
end;
end;
procedure TJvXPCustomWinXPBar.HookResized;
begin
// perform actions only on 'width'-change
if FGradientWidth <> Width then
begin
FGradientWidth := Width;
end;
// resize to maximum height
ResizeToMaxHeight;
inherited HookResized;
end;
procedure TJvXPCustomWinXPBar.SetCollapsed(Value: Boolean);
begin
if Value <> FCollapsed then
begin
if not (csLoading in ComponentState) then
begin
if Assigned(FBeforeCollapsedChange) then
FBeforeCollapsedChange(Self, Value);
if Value then
FFadeThread := TJvXPFadeThread.Create(Self, rdCollapse)
else
FFadeThread := TJvXPFadeThread.Create(Self, rdExpand);
if Assigned(FOnCollapsedChange) then
FOnCollapsedChange(Self, Value);
end
else
begin
FCollapsed := Value;
FRolling := True;
if Value then
RollOffset := 0
else
RollOffset := FItemHeight;
FRolling := False;
if Grouped and not Value then
GroupMessage;
end;
end;
end;
procedure TJvXPCustomWinXPBar.SetFont(Value: TFont);
begin
FFont.Assign(Value);
InternalRedraw;
end;
procedure TJvXPCustomWinXPBar.SetHeaderFont(Value: TFont);
begin
FHeaderFont.Assign(Value);
InternalRedraw;
end;
procedure TJvXPCustomWinXPBar.SetHotTrack(Value: Boolean);
const
MouseEvents: TJvXPControlStyle = [csRedrawMouseEnter, csRedrawMouseLeave];
begin
if Value <> FHotTrack then
begin
FHotTrack := Value;
// if FHotTrack then
// ExControlStyle := ExControlStyle + MouseEvents
// else
// ExControlStyle := ExControlStyle - MouseEvents;
if not (csLoading in ComponentState) then
InternalRedraw;
end;
end;
procedure TJvXPCustomWinXPBar.SetHotTrackColor(Value: TColor);
begin
if Value <> FHotTrackColor then
begin
FHotTrackColor := Value;
InternalRedraw;
end;
end;
procedure TJvXPCustomWinXPBar.SetIcon(Value: TIcon);
begin
if Value <> FIcon then
begin
FIcon.Assign(Value);
InternalRedraw;
end;
end;
procedure TJvXPCustomWinXPBar.SetImageList(Value: TCustomImageList);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -