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 // StatusLabel.cpp : implementation file
27 #include "StatusLabel.h"
32 IMPLEMENT_DYNAMIC(CStatusLabel
, CStatic
)
33 CStatusLabel::CStatusLabel(bool fRightAlign
, bool fAddEllipses
)
34 : m_fRightAlign(fRightAlign
)
35 , m_fAddEllipses(fAddEllipses
)
37 HDC hdc
= ::GetDC(NULL
);
38 double scale
= 1.0*GetDeviceCaps(hdc
, LOGPIXELSY
) / 96.0;
41 m_font
.m_hObject
= NULL
;
43 if(!(::GetVersion()&0x80000000))
44 m_font
.CreateFont(int(14.0 * scale
), 0, 0, 0, FW_NORMAL
, 0, 0, 0, DEFAULT_CHARSET
,
45 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|FF_DONTCARE
,
46 _T("Microsoft Sans Serif"));
48 m_font
.CreateFont(int(14.0 * scale
), 0, 0, 0, FW_NORMAL
, 0, 0, 0, DEFAULT_CHARSET
,
49 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|FF_DONTCARE
,
53 CStatusLabel::~CStatusLabel()
57 BEGIN_MESSAGE_MAP(CStatusLabel
, CStatic
)
61 // CStatusLabel message handlers
63 void CStatusLabel::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct
)
66 dc
.Attach(lpDrawItemStruct
->hDC
);
71 CFont
* old
= dc
.SelectObject(&m_font
);
72 dc
.SetTextColor(0xffffff);
74 CSize size
= dc
.GetTextExtent(str
);
75 CPoint p
= CPoint(m_fRightAlign
? r
.Width() - size
.cx
: 0, (r
.Height()-size
.cy
)/2);
78 while(size
.cx
> r
.Width()-3 && str
.GetLength() > 3)
80 str
= str
.Left(str
.GetLength()-4) + _T("...");
81 size
= dc
.GetTextExtent(str
);
84 dc
.TextOut(p
.x
, p
.y
, str
);
85 dc
.ExcludeClipRect(CRect(p
, size
));
86 dc
.SelectObject(&old
);
87 dc
.FillSolidRect(&r
, 0);
91 BOOL
CStatusLabel::OnEraseBkgnd(CDC
* pDC
)
95 pDC
->FillSolidRect(&r
, 0);