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 WMResizeScrollViewContent(WMScrollView *sPtr, unsigned int width, unsigned int height) { int w, h, x; w = width; h = height; x = 0; if (sPtr->flags.relief == WRSimple) { w += 2; h += 2; } else if (sPtr->flags.relief != WRFlat) { w += 4; h += 4; x = 1; } if (sPtr->flags.hasVScroller) { WMResizeWidget(sPtr->vScroller, 20, h); width -= W_VIEW(sPtr->vScroller)->size.width; } if (sPtr->flags.hasHScroller) { WMResizeWidget(sPtr->hScroller, w, 20); WMMoveWidget(sPtr->hScroller, x, h); height -= W_VIEW(sPtr->hScroller)->size.height; } W_ResizeView(sPtr->view, w, h); W_ResizeView(sPtr->viewport, width, height); }
struct W_Balloon *W_CreateBalloon(WMScreen * scr) { Balloon *bPtr; bPtr = wmalloc(sizeof(Balloon)); bPtr->view = W_CreateUnmanagedTopView(scr); if (!bPtr->view) { wfree(bPtr); return NULL; } bPtr->view->self = bPtr; bPtr->textColor = WMRetainColor(bPtr->view->screen->black); WMCreateEventHandler(bPtr->view, StructureNotifyMask, handleEvents, bPtr); W_ResizeView(bPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT); bPtr->flags.alignment = DEFAULT_ALIGNMENT; bPtr->table = WMCreateHashTable(WMIntHashCallbacks); bPtr->delay = DEFAULT_DELAY; bPtr->flags.enabled = 1; return bPtr; }
WMLabel *WMCreateLabel(WMWidget * parent) { Label *lPtr; lPtr = wmalloc(sizeof(Label)); lPtr->widgetClass = WC_Label; lPtr->view = W_CreateView(W_VIEW(parent)); if (!lPtr->view) { wfree(lPtr); return NULL; } lPtr->view->self = lPtr; lPtr->textColor = WMRetainColor(lPtr->view->screen->black); WMCreateEventHandler(lPtr->view, ExposureMask | StructureNotifyMask, handleEvents, lPtr); W_ResizeView(lPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT); lPtr->flags.alignment = DEFAULT_ALIGNMENT; lPtr->flags.relief = DEFAULT_RELIEF; lPtr->flags.imagePosition = DEFAULT_IMAGE_POSITION; lPtr->flags.noWrap = 1; return lPtr; }
WMScroller *WMCreateScroller(WMWidget * parent) { Scroller *sPtr; sPtr = wmalloc(sizeof(Scroller)); sPtr->widgetClass = WC_Scroller; sPtr->view = W_CreateView(W_VIEW(parent)); if (!sPtr->view) { wfree(sPtr); return NULL; } sPtr->view->self = sPtr; sPtr->view->delegate = &_ScrollerViewDelegate; sPtr->flags.documentFullyVisible = 1; WMCreateEventHandler(sPtr->view, ExposureMask | StructureNotifyMask | ClientMessageMask, handleEvents, sPtr); W_ResizeView(sPtr->view, DEFAULT_WIDTH, DEFAULT_WIDTH); sPtr->flags.arrowsPosition = DEFAULT_ARROWS_POSITION; WMCreateEventHandler(sPtr->view, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | ButtonMotionMask, handleActionEvents, sPtr); sPtr->flags.hitPart = WSNoPart; sPtr->floatValue = 0.0; sPtr->knobProportion = 1.0; return sPtr; }
static void doRearrange(void *object, void *cdata) { SubviewItem *item = (SubviewItem *) object; BoxData *eData = (BoxData *) cdata; if (eData->box->horizontal) { eData->w = item->minSize; if (item->expand) eData->w += eData->total / eData->expands; } else { eData->h = item->minSize; if (item->expand) eData->h += eData->total / eData->expands; } if (!item->end) { W_MoveView(item->view, eData->x, eData->y); } W_ResizeView(item->view, eData->w, eData->h); if (eData->box->horizontal) { if (item->end) eData->xe -= eData->w + item->space; else eData->x += eData->w + item->space; } else { if (item->end) eData->ye -= eData->h + item->space; else eData->y += eData->h + item->space; } if (item->end) { W_MoveView(item->view, eData->xe, eData->ye); } }
static void resizedParent(void *self, WMNotification * notif) { WMSize size = WMGetViewSize((WMView *) WMGetNotificationObject(notif)); WMView *view = (WMView *) self; W_MoveView(view, view->leftOffs, view->topOffs); W_ResizeView(view, size.width - (view->leftOffs + view->rightOffs), size.height - (view->topOffs + view->bottomOffs)); }
WMTextField *WMCreateTextField(WMWidget * parent) { TextField *tPtr; tPtr = wmalloc(sizeof(TextField)); tPtr->widgetClass = WC_TextField; tPtr->view = W_CreateView(W_VIEW(parent)); if (!tPtr->view) { wfree(tPtr); return NULL; } tPtr->view->self = tPtr; tPtr->view->delegate = &_TextFieldViewDelegate; tPtr->view->attribFlags |= CWCursor; tPtr->view->attribs.cursor = tPtr->view->screen->textCursor; W_SetViewBackgroundColor(tPtr->view, tPtr->view->screen->white); tPtr->text = wmalloc(MIN_TEXT_BUFFER); tPtr->textLen = 0; tPtr->bufferSize = MIN_TEXT_BUFFER; tPtr->flags.enabled = 1; WMCreateEventHandler(tPtr->view, ExposureMask | StructureNotifyMask | FocusChangeMask, handleEvents, tPtr); tPtr->font = WMRetainFont(tPtr->view->screen->normalFont); tPtr->flags.bordered = DEFAULT_BORDERED; tPtr->flags.beveled = True; tPtr->flags.alignment = DEFAULT_ALIGNMENT; tPtr->offsetWidth = WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font)) / 2, 1); W_ResizeView(tPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT); WMCreateEventHandler(tPtr->view, EnterWindowMask | LeaveWindowMask | ButtonReleaseMask | ButtonPressMask | KeyPressMask | Button1MotionMask, handleTextFieldActionEvents, tPtr); WMAddNotificationObserver(selectionNotification, tPtr->view, WMSelectionOwnerDidChangeNotification, (void *)XA_PRIMARY); WMAddNotificationObserver(realizeObserver, tPtr, WMViewRealizedNotification, tPtr->view); tPtr->flags.cursorOn = 1; return tPtr; }
WMRuler *WMCreateRuler(WMWidget * parent) { Ruler *rPtr = wmalloc(sizeof(Ruler)); unsigned int w = WMWidgetWidth(parent); rPtr->widgetClass = WC_Ruler; rPtr->view = W_CreateView(W_VIEW(parent)); if (!rPtr->view) { wfree(rPtr); return NULL; } rPtr->view->self = rPtr; rPtr->drawBuffer = (Pixmap) NULL; W_ResizeView(rPtr->view, w, 40); WMCreateEventHandler(rPtr->view, ExposureMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask | ButtonReleaseMask | ButtonPressMask | KeyReleaseMask | KeyPressMask | Button1MotionMask, handleEvents, rPtr); rPtr->view->delegate = &_RulerViewDelegate; rPtr->fg = WMBlackColor(rPtr->view->screen); rPtr->fgGC = WMColorGC(rPtr->fg); rPtr->bgGC = WMColorGC(WMGrayColor(rPtr->view->screen)); rPtr->font = WMSystemFontOfSize(rPtr->view->screen, 8); rPtr->offset = 22; rPtr->margins.left = 22; rPtr->margins.body = 22; rPtr->margins.first = 42; rPtr->margins.right = (w < 502 ? w : 502); rPtr->margins.tabs = NULL; rPtr->flags.whichMarker = 0; /* none */ rPtr->flags.buttonPressed = False; rPtr->flags.redraw = True; rPtr->moveAction = NULL; rPtr->releaseAction = NULL; rPtr->pview = W_VIEW(parent); return rPtr; }
void WMSetViewExpandsToParent(WMView * view, int leftOffs, int topOffs, int rightOffs, int bottomOffs) { WMSize size = view->parent->size; view->topOffs = topOffs; view->bottomOffs = bottomOffs; view->leftOffs = leftOffs; view->rightOffs = rightOffs; WMAddNotificationObserver(resizedParent, view, WMViewSizeDidChangeNotification, view->parent); WMSetViewNotifySizeChanges(view->parent, True); W_MoveView(view, leftOffs, topOffs); W_ResizeView(view, size.width - (leftOffs + rightOffs), size.height - (topOffs + bottomOffs)); }
static void resizeView(WMSplitView * sPtr, WMView * view, int size) { int width, height; if (sPtr->flags.vertical) { width = size; height = sPtr->view->size.height; } else { width = sPtr->view->size.width; height = size; } if (view->self) WMResizeWidget(view->self, width, height); else W_ResizeView(view, width, height); }
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); }
static void reorganizeInterior(WMScrollView *sPtr) { int hx, hy, hw; int vx, vy, vh; int cx, cy, cw, ch; cw = hw = sPtr->view->size.width; vh = ch = sPtr->view->size.height; if (sPtr->flags.relief == WRSimple) { cw -= 2; ch -= 2; cx = 1; cy = 1; } else if (sPtr->flags.relief != WRFlat) { cw -= 3; ch -= 3; cx = 2; cy = 2; } else { cx = 0; cy = 0; } if (sPtr->flags.hasHScroller) { int h = 20; ch -= h; if (sPtr->flags.relief == WRSimple) { hx = 0; hy = sPtr->view->size.height - h; } else if (sPtr->flags.relief != WRFlat) { hx = 1; hy = sPtr->view->size.height - h - 1; hw -= 2; } else { hx = 0; hy = sPtr->view->size.height - h; } } else { /* make compiler shutup */ hx = 0; hy = 0; } if (sPtr->flags.hasVScroller) { int w = 20; cw -= w; cx += w; hx += w - 1; hw -= w - 1; if (sPtr->flags.relief == WRSimple) { vx = 0; vy = 0; } else if (sPtr->flags.relief != WRFlat) { vx = 1; vy = 1; vh -= 2; } else { vx = 0; vy = 0; } } else { /* make compiler shutup */ vx = 0; vy = 0; } W_ResizeView(sPtr->viewport, cw, ch); W_MoveView(sPtr->viewport, cx, cy); if (sPtr->flags.hasHScroller) { WMResizeWidget(sPtr->hScroller, hw, 20); WMMoveWidget(sPtr->hScroller, hx, hy); } if (sPtr->flags.hasVScroller) { WMResizeWidget(sPtr->vScroller, 20, vh); WMMoveWidget(sPtr->vScroller, vx, vy); } applyScrollerValues(sPtr); }
static void showText(Balloon * bPtr, int x, int y, int w, int h, const char *text) { WMScreen *scr = bPtr->view->screen; Display *dpy = WMScreenDisplay(scr); int width; int height; Pixmap pixmap; Pixmap mask; WMFont *font = bPtr->font ? bPtr->font : scr->normalFont; int textHeight; int side = 0; int ty; int bx, by; { int w; const char *ptr, *ptr2; ptr2 = ptr = text; width = 0; while (ptr && ptr2) { ptr2 = strchr(ptr, '\n'); if (ptr2) { w = WMWidthOfString(font, ptr, ptr2 - ptr); } else { w = WMWidthOfString(font, ptr, strlen(ptr)); } if (w > width) width = w; ptr = ptr2 + 1; } } width += 16; textHeight = W_GetTextHeight(font, text, width, False); height = textHeight + 4; if (height < 16) height = 16; if (width < height) width = height; if (x + width > scr->rootView->size.width) { side = RIGHT; bx = x - width + w / 2; if (bx < 0) bx = 0; } else { side = LEFT; bx = x + w / 2; } if (bx + width > scr->rootView->size.width) bx = scr->rootView->size.width - width; if (y - (height + SPACE) < 0) { side |= TOP; by = y + h - 1; ty = SPACE; } else { side |= BOTTOM; by = y - (height + SPACE); ty = 0; } pixmap = makePixmap(scr, width, height, side, &mask); W_PaintText(bPtr->view, pixmap, font, 8, ty + (height - textHeight) / 2, width, bPtr->flags.alignment, bPtr->textColor ? bPtr->textColor : scr->black, False, text, strlen(text)); XSetWindowBackgroundPixmap(dpy, bPtr->view->window, pixmap); W_ResizeView(bPtr->view, width, height + SPACE); XFreePixmap(dpy, pixmap); #ifdef USE_XSHAPE XShapeCombineMask(dpy, bPtr->view->window, ShapeBounding, 0, 0, mask, ShapeSet); #endif XFreePixmap(dpy, mask); W_MoveView(bPtr->view, bx, by); W_MapView(bPtr->view); }
void WMResizeWidget(WMWidget * w, unsigned int width, unsigned int height) { W_ResizeView(W_VIEW(w), width, height); }