imchatrecordcontainer.cpp
来自「国内著名嵌入式培训机构内部资料,内含一些实例代码,包括技术专题书籍」· C++ 代码 · 共 208 行
CPP
208 行
/*
============================================================================
Author : hou maoqing
Version : 1.0
Copyright : Copyright (c) Hou maoqing 2008
Mail : houmqing@163.com
============================================================================
*/
#include "ImChatRecordContainer.h"
#include <ImClientExam.rsg>
#include <StringLoader.h>
#include <eiklabel.h>
#include <barsread.h> // for resource reader
#include <eikedwin.h> // for CEikEdwin
#include <eikseced.h> // for secret editor
#include <EIKENV.H>
#include <TXTGLOBL.H>
#include <eikgted.h>
#include <ImChatRecordView.h>
#include <sockets.hrh>
// ================= MEMBER FUNCTIONS =======================
CImChatRecordContainer::CImChatRecordContainer(CImChatRecordView* pView)
{
m_pView=pView;
}
// ---------------------------------------------------------
// CImChatRecordContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CImChatRecordContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC( reader, R_IMCHAT_RECORD_VIEW_GTEXTED );
iGTextEd = new ( ELeave ) CEikGlobalTextEditor;
iGTextEd->SetContainerWindowL( *this );
iGTextEd->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // Resource reader
iGTextEd->SetAvkonWrap( ETrue );
iCoeEnv->CreateResourceReaderLC( reader, R_IMCHAT_RECORD_VIEW_EDWIN );
iInputBox = new ( ELeave ) CEikEdwin;
iInputBox->SetContainerWindowL( *this );
iInputBox->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // Resource reader
iInputBox->SetFocus(ETrue);
SetRect(aRect);
SetBlank();
ActivateL();
}
// Destructor
CImChatRecordContainer::~CImChatRecordContainer()
{
delete iGTextEd;
delete iInputBox;
}
// ---------------------------------------------------------
// CImChatRecordContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CImChatRecordContainer::SizeChanged()
{
const CFont* pFont = CEikonEnv::Static()->DenseFont();
int nLineHeight=pFont->FontMaxHeight()+8;
TRect rectClient=Rect();
TRect rectChatRecord=rectClient;
TRect rectInputBox=rectClient;
rectChatRecord.iBr.iY-=nLineHeight;
rectInputBox.iTl.iY=rectInputBox.iBr.iY-nLineHeight;
rectInputBox.Grow(-2,-2);
TSize size = rectChatRecord.Size();
if (iGTextEd->ScrollBarFrame())
{
size.iWidth -= iGTextEd->ScrollBarFrame()->VerticalScrollBar()->ScrollBarBreadth();
}
iGTextEd->SetExtent( rectChatRecord.iTl, size );
iInputBox->SetExtent( rectInputBox.iTl, rectInputBox.Size() );
}
// ---------------------------------------------------------
// CImChatRecordContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CImChatRecordContainer::CountComponentControls() const
{
return 2; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CImChatRecordContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CImChatRecordContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iGTextEd;
case 1:
return iInputBox;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CImChatRecordContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CImChatRecordContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CImChatRecordContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CImChatRecordContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
TKeyResponse CImChatRecordContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType)
{
TKeyResponse r = EKeyWasNotConsumed;
if (aType == EEventKey)
{
if(aKeyEvent.iCode==EKeyUpArrow
|| aKeyEvent.iCode==EKeyDownArrow)
{
return iGTextEd->OfferKeyEventL(aKeyEvent,aType);
}
else if(aKeyEvent.iCode==EKeyDevice3) //ok key
{
m_pView->HandleCommandL(EImCmdSendMessage);
r=EKeyWasConsumed;
}
}
if(r==EKeyWasConsumed)
return r;
if(iInputBox->IsFocused())
return iInputBox->OfferKeyEventL(aKeyEvent,aType);
return CCoeControl::OfferKeyEventL(aKeyEvent,aType);
}
void CImChatRecordContainer::GetInputBoxText(TDes& desText)
{
iInputBox->GetText(desText);
TBuf<2> buf;
buf.Append(_L(""));
iInputBox->SetTextL(&buf);
iInputBox->HandleTextChangedL();
iInputBox->DrawDeferred();
}
void CImChatRecordContainer::AddChatRecord(const TDesC& desChatRecord)
{
int pos=iGTextEd->CursorPos();
CGlobalText* pRichText=iGTextEd->GlobalText();
pRichText->InsertL( pos ,desChatRecord);
iGTextEd->SetCursorPosL( pos + desChatRecord.Length(), ETrue );
iGTextEd->HandleTextChangedL();
iGTextEd->MoveDisplayL(TCursorPosition::EFPageDown);
//插入换行符
TBuf<2> bufLine;
bufLine.Append(0x2029);
pos=iGTextEd->CursorPos();
pRichText->InsertL( pos ,bufLine);
iGTextEd->SetCursorPosL( pos + bufLine.Length(), ETrue );
iGTextEd->HandleTextChangedL();
iGTextEd->MoveDisplayL(TCursorPosition::EFPageDown);
iGTextEd->DrawDeferred();
}
// End of File
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?