// COEAUIS.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <coeauis.h>
#include <coecntrl.h>
#include <coepanic.h>

EXPORT_C CCoeAppUiSimple::CCoeAppUiSimple()
	{
	}

EXPORT_C CCoeAppUiSimple::~CCoeAppUiSimple()
	{
	delete iRootControl;
	}

EXPORT_C void CCoeAppUiSimple::SetRootControl(CCoeControl* aControl)
	{
	__ASSERT_ALWAYS(!iRootControl,Panic(ECoePanicRootControlAlreadyExists));
	iRootControl=aControl;
	}

EXPORT_C void CCoeAppUiSimple::HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination)
	{
	const TInt type=aEvent.Type();
	switch (type)
		{
	case EEventKey:
	case EEventKeyUp:
	case EEventKeyDown:
		HandleKeyEventL(*aEvent.Key(),(TEventCode)type);
		break;
	case EEventPointer:
		aDestination->ProcessPointerEventL(*aEvent.Pointer());
		break;
	case EEventFocusLost:
	case EEventFocusGained:
		HandleForegroundEventL(type==EEventFocusGained);
		break;
	default:
		break;
		}
	}

EXPORT_C void CCoeAppUiSimple::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	if (iRootControl)
		iRootControl->OfferKeyEventL(aKeyEvent,aType);
	}

EXPORT_C void CCoeAppUiSimple::HandleForegroundEventL(TBool aForeground)
	{
	if (iRootControl)
		iRootControl->SetFocus(aForeground,EDrawNow);
	}
