Skip to content

Commit

Permalink
LCL: TPageControl: Win32: Fixed Pagecontrol does show space for tabs,…
Browse files Browse the repository at this point in the history
… but no tabs in it. Issue #19278

git-svn-id: http://svn.freepascal.org/svn/lazarus/trunk@54781 4005530d-fff6-0310-9dd1-cebe43e6787f
  • Loading branch information
michl committed Apr 30, 2017
1 parent 8e87622 commit 97c1cdb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
44 changes: 41 additions & 3 deletions lcl/interfaces/win32/win32pagecontrol.inc
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ begin
RealIndex := TCustomTabControl(AWinControl.Parent).PageToTabIndex(PageIndex);
if RealIndex <> -1 then
begin
Windows.SendMessage(PageControlHandle, TCM_DELETEITEM, Windows.WPARAM(RealIndex), 0);
TWin32WSCustomTabControl.DeletePage(TCustomTabControl(AWinControl.Parent), RealIndex);
AWinControl.Parent.InvalidateClientRectCache(False);
end;
end;
TWSWinControlClass(ClassParent).DestroyHandle(AWinControl);
end;

class procedure TWin32WSCustomPage.ThemeChange(Wnd: HWnd);
class procedure TWin32WSCustomPage.ThemeChange(Wnd: HWND);
var
WindowInfo: PWin32WindowInfo;
begin
Expand Down Expand Up @@ -279,6 +279,44 @@ begin
Dec(ORect.Bottom, ARect.Bottom);
end;

class procedure TWin32WSCustomTabControl.DeletePage(
const ATabControl: TCustomTabControl; const AIndex: integer);

var
Wnd: HWND;

function TabsScrollingNeeded: Boolean;
var
HitTestInfo: TC_HITTESTINFO;
ARect: TRect;
TabCount, FirstShowedIndex: Integer;
begin
if AIndex <= 0 then Exit(False);

TabCount := Windows.SendMessage(Wnd, TCM_GETITEMCOUNT, 0, 0);
if AIndex < TabCount - 1 then Exit(False);

// we have to look, if the first shown tab is the tab that is to be deleted
Windows.GetClientRect(Wnd, @ARect);
Windows.SendMessage(Wnd, TCM_AdjustRect, 0, LPARAM(@ARect));

HitTestInfo.pt.x := ARect.Left;
HitTestInfo.pt.y := ARect.Top div 2;
FirstShowedIndex := Windows.SendMessage(Wnd, TCM_HITTEST, 0, LPARAM(@HitTestInfo));

Result := (FirstShowedIndex > 0) and (FirstShowedIndex = AIndex);
end;

begin
// There is a bug in Windows. When only one tab is left in a scrolled Tab Control
// and this is deleted, Windows doesn't scroll it automatically. So we have to
// do it manually. See Mantis #19278
Wnd := ATabControl.Handle;
if TabsScrollingNeeded then
Windows.SendMessage(Wnd, TCM_SETCURSEL, Windows.WPARAM(AIndex - 1), 0);
Windows.SendMessage(Wnd, TCM_DELETEITEM, Windows.WPARAM(AIndex), 0);
end;

class function TWin32WSCustomTabControl.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
const
Expand Down Expand Up @@ -391,7 +429,7 @@ begin
if ATabControl is TTabControl then
exit;

Windows.SendMessage(ATabControl.Handle, TCM_DELETEITEM, Windows.WPARAM(AIndex), 0);
DeletePage(ATabControl, AIndex);
if LCLControlSizeNeedsUpdate(ATabControl, True) then
AdjustSizeTabControlPages(ATabControl);
end;
Expand Down
2 changes: 2 additions & 0 deletions lcl/interfaces/win32/win32wscomctrls.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ TWin32WSCustomPage = class(TWSCustomPage)
{ TWin32WSCustomTabControl }

TWin32WSCustomTabControl = class(TWSCustomTabControl)
public
class procedure DeletePage(const ATabControl: TCustomTabControl; const AIndex: integer);
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
Expand Down

0 comments on commit 97c1cdb

Please sign in to comment.