|
1 /* |
|
2 * Copyright (c) 2003-2005 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 the License "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: Implements LIW Menu utilities for providers to access consumer menu. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #include <barsread.h> |
|
24 #include <barsc.h> |
|
25 #include <bautils.h> |
|
26 #include "liwmenu.h" |
|
27 #include "liwcommon.hrh" |
|
28 |
|
29 // This is needed for resource reading. |
|
30 const TInt KCCMask(0x00000fff); |
|
31 |
|
32 |
|
33 EXPORT_C CLiwMenuPane::CLiwMenuPane(CEikMenuPane& aMenuPane, TInt aBaseCmdId) |
|
34 : iMenuPane(&aMenuPane), iBaseCmdId(aBaseCmdId) |
|
35 { |
|
36 iNextCmdId = aBaseCmdId; |
|
37 } |
|
38 |
|
39 |
|
40 EXPORT_C CLiwMenuPane::~CLiwMenuPane() |
|
41 { |
|
42 delete iMenuPane; |
|
43 |
|
44 for(TInt i = 0; i < iIdMap.Count(); i++) |
|
45 { |
|
46 iIdMap[i].extraText.Close(); |
|
47 } |
|
48 |
|
49 iIdMap.Reset(); |
|
50 } |
|
51 |
|
52 |
|
53 EXPORT_C void CLiwMenuPane::AddMenuItemL( |
|
54 TInt aServiceCmd, |
|
55 CEikMenuPaneItem::SData& aMenuItem, |
|
56 TInt aIndex) |
|
57 { |
|
58 AddMenuItemL(aServiceCmd, aMenuItem, aIndex, KNullDesC()); |
|
59 } |
|
60 |
|
61 |
|
62 EXPORT_C void CLiwMenuPane::AddMenuItemL( |
|
63 TInt aServiceCmd, |
|
64 CEikMenuPaneItem::SData& aMenuItem, |
|
65 TInt aIndex, |
|
66 const TDesC& aExtraText) |
|
67 { |
|
68 SMenuIdMap map; |
|
69 |
|
70 map.dynMenuCmdId = iNextCmdId + iPaneOffset; |
|
71 map.serviceCmdId = aServiceCmd; |
|
72 map.origCmdId = aMenuItem.iCommandId; |
|
73 map.owner = iInitializingOwner; |
|
74 map.extraText.Assign(aExtraText.AllocL()); |
|
75 CleanupClosePushL(map.extraText); |
|
76 |
|
77 aMenuItem.iCommandId = iNextCmdId + iPaneOffset; |
|
78 iNextCmdId++; |
|
79 |
|
80 iMenuPane->InsertMenuItemL(aMenuItem, aIndex); |
|
81 User::LeaveIfError(iIdMap.Append( map )); |
|
82 CleanupStack::Pop(&(map.extraText)); // map.extraText |
|
83 } |
|
84 |
|
85 |
|
86 |
|
87 EXPORT_C void CLiwMenuPane::AddMenuItemsL( |
|
88 TResourceReader& aReader, |
|
89 TInt aServiceCmd, |
|
90 TInt aIndex, |
|
91 TBool /*aAddSeperator*/) |
|
92 { |
|
93 CEikMenuPaneItem::SData data; |
|
94 |
|
95 TInt index = aIndex; |
|
96 |
|
97 TInt count = aReader.ReadInt16(); |
|
98 for (TInt i = 0; i < count; i++) |
|
99 { |
|
100 data.iCommandId = aReader.ReadInt32(); |
|
101 data.iCascadeId = aReader.ReadInt32(); |
|
102 data.iFlags = aReader.ReadInt32(); |
|
103 data.iText.Copy(aReader.ReadTPtrC()); |
|
104 |
|
105 // Extra text (additional submenu text) must be handled separately |
|
106 // because SData doesn't offer space for it. |
|
107 TPtrC extraText = aReader.ReadTPtrC(); |
|
108 |
|
109 aReader.ReadTPtrC(); // Skip bmpfile. |
|
110 aReader.ReadInt16(); // Skip bmpid. |
|
111 aReader.ReadInt16(); // Skip bmpmask. |
|
112 aReader.ReadInt32(); // Skip extension. |
|
113 |
|
114 if (data.iCommandId == LIW_SUBMENU_TITLE) |
|
115 { |
|
116 AddTitleItemL(data.iText, index); |
|
117 } |
|
118 else |
|
119 { |
|
120 AddMenuItemL(aServiceCmd, data, index++, extraText); |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 |
|
126 |
|
127 EXPORT_C void CLiwMenuPane::AddMenuItemsL( |
|
128 TFileName& aFileName, |
|
129 TInt aResId, |
|
130 TInt aServiceCmd, |
|
131 TInt aIndex, |
|
132 TBool aAddSeparator) |
|
133 { |
|
134 TResourceReader reader; |
|
135 |
|
136 RFs fsSession; |
|
137 User::LeaveIfError( fsSession.Connect() ); |
|
138 CleanupClosePushL( fsSession ); |
|
139 |
|
140 BaflUtils::NearestLanguageFile(fsSession, aFileName); |
|
141 |
|
142 RResourceFile rsFile; |
|
143 rsFile.OpenL( fsSession, aFileName ); |
|
144 CleanupClosePushL( rsFile ); |
|
145 |
|
146 // Read multitapping resource. |
|
147 HBufC8* rBuffer = rsFile.AllocReadLC(aResId & KCCMask); // Remove offset from id |
|
148 reader.SetBuffer( rBuffer ); |
|
149 |
|
150 AddMenuItemsL(reader, aServiceCmd, aIndex, aAddSeparator); |
|
151 |
|
152 CleanupStack::PopAndDestroy(rBuffer); // rBuffer, rsFile, fsSession |
|
153 CleanupStack::PopAndDestroy(&rsFile); |
|
154 CleanupStack::PopAndDestroy(&fsSession); |
|
155 } |
|
156 |
|
157 |
|
158 |
|
159 EXPORT_C TInt CLiwMenuPane::MenuCmdId(TInt aDynCmdId) const |
|
160 { |
|
161 for (TInt i = 0; i < iIdMap.Count(); i++) |
|
162 { |
|
163 if (iIdMap[i].dynMenuCmdId == aDynCmdId) |
|
164 { |
|
165 return iIdMap[i].origCmdId; |
|
166 } |
|
167 } |
|
168 |
|
169 return 0; |
|
170 } |
|
171 |
|
172 |
|
173 |
|
174 EXPORT_C TInt CLiwMenuPane::DynCmdId(TInt aMenuCmdId) const |
|
175 { |
|
176 for (TInt i = 0; i < iIdMap.Count(); i++) |
|
177 { |
|
178 if (iIdMap[i].origCmdId == aMenuCmdId) |
|
179 { |
|
180 return iIdMap[i].dynMenuCmdId; |
|
181 } |
|
182 } |
|
183 |
|
184 return 0; |
|
185 } |
|
186 |
|
187 |
|
188 |
|
189 EXPORT_C TInt CLiwMenuPane::ServiceCmdId(TInt aDynCmdId) const |
|
190 { |
|
191 for (TInt i = 0; i < iIdMap.Count(); i++) |
|
192 { |
|
193 if (iIdMap[i].dynMenuCmdId == aDynCmdId) |
|
194 { |
|
195 return iIdMap[i].serviceCmdId; |
|
196 } |
|
197 } |
|
198 |
|
199 return 0; |
|
200 } |
|
201 |
|
202 |
|
203 |
|
204 TInt CLiwMenuPane::FindCmdId(TInt aIndex) |
|
205 { |
|
206 TInt index; |
|
207 |
|
208 for (TInt i = 0; i < iIdMap.Count(); i++) |
|
209 { |
|
210 if (iMenuPane->MenuItemExists(iIdMap[i].dynMenuCmdId, index)) |
|
211 { |
|
212 if (aIndex == index) |
|
213 { |
|
214 return iIdMap[i].dynMenuCmdId; |
|
215 } |
|
216 } |
|
217 } |
|
218 |
|
219 return -1; |
|
220 } |
|
221 |
|
222 |
|
223 |
|
224 EXPORT_C void CLiwMenuPane::AddTitleItemL(const TDesC& aTitle, TInt aIndex) |
|
225 { |
|
226 CEikMenuPaneItem::SData data; |
|
227 |
|
228 data.iCommandId = LIW_SUBMENU_TITLE; |
|
229 data.iCascadeId = 0; |
|
230 data.iFlags = 0; |
|
231 data.iText.Copy(aTitle); |
|
232 |
|
233 iMenuPane->InsertMenuItemL(data, aIndex); |
|
234 } |
|
235 |
|
236 |
|
237 TBool CLiwMenuPane::IsCmdInRange(TInt aCmdSpaceSize, TInt aCmd) |
|
238 { |
|
239 if ((aCmd >= iPaneOffset + iBaseCmdId) && |
|
240 (aCmd < iPaneOffset + iBaseCmdId + aCmdSpaceSize)) |
|
241 { |
|
242 return ETrue; |
|
243 } |
|
244 |
|
245 return EFalse; |
|
246 } |
|
247 |
|
248 |
|
249 CLiwServiceIfBase* CLiwMenuPane::CommandOwner(TInt aDynCmd) const |
|
250 { |
|
251 for (TInt i = 0; i < iIdMap.Count(); i++) |
|
252 { |
|
253 if (iIdMap[i].dynMenuCmdId == aDynCmd) |
|
254 { |
|
255 return iIdMap[i].owner; |
|
256 } |
|
257 } |
|
258 |
|
259 return NULL; |
|
260 } |
|
261 |
|
262 |
|
263 const TDesC& CLiwMenuPane::ExtraText(TInt aDynMenuCmdId) |
|
264 { |
|
265 TInt count = iIdMap.Count(); |
|
266 for(TInt i = 0; i < count; i++) |
|
267 { |
|
268 if(iIdMap[i].dynMenuCmdId == aDynMenuCmdId) |
|
269 { |
|
270 return iIdMap[i].extraText; |
|
271 } |
|
272 } |
|
273 return KNullDesC; |
|
274 } |
|
275 |
|
276 // End of file |