2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // PlayerStatusBar.cpp : implementation file
27 #include "PlayerStatusBar.h"
29 #include "..\..\DSUtil\DSUtil.h"
33 IMPLEMENT_DYNAMIC(CPlayerStatusBar
, CDialogBar
)
35 CPlayerStatusBar::CPlayerStatusBar()
36 : m_status(false, false)
43 CPlayerStatusBar::~CPlayerStatusBar()
45 if(m_hIcon
) DestroyIcon(m_hIcon
);
48 BOOL
CPlayerStatusBar::Create(CWnd
* pParentWnd
)
50 return CDialogBar::Create(pParentWnd
, IDD_PLAYERSTATUSBAR
, WS_CHILD
|WS_VISIBLE
|CBRS_ALIGN_BOTTOM
, IDD_PLAYERSTATUSBAR
);
53 BOOL
CPlayerStatusBar::PreCreateWindow(CREATESTRUCT
& cs
)
55 if(!CDialogBar::PreCreateWindow(cs
))
58 m_dwStyle
&= ~CBRS_BORDER_TOP
;
59 m_dwStyle
&= ~CBRS_BORDER_BOTTOM
;
64 int CPlayerStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct
)
66 if(CDialogBar::OnCreate(lpCreateStruct
) == -1)
72 m_type
.Create(_T(""), WS_CHILD
|WS_VISIBLE
|SS_ICON
,
73 r
, this, IDC_STATIC1
);
75 m_status
.Create(_T(""), WS_CHILD
|WS_VISIBLE
|SS_OWNERDRAW
,
76 r
, this, IDC_PLAYERSTATUS
);
78 m_time
.Create(_T(""), WS_CHILD
|WS_VISIBLE
|SS_OWNERDRAW
,
79 r
, this, IDC_PLAYERTIME
);
81 m_status
.SetWindowPos(&m_time
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
88 void CPlayerStatusBar::Relayout()
91 memset(&bm
, 0, sizeof(bm
));
92 if(m_bm
.m_hObject
) m_bm
.GetBitmap(&bm
);
97 r
.DeflateRect(27, 5, bm
.bmWidth
+ 8, 4);
98 int div
= r
.right
- (m_time
.IsWindowVisible() ? 140 : 0);
101 m_time
.GetWindowText(str
);
102 if(CDC
* pDC
= m_time
.GetDC())
104 CFont
* pOld
= pDC
->SelectObject(&m_time
.GetFont());
105 div
= r
.right
- pDC
->GetTextExtent(str
).cx
;
106 pDC
->SelectObject(pOld
);
107 m_time
.ReleaseDC(pDC
);
112 m_status
.MoveWindow(&r2
);
116 m_time
.MoveWindow(&r2
);
119 r
.SetRect(6, r
.top
+4, 22, r
.bottom
-4);
120 m_type
.MoveWindow(r
);
125 void CPlayerStatusBar::Clear()
127 m_status
.SetWindowText(_T(""));
128 m_time
.SetWindowText(_T(""));
130 SetStatusTypeIcon(0);
135 void CPlayerStatusBar::SetStatusBitmap(UINT id
)
137 if(m_bmid
== id
) return;
139 if(m_bm
.m_hObject
) m_bm
.DeleteObject();
140 if(id
) m_bm
.LoadBitmap(id
);
146 void CPlayerStatusBar::SetStatusTypeIcon(HICON hIcon
)
148 if(m_hIcon
== hIcon
) return;
150 if(m_hIcon
) DestroyIcon(m_hIcon
);
151 m_type
.SetIcon(m_hIcon
= hIcon
);
156 void CPlayerStatusBar::SetStatusMessage(CString str
)
159 m_status
.SetWindowText(str
);
162 void CPlayerStatusBar::SetStatusTimer(CString str
)
165 m_time
.GetWindowText(tmp
);
166 if(tmp
== str
) return;
169 m_time
.SetWindowText(str
);
174 void CPlayerStatusBar::SetStatusTimer(REFERENCE_TIME rtNow
, REFERENCE_TIME rtDur
, bool fHighPrecision
, const GUID
* pTimeFormat
)
179 CString posstr
, durstr
;
181 if(*pTimeFormat
== TIME_FORMAT_MEDIA_TIME
)
183 DVD_HMSF_TIMECODE tcNow
= RT2HMSF(rtNow
);
184 DVD_HMSF_TIMECODE tcDur
= RT2HMSF(rtDur
);
186 if(tcDur
.bHours
> 0 || (rtNow
>= rtDur
&& tcNow
.bHours
> 0))
187 posstr
.Format(_T("%02d:%02d:%02d"), tcNow
.bHours
, tcNow
.bMinutes
, tcNow
.bSeconds
);
189 posstr
.Format(_T("%02d:%02d"), tcNow
.bMinutes
, tcNow
.bSeconds
);
192 durstr
.Format(_T("%02d:%02d:%02d"), tcDur
.bHours
, tcDur
.bMinutes
, tcDur
.bSeconds
);
194 durstr
.Format(_T("%02d:%02d"), tcDur
.bMinutes
, tcDur
.bSeconds
);
198 str
.Format(_T("%s.%03d"), posstr
, (rtNow
/10000)%1000);
200 str
.Format(_T("%s.%03d"), durstr
, (rtDur
/10000)%1000);
205 else if(*pTimeFormat
== TIME_FORMAT_FRAME
)
207 posstr
.Format(_T("%I64d"), rtNow
);
208 durstr
.Format(_T("%I64d"), rtDur
);
211 str
= (/*start <= 0 &&*/ rtDur
<= 0) ? posstr
: posstr
+ _T(" / ") + durstr
;
216 void CPlayerStatusBar::ShowTimer(bool fShow
)
218 m_time
.ShowWindow(fShow
? SW_SHOW
: SW_HIDE
);
223 BEGIN_MESSAGE_MAP(CPlayerStatusBar
, CDialogBar
)
234 // CPlayerStatusBar message handlers
237 BOOL
CPlayerStatusBar::OnEraseBkgnd(CDC
* pDC
)
239 for(CWnd
* pChild
= GetWindow(GW_CHILD
); pChild
; pChild
= pChild
->GetNextWindow())
241 if(!pChild
->IsWindowVisible()) continue;
244 pChild
->GetClientRect(&r
);
245 pChild
->MapWindowPoints(this, &r
);
246 pDC
->ExcludeClipRect(&r
);
252 CMainFrame
* pFrame
= ((CMainFrame
*)GetParentFrame());
254 if(pFrame
->m_pLastBar
!= this || pFrame
->m_fFullScreen
)
255 r
.InflateRect(0, 0, 0, 1);
257 if(pFrame
->m_fFullScreen
)
258 r
.InflateRect(1, 0, 1, 0);
260 pDC
->Draw3dRect(&r
, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
264 pDC
->FillSolidRect(&r
, 0);
269 void CPlayerStatusBar::OnPaint()
271 CPaintDC
dc(this); // device context for painting
280 memdc
.CreateCompatibleDC(&dc
);
281 memdc
.SelectObject(&m_bm
);
283 dc
.BitBlt(r
.right
-bm
.bmWidth
-1, (r
.Height() - bm
.bmHeight
)/2, bm
.bmWidth
, bm
.bmHeight
, &memdc
, 0, 0, SRCCOPY
);
291 r.SetRect(6, r.top+4, 22-1, r.bottom-4-1);
292 DrawIconEx(dc, r.left, r.top, m_hIcon, r.Width(), r.Height(), 0, NULL, DI_NORMAL|DI_COMPAT);
295 // Do not call CDialogBar::OnPaint() for painting messages
298 void CPlayerStatusBar::OnSize(UINT nType
, int cx
, int cy
)
300 CDialogBar::OnSize(nType
, cx
, cy
);
305 void CPlayerStatusBar::OnLButtonDown(UINT nFlags
, CPoint point
)
307 CMainFrame
* pFrame
= ((CMainFrame
*)GetParentFrame());
310 wp
.length
= sizeof(wp
);
311 pFrame
->GetWindowPlacement(&wp
);
313 if(!pFrame
->m_fFullScreen
&& wp
.showCmd
!= SW_SHOWMAXIMIZED
)
319 MapWindowPoints(pFrame
, &point
, 1);
320 pFrame
->PostMessage(WM_NCLBUTTONDOWN
,
321 // (p.x+p.y >= r.Width()) ? HTBOTTOMRIGHT : HTCAPTION,
322 (p
.x
>= r
.Width()-r
.Height()) ? HTBOTTOMRIGHT
:
324 MAKELPARAM(point
.x
, point
.y
));
328 BOOL
CPlayerStatusBar::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
330 CMainFrame
* pFrame
= ((CMainFrame
*)GetParentFrame());
333 wp
.length
= sizeof(wp
);
334 pFrame
->GetWindowPlacement(&wp
);
336 if(!pFrame
->m_fFullScreen
&& wp
.showCmd
!= SW_SHOWMAXIMIZED
)
343 // if(p.x+p.y >= r.Width())
344 if(p
.x
>= r
.Width()-r
.Height())
346 SetCursor(LoadCursor(NULL
, IDC_SIZENWSE
));
351 return CDialogBar::OnSetCursor(pWnd
, nHitTest
, message
);
354 HBRUSH
CPlayerStatusBar::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
356 HBRUSH hbr
= CDialogBar::OnCtlColor(pDC
, pWnd
, nCtlColor
);
360 hbr
= GetStockBrush(BLACK_BRUSH
);
363 // TODO: Return a different brush if the default is not desired