|
|
|
@ -13,7 +13,7 @@
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
//处理工具栏按钮
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
#include "TabBar.h"
|
|
|
|
|
#include "Parameters.h"
|
|
|
|
@ -40,7 +40,7 @@ COLORREF TabBarPlus::_inactiveBgColour = RGB(192, 192, 192);
|
|
|
|
|
|
|
|
|
|
HWND TabBarPlus::_hwndArray[nbCtrlMax] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
|
|
|
|
|
int TabBarPlus::_nbCtrl = 0;
|
|
|
|
|
|
|
|
|
|
//初始化标签栏,创建窗口
|
|
|
|
|
void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLine)
|
|
|
|
|
{
|
|
|
|
|
Window::init(hInst, parent);
|
|
|
|
@ -49,7 +49,7 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLin
|
|
|
|
|
_isVertical = isVertical;
|
|
|
|
|
_isMultiLine = isMultiLine;
|
|
|
|
|
|
|
|
|
|
INITCOMMONCONTROLSEX icce{};
|
|
|
|
|
INITCOMMONCONTROLSEX icce{};//初始化通用控件库
|
|
|
|
|
icce.dwSize = sizeof(icce);
|
|
|
|
|
icce.dwICC = ICC_TAB_CLASSES;
|
|
|
|
|
InitCommonControlsEx(&icce);
|
|
|
|
@ -75,27 +75,27 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLin
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//清理与TabBar相关的资源
|
|
|
|
|
void TabBar::destroy()
|
|
|
|
|
{
|
|
|
|
|
if (_hFont)
|
|
|
|
|
{
|
|
|
|
|
::DeleteObject(_hFont);
|
|
|
|
|
_hFont = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}//删除字体对象
|
|
|
|
|
|
|
|
|
|
if (_hLargeFont)
|
|
|
|
|
{
|
|
|
|
|
::DeleteObject(_hLargeFont);
|
|
|
|
|
_hLargeFont = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}//删除字体大小格式
|
|
|
|
|
|
|
|
|
|
if (_hVerticalFont)
|
|
|
|
|
{
|
|
|
|
|
::DeleteObject(_hVerticalFont);
|
|
|
|
|
_hVerticalFont = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除垂直字体对象
|
|
|
|
|
if (_hVerticalLargeFont)
|
|
|
|
|
{
|
|
|
|
|
::DeleteObject(_hVerticalLargeFont);
|
|
|
|
@ -106,13 +106,13 @@ void TabBar::destroy()
|
|
|
|
|
_hSelf = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//在TabBar末尾插入一个新的选项卡,并设置名称。使用TCITEM结构设置选项卡的属性,并发送消息将选项卡插入TabBar中
|
|
|
|
|
int TabBar::insertAtEnd(const TCHAR* subTabName)
|
|
|
|
|
{
|
|
|
|
|
TCITEM tie{};
|
|
|
|
|
tie.mask = TCIF_TEXT | TCIF_IMAGE;
|
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
|
|
//如果存在图像列表,那么新TabItem应该被放置在列表的开始。
|
|
|
|
|
if (_hasImgLst)
|
|
|
|
|
index = 0;
|
|
|
|
|
tie.iImage = index;
|
|
|
|
@ -120,7 +120,7 @@ int TabBar::insertAtEnd(const TCHAR *subTabName)
|
|
|
|
|
return int(::SendMessage(_hSelf, TCM_INSERTITEM, _nbItem++, reinterpret_cast<LPARAM>(&tie)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取当前选定选项卡的标题。
|
|
|
|
|
void TabBar::getCurrentTitle(TCHAR* title, int titleLen)
|
|
|
|
|
{
|
|
|
|
|
TCITEM tci{};
|
|
|
|
@ -130,7 +130,7 @@ void TabBar::getCurrentTitle(TCHAR *title, int titleLen)
|
|
|
|
|
::SendMessage(_hSelf, TCM_GETITEM, getCurrentTabIndex(), reinterpret_cast<LPARAM>(&tci));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//为TabBar中的选项卡设置字体。根据提供的参数创建新字体,并发送消息为TabBar设置该字体
|
|
|
|
|
void TabBar::setFont(const TCHAR* fontName, int fontSize)
|
|
|
|
|
{
|
|
|
|
|
if (_hFont)
|
|
|
|
@ -147,7 +147,7 @@ void TabBar::setFont(const TCHAR *fontName, int fontSize)
|
|
|
|
|
::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//激活指定索引处的选项卡。发送消息以确保在TabBar中激活指定索引处的选项卡。
|
|
|
|
|
void TabBar::activateAt(int index) const
|
|
|
|
|
{
|
|
|
|
|
if (getCurrentTabIndex() != index)
|
|
|
|
@ -163,14 +163,14 @@ void TabBar::activateAt(int index) const
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除指定索引处的选项卡
|
|
|
|
|
void TabBar::deletItemAt(size_t 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)
|
|
|
|
|
if (_nbItem > 1)//至少两个
|
|
|
|
|
{
|
|
|
|
|
RECT itemRect{};
|
|
|
|
|
::SendMessage(_hSelf, TCM_GETITEMRECT, index, reinterpret_cast<LPARAM>(&itemRect));
|
|
|
|
@ -182,7 +182,7 @@ void TabBar::deletItemAt(size_t index)
|
|
|
|
|
//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);
|
|
|
|
|
|
|
|
|
|
//TabBar控件向左滚动一个Tab项的位置。
|
|
|
|
|
wParam = MAKEWPARAM(SB_ENDSCROLL, index - 1);
|
|
|
|
|
::SendMessage(_hSelf, WM_HSCROLL, wParam, 0);
|
|
|
|
|
}
|
|
|
|
@ -192,14 +192,14 @@ void TabBar::deletItemAt(size_t index)
|
|
|
|
|
_nbItem--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置TabBar中的图像列表。使用TCM_SETIMAGELIST消息来设置图像列表。
|
|
|
|
|
void TabBar::setImageList(HIMAGELIST himl)
|
|
|
|
|
{
|
|
|
|
|
_hasImgLst = true;
|
|
|
|
|
::SendMessage(_hSelf, TCM_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(himl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//调整TabBar的大小以适应给定的矩形区域。调整TabBar的显示方式并计算新的大小,然后调整提供的矩形区域。
|
|
|
|
|
void TabBar::reSizeTo(RECT& rc2Ajust)
|
|
|
|
|
{
|
|
|
|
|
RECT rowRect{};
|
|
|
|
@ -208,6 +208,7 @@ void TabBar::reSizeTo(RECT & rc2Ajust)
|
|
|
|
|
// Important to do that!
|
|
|
|
|
// Otherwise, the window(s) it contains will take all the resouce of CPU
|
|
|
|
|
// We don't need to resize the contained windows if they are even invisible anyway
|
|
|
|
|
//调用display方法,根据调整矩形的右边界是否大于10来决定是否显示TabBar中的窗口
|
|
|
|
|
display(rc2Ajust.right > 10);
|
|
|
|
|
RECT rc = rc2Ajust;
|
|
|
|
|
Window::reSizeTo(rc);
|
|
|
|
@ -226,7 +227,7 @@ void TabBar::reSizeTo(RECT & rc2Ajust)
|
|
|
|
|
if (rowCount == 1)
|
|
|
|
|
{
|
|
|
|
|
style &= ~TCS_BUTTONS;
|
|
|
|
|
}
|
|
|
|
|
}// 如果有多行Tab项(至少两行),则启用TabCtrl的按钮样式,并计算间距的值
|
|
|
|
|
else // (rowCount >= 2)
|
|
|
|
|
{
|
|
|
|
|
style |= TCS_BUTTONS;
|
|
|
|
@ -249,15 +250,19 @@ void TabBar::reSizeTo(RECT & rc2Ajust)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//销毁TabBarPlus及其资源。
|
|
|
|
|
void TabBarPlus::destroy()
|
|
|
|
|
{
|
|
|
|
|
TabBar::destroy();
|
|
|
|
|
::DestroyWindow(_tooltips);
|
|
|
|
|
_tooltips = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
初始化TabBarPlus。
|
|
|
|
|
创建TabControl和工具提示窗口,并确保它们已成功创建。
|
|
|
|
|
设置所需的样式,并根据参数创建相应的字体。
|
|
|
|
|
将TabBarPlus添加到控件数组中,以便跟踪。
|
|
|
|
|
*/
|
|
|
|
|
void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLine)
|
|
|
|
|
{
|
|
|
|
|
Window::init(hInst, parent);
|
|
|
|
@ -290,7 +295,7 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("TabBarPlus::init : CreateWindowEx() function return null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//工具提示
|
|
|
|
|
_tooltips = ::CreateWindowEx(
|
|
|
|
|
0,
|
|
|
|
|
TOOLTIPS_CLASS,
|
|
|
|
@ -306,7 +311,7 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("TabBarPlus::init : tooltip CreateWindowEx() function return null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//暗色主题
|
|
|
|
|
NppDarkMode::setDarkTooltips(_tooltips, NppDarkMode::ToolTipsType::tooltip);
|
|
|
|
|
|
|
|
|
|
::SendMessage(_hSelf, TCM_SETTOOLTIPS, reinterpret_cast<WPARAM>(_tooltips), 0);
|
|
|
|
@ -317,12 +322,13 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult
|
|
|
|
|
_ctrlID = _nbCtrl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
{//查找第一个为空的位置,并设置_ctrlID为该位置的值
|
|
|
|
|
int i = 0;
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (; i < nbCtrlMax && !found; ++i)
|
|
|
|
|
if (!_hwndArray[i])
|
|
|
|
|
found = true;
|
|
|
|
|
//满了未找到,销毁
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
_ctrlID = -1;
|
|
|
|
@ -354,7 +360,7 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult
|
|
|
|
|
_hVerticalLargeFont = CreateFontIndirect(&lfVer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//处理选项卡控件的自定义填充。
|
|
|
|
|
void TabBarPlus::doOwnerDrawTab()
|
|
|
|
|
{
|
|
|
|
|
::SendMessage(_hwndArray[0], TCM_SETPADDING, 0, MAKELPARAM(6, 0));
|
|
|
|
@ -363,6 +369,7 @@ void TabBarPlus::doOwnerDrawTab()
|
|
|
|
|
if (_hwndArray[i])
|
|
|
|
|
{
|
|
|
|
|
LONG_PTR style = ::GetWindowLongPtr(_hwndArray[i], GWL_STYLE);
|
|
|
|
|
//检查是否需要自定义
|
|
|
|
|
if (isOwnerDrawTab())
|
|
|
|
|
style |= TCS_OWNERDRAWFIXED;
|
|
|
|
|
else
|
|
|
|
@ -378,7 +385,7 @@ void TabBarPlus::doOwnerDrawTab()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据给定的索引为选项卡栏设置不同的颜色(如活动文本颜色、背景颜色等)。在更新颜色之后,它调用doOwnerDrawTab()来刷新显示。
|
|
|
|
|
void TabBarPlus::setColour(COLORREF colour2Set, tabColourIndex i)
|
|
|
|
|
{
|
|
|
|
|
switch (i)
|
|
|
|
@ -404,7 +411,7 @@ void TabBarPlus::setColour(COLORREF colour2Set, tabColourIndex i)
|
|
|
|
|
doOwnerDrawTab();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置垂直选项卡
|
|
|
|
|
void TabBarPlus::doVertical()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _nbCtrl; ++i)
|
|
|
|
@ -414,7 +421,7 @@ void TabBarPlus::doVertical()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//显示多行选项卡
|
|
|
|
|
void TabBarPlus::doMultiLine()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _nbCtrl; ++i)
|
|
|
|
@ -423,7 +430,7 @@ void TabBarPlus::doMultiLine()
|
|
|
|
|
SendMessage(_hwndArray[i], WM_TABSETSTYLE, isMultiLine(), TCS_MULTILINE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//向父窗口发送通知消息,其中包含有关选项卡索引和特定通知代码的信息。
|
|
|
|
|
void TabBarPlus::notify(int notifyCode, int tabIndex)
|
|
|
|
|
{
|
|
|
|
|
TBHDR nmhdr{};
|
|
|
|
@ -433,7 +440,7 @@ void TabBarPlus::notify(int notifyCode, int tabIndex)
|
|
|
|
|
nmhdr._tabOrigin = tabIndex;
|
|
|
|
|
::SendMessage(_hParent, WM_NOTIFY, 0, reinterpret_cast<LPARAM>(&nmhdr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//启动对选项卡栏控件上的鼠标事件的跟踪,例如当鼠标进入或离开控件区域时。
|
|
|
|
|
void TabBarPlus::trackMouseEvent(DWORD event2check)
|
|
|
|
|
{
|
|
|
|
|
TRACKMOUSEEVENT tme = {};
|
|
|
|
@ -442,12 +449,13 @@ void TabBarPlus::trackMouseEvent(DWORD event2check)
|
|
|
|
|
tme.hwndTrack = _hSelf;
|
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//消息处理,处理窗口消息
|
|
|
|
|
LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
switch (Message)
|
|
|
|
|
{
|
|
|
|
|
// Custom window message to change tab control style on the fly
|
|
|
|
|
//改变窗口样式
|
|
|
|
|
case WM_TABSETSTYLE:
|
|
|
|
|
{
|
|
|
|
|
LONG_PTR style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
|
|
|
@ -465,13 +473,13 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//深色模式
|
|
|
|
|
case NPPM_INTERNAL_REFRESHDARKMODE:
|
|
|
|
|
{
|
|
|
|
|
NppDarkMode::setDarkTooltips(hwnd, NppDarkMode::ToolTipsType::tabbar);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//鼠标滚轮
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
|
{
|
|
|
|
|
// ..............................................................................
|
|
|
|
@ -489,7 +497,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
// CTRL + SHIFT + MOUSEWHEEL:
|
|
|
|
|
// will switch to the first/last tab
|
|
|
|
|
// ..............................................................................
|
|
|
|
|
|
|
|
|
|
//是否被拖动,如是,会交换当前鼠标所在位置和目标位置的数据
|
|
|
|
|
if (_isDragging)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
@ -581,7 +589,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//左键按下
|
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
|
{
|
|
|
|
|
if (::GetWindowLongPtr(_hSelf, GWL_STYLE) & TCS_BUTTONS)
|
|
|
|
@ -592,7 +600,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
setActiveTab(nTab);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//是否关闭
|
|
|
|
|
if (_drawTabCloseButton)
|
|
|
|
|
{
|
|
|
|
|
int xPos = LOWORD(lParam);
|
|
|
|
@ -621,7 +629,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//右键按下,处理选项
|
|
|
|
|
case WM_RBUTTONDOWN: //rightclick selects tab aswell
|
|
|
|
|
{
|
|
|
|
|
// TCS_BUTTONS doesn't select the tab
|
|
|
|
@ -637,7 +645,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
::CallWindowProc(_tabBarDefaultProc, hwnd, WM_LBUTTONDOWN, wParam, lParam);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//鼠标移动
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
|
{
|
|
|
|
|
if (_mightBeDragging && !_isDragging)
|
|
|
|
@ -670,7 +678,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
POINT p{};
|
|
|
|
|
p.x = LOWORD(lParam);
|
|
|
|
|
p.y = HIWORD(lParam);
|
|
|
|
|
|
|
|
|
|
//是否拖动tag,是,光标移动,tab数据交换,否,判断并进行相关操作
|
|
|
|
|
if (_isDragging)
|
|
|
|
|
{
|
|
|
|
|
exchangeItemData(p);
|
|
|
|
@ -758,7 +766,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//鼠标移开,重绘鼠标区域,重置相关变量
|
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
|
{
|
|
|
|
|
if (_isCloseHover)
|
|
|
|
@ -772,7 +780,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
notify(TCN_MOUSELEAVING, _currentHoverTabItem);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//释放左键,告知操作结束
|
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
|
{
|
|
|
|
|
_mightBeDragging = false;
|
|
|
|
@ -820,7 +828,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//抓取鼠标输入的改变
|
|
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
|
{
|
|
|
|
|
if (_isDragging)
|
|
|
|
@ -830,20 +838,20 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//重绘tab
|
|
|
|
|
case WM_DRAWITEM:
|
|
|
|
|
{
|
|
|
|
|
drawItem((DRAWITEMSTRUCT*)lParam);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//是否按下control键
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
|
{
|
|
|
|
|
if (wParam == VK_LCONTROL)
|
|
|
|
|
::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_PLUS_TAB)));
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//鼠标中键释放
|
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
|
{
|
|
|
|
|
int xPos = LOWORD(lParam);
|
|
|
|
@ -852,7 +860,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
notify(TCN_TABDELETE, currentTabOn);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//双击鼠标左键
|
|
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
|
{
|
|
|
|
|
if (_isDbClk2Close)
|
|
|
|
@ -864,7 +872,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果程序正在使用暗黑模式,将会用指定的画刷填充整个Tab的客户区,代替了系统默认的橡皮擦背景操作。
|
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
|
{
|
|
|
|
|
if (!NppDarkMode::isEnabled())
|
|
|
|
@ -878,7 +886,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//在Tab控件需要重绘时调用,这里会进行大量的绘制操作,内容包括Tab本身和每一个Tab的文字、关闭按钮等元素。
|
|
|
|
|
case WM_PAINT:
|
|
|
|
|
{
|
|
|
|
|
if (!NppDarkMode::isEnabled())
|
|
|
|
@ -1049,7 +1057,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
|
|
|
|
|
|
|
|
|
|
return ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//实现了Tab的绘制过程,包括对Tab背景颜色、文字颜色的调整,判断并处理当前Tab的激活状态,处理Tab的图标和标题等。
|
|
|
|
|
void TabBarPlus::drawItem(DRAWITEMSTRUCT* pDrawItemStruct, bool isDarkMode)
|
|
|
|
|
{
|
|
|
|
|
RECT rect = pDrawItemStruct->rcItem;
|
|
|
|
@ -1371,7 +1379,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
|
|
|
|
|
::RestoreDC(hDC, nSavedDC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用于改变鼠标光标的形状,根据用户托拽标签的不同位置(是否在同一应用中、是否在一个有效的放置位置等)表现为不同的光标形状。
|
|
|
|
|
void TabBarPlus::draggingCursor(POINT screenPoint)
|
|
|
|
|
{
|
|
|
|
|
HWND hWin = ::WindowFromPoint(screenPoint);
|
|
|
|
@ -1394,7 +1402,7 @@ void TabBarPlus::draggingCursor(POINT screenPoint)
|
|
|
|
|
::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_OUT_TAB)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//简单地把指定的标签设为活动状态。
|
|
|
|
|
void TabBarPlus::setActiveTab(int tabIndex)
|
|
|
|
|
{
|
|
|
|
|
// TCM_SETCURFOCUS is busted on WINE/ReactOS for single line (non-TCS_BUTTONS) tabs...
|
|
|
|
@ -1407,7 +1415,7 @@ void TabBarPlus::setActiveTab(int tabIndex)
|
|
|
|
|
::SendMessage(_hSelf, TCM_SETCURSEL, tabIndex, 0);
|
|
|
|
|
notify(TCN_SELCHANGE, tabIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//交换两个Tab的数据,实现两个Tab的位置交换。
|
|
|
|
|
void TabBarPlus::exchangeTabItemData(int oldTab, int newTab)
|
|
|
|
|
{
|
|
|
|
|
//1. shift their data, and insert the source
|
|
|
|
@ -1449,7 +1457,7 @@ void TabBarPlus::exchangeTabItemData(int oldTab, int newTab)
|
|
|
|
|
//2. set to focus
|
|
|
|
|
setActiveTab(newTab);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//在接收到鼠标托拽消息的时候被调用,用于各个标签的排序和交换位置。
|
|
|
|
|
void TabBarPlus::exchangeItemData(POINT point)
|
|
|
|
|
{
|
|
|
|
|
// Find the destination tab...
|
|
|
|
@ -1486,7 +1494,7 @@ void TabBarPlus::exchangeItemData(POINT point)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用于处理与关闭按钮相关的操作,如获取关闭按钮的大小及位置,判断是否点击到了关闭按钮等。
|
|
|
|
|
CloseButtonZone::CloseButtonZone()
|
|
|
|
|
{
|
|
|
|
|
// TODO: get width/height of close button dynamically
|
|
|
|
|