📄 suitabcontrol.pas
字号:
////////////////////////////////////////////////////////////////////////////////
//
//
// FileName : SUITabControl.pas
// Creator : Shen Min
// Date : 2002-09-10 V1-V3
// 2003-07-10 V4
// 2006-06-16 V6
// Comment :
//
// Copyright (c) 2002-2006 Sunisoft
// http://www.sunisoft.com
// Email: support@sunisoft.com
//
////////////////////////////////////////////////////////////////////////////////
unit SUITabControl;
interface
{$I SUIPack.inc}
uses Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, Forms, Graphics,
ComCtrls, Math, ImgList,
SUIThemes, SUIMgr, SUI2Define;
const
SUI_TABCONTROL_MAXTABS = 64;
type
TsuiTabPosition = (suiTop, suiBottom);
TsuiTab = class;
TTabActiveNotify = procedure (Sender : TObject; TabIndex : Integer) of object;
TsuiTabControlTopPanel = class(TCustomPanel)
private
m_Tabs : TStrings;
m_UIStyle : TsuiUIStyle;
m_FileTheme : TsuiFileTheme;
m_TabIndex : Integer;
m_LeftMargin : Integer;
m_TabPos : array [0 .. SUI_TABCONTROL_MAXTABS - 1] of Integer;
m_TabHeight : Integer;
m_UserChanging : Boolean;
m_Passed : Integer;
m_ShowButton : Boolean;
m_InButtons : Integer;
m_BtnSize : TPoint;
m_AutoFit : Boolean;
m_ActiveTab, m_InactiveTab, m_Line : TBitmap;
m_TabPosition : TsuiTabPosition;
m_ActiveTabFontColor, m_InactiveTabFontColor : TColor;
procedure OnTabsChange(Sender : TObject);
procedure SetTabs(const Value: TStrings);
procedure SetUIStyle(const Value: TsuiUIStyle);
procedure SetLeftMargin(const Value: Integer);
procedure SetTabIndex(const Value: Integer);
procedure SetFileTheme(const Value: TsuiFileTheme);
procedure SetTabPosition(const Value: TsuiTabPosition);
procedure WMERASEBKGND(var Msg : TMessage); message WM_ERASEBKGND;
function PaintTabs(const Buf : TBitmap) : Integer;
procedure PaintButtons(const Buf : TBitmap);
function GetInvisibleTabs() : Integer;
procedure WMKillFocus (var Msg : TWMKillFocus); message WM_KILLFOCUS;
procedure WMSetFocus (var Msg: TWMSetFocus); message WM_SETFOCUS;
protected
m_TabControl : TsuiTab;
procedure Paint(); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure DblClick; override;
procedure RequestAlign; override;
procedure Resize(); override;
public
m_TabVisible : array [0 .. SUI_TABCONTROL_MAXTABS - 1] of Boolean;
constructor Create(AOwner : TComponent; TabControl : TsuiTab); reintroduce;
destructor Destroy(); override;
published
property FileTheme : TsuiFileTheme read m_FileTheme write SetFileTheme;
property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
property Tabs : TStrings read m_Tabs write SetTabs;
property TabIndex : Integer read m_TabIndex write SetTabIndex;
property LeftMargin : Integer read m_LeftMargin write SetLeftMargin;
property TabPosition : TsuiTabPosition read m_TabPosition write SetTabPosition;
end;
TsuiTab = class(TCustomPanel)
private
m_UIStyle : TsuiUIStyle;
m_FileTheme: TsuiFileTheme;
m_BorderColor : TColor;
m_Font : TFont;
m_TabPosition : TsuiTabPosition;
m_OnTabActive : TTabActiveNotify;
m_OnChange : TNotifyEvent;
m_OnChanging : TTabChangingEvent;
m_ImageList : TCustomImageList;
m_PageDrawFocused : Boolean;
procedure SetFileTheme(const Value: TsuiFileTheme);
procedure SetUIStyle(const Value: TsuiUIStyle);
procedure SetTabs(const Value: TStrings);
function GetTabs() : TStrings;
function GetLeftMargin: Integer;
function GetTabIndex: Integer;
procedure SetLeftMargin(const Value: Integer);
procedure SetBorderColor(const Value: TColor);
procedure SetFont(const Value: TFont);
procedure SetTabPosition(const Value: TsuiTabPosition);
procedure CMCursorChanged(var Message: TMessage); message CM_CURSORCHANGED;
procedure WMERASEBKGND(var Message : TMessage); message WM_ERASEBKGND;
procedure TopPanelClick(Sender : TObject);
procedure TopPanelDblClick(Sender : TObject);
procedure SetImageList(const Value: TCustomImageList);
procedure SetPageDrawFocused(const Value: Boolean);
protected
m_TopPanel : TsuiTabControlTopPanel;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Paint(); override;
function CreateTopPanel() : TsuiTabControlTopPanel; virtual; abstract;
function GetImageIndex(PageId : Integer) : Integer; virtual; abstract;
procedure SetTabIndex(const Value: Integer); virtual;
procedure BorderColorChanged(); virtual;
procedure AlignControls(AControl: TControl; var Rect: TRect); override;
procedure Resize(); override;
property Tabs : TStrings read GetTabs write SetTabs;
property TabIndex : Integer read GetTabIndex write SetTabIndex;
procedure TabActive(TabIndex : Integer); virtual;
public
constructor Create(AOwner : TComponent); override;
destructor Destroy(); override;
procedure UpdateUIStyle(UIStyle : TsuiUIStyle; FileTheme : TsuiFileTheme); virtual;
property DockManager;
published
property Align;
property FileTheme : TsuiFileTheme read m_FileTheme write SetFileTheme;
property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
property LeftMargin : Integer read GetLeftMargin write SetLeftMargin;
property BorderColor : TColor read m_BorderColor write SetBorderColor;
property Color;
property Font : TFont read m_Font write SetFont;
property Visible;
property TabPosition : TsuiTabPosition read m_TabPosition write SetTabPosition;
property Images : TCustomImageList read m_ImageList write SetImageList;
property PageDrawFocused : Boolean read m_PageDrawFocused write SetPageDrawFocused;
property Anchors;
property BiDiMode;
property Constraints;
property UseDockManager default True;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Locked;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property OnTabActive : TTabActiveNotify read m_OnTabActive write m_OnTabActive;
property OnChange : TNotifyEvent read m_OnChange write m_OnChange;
property OnChanging : TTabChangingEvent read m_OnChanging write m_OnChanging;
end;
TsuiTabControl = class(TsuiTab)
protected
function CreateTopPanel() : TsuiTabControlTopPanel; override;
function GetImageIndex(PageId : Integer) : Integer; override;
published
property Tabs;
property TabIndex;
end;
implementation
uses SUIPublic;
{ TsuiTabControlTopPanel }
constructor TsuiTabControlTopPanel.Create(AOwner: TComponent; TabControl : TsuiTab);
var
i : Integer;
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csAcceptsControls] + [csReflector];
TabStop := true;
m_ActiveTab := TBitmap.Create();
m_ActiveTab.PixelFormat := pf24Bit;
m_InactiveTab := TBitmap.Create();
m_InactiveTab.PixelFormat := pf24Bit;
m_Line := TBitmap.Create();
m_Tabs := TStringList.Create();
(m_Tabs as TStringList).OnChange := OnTabsChange;
m_Tabs.Add('Tab1');
m_TabControl := TabControl;
Caption := ' ';
BevelInner := bvNone;
BevelOuter := bvNone;
BorderWidth := 0;
Align := alNone;
m_LeftMargin := 10;
m_TabIndex := 0;
m_UserChanging := false;
m_Passed := 0;
m_AutoFit := false;
m_ShowButton := false;
m_InButtons := 0;
m_BtnSize.X := 0;
m_BtnSize.Y := 0;
m_TabPosition := suiTop;
for i := 0 to SUI_TABCONTROL_MAXTABS - 1 do
begin
m_TabPos[i] := -1;
m_TabVisible[i] := true;
end;
end;
procedure TsuiTabControlTopPanel.DblClick;
begin
inherited;
Windows.SetFocus(Handle);
end;
destructor TsuiTabControlTopPanel.Destroy;
begin
m_Tabs.Free();
m_Tabs := nil;
m_ActiveTab.Free();
m_InactiveTab.Free();
m_Line.Free();
inherited;
end;
function TsuiTabControlTopPanel.GetInvisibleTabs(): Integer;
var
i : Integer;
n, m : Integer;
begin
Result := 0;
n := 0;
m := 0;
for i := 0 to m_Tabs.Count - 1 do
begin
if n = m_Passed then
begin
m := i;
break;
end;
if m_TabVisible[i] then
Inc(n);
end;
for i := 0 to m do
begin
if not m_TabVisible[i] then
Inc(Result);
end;
end;
procedure TsuiTabControlTopPanel.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited;
if (Key = 9) then
begin
if TabIndex >= Tabs.Count - 1 then
TabIndex := 0
else
TabIndex := TabIndex + 1;
end;
end;
procedure TsuiTabControlTopPanel.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i : Integer;
nLeft : Integer;
nRight : Integer;
begin
inherited;
if Button <> mbLeft then
Exit;
Repaint();
if m_InButtons = -1 then
Dec(m_Passed)
else if (m_InButtons = 1) and m_ShowButton then
Inc(m_Passed);
if m_InButtons <> 0 then
begin
if m_Passed < 0 then
m_Passed := 0;
if m_Passed > m_Tabs.Count then
m_Passed := m_Tabs.Count;
Repaint();
Exit;
end;
nRight := m_LeftMargin;
for i := m_Passed + GetInvisibleTabs() to m_Tabs.Count - 1 do
begin
if m_TabPos[i] = -1 then
break;
nLeft := nRight;
Inc(nRight, m_TabPos[i]);
if (X < nRight) and (X > nLeft) and (Y > 0) and (Y < m_TabHeight) then
begin
m_UserChanging := true;
TabIndex := i;
m_AutoFit := true;
Repaint();
m_AutoFit := false;
m_UserChanging := false;
break;
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -