📄 suitabcontrol.pas
字号:
procedure TsuiTabControlTopPanel.MouseMove(Shift: TShiftState; X,
Y: Integer);
begin
inherited;
if m_ShowButton then
Repaint();
end;
procedure TsuiTabControlTopPanel.OnTabsChange(Sender: TObject);
begin
Repaint();
end;
procedure TsuiTabControlTopPanel.Paint;
var
Buf : TBitmap;
nRet : Integer;
begin
Buf := TBitmap.Create();
Buf.Width := Width;
Buf.Height := Height;
DoTrans(Buf.Canvas, m_TabControl);
m_InButtons := 0;
if m_Passed > m_Tabs.Count - 1 then
m_Passed := m_Tabs.Count - 1;
if m_Passed < 0 then
m_Passed := 0;
if m_AutoFit then
begin
nRet := PaintTabs(Buf);
if nRet < m_TabIndex then
begin
while (nRet < m_TabIndex) and (m_Passed < m_Tabs.Count - 1) do
begin
Inc(m_Passed);
nRet := PaintTabs(Buf);
end;
end
// else if nRet > m_TabIndex then
// begin
// while (nRet > m_TabIndex) and (m_Passed > 0) do
// begin
// Dec(m_Passed);
// nRet := PaintTabs(Buf);
// end;
// end;
end
else
PaintTabs(Buf);
PaintButtons(Buf);
BitBlt(Canvas.Handle, 0, 0, Buf.Width, Buf.Height, Buf.Canvas.Handle, 0, 0, SRCCOPY);
Buf.Free();
end;
procedure TsuiTabControlTopPanel.PaintButtons(const Buf: TBitmap);
var
BtnBuf : TBitmap;
BtnRect : TRect;
MousePoint : TPoint;
OutUIStyle : TsuiUIStyle;
nLeft : Integer;
nTop : Integer;
nIndex : Integer;
begin
if (not m_ShowButton) and (m_Passed <= 0) then
Exit;
GetCursorPos(MousePoint);
MousePoint := ScreenToClient(MousePoint);
m_InButtons := 0;
BtnBuf := TBitmap.Create();
BtnBuf.Transparent := true;
nLeft := Width - 2 - m_BtnSize.X;
if m_TabPosition = suiTop then
begin
if m_BtnSize.Y + 4 < Buf.Height then
nTop := (Buf.Height - m_BtnSize.Y) div 2 - 2
else
nTop := 0;
end
else
begin
if m_BtnSize.Y + 4 < Buf.Height then
nTop := (Buf.Height - m_BtnSize.Y) div 2 + 2
else
nTop := Buf.Height - m_BtnSize.Y;
end;
// Right Button
BtnRect := Rect(nLeft, nTop, Width - 2, nTop + m_BtnSize.Y);
if InRect(MousePoint, BtnRect) then
begin
nIndex := 2;
m_InButtons := 1;
end
else
nIndex := 1;
if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
begin
if m_FileTheme.GetBitmap(SKIN2_SCROLLBUTTON) = nil then
GetInsideThemeBitmap(SUI_THEME_DEFAULT, SUI_THEME_SCROLLBUTTON_IMAGE, BtnBuf, 4, nIndex)
else
m_FileTheme.GetBitmap2(SKIN2_SCROLLBUTTON, BtnBuf, 4, nIndex)
end
else
GetInsideThemeBitmap(OutUIStyle, SUI_THEME_SCROLLBUTTON_IMAGE, BtnBuf, 4, nIndex);
Buf.Canvas.Draw(nLeft, nTop, BtnBuf);
// Left Button
BtnRect := Rect(nLeft - m_BtnSize.X, nTop, nLeft, nTop + m_BtnSize.Y);
if InRect(MousePoint, BtnRect) then
begin
nIndex := 4;
m_InButtons := -1;
end
else
nIndex := 3;
if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
begin
if m_FileTheme.GetBitmap(SKIN2_SCROLLBUTTON) = nil then
GetInsideThemeBitmap(SUI_THEME_DEFAULT, SUI_THEME_SCROLLBUTTON_IMAGE, BtnBuf, 4, nIndex)
else
m_FileTheme.GetBitmap2(SKIN2_SCROLLBUTTON, BtnBuf, 4, nIndex)
end
else
GetInsideThemeBitmap(OutUIStyle, SUI_THEME_SCROLLBUTTON_IMAGE, BtnBuf, 4, nIndex);
Buf.Canvas.Draw(nLeft - m_BtnSize.X, nTop, BtnBuf);
BtnBuf.Free();
end;
function TsuiTabControlTopPanel.PaintTabs(const Buf: TBitmap) : Integer;
var
nLeft : Integer;
nWidth : Integer;
i : Integer;
nShowed : Integer;
R : TRect;
RightBorder : Integer;
RightBorder1, RightBorder2 : Integer;
OverRightBorder : Boolean;
ATrans, ITrans : Boolean;
ASampleTop, ISampleTop : Boolean;
T1, T2, T3, T4 : Integer;
ImgId : Integer;
begin
RightBorder1 := Width - 2 * m_BtnSize.X - 2;
RightBorder2 := Width - 10;
RightBorder := 0;
ASampleTop := true;
if m_ActiveTab.Canvas.Pixels[0, 0] = clFuchsia then
begin
ATrans := true;
end
else if m_ActiveTab.Canvas.Pixels[0, m_ActiveTab.Height - 1] = clFuchsia then
begin
ATrans := true;
ASampleTop := false;
end
else
ATrans := false;
ISampleTop := true;
if m_InactiveTab.Canvas.Pixels[0, 0] = clFuchsia then
begin
ITrans := true;
end
else if m_InactiveTab.Canvas.Pixels[0, m_InactiveTab.Height - 1] = clFuchsia then
begin
ITrans := true;
ISampleTop := false;
end
else
ITrans := false;
m_TabHeight := m_ActiveTab.Height;
if m_TabPosition = suiTop then
begin
Buf.Canvas.StretchDraw(
Rect(1, m_InactiveTab.Height, Width - 1, m_InactiveTab.Height + m_Line.Height),
m_Line
);
Buf.Canvas.Pen.Color := m_TabControl.BorderColor;
Buf.Canvas.MoveTo(0, m_InactiveTab.Height);
Buf.Canvas.LineTo(0, m_InactiveTab.Height + m_Line.Height);
Buf.Canvas.MoveTo(Width - 1, m_InactiveTab.Height);
Buf.Canvas.LineTo(Width - 1, m_InactiveTab.Height + m_Line.Height);
T1 := 0;
T2 := m_InactiveTab.Height;
T3 := T1 + 1;
T4 := T2 + 1;
end
else
begin
Buf.Canvas.StretchDraw(
Rect(1, 0, Width - 1, m_Line.Height),
m_Line
);
Buf.Canvas.Pen.Color := m_TabControl.BorderColor;
Buf.Canvas.MoveTo(0, 0);
Buf.Canvas.LineTo(0, m_Line.Height);
Buf.Canvas.MoveTo(Width - 1, 0);
Buf.Canvas.LineTo(Width - 1, m_Line.Height);
T1 := Height - m_InactiveTab.Height;
T2 := Height;
T3 := T1 - 1;
T4 := T2 - 1;
end;
nLeft := m_LeftMargin;
Buf.Canvas.Font := m_TabControl.Font;
nShowed := 0;
OverRightBorder := false;
Result := m_Tabs.Count - 1;
for i := 0 to m_Tabs.Count - 1 do
begin
if (i = m_Tabs.Count - 1) and (m_Passed = 0) then
RightBorder := RightBorder2
else
RightBorder := RightBorder1;
if not m_TabVisible[i] then
begin
m_TabPos[i] := 0;
continue;
end;
if OverRightBorder then
break;
if m_Tabs[i] <> '' then
nWidth := Buf.Canvas.TextWidth(m_Tabs[i]) + 20
else
nWidth := 80;
ImgId := -1;
if m_TabControl.Images <> nil then
begin
ImgId := m_TabControl.GetImageIndex(i);
if (ImgId > -1) and (ImgId < m_TabControl.Images.Count) then
Inc(nWidth, m_TabControl.Images.Width + 4)
else
ImgId := -1;
end;
if nWidth < 15 then
nWidth := 15;
if i < SUI_TABCONTROL_MAXTABS - 1 then
m_TabPos[i] := nWidth;
Inc(nShowed);
if nShowed <= m_Passed then
continue;
if m_TabIndex = i then
begin
R := Rect(nLeft, T3, nWidth + nLeft, T4);
if R.Right > RightBorder then
begin
R.Right := RightBorder1;
OverRightBorder := true;
Result := i - 1;
end;
SpitDrawHorizontal(m_ActiveTab, Buf.Canvas, R, ATrans, Color, ASampleTop);
Buf.Canvas.Font.Color := m_ActiveTabFontColor;
end
else
begin
R := Rect(nLeft, T1, nWidth + nLeft, T2);
if R.Right > RightBorder then
begin
R.Right := RightBorder1;
m_TabPos[i] := R.Right - R.Left;
OverRightBorder := true;
Result := i - 1;
end;
SpitDrawHorizontal(m_InactiveTab, Buf.Canvas, R, ITrans, Color, ISampleTop);
Buf.Canvas.Font.Color := m_InactiveTabFontColor;
end;
Inc(nLeft, nWidth);
if ImgId > -1 then
begin
m_TabControl.Images.Draw(Buf.Canvas, R.Left + 8, Max(R.Top + 1, (R.Bottom - R.Top - m_TabControl.Images.Height) div 2), ImgId);
R.Left := R.Left + m_TabControl.Images.Width + 4
end;
Buf.Canvas.Brush.Style := bsClear;
if OverRightBorder then
begin
R.Left := R.Left + 10;
R.Right := R.Right - 4;
DrawText(Buf.Canvas.Handle, PAnsiChar(m_Tabs[i]), -1, R, DT_SINGLELINE or DT_VCENTER);
end
else
DrawText(Buf.Canvas.Handle, PAnsiChar(m_Tabs[i]), -1, R, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
if (m_TabIndex = i) and Focused() and m_TabControl.m_PageDrawFocused then
begin
Buf.Canvas.Brush.Style := bsSolid;
Inc(R.Left, 8);
Dec(R.Right, 8);
Inc(R.Top, 1);
Dec(R.Bottom, 1);
Buf.Canvas.DrawFocusRect(R);
end;
end;
if ((nLeft > RightBorder) or OverRightBorder) and (m_Tabs.Count <> 0) then
m_ShowButton := true
else
m_ShowButton := false;
end;
procedure TsuiTabControlTopPanel.RequestAlign;
var
R : TRect;
begin
if m_TabControl <> nil then
begin
if m_TabPosition = suiTop then
R := Rect(0, 0, m_TabControl.Width, Height)
else
R := Rect(0, m_TabControl.Height - Height, m_TabControl.Width, m_TabControl.Height);
PlaceControl(self, R);
end
else
inherited;
end;
procedure TsuiTabControlTopPanel.Resize;
begin
inherited;
if m_TabControl <> nil then
begin
if m_TabPosition = suiTop then
SetBounds(0, 0, m_TabControl.Width, Height)
else
begin
Top := m_TabControl.Height - Height;
Left := 0;
Width := m_TabControl.Width;
end;
end;
end;
procedure TsuiTabControlTopPanel.SetFileTheme(const Value: TsuiFileTheme);
begin
m_FileTheme := Value;
SetUIStyle(m_UIStyle);
end;
procedure TsuiTabControlTopPanel.SetLeftMargin(const Value: Integer);
begin
m_LeftMargin := Value;
Repaint();
end;
procedure TsuiTabControlTopPanel.SetTabIndex(const Value: Integer);
var
bAllow : Boolean;
begin
if m_TabIndex = Value then
Exit;
if m_Tabs.Count = 0 then
begin
m_TabIndex := -1;
Repaint();
Exit;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -