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