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