Esempio n. 1
0
static INT CALLBACK winFileDlgBrowseCallback(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
  (void)lParam;
  if (uMsg == BFFM_INITIALIZED)
  {
    char* value;
    Ihandle* ih = (Ihandle*)lpData;
    ih->handle = hWnd;
    iupDialogUpdatePosition(ih);
    ih->handle = NULL;  /* reset handle */
    value = iupStrDup(iupAttribGet(ih, "DIRECTORY"));
    if (value)
    {
      winFileDlgStrReplacePathSlash(value);
      SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)value);
      free(value);
    }
  }
  else if (uMsg == BFFM_SELCHANGED)
  {
    char buffer[IUP_MAX_FILENAME_SIZE];
    ITEMIDLIST* selecteditem = (ITEMIDLIST*)lParam;
    buffer[0] = 0;
    SHGetPathFromIDList(selecteditem, buffer);
    if (buffer[0] == 0)
      SendMessage(hWnd, BFFM_ENABLEOK, 0, (LPARAM)FALSE);
    else
      SendMessage(hWnd, BFFM_ENABLEOK, 0, (LPARAM)TRUE);
  }
  return 0;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
Imask* iupMaskCreate(const char* mask_str, int casei)
{
  ImaskParsed* fsm;
  Imask* mask;
  char* copy_mask_str;

  if (!mask_str)
    return NULL;

  /* Parse the mask first */
  copy_mask_str = iupStrDup(mask_str);
  if (iupMaskParse(copy_mask_str, &fsm) != IMASK_PARSE_OK)
  {
    free(copy_mask_str);
    return NULL;
  }

  mask = (Imask*)malloc(sizeof(Imask));
  memset(mask, 0, sizeof(Imask));

  mask->mask_str = copy_mask_str;
  mask->casei = casei;
  mask->fsm = fsm;

  return mask;
}
Esempio n. 4
0
static char* gtkColorDlgPaletteToString(const char* palette)
{
  char iup_str[20], *gtk_str, *palette_p;
  char* str = iupStrGetMemory(300);
  int off = 0, inc;
  GdkColor color;

  gtk_str = iupStrDup(palette);
  iupStrReplace(gtk_str, ':', 0);

  while (palette && *palette)
  {
    if (!gdk_color_parse (gtk_str, &color))
      return NULL;

    inc = sprintf(iup_str, "%d %d %d;", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue));
    memcpy(str+off, iup_str, inc);
    off += inc;
    palette_p = strchr(palette, ':');
    if (palette_p) 
    {
      palette_p++;
      gtk_str += palette_p-palette;
    }
    palette = palette_p;
  }
  str[off-1] = 0;  /* remove last separator */
  return str;
}
Esempio n. 5
0
static int winListCallEditCb(Ihandle* ih, HWND cbedit, const char* insert_value, int key, int dir)
{
  int start, end, ret = 1;
  char *value, *new_value;

  IFnis cb = (IFnis)IupGetCallback(ih, "EDIT_CB");
  if (!cb && !ih->data->mask)
    return 1;

  SendMessage(cbedit, EM_GETSEL, (WPARAM)&start, (LPARAM)&end);

  value = winListGetValueAttrib(ih);

  if (!value)
    new_value = iupStrDup(insert_value);
  else if (insert_value)
    new_value = iupStrInsert(value, insert_value, start, end);
  else
  {
    new_value = value;
    iupStrRemove(value, start, end, dir);
  }

  if (!new_value)
    return 0; /* abort */

  if (ih->data->nc && (int)strlen(new_value) > ih->data->nc)
  {
    if (new_value != value) free(new_value);
    return 0; /* abort */
  }

  if (ih->data->mask && iupMaskCheck(ih->data->mask, new_value)==0)
  {
    if (new_value != value) free(new_value);
    return 0; /* abort */
  }

  if (cb)
  {
    int cb_ret = cb(ih, key, (char*)new_value);
    if (cb_ret==IUP_IGNORE)
      ret = 0;     /* abort processing */
    else if (cb_ret==IUP_CLOSE)
    {
      IupExitLoop();
      ret = 0;     /* abort processing */
    }
    else if (cb_ret!=0 && key!=0 && 
             cb_ret != IUP_DEFAULT && cb_ret != IUP_CONTINUE)  
    {
      WNDPROC oldProc = (WNDPROC)IupGetCallback(ih, "_IUPWIN_EDITOLDPROC_CB");
      CallWindowProc(oldProc, cbedit, WM_CHAR, cb_ret, 0);  /* replace key */
      ret = 0;     /* abort processing */
    }
  }

  if (new_value != value) free(new_value);
  return ret;
}
Esempio n. 6
0
static int iMatrixExUndoDataSwap(ImatExData* matex_data, IundoData* undo_data)
{
  char* id = iupTableFirst(undo_data->data_table);
  while (id)
  {
    char *value, *old_value;
    int lin=1, col=1;
    iupStrToIntInt(id, &lin, &col, ':');

    value = (char*)iupTableGetCurr(undo_data->data_table);

    old_value = iupStrDup(iupMatrixExGetCellValue(matex_data->ih, lin, col, 0));  /* get internal value */

    iupMatrixExSetCellValue(matex_data->ih, lin, col, value);

    if (!old_value)
      iupTableSetCurr(undo_data->data_table, (void*)"", IUPTABLE_POINTER);
    else
    {
      iupTableSetCurr(undo_data->data_table, (void*)old_value, IUPTABLE_STRING);
      free(old_value);
    }

    if (!iupMatrixExBusyInc(matex_data))
      return 0;

    id = iupTableNext(undo_data->data_table);
  }

  return 1;
}
Esempio n. 7
0
static int iScintillaSetSearchFlagsAttrib(Ihandle* ih, const char* value)
{
  if (!value)
    IupScintillaSendMessage(ih, SCI_SETSEARCHFLAGS, 0, 0);
  else
  {
    int flags = 0;
    char* VALUE = iupStrDup(value);
    iupStrUpper(VALUE, VALUE);

    if (strstr(VALUE, "MATCHCASE"))
      flags |= SCFIND_MATCHCASE;
    if (strstr(VALUE, "WHOLEWORD"))
      flags |= SCFIND_WHOLEWORD;
    if (strstr(VALUE, "WORDSTART"))
      flags |= SCFIND_WORDSTART;
    if (strstr(VALUE, "REGEXP"))
      flags |= SCFIND_REGEXP;
    if (strstr(VALUE, "POSIX"))
      flags |= SCFIND_POSIX;

    IupScintillaSendMessage(ih, SCI_SETSEARCHFLAGS, flags, 0);
    free(VALUE);
  }

  return 0;
}
Esempio n. 8
0
static int iGaugeSetTextAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->text)
    free(ih->data->text);

  ih->data->text = iupStrDup(value);

  iGaugeRepaint(ih);
  return 0; /* do not store value in hash table */
}
Esempio n. 9
0
void iupMatrixCellSetValue(Ihandle* ih, int lin, int col, const char* value)
{
  if (ih->data->callback_mode)
    return;

  if (ih->data->cells[lin][col].value)
    free(ih->data->cells[lin][col].value);

  ih->data->cells[lin][col].value = iupStrDup(value);

  if (lin==0 || col==0)
    ih->data->need_calcsize = 1;
}
Esempio n. 10
0
static void iupEnvParse(Ihandle *n, const char* attr)
{
  char env_buffer[256];
  char* a=NULL;
  char* v=NULL;
  int state = 'a';               /* get attribute */
  int end = 0;

  env_str = attr;

  for (;;)
  {
    switch (iupEnvToken(env_buffer))
    {
    case TK_END:                 /* procedimento igual ao TK_COMMA */
      end = 1;
    case TK_COMMA:
      if (a != NULL)
      {
        iupTableSet(env(n), a, v, IUP_STRING);
        iupCpiSetAttribute (n, a, v);
        free(a);
      }
      if (end)
        return;
      a=v=NULL;
      state = 'a';
      break;

    case TK_SET:
      state = 'v';                /* get value */
      break;

    case TK_NAME:
      if (state == 'a')
        a = iupStrDup(env_buffer);
      else
        v = env_buffer;
      break;
    }
  }
}
Esempio n. 11
0
static void iAttribParse(Ihandle *ih, const char* str)
{
  char env_buffer[256];
  char* name=NULL;
  char* value=NULL;
  char state = 'a';               /* get attribute */
  int end = 0;

  env_str = str;

  for (;;)
  {
    switch (iAttribToken(env_buffer))
    {
    case IUPLEX_TK_END:                 /* procedimento igual ao IUPLEX_TK_COMMA */
      end = 1;
    case IUPLEX_TK_COMMA:
      if (name)
      {
        IupStoreAttribute(ih, name, value);
        free(name);
      }
      if (end)
        return;
      name = value = NULL;
      state = 'a';
      break;

    case IUPLEX_TK_SET:
      state = 'v';                /* get value */
      break;

    case IUPLEX_TK_NAME:
      if (state == 'a')
        name = iupStrDup(env_buffer);
      else
        value = env_buffer;
      break;
    }
  }
}
Esempio n. 12
0
static void iMatrixGetInitialValues(Ihandle* ih)
{
  int lin, col;
  char* value;

  for (lin=0; lin<ih->data->lines.num; lin++)
  {
    for (col=0; col<ih->data->columns.num; col++)
    {
      value = iupAttribGetId2(ih, "", lin, col);
      if (value)
      {
        /* get the initial value and remove it from the hash table */

        if (*value)
          ih->data->cells[lin][col].value = iupStrDup(value);

        iupAttribSetId2(ih, "", lin, col, NULL);
      }
    }
  }
}
Esempio n. 13
0
void iupTableSet(Itable *it, const char *key, void *value, Itable_Types itemType)
{
  unsigned int  itemIndex,
                itemFound;
  unsigned long keyIndex;
  ItableEntry  *entry;
  ItableItem   *item;
  void         *v;

  iupASSERT(it!=NULL);
  iupASSERT(key!=NULL);
  if (!it || !key || !value)
    return;

  itemFound = iTableFindItem(it, key, &entry, &itemIndex, &keyIndex);

#ifdef DEBUGTABLE
  if (it->indexType == IUPTABLE_STRINGINDEXED)
    iTableCheckDuplicated(&(entry->items[0]), entry->nextItemIndex, key, keyIndex);
#endif

  if (!itemFound)
  {
    /* create a new item */

    /* first check if the hash table has to be reorganized */
    if (iTableResize(it))
    {
      /* We have to search for the entry again, since it may
       * have been moved by iTableResize. */
      iTableFindItem(it, key, &entry, &itemIndex, &keyIndex);
    }

    iTableUpdateArraySize(entry);

    /* add the item at the end of the item array */
    if (itemType == IUPTABLE_STRING)
      v = iupStrDup(value);
    else
      v = value;

    item = &(entry->items[entry->nextItemIndex]);

    item->itemType     = itemType;
    item->key.keyIndex = keyIndex;
    item->key.keyStr   = it->indexType == IUPTABLE_STRINGINDEXED? iupStrDup(key) : key;
    item->value        = v;

    entry->nextItemIndex++;
    it->numberOfEntries++;
  }
  else
  {
    /* change an existing item */
    void *v;
    item = &(entry->items[itemIndex]);

    if (itemType == IUPTABLE_STRING && item->itemType == IUPTABLE_STRING)
    {
      /* this will avoid to free + alloc of a new pointer */
      if (iupStrEqual((char*)item->value, (char*)value))
        return;
    }

    if (itemType == IUPTABLE_STRING)
      v = iupStrDup(value);
    else
      v = value;

    if (item->itemType == IUPTABLE_STRING)
      free(item->value);

    item->value    = v;
    item->itemType = itemType;
  }
}
Esempio n. 14
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, "...");
  }
}
Esempio n. 15
0
int  iupDataEntry(int    maxlin,
                  int*   maxcol,
                  int*   maxscr,
                  char*  title,
                  char** text,
                  char** data)
{
  int i, bt;
  Ihandle *ok, *cancel, *dlg, *vb, *hb, **txt, **lbl, *button_box, *dlg_box;

  txt = (Ihandle **)calloc(maxlin, sizeof(Ihandle*));
  if (txt == NULL) return -2;
  lbl = (Ihandle **)calloc(maxlin+1, sizeof(Ihandle*));

  vb = IupVbox(NULL);

  for (i=0; i<maxlin; i++)
  {
    txt[i] = IupText(NULL);
    IupSetAttribute(txt[i],"VALUE",data[i]);
    IupSetfAttribute(txt[i],"VISIBLECOLUMNS","%dx", maxscr[i]);
    IupSetfAttribute(txt[i],"NC", "%d", maxcol[i]);
    IupSetAttribute(txt[i],"EXPAND","HORIZONTAL");

    hb = IupHbox(lbl[i] = IupLabel(text[i]), txt[i], NULL);
    IupSetAttribute(hb,"MARGIN","0x0");
    IupSetAttribute(hb,"ALIGNMENT","ACENTER");
    IupAppend(vb, hb);
  }
  lbl[i] = NULL;
  IupInsert(vb, NULL, IupNormalizerv(lbl));

  ok = IupButton("OK", NULL);
  IupSetAttribute(ok, "PADDING", "20x0");
  IupSetCallback(ok, "ACTION", (Icallback)CB_button_OK);

  cancel = IupButton(iupStrMessageGet("IUP_CANCEL"), NULL);
  IupSetAttribute(cancel, "PADDING", "20x0");
  IupSetCallback(cancel, "ACTION", (Icallback)CB_button_CANCEL);

  button_box = IupHbox(
    IupFill(), 
    ok,
    cancel,
    NULL);
  IupSetAttribute(button_box,"MARGIN","0x0");
  IupSetAttribute(button_box, "NORMALIZESIZE", "HORIZONTAL");

  dlg_box = IupVbox(
    IupFrame(vb),
    button_box,
    NULL);
  IupSetAttribute(dlg_box,"MARGIN","10x10");
  IupSetAttribute(dlg_box,"GAP","5");

  dlg = IupDialog(dlg_box);

  IupSetAttribute(dlg,"TITLE",title);
  IupSetAttribute(dlg,"MINBOX","NO");
  IupSetAttribute(dlg,"MAXBOX","NO");
  IupSetAttributeHandle(dlg,"DEFAULTENTER", ok);
  IupSetAttributeHandle(dlg,"DEFAULTESC", cancel);
  IupSetAttribute(dlg,"PARENTDIALOG",IupGetGlobal("PARENTDIALOG"));
  IupSetAttribute(dlg,"ICON", IupGetGlobal("ICON"));

  IupMap(dlg);

  IupSetfAttribute(dlg,"MAXSIZE", "65535x%d", IupGetInt2(dlg, "RASTERSIZE"));
  IupSetAttribute(dlg,"MINSIZE", IupGetAttribute(dlg, "RASTERSIZE"));

  IupPopup(dlg,IUP_CENTER,IUP_CENTER);

  for (i=0; i<maxlin; i++)
  {
    data[i] = (char *)iupStrDup(IupGetAttribute(txt[i], "VALUE"));
  }

  free(txt);

  bt = IupGetInt(dlg, "STATUS");
  IupDestroy(dlg);
  return bt;
}
Esempio n. 16
0
int  iupDataEntry  ( int    maxlin,
                    int    maxcol[],
                    int    maxscr[],
                    const char  *title,
                    const char  **text,
                    char  *data[] )

{
  int i, bt;
  Ihandle *ok, *cancel, *dialog, *vb, *hb, **txt, *button_box, *dlg_box;
  char scroll[20];
  char sizecol[20];

  txt = (Ihandle **) calloc(maxlin, sizeof(Ihandle*));
  if (txt == NULL) return -2;

  vb = IupVbox(NULL);

  for (i=0; i<maxlin; i++)
  {
    sprintf(scroll, "%d", 4*maxscr[i]+4);
    sprintf(sizecol, "%d", maxcol[i]);

    txt[i] = IupText("do_nothing");
    IupSetAttribute(txt[i],IUP_VALUE,data[i]);
    IupStoreAttribute(txt[i],IUP_SIZE,scroll);
    IupStoreAttribute(txt[i],IUP_NC,sizecol);

    hb = IupHbox(IupLabel(text[i]), IupFill(), txt[i],NULL);
    IupSetAttribute(hb,IUP_MARGIN,"0x0");
    IupSetAttribute(hb,IUP_ALIGNMENT,IUP_ACENTER);
    IupAppend(vb, hb);
  }

  ok = IupButton(strok, NULL);
  IupSetAttribute(ok, IUP_SIZE, "50x");
  IupSetCallback(ok, "ACTION", (Icallback)CB_button_OK);
  IupSetHandle("iupDataEntryOkButton", ok);

  cancel = IupButton(strcancel, NULL);
  IupSetAttribute(cancel, IUP_SIZE, "50x");
  IupSetCallback(cancel, "ACTION", (Icallback)CB_button_CANCEL);
  IupSetHandle("iupDataEntryCancelButton", cancel );

  button_box = IupHbox(
    IupSetAttributes(IupFill(), "EXPAND=HORIZONTAL"),
    ok,
    IupSetAttributes(IupFill(), "SIZE=1x"),
    cancel,
    NULL);
  IupSetAttribute(button_box,IUP_MARGIN,"0x0");

  dlg_box = IupVbox(
    IupFrame(vb),
    IupSetAttributes(IupFill(), "SIZE=1x"),
    button_box,
    NULL);
  IupSetAttribute(dlg_box,IUP_MARGIN,"10x10");
  IupSetAttribute(dlg_box,IUP_GAP,"5");

  dialog = IupDialog(dlg_box);

  IupSetAttribute(dialog,IUP_TITLE,title);
  IupSetAttribute(dialog,IUP_MINBOX,IUP_NO);
  IupSetAttribute(dialog,IUP_MAXBOX,IUP_NO);
  IupSetAttribute(dialog,IUP_RESIZE,IUP_NO);
  IupSetAttribute(dialog,IUP_DEFAULTENTER,"iupDataEntryOkButton");
  IupSetAttribute(dialog,IUP_DEFAULTESC,"iupDataEntryCancelButton");
  IupSetAttribute(dialog,IUP_PARENTDIALOG,IupGetGlobal(IUP_PARENTDIALOG));
  IupSetAttribute(dialog,IUP_ICON, IupGetGlobal(IUP_ICON));

  IupPopup(dialog,IUP_CENTER,IUP_CENTER);

  for (i=0; i<maxlin; i++)
  {
    data[i] = (char *)iupStrDup(IupGetAttribute(txt[i], IUP_VALUE));
  }

  free(txt);

  bt = IupGetInt(dialog, IUP_STATUS);
  IupDestroy(dialog);
  return bt;
}
Esempio n. 17
0
static void motTextModifyVerifyCallback(Widget w, Ihandle *ih, XmTextVerifyPtr text)
{
  int start, end, key = 0;
  char *value, *new_value, *insert_value;
  KeySym motcode = 0;
  IFnis cb;

  if (iupAttribGet(ih, "_IUPMOT_DISABLE_TEXT_CB"))
    return;

  if (iupAttribGet(ih, "_IUPMOT_SPIN_DISABLE_TEXT_CB"))
  {
    if (iupAttribGet(ih, "_IUPMOT_SPIN_NOAUTO"))
      text->doit = False;

    iupAttribSetStr(ih, "_IUPMOT_SPIN_DISABLE_TEXT_CB", NULL);
    return;
  }

  cb = (IFnis)IupGetCallback(ih, "ACTION");
  if (!cb && !ih->data->mask)
    return;

  if (text->event && text->event->type == KeyPress)
  {
    unsigned int state = ((XKeyEvent*)text->event)->state;
    if (state & ControlMask ||  /* Ctrl */
        state & Mod1Mask || 
        state & Mod5Mask ||  /* Alt */
        state & Mod4Mask) /* Apple/Win */
      return;

    motcode = XKeycodeToKeysym(iupmot_display, ((XKeyEvent*)text->event)->keycode, 0);
  }

  value = XmTextGetString(ih->handle);
  start = text->startPos;
  end = text->endPos;
  insert_value = text->text->ptr;

  if (motcode == XK_Delete)
  {
    new_value = value;
    iupStrRemove(value, start, end, 1);
  }
  else if (motcode == XK_BackSpace)
  {
    new_value = value;
    iupStrRemove(value, start, end, -1);
  }
  else
  {
    if (!value)
      new_value = iupStrDup(insert_value);
    else if (insert_value)
      new_value = iupStrInsert(value, insert_value, start, end);
    else
      new_value = value;
  }

  if (insert_value && insert_value[0]!=0 && insert_value[1]==0)
    key = insert_value[0];

  if (ih->data->mask && iupMaskCheck(ih->data->mask, new_value)==0)
  {
    if (new_value != value) free(new_value);
    XtFree(value);
    text->doit = False;     /* abort processing */
    return;
  }

  if (cb)
  {
    int cb_ret = cb(ih, key, (char*)new_value);
    if (cb_ret==IUP_IGNORE)
      text->doit = False;     /* abort processing */
    else if (cb_ret==IUP_CLOSE)
    {
      IupExitLoop();
      text->doit = False;     /* abort processing */
    }
    else if (cb_ret!=0 && key!=0 && 
             cb_ret != IUP_DEFAULT && cb_ret != IUP_CONTINUE)  
    {
      insert_value[0] = (char)cb_ret;  /* replace key */
    }
  }

  if (text->doit)
  {
    /* Spin is not automatically updated when you directly edit the text */
    Widget spinbox = (Widget)iupAttribGet(ih, "_IUP_EXTRAPARENT");
    if (spinbox && XmIsSpinBox(spinbox) && !iupAttribGet(ih, "_IUPMOT_SPIN_NOAUTO"))
    {
      int pos;
      if (iupStrToInt(new_value, &pos))
      {
        XmTextPosition caret_pos = text->currInsert;
        iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");
        XtVaSetValues(ih->handle, XmNposition, pos, NULL);
        iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
        /* do not handle all situations, but handle the basic ones */
        if (text->startPos == text->endPos) /* insert */
          caret_pos++;
        else if (text->startPos < text->endPos && text->startPos < text->currInsert)  /* backspace */
          caret_pos--;
        XmTextSetInsertionPosition(ih->handle, caret_pos);
        text->doit = False;
      }
    }
  }

  if (new_value != value) free(new_value);
  XtFree(value);
  (void)w;
}
Esempio n. 18
0
/* Put a text in the screen, using the specified color and alignment.
   Receive the size of cell and also the visible part of the cell,
   because need to clip with this visible part and calculate, correctly,
   the center position and right margin of the cell, using the entire
   size of it.
   -> y1, y2 : vertical limits of the cell
   -> x1, x2 : horizontal limits of the complete cell
   -> xc : point where the text is clipped
   -> alignment : alignment type (horizontal) assigned to the text. The options are:
                  [IMAT_T_CENTER,IMAT_T_LEFT,IMAT_T_RIGHT]
   -> cor : color schema that will be used:
           IMAT_TITLE_COLOR  ->  Black letters in gray background (for the titles)
           IMAT_ELEM_COLOR    -> Letters with FGCOLOR and background with BGCOLOR
           IMAT_REVERSE_COLOR -> Letters with BGCOLOR and background with FGCOLOR
   -> lin, col - cell coordinates, in IUP format - i.e., l,l represents the left
                 top cell of the matrix; lin and col values = 0 represents the
                 title lines and columns.
*/
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, char *text, int alignment, int xc, int cor, int lin, int col)
{
  int oldbgc = -1;
  int ypos;

  int oldx1 = x1,                  /* Full limit of the cell,     */
      oldx2 = x2 - 1,              /* considering the decorations */
      oldy1 = y1,
      oldy2 = y2,
      oldxc = xc;

  /* Create an space between text and cell margin */
  x1 += IMAT_DECOR_X / 2;       x2 -= IMAT_DECOR_X / 2;       xc -= IMAT_DECOR_X / 2;          
  y1 += IMAT_DECOR_Y / 2;       y2 -= IMAT_DECOR_Y / 2;

  /* Clear the cell */
  if(cor == IMAT_TITLE_COLOR)
  {
    oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 0);
    CdBox(oldx1 + 2, oldxc - 2, oldy1 + 2, oldy2 - 2); /* Clear cell box, considering the xc */
  }
  else if(cor == IMAT_ELEM_COLOR)
  {
    oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 0);
    CdBox(oldx1, oldx2, oldy1, oldy2); /* Clear cell box */
  }
  else
  {
    oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 1);
    /* Clear the text box, with the attenuated color... */
    CdBox(oldx1, oldx2, oldy1, oldy2);
    iMatrixDrawSetFgColor(ih, lin, col, 1);
  }

  if(!iMatrixDrawCallDrawCB(ih, cor, lin, col, oldx1, oldx2, oldy1, oldy2))
    return;

  /* Put the text */
  if(text && *text)
  {
    int numl;
    int lineh, totalh, spacing;

    /* Set the clip area to the cell region informed */
    CdClipArea(x1, xc, oldy1, oldy2);
    cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA);

    /* Set the color used to draw the text */
    if((lin > 0 && ih->data->lin.inactive[lin-1]) ||
       (col > 0 && ih->data->col.inactive[col-1]) ||
       !IupGetInt(ih, "ACTIVE"))
      cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_COLOR);
    else if(cor == IMAT_ELEM_COLOR)
      iMatrixDrawSetFgColor(ih, lin, col, 0);
    else if(cor == IMAT_REVERSE_COLOR)
      oldbgc = iMatrixDrawSetFgColor(ih, lin, col, 1);
    else
      iMatrixDrawSetFgColor(ih, lin, col, 0);

    numl = iupMatrixAuxTextHeight(ih, text, &totalh, &lineh, &spacing);

    iMatrixDrawSetFont(ih, lin, col);

    if(numl == 1)
    {
      ypos = (int)((y1 + y2) / 2.0 - .5);

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

      if(text != NULL)
      {
        p = (char*) iupStrDup(text);
        newtext = p;
      }
      else
        p = NULL;

      /* Get the position of the first text to be put in the screen */
      ypos = (int)( (y1 + y2) / 2.0 - .5) - totalh / 2 + lineh / 2;
      for(i = 0; i < numl; i++)
      {
        q = strchr(p, '\n');
        if(q)
          *q = 0;  /* Cut the string to contain a line */

        /* Put the text */
        if(alignment == IMAT_T_CENTER)
          CdPutText((x1 + x2) / 2, ypos, p, CD_CENTER);
        else if(alignment == IMAT_T_LEFT)
          CdPutText(x1, ypos, p, CD_WEST);
        else
          CdPutText(x2, ypos, p, CD_EAST);

        if(q)
          *q = '\n'; /* Restore the string */
        p = q + 1;

        /* Advance a line */
        ypos += lineh + spacing;
      }

      if(newtext)
        free(newtext);
    }

    cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF);
  }

  if(cor != IMAT_TITLE_COLOR)
    CdRestoreBgColor();
}
Esempio n. 19
0
static int iMatrixSetSortColumnAttrib(Ihandle* ih, int col, const char* value)
{
  int lines_num = ih->data->lines.num;
  int lin, lin1=1, lin2=lines_num-1;   /* ALL */
  int ascending;
  int* sort_line_index;
  IFniii sort_cb;

  /* Notice that sort_line_index[0] is always 0 */

  if (!ih->data->sort_line_index)
    ih->data->sort_line_index = (int*)calloc(ih->data->lines.num_alloc, sizeof(int));

  sort_line_index = ih->data->sort_line_index;

  if (!ih->data->sort_has_index)
  {
    for (lin = 0; lin < lines_num; lin++)
      sort_line_index[lin] = lin;
  }

  if (iupStrEqualNoCase(value, "RESET"))
  {
    ih->data->sort_has_index = 0;
    iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, NULL);
    ih->data->last_sort_col = 0;

    iupMatrixDraw(ih, 1);
    iupAttribSet(ih, "SORTCOLUMNINTERVAL", NULL);
    return 0;
  }

  if (iupStrEqualNoCase(value, "INVERT"))
  {
    int l1, l2;

    if (!ih->data->sort_has_index)
      return 0;

    IupGetIntInt(ih, "SORTCOLUMNINTERVAL", &lin1, &lin2);

    for (l1=lin1,l2=lin2; l1<l2; ++l1,--l2)
    {
      int tmp = sort_line_index[l1];
      sort_line_index[l1] = sort_line_index[l2];
      sort_line_index[l2] = tmp;
    }

    if (iupStrEqualNoCase(iupAttribGetId(ih, "SORTSIGN", ih->data->last_sort_col), "UP"))
      iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, "DOWN");
    else
      iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, "UP");

    iupMatrixDraw(ih, 1);
    return 0;
  }

  if (!iupMATRIX_CHECK_COL(ih, col))
    return 0;

  if (!iupStrEqualNoCase(value, "ALL"))
    iupStrToIntInt(value, &lin1, &lin2, '-');

  iupAttribSetStrf(ih, "SORTCOLUMNINTERVAL", "%d,%d", lin1, lin2);

  if (lin1 < 1) lin1 = 1;
  if (lin2 < lin1) lin2 = lin1;

  ascending = iupStrEqualNoCase(iupAttribGetStr(ih, "SORTCOLUMNORDER"), "ASCENDING");
  
  sort_cb = (IFniii)IupGetCallback(ih, "SORTCOLUMNCOMPARE_CB");
  if (sort_cb)
  {
    iMatrixQSort_sort_cb = sort_cb;
    iMatrixQSort_ih = ih;
    iMatrixQSort_col = col;
    qsort(sort_line_index+lin1,lin2-lin1+1,sizeof(int),iMatrixCompareCallbackFunc);
  }
  else
  {
    if (ih->data->numeric_columns && ih->data->numeric_columns[col].flags & IMAT_IS_NUMERIC)
    {
      ImatSortNumber* sort_line_number = (ImatSortNumber*)malloc((lin2-lin1+1)*sizeof(ImatSortNumber));

      for (lin=lin1; lin<=lin2; lin++)
      {
        sort_line_number[lin-lin1].lin = sort_line_index[lin];
        sort_line_number[lin-lin1].number = iupMatrixGetValueNumeric(ih, lin, col);
      }

      qsort(sort_line_number,lin2-lin1+1,sizeof(ImatSortNumber), iMatrixCompareNumberFunc);

      for (lin=lin1; lin<=lin2; lin++)
      {
        if (ascending)
          sort_line_index[lin] = sort_line_number[lin-lin1].lin;
        else
          sort_line_index[lin2 - (lin-lin1)] = sort_line_number[lin-lin1].lin;
      }

      free(sort_line_number);
    }
    else
    {
      ImatSortText* sort_line_text = (ImatSortText*)malloc((lin2-lin1+1)*sizeof(ImatSortText));

      for (lin=lin1; lin<=lin2; lin++)
      {
        sort_line_text[lin-lin1].lin = sort_line_index[lin];
        sort_line_text[lin-lin1].text = iupMatrixGetValueDisplay(ih, lin, col);

        if (ih->data->callback_mode)
          sort_line_text[lin-lin1].text = iupStrDup(sort_line_text[lin-lin1].text);
      }

      iMatrixQSort_utf8 = IupGetInt(NULL, "UTF8MODE");
      iMatrixQSort_casesensitive = iupAttribGetInt(ih, "SORTCOLUMNCASESENSITIVE");
      qsort(sort_line_text,lin2-lin1+1,sizeof(ImatSortText), iMatrixCompareTextFunc);

      for (lin=lin1; lin<=lin2; lin++)
      {
        if (ascending)
          sort_line_index[lin] = sort_line_text[lin-lin1].lin;
        else
          sort_line_index[lin2 - (lin-lin1)] = sort_line_text[lin-lin1].lin;

        if (ih->data->callback_mode && sort_line_text[lin-lin1].text)
          free(sort_line_text[lin-lin1].text);
      }

      free(sort_line_text);
    }
  }

  iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, NULL);
  if (ascending)
    iupAttribSetId(ih, "SORTSIGN", col, "DOWN");
  else
    iupAttribSetId(ih, "SORTSIGN", col, "UP");

  ih->data->sort_has_index = 1;
  ih->data->last_sort_col = col;
  iupMatrixDraw(ih, 1);
  return 0;
}
Esempio n. 20
0
static int winFileDlgPopup(Ihandle *ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  OPENFILENAME openfilename;
  int result, dialogtype;
  char *value, *initial_dir=NULL;
  TCHAR* extfilter = NULL;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  value = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(value, "SAVE"))
    dialogtype = IUP_DIALOGSAVE;
  else if (iupStrEqualNoCase(value, "DIR"))
    dialogtype = IUP_DIALOGDIR;
  else
    dialogtype = IUP_DIALOGOPEN;

  if (dialogtype == IUP_DIALOGDIR)
  {
    winFileDlgGetFolder(ih);
    return IUP_NOERROR;
  }

  /* if NOT set will NOT be Modal */
  /* anyway it will be modal only relative to its parent */
  if (!parent)
    parent = GetActiveWindow();

  ZeroMemory(&openfilename, sizeof(OPENFILENAME));
  openfilename.lStructSize = sizeof(OPENFILENAME);
  openfilename.hwndOwner = parent;

  value = iupAttribGet(ih, "EXTFILTER");
  if (value)
  {
    int index;
    extfilter = winFileDlgStrReplaceSeparator(iupwinStrToSystem(value));
    openfilename.lpstrFilter = extfilter;

    value = iupAttribGet(ih, "FILTERUSED");
    if (iupStrToInt(value, &index))
      openfilename.nFilterIndex = index;
    else
      openfilename.nFilterIndex = 1;
  }
  else 
  {
    value = iupAttribGet(ih, "FILTER");
    if (value)
    {
      TCHAR *winfo, *wvalue;
      int sz1, sz2;
      char* info = iupAttribGet(ih, "FILTERINFO");
      if (!info)
        info = value;

      winfo = iupwinStrToSystem(info);
      wvalue = iupwinStrToSystem(value);

      /* concat FILTERINFO+FILTER */
      sz1 = lstrlen(winfo)+1; /* each part has a terminator */
      sz2 = lstrlen(wvalue)+1;
      extfilter = (TCHAR*)malloc((sz1+sz2+1)*sizeof(TCHAR));
      memcpy(extfilter, winfo, sz1*sizeof(TCHAR)); /* copy also the terminator */
      memcpy(extfilter+sz1, wvalue, sz2*sizeof(TCHAR));
      extfilter[sz1+sz2] = 0;  /* additional terminator at the end */

      openfilename.lpstrFilter = extfilter;
      openfilename.nFilterIndex = 1;
    }
  }

  openfilename.lpstrFile = (TCHAR*)malloc((IUP_MAX_FILENAME_SIZE+1)*sizeof(TCHAR));
  value = iupAttribGet(ih, "FILE");
  if (value)
  {
    iupwinStrCopy(openfilename.lpstrFile, value, IUP_MAX_FILENAME_SIZE);
    winFileDlgStrReplacePathSlash(openfilename.lpstrFile);
  }
  else
    openfilename.lpstrFile[0] = 0;

  openfilename.nMaxFile = IUP_MAX_FILENAME_SIZE;

  /* only supports extensions with up to three characters, should NOT include the period */
  openfilename.lpstrDefExt = iupwinStrToSystem(iupAttribGet(ih, "EXTDEFAULT"));

  initial_dir = iupStrDup(iupAttribGet(ih, "DIRECTORY"));
  openfilename.lpstrInitialDir = iupwinStrToSystemFilename(initial_dir);
  if (openfilename.lpstrInitialDir)
    winFileDlgStrReplacePathSlash((TCHAR*)openfilename.lpstrInitialDir);

  openfilename.lpstrTitle = iupwinStrToSystem(iupAttribGet(ih, "TITLE"));
  openfilename.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;

  if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT"))
    openfilename.Flags |= OFN_OVERWRITEPROMPT;

  if (iupAttribGetBoolean(ih, "SHOWHIDDEN"))
    openfilename.Flags |= OFN_FORCESHOWHIDDEN;

  value = iupAttribGet(ih, "ALLOWNEW");
  if (!value)
  {
    if (dialogtype == IUP_DIALOGSAVE)
      value = "YES";
    else
      value = "NO";
  }
  if (iupStrBoolean(value))
    openfilename.Flags |= OFN_CREATEPROMPT;
  else
    openfilename.Flags |= OFN_FILEMUSTEXIST;

  if (iupAttribGetBoolean(ih, "NOCHANGEDIR"))
    openfilename.Flags |= OFN_NOCHANGEDIR;

  if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
     openfilename.Flags |= OFN_ALLOWMULTISELECT;

  openfilename.lpfnHook = winFileDlgSimpleHook;
  openfilename.Flags |= OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING;
  openfilename.lCustData = (LPARAM)ih;

  if (iupAttribGetBoolean(ih, "SHOWPREVIEW") && IupGetCallback(ih, "FILE_CB"))
  {
    openfilename.Flags |= OFN_ENABLETEMPLATE;
    openfilename.hInstance = iupwin_dll_hinstance? iupwin_dll_hinstance: iupwin_hinstance;
    openfilename.lpTemplateName = TEXT("iupPreviewDlg");
    openfilename.lpfnHook = winFileDlgPreviewHook;
  }

  if (IupGetCallback(ih, "HELP_CB"))
    openfilename.Flags |= OFN_SHOWHELP;

  if (dialogtype == IUP_DIALOGOPEN)
    result = GetOpenFileName(&openfilename);
  else
    result = GetSaveFileName(&openfilename);

  if (result)
  {
    if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
    {
      /* If there is more than one file, replace terminator by the separator */
      if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && 
          openfilename.nFileOffset>0) 
      {
        int i = 0;
        int count = 0;

        char* dir = iupwinStrFromSystemFilename(openfilename.lpstrFile);  /* already is the directory, but without the last separator */
        iupAttribSetStrf(ih, "DIRECTORY", "%s\\", dir);  /* add the last separator */

        /* first the path */
        iupAttribSetStrId(ih, "MULTIVALUE", count, iupAttribGet(ih, "DIRECTORY"));  /* here count=0 always */
        count++;

        while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i + 1] != 0)
        {
          if (openfilename.lpstrFile[i] == 0)
          {
            iupAttribSetStrId(ih, "MULTIVALUE", count, iupwinStrFromSystemFilename(openfilename.lpstrFile + i + 1));
            count++;

            openfilename.lpstrFile[i] = TEXT('|');
          }

          i++;
        }

        iupAttribSetInt(ih, "MULTIVALUECOUNT", count);
        openfilename.lpstrFile[i] = TEXT('|');  /* one last at the end */

        iupAttribSetStr(ih, "VALUE", iupwinStrFromSystemFilename(openfilename.lpstrFile));  /* here file was already modified to match the IUP format */
      }
      else
      {
        /* if there is only one file selected the returned value is different 
           and includes just that file */
        char* filename = iupwinStrFromSystemFilename(openfilename.lpstrFile);
        char* dir = iupStrFileGetPath(filename);
        int dir_len = (int)strlen(dir);
        iupAttribSetStr(ih, "DIRECTORY", dir);

        iupAttribSetStrId(ih, "MULTIVALUE", 0, dir);
        iupAttribSetStrId(ih, "MULTIVALUE", 1, filename + dir_len);

        iupAttribSetStr(ih, "VALUE", filename);  /* here value is not separated by '|' */

        iupAttribSetInt(ih, "MULTIVALUECOUNT", 2);
        free(dir);
      }

      iupAttribSet(ih, "STATUS", "0");
      iupAttribSet(ih, "FILEEXIST", "YES");
    }
    else
    {
      char* filename = iupwinStrFromSystemFilename(openfilename.lpstrFile);
      char* dir = iupStrFileGetPath(filename);
      iupAttribSetStr(ih, "DIRECTORY", dir);
      free(dir);

      if (winIsFile(openfilename.lpstrFile))  /* check if file exists */
      {
        iupAttribSet(ih, "FILEEXIST", "YES");
        iupAttribSet(ih, "STATUS", "0");
      }
      else
      {
        iupAttribSet(ih, "FILEEXIST", "NO");
        iupAttribSet(ih, "STATUS", "1");
      }

      iupAttribSetStr(ih, "VALUE", filename);
    }

    iupAttribSetInt(ih, "FILTERUSED", (int)openfilename.nFilterIndex);
  }
  else
  {
    iupAttribSet(ih, "FILTERUSED", NULL);
    iupAttribSet(ih, "VALUE", NULL);
    iupAttribSet(ih, "DIRECTORY", NULL);
    iupAttribSet(ih, "FILEEXIST", NULL);
    iupAttribSet(ih, "STATUS", "-1");
  }

  if (extfilter) free(extfilter);
  if (initial_dir) free(initial_dir);
  if (openfilename.lpstrFile) free(openfilename.lpstrFile);

  return IUP_NOERROR;
}
Esempio n. 21
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];
}
Esempio n. 22
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, "...");
        }
    }
}
Esempio n. 23
0
int IupAlarm (const char *title, const char *m, const char *b1, const char *b2, const char *b3)
{
  Ihandle  *dialog, *dlg_box, *lbl_box, *botoes, *button;
  char *aux, *linha, *default_esc;
  int i, bt, wb;
  char button_size[10];

  m = m ? m : "";

  if (b1 == NULL)
    return 0;

  aux=(char *)iupStrDup(m);
  if (aux == NULL)
    return 0;

  lbl_box = IupVbox(NULL);
  IupSetAttribute(lbl_box,IUP_MARGIN,"0x0");
  IupSetAttribute(lbl_box,IUP_GAP,"0");
  IupSetAttribute(lbl_box,IUP_ALIGNMENT, IUP_ACENTER);

  for (i=0,linha=aux; linha[i]; ++i)
  {
    if (linha[i] == '\n')
    {
      linha[i] = '\0';
      IupAppend(lbl_box,IupHbox(IupFill(),IupLabel(linha),IupFill(),NULL));
      linha=&linha[i+1];
      i=-1;
    }
  }

  if (*linha)
    IupAppend(lbl_box,IupHbox(IupFill(),IupLabel(linha),IupFill(),NULL));

  botoes = IupHbox(NULL);

  button = IupButton(b1, NULL);
  IupSetHandle("IupAlarmButton1", button );
  IupSetAttribute(button, "_BUTTON_NUMBER", "1");
  IupAppend(botoes, IupFill());
  IupAppend(botoes, button);
  IupSetCallback (button, "ACTION", (Icallback)CB_button);
  default_esc = "IupAlarmButton1";

  if (b2 != NULL)
  {
    button = IupButton(b2, NULL);
    IupSetHandle( "IupAlarmButton2", button );
    IupSetAttribute(button, "_BUTTON_NUMBER", "2");
    IupAppend(botoes, IupFill());
    IupAppend(botoes, button);
    IupSetCallback (button, "ACTION", (Icallback)CB_button);
    default_esc = "IupAlarmButton2";
  }

  if (b3 != NULL)
  {
    button   = IupButton(b3, NULL);
    IupSetHandle( "IupAlarmButton3", button );
    IupSetAttribute(button, "_BUTTON_NUMBER", "3");
    IupAppend(botoes, IupFill());
    IupAppend(botoes, button);
    IupSetCallback (button, "ACTION", (Icallback)CB_button);
    default_esc = "IupAlarmButton3";
  }

  IupAppend(botoes, IupFill());

  dlg_box = IupVbox (
    IupSetAttributes(IupFill(), "SIZE=1x"),
    lbl_box,
    IupSetAttributes(IupFill(), "SIZE=1x"),
    botoes,
    NULL);

  IupSetAttribute(dlg_box,IUP_MARGIN,"10x10");
  IupSetAttribute(dlg_box,IUP_GAP,"5");

  dialog = IupDialog(dlg_box);

  IupSetAttribute(dialog,IUP_TITLE,title ? title : "");
  IupSetAttribute(dialog,IUP_MINBOX ,IUP_NO);
  IupSetAttribute(dialog,IUP_MAXBOX ,IUP_NO);
  IupSetAttribute(dialog,IUP_RESIZE ,IUP_NO);
  IupSetAttribute(dialog,IUP_DEFAULTENTER,"IupAlarmButton1");
  IupSetAttribute(dialog,IUP_DEFAULTESC,default_esc);
  IupSetAttribute(dialog, IUP_PARENTDIALOG, IupGetGlobal(IUP_PARENTDIALOG));
  IupSetAttribute(dialog, IUP_ICON, IupGetGlobal(IUP_ICON));

  IupMap(dialog);

  wb = IupGetInt(IupGetHandle("IupAlarmButton1"), IUP_SIZE);

  if (b2 != NULL)
  {
    int wb2 = IupGetInt(IupGetHandle("IupAlarmButton2"), IUP_SIZE);
    if(wb2 > wb) wb = wb2;
  }
  if (b3 != NULL)
  {
    int wb3 = IupGetInt(IupGetHandle("IupAlarmButton3"), IUP_SIZE);
    if(wb3 > wb) wb = wb3;
  }

  sprintf(button_size, "%dx", wb);

  IupSetAttribute(IupGetHandle("IupAlarmButton1"), IUP_SIZE, button_size);
  IupSetAttribute(IupGetHandle("IupAlarmButton2"), IUP_SIZE, button_size);
  IupSetAttribute(IupGetHandle("IupAlarmButton3"), IUP_SIZE, button_size);

  /* Force to calculate dialog's size again. */
  IupSetAttribute(dialog, IUP_RASTERSIZE, 0);

  IupPopup(dialog,IUP_CENTER,IUP_CENTER);

  bt = IupGetInt(dialog, "_BUTTON_NUMBER");

  IupDestroy(dialog);
  free(aux);

  return bt;
}
Esempio n. 24
0
static int winFileDlgPopup(Ihandle *ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  OPENFILENAME openfilename;
  int result, dialogtype;
  char *value;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  value = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(value, "SAVE"))
    dialogtype = IUP_DIALOGSAVE;
  else if (iupStrEqualNoCase(value, "DIR"))
    dialogtype = IUP_DIALOGDIR;
  else
    dialogtype = IUP_DIALOGOPEN;

  if (dialogtype == IUP_DIALOGDIR)
  {
    winFileDlgGetFolder(ih);
    return IUP_NOERROR;
  }

  if (!parent)
    parent = GetActiveWindow();  /* if NOT set will NOT be Modal */
                                 /* anyway it will be modal only relative to its parent */

  ZeroMemory(&openfilename, sizeof(OPENFILENAME));
  openfilename.lStructSize = sizeof(OPENFILENAME);
  openfilename.hwndOwner = parent;

  value = iupAttribGet(ih, "EXTFILTER");
  if (value)
  {
    int index;
    openfilename.lpstrFilter = winFileDlgStrReplaceSeparator(value);

    value = iupAttribGet(ih, "FILTERUSED");
    if (iupStrToInt(value, &index))
      openfilename.nFilterIndex = index;
    else
      openfilename.nFilterIndex = 1;
  }
  else 
  {
    value = iupAttribGet(ih, "FILTER");
    if (value)
    {
      int sz1, sz2;
      char* info = iupAttribGet(ih, "FILTERINFO");
      if (!info)
        info = value;

      /* concat FILTERINFO+FILTER */
      sz1 = strlen(info)+1;
      sz2 = strlen(value)+1;
      openfilename.lpstrFilter = (char*)malloc(sz1+sz2+1);
      memcpy((char*)openfilename.lpstrFilter, info, sz1);
      memcpy((char*)openfilename.lpstrFilter+sz1, value, sz2);
      ((char*)openfilename.lpstrFilter)[sz1+sz2] = 0; /* additional 0 at the end */

      openfilename.nFilterIndex = 1;
    }
  }

  openfilename.lpstrFile = (char*)malloc(IUP_MAX_FILENAME_SIZE+1);
  value = iupAttribGet(ih, "FILE");
  if (value)
  {
    strncpy(openfilename.lpstrFile, value, IUP_MAX_FILENAME_SIZE);
    winFileDlgStrReplacePathSlash(openfilename.lpstrFile);
  }
  else
    openfilename.lpstrFile[0] = 0;

  openfilename.nMaxFile = IUP_MAX_FILENAME_SIZE;

  openfilename.lpstrInitialDir = iupStrDup(iupAttribGet(ih, "DIRECTORY"));
  if (openfilename.lpstrInitialDir)
    winFileDlgStrReplacePathSlash((char*)openfilename.lpstrInitialDir);

  openfilename.lpstrTitle = iupAttribGet(ih, "TITLE");
  openfilename.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;

  if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT"))
    openfilename.Flags |= OFN_OVERWRITEPROMPT;

  if (iupAttribGetBoolean(ih, "SHOWHIDDEN"))
    openfilename.Flags |= OFN_FORCESHOWHIDDEN;

  value = iupAttribGet(ih, "ALLOWNEW");
  if (!value)
  {
    if (dialogtype == IUP_DIALOGSAVE)
      value = "YES";
    else
      value = "NO";
  }
  if (iupStrBoolean(value))
    openfilename.Flags |= OFN_CREATEPROMPT;
  else
    openfilename.Flags |= OFN_FILEMUSTEXIST;

  if (iupAttribGetBoolean(ih, "NOCHANGEDIR"))
    openfilename.Flags |= OFN_NOCHANGEDIR;

  if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
     openfilename.Flags |= OFN_ALLOWMULTISELECT;

  openfilename.lpfnHook = winFileDlgSimpleHook;
  openfilename.Flags |= OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING;
  openfilename.lCustData = (LPARAM)ih;

  if (iupAttribGetBoolean(ih, "SHOWPREVIEW") && IupGetCallback(ih, "FILE_CB"))
  {
    openfilename.Flags |= OFN_ENABLETEMPLATE;
    openfilename.hInstance = iupwin_dll_hinstance? iupwin_dll_hinstance: iupwin_hinstance;
    openfilename.lpTemplateName = "iupPreviewDlg";
    openfilename.lpfnHook = winFileDlgPreviewHook;
  }

  if (IupGetCallback(ih, "HELP_CB"))
    openfilename.Flags |= OFN_SHOWHELP;

  if (dialogtype == IUP_DIALOGOPEN)
    result = GetOpenFileName(&openfilename);
  else
    result = GetSaveFileName(&openfilename);

  if (result)
  {
    if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
    {
      int i = 0;

      char* dir = iupStrFileGetPath(openfilename.lpstrFile);  /* the first part is the directory already */
      iupAttribStoreStr(ih, "DIRECTORY", dir);
      free(dir);
    
      /* If there is more than one file, replace terminator by the separator */
      if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && 
          openfilename.nFileOffset>0) 
      {
        while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i+1] != 0)
        {
          if (openfilename.lpstrFile[i]==0)
            openfilename.lpstrFile[i] = '|';
          i++;
        }
        openfilename.lpstrFile[i] = '|';
      }

      iupAttribSetStr(ih, "STATUS", "0");
      iupAttribSetStr(ih, "FILEEXIST", "YES");
    }
    else
    {
      if (iupdrvIsFile(openfilename.lpstrFile))  /* check if file exists */
      {
        char* dir = iupStrFileGetPath(openfilename.lpstrFile);
        iupAttribStoreStr(ih, "DIRECTORY", dir);
        free(dir);

        iupAttribSetStr(ih, "FILEEXIST", "YES");
        iupAttribSetStr(ih, "STATUS", "0");
      }
      else
      {
        iupAttribSetStr(ih, "FILEEXIST", "NO");
        iupAttribSetStr(ih, "STATUS", "1");
      }
    }

    iupAttribStoreStr(ih, "VALUE", openfilename.lpstrFile);
    iupAttribSetInt(ih, "FILTERUSED", (int)openfilename.nFilterIndex);
  }
  else
  {
    iupAttribSetStr(ih, "FILTERUSED", NULL);
    iupAttribSetStr(ih, "VALUE", NULL);
    iupAttribSetStr(ih, "FILEEXIST", NULL);
    iupAttribSetStr(ih, "STATUS", "-1");
  }

  if (openfilename.lpstrFilter) free((char*)openfilename.lpstrFilter);
  if (openfilename.lpstrInitialDir) free((char*)openfilename.lpstrInitialDir);
  if (openfilename.lpstrFile) free(openfilename.lpstrFile);

  return IUP_NOERROR;
}
Esempio n. 25
0
static void motListEditModifyVerifyCallback(Widget cbedit, Ihandle *ih, XmTextVerifyPtr text)
{
  int start, end, key = 0;
  char *value, *new_value, *insert_value;
  KeySym motcode = 0;
  IFnis cb;

  if (iupAttribGet(ih, "_IUPMOT_DISABLE_TEXT_CB"))
    return;

  if (text->event && text->event->type == KeyPress)
  {
    unsigned int state = ((XKeyEvent*)text->event)->state;
    if (state & ControlMask ||  /* Ctrl */
        state & Mod1Mask || state & Mod5Mask ||  /* Alt */
        state & Mod4Mask) /* Apple/Win */
    {
      text->doit = False;     /* abort processing */
      return;
    }

    motcode = iupmotKeycodeToKeysym(((XKeyEvent*)text->event)->keycode);
  }

  cb = (IFnis)IupGetCallback(ih, "EDIT_CB");
  if (!cb && !ih->data->mask)
    return;

  value = XmTextFieldGetString(cbedit);
  start = text->startPos;
  end = text->endPos;
  insert_value = text->text->ptr;

  if (motcode == XK_Delete)
  {
    new_value = value;
    iupStrRemove(value, start, end, 1);
  }
  else if (motcode == XK_BackSpace)
  {
    new_value = value;
    iupStrRemove(value, start, end, -1);
  }
  else
  {
    if (!value)
      new_value = iupStrDup(insert_value);
    else if (insert_value)
      new_value = iupStrInsert(value, insert_value, start, end);
    else
      new_value = value;
  }

  if (insert_value && insert_value[0]!=0 && insert_value[1]==0)
    key = insert_value[0];

  if (ih->data->mask && iupMaskCheck(ih->data->mask, new_value)==0)
  {
    if (new_value != value) free(new_value);
    XtFree(value);
    text->doit = False;     /* abort processing */
    return;
  }

  if (cb)
  {
    int cb_ret = cb(ih, key, (char*)new_value);
    if (cb_ret==IUP_IGNORE)
      text->doit = False;     /* abort processing */
    else if (cb_ret==IUP_CLOSE)
    {
      IupExitLoop();
      text->doit = False;     /* abort processing */
    }
    else if (cb_ret!=0 && key!=0 && 
             cb_ret != IUP_DEFAULT && cb_ret != IUP_CONTINUE)  
    {
      insert_value[0] = (char)cb_ret;  /* replace key */
    }
  }

  if (new_value != value) free(new_value);
  XtFree(value);
}
Esempio n. 26
0
void iupmotCBlist (Widget w, XtPointer client_data, XtPointer call_data)
{
   IFns ms_cb;
   IFnsii cb;
   Iwidgetdata *d = NULL;
   Ihandle *n;
 
   if (iupmot_incallback) return;

   XtVaGetValues (w, XmNuserData, &d, NULL);
   if (!d) return;
   n = d->ihandle;

   if (n == NULL) return;

   cb = (IFnsii) IupGetCallback(n,IUP_ACTION);
   ms_cb = (IFns)IupGetCallback(n,"MULTISELECT_CB");
   if (cb || ms_cb)
   {
      char opstr[10];
      char *old_pos;
      int option;
      int old_opt;
      char *str, *old_str;

      if (XtClass(w) == xmComboBoxWidgetClass)
      {
         option = ((XmComboBoxCallbackStruct*)call_data)->item_position;
      }
      else /* XmList */
      {
         XmListCallbackStruct *data = (XmListCallbackStruct *)call_data;
         option = data->item_position;

         if (data->reason != XmCR_BROWSE_SELECT)
         {
            /* Multiple */
            int pos = 0;
            char *old_value = iupGetEnv(n, "_IUPMOT_LISTOLDVALUE");
            if (ms_cb)
            {
              char *ms_value = iupStrDup(IupGetAttribute(n, IUP_VALUE));
              if (old_value)
              {
                while(ms_value[pos] != '\0')
                {
                  if(ms_value[pos] == old_value[pos])
                    ms_value[pos] = 'x';    /* mark unchanged values */
                  pos++;
                }
              }

              iupmot_incallback = TRUE;
              if (ms_cb(n, ms_value) == IUP_CLOSE)
                iupmot_exitmainloop = 1;
              iupmot_incallback = FALSE;

              iupStoreEnv(n, "_IUPMOT_LISTOLDVALUE", IupGetAttribute(n, IUP_VALUE));
              free(ms_value);
              return;
            }
            else
            {
              char *new_value = iupStrDup(IupGetAttribute(n, IUP_VALUE));

              /* call list callback for each changed item */
              while(new_value[pos] != '\0')
              {
                int select = 0;

                if(!old_value && new_value[pos] == '+')
                  select = 1;
                else if(old_value && new_value[pos] == '+' &&
                                     old_value[pos] == '-')
                  select = 1;
                else if(old_value && new_value[pos] == '-' &&
                                     old_value[pos] == '+')
                  select = 0;
                else
                {
                  pos++;
                  continue;
                }

                sprintf(opstr, "%d", pos+1);
                str = iupGetEnv(n, opstr);

                iupmot_incallback = TRUE;
                if (cb(n, str, pos+1, select) == IUP_CLOSE)
                {
                  iupmot_exitmainloop = 1;
                  break;
                }
                iupmot_incallback = FALSE;

                pos++;
              }

              iupStoreEnv(n, "_IUPMOT_LISTOLDVALUE", new_value);
              free(new_value);
              return;
            }
         }
      }

      if (!cb) return;
     
      if (!iupStrEqualNoCase(IupGetAttribute(n, IUP_MULTIPLE), IUP_YES))
      {
        old_pos = iupGetEnv(n, "_IUPMOT_PREV_LIST_POS");
        if (!old_pos) old_pos = "1";
        sscanf(old_pos, "%d", &old_opt);
        old_str = iupGetEnv(n, old_pos);
        iupmot_incallback = TRUE;
        if (cb(n, old_str, old_opt, 0) == IUP_CLOSE)
           iupmot_exitmainloop = 1;
        iupmot_incallback = FALSE;
        
        sprintf(opstr, "%d", option);
        iupStoreEnv(n, "_IUPMOT_PREV_LIST_POS", opstr);
      }

      sprintf(opstr, "%d", option);
      str = iupGetEnv(n, opstr);

      iupmot_incallback = TRUE;
      if (cb(n, str, option, 1) == IUP_CLOSE)
        iupmot_exitmainloop = 1;
      iupmot_incallback = FALSE;
   }
}
Esempio n. 27
0
static int gtkListCallEditCb(Ihandle* ih, GtkEditable *editable, const char* insert_value, int len, int start, int end)
{
  char *new_value, *value;
  int ret = -1, key = 0;

  IFnis cb = (IFnis)IupGetCallback(ih, "EDIT_CB");
  if (!cb && !ih->data->mask)
    return -1; /* continue */

  value = iupStrGetMemoryCopy(iupgtkStrConvertFromUTF8(gtk_entry_get_text(GTK_ENTRY(editable))));

  if (!insert_value)
  {
    new_value = iupStrDup(value);
    if (end<0) end = strlen(value)+1;
    iupStrRemove(new_value, start, end, 1);
  }
  else
  {
    if (!value)
      new_value = iupStrDup(insert_value);
    else
    {
      if (len < end-start)
      {
        new_value = iupStrDup(value);
        new_value = iupStrInsert(new_value, insert_value, start, end);
      }
      else
        new_value = iupStrInsert(value, insert_value, start, end);
    }
  }

  if (insert_value && insert_value[0]!=0 && insert_value[1]==0)
    key = insert_value[0];

  if (!new_value)
    return -1; /* continue */

  if (ih->data->nc && (int)strlen(new_value) > ih->data->nc)
  {
    if (new_value != value) free(new_value);
    return 0; /* abort */
  }

  if (ih->data->mask && iupMaskCheck(ih->data->mask, new_value)==0)
  {
    if (new_value != value) free(new_value);
    return 0; /* abort */
  }

  if (cb)
  {
    int cb_ret = cb(ih, key, (char*)new_value);
    if (cb_ret==IUP_IGNORE)
      ret = 0; /* abort */
    else if (cb_ret==IUP_CLOSE)
    {
      IupExitLoop();
      ret = 0; /* abort */
    }
    else if (cb_ret!=0 && key!=0 && 
             cb_ret != IUP_DEFAULT && cb_ret != IUP_CONTINUE)  
      ret = cb_ret; /* abort and replace */
  }

  if (new_value != value) free(new_value);
  return ret; /* continue */
}
Esempio n. 28
0
static int gtkFileDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkWidget* dialog;
  GtkWidget* preview_canvas = NULL;
  GtkFileChooserAction action;
  IFnss file_cb;
  char* value;
  int response, filter_count = 0;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  value = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(value, "SAVE"))
    action = GTK_FILE_CHOOSER_ACTION_SAVE;
  else if (iupStrEqualNoCase(value, "DIR"))
    action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
  else
    action = GTK_FILE_CHOOSER_ACTION_OPEN;

  value = iupAttribGet(ih, "TITLE");
  if (!value)
  {
    GtkStockItem item;

    if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
      value = GTK_STOCK_SAVE_AS;
    else
      value = GTK_STOCK_OPEN;

    gtk_stock_lookup(value, &item);
    value = item.label;

    iupAttribStoreStr(ih, "TITLE", iupgtkStrConvertFromUTF8(value));
    value = iupAttribGet(ih, "TITLE");
    iupStrRemoveChar(value, '_');
  }

  dialog = gtk_file_chooser_dialog_new(iupgtkStrConvertToUTF8(value), (GtkWindow*)parent, action, 
                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
                                       NULL);
  if (!dialog)
    return IUP_ERROR;

  if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_SAVE, GTK_RESPONSE_OK);
  else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_OK);
  else
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_OK);

  if (IupGetCallback(ih, "HELP_CB"))
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP);

#if GTK_CHECK_VERSION(2, 6, 0)
  if (iupAttribGetBoolean(ih, "SHOWHIDDEN"))
    gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE);
#endif

  if (iupAttribGetBoolean(ih, "MULTIPLEFILES") && action == GTK_FILE_CHOOSER_ACTION_OPEN)
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);

#if GTK_CHECK_VERSION(2, 8, 0)
  if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT") && action == GTK_FILE_CHOOSER_ACTION_SAVE)
    gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
#endif

  /* just check for the path inside FILE */
  value = iupAttribGet(ih, "FILE");
  if (value && (value[0] == '/' || value[1] == ':'))
  {
    char* dir = iupStrFileGetPath(value);
    int len = strlen(dir);
    iupAttribStoreStr(ih, "DIRECTORY", dir);
    free(dir);
    iupAttribStoreStr(ih, "FILE", value+len);
  }

  value = iupAttribGet(ih, "DIRECTORY");
  if (value)
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value));

  value = iupAttribGet(ih, "FILE");
  if (value)
  {
    if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value));
    else
    {
      if (iupdrvIsFile(value))  /* check if file exists */
        gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value));
    }
  }

  value = iupAttribGet(ih, "EXTFILTER");
  if (value)
  {
    char *name, *pattern, *filters = iupStrDup(value), *p;
    char atrib[30];
    int i;
    int filter_index = iupAttribGetInt(ih, "FILTERUSED");
    if (!filter_index)
      filter_index = 1;

    filter_count = iupStrReplace(filters, '|', 0) / 2;

    p = filters;
    for (i=0; i<filter_count; i++)
    {
      GtkFileFilter *filter = gtk_file_filter_new();

      gtkFileDlgGetNextFilter(&p, &name, &pattern);

      gtk_file_filter_set_name(filter, iupgtkStrConvertToUTF8(name));
      gtk_file_filter_add_pattern(filter, pattern);
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

      sprintf(atrib, "_IUPDLG_FILTER%d", i+1);
      iupAttribSetStr(ih, atrib, (char*)filter);

      if (i+1 == filter_index)
        gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
    }

    free(filters);
  }
  else 
  {
    value = iupAttribGet(ih, "FILTER");
    if (value)
    {
      GtkFileFilter *filter = gtk_file_filter_new();
      char* info = iupAttribGet(ih, "FILTERINFO");
      if (!info)
        info = value;

      gtk_file_filter_set_name(filter, iupgtkStrConvertToUTF8(info));
      gtk_file_filter_add_pattern(filter, value);
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
    }
  }

  file_cb = (IFnss)IupGetCallback(ih, "FILE_CB");
  if (file_cb && action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
  {
    g_signal_connect(GTK_FILE_CHOOSER(dialog), "update-preview", G_CALLBACK(gtkFileDlgUpdatePreview), ih);
    g_signal_connect(dialog, "realize", G_CALLBACK(gtkFileDlgRealize), ih);

    if (iupAttribGetBoolean(ih, "SHOWPREVIEW"))
    {
      GtkWidget* frame = gtk_frame_new(NULL);
      gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
      gtk_widget_set_size_request(frame, 180, 150);

      preview_canvas = gtk_drawing_area_new();
      gtk_widget_set_double_buffered(preview_canvas, FALSE);
      gtk_container_add(GTK_CONTAINER(frame), preview_canvas);
      gtk_widget_show(preview_canvas);

      g_signal_connect(preview_canvas, "configure-event", G_CALLBACK(gtkFileDlgPreviewConfigureEvent), ih);
      g_signal_connect(preview_canvas, "expose-event", G_CALLBACK(gtkFileDlgPreviewExposeEvent), ih);
      g_signal_connect(preview_canvas, "realize", G_CALLBACK(gtkFileDlgPreviewRealize), ih);

      iupAttribSetStr(ih, "_IUPDLG_FILE_CHOOSER", (char*)dialog);

      gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), frame);
    }
  }
  
  /* initialize the widget */
  gtk_widget_realize(GTK_WIDGET(dialog));
  
  ih->handle = GTK_WIDGET(dialog);
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;  /* reset handle */

  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == GTK_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
        response = GTK_RESPONSE_CANCEL;
    }
    else if (response == GTK_RESPONSE_OK)
    {
      char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
      int file_exist = iupdrvIsFile(filename);
      int dir_exist = iupdrvIsDirectory(filename);
      g_free(filename);

      if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
      {
        if (!dir_exist)
        {
          iupStrMessageShowError(ih, "IUP_INVALIDDIR");
          response = GTK_RESPONSE_HELP; /* to leave the dialog open */
          continue;
        }
      }
      else if (!iupAttribGetBoolean(ih, "MULTIPLEFILES"))
      {
        if (dir_exist)
        {
          iupStrMessageShowError(ih, "IUP_FILEISDIR");
          response = GTK_RESPONSE_HELP; /* to leave the dialog open */
          continue;
        }

        if (!file_exist)  /* if do not exist check ALLOWNEW */
        {
          value = iupAttribGet(ih, "ALLOWNEW");
          if (!value)
          {
            if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
              value = "YES";
            else
              value = "NO";
          }

          if (!iupStrBoolean(value))
          {
            iupStrMessageShowError(ih, "IUP_FILENOTEXIST");
            response = GTK_RESPONSE_HELP; /* to leave the dialog open */
            continue;
          }
        }

        if (file_cb)
        {
          char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
          int ret = file_cb(ih, iupgtkStrConvertFromFilename(filename), "OK");
          g_free(filename);
          
          if (ret == IUP_IGNORE)
          {
            response = GTK_RESPONSE_HELP; /* to leave the dialog open */
            continue;
          }
        }
      }
    }
  } while (response == GTK_RESPONSE_HELP);

  if (file_cb)
  {
    if (iupAttribGetBoolean(ih, "SHOWPREVIEW"))
      iupgtkReleaseNativeGraphicsContext(preview_canvas, (void*)iupAttribGet(ih, "PREVIEWDC"));

    file_cb(ih, NULL, "FINISH");
  }

  if (response == GTK_RESPONSE_OK)
  {
    int file_exist, dir_exist;

    if (filter_count)
    {
      int i;
      char atrib[30];
      GtkFileFilter* filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));

      for (i=0; i<filter_count; i++)
      {
        sprintf(atrib, "_IUPDLG_FILTER%d", i+1);
        if (filter == (GtkFileFilter*)iupAttribGet(ih, atrib))
          iupAttribSetInt(ih, "FILTERUSED", i+1);
      }
    }

    if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
    {
      GSList* file_list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));

      if (file_list->next) /* if more than one file */
        gtkFileDlgGetMultipleFiles(ih, file_list);
      else
      {
        char* filename = (char*)file_list->data;
        iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(filename));
        g_free(filename);
      }

      g_slist_free(file_list);
      file_exist = 1;
      dir_exist = 0;
    }
    else
    {
      char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
      iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(filename));
      file_exist = iupdrvIsFile(filename);
      dir_exist = iupdrvIsDirectory(filename);
      g_free(filename);
    }

    if (dir_exist)
    {
      iupAttribSetStr(ih, "FILEEXIST", NULL);
      iupAttribSetStr(ih, "STATUS", "0");
    }
    else
    {
      if (file_exist)  /* check if file exists */
      {
        iupAttribSetStr(ih, "FILEEXIST", "YES");
        iupAttribSetStr(ih, "STATUS", "0");
      }
      else
      {
        iupAttribSetStr(ih, "FILEEXIST", "NO");
        iupAttribSetStr(ih, "STATUS", "1");
      }
    }

    if (action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER && !iupAttribGetBoolean(ih, "NOCHANGEDIR"))  /* do change the current directory */
    {
      /* GtkFileChooser does not change the current directory */
      char* dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
      if (dir) iupdrvSetCurrentDirectory(dir);
      g_free(dir);
    }
  }
  else
  {
    iupAttribSetStr(ih, "FILTERUSED", NULL);
    iupAttribSetStr(ih, "VALUE", NULL);
    iupAttribSetStr(ih, "FILEEXIST", NULL);
    iupAttribSetStr(ih, "STATUS", "-1");
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));  

  return IUP_NOERROR;
}