Example #1
0
static int iMatrixEditDropDownKeyAny_CB(Ihandle* ih_list, int c)
{
    Ihandle* ih = ih_list->parent;
    IFniiiis cb = (IFniiiis)IupGetCallback(ih, "ACTION_CB");
    if (cb)
    {
        int oldc = c;
        c = cb(ih, c, ih->data->edit_lin, ih->data->edit_col, 1, "");
        if (c == IUP_IGNORE || c == IUP_CLOSE  || c == IUP_CONTINUE)
            return c;
        else if(c == IUP_DEFAULT)
            c = oldc;
    }

    switch (c)
    {
    case K_CR:
        if (iupMatrixEditConfirm(ih) == IUP_DEFAULT)
        {
            if (iupMatrixAuxCallLeaveCellCb(ih) != IUP_IGNORE)
            {
                iupMATRIX_ScrollKeyCr(ih);
                iupMatrixAuxCallEnterCellCb(ih);
            }
            iupMatrixDrawUpdate(ih);
            return IUP_IGNORE;
        }
        break;
    case K_ESC:
        iupMatrixEditAbort(ih);
        return IUP_IGNORE;
    }

    return IUP_CONTINUE;
}
Example #2
0
static int iMatrixEditDropDownKeyAny_CB(Ihandle* ih, int c)
{
  Ihandle* ih_matrix = ih->parent;
  IFniiiis cb = (IFniiiis)IupGetCallback(ih_matrix, "ACTION_CB");
  if (cb)
  {
    int oldc = c;
    c = cb(ih_matrix, c, ih_matrix->data->lines.focus_cell, ih_matrix->data->columns.focus_cell, 1, "");
    if (c == IUP_IGNORE || c == IUP_CLOSE  || c == IUP_CONTINUE)
      return c;
    else if(c == IUP_DEFAULT)
      c = oldc;
  }

  switch (c)
  {
    case K_CR:
      if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
      {
        if (iupMatrixAuxCallLeaveCellCb(ih_matrix) != IUP_IGNORE)
        {
          iupMATRIX_ScrollKeyCr(ih_matrix);
          iupMatrixAuxCallEnterCellCb(ih_matrix);
        }
        iupMatrixDrawUpdate(ih_matrix);
        return IUP_IGNORE;
      }
      break;
    case K_ESC:
      iMatrixEditCancel(ih_matrix, 1, 0, 0); /* set focus + NO update + NO ignore */
      return IUP_IGNORE;
  }

  return IUP_CONTINUE;
}
Example #3
0
static int iMatrixFocus_CB(Ihandle* ih, int focus)
{
  int rc = IUP_DEFAULT;

  if (!iupMatrixIsValid(ih, 1))
    return IUP_DEFAULT;

  if (IupGetGlobal("MOTIFVERSION"))
  {
    if (iupAttribGet(ih, "_IUPMAT_DROPDOWN") ||  /* from iMatrixEditDropDown_CB, in Motif */
        iupAttribGet(ih, "_IUPMAT_DOUBLECLICK"))  /* from iMatrixMouseLeftPress, in Motif */
      return IUP_DEFAULT;
  }

  ih->data->has_focus = focus;
  iupMatrixDrawUpdate(ih);

  if (focus)
    iupMatrixAuxCallEnterCellCb(ih);
  else
    iupMatrixAuxCallLeaveCellCb(ih);

  return rc;
}
Example #4
0
static int iMatrixEditTextKeyAny_CB(Ihandle* ih_text, int c)
{
    Ihandle* ih = ih_text->parent;
    IFniiiis cb = (IFniiiis) IupGetCallback(ih, "ACTION_CB");
    if (cb && !iup_isprint(c)) /* only for keys that are NOT ASCii characters */
    {
        int oldc = c;
        c = cb(ih, c, ih->data->edit_lin, ih->data->edit_col, 1, IupGetAttribute(ih_text, "VALUE"));
        if(c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE)
            return c;
        else if(c == IUP_DEFAULT)
            c = oldc;
    }

    switch (c)
    {
    case K_cUP:
    case K_cDOWN:
    case K_cLEFT:
    case K_cRIGHT:
        if (iupMatrixEditConfirm(ih) == IUP_DEFAULT)
        {
            iupMatrixProcessKeyPress(ih, c);
            return IUP_IGNORE;
        }
        break;
    case K_UP:
        if (!IupGetInt(ih_text, "MULTILINE") || IupGetInt(ih_text, "CARET") == 1)  /* if Multiline CARET will be "L,C" */
        {
            /* if at the first line of the text */
            if (iupMatrixEditConfirm(ih) == IUP_DEFAULT)
            {
                iupMatrixProcessKeyPress(ih, c);
                return IUP_IGNORE;
            }
        }
        break;
    case K_DOWN:
    {
        /* if at the last line of the text */
        if (!IupGetInt(ih_text, "MULTILINE") || IupGetInt(ih_text, "LINECOUNT") == IupGetInt(ih_text, "CARET"))  /* if Multiline CARET will be "L,C" */
        {
            if (iupMatrixEditConfirm(ih) == IUP_DEFAULT)
            {
                iupMatrixProcessKeyPress(ih, c);
                return IUP_IGNORE;
            }
        }
    }
    break;
    case K_LEFT:
        if (IupGetInt(ih_text, "CARETPOS") == 0)
        {
            /* if at the first character */
            if (iupMatrixEditConfirm(ih) == IUP_DEFAULT)
            {
                iupMatrixProcessKeyPress(ih, c);
                return IUP_IGNORE;
            }
        }
        break;
    case K_RIGHT:
    {
        /* if at the last character */
        if (IupGetInt(ih_text, "COUNT") == IupGetInt(ih_text, "CARETPOS"))
        {
            if (iupMatrixEditConfirm(ih) == IUP_DEFAULT)
            {
                iupMatrixProcessKeyPress(ih, c);
                return IUP_IGNORE;
            }
        }
    }
    break;
    case K_ESC:
        iupMatrixEditAbort(ih);
        return IUP_IGNORE;  /* always ignore to avoid the defaultesc behavior from here */
    case K_CR:
        if (iupMatrixEditConfirm(ih) == IUP_DEFAULT)
        {
            if (iupStrEqualNoCase(IupGetGlobal("DRIVER"), "Win32") && IupGetInt(ih_text, "MULTILINE"))
            {
                /* work around for Windows when using Multiline */
                iupAttribSet(ih, "_IUPMAT_IGNORE_SHOW", "1");
            }

            if (iupMatrixAuxCallLeaveCellCb(ih) != IUP_IGNORE)
            {
                iupMATRIX_ScrollKeyCr(ih);
                iupMatrixAuxCallEnterCellCb(ih);
            }
            iupMatrixDrawUpdate(ih);
        }
        return IUP_IGNORE;  /* always ignore to avoid the defaultenter behavior from here */
    }

    return IUP_CONTINUE;
}
Example #5
0
static int iMatrixEditTextKeyAny_CB(Ihandle* ih, int c)
{
  Ihandle* ih_matrix = ih->parent;
  IFniiiis cb = (IFniiiis) IupGetCallback(ih_matrix, "ACTION_CB");
  if (cb && !iup_isprint(c)) /* only for other keys that are not characters */
  {
    int oldc = c;
    c = cb(ih_matrix, c, ih_matrix->data->lines.focus_cell, ih_matrix->data->columns.focus_cell, 1, IupGetAttribute(ih, "VALUE"));
    if(c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE)
      return c;
    else if(c == IUP_DEFAULT)
      c = oldc;
  }

  switch (c)
  {
    case K_cUP:
    case K_cDOWN:
    case K_cLEFT:
    case K_cRIGHT:     
      if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
      {
        iupMatrixProcessKeyPress(ih_matrix, c);  
        return IUP_IGNORE;
      }
      break;
    case K_UP:
      if (IupGetInt(ih, "CARET") == 1)
      {
        /* if at the first line of the text */
        if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
        {
          iupMatrixProcessKeyPress(ih_matrix, c);  
          return IUP_IGNORE;
        }
      }
      break;
    case K_DOWN:
      { 
        char* value = IupGetAttribute(ih, "VALUE");
        if (value)
        {
          /* if at the last line of the text */
          if (iupStrLineCount(value) == IupGetInt(ih, "CARET"))
          {
            if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
            {
              iupMatrixProcessKeyPress(ih_matrix, c);  
              return IUP_IGNORE;
            }
          }
        }
      }
      break;
    case K_LEFT:
      if (IupGetInt(ih, "CARETPOS") == 0)
      {
        /* if at the first character */
        if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
        {
          iupMatrixProcessKeyPress(ih_matrix, c);  
          return IUP_IGNORE;
        }
      }
      break;
    case K_RIGHT:
      { 
        char* value = IupGetAttribute(ih, "VALUE");
        if (value)
        {
          /* if at the last character */
          if ((int)strlen(value) == IupGetInt(ih, "CARETPOS"))
          {
            if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
            {
              iupMatrixProcessKeyPress(ih_matrix, c);  
              return IUP_IGNORE;
            }
          }
        }
      }
      break;
    case K_ESC:
      iMatrixEditCancel(ih_matrix, 1, 0, 0); /* set focus + NO update + NO ignore */
      return IUP_IGNORE;  /* always ignore to avoid the defaultesc behavior from here */
    case K_CR:
      if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
      {
        if (iupStrEqualNoCase(IupGetGlobal("DRIVER"), "Win32") && IupGetInt(ih, "MULTILINE"))
        {
          /* work around for Windows when using Multiline */
          iupAttribSetStr(ih_matrix, "_IUPMAT_IGNORE_SHOW", "1");
        }

        if (iupMatrixAuxCallLeaveCellCb(ih_matrix) != IUP_IGNORE)
        {
          iupMATRIX_ScrollKeyCr(ih_matrix);
          iupMatrixAuxCallEnterCellCb(ih_matrix);
        }
        iupMatrixDrawUpdate(ih_matrix);
      }
      return IUP_IGNORE;  /* always ignore to avoid the defaultenter behavior from here */
  }

  return IUP_CONTINUE;
}
Example #6
0
int iupMatrixProcessKeyPress(Ihandle* ih, int c)
{
  /* This function is also called from inside the keyboard callbacks 
     of the Text and Dropdown list when in edition mode */

  int ret = IUP_IGNORE; /* default for processed keys */

  /* Hide (off) the marked cells if the key is not tab/del */
  if (c != K_TAB && c != K_sTAB && c != K_DEL && c != K_sDEL)
    iupMatrixMarkClearAll(ih, 1);

  /* If the focus is not visible, a scroll is done for that the focus to be visible */
  if (!iupMatrixAuxIsCellFullVisible(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell))
    iupMatrixScrollToVisible(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell);

  switch (c)
  {
    case K_CR+2000:   /* used by the iMatrixEditTextKeyAny_CB and iMatrixEditDropDownKeyAny_CB */
      if (iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyCr(ih);
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_cHOME:
    case K_sHOME:
    case K_HOME:
      if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyHome(ih);
      ih->data->homekeycount++;
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_cEND:
    case K_sEND:
    case K_END:
      if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyEnd(ih);
      ih->data->endkeycount++;
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_sTAB:
    case K_TAB:
      return IUP_CONTINUE;  /* do not redraw */

    case K_cLEFT:
    case K_sLEFT:
    case K_LEFT:
      if (iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyLeft(ih);
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_cRIGHT:
    case K_sRIGHT:
    case K_RIGHT:
      if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyRight(ih);
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_cUP:
    case K_sUP:
    case K_UP:
      if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyUp(ih);
      iupMatrixAuxCallEnterCellCb(ih);
      break ;

    case K_cDOWN:
    case K_sDOWN:
    case K_DOWN:
      if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyDown(ih);
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_sPGUP:
    case K_PGUP:
      if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyPgUp(ih);
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_sPGDN:
    case K_PGDN:
      if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE)
        break;
      iupMatrixScrollKeyPgDown(ih);
      iupMatrixAuxCallEnterCellCb(ih);
      break;

    case K_SP:
    case K_CR:
    case K_sCR:
      if (iupMatrixEditShow(ih))
        return IUP_IGNORE; /* do not redraw */
      break;

    case K_sDEL:
    case K_DEL:
      {
        int lin, col;
        char str[100];
        IFnii mark_cb = (IFnii)IupGetCallback(ih, "MARK_CB");

        iupMatrixPrepareDrawData(ih);

        for(lin = 1; lin < ih->data->lines.num; lin++)
        {
          for(col = 1; col < ih->data->columns.num; col++)
          {
            if (iupMatrixMarkCellGet(ih, lin, col, mark_cb, str))
            {
              if (iupMatrixAuxCallEditionCbLinCol(ih, lin, col, 1) != IUP_IGNORE)
              {
                IFniis value_edit_cb;

                iupMatrixCellSetValue(ih, lin, col, NULL);

                value_edit_cb = (IFniis)IupGetCallback(ih, "VALUE_EDIT_CB");
                if (value_edit_cb)
                  value_edit_cb(ih, lin, col, NULL);

                iupMatrixDrawCells(ih, lin, col, lin, col);
              }
            }
          }
        }
        break;
      }
    default:
      /* if a valid character is pressed enter edition mode */
      if (iup_isprint(c))
      {
        if (iupMatrixEditShow(ih))
        {
          if (ih->data->datah == ih->data->texth)
          {
            char value[2] = {0,0};
            value[0] = (char)c;
            IupStoreAttribute(ih->data->datah, "VALUE", value);
            IupSetAttribute(ih->data->datah, "CARET", "2");
          }
          return IUP_IGNORE; /* do not redraw */
        }
      }
      ret = IUP_DEFAULT; /* unprocessed keys */
      break;
  }

  iupMatrixDrawUpdate(ih);  
  return ret;
}