예제 #1
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;
}
예제 #2
0
파일: iup_text.c 프로젝트: kmx/mirror-iup
static int iTextSetValueMaskedAttrib(Ihandle* ih, const char* value)
{
  if (value)
  {
    if (ih->data->mask && iupMaskCheck(ih->data->mask, value)==0)
      return 0; /* abort */
    IupStoreAttribute(ih, "VALUE", value);
  }
  return 0;
}
예제 #3
0
int iupmaskGet(Ihandle *ih, char **sval)
{
    char *val = IupGetAttribute(ih,"VALUE");
    Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA");

    if (iupMaskCheck(mask,val)==1)
    {
        *sval = val;
        return 1;
    }
    else
        return 0;
}
예제 #4
0
파일: iup_oldmask.c 프로젝트: defdef/iup
int iupmaskMatGet(Ihandle *ih, char **sval, int lin, int col)
{
  char *val = IupGetAttributeId2(ih,"",lin,col);
  Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA");

  if (iupMaskCheck(mask,val)==1)
  {
    *sval = val;
    return 1;
  }
  else
    return 0;
}
예제 #5
0
int iupmaskMatGetInt(Ihandle *ih, int *ival, int lin, int col)
{
    char *val = IupMatGetAttribute(ih,"",lin,col);
    Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA");

    if(iupMaskCheck(mask,val)==1)
    {
        *ival = 0;
        sscanf(val,"%d",ival);
        return 1;
    }
    else
        return 0;
}
예제 #6
0
int iupmaskMatGetFloat(Ihandle *ih, float *fval, int lin, int col)
{
    char *val = IupMatGetAttribute(ih,"",lin,col);
    Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA");

    if (iupMaskCheck(mask,val)==1)
    {
        *fval = 0.0F;
        sscanf(val,"%f",fval);
        return 1;
    }
    else
        return 0;
}
예제 #7
0
int iupmaskMatGetDouble(Ihandle *ih, double *dval, int lin, int col)
{
    char *val = IupMatGetAttribute(ih,"",lin,col);
    Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA");

    if(iupMaskCheck(mask,val)==1)
    {
        *dval = 0.0;
        sscanf(val,"%lf",dval);
        return 1;
    }
    else
        return 0;
}
예제 #8
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;
}
예제 #9
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 */
}
예제 #10
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);
}
예제 #11
0
int iupmaskMatCheck(Ihandle *ih, int lin, int col)
{
    char *val = IupMatGetAttribute(ih,"",lin,col);
    Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA");
    return iupMaskCheck(mask,val)==1;
}
예제 #12
0
int iupmaskCheck(Ihandle* ih)
{
    char *val = IupGetAttribute(ih,"VALUE");
    Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA");
    return iupMaskCheck(mask,val)==1;
}