void WMInsertItemInTabView(WMTabView *tPtr, int index, WMTabViewItem *item) { wassertr(W_TabViewItemView(item) != NULL); if (tPtr->maxItems == tPtr->itemCount) { WMTabViewItem **items; items = wrealloc(tPtr->items, sizeof(WMTabViewItem*) * (tPtr->maxItems + 10)); memset(&items[tPtr->maxItems], 0, sizeof(WMTabViewItem*) * 10); tPtr->items = items; tPtr->maxItems += 10; } if (index > tPtr->itemCount) index = tPtr->itemCount; if (index == 0 && tPtr->items[0]) { W_UnmapTabViewItem(tPtr->items[0]); } if (index < tPtr->itemCount) { memmove(tPtr->items + index + 1, tPtr->items + index, (tPtr->itemCount - index) * sizeof(WMTabViewItem*)); } tPtr->items[index] = item; tPtr->itemCount++; recalcTabWidth(tPtr); W_SetTabViewItemParent(item, tPtr); W_UnmapTabViewItem(item); if (tPtr->flags.bordered) { W_ReparentView(W_TabViewItemView(item), tPtr->view, 1, tPtr->tabHeight + 1); W_ResizeView(W_TabViewItemView(item), tPtr->view->size.width - 3, tPtr->view->size.height - tPtr->tabHeight - 3); } else { W_ReparentView(W_TabViewItemView(item), tPtr->view, 0, tPtr->tabHeight); W_ResizeView(W_TabViewItemView(item), tPtr->view->size.width, tPtr->view->size.height - tPtr->tabHeight); } if (index == 0) { W_MapTabViewItem(item); } if (tPtr->delegate && tPtr->delegate->didChangeNumberOfItems) (*tPtr->delegate->didChangeNumberOfItems)(tPtr->delegate, tPtr); if (W_VIEW_REALIZED(tPtr->view)) paintTabView(tPtr); }
void WMRemoveTabViewItem(WMTabView * tPtr, WMTabViewItem * item) { int i; for (i = 0; i < tPtr->itemCount; i++) { if (tPtr->items[i] == item) { if (i < tPtr->itemCount - 1) memmove(&tPtr->items[i], &tPtr->items[i + 1], tPtr->itemCount - i - 1); else tPtr->items[i] = NULL; W_SetTabViewItemParent(item, NULL); tPtr->itemCount--; break; } } if (tPtr->delegate && tPtr->delegate->didChangeNumberOfItems) (*tPtr->delegate->didChangeNumberOfItems) (tPtr->delegate, tPtr); }