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 "LibraryFolders.h"
00027 #include "SharedFolder.h"
00028 #include "SharedFile.h"
00029 #include "AlbumFolder.h"
00030 #include "Schema.h"
00031 #include "SchemaCache.h"
00032 #include "CoolInterface.h"
00033 #include "ShellIcons.h"
00034 #include "Skin.h"
00035 #include "ThumbCache.h"
00036 #include "ImageServices.h"
00037 #include "CtrlLibraryFrame.h"
00038 #include "CtrlLibraryMetaPanel.h"
00039 #include "CtrlLibraryTree.h"
00040 #include "DlgFilePropertiesSheet.h"
00041
00042 #ifdef _DEBUG
00043 #define new DEBUG_NEW
00044 #undef THIS_FILE
00045 static char THIS_FILE[] = __FILE__;
00046 #endif
00047
00048 IMPLEMENT_DYNCREATE(CLibraryMetaPanel, CLibraryPanel)
00049
00050 BEGIN_MESSAGE_MAP(CLibraryMetaPanel, CLibraryPanel)
00051
00052 ON_WM_PAINT()
00053 ON_WM_VSCROLL()
00054 ON_WM_SIZE()
00055 ON_WM_CREATE()
00056 ON_WM_DESTROY()
00057 ON_WM_SETCURSOR()
00058 ON_WM_LBUTTONUP()
00059 ON_WM_LBUTTONDOWN()
00060 ON_WM_MOUSEWHEEL()
00061
00062 END_MESSAGE_MAP()
00063
00064 #define THUMB_STORE_SIZE 128
00065
00067
00068
00069 CLibraryMetaPanel::CLibraryMetaPanel()
00070 {
00071 m_nThumbSize = 96;
00072 m_crLight = CCoolInterface::CalculateColour(
00073 CoolInterface.m_crTipBack, RGB( 255, 255, 255 ), 128 );
00074
00075
00076 if( !SystemParametersInfo ( SPI_GETWHEELSCROLLLINES, 0, &m_nScrollWheelLines, 0) )
00077 {
00078 m_nScrollWheelLines = 3;
00079 }
00080 m_bNewFile = TRUE;
00081 }
00082
00083 CLibraryMetaPanel::~CLibraryMetaPanel()
00084 {
00085 }
00086
00088
00089
00090 BOOL CLibraryMetaPanel::CheckAvailable(CLibraryTreeItem* pFolders, CLibraryList* pObjects)
00091 {
00092 m_bAvailable = FALSE;
00093
00094 if ( pFolders != NULL )
00095 {
00096 m_bAvailable = TRUE;
00097
00098 if ( pFolders->m_pSelNext == NULL && pFolders->m_pVirtual != NULL )
00099 {
00100 if ( pFolders->m_pVirtual->m_bCollSHA1 &&
00101 pFolders->m_pVirtual->GetBestView().Find( _T("Collection") ) > 0 )
00102 m_bAvailable = FALSE;
00103 if ( pFolders->m_pVirtual->GetFolderCount() > 0 ) m_bAvailable = FALSE;
00104 }
00105 }
00106
00107 return m_bAvailable;
00108 }
00109
00110 void CLibraryMetaPanel::Update()
00111 {
00112 CSingleLock pLock1( &Library.m_pSection, TRUE );
00113 CSingleLock pLock2( &m_pSection, TRUE );
00114
00115 CLibraryList* pSel = GetViewSelection();
00116 m_nSelected = pSel->GetCount();
00117
00118 CLibraryFile* pFirst = m_nSelected ? Library.LookupFile( pSel->GetHead() ) : NULL;
00119 if ( pFirst == NULL ) m_nSelected = 0;
00120
00121 m_nIcon32 = m_nIcon48 = -1;
00122
00123 if ( m_nSelected == 1 )
00124 {
00125 m_nIndex = pFirst->m_nIndex;
00126 m_sName = pFirst->m_sName;
00127 CString strNewFile( pFirst->GetPath() );
00128 m_bNewFile = ( m_sPath != strNewFile );
00129 if ( m_bNewFile ) m_sPath = strNewFile;
00130 if ( pFirst->m_pFolder != NULL ) m_sFolder = pFirst->m_pFolder->m_sPath;
00131 m_sSize = Settings.SmartVolume( pFirst->GetSize(), FALSE );
00132 m_sType = ShellIcons.GetTypeString( m_sName );
00133 m_nIcon32 = ShellIcons.Get( m_sName, 32 );
00134 m_nIcon48 = ShellIcons.Get( m_sName, 48 );
00135 m_nRating = pFirst->m_nRating;
00136 }
00137 else if ( m_nSelected > 1 )
00138 {
00139 CString strFormat;
00140 m_bNewFile = TRUE;
00141 LoadString( strFormat, IDS_LIBPANEL_MULTIPLE_FILES );
00142 m_sName.Format( strFormat, m_nSelected );
00143 QWORD nSize = 0;
00144
00145 m_sFolder = ( pFirst->m_pFolder != NULL ) ? pFirst->m_pFolder->m_sPath : _T("");
00146 m_nIcon32 = ShellIcons.Get( pFirst->m_sName, 32 );
00147 m_nIcon48 = ShellIcons.Get( pFirst->m_sName, 48 );
00148 m_nRating = 0;
00149
00150 for ( POSITION pos = pSel->GetHeadPosition() ; pos ; )
00151 {
00152 CLibraryFile* pFile = Library.LookupFile( pSel->GetNext( pos ) );
00153 if ( pFile == NULL ) continue;
00154
00155 nSize += pFile->GetSize() / 1024;
00156
00157 if ( pFile->m_pFolder != NULL && pFile->m_pFolder->m_sPath != m_sFolder )
00158 {
00159 LoadString( m_sFolder, IDS_LIBPANEL_MULTIPLE_FOLDERS );
00160 }
00161
00162 int nIcon = ShellIcons.Get( pFile->m_sName, 48 );
00163 if ( nIcon != m_nIcon48 ) m_nIcon48 = -1;
00164 nIcon = ShellIcons.Get( pFile->m_sName, 32 );
00165 if ( nIcon != m_nIcon32 ) m_nIcon32 = -1;
00166 }
00167
00168 m_sSize = Settings.SmartVolume( nSize, TRUE );
00169 m_sPath.Empty();
00170 m_sType.Empty();
00171 }
00172
00173 m_pSchema = NULL;
00174
00175 for ( POSITION pos = pSel->GetHeadPosition() ; pos ; )
00176 {
00177 CLibraryFile* pFile = Library.LookupFile( pSel->GetNext( pos ) );
00178 if ( pFile == NULL ) continue;
00179 m_pSchema = pFile->m_pSchema;
00180 if ( m_pSchema ) break;
00181 }
00182
00183 m_pMetadata.Setup( m_pSchema );
00184
00185 if ( m_pSchema != NULL )
00186 {
00187 for ( POSITION pos = pSel->GetHeadPosition() ; pos ; )
00188 {
00189 if ( CLibraryFile* pFile = Library.LookupFile( pSel->GetNext( pos ) ) )
00190 {
00191 if ( pFile->m_pMetadata != NULL &&
00192 m_pSchema->Equals( pFile->m_pSchema ) )
00193 {
00194 m_pMetadata.Combine( pFile->m_pMetadata );
00195 }
00196 }
00197 }
00198 }
00199
00200 m_pMetadata.CreateLinks();
00201 m_pMetadata.Clean( 4096 );
00202
00203 CClientDC dc( this );
00204 if ( theApp.m_bRTL ) theApp.m_pfnSetLayout( dc.m_hDC, LAYOUT_BITMAPORIENTATIONPRESERVED );
00205 SCROLLINFO pInfo;
00206 CRect rc;
00207
00208 GetClientRect( &rc );
00209
00210 int nThumbSize = rc.Height() - 16;
00211 nThumbSize = max( nThumbSize, 64 );
00212 nThumbSize = min( nThumbSize, 128 );
00213
00214 int nHeight = 54 + m_pMetadata.Layout( &dc, rc.Width() - 24 - nThumbSize );
00215
00216 pInfo.cbSize = sizeof(pInfo);
00217 pInfo.fMask = SIF_ALL & ~SIF_TRACKPOS;
00218 pInfo.nMin = 0;
00219 pInfo.nMax = nHeight;
00220 pInfo.nPage = rc.Height();
00221 pInfo.nPos = GetScrollPos( SB_VERT );
00222 pInfo.nPos = max( 0, min( pInfo.nPos, pInfo.nMax - (int)pInfo.nPage + 1 ) );
00223
00224 SetScrollInfo( SB_VERT, &pInfo, TRUE );
00225
00226 if ( m_bmThumb.m_hObject != NULL && m_sThumb != m_sPath ) m_bmThumb.DeleteObject();
00227
00228 pLock2.Unlock();
00229 pLock1.Unlock();
00230
00231 if ( m_sPath.GetLength() && m_bmThumb.m_hObject == NULL )
00232 {
00233 if ( m_bThread == FALSE )
00234 {
00235 m_bThread = TRUE;
00236 CWinThread* pThread = AfxBeginThread( ThreadStart, this, THREAD_PRIORITY_IDLE );
00237 m_hThread = pThread->m_hThread;
00238 }
00239
00240 m_pWakeup.SetEvent();
00241 }
00242
00243 Invalidate();
00244 }
00245
00247
00248
00249 int CLibraryMetaPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
00250 {
00251 if ( CLibraryPanel::OnCreate( lpCreateStruct ) == -1 ) return -1;
00252
00253 m_hThread = NULL;
00254 m_bThread = FALSE;
00255
00256 return 0;
00257 }
00258
00259 void CLibraryMetaPanel::OnDestroy()
00260 {
00261 m_bThread = FALSE;
00262 m_pWakeup.SetEvent();
00263
00264 int nAttempt = 5;
00265 for ( ; nAttempt > 0 ; nAttempt-- )
00266 {
00267 DWORD nCode;
00268
00269 if ( ! GetExitCodeThread( m_hThread, &nCode ) ) break;
00270 if ( nCode != STILL_ACTIVE ) break;
00271
00272 Sleep( 100 );
00273 }
00274
00275 if ( nAttempt == 0 )
00276 {
00277 TerminateThread( m_hThread, 0 );
00278 theApp.Message( MSG_DEBUG, _T("WARNING: Terminating CLibraryMetaPanel thread.") );
00279 Sleep( 100 );
00280 }
00281
00282 m_hThread = NULL;
00283
00284 CLibraryPanel::OnDestroy();
00285 }
00286
00288
00289
00290 void CLibraryMetaPanel::OnPaint()
00291 {
00292 CSingleLock pLock( &m_pSection, TRUE );
00293 CPaintDC dc( this );
00294 CRect rcClient;
00295 CString str;
00296 DWORD dwFlags = ( theApp.m_bRTL ? ETO_RTLREADING : 0 );
00297
00298 GetClientRect( &rcClient );
00299
00300 CFont* pOldFont = dc.GetCurrentFont();
00301 dc.SetTextColor( CoolInterface.m_crText );
00302 dc.SetBkColor( CoolInterface.m_crWindow );
00303 dc.SetBkMode( OPAQUE );
00304
00305 if ( m_nSelected == 0 )
00306 {
00307 dc.SelectObject( &CoolInterface.m_fntNormal );
00308 LoadString( str, IDS_LIBPANEL_NO_SELECTION );
00309 CSize sz = dc.GetTextExtent( str );
00310 CPoint pt = rcClient.CenterPoint();
00311 pt.x -= sz.cx / 2; pt.y -= sz.cy / 2;
00312 dc.ExtTextOut( pt.x, pt.y, ETO_OPAQUE|dwFlags, &rcClient, str, NULL );
00313 dc.SelectObject( pOldFont );
00314 return;
00315 }
00316
00317 CRect rcWork;
00318 DrawThumbnail( &dc, rcClient, rcWork );
00319
00320 dc.SetViewportOrg( 0, -GetScrollPos( SB_VERT ) );
00321
00322 dc.SetBkColor( CoolInterface.m_crWindow );
00323
00324 dc.SelectObject( &CoolInterface.m_fntCaption );
00325 DrawText( &dc, rcWork.left, rcWork.top, m_sName );
00326
00327 if ( m_nRating > 1 )
00328 {
00329 CPoint ptStar( rcWork.right - 3, rcWork.top - 2 );
00330 m_rcRating.SetRectEmpty();
00331
00332 for ( int nRating = m_nRating - 1 ; nRating ; nRating-- )
00333 {
00334 ptStar.x -= 16;
00335 ShellIcons.Draw( &dc, SHI_STAR, 16, ptStar.x, ptStar.y, CoolInterface.m_crWindow );
00336 m_rcRating.UnionRect( &m_rcRating, CRect( ptStar.x, ptStar.y, ptStar.x + 16, ptStar.y + 16 ) );
00337 }
00338 }
00339 else if ( m_nRating == 1 )
00340 {
00341 CPoint ptStar( rcWork.right - 3, rcWork.top - 2 );
00342 m_rcRating.SetRectEmpty();
00343 ptStar.x -= 16;
00344 ShellIcons.Draw( &dc, SHI_FAKE, 16, ptStar.x, ptStar.y, CoolInterface.m_crWindow );
00345 m_rcRating.UnionRect( &m_rcRating, CRect( ptStar.x, ptStar.y, ptStar.x + 16, ptStar.y + 16 ) );
00346 }
00347 else
00348 {
00349 dc.SelectObject( &CoolInterface.m_fntUnder );
00350 dc.SetTextColor( RGB( 0, 0, 255 ) );
00351 LoadString( str, IDS_LIBPANEL_RATE_FILE );
00352 CSize szText = dc.GetTextExtent( str );
00353 DrawText( &dc, rcWork.right - szText.cx, rcWork.top, str, &m_rcRating );
00354 }
00355
00356 rcWork.top += 20;
00357 dc.FillSolidRect( rcWork.left, rcWork.top, rcWork.Width(), 1, CoolInterface.m_crMargin );
00358 dc.ExcludeClipRect( rcWork.left, rcWork.top, rcWork.right, rcWork.top + 1 );
00359 dc.SetBkColor( CoolInterface.m_crWindow );
00360 dc.SetTextColor( CoolInterface.m_crText );
00361 rcWork.top += 4;
00362
00363 dc.SelectObject( &CoolInterface.m_fntBold );
00364 LoadString( str, IDS_TIP_LOCATION );
00365 if ( theApp.m_bRTL )
00366 DrawText( &dc, rcWork.left, rcWork.top, ':' + str );
00367 else
00368 DrawText( &dc, rcWork.left, rcWork.top, str + ':' );
00369 LoadString( str, IDS_TIP_SIZE );
00370 DrawText( &dc, rcWork.right - 125, rcWork.top, str + ':' );
00371 dc.SelectObject( &CoolInterface.m_fntNormal );
00372 DrawText( &dc, rcWork.right - 60, rcWork.top, m_sSize );
00373
00374 if ( m_sFolder.Find( '\\' ) >= 0 )
00375 {
00376 dc.SelectObject( &CoolInterface.m_fntUnder );
00377 dc.SetTextColor( RGB( 0, 0, 255 ) );
00378 str = m_sFolder;
00379 long nTextLength = dc.GetTextExtent( str + _T('\x2026') ).cx;
00380 const long nLimit = rcWork.Width() - 125 - 68 - 10;
00381 if ( nTextLength > nLimit && nLimit > 0 )
00382 {
00383 while ( nTextLength > nLimit )
00384 {
00385 if ( str.IsEmpty() ) break;
00386 str = str.Left( str.GetLength() - 1 );
00387 nTextLength = dc.GetTextExtent( str + _T('\x2026') ).cx;
00388 }
00389 str += _T('\x2026');
00390 }
00391 else if ( nLimit <= 0 ) str.Empty();
00392 }
00393 else str.Empty();
00394
00395 DrawText( &dc, rcWork.left + 68, rcWork.top, str, &m_rcFolder );
00396 if ( m_sFolder.Find( '\\' ) < 0 ) m_rcFolder.SetRect( 0, 0, 0, 0 );
00397 rcWork.top += 18;
00398
00399 m_pMetadata.Paint( &dc, &rcWork );
00400
00401 dc.SetViewportOrg( 0, 0 );
00402
00403 dc.SelectObject( pOldFont );
00404 dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
00405 }
00406
00407 void CLibraryMetaPanel::DrawText(CDC* pDC, int nX, int nY, LPCTSTR pszText, RECT* pRect)
00408 {
00409 DWORD dwFlags = ( theApp.m_bRTL ? ETO_RTLREADING : 0 );
00410 CSize sz = pDC->GetTextExtent( pszText, _tcslen( pszText ) );
00411 CRect rc( nX - 2, nY - 2, nX + sz.cx + 2, nY + sz.cy + 2 );
00412
00413 pDC->ExtTextOut( nX, nY, ETO_CLIPPED|ETO_OPAQUE|dwFlags, &rc, pszText, _tcslen( pszText ), NULL );
00414 pDC->ExcludeClipRect( &rc );
00415
00416 if ( pRect != NULL ) CopyMemory( pRect, &rc, sizeof(RECT) );
00417 }
00418
00420
00421
00422 void CLibraryMetaPanel::DrawThumbnail(CDC* pDC, CRect& rcClient, CRect& rcWork)
00423 {
00424 int nThumbSize = rcClient.Height() - 16;
00425 nThumbSize = max( nThumbSize, 64 );
00426 nThumbSize = min( nThumbSize, 128 );
00427
00428 CRect rcThumb( rcClient.left + 8, rcClient.top + 8,
00429 rcClient.left + 8 + nThumbSize, rcClient.top + 8 + nThumbSize );
00430
00431 rcWork.CopyRect( &rcThumb );
00432 pDC->Draw3dRect( &rcWork, CoolInterface.m_crMargin, CoolInterface.m_crMargin );
00433 rcWork.DeflateRect( 1, 1 );
00434 m_nThumbSize = rcWork.Width();
00435
00436 DrawThumbnail( pDC, rcWork );
00437 pDC->ExcludeClipRect( &rcThumb );
00438
00439 rcWork.SetRect( rcThumb.right + 8, rcThumb.top, rcClient.right - 8, rcClient.bottom );
00440 }
00441
00442 void CLibraryMetaPanel::DrawThumbnail(CDC* pDC, CRect& rcThumb)
00443 {
00444 if ( m_bmThumb.m_hObject &&
00445 ( m_szThumb.cx == m_nThumbSize || m_szThumb.cy == m_nThumbSize ) )
00446 {
00447 CDC dcMem;
00448 dcMem.CreateCompatibleDC( pDC );
00449
00450 CBitmap* pOld = (CBitmap*)dcMem.SelectObject( &m_bmThumb );
00451
00452 CPoint ptImage( ( rcThumb.left + rcThumb.right ) / 2 - m_szThumb.cx / 2,
00453 ( rcThumb.top + rcThumb.bottom ) / 2 - m_szThumb.cy / 2 );
00454
00455 pDC->BitBlt( ptImage.x, ptImage.y, m_szThumb.cx, m_szThumb.cy,
00456 &dcMem, 0, 0, SRCCOPY );
00457 pDC->ExcludeClipRect( ptImage.x, ptImage.y,
00458 ptImage.x + m_szThumb.cx, ptImage.y + m_szThumb.cy );
00459
00460 dcMem.SelectObject( pOld );
00461
00462 pDC->FillSolidRect( &rcThumb, m_crLight );
00463 }
00464 else
00465 {
00466 CPoint pt( ( rcThumb.left + rcThumb.right ) / 2 - 24,
00467 ( rcThumb.top + rcThumb.bottom ) / 2 - 24 );
00468
00469 if ( m_nIcon48 >= 0 )
00470 {
00471 ImageList_DrawEx( ShellIcons.GetHandle( 48 ), m_nIcon48, pDC->GetSafeHdc(),
00472 pt.x, pt.y, 48, 48, m_crLight, CLR_NONE, ILD_NORMAL );
00473 pDC->ExcludeClipRect( pt.x, pt.y, pt.x + 48, pt.y + 48 );
00474 }
00475 else if ( m_nIcon32 >= 0 )
00476 {
00477 pt.x += 8; pt.y += 8;
00478 ImageList_DrawEx( ShellIcons.GetHandle( 32 ), m_nIcon32, pDC->GetSafeHdc(),
00479 pt.x, pt.y, 32, 32, m_crLight, CLR_NONE, ILD_NORMAL );
00480 pDC->ExcludeClipRect( pt.x, pt.y, pt.x + 32, pt.y + 32 );
00481 }
00482
00483 pDC->FillSolidRect( &rcThumb, m_crLight );
00484 }
00485 }
00486
00488
00489
00490 void CLibraryMetaPanel::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00491 {
00492 SCROLLINFO pScroll;
00493
00494 ZeroMemory( &pScroll, sizeof(pScroll) );
00495 pScroll.cbSize = sizeof(pScroll);
00496 pScroll.fMask = SIF_ALL;
00497
00498 GetScrollInfo( SB_VERT, &pScroll );
00499
00500 switch ( nSBCode )
00501 {
00502 case SB_TOP:
00503 pScroll.nPos = 0;
00504 break;
00505 case SB_BOTTOM:
00506 pScroll.nPos = pScroll.nMax - 1;
00507 break;
00508 case SB_LINEUP:
00509 pScroll.nPos -= 8;
00510 break;
00511 case SB_LINEDOWN:
00512 pScroll.nPos += 8;
00513 break;
00514 case SB_PAGEUP:
00515 pScroll.nPos -= pScroll.nPage;
00516 break;
00517 case SB_PAGEDOWN:
00518 pScroll.nPos += pScroll.nPage;
00519 break;
00520 case SB_THUMBPOSITION:
00521 case SB_THUMBTRACK:
00522 pScroll.nPos = nPos;
00523 break;
00524 }
00525
00526 pScroll.fMask = SIF_POS;
00527 pScroll.nPos = max( 0, min( pScroll.nPos, pScroll.nMax ) );
00528
00529 SetScrollInfo( SB_VERT, &pScroll );
00530 Invalidate();
00531 }
00532
00533 void CLibraryMetaPanel::OnSize(UINT nType, int cx, int cy)
00534 {
00535 CLibraryPanel::OnSize( nType, cx, cy );
00536 Update();
00537 }
00538
00540
00541
00542 BOOL CLibraryMetaPanel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00543 {
00544 CPoint point;
00545
00546 GetCursorPos( &point );
00547 ScreenToClient( &point );
00548 point.y += GetScrollPos( SB_VERT );
00549
00550 if ( m_nSelected > 0 && m_rcFolder.PtInRect( point ) )
00551 {
00552 SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
00553 return TRUE;
00554 }
00555 else if ( m_nSelected > 0 && m_rcRating.PtInRect( point ) )
00556 {
00557 SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
00558 return TRUE;
00559 }
00560 else if ( m_pMetadata.HitTest( point, TRUE ) )
00561 {
00562 SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
00563 return TRUE;
00564 }
00565
00566 return CLibraryPanel::OnSetCursor( pWnd, nHitTest, message );
00567 }
00568
00569 void CLibraryMetaPanel::OnLButtonUp(UINT nFlags, CPoint point)
00570 {
00571 point.y += GetScrollPos( SB_VERT );
00572
00573 if ( m_nSelected > 0 && m_rcFolder.PtInRect( point ) )
00574 {
00575 if ( CLibraryFolder* pFolder = LibraryFolders.GetFolder( m_sFolder ) )
00576 {
00577 CLibraryFrame* pFrame = (CLibraryFrame*)GetOwner();
00578 ASSERT_KINDOF(CLibraryFrame, pFrame );
00579 pFrame->Display( pFolder );
00580 }
00581 }
00582 else if ( m_nSelected > 0 && m_rcRating.PtInRect( point ) )
00583 {
00584 CLibraryList* pList = GetViewSelection();
00585
00586 if ( pList != NULL && pList->GetCount() > 0 )
00587 {
00588 CFilePropertiesSheet dlg;
00589 dlg.Add( pList );
00590 dlg.DoModal( 2 );
00591 }
00592 }
00593 else if ( CMetaItem* pItem = m_pMetadata.HitTest( point, TRUE ) )
00594 {
00595 if ( CAlbumFolder* pFolder = pItem->GetLinkTarget() )
00596 {
00597 CLibraryFrame* pFrame = (CLibraryFrame*)GetOwner();
00598 ASSERT_KINDOF(CLibraryFrame, pFrame );
00599 pFrame->Display( pFolder );
00600 }
00601 }
00602
00603 CLibraryPanel::OnLButtonUp( nFlags, point );
00604 }
00605
00606 void CLibraryMetaPanel::OnLButtonDown(UINT nFlags, CPoint point)
00607 {
00608 SetFocus();
00609 }
00610
00611 BOOL CLibraryMetaPanel::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
00612 {
00613 OnVScroll( SB_THUMBPOSITION, (int)( GetScrollPos( SB_VERT ) - zDelta / WHEEL_DELTA * m_nScrollWheelLines * 8 ), NULL );
00614 return TRUE;
00615 }
00616
00618
00619
00620 UINT CLibraryMetaPanel::ThreadStart(LPVOID pParam)
00621 {
00622 CLibraryMetaPanel* pPanel = (CLibraryMetaPanel*)pParam;
00623 pPanel->OnRun();
00624 return 0;
00625 }
00626
00627 void CLibraryMetaPanel::OnRun()
00628 {
00629 CImageServices pServices;
00630
00631 while ( m_bThread )
00632 {
00633 WaitForSingleObject( m_pWakeup, INFINITE );
00634 if ( ! m_bThread ) break;
00635 if ( ! m_bNewFile )
00636 {
00637 m_bThread = FALSE;
00638 break;
00639 }
00640
00641 m_pSection.Lock();
00642 CString strPath = m_sPath;
00643 m_pSection.Unlock();
00644
00645 CImageFile pFile( &pServices );
00646 CThumbCache pCache;
00647 CSize Size( THUMB_STORE_SIZE, THUMB_STORE_SIZE );
00648 BOOL bSuccess = FALSE;
00649
00650 if ( !pCache.Load( strPath, &Size, m_nIndex, &pFile ) )
00651 {
00652 bSuccess = pFile.LoadFromFile( strPath, FALSE, TRUE ) && pFile.EnsureRGB();
00653 if ( bSuccess )
00654 {
00655 int nSize = THUMB_STORE_SIZE * pFile.m_nWidth / pFile.m_nHeight;
00656
00657 if ( nSize > THUMB_STORE_SIZE )
00658 {
00659 nSize = THUMB_STORE_SIZE * pFile.m_nHeight / pFile.m_nWidth;
00660 pFile.Resample( THUMB_STORE_SIZE, nSize );
00661 }
00662 else
00663 {
00664 pFile.Resample( nSize, THUMB_STORE_SIZE );
00665 }
00666 pCache.Store( strPath, &Size, m_nIndex, &pFile );
00667 }
00668 }
00669 else bSuccess = TRUE;
00670
00671 if ( bSuccess )
00672 {
00673
00674 int nSize = m_nThumbSize * pFile.m_nWidth / pFile.m_nHeight;
00675
00676 if ( nSize > m_nThumbSize )
00677 {
00678 nSize = m_nThumbSize * pFile.m_nHeight / pFile.m_nWidth;
00679 pFile.Resample( m_nThumbSize, nSize );
00680 }
00681 else
00682 {
00683 pFile.Resample( nSize, m_nThumbSize );
00684 }
00685
00686 m_pSection.Lock();
00687
00688 if ( m_bmThumb.m_hObject ) m_bmThumb.DeleteObject();
00689
00690 if ( m_sPath == strPath )
00691 {
00692 m_sThumb = m_sPath;
00693 m_bmThumb.Attach( pFile.CreateBitmap() );
00694 m_szThumb.cx = pFile.m_nWidth;
00695 m_szThumb.cy = pFile.m_nHeight;
00696 Invalidate();
00697 }
00698
00699 m_pSection.Unlock();
00700 }
00701 }
00702
00703 m_bThread = FALSE;
00704 }
00705