示例#1
0
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h)
{
  int max_w;

  IgtkFont* gtkfont = gtkFontGet(ih);
  if (!gtkfont)
  {
    if (w) *w = 0;
    if (h) *h = 0;
    return;
  }

  if (!str)
  {
    if (w) *w = 0;
    if (h) *h = gtkfont->charheight * 1;
    return;
  }

  max_w = 0;
  if (str[0])
  {
    int dummy_h;

    if (iupStrBoolean(iupAttribGetStr(ih, "MARKUP")))
      pango_layout_set_markup(gtkfont->layout, iupgtkStrConvertToUTF8(str), -1);
    else
      pango_layout_set_text(gtkfont->layout, iupgtkStrConvertToUTF8(str), -1);

    pango_layout_get_pixel_size(gtkfont->layout, &max_w, &dummy_h);
  }

  if (w) *w = max_w;
  if (h) *h = gtkfont->charheight * iupStrLineCount(str);
}
示例#2
0
文件: iup_str.c 项目: Airr/iup_mac
char* iupStrToMac(const char* str)
{
  int at_start = 1;
  char* pstr, *new_str;

  if (!str) return NULL;

  if (iupStrLineCount(str) == 1)
    return (char*)str;

  new_str = iupStrDup(str);
  str = new_str;
  pstr = new_str;
  
  while (*str)
  {
    if (*str == '\n')
    {
      if (!at_start && *(str-1) != '\r')  /* UNIX line end */
        *pstr++ = '\r';
      str++;
    }
    else
      *pstr++ = *str++;
    at_start = 0;
  }
  
  *pstr = *str;

  return new_str;
}
示例#3
0
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h)
{
  int max_w = 0;

  IwinFont* winfont = winFontGet(ih);
  if (!winfont)
  {
    if (w) *w = 0;
    if (h) *h = 0;
    return;
  }

  if (!str)
  {
    if (w) *w = 0;
    if (h) *h = winfont->charheight * 1;
    return;
  }

  if (str[0])
  {
    SIZE size;
    int len, wlen;
    const char *nextstr;
    const char *curstr = str;

    HDC hdc = winFontGetDC(ih);
    HFONT oldhfont = (HFONT)SelectObject(hdc, winfont->hFont);
    TCHAR* wstr = iupwinStrToSystem(str);

    do
    {
      nextstr = iupStrNextLine(curstr, &len);
      if (len)
      {
#ifdef UNICODE
        wlen = MultiByteToWideChar(iupwinStrGetUTF8Mode()? CP_UTF8: CP_ACP, 0, curstr, len, 0, 0);
#else
        wlen = len;
#endif

        size.cx = 0;
        GetTextExtentPoint32(hdc, wstr, wlen, &size);
        max_w = iupMAX(max_w, size.cx);

        wstr += wlen+1;
      }

      curstr = nextstr;
    } while(*nextstr);

    SelectObject(hdc, oldhfont);
    winFontReleaseDC(ih, hdc);
  }

  if (w) *w = max_w;
  if (h) *h = winfont->charheight * iupStrLineCount(str);
}
示例#4
0
void iupDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, unsigned char r, unsigned char g, unsigned char b, const char* font)
{
  int num_line;
  HFONT hOldFont, hFont = (HFONT)iupwinGetHFont(font);
  SetTextColor(dc->hBitmapDC, RGB(r, g, b));
  hOldFont = SelectObject(dc->hBitmapDC, hFont);

  num_line = iupStrLineCount(text);

  if (num_line == 1)
  {
    TCHAR* wtext = iupwinStrToSystemLen(text, &len);
    TextOut(dc->hBitmapDC, x, y, wtext, len);
  }
  else
  {
    int i, line_height, len;
    const char *p, *q;
    TCHAR* wtext;
    TEXTMETRIC tm;

    GetTextMetrics(dc->hBitmapDC, &tm);
    line_height = tm.tmHeight;

    p = text;
    for (i = 0; i < num_line; i++)
    {
      q = strchr(p, '\n');
      if (q) 
        len = (int)(q - p);  /* Cut the string to contain only one line */
      else 
        len = (int)strlen(p);  /* use the remaining characters */

      /* Draw the line */
      wtext = iupwinStrToSystemLen(p, &len);
      TextOut(dc->hBitmapDC, x, y, wtext, len);

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

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

  SelectObject(dc->hBitmapDC, hOldFont);
}
示例#5
0
void iupDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, unsigned char r, unsigned char g, unsigned char b, const char* font)
{
    int num_line;
    XFontStruct* xfont = (XFontStruct*)iupmotGetFontStruct(font);
    XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(r, g, b));
    XSetFont(iupmot_display, dc->pixmap_gc, xfont->fid);

    num_line = iupStrLineCount(text);

    if (num_line == 1)
        XDrawString(iupmot_display, dc->pixmap, dc->pixmap_gc, x, y+xfont->ascent, text, len);
    else
    {
        int i, line_height, len;
        const char *p, *q;

        line_height = xfont->ascent + xfont->descent;

        p = text;
        for (i = 0; i < num_line; i++)
        {
            q = strchr(p, '\n');
            if (q)
                len = (int)(q - p);  /* Cut the string to contain only one line */
            else
                len = (int)strlen(p);  /* use the remaining characters */

            /* Draw the line */
            XDrawString(iupmot_display, dc->pixmap, dc->pixmap_gc, x, y + xfont->ascent, p, len);

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

            /* Advance a line */
            y += line_height;
        }
    }
}
示例#6
0
static int iMatrixExStrGetDataSize(const char* data, int *num_lin, int *num_col, char *sep)
{
  int len = strlen(data);
  *num_lin = iupStrLineCount(data);
  if (data[len-1] == '\n')
    (*num_lin)--;  /* avoid an empty last line */

  if (*num_lin == 0)
    return 0;

  if (*sep != 0)
    *num_col = iupStrCountChar(data, *sep);
  else
  {
    /* try to guess the separator */
    *sep = '\t';
    *num_col = iupStrCountChar(data, *sep);
    if (*num_col == 0)
    {
      *sep = ';';
      *num_col = iupStrCountChar(data, *sep);
    }
  }

  /* If here is no column separator for the last column, so add it */
  if (!((data[len-1] == '\n' && data[len-2] == *sep) ||
        (data[len-1] == *sep)))
    *num_col += *num_lin;

  if (*num_col == 0)
    return 0;

  if ((*num_col)%(*num_lin)!=0)
    return 0;

  *num_col = (*num_col)/(*num_lin);
  return 1;
}
示例#7
0
文件: iup_str.c 项目: Airr/iup_mac
char* iupStrToDos(const char* str)
{
	char *auxstr, *newstr;
	int num_lin;

  if (!str) return NULL;

  num_lin = iupStrLineCount(str);
  if (num_lin == 1)
    return (char*)str;

	newstr = malloc(num_lin + strlen(str) + 1);
  auxstr = newstr;
	while(*str)
	{
		if (*str == '\r' && *(str+1)=='\n')  /* DOS line end */
    {
      *auxstr++ = *str++;
      *auxstr++ = *str++;
    }
    else if (*str == '\r')   /* MAC line end */
    {
		  *auxstr++ = *str++;
			*auxstr++ = '\n';
    }
    else if (*str == '\n')  /* UNIX line end */
    {
			*auxstr++ = '\r';
		  *auxstr++ = *str++;
    }
    else
		  *auxstr++ = *str++;
	}
	*auxstr = 0;

	return newstr;	
}
示例#8
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, "...");
  }
}
示例#9
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, "...");
        }
    }
}
示例#10
0
static int iMatrixEditTextKeyAny_CB(Ihandle* ih, int c)
{
  Ihandle* ih_matrix = ih->parent;
  IFniiiis cb = (IFniiiis) IupGetCallback(ih_matrix, "ACTION_CB");
  if (cb && !iup_isprint(c)) /* only for other keys that are not characters */
  {
    int oldc = c;
    c = cb(ih_matrix, c, ih_matrix->data->lines.focus_cell, ih_matrix->data->columns.focus_cell, 1, IupGetAttribute(ih, "VALUE"));
    if(c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE)
      return c;
    else if(c == IUP_DEFAULT)
      c = oldc;
  }

  switch (c)
  {
    case K_cUP:
    case K_cDOWN:
    case K_cLEFT:
    case K_cRIGHT:     
      if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
      {
        iupMatrixProcessKeyPress(ih_matrix, c);  
        return IUP_IGNORE;
      }
      break;
    case K_UP:
      if (IupGetInt(ih, "CARET") == 1)
      {
        /* if at the first line of the text */
        if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
        {
          iupMatrixProcessKeyPress(ih_matrix, c);  
          return IUP_IGNORE;
        }
      }
      break;
    case K_DOWN:
      { 
        char* value = IupGetAttribute(ih, "VALUE");
        if (value)
        {
          /* if at the last line of the text */
          if (iupStrLineCount(value) == IupGetInt(ih, "CARET"))
          {
            if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
            {
              iupMatrixProcessKeyPress(ih_matrix, c);  
              return IUP_IGNORE;
            }
          }
        }
      }
      break;
    case K_LEFT:
      if (IupGetInt(ih, "CARETPOS") == 0)
      {
        /* if at the first character */
        if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
        {
          iupMatrixProcessKeyPress(ih_matrix, c);  
          return IUP_IGNORE;
        }
      }
      break;
    case K_RIGHT:
      { 
        char* value = IupGetAttribute(ih, "VALUE");
        if (value)
        {
          /* if at the last character */
          if ((int)strlen(value) == IupGetInt(ih, "CARETPOS"))
          {
            if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
            {
              iupMatrixProcessKeyPress(ih_matrix, c);  
              return IUP_IGNORE;
            }
          }
        }
      }
      break;
    case K_ESC:
      iMatrixEditCancel(ih_matrix, 1, 0, 0); /* set focus + NO update + NO ignore */
      return IUP_IGNORE;  /* always ignore to avoid the defaultesc behavior from here */
    case K_CR:
      if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT)
      {
        if (iupStrEqualNoCase(IupGetGlobal("DRIVER"), "Win32") && IupGetInt(ih, "MULTILINE"))
        {
          /* work around for Windows when using Multiline */
          iupAttribSetStr(ih_matrix, "_IUPMAT_IGNORE_SHOW", "1");
        }

        if (iupMatrixAuxCallLeaveCellCb(ih_matrix) != IUP_IGNORE)
        {
          iupMATRIX_ScrollKeyCr(ih_matrix);
          iupMatrixAuxCallEnterCellCb(ih_matrix);
        }
        iupMatrixDrawUpdate(ih_matrix);
      }
      return IUP_IGNORE;  /* always ignore to avoid the defaultenter behavior from here */
  }

  return IUP_CONTINUE;
}