From 5d11a87060cb0079e2509f736640150b56dd2a9e Mon Sep 17 00:00:00 2001 From: harrybharry Date: Sun, 2 Nov 2008 12:18:11 +0000 Subject: [PATCH] [BUG_FIXED] Fix tab control draw bug again (With a slightly different approach this time). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@351 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 24 +++++++++++++++++++ PowerEditor/src/WinControls/TabBar/TabBar.h | 5 +--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 83156bb5..3c1c189b 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -102,6 +102,30 @@ void TabBar::getCurrentTitle(TCHAR *title, int titleLen) ::SendMessage(_hSelf, TCM_GETITEM, getCurrentTabIndex(), reinterpret_cast(&tci)); } +void TabBar::deletItemAt(int index) { + if ((index == _nbItem-1)) { + //prevent invisible tabs. If last visible tab is removed, other tabs are put in view but not redrawn + //Therefore, scroll one tab to the left if only one tab visible + if (_nbItem > 1) { + RECT itemRect; + ::SendMessage(_hSelf, TCM_GETITEMRECT, (WPARAM)index, (LPARAM)&itemRect); + if (itemRect.left < 5) { //if last visible tab, scroll left once (no more than 5px away should be safe, usually 2px depending on the drawing) + //To scroll the tab control to the left, use the WM_HSCROLL notification + //Doesn't really seem to be documented anywhere, but the values do match the message parameters + //The up/down control really is just some sort of scrollbar + //There seems to be no negative effect on any internal state of the tab control or the up/down control + int wParam = MAKEWPARAM(SB_THUMBPOSITION, index - 1); + ::SendMessage(_hSelf, WM_HSCROLL, wParam, 0); + + wParam = MAKEWPARAM(SB_ENDSCROLL, index - 1); + ::SendMessage(_hSelf, WM_HSCROLL, wParam, 0); + } + } + } + ::SendMessage(_hSelf, TCM_DELETEITEM, index, 0); + _nbItem--; + }; + void TabBar::reSizeTo(RECT & rc2Ajust) { RECT RowRect; diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.h b/PowerEditor/src/WinControls/TabBar/TabBar.h index d8032ede..2294d623 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.h +++ b/PowerEditor/src/WinControls/TabBar/TabBar.h @@ -93,10 +93,7 @@ public: int getCurrentTabIndex() const { return ::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0); }; - void deletItemAt(int index) { - ::SendMessage(_hSelf, TCM_DELETEITEM, index, 0); - _nbItem--; - }; + void deletItemAt(int index); void deletAllItem() { ::SendMessage(_hSelf, TCM_DELETEALLITEMS, 0, 0);