1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
8 ** |
8 ** |
99 int cBmpImages; |
99 int cBmpImages; |
100 HWND hwndMB; |
100 HWND hwndMB; |
101 COLORREF clrBk; |
101 COLORREF clrBk; |
102 }; |
102 }; |
103 |
103 |
104 typedef int (WINAPI *superfunc)(int, int); |
|
105 typedef BOOL (WINAPI *AygCreateMenuBar)(qt_SHMENUBARINFO*); |
104 typedef BOOL (WINAPI *AygCreateMenuBar)(qt_SHMENUBARINFO*); |
106 typedef HRESULT (WINAPI *AygEnableSoftKey)(HWND,UINT,BOOL,BOOL); |
105 typedef HRESULT (WINAPI *AygEnableSoftKey)(HWND,UINT,BOOL,BOOL); |
107 |
106 |
108 static bool aygResolved = false; |
107 static bool aygResolved = false; |
109 static AygCreateMenuBar ptrCreateMenuBar = 0; |
108 static AygCreateMenuBar ptrCreateMenuBar = 0; |
252 else |
251 else |
253 CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_UNCHECKED); |
252 CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_UNCHECKED); |
254 } |
253 } |
255 } |
254 } |
256 |
255 |
|
256 // Removes all items from the menu without destroying the handles. |
|
257 static void qt_wce_clear_menu(HMENU hMenu) |
|
258 { |
|
259 while (RemoveMenu(hMenu, 0, MF_BYPOSITION)); |
|
260 } |
|
261 |
257 /*! |
262 /*! |
258 \internal |
263 \internal |
259 |
264 |
260 This function refreshes the native Windows CE menu. |
265 This function refreshes the native Windows CE menu. |
261 */ |
266 */ |
402 menuHandle = 0; |
407 menuHandle = 0; |
403 } |
408 } |
404 |
409 |
405 QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() { |
410 QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() { |
406 qt_wce_delete_action_list(&actionItems); |
411 qt_wce_delete_action_list(&actionItems); |
407 menuHandle = 0; |
412 if (menuHandle) |
|
413 DestroyMenu(menuHandle); |
408 } |
414 } |
409 |
415 |
410 void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) { |
416 void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) { |
411 QWceMenuAction *action = new QWceMenuAction; |
417 QWceMenuAction *action = new QWceMenuAction; |
412 action->action = a; |
418 action->action = a; |
437 |
443 |
438 HMENU QMenuPrivate::wceMenu(bool create) { |
444 HMENU QMenuPrivate::wceMenu(bool create) { |
439 if (!wce_menu) |
445 if (!wce_menu) |
440 wce_menu = new QWceMenuPrivate; |
446 wce_menu = new QWceMenuPrivate; |
441 if (!wce_menu->menuHandle || create) |
447 if (!wce_menu->menuHandle || create) |
442 wce_menu->rebuild(create); |
448 wce_menu->rebuild(); |
443 return wce_menu->menuHandle; |
449 return wce_menu->menuHandle; |
444 } |
450 } |
445 |
451 |
446 void QMenuPrivate::QWceMenuPrivate::rebuild(bool reCreate) { |
452 void QMenuPrivate::QWceMenuPrivate::rebuild() |
447 if (menuHandle && !reCreate) |
453 { |
448 DestroyMenu(menuHandle); |
454 if (!menuHandle) |
449 menuHandle = CreatePopupMenu(); |
455 menuHandle = CreatePopupMenu(); |
|
456 else |
|
457 qt_wce_clear_menu(menuHandle); |
|
458 |
450 for (int i = 0; i < actionItems.size(); ++i) { |
459 for (int i = 0; i < actionItems.size(); ++i) { |
451 QWceMenuAction *action = actionItems.at(i); |
460 QWceMenuAction *action = actionItems.at(i); |
452 action->menuHandle = menuHandle; |
461 action->menuHandle = menuHandle; |
453 qt_wce_insert_action(menuHandle, action, true); |
462 qt_wce_insert_action(menuHandle, action, true); |
454 } |
463 } |
520 else { |
529 else { |
521 maxEntries = 8; |
530 maxEntries = 8; |
522 resourceHandle = IDR_MAIN_MENU5; |
531 resourceHandle = IDR_MAIN_MENU5; |
523 } |
532 } |
524 Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted"); |
533 Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted"); |
|
534 qt_wce_clear_menu(menuHandle); |
525 DestroyWindow(menubarHandle); |
535 DestroyWindow(menubarHandle); |
526 menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), resourceHandle); |
536 menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), resourceHandle); |
527 Q_ASSERT_X(menubarHandle, "rebuild classic menu", "cannot create menubar from resource"); |
537 Q_ASSERT_X(menubarHandle, "rebuild classic menu", "cannot create menubar from resource"); |
528 DrawMenuBar(menubarHandle); |
538 DrawMenuBar(menubarHandle); |
529 QList<int> menu_ids; |
539 QList<int> menu_ids; |
561 if (!leftButtonAction) |
571 if (!leftButtonAction) |
562 leftButtonAction = qt_wce_get_quit_action(actionItems); |
572 leftButtonAction = qt_wce_get_quit_action(actionItems); |
563 |
573 |
564 leftButtonIsMenu = (leftButtonAction && leftButtonAction->menu()); |
574 leftButtonIsMenu = (leftButtonAction && leftButtonAction->menu()); |
565 Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted"); |
575 Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted"); |
|
576 qt_wce_clear_menu(menuHandle); |
566 DestroyWindow(menubarHandle); |
577 DestroyWindow(menubarHandle); |
567 if (leftButtonIsMenu) { |
578 if (leftButtonIsMenu) { |
568 menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU2); |
579 menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU2); |
569 Q_ASSERT_X(menubarHandle, "rebuild !created left menubar", "cannot create menubar from resource"); |
580 Q_ASSERT_X(menubarHandle, "rebuild !created left menubar", "cannot create menubar from resource"); |
570 menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU); |
581 menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU); |