static void handleEvents(XEvent *event, void *data) { TabView *tPtr = (TabView*)data; CHECK_CLASS(data, WC_TabView); switch (event->type) { case Expose: if (event->xexpose.count!=0) break; paintTabView(tPtr); break; case ButtonPress: if (tPtr->flags.enabled) { WMTabViewItem *item = WMTabViewItemAtPoint(tPtr, event->xbutton.x, event->xbutton.y); /*if (item && !item->flags.enabled) break;*/ if (item && item->flags.enabled) { WMSelectTabViewItem(tPtr, item); } else if (tPtr->flags.dontFitAll) { int redraw = 0; int lastVisible = tPtr->firstVisible+tPtr->visibleTabs-1; if (event->xbutton.x < BUTTONED_SIDE_OFFSET) { if (tPtr->firstVisible > 0) { redraw = 1; tPtr->firstVisible--; } } else if (event->xbutton.x > positionOfTab(tPtr,lastVisible)){ if (lastVisible < tPtr->itemCount-1) { redraw = 1; tPtr->firstVisible++; } } tPtr->visibleTabs = countVisibleTabs(tPtr, tPtr->firstVisible); if (redraw) { paintTabView(tPtr); } } } break; case DestroyNotify: destroyTabView(tPtr); break; } }
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); }
void WMSetTabViewItemEnabled(WMTabViewItem *tPtr, Bool flag) { tPtr->flags.enabled = ((flag==0) ? 0 : 1); if (tPtr->tabView && W_VIEW_REALIZED(tPtr->tabView->view)) paintTabView(tPtr->tabView); }
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 WMSetTabViewEnabled(WMTabView *tPtr, Bool flag) { tPtr->flags.enabled = ((flag==0) ? 0 : 1); if (W_VIEW_REALIZED(tPtr->view)) paintTabView(tPtr); }
static void rearrange(TabView * tPtr) { int i; int width, height; int bordered = tPtr->flags.bordered; recalcTabWidth(tPtr); width = tPtr->view->size.width - (bordered ? 3 : 0); height = tPtr->view->size.height - tPtr->tabHeight - (bordered ? 3 : 0); for (i = 0; i < tPtr->itemCount; i++) { W_MoveView(W_TabViewItemView(tPtr->items[i]), 1 * bordered, tPtr->tabHeight + 1 * bordered); W_ResizeView(W_TabViewItemView(tPtr->items[i]), width, height); } if (W_VIEW_MAPPED(tPtr->view) && W_VIEW_REALIZED(tPtr->view)) paintTabView(tPtr); }