示例#1
0
static int iListSetInsertItemAttrib(Ihandle* ih, const char* name_id, const char* value)
{
  if (!ih->handle)  /* do not store the action before map */
    return 0;
  if (value)
  {
    int pos = iupListGetPos(ih, name_id);
    if (pos!=-1)
      iupdrvListInsertItem(ih, pos, value);
  }
  return 0;
}
示例#2
0
static void motListDragTransferProc(Widget drop_context, Ihandle* ih, Atom *seltype, Atom *type, XtPointer value, unsigned long *length, int format)
{
  Atom atomListItem = XInternAtom(iupmot_display, "LIST_ITEM", False);
  int idDrag = (int)value;  /* starts at 1 */
  int idDrop = iupAttribGetInt(ih, "_IUPLIST_DROPITEM");  /* starts at 1 */

  if (idDrop==0)
    return;

  /* shift to start at 0 */
  idDrag--;
  idDrop--;

  if (*type == atomListItem)
  {
    int is_ctrl;

    if (iupListCallDragDropCb(ih, idDrag, idDrop, &is_ctrl) == IUP_CONTINUE)  /* starts at 0 */
    {
      char* text = motListGetIdValueAttrib(ih, idDrag+1); /* starts at 1 */
      int count = iupdrvListGetCount(ih);
        
      /* Copy the item to the idDrop position */
      if (idDrop >= 0 && idDrop < count) /* starts at 0 */
      {
        iupdrvListInsertItem(ih, idDrop, text);   /* starts at 0, insert before */
        if (idDrag > idDrop)
          idDrag++;
      }
      else  /* idDrop = -1 */
      {
        iupdrvListAppendItem(ih, text);
        idDrop = count;  /* new item is the previous count */
      }

      /* Selects the drop item */
      XmListSelectPos(ih->handle, idDrop+1, FALSE);    /* starts at 1 */
      iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", idDrop+1);  /* starts at 1 */

      /* Remove the Drag item if moving */
      if (!is_ctrl)
        iupdrvListRemoveItem(ih, idDrag);   /* starts at 0 */
    }
  }

  iupAttribSet(ih, "_IUPLIST_DROPITEM", NULL);

  (void)drop_context;
  (void)seltype;
  (void)format;
  (void)length;
}
示例#3
0
文件: iup_list.c 项目: Vulcanior/IUP
static int iListSetInsertItemAttrib(Ihandle* ih, int id, const char* value)
{
  if (!ih->handle)  /* do not do the action before map */
    return 0;
  if (value)
  {
    int pos = iupListGetPosAttrib(ih, id);
    if (pos >= 0)
      iupdrvListInsertItem(ih, pos, value);
    else if (pos == -2)
      iupdrvListAppendItem(ih, value);
  }
  return 0;
}
示例#4
0
int iupListSetIdValueAttrib(Ihandle* ih, const char* name_id, const char* value)
{
  int pos;
  if (iupStrToInt(name_id, &pos))
  {
    int count = iupdrvListGetCount(ih);

    pos--; /* IUP starts at 1 */

    if (!value)
    {
      if (pos >= 0 && pos <= count-1)
      {
        if (pos == 0)
          iupdrvListRemoveAllItems(ih);
        else
        {
          int i = pos;
          while (i < count)
          {
            iupdrvListRemoveItem(ih, pos);
            i++;
          }
        }
      }
    }
    else
    {
      if (pos >= 0 && pos <= count-1)
      {
        iupdrvListRemoveItem(ih, pos);
        iupdrvListInsertItem(ih, pos, value);
      }
      else if (pos == count)
        iupdrvListAppendItem(ih, value);
    }
  }
  return 1;
}
示例#5
0
文件: iup_list.c 项目: Vulcanior/IUP
int iupListSetIdValueAttrib(Ihandle* ih, int pos, const char* value)
{
  int count = iupdrvListGetCount(ih);

  pos--; /* IUP starts at 1 */

  if (!value)
  {
    if (pos >= 0 && pos <= count-1)
    {
      if (pos == 0)
      {
        iupdrvListRemoveAllItems(ih);
        iupAttribSet(ih, "_IUPLIST_OLDVALUE", NULL);
      }
      else
      {
        int i = pos;
        while (i < count)
        {
          iupdrvListRemoveItem(ih, pos);
          i++;
        }
      }
    }
  }
  else
  {
    if (pos >= 0 && pos <= count-1)
    {
      iupdrvListRemoveItem(ih, pos);
      iupdrvListInsertItem(ih, pos, value);
    }
    else if (pos == count)
      iupdrvListAppendItem(ih, value);
  }
  return 0;
}
示例#6
0
文件: iup_list.c 项目: Vulcanior/IUP
static int iListDropData_CB(Ihandle *ih, char* type, void* data, int len, int x, int y)
{
  int pos = IupConvertXYToPos(ih, x, y);
  int is_ctrl = 0;
  char key[5];

  /* Data is not the pointer, it contains the pointer */
  Ihandle* ih_source;
  memcpy((void*)&ih_source, data, len);

  /* A copy operation is enabled with the CTRL key pressed, or else a move operation will occour.
     A move operation will be possible only if the attribute DRAGSOURCEMOVE is Yes.
     When no key is pressed the default operation is copy when DRAGSOURCEMOVE=No and move when DRAGSOURCEMOVE=Yes. */
  iupdrvGetKeyState(key);
  if (key[1] == 'C')
    is_ctrl = 1;

  if (ih_source->data->is_multiple)
  {
    char *buffer = IupGetAttribute(ih_source, "VALUE");

    /* Copy all selected items */
    int i = 1;  /* IUP starts at 1 */
    while(buffer[i-1] != '\0')
    {
      if(buffer[i-1] == '+')
      {
        iupdrvListInsertItem(ih, pos, IupGetAttribute(ih_source, iupStrReturnInt(i)));
        iupdrvListSetImageHandle(ih, ++pos, iupdrvListGetImageHandle(ih_source, i));
      }

      i++;
    }

    if (IupGetInt(ih_source, "DRAGSOURCEMOVE") && !is_ctrl)
    {
      /* Remove all item from source if MOVE */
      i = 1;  /* IUP starts at 1 */
      while(*buffer != '\0')
      {
        if (*buffer == '+')
          iupdrvListRemoveItem(ih_source, --i);  /* update index in the source */

        i++;
        buffer++;
      }
    }
  }
  else
  {
    iupdrvListInsertItem(ih, pos, IupGetAttribute(ih_source, IupGetAttribute(ih_source, "VALUE")));
    iupdrvListSetImageHandle(ih, ++pos, iupdrvListGetImageHandle(ih_source, IupGetInt(ih_source, "VALUE")));

    if(IupGetInt(ih_source, "DRAGSOURCEMOVE") && !is_ctrl)
    {
      int srcPos = iupAttribGetInt(ih_source, "_IUP_LIST_SOURCEPOS");
      iupdrvListRemoveItem(ih_source, --srcPos);  /* IUP starts at 1 */
    }
  }

  (void)type;
  return IUP_DEFAULT;
}