📄 syncserialcommappview.cpp
字号:
/*
============================================================================
Name : SyncSerialCommAppView.cpp
Author : Redasen
Copyright : Redasen
Description : Application view implementation
============================================================================
*/
// INCLUDE FILES
#include <coemain.h>
#include <COECOBS.h>
#include <BARSREAD.H> // for TResourceReader
#include <eiklabel.h> // for CEikLabel
#include <eikgted.h> // for CEikGlobalTextEditor
#include "SyncSerialCommAppView.h"
#include <SyncSerialComm_0xEBC1006D.rsg>
#include "Utility.h"
#include "SyncSerialEngine.h"
_LIT( KLabelSend, "Send Data:" );
_LIT( KLabelSendData, "serial comm" );
_LIT( KLabelRecv, "Recv Data:" );
_LIT( KLabelRecvData, "Display recv data." );
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CSyncSerialCommAppView* CSyncSerialCommAppView::NewL(const TRect& aRect)
{
CSyncSerialCommAppView* self = CSyncSerialCommAppView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CSyncSerialCommAppView* CSyncSerialCommAppView::NewLC(const TRect& aRect)
{
CSyncSerialCommAppView* self = new (ELeave) CSyncSerialCommAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CSyncSerialCommAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
// 与发送数据相关的控件
iLabelSend = new (ELeave) CEikLabel;
iLabelSend->SetContainerWindowL(*this);
iLabelSend->SetTextL(KLabelSend);
iLabelSendData = new (ELeave) CEikLabel;
iLabelSendData->SetContainerWindowL(*this);
iLabelSendData->SetTextL(KLabelSendData);
// 与接收数据相关的控件
iLabelRecv = new (ELeave) CEikLabel;
iLabelRecv->SetContainerWindowL(*this);
iLabelRecv->SetTextL(KLabelRecv);
iLabelRecvData = new (ELeave) CEikLabel;
iLabelRecvData->SetContainerWindowL(*this);
iLabelRecvData->SetTextL(KLabelRecvData);
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::CSyncSerialCommAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CSyncSerialCommAppView::CSyncSerialCommAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::~CSyncSerialCommAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CSyncSerialCommAppView::~CSyncSerialCommAppView()
{
// No implementation required
if (iLabelSend)
{
delete iLabelSend;
iLabelSend = NULL;
}
if (iLabelSendData)
{
delete iLabelSendData;
iLabelSendData = NULL;
}
if (iLabelRecv)
{
delete iLabelRecv;
iLabelRecv = NULL;
}
if (iLabelRecvData)
{
delete iLabelRecvData;
iLabelRecvData = NULL;
}
if (iEngine )
{
delete iEngine;
iEngine = NULL;
}
}
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CSyncSerialCommAppView::Draw(const TRect& aRect) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CSyncSerialCommAppView::SizeChanged()
{
TPoint ptLabelSend(0, 0);
TSize sizeLabelSend = iLabelSend->MinimumSize();
iLabelSend->SetExtent(TPoint(0, 0), sizeLabelSend);
TPoint ptEditSend(0, sizeLabelSend.iHeight);
TSize sizeEditSend(Size().iWidth, 100);
iLabelSendData->SetExtent(ptEditSend, sizeEditSend);
TPoint ptLabelRecv(0, sizeLabelSend.iHeight + sizeEditSend.iHeight);
TSize sizeLabelRecv = iLabelRecv->MinimumSize();
iLabelRecv->SetExtent(ptLabelRecv, sizeLabelRecv);
TPoint ptLabelDisplay(0, sizeLabelSend.iHeight + sizeEditSend.iHeight
+ sizeLabelRecv.iHeight);
TSize sizeLabelDisplay = iLabelRecvData->MinimumSize();
iLabelRecvData->SetExtent(ptLabelDisplay, sizeLabelDisplay);
}
// -----------------------------------------------------------------------------
// CSyncSerialCommAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs,
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CSyncSerialCommAppView::HandlePointerEventL(
const TPointerEvent& aPointerEvent)
{
// Call base class HandlePointerEventL()
CCoeControl::HandlePointerEventL(aPointerEvent);
}
// ---------------------------------------------------------
// CSyncSerialCommAppView::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSyncSerialCommAppView::CountComponentControls() const
{
return 4; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CSyncSerialCommAppView::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSyncSerialCommAppView::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iLabelSend;
case 1:
return iLabelRecv;
case 2:
return iLabelRecvData;
case 3:
return iLabelSendData;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CSyncSerialCommAppView::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSyncSerialCommAppView::HandleControlEventL(CCoeControl* /*aControl*/,
TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
// ---------------------------------------------------------
// CSyncSerialCommAppView::OfferKeyEventL()
// Notify key events to the editor.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
TKeyResponse CSyncSerialCommAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
return iLabelSendData->OfferKeyEventL(aKeyEvent, aType);
}
void CSyncSerialCommAppView::InitSerial()
{
iEngine = CSyncSerialEngine::NewL();
iEngine->InitSerial();
}
void CSyncSerialCommAppView::CloseSerial()
{
iEngine->CloseSerial();
}
void CSyncSerialCommAppView::SendData()
{
TBuf8<255> sendData;
CUtility::ConvUni2Gbk( sendData, *(iLabelSendData->Text()) );
iEngine->Send( sendData );
}
void CSyncSerialCommAppView::RecvData()
{
TBuf16<255> recvData;
TBuf8<255> recvSerial;
iEngine->Recv( recvSerial );
CUtility::ConvGbk2Uni( recvData, recvSerial );
iLabelRecvData->SetTextL( recvData );
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -