📄 mailboxview.cpp
字号:
{
GetListSettings();
}
ModifyStyle( LVS_TYPEMASK, LVS_SMALLICON );
theApp.intMVMode = LVS_SMALLICON;
}
void CMailboxView::OnUpdateViewIcon(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio( LVS_ICON == theApp.intMVMode );
}
void CMailboxView::OnUpdateViewList(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio( LVS_LIST == theApp.intMVMode );
}
void CMailboxView::OnUpdateViewReport(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio( LVS_REPORT == theApp.intMVMode );
}
void CMailboxView::OnUpdateViewSmallicon(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio( LVS_SMALLICON == theApp.intMVMode );
}
void CMailboxView::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if( theApp.intMVSortColumn == pNMListView->iSubItem )
{
theApp.intMVSortAscend = !theApp.intMVSortAscend;
}
theApp.intMVSortColumn = pNMListView->iSubItem;
SortItems();
m_ColSortGUI.SetSortMark(GetListCtrl(), theApp.intMVSortColumn, theApp.intMVSortAscend);
*pResult = 0;
}
int CALLBACK CMailboxView::CompareSubItems(LPARAM lp0, LPARAM lp1, LPARAM )
{
ASSERT( lp0 && lp1 );
CMailbox &mbox0 = *(CMailbox*) lp0;
CMailbox &mbox1 = *(CMailbox*) lp1;
int intRes = -1;
switch( theApp.intMVSortColumn )
{
case COLUMN_ALIAS:
intRes = mbox0.m_strAlias.CompareNoCase( mbox1.m_strAlias );
break;
case COLUMN_USER:
intRes = mbox0.m_strUser.CompareNoCase( mbox1.m_strUser );
break;
case COLUMN_HOST:
intRes = mbox0.m_strHost.CompareNoCase( mbox1.m_strHost );
break;
case COLUMN_MAIL:
if( mbox0.m_arrayExcerpt.GetSize() == mbox1.m_arrayExcerpt.GetSize() ) intRes = 0;
else if( mbox0.m_arrayExcerpt.GetSize() < mbox1.m_arrayExcerpt.GetSize() ) intRes = -1;
else intRes = 1;
break;
case COLUMN_STATE:
if( mbox0.m_intState == mbox1.m_intState ) intRes = 0;
else if( mbox0.m_intState < mbox1.m_intState ) intRes = -1;
else intRes = 1;
break;
case COLUMN_ELAPSED:
if( mbox0.m_intElapsed == mbox1.m_intElapsed ) intRes = 0;
else if( mbox0.m_intElapsed < mbox1.m_intElapsed ) intRes = -1;
else intRes = 1;
break;
case COLUMN_PORT:
if( mbox0.m_intPort == mbox1.m_intPort ) intRes = 0;
else if( mbox0.m_intPort < mbox1.m_intPort ) intRes = -1;
else intRes = 1;
break;
case COLUMN_POLL:
if( mbox0.m_intPoll == mbox1.m_intPoll ) intRes = 0;
else if( mbox0.m_intPoll < mbox1.m_intPoll ) intRes = -1;
else intRes = 1;
break;
}
return theApp.intMVSortAscend ? intRes : -intRes;
}
void CMailboxView::OnRclick(NMHDR* , LRESULT* )
{
POINT pt = {0};
VERIFY( GetCursorPos( &pt ) );
ShowContextMenu( pt );
}
void CMailboxView::OnDblclk(NMHDR* , LRESULT* pResult)
{
SendMessage( WM_COMMAND, ID_COMMAND );
*pResult = 0;
}
void CMailboxView::OnEditSelectAll()
{
CListCtrl &list = GetListCtrl();
for( int i = list.GetItemCount(); i; --i ) list.SetItemState( i-1, LVIS_SELECTED, LVIS_SELECTED );
}
void CMailboxView::OnUpdateEditSelectAll(CCmdUI* pCmdUI)
{
pCmdUI->Enable( GetListCtrl().GetItemCount() );
}
void CMailboxView::OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult )
{
ASSERT( GetDocument() );
NM_LISTVIEW *pnmv = (NM_LISTVIEW*) pNMHDR;
if( ( pnmv->uOldState ^ pnmv->uNewState ) & LVIS_SELECTED )
{
CListCtrl &list = GetListCtrl();
switch( list.GetSelectedCount() )
{
case 0:
{
for( int i = list.GetItemCount(); i; --i )
{
CMailbox &mbox = *(CMailbox*) list.GetItemData( i-1 );
mbox.m_bitSelected = 1;
mbox.Change( COLUMN_SELECTED );
}
}
break;
case 1:
{
for( int i = list.GetItemCount(); i; --i )
{
CMailbox &mbox = *(CMailbox*) list.GetItemData( i-1 );
mbox.m_bitSelected = 0;
mbox.Change( COLUMN_SELECTED );
}
}
default:
{
CMailbox &mbox = *(CMailbox*) GetListCtrl().GetItemData( pnmv->iItem );
mbox.m_bitSelected = !!( LVIS_SELECTED & pnmv->uNewState );
mbox.Change( COLUMN_SELECTED );
}
}
}
*pResult = 0;
}
void CMailboxView::OnViewRefresh()
{
CMagicDoc *doc = (CMagicDoc*) GetDocument();
if( doc ) doc->Check();
}
void CMailboxView::OnEditDelete()
{
if ( IDYES != AfxMessageBox( IDS_MBOX_DELETE_CNF, MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 ) )
return;
CListCtrl &list = GetListCtrl();
for( int i = list.GetItemCount(); i; --i )
{
if( LVNI_SELECTED == list.GetItemState( i-1, LVNI_SELECTED ) )
{
GetDocument()->DeleteMailbox( (CMailbox*) list.GetItemData( i-1 ) );
}
}
}
void CMailboxView::OnEditProperties()
{
CTypedPtrArray < CPtrArray, CMailbox* > arrayMailbox;
CListCtrl &list = GetListCtrl();
int i = -1;
while( -1 != ( i = list.GetNextItem( i, LVNI_SELECTED ) ) )
{
arrayMailbox.Add( (CMailbox*) list.GetItemData(i) );
}
GetDocument()->MailboxProperties( arrayMailbox );
}
void CMailboxView::OnEditNew()
{
GetDocument()->NewMailbox();
}
void CMailboxView::OnCommand()
{
CListCtrl &list = GetListCtrl();
for( int i = list.GetItemCount(); i; --i )
{
if( list.GetItemState( i-1, LVIS_FOCUSED ) )
{
theApp.m_pMainWnd->SendMessage( VM_START_COMMAND, 0, LPARAM( list.GetItemData( i-1 ) ) );
break;
}
}
}
void CMailboxView::OnUpdateIfSelectedCount(CCmdUI* pCmdUI)
{
pCmdUI->Enable( GetListCtrl().GetSelectedCount() );
}
void CMailboxView::OnUpdateIfItemCount(CCmdUI* pCmdUI)
{
pCmdUI->Enable( GetListCtrl().GetItemCount() );
}
void CMailboxView::OnUpdateIfFocusedCount(CCmdUI* pCmdUI)
{
CListCtrl &list = GetListCtrl();
for( int i = list.GetItemCount(); i; --i )
{
if( list.GetItemState( i-1, LVIS_FOCUSED ) )
{
pCmdUI->Enable( TRUE );
return;
}
}
pCmdUI->Enable( FALSE );
}
void CMailboxView::OnUpdateIndicatorObjects( CCmdUI *pCmdUI )
{
CListCtrl &list = GetListCtrl();
pCmdUI->Enable();
UINT uintSelected = list.GetSelectedCount();
UINT uintTotal = list.GetItemCount();
UINT uintReported = uintSelected ? uintSelected : uintTotal;
CString strTmp1, strTmp2;
strTmp1.LoadString( uintReported-1 ? IDP_MAILBOXES : IDP_MAILBOX );
StrTranslate(strTmp1);
if( uintSelected ) strTmp2.LoadString( IDP_SELECTED );
StrTranslate(strTmp2);
CString strObjects;
strObjects.Format( _T("%d %s %s"), uintReported, strTmp1, strTmp2);
pCmdUI->SetText( strObjects );
}
void CMailboxView::OnUpdateIndicatorContents( CCmdUI *pCmdUI )
{
CListCtrl &list = GetListCtrl();
pCmdUI->Enable();
UINT uintCount = 0;
UINT uSize = 0;
BOOL bNoneSelected = !list.GetSelectedCount();
for( int i = list.GetItemCount(); i; --i )
{
if( bNoneSelected || list.GetItemState( i-1, LVIS_SELECTED ) )
{
CMailbox* pM = (CMailbox*) list.GetItemData( i-1 );
if (!pM)
continue;
uintCount += pM->m_arrayExcerpt.GetSize();
for (int e=0; e<pM->m_arrayExcerpt.GetSize(); e++)
{
if (pM->m_arrayExcerpt[e])
uSize += pM->m_arrayExcerpt[e]->m_intSize;
}
}
}
CString strContents, strTmp;
strTmp.LoadString( uintCount-1 ? IDP_MESSAGES : IDP_MESSAGE );
StrTranslate(strTmp);
CString strSize;
BytesToString( uSize, strSize);
strContents.Format( _T("%d %s - %s"), uintCount, strTmp, strSize );
pCmdUI->SetText( strContents );
}
void CMailboxView::OnStopChecking()
{
CMagicDoc *doc = (CMagicDoc*) GetDocument();
if( doc ) doc->StopChecking();
}
void CMailboxView::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
if( pLVKeyDown->wVKey == VK_APPS )
{
CListCtrl &list = GetListCtrl();
int iFocusedItem = list.GetNextItem( -1, LVNI_FOCUSED );
POINT pt = {0};
if( iFocusedItem != -1 )
{
RECT rc = {0};
list.GetItemRect( iFocusedItem, &rc, LVIR_BOUNDS );
pt.x = rc.left;
pt.y = rc.bottom;
}
ClientToScreen( &pt );
ShowContextMenu( pt );
}
else if( pLVKeyDown->wVKey == VK_TAB )
{
CMagicFrame *frame = (CMagicFrame*) GetParentFrame();
if( frame )
{
frame->SwitchPane();
}
}
}
void CMailboxView::ShowContextMenu( const POINT& pt )
{
CMenu menuPopup;
VERIFY( menuPopup.LoadMenu( IDR_MAILBOX_POPUP_MENU ) );
MENUITEMINFO info;
info.cbSize = sizeof( info );
info.fMask = MIIM_STATE;
info.fState = MFS_DEFAULT;
VERIFY( SetMenuItemInfo( menuPopup.m_hMenu, ID_COMMAND, FALSE, &info ) );
MenuTranslate(menuPopup.GetSubMenu(0)->m_hMenu);
menuPopup.GetSubMenu(0)->TrackPopupMenu
(
TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
pt.x, pt.y, AfxGetMainWnd(), NULL
);
}
LRESULT CMailboxView::OnLanguage(WPARAM, LPARAM)
{
CString strColumn;
int nCols = sizeof(anMBCols)/sizeof(anMBCols[0]);
for (int i=0; i<nCols; i++)
{
LOAD_STRING(strColumn, anMBCols[i]);
SetColTitle(i, strColumn);
}
return 0;
}
void CMailboxView::OnFilters()
{
DFilters dlg((CMagicDoc*)GetDocument());
dlg.DoModal();
}
void CMailboxView::OnHeaderEndDrag(LPNMHEADER /*pHeader*/, LRESULT* pResult)
{
RedrawWindow(NULL, NULL, RDW_INTERNALPAINT | RDW_INVALIDATE);
*pResult = 0;
}
void CMailboxView::GetListSettings(void)
{
CListCtrl &list = GetListCtrl();
LVCOLUMN lvc;
lvc.mask=LVCF_WIDTH | LVCF_ORDER;
list.GetColumn(COLUMN_ALIAS, &lvc);
theApp.intMCAliasWidth = lvc.cx;
theApp.intMCAliasPos = lvc.iOrder;
list.GetColumn(COLUMN_USER, &lvc);
theApp.intMCUserWidth = lvc.cx;
theApp.intMCUserPos = lvc.iOrder;
list.GetColumn(COLUMN_HOST, &lvc);
theApp.intMCHostWidth = lvc.cx;
theApp.intMCHostPos = lvc.iOrder;
list.GetColumn(COLUMN_MAIL, &lvc);
theApp.intMCMailWidth = lvc.cx;
theApp.intMCMailPos = lvc.iOrder;
list.GetColumn(COLUMN_STATE, &lvc);
theApp.intMCStatWidth = lvc.cx;
theApp.intMCStatPos = lvc.iOrder;
list.GetColumn(COLUMN_ELAPSED, &lvc);
theApp.intMCElapsedWidth = lvc.cx;
theApp.intMCElapsedPos = lvc.iOrder;
list.GetColumn(COLUMN_PORT, &lvc);
theApp.intMCPortWidth = lvc.cx;
theApp.intMCPortPos = lvc.iOrder;
list.GetColumn(COLUMN_POLL, &lvc);
theApp.intMCPollWidth = lvc.cx;
theApp.intMCPollPos = lvc.iOrder;
}
void CMailboxView::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (!lpDrawItemStruct)
return;
int nItem = lpDrawItemStruct->itemID;
CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
CMailbox &mbox = *(CMailbox*) GetListCtrl().GetItemData( nItem );
int nNew = (mbox.m_nUnread > 0);
// select bold font for unread messages
if (!m_fntBold.m_hObject)
{
CFont* pF = GetFont();
if (pF)
{
pF->GetObject(sizeof(LOGFONT), &m_lfBold);
m_lfBold.lfWeight = 800;
m_fntBold.CreateFontIndirect(&m_lfBold);
}
}
CFont* pOldF = NULL;
if (m_fntBold.m_hObject && nNew)
{
pOldF = pDC->SelectObject(&m_fntBold);
}
CListViewEx::DrawItem(lpDrawItemStruct);
if (pOldF)
pDC->SelectObject(pOldF);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -