Patch from Hans-Peter, starts fixing TTabControl, from bug #19575

git-svn-id: trunk@31686 -
This commit is contained in:
sekelsenmat 2011-07-13 12:43:43 +00:00
parent e0e4d9ce23
commit ca84ba2f7f
10 changed files with 254 additions and 89 deletions

View File

@ -8310,7 +8310,7 @@ var
begin
Result := nil;
for i := FSourceWindowList.Count-1 downto 0 do begin
if TSourceNotebook(SourceWindows[i]).FNoteBook.PageList.IndexOf(APage) >= 0 then begin
if TSourceNotebook(SourceWindows[i]).FNoteBook.IndexOf(APage) >= 0 then begin
Result := SourceWindows[i];
break;
end;

View File

@ -6342,7 +6342,7 @@ begin
if not (AComponent is TCustomNotebook) then
raise Exception.Create('invalid instance for this property editor');
Notebook:=TCustomNotebook(AComponent);
if Notebook.PageList.IndexOf(APersistent)<0 then
if Notebook.IndexOf(APersistent)<0 then
raise Exception.Create('only children are allowed for this property');
end;
@ -6361,8 +6361,8 @@ begin
AComponent:=GetComponent(0);
if not (AComponent is TCustomNotebook) then exit;
Notebook:=TCustomNotebook(AComponent);
for i:=0 to Notebook.PageList.Count-1 do
Proc(TComponent(Notebook.PageList[i]).Name);
for i:=0 to Notebook.PageCount-1 do
Proc(Notebook.Page[i].Name);
end;
{ TCustomShortCutGrabBox }

View File

@ -225,7 +225,6 @@ type
FImageIndex: TImageIndex;
FOnHide: TNotifyEvent;
FOnShow: TNotifyEvent;
function GetTabVisible: Boolean;
procedure SetImageIndex(const AValue: TImageIndex);
procedure SetTabVisible(const AValue: Boolean);
protected
@ -234,8 +233,9 @@ type
procedure SetParent(AParent: TWinControl); override;
property Flags: TPageFlags read FFlags write FFlags;
procedure CMHitTest(var Message: TLMNCHITTEST); message CM_HITTEST;
function GetPageIndex: integer;
procedure SetPageIndex(AValue: Integer);
function GetPageIndex: integer; virtual;
procedure SetPageIndex(AValue: Integer); virtual;
function GetTabVisible: Boolean; virtual;
function DialogChar(var Message: TLMKey): boolean; override;
procedure DoHide; virtual;
procedure DoShow; virtual;
@ -246,7 +246,7 @@ type
function CanTab: boolean; override;
function IsControlVisible: Boolean; override;
function HandleObjectShouldBeVisible: boolean; override;
function VisibleIndex: integer;
function VisibleIndex: integer; virtual;
property PageIndex: Integer read GetPageIndex write SetPageIndex;
property TabVisible: Boolean read GetTabVisible write SetTabVisible default True;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
@ -292,6 +292,8 @@ type
TTabPosition = (tpTop, tpBottom, tpLeft, tpRight);
TTabStyle = (tsTabs, tsButtons, tsFlatButtons);
TTabGetImageEvent = procedure(Sender: TObject; TabIndex: Integer;
var ImageIndex: Integer) of object;
@ -300,24 +302,36 @@ type
TNoteBookCapability = (nbcShowCloseButtons, nbcMultiLine, nbcPageListPopup);
TNoteBookCapabilities = set of TNoteBookCapability;
TDrawTabEvent = procedure(Control: TCustomNotebook; TabIndex: Integer;
const Rect: TRect; Active: Boolean) of object;
TCustomNotebook = class(TWinControl)
private
FAccess: TStrings; // TNBPages
FAddingPages: boolean;
FHotTrack: Boolean;
FImages: TImageList;
FImageListChangeLink: TChangeLink;
FLoadedPageIndex: integer;
FMultiSelect: Boolean;
FOnChanging: TTabChangingEvent;
FOnCloseTabClicked: TNotifyEvent;
FOnDrawTab: TDrawTabEvent;
FOnGetImageIndex: TTabGetImageEvent;
FOnPageChanged: TNotifyEvent;
FOptions: TNoteBookOptions;
FOwnerDraw: Boolean;
FPageIndex: Integer;
FPageIndexOnLastChange: integer;// needed for unique OnChange events
FPageIndexOnLastShow: integer;
FPageList: TList; // TListWithEvent of TCustomPage
FRaggedRight: Boolean;
FScrollOpposite: Boolean;
FShowTabs: Boolean;
FStyle: TTabStyle;
FTabHeight: Smallint;
FTabPosition: TTabPosition;
FTabWidth: Smallint;
procedure CNNotify(var Message: TLMNotify); message CN_NOTIFY;
procedure DoSendPageIndex;
procedure DoSendShowTabs;
@ -325,19 +339,15 @@ type
procedure DoImageListChange(Sender: TObject);
function GetActivePage: String;
function GetActivePageComponent: TCustomPage;
function GetDisplayRect: TRect;
function GetMultiLine: Boolean;
function GetPage(AIndex: Integer): TCustomPage;
function GetPageCount : integer;
function GetPageIndex: Integer;
function FindVisiblePage(Index: Integer): Integer;
procedure InsertPage(APage: TCustomPage; Index: Integer);
function IsStoredActivePage: boolean;
procedure AddRemovePageHandle(APage: TCustomPage);
procedure MoveTab(Sender: TObject; NewIndex: Integer);
procedure SetMultiLine(const AValue: Boolean);
procedure WSMovePage(APage: TCustomPage; NewIndex: Integer);
procedure PageRemoved(Index: Integer);
procedure RemovePage(Index: Integer);
procedure SetActivePage(const Value: String);
procedure SetActivePageComponent(const AValue: TCustomPage);
procedure SetImages(const AValue: TImageList);
@ -368,18 +378,39 @@ type
write SetActivePageComponent;
property ActivePage: String read GetActivePage write SetActivePage
stored IsStoredActivePage;
protected //elevated visibility for un/paged
FUnPaged: boolean; //false iff unpaged (TabControl)
function GetPage(AIndex: Integer): TCustomPage; virtual;
function GetPageCount : integer; virtual;
procedure InsertPage(APage: TCustomPage; Index: Integer); virtual;
procedure RemovePage(Index: Integer); virtual;
//Delphi compatible properties
property DisplayRect: TRect read GetDisplayRect;
property HotTrack: Boolean read FHotTrack write FHotTrack default False;
property MultiSelect: Boolean read FMultiSelect write FMultiSelect default False;
property OwnerDraw: Boolean read FOwnerDraw write FOwnerDraw default False;
property RaggedRight: Boolean read FRaggedRight write FRaggedRight default False;
property ScrollOpposite: Boolean read FScrollOpposite write FScrollOpposite default False;
property Style: TTabStyle read FStyle write FStyle default tsTabs;
property TabHeight: Smallint read FTabHeight write FTabHeight default 0;
property TabIndex: Integer read FPageIndex write SetPageIndex default -1;
property TabWidth: Smallint read FTabWidth write FTabWidth default 0;
property OnChange: TNotifyEvent read FOnPageChanged write FOnPageChanged;
property OnDrawTab: TDrawTabEvent read FOnDrawTab write FOnDrawTab;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function TabIndexAtClientPos(ClientPos: TPoint): integer;
function TabRect(AIndex: Integer): TRect;
function GetImageIndex(ThePageIndex: Integer): Integer; virtual;
function IndexOf(APage: TCustomPage): integer;
function IndexOf(APage: TPersistent): integer; virtual;
function CustomPage(Index: integer): TCustomPage;
function CanChangePageIndex: boolean; virtual;
function GetMinimumTabWidth: integer; virtual;
function GetMinimumTabHeight: integer; virtual;
function GetCapabilities: TNoteBookCapabilities; virtual;
function TabToPageIndex(AIndex: integer): integer;
function PageToTabIndex(AIndex: integer): integer;
public
procedure DoCloseTabClicked(APage: TCustomPage); virtual;
property Images: TImageList read FImages write SetImages;
@ -393,11 +424,12 @@ type
property Options: TNoteBookOptions read FOptions write SetOptions default [];
property Page[Index: Integer]: TCustomPage read GetPage;
property PageCount: integer read GetPageCount;
property PageIndex: Integer read GetPageIndex write SetPageIndex default -1;
property PageList: TList read FPageList;
property PageIndex: Integer read FPageIndex write SetPageIndex default -1;
//property PageList: TList read FPageList; - iff paged
property Pages: TStrings read FAccess write SetPages;
property ShowTabs: Boolean read FShowTabs write SetShowTabs default True;
property TabPosition: TTabPosition read FTabPosition write SetTabPosition default tpTop;
property IsUnpaged: boolean read FUnPaged;
published
property TabStop default true;
end;
@ -406,11 +438,6 @@ type
TPageControl = class;
// TTabPosition is in extctrls.pas
TTabStyle = (tsTabs, tsButtons, tsFlatButtons);
{ TTabSheet }
TTabSheet = class(TCustomPage)
private
function GetPageControl: TPageControl;
@ -465,14 +492,11 @@ type
TPageControl = class(TCustomNotebook)
private
FPageToUndock: TTabSheet;
FOnChange: TNotifyEvent;
function GetActivePageIndex: Integer;
function GetActiveTabSheet: TTabSheet;
function GetTabIndex: Integer;
function GetTabSheet(Index: Integer): TTabSheet;
procedure SetActivePageIndex(const AValue: Integer);
procedure SetActiveTabSheet(const AValue: TTabSheet);
procedure SetTabIndex(const AValue: Integer);
function FindPageWithDockClient(Client: TControl): TTabSheet;
protected
class procedure WSRegisterClass; override;
@ -520,13 +544,13 @@ type
property ShowTabs;
//property Style;
//property TabHeight;
property TabIndex: Integer read GetTabIndex write SetTabIndex default -1;
property TabIndex;
property TabOrder;
property TabPosition;
property TabStop;
//property TabWidth;
property Visible;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChange;
property OnChanging;
property OnCloseTabClicked;
property OnContextPopup;
@ -554,7 +578,6 @@ type
property Options;
end;
TCustomTabControl = class;
{ TTabControlStrings }
@ -650,9 +673,6 @@ type
{ TCustomTabControl }
TDrawTabEvent = procedure(Control: TCustomTabControl; TabIndex: Integer;
const Rect: TRect; Active: Boolean) of object;
TCustomTabControl = class(TCustomControl)
private
@ -811,6 +831,81 @@ type
end;
{ TTabs }
(* TTabs is a replacement for TTabControl, derived from TCustomNotebook.
TTabPage is a dummy page, for communication with the widgetsets.
TTabPages holds the tabs (Strings[] and Objects[]).
*)
TTabs = class(TCustomNotebook)
protected
procedure DoChange; override;
function GetPage(AIndex: Integer): TCustomPage; override;
procedure InsertPage(APage: TCustomPage; Index: Integer); override;
procedure RemovePage(Index: Integer); override;
public
constructor Create(TheOwner: TComponent); override;
function IndexOf(APage: TPersistent): integer; override;
function IndexOfTabWithCaption(const TabCaption: string): Integer;
published //copied from TTabControl
property Align;
property Anchors;
property BorderSpacing;
property Constraints;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HotTrack;
property Images;
property MultiLine;
property MultiSelect;
property OnChange;
property OnChangeBounds;
property OnChanging;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnDrawTab;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetImageIndex;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property OwnerDraw;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property RaggedRight;
property ScrollOpposite;
property ShowHint;
property Style;
property TabHeight;
property TabCount: integer read GetPageCount;
property TabIndex: Integer read FPageIndex write SetPageIndex default -1;
property TabOrder;
property TabPosition;
property Tabs: TStrings read FAccess write SetPages;
property TabStop;
property TabWidth;
property Visible;
end;
{ Custom draw }
TCustomDrawTarget = (
@ -3306,6 +3401,7 @@ const
{$I tabsheet.inc}
{$I pagecontrol.inc}
{$I tabcontrol.inc}
{$I tabctl.inc}
{$I listcolumns.inc}
{$I listcolumn.inc}
{$I listitem.inc}
@ -3382,7 +3478,7 @@ end;
procedure Register;
begin
RegisterComponents('Common Controls',[TTrackbar,TProgressBar,TTreeView,
TListView,TStatusBar,TToolBar,TUpDown,TPageControl,TTabControl, THeaderControl]);
TListView,TStatusBar,TToolBar,TUpDown,TPageControl,TTabControl,{$IFDEF LCL_REGISTER_TTABS}TTabs,{$ENDIF} THeaderControl]);
RegisterNoIcon([TToolButton,TTabSheet]);
end;

View File

@ -206,11 +206,14 @@ begin
fCompStyle := csNoteBook;
FPageList := TListWithEvent.Create;
if not FUnPaged then begin
FPageList := TListWithEvent.Create;
fAccess := TNBPages.Create(TListWithEvent(fPageList), Self);
end;
FImageListChangeLink := TChangeLink.Create;
FImageListChangeLink.OnChange := @DoImageListChange;
fAccess := TNBPages.Create(TListWithEvent(fPageList), Self);
FPageIndex := -1;
FLoadedPageIndex:=-1;
FPageIndexOnLastShow:=-1;
@ -255,7 +258,7 @@ begin
DisableAlign;
try
FAddingPages := True;
for i := 0 to FPageList.Count -1 do
for i := 0 to PageCount -1 do
begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TCustomNotebook.DoCreateWnd ',dbgsName(Self),' Page.Caption=',Page[i].Caption,' pfAdded=',pfAdded in Page[i].Flags]);
@ -291,7 +294,7 @@ begin
FImageListChangeLink.Free;
Pages.Clear;
FreeAndNil(FAccess);
FreeAndNil(FPageList);
FreeAndNil(fPageList);
inherited Destroy;
end;
@ -332,9 +335,12 @@ begin
OnGetImageIndex(Self, ThePageIndex, Result);
end;
function TCustomNotebook.IndexOf(APage: TCustomPage): integer;
function TCustomNotebook.IndexOf(APage: TPersistent): integer;
begin
Result:=FPageList.IndexOf(APage);
if FUnPaged then
Result := -1
else
Result:=FPageList.IndexOf(APage);
end;
function TCustomNotebook.CustomPage(Index: integer): TCustomPage;
@ -366,6 +372,45 @@ begin
Result:=TWSCustomNotebookClass(WidgetSetClass).GetCapabilities;
end;
function TCustomNotebook.PageToTabIndex(AIndex: integer): integer;
var
i: integer;
begin
(* Map LCL Page into widgetset Tab index.
Taken from TWin32WSCustomNotebook.GetPageRealIndex (modified)
*)
if (AIndex < 0) or (AIndex >= PageCount) then
exit(-1);
Result := AIndex;
if csDesigning in ComponentState then
exit; //all pages are visible
for i := 0 to AIndex - 1 do begin
if not Page[i].TabVisible then
dec(Result); //exclude invisible page
end;
end;
function TCustomNotebook.TabToPageIndex(AIndex: integer): integer;
var
I: integer;
begin
(* Map widgetset Tab index into LCL Page index.
Taken from win32 NotebookPageRealToLCLIndex
*)
Result := AIndex;
if FUnPaged or (csDesigning in ComponentState) then
exit; //all pages are visible
I := 0;
while (I < PageCount) and (I <= Result) do
begin
if not Page[I].TabVisible then
Inc(Result); //insert invisible page
Inc(I);
end;
end;
{------------------------------------------------------------------------------
method TCustomNotebook DoCloseTabClicked
Params: APage: TCustomPage
@ -384,7 +429,7 @@ end;
function TCustomNotebook.GetActivePage: String;
begin
if (FPageIndex >= 0) and (FPageIndex < PageCount) then
Result := TCustomPage(FPageList[FPageIndex]).Caption
Result := Page[FPageIndex].Caption
else
Result := '';
end;
@ -400,6 +445,11 @@ begin
Result := nil;
end;
function TCustomNotebook.GetDisplayRect: TRect;
begin
Result := GetClientRect; //???
end;
function TCustomNotebook.GetMultiLine: Boolean;
begin
Result := nboMultiLine in Options;
@ -412,9 +462,9 @@ procedure TCustomNotebook.SetActivePage(const Value: String);
var
i: Integer;
begin
for i := 0 to FPageList.Count - 1 do
for i := 0 to PageCount - 1 do
begin
if TCustomPage(FPageList[i]).Caption = Value then
if Page[i].Caption = Value then
begin
SetPageIndex(i);
Exit;
@ -424,7 +474,8 @@ end;
procedure TCustomNotebook.SetActivePageComponent(const AValue: TCustomPage);
begin
PageIndex := FPageList.IndexOf(AValue);
if not FUnPaged then
PageIndex := FPageList.IndexOf(AValue);
end;
procedure TCustomNotebook.SetImages(const AValue: TImageList);
@ -471,12 +522,14 @@ begin
//debugln('TCustomNotebook.SetPageIndex B ',dbgsName(Self),' AValue=',dbgs(AValue),' fPageIndex=',dbgs(fPageIndex),' PageCount=',dbgs(PageCount),' HandleAllocated=',dbgs(HandleAllocated));
FPageIndex := AValue;
UpdateAllDesignerFlags;
if not FUnPaged then
UpdateAllDesignerFlags;
DoSendPageIndex;
if ([csDesigning, csLoading, csDestroying] * ComponentState = []) then
DoChange;
end;
{$IFDEF old}
{------------------------------------------------------------------------------
TCustomNotebook GetPageIndex
------------------------------------------------------------------------------}
@ -484,20 +537,23 @@ function TCustomNotebook.GetPageIndex: Integer;
begin
Result := FPageIndex;
end;
{$ELSE}
//if override is required, make virtual first!
{$ENDIF}
procedure TCustomNotebook.InsertPage(APage: TCustomPage; Index: Integer);
var
NewZPosition: integer;
begin
if FPageList.IndexOf(APage) >= 0 then Exit;
if FUnPaged or (IndexOf(APage) >= 0) then Exit;
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TCustomNotebook.InsertPage A ',dbgsName(Self),' Index=',Index,' Name=',
APage.Name,' Caption=',APage.Caption]);
{$ENDIF}
APage.DisableAlign;
try
if Index < FPageList.Count then
NewZPosition := GetControlIndex(TCustomPage(fPageList[Index]))
if Index < PageCount then
NewZPosition := GetControlIndex(Page[Index])
else
NewZPosition := -1;
Include(APage.FFlags, pfInserting);
@ -556,12 +612,12 @@ end;
function TCustomNotebook.FindVisiblePage(Index: Integer): Integer;
begin
for Result := Index to FPageList.Count - 1 do
if TCustomPage(FPageList[Result]).TabVisible then
for Result := Index to PageCount - 1 do
if Page[Result].TabVisible then
exit;
// if arrived here no visible forward page was found, search backwards
for Result := Index - 1 downto 0 do
if TCustomPage(FPageList[Result]).TabVisible then
if Page[Result].TabVisible then
exit;
Result := -1;
end;
@ -641,11 +697,11 @@ begin
// Make sure Index is in the range of valid pages to delete
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TCustomNotebook.RemovePage A ',dbgsName(Self),' Index=',Index,
' FPageList.Count=',FPageList.Count,' PageIndex=',PageIndex]);
' FPageList.Count=',PageCount,' PageIndex=',PageIndex]);
{$ENDIF}
if (Index >= 0) and (Index < FPageList.Count) then
if not FUnPaged and (Index >= 0) and (Index < PageCount) then
begin
APage:=TCustomPage(fPageList[Index]);
APage:=Page[Index];
APage.FTabVisible:=false;
if HandleAllocated then
AddRemovePageHandle(APage);
@ -673,7 +729,10 @@ end;
------------------------------------------------------------------------------}
function TCustomNotebook.GetPageCount: Integer;
begin
Result := fPageList.Count;
if FUnPaged then
Result := FAccess.Count
else
Result := fPageList.Count;
end;
{------------------------------------------------------------------------------
@ -689,7 +748,7 @@ end;
------------------------------------------------------------------------------}
function TCustomNotebook.GetPage(AIndex: Integer): TCustomPage;
begin
if (AIndex < 0) or (AIndex >= FPageList.Count) then
if (AIndex < 0) or (AIndex >= PageCount) then
RaiseGDBException('TCustomNotebook.GetCustomPage Index out of bounds');
Result := TCustomPage(FPageList.Items[AIndex]);
end;
@ -721,6 +780,8 @@ procedure TCustomNotebook.UpdateAllDesignerFlags;
var
i: integer;
begin
if FUnPaged then
exit;
for i:=0 to PageCount-1 do
UpdateDesignerFlags(i);
end;
@ -765,8 +826,8 @@ begin
{ Find a child control that matches the one passed in and display
the page that contains that control. This method is necessary
for compatibility with Delphi }
for i := 0 to fPageList.Count - 1 do begin
if TControl(fPageList[i]) = APage then begin
for i := 0 to PageCount - 1 do begin
if Page[i] = APage then begin
PageIndex := i;
Exit;
end;

View File

@ -130,7 +130,7 @@ begin
begin
// add to new pagelist
ParentNotebook := TCustomNotebook(Parent);
i := ParentNotebook.PageList.IndexOf(Self);
i := ParentNotebook.IndexOf(Self);
if i < 0 then
ParentNotebook.InsertPage(Self, ParentNotebook.PageCount);
end;
@ -160,7 +160,7 @@ end;
function TCustomPage.GetPageIndex: integer;
begin
if (Parent <> nil) and (Parent is TCustomNotebook) then
Result := TCustomNotebook(Parent).PageList.IndexOf(Self)
Result := TCustomNotebook(Parent).IndexOf(Self)
else
Result := -1;
end;
@ -232,23 +232,28 @@ end;
function TCustomPage.VisibleIndex: integer;
// returns the visible index, as if TabVisible=true
var
List: TList;
notebook: TCustomNotebook;
i: Integer;
begin
(* Removed PageList dependency.
Added missing result value.
*)
if (Parent <> nil) and (Parent is TCustomNotebook) then
begin
Result := 0;
List := TCustomNotebook(Parent).PageList;
//List := TCustomNotebook(Parent).PageList;
notebook := TCustomNotebook(Parent);
i := 0;
repeat
if i = List.Count then exit(-1);
if (TObject(List[i]) = Self) then exit;
if TCustomPage(List[i]).TabVisible or (csDesigning in ComponentState)
if i = notebook.PageCount then exit(-1);
if notebook.Page[i] = Self then exit;
if (csDesigning in ComponentState) or notebook.Page[i].TabVisible
then inc(Result);
inc(i);
until False;
end else
Result := -1;
end;
// else
Result := -1;
end;
{------------------------------------------------------------------------------

View File

@ -33,11 +33,6 @@ begin
Result:=TTabSheet(inherited ActivePageComponent);
end;
function TPageControl.GetTabIndex: Integer;
begin
Result:=inherited PageIndex;
end;
function TPageControl.GetTabSheet(Index: Integer): TTabSheet;
begin
Result:=TTabSheet(inherited Page[Index]);
@ -53,11 +48,6 @@ begin
ActivePageComponent := AValue;
end;
procedure TPageControl.SetTabIndex(const AValue: Integer);
begin
inherited PageIndex := Avalue;
end;
function TPageControl.FindPageWithDockClient(Client: TControl): TTabSheet;
var
i: integer;

View File

@ -479,7 +479,7 @@ procedure TCustomTabControl.DrawTab(ATabIndex: Integer; const Rect: TRect;
Active: Boolean);
begin
if Assigned(FOnDrawTab) then
FOnDrawTab(Self,TabIndex,Rect,Active)
FOnDrawTab(TCustomNotebook(Self),TabIndex,Rect,Active)
else
Canvas.FillRect(Rect);
end;

View File

@ -59,17 +59,8 @@ begin
end;
function NotebookPageRealToLCLIndex(const ANotebook: TCustomNotebook; AIndex: integer): integer;
var
I: Integer;
begin
Result := AIndex;
if csDesigning in ANotebook.ComponentState then exit;
I := 0;
while (I < ANotebook.PageCount) and (I <= Result) do
begin
if not ANotebook.Page[I].TabVisible then Inc(Result);
Inc(I);
end;
Result := ANotebook.TabToPageIndex(AIndex);
end;
function ShowHideTabPage(NotebookHandle: HWnd; Showing: boolean): integer;
@ -83,7 +74,13 @@ begin
Notebook := GetWin32WindowInfo(NotebookHandle)^.WinControl as TCustomNotebook;
PageIndex := Windows.SendMessage(NotebookHandle, TCM_GETCURSEL, 0, 0);
PageIndex := NotebookPageRealToLCLIndex(Notebook, PageIndex);
if PageIndex = -1 then exit;
if NoteBook.IsUnpaged then
exit(PageIndex);
if PageIndex = -1 then
exit(PageIndex); //DONE: must return something!
PageHandle := Notebook.CustomPage(PageIndex).Handle;
Windows.SetWindowPos(PageHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or ShowFlags[Showing]);
Windows.RedrawWindow(PageHandle, nil, 0, RDW_INVALIDATE or RDW_ALLCHILDREN or RDW_ERASE);
@ -332,7 +329,8 @@ begin
// but on windows page handle is differ from tab and thus allocation can be
// postponed, but this cause problems with event handling like bug #0012434
// so to overcome such problems we need to allocate this handle
AChild.HandleNeeded;
if not ANotebook.IsUnpaged then
AChild.HandleNeeded;
if ShowTabs then
begin
TCI.Mask := TCIF_TEXT or TCIF_PARAM or TCIF_IMAGE;
@ -465,6 +463,7 @@ begin
AdjustSizeNotebookPages(ANotebook);
end;
{$IFDEF old}
class function TWin32WSCustomNotebook.GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer;
var
X: Integer;
@ -474,6 +473,8 @@ begin
for X := 0 to AIndex - 1 do
if ANotebook.Page[X].TabVisible = False then Dec(Result);
end;
{$ELSE}
{$ENDIF}
procedure SendSelChangeMessage(const ANotebook: TCustomNotebook; const AHandle: HWND;
const APageIndex: integer);
@ -565,6 +566,10 @@ begin
NewRealIndex := GetPageRealIndex(ANotebook, AIndex);
SendMessage(NotebookHandle, TCM_SETCURSEL, Windows.WParam(NewRealIndex), 0);
if ANotebook.IsUnpaged then
exit; //all done
if not (csDestroying in ANotebook.ComponentState) then
begin
// create handle if not already done, need to show!

View File

@ -70,7 +70,11 @@ type
class procedure RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
{$IFDEF old}
class function GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer; override;
{$ELSE}
//use ANotebook.PageToTabIndex (and .TabToPageIndex)
{$ENDIF}
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; override;
class function GetCapabilities: TNoteBookCapabilities;override;

View File

@ -68,7 +68,7 @@ type
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; virtual;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; virtual;
class function GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer; virtual;
class function GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer; //virtual;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; virtual;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; virtual;
class function GetCapabilities: TNoteBookCapabilities; virtual;
@ -342,7 +342,11 @@ end;
class function TWSCustomNotebook.GetPageRealIndex(const ANotebook: TCustomNotebook;
AIndex: Integer): Integer;
begin
Result := AIndex;
(* Get the Tab index from Page index.
No need to override, everything handled in the notebook.
*)
//Result := AIndex;
Result := ANotebook.PageToTabIndex(AIndex);
end;
class function TWSCustomNotebook.GetTabIndexAtPos(const ANotebook: TCustomNotebook;