- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# StatusLabel.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 // StatusLabel.cpp : implementation file
    00023 //
    00024
    00025 #include "stdafx.h"
    00026 #include "mplayerc.h"
    00027 #include "StatusLabel.h"
    00028
    00029
    00030 // CStatusLabel
    00031
    00032 IMPLEMENT_DYNAMIC(CStatusLabel, CStatic)
    00033 CStatusLabel::CStatusLabel(bool fRightAlign, bool fAddEllipses)
    00034         : m_fRightAlign(fRightAlign)
    00035         , m_fAddEllipses(fAddEllipses)
    00036 {
    00037         HDC hdc = ::GetDC(NULL);
    00038         double scale = 1.0*GetDeviceCaps(hdc, LOGPIXELSY) / 96.0;
    00039         ::ReleaseDC(0, hdc);
    00040
    00041         m_font.CreateFont(int(14.0 * scale), 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
    00042                 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,
    00043                 _T("Microsoft Sans Serif"));
    00044         if(!m_font.m_hObject)
    00045         m_font.CreateFont(int(14.0 * scale), 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
    00046                 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,
    00047                 _T("MS Sans Serif"));
    00048 }
    00049
    00050 CStatusLabel::~CStatusLabel()
    00051 {
    00052 }
    00053
    00054 BEGIN_MESSAGE_MAP(CStatusLabel, CStatic)
    00055         ON_WM_ERASEBKGND()
    00056 END_MESSAGE_MAP()
    00057
    00058 // CStatusLabel message handlers
    00059
    00060 void CStatusLabel::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    00061 {
    00062         CDC dc;
    00063         dc.Attach(lpDrawItemStruct->hDC);
    00064                 CString str;
    00065                 GetWindowText(str);
    00066                 CRect r;
    00067                 GetClientRect(&r);
    00068                 CFont* old = dc.SelectObject(&m_font);
    00069                 dc.SetTextColor(0xffffff);
    00070                 dc.SetBkColor(0);
    00071                 CSize size = dc.GetTextExtent(str);
    00072                 CPoint p = CPoint(m_fRightAlign ? r.Width() - size.cx : 0, (r.Height()-size.cy)/2);
    00073
    00074                 if(m_fAddEllipses)
    00075                 while(size.cx > r.Width()-3 && str.GetLength() > 3)
    00076                 {
    00077                         str = str.Left(str.GetLength()-4) + _T("...");
    00078                         size = dc.GetTextExtent(str);
    00079                 }
    00080
    00081                 dc.TextOut(p.x, p.y, str);
    00082                 dc.ExcludeClipRect(CRect(p, size));
    00083                 dc.SelectObject(&old);
    00084                 dc.FillSolidRect(&r, 0);
    00085         dc.Detach();
    00086 }
    00087
    00088 BOOL CStatusLabel::OnEraseBkgnd(CDC* pDC)
    00089 {
    00090         CRect r;
    00091         GetClientRect(&r);
    00092         pDC->FillSolidRect(&r, 0);
    00093         return TRUE;
    00094 }
    00095