📄 ctrllibrarytileview.cpp
字号:
CLibraryTileItem** pList = m_pList;
for ( int nItem = m_nCount ; nItem && pt.y < rcClient.bottom ; nItem--, pList++ )
{
CLibraryTileItem* pTile = *pList;
CRect rcBlock( pt.x, pt.y, pt.x + m_szBlock.cx, pt.y + m_szBlock.cy );
if ( rcBlock.bottom >= rcClient.top && dc.RectVisible( &rcBlock ) )
{
pBuffer->FillSolidRect( &rcBuffer, CoolInterface.m_crWindow );
pTile->Paint( pBuffer, rcBuffer, &dcMem );
dc.BitBlt( rcBlock.left, rcBlock.top, m_szBlock.cx, m_szBlock.cy,
pBuffer, 0, 0, SRCCOPY );
dc.ExcludeClipRect( &rcBlock );
}
pt.x += m_szBlock.cx;
if ( pt.x + m_szBlock.cx > rcClient.right )
{
pt.x = rcClient.left;
pt.y += m_szBlock.cy;
}
}
pBuffer->SelectObject( pOldFont );
dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
}
CLibraryTileItem* CLibraryTileView::HitTest(const CPoint& point) const
{
CRect rcClient;
GetClientRect( &rcClient );
CPoint pt( rcClient.left, rcClient.top - m_nScroll );
CLibraryTileItem** pList = m_pList;
for ( int nItem = m_nCount ; nItem && pt.y < rcClient.bottom ; nItem--, pList++ )
{
CLibraryTileItem* pTile = *pList;
CRect rcBlock( pt.x, pt.y, pt.x + m_szBlock.cx, pt.y + m_szBlock.cy );
if ( rcBlock.PtInRect( point ) ) return pTile;
pt.x += m_szBlock.cx;
if ( pt.x + m_szBlock.cx > rcClient.right )
{
pt.x = rcClient.left;
pt.y += m_szBlock.cy;
}
}
return NULL;
}
BOOL CLibraryTileView::GetItemRect(CLibraryTileItem* pTile, CRect* pRect)
{
CRect rcClient;
GetClientRect( &rcClient );
CPoint pt( rcClient.left, rcClient.top - m_nScroll );
CLibraryTileItem** pList = m_pList;
for ( int nItem = m_nCount ; nItem ; nItem--, pList++ )
{
CRect rcBlock( pt.x, pt.y, pt.x + m_szBlock.cx, pt.y + m_szBlock.cy );
if ( pTile == *pList )
{
*pRect = rcBlock;
return TRUE;
}
pt.x += m_szBlock.cx;
if ( pt.x + m_szBlock.cx > rcClient.right )
{
pt.x = rcClient.left;
pt.y += m_szBlock.cy;
}
}
return FALSE;
}
void CLibraryTileView::OnLButtonDown(UINT nFlags, CPoint point)
{
CLibraryTileItem* pHit = HitTest( point );
if ( SelectTo( pHit ) ) Invalidate();
SetFocus();
SetCapture();
if ( pHit && ( nFlags & MK_RBUTTON ) == 0 && Settings.Library.ShowVirtual )
{
m_bDrag = TRUE;
m_ptDrag = point;
}
CLibraryView::OnLButtonDown( nFlags, point );
}
void CLibraryTileView::OnMouseMove(UINT nFlags, CPoint point)
{
if ( m_bDrag & ( nFlags & MK_LBUTTON ) )
{
CSize szDiff = point - m_ptDrag;
if ( abs( szDiff.cx ) > 5 || abs( szDiff.cy ) > 5 )
{
m_bDrag = FALSE;
StartDragging( point );
}
}
CLibraryView::OnMouseMove( nFlags, point );
}
void CLibraryTileView::OnLButtonUp(UINT nFlags, CPoint point)
{
ReleaseCapture();
m_bDrag = FALSE;
if ( ( nFlags & (MK_SHIFT|MK_CONTROL) ) == 0 && m_pFocus && m_pFocus->m_bSelected )
{
if ( DeselectAll( m_pFocus ) ) Invalidate();
}
}
void CLibraryTileView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
SendMessage( WM_COMMAND, ID_LIBRARY_ALBUM_OPEN );
}
void CLibraryTileView::OnRButtonDown(UINT nFlags, CPoint point)
{
OnLButtonDown( nFlags, point );
CLibraryView::OnRButtonDown( nFlags, point );
}
void CLibraryTileView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch ( nChar )
{
case VK_LEFT:
SelectTo( - 1 );
break;
case VK_RIGHT:
SelectTo( 1 );
break;
case VK_UP:
SelectTo( -m_nColumns );
break;
case VK_DOWN:
SelectTo( m_nColumns );
break;
case VK_PRIOR:
SelectTo( m_nRows * -m_nColumns );
break;
case VK_NEXT:
ScrollBy( m_nRows * m_nColumns );
break;
case VK_HOME:
SelectTo( -m_nCount );
break;
case VK_END:
SelectTo( m_nCount );
break;
case VK_RETURN:
PostMessage( WM_COMMAND, ID_LIBRARY_ALBUM_OPEN );
break;
}
CLibraryView::OnKeyDown( nChar, nRepCnt, nFlags );
}
void CLibraryTileView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ( _istalnum( nChar ) )
{
CLibraryTileItem* pStart = m_pFocus;
for ( int nLoop = 0 ; nLoop < 2 ; nLoop++ )
{
CLibraryTileItem** pChild = m_pList;
for ( int nCount = m_nCount ; nCount ; nCount--, pChild++ )
{
if ( pStart != NULL )
{
if ( pStart == *pChild ) pStart = NULL;
}
else if ( toupper( (*pChild)->m_sTitle.GetAt( 0 ) ) == toupper( (int)nChar ) )
{
DeselectAll( m_pFocus = *pChild );
Select( m_pFocus, TS_TRUE );
Highlight( m_pFocus );
Invalidate();
return;
}
}
}
}
CLibraryView::OnChar( nChar, nRepCnt, nFlags );
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryTileView drag setup
#define MAX_DRAG_SIZE 256
#define MAX_DRAG_SIZE_2 128
void CLibraryTileView::StartDragging(CPoint& ptMouse)
{
CImageList* pImage = CreateDragImage( ptMouse );
if ( ! pImage ) return;
ReleaseCapture();
ClientToScreen( &ptMouse );
DragObjects( pImage, ptMouse );
}
CImageList* CLibraryTileView::CreateDragImage(const CPoint& ptMouse)
{
CRect rcClient, rcOne, rcAll( 32000, 32000, -32000, -32000 );
GetClientRect( &rcClient );
for ( POSITION pos = m_pSelTile.GetHeadPosition() ; pos ; )
{
CLibraryTileItem* pTile = (CLibraryTileItem*)m_pSelTile.GetNext( pos );
GetItemRect( pTile, &rcOne );
if ( rcOne.IntersectRect( &rcClient, &rcOne ) )
{
rcAll.left = min( rcAll.left, rcOne.left );
rcAll.top = min( rcAll.top, rcOne.top );
rcAll.right = max( rcAll.right, rcOne.right );
rcAll.bottom = max( rcAll.bottom, rcOne.bottom );
}
}
BOOL bClipped = rcAll.Height() > MAX_DRAG_SIZE;
if ( bClipped )
{
rcAll.left = max( rcAll.left, ptMouse.x - MAX_DRAG_SIZE_2 );
rcAll.right = max( rcAll.right, ptMouse.x + MAX_DRAG_SIZE_2 );
rcAll.top = max( rcAll.top, ptMouse.y - MAX_DRAG_SIZE_2 );
rcAll.bottom = max( rcAll.bottom, ptMouse.y + MAX_DRAG_SIZE_2 );
}
CClientDC dcClient( this );
CDC dcMem, dcDrag;
CBitmap bmDrag;
if ( ! dcMem.CreateCompatibleDC( &dcClient ) )
return NULL;
if ( ! dcDrag.CreateCompatibleDC( &dcClient ) )
return NULL;
if ( ! bmDrag.CreateCompatibleBitmap( &dcClient, rcAll.Width(), rcAll.Height() ) )
return NULL;
CBitmap *pOldDrag = dcDrag.SelectObject( &bmDrag );
dcDrag.FillSolidRect( 0, 0, rcAll.Width(), rcAll.Height(), RGB( 250, 255, 250 ) );
CRgn pRgn;
if ( bClipped )
{
CPoint ptMiddle( ptMouse.x - rcAll.left, ptMouse.y - rcAll.top );
pRgn.CreateEllipticRgn( ptMiddle.x - MAX_DRAG_SIZE_2, ptMiddle.y - MAX_DRAG_SIZE_2,
ptMiddle.x + MAX_DRAG_SIZE_2, ptMiddle.y + MAX_DRAG_SIZE_2 );
dcDrag.SelectClipRgn( &pRgn );
}
CDC* pBuffer = CoolInterface.GetBuffer( dcClient, m_szBlock );
CRect rcBuffer( 0, 0, m_szBlock.cx, m_szBlock.cy );
CFont* pOldFont = (CFont*)pBuffer->SelectObject( &CoolInterface.m_fntNormal );
for ( pos = m_pSelTile.GetHeadPosition() ; pos ; )
{
CLibraryTileItem* pTile = (CLibraryTileItem*)m_pSelTile.GetNext( pos );
GetItemRect( pTile, &rcOne );
CRect rcDummy;
if ( rcDummy.IntersectRect( &rcAll, &rcOne ) )
{
pBuffer->FillSolidRect( &rcBuffer, RGB( 250, 255, 250 ) );
pTile->Paint( pBuffer, rcBuffer, &dcMem );
dcDrag.BitBlt( rcOne.left - rcAll.left, rcOne.top - rcAll.top,
m_szBlock.cx, m_szBlock.cy, pBuffer, 0, 0, SRCCOPY );
}
}
pBuffer->SelectObject( pOldFont );
dcDrag.SelectObject( pOldDrag );
dcDrag.DeleteDC();
CImageList* pAll = new CImageList();
pAll->Create( rcAll.Width(), rcAll.Height(), ILC_COLOR16|ILC_MASK, 1, 1 );
pAll->Add( &bmDrag, RGB( 250, 255, 250 ) );
bmDrag.DeleteObject();
pAll->BeginDrag( 0, ptMouse - rcAll.TopLeft() );
return pAll;
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryTileItem construction
CLibraryTileItem::CLibraryTileItem(CAlbumFolder* pFolder)
{
m_pFolder = pFolder;
m_nCookie = 0xFFFFFFFF;
m_bSelected = FALSE;
Update();
}
CLibraryTileItem::~CLibraryTileItem()
{
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryTileItem operations
BOOL CLibraryTileItem::Update()
{
if ( m_pFolder->m_nUpdateCookie == m_nCookie ) return FALSE;
m_nCookie = m_pFolder->m_nUpdateCookie;
m_sTitle = m_pFolder->m_sName;
m_nIcon32 = m_pFolder->m_pSchema ? m_pFolder->m_pSchema->m_nIcon32 : -1;
m_nIcon48 = m_pFolder->m_pSchema ? m_pFolder->m_pSchema->m_nIcon48 : -1;
m_bCollection = m_pFolder->m_bCollSHA1;
CSchema* pSchema = m_pFolder->m_pSchema;
if ( pSchema != NULL && m_pFolder->m_pXML != NULL )
{
m_sSubtitle1 = pSchema->m_sTileLine1;
m_sSubtitle2 = pSchema->m_sTileLine2;
pSchema->ResolveTokens( m_sSubtitle1, m_pFolder->m_pXML );
pSchema->ResolveTokens( m_sSubtitle2, m_pFolder->m_pXML );
}
else
{
m_sSubtitle1.Empty();
m_sSubtitle2.Empty();
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryTileItem paint
void CLibraryTileItem::Paint(CDC* pDC, const CRect& rcBlock, CDC* pMemDC)
{
CRect rc( &rcBlock );
UINT nStyle = 0;
if ( m_bSelected ) nStyle |= ILD_SELECTED;
if ( m_bCollection ) nStyle |= INDEXTOOVERLAYMASK(SHI_O_COLLECTION);
if ( m_nIcon48 >= 0 )
{
ImageList_DrawEx( ShellIcons.GetHandle( 48 ), m_nIcon48, *pDC,
rc.left + 5, rc.top + 4, 48, 48, CLR_NONE, CLR_DEFAULT, nStyle );
}
else if ( m_nIcon32 >= 0 )
{
ImageList_DrawEx( ShellIcons.GetHandle( 32 ), m_nIcon32, *pDC,
rc.left + 5 + 8, rc.top + 4 + 8, 32, 32, CLR_NONE, CLR_DEFAULT, nStyle );
}
rc.left += 48 + 5;
rc.DeflateRect( 10, 5 );
if ( m_bSelected )
{
pDC->SetBkColor( CoolInterface.m_crHighlight );
pDC->SetTextColor( CoolInterface.m_crHiText );
pDC->SetBkMode( OPAQUE );
}
else
{
pDC->SetBkColor( CoolInterface.m_crWindow );
pDC->SetTextColor( CoolInterface.m_crText );
pDC->SetBkMode( TRANSPARENT );
}
int nX = rc.left + 2;
int nY = ( rc.top + rc.bottom ) / 2;
int nH = pDC->GetTextExtent( _T("Xy") ).cy;
if ( m_sSubtitle1.GetLength() > 0 )
{
CRect rcUnion( nX, nY, nX, nY );
if ( m_sSubtitle2.GetLength() > 0 )
{
nY -= ( nH * 3 ) / 2;
if ( m_bCollection ) pDC->SelectObject( &CoolInterface.m_fntBold );
DrawText( pDC, &rc, nX, nY, m_sTitle, &rcUnion );
if ( m_bCollection ) pDC->SelectObject( &CoolInterface.m_fntNormal );
if ( ! m_bSelected ) pDC->SetTextColor( CoolInterface.m_crDisabled );
DrawText( pDC, &rc, nX, nY + nH, m_sSubtitle1, &rcUnion );
DrawText( pDC, &rc, nX, nY + nH + nH, m_sSubtitle2, &rcUnion );
}
else
{
if ( m_bCollection ) pDC->SelectObject( &CoolInterface.m_fntBold );
DrawText( pDC, &rc, nX, nY - nH, m_sTitle, &rcUnion );
if ( m_bCollection ) pDC->SelectObject( &CoolInterface.m_fntNormal );
if ( ! m_bSelected ) pDC->SetTextColor( CoolInterface.m_crDisabled );
DrawText( pDC, &rc, nX, nY, m_sSubtitle1, &rcUnion );
}
pDC->FillSolidRect( &rcUnion, pDC->GetBkColor() );
}
else
{
nY -= nH / 2;
if ( m_bCollection ) pDC->SelectObject( &CoolInterface.m_fntBold );
DrawText( pDC, &rc, nX, nY, m_sTitle );
if ( m_bCollection ) pDC->SelectObject( &CoolInterface.m_fntNormal );
}
pDC->SelectClipRgn( NULL );
}
void CLibraryTileItem::DrawText(CDC* pDC, const CRect* prcClip, int nX, int nY, LPCTSTR pszText, CRect* prcUnion)
{
CSize sz = pDC->GetTextExtent( pszText, _tcslen( pszText ) );
CRect rc( nX - 2, nY - 1, nX + sz.cx + 2, nY + sz.cy + 1 );
rc.IntersectRect( &rc, prcClip );
pDC->ExtTextOut( nX, nY, ETO_CLIPPED|ETO_OPAQUE, &rc, pszText, _tcslen( pszText ), NULL );
pDC->ExcludeClipRect( rc.left, rc.top, rc.right, rc.bottom );
if ( prcUnion != NULL ) prcUnion->UnionRect( prcUnion, &rc );
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryTileView command handlers
void CLibraryTileView::OnContextMenu(CWnd* pWnd, CPoint point)
{
Skin.TrackPopupMenu( m_pszToolBar, point, ID_LIBRARY_ALBUM_OPEN );
}
void CLibraryTileView::OnUpdateLibraryAlbumOpen(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_nSelected == 1 );
}
void CLibraryTileView::OnLibraryAlbumOpen()
{
if ( m_pSelTile.GetCount() == 0 ) return;
CLibraryTileItem* pItem = (CLibraryTileItem*)m_pSelTile.GetHead();
GetFrame()->Display( pItem->m_pFolder );
}
void CLibraryTileView::OnUpdateLibraryAlbumDelete(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_nSelected > 0 );
}
void CLibraryTileView::OnLibraryAlbumDelete()
{
if ( m_nSelected == 0 ) return;
CString strFormat, strMessage;
Skin.LoadString( strFormat, IDS_LIBRARY_FOLDER_DELETE );
strMessage.Format( strFormat, m_nSelected );
if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_OKCANCEL ) != IDOK ) return;
Library.Lock();
for ( POSITION pos = m_pSelTile.GetHeadPosition() ; pos ; )
{
CLibraryTileItem* pTile = (CLibraryTileItem*)m_pSelTile.GetNext( pos );
CAlbumFolder* pFolder = pTile->m_pFolder;
if ( LibraryFolders.CheckAlbum( pFolder ) ) pFolder->Delete();
}
Library.Unlock();
PostUpdate();
}
void CLibraryTileView::OnUpdateLibraryAlbumProperties(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_nSelected == 1 );
}
void CLibraryTileView::OnLibraryAlbumProperties()
{
if ( m_pSelTile.GetCount() == 0 ) return;
CLibraryTileItem* pItem = (CLibraryTileItem*)m_pSelTile.GetHead();
CAlbumFolder* pFolder = pItem->m_pFolder;
CFolderPropertiesDlg dlg( NULL, pFolder );
if ( dlg.DoModal() == IDOK ) GetFrame()->Display( pFolder );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -