/********************************************************************
This file is part of the abs 0.907 distribution.  abs is a spreadsheet
with graphical user interface.

Copyright (C) 1998-2001  André Bertin (Andre.Bertin@ping.be) 

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version if in the same spirit as version 2.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Concact: abs@pi.be
         http://home.pi.be/bertin/abs.shtml

*********************************************************************/




























#include "cursor.h"
#include <X11/cursorfont.h>


static int CURSOR = 0;

int 
getcursortype ()
{
  return CURSOR;
};

int 
setcursortype (cursor_type type)
{
  









  return 0;
}

void
TurnOnCross (
	      Widget w)
{
  Cursor cursor;
  cursor = XCreateFontCursor (XtDisplay (w), XC_sizing);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = CROSS;
}

void
TurnOnSpray (
	      Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_spraycan);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = SPRAY;
}

void
TurnOnPencil (Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_pencil);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = PENCIL;
}


void
TurnOnMove (
	     Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_fleur);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = CMOVE;
}

void
TurnOnHand (
	     Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_hand1);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = HAND;
}

void
TurnOnBottomLeft (
		   Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_bottom_left_corner);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = BOTTOM_LEFT;
}

void
TurnOnBottomRight (
		    Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_bottom_right_corner);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = BOTTOM_RIGHT;
}
void
TurnOnTopLeft (
		Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_top_left_corner);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = TOP_LEFT;
}
void
TurnOnTopRight (
		 Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_top_right_corner);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = TOP_RIGHT;
}
void
TurnOnTopSide (
		Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_top_side);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = TOP_SIDE;
}
void
TurnOnLeftSide (
		 Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_left_side);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = LEFT_SIDE;
}
void
TurnOnRightSide (
		  Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_right_side);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = RIGHT_SIDE;
}
void
TurnOnBottomSide (
		   Widget w)
{
  Cursor cursor;

  cursor = XCreateFontCursor (XtDisplay (w), XC_bottom_side);
  XDefineCursor (XtDisplay (w), XtWindow (w), cursor);
  XFlush (XtDisplay (w));
  CURSOR = BOTTOM_SIDE;
}



void
TurnOffMove (
	      Widget w)

{

  XUndefineCursor (XtDisplay (w), XtWindow (w));
  XFlush (XtDisplay (w));
  CURSOR = ARROW;
}



void
TurnOffCursor (
		Widget w)
{

  XUndefineCursor (XtDisplay (w), XtWindow (w));
  XFlush (XtDisplay (w));
  CURSOR = ARROW;
}

void
TurnOffCross (
	       Widget w)

{

  XUndefineCursor (XtDisplay (w), XtWindow (w));
  XFlush (XtDisplay (w));
  CURSOR = ARROW;
}

int 
TurnOnLimitCursor (Widget draw, int xa, int ya, int xb, int yb, int x, int y)
{
  if (xa - 4 <= x && x <= xa + 4 && yb - 4 <= y && y <= yb + 4)
    {
      if (CURSOR != BOTTOM_LEFT)
	TurnOnBottomLeft (draw);
      return BOTTOM_LEFT;
    }
  else if (CURSOR == BOTTOM_LEFT)
    {
      TurnOffCursor (draw);
    }
  if (xb - 4 <= x && x <= xb + 4 && yb - 4 <= y && y <= yb + 4)
    {
      if (CURSOR != BOTTOM_RIGHT)
	TurnOnBottomRight (draw);
      return BOTTOM_RIGHT;
    }
  else if (CURSOR == BOTTOM_RIGHT)
    {
      TurnOffCursor (draw);
    }
  if (xa - 4 <= x && x <= xa + 4 && ya - 4 <= y && y <= ya + 4)
    {
      if (CURSOR != TOP_LEFT)
	TurnOnTopLeft (draw);
      return TOP_LEFT;
    }
  else if (CURSOR == TOP_LEFT)
    {
      TurnOffCursor (draw);
    }
  if (xb - 4 <= x && x <= xb + 4 && ya - 4 <= y && y <= ya + 4)
    {
      if (CURSOR != TOP_RIGHT)
	TurnOnTopRight (draw);
      return TOP_RIGHT;
    }
  else if (CURSOR == TOP_RIGHT)
    {
      TurnOffCursor (draw);
    }
  if ((xa + xb) / 2 - 4 <= x && x <= (xa + xb) / 2 + 4 && yb - 4 <= y && y <= yb + 4)
    {
      if (CURSOR != BOTTOM_SIDE)
	TurnOnBottomSide (draw);
      return BOTTOM_SIDE;
    }
  else if (CURSOR == BOTTOM_SIDE)
    {
      TurnOffCursor (draw);
    }
  if (xb - 4 <= x && x <= xb + 4 && (yb + ya) / 2 - 4 <= y && y <= (yb + ya) / 2 + 4)
    {
      if (CURSOR != RIGHT_SIDE)
	TurnOnRightSide (draw);
      return RIGHT_SIDE;
    }
  else if (CURSOR == RIGHT_SIDE)
    {
      TurnOffCursor (draw);
    }
  if ((xa + xb) / 2 - 4 <= x && x <= (xa + xb) / 2 + 4 && ya - 4 <= y && y <= ya + 4)
    {
      if (CURSOR != TOP_SIDE)
	TurnOnTopSide (draw);
      return TOP_SIDE;
    }
  else if (CURSOR == TOP_SIDE)
    {
      TurnOffCursor (draw);
    }
  if (xa - 4 <= x && x <= xa + 4 && (yb + ya) / 2 - 4 <= y && y <= (yb + ya) / 2 + 4)
    {
      if (CURSOR != LEFT_SIDE)
	TurnOnLeftSide (draw);
      return LEFT_SIDE;
    }
  else if (CURSOR == LEFT_SIDE)
    {
      TurnOffCursor (draw);
    }









  TurnOffCursor (draw);


  return CURSOR;
}












































