CGainFocusEventObserver.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <mw/eikappui.h>
  2. #include <mw/APGWGNAM.H> //CApaWindowGroupName
  3. #include "CGainFocusEventObserver.h"
  4. CGainFocusEventObserver* CGainFocusEventObserver::NewL(MFocusEventObserver& aObserver,
  5. TInt aWgroup)
  6. {
  7. CGainFocusEventObserver* self = new (ELeave) CGainFocusEventObserver(aObserver);
  8. CleanupStack::PushL( self );
  9. self->ConstructL(aWgroup);
  10. CleanupStack::Pop( self );
  11. return self;
  12. }
  13. void CGainFocusEventObserver::ConstructL(TInt aWgroup)
  14. {
  15. CCoeEnv::Static()->RootWin().EnableFocusChangeEvents();
  16. iSession = new (ELeave)RWsSession();
  17. User::LeaveIfError(iSession->Connect());
  18. TUint groupHandle = iSession->GetWindowGroupHandle(aWgroup);
  19. iWGroup = new(ELeave) RWindowGroup(*iSession);
  20. iWGroup->Construct(groupHandle); //connect to aWgroup group
  21. User::LeaveIfError(iWGroup->EnableFocusChangeEvents());
  22. CActiveScheduler::Add(this);
  23. startListening();
  24. }
  25. CGainFocusEventObserver::CGainFocusEventObserver(MFocusEventObserver& aObserver):
  26. CActive(EPriorityStandard),
  27. iObserver(&aObserver)
  28. {
  29. }
  30. CGainFocusEventObserver::~CGainFocusEventObserver()
  31. {
  32. iWGroup->Close();
  33. iSession->Close();
  34. delete iSession;
  35. delete iWGroup;
  36. }
  37. void CGainFocusEventObserver::RunL()
  38. {
  39. if (iStatus == KErrNone)
  40. {
  41. TWsEvent event;
  42. iSession->GetEvent(event);
  43. iObserver->Notify(event.Type());
  44. }
  45. if (iStatus != KErrCancel)
  46. {
  47. startListening();
  48. }
  49. }
  50. void CGainFocusEventObserver::DoCancel()
  51. {
  52. iSession->EventReadyCancel();
  53. }
  54. void CGainFocusEventObserver::startListening()
  55. {
  56. iSession->EventReady(&iStatus);
  57. SetActive();
  58. }