common/tools/ats/smoketest/localisation/apparchitecture/tef/ChildII_Main.cpp
changeset 793 0c32c669a39d
child 872 17498133d9ad
equal deleted inserted replaced
792:893b85cda81b 793:0c32c669a39d
       
     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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // A simple application containing a single view with the text "Child II !" drawn on it.
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent - Internal Symbian test code
       
    23 */
       
    24 
       
    25 #include <coeccntx.h>
       
    26 
       
    27 #include <eikenv.h>
       
    28 #include <eikappui.h>
       
    29 #include <eikapp.h>
       
    30 #include <eikdoc.h>
       
    31 #include <eikmenup.h>
       
    32 #include <eikstart.h>
       
    33 
       
    34 #include <eikon.hrh>
       
    35 
       
    36 #include <ChildII.rsg>
       
    37 #include "ChildII.hrh"
       
    38 
       
    39 ////////////////////////////////////////////////////////////////////////
       
    40 //
       
    41 // CExampleAppView
       
    42 //
       
    43 ////////////////////////////////////////////////////////////////////////
       
    44 class CExampleAppView : public CCoeControl
       
    45     {
       
    46 public:
       
    47 	static CExampleAppView* NewL(const TRect& aRect);
       
    48 	CExampleAppView();
       
    49 	~CExampleAppView();
       
    50     void ConstructL(const TRect& aRect);
       
    51 
       
    52 private:
       
    53 	           // Inherited from CCoeControl
       
    54 	void Draw(const TRect& /*aRect*/) const;
       
    55 
       
    56 private:
       
    57 	HBufC*  iExampleText;
       
    58     };
       
    59 
       
    60 //
       
    61 //             Constructor for the view.
       
    62 //
       
    63 CExampleAppView::CExampleAppView()
       
    64 	{
       
    65 	}
       
    66 
       
    67 //             Static NewL() function to start the standard two
       
    68 //             phase construction.
       
    69 //
       
    70 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
       
    71 	{
       
    72 	CExampleAppView* self = new(ELeave) CExampleAppView();
       
    73 	CleanupStack::PushL(self);
       
    74 	self->ConstructL(aRect);
       
    75 	CleanupStack::Pop();
       
    76 	return self;
       
    77 	}
       
    78 
       
    79 
       
    80 //
       
    81 //             Destructor for the view.
       
    82 //
       
    83 CExampleAppView::~CExampleAppView()
       
    84 	{
       
    85 	delete iExampleText;
       
    86 	}
       
    87 
       
    88 
       
    89 //             Second phase construction.
       
    90 //
       
    91 void CExampleAppView::ConstructL(const TRect& aRect)
       
    92     {
       
    93 			   // Fetch the text from the resource file.
       
    94 	iExampleText = iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_CHILDII);
       
    95 	           // Control is a window owning control
       
    96 	CreateWindowL();
       
    97 	           // Extent of the control. This is
       
    98 	           // the whole rectangle available to application.
       
    99 	           // The rectangle is passed to us from the application UI.
       
   100 	SetRect(aRect);
       
   101 			   // At this stage, the control is ready to draw so
       
   102 	           // we tell the UI framework by activating it.
       
   103 	ActivateL();
       
   104 	}
       
   105 
       
   106 
       
   107 //             Drawing the view - in this example, 
       
   108 //             consists of drawing a simple outline rectangle
       
   109 //             and then drawing the text in the middle.
       
   110 //             We use the Normal font supplied by the UI.
       
   111 //
       
   112 //             In this example, we don't use the redraw
       
   113 //             region because it's easier to redraw to
       
   114 //             the whole client area.
       
   115 //
       
   116 void CExampleAppView::Draw(const TRect& /*aRect*/) const
       
   117 	{
       
   118                // Window graphics context
       
   119 	CWindowGc& gc = SystemGc();
       
   120 	           // Area in which we shall draw
       
   121 	TRect      drawRect = Rect();
       
   122 			   // Font used for drawing text
       
   123 	const CFont*     fontUsed;
       
   124 	
       
   125 	           // Start with a clear screen
       
   126 	gc.Clear();
       
   127 			   // Draw an outline rectangle (the default pen
       
   128 	           // and brush styles ensure this) slightly
       
   129 	           // smaller than the drawing area.
       
   130 	drawRect.Shrink(10,10);		   	
       
   131 	gc.DrawRect(drawRect);
       
   132                // Use the title font supplied by the UI
       
   133 	fontUsed = iEikonEnv->TitleFont();
       
   134 	gc.UseFont(fontUsed);
       
   135 			   // Draw the text in the middle of the rectangle.
       
   136 	TInt   baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
       
   137 	gc.DrawText(*iExampleText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
       
   138                // Finished using the font
       
   139 	gc.DiscardFont();
       
   140 	}
       
   141 
       
   142 ////////////////////////////////////////////////////////////////////////
       
   143 //
       
   144 // CExampleAppUi
       
   145 //
       
   146 ////////////////////////////////////////////////////////////////////////
       
   147 class CExampleAppUi : public CEikAppUi
       
   148     {
       
   149 public:
       
   150     void ConstructL();
       
   151 	~CExampleAppUi();
       
   152 
       
   153 private:
       
   154               // Inherirted from class CEikAppUi
       
   155 	void HandleCommandL(TInt aCommand);
       
   156 
       
   157 private:
       
   158 	CCoeControl* iAppView;
       
   159 	};
       
   160 
       
   161 //             The second phase constructor of the application UI class.
       
   162 //             The application UI creates and owns the one and only view.
       
   163 // 
       
   164 void CExampleAppUi::ConstructL()
       
   165     {
       
   166 	           // BaseConstructL() completes the UI framework's
       
   167 	           // construction of the App UI.
       
   168     BaseConstructL();
       
   169 	           // Create the single application view in which to
       
   170 	           // draw the text "Child II", passing into it
       
   171 	           // the rectangle available to it.
       
   172 	iAppView = CExampleAppView::NewL(ClientRect());
       
   173 	}
       
   174 
       
   175 
       
   176 //             The app Ui owns the two views and is. 
       
   177 //             therefore, responsible for destroying them
       
   178 //
       
   179 CExampleAppUi::~CExampleAppUi()
       
   180 	{
       
   181 	delete iAppView;
       
   182 	}
       
   183 
       
   184 
       
   185 //             Called by the UI framework when a command has been issued.
       
   186 //             In this example, a command can originate through a 
       
   187 //             hot-key press or by selection of a menu item.
       
   188 //             The command Ids are defined in the .hrh file
       
   189 //             and are 'connected' to the hot-key and menu item in the
       
   190 //             resource file.
       
   191 //             Note that the EEikCmdExit is defined by the UI
       
   192 //             framework and is pulled in by including eikon.hrh
       
   193 //
       
   194 void CExampleAppUi::HandleCommandL(TInt aCommand)
       
   195 	{
       
   196 	switch (aCommand)
       
   197 		{
       
   198 		      // Just issue simple info messages to show that
       
   199 		      // the menu items have been selected
       
   200 	case EExampleItem0:
       
   201 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM0);
       
   202 		break;
       
   203 
       
   204 	
       
   205 	case EExampleItem1:
       
   206 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM1);
       
   207 		break;
       
   208 	
       
   209 	case EExampleItem2:
       
   210 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM2);
       
   211 		break;
       
   212                // Exit the application. The call is
       
   213 		       // implemented by the UI framework.
       
   214 
       
   215 	case EEikCmdExit: 
       
   216 		Exit();
       
   217 		break;
       
   218 		}
       
   219 	}
       
   220 
       
   221 ////////////////////////////////////////////////////////////////////////
       
   222 //
       
   223 // CExampleDocument
       
   224 //
       
   225 ////////////////////////////////////////////////////////////////////////
       
   226 class CExampleDocument : public CEikDocument
       
   227 	{
       
   228 public:
       
   229 	static CExampleDocument* NewL(CEikApplication& aApp);
       
   230 	CExampleDocument(CEikApplication& aApp);
       
   231 	void ConstructL();
       
   232 private: 
       
   233 	           // Inherited from CEikDocument
       
   234 	CEikAppUi* CreateAppUiL();
       
   235 	};
       
   236 
       
   237 //             The constructor of the document class just passes the
       
   238 //             supplied reference to the constructor initialisation list.
       
   239 //             The document has no real work to do in this application.
       
   240 //
       
   241 CExampleDocument::CExampleDocument(CEikApplication& aApp)
       
   242 		: CEikDocument(aApp)
       
   243 	{
       
   244 	}
       
   245 
       
   246 
       
   247 //             This is called by the UI framework as soon as the 
       
   248 //             document has been created. It creates an instance
       
   249 //             of the ApplicationUI. The Application UI class is
       
   250 //             an instance of a CEikAppUi derived class.
       
   251 //
       
   252 CEikAppUi* CExampleDocument::CreateAppUiL()
       
   253 	{
       
   254     return new(ELeave) CExampleAppUi;
       
   255 	}
       
   256 
       
   257 ////////////////////////////////////////////////////////////////////////
       
   258 //
       
   259 // CExampleApplication
       
   260 //
       
   261 ////////////////////////////////////////////////////////////////////////
       
   262 
       
   263 class CExampleApplication : public CEikApplication
       
   264 	{
       
   265 private: 
       
   266 	           // Inherited from class CApaApplication
       
   267 	CApaDocument* CreateDocumentL();
       
   268 	TUid AppDllUid() const;
       
   269 	};
       
   270 
       
   271 const TUid KUidChildII = { 0X10207f85 }; 
       
   272 
       
   273 //             The function is called by the UI framework to ask for the
       
   274 //             application's UID. The returned value is defined by the
       
   275 //             constant KUidChildIIe and must match the second value
       
   276 //             defined in the project definition file.
       
   277 // 
       
   278 TUid CExampleApplication::AppDllUid() const
       
   279 	{
       
   280 	return KUidChildII;
       
   281 	}
       
   282 
       
   283 //             This function is called by the UI framework at
       
   284 //             application start-up. It creates an instance of the
       
   285 //             document class.
       
   286 //
       
   287 CApaDocument* CExampleApplication::CreateDocumentL()
       
   288 	{
       
   289 	return new (ELeave) CExampleDocument(*this);
       
   290 	}
       
   291 
       
   292 //             The entry point for the application code. It creates
       
   293 //             an instance of the CApaApplication derived
       
   294 //             class, CExampleApplication.
       
   295 //
       
   296 
       
   297 LOCAL_C CApaApplication* NewApplication()
       
   298 	{
       
   299 	return new CExampleApplication;
       
   300 	}
       
   301 	
       
   302 GLDEF_C TInt E32Main()
       
   303 	{
       
   304 	return EikStart::RunApplication(NewApplication);
       
   305 	}