📄 suipagecontrol.pas
字号:
end;
m_PageList.Move(Page.PageIndex, NewIndex);
UpdatePageIndex();
UpdateCaptions();
ActivatePage(Page);
end;
function TsuiPageControl.NewPage: TsuiTabSheet;
var
Form : TCustomForm;
begin
Result := TsuiTabSheet.Create(Owner);
Form := TCustomForm(Owner);
if Form <> nil then
Result.Name := Form.Designer.UniqueName('suiTabSheet')
else
Result.Name := 'suiTabSheet' + IntToStr(m_PageList.Count + 1);
Result.Caption := Result.Name;
Result.Parent := self;
Result.Align := alClient;
end;
procedure TsuiPageControl.ReadPages(Reader: TReader);
begin
Reader.ReadListBegin();
while not Reader.EndOfList() do
m_TempList.Add(Reader.ReadIdent());
Reader.ReadListEnd();
end;
procedure TsuiPageControl.RemovePage(Page: TsuiTabSheet);
begin
m_TopPanel.Tabs.Delete(Page.PageIndex);
m_PageList.Delete(Page.PageIndex);
UpdatePageIndex();
ActivatePage(Page.PageIndex - 1);
end;
procedure TsuiPageControl.ReSortPages;
function SortList(Item1, Item2: Pointer): Integer;
begin
if TsuiTabSheet(Item1).m_PageIndex < TsuiTabSheet(Item2).m_PageIndex then
Result := -1
else if TsuiTabSheet(Item1).m_PageIndex = TsuiTabSheet(Item2).m_PageIndex then
Result := 0
else
Result := 1;
end;
var
i : Integer;
begin
for i := 0 to m_PageList.Count - 1 do
TsuiTabSheet(m_PageList[i]).m_PageIndex := m_TempList.IndexOf(TsuiTabSheet(m_PageList[i]).Name);
m_PageList.Sort(@SortList);
UpdatePageIndex();
UpdateCaptions();
end;
procedure TsuiPageControl.SetActivePage(const Value: TsuiTabSheet);
begin
ActivatePage(Value);
end;
procedure TsuiPageControl.TabActive(TabIndex: Integer);
begin
if (m_ActivePage <> nil) and (m_ActivePage.PageIndex <> TabIndex) then
begin
m_ActivePage.Enabled := false;
m_ActivePage.DoHide();
end;
m_ActivePage := TsuiTabSheet(m_PageList[TabIndex]);
m_ActivePage.Visible := true;
m_ActivePage.Enabled := true;
m_ActivePage.BringToFront();
m_ActivePage.Repaint();
if not m_TopPanel.Focused then
begin
if (not (csLoading in ComponentState)) and (not (csDesigning in ComponentState)) then
begin
if (
(m_ActivePage.ControlCount > 0) and
(m_ActivePage.Controls[0] is TWinControl) and
(m_ActivePage.Controls[0].Visible) //"Fastream Technologies (http://www.fastream.com) fixed a bug here. Happy Coding!"
) then
try
if (m_ActivePage.Controls[0] as TWinControl).CanFocus() then
GetParentForm(self).ActiveControl := m_ActivePage.Controls[0] as TWinControl;
except
end;
end;
m_ActivePage.DoShow();
end;
inherited;
end;
procedure TsuiPageControl.UpdateCaptions;
var
i : Integer;
begin
m_TopPanel.Tabs.Clear();
for i := 0 to m_PageList.Count - 1 do
m_TopPanel.Tabs.Add(TsuiTabSheet(m_PageList[i]).Caption)
end;
procedure TsuiPageControl.UpdatePageIndex;
var
i : Integer;
begin
for i := 0 to m_PageList.Count - 1 do
TsuiTabSheet(m_PageList[i]).m_PageIndex := i;
end;
procedure TsuiPageControl.UpdateUIStyle(UIStyle: TsuiUIStyle; FileTheme : TsuiFileTheme);
var
i : Integer;
begin
if m_PageList = nil then
Exit;
for i := 0 to m_PageList.Count - 1 do
begin
TsuiTabSheet(m_PageList[i]).UpdateUIStyle(UIStyle, FileTheme);
TsuiTabSheet(m_PageList[i]).Color := Color;
TsuiTabSheet(m_PageList[i]).m_BorderColor := BorderColor;
TsuiTabSheet(m_PageList[i]).Align := alClient;
end;
end;
procedure TsuiPageControl.WritePages(Writer: TWriter);
var
i : Integer;
begin
Writer.WriteListBegin();
for i := 0 to m_PageList.Count - 1 do
Writer.WriteIdent(TsuiTabSheet(m_PageList[i]).Name);
Writer.WriteListEnd();
end;
procedure TsuiPageControl.UpdateTabVisible;
var
i : Integer;
begin
for i := 0 to m_PageList.Count - 1 do
m_TopPanel.m_TabVisible[i] := TsuiTabSheet(m_PageList[i]).m_TabVisible;
end;
function TsuiPageControl.GetPageCount: Integer;
begin
Result := m_PageList.Count;
end;
function TsuiPageControl.GetPage(Index: Integer): TsuiTabSheet;
begin
if (Index > m_PageList.Count - 1) or (Index < 0) then
Result := nil
else
Result := TsuiTabSheet(m_PageList[Index]);
end;
function TsuiPageControl.GetActivePageIndex: Integer;
begin
if m_ActivePage <> nil then
Result := m_ActivePage.PageIndex
else
Result := 0;
end;
procedure TsuiPageControl.SetActivePageIndex(const Value: Integer);
begin
if (Value > m_PageList.Count - 1) or (Value < 0) then
Exit;
ActivatePage(Value);
end;
procedure TsuiPageControl.SelectNextPage(GoForward: Boolean);
begin
if m_ActivePage = nil then
Exit;
ActivatePage(FindNextPage(m_ActivePage, GoForward));
end;
function TsuiPageControl.FindNextVisiblePage(CurPageIndex: Integer) : Integer;
var
i : Integer;
Found : Boolean;
begin
Result := -1;
Found := false;
for i := CurPageIndex + 1 to m_PageList.Count - 1 do
begin
if TsuiTabSheet(m_PageList[i]).TabVisible then
begin
Result := i;
Found := true;
break;
end;
end;
if Found then
Exit;
for i := 0 to CurPageIndex - 1 do
begin
if TsuiTabSheet(m_PageList[i]).TabVisible then
begin
Result := i;
break;
end;
end;
end;
function TsuiPageControl.FindPrevVisiblePage(CurPageIndex: Integer) : Integer;
var
i : Integer;
Found : Boolean;
begin
Result := -1;
Found := false;
for i := CurPageIndex - 1 downto 0 do
begin
if TsuiTabSheet(m_PageList[i]).TabVisible then
begin
Result := i;
Found := true;
break;
end;
end;
if Found then
Exit;
for i := m_PageList.Count - 1 downto CurPageIndex + 1 do
begin
if TsuiTabSheet(m_PageList[i]).TabVisible then
begin
Result := i;
break;
end;
end;
end;
function TsuiPageControl.FindNextPage(CurPage: TsuiTabSheet; GoForward: Boolean): TsuiTabSheet;
var
NextPage : Integer;
begin
Result := nil;
if GoForward then
NextPage := FindNextVisiblePage(CurPage.PageIndex)
else
NextPage := FindPrevVisiblePage(CurPage.PageIndex);
if NextPage <> -1 then
Result := m_PageList[NextPage];
end;
procedure TsuiPageControl.ShowControl(AControl: TControl);
begin
inherited;
if not (AControl is TsuiTabSheet) then
Exit;
ActivatePage(AControl as TsuiTabSheet);
end;
function TsuiPageControl.GetImageIndex(PageId: Integer): Integer;
begin
if Pages[PageId] <> nil then
Result := Pages[PageId].ImageIndex
else
Result := -1;
end;
{ TsuiPageControlTopPanel }
procedure TsuiPageControlTopPanel.CMDesignHitTest(var Msg: TCMDesignHitTest);
var
HitPos : TPoint;
Form : TCustomForm;
begin
if Msg.Keys = MK_LBUTTON then
begin
HitPos := SmallPointToPoint(Msg.Pos);
MouseDown(mbLeft, [], HitPos.X, HitPos.Y);
if Owner.Owner is TCustomForm then
begin
Form := TCustomForm(Owner.Owner);
if Form <> nil then
Form.Designer.Modified();
end;
Msg.Result := 0;
end;
end;
{ TsuiTabSheet }
constructor TsuiTabSheet.Create(AOwner: TComponent);
begin
inherited;
inherited Caption := ' ';
m_PageIndex := -1;
m_ImageIndex := -1;
m_TabVisible := true;
BevelInner := bvNone;
BevelOuter := bvNone;
BorderWidth := 0;
Align := alClient;
end;
procedure TsuiTabSheet.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineProperty(
'PageControl',
ReadPageControl,
WritePageControl,
true
);
end;
procedure TsuiTabSheet.DoHide;
begin
if Assigned(m_OnHide) then
m_OnHide(self);
end;
procedure TsuiTabSheet.DoShow;
begin
if Assigned(m_OnShow) then
m_OnShow(Self);
end;
function TsuiTabSheet.GetTabVisible: Boolean;
begin
Result := m_PageControl.m_TopPanel.m_TabVisible[PageIndex];
end;
procedure TsuiTabSheet.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if l_EditorRemove then
Exit;
if m_PageControl = nil then
Exit;
if (Operation = opRemove) and (AComponent = self) then
Parent := nil;
end;
procedure TsuiTabSheet.ReadPageControl(Reader: TReader);
begin
m_PageControl := TsuiPageControl(Owner.FindComponent(Reader.ReadIdent()));
if m_PageControl = nil then
Exit;
if m_PageControl.m_PageList.Count = m_PageControl.m_TempList.Count then
begin
m_PageControl.ReSortPages();
m_PageControl.UpdateTabVisible();
end;
end;
procedure TsuiTabSheet.SetCaption(const Value: TCaption);
begin
m_Caption := Value;
if m_PageControl = nil then
Exit;
m_PageControl.UpdateCaptions();
end;
procedure TsuiTabSheet.SetImageIndex(const Value: Integer);
begin
if m_PageControl = nil then
Exit;
m_ImageIndex := Value;
m_PageControl.m_TopPanel.Repaint();
end;
procedure TsuiTabSheet.SetPageControl(const Value: TsuiPageControl);
begin
m_PageControl := Value;
if m_PageControl = nil then
Exit;
Parent := m_PageControl;
end;
procedure TsuiTabSheet.SetPageIndex(const Value: Integer);
var
NewIndex : Integer;
begin
if m_PageControl = nil then
Exit;
NewIndex := Value;
m_PageControl.MovePage(self, NewIndex);
m_PageIndex := NewIndex;
end;
procedure TsuiTabSheet.SetTabVisible(const Value: Boolean);
begin
m_TabVisible := Value;
if m_PageControl = nil then
Exit;
m_PageControl.m_TopPanel.m_TabVisible[PageIndex] := Value;
m_PageControl.m_TopPanel.Repaint();
if (not Value) and (m_PageControl.ActivePage = self) then
m_PageControl.ActivateNextVisiblePage(PageIndex)
// else
// m_PageControl.ActivatePage(PageIndex);
end;
procedure TsuiTabSheet.UpdateUIStyle(UIStyle: TsuiUIStyle; FileTheme : TsuiFileTheme);
begin
ContainerApplyUIStyle(self, UIStyle, FileTheme);
end;
procedure TsuiTabSheet.WritePageControl(Writer: TWriter);
begin
if m_PageControl <> nil then
Writer.WriteIdent(m_PageControl.Name);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -