/*********************************************************************
*
*       _cbDialog
*
* Function description
*   Callback routine of dialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
  static WM_HWIN   hCellEdit = 0;
  CELL_EDIT_ORG    CellEditOrg;
  WM_KEY_INFO    * pKeyInfo;
  GUI_RECT         ItemRect;
  WM_HWIN          hDlg;
  WM_HWIN          hItem;
  char             acItemText[LEN_ITEM_TEXT];
  int              CheckState;
  int              NCode;
  int              Id;
  int              i;

  hDlg = pMsg->hWin;
  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    //
    // Set listview properties
    //
    hItem = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
    WM_SetCallback(hItem, _cbList);
    HEADER_SetDragLimit(LISTVIEW_GetHeader(hItem), 1);
    LISTVIEW_SetAutoScrollV(hItem, 1);
    LISTVIEW_SetGridVis(hItem, 1);
    LISTVIEW_SetRBorder(hItem, 5);
    LISTVIEW_SetLBorder(hItem, 5);
    for (i = 0; i < 3; i++) {
      LISTVIEW_AddColumn(hItem, _aColProps[i].Width, _aColProps[i].pText, _aColProps[i].Align);
      LISTVIEW_SetCompareFunc(hItem, i, _aColProps[i].fpCompare);
    }
    LISTVIEW_EnableSort(hItem);
    for (i = 0; i < 6; i++) {
      if (_AddRow(hItem, 1)) {
        break;
      }
    }
    //
    // Set radio button text
    //
    hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
    RADIO_SetText(hItem, "Sorted",   0);
    RADIO_SetText(hItem, "Unsorted", 1);
    //
    // Init checkbox text
    //
    hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0);
    CHECKBOX_SetTextAlign(hItem, GUI_TA_LEFT);
    CHECKBOX_SetText(hItem, "Cell select");
    break;
  case WM_KEY:
    hItem = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
    if (pMsg->hWinSrc == hItem) {
      pKeyInfo = (WM_KEY_INFO *)pMsg->Data.p;
      if (pKeyInfo->PressedCnt == 0) {
        if (pKeyInfo->Key == GUI_KEY_ENTER) {
          if (hCellEdit == 0) {
            CellEditOrg.Row = LISTVIEW_GetSel(hItem);
            CellEditOrg.Col = LISTVIEW_GetSelCol(hItem);
            LISTVIEW_GetItemRect(hItem, CellEditOrg.Col, CellEditOrg.Row, &ItemRect);
            LISTVIEW_GetItemTextSorted(hItem, CellEditOrg.Col, CellEditOrg.Row, acItemText, LEN_ITEM_TEXT);
            hCellEdit = EDIT_CreateUser(ItemRect.x0, ItemRect.y0, ItemRect.x1 - ItemRect.x0 + 2, ItemRect.y1 - ItemRect.y0 + 1, hItem, WM_CF_SHOW, 0, 0, LEN_ITEM_TEXT, sizeof(CELL_EDIT_ORG));
            EDIT_SetUserData(hCellEdit, &CellEditOrg, sizeof(CELL_EDIT_ORG));
            WIDGET_SetEffect(hCellEdit, &WIDGET_Effect_Simple);
            WM_SetCallback(hCellEdit, _cbCellEdit);
            WM_SetFocus(hCellEdit);
            EDIT_SetText(hCellEdit, acItemText);
          }
        }
      }
    }
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch (NCode) {
    case WM_NOTIFICATION_CHILD_DELETED:
      if (pMsg->hWinSrc == hCellEdit) {
        hCellEdit = 0;
      }
      break;
    case WM_NOTIFICATION_VALUE_CHANGED:
      switch (Id) {
      case GUI_ID_RADIO0:
        //
        // Enable/Disable sorting
        //
        hItem = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
        switch (RADIO_GetValue(WM_GetDialogItem(hDlg, GUI_ID_RADIO0))) {
        case 0:
          LISTVIEW_EnableSort(hItem);
          break;
        default:
          LISTVIEW_DisableSort(hItem);
          break;
        }
        break;
      }
      break;
    case WM_NOTIFICATION_RELEASED:
      switch (Id) {
      case GUI_ID_BUTTON0:
        //
        // Add new row
        //
        hItem = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
        _AddRow(hItem, 0);
        break;
      case GUI_ID_BUTTON1:
        //
        // Insert new row
        //
        hItem = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
        i     = LISTVIEW_GetSelUnsorted(hItem);
        _AddRow(hItem, 1);
        if (i >= 0) {
          LISTVIEW_SetSelUnsorted(hItem, i + 1);
        }
        break;
      case GUI_ID_BUTTON2:
        //
        // Delete row
        //
        hItem = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
        i     = LISTVIEW_GetSelUnsorted(hItem);
        LISTVIEW_DeleteRow(hItem, (i >= 0) ? i : 0);
        break;
      case GUI_ID_OK:
        //
        // End dialog
        //
        GUI_EndDialog(hDlg, 0);
        break;
      case GUI_ID_CHECK0:
        //
        // Enable/Disable cell selection
        //
        hItem      = WM_GetDialogItem(hDlg, GUI_ID_CHECK0);
        CheckState = CHECKBOX_GetState(hItem);
        hItem      = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
        if (CheckState) {
          LISTVIEW_EnableCellSelect(hItem, 1);
        } else {
          LISTVIEW_EnableCellSelect(hItem, 0);
        }
        break;
      }
      break;
    }
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}
예제 #2
0
/*********************************************************************
*
*       _Action
*
* Purpose:
*   Does some action with the widget
*/
static void _Action(WM_HWIN hList) {
  unsigned ColoredCol   = 0;
  unsigned ColoredRow   = 0;
  unsigned NumRows;
  unsigned Index;
  unsigned i;
  int      SortedColumn = -1;
  int      ColorIndex   = 0;
  int      Reverse      = 0;

  Index = 0;
  do {
    if (_aAction[Index].pDescription) {
      GUIDEMO_ShowInfo(_aAction[Index].pDescription);
    }
    switch (_aAction[Index].Job) {
    case JOB_COLOR:
      NumRows = LISTVIEW_GetNumRows(hList);
      for (i = 0; i < NumRows; i++) {
        LISTVIEW_SetItemBkColor(hList, ColoredCol, ColoredRow, LISTVIEW_CI_UNSEL, _aColor[ColorIndex]);
        if (++ColorIndex == GUI_COUNTOF(_aColor)) {
          ColorIndex = 0;
        }
        if (++ColoredCol == LISTVIEW_GetNumColumns(hList)) {
          ColoredCol = 0;
        }
        if (++ColoredRow == NumRows) {
          ColoredRow = 0;
        }
      }
      break;
    case JOB_INCSEL:
      LISTVIEW_IncSel(hList);
      break;
    case JOB_DECSEL:
      LISTVIEW_DecSel(hList);
      break;
    case JOB_REVERSE:
      Reverse ^= 1;
      LISTVIEW_SetSort(hList, SortedColumn, Reverse);
      break;
    case JOB_ADDROWS:
      for (i = 0; i < 40; i++) {
        _AddRow(hList, 0);
      }
      break;
    case JOB_SETSORT:
      if (SortedColumn == -1) {
        SortedColumn = 0;
      } else {
        SortedColumn++;
        if (SortedColumn == (int)LISTVIEW_GetNumColumns(hList)) {
          SortedColumn = 0;
        }
      }
      LISTVIEW_SetSort(hList, SortedColumn, Reverse);
      break;
    }
    GUI_Delay(_aAction[Index].Delay);
  } while ((++Index < GUI_COUNTOF(_aAction)) && (GUIDEMO_CheckCancel() == 0));
}