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