/* %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_size_hints_struct xlib_size_hints___initial_object; /* Init. to zeros */
Xlib_size_hints xlib_size_hints___initial = &xlib_size_hints___initial_object;

/*
 * xlib_size_hints__address_get(xlib_size_hints)
 *	This routine will return the address of {size_hints}.
 */
unsigned
xlib_size_hints__address_get(
    Xlib_size_hints xlib_size_hints)
{
    return (unsigned)xlib_size_hints;
}

 /*
 * xlib_size_hints__erase(xlib_size_hints)
 *	This routine will erase the contents of {xlib_size_hints}.
 */
void
xlib_size_hints__erase(
    Xlib_size_hints xlib_size_hints)
{
    if (xlib_size_hints != xlib_size_hints___initial) {
	xlib_size_hints->flags = PPosition | PSize;
	xlib_size_hints->width = 200;
	xlib_size_hints->height = 200;
    }
}

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

/*
 * xib_size_hints__maximum_size_set(xlib_size_hints, width, height)
 *	This procedure will set the maximum width and and height
 *	to {width} and {height} in {xlib_size_hints}.
 */
void
xlib_size_hints__maximum_size_set(
    Xlib_size_hints xlib_size_hints,
    unsigned width,
    unsigned height)
{
    if (xlib_size_hints != xlib_size_hints___initial) {
	xlib_size_hints->flags |= PMaxSize;
	xlib_size_hints->max_width = width;
	xlib_size_hints->max_height = height;
    }
}

/*
 * xib_size_hints__minimum_size_set(xlib_size_hints, width, height)
 *	This procedure will set the minimum width and and height
 *	to {width} and {height} in {xlib_size_hints}.
 */
void
xlib_size_hints__minimum_size_set(
    Xlib_size_hints xlib_size_hints,
    unsigned width,
    unsigned height)
{
    if (xlib_size_hints != xlib_size_hints___initial) {
	xlib_size_hints->flags |= PMinSize;
	xlib_size_hints->min_width = width;
	xlib_size_hints->min_height = height;
    }
}

/*
 * xlib_size_hints__allocate()
 *	This routine will allocate and return an erased {xlib_size_hints}
 *	object.
 */
Xlib_size_hints
xlib_size_hints__allocate(void)
{
    Xlib_size_hints xlib_size_hints;

    xlib_size_hints =
      (Xlib_size_hints)malloc(sizeof(*xlib_size_hints));
    xlib_size_hints__erase(xlib_size_hints);
    return xlib_size_hints;
}

/*
 * xlib_size_hints___print_number(label1, number1, prefix, out_stream)
 *	This routine will output {label1}, and {number1}, to {out_stream}.
 *	{label1} will be prceeded by {prefix}.
 */
void
xlib_size_hints___print_number1(
    Str label,
    unsigned number,
    Str prefix,
    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);
    unsigned__print(number, out_stream);
}

/*
 * xlib_size_hints___print_number2(label1, number1,
 *   label2, number2, prefix, out_stream)
 *	This routine will output {label1}, {number1}, {label2}, and
 *	{number2} to {out_stream}.  {label1} will be prceeded by {prefix}.
 */
void
xlib_size_hints___print_number2(
    Str label1,
    unsigned number1,
    Str label2,
    unsigned number2,
    Str prefix,
    Out_stream out_stream)
{
    xlib_size_hints___print_number1(label1, number1, prefix, out_stream);
    xlib_size_hints___print_number1(label2, number2, ", ", out_stream);
}

/*
 * xlib_size_hints__print(xlib_size_hints, out_stream)
 *	This routine will output the contents of {xlib_size_hints} to
 *	{out_stream}.
 */
void
xlib_size_hints__print(
    Xlib_size_hints xlib_size_hints,
    Out_stream out_stream)
{
    char buffer[128];

    if (xlib_size_hints == xlib_size_hints___initial) {
	string__put(string__unix_str("{??@xlib_size_hints",
	  buffer), out_stream);
    } else {
	Str separator;

	separator = "";
	string__put(string__unix_str("{", buffer), out_stream);
	if ((xlib_size_hints->flags & PMinSize) != 0) {
	    xlib_size_hints___print_number2("minimum_width",
	      xlib_size_hints->min_width, "minimum_height",
	      xlib_size_hints->min_height, separator, out_stream);
	    separator = ", ";
	}
	if ((xlib_size_hints->flags & PMaxSize) != 0) {
	    xlib_size_hints___print_number2("maximum_width",
	      xlib_size_hints->max_width, "maximum_height",
	      xlib_size_hints->max_height, separator, out_stream);
	    separator = ", ";
	}
	if ((xlib_size_hints->flags & PResizeInc) != 0) {
	    xlib_size_hints___print_number2("width_increment",
	      xlib_size_hints->width_inc, "height_increment",
	      xlib_size_hints->height_inc, separator, out_stream);
	    separator = ", ";
	}
	string__put(string__unix_str("}", buffer), out_stream);
    }
}

/*
 * xib_size_hints__resize_increments_set(xlib_size_hints,
 *    width_increment, height_increment)
 *	This procedure will set the resize increments inside of
 *	{xlib_size_hints} to {width_increment} and {height_increment}.
 */
void
xlib_size_hints__resize_increments_set(
    Xlib_size_hints xlib_size_hints,
    unsigned width_increment,
    unsigned height_increment)
{
    if (xlib_size_hints != xlib_size_hints___initial) {
	xlib_size_hints->flags |= PResizeInc;
	xlib_size_hints->width_inc = width_increment;
	xlib_size_hints->height_inc = height_increment;
    }
}

