#  Copyright (c) 1990 The Regents of the University of California.
#  Copyright (c) 1994-1996 Sun Microsystems, Inc.
#  See the file "license.terms" for information on usage and redistribution
#  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#

=head1 NAME

Tk_GetCursor, Tk_GetCursorFromData, Tk_NameOfCursor, Tk_FreeCursor - maintain database of cursors

=for category C Programming

=head1 SYNOPSIS

B<#include E<lt>tk.hE<gt>>

Tk_Cursor
B<Tk_GetCursor(>I<interp, tkwin, nameId>B<)>

Tk_Cursor
B<Tk_GetCursorFromData(>I<interp, tkwin, source, mask, width, height, xHot, yHot, fg, bg>B<)>

char *
B<Tk_NameOfCursor(>I<display, cursor>B<)>

B<Tk_FreeCursor(>I<display, cursor>B<)>

=head1 ARGUMENTS

=over 4

=item Tcl_Interp *interp (in)

Interpreter to use for error reporting.

=item Tk_Window tkwin (in)

Token for window in which the cursor will be used.

=item Tk_Uid nameId (in)

Description of cursor;  see below for possible values.

=item char *source (in)

Data for cursor bitmap, in standard bitmap format.

=item char *mask (in)

Data for mask bitmap, in standard bitmap format.

=item "int" width (in)

Width of I<source> and I<mask>.

=item "int" height (in)

Height of I<source> and I<mask>.

=item "int" xHot (in)

X-location of cursor hot-spot.

=item "int" yHot (in)

Y-location of cursor hot-spot.

=item Tk_Uid fg (in)

Textual description of foreground color for cursor.

=item Tk_Uid bg (in)

Textual description of background color for cursor.

=item Display *display (in)

Display for which I<cursor> was allocated.

=item Tk_Cursor cursor (in)

Opaque Tk identifier for cursor.  If passed toB<Tk_FreeCursor>, must
have been returned by some previous call to B<Tk_GetCursor> or
B<Tk_GetCursorFromData>.

=back

=head1 DESCRIPTION

These procedures manage a collection of cursors
being used by an application.  The procedures allow cursors to be
re-used efficiently, thereby avoiding server overhead, and also
allow cursors to be named with character strings (actually Tk_Uids).

B<Tk_GetCursor> takes as argument a Tk_Uid describing a cursor,
and returns an opaque Tk identifier for a cursor corresponding to the
description.
It re-uses an existing cursor if possible and
creates a new one otherwise.  I<NameId> must be a standard Tcl
list with one of the following forms:

=over 4

=item I<name> [I<fgColor> [I<bgColor>]]

I<Name> is the name of a cursor in the standard X cursor font,
i.e., any of the names defined in B<cursorfont.h>, without
the B<XC_>.  Some example values are B<X_cursor>, B<hand2>,
or B<left_ptr>.  Appendix B of ``The X Window System''
by Scheifler E<amp> Gettys has illustrations showing what each of these
cursors looks like.  If I<fgColor> and I<bgColor> are both
specified, they give the foreground and background colors to use
for the cursor (any of the forms acceptable to B<Tk_GetColor>
may be used).  If only I<fgColor> is specified, then there
will be no background color:  the background will be transparent.
If no colors are specified, then the cursor
will use black for its foreground color and white for its background
color.
The Macintosh version of Tk also supports all of the X cursors.
Tk on the Mac will also accept any of the standard Mac cursors
including B<ibeam>, B<crosshair>, B<watch>, B<plus>, and
B<arrow>.  In addition, Tk will load Macintosh cursor resources of
the types B<crsr> (color) and B<CURS> (black and white) by the
name of the of the resource.  The application and all its open
dynamic library's resource files will be searched for the named
cursor.  If there are conflicts color cursors will always be loaded
in preference to black and white cursors.

=item B<@>I<sourceName maskName fgColor bgColor>

In this form, I<sourceName> and I<maskName> are the names of
files describing bitmaps for the cursor's source bits and mask.
Each file must be in standard X11 or X10 bitmap format.
I<FgColor> and I<bgColor>
indicate the colors to use for the
cursor, in any of the forms acceptable to B<Tk_GetColor>.  This
form of the command will not work on Macintosh or Windows computers.

=item B<@>I<sourceName fgColor>

This form is similar to the one above, except that the source is
used as mask also.  This means that the cursor's background is
transparent.  This form of the command will not work on Macintosh
or Windows computers.

B<Tk_GetCursorFromData> allows cursors to be created from
in-memory descriptions of their source and mask bitmaps.  I<Source>
points to standard bitmap data for the cursor's source bits, and
I<mask> points to standard bitmap data describing
which pixels of I<source> are to be drawn and which are to be
considered transparent.  I<Width> and I<height> give the
dimensions of the cursor, I<xHot> and I<yHot> indicate the
location of the cursor's hot-spot (the point that is reported when
an event occurs), and I<fg> and I<bg> describe the cursor's
foreground and background colors textually (any of the forms
suitable for B<Tk_GetColor> may be used).  Typically, the
arguments to B<Tk_GetCursorFromData> are created by including
a cursor file directly into the source code for a program, as in
the following example:

 Tk_Cursor cursor;
 #include "source.cursor"
 #include "mask.cursor"
 cursor = Tk_GetCursorFromData(interp, tkwin, source_bits,
 	mask_bits, source_width, source_height, source_x_hot,
 	source_y_hot, Tk_GetUid("red"), Tk_GetUid("blue"));

Under normal conditions, B<Tk_GetCursor> and B<Tk_GetCursorFromData>
will return an identifier for the requested cursor.  If an error
occurs in creating the cursor, such as when I<nameId> refers
to a non-existent file, then B<None> is returned and an error
message will be stored in I<interp-E<gt>result>.

B<Tk_GetCursor> and B<Tk_GetCursorFromData> maintain a
database of all the cursors they have created.  Whenever possible,
a call to B<Tk_GetCursor> or B<Tk_GetCursorFromData> will
return an existing cursor rather than creating a new one.  This
approach can substantially reduce server overhead, so the Tk
procedures should generally be used in preference to Xlib procedures
like B<XCreateFontCursor> or B<XCreatePixmapCursor>, which
create a new cursor on each call.

The procedure B<Tk_NameOfCursor> is roughly the inverse of
B<Tk_GetCursor>.  If its I<cursor> argument was created
by B<Tk_GetCursor>, then the return value is the I<nameId>
argument that was passed to B<Tk_GetCursor> to create the
cursor.  If I<cursor> was created by a call to B<Tk_GetCursorFromData>,
or by any other mechanism, then the return value is a hexadecimal string
giving the X identifier for the cursor.
Note:  the string returned by B<Tk_NameOfCursor> is
only guaranteed to persist until the next call to
B<Tk_NameOfCursor>.  Also, this call is not portable except for
cursors returned by B<Tk_GetCursor>.

When a cursor returned by B<Tk_GetCursor> or B<Tk_GetCursorFromData>
is no longer needed, B<Tk_FreeCursor> should be called to release it.
There should be exactly one call to B<Tk_FreeCursor> for
each call to B<Tk_GetCursor> or B<Tk_GetCursorFromData>.
When a cursor is no longer in use anywhere (i.e. it has been freed as
many times as it has been gotten) B<Tk_FreeCursor> will release
it to the X server and remove it from the database.

=back

=head1 BUGS

In determining whether an existing cursor can be used to satisfy
a new request, B<Tk_GetCursor> and B<Tk_GetCursorFromData>
consider only the immediate values of their arguments.  For
example, when a file name is passed to B<Tk_GetCursor>,
B<Tk_GetCursor> will assume it is safe to re-use an existing
cursor created from the same file name:  it will not check to
see whether the file itself has changed, or whether the current
directory has changed, thereby causing the name to refer to
a different file.  Similarly, B<Tk_GetCursorFromData> assumes
that if the same I<source> pointer is used in two different calls,
then the pointers refer to the same data;  it does not check to
see if the actual data values have changed.

=head1 KEYWORDS

cursor
