📄 skintabs.pas
字号:
BufferTB, Picture, ActiveTabRect, W, H, TabStretchEffect)
else
CreateHSkinImage(TabLeftOffset, TabRightOffset,
BufferTB, Picture, TabRect, W, H, TabStretchEffect);
TB.Width := W;
TB.Height := H;
TB.Canvas.StretchDraw(R, BufferTB);
BufferTB.Free;
end;
if TabPosition = tpBottom then DrawFlipVert(TB);
with TB.Canvas do
begin
Brush.Style := bsClear;
if FUseSkinFont
then
begin
Font.Name := FontName;
Font.Style := FontStyle;
Font.Height := FontHeight;
end
else
Font.Assign(Self.Font);
if (SkinData <> nil) and (SkinData.ResourceStrData <> nil)
then
Font.Charset := SkinData.ResourceStrData.CharSet
else
Font.CharSet := Self.Font.CharSet;
if MouseIn and not Active
then
Font.Color := MouseInFontColor
else
if Active and Focused
then
Font.Color := FocusFontColor
else
if Active
then Font.Color := ActiveFontColor
else Font.Color := FontColor;
end;
end
else
begin
TB.Width := W;
TB.Height := H;
if MouseIn and not Active
then
begin
TB.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
TB.Canvas.FillRect(R);
end
else
if Active and Focused
then
begin
Frame3D(TB.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
TB.Canvas.Brush.Color := SP_XP_BTNDOWNCOLOR;
TB.Canvas.FillRect(R);
end
else
if Active
then
begin
Frame3D(TB.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
TB.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
TB.Canvas.FillRect(R);
end
else
begin
TB.Canvas.Brush.Color := clBtnFace;
TB.Canvas.FillRect(R);
end;
with TB.Canvas do
begin
Brush.Style := bsClear;
Font.Assign(Self.Font);
if (SkinData <> nil) and (SkinData.ResourceStrData <> nil)
then
Font.Charset := SkinData.ResourceStrData.CharSet;
end;
end;
//
if DrawGlyph
then
DrawTabGlyphAndText(TB.Canvas, TB.Width, TB.Height, S,
Images, Pages[TI].ImageIndex, Pages[TI].Enabled)
else
DrawText(TB.Canvas.Handle, PChar(S), Length(S), R, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
if TabPosition = tpLeft
then
DrawRotate90_1(Cnvs, TB, Rct.Left, Rct.Top)
else
if TabPosition = tpRight
then
DrawRotate90_2(Cnvs, TB, Rct.Left, Rct.Top)
else
Cnvs.Draw(Rct.Left, Rct.Top, TB);
TB.Free;
end;
{ TspSkinTabControl }
constructor TspSkinTabControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FromWMPaint := False;
FUseSkinFont := True;
Ctl3D := False;
FIndex := -1;
Picture := nil;
Font.Name := '宋体';
Font.Style := [];
Font.Color := clBtnText;
Font.Height := 14;
FOldTop := 0;
FOldBottom := 0;
FSkinUpDown := nil;
FSkinDataName := 'tab';
FDefaultFont := TFont.Create;
FDefaultFont.Name := '宋体';
FDefaultFont.Style := [];
FDefaultFont.Color := clBtnText;
FDefaultFont.Height := 14;
FDefaultItemHeight := 20;
end;
procedure TspSkinTabControl.MouseMove;
begin
inherited;
if not (csDesigning in ComponentState)
then
TestActive(X, Y);
end;
procedure TspSkinTabControl.MouseDown;
begin
inherited;
if (Button = mbLeft) and not (csDesigning in ComponentState)
then
TestActive(X, Y);
end;
procedure TspSkinTabControl.CMMouseLeave;
var
R: TRect;
begin
if (FOldActiveTab <> - 1) and (FOldActiveTab <> TabIndex)
then
begin
R := GetItemRect(FOldActiveTab);
DrawTab(FOldActiveTab, R, False, False, Canvas);
FOldActiveTab := -1;
end;
if (FActiveTab <> - 1) and (FActiveTab <> TabIndex)
then
begin
R := GetItemRect(FActiveTab);
DrawTab(FActiveTab, R, False, False, Canvas);
FActiveTab := -1;
end;
end;
procedure TspSkinTabControl.TestActive(X, Y: Integer);
var
i, j: Integer;
R: TRect;
begin
FOldActiveTab := FActiveTab;
j := -1;
for i := 0 to Tabs.Count-1 do
begin
R := GetItemRect(i);
if PtInRect(R, Point(X, Y))
then
begin
j := i;
Break;
end;
end;
FActiveTab := j;
if (FOldActiveTab <> FActiveTab)
then
begin
if (FOldActiveTab <> - 1) and (FOldActiveTab <> TabIndex)
then
begin
R := GetItemRect(FOldActiveTab);
DrawTab(FOldActiveTab, R, False, False, Canvas);
end;
if (FActiveTab <> -1) and (FActiveTab <> TabIndex)
then
begin
R := GetItemRect(FActiveTab);
DrawTab(FActiveTab, R, False, True, Canvas );
end;
end;
end;
procedure TspSkinTabControl.SetDefaultItemHeight;
begin
FDefaultItemHeight := Value;
if FIndex = -1
then
begin
SetitemSize(TabWidth, FDefaultItemHeight);
Change2;
ReAlign;
end;
end;
procedure TspSkinTabControl.SetDefaultFont;
begin
FDefaultFont.Assign(Value);
end;
procedure TspSkinTabControl.OnUpDownChange(Sender: TObject);
begin
FSkinUpDown.Max := GetInVisibleItemCount;
SendMessage(Handle, WM_HSCROLL,
MakeWParam(SB_THUMBPOSITION, FSkinUpDown.Position), 0);
end;
function TspSkinTabControl.GetPosition: Integer;
var
i, j: Integer;
R: TRect;
begin
j := 0;
for i := 0 to Tabs.Count - 1 do
begin
R := GetItemRect(i);
if R.Right <= 0 then inc(j);
end;
Result := j;
end;
function TspSkinTabControl.GetInVisibleItemCount;
var
i, j: Integer;
R: TRect;
Limit: Integer;
begin
if FSkinUpDown = nil
then
Limit := Width - 3
else
Limit := Width - FSkinUpDown.Width - 3;
j := 0;
for i := 0 to Tabs.Count - 1 do
begin
R := GetItemRect(i);
if (R.Right > Limit) or (R.Right <= 0)
then inc(j);
end;
Result := j;
end;
procedure TspSkinTabControl.CheckScroll;
var
Wnd: HWND;
InVCount: Integer;
begin
Wnd := FindWindowEx(Handle, 0, 'msctls_updown32', nil);
if Wnd <> 0 then DestroyWindow(Wnd);
InVCount := GetInVisibleItemCount;
if (InVCount = 0) and (FSkinUpDown <> nil)
then
HideSkinUpDown
else
if (InVCount > 0) and (FSkinUpDown = nil)
then
ShowSkinUpDown;
if FSkinUpDown <> nil
then
begin
FSkinUpDown.Max := InVCount;
FSkinUpDown.Left := Width - FSkinUpDown.Width;
if TabPosition = tpTop
then
FSkinUpDown.Top := 0
else
FSkinUpDown.Top := Height - FSkinUpDown.Height;
end;
end;
procedure TspSkinTabControl.ShowSkinUpDown;
begin
FSkinUpDown := TspSkinUpDown.Create(Self);
FSkinUpDown.Parent := Self;
FSkinUpDown.Width := 36;
FSkinUpDown.Height := 18;
FSkinUpDown.Min := 0;
FSkinUpDown.Max := GetInVisibleItemCount;
FSkinUpDown.Position := GetPosition;
FSkinUpDown.Increment := 1;
FSkinUpDown.OnChange := OnUpDownChange;
FSkinUpDown.Left := Width - FSkinUpDown.Width;
if TabPosition = tpTop
then
FSkinUpDown.Top := 0
else
FSkinUpDown.Top := Height - FSkinUpDown.Height;
FSkinUpDown.SkinDataName := UpDown;
FSkinUpDown.SkinData := SkinData;
FSkinUpDown.Visible := True;
end;
procedure TspSkinTabControl.HideSkinUpDown;
begin
FSkinUpDown.Free;
FSkinUpDown := nil;
end;
procedure TspSkinTabControl.WMPaint;
begin
FromWMPaint := True;
if ControlCount = 0
then
PaintHandler(Msg)
else
inherited;
FromWMPaint := False;
end;
procedure TspSkinTabControl.WMHSCROLL;
begin
inherited;
RePaint;
end;
procedure TspSkinTabControl.WMSize;
begin
inherited;
end;
destructor TspSkinTabControl.Destroy;
begin
FDefaultFont.Free;
inherited Destroy;
end;
procedure TspSkinTabControl.Change2;
begin
if FSkinUpDown <> nil
then FSkinUpDown.Position := GetPosition;
Invalidate;
end;
procedure TspSkinTabControl.Change;
begin
if FSkinUpDown <> nil
then FSkinUpDown.Position := GetPosition;
inherited;
Invalidate;
end;
procedure TspSkinTabControl.GetSkinData;
begin
BGPictureIndex := -1;
if FSD = nil
then
begin
FIndex := -1;
Exit;
end;
if FSD.Empty
then
FIndex := -1
else
FIndex := FSD.GetControlIndex(FSkinDataName);
//
if FIndex <> -1
then
if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinTabControl
then
with TspDataSkinTabControl(FSD.CtrlList.Items[FIndex]) do
begin
if (PictureIndex <> -1) and (PictureIndex < FSD.FActivePictures.Count)
then
Picture := TBitMap(FSD.FActivePictures.Items[PictureIndex])
else
Picture := nil;
Self.SkinRect := SkinRect;
Self.ClRect := ClRect;
Self.TabRect := TabRect;
if IsNullRect(ActiveTabRect)
then
Self.ActiveTabRect := TabRect
else
Self.ActiveTabRect := ActiveTabRect;
if IsNullRect(FocusTabRect)
then
Self.FocusTabRect := ActiveTabRect
else
Self.FocusTabRect := FocusTabRect;
//
Self.TabsBGRect := TabsBGRect;
Self.LTPoint := LTPoint;
Self.RTPoint := RTPoint;
Self.LBPoint := LBPoint;
Self.RBPoint := RBPoint;
Self.TabLeftOffset := TabLeftOffset;
Self.TabRightOffset := TabRightOffset;
//
Self.FontName := FontName;
Self.FontColor := FontColor;
Self.ActiveFontColor := ActiveFontColor;
Self.FocusFontColor := FocusFontColor;
Self.FontStyle := FontStyle;
Self.FontHeight := FontHeight;
Self.UpDown := UpDown;
Self.BGPictureIndex := BGPictureIndex;
Self.MouseInFontColor := MouseInFontColor;
Self.MouseInTabRect := MouseInTabRect;
Self.TabStretchEffect := TabStretchEffect;
end;
end;
procedure TspSkinTabControl.ChangeSkinData;
begin
GetSkinData;
//
if FIndex <> -1
then
begin
Font.Color := FontColor;
if FUseSkinFont
then
begin
Font.Name := FontName;
Font.Height := FontHeight;
Font.Style := FontStyle;
end
else
Font.Assign(FDefaultFont);
if (SkinData <> nil) and (SkinData.ResourceStrData <> nil)
then
Font.Charset := SkinData.ResourceStrData.CharSet
else
Font.CharSet := DefaultFont.CharSet;
if TabHeight <= 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -