00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PlayerStatusBar.h"
00028 #include "MainFrm.h"
00029 #include "..\..\DSUtil\DSUtil.h"
00030
00031
00032
00033 IMPLEMENT_DYNAMIC(CPlayerStatusBar, CDialogBar)
00034
00035 CPlayerStatusBar::CPlayerStatusBar()
00036 : m_status(false, false)
00037 , m_time(true, false)
00038 , m_bmid(0)
00039 , m_hIcon(0)
00040 {
00041 }
00042
00043 CPlayerStatusBar::~CPlayerStatusBar()
00044 {
00045 if(m_hIcon) DestroyIcon(m_hIcon);
00046 }
00047
00048 BOOL CPlayerStatusBar::Create(CWnd* pParentWnd)
00049 {
00050 return CDialogBar::Create(pParentWnd, IDD_PLAYERSTATUSBAR, WS_CHILD|WS_VISIBLE|CBRS_ALIGN_BOTTOM, IDD_PLAYERSTATUSBAR);
00051 }
00052
00053 BOOL CPlayerStatusBar::PreCreateWindow(CREATESTRUCT& cs)
00054 {
00055 if(!CDialogBar::PreCreateWindow(cs))
00056 return FALSE;
00057
00058 m_dwStyle &= ~CBRS_BORDER_TOP;
00059 m_dwStyle &= ~CBRS_BORDER_BOTTOM;
00060
00061 return TRUE;
00062 }
00063
00064 int CPlayerStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
00065 {
00066 if(CDialogBar::OnCreate(lpCreateStruct) == -1)
00067 return -1;
00068
00069 CRect r;
00070 r.SetRectEmpty();
00071
00072 m_type.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_ICON,
00073 r, this, IDC_STATIC1);
00074
00075 m_status.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_OWNERDRAW,
00076 r, this, ID_PLAYERSTATUS);
00077
00078 m_time.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_OWNERDRAW,
00079 r, this, ID_PLAYERTIME);
00080
00081 m_status.SetWindowPos(&m_time, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
00082
00083 Relayout();
00084
00085 return 0;
00086 }
00087
00088 void CPlayerStatusBar::Relayout()
00089 {
00090 BITMAP bm;
00091 memset(&bm, 0, sizeof(bm));
00092 if(m_bm.m_hObject) m_bm.GetBitmap(&bm);
00093
00094 CRect r, r2;
00095 GetClientRect(r);
00096
00097 r.DeflateRect(27, 5, bm.bmWidth + 8, 4);
00098 int div = r.right - (m_time.IsWindowVisible() ? 140 : 0);
00099
00100 CString str;
00101 m_time.GetWindowText(str);
00102 if(CDC* pDC = m_time.GetDC())
00103 {
00104 CFont* pOld = pDC->SelectObject(&m_time.GetFont());
00105 div = r.right - pDC->GetTextExtent(str).cx;
00106 pDC->SelectObject(pOld);
00107 m_time.ReleaseDC(pDC);
00108 }
00109
00110 r2 = r;
00111 r2.right = div - 2;
00112 m_status.MoveWindow(&r2);
00113
00114 r2 = r;
00115 r2.left = div;
00116 m_time.MoveWindow(&r2);
00117
00118 GetClientRect(r);
00119 r.SetRect(6, r.top+4, 22, r.bottom-4);
00120 m_type.MoveWindow(r);
00121
00122 Invalidate();
00123 }
00124
00125 void CPlayerStatusBar::Clear()
00126 {
00127 m_status.SetWindowText(_T(""));
00128 m_time.SetWindowText(_T(""));
00129 SetStatusBitmap(0);
00130 SetStatusTypeIcon(0);
00131
00132 Relayout();
00133 }
00134
00135 void CPlayerStatusBar::SetStatusBitmap(UINT id)
00136 {
00137 if(m_bmid == id) return;
00138
00139 if(m_bm.m_hObject) m_bm.DeleteObject();
00140 if(id) m_bm.LoadBitmap(id);
00141 m_bmid = id;
00142
00143 Relayout();
00144 }
00145
00146 void CPlayerStatusBar::SetStatusTypeIcon(HICON hIcon)
00147 {
00148 if(m_hIcon == hIcon) return;
00149
00150 if(m_hIcon) DestroyIcon(m_hIcon);
00151 m_type.SetIcon(m_hIcon = hIcon);
00152
00153 Relayout();
00154 }
00155
00156 void CPlayerStatusBar::SetStatusMessage(CString str)
00157 {
00158 str.Trim();
00159 m_status.SetWindowText(str);
00160 }
00161
00162 void CPlayerStatusBar::SetStatusTimer(CString str)
00163 {
00164 CString tmp;
00165 m_time.GetWindowText(tmp);
00166 if(tmp == str) return;
00167
00168 str.Trim();
00169 m_time.SetWindowText(str);
00170
00171 Relayout();
00172 }
00173
00174 void CPlayerStatusBar::SetStatusTimer(REFERENCE_TIME rtNow, REFERENCE_TIME rtDur, bool fHighPrecision, const GUID* pTimeFormat)
00175 {
00176 ASSERT(pTimeFormat);
00177
00178 CString str;
00179 CString posstr, durstr;
00180
00181 if(*pTimeFormat == TIME_FORMAT_MEDIA_TIME)
00182 {
00183 DVD_HMSF_TIMECODE tcNow = RT2HMSF(rtNow);
00184 DVD_HMSF_TIMECODE tcDur = RT2HMSF(rtDur);
00185
00186 if(tcDur.bHours > 0 || (rtNow >= rtDur && tcNow.bHours > 0))
00187 posstr.Format(_T("%02d:%02d:%02d"), tcNow.bHours, tcNow.bMinutes, tcNow.bSeconds);
00188 else
00189 posstr.Format(_T("%02d:%02d"), tcNow.bMinutes, tcNow.bSeconds);
00190
00191 if(tcDur.bHours > 0)
00192 durstr.Format(_T("%02d:%02d:%02d"), tcDur.bHours, tcDur.bMinutes, tcDur.bSeconds);
00193 else
00194 durstr.Format(_T("%02d:%02d"), tcDur.bMinutes, tcDur.bSeconds);
00195
00196 if(fHighPrecision)
00197 {
00198 str.Format(_T("%s.%03d"), posstr, (rtNow/10000)%1000);
00199 posstr = str;
00200 str.Format(_T("%s.%03d"), durstr, (rtDur/10000)%1000);
00201 durstr = str;
00202 str.Empty();
00203 }
00204 }
00205 else if(*pTimeFormat == TIME_FORMAT_FRAME)
00206 {
00207 posstr.Format(_T("%I64d"), rtNow);
00208 durstr.Format(_T("%I64d"), rtDur);
00209 }
00210
00211 str = ( rtDur <= 0) ? posstr : posstr + _T(" / ") + durstr;
00212
00213 SetStatusTimer(str);
00214 }
00215
00216 void CPlayerStatusBar::ShowTimer(bool fShow)
00217 {
00218 m_time.ShowWindow(fShow ? SW_SHOW : SW_HIDE);
00219
00220 Relayout();
00221 }
00222
00223 BEGIN_MESSAGE_MAP(CPlayerStatusBar, CDialogBar)
00224 ON_WM_ERASEBKGND()
00225 ON_WM_PAINT()
00226 ON_WM_SIZE()
00227 ON_WM_CREATE()
00228 ON_WM_LBUTTONDOWN()
00229 ON_WM_SETCURSOR()
00230 ON_WM_CTLCOLOR()
00231 END_MESSAGE_MAP()
00232
00233
00234
00235
00236
00237 BOOL CPlayerStatusBar::OnEraseBkgnd(CDC* pDC)
00238 {
00239 for(CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetNextWindow())
00240 {
00241 if(!pChild->IsWindowVisible()) continue;
00242
00243 CRect r;
00244 pChild->GetClientRect(&r);
00245 pChild->MapWindowPoints(this, &r);
00246 pDC->ExcludeClipRect(&r);
00247 }
00248
00249 CRect r;
00250 GetClientRect(&r);
00251
00252 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
00253
00254 if(pFrame->m_pLastBar != this || pFrame->m_fFullScreen)
00255 r.InflateRect(0, 0, 0, 1);
00256
00257 if(pFrame->m_fFullScreen)
00258 r.InflateRect(1, 0, 1, 0);
00259
00260 pDC->Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
00261
00262 r.DeflateRect(1, 1);
00263
00264 pDC->FillSolidRect(&r, 0);
00265
00266 return TRUE;
00267 }
00268
00269 void CPlayerStatusBar::OnPaint()
00270 {
00271 CPaintDC dc(this);
00272
00273 CRect r;
00274
00275 if(m_bm.m_hObject)
00276 {
00277 BITMAP bm;
00278 m_bm.GetBitmap(&bm);
00279 CDC memdc;
00280 memdc.CreateCompatibleDC(&dc);
00281 memdc.SelectObject(&m_bm);
00282 GetClientRect(&r);
00283 dc.BitBlt(r.right-bm.bmWidth-1, (r.Height() - bm.bmHeight)/2, bm.bmWidth, bm.bmHeight, &memdc, 0, 0, SRCCOPY);
00284
00285
00286 }
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 }
00297
00298 void CPlayerStatusBar::OnSize(UINT nType, int cx, int cy)
00299 {
00300 CDialogBar::OnSize(nType, cx, cy);
00301
00302 Relayout();
00303 }
00304
00305 void CPlayerStatusBar::OnLButtonDown(UINT nFlags, CPoint point)
00306 {
00307 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
00308
00309 WINDOWPLACEMENT wp;
00310 wp.length = sizeof(wp);
00311 pFrame->GetWindowPlacement(&wp);
00312
00313 if(!pFrame->m_fFullScreen && wp.showCmd != SW_SHOWMAXIMIZED)
00314 {
00315 CRect r;
00316 GetClientRect(r);
00317 CPoint p = point;
00318
00319 MapWindowPoints(pFrame, &point, 1);
00320 pFrame->PostMessage(WM_NCLBUTTONDOWN,
00321
00322 (p.x >= r.Width()-r.Height()) ? HTBOTTOMRIGHT :
00323 HTCAPTION,
00324 MAKELPARAM(point.x, point.y));
00325 }
00326 }
00327
00328 BOOL CPlayerStatusBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00329 {
00330 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
00331
00332 WINDOWPLACEMENT wp;
00333 wp.length = sizeof(wp);
00334 pFrame->GetWindowPlacement(&wp);
00335
00336 if(!pFrame->m_fFullScreen && wp.showCmd != SW_SHOWMAXIMIZED)
00337 {
00338 CRect r;
00339 GetClientRect(r);
00340 CPoint p;
00341 GetCursorPos(&p);
00342 ScreenToClient(&p);
00343
00344 if(p.x >= r.Width()-r.Height())
00345 {
00346 SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
00347 return TRUE;
00348 }
00349 }
00350
00351 return CDialogBar::OnSetCursor(pWnd, nHitTest, message);
00352 }
00353
00354 HBRUSH CPlayerStatusBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00355 {
00356 HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
00357
00358 if(*pWnd == m_type)
00359 {
00360 hbr = GetStockBrush(BLACK_BRUSH);
00361 }
00362
00363
00364 return hbr;
00365 }