appfw/apparchitecture/tef/SimpleApparcTestApp.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This is a support app used by apparc\tsrc\t_foreground
       
    15 // Test for UIKON GT0143 Typhoon Work Series 60 Changes
       
    16 // REQ758.8: Change TApaTask::BringToForeground to send a 
       
    17 // EApaSystemEventBroughtToForeground to the relevant window group
       
    18 // t_foreground sends a window server message to this app, this 
       
    19 // message is handled in CExampleAppUi::HandleSystemEventL
       
    20 // 
       
    21 //
       
    22 
       
    23 /**
       
    24  @file
       
    25  @internalComponent - Internal Symbian test code
       
    26 */
       
    27 
       
    28 
       
    29 
       
    30 #include <coeccntx.h>
       
    31 
       
    32 #include <apgtask.h>
       
    33 #include <eikenv.h>
       
    34 #include <eikappui.h>
       
    35 #include <eikapp.h>
       
    36 #include <eikdoc.h>
       
    37 #include <techview/eikmenup.h>
       
    38 
       
    39 #include <techview/eikon.hrh>
       
    40 
       
    41 #include <simpleapparctestapp.rsg>
       
    42 #include "SimpleApparcTestApp.hrh"
       
    43 
       
    44 #include <eikstart.h>
       
    45 
       
    46 
       
    47 //
       
    48 //
       
    49 // CExampleAppView
       
    50 //
       
    51 //
       
    52 class CExampleAppView : public CCoeControl
       
    53     {
       
    54 public:
       
    55 	static CExampleAppView* NewL(const TRect& aRect);
       
    56 	CExampleAppView();
       
    57 	~CExampleAppView();
       
    58     void ConstructL(const TRect& aRect);
       
    59 
       
    60 private:
       
    61 	           // Inherited from CCoeControl
       
    62 	void Draw(const TRect& /*aRect*/) const;
       
    63 
       
    64 private:
       
    65 	HBufC*  iExampleText;
       
    66     };
       
    67 
       
    68 CExampleAppView::CExampleAppView()
       
    69 	{
       
    70 	}
       
    71 
       
    72 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
       
    73 	{
       
    74 	CExampleAppView* self = new(ELeave) CExampleAppView();
       
    75 	CleanupStack::PushL(self);
       
    76 	self->ConstructL(aRect);
       
    77 	CleanupStack::Pop();
       
    78 	return self;
       
    79 	}
       
    80 
       
    81 CExampleAppView::~CExampleAppView()
       
    82 	{
       
    83 	delete iExampleText;
       
    84 	}
       
    85 
       
    86 void CExampleAppView::ConstructL(const TRect& aRect)
       
    87     {
       
    88 	iExampleText = iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_TITLE);
       
    89 	CreateWindowL();
       
    90 	SetRect(aRect);
       
    91 	ActivateL();
       
    92 	}
       
    93 
       
    94 void CExampleAppView::Draw(const TRect& /*aRect*/) const
       
    95 	{
       
    96 	CWindowGc& gc = SystemGc();
       
    97 	TRect      drawRect = Rect();
       
    98 	const CFont*     fontUsed;
       
    99 	
       
   100 	gc.Clear();
       
   101   	fontUsed = iEikonEnv->TitleFont();
       
   102 	gc.UseFont(fontUsed);
       
   103 	TInt   baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
       
   104 	gc.DrawText(*iExampleText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
       
   105 	gc.DiscardFont();
       
   106 	}
       
   107 
       
   108 
       
   109 //
       
   110 //
       
   111 // CExampleAppUi
       
   112 //
       
   113 //
       
   114 class CExampleAppUi : public CEikAppUi
       
   115     {
       
   116 public:
       
   117     void ConstructL();
       
   118 	~CExampleAppUi();
       
   119 
       
   120 private:
       
   121               // Inherirted from class CEikAppUi
       
   122 	void HandleCommandL(TInt aCommand);
       
   123 
       
   124 	// From CCoeAppUi
       
   125 	void HandleSystemEventL(const TWsEvent& aEvent);
       
   126 
       
   127 private:
       
   128 	CCoeControl* iAppView;
       
   129 	};
       
   130 
       
   131 
       
   132 void CExampleAppUi::ConstructL()
       
   133     {
       
   134     BaseConstructL();
       
   135 	iAppView = CExampleAppView::NewL(ClientRect());
       
   136 	}
       
   137 
       
   138 CExampleAppUi::~CExampleAppUi()
       
   139 	{
       
   140 	delete iAppView;
       
   141 	}
       
   142 
       
   143 void CExampleAppUi::HandleCommandL(TInt aCommand)
       
   144 	{
       
   145 	switch (aCommand)
       
   146 		{
       
   147 		      // Just issue simple info messages to show that
       
   148 		      // the menu items have been selected
       
   149 	case EExampleItem0:
       
   150 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM0);
       
   151 		break;
       
   152 
       
   153 	
       
   154 	case EExampleItem1:
       
   155 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM1);
       
   156 		break;
       
   157 	
       
   158 	case EExampleItem2:
       
   159 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM2);
       
   160 		break;
       
   161 	case EEikCmdExit: 
       
   162 		Exit();
       
   163 		break;
       
   164 		}
       
   165 	}
       
   166 
       
   167 
       
   168 void CExampleAppUi::HandleSystemEventL(const TWsEvent& aEvent)
       
   169 	{
       
   170 	switch (*(TApaSystemEvent*)(aEvent.EventData()))
       
   171 		{
       
   172 		case EApaSystemEventBroughtToForeground:
       
   173 			RProcess::Rendezvous(KErrNone);
       
   174 			break;
       
   175          default:
       
   176 			break;
       
   177 		}	
       
   178 	}
       
   179 
       
   180 
       
   181 
       
   182 
       
   183 
       
   184 //
       
   185 //
       
   186 // CExampleDocument
       
   187 //
       
   188 //
       
   189 class CExampleDocument : public CEikDocument
       
   190 	{
       
   191 public:
       
   192 	static CExampleDocument* NewL(CEikApplication& aApp);
       
   193 	CExampleDocument(CEikApplication& aApp);
       
   194 	void ConstructL();
       
   195 private: 
       
   196 	           // Inherited from CEikDocument
       
   197 	CEikAppUi* CreateAppUiL();
       
   198 	};
       
   199 
       
   200 CExampleDocument::CExampleDocument(CEikApplication& aApp)
       
   201 		: CEikDocument(aApp)
       
   202 	{
       
   203 	}
       
   204 
       
   205 CEikAppUi* CExampleDocument::CreateAppUiL()
       
   206 	{
       
   207     return new(ELeave) CExampleAppUi;
       
   208 	}
       
   209 
       
   210 
       
   211 
       
   212 //
       
   213 //
       
   214 // CExampleApplication
       
   215 //
       
   216 //
       
   217 
       
   218 class CExampleApplication : public CEikApplication
       
   219 	{
       
   220 private: 
       
   221 	           // Inherited from class CApaApplication
       
   222 	CApaDocument* CreateDocumentL();
       
   223 	TUid AppDllUid() const;
       
   224 private:
       
   225 	CApaDocument* CreateDocumentL(CApaProcess* a) { return CEikApplication::CreateDocumentL(a); }
       
   226 	//
       
   227 	};
       
   228 
       
   229 const TUid KUidSimpleApparcTestApp = { 0X12008ACE }; 
       
   230 
       
   231 TUid CExampleApplication::AppDllUid() const
       
   232 	{
       
   233 	return KUidSimpleApparcTestApp;
       
   234 	}
       
   235 
       
   236 CApaDocument* CExampleApplication::CreateDocumentL()
       
   237 	{
       
   238 	return new (ELeave) CExampleDocument(*this);
       
   239 	}
       
   240 
       
   241 
       
   242 LOCAL_C CApaApplication* NewApplication()
       
   243 	{
       
   244 	return new CExampleApplication;
       
   245 	}
       
   246 
       
   247 
       
   248 GLDEF_C TInt E32Main()
       
   249 	{
       
   250 	return EikStart::RunApplication(NewApplication);
       
   251 	}
       
   252 	
       
   253