traversing in emwin calendar

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

    • traversing in emwin calendar

      Hi,

      In my project i want to use emwin calendar dialog the way we use calendar in windows. initially i am able to produce the calendar based on RTC time. i can traverse through the months using scroll buttons provided in the calendar header but the problem is when i want to go to different year such as 2 to 3 years back or forth we have to scroll a lot. is there any way to use the calendar the way we use windows calendar like when we click on the month the dialog contracts to all the months and wen we click on year it shows all the year then we can select the desired month and date.

      thanks
      sanjeev
    • Hello,

      faced the same problem. But calendar in emWin doesn't have these options for fast navigation. If you want to implement a calendar like in Windows, then you need to do custom calendar using different emWin options (e. g. animation, memory devices).

      In my case I created an additional dialog window with some widgets: listwheel for changing months, spinbox for changing years, button for applying the changes and closing the dialog. This dialog appears on top of the calendar when clicking on the month/year area and changing selection in the days area. When clicking on the area outside the calendar it is cancelling without changes. Clicking on the month/year area calls CALENDAR_NOTIFICATION_MONTH_CLICKED message. Apparently this message implemented for various custom needs like this.

      C Source Code

      1. #include "DIALOG.h"
      2. #define ID_WINDOW_SELECTMY (GUI_ID_USER + 0x00)
      3. WM_HWIN hWinMain, hWinSelectMY, hClndr;
      4. LISTWHEEL_Handle hLw_Months;
      5. SPINBOX_Handle hSb_Years;
      6. BUTTON_Handle hB_Set, hL_b, hR_b;
      7. CALENDAR_DATE Date;
      8. WM_CALLBACK * _cbClndr_def;
      9. static const GUI_WIDGET_CREATE_INFO _aDialogSelectMY_Create[] = {
      10. { WINDOW_CreateIndirect, "WindowSelectMY", ID_WINDOW_SELECTMY, 0, 0, 126, 25, 0, 0x0, 0 },
      11. { LISTWHEEL_CreateIndirect, "Listwheel", GUI_ID_LISTWHEEL0, 2, 5, 50, 16, 0, 0x0, 0 },
      12. { SPINBOX_CreateIndirect, "Spinbox", GUI_ID_SPINBOX0, 55, 4, 50, 18, 0, 0x0, 0 },
      13. { BUTTON_CreateIndirect, "<", GUI_ID_BUTTON0, 107, 4, 18, 18, 0, 0x0, 0 },
      14. };
      15. static void _cbWinMain(WM_MESSAGE * pMsg) {
      16. WM_PID_STATE_CHANGED_INFO * pInfo;
      17. switch (pMsg->MsgId) {
      18. case WM_PAINT:
      19. GUI_SetBkColor(GUI_GRAY);
      20. GUI_Clear();
      21. break;
      22. case WM_NOTIFY_PARENT:
      23. if ((pMsg->hWinSrc == hClndr) && ((pMsg->Data.v == CALENDAR_NOTIFICATION_MONTH_CLICKED) || (pMsg->Data.v == WM_NOTIFICATION_SEL_CHANGED)))
      24. WM_ShowWin(hWinSelectMY);
      25. break;
      26. case WM_PID_STATE_CHANGED:
      27. pInfo = (WM_PID_STATE_CHANGED_INFO *)pMsg->Data.p;
      28. if ((pInfo->State == 1) && (pInfo->StatePrev == 0))
      29. {
      30. CALENDAR_GetDate(hClndr, &Date);
      31. SPINBOX_SetValue(hSb_Years, Date.Year);
      32. LISTWHEEL_SetPos(hLw_Months, Date.Month - 1);
      33. CALENDAR_SetSel(hClndr, &Date);
      34. WM_HideWin(hWinSelectMY);
      35. }
      36. break;
      37. default:
      38. WM_DefaultProc(pMsg);
      39. break;
      40. }
      41. }
      42. static void _cbDialogSelectMY(WM_MESSAGE * pMsg) {
      43. switch (pMsg->MsgId) {
      44. case WM_INIT_DIALOG:
      45. hLw_Months = WM_GetDialogItem(pMsg->hWin, GUI_ID_LISTWHEEL0);
      46. LISTWHEEL_AddString(hLw_Months, "Jan");
      47. LISTWHEEL_AddString(hLw_Months, "Feb");
      48. LISTWHEEL_AddString(hLw_Months, "Mar");
      49. LISTWHEEL_AddString(hLw_Months, "Apr");
      50. LISTWHEEL_AddString(hLw_Months, "May");
      51. LISTWHEEL_AddString(hLw_Months, "Jun");
      52. LISTWHEEL_AddString(hLw_Months, "Jul");
      53. LISTWHEEL_AddString(hLw_Months, "Aug");
      54. LISTWHEEL_AddString(hLw_Months, "Sep");
      55. LISTWHEEL_AddString(hLw_Months, "Oct");
      56. LISTWHEEL_AddString(hLw_Months, "Nov");
      57. LISTWHEEL_AddString(hLw_Months, "Dec");
      58. LISTWHEEL_SetTextAlign(hLw_Months, GUI_TA_CENTER);
      59. LISTWHEEL_SetSel(hLw_Months, 5);
      60. LISTWHEEL_SetPos(hLw_Months, 5);
      61. hSb_Years = WM_GetDialogItem(pMsg->hWin, GUI_ID_SPINBOX0);
      62. SPINBOX_SetRange(hSb_Years, 1970, 2099);
      63. SPINBOX_SetValue(hSb_Years, 2019);
      64. hB_Set = WM_GetDialogItem(pMsg->hWin, GUI_ID_BUTTON0);
      65. WINDOW_SetBkColor(pMsg->hWin, GUI_GREEN);
      66. WM_HideWin(pMsg->hWin);
      67. break;
      68. case WM_NOTIFY_PARENT:
      69. if ((pMsg->hWinSrc == hB_Set) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED))
      70. {
      71. LISTWHEEL_SetSel(hLw_Months, LISTWHEEL_GetPos(hLw_Months));
      72. CALENDAR_GetSel(hClndr, &Date);
      73. Date.Year = SPINBOX_GetValue(hSb_Years);
      74. Date.Month = LISTWHEEL_GetSel(hLw_Months) + 1;
      75. CALENDAR_SetDate(hClndr, &Date);
      76. CALENDAR_SetSel(hClndr, &Date);
      77. WM_HideWin(hWinSelectMY);
      78. }
      79. break;
      80. default:
      81. WM_DefaultProc(pMsg);
      82. break;
      83. }
      84. }
      85. static void _cbClndr(WM_MESSAGE * pMsg) {
      86. int Pos;
      87. switch (pMsg->MsgId) {
      88. case WM_NOTIFY_PARENT:
      89. if (pMsg->Data.v == WM_NOTIFICATION_RELEASED)
      90. {
      91. if (pMsg->hWinSrc == hL_b)
      92. {
      93. Pos = LISTWHEEL_GetPos(hLw_Months);
      94. if (Pos == 0)
      95. Pos = 12;
      96. LISTWHEEL_SetPos(hLw_Months, Pos - 1);
      97. LISTWHEEL_SetSel(hLw_Months, Pos - 1);
      98. }
      99. else
      100. if (pMsg->hWinSrc == hR_b)
      101. {
      102. Pos = LISTWHEEL_GetPos(hLw_Months);
      103. if (Pos == 11)
      104. Pos = -1;
      105. LISTWHEEL_SetPos(hLw_Months, Pos + 1);
      106. LISTWHEEL_SetSel(hLw_Months, Pos + 1);
      107. }
      108. }
      109. _cbClndr_def(pMsg);
      110. break;
      111. default:
      112. _cbClndr_def(pMsg);
      113. break;
      114. }
      115. }
      116. void MainTask(void) {
      117. GUI_Init();
      118. WM_MULTIBUF_Enable(1);
      119. hWinMain = WM_CreateWindow(0, 0, 320, 240, WM_CF_SHOW, _cbWinMain, 0);
      120. hClndr = CALENDAR_Create(hWinMain, 97, 62, 2019, 6, 27, 2, GUI_ID_CALENDAR0, 0);
      121. hL_b = WM_GetFirstChild(hClndr);
      122. hR_b = WM_GetNextSibling(hL_b);
      123. _cbClndr_def = WM_GetCallback(hClndr);
      124. WM_SetCallback(hClndr, _cbClndr);
      125. hWinSelectMY = GUI_CreateDialogBox(_aDialogSelectMY_Create, GUI_COUNTOF(_aDialogSelectMY_Create), _cbDialogSelectMY, hClndr, 0, 0);
      126. while(1)
      127. {
      128. GUI_Delay(50);
      129. }
      130. }
      Display All
      The only thing it is not taking into account is year changing in spinbox when scrolling calendar with the buttons. You can do it if you need.

      Alex.

      The post was edited 14 times, last by LexaGb ().