/* %Z%%M% %I% %E% */

/*
 * Copyright (c) 1994-2009 by Wayne C. Gramlich.
 * All rights reserved.
 */

/*
 * This file provide a bunch of interface routines for accessing objects
 * of type Display from Xlib from STIPPLE code.
 */

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

/* The initial object: */
Xlib_wm_hints_struct xlib_wm_hints___initial_object; /* Init. to zeros */
Xlib_wm_hints xlib_wm_hints___initial = &xlib_wm_hints___initial_object;

/*
 * xlib_wm_hints__address_get(xlib_wm_hints)
 *	This routine will return the address of {wm_hints}.
 */
unsigned
xlib_wm_hints__address_get(
    Xlib_wm_hints xlib_wm_hints)
{
    return (unsigned)xlib_wm_hints;
}

 /*
 * xlib_wm_hints__erase(xlib_wm_hints)
 *	This routine will erase the contents of {xlib_wm_hints}.
 */
void
xlib_wm_hints__erase(
    Xlib_wm_hints xlib_wm_hints)
{
    if (xlib_wm_hints != xlib_wm_hints___initial) {
	xlib_wm_hints->wm_hints.flags = 0;
    }
}

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

/*
 * xib_wm_hints__initial_state_set(wm_hints, state)
 *	This procedure will set the state in {wm_hints} to {initial_state}.
 */
void
xlib_wm_hints__initial_state_set(
    Xlib_wm_hints wm_hints,
    unsigned initial_state)
{
    extern unsigned xlib_wm_state__normal;
    extern unsigned xlib_wm_state__iconic;

    if (wm_hints != xlib_wm_hints___initial) {
	if (initial_state == xlib_wm_state__normal) {
	    wm_hints->wm_hints.initial_state = NormalState;
	} else if (initial_state == xlib_wm_state__iconic) {
	    wm_hints->wm_hints.initial_state = IconicState;
	} else {
	    assert(0);
	}
	wm_hints->initial_state = initial_state;
	wm_hints->wm_hints.flags |= StateHint;
    }
}

/*
 * xib_wm_hints__input_set(wm_hints, input)
 *	This procedure will set input field in {wm_hints} to {input}.
 */
void
xlib_wm_hints__input_set(
    Xlib_wm_hints wm_hints,
    int input)
{
    if (wm_hints != xlib_wm_hints___initial) {
	wm_hints->wm_hints.input = input;
       	wm_hints->wm_hints.flags |= InputHint;
    }
}

/*
 * xlib_wm_hints__create(screen)
 *	This routine will allocate and return an erased {xlib_wm_hints}
 *	object and associated with {screen}.
 */
Xlib_wm_hints
xlib_wm_hints__create(
    Xlib_screen screen)
{
    Xlib_wm_hints wm_hints;

    wm_hints = (Xlib_wm_hints)malloc(sizeof(*wm_hints));
    wm_hints->wm_hints.flags = 0;
    wm_hints->screen = screen;
    return wm_hints;
}

/*
 * xlib_wm_hints___label_print(prefix, label, out_stream)
 *	This routine will output {prefix} and {label}, to {out_stream}.
 */
Str
xlib_wm_hints___label_print(
    Str prefix,
    Str label,
    Out_stream out_stream)
{
    char buffer[128];

    string__put(string__unix_str(prefix, buffer), out_stream);
    string__put(string__unix_str(label, buffer), out_stream);
    string__put(string__unix_str("=", buffer), out_stream);
    return ", ";
}

/*
 * xlib_wm_hints__print(wm_hints, out_stream)
 *	This routine will output the contents of {xlib_wm_hints} to
 *	{out_stream}.
 */
void
xlib_wm_hints__print(
    Xlib_wm_hints wm_hints,
    Out_stream out_stream)
{
    char buffer[128];

    if (wm_hints == xlib_wm_hints___initial) {
	string__put(string__unix_str("{??@xlib_wm_hints", buffer), out_stream);
    } else {
	Str prefix;
	unsigned flags;

	flags = wm_hints->wm_hints.flags;
	prefix = "";
	string__put(string__unix_str("{", buffer), out_stream);
	if ((flags & StateHint) != 0) {
	    extern void xlib_wm_state__print(unsigned, Out_stream);

	    prefix =
	      xlib_wm_hints___label_print(prefix, "initial_state", out_stream);
	    xlib_wm_state__print(wm_hints->initial_state, out_stream);
	}
	if ((flags & InputHint) != 0) {
	    extern void logical__print(int, Out_stream);

	    prefix = xlib_wm_hints___label_print(prefix, "input", out_stream);
	    logical__print(wm_hints->wm_hints.input, out_stream);
	}
	if ((flags & IconPixmapHint) != 0) {
	    extern xlib_pixmap__print(Xlib_pixmap, Out_stream);

	    prefix =
	      xlib_wm_hints___label_print(prefix, "icon_pixmap", out_stream);
	    xlib_pixmap__print(wm_hints->icon_pixmap, out_stream);
	}
	string__put(string__unix_str("}", buffer), out_stream);
    }
}

/*
 * xib_wm_hints__icon_pixmap_set(wm_hints, icon_pixmap)
 *	This routine will set the icom pixmap in {wm_hints} to {icon_pixmap}.
 */
void
xlib_wm_hints__icon_pixmap_set(
    Xlib_wm_hints wm_hints,
    Xlib_pixmap icon_pixmap)
{
    if (wm_hints != xlib_wm_hints___initial) {
	if (icon_pixmap->screen == wm_hints->screen) {
	    wm_hints->wm_hints.icon_pixmap = icon_pixmap->pixmap;
	    wm_hints->icon_pixmap = icon_pixmap;
	    wm_hints->wm_hints.flags |= IconPixmapHint;
	} else {
	    /* assert(0); */
	}
    }
}













