📄 ctrllibraryframe.cpp
字号:
//
// CtrlLibraryFrame.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 "LibraryBuilder.h"
#include "AlbumFolder.h"
#include "SharedFile.h"
#include "QuerySearch.h"
#include "Schema.h"
#include "XML.h"
#include "CtrlLibraryFrame.h"
#include "DlgNewSearch.h"
#include "Skin.h"
#include "CtrlLibraryView.h"
#include "CtrlLibraryCollectionView.h"
#include "CtrlLibraryDetailView.h"
#include "CtrlLibraryThumbView.h"
#include "CtrlLibraryAlbumView.h"
#include "CtrlLibraryTileView.h"
#include "CtrlLibraryHomeView.h"
#include "CtrlLibraryPanel.h"
#include "CtrlLibraryMetaPanel.h"
#include "CtrlLibraryHistoryPanel.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CLibraryFrame, CWnd)
BEGIN_MESSAGE_MAP(CLibraryFrame, CWnd)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_MOUSEWHEEL()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_TIMER()
ON_WM_CONTEXTMENU()
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_MEASUREITEM()
ON_COMMAND(ID_LIBRARY_REFRESH, OnLibraryRefresh)
ON_UPDATE_COMMAND_UI(ID_LIBRARY_TREE_PHYSICAL, OnUpdateLibraryTreePhysical)
ON_COMMAND(ID_LIBRARY_TREE_PHYSICAL, OnLibraryTreePhysical)
ON_UPDATE_COMMAND_UI(ID_LIBRARY_TREE_VIRTUAL, OnUpdateLibraryTreeVirtual)
ON_COMMAND(ID_LIBRARY_TREE_VIRTUAL, OnLibraryTreeVirtual)
ON_UPDATE_COMMAND_UI(ID_LIBRARY_PANEL, OnUpdateLibraryPanel)
ON_COMMAND(ID_LIBRARY_PANEL, OnLibraryPanel)
ON_COMMAND(ID_LIBRARY_SEARCH, OnLibrarySearch)
ON_COMMAND(ID_LIBRARY_SEARCH_QUICK, OnLibrarySearchQuick)
ON_NOTIFY(LTN_SELCHANGED, IDC_LIBRARY_TREE, OnTreeSelection)
ON_CBN_CLOSEUP(AFX_IDW_TOOLBAR, OnFilterTypes)
ON_BN_CLICKED(AFX_IDW_TOOLBAR, OnToolbarReturn)
ON_BN_DOUBLECLICKED(AFX_IDW_TOOLBAR, OnToolbarEscape)
ON_WM_SETFOCUS()
END_MESSAGE_MAP()
#define BAR_HEIGHT 28
#define SPLIT_SIZE 6
/////////////////////////////////////////////////////////////////////////////
// CLibraryFrame construction
CLibraryFrame::CLibraryFrame()
{
m_pViews.AddTail( new CLibraryDetailView() );
m_pViews.AddTail( new CLibraryListView() );
m_pViews.AddTail( new CLibraryIconView() );
m_pViews.AddTail( new CLibraryThumbView() );
m_pViews.AddTail( new CLibraryAlbumView() );
m_pViews.AddTail( new CLibraryTileView() );
m_pViews.AddTail( new CLibraryHomeView() );
m_pViews.AddTail( new CLibraryCollectionView() );
m_pPanels.AddTail( new CLibraryMetaPanel() );
m_pPanels.AddTail( new CLibraryHistoryPanel() );
m_pView = NULL;
m_pPanel = NULL;
m_nTreeSize = Settings.Library.TreeSize;
m_nPanelSize = Settings.Library.PanelSize;
m_bPanelShow = Settings.Library.ShowPanel;
m_nHeaderSize = 0;
m_bUpdating = FALSE;
m_bMouseWheel = FALSE;
m_pDragList = NULL;
m_pDragImage = NULL;
m_hCursMove = theApp.LoadCursor( IDC_MOVE );
m_hCursCopy = theApp.LoadCursor( IDC_COPY );
}
CLibraryFrame::~CLibraryFrame()
{
for ( POSITION pos = m_pViews.GetHeadPosition() ; pos ; )
{
delete (CLibraryView*)m_pViews.GetNext( pos );
}
for ( pos = m_pPanels.GetHeadPosition() ; pos ; )
{
delete (CLibraryPanel*)m_pPanels.GetNext( pos );
}
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryFrame system message handlers
BOOL CLibraryFrame::Create(CWnd* pParentWnd)
{
CRect rect;
return CWnd::Create( NULL, _T("CLibraryFrame"),
WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, pParentWnd, IDC_LIBRARY_FRAME, NULL );
}
int CLibraryFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
if ( ! m_wndTreeTop.Create( this, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
m_wndTreeTop.SetBarStyle( m_wndTreeTop.GetBarStyle() | CBRS_TOOLTIPS|CBRS_BORDER_BOTTOM );
m_wndTreeTop.SetOwner( GetOwner() );
if ( ! m_wndTreeBottom.Create( this, WS_CHILD|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
m_wndTreeBottom.SetBarStyle( m_wndTreeBottom.GetBarStyle() | CBRS_TOOLTIPS|CBRS_BORDER_TOP );
m_wndTreeBottom.SetOwner( GetOwner() );
CRect rcTypes( 0, 0, 128, BAR_HEIGHT );
if ( ! m_wndTreeTypes.Create( WS_CHILD, rcTypes, this, AFX_IDW_TOOLBAR ) ) return -1;
m_wndTreeTypes.GetWindowRect( &rcTypes );
m_nTreeTypesHeight = rcTypes.Height();
if ( ! m_wndViewTop.Create( this, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
m_wndViewTop.SetBarStyle( m_wndViewTop.GetBarStyle() | CBRS_TOOLTIPS );
m_wndViewTop.SetOwner( GetOwner() );
if ( ! m_wndViewBottom.Create( this, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
m_wndViewBottom.SetBarStyle( m_wndViewBottom.GetBarStyle() | CBRS_TOOLTIPS|CBRS_BORDER_TOP );
m_wndViewBottom.SetOwner( GetOwner() );
if ( ! m_wndSearch.Create( WS_CHILD|ES_AUTOHSCROLL, rcTypes, &m_wndViewBottom, IDC_SEARCH_BOX ) ) return -1;
m_wndSearch.SetFont( &theApp.m_gdiFont );
m_wndTree.Create( this );
m_wndHeader.Create( this );
m_wndViewTip.Create( this, &Settings.Interface.TipLibrary );
return 0;
}
void CLibraryFrame::OnDestroy()
{
CancelDrag();
if ( m_wndViewTip.m_hWnd ) m_wndViewTip.DestroyWindow();
Settings.Library.TreeSize = m_nTreeSize;
Settings.Library.PanelSize = m_nPanelSize;
Settings.Library.ShowPanel = m_bPanelShow;
CWnd::OnDestroy();
}
BOOL CLibraryFrame::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB )
{
CWnd* pFocus = GetFocus();
if ( pFocus == &m_wndTree && m_pView != NULL )
{
m_pView->SetFocus();
return TRUE;
}
else
{
m_wndTree.SetFocus();
return TRUE;
}
}
return CWnd::PreTranslateMessage( pMsg );
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryFrame skin change
void CLibraryFrame::OnSkinChange()
{
m_wndTree.SetVirtual( Settings.Library.ShowVirtual );
Skin.CreateToolBar( _T("CLibraryTree.Top"), &m_wndTreeTop );
if ( Settings.Library.ShowVirtual )
{
Skin.CreateToolBar( _T("CLibraryHeaderBar.Virtual"), &m_wndViewTop );
Skin.CreateToolBar( _T("CLibraryTree.Virtual"), &m_wndTreeBottom );
}
else
{
Skin.CreateToolBar( _T("CLibraryHeaderBar.Physical"), &m_wndViewTop );
Skin.CreateToolBar( _T("CLibraryTree.Physical"), &m_wndTreeBottom );
m_wndTreeTypes.SetEmptyString( IDS_LIBRARY_TYPE_FILTER_ALL );
m_wndTreeTypes.Load( Settings.Library.FilterURI );
}
m_wndTreeBottom.ShowWindow( Settings.Library.ShowVirtual ? SW_SHOW : SW_HIDE );
m_wndTreeTypes.ShowWindow( Settings.Library.ShowVirtual ? SW_HIDE : SW_SHOW );
m_wndHeader.OnSkinChange();
CLibraryView* pView = m_pView;
CLibraryPanel* pPanel = m_pPanel;
SetView( NULL, TRUE, FALSE );
SetView( pView, TRUE, FALSE );
SetPanel( pPanel );
}
/////////////////////////////////////////////////////////////////////////////
// CLibraryFrame more system message handlers
BOOL CLibraryFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if ( m_wndTreeTop.m_hWnd )
{
if ( m_wndTreeTop.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
if ( m_wndTreeBottom.m_hWnd )
{
if ( m_wndTreeBottom.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
if ( m_wndViewTop.m_hWnd )
{
if ( m_wndViewTop.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
if ( m_wndViewBottom.m_hWnd )
{
if ( m_wndViewBottom.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
if ( m_wndTree.m_hWnd )
{
if ( m_wndTree.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
if ( m_pView && m_pView->m_hWnd )
{
if ( m_pView->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
if ( m_pPanel && m_pPanel->m_hWnd )
{
if ( m_pPanel->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
return CWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
}
void CLibraryFrame::OnSize(UINT nType, int cx, int cy)
{
if ( nType != 1982 ) CWnd::OnSize( nType, cx, cy );
CRect rc;
GetClientRect( &rc );
if ( rc.Width() < 32 || rc.Height() < 32 ) return;
if ( rc.Width() < m_nTreeSize + SPLIT_SIZE )
{
m_nTreeSize = max( 0, rc.Width() - SPLIT_SIZE );
}
if ( rc.Height() - BAR_HEIGHT * 2 - m_nHeaderSize < m_nPanelSize + SPLIT_SIZE )
{
m_nPanelSize = max( 0, rc.Height() - BAR_HEIGHT * 2 - m_nHeaderSize - SPLIT_SIZE );
}
HDWP hDWP = BeginDeferWindowPos(
6 + ( m_pView != NULL ) + ( m_pPanel != NULL ) + ( m_nHeaderSize > 0 ) );
DeferWindowPos( hDWP, m_wndTreeTop.GetSafeHwnd(), NULL,
rc.left, rc.top, m_nTreeSize, BAR_HEIGHT, SWP_NOZORDER );
DeferWindowPos( hDWP, m_wndTreeBottom.GetSafeHwnd(), NULL,
rc.left, rc.bottom - BAR_HEIGHT, m_nTreeSize, BAR_HEIGHT, SWP_NOZORDER );
DeferWindowPos( hDWP, m_wndTreeTypes.GetSafeHwnd(), NULL,
rc.left, rc.bottom - m_nTreeTypesHeight, m_nTreeSize, 256, SWP_NOZORDER );
DeferWindowPos( hDWP, m_wndViewTop.GetSafeHwnd(), NULL,
rc.left + m_nTreeSize + SPLIT_SIZE, rc.top,
rc.Width() - m_nTreeSize - SPLIT_SIZE, BAR_HEIGHT - 1, SWP_NOZORDER );
DeferWindowPos( hDWP, m_wndViewBottom.GetSafeHwnd(), NULL,
rc.left + m_nTreeSize + SPLIT_SIZE, rc.bottom - BAR_HEIGHT,
rc.Width() - m_nTreeSize - SPLIT_SIZE, BAR_HEIGHT, SWP_NOZORDER );
DeferWindowPos( hDWP, m_wndTree.GetSafeHwnd(), NULL,
rc.left, rc.top + BAR_HEIGHT, m_nTreeSize, rc.Height() - BAR_HEIGHT * 2, SWP_NOZORDER );
if ( m_pView != NULL )
{
int nTop = rc.top + BAR_HEIGHT - 1;
if ( m_nHeaderSize > 0 )
{
DeferWindowPos( hDWP, m_wndHeader.GetSafeHwnd(), NULL,
rc.left + m_nTreeSize + SPLIT_SIZE, nTop,
rc.Width() - m_nTreeSize - SPLIT_SIZE, m_nHeaderSize,
SWP_NOZORDER|SWP_SHOWWINDOW );
nTop += m_nHeaderSize + 1;
}
int nHeight = rc.bottom - BAR_HEIGHT - nTop;
if ( m_pPanel ) nHeight -= m_nPanelSize + SPLIT_SIZE;
DeferWindowPos( hDWP, m_pView->GetSafeHwnd(), NULL,
rc.left + m_nTreeSize + SPLIT_SIZE, nTop,
rc.Width() - m_nTreeSize - SPLIT_SIZE, nHeight, SWP_NOZORDER|SWP_SHOWWINDOW );
}
if ( m_pPanel != NULL )
{
DeferWindowPos( hDWP, m_pPanel->GetSafeHwnd(), NULL,
rc.left + m_nTreeSize + SPLIT_SIZE, rc.bottom - BAR_HEIGHT - m_nPanelSize,
rc.Width() - m_nTreeSize - SPLIT_SIZE, m_nPanelSize, SWP_NOZORDER|SWP_SHOWWINDOW );
}
EndDeferWindowPos( hDWP );
}
void CLibraryFrame::OnPaint()
{
CPaintDC dc( this );
CRect rcClient, rc;
GetClientRect( &rcClient );
rc.SetRect( rcClient.left + m_nTreeSize,
rcClient.top,
rcClient.left + m_nTreeSize + SPLIT_SIZE,
rcClient.bottom );
dc.FillSolidRect( rc.left, rc.top, 1, rc.Height(), GetSysColor( COLOR_BTNFACE ) );
dc.FillSolidRect( rc.left + 1, rc.top, 1, rc.Height(), GetSysColor( COLOR_3DHIGHLIGHT ) );
dc.FillSolidRect( rc.right - 1, rc.top, 1, rc.Height(), GetSysColor( COLOR_3DSHADOW ) );
dc.FillSolidRect( rc.left + 2, rc.top, rc.Width() - 3, rc.Height(),
GetSysColor( COLOR_BTNFACE ) );
if ( m_nHeaderSize > 0 )
{
dc.FillSolidRect( rc.right, rcClient.top + BAR_HEIGHT - 1 + m_nHeaderSize,
rcClient.right - rc.right, 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
}
if ( Settings.Library.ShowVirtual == FALSE )
{
rc.SetRect( rcClient.left, rcClient.bottom - BAR_HEIGHT,
rcClient.left + m_nTreeSize, rcClient.bottom - m_nTreeTypesHeight );
dc.FillSolidRect( rc.left, rc.top, rc.Width(), 1, GetSysColor( COLOR_3DSHADOW ) );
dc.FillSolidRect( rc.left, rc.top + 1, rc.Width(), 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
dc.FillSolidRect( rc.left, rc.top + 2, rc.Width(), rc.Height() - 2, GetSysColor( COLOR_BTNFACE ) );
}
if ( m_pPanel != NULL )
{
rc.SetRect( rcClient.left + m_nTreeSize + SPLIT_SIZE,
rcClient.bottom - BAR_HEIGHT - m_nPanelSize - SPLIT_SIZE,
rcClient.right,
rcClient.bottom - BAR_HEIGHT - m_nPanelSize );
dc.FillSolidRect( rc.left, rc.top, rc.Width(), 1, GetSysColor( COLOR_BTNFACE ) );
dc.FillSolidRect( rc.left, rc.top + 1, rc.Width(), 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
dc.FillSolidRect( rc.left, rc.bottom - 1, rc.Width(), 1, GetSysColor( COLOR_3DSHADOW ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -