⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctrllibraryframe.cpp

📁 著名的下载软件核心Shareaza
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		dc.FillSolidRect( rc.left, rc.top + 2, rc.Width(), rc.Height() - 3,
			GetSysColor( COLOR_BTNFACE ) );
	}
}

BOOL CLibraryFrame::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	CWnd* pWnd = ChildWindowFromPoint( pt );

	if ( pWnd && pWnd != this && ! m_bMouseWheel )
	{
		m_bMouseWheel = TRUE;
		pWnd->SendMessage( WM_MOUSEWHEEL,
			MAKELONG( nFlags, zDelta ), MAKELONG( pt.x, pt.y ) );
		m_bMouseWheel = FALSE;
	}

	return TRUE;
}

void CLibraryFrame::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	if ( m_pView ) m_pView->SendMessage( (WPARAM)pWnd->GetSafeHwnd(), MAKELONG( point.x, point.y ) );
}

void CLibraryFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	lpMeasureItemStruct->itemHeight = 18;
}

/////////////////////////////////////////////////////////////////////////////
// CLibraryFrame resizing behaviour

BOOL CLibraryFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	if ( m_pDragList != NULL )
	{
		if ( Settings.Library.ShowVirtual )
		{
			if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 )
				SetCursor( m_hCursMove );
			else
				SetCursor( m_hCursCopy );
		}
		else
		{
			if ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 )
				SetCursor( m_hCursCopy );
			else
				SetCursor( m_hCursMove );
		}
		return TRUE;
	}

	CRect rcClient, rc;
	CPoint point;

	GetCursorPos( &point );
	GetClientRect( &rcClient );
	ClientToScreen( &rcClient );


	rc.SetRect(	rcClient.left + m_nTreeSize,
				rcClient.top,
				rcClient.left + m_nTreeSize + SPLIT_SIZE,
				rcClient.bottom );

	if ( rc.PtInRect( point ) )
	{
		SetCursor( AfxGetApp()->LoadStandardCursor( IDC_SIZEWE ) );
		return TRUE;
	}

	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 );

		if ( rc.PtInRect( point ) )
		{
			SetCursor( AfxGetApp()->LoadStandardCursor( IDC_SIZENS ) );
			return TRUE;
		}
	}
	
	return CWnd::OnSetCursor( pWnd, nHitTest, message );
}

void CLibraryFrame::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CRect rcClient, rc;
	
	GetClientRect( &rcClient );
	
	rc.SetRect(	rcClient.left + m_nTreeSize,
				rcClient.top,
				rcClient.left + m_nTreeSize + SPLIT_SIZE,
				rcClient.bottom );
	
	if ( rc.PtInRect( point ) )
	{
		DoSizeTree();
		return;
	}
	
	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 );
		
		if ( rc.PtInRect( point ) )
		{
			DoSizePanel();
			return;
		}
	}
	
	CWnd::OnLButtonDown( nFlags, point );
}

BOOL CLibraryFrame::DoSizeTree()
{
	MSG* pMsg = &AfxGetThreadState()->m_msgCur;
	CRect rcClient;
	CPoint point;
	
	GetClientRect( &rcClient );
	ClientToScreen( &rcClient );
	ClipCursor( &rcClient );
	SetCapture();
	
	GetClientRect( &rcClient );
	
	int nOffset = 0xFFFF;
	
	while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
	{
		while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) );
		
		if ( ! AfxGetThread()->PumpMessage() )
		{
			AfxPostQuitMessage( 0 );
			break;
		}
		
		GetCursorPos( &point );
		ScreenToClient( &point );
		
		int nSplit = point.x - rcClient.left;
		
		if ( nOffset == 0xFFFF ) nOffset = m_nTreeSize - nSplit;
		nSplit += nOffset;
		
		nSplit = max( nSplit, 0 );
		nSplit = min( nSplit, rcClient.right - SPLIT_SIZE );
		
		if ( nSplit < 8 )
			nSplit = 0;
		if ( nSplit > rcClient.right - SPLIT_SIZE - 8 )
			nSplit = rcClient.right - SPLIT_SIZE;
		
		if ( nSplit != m_nTreeSize )
		{
			m_nTreeSize = nSplit;
			OnSize( 1982, 0, 0 );
			Invalidate();
		}
	}
	
	ReleaseCapture();
	ClipCursor( NULL );
	
	return TRUE;
}

BOOL CLibraryFrame::DoSizePanel()
{
	MSG* pMsg = &AfxGetThreadState()->m_msgCur;
	CRect rcClient;
	CPoint point;
	
	GetClientRect( &rcClient );
	rcClient.left += m_nTreeSize + SPLIT_SIZE;
	rcClient.top += BAR_HEIGHT + m_nHeaderSize;
	rcClient.bottom -= BAR_HEIGHT;
	ClientToScreen( &rcClient );
	ClipCursor( &rcClient );
	SetCapture();
	
	ScreenToClient( &rcClient );
	
	int nOffset = 0xFFFF;
	
	while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
	{
		while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) );
		
		if ( ! AfxGetThread()->PumpMessage() )
		{
			AfxPostQuitMessage( 0 );
			break;
		}
		
		GetCursorPos( &point );
		ScreenToClient( &point );
		
		int nSplit = rcClient.bottom - point.y;
		
		if ( nOffset == 0xFFFF ) nOffset = m_nPanelSize - nSplit;
		nSplit += nOffset;
		
		if ( nSplit < 8 )
			nSplit = 0;
		if ( nSplit > rcClient.Height() - SPLIT_SIZE - 8 )
			nSplit = rcClient.Height() - SPLIT_SIZE;
		
		if ( nSplit != m_nPanelSize )
		{
			m_nPanelSize = nSplit;
			OnSize( 1982, 0, 0 );
			Invalidate();
		}
	}
	
	ReleaseCapture();
	ClipCursor( NULL );
	
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CLibraryFrame view and panel selection

void CLibraryFrame::SetView(CLibraryView* pView, BOOL bUpdate, BOOL bUser)
{
	CSingleLock pLock( &Library.m_pSection, TRUE );

	if ( bUser && pView != NULL )
	{
		for (	CLibraryTreeItem* pItem = m_pFolderSelection ; pItem ;
				pItem = pItem->m_pSelNext )
		{
			if ( pItem->m_pVirtual != NULL )
			{
				pItem->m_pVirtual->m_sBestView = pView->GetRuntimeClass()->m_lpszClassName;
			}
		}
	}

	if ( m_pView == pView )
	{
		if ( m_pView )
		{
			m_pView->Update();
			m_pView->ShowWindow( SW_SHOW );
			m_wndViewTop.Update( m_pView );
		}

		return;
	}

	m_wndViewTip.Hide();
	m_wndViewTip.SetOwner( this );

	CWnd* pFocus = GetFocus();
	BOOL bViewSel = ( pFocus == m_pView || ( pFocus && pFocus->GetParent() == m_pView ) );

	CLibraryView* pOld = m_pView;
	m_pView = pView;

	if ( m_pView ) m_pView->Create( this );
	OnSize( 1982, 0, 0 );

	if ( m_pView && ! bUpdate ) m_pView->Update();

	if ( pOld ) pOld->ShowWindow( SW_HIDE );
	if ( m_pView ) m_pView->ShowWindow( SW_SHOW );
	if ( pOld ) pOld->DestroyWindow();

	if ( m_pView && bUpdate ) Update( TRUE );

	m_wndViewTop.Update( m_pView );

	if ( m_pView )
	{
		CString strBar( m_pView->m_pszToolBar );
		strBar += Settings.Library.ShowVirtual ? _T(".Virtual") : _T(".Physical");
		Skin.CreateToolBar( strBar, &m_wndViewBottom );
		m_wndViewTip.SetOwner( m_pView );

		if ( bViewSel ) m_pView->SetFocus();
	}

	Invalidate();
}

void CLibraryFrame::SetPanel(CLibraryPanel* pPanel)
{
	if ( pPanel == m_pPanel )
	{
		if ( m_pPanel )
		{
			m_pPanel->Update();
			m_pPanel->ShowWindow( SW_SHOW );
		}
		return;
	}

	CLibraryPanel* pOld = m_pPanel;
	m_pPanel = pPanel;

	if ( m_pPanel ) m_pPanel->Create( this );
	OnSize( 1982, 0, 0 );

	if ( m_pPanel ) m_pPanel->Update();

	if ( pOld ) pOld->ShowWindow( SW_HIDE );
	if ( m_pPanel ) m_pPanel->ShowWindow( SW_SHOW );
	if ( pOld ) pOld->DestroyWindow();
}

/////////////////////////////////////////////////////////////////////////////
// CLibraryFrame update operations

BOOL CLibraryFrame::Update(BOOL bForce, BOOL bBestView)
{
	CSingleLock pLock( &Library.m_pSection );
	if ( ! pLock.Lock( bForce ? 500 : 50 ) ) return FALSE;
	
	if ( ! bForce && m_nLibraryCookie == Library.m_nUpdateCookie ) return FALSE;
	m_nLibraryCookie = Library.m_nUpdateCookie;
	
	m_bUpdating = TRUE;
	
	m_nFolderCookie		= GetTickCount();
	m_wndTree.Update( m_nFolderCookie );
	m_pFolderSelection	= m_wndTree.GetFirstSelected();
	
	CLibraryView* pFirstView	= NULL;
	CLibraryView* pBestView		= NULL;
	CString strBest;
	
	if ( m_pFolderSelection != NULL && m_pFolderSelection->m_pVirtual != NULL )
		strBest = m_pFolderSelection->m_pVirtual->GetBestView();
	
	for ( POSITION pos = m_pViews.GetHeadPosition() ; pos ; )
	{
		CLibraryView* pView = (CLibraryView*)m_pViews.GetNext( pos );
		
		if ( pView->CheckAvailable( m_pFolderSelection ) )
		{
			if ( pFirstView == NULL ) pFirstView = pView;
			if ( strBest.CompareNoCase( CString( pView->GetRuntimeClass()->m_lpszClassName ) ) == 0 )
				pBestView = pView;
		}
	}
	
	int nHeaderSize = m_wndHeader.Update();
	
	if ( bBestView && pBestView != NULL )
	{
		if ( pBestView->IsKindOf( RUNTIME_CLASS(CLibraryCollectionView) ) )
			nHeaderSize = 0;
	}
	
	if ( nHeaderSize != m_nHeaderSize )
	{
		m_nHeaderSize = nHeaderSize;
		if ( m_nHeaderSize == 0 ) m_wndHeader.ShowWindow( SW_HIDE );
		OnSize( 1982, 0, 0 );
	}
	
	if ( pFirstView == NULL )
	{
		ASSERT( FALSE );
		m_bUpdating = FALSE;
		return TRUE;
	}
	
	if ( pBestView != NULL && bBestView )
	{
		SetView( pBestView, FALSE, FALSE );
	}
	else if ( m_pView == NULL || m_pView->m_bAvailable == FALSE )
	{
		SetView( pFirstView, FALSE, FALSE );
	}
	else
	{
		SetView( m_pView, FALSE, FALSE );
	}
	
	UpdatePanel( TRUE );
	
	m_bUpdating = FALSE;
	
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -