Mercurial > hg > xemacs-beta
comparison src/glyphs-msw.c @ 276:6330739388db r21-0b36
Import from CVS: tag r21-0b36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:30:37 +0200 |
parents | c5d627a313b1 |
children | 90d73dddcdc4 |
comparison
equal
deleted
inserted
replaced
275:a68ae4439f57 | 276:6330739388db |
---|---|
35 #include "insdel.h" | 35 #include "insdel.h" |
36 #include "opaque.h" | 36 #include "opaque.h" |
37 #include "sysfile.h" | 37 #include "sysfile.h" |
38 #include "faces.h" | 38 #include "faces.h" |
39 #include "imgproc.h" | 39 #include "imgproc.h" |
40 | |
41 #ifdef HAVE_XPM | |
42 #include <X11/xpm.h> | |
43 #endif | |
44 | 40 |
45 #ifdef FILE_CODING | 41 #ifdef FILE_CODING |
46 #include "file-coding.h" | 42 #include "file-coding.h" |
47 #endif | 43 #endif |
48 | 44 |
192 | 188 |
193 static Lisp_Object | 189 static Lisp_Object |
194 locate_pixmap_file (Lisp_Object name) | 190 locate_pixmap_file (Lisp_Object name) |
195 { | 191 { |
196 /* This function can GC if IN_REDISPLAY is false */ | 192 /* This function can GC if IN_REDISPLAY is false */ |
193 Lisp_Object found; | |
197 | 194 |
198 /* Check non-absolute pathnames with a directory component relative to | 195 /* Check non-absolute pathnames with a directory component relative to |
199 the search path; that's the way Xt does it. */ | 196 the search path; that's the way Xt does it. */ |
200 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) || | 197 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) || |
201 (XSTRING_BYTE (name, 0) == '.' && | 198 (XSTRING_BYTE (name, 0) == '.' && |
207 return name; | 204 return name; |
208 else | 205 else |
209 return Qnil; | 206 return Qnil; |
210 } | 207 } |
211 | 208 |
212 if (!NILP (Vmswindows_bitmap_file_path)) | 209 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0) |
213 { | 210 { |
214 Lisp_Object found; | 211 Lisp_Object temp = list1 (Vdata_directory); |
215 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0) | 212 struct gcpro gcpro1; |
216 { | 213 |
217 Lisp_Object temp = list1 (Vdata_directory); | 214 GCPRO1 (temp); |
218 struct gcpro gcpro1; | 215 locate_file (temp, name, "", &found, R_OK); |
219 | 216 UNGCPRO; |
220 GCPRO1 (temp); | 217 } |
221 locate_file (temp, name, "", &found, R_OK); | |
222 UNGCPRO; | |
223 } | |
224 | 218 |
225 return found; | 219 return found; |
226 } | |
227 else | |
228 return Qnil; | |
229 } | 220 } |
230 | 221 |
231 /* If INSTANTIATOR refers to inline data, return Qnil. | 222 /* If INSTANTIATOR refers to inline data, return Qnil. |
232 If INSTANTIATOR refers to data in a file, return the full filename | 223 If INSTANTIATOR refers to data in a file, return the full filename |
233 if it exists; otherwise, return a cons of (filename). | 224 if it exists; otherwise, return a cons of (filename). |
364 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth; | 355 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth; |
365 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight; | 356 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight; |
366 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount; | 357 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount; |
367 } | 358 } |
368 | 359 |
360 void | |
361 mswindows_create_icon_from_image(Lisp_Object image, struct frame* f, int size) | |
362 { | |
363 HBITMAP mask, bmp; | |
364 HDC hcdc = FRAME_MSWINDOWS_CDC (f); | |
365 HDC hdcDst = CreateCompatibleDC (hcdc); | |
366 ICONINFO x_icon; | |
367 | |
368 if (size!=16 && size!=32) | |
369 { | |
370 signal_simple_error("Icons must be 16x16 or 32x32", image); | |
371 } | |
372 | |
373 #if 0 | |
374 iIconWidth = GetSystemMetrics(SM_CXICON); | |
375 iIconHeight = GetSystemMetrics(SM_CYICON); | |
376 #endif | |
377 | |
378 SelectObject(hcdc, XIMAGE_INSTANCE_MSWINDOWS_BITMAP (image)); | |
379 | |
380 bmp = CreateCompatibleBitmap(hcdc, size, size); | |
381 DeleteObject( SelectObject(hdcDst, bmp) ); | |
382 | |
383 if (!StretchBlt(hdcDst, 0, 0, size, size, | |
384 hcdc, 0, 0, | |
385 XIMAGE_INSTANCE_PIXMAP_WIDTH (image), | |
386 XIMAGE_INSTANCE_PIXMAP_HEIGHT (image), | |
387 SRCCOPY)) | |
388 { | |
389 printf("StretchBlt failed\n"); | |
390 } | |
391 | |
392 if (!(mask = CreateBitmap(size, size, 1, 1, NULL))) | |
393 { | |
394 printf("CreateBitmap() failed\n"); | |
395 } | |
396 if (!SelectObject(hdcDst, mask) | |
397 || | |
398 !SelectObject(hcdc, bmp)) | |
399 { | |
400 printf("SelectObject() failed\n"); | |
401 } | |
402 | |
403 if (!BitBlt(hdcDst, 0, 0, size, size, | |
404 hcdc, 0, 0, | |
405 NOTSRCCOPY)) | |
406 { | |
407 printf("BitBlt failed\n"); | |
408 } | |
409 | |
410 SelectObject(hdcDst, 0); | |
411 SelectObject(hcdc, 0); | |
412 /* PatBlt(hdcDst, 0, 0, size, size, WHITENESS);*/ | |
413 | |
414 x_icon.fIcon=TRUE; | |
415 x_icon.xHotspot=XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image); | |
416 x_icon.yHotspot=XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image); | |
417 x_icon.hbmMask=mask; | |
418 x_icon.hbmColor=bmp; | |
419 | |
420 XIMAGE_INSTANCE_MSWINDOWS_ICON (image)= | |
421 CreateIconIndirect (&x_icon); | |
422 XIMAGE_INSTANCE_MSWINDOWS_MASK (image)=mask; | |
423 | |
424 DeleteDC(hdcDst); | |
425 } | |
426 | |
427 int | |
428 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii, | |
429 struct frame* f, | |
430 int newx, int newy) | |
431 { | |
432 HBITMAP newbmp; | |
433 HDC hcdc = FRAME_MSWINDOWS_CDC (f); | |
434 HDC hdcDst = CreateCompatibleDC (hcdc); | |
435 | |
436 SelectObject(hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)); | |
437 | |
438 newbmp = CreateCompatibleBitmap(hcdc, newx, newy); | |
439 | |
440 DeleteObject( SelectObject(hdcDst, newbmp) ); | |
441 | |
442 if (!StretchBlt(hdcDst, 0, 0, newx, newy, | |
443 hcdc, 0, 0, | |
444 IMAGE_INSTANCE_PIXMAP_WIDTH (ii), | |
445 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii), | |
446 SRCCOPY)) | |
447 { | |
448 return FALSE; | |
449 } | |
450 | |
451 SelectObject(hdcDst, 0); | |
452 SelectObject(hcdc, 0); | |
453 | |
454 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)) | |
455 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)); | |
456 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii)) | |
457 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii)); | |
458 | |
459 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp; | |
460 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newbmp; | |
461 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx; | |
462 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy; | |
463 | |
464 DeleteDC(hdcDst); | |
465 | |
466 return TRUE; | |
467 } | |
468 | |
369 /********************************************************************** | 469 /********************************************************************** |
370 * XPM * | 470 * XPM * |
371 **********************************************************************/ | 471 **********************************************************************/ |
372 | 472 |
373 #ifdef HAVE_XPM | 473 #ifdef HAVE_XPM |
374 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer, | 474 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer, |
375 unsigned char** data, | 475 unsigned char** data, |
376 int* width, int* height, | 476 int* width, int* height, |
377 COLORREF bg) | 477 int* x_hot, int* y_hot, |
478 COLORREF bg) | |
378 { | 479 { |
379 XpmImage xpmimage; | 480 XpmImage xpmimage; |
380 XpmInfo xpminfo; | 481 XpmInfo xpminfo; |
381 int result, i; | 482 int result, i, transp_idx, maskbpline; |
382 unsigned char* dptr; | 483 unsigned char* dptr; |
383 unsigned int* sptr; | 484 unsigned int* sptr; |
384 COLORREF color; /* the american spelling virus hits again .. */ | 485 COLORREF color; /* the american spelling virus hits again .. */ |
385 COLORREF* colortbl; | 486 COLORREF* colortbl; |
386 | 487 |
387 xzero (xpmimage); | 488 xzero (xpmimage); |
388 xzero (xpminfo); | 489 xzero (xpminfo); |
389 | 490 xpminfo.valuemask=XpmHotspot; |
491 | |
390 result = XpmCreateXpmImageFromBuffer ((char*)buffer, | 492 result = XpmCreateXpmImageFromBuffer ((char*)buffer, |
391 &xpmimage, | 493 &xpmimage, |
392 &xpminfo); | 494 &xpminfo); |
393 switch (result) | 495 switch (result) |
394 { | 496 { |
411 } | 513 } |
412 } | 514 } |
413 | 515 |
414 *width = xpmimage.width; | 516 *width = xpmimage.width; |
415 *height = xpmimage.height; | 517 *height = xpmimage.height; |
416 | 518 maskbpline = (int)(~3UL & (unsigned long) |
519 (((~7UL & (unsigned long)(*width + 7)) / 8) + 3)); | |
520 | |
417 *data = xnew_array_and_zero (unsigned char, *width * *height * 3); | 521 *data = xnew_array_and_zero (unsigned char, *width * *height * 3); |
522 | |
418 if (!*data) | 523 if (!*data) |
419 { | 524 { |
420 XpmFreeXpmImage (&xpmimage); | 525 XpmFreeXpmImage (&xpmimage); |
421 XpmFreeXpmInfo (&xpminfo); | 526 XpmFreeXpmInfo (&xpminfo); |
422 return 0; | 527 return 0; |
435 for (i=0; i<xpmimage.ncolors; i++) | 540 for (i=0; i<xpmimage.ncolors; i++) |
436 { | 541 { |
437 /* pick up transparencies */ | 542 /* pick up transparencies */ |
438 if (!strcmp (xpmimage.colorTable[i].c_color,"None")) | 543 if (!strcmp (xpmimage.colorTable[i].c_color,"None")) |
439 { | 544 { |
440 colortbl[i]=bg; | 545 colortbl[i]=bg; /* PALETTERGB(0,0,0); */ |
546 transp_idx=i; | |
441 } | 547 } |
442 else | 548 else |
443 { | 549 { |
444 colortbl[i]= | 550 colortbl[i]= |
445 mswindows_string_to_color (xpmimage.colorTable[i].c_color); | 551 mswindows_string_to_color (xpmimage.colorTable[i].c_color); |
457 *dptr++=GetRValue (color); /* red */ | 563 *dptr++=GetRValue (color); /* red */ |
458 *dptr++=GetGValue (color); /* green */ | 564 *dptr++=GetGValue (color); /* green */ |
459 *dptr++=GetBValue (color); /* blue */ | 565 *dptr++=GetBValue (color); /* blue */ |
460 } | 566 } |
461 | 567 |
568 *x_hot=xpminfo.x_hotspot; | |
569 *y_hot=xpminfo.y_hotspot; | |
570 | |
462 XpmFreeXpmImage (&xpmimage); | 571 XpmFreeXpmImage (&xpmimage); |
463 XpmFreeXpmInfo (&xpminfo); | 572 XpmFreeXpmInfo (&xpminfo); |
464 xfree (colortbl); | 573 xfree (colortbl); |
465 return TRUE; | 574 return TRUE; |
575 } | |
576 | |
577 Lisp_Object | |
578 mswindows_xpm_normalize (Lisp_Object inst, Lisp_Object console_type) | |
579 { | |
580 return simple_image_type_normalize (inst, console_type, Qxpm); | |
466 } | 581 } |
467 | 582 |
468 void | 583 void |
469 mswindows_xpm_instantiate (Lisp_Object image_instance, | 584 mswindows_xpm_instantiate (Lisp_Object image_instance, |
470 Lisp_Object instantiator, | 585 Lisp_Object instantiator, |
474 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | 589 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
475 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | 590 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
476 CONST Extbyte *bytes; | 591 CONST Extbyte *bytes; |
477 Extcount len; | 592 Extcount len; |
478 unsigned char *eimage; | 593 unsigned char *eimage; |
479 int width, height; | 594 int width, height, x_hot, y_hot; |
480 BITMAPINFO* bmp_info; | 595 BITMAPINFO* bmp_info; |
481 unsigned char* bmp_data; | 596 unsigned char* bmp_data; |
482 int bmp_bits; | 597 int bmp_bits; |
483 COLORREF bkcolor; | 598 COLORREF bkcolor; |
484 | 599 |
496 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR | 611 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR |
497 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain))); | 612 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain))); |
498 | 613 |
499 /* convert to an eimage to make processing easier */ | 614 /* convert to an eimage to make processing easier */ |
500 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height, | 615 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height, |
501 bkcolor)) | 616 &x_hot, &y_hot, bkcolor)) |
502 { | 617 { |
503 signal_simple_error ("XPM to EImage conversion failed", | 618 signal_simple_error ("XPM to EImage conversion failed", |
504 image_instance); | 619 image_instance); |
505 } | 620 } |
506 | 621 |
507 /* build a bitmap from the eimage */ | 622 /* build a bitmap from the eimage */ |
508 if (!(bmp_info=EImage2DIBitmap (device, width, height, eimage, | 623 if (!(bmp_info=EImage2DIBitmap (device, width, height, eimage, |
509 &bmp_bits, &bmp_data))) | 624 &bmp_bits, &bmp_data))) |
510 { | 625 { |
511 xfree (eimage); | |
512 signal_simple_error ("XPM to EImage conversion failed", | 626 signal_simple_error ("XPM to EImage conversion failed", |
513 image_instance); | 627 image_instance); |
514 } | 628 } |
515 xfree (eimage); | 629 xfree (eimage); |
516 | 630 |
517 /* Now create the pixmap and set up the image instance */ | 631 /* Now create the pixmap and set up the image instance */ |
518 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, | 632 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, |
519 bmp_data, bmp_bits, instantiator); | 633 bmp_data, bmp_bits, instantiator); |
520 | 634 |
635 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), x_hot); | |
636 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), y_hot); | |
637 | |
521 xfree (bmp_info); | 638 xfree (bmp_info); |
522 xfree (bmp_data); | 639 xfree (bmp_data); |
523 } | 640 } |
524 #endif /* HAVE_XPM */ | 641 #endif /* HAVE_XPM */ |
525 | 642 |
741 | 858 |
742 void | 859 void |
743 complex_vars_of_glyphs_mswindows (void) | 860 complex_vars_of_glyphs_mswindows (void) |
744 { | 861 { |
745 } | 862 } |
746 |