comparison src/glyphs-msw.c @ 284:558f606b08ae r21-0b40

Import from CVS: tag r21-0b40
author cvs
date Mon, 13 Aug 2007 10:34:13 +0200
parents c42ec1d1cded
children 57709be46d1b
comparison
equal deleted inserted replaced
283:fa3d41851a08 284:558f606b08ae
44 44
45 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp); 45 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
46 Lisp_Object Qbmp; 46 Lisp_Object Qbmp;
47 Lisp_Object Vmswindows_bitmap_file_path; 47 Lisp_Object Vmswindows_bitmap_file_path;
48 static COLORREF transparent_color = RGB (1,1,1); 48 static COLORREF transparent_color = RGB (1,1,1);
49
50 DEFINE_IMAGE_INSTANTIATOR_FORMAT (cursor);
51 Lisp_Object Qcursor;
52 Lisp_Object Q_resource_type, Q_resource_id;
49 53
50 static void 54 static void
51 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii, 55 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
52 enum image_instance_type type); 56 enum image_instance_type type);
53 static void 57 static void
360 364
361 static void 365 static void
362 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image, 366 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
363 struct frame* f) 367 struct frame* f)
364 { 368 {
365 HBITMAP mask, bmp; 369 HBITMAP mask;
370 HGDIOBJ old = NULL;
366 HDC hcdc = FRAME_MSWINDOWS_CDC (f); 371 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
367 BITMAPINFO* bmp_info = 372 BITMAPINFO* bmp_info =
368 xmalloc_and_zero (sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)); 373 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
369 int i, j; 374 int i, j;
370 int height = IMAGE_INSTANCE_PIXMAP_HEIGHT (image); 375 int height = IMAGE_INSTANCE_PIXMAP_HEIGHT (image);
371 376
372 void* and_bits; 377 void* and_bits;
373 int bpline= (int)(~3UL & (unsigned long) 378 int bpline= (int)(~3UL & (unsigned long)
400 xfree (bmp_info); 405 xfree (bmp_info);
401 return; 406 return;
402 } 407 }
403 408
404 xfree (bmp_info); 409 xfree (bmp_info);
405 SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (image)); 410 old = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (image));
406 411
407 for(i=0; i<IMAGE_INSTANCE_PIXMAP_WIDTH (image); i++) 412 for(i=0; i<IMAGE_INSTANCE_PIXMAP_WIDTH (image); i++)
408 { 413 {
409 for(j=0; j<height; j++) 414 for(j=0; j<height; j++)
410 { 415 {
419 } 424 }
420 } 425 }
421 } 426 }
422 427
423 GdiFlush(); 428 GdiFlush();
424 SelectObject(hcdc, 0); 429 SelectObject(hcdc, old);
425 430
426 IMAGE_INSTANCE_MSWINDOWS_MASK (image) = mask; 431 IMAGE_INSTANCE_MSWINDOWS_MASK (image) = mask;
427 } 432 }
428 433
429 void 434 void
446 int 451 int
447 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii, 452 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii,
448 struct frame* f, 453 struct frame* f,
449 int newx, int newy) 454 int newx, int newy)
450 { 455 {
451 HBITMAP newbmp; 456 HBITMAP newbmp, newmask=NULL;
452 HDC hcdc = FRAME_MSWINDOWS_CDC (f); 457 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
453 HDC hdcDst = CreateCompatibleDC (hcdc); 458 HDC hdcDst = CreateCompatibleDC (hcdc);
454 459
455 SelectObject(hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)); 460 SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
456 461
457 newbmp = CreateCompatibleBitmap(hcdc, newx, newy); 462 newbmp = CreateCompatibleBitmap (hcdc, newx, newy);
458 463
459 DeleteObject( SelectObject(hdcDst, newbmp) ); 464 DeleteObject (SelectObject (hdcDst, newbmp) );
460 465
461 if (!StretchBlt(hdcDst, 0, 0, newx, newy, 466 if (!StretchBlt (hdcDst, 0, 0, newx, newy,
462 hcdc, 0, 0, 467 hcdc, 0, 0,
463 IMAGE_INSTANCE_PIXMAP_WIDTH (ii), 468 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
464 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii), 469 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
465 SRCCOPY)) 470 SRCCOPY))
466 { 471 {
467 return FALSE; 472 return FALSE;
468 } 473 }
469 474
470 SelectObject(hdcDst, 0); 475 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
471 SelectObject(hcdc, 0); 476 {
477 SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
478 newmask = CreateCompatibleBitmap(hcdc, newx, newy);
479 SelectObject (hdcDst, newmask);
480
481 if (!StretchBlt(hdcDst, 0, 0, newx, newy,
482 hcdc, 0, 0,
483 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
484 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
485 SRCCOPY))
486 {
487 return FALSE;
488 }
489 }
490
491 SelectObject (hdcDst, 0);
492 SelectObject (hcdc, 0);
472 493
473 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)) 494 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii))
474 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)); 495 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
475 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii)) 496 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
476 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii)); 497 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
477 498
478 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp; 499 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp;
479 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newbmp; 500 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newmask;
480 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx; 501 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx;
481 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy; 502 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy;
482 503
483 DeleteDC(hdcDst); 504 DeleteDC (hdcDst);
484 505
485 return TRUE; 506 return TRUE;
486 } 507 }
487 508
488 /********************************************************************** 509 /**********************************************************************
653 } 674 }
654 } 675 }
655 /* pick up transparencies */ 676 /* pick up transparencies */
656 else if (!strcasecmp (xpmimage.colorTable[i].c_color,"None") 677 else if (!strcasecmp (xpmimage.colorTable[i].c_color,"None")
657 || 678 ||
658 xpmimage.colorTable[i].symbolic 679 (xpmimage.colorTable[i].symbolic
659 && 680 &&
660 (!strcasecmp (xpmimage.colorTable[i].symbolic,"BgColor") 681 (!strcasecmp (xpmimage.colorTable[i].symbolic,"BgColor")
661 || 682 ||
662 !strcasecmp (xpmimage.colorTable[i].symbolic,"None"))) 683 !strcasecmp (xpmimage.colorTable[i].symbolic,"None"))))
663 { 684 {
664 *transp=TRUE; 685 *transp=TRUE;
665 colortbl[i]=transparent_color; 686 colortbl[i]=transparent_color;
666 transp_idx=i; 687 transp_idx=i;
667 } 688 }
707 unsigned char *eimage; 728 unsigned char *eimage;
708 int width, height, x_hot, y_hot; 729 int width, height, x_hot, y_hot;
709 BITMAPINFO* bmp_info; 730 BITMAPINFO* bmp_info;
710 unsigned char* bmp_data; 731 unsigned char* bmp_data;
711 int bmp_bits; 732 int bmp_bits;
712 COLORREF bkcolor;
713 int nsymbols=0, transp; 733 int nsymbols=0, transp;
714 struct color_symbol* color_symbols=NULL; 734 struct color_symbol* color_symbols=NULL;
715 735
716 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 736 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
717 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator, 737 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
813 833
814 /* Now create the pixmap and set up the image instance */ 834 /* Now create the pixmap and set up the image instance */
815 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, 835 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
816 bmp_data, bmp_bits, instantiator, 836 bmp_data, bmp_bits, instantiator,
817 0, 0, 0); 837 0, 0, 0);
838 }
839
840
841 /**********************************************************************
842 * CURSORS *
843 **********************************************************************/
844
845 static void
846 cursor_validate (Lisp_Object instantiator)
847 {
848 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
849 &&
850 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
851 ||
852 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
853 signal_simple_error ("Must supply :file, :resource-id and :resource-type",
854 instantiator);
855 }
856
857 static Lisp_Object
858 cursor_normalize (Lisp_Object inst, Lisp_Object console_type)
859 {
860 /* This function can call lisp */
861 Lisp_Object file = Qnil;
862 struct gcpro gcpro1, gcpro2;
863 Lisp_Object alist = Qnil;
864
865 GCPRO2 (file, alist);
866
867 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
868 console_type);
869
870 if (CONSP (file)) /* failure locating filename */
871 signal_double_file_error ("Opening pixmap file",
872 "no such file or directory",
873 Fcar (file));
874
875 if (NILP (file)) /* no conversion necessary */
876 RETURN_UNGCPRO (inst);
877
878 alist = tagged_vector_to_alist (inst);
879
880 {
881 alist = remassq_no_quit (Q_file, alist);
882 alist = Fcons (Fcons (Q_file, file), alist);
883 }
884
885 {
886 Lisp_Object result = alist_to_tagged_vector (Qcursor, alist);
887 free_alist (alist);
888 RETURN_UNGCPRO (result);
889 }
890 }
891
892 static int
893 cursor_possible_dest_types (void)
894 {
895 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
896 }
897
898 typedef struct
899 {
900 char *name;
901 int resource_id;
902 } resource_t;
903
904 #ifndef OCR_ICOCUR
905 #define OCR_ICOCUR 32647
906 #define OIC_SAMPLE 32512
907 #define OIC_HAND 32513
908 #define OIC_QUES 32514
909 #define OIC_BANG 32515
910 #define OIC_NOTE 32516
911 #define OIC_WINLOGO 32517
912 #define LR_SHARED 0x8000
913 #endif
914
915 static CONST resource_t resource_table[] =
916 {
917 /* bitmaps */
918 { "close", OBM_CLOSE },
919 { "uparrow", OBM_UPARROW },
920 { "dnarrow", OBM_DNARROW },
921 { "rgarrow", OBM_RGARROW },
922 { "lfarrow", OBM_LFARROW },
923 { "reduce", OBM_REDUCE },
924 { "zoom", OBM_ZOOM },
925 { "restore", OBM_RESTORE },
926 { "reduced", OBM_REDUCED },
927 { "zoomd", OBM_ZOOMD },
928 { "restored", OBM_RESTORED },
929 { "uparrowd", OBM_UPARROWD },
930 { "dnarrowd", OBM_DNARROWD },
931 { "rgarrowd", OBM_RGARROWD },
932 { "lfarrowd", OBM_LFARROWD },
933 { "mnarrow", OBM_MNARROW },
934 { "combo", OBM_COMBO },
935 { "uparrowi", OBM_UPARROWI },
936 { "dnarrowi", OBM_DNARROWI },
937 { "rgarrowi", OBM_RGARROWI },
938 { "lfarrowi", OBM_LFARROWI },
939 { "size", OBM_SIZE },
940 { "btsize", OBM_BTSIZE },
941 { "check", OBM_CHECK },
942 { "cehckboxes", OBM_CHECKBOXES },
943 { "btncorners" , OBM_BTNCORNERS },
944 /* cursors */
945 { "normal", OCR_NORMAL },
946 { "ibeam", OCR_IBEAM },
947 { "wait", OCR_WAIT },
948 { "cross", OCR_CROSS },
949 { "up", OCR_UP },
950 /* { "icon", OCR_ICON }, */
951 { "sizenwse", OCR_SIZENWSE },
952 { "sizenesw", OCR_SIZENESW },
953 { "sizewe", OCR_SIZEWE },
954 { "sizens", OCR_SIZENS },
955 { "sizeall", OCR_SIZEALL },
956 /* { "icour", OCR_ICOCUR }, */
957 { "no", OCR_NO },
958 /* icons */
959 { "sample", OIC_SAMPLE },
960 { "hand", OIC_HAND },
961 { "ques", OIC_QUES },
962 { "bang", OIC_BANG },
963 { "note", OIC_NOTE },
964 { "winlogo", OIC_WINLOGO },
965 {0}
966 };
967
968 static int cursor_name_to_resource (Lisp_Object name)
969 {
970 CONST resource_t* res = resource_table;
971
972 if (INTP (name))
973 {
974 return XINT (name);
975 }
976 else if (!STRINGP (name))
977 {
978 signal_simple_error ("invalid resource identifier", name);
979 }
980
981 do {
982 if (!strcasecmp ((char*)res->name, XSTRING_DATA (name)))
983 return res->resource_id;
984 } while ((++res)->name);
985 return 0;
986 }
987
988 static void
989 cursor_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
990 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
991 int dest_mask, Lisp_Object domain)
992 {
993 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
994 unsigned int type = 0;
995 HANDLE himage = NULL;
996 LPCTSTR resid=0;
997 int iitype=0;
998 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
999
1000 Lisp_Object file = find_keyword_in_vector (instantiator, Q_file);
1001 Lisp_Object resource_type = find_keyword_in_vector (instantiator,
1002 Q_resource_type);
1003 Lisp_Object resource_id = find_keyword_in_vector (instantiator,
1004 Q_resource_id);
1005
1006 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
1007 signal_simple_error ("Not an mswindows device", device);
1008
1009 assert (!NILP (resource_type) && !NILP (resource_id));
1010
1011 /* check the resource type */
1012 if (!SYMBOLP (resource_type))
1013 {
1014 signal_simple_error ("invalid resource type", resource_type);
1015 }
1016 if (!strcmp ((char *) string_data (XSYMBOL (resource_type)->name),
1017 "bitmap"))
1018 type = IMAGE_BITMAP;
1019 else if (!strcmp ((char *) string_data (XSYMBOL (resource_type)->name),
1020 "cursor"))
1021 type = IMAGE_CURSOR;
1022 else if (!strcmp ((char *) string_data (XSYMBOL (resource_type)->name),
1023 "icon"))
1024 type = IMAGE_ICON;
1025 else
1026 signal_simple_error ("invalid resource type", resource_type);
1027
1028 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_CURSOR)
1029 iitype = IMAGE_POINTER;
1030 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1031 iitype = IMAGE_COLOR_PIXMAP;
1032 else
1033 incompatible_image_types (instantiator, dest_mask,
1034 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
1035
1036 if (!NILP (file))
1037 resid = (LPCTSTR)XSTRING_DATA (file);
1038 else if (!(resid = MAKEINTRESOURCE(cursor_name_to_resource (resource_id))))
1039 signal_simple_error ("invalid resource id", resource_id);
1040
1041 /* load the image */
1042 if (!(himage = LoadImage (NULL, resid, type, 0, 0,
1043 LR_CREATEDIBSECTION | LR_DEFAULTSIZE |
1044 LR_SHARED |
1045 (!NILP (file) ? LR_LOADFROMFILE : 0))))
1046 {
1047 signal_simple_error ("cannot load image", instantiator);
1048 }
1049
1050 mswindows_initialize_dibitmap_image_instance (ii, iitype);
1051
1052 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = file;
1053 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = (type==IMAGE_BITMAP ? himage : NULL);
1054 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
1055 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = (type!=IMAGE_BITMAP ? himage : NULL);
1056 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) =
1057 (type == IMAGE_CURSOR ? SM_CXCURSOR : SM_CXICON);
1058 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) =
1059 (type == IMAGE_CURSOR ? SM_CYCURSOR : SM_CYICON);
1060 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 0;
1061 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
1062 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
1063 }
1064
1065 void
1066 check_valid_symbol (Lisp_Object data)
1067 {
1068 CHECK_SYMBOL (data);
1069 }
1070
1071 void
1072 check_valid_string_or_int (Lisp_Object data)
1073 {
1074 if (!INTP (data))
1075 CHECK_STRING (data);
1076 else
1077 CHECK_INT (data);
818 } 1078 }
819 1079
820 1080
821 /************************************************************************/ 1081 /************************************************************************/
822 /* image instance methods */ 1082 /* image instance methods */
933 /************************************************************************/ 1193 /************************************************************************/
934 1194
935 void 1195 void
936 syms_of_glyphs_mswindows (void) 1196 syms_of_glyphs_mswindows (void)
937 { 1197 {
1198 defkeyword (&Q_resource_id, ":resource-id");
1199 defkeyword (&Q_resource_type, ":resource-type");
938 } 1200 }
939 1201
940 void 1202 void
941 console_type_create_glyphs_mswindows (void) 1203 console_type_create_glyphs_mswindows (void)
942 { 1204 {
965 IIFORMAT_HAS_METHOD (bmp, possible_dest_types); 1227 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
966 IIFORMAT_HAS_METHOD (bmp, instantiate); 1228 IIFORMAT_HAS_METHOD (bmp, instantiate);
967 1229
968 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string); 1230 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
969 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string); 1231 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
1232
1233 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor, "cursor");
1234
1235 IIFORMAT_HAS_METHOD (cursor, validate);
1236 IIFORMAT_HAS_METHOD (cursor, normalize);
1237 IIFORMAT_HAS_METHOD (cursor, possible_dest_types);
1238 IIFORMAT_HAS_METHOD (cursor, instantiate);
1239
1240 IIFORMAT_VALID_KEYWORD (cursor, Q_resource_type, check_valid_symbol);
1241 IIFORMAT_VALID_KEYWORD (cursor, Q_resource_id, check_valid_string_or_int);
1242 IIFORMAT_VALID_KEYWORD (cursor, Q_file, check_valid_string);
970 } 1243 }
971 1244
972 void 1245 void
973 vars_of_glyphs_mswindows (void) 1246 vars_of_glyphs_mswindows (void)
974 { 1247 {
975 Fprovide (Qbmp); 1248 Fprovide (Qbmp);
1249 Fprovide (Qcursor);
976 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /* 1250 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
977 A list of the directories in which mswindows bitmap files may be found. 1251 A list of the directories in which mswindows bitmap files may be found.
978 This is used by the `make-image-instance' function. 1252 This is used by the `make-image-instance' function.
979 */ ); 1253 */ );
980 Vmswindows_bitmap_file_path = Qnil; 1254 Vmswindows_bitmap_file_path = Qnil;