591
|
1 |
/*
|
|
2 |
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
* HelloWorld_CExampleAppView.cpp
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
#include "HelloWorld.h"
|
|
21 |
|
|
22 |
//
|
|
23 |
// Constructor for the view.
|
|
24 |
//
|
|
25 |
CExampleAppView::CExampleAppView()
|
|
26 |
{
|
|
27 |
}
|
|
28 |
|
|
29 |
|
|
30 |
// Static NewL() function to start the standard two
|
|
31 |
// phase construction.
|
|
32 |
//
|
|
33 |
CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
|
|
34 |
{
|
|
35 |
CExampleAppView* self = new(ELeave) CExampleAppView();
|
|
36 |
CleanupStack::PushL(self);
|
|
37 |
self->ConstructL(aRect);
|
|
38 |
CleanupStack::Pop();
|
|
39 |
return self;
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
//
|
|
44 |
// Destructor for the view.
|
|
45 |
//
|
|
46 |
CExampleAppView::~CExampleAppView()
|
|
47 |
{
|
|
48 |
delete iExampleText;
|
|
49 |
}
|
|
50 |
|
|
51 |
|
|
52 |
// Second phase construction.
|
|
53 |
//
|
|
54 |
void CExampleAppView::ConstructL(const TRect& aRect)
|
|
55 |
{
|
|
56 |
// Fetch the text from the resource file.
|
|
57 |
iExampleText = iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_HELLO);
|
|
58 |
// Control is a window owning control
|
|
59 |
CreateWindowL();
|
|
60 |
// Extent of the control. This is
|
|
61 |
// the whole rectangle available to application.
|
|
62 |
// The rectangle is passed to us from the application UI.
|
|
63 |
SetRect(aRect);
|
|
64 |
// At this stage, the control is ready to draw so
|
|
65 |
// we tell the UI framework by activating it.
|
|
66 |
ActivateL();
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
// Drawing the view - in this example,
|
|
71 |
// consists of drawing a simple outline rectangle
|
|
72 |
// and then drawing the text in the middle.
|
|
73 |
// We use the Normal font supplied by the UI.
|
|
74 |
//
|
|
75 |
// In this example, we don't use the redraw
|
|
76 |
// region because it's easier to redraw to
|
|
77 |
// the whole client area.
|
|
78 |
//
|
|
79 |
void CExampleAppView::Draw(const TRect& /*aRect*/) const
|
|
80 |
{
|
|
81 |
// Window graphics context
|
|
82 |
CWindowGc& gc = SystemGc();
|
|
83 |
// Area in which we shall draw
|
|
84 |
TRect drawRect = Rect();
|
|
85 |
// Font used for drawing text
|
|
86 |
const CFont* fontUsed;
|
|
87 |
|
|
88 |
// Start with a clear screen
|
|
89 |
gc.Clear();
|
|
90 |
// Draw an outline rectangle (the default pen
|
|
91 |
// and brush styles ensure this) slightly
|
|
92 |
// smaller than the drawing area.
|
|
93 |
drawRect.Shrink(10,10);
|
|
94 |
gc.DrawRect(drawRect);
|
|
95 |
// Use the title font supplied by the UI
|
|
96 |
fontUsed = iEikonEnv->TitleFont();
|
|
97 |
gc.UseFont(fontUsed);
|
|
98 |
// Draw the text in the middle of the rectangle.
|
|
99 |
TInt baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2;
|
|
100 |
gc.DrawText(*iExampleText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
|
|
101 |
// Finished using the font
|
|
102 |
gc.DiscardFont();
|
|
103 |
}
|
|
104 |
|
|
105 |
|
|
106 |
|