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

CtrlMediaFrame.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlMediaFrame.cpp
00003 //
00004 //      Date:                   "$Date: 2005/10/25 18:30:37 $"
00005 //      Revision:               "$Revision: 1.31 $"
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 "ImageServices.h"
00030 #include "Plugins.h"
00031 #include "Library.h"
00032 #include "SharedFile.h"
00033 
00034 #include "Skin.h"
00035 #include "ShellIcons.h"
00036 #include "CtrlMediaFrame.h"
00037 #include "DlgSettingsManager.h"
00038 #include "DlgMediaVis.h"
00039 #include "CoolInterface.h"
00040 
00041 IMPLEMENT_DYNAMIC(CMediaFrame, CWnd)
00042 
00043 BEGIN_MESSAGE_MAP(CMediaFrame, CWnd)
00044         ON_WM_CREATE()
00045         ON_WM_DESTROY()
00046         ON_WM_SIZE()
00047         ON_WM_PAINT()
00048         ON_WM_TIMER()
00049         ON_WM_CONTEXTMENU()
00050         ON_WM_HSCROLL()
00051         ON_WM_CLOSE()
00052         ON_WM_SETCURSOR()
00053         ON_WM_LBUTTONDOWN()
00054         ON_WM_SYSCOMMAND()
00055         ON_WM_LBUTTONDBLCLK()
00056         ON_UPDATE_COMMAND_UI(ID_MEDIA_CLOSE, OnUpdateMediaClose)
00057         ON_COMMAND(ID_MEDIA_CLOSE, OnMediaClose)
00058         ON_UPDATE_COMMAND_UI(ID_MEDIA_PLAY, OnUpdateMediaPlay)
00059         ON_COMMAND(ID_MEDIA_PLAY, OnMediaPlay)
00060         ON_UPDATE_COMMAND_UI(ID_MEDIA_PAUSE, OnUpdateMediaPause)
00061         ON_COMMAND(ID_MEDIA_PAUSE, OnMediaPause)
00062         ON_UPDATE_COMMAND_UI(ID_MEDIA_STOP, OnUpdateMediaStop)
00063         ON_COMMAND(ID_MEDIA_STOP, OnMediaStop)
00064         ON_COMMAND(ID_MEDIA_ZOOM, OnMediaZoom)
00065         ON_UPDATE_COMMAND_UI(ID_MEDIA_SIZE_FILL, OnUpdateMediaSizeFill)
00066         ON_COMMAND(ID_MEDIA_SIZE_FILL, OnMediaSizeFill)
00067         ON_UPDATE_COMMAND_UI(ID_MEDIA_SIZE_DISTORT, OnUpdateMediaSizeDistort)
00068         ON_COMMAND(ID_MEDIA_SIZE_DISTORT, OnMediaSizeDistort)
00069         ON_UPDATE_COMMAND_UI(ID_MEDIA_SIZE_ONE, OnUpdateMediaSizeOne)
00070         ON_COMMAND(ID_MEDIA_SIZE_ONE, OnMediaSizeOne)
00071         ON_UPDATE_COMMAND_UI(ID_MEDIA_SIZE_TWO, OnUpdateMediaSizeTwo)
00072         ON_COMMAND(ID_MEDIA_SIZE_TWO, OnMediaSizeTwo)
00073         ON_UPDATE_COMMAND_UI(ID_MEDIA_SIZE_THREE, OnUpdateMediaSizeThree)
00074         ON_COMMAND(ID_MEDIA_SIZE_THREE, OnMediaSizeThree)
00075         ON_UPDATE_COMMAND_UI(ID_MEDIA_ASPECT_DEFAULT, OnUpdateMediaAspectDefault)
00076         ON_COMMAND(ID_MEDIA_ASPECT_DEFAULT, OnMediaAspectDefault)
00077         ON_UPDATE_COMMAND_UI(ID_MEDIA_ASPECT_4_3, OnUpdateMediaAspect43)
00078         ON_COMMAND(ID_MEDIA_ASPECT_4_3, OnMediaAspect43)
00079         ON_UPDATE_COMMAND_UI(ID_MEDIA_ASPECT_16_9, OnUpdateMediaAspect169)
00080         ON_COMMAND(ID_MEDIA_ASPECT_16_9, OnMediaAspect169)
00081         ON_UPDATE_COMMAND_UI(ID_MEDIA_FULLSCREEN, OnUpdateMediaFullScreen)
00082         ON_COMMAND(ID_MEDIA_FULLSCREEN, OnMediaFullScreen)
00083         ON_UPDATE_COMMAND_UI(ID_MEDIA_PLAYLIST, OnUpdateMediaPlaylist)
00084         ON_COMMAND(ID_MEDIA_PLAYLIST, OnMediaPlaylist)
00085         ON_COMMAND(ID_MEDIA_SETTINGS, OnMediaSettings)
00086         ON_UPDATE_COMMAND_UI(ID_MEDIA_SETTINGS, OnUpdateMediaSettings)
00087         ON_COMMAND(ID_MEDIA_VIS, OnMediaVis)
00088         ON_UPDATE_COMMAND_UI(ID_MEDIA_VIS, OnUpdateMediaVis)
00089         ON_UPDATE_COMMAND_UI(ID_MEDIA_STATUS, OnUpdateMediaStatus)
00090         ON_COMMAND(ID_MEDIA_STATUS, OnMediaStatus)
00091         ON_UPDATE_COMMAND_UI(ID_MEDIA_MUTE, OnUpdateMediaMute)
00092         ON_COMMAND(ID_MEDIA_MUTE, OnMediaMute)
00093         ON_NOTIFY(MLN_NEWCURRENT, IDC_MEDIA_PLAYLIST, OnNewCurrent)
00094         ON_MESSAGE(0x0319, OnMediaKey)
00095 END_MESSAGE_MAP()
00096 
00097 #define SIZE_INTERNAL   1982
00098 #define SIZE_BARSLIDE   1983
00099 #define TOOLBAR_HEIGHT  28
00100 #define TOOLBAR_STICK   3000
00101 #define TOOLBAR_ANIMATE 1000
00102 #define HEADER_HEIGHT   16
00103 #define STATUS_HEIGHT   18
00104 #define SPLIT_SIZE              6
00105 #define META_DELAY              10000
00106 #define TIME_FACTOR             1000000
00107 #define ONE_SECOND              10000000
00108 
00109 CMediaFrame* CMediaFrame::g_pMediaFrame = NULL;
00110 
00111 
00113 // CMediaFrame construction
00114 
00115 CMediaFrame::CMediaFrame()
00116 {
00117         if ( g_pMediaFrame == NULL ) g_pMediaFrame = this;
00118         
00119         m_pPlayer               = NULL;
00120         m_nState                = smsNull;
00121         m_bMute                 = FALSE;
00122         m_bThumbPlay    = FALSE;
00123         m_bRepeat               = FALSE;
00124         m_bLastMedia    = FALSE;
00125         m_bLastNotPlayed= FALSE;
00126         m_bStopFlag             = FALSE;
00127         m_bEnqueue              = FALSE;
00128         m_tLastPlay             = 0;
00129         m_tMetadata             = 0;
00130         
00131         m_bFullScreen           = FALSE;
00132         m_bListWasVisible   = Settings.MediaPlayer.ListVisible;
00133         m_bListVisible          = Settings.MediaPlayer.ListVisible;
00134         m_nListSize                     = Settings.MediaPlayer.ListSize;
00135         m_bStatusVisible        = Settings.MediaPlayer.StatusVisible;
00136         m_bScreenSaverEnabled = TRUE;
00137 }
00138 
00139 CMediaFrame::~CMediaFrame()
00140 {
00141         if ( g_pMediaFrame == this ) g_pMediaFrame = NULL;
00142 }
00143 
00145 // CMediaFrame system message handlers
00146 
00147 BOOL CMediaFrame::Create(CWnd* pParentWnd) 
00148 {
00149         CRect rect;
00150         return CWnd::Create( NULL, _T("CMediaFrame"), WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,
00151                 rect, pParentWnd, IDC_MEDIA_FRAME, NULL );
00152 }
00153 
00154 int CMediaFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00155 {
00156         if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00157         
00158         CRect rectDefault;
00159         SetOwner( GetParent() );
00160         
00161         m_wndList.Create( this, IDC_MEDIA_PLAYLIST );
00162         
00163         if ( ! m_wndListBar.Create( this, WS_CHILD|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
00164         m_wndListBar.SetBarStyle( m_wndListBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_BORDER_TOP );
00165         m_wndListBar.SetOwner( GetOwner() );
00166         
00167         if ( ! m_wndToolBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
00168         m_wndToolBar.SetBarStyle( m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_BORDER_TOP );
00169         m_wndToolBar.SetOwner( GetOwner() );
00170         
00171         m_wndPosition.Create( WS_CHILD|WS_TABSTOP|TBS_HORZ|TBS_NOTICKS|TBS_TOP,
00172                 rectDefault, &m_wndToolBar, IDC_MEDIA_POSITION );
00173         m_wndPosition.SetRange( 0, 0 );
00174         m_wndPosition.SetPageSize( 0 );
00175         
00176         m_wndSpeed.Create( WS_CHILD|WS_TABSTOP|TBS_HORZ|TBS_NOTICKS|TBS_TOP,
00177                 rectDefault, &m_wndToolBar, IDC_MEDIA_SPEED );
00178         m_wndSpeed.SetRange( 0, 200 );
00179         m_wndSpeed.SetTic( 0 );
00180         m_wndSpeed.SetTic( 100 );
00181         m_wndSpeed.SetTic( 200 );
00182         
00183         m_wndVolume.Create( WS_CHILD|WS_TABSTOP|TBS_HORZ|TBS_NOTICKS|TBS_TOP,
00184                 rectDefault, &m_wndToolBar, IDC_MEDIA_VOLUME );
00185         m_wndVolume.SetRange( 0, 100 );
00186         m_wndVolume.SetTic( 0 );
00187         m_wndVolume.SetTic( 100 );
00188 
00189         if ( theApp.m_bRTL )
00190         {
00191                 m_wndPosition.ModifyStyleEx( WS_EX_LAYOUTRTL, 0, 0 );
00192                 m_wndSpeed.ModifyStyleEx( WS_EX_LAYOUTRTL, 0, 0 );
00193                 m_wndVolume.ModifyStyleEx( WS_EX_LAYOUTRTL, 0, 0 );
00194         }
00195 
00196         CBitmap bmIcons;
00197         bmIcons.LoadBitmap( IDB_MEDIA_STATES );
00198         m_pIcons.Create( 16, 16, ILC_COLOR16|ILC_MASK, 3, 0 );
00199         m_pIcons.Add( &bmIcons, RGB( 0, 255, 0 ) );
00200         
00201         UpdateState();
00202         
00203         SetTimer( 1, 200, NULL );
00204         
00205         return 0;
00206 }
00207 
00208 void CMediaFrame::OnDestroy() 
00209 {
00210         Settings.MediaPlayer.ListVisible        = m_bListVisible;
00211         Settings.MediaPlayer.ListSize           = m_nListSize;
00212         Settings.MediaPlayer.StatusVisible      = m_bStatusVisible;
00213         
00214         KillTimer( 2 );
00215         KillTimer( 1 );
00216         
00217         Cleanup();
00218         
00219         if ( ! m_bScreenSaverEnabled ) EnableScreenSaver();
00220 
00221         CWnd::OnDestroy();
00222 }
00223 
00224 BOOL CMediaFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
00225 {
00226         if ( m_wndList.m_hWnd )
00227         {
00228                 if ( m_wndList.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00229         }
00230         if ( m_wndListBar.m_hWnd )
00231         {
00232                 if ( m_wndListBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00233         }
00234         if ( m_wndToolBar.m_hWnd )
00235         {
00236                 if ( m_wndToolBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00237         }
00238         
00239         return CWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00240 }
00241 
00242 BOOL CMediaFrame::PreTranslateMessage(MSG* pMsg) 
00243 {
00244         if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE )
00245         {
00246                 if ( m_bFullScreen )
00247                 {
00248                         SetFullScreen( FALSE );
00249                         return TRUE;
00250                 }
00251         }
00252         else if ( pMsg->message == WM_SYSKEYDOWN && pMsg->wParam == VK_RETURN )
00253         {
00254                 SetFullScreen( ! m_bFullScreen );
00255                 return TRUE;
00256         }
00257         else if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_LEFT )
00258         {
00259                 if ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 )
00260                 {
00261                         m_wndList.PostMessage( WM_COMMAND, ID_MEDIA_PREVIOUS );
00262                         return TRUE;
00263                 }
00264         }
00265         else if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RIGHT )
00266         {
00267                 if ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 )
00268                 {
00269                         m_wndList.PostMessage( WM_COMMAND, ID_MEDIA_NEXT );
00270                         return TRUE;
00271                 }
00272         }
00273 
00274         return CWnd::PreTranslateMessage( pMsg );
00275 }
00276 
00278 // CMediaFrame presentation message handlers
00279 
00280 void CMediaFrame::OnSkinChange()
00281 {
00282         Skin.CreateToolBar( _T("CMediaFrame"), &m_wndToolBar );
00283         Skin.CreateToolBar( _T("CMediaList"), &m_wndListBar );
00284         
00285         if ( CCoolBarItem* pItem = m_wndToolBar.GetID( IDC_MEDIA_POSITION ) ) pItem->Enable( FALSE );
00286         if ( CCoolBarItem* pItem = m_wndToolBar.GetID( IDC_MEDIA_SPEED ) ) pItem->Enable( FALSE );
00287         if ( CCoolBarItem* pItem = m_wndToolBar.GetID( IDC_MEDIA_VOLUME ) ) pItem->Enable( FALSE );
00288 }
00289 
00290 void CMediaFrame::OnUpdateCmdUI()
00291 {
00292         m_wndToolBar.OnUpdateCmdUI( (CFrameWnd*)GetOwner(), TRUE );
00293         m_wndListBar.OnUpdateCmdUI( (CFrameWnd*)GetOwner(), TRUE );
00294 }
00295 
00296 void CMediaFrame::SetFullScreen(BOOL bFullScreen)
00297 {
00298         if ( bFullScreen == m_bFullScreen ) return;
00299         
00300         ShowWindow( SW_HIDE );
00301         m_tBarTime = GetTickCount();
00302         
00303         if ( m_bFullScreen = bFullScreen )
00304         {
00305                 ModifyStyle( WS_CHILD, 0 );
00306                 SetParent( NULL );
00307                 
00308                 if ( theApp.m_pfnGetMonitorInfoA != NULL ) //If GetMonitorInfo() is available
00309                 {
00310                         MONITORINFO oMonitor;
00311                         ZeroMemory( &oMonitor, sizeof(oMonitor) );
00312                         oMonitor.cbSize = sizeof(oMonitor);
00313                         theApp.m_pfnGetMonitorInfoA( theApp.m_pfnMonitorFromWindow( AfxGetMainWnd()->GetSafeHwnd(), MONITOR_DEFAULTTOPRIMARY ), &oMonitor );
00314                         
00315                         SetWindowPos( &wndTopMost, oMonitor.rcMonitor.left, oMonitor.rcMonitor.top,
00316                                 oMonitor.rcMonitor.right - oMonitor.rcMonitor.left,
00317                                 oMonitor.rcMonitor.bottom - oMonitor.rcMonitor.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW );
00318                 }
00319                 else
00320                 {
00321                         SetWindowPos( &wndTopMost, 0, 0, GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ), SWP_FRAMECHANGED|SWP_SHOWWINDOW ); 
00322                 }
00323                 
00324                 m_bListWasVisible       = m_bListVisible;
00325                 m_bListVisible          = FALSE;
00326                 OnSize( SIZE_INTERNAL, 0, 0 );
00327                 
00328                 SetTimer( 2, 30, NULL );
00329         }
00330         else
00331         {
00332                 CWnd* pOwner = GetOwner();
00333                 CRect rc;
00334                 
00335                 ModifyStyle( 0, WS_CHILD );
00336                 SetParent( pOwner );
00337                 
00338                 pOwner->GetClientRect( &rc );
00339                 SetWindowPos( NULL, 0, 0, rc.right, rc.bottom,
00340                         SWP_FRAMECHANGED|SWP_SHOWWINDOW );
00341                 m_bListVisible = m_bListWasVisible;
00342                 OnSize( SIZE_INTERNAL, 0, 0 );
00343                 KillTimer( 2 );
00344         }
00345 }
00346 
00347 void CMediaFrame::OnSize(UINT nType, int cx, int cy) 
00348 {
00349         if ( nType != SIZE_INTERNAL && nType != SIZE_BARSLIDE ) CWnd::OnSize( nType, cx, cy );
00350         
00351         CRect rc;
00352         GetClientRect( &rc );
00353         
00354         if ( rc.Width() < 32 || rc.Height() < 32 ) return;
00355         
00356         if ( rc.Width() < m_nListSize + SPLIT_SIZE )
00357         {
00358                 m_nListSize = max( 0, rc.Width() - SPLIT_SIZE );
00359         }
00360         
00361         if ( m_bListVisible || ! m_bFullScreen )
00362         {
00363                 rc.bottom -= TOOLBAR_HEIGHT;
00364                 m_wndToolBar.SetWindowPos( NULL, rc.left, rc.bottom, rc.Width(),
00365                         TOOLBAR_HEIGHT, SWP_NOZORDER|SWP_SHOWWINDOW );
00366                 
00367                 if ( m_bListVisible )
00368                 {
00369                         rc.right -= m_nListSize;
00370                         m_wndList.SetWindowPos( NULL, rc.right, rc.top + HEADER_HEIGHT, m_nListSize,
00371                                 rc.bottom - TOOLBAR_HEIGHT - HEADER_HEIGHT, SWP_NOZORDER|SWP_SHOWWINDOW );
00372                         m_wndListBar.SetWindowPos( NULL, rc.right, rc.bottom - TOOLBAR_HEIGHT,
00373                                 m_nListSize, TOOLBAR_HEIGHT, SWP_NOZORDER|SWP_SHOWWINDOW );
00374                         rc.right -= SPLIT_SIZE;
00375                 }
00376                 else if ( m_wndList.IsWindowVisible() )
00377                 {
00378                         m_wndList.ShowWindow( SW_HIDE );
00379                         m_wndListBar.ShowWindow( SW_HIDE );
00380                 }
00381         }
00382         else
00383         {
00384                 if ( m_wndList.IsWindowVisible() )
00385                 {
00386                         m_wndList.ShowWindow( SW_HIDE );
00387                         m_wndListBar.ShowWindow( SW_HIDE );
00388                 }
00389                 
00390                 DWORD tElapse = GetTickCount() - m_tBarTime;
00391                 int nBar = TOOLBAR_HEIGHT;
00392                 
00393                 if ( tElapse < TOOLBAR_STICK )
00394                 {
00395                         nBar = TOOLBAR_HEIGHT;
00396                 }
00397                 else if ( tElapse > TOOLBAR_STICK + TOOLBAR_ANIMATE )
00398                 {
00399                         nBar = 0;
00400                         SetCursor( NULL );
00401                         KillTimer( 2 );
00402                 }
00403                 else
00404                 {
00405                         tElapse -= TOOLBAR_STICK;
00406                         nBar = TOOLBAR_HEIGHT - ( tElapse * TOOLBAR_HEIGHT / TOOLBAR_ANIMATE );
00407                 }
00408                 
00409                 m_wndToolBar.SetWindowPos( NULL, rc.left, rc.bottom - nBar, rc.Width(),
00410                         TOOLBAR_HEIGHT, SWP_NOZORDER|SWP_SHOWWINDOW );
00411         }
00412         
00413         if ( m_bStatusVisible )
00414         {
00415                 if ( m_bFullScreen )
00416                 {
00417                         m_rcStatus.SetRect( rc.left, rc.top, rc.right, rc.top + STATUS_HEIGHT );
00418                         rc.top += STATUS_HEIGHT;
00419                 }
00420                 else
00421                 {
00422                         m_rcStatus.SetRect( rc.left, rc.bottom - STATUS_HEIGHT, rc.right, rc.bottom );
00423                         rc.bottom -= STATUS_HEIGHT;
00424                 }
00425         }
00426 
00427         m_rcVideo = rc;
00428 
00429         if ( m_pPlayer != NULL && nType != SIZE_BARSLIDE )
00430         {
00431                 m_pPlayer->Reposition( &rc );
00432         }
00433         
00434         if ( nType != SIZE_BARSLIDE ) Invalidate();
00435 }
00436 
00437 void CMediaFrame::OnPaint() 
00438 {
00439         CPaintDC dc( this );
00440 
00441         if ( m_bmLogo.m_hObject == NULL)
00442         {
00443                 if ( CImageServices::LoadBitmap( &m_bmLogo, IDR_LARGE_LOGO, RT_JPEG ) )
00444                 {
00445                         if ( m_pPlayer ) m_pPlayer->SetLogoBitmap( (HBITMAP)m_bmLogo.m_hObject );
00446                 }
00447         }
00448         
00449         if ( m_pFontDefault.m_hObject == NULL )
00450         {
00451                 LOGFONT pFont = { 80, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
00452                         OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
00453                         DEFAULT_PITCH|FF_DONTCARE, _T("Tahoma") };
00454                 
00455                 m_pFontDefault.CreatePointFontIndirect( &pFont );
00456                 
00457                 pFont.lfHeight = 80;
00458                 m_pFontValue.CreatePointFontIndirect( &pFont );
00459                 pFont.lfWeight = FW_BLACK;
00460                 m_pFontKey.CreatePointFontIndirect( &pFont );
00461         }
00462         
00463         CFont* pOldFont = (CFont*)dc.SelectObject( &m_pFontDefault );
00464         
00465         CRect rcClient;
00466         GetClientRect( &rcClient );
00467         
00468         if ( m_bListVisible )
00469         {
00470                 CRect rcBar(    rcClient.right - m_nListSize - SPLIT_SIZE,
00471                                                 rcClient.top,
00472                                                 rcClient.right - m_nListSize,
00473                                                 rcClient.bottom );
00474                 
00475                 dc.FillSolidRect( rcBar.left, rcBar.top, 1, rcBar.Height(), GetSysColor( COLOR_BTNFACE ) );
00476                 dc.FillSolidRect( rcBar.left + 1, rcBar.top, 1, rcBar.Height(), GetSysColor( COLOR_3DHIGHLIGHT ) );
00477                 dc.FillSolidRect( rcBar.right - 1, rcBar.top, 1, rcBar.Height(), GetSysColor( COLOR_3DSHADOW ) );
00478                 dc.FillSolidRect( rcBar.left + 2, rcBar.top, rcBar.Width() - 3, rcBar.Height(), GetSysColor( COLOR_BTNFACE ) );
00479                 dc.ExcludeClipRect( &rcBar );
00480                 
00481                 rcBar.SetRect( rcBar.right, rcClient.top,
00482                         rcClient.right, rcClient.top + HEADER_HEIGHT );
00483                 
00484                 if ( dc.RectVisible( &rcBar ) ) PaintListHeader( dc, rcBar );
00485         }
00486         
00487         if ( m_bStatusVisible )
00488         {
00489                 CRect rcStatus( &m_rcStatus );
00490                 if ( dc.RectVisible( &rcStatus ) ) PaintStatus( dc, rcStatus );
00491         }
00492         
00493         if ( m_pPlayer == NULL )
00494         {
00495                 if ( dc.RectVisible( &m_rcVideo ) ) PaintSplash( dc, m_rcVideo );
00496         }
00497         
00498         dc.SelectObject( pOldFont );
00499 }
00500 
00501 void CMediaFrame::PaintSplash(CDC& dc, CRect& rcBar)
00502 {
00503         if ( m_bmLogo.m_hObject == NULL )
00504         {
00505                 dc.FillSolidRect( &m_rcVideo, 0 );
00506                 return;
00507         }
00508         
00509         BITMAP pInfo;
00510         m_bmLogo.GetBitmap( &pInfo );
00511         
00512         CPoint pt = m_rcVideo.CenterPoint();
00513         pt.x -= pInfo.bmWidth / 2;
00514         pt.y -= ( pInfo.bmHeight + 32 ) / 2;
00515         
00516         CDC dcMem;
00517         dcMem.CreateCompatibleDC( &dc );
00518         CBitmap* pOldBmp = (CBitmap*)dcMem.SelectObject( &m_bmLogo );
00519         dc.BitBlt( pt.x, pt.y, pInfo.bmWidth, pInfo.bmHeight, &dcMem,
00520                 0, 0, SRCCOPY );
00521         dc.ExcludeClipRect( pt.x, pt.y, pt.x + pInfo.bmWidth, pt.y + pInfo.bmHeight );
00522         dcMem.SelectObject( pOldBmp );
00523         
00524         CRect rcText( m_rcVideo.left, pt.y + pInfo.bmHeight, m_rcVideo.right, pt.y + pInfo.bmHeight + 32 );
00525         
00526         CString strText;
00527         LoadString( strText, IDS_MEDIA_TITLE );
00528 
00529         pt.x = ( m_rcVideo.left + m_rcVideo.right ) / 2 - dc.GetTextExtent( strText ).cx / 2;
00530         pt.y = rcText.top + 8;
00531         
00532         dc.SetBkColor( 0 );
00533         dc.SetTextColor( RGB( 200, 200, 255 ) );
00534         dc.ExtTextOut( pt.x, pt.y, ETO_OPAQUE, &m_rcVideo, strText, NULL );
00535         dc.ExcludeClipRect( &rcText );
00536         
00537         dc.FillSolidRect( &m_rcVideo, 0 );
00538 }
00539 
00540 void CMediaFrame::PaintListHeader(CDC& dc, CRect& rcBar)
00541 {
00542         CString strText;
00543         CPoint pt = rcBar.CenterPoint();
00544         LoadString( strText, IDS_MEDIA_PLAYLIST );
00545         CSize szText = dc.GetTextExtent( strText );
00546         pt.x -= szText.cx / 2; pt.y -= szText.cy / 2;
00547         dc.SetBkMode( OPAQUE );
00548         dc.SetBkColor( RGB( 0, 0, 0x80 ) );
00549         dc.SetTextColor( RGB( 0xFF, 0xFF, 0 ) );
00550         dc.ExtTextOut( pt.x, pt.y, ETO_OPAQUE|ETO_CLIPPED, &rcBar, strText, NULL );
00551 }
00552 
00553 void CMediaFrame::PaintStatus(CDC& dc, CRect& rcBar)
00554 {
00555         COLORREF crBack = RGB( 0x00, 0x00, 0x60 );
00556         COLORREF crText = RGB( 0xF0, 0xF0, 0xFF );
00557         
00558         dc.SelectObject( &m_pFontValue );
00559         DWORD dwOptions = theApp.m_bRTL ? ETO_RTLREADING : 0;
00560 
00561         int nY = ( rcBar.top + rcBar.bottom ) / 2 - dc.GetTextExtent( _T("Cy") ).cy / 2;
00562         CRect rcPart( &rcBar );
00563         CString str;
00564         CSize sz;
00565         
00566         int nState = 0;
00567         if ( m_nState >= smsPlaying ) nState = 2;
00568         else if ( m_nState >= smsPaused ) nState = 1;
00569         ImageList_DrawEx( m_pIcons, nState, dc, rcBar.left + 2,
00570                 ( rcBar.top + rcBar.bottom ) / 2 - 8, 16, 16,
00571                 crBack, CLR_NONE, ILD_NORMAL );
00572         dc.ExcludeClipRect( rcBar.left + 2, ( rcBar.top + rcBar.bottom ) / 2 - 8,
00573                 rcBar.left + 18, ( rcBar.top + rcBar.bottom ) / 2 + 8 );
00574         
00575         dc.SetBkMode( OPAQUE );
00576         dc.SetBkColor( crBack );
00577         dc.SetTextColor( crText );
00578         
00579         if ( CMetaItem* pItem = m_pMetadata.GetFirst() )
00580         {
00581                 dc.SelectObject( &m_pFontKey );
00582                 CString str = theApp.m_bRTL ? ':' + pItem->m_sKey : pItem->m_sKey + ':';
00583                 sz                              = dc.GetTextExtent( str );
00584                 rcPart.left             = rcBar.left + 20;
00585                 rcPart.right    = rcPart.left + sz.cx + 8;
00586                 dc.ExtTextOut( rcPart.left + 4, nY, ETO_CLIPPED|ETO_OPAQUE|dwOptions, &rcPart, str, NULL );
00587                 dc.ExcludeClipRect( &rcPart );
00588                 
00589                 dc.SelectObject( &m_pFontValue );
00590                 sz                              = dc.GetTextExtent( pItem->m_sValue );
00591                 rcPart.left             = rcPart.right;
00592                 rcPart.right    = rcPart.left + sz.cx + 8;
00593                 dc.ExtTextOut( rcPart.left + 4, nY, ETO_CLIPPED|ETO_OPAQUE|dwOptions, &rcPart, pItem->m_sValue, NULL );
00594                 dc.ExcludeClipRect( &rcPart );
00595         }
00596         else
00597         {
00598                 if ( m_nState >= smsOpen )
00599                 {
00600                         int nSlash = m_sFile.ReverseFind( '\\' );
00601                         str = nSlash >= 0 ? m_sFile.Mid( nSlash + 1 ) : m_sFile;
00602                 }
00603                 else
00604                 {
00605                         LoadString( str, IDS_MEDIA_EMPTY );
00606                 }
00607                 
00608                 sz                              = dc.GetTextExtent( str );
00609                 rcPart.left             = rcBar.left + 20;
00610                 rcPart.right    = rcPart.left + sz.cx + 8;
00611                 dc.ExtTextOut( rcPart.left + 4, nY, ETO_CLIPPED|ETO_OPAQUE|dwOptions, &rcPart, str, NULL );
00612                 dc.ExcludeClipRect( &rcPart );
00613         }
00614 
00615         if ( m_nState >= smsOpen )
00616         {
00617                 CString strFormat;
00618                 LoadString( strFormat, IDS_GENERAL_OF );
00619                 strFormat = _T("%.2i:%.2i ") + strFormat + _T(" %.2i:%.2i");
00620                 if ( theApp.m_bRTL ) strFormat = _T("\x200F") + strFormat;
00621 
00622                 str.Format( strFormat,
00623                         (int)( ( m_nPosition / ONE_SECOND ) / 60 ),
00624                         (int)( ( m_nPosition / ONE_SECOND ) % 60 ),
00625                         (int)( ( m_nLength / ONE_SECOND ) / 60 ),
00626                         (int)( ( m_nLength / ONE_SECOND ) % 60 ) );
00627                 
00628                 sz                              = dc.GetTextExtent( str );
00629                 rcPart.right    = rcBar.right;
00630                 rcPart.left             = rcPart.right - sz.cx - 8;
00631                 
00632                 dc.ExtTextOut( rcPart.left + 4, nY, ETO_CLIPPED|ETO_OPAQUE|dwOptions, &rcPart, str, NULL );
00633                 dc.ExcludeClipRect( &rcPart );
00634         }
00635         
00636         dc.FillSolidRect( &rcBar, crBack );
00637         dc.SelectObject( &m_pFontDefault );
00638 }
00639 
00640 BOOL CMediaFrame::PaintStatusMicro(CDC& dc, CRect& rcBar)
00641 {
00642         if ( m_nState <= smsOpen ) return FALSE;
00643         
00644         CRect rcStatus( &rcBar );
00645         CRect rcPart( &rcBar );
00646         CString str;
00647         CSize sz;
00648         CDC* pMemDC = CoolInterface.GetBuffer( dc, rcBar.Size() );
00649 
00650         DWORD dwOptions = theApp.m_bRTL ? DT_RTLREADING : 0;
00651         if ( m_nState >= smsOpen )
00652         {
00653                 CString strFormat;
00654                 LoadString( strFormat, IDS_GENERAL_OF );
00655                 strFormat = _T("%.2i:%.2i ") + strFormat + _T(" %.2i:%.2i");
00656                 if ( theApp.m_bRTL ) strFormat = _T("\x200F") + strFormat;
00657 
00658                 str.Format( strFormat,
00659                         (int)( ( m_nPosition / ONE_SECOND ) / 60 ),
00660                         (int)( ( m_nPosition / ONE_SECOND ) % 60 ),
00661                         (int)( ( m_nLength / ONE_SECOND ) / 60 ),
00662                         (int)( ( m_nLength / ONE_SECOND ) % 60 ) );
00663                 
00664                 sz                              = pMemDC->GetTextExtent( str );
00665                 rcPart.right    = rcStatus.right;
00666                 rcPart.left             = rcPart.right - sz.cx - 2;
00667                 rcStatus.right  = rcPart.left;
00668                 
00669                 pMemDC->DrawText( str, &rcPart, DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|DT_RIGHT );
00670         }
00671         
00672         if ( CMetaItem* pItem = m_pMetadata.GetFirst() )
00673         {
00674                 CString str = theApp.m_bRTL ? ':' + pItem->m_sKey : pItem->m_sKey + ':';
00675                 sz                              = pMemDC->GetTextExtent( str );
00676                 rcPart.left             = rcStatus.left;
00677                 rcPart.right    = rcPart.left + sz.cx + 2;
00678                 rcStatus.left   = rcPart.right;
00679 
00680                 pMemDC->DrawText( str, &rcPart, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX|dwOptions );
00681                 pMemDC->DrawText( pItem->m_sValue, &rcStatus, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS|dwOptions );
00682         }
00683         else
00684         {
00685                 if ( m_nState >= smsOpen )
00686                 {
00687                         int nSlash = m_sFile.ReverseFind( '\\' );
00688                         str = nSlash >= 0 ? m_sFile.Mid( nSlash + 1 ) : m_sFile;
00689                 }
00690                 
00691                 pMemDC->DrawText( str, &rcStatus, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS|dwOptions );
00692         }
00693 
00694         if ( theApp.m_bRTL ) 
00695                 dc.StretchBlt( rcBar.Width() + rcBar.left, rcBar.top, -rcBar.Width(), rcBar.Height(),
00696                         pMemDC, rcBar.left, rcBar.top, rcBar.Width(), rcBar.Height(), SRCCOPY );
00697         else
00698                 dc.BitBlt( rcBar.left, rcBar.top, rcBar.Width(), rcBar.Height(),
00699                         pMemDC, rcBar.left, rcBar.top, SRCCOPY );
00700 
00701         return TRUE;
00702 }
00703 
00705 // CMediaFrame interaction message handlers
00706 
00707 void CMediaFrame::OnContextMenu(CWnd* pWnd, CPoint point) 
00708 {
00709         Skin.TrackPopupMenu( _T("CMediaFrame"), point,
00710                 m_nState == smsPlaying ? ID_MEDIA_PAUSE : ID_MEDIA_PLAY );
00711 }
00712 
00713 void CMediaFrame::OnTimer(UINT nIDEvent) 
00714 {
00715         if ( nIDEvent == 1 )
00716         {
00717                 DWORD tNow = GetTickCount();
00718                 
00719                 UpdateState();
00720                 
00721                 if ( m_bFullScreen && ! m_bListVisible )
00722                 {
00723                         CPoint ptCursor;
00724                         GetCursorPos( &ptCursor );
00725                         
00726                         if ( ptCursor != m_ptCursor )
00727                         {
00728                                 m_tBarTime = tNow;
00729                                 m_ptCursor = ptCursor;
00730                                 SetTimer( 2, 50, NULL );
00731                         }
00732                 }
00733                 
00734                 if ( tNow - m_tMetadata > META_DELAY )
00735                 {
00736                         m_tMetadata = tNow;
00737                         m_pMetadata.Shuffle();
00738                 }
00739         }
00740         else if ( nIDEvent == 2 )
00741         {
00742                 OnSize( SIZE_BARSLIDE, 0, 0 );
00743         }
00744 }
00745 
00746 void CMediaFrame::OnClose() 
00747 {
00748         SetFullScreen( FALSE );
00749 }
00750 
00751 BOOL CMediaFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
00752 {
00753         if ( m_bListVisible )
00754         {
00755                 CRect rcClient, rc;
00756                 CPoint point;
00757                 
00758                 GetCursorPos( &point );
00759                 GetClientRect( &rcClient );
00760                 ClientToScreen( &rcClient );
00761                 
00762                 rc.SetRect(     theApp.m_bRTL ? rcClient.left + m_nListSize : 
00763                                         rcClient.right - m_nListSize - SPLIT_SIZE,
00764                                         rcClient.top,
00765                                         theApp.m_bRTL ? rcClient.left + m_nListSize + SPLIT_SIZE :
00766                                         rcClient.right - m_nListSize,
00767                                         rcClient.bottom );
00768                 
00769                 if ( rc.PtInRect( point ) )
00770                 {
00771                         SetCursor( AfxGetApp()->LoadStandardCursor( IDC_SIZEWE ) );
00772                         return TRUE;
00773                 }
00774         }
00775         else if ( m_bFullScreen )
00776         {
00777                 DWORD tElapse = GetTickCount() - m_tBarTime;
00778                 
00779                 if ( tElapse > TOOLBAR_STICK + TOOLBAR_ANIMATE )
00780                 {
00781                         SetCursor( NULL );
00782                         return TRUE;
00783                 }
00784         }
00785         
00786         return CWnd::OnSetCursor( pWnd, nHitTest, message );
00787 }
00788 
00789 void CMediaFrame::OnLButtonDown(UINT nFlags, CPoint point) 
00790 {
00791         CRect rcClient;
00792         GetClientRect( &rcClient );
00793         if ( theApp.m_bMenuWasVisible ) 
00794         {
00795                 theApp.m_bMenuWasVisible = FALSE ;
00796                 return;
00797         }
00798         if ( m_bListVisible )
00799         {
00800                 CRect rcBar(    rcClient.right - m_nListSize - SPLIT_SIZE,
00801                                                 rcClient.top,
00802                                                 rcClient.right - m_nListSize,
00803                                                 rcClient.bottom );
00804 
00805                 if ( rcBar.PtInRect( point ) )
00806                 {
00807                         DoSizeList();
00808                         return;
00809                 }
00810         }
00811         
00812         if (    ( m_bFullScreen && point.y <= STATUS_HEIGHT ) ||
00813                         ( ! m_bFullScreen && point.y >= rcClient.bottom - STATUS_HEIGHT - TOOLBAR_HEIGHT ) )
00814         {
00815                 OnMediaStatus();
00816                 return;
00817         }
00818 
00819         CRect rcSenseLess(      rcClient.right - m_nListSize - SPLIT_SIZE - 30,
00820                                                 rcClient.top,
00821                                                 rcClient.right - m_nListSize - SPLIT_SIZE,
00822                                                 rcClient.bottom );
00823 
00824         if ( rcSenseLess.PtInRect( point ) ) 
00825                 return;
00826 
00827         if ( m_nState == smsPlaying )
00828                 OnMediaPause();
00829         else if ( m_nState == smsPaused )
00830                 OnMediaPlay();
00831         
00832         CWnd::OnLButtonDown( nFlags, point );
00833 }
00834 
00835 void CMediaFrame::OnLButtonDblClk(UINT nFlags, CPoint point) 
00836 {
00837         OnMediaFullScreen();
00838         
00839         if ( m_nState == smsPlaying )
00840                 OnMediaPause();
00841         else if ( m_nState == smsPaused )
00842                 OnMediaPlay();
00843         
00844         CWnd::OnLButtonDblClk( nFlags, point );
00845 }
00846 
00847 BOOL CMediaFrame::DoSizeList()
00848 {
00849         MSG* pMsg = &AfxGetThreadState()->m_msgCur;
00850         CRect rcClient;
00851         CPoint point;
00852         
00853         GetClientRect( &rcClient );
00854         ClientToScreen( &rcClient );
00855         ClipCursor( &rcClient );
00856         SetCapture();
00857 
00858         GetClientRect( &rcClient );
00859         
00860         int nOffset = 0xFFFF;
00861         
00862         while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
00863         {
00864                 while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) );
00865 
00866                 if ( ! AfxGetThread()->PumpMessage() )
00867                 {
00868                         AfxPostQuitMessage( 0 );
00869                         break;
00870                 }
00871 
00872                 GetCursorPos( &point );
00873                 ScreenToClient( &point );
00874 
00875                 int nSplit = rcClient.right - point.x;
00876 
00877                 if ( nOffset == 0xFFFF ) nOffset = m_nListSize - nSplit;
00878                 nSplit += nOffset;
00879 
00880                 nSplit = max( nSplit, 0 );
00881                 nSplit = min( nSplit, int(rcClient.right - SPLIT_SIZE) );
00882 
00883                 if ( nSplit < 8 )
00884                         nSplit = 0;
00885                 if ( nSplit > rcClient.right - SPLIT_SIZE - 8 )
00886                         nSplit = rcClient.right - SPLIT_SIZE;
00887 
00888                 if ( nSplit != m_nListSize )
00889                 {
00890                         m_nListSize = nSplit;
00891                         OnSize( SIZE_INTERNAL, 0, 0 );
00892                         Invalidate();
00893                 }
00894         }
00895         
00896         ReleaseCapture();
00897         ClipCursor( NULL );
00898         
00899         return TRUE;
00900 }
00901 
00902 LONG CMediaFrame::OnMediaKey(WPARAM wParam, LPARAM lParam)
00903 {
00904         if ( wParam != 1 ) return 0;
00905         
00906         switch ( lParam )
00907         {
00908         case 0xB0000:
00909                 GetOwner()->PostMessage( WM_COMMAND, ID_MEDIA_NEXT );
00910                 return 1;
00911         case 0xC0000:
00912                 GetOwner()->PostMessage( WM_COMMAND, ID_MEDIA_PREVIOUS );
00913                 return 1;
00914         case 0xD0000:
00915                 GetOwner()->PostMessage( WM_COMMAND, ID_MEDIA_STOP );
00916                 return 1;
00917         case 0xE0000:
00918                 GetOwner()->PostMessage( WM_COMMAND, m_nState == smsPlaying ? ID_MEDIA_PAUSE : ID_MEDIA_PLAY );
00919                 return 1;
00920         }
00921 
00922         return 0;
00923 }
00924 
00926 // CMediaFrame thumb bars
00927 
00928 void CMediaFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
00929 {
00930         if ( pScrollBar == (CScrollBar*)&m_wndVolume )
00931         {
00932                 double nVolume = (double)m_wndVolume.GetPos() / 100.0f;
00933                 
00934                 if ( nVolume != Settings.MediaPlayer.Volume )
00935                 {
00936                         Settings.MediaPlayer.Volume = nVolume;
00937                         if ( m_pPlayer != NULL ) m_pPlayer->SetVolume( m_bMute ? 0 : Settings.MediaPlayer.Volume );
00938                 }
00939         }
00940         
00941         if ( m_pPlayer == NULL ) return;
00942         
00943         MediaState nState = smsNull;
00944         if ( FAILED( m_pPlayer->GetState( &nState ) ) ) return;
00945         if ( nState < smsOpen ) return;
00946         
00947         if ( pScrollBar == (CScrollBar*)&m_wndPosition )
00948         {
00949                 LONGLONG nLength = 0;
00950                 if ( FAILED( m_pPlayer->GetLength( &nLength ) ) ) return;
00951                 nLength /= TIME_FACTOR;
00952                 
00953                 LONGLONG nPosition = 0;
00954                 if ( FAILED( m_pPlayer->GetPosition( &nPosition ) ) ) return;
00955                 nPosition /= TIME_FACTOR;
00956                 
00957                 switch ( nSBCode )
00958                 {
00959                 case TB_TOP:
00960                         nPosition = 0;
00961                         break;
00962                 case TB_BOTTOM:
00963                         nPosition = nLength;
00964                         break;
00965                 case TB_LINEUP:
00966                         nPosition -= 5;
00967                         break;
00968                 case TB_LINEDOWN:
00969                         nPosition += 5;
00970                         break;
00971                 case TB_PAGEUP:
00972                 case TB_PAGEDOWN:
00973                         if ( TRUE )
00974                         {
00975                                 CRect rc1, rc2;
00976                                 CPoint pt;
00977                                 
00978                                 GetCursorPos( &pt );
00979                                 pScrollBar->GetWindowRect( &rc1 );
00980                                 ((CSliderCtrl*)pScrollBar)->GetChannelRect( &rc2 );
00981 
00982                                 if ( rc1.PtInRect( pt ) )
00983                                 {
00984                                         rc2.OffsetRect( rc1.left, rc1.top );
00985                                         if ( pt.x <= rc2.left )
00986                                                 nPosition = 0;
00987                                         else if ( pt.x >= rc2.right )
00988                                                 nPosition = nLength;
00989                                         else
00990                                                 nPosition = (LONGLONG)( (double)( pt.x - rc2.left ) / (double)rc2.Width() * (double)nLength );
00991                                 }
00992                         }
00993                         break;
00994                 case TB_THUMBPOSITION:
00995                 case TB_THUMBTRACK:
00996                         nPosition = (int)nPos;
00997                         break;
00998                 }
00999                 
01000                 if ( nState == smsOpen ) nPosition = 0;
01001                 if ( nPosition < 0 ) nPosition = 0;
01002                 if ( nPosition > nLength ) nPosition = nLength;
01003                 
01004                 if ( nState == smsPlaying )
01005                 {
01006                         m_pPlayer->Pause();
01007                         m_bThumbPlay = TRUE;
01008                 }
01009                 
01010                 m_pPlayer->SetPosition( nPosition * TIME_FACTOR );
01011                 m_wndPosition.SetPos( (int)nPosition );
01012                 
01013                 if ( m_bThumbPlay && nSBCode == TB_ENDTRACK )
01014                 {
01015                         m_pPlayer->Play();
01016                         m_bThumbPlay = FALSE;
01017                 }
01018                 
01019                 UpdateState();
01020                 UpdateWindow();
01021         }
01022         else if ( pScrollBar == (CScrollBar*)&m_wndSpeed )
01023         {
01024                 double nNewSpeed = (double)m_wndSpeed.GetPos() / 100.0f;
01025                 double nOldSpeed;
01026                 
01027                 if ( nSBCode == TB_TOP || nSBCode == TB_BOTTOM )
01028                 {
01029                         nNewSpeed = 1.0f;
01030                         m_wndSpeed.SetPos( 100 );
01031                 }
01032 
01033                 m_pPlayer->GetSpeed( &nOldSpeed );
01034                 if ( nNewSpeed != nOldSpeed ) m_pPlayer->SetSpeed( nNewSpeed );
01035         }
01036 }
01037 
01039 // CMediaFrame command handlers
01040 
01041 void CMediaFrame::OnUpdateMediaClose(CCmdUI* pCmdUI) 
01042 {
01043         pCmdUI->Enable( m_wndList.GetItemCount() > 0 );
01044 }
01045 
01046 void CMediaFrame::OnMediaClose() 
01047 {
01048         Cleanup();
01049         m_wndList.Clear();
01050 }
01051 
01052 void CMediaFrame::OnUpdateMediaPlay(CCmdUI* pCmdUI) 
01053 {
01054         MediaState nState = m_nState;
01055         if ( m_bThumbPlay && nState == smsPaused ) nState = smsPlaying;
01056         pCmdUI->Enable( m_nState < smsPlaying );
01057         if ( CCoolBarItem* pItem = CCoolBarItem::FromCmdUI( pCmdUI ) )
01058                 pItem->Show( nState != smsPlaying );
01059 }
01060 
01061 void CMediaFrame::OnMediaPlay() 
01062 {
01063         if ( m_nState < smsOpen )
01064         {
01065                 if ( m_wndList.GetCount() == 0 ) 
01066                         PostMessage( WM_COMMAND, ID_MEDIA_OPEN );
01067                 else
01068                         m_wndList.GetNext();
01069         }
01070         else
01071         {
01072                 if ( m_pPlayer != NULL ) m_pPlayer->Play();
01073                 UpdateState();
01074         }
01075 }
01076 
01077 void CMediaFrame::OnUpdateMediaPause(CCmdUI* pCmdUI) 
01078 {
01079         MediaState nState = m_nState;
01080         if ( m_bThumbPlay && nState == smsPaused ) nState = smsPlaying;
01081         pCmdUI->Enable( nState == smsPlaying );
01082         if ( CCoolBarItem* pItem = CCoolBarItem::FromCmdUI( pCmdUI ) )
01083                 pItem->Show( nState == smsPlaying );
01084 }
01085 
01086 void CMediaFrame::OnMediaPause() 
01087 {
01088         if ( m_pPlayer ) m_pPlayer->Pause();
01089         UpdateState();
01090         if ( ! m_bScreenSaverEnabled ) EnableScreenSaver();
01091 }
01092 
01093 void CMediaFrame::OnUpdateMediaStop(CCmdUI* pCmdUI) 
01094 {
01095         pCmdUI->Enable( m_nState > smsOpen );
01096 }
01097 
01098 void CMediaFrame::OnMediaStop() 
01099 {
01100         if ( m_pPlayer ) m_pPlayer->Stop();
01101         m_bStopFlag = TRUE;
01102         m_wndList.Reset();
01103         EnableScreenSaver();
01104 }
01105 
01106 void CMediaFrame::OnUpdateMediaFullScreen(CCmdUI* pCmdUI) 
01107 {
01108         pCmdUI->SetCheck( m_bFullScreen );
01109 }
01110 
01111 void CMediaFrame::OnMediaFullScreen() 
01112 {
01113         SetFullScreen( ! m_bFullScreen );
01114 }
01115 
01116 void CMediaFrame::OnMediaZoom() 
01117 {
01118         CMenu* pMenu = Skin.GetMenu( _T("CMediaFrame.Zoom") );
01119         m_wndToolBar.ThrowMenu( ID_MEDIA_ZOOM, pMenu );
01120 }
01121 
01122 void CMediaFrame::OnUpdateMediaSizeFill(CCmdUI* pCmdUI) 
01123 {
01124         pCmdUI->SetCheck( Settings.MediaPlayer.Zoom == smzFill );
01125 }
01126 
01127 void CMediaFrame::OnMediaSizeFill() 
01128 {
01129         ZoomTo( smzFill );
01130 }
01131 
01132 void CMediaFrame::OnUpdateMediaSizeDistort(CCmdUI* pCmdUI) 
01133 {
01134         pCmdUI->SetCheck( Settings.MediaPlayer.Zoom == smzDistort );
01135 }
01136 
01137 void CMediaFrame::OnMediaSizeDistort() 
01138 {
01139         ZoomTo( smzDistort );
01140 }
01141 
01142 void CMediaFrame::OnUpdateMediaSizeOne(CCmdUI* pCmdUI) 
01143 {
01144         pCmdUI->SetCheck( Settings.MediaPlayer.Zoom == 1 );
01145 }
01146 
01147 void CMediaFrame::OnMediaSizeOne() 
01148 {
01149         ZoomTo( (MediaZoom)1 );
01150 }
01151 
01152 void CMediaFrame::OnUpdateMediaSizeTwo(CCmdUI* pCmdUI) 
01153 {
01154         pCmdUI->SetCheck( Settings.MediaPlayer.Zoom == 2 );
01155 }
01156 
01157 void CMediaFrame::OnMediaSizeTwo() 
01158 {
01159         ZoomTo( (MediaZoom)2 );
01160 }
01161 
01162 void CMediaFrame::OnUpdateMediaSizeThree(CCmdUI* pCmdUI) 
01163 {
01164         pCmdUI->SetCheck( Settings.MediaPlayer.Zoom == 3 );
01165 }
01166 
01167 void CMediaFrame::OnMediaSizeThree() 
01168 {
01169         ZoomTo( (MediaZoom)3 );
01170 }
01171 
01172 void CMediaFrame::OnUpdateMediaAspectDefault(CCmdUI* pCmdUI) 
01173 {
01174         pCmdUI->Enable( Settings.MediaPlayer.Zoom != smzDistort );
01175         pCmdUI->SetCheck( Settings.MediaPlayer.Aspect == smaDefault );
01176 }
01177 
01178 void CMediaFrame::OnMediaAspectDefault() 
01179 {
01180         AspectTo( smaDefault );
01181 }
01182 
01183 void CMediaFrame::OnUpdateMediaAspect43(CCmdUI* pCmdUI) 
01184 {
01185         pCmdUI->Enable( Settings.MediaPlayer.Zoom != smzDistort );
01186         pCmdUI->SetCheck( fabs( Settings.MediaPlayer.Aspect - 4.0f/3.0f ) < 0.1f );
01187 }
01188 
01189 void CMediaFrame::OnMediaAspect43() 
01190 {
01191         AspectTo( (4.0f/3.0f) );
01192 }
01193 
01194 void CMediaFrame::OnUpdateMediaAspect169(CCmdUI* pCmdUI) 
01195 {
01196         pCmdUI->Enable( Settings.MediaPlayer.Zoom != smzDistort );
01197         pCmdUI->SetCheck( fabs( Settings.MediaPlayer.Aspect - 16.0f/9.0f ) < 0.1f );
01198 }
01199 
01200 void CMediaFrame::OnMediaAspect169() 
01201 {
01202         AspectTo( (16.0f/9.0f) );
01203 }
01204 
01205 void CMediaFrame::OnUpdateMediaPlaylist(CCmdUI* pCmdUI) 
01206 {
01207         pCmdUI->SetCheck( m_bListVisible );
01208 }
01209 
01210 void CMediaFrame::OnMediaPlaylist() 
01211 {
01212         m_bListVisible = ! m_bListVisible;
01213         m_tBarTime = GetTickCount();
01214         OnSize( SIZE_INTERNAL, 0, 0 );
01215 }
01216 
01217 void CMediaFrame::OnUpdateMediaStatus(CCmdUI* pCmdUI) 
01218 {
01219         pCmdUI->SetCheck( m_bStatusVisible );
01220 }
01221 
01222 void CMediaFrame::OnMediaStatus() 
01223 {
01224         m_bStatusVisible = ! m_bStatusVisible;
01225         OnSize( SIZE_INTERNAL, 0, 0 );
01226 }
01227 
01228 void CMediaFrame::OnUpdateMediaVis(CCmdUI* pCmdUI) 
01229 {
01230         pCmdUI->Enable( ! m_bFullScreen );
01231 }
01232 
01233 void CMediaFrame::OnMediaVis() 
01234 {
01235         CMediaVisDlg dlg( this );
01236         if ( dlg.DoModal() == IDOK ) PrepareVis();
01237 }
01238 
01239 void CMediaFrame::OnUpdateMediaSettings(CCmdUI* pCmdUI) 
01240 {
01241         pCmdUI->Enable( ! m_bFullScreen );
01242 }
01243 
01244 void CMediaFrame::OnMediaSettings() 
01245 {
01246         CSettingsManagerDlg::Run( _T("CMediaSettingsPage") );
01247 }
01248 
01249 void CMediaFrame::OnUpdateMediaMute(CCmdUI* pCmdUI) 
01250 {
01251         pCmdUI->SetCheck( m_bMute );
01252 }
01253 
01254 void CMediaFrame::OnMediaMute() 
01255 {
01256         m_bMute = ! m_bMute;
01257         if ( m_pPlayer != NULL ) m_pPlayer->SetVolume( m_bMute ? 0 : Settings.MediaPlayer.Volume );
01258 }
01259 
01261 // CMediaFrame public media operations
01262 
01263 BOOL CMediaFrame::PlayFile(LPCTSTR pszFile)
01264 {
01265         UpdateWindow();
01266 
01267         DWORD tNow = GetTickCount();
01268 
01269         if ( tNow - m_tLastPlay < 500 )
01270         {
01271                 m_tLastPlay = tNow;
01272                 return EnqueueFile( pszFile );
01273         }
01274         else
01275         {
01276                 m_tLastPlay = tNow;
01277                 return m_wndList.Open( pszFile );
01278         }
01279 }
01280 
01281 BOOL CMediaFrame::EnqueueFile(LPCTSTR pszFile)
01282 {
01283         m_bEnqueue = TRUE;
01284         BOOL bResult = m_wndList.Enqueue( pszFile, TRUE );
01285         m_bLastMedia = FALSE;
01286         m_bLastNotPlayed = TRUE;
01287         m_bEnqueue = FALSE;
01288         return bResult;
01289 }
01290 
01291 BOOL CMediaFrame::IsPlaying()
01292 {
01293         return m_pPlayer != NULL && m_nState == smsPlaying;
01294 }
01295 
01296 void CMediaFrame::OnFileDelete(LPCTSTR pszFile)
01297 {
01298         if ( m_sFile.CompareNoCase( pszFile ) == 0 )
01299         {
01300                 if ( m_pPlayer ) m_pPlayer->Close();
01301         }
01302 }
01303 
01304 float CMediaFrame::GetPosition()
01305 {
01306         if ( m_pPlayer != NULL && m_nState >= smsOpen && m_nLength > 0 )
01307         {
01308                 return (float)m_nPosition / (float)m_nLength;
01309         }
01310         else
01311         {
01312                 return 0;
01313         }
01314 }
01315 
01316 BOOL CMediaFrame::SeekTo(float nPosition)
01317 {
01318         if ( m_pPlayer != NULL && m_nState >= smsPaused && m_nLength > 0 )
01319         {
01320                 m_nPosition = (LONGLONG)( nPosition * (float)m_nLength );
01321                 m_pPlayer->SetPosition( m_nPosition );
01322                 OnTimer( 1 );
01323                 return TRUE;
01324         }
01325         else
01326         {
01327                 return FALSE;
01328         }
01329 }
01330 
01331 float CMediaFrame::GetVolume()
01332 {
01333         return (float)Settings.MediaPlayer.Volume;
01334 }
01335 
01336 BOOL CMediaFrame::SetVolume(float nVolume)
01337 {
01338         Settings.MediaPlayer.Volume = (double)nVolume;
01339         if ( m_pPlayer != NULL ) m_pPlayer->SetVolume( m_bMute ? 0 : Settings.MediaPlayer.Volume );
01340         OnTimer( 1 );
01341         return ( m_pPlayer != NULL );
01342 }
01343 
01345 // CMediaFrame private media operations
01346 
01347 BOOL CMediaFrame::Prepare()
01348 {
01349         m_bThumbPlay = FALSE;
01350 
01351         if ( m_pPlayer != NULL ) return TRUE;
01352         if ( GetSafeHwnd() == NULL ) return FALSE;
01353         
01354         CWaitCursor pCursor;
01355         CLSID pCLSID;
01356         
01357         if ( Plugins.LookupCLSID( _T("MediaPlayer"), _T("Default"), pCLSID ) )
01358         {
01359                 HINSTANCE hRes = AfxGetResourceHandle();
01360                 CoCreateInstance( pCLSID, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER,
01361                         IID_IMediaPlayer, (void**)&m_pPlayer );
01362                 AfxSetResourceHandle( hRes );
01363         }
01364         
01365         if ( m_pPlayer == NULL )
01366         {
01367                 pCursor.Restore();
01368                 CString strMessage;
01369                 Skin.LoadString( strMessage, IDS_MEDIA_PLUGIN_CREATE );
01370                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
01371                 return FALSE;
01372         }
01373         ModifyStyleEx( WS_EX_LAYOUTRTL, 0, 0 );
01374         m_pPlayer->Create( GetSafeHwnd() );
01375         if ( theApp.m_bRTL ) ModifyStyleEx( 0, WS_EX_LAYOUTRTL, 0 );
01376         m_pPlayer->SetZoom( Settings.MediaPlayer.Zoom );
01377         m_pPlayer->SetAspect( Settings.MediaPlayer.Aspect );
01378         m_pPlayer->SetVolume( m_bMute ? 0 : Settings.MediaPlayer.Volume );
01379         
01380         if ( m_bmLogo.m_hObject ) m_pPlayer->SetLogoBitmap( (HBITMAP)m_bmLogo.m_hObject );
01381         
01382         if ( TRUE )
01383         {
01384                 HINSTANCE hRes = AfxGetResourceHandle();
01385                 PrepareVis();
01386                 AfxSetResourceHandle( hRes );
01387         }
01388         
01389         OnSize( SIZE_INTERNAL, 0, 0 );
01390         UpdateState();
01391         
01392         return TRUE;
01393 }
01394 
01395 BOOL CMediaFrame::PrepareVis()
01396 {
01397         if ( m_pPlayer == NULL ) return FALSE;
01398         
01399         IAudioVisPlugin* pPlugin = NULL;
01400         CLSID pCLSID;
01401         
01402         if ( GUIDX::Decode( Settings.MediaPlayer.VisCLSID, &pCLSID ) &&
01403                  Plugins.LookupEnable( pCLSID, TRUE ) )
01404         {
01405                 HRESULT hr = CoCreateInstance( pCLSID, NULL,
01406                         CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IAudioVisPlugin,
01407                         (void**)&pPlugin );
01408                 
01409                 if ( SUCCEEDED(hr) && pPlugin != NULL )
01410                 {
01411                         if ( Settings.MediaPlayer.VisPath.GetLength() )
01412                         {
01413                                 IWrappedPluginControl* pWrap = NULL;
01414                                 
01415                                 hr = pPlugin->QueryInterface( IID_IWrappedPluginControl,
01416                                         (void**)&pWrap );
01417 
01418                                 if ( SUCCEEDED(hr) && pWrap != NULL )
01419                                 {
01420                                         BSTR bsPath = Settings.MediaPlayer.VisPath.AllocSysString();
01421                                         hr = pWrap->Load( bsPath, 0 );
01422                                         SysFreeString( bsPath );
01423                                         pWrap->Release();
01424                                 }
01425                                 
01426                                 if ( FAILED(hr) )
01427                                 {
01428                                         pPlugin->Release();
01429                                         pPlugin = NULL;
01430                                 }
01431                         }
01432                 }
01433         }
01434         
01435         m_pPlayer->SetPluginSize( Settings.MediaPlayer.VisSize );
01436         m_pPlayer->SetPlugin( pPlugin );
01437         
01438         if ( pPlugin != NULL ) pPlugin->Release();
01439         
01440         return TRUE;
01441 }
01442 
01443 BOOL CMediaFrame::OpenFile(LPCTSTR pszFile)
01444 {
01445         if ( ! Prepare() ) return FALSE;
01446         
01447         if ( m_sFile == pszFile )
01448         {
01449                 m_pPlayer->Stop();
01450                 UpdateState();
01451                 return TRUE;
01452         }
01453         
01454         CWaitCursor pCursor;
01455         m_sFile.Empty();
01456         m_pMetadata.Clear();
01457         
01458         HINSTANCE hRes = AfxGetResourceHandle();
01459         
01460         BSTR bsFile = CString( pszFile ).AllocSysString();
01461         HRESULT hr = PluginPlay( bsFile );
01462 
01463         SysFreeString( bsFile );
01464 
01465         AfxSetResourceHandle( hRes );
01466         
01467         UpdateState();
01468         pCursor.Restore();
01469         m_tMetadata = GetTickCount();
01470         
01471         if ( FAILED(hr) )
01472         {
01473                 LPCTSTR pszBase = _tcsrchr( pszFile, '\\' );
01474                 pszBase = pszBase ? pszBase + 1 : pszFile;
01475                 CString strMessage, strFormat;
01476                 LoadString( strFormat, IDS_MEDIA_LOAD_FAIL );
01477                 strMessage.Format( strFormat, pszBase );
01478                 m_pMetadata.Add( _T("Error"), strMessage );
01479                 LoadString( strMessage, IDS_MEDIA_LOAD_FAIL_HELP );
01480                 m_pMetadata.Add( _T("Error"), strMessage );
01481                 return FALSE;
01482         }
01483         
01484         m_sFile = pszFile;
01485         
01486         {
01487                 CSingleLock oLock( &Library.m_pSection, TRUE );
01488                 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( m_sFile ) )
01489                 {
01490                         m_pMetadata.Add( _T("Filename"), pFile->m_sName );
01491                         m_pMetadata.Setup( pFile->m_pSchema, FALSE );
01492                         m_pMetadata.Combine( pFile->m_pMetadata );
01493                         m_pMetadata.Clean( 1024 );
01494                         oLock.Unlock();
01495                         
01496                         CMetaItem* pWidth       = m_pMetadata.Find( _T("Width") );
01497                         CMetaItem* pHeight      = m_pMetadata.Find( _T("Height") );
01498                         
01499                         if ( pWidth != NULL && pHeight != NULL )
01500                         {
01501                                 pWidth->m_sKey = _T("Dimensions");
01502                                 pWidth->m_sValue += 'x' + pHeight->m_sValue;
01503                                 m_pMetadata.Remove( _T("Height") );
01504                         }
01505                 }
01506         }
01507         
01508         if ( hr != S_OK )
01509         {
01510                 CString strMessage;
01511                 LoadString( strMessage, IDS_MEDIA_PARTIAL_RENDER );
01512                 m_pMetadata.Add( _T("Warning"), strMessage );
01513         }
01514         
01515         return TRUE;
01516 }
01517 
01518 HRESULT CMediaFrame::PluginPlay(BSTR bsFilePath)
01519 {
01520         HRESULT hr = E_FAIL;
01521         __try
01522         {
01523                 hr = m_pPlayer->Stop();
01524                 hr = m_pPlayer->Open( bsFilePath );
01525         } 
01526         __except( GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION )
01527         { 
01528                 theApp.Message( MSG_ERROR, _T("Media Player failed to open file: %s"), bsFilePath );
01529                 Cleanup(); 
01530                 return EXCEPTION_CONTINUE_EXECUTION;
01531         }
01532         return hr;
01533 }
01534 
01535 void CMediaFrame::Cleanup()
01536 {
01537         m_sFile.Empty();
01538         m_pMetadata.Clear();
01539         
01540         if ( m_pPlayer != NULL )
01541         {
01542                 HINSTANCE hRes = AfxGetResourceHandle();
01543                 m_pPlayer->Close();
01544                 m_pPlayer->Destroy();
01545                 m_pPlayer->Release();
01546                 m_pPlayer = NULL;
01547                 AfxSetResourceHandle( hRes );
01548         }
01549         
01550         UpdateState();
01551         Invalidate();
01552 }
01553 
01554 void CMediaFrame::ZoomTo(MediaZoom nZoom)
01555 {
01556         if ( Settings.MediaPlayer.Zoom == nZoom ) return;
01557         Settings.MediaPlayer.Zoom = nZoom;
01558         if ( m_pPlayer == NULL ) return;
01559         m_pPlayer->SetZoom( Settings.MediaPlayer.Zoom );
01560 }
01561 
01562 void CMediaFrame::AspectTo(double nAspect)
01563 {
01564         if ( Settings.MediaPlayer.Aspect == nAspect ) return;
01565         Settings.MediaPlayer.Aspect = nAspect;
01566         if ( m_pPlayer == NULL ) return;
01567         m_pPlayer->SetAspect( Settings.MediaPlayer.Aspect );
01568 }
01569 
01570 void CMediaFrame::UpdateState()
01571 {
01572         m_nState = smsNull;
01573         
01574         if ( m_pPlayer ) m_pPlayer->GetState( &m_nState );
01575         
01576         if ( m_nState >= smsOpen )
01577         {
01578                 m_nLength = 0;
01579                 m_pPlayer->GetLength( &m_nLength );
01580                 int nLength = (int)( m_nLength / TIME_FACTOR );
01581                 
01582                 m_nPosition = 0;
01583                 m_pPlayer->GetPosition( &m_nPosition );
01584                 int nPosition = (int)( m_nPosition / TIME_FACTOR );
01585                 
01586                 m_wndPosition.EnableWindow( TRUE );
01587                 m_wndPosition.SetRangeMax( (int)nLength );
01588                 m_wndPosition.SetPos( (int)nPosition );
01589                 
01590                 double nSpeed = 1.0f;
01591                 m_pPlayer->GetSpeed( &nSpeed );
01592                 m_wndSpeed.SetPos( (int)( nSpeed * 100 ) );
01593                 m_wndSpeed.EnableWindow( TRUE );
01594                 
01595                 if ( ! m_bMute )
01596                 {
01597                         Settings.MediaPlayer.Volume = 1.0f;
01598                         m_pPlayer->GetVolume( &Settings.MediaPlayer.Volume );
01599                 }
01600                 
01601                 if ( m_nState == smsPlaying && nPosition >= nLength && nPosition != 0 )
01602                 {
01603                         m_wndList.GetNext();
01604                 }
01605         }
01606         else
01607         {
01608                 if ( m_nState != smsNull && m_wndList.GetCount() == 0 ) Cleanup();
01609                 m_wndPosition.SetPos( 0 );
01610                 m_wndPosition.SetRange( 0, 0 );
01611                 m_wndPosition.EnableWindow( FALSE );
01612                 m_wndSpeed.SetPos( 100 );
01613                 m_wndSpeed.EnableWindow( FALSE );
01614         }
01615         
01616         m_wndVolume.SetPos( (int)( Settings.MediaPlayer.Volume * 100 ) );
01617         
01618         if ( m_bStatusVisible )
01619         {
01620                 InvalidateRect( &m_rcStatus );
01621         }
01622 }
01623 
01624 void CMediaFrame::OnNewCurrent(NMHDR* pNotify, LRESULT* pResult)
01625 {
01626         int nCurrent = m_wndList.GetCurrent();
01627         m_wndList.UpdateWindow();
01628         m_bRepeat = Settings.MediaPlayer.Repeat;
01629         m_bLastMedia = ( nCurrent == m_wndList.GetItemCount() - 1 );
01630 
01631         if ( m_bStopFlag )
01632         {
01633                 m_bStopFlag = FALSE;
01634                 m_bLastNotPlayed = FALSE;
01635                 if ( m_pPlayer ) Cleanup();
01636                 if ( ! m_bScreenSaverEnabled ) EnableScreenSaver();
01637                 *pResult = 0;
01638                 return;
01639         }
01640 
01641         if ( nCurrent >= 0 ) // not the last in the list
01642         {
01643                 BOOL bPlayIt;
01644                 BOOL bCorrupted = FALSE;
01645 
01646                 if ( m_bEnqueue )
01647                         bPlayIt = FALSE;
01648                 else
01649                 {
01650                         // Play when repeat is on or when whithin the playlist
01651                         bPlayIt = m_bRepeat || ! m_bLastMedia || m_bLastNotPlayed;
01652                         // The whole playlist was played and the list was reset
01653                         if ( ! m_bRepeat && m_bLastNotPlayed && ! m_bLastMedia )
01654                         {
01655                                 if ( m_nState != smsPlaying )
01656                         bPlayIt = FALSE;
01657                                 else // New file was clicked, clear the flag
01658                                         m_bLastNotPlayed = FALSE;
01659                         }
01660 
01661                         if ( ! m_pPlayer || bPlayIt || m_wndList.GetItemCount() == 1 )
01662                         {
01663                                 bPlayIt = TRUE;
01664                                 bCorrupted = ! OpenFile( m_wndList.GetPath( nCurrent ) );
01665                         }
01666                 }
01667 
01668                 if ( bPlayIt && ! bCorrupted )
01669                 {
01670                         m_pPlayer->Play();
01671                         if ( m_bScreenSaverEnabled ) DisableScreenSaver();
01672                         // check if the last was not played; flag only when we are playing the file before it
01673                         if ( ! m_bLastNotPlayed )
01674                                 m_bLastNotPlayed = ( nCurrent == m_wndList.GetItemCount() - 2 );
01675                         UpdateState();
01676                 }
01677                 else if ( bCorrupted ) // file was corrupted, move to the next file
01678                 {
01679                         nCurrent = m_wndList.GetNext( FALSE );
01680                         if ( m_wndList.GetItemCount() != 1 ) 
01681                                 m_wndList.SetCurrent( nCurrent );
01682                         else if ( m_pPlayer ) 
01683                                 Cleanup(); //cleanup when no exception happened but the file couldn't be opened (png files)
01684                 }
01685                 else
01686                 {
01687                         // reset list and cleanup
01688                         m_bLastNotPlayed = FALSE;
01689                         m_wndList.Reset( TRUE );
01690                         m_bStopFlag = FALSE;
01691                         if ( m_pPlayer ) Cleanup();
01692                 }
01693         }
01694         else if ( m_wndList.GetItemCount() > 0 ) // the list was reset; current file was set to -1
01695         {
01696                 nCurrent = m_wndList.GetCurrent(); // get file #0
01697 
01698                 if ( m_pPlayer )
01699                 {
01700                         if ( ! m_bRepeat ) 
01701                                 m_bStopFlag = TRUE;
01702                         else
01703                                 nCurrent = m_wndList.GetNext( FALSE );
01704                         if ( ! m_bEnqueue ) 
01705                                 m_wndList.SetCurrent( nCurrent );
01706                 }
01707         }
01708         else if ( m_pPlayer ) 
01709                 Cleanup();
01710 
01711         *pResult = 0;
01712 }
01713 
01715 // Screensaver Enable / Disable functions from
01716 // http://www.codeproject.com/system/disablescreensave.asp
01717 
01718 static UINT dss_GetList[] = {SPI_GETLOWPOWERTIMEOUT, 
01719     SPI_GETPOWEROFFTIMEOUT, SPI_GETSCREENSAVETIMEOUT};
01720 static UINT dss_SetList[] = {SPI_SETLOWPOWERTIMEOUT, 
01721     SPI_SETPOWEROFFTIMEOUT, SPI_SETSCREENSAVETIMEOUT};
01722 
01723 static const int dss_ListCount = sizeof( dss_GetList ) / sizeof( dss_GetList[0] );
01724 
01725 void CMediaFrame::DisableScreenSaver()
01726 {
01727         if ( m_bScreenSaverEnabled )
01728         {
01729                 m_pScreenSaveValue = new int[dss_ListCount];
01730 
01731                 for ( int x=0; x < dss_ListCount; x++ )
01732                 {
01733                         // Get the current value
01734                         VERIFY( SystemParametersInfo( dss_GetList[x], 0, 
01735                                 &m_pScreenSaveValue[x], 0 ) );
01736 
01737                         TRACE(_T("%d = %d\n"), dss_GetList[x], m_pScreenSaveValue[x]);
01738 
01739                         // Turn off the parameter
01740                         VERIFY( SystemParametersInfo( dss_SetList[x], 0, 
01741                                 NULL, 0 ) );
01742                 }
01743                 m_bScreenSaverEnabled = FALSE;
01744         }
01745 }
01746 
01747 void CMediaFrame::EnableScreenSaver()
01748 {
01749     if ( ! m_bScreenSaverEnabled )
01750         {
01751                 for ( int x=0; x < dss_ListCount; x++ )
01752                 {
01753                         // Set the old value
01754                         VERIFY( SystemParametersInfo( dss_SetList[x], 
01755                                 m_pScreenSaveValue[x], NULL, 0 ) );
01756                 }
01757 
01758                 delete[] m_pScreenSaveValue;
01759                 m_bScreenSaverEnabled = TRUE;
01760         }
01761 }
01762 
01763 void CMediaFrame::UpdateScreenSaverStatus(BOOL bWindowActive)
01764 {
01765         if ( bWindowActive )
01766         {
01767                 if ( m_bScreenSaverEnabled && IsPlaying() ) 
01768                         DisableScreenSaver();
01769         }
01770         else
01771         {
01772                 if ( ! m_bScreenSaverEnabled ) 
01773                         EnableScreenSaver();
01774         }
01775 }

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