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

CtrlHomeView.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlHomeView.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 "CtrlHomeView.h"
00026 #include "RichElement.h"
00027 #include "Skin.h"
00028 
00029 #include "Network.h"
00030 #include "Datagrams.h"
00031 #include "Neighbour.h"
00032 #include "Neighbours.h"
00033 #include "VersionChecker.h"
00034 
00035 #ifdef _DEBUG
00036 #define new DEBUG_NEW
00037 #undef THIS_FILE
00038 static char THIS_FILE[] = __FILE__;
00039 #endif
00040 
00041 BEGIN_MESSAGE_MAP(CHomeViewCtrl, CRichViewCtrl)
00042         ON_WM_CREATE()
00043         ON_WM_DESTROY()
00044         ON_WM_SETFOCUS()
00045 END_MESSAGE_MAP()
00046 
00047 #define GROUP_DISCONNECTED              1
00048 #define GROUP_CONNECTED                 2
00049 #define GROUP_UPGRADE                   3
00050 #define GROUP_FIREWALLED                4
00051 #define GROUP_REMOTE                    5
00052 
00053 
00055 // CHomeViewCtrl construction
00056 
00057 CHomeViewCtrl::CHomeViewCtrl()
00058 {
00059         m_peHeader = m_peSearch = m_peUpgrade = NULL;
00060 }
00061 
00062 CHomeViewCtrl::~CHomeViewCtrl()
00063 {
00064 }
00065 
00067 // CHomeViewCtrl system message handlers
00068 
00069 BOOL CHomeViewCtrl::Create(const RECT& rect, CWnd* pParentWnd)
00070 {
00071         return CRichViewCtrl::Create( WS_CHILD|WS_CLIPCHILDREN, rect, pParentWnd, IDC_HOME_VIEW );
00072 }
00073 
00074 int CHomeViewCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
00075 {
00076         if ( CRichViewCtrl::OnCreate( lpCreateStruct ) == -1 ) return -1;
00077 
00078         m_wndSearch.Create( this, IDC_HOME_SEARCH );
00079 
00080         Setup();
00081 
00082         return 0;
00083 }
00084 
00085 void CHomeViewCtrl::OnDestroy()
00086 {
00087         CRichViewCtrl::OnDestroy();
00088 }
00089 
00091 // CHomeViewCtrl operations
00092 
00093 void CHomeViewCtrl::Setup()
00094 {
00095         m_pDocument.Clear();
00096         m_peHeader = m_peSearch = m_peUpgrade = m_peRemote1 = m_peRemote2 = NULL;
00097 
00098         Skin.GetWatermark( &m_bmHeader1, _T("CHomeViewCtrl.Header1") );
00099         Skin.GetWatermark( &m_bmHeader2, _T("CHomeViewCtrl.Header2") );
00100 
00101         CXMLElement* pXML = Skin.GetDocument( _T("CHomeViewCtrl") );
00102         CMapStringToPtr pMap;
00103 
00104         if ( pXML == NULL || ! m_pDocument.LoadXML( pXML, &pMap ) )
00105         {
00106                 SetDocument( &m_pDocument );
00107                 m_wndSearch.Setup( m_pDocument.m_crBackground );
00108                 return;
00109         }
00110 
00111         pMap.Lookup( _T("Header"), (void*&)m_peHeader );
00112         pMap.Lookup( _T("SearchBox"), (void*&)m_peSearch );
00113         pMap.Lookup( _T("Upgrade"), (void*&)m_peUpgrade );
00114         pMap.Lookup( _T("RemoteAccessURL1"), (void*&)m_peRemote1 );
00115         pMap.Lookup( _T("RemoteAccessURL2"), (void*&)m_peRemote2 );
00116 
00117         m_wndSearch.Setup( m_pDocument.m_crBackground );
00118 
00119         SetDocument( &m_pDocument );
00120         Update();
00121 }
00122 
00123 void CHomeViewCtrl::Update()
00124 {
00125         BOOL bConnected = Network.IsConnected();
00126         m_pDocument.ShowGroup( GROUP_DISCONNECTED, ! bConnected );
00127         m_pDocument.ShowGroup( GROUP_CONNECTED, bConnected );
00128 
00129         BOOL bOnG2 = bConnected && Settings.Gnutella2.EnableToday && ( Neighbours.GetCount( PROTOCOL_G2, nrsConnected, -1 ) >= Settings.Gnutella2.NumHubs );
00130         m_pDocument.ShowGroup( GROUP_FIREWALLED, bOnG2 && ! Datagrams.IsStable() );
00131 
00132         if ( VersionChecker.m_bUpgrade )
00133         {
00134                 if ( m_peUpgrade ) m_peUpgrade->SetText( VersionChecker.m_sUpgradePrompt );
00135                 m_pDocument.ShowGroup( GROUP_UPGRADE, TRUE );
00136         }
00137         else
00138         {
00139                 m_pDocument.ShowGroup( GROUP_UPGRADE, FALSE );
00140         }
00141 
00142         if ( Settings.Remote.Enable && ! Settings.Remote.Username.IsEmpty() &&
00143                  ! Settings.Remote.Password.IsEmpty() && Network.IsListening() )
00144         {
00145                 CString strURL;
00146 
00147                 if ( m_peRemote1 )
00148                 {
00149                         strURL.Format( _T("http://%s:%i/remote/"),
00150                                 (LPCTSTR)CString( inet_ntoa( Network.m_pHost.sin_addr ) ),
00151                                 (int)ntohs( Network.m_pHost.sin_port ) );
00152                         m_peRemote1->SetText( theApp.m_bRTL ? _T("\x202A") + strURL : strURL );
00153                         m_peRemote1->m_sLink = strURL;
00154                 }
00155                 if ( m_peRemote2 )
00156                 {
00157                         strURL.Format( _T("http://localhost:%i/remote/"),
00158                                 (int)ntohs( Network.m_pHost.sin_port ) );
00159                         m_peRemote2->SetText( theApp.m_bRTL ? _T("\x202A") + strURL : strURL );
00160                         m_peRemote2->m_sLink = strURL;
00161                 }
00162 
00163                 m_pDocument.ShowGroup( GROUP_REMOTE, TRUE );
00164         }
00165         else
00166         {
00167                 m_pDocument.ShowGroup( GROUP_REMOTE, FALSE );
00168         }
00169 
00170         InvalidateIfModified();
00171 }
00172 
00174 // CHomeViewCtrl layout event
00175 
00176 void CHomeViewCtrl::OnLayoutComplete()
00177 {
00178         if ( m_peSearch != NULL && ( m_peSearch->m_nFlags & retfHidden ) == 0 )
00179         {
00180                 CRect rcClient, rcAnchor( 0, 0, 0, 0 );
00181 
00182                 GetClientRect( &rcClient );
00183                 GetElementRect( m_peSearch, &rcAnchor );
00184                 rcAnchor.OffsetRect( 0, -GetScrollPos( SB_VERT ) );
00185 
00186                 rcAnchor.left = rcClient.left + 55;
00187                 rcAnchor.right = rcClient.right - 55;
00188 
00189                 BOOL bShowed = m_wndSearch.IsWindowVisible() == FALSE;
00190 
00191                 m_wndSearch.SetWindowPos( NULL, rcAnchor.left, rcAnchor.top, rcAnchor.Width(), rcAnchor.Height(), SWP_SHOWWINDOW|SWP_NOACTIVATE );
00192 
00193                 if ( bShowed && GetFocus() == this ) m_wndSearch.SetFocus();
00194         }
00195         else
00196         {
00197                 m_wndSearch.ShowWindow( SW_HIDE );
00198         }
00199 }
00200 
00202 // CHomeViewCtrl paint event
00203 
00204 void CHomeViewCtrl::OnPaintBegin(CDC* pDC)
00205 {
00206         if ( m_peHeader != NULL && ( m_peHeader->m_nFlags & retfHidden ) == 0 && m_bmHeader1.m_hObject != NULL )
00207         {
00208                 CRect rcAnchor( 0, 0, 0, 0 );
00209                 GetElementRect( m_peHeader, &rcAnchor );
00210 
00211                 CRect rcClient;
00212                 GetClientRect( &rcClient );
00213                 rcAnchor.left = rcClient.left;
00214                 rcAnchor.right = rcClient.right;
00215 
00216                 CDC dcHeader;
00217                 dcHeader.CreateCompatibleDC( pDC );
00218                 CBitmap* pbmOld = (CBitmap*)dcHeader.SelectObject( &m_bmHeader1 );
00219 
00220                 BITMAP pHeader1;
00221                 m_bmHeader1.GetBitmap( &pHeader1 );
00222 
00223                 pDC->BitBlt( rcAnchor.left, rcAnchor.top, min( rcAnchor.Width(), int(pHeader1.bmWidth) ),
00224                         min( rcAnchor.Height(), int(pHeader1.bmHeight) ), &dcHeader, 0, 0, SRCCOPY );
00225 
00226                 CRect rcMark( &rcAnchor );
00227                 rcMark.left += pHeader1.bmWidth;
00228 
00229                 if ( m_bmHeader2.m_hObject != NULL && pDC->RectVisible( &rcMark ) )
00230                 {
00231                         BITMAP pHeader2;
00232                         m_bmHeader2.GetBitmap( &pHeader2 );
00233                         dcHeader.SelectObject( &m_bmHeader2 );
00234 
00235                         while ( rcMark.left < rcMark.right )
00236                         {
00237                                 pDC->BitBlt( rcMark.left, rcMark.top, min( rcMark.Width(), int(pHeader2.bmWidth) ),
00238                                         min( rcMark.Height(), int(pHeader2.bmHeight) ), &dcHeader, 0, 0, SRCCOPY );
00239                                 rcMark.left += pHeader2.bmWidth;
00240                         }
00241                 }
00242 
00243                 dcHeader.SelectObject( pbmOld );
00244                 dcHeader.DeleteDC();
00245 
00246                 pDC->ExcludeClipRect( &rcAnchor );
00247         }
00248 }
00249 
00251 // CHomeViewCtrl other event handlers
00252 
00253 void CHomeViewCtrl::OnVScrolled()
00254 {
00255         OnLayoutComplete();
00256 }
00257 
00258 void CHomeViewCtrl::OnSetFocus(CWnd* pOldWnd)
00259 {
00260         CRichViewCtrl::OnSetFocus( pOldWnd );
00261         if ( m_wndSearch.IsWindowVisible() ) m_wndSearch.SetFocus();
00262 }

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