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 WMSelectTabViewItemAtIndex(WMTabView * tPtr, int index) { WMTabViewItem *item; if (index == tPtr->selectedItem) { return; } if (index < 0) index = 0; else if (index >= tPtr->itemCount) index = tPtr->itemCount - 1; item = tPtr->items[tPtr->selectedItem]; if (tPtr->delegate && tPtr->delegate->shouldSelectItem) if (!(*tPtr->delegate->shouldSelectItem) (tPtr->delegate, tPtr, tPtr->items[index])) return; if (tPtr->delegate && tPtr->delegate->willSelectItem) (*tPtr->delegate->willSelectItem) (tPtr->delegate, tPtr, tPtr->items[index]); W_UnmapTabViewItem(item); item = tPtr->items[index]; W_MapTabViewItem(item); tPtr->selectedItem = index; if (tPtr->delegate && tPtr->delegate->didSelectItem) (*tPtr->delegate->didSelectItem) (tPtr->delegate, tPtr, tPtr->items[index]); paintTabView(tPtr); }