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

📄 tcpex_appview.cpp

📁 关于symbian uiq平台的例子不多
💻 CPP
字号:
// TCPEx_CTCPExAppView.cpp
// ------------------------------
//
// Copyright (c) 2000 Symbian Ltd.  All rights reserved.
//

////////////////////////////////////////////////////////////////////////
//
// Source file for the implementation of the 
// application view class - CTCPExAppView
//
////////////////////////////////////////////////////////////////////////

#include "TCPEx.h"

namespace // anon
	{
	
	_LIT(KStateReady,"READY");
	_LIT(KStateResolving,"RESOLVING");
	_LIT(KStateOpening,"OPENING");
	_LIT(KStateSending,"SENDING");
	_LIT(KStateFetching,"RECEIVING");
	_LIT(KStateDone,"DONE");
	_LIT(KStateError,"ERROR");
	
	_LIT(KTextEmpty,"(empty)");
	
	_LIT(KErrBadStateDesc,"Bad State");
		
	}
	
//
//             Constructor for the view.
//
CTCPExAppView::CTCPExAppView()
	{
	SetState(EIdle);
	}


//             Static NewL() function to start the standard two
//             phase construction.
//
CTCPExAppView* CTCPExAppView::NewL(const TRect& aRect)
	{
	CTCPExAppView* self = new(ELeave) CTCPExAppView();
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	CleanupStack::Pop(self);
	return self;
	}


//
//             Destructor for the view.
//
CTCPExAppView::~CTCPExAppView()
	{
	delete iBody;
	}
	
//             Second phase construction.
//
void CTCPExAppView::ConstructL(const TRect& aRect)
    {    
    // Control is a window owning control	       
	CreateWindowL();
	// Extent of the control. This is
	// the whole rectangle available to application.
	// The rectangle is passed to us from the application UI.
	SetRect(aRect);
	
	// Create body
	iBody = new(ELeave) CEikLabel;
	CleanupStack::PushL(iBody);
	TRect bodyRect = Rect();
	bodyRect.Shrink(KMargin,KMargin);
	bodyRect.iTl.iY = KSeparatorY;
	bodyRect.SetHeight(Rect().Height()-KSeparatorY-KMargin);
	bodyRect.Shrink(KMargin,KMargin);
	iBody->SetRect(bodyRect);
	ClearL();
	
	CleanupStack::Pop(iBody);
	
	// At this stage, the control is ready to draw so
	// we tell the UI framework by activating it.
 	ActivateL();
	
	} 
		
TInt CTCPExAppView::SetState(const TRetrieveHttpProgress aState)
	{
	// set state text, incorporating bounds check
	switch(aState)
		{
	case EIdle:
		iStateDesc.Set(KStateReady);
		break;
		
	case EResolving:
		iStateDesc.Set(KStateResolving);
		break;
		
	case EConnecting:
		iStateDesc.Set(KStateOpening);
		break;

	case ESending:
		iStateDesc.Set(KStateSending);
		break;

	case EReceiving:
		iStateDesc.Set(KStateFetching);
		break;
		
	case EComplete:
		iStateDesc.Set(KStateDone);
		break;
		
	case EFailed:
		iStateDesc.Set(KStateError);
		break;
		
	default:
		goto BadState;
		}
	// done
	iState = aState;
	DrawDeferred();
	return KErrNone;
BadState: // so sue us
	User::InfoPrint(KErrBadStateDesc);
	return KErrArgument;
	}

void CTCPExAppView::ClearL()
	{
	iBody->SetTextL(KTextEmpty);
	iBody->SetDimmed(ETrue);
	}
	
void CTCPExAppView::SetTextL(const TDesC& aText)
	{
	iBody->SetTextL(aText);
	iBody->SetDimmed(EFalse);
	}


//             Drawing the view - in this example, 
//             consists of drawing a simple outline rectangle
//             and then drawing the text in the middle.
//             We use the Normal font supplied by the UI.
//
//             In this example, we don't use the redraw
//             region because it's easier to redraw to
//             the whole client area.
//
void CTCPExAppView::Draw(const TRect& /*aRect*/) const
	{
	CWindowGc& gc = SystemGc();

	// Font used for drawing text
	const CFont* fontUsed;
	TRect drawRect = Rect();
		
	// Start with a clear screen
	gc.Clear();
	
	// Draw an outline rectangle (the default pen
	// and brush styles ensure this) slightly
	// smaller than the drawing area.
	drawRect.SetHeight(KSeparatorY);
	drawRect.Shrink(KMargin,KMargin);   	
	gc.DrawRect(drawRect);
    
    // Use the title font supplied by the UI
	fontUsed = iEikonEnv->TitleFont();
	gc.UseFont(fontUsed);
	
	// Draw the text in the middle of the rectangle.
	TInt baselineOffset=(KSeparatorY - fontUsed->HeightInPixels()) / 2; 
	gc.DrawText(iStateDesc,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
    
    // Finished using the font
	gc.DiscardFont();
	
	// Put a border around the body
	drawRect = iBody->Rect();
	drawRect.Grow(KMargin,KMargin);
	gc.DrawRect(drawRect);
	}

⌨️ 快捷键说明

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