📄 gfxoutbarctrl.cpp
字号:
else
rect.SetRect(rc.left, rc.top + iIndex * iFolderHeight - 1, rc.right,
rc.top + (1 + iIndex) * iFolderHeight - 1);
return true;
}
return false;
}
void CGfxOutBarCtrl::GetItemRect(const int iFolder, const int iIndex, CRect & rect)
{
CRect rc;
GetInsideRect(rc);
int top = rc.top;
CSize sz(0,0);
int y = 0;
for (int t = 0; t < iIndex; t++)
{
sz = GetItemSize(iFolder, t, ircAll);
top += sz.cy;
if (IsSmallIconView())
{
top += ySmallIconSpacing;
}
else
{
top += yLargeIconSpacing;
}
if (t == iFirstItem - 1) y = top - rc.top;
}
sz = GetItemSize(iFolder, iIndex, ircAll);
rect.SetRect(rc.left, top, rc.left + sz.cx, top + sz.cy);
rect.top -= y;
rect.bottom -= y;
rect.left += xLeftMargin;
rect.top += yTopMargin;
rect.bottom += yTopMargin;
if (!IsSmallIconView())
{
rect.left = rc.left;
rect.right = rc.right;
}
}
void CGfxOutBarCtrl::DrawFolder(CDC * pDC, const int iIdx, CRect rect, const bool bSelected)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iIdx);
if (!bSelected)
{
CPen pn1(PS_SOLID, 1, crBackGroundColor1);
CPen * op = pDC->SelectObject(&pn1);
pDC->MoveTo(rect.left, rect.top);
pDC->LineTo(rect.right, rect.top);
pDC->SelectObject(op);
rect.top ++;
pDC->Draw3dRect(rect, crHilightBorder, crBackGroundColor1);
rect.InflateRect(-1,-1);
pDC->FillSolidRect(rect, cr3dFace);
int obk = pDC->SetBkMode(TRANSPARENT);
CFont * of = pDC->SelectObject(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
pDC->DrawText(CString(pbf->cName), rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->SetBkMode(obk);
pDC->SelectObject(of);
}
else
{
CPen pn1(PS_SOLID, 1, crBackGroundColor1);
CPen * op = pDC->SelectObject(&pn1);
pDC->MoveTo(rect.left+1, rect.top);
pDC->LineTo(rect.right, rect.top);
pDC->SelectObject(op);
rect.top ++;
pDC->Draw3dRect(rect, crDkShadowBorder, crHilightBorder);
rect.InflateRect(-1,-1);
pDC->Draw3dRect(rect, crBackGroundColor1, cr3dFace);
rect.InflateRect(-1,-1);
pDC->FillSolidRect(rect, cr3dFace);
int obk = pDC->SetBkMode(TRANSPARENT);
CFont * of = pDC->SelectObject(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
pDC->DrawText(CString(pbf->cName), rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->SetBkMode(obk);
pDC->SelectObject(of);
}
}
int CGfxOutBarCtrl::AddFolder(const char * cFolderName, const DWORD exData)
{
CBarFolder * pbf = new CBarFolder(cFolderName, exData);
ASSERT(pbf);
arFolder.Add((void *)pbf);
return arFolder.GetSize() - 1;
}
CGfxOutBarCtrl::CBarFolder::CBarFolder(const char * name, DWORD exData)
{
cName = NULL;
dwData = exData;
if (name)
{
cName = new char[lstrlen(name)+1];
ASSERT(cName);
lstrcpy(cName, name);
}
pLargeImageList = NULL;
pSmallImageList = NULL;
pChild = NULL;
}
CGfxOutBarCtrl::CBarFolder::~CBarFolder()
{
if (cName) delete [] cName;
for (int t = 0; t < arItems.GetSize(); t++)
if (arItems.GetAt(t)) delete (CBarFolder*) arItems.GetAt(t);
arItems.RemoveAll();
}
void CGfxOutBarCtrl::GetInsideRect(CRect & rect) const
{
GetClientRect(rect);
if (arFolder.GetSize() > 0)
{
int max = arFolder.GetSize();
rect.top += iFolderHeight * (iSelFolder + 1) - 1;//+ 2;
rect.bottom -= (max - iSelFolder - 1)*iFolderHeight;
return;
}
}
void CGfxOutBarCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
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,10,NULL);//此定时器用来指示鼠标移过图标或目录时的动画。
}
else if (ht == htItem)
{
HighlightItem(index);
SetTimer(1,10,NULL);
}
CWnd::OnMouseMove(nFlags, point);
}
int CGfxOutBarCtrl::HitTestEx(const CPoint & point, int &index)
{
if (bUpArrow && rcUpArrow.PtInRect(point)) return htUpScroll;
if (bDownArrow && rcDownArrow.PtInRect(point)) return htDownScroll;
int max = arFolder.GetSize(), t;
CRect rc;
for (t = 0; t < max; t++)
{
GetFolderRect(t, rc);
if (rc.PtInRect(point))
{
index = t;
return htFolder;
}
}
GetInsideRect(rc);
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
max = pbf->GetItemCount();
for (t = iFirstItem; t < max; t++)
{
CBarItem * pi = (CBarItem *) pbf->arItems.GetAt(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 CGfxOutBarCtrl::HighlightFolder(const int index)
{
CWnd * pf = GetFocus();
if (pf != NULL && pf != this && IsChild(pf)) return;
if (iLastFolderHighlighted == index) return;
if (iLastFolderHighlighted >= 0)
{
CRect rc;
if (GetFolderRect(iLastFolderHighlighted, rc))
{
CClientDC dc(this);
CPen pn(PS_SOLID, 1, crBackGroundColor1);//crShadowBorder);
CPen * op = dc.SelectObject(&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(PS_SOLID, 1, cr3dFace);
dc.SelectObject(&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.SelectObject(op);
}
}
iLastFolderHighlighted = index;
if (iLastFolderHighlighted >= 0)
{
CRect rc;
if (GetFolderRect(iLastFolderHighlighted, rc))
{
CClientDC dc(this);
CPen pn(PS_SOLID, 1, crDkShadowBorder);
CPen * op = dc.SelectObject(&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(PS_SOLID, 1, crBackGroundColor1);
dc.SelectObject(&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.SelectObject(op);
}
}
}
void CGfxOutBarCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
//把消息分开来处理
//这里,应该弹出对话框
//在哪里才能删除这个对话框所占用的内存呢
Y_Msg *DispMsg = new Y_Msg;
int tempIndex=0;
int tempIndexMsg=-1;
int tempData;
int index, ht = HitTestEx(point, index);
if(ht ==htItem)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
CBarItem * piFrom = (CBarItem *) pbf->arItems.GetAt(index);
// InsertItem(idx, piFrom->OnLineUser, piFrom->cItem ,piFrom->iImageIndex , piFrom->dwData,piFrom->IsAnimDisp);
for(int tempIndex=0;tempIndex<MAXFRIENDSIZE;tempIndex++)
{
if(SockUserDef.Friend[tempIndex].Friend==piFrom->OnLineUser)
{
if(SockUserDef.Friend[tempIndex].RcvBuffer.GetSize())
{
if(SockUserDef.Friend[tempIndex].OnOrDown)
{
tempData=1;
}
else
{
tempData=0;
}
//下面这一句,应该写在对话框中。
//当对话框显示一条消息,就相应地删除一条消息
InsertItem(SockUserDef.Friend[tempIndex].Foder,
SockUserDef.Friend[tempIndex].Friend ,
SockUserDef.Friend[tempIndex].Name ,
SockUserDef.Friend[tempIndex].ImgIndex*3+tempData,
SockUserDef.Friend[tempIndex].OnOrDown,0);
tempIndexMsg=tempIndex;
RedrawWindow ();
}
DispMsg->FriendID=SockUserDef.Friend[tempIndex].Friend;
DispMsg->FriendIndex=tempIndexMsg;
DispMsg->Create (IDD_MESSAGE);
DispMsg->ShowWindow (SW_SHOW);
break;
}
}
}
}
void CGfxOutBarCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
if (GetFocus() != this) 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();
ASSERT(this == GetCapture());
CClientDC dc(this);
DrawFolder(&dc, index, rc, true);
AfxLockTempMaps();
for (;;)
{
MSG msg;
VERIFY(::GetMessage(&msg, NULL, 0, 0));
if (CWnd::GetCapture() != this) 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://鼠标在目录上UP
{
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();
ASSERT(this == GetCapture());
CClientDC dc(this);
HighlightItem(index, true);
AfxLockTempMaps();
for (;;)
{
MSG msg;
VERIFY(::GetMessage(&msg, NULL, 0, 0));
if (CWnd::GetCapture() != this) break;
switch (msg.message)
{
case WM_MOUSEMOVE:
{
CPoint pt(msg.lParam);
int idx, ht1 = HitTestEx(pt, idx);
if (bDragging)
{//在拖动模式下,只允许跨目录拖动
if (ht1 == 0)
{
// 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
{
DrawDragArrow(&dc, index, -1);
SetCursor(hNoDragCursor);
hCur = hNoDragCursor;
}
}
}
else
{
if (ht1 == htItem && idx == index)
{
if (!bHigh)
{
HighlightItem(index, true);
bHigh = true;
bPressedHighlight = true;
}
}
else
{
if (ht1 == htItem)
{
if (bHigh)
{
HighlightItem(index, false);
bHigh = false;
bPressedHighlight = false;
}
}
else
{
if (dwFlags&fDragItems)
{
HighlightItem(index, true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -