Refactoring and clean up for tab interface

This commit is contained in:
Don HO 2017-02-24 03:14:47 +01:00
parent 9faa97a6f9
commit 3ba1b100f2
5 changed files with 55 additions and 75 deletions

View File

@ -257,7 +257,7 @@ void FindReplaceDlg::create(int dialogID, bool isRTL)
RECT rect; RECT rect;
//::GetWindowRect(_hSelf, &rect); //::GetWindowRect(_hSelf, &rect);
getClientRect(rect); getClientRect(rect);
_tab.init(_hInst, _hSelf, false, false, true); _tab.init(_hInst, _hSelf, false, true);
int tabDpiDynamicalHeight = NppParameters::getInstance()->_dpiManager.scaleY(13); int tabDpiDynamicalHeight = NppParameters::getInstance()->_dpiManager.scaleY(13);
_tab.setFont(TEXT("Tahoma"), tabDpiDynamicalHeight); _tab.setFont(TEXT("Tahoma"), tabDpiDynamicalHeight);

View File

@ -196,7 +196,7 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL)
RECT rect; RECT rect;
getClientRect(rect); getClientRect(rect);
_tab.init(_hInst, _hSelf, false, false, true); _tab.init(_hInst, _hSelf, false, true);
int tabDpiDynamicalHeight = NppParameters::getInstance()->_dpiManager.scaleY(13); int tabDpiDynamicalHeight = NppParameters::getInstance()->_dpiManager.scaleY(13);
_tab.setFont(TEXT("Tahoma"), tabDpiDynamicalHeight); _tab.setFont(TEXT("Tahoma"), tabDpiDynamicalHeight);

View File

@ -50,10 +50,10 @@ public :
ControlsTab() = default; ControlsTab() = default;
virtual ~ControlsTab() = default; virtual ~ControlsTab() = default;
virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isTraditional = false, bool isMultiLine = false) virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isMultiLine = false)
{ {
_isVertical = isVertical; _isVertical = isVertical;
TabBar::init(hInst, hwnd, false, isTraditional, isMultiLine); TabBar::init(hInst, hwnd, false, isMultiLine);
} }
void createTabs(WindowVector & winVector); void createTabs(WindowVector & winVector);

View File

@ -54,11 +54,11 @@ COLORREF TabBarPlus::_inactiveBgColour = RGB(192, 192, 192);
HWND TabBarPlus::_hwndArray[nbCtrlMax] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; HWND TabBarPlus::_hwndArray[nbCtrlMax] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
int TabBarPlus::_nbCtrl = 0; int TabBarPlus::_nbCtrl = 0;
void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTraditional, bool isMultiLine) void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLine)
{ {
Window::init(hInst, parent); Window::init(hInst, parent);
int vertical = isVertical?(TCS_VERTICAL | TCS_MULTILINE | TCS_RIGHTJUSTIFY):0; int vertical = isVertical?(TCS_VERTICAL | TCS_MULTILINE | TCS_RIGHTJUSTIFY):0;
_isTraditional = isTraditional;
_isVertical = isVertical; _isVertical = isVertical;
_isMultiLine = isMultiLine; _isMultiLine = isMultiLine;
@ -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 : 0) : 0; int multiLine = isMultiLine ? TCS_MULTILINE : 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;
@ -215,34 +215,12 @@ void TabBar::reSizeTo(RECT & rc2Ajust)
rowCount = TabCtrl_GetRowCount(_hSelf); rowCount = TabCtrl_GetRowCount(_hSelf);
TabCtrl_GetItemRect(_hSelf, 0, &rowRect); TabCtrl_GetItemRect(_hSelf, 0, &rowRect);
if (_isTraditional)
{
TabCtrl_AdjustRect(_hSelf, FALSE, &rc2Ajust);
}
else if (_isVertical)
{
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 int larger = _isVertical ? rowRect.right : rowRect.bottom;
tabsHight = rowCount * (rowRect.right - rowRect.left + marge); int smaller = _isVertical ? rowRect.left : rowRect.top;
tabsHight += GetSystemMetrics(SM_CXEDGE);
rc2Ajust.left += tabsHight;
rc2Ajust.right -= tabsHight;
}
else //if (_isMultiLine)
{
LONG_PTR style = ::GetWindowLongPtr(_hSelf, GWL_STYLE);
int marge = 0; int marge = 0;
LONG_PTR style = ::GetWindowLongPtr(_hSelf, GWL_STYLE);
if (rowCount == 1) if (rowCount == 1)
{ {
style &= ~TCS_BUTTONS; style &= ~TCS_BUTTONS;
@ -254,9 +232,16 @@ void TabBar::reSizeTo(RECT & rc2Ajust)
} }
::SetWindowLongPtr(_hSelf, GWL_STYLE, style); ::SetWindowLongPtr(_hSelf, GWL_STYLE, style);
tabsHight = rowCount * (rowRect.bottom - rowRect.top + marge); tabsHight = rowCount * (larger - smaller + marge);
tabsHight += GetSystemMetrics(SM_CYEDGE); tabsHight += GetSystemMetrics(_isVertical ? SM_CXEDGE : SM_CYEDGE);
if (_isVertical)
{
rc2Ajust.left += tabsHight;
rc2Ajust.right -= tabsHight;
}
else
{
rc2Ajust.top += tabsHight; rc2Ajust.top += tabsHight;
rc2Ajust.bottom -= tabsHight; rc2Ajust.bottom -= tabsHight;
} }
@ -271,11 +256,10 @@ void TabBarPlus::destroy()
} }
void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTraditional, bool isMultiLine) void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLine)
{ {
Window::init(hInst, parent); Window::init(hInst, parent);
int vertical = isVertical?(TCS_VERTICAL | TCS_MULTILINE | TCS_RIGHTJUSTIFY):0; int vertical = isVertical?(TCS_VERTICAL | TCS_MULTILINE | TCS_RIGHTJUSTIFY):0;
_isTraditional = isTraditional;
_isVertical = isVertical; _isVertical = isVertical;
_isMultiLine = isMultiLine; _isMultiLine = isMultiLine;
@ -283,7 +267,7 @@ 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 : 0) : 0; int multiLine = isMultiLine ? TCS_MULTILINE : 0;
int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE | TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine; int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE | TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine;
@ -322,8 +306,6 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTrad
} }
::SendMessage(_hSelf, TCM_SETTOOLTIPS, reinterpret_cast<WPARAM>(_tooltips), 0); ::SendMessage(_hSelf, TCM_SETTOOLTIPS, reinterpret_cast<WPARAM>(_tooltips), 0);
if (!_isTraditional)
{
if (!_hwndArray[_nbCtrl]) if (!_hwndArray[_nbCtrl])
{ {
_hwndArray[_nbCtrl] = _hSelf; _hwndArray[_nbCtrl] = _hSelf;
@ -349,7 +331,6 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTrad
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
_tabBarDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(TabBarPlus_Proc))); _tabBarDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(TabBarPlus_Proc)));
}
LOGFONT LogFont; LOGFONT LogFont;

View File

@ -68,7 +68,7 @@ public:
TabBar() : Window() {}; TabBar() : Window() {};
virtual ~TabBar() {}; virtual ~TabBar() {};
virtual void destroy(); virtual void destroy();
virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isTraditional = false, bool isMultiLine = false); virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isMultiLine = false);
virtual void reSizeTo(RECT & rc2Ajust); virtual void reSizeTo(RECT & rc2Ajust);
int insertAtEnd(const TCHAR *subTabName); int insertAtEnd(const TCHAR *subTabName);
void activateAt(int index) const; void activateAt(int index) const;
@ -115,7 +115,6 @@ protected:
HFONT _hVerticalLargeFont = nullptr; HFONT _hVerticalLargeFont = nullptr;
int _ctrlID = 0; int _ctrlID = 0;
bool _isTraditional = false;
bool _isVertical = false; bool _isVertical = false;
bool _isMultiLine = false; bool _isMultiLine = false;
@ -150,7 +149,7 @@ public :
_doDragNDrop = justDoIt; _doDragNDrop = justDoIt;
}; };
virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isTraditional = false, bool isMultiLine = false); virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isMultiLine = false);
virtual void destroy(); virtual void destroy();