Пример #1
0
/* Calculate the size, in pixels, of the invisible columns/lines,
   the left/above of the first column/line.
   In fact the start position of the visible area.
   Depends on the first visible column/line.
   -> m : choose will operate on lines or columns [IMAT_PROCESS_LIN|IMAT_PROCESS_COL]
*/
void iupMatrixAuxUpdateScrollPos(Ihandle* ih, int m)
{
  float pos;
  int i, sb, scroll_pos;
  char* POS;
  ImatLinColData *p;

  if (m == IMAT_PROCESS_LIN)
  {
    p = &(ih->data->lines);
    sb = IUP_SB_VERT;
    POS = "POSY";
  }
  else
  {
    p = &(ih->data->columns);
    sb = IUP_SB_HORIZ;
    POS = "POSX";
  }

  /* "first" was changed, so update "last" and the scroll pos */

  if (p->total_visible_size <= p->current_visible_size)
  {
    /* the matrix is fully visible */
    p->first = p->num_noscroll;
    p->first_offset = 0;
    p->last = p->num==p->num_noscroll? p->num_noscroll: p->num-1;

    if (ih->data->canvas.sb & sb)
      IupSetAttribute(ih, POS, "0");

    return;
  }

  /* must check if it is a valid position */
  scroll_pos = 0;
  for(i = p->num_noscroll; i < p->first; i++)
    scroll_pos += p->dt[i].size;
  scroll_pos += p->first_offset;

  if (scroll_pos + p->current_visible_size > p->total_visible_size)
  {
    /* invalid condition, must recalculate so it is valid */
    scroll_pos = p->total_visible_size - p->current_visible_size;

    /* position first and first_offset, according to scroll pos */
    iupMatrixAuxAdjustFirstFromScrollPos(p, scroll_pos);
  }

  pos = (float)scroll_pos/(float)p->total_visible_size;

  /* update last */
  iupMatrixAuxUpdateLast(p);

  /* update scroll pos */
  if (ih->data->canvas.sb & sb)
    IupSetFloat(ih, POS, pos);
}
Пример #2
0
/* This function is called when a drag is performed in the scrollbar.
   -> x    : scrollbar thumb position, value between 0 and 1
   -> mode : DO NOT USED
   -> m    : define the mode of operation: lines or columns [IMAT_PROCESS_LIN|IMAT_PROCESS_COL]
*/
void iupMatrixScrollPosFunc(Ihandle* ih, int mode, float pos, int m)
{
  int scroll_pos;
  ImatLinColData* p;
  (void)mode;

  if (m == IMAT_PROCESS_LIN)
    p = &(ih->data->lines);
  else
    p = &(ih->data->columns);

  if (p->num == 1)
  {
    p->first = 1;
    p->first_offset = 0;
    return;
  }

  scroll_pos = (int)(pos * p->total_size + 0.5);

  /* position first and first_offset, according to scroll pos */
  iupMatrixAuxAdjustFirstFromScrollPos(p, scroll_pos);
}