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

CtrlDownloadTabBar.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlDownloadTabBar.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "CoolInterface.h"
00026 #include "CoolMenu.h"
00027 #include "Transfers.h"
00028 #include "Downloads.h"
00029 #include "Download.h"
00030 #include "DownloadGroup.h"
00031 #include "DownloadGroups.h"
00032 #include "CtrlDownloadTabBar.h"
00033 #include "DlgDownloadGroup.h"
00034 #include "ShellIcons.h"
00035 #include "Skin.h"
00036 
00037 #ifdef _DEBUG
00038 #define new DEBUG_NEW
00039 #undef THIS_FILE
00040 static char THIS_FILE[] = __FILE__;
00041 #endif
00042 
00043 BEGIN_MESSAGE_MAP(CDownloadTabBar, CControlBar)
00044         ON_WM_LBUTTONDOWN()
00045         ON_WM_RBUTTONUP()
00046         ON_WM_LBUTTONDBLCLK()
00047         ON_WM_MOUSEMOVE()
00048         ON_WM_TIMER()
00049         ON_WM_CREATE()
00050         ON_WM_MEASUREITEM()
00051         ON_WM_DRAWITEM()
00052         ON_COMMAND(ID_DOWNLOAD_GROUP_NEW, OnDownloadGroupNew)
00053         ON_UPDATE_COMMAND_UI(ID_DOWNLOAD_GROUP_REMOVE, OnUpdateDownloadGroupRemove)
00054         ON_COMMAND(ID_DOWNLOAD_GROUP_REMOVE, OnDownloadGroupRemove)
00055         ON_UPDATE_COMMAND_UI(ID_DOWNLOAD_GROUP_PROPERTIES, OnUpdateDownloadGroupProperties)
00056         ON_COMMAND(ID_DOWNLOAD_GROUP_PROPERTIES, OnDownloadGroupProperties)
00057         ON_UPDATE_COMMAND_UI(ID_DOWNLOAD_GROUP_RESUME, OnUpdateDownloadGroupResume)
00058         ON_COMMAND(ID_DOWNLOAD_GROUP_RESUME, OnDownloadGroupResume)
00059         ON_UPDATE_COMMAND_UI(ID_DOWNLOAD_GROUP_PAUSE, OnUpdateDownloadGroupPause)
00060         ON_COMMAND(ID_DOWNLOAD_GROUP_PAUSE, OnDownloadGroupPause)
00061         ON_UPDATE_COMMAND_UI(ID_DOWNLOAD_GROUP_CLEAR, OnUpdateDownloadGroupClear)
00062         ON_COMMAND(ID_DOWNLOAD_GROUP_CLEAR, OnDownloadGroupClear)
00063 END_MESSAGE_MAP()
00064 
00065 
00067 // CDownloadTabBar construction
00068 
00069 CDownloadTabBar::CDownloadTabBar()
00070 {
00071         m_bTimer                = FALSE;
00072         m_bMenuGray             = FALSE;
00073         m_nCookie               = 0;
00074         m_nMaximumWidth = 140;
00075         m_nMessage              = 0;
00076         m_pHot                  = NULL;
00077 }
00078 
00079 CDownloadTabBar::~CDownloadTabBar()
00080 {
00081         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00082         {
00083                 delete (TabItem*)m_pItems.GetNext( pos );
00084         }
00085         
00086         m_pItems.RemoveAll();
00087 }
00088 
00090 // CDownloadTabBar operations
00091 
00092 BOOL CDownloadTabBar::Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID)
00093 {
00094         CRect rc;
00095         dwStyle |= WS_CHILD;
00096         return CWnd::Create( NULL, NULL, dwStyle, rc, pParentWnd, nID, NULL );
00097 }
00098 
00099 void CDownloadTabBar::SetWatermark(HBITMAP hBitmap)
00100 {
00101         if ( m_bmImage.m_hObject != NULL ) m_bmImage.DeleteObject();
00102         if ( hBitmap != NULL ) m_bmImage.Attach( hBitmap );
00103 }
00104 
00106 // CDownloadTabBar message handlers
00107 
00108 int CDownloadTabBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00109 {
00110         if ( CControlBar::OnCreate( lpCreateStruct ) == -1 ) return -1;
00111         m_dwStyle |= CBRS_BORDER_3D;
00112         return 0;
00113 }
00114 
00115 CSize CDownloadTabBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
00116 {
00117         CSize size( 32767, 26 );
00118         
00119         if ( CWnd* pParent = AfxGetMainWnd() )
00120         {
00121                 CRect rc;
00122                 pParent->GetWindowRect( &rc );
00123                 if ( rc.Width() > 32 ) size.cx = rc.Width() + 2;
00124         }
00125         
00126         return size;
00127 }
00128 
00129 void CDownloadTabBar::Update(int nCookie)
00130 {
00131         CSingleLock pLock( &DownloadGroups.m_pSection, TRUE );
00132         
00133         if ( m_nCookie != DownloadGroups.GetGroupCookie() )
00134         {
00135                 UpdateGroups( nCookie );
00136         }
00137         else
00138         {
00139                 UpdateStates( nCookie );
00140         }
00141 }
00142 
00143 void CDownloadTabBar::UpdateGroups(int nCookie)
00144 {
00145         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00146         {
00147                 delete (TabItem*)m_pItems.GetNext( pos );
00148         }
00149         
00150         m_pItems.RemoveAll();
00151         
00152         BOOL bFoundHot = ( m_pHot == NULL );
00153         
00154         for ( POSITION pos = DownloadGroups.GetIterator() ; pos ; )
00155         {
00156                 CDownloadGroup* pGroup = DownloadGroups.GetNext( pos );
00157                 m_pItems.AddTail( new TabItem( pGroup, nCookie ) );
00158                 
00159                 if ( ! bFoundHot && pGroup == m_pHot->m_pGroup ) bFoundHot = TRUE;
00160         }
00161         
00162         if ( ! bFoundHot ) m_pHot = NULL;
00163         
00164         m_nCookie = DownloadGroups.GetGroupCookie();
00165         Invalidate();
00166 }
00167 
00168 void CDownloadTabBar::UpdateStates(int nCookie)
00169 {
00170         BOOL bChanged = FALSE;
00171         
00172         for ( POSITION posNext = m_pItems.GetHeadPosition() ; posNext ; )
00173         {
00174                 POSITION posThis        = posNext;
00175                 TabItem* pItem          = (TabItem*)m_pItems.GetNext( posNext );
00176                 
00177                 if ( DownloadGroups.Check( pItem->m_pGroup ) )
00178                 {
00179                         bChanged |= pItem->Update( nCookie );
00180                 }
00181                 else
00182                 {
00183                         m_pItems.RemoveAt( posThis );
00184                         delete pItem;
00185                 }
00186         }
00187         
00188         if ( bChanged ) Invalidate();
00189 }
00190 
00191 CDownloadTabBar::TabItem* CDownloadTabBar::HitTest(const CPoint& point, CRect* pItemRect) const
00192 {
00193         if ( m_pItems.IsEmpty() ) return NULL;
00194         
00195         CRect rc;
00196         GetClientRect( &rc );
00197         CalcInsideRect( rc, FALSE );
00198         
00199         rc.left -= m_cyTopBorder;
00200         rc.top -= m_cxLeftBorder;
00201         rc.right += m_cyBottomBorder;
00202         rc.bottom += m_cxRightBorder;
00203         
00204         CRect rcItem( rc.left + 3, rc.top + 1, 0, rc.bottom - 1 );
00205         rcItem.right = ( rc.Width() - 3 * m_pItems.GetCount() ) / m_pItems.GetCount() + 3;
00206         rcItem.right = min( rcItem.right, LONG(m_nMaximumWidth) );
00207         
00208         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00209         {
00210                 TabItem* pItem = (TabItem*)m_pItems.GetNext( pos );
00211                 
00212                 if ( rcItem.PtInRect( point ) )
00213                 {
00214                         if ( pItemRect ) *pItemRect = rcItem;
00215                         return pItem;
00216                 }
00217                 
00218                 rcItem.OffsetRect( rcItem.Width() + 3, 0 );
00219         }
00220         
00221         return NULL;
00222 }
00223 
00224 int CDownloadTabBar::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
00225 {
00226         CRect rcItem;
00227         TabItem* pItem = HitTest( point, &rcItem );
00228         
00229         if ( pItem == NULL ) return -1;
00230         if ( pTI == NULL ) return 1;
00231         
00232         pTI->uFlags             = 0;
00233         pTI->hwnd               = GetSafeHwnd();
00234         pTI->uId                = (UINT)pItem->m_pGroup;
00235         pTI->rect               = rcItem;
00236         pTI->lpszText   = _tcsdup( pItem->m_sCaption );
00237         
00238         return pTI->uId;
00239 }
00240 
00241 void CDownloadTabBar::DoPaint(CDC* pDC)
00242 {
00243         ASSERT_VALID(this);
00244         ASSERT_VALID(pDC);
00245         
00246         CDC* pOutDC = pDC;
00247         CRect rc;
00248         
00249         GetClientRect( &rc );
00250         
00251         if ( m_bmImage.m_hObject != NULL )
00252         {
00253                 pDC = CoolInterface.GetBuffer( *pDC, rc.Size() );
00254                 CoolInterface.DrawWatermark( pDC, &rc, &m_bmImage );
00255         }
00256         
00257         DrawBorders( pDC, rc );
00258         
00259         CFont* pOldFont = (CFont*)pDC->SelectObject( &CoolInterface.m_fntNormal );
00260         
00261         if ( m_pItems.GetCount() )
00262         {
00263                 CRect rcItem( rc.left + 3, rc.top + 1, 0, rc.bottom - 1 );
00264                 rcItem.right = ( rc.Width() - 3 * m_pItems.GetCount() ) / m_pItems.GetCount() + 3;
00265                 rcItem.right = min( rcItem.right, LONG(m_nMaximumWidth) );
00266                 
00267                 for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00268                 {
00269                         TabItem* pItem = (TabItem*)m_pItems.GetNext( pos );
00270                         
00271                         pItem->Paint( this, pDC, &rcItem, m_pHot == pItem, pDC != pOutDC );
00272                         pDC->ExcludeClipRect( &rcItem );
00273                         
00274                         rcItem.OffsetRect( rcItem.Width() + 3, 0 );
00275                 }
00276                 
00277                 if ( pDC == pOutDC ) pDC->FillSolidRect( &rc, CoolInterface.m_crMidtone );
00278         }
00279         else
00280         {
00281                 CSize  sz = pDC->GetTextExtent( m_sMessage );
00282                 CPoint pt = rc.CenterPoint();
00283                 pt.x -= sz.cx / 2; pt.y -= sz.cy / 2 + 1;
00284                 
00285                 pDC->SetBkColor( CoolInterface.m_crMidtone );
00286                 pDC->SetTextColor( CoolInterface.m_crDisabled );
00287                 
00288                 if ( pDC == pOutDC )
00289                 {
00290                         pDC->SetBkMode( OPAQUE );
00291                         pDC->ExtTextOut( pt.x, pt.y, ETO_CLIPPED|ETO_OPAQUE, &rc, m_sMessage, NULL );
00292                 }
00293                 else
00294                 {
00295                         pDC->SetBkMode( TRANSPARENT );
00296                         pDC->ExtTextOut( pt.x, pt.y, ETO_CLIPPED, &rc, m_sMessage, NULL );
00297                 }
00298         }
00299         
00300         pDC->SelectObject( pOldFont );
00301         
00302         if ( pDC != pOutDC )
00303         {
00304                 GetClientRect( &rc );
00305                 pOutDC->BitBlt( 0, 0, rc.Width(), rc.Height(), pDC, 0, 0, SRCCOPY );
00306                 pDC->SelectClipRgn( NULL );
00307         }
00308 }
00309 
00310 void CDownloadTabBar::OnMouseMove(UINT nFlags, CPoint point) 
00311 {
00312         TabItem* pItem = HitTest( point );
00313         
00314         if ( pItem != m_pHot )
00315         {
00316                 m_pHot = pItem;
00317                 Invalidate();
00318         }
00319         
00320         if ( ! m_bTimer && m_pHot )
00321         {
00322                 SetTimer( 1, 100, NULL );
00323                 m_bTimer = TRUE;
00324         }
00325         else if ( m_bTimer && ! m_pHot )
00326         {
00327                 KillTimer( 1 );
00328                 m_bTimer = FALSE;
00329         }
00330         
00331         CControlBar::OnMouseMove( nFlags, point );
00332 }
00333 
00334 void CDownloadTabBar::OnTimer(UINT nIDEvent) 
00335 {
00336         if ( nIDEvent == 1 )
00337         {
00338                 CRect rcWindow;
00339                 CPoint point;
00340                 
00341                 GetClientRect( &rcWindow );
00342                 ClientToScreen( &rcWindow );
00343                 GetCursorPos( &point );
00344                 
00345                 if ( ! rcWindow.PtInRect( point ) )
00346                 {
00347                         KillTimer( nIDEvent );
00348                         m_pHot          = NULL;
00349                         m_bTimer        = FALSE;
00350                         Invalidate();
00351                 }
00352         }
00353         
00354         CControlBar::OnTimer( nIDEvent );
00355 }
00356 
00357 void CDownloadTabBar::OnLButtonDown(UINT nFlags, CPoint point) 
00358 {
00359         if ( TabItem* pHit = HitTest( point ) )
00360         {
00361                 BOOL bShift             = ( nFlags & MK_SHIFT ) != 0;
00362                 BOOL bControl   = ( nFlags & MK_CONTROL ) != 0;
00363                 BOOL bChanged   = FALSE;
00364                 
00365                 if ( bControl )
00366                 {
00367                         bChanged |= pHit->Select( ! pHit->m_bSelected );
00368                 }
00369                 else if ( bShift )
00370                 {
00371                         bChanged |= pHit->Select( TRUE );
00372                 }
00373                 else
00374                 {
00375                         bChanged |= Select( pHit );
00376                 }
00377                 
00378                 if ( bChanged ) NotifySelection();
00379                 
00380                 return;
00381         }
00382         
00383         CControlBar::OnLButtonDown( nFlags, point );
00384 }
00385 
00386 void CDownloadTabBar::OnLButtonDblClk(UINT nFlags, CPoint point) 
00387 {
00388         if ( TabItem* pHit = HitTest( point ) )
00389         {
00390                 PostMessage( WM_COMMAND, ID_DOWNLOAD_GROUP_PROPERTIES );
00391                 return;
00392         }
00393         
00394         OnLButtonDown( nFlags, point );
00395 }
00396 
00397 void CDownloadTabBar::OnRButtonUp(UINT nFlags, CPoint point) 
00398 {
00399         CRect rcItem;
00400         
00401         if ( TabItem* pItem = HitTest( point, &rcItem ) )
00402         {
00403                 m_bMenuGray = TRUE;
00404                 if ( Select( pItem ) ) NotifySelection();
00405                 Invalidate();
00406                 ClientToScreen( &rcItem );
00407                 CoolMenu.RegisterEdge( theApp.m_bRTL ? rcItem.right : rcItem.left, rcItem.bottom - 1, rcItem.Width() );
00408                 Skin.TrackPopupMenu( _T("CDownloadTabBar"), CPoint( theApp.m_bRTL ? rcItem.right : rcItem.left, 
00409                         rcItem.bottom - 1 ), ID_DOWNLOAD_GROUP_PROPERTIES );
00410                 m_bMenuGray = FALSE;
00411                 Invalidate();
00412                 return;
00413         }
00414         else
00415         {
00416                 ClientToScreen( &point );
00417                 Skin.TrackPopupMenu( _T("CDownloadTabBar"), point );
00418                 return;
00419         }
00420         
00421         CControlBar::OnRButtonUp( nFlags, point );
00422 }
00423 
00424 void CDownloadTabBar::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
00425 {
00426         CoolMenu.OnMeasureItem( lpMeasureItemStruct );
00427 }
00428 
00429 void CDownloadTabBar::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
00430 {
00431         CoolMenu.OnDrawItem( lpDrawItemStruct );
00432 }
00433 
00434 BOOL CDownloadTabBar::Select(TabItem* pHit)
00435 {
00436         BOOL bChanged = FALSE;
00437         
00438         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00439         {
00440                 TabItem* pItem = (TabItem*)m_pItems.GetNext( pos );
00441                 bChanged |= pItem->Select( pItem == pHit );
00442         }
00443         
00444         return bChanged;
00445 }
00446 
00447 int CDownloadTabBar::GetSelectedCount(BOOL bDownloads)
00448 {
00449         int nCount = 0;
00450         
00451         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00452         {
00453                 TabItem* pItem = (TabItem*)m_pItems.GetNext( pos );
00454                 
00455                 if ( pItem->m_bSelected )
00456                 {
00457                         nCount += bDownloads ? pItem->m_nCount : 1;
00458                 }
00459         }
00460         
00461         return nCount;
00462 }
00463 
00464 CDownloadTabBar::TabItem* CDownloadTabBar::GetSelectedItem()
00465 {
00466         TabItem* pSelected = NULL;
00467         
00468         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00469         {
00470                 TabItem* pItem = (TabItem*)m_pItems.GetNext( pos );
00471                 
00472                 if ( pItem->m_bSelected )
00473                 {
00474                         if ( pSelected == NULL )
00475                                 pSelected = pItem;
00476                         else
00477                                 return NULL;
00478                 }
00479         }
00480         
00481         return pSelected;
00482 }
00483 
00484 CDownloadGroup* CDownloadTabBar::GetSelectedGroup()
00485 {
00486         TabItem* pItem = GetSelectedItem();
00487         return pItem ? pItem->m_pGroup : NULL;
00488 }
00489 
00490 void CDownloadTabBar::GetSelectedDownloads(CPtrList* pDownloads)
00491 {
00492         CSingleLock pLock( &DownloadGroups.m_pSection, TRUE );
00493         
00494         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00495         {
00496                 TabItem* pItem = (TabItem*)m_pItems.GetNext( pos );
00497                 
00498                 if ( pItem->m_bSelected && DownloadGroups.Check( pItem->m_pGroup ) )
00499                 {
00500                         pItem->m_pGroup->CopyList( pDownloads );
00501                 }
00502         }
00503 }
00504 
00505 void CDownloadTabBar::NotifySelection()
00506 {
00507         Invalidate();
00508         GetOwner()->PostMessage( WM_TIMER, 2 );
00509 }
00510 
00511 
00513 // CDownloadTabBar::TabItem construction
00514 
00515 CDownloadTabBar::TabItem::TabItem(CDownloadGroup* pGroup, int nCookie)
00516 {
00517         m_pGroup        = pGroup;
00518         m_nImage        = 0;
00519         m_bSelected     = ( m_pGroup == DownloadGroups.GetSuperGroup() );
00520         
00521         Update( nCookie );
00522 }
00523 
00524 CDownloadTabBar::TabItem::~TabItem()
00525 {
00526 }
00527 
00529 // CDownloadTabBar::TabItem update
00530 
00531 BOOL CDownloadTabBar::TabItem::Update(int nCookie)
00532 {
00533         if ( m_bSelected && nCookie ) m_pGroup->SetCookie( nCookie );
00534         
00535         BOOL bChanged = FALSE;
00536         
00537         if ( m_sName != m_pGroup->m_sName )
00538         {
00539                 m_sName = m_pGroup->m_sName;
00540                 bChanged = TRUE;
00541         }
00542         
00543         BOOL nCount = m_pGroup->GetCount();
00544         
00545         if ( m_nCount != nCount )
00546         {
00547                 m_nCount = nCount;
00548                 bChanged = TRUE;
00549         }
00550         
00551         if ( m_nImage != m_pGroup->m_nImage )
00552         {
00553                 m_nImage = m_pGroup->m_nImage;
00554                 bChanged = TRUE;
00555         }
00556         
00557         if ( bChanged )
00558         {
00559                 m_sCaption.Format( _T("%s (%i)"), (LPCTSTR)m_sName, m_nCount );
00560         }
00561         
00562         return bChanged;
00563 }
00564 
00566 // CDownloadTabBar::TabItem select
00567 
00568 BOOL CDownloadTabBar::TabItem::Select(BOOL bSelect)
00569 {
00570         if ( bSelect == m_bSelected ) return FALSE;
00571         m_bSelected = bSelect;
00572         return TRUE;
00573 }
00574 
00576 // CDownloadTabBar::TabItem paint
00577 
00578 void CDownloadTabBar::TabItem::Paint(CDownloadTabBar* pBar, CDC* pDC, CRect* pRect, BOOL bHot, BOOL bTransparent)
00579 {
00580         CRect rc( pRect );
00581         COLORREF crBack;
00582         
00583         BOOL bPopulated = m_nCount > 0;
00584         
00585         if ( m_bSelected && pBar->m_bMenuGray )
00586         {
00587                 crBack = CoolInterface.m_crBackNormal;
00588                 pDC->Draw3dRect( &rc, CoolInterface.m_crDisabled, CoolInterface.m_crDisabled );
00589         }
00590         else if ( bHot || m_bSelected )
00591         {
00592                 crBack = ( bHot && m_bSelected ) ? CoolInterface.m_crBackCheckSel : CoolInterface.m_crBackSel;
00593                 pDC->Draw3dRect( &rc, CoolInterface.m_crBorder, CoolInterface.m_crBorder );
00594         }
00595         else
00596         {
00597                 crBack = bTransparent ? CLR_NONE : CoolInterface.m_crMidtone;
00598                 if ( crBack != CLR_NONE ) pDC->Draw3dRect( &rc, crBack, crBack );
00599         }
00600         
00601         rc.DeflateRect( 1, 1 );
00602         if ( crBack != CLR_NONE ) pDC->SetBkColor( crBack );
00603         
00604         CPoint ptImage( rc.left + 2, rc.top + 1 );
00605         
00606         if ( m_bSelected )
00607         {
00608                 ImageList_DrawEx( ShellIcons.GetHandle( 16 ), m_nImage, pDC->GetSafeHdc(),
00609                         ptImage.x, ptImage.y, 0, 0, crBack, CLR_NONE, ILD_NORMAL );
00610                 pDC->ExcludeClipRect( ptImage.x, ptImage.y, ptImage.x + 16, ptImage.y + 16 );
00611         }
00612         else if ( bHot )
00613         {
00614                 ptImage.Offset( -1, -1 );
00615                 
00616                 if ( crBack != CLR_NONE )
00617                 {
00618                         pDC->FillSolidRect( ptImage.x, ptImage.y, 18, 2, crBack );
00619                         pDC->FillSolidRect( ptImage.x, ptImage.y + 2, 2, 16, crBack );
00620                 }
00621                 
00622                 ptImage.Offset( 2, 2 );
00623                 pDC->SetTextColor( CoolInterface.m_crShadow );
00624                 ImageList_DrawEx( ShellIcons.GetHandle( 16 ), m_nImage, pDC->GetSafeHdc(),
00625                         ptImage.x, ptImage.y, 0, 0, crBack, CLR_NONE, ILD_MASK );
00626                 
00627                 ptImage.Offset( -2, -2 );
00628                 ImageList_DrawEx( ShellIcons.GetHandle( 16 ), m_nImage, pDC->GetSafeHdc(),
00629                         ptImage.x, ptImage.y, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL );
00630                 
00631                 pDC->ExcludeClipRect( ptImage.x, ptImage.y, ptImage.x + 18, ptImage.y + 18 );
00632                 
00633                 ptImage.Offset( 1, 1 );
00634         }
00635         else
00636         {
00637                 ImageList_DrawEx( ShellIcons.GetHandle( 16 ), m_nImage, pDC->GetSafeHdc(),
00638                         ptImage.x, ptImage.y, 0, 0, crBack, CoolInterface.m_crShadow, ILD_BLEND50 );
00639                 pDC->ExcludeClipRect( ptImage.x, ptImage.y, ptImage.x + 16, ptImage.y + 16 );
00640         }
00641         
00642         rc.left += 20;
00643         
00644         CString strText = m_sCaption;
00645         if ( theApp.m_bRTL ) strText = _T("\x202A") + strText;
00646         
00647         if ( pDC->GetTextExtent( strText ).cx > rc.Width() )
00648         {
00649                 while ( pDC->GetTextExtent( strText + _T('\x2026') ).cx > rc.Width() && strText.GetLength() )
00650                 {
00651                         strText = strText.Left( strText.GetLength() - 1 );
00652                 }
00653                 
00654                 if ( strText.GetLength() ) strText += _T('\x2026');
00655         }
00656         
00657         rc.left -= 20;
00658         
00659         if ( crBack != CLR_NONE ) pDC->SetBkColor( crBack );
00660         
00661         if ( m_bSelected || bHot )
00662         {
00663                 pDC->SetTextColor( CoolInterface.m_crCmdTextSel );
00664         }
00665         else if ( ! bPopulated )
00666         {
00667                 pDC->SetTextColor( CoolInterface.m_crDisabled );
00668         }
00669         else
00670         {
00671                 pDC->SetTextColor( CoolInterface.m_crCmdText );
00672         }
00673         
00674         if ( crBack != CLR_NONE )
00675         {
00676                 pDC->SetBkMode( OPAQUE );
00677                 pDC->ExtTextOut( rc.left + 20, rc.top + 2, ETO_CLIPPED|ETO_OPAQUE, &rc, strText, NULL );
00678         }
00679         else
00680         {
00681                 pDC->SetBkMode( TRANSPARENT );
00682                 pDC->ExtTextOut( rc.left + 20, rc.top + 2, ETO_CLIPPED, &rc, strText, NULL );
00683         }
00684 }
00685 
00687 // CDownloadTabBar command handlers
00688 
00689 void CDownloadTabBar::OnDownloadGroupNew() 
00690 {
00691         CDownloadGroup* pGroup = DownloadGroups.Add( _T("New Group") );
00692         NotifySelection();
00693         
00694         CDownloadGroupDlg dlg( pGroup );
00695         
00696         if ( dlg.DoModal() == IDOK )
00697         {
00698                 if ( Transfers.m_pSection.Lock( 300 ) )
00699                 {
00700                         if ( DownloadGroups.Check( pGroup ) ) pGroup->LinkAll();
00701                         Transfers.m_pSection.Unlock();
00702                 }
00703         }
00704         else
00705         {
00706                 DownloadGroups.Remove( pGroup );
00707         }
00708         
00709         NotifySelection();
00710 }
00711 
00712 void CDownloadTabBar::OnUpdateDownloadGroupRemove(CCmdUI* pCmdUI) 
00713 {
00714         pCmdUI->Enable( GetSelectedCount() == 1 && GetSelectedGroup() != DownloadGroups.GetSuperGroup() );
00715 }
00716 
00717 void CDownloadTabBar::OnDownloadGroupRemove() 
00718 {
00719         DownloadGroups.Remove( GetSelectedGroup() );
00720         NotifySelection();
00721 }
00722 
00723 void CDownloadTabBar::OnUpdateDownloadGroupProperties(CCmdUI* pCmdUI) 
00724 {
00725         pCmdUI->Enable( GetSelectedCount() == 1 );
00726 }
00727 
00728 void CDownloadTabBar::OnDownloadGroupProperties() 
00729 {
00730         CDownloadGroupDlg dlg( GetSelectedGroup() );
00731         if ( dlg.DoModal() == IDOK ) NotifySelection();
00732 }
00733 
00734 void CDownloadTabBar::OnUpdateDownloadGroupResume(CCmdUI* pCmdUI) 
00735 {
00736         pCmdUI->Enable( GetSelectedCount( TRUE ) > 0 );
00737 }
00738 
00739 void CDownloadTabBar::OnDownloadGroupResume() 
00740 {
00741         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00742         CPtrList pDownloads;
00743         
00744         GetSelectedDownloads( &pDownloads );
00745         
00746         for ( POSITION pos = pDownloads.GetHeadPosition() ; pos ; )
00747         {
00748                 CDownload* pDownload = (CDownload*)pDownloads.GetNext( pos );
00749                 if ( Downloads.Check( pDownload ) ) pDownload->Resume();
00750         }
00751 }
00752 
00753 void CDownloadTabBar::OnUpdateDownloadGroupPause(CCmdUI* pCmdUI) 
00754 {
00755         pCmdUI->Enable( GetSelectedCount( TRUE ) > 0 );
00756 }
00757 
00758 void CDownloadTabBar::OnDownloadGroupPause() 
00759 {
00760         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00761         CPtrList pDownloads;
00762         
00763         GetSelectedDownloads( &pDownloads );
00764         
00765         for ( POSITION pos = pDownloads.GetHeadPosition() ; pos ; )
00766         {
00767                 CDownload* pDownload = (CDownload*)pDownloads.GetNext( pos );
00768                 if ( Downloads.Check( pDownload ) ) pDownload->Pause();
00769         }
00770 }
00771 
00772 void CDownloadTabBar::OnUpdateDownloadGroupClear(CCmdUI* pCmdUI) 
00773 {
00774         pCmdUI->Enable( GetSelectedCount( TRUE ) > 0 );
00775 }
00776 
00777 void CDownloadTabBar::OnDownloadGroupClear() 
00778 {
00779         CString strMessage;
00780         LoadString( strMessage, IDS_DOWNLOAD_CLEAR_GROUP );
00781         if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 ) != IDYES ) return;
00782         
00783         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00784         CPtrList pDownloads;
00785         
00786         GetSelectedDownloads( &pDownloads );
00787         
00788         for ( POSITION pos = pDownloads.GetHeadPosition() ; pos ; )
00789         {
00790                 CDownload* pDownload = (CDownload*)pDownloads.GetNext( pos );
00791                 if ( Downloads.Check( pDownload ) ) pDownload->Remove();
00792         }
00793 }
00794 
00796 // CDownloadTabBar drag and drop
00797 
00798 BOOL CDownloadTabBar::DropShowTarget(CPtrList* pList, const CPoint& ptScreen)
00799 {
00800         CPoint ptLocal( ptScreen );
00801         ScreenToClient( &ptLocal );
00802         
00803         TabItem* pItem = HitTest( ptLocal );
00804         
00805         if ( pItem != m_pHot )
00806         {
00807                 m_pHot = pItem;
00808                 CImageList::DragShowNolock( FALSE );
00809                 RedrawWindow();
00810                 CImageList::DragShowNolock( TRUE );
00811         }
00812         
00813         return pItem != NULL;
00814 }
00815 
00816 BOOL CDownloadTabBar::DropObjects(CPtrList* pList, const CPoint& ptScreen)
00817 {
00818         CPoint ptLocal( ptScreen );
00819         ScreenToClient( &ptLocal );
00820         
00821         if ( m_pHot != NULL )
00822         {
00823                 m_pHot = NULL;
00824                 Invalidate();
00825         }
00826         
00827         TabItem* pItem = HitTest( ptLocal );
00828         if ( pItem == NULL ) return FALSE;
00829 
00830         BOOL bMove = ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 ) == 0;
00831         
00832         CSingleLock pLock1( &Transfers.m_pSection, TRUE );
00833         CSingleLock pLock2( &DownloadGroups.m_pSection, TRUE );
00834         
00835         if ( DownloadGroups.Check( pItem->m_pGroup ) )
00836         {
00837                 for ( POSITION posD = pList->GetHeadPosition() ; posD ; )
00838                 {
00839                         CDownload* pDownload = (CDownload*)pList->GetNext( posD );
00840                         
00841                         if ( Downloads.Check( pDownload ) )
00842                         {
00843                                 if ( bMove )
00844                                 {
00845                                         DownloadGroups.Unlink( pDownload, FALSE );
00846                                 }
00847                                 
00848                                 pItem->m_pGroup->Add( pDownload );
00849                         }
00850                 }
00851         }
00852         
00853         return TRUE;
00854 }
00855 

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