📄 wndsearch.cpp
字号:
//
// WndSearch.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 "QuerySearch.h"
#include "QueryHit.h"
#include "MatchObjects.h"
#include "Network.h"
#include "Packet.h"
#include "Schema.h"
#include "SchemaCache.h"
#include "ManagedSearch.h"
#include "CoolInterface.h"
#include "ShellIcons.h"
#include "Skin.h"
#include "SHA.h"
#include "XML.h"
#include "WndSearch.h"
#include "WndMain.h"
#include "DlgNewSearch.h"
#include "DlgHitColumns.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CSearchWnd, CBaseMatchWnd)
BEGIN_MESSAGE_MAP(CSearchWnd, CBaseMatchWnd)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_CONTEXTMENU()
ON_WM_TIMER()
ON_WM_NCLBUTTONUP()
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_SYSCOMMAND()
ON_WM_SETCURSOR()
ON_WM_LBUTTONDOWN()
ON_LBN_SELCHANGE(IDC_MATCHES, OnSelChangeMatches)
ON_UPDATE_COMMAND_UI(ID_SEARCH_SEARCH, OnUpdateSearchSearch)
ON_COMMAND(ID_SEARCH_SEARCH, OnSearchSearch)
ON_COMMAND(ID_SEARCH_CLEAR, OnSearchClear)
ON_UPDATE_COMMAND_UI(ID_SEARCH_STOP, OnUpdateSearchStop)
ON_COMMAND(ID_SEARCH_STOP, OnSearchStop)
ON_UPDATE_COMMAND_UI(ID_SEARCH_PANEL, OnUpdateSearchPanel)
ON_COMMAND(ID_SEARCH_PANEL, OnSearchPanel)
ON_UPDATE_COMMAND_UI(ID_SEARCH_CLEAR, OnUpdateSearchClear)
ON_UPDATE_COMMAND_UI(ID_SEARCH_DETAILS, OnUpdateSearchDetails)
ON_COMMAND(ID_SEARCH_DETAILS, OnSearchDetails)
ON_WM_MDIACTIVATE()
END_MESSAGE_MAP()
#define SIZE_INTERNAL 1982
#define PANEL_WIDTH 200
#define TOOLBAR_HEIGHT 28
#define STATUS_HEIGHT 24
#define SPLIT_SIZE 6
/////////////////////////////////////////////////////////////////////////////
// CSearchWnd construction
CSearchWnd::CSearchWnd(CQuerySearch* pSearch)
{
if ( pSearch != NULL )
{
m_pSearches.AddTail( new CManagedSearch( pSearch ) );
}
Create( IDR_SEARCHFRAME );
}
CSearchWnd::~CSearchWnd()
{
CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
for ( POSITION pos = m_pSearches.GetHeadPosition() ; pos ; )
{
delete (CManagedSearch*)m_pSearches.GetNext( pos );
}
m_pSearches.RemoveAll();
}
/////////////////////////////////////////////////////////////////////////////
// CSearchWnd message handlers
int CSearchWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if ( CBaseMatchWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
m_wndPanel.Create( this );
m_wndDetails.Create( this );
CQuerySearch* pSearch = GetLastSearch();
if ( pSearch && pSearch->m_pSchema != NULL )
{
CPtrList pColumns;
CSchemaColumnsDlg::LoadColumns( pSearch->m_pSchema, &pColumns );
m_wndList.SelectSchema( pSearch->m_pSchema, &pColumns );
}
else if ( CSchema* pSchema = SchemaCache.Get( Settings.Search.BlankSchemaURI ) )
{
CPtrList pColumns;
CSchemaColumnsDlg::LoadColumns( pSchema, &pColumns );
m_wndList.SelectSchema( pSchema, &pColumns );
}
m_nCacheHubs = 0;
m_nCacheLeaves = 0;
m_bPanel = Settings.Search.SearchPanel;
m_bDetails = Settings.Search.DetailPanelVisible;
m_nDetails = Settings.Search.DetailPanelSize;
m_bPaused = TRUE;
m_bSetFocus = TRUE;
LoadState( _T("CSearchWnd"), TRUE );
ExecuteSearch();
if ( pSearch == NULL ) m_wndPanel.ShowSearch( NULL );
OnSkinChange();
PostMessage( WM_TIMER, 1 );
return 0;
}
void CSearchWnd::OnDestroy()
{
CQuerySearch* pSearch = GetLastSearch();
if ( pSearch && pSearch->m_pSchema == NULL )
{
if ( m_wndList.m_pSchema != NULL )
{
Settings.Search.BlankSchemaURI = m_wndList.m_pSchema->m_sURI;
}
else
{
Settings.Search.BlankSchemaURI.Empty();
}
}
SaveState( _T("CSearchWnd") );
CBaseMatchWnd::OnDestroy();
}
void CSearchWnd::OnSize(UINT nType, int cx, int cy)
{
if ( nType != SIZE_INTERNAL ) CPanelWnd::OnSize( nType, cx, cy );
CRect rc;
GetClientRect( &rc );
if ( m_bPanel )
{
m_wndPanel.SetWindowPos( NULL, rc.left, rc.top, PANEL_WIDTH, rc.Height(),
SWP_NOZORDER|SWP_SHOWWINDOW );
rc.left += PANEL_WIDTH;
}
else if ( m_wndPanel.IsWindowVisible() )
{
m_wndPanel.ShowWindow( SW_HIDE );
}
if ( ! m_bPaused ) rc.top += STATUS_HEIGHT;
m_wndToolBar.SetWindowPos( NULL, rc.left, rc.bottom - TOOLBAR_HEIGHT, rc.Width(), TOOLBAR_HEIGHT, SWP_NOZORDER );
rc.bottom -= TOOLBAR_HEIGHT;
if ( m_bDetails )
{
m_wndDetails.SetWindowPos( NULL, rc.left, rc.bottom - m_nDetails, rc.Width(),
m_nDetails, SWP_NOZORDER|SWP_SHOWWINDOW );
rc.bottom -= m_nDetails + SPLIT_SIZE;
}
else if ( m_wndDetails.IsWindowVisible() )
{
m_wndDetails.ShowWindow( SW_HIDE );
}
m_wndList.SetWindowPos( NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER );
Invalidate();
}
void CSearchWnd::OnSkinChange()
{
CBaseMatchWnd::OnSkinChange();
m_wndToolBar.Clear();
if ( ! Skin.CreateToolBar( m_bPanel ? _T("CSearchWnd.Panel") : _T("CSearchWnd.Full"), &m_wndToolBar ) )
{
Skin.CreateToolBar( _T("CSearchWnd"), &m_wndToolBar );
}
OnSize( SIZE_INTERNAL, 0, 0 );
UpdateMessages();
m_wndPanel.OnSkinChange();
}
void CSearchWnd::OnContextMenu(CWnd* pWnd, CPoint point)
{
if ( m_bContextMenu )
{
TrackPopupMenu( _T("CSearchWnd"), point, ID_SEARCH_DOWNLOAD );
}
else
{
CBaseMatchWnd::OnContextMenu( pWnd, point );
}
}
void CSearchWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
{
CBaseMatchWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
if ( bActivate )
{
if ( m_pMatches->m_nFiles > 0 )
m_wndList.SetFocus();
else if ( m_wndPanel.IsWindowVisible() )
m_wndPanel.SetSearchFocus();
else if ( m_wndList.IsWindowVisible() )
m_wndList.SetFocus();
}
}
void CSearchWnd::OnPaint()
{
CPaintDC dc( this );
CRect rcClient;
GetClientRect( &rcClient );
rcClient.bottom -= TOOLBAR_HEIGHT;
if ( m_wndDetails.IsWindowVisible() )
{
CRect rcBar( rcClient.left,
rcClient.bottom - m_nDetails - SPLIT_SIZE,
rcClient.right,
rcClient.bottom - m_nDetails );
if ( m_bPanel ) rcBar.left += PANEL_WIDTH;
dc.FillSolidRect( rcBar.left, rcBar.top, rcBar.Width(), 1, GetSysColor( COLOR_BTNFACE ) );
dc.FillSolidRect( rcBar.left, rcBar.top + 1, rcBar.Width(), 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
dc.FillSolidRect( rcBar.left, rcBar.bottom - 1, rcBar.Width(), 1, GetSysColor( COLOR_3DSHADOW ) );
dc.FillSolidRect( rcBar.left, rcBar.top + 2, rcBar.Width(), rcBar.Height() - 3,
GetSysColor( COLOR_BTNFACE ) );
}
if ( m_bPaused ) return;
CRect rc( &rcClient );
rc.bottom = rc.top + STATUS_HEIGHT;
int nTop = rc.top + 4;
if ( m_bPanel )
{
rc.left += PANEL_WIDTH;
rc.bottom --;
dc.FillSolidRect( rc.left, rc.bottom, rc.Width(), 1, RGB( 255, 255, 255 ) );
dc.Draw3dRect( &rc,
CCoolInterface::CalculateColour( Skin.m_crBannerBack, RGB(255,255,255), 100 ),
CCoolInterface::CalculateColour( Skin.m_crBannerBack, 0, 150 ) );
rc.DeflateRect( 1, 1 );
nTop --;
}
ShellIcons.Draw( &dc, SHI_SEARCH, 16, rc.left + 4, nTop, Skin.m_crBannerBack );
dc.ExcludeClipRect( rc.left + 4, nTop, rc.left + 4 + 16, nTop + 16 );
CFont* pFont = (CFont*)dc.SelectObject( &CoolInterface.m_fntNormal );
CString str;
LoadString( str, IDS_SEARCH_ACTIVE );
dc.SetBkColor( Skin.m_crBannerBack );
dc.SetTextColor( Skin.m_crBannerText );
dc.ExtTextOut( rc.left + 8 + 16, nTop + 1, ETO_CLIPPED|ETO_OPAQUE,
&rc, str, NULL );
dc.SelectObject( pFont );
}
BOOL CSearchWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if ( m_wndDetails.IsWindowVisible() )
{
CRect rcClient, rc;
CPoint point;
GetCursorPos( &point );
GetClientRect( &rcClient );
ClientToScreen( &rcClient );
rc.SetRect( rcClient.left,
rcClient.bottom - TOOLBAR_HEIGHT - m_nDetails - SPLIT_SIZE,
rcClient.right,
rcClient.bottom - TOOLBAR_HEIGHT - m_nDetails );
if ( m_bPanel ) rc.left += PANEL_WIDTH;
if ( rc.PtInRect( point ) )
{
SetCursor( AfxGetApp()->LoadStandardCursor( IDC_SIZENS ) );
return TRUE;
}
}
return CBaseMatchWnd::OnSetCursor( pWnd, nHitTest, message );
}
void CSearchWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rcClient, rc;
GetClientRect( &rcClient );
rc.SetRect( rcClient.left,
rcClient.bottom - TOOLBAR_HEIGHT - m_nDetails - SPLIT_SIZE,
rcClient.right,
rcClient.bottom - TOOLBAR_HEIGHT - m_nDetails );
if ( m_bPanel ) rc.left += PANEL_WIDTH;
if ( m_wndDetails.IsWindowVisible() && rc.PtInRect( point ) )
{
DoSizeDetails();
return;
}
CBaseMatchWnd::OnLButtonDown( nFlags, point );
}
BOOL CSearchWnd::DoSizeDetails()
{
MSG* pMsg = &AfxGetThreadState()->m_msgCur;
CRect rcClient;
CPoint point;
GetClientRect( &rcClient );
if ( m_bPanel ) rcClient.left += PANEL_WIDTH;
if ( ! m_bPaused ) rcClient.top += STATUS_HEIGHT;
rcClient.bottom -= TOOLBAR_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_nDetails - nSplit;
nSplit += nOffset;
if ( nSplit < 8 )
nSplit = 0;
if ( nSplit > rcClient.Height() - SPLIT_SIZE - 8 )
nSplit = rcClient.Height() - SPLIT_SIZE;
if ( nSplit != m_nDetails )
{
m_nDetails = nSplit;
Settings.Search.DetailPanelSize = nSplit;
OnSize( SIZE_INTERNAL, 0, 0 );
Invalidate();
}
}
ReleaseCapture();
ClipCursor( NULL );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -