|
1 /* |
|
2 * Copyright (c) 1997-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "Tgb18030.h" |
|
20 #include <barsread.h> |
|
21 // |
|
22 // Constructor for the view. |
|
23 // |
|
24 CTgb18030AppView::CTgb18030AppView() |
|
25 { |
|
26 } |
|
27 |
|
28 |
|
29 // Static NewL() function to start the standard two |
|
30 // phase construction. |
|
31 // |
|
32 CTgb18030AppView* CTgb18030AppView::NewL(const TRect& aRect) |
|
33 { |
|
34 CTgb18030AppView* self = new(ELeave) CTgb18030AppView(); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(aRect); |
|
37 CleanupStack::Pop(); |
|
38 return self; |
|
39 } |
|
40 |
|
41 |
|
42 // |
|
43 // Destructor for the view. |
|
44 // |
|
45 CTgb18030AppView::~CTgb18030AppView() |
|
46 { |
|
47 delete iTgb18030Text; |
|
48 delete iRcompTestText; |
|
49 delete iEditor; |
|
50 } |
|
51 |
|
52 |
|
53 // Second phase construction. |
|
54 // |
|
55 void CTgb18030AppView::ConstructL(const TRect& aRect) |
|
56 { |
|
57 // Fetch the text from the resource file. |
|
58 iTgb18030Text = iEikonEnv->AllocReadResourceL(R_TGB18030_TEXT_HELLO); |
|
59 iRcompTestText = iEikonEnv->AllocReadResourceL(R_TRCOMP_TEXT_POS1); |
|
60 |
|
61 // Control is a window owning control |
|
62 CreateWindowL(); |
|
63 // Extent of the control. This is |
|
64 // the whole rectangle available to application. |
|
65 // The rectangle is passed to us from the application UI. |
|
66 |
|
67 TResourceReader reader; |
|
68 iCoeEnv->CreateResourceReaderLC( reader, R_OUTPUT_VIEW_RTEXTED ); |
|
69 iEditor = new ( ELeave ) CEikRichTextEditor(); |
|
70 |
|
71 iEditor->SetContainerWindowL( *this ); |
|
72 iEditor->ConstructFromResourceL( reader ); |
|
73 CleanupStack::PopAndDestroy(); // Resource reader |
|
74 iEditor->SetFocus( ETrue ); |
|
75 |
|
76 iEditor->SetExtent( TPoint( 0, 0 ), |
|
77 TSize( aRect.Width(), aRect.Height() ) ); |
|
78 |
|
79 iEditor->CreateScrollBarFrameL(); |
|
80 iEditor->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EOn); |
|
81 iEditor->ScrollBarFrame()->DrawScrollBarsNow(); |
|
82 iEditor->SetTextL( iTgb18030Text ); |
|
83 |
|
84 |
|
85 |
|
86 SetRect(aRect); |
|
87 |
|
88 iEditor->DrawNow(); |
|
89 // At this stage, the control is ready to draw so |
|
90 // we tell the UI framework by activating it. |
|
91 ActivateL(); |
|
92 } |
|
93 |
|
94 void CTgb18030AppView::ChangeEditorText() |
|
95 { |
|
96 iEditor->SetTextL(iRcompTestText); |
|
97 iEditor->DrawNow(); |
|
98 } |
|
99 |
|
100 TKeyResponse CTgb18030AppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
101 { |
|
102 if (iEditor) |
|
103 return iEditor->OfferKeyEventL (aKeyEvent, aType); |
|
104 else |
|
105 return EKeyWasNotConsumed; |
|
106 } |
|
107 |
|
108 CCoeControl* CTgb18030AppView::ComponentControl(TInt aIndex) const |
|
109 { |
|
110 switch (aIndex) |
|
111 { |
|
112 case 0: |
|
113 return iEditor; |
|
114 |
|
115 default: |
|
116 return NULL; |
|
117 } |
|
118 } |
|
119 |
|
120 void CTgb18030AppView::SizeChanged() |
|
121 { |
|
122 } |
|
123 |
|
124 TInt CTgb18030AppView::CountComponentControls() const |
|
125 { |
|
126 return 1; // return number of controls inside this container |
|
127 } |
|
128 |
|
129 void CTgb18030AppView::Draw(const TRect& /*aRect*/) const |
|
130 { |
|
131 // Window graphics context |
|
132 CWindowGc& gc = SystemGc(); |
|
133 // Area in which we shall draw |
|
134 TRect drawRect = Rect(); |
|
135 // Font used for drawing text |
|
136 const CFont* fontUsed; |
|
137 |
|
138 // Start with a clear screen |
|
139 gc.Clear(); |
|
140 // Draw an outline rectangle (the default pen |
|
141 // and brush styles ensure this) slightly |
|
142 // smaller than the drawing area. |
|
143 drawRect.Shrink(10,10); |
|
144 gc.DrawRect(drawRect); |
|
145 // Use the title font supplied by the UI |
|
146 fontUsed = iEikonEnv->TitleFont(); |
|
147 gc.UseFont(fontUsed); |
|
148 // Draw the text in the middle of the rectangle. |
|
149 TInt baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; |
|
150 gc.DrawText(*iTgb18030Text,drawRect,baselineOffset,CGraphicsContext::ECenter, 0); |
|
151 // Finished using the font |
|
152 |
|
153 gc.DiscardFont(); |
|
154 } |
|
155 |
|
156 |
|
157 |