author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:23:59 +0300 | |
branch | RCL_3 |
changeset 83 | 26b2b12093af |
parent 77 | 7cee158cb8cd |
permissions | -rw-r--r-- |
66 | 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 |
#include <aknenv.h> |
|
13 |
#include <avkon.hrh> |
|
14 |
#include <AknUtils.h> |
|
15 |
#include "swtcommandarranger.h" |
|
16 |
#include "swtcommandcontainer.h" |
|
17 |
#include "swtcommandmenu.h" |
|
18 |
||
19 |
||
20 |
static const TInt KPositiveCbaCategory = 0; |
|
21 |
static const TInt KNegativeCbaCategory = 1; |
|
22 |
static const TInt KCommandGroupCategory = 3; |
|
23 |
static const TInt KPositiveCbaButton = 0; |
|
24 |
static const TInt KNegativeCbaButton = 1; |
|
25 |
static const TInt KMSKCbaButton = 2; |
|
26 |
||
27 |
const TInt KPositionsInCBAForSoftkeys[KCbaButtonCountMax] = |
|
28 |
{ |
|
29 |
0, // Left softkey |
|
30 |
2, // Right softkey |
|
31 |
3 // Middle softkey |
|
32 |
}; |
|
33 |
||
34 |
||
35 |
// ======== MEMBER FUNCTIONS ======== |
|
36 |
||
37 |
||
38 |
inline CSwtCommandArranger::CSwtCommandArranger(MSwtDisplay& aDisplay) |
|
39 |
: iDisplay(aDisplay) |
|
40 |
, iCba(aDisplay.UiUtils().Cba()) |
|
41 |
{ |
|
42 |
iCbaCommands.Reset(); |
|
43 |
iDefaultCommand = NULL; |
|
44 |
iClearCommand = NULL; |
|
45 |
iSelectionCommand = NULL; |
|
46 |
iHelpCommand = NULL; |
|
47 |
} |
|
48 |
||
49 |
||
50 |
CSwtCommandArranger::~CSwtCommandArranger() |
|
51 |
{ |
|
52 |
delete iSearchedContainer; |
|
53 |
||
54 |
// Clean our mess in CBA (in case some commands weren't disposed?) |
|
55 |
ClearCba(); |
|
56 |
// Clean our mess in menus (in case some commands weren't disposed?) |
|
57 |
ClearMenu(); |
|
58 |
||
59 |
// Cannot use protected delete |
|
60 |
if (iCommandMenu) |
|
61 |
{ |
|
62 |
// The command menu is removed from the menu arranger |
|
63 |
iDisplay.MenuArranger().SetCommandMenu(NULL); |
|
64 |
iCommandMenu->Dispose(); |
|
65 |
iCommandMenu = NULL; |
|
66 |
} |
|
67 |
||
68 |
// Cannot use protected delete |
|
69 |
if (iCommandMenuOK) |
|
70 |
{ |
|
71 |
iCommandMenuOK->Dispose(); |
|
72 |
iCommandMenuOK = NULL; |
|
73 |
} |
|
74 |
||
75 |
#ifdef RD_SCALABLE_UI_V2 |
|
76 |
if (iStylusPopupMenuCommands) |
|
77 |
{ |
|
78 |
iStylusPopupMenuCommands->Reset(); |
|
79 |
iStylusPopupMenuCommands->Dispose(); |
|
80 |
iStylusPopupMenuCommands = NULL; |
|
81 |
} |
|
82 |
#endif //RD_SCALABLE_UI_V2 |
|
83 |
||
84 |
// All commands should have been disposed (and therefore removed |
|
85 |
// from following array) when arranger is deleted |
|
86 |
ASSERT(iCommands.Count() == 0); |
|
87 |
iCommands.Close(); |
|
88 |
||
89 |
iCommandCascadeMenus.Close(); |
|
90 |
||
91 |
#ifdef _lint |
|
92 |
iDefaultCommand = NULL; |
|
93 |
iClearCommand = NULL; |
|
94 |
iSelectionCommand = NULL; |
|
95 |
iHelpCommand = NULL; |
|
96 |
#endif |
|
97 |
} |
|
98 |
||
99 |
||
100 |
void CSwtCommandArranger::ConstructL() |
|
101 |
{ |
|
102 |
iButtonCount = KCbaButtonCountMax;//iCba.ButtonCount(); |
|
103 |
||
104 |
iSearchedContainer = CSwtCommandContainer::NewL(); |
|
105 |
iCommandMenu = CSwtCommandMenu::NewL(iDisplay); |
|
106 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
107 |
iCommandMenuOK = CSwtCommandMenu::NewL(iDisplay); |
|
108 |
#endif |
|
109 |
#ifdef RD_SCALABLE_UI_V2 |
|
110 |
iStylusPopupMenuCommands = CSwtCommandMenu::NewL(iDisplay); |
|
111 |
#endif //RD_SCALABLE_UI_V2 |
|
112 |
// The command menu is set to the menu arranger |
|
113 |
iDisplay.MenuArranger().SetCommandMenu(iCommandMenu); |
|
114 |
} |
|
115 |
||
116 |
||
117 |
CSwtCommandArranger* CSwtCommandArranger::NewL(MSwtDisplay& aDisplay) |
|
118 |
{ |
|
119 |
CSwtCommandArranger* self = new(ELeave) CSwtCommandArranger(aDisplay); |
|
120 |
CleanupStack::PushL(self); |
|
121 |
self->ConstructL(); |
|
122 |
CleanupStack::Pop(self); |
|
123 |
return self; |
|
124 |
} |
|
125 |
||
126 |
const MSwtControl* CSwtCommandArranger::GetFocusedControl() const |
|
127 |
{ |
|
128 |
const MSwtShell* activeShell = iDisplay.UiUtils().GetActiveShell(); |
|
129 |
if (activeShell) |
|
130 |
{ |
|
131 |
return activeShell->FocusControl(); |
|
132 |
} |
|
133 |
return NULL; |
|
134 |
} |
|
135 |
||
136 |
const MSwtControl* CSwtCommandArranger::GetFirstFocusedControl() const |
|
137 |
{ |
|
138 |
// Get pointer to first control (the one that is actually focused) to process |
|
139 |
const MSwtControl* firstFocusedControl = GetFocusedControl(); |
|
140 |
||
141 |
if (!firstFocusedControl && iDisplay.UiUtils().GetActiveShell()) |
|
142 |
{ |
|
143 |
firstFocusedControl = iDisplay.UiUtils().GetActiveShell()->Control(); |
|
144 |
} |
|
145 |
||
146 |
return firstFocusedControl; |
|
147 |
} |
|
148 |
||
149 |
void CSwtCommandArranger::ClearCba() |
|
150 |
{ |
|
151 |
// Clear right softkey command and observer added by calling UpdateRightSoftkeyCommandAndObserver |
|
152 |
// if there are |
|
153 |
if (iRightSoftkeyObserverAddedByControl) |
|
154 |
{ |
|
155 |
// remove command observer for right softkey added by control |
|
156 |
iCba.RemoveCommandObserver(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ]); |
|
157 |
iRightSoftkeyObserverAddedByControl = EFalse; |
|
158 |
} |
|
159 |
if (iRightSoftkeyCommandIdFromControl) |
|
160 |
{ |
|
161 |
// remove command added by control |
|
162 |
iCba.RemoveCommandFromStack(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ], |
|
163 |
iRightSoftkeyCommandIdFromControl); |
|
164 |
iRightSoftkeyCommandIdFromControl = 0; |
|
165 |
} |
|
166 |
||
167 |
// For each command that has been mapped to CBA, clean the correponding CBA button |
|
168 |
for (TInt cbaIndex = 0; cbaIndex < iButtonCount; ++cbaIndex) |
|
169 |
{ |
|
170 |
if (iCbaCommands[cbaIndex]) |
|
171 |
{ |
|
172 |
TInt commandId = KSwtCommandBaseId + cbaIndex; |
|
173 |
// Remove our command observer as it's still there |
|
174 |
iCba.RemoveCommandObserver(KPositionsInCBAForSoftkeys[cbaIndex]); |
|
175 |
// Remove our command from stack (even if someone else push another command on top of it) |
|
176 |
iCba.RemoveCommandFromStack(KPositionsInCBAForSoftkeys[cbaIndex], commandId); |
|
177 |
} |
|
178 |
else if (cbaIndex == KMSKCbaButton) |
|
179 |
{ |
|
180 |
MEikButtonGroup* lButtonGroup = iCba.ButtonGroup(); |
|
181 |
TInt cmdID = lButtonGroup->CommandId(KPositionsInCBAForSoftkeys[KMSKCbaButton]); |
|
182 |
iCba.RemoveCommandFromStack(KPositionsInCBAForSoftkeys[KMSKCbaButton], cmdID); |
|
183 |
if (cmdID == EAknSoftkeyContextOptions || cmdID == KSwtCommandBaseId + KMSKCbaButton) |
|
184 |
{ |
|
185 |
iCba.RemoveCommandObserver(KPositionsInCBAForSoftkeys[KMSKCbaButton]); |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
// Clear array of CBA commands |
|
191 |
iCbaCommands.Reset(); |
|
192 |
// Refresh CBA |
|
193 |
if (iCba.IsVisible()) |
|
194 |
{ |
|
195 |
iCba.DrawDeferred(); |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
void CSwtCommandArranger::RefreshCba(TBool aFocusedControlOnly) |
|
200 |
{ |
|
201 |
// Compute CBA and Menu with active shell commands |
|
202 |
TRAPD(err, ComputeAndRefreshCbaAndMenuL(aFocusedControlOnly)); |
|
203 |
if (err) |
|
204 |
{ |
|
205 |
CleanCbaAndMenuAfterLeaveInCompute(); |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
void CSwtCommandArranger::ClearMenu() |
|
210 |
{ |
|
211 |
iCommandMenu->Reset(); |
|
212 |
||
213 |
for (TInt menuIndex = 0; menuIndex < iCommandCascadeMenus.Count(); ++menuIndex) |
|
214 |
{ |
|
215 |
iCommandCascadeMenus[menuIndex]->Reset(); |
|
216 |
iCommandCascadeMenus[menuIndex]->Dispose(); |
|
217 |
} |
|
218 |
iCommandCascadeMenus.Reset(); |
|
219 |
||
220 |
if (iCommandMenuOK) |
|
221 |
{ |
|
222 |
iCommandMenuOK->Reset(); |
|
223 |
} |
|
224 |
||
225 |
if (iDisplay.MenuArranger().EikMenuBar()->IsDisplayed()) |
|
226 |
{ |
|
227 |
iDisplay.MenuArranger().StopDisplayingMenuBar(); |
|
228 |
} |
|
229 |
||
230 |
#ifdef RD_SCALABLE_UI_V2 |
|
231 |
TRAP_IGNORE(iDisplay.MenuArranger().CloseStylusPopupMenuL()); |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
232 |
#endif //RD_SCALABLE_UI_V2); |
66 | 233 |
} |
234 |
||
235 |
void CSwtCommandArranger::ComputeAndRefreshCbaAndMenuL(TBool aFocusedControlOnly) |
|
236 |
{ |
|
237 |
if (iCbaIsBeingComputed) |
|
238 |
return; |
|
239 |
||
240 |
iCbaIsBeingComputed = ETrue; |
|
241 |
||
242 |
MSwtMenuArranger& menuArranger = iDisplay.MenuArranger(); |
|
243 |
||
244 |
iClearCommand = NULL; |
|
245 |
iHelpCommand = NULL; |
|
246 |
iDefaultCommand = NULL; |
|
247 |
iSelectionCommand = NULL; |
|
248 |
iCbaIndexWhenComputeLeave = 0; |
|
249 |
iNumberOfContextOptionMenuItems = 0; |
|
250 |
||
251 |
// Get pointer to first control (the one that is actually focused) to process |
|
252 |
const MSwtControl* control = GetFirstFocusedControl(); |
|
253 |
||
254 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
255 |
if (control) |
|
256 |
{ |
|
257 |
control = control->GetShell().Control(); |
|
258 |
} |
|
259 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
260 |
||
261 |
const MSwtControl* focusedControl(control); |
|
262 |
||
263 |
TFixedArray<TBool, KCbaButtonCountMax> cbaIsAvailable; |
|
264 |
TInt cbaIndex; |
|
265 |
||
266 |
// Ask focused control for CBA buttons availability |
|
267 |
if (control != NULL) |
|
268 |
{ |
|
269 |
for (cbaIndex = 0; cbaIndex < iButtonCount; ++cbaIndex) |
|
270 |
{ |
|
271 |
if (control->CbaButtonIsUsed(cbaIndex)) |
|
272 |
{ |
|
273 |
cbaIsAvailable[cbaIndex] = EFalse; |
|
274 |
} |
|
275 |
else |
|
276 |
{ |
|
277 |
cbaIsAvailable[cbaIndex] = ETrue; |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
else |
|
282 |
{ |
|
283 |
for (cbaIndex = 0; cbaIndex < iButtonCount; ++cbaIndex) |
|
284 |
{ |
|
285 |
cbaIsAvailable[cbaIndex] = ETrue; |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
// Clear commands in CBA and menus |
|
290 |
// It is important to clear menu before the cba. |
|
291 |
ClearMenu(); |
|
292 |
ClearCba(); |
|
293 |
||
294 |
// Go through list of commands belonging to focused control and its parents |
|
295 |
TBool itIsNotTheFirstControlWithCommands = EFalse; |
|
296 |
while (control) |
|
297 |
{ |
|
298 |
// Find command container of control |
|
299 |
TLinearOrder<CSwtCommandContainer> containerOrder(CSwtCommandArranger::CommandContainerCompare); |
|
300 |
iSearchedContainer->SetParentControl(*control); |
|
301 |
TInt indexOfContainer = iCommands.FindInOrder(iSearchedContainer, containerOrder); |
|
302 |
// If control has commands then process them |
|
303 |
if (indexOfContainer != KErrNotFound) |
|
304 |
{ |
|
305 |
// Add a separator in the command menu before appending the new commands to it |
|
306 |
if (itIsNotTheFirstControlWithCommands) |
|
307 |
{ |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
308 |
iCommandMenu->AppendSeparator(); |
66 | 309 |
if (iCommandMenuOK) |
310 |
{ |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
311 |
iCommandMenuOK->AppendSeparator(); |
66 | 312 |
} |
313 |
} |
|
314 |
else |
|
315 |
{ |
|
316 |
itIsNotTheFirstControlWithCommands = ETrue; |
|
317 |
} |
|
318 |
||
319 |
RPointerArray<MSwtCommand>& commands = iCommands[indexOfContainer]->Commands(); |
|
320 |
// commands are ordered by priority |
|
321 |
for (TInt commandIndex = 0; commandIndex < commands.Count(); ++commandIndex) |
|
322 |
{ |
|
323 |
// Assign command to corresponding CBA button if available |
|
324 |
if (commands[commandIndex] != NULL) |
|
325 |
{ |
|
326 |
// Find selection type command. |
|
327 |
// This selection type command can substitute for MSK selection operation |
|
328 |
// that is handled by list, listbox, listview or table |
|
329 |
if (!iSelectionCommand && control == focusedControl |
|
330 |
&& &(commands[commandIndex]->ParentControl()) == focusedControl |
|
331 |
&& commands[commandIndex]->Type() == MSwtCommand::ESelect) |
|
332 |
{ |
|
333 |
iSelectionCommand = commands[commandIndex]; |
|
334 |
} |
|
335 |
// Assign command to CBA buttons and menus. |
|
336 |
AssignCommandToCbaAndMenuL( |
|
337 |
cbaIsAvailable, |
|
338 |
*commands[commandIndex], |
|
339 |
*control, |
|
340 |
indexOfContainer); |
|
341 |
} |
|
342 |
} |
|
343 |
} |
|
344 |
||
345 |
if (aFocusedControlOnly) |
|
346 |
{ |
|
347 |
break; |
|
348 |
} |
|
349 |
||
350 |
// Stop going through parents if we encounter a (modal or not) shell |
|
351 |
if (control->IsShell() /*&& ((control->Style() & KSwtModalityMask)!=KSwtStyleModeless)*/) |
|
352 |
{ |
|
353 |
control = NULL; |
|
354 |
} |
|
355 |
// Next control |
|
356 |
else |
|
357 |
{ |
|
358 |
MSwtComposite* parent = control->GetParent(); |
|
359 |
control = (parent) ? parent->Control() : NULL; |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
// Check if the Options command is needed: |
|
364 |
// - if there are menu items |
|
365 |
// - if there are more than one command in command menu |
|
366 |
// - if there is one command and this item is a command group |
|
367 |
TBool optionsCmdNeeded = EFalse; |
|
368 |
TBool isFullscreen = (iDisplay.UiUtils().GetActiveShell()) ? |
|
369 |
iDisplay.UiUtils().GetActiveShell()->FullScreenMode() : EFalse; |
|
370 |
if (menuArranger.HasMenuItems()) |
|
371 |
{ |
|
372 |
optionsCmdNeeded = ETrue; |
|
373 |
} |
|
374 |
else if (iCommandMenu->CountDisplayableItems() > 1) |
|
375 |
{ |
|
376 |
optionsCmdNeeded = ETrue; |
|
377 |
} |
|
378 |
else if (iCommandMenu->CountDisplayableItems() == 1) |
|
379 |
{ |
|
380 |
if (isFullscreen) |
|
381 |
{ |
|
382 |
optionsCmdNeeded = ETrue; |
|
383 |
} |
|
384 |
else |
|
385 |
{ |
|
386 |
const RPointerArray<MSwtCommand>& menuItems = iCommandMenu->Commands(); |
|
387 |
for (TInt indexMenuItem = 0; indexMenuItem < menuItems.Count(); indexMenuItem++) |
|
388 |
{ |
|
389 |
if (menuItems[indexMenuItem]->IsEnabled() |
|
390 |
&& menuItems[indexMenuItem]->Type() == MSwtCommand::ECommandGroup) |
|
391 |
{ |
|
392 |
optionsCmdNeeded = ETrue; |
|
393 |
} |
|
394 |
} |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
// Update the options command: |
|
399 |
// - if the options command is not set and needed, it is added to the cba. |
|
400 |
// - if the options command is already set and no more needed, it is removed from cba; |
|
401 |
// - if the options command is already set and is still needed, nothing is done; |
|
402 |
if (optionsCmdNeeded && !menuArranger.IsOptionsCommandAdded()) |
|
403 |
{ |
|
404 |
menuArranger.AddOptionsCommandL(); |
|
405 |
} |
|
406 |
else if (!optionsCmdNeeded && menuArranger.IsOptionsCommandAdded()) |
|
407 |
{ |
|
408 |
menuArranger.RemoveOptionsCommand(); |
|
409 |
} |
|
410 |
||
411 |
// If options command has already been added, |
|
412 |
// no other command can be set to left cba button |
|
413 |
if (menuArranger.IsOptionsCommandAdded()) |
|
414 |
{ |
|
415 |
// The left cba command is set to null |
|
416 |
// in case that a command has been set earlier |
|
417 |
iCbaCommands[KPositiveCbaButton] = NULL; |
|
418 |
// Since the options command is set, the left cba button is not available |
|
419 |
cbaIsAvailable[KPositiveCbaButton] = EFalse; |
|
420 |
} |
|
421 |
||
422 |
// Compute the number of items available in context options menu |
|
423 |
// Includes the default command, the OK (or SELECT) commands and |
|
424 |
// the menu items provided by a control (retrieved by GetControlMenu) |
|
425 |
ComputeNumberOfContextOptionsMenuItems(); |
|
426 |
||
427 |
// For each command that has been mapped to CBA, set the correponding CBA button |
|
428 |
cbaIndex = 0; |
|
429 |
iCbaIndexWhenComputeLeave = 0; |
|
430 |
while (cbaIndex < iButtonCount) |
|
431 |
{ |
|
432 |
iCbaIndexWhenComputeLeave = 2 * cbaIndex; |
|
433 |
if (iCbaCommands[cbaIndex]) |
|
434 |
{ |
|
435 |
TInt commandId = KSwtCommandBaseId + cbaIndex; |
|
436 |
// Update command bar |
|
437 |
iCba.UpdateCommandObserverL( |
|
438 |
KPositionsInCBAForSoftkeys[cbaIndex], |
|
439 |
*this); |
|
440 |
++iCbaIndexWhenComputeLeave; |
|
441 |
||
442 |
iCba.AddCommandToStackL( |
|
443 |
KPositionsInCBAForSoftkeys[cbaIndex], |
|
444 |
commandId, |
|
445 |
iCbaCommands[cbaIndex]->Text()); |
|
446 |
||
447 |
// Dimming |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
448 |
if (!iCbaCommands[cbaIndex]->IsEnabled()) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
449 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
450 |
iCba.DimCommand(commandId, ETrue); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
451 |
} |
66 | 452 |
|
453 |
// Set default command |
|
454 |
if (iCbaCommands[cbaIndex] == iDefaultCommand) |
|
455 |
{ |
|
456 |
iCba.SetDefaultCommand(commandId); |
|
457 |
} |
|
458 |
} |
|
459 |
// If MSK not already set, assign it to CBA |
|
460 |
// if MSK enabled and not in fullscreen mode |
|
461 |
else if (AknLayoutUtils::MSKEnabled() |
|
462 |
&& cbaIndex == KMSKCbaButton |
|
463 |
&& !isFullscreen) |
|
464 |
{ |
|
465 |
ASSERT(iCbaCommands[KMSKCbaButton] == NULL); |
|
466 |
AssignMSKToCbaL(); |
|
467 |
} |
|
468 |
++cbaIndex; |
|
469 |
} |
|
470 |
||
471 |
// Refresh CBA |
|
472 |
if (iCba.IsVisible()) |
|
473 |
{ |
|
474 |
iCba.DrawDeferred(); |
|
475 |
} |
|
476 |
||
477 |
iCbaIsBeingComputed = EFalse; |
|
478 |
} |
|
479 |
||
480 |
void CSwtCommandArranger::AssignCommandToCbaAndMenuL( |
|
481 |
TFixedArray<TBool, KCbaButtonCountMax>& aCbaIsAvailable, |
|
482 |
const MSwtCommand& aCommand, |
|
483 |
const MSwtControl& aControl, |
|
484 |
const TInt& aIndexOfContainer) |
|
485 |
{ |
|
486 |
TInt commandCategory = CSwtCommandArranger::CbaCategoryOfCommand(aCommand); |
|
487 |
CSwtCommandMenu* commandCascadeMenu = NULL; |
|
488 |
const MSwtShell* activeShell = iDisplay.UiUtils().GetActiveShell(); |
|
489 |
||
490 |
switch (commandCategory) |
|
491 |
{ |
|
492 |
case KPositiveCbaCategory: |
|
493 |
{ |
|
494 |
// Set left cba button |
|
495 |
||
496 |
// Handle Help and Clear command |
|
497 |
if (aCommand.IsEnabled()) |
|
498 |
{ |
|
499 |
// Set the Help command if the type of command is Help |
|
500 |
if ((!iHelpCommand) |
|
501 |
&& (aCommand.Type() == MSwtCommand::EHelp)) |
|
502 |
{ |
|
503 |
iHelpCommand = &aCommand; |
|
504 |
} |
|
505 |
||
506 |
// If command is positive category, enabled and the type of command is Delete, |
|
507 |
// set the Clear command |
|
508 |
if ((!iClearCommand) |
|
509 |
&& (!aControl.IsKeyUsed(EKeyBackspace)) |
|
510 |
&& (aCommand.Type() == MSwtCommand::EDelete)) |
|
511 |
{ |
|
512 |
iClearCommand = &aCommand; |
|
513 |
} |
|
514 |
} |
|
515 |
||
516 |
if (!iDisplay.MenuArranger().HasMenuItems() |
|
517 |
&& activeShell && !activeShell->FullScreenMode()) |
|
518 |
{ |
|
519 |
// If left button is available, the button can be set |
|
520 |
// Otherwise if the command currently set is disabled and the new one is enabled, |
|
521 |
// then the left button can be set with the new command. |
|
522 |
if ((aCbaIsAvailable[KPositiveCbaButton]) |
|
523 |
|| (iCbaCommands[KPositiveCbaButton] |
|
524 |
&& !iCbaCommands[KPositiveCbaButton]->IsEnabled() |
|
525 |
&& aCommand.IsEnabled())) |
|
526 |
{ |
|
527 |
// CBA may contain only one positive command |
|
528 |
iCbaCommands[KPositiveCbaButton] = &aCommand; |
|
529 |
aCbaIsAvailable[KPositiveCbaButton] = EFalse; |
|
530 |
} |
|
531 |
} |
|
532 |
||
533 |
if (iCommandMenuOK) |
|
534 |
{ |
|
535 |
// Add command to command menu OK |
|
536 |
if (aCommand.Type() == MSwtCommand::EOk |
|
537 |
|| aCommand.Type() == MSwtCommand::ESelect) |
|
538 |
{ |
|
539 |
iCommandMenuOK->AppendCommand(aCommand, NULL); |
|
540 |
} |
|
541 |
} |
|
542 |
} |
|
543 |
break; |
|
544 |
case KNegativeCbaCategory: |
|
545 |
{ |
|
546 |
// Set right cba button |
|
547 |
if (activeShell && !activeShell->FullScreenMode() |
|
548 |
&& aCbaIsAvailable[KNegativeCbaButton]) |
|
549 |
{ |
|
550 |
// CBA may contain only one negative command |
|
551 |
iCbaCommands[KNegativeCbaButton] = &aCommand; |
|
552 |
aCbaIsAvailable[KNegativeCbaButton] = EFalse; |
|
553 |
return; |
|
554 |
} |
|
555 |
} |
|
556 |
break; |
|
557 |
case KCommandGroupCategory: |
|
558 |
{ |
|
559 |
// If command is a commandgroup then create a cascade menu and add sub commands to it. |
|
560 |
// Don't create the cascade menu if commandgroup is disabled. |
|
561 |
if (aCommand.Type() == MSwtCommand::ECommandGroup && |
|
562 |
aCommand.IsEnabled()) |
|
563 |
{ |
|
564 |
commandCascadeMenu = CSwtCommandMenu::NewL(iDisplay); |
|
565 |
if (iCommandCascadeMenus.Append(commandCascadeMenu) == KErrNone) |
|
566 |
{ |
|
567 |
// commandCascadeMenu is owned by CSwtCommandArranger (through iCommandCascadeMenus) |
|
568 |
// so no need to put it on CleanupStack |
|
569 |
AddSubCommandsToCommandMenuL( |
|
570 |
&aControl, |
|
571 |
iCommands[aIndexOfContainer]->SubCommandContainer(aCommand), |
|
572 |
*commandCascadeMenu); |
|
573 |
} |
|
574 |
else |
|
575 |
{ |
|
576 |
commandCascadeMenu->Dispose(); |
|
577 |
commandCascadeMenu = NULL; |
|
578 |
} |
|
579 |
} |
|
580 |
} |
|
581 |
break; |
|
582 |
default: |
|
583 |
ASSERT(EFalse); |
|
584 |
break; |
|
585 |
} |
|
586 |
||
587 |
// Add command to command menu if not default command |
|
588 |
if (aCommand.IsDefaultCommand() && aCommand.IsEnabled() |
|
589 |
&& !iDefaultCommand) |
|
590 |
{ |
|
591 |
iDefaultCommand = &aCommand; |
|
592 |
iCommandMenu->InsertCommand(aCommand, commandCascadeMenu, 0); |
|
593 |
} |
|
594 |
else |
|
595 |
{ |
|
596 |
iCommandMenu->AppendCommand(aCommand, commandCascadeMenu); |
|
597 |
} |
|
598 |
} |
|
599 |
||
600 |
void CSwtCommandArranger::AssignMSKToCbaL() |
|
601 |
{ |
|
602 |
// Get pointer to first control (the one that is actually focused) to process |
|
603 |
const MSwtControl* focusedControl = GetFirstFocusedControl(); |
|
604 |
||
605 |
// Check if there is only one command in context options menu and get it |
|
606 |
MSwtCommand* commandOK = NULL; |
|
607 |
if (iCommandMenuOK && !IsContextSensitiveOperationSet()) |
|
608 |
{ |
|
609 |
const RPointerArray<MSwtCommand>& cmdItems = iCommandMenuOK->Commands(); |
|
610 |
for (TInt indexCommandItem = 0; indexCommandItem < cmdItems.Count(); indexCommandItem++) |
|
611 |
{ |
|
612 |
if (cmdItems[indexCommandItem]->IsEnabled()) |
|
613 |
{ |
|
614 |
commandOK = cmdItems[indexCommandItem]; |
|
615 |
break; |
|
616 |
} |
|
617 |
} |
|
618 |
} |
|
619 |
||
620 |
// If focused control uses the selection key for its internal operation |
|
621 |
if (focusedControl && focusedControl->IsKeyUsed(EKeyOK)) |
|
622 |
{ |
|
623 |
// control will handle EKeyOK internally |
|
624 |
iCba.UpdateCommandObserverL(KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
625 |
*this); |
|
626 |
++iCbaIndexWhenComputeLeave; |
|
627 |
HBufC* mskLabel = focusedControl->MSKLabelL(); |
|
628 |
ASSERT(mskLabel); |
|
629 |
CleanupStack::PushL(mskLabel); |
|
630 |
iCba.AddCommandToStackL( |
|
631 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
632 |
KSwtCommandBaseId + KMSKCbaButton, |
|
633 |
*mskLabel); |
|
634 |
CleanupStack::PopAndDestroy(mskLabel); |
|
635 |
||
636 |
} |
|
637 |
//If default command set |
|
638 |
else if (iDefaultCommand) |
|
639 |
{ |
|
640 |
if (iCbaCommands[KPositiveCbaButton] == iDefaultCommand) |
|
641 |
{ |
|
642 |
//Set MSK to be the same as SK1 |
|
643 |
iCba.AddCommandToStackL( |
|
644 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
645 |
KSwtCommandBaseId + KPositiveCbaButton, //commandId |
|
646 |
iCbaCommands[KPositiveCbaButton]->Text()); |
|
647 |
} |
|
648 |
else |
|
649 |
{ |
|
650 |
iCba.UpdateCommandObserverL( |
|
651 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
652 |
*this); |
|
653 |
++iCbaIndexWhenComputeLeave; |
|
654 |
iCba.AddCommandToStackL( |
|
655 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
656 |
KSwtCommandBaseId + KMSKCbaButton, //commandId |
|
657 |
iDefaultCommand->Text()); |
|
658 |
iCbaCommands[KMSKCbaButton] = iDefaultCommand; |
|
659 |
} |
|
660 |
} |
|
661 |
// allow a external selection command to substitute internal selection operations from focused control |
|
662 |
else if (focusedControl && iSelectionCommand && focusedControl->MSKSelCmdEnabled()) |
|
663 |
{ |
|
664 |
// Selection type command is assigned to the MSK |
|
665 |
// operation in command listener will replace internal handling from the control |
|
666 |
if (iCbaCommands[KPositiveCbaButton] == iSelectionCommand) |
|
667 |
{ |
|
668 |
//Set MSK to be the same as SK1 |
|
669 |
iCba.AddCommandToStackL( |
|
670 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
671 |
KSwtCommandBaseId + KPositiveCbaButton, |
|
672 |
iCbaCommands[KPositiveCbaButton]->Text()); |
|
673 |
} |
|
674 |
else |
|
675 |
{ |
|
676 |
iCba.UpdateCommandObserverL( |
|
677 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
678 |
*this); |
|
679 |
++iCbaIndexWhenComputeLeave; |
|
680 |
iCba.AddCommandToStackL( |
|
681 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
682 |
KSwtCommandBaseId + KMSKCbaButton, |
|
683 |
iSelectionCommand->Text()); |
|
684 |
iCbaCommands[KMSKCbaButton] = iSelectionCommand; |
|
685 |
} |
|
686 |
||
687 |
} |
|
688 |
// If there is only one command in context options menu |
|
689 |
else if (commandOK) |
|
690 |
{ |
|
691 |
if (iCbaCommands[KPositiveCbaButton] == commandOK) |
|
692 |
{ |
|
693 |
//Set MSK to be the same as SK1 |
|
694 |
iCba.AddCommandToStackL( |
|
695 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
696 |
KSwtCommandBaseId + KPositiveCbaButton, //commandId |
|
697 |
iCbaCommands[KPositiveCbaButton]->Text()); |
|
698 |
} |
|
699 |
else |
|
700 |
{ |
|
701 |
iCba.UpdateCommandObserverL( |
|
702 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
703 |
*this); |
|
704 |
++iCbaIndexWhenComputeLeave; |
|
705 |
iCba.AddCommandToStackL( |
|
706 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
707 |
KSwtCommandBaseId + KMSKCbaButton, //commandId |
|
708 |
commandOK->Text()); |
|
709 |
iCbaCommands[KMSKCbaButton] = commandOK; |
|
710 |
} |
|
711 |
} |
|
712 |
// If context options menu has more than one command |
|
713 |
else if (iNumberOfContextOptionMenuItems > 0) |
|
714 |
{ |
|
715 |
iCbaCommands[KMSKCbaButton] = NULL; |
|
716 |
iCba.UpdateCommandObserverL( |
|
717 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
718 |
*this); |
|
719 |
++iCbaIndexWhenComputeLeave; |
|
720 |
iCba.AddCommandToStackL( |
|
721 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
722 |
EAknSoftkeyContextOptions, |
|
723 |
KNullDesC); |
|
724 |
} |
|
725 |
// If there is only one command mapped to softkey 1 |
|
726 |
else if (iCbaCommands[KPositiveCbaButton]) |
|
727 |
{ |
|
728 |
//Set MSK to be the same as SK1 |
|
729 |
iCba.AddCommandToStackL( |
|
730 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
731 |
KSwtCommandBaseId + KPositiveCbaButton, //commandId |
|
732 |
iCbaCommands[KPositiveCbaButton]->Text()); |
|
733 |
} |
|
734 |
else if (iDisplay.MenuArranger().IsOptionsCommandAdded()) |
|
735 |
{ |
|
736 |
//Set MSK to be the same as SK1 |
|
737 |
iCba.AddCommandToStackL( |
|
738 |
KPositionsInCBAForSoftkeys[KMSKCbaButton], |
|
739 |
EAknSoftkeyOptions, //commandId |
|
740 |
KNullDesC); |
|
741 |
} |
|
742 |
} |
|
743 |
||
744 |
void CSwtCommandArranger::ComputeNumberOfContextOptionsMenuItems() |
|
745 |
{ |
|
746 |
// Get pointer to first control (the one that is actually focused) to process |
|
747 |
const MSwtControl* focusedControl = GetFirstFocusedControl(); |
|
748 |
||
749 |
if (!iDefaultCommand) |
|
750 |
{ |
|
751 |
// count context options displayable menu items |
|
752 |
TInt numberOfControlMenuItems(0); |
|
753 |
||
754 |
const MSwtMenu* controlMenu = focusedControl ? focusedControl->GetControlMenu() : NULL; |
|
755 |
if (controlMenu) |
|
756 |
{ |
|
757 |
numberOfControlMenuItems = controlMenu->CountDisplayableItems(); |
|
758 |
} |
|
759 |
||
760 |
if (iCommandMenuOK) |
|
761 |
{ |
|
762 |
TInt numberOfOKCommands(iCommandMenuOK->CountDisplayableItems()); |
|
763 |
||
764 |
// If MSK enabled, not in fullscreen, no control menu items, |
|
765 |
// and there is only one OK (or SELECT) command, |
|
766 |
// this command is not included in the context options menu since |
|
767 |
// it will be assigned to MSK instead |
|
768 |
const MSwtShell* activeShell = iDisplay.UiUtils().GetActiveShell(); |
|
769 |
TBool isFullscreen = activeShell ? activeShell->FullScreenMode() : EFalse; |
|
770 |
if (AknLayoutUtils::MSKEnabled() |
|
771 |
&& !isFullscreen |
|
772 |
&& numberOfControlMenuItems == 0 |
|
773 |
&& numberOfOKCommands == 1) |
|
774 |
{ |
|
775 |
numberOfOKCommands = 0; |
|
776 |
} |
|
777 |
||
778 |
// Addition of control menu items and OK (or SELECT) commands |
|
779 |
iNumberOfContextOptionMenuItems = |
|
780 |
numberOfOKCommands + numberOfControlMenuItems; |
|
781 |
} |
|
782 |
} |
|
783 |
} |
|
784 |
||
785 |
void CSwtCommandArranger::CleanCbaAndMenuAfterLeaveInCompute() |
|
786 |
{ |
|
787 |
iCbaIsBeingComputed = EFalse; |
|
788 |
||
789 |
if (iCbaIndexWhenComputeLeave % 2) |
|
790 |
{ |
|
791 |
iCba.RemoveCommandObserver(KPositionsInCBAForSoftkeys[iCbaIndexWhenComputeLeave / 2]); |
|
792 |
} |
|
793 |
for (TInt cbaIndex = iCbaIndexWhenComputeLeave / 2; cbaIndex < iButtonCount; ++cbaIndex) |
|
794 |
{ |
|
795 |
iCbaCommands[cbaIndex] = NULL; |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
||
800 |
void CSwtCommandArranger::AddSubCommandsToCommandMenuL(const MSwtControl* aControl, |
|
801 |
const CSwtSubCommandContainer& aSubCommandContainer, CSwtCommandMenu& aCommandMenu) |
|
802 |
{ |
|
803 |
// Process sub commands of the container |
|
804 |
for (TInt subCommandIndex = 0; subCommandIndex < aSubCommandContainer.SubCommands().Count(); ++subCommandIndex) |
|
805 |
{ |
|
806 |
CSwtCommandMenu* commandCascadeMenu = NULL; |
|
807 |
// If the sub command is a commandgroup then create cascade menu |
|
808 |
// and process sub commands of the sub command |
|
809 |
if (aSubCommandContainer.SubCommands()[subCommandIndex]->Type() == MSwtCommand::ECommandGroup) |
|
810 |
{ |
|
811 |
commandCascadeMenu = CSwtCommandMenu::NewL(iDisplay); |
|
812 |
if (iCommandCascadeMenus.Append(commandCascadeMenu) == KErrNone) |
|
813 |
{ |
|
814 |
// commandCascadeMenu is owned by CSwtCommandArranger |
|
815 |
// (through iCommandCascadeMenus) so no need to put it on CleanupStack |
|
816 |
AddSubCommandsToCommandMenuL(aControl, |
|
817 |
aSubCommandContainer.SubSubCommandContainer( |
|
818 |
*aSubCommandContainer.SubCommands()[subCommandIndex]), |
|
819 |
*commandCascadeMenu); |
|
820 |
} |
|
821 |
else |
|
822 |
{ |
|
823 |
commandCascadeMenu->Dispose(); |
|
824 |
commandCascadeMenu = NULL; |
|
825 |
} |
|
826 |
} |
|
827 |
// Append sub command to command menu |
|
828 |
aCommandMenu.AppendCommand(*aSubCommandContainer.SubCommands()[subCommandIndex], commandCascadeMenu); |
|
829 |
||
830 |
if (iCommandMenuOK) |
|
831 |
{ |
|
832 |
// Add command to command menu OK |
|
833 |
if (aSubCommandContainer.SubCommands()[subCommandIndex]->Type() == MSwtCommand::EOk || |
|
834 |
aSubCommandContainer.SubCommands()[subCommandIndex]->Type() == MSwtCommand::ESelect) |
|
835 |
{ |
|
836 |
iCommandMenuOK->AppendCommand(*aSubCommandContainer.SubCommands()[subCommandIndex], NULL); |
|
837 |
} |
|
838 |
} |
|
839 |
||
840 |
// Set the clear command |
|
841 |
if (iClearCommand == NULL && |
|
842 |
!aControl->IsKeyUsed(EKeyBackspace) && |
|
843 |
aSubCommandContainer.SubCommands()[subCommandIndex]->Type() == MSwtCommand::EDelete) |
|
844 |
{ |
|
845 |
iClearCommand = aSubCommandContainer.SubCommands()[subCommandIndex]; |
|
846 |
} |
|
847 |
||
848 |
if (!iHelpCommand |
|
849 |
&& aSubCommandContainer.SubCommands()[subCommandIndex]->Type() == MSwtCommand::EHelp) |
|
850 |
{ |
|
851 |
iHelpCommand = aSubCommandContainer.SubCommands()[subCommandIndex]; |
|
852 |
} |
|
853 |
} |
|
854 |
} |
|
855 |
||
856 |
||
857 |
TInt CSwtCommandArranger::CommandContainerCompare(const CSwtCommandContainer& aFirst, |
|
858 |
const CSwtCommandContainer& aSecond) |
|
859 |
{ |
|
860 |
if (aFirst.Control() < aSecond.Control()) |
|
861 |
{ |
|
862 |
return -1; |
|
863 |
} |
|
864 |
else if (aFirst.Control() > aSecond.Control()) |
|
865 |
{ |
|
866 |
return 1; |
|
867 |
} |
|
868 |
else |
|
869 |
{ |
|
870 |
return 0; |
|
871 |
} |
|
872 |
} |
|
873 |
||
874 |
||
875 |
TInt CSwtCommandArranger::CommandCompare(const MSwtCommand& aFirst, const MSwtCommand& aSecond) |
|
876 |
{ |
|
877 |
if (aFirst.Priority() < aSecond.Priority()) |
|
878 |
{ |
|
879 |
return 1/*-1*/; |
|
880 |
} |
|
881 |
else if (aFirst.Priority() > aSecond.Priority()) |
|
882 |
{ |
|
883 |
return -1/*1*/; |
|
884 |
} |
|
885 |
else |
|
886 |
{ |
|
887 |
return 0; |
|
888 |
} |
|
889 |
} |
|
890 |
||
891 |
||
892 |
TBool CSwtCommandArranger::ControlIsInFocusHierarchy(const MSwtControl& aControl) |
|
893 |
{ |
|
894 |
TBool returnedResult = EFalse; |
|
895 |
||
896 |
const MSwtControl* controlInFocusHierarchy; |
|
897 |
||
898 |
// If control is a shell then no need to go through focused control hierarchy. Instead, directly |
|
899 |
// check active shell hierarchy. Moreover, there may be an active shell without a focused control. |
|
900 |
if (aControl.IsShell()) |
|
901 |
{ |
|
902 |
controlInFocusHierarchy = iDisplay.UiUtils().GetActiveShell() ? |
|
903 |
iDisplay.UiUtils().GetActiveShell()->Control() : NULL; |
|
904 |
} |
|
905 |
// If control is a normal control then go through focused control hierarchy |
|
906 |
else |
|
907 |
{ |
|
908 |
controlInFocusHierarchy = GetFocusedControl(); |
|
909 |
} |
|
910 |
||
911 |
// Go through current focus and its parents |
|
912 |
while (controlInFocusHierarchy) |
|
913 |
{ |
|
914 |
if (controlInFocusHierarchy == &aControl) |
|
915 |
{ |
|
916 |
returnedResult = ETrue; |
|
917 |
break; |
|
918 |
} |
|
919 |
||
920 |
// Stop going through parents if we encounter a (modal or not) shell |
|
921 |
if (controlInFocusHierarchy->IsShell() /*&& ((controlInFocusHierarchy->Style() & KSwtModalityMask)!=KSwtStyleModeless)*/) |
|
922 |
{ |
|
923 |
break; |
|
924 |
} |
|
925 |
else |
|
926 |
{ |
|
927 |
MSwtComposite* parent = controlInFocusHierarchy->GetParent(); |
|
928 |
controlInFocusHierarchy = (parent) ? parent->Control() : NULL; |
|
929 |
} |
|
930 |
} |
|
931 |
||
932 |
return returnedResult; |
|
933 |
} |
|
934 |
||
935 |
||
936 |
TBool CSwtCommandArranger::CbaCategoryIsAvailable(TInt aCategory, |
|
937 |
const TFixedArray<TBool, KCbaButtonCountMax>& aCbaAvailability, TInt /*aNeutralCommandCurrentNumber*/) |
|
938 |
{ |
|
939 |
TBool categoryIsAvailable(EFalse); |
|
940 |
||
941 |
switch (aCategory) |
|
942 |
{ |
|
943 |
case KPositiveCbaCategory: |
|
944 |
categoryIsAvailable = aCbaAvailability[KPositiveCbaButton]; |
|
945 |
break; |
|
946 |
||
947 |
case KNegativeCbaCategory: |
|
948 |
categoryIsAvailable = aCbaAvailability[KNegativeCbaButton]; |
|
949 |
break; |
|
950 |
||
951 |
default: |
|
952 |
//ASSERT(aCategory == KNeutralCbaCategory); |
|
953 |
// CBA may contain as many neutral commands as its button count |
|
954 |
/* TInt maxNeutralCommands = aCbaAvailability.Count(); |
|
955 |
if (!aCbaAvailability[KPositiveCbaButton]) |
|
956 |
{ |
|
957 |
maxNeutralCommands--; |
|
958 |
} |
|
959 |
if (!aCbaAvailability[KNegativeCbaButton]) |
|
960 |
{ |
|
961 |
maxNeutralCommands--; |
|
962 |
} |
|
963 |
categoryIsAvailable = (aNeutralCommandCurrentNumber < maxNeutralCommands) ? ETrue : EFalse; |
|
964 |
*/ |
|
965 |
ASSERT(EFalse); |
|
966 |
break; |
|
967 |
} |
|
968 |
||
969 |
return categoryIsAvailable; |
|
970 |
} |
|
971 |
||
972 |
||
973 |
TInt CSwtCommandArranger::CbaCategoryOfCommand(const MSwtCommand& aCommand) |
|
974 |
{ |
|
975 |
if (aCommand.ParentCommand() != NULL || aCommand.Type() == MSwtCommand::ECommandGroup) |
|
976 |
{ |
|
977 |
return KCommandGroupCategory; |
|
978 |
} |
|
979 |
TInt cbaCategory(0); |
|
980 |
||
981 |
switch (aCommand.Type()) |
|
982 |
{ |
|
983 |
case MSwtCommand::EOk: |
|
984 |
case MSwtCommand::ESelect: |
|
985 |
case MSwtCommand::EDelete: |
|
986 |
case MSwtCommand::EGeneral: |
|
987 |
case MSwtCommand::EHelp: |
|
988 |
cbaCategory = KPositiveCbaCategory; |
|
989 |
break; |
|
990 |
||
991 |
case MSwtCommand::EStop: |
|
992 |
case MSwtCommand::ECancel: |
|
993 |
//case MSwtCommand::EDelete: |
|
994 |
case MSwtCommand::EBack: |
|
995 |
case MSwtCommand::EExit: |
|
996 |
cbaCategory = KNegativeCbaCategory; |
|
997 |
break; |
|
998 |
||
999 |
default: |
|
1000 |
ASSERT(EFalse); |
|
1001 |
//ASSERT(aCommand.Type() == MSwtCommand::EHelp || aCommand.Type() == MSwtCommand::EGeneral); |
|
1002 |
//cbaCategory = KNeutralCbaCategory; |
|
1003 |
break; |
|
1004 |
} |
|
1005 |
||
1006 |
return cbaCategory; |
|
1007 |
} |
|
1008 |
||
1009 |
||
1010 |
TInt CSwtCommandArranger::FindAvailableNeutralButtonInCba( |
|
1011 |
const TFixedArray<TBool, KCbaButtonCountMax>& aCbaAvailability) |
|
1012 |
{ |
|
1013 |
if (aCbaAvailability[KPositiveCbaButton]) |
|
1014 |
{ |
|
1015 |
return KPositiveCbaButton; |
|
1016 |
} |
|
1017 |
else if (aCbaAvailability[KNegativeCbaButton]) |
|
1018 |
{ |
|
1019 |
return KNegativeCbaButton; |
|
1020 |
} |
|
1021 |
else |
|
1022 |
{ |
|
1023 |
return KErrNotFound; |
|
1024 |
} |
|
1025 |
} |
|
1026 |
||
1027 |
||
1028 |
||
1029 |
||
1030 |
// |
|
1031 |
// From MSwtCommandArranger |
|
1032 |
// |
|
1033 |
||
1034 |
void CSwtCommandArranger::ControlFocusLost() |
|
1035 |
{ |
|
1036 |
MSwtMenuArranger& menuArranger = iDisplay.MenuArranger(); |
|
1037 |
ASSERT(menuArranger.EikMenuBar() != NULL); |
|
1038 |
if (!menuArranger.EikMenuBar()->IsDisplayed()) |
|
1039 |
{ |
|
1040 |
// Compute CBA and Menu with active shell commands |
|
1041 |
RefreshCba(); |
|
1042 |
} |
|
1043 |
} |
|
1044 |
||
1045 |
void CSwtCommandArranger::ControlFocusGained(const MSwtControl& aControl) |
|
1046 |
{ |
|
1047 |
if (&(aControl.GetShell()) == iDisplay.UiUtils().GetActiveShell()) |
|
1048 |
{ |
|
1049 |
RefreshCba(); |
|
1050 |
} |
|
1051 |
} |
|
1052 |
||
1053 |
void CSwtCommandArranger::ActiveShellLost() |
|
1054 |
{ |
|
1055 |
// If no shell is active then no command is available so clear our mess in CBA and menus |
|
1056 |
ClearCba(); |
|
1057 |
ClearMenu(); |
|
1058 |
} |
|
1059 |
||
1060 |
void CSwtCommandArranger::ActiveShellGained(const MSwtShell& /*aShell*/) |
|
1061 |
{ |
|
1062 |
ASSERT(iDisplay.UiUtils().GetActiveShell()); |
|
1063 |
RefreshCba(); |
|
1064 |
} |
|
1065 |
||
1066 |
void CSwtCommandArranger::CommandAddedL(const MSwtCommand& aCommand) |
|
1067 |
{ |
|
1068 |
// Find allocated command container of parent control of added command |
|
1069 |
TInt indexOfContainer; |
|
1070 |
TLinearOrder<CSwtCommandContainer> containerOrder(CSwtCommandArranger::CommandContainerCompare); |
|
1071 |
iSearchedContainer->SetParentControl(aCommand.ParentControl()); |
|
1072 |
TInt findContainer = iCommands.FindInOrder(iSearchedContainer, indexOfContainer, containerOrder); |
|
1073 |
if (findContainer == KErrNotFound) |
|
1074 |
{ |
|
1075 |
// Insert a new command container as there is no existing one for parent control of added command |
|
1076 |
CSwtCommandContainer* newContainer = CSwtCommandContainer::NewL(); |
|
1077 |
CleanupStack::PushL(newContainer); |
|
1078 |
newContainer->SetParentControl(aCommand.ParentControl()); |
|
1079 |
User::LeaveIfError(iCommands.Insert(newContainer, indexOfContainer)); |
|
1080 |
// Ownership has been transferred to iCommands |
|
1081 |
CleanupStack::Pop(newContainer); |
|
1082 |
} |
|
1083 |
||
1084 |
// Add command to parent control list of commands |
|
1085 |
TLinearOrder<MSwtCommand> commandOrder(CSwtCommandArranger::CommandCompare); |
|
1086 |
TInt insertError = iCommands[indexOfContainer]->InsertCommandInOrder(aCommand, commandOrder); |
|
1087 |
if (insertError) |
|
1088 |
{ |
|
1089 |
// If insertion of command fails and a new container was allocated for the command then delete container |
|
1090 |
if (findContainer == KErrNotFound) |
|
1091 |
{ |
|
1092 |
delete iCommands[indexOfContainer]; |
|
1093 |
iCommands.Remove(indexOfContainer); |
|
1094 |
} |
|
1095 |
User::Leave(insertError); |
|
1096 |
} |
|
1097 |
||
1098 |
// Compute CBA and Menu if parent control of added command is the current focused control or a parent |
|
1099 |
if (ControlIsInFocusHierarchy(aCommand.ParentControl())) |
|
1100 |
{ |
|
1101 |
RefreshCba(); |
|
1102 |
} |
|
1103 |
} |
|
1104 |
||
1105 |
void CSwtCommandArranger::CommandRemoved(const MSwtCommand& aCommand) |
|
1106 |
{ |
|
1107 |
if (iDefaultCommand == &aCommand) |
|
1108 |
{ |
|
1109 |
iDefaultCommand = NULL; |
|
1110 |
} |
|
1111 |
||
1112 |
// Find allocated command container of parent control of removed command |
|
1113 |
TLinearOrder<CSwtCommandContainer> containerOrder(CSwtCommandArranger::CommandContainerCompare); |
|
1114 |
iSearchedContainer->SetParentControl(aCommand.ParentControl()); |
|
1115 |
TInt indexOfContainer = iCommands.FindInOrder(iSearchedContainer, containerOrder); |
|
1116 |
if (indexOfContainer != KErrNotFound) |
|
1117 |
{ |
|
1118 |
// If removed command was the default command then it is not anymore |
|
1119 |
const MSwtCommand* defaultCommand = iCommands[indexOfContainer]->DefaultCommand(); |
|
1120 |
if (defaultCommand == &aCommand) |
|
1121 |
{ |
|
1122 |
iCommands[indexOfContainer]->ClearDefaultCommand(); |
|
1123 |
} |
|
1124 |
// Actually remove command |
|
1125 |
iCommands[indexOfContainer]->Remove(aCommand); |
|
1126 |
// If container is empty then delete container |
|
1127 |
if (iCommands[indexOfContainer]->Commands().Count() == 0) |
|
1128 |
{ |
|
1129 |
delete iCommands[indexOfContainer]; |
|
1130 |
iCommands.Remove(indexOfContainer); |
|
1131 |
} |
|
1132 |
} |
|
1133 |
||
1134 |
// Compute CBA and Menu if parent control of removed command is the current focused control or a parent |
|
1135 |
if (ControlIsInFocusHierarchy(aCommand.ParentControl())) |
|
1136 |
{ |
|
1137 |
RefreshCba(); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
1141 |
void CSwtCommandArranger::CommandContentUpdated(const MSwtCommand& aCommand) |
|
1142 |
{ |
|
1143 |
// Compute CBA and Menu if parent control of updated command is the current focused control or a parent |
|
1144 |
if (ControlIsInFocusHierarchy(aCommand.ParentControl())) |
|
1145 |
{ |
|
1146 |
RefreshCba(); |
|
1147 |
} |
|
1148 |
} |
|
1149 |
||
1150 |
void CSwtCommandArranger::CommandEnablingUpdated(const MSwtCommand& aCommand) |
|
1151 |
{ |
|
1152 |
// Compute CBA and Menu if parent control of updated command is the current focused control or a parent |
|
1153 |
if (ControlIsInFocusHierarchy(aCommand.ParentControl())) |
|
1154 |
{ |
|
1155 |
RefreshCba(); |
|
1156 |
} |
|
1157 |
} |
|
1158 |
||
1159 |
void CSwtCommandArranger::CommandSetAsDefault(const MSwtCommand& aCommand) |
|
1160 |
{ |
|
1161 |
// Find command container of control |
|
1162 |
TLinearOrder<CSwtCommandContainer> containerOrder(CSwtCommandArranger::CommandContainerCompare); |
|
1163 |
iSearchedContainer->SetParentControl(aCommand.ParentControl()); |
|
1164 |
TInt indexOfContainer = iCommands.FindInOrder(iSearchedContainer, containerOrder); |
|
1165 |
if (indexOfContainer != KErrNotFound) |
|
1166 |
{ |
|
1167 |
// Old default command of related parent control is no more default |
|
1168 |
const MSwtCommand* defaultCommand = iCommands[indexOfContainer]->DefaultCommand(); |
|
1169 |
if (defaultCommand != NULL && defaultCommand != &aCommand) |
|
1170 |
{ |
|
1171 |
TInt indexOfCommand = iCommands[indexOfContainer]->Commands().Find(defaultCommand); |
|
1172 |
// (indexOfCommand == KErrNotFound) happens if defaultCommand is a sub command |
|
1173 |
// (but in this case it will never be a candidate for CBA default, so we don't bother) |
|
1174 |
if (indexOfCommand != KErrNotFound) |
|
1175 |
{ |
|
1176 |
iCommands[indexOfContainer]->Commands()[indexOfCommand]->SetDefaultCommand(EFalse); |
|
1177 |
} |
|
1178 |
} |
|
1179 |
// Set the new default command of related parent control |
|
1180 |
iCommands[indexOfContainer]->SetDefaultCommand(aCommand); |
|
1181 |
} |
|
1182 |
||
1183 |
// Compute CBA and Menu if parent control of updated command is the current focused control or a parent |
|
1184 |
if (ControlIsInFocusHierarchy(aCommand.ParentControl())) |
|
1185 |
{ |
|
1186 |
RefreshCba(); |
|
1187 |
} |
|
1188 |
} |
|
1189 |
||
1190 |
TInt CSwtCommandArranger::NumberOfCommandsInCba() const |
|
1191 |
{ |
|
1192 |
TInt numberOfCommand = 0; |
|
1193 |
for (TInt cbaIndex = 0; cbaIndex < iButtonCount; ++cbaIndex) |
|
1194 |
{ |
|
1195 |
if (iCbaCommands[cbaIndex]) |
|
1196 |
{ |
|
1197 |
++numberOfCommand; |
|
1198 |
} |
|
1199 |
} |
|
1200 |
||
1201 |
if (iDisplay.MenuArranger().IsOptionsCommandAdded()) |
|
1202 |
{ |
|
1203 |
++numberOfCommand; |
|
1204 |
} |
|
1205 |
||
1206 |
return numberOfCommand; |
|
1207 |
} |
|
1208 |
||
1209 |
TBool CSwtCommandArranger::ShowMenuL(TSwtMenuType aMenuType) |
|
1210 |
{ |
|
1211 |
if (aMenuType == ESwtNoMenu) |
|
1212 |
{ |
|
1213 |
return EFalse; |
|
1214 |
} |
|
1215 |
||
1216 |
MSwtMenuArranger& menuArranger = iDisplay.MenuArranger(); |
|
1217 |
||
1218 |
ASSERT(menuArranger.EikMenuBar() != NULL); |
|
1219 |
if (menuArranger.EikMenuBar()->IsDisplayed()) |
|
1220 |
{ |
|
1221 |
return EFalse; |
|
1222 |
} |
|
1223 |
||
1224 |
if (aMenuType == ESwtOptionsMenu) |
|
1225 |
{ |
|
1226 |
if (!menuArranger.IsOptionsCommandAdded()) |
|
1227 |
{ |
|
1228 |
return EFalse; |
|
1229 |
} |
|
1230 |
menuArranger.TryDisplayMenuBarL(EFalse); |
|
1231 |
} |
|
1232 |
else if (aMenuType == ESwtContextOptionsMenu) |
|
1233 |
{ |
|
1234 |
if (iNumberOfContextOptionMenuItems <= 0) |
|
1235 |
{ |
|
1236 |
return EFalse; |
|
1237 |
} |
|
1238 |
menuArranger.SetContextMenu(iCommandMenuOK); |
|
1239 |
menuArranger.TryDisplayMenuBarL(ETrue); |
|
1240 |
} |
|
1241 |
||
1242 |
return ETrue; |
|
1243 |
} |
|
1244 |
||
1245 |
TBool CSwtCommandArranger::DoContextSensitiveOperationL() |
|
1246 |
{ |
|
1247 |
if (iDefaultCommand && iDefaultCommand->JavaPeer()) |
|
1248 |
{ |
|
1249 |
iDisplay.PostSelectionEventL(iDefaultCommand->JavaPeer()); |
|
1250 |
return ETrue; |
|
1251 |
} |
|
1252 |
else |
|
1253 |
{ |
|
1254 |
return ShowMenuL(MSwtCommandArranger::ESwtContextOptionsMenu); |
|
1255 |
} |
|
1256 |
} |
|
1257 |
||
1258 |
TBool CSwtCommandArranger::DoClearOperationL() |
|
1259 |
{ |
|
1260 |
if (iClearCommand != NULL) |
|
1261 |
{ |
|
1262 |
iDisplay.PostSelectionEventL(iClearCommand->JavaPeer()); |
|
1263 |
return ETrue; |
|
1264 |
} |
|
1265 |
return EFalse; |
|
1266 |
} |
|
1267 |
||
1268 |
TBool CSwtCommandArranger::IsContextSensitiveOperationSet() const |
|
1269 |
{ |
|
1270 |
if (iDefaultCommand |
|
1271 |
|| (iNumberOfContextOptionMenuItems > 0)) |
|
1272 |
{ |
|
1273 |
return ETrue; |
|
1274 |
} |
|
1275 |
return EFalse; |
|
1276 |
} |
|
1277 |
||
1278 |
TBool CSwtCommandArranger::IsClearOperationSet() const |
|
1279 |
{ |
|
1280 |
if (iClearCommand != NULL && iClearCommand->IsEnabled()) |
|
1281 |
{ |
|
1282 |
return ETrue; |
|
1283 |
} |
|
1284 |
return EFalse; |
|
1285 |
} |
|
1286 |
||
1287 |
// |
|
1288 |
// From MEikCommandObserver |
|
1289 |
// Notified from CEikCba::OfferKeyEventL > CEikButtonGroupContainer::ProcessCommandL |
|
1290 |
// |
|
1291 |
void CSwtCommandArranger::ProcessCommandL(TInt aCommandId) |
|
1292 |
{ |
|
1293 |
TInt cmdIndex(aCommandId - KSwtCommandBaseId); |
|
1294 |
if (aCommandId == EAknSoftkeyContextOptions) |
|
1295 |
{ |
|
1296 |
// This happens if pressing MSK with AknLayoutUtils::MSKEnabled() true. |
|
1297 |
ShowMenuL(MSwtCommandArranger::ESwtContextOptionsMenu); |
|
1298 |
} |
|
1299 |
else |
|
1300 |
{ |
|
1301 |
const MSwtCommand* command = NULL; |
|
1302 |
if ((cmdIndex >= 0) && (cmdIndex < iCbaCommands.Count())) |
|
1303 |
{ |
|
1304 |
command = iCbaCommands[cmdIndex]; |
|
1305 |
} |
|
1306 |
if (command && command->IsEnabled()) |
|
1307 |
{ |
|
1308 |
iDisplay.PostSelectionEventL(command->JavaPeer()); |
|
1309 |
} |
|
1310 |
} |
|
1311 |
} |
|
1312 |
void CSwtCommandArranger::UpdateMSKLabelL() |
|
1313 |
{ |
|
1314 |
||
1315 |
if (iCba.PositionById(KSwtCommandBaseId + KMSKCbaButton) == KPositionsInCBAForSoftkeys[KMSKCbaButton]) |
|
1316 |
{ |
|
1317 |
const MSwtControl* control = GetFocusedControl(); |
|
1318 |
if (AknLayoutUtils::MSKEnabled() && control && control->IsKeyUsed(EKeyOK)) |
|
1319 |
{ |
|
1320 |
iCba.RemoveCommandFromStack(KPositionsInCBAForSoftkeys[KMSKCbaButton], KSwtCommandBaseId + KMSKCbaButton); |
|
1321 |
HBufC* mskLabel = control->MSKLabelL(); |
|
1322 |
ASSERT(mskLabel); |
|
1323 |
CleanupStack::PushL(mskLabel); |
|
1324 |
iCba.AddCommandToStackL(KPositionsInCBAForSoftkeys[KMSKCbaButton], KSwtCommandBaseId + KMSKCbaButton, *mskLabel); |
|
1325 |
CleanupStack::PopAndDestroy(mskLabel); |
|
1326 |
} |
|
1327 |
} |
|
1328 |
} |
|
1329 |
// This function is only used by browser currently in order to adding temporary command |
|
1330 |
// observer. Both added command and observer will be gone after caling RefreshCba(); |
|
1331 |
void CSwtCommandArranger::UpdateRightSoftkeyCommandAndObserver(TInt aCommandId, |
|
1332 |
const TDesC& aText, MEikCommandObserver& aCommandObserver) |
|
1333 |
{ |
|
1334 |
// remove current observer and command for right softkey |
|
1335 |
if (iRightSoftkeyObserverAddedByControl || iCbaCommands[ KNegativeCbaButton ]) |
|
1336 |
{ |
|
1337 |
iCba.RemoveCommandObserver(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ]); |
|
1338 |
} |
|
1339 |
||
1340 |
if (iRightSoftkeyCommandIdFromControl) |
|
1341 |
{ |
|
1342 |
iCba.RemoveCommandFromStack(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ], |
|
1343 |
iRightSoftkeyCommandIdFromControl); |
|
1344 |
} |
|
1345 |
else if (iCbaCommands[ KNegativeCbaButton ]) |
|
1346 |
{ |
|
1347 |
iCba.RemoveCommandFromStack(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ], |
|
1348 |
KSwtCommandBaseId + KNegativeCbaButton); |
|
1349 |
iCbaCommands[ KNegativeCbaButton ] = NULL; |
|
1350 |
} |
|
1351 |
||
1352 |
iRightSoftkeyCommandIdFromControl = 0; |
|
1353 |
iRightSoftkeyObserverAddedByControl = EFalse; |
|
1354 |
||
1355 |
// add control specific command and observer |
|
1356 |
TInt err(KErrNone); |
|
1357 |
TRAP(err, iCba.AddCommandToStackL(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ], |
|
1358 |
aCommandId, aText)); |
|
1359 |
if (err) |
|
1360 |
{ |
|
1361 |
return; |
|
1362 |
} |
|
1363 |
iRightSoftkeyCommandIdFromControl = aCommandId; |
|
1364 |
||
1365 |
TRAP(err, iCba.UpdateCommandObserverL(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ] |
|
1366 |
, aCommandObserver)); |
|
1367 |
if (err) |
|
1368 |
{ |
|
1369 |
iCba.RemoveCommandFromStack(KPositionsInCBAForSoftkeys[ KNegativeCbaButton ], |
|
1370 |
iRightSoftkeyCommandIdFromControl); |
|
1371 |
iRightSoftkeyCommandIdFromControl =0; |
|
1372 |
return; |
|
1373 |
} |
|
1374 |
iRightSoftkeyObserverAddedByControl = ETrue; |
|
1375 |
} |
|
1376 |
||
1377 |
TBool CSwtCommandArranger::HandleEnterKeyL() |
|
1378 |
{ |
|
1379 |
// EnterKey should be treated as MSK |
|
1380 |
||
1381 |
if (!AknLayoutUtils::MSKEnabled()) |
|
1382 |
{ |
|
1383 |
return EFalse; |
|
1384 |
} |
|
1385 |
||
1386 |
// get msk command id |
|
1387 |
MEikButtonGroup* buttonGroup = iCba.ButtonGroup(); |
|
1388 |
TInt mskCmdId = buttonGroup->CommandId(KPositionsInCBAForSoftkeys[ KMSKCbaButton ]); |
|
1389 |
||
1390 |
if (mskCmdId == EAknSoftkeyOptions) |
|
1391 |
{ |
|
1392 |
MSwtMenuArranger& menuArranger = iDisplay.MenuArranger(); |
|
1393 |
if (!menuArranger.EikMenuBar()->IsDisplayed()) |
|
1394 |
{ |
|
1395 |
menuArranger.TryDisplayMenuBarL(EFalse); |
|
1396 |
return ETrue; |
|
1397 |
} |
|
1398 |
} |
|
1399 |
else if (mskCmdId == EAknSoftkeyContextOptions) |
|
1400 |
{ |
|
1401 |
return ShowMenuL(MSwtCommandArranger::ESwtContextOptionsMenu); |
|
1402 |
} |
|
1403 |
else |
|
1404 |
{ |
|
1405 |
TInt cmdIndex(mskCmdId - KSwtCommandBaseId); |
|
1406 |
if (cmdIndex == KMSKCbaButton || cmdIndex == KPositiveCbaButton) |
|
1407 |
{ |
|
1408 |
const MSwtCommand* command = NULL; |
|
1409 |
command = iCbaCommands[ cmdIndex ]; |
|
1410 |
if (command && command->IsEnabled() && command->JavaPeer()) |
|
1411 |
{ |
|
1412 |
iDisplay.PostSelectionEventL(command->JavaPeer()); |
|
1413 |
return ETrue; |
|
1414 |
} |
|
1415 |
} |
|
1416 |
} |
|
1417 |
||
1418 |
return EFalse; |
|
1419 |
} |
|
1420 |
||
1421 |
TBool CSwtCommandArranger::DoHelpOperationL() |
|
1422 |
{ |
|
1423 |
if (iHelpCommand && iHelpCommand->IsEnabled()) |
|
1424 |
{ |
|
1425 |
iDisplay.PostSelectionEventL(iHelpCommand->JavaPeer()); |
|
1426 |
return ETrue; |
|
1427 |
} |
|
1428 |
return EFalse; |
|
1429 |
} |
|
1430 |
||
1431 |
TBool CSwtCommandArranger::IsDefaultCommandSet() const |
|
1432 |
{ |
|
1433 |
return (iDefaultCommand && (iCbaCommands[KPositiveCbaButton] == iDefaultCommand)); |
|
1434 |
} |
|
1435 |
||
1436 |
#ifdef RD_SCALABLE_UI_V2 |
|
1437 |
TBool CSwtCommandArranger::ControlHasStylusPopupMenu(const MSwtControl& aControl) const |
|
1438 |
{ |
|
1439 |
// Check if there is popup/control menu for the control |
|
1440 |
const MSwtMenu* popupMenu = aControl.GetPopupMenu(); |
|
1441 |
if (popupMenu && (popupMenu->CountDisplayableItems(ETrue) > 0)) |
|
1442 |
{ |
|
1443 |
return ETrue; |
|
1444 |
} |
|
1445 |
||
1446 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1447 |
if (aControl.IsShell()) |
|
1448 |
{ |
|
1449 |
return EFalse; |
|
1450 |
} |
|
1451 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
1452 |
||
1453 |
const MSwtMenu* controlMenu = aControl.GetStylusPopupControlMenu(); |
|
1454 |
if (controlMenu && (controlMenu->CountDisplayableItems(ETrue) > 0)) |
|
1455 |
{ |
|
1456 |
return ETrue; |
|
1457 |
} |
|
1458 |
||
1459 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
1460 |
// Check if there are commands. If aControl is the focused one, we can directly check iCommandMenuOk count. |
|
1461 |
// Otherwise check that there is at least one ok/select command for aControl. |
|
1462 |
if (&aControl == GetFocusedControl()) |
|
1463 |
{ |
|
1464 |
return (iCommandMenuOK && iCommandMenuOK->CountDisplayableItems(ETrue) > 0); |
|
1465 |
} |
|
1466 |
else |
|
1467 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
1468 |
{ |
|
1469 |
TInt indexOfContainer = GetIndexOfCommandContainer(aControl); |
|
1470 |
if (indexOfContainer != KErrNotFound) |
|
1471 |
{ |
|
1472 |
return ContainsStylusPopupMenuCommands(iCommands[indexOfContainer], NULL); |
|
1473 |
} |
|
1474 |
else |
|
1475 |
{ |
|
1476 |
return EFalse; |
|
1477 |
} |
|
1478 |
} |
|
1479 |
} |
|
1480 |
||
1481 |
||
1482 |
const MSwtMenu* CSwtCommandArranger::GetStylusPopupCommandsMenu(const MSwtControl& aControl) |
|
1483 |
{ |
|
1484 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
1485 |
if (&aControl == GetFocusedControl()) |
|
1486 |
{ |
|
1487 |
return iCommandMenuOK; |
|
1488 |
} |
|
1489 |
else |
|
1490 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
1491 |
{ |
|
1492 |
iStylusPopupMenuCommands->Reset(); |
|
1493 |
||
1494 |
TInt indexOfContainer = GetIndexOfCommandContainer(aControl); |
|
1495 |
if (indexOfContainer != KErrNotFound) |
|
1496 |
{ |
|
1497 |
AddCommandsToStylusPopupCommandMenu(iCommands[indexOfContainer], NULL); |
|
1498 |
} |
|
1499 |
||
1500 |
return iStylusPopupMenuCommands; |
|
1501 |
} |
|
1502 |
} |
|
1503 |
||
1504 |
||
1505 |
TBool CSwtCommandArranger::ContainsStylusPopupMenuCommands(CSwtCommandContainer* aCmdContainer, |
|
1506 |
CSwtSubCommandContainer* aSubCmdContainer) const |
|
1507 |
{ |
|
1508 |
ASSERT(aSubCmdContainer || aCmdContainer); |
|
1509 |
ASSERT(!aSubCmdContainer || !aCmdContainer); |
|
1510 |
||
1511 |
const RPointerArray<MSwtCommand>* commands = aSubCmdContainer ? |
|
1512 |
&(aSubCmdContainer->SubCommands()) : &(aCmdContainer->Commands()) ; |
|
1513 |
||
1514 |
TInt count = commands->Count(); |
|
1515 |
for (TInt commandIndex = 0; commandIndex < count; ++commandIndex) |
|
1516 |
{ |
|
1517 |
MSwtCommand* cmd = (*commands)[commandIndex]; |
|
1518 |
if (cmd && cmd->IsEnabled()) |
|
1519 |
{ |
|
1520 |
TInt type = cmd->Type(); |
|
1521 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
1522 |
if (type == MSwtCommand::ESelect || type == MSwtCommand::EOk) |
|
1523 |
#else |
|
1524 |
if (type != MSwtCommand::ECommandGroup) |
|
1525 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
1526 |
{ |
|
1527 |
return ETrue; |
|
1528 |
} |
|
1529 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
1530 |
else if (type == MSwtCommand::ECommandGroup) |
|
1531 |
#else |
|
1532 |
else |
|
1533 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
1534 |
{ |
|
1535 |
const CSwtSubCommandContainer* subContainer = aSubCmdContainer ? |
|
1536 |
&(aSubCmdContainer->SubSubCommandContainer(*cmd)): |
|
1537 |
&(aCmdContainer->SubCommandContainer(*cmd)); |
|
1538 |
||
1539 |
if (ContainsStylusPopupMenuCommands(NULL, |
|
1540 |
const_cast<CSwtSubCommandContainer*>(subContainer))) |
|
1541 |
{ |
|
1542 |
return ETrue; |
|
1543 |
} |
|
1544 |
} |
|
1545 |
} |
|
1546 |
} |
|
1547 |
||
1548 |
return EFalse; |
|
1549 |
} |
|
1550 |
||
1551 |
||
1552 |
void CSwtCommandArranger::AddCommandsToStylusPopupCommandMenu( |
|
1553 |
CSwtCommandContainer* aCmdContainer, |
|
1554 |
CSwtSubCommandContainer* aSubCmdContainer) |
|
1555 |
{ |
|
1556 |
ASSERT(aSubCmdContainer || aCmdContainer); |
|
1557 |
ASSERT(!aSubCmdContainer || !aCmdContainer); |
|
1558 |
||
1559 |
const RPointerArray<MSwtCommand>* commands = aSubCmdContainer ? |
|
1560 |
&(aSubCmdContainer->SubCommands()) : &(aCmdContainer->Commands()) ; |
|
1561 |
||
1562 |
TInt count = commands->Count(); |
|
1563 |
for (TInt commandIndex = 0; commandIndex < count; ++commandIndex) |
|
1564 |
{ |
|
1565 |
MSwtCommand* cmd = (*commands)[commandIndex]; |
|
1566 |
if (cmd && cmd->IsEnabled()) |
|
1567 |
{ |
|
1568 |
TInt type = cmd->Type(); |
|
1569 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
1570 |
if (type == MSwtCommand::ESelect || type == MSwtCommand::EOk) |
|
1571 |
#else |
|
1572 |
if (type != MSwtCommand::ECommandGroup) |
|
1573 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
1574 |
{ |
|
1575 |
iStylusPopupMenuCommands->AppendCommand(*cmd, NULL); |
|
1576 |
} |
|
1577 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
1578 |
else if (type == MSwtCommand::ECommandGroup) |
|
1579 |
#else |
|
1580 |
else |
|
1581 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
1582 |
{ |
|
1583 |
const CSwtSubCommandContainer* subContainer = aSubCmdContainer ? |
|
1584 |
&(aSubCmdContainer->SubSubCommandContainer(*cmd)): |
|
1585 |
&(aCmdContainer->SubCommandContainer(*cmd)); |
|
1586 |
||
1587 |
AddCommandsToStylusPopupCommandMenu(NULL, |
|
1588 |
const_cast<CSwtSubCommandContainer*>(subContainer)); |
|
1589 |
} |
|
1590 |
} |
|
1591 |
} |
|
1592 |
} |
|
1593 |
||
1594 |
||
1595 |
TInt CSwtCommandArranger::GetIndexOfCommandContainer(const MSwtControl& aControl) const |
|
1596 |
{ |
|
1597 |
TLinearOrder<CSwtCommandContainer> containerOrder( |
|
1598 |
CSwtCommandArranger::CommandContainerCompare); |
|
1599 |
iSearchedContainer->SetParentControl(aControl); |
|
1600 |
return iCommands.FindInOrder(iSearchedContainer, containerOrder); |
|
1601 |
} |
|
1602 |
||
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
1603 |
#endif //RD_SCALABLE_UI_V2 |
66 | 1604 |