00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Library.h"
00026 #include "LibraryHistory.h"
00027 #include "AlbumFolder.h"
00028 #include "SharedFile.h"
00029 #include "CoolInterface.h"
00030 #include "ShellIcons.h"
00031 #include "Skin.h"
00032
00033 #include "CtrlLibraryFrame.h"
00034 #include "CtrlLibraryHistoryPanel.h"
00035
00036 #ifdef _DEBUG
00037 #define new DEBUG_NEW
00038 #undef THIS_FILE
00039 static char THIS_FILE[] = __FILE__;
00040 #endif
00041
00042 BEGIN_MESSAGE_MAP(CLibraryHistoryPanel, CLibraryPanel)
00043
00044 ON_WM_SIZE()
00045 ON_WM_PAINT()
00046 ON_WM_VSCROLL()
00047 ON_WM_SETCURSOR()
00048 ON_WM_LBUTTONUP()
00049 ON_WM_LBUTTONDOWN()
00050 ON_WM_MOUSEWHEEL()
00051
00052 END_MESSAGE_MAP()
00053
00054
00056
00057
00058 CLibraryHistoryPanel::CLibraryHistoryPanel()
00059 {
00060
00061 if( !SystemParametersInfo ( SPI_GETWHEELSCROLLLINES, 0, &m_nScrollWheelLines, 0) )
00062 {
00063 m_nScrollWheelLines = 3;
00064 }
00065 }
00066
00067 CLibraryHistoryPanel::~CLibraryHistoryPanel()
00068 {
00069 for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00070 {
00071 delete (Item*)m_pList.GetAt( nItem );
00072 }
00073 }
00074
00076
00077
00078 BOOL CLibraryHistoryPanel::CheckAvailable(CLibraryTreeItem* pFolders, CLibraryList* pObjects)
00079 {
00080 m_bAvailable = ( pFolders == NULL );
00081 return m_bAvailable;
00082 }
00083
00084 void CLibraryHistoryPanel::Update()
00085 {
00086 CSingleLock pLock( &Library.m_pSection, TRUE );
00087 BOOL bChanged = FALSE;
00088
00089 for ( int nItem = m_pList.GetSize() - 1 ; nItem >= 0 ; nItem-- )
00090 {
00091 Item* pItem = (Item*)m_pList.GetAt( nItem );
00092
00093 if ( ! LibraryHistory.Check( pItem->m_pRecent ) ||
00094 ! pItem->m_pRecent->m_pFile )
00095 {
00096 delete pItem;
00097 m_pList.RemoveAt( nItem );
00098 bChanged = TRUE;
00099 }
00100 }
00101
00102 int nCount = 0;
00103
00104 for ( POSITION pos = LibraryHistory.GetIterator() ; pos ; )
00105 {
00106 CLibraryRecent* pRecent = LibraryHistory.GetNext( pos );
00107 if ( ! pRecent->m_pFile ) continue;
00108
00109 int nItem = m_pList.GetSize() - 1;
00110 for ( ; nItem >= 0 ; nItem-- )
00111 {
00112 Item* pItem = (Item*)m_pList.GetAt( nItem );
00113 if ( pItem->m_pRecent == pRecent ) break;
00114 }
00115
00116 if ( nItem < 0 )
00117 {
00118 Item* pItem = new Item();
00119 pItem->m_pRecent = pRecent;
00120 pItem->m_nIndex = pRecent->m_pFile->m_nIndex;
00121 pItem->m_sText = pRecent->m_pFile->m_sName;
00122 pItem->m_nIcon16 = ShellIcons.Get( pItem->m_sText, 16 );
00123
00124 FileTimeToSystemTime( &pRecent->m_tAdded, &pItem->m_pTime );
00125 SystemTimeToTzSpecificLocalTime( NULL, &pItem->m_pTime, &pItem->m_pTime );
00126 GetDateFormat( LOCALE_USER_DEFAULT, NULL, &pItem->m_pTime,
00127 _T("ddd',' MMM dd"), pItem->m_sTime.GetBuffer( 64 ), 64 );
00128 pItem->m_sTime.ReleaseBuffer();
00129
00130 m_pList.InsertAt( nCount++, pItem );
00131 bChanged = TRUE;
00132 }
00133 }
00134
00135 SCROLLINFO pInfo;
00136 CRect rc;
00137
00138 GetClientRect( &rc );
00139
00140 m_nColumns = ( rc.Width() > 500 ) ? 2 : 1;
00141 int nHeight = ( m_pList.GetSize() + m_nColumns - 1 ) / m_nColumns * 24 + 2;
00142
00143 pInfo.cbSize = sizeof(pInfo);
00144 pInfo.fMask = SIF_ALL & ~SIF_TRACKPOS;
00145 pInfo.nMin = 0;
00146 pInfo.nMax = nHeight;
00147 pInfo.nPage = rc.Height() - 18;
00148 pInfo.nPos = GetScrollPos( SB_VERT );
00149 pInfo.nPos = max( 0, min( pInfo.nPos, pInfo.nMax - (int)pInfo.nPage + 1 ) );
00150
00151 SetScrollInfo( SB_VERT, &pInfo, TRUE );
00152
00153 if ( bChanged )
00154 {
00155 m_pHover = NULL;
00156 Invalidate();
00157 }
00158 }
00159
00161
00162
00163 void CLibraryHistoryPanel::OnSize(UINT nType, int cx, int cy)
00164 {
00165 CLibraryPanel::OnSize( nType, cx, cy );
00166 Update();
00167 }
00168
00169 void CLibraryHistoryPanel::OnPaint()
00170 {
00171 CRect rcClient, rcItem;
00172 CPaintDC dc( this );
00173 CString str;
00174
00175 GetClientRect( &rcClient );
00176
00177 rcItem.CopyRect( &rcClient );
00178 rcItem.bottom = rcItem.top + 18;
00179 rcClient.top += 18;
00180
00181 LoadString( str, IDS_LIBPANEL_RECENT_ADDITIONS );
00182
00183 CFont* pFontOld = (CFont*)dc.SelectObject( &CoolInterface.m_fntCaption );
00184 CSize szText = dc.GetTextExtent( str );
00185 int nY = ( rcItem.top + rcItem.bottom + 1 ) / 2 - szText.cy / 2;
00186
00187 dc.SetBkMode( OPAQUE );
00188 dc.SetBkColor( Skin.m_crBannerBack );
00189 dc.SetTextColor( Skin.m_crBannerText );
00190 dc.ExtTextOut( 4, nY, ETO_CLIPPED|ETO_OPAQUE, &rcItem, str, NULL );
00191 dc.ExcludeClipRect( &rcItem );
00192
00193 dc.SetBkColor( CoolInterface.m_crWindow );
00194 dc.SetViewportOrg( 0, -GetScrollPos( SB_VERT ) );
00195
00196 CRect rcWork( &rcClient );
00197 rcWork.top += 1;
00198
00199 for ( int nRow = 0, nItem = 0 ; nItem < m_pList.GetSize() ; nRow++ )
00200 {
00201 dc.SetBkColor( Skin.m_crSchemaRow[ nRow & 1 ] );
00202
00203 for ( int nColumn = 0 ; nColumn < m_nColumns ; nColumn++ )
00204 {
00205 Item* pItem = ( nItem < m_pList.GetSize() ) ? (Item*)m_pList.GetAt( nItem++ ) : NULL;
00206
00207 rcItem.SetRect( rcWork.left, rcWork.top, rcWork.left, rcWork.top + 22 );
00208
00209 rcItem.left += nColumn * rcWork.Width() / m_nColumns + 1;
00210 rcItem.right += ( nColumn + 1 ) * rcWork.Width() / m_nColumns - 1;
00211
00212 if ( pItem != NULL )
00213 {
00214 ShellIcons.Draw( &dc, pItem->m_nIcon16, 16,
00215 rcItem.left + 3, rcItem.top + 3, dc.GetBkColor() );
00216 dc.ExcludeClipRect( rcItem.left + 3, rcItem.top + 3,
00217 rcItem.left + 3 + 16, rcItem.top + 3 + 16 );
00218
00219 dc.SelectObject( &CoolInterface.m_fntNormal );
00220 dc.SetTextColor( CoolInterface.m_crDisabled );
00221
00222 szText = dc.GetTextExtent( pItem->m_sTime );
00223 nY = ( rcItem.top + rcItem.bottom ) / 2 - szText.cy / 2;
00224
00225 CRect rcText( rcItem.right - szText.cx - 5, rcItem.top, rcItem.right, rcItem.bottom );
00226
00227 dc.ExtTextOut( rcText.left + 2, nY,
00228 ETO_CLIPPED|ETO_OPAQUE, &rcText, pItem->m_sTime, NULL );
00229 dc.ExcludeClipRect( &rcText );
00230
00231 dc.SetTextColor( RGB( 0, 0, 255 ) );
00232 dc.SelectObject( &CoolInterface.m_fntUnder );
00233
00234 rcText.right = rcText.left;
00235 rcText.left = rcItem.left + 3 + 16 + 3;
00236
00237 str = pItem->m_sText;
00238 szText = dc.GetTextExtent( str );
00239
00240 if ( szText.cx > rcText.Width() - 4 )
00241 {
00242 while ( str.GetLength() > 0 )
00243 {
00244 szText = dc.GetTextExtent( str + _T('\x2026') );
00245 if ( szText.cx < rcText.Width() - 4 ) break;
00246 str = str.Left( str.GetLength() - 1 );
00247 }
00248
00249 str += _T('\x2026');
00250 }
00251
00252 rcText.right = rcText.left + szText.cx + 4;
00253
00254 dc.ExtTextOut( rcText.left + 2, nY, ETO_CLIPPED|ETO_OPAQUE,
00255 &rcItem, str, NULL );
00256
00257 pItem->m_rect.CopyRect( &rcText );
00258 }
00259 else
00260 {
00261 dc.ExtTextOut( 0, 0, ETO_OPAQUE, &rcItem, NULL, 0, NULL );
00262 }
00263
00264 dc.ExcludeClipRect( &rcItem );
00265 }
00266
00267 rcWork.top += 24;
00268 }
00269
00270 dc.SetViewportOrg( 0, 0 );
00271 dc.SelectObject( pFontOld );
00272 dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
00273 }
00274
00275 void CLibraryHistoryPanel::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00276 {
00277 SCROLLINFO pScroll;
00278
00279 ZeroMemory( &pScroll, sizeof(pScroll) );
00280 pScroll.cbSize = sizeof(pScroll);
00281 pScroll.fMask = SIF_ALL;
00282
00283 GetScrollInfo( SB_VERT, &pScroll );
00284
00285 switch ( nSBCode )
00286 {
00287 case SB_TOP:
00288 pScroll.nPos = 0;
00289 break;
00290 case SB_BOTTOM:
00291 pScroll.nPos = pScroll.nMax - 1;
00292 break;
00293 case SB_LINEUP:
00294 pScroll.nPos -= 8;
00295 break;
00296 case SB_LINEDOWN:
00297 pScroll.nPos += 8;
00298 break;
00299 case SB_PAGEUP:
00300 pScroll.nPos -= pScroll.nPage;
00301 break;
00302 case SB_PAGEDOWN:
00303 pScroll.nPos += pScroll.nPage;
00304 break;
00305 case SB_THUMBPOSITION:
00306 case SB_THUMBTRACK:
00307 pScroll.nPos = nPos;
00308 break;
00309 }
00310
00311 pScroll.fMask = SIF_POS;
00312 pScroll.nPos = max( 0, min( pScroll.nPos, pScroll.nMax ) );
00313
00314 SetScrollInfo( SB_VERT, &pScroll );
00315 Invalidate();
00316 }
00317
00318 BOOL CLibraryHistoryPanel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00319 {
00320 CPoint point;
00321
00322 GetCursorPos( &point );
00323 ScreenToClient( &point );
00324 point.y += GetScrollPos( SB_VERT );
00325
00326 for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00327 {
00328 Item* pItem = (Item*)m_pList.GetAt( nItem );
00329
00330 if ( pItem->m_rect.PtInRect( point ) )
00331 {
00332 SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
00333 return TRUE;
00334 }
00335 }
00336
00337 return CLibraryPanel::OnSetCursor( pWnd, nHitTest, message );
00338 }
00339
00340 void CLibraryHistoryPanel::OnLButtonUp(UINT nFlags, CPoint point)
00341 {
00342 point.y += GetScrollPos( SB_VERT );
00343
00344 for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00345 {
00346 Item* pItem = (Item*)m_pList.GetAt( nItem );
00347
00348 if ( pItem->m_rect.PtInRect( point ) )
00349 {
00350 OnClickFile( pItem->m_nIndex );
00351 break;
00352 }
00353 }
00354
00355 point.y -= GetScrollPos( SB_VERT );
00356
00357 CLibraryPanel::OnLButtonUp( nFlags, point );
00358 }
00359
00360 void CLibraryHistoryPanel::OnLButtonDown(UINT nFlags, CPoint point)
00361 {
00362 SetFocus();
00363 }
00364
00365 BOOL CLibraryHistoryPanel::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
00366 {
00367 OnVScroll( SB_THUMBPOSITION, (int)( GetScrollPos( SB_VERT ) - zDelta / WHEEL_DELTA * m_nScrollWheelLines * 8 ), NULL );
00368 return TRUE;
00369 }
00370
00371 void CLibraryHistoryPanel::OnClickFile(DWORD nFile)
00372 {
00373 CQuickLock oLock( Library.m_pSection );
00374 CLibraryFile* pFile = Library.LookupFile( nFile );
00375
00376 CLibraryFrame* pFrame = (CLibraryFrame*)GetParent();
00377 ASSERT_KINDOF(CLibraryFrame, pFrame);
00378
00379 pFrame->Display( pFile );
00380 }