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