2 * Copyright 1989 Massachusetts Institute of Technology
4 * Permission to use, copy, modify, and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in advertising
9 * or publicity pertaining to distribution of the software without specific,
10 * written prior permission. M.I.T. makes no representations about the
11 * suitability of this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
14 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
16 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 /***********************************************************************
24 * $XConsortium: cursor.c,v 1.10 89/12/14 14:52:23 jim Exp $
26 * cursor creation code
28 * 05-Apr-89 Thomas E. LaStrange File created
30 ***********************************************************************/
38 void NewBitmapCursor();
40 static struct _CursorName {
46 {"X_cursor", XC_X_cursor, None},
47 {"arrow", XC_arrow, None},
48 {"based_arrow_down", XC_based_arrow_down, None},
49 {"based_arrow_up", XC_based_arrow_up, None},
50 {"boat", XC_boat, None},
51 {"bogosity", XC_bogosity, None},
52 {"bottom_left_corner", XC_bottom_left_corner, None},
53 {"bottom_right_corner", XC_bottom_right_corner, None},
54 {"bottom_side", XC_bottom_side, None},
55 {"bottom_tee", XC_bottom_tee, None},
56 {"box_spiral", XC_box_spiral, None},
57 {"center_ptr", XC_center_ptr, None},
58 {"circle", XC_circle, None},
59 {"clock", XC_clock, None},
60 {"coffee_mug", XC_coffee_mug, None},
61 {"cross", XC_cross, None},
62 {"cross_reverse", XC_cross_reverse, None},
63 {"crosshair", XC_crosshair, None},
64 {"diamond_cross", XC_diamond_cross, None},
65 {"dot", XC_dot, None},
66 {"dotbox", XC_dotbox, None},
67 {"double_arrow", XC_double_arrow, None},
68 {"draft_large", XC_draft_large, None},
69 {"draft_small", XC_draft_small, None},
70 {"draped_box", XC_draped_box, None},
71 {"exchange", XC_exchange, None},
72 {"fleur", XC_fleur, None},
73 {"gobbler", XC_gobbler, None},
74 {"gumby", XC_gumby, None},
75 {"hand1", XC_hand1, None},
76 {"hand2", XC_hand2, None},
77 {"heart", XC_heart, None},
78 {"icon", XC_icon, None},
79 {"iron_cross", XC_iron_cross, None},
80 {"left_ptr", XC_left_ptr, None},
81 {"left_side", XC_left_side, None},
82 {"left_tee", XC_left_tee, None},
83 {"leftbutton", XC_leftbutton, None},
84 {"ll_angle", XC_ll_angle, None},
85 {"lr_angle", XC_lr_angle, None},
86 {"man", XC_man, None},
87 {"middlebutton", XC_middlebutton, None},
88 {"mouse", XC_mouse, None},
89 {"pencil", XC_pencil, None},
90 {"pirate", XC_pirate, None},
91 {"plus", XC_plus, None},
92 {"question_arrow", XC_question_arrow, None},
93 {"right_ptr", XC_right_ptr, None},
94 {"right_side", XC_right_side, None},
95 {"right_tee", XC_right_tee, None},
96 {"rightbutton", XC_rightbutton, None},
97 {"rtl_logo", XC_rtl_logo, None},
98 {"sailboat", XC_sailboat, None},
99 {"sb_down_arrow", XC_sb_down_arrow, None},
100 {"sb_h_double_arrow", XC_sb_h_double_arrow, None},
101 {"sb_left_arrow", XC_sb_left_arrow, None},
102 {"sb_right_arrow", XC_sb_right_arrow, None},
103 {"sb_up_arrow", XC_sb_up_arrow, None},
104 {"sb_v_double_arrow", XC_sb_v_double_arrow, None},
105 {"shuttle", XC_shuttle, None},
106 {"sizing", XC_sizing, None},
107 {"spider", XC_spider, None},
108 {"spraycan", XC_spraycan, None},
109 {"star", XC_star, None},
110 {"target", XC_target, None},
111 {"tcross", XC_tcross, None},
112 {"top_left_arrow", XC_top_left_arrow, None},
113 {"top_left_corner", XC_top_left_corner, None},
114 {"top_right_corner", XC_top_right_corner, None},
115 {"top_side", XC_top_side, None},
116 {"top_tee", XC_top_tee, None},
117 {"trek", XC_trek, None},
118 {"ul_angle", XC_ul_angle, None},
119 {"umbrella", XC_umbrella, None},
120 {"ur_angle", XC_ur_angle, None},
121 {"watch", XC_watch, None},
122 {"xterm", XC_xterm, None},
125 void NewFontCursor (cp, str)
131 for (i = 0; i < sizeof(cursor_names)/sizeof(struct _CursorName); i++)
133 if (strcmp(str, cursor_names[i].name) == 0)
135 if (cursor_names[i].cursor == None)
136 cursor_names[i].cursor = XCreateFontCursor(dpy,
137 cursor_names[i].shape);
138 *cp = cursor_names[i].cursor;
142 fprintf (stderr, "%s: unable to find font cursor \"%s\"\n",
146 void NewBitmapCursor(cp, source, mask)
153 unsigned int sw, sh, mw, mh;
155 Colormap cmap = Scr->TwmRoot.cmaps.cwins[0]->colormap->c;
157 fore.pixel = Scr->Black;
158 XQueryColor(dpy, cmap, &fore);
159 back.pixel = Scr->White;
160 XQueryColor(dpy, cmap, &back);
162 spm = GetBitmap(source);
163 if ((hotx = HotX) < 0) hotx = 0;
164 if ((hoty = HotY) < 0) hoty = 0;
165 mpm = GetBitmap(mask);
167 /* make sure they are the same size */
169 XGetGeometry(dpy, spm, &JunkRoot, &sx, &sy, &sw, &sh, &JunkBW,&JunkDepth);
170 XGetGeometry(dpy, mpm, &JunkRoot, &mx, &my, &mw, &mh, &JunkBW,&JunkDepth);
171 if (sw != mw || sh != mh)
174 "%s: cursor bitmaps \"%s\" and \"%s\" not the same size\n",
175 ProgramName, source, mask);
178 *cp = XCreatePixmapCursor(dpy, spm, mpm, &fore, &back, hotx,hoty);