A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / PlayerInfoBar.cpp
blobe1e47ec962a2c734c4e5d32b1740a7a3aca3e13f
1 /*
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)
8 * any later version.
9 *
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 // PlayerInfoBar.cpp : implementation file
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "PlayerInfoBar.h"
28 #include "MainFrm.h"
31 // CPlayerInfoBar
33 IMPLEMENT_DYNAMIC(CPlayerInfoBar, CDialogBar)
34 CPlayerInfoBar::CPlayerInfoBar(int nFirstColWidth) : m_nFirstColWidth(nFirstColWidth)
38 CPlayerInfoBar::~CPlayerInfoBar()
42 void CPlayerInfoBar::SetLine(CString label, CString info)
44 if(info.IsEmpty())
46 RemoveLine(label);
47 return;
50 for(size_t idx = 0; idx < m_label.GetCount(); idx++)
52 CString tmp;
53 m_label[idx]->GetWindowText(tmp);
54 if(label == tmp)
56 m_info[idx]->GetWindowText(tmp);
57 if(info != tmp) m_info[idx]->SetWindowText(info);
58 return;
62 CAutoPtr<CStatusLabel> l(new CStatusLabel(true, false));
63 l->Create(label, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|SS_OWNERDRAW, CRect(0,0,0,0), this);
64 m_label.Add(l);
66 CAutoPtr<CStatusLabel> i(new CStatusLabel(false, true));
67 i->Create(info, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|SS_OWNERDRAW, CRect(0,0,0,0), this);
68 m_info.Add(i);
70 Relayout();
73 void CPlayerInfoBar::GetLine(CString label, CString& info)
75 info.Empty();
77 for(size_t idx = 0; idx < m_label.GetCount(); idx++)
79 CString tmp;
80 m_label[idx]->GetWindowText(tmp);
81 if(label == tmp)
83 m_info[idx]->GetWindowText(tmp);
84 info = tmp;
85 return;
90 void CPlayerInfoBar::RemoveLine(CString label)
92 for(size_t i = 0; i < m_label.GetCount(); i++)
94 CString tmp;
95 m_label[i]->GetWindowText(tmp);
96 if(label == tmp)
98 m_label.RemoveAt(i);
99 m_info.RemoveAt(i);
100 break;
104 Relayout();
107 void CPlayerInfoBar::RemoveAllLines()
109 m_label.RemoveAll();
110 m_info.RemoveAll();
112 Relayout();
115 BOOL CPlayerInfoBar::Create(CWnd* pParentWnd)
117 return CDialogBar::Create(pParentWnd, IDD_PLAYERINFOBAR, WS_CHILD|WS_VISIBLE|CBRS_ALIGN_BOTTOM, IDD_PLAYERINFOBAR);
120 BOOL CPlayerInfoBar::PreCreateWindow(CREATESTRUCT& cs)
122 if(!CDialogBar::PreCreateWindow(cs))
123 return FALSE;
125 m_dwStyle &= ~CBRS_BORDER_TOP;
126 m_dwStyle &= ~CBRS_BORDER_BOTTOM;
128 return TRUE;
131 CSize CPlayerInfoBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
133 CRect r;
134 GetParent()->GetClientRect(&r);
135 r.bottom = r.top + m_label.GetCount() * 17 + (m_label.GetCount() ? 4 : 0);
136 return r.Size();
139 void CPlayerInfoBar::Relayout()
141 CRect r;
142 GetParent()->GetClientRect(&r);
144 int w = m_nFirstColWidth, h = 17, y = 2;
146 for(size_t i = 0; i < m_label.GetCount(); i++)
148 CDC* pDC = m_label[i]->GetDC();
149 CString str;
150 m_label[i]->GetWindowText(str);
151 w = max(w, pDC->GetTextExtent(str).cx);
152 m_label[i]->ReleaseDC(pDC);
155 for(size_t i = 0; i < m_label.GetCount(); i++, y += h)
157 m_label[i]->MoveWindow(1, y, w - 10, h);
158 m_info[i]->MoveWindow(w + 10, y, r.Width()-(w+10)-1, h);
162 BEGIN_MESSAGE_MAP(CPlayerInfoBar, CDialogBar)
163 ON_WM_ERASEBKGND()
164 ON_WM_SIZE()
165 ON_WM_LBUTTONDOWN()
166 END_MESSAGE_MAP()
170 // CPlayerInfoBar message handlers
172 BOOL CPlayerInfoBar::OnEraseBkgnd(CDC* pDC)
174 for(CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetNextWindow())
176 CRect r;
177 pChild->GetClientRect(&r);
178 pChild->MapWindowPoints(this, &r);
179 pDC->ExcludeClipRect(&r);
182 CRect r;
183 GetClientRect(&r);
185 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
187 if(pFrame->m_pLastBar != this || pFrame->m_fFullScreen)
188 r.InflateRect(0, 0, 0, 1);
190 if(pFrame->m_fFullScreen)
191 r.InflateRect(1, 0, 1, 0);
193 pDC->Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
195 r.DeflateRect(1, 1);
197 pDC->FillSolidRect(&r, 0);
199 return TRUE;
202 void CPlayerInfoBar::OnSize(UINT nType, int cx, int cy)
204 CDialogBar::OnSize(nType, cx, cy);
206 Relayout();
208 Invalidate();
211 void CPlayerInfoBar::OnLButtonDown(UINT nFlags, CPoint point)
213 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
214 if(!pFrame->m_fFullScreen)
216 MapWindowPoints(pFrame, &point, 1);
217 pFrame->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));