|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Selection popup dialog. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 |
|
23 #include <avkon.hrh> |
|
24 #include <AknLayoutScalable_Avkon.cdl.h> |
|
25 #include <AknLayoutScalable_Apps.cdl.h> |
|
26 #include <fbs.h> |
|
27 #include <AknIconUtils.h> |
|
28 #include <AknUtils.h> |
|
29 |
|
30 #include <AknBidiTextUtils.h> |
|
31 #include <BidiText.h> |
|
32 |
|
33 #include <ImageEditorUi.mbg> |
|
34 #include <ImageEditorUI.rsg> |
|
35 #include <draw.rsg> |
|
36 |
|
37 #include "ResolutionUtil.h" |
|
38 #include "selectionpopup.h" |
|
39 #include "ImageEditorUiDefs.h" |
|
40 |
|
41 // CONSTANTS |
|
42 const TInt KGridColumnCount = 5; |
|
43 const TInt KGridRowCount = 1; |
|
44 |
|
45 |
|
46 //============================================================================= |
|
47 CSelectionPopup::CSelectionPopup() |
|
48 { |
|
49 // Set values into an array |
|
50 iItemArray.Append( 4 ); |
|
51 iItemArray.Append( 8 ); |
|
52 iItemArray.Append( 16 ); |
|
53 iItemArray.Append( 32 ); |
|
54 iItemArray.Append( 64 ); |
|
55 } |
|
56 |
|
57 //============================================================================= |
|
58 CSelectionPopup::~CSelectionPopup() |
|
59 { |
|
60 delete iPopupCenter; |
|
61 delete iPopupCenterMask; |
|
62 delete iPopupCornerTL; |
|
63 delete iPopupCornerTLMask; |
|
64 delete iPopupCornerTR; |
|
65 delete iPopupCornerTRMask; |
|
66 delete iPopupCornerBL; |
|
67 delete iPopupCornerBLMask; |
|
68 delete iPopupCornerBR; |
|
69 delete iPopupCornerBRMask; |
|
70 delete iPopupSideL; |
|
71 delete iPopupSideLMask; |
|
72 delete iPopupSideR; |
|
73 delete iPopupSideRMask; |
|
74 delete iPopupSideT; |
|
75 delete iPopupSideTMask; |
|
76 delete iPopupSideB; |
|
77 delete iPopupSideBMask; |
|
78 |
|
79 iHighlightRectsArray.Close(); |
|
80 iGridRectsArray.Close(); |
|
81 iColorBitmapsArray.ResetAndDestroy(); |
|
82 iItemArray.Close(); |
|
83 } |
|
84 |
|
85 //============================================================================= |
|
86 void CSelectionPopup::ConstructL ( CCoeControl* aParent ) |
|
87 { |
|
88 // Set parent |
|
89 SetContainerWindowL( *aParent ); |
|
90 TFileName iconFile( KImageEditorUiMifFile ); |
|
91 |
|
92 // Create trans popup window graphics |
|
93 // Center |
|
94 AknIconUtils::CreateIconL( iPopupCenter, iPopupCenterMask, iconFile, |
|
95 EMbmImageeditoruiQgn_graf_popup_trans_center, |
|
96 EMbmImageeditoruiQgn_graf_popup_trans_center_mask ); |
|
97 |
|
98 // Top-left corner |
|
99 AknIconUtils::CreateIconL( iPopupCornerTL, iPopupCornerTLMask, iconFile, |
|
100 EMbmImageeditoruiQgn_graf_popup_trans_corner_tl, |
|
101 EMbmImageeditoruiQgn_graf_popup_trans_corner_tl_mask ); |
|
102 |
|
103 // Top-right corner |
|
104 AknIconUtils::CreateIconL( iPopupCornerTR, iPopupCornerTRMask, iconFile, |
|
105 EMbmImageeditoruiQgn_graf_popup_trans_corner_tr, |
|
106 EMbmImageeditoruiQgn_graf_popup_trans_corner_tr_mask ); |
|
107 |
|
108 // Bottom-left corner |
|
109 AknIconUtils::CreateIconL( iPopupCornerBL, iPopupCornerBLMask, iconFile, |
|
110 EMbmImageeditoruiQgn_graf_popup_trans_corner_bl, |
|
111 EMbmImageeditoruiQgn_graf_popup_trans_corner_bl_mask ); |
|
112 |
|
113 // Bottom-right corner |
|
114 AknIconUtils::CreateIconL( iPopupCornerBR, iPopupCornerBRMask, iconFile, |
|
115 EMbmImageeditoruiQgn_graf_popup_trans_corner_br, |
|
116 EMbmImageeditoruiQgn_graf_popup_trans_corner_br_mask ); |
|
117 |
|
118 // left side |
|
119 AknIconUtils::CreateIconL( iPopupSideL, iPopupSideLMask, iconFile, |
|
120 EMbmImageeditoruiQgn_graf_popup_trans_side_l, |
|
121 EMbmImageeditoruiQgn_graf_popup_trans_side_l_mask ); |
|
122 |
|
123 // left side |
|
124 AknIconUtils::CreateIconL( iPopupSideR, iPopupSideRMask, iconFile, |
|
125 EMbmImageeditoruiQgn_graf_popup_trans_side_r, |
|
126 EMbmImageeditoruiQgn_graf_popup_trans_side_r_mask ); |
|
127 |
|
128 // top side |
|
129 AknIconUtils::CreateIconL( iPopupSideT, iPopupSideTMask, iconFile, |
|
130 EMbmImageeditoruiQgn_graf_popup_trans_side_t, |
|
131 EMbmImageeditoruiQgn_graf_popup_trans_side_t_mask ); |
|
132 |
|
133 // bottom side |
|
134 AknIconUtils::CreateIconL( iPopupSideB, iPopupSideBMask, iconFile, |
|
135 EMbmImageeditoruiQgn_graf_popup_trans_side_b, |
|
136 EMbmImageeditoruiQgn_graf_popup_trans_side_b_mask ); |
|
137 |
|
138 // Activate control |
|
139 ActivateL(); |
|
140 |
|
141 } |
|
142 |
|
143 //============================================================================= |
|
144 void CSelectionPopup::CreateColorBitmapsL( TSize aSize ) |
|
145 { |
|
146 // Generate color bitmaps |
|
147 iColorBitmapsArray.Reset(); |
|
148 for( TInt i = 0; i < iItemArray.Count(); i++ ) |
|
149 { |
|
150 CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap; |
|
151 CleanupStack::PushL( bitmap ); |
|
152 User::LeaveIfError ( bitmap->Create ( aSize, EColor64K ) ); |
|
153 |
|
154 // Compute color for bitmap |
|
155 TRgb color( KRgbBlack );//iRGBArray[i] ); |
|
156 |
|
157 // Fill the bitmap with the correct color |
|
158 TUint16 color_64k = ( TUint16 ) |
|
159 (0 | |
|
160 ((( TUint8 )color.Red() >> 3) << 11) | |
|
161 ((( TUint8 )color.Green() >> 2) << 5) | |
|
162 (( TUint8 )color.Blue() >> 3)); |
|
163 |
|
164 bitmap->LockHeapLC(); |
|
165 TUint16 * pd = (TUint16 *)bitmap->DataAddress(); |
|
166 TSize size = bitmap->SizeInPixels(); |
|
167 TInt w = (bitmap->ScanLineLength(size.iWidth, EColor64K) >> 1) |
|
168 * size.iHeight; |
|
169 for( TInt k = w; k != 0; --k) |
|
170 { |
|
171 *pd++ = color_64k; |
|
172 } |
|
173 |
|
174 iColorBitmapsArray.Append( bitmap ); |
|
175 |
|
176 CleanupStack::PopAndDestroy(); // LockHeapLC() |
|
177 CleanupStack::Pop(); // bitmap |
|
178 |
|
179 } |
|
180 |
|
181 } |
|
182 |
|
183 //============================================================================= |
|
184 void CSelectionPopup::Draw( const TRect& /*aRect*/ ) const |
|
185 { |
|
186 const TRgb KHighlightCenterColor (229, 229, 229); |
|
187 |
|
188 CWindowGc& gc = SystemGc(); |
|
189 |
|
190 CPreviewControlBase::DrawPreviewImage (Rect()); |
|
191 |
|
192 // Change brush to null to enable transparent drawing |
|
193 gc.SetBrushStyle (CGraphicsContext::ENullBrush); |
|
194 |
|
195 // draw center of the borders |
|
196 gc.BitBltMasked( iPopupCenterRect.iTl, iPopupCenter, |
|
197 iPopupCenterRect.Size(), iPopupCenterMask, EFalse ); |
|
198 // draw Top left corner |
|
199 gc.BitBltMasked( iPopupCornerTLRect.iTl, iPopupCornerTL, |
|
200 iPopupCornerTLRect.Size(), iPopupCornerTLMask, EFalse ); |
|
201 // draw Top right corner |
|
202 gc.BitBltMasked( iPopupCornerTRRect.iTl, iPopupCornerTR, |
|
203 iPopupCornerTRRect.Size(), iPopupCornerTRMask, EFalse ); |
|
204 // draw Bottom left corner |
|
205 gc.BitBltMasked( iPopupCornerBLRect.iTl, iPopupCornerBL, |
|
206 iPopupCornerBLRect.Size(), iPopupCornerBLMask, EFalse ); |
|
207 // draw Bottom right corner |
|
208 gc.BitBltMasked( iPopupCornerBRRect.iTl, iPopupCornerBR, |
|
209 iPopupCornerBRRect.Size(), iPopupCornerBRMask, EFalse ); |
|
210 // draw Left side |
|
211 gc.BitBltMasked( iPopupSideLRect.iTl, iPopupSideL, |
|
212 iPopupSideLRect.Size(), iPopupSideLMask, EFalse ); |
|
213 // draw Right side |
|
214 gc.BitBltMasked( iPopupSideRRect.iTl, iPopupSideR, |
|
215 iPopupSideRRect.Size(), iPopupSideRMask, EFalse ); |
|
216 // draw Top side |
|
217 gc.BitBltMasked( iPopupSideTRect.iTl, iPopupSideT, |
|
218 iPopupSideTRect.Size(), iPopupSideTMask, EFalse ); |
|
219 // draw Bottom side |
|
220 gc.BitBltMasked( iPopupSideBRect.iTl, iPopupSideB, |
|
221 iPopupSideBRect.Size(), iPopupSideBMask, EFalse ); |
|
222 |
|
223 // Draw color items and selection indicator |
|
224 for( TInt index = 0; index < iGridRectsArray.Count(); index++ ) |
|
225 { |
|
226 // Draw selection indicator for current item |
|
227 if( index == iCurrentItem ) |
|
228 { |
|
229 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
230 gc.SetBrushColor( KHighlightCenterColor ); |
|
231 gc.SetPenColor( KRgbBlack ); |
|
232 gc.SetPenSize( TSize(2,2) ); |
|
233 gc.DrawRect( iHighlightRectsArray[ iCurrentItem ] ); |
|
234 |
|
235 gc.SetBrushStyle (CGraphicsContext::ENullBrush); |
|
236 } |
|
237 |
|
238 // draw color bitmap |
|
239 TRect currentRect = iGridRectsArray[index]; |
|
240 gc.BitBlt(currentRect.iTl, iColorBitmapsArray[index]); |
|
241 } |
|
242 |
|
243 // Draw heading |
|
244 // Convert the plug-in name to visual representation |
|
245 // (in case would be right-to-left) |
|
246 const CFont* font = NULL; |
|
247 font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont ); |
|
248 TBuf<256> visual; |
|
249 // Text to be converted |
|
250 HBufC * heading = ControlEnv()->AllocReadResourceLC ( R_TITLE_LINE_WEIGHT ); |
|
251 |
|
252 AknBidiTextUtils::ConvertToVisualAndClip( |
|
253 heading->Des(), |
|
254 visual, |
|
255 *font, |
|
256 iHeadingRect.Width(), |
|
257 iHeadingRect.Width() |
|
258 ); |
|
259 |
|
260 CleanupStack::PopAndDestroy( heading ); |
|
261 |
|
262 gc.UseFont( font ); |
|
263 gc.SetBrushStyle ( CGraphicsContext::ENullBrush ); |
|
264 |
|
265 TInt baseline = iHeadingRect.Height() / 2 + font->AscentInPixels() / 2; |
|
266 |
|
267 // Check the directionality of the current language and set the alignment |
|
268 // according the directionality |
|
269 TBidiText::TDirectionality dir = TBidiText::ScriptDirectionality(User::Language()); |
|
270 CGraphicsContext::TTextAlign align = CGraphicsContext::ELeft; |
|
271 |
|
272 if( dir == TBidiText::ERightToLeft ) |
|
273 { |
|
274 align = CGraphicsContext::ERight; |
|
275 } |
|
276 gc.SetPenColor(KRgbWhite); |
|
277 gc.DrawText( |
|
278 visual, |
|
279 iHeadingRect, |
|
280 baseline, |
|
281 align, |
|
282 0); |
|
283 } |
|
284 |
|
285 //============================================================================= |
|
286 void CSelectionPopup::SizeChanged() |
|
287 { |
|
288 |
|
289 TAknLayoutRect layoutRect; |
|
290 layoutRect.LayoutRect( Rect(), AknLayoutScalable_Apps::popup_imed_trans_window(0) ); |
|
291 TRect parentRect = layoutRect.Rect(); |
|
292 |
|
293 TAknLayoutRect iconLayout; |
|
294 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g1()); |
|
295 iPopupCenterRect = iconLayout.Rect(); |
|
296 |
|
297 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2()); |
|
298 iPopupCornerTLRect = iconLayout.Rect(); |
|
299 |
|
300 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g3()); |
|
301 iPopupCornerTRRect = iconLayout.Rect(); |
|
302 |
|
303 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g4()); |
|
304 iPopupCornerBLRect = iconLayout.Rect(); |
|
305 |
|
306 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g5()); |
|
307 iPopupCornerBRRect = iconLayout.Rect(); |
|
308 |
|
309 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g6()); |
|
310 iPopupSideLRect = iconLayout.Rect(); |
|
311 |
|
312 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g7()); |
|
313 iPopupSideRRect = iconLayout.Rect(); |
|
314 |
|
315 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g8()); |
|
316 iPopupSideTRect = iconLayout.Rect(); |
|
317 |
|
318 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g9()); |
|
319 iPopupSideBRect = iconLayout.Rect(); |
|
320 |
|
321 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Apps::listscroll_imed_pane()); |
|
322 TRect listscrollPaneRect = iconLayout.Rect(); |
|
323 |
|
324 iconLayout.LayoutRect( listscrollPaneRect, AknLayoutScalable_Apps::grid_imed_colour_35_pane( 1 )); |
|
325 TRect gridPaneRect = iconLayout.Rect(); |
|
326 |
|
327 // Calculate grid's cell rects |
|
328 iHighlightRectsArray.Reset(); |
|
329 iGridRectsArray.Reset(); |
|
330 for( TInt row = 0; row < KGridRowCount; row++ ) |
|
331 { |
|
332 for( TInt column = 0; column < KGridColumnCount; column++ ) |
|
333 { |
|
334 iconLayout.LayoutRect( gridPaneRect, |
|
335 AknLayoutScalable_Apps::cell_imed_colour_pane(0 , column, row )); |
|
336 TRect highlightRect = iconLayout.Rect(); |
|
337 iHighlightRectsArray.Append( highlightRect ); |
|
338 |
|
339 iconLayout.LayoutRect( highlightRect, |
|
340 AknLayoutScalable_Apps::cell_imed_colour_pane_g1(0) ); |
|
341 |
|
342 iGridRectsArray.Append( iconLayout.Rect() ); |
|
343 |
|
344 } |
|
345 } |
|
346 |
|
347 CreateColorBitmapsL( iconLayout.Rect().Size() ); |
|
348 |
|
349 //Heading rect |
|
350 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Apps::heading_imed_pane()); |
|
351 TRect heading = iconLayout.Rect(); |
|
352 |
|
353 TAknLayoutText layoutText; |
|
354 layoutText.LayoutText( heading, AknLayoutScalable_Apps::heading_imed_pane_t1() ); |
|
355 iHeadingRect = layoutText.TextRect(); |
|
356 iLayoutTextHeading = layoutText; |
|
357 |
|
358 // Resize graphics to correct size |
|
359 AknIconUtils::SetSize( iPopupCenter, iPopupCenterRect.Size(), EAspectRatioNotPreserved); |
|
360 AknIconUtils::SetSize( iPopupCornerTL, iPopupCornerTLRect.Size(), EAspectRatioNotPreserved); |
|
361 AknIconUtils::SetSize( iPopupCornerTR, iPopupCornerTRRect.Size(), EAspectRatioNotPreserved); |
|
362 AknIconUtils::SetSize( iPopupCornerBL, iPopupCornerBLRect.Size(), EAspectRatioNotPreserved); |
|
363 AknIconUtils::SetSize( iPopupCornerBR, iPopupCornerBRRect.Size(), EAspectRatioNotPreserved); |
|
364 AknIconUtils::SetSize( iPopupSideL, iPopupSideLRect.Size(), EAspectRatioNotPreserved); |
|
365 AknIconUtils::SetSize( iPopupSideR, iPopupSideRRect.Size(), EAspectRatioNotPreserved); |
|
366 AknIconUtils::SetSize( iPopupSideT, iPopupSideTRect.Size(), EAspectRatioNotPreserved); |
|
367 AknIconUtils::SetSize( iPopupSideB, iPopupSideBRect.Size(), EAspectRatioNotPreserved); |
|
368 |
|
369 } |
|
370 |
|
371 //============================================================================= |
|
372 TKeyResponse CSelectionPopup::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
373 TEventCode aType ) |
|
374 { |
|
375 TKeyResponse res = EKeyWasNotConsumed; |
|
376 |
|
377 if (aType == EEventKey) |
|
378 { |
|
379 // If in landscape mode, do different mapping for the number keys. |
|
380 TUint keyCode = aKeyEvent.iCode; |
|
381 TBool landscape = CResolutionUtil::Self()->GetLandscape(); |
|
382 if (landscape) |
|
383 { |
|
384 switch (keyCode) |
|
385 { |
|
386 case 49: // numeric keypad '1' |
|
387 keyCode = 55; |
|
388 break; |
|
389 case 50: // numeric keypad '2' |
|
390 keyCode = 52; |
|
391 break; |
|
392 case 51: // numeric keypad '3' |
|
393 keyCode = 49; |
|
394 break; |
|
395 case 52: // numeric keypad '4' |
|
396 keyCode = 56; |
|
397 break; |
|
398 case 54: // numeric keypad '6' |
|
399 keyCode = 50; |
|
400 break; |
|
401 case 55: // numeric keypad '7' |
|
402 keyCode = 57; |
|
403 break; |
|
404 case 56: // numeric keypad '8' |
|
405 keyCode = 54; |
|
406 break; |
|
407 case 57: // numeric keypad '9' |
|
408 keyCode = 51; |
|
409 break; |
|
410 default: |
|
411 break; |
|
412 } |
|
413 } |
|
414 |
|
415 switch (keyCode) |
|
416 { |
|
417 case EKeyLeftArrow: |
|
418 case 52: // numeric keypad '4' |
|
419 { |
|
420 if (iCurrentItem == 0) |
|
421 { |
|
422 iCurrentItem = iGridRectsArray.Count() - 1; |
|
423 } |
|
424 else |
|
425 { |
|
426 iCurrentItem--; |
|
427 } |
|
428 |
|
429 res = EKeyWasConsumed; |
|
430 break; |
|
431 } |
|
432 |
|
433 case EKeyRightArrow: |
|
434 case 54: // numeric keypad '6' |
|
435 { |
|
436 iCurrentItem++; |
|
437 if (iCurrentItem >= iGridRectsArray.Count()) |
|
438 { |
|
439 iCurrentItem = 0; |
|
440 } |
|
441 |
|
442 res = EKeyWasConsumed; |
|
443 break; |
|
444 } |
|
445 |
|
446 case EKeyDownArrow: |
|
447 case 56: // numeric keypad '8' |
|
448 { |
|
449 iCurrentItem += KGridColumnCount; |
|
450 if (iCurrentItem >= iGridRectsArray.Count()) |
|
451 { |
|
452 iCurrentItem = iCurrentItem - iGridRectsArray.Count(); |
|
453 } |
|
454 |
|
455 res = EKeyWasConsumed; |
|
456 break; |
|
457 } |
|
458 |
|
459 case EKeyUpArrow: |
|
460 case 50: // numeric keypad '2' |
|
461 { |
|
462 iCurrentItem -= KGridColumnCount; |
|
463 if (iCurrentItem < 0) |
|
464 { |
|
465 iCurrentItem = iGridRectsArray.Count() + iCurrentItem; |
|
466 } |
|
467 |
|
468 res = EKeyWasConsumed; |
|
469 break; |
|
470 } |
|
471 |
|
472 case 49: // numeric keypad '1' |
|
473 { |
|
474 // Move up and left |
|
475 iCurrentItem -= KGridColumnCount; |
|
476 iCurrentItem --; |
|
477 if (iCurrentItem < 0) |
|
478 { |
|
479 iCurrentItem = iGridRectsArray.Count() + iCurrentItem; |
|
480 } |
|
481 res = EKeyWasConsumed; |
|
482 break; |
|
483 } |
|
484 |
|
485 case 51: // numeric keypad '3' |
|
486 { |
|
487 // Move up and right |
|
488 iCurrentItem -= KGridColumnCount; |
|
489 iCurrentItem ++; |
|
490 if (iCurrentItem < 0) |
|
491 { |
|
492 iCurrentItem = iGridRectsArray.Count() + iCurrentItem; |
|
493 } |
|
494 res = EKeyWasConsumed; |
|
495 break; |
|
496 } |
|
497 |
|
498 case 55: // numeric keypad '7' |
|
499 { |
|
500 // Move down and left |
|
501 iCurrentItem += KGridColumnCount; |
|
502 iCurrentItem--; |
|
503 if (iCurrentItem >= iGridRectsArray.Count()) |
|
504 { |
|
505 iCurrentItem = iCurrentItem - iGridRectsArray.Count(); |
|
506 } |
|
507 res = EKeyWasConsumed; |
|
508 break; |
|
509 } |
|
510 |
|
511 case 57: // numeric keypad '9' |
|
512 { |
|
513 // Move down and left |
|
514 iCurrentItem += KGridColumnCount; |
|
515 iCurrentItem++; |
|
516 if (iCurrentItem >= iGridRectsArray.Count()) |
|
517 { |
|
518 iCurrentItem = iCurrentItem - iGridRectsArray.Count(); |
|
519 } |
|
520 res = EKeyWasConsumed; |
|
521 break; |
|
522 } |
|
523 |
|
524 default: |
|
525 { |
|
526 break; |
|
527 } |
|
528 } |
|
529 } |
|
530 |
|
531 return res; |
|
532 |
|
533 } |
|
534 |
|
535 //============================================================================= |
|
536 void CSelectionPopup::HandlePointerEventL( const TPointerEvent &aPointerEvent ) |
|
537 { |
|
538 if( AknLayoutUtils::PenEnabled() ) |
|
539 { |
|
540 switch( aPointerEvent.iType ) |
|
541 { |
|
542 case TPointerEvent::EButton1Down: |
|
543 case TPointerEvent::EDrag: |
|
544 { |
|
545 // calculate which one of the grid items was pressed by |
|
546 // by comparing item rects and pressed position |
|
547 for (TInt i = 0; i < iHighlightRectsArray.Count(); ++i) |
|
548 { |
|
549 TRect iconRect( iHighlightRectsArray[i] ); |
|
550 |
|
551 if( iconRect.Contains( aPointerEvent.iPosition ) ) |
|
552 { |
|
553 // set new highlighted item |
|
554 iCurrentItem = i; |
|
555 break; |
|
556 } |
|
557 } |
|
558 break; |
|
559 } |
|
560 case TPointerEvent::EButton1Up: |
|
561 { |
|
562 break; |
|
563 } |
|
564 default: |
|
565 { |
|
566 break; |
|
567 } |
|
568 } |
|
569 } |
|
570 } |
|
571 |
|
572 //============================================================================= |
|
573 TRect CSelectionPopup::GridRect() const |
|
574 { |
|
575 return iPopupCenterRect; |
|
576 } |
|
577 |
|
578 //============================================================================= |
|
579 TBool CSelectionPopup::HighlightedItemPressed( TPoint aPosition ) const |
|
580 { |
|
581 TRect iconRect = iHighlightRectsArray[ iCurrentItem ]; |
|
582 |
|
583 if (iconRect.Contains( aPosition )) |
|
584 { |
|
585 return ETrue; |
|
586 } |
|
587 else |
|
588 { |
|
589 return EFalse; |
|
590 } |
|
591 } |
|
592 |
|
593 //============================================================================= |
|
594 void CSelectionPopup::SetSelectedValue( TInt aSelected ) |
|
595 { |
|
596 ASSERT( aSelected >= 0 ); |
|
597 iCurrentItem = iItemArray.Find( aSelected ); |
|
598 } |
|
599 |
|
600 //============================================================================= |
|
601 TInt CSelectionPopup::GetSelectedValue() const |
|
602 { |
|
603 ASSERT( iCurrentItem >= 0 && iCurrentItem < iItemArray.Count() ); |
|
604 return iItemArray[iCurrentItem]; |
|
605 } |
|
606 |
|
607 |
|
608 //============================================================================= |
|
609 // DIALOG |
|
610 //============================================================================= |
|
611 TInt CSelectionDialog::RunDlgLD( const CFbsBitmap* aBitmap, |
|
612 const TRect& aRect, |
|
613 TInt& aSelection ) |
|
614 { |
|
615 CSelectionDialog* dialog = |
|
616 new (ELeave) CSelectionDialog ( aSelection ); |
|
617 dialog->ConstructL( aBitmap, aRect); |
|
618 return dialog->ExecuteLD( R_IMAGE_EDITOR_COLOR_DIALOG ); |
|
619 } |
|
620 |
|
621 //============================================================================= |
|
622 CSelectionDialog::CSelectionDialog( TInt& aSelection ) |
|
623 : iCurrentValue( aSelection ) |
|
624 { |
|
625 } |
|
626 |
|
627 //============================================================================= |
|
628 CSelectionDialog::~CSelectionDialog() |
|
629 { |
|
630 delete iPopup; |
|
631 } |
|
632 |
|
633 //============================================================================= |
|
634 |
|
635 void CSelectionDialog::ConstructL( const CFbsBitmap* aBitmap, |
|
636 const TRect& aRect ) |
|
637 { |
|
638 iPopup = new ( ELeave ) CSelectionPopup(); |
|
639 iPopup->SetSelectedValue( iCurrentValue); |
|
640 iPopup->ConstructL( this ); |
|
641 |
|
642 SetRect(aRect); |
|
643 |
|
644 // Not drawn correctly if calling SetRect() |
|
645 iPopup->SetSize(aRect.Size()); |
|
646 iPopup->SetPosition(TPoint(0,0)); |
|
647 iPopup->SetImageL( aBitmap ); |
|
648 } |
|
649 |
|
650 //============================================================================= |
|
651 TBool CSelectionDialog::OkToExitL( TInt aButtonId ) |
|
652 { |
|
653 if ( aButtonId == EAknSoftkeyOk || aButtonId == EAknSoftkeySelect) |
|
654 { |
|
655 iCurrentValue = iPopup->GetSelectedValue(); |
|
656 return ETrue; |
|
657 } |
|
658 else |
|
659 { |
|
660 return EFalse; |
|
661 } |
|
662 } |
|
663 |
|
664 //============================================================================= |
|
665 void CSelectionDialog::Draw(const TRect& /*aRect*/) const |
|
666 { |
|
667 } |
|
668 |
|
669 //============================================================================= |
|
670 void CSelectionDialog::SizeChanged() |
|
671 { |
|
672 } |
|
673 |
|
674 //============================================================================= |
|
675 void CSelectionDialog::PreLayoutDynInitL() |
|
676 { |
|
677 } |
|
678 |
|
679 |
|
680 //============================================================================= |
|
681 TInt CSelectionDialog::CountComponentControls() const |
|
682 { |
|
683 return 1; |
|
684 } |
|
685 |
|
686 //============================================================================= |
|
687 CCoeControl* CSelectionDialog::ComponentControl(TInt /*aIndex*/) const |
|
688 { |
|
689 return iPopup; |
|
690 } |
|
691 |
|
692 //============================================================================= |
|
693 TKeyResponse CSelectionDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
694 { |
|
695 // Selection key or numeric keypad '5' close the dialog |
|
696 TKeyResponse res = EKeyWasNotConsumed; |
|
697 if (aType == EEventKey && |
|
698 (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == 53 || aKeyEvent.iScanCode == EStdKeyEnter) ) |
|
699 { |
|
700 TryExitL (EAknSoftkeyOk); |
|
701 res = EKeyWasConsumed; |
|
702 } |
|
703 else if (aType == EEventKey && aKeyEvent.iCode == EKeyNo || aKeyEvent.iCode == EKeyEscape) // Do not exit if dialog active |
|
704 { |
|
705 TryExitL (EAknSoftkeyCancel); |
|
706 res = EKeyWasNotConsumed; |
|
707 } |
|
708 #ifdef FULLSCREEN_AVAILABLE |
|
709 else if (aType == EEventKey && aKeyEvent.iCode == 48 ) // 0 |
|
710 { |
|
711 // Switch normal screen / full screen |
|
712 if (CResolutionUtil::Self()->GetFullScreen()) |
|
713 { |
|
714 iEikonEnv->EikAppUi()->HandleCommandL(EImageEditorMenuCmdNormalScreen); |
|
715 SetRect(iEikonEnv->EikAppUi()->ClientRect()); |
|
716 SizeChanged(); |
|
717 DrawNow(); |
|
718 } |
|
719 else |
|
720 { |
|
721 iEikonEnv->EikAppUi()->HandleCommandL(EImageEditorMenuCmdFullScreen); |
|
722 SetExtentToWholeScreen(); |
|
723 SizeChanged(); |
|
724 DrawNow(); |
|
725 } |
|
726 res = EKeyWasConsumed; |
|
727 } |
|
728 #endif // FULLSCREEN_AVAILABLE |
|
729 else |
|
730 { |
|
731 res = iPopup->OfferKeyEventL(aKeyEvent, aType); |
|
732 if (res == EKeyWasConsumed) |
|
733 { |
|
734 DrawDeferred(); |
|
735 } |
|
736 } |
|
737 |
|
738 return res; |
|
739 } |
|
740 |
|
741 //============================================================================= |
|
742 void CSelectionDialog::HandlePointerEventL( |
|
743 const TPointerEvent &aPointerEvent ) |
|
744 { |
|
745 if( AknLayoutUtils::PenEnabled() ) |
|
746 { |
|
747 TBool draw( EFalse ); |
|
748 switch( aPointerEvent.iType ) |
|
749 { |
|
750 case TPointerEvent::EButton1Down: |
|
751 { |
|
752 // forward event only if grid area was pressed |
|
753 if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) ) |
|
754 { |
|
755 iPopup->HandlePointerEventL( aPointerEvent ); |
|
756 draw = ETrue; |
|
757 } |
|
758 break; |
|
759 } |
|
760 case TPointerEvent::EDrag: |
|
761 { |
|
762 if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) ) |
|
763 { |
|
764 iPopup->HandlePointerEventL( aPointerEvent ); |
|
765 draw = ETrue; |
|
766 } |
|
767 break; |
|
768 } |
|
769 case TPointerEvent::EButton1Up: |
|
770 { |
|
771 // already highlighted item is pressed |
|
772 if ( iPopup->HighlightedItemPressed( aPointerEvent.iPosition ) ) |
|
773 { |
|
774 TryExitL (EAknSoftkeyOk); |
|
775 } |
|
776 break; |
|
777 } |
|
778 default: |
|
779 { |
|
780 break; |
|
781 } |
|
782 } |
|
783 |
|
784 if ( draw ) |
|
785 { |
|
786 DrawDeferred(); |
|
787 } |
|
788 } |
|
789 } |
|
790 |
|
791 // End of file |
|
792 |