📄 oledragdroptabctrl.h
字号:
{
_ClearInsertionEdge();
}
// Implementation
int _HitTestSideInset(CPoint point, int nInset = 0, bool* pbLeft = NULL)
{
int cxGap = (nInset == 0) ? (s_kcxGap*2 + s_kcxSeparator) : nInset;
int cyGap = GetItemHeight();
bool bCheckLeftSide = (m_dwTabCtrl2ExtendedStyle & TAB2_EX_MULTILINE) ||
( m_nFirstIndexOnSingleLine == 0 && !(m_dwTabCtrl2ExtendedStyle & TAB2_EX_MULTILINE) );
if (bCheckLeftSide && m_items.size() > 0) {
int nIndex = HitTest(point);
if (nIndex == -1)
return -1;
ATLASSERT(_IsValidIndex(nIndex));
CRect rc; GetClientRect(&rc);
const CRect& rcItem = m_items[nIndex].m_rcItem;
if (rcItem.left == 0) {// left side
if (CRect(rcItem.left, rcItem.top, rcItem.left + cxGap, rcItem.top + cyGap).PtInRect(point)) {
if (pbLeft)
*pbLeft = true;
return nIndex;
}
else
return -1;
}
else if (rcItem.right > rc.right - s_kcxGap - s_kcxSeparator) {// right side
if (CRect(rcItem.right - cxGap, rcItem.top, rcItem.right, rcItem.top + cyGap).PtInRect(point)) {
if (pbLeft)
*pbLeft = false;
return nIndex;
}
else
return -1;
}
}
return -1;
}
int _HitTestSeparator(CPoint point, int nInset)
{
DDTCTRACE(_T("CTablCtrl2Impl::_HitTestSeparator\n"));
CRect rc;
GetClientRect(&rc);
if (!rc.PtInRect(point)) {
DDTCTRACE(_T(" outside of client area\n"));
return -1;
}
int cyGap = GetItemHeight();
int i = (m_dwTabCtrl2ExtendedStyle & TAB2_EX_MULTILINE) ? 0 : m_nFirstIndexOnSingleLine;
for (; i < m_items.size(); ++i) {
const CRect& rcItem = m_items[i].m_rcItem;
CRect rcSep = CRect(rcItem.right + s_kcxGap, rcItem.top,
rcItem.right + s_kcxGap + s_kcxSeparator, rcItem.top + cyGap);
rcSep.InflateRect(nInset, 0);
if (rcSep.PtInRect(point)) {
DDTCTRACE(_T(" between items hit!\n"));
return i;
}
}
DDTCTRACE(_T(" not inside of the gaps \n"));
return -1;
}
void _ClearInsertionEdge()
{
if (!m_rcInvalidateOnDrawingInsertionEdge.IsRectEmpty())
{
InvalidateRect(m_rcInvalidateOnDrawingInsertionEdge);
UpdateWindow();
m_rcInvalidateOnDrawingInsertionEdge.SetRectEmpty();
}
}
bool _DrawInsertionEdge(_hitTestFlag flag, int nIndex)
{
CRect rcInvalidateOnDrawingInsertionEdge;
if (flag == htOutside) {
if (m_items.size() > 0) {
flag = htSeparator;
nIndex = m_items.size() - 1;
}
else {
flag = htWhole;
}
}
CRect rcItem;
if (flag == htInsetLeft) {
ATLASSERT(_IsValidIndex(nIndex));
rcItem = m_items[nIndex].m_rcItem;
rcInvalidateOnDrawingInsertionEdge.SetRect(rcItem.left, rcItem.top, rcItem.left + s_kcxSeparator*2, rcItem.bottom);
_DrawInsertionEdgeAux(rcItem.TopLeft(), insertLeft);
}
else if (flag == htInsetRight) {
ATLASSERT(_IsValidIndex(nIndex));
rcItem = m_items[nIndex].m_rcItem;
rcInvalidateOnDrawingInsertionEdge.SetRect(rcItem.right - s_kcxSeparator*2, rcItem.top, rcItem.right, rcItem.bottom);
_DrawInsertionEdgeAux(CPoint(rcItem.right - s_kcxSeparator, rcItem.top), insertRight);
}
else if (flag == htSeparator) {
ATLASSERT(_IsValidIndex(nIndex));
rcItem = m_items[nIndex].m_rcItem;
CPoint ptSep(rcItem.right + s_kcxGap, rcItem.top);
_DrawInsertionEdgeAux(ptSep, insertMiddle);
rcInvalidateOnDrawingInsertionEdge.SetRect(rcItem.right, rcItem.top, rcItem.right + s_kcxGap*2 + s_kcxSeparator, rcItem.bottom);
}
else if (flag == htItem) {
ATLASSERT(_IsValidIndex(nIndex));
rcItem = m_items[nIndex].m_rcItem;
_DrawInsertionEdgeAux(rcItem);
rcInvalidateOnDrawingInsertionEdge = rcItem;
}
else if (flag == htWhole) {
GetClientRect(rcItem);
rcInvalidateOnDrawingInsertionEdge.SetRect(rcItem.left, rcItem.top, rcItem.left + s_kcxSeparator*2, rcItem.bottom);
_DrawInsertionEdgeAux(rcItem.TopLeft(), insertLeft);
}
else {
_ClearInsertionEdge();
return false;
}
if (rcInvalidateOnDrawingInsertionEdge != m_rcInvalidateOnDrawingInsertionEdge) {
_ClearInsertionEdge();
m_rcInvalidateOnDrawingInsertionEdge = rcInvalidateOnDrawingInsertionEdge;
}
return true;
}
enum insertFlags { insertLeft, insertMiddle, insertRight };
void _DrawInsertionEdgeAux(CPoint pt, insertFlags flag)
{
int cy = GetItemHeight();
int sep = s_kcxSeparator;
CClientDC dc(m_hWnd);
CBrush hbr;
hbr.CreateSolidBrush(::GetSysColor(COLOR_3DDKSHADOW));
dc.SetBrushOrg(pt.x, pt.y);
CBrushHandle hbrOld = dc.SelectBrush(hbr);
if (flag == insertLeft) {
POINT pts[] = { { pt.x, pt.y }, { pt.x, pt.y + cy - 1}, { pt.x + sep*2 - 1, pt.y + cy - 1 },
{ pt.x + sep - 1, pt.y + cy - sep - 1}, { pt.x + sep - 1, pt.y + sep }, { pt.x + sep*2 - 1, pt.y }, };
dc.Polygon(pts, _countof(pts));
}
else if (flag == insertMiddle) {
pt. x -= sep;
POINT pts[] = { { pt.x, pt.y }, { pt.x + sep, pt.y + sep }, { pt.x + sep, pt.y + cy - sep - 1},
{ pt.x, pt.y + cy - 1 }, { pt.x + sep*3 - 1, pt.y + cy - 1}, { pt.x + sep*2 - 1, pt.y + cy - sep - 1},
{ pt.x + sep*2 - 1, pt.y + sep }, { pt.x + sep*3 - 1, pt.y } };
dc.Polygon(pts, _countof(pts));
}
else if (flag == insertRight) {
POINT pts[] = { { pt.x - sep, pt.y }, { pt.x, pt.y + sep }, { pt.x, pt.y + cy - sep - 1 },
{ pt.x - sep, pt.y + cy - 1}, { pt.x + sep - 1, pt.y + cy - 1 }, { pt.x + sep - 1, pt.y }, };
dc.Polygon(pts, _countof(pts));
}
dc.SelectBrush(hbrOld);
}
void _DrawInsertionEdgeAux(const CRect& rc)
{
CClientDC dc(m_hWnd);
CBrush hbr;
hbr.CreateSolidBrush(::GetSysColor(COLOR_3DDKSHADOW));
dc.SetBrushOrg(rc.left, rc.top);
CBrushHandle hbrOld = dc.SelectBrush(hbr);
POINT pts[] = { { rc.left, rc.top }, { rc.left, rc.bottom - 1 },
{ rc.right - 1, rc.bottom - 1 }, { rc.right - 1, rc.top }, { rc.left, rc.top } };
dc.Polyline(pts, _countof(pts));
dc.SelectBrush(hbrOld);
}
/* void _DrawInsertionEdgeClientRect()
{
CClientDC dc(m_hWnd);
CRect rc; GetClientRect(rc);
CBrush hbr;
hbr.CreateSolidBrush(::GetSysColor(COLOR_3DDKSHADOW));
dc.SetBrushOrg(rc.left, rc.top);
CBrushHandle hbrOld = dc.SelectBrush(hbr);
POINT pts[] = { { rc.left, rc.top }, { rc.left, rc.bottom },
{ rc.right, rc.bottom }, { rc.right, rc.top }, { rc.left, rc.top } };
dc.Polyline(pts, _countof(pts));
dc.SelectBrush(hbrOld);
}
*/
bool _IsSameIndexDropped(int nDestIndex)
{
if (!m_bDragFromItself)
return false;
for (int i = 0; i < m_arrCurDragItems.GetSize(); ++i) {
int nSrcIndex = m_arrCurDragItems[i];
if (nSrcIndex == nDestIndex)
return true;
}
return false;
}
void _DoDragDrop(CPoint pt, UINT nFlags, int nIndex, bool bLeftButton)
{
// CRect rc; GetItemRect(nIndex, rc);
// ClientToScreen(rc);
if (PreDoDragDrop(m_hWnd, NULL, false)) {// now dragging
_HotItem();// clean up hot item
CComPtr<IDataObject> spDataObject;
T* pT = static_cast<T*>(this);
// set up current drag item index list
GetCurMultiSel(m_arrCurDragItems);
if (m_arrCurDragItems.Find(nIndex) == -1) {// not multi-select draging
m_arrCurDragItems.RemoveAll();
m_arrCurDragItems.Add(nIndex);
}
HRESULT hr = pT->OnGetTabCtrlDataObject(m_arrCurDragItems, &spDataObject);
if (SUCCEEDED(hr)) {
m_bDragFromItself = true;
DROPEFFECT dropEffect = DoDragDrop(spDataObject, DROPEFFECT_MOVE|DROPEFFECT_COPY|DROPEFFECT_LINK);
m_bDragFromItself = false;
}
m_arrCurDragItems.RemoveAll();
}
else {
if (bLeftButton) {
SetCurSel(nIndex, true);
NMHDR nmhdr = { m_hWnd, GetDlgCtrlID(), TCN_SELCHANGE };
::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nmhdr);
}
else {
SendMessage(WM_RBUTTONUP, (WPARAM)nFlags, MAKELPARAM(pt.x, pt.y));
}
}
}
};
////////////////////////////////////////////////////////////////////////////
} //namespace MTL
#ifndef _MTL_NO_AUTOMATIC_NAMESPACE
using namespace MTL;
#endif //!_MTL_NO_AUTOMATIC_NAMESPACE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -