|
1 /* |
|
2 * Copyright (c) 2002-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // AknPopupField.cpp |
|
19 // |
|
20 // Copyright (c) 1997-2001 Symbian Ltd. All rights reserved. |
|
21 // |
|
22 |
|
23 #include <barsread.h> |
|
24 #include <gulicon.h> |
|
25 #include <AknIconArray.h> |
|
26 #include <eikmop.h> |
|
27 |
|
28 #include "AknPopupField.h" |
|
29 #include "AknQueryValue.h" |
|
30 #include "aknlists.h" |
|
31 #include "AknDef.h" |
|
32 #include <AknsDrawUtils.h> |
|
33 #include <AknsBasicBackgroundControlContext.h> |
|
34 #include <AknsListBoxBackgroundControlContext.h> |
|
35 #include <AknIconUtils.h> |
|
36 #include <AknsPointerStore.h> |
|
37 #include <AknsFrameBackgroundControlContext.h> |
|
38 #include <skinlayout.cdl.h> |
|
39 #include <aknlayoutscalable_avkon.cdl.h> |
|
40 #include <touchfeedback.h> |
|
41 |
|
42 _LIT(KPopFieldLeadingLayoutTextActive, "1\t"); |
|
43 _LIT(KPopFieldLeadingLayoutTextInactive, "\t\t"); |
|
44 const TInt KDefaultMaxNoLines = 6; |
|
45 |
|
46 class CAknPopupFieldExtension : public CBase |
|
47 { |
|
48 public: |
|
49 TRect iFormFieldRect; // moved to extension |
|
50 TInt iEditTextPos; // position of editable text inside form. 0..5 based on Form data field texts, line 2 baseline from 2.6 spec. |
|
51 CAknsFrameBackgroundControlContext *iFrameSkinContext; // this will be linked to listbox's context as background. |
|
52 CAknsBasicBackgroundControlContext *iBgContext; |
|
53 MTouchFeedback* iFeedback; |
|
54 TInt iOldItemIndex; |
|
55 TBool iSingleClickEnabled; |
|
56 }; |
|
57 |
|
58 |
|
59 //*******************************************************************************************/ |
|
60 // AknPopupFieldBitmapButton |
|
61 |
|
62 CAknPopupField::CAknPopupFieldBitmapButton::CAknPopupFieldBitmapButton() |
|
63 { |
|
64 // set all margins to zero, we just want the bitmap with no margin |
|
65 iMargins.iTop = 0; |
|
66 iMargins.iBottom = 0; |
|
67 iMargins.iLeft = 0; |
|
68 iMargins.iRight = 0; |
|
69 } |
|
70 |
|
71 |
|
72 //*******************************************************************************************/ |
|
73 // CAknPopupField |
|
74 |
|
75 EXPORT_C CAknPopupField::CAknPopupField() |
|
76 : iCba( NULL ), |
|
77 iFormMode( EAknFormModeView ), |
|
78 iSelectionMode(EAknPopupFieldLabelMode), |
|
79 iMaxNoLines(KDefaultMaxNoLines) |
|
80 { |
|
81 } |
|
82 |
|
83 EXPORT_C CAknPopupField::~CAknPopupField() |
|
84 { |
|
85 delete iAttemptExitAsync; |
|
86 delete iLabel; |
|
87 delete iButton; |
|
88 DestroyPopout(); |
|
89 delete iLayoutDecorator; |
|
90 delete iOtherText; |
|
91 delete iEmptyText; |
|
92 delete iInvalidText; |
|
93 delete iCba; |
|
94 if (iExtension) |
|
95 delete iExtension->iBgContext; |
|
96 if (iExtension) |
|
97 delete iExtension->iFrameSkinContext; |
|
98 delete iExtension; |
|
99 } |
|
100 |
|
101 EXPORT_C void CAknPopupField::ConstructL() |
|
102 { |
|
103 iEmptyText->Des() = KNullDesC; |
|
104 iInvalidText->Des() = KNullDesC; |
|
105 |
|
106 |
|
107 CommonConstructL(); |
|
108 } |
|
109 |
|
110 EXPORT_C void CAknPopupField::ConstructFromResourceL(TResourceReader& aReader) |
|
111 { |
|
112 iFlags=aReader.ReadInt16(); |
|
113 iWidth=aReader.ReadInt16(); |
|
114 iOtherText = aReader.ReadHBufCL(); |
|
115 iEmptyNoteResourceId = aReader.ReadInt32(); |
|
116 iEmptyText = aReader.ReadHBufCL(); |
|
117 iInvalidText = aReader.ReadHBufCL(); |
|
118 |
|
119 CommonConstructL(); |
|
120 } |
|
121 EXPORT_C void CAknPopupField::SetFormFieldRect(TRect aRect) |
|
122 { // captioned control will call this |
|
123 if (iExtension) |
|
124 iExtension->iFormFieldRect = aRect; |
|
125 } |
|
126 |
|
127 |
|
128 void CAknPopupField::CommonConstructL() |
|
129 { |
|
130 iExtension = new(ELeave)CAknPopupFieldExtension; |
|
131 iExtension->iSingleClickEnabled = static_cast<CAknAppUi*>( |
|
132 iCoeEnv->AppUi() )->IsSingleClickCompatible(); |
|
133 |
|
134 //iExtension = new(ELeave)CAknPopupFieldExtension; |
|
135 iExtension->iFormFieldRect = TRect(0,0,0,0); |
|
136 |
|
137 if (!iOtherText) |
|
138 iOtherText = HBufC::NewL(0); // set to zero length so we can then test for 0 length later |
|
139 |
|
140 iEmptyNoteTimeout = CAknNoteDialog::EShortTimeout; |
|
141 iEmptyNoteTone = CAknNoteDialog::ENoTone; |
|
142 |
|
143 ConstructLabelL(); |
|
144 if (iFlags & EAknPopupFieldFlagButton) |
|
145 ConstructCommandButtonL(); |
|
146 |
|
147 ConfigureDecorator(); |
|
148 ConstructLayoutDecoratorL(); |
|
149 |
|
150 // layer 1, main_pane background |
|
151 iExtension->iBgContext = CAknsListBoxBackgroundControlContext::NewL( |
|
152 KAknsIIDQsnBgAreaMainListGene, TRect(0,0,1,1), ETrue, |
|
153 KAknsIIDQsnBgColumnAB, TRect(0,0,1,1) ) ; |
|
154 |
|
155 //CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, TRect(0,0,1,1), ETrue); |
|
156 // layer 2, form field highlight |
|
157 iExtension->iFrameSkinContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrInput, TRect(0,0,1,1), TRect(0,0,1,1), ETrue); |
|
158 |
|
159 iExtension->iFeedback = MTouchFeedback::Instance(); |
|
160 } |
|
161 |
|
162 void CAknPopupField::ConstructLabelL() |
|
163 { |
|
164 if (iLabel) |
|
165 return; // already exists |
|
166 iLabel=new(ELeave) CEikLabel(); |
|
167 iLabel->SetContainerWindowL(*this); |
|
168 iLabel->SetTextL(KNullDesC); |
|
169 } |
|
170 |
|
171 void CAknPopupField::ConstructCommandButtonL() |
|
172 { |
|
173 } |
|
174 |
|
175 void CAknPopupField::ConstructSelectionListL() |
|
176 { |
|
177 if (iSelectionList) |
|
178 return; // already exists |
|
179 |
|
180 //TRect rect = Rect(); |
|
181 if ( iFormMode==EAknFormModeEdit || iFormMode==EAknFormModeView ) |
|
182 iSelectionList = new(ELeave) CAknFormGraphicStyleListBox; |
|
183 else if ( iFormMode==EAknFormModeEditWideWithoutGraphic || iFormMode==EAknFormModeViewWideWithoutGraphic ) |
|
184 iSelectionList = new(ELeave) CAknFormGraphicWideStyleListBox; |
|
185 else // wide with bitmap for now use wide style |
|
186 iSelectionList = new(ELeave) CAknFormGraphicWideStyleListBox; |
|
187 |
|
188 iSelectionList->ConstructWithWindowL(this, EAknListBoxMultipleSelection); |
|
189 // We dont want captionedcontrol's skin context, since captionedcontrol has |
|
190 // different coordinates. (window starts with 0,0). |
|
191 iSelectionList->SetMopParent(NULL); |
|
192 iSelectionList->SetParent(this); |
|
193 |
|
194 iSelectionList->SetListBoxObserver(this); |
|
195 |
|
196 // set the array into the listbox |
|
197 iSelectionList->Model()->SetItemTextArray(iLayoutDecorator); |
|
198 iSelectionList->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
199 |
|
200 iSelectionList->SetObserver(this); |
|
201 |
|
202 InitialiseRadioButtonBitmapsL(); |
|
203 iSelectionList->ItemDrawer()->FormattedCellData()->SetControl(iSelectionList); |
|
204 //TRect screenRect = AknLayout::screen().Rect(); |
|
205 iSelectionList->ItemDrawer()->FormattedCellData()->SetBackgroundSkinStyle(&KAknsIIDQsnFrInput, iExtension->iFormFieldRect); |
|
206 } |
|
207 |
|
208 |
|
209 void CAknPopupField::SetUpScrollBarL() |
|
210 { |
|
211 if ( !iExtension || !iExtension->iSingleClickEnabled ) |
|
212 { |
|
213 __ASSERT_DEBUG( iCba, Panic( EAknPanicPopupFieldCBADoesntExist ) ); |
|
214 } |
|
215 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
216 iSelectionList->SetMopParent(this); // to get remote scb |
|
217 iSelectionList->CreateScrollBarFrameL(ETrue, ETrue); |
|
218 iSelectionList->SetMopParent(NULL); |
|
219 iSelectionList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
220 } |
|
221 |
|
222 void CAknPopupField::SetScrollBarSelectionL() |
|
223 { |
|
224 TInt selection = iValue->CurrentValueIndex(); |
|
225 if (IsInvalid()) selection = 0; |
|
226 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
227 iSelectionList->SetCurrentItemIndex(selection); |
|
228 iSelectionList->View()->SelectItemL(selection); |
|
229 |
|
230 if ( iExtension ) |
|
231 { |
|
232 iExtension->iOldItemIndex = iSelectionList->CurrentItemIndex(); |
|
233 } |
|
234 } |
|
235 |
|
236 |
|
237 void CAknPopupField::InitialiseRadioButtonBitmapsL() |
|
238 { |
|
239 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
240 TResourceReader reader; |
|
241 iCoeEnv->CreateResourceReaderLC(reader, R_AVKON_RADIOBUTT_BMP); |
|
242 |
|
243 HBufC* bmpFile = reader.ReadHBufCL(); |
|
244 TInt bmpSelected = reader.ReadInt16(); |
|
245 TInt bmpSelectedM = reader.ReadInt16(); |
|
246 TInt bmp = reader.ReadInt16(); |
|
247 TInt bmpM = reader.ReadInt16(); |
|
248 CleanupStack::PopAndDestroy(); // reader |
|
249 |
|
250 if (bmpFile == NULL) |
|
251 return; |
|
252 CleanupStack::PushL(bmpFile); |
|
253 |
|
254 if (iFlags & EAknPopupFieldNoGraphic) |
|
255 {// no graphic |
|
256 SetShowIndicatorsL(EFalse); |
|
257 } |
|
258 |
|
259 CArrayPtr<CGulIcon>* icons = iSelectionList->ItemDrawer()->FormattedCellData()->IconArray(); |
|
260 if ( icons ) |
|
261 { |
|
262 icons->ResetAndDestroy(); |
|
263 } |
|
264 else |
|
265 { |
|
266 icons = new(ELeave) CAknIconArray(2); |
|
267 iSelectionList->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons); // ownership transferred, cell data deletes all members of list |
|
268 } |
|
269 |
|
270 CFbsBitmap* bitmap = 0; |
|
271 CFbsBitmap* mask = 0; |
|
272 |
|
273 //AknIconUtils::CreateIconLC(bitmap, mask, *bmpFile, bmpSelected, bmpSelectedM); |
|
274 AknsUtils::CreateColorIconLC( skin, KAknsIIDQgnIndiRadiobuttOn, |
|
275 KAknsIIDQsnIconColors, |
|
276 EAknsCIQsnIconColorsCG15, |
|
277 bitmap, mask, *bmpFile, |
|
278 bmpSelected, |
|
279 bmpSelectedM, |
|
280 KRgbBlack); |
|
281 |
|
282 |
|
283 CGulIcon* gulicon = CGulIcon::NewL(bitmap,mask); // ownership passed |
|
284 CleanupStack::Pop(); // mask |
|
285 CleanupStack::Pop(); // bitmap |
|
286 CleanupStack::PushL(gulicon); |
|
287 icons->AppendL(gulicon); |
|
288 CleanupStack::Pop(); // gulicon |
|
289 |
|
290 bitmap = 0; |
|
291 mask = 0; |
|
292 |
|
293 //AknIconUtils::CreateIconLC(bitmap, mask, *bmpFile, bmp, bmpM); |
|
294 AknsUtils::CreateColorIconLC( skin, KAknsIIDQgnIndiRadiobuttOff, |
|
295 KAknsIIDQsnIconColors, |
|
296 EAknsCIQsnIconColorsCG15, |
|
297 bitmap, mask, *bmpFile, |
|
298 bmp, |
|
299 bmpM, |
|
300 KRgbBlack); |
|
301 |
|
302 |
|
303 CGulIcon* gulicon2 = CGulIcon::NewL(bitmap,mask); // ownership passed |
|
304 CleanupStack::Pop(); // mask |
|
305 CleanupStack::Pop(); // bitmap |
|
306 CleanupStack::PushL(gulicon2); |
|
307 icons->AppendL(gulicon2); |
|
308 CleanupStack::Pop(); // gulicon2 |
|
309 |
|
310 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
311 |
|
312 CleanupStack::PopAndDestroy(); // bmpfile |
|
313 } |
|
314 |
|
315 EXPORT_C TSize CAknPopupField::MinimumSize() |
|
316 { |
|
317 TSize size(0,0); |
|
318 TSize minTabSize(0,0); |
|
319 |
|
320 switch(iSelectionMode) |
|
321 { |
|
322 case EAknPopupFieldLabelMode: |
|
323 if (iLabel) |
|
324 size=iLabel->MinimumSize(); |
|
325 if (iButton) |
|
326 minTabSize = iButton->MinimumSize(); |
|
327 size.iWidth+=minTabSize.iWidth+iBorder.Margins().iLeft; |
|
328 size.iHeight=Max(size.iHeight+iBorder.SizeDelta().iHeight,minTabSize.iHeight); |
|
329 break; |
|
330 case EAknPopupFieldSelectionListMode: |
|
331 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
332 size = iSelectionList->MinimumSize(); |
|
333 break; |
|
334 default: |
|
335 __ASSERT_DEBUG(ETrue, Panic(EAknPanicPopupFieldUndefinedMode)); |
|
336 break; |
|
337 } |
|
338 return size; |
|
339 } |
|
340 |
|
341 |
|
342 EXPORT_C void CAknPopupField::SizeChanged() |
|
343 { |
|
344 TRAP_IGNORE(DoSizeChangedL()); |
|
345 } |
|
346 |
|
347 EXPORT_C void CAknPopupField::FocusChanged( TDrawNow aDrawNow ) |
|
348 { |
|
349 CEikBorderedControl::FocusChanged( aDrawNow ); |
|
350 if( iSelectionList ) |
|
351 { |
|
352 iSelectionList->SetFocus( IsFocused() ); |
|
353 } |
|
354 } |
|
355 |
|
356 void CAknPopupField::DoSizeChangedL() |
|
357 { |
|
358 // captioned control is supposed to set the iFormFieldRect before SizeChanged(). |
|
359 // note that the iLabel in Label mode is really implemented in wrong place -- popup field should not be |
|
360 // responsible of the label. |
|
361 __ASSERT_DEBUG(iExtension && iExtension->iFormFieldRect != TRect(0,0,0,0), Panic(EAknPanicPopupFieldNoFieldRectSet)); |
|
362 const TRect rect(Rect()); |
|
363 |
|
364 switch(iSelectionMode) |
|
365 { |
|
366 case EAknPopupFieldLabelMode: |
|
367 { |
|
368 #if 0 |
|
369 TInt mode = (( iFormMode==EAknFormModeEdit |
|
370 || iFormMode==EAknFormModeEditWideWithGraphic |
|
371 || iFormMode==EAknFormModeEditWideWithoutGraphic) |
|
372 && iButton) ? 0 : 1; |
|
373 TAknTextLineLayout labelLayout(AKN_LAYOUT_TEXT_List_pane_texts__form_graphic__Line_1(0,mode)); |
|
374 if ( iFormMode==EAknFormModeEdit || iFormMode==EAknFormModeView ) |
|
375 { |
|
376 labelLayout = AKN_LAYOUT_TEXT_List_pane_texts__form_graphic__Line_1(0,mode); |
|
377 } |
|
378 else if ( iFormMode==EAknFormModeEditWideWithoutGraphic || iFormMode==EAknFormModeViewWideWithoutGraphic ) |
|
379 { |
|
380 labelLayout = AKN_LAYOUT_TEXT_List_pane_texts__form_graphic_wide__Line_1(0, mode, 0,0); |
|
381 } |
|
382 else // wide with bitmap for now use wide style |
|
383 { |
|
384 labelLayout = AKN_LAYOUT_TEXT_List_pane_texts__form_graphic_wide__Line_1(0, mode, 0,0); |
|
385 } |
|
386 TAknTextLineLayout labelLayoutFormView(AKN_LAYOUT_TEXT_Form_data_field_texts_Line_2(0)); |
|
387 |
|
388 // labelLayout.iFont = labelLayoutFormView.iFont; // for view and edit mode need same font as in form, in expanded mode use from laf |
|
389 AknLayoutUtils::LayoutLabel(iLabel, rect, labelLayout, AknLayoutUtils::FontFromId(labelLayoutFormView.FontId())); |
|
390 #endif |
|
391 TAknTextLineLayout labelLayout(AknLayout::Form_data_field_texts_Line_2(0)); |
|
392 if (iFormMode == EAknFormModeEdit || iFormMode == EAknFormModeView) |
|
393 { |
|
394 labelLayout = AknLayout::Form_data_field_texts_Line_2(0); |
|
395 } |
|
396 else if ( iFormMode==EAknFormModeEditWideWithoutGraphic || iFormMode==EAknFormModeViewWideWithoutGraphic ) |
|
397 { |
|
398 labelLayout = AknLayout::Form_data_wide_field_texts_Line_2(0); |
|
399 } |
|
400 else // wide with bitmap for now use wide style |
|
401 { |
|
402 labelLayout = AknLayout::Form_data_wide_graphic_field_texts_Line_2(0); |
|
403 } |
|
404 AknLayoutUtils::LayoutLabel(iLabel, iExtension ? iExtension->iFormFieldRect : Rect(), labelLayout); |
|
405 |
|
406 if (iButton) |
|
407 AknLayoutUtils::LayoutControl(iButton, rect, AKN_LAYOUT_WINDOW_List_pane_elements__form_graphic__Line_2); |
|
408 |
|
409 if (IsInvalid()) |
|
410 { |
|
411 if (iInvalidText) |
|
412 { |
|
413 iLabel->SetTextL(*iInvalidText); // takes copy |
|
414 iLabel->CropText(); |
|
415 } |
|
416 else |
|
417 iLabel->SetTextL(KNullDesC); |
|
418 } |
|
419 else if (!IsEmpty()) |
|
420 { |
|
421 // update the label if the text should be changed due to the size change |
|
422 HBufC* newText = iValue->CurrentValueTextLC(); // ownership passed |
|
423 iLabel->SetTextL(*newText); // takes copy |
|
424 CleanupStack::PopAndDestroy(); // newText |
|
425 iLabel->CropText(); |
|
426 } |
|
427 else |
|
428 { |
|
429 if (iEmptyText) |
|
430 { |
|
431 iLabel->SetTextL(*iEmptyText); // takes copy |
|
432 iLabel->CropText(); |
|
433 } |
|
434 else |
|
435 iLabel->SetTextL(KNullDesC); |
|
436 } |
|
437 |
|
438 // reset the border to none |
|
439 if (iButton) |
|
440 iButton->SetBorder(TGulBorder::ENone); |
|
441 break; |
|
442 } |
|
443 case EAknPopupFieldSelectionListMode: |
|
444 { |
|
445 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
446 iSelectionList->SetRect(rect); |
|
447 AknsUtils::RegisterControlPosition(this); |
|
448 AknsUtils::RegisterControlPosition(iSelectionList); |
|
449 TRect listBoxRect = iExtension->iFormFieldRect; //iSelectionList->Rect(); |
|
450 listBoxRect.iTl = TPoint(0,0); |
|
451 // Cannot use KAknsIIDNone here because highlight animation |
|
452 // creation would fail in eikfrlbd.cpp (with KAknsIIDNone there |
|
453 // would be no background to animate). |
|
454 iSelectionList->ItemDrawer()->FormattedCellData()->SetBackgroundSkinStyle(&KAknsIIDNone, listBoxRect); |
|
455 //iSelectionList->ItemDrawer()->FormattedCellData()->SetBackgroundSkinStyle(&KAknsIIDNone /*Center*/, /*Rect()*/ /*TRect(0,0,176,208)*/); |
|
456 TAknLayoutRect frame_tl; |
|
457 frame_tl.LayoutRect(listBoxRect, SkinLayout::Input_field_skin_placing__general__Line_2()); |
|
458 TAknLayoutRect frame_br; |
|
459 frame_br.LayoutRect(listBoxRect, SkinLayout::Input_field_skin_placing__general__Line_5()); |
|
460 TRect center = TRect(frame_tl.Rect().iBr, frame_br.Rect().iTl); |
|
461 |
|
462 // |
|
463 // Skin contexts are in 3 layers: |
|
464 // 1) background |
|
465 // 2) form field highlight |
|
466 // 3) list context |
|
467 if (iExtension) |
|
468 { |
|
469 TRect main_pane; |
|
470 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, main_pane ); |
|
471 |
|
472 TRect clientRect = main_pane; |
|
473 TPoint ctrlPoint = PositionRelativeToScreen(); |
|
474 |
|
475 TPoint innerPoint = Rect().iTl; |
|
476 clientRect.iTl.iX -= ctrlPoint.iX; |
|
477 clientRect.iBr.iX -= ctrlPoint.iX; |
|
478 clientRect.iTl.iY -= ctrlPoint.iY; |
|
479 clientRect.iBr.iY -= ctrlPoint.iY; |
|
480 |
|
481 clientRect.iTl.iX += innerPoint.iX; |
|
482 clientRect.iBr.iX += innerPoint.iX; |
|
483 clientRect.iTl.iY += innerPoint.iY; |
|
484 clientRect.iBr.iY += innerPoint.iY; |
|
485 |
|
486 |
|
487 //TPoint p = clientRect.iTl; |
|
488 iExtension->iBgContext -> SetParentPos(main_pane.iTl); |
|
489 iExtension->iBgContext -> SetRect(clientRect /*TRect(c,clientRect.Size())*/); |
|
490 } |
|
491 |
|
492 if (iExtension) |
|
493 { |
|
494 // Calculate formfieldRect relative to screen. |
|
495 TPoint p; |
|
496 p = PositionRelativeToScreen(); |
|
497 p.iX += iExtension->iFormFieldRect.iTl.iX; |
|
498 p.iY += iExtension->iFormFieldRect.iTl.iY; |
|
499 p.iX -= Rect().iTl.iX; |
|
500 p.iY -= Rect().iTl.iY; |
|
501 iExtension->iFrameSkinContext -> SetParentPos( p /*iSelectionList->PositionRelativeToScreen()*/ ); |
|
502 |
|
503 |
|
504 iExtension->iFrameSkinContext -> SetFrameRects(listBoxRect, center); |
|
505 iExtension->iFrameSkinContext -> SetFrame(KAknsIIDQsnFrInput ); // frInput or frList? |
|
506 iExtension->iFrameSkinContext -> SetParentContext(iExtension->iBgContext); |
|
507 } |
|
508 CAknsBasicBackgroundControlContext *bgContext = (CAknsBasicBackgroundControlContext*)iSelectionList->ItemDrawer()->FormattedCellData()->SkinBackgroundContext(); |
|
509 if (iExtension) |
|
510 { |
|
511 bgContext->SetParentContext(iExtension->iFrameSkinContext); |
|
512 //iExtension->iFrameSkinContext -> SetParentPos( iSelectionList->PositionRelativeToScreen() ); |
|
513 |
|
514 } |
|
515 TRect main_pane = iAvkonAppUi->ClientRect(); |
|
516 |
|
517 TAknLayoutRect listscroll_form_pane_rect; |
|
518 listscroll_form_pane_rect.LayoutRect(main_pane, AknLayoutScalable_Avkon::listscroll_form_pane()); |
|
519 |
|
520 |
|
521 // set SVG icons (call SizeChanged between InitialiseRadioButtonBitmapsL and Draw) |
|
522 CArrayPtr<CGulIcon> *iconarray = 0; |
|
523 iconarray = iSelectionList->ItemDrawer()->FormattedCellData()->IconArray(); |
|
524 |
|
525 if (iconarray) |
|
526 { |
|
527 TInt iconCount = iconarray->Count(); |
|
528 if (iconCount) |
|
529 { |
|
530 TAknLayoutRect rect; |
|
531 rect.LayoutRect(Rect(), AKN_LAYOUT_WINDOW_List_pane_elements__form_graphic__Line_2); |
|
532 for (TInt i = 0 ; i < iconCount ; i++) |
|
533 AknIconUtils::SetSize((*iconarray)[i]->Bitmap(), rect.Rect().Size()); |
|
534 } |
|
535 } |
|
536 break; |
|
537 } |
|
538 default: |
|
539 __ASSERT_DEBUG(ETrue, Panic(EAknPanicPopupFieldUndefinedMode)); |
|
540 break; |
|
541 } |
|
542 iFlags |= EAknPopupFieldFlagInitialised; |
|
543 } |
|
544 |
|
545 |
|
546 EXPORT_C TKeyResponse CAknPopupField::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
547 { |
|
548 switch(iSelectionMode) |
|
549 { |
|
550 case EAknPopupFieldLabelMode: |
|
551 { |
|
552 TBool okPressed = aKeyEvent.iCode==EKeyTab || aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK; |
|
553 switch(aKeyEvent.iCode) |
|
554 { |
|
555 case EKeyTab: // fall through |
|
556 case EKeyEnter: // fall through |
|
557 case EKeyOK: |
|
558 if ((okPressed) && (!(aKeyEvent.iModifiers&EModifierCtrl) || aKeyEvent.iModifiers&EModifierPureKeycode)) |
|
559 { |
|
560 // note also that when page goes from view to edit mode, controls go from nonfocusing to focusing |
|
561 // therefore we only want focusing controls that have the focus |
|
562 if (!IsNonFocusing() && IsFocused()) |
|
563 { |
|
564 if (!IsEmpty()) |
|
565 { |
|
566 CreatePopoutL(); |
|
567 // In single click, enable highlight when opening |
|
568 // with hw key |
|
569 if ( iExtension |
|
570 && iExtension->iSingleClickEnabled |
|
571 && iSelectionList ) |
|
572 { |
|
573 TKeyEvent enterEvent( aKeyEvent ); |
|
574 enterEvent.iCode = EKeyEnter; |
|
575 iSelectionList->OfferKeyEventL( |
|
576 enterEvent, aType ); |
|
577 } |
|
578 } |
|
579 else |
|
580 ShowEmptyListNoteL(); |
|
581 return EKeyWasConsumed; |
|
582 } |
|
583 else |
|
584 return EKeyWasNotConsumed; |
|
585 } |
|
586 break; |
|
587 case EKeyLeftArrow: // fall through |
|
588 case EKeyRightArrow: |
|
589 return HandleHorizontalKeyEventL(aKeyEvent.iCode); |
|
590 default: |
|
591 return EKeyWasNotConsumed; |
|
592 } |
|
593 } |
|
594 break; |
|
595 case EAknPopupFieldSelectionListMode: |
|
596 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
597 return iSelectionList->OfferKeyEventL(aKeyEvent,aType); |
|
598 default: |
|
599 __ASSERT_DEBUG(ETrue, Panic(EAknPanicPopupFieldUndefinedMode)); |
|
600 break; |
|
601 } |
|
602 return EKeyWasConsumed; |
|
603 } |
|
604 |
|
605 EXPORT_C void CAknPopupField::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEvent) |
|
606 { |
|
607 switch (aEvent) |
|
608 { |
|
609 case EEventRequestFocus: // drop through |
|
610 case EEventPrepareFocusTransition: |
|
611 ReportEventL(aEvent); |
|
612 break; |
|
613 case EEventStateChanged: |
|
614 if (aControl != NULL && aControl==iButton) |
|
615 CreatePopoutL(); |
|
616 break; |
|
617 case EEventRequestExit: |
|
618 break; |
|
619 case EEventRequestCancel: |
|
620 if ( AknLayoutUtils::PenEnabled() ) |
|
621 { |
|
622 AttemptExitL(EFalse); |
|
623 } |
|
624 break; |
|
625 default: |
|
626 break; |
|
627 } |
|
628 } |
|
629 |
|
630 EXPORT_C void CAknPopupField::ProcessCommandL(TInt aCommandId) |
|
631 { |
|
632 // Respond to softkey events |
|
633 switch (aCommandId) |
|
634 { |
|
635 case EAknSoftkeyOk: |
|
636 AttemptExitL(ETrue); |
|
637 break; |
|
638 case EAknSoftkeyCancel: |
|
639 AttemptExitL(EFalse); |
|
640 break; |
|
641 default: |
|
642 break; |
|
643 } |
|
644 } |
|
645 |
|
646 EXPORT_C void CAknPopupField::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType) |
|
647 { |
|
648 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
649 if (aListBox == iSelectionList) |
|
650 { |
|
651 switch ( aEventType ) |
|
652 { |
|
653 case MEikListBoxObserver::EEventItemSingleClicked: |
|
654 { |
|
655 CListBoxView* view = iSelectionList->View(); |
|
656 |
|
657 if ( view->CurrentItemIndex() != iExtension->iOldItemIndex ) |
|
658 { |
|
659 view->DeselectItem( iExtension->iOldItemIndex ); |
|
660 iExtension->iOldItemIndex = view->CurrentItemIndex(); |
|
661 view->SelectItemL( iExtension->iOldItemIndex ); |
|
662 } |
|
663 } |
|
664 |
|
665 case MEikListBoxObserver::EEventItemDoubleClicked: |
|
666 case MEikListBoxObserver::EEventEnterKeyPressed: |
|
667 { |
|
668 // We can't delete the selection list until it's finished |
|
669 // processing the event, so call ourselves back and do it when |
|
670 // the list has finished. |
|
671 TCallBack cb( AttemptExitCallbackL, this ); |
|
672 delete iAttemptExitAsync; |
|
673 iAttemptExitAsync = NULL; |
|
674 iAttemptExitAsync = new ( ELeave ) |
|
675 CAsyncCallBack( cb, CActive::EPriorityHigh ); |
|
676 iAttemptExitAsync->CallBack(); |
|
677 } |
|
678 break; |
|
679 |
|
680 default: |
|
681 break; |
|
682 } |
|
683 } |
|
684 } |
|
685 |
|
686 |
|
687 EXPORT_C TInt CAknPopupField::CountComponentControls() const |
|
688 { |
|
689 CCoeControl* controls[] = |
|
690 { |
|
691 iButton, |
|
692 iLabel, |
|
693 iSelectionList |
|
694 }; |
|
695 |
|
696 TInt count = 0; |
|
697 for (TUint ii=0; ii<sizeof(controls)/sizeof(CCoeControl*); ii++) |
|
698 if (controls[ii]) |
|
699 count++; |
|
700 return count; |
|
701 } |
|
702 |
|
703 EXPORT_C CCoeControl* CAknPopupField::ComponentControl(TInt aIndex) const |
|
704 { |
|
705 CCoeControl* controls[] = |
|
706 { |
|
707 iButton, |
|
708 iLabel, |
|
709 iSelectionList |
|
710 }; |
|
711 |
|
712 for (TUint ii=0; ii<sizeof(controls)/sizeof(CCoeControl*); ii++) |
|
713 if (controls[ii] && aIndex-- == 0) |
|
714 return controls[ii]; |
|
715 return NULL; |
|
716 } |
|
717 |
|
718 TBool CAknPopupField::HandleInteractionConfirmedL() |
|
719 { |
|
720 if (IsEmpty()) |
|
721 { |
|
722 iLabel->SetTextL(KNullDesC); |
|
723 } |
|
724 else if (IsInvalid()) |
|
725 { |
|
726 if (iInvalidText) |
|
727 { |
|
728 iLabel->SetTextL(*iInvalidText); |
|
729 iLabel->CropText(); |
|
730 } |
|
731 else iLabel->SetTextL(KNullDesC); |
|
732 ReportEventL(EEventStateChanged); |
|
733 if (iObserver) |
|
734 iObserver->HandlePopupFieldEventL(this, MAknPopupFieldObserver::EAknPopupFieldEventValueChange, 0); |
|
735 } |
|
736 else |
|
737 { |
|
738 HBufC* newText = iValue->CurrentValueTextLC(); // ownership passed |
|
739 iLabel->SetTextL(*newText); // takes copy |
|
740 CleanupStack::PopAndDestroy(); // newText |
|
741 iLabel->CropText(); |
|
742 ReportEventL(EEventStateChanged); |
|
743 if (iObserver) |
|
744 iObserver->HandlePopupFieldEventL(this, MAknPopupFieldObserver::EAknPopupFieldEventValueChange, 0); |
|
745 } |
|
746 return ETrue; |
|
747 } |
|
748 |
|
749 void CAknPopupField::DestroyPopout() |
|
750 { |
|
751 if (iSelectionList) |
|
752 { |
|
753 iEikonEnv->RemoveFromStack(iSelectionList); |
|
754 delete iSelectionList; |
|
755 iSelectionList=NULL; |
|
756 } |
|
757 } |
|
758 |
|
759 TBool CAknPopupField::IsEmpty() const |
|
760 { |
|
761 if (!iValue) |
|
762 return ETrue; |
|
763 if (iDecorator.MdcaCount() <= 0) |
|
764 return ETrue; |
|
765 return EFalse; |
|
766 } |
|
767 |
|
768 TBool CAknPopupField::IsInvalid() const |
|
769 { |
|
770 if (IsEmpty()) return EFalse; |
|
771 TInt valueIndex = iValue->CurrentValueIndex(); |
|
772 if (valueIndex < 0 || valueIndex >= iDecorator.MdcaCount()) |
|
773 return ETrue; |
|
774 return EFalse; |
|
775 } |
|
776 |
|
777 TKeyResponse CAknPopupField::HandleHorizontalKeyEventL(TUint aKeyEventCode) |
|
778 { |
|
779 TKeyResponse keyResponse = EKeyWasNotConsumed; |
|
780 TBool finished = EFalse; |
|
781 |
|
782 TInt decIndex = 0; |
|
783 if (IsEmpty() || (iDecorator.MdcaCount() == 1 && iDecorator.DecoratedIndex(decIndex))) |
|
784 finished = ETrue; // Popupfield was empty or just contained decorated item |
|
785 |
|
786 TInt changeIndexBy = 0; |
|
787 if (!finished) |
|
788 { |
|
789 TBool isMirrored = AknLayoutUtils::LayoutMirrored(); |
|
790 |
|
791 switch(aKeyEventCode) |
|
792 { |
|
793 case EKeyLeftArrow: |
|
794 changeIndexBy = (isMirrored ? 1 : -1); |
|
795 break; |
|
796 case EKeyRightArrow: |
|
797 changeIndexBy = (isMirrored ? -1 : 1); |
|
798 break; |
|
799 default: |
|
800 finished = ETrue; // Not a horizontal key event |
|
801 break; |
|
802 } |
|
803 } |
|
804 |
|
805 if (!finished) |
|
806 { |
|
807 TInt newValue = iValue->CurrentValueIndex() + changeIndexBy; |
|
808 if (newValue < 0) // cycle around |
|
809 { |
|
810 newValue = iValue->MdcArray()->MdcaCount() - 1; |
|
811 } |
|
812 else if (newValue > (iValue->MdcArray()->MdcaCount() - 1)) // cycle around |
|
813 { |
|
814 newValue = 0; |
|
815 } |
|
816 if (newValue != iValue->CurrentValueIndex()) |
|
817 { |
|
818 iValue->SetCurrentValueIndex(newValue); |
|
819 HandleInteractionConfirmedL(); |
|
820 DrawDeferred(); |
|
821 } |
|
822 keyResponse = EKeyWasConsumed; |
|
823 } |
|
824 |
|
825 return keyResponse; |
|
826 } |
|
827 |
|
828 void CAknPopupField::CreatePopoutL() |
|
829 { |
|
830 if ( !iExtension || !iExtension->iSingleClickEnabled ) |
|
831 { |
|
832 CreateCbaL(); |
|
833 } |
|
834 ConstructSelectionListL(); |
|
835 ChangeMode(EAknPopupFieldSelectionListMode); |
|
836 SetUpScrollBarL(); |
|
837 // need to initialize the selection so that the list box is drawn in the correct place |
|
838 SetScrollBarSelectionL(); |
|
839 // make the selection list visible and update the scrollbar |
|
840 SetScrollBarSelectionL(); |
|
841 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
842 iSelectionList->MakeVisible(ETrue); |
|
843 iSelectionList->ActivateL(); |
|
844 iSelectionList->SetFocus(ETrue); |
|
845 iSelectionList->UpdateScrollBarsL(); |
|
846 |
|
847 // now let the container resize the list box |
|
848 if (iObserver) |
|
849 iObserver->HandlePopupFieldEventL(this, MAknPopupFieldObserver::EAknPopupFieldEventModeChange, NumLines()); |
|
850 } |
|
851 |
|
852 |
|
853 void CAknPopupField::CreateCbaL() |
|
854 { |
|
855 CEikButtonGroupContainer* cba = CEikButtonGroupContainer::NewL( |
|
856 CEikButtonGroupContainer::ECba, |
|
857 CEikButtonGroupContainer::EHorizontal, |
|
858 this, // popup field is a command observer |
|
859 R_AVKON_SOFTKEYS_OK_CANCEL__OK); |
|
860 |
|
861 delete iCba; |
|
862 iCba = cba; |
|
863 |
|
864 const TSize screenSize=iAvkonAppUi->ApplicationRect().Size(); /*TSize(AKN_LAYOUT_WINDOW_screen.iW, AKN_LAYOUT_WINDOW_screen.iH);*/ |
|
865 iCba->SetBoundingRect(TRect(screenSize)); |
|
866 } |
|
867 |
|
868 |
|
869 EXPORT_C void CAknPopupField::HandleResourceChange(TInt aType) |
|
870 { |
|
871 EAknFormMode newMode( iFormMode ); |
|
872 TBool notEditable( EFalse ); |
|
873 switch( aType ) |
|
874 { |
|
875 case KEikMessageCaptionedControlEditableStateChange: |
|
876 { |
|
877 newMode = EAknFormModeEdit; |
|
878 break; |
|
879 } |
|
880 case KEikMessageCaptionedControlEditableStateChangeWideWithGraphic: |
|
881 { |
|
882 newMode = EAknFormModeEditWideWithGraphic; |
|
883 break; |
|
884 } |
|
885 case KEikMessageCaptionedControlEditableStateChangeWideWithoutGraphic: |
|
886 { |
|
887 newMode = EAknFormModeEditWideWithoutGraphic; |
|
888 break; |
|
889 } |
|
890 case KEikMessageCaptionedControlNotEditableStateChange: |
|
891 { |
|
892 newMode = EAknFormModeView; |
|
893 notEditable = ETrue; |
|
894 break; |
|
895 } |
|
896 case KEikMessageCaptionedControlNotEditableStateChangeWideWithGraphic: |
|
897 { |
|
898 newMode = EAknFormModeViewWideWithGraphic; |
|
899 notEditable = ETrue; |
|
900 break; |
|
901 } |
|
902 case KEikMessageCaptionedControlNotEditableStateChangeWideWithoutGraphic: |
|
903 { |
|
904 newMode = EAknFormModeViewWideWithoutGraphic; |
|
905 notEditable = ETrue; |
|
906 break; |
|
907 } |
|
908 default: |
|
909 { |
|
910 break; |
|
911 } |
|
912 } |
|
913 if ( newMode != iFormMode ) |
|
914 { |
|
915 if ( iSelectionList && notEditable |
|
916 && iSelectionMode == EAknPopupFieldSelectionListMode |
|
917 && iExtension && iExtension->iSingleClickEnabled ) |
|
918 { |
|
919 // Edit mode to view while popup is open -> first cancel popup |
|
920 AttemptExitL( EFalse ); |
|
921 } |
|
922 else |
|
923 { |
|
924 __ASSERT_DEBUG( iSelectionMode == EAknPopupFieldLabelMode, |
|
925 Panic( EAknPanicPopupFieldWrongMode ) ); |
|
926 } |
|
927 iFormMode = newMode; |
|
928 if ( iButton && |
|
929 ( notEditable || ( iValue && iDecorator.MdcaCount() != 0 ) ) ) |
|
930 { |
|
931 iButton->MakeVisible( !notEditable ); |
|
932 } |
|
933 } |
|
934 if ( iSelectionList && !IsEmpty() ) |
|
935 { |
|
936 TRAP_IGNORE( InitialiseRadioButtonBitmapsL() ); |
|
937 } |
|
938 |
|
939 CEikBorderedControl::HandleResourceChange(aType); |
|
940 } |
|
941 |
|
942 //--------------------------------------------------------------------------------------- |
|
943 // CAknPopupField::HandlePointerEventL() |
|
944 // Starts popuplist or empty popuplist when popup item is clicked |
|
945 //--------------------------------------------------------------------------------------- |
|
946 // |
|
947 EXPORT_C void CAknPopupField::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
948 { |
|
949 if ( AknLayoutUtils::PenEnabled() ) |
|
950 { |
|
951 if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
952 { |
|
953 // note also that when page goes from view to edit mode, controls go from nonfocusing to focusing |
|
954 // therefore we only want focusing controls that have the focus |
|
955 if (!IsNonFocusing() && IsFocused()) |
|
956 { |
|
957 if ( iExtension && iExtension->iFeedback ) |
|
958 { |
|
959 iExtension->iFeedback->InstantFeedback( |
|
960 this, |
|
961 ETouchFeedbackPopUp, |
|
962 ETouchFeedbackVibra, |
|
963 aPointerEvent ); |
|
964 } |
|
965 if (!IsEmpty()) |
|
966 { |
|
967 CreatePopoutL(); |
|
968 } |
|
969 else |
|
970 { |
|
971 ShowEmptyListNoteL(); |
|
972 } |
|
973 } |
|
974 } |
|
975 else if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
976 { |
|
977 if (!IsNonFocusing() |
|
978 && IsFocused() |
|
979 && iExtension->iFormFieldRect.Contains( aPointerEvent.iPosition )) |
|
980 { |
|
981 // clicked inside popup field, will open popup or note |
|
982 if ( iExtension && iExtension->iFeedback ) |
|
983 { |
|
984 iExtension->iFeedback->InstantFeedback( ETouchFeedbackPopUp ); |
|
985 } |
|
986 } |
|
987 if ( iSelectionList && iSelectionMode == EAknPopupFieldSelectionListMode ) |
|
988 { |
|
989 // Clicked outside popup form field, closing popup |
|
990 if ( !iExtension->iFormFieldRect.Contains( aPointerEvent.iParentPosition ) ) |
|
991 { |
|
992 if ( iExtension && iExtension->iFeedback ) |
|
993 { |
|
994 iExtension->iFeedback->InstantFeedback( ETouchFeedbackPopUp ); |
|
995 } |
|
996 AttemptExitL( EFalse ); |
|
997 } |
|
998 } |
|
999 } |
|
1000 } |
|
1001 } |
|
1002 |
|
1003 |
|
1004 EXPORT_C void* CAknPopupField::ExtensionInterface( TUid /*aInterface*/ ) |
|
1005 { |
|
1006 return NULL; |
|
1007 } |
|
1008 |
|
1009 |
|
1010 EXPORT_C void CAknPopupField::Reserved_1() |
|
1011 {} |
|
1012 EXPORT_C void CAknPopupField::Reserved_2() |
|
1013 {} |
|
1014 |
|
1015 |
|
1016 |
|
1017 EXPORT_C void CAknPopupField::SetAllowsUserDefinedEntry(TBool aAllows) |
|
1018 { |
|
1019 if (aAllows) |
|
1020 { |
|
1021 if (iOtherText->Length() > 0) |
|
1022 iFlags |= EAknPopupFieldFlagAllowsUserDefinedEntry; |
|
1023 } |
|
1024 else |
|
1025 iFlags &= ~EAknPopupFieldFlagAllowsUserDefinedEntry; |
|
1026 |
|
1027 ConfigureDecorator(); |
|
1028 } |
|
1029 |
|
1030 |
|
1031 EXPORT_C void CAknPopupField::ActivateSelectionListL() |
|
1032 { |
|
1033 if (!IsEmpty()) |
|
1034 { |
|
1035 CreatePopoutL(); |
|
1036 } |
|
1037 else |
|
1038 { |
|
1039 ShowEmptyListNoteL(); |
|
1040 } |
|
1041 } |
|
1042 |
|
1043 EXPORT_C void CAknPopupField::SetQueryValueL(MAknQueryValue* aValue) |
|
1044 { |
|
1045 __ASSERT_DEBUG(aValue, Panic(EAknPanicPopupFieldInvalidValue)); |
|
1046 |
|
1047 iValue = aValue; |
|
1048 |
|
1049 if (iFlags & EAknPopupFieldFlagInitialised) |
|
1050 { |
|
1051 // put the current value text into the label |
|
1052 HBufC* newText = iValue->CurrentValueTextLC(); |
|
1053 iLabel->SetTextL(*newText); // takes copy |
|
1054 CleanupStack::PopAndDestroy(); // newText |
|
1055 iLabel->CropText(); |
|
1056 if (iObserver) |
|
1057 { |
|
1058 iObserver->HandlePopupFieldEventL( this, |
|
1059 MAknPopupFieldObserver::EAknPopupFieldEventValueChange, 0 ); |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 // decorate the array from the query value |
|
1064 const MDesCArray* array = iValue->MdcArray(); |
|
1065 iDecorator.SetArray(array); |
|
1066 } |
|
1067 |
|
1068 EXPORT_C void CAknPopupField::SetFont(const CFont* aFont) |
|
1069 { |
|
1070 if (iLabel) |
|
1071 iLabel->SetFont(aFont); |
|
1072 } |
|
1073 |
|
1074 EXPORT_C void CAknPopupField::SetShowIndicatorsL(TBool aShowIndicators) |
|
1075 { |
|
1076 if (!aShowIndicators) |
|
1077 { |
|
1078 if (iLayoutDecorator) |
|
1079 iLayoutDecorator->SetLeadingDecorationTextL(KPopFieldLeadingLayoutTextInactive); |
|
1080 } |
|
1081 } |
|
1082 |
|
1083 EXPORT_C TInt CAknPopupField::NumLines() const |
|
1084 { |
|
1085 TInt lines = 0; |
|
1086 |
|
1087 switch(iSelectionMode) |
|
1088 { |
|
1089 case EAknPopupFieldLabelMode: |
|
1090 lines = 1; |
|
1091 break; |
|
1092 case EAknPopupFieldSelectionListMode: |
|
1093 lines = iDecorator.MdcaCount(); |
|
1094 break; |
|
1095 default: |
|
1096 __ASSERT_DEBUG(ETrue, Panic(EAknPanicPopupFieldUndefinedMode)); |
|
1097 break; |
|
1098 } |
|
1099 |
|
1100 // we must restrict ourselves to the max number of lines. |
|
1101 if (lines > iMaxNoLines) |
|
1102 lines = iMaxNoLines; |
|
1103 return lines; |
|
1104 } |
|
1105 |
|
1106 EXPORT_C void CAknPopupField::SetPopupFieldObserver(MAknPopupFieldObserver* aObserver) |
|
1107 { |
|
1108 iObserver = aObserver; |
|
1109 } |
|
1110 |
|
1111 EXPORT_C void CAknPopupField::SetEmptyListNoteL(TInt aResourceId, CAknNoteDialog::TTimeout aTimeout, CAknNoteDialog::TTone aTone) |
|
1112 { |
|
1113 iEmptyNoteResourceId = aResourceId; |
|
1114 iEmptyNoteTimeout = aTimeout; |
|
1115 iEmptyNoteTone = aTone; |
|
1116 } |
|
1117 |
|
1118 EXPORT_C void CAknPopupField::SetEmptyTextL(const TDesC& aEmptyText) |
|
1119 { |
|
1120 HBufC* newText = aEmptyText.AllocLC(); |
|
1121 delete iEmptyText; |
|
1122 iEmptyText = NULL; |
|
1123 iEmptyText = newText; |
|
1124 CleanupStack::Pop(); // newText |
|
1125 |
|
1126 if (IsEmpty()) |
|
1127 { |
|
1128 iLabel->SetTextL(*iEmptyText); |
|
1129 iLabel->CropText(); |
|
1130 DrawDeferred(); |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 EXPORT_C void CAknPopupField::SetOtherTextL(const TDesC& aOtherText) |
|
1135 { |
|
1136 if (aOtherText.Length() < 1) |
|
1137 return; |
|
1138 |
|
1139 HBufC* newText = aOtherText.AllocLC(); |
|
1140 delete iOtherText; |
|
1141 iOtherText = NULL; |
|
1142 iOtherText = newText; |
|
1143 CleanupStack::Pop(); // newText |
|
1144 |
|
1145 ConfigureDecorator(); |
|
1146 } |
|
1147 |
|
1148 EXPORT_C void CAknPopupField::SetInvalidTextL(const TDesC& aInvalidText) |
|
1149 { |
|
1150 HBufC* newText = aInvalidText.AllocLC(); |
|
1151 delete iInvalidText; |
|
1152 iInvalidText = NULL; |
|
1153 iInvalidText = newText; |
|
1154 CleanupStack::Pop(); // newText |
|
1155 |
|
1156 if (IsInvalid()) |
|
1157 { |
|
1158 iLabel->SetTextL(*iInvalidText); |
|
1159 iLabel->CropText(); |
|
1160 } |
|
1161 } |
|
1162 |
|
1163 |
|
1164 void CAknPopupField::ConfigureDecorator() |
|
1165 { |
|
1166 __ASSERT_DEBUG(iOtherText, Panic(EAknPanicPopupFieldUninitialisedMember)); |
|
1167 |
|
1168 iDecorator.SetDecorationText(*iOtherText); |
|
1169 iDecorator.SetActive(iFlags & EAknPopupFieldFlagAllowsUserDefinedEntry); |
|
1170 } |
|
1171 |
|
1172 void CAknPopupField::ConstructLayoutDecoratorL() |
|
1173 { |
|
1174 if (iLayoutDecorator) |
|
1175 return; // already exists |
|
1176 iLayoutDecorator = CAknListBoxLayoutDecorator::NewL(); |
|
1177 TPtrC textPtr(KPopFieldLeadingLayoutTextActive); |
|
1178 iLayoutDecorator->SetLeadingDecorationTextL(textPtr); |
|
1179 iLayoutDecorator->SetArray(&iDecorator); |
|
1180 iLayoutDecorator->SetActive(ETrue); // for now |
|
1181 } |
|
1182 |
|
1183 void CAknPopupField::ShowEmptyListNoteL() |
|
1184 { |
|
1185 if (!iEmptyNoteResourceId) |
|
1186 return; |
|
1187 CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog(iEmptyNoteTone,iEmptyNoteTimeout); |
|
1188 dlg->PrepareLC(iEmptyNoteResourceId); |
|
1189 dlg->RunLD(); |
|
1190 } |
|
1191 |
|
1192 void CAknPopupField::AttemptExitL(TBool aAccept) |
|
1193 { |
|
1194 // we must be in selection list mode in order to get the cba event |
|
1195 __ASSERT_DEBUG(iSelectionMode == EAknPopupFieldSelectionListMode, Panic(EAknPanicPopupFieldWrongMode)); |
|
1196 __ASSERT_DEBUG(iSelectionList != NULL, Panic(EAknPanicPopupFieldSelectionListDoesntExist)); |
|
1197 TBool finished = ETrue; |
|
1198 |
|
1199 if (aAccept) |
|
1200 { |
|
1201 // get current selection |
|
1202 const TInt selection=iSelectionList->CurrentItemIndex(); |
|
1203 TInt decoratedIndex; |
|
1204 TBool decorated = iDecorator.DecoratedIndex(decoratedIndex); |
|
1205 if (decorated && (selection == decoratedIndex)) |
|
1206 { |
|
1207 TBool accepted = iValue->CreateEditorL(); |
|
1208 if (!accepted) |
|
1209 { |
|
1210 // dialog was cancelled, so popup list must remain |
|
1211 finished = EFalse; |
|
1212 } |
|
1213 } |
|
1214 else |
|
1215 iValue->SetCurrentValueIndex(selection); |
|
1216 } |
|
1217 |
|
1218 if (finished) |
|
1219 { |
|
1220 delete iCba; |
|
1221 iCba = NULL; |
|
1222 DestroyPopout(); |
|
1223 ChangeMode(EAknPopupFieldLabelMode); |
|
1224 // Move up to make sure the following line is always executed |
|
1225 if (iObserver) |
|
1226 iObserver->HandlePopupFieldEventL(this, MAknPopupFieldObserver::EAknPopupFieldEventModeChange, NumLines()); |
|
1227 |
|
1228 if (aAccept) |
|
1229 HandleInteractionConfirmedL(); |
|
1230 |
|
1231 } |
|
1232 } |
|
1233 |
|
1234 void CAknPopupField::ChangeMode(EAknPopupFieldSelectionMode aNewMode) |
|
1235 { |
|
1236 // change mode, and show / hide the appropriate controls |
|
1237 switch(aNewMode) |
|
1238 { |
|
1239 case EAknPopupFieldLabelMode: |
|
1240 iSelectionMode = EAknPopupFieldLabelMode; |
|
1241 iLabel->MakeVisible(ETrue); |
|
1242 if (iButton) |
|
1243 iButton->MakeVisible(ETrue); |
|
1244 break; |
|
1245 case EAknPopupFieldSelectionListMode: |
|
1246 iSelectionMode = EAknPopupFieldSelectionListMode; |
|
1247 iLabel->MakeVisible(EFalse); |
|
1248 if (iButton) |
|
1249 iButton->MakeVisible(EFalse); |
|
1250 break; |
|
1251 default: |
|
1252 __ASSERT_DEBUG(ETrue, Panic(EAknPanicPopupFieldUndefinedMode)); |
|
1253 break; |
|
1254 } |
|
1255 } |
|
1256 |
|
1257 TInt CAknPopupField::AttemptExitCallbackL(TAny* aThis) |
|
1258 { |
|
1259 if (aThis) |
|
1260 { |
|
1261 static_cast<CAknPopupField*>(aThis)->DoAttemptExitL(); |
|
1262 } |
|
1263 return 0; |
|
1264 } |
|
1265 |
|
1266 void CAknPopupField::DoAttemptExitL() |
|
1267 { |
|
1268 AttemptExitL(ETrue); |
|
1269 delete iAttemptExitAsync; |
|
1270 iAttemptExitAsync = NULL; |
|
1271 } |
|
1272 |
|
1273 EXPORT_C void CAknPopupField::SetMaxNumberOfLinesPermitted(TInt aMaxNoLines) |
|
1274 { |
|
1275 iMaxNoLines = aMaxNoLines; |
|
1276 }; |
|
1277 |
|
1278 EXPORT_C TTypeUid::Ptr CAknPopupField::MopSupplyObject(TTypeUid aId) |
|
1279 { |
|
1280 // Only thing supplied at this level of descent in the class hierarchy |
|
1281 // or in the object provider chain is the cba |
|
1282 if ( iCba ) |
|
1283 { |
|
1284 TTypeUid::Ptr myPtr( SupplyMopObject( aId, iCba ) ); |
|
1285 if ( myPtr.Pointer() ) |
|
1286 { |
|
1287 return myPtr; |
|
1288 } |
|
1289 } |
|
1290 return CEikBorderedControl::MopSupplyObject( aId ); |
|
1291 } |
|
1292 |
|
1293 EXPORT_C void CAknPopupField::Draw(const TRect& aRect) const |
|
1294 { |
|
1295 if ( iSelectionMode == EAknPopupFieldSelectionListMode ) |
|
1296 { |
|
1297 TBool backgroundDrawn = EFalse; |
|
1298 |
|
1299 if ( AknsUtils::AvkonSkinEnabled() ) |
|
1300 { |
|
1301 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
1302 MAknsControlContext* edCc = AknsDrawUtils::ControlContext( this ); |
|
1303 CWindowGc& gc = SystemGc(); |
|
1304 backgroundDrawn = AknsDrawUtils::Background( skin, edCc, this, gc, aRect ); |
|
1305 iLabel->SetBrushStyle(CGraphicsContext::ENullBrush); |
|
1306 } |
|
1307 |
|
1308 if ( !backgroundDrawn ) |
|
1309 { |
|
1310 // This should be the legacy behaviour (there was no draw routine before 2.0) |
|
1311 CEikBorderedControl::Draw( aRect ); |
|
1312 iLabel->SetBrushStyleFromContext(); |
|
1313 } |
|
1314 } |
|
1315 } |
|
1316 |
|
1317 // End of File |