/* xyz */

/*
 * Copyright (c) 1994, 1995, 1997 by Wayne C. Gramlich.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * for any purpose is hereby granted without fee provided that the above
 * copyright notice and this permission are retained.  The author makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

/*
 * This file provide a bunch of interface routines for manipulation
 * an Xlib {GC} object.
 */

#ifndef XLIB_H
#include "xlib.h"
#endif

/* The initial object: */
Xlib_gc_struct xlib_gc___initial_object = {
    &xlib_screen___initial_object,
    0,
    (GC)0
};
Xlib_gc xlib_gc___initial = &xlib_gc___initial_object;

/*
 * xlib_gc__address_get(gc)
 *	This routine will return the address of {gc}.
 */
unsigned
xlib_gc__address_get(
    Xlib_gc gc)
{
    return (unsigned)gc;
}

/*
 * xlib_gc__change(gc, gc_values)
 *	This routine will change the appropriate values in {gc} to {gc_values}.
 */
void
xlib_gc__change(
    Xlib_gc gc,
    Xlib_gc_values gc_values)
{
    Xlib_display display;

    display = gc_values->screen->display;
    if (display->closed) {
	xlib_display___closed(display);
    } else {
	XChangeGC(display->display, gc->gc,
	  gc_values->values_mask, &gc_values->values);
    }
}

/*
 * xlib_gc__create_helper(gc_values, drawable)
 *	This routine will create and return a new graphics context.
 */
Xlib_gc
xlib_gc__create_helper(
    Xlib_gc_values gc_values,
    Drawable drawable,
    unsigned depth)
{
    Xlib_display display;
    Xlib_screen screen;
    Xlib_gc gc;

    gc = xlib_gc___initial;
    screen = gc_values->screen;
    display = screen->display;
    if (display->closed) {
	xlib_display___closed(display);
    } else {
	GC x_gc;

	x_gc = XCreateGC(display->display, drawable,
	  gc_values->values_mask, &gc_values->values);
	gc = (Xlib_gc)malloc(sizeof(*gc));
	(void)memset((void *)gc, 0, sizeof(*gc));
	gc->depth = depth;
	gc->screen = screen;
	gc->gc = x_gc;
    }
    return gc;
}

/*
 * xlib_gc__depth_get(gc)
 *	This routine will return the depth associated with {gc}.
 */
unsigned
xlib_gc__depth_get(
    Xlib_gc gc)
{
    return gc->depth;
}

/*
 * xlib_gc__external__initialize()
 *	This routine will "initialize" the {xlib_gc} external
 *	code.
 */
void
xlib_gc__external__initialize(void)
{
    /* Do nothing! */
}


/*
 * xlib_gc__foreground_set(gc, color)
 *	This procedure will set the foreground pixel value for {gc} to {color}.
 */
void
xlib_gc__foreground_set(
    Xlib_gc gc,
    Xlib_color color)
{
    XSetForeground(gc->screen->display->display, gc->gc, color->color.pixel);
}
