How to disable reacting the MENU-widget to PID-events (mouse / touchpad)?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • How to disable reacting the MENU-widget to PID-events (mouse / touchpad)?

      Hello.

      There was a following task with special MENU behaviour:

      If I select the menu-item that is "endpoint" (not a submenu), and press Enter, then new dialog-window should appear, but the entire menu should not collapsed.
      After closing dialog-window I should return to last selected menu-item.

      For that I wrote the special MENU-callback (see pictures). This works well on our device with a HW-keyboard (without a mouse).

      But now we intend to use a new device with touch screen.

      To prevent a reaction of menu to PID while dialog window is still open I tried to use WM_MakeModal. It works, the menu does not respond to the mouse until I close this modal window.
      But for this modal window I cannot use screen-keyboard for input data to this window, because it is modal.

      How to resolve this situation? I would like to implement this behavior of the menu - it should not respond to a pointer (mouse / touchpad) of events while this window is open.

      Is it possible to make a "modal" window with its modality not for all windows?


      Or maybe there is a way to handle mouse/touchpad events inside MENU-callback to avoid their influence to menu behaviour (collapsing)?
      Could you provide some code sample?
      Images
      • menu_parWin.PNG

        11.16 kB, 466×256, viewed 565 times
      • menu_parWin_2.PNG

        13.53 kB, 484×249, viewed 443 times
      Best regards,
      Volodymyr.

      The post was edited 1 time, last by volodymyr ().

    • Hello,

      maybe it is just easier to make modal the keyboard window and after closing it pass the "modality" to the dialog window.

      C Source Code

      1. #include "DIALOG.h"
      2. #define ID_MENU (GUI_ID_USER + 0x00)
      3. #define ID_MENU_SUB (GUI_ID_USER + 0x01)
      4. #define ID_MENU_SUB_I1 (GUI_ID_USER + 0x02)
      5. #define ID_MENU_SUB_I2 (GUI_ID_USER + 0x03)
      6. #define ID_MENU_SUB_I3 (GUI_ID_USER + 0x04)
      7. #define ID_FRAMEWIN_DLG (GUI_ID_USER + 0x05)
      8. #define ID_FRAMEWIN_KBRD (GUI_ID_USER + 0x06)
      9. static const GUI_WIDGET_CREATE_INFO _aFW_DlgCreate[] = {
      10. { FRAMEWIN_CreateIndirect, "Dialog window", ID_FRAMEWIN_DLG, 50, 30, 160, 60, 0, 0x64, 0 },
      11. { EDIT_CreateIndirect, "Edit", GUI_ID_EDIT0, 36, 10, 80, 20, 0, 0x64, 0 },
      12. };
      13. static const GUI_WIDGET_CREATE_INFO _aFW_KbrdCreate[] = {
      14. { FRAMEWIN_CreateIndirect, "Keyboard", ID_FRAMEWIN_KBRD, 100, 200, 160, 120, 0, 0x64, 0 },
      15. { BUTTON_CreateIndirect, "1", GUI_ID_BUTTON0, 16, 26, 30, 30, 0, 0x0, 0 },
      16. { BUTTON_CreateIndirect, "2", GUI_ID_BUTTON1, 58, 26, 30, 30, 0, 0x0, 0 },
      17. { BUTTON_CreateIndirect, "3", GUI_ID_BUTTON2, 101, 26, 30, 30, 0, 0x0, 0 },
      18. };
      19. MENU_Handle hMenu, hMenuSub;
      20. FRAMEWIN_Handle hFW_Dlg, hFW_Kbrd;
      21. EDIT_Handle hEdit;
      22. static void _AddMenuItem(MENU_Handle hMenu, MENU_Handle hSubmenu, const char* pText, U16 Id, U16 Flags) {
      23. MENU_ITEM_DATA Item;
      24. Item.pText = pText;
      25. Item.hSubmenu = hSubmenu;
      26. Item.Flags = Flags;
      27. Item.Id = Id;
      28. MENU_AddItem(hMenu, &Item);
      29. }
      30. static void _cbFW_Dlg(WM_MESSAGE * pMsg) {
      31. switch (pMsg->MsgId) {
      32. case WM_INIT_DIALOG:
      33. hEdit = WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0);
      34. break;
      35. default:
      36. WM_DefaultProc(pMsg);
      37. break;
      38. }
      39. }
      40. static void _cbFW_Kbrd(WM_MESSAGE * pMsg) {
      41. switch (pMsg->MsgId) {
      42. case WM_NOTIFY_PARENT:
      43. if ((WM_GetId(pMsg->hWinSrc) == GUI_ID_BUTTON0) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED))
      44. EDIT_AddKey(hEdit, '1');
      45. if ((WM_GetId(pMsg->hWinSrc) == GUI_ID_BUTTON1) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED))
      46. EDIT_AddKey(hEdit, '2');
      47. if ((WM_GetId(pMsg->hWinSrc) == GUI_ID_BUTTON2) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED))
      48. EDIT_AddKey(hEdit, '3');
      49. break;
      50. case WM_DELETE:
      51. WM_MakeModal(hFW_Dlg);
      52. break;
      53. default:
      54. WM_DefaultProc(pMsg);
      55. break;
      56. }
      57. }
      58. static void _cbBk(WM_MESSAGE * pMsg) {
      59. MENU_MSG_DATA * pData;
      60. switch (pMsg->MsgId) {
      61. case WM_PAINT:
      62. GUI_SetBkColor(GUI_GRAY);
      63. GUI_Clear();
      64. break;
      65. case WM_MENU:
      66. pData = (MENU_MSG_DATA *)pMsg->Data.p;
      67. switch (pData->MsgType) {
      68. case MENU_ON_ITEMPRESSED:
      69. if (pData->ItemId == ID_MENU_SUB_I2)
      70. {
      71. hFW_Dlg = GUI_CreateDialogBox(_aFW_DlgCreate, GUI_COUNTOF(_aFW_DlgCreate), _cbFW_Dlg, WM_HBKWIN, 0, 0);
      72. FRAMEWIN_AddCloseButton(hFW_Dlg, FRAMEWIN_BUTTON_RIGHT, 1);
      73. hFW_Kbrd = GUI_CreateDialogBox(_aFW_KbrdCreate, GUI_COUNTOF(_aFW_KbrdCreate), _cbFW_Kbrd, WM_HBKWIN, 0, 0);
      74. FRAMEWIN_AddCloseButton(hFW_Kbrd, FRAMEWIN_BUTTON_RIGHT, 1);
      75. WM_MakeModal(hFW_Kbrd);
      76. WM_BringToBottom(hMenuSub);
      77. }
      78. break;
      79. default:
      80. WM_DefaultProc(pMsg);
      81. break;
      82. }
      83. break;
      84. default:
      85. WM_DefaultProc(pMsg);
      86. break;
      87. }
      88. }
      89. void MainTask(void) {
      90. GUI_Init();
      91. WM_SetCallback(WM_HBKWIN, _cbBk);
      92. hMenu = MENU_CreateEx(0, 0, 320, 0, WM_HBKWIN, 0, MENU_CF_HORIZONTAL, ID_MENU);
      93. hMenuSub = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, ID_MENU_SUB);
      94. _AddMenuItem(hMenuSub, 0, "Item 1", ID_MENU_SUB_I1, 0);
      95. _AddMenuItem(hMenuSub, 0, "Item 2 -> Open dialog", ID_MENU_SUB_I2, 0);
      96. _AddMenuItem(hMenuSub, 0, "Item 3", ID_MENU_SUB_I3, 0);
      97. _AddMenuItem(hMenu, hMenuSub, "Menu", 0, 0);
      98. while(1)
      99. {
      100. GUI_Delay(50);
      101. }
      102. }
      Display All
      If you want to prevent user input only to opened submenu you must also prevent it to the other widgets (e. g. horizontal menu). It seems in this case you must catch PID-messages in corresponding callbacks (at least WM_TOUCH and WM_MOUSEOVER to prevent changing appearance of the menu items).

      Alex.
    • I already solved this problem!!! 8o 8o 8o

      There is undocumented internal EmWin message 0x240 (576), that is used for MENU collapse - you should use "break" for this message inside your callback.

      8)
      Best regards,
      Volodymyr.

      The post was edited 1 time, last by volodymyr ().

    • Yes!

      Found it too :thumbup: !

      But what if they change that undocumented code (0x240) in next releases... :)

      Why the collapse / expand of MENU widgets is not provided as API functions...
    • LexaGb wrote:

      Yes!

      Found it too :thumbup: !

      But what if they change that undocumented code (0x240) in next releases... :)

      Why the collapse / expand of MENU widgets is not provided as API functions...
      "But what if they change that undocumented code (0x240) in next releases..."
      At this point it does not matter for me. But if SEGGER answer here it would be nice...

      "Why the collapse / expand of MENU widgets is not provided as API functions..."
      Who knows.. :/
      Best regards,
      Volodymyr.