124 { |
124 { |
125 resolveAygLibs(); |
125 resolveAygLibs(); |
126 if (ptrEnableSoftKey) |
126 if (ptrEnableSoftKey) |
127 ptrEnableSoftKey(handle, command, false, true); |
127 ptrEnableSoftKey(handle, command, false, true); |
128 } |
128 } |
|
129 |
129 static void qt_wce_disable_soft_key(HWND handle, uint command) |
130 static void qt_wce_disable_soft_key(HWND handle, uint command) |
130 { |
131 { |
131 resolveAygLibs(); |
132 resolveAygLibs(); |
132 if (ptrEnableSoftKey) |
133 if (ptrEnableSoftKey) |
133 ptrEnableSoftKey(handle, command, false, false); |
134 ptrEnableSoftKey(handle, command, false, false); |
134 } |
135 } |
135 |
136 |
136 static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list) { |
137 static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list) |
|
138 { |
137 for(QList<QWceMenuAction*>::Iterator it = list->begin(); it != list->end(); ++it) { |
139 for(QList<QWceMenuAction*>::Iterator it = list->begin(); it != list->end(); ++it) { |
138 QWceMenuAction *action = (*it); |
140 QWceMenuAction *action = (*it); |
139 delete action; |
141 delete action; |
140 action = 0; |
142 action = 0; |
141 } |
143 } |
142 list->clear(); |
144 list->clear(); |
143 } |
145 } |
144 |
146 |
145 //search for first QuitRole in QMenuBar |
147 //search for first QuitRole in QMenuBar |
146 static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems) { |
148 static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems) |
|
149 { |
147 QAction *returnAction = 0; |
150 QAction *returnAction = 0; |
148 for (int i = 0; i < actionItems.size(); ++i) { |
151 for (int i = 0; i < actionItems.size(); ++i) { |
149 QAction *action = actionItems.at(i); |
152 QAction *action = actionItems.at(i); |
150 if (action->menuRole() == QAction::QuitRole) |
153 if (action->menuRole() == QAction::QuitRole) |
151 returnAction = action; |
154 returnAction = action; |
156 return returnAction; //return first action found |
159 return returnAction; //return first action found |
157 } |
160 } |
158 return 0; //nothing found; |
161 return 0; //nothing found; |
159 } |
162 } |
160 |
163 |
161 static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems) { |
164 static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems) |
|
165 { |
162 for (int i = 0; i < actionItems.size(); ++i) { |
166 for (int i = 0; i < actionItems.size(); ++i) { |
163 if (actionItems.at(i)->action->menuRole() == QAction::QuitRole) |
167 if (actionItems.at(i)->action->menuRole() == QAction::QuitRole) |
164 return actionItems.at(i)->action; |
168 return actionItems.at(i)->action; |
165 else if (actionItems.at(i)->action->menu()) { |
169 else if (actionItems.at(i)->action->menu()) { |
166 QAction *returnAction = qt_wce_get_quit_action(actionItems.at(i)->action->menu()->actions()); |
170 QAction *returnAction = qt_wce_get_quit_action(actionItems.at(i)->action->menu()->actions()); |
169 } |
173 } |
170 } |
174 } |
171 return 0; |
175 return 0; |
172 } |
176 } |
173 |
177 |
174 static HMODULE qt_wce_get_module_handle() { |
178 static HMODULE qt_wce_get_module_handle() |
|
179 { |
175 HMODULE module = 0; //handle to resources |
180 HMODULE module = 0; //handle to resources |
176 if (!(module = GetModuleHandle(L"QtGui4"))) //release dynamic |
181 if (!(module = GetModuleHandle(L"QtGui4"))) //release dynamic |
177 if (!(module = GetModuleHandle(L"QtGuid4"))) //debug dynamic |
182 if (!(module = GetModuleHandle(L"QtGuid4"))) //debug dynamic |
178 module = (HINSTANCE)qWinAppInst(); //static |
183 module = (HINSTANCE)qWinAppInst(); //static |
179 Q_ASSERT_X(module, "qt_wce_get_module_handle()", "cannot get handle to module?"); |
184 Q_ASSERT_X(module, "qt_wce_get_module_handle()", "cannot get handle to module?"); |
180 return module; |
185 return module; |
181 } |
186 } |
182 |
187 |
183 static void qt_wce_change_command(HWND menuHandle, int item, int command) { |
188 static void qt_wce_change_command(HWND menuHandle, int item, int command) |
|
189 { |
184 TBBUTTONINFOA tbbi; |
190 TBBUTTONINFOA tbbi; |
185 memset(&tbbi,0,sizeof(tbbi)); |
191 memset(&tbbi,0,sizeof(tbbi)); |
186 tbbi.cbSize = sizeof(tbbi); |
192 tbbi.cbSize = sizeof(tbbi); |
187 tbbi.dwMask = TBIF_COMMAND; |
193 tbbi.dwMask = TBIF_COMMAND; |
188 tbbi.idCommand = command; |
194 tbbi.idCommand = command; |
189 SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); |
195 SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); |
190 } |
196 } |
191 |
197 |
192 static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &newText) { |
198 static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &newText) |
|
199 { |
193 TBBUTTONINFOA tbbi; |
200 TBBUTTONINFOA tbbi; |
194 memset(&tbbi,0,sizeof(tbbi)); |
201 memset(&tbbi,0,sizeof(tbbi)); |
195 tbbi.cbSize = sizeof(tbbi); |
202 tbbi.cbSize = sizeof(tbbi); |
196 tbbi.dwMask = TBIF_TEXT; |
203 tbbi.dwMask = TBIF_TEXT; |
197 QString text = newText; |
204 QString text = newText; |
198 text.remove(QChar::fromLatin1('&')); |
205 text.remove(QChar::fromLatin1('&')); |
199 tbbi.pszText = (LPSTR) text.utf16(); |
206 tbbi.pszText = (LPSTR) text.utf16(); |
200 SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); |
207 SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); |
201 } |
208 } |
202 |
209 |
203 static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags = 0) { |
210 static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags = 0) |
|
211 { |
204 resolveAygLibs(); |
212 resolveAygLibs(); |
205 |
213 |
206 if (ptrCreateMenuBar) { |
214 if (ptrCreateMenuBar) { |
207 qt_SHMENUBARINFO mbi; |
215 qt_SHMENUBARINFO mbi; |
208 memset(&mbi, 0, sizeof(qt_SHMENUBARINFO)); |
216 memset(&mbi, 0, sizeof(qt_SHMENUBARINFO)); |
238 AppendMenu (menu, MF_SEPARATOR , 0, 0); |
246 AppendMenu (menu, MF_SEPARATOR , 0, 0); |
239 } |
247 } |
240 else if (action->action->menu()) { |
248 else if (action->action->menu()) { |
241 text.remove(QChar::fromLatin1('&')); |
249 text.remove(QChar::fromLatin1('&')); |
242 AppendMenu (menu, MF_STRING | flags | MF_POPUP, |
250 AppendMenu (menu, MF_STRING | flags | MF_POPUP, |
243 (UINT) action->action->menu()->wceMenu(created), reinterpret_cast<const wchar_t *> (text.utf16())); |
251 (UINT) action->action->menu()->wceMenu(), reinterpret_cast<const wchar_t *> (text.utf16())); |
244 } |
252 } |
245 else { |
253 else { |
246 AppendMenu (menu, MF_STRING | flags, action->command, reinterpret_cast<const wchar_t *> (text.utf16())); |
254 AppendMenu (menu, MF_STRING | flags, action->command, reinterpret_cast<const wchar_t *> (text.utf16())); |
247 } |
255 } |
248 if (action->action->isCheckable()) |
256 if (action->action->isCheckable()) |
263 \internal |
271 \internal |
264 |
272 |
265 This function refreshes the native Windows CE menu. |
273 This function refreshes the native Windows CE menu. |
266 */ |
274 */ |
267 |
275 |
268 void QMenuBar::wceRefresh() { |
276 void QMenuBar::wceRefresh() |
|
277 { |
269 for (int i = 0; i < nativeMenuBars.size(); ++i) |
278 for (int i = 0; i < nativeMenuBars.size(); ++i) |
270 nativeMenuBars.at(i)->d_func()->wceRefresh(); |
279 nativeMenuBars.at(i)->d_func()->wceRefresh(); |
271 } |
280 } |
272 |
281 |
273 void QMenuBarPrivate::wceRefresh() { |
282 void QMenuBarPrivate::wceRefresh() |
|
283 { |
274 DrawMenuBar(wce_menubar->menubarHandle); |
284 DrawMenuBar(wce_menubar->menubarHandle); |
275 } |
285 } |
276 |
286 |
277 /*! |
287 /*! |
278 \internal |
288 \internal |
279 |
289 |
280 This function sends native Windows CE commands to Qt menus. |
290 This function sends native Windows CE commands to Qt menus. |
281 */ |
291 */ |
282 |
292 |
283 QAction* QMenu::wceCommands(uint command) { |
293 QAction* QMenu::wceCommands(uint command) |
|
294 { |
284 Q_D(QMenu); |
295 Q_D(QMenu); |
285 return d->wceCommands(command); |
296 return d->wceCommands(command); |
286 } |
297 } |
287 |
298 |
288 /*! |
299 /*! |
290 |
301 |
291 This function sends native Windows CE commands to Qt menu bars |
302 This function sends native Windows CE commands to Qt menu bars |
292 and all their child menus. |
303 and all their child menus. |
293 */ |
304 */ |
294 |
305 |
295 void QMenuBar::wceCommands(uint command, HWND) { |
306 void QMenuBar::wceCommands(uint command) |
296 for (int i = 0; i < nativeMenuBars.size(); ++i) |
307 { |
297 nativeMenuBars.at(i)->d_func()->wceCommands(command); |
308 const HWND hwndActiveWindow = GetActiveWindow(); |
298 } |
309 for (int i = 0; i < nativeMenuBars.size(); ++i) { |
299 |
310 QMenuBarPrivate* nativeMenuBar = nativeMenuBars.at(i)->d_func(); |
300 bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint command) { |
311 if (hwndActiveWindow == nativeMenuBar->wce_menubar->parentWindowHandle) |
|
312 nativeMenuBar->wceCommands(command); |
|
313 } |
|
314 } |
|
315 |
|
316 bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint command) |
|
317 { |
301 QAction *foundAction = 0; |
318 QAction *foundAction = 0; |
302 for (int i = 0; i < actions.size(); ++i) { |
319 for (int i = 0; i < actions.size(); ++i) { |
303 if (foundAction) |
|
304 break; |
|
305 QWceMenuAction *action = actions.at(i); |
320 QWceMenuAction *action = actions.at(i); |
306 if (action->action->menu()) { |
321 if (action->action->menu()) { |
307 foundAction = action->action->menu()->wceCommands(command); |
322 foundAction = action->action->menu()->wceCommands(command); |
|
323 if (foundAction) |
|
324 break; |
308 } |
325 } |
309 else if (action->command == command) { |
326 else if (action->command == command) { |
310 emit q_func()->triggered(action->action); |
|
311 action->action->activate(QAction::Trigger); |
327 action->action->activate(QAction::Trigger); |
312 return true; |
328 return true; |
313 } |
329 } |
314 } |
330 } |
315 if (foundAction) { |
331 if (foundAction) { |
317 return true; |
333 return true; |
318 } |
334 } |
319 return false; |
335 return false; |
320 } |
336 } |
321 |
337 |
322 void QMenuBarPrivate::wceCommands(uint command) { |
338 void QMenuBarPrivate::wceCommands(uint command) |
|
339 { |
323 if (wceClassicMenu) { |
340 if (wceClassicMenu) { |
324 for (int i = 0; i < wce_menubar->actionItemsClassic.size(); ++i) |
341 for (int i = 0; i < wce_menubar->actionItemsClassic.size(); ++i) |
325 wceEmitSignals(wce_menubar->actionItemsClassic.at(i), command); |
342 wceEmitSignals(wce_menubar->actionItemsClassic.at(i), command); |
326 } else { |
343 } else { |
327 if (wceEmitSignals(wce_menubar->actionItems, command)) { |
344 if (wceEmitSignals(wce_menubar->actionItems, command)) { |
328 return ; |
345 return; |
329 } |
346 } |
330 else if (wce_menubar->leftButtonIsMenu) {//check if command is on the left quick button |
347 else if (wce_menubar->leftButtonIsMenu) {//check if command is on the left quick button |
331 wceEmitSignals(wce_menubar->actionItemsLeftButton, command); |
348 wceEmitSignals(wce_menubar->actionItemsLeftButton, command); |
332 } |
349 } |
333 else if ((wce_menubar->leftButtonAction) && (command == wce_menubar->leftButtonCommand)) { |
350 else if ((wce_menubar->leftButtonAction) && (command == wce_menubar->leftButtonCommand)) { |
335 wce_menubar->leftButtonAction->activate(QAction::Trigger); |
352 wce_menubar->leftButtonAction->activate(QAction::Trigger); |
336 } |
353 } |
337 } |
354 } |
338 } |
355 } |
339 |
356 |
340 QAction *QMenuPrivate::wceCommands(uint command) { |
357 QAction *QMenuPrivate::wceCommands(uint command) |
|
358 { |
341 QAction *foundAction = 0; |
359 QAction *foundAction = 0; |
342 for (int i = 0; i < wce_menu->actionItems.size(); ++i) { |
360 for (int i = 0; i < wce_menu->actionItems.size(); ++i) { |
343 if (foundAction) |
361 if (foundAction) |
344 break; |
362 break; |
345 QWceMenuAction *action = wce_menu->actionItems.at(i); |
363 QWceMenuAction *action = wce_menu->actionItems.at(i); |
346 if (action->action->menu()) { |
364 if (action->action->menu()) { |
347 foundAction = action->action->menu()->d_func()->wceCommands(command); |
365 foundAction = action->action->menu()->d_func()->wceCommands(command); |
348 } |
366 } |
349 else if (action->command == command) { |
367 else if (action->command == command) { |
350 action->action->activate(QAction::Trigger); |
368 activateAction(action->action, QAction::Trigger); |
351 return action->action; |
369 return action->action; |
352 } |
370 } |
353 } |
371 } |
354 if (foundAction) |
372 if (foundAction) |
355 emit q_func()->triggered(foundAction); |
373 emit q_func()->triggered(foundAction); |
356 return foundAction; |
374 return foundAction; |
357 } |
375 } |
358 |
376 |
359 void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent) { |
377 void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent) |
360 |
378 { |
361 Q_Q(QMenuBar); |
379 Q_Q(QMenuBar); |
362 wce_menubar = new QWceMenuBarPrivate(this); |
380 wce_menubar = new QWceMenuBarPrivate(this); |
363 |
381 |
364 wce_menubar->parentWindowHandle = parent ? parent->winId() : q->winId(); |
382 wce_menubar->parentWindowHandle = parent ? parent->winId() : q->winId(); |
365 wce_menubar->leftButtonAction = defaultAction; |
383 wce_menubar->leftButtonAction = defaultAction; |
369 DrawMenuBar(wce_menubar->menubarHandle); |
387 DrawMenuBar(wce_menubar->menubarHandle); |
370 nativeMenuBars.append(q); |
388 nativeMenuBars.append(q); |
371 wceClassicMenu = (!qt_wince_is_smartphone() && !qt_wince_is_pocket_pc()); |
389 wceClassicMenu = (!qt_wince_is_smartphone() && !qt_wince_is_pocket_pc()); |
372 } |
390 } |
373 |
391 |
374 void QMenuBarPrivate::wceDestroyMenuBar() { |
392 void QMenuBarPrivate::wceDestroyMenuBar() |
|
393 { |
375 Q_Q(QMenuBar); |
394 Q_Q(QMenuBar); |
376 int index = nativeMenuBars.indexOf(q); |
395 int index = nativeMenuBars.indexOf(q); |
377 nativeMenuBars.removeAt(index); |
396 nativeMenuBars.removeAt(index); |
378 if (wce_menubar) |
397 if (wce_menubar) { |
379 delete wce_menubar; |
398 delete wce_menubar; |
380 wce_menubar = 0; |
399 wce_menubar = 0; |
381 } |
400 } |
382 |
401 } |
383 QMenuBarPrivate::QWceMenuBarPrivate::QWceMenuBarPrivate(QMenuBarPrivate *menubar) : |
402 |
384 menubarHandle(0), menuHandle(0),leftButtonMenuHandle(0) , |
403 QMenuBarPrivate::QWceMenuBarPrivate::QWceMenuBarPrivate(QMenuBarPrivate *menubar) |
385 leftButtonAction(0), leftButtonIsMenu(false), d(menubar) { |
404 : menubarHandle(0), menuHandle(0), leftButtonMenuHandle(0), |
386 } |
405 leftButtonAction(0), leftButtonIsMenu(false), d(menubar) |
387 |
406 { |
388 QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate() { |
407 } |
|
408 |
|
409 QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate() |
|
410 { |
389 if (menubarHandle) |
411 if (menubarHandle) |
390 DestroyWindow(menubarHandle); |
412 DestroyWindow(menubarHandle); |
391 qt_wce_delete_action_list(&actionItems); |
413 qt_wce_delete_action_list(&actionItems); |
392 qt_wce_delete_action_list(&actionItemsLeftButton); |
414 qt_wce_delete_action_list(&actionItemsLeftButton); |
393 |
415 |
401 leftButtonMenuHandle = 0; |
423 leftButtonMenuHandle = 0; |
402 leftButtonCommand = 0; |
424 leftButtonCommand = 0; |
403 QMenuBar::wceRefresh(); |
425 QMenuBar::wceRefresh(); |
404 } |
426 } |
405 |
427 |
406 QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate() { |
428 QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate() |
407 menuHandle = 0; |
429 : menuHandle(0) |
408 } |
430 { |
409 |
431 } |
410 QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() { |
432 |
|
433 QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() |
|
434 { |
411 qt_wce_delete_action_list(&actionItems); |
435 qt_wce_delete_action_list(&actionItems); |
412 if (menuHandle) |
436 if (menuHandle) |
413 DestroyMenu(menuHandle); |
437 DestroyMenu(menuHandle); |
414 } |
438 } |
415 |
439 |
416 void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) { |
440 void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) |
|
441 { |
417 QWceMenuAction *action = new QWceMenuAction; |
442 QWceMenuAction *action = new QWceMenuAction; |
418 action->action = a; |
443 action->action = a; |
419 action->command = qt_wce_menu_static_cmd_id++; |
444 action->command = qt_wce_menu_static_cmd_id++; |
420 addAction(action, before); |
445 addAction(action, before); |
421 } |
446 } |
422 |
447 |
423 void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) { |
448 void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) |
|
449 { |
424 if (!action) |
450 if (!action) |
425 return; |
451 return; |
426 int before_index = actionItems.indexOf(before); |
452 int before_index = actionItems.indexOf(before); |
427 if (before_index < 0) { |
453 if (before_index < 0) { |
428 before = 0; |
454 before = 0; |
437 |
463 |
438 This function will return the HMENU used to create the native |
464 This function will return the HMENU used to create the native |
439 Windows CE menu bar bindings. |
465 Windows CE menu bar bindings. |
440 */ |
466 */ |
441 |
467 |
442 HMENU QMenu::wceMenu(bool create) { return d_func()->wceMenu(create); } |
468 HMENU QMenu::wceMenu() |
443 |
469 { |
444 HMENU QMenuPrivate::wceMenu(bool create) { |
470 return d_func()->wceMenu(); |
|
471 } |
|
472 |
|
473 HMENU QMenuPrivate::wceMenu() |
|
474 { |
445 if (!wce_menu) |
475 if (!wce_menu) |
446 wce_menu = new QWceMenuPrivate; |
476 wce_menu = new QWceMenuPrivate; |
447 if (!wce_menu->menuHandle || create) |
477 if (!wce_menu->menuHandle) |
448 wce_menu->rebuild(); |
478 wce_menu->rebuild(); |
449 return wce_menu->menuHandle; |
479 return wce_menu->menuHandle; |
450 } |
480 } |
451 |
481 |
452 void QMenuPrivate::QWceMenuPrivate::rebuild() |
482 void QMenuPrivate::QWceMenuPrivate::rebuild() |
457 qt_wce_clear_menu(menuHandle); |
487 qt_wce_clear_menu(menuHandle); |
458 |
488 |
459 for (int i = 0; i < actionItems.size(); ++i) { |
489 for (int i = 0; i < actionItems.size(); ++i) { |
460 QWceMenuAction *action = actionItems.at(i); |
490 QWceMenuAction *action = actionItems.at(i); |
461 action->menuHandle = menuHandle; |
491 action->menuHandle = menuHandle; |
462 qt_wce_insert_action(menuHandle, action, true); |
492 qt_wce_insert_action(menuHandle, action); |
463 } |
493 } |
464 QMenuBar::wceRefresh(); |
494 QMenuBar::wceRefresh(); |
465 } |
495 } |
466 |
496 |
467 void QMenuPrivate::QWceMenuPrivate::syncAction(QWceMenuAction *) { |
497 void QMenuPrivate::QWceMenuPrivate::syncAction(QWceMenuAction *) |
|
498 { |
468 rebuild(); |
499 rebuild(); |
469 } |
500 } |
470 |
501 |
471 void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action) { |
502 void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action) |
472 actionItems.removeAll(action); |
503 { |
473 delete action; |
504 actionItems.removeAll(action); |
474 action = 0; |
505 delete action; |
475 rebuild(); |
506 rebuild(); |
476 } |
507 } |
477 |
508 |
478 void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before) { |
509 void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before) |
|
510 { |
479 QWceMenuAction *action = new QWceMenuAction; |
511 QWceMenuAction *action = new QWceMenuAction; |
480 action->action = a; |
512 action->action = a; |
481 action->command = qt_wce_menu_static_cmd_id++; |
513 action->command = qt_wce_menu_static_cmd_id++; |
482 addAction(action, before); |
514 addAction(action, before); |
483 } |
515 } |
484 |
516 |
485 void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) { |
517 void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) |
|
518 { |
486 if (!action) |
519 if (!action) |
487 return; |
520 return; |
488 int before_index = actionItems.indexOf(before); |
521 int before_index = actionItems.indexOf(before); |
489 if (before_index < 0) { |
522 if (before_index < 0) { |
490 before = 0; |
523 before = 0; |
492 } |
525 } |
493 actionItems.insert(before_index, action); |
526 actionItems.insert(before_index, action); |
494 rebuild(); |
527 rebuild(); |
495 } |
528 } |
496 |
529 |
497 void QMenuBarPrivate::QWceMenuBarPrivate::syncAction(QWceMenuAction*) { |
530 void QMenuBarPrivate::QWceMenuBarPrivate::syncAction(QWceMenuAction*) |
|
531 { |
498 QMenuBar::wceRefresh(); |
532 QMenuBar::wceRefresh(); |
499 rebuild(); |
533 rebuild(); |
500 } |
534 } |
501 |
535 |
502 void QMenuBarPrivate::QWceMenuBarPrivate::removeAction(QWceMenuAction *action) { |
536 void QMenuBarPrivate::QWceMenuBarPrivate::removeAction(QWceMenuAction *action) |
|
537 { |
503 actionItems.removeAll(action); |
538 actionItems.removeAll(action); |
504 delete action; |
539 delete action; |
505 action = 0; |
|
506 rebuild(); |
540 rebuild(); |
507 } |
541 } |
508 |
542 |
509 void QMenuBarPrivate::_q_updateDefaultAction() { |
543 void QMenuBarPrivate::_q_updateDefaultAction() |
|
544 { |
510 if (wce_menubar) |
545 if (wce_menubar) |
511 wce_menubar->rebuild(); |
546 wce_menubar->rebuild(); |
512 } |
547 } |
513 |
548 |
514 void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() { |
549 void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() |
515 |
550 { |
516 d->q_func()->resize(0,0); |
551 d->q_func()->resize(0,0); |
517 parentWindowHandle = d->q_func()->parentWidget() ? d->q_func()->parentWidget()->winId() : d->q_func()->winId(); |
552 parentWindowHandle = d->q_func()->parentWidget() ? d->q_func()->parentWidget()->winId() : d->q_func()->winId(); |
518 if (d->wceClassicMenu) { |
553 if (d->wceClassicMenu) { |
519 QList<QAction*> actions = d->actions; |
554 QList<QAction*> actions = d->actions; |
520 int maxEntries; |
555 int maxEntries; |
557 QWceMenuAction *action = new QWceMenuAction; |
592 QWceMenuAction *action = new QWceMenuAction; |
558 action->action = subActions.at(c); |
593 action->action = subActions.at(c); |
559 action->command = qt_wce_menu_static_cmd_id++; |
594 action->command = qt_wce_menu_static_cmd_id++; |
560 action->menuHandle = subMenuHandle; |
595 action->menuHandle = subMenuHandle; |
561 actionItemsClassic.last().append(action); |
596 actionItemsClassic.last().append(action); |
562 qt_wce_insert_action(subMenuHandle, action, true); |
597 qt_wce_insert_action(subMenuHandle, action); |
563 } |
598 } |
564 } |
599 } |
565 for (int i = actions.size();i<maxEntries;++i) { |
600 for (int i = actions.size();i<maxEntries;++i) { |
566 qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), QString()); |
601 qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), QString()); |
567 qt_wce_disable_soft_key(menubarHandle, menu_ids.at(i)); |
602 qt_wce_disable_soft_key(menubarHandle, menu_ids.at(i)); |
600 qt_wce_disable_soft_key(menubarHandle, IDM_MENU); |
635 qt_wce_disable_soft_key(menubarHandle, IDM_MENU); |
601 } |
636 } |
602 for (int i = 0; i < actionItems.size(); ++i) { |
637 for (int i = 0; i < actionItems.size(); ++i) { |
603 QWceMenuAction *action = actionItems.at(i); |
638 QWceMenuAction *action = actionItems.at(i); |
604 action->menuHandle = menuHandle; |
639 action->menuHandle = menuHandle; |
605 qt_wce_insert_action(menuHandle, action, true); |
640 qt_wce_insert_action(menuHandle, action); |
606 } |
641 } |
607 if (!leftButtonIsMenu) { |
642 if (!leftButtonIsMenu) { |
608 if (leftButtonAction) { |
643 if (leftButtonAction) { |
609 qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, leftButtonAction->text()); |
644 qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, leftButtonAction->text()); |
610 qt_wce_enable_soft_key(menubarHandle, leftButtonCommand); |
645 qt_wce_enable_soft_key(menubarHandle, leftButtonCommand); |
620 QWceMenuAction *action = new QWceMenuAction; |
655 QWceMenuAction *action = new QWceMenuAction; |
621 action->action = actions.at(i); |
656 action->action = actions.at(i); |
622 action->command = qt_wce_menu_static_cmd_id++; |
657 action->command = qt_wce_menu_static_cmd_id++; |
623 action->menuHandle = leftButtonMenuHandle; |
658 action->menuHandle = leftButtonMenuHandle; |
624 actionItemsLeftButton.append(action); |
659 actionItemsLeftButton.append(action); |
625 qt_wce_insert_action(leftButtonMenuHandle, action, true); |
660 qt_wce_insert_action(leftButtonMenuHandle, action); |
626 } |
661 } |
627 } |
662 } |
628 } |
663 } |
629 DrawMenuBar(menubarHandle); |
664 DrawMenuBar(menubarHandle); |
630 } |
665 } |