Exemplo n.º 1
0
/* Draw the line titles, visible, between lin and lastlin, include it. 
   Line titles marked will be draw with the appropriate feedback.
   -> lin - First line to have its title drawn
   -> lastlin - Last line to have its title drawn
*/
int iupMatrixDrawLineTitle(Ihandle* ih, int lin, int lastlin)
{
  int x1, y1, x2, y2;
  int j;
  char *str;

  /* If no has line title, also must return the position (in pixels).
     This position would be the vertical position in the end of the
     last line drawn, if necessary the draw. This is a requirement
     used by scroll function
  */

  /* Fix lin and lastlin to contain the region of the lines that
     will be draw (visible)
  */

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

  if(lastlin > ih->data->lin.last)
    lastlin = ih->data->lin.last;

  if(lastlin < lin)
    return 0;

  /* Start the position of the line title */
  x1 = 0;
  x2 = ih->data->col.titlewh;
  y1 = ih->data->lin.titlewh;

  for(j = ih->data->lin.first; j < lin; j++)
    y1 += ih->data->lin.wh[j];

  ih->data->redraw = 1;

  /* Draw the titles */
  for(j = lin; j <= lastlin; j++)
  {
    /* If it is an hide line (size = 0), no draw the title */
    if(ih->data->lin.wh[j] == 0)
      continue;

    y2 = y1 + ih->data->lin.wh[j]-1;

    /* If it doesn't have title, the loop just calculate the final position */
    if(ih->data->col.titlewh)
    {
      iMatrixDrawTitleLineBox(ih, j+1, x1, y1, x2-x1, y2-y1+1);
      str = iupMatrixAuxGetCellValue(ih, j, -1);
      iMatrixDrawText(ih, x1, x2, y1, y2, str, iMatrixDrawGetColAlignment(ih, 0), x2, IMAT_TITLE_COLOR, j+1, 0);
      iupMatrixCDSetCdFrameColor(ih);
      CdLine(x2-1, y1, x2-1, y2);
    }

    y1 = y2 + 1;
  }

  return y1;
}
Exemplo n.º 2
0
/* Draw the corner between line and column titles */
void iupMatrixDrawTitleCorner(Ihandle* ih)
{
  char *str;

  /* If there are lines or columns, and exist column and line titles, */
  /* then draw the left top corner                                    */
  if((ih->data->lin.num != 0 || ih->data->col.num != 0) && ih->data->lin.titlewh && ih->data->col.titlewh)
  {
    ih->data->redraw = 1;

    iMatrixDrawBoxReleased(ih, 0, 0, ih->data->col.titlewh, ih->data->lin.titlewh, 0, 0);
    str = iupMatrixAuxGetCellValue(ih, -1, -1);
    iMatrixDrawText(ih, 0, ih->data->col.titlewh, 0, ih->data->lin.titlewh-1, str, IMAT_T_CENTER, ih->data->col.titlewh, IMAT_TITLE_COLOR, 0, 0);
  }
}
Exemplo n.º 3
0
/* Put the cell contents in the screen, using the specified color and alignment.
   -> y1, y2 : vertical limits of the cell
   -> x1, x2 : horizontal limits of the complete cell
   -> alignment : alignment type (horizontal) assigned to the text. The options are:
                  [IMAT_ALIGN_CENTER,IMAT_ALIGN_LEFT,IMAT_ALIGN_RIGHT]
   -> marked : mark state
   -> lin, col - cell coordinates */
static void iMatrixDrawCellValue(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, IFniiiiiiC draw_cb, long framecolor)
{
  char *value;

  /* avoid drawing over the frame of the next cell */
  x2 -= IMAT_FRAME_W/2;
  y2 -= IMAT_FRAME_H/2;

  /* avoid drawing over the frame of the cell */
  x2 -= IMAT_FRAME_W/2;
  y2 -= IMAT_FRAME_H/2;

  if (lin==0 || col==0)
  {
    /* avoid drawing over the frame of the cell */
    x1 += IMAT_FRAME_W/2;
    y1 += IMAT_FRAME_H/2;

    if (col==0) x1 += IMAT_FRAME_W/2;
    if (lin==0) y1 += IMAT_FRAME_H/2;
  }
  else if ((col==1 && ih->data->columns.dt[0].size == 0) || (lin==1 && ih->data->lines.dt[0].size == 0))
  {
    /* avoid drawing over the frame of the cell */
    x1 += IMAT_FRAME_W/2;
    y1 += IMAT_FRAME_H/2;
  }

  if (draw_cb && !iMatrixDrawCallDrawCB(ih, lin, col, x1, x2, y1, y2, draw_cb))
    return;

  value = iupMatrixGetValueDisplay(ih, lin, col);

  /* Put the text */
  if (value && *value)
  {
    int type = iupMatrixGetType(ih, lin, col);
    if (type == IMAT_TYPE_TEXT)
      iMatrixDrawText(ih, x1, x2, y1, y2, alignment, marked, active, lin, col, value);
    else if (type == IMAT_TYPE_COLOR)
      iMatrixDrawColor(ih, x1, x2, y1, y2, marked, active, value, framecolor);
    else if (type == IMAT_TYPE_FILL)
      iMatrixDrawFill(ih, x1, x2, y1, y2, marked, active, lin, col, value, framecolor);
    else if (type == IMAT_TYPE_IMAGE)
      iMatrixDrawImage(ih, x1, x2, y1, y2, alignment, marked, active, lin, col, value);
  }
}
Exemplo n.º 4
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;
  }
}
Exemplo n.º 5
0
/* Draw the column titles, visible, between col and lastcol, include it. 
   Column titles marked will be draw with the appropriate feedback.
   -> col - First column to have its title drawn
   -> lastcol - Last column to have its title drawn
*/
int iupMatrixDrawColumnTitle(Ihandle* ih, int col, int lastcol)
{
  int x1, y1, x2, y2;
  int j;
  char *str;

  /* If no has column title, also must return the position (in pixels).
     This position would be the horizontal position in the end of the
     last column drawn, if necessary the draw. This is a requirement
     used by scroll function
  */

  /* Fix col and lastcol to contain the region of the columns that
     will be draw (visible)
  */

  if(col < ih->data->col.first)
    col = ih->data->col.first;

  if(lastcol > ih->data->col.last)
    lastcol = ih->data->col.last;

  if(lastcol < col)
    return 0;
 
  /* Start the position of the first column title */
  y1 = 0;
  y2 = ih->data->lin.titlewh - 1;
  x1 = ih->data->col.titlewh;

  for(j = ih->data->col.first; j < col; j++)
    x1 += ih->data->col.wh[j];

  ih->data->redraw = 1;

  /* Draw the titles */
  for(j = col; j <= lastcol; j++)
  {
    int w, alignment;

    /* If it is an hide column (size = 0), no draw the title */
    if(ih->data->col.wh[j] == 0)
      continue;

    /* Decide which alignment must be used.
       If the text can be inside the canvas, then center alignment,
       if no, left alignment
    */
    x2 = x1 + (j == ih->data->col.last ? ih->data->col.lastwh : ih->data->col.wh[j]);

    /* If it doesn't have title, the loop just calculate the final position */
    if(ih->data->lin.titlewh)
    {
      str = iupMatrixAuxGetCellValue(ih, -1, j);
      if(str)
        iupMatrixAuxTextWidth(ih, str, &w);
      else
        w = 0;
      alignment = (w > x2 - x1 + 1 - IMAT_DECOR_X) ? IMAT_T_LEFT : IMAT_T_CENTER;

      /* draw the title */
      iMatrixDrawTitleColumnBox(ih, j+1, x1, y1, x2-x1, y2-y1+1);
      iMatrixDrawText(ih, x1, x1 + ih->data->col.wh[j], y1, y2, str, alignment, x2, IMAT_TITLE_COLOR, 0, j+1);
      iupMatrixCDSetCdFrameColor(ih);
      CdLine(x1, y2, x2-1, y2);
      {
        char* aux = iupStrGetMemory(50);
        char* sort;
        sprintf(aux, "SORTSIGN%d", j+1);
        sort = iupAttribGetStr(ih, aux);
        if(sort && !iupStrEqualNoCase(sort, "NO"))
          iMatrixDrawSort(ih, x1 + ih->data->col.wh[j], y1, y2, x2, 0, j+1, sort);
      }
    }
    x1 = x2;
  }

  return x1;
}