SPINBOX - strange behaviour

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

    • SPINBOX - strange behaviour

      Hello.

      I would like to understand if there is the strange behaviour of SPINBOX or I do something wrong.

      In attachment - source code (on base of demo-code of SPINBOX-widget).

      I have added a BUTTON (id GUI_ID_BUTTON0) for disable/enable SPINBOX-widget (id GUI_ID_SPINBOX2) by its cklicking.
      But If you run this sample you will see, that the state disable/enable of this SPINBOX-widget is changed by cklicking on every widget, even from itself.

      The code of enable/disable by pressing BUTTON starts from line 39.
      And this code gets entry by pressing of ALL widgets, not only by BUTTON with id GUI_ID_BUTTON0.

      And why if I click right arrow of SPINBOX with id GUI_ID_SPINBOX2 it starts increasing continuously?

      C Source Code

      1. #include "GUI.h"
      2. #include "DIALOG.h"
      3. static const GUI_WIDGET_CREATE_INFO _aDialogSpinbox[] = {
      4. { FRAMEWIN_CreateIndirect, "Spinbox", 0, 0, 0, 320, 240, 0, 0, 0 },
      5. { SPINBOX_CreateIndirect, NULL, GUI_ID_SPINBOX0, 10, 15, 60, 21, 0, 0, 0 },
      6. { SPINBOX_CreateIndirect, NULL, GUI_ID_SPINBOX1, 10, 42, 60, 21, 0, 0, 0 },
      7. { SPINBOX_CreateIndirect, NULL, GUI_ID_SPINBOX2, 10, 75, 220, 80, 0, 0, 0 },
      8. { BUTTON_CreateIndirect, "Click", GUI_ID_BUTTON0, 10, 170, 80, 24, 0, 0, 0 },
      9. };
      10. static void _cb(WM_MESSAGE * pMsg) {
      11. EDIT_Handle hEdit;
      12. WM_HWIN hItem;
      13. int Value;
      14. int NCode;
      15. int Id;
      16. switch (pMsg->MsgId) {
      17. case WM_INIT_DIALOG:
      18. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SPINBOX0);
      19. hEdit = SPINBOX_GetEditHandle(hItem);
      20. EDIT_SetDecMode(hEdit, 1, 1, 10, 0, 0);
      21. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SPINBOX1);
      22. hEdit = SPINBOX_GetEditHandle(hItem);
      23. EDIT_SetDecMode(hEdit, 1, 0, 99999, 0, 0);
      24. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SPINBOX2);
      25. SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
      26. SPINBOX_SetEditMode(hItem, SPINBOX_EM_EDIT);
      27. SPINBOX_SetRange(hItem, 0, 99999);
      28. break;
      29. case WM_NOTIFY_PARENT:
      30. NCode = pMsg->Data.v;
      31. Id = WM_GetId(pMsg->hWinSrc);
      32. switch (NCode) {
      33. case WM_NOTIFICATION_CLICKED:
      34. if (Id = GUI_ID_BUTTON0) {
      35. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SPINBOX2);
      36. WM_SetEnableState(hItem, !WM_IsEnabled(hItem));
      37. }
      38. break;
      39. case WM_NOTIFICATION_VALUE_CHANGED:
      40. if (Id == GUI_ID_SPINBOX0) {
      41. Value = SPINBOX_GetValue(pMsg->hWinSrc);
      42. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SPINBOX1);
      43. SPINBOX_SetStep(hItem, Value);
      44. }
      45. break;
      46. default:
      47. WM_DefaultProc(pMsg);
      48. }
      49. break;
      50. default:
      51. WM_DefaultProc(pMsg);
      52. }
      53. }
      54. void MainTask(void) {
      55. GUI_Init();
      56. GUI_CreateDialogBox(_aDialogSpinbox, GUI_COUNTOF(_aDialogSpinbox), _cb, WM_HBKWIN, 30, 30);
      57. while (1) {
      58. GUI_Delay(100);
      59. }
      60. }
      Display All
      Best regards,
      Volodymyr.
    • Hi Volodymyr,

      the error lies in line 39. It should be "Id == GUI_ID_BUTTON0" instead of "Id = GUI_ID_BUTTON0". Now you just set the Id variable and the if-clause checks if Id is not zero, so you always land in that case. A tiny but weighty error, took me a while until I saw it, too...

      I'd advise you to call WM_InvalidateWindow(hItem); after you set the enable/disable state of the spinbox, so it gets completely redrawn.

      Best regards,

      Florian