📄 categorybar.cpp
字号:
rect.bottom -= yTopMargin;
rect.top -= y;
rect.bottom -= y;
}
else
{
rect.SetRect(rc.left + (rc.Width() - sz.cx)/2, top, rc.left + (rc.Width() - sz.cx)/2 + sz.cx, top + sz.cy);
rect.top -= y + 3;
rect.bottom -= y + 2;
}
}
void CCategoryBar::GetLabelRect(const int iFolder, const int iIndex, CRect & rect)
{
CRect rc;
GetInsideRect(rc);
int top = rc.top;
CSize sz(0,0);
int y = 0;
int spacing = IsSmallIconView() ? ySmallIconSpacing : yLargeIconSpacing;
for (int t = 0; t < iIndex; t++)
{
sz = GetItemSize(iFolder, t, ircAll);
top += sz.cy;
top += spacing;
if (t == iFirstItem - 1) y = top - rc.top;
}
top += spacing;
sz = GetItemSize(iFolder, iIndex, ircAll);
CSize szLabel = GetItemSize(iFolder, iIndex, ircLabel);
if (IsSmallIconView())
{
rect.SetRect(rc.left, top, rc.left + sz.cx, top + sz.cy);
rect.left += xLeftMargin + 2;
rect.right += xLeftMargin + 2;
rect.top += yTopMargin - 5;
rect.bottom += yTopMargin - 5;
}
else
{
rect.SetRect(rc.left + (rc.Width() - sz.cx)/2, top, rc.left + (rc.Width() - sz.cx)/2 + sz.cx, top + sz.cy);
rect.top -= y + 3;
rect.bottom -= y + 2;
rect.bottom -= yLargeIconSpacing;
rect.top = rect.bottom - szLabel.cy;
}
}
void CCategoryBar::StartGroupEdit(const int index)
{
CGroupEdit * pEdit = new CGroupEdit;
pEdit->iIndex = index;
CRect rc;
GetFolderRect(index, rc);
rc.InflateRect(-2,-2);
pEdit->Create(WS_CHILD|WS_VISIBLE|ES_CENTER|ES_MULTILINE,rc,this,1);
pEdit->msgSend = NM_OB_ONGROUPENDEDIT;
pEdit->ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_FRAMECHANGED);
ASSERT(index >= 0 && index < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(index);
pEdit->SetWindowText(pbf->cName);
pEdit->SetFocus();
}
void CCategoryBar::StartItemEdit(const int index)
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
ASSERT(index >= 0 && index < pbf->GetItemCount());
CBarItem * pi = (CBarItem *) pbf->arItems.GetAt(index);
CGroupEdit * pEdit = new CGroupEdit;
pEdit->iIndex = index;
CRect rc, crc;
GetLabelRect(iSelFolder, index, rc);
GetInsideRect(crc);
DWORD dwFlag = WS_CHILD|WS_VISIBLE|WS_BORDER;
if (!IsSmallIconView())
{
rc.left = crc.left + 5;
rc.right = crc.right - 5;
rc.bottom += 5;
dwFlag |= ES_CENTER|ES_MULTILINE;
}
else
{
CRect irc;
GetIconRect(iSelFolder, index, irc);
dwFlag |= ES_AUTOHSCROLL;
rc.OffsetRect(irc.Width()+1, -6);
pEdit->bNoDown = true;
}
pEdit->Create(dwFlag, rc, this, 1);
pEdit->msgSend = NM_OB_ONLABELENDEDIT;
pEdit->SetWindowText(pi->cItem);
pEdit->SetFocus();
}
void CCategoryBar::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
iHitInternal1 = HitTestEx(point, iHitInternal2);
if (iHitInternal1 == htItem)
{
SetCapture();
CPoint pt = point;
ClientToScreen(&pt);
// Load the popup menu.
VERIFY(m_popupMenu.LoadMenu(IDR_CATEGORYBAR));
CCJMenu* pPopup = (CCJMenu*)m_popupMenu.GetSubMenu(0);
ASSERT(pPopup != NULL);
// Load toolbar resource if any for menu icons.
pPopup->LoadToolbar(IDR_CATEGORYBAR);
// Display the popup menu, use the main window as its parent.
pPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON,
pt.x, pt.y, this );
m_popupMenu.DestroyMenu();
ReleaseCapture();
}
CWnd::OnRButtonDown(nFlags, point);
}
void CCategoryBar::OnCategoryLargeicon()
{
SetSmallIconView(false);
Invalidate();
}
void CCategoryBar::OnUpdateCategoryLargeicon(CCmdUI* pCmdUI)
{
pCmdUI->Enable(IsSmallIconView());
}
void CCategoryBar::OnCategorySmallicon()
{
SetSmallIconView(true);
Invalidate();
}
void CCategoryBar::OnUpdateCategorySmallicon(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!IsSmallIconView());
}
void CCategoryBar::OnCategoryHide()
{
AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_VIEW_CATEGORY);
}
void CCategoryBar::RemoveItem(const int index)
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
ASSERT(index >= 0 && index < pbf->GetItemCount());
if (IsValidItem(index) &&
GetOwner()->SendMessage(WM_CATEGORY_NOTIFY, NM_OB_ITEMDELETE, index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
delete i;
pbf->arItems.RemoveAt(index);
CRect rc;
GetInsideRect(rc);
InvalidateRect(rc);
}
}
bool CCategoryBar::IsValidItem(const int index) const
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
return (index >= 0 && index < pbf->GetItemCount());
}
DWORD CCategoryBar::GetItemData(const int index) const
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
return i->dwData;
}
return 0;
}
int CCategoryBar::GetItemImage(const int index) const
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
return i->iImageIndex;
}
return 0;
}
void CCategoryBar::SetItemData(const int index, const DWORD dwData)
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
i->dwData = dwData;
}
}
void CCategoryBar::SetItemImage(const int index, const int iImage)
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
i->iImageIndex = iImage;
}
}
void CCategoryBar::DrawDragArrow(CDC * pDC, const int /*iFrom*/, const int iTo)
{
if (iTo == iLastDragItemDraw) return;
CRect rc1;
if (iLastDragItemDraw >= 0)
{
GetDragItemRect(iLastDragItemDraw, rc1);
if (iLastDragItemDrawType == 0) rc1.bottom = rc1.top + 5;
else if (iLastDragItemDrawType == 1) { rc1.top -= 4; rc1.bottom = rc1.top + 9; }
else if (iLastDragItemDrawType == 2) { rc1.top -= 4; rc1.bottom = rc1.top + 5; }
InvalidateRect(rc1, true);
UpdateWindow();
}
iLastDragItemDraw = iTo;
if (iLastDragItemDraw >= 0)
{
iLastDragItemDrawType = GetDragItemRect(iLastDragItemDraw, rc1);
CPen * op = pDC->SelectObject(pBlackPen);
pDC->MoveTo(rc1.left, rc1.top);
pDC->LineTo(rc1.right, rc1.top);
if (iLastDragItemDrawType != 2)
{
pDC->MoveTo(rc1.left, rc1.top+1);
pDC->LineTo(rc1.left + 7, rc1.top+1);
pDC->MoveTo(rc1.left, rc1.top+2);
pDC->LineTo(rc1.left + 5, rc1.top+2);
pDC->MoveTo(rc1.left, rc1.top+3);
pDC->LineTo(rc1.left + 3, rc1.top+3);
pDC->MoveTo(rc1.left, rc1.top+4);
pDC->LineTo(rc1.left + 1, rc1.top+4);
pDC->MoveTo(rc1.right-1, rc1.top+1);
pDC->LineTo(rc1.right - 7, rc1.top+1);
pDC->MoveTo(rc1.right-1, rc1.top+2);
pDC->LineTo(rc1.right - 5, rc1.top+2);
pDC->MoveTo(rc1.right-1, rc1.top+3);
pDC->LineTo(rc1.right - 3, rc1.top+3);
}
if (iLastDragItemDrawType != 0)
{
pDC->MoveTo(rc1.left, rc1.top-1);
pDC->LineTo(rc1.left + 7, rc1.top-1);
pDC->MoveTo(rc1.left, rc1.top-2);
pDC->LineTo(rc1.left + 5, rc1.top-2);
pDC->MoveTo(rc1.left, rc1.top-3);
pDC->LineTo(rc1.left + 3, rc1.top-3);
pDC->MoveTo(rc1.left, rc1.top-4);
pDC->LineTo(rc1.left + 1, rc1.top-4);
pDC->MoveTo(rc1.right-1, rc1.top-1);
pDC->LineTo(rc1.right - 7, rc1.top-1);
pDC->MoveTo(rc1.right-1, rc1.top-2);
pDC->LineTo(rc1.right - 5, rc1.top-2);
pDC->MoveTo(rc1.right-1, rc1.top-3);
pDC->LineTo(rc1.right - 3, rc1.top-3);
pDC->MoveTo(rc1.right-1, rc1.top-4);
pDC->LineTo(rc1.right - 1, rc1.top-4);
}
pDC->SelectObject(op);
}
}
int CCategoryBar::GetDragItemRect(const int index, CRect & rect)
{
CRect rc, crc;
GetInsideRect(crc);
crc.InflateRect(-2, 0);
GetItemRect(iSelFolder, index < GetItemCount() ? index : index - 1, rc);
int line = 0;
if (index < GetItemCount())
{
line = rc.top - 4;
}
else
{
line = rc.bottom + 6;
}
int tpe;
if (index == 0)
{
rect.SetRect(crc.left, line+2, crc.right, line + 7);
tpe = 0;
}
else if (index < GetItemCount())
{
rect.SetRect(crc.left, line - 9, crc.right, line);
tpe = 1;
if (IsSmallIconView())
{
rect.top += 8;
rect.bottom += 8;
}
}
else
{
rect.SetRect(crc.left, line, crc.right, line + 5);
tpe = 2;
}
return tpe;
}
void CCategoryBar::AnimateFolderScroll(const int iFrom, const int iTo)
{
ASSERT(iFrom >= 0 && iFrom < GetFolderCount());
ASSERT(iTo >= 0 && iTo < GetFolderCount());
CRect rc, rc1, frc, frc1;
GetInsideRect(rc);
rc1.SetRect(0,0,rc.Width(),rc.Height());
GetFolderRect(iTo, frc);
frc1 = frc;
CClientDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bmpFrom, bmpTo;
bmpFrom.CreateCompatibleBitmap(&dc, rc1.Width(), rc1.Height() + frc.Height() * 2);
bmpTo.CreateCompatibleBitmap(&dc, rc1.Width(), rc1.Height() + frc.Height() * 2);
CDC * pDC = &memDC;
CWnd * pWnd1 = GetFolderChild(iFrom);
CWnd * pWnd2 = GetFolderChild(iTo);
CBitmap * obmp = pDC->SelectObject(&bmpFrom);
if (iTo > iFrom)
{
rc1.bottom += frc.Height() * 2;
pDC->FillSolidRect(rc1, crBackGroundColor);
if (pWnd1)
{
BOOL bPrev = pWnd1->ShowWindow(SW_SHOW);
pWnd1->SendMessage(WM_ERASEBKGND, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
pWnd1->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
if (!bPrev) pWnd1->ShowWindow(SW_HIDE);
}
else PaintItems(pDC, iFrom, rc1);
pDC->SelectObject(&bmpTo);
frc.SetRect(0,0,frc.Width(),frc.Height());
rc1.SetRect(0,frc.Height(),rc.Width(), rc.Height()+frc.Height() * 2);
pDC->FillSolidRect(rc1, crBackGroundColor);
if (pWnd2)
{
CPoint ovpt = pDC->SetViewportOrg(0, frc.Height());
BOOL bPrev = pWnd2->ShowWindow(SW_SHOW);
pWnd2->SendMessage(WM_ERASEBKGND, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
pWnd2->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
if (!bPrev) pWnd2->ShowWindow(SW_HIDE);
pDC->SetViewportOrg(ovpt);
}
else PaintItems(pDC, iTo, rc1);
DrawFolder(pDC, iTo, frc, false);
}
else
{
frc.SetRect(0,0,frc.Width(),frc.Height());
rc1.top += frc.Height();
rc1.bottom += frc.Height() * 2;
pDC->FillSolidRect(rc1, crBackGroundColor);
if (pWnd1)
{
CPoint ovpt = pDC->SetViewportOrg(0, frc.Height());
BOOL bPrev = pWnd1->ShowWindow(SW_SHOW);
pWnd1->SendMessage(WM_ERASEBKGND, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
pWnd1->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
if (!bPrev) pWnd1->ShowWindow(SW_HIDE);
pDC->SetViewportOrg(ovpt);
}
else PaintItems(pDC, iFrom, rc1);
DrawFolder(pDC, iFrom, frc, false);
pDC->SelectObject(&bmpTo);
rc1.SetRect(0,0,rc.Width(), rc.Height() + frc.Height() * 2);
pDC->FillSolidRect(rc1, crBackGroundColor);
if (pWnd2)
{
BOOL bPrev = pWnd2->ShowWindow(SW_SHOW);
pWnd2->SendMessage(WM_ERASEBKGND, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
pWnd2->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
if (!bPrev) pWnd2->ShowWindow(SW_HIDE);
}
else PaintItems(pDC, iTo, rc1);
}
if (iTo > iFrom)
{
CRect rcFrom, rcTo;
GetFolderRect(iFrom, rcFrom);
GetFolderRect(iTo, rcTo);
int fh = rcFrom.Height();
for (int y = rcTo.top - fh; y > rcFrom.bottom; y -= fh)
{
pDC->SelectObject(&bmpFrom);
dc.BitBlt(rc.left, rcFrom.bottom + 1, rc.Width(), y - rcFrom.bottom - 1, pDC, 0,fh, SRCCOPY);
pDC->SelectObject(&bmpTo);
dc.BitBlt(rc.left, y, rc.Width(), rc.bottom - y + fh, pDC, 0,0, SRCCOPY);
Sleep(lAnimationTickCount);
}
}
else
{
CRect rcFrom, rcTo;
GetFolderRect(iFrom, rcFrom);
int fh = rcFrom.Height();
rcTo.SetRect(rc.left, rc.bottom, rc.right, rc.bottom - fh);
for (int y = rcFrom.top + 1; y < rcTo.top - fh; y += fh)
{
pDC->SelectObject(&bmpTo);
dc.BitBlt(rc.left, rcFrom.top, rc.Width(), y - rcFrom.top - 1, pDC, 0, fh*2, SRCCOPY);
pDC->SelectObject(&bmpFrom);
dc.BitBlt(rc.left, y, rc.Width(), rc.bottom - y, pDC, 0,0, SRCCOPY);
Sleep(lAnimationTickCount);
}
}
pDC->SelectObject(obmp);
// fix potential resource leak - KStowell - 10-21-99
memDC.DeleteDC();
bmpFrom.DeleteObject();
bmpTo.DeleteObject();
}
CString CCategoryBar::GetItemText(const int index)
{
CString item;
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
if (IsValidItem(index))
{
CBarItem * pi = (CBarItem *) pbf->arItems.GetAt(index);
if (pi->cItem) item = pi->cItem;
}
return item;
}
int CCategoryBar::AddFolderBar( LPCTSTR pFolder, CWnd* pSon, const DWORD exData )
{
CBarFolder* pbf = new CBarFolder( pFolder, exData );
ASSERT( pbf );
pbf->pChild = pSon;
arFolder.Add((void*) pbf);
return arFolder.GetSize() - 1;
}
CWnd * CCategoryBar::GetFolderChild(int iFolder)
{
if (GetFolderCount())
{
if (iFolder < 0) iFolder = iSelFolder;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
return pbf->pChild;
}
return NULL;
}
DWORD CCategoryBar::GetFolderData(int iFolder)
{
if (iFolder < 0) iFolder = iSelFolder;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
return pbf->dwData;
}
void CCategoryBar::SetAnimSelHighlight(const int iTime)
{
// if (iTime <= 0) KillTimer(3);
// else SetTimer(3, iTime, NULL);
// iSelAnimTiming = iTime;
}
void CCategoryBar::OnSysColorChange()
{
crBackGroundColor = ::GetSysColor(COLOR_3DSHADOW);//RGB(0,128,128);//
crBackGroundColor1 = ::GetSysColor(COLOR_3DSHADOW);
crTextColor = ::GetSysColor(COLOR_WINDOW);
cr3dFace = ::GetSysColor(COLOR_3DFACE);
crLightBorder = ::GetSysColor(COLOR_3DLIGHT);
crHilightBorder = ::GetSysColor(COLOR_3DHILIGHT);
crShadowBorder = ::GetSysColor(COLOR_3DSHADOW);
crDkShadowBorder = ::GetSysColor(COLOR_3DDKSHADOW);
CWnd::OnSysColorChange();
// TODO: Add your message handler code here
}
void CCategoryBar::GetHighItemRect(CRect &rect)
{
CRect rc;
GetInsideRect(rc);
GetItemRect(iSelFolder, iLastItemHighlighted, rect);
if (IsSmallIconView()){
rect.top -= ySmallIconSpacing/2;
rect.bottom += ySmallIconSpacing/2;
rect.left = rc.left;
rect.right = rc.right;
}
else
rect.top -= yLargeIconSpacing;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -