3 Copyright 1987, 1988, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
27 /***********************************************************
29 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
33 Permission to use, copy, modify, and distribute this software and its
34 documentation for any purpose and without fee is hereby granted,
35 provided that the above copyright notice appear in all copies and that
36 both that copyright notice and this permission notice appear in
37 supporting documentation, and that the name of Digital not be
38 used in advertising or publicity pertaining to distribution of the
39 software without specific, written prior permission.
41 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
42 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
43 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
44 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
45 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
46 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49 ******************************************************************/
54 #include <X11/Intrinsic.h>
55 #include <X11/StringDefs.h>
56 #include <X11/Xmu/Converters.h>
57 #include <X11/Xmu/Drawing.h>
58 #include <X11/Xmu/CurUtil.h>
59 #include <X11/Xmu/CharSet.h>
70 #endif /* X_NOT_POSIX */
75 #include <sys/param.h>
79 #define PATH_MAX MAXPATHLEN
86 /* Kludge source to avoid encountering broken shared library linkers
87 which insist on resolving references unused by the application,
88 and broken object file formats that don't correctly distinguish
89 references to procedures from references to data.
91 #if defined(SUNSHLIB) || defined(SVR4)
96 * XmuConvertStringToCursor:
98 * allows String to specify a standard cursor name (from cursorfont.h), a
99 * font name and glyph index of the form "FONT fontname index [[font] index]",
100 * or a bitmap file name (absolute, or relative to the global resource
101 * bitmapFilePath, class BitmapFilePath). If the resource is not
102 * defined, the default value is the build symbol BITMAPDIR.
104 * shares lots of code with XmuCvtStringToPixmap, but unfortunately
105 * can't use it as the hotspot info is lost.
107 * To use, include the following in your ClassInitialize procedure:
109 static XtConvertArgRec screenConvertArg[] = {
110 {XtBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
114 XtAddConverter(XtRString, XtRCursor, XmuCvtStringToCursor,
115 screenConvertArg, XtNumber(screenConvertArg));
119 #define done(address, type) \
120 { (*toVal).size = sizeof(type); (*toVal).addr = (XPointer) address; }
122 #define FONTSPECIFIER "FONT "
126 XmuCvtStringToCursor(XrmValuePtr args, Cardinal *num_args,
127 XrmValuePtr fromVal, XrmValuePtr toVal)
129 static Cursor cursor; /* static for cvt magic */
130 char *name = (char *)fromVal->addr;
133 char maskname[PATH_MAX];
134 Pixmap source, mask = 0;
135 /* XXX - make fg/bg resources */
136 static XColor bgColor = {0, 0xffff, 0xffff, 0xffff};
137 static XColor fgColor = {0, 0, 0, 0};
143 XtErrorMsg("wrongParameters","cvtStringToCursor","XtToolkitError",
144 "String to cursor conversion needs screen argument",
145 (String *)NULL, (Cardinal *)NULL);
147 if (XmuCompareISOLatin1(name, "None") == 0)
150 done(&cursor, Cursor);
154 screen = *((Screen **) args[0].addr);
156 if (0 == strncmp(FONTSPECIFIER, name, strlen(FONTSPECIFIER))) {
157 char source_name[PATH_MAX], mask_name[PATH_MAX];
158 int source_char, mask_char, fields = 0;
159 Font source_font, mask_font;
160 XrmValue fromString, toFont;
163 Display *dpy = DisplayOfScreen(screen);
164 char *strspec = NULL;
170 strspeclen = strlen("FONT %s %d %s %d") + 21;
171 strspec = XtMalloc(strspeclen);
172 if (strspec != NULL) {
173 snprintf(strspec, strspeclen, "FONT %%%lds %%d %%%lds %%d",
174 (unsigned long)sizeof(source_name) - 1,
175 (unsigned long)sizeof(mask_name) - 1);
176 fields = sscanf(name, strspec,
177 source_name, &source_char,
178 mask_name, &mask_char);
182 XtStringConversionWarning(name, XtRCursor);
186 fromString.addr = source_name;
187 fromString.size = strlen(source_name) + 1;
188 toFont.addr = (XPointer) &source_font;
189 toFont.size = sizeof(Font);
190 cvtArg.addr = (XPointer) &dpy;
191 cvtArg.size = sizeof(Display *);
192 /* XXX using display of screen argument as message display */
194 /* XXX Sacrifice caching */
196 success = XtCvtStringToFont(dpy, &cvtArg, &num, &fromString, &toFont,
199 success = XtCallConverter(dpy, XtCvtStringToFont, &cvtArg,
200 (Cardinal)1, &fromString, &toFont, NULL);
203 XtStringConversionWarning(name, XtRCursor);
208 case 2: /* defaulted mask font & char */
209 mask_font = source_font;
210 mask_char = source_char;
213 case 3: /* defaulted mask font */
214 mask_font = source_font;
215 mask_char = atoi(mask_name);
218 case 4: /* specified mask font & char */
219 fromString.addr = mask_name;
220 fromString.size = strlen(mask_name) + 1;
221 toFont.addr = (XPointer) &mask_font;
222 toFont.size = sizeof(Font);
223 /* XXX using display of screen argument as message display */
225 /* XXX Sacrifice caching */
227 success = XtCvtStringToFont(dpy, &cvtArg, &num, &fromString,
230 success = XtCallConverter(dpy, XtCvtStringToFont, &cvtArg,
231 (Cardinal)1, &fromString, &toFont, NULL);
234 XtStringConversionWarning(name, XtRCursor);
239 cursor = XCreateGlyphCursor( DisplayOfScreen(screen), source_font,
240 mask_font, source_char, mask_char,
241 &fgColor, &bgColor );
242 done(&cursor, Cursor);
246 i = XmuCursorNameToIndex (name);
248 cursor = XCreateFontCursor (DisplayOfScreen(screen), i);
249 done(&cursor, Cursor);
253 if ((source = XmuLocateBitmapFile (screen, name,
254 maskname, (sizeof maskname) - 4,
255 NULL, NULL, &xhot, &yhot)) == None) {
256 XtStringConversionWarning (name, XtRCursor);
258 done(&cursor, Cursor);
261 len = strlen (maskname);
262 for (i = 0; i < 2; i++) {
263 strcpy (maskname + len, i == 0 ? "Mask" : "msk");
264 if ((mask = XmuLocateBitmapFile (screen, maskname, NULL, 0,
265 NULL, NULL, NULL, NULL)) != None)
269 cursor = XCreatePixmapCursor( DisplayOfScreen(screen), source, mask,
270 &fgColor, &bgColor, xhot, yhot );
271 XFreePixmap( DisplayOfScreen(screen), source );
272 if (mask != None) XFreePixmap( DisplayOfScreen(screen), mask );
274 done(&cursor, Cursor);
277 #define new_done(type, value) \
279 if (toVal->addr != NULL) { \
280 if (toVal->size < sizeof(type)) { \
281 toVal->size = sizeof(type); \
284 *(type*)(toVal->addr) = (value); \
287 static type static_val; \
288 static_val = (value); \
289 toVal->addr = (XPointer)&static_val; \
291 toVal->size = sizeof(type); \
295 /* Function Name: XmuCvtStringToColorCursor
296 * Description: Converts a string into a colored cursor.
298 * args - an argument list (see below).
299 * num_args - number of elements in the argument list.
300 * fromVal - value to convert from.
301 * toVal - value to convert to.
303 * Returns: True or False
308 XmuCvtStringToColorCursor(Display *dpy, XrmValuePtr args, Cardinal *num_args,
309 XrmValuePtr fromVal, XrmValuePtr toVal,
310 XtPointer *converter_data)
320 if (*num_args != 4) {
321 XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
322 "wrongParameters","cvtStringToColorCursor","XmuError",
323 "String to color cursor conversion needs four arguments",
324 (String *)NULL, (Cardinal *)NULL);
328 screen = *((Screen **) args[0].addr);
329 fg = *((Pixel *) args[1].addr);
330 bg = *((Pixel *) args[2].addr);
331 c_map = *((Colormap *) args[3].addr);
334 XmuCvtStringToCursor(args, &number, fromVal, &ret_val);
336 cursor = *((Cursor *) ret_val.addr);
338 if (cursor == None || (fg == BlackPixelOfScreen(screen)
339 && bg == WhitePixelOfScreen(screen)))
340 new_done(Cursor, cursor);
342 colors[0].pixel = fg;
343 colors[1].pixel = bg;
345 XQueryColors (dpy, c_map, colors, 2);
346 XRecolorCursor(dpy, cursor, colors, colors + 1);
347 new_done(Cursor, cursor);