PlayerInfoBar.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // PlayerInfoBar.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PlayerInfoBar.h"
00028 #include "MainFrm.h"
00029 
00030 
00031 // CPlayerInfoBar
00032 
00033 IMPLEMENT_DYNAMIC(CPlayerInfoBar, CDialogBar)
00034 CPlayerInfoBar::CPlayerInfoBar(int nFirstColWidth) : m_nFirstColWidth(nFirstColWidth)
00035 {
00036 }
00037 
00038 CPlayerInfoBar::~CPlayerInfoBar()
00039 {
00040 }
00041 
00042 void CPlayerInfoBar::SetLine(CString label, CString info)
00043 {
00044         if(info.IsEmpty()) 
00045         {
00046                 RemoveLine(label);
00047                 return;
00048         }
00049 
00050         for(size_t idx = 0; idx < m_label.GetCount(); idx++)
00051         {
00052                 CString tmp;
00053                 m_label[idx]->GetWindowText(tmp);
00054                 if(label == tmp)
00055                 {
00056                         m_info[idx]->GetWindowText(tmp);
00057                         if(info != tmp) m_info[idx]->SetWindowText(info);
00058                         return;
00059                 }
00060         }
00061 
00062         CAutoPtr<CStatusLabel> l(new CStatusLabel(true, false));
00063         l->Create(label, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|SS_OWNERDRAW, CRect(0,0,0,0), this);
00064         m_label.Add(l);
00065 
00066         CAutoPtr<CStatusLabel> i(new CStatusLabel(false, true));
00067         i->Create(info, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|SS_OWNERDRAW, CRect(0,0,0,0), this);
00068         m_info.Add(i);
00069 
00070         Relayout();
00071 }
00072 
00073 void CPlayerInfoBar::GetLine(CString label, CString& info)
00074 {
00075         info.Empty();
00076 
00077         for(size_t idx = 0; idx < m_label.GetCount(); idx++)
00078         {
00079                 CString tmp;
00080                 m_label[idx]->GetWindowText(tmp);
00081                 if(label == tmp)
00082                 {
00083                         m_info[idx]->GetWindowText(tmp);
00084                         info = tmp;
00085                         return;
00086                 }
00087         }
00088 }
00089 
00090 void CPlayerInfoBar::RemoveLine(CString label)
00091 {
00092         for(size_t i = 0; i < m_label.GetCount(); i++)
00093         {
00094                 CString tmp;
00095                 m_label[i]->GetWindowText(tmp);
00096                 if(label == tmp)
00097                 {
00098                         m_label.RemoveAt(i);
00099                         m_info.RemoveAt(i);
00100                         break;
00101                 }
00102         }
00103 
00104         Relayout();
00105 }
00106 
00107 void CPlayerInfoBar::RemoveAllLines()
00108 {
00109         m_label.RemoveAll();
00110         m_info.RemoveAll();
00111 
00112         Relayout();
00113 }
00114 
00115 BOOL CPlayerInfoBar::Create(CWnd* pParentWnd)
00116 {
00117         return CDialogBar::Create(pParentWnd, IDD_PLAYERINFOBAR, WS_CHILD|WS_VISIBLE|CBRS_ALIGN_BOTTOM, IDD_PLAYERINFOBAR);
00118 }
00119 
00120 BOOL CPlayerInfoBar::PreCreateWindow(CREATESTRUCT& cs)
00121 {
00122         if(!CDialogBar::PreCreateWindow(cs))
00123                 return FALSE;
00124 
00125         m_dwStyle &= ~CBRS_BORDER_TOP;
00126         m_dwStyle &= ~CBRS_BORDER_BOTTOM;
00127 
00128         return TRUE;
00129 }
00130 
00131 CSize CPlayerInfoBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
00132 {
00133         CRect r;
00134         GetParent()->GetClientRect(&r);
00135         r.bottom = r.top + m_label.GetCount() * 17 + (m_label.GetCount() ? 4 : 0);
00136         return r.Size();
00137 }
00138 
00139 void CPlayerInfoBar::Relayout()
00140 {
00141         CRect r;
00142         GetParent()->GetClientRect(&r);
00143 
00144         int w = m_nFirstColWidth, h = 17, y = 2;
00145 
00146         for(size_t i = 0; i < m_label.GetCount(); i++)
00147         {
00148                 CDC* pDC = m_label[i]->GetDC();
00149                 CString str;
00150                 m_label[i]->GetWindowText(str);
00151                 w = max(w, pDC->GetTextExtent(str).cx);
00152                 m_label[i]->ReleaseDC(pDC);
00153         }
00154 
00155         for(size_t i = 0; i < m_label.GetCount(); i++, y += h)
00156         {
00157                 m_label[i]->MoveWindow(1, y, w - 10, h);
00158                 m_info[i]->MoveWindow(w + 10, y, r.Width()-(w+10)-1, h);
00159         }
00160 }
00161 
00162 BEGIN_MESSAGE_MAP(CPlayerInfoBar, CDialogBar)
00163         ON_WM_ERASEBKGND()
00164         ON_WM_SIZE()
00165         ON_WM_LBUTTONDOWN()
00166 END_MESSAGE_MAP()
00167 
00168 
00169 
00170 // CPlayerInfoBar message handlers
00171 
00172 BOOL CPlayerInfoBar::OnEraseBkgnd(CDC* pDC)
00173 {
00174         for(CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetNextWindow())
00175         {
00176                 CRect r;
00177                 pChild->GetClientRect(&r);
00178                 pChild->MapWindowPoints(this, &r);
00179                 pDC->ExcludeClipRect(&r);
00180         }
00181 
00182         CRect r;
00183         GetClientRect(&r);
00184 
00185         CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
00186         
00187         if(pFrame->m_pLastBar != this || pFrame->m_fFullScreen)
00188                 r.InflateRect(0, 0, 0, 1);
00189 
00190         if(pFrame->m_fFullScreen) 
00191                 r.InflateRect(1, 0, 1, 0);
00192 
00193         pDC->Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); 
00194 
00195         r.DeflateRect(1, 1);
00196 
00197         pDC->FillSolidRect(&r, 0);
00198 
00199         return TRUE;
00200 }
00201 
00202 void CPlayerInfoBar::OnSize(UINT nType, int cx, int cy)
00203 {
00204         CDialogBar::OnSize(nType, cx, cy);
00205 
00206         Relayout();
00207 
00208         Invalidate();
00209 }
00210 
00211 void CPlayerInfoBar::OnLButtonDown(UINT nFlags, CPoint point)
00212 {
00213         CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
00214         if(!pFrame->m_fFullScreen)
00215         {
00216                 MapWindowPoints(pFrame, &point, 1);
00217                 pFrame->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
00218         }
00219 }

Generated on Tue Dec 13 14:46:58 2005 for guliverkli by  doxygen 1.4.5