|
1 /* |
|
2 * Copyright (c) 2003-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CMIDChoiceGroupElement encapsulates a ChoiceGroup |
|
15 * listbox entry (text, image, selection state and all) |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <fbs.h> |
|
23 #include <bitdev.h> |
|
24 #include <gdi.h> |
|
25 |
|
26 #include "CMIDChoiceGroupElement.h" |
|
27 #include "CMIDUtils.h" |
|
28 |
|
29 const TInt KSpaceForNumber = 6; |
|
30 const TInt KSpaceForTabulator = 1; |
|
31 |
|
32 CMIDChoiceGroupElement* CMIDChoiceGroupElement::NewL() |
|
33 { |
|
34 return new(ELeave)CMIDChoiceGroupElement(); |
|
35 } |
|
36 |
|
37 CMIDChoiceGroupElement::CMIDChoiceGroupElement() |
|
38 { |
|
39 } |
|
40 |
|
41 |
|
42 // Destructor |
|
43 CMIDChoiceGroupElement::~CMIDChoiceGroupElement() |
|
44 { |
|
45 delete iText; |
|
46 |
|
47 if (Flags() & CGEF_OWNSICON) |
|
48 { |
|
49 delete iIcon; |
|
50 } |
|
51 } |
|
52 |
|
53 |
|
54 // Set element text |
|
55 void CMIDChoiceGroupElement::SetTextL(const TDesC& aText) |
|
56 { |
|
57 // Get rid of old text, set to NULL in case allocation fails |
|
58 if (iText) |
|
59 { |
|
60 delete iText; |
|
61 iText = NULL; |
|
62 } |
|
63 |
|
64 // Make a copy of the string |
|
65 iText = aText.AllocL(); |
|
66 } |
|
67 |
|
68 |
|
69 // Retrieve text for the listbox. This means that the image indeces |
|
70 // are also added into the string and separated by tabs |
|
71 const TPtrC CMIDChoiceGroupElement::LboxText(TInt aImageIndex) |
|
72 { |
|
73 // Construct a new line with the correct image index |
|
74 _LIT(KLboxLineFormat, "%d\t%d\t%S"); |
|
75 delete iLboxText; |
|
76 |
|
77 // Reserve space for number + tab + number + tab + element text |
|
78 TInt len = 2 * KSpaceForNumber + 2 * KSpaceForTabulator + (iText ? iText->Length() : 0); |
|
79 iLboxText = HBufC::New(len); |
|
80 |
|
81 if (!iLboxText) |
|
82 { |
|
83 return TPtrC(KNullDesC); |
|
84 } |
|
85 |
|
86 // Write the string into the buffer |
|
87 TPtr ptr = iLboxText->Des(); |
|
88 ptr.Format( |
|
89 KLboxLineFormat, |
|
90 IsSelected() ? 0 : 1, |
|
91 aImageIndex, |
|
92 iText); |
|
93 |
|
94 return ptr; |
|
95 } |
|
96 |
|
97 |
|
98 // Set icon. If owned, an icon is deleted by the element |
|
99 void CMIDChoiceGroupElement::SetIcon( |
|
100 CGulIcon* aIcon, |
|
101 TBool aElementOwnsIcon /*= ETrue */) |
|
102 { |
|
103 // Get rid of old icon, if any and if owned |
|
104 if ((iIcon) && (Flags() & CGEF_OWNSICON)) |
|
105 { |
|
106 delete iIcon; |
|
107 } |
|
108 |
|
109 iIcon = aIcon; |
|
110 |
|
111 if (aElementOwnsIcon) |
|
112 { |
|
113 iFlags |= CGEF_OWNSICON; |
|
114 } |
|
115 else |
|
116 { |
|
117 iFlags &= ~CGEF_OWNSICON; |
|
118 } |
|
119 } |
|
120 |
|
121 |
|
122 // Set icon from bitmaps. If owned, an icon is deleted by the element |
|
123 // We expect that the bitmaps have been created for us and are in the correct format |
|
124 void CMIDChoiceGroupElement::SetIconL( |
|
125 CFbsBitmap& aBitmap, |
|
126 CFbsBitmap* aMask /* = NULL */, |
|
127 TBool aElementOwnsIcon /* = ETrue */) |
|
128 { |
|
129 CGulIcon* icon = CGulIcon::NewL(&aBitmap, aMask); |
|
130 icon->SetBitmapsOwnedExternally(!aElementOwnsIcon); |
|
131 |
|
132 SetIcon(icon, aElementOwnsIcon); |
|
133 } |
|
134 |
|
135 // End of File |