|
1 /******************************************************************************* |
|
2 * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #include <eikon.hrh> |
|
14 #include <eikhkeyt.h> |
|
15 #include <AknDef.h> |
|
16 #include <eswtcore.rsg> |
|
17 #include "swtcontrolhelper.h" |
|
18 #include "swtmenuitem.h" |
|
19 |
|
20 |
|
21 _LIT(KExtraSpaces, " "); |
|
22 |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CSwtMenuItem::CSwtMenuItem |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 inline CSwtMenuItem::CSwtMenuItem(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
32 MSwtMenu& aParent, TInt aIndex, TInt aStyle, TInt aCommandId) |
|
33 : iDisplay(aDisplay) |
|
34 , iPeer(aPeer) |
|
35 , iParent(aParent) |
|
36 , iIndexOfCreation(aIndex) |
|
37 , iStyle(aStyle) |
|
38 , iEnabled(ETrue) |
|
39 { |
|
40 if (aCommandId != 0) |
|
41 { |
|
42 iCommandId = aCommandId; |
|
43 } |
|
44 else |
|
45 { |
|
46 iCommandId = reinterpret_cast<TInt>(this); |
|
47 } |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CSwtMenuItem::CSwtMenuItem |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CSwtMenuItem::~CSwtMenuItem() |
|
55 { |
|
56 // Own |
|
57 delete iText; |
|
58 delete iDummyMask; |
|
59 iText = NULL; |
|
60 iDummyMask = NULL; |
|
61 |
|
62 // Not own |
|
63 TInt imageSizesCount = iImageSizes.Count(); |
|
64 for (TInt i = 0; i < imageSizesCount; i++) |
|
65 { |
|
66 if (iImage) |
|
67 { |
|
68 iImage->RemoveSubRef(iImageSizes[i]); |
|
69 } |
|
70 } |
|
71 iImageSizes.Close(); |
|
72 if (iImage) |
|
73 { |
|
74 iImage->RemoveRef(); |
|
75 } |
|
76 iImage = NULL; |
|
77 iMenu = NULL; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CSwtMenuItem::ConstructL |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 void CSwtMenuItem::ConstructL() |
|
85 { |
|
86 iParent.RegisterChildL(*this, iIndexOfCreation); |
|
87 |
|
88 CEikMenuPane* pane = Pane(); |
|
89 if (pane) |
|
90 { |
|
91 CEikMenuPaneItem::SData itemData; |
|
92 itemData.iText = KNullDesC; |
|
93 itemData.iExtraText = KNullDesC; |
|
94 itemData.iFlags = 0; |
|
95 itemData.iCascadeId = 0; |
|
96 itemData.iCommandId = iCommandId; |
|
97 |
|
98 pane->AddMenuItemL(itemData); |
|
99 UpdatePaneL(*pane, ESwtMenuItemDataFlags); |
|
100 pane->HandleResourceChange(KEikDynamicLayoutVariantSwitch); |
|
101 } |
|
102 |
|
103 iDisplay.MenuArranger().HandleMenuChangedL(iParent, |
|
104 MSwtMenuArranger::ESwtMenuItemAdded); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CSwtMenuItem::NewL |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 CSwtMenuItem* CSwtMenuItem::NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
112 MSwtMenu& aParent, TInt aIndex, TInt aStyle, TInt aCommandId /* = 0 */) |
|
113 { |
|
114 CSwtMenuItem* self = new(ELeave) CSwtMenuItem(aDisplay, aPeer, aParent, |
|
115 aIndex, aStyle, aCommandId); |
|
116 CleanupStack::PushL(self); |
|
117 self->ConstructL(); |
|
118 CleanupStack::Pop(self); |
|
119 return self; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CSwtMenuItem::Dispose |
|
124 // From MSwtMenuItem |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 TSwtPeer CSwtMenuItem::Dispose() |
|
128 { |
|
129 iParent.UnregisterChild(*this); |
|
130 |
|
131 CleanPane(); |
|
132 |
|
133 TRAP_IGNORE(iDisplay.MenuArranger().HandleMenuChangedL(iParent, |
|
134 MSwtMenuArranger::ESwtMenuItemRemoved)); |
|
135 |
|
136 // Actual dispose |
|
137 TSwtPeer peer(iPeer); |
|
138 delete this; |
|
139 return peer; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CSwtMenuItem::JavaPeer |
|
144 // From MSwtMenuItem |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 TSwtPeer CSwtMenuItem::JavaPeer() const |
|
148 { |
|
149 return iPeer; |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CSwtMenuItem::GetSelection |
|
154 // From MSwtMenuItem |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CSwtMenuItem::GetSelection() const |
|
158 { |
|
159 return iSelected; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CSwtMenuItem::SetAcceleratorL |
|
164 // From MSwtMenuItem |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CSwtMenuItem::SetAcceleratorL(TInt aAccelerator) |
|
168 { |
|
169 iAccelerator = aAccelerator; |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CSwtMenuItem::SetEnabled |
|
174 // From MSwtMenuItem |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void CSwtMenuItem::SetEnabled(TBool aEnabled) |
|
178 { |
|
179 if (iEnabled != aEnabled) |
|
180 { |
|
181 iEnabled = aEnabled; |
|
182 |
|
183 CEikMenuPane* pane = Pane(); |
|
184 if (pane) |
|
185 { |
|
186 if (iEnabled) |
|
187 { |
|
188 CEikMenuPaneItem::SData itemData; |
|
189 itemData.iText = KNullDesC; |
|
190 itemData.iExtraText = KNullDesC; |
|
191 itemData.iFlags = 0; |
|
192 itemData.iCascadeId = 0; |
|
193 itemData.iCommandId = iCommandId; |
|
194 |
|
195 TRAP_IGNORE( |
|
196 pane->AddMenuItemL(itemData); |
|
197 UpdatePaneL(*pane, ESwtMenuItemDataAll); |
|
198 ); |
|
199 pane->HandleResourceChange(KEikDynamicLayoutVariantSwitch); |
|
200 } |
|
201 else |
|
202 { |
|
203 CleanPane(); |
|
204 } |
|
205 } |
|
206 |
|
207 TRAP_IGNORE(iDisplay.MenuArranger().HandleMenuChangedL(iParent, |
|
208 MSwtMenuArranger::ESwtMenuItemEnableStateChanged)); |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CSwtMenuItem::SetImageL |
|
214 // From MSwtMenuItem |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CSwtMenuItem::SetImageL(const MSwtImage* aImage) |
|
218 { |
|
219 TInt imageSizesCount = iImageSizes.Count(); |
|
220 for (TInt i = 0; i < imageSizesCount; i++) |
|
221 { |
|
222 if (iImage) |
|
223 { |
|
224 iImage->RemoveSubRef(iImageSizes[i]); |
|
225 } |
|
226 } |
|
227 iImageSizes.Close(); |
|
228 if (iImage) |
|
229 { |
|
230 iImage->RemoveRef(); |
|
231 } |
|
232 iImage = aImage; |
|
233 if (iImage) |
|
234 { |
|
235 iImage->AddRef(); |
|
236 } |
|
237 |
|
238 CEikMenuPane* pane = Pane(); |
|
239 if (pane) |
|
240 { |
|
241 UpdatePaneL(*pane, ESwtMenuItemDataImage); |
|
242 pane->HandleResourceChange(KEikDynamicLayoutVariantSwitch); |
|
243 } |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CSwtMenuItem::SetMenuL |
|
248 // From MSwtMenuItem |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 void CSwtMenuItem::SetMenuL(const MSwtMenu* aMenu) |
|
252 { |
|
253 if (iMenu == aMenu) |
|
254 { |
|
255 return; |
|
256 } |
|
257 |
|
258 // If item displayed, close cascade menu. |
|
259 CEikMenuPane* pane = Pane(); |
|
260 if (pane) |
|
261 { |
|
262 pane->CloseCascadeMenu(); |
|
263 } |
|
264 |
|
265 if (iMenu) |
|
266 { |
|
267 iDisplay.MenuArranger().HandleMenuChangedL(*iMenu, |
|
268 MSwtMenuArranger::ESwtMenuRemoved); |
|
269 } |
|
270 |
|
271 iMenu = aMenu; |
|
272 |
|
273 if (iMenu) |
|
274 { |
|
275 iDisplay.MenuArranger().HandleMenuChangedL(*iMenu, |
|
276 MSwtMenuArranger::ESwtMenuAdded); |
|
277 } |
|
278 |
|
279 // If item displayed, update cascade icon |
|
280 if (pane) |
|
281 { |
|
282 UpdatePaneL(*pane, ESwtMenuItemDataCascade); |
|
283 pane->HandleResourceChange(KEikDynamicLayoutVariantSwitch); |
|
284 } |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CSwtMenuItem::SetSelection |
|
289 // From MSwtMenuItem |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 void CSwtMenuItem::SetSelection(TBool aSelected) |
|
293 { |
|
294 iSelected = aSelected; |
|
295 |
|
296 CEikMenuPane* pane = Pane(); |
|
297 if (pane) |
|
298 { |
|
299 TRAP_IGNORE(UpdatePaneL(*pane, ESwtMenuItemDataSelection)); |
|
300 pane->HandleResourceChange(KEikDynamicLayoutVariantSwitch); |
|
301 } |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // CSwtMenuItem::SetTextL |
|
306 // From MSwtMenuItem |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 void CSwtMenuItem::SetTextL(const TDesC& aText) |
|
310 { |
|
311 if (iText) |
|
312 { |
|
313 delete iText; |
|
314 iText = NULL; |
|
315 } |
|
316 iText = aText.AllocL(); |
|
317 |
|
318 CEikMenuPane* pane = Pane(); |
|
319 if (pane) |
|
320 { |
|
321 UpdatePaneL(*pane, ESwtMenuItemDataText); |
|
322 pane->HandleResourceChange(KEikDynamicLayoutVariantSwitch); |
|
323 } |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // CSwtMenuItem::Accelerator |
|
328 // From MSwtMenuItem |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CSwtMenuItem::Accelerator() const |
|
332 { |
|
333 return iAccelerator; |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // CSwtMenuItem::IsEnabled |
|
338 // From MSwtMenuItem |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 TBool CSwtMenuItem::IsEnabled() const |
|
342 { |
|
343 return iEnabled; |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // CSwtMenuItem::Image |
|
348 // From MSwtMenuItem |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 const MSwtImage* CSwtMenuItem::Image() const |
|
352 { |
|
353 return iImage; |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------------------------- |
|
357 // CSwtMenuItem::GetImageBitmapsL |
|
358 // From MSwtMenuItem |
|
359 // --------------------------------------------------------------------------- |
|
360 // |
|
361 void CSwtMenuItem::GetImageBitmapsL(CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, |
|
362 const TSize& aSize) |
|
363 { |
|
364 aBitmap = NULL; |
|
365 aMask = NULL; |
|
366 if (!iImage) |
|
367 { |
|
368 return; |
|
369 } |
|
370 |
|
371 CFbsBitmap* bmp = const_cast<CFbsBitmap*>(&iImage->SubBitmap(aSize)); |
|
372 if (bmp) |
|
373 { |
|
374 if (iImageSizes.Find(aSize) == KErrNotFound) |
|
375 { |
|
376 iImage->AddSubRef(aSize); |
|
377 iImageSizes.Append(aSize); |
|
378 } |
|
379 aBitmap = bmp; |
|
380 aMask = const_cast<CFbsBitmap*>(iImage->SubMaskBitmap(aSize, ETrue)); |
|
381 |
|
382 if (aMask == NULL) |
|
383 { |
|
384 if (!iDummyMask) |
|
385 { |
|
386 // MenuItem drawing does not support images with a NULL mask. |
|
387 // So create a 2-bit black image mask with the same size as aSize |
|
388 iDummyMask = new(ELeave) CFbsBitmap; |
|
389 User::LeaveIfError(iDummyMask->Create(aSize, EGray2)); |
|
390 |
|
391 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iDummyMask); |
|
392 CleanupStack::PushL(device); |
|
393 CFbsBitGc* gc = CFbsBitGc::NewL(); |
|
394 CleanupStack::PushL(gc); |
|
395 |
|
396 gc->Activate(device); |
|
397 gc->SetPenStyle(CGraphicsContext::ENullPen); |
|
398 gc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
399 gc->SetBrushColor(KRgbBlack); |
|
400 gc->DrawRect(TRect(aSize)); |
|
401 |
|
402 CleanupStack::PopAndDestroy(gc); |
|
403 CleanupStack::PopAndDestroy(device); |
|
404 } |
|
405 aMask = iDummyMask; |
|
406 } |
|
407 } |
|
408 } |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // CSwtMenuItem::Menu |
|
412 // From MSwtMenuItem |
|
413 // --------------------------------------------------------------------------- |
|
414 // |
|
415 const MSwtMenu* CSwtMenuItem::Menu() const |
|
416 { |
|
417 return iMenu; |
|
418 } |
|
419 |
|
420 // --------------------------------------------------------------------------- |
|
421 // CSwtMenuItem::Text |
|
422 // From MSwtMenuItem |
|
423 // --------------------------------------------------------------------------- |
|
424 // |
|
425 const TDesC& CSwtMenuItem::Text() const |
|
426 { |
|
427 if (iText) |
|
428 { |
|
429 return *iText; |
|
430 } |
|
431 else |
|
432 { |
|
433 return KNullDesC; |
|
434 } |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // CSwtMenuItem::CommandId |
|
439 // From MSwtMenuItem |
|
440 // --------------------------------------------------------------------------- |
|
441 // |
|
442 TInt CSwtMenuItem::CommandId() const |
|
443 { |
|
444 return iCommandId; |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------------------------- |
|
448 // CSwtMenuItem::Style |
|
449 // From MSwtMenuItem |
|
450 // --------------------------------------------------------------------------- |
|
451 // |
|
452 TInt CSwtMenuItem::Style() const |
|
453 { |
|
454 return iStyle; |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // CSwtMenuItem::Parent |
|
459 // From MSwtMenuItem |
|
460 // --------------------------------------------------------------------------- |
|
461 // |
|
462 const MSwtMenu& CSwtMenuItem::Parent() const |
|
463 { |
|
464 return iParent; |
|
465 } |
|
466 |
|
467 // --------------------------------------------------------------------------- |
|
468 // CSwtMenuItem::UpdatePaneL |
|
469 // From MSwtMenuItem |
|
470 // --------------------------------------------------------------------------- |
|
471 // |
|
472 void CSwtMenuItem::UpdatePaneL(CEikMenuPane& aPane, TSwtMenuItemData aDetail) |
|
473 { |
|
474 TInt paneItemIndex; |
|
475 CEikMenuPaneItem* paneItem(NULL); |
|
476 |
|
477 if (!aPane.MenuItemExists(iCommandId, paneItemIndex)) |
|
478 { |
|
479 return; |
|
480 } |
|
481 |
|
482 paneItem = aPane.ItemAndPos(iCommandId, paneItemIndex); |
|
483 if (!paneItem || paneItemIndex == KErrNotFound) |
|
484 { |
|
485 return; |
|
486 } |
|
487 |
|
488 CEikMenuPaneItem::SData& data = paneItem->iData; |
|
489 |
|
490 // Text |
|
491 if (aDetail == ESwtMenuItemDataAll || aDetail == ESwtMenuItemDataText) |
|
492 { |
|
493 TInt maxLength = data.iText.MaxLength(); |
|
494 if (Text().Length() <= maxLength) |
|
495 { |
|
496 data.iText = Text(); |
|
497 } |
|
498 else |
|
499 { |
|
500 data.iText = Text().Left(maxLength - 1); |
|
501 } |
|
502 |
|
503 // If push or cascade add some space after text to fix overlapping image |
|
504 if (!(Style() & (KSwtStyleCheck | KSwtStyleRadio)) |
|
505 && aPane.IsCascadeMenuPane() |
|
506 && data.iText.Length() > 0) |
|
507 { |
|
508 TInt diff = data.iText.MaxLength() - data.iText.Length(); |
|
509 if (diff >= KExtraSpaces().Length()) |
|
510 { |
|
511 data.iText.Append(KExtraSpaces); |
|
512 } |
|
513 } |
|
514 |
|
515 data.iExtraText = KNullDesC; |
|
516 |
|
517 if (aDetail != ESwtMenuItemDataAll) |
|
518 { |
|
519 return; |
|
520 } |
|
521 } |
|
522 |
|
523 // Cascade |
|
524 if (aDetail == ESwtMenuItemDataAll || aDetail == ESwtMenuItemDataCascade) |
|
525 { |
|
526 if (iMenu) |
|
527 { |
|
528 if (iMenu->HasRadioGroup()) |
|
529 { |
|
530 data.iCascadeId = R_SWT_SUBMENUPANE_WITHRADIOGROUP; |
|
531 } |
|
532 else |
|
533 { |
|
534 data.iCascadeId = R_SWT_SUBMENUPANE; |
|
535 } |
|
536 } |
|
537 else |
|
538 { |
|
539 data.iCascadeId = 0; |
|
540 } |
|
541 |
|
542 if (aDetail != ESwtMenuItemDataAll) |
|
543 { |
|
544 return; |
|
545 } |
|
546 } |
|
547 |
|
548 // Selection |
|
549 if (aDetail == ESwtMenuItemDataAll || aDetail == ESwtMenuItemDataSelection) |
|
550 { |
|
551 if (GetSelection()) |
|
552 { |
|
553 aPane.SetItemButtonState(iCommandId, EEikMenuItemSymbolOn); |
|
554 } |
|
555 else |
|
556 { |
|
557 aPane.SetItemButtonState(iCommandId, EEikMenuItemSymbolIndeterminate); |
|
558 } |
|
559 |
|
560 if (aDetail != ESwtMenuItemDataAll) |
|
561 { |
|
562 return; |
|
563 } |
|
564 } |
|
565 |
|
566 // Flags |
|
567 if (aDetail == ESwtMenuItemDataAll || aDetail == ESwtMenuItemDataFlags) |
|
568 { |
|
569 TInt index = Index(); |
|
570 if (Style() & KSwtStyleRadio) |
|
571 { |
|
572 TInt firstRadioIndex = FirstRadioSibbling(); |
|
573 TInt lastRadioIndex = LastRadioSibbling(); |
|
574 if (index == firstRadioIndex) |
|
575 { |
|
576 if (index == firstRadioIndex) |
|
577 { |
|
578 data.iFlags |= EEikMenuItemRadioStart; |
|
579 } |
|
580 else if (index == lastRadioIndex) |
|
581 { |
|
582 data.iFlags |= EEikMenuItemRadioEnd; |
|
583 } |
|
584 else |
|
585 { |
|
586 data.iFlags |= EEikMenuItemRadioMiddle; |
|
587 } |
|
588 } |
|
589 } |
|
590 else if (Style() & KSwtStyleCheck) |
|
591 { |
|
592 data.iFlags |= EEikMenuItemCheckBox; |
|
593 } |
|
594 |
|
595 if (iParent.Items() && index < iParent.Items()->Count() - 1 |
|
596 && ((*iParent.Items())[index + 1]->Style() & KSwtStyleSeparator)) |
|
597 { |
|
598 data.iFlags |= EEikMenuItemSeparatorAfter; |
|
599 } |
|
600 |
|
601 if (iParent.DefaultItem() == this) |
|
602 { |
|
603 aPane.SetSelectedItem(paneItemIndex); |
|
604 } |
|
605 |
|
606 if (aDetail != ESwtMenuItemDataAll) |
|
607 { |
|
608 return; |
|
609 } |
|
610 } |
|
611 |
|
612 // Image. Keep it last. |
|
613 if ((aDetail == ESwtMenuItemDataAll || aDetail == ESwtMenuItemDataImage)) |
|
614 { |
|
615 if (Image()) |
|
616 { |
|
617 // const cast for CreateIconL but bitmaps set as owned externally |
|
618 // CeikMenuPaneItem does not modify the image so that using cast |
|
619 // in relation to SetBitmapsOwnedExternally is safe. |
|
620 MSwtImage* image = const_cast<MSwtImage*>(Image()); |
|
621 TSize iconRealSize = SwtControlHelper::GetAspectRatioScaledBitmapSize( |
|
622 image->Bitmap().SizeInPixels(), iDisplay.MenuArranger().ImageSize()); |
|
623 |
|
624 CFbsBitmap* bmp = NULL; |
|
625 CFbsBitmap* mask = NULL; |
|
626 GetImageBitmapsL(bmp, mask, iconRealSize); |
|
627 if (bmp) |
|
628 { |
|
629 paneItem->CreateIconL(bmp, mask); // bmp cannot be NULL here |
|
630 paneItem->SetBitmapsOwnedExternally(ETrue); // Bitmaps deleted by CSwtImage |
|
631 } |
|
632 } |
|
633 else |
|
634 { |
|
635 paneItem->SetIcon(NULL); |
|
636 } |
|
637 } |
|
638 } |
|
639 |
|
640 // --------------------------------------------------------------------------- |
|
641 // CSwtMenuItem::Pane |
|
642 // --------------------------------------------------------------------------- |
|
643 // |
|
644 CEikMenuPane* CSwtMenuItem::Pane() const |
|
645 { |
|
646 CEikMenuPane* pane = iParent.Host(); |
|
647 if (pane && pane->IsVisible()) |
|
648 { |
|
649 return pane; |
|
650 } |
|
651 else |
|
652 { |
|
653 return NULL; |
|
654 } |
|
655 } |
|
656 |
|
657 // --------------------------------------------------------------------------- |
|
658 // CSwtMenuItem::FirstRadioSibbling |
|
659 // --------------------------------------------------------------------------- |
|
660 // |
|
661 TInt CSwtMenuItem::FirstRadioSibbling() const |
|
662 { |
|
663 if (iParent.Items()) |
|
664 { |
|
665 const RPointerArray<MSwtMenuItem>& items = *iParent.Items(); |
|
666 TInt count = items.Count(); |
|
667 for (TInt i = 0; i < count; i++) |
|
668 { |
|
669 MSwtMenuItem* item = items[i]; |
|
670 if (item && item->Style() & KSwtStyleRadio) |
|
671 { |
|
672 return i; |
|
673 } |
|
674 } |
|
675 } |
|
676 return KErrNotFound; |
|
677 } |
|
678 |
|
679 // --------------------------------------------------------------------------- |
|
680 // CSwtMenuItem::LastRadioSibbling |
|
681 // --------------------------------------------------------------------------- |
|
682 // |
|
683 TInt CSwtMenuItem::LastRadioSibbling() const |
|
684 { |
|
685 if (iParent.Items()) |
|
686 { |
|
687 const RPointerArray<MSwtMenuItem>& items = *iParent.Items(); |
|
688 for (TInt i = items.Count() - 1; i >= 0; i--) |
|
689 { |
|
690 MSwtMenuItem* item = items[i]; |
|
691 if (item && item->Style() & KSwtStyleRadio) |
|
692 { |
|
693 return i; |
|
694 } |
|
695 } |
|
696 } |
|
697 return KErrNotFound; |
|
698 } |
|
699 |
|
700 // --------------------------------------------------------------------------- |
|
701 // CSwtMenuItem::Index |
|
702 // --------------------------------------------------------------------------- |
|
703 // |
|
704 TInt CSwtMenuItem::Index() const |
|
705 { |
|
706 TInt res = KErrNotFound; |
|
707 if (iParent.Items()) |
|
708 { |
|
709 res = iParent.Items()->Find(this); |
|
710 } |
|
711 return res; |
|
712 } |
|
713 |
|
714 // --------------------------------------------------------------------------- |
|
715 // CSwtMenuItem::CleanPane |
|
716 // --------------------------------------------------------------------------- |
|
717 // |
|
718 void CSwtMenuItem::CleanPane() const |
|
719 { |
|
720 CEikMenuPane* pane = Pane(); |
|
721 if (pane) |
|
722 { |
|
723 TInt index(KErrNotFound); |
|
724 if (pane->MenuItemExists(iCommandId, index)) |
|
725 { |
|
726 pane->CloseCascadeMenu(); |
|
727 pane->SetSelectedItem(0); |
|
728 pane->DeleteMenuItem(iCommandId); |
|
729 pane->HandleResourceChange(KEikDynamicLayoutVariantSwitch); |
|
730 } |
|
731 } |
|
732 } |