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

WndMain.cpp

Go to the documentation of this file.
00001 //
00002 // WndMain.cpp
00003 //
00004 //      Date:                   "$Date: 2005/09/01 18:00:14 $"
00005 //      Revision:               "$Revision: 1.42 $"
00006 //  Last change by:     "$Author: rolandas $"
00007 //
00008 // Copyright (c) Shareaza Development Team, 2002-2005.
00009 // This file is part of SHAREAZA (www.shareaza.com)
00010 //
00011 // Shareaza is free software; you can redistribute it
00012 // and/or modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Shareaza is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with Shareaza; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //
00025 
00026 #include "StdAfx.h"
00027 #include "Shareaza.h"
00028 #include "Settings.h"
00029 #include "CoolInterface.h"
00030 #include "CoolMenu.h"
00031 #include "Network.h"
00032 #include "Handshake.h"
00033 #include "HostCache.h"
00034 #include "Neighbours.h"
00035 #include "Transfers.h"
00036 #include "Downloads.h"
00037 #include "Library.h"
00038 #include "LibraryBuilder.h"
00039 #include "Plugins.h"
00040 #include "QuerySearch.h"
00041 #include "VersionChecker.h"
00042 #include "GraphItem.h"
00043 #include "ShareazaURL.h"
00044 #include "ChatCore.h"
00045 #include "ChatSession.h"
00046 #include "Statistics.h"
00047 #include "Plugins.h"
00048 #include "BTInfo.h"
00049 #include "Skin.h"
00050 #include "SkinWindow.h"
00051 #include "Scheduler.h"
00052 #include "DlgHelp.h"
00053 #include "LibraryHistory.h"
00054 
00055 #include "WndMain.h"
00056 #include "WndChild.h"
00057 #include "WndSystem.h"
00058 #include "WndNeighbours.h"
00059 #include "WndTraffic.h"
00060 #include "WndDownloads.h"
00061 #include "WndUploads.h"
00062 #include "WndLibrary.h"
00063 #include "WndMedia.h"
00064 #include "WndHostCache.h"
00065 #include "WndDiscovery.h"
00066 #include "WndPacket.h"
00067 #include "WndSearchPad.h"
00068 #include "WndSearchMonitor.h"
00069 #include "WndHitMonitor.h"
00070 #include "WndSecurity.h"
00071 #include "WndSearch.h"
00072 #include "WndBrowseHost.h"
00073 #include "WndHome.h"
00074 #include "WndHelp.h"
00075 #include "WizardSheet.h"
00076 
00077 #include "DlgSettingsManager.h"
00078 #include "DlgShareManager.h"
00079 #include "DlgAbout.h"
00080 #include "DlgConnectTo.h"
00081 #include "DlgNewSearch.h"
00082 #include "DlgDownload.h"
00083 #include "DlgURLAction.h"
00084 #include "DlgUpgrade.h"
00085 #include "DlgDownloadMonitor.h"
00086 #include "DlgFilePreview.h"
00087 #include "DlgLanguage.h"
00088 #include "DlgProfileManager.h"
00089 #include "DlgWarnings.h"
00090 #include "DlgPromote.h"
00091 #include "DlgCloseMode.h"
00092 #include "DlgTorrentSeed.h"
00093 
00094 IMPLEMENT_DYNCREATE(CMainWnd, CMDIFrameWnd)
00095 
00096 BEGIN_INTERFACE_MAP(CMainWnd, CMDIFrameWnd)
00097     INTERFACE_PART(CMainWnd, IID_IDropTarget, DropTarget)
00098 END_INTERFACE_MAP()
00099 
00100 BEGIN_MESSAGE_MAP(CMainWnd, CMDIFrameWnd)
00101         ON_WM_CREATE()
00102         ON_WM_DESTROY()
00103         ON_WM_CLOSE()
00104         ON_WM_MEASUREITEM()
00105         ON_WM_DRAWITEM()
00106         ON_WM_INITMENUPOPUP()
00107         ON_WM_SYSCOLORCHANGE()
00108         ON_WM_TIMER()
00109         ON_WM_CONTEXTMENU()
00110         ON_WM_SYSCOMMAND()
00111         ON_WM_ACTIVATEAPP()
00112         ON_WM_ACTIVATE()
00113         ON_WM_NCLBUTTONDBLCLK()
00114         ON_WM_NCCALCSIZE()
00115         ON_WM_NCHITTEST()
00116         ON_WM_NCPAINT()
00117         ON_WM_NCACTIVATE()
00118         ON_WM_NCMOUSEMOVE()
00119         ON_WM_NCLBUTTONDOWN()
00120         ON_WM_NCLBUTTONUP()
00121         ON_WM_SIZE()
00122         ON_WM_GETMINMAXINFO()
00123         ON_WM_ENDSESSION()
00124         ON_WM_WINDOWPOSCHANGING()
00125         ON_MESSAGE(WM_WINSOCK, OnWinsock)
00126         ON_MESSAGE(WM_URL, OnHandleURL)
00127         ON_MESSAGE(WM_COLLECTION, OnHandleCollection)
00128         ON_MESSAGE(WM_VERSIONCHECK, OnVersionCheck)
00129         ON_MESSAGE(WM_OPENCHAT, OnOpenChat)
00130         ON_MESSAGE(WM_OPENSEARCH, OnOpenSearch)
00131         ON_MESSAGE(WM_TRAY, OnTray)
00132         ON_MESSAGE(WM_LOG, OnLog)
00133         ON_MESSAGE(WM_SKINCHANGED, OnSkinChanged)
00134         ON_MESSAGE(WM_AFX_SETMESSAGESTRING, OnSetMessageString)
00135         ON_MESSAGE(WM_SETTEXT, OnSetText)
00136         ON_MESSAGE(0x0319, OnMediaKey)
00137         ON_MESSAGE(WM_DEVMODECHANGE, OnDevModeChange)
00138         ON_MESSAGE(WM_DISPLAYCHANGE, OnDisplayChange)
00139         ON_UPDATE_COMMAND_UI_RANGE(ID_PLUGIN_FIRST, ID_PLUGIN_LAST, OnUpdatePluginRange)
00140         ON_UPDATE_COMMAND_UI(ID_VIEW_SYSTEM, OnUpdateViewSystem)
00141         ON_COMMAND(ID_VIEW_SYSTEM, OnViewSystem)
00142         ON_UPDATE_COMMAND_UI(ID_VIEW_NEIGHBOURS, OnUpdateViewNeighbours)
00143         ON_COMMAND(ID_VIEW_NEIGHBOURS, OnViewNeighbours)
00144         ON_UPDATE_COMMAND_UI(ID_NETWORK_CONNECT, OnUpdateNetworkConnect)
00145         ON_COMMAND(ID_NETWORK_CONNECT, OnNetworkConnect)
00146         ON_UPDATE_COMMAND_UI(ID_NETWORK_DISCONNECT, OnUpdateNetworkDisconnect)
00147         ON_COMMAND(ID_NETWORK_DISCONNECT, OnNetworkDisconnect)
00148         ON_UPDATE_COMMAND_UI(ID_VIEW_PACKETS, OnUpdateViewPackets)
00149         ON_COMMAND(ID_VIEW_PACKETS, OnViewPackets)
00150         ON_UPDATE_COMMAND_UI(ID_VIEW_HOSTS, OnUpdateViewHosts)
00151         ON_COMMAND(ID_VIEW_HOSTS, OnViewHosts)
00152         ON_COMMAND(ID_NETWORK_CONNECT_TO, OnNetworkConnectTo)
00153         ON_UPDATE_COMMAND_UI(ID_VIEW_SEARCH_MONITOR, OnUpdateViewSearchMonitor)
00154         ON_COMMAND(ID_VIEW_SEARCH_MONITOR, OnViewSearchMonitor)
00155         ON_COMMAND(ID_NETWORK_EXIT, OnNetworkExit)
00156         ON_UPDATE_COMMAND_UI(ID_NETWORK_SEARCH, OnUpdateNetworkSearch)
00157         ON_COMMAND(ID_NETWORK_SEARCH, OnNetworkSearch)
00158         ON_UPDATE_COMMAND_UI(ID_VIEW_RESULTS_MONITOR, OnUpdateViewResultsMonitor)
00159         ON_COMMAND(ID_VIEW_RESULTS_MONITOR, OnViewResultsMonitor)
00160         ON_UPDATE_COMMAND_UI(ID_NETWORK_CONNECT_TO, OnUpdateNetworkConnectTo)
00161         ON_UPDATE_COMMAND_UI(ID_VIEW_DOWNLOADS, OnUpdateViewDownloads)
00162         ON_COMMAND(ID_VIEW_DOWNLOADS, OnViewDownloads)
00163         ON_UPDATE_COMMAND_UI(ID_VIEW_LIBRARY, OnUpdateViewLibrary)
00164         ON_COMMAND(ID_VIEW_LIBRARY, OnViewLibrary)
00165         ON_UPDATE_COMMAND_UI(ID_VIEW_UPLOADS, OnUpdateViewUploads)
00166         ON_COMMAND(ID_VIEW_UPLOADS, OnViewUploads)
00167         ON_COMMAND(ID_TOOLS_SETTINGS, OnToolsSettings)
00168         ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
00169         ON_COMMAND(ID_HELP_HOMEPAGE, OnHelpHomepage)
00170         ON_COMMAND(ID_HELP_WEB_1, OnHelpWeb1)
00171         ON_COMMAND(ID_HELP_WEB_2, OnHelpWeb2)
00172         ON_COMMAND(ID_HELP_WEB_3, OnHelpWeb3)
00173         ON_COMMAND(ID_HELP_WEB_4, OnHelpWeb4)
00174         ON_COMMAND(ID_HELP_WEB_5, OnHelpWeb5)
00175         ON_COMMAND(ID_HELP_WEB_6, OnHelpWeb6)
00176         ON_COMMAND(ID_HELP_FAQ, OnHelpFaq)
00177         ON_COMMAND(ID_HELP_GUIDE, OnHelpGuide)
00178         ON_COMMAND(ID_HELP_FORUMS, OnHelpForums)
00179         ON_COMMAND(ID_HELP_UPDATE, OnHelpUpdate)
00180         ON_COMMAND(ID_HELP_ROUTER, OnHelpRouter)
00181         ON_COMMAND(ID_HELP_SECURITY, OnHelpSecurity)
00182         ON_COMMAND(ID_HELP_CODEC, OnHelpCodec)
00183         ON_UPDATE_COMMAND_UI(ID_VIEW_TRAFFIC, OnUpdateViewTraffic)
00184         ON_COMMAND(ID_VIEW_TRAFFIC, OnViewTraffic)
00185         ON_COMMAND(ID_WINDOW_CASCADE, OnWindowCascade)
00186         ON_COMMAND(ID_TOOLS_WIZARD, OnToolsWizard)
00187         ON_COMMAND(ID_TRAY_OPEN, OnTrayOpen)
00188         ON_UPDATE_COMMAND_UI(ID_NETWORK_AUTO_CLOSE, OnUpdateNetworkAutoClose)
00189         ON_COMMAND(ID_NETWORK_AUTO_CLOSE, OnNetworkAutoClose)
00190         ON_UPDATE_COMMAND_UI(ID_TOOLS_DOWNLOAD, OnUpdateToolsDownload)
00191         ON_COMMAND(ID_TOOLS_DOWNLOAD, OnToolsDownload)
00192         ON_UPDATE_COMMAND_UI(ID_VIEW_SECURITY, OnUpdateViewSecurity)
00193         ON_COMMAND(ID_VIEW_SECURITY, OnViewSecurity)
00194         ON_UPDATE_COMMAND_UI(ID_WINDOW_CASCADE, OnUpdateWindowCascade)
00195         ON_UPDATE_COMMAND_UI(ID_WINDOW_TILE_HORZ, OnUpdateWindowTileHorz)
00196         ON_UPDATE_COMMAND_UI(ID_WINDOW_TILE_VERT, OnUpdateWindowTileVert)
00197         ON_UPDATE_COMMAND_UI(ID_TAB_CONNECT, OnUpdateTabConnect)
00198         ON_COMMAND(ID_TAB_CONNECT, OnTabConnect)
00199         ON_UPDATE_COMMAND_UI(ID_TAB_NETWORK, OnUpdateTabNetwork)
00200         ON_COMMAND(ID_TAB_NETWORK, OnTabNetwork)
00201         ON_UPDATE_COMMAND_UI(ID_TAB_LIBRARY, OnUpdateTabLibrary)
00202         ON_COMMAND(ID_TAB_LIBRARY, OnTabLibrary)
00203         ON_UPDATE_COMMAND_UI(ID_TAB_TRANSFERS, OnUpdateTabTransfers)
00204         ON_COMMAND(ID_TAB_TRANSFERS, OnTabTransfers)
00205         ON_UPDATE_COMMAND_UI(ID_VIEW_TABBED, OnUpdateViewTabbed)
00206         ON_COMMAND(ID_VIEW_TABBED, OnViewTabbed)
00207         ON_UPDATE_COMMAND_UI(ID_VIEW_WINDOWED, OnUpdateViewWindowed)
00208         ON_COMMAND(ID_VIEW_WINDOWED, OnViewWindowed)
00209         ON_UPDATE_COMMAND_UI(ID_VIEW_DISCOVERY, OnUpdateViewDiscovery)
00210         ON_COMMAND(ID_VIEW_DISCOVERY, OnViewDiscovery)
00211         ON_UPDATE_COMMAND_UI(ID_TAB_HOME, OnUpdateTabHome)
00212         ON_COMMAND(ID_TAB_HOME, OnTabHome)
00213         ON_COMMAND(ID_TOOLS_RESKIN, OnToolsReskin)
00214         ON_UPDATE_COMMAND_UI(ID_WINDOW_TABBAR, OnUpdateWindowTabBar)
00215         ON_COMMAND(ID_WINDOW_TABBAR, OnWindowTabBar)
00216         ON_UPDATE_COMMAND_UI(ID_WINDOW_TOOLBAR, OnUpdateWindowToolBar)
00217         ON_COMMAND(ID_WINDOW_TOOLBAR, OnWindowToolBar)
00218         ON_UPDATE_COMMAND_UI(ID_WINDOW_MONITOR, OnUpdateWindowMonitor)
00219         ON_COMMAND(ID_WINDOW_MONITOR, OnWindowMonitor)
00220         ON_COMMAND(ID_NETWORK_BROWSE_TO, OnNetworkBrowseTo)
00221         ON_COMMAND(ID_TOOLS_SKIN, OnToolsSkin)
00222         ON_COMMAND(ID_TOOLS_LANGUAGE, OnToolsLanguage)
00223         ON_COMMAND(ID_TOOLS_SEEDTORRENT, OnToolsSeedTorrent)
00224         ON_COMMAND(ID_TOOLS_RESEEDTORRENT, OnToolsReseedTorrent)
00225         ON_COMMAND(ID_HELP_DISKSPACE, OnDiskSpace)
00226         ON_COMMAND(ID_HELP_DISKWRITEFAIL, OnDiskWriteFail)
00227         ON_COMMAND(ID_HELP_CONNECTIONFAIL, OnConnectionFail)
00228         ON_COMMAND(ID_HELP_DONKEYSERVERS, OnNoDonkeyServers)
00229         ON_UPDATE_COMMAND_UI(ID_VIEW_MEDIA, OnUpdateViewMedia)
00230         ON_COMMAND(ID_VIEW_MEDIA, OnViewMedia)
00231         ON_UPDATE_COMMAND_UI(ID_TAB_MEDIA, OnUpdateTabMedia)
00232         ON_COMMAND(ID_TAB_MEDIA, OnTabMedia)
00233         ON_UPDATE_COMMAND_UI(ID_TAB_SEARCH, OnUpdateTabSearch)
00234         ON_COMMAND(ID_TAB_SEARCH, OnTabSearch)
00235         ON_COMMAND(ID_TOOLS_PROFILE, OnToolsProfile)
00236         ON_UPDATE_COMMAND_UI(ID_VIEW_HELP, OnUpdateViewHelp)
00237         ON_COMMAND(ID_VIEW_HELP, OnViewHelp)
00238         ON_UPDATE_COMMAND_UI(ID_TAB_HELP, OnUpdateTabHelp)
00239         ON_COMMAND(ID_TAB_HELP, OnTabHelp)
00240         ON_COMMAND(ID_LIBRARY_FOLDERS, OnLibraryFolders)
00241         ON_COMMAND(ID_HELP_WARNINGS, OnHelpWarnings)
00242         ON_COMMAND(ID_HELP_PROMOTE, OnHelpPromote)
00243         ON_UPDATE_COMMAND_UI(ID_NETWORK_G2, OnUpdateNetworkG2)
00244         ON_COMMAND(ID_NETWORK_G2, OnNetworkG2)
00245         ON_UPDATE_COMMAND_UI(ID_NETWORK_G1, OnUpdateNetworkG1)
00246         ON_COMMAND(ID_NETWORK_G1, OnNetworkG1)
00247         ON_UPDATE_COMMAND_UI(ID_NETWORK_ED2K, OnUpdateNetworkED2K)
00248         ON_COMMAND(ID_NETWORK_ED2K, OnNetworkED2K)
00249         ON_UPDATE_COMMAND_UI(ID_VIEW_BASIC, OnUpdateViewBasic)
00250         ON_COMMAND(ID_VIEW_BASIC, OnViewBasic)
00251         ON_UPDATE_COMMAND_UI(ID_LIBRARY_HASH_PRIORITY, OnUpdateLibraryHashPriority)
00252         ON_COMMAND(ID_LIBRARY_HASH_PRIORITY, OnLibraryHashPriority)
00253         ON_UPDATE_COMMAND_UI(ID_WINDOW_NAVBAR, OnUpdateWindowNavBar)
00254         ON_COMMAND(ID_WINDOW_NAVBAR, OnWindowNavBar)
00255         ON_UPDATE_COMMAND_UI(ID_WINDOW_REMOTE, OnUpdateWindowRemote)
00256         ON_COMMAND(ID_WINDOW_REMOTE, OnWindowRemote)
00257         ON_COMMAND(ID_MONITOR_CLOSE, OnRemoteClose)
00258         ON_UPDATE_COMMAND_UI(ID_MEDIA_PLAY, OnUpdateMediaCommand)
00259         ON_UPDATE_COMMAND_UI(ID_MEDIA_ADD, OnUpdateMediaCommand)
00260         ON_UPDATE_COMMAND_UI(ID_MEDIA_ADD_FOLDER, OnUpdateMediaCommand)
00261         ON_COMMAND(ID_MEDIA_PLAY, OnMediaCommand)
00262         ON_COMMAND(ID_MEDIA_ADD, OnMediaCommand)
00263         ON_COMMAND(ID_MEDIA_ADD_FOLDER, OnMediaCommand)
00264 END_MESSAGE_MAP()
00265 
00266 
00268 // CMainWnd construction
00269 
00270 CMainWnd::CMainWnd()
00271 {
00272         theApp.m_pMainWnd = this;
00273 
00274         m_hInstance             = AfxGetResourceHandle();
00275         m_pSkin                 = NULL;
00276         m_pURLDialog    = NULL;
00277         m_tURLTime              = 0;
00278         
00279         LoadFrame( IDR_MAINFRAME, WS_OVERLAPPEDWINDOW );
00280         
00281         theApp.m_pSafeWnd = this;
00282 }
00283 
00284 CMainWnd::~CMainWnd()
00285 {
00286         theApp.m_pSafeWnd = NULL;
00287 }
00288 
00290 // CMainWnd create window
00291 
00292 BOOL CMainWnd::PreCreateWindow(CREATESTRUCT& cs) 
00293 {
00294         WNDCLASS wndcls;
00295         
00296         ZeroMemory( &wndcls, sizeof(WNDCLASS) );
00297         wndcls.style                    = CS_DBLCLKS;
00298         wndcls.lpfnWndProc              = AfxWndProc;
00299         wndcls.hInstance                = AfxGetInstanceHandle();
00300         wndcls.hIcon                    = theApp.LoadIcon( IDR_MAINFRAME );
00301         wndcls.hCursor                  = theApp.LoadStandardCursor( IDC_ARROW );
00302         wndcls.hbrBackground    = NULL;
00303         wndcls.lpszMenuName             = NULL;
00304         wndcls.lpszClassName    = _T("ShareazaMainWnd");
00305         
00306         AfxRegisterClass( &wndcls );
00307         
00308         cs.lpszClass = wndcls.lpszClassName;
00309         
00310         return CMDIFrameWnd::PreCreateWindow( cs );
00311 }
00312 
00313 int CMainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00314 {
00315         if ( theApp.m_bRTL )
00316         {
00317                 lpCreateStruct->dwExStyle |= WS_EX_LAYOUTRTL;
00318                 SetWindowLong( GetSafeHwnd(), GWL_EXSTYLE, lpCreateStruct->dwExStyle );
00319         }
00320 
00321         if ( CMDIFrameWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00322         
00323         // Icon
00324         
00325         SetIcon( AfxGetApp()->LoadIcon( IDI_SMALL ), FALSE );
00326         
00327         // Status Bar
00328         
00329         UINT wID[2] = { ID_SEPARATOR, ID_SEPARATOR };
00330         if ( ! m_wndStatusBar.Create( this ) ) return -1;
00331         m_wndStatusBar.SetIndicators( wID, 2 );
00332         m_wndStatusBar.SetPaneInfo( 0, ID_SEPARATOR, SBPS_STRETCH, 0 );
00333         m_wndStatusBar.SetPaneInfo( 1, ID_SEPARATOR, SBPS_NORMAL, 210 );
00334         
00335         EnableDocking( CBRS_ALIGN_ANY );
00336         
00337         // Menu Bar
00338         
00339         SetMenu( NULL );
00340 
00341         if ( ! m_wndMenuBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_TOP, IDW_MENU_BAR ) ) return -1;
00342         m_wndMenuBar.SetWindowText( _T("Menubar") );
00343         m_wndMenuBar.EnableDocking( CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM );
00344         DockControlBar( &m_wndMenuBar, AFX_IDW_DOCKBAR_TOP );
00345         
00346         // Nav Bar
00347         
00348         if ( ! m_wndNavBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_TOP, IDW_NAV_BAR ) ) return -1;
00349         m_wndNavBar.SetWindowText( _T("Navigation Bar") );
00350         m_wndNavBar.EnableDocking( CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM );
00351         m_wndNavBar.SetBarStyle( m_wndNavBar.GetBarStyle() | CBRS_TOOLTIPS );
00352         DockControlBar( &m_wndNavBar, AFX_IDW_DOCKBAR_TOP );
00353         ShowControlBar( &m_wndNavBar, FALSE, FALSE );
00354         
00355         // Tool Bar
00356         
00357         if ( ! m_wndToolBar.Create( this, WS_CHILD|CBRS_TOP, IDW_TOOL_BAR ) ) return -1;
00358         m_wndToolBar.SetWindowText( _T("Toolbar") );
00359         m_wndToolBar.EnableDocking( CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM );
00360         m_wndToolBar.SetBarStyle( m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS );
00361         m_wndToolBar.SetGripper( TRUE );
00362         DockControlBar( &m_wndToolBar, AFX_IDW_DOCKBAR_TOP );
00363         ShowControlBar( &m_wndToolBar, FALSE, FALSE );
00364         
00365         // Tab Bar
00366         
00367         if ( ! m_wndTabBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_BOTTOM, IDW_TAB_BAR ) ) return -1;
00368         m_wndTabBar.SetWindowText( _T("Windows") );
00369         m_wndTabBar.EnableDocking( CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM );
00370         m_wndTabBar.SetBarStyle( m_wndTabBar.GetBarStyle() | CBRS_TOOLTIPS );
00371         DockControlBar( &m_wndTabBar, AFX_IDW_DOCKBAR_TOP );
00372         
00373         // Monitor Bar
00374         
00375         if ( ! m_wndMonitorBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_BOTTOM, IDW_MONITOR_BAR ) ) return -1;
00376         m_wndMonitorBar.m_pSnapBar[0] = &m_wndNavBar;
00377         m_wndMonitorBar.m_pSnapBar[1] = &m_wndToolBar;
00378         m_wndMonitorBar.SetWindowText( _T("Monitor") );
00379         m_wndMonitorBar.EnableDocking( CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM );
00380         DockControlBar( &m_wndMonitorBar, AFX_IDW_DOCKBAR_TOP );
00381         
00382         // Default Size
00383         int iXSize, iYSize;
00384         /*
00385         //Creates problems in dualview mode
00386         if ( ( theApp.m_dwWindowsVersion >= 5 ) && (GetSystemMetrics( SM_CMONITORS ) > 1) )
00387         {       // Multi Monitor
00388                 iXSize = GetSystemMetrics( SM_CXVIRTUALSCREEN );
00389                 iYSize = GetSystemMetrics( SM_CYVIRTUALSCREEN );
00390         }
00391         else    
00392         */
00393         {       // Single Monitor
00394                 iXSize = GetSystemMetrics( SM_CXSCREEN );
00395                 iYSize = GetSystemMetrics( SM_CYSCREEN );
00396         }
00397 
00398         SetWindowPos( NULL, iXSize  * 1 / 10,
00399                                                 iYSize * 1 / 10,
00400                                                 iXSize  * 8 / 10,
00401                                                 iYSize * 8 / 10, 0 );
00402         
00403         // Plugins
00404         
00405         Plugins.Enumerate();
00406         
00407         // Window Setup
00408         
00409         Settings.LoadWindow( _T("CMainWnd"), this );
00410         
00411         LoadBarState( _T("Toolbars\\CoolBar") );
00412         
00413         if ( ! m_wndMenuBar.IsVisible() ) ShowControlBar( &m_wndMenuBar, TRUE, TRUE );
00414         if ( ! m_wndNavBar.IsVisible() && ! m_wndToolBar.IsVisible() )
00415         {
00416                 ShowControlBar( &m_wndNavBar, Settings.General.GUIMode != GUI_WINDOWED, TRUE );
00417                 ShowControlBar( &m_wndToolBar, Settings.General.GUIMode == GUI_WINDOWED, TRUE );
00418         }
00419         if ( ! m_wndTabBar.IsVisible() ) ShowControlBar( &m_wndTabBar, TRUE, FALSE );
00420         
00421         if ( theApp.GetProfileInt( _T("Toolbars"), _T("CRemoteWnd"), TRUE ) )
00422                 m_wndRemoteWnd.Create( &m_wndMonitorBar );
00423         
00424         m_pWindows.SetOwner( this );
00425         SetGUIMode( Settings.General.GUIMode, FALSE );
00426         
00427         // Boot
00428 
00429         if ( theApp.GetProfileInt( _T("Windows"), _T("RunWizard"), FALSE ) == FALSE )
00430         {
00431                 PostMessage( WM_COMMAND, ID_TOOLS_WIZARD );
00432         }
00433         else if ( theApp.GetProfileInt( _T("Windows"), _T("RunWarnings"), FALSE ) == FALSE )
00434         {
00435                 PostMessage( WM_COMMAND, ID_HELP_WARNINGS );
00436         }
00437         else if ( theApp.GetProfileInt( _T("Windows"), _T("RunPromote"), FALSE ) == FALSE )
00438         {
00439                 PostMessage( WM_COMMAND, ID_HELP_PROMOTE );
00440         }
00441         
00442         if ( Settings.Connection.AutoConnect )
00443                 PostMessage( WM_COMMAND, ID_NETWORK_CONNECT );
00444         
00445         Settings.Live.LoadWindowState = TRUE;
00446         
00447         RegisterDragDrop( GetSafeHwnd(), &m_xDropTarget );
00448         
00449         // Go
00450         
00451         m_bTrayHide     = FALSE;
00452         m_bTrayIcon     = FALSE;
00453         m_bTimer        = FALSE;
00454         
00455         SetTimer( 1, 1000, NULL );
00456         
00457         return 0;
00458 }
00459 
00461 // CMainWnd destroy window
00462 
00463 void CMainWnd::OnClose() 
00464 {
00465         CWaitCursor pCursor;
00466         
00467         theApp.m_pSafeWnd               = NULL;
00468         m_pWindows.m_bClosing   = TRUE;
00469         
00470         if ( m_bTrayIcon )
00471         {
00472                 Shell_NotifyIcon( NIM_DELETE, &m_pTray );
00473                 m_bTrayIcon = FALSE;
00474         }
00475         
00476         if ( ! m_bTrayHide )
00477         {
00478                 if ( ! IsIconic() ) SaveBarState( _T("Toolbars\\CoolBar") );
00479                 theApp.WriteProfileInt( _T("Toolbars"), _T("CRemoteWnd"), m_wndRemoteWnd.IsVisible() );
00480                 Settings.SaveWindow( _T("CMainWnd"), this );
00481                 m_pWindows.SaveWindowStates();
00482         }
00483         
00484         m_pWindows.SaveSearchWindows();
00485         m_pWindows.Close();     
00486         
00487         CDownloadMonitorDlg::CloseAll();
00488         CFilePreviewDlg::CloseAll();
00489         
00490         Network.Disconnect();
00491         Transfers.StopThread();
00492         Library.StopThread();
00493         ChatCore.StopThread();
00494         Plugins.Clear();
00495         
00496         CMDIFrameWnd::OnClose();
00497 }
00498 
00499 void CMainWnd::OnDestroy() 
00500 {
00501         KillTimer( 1 );
00502         if ( m_wndRemoteWnd.IsVisible() ) m_wndRemoteWnd.DestroyWindow();
00503         
00504         RevokeDragDrop( GetSafeHwnd() );
00505         Network.Disconnect();
00506         
00507         CMDIFrameWnd::OnDestroy();
00508 }
00509 
00510 void CMainWnd::OnEndSession(BOOL bEnding) 
00511 {
00512         CMDIFrameWnd::OnEndSession( bEnding );
00513         if ( bEnding ) SendMessage( WM_CLOSE );
00514 }
00515 
00517 // CMainWnd GUI modes
00518 
00519 void CMainWnd::SetGUIMode(int nMode, BOOL bSaveState)
00520 {
00521         m_pWindows.ShowWindow( SW_HIDE );
00522         
00523         if ( bSaveState )
00524         {
00525                 if ( nMode < 0 ) nMode = Settings.General.GUIMode;
00526                 
00527                 ShowControlBar( &m_wndMenuBar, FALSE, TRUE );
00528                 ShowControlBar( &m_wndNavBar, FALSE, TRUE );
00529                 ShowControlBar( &m_wndToolBar, FALSE, TRUE );
00530                 ShowControlBar( &m_wndTabBar, FALSE, TRUE );
00531                 ShowControlBar( &m_wndMonitorBar, FALSE, TRUE );
00532         }
00533         
00534         m_pWindows.SetGUIMode( nMode, bSaveState );
00535         OnSkinChanged( 0, 0 );
00536         
00537         if ( bSaveState )
00538         {
00539                 DockControlBar( &m_wndMenuBar, AFX_IDW_DOCKBAR_TOP );
00540                 ShowControlBar( &m_wndMenuBar, TRUE, TRUE );
00541                 
00542                 if ( nMode != GUI_WINDOWED && m_wndNavBar.HasLocalVersion() )
00543                 {
00544                         DockControlBar( &m_wndNavBar, AFX_IDW_DOCKBAR_TOP );
00545                         ShowControlBar( &m_wndNavBar, TRUE, TRUE );
00546                 }
00547                 else
00548                 {
00549                         DockControlBar( &m_wndToolBar, AFX_IDW_DOCKBAR_TOP );
00550                         ShowControlBar( &m_wndToolBar, TRUE, TRUE );
00551                 }
00552                 
00553                 DockControlBar( &m_wndTabBar, nMode == GUI_WINDOWED ? AFX_IDW_DOCKBAR_BOTTOM : AFX_IDW_DOCKBAR_TOP );
00554                 ShowControlBar( &m_wndTabBar, TRUE, TRUE );
00555         }
00556 
00557         m_wndTabBar.SetMaximumWidth( nMode != GUI_WINDOWED ? 200 : 140 );
00558         m_wndTabBar.SetMessage( (UINT)0 );
00559         
00560         if ( bSaveState )
00561         {
00562                 CRect rcWnd, rcBar;
00563                 
00564                 GetWindowRect( &rcWnd );
00565                 if ( m_wndNavBar.IsVisible() )
00566                         m_wndNavBar.GetWindowRect( &rcBar );
00567                 else
00568                         m_wndToolBar.GetWindowRect( &rcBar );
00569                 rcBar.left      = rcWnd.right - 128;
00570                 rcBar.right     = rcWnd.right;
00571                 
00572                 DockControlBar( &m_wndMonitorBar, AFX_IDW_DOCKBAR_TOP, &rcBar );
00573                 ShowControlBar( &m_wndMonitorBar, nMode == GUI_WINDOWED, TRUE );
00574         }
00575         
00576         m_pWindows.ShowWindow( SW_SHOW );
00577 }
00578 
00580 // CMainWnd command architecture
00581 
00582 BOOL CMainWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
00583 {
00584         if ( m_wndMonitorBar.m_hWnd != NULL )
00585         {
00586                 if ( m_wndMonitorBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00587         }
00588         
00589         if ( CMediaFrame::g_pMediaFrame != NULL )
00590         {
00591                 if ( CMediaFrame::g_pMediaFrame->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) )
00592                         return TRUE;
00593         }
00594         
00595         return CMDIFrameWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00596 }
00597 
00598 BOOL CMainWnd::OnCommand(WPARAM wParam, LPARAM lParam) 
00599 {
00600         if ( Plugins.OnCommand( m_pWindows.GetActive(), LOWORD( wParam ) ) ) return TRUE;
00601         return CMDIFrameWnd::OnCommand( wParam, lParam );
00602 }
00603 
00604 void CMainWnd::OnUpdatePluginRange(CCmdUI* pCmdUI)
00605 {
00606         if ( ! Plugins.OnUpdate( m_pWindows.GetActive(), pCmdUI ) ) pCmdUI->Enable( FALSE );
00607 }
00608 
00610 // CMainWnd menu GUI
00611 
00612 void CMainWnd::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
00613 {
00614         CMDIFrameWnd::OnInitMenuPopup( pPopupMenu, nIndex, bSysMenu );
00615         UINT nID = pPopupMenu->GetMenuItemID( 0 );
00616         if ( nID != SC_RESTORE ) CoolMenu.AddMenu( pPopupMenu, TRUE );
00617 }
00618 
00619 void CMainWnd::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
00620 {
00621         CoolMenu.OnMeasureItem( lpMeasureItemStruct );
00622 }
00623 
00624 void CMainWnd::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
00625 {
00626         CoolMenu.OnDrawItem( lpDrawItemStruct );
00627 }
00628 
00629 void CMainWnd::OnSysColorChange() 
00630 {
00631         CMDIFrameWnd::OnSysColorChange();
00632         CoolInterface.OnSysColourChange();
00633 }
00634 
00635 void CMainWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
00636 {
00637         m_wndTabBar.OnUpdateCmdUI( this, FALSE );
00638         m_wndNavBar.OnUpdateCmdUI( this, FALSE );
00639 }
00640 
00641 void CMainWnd::OnContextMenu(CWnd* pWnd, CPoint point) 
00642 {
00643         if ( ( pWnd != this || OnNcHitTest( point ) != HTCAPTION ) )
00644         {
00645                 CMenu* pMenu = Skin.GetMenu( _T("CMainWnd.View") );
00646                 if ( pMenu == NULL ) return;
00647                 pMenu->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, point.x, point.y, this );
00648         }
00649 }
00650 
00651 #define SNAP_SIZE 6
00652 
00653 void CMainWnd::OnWindowPosChanging(WINDOWPOS* lpwndpos)
00654 {
00655         CMDIFrameWnd::OnWindowPosChanging( lpwndpos );
00656         
00657         if ( theApp.m_pfnGetMonitorInfoA != NULL ) //If GetMonitorInfo() is available
00658         {
00659                 MONITORINFO oMonitor;
00660                 ZeroMemory( &oMonitor, sizeof(oMonitor) );
00661                 oMonitor.cbSize = sizeof(oMonitor);
00662                 
00663                 theApp.m_pfnGetMonitorInfoA( theApp.m_pfnMonitorFromWindow( GetSafeHwnd(), MONITOR_DEFAULTTOPRIMARY ), &oMonitor );
00664                 
00665                 if ( abs( lpwndpos->x - oMonitor.rcWork.left ) < SNAP_SIZE )
00666                         lpwndpos->x = oMonitor.rcWork.left;
00667                 if ( abs( lpwndpos->y - oMonitor.rcWork.top ) < SNAP_SIZE )
00668                         lpwndpos->y = oMonitor.rcWork.top;
00669                 if ( abs( lpwndpos->x + lpwndpos->cx - oMonitor.rcWork.right ) < SNAP_SIZE )
00670                         lpwndpos->x = oMonitor.rcWork.right - lpwndpos->cx;
00671                 if ( abs( lpwndpos->y + lpwndpos->cy - oMonitor.rcWork.bottom ) < SNAP_SIZE )
00672                         lpwndpos->y = oMonitor.rcWork.bottom - lpwndpos->cy;
00673         }
00674         else
00675         {
00676                 CRect rcWork;
00677                 SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 );
00678                 
00679                 if ( abs( lpwndpos->x ) <= ( rcWork.left + SNAP_SIZE ) )
00680                 {
00681                         lpwndpos->x = rcWork.left;
00682                 }
00683                 else if (       ( lpwndpos->x + lpwndpos->cx ) >= ( rcWork.right - SNAP_SIZE ) &&
00684                                         ( lpwndpos->x + lpwndpos->cx ) <= ( rcWork.right + SNAP_SIZE ) )
00685                 {
00686                         lpwndpos->x = rcWork.right - lpwndpos->cx;
00687                 }
00688                 
00689                 if ( abs( lpwndpos->y ) <= ( rcWork.top + SNAP_SIZE ) )
00690                 {
00691                         lpwndpos->y = rcWork.top;
00692                 }
00693                 else if (       ( lpwndpos->y + lpwndpos->cy ) >= ( rcWork.bottom - SNAP_SIZE ) &&
00694                                         ( lpwndpos->y + lpwndpos->cy ) <= ( rcWork.bottom + SNAP_SIZE ) )
00695                 {
00696                         lpwndpos->y = rcWork.bottom-lpwndpos->cy;
00697                 }
00698         }
00699 }
00700 
00702 // CMainWnd common timer
00703 
00704 void CMainWnd::OnTimer(UINT nIDEvent) 
00705 {
00706         // Fix resource handle
00707         
00708         if ( AfxGetResourceHandle() != m_hInstance )
00709                 AfxSetResourceHandle( m_hInstance );
00710 
00711         // Propagate to children
00712         
00713         if ( m_bTimer ) return;
00714         m_bTimer = TRUE;
00715         
00716         for ( POSITION pos = m_pWindows.GetIterator() ; pos ; )
00717         {
00718                 CChildWnd* pChild = m_pWindows.GetNext( pos );
00719                 pChild->PostMessage( WM_TIMER, 1, 0 );
00720         }
00721         
00722         m_bTimer = FALSE;
00723         Settings.Live.LoadWindowState = FALSE;
00724         
00725         // Statistics
00726         
00727         Statistics.Update();
00728         
00729         // Hashing progress window
00730         
00731         m_wndHashProgressBar.Run();
00732         
00733         // Switch tray icon
00734         
00735         BOOL bNeedTrayIcon = m_bTrayHide || Settings.General.TrayMinimise || Settings.General.CloseMode == 2;
00736         
00737         if ( bNeedTrayIcon && ! m_bTrayIcon )
00738         {
00739                 // Delete existing tray icon (if any), windows can't create a new icon with same uID
00740                 Shell_NotifyIcon( NIM_DELETE, &m_pTray );
00741 
00742                 m_pTray.cbSize                          = sizeof(m_pTray);
00743                 m_pTray.hWnd                            = GetSafeHwnd();
00744                 m_pTray.uID                                     = 0;
00745                 m_pTray.uFlags                          = NIF_ICON | NIF_MESSAGE | NIF_TIP;
00746                 m_pTray.uCallbackMessage        = WM_TRAY;
00747                 
00748                 if ( CoolInterface.IsNewWindows() )
00749                         m_pTray.hIcon = AfxGetApp()->LoadIcon( IDI_SMALL );
00750                 else
00751                         m_pTray.hIcon = AfxGetApp()->LoadIcon( IDI_ICON );
00752                 
00753                 _tcscpy( m_pTray.szTip, _T("Shareaza") );
00754                 m_bTrayIcon = Shell_NotifyIcon( NIM_ADD, &m_pTray );
00755         }
00756         else if ( m_bTrayIcon && ! bNeedTrayIcon )
00757         {
00758                 Shell_NotifyIcon( NIM_DELETE, &m_pTray );
00759                 m_bTrayIcon = FALSE;
00760         }
00761         
00762         // Menu Bar
00763         
00764         if ( m_wndMenuBar.IsWindowVisible() == FALSE ) ShowControlBar( &m_wndMenuBar, TRUE, FALSE );
00765 
00766         // Scheduler
00767         
00768         if ( Settings.Scheduler.Enable ) Schedule.Update();
00769 
00770         // Network / disk space / directory checks
00771 
00772         LocalSystemChecks();
00773         
00774         // Update messages
00775         
00776         UpdateMessages();
00777 }
00778 
00779 void CMainWnd::OnActivateApp(BOOL bActive, DWORD dwTask) 
00780 {
00781         CMDIFrameWnd::OnActivateApp( bActive, dwTask );
00782         
00783         if ( ! bActive )
00784         {
00785                 CoFreeUnusedLibraries();
00786                 // SetProcessWorkingSetSize( GetCurrentProcess(), 0xFFFFFFFF, 0xFFFFFFFF );
00787         }
00788 }
00789 
00790 void CMainWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
00791 {
00792         CMDIFrameWnd::OnActivate( nState, pWndOther, bMinimized );
00793         
00794     if ( nState != WA_INACTIVE )
00795         {
00796                 if ( CChildWnd* pChildWnd = m_pWindows.GetActive() )
00797                 {
00798                         pChildWnd->SendMessage( WM_MDIACTIVATE, NULL, (LPARAM)pChildWnd->GetSafeHwnd() );
00799                 }
00800         }
00801 }
00802 
00803 void CMainWnd::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
00804 {
00805         CMDIFrameWnd::OnGetMinMaxInfo( lpMMI );
00806         
00807         lpMMI->ptMinTrackSize.x = 320;
00808         lpMMI->ptMinTrackSize.y = 240;
00809         
00810         if ( m_pSkin ) m_pSkin->OnGetMinMaxInfo( lpMMI );
00811 }
00812 
00813 LONG CMainWnd::OnLog(WPARAM wParam, LPARAM lParam)
00814 {
00815         LPTSTR pszLog = (LPTSTR)lParam;
00816         
00817         if ( CSystemWnd* pWnd = (CSystemWnd*)m_pWindows.Find( RUNTIME_CLASS(CSystemWnd) ) )
00818         {
00819                 pWnd->Add( (int)wParam, pszLog );
00820         }
00821         
00822         free( pszLog );
00823         return 0;
00824 }
00825 
00827 // CMainWnd tray functionality
00828 
00829 void CMainWnd::CloseToTray()
00830 {
00831         if ( m_bTrayHide ) return;
00832 
00833         ShowWindow( SW_HIDE );
00834 
00835         m_bTrayHide = TRUE;
00836 }
00837 
00838 void CMainWnd::OpenFromTray(int nShowCmd)
00839 {
00840         if ( m_bTrayHide ) ShowWindow( nShowCmd );
00841         if ( IsIconic() ) SendMessage( WM_SYSCOMMAND, SC_RESTORE );
00842         
00843         SetForegroundWindow();
00844         m_bTrayHide = FALSE;
00845 }
00846 
00847 LONG CMainWnd::OnTray(UINT wParam, LONG lParam)
00848 {
00849         if ( LOWORD(lParam) == WM_LBUTTONDBLCLK )
00850         {
00851                 OpenFromTray();
00852         }
00853         else if ( LOWORD(lParam) == WM_RBUTTONDOWN )
00854         {
00855                 UINT nFlags = TPM_RIGHTBUTTON;
00856                 CPoint pt;
00857                 CRect rc;
00858                 
00859                 GetCursorPos( &pt );
00860                 SystemParametersInfo( SPI_GETWORKAREA, 0, &rc, 0 );
00861                 
00862                 nFlags |= TPM_CENTERALIGN;
00863                 
00864                 if ( pt.y > GetSystemMetrics( SM_CYSCREEN ) / 2 )
00865                 {
00866                         pt.y = rc.bottom;
00867                         nFlags |= TPM_TOPALIGN;
00868                 }
00869                 else
00870                 {
00871                         pt.y = rc.top;
00872                         nFlags |= TPM_BOTTOMALIGN;
00873                 }
00874                 
00875                 SetForegroundWindow();
00876                 
00877                 CMenu* pMenu = Skin.GetMenu( _T("CMainWnd.Tray") );
00878                 if ( pMenu == NULL ) return 0;
00879                 
00880                 MENUITEMINFO pInfo;
00881                 pInfo.cbSize    = sizeof(pInfo);
00882                 pInfo.fMask             = MIIM_STATE;
00883                 GetMenuItemInfo( pMenu->GetSafeHmenu(), ID_TRAY_OPEN, FALSE, &pInfo );
00884                 pInfo.fState    |= MFS_DEFAULT;
00885                 SetMenuItemInfo( pMenu->GetSafeHmenu(), ID_TRAY_OPEN, FALSE, &pInfo );
00886                 
00887                 pMenu->TrackPopupMenu( nFlags, pt.x, pt.y, this, NULL );
00888                 
00889                 PostMessage( WM_NULL );
00890         }
00891 
00892         return 0;
00893 }
00894 
00895 void CMainWnd::OnTrayOpen() 
00896 {
00897         OpenFromTray();
00898 }
00899 
00900 void CMainWnd::OnSysCommand(UINT nID, LPARAM lParam) 
00901 {
00902         if ( ( nID & 0xFFF0 ) == SC_KEYMENU )
00903         {
00904                 if ( lParam != ' ' && lParam != '-' )
00905                 {
00906                         if ( lParam )
00907                                 m_wndMenuBar.OpenMenuChar( lParam );
00908                         else
00909                                 m_wndMenuBar.OpenMenuBar();
00910                                 
00911                         return;
00912                 }
00913         }
00914         
00915         if ( m_bTrayHide )
00916         {
00917                 switch ( nID & 0xFFF0 )
00918                 {
00919                 case SC_RESTORE:
00920                         OpenFromTray( SW_SHOWNORMAL );
00921                         return;
00922                 case SC_MAXIMIZE:
00923                         OpenFromTray( SW_SHOWMAXIMIZED );
00924                         return;
00925                 }
00926         }
00927         else
00928         {
00929                 BOOL bShift = ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 );
00930                 
00931                 switch ( nID & 0xFFF0 )
00932                 {
00933                 case SC_CLOSE:
00934                         if ( Settings.General.CloseMode == 0 )
00935                         {
00936                                 CCloseModeDlg dlg;
00937                                 if ( dlg.DoModal() != IDOK ) return;
00938                         }
00939                         
00940                         if ( Settings.General.CloseMode == 3 && ! bShift )
00941                         {
00942                                 if ( Settings.Live.AutoClose )
00943                                         CloseToTray();
00944                                 else
00945                                         OnNetworkAutoClose();
00946                                 return;
00947                         }
00948                         else if ( Settings.General.CloseMode == 2 && ! bShift )
00949                         {
00950                                 CloseToTray();
00951                                 return;
00952                         }
00953                         break;
00954                 case SC_MINIMIZE:
00955                         if ( ( Settings.General.TrayMinimise && ! bShift ) || ( ! Settings.General.TrayMinimise && bShift ) )
00956                         {
00957                                 CloseToTray();
00958                                 return;
00959                         }
00960                         break;
00961                 }
00962         }
00963         
00964         CMDIFrameWnd::OnSysCommand( nID, lParam );
00965 }
00966 
00968 // CMainWnd custom message handlers
00969 
00970 LONG CMainWnd::OnSkinChanged(UINT wParam, LONG lParam)
00971 {
00972         CWaitCursor pCursor;
00973         
00974         m_pSkin = NULL;
00975         
00976         m_pWindows.PostSkinRemove();
00977         m_wndMenuBar.SetMenu( NULL );
00978         m_wndToolBar.Clear();
00979         
00980         CDownloadMonitorDlg::OnSkinChange( FALSE );
00981         CSettingsManagerDlg::OnSkinChange( FALSE );
00982         CFilePreviewDlg::OnSkinChange( FALSE );
00983         
00984         Skin.Apply();
00985         
00986         if ( CMenu* pMenu = Skin.GetMenu( _T("CMainWnd") ) )
00987         {
00988                 m_wndMenuBar.SetMenu( pMenu->Detach() );
00989         }
00990         
00991         Skin.CreateToolBar( _T("CMainWnd"), &m_wndToolBar );
00992         m_wndNavBar.OnSkinChange();
00993         
00994         m_wndMenuBar.SetWatermark( Skin.GetWatermark( _T("CCoolMenuBar") ) );
00995         m_wndTabBar.SetWatermark( Skin.GetWatermark( _T("CWndTabBar") ) );
00996         
00997         if ( CWnd* pDockBar = GetDlgItem( AFX_IDW_DOCKBAR_TOP ) )
00998         {
00999                 DWORD nBrush = GetClassLong( pDockBar->GetSafeHwnd(), GCL_HBRBACKGROUND );
01000                 if ( nBrush > 64 ) DeleteObject( (HBRUSH)nBrush );
01001                 nBrush = (DWORD)CreateSolidBrush( CoolInterface.m_crMidtone );
01002                 SetClassLong( pDockBar->GetSafeHwnd(), GCL_HBRBACKGROUND, (LONG)nBrush );
01003         }
01004         
01005         m_pSkin = Skin.GetWindowSkin( this );
01006         
01007         if ( m_pSkin != NULL )
01008         {
01009                 ModifyStyle( WS_CAPTION, 0 );
01010                 m_pWindows.ModifyStyleEx( WS_EX_CLIENTEDGE, 0 );
01011                 SetWindowRgn( NULL, TRUE );
01012                 m_pSkin->OnSize( this );
01013         }
01014         else
01015         {
01016                 ModifyStyle( 0, WS_CAPTION, 0 );
01017                 m_pWindows.ModifyStyleEx( 0, WS_EX_CLIENTEDGE );
01018                 SetWindowRgn( NULL, TRUE );
01019         }
01020         
01021         m_wndMonitorBar.OnSkinChange();
01022         m_wndRemoteWnd.OnSkinChange();
01023         
01024         SetWindowPos( NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|
01025                 SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED|SWP_DRAWFRAME );
01026         
01027         UpdateMessages();
01028         
01029         if ( TRUE )
01030         {
01031                 m_wndToolBar.OnUpdated();
01032                 m_pWindows.PostSkinChange();
01033                 m_wndTabBar.OnUpdateCmdUI( this, FALSE );
01034                 RedrawWindow( NULL, NULL, RDW_INVALIDATE|RDW_FRAME|RDW_ALLCHILDREN );
01035         }
01036         
01037         CSettingsManagerDlg::OnSkinChange( TRUE );
01038         CDownloadMonitorDlg::OnSkinChange( TRUE );
01039         CFilePreviewDlg::OnSkinChange( TRUE );
01040         
01041         Invalidate();
01042         
01043         return 0;
01044 }
01045 
01046 LONG CMainWnd::OnWinsock(WPARAM wParam, LPARAM lParam)
01047 {
01048         Network.OnWinsock( wParam, lParam );
01049         return 0;
01050 }
01051 
01052 LONG CMainWnd::OnHandleURL(WPARAM wParam, LPARAM lParam)
01053 {
01054         CShareazaURL* pURL = (CShareazaURL*)wParam;
01055         
01056         DWORD tNow = GetTickCount();
01057         BOOL bSoon = ( tNow - m_tURLTime < 750 );
01058         m_tURLTime = tNow;
01059         
01060         if ( IsWindowEnabled() )
01061         {
01062                 m_pURLDialog = new CURLActionDlg( this, pURL, bSoon );
01063                 m_pURLDialog->DoModal();
01064                 delete m_pURLDialog;
01065                 m_pURLDialog = NULL;
01066         }
01067         else
01068         {
01069                 if ( m_pURLDialog != NULL && bSoon )
01070                 {
01071                         m_pURLDialog->AddURL( pURL );
01072                 }
01073                 else
01074                 {
01075                         theApp.Message( MSG_ERROR, IDS_URL_BUSY );
01076                         delete pURL;
01077                 }
01078         }
01079         
01080         return 0;
01081 }
01082 
01083 LONG CMainWnd::OnHandleCollection(WPARAM wParam, LPARAM lParam)
01084 {
01085         LPTSTR pszPath = (LPTSTR)wParam;
01086         CString strPath( pszPath );
01087         delete [] pszPath;
01088         
01089         if ( CLibraryWnd* pLibrary = (CLibraryWnd*)m_pWindows.Open( RUNTIME_CLASS(CLibraryWnd) ) )
01090         {
01091                 pLibrary->OnCollection( strPath );
01092         }
01093         
01094         return 0;
01095 }
01096 
01097 LONG CMainWnd::OnVersionCheck(WPARAM wParam, LPARAM lParam)
01098 {
01099         if ( wParam == 0 && VersionChecker.m_sMessage.GetLength() )
01100         {
01101                 AfxMessageBox( VersionChecker.m_sMessage, MB_ICONINFORMATION );
01102         }
01103         
01104         if ( ( wParam == 0 || wParam == 1 ) && VersionChecker.m_bUpgrade )
01105         {
01106                 CUpgradeDlg dlg;
01107                 dlg.DoModal();
01108         }
01109         
01110         if ( wParam == 2 && VersionChecker.m_sUpgradePath.GetLength() )
01111         {
01112                 CString strFormat, strMessage;
01113                 
01114                 LoadString( strFormat, IDS_UPGRADE_LAUNCH );
01115                 strMessage.Format( strFormat, (LPCTSTR)VersionChecker.m_sUpgradeFile );
01116                 
01117                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES )
01118                 {
01119                         ShellExecute( GetSafeHwnd(), _T("open"), VersionChecker.m_sUpgradePath,
01120                                 _T("/launch"), NULL, SW_SHOWNORMAL );
01121                         PostMessage( WM_CLOSE );
01122                 }
01123         }
01124         
01125         return 0;
01126 }
01127 
01128 LONG CMainWnd::OnOpenChat(WPARAM wParam, LPARAM lParam)
01129 {
01130         CSingleLock pLock( &ChatCore.m_pSection, TRUE );
01131         CChatSession* pSession = (CChatSession*)wParam;
01132         if ( ChatCore.Check( pSession ) ) pSession->OnOpenWindow();
01133         return 0;
01134 }
01135 
01136 LONG CMainWnd::OnOpenSearch(WPARAM wParam, LPARAM lParam)
01137 {
01138         CQuerySearch* pSearch = (CQuerySearch*)wParam;
01139         if ( pSearch->OpenWindow() == NULL ) delete pSearch;
01140         return 0;
01141 }
01142 
01143 LONG CMainWnd::OnMediaKey(WPARAM wParam, LPARAM lParam)
01144 {
01145         if ( CMediaWnd* pWnd = (CMediaWnd*)m_pWindows.Find( RUNTIME_CLASS(CMediaWnd) ) )
01146         {
01147                 return pWnd->SendMessage( 0x0319, 1, lParam );
01148         }
01149         return 0;
01150 }
01151 
01152 LONG CMainWnd::OnDevModeChange(WPARAM wParam, LPARAM lParam)
01153 {
01154         if ( CMediaWnd* pWnd = (CMediaWnd*)m_pWindows.Find( RUNTIME_CLASS(CMediaWnd) ) )
01155         {
01156                 return pWnd->SendMessage( WM_DEVMODECHANGE, wParam, lParam );
01157         }
01158         return 0;
01159 }
01160 
01161 LONG CMainWnd::OnDisplayChange(WPARAM wParam, LPARAM lParam)
01162 {
01163         if ( CMediaWnd* pWnd = (CMediaWnd*)m_pWindows.Find( RUNTIME_CLASS(CMediaWnd) ) )
01164         {
01165                 return pWnd->SendMessage( WM_DISPLAYCHANGE, wParam, lParam );
01166         }
01167         return 0;
01168 }
01169 
01171 // CMainWnd status message functionality
01172 
01173 LONG CMainWnd::OnSetMessageString(WPARAM wParam, LPARAM lParam)
01174 {
01175         if ( wParam == AFX_IDS_IDLEMESSAGE )
01176         {
01177                 CString strOld;
01178                 m_wndStatusBar.GetWindowText( strOld );
01179                 if ( strOld != m_sMsgStatus ) m_wndStatusBar.SetWindowText( m_sMsgStatus );
01180                 m_nIDLastMessage = m_nIDTracking = wParam;
01181                 return 0;
01182         }
01183         else
01184         {
01185                 return CMDIFrameWnd::OnSetMessageString( wParam, lParam );
01186         }
01187 }
01188 
01189 void CMainWnd::GetMessageString(UINT nID, CString& rMessage) const
01190 {
01191         if ( LoadString( rMessage, nID ) )
01192         {
01193                 int nPos = rMessage.Find( '\n' );
01194                 if ( nPos >= 0 ) rMessage.SetAt( nPos, 0 );
01195         }
01196 }
01197 
01198 void CMainWnd::UpdateMessages()
01199 {
01200         CString strFormat, strMessage, strOld;
01201 
01202         int nCount = Network.IsWellConnected();
01203 
01204         if ( nCount > 0 )
01205         {       //If you have neighbours, you are connected
01206                 QWORD nLocalVolume;
01207                 LibraryMaps.GetStatistics( NULL, &nLocalVolume );
01208 
01209                 if( Settings.General.GUIMode == GUI_BASIC )
01210                 {       //In the basic GUI, don't bother with mode details or neighbour count.
01211                         LoadString( strFormat, IDS_STATUS_BAR_CONNECTED_SIMPLE );
01212                         strMessage.Format( strFormat, (LPCTSTR)Settings.SmartVolume( nLocalVolume, TRUE ) );
01213                 }
01214                 else
01215                 {       //Display node type and number of neighbours
01216                         if (  Neighbours.IsG2Hub() )
01217                         {
01218                                 if (  Neighbours.IsG1Ultrapeer() )
01219                                         LoadString( strFormat, IDS_STATUS_BAR_CONNECTED_HUB_UP );
01220                                 else
01221                                         LoadString( strFormat, IDS_STATUS_BAR_CONNECTED_HUB );
01222                         }
01223                         else
01224                         {
01225                                 if (  Neighbours.IsG1Ultrapeer() )
01226                                         LoadString( strFormat, IDS_STATUS_BAR_CONNECTED_UP );
01227                                 else
01228                                         LoadString( strFormat, IDS_STATUS_BAR_CONNECTED );
01229                         }
01230                         strMessage.Format( strFormat, nCount,
01231                                                                 (LPCTSTR)Settings.SmartVolume( nLocalVolume, TRUE ) );
01232                 }
01233         }
01234         else if ( Network.IsConnected() )
01235         {       //Trying to connect
01236                 LoadString( strMessage, IDS_STATUS_BAR_CONNECTING );
01237         }
01238         else
01239         {       //Idle
01240                 LoadString( strMessage, IDS_STATUS_BAR_DISCONNECTED );
01241         }
01242 
01243         if ( VersionChecker.m_sQuote.GetLength() )
01244         {
01245                 strMessage += _T("  ");
01246                 strMessage += VersionChecker.m_sQuote;
01247         }
01248 
01249         if ( m_nIDLastMessage == AFX_IDS_IDLEMESSAGE )
01250         {
01251                 m_wndStatusBar.GetWindowText( strOld );
01252                 if ( strOld != strMessage ) m_wndStatusBar.SetWindowText( strMessage );
01253         }
01254 
01255         m_sMsgStatus = strMessage;
01256 
01257         LoadString( strFormat, IDS_STATUS_BAR_BANDWIDTH );
01258         strMessage.Format( strFormat,
01259                 (LPCTSTR)Settings.SmartVolume( CGraphItem::GetValue( GRC_TOTAL_BANDWIDTH_IN ), FALSE, TRUE ),
01260                 (LPCTSTR)Settings.SmartVolume( CGraphItem::GetValue( GRC_TOTAL_BANDWIDTH_OUT ), FALSE, TRUE ),
01261                 (int)CGraphItem::GetValue( GRC_DOWNLOADS_TRANSFERS, 0 ),
01262                 (int)CGraphItem::GetValue( GRC_UPLOADS_TRANSFERS, 0 ) );
01263 
01264         m_wndStatusBar.GetPaneText( 1, strOld );
01265         if ( strOld != strMessage ) m_wndStatusBar.SetPaneText( 1, strMessage );
01266 
01267         if ( m_bTrayIcon )
01268         {
01269                 LoadString( strFormat, IDS_TRAY_TIP );
01270                 strMessage.Format( strFormat,
01271                         (int)CGraphItem::GetValue( GRC_GNUTELLA_CONNECTIONS, 0 ),
01272                         (LPCTSTR)Settings.SmartVolume( CGraphItem::GetValue( GRC_TOTAL_BANDWIDTH_IN ), FALSE, TRUE ),
01273                         (LPCTSTR)Settings.SmartVolume( CGraphItem::GetValue( GRC_TOTAL_BANDWIDTH_OUT ), FALSE, TRUE ),
01274                         (int)CGraphItem::GetValue( GRC_DOWNLOADS_TRANSFERS ),
01275                         (int)CGraphItem::GetValue( GRC_UPLOADS_TRANSFERS ) );
01276 
01277                 if ( strMessage != m_pTray.szTip )
01278                 {
01279                         m_pTray.uFlags = NIF_TIP;
01280                         _tcsncpy( m_pTray.szTip, strMessage, 63 );
01281                         if ( ! Shell_NotifyIcon( NIM_MODIFY, &m_pTray ) ) m_bTrayIcon = FALSE;
01282                 }
01283         }
01284         
01285         LoadString( strMessage, IDR_MAINFRAME );
01286         
01287         if ( Settings.Live.AutoClose )
01288         {
01289                 LoadString( strOld, IDS_CLOSING_AFTER );
01290                 strMessage += strOld;
01291         }
01292         
01293         if ( _tcsistr( strMessage, _T("Shareaza") ) == NULL )
01294         {
01295                 strMessage = _T("Shareaza ") + strMessage;
01296         }
01297         
01298         GetWindowText( strOld );
01299         if ( strOld != strMessage ) SetWindowText( strMessage );
01300 }
01301 
01302 // This function runs some basic checks that everything is okay- disks, directories, local network is
01303 // up, etc.
01304 void CMainWnd::LocalSystemChecks()
01305 {
01306         static DWORD tLastCheck = 0;                    // Time the checks were last run
01307         static DWORD nConnectionFailCount = 0;  // Counter for times a connection problem has been detected
01308         DWORD tTicks = GetTickCount();                  // Current time
01309 
01310         if ( tTicks - tLastCheck > 1 * 60 * 1000 )  // Run once every minute
01311         {
01312                 tLastCheck = tTicks;
01313 
01314                 // Check disk space
01315                 if ( Settings.Live.DiskSpaceStop == FALSE )
01316                 {
01317                         if ( ! Downloads.IsSpaceAvailable( (QWORD)Settings.General.DiskSpaceStop * 1024 * 1024 ) )
01318                         {
01319                                 CSingleLock pLock( &Transfers.m_pSection );
01320                                 if ( pLock.Lock( 250 ) )
01321                                 {
01322                                         Settings.Live.DiskSpaceStop = TRUE;
01323                                         Downloads.PauseAll();
01324                                 }
01325 
01326                         }
01327                 }
01328                 if ( Settings.Live.DiskSpaceWarning == FALSE )
01329                 {
01330                         if ( ! Downloads.IsSpaceAvailable( (QWORD)Settings.General.DiskSpaceWarning * 1024 * 1024 ) )
01331                         {
01332                                 Settings.Live.DiskSpaceWarning = TRUE;
01333                                 PostMessage( WM_COMMAND, ID_HELP_DISKSPACE );
01334                         }
01335                 }
01336 
01337 
01338                 // Check disk/directory exists and isn't read-only
01339                 if ( Settings.Live.DiskWriteWarning == FALSE )
01340                 {
01341                         DWORD nCompleteAttributes, nIncompleteAttributes;
01342                         nCompleteAttributes = GetFileAttributes( Settings.Downloads.CompletePath );
01343                         nIncompleteAttributes = GetFileAttributes( Settings.Downloads.IncompletePath );
01344 
01345                         if ( ( nCompleteAttributes == INVALID_FILE_ATTRIBUTES ) ||  ( nIncompleteAttributes == INVALID_FILE_ATTRIBUTES ) || 
01346                                 !( nCompleteAttributes & FILE_ATTRIBUTE_DIRECTORY ) || !( nIncompleteAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
01347                         {
01348                                 Settings.Live.DiskWriteWarning = TRUE;
01349                                 PostMessage( WM_COMMAND, ID_HELP_DISKWRITEFAIL );
01350                         }
01351                         else if ( theApp.m_bNT )
01352                         {
01353 /*
01354 // Note: These checks fail on some machines. WinXP goofyness?
01355                                 // Extra NT/Win2000/XP permission checks
01356                                 if ( ( _taccess( Settings.Downloads.IncompletePath, 06 ) != 0 ) ||
01357                                          ( _taccess( Settings.Downloads.CompletePath, 06 ) != 0 ) )
01358                                 {
01359                                         Settings.Live.DiskWriteWarning = TRUE;
01360                                         PostMessage( WM_COMMAND, ID_HELP_DISKWRITEFAIL );
01361                                 }
01362 */
01363                         }
01364                 }
01365 
01366 
01367                 // Check network connection state
01368                 if ( Settings.Connection.DetectConnectionLoss )
01369                 {
01370                         if ( Network.IsConnected() )
01371                         {
01372                                 if ( ( Network.IsAvailable() ) || ( Network.IsWellConnected() > 0 ) )                           
01373                                 {
01374                                         // Internet is available
01375                                         nConnectionFailCount = 0;
01376                                 }
01377                                 else
01378                                 {
01379                                         // Internet may have failed
01380                                         nConnectionFailCount++;
01381                                         // Give it at least two failures before assuming it's bad
01382                                         if ( nConnectionFailCount > 1 )
01383                                         {
01384                                                 if ( Settings.Connection.DetectConnectionReset )
01385                                                         theApp.Message( MSG_ERROR, _T("Internet disconnection detected- shutting down network") );
01386                                                 else
01387                                                         PostMessage( WM_COMMAND, ID_HELP_CONNECTIONFAIL );
01388 
01389                                                 Network.Disconnect();
01390                                         }
01391                                 }
01392                         }
01393                         else
01394                         {
01395                                 // We are not currently connected. Check if we disconnected because of failure and want to re-connect.
01396                                 if ( ( nConnectionFailCount > 0 ) && ( Settings.Connection.DetectConnectionReset ) )
01397                                 {
01398                                         // See if we can reconnect
01399                                         if ( Network.IsAvailable() )
01400                                         {
01401                                                 nConnectionFailCount = 0;
01402                                                 Network.Connect();
01403                                                 theApp.Message( MSG_ERROR, _T("Internet reconnect detected- restarting network") );
01404                                         }
01405                                 }
01406                         }
01407                 }
01408 
01409 
01410                 // Check we have donkey servers
01411                 if ( ( Settings.Live.DonkeyServerWarning == FALSE ) && ( Settings.eDonkey.EnableToday ) )
01412                 {
01413                         if ( ( ! Settings.eDonkey.MetAutoQuery ) && ( HostCache.eDonkey.CountHosts() < 1 ) )
01414                         {
01415                                 Settings.Live.DonkeyServerWarning = TRUE;
01416                                 PostMessage( WM_COMMAND, ID_HELP_DONKEYSERVERS );
01417                         }
01418                 }
01419         }
01420 
01421 }
01422 
01424 // CMainWnd network menu
01425 
01426 void CMainWnd::OnUpdateNetworkSearch(CCmdUI* pCmdUI) 
01427 {
01428         pCmdUI->Enable( IsWindowEnabled() );
01429 }
01430 
01431 void CMainWnd::OnNetworkSearch() 
01432 {
01433         if ( ! Network.IsWellConnected() ) Network.Connect( TRUE );
01434         
01435         if ( Settings.Search.SearchPanel && ! m_bTrayHide && ! IsIconic() )
01436         {
01437                 m_pWindows.OpenNewSearchWindow();
01438         }
01439         else
01440         {
01441                 CNewSearchDlg dlg;
01442                 if ( dlg.DoModal() != IDOK ) return;
01443                 new CSearchWnd( dlg.GetSearch() );
01444         }
01445         
01446         OpenFromTray();
01447 }
01448 
01449 void CMainWnd::OnUpdateNetworkConnect(CCmdUI* pCmdUI) 
01450 {
01451         pCmdUI->Enable( TRUE );
01452 
01453         UINT nTextID = 0;
01454 
01455         if ( Network.IsWellConnected() )
01456         {
01457                 nTextID = IDS_NETWORK_CONNECTED;
01458                 pCmdUI->SetCheck( TRUE );
01459         }
01460         else if ( Network.IsConnected() )
01461         {
01462                 nTextID = IDS_NETWORK_CONNECTING;
01463                 pCmdUI->SetCheck( TRUE );
01464         }
01465         else
01466         {
01467                 nTextID = IDS_NETWORK_CONNECT;
01468                 pCmdUI->SetCheck( FALSE );
01469         }
01470 
01471         CString strText;
01472         LoadString( strText, nTextID );
01473         pCmdUI->SetText( strText );
01474 }
01475 
01476 void CMainWnd::OnNetworkConnect() 
01477 {
01478         Network.Connect( TRUE );
01479 }
01480 
01481 void CMainWnd::OnUpdateNetworkDisconnect(CCmdUI* pCmdUI) 
01482 {
01483         pCmdUI->Enable( Network.IsConnected() );
01484 }
01485 
01486 void CMainWnd::OnNetworkDisconnect() 
01487 {
01488         Network.Disconnect();
01489 }
01490 
01491 void CMainWnd::OnUpdateNetworkConnectTo(CCmdUI* pCmdUI) 
01492 {
01493         pCmdUI->Enable( TRUE );
01494 }
01495 
01496 void CMainWnd::OnNetworkConnectTo() 
01497 {
01498         CConnectToDlg dlg;
01499         if ( dlg.DoModal() != IDOK ) return;
01500         Network.ConnectTo( dlg.m_sHost, dlg.m_nPort, dlg.m_nProtocol + 1, dlg.m_bNoUltraPeer );
01501 }
01502 
01503 void CMainWnd::OnNetworkBrowseTo() 
01504 {
01505         CConnectToDlg dlg( NULL, TRUE );
01506         if ( dlg.DoModal() != IDOK ) return;
01507 
01508         SOCKADDR_IN pAddress;
01509 
01510         if ( Network.Resolve( dlg.m_sHost, dlg.m_nPort, &pAddress ) )
01511         {
01512                 new CBrowseHostWnd( &pAddress );
01513         }
01514 }
01515 
01516 void CMainWnd::OnUpdateNetworkG2(CCmdUI* pCmdUI) 
01517 {
01518         pCmdUI->SetCheck( Settings.Gnutella2.EnableToday );
01519 }
01520 
01521 void CMainWnd::OnNetworkG2() 
01522 {
01523         if ( Network.IsConnected() && Settings.Gnutella2.EnableToday )
01524         {
01525                 CString strMessage;
01526                 LoadString( strMessage, IDS_NETWORK_DISABLE_G2 );
01527                 
01528                 if ( AfxMessageBox( strMessage, MB_ICONEXCLAMATION|MB_YESNO|MB_DEFBUTTON2 ) == IDYES )
01529                 {
01530                         Settings.Gnutella2.EnableToday = FALSE;
01531                 }
01532         }
01533         else
01534         {
01535                 Settings.Gnutella2.EnableToday = TRUE;
01536                 Network.Connect( TRUE );
01537         }
01538 }
01539 
01540 void CMainWnd::OnUpdateNetworkG1(CCmdUI* pCmdUI) 
01541 {
01542         pCmdUI->SetCheck( Settings.Gnutella1.EnableToday );
01543         pCmdUI->Enable( Settings.GetOutgoingBandwidth() >= 2 );
01544 }
01545 
01546 void CMainWnd::OnNetworkG1() 
01547 {
01548         if ( Network.IsConnected() && Settings.Gnutella1.EnableToday )
01549         {
01550                 Settings.Gnutella1.EnableToday = FALSE;
01551         }
01552         else
01553         {
01554                 Settings.Gnutella1.EnableToday = TRUE;
01555                 Network.Connect( TRUE );
01556         }
01557 }
01558 
01559 void CMainWnd::OnUpdateNetworkED2K(CCmdUI* pCmdUI) 
01560 {
01561         pCmdUI->SetCheck( Settings.eDonkey.EnableToday );
01562         pCmdUI->Enable( Settings.GetOutgoingBandwidth() >= 2 );
01563 }
01564 
01565 void CMainWnd::OnNetworkED2K() 
01566 {
01567         if ( Network.IsConnected() && Settings.eDonkey.EnableToday )
01568         {
01569                 Settings.eDonkey.EnableToday = FALSE;
01570         }
01571         else
01572         {
01573                 Settings.eDonkey.EnableToday = TRUE;
01574                 Network.Connect( TRUE );
01575         }
01576 }
01577 
01578 void CMainWnd::OnUpdateNetworkAutoClose(CCmdUI* pCmdUI) 
01579 {
01580         pCmdUI->Enable( Settings.Live.AutoClose || ( Transfers.GetActiveCount() > 0 ) );
01581         pCmdUI->SetCheck( Settings.Live.AutoClose );
01582 }
01583 
01584 void CMainWnd::OnNetworkAutoClose() 
01585 {
01586         if ( Settings.Live.AutoClose )
01587         {
01588                 Settings.Live.AutoClose = FALSE;
01589         }
01590         else
01591         {
01592                 Network.Disconnect();
01593                 Settings.Live.AutoClose = ( Transfers.GetActiveCount() > 0 );
01594                 
01595                 if ( Settings.Live.AutoClose )
01596                 {
01597                         if ( ! m_bTrayHide ) CloseToTray();
01598                 }
01599                 else
01600                 {
01601                         PostMessage( WM_CLOSE );
01602                 }
01603         }
01604 }
01605 
01606 void CMainWnd::OnNetworkExit() 
01607 {
01608         PostMessage( WM_CLOSE );
01609 }
01610 
01612 // CMainWnd view menu
01613 
01614 void CMainWnd::OnUpdateViewBasic(CCmdUI* pCmdUI) 
01615 {
01616         pCmdUI->SetCheck( Settings.General.GUIMode == GUI_BASIC );
01617 }
01618 
01619 void CMainWnd::OnViewBasic() 
01620 {
01621         if ( Settings.General.GUIMode == GUI_BASIC ) return;
01622         CString strMessage;
01623         LoadString( strMessage, IDS_VIEW_MODE_CONFIRM );
01624         if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
01625         CWaitCursor pCursor;
01626         SetGUIMode( GUI_BASIC );
01627 }
01628 
01629 void CMainWnd::OnUpdateViewTabbed(CCmdUI* pCmdUI) 
01630 {
01631         pCmdUI->SetCheck( Settings.General.GUIMode == GUI_TABBED );
01632 }
01633 
01634 void CMainWnd::OnViewTabbed() 
01635 {
01636         if ( Settings.General.GUIMode == GUI_TABBED ) return;
01637         CString strMessage;
01638         LoadString( strMessage, IDS_VIEW_MODE_CONFIRM );
01639         if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
01640         CWaitCursor pCursor;
01641         SetGUIMode( GUI_TABBED );
01642 }
01643 
01644 void CMainWnd::OnUpdateViewWindowed(CCmdUI* pCmdUI) 
01645 {
01646         pCmdUI->SetCheck( Settings.General.GUIMode == GUI_WINDOWED );
01647 }
01648 
01649 void CMainWnd::OnViewWindowed() 
01650 {
01651         if ( Settings.General.GUIMode == GUI_WINDOWED ) return;
01652         CString strMessage;
01653         LoadString( strMessage, IDS_VIEW_MODE_CONFIRM );
01654         if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
01655         CWaitCursor pCursor;
01656         SetGUIMode( GUI_WINDOWED );
01657 }
01658 
01659 void CMainWnd::OnUpdateViewSystem(CCmdUI* pCmdUI) 
01660 {
01661         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CSystemWnd) ) != NULL );
01662 }
01663 
01664 void CMainWnd::OnViewSystem() 
01665 {
01666         m_pWindows.Open( RUNTIME_CLASS(CSystemWnd), TRUE );
01667         OpenFromTray();
01668 }
01669 
01670 void CMainWnd::OnUpdateViewNeighbours(CCmdUI* pCmdUI) 
01671 {
01672         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CNeighboursWnd) ) != NULL );
01673 }
01674 
01675 void CMainWnd::OnViewNeighbours() 
01676 {
01677         m_pWindows.Open( RUNTIME_CLASS(CNeighboursWnd), TRUE );
01678         OpenFromTray();
01679 }
01680 
01681 void CMainWnd::OnUpdateViewTraffic(CCmdUI* pCmdUI) 
01682 {
01683         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CTrafficWnd) ) != NULL );
01684 }
01685 
01686 void CMainWnd::OnViewTraffic() 
01687 {
01688         if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 )
01689         {
01690                 new CTrafficWnd();
01691         }
01692         else
01693         {
01694                 m_pWindows.Open( RUNTIME_CLASS(CTrafficWnd), TRUE );
01695         }
01696         OpenFromTray();
01697 }
01698 
01699 void CMainWnd::OnUpdateViewDownloads(CCmdUI* pCmdUI) 
01700 {
01701         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CDownloadsWnd) ) != NULL );
01702 }
01703 
01704 void CMainWnd::OnViewDownloads() 
01705 {
01706         m_pWindows.Open( RUNTIME_CLASS(CDownloadsWnd), TRUE );
01707         OpenFromTray();
01708 }
01709 
01710 void CMainWnd::OnUpdateViewUploads(CCmdUI* pCmdUI) 
01711 {
01712         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CUploadsWnd) ) != NULL );
01713 }
01714 
01715 void CMainWnd::OnViewUploads() 
01716 {
01717         m_pWindows.Open( RUNTIME_CLASS(CUploadsWnd), TRUE );
01718         OpenFromTray();
01719 }
01720 
01721 void CMainWnd::OnUpdateViewLibrary(CCmdUI* pCmdUI) 
01722 {
01723         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CLibraryWnd) ) != NULL );
01724 }
01725 
01726 void CMainWnd::OnViewLibrary() 
01727 {
01728         m_pWindows.Open( RUNTIME_CLASS(CLibraryWnd), TRUE );
01729         OpenFromTray();
01730 }
01731 
01732 void CMainWnd::OnUpdateViewMedia(CCmdUI* pCmdUI) 
01733 {
01734         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CMediaWnd) ) != NULL );
01735 }
01736 
01737 void CMainWnd::OnViewMedia() 
01738 {
01739         if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 )
01740         {
01741                 new CMediaWnd();
01742         }
01743         else
01744         {
01745                 m_pWindows.Open( RUNTIME_CLASS(CMediaWnd), TRUE );
01746         }
01747         OpenFromTray();
01748 }
01749 
01750 void CMainWnd::OnUpdateViewHosts(CCmdUI* pCmdUI) 
01751 {
01752         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CHostCacheWnd) ) != NULL );
01753 }
01754 
01755 void CMainWnd::OnViewHosts() 
01756 {
01757         m_pWindows.Open( RUNTIME_CLASS(CHostCacheWnd), TRUE );
01758         OpenFromTray();
01759 }
01760 
01761 void CMainWnd::OnUpdateViewDiscovery(CCmdUI* pCmdUI) 
01762 {
01763         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CDiscoveryWnd) ) != NULL );
01764 }
01765 
01766 void CMainWnd::OnViewDiscovery() 
01767 {
01768         m_pWindows.Open( RUNTIME_CLASS(CDiscoveryWnd), TRUE );
01769         OpenFromTray();
01770 }
01771 
01772 void CMainWnd::OnUpdateViewPackets(CCmdUI* pCmdUI) 
01773 {
01774         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CPacketWnd) ) != NULL );
01775 }
01776 
01777 void CMainWnd::OnViewPackets() 
01778 {
01779         if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 )
01780         {
01781                 new CPacketWnd();
01782         }
01783         else
01784         {
01785                 m_pWindows.Open( RUNTIME_CLASS(CPacketWnd), TRUE );
01786         }
01787         OpenFromTray();
01788 }
01789 
01790 void CMainWnd::OnUpdateViewSearchMonitor(CCmdUI* pCmdUI) 
01791 {
01792         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CSearchMonitorWnd) ) != NULL );
01793 }
01794 
01795 void CMainWnd::OnViewSearchMonitor() 
01796 {
01797         m_pWindows.Open( RUNTIME_CLASS(CSearchMonitorWnd), TRUE );
01798         OpenFromTray();
01799 }
01800 
01801 void CMainWnd::OnUpdateViewResultsMonitor(CCmdUI* pCmdUI) 
01802 {
01803         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CHitMonitorWnd) ) != NULL );
01804 }
01805 
01806 void CMainWnd::OnViewResultsMonitor() 
01807 {
01808         m_pWindows.Open( RUNTIME_CLASS(CHitMonitorWnd), TRUE );
01809         OpenFromTray();
01810 }
01811 
01812 void CMainWnd::OnUpdateViewSecurity(CCmdUI* pCmdUI) 
01813 {
01814         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CSecurityWnd) ) != NULL );
01815 }
01816 
01817 void CMainWnd::OnViewSecurity() 
01818 {
01819         m_pWindows.Open( RUNTIME_CLASS(CSecurityWnd), TRUE );
01820         OpenFromTray();
01821 }
01822 
01823 void CMainWnd::OnUpdateViewHelp(CCmdUI* pCmdUI) 
01824 {
01825         pCmdUI->SetCheck( m_pWindows.Find( RUNTIME_CLASS(CHelpWnd) ) != NULL );
01826 }
01827 
01828 void CMainWnd::OnViewHelp() 
01829 {
01830         m_pWindows.Open( RUNTIME_CLASS(CHelpWnd), TRUE );
01831         OpenFromTray();
01832 }
01833 
01835 // CMainWnd tab menu
01836 
01837 void CMainWnd::OnUpdateTabConnect(CCmdUI* pCmdUI) 
01838 {
01839         CCoolBarItem* pItem = m_wndToolBar.GetID( ID_TAB_CONNECT );
01840         
01841         UINT nTextID = 0;
01842         UINT nTipID = 0;
01843         
01844         if ( Network.IsWellConnected() )
01845         {
01846                 if ( pItem ) pItem->SetCheck( FALSE );
01847                 if ( pItem ) pItem->SetTextColour( RGB( 255, 0, 0 ) );
01848                 m_wndTabBar.SetMessage( IDS_TABBAR_CONNECTED );
01849                 nTextID = IDS_NETWORK_DISCONNECT;
01850                 nTipID  = ID_NETWORK_DISCONNECT;
01851         }
01852         else if ( Network.IsConnected() )
01853         {
01854                 if ( pItem ) pItem->SetCheck( TRUE );
01855                 if ( pItem ) pItem->SetTextColour( CoolInterface.m_crCmdText == 0 ? RGB( 0, 127, 0 ) : CoolInterface.m_crCmdText );
01856                 m_wndTabBar.SetMessage( (UINT)0 );
01857                 nTextID = IDS_NETWORK_CONNECTING;
01858                 nTipID  = ID_NETWORK_DISCONNECT;
01859         }
01860         else
01861         {
01862                 if ( pItem ) pItem->SetCheck( FALSE );
01863                 if ( pItem ) pItem->SetTextColour( CoolInterface.m_crCmdText == 0 ? RGB( 0, 127, 0 ) : CoolInterface.m_crCmdText );
01864                 if ( m_wndToolBar.IsVisible() ) m_wndTabBar.SetMessage( IDS_TABBAR_NOT_CONNECTED );
01865                 nTextID = IDS_NETWORK_CONNECT;
01866                 nTipID  = ID_NETWORK_CONNECT;
01867         }
01868         
01869         CString strText;
01870         
01871         LoadString( strText, nTextID );
01872         if ( pItem ) pItem->SetText( strText );
01873         
01874         LoadString( strText, nTipID );
01875         if ( pItem ) pItem->SetTip( strText );
01876         
01877         if ( pItem ) pItem->SetImage( nTipID );
01878 }
01879 
01880 void CMainWnd::OnTabConnect() 
01881 {
01882         if ( Network.IsConnected() )
01883         {
01884                 CString strMessage;
01885                 LoadString( strMessage, IDS_NETWORK_DISCONNECT_CONFIRM );
01886 
01887                 if ( ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) ||
01888                          ! Network.IsWellConnected() ||
01889                         AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES )
01890                 {
01891                         Network.Disconnect();
01892                 }
01893         }
01894         else
01895         {
01896                 Network.Connect( TRUE );
01897 
01898                 CChildWnd* pActive = m_pWindows.GetActive();
01899 
01900                 if ( ! pActive || ! pActive->IsKindOf( RUNTIME_CLASS(CHomeWnd) ) )
01901                 {
01902                         m_pWindows.Open( RUNTIME_CLASS(CNeighboursWnd) );
01903                 }
01904         }
01905 }
01906 
01907 void CMainWnd::OnUpdateTabHome(CCmdUI* pCmdUI) 
01908 {
01909         CChildWnd* pChild = m_pWindows.GetActive();
01910         pCmdUI->SetCheck( pChild && pChild->IsKindOf( RUNTIME_CLASS(CHomeWnd) ) );
01911 }
01912 
01913 void CMainWnd::OnTabHome() 
01914 {
01915         m_pWindows.Open( RUNTIME_CLASS(CHomeWnd) );
01916         OpenFromTray();
01917 }
01918 
01919 void CMainWnd::OnUpdateTabLibrary(CCmdUI* pCmdUI) 
01920 {
01921         CChildWnd* pChild = m_pWindows.GetActive();
01922         pCmdUI->SetCheck( pChild && pChild->IsKindOf( RUNTIME_CLASS(CLibraryWnd) ) );
01923 }
01924 
01925 void CMainWnd::OnTabLibrary() 
01926 {
01927         m_pWindows.Open( RUNTIME_CLASS(CLibraryWnd) );
01928         OpenFromTray();
01929 }
01930 
01931 void CMainWnd::OnUpdateTabMedia(CCmdUI* pCmdUI) 
01932 {
01933         CMediaWnd* pChild = (CMediaWnd*)m_pWindows.GetActive();
01934         pCmdUI->SetCheck( pChild && pChild->IsKindOf( RUNTIME_CLASS(CMediaWnd) ) );
01935 
01936         if ( CCoolBarItem* pItem = m_wndToolBar.GetID( ID_TAB_MEDIA ) )
01937         {
01938                 if ( pChild = (CMediaWnd*)m_pWindows.Find( RUNTIME_CLASS(CMediaWnd) ) )
01939                 {
01940                         pItem->SetTextColour( pChild->IsPlaying() ? RGB( 0, 0x80, 0 ) : CoolInterface.m_crCmdText );
01941                 }
01942                 else
01943                 {
01944                         pItem->SetTextColour( CoolInterface.m_crCmdText );
01945                 }
01946         }
01947 }
01948 
01949 void CMainWnd::OnTabMedia() 
01950 {
01951         m_pWindows.Open( RUNTIME_CLASS(CMediaWnd) );
01952         theApp.m_bMenuWasVisible = FALSE;
01953         OpenFromTray();
01954 }
01955 
01956 void CMainWnd::OnUpdateTabSearch(CCmdUI* pCmdUI) 
01957 {
01958         CChildWnd* pChild = m_pWindows.GetActive();
01959         // pCmdUI->SetCheck( pChild && pChild->IsKindOf( RUNTIME_CLASS(CSearchPadWnd) ) );
01960         pCmdUI->SetCheck( pChild && pChild->IsKindOf( RUNTIME_CLASS(CSearchWnd) ) );
01961 }
01962 
01963 void CMainWnd::OnTabSearch() 
01964 {
01965         if ( Settings.General.GUIMode != GUI_WINDOWED )
01966         {
01967                 // m_pWindows.Open( RUNTIME_CLASS(CSearchPadWnd) );
01968                 m_pWindows.OpenNewSearchWindow();
01969                 OpenFromTray();
01970         }
01971         else
01972         {
01973                 PostMessage( WM_COMMAND, ID_NETWORK_SEARCH );
01974         }
01975 }
01976 
01977 void CMainWnd::OnUpdateTabTransfers(CCmdUI* pCmdUI) 
01978 {
01979         CChildWnd* pChild = m_pWindows.GetActive();
01980         
01981         if ( pChild != NULL && pChild->m_pGroupParent != NULL )
01982         {
01983                 pChild = pChild->m_pGroupParent;
01984                 if ( ! m_pWindows.Check( pChild ) ) pChild = NULL;
01985         }
01986         
01987         pCmdUI->SetCheck( pChild != NULL && pChild->IsKindOf( RUNTIME_CLASS(CDownloadsWnd) ) );
01988 }
01989 
01990 void CMainWnd::OnTabTransfers() 
01991 {
01992         m_pWindows.Open( RUNTIME_CLASS(CDownloadsWnd) );
01993         OpenFromTray();
01994 }
01995 
01996 void CMainWnd::OnUpdateTabNetwork(CCmdUI* pCmdUI) 
01997 {
01998         CChildWnd* pChild = m_pWindows.GetActive();
01999         
02000         if ( pChild != NULL && pChild->m_pGroupParent != NULL )
02001         {
02002                 pChild = pChild->m_pGroupParent;
02003                 if ( ! m_pWindows.Check( pChild ) ) pChild = NULL;
02004         }
02005         
02006         pCmdUI->SetCheck( pChild != NULL && pChild->IsKindOf( RUNTIME_CLASS(CNeighboursWnd) ) );
02007 }
02008 
02009 void CMainWnd::OnTabNetwork() 
02010 {
02011         m_pWindows.Open( RUNTIME_CLASS(CNeighboursWnd) );
02012         OpenFromTray();
02013 }
02014 
02015 void CMainWnd::OnUpdateTabHelp(CCmdUI* pCmdUI) 
02016 {
02017         CChildWnd* pChild = m_pWindows.GetActive();
02018         pCmdUI->SetCheck( pChild && pChild->IsKindOf( RUNTIME_CLASS(CHelpWnd) ) );
02019 }
02020 
02021 void CMainWnd::OnTabHelp() 
02022 {
02023         m_pWindows.Open( RUNTIME_CLASS(CHelpWnd) );
02024         OpenFromTray();
02025 }
02026 
02028 // CMainWnd tools menu
02029 
02030 void CMainWnd::OnUpdateToolsDownload(CCmdUI* pCmdUI)
02031 {
02032         pCmdUI->Enable( IsWindowEnabled() );
02033 }
02034 
02035 void CMainWnd::OnToolsDownload() 
02036 {
02037         CDownloadDlg dlg;
02038         if ( dlg.DoModal() != IDOK ) return;
02039 
02040         if ( dlg.m_pURL->m_nAction == CShareazaURL::uriDownload )
02041         {
02042                 Downloads.Add( dlg.m_pURL );
02043                 if ( ! Network.IsWellConnected() ) Network.Connect( TRUE );
02044                 m_pWindows.Open( RUNTIME_CLASS(CDownloadsWnd) );
02045         }
02046         else if ( dlg.m_pURL->m_nAction == CShareazaURL::uriSource )
02047         {
02048                 Downloads.Add( dlg.m_pURL );
02049                 m_pWindows.Open( RUNTIME_CLASS(CDownloadsWnd) );
02050         }
02051         else
02052         {
02053                 PostMessage( WM_URL, (WPARAM)dlg.GetURL() );
02054         }
02055 }
02056 
02057 void CMainWnd::OnToolsSkin() 
02058 {
02059         if ( ! IsWindowEnabled() ) return;
02060         CSettingsManagerDlg::Run( _T("CSkinsSettingsPage") );
02061 }
02062 
02063 void CMainWnd::OnToolsLanguage() 
02064 {
02065         if ( ! IsWindowEnabled() ) return;
02066         theApp.WriteProfileInt( _T("Windows"), _T("RunLanguage"), TRUE );
02067         
02068         CLanguageDlg dlg;
02069         
02070         if ( dlg.DoModal() == IDOK )
02071         {
02072                 CWaitCursor pCursor;
02073                 OnSkinChanged( 0, 0 );
02074                 SetGUIMode( Settings.General.GUIMode );
02075         }
02076 }
02077 
02078 
02079 void CMainWnd::OnToolsSeedTorrent()
02080 {
02081         CFileDialog dlgFile( TRUE, _T("torrent"), ( Settings.Downloads.TorrentPath + "\\." ) , OFN_HIDEREADONLY,
02082                 _T("Torrent Files|*.torrent|All Files|*.*||"), this );
02083         
02084         if ( dlgFile.DoModal() != IDOK ) return;
02085         
02086         CTorrentSeedDlg dlgSeed( dlgFile.GetPathName(), TRUE );
02087         dlgSeed.DoModal();
02088 }
02089 
02090 void CMainWnd::OnToolsReseedTorrent()
02091 {
02092         CTorrentSeedDlg dlgSeed( LibraryHistory.LastSeededTorrent.m_sPath, TRUE );
02093         dlgSeed.DoModal();
02094 }
02095 
02096 void CMainWnd::OnDiskSpace()
02097 {
02098         CHelpDlg::Show( _T("GeneralHelp.DiskSpace") );
02099 }
02100 
02101 void CMainWnd::OnDiskWriteFail()
02102 {
02103         CHelpDlg::Show( _T("GeneralHelp.DiskWriteFail") );
02104 }
02105 
02106 void CMainWnd::OnConnectionFail()
02107 {
02108         CHelpDlg::Show( _T("GeneralHelp.ConnectionFail") );
02109 }
02110 
02111 void CMainWnd::OnNoDonkeyServers()
02112 {
02113         CHelpDlg::Show( _T("GeneralHelp.DonkeyServerList") );
02114 }
02115 
02116 void CMainWnd::OnToolsProfile() 
02117 {
02118         CProfileManagerDlg dlg;
02119         dlg.DoModal();
02120 }
02121 
02122 void CMainWnd::OnLibraryFolders() 
02123 {
02124         CShareManagerDlg dlg;
02125         dlg.DoModal();
02126 }
02127 
02128 void CMainWnd::OnToolsWizard() 
02129 {
02130         if ( ! IsWindowEnabled() ) return;
02131         theApp.WriteProfileInt( _T("Windows"), _T("RunWizard"), TRUE );
02132         CWizardSheet::RunWizard( this );
02133 }
02134 
02135 void CMainWnd::OnToolsSettings() 
02136 {
02137         if ( ! IsWindowEnabled() ) return;
02138         CSettingsManagerDlg::Run();
02139 }
02140 
02141 void CMainWnd::OnToolsReskin() 
02142 {
02143         OnSkinChanged( 0, 0 );
02144 }
02145 
02147 // CMainWnd library hook in
02148 
02149 void CMainWnd::OnUpdateLibraryHashPriority(CCmdUI* pCmdUI) 
02150 {
02151         pCmdUI->SetCheck( LibraryBuilder.GetBoostPriority() );
02152 }
02153 
02154 void CMainWnd::OnLibraryHashPriority() 
02155 {
02156         LibraryBuilder.BoostPriority( ! LibraryBuilder.GetBoostPriority() );
02157 }
02158 
02160 // CMainWnd window menu
02161 
02162 void CMainWnd::OnUpdateWindowCascade(CCmdUI* pCmdUI) 
02163 {
02164         pCmdUI->Enable( TRUE );
02165 }
02166 
02167 void CMainWnd::OnWindowCascade() 
02168 {
02169         m_pWindows.Cascade( GetAsyncKeyState( VK_SHIFT ) & 0x8000 );
02170 }
02171 
02172 void CMainWnd::OnUpdateWindowTileHorz(CCmdUI* pCmdUI) 
02173 {
02174         pCmdUI->Enable( Settings.General.GUIMode == GUI_WINDOWED );
02175 }
02176 
02177 void CMainWnd::OnUpdateWindowTileVert(CCmdUI* pCmdUI) 
02178 {
02179         pCmdUI->Enable( Settings.General.GUIMode == GUI_WINDOWED );
02180 }
02181 
02182 void CMainWnd::OnUpdateWindowNavBar(CCmdUI *pCmdUI)
02183 {
02184         pCmdUI->SetCheck( m_wndNavBar.IsVisible() );
02185 }
02186 
02187 void CMainWnd::OnWindowNavBar()
02188 {
02189         ShowControlBar( &m_wndToolBar, FALSE, TRUE );
02190         ShowControlBar( &m_wndNavBar, ! m_wndNavBar.IsVisible(), TRUE );
02191         if ( ! m_wndNavBar.IsVisible() )
02192         {
02193                 if ( ! Network.IsConnected() ) m_wndTabBar.SetMessage( IDS_TABBAR_NOT_CONNECTED );
02194         }
02195         else
02196                 m_wndTabBar.SetMessage( _T("") );
02197 }
02198 
02199 void CMainWnd::OnUpdateWindowToolBar(CCmdUI* pCmdUI) 
02200 {
02201         pCmdUI->SetCheck( m_wndToolBar.IsVisible() );
02202 }
02203 
02204 void CMainWnd::OnWindowToolBar() 
02205 {
02206         ShowControlBar( &m_wndNavBar, FALSE, TRUE );
02207         ShowControlBar( &m_wndToolBar, ! m_wndToolBar.IsVisible(), TRUE );
02208         if ( m_wndToolBar.IsVisible() ) 
02209         {
02210                 if ( ! Network.IsConnected() ) m_wndTabBar.SetMessage( IDS_TABBAR_NOT_CONNECTED );
02211         }
02212         else
02213                 m_wndTabBar.SetMessage( _T("") );
02214 }
02215 
02216 void CMainWnd::OnUpdateWindowTabBar(CCmdUI* pCmdUI) 
02217 {
02218         pCmdUI->SetCheck( m_wndTabBar.IsVisible() );
02219 }
02220 
02221 void CMainWnd::OnWindowTabBar() 
02222 {
02223         ShowControlBar( &m_wndTabBar, ! m_wndTabBar.IsVisible(), TRUE );
02224 }
02225 
02226 void CMainWnd::OnUpdateWindowMonitor(CCmdUI* pCmdUI) 
02227 {
02228         pCmdUI->SetCheck( m_wndMonitorBar.IsVisible() );
02229 }
02230 
02231 void CMainWnd::OnWindowMonitor() 
02232 {
02233         ShowControlBar( &m_wndMonitorBar, ! m_wndMonitorBar.IsVisible(), TRUE );
02234 }
02235 
02236 void CMainWnd::OnUpdateWindowRemote(CCmdUI *pCmdUI)
02237 {
02238         pCmdUI->SetCheck( m_wndRemoteWnd.IsVisible() );
02239 }
02240 
02241 void CMainWnd::OnWindowRemote()
02242 {
02243         if ( m_wndRemoteWnd.IsVisible() )
02244                 m_wndRemoteWnd.DestroyWindow();
02245         else
02246                 m_wndRemoteWnd.Create( &m_wndMonitorBar );
02247 }
02248 
02249 void CMainWnd::OnRemoteClose()
02250 {
02251         if ( m_wndRemoteWnd.IsVisible() ) m_wndRemoteWnd.DestroyWindow();
02252 }
02253 
02254 void CMainWnd::OnUpdateMediaCommand(CCmdUI *pCmdUI)
02255 {
02256         if ( CMediaFrame::g_pMediaFrame != NULL )
02257                 pCmdUI->ContinueRouting();
02258         else
02259                 pCmdUI->Enable( TRUE );
02260 }
02261 
02262 void CMainWnd::OnMediaCommand()
02263 {
02264         if ( CMediaFrame::g_pMediaFrame == NULL ) OnTabMedia();
02265         if ( CMediaFrame::g_pMediaFrame == NULL ) return;
02266         CMediaFrame::g_pMediaFrame->SendMessage( WM_COMMAND, GetCurrentMessage()->wParam );
02267 }
02268 
02270 // CMainWnd help menu
02271 
02272 void CMainWnd::OnHelpAbout() 
02273 {
02274         CAboutDlg dlg;
02275         dlg.DoModal();
02276         Neighbours.IsG1UltrapeerCapable( TRUE );
02277         Neighbours.IsG2HubCapable( TRUE );
02278 }
02279 
02280 void CMainWnd::OnHelpHomepage() 
02281 {
02282         ShellExecute( GetSafeHwnd(), _T("open"),
02283                 _T("http://www.shareaza.com/?Version=") + theApp.m_sVersion,
02284                 NULL, NULL, SW_SHOWNORMAL );
02285 }
02286 
02287 void CMainWnd::OnHelpWeb1() 
02288 {
02289         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/external/?link1"),
02290                 NULL, NULL, SW_SHOWNORMAL );
02291 }
02292 
02293 void CMainWnd::OnHelpWeb2() 
02294 {
02295         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/external/?link2"),
02296                 NULL, NULL, SW_SHOWNORMAL );
02297 }
02298 
02299 void CMainWnd::OnHelpWeb3() 
02300 {
02301         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/external/?link3"),
02302                 NULL, NULL, SW_SHOWNORMAL );
02303 }
02304 
02305 void CMainWnd::OnHelpWeb4() 
02306 {
02307         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/external/?link4"),
02308                 NULL, NULL, SW_SHOWNORMAL );
02309 }
02310 
02311 void CMainWnd::OnHelpWeb5() 
02312 {
02313         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/external/?link5"),
02314                 NULL, NULL, SW_SHOWNORMAL );
02315 }
02316 
02317 void CMainWnd::OnHelpWeb6() 
02318 {
02319         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/external/?link6"),
02320                 NULL, NULL, SW_SHOWNORMAL );
02321 }
02322 
02323 void CMainWnd::OnHelpFaq() 
02324 {
02325         ShellExecute( GetSafeHwnd(), _T("open"),
02326                 _T("http://www.shareaza.com/help/?faq"),
02327                 NULL, NULL, SW_SHOWNORMAL );
02328 }
02329 
02330 void CMainWnd::OnHelpGuide() 
02331 {
02332         ShellExecute( GetSafeHwnd(), _T("open"),
02333                 _T("http://www.shareaza.com/help/?guide"),
02334                 NULL, NULL, SW_SHOWNORMAL );
02335 }
02336 
02337 void CMainWnd::OnHelpForums() 
02338 {
02339         ShellExecute( GetSafeHwnd(), _T("open"),
02340                 _T("http://forums.shareaza.com/"),
02341                 NULL, NULL, SW_SHOWNORMAL );
02342 }
02343 
02344 void CMainWnd::OnHelpUpdate() 
02345 {
02346         ShellExecute( GetSafeHwnd(), _T("open"),
02347                 _T("http://www.shareaza.com/help/update/?Version=") + theApp.m_sVersion,
02348                 NULL, NULL, SW_SHOWNORMAL );
02349 }
02350 
02351 void CMainWnd::OnHelpRouter()
02352 {
02353         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/?router"),
02354                 NULL, NULL, SW_SHOWNORMAL );
02355 }
02356 
02357 void CMainWnd::OnHelpSecurity()
02358 {
02359         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/?security"),
02360                 NULL, NULL, SW_SHOWNORMAL );
02361 }
02362 
02363 void CMainWnd::OnHelpCodec()
02364 {
02365         ShellExecute( GetSafeHwnd(), _T("open"), _T("http://www.shareaza.com/help/?codec"),
02366                 NULL, NULL, SW_SHOWNORMAL );
02367 }
02368 
02369 void CMainWnd::OnHelpWarnings() 
02370 {
02371         if ( IsWindowEnabled() && IsWindowVisible() && ! IsIconic() )
02372         {
02373                 theApp.WriteProfileInt( _T("Windows"), _T("RunWarnings"), TRUE );
02374                 CWarningsDlg dlg;
02375                 dlg.DoModal();
02376         }
02377 }
02378 
02379 void CMainWnd::OnHelpPromote() 
02380 {
02381         if ( IsWindowEnabled() && IsWindowVisible() && ! IsIconic() )
02382         {
02383                 theApp.WriteProfileInt( _T("Windows"), _T("RunPromote"), TRUE );
02384                 CPromoteDlg dlg;
02385                 dlg.DoModal();
02386         }
02387 }
02388 
02390 // CMainWnd skin forwarding
02391 
02392 void CMainWnd::OnSize(UINT nType, int cx, int cy) 
02393 {
02394         if ( m_pSkin ) m_pSkin->OnSize( this );
02395         CMDIFrameWnd::OnSize( nType, cx, cy );
02396 }
02397 
02398 void CMainWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
02399 {
02400         if ( m_pSkin )
02401                 m_pSkin->OnNcCalcSize( this, bCalcValidRects, lpncsp );
02402         else
02403                 CMDIFrameWnd::OnNcCalcSize( bCalcValidRects, lpncsp );
02404 }
02405 
02406 UINT CMainWnd::OnNcHitTest(CPoint point) 
02407 {
02408         if ( m_pSkin )
02409                 return m_pSkin->OnNcHitTest( this, point, TRUE );
02410         else
02411                 return CMDIFrameWnd::OnNcHitTest( point );
02412 }
02413 
02414 void CMainWnd::OnNcPaint() 
02415 {
02416         if ( m_pSkin )
02417                 m_pSkin->OnNcPaint( this );
02418         else
02419                 CMDIFrameWnd::OnNcPaint();
02420 }
02421 
02422 BOOL CMainWnd::OnNcActivate(BOOL bActive) 
02423 {
02424         if ( m_pSkin )
02425         {
02426                 m_pSkin->OnNcActivate( this, IsWindowEnabled() && ( bActive || ( m_nFlags & WF_STAYACTIVE ) ) );
02427                 return TRUE;
02428         }
02429         else
02430         {
02431                 return CMDIFrameWnd::OnNcActivate( bActive );
02432         }
02433 }
02434 
02435 void CMainWnd::OnNcMouseMove(UINT nHitTest, CPoint point) 
02436 {
02437         if ( m_pSkin ) m_pSkin->OnNcMouseMove( this, nHitTest, point );
02438         CMDIFrameWnd::OnNcMouseMove( nHitTest, point );
02439 }
02440 
02441 void CMainWnd::OnNcLButtonDown(UINT nHitTest, CPoint point) 
02442 {
02443         if ( m_pSkin && m_pSkin->OnNcLButtonDown( this, nHitTest, point ) ) return;
02444         CMDIFrameWnd::OnNcLButtonDown( nHitTest, point );
02445 }
02446 
02447 void CMainWnd::OnNcLButtonUp(UINT nHitTest, CPoint point) 
02448 {
02449         if ( m_pSkin && m_pSkin->OnNcLButtonUp( this, nHitTest, point ) ) return;
02450         CMDIFrameWnd::OnNcLButtonUp( nHitTest, point );
02451 }
02452 
02453 void CMainWnd::OnNcLButtonDblClk(UINT nHitTest, CPoint point) 
02454 {
02455         if ( m_pSkin && m_pSkin->OnNcLButtonDblClk( this, nHitTest, point ) ) return;
02456         CMDIFrameWnd::OnNcLButtonDblClk( nHitTest, point );
02457 }
02458 
02459 LONG CMainWnd::OnSetText(WPARAM wParam, LPARAM lParam)
02460 {
02461         if ( m_pSkin )
02462         {
02463                 BOOL bVisible = IsWindowVisible();
02464                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
02465                 LONG lResult = Default();
02466                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
02467                 if ( m_pSkin ) m_pSkin->OnSetText( this );
02468                 return lResult;
02469         }
02470         else
02471         {
02472                 return Default();
02473         }
02474 }
02475 
02477 // CMainWnd IDropTarget implementation
02478 
02479 IMPLEMENT_UNKNOWN(CMainWnd, DropTarget)
02480 
02481 STDMETHODIMP CMainWnd::XDropTarget::DragEnter(IDataObject FAR* pDataObj, DWORD grfKeyState, POINTL pt, DWORD FAR* pdwEffect)
02482 {
02483         METHOD_PROLOGUE( CMainWnd, DropTarget )
02484         
02485         if ( ObjectToFiles( pDataObj ) )
02486         {
02487                 *pdwEffect = DROPEFFECT_COPY;
02488                 return S_OK;
02489         }
02490         else if ( ObjectToURL( pDataObj ).GetLength() > 0 )
02491         {
02492                 *pdwEffect = DROPEFFECT_LINK;
02493                 return S_OK;
02494         }
02495         else
02496         {
02497                 *pdwEffect = DROPEFFECT_NONE;
02498                 return E_UNEXPECTED;
02499         }
02500 }
02501 
02502 STDMETHODIMP CMainWnd::XDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD FAR* pdwEffect)
02503 {
02504         METHOD_PROLOGUE( CMainWnd, DropTarget )
02505         
02506         if ( m_pFiles.GetCount() > 0 )
02507         {
02508                 CPoint point( pt.x, pt.y );
02509                 pThis->ClientToScreen( &point );
02510                 *pdwEffect = DROPEFFECT_NONE;
02511                 
02512                 if ( IsTorrentFile() )
02513                 {
02514                         *pdwEffect = DROPEFFECT_COPY;
02515                 }
02516                 else if ( CChildWnd* pChild = pThis->m_pWindows.FindFromPoint( point ) )
02517                 {
02518                         if ( pChild->OnDropFiles( m_pFiles, point, FALSE ) )
02519                         {
02520                                 *pdwEffect = DROPEFFECT_COPY;
02521                         }
02522                 }
02523         }
02524         else
02525         {
02526                 *pdwEffect = DROPEFFECT_LINK;
02527         }
02528         
02529         return S_OK;
02530 }
02531 
02532 STDMETHODIMP CMainWnd::XDropTarget::DragLeave()
02533 {
02534         METHOD_PROLOGUE( CMainWnd, DropTarget )
02535         return S_OK;
02536 }
02537 
02538 STDMETHODIMP CMainWnd::XDropTarget::Drop(IDataObject FAR* pDataObj, DWORD grfKeyState, POINTL pt, DWORD FAR* pdwEffect)
02539 {
02540         METHOD_PROLOGUE( CMainWnd, DropTarget )
02541         
02542         if ( ObjectToFiles( pDataObj ) )
02543         {
02544                 CPoint point( pt.x, pt.y );
02545                 pThis->ClientToScreen( &point );
02546                 
02547                 if ( IsTorrentFile() )
02548                 {
02549                         theApp.Message( MSG_SYSTEM, IDS_BT_PREFETCH_FILE, (LPCTSTR)m_pFiles.GetHead() );
02550                         
02551                         CBTInfo* pTorrent = new CBTInfo();
02552                         
02553                         if ( pTorrent->LoadTorrentFile( m_pFiles.GetHead() ) )
02554                         {
02555                                 if ( pTorrent->HasEncodingError() ) theApp.Message( MSG_SYSTEM, _T("Possible encoding error detected while parsing torrent") );
02556                                 CShareazaURL* pURL = new CShareazaURL( pTorrent );
02557                                 if ( pThis->PostMessage( WM_URL, (WPARAM)pURL ) ) return S_OK;
02558                                 delete pURL;
02559                         }
02560                         
02561                         delete pTorrent;
02562                         theApp.Message( MSG_ERROR, IDS_BT_PREFETCH_ERROR, (LPCTSTR)m_pFiles.GetHead() );
02563                 }
02564                 else if ( CChildWnd* pChild = pThis->m_pWindows.FindFromPoint( point ) )
02565                 {
02566                         pChild->OnDropFiles( m_pFiles, point, TRUE );
02567                 }
02568         }
02569         else
02570         {
02571                 CString strURL = ObjectToURL( pDataObj );
02572                 theApp.Message( MSG_SYSTEM, IDS_URL_RECEIVED, (LPCTSTR)strURL );
02573                 
02574                 CShareazaURL* pURL = new CShareazaURL();
02575                 if ( pURL->Parse( strURL ) && pThis->PostMessage( WM_URL, (WPARAM)pURL ) ) return S_OK;
02576                 delete pURL;
02577                 
02578                 theApp.Message( MSG_ERROR, IDS_URL_PARSE_ERROR );
02579         }
02580         
02581         return S_OK;
02582 }
02583 
02584 CString CMainWnd::XDropTarget::ObjectToURL(IDataObject* pObject)
02585 {
02586         FORMATETC pFormat = { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
02587         STGMEDIUM pMedium;
02588         CString str;
02589         
02590         pFormat.cfFormat = RegisterClipboardFormat( _T("UniformResourceLocator") );
02591         
02592         if ( SUCCEEDED( pObject->GetData( &pFormat, &pMedium ) ) && pMedium.hGlobal != NULL )
02593         {
02594                 if ( LPCSTR psz = (LPCSTR)GlobalLock( pMedium.hGlobal ) )
02595                 {
02596                         str = psz;
02597                         GlobalUnlock( pMedium.hGlobal );
02598                 }
02599                 
02600                 ReleaseStgMedium( &pMedium );
02601         }
02602         
02603         return str;
02604 }
02605 
02606 BOOL CMainWnd::XDropTarget::ObjectToFiles(IDataObject* pObject)
02607 {
02608         FORMATETC pFormat = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
02609         STGMEDIUM pMedium;
02610 
02611         m_pFiles.RemoveAll();
02612         
02613         if ( FAILED( pObject->GetData( &pFormat, &pMedium ) ) ) return FALSE;
02614         if ( pMedium.hGlobal == NULL ) return FALSE;
02615         
02616         HDROP   hDropInfo       = (HDROP)pMedium.hGlobal;
02617         UINT    nCount          = DragQueryFile( hDropInfo, 0xFFFFFFFF, NULL, 0 );
02618         
02619         for ( UINT nFile = 0 ; nFile < nCount ; nFile++ )
02620         {
02621                 TCHAR szFile[MAX_PATH];
02622                 DragQueryFile( hDropInfo, nFile, szFile, MAX_PATH );
02623                 m_pFiles.AddTail( szFile );
02624         }
02625         
02626         ReleaseStgMedium( &pMedium );
02627         
02628         return ( m_pFiles.GetCount() > 0 );
02629 }
02630 
02631 BOOL CMainWnd::XDropTarget::IsTorrentFile() const
02632 {
02633         return  m_pFiles.GetCount() == 1 &&
02634                         _tcsistr( m_pFiles.GetHead(), _T(".torrent") ) != NULL;
02635 }

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