📄 jvqpagelist.pas
字号:
procedure TJvCustomPage.DoShow;
begin
if Assigned(FOnShow) then
FOnShow(Self);
end;
procedure TJvCustomPage.ShowingChanged;
begin
inherited ShowingChanged;
if Showing then
try
DoShow
except
Application.HandleException(Self);
end
else
if not Showing then
try
DoHide;
except
Application.HandleException(Self);
end;
end;
function TJvCustomPage.WidgetFlags: Integer;
begin
Result := inherited WidgetFlags or Integer(WidgetFlags_WRepaintNoErase);
end;
//=== { TJvCustomPageList } ==================================================
constructor TJvCustomPageList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csAcceptsControls];
// IncludeThemeStyle(Self, [csParentBackground]);
FPages := TList.Create;
FHiddenPages := TList.Create;
Height := 200;
Width := 300;
FShowDesignCaption := sdcCenter;
ActivePageIndex := -1;
QWidget_setBackgroundMode(Handle, QWidgetBackgroundMode_NoBackground);
end;
destructor TJvCustomPageList.Destroy;
var
I: Integer;
begin
for I := FPages.Count - 1 downto 0 do
TJvCustomPage(FPages[I]).FPageList := nil;
FPages.Free;
FHiddenPages.Free;
inherited Destroy;
end;
function TJvCustomPageList.CanChange(AIndex: Integer): Boolean;
begin
Result := (AIndex >= 0) and (AIndex < GetPageCount);
if Result and Assigned(FOnChanging) then
FOnChanging(Self, AIndex, Result);
end;
procedure TJvCustomPageList.Change;
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TJvCustomPageList.CMDesignHitTest(var Msg: TCMDesignHitTest);
var
Pt: TPoint;
begin
inherited;
Pt := SmallPointToPoint(Msg.Pos);
if Assigned(ActivePage) and PtInRect(ActivePage.BoundsRect, Pt) then
Msg.Result := 1;
end;
procedure TJvCustomPageList.GetChildren(Proc: TGetChildProc;
Root: TComponent);
var
I: Integer;
Control: TControl;
begin
for I := 0 to FPages.Count - 1 do
Proc(TComponent(FPages[I]));
for I := 0 to ControlCount - 1 do
begin
Control := Controls[I];
if not (Control is TJvCustomPage) and (Control.Owner = Root) then
Proc(Control);
end;
end;
function TJvCustomPageList.GetPageCaption(AIndex: Integer): string;
begin
if (AIndex >= 0) and (AIndex < GetPageCount) then
Result := TJvCustomPage(FPages[AIndex]).Caption
else
Result := '';
end;
function TJvCustomPageList.InternalGetPageClass: TJvCustomPageClass;
begin
Result := TJvCustomPage;
end;
function TJvCustomPageList.GetPageCount: Integer;
begin
if FPages = nil then
Result := 0
else
Result := FPages.Count;
end;
procedure TJvCustomPageList.InsertPage(APage: TJvCustomPage);
begin
if (APage <> nil) and (FPages.IndexOf(APage) = -1) then
FPages.Add(APage);
end;
procedure TJvCustomPageList.Loaded;
begin
inherited Loaded;
if (GetPageCount > 0) and (ActivePage = nil) then
ActivePage := Pages[0];
end;
procedure TJvCustomPageList.Paint;
begin
if (csDesigning in ComponentState) and (GetPageCount = 0) then
with Canvas do
begin
Pen.Color := clBlack;
Pen.Style := psDot;
Brush.Style := bsClear;
Rectangle(ClientRect);
end;
end;
procedure TJvCustomPageList.RemovePage(APage: TJvCustomPage);
var
I: Integer;
NextPage: TJvCustomPage;
begin
NextPage := FindNextPage(APage, True, not (csDesigning in ComponentState));
if NextPage = APage then
NextPage := nil;
APage.Visible := False;
APage.FPageList := nil;
FPages.Remove(APage);
SetActivePage(NextPage);
// (ahuser) In some cases SetActivePage does not change FActivePage
// so we force FActivePage not to be "APage"
if (FActivePage = APage) or (FActivePage = nil) then
begin
FActivePage := nil;
for I := 0 to PageCount - 1 do
if Pages[I] <> APage then
begin
FActivePage := Pages[I];
Break;
end;
end;
end;
function TJvCustomPageList.GetPageFromIndex(AIndex: Integer): TJvCustomPage;
begin
if (AIndex >= 0) and (AIndex < GetPageCount) then
Result := TJvCustomPage(Pages[AIndex])
else
Result := nil;
end;
procedure TJvCustomPageList.SetActivePageIndex(AIndex: Integer);
begin
if (AIndex > -1) and (AIndex < PageCount) then
ActivePage := Pages[AIndex]
else
ActivePage := nil;
end;
procedure TJvCustomPageList.ShowControl(AControl: TControl);
begin
if AControl is TJvCustomPage then
ActivePage := TJvCustomPage(AControl);
inherited ShowControl(AControl);
end;
function TJvCustomPageList.GetPageClass: TJvCustomPageClass;
begin
Result := InternalGetPageClass;
end;
function TJvCustomPageList.HidePage(Page: TJvCustomPage): TJvCustomPage;
var
I: Integer;
begin
if (Page <> nil) and (Page.PageList = Self) then
begin
if ActivePage = Page then
NextPage;
if ActivePage = Page then
ActivePage := nil;
I := Page.PageIndex;
Page.PageList := nil;
Page.PageIndex := I;
Result := Page;
FHiddenPages.Add(Result);
end
else
Result := nil;
end;
function TJvCustomPageList.ShowPage(Page: TJvCustomPage; PageIndex: Integer): TJvCustomPage;
var
I: Integer;
begin
if (Page <> nil) and (Page.PageList = nil) then
begin
I := Page.PageIndex;
Page.PageList := Self;
Page.Parent := Self;
if PageIndex > -1 then
Page.PageIndex := PageIndex
else
if I > -1 then
Page.PageIndex := I;
Result := Page;
FHiddenPages.Remove(Result);
end
else
Result := nil;
end;
procedure TJvCustomPageList.SetActivePage(Page: TJvCustomPage);
var
ParentForm: TCustomForm;
begin
if GetPageCount = 0 then
FActivePage := nil;
if (Page = nil) or (Page.PageList <> Self) then
Exit
else
begin
ParentForm := GetParentForm(Self);
if (ParentForm <> nil) and (FActivePage <> nil) and
FActivePage.ContainsControl(ParentForm.ActiveControl) then
begin
ParentForm.ActiveControl := FActivePage;
if ParentForm.ActiveControl <> FActivePage then
begin
ActivePage := GetPageFromIndex(FActivePage.PageIndex);
Exit;
end;
end;
Page.BringToFront;
Page.Visible := True;
if (ParentForm <> nil) and (FActivePage <> nil) and (ParentForm.ActiveControl = FActivePage) then
begin
if Page.CanFocus then
ParentForm.ActiveControl := Page
else
ParentForm.ActiveControl := Self;
end;
Page.Refresh;
if CanChange(FPages.IndexOf(Page)) then
begin
if (FActivePage <> nil) and (FActivePage <> Page) then
FActivePage.Visible := False;
if (FActivePage <> Page) then
begin
FActivePage := Page;
Change;
end;
if (ParentForm <> nil) and (FActivePage <> nil) and
(ParentForm.ActiveControl = FActivePage) then
begin
FActivePage.SelectFirst;
end;
end;
end;
end;
function TJvCustomPageList.GetActivePageIndex: Integer;
begin
if ActivePage <> nil then
Result := ActivePage.PageIndex
else
Result := -1;
end;
procedure TJvCustomPageList.NextPage;
begin
if (ActivePageIndex < PageCount - 1) and (PageCount > 1) then
ActivePageIndex := ActivePageIndex + 1
else
if PageCount > 0 then
ActivePageIndex := 0
else
ActivePageIndex := -1;
end;
procedure TJvCustomPageList.PrevPage;
begin
if ActivePageIndex > 0 then
ActivePageIndex := ActivePageIndex - 1
else
ActivePageIndex := PageCount - 1;
end;
procedure TJvCustomPageList.SetPropagateEnable(const Value: Boolean);
begin
if FPropagateEnable <> Value then
begin
FPropagateEnable := Value;
UpdateEnabled;
end;
end;
procedure TJvCustomPageList.EnabledChanged;
begin
inherited EnabledChanged;
UpdateEnabled;
end;
function TJvCustomPageList.FindNextPage(CurPage: TJvCustomPage;
GoForward, IncludeDisabled: Boolean): TJvCustomPage;
var
I, StartIndex: Integer;
begin
if PageCount <> 0 then
begin
StartIndex := FPages.IndexOf(CurPage);
if StartIndex < 0 then
if GoForward then
StartIndex := FPages.Count - 1
else
StartIndex := 0;
I := StartIndex;
repeat
if GoForward then
begin
Inc(I);
if I >= FPages.Count - 1 then
I := 0;
end
else
begin
if I <= 0 then
I := FPages.Count - 1;
Dec(I);
end;
Result := Pages[I];
if IncludeDisabled or Result.Enabled then
Exit;
until I = StartIndex;
end;
Result := nil;
end;
procedure TJvCustomPageList.SetShowDesignCaption(const Value: TJvShowDesignCaption);
begin
if FShowDesignCaption <> Value then
begin
FShowDesignCaption := Value;
if HandleAllocated and (csDesigning in ComponentState) then
Invalidate;
end;
end;
procedure TJvCustomPageList.UpdateEnabled;
procedure InternalSetEnabled(AControl: TWinControl);
var
I: Integer;
begin
for I := 0 to AControl.ControlCount - 1 do
begin
AControl.Controls[I].Enabled := Self.Enabled;
if AControl.Controls[I] is TWinControl then
InternalSetEnabled(TWinControl(AControl.Controls[I]));
end;
end;
begin
if PropagateEnable then
InternalSetEnabled(Self);
end;
function TJvCustomPageList.GetPage(Index: Integer): TJvCustomPage;
begin
if (Index >= 0) and (Index < FPages.Count) then
Result := FPages[Index]
else
Result := nil;
end;
//===TJvPageList =============================================================
function TJvPageList.InternalGetPageClass: TJvCustomPageClass;
begin
Result := TJvStandardPage;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQPageList.pas,v $';
Revision: '$Revision: 1.23 $';
Date: '$Date: 2005/02/06 14:06:16 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -