/* Copyright 2001-2003 by Norbert Freudemann, David Frese */

#include "xlib.h"

s48_ref_t scx_Create_Pixmap_Cursor(s48_call_t call, s48_ref_t display,
				   s48_ref_t src, s48_ref_t mask,
				   s48_ref_t foreground,
				   s48_ref_t background,
				   s48_ref_t x, s48_ref_t y) {
  XColor f, b;
  Cursor xc;
  scx_extract_color(call, foreground, &f);
  scx_extract_color(call, background, &b);
  xc = XCreatePixmapCursor(scx_extract_display(call, display),
			   scx_extract_pixmap(call, src),
			   scx_extract_pixmap(call, mask),
			   &f, &b,
			   s48_extract_long_2(call, x),
			   s48_extract_long_2(call, y));
  return scx_enter_cursor(call, xc);
}

s48_ref_t scx_Create_Glyph_Cursor(s48_call_t call, s48_ref_t display,
	    s48_ref_t src_font, s48_ref_t mask_font, s48_ref_t srcc, 
            s48_ref_t maskc, s48_ref_t foreground, s48_ref_t background) {
  XColor f, b;
  Cursor xc;
  scx_extract_color(call, foreground, &f);
  scx_extract_color(call, background, &b);
  xc = XCreateGlyphCursor(scx_extract_display(call, display),
			  scx_extract_font(call, src_font),
			  scx_extract_font(call, mask_font),
			  s48_extract_long_2(call, srcc),
			  s48_extract_long_2(call, maskc),
			  &f, &b);
  return scx_enter_cursor(call, xc);
}

s48_ref_t scx_Create_Font_Cursor(s48_call_t call, s48_ref_t display, 
            s48_ref_t shape) {
  Cursor xc;
  xc = XCreateFontCursor(scx_extract_display(call, display),
			 s48_extract_long_2(call, shape));
  return scx_enter_cursor(call, xc);
}

s48_ref_t scx_Define_Cursor(s48_call_t call, s48_ref_t display, 
            s48_ref_t window, s48_ref_t cursor) {
  XDefineCursor(scx_extract_display(call, display), 
		scx_extract_window(call, window),
		scx_extract_cursor(call, cursor));
  return s48_unspecific_2(call);
}

s48_ref_t scx_Undefine_Cursor(s48_call_t call, s48_ref_t display, 
			      s48_ref_t window) {
  XUndefineCursor(scx_extract_display(call, display),
		  scx_extract_window(call, window));
  return s48_unspecific_2(call);
}

s48_ref_t scx_Recolor_Cursor(s48_call_t call, s48_ref_t display, 
            s48_ref_t cursor, s48_ref_t foreground, s48_ref_t background) {
  XColor f, b;
  scx_extract_color(call, foreground, &f);
  scx_extract_color(call, background, &b);
  XRecolorCursor(scx_extract_display(call, display),
		 scx_extract_cursor(call, cursor),
		 &f, &b);
  return s48_unspecific_2(call);
}

s48_ref_t scx_Free_Cursor(s48_call_t call, s48_ref_t display, s48_ref_t cursor) {
  XFreeCursor(scx_extract_display(call, display),
	      scx_extract_cursor(call, cursor));
  return s48_unspecific_2(call);
}

void scx_init_cursor(void) {
  S48_EXPORT_FUNCTION(scx_Create_Pixmap_Cursor);
  S48_EXPORT_FUNCTION(scx_Create_Glyph_Cursor);
  S48_EXPORT_FUNCTION(scx_Create_Font_Cursor);
  S48_EXPORT_FUNCTION(scx_Define_Cursor);
  S48_EXPORT_FUNCTION(scx_Undefine_Cursor);
  S48_EXPORT_FUNCTION(scx_Recolor_Cursor);
  S48_EXPORT_FUNCTION(scx_Free_Cursor);
}
