📄 ctrllibrarymetapanel.cpp
字号:
//
// CtrlLibraryMetaPanel.cpp
//
// Copyright (c) Shareaza Development Team, 2002-2004.
// This file is part of SHAREAZA (www.shareaza.com)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "StdAfx.h"
#include "Shareaza.h"
#include "Settings.h"
#include "Library.h"
#include "LibraryFolders.h"
#include "SharedFolder.h"
#include "SharedFile.h"
#include "AlbumFolder.h"
#include "Schema.h"
#include "SchemaCache.h"
#include "CoolInterface.h"
#include "ShellIcons.h"
#include "Skin.h"
#include "ImageServices.h"
#include "CtrlLibraryFrame.h"
#include "CtrlLibraryMetaPanel.h"
#include "CtrlLibraryTree.h"
#include "DlgFilePropertiesSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CLibraryMetaPanel, CLibraryPanel)
BEGIN_MESSAGE_MAP(CLibraryMetaPanel, CLibraryPanel)
//{{AFX_MSG_MAP(CLibraryMetaPanel)
ON_WM_PAINT()
ON_WM_VSCROLL()
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SETCURSOR()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLibraryMetaPanel construction
CLibraryMetaPanel::CLibraryMetaPanel()
{
m_nThumbSize = 96;
m_crLight = CCoolInterface::CalculateColour(
CoolInterface.m_crTipBack, RGB( 255, 255, 255 ), 128 );
}
CLibraryMetaPanel::~CLibraryMetaPanel()
{
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryMetaPanel operations
BOOL CLibraryMetaPanel::CheckAvailable(CLibraryTreeItem* pFolders, CLibraryList* pObjects)
{
m_bAvailable = FALSE;
if ( pFolders != NULL )
{
m_bAvailable = TRUE;
if ( pFolders->m_pSelNext == NULL && pFolders->m_pVirtual != NULL )
{
if ( pFolders->m_pVirtual->m_bCollSHA1 &&
pFolders->m_pVirtual->GetBestView().Find( _T("Collection") ) > 0 )
m_bAvailable = FALSE;
if ( pFolders->m_pVirtual->GetFolderCount() > 0 ) m_bAvailable = FALSE;
}
}
return m_bAvailable;
}
void CLibraryMetaPanel::Update()
{
CSingleLock pLock1( &Library.m_pSection, TRUE );
CSingleLock pLock2( &m_pSection, TRUE );
CLibraryList* pSel = GetViewSelection();
m_nSelected = pSel->GetCount();
CLibraryFile* pFirst = m_nSelected ? Library.LookupFile( pSel->GetHead() ) : NULL;
if ( pFirst == NULL ) m_nSelected = 0;
m_nIcon32 = m_nIcon48 = -1;
if ( m_nSelected == 1 )
{
m_nIndex = pFirst->m_nIndex;
m_sName = pFirst->m_sName;
m_sPath = pFirst->GetPath();
if ( pFirst->m_pFolder != NULL ) m_sFolder = pFirst->m_pFolder->m_sPath;
m_sSize = Settings.SmartVolume( pFirst->GetSize(), FALSE );
m_sType = ShellIcons.GetTypeString( m_sName );
m_nIcon32 = ShellIcons.Get( m_sName, 32 );
m_nIcon48 = ShellIcons.Get( m_sName, 48 );
m_nRating = pFirst->m_nRating;
}
else if ( m_nSelected > 1 )
{
CString strFormat;
LoadString( strFormat, IDS_LIBPANEL_MULTIPLE_FILES );
m_sName.Format( strFormat, m_nSelected );
QWORD nSize = 0;
m_sFolder = ( pFirst->m_pFolder != NULL ) ? pFirst->m_pFolder->m_sPath : _T("");
m_nIcon32 = ShellIcons.Get( pFirst->m_sName, 32 );
m_nIcon48 = ShellIcons.Get( pFirst->m_sName, 48 );
m_nRating = 0;
for ( POSITION pos = pSel->GetHeadPosition() ; pos ; )
{
CLibraryFile* pFile = Library.LookupFile( pSel->GetNext( pos ) );
if ( pFile == NULL ) continue;
nSize += pFile->GetSize() / 1024;
if ( pFile->m_pFolder != NULL && pFile->m_pFolder->m_sPath != m_sFolder )
{
LoadString( m_sFolder, IDS_LIBPANEL_MULTIPLE_FOLDERS );
}
int nIcon = ShellIcons.Get( pFile->m_sName, 48 );
if ( nIcon != m_nIcon48 ) m_nIcon48 = -1;
nIcon = ShellIcons.Get( pFile->m_sName, 32 );
if ( nIcon != m_nIcon32 ) m_nIcon32 = -1;
}
m_sSize = Settings.SmartVolume( nSize, TRUE );
m_sPath.Empty();
m_sType.Empty();
}
m_pSchema = NULL;
for ( POSITION pos = pSel->GetHeadPosition() ; pos ; )
{
CLibraryFile* pFile = Library.LookupFile( pSel->GetNext( pos ) );
if ( pFile == NULL ) continue;
m_pSchema = pFile->m_pSchema;
if ( m_pSchema ) break;
}
m_pMetadata.Setup( m_pSchema );
if ( m_pSchema != NULL )
{
for ( POSITION pos = pSel->GetHeadPosition() ; pos ; )
{
if ( CLibraryFile* pFile = Library.LookupFile( pSel->GetNext( pos ) ) )
{
if ( pFile->m_pMetadata != NULL &&
m_pSchema->Equals( pFile->m_pSchema ) )
{
m_pMetadata.Combine( pFile->m_pMetadata );
}
}
}
}
m_pMetadata.CreateLinks();
m_pMetadata.Clean( 4096 );
CClientDC dc( this );
SCROLLINFO pInfo;
CRect rc;
GetClientRect( &rc );
int nThumbSize = rc.Height() - 16;
nThumbSize = max( nThumbSize, 64 );
nThumbSize = min( nThumbSize, 128 );
int nHeight = 54 + m_pMetadata.Layout( &dc, rc.Width() - 24 - nThumbSize );
pInfo.cbSize = sizeof(pInfo);
pInfo.fMask = SIF_ALL & ~SIF_TRACKPOS;
pInfo.nMin = 0;
pInfo.nMax = nHeight;
pInfo.nPage = rc.Height();
pInfo.nPos = GetScrollPos( SB_VERT );
pInfo.nPos = max( 0, min( pInfo.nPos, pInfo.nMax - (int)pInfo.nPage + 1 ) );
SetScrollInfo( SB_VERT, &pInfo, TRUE );
if ( m_bmThumb.m_hObject != NULL && m_sThumb != m_sPath ) m_bmThumb.DeleteObject();
pLock2.Unlock();
pLock1.Unlock();
if ( m_sPath.GetLength() && m_bmThumb.m_hObject == NULL )
{
if ( m_bThread == FALSE )
{
m_bThread = TRUE;
CWinThread* pThread = AfxBeginThread( ThreadStart, this, THREAD_PRIORITY_IDLE );
m_hThread = pThread->m_hThread;
}
m_pWakeup.SetEvent();
}
Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryMetaPanel create and destroy
int CLibraryMetaPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if ( CLibraryPanel::OnCreate( lpCreateStruct ) == -1 ) return -1;
m_hThread = NULL;
m_bThread = FALSE;
return 0;
}
void CLibraryMetaPanel::OnDestroy()
{
m_bThread = FALSE;
m_pWakeup.SetEvent();
for ( int nAttempt = 5 ; nAttempt > 0 ; nAttempt-- )
{
DWORD nCode;
if ( ! GetExitCodeThread( m_hThread, &nCode ) ) break;
if ( nCode != STILL_ACTIVE ) break;
Sleep( 100 );
}
if ( nAttempt == 0 )
{
TerminateThread( m_hThread, 0 );
theApp.Message( MSG_DEBUG, _T("WARNING: Terminating CLibraryMetaPanel thread.") );
Sleep( 100 );
}
m_hThread = NULL;
CLibraryPanel::OnDestroy();
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryMetaPanel painting
void CLibraryMetaPanel::OnPaint()
{
CSingleLock pLock( &m_pSection, TRUE );
CPaintDC dc( this );
CRect rcClient;
CString str;
GetClientRect( &rcClient );
CFont* pOldFont = dc.GetCurrentFont();
dc.SetTextColor( CoolInterface.m_crText );
dc.SetBkColor( CoolInterface.m_crWindow );
dc.SetBkMode( OPAQUE );
if ( m_nSelected == 0 )
{
dc.SelectObject( &CoolInterface.m_fntNormal );
LoadString( str, IDS_LIBPANEL_NO_SELECTION );
CSize sz = dc.GetTextExtent( str );
CPoint pt = rcClient.CenterPoint();
pt.x -= sz.cx / 2; pt.y -= sz.cy / 2;
dc.ExtTextOut( pt.x, pt.y, ETO_OPAQUE, &rcClient, str, NULL );
dc.SelectObject( pOldFont );
return;
}
CRect rcWork;
DrawThumbnail( &dc, rcClient, rcWork );
dc.SetViewportOrg( 0, -GetScrollPos( SB_VERT ) );
dc.SetBkColor( CoolInterface.m_crWindow );
dc.SelectObject( &CoolInterface.m_fntCaption );
DrawText( &dc, rcWork.left, rcWork.top, m_sName );
if ( m_nRating > 1 )
{
CPoint ptStar( rcWork.right - 3, rcWork.top - 2 );
m_rcRating.SetRectEmpty();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -