Mercurial > hg > xemacs-beta
comparison src/objects-x.c @ 440:8de8e3f6228a r21-2-28
Import from CVS: tag r21-2-28
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:33:38 +0200 |
parents | 3ecd8885ac67 |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
439:357dd071b03c | 440:8de8e3f6228a |
---|---|
67 } | 67 } |
68 else | 68 else |
69 { | 69 { |
70 /* We're dealing with a TrueColor/DirectColor visual, so play games | 70 /* We're dealing with a TrueColor/DirectColor visual, so play games |
71 with the RGB values in the XColor struct. */ | 71 with the RGB values in the XColor struct. */ |
72 /* ### JH: I'm not sure how a call to XAllocColor can fail in a | 72 /* #### JH: I'm not sure how a call to XAllocColor can fail in a |
73 TrueColor or DirectColor visual, so I will just reformat the | 73 TrueColor or DirectColor visual, so I will just reformat the |
74 request to match the requirements of the visual, and re-issue | 74 request to match the requirements of the visual, and re-issue |
75 the request. If this fails for anybody, I wanna know about it | 75 the request. If this fails for anybody, I wanna know about it |
76 so I can come up with a better plan */ | 76 so I can come up with a better plan */ |
77 | 77 |
116 if (XAllocColor (display, colormap, color_def) != 0) | 116 if (XAllocColor (display, colormap, color_def) != 0) |
117 status = 1; | 117 status = 1; |
118 else | 118 else |
119 { | 119 { |
120 int rd, gr, bl; | 120 int rd, gr, bl; |
121 /* ### JH: I'm punting here, knowing that doing this will at | 121 /* #### JH: I'm punting here, knowing that doing this will at |
122 least draw the color correctly. However, unless we convert | 122 least draw the color correctly. However, unless we convert |
123 all of the functions that allocate colors (graphics | 123 all of the functions that allocate colors (graphics |
124 libraries, etc) to use this function doing this is very | 124 libraries, etc) to use this function doing this is very |
125 likely to cause problems later... */ | 125 likely to cause problems later... */ |
126 | 126 |
230 xzero (*color); | 230 xzero (*color); |
231 { | 231 { |
232 CONST Extbyte *extname; | 232 CONST Extbyte *extname; |
233 Extcount extnamelen; | 233 Extcount extnamelen; |
234 | 234 |
235 GET_CHARPTR_EXT_BINARY_DATA_ALLOCA (name, len, extname, extnamelen); | 235 TO_EXTERNAL_FORMAT (DATA, (name, len), |
236 ALLOCA, (extname, extnamelen), | |
237 Qbinary); | |
236 result = XParseColor (dpy, cmap, (char *) extname, color); | 238 result = XParseColor (dpy, cmap, (char *) extname, color); |
237 } | 239 } |
238 if (!result) | 240 if (!result) |
239 { | 241 { |
240 maybe_signal_simple_error ("Unrecognized color", make_string (name, len), | 242 maybe_signal_simple_error ("Unrecognized color", make_string (name, len), |
251 | 253 |
252 return result; | 254 return result; |
253 } | 255 } |
254 | 256 |
255 static int | 257 static int |
256 x_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name, | 258 x_initialize_color_instance (Lisp_Color_Instance *c, Lisp_Object name, |
257 Lisp_Object device, Error_behavior errb) | 259 Lisp_Object device, Error_behavior errb) |
258 { | 260 { |
259 XColor color; | 261 XColor color; |
260 int result; | 262 int result; |
261 | 263 |
277 COLOR_INSTANCE_X_COLOR (c) = color; | 279 COLOR_INSTANCE_X_COLOR (c) = color; |
278 return 1; | 280 return 1; |
279 } | 281 } |
280 | 282 |
281 static void | 283 static void |
282 x_print_color_instance (struct Lisp_Color_Instance *c, | 284 x_print_color_instance (Lisp_Color_Instance *c, |
283 Lisp_Object printcharfun, | 285 Lisp_Object printcharfun, |
284 int escapeflag) | 286 int escapeflag) |
285 { | 287 { |
286 char buf[100]; | 288 char buf[100]; |
287 XColor color = COLOR_INSTANCE_X_COLOR (c); | 289 XColor color = COLOR_INSTANCE_X_COLOR (c); |
289 color.pixel, color.red, color.green, color.blue); | 291 color.pixel, color.red, color.green, color.blue); |
290 write_c_string (buf, printcharfun); | 292 write_c_string (buf, printcharfun); |
291 } | 293 } |
292 | 294 |
293 static void | 295 static void |
294 x_finalize_color_instance (struct Lisp_Color_Instance *c) | 296 x_finalize_color_instance (Lisp_Color_Instance *c) |
295 { | 297 { |
296 if (c->data) | 298 if (c->data) |
297 { | 299 { |
298 if (DEVICE_LIVE_P (XDEVICE (c->device))) | 300 if (DEVICE_LIVE_P (XDEVICE (c->device))) |
299 { | 301 { |
312 screen (have the same RGB values). I imagine that | 314 screen (have the same RGB values). I imagine that |
313 "same RGB values" == "same cell in the colormap." Arguably we should | 315 "same RGB values" == "same cell in the colormap." Arguably we should |
314 be comparing their names or pixel values instead. */ | 316 be comparing their names or pixel values instead. */ |
315 | 317 |
316 static int | 318 static int |
317 x_color_instance_equal (struct Lisp_Color_Instance *c1, | 319 x_color_instance_equal (Lisp_Color_Instance *c1, |
318 struct Lisp_Color_Instance *c2, | 320 Lisp_Color_Instance *c2, |
319 int depth) | 321 int depth) |
320 { | 322 { |
321 XColor color1 = COLOR_INSTANCE_X_COLOR (c1); | 323 XColor color1 = COLOR_INSTANCE_X_COLOR (c1); |
322 XColor color2 = COLOR_INSTANCE_X_COLOR (c2); | 324 XColor color2 = COLOR_INSTANCE_X_COLOR (c2); |
323 return ((color1.red == color2.red) && | 325 return ((color1.red == color2.red) && |
324 (color1.green == color2.green) && | 326 (color1.green == color2.green) && |
325 (color1.blue == color2.blue)); | 327 (color1.blue == color2.blue)); |
326 } | 328 } |
327 | 329 |
328 static unsigned long | 330 static unsigned long |
329 x_color_instance_hash (struct Lisp_Color_Instance *c, int depth) | 331 x_color_instance_hash (Lisp_Color_Instance *c, int depth) |
330 { | 332 { |
331 XColor color = COLOR_INSTANCE_X_COLOR (c); | 333 XColor color = COLOR_INSTANCE_X_COLOR (c); |
332 return HASH3 (color.red, color.green, color.blue); | 334 return HASH3 (color.red, color.green, color.blue); |
333 } | 335 } |
334 | 336 |
335 static Lisp_Object | 337 static Lisp_Object |
336 x_color_instance_rgb_components (struct Lisp_Color_Instance *c) | 338 x_color_instance_rgb_components (Lisp_Color_Instance *c) |
337 { | 339 { |
338 XColor color = COLOR_INSTANCE_X_COLOR (c); | 340 XColor color = COLOR_INSTANCE_X_COLOR (c); |
339 return (list3 (make_int (color.red), | 341 return (list3 (make_int (color.red), |
340 make_int (color.green), | 342 make_int (color.green), |
341 make_int (color.blue))); | 343 make_int (color.blue))); |
348 Display *dpy = DEVICE_X_DISPLAY (d); | 350 Display *dpy = DEVICE_X_DISPLAY (d); |
349 Colormap cmap = DEVICE_X_COLORMAP (d); | 351 Colormap cmap = DEVICE_X_COLORMAP (d); |
350 | 352 |
351 CONST char *extname; | 353 CONST char *extname; |
352 | 354 |
353 GET_C_STRING_CTEXT_DATA_ALLOCA (color, extname); | 355 TO_EXTERNAL_FORMAT (LISP_STRING, color, C_STRING_ALLOCA, extname, Qctext); |
354 | 356 |
355 return XParseColor (dpy, cmap, | 357 return XParseColor (dpy, cmap, extname, &c); |
356 extname, &c); | |
357 } | 358 } |
358 | 359 |
359 | 360 |
360 /************************************************************************/ | 361 /************************************************************************/ |
361 /* font instances */ | 362 /* font instances */ |
362 /************************************************************************/ | 363 /************************************************************************/ |
363 | 364 |
364 static int | 365 static int |
365 x_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name, | 366 x_initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name, |
366 Lisp_Object device, Error_behavior errb) | 367 Lisp_Object device, Error_behavior errb) |
367 { | 368 { |
368 Display *dpy; | 369 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (device)); |
369 XFontStruct *xf; | 370 XFontStruct *xf; |
370 CONST char *extname; | 371 CONST char *extname; |
371 | 372 |
372 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); | 373 TO_EXTERNAL_FORMAT (LISP_STRING, f->name, C_STRING_ALLOCA, extname, Qctext); |
373 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, extname); | |
374 xf = XLoadQueryFont (dpy, extname); | 374 xf = XLoadQueryFont (dpy, extname); |
375 | 375 |
376 if (!xf) | 376 if (!xf) |
377 { | 377 { |
378 maybe_signal_simple_error ("Couldn't load font", f->name, | 378 maybe_signal_simple_error ("Couldn't load font", f->name, |
455 | 455 |
456 return 1; | 456 return 1; |
457 } | 457 } |
458 | 458 |
459 static void | 459 static void |
460 x_mark_font_instance (struct Lisp_Font_Instance *f) | 460 x_mark_font_instance (Lisp_Font_Instance *f) |
461 { | 461 { |
462 mark_object (FONT_INSTANCE_X_TRUENAME (f)); | 462 mark_object (FONT_INSTANCE_X_TRUENAME (f)); |
463 } | 463 } |
464 | 464 |
465 static void | 465 static void |
466 x_print_font_instance (struct Lisp_Font_Instance *f, | 466 x_print_font_instance (Lisp_Font_Instance *f, |
467 Lisp_Object printcharfun, | 467 Lisp_Object printcharfun, |
468 int escapeflag) | 468 int escapeflag) |
469 { | 469 { |
470 char buf[200]; | 470 char buf[200]; |
471 sprintf (buf, " 0x%lx", (unsigned long) FONT_INSTANCE_X_FONT (f)->fid); | 471 sprintf (buf, " 0x%lx", (unsigned long) FONT_INSTANCE_X_FONT (f)->fid); |
472 write_c_string (buf, printcharfun); | 472 write_c_string (buf, printcharfun); |
473 } | 473 } |
474 | 474 |
475 static void | 475 static void |
476 x_finalize_font_instance (struct Lisp_Font_Instance *f) | 476 x_finalize_font_instance (Lisp_Font_Instance *f) |
477 { | 477 { |
478 | 478 |
479 if (f->data) | 479 if (f->data) |
480 { | 480 { |
481 if (DEVICE_LIVE_P (XDEVICE (f->device))) | 481 if (DEVICE_LIVE_P (XDEVICE (f->device))) |
771 else | 771 else |
772 return Qnil; | 772 return Qnil; |
773 } | 773 } |
774 | 774 |
775 static Lisp_Object | 775 static Lisp_Object |
776 x_font_instance_truename (struct Lisp_Font_Instance *f, Error_behavior errb) | 776 x_font_instance_truename (Lisp_Font_Instance *f, Error_behavior errb) |
777 { | 777 { |
778 struct device *d = XDEVICE (f->device); | 778 struct device *d = XDEVICE (f->device); |
779 | 779 |
780 if (NILP (FONT_INSTANCE_X_TRUENAME (f))) | 780 if (NILP (FONT_INSTANCE_X_TRUENAME (f))) |
781 { | 781 { |
799 } | 799 } |
800 return (FONT_INSTANCE_X_TRUENAME (f)); | 800 return (FONT_INSTANCE_X_TRUENAME (f)); |
801 } | 801 } |
802 | 802 |
803 static Lisp_Object | 803 static Lisp_Object |
804 x_font_instance_properties (struct Lisp_Font_Instance *f) | 804 x_font_instance_properties (Lisp_Font_Instance *f) |
805 { | 805 { |
806 struct device *d = XDEVICE (f->device); | 806 struct device *d = XDEVICE (f->device); |
807 int i; | 807 int i; |
808 Lisp_Object result = Qnil; | 808 Lisp_Object result = Qnil; |
809 XFontProp *props; | 809 XFontProp *props; |
859 char **names; | 859 char **names; |
860 int count = 0; | 860 int count = 0; |
861 Lisp_Object result = Qnil; | 861 Lisp_Object result = Qnil; |
862 CONST char *patternext; | 862 CONST char *patternext; |
863 | 863 |
864 GET_C_STRING_BINARY_DATA_ALLOCA (pattern, patternext); | 864 TO_EXTERNAL_FORMAT (LISP_STRING, pattern, |
865 C_STRING_ALLOCA, patternext, | |
866 Qbinary); | |
865 | 867 |
866 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)), | 868 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)), |
867 patternext, MAX_FONT_COUNT, &count); | 869 patternext, MAX_FONT_COUNT, &count); |
868 while (count--) | 870 while (count--) |
869 result = Fcons (build_ext_string (names [count], FORMAT_BINARY), result); | 871 result = Fcons (build_ext_string (names [count], Qbinary), result); |
870 if (names) | 872 if (names) |
871 XFreeFontNames (names); | 873 XFreeFontNames (names); |
872 return result; | 874 return result; |
873 } | 875 } |
874 | 876 |
932 int count = 0; | 934 int count = 0; |
933 Lisp_Object result = Qnil; | 935 Lisp_Object result = Qnil; |
934 CONST char *patternext; | 936 CONST char *patternext; |
935 int i; | 937 int i; |
936 | 938 |
937 GET_C_STRING_BINARY_DATA_ALLOCA (font, patternext); | 939 TO_EXTERNAL_FORMAT (LISP_STRING, font, |
940 C_STRING_ALLOCA, patternext, | |
941 Qbinary); | |
938 | 942 |
939 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)), | 943 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)), |
940 patternext, MAX_FONT_COUNT, &count); | 944 patternext, MAX_FONT_COUNT, &count); |
941 /* ### This code seems awfully bogus -- mrb */ | 945 /* #### This code seems awfully bogus -- mrb */ |
942 for (i = 0; i < count; i ++) | 946 for (i = 0; i < count; i ++) |
943 { | 947 { |
944 CONST Bufbyte *intname; | 948 CONST char *intname; |
945 | 949 |
946 GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA (names[i], intname); | 950 TO_INTERNAL_FORMAT (C_STRING, names[i], |
951 C_STRING_ALLOCA, intname, | |
952 Qbinary); | |
947 if (x_font_spec_matches_charset (XDEVICE (device), charset, | 953 if (x_font_spec_matches_charset (XDEVICE (device), charset, |
948 intname, Qnil, 0, -1)) | 954 (Bufbyte *) intname, Qnil, 0, -1)) |
949 { | 955 { |
950 result = build_string ((char *) intname); | 956 result = build_string (intname); |
951 break; | 957 break; |
952 } | 958 } |
953 } | 959 } |
954 | 960 |
955 if (names) | 961 if (names) |