static void drawTitleOfColumn(WMBrowser * bPtr, int column) { WMScreen *scr = bPtr->view->screen; int x; x = (column - bPtr->firstVisibleColumn) * (bPtr->columnSize.width + COLUMN_SPACING); XFillRectangle(scr->display, bPtr->view->window, WMColorGC(scr->darkGray), x, 0, bPtr->columnSize.width, bPtr->titleHeight); W_DrawRelief(scr, bPtr->view->window, x, 0, bPtr->columnSize.width, bPtr->titleHeight, WRSunken); if (column < bPtr->usedColumnCount && bPtr->titles[column]) { int titleLen = strlen(bPtr->titles[column]); int widthC = bPtr->columnSize.width - 8; if (WMWidthOfString(scr->boldFont, bPtr->titles[column], titleLen) > widthC) { char *titleBuf = createTruncatedString(scr->boldFont, bPtr->titles[column], &titleLen, widthC); W_PaintText(bPtr->view, bPtr->view->window, scr->boldFont, x, (bPtr->titleHeight - WMFontHeight(scr->boldFont)) / 2, bPtr->columnSize.width, WACenter, scr->white, False, titleBuf, titleLen); wfree(titleBuf); } else { W_PaintText(bPtr->view, bPtr->view->window, scr->boldFont, x, (bPtr->titleHeight - WMFontHeight(scr->boldFont)) / 2, bPtr->columnSize.width, WACenter, scr->white, False, bPtr->titles[column], titleLen); } } }
WMTabView *WMCreateTabView(WMWidget * parent) { TabView *tPtr; WMScreen *scr = WMWidgetScreen(parent); tPtr = wmalloc(sizeof(TabView)); tPtr->widgetClass = WC_TabView; tPtr->view = W_CreateView(W_VIEW(parent)); if (!tPtr->view) { wfree(tPtr); return NULL; } tPtr->view->self = tPtr; tPtr->view->delegate = &delegate; tPtr->lightGray = WMCreateRGBColor(scr, 0xd9d9, 0xd9d9, 0xd9d9, False); tPtr->tabColor = WMCreateRGBColor(scr, 0x8420, 0x8420, 0x8420, False); tPtr->font = WMRetainFont(scr->normalFont); tPtr->flags.type = WTTopTabsBevelBorder; tPtr->flags.bordered = 1; tPtr->flags.uniformTabs = 0; tPtr->flags.enabled = 1; WMCreateEventHandler(tPtr->view, ExposureMask | StructureNotifyMask | ButtonPressMask, handleEvents, tPtr); WMResizeWidget(tPtr, DEFAULT_WIDTH, DEFAULT_HEIGHT); tPtr->tabHeight = WMFontHeight(tPtr->font) + 3; return tPtr; }
static void showText(WScreen *scr, int x, int y, int h, int w, const char *text) { int width; int height; Pixmap pixmap; Pixmap mask; WMFont *font = scr->info_text_font; int side = 0; int ty; int bx, by; if (scr->balloon->contents) XFreePixmap(dpy, scr->balloon->contents); width = getMaxStringWidth(font, text) + 16; height = countLines(text) * WMFontHeight(font) + 4; if (height < 16) height = 16; if (width < height) width = height; if (x + width > scr->scr_width) { side = RIGHT; bx = x - width + w / 2; if (bx < 0) bx = 0; } else { side = LEFT; bx = x + w / 2; } if (bx + width > scr->scr_width) bx = scr->scr_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); drawMultiLineString(scr->wmscreen, pixmap, scr->black, font, 8, ty + 2, text, strlen(text)); XSetWindowBackgroundPixmap(dpy, scr->balloon->window, pixmap); scr->balloon->contents = pixmap; XResizeWindow(dpy, scr->balloon->window, width, height + SPACE); XShapeCombineMask(dpy, scr->balloon->window, ShapeBounding, 0, 0, mask, ShapeSet); XFreePixmap(dpy, mask); XMoveWindow(dpy, scr->balloon->window, bx, by); XMapRaised(dpy, scr->balloon->window); scr->balloon->mapped = 1; }
void WMSetTabViewFont(WMTabView * tPtr, WMFont * font) { if (tPtr->font) WMReleaseFont(tPtr->font); tPtr->font = WMRetainFont(font); tPtr->tabHeight = WMFontHeight(tPtr->font) + 3; recalcTabWidth(tPtr); }
static void didResizeTextField(W_ViewDelegate * self, WMView * view) { WMTextField *tPtr = (WMTextField *) view->self; /* Parameter not used, but tell the compiler that it is ok */ (void) self; tPtr->offsetWidth = WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font)) / 2, 1); tPtr->usableWidth = tPtr->view->size.width - 2 * tPtr->offsetWidth /*+ 2 */ ; }
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; }
void WMSetTextFieldFont(WMTextField * tPtr, WMFont * font) { CHECK_CLASS(tPtr, WC_TextField); if (tPtr->font) WMReleaseFont(tPtr->font); tPtr->font = WMRetainFont(font); tPtr->offsetWidth = WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font)) / 2, 1); if (tPtr->view->flags.realized) { paintTextField(tPtr); } }
static void showText(WScreen *scr, int x, int y, int h, int w, const char *text) { int width; int height; Pixmap pixmap; WMFont *font = scr->info_text_font; if (scr->balloon->contents) XFreePixmap(dpy, scr->balloon->contents); width = getMaxStringWidth(font, text) + 8; /*width = WMWidthOfString(font, text, strlen(text))+8; */ height = countLines(text) * WMFontHeight(font) + 4; if (x < 0) x = 0; else if (x + width > scr->scr_width - 1) x = scr->scr_width - width; if (y - height - 2 < 0) { y += h; if (y < 0) y = 0; } else { y -= height + 2; } if (scr->window_title_texture[0]) XSetForeground(dpy, scr->draw_gc, scr->window_title_texture[0]->any.color.pixel); else XSetForeground(dpy, scr->draw_gc, scr->light_pixel); pixmap = XCreatePixmap(dpy, scr->root_win, width, height, scr->w_depth); XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width, height); drawMultiLineString(scr->wmscreen, pixmap, scr->window_title_color[0], font, 4, 2, text, strlen(text)); XResizeWindow(dpy, scr->balloon->window, width, height); XMoveWindow(dpy, scr->balloon->window, x, y); XSetWindowBackgroundPixmap(dpy, scr->balloon->window, pixmap); XClearWindow(dpy, scr->balloon->window); XMapRaised(dpy, scr->balloon->window); scr->balloon->contents = pixmap; scr->balloon->mapped = 1; }
void WMSetTabViewType(WMTabView * tPtr, WMTabViewType type) { tPtr->flags.type = type; if (type != WTTopTabsBevelBorder) tPtr->tabHeight = 0; else tPtr->tabHeight = WMFontHeight(tPtr->font) + 3; if (type == WTNoTabsNoBorder) tPtr->flags.bordered = 0; else tPtr->flags.bordered = 1; rearrange(tPtr); }
static void updateDockNumbers(virtual_screen *vscr) { int length; char *ws_numbers; WAppIcon *dicon = vscr->dock.dock->icon_array[0]; ws_numbers = wmalloc(20); snprintf(ws_numbers, 20, "%i [ %i ]", vscr->workspace.current + 1, ((vscr->workspace.current / 10) + 1)); length = strlen(ws_numbers); XClearArea(dpy, dicon->icon->core->window, 2, 2, 50, WMFontHeight(vscr->screen_ptr->icon_title_font) + 1, False); WMDrawString(vscr->screen_ptr->wmscreen, dicon->icon->core->window, vscr->screen_ptr->black, vscr->screen_ptr->icon_title_font, 4, 3, ws_numbers, length); WMDrawString(vscr->screen_ptr->wmscreen, dicon->icon->core->window, vscr->screen_ptr->white, vscr->screen_ptr->icon_title_font, 3, 2, ws_numbers, length); wfree(ws_numbers); }
static void drawMultiLineString(WMScreen *scr, Pixmap pixmap, WMColor *color, WMFont *font, int x, int y, const char *text, int len) { const char *p = text; const char *pb = p; int l = 0, pos = 0; int height = WMFontHeight(font); while (*p && p - text < len) { if (*p == '\n') { WMDrawString(scr, pixmap, color, font, x, y + l * height, pb, pos); l++; pos = 0; pb = p + 1; } else { pos++; } p++; } if (pos > 0) WMDrawString(scr, pixmap, color, font, x, y + l * height, pb, pos); }
int W_GetTextHeight(WMFont * font, const char *text, int width, int wrap) { const char *ptr = text; int count; int length = strlen(text); int h; int fheight = WMFontHeight(font); h = 0; while (length > 0) { count = fitText(ptr, font, width, wrap); h += fheight; if (isspace(ptr[count])) count++; ptr += count; length -= count; } return h; }
void W_PaintText(W_View * view, Drawable d, WMFont * font, int x, int y, int width, WMAlignment alignment, WMColor * color, int wrap, const char *text, int length) { const char *ptr = text; int line_width; int line_x; int count; int fheight = WMFontHeight(font); while (length > 0) { count = fitText(ptr, font, width, wrap); line_width = WMWidthOfString(font, ptr, count); if (alignment == WALeft) line_x = x; else if (alignment == WARight) line_x = x + width - line_width; else line_x = x + (width - line_width) / 2; WMDrawString(view->screen, d, color, font, line_x, y, ptr, count); if (wrap && ptr[count] != '\n') y += fheight; while (ptr[count] && ptr[count] == '\n') { y += fheight; count++; } ptr += count; length -= count; } }
static void showWorkspaceName(WScreen * scr, int workspace) { WorkspaceNameData *data; RXImage *ximg; Pixmap text, mask; int w, h; int px, py; char *name = w_global.workspace.array[workspace]->name; int len = strlen(name); int x, y; #ifdef USE_XINERAMA int head; WMRect rect; int xx, yy; #endif if (wPreferences.workspace_name_display_position == WD_NONE || w_global.workspace.count < 2) return; if (scr->workspace_name_timer) { WMDeleteTimerHandler(scr->workspace_name_timer); XUnmapWindow(dpy, scr->workspace_name); XFlush(dpy); } scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY, hideWorkspaceName, scr); if (scr->workspace_name_data) { RReleaseImage(scr->workspace_name_data->back); RReleaseImage(scr->workspace_name_data->text); wfree(scr->workspace_name_data); } data = wmalloc(sizeof(WorkspaceNameData)); data->back = NULL; w = WMWidthOfString(w_global.workspace.font_for_name, name, len); h = WMFontHeight(w_global.workspace.font_for_name); #ifdef USE_XINERAMA head = wGetHeadForPointerLocation(scr); rect = wGetRectForHead(scr, head); if (scr->xine_info.count) { xx = rect.pos.x + (scr->xine_info.screens[head].size.width - (w + 4)) / 2; yy = rect.pos.y + (scr->xine_info.screens[head].size.height - (h + 4)) / 2; } else { xx = (scr->scr_width - (w + 4)) / 2; yy = (scr->scr_height - (h + 4)) / 2; } #endif switch (wPreferences.workspace_name_display_position) { case WD_TOP: #ifdef USE_XINERAMA px = xx; #else px = (scr->scr_width - (w + 4)) / 2; #endif py = WORKSPACE_NAME_DISPLAY_PADDING; break; case WD_BOTTOM: #ifdef USE_XINERAMA px = xx; #else px = (scr->scr_width - (w + 4)) / 2; #endif py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING); break; case WD_TOPLEFT: px = WORKSPACE_NAME_DISPLAY_PADDING; py = WORKSPACE_NAME_DISPLAY_PADDING; break; case WD_TOPRIGHT: px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING); py = WORKSPACE_NAME_DISPLAY_PADDING; break; case WD_BOTTOMLEFT: px = WORKSPACE_NAME_DISPLAY_PADDING; py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING); break; case WD_BOTTOMRIGHT: px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING); py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING); break; case WD_CENTER: default: #ifdef USE_XINERAMA px = xx; py = yy; #else px = (scr->scr_width - (w + 4)) / 2; py = (scr->scr_height - (h + 4)) / 2; #endif break; } XResizeWindow(dpy, scr->workspace_name, w + 4, h + 4); XMoveWindow(dpy, scr->workspace_name, px, py); text = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, scr->w_depth); mask = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, 1); /*XSetForeground(dpy, scr->mono_gc, 0); XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */ XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4); for (x = 0; x <= 4; x++) for (y = 0; y <= 4; y++) WMDrawString(scr->wmscreen, text, scr->white, w_global.workspace.font_for_name, x, y, name, len); XSetForeground(dpy, scr->mono_gc, 1); XSetBackground(dpy, scr->mono_gc, 0); XCopyPlane(dpy, text, mask, scr->mono_gc, 0, 0, w + 4, h + 4, 0, 0, 1 << (scr->w_depth - 1)); /*XSetForeground(dpy, scr->mono_gc, 1); */ XSetBackground(dpy, scr->mono_gc, 1); XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4); WMDrawString(scr->wmscreen, text, scr->white, w_global.workspace.font_for_name, 2, 2, name, len); #ifdef USE_XSHAPE if (w_global.xext.shape.supported) XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask, ShapeSet); #endif XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text); XClearWindow(dpy, scr->workspace_name); data->text = RCreateImageFromDrawable(scr->rcontext, text, None); XFreePixmap(dpy, text); XFreePixmap(dpy, mask); if (!data->text) { XMapRaised(dpy, scr->workspace_name); XFlush(dpy); goto erro; } ximg = RGetXImage(scr->rcontext, scr->root_win, px, py, data->text->width, data->text->height); if (!ximg || !ximg->image) { goto erro; } XMapRaised(dpy, scr->workspace_name); XFlush(dpy); data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL); RDestroyXImage(scr->rcontext, ximg); if (!data->back) { goto erro; } data->count = 10; /* set a timeout for the effect */ data->timeout = time(NULL) + 2 + (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY * data->count) / 1000; scr->workspace_name_data = data; return; erro: if (scr->workspace_name_timer) WMDeleteTimerHandler(scr->workspace_name_timer); if (data->text) RReleaseImage(data->text); if (data->back) RReleaseImage(data->back); wfree(data); scr->workspace_name_data = NULL; scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY + 10 * WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr); }
static void showApercu(WScreen *scr, int x, int y, int height, int width, char *title, Pixmap apercu) { Pixmap pixmap; WMFont *font = scr->info_text_font; int titleHeight = 0; char *shortenTitle = title; if (scr->balloon->contents) XFreePixmap(dpy, scr->balloon->contents); if (wPreferences.miniwin_title_balloon) { shortenTitle = ShrinkString(font, title, width - APERCU_BORDER); titleHeight = countLines(shortenTitle) * WMFontHeight(font) + 4; height += titleHeight; } if (x < 0) x = 0; else if (x + width > scr->scr_width - 1) x = scr->scr_width - width - APERCU_BORDER; if (y - height - 2 < 0) { y += wPreferences.icon_size; if (y < 0) y = 0; } else { y -= height + 2; } if (scr->window_title_texture[0]) XSetForeground(dpy, scr->draw_gc, scr->window_title_texture[0]->any.color.pixel); else XSetForeground(dpy, scr->draw_gc, scr->light_pixel); pixmap = XCreatePixmap(dpy, scr->root_win, width, height, scr->w_depth); XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width, height); if (shortenTitle && wPreferences.miniwin_title_balloon) { drawMultiLineString(scr->wmscreen, pixmap, scr->window_title_color[0], font, APERCU_BORDER, APERCU_BORDER, shortenTitle, strlen(shortenTitle)); wfree(shortenTitle); } XCopyArea(dpy, apercu, pixmap, scr->draw_gc, 0, 0, (wPreferences.icon_size - 1 - APERCU_BORDER) * wPreferences.apercu_size, (wPreferences.icon_size - 1 - APERCU_BORDER) * wPreferences.apercu_size, APERCU_BORDER, APERCU_BORDER + titleHeight); #ifdef SHAPED_BALLOON XShapeCombineMask(dpy, scr->balloon->window, ShapeBounding, 0, 0, None, ShapeSet); #endif XResizeWindow(dpy, scr->balloon->window, width, height); XMoveWindow(dpy, scr->balloon->window, x, y); XSetWindowBackgroundPixmap(dpy, scr->balloon->window, pixmap); XClearWindow(dpy, scr->balloon->window); XMapRaised(dpy, scr->balloon->window); scr->balloon->contents = pixmap; scr->balloon->mapped = 1; }