www.pudn.com > CirMMI.rar > CommunicateStatic.cpp
// CommunicateStatic.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "CommunicateStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCommunicateStatic
CCommunicateStatic::CCommunicateStatic()
{
m_hIconRevDownUp=AfxGetApp()->LoadIcon(IDI_ICON_RECV_UPDOWN);
m_hIconRevDown=AfxGetApp()->LoadIcon(IDI_ICON_RECV_DOWN);
m_hIconRevUp=AfxGetApp()->LoadIcon(IDI_ICON_RECV_UP);
m_hIconSend=AfxGetApp()->LoadIcon(IDI_ICON_SEND);
m_hIconZero=AfxGetApp()->LoadIcon(IDI_ICON_ZERO);
m_hIconSendZero=AfxGetApp()->LoadIcon(IDI_ICON_SEND_ZERO);
m_hIconSpeaker=AfxGetApp()->LoadIcon(IDI_ICON_SPEAKER);
m_hIconHandset=AfxGetApp()->LoadIcon(IDI_ICON_PHONE);
m_hIconUpLink=AfxGetApp()->LoadIcon(IDI_ICON_UPLINK);
m_hIconDownLink=AfxGetApp()->LoadIcon(IDI_ICON_DOWNLINK);
m_hIconTalk=AfxGetApp()->LoadIcon(IDI_ICON_MIC32);
m_hIconNoTalk=AfxGetApp()->LoadIcon(IDI_ICON_NOMIC32);
m_hIconTea=AfxGetApp()->LoadIcon(IDI_ICON_TEA32);
m_hIconBusy=AfxGetApp()->LoadIcon(IDI_ICON_BUSY32);
m_ftIndicationText.CreateFont
(12,0,
0,
0,
200,
0,
0,
0,
DEFAULT_CHARSET,
2,
3,
DEFAULT_QUALITY,
49,
_T("宋体"));
m_ftStateText.CreateFont
(16,0,
0,
0,
500,
0,
0,
0,
DEFAULT_CHARSET,
2,
3,
DEFAULT_QUALITY,
49,
_T("宋体")
);
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfOutPrecision= 3;
lf.lfClipPrecision= 2;
lf.lfQuality= 1;
lf.lfPitchAndFamily= 49;
lf.lfHeight= -12;//小四 -24:小二
lf.lfWidth=0;
lf.lfWeight= 200;
lf.lfCharSet= GB2312_CHARSET;
//lf.lfCharSet= DEFAULT_CHARSET;
wcscpy(lf.lfFaceName, _T("Courier New"));
m_ftCallList.m_hObject= ::CreateFontIndirect(&lf);
m_strText=_T("欢迎使用");
m_crText=g_CommonSet.crSecondText;
m_bLightSwitch=FALSE;
m_workmode=M_IDLE;
m_bShuanggong=FALSE;
m_buRevSignal=FALSE;
m_bdRevSignal=FALSE;
m_bSendSignal=FALSE;
m_ctBk=RGB(64,64,64*2);//RGB(64,64,64);
m_iCallDir=CALL_OUT;
m_crBorder=RGB(128,128,128);//g_CommonSet.crBorder;
m_iTalkState=-1;
m_iCallSel=0;
}
CCommunicateStatic::~CCommunicateStatic()
{
}
BEGIN_MESSAGE_MAP(CCommunicateStatic, CStatic)
//{{AFX_MSG_MAP(CCommunicateStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCommunicateStatic message handlers
void CCommunicateStatic::OnPaint()
{
// DWORD s=GetTickCount();
CPaintDC dc(this); // device context for painting
GetClientRect(m_Rect);
CDC memDC;
if(m_bitmap.m_hObject==NULL)
m_bitmap.CreateCompatibleBitmap(&dc,m_Rect.Width(),m_Rect.Height());
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&m_bitmap);
memDC.FillSolidRect(m_Rect,m_ctBk /*g_CommonSet.crMainBk*/);
//m_Rect.DeflateRect(1,1,1,1);
if(MODE_GSMR==g_CommonSet.iWorkMode)
{
GsmrDraw(&memDC);
}
else if(MODE_450M==g_CommonSet.iWorkMode)
{
M450Draw(&memDC);
}
else if(MODE_BOTH== g_CommonSet.iWorkMode)
{
if(g_CommonSet.iWitchUI==UI_GSMR)
{
GsmrDraw(&memDC);
}
else
{
M450Draw(&memDC);
}
}
dc.BitBlt(0,0,m_Rect.Width(),m_Rect.Height(),&memDC,0,0,SRCCOPY);
// CString str;
//str.Format(L"\r\n-----------------need time[%04d]--------------------------\r\n",GetTickCount()-s);
// TRACE(str);
}
void CCommunicateStatic::MySetText(const CString &strText,COLORREF cr, BOOL bFlash)
{
m_crText=cr;
m_strText=strText;
if(bFlash)
{
CDC *pDC=GetDC();
if(!pDC)
return;
if(MODE_GSMR==g_CommonSet.iWorkMode || (MODE_BOTH==g_CommonSet.iWorkMode && g_CommonSet.iWitchUI==UI_GSMR))
{
GsmrDraw(pDC);
}
else if(MODE_450M==g_CommonSet.iWorkMode || (MODE_BOTH==g_CommonSet.iWorkMode && g_CommonSet.iWitchUI==UI_450M))
{
INT index=pDC->SaveDC();
pDC->SetBkMode(TRANSPARENT);
CRect Canvas(m_M450TextCanvasRect);
Canvas.DeflateRect(1,1,1,1);
pDC->FillSolidRect(Canvas,g_CommonSet.crMainBk);
if(!m_strText.IsEmpty())
{
pDC->SelectObject(&m_ftStateText);
pDC->SetTextColor(m_crText);
int rows=::GetRows(m_strText);
if(rows>1) //暂不考虑2行以上的情况
{
CRect vrect[2];
vrect[0]=m_M450TextCanvasRect;
vrect[1]=m_M450TextCanvasRect;
vrect[0].DeflateRect(2,2,2,2);
vrect[1].DeflateRect(2,2,2,2);
vrect[0].bottom=m_M450TextCanvasRect.Height()/2;
vrect[1].top=vrect[0].bottom;
INT index=m_strText.Find('\r',0);
CString strUp,strDown;
strUp=m_strText.Left(index);
strDown=m_strText.Mid(index+2);
//pDC->SetTextColor(m_crText);
pDC->DrawText(strUp,vrect[0],DT_VCENTER|DT_SINGLELINE);
//pDC->SetTextColor(RGB(128,255,0));
pDC->SelectObject(&m_ftIndicationText);
pDC->DrawText(strDown,vrect[1],DT_VCENTER|DT_SINGLELINE);
}
else
pDC->DrawText(m_strText,m_M450TextCanvasRect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
pDC->RestoreDC(index);
}
}
}
void CCommunicateStatic::DrawTalkState(CDC *pDC)
{
/*
一字节:00H:上行链路空闲 01H:上行链路占用
02H:抢占成功 03H:抢占失败
*/
CRect r[2];
r[0]=m_GsmrIndicationRect;
r[1]=m_GsmrIndicationRect;
r[0].bottom=m_GsmrIndicationRect.top+m_GsmrIndicationRect.Height()/2;
r[1].top=r[0].bottom;
r[0].DeflateRect(1,1,1,1);
r[1].DeflateRect(1,1,1,1);
CString str;
// pDC->FillSolidRect(r[0],m_ctBk);
// pDC->FillSolidRect(r[1],m_ctBk);
CRect tmpr=m_GsmrIndicationRect;
tmpr.DeflateRect(1,1,1,1);
pDC->FillSolidRect(tmpr,m_ctBk);
pDC->SetTextColor(RGB(128,255,0));
switch(m_iTalkState)
{
case 0:
str=L"上行链路空闲";
pDC->DrawIcon(r[0].left,r[0].top,m_hIconTea);
break;
case 1:
str=L"上行链路忙";
pDC->SetTextColor(RGB(128,255,0));
pDC->DrawIcon(r[0].left,r[0].top,m_hIconBusy);
break;
case 2:
str=L"可以讲话";
pDC->DrawIcon(r[0].left,r[0].top,m_hIconTalk);
break;
case 3:
str=L"不可以讲话";
pDC->DrawIcon(r[0].left,r[0].top,m_hIconNoTalk);
pDC->SetTextColor(RGB(255,0,0));
break;
default:
str=L"";
}
pDC->DrawText(str,r[1],DT_SINGLELINE|DT_CENTER|DT_BOTTOM );
}
void CCommunicateStatic::DrawTalkList(CDC *pDC)
{
if(!IsWindowVisible())
return ;
const COLORREF crAct=RGB(128,255,0);
const COLORREF crnoAct=g_CommonSet.crSecondText;//RGB(192,192,192);
CRect listrt=m_GsmrTextCanvasRect;
listrt.DeflateRect(1,1,1,2);
listrt.top=listrt.Height()*2/3;
int callsize=m_CallAr.GetSize();
BOOL bSel=FALSE;
if(m_iCallSel>=0 && m_iCallSel1)
{
pDC->SelectObject(m_ftCallList);
CALL_INFO &refcall=m_CallAr.ElementAt(bSel ? m_iCallSel : 0);
pDC->SetTextColor(refcall.cbActive == 1 ? crAct :crnoAct);
CString str,strindex,strInfo;
strindex.Format(L"[%d/%d] ",bSel ? m_iCallSel+1 : 1,callsize);
str.Format(L"%s",refcall.cbActive == 1 ? L"通话" : refcall.cbActive==2 ? L"等待" : L"保持" );
str=strindex+str+',';
strInfo+=str;
str.Format(L"%c",refcall.cbPri ? refcall.cbPri : ' ');
str+=',';
strInfo+=str;
if(refcall.cbtype == CALL_GROUP )
{
if(refcall.strNum==L"299")
{
str=L"紧急组";
}
else
str=L"组"+refcall.strNum;
}else if(refcall.cbtype ==CALL_ALL)
{
str=L"广播"+refcall.strNum;
}else
{
if(!refcall.strFnNum.IsEmpty())
{
CString tmpstr;
/*
if(TranTFNtoTRN(refcall.strFnNum,tmpstr))
{
str=tmpstr+L"车次";
if(refcall.strFnNum.Right(1) == L"1")
str+=L"司机";
else if(refcall.strFnNum.Right(1) == L"8")
str+=L"车长";
str+=',';
}*/
if(translateByFn(refcall.strFnNum,tmpstr))
{
str=tmpstr+',';
}
else
str=refcall.strFnNum+',';
}
else
str=',';
if(!refcall.strNum.IsEmpty())
{
str+=refcall.strNum;
}
else
str+="未知身份";
}
strInfo+=str;
pDC->DrawText(strInfo,listrt,DT_SINGLELINE|DT_LEFT|DT_BOTTOM);
CSize sz=pDC->GetTextExtent(strInfo);
listrt.left+=sz.cx+4;
}
}
void CCommunicateStatic::GsmrDraw(CDC *pDC)
{
#define GSMR_SCALE 1/4
if(!IsWindowVisible())
return ;
INT index=pDC->SaveDC();
pDC->SetBkMode(TRANSPARENT);
CBrush br(m_crBorder);
pDC->FrameRect(m_Rect,&br);
CPen pen(PS_SOLID,1,m_crBorder);
pDC->SelectObject(&pen);
CPoint pt;
CRect Lrect(m_Rect),Rrect(m_Rect);
Lrect.right=m_Rect.Width()*GSMR_SCALE;
Rrect.left=Lrect.right;
m_GsmrIndicationRect=Lrect;
m_GsmrTextCanvasRect=Rrect;
// Lrect.DeflateRect(1,1,1,1);
// Rrect.DeflateRect(1,1,1,1);
/*
pt.x=Lrect.left;
pt.y=m_Rect.Height()/2;
pDC->MoveTo(pt);
pt.x=Lrect.right;
pDC->LineTo(pt);
pt.y=Lrect.top;
pDC->MoveTo(pt);
pt.y=Lrect.bottom;
pDC->LineTo(pt);
*/
pt.x=Lrect.right;
pt.y=Lrect.top;
pDC->MoveTo(pt);
pt.y=Lrect.bottom;
pDC->LineTo(pt);
if(m_CallAr.GetSize()>1)
{
Rrect.DeflateRect(0,0,0,m_GsmrTextCanvasRect.Height()/3);
CRect tmprt(Rrect.left,Rrect.bottom,Rrect.right,Rrect.bottom+m_GsmrTextCanvasRect.Height()/3);
tmprt.DeflateRect(1,1,1,1);
pDC->FillSolidRect(tmprt,RGB(0,0,0));
pt.x=Rrect.left;
pt.y=Rrect.bottom;
pDC->MoveTo(pt);
pt.x=Rrect.right;
pDC->LineTo(pt);
}
/*
if(!m_strText.IsEmpty())
{
pDC->SelectObject(&m_ftStateText);
pDC->DrawText(m_strText,Rrect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
*/
if(m_workmode == M_TALK)
DrawTalkState(pDC);
pDC->SetTextColor(m_crText);
if(!m_strText.IsEmpty())
{
pDC->SelectObject(&m_ftStateText);
int rows=::GetRows(m_strText);
pDC->SetTextColor(m_crText);
if(rows>1) //暂不考虑2行以上的情况
{
CRect vrect[2];
vrect[0]=Rrect;
vrect[1]=Rrect;
vrect[0].bottom=Rrect.Height()/2;
vrect[1].top=vrect[0].bottom;
vrect[0].DeflateRect(2,2,0,0);
vrect[1].DeflateRect(2,2,0,0);
INT index=m_strText.Find('\r',0);
CString strUp,strDown;
strUp=m_strText.Left(index);
strDown=m_strText.Mid(index+2);
pDC->DrawText(strUp,vrect[0],DT_VCENTER|DT_SINGLELINE);
//pDC->SetTextColor(RGB(125,225,0));
pDC->SelectObject(&m_ftIndicationText);
pDC->DrawText(strDown,vrect[1],DT_VCENTER|DT_SINGLELINE);
}
else
{
DWORD dwDTStyle=DT_VCENTER|DT_SINGLELINE;
if(m_workmode== M_TALK)
{
dwDTStyle|=DT_LEFT;
Rrect.DeflateRect(4,0,0,0);
CPoint InDirpt;
InDirpt.x=Rrect.left;
InDirpt.y=Rrect.Height()/2-8;
if(CALL_OUT==m_iCallDir)
{
pDC->DrawIcon(InDirpt,m_hIconDownLink);
Rrect.left+=16;
}
else if(CALL_IN==m_iCallDir)
{
pDC->DrawIcon(InDirpt,m_hIconUpLink);
Rrect.left+=16;
}
}
else
dwDTStyle|=DT_CENTER;
if(m_strText.GetLength()>10)
{
LOGFONT lf;
m_ftStateText.GetLogFont(&lf);
CFont newFont;
lf.lfHeight=14;
lf.lfWeight=500;
newFont.CreateFontIndirect(&lf);
pDC->SelectObject(&newFont);
pDC->DrawText(m_strText,Rrect,dwDTStyle);
}
else
pDC->DrawText(m_strText,Rrect,dwDTStyle);
}
}
if(m_CallAr.GetSize()>0)
{
DrawTalkList(pDC);
}
pDC->RestoreDC(index);
}
void CCommunicateStatic::M450Draw(CDC *pDC)
{
#define M450_SCALE 1/4
if(!IsWindowVisible())
return ;
INT index=pDC->SaveDC();
pDC->SetBkMode(TRANSPARENT);
CBrush br(m_crBorder);
pDC->FrameRect(m_Rect,&br);
CPen pen(PS_SOLID,1,m_crBorder);
pDC->SelectObject(&pen);
CPoint pt;
CRect Lrect(m_Rect),Rrect(m_Rect);
Lrect.right=m_Rect.Width()*M450_SCALE;
Rrect.left=Lrect.right;
pt.x=Lrect.right;
pt.y=Lrect.top;
pDC->MoveTo(pt);
pt.y=Lrect.bottom;
pDC->LineTo(pt);
CRect subLrect[2];
subLrect[0]=Lrect;
subLrect[1]=Lrect;
subLrect[0].bottom=m_Rect.Height()/2;
subLrect[1].top=subLrect[0].bottom;
pt.x=subLrect[0].left;
pt.y=subLrect[0].top;
pt.x+=5;pt.y+=8;
HICON hIRev=NULL;
if(FALSE && !m_bLightSwitch)
hIRev=m_hIconZero;
else
{
if(m_buRevSignal && m_bdRevSignal)
{
hIRev=m_hIconRevDownUp;
}
if(m_buRevSignal)
{
hIRev=m_hIconRevUp;
}else if(m_bdRevSignal)
{
hIRev=m_hIconRevDown;
}
else
{
hIRev=m_hIconZero;
}
}
if(hIRev)
{
m_450RevSignalPoint=pt;
pDC->DrawIcon(pt,hIRev);
}
pt.x=subLrect[1].left;
pt.y=subLrect[1].top;
pt.x+=5;pt.y+=4;
HICON hISend=NULL;
if(FALSE && FALSE==m_bLightSwitch)
hISend=m_hIconSendZero;
else
{
if(m_bSendSignal)
{
hISend=m_hIconSend;
}
else if(m_bShuanggong)
{
hISend=m_hIconSend;
}
else
{
hISend=m_hIconSendZero;
}
}
if(hISend)
{
m_450SendSignalPoint=pt;
pDC->DrawIcon(pt,hISend);
}
subLrect[0].left+=16+6;
subLrect[1].left+=16+6;
subLrect[0].top+=4;
subLrect[1].top+=4;
pDC->SelectObject(&m_ftIndicationText);
pDC->SetTextColor(g_CommonSet.crMainText);
pDC->DrawText(_T("(接收)"),subLrect[0],DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->DrawText(_T("(发射)"),subLrect[1],DT_CENTER|DT_VCENTER|DT_SINGLELINE);
if(!m_strText.IsEmpty())
{
m_M450TextCanvasRect=Rrect;
pDC->SelectObject(&m_ftStateText);
int rows=::GetRows(m_strText);
pDC->SetTextColor(m_crText);
if(rows>1) //暂不考虑2行以上的情况
{
CRect vrect[2];
vrect[0]=Rrect;
vrect[1]=Rrect;
vrect[0].bottom=Rrect.Height()/2;
vrect[1].top=vrect[0].bottom;
vrect[0].DeflateRect(2,2,0,0);
vrect[1].DeflateRect(2,2,0,0);
INT index=m_strText.Find('\r',0);
CString strUp,strDown;
strUp=m_strText.Left(index);
strDown=m_strText.Mid(index+2);
pDC->DrawText(strUp,vrect[0],DT_VCENTER|DT_SINGLELINE);
//pDC->SetTextColor(RGB(125,225,0));
pDC->SelectObject(&m_ftIndicationText);
pDC->DrawText(strDown,vrect[1],DT_VCENTER|DT_SINGLELINE);
}
else
{
DWORD dwDTStyle=DT_VCENTER|DT_SINGLELINE;
if(m_workmode== M_TALK)
{
dwDTStyle|=DT_LEFT;
Rrect.DeflateRect(4,0,0,0);
CPoint InDirpt;
InDirpt.x=Rrect.left;
InDirpt.y=Rrect.Height()/2-8;
if(CALL_OUT==m_iCallDir)
{
pDC->DrawIcon(InDirpt,m_hIconDownLink);
Rrect.left+=16;
}
else if(CALL_IN==m_iCallDir)
{
pDC->DrawIcon(InDirpt,m_hIconUpLink);
Rrect.left+=16;
}
}
else
dwDTStyle|=DT_CENTER;
if(m_strText.GetLength()>10)
{
LOGFONT lf;
m_ftStateText.GetLogFont(&lf);
CFont newFont;
lf.lfHeight=14;
lf.lfWeight=500;
newFont.CreateFontIndirect(&lf);
pDC->SelectObject(&newFont);
pDC->DrawText(m_strText,Rrect,dwDTStyle);
}
else
pDC->DrawText(m_strText,Rrect,dwDTStyle);
}
}
pDC->RestoreDC(index);
}
void CCommunicateStatic::FillTalkList(CArray *pCallAr)
{
if(pCallAr)
{
m_CallAr.Copy(*pCallAr);
Invalidate(FALSE);
}
else
{
m_CallAr.RemoveAll();
Invalidate(FALSE);
}
}