📄 jvtabbar.pas
字号:
procedure TJvTabBarItem.MakeVisible;
begin
TabBar.MakeVisible(Self);
end;
function TJvTabBarItem.GetEnabled: Boolean;
begin
Result := FEnabled;
if Assigned(FOnGetEnabled) then
FOnGetEnabled(Self, Result);
end;
function TJvTabBarItem.GetModified: Boolean;
begin
Result := FModified;
if Assigned(FOnGetModified) then
FOnGetModified(Self, Result);
end;
procedure TJvTabBarItem.SetIndex(Value: Integer);
begin
inherited SetIndex(Value);
Changed;
end;
//=== { TJvTabBarItems } =====================================================
function TJvTabBarItems.Find(const AName: string): TJvTabBarItem;
var
I: Integer;
begin
Result := nil;
for I := 0 to Count - 1 do
if Items[I].Name = AName then
begin
Result := Items[I];
Break;
end;
end;
function TJvTabBarItems.GetTabBar: TJvCustomTabBar;
begin
Result := GetOwner as TJvCustomTabBar;
end;
function TJvTabBarItems.GetItem(Index: Integer): TJvTabBarItem;
begin
Result := TJvTabBarItem(inherited Items[Index]);
end;
procedure TJvTabBarItems.SetItem(Index: Integer; const Value: TJvTabBarItem);
begin
if Value <> GetItem(Index) then
GetItem(Index).Assign(Value);
end;
procedure TJvTabBarItems.Notify(Item: TCollectionItem; Action: TCollectionNotification);
begin
inherited Notify(Item, Action);
if Action in [cnExtracting, cnDeleting] then
begin
// unselect the item to delete
if TabBar.SelectedTab = Item then
TabBar.SelectedTab := nil;
if TabBar.HotTab = Item then
TabBar.SetHotTab(nil);
if TabBar.FMouseDownClosingTab = Item then
TabBar.FMouseDownClosingTab := nil;
if TabBar.ClosingTab = Item then
TabBar.FClosingTab := nil;
end;
TabBar.Changed;
end;
function TJvTabBarItems.IndexOf(Item: TJvTabBarItem): Integer;
begin
for Result := 0 to Count - 1 do
if Items[Result] = Item then
Exit;
Result := -1;
end;
//=== { TJvTabBarPainter } ===================================================
procedure TJvTabBarPainter.Changed;
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
//=== { TJvModernTabBarPainter } =============================================
constructor TJvModernTabBarPainter.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FFont := TFont.Create;
FDisabledFont := TFont.Create;
FFont.Color := clWindowText;
FDisabledFont.Color := clGrayText;
FFont.OnChange := FontChanged;
FDisabledFont.OnChange := FontChanged;
FTabColor := clBtnFace;
FColor := clWindow;
FBorderColor := clSilver;
FControlDivideColor := clBlack;
FModifiedCrossColor := clRed;
FCloseColorSelected := $F4F4F4;
FCloseColor := clWhite;
FCloseCrossColorSelected := clBlack;
FCloseCrossColor := $5D5D5D;
FCloseCrossColorDisabled := $ADADAD;
FCloseRectColor := $868686;
FCloseRectColorDisabled := $D6D6D6;
FDividerColor := $99A8AC;
end;
destructor TJvModernTabBarPainter.Destroy;
begin
FFont.Free;
FDisabledFont.Free;
inherited Destroy;
end;
procedure TJvModernTabBarPainter.DrawBackground(Canvas: TCanvas;
TabBar: TJvCustomTabBar; R: TRect);
begin
with TCanvasX(Canvas) do
begin
Brush.Style := bsSolid;
Brush.Color := Color;
FillRect(R);
Brush.Style := bsClear;
Pen.Color := BorderColor;
case TabBar.Align of
alBottom:
begin
MoveTo(0, R.Bottom - 1);
LineTo(0, 0);
Pen.Color := ControlDivideColor;
LineTo(R.Right - 1, 0);
Pen.Color := BorderColor;
LineTo(R.Right - 1, R.Bottom - 1);
LineTo(0, R.Bottom - 1);
end;
else
// Top
MoveTo(0, R.Bottom - 1);
LineTo(0, 0);
LineTo(R.Right - 1, 0);
LineTo(R.Right - 1, R.Bottom - 1);
Pen.Color := ControlDivideColor;
LineTo(0, R.Bottom - 1);
end;
end;
end;
procedure TJvModernTabBarPainter.DrawDivider(Canvas: TCanvas;
LeftTab: TJvTabBarItem; R: TRect);
begin
if not LeftTab.Selected then
begin
if not Assigned(LeftTab.TabBar.SelectedTab) or
(LeftTab.GetNextVisible <> LeftTab.TabBar.SelectedTab) then
begin
with TCanvasX(Canvas) do
begin
Pen.Color := DividerColor;
MoveTo(R.Right - 1, R.Top + 3);
LineTo(R.Right - 1, R.Bottom - 3);
end;
end;
end;
end;
procedure TJvModernTabBarPainter.DrawTab(Canvas: TCanvas; Tab: TJvTabBarItem; R: TRect);
var
CloseR: TRect;
begin
with TCanvasX(Canvas) do
begin
Brush.Style := bsSolid;
Brush.Color := Color;
Pen.Mode := pmCopy;
Pen.Style := psSolid;
if Tab.Selected then
begin
Brush.Style := bsSolid;
Brush.Color := TabColor;
FillRect(R);
Pen.Color := ControlDivideColor;
case Tab.TabBar.Align of
alBottom:
begin
MoveTo(R.Left, R.Top);
LineTo(R.Left, R.Bottom - 1);
LineTo(R.Right - 1, R.Bottom - 1);
LineTo(R.Right - 1, R.Top - 1{end});
end;
else
// Top
MoveTo(R.Left, R.Bottom - 1);
LineTo(R.Left, R.Top);
LineTo(R.Right - 1, R.Top);
LineTo(R.Right - 1, R.Bottom - 1 + 1{end});
end;
end;
if Tab.TabBar.CloseButton then
begin
// close button color
if Tab.Selected then
Brush.Color := CloseColorSelected
else
Brush.Color := CloseColor;
if Tab.Enabled and not Tab.Selected and Tab.Hot then
begin
// hot
Pen.Color := DividerColor;
MoveTo(R.Left, R.Top);
LineTo(R.Right - 1 - 1, R.Top);
end;
CloseR := GetCloseRect(Canvas, Tab, Tab.DisplayRect);
Pen.Color := CloseRectColor;
if not Tab.Enabled then
Pen.Color := CloseRectColorDisabled;
if Tab.Closing then
// shrink
Rectangle(CloseR.Left + 1, CloseR.Top + 1, CloseR.Right - 1, CloseR.Bottom - 1)
else
Rectangle(CloseR);
if Tab.Modified then
Pen.Color := ModifiedCrossColor
else
if Tab.Selected and not Tab.Closing then
Pen.Color := CloseCrossColorSelected
else
if Tab.Enabled then
Pen.Color := CloseCrossColor
else
Pen.Color := CloseCrossColorDisabled;
// close cross
MoveTo(CloseR.Left + 3, CloseR.Top + 3);
LineTo(CloseR.Right - 3, CloseR.Bottom - 3);
MoveTo(CloseR.Left + 4, CloseR.Top + 3);
LineTo(CloseR.Right - 4, CloseR.Bottom - 3);
MoveTo(CloseR.Right - 4, CloseR.Top + 3);
LineTo(CloseR.Left + 2, CloseR.Bottom - 3);
MoveTo(CloseR.Right - 5, CloseR.Top + 3);
LineTo(CloseR.Left + 3, CloseR.Bottom - 3);
// remove intersection
if Tab.Modified then
FillRect(Rect(CloseR.Left + 5, CloseR.Top + 4, CloseR.Right - 5, CloseR.Bottom - 4));
R.Left := CloseR.Right;
end;
InflateRect(R, -1, -1);
if not Tab.TabBar.CloseButton then
Inc(R.Left, 2);
if (Tab.ImageIndex <> -1) and (Tab.GetImages <> nil) then
begin
Tab.GetImages.Draw(Canvas, R.Left, R.Top + (R.Bottom - R.Top - Tab.GetImages.Height) div 2,
Tab.ImageIndex, {$IFDEF VisualCLX} itImage, {$ENDIF} Tab.Enabled);
Inc(R.Left, Tab.GetImages.Width + 2);
end;
if Tab.Enabled then
Font.Assign(Self.Font)
else
Font.Assign(Self.DisabledFont);
Brush.Style := bsClear;
TextRect(R, R.Left + 3, R.Top + 3, Tab.Caption);
end;
end;
function TJvModernTabBarPainter.GetCloseRect(Canvas: TCanvas; Tab: TJvTabBarItem; R: TRect): TRect;
begin
Result.Left := R.Left + 5;
Result.Top := R.Top + 5;
Result.Right := Result.Left + 12;
Result.Bottom := Result.Top + 11;
end;
function TJvModernTabBarPainter.GetDividerWidth(Canvas: TCanvas; LeftTab: TJvTabBarItem): Integer;
begin
Result := 1;
end;
function TJvModernTabBarPainter.GetTabSize(Canvas: TCanvas; Tab: TJvTabBarItem): TSize;
begin
if Tab.Enabled then
Canvas.Font.Assign(Font)
else
Canvas.Font.Assign(DisabledFont);
Result.cx := Canvas.TextWidth(Tab.Caption) + 11;
Result.cy := Canvas.TextHeight(Tab.Caption + 'Ag') + 7;
if Tab.TabBar.CloseButton then
Result.cx := Result.cx + 15;
if (Tab.ImageIndex <> -1) and (Tab.GetImages <> nil) then
Result.cx := Result.cx + Tab.GetImages.Width + 2;
end;
function TJvModernTabBarPainter.Options: TJvTabBarPainterOptions;
begin
Result := [poPaintsHotTab];
end;
procedure TJvModernTabBarPainter.FontChanged(Sender: TObject);
begin
Changed;
end;
procedure TJvModernTabBarPainter.SetBorderColor(const Value: TColor);
begin
if Value <> FBorderColor then
begin
FBorderColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetColor(const Value: TColor);
begin
if Value <> FColor then
begin
FColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetControlDivideColor(const Value: TColor);
begin
if Value <> FControlDivideColor then
begin
FControlDivideColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetModifiedCrossColor(const Value: TColor);
begin
if Value <> FModifiedCrossColor then
begin
FModifiedCrossColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetTabColor(const Value: TColor);
begin
if Value <> FTabColor then
begin
FTabColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetCloseColor(const Value: TColor);
begin
if Value <> FCloseColor then
begin
FCloseColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetCloseColorSelected(const Value: TColor);
begin
if Value <> FCloseColorSelected then
begin
FCloseColorSelected := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetCloseCrossColor(const Value: TColor);
begin
if Value <> FCloseCrossColor then
begin
FCloseCrossColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetCloseCrossColorDisabled(const Value: TColor);
begin
if Value <> FCloseCrossColorDisabled then
begin
FCloseCrossColorDisabled := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetCloseCrossColorSelected(const Value: TColor);
begin
if Value <> FCloseCrossColorSelected then
begin
FCloseCrossColorSelected := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetCloseRectColor(const Value: TColor);
begin
if Value <> FCloseRectColor then
begin
FCloseRectColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetCloseRectColorDisabled(const Value: TColor);
begin
if Value <> FCloseRectColorDisabled then
begin
FCloseRectColorDisabled := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetDividerColor(const Value: TColor);
begin
if Value <> FDividerColor then
begin
FDividerColor := Value;
Changed;
end;
end;
procedure TJvModernTabBarPainter.SetDisabledFont(const Value: TFont);
begin
if Value <> FDisabledFont then
FDisabledFont.Assign(Value);
end;
procedure TJvModernTabBarPainter.SetFont(const Value: TFont);
begin
if Value <> FFont then
FFont.Assign(Value);
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -