📄 jnoutbar.cpp
字号:
}
void JnOutBar::OnGfxSmallicon()
{
SetSmallIconView(true);
Invalidate();
}
void JnOutBar::OnUpdateGfxSmallicon(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!IsSmallIconView());
}
void JnOutBar::OnGfxRemoveitem()
{
if (iHitInternal1 == htFolder)
{
RemoveFolder(iHitInternal2);
}
else if (iHitInternal1 == htItem)
{
RemoveItem(iHitInternal2);
}
}
void JnOutBar::OnUpdateGfxRemoveitem(CCmdUI* pCmdUI)
{
}
void JnOutBar::OnGfxRenameitem()
{
if (iHitInternal1 == htFolder)
{
StartGroupEdit(iHitInternal2);
}
else if (iHitInternal1 == htItem)
{
StartItemEdit(iHitInternal2);
}
}
void JnOutBar::OnUpdateGfxRenameitem(CCmdUI* pCmdUI)
{
}
void JnOutBar::RemoveItem(const int index)
{
if(GetFolderCount()<1)
return;
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);
CRect rc;
GetInsideRect(rc);
InvalidateRect(rc);
}
}
bool JnOutBar::IsValidItem(const int index) const
{
if(GetFolderCount()<1)
return false;
ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
return (index >= 0 && index < pbf->GetItemCount());
}
DWORD JnOutBar::GetItemData(const int index) const
{
if(GetFolderCount()<1)
return 0;
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 JnOutBar::GetItemImage(const int index) const
{
if(GetFolderCount()<1)
return 0;
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 JnOutBar::SetItemData(const int index, const DWORD dwData)
{
if(GetFolderCount()<1)
return;
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 JnOutBar::SetItemImage(const int index, const int iImage)
{
if(GetFolderCount()<1)
return;
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 JnOutBar::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 JnOutBar::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 JnOutBar::AnimateFolderScroll(const int iFrom, const int iTo)
{
if(GetFolderCount()<1)
return;
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 JnOutBar::GetItemText(const int index)
{
CString item;
if(GetFolderCount()<1)
return "";
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 JnOutBar::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 * JnOutBar::GetFolderChild(int iFolder)
{
if (GetFolderCount())
{
if (iFolder < 0) iFolder = iSelFolder;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
return pbf->pChild;
}
return NULL;
}
DWORD JnOutBar::GetFolderData(int iFolder)
{
if(iFolder<0 || iFolder>=GetFolderCount())
return 0;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
return pbf->dwData;
}
void JnOutBar::SetAnimSelHighlight(const int iTime)
{
if (iTime <= 0) KillTimer(3);
else SetTimer(3, iTime, NULL);
iSelAnimTiming = iTime;
}
int JnOutBar::GetItemCount(int nFolder)
{
ASSERT(nFolder >= 0 && nFolder < GetFolderCount());
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
return pbf->GetItemCount();
}
void JnOutBar::RemoveItem(int nFolder, int nIndex)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
if (IsValidItem(nIndex))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(nIndex);
delete i;
pbf->arItems.RemoveAt(nIndex);
CRect rc;
GetInsideRect(rc);
InvalidateRect(rc);
}
}
void JnOutBar::SetItemText(int nFolder, int nIndex, const char * text)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
CBarItem * pi = (CBarItem *) pbf->arItems.GetAt(nIndex);
if (pi->cItem)
{
delete [] pi->cItem;
pi->cItem = NULL;
}
pi->cItem = new char [lstrlen(text)+1];
lstrcpy(pi->cItem, text);
}
BOOL JnOutBar::CheckItem(int nFolder, int nItem)
{
if(nFolder>=GetFolderCount() || nFolder<0)
{
return FALSE;
}
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
if(nItem<0 || nItem>=pbf->GetItemCount())
return FALSE;
return TRUE;
}
CString JnOutBar::GetItemText(int nFolder, int nIndex)
{
CString item;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
if (IsValidItem(nIndex))
{
CBarItem * pi = (CBarItem *) pbf->arItems.GetAt(nIndex);
if (pi->cItem) item = pi->cItem;
}
return item;
}
void JnOutBar::SetItemImage(int nFolder, int nIndex, int nImage)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
if (IsValidItem(nIndex))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(nIndex);
i->iImageIndex = nImage;
}
}
short JnOutBar::GetItemImage(int nFolder, int nIndex)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
if (IsValidItem(nIndex))
{
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(nIndex);
return i->iImageIndex;
}
return 0;
}
void JnOutBar::SetItemData(int nFolder, int nIndex, long exData)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
// if (IsValidItem(nIndex))
// {
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(nIndex);
i->dwData = exData;
// }
}
long JnOutBar::GetItemData(int nFolder, int nIndex)
{
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
// if (IsValidItem(nIndex))
// {
CBarItem * i = (CBarItem *) pbf->arItems.GetAt(nIndex);
return i->dwData;
// }
}
CString JnOutBar::GetFolderText(int nFolder)
{
if(nFolder<0 || nFolder>=GetFolderCount())
return _T("");
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
return pbf->cName;
}
void JnOutBar::SetFolderData(int nFolder, long exData)
{
if(nFolder<0 || nFolder>=GetFolderCount())
return;
CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(nFolder);
if(pbf)
pbf->dwData=exData;
}
void JnOutBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
if(GetFolderCount()<1)
return;
int index, ht = HitTestEx(point, index);
GetOwner()->PostMessage(WM_OUTBAR_NOTIFY, NM_OB_ITEMDBCLICK, index);
CWnd::OnLButtonDblClk(nFlags, point);
}
int JnOutBar::GetFolderPos(CString sFolderText)
{
int nRet=-1;
for(int i=0;i<GetFolderCount();i++)
{
if(GetFolderText(i)==sFolderText)
{
nRet=i;
break;
}
}
return nRet;
}
void JnOutBar::ResetContent()
{
// for(int i=GetFolderCount()-1;i>-1;i--)
// {
// RemoveFolder(i);
// }
for (int t = 0; t < arFolder.GetSize(); t++)
{
if (arFolder.GetAt(t))
delete (CBarFolder*)arFolder.GetAt(t);
}
arFolder.RemoveAll();
}
void JnOutBar::SetBkColor(COLORREF color)
{
crBackGroundColor=color;
Invalidate();
}
BOOL JnOutBar::FindItem(CString &sItem, int &nFolder, int &nItem)
{
nFolder=-1;
nItem=-1;
for(int i=0;i<GetFolderCount();i++)
{
for(int j=0;j<GetItemCount(i);j++)
{
if(GetItemText(i,j)==sItem)
{
nFolder=i;
nItem=j;
break;
}
}
}
if(nFolder>-1 && nItem>-1)
return TRUE;
else
return FALSE;
}
BOOL JnOutBar::FindData(UINT& nData,int &nFolder,int & nItem)
{
nFolder=-1;
nItem=-1;
for(int i=0;i<GetFolderCount();i++)
{
for(int j=0;j<GetItemCount(i);j++)
{
if(GetItemData(i,j)==nData)
{
nFolder=i;
nItem=j;
break;
}
}
}
if(nFolder>-1 && nItem>-1)
return TRUE;
else
return FALSE;
}
int JnOutBar::FindFolder(CString &sFolder)
{
int nFolder=-1;
for(int i=0;i<GetFolderCount();i++)
{
if(GetFolderText(i)==sFolder)
{
nFolder=i;
break;
}
}
return nFolder;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -