Example #1
0
int iupMatrixEditShowXY(Ihandle* ih, int x, int y)
{
    char* mask;

    /* work around for Windows when using Multiline */
    if (iupAttribGet(ih, "_IUPMAT_IGNORE_SHOW"))
    {
        iupAttribSet(ih, "_IUPMAT_IGNORE_SHOW", NULL);
        return 0;
    }

    /* there are no cells that can be edited */
    if (ih->data->columns.num <= 1 || ih->data->lines.num <= 1)
        return 0;

    if (ih->data->editing || iupMatrixEditIsVisible(ih))
    {
        if (ih->data->edit_hide_onfocus)
            return 0;

        iupMatrixEditHide(ih);
    }

    ih->data->edit_lin = ih->data->lines.focus_cell;
    ih->data->edit_col = ih->data->columns.focus_cell;

    /* notify application */
    if (iMatrixEditCallEditionCbUpdateValue(ih, 1, 0) == IUP_IGNORE)  /* only place where mode=1 */
        return 0;

    if (iMatrixEditCallMenuDropCb(ih, ih->data->edit_lin, ih->data->edit_col))
        return 0;

    ih->data->editing = 1;

    /* select edit control */
    iMatrixEditChooseElement(ih);

    /* position the cell to make it visible */
    /* If the focus is not visible, a scroll is done for that the focus to be visible */
    if (!iupMatrixAuxIsCellStartVisible(ih, ih->data->edit_lin, ih->data->edit_col))
        iupMatrixScrollToVisible(ih, ih->data->edit_lin, ih->data->edit_col);

    /* set attributes */
    iupMatrixPrepareDrawData(ih);
    IupStoreAttribute(ih->data->datah, "BGCOLOR", iupMatrixGetBgColorStr(ih, ih->data->edit_lin, ih->data->edit_col));
    IupStoreAttribute(ih->data->datah, "FGCOLOR", iupMatrixGetFgColorStr(ih, ih->data->edit_lin, ih->data->edit_col));
    IupSetAttribute(ih->data->datah, "FONT", iupMatrixGetFont(ih, ih->data->edit_lin, ih->data->edit_col));

    mask = IupGetAttributeId2(ih, "MASK", ih->data->edit_lin, ih->data->edit_col);
    if (mask)
    {
        IupSetAttribute(ih->data->datah, "MASKCASEI", IupGetAttributeId2(ih, "MASKCASEI", ih->data->edit_lin, ih->data->edit_col));
        IupSetAttribute(ih->data->datah, "MASKNOEMPTY", IupGetAttributeId2(ih, "MASKNOEMPTY", ih->data->edit_lin, ih->data->edit_col));
        IupSetAttribute(ih->data->datah, "MASK", mask);
    }
    else
    {
        mask = IupGetAttributeId2(ih, "MASKINT", ih->data->edit_lin, ih->data->edit_col);
        if (mask)
            IupSetAttribute(ih->data->datah, "MASKINT", mask);
        else
        {
            mask = IupGetAttributeId2(ih, "MASKFLOAT", ih->data->edit_lin, ih->data->edit_col);
            if (mask)
                IupSetAttribute(ih->data->datah, "MASKFLOAT", mask);
            else
                IupSetAttribute(ih->data->datah, "MASK", NULL);
        }
    }

    iupMatrixEditUpdatePos(ih);

    /* activate and show */
    IupSetAttribute(ih->data->datah, "ACTIVE",  "YES");
    IupSetAttribute(ih->data->datah, "VISIBLE", "YES");
    IupSetFocus(ih->data->datah);

    if (ih->data->datah == ih->data->texth)
    {
        if (iupAttribGetBoolean(ih, "EDITALIGN"))
            IupSetStrAttribute(ih->data->datah, "ALIGNMENT", IupGetAttributeId(ih, "ALIGNMENT", ih->data->edit_col));

        if (x || y)
        {
            int pos;

            x -= ih->data->datah->x;
            y -= ih->data->datah->y;

            pos = IupConvertXYToPos(ih->data->datah, x, y);
            IupSetInt(ih->data->datah, "CARETPOS", pos);
        }
    }

    return 1;
}
Example #2
0
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, int col_alignment, int lin_alignment, int marked, int active, int lin, int col, const char* text)
{
  int text_alignment;
  int charheight, x, y, hidden_text_marks = 0;

  iupdrvFontGetCharSize(ih, NULL, &charheight);

  if (lin==0 || ih->data->hidden_text_marks)
  {
    int text_w;
    iupdrvFontGetMultiLineStringSize(ih, text, &text_w, NULL);
    if (text_w > x2 - x1 + 1 - IMAT_PADDING_W - IMAT_FRAME_W)
    {
      if (lin == 0)
        col_alignment = IMAT_ALIGN_START;

      if (ih->data->hidden_text_marks)
        hidden_text_marks = 1;
    }
  }

  /* Set the color used to draw the text */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);

  /* Set the clip area to the cell region informed, the text maybe greater than the cell */
  if (hidden_text_marks)
  {
    int crop = iupdrvFontGetStringWidth(ih, "...") + 2;
    iMatrixDrawSetCellClipping(ih, x1, x2-crop, y1, y2);
  }
  else
    iMatrixDrawSetCellClipping(ih, x1, x2, y1, y2);

  IupCdSetFont(ih, ih->data->cd_canvas, iupMatrixGetFont(ih, lin, col));

  /* Create an space between text and cell frame */
  x1 += IMAT_PADDING_W/2;       x2 -= IMAT_PADDING_W/2;
  y1 += IMAT_PADDING_H/2;       y2 -= IMAT_PADDING_H/2;

  iMatrixGetCellAlign(ih, lin, col, &col_alignment, &lin_alignment);

  if (lin_alignment == IMAT_ALIGN_CENTER)
  {
    y = iupROUND((y1 + y2) / 2.0);

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_CENTER;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_EAST;
    }
  }
  else if (lin_alignment == IMAT_ALIGN_START)
  {
    y = y1;

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_NORTH;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_NORTH_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_NORTH_EAST;
    }
  }
  else /* lin_alignment == IMAT_ALIGN_END */
  {
    y = y2;

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_SOUTH;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_SOUTH_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_SOUTH_EAST;
    }
  }

  cdCanvasTextAlignment(ih->data->cd_canvas, text_alignment);
  iupMATRIX_TEXT(ih, x, y, text);

  iMatrixDrawResetCellClipping(ih);

  if (hidden_text_marks)
  {
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);
    y = (int)((y1 + y2) / 2.0 - 0.5);
    x = x2 + IMAT_PADDING_W / 2;
    iupMATRIX_TEXT(ih, x, y, "...");
  }
}
Example #3
0
int iupMatrixEditShow(Ihandle* ih)
{
  char* mask;
  int w, h, x, y;

  /* work around for Windows when using Multiline */
  if (iupAttribGet(ih, "_IUPMAT_IGNORE_SHOW"))
  {
    iupAttribSetStr(ih, "_IUPMAT_IGNORE_SHOW", NULL);
    return 0;
  }

  /* there are no cells that can be edited */
  if (ih->data->columns.num <= 1 || ih->data->lines.num <= 1)
    return 0;

  /* not active */
  if(!IupGetInt(ih, "ACTIVE"))
    return 0;

  /* already visible */
  if(IupGetInt(ih->data->datah, "VISIBLE"))
    return 0;

  /* notify application */
  if (iMatrixEditCallEditionCb(ih, 1, 0) == IUP_IGNORE)
    return 0;

  if (iMatrixEditCallMenuDropCb(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell))
    return 0;

  /* select edit control */
  iMatrixEditChooseElement(ih);

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

  /* set attributes */
  iupMatrixPrepareDrawData(ih);
  IupStoreAttribute(ih->data->datah, "BGCOLOR", iupMatrixGetBgColor(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell));
  IupStoreAttribute(ih->data->datah, "FGCOLOR", iupMatrixGetFgColor(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell));
  IupSetAttribute(ih->data->datah, "FONT", iupMatrixGetFont(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell));

  mask = IupMatGetAttribute(ih,"MASK", ih->data->lines.focus_cell, ih->data->columns.focus_cell);
  if (mask)
  {
    IupSetAttribute(ih->data->datah, "MASKCASEI", IupMatGetAttribute(ih,"MASKCASEI", ih->data->lines.focus_cell, ih->data->columns.focus_cell));
    IupSetAttribute(ih->data->datah, "MASK", mask);
  }
  else
  {
    mask = IupMatGetAttribute(ih,"MASKINT", ih->data->lines.focus_cell, ih->data->columns.focus_cell);
    if (mask)
      IupSetAttribute(ih->data->datah, "MASKINT", mask);
    else
    {
      mask = IupMatGetAttribute(ih,"MASKFLOAT", ih->data->lines.focus_cell, ih->data->columns.focus_cell);
      if (mask)
        IupSetAttribute(ih->data->datah, "MASKFLOAT", mask);
      else
        IupSetAttribute(ih->data->datah, "MASK", NULL);
    }
  }

  /* calc size */
  iupMatrixGetVisibleCellDim(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell, &x, &y, &w, &h);

  ih->data->datah->x = x;
  ih->data->datah->y = y;

  ih->data->datah->currentwidth  = w;
  ih->data->datah->currentheight = h;
  iupClassObjectLayoutUpdate(ih->data->datah);

  /* activate and show */
  IupSetAttribute(ih->data->datah, "ACTIVE",  "YES");
  IupSetAttribute(ih->data->datah, "VISIBLE", "YES");
  IupSetFocus(ih->data->datah);

  return 1;
}