|
1 // Copyright (c) 1999-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 // |
|
15 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
16 #include "vwsinternal.h" |
|
17 #include "vwsdefpartner.h" |
|
18 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
19 #include "VWSWEVNT.H" |
|
20 #include "VWSERVER.H" |
|
21 #include "VWSDEBUG.H" |
|
22 |
|
23 const TInt KPriorityNeverAtFront = -999; |
|
24 const TInt KPriorityAlwaysAtFront = 999;//Setting a priority greater than or equal to KPasswordWindowGroupPriority which is 1000, |
|
25 //on a window group will require the capability SwEvent.If the client does not have |
|
26 //this capability, then the window group priority will be reduced to KPasswordWindowGroupPriority - 1. |
|
27 //As KPasswordWindowGroupPriority has been deprectated 999 is set as the priority.KPriorityAlwaysAtFront |
|
28 //is used when calling SetOrdinalPosition API. |
|
29 |
|
30 |
|
31 // |
|
32 // CVwsWServEventHandler. |
|
33 // |
|
34 |
|
35 CVwsWServEventHandler::CVwsWServEventHandler(CVwsServer& aServer, RWsSession& aWsSession, TBool aIgnoreFirstScreenDeviceChangedEvent) |
|
36 : CActive(CActive::EPriorityStandard),iServer(aServer),iWsSession(aWsSession), |
|
37 iIgnoreNextScreenDeviceChangedEvent(aIgnoreFirstScreenDeviceChangedEvent) |
|
38 { |
|
39 } |
|
40 |
|
41 CVwsWServEventHandler::~CVwsWServEventHandler() |
|
42 { |
|
43 Cancel(); |
|
44 } |
|
45 |
|
46 CVwsWServEventHandler* CVwsWServEventHandler::NewL(CVwsServer& aServer, RWsSession& aWsSession, TBool aIgnoreFirstScreenDeviceChangedEvent) |
|
47 { |
|
48 CVwsWServEventHandler* self=new(ELeave) CVwsWServEventHandler(aServer, aWsSession, aIgnoreFirstScreenDeviceChangedEvent); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 void CVwsWServEventHandler::ConstructL() |
|
56 { |
|
57 CActiveScheduler::Add(this); |
|
58 Queue(); |
|
59 } |
|
60 |
|
61 void CVwsWServEventHandler::Queue() |
|
62 { |
|
63 ASSERT (!IsActive()); |
|
64 iWsSession.EventReady(&iStatus); |
|
65 SetActive(); |
|
66 } |
|
67 |
|
68 void CVwsWServEventHandler::RunL() |
|
69 { |
|
70 TWsEvent event; |
|
71 iWsSession.GetEvent(event); |
|
72 LOG3(CVwsLog::ELoud,_L("Received %d event type from WServ"),event.Type()); |
|
73 TInt err=KErrNone; |
|
74 switch (event.Type()) |
|
75 { |
|
76 case EEventScreenDeviceChanged: |
|
77 if (iIgnoreNextScreenDeviceChangedEvent) |
|
78 { |
|
79 iIgnoreNextScreenDeviceChangedEvent = EFalse; |
|
80 } |
|
81 else |
|
82 { |
|
83 TRAP(err,iServer.HandleScreenDeviceChangedL()); |
|
84 } |
|
85 break; |
|
86 case EEventFocusGroupChanged: |
|
87 iServer.HandleForegroundTaskChange(); |
|
88 break; |
|
89 default: |
|
90 break; |
|
91 } |
|
92 |
|
93 Queue(); |
|
94 User::LeaveIfError(err); |
|
95 } |
|
96 |
|
97 void CVwsWServEventHandler::DoCancel() |
|
98 { |
|
99 iWsSession.EventReadyCancel(); |
|
100 } |
|
101 |
|
102 #ifdef _DEBUG |
|
103 TInt CVwsWServEventHandler::RunError(TInt aError) |
|
104 #else |
|
105 TInt CVwsWServEventHandler::RunError(TInt /*aError*/) |
|
106 #endif |
|
107 { |
|
108 LOG3(CVwsLog::ENormal,_L("CVwsWServEventHandler::RunError: %d"), aError); |
|
109 iServer.KickStartEventQ(); |
|
110 return KErrNone; |
|
111 } |
|
112 |
|
113 // |
|
114 // class CVwsWServRedrawer |
|
115 // |
|
116 |
|
117 CVwsWServRedrawer::CVwsWServRedrawer(RWsSession& aWsSession, CWindowGc& aGc, RWindow& aWindow) |
|
118 : CActive(EPriorityLow),iWsSession(aWsSession),iGc(aGc),iWindow(aWindow),iOpaque(EFalse) |
|
119 { |
|
120 } |
|
121 |
|
122 CVwsWServRedrawer::~CVwsWServRedrawer() |
|
123 { |
|
124 Cancel(); |
|
125 } |
|
126 |
|
127 CVwsWServRedrawer* CVwsWServRedrawer::NewL(RWsSession& aWsSession, CWindowGc& aGc, RWindow& aWindow) |
|
128 { |
|
129 CVwsWServRedrawer* self=new(ELeave) CVwsWServRedrawer(aWsSession,aGc,aWindow); |
|
130 CleanupStack::PushL(self); |
|
131 self->ConstructL(); |
|
132 CleanupStack::Pop(); |
|
133 return self; |
|
134 } |
|
135 |
|
136 void CVwsWServRedrawer::ConstructL() |
|
137 { |
|
138 CActiveScheduler::Add(this); |
|
139 Queue(); |
|
140 } |
|
141 |
|
142 void CVwsWServRedrawer::RunL() |
|
143 { |
|
144 TWsRedrawEvent redraw; |
|
145 iWsSession.GetRedraw(redraw); |
|
146 HandleRedrawEvent(redraw.Rect()); |
|
147 Queue(); |
|
148 } |
|
149 |
|
150 void CVwsWServRedrawer::Queue() |
|
151 { |
|
152 ASSERT (!IsActive()); |
|
153 iWsSession.RedrawReady(&iStatus); |
|
154 SetActive(); |
|
155 } |
|
156 |
|
157 void CVwsWServRedrawer::DoCancel() |
|
158 { |
|
159 iWsSession.RedrawReadyCancel(); |
|
160 } |
|
161 |
|
162 void CVwsWServRedrawer::SetDrawMode(TBool aOpaque) |
|
163 { |
|
164 iOpaque=aOpaque; |
|
165 } |
|
166 |
|
167 void CVwsWServRedrawer::HandleRedrawEvent(const TRect& aRect) |
|
168 { |
|
169 // this code is needed to make the screen redraw correctly |
|
170 // after a screen mode switch. |
|
171 |
|
172 LOG2(CVwsLog::ELoud,_L("CVwsWServRedrawer::HandleRedrawEvent")); |
|
173 iGc.Activate(iWindow); |
|
174 iWindow.BeginRedraw(aRect); |
|
175 iWindow.EndRedraw(); |
|
176 iGc.Deactivate(); |
|
177 iWsSession.Flush(); |
|
178 } |
|
179 |
|
180 CVwsWServSessionHandler::CVwsWServSessionHandler(CVwsServer& aServer) |
|
181 :iServer(aServer), |
|
182 iFirstDisplay(ETrue) |
|
183 { |
|
184 } |
|
185 |
|
186 CVwsWServSessionHandler::~CVwsWServSessionHandler() |
|
187 { |
|
188 delete iWServEventHandler; |
|
189 delete iWServRedrawer; |
|
190 delete iGc; |
|
191 delete iScreen; |
|
192 iRootWin.Close(); |
|
193 if (iWindow!=NULL) |
|
194 { |
|
195 iWindow->Close(); |
|
196 delete iWindow; |
|
197 } |
|
198 |
|
199 ASSERT(iWsSession.ResourceCount()==0); |
|
200 iWsSession.Close(); |
|
201 } |
|
202 |
|
203 CVwsWServSessionHandler* CVwsWServSessionHandler::NewL(CVwsServer& aServer) |
|
204 { |
|
205 CVwsWServSessionHandler* self=new(ELeave) CVwsWServSessionHandler(aServer); |
|
206 CleanupStack::PushL(self); |
|
207 self->ConstructL(); |
|
208 CleanupStack::Pop(); |
|
209 return self; |
|
210 } |
|
211 |
|
212 void CVwsWServSessionHandler::ConstructL() |
|
213 { |
|
214 CreateWServSessionL(); |
|
215 TBool ignoreFirstScreenDeviceChangedEvent = (GetScreenMode() > 0); |
|
216 iWServEventHandler=CVwsWServEventHandler::NewL(iServer,iWsSession, |
|
217 ignoreFirstScreenDeviceChangedEvent); |
|
218 iWServRedrawer=CVwsWServRedrawer::NewL(iWsSession,*iGc,*iWindow); |
|
219 } |
|
220 |
|
221 void CVwsWServSessionHandler::CreateWServSessionL() |
|
222 { |
|
223 User::LeaveIfError(iWsSession.Connect()); |
|
224 |
|
225 iScreen=new(ELeave) CWsScreenDevice(iWsSession); |
|
226 User::LeaveIfError(iScreen->Construct()); |
|
227 User::LeaveIfError(iScreen->CreateContext(iGc)); |
|
228 |
|
229 iRootWin=RWindowGroup(iWsSession); |
|
230 User::LeaveIfError(iRootWin.Construct((TUint32)this,EFalse)); |
|
231 iRootWin.SetOrdinalPosition(0,KPriorityNeverAtFront); |
|
232 iRootWin.EnableScreenChangeEvents(); |
|
233 iRootWin.EnableFocusChangeEvents(); |
|
234 |
|
235 iWindow=new(ELeave) RWindow(iWsSession); |
|
236 User::LeaveIfError(iWindow->Construct(iRootWin,((TUint32)this)+1)); |
|
237 iWindow->Activate(); |
|
238 iWindow->SetVisible(EFalse); |
|
239 } |
|
240 |
|
241 TInt CVwsWServSessionHandler::GetScreenMode() |
|
242 { |
|
243 return iScreen->CurrentScreenMode(); |
|
244 } |
|
245 |
|
246 void CVwsWServSessionHandler::ConfigureScreenDevice() |
|
247 { |
|
248 LOG2(CVwsLog::ENormal,_L("CVwsWServSessionHandler:::ConfigureScreenDevice()")); |
|
249 TPixelsAndRotation sizeAndRotation; |
|
250 iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation); |
|
251 iScreen->SetScreenSizeAndRotation(sizeAndRotation); |
|
252 iWindow->SetSize(sizeAndRotation.iPixelSize); |
|
253 } |
|
254 |
|
255 void CVwsWServSessionHandler::DisplayWindow() |
|
256 { |
|
257 LOG2(CVwsLog::ENormal,_L("CVwsWServSessionHandler::DisplayWindow()")); |
|
258 if (iFirstDisplay) |
|
259 { |
|
260 iRootWin.SetOrdinalPosition(0,KPriorityAlwaysAtFront); |
|
261 iFirstDisplay=EFalse; |
|
262 } |
|
263 iWindow->SetVisible(ETrue); |
|
264 iWsSession.Flush(); |
|
265 } |
|
266 |
|
267 void CVwsWServSessionHandler::HideWindow() |
|
268 { |
|
269 LOG2(CVwsLog::ENormal,_L("CVwsWServSessionHandler::HideWindow()")); |
|
270 iWindow->SetVisible(EFalse); |
|
271 iWsSession.Flush(); |
|
272 iWServRedrawer->SetDrawMode(EFalse); |
|
273 } |
|
274 |
|
275 void CVwsWServSessionHandler::UpdateScreenAndDisplayWindow() |
|
276 { |
|
277 ConfigureScreenDevice(); |
|
278 iWServRedrawer->SetDrawMode(ETrue); |
|
279 DisplayWindow(); |
|
280 } |
|
281 |
|
282 void CVwsWServSessionHandler::SetWindowBackgroundColor(const TRgb& aBgColor) |
|
283 { |
|
284 iWindow->SetBackgroundColor(aBgColor); |
|
285 } |