Ejemplo n.º 1
0
/*ARGSUSED*/
static void
ClearToBackground(Widget w, int x, int y,
		  unsigned int width, unsigned int height)
{
    /* 
     * Don't clear in height or width are zero
     * XClearArea() has special semantic for these values
     */
    TextWidget xaw = (TextWidget)XtParent(w);
    Position x1, y1, x2, y2;

    x1 = XawMax(x, xaw->text.r_margin.left);
    y1 = XawMax(y, xaw->text.r_margin.top);
    x2 = XawMin(x + (int)width, (int)XtWidth(xaw) - xaw->text.r_margin.right);
    y2 = XawMin(y + (int)height, (int)XtHeight(xaw) - xaw->text.r_margin.bottom);

    x = x1;
    y = y1;
    width = XawMax(0, x2 - x1);
    height = XawMax(0, y2 - y1);

    if (height != 0 && width != 0)
	XClearArea(XtDisplayOfObject(w), XtWindowOfObject(w),
		   x, y, width, height, False);
}
/* Paint the thumb in the area specified by w->top and
   w->shown.  The old area is erased.  The painting and
   erasing is done cleverly so that no flickering will occur. */
static void
PaintThumb(ScrollbarWidget w)
{
    Position oldtop, oldbot, newtop, newbot;

    oldtop = w->scrollbar.topLoc;
    oldbot = oldtop + w->scrollbar.shownLength;
    newtop = w->scrollbar.length * w->scrollbar.top;
    newbot = newtop + (int)(w->scrollbar.length * w->scrollbar.shown);
    if (newbot < newtop + (int)w->scrollbar.min_thumb)
	newbot = newtop + w->scrollbar.min_thumb;
    w->scrollbar.topLoc = newtop;
    w->scrollbar.shownLength = newbot - newtop;

    if (XtIsRealized((Widget)w)) {
	if (newtop < oldtop)
	    FillArea(w, newtop, XawMin(newbot, oldtop), 1);
	if (newtop > oldtop)
	    FillArea(w, oldtop, XawMin(newtop, oldbot), 0);
	if (newbot < oldbot)
	    FillArea(w, XawMax(newbot, oldtop), oldbot, 0);
	if (newbot > oldbot)
	    FillArea(w, XawMax(newtop, oldbot), newbot, 1);
    }
}
static void
FillArea(ScrollbarWidget w, int top, int bottom, int thumb)
{
    Dimension length;

    top = XawMax(1, top);
    if (w->scrollbar.orientation == XtorientHorizontal)
    bottom = XawMin(bottom, XtWidth(w) - 1);
    else
    bottom = XawMin(bottom, XtHeight(w) - 1);

    if (bottom <= top)
	return;

    length = bottom - top;

    switch(thumb) {
	/* Fill the new Thumb location */
	case 1:
	    if (w->scrollbar.orientation == XtorientHorizontal)
		XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc,
			       top, 1, length, XtHeight(w) - 2);
	    else
		XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc,
			       1, top, XtWidth(w) - 2, length);
	    break;
	/* Clear the old Thumb location */
	case 0:
	    if (w->scrollbar.orientation == XtorientHorizontal)
		XClearArea(XtDisplay(w), XtWindow(w),
			   top, 1, length, XtHeight(w) - 2, False);
	    else
		XClearArea(XtDisplay(w), XtWindow(w),
			   1, top, XtWidth(w) - 2, length, False);
	    break;
    }
}
Ejemplo n.º 4
0
static void
SetXlfdDefaults(Display *display, XawTextProperty *property)
{
    Atom atom = XInternAtom(display, "FONT", True);
    unsigned long value;
    char *str;

    if (XGetFontProperty(property->font, atom, &value)) {
	char *xlfd = XGetAtomName(display, value);

	if (xlfd) {
	    char *sep = xlfd + 1;
	    char *name = sep;

	    property->xlfd = XrmStringToQuark(xlfd);

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->foundry = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');	*sep++ = '\0';
	    property->family = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');	*sep++ = '\0';
	    property->weight = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');	*sep++ = '\0';
	    property->slant = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');	*sep++ = '\0';
	    property->setwidth = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->addstyle = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->pixel_size = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->point_size = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->res_x = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->res_y = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->spacing = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->avgwidth = XrmStringToQuark(name);
	    name = sep;

	    sep = strchr(sep, '-');     *sep++ = '\0';
	    property->registry = XrmStringToQuark(name);
	    name = sep;

	    property->encoding = XrmStringToQuark(name);

	    XFree(xlfd);
	}
    }

    atom = XInternAtom(display, "UNDERLINE_THICKNESS", True);
    if (XGetFontProperty(property->font, atom, &value) &&
	(str = XGetAtomName(display, value)) != NULL) {
	property->underline_thickness = atoi(str);
	XFree(str);
    }
    else {
	/* XLFD says:
	 * CapStemWidth = average width of the stems of capitals
	 * if (UNDERLINE_THICKNESS undefined) then
	 *   UNDERLINE_THICKNESS = CapStemWidth
	 *
	 * How do I know the value of CapStemWidth??
	 */
	if (property->pixel_size != NULLQUARK) {
	    property->underline_thickness =
		atoi(XrmQuarkToString(property->pixel_size)) / 10;
	    property->underline_thickness =
		XawMax(1, property->underline_thickness);
	}
	else
	    property->underline_thickness = 1;
    }

    atom = XInternAtom(display, "UNDERLINE_POSITION", True);
    if (XGetFontProperty(property->font, atom, &value) &&
	(str = XGetAtomName(display, value)) != NULL) {
	property->underline_position = atoi(str);
	XFree(str);
    }
    else
	/* XLFD says:
	 * if (UNDERLINE_POSITION undefined) then
	 *   UNDERLINE_POSITION = ROUND((maximum_descent) / 2)
	 */
	property->underline_position =
	    property->font->max_bounds.descent >> 1;

    /* I am assuming xlfd does not consider that lines are
     * centered in the path */
    property->underline_position += property->underline_thickness >> 1;

}