⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nettestcontainer.cpp

📁 Symbian第二版断点续传代码,可以节省用户下载流量
💻 CPP
字号:
/*
============================================================================
 Name        : CNetTestContainer from NetTestContainer.h
 Author      : wayne chen
 Version     : 1.13
 Copyright   : Your copyright notice
 Description : Container control implementation
============================================================================
*/

// INCLUDE FILES
#include "NetTestContainer.h"

#include <gdi.h>
#include <coedef.h>
#include <aknlists.h> // for avrell style listbox
#include <gulicon.h>
#include <coemain.h>
#include <barsread.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CNetTestContainer::CNetTestContainer()
{
	iMsgStore = NULL ; 
}

CNetTestContainer::~CNetTestContainer()
{
	delete iScrollBar ;
	iScrollBar = NULL ;
	if(iMsgStore) delete iMsgStore ;
}

void CNetTestContainer::ConstructL(const TRect& rc) 
{
	CreateWindowL(); // Creates window
	SetRect( rc );   // Sets rectangle of frame.
	InitEditor( rc ) ; 
	ActivateL();     // Activates window. (Ready to draw)
}

void CNetTestContainer::InitEditor(const TRect& rc) 
{
	// setup the font used and the color 
	iNormalBkColor = TRgb(255, 255, 255) ; 
	iNormalFontColor = TRgb(0, 0, 0) ; 
	iReversBkColor = TRgb(0, 0, 255) ; 
	iReversFontColor = TRgb(255, 255, 255) ; 

	iNormalFont = (CFont *)CEikonEnv::Static()->TitleFont() ; 

	// setup storage and position going to use 
	iMsgStore = NULL ;
	iWordWrap = EFalse ;

	iTopLine = 0 ; 
	iLeftMargin = 8 ;
	iRightMargin = 3 ;
	iTopMargin = 5 ;
	iLineSpace = 3 ;
	iBorderWidth = rc.Width() ;
	iBorderHeight = rc.Height() ;

	// calc how many line in one page 
	iDispLines = iBorderHeight / (iNormalFont->HeightInPixels() + iLineSpace) ;

	// create scroll bar displayed under the display window
	iScrollBar = new (ELeave) CEikScrollBarFrame(this, this);
	iScrollBar->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn);
}

void CNetTestContainer::SetDescArray(CDesCArray ** pdesc, const TDesC& body) 
{
	TInt res        = 0 ; 
	TInt this_end   = 0 ; 
	TInt next_start = 0 ; 
	TInt offset     = 0 ;

	// set default display line number, from first line to display 
	iTopLine = 0 ;
	// alloc store memory
	if(*pdesc != NULL) delete *pdesc ; 

	*pdesc = new (ELeave) CDesC16ArrayFlat(10) ;

	// copy each line in msg body into CCDesC16ArrayFlat object 
	do {
		res = CalcLineChar(body.Mid(offset), this_end, next_start);
		if (res <= 0) {
			(*pdesc)->AppendL(body.Mid(offset));
			break;
		} else {
			(*pdesc)->AppendL(body.Mid(offset, this_end));
			offset += next_start;
		}
	} while(res > 0) ; 
}

void CNetTestContainer::SetScrollBarLineCount() 
{
	TInt line_count = 0 ; 
	// Initialize the scroll bar
	TEikScrollBarModel vSbarModel;	
	vSbarModel.iThumbSpan = 1; 
	vSbarModel.iThumbPosition = 0;  // iVThumbPosition

	// calculate total lines, both message and reverse color 
	if(iMsgStore && 
		((iMsgStore->Count() - iDispLines) > 0))  {
			line_count = iMsgStore->Count() ; 
		}

	// Adjust the scrollbar span for each tab page
	vSbarModel.iScrollSpan = line_count - iDispLines + 1;
	iScrollBar->Tile(&vSbarModel);
}

void CNetTestContainer::SetMsgBody(const TDesC& body) 
{
	SetDescArray(&iMsgStore, body) ;
	SetScrollBarLineCount() ; 
	DrawNow() ; 
}

TInt CNetTestContainer::CalcLineChar(const TDesC& msg, TInt& this_end, TInt& next_start)
{
	TInt len = -1;
	TUint wd = 0;
	for (TInt i = 0; i < msg.Length(); i++) {
		// find enter in the input message 
		if (msg[i] == 0x0A) { // find the [enter] char 
			this_end = len + 1;
			next_start = len + 2;
			return len + 2;
		} else if (msg[i] == 0x0D) {  
			// find change line char some txt may be 0x0d 0x0a
			// as [enter] char 
			if (i + 1 < msg.Length()) {
				if (msg[i + 1] == 0x0A) {
					this_end = len + 1;
					next_start = len + 3;
					return len + 3;
				} else { 
					this_end = len + 1;
					next_start = len + 2;
					return len + 2;
				}
			} else { 
				this_end = 0;
				next_start = 0;
				return 0;
			}
		} // end if (msg[i] == 0x0A) ...

		// not an [enter] char, calculate the text width 
		wd = iNormalFont->TextWidthInPixels(msg.Left(i));
		if (wd > iBorderWidth - iLeftMargin - iRightMargin) {
			if (iWordWrap) {
				for (TInt j = len; j >= 0; j--) {
					// check whether the ascii code 
					if (msg[j] < 0x30 || msg[j] >= 128) {
						len = j + 1;
						break;
					}
				} // end for (TInt j = len; j ... 
			} // end if (iWordWrap) ...

			this_end = len;
			next_start = len;
			return len;
		} // end if (wd > iBorderWidth ... 
		len = i;
	} // end for (TInt i = 0; i ... 

	if (wd < iBorderWidth - iLeftMargin - iRightMargin) {
		this_end = len + 1;
		next_start = len + 2;
		return -1;
	} else {
		this_end = 0;
		next_start = 0;
		return 0;
	}
}

void CNetTestContainer::Draw(const TRect& aRect) const 
{
	CWindowGc& gc = SystemGc() ;

	// clear current display screen 
	gc.SetPenStyle( CGraphicsContext::ENullPen ) ;
	gc.SetBrushStyle( CGraphicsContext::ESolidBrush ) ;
	gc.SetBrushColor( iNormalBkColor );
	gc.DrawRect( aRect );

	// display message and revers color text 
	DispAll(gc) ; 
}

TInt CNetTestContainer::DispMsgBody(CWindowGc& gc, TInt& y, TInt line_step) const 
{
	TInt  count = iMsgStore->Count() ; 
	TInt  i ; 

	// check whether it is necessary to change pages 
	if (count > iDispLines)	count = iDispLines;
	for (i = 0; i < count; i++, y += line_step) {
		if(((TInt)(i+iTopLine)) >= iMsgStore->Count()) break ; 
		gc.DrawText((*iMsgStore)[i + iTopLine], TPoint(iLeftMargin, y));
	}

	// return the left lines can be displayed 
	return (iDispLines - i) ; 
}

void CNetTestContainer::DispAll(CWindowGc& gc) const
{
	// init display line position 
	TInt y = iNormalFont->AscentInPixels() + iTopMargin ; 
	// default line distance between each line 
	TUint line_step = iNormalFont->HeightInPixels() + iLineSpace ; 
	TInt  can_disp_line = iDispLines ; // suppose only one page info displayed 

	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	gc.UseFont(iNormalFont) ;

	// display message body and reverse body 
	if(iMsgStore) {
		// handler for message and revers both exist display 
		can_disp_line = DispMsgBody(gc, y, line_step) ; 
	}
}

TInt CNetTestContainer::CountComponentControls() const
{
	// no controls used here 
	return 0 ; 
}

CCoeControl* CNetTestContainer::ComponentControl( TInt /*aIndex*/ ) const
{
	// no handlers to be returned here 
	return NULL ; 
}

void CNetTestContainer::SizeChanged() {}

TKeyResponse CNetTestContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
											  TEventCode aType)
{
	TInt code = aKeyEvent.iCode;
	if(aType != EEventKey) return EKeyWasNotConsumed ; 
	switch(code) {
	case EKeyOK:
		break ; 
	case EKeyUpArrow:
		{
			if (iTopLine != 0) {
				iTopLine --;
				iScrollBar->MoveVertThumbTo(iTopLine);
				DrawNow();
			}
		}
		break ; 
	case EKeyDownArrow:
		{
			TInt line_count = 0 ;
			TInt val = 0 ; 
			if(iMsgStore) line_count = iMsgStore->Count() ; 

			val = line_count - iDispLines ; 
			if (val > 0 && (TInt)iTopLine < val) {
				iTopLine ++;
				iScrollBar->MoveVertThumbTo(iTopLine);
				DrawNow();
			}
		}
		break ; 
	default:
		break ; 
	}
	return EKeyWasConsumed ; 
}

void CNetTestContainer::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) {}
void CNetTestContainer::HandleScrollEventL(CEikScrollBar* /*aScrollBar*/, TEikScrollEvent /*aEventType*/) {}
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -