Exemple #1
0
int iupTextSetAddFormatTagHandleAttrib(Ihandle* ih, const char* value)
{
  Ihandle* formattag = (Ihandle*)value;
  if (!iupObjectCheck(formattag))
    return 0;

  if (ih->handle)
  {
    /* must update VALUE before updating the format */
    iTextUpdateValueAttrib(ih);

    iupdrvTextAddFormatTag(ih, formattag);
    IupDestroy(formattag);
  }
  else
  {
    Ihandle** tag_array;
    int i;

    if (!ih->data->formattags)
      ih->data->formattags = iupArrayCreate(10, sizeof(Ihandle*));

    i = iupArrayCount(ih->data->formattags);
    tag_array = (Ihandle**)iupArrayInc(ih->data->formattags);
    tag_array[i] = formattag;
  }
  return 0;
}
Exemple #2
0
static int iNormalizerSetAddControlHandleAttrib(Ihandle* ih, const char* value)
{
  Ihandle* ih_control = (Ihandle*)value;
  Ihandle** ih_list = (Ihandle**)iupArrayInc(ih->data->ih_array);
  int count = iupArrayCount(ih->data->ih_array);
  ih_list[count-1] = ih_control;
  return 0;
}
Exemple #3
0
static ImotFont* motFindFont(const char* foundry, const char *standardfont)
{
  char xlfd[1024];
  XFontStruct* fontstruct;
  int i, count = iupArrayCount(mot_fonts);
  int is_underline = 0, is_strikeout = 0;

  ImotFont* fonts = (ImotFont*)iupArrayGetData(mot_fonts);

  /* Check if the standardfont already exists in cache */
  for (i = 0; i < count; i++)
  {
    if (iupStrEqualNoCase(standardfont, fonts[i].standardfont))
      return &fonts[i];
  }

  /* not found, create a new one */
  if (standardfont[0] == '-')
  {
    fontstruct = XLoadQueryFont(iupmot_display, standardfont);
    if (!fontstruct) return NULL;
    strcpy(xlfd, standardfont);
  }
  else
  {
    int size,
        is_bold = 0,
        is_italic = 0;
    char typeface[1024];
    const char* mapped_name;

    if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout))
      return NULL;

    mapped_name = iupFontGetXName(typeface);
    if (mapped_name)
      strcpy(typeface, mapped_name);

    fontstruct = motLoadFont(foundry, typeface, size, is_bold, is_italic, xlfd);
    if (!fontstruct) return NULL;
  }

  /* create room in the array */
  fonts = (ImotFont*)iupArrayInc(mot_fonts);

  strcpy(fonts[i].standardfont, standardfont);
  strcpy(fonts[i].xlfd, xlfd);
  fonts[i].fontstruct = fontstruct;
  fonts[i].fontlist = motFontCreateRenderTable(fontstruct, is_underline, is_strikeout);
  fonts[i].charwidth = motFontCalcCharWidth(fontstruct);
  fonts[i].charheight = fontstruct->ascent + fontstruct->descent;

  return &fonts[i];
}
static void iMatrixUndoStackAdd(ImatExData* matex_data, const char* name)
{
  int i, undo_stack_count = iupArrayCount(matex_data->undo_stack);
  IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack);

  /* Remove all Redo data */
  for (i=matex_data->undo_stack_pos; i<undo_stack_count; i++)
    iMatrixExUndoDataClear(&(undo_stack_data[i]));
  iupArrayRemove(matex_data->undo_stack, matex_data->undo_stack_pos, undo_stack_count-matex_data->undo_stack_pos);

  undo_stack_data = (IundoData*)iupArrayInc(matex_data->undo_stack);
  iMatrixExUndoDataInit(&(undo_stack_data[matex_data->undo_stack_pos]), name);
}
Exemple #5
0
int iupTextSetAddFormatTagHandleAttrib(Ihandle* ih, const char* value)
{
  Ihandle* formattag = (Ihandle*)value;
  if (!iupObjectCheck(formattag))
    return 0;

  if (ih->handle)
  {
    char* bulk;

    /* must update VALUE before updating the format */
    iTextUpdateValueAttrib(ih);

    bulk = iupAttribGet(formattag, "BULK");
    if (bulk && iupStrBoolean(bulk))
    {
      Ihandle* child;
      void* state = iupdrvTextAddFormatTagStartBulk(ih);

      char* cleanout = iupAttribGet(formattag, "CLEANOUT");
      if (cleanout && iupStrBoolean(cleanout))
        IupSetAttribute(ih, "REMOVEFORMATTING", "ALL");

      for (child = formattag->firstchild; child; child = child->brother)
        iupdrvTextAddFormatTag(ih, child, 1);

      iupdrvTextAddFormatTagStopBulk(ih, state);
    }
    else
      iupdrvTextAddFormatTag(ih, formattag, 0);

    IupDestroy(formattag);
  }
  else
  {
    Ihandle** tag_array;
    int i;

    if (!ih->data->formattags)
      ih->data->formattags = iupArrayCreate(10, sizeof(Ihandle*));

    i = iupArrayCount(ih->data->formattags);
    tag_array = (Ihandle**)iupArrayInc(ih->data->formattags);
    tag_array[i] = formattag;
  }
  return 0;
}
Exemple #6
0
static void gtkFileDlgGetMultipleFiles(Ihandle* ih, GSList* list)
{
  int len, cur_len, dir_len = -1;
  char *filename, *all_names;
  Iarray* names_array = iupArrayCreate(1024, 1);  /* just set an initial size, but count is 0 */

  while (list)
  {
    filename = (char*)list->data;
    len = strlen(filename);

    if (dir_len == -1)
    {
      dir_len = len;

      while (dir_len && (filename[dir_len] != '/' && filename[dir_len] != '\\'))
        dir_len--;

      cur_len = iupArrayCount(names_array);
      all_names = iupArrayAdd(names_array, dir_len+1);
      memcpy(all_names+cur_len, filename, dir_len);
      all_names[cur_len+dir_len] = '0';
      iupAttribStoreStr(ih, "DIRECTORY", all_names);
      all_names[cur_len+dir_len] = '|';

      dir_len++; /* skip separator */
    }
    len -= dir_len; /* remove directory */

    cur_len = iupArrayCount(names_array);
    all_names = iupArrayAdd(names_array, len+1);
    memcpy(all_names+cur_len, filename+dir_len, len);
    all_names[cur_len+len] = '|';

    g_free(filename);
    list = list->next;
  }

  cur_len = iupArrayCount(names_array);
  all_names = iupArrayInc(names_array);
  all_names[cur_len+1] = 0;

  iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(all_names));

  iupArrayDestroy(names_array);
}
static int motFileDlgGetMultipleFiles(Ihandle* ih, const char* dir, Widget wList)
{
  int *pos, sel_count, dir_len;
  int i, len, cur_len;
  char *filename, *all_names;
  Iarray* names_array;
  XmString* items;

  if (!XmListGetSelectedPos(wList, &pos, &sel_count))
    return 0;

  names_array = iupArrayCreate(1024, 1);  /* just set an initial size, but count is 0 */
  XtVaGetValues(wList, XmNitems, &items, NULL);

  cur_len = strlen(dir);

  all_names = iupArrayAdd(names_array, cur_len+1);
  memcpy(all_names, dir, cur_len);
  all_names[cur_len] = '|';
  dir_len = cur_len;
  cur_len++; /* skip separator */

  for (i = 0; i<sel_count; i++)
  {
    filename = iupmotConvertString(items[pos[i]-1]);  /* XmListGetSelectedPos starts at 1 */
    len = strlen(filename)-dir_len;

    cur_len = iupArrayCount(names_array);
    all_names = iupArrayAdd(names_array, len+1);
    memcpy(all_names+cur_len, filename+dir_len, len);
    all_names[cur_len+len] = '|';
  }

  XtFree((char*)pos);

  cur_len = iupArrayCount(names_array);
  all_names = iupArrayInc(names_array);
  all_names[cur_len+1] = 0;

  iupAttribStoreStr(ih, "VALUE", all_names);

  iupArrayDestroy(names_array);
  return 1;
}
Exemple #8
0
static int iNormalizerCreateMethod(Ihandle* ih, void** params)
{
  ih->data = iupALLOCCTRLDATA();
  ih->data->ih_array = iupArrayCreate(10, sizeof(Ihandle*));

  if (params)
  {
    Ihandle** iparams = (Ihandle**)params;
    Ihandle** ih_list;
    int i = 0;
    while (*iparams) 
    {
      ih_list = (Ihandle**)iupArrayInc(ih->data->ih_array);
      ih_list[i] = *iparams;
      i++;
      iparams++;
    }
  }

  return IUP_NOERROR;
}
Exemple #9
0
static IwinFont* winFindFont(const char *standardfont)
{
  HFONT hFont;
  int height_pixels;  /* negative value */
  char typeface[50] = "";
  int size = 8;
  int is_bold = 0,
    is_italic = 0, 
    is_underline = 0,
    is_strikeout = 0;
  int res = iupwinGetScreenRes();
  int i, count = iupArrayCount(win_fonts);
  const char* mapped_name;

  /* Check if the standardfont already exists in cache */
  IwinFont* fonts = (IwinFont*)iupArrayGetData(win_fonts);
  for (i = 0; i < count; i++)
  {
    if (iupStrEqualNoCase(standardfont, fonts[i].standardfont))
      return &fonts[i];
  }

  if (!iupGetFontInfo(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout))
    return NULL;

  /* Map standard names to native names */
  mapped_name = iupFontGetWinName(typeface);
  if (mapped_name)
    strcpy(typeface, mapped_name);

  /* get in pixels */
  if (size < 0)  
    height_pixels = size;    /* already in pixels */
  else
    height_pixels = -iupWIN_PT2PIXEL(size, res);

  if (height_pixels == 0)
    return NULL;

  hFont = CreateFont(height_pixels, 0,0,0,
                    (is_bold) ? FW_BOLD : FW_NORMAL,
                    is_italic, is_underline, is_strikeout,
                    DEFAULT_CHARSET,OUT_TT_PRECIS,
                    CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
                    FF_DONTCARE|DEFAULT_PITCH,
                    iupwinStrToSystem(typeface));

  if (!hFont)
    return NULL;

  /* create room in the array */
  fonts = (IwinFont*)iupArrayInc(win_fonts);

  strcpy(fonts[i].standardfont, standardfont);
  fonts[i].hFont = hFont;

  {
    HDC hdc = GetDC(NULL);
    HFONT oldfont = (HFONT)SelectObject(hdc, hFont);

    TEXTMETRIC tm;
    GetTextMetrics(hdc, &tm);
    /* NOTICE that this is different from CD.
       In IUP we need "average" width,
       in CD is "maximum" width. */
    fonts[i].charwidth = tm.tmAveCharWidth; 
    fonts[i].charheight = tm.tmHeight;

    SelectObject(hdc, oldfont);
    ReleaseDC(NULL, hdc);
  }

  return &fonts[i];
}
Exemple #10
0
static void iMatrixExArrayAddChar(Iarray* data, char c)
{
  int last_count = iupArrayCount(data);
  char* str_data = (char*)iupArrayInc(data);
  str_data[last_count] = c;
}
Exemple #11
0
static int winTabsGetImageIndex(Ihandle* ih, const char* name)
{
  HIMAGELIST image_list;
  int count, i, bpp, ret;
  Iarray* bmp_array;
  HBITMAP *bmp_array_data, hMask=NULL;
  HBITMAP bmp = iupImageGetImage(name, ih, 0);
  if (!bmp)
    return -1;

  /* the array is used to avoi adding the same bitmap twice */
  bmp_array = (Iarray*)iupAttribGet(ih, "_IUPWIN_BMPARRAY");
  if (!bmp_array)
  {
    /* create the array if does not exist */
    bmp_array = iupArrayCreate(50, sizeof(HBITMAP));
    iupAttribSetStr(ih, "_IUPWIN_BMPARRAY", (char*)bmp_array);
  }

  bmp_array_data = iupArrayGetData(bmp_array);

  image_list = (HIMAGELIST)SendMessage(ih->handle, TCM_GETIMAGELIST, 0, 0);
  if (!image_list)
  {
    int width, height;
    UINT flags = ILC_COLOR32|ILC_MASK;

    /* must use this info, since image can be a driver image loaded from resources */
    iupdrvImageGetInfo(bmp, &width, &height, &bpp);

    /* create the image list if does not exist */
    image_list = ImageList_Create(width, height, flags, 0, 50);
    SendMessage(ih->handle, TCM_SETIMAGELIST, 0, (LPARAM)image_list);
  }
  else
    iupdrvImageGetInfo(bmp, NULL, NULL, &bpp);

  /* check if that bitmap is already added to the list,
     but we can not compare with the actual bitmap at the list since it is a copy */
  count = ImageList_GetImageCount(image_list);
  for (i=0; i<count; i++)
  {
    if (bmp_array_data[i] == bmp)
      return i;
  }

  if (bpp == 8)
  {
    Ihandle* image = IupGetHandle(name);
    if (image)
    {
      iupAttribSetStr(image, "_IUPIMG_NO_INVERT", "1");
      hMask = iupdrvImageCreateMask(image);
      iupAttribSetStr(image, "_IUPIMG_NO_INVERT", NULL);
    }
  }

  bmp_array_data = iupArrayInc(bmp_array);
  bmp_array_data[i] = bmp;
  ret = ImageList_Add(image_list, bmp, hMask);  /* the bmp is duplicated at the list */
  DeleteObject(hMask);
  return ret;
}
Exemple #12
0
static IgtkFont* gtkFindFont(const char *standardfont)
{
  PangoFontMetrics* metrics;
  PangoFontDescription* fontdesc;
  int i, 
      is_underline = 0,
      is_strikeout = 0,
      count = iupArrayCount(gtk_fonts);

  IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts);

  /* Check if the standardfont already exists in cache */
  for (i = 0; i < count; i++)
  {
    if (iupStrEqualNoCase(standardfont, fonts[i].standardfont))
      return &fonts[i];
  }

  /* not found, create a new one */
  {
    int size;
    int is_bold = 0,
      is_italic = 0;
    char typeface[1024];
    char *new_standardfont = NULL;
    const char* mapped_name;

    if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout))
      return NULL;

    mapped_name = iupFontGetPangoName(typeface);
    if (mapped_name)
      strcpy(typeface, mapped_name);

    if (is_underline || is_strikeout || size<0)
      new_standardfont = iupStrDup(standardfont);

    if (is_underline)
    {
      char* under = strstr(standardfont, "Underline");
      int len = strlen(standardfont);
      int len1 = (size_t)(under-standardfont);
      memcpy(new_standardfont, standardfont, len1);
      memcpy(new_standardfont+len1, under+9+1, len-len1-9+1); /* strlen("Underline") */
      standardfont = new_standardfont;
    }

    if (is_strikeout)
    {
      char* strike = strstr(standardfont, "Strikeout");
      int len = strlen(standardfont);
      int len1 = (size_t)(strike-standardfont);
      memcpy(new_standardfont, standardfont, len1);
      memcpy(new_standardfont+len1, strike+9+1, len-len1-9+1); /* strlen("Strikeout") */
      standardfont = new_standardfont;
    }

    if (size<0)
    {
      double res;
      int len1, len2;
      char *sz, size_str[10];
      sprintf(size_str, "%d", size);
      sz = strstr(standardfont, size_str);
      len1 = (size_t)(sz-standardfont);

      res = ((double)gdk_screen_get_width(gdk_screen_get_default()) / (double)gdk_screen_get_width_mm(gdk_screen_get_default())); /* pixels/mm */
      /* 1 point = 1/72 inch     1 inch = 25.4 mm */
      /* pixel = ((point/72)*25.4)*pixel/mm */
      size = (int)((-size/res)*2.83464567 + 0.5); /* from pixels to points */

      len2 = sprintf(size_str, "%d", size);

      memcpy(new_standardfont, standardfont, len1);
      memcpy(new_standardfont+len1, size_str, len2+1);
    }

    fontdesc = pango_font_description_from_string(standardfont);

    if (new_standardfont) free(new_standardfont);
  }

  if (!fontdesc) 
    return NULL;

  /* create room in the array */
  fonts = (IgtkFont*)iupArrayInc(gtk_fonts);

  strcpy(fonts[i].standardfont, standardfont);
  fonts[i].fontdesc = fontdesc;
  fonts[i].strikethrough = pango_attr_strikethrough_new(is_strikeout? TRUE: FALSE);
  fonts[i].underline = pango_attr_underline_new(is_underline? PANGO_UNDERLINE_SINGLE: PANGO_UNDERLINE_NONE);
  fonts[i].layout = pango_layout_new(gtk_fonts_context);

  metrics = pango_context_get_metrics(gtk_fonts_context, fontdesc, pango_context_get_language(gtk_fonts_context));
  fonts[i].charheight = pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics);
  fonts[i].charheight = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charheight);
  fonts[i].charwidth = pango_font_metrics_get_approximate_char_width(metrics);
  fonts[i].charwidth = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charwidth);
  pango_font_metrics_unref(metrics); 

  gtkFontUpdate(&(fonts[i]));

  return &fonts[i];
}
Exemple #13
0
static IgtkFont* gtkFindFont(const char *standardfont)
{
  PangoFontMetrics* metrics;
  PangoFontDescription* fontdesc;
  int i, 
      is_underline = 0,
      is_strikeout = 0,
      count = iupArrayCount(gtk_fonts);

  IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts);

  /* Check if the standardfont already exists in cache */
  for (i = 0; i < count; i++)
  {
    if (iupStrEqualNoCase(standardfont, fonts[i].standardfont))
      return &fonts[i];
  }

  /* not found, create a new one */
  {
    int size = 0, is_pango = 0;
    int is_bold = 0,
      is_italic = 0;
    char typeface[1024];
    const char* mapped_name;

    /* parse the old Windows format first */
    if (!iupFontParseWin(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout))
    {
      if (!iupFontParseX(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout))
      {
        if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout))
          return NULL;
        else
          is_pango = 1;
      }
    }

    mapped_name = iupFontGetPangoName(typeface);
    if (mapped_name)
      strcpy(typeface, mapped_name);

    if (is_pango && !is_underline && !is_strikeout && size>0)
      fontdesc = pango_font_description_from_string(standardfont);
    else
    {
      char new_standardfont[200];
      if (size<0)
      {
        double res = ((double)gdk_screen_get_width(gdk_screen_get_default()) / (double)gdk_screen_get_width_mm(gdk_screen_get_default())); /* pixels/mm */
        /* 1 point = 1/72 inch     1 inch = 25.4 mm */
        /* pixel = ((point/72)*25.4)*pixel/mm */
        size = (int)((-size/res)*2.83464567 + 0.5); /* from pixels to points */
      }

      sprintf(new_standardfont, "%s, %s%s%d", typeface, is_bold?"Bold ":"", is_italic?"Italic ":"", size);

      fontdesc = pango_font_description_from_string(new_standardfont);
    }
  }

  if (!fontdesc) 
    return NULL;

  /* create room in the array */
  fonts = (IgtkFont*)iupArrayInc(gtk_fonts);

  strcpy(fonts[i].standardfont, standardfont);
  fonts[i].fontdesc = fontdesc;
  fonts[i].strikethrough = pango_attr_strikethrough_new(is_strikeout? TRUE: FALSE);
  fonts[i].underline = pango_attr_underline_new(is_underline? PANGO_UNDERLINE_SINGLE: PANGO_UNDERLINE_NONE);
  fonts[i].layout = pango_layout_new(gtk_fonts_context);

  metrics = pango_context_get_metrics(gtk_fonts_context, fontdesc, pango_context_get_language(gtk_fonts_context));
  fonts[i].charheight = pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics);
  fonts[i].charheight = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charheight);
  fonts[i].charwidth = pango_font_metrics_get_approximate_char_width(metrics);
  fonts[i].charwidth = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charwidth);
  pango_font_metrics_unref(metrics); 

  gtkFontUpdate(&(fonts[i]));

  return &fonts[i];
}
Exemple #14
0
static IwinFont* winFindFont(const char *standardfont)
{
  HFONT hFont;
  int height_pixels;
  char typeface[50] = "";
  int height = 8;
  int is_bold = 0,
    is_italic = 0, 
    is_underline = 0,
    is_strikeout = 0;
  int res = iupwinGetScreenRes();
  int i, count = iupArrayCount(win_fonts);
  const char* mapped_name;

  /* Check if the standardfont already exists in cache */
  IwinFont* fonts = (IwinFont*)iupArrayGetData(win_fonts);
  for (i = 0; i < count; i++)
  {
    if (iupStrEqualNoCase(standardfont, fonts[i].standardfont))
      return &fonts[i];
  }

  /* parse the old format first */
  if (!iupFontParseWin(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout))
  {
    if (!iupFontParsePango(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout))
      return NULL;
  }

  mapped_name = iupFontGetWinName(typeface);
  if (mapped_name)
    strcpy(typeface, mapped_name);

  /* get in pixels */
  if (height < 0)  
    height_pixels = height;    /* already in pixels */
  else
    height_pixels = -IUPWIN_PT2PIXEL(height, res);

  if (height_pixels == 0)
    return NULL;

  hFont = CreateFont(height_pixels,
                        0,0,0,
                        (is_bold) ? FW_BOLD : FW_NORMAL,
                        is_italic,
                        is_underline,
                        is_strikeout,
                        DEFAULT_CHARSET,OUT_TT_PRECIS,
                        CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
                        FF_DONTCARE|DEFAULT_PITCH,
                        typeface);
  if (!hFont)
    return NULL;

  /* create room in the array */
  fonts = (IwinFont*)iupArrayInc(win_fonts);

  strcpy(fonts[i].standardfont, standardfont);
  fonts[i].hFont = hFont;

  {
    TEXTMETRIC tm;
    HDC hdc = GetDC(NULL);
    HFONT oldfont = SelectObject(hdc, hFont);

    GetTextMetrics(hdc, &tm);

    SelectObject(hdc, oldfont);
    ReleaseDC(NULL, hdc);
    
    fonts[i].charwidth = tm.tmAveCharWidth; 
    fonts[i].charheight = tm.tmHeight;
  }

  return &fonts[i];
}