|
1 /* |
|
2 * Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation for full screen UI layout |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <w32std.h> |
|
20 #include <peninputcmd.h> |
|
21 #include "peninputfullscrlayout.h" |
|
22 #include "peninputlayoutrootctrl.h" |
|
23 #include "peninputlayouttimer.h" |
|
24 #include "peninputlayouthwrwnd.h" |
|
25 #include <coemain.h> |
|
26 |
|
27 const TInt KDefaultMaxStep = 3; |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CFepFullScreenLayout::CFepFullScreenLayout |
|
32 // Constructor |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 |
|
36 EXPORT_C CFepFullScreenLayout::CFepFullScreenLayout(MLayoutOwner* aLayoutOwner, |
|
37 TInt aDuration) |
|
38 :CFepUiLayout(aLayoutOwner), |
|
39 iBufferEvent(EFalse),iXLeftPos(0),iXRightPos(0), |
|
40 iYTopPos(0),iYBottomPos(0), |
|
41 iEventBufDruation(aDuration) |
|
42 |
|
43 { |
|
44 const TInt KDefaultBufferTimer = 1000*250; //1/4 seconds |
|
45 if(iEventBufDruation <= 0) |
|
46 iEventBufDruation = KDefaultBufferTimer; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CFepFullScreenLayout::~CFepFullScreenLayout |
|
51 // Destructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CFepFullScreenLayout::~CFepFullScreenLayout() |
|
55 { |
|
56 delete iBufferTimer; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CFepFullScreenLayout::BaseConstructL |
|
61 // Do basic contructor |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C void CFepFullScreenLayout::BaseConstructL() |
|
65 { |
|
66 iBufferTimer = CLayoutTimer::NewL(this,CLayoutTimer::EOthers); |
|
67 |
|
68 CFepUiLayout::BaseConstructL(); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CFepUiLayout::HandleEventL |
|
73 // handle event from window server |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 EXPORT_C TBool CFepFullScreenLayout::HandleEventL(TEventType aType, const TAny* aData) |
|
77 { |
|
78 TRawEvent event=*((TRawEvent*)aData); |
|
79 |
|
80 //if pointer is captured, don't buffer the event. |
|
81 if(RootControl()->CtrlCapPointer()) |
|
82 return CFepUiLayout::HandleEventL(aType,aData); |
|
83 |
|
84 if((ERawEvent == aType) && (TRawEvent::EButton1Down == event.Type() || |
|
85 TRawEvent::EButton1Up == event.Type() || |
|
86 TRawEvent::EPointerMove == event.Type()) ) |
|
87 { |
|
88 if(iBufferEvent) |
|
89 { |
|
90 if(TRawEvent::EButton1Up == event.Type()) |
|
91 { |
|
92 //is the buffer timer still active? if so, cancel it and |
|
93 //simulate the event to others |
|
94 if(iBufferTimer->IsActive()) |
|
95 { |
|
96 iEventBuf.Append(event); |
|
97 SimulateEvent(); |
|
98 return ETrue; |
|
99 } |
|
100 else |
|
101 { |
|
102 //is this a valid trace? |
|
103 iEventBuf.Append(event); |
|
104 if(IsValidStroke()) |
|
105 HandleBufferedEventL(); |
|
106 else |
|
107 SimulateEvent(); |
|
108 return ETrue; |
|
109 } |
|
110 } |
|
111 |
|
112 BufferEventL(event); |
|
113 return ETrue; |
|
114 } |
|
115 |
|
116 |
|
117 //Check whether buffering should starts. |
|
118 //Only when pen downs in the area where trace can be started, |
|
119 //e.g, not in the button, should we start the buffering. |
|
120 if(!(RootControl()->NonHwrStartingPtRegion().Contains(event.Pos()))) |
|
121 { |
|
122 if(IsHwrNewCharacter() && TRawEvent::EButton1Down == event.Type()) |
|
123 { |
|
124 StartBufferEvent(event); |
|
125 return ETrue; |
|
126 } |
|
127 } |
|
128 } |
|
129 return CFepUiLayout::HandleEventL(aType,aData); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CFepFullScreenLayout::StartBufferEvent |
|
134 // Start bufferring the event |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 void CFepFullScreenLayout::StartBufferEvent(TRawEvent& aEvent) |
|
138 { |
|
139 iBufferEvent = ETrue; |
|
140 iXLeftPos = aEvent.Pos().iX; |
|
141 iXRightPos = aEvent.Pos().iX; |
|
142 iYTopPos = aEvent.Pos().iY; |
|
143 iYBottomPos = aEvent.Pos().iY; |
|
144 iEventBuf.Append(aEvent); |
|
145 iHwrWndPenSize = iHwrWnd->PenSize(); |
|
146 iHwrWnd->SetPenSize(TSize(0,0)); |
|
147 iBufferTimer->SetTimer(iEventBufDruation); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CFepFullScreenLayout::BufferEventL |
|
152 // Bufferring theevent |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void CFepFullScreenLayout::BufferEventL(TRawEvent& aEvent) |
|
156 { |
|
157 iEventBuf.AppendL(aEvent); |
|
158 if(IsValidStroke()) |
|
159 HandleBufferedEventL(); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CFepFullScreenLayout::SimulateEvent |
|
164 // Simulates the bufferred event to other app |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CFepFullScreenLayout::SimulateEvent() |
|
168 { |
|
169 |
|
170 iBufferEvent = EFalse; |
|
171 //resotre the hwr window pen size |
|
172 iHwrWnd->SetPenSize(iHwrWndPenSize); |
|
173 |
|
174 for(TInt i = 0; i < iEventBuf.Count(); i++) |
|
175 { |
|
176 TPtrC data; |
|
177 data.Set(reinterpret_cast<TUint16*>(&iEventBuf[i]),sizeof(iEventBuf[i])/sizeof(TUint16)); |
|
178 |
|
179 SignalOwner(ESignalSimulateEvent,data); |
|
180 } |
|
181 iEventBuf.Reset(); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // CFepFullScreenLayout::HandleBufferedEventL |
|
186 // Forward event to iput UI |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CFepFullScreenLayout::HandleBufferedEventL() |
|
190 { |
|
191 iBufferEvent = EFalse; |
|
192 //resotre the hwr window pen size |
|
193 iHwrWnd->SetPenSize(iHwrWndPenSize); |
|
194 |
|
195 for(TInt i = 0; i < iEventBuf.Count(); i++) |
|
196 { |
|
197 CFepUiLayout::HandleEventL(ERawEvent,&iEventBuf[i]); |
|
198 } |
|
199 |
|
200 iEventBuf.Reset(); |
|
201 } |
|
202 |
|
203 EXPORT_C void CFepFullScreenLayout::HandleTimerOut(TInt /*aTimeType*/) |
|
204 { |
|
205 iBufferEvent = EFalse; |
|
206 //change pen width for hwr window |
|
207 TRAP_IGNORE(HandleBufferedEventL()); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CFepFullScreenLayout::InitL |
|
212 // Initialize the layout |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C TRect CFepFullScreenLayout::Init() |
|
216 { |
|
217 //find hwr window |
|
218 iHwrWnd =(CHwrWndBase*)(RootControl()->ControlForKindOfType(ECtrlTransparentHwrWnd)); |
|
219 __ASSERT_ALWAYS(iHwrWnd, User::Panic(_L("peninputserver"), EUiFullscreenWithoutHWRWnd)); |
|
220 return CFepUiLayout::Init(); |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // CFepFullScreenLayout::IsHwrNewCharacter |
|
225 // Test whether a new character is starting |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 EXPORT_C TBool CFepFullScreenLayout::IsHwrNewCharacter() |
|
229 { |
|
230 return iHwrWnd->StrokeList().Count() <= 0; |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CFepFullScreenLayout::SemiTransparencyRequired |
|
235 // Tell whether this layout require trancparency |
|
236 // (other items were commented in a header). |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 EXPORT_C TBool CFepFullScreenLayout::SemiTransparencyRequired() |
|
240 { |
|
241 //full screen HWR using full-transparency, so black-white mask is OK. |
|
242 return EFalse; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // CFepFullScreenLayout::IsValidStroke |
|
247 // Tests whether current pen trace is valid for a character |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 EXPORT_C TBool CFepFullScreenLayout::IsValidStroke() |
|
251 { |
|
252 if(iEventBuf.Count() >= KMaxBufferEventNum) |
|
253 { |
|
254 return ETrue; //buffer overflow, this is considering to be a valid stroke. |
|
255 } |
|
256 |
|
257 TPoint pt = iEventBuf[iEventBuf.Count()-1].Pos(); |
|
258 if(pt.iX < iXLeftPos) |
|
259 { |
|
260 iXLeftPos = pt.iX; |
|
261 } |
|
262 else |
|
263 { |
|
264 if(pt.iX > iXRightPos) |
|
265 { |
|
266 iXRightPos = pt.iX; |
|
267 } |
|
268 } |
|
269 |
|
270 if(pt.iY < iYTopPos) |
|
271 { |
|
272 iYTopPos = pt.iY; |
|
273 } |
|
274 else |
|
275 { |
|
276 if(pt.iY > iYBottomPos) |
|
277 { |
|
278 iYBottomPos = pt.iY; |
|
279 } |
|
280 } |
|
281 if((iXRightPos - iXLeftPos) >= KDefaultMaxStep || |
|
282 (iYBottomPos - iYBottomPos) >= KDefaultMaxStep) |
|
283 { |
|
284 //HandleBufferedEventL(); |
|
285 return ETrue; |
|
286 } |
|
287 else |
|
288 return EFalse; |
|
289 } |
|
290 //end of file |