Exemplo n.º 1
0
static int iTabsGetMaxWidth(Ihandle* ih)
{
  int max_width = 0, width, pos;
  char *tabtitle, *tabimage;
  Ihandle* child;

  for (pos = 0, child = ih->firstchild; child; child = child->brother, pos++)
  {
    tabtitle = iupAttribGet(child, "TABTITLE");
    if (!tabtitle) tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos);
    tabimage = iupAttribGet(child, "TABIMAGE");
    if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos);
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    width = 0;
    if (tabtitle)
      width += iupdrvFontGetStringWidth(ih, tabtitle);

    if (tabimage)
    {
      void* img = iupImageGetImage(tabimage, ih, 0);
      if (img)
      {
        int w;
        iupdrvImageGetInfo(img, &w, NULL, NULL);
        width += w;
      }
    }

    if (width > max_width) max_width = width;
  }

  return max_width;
}
Exemplo n.º 2
0
int iupTreeKeyNodeCalcPos(Ihandle* ih, int* x, int* y, int* text_x)
{
  ItreeNodePtr node  = (ItreeNodePtr)ih->data->root;
  float posy = IupGetFloat(ih, "POSY");
  float dy   = IupGetFloat(ih, "DY");
  float posx = IupGetFloat(ih, "POSX");
  float dx   = IupGetFloat(ih, "DX");

  cdCanvasActivate(ih->data->cddbuffer);

  *y = (int)((1.0 + posy/dy)*(ih->data->YmaxC-ITREE_TREE_TOP_MARGIN));

  while(node != ih->data->selected)
  {
    if(node->visible == YES)
      *y -= ITREE_NODE_Y;

    node = node->next;
    if(node == NULL)
      return 0;
  }

  *y -= ITREE_NODE_Y;
  *x = (int)(ITREE_TREE_LEFT_MARGIN - (ih->data->XmaxC - ITREE_NODE_X) * posx / dx) + ITREE_NODE_X * node->depth;

  /* if node has a text associated to it... */
  *text_x = 0;
  if(node->name)
  {
    /* Calculates its dimensions */
    *text_x = iupdrvFontGetStringWidth(ih, node->name);
  }

  return 1;
}
Exemplo n.º 3
0
void iupdrvListInsertItem(Ihandle* ih, int pos, const char* value)
{
  SendMessage(ih->handle, WIN_INSERTSTRING(ih), pos, (LPARAM)value);
  SendMessage(ih->handle, WIN_SETITEMDATA(ih), pos, (LPARAM)iupdrvFontGetStringWidth(ih, value));
  winListUpdateScrollWidth(ih);

  iupListUpdateOldValue(ih, pos, 0);
}
Exemplo n.º 4
0
static void iTextComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand)
{
  int natural_w = 0, 
      natural_h = 0,
      visiblecolumns = iupAttribGetInt(ih, "VISIBLECOLUMNS"),
      visiblelines = iupAttribGetInt(ih, "VISIBLELINES");
  (void)expand; /* unset if not a container */

  /* Since the contents can be changed by the user, the size can not be dependent on it. */
  if (ih->data->is_multiline)
  {
    iupdrvFontGetCharSize(ih, NULL, &natural_h);  /* one line height */
    natural_w = iupdrvFontGetStringWidth(ih, "WWWWWWWWWW");
    natural_w = (visiblecolumns*natural_w)/10;
    natural_h = visiblelines*natural_h;
  }
  else
  {
    iupdrvFontGetCharSize(ih, NULL, &natural_h);  /* one line height */
    natural_w = iupdrvFontGetStringWidth(ih, "WWWWWWWWWW");
    natural_w = (visiblecolumns*natural_w)/10;
  }

  /* compute the borders space */
  if (iupAttribGetBoolean(ih, "BORDER"))
    iupdrvTextAddBorders(&natural_w, &natural_h);

  if (iupAttribGetBoolean(ih, "SPIN"))
    iupdrvTextAddSpin(&natural_w, natural_h);

  natural_w += 2*ih->data->horiz_padding;
  natural_h += 2*ih->data->vert_padding;

  /* add scrollbar */
  if (ih->data->is_multiline && ih->data->sb)
  {
    int sb_size = iupdrvGetScrollbarSize();
    if (ih->data->sb & IUP_SB_HORIZ)
      natural_w += sb_size;
    if (ih->data->sb & IUP_SB_VERT)
      natural_h += sb_size;
  }

  *w = natural_w;
  *h = natural_h;
}
Exemplo n.º 5
0
static void winListUpdateItemWidth(Ihandle* ih)
{
  int i, count = SendMessage(ih->handle, WIN_GETCOUNT(ih), 0, 0);
  for (i=0; i<count; i++)
  { 
    int len = SendMessage(ih->handle, WIN_GETTEXTLEN(ih), (WPARAM)i, 0);
    char* str = iupStrGetMemory(len+1);
    SendMessage(ih->handle, WIN_GETTEXT(ih), (WPARAM)i, (LPARAM)str);
    SendMessage(ih->handle, WIN_SETITEMDATA(ih), i, (LPARAM)iupdrvFontGetStringWidth(ih, str));
  }
}
Exemplo n.º 6
0
static void winListUpdateItemWidth(Ihandle* ih)
{
  int i, count = SendMessage(ih->handle, WIN_GETCOUNT(ih), 0, 0);
  for (i=0; i<count; i++)
  { 
    winListItemData* itemdata = winListGetItemData(ih, i);
    char* str = winListGetText(ih, i);
    itemdata->text_width = iupdrvFontGetStringWidth(ih, str);
    free(str);
  }
}
Exemplo n.º 7
0
static void winListSetItemData(Ihandle* ih, int pos, const char* str, HBITMAP hBitmap)
{
  winListItemData* itemdata = winListGetItemData(ih, pos);
  if (!itemdata)
  {
    itemdata = malloc(sizeof(winListItemData));
    SendMessage(ih->handle, WIN_SETITEMDATA(ih), pos, (LPARAM)itemdata);
  }

  itemdata->hBitmap = hBitmap;
  itemdata->text_width = iupdrvFontGetStringWidth(ih, str);
  winListUpdateScrollWidthItem(ih, itemdata->text_width, 1);
}
Exemplo n.º 8
0
static int iMatrixEditTextAction_CB(Ihandle* ih_text, int c, char* after)
{
    Ihandle* ih = ih_text->parent;
    IFniiiis cb = (IFniiiis) IupGetCallback(ih, "ACTION_CB");

    if (iupAttribGetBoolean(ih, "EDITFITVALUE"))
    {
        int value_w, value_h, resize = 0;

        value_w = iupdrvFontGetStringWidth(ih_text, after);
        iupdrvFontGetCharSize(ih_text, NULL, &value_h);

        if (iupAttribGetBoolean(ih_text, "BORDER"))
        {
            value_w += 2 * 4;
            value_h += 2 * 4;
        }

        if (value_w > ih_text->currentwidth)
        {
            ih_text->currentwidth = value_w;
            resize = 1;
        }
        if (value_h > ih_text->currentheight)
        {
            ih_text->currentheight = value_h;
            resize = 1;
        }

        if (resize)
            iupClassObjectLayoutUpdate(ih_text);
    }

    if (cb && iup_isprint(c)) /* only for keys that ARE ASCii characters */
    {
        int oldc = c;
        c = cb(ih, c, ih->data->edit_lin, ih->data->edit_col, 1, after);
        if (c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE)
            return c;
        else if(c == IUP_DEFAULT)
            c = oldc;
        return c;
    }

    return IUP_DEFAULT;
}
Exemplo n.º 9
0
static void iTreeMouseDrop(Ihandle* ih, int xmouse, int ymouse, int shift, int control)
{
  ItreeNodePtr node = (ItreeNodePtr)ih->data->root;
  int x;
  int y = ih->data->YmaxC - ITREE_TREE_TOP_MARGIN;
  int tree_drop_id = 0;
  (void)control;
  (void)shift;

  while(node)
  {
    int text_x;
    text_x = 0;

    x = ITREE_TREE_LEFT_MARGIN + ITREE_NODE_X * node->depth;
    if(node->visible == YES)
      y-= ITREE_NODE_Y;

    /* if node has a text associated to it... */
    if(node->name)
    {
      /* Calculates its dimensions */
      text_x = iupdrvFontGetStringWidth(ih, node->name);
    }

    /* Looks for associated text (leaf or branch) */
    if(iupTreeMouseText(ih, node, text_x, xmouse, ymouse, x, y))
    {
      tree_drag = 0;
      tree_drop_id = iupTreeFindNodeId(ih, node);
      break;
    }

    node = node->next;
  }

  IupSetAttribute(ih, "CURSOR", "ARROW");
  tree_drag_mouse = 0;

  if(tree_drag || tree_drag_id==tree_drop_id)
    tree_drag = 0;
  else
    iupTreeCallbackDragDropCB(ih, tree_drag_id, tree_drop_id, tree_shift, tree_ctrl);
}
Exemplo n.º 10
0
static void iTreeMouseDrag(Ihandle* ih, int xmouse, int ymouse)
{
  ItreeNodePtr node = (ItreeNodePtr)ih->data->root;
  int x;
  int y = ih->data->YmaxC - ITREE_TREE_TOP_MARGIN;

  tree_drag = 0;
  tree_drag_mouse = 0;

  while(node)
  {
    int text_x;
    text_x = 0;

    x = ITREE_TREE_LEFT_MARGIN + ITREE_NODE_X * node->depth;
    if(node->visible == YES)
      y-= ITREE_NODE_Y;

    /* if node has a text associated to it... */
    if(node->name)
    {
      /* Calculates its dimensions */
      text_x = iupdrvFontGetStringWidth(ih, node->name);
    }

    /* Looks for associated text (leaf or branch) */
    if(iupTreeMouseText(ih, node, text_x, xmouse, ymouse, x, y))
    {
      tree_drag = 1;
      tree_drag_id = iupTreeFindNodeId(ih, node);
      tree_drag_mouse = 1;
      tree_drag_mouse_x = xmouse;
      tree_drag_mouse_y = ymouse;
      break;
    }

    node = node->next;
  }
}
Exemplo n.º 11
0
void iupMatrixEditUpdatePos(Ihandle* ih)
{
    int w, h, x, y, visible;
    visible = iupMatrixGetVisibleCellDim(ih, ih->data->edit_lin, ih->data->edit_col, &x, &y, &w, &h);
    if (!visible && !ih->data->edit_hide_onfocus)
        IupSetAttribute(ih->data->datah, "VISIBLE", "NO");

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

    ih->data->datah->currentwidth = w;
    ih->data->datah->currentheight = h;

    if (ih->data->datah==ih->data->texth && iupAttribGetBoolean(ih, "EDITFITVALUE"))
    {
        char* value = IupGetAttribute(ih->data->texth, "VALUE");
        int value_w, value_h;

        value_w = iupdrvFontGetStringWidth(ih->data->texth, value);
        iupdrvFontGetCharSize(ih->data->texth, NULL, &value_h);

        if (iupAttribGetBoolean(ih->data->texth, "BORDER"))
        {
            value_w += 2*4;
            value_h += 2*4;
        }

        if (value_w > ih->data->datah->currentwidth)
            ih->data->datah->currentwidth = value_w;
        if (value_h > ih->data->datah->currentheight)
            ih->data->datah->currentheight = value_h;
    }

    iupClassObjectLayoutUpdate(ih->data->datah);

    if (visible && !ih->data->edit_hide_onfocus)
        IupSetAttribute(ih->data->datah, "VISIBLE", "YES");
}
Exemplo n.º 12
0
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, const char* text)
{
  int num_line, line_height, total_height;
  int charheight, y, hidden_text_marks = 0;

  num_line = iupStrLineCount(text);
  iupdrvFontGetCharSize(ih, NULL, &charheight);

  line_height  = charheight;
  total_height = (line_height + IMAT_PADDING_H/2) * num_line - IMAT_PADDING_H/2 - IMAT_FRAME_H/2;

  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)
        alignment = IMAT_ALIGN_LEFT;

      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 greatter 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;

  if (alignment == IMAT_ALIGN_CENTER)
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_CENTER);
  else if(alignment == IMAT_ALIGN_LEFT)
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_WEST);
  else  /* RIGHT */
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);

  if (num_line == 1)
  {
    y = (int)((y1 + y2) / 2.0 - 0.5);

    /* Put the text */
    if (alignment == IMAT_ALIGN_CENTER)
      iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, text);
    else if(alignment == IMAT_ALIGN_LEFT)
      iupMATRIX_TEXT(ih, x1, y, text);
    else  /* RIGHT */
      iupMATRIX_TEXT(ih, x2, y, text);
  }
  else
  {
    int i;
    char *p, *q, *newtext;

    newtext = iupStrDup(text);
    p = newtext;

    /* Get the position of the first text to be put in the screen */
    y = (int)( (y1 + y2) / 2.0 - 0.5) - total_height/2 + line_height/2;

    for(i = 0; i < num_line; i++)
    {
      q = strchr(p, '\n');
      if (q) *q = 0;  /* Cut the string to contain only one line */

      /* Draw the text */
      if(alignment == IMAT_ALIGN_CENTER)
        iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, p);
      else if(alignment == IMAT_ALIGN_LEFT)
        iupMATRIX_TEXT(ih, x1, y, p);
      else  /* RIGHT */
        iupMATRIX_TEXT(ih, x2, y, p);

      /* Advance the string */
      if (q) p = q + 1;

      /* Advance a line */
      y += line_height + IMAT_PADDING_H/2;
    }

    free(newtext);
  }

  iMatrixDrawResetCellClipping(ih);

  if (hidden_text_marks)
  {
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);
    y = (int)((y1 + y2) / 2.0 - 0.5);
    iupMATRIX_TEXT(ih, x2+IMAT_PADDING_W/2, y, "...");
  }
}
Exemplo n.º 13
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_T_CENTER,IMAT_T_LEFT,IMAT_T_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)
{
    char *text;

    /* 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.sizes[0] == 0) || (lin==1 && ih->data->lines.sizes[0] == 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;

    text = iupMatrixCellGetValue(ih, lin, col);

    /* Put the text */
    if (text && *text)
    {
        int num_line, line_height, total_height;
        int charheight, ypos, hidden_text_marks = 0;

        num_line = iupStrLineCount(text);
        iupdrvFontGetCharSize(ih, NULL, &charheight);

        line_height  = charheight;
        total_height = (line_height + IMAT_PADDING_H/2) * num_line - IMAT_PADDING_H/2 - IMAT_FRAME_H/2;

        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)
                    alignment = IMAT_T_LEFT;

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

        /* Set the color used to draw the text */
        if (!active)
            cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_FGCOLOR);
        else
            iMatrixDrawSetFgColor(ih, lin, col, marked);

        /* Set the clip area to the cell region informed, the text maybe greatter 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);

        cdCanvasNativeFont(ih->data->cddbuffer, 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;

        if (alignment == IMAT_T_CENTER)
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_CENTER);
        else if(alignment == IMAT_T_LEFT)
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_WEST);
        else
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_EAST);

        if (num_line == 1)
        {
            ypos = (int)((y1 + y2) / 2.0 - 0.5);

            /* Put the text */
            if (alignment == IMAT_T_CENTER)
                iupMATRIX_TEXT(ih, (x1 + x2) / 2, ypos, text);
            else if(alignment == IMAT_T_LEFT)
                iupMATRIX_TEXT(ih, x1, ypos, text);
            else
                iupMATRIX_TEXT(ih, x2, ypos, text);
        }
        else
        {
            int i;
            char *p, *q, *newtext;

            newtext = iupStrDup(text);
            p = newtext;

            /* Get the position of the first text to be put in the screen */
            ypos = (int)( (y1 + y2) / 2.0 - 0.5) - total_height/2 + line_height/2;

            for(i = 0; i < num_line; i++)
            {
                q = strchr(p, '\n');
                if (q) *q = 0;  /* Cut the string to contain only one line */

                /* Draw the text */
                if(alignment == IMAT_T_CENTER)
                    iupMATRIX_TEXT(ih, (x1 + x2) / 2, ypos, p);
                else if(alignment == IMAT_T_LEFT)
                    iupMATRIX_TEXT(ih, x1, ypos, p);
                else
                    iupMATRIX_TEXT(ih, x2, ypos, p);

                /* Advance the string */
                if (q) p = q + 1;

                /* Advance a line */
                ypos += line_height + IMAT_PADDING_H/2;
            }

            free(newtext);
        }

        iMatrixDrawResetCellClipping(ih);

        if (hidden_text_marks)
        {
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_EAST);
            ypos = (int)((y1 + y2) / 2.0 - 0.5);
            iupMATRIX_TEXT(ih, x2+IMAT_PADDING_W/2, ypos, "...");
        }
    }
}
Exemplo n.º 14
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, "...");
  }
}
Exemplo n.º 15
0
static void iListGetNaturalItemsSize(Ihandle *ih, int *w, int *h)
{
  char *value;
  int max_w = 0, max_h = 0;
  int visiblecolumns, i, 
      count = iListGetCount(ih);

  *w = 0;
  *h = 0;

  iupdrvFontGetCharSize(ih, w, h);   /* one line height, and one character width */

  visiblecolumns = iupAttribGetInt(ih, "VISIBLECOLUMNS");
  if (visiblecolumns)
  {
    *w = iupdrvFontGetStringWidth(ih, "WWWWWWWWWW");
    *w = (visiblecolumns*(*w))/10;
  }
  else
  {
    int item_w;

    for (i=1; i<=count; i++)
    {
      item_w = 0;

      value = IupGetAttributeId(ih, "", i);  /* must use IupGetAttribute to check the native system */
      if (value)
        item_w = iupdrvFontGetStringWidth(ih, value);

      if (item_w > *w)
        *w = item_w;
    }

    if (*w == 0) /* default is 5 characters in 1 item */
      *w = iupdrvFontGetStringWidth(ih, "WWWWW");
  }

  if (ih->data->show_image)
  {
    for (i=1; i<=count; i++)
    {
      int img_w, img_h;
      iListGetItemImageInfo(ih, i, &img_w, &img_h);
      if (img_w > max_w)
        max_w = img_w;
      if (img_h > max_h)
        max_h = img_h;
    }

    /* Used only in Windows */
    ih->data->maximg_w = max_w;
    ih->data->maximg_h = max_h;

    *w += max_w;
  }

  /* compute height for multiple lines, dropdown is just 1 line */
  if (!ih->data->is_dropdown)
  {
    int visiblelines, num_lines, 
        edit_line_size = *h;  /* don't include the highest image */

    if (ih->data->show_image && max_h > *h)  /* use the highest image to compute the natural size */
      *h = max_h;

    iupdrvListAddItemSpace(ih, h);  /* this is independent from spacing */

    *h += 2*ih->data->spacing;  /* this will be multiplied by the number of lines */
    *w += 2*ih->data->spacing;  /* include also horizontal spacing */

    num_lines = count;
    if (num_lines == 0) num_lines = 1;

    visiblelines = iupAttribGetInt(ih, "VISIBLELINES");
    if (visiblelines)
      num_lines = visiblelines;   

    *h = *h * num_lines;

    if (ih->data->has_editbox) 
      *h += edit_line_size;
  }
  else
  {
    if (!ih->data->has_editbox)
    {
      if (ih->data->show_image && max_h > *h)  /* use the highest image to compute the natural size */
        *h = max_h;
    }
  }
}
Exemplo n.º 16
0
int iupTreeFindNodeIdFromXY(Ihandle* ih, int xmouse, int ymouse)
{
  ItreeNodePtr node  = (ItreeNodePtr)ih->data->root;
  int id = 0;
  int kind;
  int x;
  int y = ih->data->YmaxC - ITREE_TREE_TOP_MARGIN;

  while(node)
  {
    int text_x = 0;

    x = ITREE_TREE_LEFT_MARGIN + ITREE_NODE_X * node->depth;
    if(node->visible == YES)
      y -= ITREE_NODE_Y;

    kind = node->kind;

    /* if node has a text associated to it... */
    if(node->name)
    {
      /* Calculates its dimensions */
      text_x = iupdrvFontGetStringWidth(ih, node->name);
    }

    switch(kind)
    {
      case ITREE_BRANCH:
        {
          if(node->state == ITREE_EXPANDED)
          {
            /* if node isn't root, looks for button to collapse */
            if(node != ih->data->root && iupTreeMouseCollapseButton(ih, xmouse, ymouse, x, y))
              return id;
          }
          else
          {
            /* if node isn't root, looks for button to expand */
            if((node != ih->data->root && iupTreeMouseExpandButton(ih, xmouse, ymouse, x, y)))
              return id;
          }
      
          /* Looks for branch */
          if(iupTreeMouseCollapsedBranch(ih, xmouse, ymouse, x, y))
            return id;
        }
        break;

      case ITREE_LEAF:
        {
          /* Looks for leaf */
          if(iupTreeMouseLeaf(ih, xmouse, ymouse, x, y))
            return id;  
        }
        break;

      default:
        {
          return -1;
        }
    }

    /* Looks for associated text */
    if(iupTreeMouseText(ih, node, text_x, xmouse, ymouse, x, y))
      return id;

    node = node->next;
    id++;
  }
  
  return -1;
}
Exemplo n.º 17
0
void iupdrvListAppendItem(Ihandle* ih, const char* value)
{
  int pos = SendMessage(ih->handle, WIN_ADDSTRING(ih), 0, (LPARAM)value);
  SendMessage(ih->handle, WIN_SETITEMDATA(ih), pos, (LPARAM)iupdrvFontGetStringWidth(ih, value));
  winListUpdateScrollWidth(ih);
}
Exemplo n.º 18
0
static void iListGetNaturalItemsSize(Ihandle *ih, int *w, int *h)
{
  char *value;
  int visiblecolumns, 
      count = iListGetCount(ih);

  *w = 0;
  *h = 0;

  iupdrvFontGetCharSize(ih, w, h);   /* one line height, and one character width */

  visiblecolumns = iupAttribGetInt(ih, "VISIBLECOLUMNS");
  if (visiblecolumns)
  {
    *w = iupdrvFontGetStringWidth(ih, "WWWWWWWWWW");
    *w = (visiblecolumns*(*w))/10;
  }
  else
  {
    int item_w, i;
    char str[20];

    for (i=1; i<=count; i++)
    {
      sprintf(str, "%d", i);
      value = IupGetAttribute(ih, str);  /* must use IupGetAttribute to check the native system */
      if (value)
      {
        item_w = iupdrvFontGetStringWidth(ih, value);
        if (item_w > *w)
          *w = item_w;
      }
    }

    if (*w == 0) /* default is 5 characters in 1 item */
      *w = iupdrvFontGetStringWidth(ih, "WWWWW");
  }

  /* compute height for multiple lines, drodown is just 1 line */
  if (!ih->data->is_dropdown)
  {
    int visiblelines, num_lines, line_size = *h;

    iupdrvListAddItemSpace(ih, h);  /* this independs from spacing */

    *h += 2*ih->data->spacing;  /* this will be multiplied by the number of lines */
    *w += 2*ih->data->spacing;  /* include also horizontal spacing */

    num_lines = count;
    if (num_lines == 0) num_lines = 1;

    visiblelines = iupAttribGetInt(ih, "VISIBLELINES");
    if (visiblelines)
      num_lines = visiblelines;   

    *h = *h * num_lines;

    if (ih->data->has_editbox) 
      *h += line_size;
  }
}
Exemplo n.º 19
0
static void iTreeMouseRightPress(Ihandle* ih, int xmouse, int ymouse, char* r)
{
  ItreeNodePtr node = (ItreeNodePtr)ih->data->root;
  int kind;
  int x;
  int y = ih->data->YmaxC - ITREE_TREE_TOP_MARGIN;
  int id = 0;

  while(node)
  {
    int text_x;
    text_x = 0;

    x = ITREE_TREE_LEFT_MARGIN + ITREE_NODE_X * node->depth;
    if(node->visible == YES)
      y -= ITREE_NODE_Y;

    kind = node->kind;

    /* if node has a text associated to it... */
    if(node->name)
    {
      /* Calculates its dimensions */
      text_x = iupdrvFontGetStringWidth(ih, node->name);
    }

    if(kind == ITREE_BRANCH)
    {
      if(node->state == ITREE_EXPANDED)
      {
        /* if node isn't root, looks for button to collapse */
        if(node != ih->data->root && iupTreeMouseCollapseButton(ih, xmouse, ymouse, x, y))
        {
          iupTreeCallbackRightClickCB(ih, id, r);
          return;
        }
      }
      else
      {
        /* if node isn't root, looks for button to expand */
        if((node != ih->data->root && iupTreeMouseExpandButton(ih, xmouse, ymouse, x, y)))
        {
          iupTreeCallbackRightClickCB(ih, id, r);
          return;
        }
      }
      
      /* Looks for click on branch image only */
      if(iupTreeMouseCollapsedBranch(ih, xmouse, ymouse, x, y))
      {
        iupTreeCallbackRightClickCB(ih, id, r);
        return;
      }
    }
    else /* node is a leaf */
    {
      /* Looks for click on leaf image only */
      if(iupTreeMouseLeaf(ih, xmouse, ymouse, x, y))
      {
        iupTreeCallbackRightClickCB(ih, id, r);
        return;
      }
    }

    /* Looks for associated text */
    if(iupTreeMouseText(ih, node, text_x, xmouse, ymouse, x, y))
    {
      iupTreeCallbackRightClickCB(ih, id, r);
      return;
    }

    node = node->next;
    id++;
  }
  
  iupTreeCallbackRightClickCB(ih, -1, r);
}
Exemplo n.º 20
0
static void iTreeMouseLeftPress(Ihandle* ih, int xmouse, int ymouse, int mouse_shift, int mouse_ctrl, int dclick)
{
  ItreeNodePtr node = (ItreeNodePtr)ih->data->root;
  int willmark = 0;
  int x;
  int y = ih->data->YmaxC - ITREE_TREE_TOP_MARGIN;

  tree_ctrl  = mouse_ctrl;
  tree_shift = mouse_shift;

  while(node)
  {
    int text_x;
    text_x = 0;

    x = ITREE_TREE_LEFT_MARGIN + ITREE_NODE_X * node->depth;
    if(node->visible == YES)
      y-= ITREE_NODE_Y;

    /* if node has a text associated to it... */
    if(node->name)
    {
      /* Calculates its dimensions */
      text_x = iupdrvFontGetStringWidth(ih, node->name);
    }

    if(node->kind == ITREE_BRANCH)
    {
      /* Looks for click on branch image only */
      if(iTreeMouseLeftPressOnBranch(ih, node, dclick, xmouse, ymouse, x, y, &willmark))
      {
        /* User only pressed in the expand/collapse button */
        iupTreeRepaint(ih);
        return;
      }
    }
    else /* node is a leaf */
    {
      /* Looks for click on leaf image only */
      if(iupTreeMouseLeaf(ih, xmouse, ymouse, x, y))
      {
        willmark = 1;
  
        /* If it is a double click */
        if(dclick)
        {
          iupTreeCallbackExecuteLeafCB(ih);
          break;
        }
      }
    }

    /* Looks for associated text (leaf or branch) */
    if(iupTreeMouseText(ih, node, text_x, xmouse, ymouse, x, y))
    {
      willmark = 1;
      
      /* If it is a double click */
      if(dclick)
      {
        if(IupGetInt(ih, "SHOWRENAME"))
        {
          if(!iupTreeKeyNodeCalcPos(ih, &x, &y, &text_x))
            break;

          iupTreeEditShow(ih, text_x, x, y);

          if (iupStrEqualNoCase(IupGetGlobal("DRIVER"), "Motif"))
            if(atoi(IupGetGlobal("MOTIFNUMBER")) < 2203) /* since OpenMotif version 2.2.3 this is not necessary */
              IupSetAttribute(ih, "_IUPTREE_DOUBLE_CLICK", "1");
        }
        else
          iupTreeCallbackRenameNodeCB(ih);
        break;
      }
    }

    if(willmark)
    {
      ih->data->selected = node;
      break;
    }

    node = node->next;
  }

  /* Deselects all nodes if control and tree_shift were not pressed */
  if(!tree_ctrl && !tree_shift)
    iupTreeGSSetValue(ih, "CLEARALL", 1);

  if(node)
  {
    if(tree_ctrl == YES)
    {
      iupTreeGSSetValue(ih, "INVERT", 1); /* Control inverts selection */
    }
    else
    {
      if(willmark || node->kind != ITREE_BRANCH)
      {
        int test = IUP_DEFAULT;
        int id = iupTreeFindNodeId(ih, node);
        if(id == -1)
          return;

        if((tree_shift != YES || !IupGetCallback(ih, "MULTISELECTION_CB")) && (node->visible == YES))
        {
          if(node->marked == NO)
            test = iupTreeCallbackSelectionCB(ih, id, 1);
          if(test != IUP_IGNORE)
            node->marked = YES;
        }
      }
    }
  
    if(tree_shift == YES)
    {
      /* Marks block (which is from STARTING to last selected node) */
      iupTreeGSSetValue(ih, "BLOCK", 1);
    }
    else
    {
      /* If tree_shift is not pressed, STARTING becomes the selected node */
      iupTreeGSSetStarting(ih, iupTreeGSGetValue(ih));
    }
  }

  iupTreeRepaint(ih);
}