📄 ctrlmatchtip.cpp
字号:
m_sName = m_pHit->m_sName;
m_sSize = Settings.SmartVolume( m_pHit->m_nSize, FALSE );
LoadTypeInfo();
if ( m_pHit->m_bSHA1 )
{
m_sSHA1 = _T("sha1:") + CSHA::HashToString( &m_pHit->m_pSHA1 );
}
else
{
m_sSHA1.Empty();
}
if ( m_pHit->m_bTiger )
{
m_sTiger = _T("tree:tiger/:") + CTigerNode::HashToString( &m_pHit->m_pTiger );
}
else
{
m_sTiger.Empty();
}
if ( m_pHit->m_bED2K )
{
m_sED2K = _T("ed2k:") + CED2K::HashToString( &m_pHit->m_pED2K );
}
else
{
m_sED2K.Empty();
}
if ( m_pHit->m_nPartial )
{
CString strFormat;
LoadString( strFormat, IDS_TIP_PARTIAL );
m_sPartial.Format( strFormat, 100.0f * (float)m_pHit->m_nPartial / (float)m_pHit->m_nSize );
}
else
{
m_sPartial.Empty();
}
if ( m_pHit->m_nUpSlots )
{
CString strFormat;
LoadString( strFormat, IDS_TIP_QUEUE );
m_sQueue.Format( strFormat, m_pHit->m_nUpSlots,
max( 0, m_pHit->m_nUpQueue - m_pHit->m_nUpSlots ) );
}
else
{
m_sQueue.Empty();
}
m_pSchema = SchemaCache.Get( m_pHit->m_sSchemaURI );
m_pMetadata.Setup( m_pSchema );
if ( m_pSchema != NULL )
{
if ( m_pHit->m_pXML && m_pSchema->CheckURI( m_pHit->m_sSchemaURI ) )
{
m_pMetadata.Combine( m_pHit->m_pXML );
}
m_pMetadata.Clean( 72 );
}
m_nRating = m_pHit->m_nRating;
m_sStatus.Empty();
if ( m_pFile->m_bExisting )
{
LoadString( m_sStatus, IDS_TIP_EXISTS_LIBRARY );
m_crStatus = RGB( 0, 128, 0 );
}
else if ( m_pFile->m_bDownload || m_pHit->m_bDownload )
{
LoadString( m_sStatus, IDS_TIP_EXISTS_DOWNLOAD );
m_crStatus = RGB( 0, 128, 0 );
}
else if ( m_pHit->m_bBogus )
{
LoadString( m_sStatus, IDS_TIP_BOGUS );
m_crStatus = RGB( 255, 0, 0 );
}
if ( m_pHit->m_sNick.GetLength() )
{
m_sUser.Format( _T("%s (%s - %s)"),
(LPCTSTR)m_pHit->m_sNick,
(LPCTSTR)CString( inet_ntoa( m_pHit->m_pAddress ) ),
(LPCTSTR)m_pHit->m_pVendor->m_sName );
}
else
{
m_sUser.Format( _T("%s - %s"),
(LPCTSTR)CString( inet_ntoa( m_pHit->m_pAddress ) ),
(LPCTSTR)m_pHit->m_pVendor->m_sName );
}
}
BOOL CMatchTipCtrl::LoadTypeInfo()
{
int nPeriod = m_sName.ReverseFind( '.' );
m_sType.Empty();
m_nIcon = 0;
if ( nPeriod > 0 )
{
CString strType = m_sName.Mid( nPeriod );
CString strName, strMime;
ShellIcons.Lookup( strType, NULL, NULL, &strName, &strMime );
m_nIcon = ShellIcons.Get( strType, 32 );
if ( strName.GetLength() )
{
m_sType = strName;
if ( strMime.GetLength() ) m_sType += _T(" (") + strMime + _T(")");
}
else
{
m_sType = strType.Mid( 1 );
}
}
if ( m_sType.IsEmpty() ) m_sType = _T("Unknown");
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// CMatchTipCtrl layout
CSize CMatchTipCtrl::ComputeSize()
{
CClientDC dc( this );
CSize sz( 0, 0 );
CFont* pOldFont = (CFont*)dc.SelectObject( &CoolInterface.m_fntBold );
ExpandSize( dc, sz, m_sName );
sz.cy += TIP_TEXTHEIGHT;
dc.SelectObject( &CoolInterface.m_fntNormal );
if ( m_sUser.GetLength() )
{
ExpandSize( dc, sz, m_sUser );
sz.cy += TIP_TEXTHEIGHT;
}
sz.cy += 5 + 6;
if ( m_sStatus.GetLength() )
{
dc.SelectObject( &CoolInterface.m_fntBold );
ExpandSize( dc, sz, m_sStatus );
dc.SelectObject( &CoolInterface.m_fntNormal );
sz.cy += TIP_TEXTHEIGHT;
sz.cy += 5 + 6;
}
sz.cy += 32;
ExpandSize( dc, sz, m_sSize, 80 );
ExpandSize( dc, sz, m_sType, 80 );
if ( m_sSHA1.GetLength() || m_sTiger.GetLength() || m_sED2K.GetLength() )
{
sz.cy += 5 + 6;
if ( m_sSHA1.GetLength() )
{
ExpandSize( dc, sz, m_sSHA1 );
sz.cy += TIP_TEXTHEIGHT;
}
if ( m_sTiger.GetLength() )
{
ExpandSize( dc, sz, m_sTiger );
sz.cy += TIP_TEXTHEIGHT;
}
if ( m_sED2K.GetLength() )
{
ExpandSize( dc, sz, m_sED2K );
sz.cy += TIP_TEXTHEIGHT;
}
}
if ( m_sPartial.GetLength() || m_sQueue.GetLength() )
{
sz.cy += 5 + 6;
if ( m_sPartial.GetLength() )
{
ExpandSize( dc, sz, m_sPartial );
sz.cy += TIP_TEXTHEIGHT;
}
if ( m_sQueue.GetLength() )
{
ExpandSize( dc, sz, m_sQueue );
sz.cy += TIP_TEXTHEIGHT;
}
}
if ( m_pMetadata.GetCount() )
{
sz.cy += 5 + 6;
int nValueWidth = 0;
m_nKeyWidth = 0;
m_pMetadata.ComputeWidth( &dc, m_nKeyWidth, nValueWidth );
if ( m_nKeyWidth ) m_nKeyWidth += TIP_MARGIN;
sz.cx = max( sz.cx, m_nKeyWidth + nValueWidth );
sz.cy += TIP_TEXTHEIGHT * m_pMetadata.GetCount();
}
dc.SelectObject( pOldFont );
sz.cx += TIP_MARGIN * 2;
sz.cy += TIP_MARGIN * 2;
return sz;
}
void CMatchTipCtrl::ExpandSize(CDC& dc, CSize& sz, LPCTSTR pszText, int nBase)
{
CSize szText = dc.GetTextExtent( pszText, _tcslen( pszText ) );
szText.cx += nBase;
sz.cx = max( sz.cx, szText.cx );
}
/////////////////////////////////////////////////////////////////////////////
// CMatchTipCtrl painting
BOOL CMatchTipCtrl::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CMatchTipCtrl::OnPaint()
{
CPaintDC dc( this );
CString str;
CRect rc;
GetClientRect( &rc );
dc.Draw3dRect( &rc, m_crBorder, m_crBorder );
rc.DeflateRect( 1, 1 );
CFont* pOldFont = (CFont*)dc.SelectObject( &CoolInterface.m_fntBold );
CPoint pt( TIP_MARGIN, TIP_MARGIN );
dc.SetTextColor( m_crText );
DrawText( dc, pt, m_sName );
pt.y += TIP_TEXTHEIGHT;
dc.SelectObject( &CoolInterface.m_fntNormal );
if ( m_sUser.GetLength() )
{
DrawText( dc, pt, m_sUser );
pt.y += TIP_TEXTHEIGHT;
}
pt.y += 5;
dc.Draw3dRect( rc.left + 2, pt.y, rc.Width() - 4, 1,
m_crBorder, m_crBorder );
dc.ExcludeClipRect( rc.left + 2, pt.y, rc.right - 2, pt.y + 1 );
pt.y += 6;
if ( m_sStatus.GetLength() )
{
dc.SetTextColor( m_crStatus );
dc.SelectObject( &CoolInterface.m_fntBold );
DrawText( dc, pt, m_sStatus );
dc.SelectObject( &CoolInterface.m_fntNormal );
dc.SetTextColor( m_crText );
pt.y += TIP_TEXTHEIGHT;
pt.y += 5;
dc.Draw3dRect( rc.left + 2, pt.y, rc.Width() - 4, 1,
m_crBorder, m_crBorder );
dc.ExcludeClipRect( rc.left + 2, pt.y, rc.right - 2, pt.y + 1 );
pt.y += 6;
}
ShellIcons.Draw( &dc, m_nIcon, 32, pt.x, pt.y, m_crBack );
if ( m_nRating > 1 )
{
CPoint ptStar( rc.right - 3, pt.y - 2 );
for ( int nRating = m_nRating - 1 ; nRating ; nRating-- )
{
ptStar.x -= 16;
ShellIcons.Draw( &dc, SHI_STAR, 16, ptStar.x, ptStar.y, m_crBack );
}
}
pt.x += 40;
LoadString( str, IDS_TIP_SIZE );
DrawText( dc, pt, str + ':' );
pt.x += 40;
DrawText( dc, pt, m_sSize );
pt.x -= 40;
pt.y += 16;
LoadString( str, IDS_TIP_TYPE );
DrawText( dc, pt, str + ':' );
pt.x += 40;
DrawText( dc, pt, m_sType );
pt.x -= 40;
pt.x -= 40;
pt.y += 16;
if ( m_sSHA1.GetLength() || m_sTiger.GetLength() || m_sED2K.GetLength() )
{
pt.y += 5;
dc.Draw3dRect( rc.left + 2, pt.y, rc.Width() - 4, 1,
m_crBorder, m_crBorder );
dc.ExcludeClipRect( rc.left + 2, pt.y, rc.right - 2, pt.y + 1 );
pt.y += 6;
if ( m_sSHA1.GetLength() )
{
DrawText( dc, pt, m_sSHA1 );
pt.y += TIP_TEXTHEIGHT;
}
if ( m_sTiger.GetLength() )
{
DrawText( dc, pt, m_sTiger );
pt.y += TIP_TEXTHEIGHT;
}
if ( m_sED2K.GetLength() )
{
DrawText( dc, pt, m_sED2K );
pt.y += TIP_TEXTHEIGHT;
}
}
if ( m_sPartial.GetLength() || m_sQueue.GetLength() )
{
pt.y += 5;
dc.Draw3dRect( rc.left + 2, pt.y, rc.Width() - 4, 1,
m_crBorder, m_crBorder );
dc.ExcludeClipRect( rc.left + 2, pt.y, rc.right - 2, pt.y + 1 );
pt.y += 6;
if ( m_sPartial.GetLength() )
{
DrawText( dc, pt, m_sPartial );
pt.y += TIP_TEXTHEIGHT;
}
if ( m_sQueue.GetLength() )
{
DrawText( dc, pt, m_sQueue );
pt.y += TIP_TEXTHEIGHT;
}
}
if ( m_pMetadata.GetCount() )
{
pt.y += 5;
dc.Draw3dRect( rc.left + 2, pt.y, rc.Width() - 4, 1,
m_crBorder, m_crBorder );
dc.ExcludeClipRect( rc.left + 2, pt.y, rc.right - 2, pt.y + 1 );
pt.y += 6;
for ( POSITION pos = m_pMetadata.GetIterator() ; pos ; )
{
CMetaItem* pItem = m_pMetadata.GetNext( pos );
DrawText( dc, pt, pItem->m_sKey + ':' );
pt.x += m_nKeyWidth;
DrawText( dc, pt, pItem->m_sValue );
pt.x -= m_nKeyWidth;
pt.y += TIP_TEXTHEIGHT;
}
}
dc.SelectObject( pOldFont );
dc.FillSolidRect( &rc, m_crBack );
}
void CMatchTipCtrl::DrawText(CDC& dc, CPoint& pt, LPCTSTR pszText)
{
CSize sz = dc.GetTextExtent( pszText, _tcslen( pszText ) );
CRect rc( pt.x, pt.y, pt.x + sz.cx, pt.y + sz.cy );
dc.SetBkColor( m_crBack );
dc.ExtTextOut( pt.x, pt.y, ETO_CLIPPED|ETO_OPAQUE, &rc, pszText, _tcslen( pszText ), NULL );
dc.ExcludeClipRect( &rc );
}
void CMatchTipCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
Hide();
}
void CMatchTipCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
Hide();
CWnd::OnKeyDown( nChar, nRepCnt, nFlags );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -