sl@0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Test modifier changed message
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32std.h>
|
sl@0
|
19 |
#include <e32svr.h>
|
sl@0
|
20 |
#include "W32STD.H"
|
sl@0
|
21 |
#include "../tlib/testbase.h"
|
sl@0
|
22 |
#include "TMAN.H"
|
sl@0
|
23 |
|
sl@0
|
24 |
class CTModifiersChangedTest;
|
sl@0
|
25 |
|
sl@0
|
26 |
class CMCWindow : public CTWin
|
sl@0
|
27 |
{
|
sl@0
|
28 |
public:
|
sl@0
|
29 |
CMCWindow(CTModifiersChangedTest *aTest);
|
sl@0
|
30 |
void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
|
sl@0
|
31 |
void Draw();
|
sl@0
|
32 |
void DrawModSetLine(const TDesC &aDes,TInt aModifier,TInt iSettableModifiers);
|
sl@0
|
33 |
protected:
|
sl@0
|
34 |
CTModifiersChangedTest *iTest;
|
sl@0
|
35 |
TRgb iBack;
|
sl@0
|
36 |
TInt iLineHeight;
|
sl@0
|
37 |
TInt iFontAscent;
|
sl@0
|
38 |
TInt iYpos;
|
sl@0
|
39 |
TInt iXpos1;
|
sl@0
|
40 |
TInt iXpos2;
|
sl@0
|
41 |
};
|
sl@0
|
42 |
|
sl@0
|
43 |
class CTEventWindowGroup : public CTWindowGroup
|
sl@0
|
44 |
{
|
sl@0
|
45 |
public:
|
sl@0
|
46 |
CTEventWindowGroup(CTClient *aClient, CTModifiersChangedTest *iTest);
|
sl@0
|
47 |
void ConstructL();
|
sl@0
|
48 |
void ModifiersChanged(const TModifiersChangedEvent &aModifiersChanged ,const TTime &aTime);
|
sl@0
|
49 |
void KeyL(const TKeyEvent &aKey,const TTime &aTime);
|
sl@0
|
50 |
private:
|
sl@0
|
51 |
CTModifiersChangedTest *iTest;
|
sl@0
|
52 |
};
|
sl@0
|
53 |
|
sl@0
|
54 |
class CTModifiersChangedTest : public CTestBase
|
sl@0
|
55 |
{
|
sl@0
|
56 |
public:
|
sl@0
|
57 |
CTModifiersChangedTest();
|
sl@0
|
58 |
~CTModifiersChangedTest();
|
sl@0
|
59 |
TestState DoTestL();
|
sl@0
|
60 |
void ConstructL();
|
sl@0
|
61 |
void EndTest();
|
sl@0
|
62 |
TInt SubState() const;
|
sl@0
|
63 |
void IncSubState();
|
sl@0
|
64 |
void BadParams();
|
sl@0
|
65 |
void ModifierChangedEventsL();
|
sl@0
|
66 |
void SetModifiersL();
|
sl@0
|
67 |
void CheckModifierL(TEventModifier aModifier);
|
sl@0
|
68 |
public:
|
sl@0
|
69 |
TBool iModSetTest;
|
sl@0
|
70 |
TInt iSettable;
|
sl@0
|
71 |
private:
|
sl@0
|
72 |
TSize iWinSize;
|
sl@0
|
73 |
TInt iState;
|
sl@0
|
74 |
TInt iSubState;
|
sl@0
|
75 |
CTEventWindowGroup *iEventGroup;
|
sl@0
|
76 |
CMCWindow *iWin;
|
sl@0
|
77 |
};
|
sl@0
|
78 |
|
sl@0
|
79 |
struct TModifierChangedTestsParams
|
sl@0
|
80 |
{
|
sl@0
|
81 |
TText *txt; // Text message telling user what to do
|
sl@0
|
82 |
TUint changed;
|
sl@0
|
83 |
TUint state;
|
sl@0
|
84 |
TUint stateMask;
|
sl@0
|
85 |
};
|
sl@0
|
86 |
|
sl@0
|
87 |
LOCAL_D TModifierChangedTestsParams ModifierChangedTests[]={
|
sl@0
|
88 |
#if defined(__WINS__)
|
sl@0
|
89 |
{(TText *)_S("Press Caps"),EModifierCapsLock,EModifierCapsLock,EModifierCapsLock},
|
sl@0
|
90 |
{(TText *)_S("Press Caps (again)"),EModifierCapsLock,0,EModifierCapsLock},
|
sl@0
|
91 |
#endif
|
sl@0
|
92 |
{(TText *)_S("Press left shift"),EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift},
|
sl@0
|
93 |
{(TText *)_S("Release left shift"),EModifierShift|EModifierLeftShift,0,EModifierShift|EModifierLeftShift},
|
sl@0
|
94 |
{(TText *)_S("Press right shift"),EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift},
|
sl@0
|
95 |
{(TText *)_S("Release right shift"),EModifierShift|EModifierRightShift,0,EModifierShift|EModifierRightShift},
|
sl@0
|
96 |
{(TText *)_S("Press (left) func"),EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc},
|
sl@0
|
97 |
{(TText *)_S("Release (left) func"),EModifierFunc|EModifierLeftFunc,0,EModifierFunc|EModifierLeftFunc},
|
sl@0
|
98 |
{(TText *)_S("Press (left) control"),EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl},
|
sl@0
|
99 |
{(TText *)_S("Release (left) control"),EModifierCtrl|EModifierLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl},
|
sl@0
|
100 |
};
|
sl@0
|
101 |
|
sl@0
|
102 |
const TInt numTests=sizeof(ModifierChangedTests)/sizeof(ModifierChangedTests[0]);
|
sl@0
|
103 |
|
sl@0
|
104 |
GLDEF_C CTestBase *CreateModifiersChangedTest()
|
sl@0
|
105 |
{
|
sl@0
|
106 |
return(new(ELeave) CTModifiersChangedTest());
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
//
|
sl@0
|
110 |
// CTEventWindowGroup class //
|
sl@0
|
111 |
//
|
sl@0
|
112 |
|
sl@0
|
113 |
CTEventWindowGroup::CTEventWindowGroup(CTClient *aClient, CTModifiersChangedTest *aTest) : CTWindowGroup(aClient), iTest(aTest)
|
sl@0
|
114 |
{}
|
sl@0
|
115 |
|
sl@0
|
116 |
void CTEventWindowGroup::ConstructL()
|
sl@0
|
117 |
{
|
sl@0
|
118 |
CTWindowGroup::ConstructL();
|
sl@0
|
119 |
iGroupWin.EnableModifierChangedEvents(EModifierShift|EModifierLeftShift|EModifierRightShift|EModifierCapsLock|
|
sl@0
|
120 |
EModifierFunc|EModifierLeftFunc|EModifierCtrl|EModifierLeftCtrl,EEventControlAlways);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
void CTEventWindowGroup::ModifiersChanged(const TModifiersChangedEvent &aModifiersChanged ,const TTime &)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
TInt ss=iTest->SubState();
|
sl@0
|
126 |
TInt getMods=Client()->iWs.GetModifierState(); // Double check the mods with get mods
|
sl@0
|
127 |
if (aModifiersChanged.iChangedModifiers==ModifierChangedTests[ss].changed &&
|
sl@0
|
128 |
(aModifiersChanged.iModifiers&ModifierChangedTests[ss].stateMask)==ModifierChangedTests[ss].state &&
|
sl@0
|
129 |
(getMods&ModifierChangedTests[ss].stateMask)==ModifierChangedTests[ss].state)
|
sl@0
|
130 |
iTest->IncSubState();
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
void CTEventWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
if (aKey.iCode==EKeyEscape || (aKey.iCode==' ' && iTest->iModSetTest))
|
sl@0
|
136 |
iTest->EndTest();
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
//
|
sl@0
|
140 |
// CMCWindow, class //
|
sl@0
|
141 |
//
|
sl@0
|
142 |
|
sl@0
|
143 |
CMCWindow::CMCWindow(CTModifiersChangedTest *aTest) : CTWin(), iTest(aTest)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
iBack=TRgb::Gray256(230);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
void CMCWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
ConstructExtLD(*parent,pos,size);
|
sl@0
|
151 |
iWin.SetBackgroundColor(iBack);
|
sl@0
|
152 |
Activate();
|
sl@0
|
153 |
AssignGC(aGc);
|
sl@0
|
154 |
iLineHeight=iFont->HeightInPixels()*5/4;
|
sl@0
|
155 |
iFontAscent=iFont->AscentInPixels();
|
sl@0
|
156 |
iXpos1=4;
|
sl@0
|
157 |
iXpos2=iXpos1+12*iFont->TextWidthInPixels(_L("M"));
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
void CMCWindow::DrawModSetLine(const TDesC &aDes,TInt aModifier,TInt iSettableModifiers)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
iYpos+=iLineHeight;
|
sl@0
|
163 |
iGc->DrawText(aDes, TPoint(iXpos1,iYpos));
|
sl@0
|
164 |
iGc->DrawText(aModifier&iSettableModifiers ? _L("Yes"):_L("No"), TPoint(iXpos2,iYpos));
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
void CMCWindow::Draw()
|
sl@0
|
168 |
{
|
sl@0
|
169 |
iGc->Clear();
|
sl@0
|
170 |
if (iTest->iModSetTest)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
iYpos=iFontAscent+3;
|
sl@0
|
173 |
TBuf<32> buf;
|
sl@0
|
174 |
buf.Format(TRefByValue<const TDesC>(_L("Settable? [0x%4x]")), iTest->iSettable);
|
sl@0
|
175 |
iGc->DrawText(_L("Modifier"), TPoint(iXpos1,iYpos));
|
sl@0
|
176 |
iGc->DrawText(buf, TPoint(iXpos2,iYpos));
|
sl@0
|
177 |
DrawModSetLine(_L("Shift"),EModifierShift,iTest->iSettable);
|
sl@0
|
178 |
DrawModSetLine(_L("Left Shift"),EModifierLeftShift,iTest->iSettable);
|
sl@0
|
179 |
DrawModSetLine(_L("Func"),EModifierFunc,iTest->iSettable);
|
sl@0
|
180 |
DrawModSetLine(_L("Caps"),EModifierCapsLock,iTest->iSettable);
|
sl@0
|
181 |
DrawModSetLine(_L("NumLock"),EModifierNumLock,iTest->iSettable);
|
sl@0
|
182 |
DrawModSetLine(_L("Double Click"),EModifierDoubleClick,iTest->iSettable);
|
sl@0
|
183 |
}
|
sl@0
|
184 |
else
|
sl@0
|
185 |
iGc->DrawText(TPtrC(ModifierChangedTests[iTest->SubState()].txt), TPoint(10,20));
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
//
|
sl@0
|
189 |
|
sl@0
|
190 |
CTModifiersChangedTest::CTModifiersChangedTest() : CTestBase(_L("Capture Key"))
|
sl@0
|
191 |
{}
|
sl@0
|
192 |
|
sl@0
|
193 |
CTModifiersChangedTest::~CTModifiersChangedTest()
|
sl@0
|
194 |
{
|
sl@0
|
195 |
delete iWin;
|
sl@0
|
196 |
delete iEventGroup;
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
void CTModifiersChangedTest::EndTest()
|
sl@0
|
200 |
{
|
sl@0
|
201 |
if (iModSetTest)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
iModSetTest=EFalse;
|
sl@0
|
204 |
iWin->Invalidate();
|
sl@0
|
205 |
}
|
sl@0
|
206 |
Request();
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
void CTModifiersChangedTest::ConstructL()
|
sl@0
|
210 |
{
|
sl@0
|
211 |
iWin=new(ELeave) CMCWindow(this);
|
sl@0
|
212 |
iWin->SetUpL(TPoint(10,10),TSize(240,200),Client()->iGroup, *Client()->iGc);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
TInt CTModifiersChangedTest::SubState() const
|
sl@0
|
216 |
{
|
sl@0
|
217 |
return(iSubState);
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
void CTModifiersChangedTest::IncSubState()
|
sl@0
|
221 |
{
|
sl@0
|
222 |
if (iSubState==(numTests-1))
|
sl@0
|
223 |
EndTest();
|
sl@0
|
224 |
else
|
sl@0
|
225 |
{
|
sl@0
|
226 |
iSubState++;
|
sl@0
|
227 |
iWin->Invalidate();
|
sl@0
|
228 |
}
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
void CTModifiersChangedTest::BadParams()
|
sl@0
|
232 |
{
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
void CTModifiersChangedTest::ModifierChangedEventsL()
|
sl@0
|
236 |
{
|
sl@0
|
237 |
iEventGroup=new(ELeave) CTEventWindowGroup(Client(), this);
|
sl@0
|
238 |
iEventGroup->ConstructL();
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
void CTModifiersChangedTest::CheckModifierL(TEventModifier aModifier)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
TInt oldMods=Client()->iWs.GetModifierState();
|
sl@0
|
244 |
Client()->iWs.SetModifierState(aModifier, EToggleModifier);
|
sl@0
|
245 |
TInt getMods=Client()->iWs.GetModifierState();
|
sl@0
|
246 |
if (oldMods!=getMods)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
iSettable|=aModifier;
|
sl@0
|
249 |
Client()->iWs.SetModifierState(aModifier, ETurnOffModifier);
|
sl@0
|
250 |
getMods=Client()->iWs.GetModifierState();
|
sl@0
|
251 |
TestL(!(getMods&aModifier));
|
sl@0
|
252 |
Client()->iWs.SetModifierState(aModifier, ETurnOnModifier);
|
sl@0
|
253 |
getMods=Client()->iWs.GetModifierState();
|
sl@0
|
254 |
TestL(getMods&aModifier);
|
sl@0
|
255 |
Client()->iWs.SetModifierState(aModifier, ETurnOffModifier);
|
sl@0
|
256 |
getMods=Client()->iWs.GetModifierState();
|
sl@0
|
257 |
TestL(!(getMods&aModifier));
|
sl@0
|
258 |
if (oldMods&aModifier)
|
sl@0
|
259 |
Client()->iWs.SetModifierState(aModifier, ETurnOnModifier);
|
sl@0
|
260 |
}
|
sl@0
|
261 |
else
|
sl@0
|
262 |
{
|
sl@0
|
263 |
Client()->iWs.SetModifierState(aModifier, ETurnOffModifier);
|
sl@0
|
264 |
TestL(oldMods==Client()->iWs.GetModifierState());
|
sl@0
|
265 |
Client()->iWs.SetModifierState(aModifier, ETurnOnModifier);
|
sl@0
|
266 |
TestL(oldMods==Client()->iWs.GetModifierState());
|
sl@0
|
267 |
}
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
void CTModifiersChangedTest::SetModifiersL()
|
sl@0
|
271 |
{
|
sl@0
|
272 |
iModSetTest=ETrue;
|
sl@0
|
273 |
for(TInt mod=1;mod!=0;mod<<=1)
|
sl@0
|
274 |
CheckModifierL((TEventModifier)mod);
|
sl@0
|
275 |
iWin->Invalidate();
|
sl@0
|
276 |
Client()->iWs.Flush();
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
TestState CTModifiersChangedTest::DoTestL()
|
sl@0
|
280 |
{
|
sl@0
|
281 |
switch(iState)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
case 0: //The first 2 tests have been converted to TAuto test code.
|
sl@0
|
284 |
ModifierChangedEventsL();
|
sl@0
|
285 |
/* iState++;
|
sl@0
|
286 |
return(EContinue);
|
sl@0
|
287 |
case 1:
|
sl@0
|
288 |
LogSubTest(_L("Errors"),1);
|
sl@0
|
289 |
BadParams();
|
sl@0
|
290 |
break;
|
sl@0
|
291 |
case 2:*/
|
sl@0
|
292 |
LogSubTest(_L("Set modifiers"),1);
|
sl@0
|
293 |
SetModifiersL();
|
sl@0
|
294 |
iState++;
|
sl@0
|
295 |
return(EContinue);
|
sl@0
|
296 |
default:
|
sl@0
|
297 |
return(EFinished);
|
sl@0
|
298 |
}
|
sl@0
|
299 |
//iState++;
|
sl@0
|
300 |
//return(ENext);
|
sl@0
|
301 |
}
|