Exemple #1
0
/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
    WM_HWIN          hItem;
    int              NCode;
    int              Id;
    WM_HWIN         hNumPad;
    u8              Mb_Val;

    switch (pMsg->MsgId) {
    case WM_INIT_DIALOG:
        //
        //Initialization of Window
        //
        hItem = pMsg->hWin;
        WINDOW_SetBkColor(hItem, GUI_LIGHTBLUE);
        //
        // Initialization of 'Button'
        //
        GUI_UC_SetEncodeUTF8();
        GUI_SetFont(&GUI_FontSongTi16);
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_BACK);
        BUTTON_SetFont(hItem,&GUI_FontSongTi12);
        BUTTON_SetText(hItem, _StringHZ[2]);

        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_ENTER);
        BUTTON_SetFont(hItem,&GUI_FontSongTi12);
        BUTTON_SetText(hItem, _StringHZ[3]);

        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_NEW);
        BUTTON_SetFont(hItem,&GUI_FontSongTi16);
        BUTTON_SetText(hItem, _StringHZ[0]);

        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_OPEN);
        BUTTON_SetFont(hItem,&GUI_FontSongTi16);
        BUTTON_SetText(hItem, _StringHZ[1]);
        //
        // Initialization of 'Header'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_HEADER_1);
        HEADER_AddItem(hItem, 80, "LeCoder", 14);
        //
        //Initialize EDIT0
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_MULTIEDIT_0);
        MULTIEDIT_SetText(hItem, "");     //清空EDIT内容
        MULTIEDIT_SetFocussable(hItem,1); //设为捕捉光标焦点
        MULTIEDIT_SetAutoScrollV(hItem,1);//自动竖直滑块
        MULTIEDIT_SetAutoScrollH(hItem,1);//自动水平滑块
        MULTIEDIT_SetWrapWord(hItem);     //自动换行
        MULTIEDIT_SetFocussable(hItem, 1);
        WM_SetFocus(hItem);
        break;
    case WM_PAINT:
        GUI_SetColor(GUI_RED);
        GUI_SetFont(&GUI_FontSongTi12);
        GUI_DispStringAt(_StringHZ[4], 100, 25);
        break;
    case WM_NOTIFY_PARENT:
        Id    = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        switch(Id) {

        case ID_BUTTON_BACK: // Notifications sent by 'Button'
            switch(NCode) {
            case WM_NOTIFICATION_CLICKED:
                break;
            case WM_NOTIFICATION_RELEASED:
                Key_Value = WINDOW_TOP;
                break;
            }
            break;
        case ID_BUTTON_ENTER: // Notifications sent by 'ENTER'
        case ID_BUTTON_NEW: // Notifications sent by 'New'
            switch(NCode) {
            case WM_NOTIFICATION_CLICKED:
                break;
            case WM_NOTIFICATION_RELEASED:
                //get the program name in the edit
                hItem = WM_GetDialogItem(pMsg->hWin, ID_MULTIEDIT_0);
                MULTIEDIT_GetText(hItem,program_name,sizeof(program_name));
                //warning the situation of empty program name
                if(strcmp(program_name, "") == 0)
                {
                    _MessageBox(_StringHZ[4],_StringHZ[5], &Mb_Val);
                }
                else
                {
                    CreateWindow_1_1();
                }
                break;
            }
            break;
        case ID_BUTTON_OPEN: // Notifications sent by 'Open'
            switch(NCode) {
            case WM_NOTIFICATION_CLICKED:
                break;
            case WM_NOTIFICATION_RELEASED:
                CreateWindow_TreeView();
                break;
            }
            break;
        case ID_HEADER_1: // Notifications sent by 'Header'
            switch(NCode) {
            case WM_NOTIFICATION_CLICKED:
                break;
            case WM_NOTIFICATION_RELEASED:
                break;
            case WM_NOTIFICATION_MOVED_OUT:
                break;
            }
            break;
        case ID_MULTIEDIT_0: // Notifications sent by 'Edit1'
            switch(NCode) {
            case WM_NOTIFICATION_CLICKED:
                break;
            case WM_NOTIFICATION_RELEASED:
                hNumPad = Create_NumPad(pMsg->hWin);
                WM_MakeModal(hNumPad);
                GUI_ExecCreatedDialog(hNumPad);
                break;
            case WM_NOTIFICATION_VALUE_CHANGED:
                break;
            }
            break;
        }
        break;
    default:
        WM_DefaultProc(pMsg);
        break;
    }
}
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  WM_HWIN hScrollbar, hDlgOptions;
  GUI_RECT RectDlg, RectClient;
  int Cnt = 0, IndexEffect = 0, ButtonState = 0, DropdownState = 0;
  int ProgbarValue   = 0, ProgbarInc   = 1;
  int SliderValue    = 0, SliderInc    = 1;
  int ScrollbarValue = 0, ScrollbarInc = 1;
  int ListViewInc  = 1;
  int ListBoxInc   = 1;
  int MultiEditInc = 1;
  int Vz = 1;
  const WIDGET_EFFECT * _apEffect[] = {&WIDGET_Effect_3D,     /* Array of effects */
                                      &WIDGET_Effect_Simple, 
                                      &WIDGET_Effect_None};
  const char * _apEffects[] = {"Widget effect: 3D", "Widget effect: Simple", "Widget effect: None"};
  GUI_Init();
  GUI_CURSOR_Show();
  WM_SetCallback(WM_HBKWIN, _cbBkWindow);
  WM_SetCreateFlags(WM_CF_MEMDEV);  /* Use memory devices on all windows to avoid flicker */
  WM_EnableMemdev(WM_HBKWIN);       /* Enable use of memory devices for desktop windows */
  /* Create framewindow and set its properties */
  _hFrameWin = FRAMEWIN_CreateEx(0, 0, 640, 480, 0, WM_CF_SHOW, 0, 0, "", &_cbCallbackFramewin);
  FRAMEWIN_SetMoveable(_hFrameWin, 1);
  FRAMEWIN_SetText(_hFrameWin, _apEffects[0]);
  FRAMEWIN_SetFont(_hFrameWin, &GUI_Font13B_ASCII);
  /* Create main dialog window as child from framewindows client window */
  _hDlg = GUI_CreateDialogBox(_aDlgWidgets,
                              GUI_COUNTOF(_aDlgWidgets), 
                              &_cbCallbackWidgets, 
                              WM_GetClientWindow(_hFrameWin), 0, 0);
  /* Attach scrollbar to framewindows client window and set its properties */
  hScrollbar = SCROLLBAR_CreateAttached(WM_GetClientWindow(_hFrameWin), 0);
  WM_GetWindowRectEx(_hDlg, &RectDlg);
  WM_GetClientRectEx(WM_GetClientWindow(_hFrameWin), &RectClient);
  SCROLLBAR_SetNumItems(hScrollbar, RectDlg.x1);
  SCROLLBAR_SetPageSize(hScrollbar, RectClient.x1);
  /* Create options dialog with 'stay on top' and 'moveable' attribute */
  hDlgOptions = GUI_CreateDialogBox(_aDlgOptions, 
                                    GUI_COUNTOF(_aDlgOptions), 
                                    &_cbCallbackOptions, 
                                    WM_HBKWIN, 0, 0);
  FRAMEWIN_SetMoveable(hDlgOptions, 1);
  WM_SetStayOnTop(hDlgOptions, 1);
  /* Main loop for modifying the widgets */
  while (1) {
    if (_AutoMode) {
      Cnt++;
      /* Modify progbar */
      if ((Cnt % 2) == 0) {
        ProgbarValue += ProgbarInc;
        if ((ProgbarValue == 110) || (ProgbarValue == -10)) {
          ProgbarInc *= -1;
        }
        PROGBAR_SetValue(_ahWin[PROGBAR0], ProgbarValue);
      }
      /* Modify slider */
      if ((Cnt % 2) == 0) {
        int j;
        SliderValue += SliderInc;
        if ((SliderValue == 100) || (SliderValue == 0)) {
          SliderInc *= -1;
        }
        for (j = 0; j < 3; j++) {
          SLIDER_SetValue(_ahWin[SLIDER0 + j], SliderValue);
        }
      }
      /* Modify scrollbar */
      if ((Cnt % 3) == 0) {
        int j;
        ScrollbarValue += ScrollbarInc;
        if ((ScrollbarValue == 90) || (ScrollbarValue == 0)) {
          ScrollbarInc *= -1;
        }
        for (j = 0; j < 3; j++) {
          SCROLLBAR_SetValue(_ahWin[SCROLLBAR0 + j], ScrollbarValue);
        }
      }
      /* Modify multipage */
      if ((Cnt % 120) == 0) {
        MULTIPAGE_SelectPage(_ahWin[MULTIPAGE0], MULTIPAGE_GetSelection(_ahWin[MULTIPAGE0]) ^ 1);
      }
      /* Modify dropdown */
      if ((Cnt % 120) == 0) {
        DropdownState ^= 1;
        if (DropdownState) {
          DROPDOWN_Expand(_ahWin[DROPDOWN0]);
        } else {
          DROPDOWN_Collapse(_ahWin[DROPDOWN0]);
        }
      }
      /* Modify button */
      if ((Cnt % 40) == 0) {
        ButtonState ^= 1;
        BUTTON_SetPressed(_ahWin[BUTTON0], ButtonState);
      }
      /* Modify listbox */
      if ((Cnt % 30) == 0) {
        int Sel;
        Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]);
        if (Sel < 0) {
          Sel = 0;
        }
        LISTBOX_SetSel(_ahWin[LISTBOX0], Sel + ListBoxInc);
        Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]);
        if ((Sel == (int)LISTBOX_GetNumItems(_ahWin[LISTBOX0]) - 1) || (Sel == 0)) {
          ListBoxInc *= -1;
        }
      }
      /* Modify listview */
      if ((Cnt % 50) == 0) {
        int Sel;
        Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]);
        if (Sel < 0) {
          Sel = 0;
        }
        LISTVIEW_SetSel(_ahWin[LISTVIEW0], Sel + ListViewInc);
        Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]);
        if ((Sel == (int)LISTVIEW_GetNumRows(_ahWin[LISTVIEW0]) - 1) || (Sel == 0)) {
          ListViewInc *= -1;
        }
      }
      /* Modify multiedit */
      if ((Cnt % 5) == 0) {
        int Sel, Len;
        char acBuffer[100];
        MULTIEDIT_SetCursorOffset(_ahWin[MULTIEDIT0], MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]) + MultiEditInc);
        MULTIEDIT_GetText(_ahWin[MULTIEDIT0], acBuffer, sizeof(acBuffer));
        Sel = MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]);
        Len = strlen(acBuffer);
        if ((Sel == (Len - 1)) || (Sel == 0)) {
          MultiEditInc *= -1;
        }
        if (!DropdownState) {
          WM_SetFocus(_ahWin[MULTIEDIT0]);
        }
      }
      /* Modify graph */
      _AddValues(_ahWin[GRAPH0], 95);
      /* Move window */
      if ((Cnt % 1200) == 0) {
        int Inc;
        WM_HWIN hScroll;
        WM_SCROLL_STATE ScrollState;
        hScroll = WM_GetScrollbarH(WM_GetClientWindow(_hFrameWin));
        WM_GetScrollState(hScroll, &ScrollState);
        Inc = (ScrollState.NumItems - ScrollState.PageSize) / 2;
        ScrollState.v += Inc * Vz;
        if ((ScrollState.v >= Inc * 2) || (ScrollState.v <= 0)) {
          Vz *= -1;
        }
        SCROLLBAR_SetValue(hScroll, ScrollState.v);
      }
      /* Change effect */
      if ((Cnt % 400) == 0) {
        int Index;
        WM_HWIN hWin;
        IndexEffect++;
        Index = IndexEffect % GUI_COUNTOF(_apEffect);
        _SetEffect(Index);
        hWin = WM_GetDialogItem(hDlgOptions, GUI_ID_RADIO0);
        RADIO_SetValue(hWin, Index);
      }
    }
    /* Wait a while */
    GUI_Delay(10);
  }
}