// TBORDER.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <basched.h>
#include <eikenv.h>
#include <coecntrl.h>
#include <eikappui.h>
#include <e32keys.h>
#include <eikdef.h>
#include <eikdutil.h>
#include <eikbordr.h>
#include <coeutils.h>
#include <eikdoc.h>
#include <eikapp.h>

const KMaxBufLength = 40;

//
// class CSimpleControl
//

class CSimpleControl : public CCoeControl
    {
public:
    void ConstructL();
private: // framework
	void Draw(const TRect& aRect) const;
	TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
private: // new function
	void DrawText() const;
private:
	TBuf<KMaxBufLength> iBuf1;
	TBuf<KMaxBufLength> iBuf2;
	TRect iRect;
	CGraphicsContext::TTextAlign iAlign;
    };

void CSimpleControl::ConstructL()
    {
    CreateWindowL();
    Window().SetShadowDisabled(ETrue);
	iAlign=CGraphicsContext::ECenter;
    SetExtentToWholeScreenL();
    ActivateL();
	iBuf1 = _L("This &line has 0 margin...");
	iBuf2 = _L("and this one has a &margin of 20!");
	iRect = TRect(TPoint(40,40),TSize(560,160));
    }

TKeyResponse CSimpleControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    if (aType!=EEventKey)
        return(EKeyWasNotConsumed);
    TInt code=aKeyEvent.iCode;
    if (code==CTRL('e'))
        CBaActiveScheduler::Exit();
	if (code==CTRL('l'))
		iAlign=CGraphicsContext::ELeft;
	else if (code==CTRL('r'))
		iAlign=CGraphicsContext::ERight;
	else if (code==CTRL('c'))
		iAlign=CGraphicsContext::ECenter;
	else
		return(EKeyWasConsumed);
	ActivateGc();
	DrawText();
	DeactivateGc();
    return(EKeyWasConsumed);
    }

void CSimpleControl::Draw(const TRect& /*aRect*/) const
	{
	CWindowGc& gc = SystemGc();
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.DrawRect(Rect());

	gc.UseFont(iCoeEnv->NormalFont());

	TInt yPos = 30;
	TInt yTextPos = 42;
	const TInt yInc = 25;

	{TEikBorder border(TEikBorder::ENone);
	gc.SetClippingRect(TRect(TPoint(30,yPos),TSize(100,20)));
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("ENone"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}

	{TEikBorder border(TEikBorder::ESingleBlack);
	gc.SetClippingRect(TRect(TPoint(30,yPos),TSize(100,20)));
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("ESingleBlack"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}
	
	{TEikBorder border(TEikBorder::EShallowRaised);
	gc.SetClippingRect(TRect(TPoint(30,yPos),TSize(100,20)));
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("EShallowRaised"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}
	
	{TEikBorder border(TEikBorder::EDeepRaised);
	gc.SetClippingRect(TRect(TPoint(30,yPos),TSize(100,20)));
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("EDeepRaised"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}
	
	{TEikBorder border(TEikBorder::EShallowSunken);
	gc.SetClippingRect(TRect(TPoint(30,yPos),TSize(100,20)));
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("EShallowSunken"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}
	
	{TEikBorder border(TEikBorder::EDeepSunken);
	gc.SetClippingRect(TRect(TPoint(30,yPos),TSize(100,20)));
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("EDeepSunken"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}
	
/*	{TEikBorder border(TEikBorder::EShallowRaisedWithShadow);
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("EShallowRaisedWithShadow"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}
	
	{TEikBorder border(TEikBorder::EDeepRaisedWithShadow);
	border.Draw(gc,TRect(TPoint(30,yPos),TSize(100,20)));
	gc.CancelClippingRect();
	border.Draw(gc,TRect(TPoint(140,yPos),TSize(100,20)));
	gc.SetPenColor(KRgbBlack);
	gc.DrawText(_L("EDeepRaisedWithShadow"),TPoint(250,yTextPos));
	yTextPos+=yInc;
	yPos+=yInc;}*/

//	DrawText();
	}

void CSimpleControl::DrawText() const
	{ // assumes brush style is NULL on entry to routine; trashed at exit
	CWindowGc& gc = SystemGc();
	TRect rect = iRect;
	rect.Shrink(TSize(80,60));
	rect.Move(0,-30);
	const CFont* font = iCoeEnv->NormalFont();
	gc.UseFont(font);
	TRect tmp=rect;
	gc.DrawRect(tmp);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	tmp.Shrink(1,1);
	EikDrawUtils::DrawText(gc,iBuf1,tmp,font->AscentInPixels()*2,iAlign,0,font);
	rect.Move(0,60);
	gc.SetBrushStyle(CGraphicsContext::ENullBrush);
	gc.DrawRect(rect);
	rect.Shrink(1,1);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	EikDrawUtils::DrawText(gc,iBuf2,rect,font->AscentInPixels()*2,iAlign,20,font);
	}


//
// CSimpleAppUi
//

class CSimpleAppUi : public CEikAppUi
    {
public:
    void ConstructL();
	~CSimpleAppUi();
private: // framework
private:
    CSimpleControl* iSimpleControl;
    };

void CSimpleAppUi::ConstructL()
    {
    BaseConstructL(ENoAppResourceFile);
    iSimpleControl=new(ELeave) CSimpleControl;
    iSimpleControl->ConstructL();
    AddToStackL(iSimpleControl);
    }

CSimpleAppUi::~CSimpleAppUi()
	{
    delete iSimpleControl;
	}

//
// CSimpleDocument
//

class CSimpleDocument : public CEikDocument
	{
public:
	CSimpleDocument(CEikApplication& aApp): CEikDocument(aApp) { }
private: // from CApaDocument
	CEikAppUi* CreateAppUiL();
	};

CEikAppUi* CSimpleDocument::CreateAppUiL()
	{
    return(new(ELeave) CSimpleAppUi);
	}

//
// CSimpleApplication
//

class CSimpleApplication : public CEikApplication
	{
private: // from CApaApplication
	CApaDocument* CreateDocumentL();
	TUid AppDllUid() const;
	TFileName ResourceFileName() const;
	};

TFileName CSimpleApplication::ResourceFileName() const
	{
	TPtrC empty;
	return(empty);
	}
	
const TUid KUidTBorderApp={203};

TUid CSimpleApplication::AppDllUid() const
	{
	return(KUidTBorderApp);
	}

CApaDocument* CSimpleApplication::CreateDocumentL()
	{
	return(new(ELeave) CSimpleDocument(*this));
	}

//
// EXPORTed functions
//

EXPORT_C CApaApplication* NewApplication()
	{
	return(new CSimpleApplication);
	}

GLDEF_C TInt E32Dll(TDllReason)
	{
	return(KErrNone);
	}
