localisation/apparchitecture/tef/ParentProcess_Main.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     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 "Parent Process !" 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 <ParentProcess.rsg>
       
    37 #include "ParentProcess.hrh"
       
    38 
       
    39 ////////////////////////////////////////////////////////////////////////
       
    40 //
       
    41 // CExampleAppView
       
    42 //										
       
    43 ////////////////////////////////////////////////////////////////////////
       
    44 
       
    45 class CExampleAppView : public CCoeControl
       
    46     {
       
    47 public:
       
    48 	static CExampleAppView* NewL(const TRect& aRect);
       
    49 	CExampleAppView();
       
    50 	~CExampleAppView();
       
    51     void ConstructL(const TRect& aRect);
       
    52 
       
    53 private:
       
    54 	           // Inherited from CCoeControl
       
    55 	void Draw(const TRect& /*aRect*/) const;
       
    56 
       
    57 private:
       
    58 	HBufC*  iExampleText;
       
    59     };
       
    60     
       
    61 //
       
    62 //             Constructor for the view.
       
    63 //
       
    64 CExampleAppView::CExampleAppView()
       
    65 	{
       
    66 	}
       
    67 
       
    68 
       
    69 //             Static NewL() function to start the standard two
       
    70 //             phase construction.
       
    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 
       
    82 //
       
    83 //             Destructor for the view.
       
    84 //
       
    85 CExampleAppView::~CExampleAppView()
       
    86 	{
       
    87 	delete iExampleText;
       
    88 	}
       
    89 
       
    90 
       
    91 //             Second phase construction.
       
    92 //
       
    93 void CExampleAppView::ConstructL(const TRect& aRect)
       
    94     {
       
    95 			   // Fetch the text from the resource file.
       
    96 	iExampleText = iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_PARENTPROC);
       
    97 	           // Control is a window owning control
       
    98 	CreateWindowL();
       
    99 	           // Extent of the control. This is
       
   100 	           // the whole rectangle available to application.
       
   101 	           // The rectangle is passed to us from the application UI.
       
   102 	SetRect(aRect);
       
   103 			   // At this stage, the control is ready to draw so
       
   104 	           // we tell the UI framework by activating it.
       
   105 	ActivateL();
       
   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 
       
   150 class CExampleAppUi : public CEikAppUi
       
   151     {
       
   152 public:
       
   153     void ConstructL();
       
   154 	~CExampleAppUi();
       
   155 
       
   156 private:
       
   157               // Inherirted from class CEikAppUi
       
   158 	void HandleCommandL(TInt aCommand);
       
   159 
       
   160 private:
       
   161 	CCoeControl* iAppView;
       
   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 "Parent Process !", 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 
       
   251 //             This is called by the UI framework as soon as the 
       
   252 //             document has been created. It creates an instance
       
   253 //             of the ApplicationUI. The Application UI class is
       
   254 //             an instance of a CEikAppUi derived class.
       
   255 //
       
   256 CEikAppUi* CExampleDocument::CreateAppUiL()
       
   257 	{
       
   258     return new(ELeave) CExampleAppUi;
       
   259 	}
       
   260 
       
   261 ////////////////////////////////////////////////////////////////////////
       
   262 //
       
   263 // CExampleApplication
       
   264 //
       
   265 ////////////////////////////////////////////////////////////////////////
       
   266 
       
   267 class CExampleApplication : public CEikApplication
       
   268 	{
       
   269 private: 
       
   270 	           // Inherited from class CApaApplication
       
   271 	CApaDocument* CreateDocumentL();
       
   272 	TUid AppDllUid() const;
       
   273 	};
       
   274 
       
   275 //             The entry point for the application code. It creates
       
   276 //             an instance of the CApaApplication derived
       
   277 //             class, CExampleApplication.
       
   278 //
       
   279 
       
   280 const TUid KUidParentProcess = { 0x10207f87 }; 
       
   281 
       
   282 //             The function is called by the UI framework to ask for the
       
   283 //             application's UID. The returned value is defined by the
       
   284 //             constant KUidParentProcess and must match the second value
       
   285 //             defined in the project definition file.
       
   286 // 
       
   287 TUid CExampleApplication::AppDllUid() const
       
   288 	{
       
   289 	return KUidParentProcess;
       
   290 	}
       
   291 
       
   292 //             This function is called by the UI framework at
       
   293 //             application start-up. It creates an instance of the
       
   294 //             document class.
       
   295 //
       
   296 CApaDocument* CExampleApplication::CreateDocumentL()
       
   297 	{
       
   298 	return new (ELeave) CExampleDocument(*this);
       
   299 	}
       
   300 
       
   301 LOCAL_C CApaApplication* NewApplication()
       
   302 	{
       
   303 	return new CExampleApplication;
       
   304 	}
       
   305 	
       
   306 GLDEF_C TInt E32Main()
       
   307 	{
       
   308 	return EikStart::RunApplication(NewApplication);
       
   309 	}