Mercurial > hg > xemacs-beta
comparison src/glyphs-msw.c @ 280:7df0dd720c89 r21-0b38
Import from CVS: tag r21-0b38
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:32:22 +0200 |
parents | 90d73dddcdc4 |
children | c42ec1d1cded |
comparison
equal
deleted
inserted
replaced
279:c20b2fb5bb0a | 280:7df0dd720c89 |
---|---|
1 /* mswindows-specific Lisp objects. | 1 /* mswindows-specific Lisp objects. |
2 Copyright (C) 1998 Free Software Foundation, Inc. | 2 Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
3 Copyright (C) 1995 Board of Trustees, University of Illinois. | |
4 Copyright (C) 1995 Tinker Systems | |
5 Copyright (C) 1995, 1996 Ben Wing | |
6 Copyright (C) 1995 Sun Microsystems | |
7 Copyright (C) 1998 Andy Piper. | |
3 | 8 |
4 This file is part of XEmacs. | 9 This file is part of XEmacs. |
5 | 10 |
6 XEmacs is free software; you can redistribute it and/or modify it | 11 XEmacs is free software; you can redistribute it and/or modify it |
7 under the terms of the GNU General Public License as published by the | 12 under the terms of the GNU General Public License as published by the |
185 | 190 |
186 /* Given a pixmap filename, look through all of the "standard" places | 191 /* Given a pixmap filename, look through all of the "standard" places |
187 where the file might be located. Return a full pathname if found; | 192 where the file might be located. Return a full pathname if found; |
188 otherwise, return Qnil. */ | 193 otherwise, return Qnil. */ |
189 | 194 |
190 Lisp_Object | 195 static Lisp_Object |
191 mswindows_locate_pixmap_file (Lisp_Object name) | 196 mswindows_locate_pixmap_file (Lisp_Object name) |
192 { | 197 { |
193 /* This function can GC if IN_REDISPLAY is false */ | 198 /* This function can GC if IN_REDISPLAY is false */ |
194 Lisp_Object found; | 199 Lisp_Object found; |
195 | 200 |
218 } | 223 } |
219 | 224 |
220 return found; | 225 return found; |
221 } | 226 } |
222 | 227 |
223 #if 0 | |
224 /* If INSTANTIATOR refers to inline data, return Qnil. | |
225 If INSTANTIATOR refers to data in a file, return the full filename | |
226 if it exists; otherwise, return a cons of (filename). | |
227 | |
228 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the | |
229 keywords used to look up the file and inline data, | |
230 respectively, in the instantiator. Normally these would | |
231 be Q_file and Q_data, but might be different for mask data. */ | |
232 | |
233 static Lisp_Object | |
234 potential_pixmap_file_instantiator (Lisp_Object instantiator, | |
235 Lisp_Object file_keyword, | |
236 Lisp_Object data_keyword) | |
237 { | |
238 Lisp_Object file; | |
239 Lisp_Object data; | |
240 | |
241 assert (VECTORP (instantiator)); | |
242 | |
243 data = find_keyword_in_vector (instantiator, data_keyword); | |
244 file = find_keyword_in_vector (instantiator, file_keyword); | |
245 | |
246 if (!NILP (file) && NILP (data)) | |
247 { | |
248 Lisp_Object retval = locate_pixmap_file(file); | |
249 if (!NILP (retval)) | |
250 return retval; | |
251 else | |
252 return Fcons (file, Qnil); /* should have been file */ | |
253 } | |
254 | |
255 return Qnil; | |
256 } | |
257 | |
258 static Lisp_Object | |
259 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type, | |
260 Lisp_Object image_type_tag) | |
261 { | |
262 /* This function can call lisp */ | |
263 Lisp_Object file = Qnil; | |
264 struct gcpro gcpro1, gcpro2; | |
265 Lisp_Object alist = Qnil; | |
266 | |
267 GCPRO2 (file, alist); | |
268 | |
269 /* Now, convert any file data into inline data. At the end of this, | |
270 `data' will contain the inline data (if any) or Qnil, and `file' | |
271 will contain the name this data was derived from (if known) or | |
272 Qnil. | |
273 | |
274 Note that if we cannot generate any regular inline data, we | |
275 skip out. */ | |
276 | |
277 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data); | |
278 | |
279 if (CONSP (file)) /* failure locating filename */ | |
280 signal_double_file_error ("Opening pixmap file", | |
281 "no such file or directory", | |
282 Fcar (file)); | |
283 | |
284 if (NILP (file)) /* no conversion necessary */ | |
285 RETURN_UNGCPRO (inst); | |
286 | |
287 alist = tagged_vector_to_alist (inst); | |
288 | |
289 { | |
290 Lisp_Object data = make_string_from_file (file); | |
291 alist = remassq_no_quit (Q_file, alist); | |
292 /* there can't be a :data at this point. */ | |
293 alist = Fcons (Fcons (Q_file, file), | |
294 Fcons (Fcons (Q_data, data), alist)); | |
295 } | |
296 | |
297 { | |
298 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist); | |
299 free_alist (alist); | |
300 RETURN_UNGCPRO (result); | |
301 } | |
302 } | |
303 #endif | |
304 | |
305 | 228 |
306 /* Initialize an image instance from a bitmap | 229 /* Initialize an image instance from a bitmap |
307 | 230 |
308 DEST_MASK specifies the mask of allowed image types. | 231 DEST_MASK specifies the mask of allowed image types. |
309 | 232 |
451 SelectObject(hdcDst, 0); | 374 SelectObject(hdcDst, 0); |
452 SelectObject(hcdc, 0); | 375 SelectObject(hcdc, 0); |
453 /* PatBlt(hdcDst, 0, 0, size, size, WHITENESS);*/ | 376 /* PatBlt(hdcDst, 0, 0, size, size, WHITENESS);*/ |
454 | 377 |
455 x_icon.fIcon=TRUE; | 378 x_icon.fIcon=TRUE; |
456 x_icon.xHotspot=XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image); | 379 x_icon.xHotspot=XINT (XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image)); |
457 x_icon.yHotspot=XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image); | 380 x_icon.yHotspot=XINT (XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image)); |
458 x_icon.hbmMask=mask; | 381 x_icon.hbmMask=mask; |
459 x_icon.hbmColor=bmp; | 382 x_icon.hbmColor=bmp; |
460 | 383 |
461 XIMAGE_INSTANCE_MSWINDOWS_ICON (image)= | 384 XIMAGE_INSTANCE_MSWINDOWS_ICON (image)= |
462 CreateIconIndirect (&x_icon); | 385 CreateIconIndirect (&x_icon); |
510 /********************************************************************** | 433 /********************************************************************** |
511 * XPM * | 434 * XPM * |
512 **********************************************************************/ | 435 **********************************************************************/ |
513 | 436 |
514 #ifdef HAVE_XPM | 437 #ifdef HAVE_XPM |
438 | |
439 struct color_symbol | |
440 { | |
441 char* name; | |
442 COLORREF color; | |
443 }; | |
444 | |
445 static struct color_symbol* | |
446 extract_xpm_color_names (Lisp_Object device, | |
447 Lisp_Object domain, | |
448 Lisp_Object color_symbol_alist, | |
449 int* nsymbols) | |
450 { | |
451 /* This function can GC */ | |
452 Lisp_Object rest; | |
453 Lisp_Object results = Qnil; | |
454 int i, j; | |
455 struct color_symbol *colortbl; | |
456 struct gcpro gcpro1, gcpro2; | |
457 | |
458 GCPRO2 (results, device); | |
459 | |
460 /* We built up results to be (("name" . #<color>) ...) so that if an | |
461 error happens we don't lose any malloc()ed data, or more importantly, | |
462 leave any pixels allocated in the server. */ | |
463 i = 0; | |
464 LIST_LOOP (rest, color_symbol_alist) | |
465 { | |
466 Lisp_Object cons = XCAR (rest); | |
467 Lisp_Object name = XCAR (cons); | |
468 Lisp_Object value = XCDR (cons); | |
469 if (NILP (value)) | |
470 continue; | |
471 if (STRINGP (value)) | |
472 value = | |
473 Fmake_color_instance | |
474 (value, device, encode_error_behavior_flag (ERROR_ME_NOT)); | |
475 else | |
476 { | |
477 assert (COLOR_SPECIFIERP (value)); | |
478 value = Fspecifier_instance (value, domain, Qnil, Qnil); | |
479 } | |
480 if (NILP (value)) | |
481 continue; | |
482 results = noseeum_cons (noseeum_cons (name, value), results); | |
483 i++; | |
484 } | |
485 UNGCPRO; /* no more evaluation */ | |
486 | |
487 *nsymbols=i; | |
488 if (i == 0) return 0; | |
489 | |
490 colortbl = xnew_array_and_zero (struct color_symbol, i); | |
491 | |
492 for (j=0; j<i; j++) | |
493 { | |
494 Lisp_Object cons = XCAR (results); | |
495 colortbl[j].color = | |
496 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons))); | |
497 | |
498 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons)); | |
499 free_cons (XCONS (cons)); | |
500 cons = results; | |
501 results = XCDR (results); | |
502 free_cons (XCONS (cons)); | |
503 } | |
504 return colortbl; | |
505 } | |
506 | |
515 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer, | 507 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer, |
516 unsigned char** data, | 508 unsigned char** data, |
517 int* width, int* height, | 509 int* width, int* height, |
518 int* x_hot, int* y_hot, | 510 int* x_hot, int* y_hot, |
519 COLORREF bg) | 511 COLORREF bg, struct color_symbol* color_symbols, |
512 int nsymbols) | |
520 { | 513 { |
521 XpmImage xpmimage; | 514 XpmImage xpmimage; |
522 XpmInfo xpminfo; | 515 XpmInfo xpminfo; |
523 int result, i, transp_idx, maskbpline; | 516 int result, i, j, transp_idx, maskbpline; |
524 unsigned char* dptr; | 517 unsigned char* dptr; |
525 unsigned int* sptr; | 518 unsigned int* sptr; |
526 COLORREF color; /* the american spelling virus hits again .. */ | 519 COLORREF color; /* the american spelling virus hits again .. */ |
527 COLORREF* colortbl; | 520 COLORREF* colortbl; |
528 | 521 |
578 return 0; | 571 return 0; |
579 } | 572 } |
580 | 573 |
581 for (i=0; i<xpmimage.ncolors; i++) | 574 for (i=0; i<xpmimage.ncolors; i++) |
582 { | 575 { |
576 /* pick up symbolic colors */ | |
577 if (xpmimage.colorTable[i].c_color == 0 | |
578 && | |
579 xpmimage.colorTable[i].symbolic != 0) | |
580 { | |
581 if (!color_symbols) | |
582 { | |
583 xfree (*data); | |
584 xfree (colortbl); | |
585 XpmFreeXpmImage (&xpmimage); | |
586 XpmFreeXpmInfo (&xpminfo); | |
587 return 0; | |
588 } | |
589 for (j = 0; j<nsymbols; j++) | |
590 { | |
591 if (!strcmp (xpmimage.colorTable[i].symbolic, | |
592 color_symbols[j].name )) | |
593 { | |
594 colortbl[i]=color_symbols[j].color; | |
595 } | |
596 } | |
597 } | |
583 /* pick up transparencies */ | 598 /* pick up transparencies */ |
584 if (!strcmp (xpmimage.colorTable[i].c_color,"None")) | 599 else if (!strcmp (xpmimage.colorTable[i].c_color,"None")) |
585 { | 600 { |
586 colortbl[i]=bg; /* PALETTERGB(0,0,0); */ | 601 colortbl[i]=bg; /* PALETTERGB(0,0,0); */ |
587 transp_idx=i; | 602 transp_idx=i; |
588 } | 603 } |
589 else | 604 else |
613 XpmFreeXpmInfo (&xpminfo); | 628 XpmFreeXpmInfo (&xpminfo); |
614 xfree (colortbl); | 629 xfree (colortbl); |
615 return TRUE; | 630 return TRUE; |
616 } | 631 } |
617 | 632 |
618 Lisp_Object | 633 static void |
619 mswindows_xpm_normalize (Lisp_Object inst, Lisp_Object console_type) | |
620 { | |
621 return simple_image_type_normalize (inst, console_type, Qxpm); | |
622 } | |
623 | |
624 void | |
625 mswindows_xpm_instantiate (Lisp_Object image_instance, | 634 mswindows_xpm_instantiate (Lisp_Object image_instance, |
626 Lisp_Object instantiator, | 635 Lisp_Object instantiator, |
627 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | 636 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
628 int dest_mask, Lisp_Object domain) | 637 int dest_mask, Lisp_Object domain) |
629 { | 638 { |
635 int width, height, x_hot, y_hot; | 644 int width, height, x_hot, y_hot; |
636 BITMAPINFO* bmp_info; | 645 BITMAPINFO* bmp_info; |
637 unsigned char* bmp_data; | 646 unsigned char* bmp_data; |
638 int bmp_bits; | 647 int bmp_bits; |
639 COLORREF bkcolor; | 648 COLORREF bkcolor; |
649 int nsymbols=0; | |
650 struct color_symbol* color_symbols=NULL; | |
640 | 651 |
641 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | 652 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
653 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator, | |
654 Q_color_symbols); | |
642 | 655 |
643 if (!DEVICE_MSWINDOWS_P (XDEVICE (device))) | 656 if (!DEVICE_MSWINDOWS_P (XDEVICE (device))) |
644 signal_simple_error ("Not an mswindows device", device); | 657 signal_simple_error ("Not an mswindows device", device); |
645 | 658 |
646 assert (!NILP (data)); | 659 assert (!NILP (data)); |
650 /* this is a hack but MaskBlt and TransparentBlt are not supported | 663 /* this is a hack but MaskBlt and TransparentBlt are not supported |
651 on most windows variants */ | 664 on most windows variants */ |
652 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR | 665 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR |
653 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain))); | 666 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain))); |
654 | 667 |
668 /* in case we have color symbols */ | |
669 color_symbols = extract_xpm_color_names (device, domain, | |
670 color_symbol_alist, &nsymbols); | |
671 | |
655 /* convert to an eimage to make processing easier */ | 672 /* convert to an eimage to make processing easier */ |
656 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height, | 673 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height, |
657 &x_hot, &y_hot, bkcolor)) | 674 &x_hot, &y_hot, bkcolor, color_symbols, nsymbols)) |
658 { | 675 { |
659 signal_simple_error ("XPM to EImage conversion failed", | 676 signal_simple_error ("XPM to EImage conversion failed", |
660 image_instance); | 677 image_instance); |
661 } | 678 } |
679 | |
680 if (color_symbols) | |
681 xfree(color_symbols); | |
662 | 682 |
663 /* build a bitmap from the eimage */ | 683 /* build a bitmap from the eimage */ |
664 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage, | 684 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage, |
665 &bmp_bits, &bmp_data))) | 685 &bmp_bits, &bmp_data))) |
666 { | 686 { |
868 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance); | 888 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance); |
869 CONSOLE_HAS_METHOD (mswindows, image_instance_equal); | 889 CONSOLE_HAS_METHOD (mswindows, image_instance_equal); |
870 CONSOLE_HAS_METHOD (mswindows, image_instance_hash); | 890 CONSOLE_HAS_METHOD (mswindows, image_instance_hash); |
871 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage); | 891 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage); |
872 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file); | 892 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file); |
893 #ifdef HAVE_XPM | |
894 CONSOLE_HAS_METHOD (mswindows, xpm_instantiate); | |
895 #endif | |
873 } | 896 } |
874 | 897 |
875 void | 898 void |
876 image_instantiator_format_create_glyphs_mswindows (void) | 899 image_instantiator_format_create_glyphs_mswindows (void) |
877 { | 900 { |