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

📄 launchjavacontainer.cpp

📁 在Symbian平台程序调用J2ME程序.
💻 CPP
字号:
/*
============================================================================
 Name        : CLaunchJavaContainer from LaunchJavaContainer.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Container control implementation
============================================================================
*/

#include "LaunchJavaContainer.h"
#include <aknlists.h> 
#include <BADESCA.H>

#include <APGCLI.H>
_LIT( KStringFormat, "%d\t%S\t%S" );

_LIT( KSpace, " " );


// ---------------------------------------------------------
// CLaunchJavaContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CLaunchJavaContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

	iListBox = new( ELeave ) CAknDoubleNumberStyleListBox();
	iListBox->SetContainerWindowL( *this );
	iListBox->ConstructL( this, EAknListBoxSelectionList | EAknListBoxLoopScrolling );
	iListBox->CreateScrollBarFrameL(ETrue);
	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
		CEikScrollBarFrame::EAuto );

	iIndex = 1;

	// Get the item list
	iItems = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());

	ListAllAppsL();

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CLaunchJavaContainer::~CLaunchJavaContainer()
    {
	delete iListBox;
    }

// ---------------------------------------------------------
// CLaunchJavaContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CLaunchJavaContainer::SizeChanged()
    {
	if ( iListBox )
		{
		iListBox->SetExtent( TPoint(0,0), Rect().Size() );	
		}
    }

// ---------------------------------------------------------
// CLaunchJavaContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CLaunchJavaContainer::CountComponentControls() const
    {
	if ( iListBox )
		{
		return 1;
		}
	else
		{
		return 0;
		}
    }

// ---------------------------------------------------------
// CLaunchJavaContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CLaunchJavaContainer::ComponentControl(TInt aIndex) const
    {
	switch ( aIndex )
		{
		case 0:
			return iListBox;
		default:
			return NULL;
		}
    }

// ---------------------------------------------------------
// CLaunchJavaContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CLaunchJavaContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

// ---------------------------------------------------------
// CLaunchJavaContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CLaunchJavaContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    // TODO: Add your control event handler code here
    }

void CLaunchJavaContainer::ListAllAppsL()
	{
	RApaLsSession apa;

	User::LeaveIfError( apa.Connect() );
	CleanupClosePushL( apa );

	TUid KUid = { 0x10100b88 };
	TThreadId threadId;

	TInt err = KErrNone;

	TInt appCount = 0;
	err = apa.AppCount( appCount );
	if ( err != KErrNone)
		{
		CEikonEnv::Static()->InfoWinL( _L("DoLaunchL"), _L("Error in getting Count!") );
		CleanupStack::PopAndDestroy(); // apa
		// User::Leave( err );
		return;
		}

	err = apa.GetAllApps();
	if ( err != KErrNone )
		{
		CEikonEnv::Static()->InfoWinL( _L("DoLaunchL"), _L("Error in getting all apps!") );
		CleanupStack::PopAndDestroy(); // apa
		return;
		}

	TApaAppInfo appInfo;
	for ( TInt i = 0; i < appCount; i ++ )
		{
		if ( apa.GetNextApp( appInfo ) != KErrNone ) 
			break;
		
		TBuf<100> second;
		second.Append( appInfo.iCaption );
		second.Append( KSpace );

		TBuf<10> uid;
		uid.Format( _L("0x%x"), appInfo.iUid.iUid );
		second.Append( uid );

		TBuf<256> item;
		item.Format( KStringFormat, iIndex++, &appInfo.iFullName, &second );
		iItems->AppendL( item );
		}

	// Update the display now!
	UpdateDisplayL();

#if 0
	TApaAppInfo info;
	err = apa.GetAppInfo( info, KUid );
	if ( err != KErrNone )
		{
		CEikonEnv::Static()->InfoWinL( _L("DoLaunchL"), _L("Error in getting AppInfo!") );
		CleanupStack::PopAndDestroy( ); // apa
		return;
		}

	CEikonEnv::Static()->InfoWinL( _L("DoLaunchL"), info.iFullName );

	err = apa.StartDocument( info.iFullName, KUid, threadId);

	if ( err == KErrNotFound )
		{
		CEikonEnv::Static()->InfoWinL( _L("DoLaunchL"), _L("App Not found!") );
		}
	else if ( err == RApaLsSession::EAppListInvalid )
		{
		CEikonEnv::Static()->InfoWinL( _L("DoLaunchL"), _L("Population of the list has not completed!") );
		}
#endif

	CleanupStack::PopAndDestroy( ); // apa
	}
  
TKeyResponse  CLaunchJavaContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
		TEventCode aType)
	{
	switch (aKeyEvent.iCode)
		{
		case EKeyLeftArrow:
		case EKeyRightArrow:
			// Listbox takes all event even if it doesn't use them
			return EKeyWasNotConsumed;
			break;

		case EKeyBackspace:
			{
			return EKeyWasConsumed;
			break;
			}

		default:
			break;
		}

	// now it's iListBox's job to process the key event
	return iListBox->OfferKeyEventL(aKeyEvent, aType); 
	}

void CLaunchJavaContainer::UpdateDisplayL(void)
	{
	iListBox->HandleItemAdditionL();
	iListBox->SetCurrentItemIndex( 0 );
	iListBox->ActivateL();
	iListBox->DrawNow();
	}

⌨️ 快捷键说明

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