📄 foreground.cpp
字号:
#include "foreground.h"
002 #include "symbian_auto_ptr.h"
003 #include <e32std.h>
004 #include <apgwgnam.h>
005
006
007 class CForegroundImpl : public CForeground {
008 virtual void AddObserver(MForegroundObserver* aObserver);
009
010 CForegroundImpl(RWsSession& aWsSession);
011
012 void ConstructL();
013 void RunL();
014 TInt RunError(TInt aError);
015 void DoCancel();
016 void StartL();
017 void Release();
018 void Listen();
019
020 RPointerArray<MForegroundObserver> iObservers;
021 RWsSession& iWsSession;
022 RWindowGroup iWg; bool iWg_is_open;
023
024 friend class CForeground;
025 public:
026 virtual ~CForegroundImpl();
027 };
028
029 CForeground::CForeground(CActive::TPriority aPriority) : CActive(aPriority)
030 {
031 }
032
033 CForeground::~CForeground()
034 {
035
036 }
037
038 CForeground* CForeground::NewL(RWsSession& aWsSession)
039 {
040 auto_ptr<CForegroundImpl> ret(new (ELeave) CForegroundImpl(aWsSession));
041 ret->ConstructL();
042 return ret.release();
043 }
044
045 void CForegroundImpl::AddObserver(MForegroundObserver* aObserver)
046 {
047 User::LeaveIfError(iObservers.Append(aObserver));
048 }
049
050 CForegroundImpl::CForegroundImpl(RWsSession& aWsSession) : CForeground(EPriorityHigh), iWsSession(aWsSession), iWg(aWsSession)
051 {
052 }
053
054 CForegroundImpl::~CForegroundImpl()
055 {
056 Release();
057
058 iObservers.Close();
059 }
060
061 void CForegroundImpl::ConstructL()
062 {
063 CActiveScheduler::Add(this);
064
065 StartL();
066 }
067
068 void CForegroundImpl::RunL()
069 {
070 if (iStatus == KErrNone) {
071 TWsEvent e;
072 iWsSession.GetEvent(e);
073 }
074
075 TInt wgid=iWsSession.GetFocusWindowGroup();
076
077 CApaWindowGroupName* gn;
078 gn=CApaWindowGroupName::NewLC(iWsSession, wgid);
079
080 int i;
081 for (i=0; i<iObservers.Count(); i++) {
082 iObservers[i]->ForegroundChanged(gn->AppUid());
083 }
084 CleanupStack::PopAndDestroy(); // gn
085
086 Listen();
087 }
088
089 TInt CForegroundImpl::RunError(TInt /*aError*/)
090 {
091 TRAPD(err, StartL());
092 return err;
093 }
094
095 void CForegroundImpl::DoCancel()
096 {
097 iWsSession.EventReadyCancel();
098 }
099
100 void CForegroundImpl::StartL()
101 {
102 Release();
103 User::LeaveIfError(iWg.Construct((TUint32)&iWg, EFalse));
104 iWg.SetOrdinalPosition(-1);
105 iWg.EnableReceiptOfFocus(EFalse);
106
107 CApaWindowGroupName* wn=CApaWindowGroupName::NewLC(iWsSession);
108 wn->SetHidden(ETrue);
109 wn->SetWindowGroupName(iWg);
110 CleanupStack::PopAndDestroy();
111
112 User::LeaveIfError(iWg.EnableFocusChangeEvents());
113
114 Listen();
115 }
116
117 void CForegroundImpl::Listen()
118 {
119 iStatus=KRequestPending;
120 iWsSession.EventReady(&iStatus);
121 SetActive();
122 }
123
124 void CForegroundImpl::Release()
125 {
126 Cancel();
127 if (iWg_is_open) {
128 iWg.Close();
129 iWg_is_open=false;
130 }
131 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -