229 if ( popupSize != iPopUp->Size() ) |
229 if ( popupSize != iPopUp->Size() ) |
230 { |
230 { |
231 resize = ETrue; |
231 resize = ETrue; |
232 } |
232 } |
233 |
233 |
234 // allowed rect |
234 // Adjust the position if the popup would go outside of the screen |
235 TRect clientRect; |
235 // rect with the given position. |
236 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect ); |
236 TRect screenRect; |
237 |
237 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect ); |
238 // Control is allowed to be on top of the status pane but it cannot |
238 TInt screenWidth( screenRect.Width() ); |
239 // overlay either stacon pane or control pane. |
239 TInt screenHeight( screenRect.Height() ); |
240 |
240 |
241 //switch ( iAvkonAppUi->StatusPane()->CurrentLayoutResId() ) |
241 TPoint finalPosition; |
242 CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current(); |
242 |
243 TInt currentStatusPaneLayoutResId = 0; |
243 // Resize if the popup is too wide. |
244 if (statusPane) |
244 if ( popupSize.iWidth > screenWidth ) |
245 { |
245 { |
246 currentStatusPaneLayoutResId = statusPane->CurrentLayoutResId(); |
246 resize = ETrue; |
|
247 popupSize.iWidth = screenWidth; |
|
248 } |
|
249 |
|
250 // Resize if the popup is too tall. |
|
251 if ( popupSize.iHeight > screenHeight ) |
|
252 { |
|
253 resize = ETrue; |
|
254 popupSize.iHeight = screenHeight; |
|
255 } |
|
256 |
|
257 // Default horizontal position is left from the given point. |
|
258 if ( askedPoint.iX - popupSize.iWidth >= screenRect.iTl.iX ) |
|
259 { |
|
260 finalPosition.iX = askedPoint.iX - popupSize.iWidth; |
247 } |
261 } |
248 else |
262 else |
249 { |
263 { |
250 // If this app does not have statuspane, then we ask the layout from AknCapServer. |
264 // outside left border, move to left border |
251 currentStatusPaneLayoutResId = CAknSgcClient::CurrentStatuspaneResource(); |
265 finalPosition.iX = screenRect.iTl.iX; |
252 } |
266 } |
253 |
267 |
254 switch ( currentStatusPaneLayoutResId ) |
268 // Check the right border. |
255 { |
269 if ( finalPosition.iX + popupSize.iWidth > screenRect.iBr.iX ) |
256 case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT: |
270 { |
257 case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT: |
271 finalPosition.iX = screenRect.iBr.iX - popupSize.iWidth; |
258 case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_RIGHT: |
272 } |
259 case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_LEFT: |
273 |
260 case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT: |
274 // Default vertical position is up from the given point. |
261 case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT: |
275 // Coordinates grow from top to bottom. |
262 break; |
276 if ( askedPoint.iY > screenRect.iTl.iY ) |
263 |
277 { |
264 default: |
278 finalPosition.iY = askedPoint.iY; |
265 TRect statusPaneRect; |
|
266 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, |
|
267 statusPaneRect ); |
|
268 |
|
269 clientRect.BoundingRect( statusPaneRect ); |
|
270 } |
|
271 |
|
272 TPoint finalPosition; |
|
273 |
|
274 // resize if the popup is too wide |
|
275 if ( popupSize.iWidth > clientRect.Width() ) |
|
276 { |
|
277 resize = ETrue; |
|
278 popupSize.iWidth = clientRect.Width(); |
|
279 } |
|
280 |
|
281 // resize if the popup is too tall |
|
282 if ( popupSize.iHeight > clientRect.Height() ) |
|
283 { |
|
284 resize = ETrue; |
|
285 popupSize.iHeight = clientRect.Height(); |
|
286 } |
|
287 |
|
288 // default horizontal position is left from the given point |
|
289 if ( askedPoint.iX - popupSize.iWidth >= clientRect.iTl.iX ) |
|
290 { |
|
291 finalPosition.iX = askedPoint.iX - popupSize.iWidth; |
|
292 } |
279 } |
293 else |
280 else |
294 { |
281 { |
295 // outside left border, move to left border |
282 // Outside top border, move to top border. |
296 finalPosition.iX = clientRect.iTl.iX; |
283 finalPosition.iY = screenRect.iTl.iY; |
297 } |
284 } |
298 |
285 |
299 // check the right border |
286 // Outside bottom border, move to bottom border. |
300 if ( finalPosition.iX + popupSize.iWidth > clientRect.iBr.iX ) |
287 if ( ( askedPoint.iY + popupSize.iHeight ) > screenRect.iBr.iY ) |
301 { |
288 { |
302 finalPosition.iX = clientRect.iBr.iX - popupSize.iWidth; |
289 finalPosition.iY = screenRect.iBr.iY - popupSize.iHeight; |
303 } |
|
304 |
|
305 // default vertical position is up from the given point |
|
306 // coordinates grow from top to bottom |
|
307 if ( askedPoint.iY > clientRect.iTl.iY ) |
|
308 { |
|
309 finalPosition.iY = askedPoint.iY; |
|
310 } |
|
311 else |
|
312 { |
|
313 // outside top border, move to top border |
|
314 finalPosition.iY = clientRect.iTl.iY; |
|
315 } |
|
316 |
|
317 // outside bottom border, move to bottom border |
|
318 if ( ( askedPoint.iY + popupSize.iHeight ) > clientRect.iBr.iY ) |
|
319 { |
|
320 finalPosition.iY = clientRect.iBr.iY - popupSize.iHeight; |
|
321 } |
290 } |
322 |
291 |
323 if ( resize ) |
292 if ( resize ) |
324 { |
293 { |
325 iPopUp->SetSize( popupSize ); |
294 iPopUp->SetSize( popupSize ); |