📄 atloutbarctrl.h
字号:
void HighlightFolder(const int index)
{
HWND hFocusedWindow = GetFocus();
CWindow pf(hFocusedWindow);
if (hFocusedWindow != NULL && hFocusedWindow != m_hWnd && pf.IsChild(hFocusedWindow)) return;
if (iLastFolderHighlighted == index) return;
if (iLastFolderHighlighted >= 0)
{
CRect rc;
if (GetFolderRect(iLastFolderHighlighted, rc))
{
CClientDC dc(m_hWnd);
CPen pn;
pn.CreatePen(PS_SOLID, 1, crBackGroundColor1);//crShadowBorder);
HPEN op = dc.SelectPen(pn);
dc.MoveTo(rc.left, rc.bottom-1);
dc.LineTo(rc.right-1, rc.bottom-1);
dc.LineTo(rc.right-1, rc.top);
CPen pn1;
pn1.CreatePen(PS_SOLID, 1, cr3dFace);
dc.SelectPen(pn1);
dc.MoveTo(rc.left+1, rc.bottom-2);
dc.LineTo(rc.right-2, rc.bottom-2);
dc.LineTo(rc.right-2, rc.top+1);
dc.SelectPen(op);
pn.DeleteObject();
}
}
iLastFolderHighlighted = index;
if (iLastFolderHighlighted >= 0)
{
CRect rc;
if (GetFolderRect(iLastFolderHighlighted, rc))
{
CClientDC dc(m_hWnd);
CPen pn;
pn.CreatePen(PS_SOLID, 1, crDkShadowBorder);
HPEN op = dc.SelectPen(pn);
dc.MoveTo(rc.left, rc.bottom-1);
dc.LineTo(rc.right-1, rc.bottom-1);
dc.LineTo(rc.right-1, rc.top);
CPen pn1;
pn1.CreatePen(PS_SOLID, 1, crBackGroundColor1);
dc.SelectPen(pn1);
dc.MoveTo(rc.left+1, rc.bottom-2);
dc.LineTo(rc.right-2, rc.bottom-2);
dc.LineTo(rc.right-2, rc.top+1);
dc.SelectPen(op);
pn.DeleteObject();
}
}
}
int HitTestEx(const CPoint &point, int &index)
{
if (bUpArrow && rcUpArrow.PtInRect(point)) return htUpScroll;
if (bDownArrow && rcDownArrow.PtInRect(point)) return htDownScroll;
int max = arFolder.size(), t;
CRect rc;
for (t = 0; t < max; t++)
{
GetFolderRect(t, rc);
if (rc.PtInRect(point))
{
index = t;
return htFolder;
}
}
GetInsideRect(rc);
CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
max = pbf->GetItemCount();
for (t = iFirstItem; t < max; t++)
{
CBarItem* pi = GetBarItemListItem(pbf, t);
CRect itemRc;
if (!IsSmallIconView())
{
GetIconRect(iSelFolder, t, itemRc);
if (itemRc.PtInRect(point))
{
index = t;
return htItem;
}
else if (itemRc.top > rc.bottom) break;
GetLabelRect(iSelFolder, t, itemRc);
itemRc.top -= yLargeIconLabelOffset;
if (itemRc.PtInRect(point))
{
index = t;
return htItem;
}
else if (itemRc.top > rc.bottom) break;
}
else
{
GetItemRect(iSelFolder, t, itemRc);
if (itemRc.PtInRect(point))
{
index = t;
return htItem;
}
else if (itemRc.top > rc.bottom) break;
}
}
return htNothing;
}
void ModifyFlag(const DWORD &dwRemove, const DWORD &dwAdd, const UINT redraw = 0)
{
if (dwRemove) dwFlags &= ~(dwRemove);
if (dwAdd) dwFlags |= dwAdd;
if (m_hWnd)
{
if (redraw != 0) SetWindowPos(0,0,0,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|redraw);
else Invalidate();
}
}
DWORD GetFlag() {return dwFlags;}
void SetSmallIconView(const BOOL bSet)
{
iFirstItem = 0;
if (bSet)
{
if (!IsSmallIconView())
{
dwFlags |= fSmallIcon;
CRect rc;
GetInsideRect(rc);
InvalidateRect(rc, FALSE);
}
}
else
{
if (IsSmallIconView())
{
dwFlags &= ~fSmallIcon;
CRect rc;
GetInsideRect(rc);
InvalidateRect(rc, FALSE);
}
}
}
BOOL Create(DWORD dwStyle, RECT& rect, HWND pParentWnd, UINT nID, const DWORD dwFlag = fDragItems|fEditGroups|fEditItems|fRemoveGroups|fRemoveItems|fAddGroups|fAnimation|fSelHighlight)
{
dwFlags = dwFlag;
HWND hWnd = CWindowImpl<COutBarCtrl, CWindow>::Create(pParentWnd, rect, NULL, dwStyle|WS_CHILD, WS_EX_STATICEDGE, nID);
return (hWnd != NULL);
}
protected:
COLORREF crBackGroundColor, crBackGroundColor1;
COLORREF crTextColor;
COLORREF cr3dFace, crLightBorder, crHilightBorder, crShadowBorder, crDkShadowBorder;
CGroupEdit* m_pGroupEdit;
int iFolderHeight;
int xSmallIconLabelOffset, yLargeIconLabelOffset;
int ySmallIconSpacing, yLargeIconSpacing;
int xLeftMargin, yTopMargin;
BOOL bUpArrow, bDownArrow, bUpPressed, bDownPressed;
CRect rcUpArrow, rcDownArrow;
BOOL bLooping;
int iHitInternal1, iHitInternal2;
long lAnimationTickCount;
int iLastSel, iSelAnimTiming;
int iSelAnimCount;
DWORD dwFlags;
int iLastFolderHighlighted;
int iLastSelectedFolder;
int iFirstItem;
int iLastItemHighlighted;
BOOL bPressedHighlight;
int iLastDragItemDraw, iLastDragItemDrawType;
CBarFolderList arFolder;
int iSelFolder;
CImageList* pLargeImageList;
CImageList* pSmallImageList;
HCURSOR hHandCursor;
HCURSOR hNormalCursor;
HCURSOR hDragCursor;
HCURSOR hNoDragCursor;
CPen* pBlackPen;
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
LPCREATESTRUCT lpCreateStruct = (LPCREATESTRUCT)lParam;
return 0;
}
LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
UINT nIDEvent = (UINT)wParam;
if (nIDEvent == 1)
{
CPoint pt(GetMessagePos());
ScreenToClient(&pt);
CRect rc;
GetClientRect(&rc);
if (!(rc.PtInRect(pt)))
{
HighlightFolder(-1);
HighlightItem(-1);
KillTimer(1);
}
}
else if (nIDEvent == 3 && iLastSel >= 0)
{
iSelAnimCount ++;
if (iSelAnimCount > 10) iSelAnimCount = -1;
if (iSelAnimCount == 0)
DrawAnimItem(-1, 1, iLastSel);
if (iSelAnimCount == 1)
DrawAnimItem(0, 0, iLastSel);
if (iSelAnimCount == 2)
DrawAnimItem(1, 1, iLastSel);
if (iSelAnimCount == 3)
DrawAnimItem(0, 0, iLastSel);
}
return 0;
}
LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CRect clientRc;
GetClientRect(&clientRc);
CPaintDC dc(m_hWnd);
CDC* pDC = NULL;
pDC = new CDC;
ATLASSERT(pDC);
pDC->CreateCompatibleDC(dc.m_hDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(dc.m_hDC, clientRc.Width(), clientRc.Height());
HBITMAP obmp = pDC->SelectBitmap(bmp);
CRect rc;
GetInsideRect(rc);
if (!GetFolderChild())
pDC->FillSolidRect(rc, crBackGroundColor);
int max = arFolder.size();
CRect frc;
for (int t = 0; t < max; t++)
{
GetFolderRect(t, frc);
DrawFolder(pDC, t, frc, FALSE);
}
if (!GetFolderChild())
{
int f,l;
GetVisibleRange(iSelFolder, f,l);
rcUpArrow.SetRect(0,0,GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CXVSCROLL));
rcDownArrow = rcUpArrow;
rcUpArrow.OffsetRect(rc.right - 5 - GetSystemMetrics(SM_CXVSCROLL), rc.top +5);
rcDownArrow.OffsetRect(rc.right - 5 - GetSystemMetrics(SM_CXVSCROLL), rc.bottom - 5 - GetSystemMetrics(SM_CXVSCROLL));
if (f > 0)
{
if (bUpPressed) pDC->DrawFrameControl(rcUpArrow, DFC_SCROLL, DFCS_SCROLLUP|DFCS_PUSHED);
else pDC->DrawFrameControl(rcUpArrow, DFC_SCROLL, DFCS_SCROLLUP);
bUpArrow = TRUE;
pDC->ExcludeClipRect(rcUpArrow);
}
else bUpArrow = FALSE;
if (l < GetItemCount() - 1)
{
if (bDownPressed) pDC->DrawFrameControl(rcDownArrow, DFC_SCROLL, DFCS_SCROLLDOWN|DFCS_PUSHED);
else pDC->DrawFrameControl(rcDownArrow, DFC_SCROLL, DFCS_SCROLLDOWN);
bDownArrow = TRUE;
pDC->ExcludeClipRect(rcDownArrow);
}
else bDownArrow = FALSE;
PaintItems(pDC, iSelFolder, rc);
}
dc.BitBlt(clientRc.left, clientRc.top, clientRc.Width(), clientRc.Height(), pDC->m_hDC, 0,0, SRCCOPY);
pDC->SelectBitmap(obmp);
if (iLastFolderHighlighted >= 0)
{
int i = iLastFolderHighlighted;
iLastFolderHighlighted = -1;
HighlightFolder(i);
}
if (iLastItemHighlighted >= 0)
{
int i = iLastItemHighlighted;
iLastItemHighlighted = -1;
HighlightItem(i, bPressedHighlight);
}
pDC->DeleteDC();
bmp.DeleteObject();
if (pDC)
delete pDC;
return 0;
}
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// TODO : Add Code for message handler. Call DefWindowProc if necessary. return 1;
}
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
WORD x, y;
x = LOWORD(lParam);
y = HIWORD(lParam);
CPoint point(x, y);
int index, ht = HitTestEx(point, index);
if (ht != htFolder && iLastFolderHighlighted >= 0) HighlightFolder(-1);
if (ht != htItem && iLastItemHighlighted >= 0) HighlightItem(-1);
if (ht == htFolder)
{
HighlightFolder(index);
SetTimer(1,100);
}
else if (ht == htItem)
{
HighlightItem(index);
SetTimer(1,100);
}
return 0;
}
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
WORD x, y;
x = LOWORD(lParam);
y = HIWORD(lParam);
CPoint point(x, y);
if (GetFocus() != m_hWnd)
SetFocus();
int index, ht = HitTestEx(point, index);
iLastDragItemDrawType = -1;
CRect inRc;
GetInsideRect(inRc);
if (ht == htFolder)
{
BOOL bHigh = TRUE;
CRect rc;
GetFolderRect(index, rc);
if (::GetCapture() == NULL)
{
SetCapture();
ATLASSERT(m_hWnd == GetCapture());
CClientDC dc(m_hWnd);
DrawFolder(&dc, index, rc, TRUE);
//@@AfxLockTempMaps();
for (;;)
{
MSG msg;
::GetMessage(&msg, NULL, 0, 0);
if (GetCapture() != m_hWnd)
break;
switch (msg.message)
{
case WM_MOUSEMOVE:
{
CPoint pt(msg.lParam);
int idx, ht1 = HitTestEx(pt, idx);
if (ht1 == htFolder && idx == index)
{
if (!bHigh)
{
DrawFolder(&dc, index, rc, TRUE);
bHigh = TRUE;
}
}
else
{
if (bHigh)
{
DrawFolder(&dc, index, rc, FALSE);
bHigh = FALSE;
}
}
}
break;
case WM_LBUTTONUP:
{
if (bHigh)
{
DrawFolder(&dc, index, rc, FALSE);
bHigh = FALSE;
}
CPoint pt(msg.lParam);
int idx, ht1 = HitTestEx(pt, idx);
if (ht1 == htFolder && idx != iSelFolder)
SetSelFolder(idx);
}
goto ExitLoop2;
case WM_KEYDOWN:
if (msg.wParam != VK_ESCAPE)
break;
default:
DispatchMessage(&msg);
break;
}
}
ExitLoop2:
ReleaseCapture();
//@@@AfxUnlockTempMaps(FALSE);
}
if (bHigh)
InvalidateRect(rc, FALSE);
}
else iLastSelectedFolder = -1;
if (ht == htItem)
{
iLastDragItemDraw = -1;
BOOL bHigh = TRUE, bDragging = FALSE;
CRect rc;
GetItemRect(iSelFolder, index, rc);
HCURSOR hCur = GetCursor();
if (::GetCapture() == NULL)
{
SetCapture();
ATLASSERT(m_hWnd == GetCapture());
CClientDC dc(m_hWnd);
HighlightItem(index, TRUE);
//@@@AfxLockTempMaps();
for (;;)
{
MSG msg;
::GetMessage(&msg, NULL, 0, 0);
if (GetCapture() != m_hWnd) break;
switch (msg.message)
{
case WM_MOUSEMOVE:
{
CPoint pt(msg.lParam);
int idx, ht1 = HitTestEx(pt, idx);
if (bDragging)
{
if (ht1 == htItem)
{
DrawDragArrow(&dc, index, idx);
SetCursor(hDragCursor);
hCur = hDragCursor;
}
else
{
CRect rcItem;
GetItemRect(iSelFolder, GetItemCount() - 1, rcItem);
if (pt.y > rcItem.bottom && pt.y < inRc.bottom)
{
DrawDragArrow(&dc, index, GetItemCount());
SetCursor(hDragCursor);
hCur = hDragCursor;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -