Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

WndSearchPad.cpp

Go to the documentation of this file.
00001 //
00002 // WndSearchPad.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "CoolInterface.h"
00026 #include "QuerySearch.h"
00027 #include "Network.h"
00028 #include "Schema.h"
00029 #include "Skin.h"
00030 #include "XML.h"
00031 
00032 #include "WndSearchPad.h"
00033 #include "WndSearch.h"
00034 
00035 #ifdef _DEBUG
00036 #define new DEBUG_NEW
00037 #undef THIS_FILE
00038 static char THIS_FILE[] = __FILE__;
00039 #endif
00040 
00041 IMPLEMENT_DYNCREATE(CSearchPadWnd, CPanelWnd)
00042 
00043 BEGIN_MESSAGE_MAP(CSearchPadWnd, CPanelWnd)
00044         //{{AFX_MSG_MAP(CSearchPadWnd)
00045         ON_WM_CREATE()
00046         ON_WM_DESTROY()
00047         ON_WM_SIZE()
00048         ON_WM_PAINT()
00049         ON_CBN_SELCHANGE(IDC_SEARCH_SCHEMAS, OnSelChangeSchemas)
00050         ON_BN_CLICKED(IDC_SEARCH_CREATE, OnSearchCreate)
00051         ON_WM_MDIACTIVATE()
00052         //}}AFX_MSG_MAP
00053 END_MESSAGE_MAP()
00054 
00055 
00057 // CSearchPadWnd construction
00058 
00059 CSearchPadWnd::CSearchPadWnd() : CPanelWnd( TRUE, FALSE )
00060 {
00061         Create( IDR_SEARCHPADFRAME );
00062 }
00063 
00064 CSearchPadWnd::~CSearchPadWnd()
00065 {
00066 }
00067 
00069 // CSearchPadWnd system message handlers
00070 
00071 int CSearchPadWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00072 {
00073         if ( CPanelWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00074         
00075         CRect rc( 0, 0, 0, 0 );
00076 
00077         if ( ! m_wndText.Create( WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|WS_TABSTOP|WS_GROUP, rc,
00078                 this, IDC_SEARCH_TEXT ) ) return -1;
00079 
00080         m_wndText.SetFont( &theApp.m_gdiFont );
00081         m_wndText.ModifyStyleEx( 0, WS_EX_CLIENTEDGE );
00082 
00083         if ( ! m_wndSchema.Create( WS_VISIBLE|WS_TABSTOP, rc, this, IDC_SEARCH_SCHEMAS ) )
00084                 return -1;
00085         
00086         m_wndSchema.SetDroppedWidth( 200 );
00087         LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
00088         m_wndSchema.Load( Settings.Search.LastSchemaURI );
00089 
00090         if ( ! m_wndData.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, rc, this,
00091                 IDC_SEARCH_DATA ) ) return -1;
00092 
00093         CString strCaption;
00094         LoadString( strCaption, IDS_SEARCH_PANEL_START );
00095         m_wndSearch.Create( rc, this, IDC_SEARCH_CREATE );
00096         m_wndSearch.SetWindowText( strCaption );
00097         m_wndSearch.SetIcon( CoolInterface.ExtractIcon( ID_SEARCH_SEARCH ) );
00098         m_wndSearch.SetHandCursor( TRUE );
00099 
00100         m_pFont.CreateFont( -(theApp.m_nDefaultFontSize + 9), 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
00101                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
00102                 DEFAULT_PITCH|FF_DONTCARE, theApp.m_sDefaultFont );
00103 
00104         LoadState();
00105 
00106         OnSelChangeSchemas();
00107         
00108         return 0;
00109 }
00110 
00111 void CSearchPadWnd::OnDestroy() 
00112 {
00113         SaveState();
00114         CPanelWnd::OnDestroy();
00115 }
00116 
00117 void CSearchPadWnd::OnSkinChange()
00118 {
00119         CString strCaption;
00120         LoadString( strCaption, IDS_SEARCH_PANEL_START );
00121         m_wndSearch.SetWindowText( strCaption );
00122         LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
00123 
00124         CPanelWnd::OnSkinChange();
00125 }
00126 
00128 // CSearchPadWnd display message handlers
00129 
00130 void CSearchPadWnd::OnSize(UINT nType, int cx, int cy) 
00131 {
00132         CPanelWnd::OnSize( nType, cx, cy );
00133         
00134         CRect rcClient( 0, 0, cx, cy );
00135         CRect rcItem;
00136         
00137         if ( rcClient.Width() > 640 )
00138                 rcClient.DeflateRect( rcClient.Width() / 2 - 320, 0 );
00139         if ( rcClient.Height() > 480 )
00140                 rcClient.DeflateRect( 0, rcClient.Height() / 2 - 240 );
00141 
00142         rcClient.DeflateRect( 72, 64 );
00143         rcClient.top += 8;
00144         
00145         rcItem.SetRect( rcClient.left, rcClient.top, rcClient.right - 104, rcClient.top + 19 );
00146         m_wndText.MoveWindow( &rcItem );
00147 
00148         rcItem.SetRect( rcClient.right - 92, rcClient.top - 2, rcClient.right, rcClient.top + 22 );
00149         m_wndSearch.MoveWindow( &rcItem );
00150         
00151         rcClient.top += 32;
00152 
00153         rcItem.SetRect( rcClient.right - 104 - 128, rcClient.top, rcClient.right - 104, rcClient.top + 256 );
00154         rcItem.left = max( rcItem.left, rcClient.left );
00155         m_wndSchema.MoveWindow( &rcItem );
00156 
00157         rcClient.top += 40;
00158 
00159         rcItem.CopyRect( &rcClient );
00160         m_wndData.MoveWindow( &rcItem );
00161 }
00162 
00163 void CSearchPadWnd::OnPaint() 
00164 {
00165         CRect rcClient, rcItem;
00166         CPaintDC dc( this );
00167         CString str;
00168         
00169         GetClientRect( &rcClient );
00170 
00171         if ( rcClient.Width() > 640 )
00172                 rcClient.DeflateRect( rcClient.Width() / 2 - 320, 0 );
00173         if ( rcClient.Height() > 480 )
00174                 rcClient.DeflateRect( 0, rcClient.Height() / 2 - 240 );
00175         
00176         rcClient.DeflateRect( 16, 16 );
00177 
00178         // draw image
00179 
00180         rcClient.DeflateRect( 56, 0 );
00181 
00182         CFont* pOldFont = (CFont*)dc.SelectObject( &m_pFont );
00183         dc.SetBkMode( OPAQUE );
00184         dc.SetBkColor( CoolInterface.m_crWindow );
00185         dc.SetTextColor( Skin.m_crPanelBack );
00186 
00187         LoadString( str, IDS_SEARCH_PAD_HEADER );
00188 
00189         rcItem.SetRect( rcClient.left, rcClient.top, rcClient.right, rcClient.top + 26 );
00190         dc.ExtTextOut( rcItem.left + 2, rcItem.top + 2, ETO_CLIPPED|ETO_OPAQUE,
00191                 &rcItem, str, NULL );
00192         dc.ExcludeClipRect( &rcItem );
00193         
00194         rcClient.DeflateRect( 0, 26 );
00195         
00196         LoadString( str, IDS_SEARCH_PAD_WORDS );
00197 
00198         rcItem.SetRect( rcClient.left, rcClient.top, rcClient.right, rcClient.top + 16 );
00199         dc.SetTextColor( 0 );
00200         dc.SelectObject( &CoolInterface.m_fntBold );
00201         dc.ExtTextOut( rcItem.left + 2, rcItem.top + 2, ETO_CLIPPED|ETO_OPAQUE,
00202                 &rcItem, str, NULL );
00203         dc.ExcludeClipRect( &rcItem );
00204 
00205         rcClient.DeflateRect( 0, 22 );
00206         rcClient.top += 8;
00207         rcClient.top += 32;
00208 
00209         rcItem.SetRect( rcClient.left, rcClient.top,
00210                 rcClient.right - 104 - 128 - 4, rcClient.top + 22 );
00211         
00212         if ( rcItem.right > rcItem.left )
00213         {
00214                 LoadString( str, IDS_SEARCH_PAD_TYPE );
00215                 CSize sz = dc.GetTextExtent( str );
00216                 dc.ExtTextOut( rcItem.right - sz.cx, ( rcItem.top + rcItem.bottom ) / 2 - sz.cy / 2,
00217                         ETO_CLIPPED|ETO_OPAQUE, &rcItem, str, NULL );
00218                 dc.ExcludeClipRect( &rcItem );
00219         }
00220 
00221         dc.SelectObject( pOldFont );
00222         GetClientRect( &rcClient );
00223         dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
00224 }
00225 
00227 // CSearchPadWnd search interface
00228 
00229 CQuerySearch* CSearchPadWnd::GetSearch()
00230 {
00231         CQuerySearch* pSearch = new CQuerySearch();
00232         
00233         m_wndText.GetWindowText( pSearch->m_sSearch );
00234         pSearch->m_sSearch.TrimLeft();
00235         pSearch->m_sSearch.TrimRight();
00236         
00237         if ( CSchema* pSchema = m_wndSchema.GetSelected() )
00238         {
00239                 pSearch->m_pSchema      = pSchema;
00240                 pSearch->m_pXML         = pSchema->Instantiate();
00241                 
00242                 m_wndData.UpdateData(
00243                         pSearch->m_pXML->AddElement( pSchema->m_sSingular ), TRUE );
00244                 
00245                 Settings.Search.LastSchemaURI = pSchema->m_sURI;
00246         }
00247         else
00248         {
00249                 Settings.Search.LastSchemaURI.Empty();
00250         }
00251         
00252         if ( ! pSearch->CheckValid() )
00253         {
00254                 delete pSearch;
00255                 return NULL;
00256         }
00257         
00258         return pSearch;
00259 }
00260 
00261 void CSearchPadWnd::ClearSearch()
00262 {
00263         m_wndText.SetWindowText( _T("") );
00264 
00265         CSchema* pSchema = m_wndSchema.GetSelected();
00266         m_wndData.SetSchema( pSchema, TRUE );
00267 }
00268 
00270 // CSearchPadWnd control message handlers
00271 
00272 void CSearchPadWnd::OnSelChangeSchemas()
00273 {
00274         CSchema* pSchema = m_wndSchema.GetSelected();
00275         m_wndData.SetSchema( pSchema, TRUE );
00276         m_wndData.ShowWindow( pSchema != NULL ? SW_SHOW : SW_HIDE );
00277 }
00278 
00279 void CSearchPadWnd::OnSearchCreate()
00280 {
00281         if ( ! Network.IsWellConnected() ) Network.Connect( TRUE );
00282         
00283         CQuerySearch* pSearch = GetSearch();
00284         if ( NULL == pSearch ) return;
00285         
00286         ClearSearch();
00287         
00288         new CSearchWnd( pSearch );
00289         
00290         PostMessage( WM_CLOSE );
00291 }
00292 
00293 void CSearchPadWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd) 
00294 {
00295         CPanelWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
00296         if ( bActivate ) m_wndText.SetFocus();
00297 }
00298 
00299 BOOL CSearchPadWnd::PreTranslateMessage(MSG* pMsg) 
00300 {
00301         if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
00302         {
00303                 PostMessage( WM_COMMAND, IDC_SEARCH_CREATE );
00304                 return TRUE;
00305         }
00306         else if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB )
00307         {
00308                 if ( m_wndData.OnTab() ) return TRUE;
00309         }
00310         
00311         return CPanelWnd::PreTranslateMessage( pMsg );
00312 }

Generated on Thu Dec 15 10:39:53 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2