Improve multi-line mode for tab interface

pull/2949/head
Don HO 8 years ago
parent 82dd554c49
commit e1125f0bbc

@ -66,7 +66,7 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTraditio
icce.dwSize = sizeof(icce); icce.dwSize = sizeof(icce);
icce.dwICC = ICC_TAB_CLASSES; icce.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icce); InitCommonControlsEx(&icce);
int multiLine = isMultiLine ? (_isTraditional ? TCS_MULTILINE | TCS_BUTTONS : 0) : 0; int multiLine = isMultiLine ? (_isTraditional ? TCS_MULTILINE : 0) : 0;
int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\ int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\
TCS_FOCUSNEVER | TCS_TABS | WS_TABSTOP | vertical | multiLine; TCS_FOCUSNEVER | TCS_TABS | WS_TABSTOP | vertical | multiLine;
@ -221,14 +221,40 @@ void TabBar::reSizeTo(RECT & rc2Ajust)
} }
else if (_isVertical) else if (_isVertical)
{ {
tabsHight = rowCount * (rowRect.right - rowRect.left); LONG_PTR style = ::GetWindowLongPtr(_hSelf, GWL_STYLE);
if (rowCount == 1)
{
style &= ~TCS_BUTTONS;
}
else // (rowCount >= 2)
{
style |= TCS_BUTTONS;
}
::SetWindowLongPtr(_hSelf, GWL_STYLE, style);
const int marge = 3; // in TCS_BUTTONS mode, each row has few pixels higher
tabsHight = rowCount * (rowRect.right - rowRect.left + marge);
tabsHight += GetSystemMetrics(SM_CXEDGE); tabsHight += GetSystemMetrics(SM_CXEDGE);
rc2Ajust.left += tabsHight; rc2Ajust.left += tabsHight;
rc2Ajust.right -= tabsHight; rc2Ajust.right -= tabsHight;
} }
else else //if (_isMultiLine)
{
if (rowCount == 1)
{ {
LONG_PTR style = ::GetWindowLongPtr(_hSelf, GWL_STYLE);
style &= ~TCS_BUTTONS;
::SetWindowLongPtr(_hSelf, GWL_STYLE, style);
TabCtrl_AdjustRect(_hSelf, FALSE, &rc2Ajust);
}
else // (rowCount >= 2)
{
LONG_PTR style = ::GetWindowLongPtr(_hSelf, GWL_STYLE);
style |= TCS_BUTTONS;
::SetWindowLongPtr(_hSelf, GWL_STYLE, style);
const int marge = 3; // in TCS_BUTTONS mode, each row has few pixels higher const int marge = 3; // in TCS_BUTTONS mode, each row has few pixels higher
tabsHight = rowCount * (rowRect.bottom - rowRect.top + marge); tabsHight = rowCount * (rowRect.bottom - rowRect.top + marge);
tabsHight += GetSystemMetrics(SM_CYEDGE); tabsHight += GetSystemMetrics(SM_CYEDGE);
@ -237,6 +263,7 @@ void TabBar::reSizeTo(RECT & rc2Ajust)
rc2Ajust.bottom -= tabsHight; rc2Ajust.bottom -= tabsHight;
} }
} }
}
void TabBarPlus::destroy() void TabBarPlus::destroy()
@ -259,10 +286,9 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTrad
icce.dwSize = sizeof(icce); icce.dwSize = sizeof(icce);
icce.dwICC = ICC_TAB_CLASSES; icce.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icce); InitCommonControlsEx(&icce);
int multiLine = isMultiLine ? (_isTraditional ? TCS_MULTILINE | TCS_BUTTONS : 0) : 0; int multiLine = isMultiLine ? (_isTraditional ? TCS_MULTILINE : 0) : 0;
int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\ int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE | TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine;
TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine;
style |= TCS_OWNERDRAWFIXED; style |= TCS_OWNERDRAWFIXED;
@ -415,7 +441,7 @@ void TabBarPlus::doMultiLine()
for (int i = 0 ; i < _nbCtrl ; ++i) for (int i = 0 ; i < _nbCtrl ; ++i)
{ {
if (_hwndArray[i]) if (_hwndArray[i])
SendMessage(_hwndArray[i], WM_TABSETSTYLE, isMultiLine(), TCS_MULTILINE | TCS_BUTTONS); SendMessage(_hwndArray[i], WM_TABSETSTYLE, isMultiLine(), TCS_MULTILINE);
} }
} }

Loading…
Cancel
Save