00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Downloads_Bittorrent.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 CDownloads_Bittorrent::CDownloads_Bittorrent()
00017 {
00018 m_vTabs.push_back (&m_general);
00019 m_vTabs.push_back (&m_peers);
00020 m_vTabs.push_back (&m_files);
00021 }
00022
00023 CDownloads_Bittorrent::~CDownloads_Bittorrent()
00024 {
00025 }
00026
00027 BEGIN_MESSAGE_MAP(CDownloads_Bittorrent, CTabCtrl)
00028
00029 ON_WM_CREATE()
00030 ON_WM_SIZE()
00031 ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
00032 ON_WM_SHOWWINDOW()
00033
00034 END_MESSAGE_MAP()
00035
00036 BOOL CDownloads_Bittorrent::Create(CWnd *pParent)
00037 {
00038 CRect rc (50, 50, 275, 70);
00039
00040 if (FALSE == CTabCtrl::Create (TCS_SINGLELINE|TCS_RIGHTJUSTIFY|TCS_FOCUSNEVER,
00041 rc, pParent, 0x5a11))
00042 return FALSE;
00043
00044 LOGFONT lf;
00045 NONCLIENTMETRICS nm;
00046
00047 ZeroMemory (&nm, sizeof (nm));
00048 nm.cbSize = sizeof (nm);
00049 SystemParametersInfo (SPI_GETNONCLIENTMETRICS, nm.cbSize, &nm, 0);
00050 lf = nm.lfMenuFont;
00051 lf.lfCharSet = DEFAULT_CHARSET;
00052
00053 m_fontItems.CreateFontIndirect (&lf);
00054
00055 SetFont (&m_fontItems, FALSE);
00056
00057 return TRUE;
00058 }
00059
00060 void CDownloads_Bittorrent::Set_ActiveDownload(vmsDownloadSmartPtr dld)
00061 {
00062 if (dld != NULL && dld->pMgr->IsBittorrent () == FALSE)
00063 dld = NULL;
00064 m_general.set_ActiveDownload (dld);
00065 m_peers.set_ActiveDownload (dld);
00066 m_files.set_ActiveDownload (dld);
00067 }
00068
00069 void CDownloads_Bittorrent::ApplyLanguage()
00070 {
00071 TCITEM item;
00072 ZeroMemory (&item, sizeof (item));
00073
00074 item.mask = TCIF_TEXT;
00075 item.pszText = (LPSTR) LS (L_GENERAL);
00076 SetItem (0, &item);
00077
00078 item.pszText = (LPSTR) LS (L_PEERS);
00079 SetItem (1, &item);
00080
00081 item.pszText = (LPSTR) LS (L_FILES);
00082 SetItem (2, &item);
00083
00084 m_general.ApplyLanguage ();
00085 m_peers.ApplyLanguage ();
00086 m_files.ApplyLanguage ();
00087 }
00088
00089 int CDownloads_Bittorrent::OnCreate(LPCREATESTRUCT lpCreateStruct)
00090 {
00091 if (CTabCtrl::OnCreate(lpCreateStruct) == -1)
00092 return -1;
00093
00094 m_general.Create (this);
00095 m_peers.Create (this);
00096 m_files.Create (this);
00097
00098 InsertItem (0, "");
00099 InsertItem (1, "");
00100 InsertItem (2, "");
00101
00102 set_ActiveTab (0);
00103
00104 return 0;
00105 }
00106
00107 void CDownloads_Bittorrent::OnSize(UINT nType, int cx, int cy)
00108 {
00109 CTabCtrl::OnSize(nType, cx, cy);
00110 ApplySize ();
00111 }
00112
00113 void CDownloads_Bittorrent::UpdateStat()
00114 {
00115 m_general.UpdateStat ();
00116 }
00117
00118 void CDownloads_Bittorrent::set_ActiveTab(int nTab)
00119 {
00120 SetCurSel (nTab);
00121 nTab = GetCurSel ();
00122 ApplyCurTab ();
00123 }
00124
00125 void CDownloads_Bittorrent::ApplySize()
00126 {
00127 int nTab = GetCurSel ();
00128 if (nTab == -1)
00129 return;
00130
00131 CRect rc;
00132 GetItemRect (0, &rc);
00133
00134 int x = 2, y = rc.bottom + 3;
00135
00136 GetClientRect (&rc);
00137
00138 m_vTabs [nTab]->MoveWindow (x, y, rc.Width () - x - 3, rc.Height () - y - 3);
00139 }
00140
00141 void CDownloads_Bittorrent::ApplyCurTab()
00142 {
00143 size_t nCur = GetCurSel ();
00144
00145 ApplySize ();
00146
00147 for (size_t i = 0; i < m_vTabs.size (); i++)
00148 m_vTabs [i]->ShowWindow (nCur == i ? SW_SHOW : SW_HIDE);
00149 }
00150
00151 void CDownloads_Bittorrent::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
00152 {
00153 ApplyCurTab ();
00154 *pResult = 0;
00155 }
00156
00157 void CDownloads_Bittorrent::UpdatePeersStat()
00158 {
00159 m_general.UpdatePeersStat ();
00160 m_peers.UpdateStat ();
00161 }
00162
00163 void CDownloads_Bittorrent::OnShowWindow(BOOL bShow, UINT nStatus)
00164 {
00165 CTabCtrl::OnShowWindow(bShow, nStatus);
00166 size_t nCur = GetCurSel ();
00167 if (nCur != -1)
00168 m_vTabs [nCur]->PostMessage (WM_COMMAND, ID_UPDATE);
00169 }