📄 suipagecontrol.pas
字号:
////////////////////////////////////////////////////////////////////////////////
//
//
// FileName : SUIPageControl.pas
// Creator : Shen Min
// Date : 2002-11-20 V1-V3
// 2003-07-11 V4
// Comment :
//
// Copyright (c) 2002-2006 Sunisoft
// http://www.sunisoft.com
// Email: support@sunisoft.com
//
////////////////////////////////////////////////////////////////////////////////
unit SUIPageControl;
interface
{$I SUIPack.inc}
uses Windows, Messages, SysUtils, Classes, Controls, Forms, CommCtrl, ExtCtrls,
Graphics,
SUITabControl, SUIThemes, SUIMgr;
type
// -------------- TsuiPageControlTopPanel ------------------
TsuiPageControlTopPanel = class(TsuiTabControlTopPanel)
private
procedure CMDesignHitTest(var Msg: TCMDesignHitTest); message CM_DESIGNHITTEST;
end;
TsuiPageControl = class;
// -------------- TsuiTabSheet -----------------------------
TsuiTabSheet = class(TCustomPanel)
private
m_PageControl : TsuiPageControl;
m_PageIndex : Integer;
m_Caption : TCaption;
m_BorderColor : TColor;
m_TabVisible : Boolean;
m_OnShow: TNotifyEvent;
m_OnHide : TNotifyEvent;
m_ImageIndex : Integer;
procedure SetPageControl(const Value: TsuiPageControl);
procedure SetPageIndex(const Value: Integer);
procedure ReadPageControl(Reader: TReader);
procedure WritePageControl(Writer: TWriter);
procedure SetCaption(const Value: TCaption);
function GetTabVisible: Boolean;
procedure SetTabVisible(const Value: Boolean);
procedure DoShow();
procedure DoHide();
procedure SetImageIndex(const Value: Integer);
protected
procedure DefineProperties(Filer: TFiler); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner : TComponent); override;
procedure UpdateUIStyle(UIStyle: TsuiUIStyle; FileTheme : TsuiFileTheme);
property PageControl : TsuiPageControl read m_PageControl write SetPageControl;
published
property PageIndex : Integer read m_PageIndex write SetPageIndex;
property Caption : TCaption read m_Caption write SetCaption;
property TabVisible : Boolean read GetTabVisible write SetTabVisible;
property ImageIndex : Integer read m_ImageIndex write SetImageIndex;
property BiDiMode;
property Color;
property Constraints;
property UseDockManager default True;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnCanResize;
property OnClick;
property OnShow: TNotifyEvent read m_OnShow write m_OnShow;
property OnHide : TNotifyEvent read m_OnHide write m_OnHide;
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;
end;
// -------------- TsuiPageControl --------------------------
TsuiPageControl = class(TsuiTab)
private
m_PageList : TList;
m_ActivePage : TsuiTabSheet;
m_TempList : TStrings;
function NewPage() : TsuiTabSheet;
procedure ActivatePage(Page : TsuiTabSheet); overload;
procedure ActivatePage(nPageIndex : Integer); overload;
procedure RemovePage(Page: TsuiTabSheet);
procedure InsertPage(Page: TsuiTabSheet);
function GetCurPage() : TsuiTabSheet;
procedure MovePage(Page : TsuiTabSheet; var NewIndex : Integer);
procedure ActivateNextVisiblePage(CurPageIndex : Integer);
procedure UpdateTabVisible();
function FindNextVisiblePage(CurPageIndex : Integer) : Integer;
function FindPrevVisiblePage(CurPageIndex : Integer) : Integer;
procedure UpdateCaptions();
procedure UpdatePageIndex();
procedure CMCONTROLLISTCHANGE(var Msg : TMessage); message CM_CONTROLLISTCHANGE;
procedure CMCOLORCHANGED(var Msg : TMessage); message CM_COLORCHANGED;
procedure SetActivePage(const Value: TsuiTabSheet);
procedure ReadPages(Reader: TReader);
procedure WritePages(Writer: TWriter);
procedure ReSortPages();
function GetPageCount: Integer;
function GetPage(Index: Integer): TsuiTabSheet;
function GetActivePageIndex: Integer;
procedure SetActivePageIndex(const Value: Integer);
protected
function CreateTopPanel() : TsuiTabControlTopPanel; override;
procedure TabActive(TabIndex : Integer); override;
procedure DefineProperties(Filer: TFiler); override;
procedure BorderColorChanged(); override;
procedure ShowControl(AControl: TControl); override;
function GetImageIndex(PageId : Integer) : Integer; override;
public
constructor Create(AOwner : TComponent); override;
destructor Destroy(); override;
procedure UpdateUIStyle(UIStyle : TsuiUIStyle; FileTheme : TsuiFileTheme); override;
procedure SelectNextPage(GoForward: Boolean);
function FindNextPage(CurPage: TsuiTabSheet; GoForward : Boolean): TsuiTabSheet;
property Pages[Index: Integer]: TsuiTabSheet read GetPage;
property ActivePageIndex: Integer read GetActivePageIndex write SetActivePageIndex;
published
property ActivePage : TsuiTabSheet read m_ActivePage write SetActivePage;
property PageCount : Integer read GetPageCount;
end;
procedure PageControl_InsertPage(AComponent : TComponent);
procedure PageControl_RemovePage(AComponent : TComponent);
function PageControl_CanRemove(AComponent : TComponent) : Boolean;
procedure TabSheet_InsertPage(AComponent : TComponent);
procedure TabSheet_RemovePage(AComponent : TComponent);
function TabSheet_CanRemove(AComponent : TComponent) : Boolean;
implementation
uses SUIPublic;
var
l_EditorRemove : Boolean = false;
procedure PageControl_InsertPage(AComponent : TComponent);
begin
(AComponent as TsuiPageControl).NewPage();
end;
procedure PageControl_RemovePage(AComponent : TComponent);
var
TabSheet : TsuiTabSheet;
begin
with (AComponent as TsuiPageControl) do
begin
l_EditorRemove := true;
TabSheet := GetCurPage();
TabSheet.PageControl := nil;
TabSheet.Parent := nil;
TabSheet.Free();
l_EditorRemove := false;
end;
end;
function PageControl_CanRemove(AComponent : TComponent) : Boolean;
begin
if ((AComponent as TsuiPageControl).m_TopPanel.Tabs.Count = 0) then
Result := false
else
Result := true;
end;
procedure TabSheet_InsertPage(AComponent : TComponent);
begin
if (AComponent as TsuiTabSheet).PageControl <> nil then
(AComponent as TsuiTabSheet).PageControl.NewPage();
end;
procedure TabSheet_RemovePage(AComponent : TComponent);
begin
l_EditorRemove := true;
with (AComponent as TsuiTabSheet) do
begin
PageControl := nil;
Parent := nil;
Free();
end;
l_EditorRemove := false;
end;
function TabSheet_CanRemove(AComponent : TComponent) : Boolean;
begin
Result := false;
if (AComponent as TsuiTabSheet).PageControl = nil then
Exit;
if ((AComponent as TsuiTabSheet).PageControl.m_TopPanel.Tabs.Count = 0) then
Result := false
else
Result := true;
end;
{ TsuiPageControl }
procedure TsuiPageControl.ActivatePage(Page: TsuiTabSheet);
begin
if (m_ActivePage <> nil) and (m_ActivePage <> Page) then
begin
m_ActivePage.Enabled := false;
m_ActivePage.DoHide();
end;
m_ActivePage := Page;
if Page = nil then
Exit;
TabIndex := Page.PageIndex;
m_TopPanel.TabIndex := Page.PageIndex;
m_ActivePage.Visible := true;
m_ActivePage.Enabled := true;
m_ActivePage.BringToFront();
m_ActivePage.Repaint();
m_ActivePage.DoShow();
end;
procedure TsuiPageControl.ActivateNextVisiblePage(CurPageIndex: Integer);
var
i : Integer;
Found : Boolean;
begin
Found := false;
for i := CurPageIndex - 1 downto 0 do
begin
if TsuiTabSheet(m_PageList[i]).TabVisible then
begin
ActivatePage(i);
Found := true;
break;
end;
end;
if Found then
Exit;
for i := CurPageIndex + 1 to m_PageList.Count - 1 do
begin
if TsuiTabSheet(m_PageList[i]).TabVisible then
begin
ActivatePage(i);
break;
end;
end;
end;
procedure TsuiPageControl.ActivatePage(nPageIndex: Integer);
begin
if (m_ActivePage <> nil) and (m_ActivePage.PageIndex <> nPageIndex) then
begin
m_ActivePage.Enabled := false;
m_ActivePage.DoHide();
end;
if (
(nPageIndex > m_TopPanel.Tabs.Count - 1) or
(nPageIndex < 0)
) then
begin
ActivePage := nil;
Exit;
end;
TabIndex := nPageIndex;
m_TopPanel.TabIndex := nPageIndex;
m_ActivePage := TsuiTabSheet(m_PageList[nPageIndex]);
m_ActivePage.Visible := true;
m_ActivePage.Enabled := true;
m_ActivePage.BringToFront();
m_ActivePage.Repaint();
m_ActivePage.DoShow();
end;
procedure TsuiPageControl.BorderColorChanged;
var
i : Integer;
begin
if m_PageList = nil then
Exit;
for i := 0 to m_PageList.Count - 1 do
TsuiTabSheet(m_PageList[i]).m_BorderColor := BorderColor;
if m_ActivePage <> nil then
m_ActivePage.Repaint();
end;
procedure TsuiPageControl.CMCOLORCHANGED(var Msg: TMessage);
var
i : Integer;
begin
if m_PageList = nil then
Exit;
if csLoading in ComponentState then
Exit;
for i := 0 to m_PageList.Count - 1 do
TsuiTabSheet(m_PageList[i]).Color := Color;
end;
procedure TsuiPageControl.CMCONTROLLISTCHANGE(var Msg: TMessage);
begin
if not Boolean(Msg.LParam) then
begin // remove
if TControl(Msg.WParam) is TsuiTabSheet then
RemovePage(TsuiTabSheet(Msg.WParam));
end
else
begin // add
if TControl(Msg.WParam) is TsuiTabSheet then
InsertPage(TsuiTabSheet(Msg.WParam));
end;
end;
constructor TsuiPageControl.Create(AOwner: TComponent);
begin
inherited;
m_PageList := TList.Create();
m_TempList := TStringList.Create();
m_TopPanel.Tabs.Clear();
end;
function TsuiPageControl.CreateTopPanel: TsuiTabControlTopPanel;
begin
Result := TsuiPageControlTopPanel.Create(self, self);
end;
procedure TsuiPageControl.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineProperty(
'Pages',
ReadPages,
WritePages,
true
);
end;
destructor TsuiPageControl.Destroy;
var
i : Integer;
begin
for i := 0 to m_PageList.Count - 1 do
TsuiTabSheet(m_PageList[i]).m_PageControl := nil;
m_TempList.Free();
m_TempList := nil;
m_PageList.Free();
m_PageList := nil;
inherited;
end;
function TsuiPageControl.GetCurPage: TsuiTabSheet;
begin
Result := m_PageList[m_TopPanel.TabIndex];
end;
procedure TsuiPageControl.InsertPage(Page: TsuiTabSheet);
begin
Page.m_PageControl := self;
Page.Color := Color;
Page.m_BorderColor := BorderColor;
m_TopPanel.Tabs.Add(Page.Caption);
m_PageList.Add(Page);
UpdatePageIndex();
UpdateCaptions();
ActivatePage(Page);
end;
procedure TsuiPageControl.MovePage(Page: TsuiTabSheet; var NewIndex: Integer);
begin
if (NewIndex < 0) or (NewIndex > m_PageList.Count - 1) then
begin
NewIndex := Page.PageIndex;
Exit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -