|
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 // @file |
|
15 // @internalComponent - Internal Symbian test code |
|
16 // test code for the message-window class |
|
17 // $Workfile: TMSGWIN0.CPP $ |
|
18 // $Revision: 1.6 $ |
|
19 // $Author: DougF $ |
|
20 // $Date: 07 Jul 1999 16:16:30 $ |
|
21 // |
|
22 // |
|
23 |
|
24 #include <e32keys.h> |
|
25 #include <coemain.h> |
|
26 #include <coedef.h> |
|
27 #include <coeaui.h> |
|
28 #include <coecntrl.h> |
|
29 #include <clock.h> |
|
30 #include <basched.h> |
|
31 |
|
32 |
|
33 #include "TMsgWin0Step.h" |
|
34 |
|
35 // enums |
|
36 |
|
37 // CClkMsgWinControl |
|
38 |
|
39 CClkMsgWinControl::CClkMsgWinControl() |
|
40 :iBackgroundColor(85, 85, 85), |
|
41 iAnimDll(iCoeEnv->WsSession()), |
|
42 iCounter(0) |
|
43 { |
|
44 __DECLARE_NAME(_S("CClkMsgWinControl")); |
|
45 |
|
46 __ASSERT_DEBUG(iMessageWindow==NULL, User::Panic(_L("Clock test-code"), 1)); |
|
47 } |
|
48 |
|
49 void CClkMsgWinControl::ConstructL() |
|
50 { |
|
51 CreateWindowL(); |
|
52 EnableDragEvents(); |
|
53 RWindow& window=Window(); |
|
54 window.SetPointerGrab(ETrue); |
|
55 window.SetBackgroundColor(iBackgroundColor); |
|
56 window.SetShadowHeight(8); |
|
57 User::LeaveIfError(iAnimDll.Load(_L("CLOCKA.DLL"))); |
|
58 TFontSpec fontSpec(_L("arial"), iCoeEnv->ScreenDevice()->VerticalPixelsToTwips(25)); |
|
59 User::LeaveIfError(iCoeEnv->ScreenDevice()->GetNearestFontInTwips((CFont*&)iFont, fontSpec)); |
|
60 iDummy=new(ELeave) CCoeControl; |
|
61 iDummy->SetNonFocusing(); |
|
62 iBlankWindow=new(ELeave) RBlankWindow(iCoeEnv->WsSession()); |
|
63 User::LeaveIfError(iBlankWindow->Construct(iCoeEnv->RootWin(), (TUint32)iDummy)); |
|
64 iMessageWindow=new(ELeave) RMessageWindow(iAnimDll, *iBlankWindow); |
|
65 iMessageWindow->ConstructL(EGapAboveMessageWindowText+iFont->AscentInPixels(), iFont->Handle(), TRgb(0, 0, 0), TRgb(255, 255, 255)); |
|
66 SetExtent(TPoint(10, 10), TSize(100, 100)); |
|
67 iBlankWindow->Activate(); |
|
68 ActivateL(); |
|
69 } |
|
70 |
|
71 CClkMsgWinControl::~CClkMsgWinControl() |
|
72 { |
|
73 iCoeEnv->ScreenDevice()->ReleaseFont(iFont); // N.B. do not need to do "delete iFont" |
|
74 if (iMessageWindow!=NULL) |
|
75 iMessageWindow->Destroy(); |
|
76 if (iBlankWindow!=NULL) |
|
77 iBlankWindow->Destroy(); |
|
78 delete iDummy; |
|
79 iAnimDll.Close(); |
|
80 } |
|
81 |
|
82 TKeyResponse CClkMsgWinControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
83 { |
|
84 if (aType==EEventKey) |
|
85 { |
|
86 switch (aKeyEvent.iCode) |
|
87 { |
|
88 case CTRL('e'): |
|
89 iCoeEnv->Flush(); |
|
90 CBaActiveScheduler::Exit(); |
|
91 break; |
|
92 case EKeyBackspace: |
|
93 case EKeyDelete: |
|
94 iMessageWindow->CancelDisplay(); |
|
95 break; |
|
96 case EKeyLineFeed: |
|
97 case EKeyEnter: |
|
98 { |
|
99 TBuf<64> text; |
|
100 TInt initialDelay=(aKeyEvent.iModifiers&EModifierRightShift)? 1*1000000: 0; |
|
101 TBool flash=(aKeyEvent.iModifiers&EModifierLeftShift); |
|
102 if (aKeyEvent.iModifiers&EModifierCtrl) |
|
103 { |
|
104 text.Format(_L("Counter=%d"), iCounter++); |
|
105 iBlankWindow->SetExtent(TPoint(50, 50), WindowSize(*iFont, text)); |
|
106 iMessageWindow->StartDisplay(flash, initialDelay, text); |
|
107 } |
|
108 else |
|
109 { |
|
110 text.Format(_L("Counter=%d, duration=5"), iCounter++); |
|
111 iBlankWindow->SetExtent(TPoint(50, 50), WindowSize(*iFont, text)); |
|
112 iMessageWindow->StartDisplay(flash, initialDelay, 5*1000000, text); |
|
113 } |
|
114 } |
|
115 break; |
|
116 } |
|
117 } |
|
118 |
|
119 return EKeyWasNotConsumed; |
|
120 } |
|
121 |
|
122 void CClkMsgWinControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
123 { |
|
124 RWindow& window=Window(); |
|
125 switch (aPointerEvent.iType) |
|
126 { |
|
127 case TPointerEvent::EButton1Down: |
|
128 iCoeEnv->RootWin().SetOrdinalPosition(0); |
|
129 window.SetOrdinalPosition(0); |
|
130 iPointerOffset=aPointerEvent.iPosition; |
|
131 break; |
|
132 case TPointerEvent::EDrag: |
|
133 SetPosition(aPointerEvent.iParentPosition-iPointerOffset); |
|
134 break; |
|
135 case TPointerEvent::EButton1Up: |
|
136 window.SetOrdinalPosition(1000); |
|
137 iPointerOffset.SetXY(0, 0); |
|
138 break; |
|
139 default: |
|
140 break; |
|
141 } |
|
142 } |
|
143 |
|
144 void CClkMsgWinControl::Draw(const TRect&) const |
|
145 { |
|
146 CGraphicsContext& systemGc=SystemGc(); |
|
147 systemGc.SetPenStyle(CGraphicsContext::ENullPen); |
|
148 systemGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
149 systemGc.SetBrushColor(iBackgroundColor); |
|
150 systemGc.DrawRect(Rect()); |
|
151 } |
|
152 |
|
153 TSize CClkMsgWinControl::WindowSize(const CFbsFont& aFont, const TDesC& aText) const |
|
154 { |
|
155 TMargins borders; |
|
156 iMessageWindow->GetBorders(borders); |
|
157 __ASSERT_ALWAYS(borders.iLeft==3 && |
|
158 borders.iRight==4 && |
|
159 borders.iTop==3 && |
|
160 borders.iBottom==4, User::Panic(_L("Clock test-code"), 2)); |
|
161 return TSize(borders.iLeft+borders.iRight+EGapLeftOfMessageWindowText+EGapRightOfMessageWindowText+aFont.TextWidthInPixels(aText), |
|
162 borders.iTop+borders.iBottom+EGapAboveMessageWindowText+EGapBelowMessageWindowText+aFont.HeightInPixels()); |
|
163 } |
|
164 |
|
165 // |
|
166 |
|
167 CTMsgWinTestAppUi::CTMsgWinTestAppUi(CTmsTestStep* aStep) : |
|
168 CTestCoeAppUi(aStep) |
|
169 {} |
|
170 |
|
171 |
|
172 void CTMsgWinTestAppUi::ConstructL() |
|
173 { |
|
174 CTestCoeAppUi::ConstructL(); |
|
175 iControl=new(ELeave) CClkMsgWinControl; |
|
176 AddToStackL(iControl,ECoeStackPriorityDefault,ECoeStackFlagOwnershipTransfered); |
|
177 iControl->ConstructL(); |
|
178 |
|
179 AutoTestManager().StartAutoTest(); |
|
180 |
|
181 } |
|
182 |
|
183 /** |
|
184 @SYMTestCaseID UIF-Clock-TMsgWin |
|
185 */ |
|
186 |
|
187 void CTMsgWinTestAppUi::RunTestStepL(TInt aStep) |
|
188 { |
|
189 TKeyEvent theKeyEvent; |
|
190 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
191 |
|
192 switch(aStep) |
|
193 { |
|
194 case 1: |
|
195 SetTestStepID(_L("UIF-Clock-TMsgWin")); |
|
196 case 2: case 3: case 4: |
|
197 theKeyEvent.iCode = EKeyEnter; |
|
198 theKeyEvent.iModifiers = 0; |
|
199 INFO_PRINTF1(_L("Start display counter window with duration")); |
|
200 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
201 break; |
|
202 case 5: |
|
203 theKeyEvent.iCode = EKeyDelete; |
|
204 INFO_PRINTF1(_L("Close counter window")); |
|
205 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
206 break; |
|
207 case 6: case 7: case 8: case 9: //flashing |
|
208 theKeyEvent.iCode = EKeyEnter; |
|
209 theKeyEvent.iModifiers = EModifierLeftShift; |
|
210 INFO_PRINTF1(_L("Flashing display counter window with duration")); |
|
211 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
212 break; |
|
213 case 10: |
|
214 theKeyEvent.iCode = EKeyDelete; |
|
215 INFO_PRINTF1(_L("Close counter window")); |
|
216 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
217 break; |
|
218 |
|
219 case 11: case 12: |
|
220 theKeyEvent.iCode = EKeyEnter; |
|
221 theKeyEvent.iModifiers = EModifierCtrl; |
|
222 INFO_PRINTF1(_L("Start display counter window")); |
|
223 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
224 break; |
|
225 case 13: |
|
226 theKeyEvent.iCode = EKeyDelete; |
|
227 INFO_PRINTF1(_L("Close counter window")); |
|
228 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
229 break; |
|
230 case 14: case 15: //flashing |
|
231 theKeyEvent.iCode = EKeyEnter; |
|
232 INFO_PRINTF1(_L("Flashing display counter window")); |
|
233 theKeyEvent.iModifiers = EModifierLeftShift | EModifierCtrl; |
|
234 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
235 break; |
|
236 case 16: |
|
237 theKeyEvent.iCode = EKeyDelete; |
|
238 INFO_PRINTF1(_L("Close counter window")); |
|
239 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
240 break; |
|
241 case 17: |
|
242 theKeyEvent.iCode = CTRL('e'); |
|
243 iControl->OfferKeyEventL(theKeyEvent, EEventKey); |
|
244 RecordTestResultL(); |
|
245 CloseTMSGraphicsStep(); |
|
246 break; |
|
247 } |
|
248 } |
|
249 |
|
250 //--------- |
|
251 void CTMsgWin0Step::ConstructAppL(CCoeEnv* aCoe) |
|
252 { // runs inside a TRAP harness |
|
253 aCoe->ConstructL(); |
|
254 CTMsgWinTestAppUi* appUi= new (ELeave) CTMsgWinTestAppUi(this); |
|
255 aCoe->SetAppUi(appUi); |
|
256 appUi->ConstructL(); |
|
257 } |
|
258 |
|
259 CTMsgWin0Step::~CTMsgWin0Step() |
|
260 /** |
|
261 Destructor |
|
262 */ |
|
263 { |
|
264 } |
|
265 |
|
266 CTMsgWin0Step::CTMsgWin0Step() |
|
267 /** |
|
268 Constructor |
|
269 */ |
|
270 { |
|
271 // Call base class method to set up the human readable name for logging |
|
272 SetTestStepName(KTMsgWin0Step); |
|
273 } |
|
274 |
|
275 |
|
276 TVerdict CTMsgWin0Step::doTestStepL() // main function called by E32 |
|
277 { |
|
278 PreallocateHALBuffer(); |
|
279 |
|
280 __UHEAP_MARK; |
|
281 |
|
282 INFO_PRINTF1(_L("Test Started")); |
|
283 CCoeEnv* coe=new CCoeEnv; |
|
284 TRAPD(err,ConstructAppL(coe)); |
|
285 |
|
286 if (!err) |
|
287 coe->ExecuteD(); |
|
288 |
|
289 __UHEAP_MARKEND; |
|
290 |
|
291 INFO_PRINTF1(_L("Test Finished")); |
|
292 |
|
293 return TestStepResult(); |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 |