|
1 /* |
|
2 * Copyright (c) 2005-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 pop up window |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "peninputlayoutrootctrl.h" |
|
19 #include "peninputlayoutpopupwnd.h" |
|
20 #include "peninputlayout.h" |
|
21 #include <coemain.h> |
|
22 #include <coecntrl.h> |
|
23 #include "peninputcmd.h" |
|
24 // ============================ MEMBER FUNCTIONS ============================= |
|
25 |
|
26 // Implementation of Class CFepLayoutPopupWnd |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CFepLayoutPopupWnd::CFepLayoutPopupWnd |
|
30 // C++ default constructor |
|
31 // (other items were commented in a header). |
|
32 // --------------------------------------------------------------------------- |
|
33 EXPORT_C CFepLayoutPopupWnd::CFepLayoutPopupWnd(const TSize& /*aSize*/, |
|
34 CFepUiLayout* aUiLayout,TInt aControlId) |
|
35 : CControlGroup(aUiLayout, aControlId), iIsShowing(EFalse) |
|
36 { |
|
37 SetControlType(ECtrlPopupWindow | ECtrlControlGroup); |
|
38 Hide(ETrue); |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CFepLayoutPopupWnd::~CFepLayoutPopupWnd |
|
43 // Destructor |
|
44 // --------------------------------------------------------------------------- |
|
45 EXPORT_C CFepLayoutPopupWnd::~CFepLayoutPopupWnd() |
|
46 { |
|
47 if(iIsShowing) // is showing |
|
48 { |
|
49 //do nothing |
|
50 } |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CFepLayoutPopupWnd::ConsructL() |
|
55 // Symbian 2nd phase constructor |
|
56 // (other items were commented in a header). |
|
57 // --------------------------------------------------------------------------- |
|
58 EXPORT_C void CFepLayoutPopupWnd::ConstructL() |
|
59 { |
|
60 BaseConstructL(); |
|
61 } |
|
62 |
|
63 EXPORT_C void CFepLayoutPopupWnd::ReDrawRect(const TRect& /*aRect*/) |
|
64 { |
|
65 Draw(); |
|
66 } |
|
67 |
|
68 |
|
69 /* |
|
70 |
|
71 |
|
72 Four directions description |
|
73 |
|
74 |
|
75 +-----------+ +-----------+ |
|
76 | | | | |
|
77 EDispTopLeft; | PopupWnd | | PopupWnd | EDispTopRight; |
|
78 | | | | |
|
79 +-------+---+ +---+---+---+ |
|
80 | | | | |
|
81 +---+ +---+ |
|
82 |
|
83 +---+ +---+ |
|
84 | | | | |
|
85 +-------+---+ +---+-------+ |
|
86 | | | | |
|
87 EDispBottomLeft; | PopupWnd | | PopupWnd | EDispBottomRight; |
|
88 | | | | |
|
89 +-------+---+ +-------+---+ |
|
90 |
|
91 |
|
92 The method to determine the direction |
|
93 |
|
94 1.Convert coordinates to screen based |
|
95 2.Determine left-right direction |
|
96 2.1 First consider screen |
|
97 2.2 if both left & right are in screen, consider layout |
|
98 2.3 if both left & right are neigher in screen nor in layout, |
|
99 use the less difference |
|
100 3.Determine top-bottom direction |
|
101 |
|
102 |
|
103 |
|
104 */ |
|
105 CFepLayoutPopupWnd::TDisplayPosition CFepLayoutPopupWnd::DeterminePosition(const TRect& aSrcRect) |
|
106 { |
|
107 TBool down = ETrue; |
|
108 TBool right = ETrue; |
|
109 |
|
110 TSize szPopup = iRect.Size(); |
|
111 TRect rtLayout = UiLayout()->Rect(); |
|
112 TPoint ptLayout = UiLayout()->Position(); |
|
113 rtLayout.Move( ptLayout ); |
|
114 |
|
115 TPixelsTwipsAndRotation ptScreenSize; |
|
116 CCoeEnv::Static()->ScreenDevice()-> |
|
117 GetDefaultScreenSizeAndRotation(ptScreenSize); |
|
118 TRect rtScreen (TPoint(), ptScreenSize.iPixelSize ); |
|
119 |
|
120 //determine right or left |
|
121 TInt rsRight = aSrcRect.iTl.iX + ptLayout.iX + szPopup.iWidth; |
|
122 TInt lsLeft = aSrcRect.iBr.iX + ptLayout.iX - szPopup.iWidth; |
|
123 |
|
124 do |
|
125 { |
|
126 if( rsRight > rtScreen.iBr.iX && lsLeft > 0 ) |
|
127 { |
|
128 right = EFalse; |
|
129 break; |
|
130 } |
|
131 |
|
132 if( rsRight < rtScreen.iBr.iX && lsLeft < 0 ) |
|
133 { |
|
134 right = ETrue; |
|
135 break; |
|
136 } |
|
137 |
|
138 if( rsRight > rtScreen.iBr.iX && lsLeft < 0 ) |
|
139 { |
|
140 if( rsRight - rtScreen.iBr.iX < 0 - lsLeft ) |
|
141 { |
|
142 right = ETrue; |
|
143 } |
|
144 else |
|
145 { |
|
146 right = EFalse; |
|
147 } |
|
148 break; |
|
149 } |
|
150 |
|
151 if( rsRight < rtLayout.iBr.iX ) |
|
152 { |
|
153 right = ETrue; |
|
154 break; |
|
155 } |
|
156 |
|
157 if( lsLeft > rtLayout.iTl.iX ) |
|
158 { |
|
159 right = EFalse; |
|
160 break; |
|
161 } |
|
162 |
|
163 if( rtLayout.iTl.iX - lsLeft < rsRight - rtLayout.iBr.iX ) |
|
164 { |
|
165 right = EFalse; |
|
166 break; |
|
167 } |
|
168 |
|
169 right = ETrue; |
|
170 }while( EFalse ); |
|
171 //determin down or up |
|
172 TInt dsBottom = aSrcRect.iBr.iY + ptLayout.iY + szPopup.iHeight; |
|
173 TInt usTop = aSrcRect.iTl.iY + ptLayout.iY - szPopup.iHeight; |
|
174 |
|
175 do |
|
176 { |
|
177 if( dsBottom > rtScreen.iBr.iY && usTop > 0 ) |
|
178 { |
|
179 down = EFalse; |
|
180 break; |
|
181 } |
|
182 |
|
183 if( dsBottom < rtScreen.iBr.iY && usTop < 0 ) |
|
184 { |
|
185 down = ETrue; |
|
186 break; |
|
187 } |
|
188 |
|
189 if( dsBottom > rtScreen.iBr.iY && usTop < 0 ) |
|
190 { |
|
191 if( dsBottom - rtScreen.iBr.iY < 0 - usTop ) |
|
192 { |
|
193 down = ETrue; |
|
194 } |
|
195 else |
|
196 { |
|
197 down = EFalse; |
|
198 } |
|
199 break; |
|
200 } |
|
201 |
|
202 if( dsBottom < rtLayout.iBr.iY ) |
|
203 { |
|
204 down = ETrue; |
|
205 break; |
|
206 } |
|
207 |
|
208 if( usTop > rtLayout.iTl.iY ) |
|
209 { |
|
210 down = EFalse; |
|
211 break; |
|
212 } |
|
213 |
|
214 if( rtLayout.iTl.iY - usTop < dsBottom - rtLayout.iBr.iY ) |
|
215 { |
|
216 down = EFalse; |
|
217 break; |
|
218 } |
|
219 |
|
220 down = ETrue; |
|
221 }while( EFalse ); |
|
222 |
|
223 TDisplayPosition disPostion; |
|
224 if( down ) |
|
225 { |
|
226 if( right ) |
|
227 { |
|
228 disPostion = EDispBottomRight; |
|
229 } |
|
230 else |
|
231 { |
|
232 disPostion = EDispBottomLeft; |
|
233 } |
|
234 } |
|
235 else |
|
236 { |
|
237 if( right ) |
|
238 { |
|
239 disPostion = EDispTopRight; |
|
240 } |
|
241 else |
|
242 { |
|
243 disPostion = EDispTopLeft; |
|
244 } |
|
245 } |
|
246 return disPostion; |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CFepLayoutPopupWnd::Display() |
|
251 // display pop up window |
|
252 // (other items were commented in a header). |
|
253 // --------------------------------------------------------------------------- |
|
254 EXPORT_C void CFepLayoutPopupWnd::Display( const TRect& aOffsetRect, TDisplayPosition aDisPostion) |
|
255 { |
|
256 if(iIsShowing) |
|
257 return; |
|
258 RootControl()->SetActiveCtrl(this); |
|
259 ReportEvent(EEventCapturePointer); |
|
260 |
|
261 //let pop up window do preparation |
|
262 OnDisplay(); |
|
263 |
|
264 //determine the directoin |
|
265 TRect rtPopup; //final position |
|
266 TSize szPopup = iRect.Size(); |
|
267 TRect rtLayout = UiLayout()->Rect(); |
|
268 TPoint ptLayout = UiLayout()->Position(); |
|
269 rtLayout.Move( ptLayout ); |
|
270 |
|
271 |
|
272 TRect layoutRect = UiLayout()->Rect();//relative layout |
|
273 |
|
274 if( aDisPostion == EDispAutomatic ) |
|
275 { |
|
276 aDisPostion = DeterminePosition( aOffsetRect ); |
|
277 } |
|
278 |
|
279 //reposition if the rect is out of screen |
|
280 TPixelsTwipsAndRotation ptScreenSize; |
|
281 CCoeEnv::Static()->ScreenDevice()-> |
|
282 GetDefaultScreenSizeAndRotation(ptScreenSize); |
|
283 |
|
284 TRect offsetRect( aOffsetRect ); |
|
285 offsetRect.Move( ptLayout ); |
|
286 |
|
287 switch( aDisPostion ) |
|
288 { |
|
289 case EDispBottomRight: |
|
290 rtPopup.SetRect( TPoint( offsetRect.iTl.iX, offsetRect.iBr.iY ), szPopup ); |
|
291 if( rtPopup.iBr.iY > ptScreenSize.iPixelSize.iHeight ) |
|
292 { |
|
293 //we need move x also |
|
294 rtPopup.Move( aOffsetRect.Width(), |
|
295 ptScreenSize.iPixelSize.iHeight - rtPopup.iBr.iY ); |
|
296 } |
|
297 if(rtPopup.iBr.iX > ptScreenSize.iPixelSize.iWidth ) |
|
298 { |
|
299 rtPopup.Move ( ptScreenSize.iPixelSize.iWidth - rtPopup.iBr.iX, 0 ); |
|
300 } |
|
301 break; |
|
302 case EDispBottomLeft: |
|
303 rtPopup.SetRect( TPoint( offsetRect.iBr.iX - szPopup.iWidth, offsetRect.iBr.iY), |
|
304 szPopup ); |
|
305 if( rtPopup.iBr.iY > ptScreenSize.iPixelSize.iHeight ) |
|
306 { |
|
307 //we need move x also |
|
308 rtPopup.Move( aOffsetRect.Width(), |
|
309 ptScreenSize.iPixelSize.iHeight - rtPopup.iBr.iY ); |
|
310 } |
|
311 if( rtPopup.iTl.iX < 0 ) |
|
312 { |
|
313 rtPopup.Move ( -rtPopup.iTl.iX, 0 ); |
|
314 } |
|
315 break; |
|
316 case EDispTopRight: |
|
317 rtPopup.SetRect( TPoint( offsetRect.iTl.iX, offsetRect.iTl.iY - szPopup.iHeight ), |
|
318 szPopup ); |
|
319 if( rtPopup.iTl.iY < 0 ) |
|
320 { |
|
321 rtPopup.Move ( aOffsetRect.Width(), -rtPopup.iTl.iY ); |
|
322 } |
|
323 if(rtPopup.iBr.iX > ptScreenSize.iPixelSize.iWidth ) |
|
324 { |
|
325 rtPopup.Move ( ptScreenSize.iPixelSize.iWidth - rtPopup.iBr.iX, 0 ); |
|
326 } |
|
327 |
|
328 break; |
|
329 case EDispTopLeft: |
|
330 rtPopup.SetRect( TPoint( offsetRect.iBr.iX - szPopup.iWidth, |
|
331 offsetRect.iTl.iY - szPopup.iHeight ), szPopup ); |
|
332 |
|
333 if( rtPopup.iTl.iY < 0 ) |
|
334 { |
|
335 rtPopup.Move ( -aOffsetRect.Width(), -rtPopup.iTl.iY ); |
|
336 } |
|
337 |
|
338 if( rtPopup.iTl.iX < 0 ) |
|
339 { |
|
340 rtPopup.Move ( -rtPopup.iTl.iX, 0 ); |
|
341 } |
|
342 break; |
|
343 } |
|
344 |
|
345 MLayoutOwner* layoutOwner = UiLayout()->LayoutOwner(); |
|
346 |
|
347 //calculate the bound rect of current layout + popup window in screen coordination |
|
348 TRect totalRect(rtPopup); |
|
349 |
|
350 totalRect.BoundingRect(rtLayout); |
|
351 |
|
352 TRect rtFinal( totalRect ); |
|
353 |
|
354 rtPopup.Move( -ptLayout ); |
|
355 if( rtFinal != rtLayout ) |
|
356 {//resize |
|
357 iPrevLayoutRect = rtLayout; |
|
358 iLayoutMoveOff = rtLayout.iTl - rtFinal.iTl; |
|
359 rtPopup.Move( iLayoutMoveOff ); |
|
360 layoutOwner->LayoutSizeChanged(rtFinal.Size(), EFalse); |
|
361 layoutOwner->SetPosition(rtFinal.iTl); |
|
362 //RootControl()->Clear(); |
|
363 DrawTransparentMaskBackground( TRect( TPoint(), rtFinal.Size() ) ); |
|
364 RootControl()->Move(iLayoutMoveOff); |
|
365 RootControl()->Draw(); |
|
366 //UpdateArea( TRect( TPoint(), rtFinal.Size()), ETrue); |
|
367 } |
|
368 else |
|
369 { |
|
370 iPrevLayoutRect.SetSize(TSize(0,0)); |
|
371 } |
|
372 |
|
373 //capture pointer |
|
374 iPreCaptureCtrl= CapturePointer(); |
|
375 |
|
376 if(iWndControl) |
|
377 { |
|
378 iWndControl->MakeVisible(ETrue); |
|
379 } |
|
380 |
|
381 //iRect = rtPopup; |
|
382 Move( rtPopup.iTl - Rect().iTl); |
|
383 UiLayout()->LockArea(iRect,this); |
|
384 Hide(EFalse); |
|
385 |
|
386 iIsShowing = ETrue; |
|
387 AfterDisplayed(); |
|
388 |
|
389 TRect rectOfPopup =Rect(); //in new layout coord-sys |
|
390 TRect rectTrimLayout = RootControl()->Rect(); // in new layout coord-sys |
|
391 |
|
392 TInt rectsz = sizeof(TRect)/sizeof(TUint16); |
|
393 RBuf buf; |
|
394 buf.Create( rectsz * 2 ); |
|
395 buf.Append( reinterpret_cast<const TUint16*>(&rectOfPopup), rectsz ); |
|
396 buf.Append( reinterpret_cast<const TUint16*>(&rectTrimLayout), rectsz ); |
|
397 UiLayout()->SignalOwner(ESignalPopupWnd, buf ); |
|
398 buf.Close(); |
|
399 } |
|
400 // --------------------------------------------------------------------------- |
|
401 // CFepLayoutPopupWnd::Display() |
|
402 // display pop up window |
|
403 // (other items were commented in a header). |
|
404 // --------------------------------------------------------------------------- |
|
405 EXPORT_C void CFepLayoutPopupWnd::Display( const TRect& aOffsetRect ) |
|
406 { |
|
407 Display( aOffsetRect, EDispAutomatic); |
|
408 } |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // CFepLayoutPopupWnd::Display() |
|
412 // display pop up window |
|
413 // (other items were commented in a header). |
|
414 // --------------------------------------------------------------------------- |
|
415 EXPORT_C void CFepLayoutPopupWnd::Display(const TPoint& aOffset) |
|
416 { |
|
417 Display ( TRect( aOffset, aOffset ) , EDispAutomatic); |
|
418 } |
|
419 |
|
420 // --------------------------------------------------------------------------- |
|
421 // CFepLayoutPopupWnd::CloseWindow() |
|
422 // display window |
|
423 // --------------------------------------------------------------------------- |
|
424 EXPORT_C void CFepLayoutPopupWnd::CloseWindow() |
|
425 { |
|
426 if( !iIsShowing ) |
|
427 { |
|
428 return; |
|
429 } |
|
430 |
|
431 if(iPreCaptureCtrl) |
|
432 iPreCaptureCtrl->CapturePointer(); |
|
433 else |
|
434 CapturePointer(EFalse); |
|
435 UiLayout()->SignalOwner(ESignalPopupWndClosed); |
|
436 |
|
437 iIsShowing = EFalse; |
|
438 if(iWndControl) |
|
439 iWndControl->MakeVisible(EFalse); |
|
440 Hide(ETrue); |
|
441 UiLayout()->UnLockArea(iRect,this); |
|
442 iRect.Move(-iRect.iTl); |
|
443 MLayoutOwner* layoutOwner = UiLayout()->LayoutOwner(); |
|
444 if(!iPrevLayoutRect.IsEmpty()) |
|
445 { |
|
446 RootControl()->Move(-iLayoutMoveOff); |
|
447 TRect rt; |
|
448 rt.SetSize( layoutOwner->LayoutRect().Size() ); |
|
449 layoutOwner->SetPosition(iPrevLayoutRect.iTl); |
|
450 layoutOwner->LayoutSizeChanged(iPrevLayoutRect.Size()); |
|
451 RootControl()->GraphicDeviceSizeChanged(); |
|
452 } |
|
453 |
|
454 RootControl()->Draw(); |
|
455 |
|
456 iIsShowing = EFalse; |
|
457 |
|
458 TRect rect( TPoint(0,0),iPrevLayoutRect.Size() ); |
|
459 UpdateArea( rect, EFalse ); |
|
460 } |
|
461 |
|
462 // --------------------------------------------------------------------------- |
|
463 // CFepLayoutPopupWnd::SetRect |
|
464 // Set the pop up window's rect |
|
465 // --------------------------------------------------------------------------- |
|
466 // |
|
467 EXPORT_C void CFepLayoutPopupWnd::SetRect(const TRect& aRect) |
|
468 { |
|
469 iRect = aRect; |
|
470 //Ensure that the top left of pop up window is always (0,0) |
|
471 iRect.Move(-aRect.iTl.iX,-aRect.iTl.iY); |
|
472 } |
|
473 |
|
474 // --------------------------------------------------------------------------- |
|
475 // CFepLayoutPopupWnd::OnDeActivate |
|
476 // DeActivate popup window |
|
477 // --------------------------------------------------------------------------- |
|
478 // |
|
479 EXPORT_C void CFepLayoutPopupWnd::OnDeActivate() |
|
480 { |
|
481 CloseWindow(); |
|
482 } |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // CFepLayoutPopupWnd::OnDisplay |
|
486 // Prepare for window displaying |
|
487 // --------------------------------------------------------------------------- |
|
488 // |
|
489 EXPORT_C void CFepLayoutPopupWnd::OnDisplay() |
|
490 { |
|
491 //do nothing |
|
492 } |
|
493 // --------------------------------------------------------------------------- |
|
494 // CFepLayoutPopupWnd::AfterDisplayed |
|
495 // Notify pops up window displayed |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 EXPORT_C void CFepLayoutPopupWnd::AfterDisplayed() |
|
499 { |
|
500 //do nothing |
|
501 } |