|
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 <eikhkeyt.h> |
|
14 #include <eikon.hrh> |
|
15 #include <eswtcore.rsg> |
|
16 #ifdef RD_SCALABLE_UI_V2 |
|
17 #include <aknstyluspopupmenu.h> |
|
18 #endif //RD_SCALABLE_UI_V2 |
|
19 #include "swtcommandmenu.h" |
|
20 |
|
21 |
|
22 const TUint KCknEnvClipEndChar=0x2026; |
|
23 |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 |
|
28 inline CSwtCommandMenu::CSwtCommandMenu(MSwtDisplay& aDisplay) |
|
29 : iDisplay(aDisplay) |
|
30 { |
|
31 } |
|
32 |
|
33 CSwtCommandMenu::~CSwtCommandMenu() |
|
34 { |
|
35 ASSERT(iItems.Count() == 0); |
|
36 iItems.Close(); |
|
37 ASSERT(iCascadeMenus.Count() == 0); |
|
38 iCascadeMenus.Close(); |
|
39 ASSERT(iSeparators.Count() == 0); |
|
40 iSeparators.Close(); |
|
41 } |
|
42 |
|
43 void CSwtCommandMenu::ConstructL() |
|
44 { |
|
45 } //lint !e1762 |
|
46 |
|
47 CSwtCommandMenu* CSwtCommandMenu::NewL(MSwtDisplay& aDisplay) |
|
48 { |
|
49 CSwtCommandMenu* self = new(ELeave) CSwtCommandMenu(aDisplay); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CSwtCommandMenu::Reset() |
|
57 { |
|
58 iItems.Reset(); |
|
59 iCascadeMenus.Reset(); |
|
60 iSeparators.Reset(); |
|
61 } |
|
62 |
|
63 void CSwtCommandMenu::AppendCommand(const MSwtCommand& aCommand, |
|
64 const MSwtMenu* aCascadeMenu) |
|
65 { |
|
66 // If append fails then item won't appear in menu (and separators might |
|
67 // appear at wrong places if later appends succeed). It's a shame but |
|
68 // it's like that (nothing specific to do if this happens). |
|
69 if (iItems.Append(&aCommand) == KErrNone) |
|
70 { |
|
71 if (iCascadeMenus.Append(aCascadeMenu) != KErrNone) |
|
72 { |
|
73 // If append in cascademenus array fails then remove item to avoid |
|
74 // arrays not being synchronized |
|
75 iItems.Remove(iItems.Count() - 1); |
|
76 } |
|
77 } |
|
78 } |
|
79 |
|
80 void CSwtCommandMenu::InsertCommand(const MSwtCommand& aCommand, |
|
81 const MSwtMenu* aCascadeMenu, TInt aPos) |
|
82 { |
|
83 // If insert fails then item won't appear in menu (and separators might |
|
84 // appear at wrong places if later appends succeed). It's a shame but |
|
85 // it's like that (nothing specific to do if this happens). |
|
86 if (iItems.Insert(&aCommand, aPos) == KErrNone) |
|
87 { |
|
88 if (iCascadeMenus.Insert(aCascadeMenu, aPos) != KErrNone) |
|
89 { |
|
90 // If insert in cascademenus array fails then remove item to avoid |
|
91 // arrays not being synchronized |
|
92 iItems.Remove(aPos); |
|
93 } |
|
94 } |
|
95 } |
|
96 |
|
97 void CSwtCommandMenu::AppendSeparator() |
|
98 { |
|
99 // If append fails then separator won't appear in menu. It's a shame but |
|
100 // it's like that (nothing specific to do if this happens). |
|
101 iSeparators.Append(iItems.Count() - 1); |
|
102 } |
|
103 |
|
104 const RPointerArray<MSwtCommand>& CSwtCommandMenu::Commands() const |
|
105 { |
|
106 return iItems; |
|
107 } |
|
108 |
|
109 TSwtPeer CSwtCommandMenu::Dispose() |
|
110 { |
|
111 // Actual dispose |
|
112 delete this; |
|
113 return NULL; |
|
114 } |
|
115 |
|
116 TSwtPeer CSwtCommandMenu::JavaPeer() const |
|
117 { |
|
118 return NULL; |
|
119 } |
|
120 |
|
121 void CSwtCommandMenu::RegisterChildL(MSwtMenuItem& /*aChild*/, TInt /*aIndex*/) |
|
122 { |
|
123 // CommandMenu contains commands instead of menuitems, so this method is not used |
|
124 } |
|
125 |
|
126 void CSwtCommandMenu::UnregisterChild(MSwtMenuItem& /*aChild*/) |
|
127 { |
|
128 // CommandMenu contains commands instead of menuitems, so this method is not used |
|
129 } |
|
130 |
|
131 void CSwtCommandMenu::SetEnabled(TBool) |
|
132 { |
|
133 } |
|
134 |
|
135 void CSwtCommandMenu::SetVisible(TBool) |
|
136 { |
|
137 } |
|
138 |
|
139 TBool CSwtCommandMenu::IsEnabled() const |
|
140 { |
|
141 return ETrue; |
|
142 } |
|
143 |
|
144 TBool CSwtCommandMenu::IsVisible() const |
|
145 { |
|
146 return ETrue; |
|
147 } |
|
148 |
|
149 void CSwtCommandMenu::SetDefaultItem(MSwtMenuItem*) |
|
150 { |
|
151 } |
|
152 |
|
153 MSwtMenuItem* CSwtCommandMenu::DefaultItem() const |
|
154 { |
|
155 return NULL; |
|
156 } |
|
157 |
|
158 void CSwtCommandMenu::FillPaneL(CEikMenuPane& aMenuPaneControl) const |
|
159 { |
|
160 TInt separatorIndex = 0; |
|
161 TInt count = iItems.Count(); |
|
162 for (TInt itemIndex = 0; itemIndex < count; ++itemIndex) |
|
163 { |
|
164 CEikMenuPaneItem::SData itemData; |
|
165 TInt maxLength = itemData.iText.MaxLength(); |
|
166 if (iItems[itemIndex]->LongLabel().Length() > 0 |
|
167 && iItems[itemIndex]->LongLabel().Length() <= maxLength) |
|
168 { |
|
169 itemData.iText = iItems[itemIndex]->LongLabel(); |
|
170 } |
|
171 else if (iItems[itemIndex]->Text().Length() <= maxLength) |
|
172 { |
|
173 itemData.iText = iItems[itemIndex]->Text(); |
|
174 } |
|
175 else |
|
176 { |
|
177 itemData.iText = iItems[itemIndex]->Text().Left(maxLength - 1); |
|
178 itemData.iText.Append(KCknEnvClipEndChar); |
|
179 } |
|
180 itemData.iExtraText = KNullDesC; |
|
181 itemData.iFlags = iItems[itemIndex]->IsEnabled() ? 0 : EEikMenuItemDimmed; |
|
182 if ((separatorIndex < iSeparators.Count()) && (iSeparators[separatorIndex] == itemIndex)) |
|
183 { |
|
184 itemData.iFlags |= EEikMenuItemSeparatorAfter; |
|
185 ++separatorIndex; |
|
186 } |
|
187 itemData.iCommandId = reinterpret_cast<TInt>(iItems[itemIndex]); |
|
188 itemData.iCascadeId = (iCascadeMenus[itemIndex] != NULL) ? R_SWT_SUBMENUPANE : 0; |
|
189 |
|
190 aMenuPaneControl.AddMenuItemL(itemData); |
|
191 } |
|
192 |
|
193 // Register the pane host. See Host(). |
|
194 iHost = &aMenuPaneControl; |
|
195 } |
|
196 |
|
197 void CSwtCommandMenu::ProcessCommandL(TInt aCommandId, TInt aItemIndex, |
|
198 TBool /*aOfferToSubMenus = EFalse*/) const |
|
199 { |
|
200 // if (reinterpret_cast<TInt>(iItems[aItemIndex]) == aCommandId) |
|
201 const MSwtCommand* command = reinterpret_cast<MSwtCommand*>(aCommandId); |
|
202 aItemIndex = iItems.Count(); |
|
203 for (TInt itemIndex = 0; itemIndex < iItems.Count(); ++itemIndex) |
|
204 { |
|
205 if (command == iItems[itemIndex]) |
|
206 { |
|
207 aItemIndex = itemIndex; |
|
208 break; |
|
209 } |
|
210 } |
|
211 if (aItemIndex < iItems.Count()) |
|
212 { |
|
213 iDisplay.PostSelectionEventL(iItems[aItemIndex]->JavaPeer()); |
|
214 } |
|
215 } |
|
216 |
|
217 TInt CSwtCommandMenu::CountDisplayableItems(TBool /*aStylusPopupMenu = EFalse*/) const |
|
218 { |
|
219 // The displayable items are the enabled items |
|
220 // since, in S60, the disabled items are not added in the menu panes |
|
221 TInt nbDisplayableItems(0); |
|
222 for (TInt itemIndex = 0; itemIndex < iItems.Count(); ++itemIndex) |
|
223 { |
|
224 if (iItems[itemIndex]->IsEnabled()) |
|
225 { |
|
226 nbDisplayableItems++; |
|
227 } |
|
228 } |
|
229 |
|
230 return nbDisplayableItems; |
|
231 } |
|
232 |
|
233 const MSwtMenu* CSwtCommandMenu::GetCascadeMenu(const CEikMenuPaneItem::SData& aItemData) const |
|
234 { |
|
235 for (TInt itemIndex = 0; itemIndex < iItems.Count(); ++itemIndex) |
|
236 { |
|
237 if (iItems[itemIndex]->IsEnabled()) |
|
238 { |
|
239 TInt commandId(REINTERPRET_CAST(TInt, iItems[itemIndex])); |
|
240 if (commandId == aItemData.iCommandId) |
|
241 { |
|
242 return iCascadeMenus[itemIndex]; |
|
243 } |
|
244 } |
|
245 } |
|
246 |
|
247 return NULL; |
|
248 } |
|
249 |
|
250 TBool CSwtCommandMenu::HasRadioGroup() const |
|
251 { |
|
252 return EFalse; |
|
253 } |
|
254 |
|
255 CEikMenuPane* CSwtCommandMenu::Host() const |
|
256 { |
|
257 return iHost; |
|
258 } |
|
259 |
|
260 void CSwtCommandMenu::SetHost(CEikMenuPane* aPane) |
|
261 { |
|
262 iHost = aPane; |
|
263 } |
|
264 |
|
265 void CSwtCommandMenu::SetLocation(TInt /*aX*/, TInt /*aY*/) |
|
266 { |
|
267 // Command menu is not able to change its location |
|
268 // This part of code should never be used! |
|
269 } |
|
270 |
|
271 TPoint CSwtCommandMenu::GetLocation() const |
|
272 { |
|
273 // Command menu is not able to change its location |
|
274 // This part of code should never be used! |
|
275 ASSERT(EFalse); |
|
276 return TPoint(); |
|
277 } |
|
278 |
|
279 TBool CSwtCommandMenu::LocationEnabled() const |
|
280 { |
|
281 return EFalse; |
|
282 } |
|
283 |
|
284 const RPointerArray<MSwtMenuItem>* CSwtCommandMenu::Items() const |
|
285 { |
|
286 return NULL; |
|
287 } |
|
288 |
|
289 #ifdef RD_SCALABLE_UI_V2 |
|
290 void CSwtCommandMenu::FillPopupL(CAknStylusPopUpMenu& aPopupMenu) const |
|
291 { |
|
292 for (TInt i = 0; i < iItems.Count(); ++i) |
|
293 { |
|
294 if (iItems[i]->IsEnabled()) |
|
295 { |
|
296 if (iItems[i]->LongLabel().Length() > 0) |
|
297 { |
|
298 aPopupMenu.AddMenuItemL(iItems[i]->LongLabel(), |
|
299 reinterpret_cast<TInt>(iItems[i])); |
|
300 } |
|
301 else |
|
302 { |
|
303 aPopupMenu.AddMenuItemL(iItems[i]->Text(), reinterpret_cast<TInt>(iItems[i])); |
|
304 } |
|
305 } |
|
306 } |
|
307 } |
|
308 #endif //RD_SCALABLE_UI_V2 |
|
309 |
|
310 |