Esempio n. 1
0
char* iupAttribGetStr(Ihandle* ih, const char* name)
{
  char* value;
  if (!ih || !name)
    return NULL;

  value = iupTableGet(ih->attrib, name);

  if (!value && !iupATTRIB_ISINTERNAL(name))
  {
    int inherit;
    char *def_value;
    iupClassObjectGetAttributeInfo(ih, name, &def_value, &inherit);

    if (inherit)
    {
      while (!value)
      {
        ih = ih->parent;
        if (!ih)
          break;

        value = iupAttribGet(ih, name);
      }
    }

    if (!value)
      value = def_value;
  }

  return value;
}
Esempio n. 2
0
void IupStoreAttribute(Ihandle *ih, const char* name, const char *value)
{
  int inherit;

  if (!name)
    return;

  if (!ih)
  {
    IupStoreGlobal(name, value);
    return;
  }

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return;

  if (iupATTRIB_ISINTERNAL(name))
    iupAttribStoreStr(ih, name, value);
  else
  {
    if (iupClassObjectSetAttribute(ih, name, value, &inherit)==1) /* store only strings */
      iupAttribStoreStr(ih, name, value);

    if (inherit)
      iAttribNotifyChildren(ih, name, value);
  }
}
Esempio n. 3
0
void IupSetAttribute(Ihandle *ih, const char* name, const char *value)
{
  int inherit;

  iupASSERT(name!=NULL);
  if (!name)
    return;

  if (!ih)
  {
    IupSetGlobal(name, value);
    return;
  }

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return;

  if (iupATTRIB_ISINTERNAL(name))
    iupAttribSetStr(ih, name, value);
  else
  {
    if (iupClassObjectSetAttribute(ih, name, value, &inherit)!=0) /* store strings and pointers */
      iupAttribSetStr(ih, name, value);

    if (inherit)
      iAttribNotifyChildren(ih, name, value);
  }
}
Esempio n. 4
0
int IupGetAllAttributes(Ihandle* ih, char** names, int n)
{
  char *name;
  int i = 0;

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return 0;

  if (!names || !n)
    return iupTableCount(ih->attrib);

  name = iupTableFirst(ih->attrib);
  while (name)
  {
    if (!iupATTRIB_ISINTERNAL(name))
    {
      names[i] = name;
      i++;
      if (i == n)
        break;
    }

    name = iupTableNext(ih->attrib);
  }

  return i;
}
Esempio n. 5
0
static void GetAttribute(void)
{
  char *name = luaL_check_string(2);
  Ihandle* ih = iuplua_checkihandle(1);
  char *value = IupGetAttribute(ih, name);
  if (!value || iupATTRIB_ISINTERNAL(name))
    lua_pushnil();
  else
  {
    if (iupAttribIsPointer(ih, name))
      lua_pushuserdata((void*)value);
    else
      lua_pushstring(value);
  }
}
Esempio n. 6
0
void iupAttribUpdateChildren(Ihandle* ih)
{
  char *name = iupTableFirst(ih->attrib);
  while (name)
  {
    if (!iupATTRIB_ISINTERNAL(name) && iAttribIsInherit(ih, name))
    {
      /* retrieve from the table */
      char* value = iupTableGet(ih->attrib, name);
      iAttribNotifyChildren(ih, name, value);
    }

    name = iupTableNext(ih->attrib);
  }
}
Esempio n. 7
0
static void iuplua_pushvalue(lua_State *L, Ihandle *ih, const char* name, const char* value)
{
  if (!value || iupATTRIB_ISINTERNAL(name))
    lua_pushnil(L);
  else
  {
    if (iupAttribIsNotString(ih, name))
    {
      if (iupAttribIsIhandle(ih, name))
        iuplua_pushihandle(L, (Ihandle*)value);
      else
        lua_pushlightuserdata(L, (void*)value);
    }
    else /* if (!lua_stringtonumber(L, value)) -- TODO: is this worth it? valid since Lua 5.3 */
      lua_pushstring(L, value);
  }
}
Esempio n. 8
0
char* IupGetAttribute(Ihandle *ih, const char* name)
{
  iupASSERT(name!=NULL);
  if (!name)
    return NULL;

  if (!ih)
    return IupGetGlobal(name);

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return NULL;

  if (iupATTRIB_ISINTERNAL(name))
    return iupAttribGet(ih, name);
  else
  {
    int inherit;
    char *value, *def_value;

    value = iupClassObjectGetAttribute(ih, name, &def_value, &inherit);

    if (!value)
      value = iupAttribGet(ih, name);

    if (!value && inherit)
    {
      while (!value)
      {
        ih = ih->parent;
        if (!ih)
          break;

        value = iupAttribGet(ih, name);
      }
    }

    if (!value)
      value = def_value;

    return value;
  }
}
Esempio n. 9
0
void iupAttribUpdate(Ihandle* ih)
{
  char** name_array;
  char *name, *value;
  int count, i = 0, inherit, store;

  count = iupTableCount(ih->attrib);
  if (!count)
    return;

  name_array = (char**)malloc(count * sizeof(char*));

  /* store the names before updating so we can add or remove attributes during the update */
  name = iupTableFirst(ih->attrib);
  while (name)
  {
    name_array[i] = name;
    name = iupTableNext(ih->attrib);
    i++;
  }

  /* for all defined attributes updates the native system */
  for (i = 0; i < count; i++)
  {
    name = name_array[i];
    if (!iupATTRIB_ISINTERNAL(name))
    {
      /* retrieve from the table */
      value = iupTableGet(ih->attrib, name);

      /* set on the class */
      store = iupClassObjectSetAttribute(ih, name, value, &inherit);

      if (inherit)
        iAttribNotifyChildren(ih, name, value);

      if (store == 0)
        iupTableRemove(ih->attrib, name); /* remove from the table acording to the class SetAttribute */
    }
  }

  free(name_array);
}
Esempio n. 10
0
char* iupAttribGetLocal(Ihandle* ih, const char* name)
{
  char* value;
  if (!ih || !name)
    return NULL;

  value = iupTableGet(ih->attrib, name);

  if (!value && !iupATTRIB_ISINTERNAL(name))
  {
    int inherit;
    char *def_value;
    value = iupClassObjectGetAttribute(ih, name, &def_value, &inherit);

    if (!value)
      value = def_value;
  }

  return value;
}
Esempio n. 11
0
char* IupGetAttributes(Ihandle *ih)
{
  char *buffer;
  char *name, *value;
  char sb[128];

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return NULL;

  buffer = iupStrGetMemory(10240);
  buffer[0] = 0;

  name = iupTableFirst(ih->attrib);
  while (name)
  {
    if (!iupATTRIB_ISINTERNAL(name))
    {
      if (buffer[0] != 0)
        strcat(buffer,",");

      value = iupTableGetCurr(ih->attrib);
      if (iupAttribIsPointer(ih, name))
      {
        sprintf(sb, "%p", (void*) value);
        value = sb;
      }
      strcat(buffer, name);
      strcat(buffer,"=\"");
      strcat(buffer, value);
      strcat(buffer,"\"");
    }

    name = iupTableNext(ih->attrib);
  }

  return buffer;
}
Esempio n. 12
0
static int MatGetAttribute(lua_State *L)
{
  Ihandle *ih = iuplua_checkihandle(L,1);
  const char *name = luaL_checkstring(L,2);
  int lin = luaL_checkint(L,3);
  int col = luaL_checkint(L,4);
  const char *value = IupGetAttributeId2(ih, name, lin, col);
  if (!value || iupATTRIB_ISINTERNAL(name))
    lua_pushnil(L);
  else
  {
    if (iupAttribIsNotString(ih, name))
    {
      if (iupObjectCheck((Ihandle*)value))
        iuplua_pushihandle(L, (Ihandle*)value);
      else
        lua_pushlightuserdata(L, (void*)value);
    }
    else
      lua_pushstring(L,value);
  }
  return 1;
}
Esempio n. 13
0
static int GetAttribute (lua_State *L)
{
  Ihandle *ih = iuplua_checkihandle(L,1);
  const char *name = luaL_checkstring(L,2);
  const char *value = IupGetAttribute(ih, name);
  if (!value || iupATTRIB_ISINTERNAL(name))
    lua_pushnil(L);
  else
  {
    if (iupAttribIsPointer(ih, name))
    {
      if (ih->handle == (InativeHandle*)value) /* work around for WID, sometimes WID in Windows is not a valid pointer. Why? */
        iuplua_pushihandle(L, ih);
      else if (iupObjectCheck((Ihandle*)value))
        iuplua_pushihandle(L, (Ihandle*)value);
      else
        lua_pushlightuserdata(L, (void*)value);
    }
    else
      lua_pushstring(L,value);
  }
  return 1;
}