Esempio n. 1
0
/* Redraw a block of cells of the matrix. Handle marked cells, change
   automatically the background color of them.
   - lin1, col1 : cell coordinates that mark the left top corner of the area to be redrawn
   - lin2, col2 : cell coordinates that mark the right bottom corner of the area to be redrawn */
void iupMatrixDrawCells(Ihandle* ih, int lin1, int col1, int lin2, int col2)
{
    int x1, y1, x2, y2, old_x2, old_y1, old_y2;
    int alignment, lin, col, active, first_col, first_lin;
    long framecolor, emptyarea_color = -1;
    char str[100];
    IFnii mark_cb;
    IFnii dropcheck_cb;
    IFniiiiiiC draw_cb;

    x2 = ih->data->w-1;
    y2 = ih->data->h-1;

    old_x2 = x2;
    old_y1 = 0;
    old_y2 = y2;

    if (ih->data->lines.num <= 1 ||
            ih->data->columns.num <= 1)
        return;

    if (ih->data->columns.num_noscroll>1 && col1==1 && col2==ih->data->columns.num_noscroll-1)
    {
        first_col = 0;
        x1 = 0;
    }
    else
    {
        if (col1 > ih->data->columns.last ||
                col2 < ih->data->columns.first)
            return;

        if (col1 < ih->data->columns.first)
            col1 = ih->data->columns.first;
        if (col2 > ih->data->columns.last)
            col2 = ih->data->columns.last;

        first_col = ih->data->columns.first;
        x1 = 0;
        for (col = 0; col< ih->data->columns.num_noscroll; col++)
            x1 += ih->data->columns.sizes[col];
    }

    if (ih->data->lines.num_noscroll>1 && lin1==1 && lin2==ih->data->lines.num_noscroll-1)
    {
        first_lin = 0;
        y1 = 0;
    }
    else
    {
        if (lin1 > ih->data->lines.last ||
                lin2 < ih->data->lines.first)
            return;

        if (lin1 < ih->data->lines.first)
            lin1 = ih->data->lines.first;
        if (lin2 > ih->data->lines.last)
            lin2 = ih->data->lines.last;

        first_lin = ih->data->lines.first;
        y1 = 0;
        for (lin = 0; lin< ih->data->lines.num_noscroll; lin++)
            y1 += ih->data->lines.sizes[lin];
    }

    iupMATRIX_CLIPAREA(ih, x1, x2, y1, y2);
    cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF);  /* wait for background */

    /* Find the initial position of the first column */
    if (first_col==ih->data->columns.first)
        x1 -= ih->data->columns.first_offset;
    for(col = first_col; col < col1; col++)
        x1 += ih->data->columns.sizes[col];

    /* Find the initial position of the first line */
    if (first_lin == ih->data->lines.first)
        y1 -= ih->data->lines.first_offset;
    for(lin = first_lin; lin < lin1; lin++)
        y1 += ih->data->lines.sizes[lin];

    /* Find the final position of the last column */
    x2 = x1;
    for( ; col <= col2; col++)
        x2 += ih->data->columns.sizes[col];

    /* Find the final position of the last line */
    y2 = y1;
    for( ; lin <= lin2; lin++)
        y2 += ih->data->lines.sizes[lin];

    if ((col2 == ih->data->columns.num-1) && (old_x2 > x2))
    {
        emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent);
        cdCanvasForeground(ih->data->cddbuffer, emptyarea_color);

        /* If it was drawn until the last column and remains space in the right of it,
           then delete this area with the the background color. */
        iupMATRIX_BOX(ih, x2, old_x2, old_y1, old_y2);
    }

    if ((lin2 == ih->data->lines.num-1) && (old_y2 > y2))
    {
        if (emptyarea_color == -1)
            emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent);
        cdCanvasForeground(ih->data->cddbuffer, emptyarea_color);

        /* If it was drawn until the last line visible and remains space below it,
           then delete this area with the the background color. */
        iupMATRIX_BOX(ih, 0, old_x2, y2, old_y2);
    }

    /* after the background */
    cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA);

    /***** Draw the cell values and frame */
    old_y1 = y1;
    framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR"));
    active = iupdrvIsActive(ih);

    mark_cb = (IFnii)IupGetCallback(ih, "MARK_CB");
    dropcheck_cb = (IFnii)IupGetCallback(ih, "DROPCHECK_CB");
    draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB");

    for(col = col1; col <= col2; col++)  /* For all the columns in the region */
    {
        if (ih->data->columns.sizes[col] == 0)
            continue;

        alignment = iMatrixDrawGetColAlignment(ih, col, str);

        x2 = x1 + ih->data->columns.sizes[col];

        for(lin = lin1; lin <= lin2; lin++)     /* For all lines in the region */
        {
            int drop = 0;
            int marked = 0;

            if (ih->data->lines.sizes[lin] == 0)
                continue;

            y2 = y1 + ih->data->lines.sizes[lin];

            /* If the cell is marked, then draw it with attenuation color */
            marked = iupMatrixMarkCellGet(ih, lin, col, mark_cb, str);

            iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, lin, col);

            iMatrixDrawFrameRectCell(ih, lin, col, x1, x2, y1, y2, framecolor, str);

            if (dropcheck_cb && dropcheck_cb(ih, lin, col) == IUP_DEFAULT)
            {
                drop = IMAT_COMBOBOX_W+IMAT_PADDING_W/2;
                iMatrixDrawComboFeedback(ih, x2, y1, y2, active, framecolor);
            }

            /* draw the cell contents */
            iMatrixDrawCellValue(ih, x1, x2-drop, y1, y2, alignment, marked, active, lin, col, draw_cb);

            y1 = y2;
        }

        x1 = x2;
        y1 = old_y1;  /* must reset also y */
    }

    cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF);
}
Esempio n. 2
0
/* Redraw a block of cells of the matrix. Handle marked cells, change
   automatically the background color of them.
   - l1, c1 : cell coordinates that mark the left top corner of the
              area to be redrawn
   - l2, c2 : cell coordinates that mark the right bottom corner of the
              area to be redrawn
*/
void iupMatrixDrawCells(Ihandle* ih, int l1, int c1, int l2, int c2)
{
  int x1, y1, x2, y2, oldx2, oldy1, oldy2;
  int yc1, yc2, xc1, xc2, i, j;
  int align;
  long framecolor;
  char str[30];
  unsigned char r,g,b;

  /* If there are no cells in the matrix, returns */
  if(ih->data->lin.num == 0 || ih->data->col.num == 0)
   return;

  /* Adjust parameters */
  if(c1 < ih->data->col.first)
    c1 = ih->data->col.first;
  if(c2 > ih->data->col.last)
    c2 = ih->data->col.last;

  if(l1 < ih->data->lin.first)
    l1 = ih->data->lin.first;
  if(l2 > ih->data->lin.last)
    l2 = ih->data->lin.last;

  if(c1 > c2 || l1 > l2)
    return;

  ih->data->redraw = 1;

  if(l1 <= l2)
    iupMatrixDrawLineTitle(ih, l1, l2);
  if(c1<=c2)
    iupMatrixDrawColumnTitle(ih, c1, c2);

  x1 = 0;
  x2 = ih->data->XmaxC;
  y1 = 0;
  y2 = ih->data->YmaxC;

  oldx2 = x2;
  oldy1 = y1;
  oldy2 = y2;

  /* Find the initial position of the first column */
  x1 += ih->data->col.titlewh;
  for(j = ih->data->col.first; j < c1; j++)
    x1 += ih->data->col.wh[j];

  /* Find the final position of the last column */
  x2 = x1;
  for( ; j < c2; j++)
    x2 += ih->data->col.wh[j];
  x2 += (c2 == ih->data->col.last ? ih->data->col.lastwh : ih->data->col.wh[c2]);

  /* Find the initial position of the first line */
  y1 += ih->data->lin.titlewh;
  for(j = ih->data->lin.first; j < l1; j++)
    y1 += ih->data->lin.wh[j];

  /* Find the final position of the last line */
  y2 = y1;
  for( ; j < l2; j++)
    y2 += ih->data->lin.wh[j];
  y2 += (l2 == ih->data->lin.last ? ih->data->lin.lastwh : ih->data->lin.wh[l2]);

  if((c2 == ih->data->col.num-1) && (oldx2 > x2))
  {
    /* If it was drawn until the last column and remains space in the right of it,
       then delete this area with the the background color.
    */
    iupMatrixDrawEmptyArea(ih, x2, oldx2, oldy1, oldy2);
  }

  if((l2 == ih->data->lin.num-1) && (oldy2 > y2))
  {
    /* If it was drawn until the last line visible and remains space below it,
       then delete this area with the the background color.
    */
    iupMatrixDrawEmptyArea(ih, 0, oldx2, y2, oldy2);
  }

  /***** Show the cell values */
  xc1 = x1;
  yc1 = y1;
  iupStrToRGB(IupGetAttribute(ih, "FRAMECOLOR"), &r, &g, &b);
  framecolor = cdEncodeColor((unsigned char) r, (unsigned char) g, (unsigned char) b);

  for(j = c1; j <= c2; j++)  /* For all the columns in the region */
  {
    if(ih->data->col.wh[j] == 0)
      continue;

    align = iMatrixDrawGetColAlignment(ih, j + 1);

    xc2 = xc1 + (j == ih->data->col.last ? ih->data->col.lastwh : ih->data->col.wh[j]);

    for(i = l1; i <= l2; i++)     /* For all lines in the region */
    {
      if(ih->data->lin.wh[i] == 0)
        continue;

      yc2 = yc1 + ih->data->lin.wh[i]-1;

      if(!(IupGetInt(ih->data->datah, "VISIBLE") && i == ih->data->lin.active && j == ih->data->col.active))
      {
        int drop = 0;
        int cor  = IMAT_ELEM_COLOR;
        char *cell_value;

        if(iMatrixDrawCallDropDownCheckCb(ih, i, j))
          drop = IMAT_BOXW;

        /* If the cell is marked, then draw it in reverse color */
        if(iupMatrixMarkCellGet(ih, i, j))
          cor = IMAT_REVERSE_COLOR;

        cell_value = iupMatrixAuxGetCellValue(ih, i, j);
        iMatrixDrawText(ih, xc1, xc1+ih->data->col.wh[j]-1-drop, yc1, yc2-1, cell_value, align, xc2, cor, i+1, j+1);

        if(drop)
          iMatrixDrawComboFeedback(ih, xc1+ih->data->col.wh[j]-1, yc1, yc2, i+1, j+1, cor);
      }

      if (ih->data->checkframecolor)
      {
        sprintf(str, "FRAMEHORIZCOLOR%d:%d", i, j);
        if (iupStrToRGB(IupGetAttribute(ih, str), &r, &g, &b))
          cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor((unsigned char) r, (unsigned char) g, (unsigned char) b));
        else
          cdCanvasForeground(ih->data->cddbuffer, framecolor);
      }
      else
        cdCanvasForeground(ih->data->cddbuffer, framecolor);
    
      /* horizontal line (only for this column) */
      CdLine(xc1, yc2, xc2-1, yc2);
      
      if (ih->data->checkframecolor)
      {
        sprintf(str, "FRAMEVERTCOLOR%d:%d", i+1, j+1);
        if (iupStrToRGB(IupGetAttribute(ih, str), &r, &g, &b))
          cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor((unsigned char) r, (unsigned char) g, (unsigned char) b));
        else
          cdCanvasForeground(ih->data->cddbuffer, framecolor);
      }
      else
        cdCanvasForeground(ih->data->cddbuffer, framecolor);

      /* vertical line (only for this line) */
      CdLine(xc2-1,yc1,xc2-1,yc2-1);

      yc1  = yc2+1;
    }

    xc1 = xc2;
    yc1 = y1;
  }
}
Esempio n. 3
0
/* Redraw a block of cells of the matrix. Handle marked cells, change
   automatically the background color of them.
   - lin1, col1 : cell coordinates that mark the left top corner of the area to be redrawn
   - lin2, col2 : cell coordinates that mark the right bottom corner of the area to be redrawn */
void iupMatrixDrawCells(Ihandle* ih, int lin1, int col1, int lin2, int col2)
{
  int x1, y1, x2, y2, old_x2, old_y1, old_y2;
  int alignment, lin, col, active;
  long framecolor, emptyarea_color = -1;
  char str[100];
  IFnii mark_cb;
  IFnii dropcheck_cb;
  IFniiiiiiC draw_cb;

  x1 = 0;
  x2 = ih->data->w-1;
  y1 = 0;
  y2 = ih->data->h-1;

  old_x2 = x2;
  old_y1 = y1;
  old_y2 = y2;

  if (col1 > ih->data->columns.last ||
      col2 < ih->data->columns.first ||
      lin1 > ih->data->lines.last ||
      lin2 < ih->data->lines.first)
    return;

  if (col1 < ih->data->columns.first)
    col1 = ih->data->columns.first;
  if (col2 > ih->data->columns.last)
    col2 = ih->data->columns.last;
  if (lin1 < ih->data->lines.first)
    lin1 = ih->data->lines.first;
  if (lin2 > ih->data->lines.last)
    lin2 = ih->data->lines.last;

  /* Find the initial position of the first column */
  x1 += ih->data->columns.sizes[0];
  for(col = ih->data->columns.first; col < col1; col++)
    x1 += ih->data->columns.sizes[col];

  /* Find the final position of the last column */
  x2 = x1;
  for( ; col <= col2; col++)
    x2 += ih->data->columns.sizes[col];

  /* Find the initial position of the first line */
  y1 += ih->data->lines.sizes[0];
  for(lin = ih->data->lines.first; lin < lin1; lin++)
    y1 += ih->data->lines.sizes[lin];

  /* Find the final position of the last line */
  y2 = y1;
  for( ; lin <= lin2; lin++)
    y2 += ih->data->lines.sizes[lin];

  if ((col2 == ih->data->columns.num-1) && (old_x2 > x2))
  {
    emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent);
    cdCanvasForeground(ih->data->cddbuffer, emptyarea_color);

    /* If it was drawn until the last column and remains space in the right of it,
       then delete this area with the the background color. */
    IUPMAT_BOX(ih, x2, old_x2, old_y1, old_y2);
  }

  if ((lin2 == ih->data->lines.num-1) && (old_y2 > y2))
  {
    if (emptyarea_color == -1)
      emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent);
    cdCanvasForeground(ih->data->cddbuffer, emptyarea_color);

    /* If it was drawn until the last line visible and remains space below it,
       then delete this area with the the background color. */
    IUPMAT_BOX(ih, 0, old_x2, y2, old_y2);
  }

  /***** Draw the cell values and frame */
  old_y1 = y1;
  framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR"));
  active = iupdrvIsActive(ih);

  mark_cb = (IFnii)IupGetCallback(ih, "MARK_CB");
  dropcheck_cb = (IFnii)IupGetCallback(ih, "DROPCHECK_CB");
  draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB");

  for(col = col1; col <= col2; col++)  /* For all the columns in the region */
  {
    if (ih->data->columns.sizes[col] == 0)
      continue;

    alignment = iMatrixDrawGetColAlignment(ih, col, str);

    x2 = x1 + ih->data->columns.sizes[col];

    for(lin = lin1; lin <= lin2; lin++)     /* For all lines in the region */
    {
      if (ih->data->lines.sizes[lin] == 0)
        continue;

      y2 = y1 + ih->data->lines.sizes[lin];

      if (col==1 && ih->data->columns.sizes[0] == 0)
      {
        /* If does not have titles then draw the left line of the cell frame */
        iMatrixDrawFrameVertLineCell(ih, lin, col, x1, y1, y2-1-1, framecolor, str);
      }

      if (lin==1 && ih->data->lines.sizes[0] == 0)
      {
        /* If does not have titles then draw the top line of the cell frame */
        iMatrixDrawFrameHorizLineCell(ih, lin, col, x1, x2-1-1, y1, framecolor, str);
      }

      /* draw the cell contents */
      {
        int drop = 0;
        int marked = 0;

        if (dropcheck_cb && dropcheck_cb(ih, lin, col) == IUP_DEFAULT)
          drop = IMAT_COMBOBOX_W;

        /* If the cell is marked, then draw it with attenuation color */
        marked = iupMatrixMarkCellGet(ih, lin, col, mark_cb, str);

        iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, lin, col);
        
        iMatrixDrawCellValue(ih, x1, x2-drop, y1, y2, alignment, marked, active, lin, col, draw_cb);

        if (drop)
          iMatrixDrawComboFeedback(ih, x2, y1, y2, lin, col, marked, active, framecolor);
      }

      /* bottom line */
      iMatrixDrawFrameHorizLineCell(ih, lin, col, x1, x2-1, y2-1, framecolor, str);
      
      /* rigth line */
      iMatrixDrawFrameVertLineCell(ih, lin, col, x2-1, y1, y2-1, framecolor, str);

      y1 = y2;
    }

    x1 = x2;
    y1 = old_y1;  /* must reset also y */
  }
}