예제 #1
0
/*	Function Name: PaintText
 *	Description: Actually paints the text into the windoe.
 *	Arguments: w - the text widget.
 *                 gc - gc to paint text with.
 *                 x, y - location to paint the text.
 *                 buf, len - buffer and length of text to paint.
 *	Returns: the width of the text painted, or 0.
 *
 * NOTE:  If this string attempts to paint past the end of the window
 *        then this function will return zero.
 */
static Dimension
PaintText(Widget w, GC gc, Position x, Position y, wchar_t *buf, int len)
{
    MultiSinkObject sink = (MultiSinkObject) w;
    TextWidget ctx = (TextWidget) XtParent(w);

    XFontSet fontset = sink->multi_sink.fontset;
    Position max_x;
    Dimension width = (Dimension) XwcTextEscapement(fontset, buf, len);
    XFontSetExtents *ext = XExtentsOfFontSet(fontset);
    max_x = (Position) ctx->core.width;

    if (((int) width) <= -x)	/* Don't draw if we can't see it. */
	return (width);

    XwcDrawImageString(XtDisplay(ctx), XtWindow(ctx), fontset, gc,
		       (int) x, (int) y, buf, len);
    if ((((Position) width + x) > max_x) && (ctx->text.margin.right != 0)) {
	x = (Position) (ctx->core.width - ctx->text.margin.right);
	width = (Dimension) ctx->text.margin.right;
	XFillRectangle(XtDisplay((Widget) ctx), XtWindow((Widget) ctx),
		       sink->multi_sink.normgc, (int) x,
		       (int) y - abs(ext->max_logical_extent.y),
		       (unsigned int) width,
		       (unsigned int) ext->max_logical_extent.height);
	return (0);
    }
    return (width);
}
예제 #2
0
파일: terma.c 프로젝트: halhen/terma
void
x_drawline(size_t col, size_t row, wchar_t *text, size_t length, color_t fg, color_t bg, bool bold, bool underline)
{
	XSetForeground(X.dpy,
                   X.gc,
                   fg);
	XSetBackground(X.dpy,
                   X.gc,
                   bg);

    size_t xpix  = col    * X.glyph_width;
    size_t width = length * X.glyph_width;
    size_t ypix  = row * X.glyph_height + X.glyph_ascent;

    XwcDrawImageString(X.dpy,
                       X.pixmap,
                       bold ? X.bold_font : X.font,
                       X.gc,
                       xpix,
                       ypix,
                       text,
                       length);
    if (underline) {
        XDrawLine(X.dpy,
                  X.pixmap,
                  X.gc,
                  xpix,
                  ypix + 1,
                  xpix + width - 1,
                  ypix + 1);
    }
}
예제 #3
0
void TStatusPanel_STD::update(Status_Pack * sp)
{
	TIMC * imc = sp->imc;

	XClearWindow(TWinMan::get_display(), id());

	uint16_t x = 2;
	uint16_t y = fontset->ascent() + 2;

	if (imc == NULL){
		im_desc.copy(sp->im_desc[0]);
#ifdef MDK_PATCH
		char dummy[10];
		im_desc.tombs(dummy, 4);
		XmbDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, dummy, strlen(dummy));
#else
		XwcDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, &im_desc[0], 1);
#endif
		return;
		}

	if (!imc->enabled()){
#ifdef MDK_PATCH
		XmbDrawImageString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, "En", 2);
#else
		XwcDrawImageString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, L"En", 2);
#endif
		return;
		}

	if (imc->is_mb_input()){
		//XFillArc(display, stat_win, stat_gc, space_width, space_heigth, font_width * 2, font_height, 0, (360 * 64));
		XFillRectangle(TWinMan::get_display(), id(), stat_gc->id(), 2, 2, fontset->width() * 2 + 1, fontset->height() + 1);
		}else{
			XPoint p[3];
			p[0].x = 2;
			p[0].y = 2;
			p[1].x = fontset->width() * 2 + 3;
			p[1].y = 2;
			p[2].x = 2;
			p[2].y = fontset->height() + 3;
			//XFillArc(display, stat_win, stat_gc, space_width, space_heigth, font_width * 2, font_height, (45 * 64), (225 * 64));
			XFillPolygon(TWinMan::get_display(), id(), stat_gc->id(), p, 3, Convex,CoordModeOrigin);
			}

	im_desc.copy(sp->im_desc[0]);
#ifdef MDK_PATCH
	char dummy[10];
	im_desc.tombs(dummy, 4);
	XmbDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, dummy, strlen(dummy));
#else
	XwcDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, &im_desc[0], 1);
#endif
}
/*
 * Function:
 *	PaintText
 *
 * Parameters:
 *	w   - text sink object
 *	gc  - gc to paint text
 *	x   - location to paint the text
 *	y   - ""
 *	buf - buffer and length of text to paint
 *	len - ""
 *	clear_bg - clear background before drawing ?
 *
 * Description:
 *	Actually paints the text into the window.
 *
 * Returns:
 *	The width of the text painted
 */
static unsigned int
PaintText(Widget w, GC gc, int x, int y, wchar_t *buf, int len, Bool clear_bg)
{
    MultiSinkObject sink = (MultiSinkObject)w;
    TextWidget ctx = (TextWidget)XtParent(w);
    XFontSet fontset = sink->multi_sink.fontset;
    unsigned int width = XwcTextEscapement(fontset, buf, len);

    if (((int)width) <= -x)		/* Don't draw if we can't see it */
	return (width);

    if (clear_bg) {
	XFontSetExtents *ext = XExtentsOfFontSet(fontset);

	_XawTextSinkClearToBackground(w, x, y - abs(ext->max_logical_extent.y),
				      width, ext->max_logical_extent.height);
	XwcDrawString(XtDisplay(ctx), XtWindow(ctx), fontset, gc, x, y, buf, len);
    }
    else
	XwcDrawImageString(XtDisplay(ctx), XtWindow(ctx), fontset, gc,
			   x, y, buf, len);

    return (width);
}
/*
 * The following procedure manages the "insert" cursor
 */
static void
InsertCursor(Widget w, int x, int y, XawTextInsertState state)
{
    MultiSinkObject sink = (MultiSinkObject)w;
    XFontSet fontset = sink->multi_sink.fontset;
    Widget ctx = XtParent(w);
    XawTextPosition position = XawTextGetInsertionPoint(ctx);

    if (XtIsRealized(ctx)) {
	int fheight, fdiff;
	XawTextBlock block;
	wchar_t c;
	XawTextPosition selection_start, selection_end;
	Boolean has_selection;
	XFontSetExtents *ext = XExtentsOfFontSet(fontset);

	XawTextGetSelectionPos((Widget)ctx, &selection_start, &selection_end);
	has_selection = selection_start != selection_end;

	fheight = ext->max_logical_extent.height;
	fdiff = fheight - abs(ext->max_logical_extent.y);

	if ((sink->multi_sink.cursor_position != position || state == XawisOff)
	    && !has_selection && sink->multi_sink.laststate != XawisOff) {
	    wchar_t *ochar;

	    (void)XawTextSourceRead(XawTextGetSource(ctx),
				    sink->multi_sink.cursor_position,
				    &block, 1);
	    if (!block.length)
		ochar = NULL;
	    else {
		c = ((wchar_t *)block.ptr)[0];
		if (c == _Xaw_atowc(XawLF))
		    ochar = NULL;
		else if (c == _Xaw_atowc(XawTAB))
		    ochar = wspace;
		else
		    ochar = (wchar_t *)block.ptr;
	    }

	    if (!ochar)
		_XawTextSinkClearToBackground(w, sink->multi_sink.cursor_x,
					      (sink->multi_sink.cursor_y - 1 -
					      fheight), CharWidth(sink, fontset,
								  0, wspace[0]),
					      fheight);
	    else {
		if (XwcTextEscapement(sink->multi_sink.fontset, ochar, 1) != 0)
		    DisplayText(w, sink->multi_sink.cursor_x,
				sink->multi_sink.cursor_y - 1 - fheight,
				sink->multi_sink.cursor_position,
				sink->multi_sink.cursor_position + 1,
				False);
		else
		    PaintText(w, sink->multi_sink.normgc,
			      sink->multi_sink.cursor_x,
			      sink->multi_sink.cursor_y - 1 - fdiff,
			      ochar, 1,
			      ctx->core.background_pixmap != XtUnspecifiedPixmap);
	    }
	}

	if (!has_selection && state != XawisOff) {
	    wchar_t *nchar;
	    Boolean focus = ((TextWidget)ctx)->text.hasfocus;

	    (void)XawTextSourceRead(XawTextGetSource(ctx),
				    position, &block, 1);
	    c = ((wchar_t *)block.ptr)[0];
	    if (!block.length || c == _Xaw_atowc(XawLF)
		|| c == _Xaw_atowc(XawTAB))
		nchar = wspace;
	    else
		nchar = (wchar_t *)block.ptr;

	    if (focus) {
		if (XwcTextEscapement(sink->multi_sink.fontset, nchar, 1) != 0)
		    XwcDrawImageString(XtDisplay(ctx), XtWindow(ctx),
				       fontset, sink->multi_sink.invgc,
				       x, (y - 1 - fdiff), nchar, 1);
		else
		    DisplayText(w, x, y - 1 - fheight,
				position, position + 1, True);
	    }
	    else
		XDrawRectangle(XtDisplay(ctx), XtWindow(ctx),
			       sink->multi_sink.xorgc ?
			       sink->multi_sink.xorgc : sink->multi_sink.normgc,
			       x, y - 1 - fheight,
			       CharWidth(sink, fontset, 0, *nchar) - 1,
			       fheight - 1);
	  }
      }

    sink->multi_sink.cursor_x = x;
    sink->multi_sink.cursor_y = y;
    sink->multi_sink.laststate = state;
    sink->multi_sink.cursor_position = position;
}