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