Jump to content

Items counter in gwinList module


Bezet

Recommended Posts

Hello,

I'm not sure if its best place to report bug but couldn't find another. 

In  gwinListAddItem function item counter is incremented but its never decremented, in my opinion it should be decremented in gwinListItemDelete

My proposition is to put gh2Obj->cnt--;   in gwinListItemDelete function;

Below are original functions bodys in 2.5 ugfx .

void gwinListItemDelete(GHandle gh, int item) {
	const gfxQueueASyncItem	*	qi;
	int							i;

	// is it a valid handle?
	if (gh->vmt != (gwinVMT *)&listVMT)
		return;

	// watch out for an invalid item
	if (item < 0 || item >= gh2obj->cnt)
		return;

	for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
		if (i == item) {
			gfxQueueASyncRemove(&gh2obj->list_head, (gfxQueueASyncItem*)qi);
			gfxFree((void *)qi);
			if (gh2obj->top >= item && gh2obj->top)
				gh2obj->top--;
			_gwinUpdate(gh);
			break;
		}
	}
}

 

 

int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
	ListItem	*newItem;

	// is it a valid handle?
	if (gh->vmt != (gwinVMT *)&listVMT)
		return -1;

	if (useAlloc) {
		size_t len = strlen(item_name)+1;
		if (!(newItem = gfxAlloc(sizeof(ListItem) + len)))
			return -1;

		memcpy((char *)(newItem+1), item_name, len);
		item_name = (const char *)(newItem+1);
	} else {
		if (!(newItem = gfxAlloc(sizeof(ListItem))))
			return -1;
	}

	// the item is not selected when added
	newItem->flags = 0;
	newItem->param = 0;
	newItem->text = item_name;
	#if GWIN_NEED_LIST_IMAGES
		newItem->pimg = 0;
	#endif

	// select the item if it's the first in the list
	if (gh2obj->cnt == 0 && !(gh->flags & GLIST_FLG_MULTISELECT))
		newItem->flags |= GLIST_FLG_SELECTED;

	// add the new item to the list
	gfxQueueASyncPut(&gh2obj->list_head, &newItem->q_item);

	// increment the total amount of entries in the list widget
	gh2obj->cnt++;

	_gwinUpdate(gh);

	// return the position in the list (-1 because we start with index 0)
	return gh2obj->cnt-1;
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...