1 /* mswindows-specific glyph objects.
2 Copyright (C) 1998 Andy Piper.
4 This file is part of XEmacs.
6 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
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Synched up with: Not in FSF. */
23 /* written by Andy Piper <andy@xemacs.org> plagerising bits from
30 #define OEMRESOURCE /* Define OCR_ and friend constants */
31 #include "console-msw.h"
32 #include "glyphs-msw.h"
33 #include "objects-msw.h"
46 #include "file-coding.h"
54 #define WIDGET_GLYPH_SLOT 0
57 DEFINE_DEVICE_IIFORMAT (mswindows, xpm);
59 DEFINE_DEVICE_IIFORMAT (mswindows, xbm);
61 DEFINE_DEVICE_IIFORMAT (mswindows, xface);
63 DEFINE_DEVICE_IIFORMAT (mswindows, button);
64 DEFINE_DEVICE_IIFORMAT (mswindows, edit);
66 DEFINE_DEVICE_IIFORMAT (mswindows, group);
68 DEFINE_DEVICE_IIFORMAT (mswindows, subwindow);
69 DEFINE_DEVICE_IIFORMAT (mswindows, widget);
70 DEFINE_DEVICE_IIFORMAT (mswindows, label);
71 DEFINE_DEVICE_IIFORMAT (mswindows, scrollbar);
72 DEFINE_DEVICE_IIFORMAT (mswindows, combo);
73 DEFINE_DEVICE_IIFORMAT (mswindows, progress);
75 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
77 Lisp_Object Vmswindows_bitmap_file_path;
78 static COLORREF transparent_color = RGB (1,1,1);
80 DEFINE_IMAGE_INSTANTIATOR_FORMAT (mswindows_resource);
81 Lisp_Object Q_resource_type, Q_resource_id;
82 Lisp_Object Qmswindows_resource;
85 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
86 enum image_instance_type type);
88 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
91 COLORREF mswindows_string_to_color (CONST char *name);
93 #define BPLINE(width) ((int)(~3UL & (unsigned long)((width) +3)))
95 /************************************************************************/
96 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/
98 /************************************************************************/
99 static BITMAPINFO* convert_EImage_to_DIBitmap (Lisp_Object device,
100 int width, int height,
103 unsigned char** bmp_data)
105 struct device *d = XDEVICE (device);
109 BITMAPINFO* bmp_info;
110 unsigned char *ip, *dp;
112 if (DEVICE_MSWINDOWS_BITSPIXEL (d) > 0)
114 int bpline = BPLINE(width * 3);
115 /* FIXME: we can do this because 24bpp implies no color table, once
116 * we start palettizing this is no longer true. The X versions of
117 * this function quantises to 256 colors or bit masks down to a
118 * long. Windows can actually handle rgb triples in the raw so I
119 * don't see much point trying to optimize down to the best
120 * structure - unless it has memory / color allocation implications
122 bmp_info=xnew_and_zero (BITMAPINFO);
129 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */
130 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */
131 bmp_info->bmiHeader.biSizeImage=width*height*3;
133 /* bitmap data needs to be in blue, green, red triples - in that
134 order, eimage is in RGB format so we need to convert */
135 *bmp_data = xnew_array_and_zero (unsigned char, bpline * height);
136 *bit_count = bpline * height;
145 for (i = height-1; i >= 0; i--) {
146 dp = (*bmp_data) + (i * bpline);
147 for (j = 0; j < width; j++) {
155 else /* scale to 256 colors */
159 int bpline = BPLINE (width * 3);
160 /* Quantize the image and get a histogram while we're at it.
161 Do this first to save memory */
162 qtable = build_EImage_quantable(pic, width, height, 256);
163 if (qtable == NULL) return NULL;
165 /* use our quantize table to allocate the colors */
166 ncolors = qtable->num_active_colors;
167 bmp_info=(BITMAPINFO*)xmalloc_and_zero (sizeof(BITMAPINFOHEADER) +
168 sizeof(RGBQUAD) * ncolors);
175 colortbl=(RGBQUAD*)(((unsigned char*)bmp_info)+sizeof(BITMAPINFOHEADER));
177 bmp_info->bmiHeader.biBitCount=8;
178 bmp_info->bmiHeader.biCompression=BI_RGB;
179 bmp_info->bmiHeader.biSizeImage=bpline*height;
180 bmp_info->bmiHeader.biClrUsed=ncolors;
181 bmp_info->bmiHeader.biClrImportant=ncolors;
183 *bmp_data = (unsigned char *) xmalloc_and_zero (bpline * height);
184 *bit_count = bpline * height;
193 /* build up an RGBQUAD colortable */
194 for (i = 0; i < qtable->num_active_colors; i++) {
195 colortbl[i].rgbRed = (BYTE) qtable->rm[i];
196 colortbl[i].rgbGreen = (BYTE) qtable->gm[i];
197 colortbl[i].rgbBlue = (BYTE) qtable->bm[i];
198 colortbl[i].rgbReserved = 0;
201 /* now build up the data. picture has to be upside-down and
202 back-to-front for msw bitmaps */
204 for (i = height-1; i >= 0; i--) {
205 dp = (*bmp_data) + (i * bpline);
206 for (j = 0; j < width; j++) {
210 *dp++ = QUANT_GET_COLOR (qtable,rd,gr,bl);
215 /* fix up the standard stuff */
216 bmp_info->bmiHeader.biWidth=width;
217 bmp_info->bmiHeader.biHeight=height;
218 bmp_info->bmiHeader.biPlanes=1;
219 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
220 bmp_info->bmiHeader.biXPelsPerMeter=0; /* unless you know better */
221 bmp_info->bmiHeader.biYPelsPerMeter=0;
226 /* Given a pixmap filename, look through all of the "standard" places
227 where the file might be located. Return a full pathname if found;
228 otherwise, return Qnil. */
231 mswindows_locate_pixmap_file (Lisp_Object name)
233 /* This function can GC if IN_REDISPLAY is false */
236 /* Check non-absolute pathnames with a directory component relative to
237 the search path; that's the way Xt does it. */
238 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) ||
239 (XSTRING_BYTE (name, 0) == '.' &&
240 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 1)) ||
241 (XSTRING_BYTE (name, 1) == '.' &&
242 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 2)))))))
244 if (!NILP (Ffile_readable_p (name)))
250 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0)
252 Lisp_Object temp = list1 (Vdata_directory);
256 locate_file (temp, name, "", &found, R_OK);
264 /* Initialize an image instance from a bitmap
266 DEST_MASK specifies the mask of allowed image types.
268 If this fails, signal an error. INSTANTIATOR is only used
269 in the error message. */
272 init_image_instance_from_dibitmap (struct Lisp_Image_Instance *ii,
273 BITMAPINFO *bmp_info,
277 Lisp_Object instantiator,
278 int x_hot, int y_hot,
281 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
282 struct device *d = XDEVICE (device);
289 if (!DEVICE_MSWINDOWS_P (d))
290 signal_simple_error ("Not an mswindows device", device);
292 if (NILP (DEVICE_SELECTED_FRAME (d)))
293 signal_simple_error ("No selected frame on mswindows device", device);
295 f = XFRAME (DEVICE_SELECTED_FRAME (d));
297 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
298 type = IMAGE_COLOR_PIXMAP;
299 else if (dest_mask & IMAGE_POINTER_MASK)
300 type = IMAGE_POINTER;
302 incompatible_image_types (instantiator, dest_mask,
303 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
304 hdc = FRAME_MSWINDOWS_CDC (f);
306 bitmap=CreateDIBSection (hdc,
312 if (!bitmap || !bmp_buf)
313 signal_simple_error ("Unable to create bitmap", instantiator);
315 /* copy in the actual bitmap */
316 memcpy (bmp_buf, bmp_data, bmp_bits);
318 mswindows_initialize_dibitmap_image_instance (ii, type);
320 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
321 find_keyword_in_vector (instantiator, Q_file);
323 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap;
324 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
325 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth;
326 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight;
327 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount;
328 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), x_hot);
329 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), y_hot);
333 mswindows_initialize_image_instance_mask (ii, f);
336 if (type == IMAGE_POINTER)
338 mswindows_initialize_image_instance_icon(ii, TRUE);
343 mswindows_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
344 int width, int height,
345 unsigned char *eimage,
347 Lisp_Object instantiator,
350 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
351 BITMAPINFO* bmp_info;
352 unsigned char* bmp_data;
356 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
357 signal_simple_error ("Not an mswindows device", device);
359 /* this is a hack but MaskBlt and TransparentBlt are not supported
360 on most windows variants */
361 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
362 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
364 /* build a bitmap from the eimage */
365 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
366 &bmp_bits, &bmp_data)))
368 signal_simple_error ("EImage to DIBitmap conversion failed",
372 /* Now create the pixmap and set up the image instance */
373 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
374 bmp_data, bmp_bits, instantiator,
381 static void set_mono_pixel ( unsigned char* bits,
382 int bpline, int height,
383 int x, int y, int white )
386 unsigned char bitnum;
387 /* Find the byte on which this scanline begins */
388 index = (height - y - 1) * bpline;
389 /* Find the byte containing this pixel */
391 /* Which bit is it? */
392 bitnum = (unsigned char)( 7 - (x % 8) );
393 if( white ) /* Turn it on */
394 bits[index] |= (1<<bitnum);
395 else /* Turn it off */
396 bits[index] &= ~(1<<bitnum);
400 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
405 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
406 unsigned char* dibits;
407 BITMAPINFO* bmp_info =
408 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
410 int height = IMAGE_INSTANCE_PIXMAP_HEIGHT (image);
413 int maskbpline = BPLINE (((IMAGE_INSTANCE_PIXMAP_WIDTH (image)+7)/8));
414 int bpline = BPLINE (IMAGE_INSTANCE_PIXMAP_WIDTH (image) * 3);
419 bmp_info->bmiHeader.biWidth=IMAGE_INSTANCE_PIXMAP_WIDTH (image);
420 bmp_info->bmiHeader.biHeight = height;
421 bmp_info->bmiHeader.biPlanes=1;
422 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
423 bmp_info->bmiHeader.biBitCount=1;
424 bmp_info->bmiHeader.biCompression=BI_RGB;
425 bmp_info->bmiHeader.biClrUsed = 2;
426 bmp_info->bmiHeader.biClrImportant = 2;
427 bmp_info->bmiHeader.biSizeImage = height * maskbpline;
428 bmp_info->bmiColors[0].rgbRed = 0;
429 bmp_info->bmiColors[0].rgbGreen = 0;
430 bmp_info->bmiColors[0].rgbBlue = 0;
431 bmp_info->bmiColors[0].rgbReserved = 0;
432 bmp_info->bmiColors[1].rgbRed = 255;
433 bmp_info->bmiColors[1].rgbGreen = 255;
434 bmp_info->bmiColors[1].rgbBlue = 255;
435 bmp_info->bmiColors[0].rgbReserved = 0;
437 if (!(mask = CreateDIBSection (hcdc,
447 old = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (image));
448 /* build up an in-memory set of bits to mess with */
451 bmp_info->bmiHeader.biWidth=IMAGE_INSTANCE_PIXMAP_WIDTH (image);
452 bmp_info->bmiHeader.biHeight = -height;
453 bmp_info->bmiHeader.biPlanes=1;
454 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
455 bmp_info->bmiHeader.biBitCount=24;
456 bmp_info->bmiHeader.biCompression=BI_RGB;
457 bmp_info->bmiHeader.biClrUsed = 0;
458 bmp_info->bmiHeader.biClrImportant = 0;
459 bmp_info->bmiHeader.biSizeImage = height * bpline;
461 dibits = xmalloc_and_zero (bpline * height);
463 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image),
468 DIB_RGB_COLORS) <= 0)
474 /* now set the colored bits in the mask and transparent ones to
475 black in the original */
476 for(i=0; i<IMAGE_INSTANCE_PIXMAP_WIDTH (image); i++)
478 for(j=0; j<height; j++)
480 unsigned char* idx = &dibits[j * bpline + i * 3];
482 if( RGB (idx[2], idx[1], idx[0]) == transparent_color )
484 idx[0] = idx[1] = idx[2] = 0;
485 set_mono_pixel( and_bits, maskbpline, height, i, j, TRUE );
489 set_mono_pixel( and_bits, maskbpline, height, i, j, FALSE );
495 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image),
505 SelectObject(hcdc, old);
507 IMAGE_INSTANCE_MSWINDOWS_MASK (image) = mask;
511 mswindows_initialize_image_instance_icon (struct Lisp_Image_Instance* image,
516 /* we rely on windows to do any resizing necessary */
517 x_icon.fIcon=cursor ? FALSE : TRUE;
518 x_icon.xHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image));
519 x_icon.yHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image));
520 x_icon.hbmMask=IMAGE_INSTANCE_MSWINDOWS_MASK (image);
521 x_icon.hbmColor=IMAGE_INSTANCE_MSWINDOWS_BITMAP (image);
523 IMAGE_INSTANCE_MSWINDOWS_ICON (image)=
524 CreateIconIndirect (&x_icon);
528 mswindows_create_resized_bitmap (struct Lisp_Image_Instance* ii,
534 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
535 HDC hdcDst = CreateCompatibleDC (hcdc);
537 old1 = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
539 newbmp = CreateCompatibleBitmap (hcdc, newx, newy);
541 old2 = SelectObject (hdcDst, newbmp);
543 if (!StretchBlt (hdcDst, 0, 0, newx, newy,
545 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
546 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
549 DeleteObject (newbmp);
554 SelectObject (hdcDst, old2);
555 SelectObject (hcdc, old1);
562 mswindows_create_resized_mask (struct Lisp_Image_Instance* ii,
566 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
570 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
571 HDC hdcDst = CreateCompatibleDC (hcdc);
573 old1 = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
574 newmask = CreateCompatibleBitmap(hcdc, newx, newy);
575 old2 = SelectObject (hdcDst, newmask);
577 if (!StretchBlt(hdcDst, 0, 0, newx, newy,
579 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
580 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
583 DeleteObject (newmask);
588 SelectObject (hdcDst, old2);
589 SelectObject (hcdc, old1);
600 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii,
604 HBITMAP newbmp = mswindows_create_resized_bitmap (ii, f, newx, newy);
605 HBITMAP newmask = mswindows_create_resized_mask (ii, f, newx, newy);
610 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii))
611 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
612 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
613 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
615 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp;
616 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newmask;
617 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx;
618 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy;
623 /**********************************************************************
625 **********************************************************************/
635 static struct color_symbol*
636 extract_xpm_color_names (Lisp_Object device,
638 Lisp_Object color_symbol_alist,
641 /* This function can GC */
643 Lisp_Object results = Qnil;
645 struct color_symbol *colortbl;
646 struct gcpro gcpro1, gcpro2;
648 GCPRO2 (results, device);
650 /* We built up results to be (("name" . #<color>) ...) so that if an
651 error happens we don't lose any malloc()ed data, or more importantly,
652 leave any pixels allocated in the server. */
654 LIST_LOOP (rest, color_symbol_alist)
656 Lisp_Object cons = XCAR (rest);
657 Lisp_Object name = XCAR (cons);
658 Lisp_Object value = XCDR (cons);
664 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
667 assert (COLOR_SPECIFIERP (value));
668 value = Fspecifier_instance (value, domain, Qnil, Qnil);
672 results = noseeum_cons (noseeum_cons (name, value), results);
675 UNGCPRO; /* no more evaluation */
678 if (i == 0) return 0;
680 colortbl = xnew_array_and_zero (struct color_symbol, i);
684 Lisp_Object cons = XCAR (results);
686 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
688 GET_C_STRING_OS_DATA_ALLOCA (XCAR (cons), colortbl[j].name);
689 free_cons (XCONS (cons));
691 results = XCDR (results);
692 free_cons (XCONS (cons));
697 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer,
698 unsigned char** data,
699 int* width, int* height,
700 int* x_hot, int* y_hot,
702 struct color_symbol* color_symbols,
707 int result, i, j, transp_idx, maskbpline;
710 COLORREF color; /* the american spelling virus hits again .. */
715 xpminfo.valuemask=XpmHotspot;
718 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
727 signal_simple_error ("Invalid XPM data", image);
731 signal_double_file_error ("Parsing pixmap data",
732 "out of memory", image);
736 signal_double_file_error_2 ("Parsing pixmap data",
737 "unknown error code",
738 make_int (result), image);
742 *width = xpmimage.width;
743 *height = xpmimage.height;
744 maskbpline = BPLINE (((~7UL & (unsigned long)(*width + 7)) / 8));
746 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
750 XpmFreeXpmImage (&xpmimage);
751 XpmFreeXpmInfo (&xpminfo);
755 /* build a color table to speed things up */
756 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
760 XpmFreeXpmImage (&xpmimage);
761 XpmFreeXpmInfo (&xpminfo);
765 for (i=0; i<xpmimage.ncolors; i++)
768 /* pick up symbolic colors in preference */
769 if (xpmimage.colorTable[i].symbolic)
771 if (!strcasecmp (xpmimage.colorTable[i].symbolic,"BgColor")
773 !strcasecmp (xpmimage.colorTable[i].symbolic,"None"))
776 colortbl[i]=transparent_color;
778 goto label_found_color;
780 else if (color_symbols)
782 for (j = 0; j<nsymbols; j++)
784 if (!strcmp (xpmimage.colorTable[i].symbolic,
785 color_symbols[j].name ))
787 colortbl[i]=color_symbols[j].color;
788 goto label_found_color;
792 else if (xpmimage.colorTable[i].c_color == 0)
797 /* pick up transparencies */
798 if (!strcasecmp (xpmimage.colorTable[i].c_color,"None"))
801 colortbl[i]=transparent_color;
803 goto label_found_color;
805 /* finally pick up a normal color spec */
806 if (xpmimage.colorTable[i].c_color)
809 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
810 goto label_found_color;
816 XpmFreeXpmImage (&xpmimage);
817 XpmFreeXpmInfo (&xpminfo);
823 /* convert the image */
826 for (i = 0; i< *width * *height; i++)
828 color = colortbl[*sptr++];
830 /* split out the 0x02bbggrr colorref into an rgb triple */
831 *dptr++=GetRValue (color); /* red */
832 *dptr++=GetGValue (color); /* green */
833 *dptr++=GetBValue (color); /* blue */
836 *x_hot=xpminfo.x_hotspot;
837 *y_hot=xpminfo.y_hotspot;
839 XpmFreeXpmImage (&xpmimage);
840 XpmFreeXpmInfo (&xpminfo);
846 mswindows_xpm_instantiate (Lisp_Object image_instance,
847 Lisp_Object instantiator,
848 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
849 int dest_mask, Lisp_Object domain)
851 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
852 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
853 CONST Extbyte *bytes;
855 unsigned char *eimage;
856 int width, height, x_hot, y_hot;
857 BITMAPINFO* bmp_info;
858 unsigned char* bmp_data;
860 int nsymbols=0, transp;
861 struct color_symbol* color_symbols=NULL;
863 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
864 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
867 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
868 signal_simple_error ("Not an mswindows device", device);
870 assert (!NILP (data));
872 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
874 /* in case we have color symbols */
875 color_symbols = extract_xpm_color_names (device, domain,
876 color_symbol_alist, &nsymbols);
878 /* convert to an eimage to make processing easier */
879 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
880 &x_hot, &y_hot, &transp, color_symbols, nsymbols))
882 signal_simple_error ("XPM to EImage conversion failed",
887 xfree(color_symbols);
889 /* build a bitmap from the eimage */
890 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
891 &bmp_bits, &bmp_data)))
893 signal_simple_error ("XPM to EImage conversion failed",
898 /* Now create the pixmap and set up the image instance */
899 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
900 bmp_data, bmp_bits, instantiator,
901 x_hot, y_hot, transp);
906 #endif /* HAVE_XPM */
908 /**********************************************************************
910 **********************************************************************/
913 bmp_validate (Lisp_Object instantiator)
915 file_or_data_must_be_present (instantiator);
919 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
921 return simple_image_type_normalize (inst, console_type, Qbmp);
925 bmp_possible_dest_types (void)
927 return IMAGE_COLOR_PIXMAP_MASK;
931 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
932 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
933 int dest_mask, Lisp_Object domain)
935 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
936 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
937 CONST Extbyte *bytes;
939 BITMAPFILEHEADER* bmp_file_header;
940 BITMAPINFO* bmp_info;
943 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
945 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
946 signal_simple_error ("Not an mswindows device", device);
948 assert (!NILP (data));
950 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
952 /* Then slurp the image into memory, decoding along the way.
953 The result is the image in a simple one-byte-per-pixel
956 bmp_file_header=(BITMAPFILEHEADER*)bytes;
957 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
958 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
959 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
961 /* Now create the pixmap and set up the image instance */
962 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
963 bmp_data, bmp_bits, instantiator,
968 /**********************************************************************
970 **********************************************************************/
973 mswindows_resource_validate (Lisp_Object instantiator)
975 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
977 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
979 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
980 signal_simple_error ("Must supply :file, :resource-id and :resource-type",
985 mswindows_resource_normalize (Lisp_Object inst, Lisp_Object console_type)
987 /* This function can call lisp */
988 Lisp_Object file = Qnil;
989 struct gcpro gcpro1, gcpro2;
990 Lisp_Object alist = Qnil;
992 GCPRO2 (file, alist);
994 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
997 if (CONSP (file)) /* failure locating filename */
998 signal_double_file_error ("Opening pixmap file",
999 "no such file or directory",
1002 if (NILP (file)) /* no conversion necessary */
1003 RETURN_UNGCPRO (inst);
1005 alist = tagged_vector_to_alist (inst);
1008 alist = remassq_no_quit (Q_file, alist);
1009 alist = Fcons (Fcons (Q_file, file), alist);
1013 Lisp_Object result = alist_to_tagged_vector (Qmswindows_resource, alist);
1015 RETURN_UNGCPRO (result);
1020 mswindows_resource_possible_dest_types (void)
1022 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
1032 #define OCR_ICOCUR 32647
1033 #define OIC_SAMPLE 32512
1034 #define OIC_HAND 32513
1035 #define OIC_QUES 32514
1036 #define OIC_BANG 32515
1037 #define OIC_NOTE 32516
1038 #define OIC_WINLOGO 32517
1039 #define LR_SHARED 0x8000
1042 static CONST resource_t bitmap_table[] =
1045 { "close", OBM_CLOSE },
1046 { "uparrow", OBM_UPARROW },
1047 { "dnarrow", OBM_DNARROW },
1048 { "rgarrow", OBM_RGARROW },
1049 { "lfarrow", OBM_LFARROW },
1050 { "reduce", OBM_REDUCE },
1051 { "zoom", OBM_ZOOM },
1052 { "restore", OBM_RESTORE },
1053 { "reduced", OBM_REDUCED },
1054 { "zoomd", OBM_ZOOMD },
1055 { "restored", OBM_RESTORED },
1056 { "uparrowd", OBM_UPARROWD },
1057 { "dnarrowd", OBM_DNARROWD },
1058 { "rgarrowd", OBM_RGARROWD },
1059 { "lfarrowd", OBM_LFARROWD },
1060 { "mnarrow", OBM_MNARROW },
1061 { "combo", OBM_COMBO },
1062 { "uparrowi", OBM_UPARROWI },
1063 { "dnarrowi", OBM_DNARROWI },
1064 { "rgarrowi", OBM_RGARROWI },
1065 { "lfarrowi", OBM_LFARROWI },
1066 { "size", OBM_SIZE },
1067 { "btsize", OBM_BTSIZE },
1068 { "check", OBM_CHECK },
1069 { "checkboxes", OBM_CHECKBOXES },
1070 { "btncorners" , OBM_BTNCORNERS },
1074 static CONST resource_t cursor_table[] =
1077 { "normal", OCR_NORMAL },
1078 { "ibeam", OCR_IBEAM },
1079 { "wait", OCR_WAIT },
1080 { "cross", OCR_CROSS },
1082 /* { "icon", OCR_ICON }, */
1083 { "sizenwse", OCR_SIZENWSE },
1084 { "sizenesw", OCR_SIZENESW },
1085 { "sizewe", OCR_SIZEWE },
1086 { "sizens", OCR_SIZENS },
1087 { "sizeall", OCR_SIZEALL },
1088 /* { "icour", OCR_ICOCUR }, */
1093 static CONST resource_t icon_table[] =
1096 { "sample", OIC_SAMPLE },
1097 { "hand", OIC_HAND },
1098 { "ques", OIC_QUES },
1099 { "bang", OIC_BANG },
1100 { "note", OIC_NOTE },
1101 { "winlogo", OIC_WINLOGO },
1105 static int resource_name_to_resource (Lisp_Object name, int type)
1107 CONST resource_t* res = (type == IMAGE_CURSOR ? cursor_table
1108 : type == IMAGE_ICON ? icon_table
1115 else if (!STRINGP (name))
1117 signal_simple_error ("invalid resource identifier", name);
1122 GET_C_STRING_OS_DATA_ALLOCA (name, nm);
1123 if (!strcasecmp ((char*)res->name, nm))
1124 return res->resource_id;
1125 } while ((++res)->name);
1130 resource_symbol_to_type (Lisp_Object data)
1132 if (EQ (data, Qcursor))
1133 return IMAGE_CURSOR;
1134 else if (EQ (data, Qicon))
1136 else if (EQ (data, Qbitmap))
1137 return IMAGE_BITMAP;
1143 mswindows_resource_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1144 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1145 int dest_mask, Lisp_Object domain)
1147 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1148 unsigned int type = 0;
1149 HANDLE himage = NULL;
1151 HINSTANCE hinst = NULL;
1155 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1157 Lisp_Object file = find_keyword_in_vector (instantiator, Q_file);
1158 Lisp_Object resource_type = find_keyword_in_vector (instantiator,
1160 Lisp_Object resource_id = find_keyword_in_vector (instantiator,
1165 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
1166 signal_simple_error ("Not an mswindows device", device);
1168 type = resource_symbol_to_type (resource_type);
1170 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_CURSOR)
1171 iitype = IMAGE_POINTER;
1172 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1173 iitype = IMAGE_COLOR_PIXMAP;
1175 incompatible_image_types (instantiator, dest_mask,
1176 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
1178 /* mess with the keyword info we were provided with */
1182 GET_C_STRING_FILENAME_DATA_ALLOCA (file, f);
1184 CYGWIN_WIN32_PATH (f, fname);
1189 if (NILP (resource_id))
1190 resid = (LPCTSTR)fname;
1193 hinst = LoadLibraryEx (fname, NULL,
1194 LOAD_LIBRARY_AS_DATAFILE);
1195 resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1199 GET_C_STRING_OS_DATA_ALLOCA (resource_id, resid);
1202 else if (!(resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1204 signal_simple_error ("Invalid resource identifier", resource_id);
1206 /* load the image */
1207 if (!(himage = LoadImage (hinst, resid, type, 0, 0,
1208 LR_CREATEDIBSECTION | LR_DEFAULTSIZE |
1210 (!NILP (file) ? LR_LOADFROMFILE : 0))))
1212 signal_simple_error ("Cannot load image", instantiator);
1216 FreeLibrary (hinst);
1218 mswindows_initialize_dibitmap_image_instance (ii, iitype);
1220 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = file;
1221 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) =
1222 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CXCURSOR : SM_CXICON);
1223 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) =
1224 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CYCURSOR : SM_CYICON);
1225 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
1227 /* hey, we've got an icon type thing so we can reverse engineer the
1229 if (type != IMAGE_BITMAP)
1231 GetIconInfo (himage, &iconinfo);
1232 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = iconinfo.hbmColor;
1233 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = iconinfo.hbmMask;
1234 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), iconinfo.xHotspot);
1235 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), iconinfo.yHotspot);
1236 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = himage;
1240 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = NULL;
1241 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = himage;
1242 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
1243 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
1244 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
1249 check_valid_resource_symbol (Lisp_Object data)
1251 CHECK_SYMBOL (data);
1252 if (!resource_symbol_to_type (data))
1253 signal_simple_error ("invalid resource type", data);
1257 check_valid_resource_id (Lisp_Object data)
1259 if (!resource_name_to_resource (data, IMAGE_CURSOR)
1261 !resource_name_to_resource (data, IMAGE_ICON)
1263 !resource_name_to_resource (data, IMAGE_BITMAP))
1264 signal_simple_error ("invalid resource identifier", data);
1268 check_valid_string_or_int (Lisp_Object data)
1271 CHECK_STRING (data);
1276 /**********************************************************************
1278 **********************************************************************/
1279 #ifndef HAVE_X_WINDOWS
1280 /* $XConsortium: RdBitF.c,v 1.10 94/04/17 20:16:13 kaleb Exp $ */
1284 Copyright (c) 1988 X Consortium
1286 Permission is hereby granted, free of charge, to any person obtaining a copy
1287 of this software and associated documentation files (the "Software"), to deal
1288 in the Software without restriction, including without limitation the rights
1289 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1290 copies of the Software, and to permit persons to whom the Software is
1291 furnished to do so, subject to the following conditions:
1293 The above copyright notice and this permission notice shall be included in
1294 all copies or substantial portions of the Software.
1296 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1297 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1298 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1299 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1300 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1301 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1303 Except as contained in this notice, the name of the X Consortium shall not be
1304 used in advertising or otherwise to promote the sale, use or other dealings
1305 in this Software without prior written authorization from the X Consortium.
1310 * This file contains miscellaneous utility routines and is not part of the
1313 * Public entry points:
1315 * XmuReadBitmapData read data from FILE descriptor
1316 * XmuReadBitmapDataFromFile read X10 or X11 format bitmap files
1319 * Note that this file and ../X/XRdBitF.c look very similar.... Keep them
1320 * that way (but don't use common source code so that people can have one
1321 * without the other).
1326 * Based on an optimized version provided by Jim Becker, August 5, 1988.
1328 #ifndef BitmapSuccess
1329 #define BitmapSuccess 0
1330 #define BitmapOpenFailed 1
1331 #define BitmapFileInvalid 2
1332 #define BitmapNoMemory 3
1334 #define MAX_SIZE 255
1336 /* shared data for the image read/parse logic */
1337 static short hexTable[256]; /* conversion value */
1338 static int initialized = FALSE; /* easier to fill in at run time */
1341 * Table index for the hex values. Initialized once, first time.
1342 * Used for translation value or delimiter significance lookup.
1344 static void initHexTable()
1347 * We build the table at run time for several reasons:
1349 * 1. portable to non-ASCII machines.
1350 * 2. still reentrant since we set the init flag after setting table.
1351 * 3. easier to extend.
1352 * 4. less prone to bugs.
1354 hexTable['0'] = 0; hexTable['1'] = 1;
1355 hexTable['2'] = 2; hexTable['3'] = 3;
1356 hexTable['4'] = 4; hexTable['5'] = 5;
1357 hexTable['6'] = 6; hexTable['7'] = 7;
1358 hexTable['8'] = 8; hexTable['9'] = 9;
1359 hexTable['A'] = 10; hexTable['B'] = 11;
1360 hexTable['C'] = 12; hexTable['D'] = 13;
1361 hexTable['E'] = 14; hexTable['F'] = 15;
1362 hexTable['a'] = 10; hexTable['b'] = 11;
1363 hexTable['c'] = 12; hexTable['d'] = 13;
1364 hexTable['e'] = 14; hexTable['f'] = 15;
1366 /* delimiters of significance are flagged w/ negative value */
1367 hexTable[' '] = -1; hexTable[','] = -1;
1368 hexTable['}'] = -1; hexTable['\n'] = -1;
1369 hexTable['\t'] = -1;
1375 * read next hex value in the input stream, return -1 if EOF
1377 static int NextInt ( FILE *fstream )
1384 /* loop, accumulate hex value until find delimiter */
1385 /* skip any initial delimiters found in read stream */
1393 /* trim high bits, check type and accumulate */
1395 if (isascii(ch) && isxdigit(ch)) {
1396 value = (value << 4) + hexTable[ch];
1398 } else if ((hexTable[ch]) < 0 && gotone)
1407 * The data returned by the following routine is always in left-most byte
1408 * first and left-most bit first. If it doesn't return BitmapSuccess then
1409 * its arguments won't have been touched. This routine should look as much
1410 * like the Xlib routine XReadBitmapfile as possible.
1412 int read_bitmap_data (fstream, width, height, datap, x_hot, y_hot)
1413 FILE *fstream; /* handle on file */
1414 unsigned int *width, *height; /* RETURNED */
1415 unsigned char **datap; /* RETURNED */
1416 int *x_hot, *y_hot; /* RETURNED */
1418 unsigned char *data = NULL; /* working variable */
1419 char line[MAX_SIZE]; /* input line from file */
1420 int size; /* number of bytes of data */
1421 char name_and_type[MAX_SIZE]; /* an input line */
1422 char *type; /* for parsing */
1423 int value; /* from an input line */
1424 int version10p; /* boolean, old format */
1425 int padding; /* to handle alignment */
1426 int bytes_per_line; /* per scanline of data */
1427 unsigned int ww = 0; /* width */
1428 unsigned int hh = 0; /* height */
1429 int hx = -1; /* x hotspot */
1430 int hy = -1; /* y hotspot */
1432 #define Xmalloc(size) malloc(size)
1434 /* first time initialization */
1435 if (initialized == FALSE) initHexTable();
1437 /* error cleanup and return macro */
1438 #define RETURN(code) { if (data) free (data); return code; }
1440 while (fgets(line, MAX_SIZE, fstream)) {
1441 if (strlen(line) == MAX_SIZE-1) {
1442 RETURN (BitmapFileInvalid);
1444 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
1445 if (!(type = strrchr(name_and_type, '_')))
1446 type = name_and_type;
1450 if (!strcmp("width", type))
1451 ww = (unsigned int) value;
1452 if (!strcmp("height", type))
1453 hh = (unsigned int) value;
1454 if (!strcmp("hot", type)) {
1455 if (type-- == name_and_type || type-- == name_and_type)
1457 if (!strcmp("x_hot", type))
1459 if (!strcmp("y_hot", type))
1465 if (sscanf(line, "static short %s = {", name_and_type) == 1)
1467 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
1469 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
1474 if (!(type = strrchr(name_and_type, '_')))
1475 type = name_and_type;
1479 if (strcmp("bits[]", type))
1483 RETURN (BitmapFileInvalid);
1485 if ((ww % 16) && ((ww % 16) < 9) && version10p)
1490 bytes_per_line = (ww+7)/8 + padding;
1492 size = bytes_per_line * hh;
1493 data = (unsigned char *) Xmalloc ((unsigned int) size);
1495 RETURN (BitmapNoMemory);
1501 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
1502 if ((value = NextInt(fstream)) < 0)
1503 RETURN (BitmapFileInvalid);
1505 if (!padding || ((bytes+2) % bytes_per_line))
1506 *(ptr++) = value >> 8;
1512 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
1513 if ((value = NextInt(fstream)) < 0)
1514 RETURN (BitmapFileInvalid);
1522 RETURN (BitmapFileInvalid);
1529 if (x_hot) *x_hot = hx;
1530 if (y_hot) *y_hot = hy;
1532 RETURN (BitmapSuccess);
1536 int read_bitmap_data_from_file (CONST char *filename, unsigned int *width,
1537 unsigned int *height, unsigned char **datap,
1538 int *x_hot, int *y_hot)
1543 if ((fstream = fopen (filename, "r")) == NULL) {
1544 return BitmapOpenFailed;
1546 status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot);
1550 #endif /* HAVE_X_WINDOWS */
1552 /* this table flips four bits around. */
1553 static int flip_table[] =
1555 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
1558 /* the bitmap data comes in the following format: Widths are padded to
1559 a multiple of 8. Scan lines are stored in increasing byte order
1560 from left to right, little-endian within a byte. 0 = white, 1 =
1561 black. It must be converted to the following format: Widths are
1562 padded to a multiple of 16. Scan lines are stored in increasing
1563 byte order from left to right, big-endian within a byte. 0 =
1564 black, 1 = white. */
1566 xbm_create_bitmap_from_data (HDC hdc, char *data,
1567 unsigned int width, unsigned int height,
1568 int mask, COLORREF fg, COLORREF bg)
1570 int old_width = (width + 7)/8;
1571 int new_width = BPLINE (2*((width + 15)/16));
1572 unsigned char *offset;
1574 unsigned char *new_data, *new_offset;
1576 BITMAPINFO* bmp_info =
1577 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
1583 new_data = (unsigned char *) xmalloc_and_zero (height * new_width);
1591 for (i=0; i<height; i++)
1593 offset = data + i*old_width;
1594 new_offset = new_data + i*new_width;
1596 for (j=0; j<old_width; j++)
1598 int byte = offset[j];
1599 new_offset[j] = ~ (unsigned char)
1600 ((flip_table[byte & 0xf] << 4) + flip_table[byte >> 4]);
1604 /* if we want a mask invert the bits */
1607 new_offset = &new_data[height * new_width];
1608 while (new_offset-- != new_data)
1610 *new_offset ^= 0xff;
1614 bmp_info->bmiHeader.biWidth=width;
1615 bmp_info->bmiHeader.biHeight=-(LONG)height;
1616 bmp_info->bmiHeader.biPlanes=1;
1617 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
1618 bmp_info->bmiHeader.biBitCount=1;
1619 bmp_info->bmiHeader.biCompression=BI_RGB;
1620 bmp_info->bmiHeader.biClrUsed = 2;
1621 bmp_info->bmiHeader.biClrImportant = 2;
1622 bmp_info->bmiHeader.biSizeImage = height * new_width;
1623 bmp_info->bmiColors[0].rgbRed = GetRValue (fg);
1624 bmp_info->bmiColors[0].rgbGreen = GetGValue (fg);
1625 bmp_info->bmiColors[0].rgbBlue = GetBValue (fg);
1626 bmp_info->bmiColors[0].rgbReserved = 0;
1627 bmp_info->bmiColors[1].rgbRed = GetRValue (bg);
1628 bmp_info->bmiColors[1].rgbGreen = GetGValue (bg);
1629 bmp_info->bmiColors[1].rgbBlue = GetBValue (bg);
1630 bmp_info->bmiColors[1].rgbReserved = 0;
1632 bitmap = CreateDIBSection (hdc,
1640 if (!bitmap || !bmp_buf)
1646 /* copy in the actual bitmap */
1647 memcpy (bmp_buf, new_data, height * new_width);
1653 /* Given inline data for a mono pixmap, initialize the given
1654 image instance accordingly. */
1657 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
1658 int width, int height,
1659 /* Note that data is in ext-format! */
1661 Lisp_Object instantiator,
1662 Lisp_Object pointer_fg,
1663 Lisp_Object pointer_bg,
1666 Lisp_Object mask_filename)
1668 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1669 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (device)));
1670 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
1671 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
1672 enum image_instance_type type;
1673 COLORREF black = PALETTERGB (0,0,0);
1674 COLORREF white = PALETTERGB (255,255,255);
1676 HDC hdc = FRAME_MSWINDOWS_CDC (f);
1678 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
1679 signal_simple_error ("Not an MS-Windows device", device);
1681 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
1682 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
1684 if (!NILP (foreground) || !NILP (background))
1685 type = IMAGE_COLOR_PIXMAP;
1687 type = IMAGE_MONO_PIXMAP;
1689 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
1690 type = IMAGE_MONO_PIXMAP;
1691 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1692 type = IMAGE_COLOR_PIXMAP;
1693 else if (dest_mask & IMAGE_POINTER_MASK)
1694 type = IMAGE_POINTER;
1696 incompatible_image_types (instantiator, dest_mask,
1697 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
1698 | IMAGE_POINTER_MASK);
1700 mswindows_initialize_dibitmap_image_instance (ii, type);
1702 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
1703 find_keyword_in_vector (instantiator, Q_file);
1704 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
1705 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
1706 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
1707 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
1708 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
1709 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = mask ? mask :
1710 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1711 TRUE, black, white);
1715 case IMAGE_MONO_PIXMAP:
1716 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1717 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1718 FALSE, black, black);
1721 case IMAGE_COLOR_PIXMAP:
1723 COLORREF fg = black;
1724 COLORREF bg = white;
1726 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
1728 Fmake_color_instance (foreground, device,
1729 encode_error_behavior_flag (ERROR_ME));
1731 if (COLOR_INSTANCEP (foreground))
1732 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
1734 if (!NILP (background) && !COLOR_INSTANCEP (background))
1736 Fmake_color_instance (background, device,
1737 encode_error_behavior_flag (ERROR_ME));
1739 if (COLOR_INSTANCEP (background))
1740 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
1742 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
1743 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
1745 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1746 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1753 COLORREF fg = black;
1754 COLORREF bg = white;
1756 if (NILP (foreground))
1757 foreground = pointer_fg;
1758 if (NILP (background))
1759 background = pointer_bg;
1761 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
1762 find_keyword_in_vector (instantiator, Q_hotspot_x);
1763 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
1764 find_keyword_in_vector (instantiator, Q_hotspot_y);
1765 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
1766 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
1767 if (COLOR_INSTANCEP (foreground))
1768 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
1769 if (COLOR_INSTANCEP (background))
1770 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
1772 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1773 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1775 mswindows_initialize_image_instance_icon (ii, TRUE);
1785 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
1786 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1787 int dest_mask, int width, int height,
1788 /* Note that data is in ext-format! */
1791 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
1792 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
1793 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1794 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME
1795 (XDEVICE (IMAGE_INSTANCE_DEVICE (ii))));
1796 HDC hdc = FRAME_MSWINDOWS_CDC (f);
1798 CONST char *gcc_may_you_rot_in_hell;
1800 if (!NILP (mask_data))
1802 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))),
1803 gcc_may_you_rot_in_hell);
1805 xbm_create_bitmap_from_data ( hdc,
1807 gcc_may_you_rot_in_hell,
1808 XINT (XCAR (mask_data)),
1809 XINT (XCAR (XCDR (mask_data))), FALSE,
1811 PALETTERGB (255,255,255));
1814 init_image_instance_from_xbm_inline (ii, width, height, bits,
1815 instantiator, pointer_fg, pointer_bg,
1816 dest_mask, mask, mask_file);
1819 /* Instantiate method for XBM's. */
1822 mswindows_xbm_instantiate (Lisp_Object image_instance,
1823 Lisp_Object instantiator,
1824 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1825 int dest_mask, Lisp_Object domain)
1827 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1828 CONST char *gcc_go_home;
1830 assert (!NILP (data));
1832 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (data))),
1835 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
1836 pointer_bg, dest_mask, XINT (XCAR (data)),
1837 XINT (XCAR (XCDR (data))), gcc_go_home);
1841 /**********************************************************************
1843 **********************************************************************/
1845 /* This is about to get redefined! */
1848 /* We have to define SYSV32 so that compface.h includes string.h
1849 instead of strings.h. */
1854 #include <compface.h>
1858 /* JMP_BUF cannot be used here because if it doesn't get defined
1859 to jmp_buf we end up with a conflicting type error with the
1860 definition in compface.h */
1861 extern jmp_buf comp_env;
1865 mswindows_xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1866 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1867 int dest_mask, Lisp_Object domain)
1869 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1871 char *p, *bits, *bp;
1872 CONST char * volatile emsg = 0;
1873 CONST char * volatile dstring;
1875 assert (!NILP (data));
1877 GET_C_STRING_BINARY_DATA_ALLOCA (data, dstring);
1879 if ((p = strchr (dstring, ':')))
1884 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
1885 if (!(stattis = setjmp (comp_env)))
1887 UnCompAll ((char *) dstring);
1894 emsg = "uncompface: internal error";
1897 emsg = "uncompface: insufficient or invalid data";
1900 emsg = "uncompface: excess data ignored";
1905 signal_simple_error_2 (emsg, data, Qimage);
1907 bp = bits = (char *) alloca (PIXELS / 8);
1909 /* the compface library exports char F[], which uses a single byte per
1910 pixel to represent a 48x48 bitmap. Yuck. */
1911 for (i = 0, p = F; i < (PIXELS / 8); ++i)
1914 /* reverse the bit order of each byte... */
1915 for (b = n = 0; b < 8; ++b)
1922 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
1923 pointer_bg, dest_mask, 48, 48, bits);
1925 #endif /* HAVE_XFACE */
1928 /************************************************************************/
1929 /* image instance methods */
1930 /************************************************************************/
1933 mswindows_print_image_instance (struct Lisp_Image_Instance *p,
1934 Lisp_Object printcharfun,
1939 switch (IMAGE_INSTANCE_TYPE (p))
1941 case IMAGE_MONO_PIXMAP:
1942 case IMAGE_COLOR_PIXMAP:
1944 sprintf (buf, " (0x%lx",
1945 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
1946 write_c_string (buf, printcharfun);
1947 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
1949 sprintf (buf, "/0x%lx",
1950 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
1951 write_c_string (buf, printcharfun);
1953 write_c_string (")", printcharfun);
1962 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
1964 if (DEVICE_LIVE_P (XDEVICE (p->device)))
1966 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET
1968 IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
1970 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
1971 DestroyWindow (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p));
1972 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0;
1976 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
1977 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
1978 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
1979 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
1980 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
1981 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
1982 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
1983 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
1984 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
1995 /************************************************************************/
1996 /* subwindow and widget support */
1997 /************************************************************************/
1999 /* unmap the image if it is a widget. This is used by redisplay via
2000 redisplay_unmap_subwindows */
2002 mswindows_unmap_subwindow (struct Lisp_Image_Instance *p)
2004 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
2006 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2009 SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE
2010 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
2014 /* map the subwindow. This is used by redisplay via
2015 redisplay_output_subwindow */
2017 mswindows_map_subwindow (struct Lisp_Image_Instance *p, int x, int y)
2019 /* ShowWindow (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), SW_SHOW);*/
2020 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2023 SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOSIZE
2024 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
2027 /* when you click on a widget you may activate another widget this
2028 needs to be checked and all appropriate widgets updated */
2030 mswindows_update_subwindow (struct Lisp_Image_Instance *p)
2032 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET)
2034 /* buttons checked or otherwise */
2035 if ( EQ (IMAGE_INSTANCE_WIDGET_TYPE (p), Qbutton))
2037 if (gui_item_selected_p (&IMAGE_INSTANCE_WIDGET_ITEM (p)))
2038 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2039 BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
2041 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2042 BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
2047 /* register widgets into our hastable so that we can cope with the
2048 callbacks. The hashtable is weak so deregistration is handled
2051 mswindows_register_widget_instance (Lisp_Object instance, Lisp_Object domain)
2053 Lisp_Object frame = FW_FRAME (domain);
2054 struct frame* f = XFRAME (frame);
2055 int id = gui_item_hash (FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f),
2056 &XIMAGE_INSTANCE_WIDGET_ITEM (instance),
2058 Fputhash (make_int (id),
2059 XIMAGE_INSTANCE_WIDGET_CALLBACK (instance),
2060 FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f));
2065 mswindows_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2066 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2067 int dest_mask, Lisp_Object domain)
2069 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2070 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
2071 struct device* d = XDEVICE (device);
2072 Lisp_Object frame = FW_FRAME (domain);
2075 if (!DEVICE_MSWINDOWS_P (d))
2076 signal_simple_error ("Not an mswindows device", device);
2078 /* have to set the type this late in case there is no device
2079 instantiation for a widget */
2080 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
2082 wnd = CreateWindow( "STATIC",
2085 0, /* starting x position */
2086 0, /* starting y position */
2087 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2088 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2089 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), /* parent window */
2092 GetWindowLong (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2096 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2097 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
2101 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
2102 struct Lisp_Image_Instance *p2, int depth)
2104 switch (IMAGE_INSTANCE_TYPE (p1))
2106 case IMAGE_MONO_PIXMAP:
2107 case IMAGE_COLOR_PIXMAP:
2109 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
2110 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
2121 static unsigned long
2122 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
2124 switch (IMAGE_INSTANCE_TYPE (p))
2126 case IMAGE_MONO_PIXMAP:
2127 case IMAGE_COLOR_PIXMAP:
2129 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
2136 /* Set all the slots in an image instance structure to reasonable
2137 default values. This is used somewhere within an instantiate
2138 method. It is assumed that the device slot within the image
2139 instance is already set -- this is the case when instantiate
2140 methods are called. */
2143 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
2144 enum image_instance_type type)
2146 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
2147 IMAGE_INSTANCE_TYPE (ii) = type;
2148 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
2149 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
2150 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
2151 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
2152 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
2153 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
2157 /************************************************************************/
2159 /************************************************************************/
2162 mswindows_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2163 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2164 int dest_mask, Lisp_Object domain,
2165 CONST char* class, int flags, int exflags)
2167 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2169 struct Lisp_Image_Instance *groupii = 0;
2170 Lisp_Object group = find_keyword_in_vector (instantiator, Q_group);
2172 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), style;
2173 struct device* d = XDEVICE (device);
2174 Lisp_Object frame = FW_FRAME (domain);
2178 struct gui_item* pgui = &IMAGE_INSTANCE_WIDGET_ITEM (ii);
2180 if (!DEVICE_MSWINDOWS_P (d))
2181 signal_simple_error ("Not an mswindows device", device);
2183 /* if the user specified another glyph as a group pick up the
2184 instance in our domain. */
2187 if (SYMBOLP (group))
2188 group = XSYMBOL (group)->value;
2189 group = glyph_image_instance (group, domain, ERROR_ME, 1);
2190 groupii = XIMAGE_INSTANCE (group);
2193 if (!gui_item_active_p (pgui))
2194 flags |= WS_DISABLED;
2196 style = pgui->style;
2198 if (!NILP (pgui->callback))
2200 id = mswindows_register_widget_instance (image_instance, domain);
2202 /* have to set the type this late in case there is no device
2203 instantiation for a widget */
2204 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
2205 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
2206 GET_C_STRING_OS_DATA_ALLOCA (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm);
2208 wnd = CreateWindowEx(
2209 exflags /* | WS_EX_NOPARENTNOTIFY*/,
2213 0, /* starting x position */
2214 0, /* starting y position */
2215 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2216 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2218 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2219 (HMENU)id, /* No menu */
2221 GetWindowLong (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2225 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
2226 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2227 /* set the widget font from the widget face */
2228 SendMessage (wnd, WM_SETFONT,
2229 (WPARAM)FONT_INSTANCE_MSWINDOWS_HFONT
2230 (XFONT_INSTANCE (widget_face_font_info
2232 IMAGE_INSTANCE_WIDGET_FACE (ii),
2234 MAKELPARAM (TRUE, 0));
2237 /* Instantiate a button widget. Unfortunately instantiated widgets are
2238 particular to a frame since they need to have a parent. It's not
2239 like images where you just select the image into the context you
2240 want to display it in and BitBlt it. So images instances can have a
2241 many-to-one relationship with things you see, whereas widgets can
2242 only be one-to-one (i.e. per frame) */
2244 mswindows_button_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2245 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2246 int dest_mask, Lisp_Object domain)
2248 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2250 int flags = BS_NOTIFY;
2252 struct gui_item* pgui = &IMAGE_INSTANCE_WIDGET_ITEM (ii);
2253 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image);
2255 if (!gui_item_active_p (pgui))
2256 flags |= WS_DISABLED;
2260 if (!IMAGE_INSTANCEP (glyph))
2261 glyph = glyph_image_instance (glyph, domain, ERROR_ME, 1);
2263 if (IMAGE_INSTANCEP (glyph))
2264 flags |= XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2265 BS_BITMAP : BS_ICON;
2268 style = pgui->style;
2270 if (EQ (style, Qradio))
2272 flags |= BS_RADIOBUTTON;
2274 else if (EQ (style, Qtoggle))
2276 flags |= BS_AUTOCHECKBOX;
2279 flags |= BS_DEFPUSHBUTTON;
2281 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2282 pointer_bg, dest_mask, domain, "BUTTON", flags,
2283 WS_EX_CONTROLPARENT);
2285 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2286 /* set the checked state */
2287 if (gui_item_selected_p (pgui))
2288 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
2290 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
2291 /* add the image if one was given */
2292 if (!NILP (glyph) && IMAGE_INSTANCEP (glyph))
2294 SendMessage (wnd, BM_SETIMAGE,
2295 (WPARAM) (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2296 IMAGE_BITMAP : IMAGE_ICON),
2297 (LPARAM) (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2298 XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) :
2299 XIMAGE_INSTANCE_MSWINDOWS_ICON (glyph)));
2303 /* instantiate an edit control */
2305 mswindows_edit_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2306 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2307 int dest_mask, Lisp_Object domain)
2309 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2310 pointer_bg, dest_mask, domain, "EDIT",
2311 ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP
2313 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2316 /* instantiate an edit control */
2318 mswindows_progress_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2319 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2320 int dest_mask, Lisp_Object domain)
2323 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2324 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2325 pointer_bg, dest_mask, domain, PROGRESS_CLASS,
2326 WS_TABSTOP | WS_BORDER | PBS_SMOOTH,
2327 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2328 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2329 /* set the colors */
2330 #ifdef PBS_SETBKCOLOR
2331 SendMessage (wnd, PBS_SETBKCOLOR, 0,
2332 (LPARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR
2335 (XIMAGE_INSTANCE_WIDGET_FACE (ii),
2336 XIMAGE_INSTANCE_SUBWINDOW_FRAME (ii))))));
2338 #ifdef PBS_SETBARCOLOR
2339 SendMessage (wnd, PBS_SETBARCOLOR, 0,
2340 (L:PARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR
2343 (XIMAGE_INSTANCE_WIDGET_FACE (ii),
2344 XIMAGE_INSTANCE_SUBWINDOW_FRAME (ii))))));
2348 /* instantiate a static control possible for putting other things in */
2350 mswindows_label_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2351 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2352 int dest_mask, Lisp_Object domain)
2354 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2355 pointer_bg, dest_mask, domain, "STATIC",
2356 0, WS_EX_STATICEDGE);
2360 /* instantiate a static control possible for putting other things in */
2362 mswindows_group_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2363 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2364 int dest_mask, Lisp_Object domain)
2366 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2367 pointer_bg, dest_mask, domain, "BUTTON",
2368 WS_GROUP | BS_GROUPBOX | WS_BORDER,
2373 /* instantiate a scrollbar control */
2375 mswindows_scrollbar_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2376 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2377 int dest_mask, Lisp_Object domain)
2379 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2380 pointer_bg, dest_mask, domain, "SCROLLBAR",
2385 /* instantiate a combo control */
2387 mswindows_combo_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2388 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2389 int dest_mask, Lisp_Object domain)
2391 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2395 /* Maybe ought to generalise this more but it may be very windows
2396 specific. In windows the window height of a combo box is the
2397 height when the combo box is open. Thus we need to set the height
2398 before creating the window and then reset it to a single line
2399 after the window is created so that redisplay does the right
2401 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2402 pointer_bg, dest_mask, domain, "COMBOBOX",
2403 WS_BORDER | WS_TABSTOP | CBS_DROPDOWN
2405 | CBS_HASSTRINGS | WS_VSCROLL,
2406 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2407 /* reset the height */
2408 widget_text_to_pixel_conversion (domain,
2409 IMAGE_INSTANCE_WIDGET_FACE (ii), 1, 0,
2410 &IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii), 0);
2411 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2412 /* add items to the combo box */
2413 SendMessage (wnd, CB_RESETCONTENT, 0, 0);
2414 LIST_LOOP (rest, Fplist_get (IMAGE_INSTANCE_WIDGET_PROPS (ii), Q_items, Qnil))
2417 GET_C_STRING_OS_DATA_ALLOCA (XCAR (rest), lparam);
2418 if (SendMessage (wnd, CB_ADDSTRING, 0, (LPARAM)lparam) == CB_ERR)
2419 signal_simple_error ("error adding combo entries", instantiator);
2423 /* get properties of a control */
2425 mswindows_widget_property (Lisp_Object image_instance, Lisp_Object prop)
2427 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2428 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2429 /* get the text from a control */
2430 if (EQ (prop, Q_text))
2432 Extcount len = SendMessage (wnd, WM_GETTEXTLENGTH, 0, 0);
2433 Extbyte* buf =alloca (len+1);
2435 SendMessage (wnd, WM_GETTEXT, (WPARAM)len+1, (LPARAM) buf);
2436 return build_ext_string (buf, FORMAT_OS);
2441 /* get properties of a button */
2443 mswindows_button_property (Lisp_Object image_instance, Lisp_Object prop)
2445 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2446 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2447 /* check the state of a button */
2448 if (EQ (prop, Q_selected))
2450 if (SendMessage (wnd, BM_GETSTATE, 0, 0) & BST_CHECKED)
2458 /* get properties of a combo box */
2460 mswindows_combo_property (Lisp_Object image_instance, Lisp_Object prop)
2462 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2463 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2464 /* get the text from a control */
2465 if (EQ (prop, Q_text))
2467 long item = SendMessage (wnd, CB_GETCURSEL, 0, 0);
2468 Extcount len = SendMessage (wnd, CB_GETLBTEXTLEN, (WPARAM)item, 0);
2469 Extbyte* buf = alloca (len+1);
2470 SendMessage (wnd, CB_GETLBTEXT, (WPARAM)item, (LPARAM)buf);
2471 return build_ext_string (buf, FORMAT_OS);
2476 /* set the properties of a control */
2478 mswindows_widget_set_property (Lisp_Object image_instance, Lisp_Object prop,
2481 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2483 if (EQ (prop, Q_text))
2487 GET_C_STRING_OS_DATA_ALLOCA (val, lparam);
2488 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2489 WM_SETTEXT, 0, (LPARAM)lparam);
2495 /* set the properties of a progres guage */
2497 mswindows_progress_set_property (Lisp_Object image_instance, Lisp_Object prop,
2500 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2502 if (EQ (prop, Q_percent))
2505 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2506 PBM_SETPOS, (WPARAM)XINT (val), 0);
2513 /************************************************************************/
2514 /* initialization */
2515 /************************************************************************/
2518 syms_of_glyphs_mswindows (void)
2520 defkeyword (&Q_resource_id, ":resource-id");
2521 defkeyword (&Q_resource_type, ":resource-type");
2525 console_type_create_glyphs_mswindows (void)
2529 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
2530 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
2531 CONSOLE_HAS_METHOD (mswindows, unmap_subwindow);
2532 CONSOLE_HAS_METHOD (mswindows, map_subwindow);
2533 CONSOLE_HAS_METHOD (mswindows, update_subwindow);
2534 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
2535 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
2536 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
2537 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
2541 image_instantiator_format_create_glyphs_mswindows (void)
2543 /* image-instantiator types */
2545 INITIALIZE_DEVICE_IIFORMAT (mswindows, xpm);
2546 IIFORMAT_HAS_DEVMETHOD (mswindows, xpm, instantiate);
2548 INITIALIZE_DEVICE_IIFORMAT (mswindows, xbm);
2549 IIFORMAT_HAS_DEVMETHOD (mswindows, xbm, instantiate);
2551 INITIALIZE_DEVICE_IIFORMAT (mswindows, xface);
2552 IIFORMAT_HAS_DEVMETHOD (mswindows, xface, instantiate);
2554 INITIALIZE_DEVICE_IIFORMAT (mswindows, button);
2555 IIFORMAT_HAS_DEVMETHOD (mswindows, button, property);
2556 IIFORMAT_HAS_DEVMETHOD (mswindows, button, instantiate);
2558 INITIALIZE_DEVICE_IIFORMAT (mswindows, edit);
2559 IIFORMAT_HAS_DEVMETHOD (mswindows, edit, instantiate);
2561 INITIALIZE_DEVICE_IIFORMAT (mswindows, subwindow);
2562 IIFORMAT_HAS_DEVMETHOD (mswindows, subwindow, instantiate);
2564 INITIALIZE_DEVICE_IIFORMAT (mswindows, widget);
2565 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, property);
2566 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, set_property);
2568 INITIALIZE_DEVICE_IIFORMAT (mswindows, group);
2569 IIFORMAT_HAS_DEVMETHOD (mswindows, group, instantiate);
2571 INITIALIZE_DEVICE_IIFORMAT (mswindows, label);
2572 IIFORMAT_HAS_DEVMETHOD (mswindows, label, instantiate);
2574 INITIALIZE_DEVICE_IIFORMAT (mswindows, combo);
2575 IIFORMAT_HAS_DEVMETHOD (mswindows, combo, property);
2576 IIFORMAT_HAS_DEVMETHOD (mswindows, combo, instantiate);
2578 INITIALIZE_DEVICE_IIFORMAT (mswindows, scrollbar);
2579 IIFORMAT_HAS_DEVMETHOD (mswindows, scrollbar, instantiate);
2581 INITIALIZE_DEVICE_IIFORMAT (mswindows, progress);
2582 IIFORMAT_HAS_DEVMETHOD (mswindows, progress, set_property);
2583 IIFORMAT_HAS_DEVMETHOD (mswindows, progress, instantiate);
2585 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
2587 IIFORMAT_HAS_METHOD (bmp, validate);
2588 IIFORMAT_HAS_METHOD (bmp, normalize);
2589 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
2590 IIFORMAT_HAS_METHOD (bmp, instantiate);
2592 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
2593 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
2595 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (mswindows_resource,
2596 "mswindows-resource");
2598 IIFORMAT_HAS_METHOD (mswindows_resource, validate);
2599 IIFORMAT_HAS_METHOD (mswindows_resource, normalize);
2600 IIFORMAT_HAS_METHOD (mswindows_resource, possible_dest_types);
2601 IIFORMAT_HAS_METHOD (mswindows_resource, instantiate);
2603 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_type,
2604 check_valid_resource_symbol);
2605 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_id, check_valid_resource_id);
2606 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_file, check_valid_string);
2610 vars_of_glyphs_mswindows (void)
2613 Fprovide (Qmswindows_resource);
2614 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
2615 A list of the directories in which mswindows bitmap files may be found.
2616 This is used by the `make-image-instance' function.
2618 Vmswindows_bitmap_file_path = Qnil;
2623 Fprovide (Qscrollbar);
2625 Fprovide (Qprogress);
2629 complex_vars_of_glyphs_mswindows (void)