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

📄 wndpanel.cpp

📁 著名的下载软件核心Shareaza
💻 CPP
字号:
//
// WndPanel.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 "WndPanel.h"
#include "CoolInterface.h"
#include "Skin.h"
#include "SkinWindow.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_DYNCREATE(CPanelWnd, CChildWnd)

BEGIN_MESSAGE_MAP(CPanelWnd, CChildWnd)
	//{{AFX_MSG_MAP(CPanelWnd)
	ON_WM_NCPAINT()
	ON_WM_NCCALCSIZE()
	ON_WM_NCHITTEST()
	ON_WM_NCACTIVATE()
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_NCLBUTTONDOWN()
	ON_WM_SETCURSOR()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_SETTEXT, OnSetText)
END_MESSAGE_MAP()

#define CAPTION_HEIGHT	20
#define CLOSEBOX		10


/////////////////////////////////////////////////////////////////////////////
// CPanelWnd construction

CPanelWnd::CPanelWnd(BOOL bTabMode, BOOL bGroupMode)
{
	m_bPanelMode = Settings.General.GUIMode != GUI_WINDOWED;
	
	if ( m_bPanelMode )
	{
		m_bTabMode |= bTabMode;
		m_bGroupMode |= bGroupMode;
	}
	
	m_bPanelClose = ( m_bPanelMode && ! m_bTabMode );
}

CPanelWnd::~CPanelWnd()
{
}

/////////////////////////////////////////////////////////////////////////////
// CPanelWnd message handlers

int CPanelWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if ( CChildWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
	
	return 0;
}

void CPanelWnd::OnSize(UINT nType, int cx, int cy) 
{
	if ( m_bPanelMode && ! m_pSkin && CCoolInterface::IsNewWindows() && ! IsIconic() )
	{
		CRect rc;
		GetWindowRect( &rc );
		rc.OffsetRect( -rc.left, -rc.top );
		rc.right++; rc.bottom++;
		SetWindowRgn( CreateRectRgnIndirect( &rc ), TRUE );
	}

	CChildWnd::OnSize( nType, cx, cy );
}

void CPanelWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
{
	if ( m_bPanelMode && m_pSkin == NULL )
	{
		NCCALCSIZE_PARAMS* pSize = (NCCALCSIZE_PARAMS*)lpncsp;
		pSize->rgrc[0].top += CAPTION_HEIGHT;
		return; // ( bCalcValidRects ) ? WVR_REDRAW|WVR_ALIGNTOP|WVR_ALIGNLEFT : 0;
	}
	
	CChildWnd::OnNcCalcSize( bCalcValidRects, lpncsp );
}

UINT CPanelWnd::OnNcHitTest(CPoint point) 
{
	if ( m_bPanelMode && ! m_pSkin )
	{
		CRect rc;
		GetWindowRect( &rc );
		rc.bottom = rc.top + CAPTION_HEIGHT;
		return rc.PtInRect( point ) ? HTCAPTION : HTCLIENT;
	}

	return CChildWnd::OnNcHitTest( point );
}

void CPanelWnd::OnNcPaint() 
{
	if ( m_bPanelMode && ! m_pSkin )
	{
		CWindowDC dc( this );
		PaintCaption( dc );
	}
	else
	{
		CChildWnd::OnNcPaint();
	}
}

BOOL CPanelWnd::OnNcActivate(BOOL bActive) 
{
	if ( m_bPanelMode && ! m_pSkin )
	{
		CWindowDC dc( this );
		PaintCaption( dc );
		return TRUE;
	}
	
	return CChildWnd::OnNcActivate( bActive );
}

LONG CPanelWnd::OnSetText(WPARAM wParam, LPARAM lParam)
{
	if ( m_pSkin )
	{
		BOOL bVisible = IsWindowVisible();
		if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
		LONG lResult = Default();
		if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );

		if ( m_pSkin ) m_pSkin->OnSetText( this );

		return lResult;
	}
	else if ( m_bPanelMode )
	{
		BOOL bVisible = IsWindowVisible();
		if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
		LONG lResult = Default();
		if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );

		CWindowDC dc( this );
		PaintCaption( dc );

		return lResult;
	}
	else
	{
		return Default();
	}
}

void CPanelWnd::PaintCaption(CDC& dc)
{
	CString strCaption;
	CRect rc, rcWnd;
	
	GetWindowRect( &rcWnd );
	rc.SetRect( 0, 0, rcWnd.Width(), CAPTION_HEIGHT );
	GetWindowText( strCaption );
	
	CDC* pBuffer = CoolInterface.GetBuffer( dc, rc.Size() );
	
	if ( ! CoolInterface.DrawWatermark( pBuffer, &rc, &Skin.m_bmPanelMark, 0, 0 ) )
	{
		pBuffer->FillSolidRect( &rc, Skin.m_crPanelBack );
	}
	
	int nIconY = rc.Height() / 2 - 8;
	DrawIconEx( pBuffer->GetSafeHdc(), 4, nIconY,
		GetIcon( FALSE ), 16, 16, 0, NULL, DI_NORMAL );
	
	CFont* pOldFont	= (CFont*)pBuffer->SelectObject( &CoolInterface.m_fntCaption );
	CSize szCaption	= pBuffer->GetTextExtent( strCaption );
	
	pBuffer->SetBkMode( TRANSPARENT );
	
	if ( Skin.m_crPanelBorder != CLR_NONE )
	{
		pBuffer->SetTextColor( Skin.m_crPanelBorder );
		pBuffer->ExtTextOut( 8 + 16 - 1, rc.Height() / 2 - szCaption.cy / 2 - 1,
			ETO_CLIPPED, &rc, strCaption, NULL );
		pBuffer->ExtTextOut( 8 + 16 + 1, rc.Height() / 2 - szCaption.cy / 2 - 1,
			ETO_CLIPPED, &rc, strCaption, NULL );
		pBuffer->ExtTextOut( 8 + 16, rc.Height() / 2 - szCaption.cy / 2 - 1 - 1,
			ETO_CLIPPED, &rc, strCaption, NULL );
		pBuffer->ExtTextOut( 8 + 16, rc.Height() / 2 - szCaption.cy / 2 - 1 + 1,
			ETO_CLIPPED, &rc, strCaption, NULL );
	}
	
	pBuffer->SetTextColor( Skin.m_crPanelText );
	pBuffer->ExtTextOut( 8 + 16, rc.Height() / 2 - szCaption.cy / 2 - 1,
		ETO_CLIPPED, &rc, strCaption, NULL );
	
	if ( m_bPanelClose )
	{
		pBuffer->SelectObject( &theApp.m_gdiFont );
		CString strText	= _T("Close");
		CSize szText	= pBuffer->GetTextExtent( strText );
		
		m_rcClose.SetRect( rc.right - szText.cx - 8, rc.top, rc.right, rc.bottom );
		pBuffer->ExtTextOut( m_rcClose.left + 2,
			( m_rcClose.top + m_rcClose.bottom ) / 2 - szText.cy / 2 - 1,
			ETO_CLIPPED, &m_rcClose, strText, NULL );
		m_rcClose.OffsetRect( rcWnd.left, rcWnd.top );
	}
	
	pBuffer->SelectObject( pOldFont );
	
	dc.BitBlt( rc.left, rc.top, rc.Width(), rc.Height(), pBuffer, 0, 0, SRCCOPY );
}

BOOL CPanelWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	if ( nHitTest == HTCAPTION && m_bGroupMode && m_pGroupParent )
	{
		SetCursor( AfxGetApp()->LoadStandardCursor( IDC_SIZENS ) );
		return TRUE;
	}
	else if ( nHitTest == HTCAPTION && m_bPanelClose && m_pSkin == NULL )
	{
		CPoint pt;
		GetCursorPos( &pt );
		
		if ( m_rcClose.PtInRect( pt ) )
		{
			SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
			return TRUE;
		}
	}
	
	return CChildWnd::OnSetCursor( pWnd, nHitTest, message );
}

void CPanelWnd::OnNcLButtonDown(UINT nHitTest, CPoint point) 
{
	if ( nHitTest == HTCAPTION && m_bGroupMode && m_pGroupParent )
	{
		PanelSizeLoop();
		return;
	}
	else if ( nHitTest == HTCAPTION && m_bPanelClose && m_pSkin == NULL )
	{
		if ( m_rcClose.PtInRect( point ) )
		{
			PostMessage( WM_SYSCOMMAND, SC_CLOSE );
			return;
		}
	}

	CChildWnd::OnNcLButtonDown( nHitTest, point );
}

void CPanelWnd::PanelSizeLoop()
{
	MSG* pMsg = &AfxGetThreadState()->m_msgCur;

	float nOffset = 10;
	CPoint point;
	CRect rcMDI;
		
	SendMessage( WM_ENTERSIZEMOVE );

	GetParent()->GetWindowRect( &rcMDI );
	GetParent()->SetCapture();
	ClipCursor( &rcMDI );
	
	while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
	{
		while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) );

		if ( ! AfxGetThread()->PumpMessage() )
		{
			AfxPostQuitMessage( 0 );
			break;
		}

		GetCursorPos( &point );
		if ( point.y < rcMDI.top ) point.y = rcMDI.top;
		if ( point.y > rcMDI.bottom ) point.y = rcMDI.bottom;

		float nSplitter = (float)( point.y - rcMDI.top ) / (float)rcMDI.Height();

		if ( nOffset == 10 ) nOffset = m_pGroupParent->m_nGroupSize - nSplitter;
		nSplitter += nOffset;

		if ( nSplitter < 0.1f ) nSplitter = 0.1f;
		if ( nSplitter > 0.9f ) nSplitter = 0.9f;

		if ( nSplitter >= 0.47f && nSplitter <= 0.53f ) nSplitter = 0.5f;

		if ( nSplitter != m_pGroupParent->m_nGroupSize )
		{
			m_pGroupParent->m_nGroupSize = nSplitter;
			GetParent()->SendMessage( WM_SIZE, 1982 );
		}
	}

	ReleaseCapture();
	ClipCursor( NULL );
	SendMessage( WM_EXITSIZEMOVE );
}

⌨️ 快捷键说明

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