/******************************************************************
News Everywhere 1.0
Copyright (c) 2004 by ����
All rights reserved.
This file is part of NewsEverywhere.
NewsEverywhere is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
NewsEverywhere is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NewsEverywhere; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For any suggestion or failure report, please contact me by:
e-mail: jonathan1983@126.com
////////////////////////////////////////////////////////////////////////////////
File Name:NewsBar.cpp
********************************************************************/
#include "stdafx.h"
#include "NewsEverywhereMFC.h"
#include "NewsBar.h"
#include "helper.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNewsBar
CNewsBar::CNewsBar()
{
m_pTitle=NULL;
m_nTitle=-1;
m_nTitleCurPlay=-1;
LOGFONT font;
ZeroMemory(&font,sizeof(LOGFONT));
font.lfHeight=12;
font.lfWidth=0;
font.lfWeight=FW_THIN;
font.lfCharSet=GB2312_CHARSET;
_tcscpy(font.lfFaceName,"����");
m_font.CreateFontIndirect(&font);
m_brush.Attach((HBRUSH)GetStockObject(BLACK_BRUSH));
m_pen.Attach((HPEN)GetStockObject(WHITE_PEN));
HINSTANCE hInst=AfxGetInstanceHandle();
m_hIconTR=(HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_TITLE_ROLL),IMAGE_ICON,16,16,0);
m_hIconTS=(HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_TITLE_STOP),IMAGE_ICON,16,16,0);
m_hIconCOn=(HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_CONTENT_ON),IMAGE_ICON,16,16,0);
m_hIconCOff=(HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_CONTENT_OFF),IMAGE_ICON,16,16,0);
m_hIconLeft=(HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_LEFT),IMAGE_ICON,16,16,0);
m_hIconRight=(HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_RIGHT),IMAGE_ICON,16,16,0);
m_bBackground=FALSE;
m_bTitle=FALSE;
m_bContent=FALSE;
m_psText="";
m_hTitle=m_hContent=m_hEarcon=NULL;
}
CNewsBar::~CNewsBar()
{
}
BEGIN_MESSAGE_MAP(CNewsBar, CWnd)
//{{AFX_MSG_MAP(CNewsBar)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_PAINT()
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewsBar message handlers
void CNewsBar::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rc;
rc=CRect(2,2,30,18);
if(PtInRect(rc,point))
{
SetCapture();
HDC hDC=::GetDC(NULL);
CDC dc;
dc.Attach(hDC);
m_ptFrom=point;
GetWindowRect(m_rcFrom);
m_rcPrev=m_rcFrom;
dc.DrawFocusRect(&m_rcFrom);
CWnd::OnLButtonDown(nFlags, point);
dc.Detach();
::ReleaseDC(NULL,hDC);
}
CWnd::OnLButtonDown(nFlags, point);
}
void CNewsBar::OnLButtonUp(UINT nFlags, CPoint point)
{
if(GetCapture())
{
ReleaseCapture();
HDC hDC=::GetDC(NULL);
CDC dc;
dc.Attach(hDC);
dc.DrawFocusRect(&m_rcPrev);
MoveWindow(m_rcPrev);
}
CWnd::OnLButtonUp(nFlags, point);
}
void CNewsBar::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rc;
HCURSOR hCursor;
if(GetCapture())
{
HDC hDC=::GetDC(NULL);
CDC dc;
dc.Attach(hDC);
dc.DrawFocusRect(&m_rcPrev);
m_rcPrev=m_rcFrom+(point-m_ptFrom);
dc.DrawFocusRect(&m_rcPrev);
dc.Detach();
::ReleaseDC(NULL,hDC);
}
else
{
rc=CRect(2,2,30,18);
if(PtInRect(rc,point))
hCursor=LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR_MOVE));
else
hCursor=LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR_POINTER));
SetCursor(hCursor);
}
CWnd::OnMouseMove(nFlags, point);
}
void CNewsBar::SetBGMode(BOOL bSet)
{
CDC* pDC=GetDC();
COLORREF white=RGB(255,255,255);
pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(m_brush);
pDC->SelectObject(m_font);
pDC->SetTextColor(white);
CRect rcFrame(2,2,30,18);
pDC->Rectangle(rcFrame);
pDC->FrameRect(&rcFrame,&m_brush);
if(bSet)
pDC->DrawText("��̨",4,&rcFrame,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
else
pDC->DrawText("ǰ̨",4,&rcFrame,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
m_bBackground=bSet;
}
void CNewsBar::OnRButtonDown(UINT nFlags, CPoint point)
{
ClientToScreen(&point);
CMenu m_pop;
m_pop.CreatePopupMenu();
if(m_nTitle==-1)
{
m_pop.InsertMenu(0,MF_STRING,TITLE_0-1,IDS_NO_ITEM);
}
else
{
m_pop.InsertMenu(0, MF_STRING, ID_GOTO_CURTITLE, "��ǰ����");
m_pop.InsertMenu(0, MF_STRING, ID_GOTO_CURCONTENT, "��ǰ����");
}
m_pop.InsertMenu(0, MF_SEPARATOR, ID_GOTO_CURTITLE, "");
TCHAR psText[100]="";
for(int i=0;i<m_nTitle;i++)
{
*psText='\0';
if(i==m_nTitleCurPlay)
_tcscpy(psText,"-->");
_tcscat(psText,m_pTitle[i].psTitle);
m_pop.InsertMenu(0,MF_STRING,TITLE_0+i,psText);
}
m_pop.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,GetParent(),NULL);
CWnd::OnRButtonDown(nFlags, point);
}
void CNewsBar::SetTitleMode(BOOL bRoll)
{
CDC* pDC=GetDC();
pDC->SelectObject(m_brush);
CRect rc(32,2,50,HEIGHT_NEWSBAR);
pDC->Rectangle(rc);
if(bRoll)
DrawIconEx(pDC->GetSafeHdc(),32,2,m_hIconTR,16,16,0,NULL,DI_NORMAL);
else
DrawIconEx(pDC->GetSafeHdc(),32,2,m_hIconTS,16,16,0,NULL,DI_NORMAL);
m_bTitle=bRoll;
}
void CNewsBar::SetContentMode(BOOL bOn)
{
CDC* pDC=GetDC();
pDC->SelectObject(m_brush);
CRect rc(50,2,66,HEIGHT_NEWSBAR);
pDC->Rectangle(rc);
if(bOn)
DrawIconEx(pDC->GetSafeHdc(),50,2,m_hIconCOn,16,16,0,NULL,DI_NORMAL);
else
DrawIconEx(pDC->GetSafeHdc(),50,2,m_hIconCOff,16,16,0,NULL,DI_NORMAL);
m_bContent=bOn;
}
void CNewsBar::SetTitleText(PCTSTR psTitle)
{
CDC* pDC=GetDC();
COLORREF white=RGB(255,255,255);
pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(m_brush);
pDC->SelectObject(m_font);
pDC->SetTextColor(white);
CString str=psTitle;
CRect rc(90,0,WIDTH_NEWSBAR-20,HEIGHT_NEWSBAR);
pDC->Rectangle(rc);
pDC->DrawText(str,&rc,DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_END_ELLIPSIS);
}
void CNewsBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
SetBGMode(m_bBackground);
SetTitleMode(m_bTitle);
SetContentMode(m_bContent);
// Draw Icon
dc.SelectObject(m_brush);
// Left arrow
CRect rc(70,2,86,HEIGHT_NEWSBAR);
dc.Rectangle(rc);
DrawIconEx(dc.GetSafeHdc(),70,2,m_hIconLeft,16,16,0,NULL,DI_NORMAL);
// Right arrow
rc=CRect(430,2,446,HEIGHT_NEWSBAR);
dc.Rectangle(rc);
DrawIconEx(dc.GetSafeHdc(),430,2,m_hIconRight,16,16,0,NULL,DI_NORMAL);
SetTitleText(m_psText);
// Do not call CWnd::OnPaint() for painting messages
}
void CNewsBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CRect rc;
// Background mode
rc=CRect(2,2,30,18);
if(PtInRect(rc,point))
{
;
}
// Switch Title mode
rc=CRect(32,2,50,HEIGHT_NEWSBAR);
if(PtInRect(rc,point))
{
GetParent()->SendMessage(ID_SWITCH_TITLE);
}
// Switch content mode
rc=CRect(50,2,70,HEIGHT_NEWSBAR);
if(PtInRect(rc,point))
{
GetParent()->SendMessage(ID_SWITCH_CONTENT);
}
// Title down
rc=CRect(70, 2, 90 , HEIGHT_NEWSBAR);
if(PtInRect(rc,point))
{
GetParent()->SendMessage(ID_TITLE_DOWN);
}
// Play current title
rc=CRect(90,2,WIDTH_NEWSBAR-20,HEIGHT_NEWSBAR);
if(PtInRect(rc,point))
{
GetParent()->SendMessage(ID_PLAY_CURTITLE);
}
// Title up
rc=CRect(WIDTH_NEWSBAR-20, 2, WIDTH_NEWSBAR , HEIGHT_NEWSBAR);
if(PtInRect(rc,point))
{
GetParent()->SendMessage(ID_TITLE_UP);
}
CWnd::OnLButtonDblClk(nFlags, point);
}