author | hgs |
Fri, 15 Oct 2010 12:29:39 +0300 | |
changeset 80 | d6dafc5d983f |
parent 78 | 71ad690e91f5 |
permissions | -rw-r--r-- |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/******************************************************************************* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. This program and the accompanying materials |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* which accompanies this distribution, and is available at |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* Contributors: |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Nokia Corporation - initial implementation |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
*******************************************************************************/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
package org.eclipse.swt.internal.qt; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
import org.eclipse.ercp.swt.mobile.Command; |
80 | 14 |
import org.eclipse.ercp.swt.mobile.Internal_MobilePackageSupport; |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
import org.eclipse.swt.widgets.Control; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
import org.eclipse.swt.widgets.Decorations; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
import org.eclipse.swt.widgets.Display; |
78 | 18 |
import org.eclipse.swt.widgets.Internal_PackageSupport; |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
import org.eclipse.swt.widgets.Menu; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
import org.eclipse.swt.widgets.Shell; |
78 | 21 |
import org.eclipse.swt.widgets.Widget; |
22 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
/** |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
* Manages the Command presentation cycle. This is a singleton object that gets |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
* notified about the events that can have an effect on the way the Commands are |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
* represented. It maintains an ordered list of Commands on the current focus |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
* context with the help of {@link CommandCollection}. It also notifies the |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
* currently active {@link CommandPresentationStrategy} so that the presentation |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
* is updated if necessary. |
78 | 30 |
* |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
* @see Command |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
32 |
* @see CommandCollection |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
* @see CommandPresentationStrategy |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
*/ |
80 | 35 |
public class CommandArranger |
36 |
{ |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
|
78 | 38 |
/** |
80 | 39 |
* A helper for keeping an ordered list of {@link Command}s in the current |
40 |
* focus context. The Commands are ordered according to their proximity to |
|
41 |
* the currently focused control. The ordered list starts with Commands from |
|
42 |
* the currently focused Control if any and ends with the active Shell and |
|
43 |
* includes all the Commands in between. If a Control has more than one |
|
44 |
* Command they are ordered among themselves according to creation order. |
|
78 | 45 |
*/ |
80 | 46 |
public class CommandCollection |
47 |
{ |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
|
78 | 49 |
private Command[] fCommands; |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
|
78 | 51 |
CommandCollection() { |
52 |
super(); |
|
53 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
54 |
|
78 | 55 |
/** |
80 | 56 |
* Adds the command to the collection. Warning: This does not make |
57 |
* duplicate control. |
|
78 | 58 |
* |
59 |
* @param command |
|
60 |
*/ |
|
61 |
void addCommand(Command command) { |
|
62 |
if (command == null) |
|
63 |
return; |
|
64 |
if (fCommands == null) { |
|
65 |
fCommands = new Command[1]; |
|
66 |
fCommands[0] = command; |
|
67 |
return; |
|
68 |
} |
|
69 |
int size = fCommands.length + 1; |
|
70 |
Command[] newList = new Command[size]; |
|
71 |
// find the insertion point so that the order is correct |
|
72 |
int insertPoint = 0; |
|
73 |
Shell activeShell = display.getActiveShell(); |
|
74 |
Control ctrl = display.getFocusControl(); |
|
75 |
while (ctrl != null && ctrl != activeShell) { |
|
80 | 76 |
if (ctrl == Internal_MobilePackageSupport.control(command)) { |
78 | 77 |
// Adding a command to focused control increment by one. |
78 |
// adding Command.internal_getCommands(ctrl).length will |
|
79 |
// just duplicate the count for Commands already in array. |
|
80 |
insertPoint++; |
|
81 |
break; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
} |
80 | 83 |
|
84 |
insertPoint += Internal_PackageSupport.getCommands(ctrl).length; |
|
78 | 85 |
ctrl = ctrl.getParent(); |
86 |
} |
|
87 |
System.arraycopy(fCommands, 0, newList, 0, insertPoint); |
|
88 |
System.arraycopy(fCommands, insertPoint, newList, insertPoint + 1, fCommands.length |
|
89 |
- insertPoint); |
|
90 |
newList[insertPoint] = command; |
|
91 |
fCommands = newList; |
|
92 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
93 |
|
78 | 94 |
/** |
95 |
* Adds the list of Commands to the collection. |
|
96 |
* |
|
97 |
* @param commands |
|
98 |
*/ |
|
99 |
void addCommand(Command[] commands) { |
|
100 |
if (commands == null || commands.length == 0) |
|
101 |
return; |
|
102 |
if (fCommands == null) { |
|
103 |
fCommands = new Command[commands.length]; |
|
104 |
System.arraycopy(commands, 0, fCommands, 0, commands.length); |
|
105 |
return; |
|
106 |
} |
|
107 |
int size = commands.length + fCommands.length; |
|
108 |
Command[] newList = new Command[size]; |
|
109 |
System.arraycopy(fCommands, 0, newList, 0, fCommands.length); |
|
110 |
System.arraycopy(commands, 0, newList, fCommands.length, commands.length); |
|
111 |
fCommands = newList; |
|
112 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
113 |
|
78 | 114 |
/** |
115 |
* Removes the command from the list. |
|
116 |
* |
|
117 |
* @param command |
|
118 |
*/ |
|
119 |
void removeCommand(Command command) { |
|
120 |
if (command == null) |
|
121 |
return; |
|
122 |
if (fCommands == null || fCommands.length == 0) |
|
123 |
return; |
|
124 |
int removeIndex = -1; |
|
125 |
for (int i = 0; i < fCommands.length; i++) { |
|
126 |
if (fCommands[i] == command) { |
|
127 |
removeIndex = i; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
} |
78 | 129 |
} |
130 |
if (removeIndex == -1) |
|
131 |
return; |
|
132 |
Command[] newList = new Command[fCommands.length - 1]; |
|
133 |
System.arraycopy(fCommands, 0, newList, 0, removeIndex); |
|
134 |
System.arraycopy(fCommands, removeIndex + 1, newList, removeIndex, (fCommands.length |
|
135 |
- removeIndex - 1)); |
|
136 |
fCommands = newList; |
|
137 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
138 |
|
78 | 139 |
/** |
140 |
* Returns the number of the Commands |
|
141 |
* |
|
142 |
* @return boolean |
|
143 |
*/ |
|
144 |
int getSize() { |
|
145 |
int size = 0; |
|
146 |
if (fCommands != null) |
|
147 |
size = fCommands.length; |
|
148 |
return size; |
|
149 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
150 |
|
78 | 151 |
/** |
80 | 152 |
* Retrieves the Commands of the types indicated by the commandTypes |
153 |
* array. The order of the commandTypes array has no significance. |
|
154 |
* Passing a null parameter or an empty array retrieves all the |
|
155 |
* available Commands. |
|
78 | 156 |
* |
157 |
* @param commandTypes |
|
158 |
* @return Command list |
|
159 |
*/ |
|
160 |
Command[] getCommands(int[] commandTypes) { |
|
161 |
if (commandTypes == null || commandTypes.length == 0) { |
|
162 |
return fCommands; |
|
163 |
} |
|
164 |
int size = getSize(); |
|
165 |
Command[] filteredCommands = new Command[size]; |
|
166 |
int index = 0; |
|
167 |
for (int i = 0; i < fCommands.length; i++) { |
|
168 |
for (int j = 0; j < commandTypes.length; j++) { |
|
80 | 169 |
if (Internal_MobilePackageSupport.type(fCommands[i]) == commandTypes[j]) { |
78 | 170 |
filteredCommands[index] = fCommands[i]; |
171 |
index++; |
|
172 |
break; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
173 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
174 |
} |
78 | 175 |
} |
176 |
if (size > (index)) {// Some commands filtered resize the Array |
|
177 |
Command[] shrunk = new Command[index]; |
|
178 |
System.arraycopy(filteredCommands, 0, shrunk, 0, index); |
|
179 |
return shrunk; |
|
180 |
} |
|
181 |
return filteredCommands; |
|
182 |
} |
|
183 |
||
184 |
}// CommandCollection |
|
185 |
||
186 |
private CommandCollection currentCommands; |
|
187 |
private Command defaultCommand; |
|
188 |
private Display display; |
|
189 |
Control focusedControl; |
|
190 |
Shell lastKnownActiveShell; |
|
191 |
private Command[] positiveKeyCommands; |
|
192 |
private Command negativeKeyCommand; |
|
193 |
||
194 |
public CommandArranger(Display display) { |
|
195 |
super(); |
|
196 |
this.display = display; |
|
197 |
currentCommands = new CommandCollection(); |
|
198 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
199 |
|
78 | 200 |
/** |
80 | 201 |
* Called when the application changes the QMenuBar. This method does not |
202 |
* handle the cases when the QMenuBar may change when the active top-level |
|
203 |
* Shell changes. Since this does not cause a menu bar change on all |
|
204 |
* platforms. |
|
78 | 205 |
* |
206 |
* @see org.eclipse.swt.widgets.Decorations#setMenuBar(Menu) |
|
207 |
* |
|
208 |
**/ |
|
209 |
public void menuBarChanged(Decorations decorations) { |
|
210 |
if (currentCommands == null || currentCommands.getSize() < 1) |
|
211 |
return; |
|
212 |
// if the changed menu bar is not on the active shell ignore and leave |
|
213 |
// it to focus change. |
|
214 |
if (decorations.getShell() != decorations.getDisplay().getActiveShell()) |
|
215 |
return; |
|
216 |
// Call internal_getOwnMenuBar because the menu bar can be set to null |
|
217 |
// in Decorations and |
|
218 |
// we may need to create the internal one. |
|
219 |
int menuBarHandle = decorations.internal_getOwnMenuBar(); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
220 |
|
78 | 221 |
handleMenuBarChanged(menuBarHandle, currentCommands); |
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* Called when a new Shell becomes active. |
|
226 |
* |
|
227 |
* @see Control#qt_swt_event_focusWasGained() //TODO |
|
228 |
*/ |
|
229 |
public void shellActivityChanged() { |
|
230 |
if (display == null) { |
|
231 |
return; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
232 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
233 |
|
78 | 234 |
Shell activeShell = display.getActiveShell(); |
80 | 235 |
|
78 | 236 |
if (activeShell == lastKnownActiveShell) { |
237 |
return; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
238 |
} |
78 | 239 |
lastKnownActiveShell = activeShell; |
80 | 240 |
|
78 | 241 |
cleanPositiveCommands(); |
242 |
cleanNegativeCommand(); |
|
80 | 243 |
|
78 | 244 |
currentCommands = new CommandCollection(); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
245 |
|
80 | 246 |
if (activeShell != null && Internal_PackageSupport.getCommands(activeShell).length > 0) { |
247 |
currentCommands.addCommand(Internal_PackageSupport.getCommands(activeShell)); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
248 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
249 |
|
78 | 250 |
// Determine where the commands go |
251 |
if (currentCommands.getSize() > 0) { |
|
252 |
Command[] add = currentCommands.getCommands(null); |
|
253 |
updateCommandPositions(add); |
|
254 |
placePositiveCommands(); |
|
255 |
placeNegativeCommand(); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
/** |
|
260 |
* Called when a new Command is created |
|
261 |
* |
|
262 |
* @param command |
|
263 |
*/ |
|
264 |
public void commandAdded(Command command) { |
|
80 | 265 |
if (isInFocusContext(Internal_MobilePackageSupport.control(command))) { |
78 | 266 |
currentCommands.addCommand(command); |
267 |
handleCommandListChange(command, null, currentCommands); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
268 |
} |
78 | 269 |
} |
270 |
||
271 |
/** |
|
272 |
* Called when a Command is disposed |
|
273 |
* |
|
274 |
* @param command |
|
275 |
*/ |
|
276 |
public void commandRemoved(Command command) { |
|
277 |
if (command == defaultCommand) |
|
278 |
defaultCommand = null; |
|
80 | 279 |
if (isInFocusContext(Internal_MobilePackageSupport.control(command))) { |
78 | 280 |
currentCommands.removeCommand(command); |
281 |
handleCommandListChange(null, command, currentCommands); |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
/** |
|
286 |
* Called when the Display is getting disposed. |
|
287 |
*/ |
|
288 |
public void dispose() { |
|
289 |
currentCommands = null; |
|
290 |
display = null; |
|
291 |
positiveKeyCommands = null; |
|
292 |
negativeKeyCommand = null; |
|
293 |
defaultCommand = null; |
|
294 |
lastKnownActiveShell = null; |
|
295 |
} |
|
296 |
||
297 |
/** |
|
298 |
* Called when a Command is set default |
|
299 |
* |
|
300 |
* @param command |
|
301 |
* @see Command#setDefaultCommand(); |
|
302 |
*/ |
|
303 |
public void setDefaultCommand(Command command) { |
|
304 |
defaultCommand = command; |
|
80 | 305 |
if (isInFocusContext(Internal_MobilePackageSupport.control(command))) { |
78 | 306 |
handleDefaultCommandChange(command); |
307 |
} |
|
308 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
309 |
|
78 | 310 |
/** |
311 |
* Returns the default command or null if there is none. |
|
312 |
* |
|
313 |
* @return |
|
314 |
* @see Command#isDefaultCommand() |
|
315 |
*/ |
|
316 |
public Command getDefaultCommand() { |
|
317 |
return defaultCommand; |
|
318 |
} |
|
319 |
||
320 |
private boolean isInFocusContext(Control control) { |
|
321 |
Display display = control.getDisplay(); |
|
322 |
Shell activeShell = display.getActiveShell(); |
|
323 |
return control == activeShell; |
|
324 |
} |
|
325 |
||
326 |
private void handleCommandListChange(Command added, Command removed, CommandCollection commands) { |
|
327 |
cleanNegativeCommand(); |
|
328 |
cleanPositiveCommands(); |
|
329 |
updateCommandPositions(commands.getCommands(null)); |
|
330 |
placeNegativeCommand(); |
|
331 |
placePositiveCommands(); |
|
332 |
} |
|
333 |
||
334 |
private void handleDefaultCommandChange(Command defaultCommand) { |
|
335 |
this.defaultCommand = defaultCommand; |
|
336 |
cleanPositiveCommands(); |
|
337 |
placePositiveCommands(); |
|
338 |
} |
|
339 |
||
340 |
private void updateCommandPositions(Command[] commands) { |
|
341 |
positiveKeyCommands = new Command[commands.length]; |
|
342 |
int positiveKeyIndex = 0; |
|
343 |
for (int i = 0; i < commands.length; i++) { |
|
344 |
Command cmd = commands[i]; |
|
345 |
if (cmd.isDefaultCommand()) { |
|
346 |
defaultCommand = cmd; |
|
347 |
continue; |
|
348 |
} |
|
80 | 349 |
if (CommandUtils.isNegativeType(Internal_MobilePackageSupport.type(cmd))) { |
78 | 350 |
if (negativeKeyCommand == null || negativeKeyCommand.isDisposed()) { |
351 |
negativeKeyCommand = cmd; |
|
80 | 352 |
} |
353 |
else if (negativeKeyCommand.getPriority() <= cmd.getPriority()) { |
|
78 | 354 |
positiveKeyCommands[positiveKeyIndex] = negativeKeyCommand; |
355 |
positiveKeyIndex++; |
|
356 |
negativeKeyCommand = cmd; |
|
80 | 357 |
} |
358 |
else { |
|
78 | 359 |
positiveKeyCommands[positiveKeyIndex] = cmd; |
360 |
positiveKeyIndex++; |
|
361 |
} |
|
362 |
continue; |
|
363 |
} |
|
364 |
positiveKeyCommands[positiveKeyIndex] = cmd; |
|
365 |
positiveKeyIndex++; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
366 |
} |
78 | 367 |
if ((positiveKeyIndex) < positiveKeyCommands.length) {// needs to shrink |
368 |
Command[] rightSized = new Command[positiveKeyIndex]; |
|
369 |
System.arraycopy(positiveKeyCommands, 0, rightSized, 0, rightSized.length); |
|
370 |
positiveKeyCommands = rightSized; |
|
371 |
} |
|
372 |
} |
|
373 |
||
374 |
private void cleanPositiveCommands() { |
|
375 |
boolean useBar = false; |
|
376 |
if ((positiveKeyCommands != null && positiveKeyCommands.length > 1) |
|
377 |
|| (defaultCommand != null && positiveKeyCommands != null)) { |
|
378 |
useBar = true; |
|
379 |
} |
|
380 |
if (defaultCommand != null && !defaultCommand.isDisposed() |
|
80 | 381 |
&& !Internal_MobilePackageSupport.control(defaultCommand).isDisposed()) { |
78 | 382 |
if (useBar) { |
80 | 383 |
OS.QWidget_removeAction(Internal_MobilePackageSupport.control(defaultCommand) |
384 |
.getShell().internal_getOwnMenuBar(), topHandle(defaultCommand)); |
|
385 |
} |
|
386 |
else { |
|
387 |
OS.QWidget_removeAction( |
|
388 |
topHandle(Internal_MobilePackageSupport.control(defaultCommand)), |
|
78 | 389 |
topHandle(defaultCommand)); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
390 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
391 |
} |
78 | 392 |
if (positiveKeyCommands != null) { |
393 |
for (int i = 0; i < positiveKeyCommands.length; i++) { |
|
394 |
Command cmd = positiveKeyCommands[i]; |
|
80 | 395 |
if (cmd == null || cmd.isDisposed() |
396 |
|| Internal_MobilePackageSupport.control(cmd).isDisposed()) { |
|
78 | 397 |
continue; |
398 |
} |
|
399 |
int handle = 0; |
|
400 |
if (useBar) { |
|
80 | 401 |
handle = Internal_MobilePackageSupport.control(cmd).getShell() |
402 |
.internal_getOwnMenuBar(); |
|
403 |
} |
|
404 |
else { |
|
405 |
handle = topHandle(Internal_MobilePackageSupport |
|
406 |
.control(positiveKeyCommands[0])); |
|
78 | 407 |
} |
408 |
OS.QWidget_removeAction(handle, topHandle(cmd)); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
409 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
410 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
411 |
} |
78 | 412 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
413 |
|
78 | 414 |
private void cleanNegativeCommand() { |
415 |
if (negativeKeyCommand != null && !negativeKeyCommand.isDisposed() |
|
80 | 416 |
&& !Internal_MobilePackageSupport.control(negativeKeyCommand).isDisposed()) { |
417 |
OS.QWidget_removeAction( |
|
418 |
topHandle(Internal_MobilePackageSupport.control(negativeKeyCommand)), |
|
78 | 419 |
topHandle(negativeKeyCommand)); |
420 |
} |
|
421 |
} |
|
422 |
||
423 |
private void placeNegativeCommand() { |
|
424 |
if (negativeKeyCommand != null) { |
|
80 | 425 |
OS.QWidget_addAction(Internal_PackageSupport.topHandle(Internal_MobilePackageSupport |
426 |
.control(negativeKeyCommand)), topHandle(negativeKeyCommand)); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
427 |
} |
78 | 428 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
429 |
|
78 | 430 |
private void placePositiveCommands() { |
431 |
if (defaultCommand != null) { |
|
432 |
int defaultCmdHandle = topHandle(defaultCommand); |
|
433 |
if (positiveKeyCommands != null) { |
|
80 | 434 |
OS.QMenuBar_addAction(Internal_MobilePackageSupport.control(defaultCommand) |
435 |
.getShell().internal_getOwnMenuBar(), defaultCmdHandle); |
|
436 |
} |
|
437 |
else { |
|
438 |
OS.QWidget_addAction(Internal_PackageSupport |
|
439 |
.topHandle(Internal_MobilePackageSupport.control(defaultCommand)), |
|
78 | 440 |
defaultCmdHandle); |
441 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
442 |
} |
78 | 443 |
if (positiveKeyCommands != null) { |
444 |
if (positiveKeyCommands.length == 1 && defaultCommand == null) { |
|
80 | 445 |
OS.QWidget_addAction(Internal_PackageSupport |
446 |
.topHandle(Internal_MobilePackageSupport.control(positiveKeyCommands[0])), |
|
78 | 447 |
topHandle(positiveKeyCommands[0])); |
80 | 448 |
} |
449 |
else { |
|
78 | 450 |
CommandUtils.sort(positiveKeyCommands); |
451 |
for (int i = 0; i < positiveKeyCommands.length; i++) { |
|
80 | 452 |
OS.QMenuBar_addAction( |
453 |
Internal_MobilePackageSupport.control(positiveKeyCommands[i]).getShell() |
|
454 |
.internal_getOwnMenuBar(), topHandle(positiveKeyCommands[i])); |
|
78 | 455 |
} |
456 |
} |
|
457 |
} |
|
458 |
} |
|
459 |
||
460 |
private void handleMenuBarChanged(int newMenuBar, CommandCollection commands) { |
|
461 |
placePositiveCommands(); |
|
462 |
} |
|
463 |
||
464 |
private static final int topHandle(Widget w) { |
|
465 |
return Internal_PackageSupport.topHandle(w); |
|
466 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
467 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
468 |
} |