?? gfxoutbarctrl.cpp
字號:
pEdit->SetWindowText(pi->cItem);
pEdit->SetFocus();
}
void CGfxOutBarCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
iHitInternal1 = HitTestEx(point, iHitInternal2);
CGfxPopupMenu cMenu;
cMenu.CreatePopupMenu();
cMenu.AppendMenu(MF_STRING, ID_GFX_SMALLICON, _ID_GFX_SMALLICON);
cMenu.AppendMenu(MF_STRING, ID_GFX_LARGEICON, _ID_GFX_LARGEICON);
//cMenu.AppendMenu(MF_STRING, ID_GFX_GROUPICON, _ID_GFX_ADDAGROUP);
//cMenu.AppendMenu(MF_STRING, ID_GFX_FONTCICON, _ID_GFX_FONTCOLOR);
//cMenu.AppendMenu(MF_STRING, ID_GFX_BACKCICON, _ID_GFX_BACKCOLOR);
if (iHitInternal1 == htItem)
{
if (dwFlags&fRemoveItems || dwFlags&fEditItems)
{
cMenu.AppendMenu(MF_SEPARATOR);
// if (iSelFolder == 0)
// cMenu.AppendMenu(MF_STRING, ID_GFX_CHANGGROUP, _ID_GFX_CHANGEGROUP);
// else if (iSelFolder == 2)
// cMenu.AppendMenu(MF_STRING, ID_GFX_CHANGFRIEND, _ID_GFX_CHANGFRIEND);
// if (dwFlags&fRemoveItems)
// cMenu.AppendMenu(MF_STRING, ID_GFX_REMOVEITEM, _ID_GFX_REMOVEITEM);
// if (dwFlags&fEditItems)
// cMenu.AppendMenu(MF_STRING, ID_GFX_RENAMEITEM, _ID_GFX_RENAMEITEM);
}
}
else if (iHitInternal1 == htFolder)
{
if (dwFlags&fRemoveGroups || dwFlags&fEditGroups)
{
//cMenu.AppendMenu(MF_SEPARATOR);
// if (dwFlags&fRemoveGroups)
// cMenu.AppendMenu(MF_STRING, ID_GFX_REMOVEITEM, _ID_GFX_REMOVEITEM);
//if (dwFlags&fEditGroups)
//cMenu.AppendMenu(MF_STRING, ID_GFX_RENAMEITEM, _ID_GFX_RENAMEITEM);
}
}
cMenu.LoadToolBarResource(IDR_MAINFRAME);
cMenu.RemapMenu(&cMenu);
cMenu.EnableMenuItems(&cMenu, this);
CPoint pt(point);
ClientToScreen(&pt);
cMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this);
cMenu.DestroyMenu();
CWnd::OnRButtonDown(nFlags, point);
}
void CGfxOutBarCtrl::OnGfxLargeicon()
{
SetSmallIconView(false);
Invalidate();
}
void CGfxOutBarCtrl::OnUpdateGfxLargeicon(CCmdUI* pCmdUI)
{
pCmdUI->Enable(IsSmallIconView());
}
void CGfxOutBarCtrl::OnGfxSmallicon()
{
SetSmallIconView(true);
Invalidate();
}
void CGfxOutBarCtrl::OnUpdateGfxSmallicon(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!IsSmallIconView());
}
/*void CGfxOutBarCtrl::OnGfxRemoveitem()
{
if (iHitInternal1 == htFolder)
{
RemoveFolder(iHitInternal2);
}
else if (iHitInternal1 == htItem)
{
RemoveItem(iHitInternal2);
}
}*/
/*void CGfxOutBarCtrl::OnUpdateGfxRemoveitem(CCmdUI* pCmdUI)
{
}*/
void CGfxOutBarCtrl::OnGfxRenameitem()
{
if (iHitInternal1 == htFolder)
{
StartGroupEdit(iHitInternal2);
}
else if (iHitInternal1 == htItem)
{
StartItemEdit(iHitInternal2);
}
}
void CGfxOutBarCtrl::OnUpdateGfxRenameitem(CCmdUI* pCmdUI)
{
}
void CGfxOutBarCtrl::RemoveItem(const int index)
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
ASSERT(index >= 0 && index < pbf->GetItemCount());
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
delete i;
pbf->arItems.RemoveAt(index);
if (iLastSel == index)
iLastSel = -1;
CRect rc;
GetInsideRect(rc);
InvalidateRect(rc);
}
}
void CGfxOutBarCtrl::RemoveItem(const int iFolder, const int index)
{
ASSERT(iFolder >= 0 && iFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
ASSERT(index >= 0 && index < pbf->GetItemCount());
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
delete i;
pbf->arItems.RemoveAt(index);
if (iSelFolder == iFolder && iLastSel == index)
iLastSel = -1;
CRect rc;
GetInsideRect(rc);
InvalidateRect(rc);
}
}
bool CGfxOutBarCtrl::IsValidItem(const int index) const
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
return (index >= 0 && index < pbf->GetItemCount());
}
DWORD CGfxOutBarCtrl::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;
}
DWORD CGfxOutBarCtrl::GetItemData(const int iFolder, const int index)
{
ASSERT(iFolder >= 0 && iFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
return i->dwData;
}
return 0;
}
int CGfxOutBarCtrl::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 CGfxOutBarCtrl::SetItemData(const int iFolder, const int index, const DWORD dwData)
{
ASSERT(iFolder >= 0 && iFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
if (IsValidItem(index))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
i->dwData = dwData;
}
}
void CGfxOutBarCtrl::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 CGfxOutBarCtrl::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 CGfxOutBarCtrl::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 CGfxOutBarCtrl::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);
}
CString CGfxOutBarCtrl::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 CGfxOutBarCtrl::AddFolderBar(const char * 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 * CGfxOutBarCtrl::GetFolderChild(int iFolder)
{
if (GetFolderCount())
{
if (iFolder < 0) iFolder = iSelFolder;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
return pbf->pChild;
}
return NULL;
}
DWORD CGfxOutBarCtrl::GetFolderData(int iFolder)
{
if (iFolder < 0) iFolder = iSelFolder;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
return pbf->dwData;
}
void CGfxOutBarCtrl::SetAnimSelHighlight(const int iTime)
{
if (iTime <= 0) KillTimer(3);
else SetTimer(3, iTime, NULL);
iSelAnimTiming = iTime;
}
void CGfxOutBarCtrl::FlashItem(int nFolder, int nItem)
{
FLASH_ITEM *pFlashItem;
for (int i=0;i<m_FlashItems.GetSize();i++)
{
pFlashItem = (FLASH_ITEM *)m_FlashItems.GetAt(i);
if (pFlashItem->nFolder == nFolder)
if (pFlashItem->nItem == nItem)
return;
}
pFlashItem = new FLASH_ITEM;
pFlashItem->nFolder = nFolder;
pFlashItem->nItem = nItem;
m_FlashItems.Add((CObject *)pFlashItem);
}
void CGfxOutBarCtrl::UnFlashItem(int nFolder, int nItem)
{
FLASH_ITEM *pFlashItem;
for (int i=0;i<m_FlashItems.GetSize();i++)
{
pFlashItem = (FLASH_ITEM *)m_FlashItems.GetAt(i);
if (pFlashItem->nFolder == nFolder)
if (pFlashItem->nItem == nItem)
{
delete pFlashItem;
m_FlashItems.RemoveAt(i);
return;
}
}
}
void CGfxOutBarCtrl::GetSelItem(int &nFolder, int &nItem)
{
if (iLastSel >= 0)
{
nFolder = iSelFolder;
nItem = iLastSel;
}
else
{
nFolder = -1;
nItem = -1;
}
}
void CGfxOutBarCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (GetFocus() != this) SetFocus();
int index, ht = HitTestEx(point, index);
if (ht == htItem)
{
m_pClientSocket->OpenChatDlg(GetItemText(index));
}
// delete m_pClientSocket;
CWnd::OnLButtonDblClk(nFlags, point);
}
void CGfxOutBarCtrl::OnGfxChangegroup()
{
DWORD nData = GetItemData(iHitInternal2);
int nImage = GetItemImage(iHitInternal2);
CString strTitle = GetItemText(iHitInternal2);
RemoveItem(iHitInternal2);
this->InsertItem(2,0,strTitle,nImage,nData);
}
void CGfxOutBarCtrl::OnGfxChangefriend()
{
DWORD nData = GetItemData(iHitInternal2);
int nImage = GetItemImage(iHitInternal2);
CString strTitle = GetItemText(iHitInternal2);
RemoveItem(iHitInternal2);
this->InsertItem(0,0,strTitle,nImage,nData);
}
int CGfxOutBarCtrl::GetItemIndex(CString strText)
{
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
for(int i=0;pbf->GetItemCount();i++)
{
CString strName = GetItemText(i);
if(strName == strText)
{
return i;
break;
}
}
return -1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -