examples/HelloWorld/HelloWorld_AppView.cpp

00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // HelloWorld_CExampleAppView.cpp
00015 // Source file for the implementation of the 
00016 // application view class - CExampleAppView
00017 //
00018 
00019 #include "HelloWorld.h"
00020 
00021 //
00022 //             Constructor for the view.
00023 //
00024 CExampleAppView::CExampleAppView()
00025         {
00026         }
00027 
00028 
00029 //             Static NewL() function to start the standard two
00030 //             phase construction.
00031 //
00032 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
00033         {
00034         CExampleAppView* self = new(ELeave) CExampleAppView();
00035         CleanupStack::PushL(self);
00036         self->ConstructL(aRect);
00037         CleanupStack::Pop();
00038         return self;
00039         }
00040 
00041 
00042 //
00043 //             Destructor for the view.
00044 //
00045 CExampleAppView::~CExampleAppView()
00046         {
00047         delete iExampleText;
00048         }
00049 
00050 
00051 //             Second phase construction.
00052 //
00053 void CExampleAppView::ConstructL(const TRect& aRect)
00054     {
00055                            // Fetch the text from the resource file.
00056         iExampleText = iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_HELLO);
00057                    // Control is a window owning control
00058         CreateWindowL();
00059                    // Extent of the control. This is
00060                    // the whole rectangle available to application.
00061                    // The rectangle is passed to us from the application UI.
00062         SetRect(aRect);
00063                            // At this stage, the control is ready to draw so
00064                    // we tell the UI framework by activating it.
00065         ActivateL();
00066         }
00067 
00068 
00069 //             Drawing the view - in this example, 
00070 //             consists of drawing a simple outline rectangle
00071 //             and then drawing the text in the middle.
00072 //             We use the Normal font supplied by the UI.
00073 //
00074 //             In this example, we don't use the redraw
00075 //             region because it's easier to redraw to
00076 //             the whole client area.
00077 //
00078 void CExampleAppView::Draw(const TRect& /*aRect*/) const
00079         {
00080                // Window graphics context
00081         CWindowGc& gc = SystemGc();
00082                    // Area in which we shall draw
00083         TRect      drawRect = Rect();
00084                            // Font used for drawing text
00085         const CFont*     fontUsed;
00086         
00087                    // Start with a clear screen
00088         gc.Clear();
00089                            // Draw an outline rectangle (the default pen
00090                    // and brush styles ensure this) slightly
00091                    // smaller than the drawing area.
00092         drawRect.Shrink(10,10);                 
00093         gc.DrawRect(drawRect);
00094                // Use the title font supplied by the UI
00095         fontUsed = iEikonEnv->TitleFont();
00096         gc.UseFont(fontUsed);
00097                            // Draw the text in the middle of the rectangle.
00098         TInt   baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
00099         gc.DrawText(*iExampleText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
00100                // Finished using the font
00101         gc.DiscardFont();
00102         }
00103 
00104 
00105 

Generated by  doxygen 1.6.2