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, Qnil, &found, R_OK) < 0)
252 Lisp_Object temp = list1 (Vdata_directory);
256 locate_file (temp, name, Qnil, &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 colortbl[j].name = xstrdup (colortbl[j].name); /* mustn't lose this when we return */
690 free_cons (XCONS (cons));
692 results = XCDR (results);
693 free_cons (XCONS (cons));
698 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer,
699 unsigned char** data,
700 int* width, int* height,
701 int* x_hot, int* y_hot,
703 struct color_symbol* color_symbols,
708 int result, i, j, transp_idx, maskbpline;
711 COLORREF color; /* the american spelling virus hits again .. */
716 xpminfo.valuemask=XpmHotspot;
719 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
728 signal_simple_error ("Invalid XPM data", image);
732 signal_double_file_error ("Parsing pixmap data",
733 "out of memory", image);
737 signal_double_file_error_2 ("Parsing pixmap data",
738 "unknown error code",
739 make_int (result), image);
743 *width = xpmimage.width;
744 *height = xpmimage.height;
745 maskbpline = BPLINE (((~7UL & (unsigned long)(*width + 7)) / 8));
747 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
751 XpmFreeXpmImage (&xpmimage);
752 XpmFreeXpmInfo (&xpminfo);
756 /* build a color table to speed things up */
757 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
761 XpmFreeXpmImage (&xpmimage);
762 XpmFreeXpmInfo (&xpminfo);
766 for (i=0; i<xpmimage.ncolors; i++)
769 /* pick up symbolic colors in preference */
770 if (xpmimage.colorTable[i].symbolic)
772 if (!strcasecmp (xpmimage.colorTable[i].symbolic,"BgColor")
774 !strcasecmp (xpmimage.colorTable[i].symbolic,"None"))
777 colortbl[i]=transparent_color;
779 goto label_found_color;
781 else if (color_symbols)
783 for (j = 0; j<nsymbols; j++)
785 if (!strcmp (xpmimage.colorTable[i].symbolic,
786 color_symbols[j].name ))
788 colortbl[i]=color_symbols[j].color;
789 goto label_found_color;
793 else if (xpmimage.colorTable[i].c_color == 0)
798 /* pick up transparencies */
799 if (!strcasecmp (xpmimage.colorTable[i].c_color,"None"))
802 colortbl[i]=transparent_color;
804 goto label_found_color;
806 /* finally pick up a normal color spec */
807 if (xpmimage.colorTable[i].c_color)
810 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
811 goto label_found_color;
817 XpmFreeXpmImage (&xpmimage);
818 XpmFreeXpmInfo (&xpminfo);
824 /* convert the image */
827 for (i = 0; i< *width * *height; i++)
829 color = colortbl[*sptr++];
831 /* split out the 0x02bbggrr colorref into an rgb triple */
832 *dptr++=GetRValue (color); /* red */
833 *dptr++=GetGValue (color); /* green */
834 *dptr++=GetBValue (color); /* blue */
837 *x_hot=xpminfo.x_hotspot;
838 *y_hot=xpminfo.y_hotspot;
840 XpmFreeXpmImage (&xpmimage);
841 XpmFreeXpmInfo (&xpminfo);
847 mswindows_xpm_instantiate (Lisp_Object image_instance,
848 Lisp_Object instantiator,
849 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
850 int dest_mask, Lisp_Object domain)
852 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
853 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
854 CONST Extbyte *bytes;
856 unsigned char *eimage;
857 int width, height, x_hot, y_hot;
858 BITMAPINFO* bmp_info;
859 unsigned char* bmp_data;
861 int nsymbols=0, transp;
862 struct color_symbol* color_symbols=NULL;
864 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
865 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
868 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
869 signal_simple_error ("Not an mswindows device", device);
871 assert (!NILP (data));
873 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
875 /* in case we have color symbols */
876 color_symbols = extract_xpm_color_names (device, domain,
877 color_symbol_alist, &nsymbols);
879 /* convert to an eimage to make processing easier */
880 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
881 &x_hot, &y_hot, &transp, color_symbols, nsymbols))
883 signal_simple_error ("XPM to EImage conversion failed",
891 xfree (color_symbols[nsymbols].name);
893 xfree(color_symbols);
896 /* build a bitmap from the eimage */
897 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
898 &bmp_bits, &bmp_data)))
900 signal_simple_error ("XPM to EImage conversion failed",
905 /* Now create the pixmap and set up the image instance */
906 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
907 bmp_data, bmp_bits, instantiator,
908 x_hot, y_hot, transp);
913 #endif /* HAVE_XPM */
915 /**********************************************************************
917 **********************************************************************/
920 bmp_validate (Lisp_Object instantiator)
922 file_or_data_must_be_present (instantiator);
926 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
928 return simple_image_type_normalize (inst, console_type, Qbmp);
932 bmp_possible_dest_types (void)
934 return IMAGE_COLOR_PIXMAP_MASK;
938 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
939 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
940 int dest_mask, Lisp_Object domain)
942 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
943 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
944 CONST Extbyte *bytes;
946 BITMAPFILEHEADER* bmp_file_header;
947 BITMAPINFO* bmp_info;
950 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
952 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
953 signal_simple_error ("Not an mswindows device", device);
955 assert (!NILP (data));
957 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
959 /* Then slurp the image into memory, decoding along the way.
960 The result is the image in a simple one-byte-per-pixel
963 bmp_file_header=(BITMAPFILEHEADER*)bytes;
964 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
965 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
966 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
968 /* Now create the pixmap and set up the image instance */
969 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
970 bmp_data, bmp_bits, instantiator,
975 /**********************************************************************
977 **********************************************************************/
980 mswindows_resource_validate (Lisp_Object instantiator)
982 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
984 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
986 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
987 signal_simple_error ("Must supply :file, :resource-id and :resource-type",
992 mswindows_resource_normalize (Lisp_Object inst, Lisp_Object console_type)
994 /* This function can call lisp */
995 Lisp_Object file = Qnil;
996 struct gcpro gcpro1, gcpro2;
997 Lisp_Object alist = Qnil;
999 GCPRO2 (file, alist);
1001 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
1004 if (CONSP (file)) /* failure locating filename */
1005 signal_double_file_error ("Opening pixmap file",
1006 "no such file or directory",
1009 if (NILP (file)) /* no conversion necessary */
1010 RETURN_UNGCPRO (inst);
1012 alist = tagged_vector_to_alist (inst);
1015 alist = remassq_no_quit (Q_file, alist);
1016 alist = Fcons (Fcons (Q_file, file), alist);
1020 Lisp_Object result = alist_to_tagged_vector (Qmswindows_resource, alist);
1022 RETURN_UNGCPRO (result);
1027 mswindows_resource_possible_dest_types (void)
1029 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
1039 #define OCR_ICOCUR 32647
1040 #define OIC_SAMPLE 32512
1041 #define OIC_HAND 32513
1042 #define OIC_QUES 32514
1043 #define OIC_BANG 32515
1044 #define OIC_NOTE 32516
1045 #define OIC_WINLOGO 32517
1046 #define LR_SHARED 0x8000
1049 static CONST resource_t bitmap_table[] =
1052 { "close", OBM_CLOSE },
1053 { "uparrow", OBM_UPARROW },
1054 { "dnarrow", OBM_DNARROW },
1055 { "rgarrow", OBM_RGARROW },
1056 { "lfarrow", OBM_LFARROW },
1057 { "reduce", OBM_REDUCE },
1058 { "zoom", OBM_ZOOM },
1059 { "restore", OBM_RESTORE },
1060 { "reduced", OBM_REDUCED },
1061 { "zoomd", OBM_ZOOMD },
1062 { "restored", OBM_RESTORED },
1063 { "uparrowd", OBM_UPARROWD },
1064 { "dnarrowd", OBM_DNARROWD },
1065 { "rgarrowd", OBM_RGARROWD },
1066 { "lfarrowd", OBM_LFARROWD },
1067 { "mnarrow", OBM_MNARROW },
1068 { "combo", OBM_COMBO },
1069 { "uparrowi", OBM_UPARROWI },
1070 { "dnarrowi", OBM_DNARROWI },
1071 { "rgarrowi", OBM_RGARROWI },
1072 { "lfarrowi", OBM_LFARROWI },
1073 { "size", OBM_SIZE },
1074 { "btsize", OBM_BTSIZE },
1075 { "check", OBM_CHECK },
1076 { "checkboxes", OBM_CHECKBOXES },
1077 { "btncorners" , OBM_BTNCORNERS },
1081 static CONST resource_t cursor_table[] =
1084 { "normal", OCR_NORMAL },
1085 { "ibeam", OCR_IBEAM },
1086 { "wait", OCR_WAIT },
1087 { "cross", OCR_CROSS },
1089 /* { "icon", OCR_ICON }, */
1090 { "sizenwse", OCR_SIZENWSE },
1091 { "sizenesw", OCR_SIZENESW },
1092 { "sizewe", OCR_SIZEWE },
1093 { "sizens", OCR_SIZENS },
1094 { "sizeall", OCR_SIZEALL },
1095 /* { "icour", OCR_ICOCUR }, */
1100 static CONST resource_t icon_table[] =
1103 { "sample", OIC_SAMPLE },
1104 { "hand", OIC_HAND },
1105 { "ques", OIC_QUES },
1106 { "bang", OIC_BANG },
1107 { "note", OIC_NOTE },
1108 { "winlogo", OIC_WINLOGO },
1112 static int resource_name_to_resource (Lisp_Object name, int type)
1114 CONST resource_t* res = (type == IMAGE_CURSOR ? cursor_table
1115 : type == IMAGE_ICON ? icon_table
1122 else if (!STRINGP (name))
1124 signal_simple_error ("invalid resource identifier", name);
1129 GET_C_STRING_OS_DATA_ALLOCA (name, nm);
1130 if (!strcasecmp ((char*)res->name, nm))
1131 return res->resource_id;
1132 } while ((++res)->name);
1137 resource_symbol_to_type (Lisp_Object data)
1139 if (EQ (data, Qcursor))
1140 return IMAGE_CURSOR;
1141 else if (EQ (data, Qicon))
1143 else if (EQ (data, Qbitmap))
1144 return IMAGE_BITMAP;
1150 mswindows_resource_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1151 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1152 int dest_mask, Lisp_Object domain)
1154 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1155 unsigned int type = 0;
1156 HANDLE himage = NULL;
1158 HINSTANCE hinst = NULL;
1162 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1164 Lisp_Object file = find_keyword_in_vector (instantiator, Q_file);
1165 Lisp_Object resource_type = find_keyword_in_vector (instantiator,
1167 Lisp_Object resource_id = find_keyword_in_vector (instantiator,
1172 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
1173 signal_simple_error ("Not an mswindows device", device);
1175 type = resource_symbol_to_type (resource_type);
1177 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_CURSOR)
1178 iitype = IMAGE_POINTER;
1179 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1180 iitype = IMAGE_COLOR_PIXMAP;
1182 incompatible_image_types (instantiator, dest_mask,
1183 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
1185 /* mess with the keyword info we were provided with */
1189 GET_C_STRING_FILENAME_DATA_ALLOCA (file, f);
1191 CYGWIN_WIN32_PATH (f, fname);
1196 if (NILP (resource_id))
1197 resid = (LPCTSTR)fname;
1200 hinst = LoadLibraryEx (fname, NULL,
1201 LOAD_LIBRARY_AS_DATAFILE);
1202 resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1206 GET_C_STRING_OS_DATA_ALLOCA (resource_id, resid);
1209 else if (!(resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1211 signal_simple_error ("Invalid resource identifier", resource_id);
1213 /* load the image */
1214 if (!(himage = LoadImage (hinst, resid, type, 0, 0,
1215 LR_CREATEDIBSECTION | LR_DEFAULTSIZE |
1217 (!NILP (file) ? LR_LOADFROMFILE : 0))))
1219 signal_simple_error ("Cannot load image", instantiator);
1223 FreeLibrary (hinst);
1225 mswindows_initialize_dibitmap_image_instance (ii, iitype);
1227 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = file;
1228 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) =
1229 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CXCURSOR : SM_CXICON);
1230 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) =
1231 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CYCURSOR : SM_CYICON);
1232 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
1234 /* hey, we've got an icon type thing so we can reverse engineer the
1236 if (type != IMAGE_BITMAP)
1238 GetIconInfo (himage, &iconinfo);
1239 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = iconinfo.hbmColor;
1240 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = iconinfo.hbmMask;
1241 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), iconinfo.xHotspot);
1242 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), iconinfo.yHotspot);
1243 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = himage;
1247 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = NULL;
1248 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = himage;
1249 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
1250 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
1251 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
1256 check_valid_resource_symbol (Lisp_Object data)
1258 CHECK_SYMBOL (data);
1259 if (!resource_symbol_to_type (data))
1260 signal_simple_error ("invalid resource type", data);
1264 check_valid_resource_id (Lisp_Object data)
1266 if (!resource_name_to_resource (data, IMAGE_CURSOR)
1268 !resource_name_to_resource (data, IMAGE_ICON)
1270 !resource_name_to_resource (data, IMAGE_BITMAP))
1271 signal_simple_error ("invalid resource identifier", data);
1275 check_valid_string_or_int (Lisp_Object data)
1278 CHECK_STRING (data);
1283 /**********************************************************************
1285 **********************************************************************/
1286 #ifndef HAVE_X_WINDOWS
1287 /* $XConsortium: RdBitF.c,v 1.10 94/04/17 20:16:13 kaleb Exp $ */
1291 Copyright (c) 1988 X Consortium
1293 Permission is hereby granted, free of charge, to any person obtaining a copy
1294 of this software and associated documentation files (the "Software"), to deal
1295 in the Software without restriction, including without limitation the rights
1296 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1297 copies of the Software, and to permit persons to whom the Software is
1298 furnished to do so, subject to the following conditions:
1300 The above copyright notice and this permission notice shall be included in
1301 all copies or substantial portions of the Software.
1303 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1304 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1305 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1306 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1307 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1308 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1310 Except as contained in this notice, the name of the X Consortium shall not be
1311 used in advertising or otherwise to promote the sale, use or other dealings
1312 in this Software without prior written authorization from the X Consortium.
1317 * This file contains miscellaneous utility routines and is not part of the
1320 * Public entry points:
1322 * XmuReadBitmapData read data from FILE descriptor
1323 * XmuReadBitmapDataFromFile read X10 or X11 format bitmap files
1326 * Note that this file and ../X/XRdBitF.c look very similar.... Keep them
1327 * that way (but don't use common source code so that people can have one
1328 * without the other).
1333 * Based on an optimized version provided by Jim Becker, August 5, 1988.
1335 #ifndef BitmapSuccess
1336 #define BitmapSuccess 0
1337 #define BitmapOpenFailed 1
1338 #define BitmapFileInvalid 2
1339 #define BitmapNoMemory 3
1341 #define MAX_SIZE 255
1343 /* shared data for the image read/parse logic */
1344 static short hexTable[256]; /* conversion value */
1345 static int initialized = FALSE; /* easier to fill in at run time */
1348 * Table index for the hex values. Initialized once, first time.
1349 * Used for translation value or delimiter significance lookup.
1351 static void initHexTable()
1354 * We build the table at run time for several reasons:
1356 * 1. portable to non-ASCII machines.
1357 * 2. still reentrant since we set the init flag after setting table.
1358 * 3. easier to extend.
1359 * 4. less prone to bugs.
1361 hexTable['0'] = 0; hexTable['1'] = 1;
1362 hexTable['2'] = 2; hexTable['3'] = 3;
1363 hexTable['4'] = 4; hexTable['5'] = 5;
1364 hexTable['6'] = 6; hexTable['7'] = 7;
1365 hexTable['8'] = 8; hexTable['9'] = 9;
1366 hexTable['A'] = 10; hexTable['B'] = 11;
1367 hexTable['C'] = 12; hexTable['D'] = 13;
1368 hexTable['E'] = 14; hexTable['F'] = 15;
1369 hexTable['a'] = 10; hexTable['b'] = 11;
1370 hexTable['c'] = 12; hexTable['d'] = 13;
1371 hexTable['e'] = 14; hexTable['f'] = 15;
1373 /* delimiters of significance are flagged w/ negative value */
1374 hexTable[' '] = -1; hexTable[','] = -1;
1375 hexTable['}'] = -1; hexTable['\n'] = -1;
1376 hexTable['\t'] = -1;
1382 * read next hex value in the input stream, return -1 if EOF
1384 static int NextInt ( FILE *fstream )
1391 /* loop, accumulate hex value until find delimiter */
1392 /* skip any initial delimiters found in read stream */
1400 /* trim high bits, check type and accumulate */
1402 if (isascii(ch) && isxdigit(ch)) {
1403 value = (value << 4) + hexTable[ch];
1405 } else if ((hexTable[ch]) < 0 && gotone)
1414 * The data returned by the following routine is always in left-most byte
1415 * first and left-most bit first. If it doesn't return BitmapSuccess then
1416 * its arguments won't have been touched. This routine should look as much
1417 * like the Xlib routine XReadBitmapfile as possible.
1419 int read_bitmap_data (fstream, width, height, datap, x_hot, y_hot)
1420 FILE *fstream; /* handle on file */
1421 unsigned int *width, *height; /* RETURNED */
1422 unsigned char **datap; /* RETURNED */
1423 int *x_hot, *y_hot; /* RETURNED */
1425 unsigned char *data = NULL; /* working variable */
1426 char line[MAX_SIZE]; /* input line from file */
1427 int size; /* number of bytes of data */
1428 char name_and_type[MAX_SIZE]; /* an input line */
1429 char *type; /* for parsing */
1430 int value; /* from an input line */
1431 int version10p; /* boolean, old format */
1432 int padding; /* to handle alignment */
1433 int bytes_per_line; /* per scanline of data */
1434 unsigned int ww = 0; /* width */
1435 unsigned int hh = 0; /* height */
1436 int hx = -1; /* x hotspot */
1437 int hy = -1; /* y hotspot */
1439 #define Xmalloc(size) malloc(size)
1441 /* first time initialization */
1442 if (initialized == FALSE) initHexTable();
1444 /* error cleanup and return macro */
1445 #define RETURN(code) { if (data) free (data); return code; }
1447 while (fgets(line, MAX_SIZE, fstream)) {
1448 if (strlen(line) == MAX_SIZE-1) {
1449 RETURN (BitmapFileInvalid);
1451 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
1452 if (!(type = strrchr(name_and_type, '_')))
1453 type = name_and_type;
1457 if (!strcmp("width", type))
1458 ww = (unsigned int) value;
1459 if (!strcmp("height", type))
1460 hh = (unsigned int) value;
1461 if (!strcmp("hot", type)) {
1462 if (type-- == name_and_type || type-- == name_and_type)
1464 if (!strcmp("x_hot", type))
1466 if (!strcmp("y_hot", type))
1472 if (sscanf(line, "static short %s = {", name_and_type) == 1)
1474 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
1476 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
1481 if (!(type = strrchr(name_and_type, '_')))
1482 type = name_and_type;
1486 if (strcmp("bits[]", type))
1490 RETURN (BitmapFileInvalid);
1492 if ((ww % 16) && ((ww % 16) < 9) && version10p)
1497 bytes_per_line = (ww+7)/8 + padding;
1499 size = bytes_per_line * hh;
1500 data = (unsigned char *) Xmalloc ((unsigned int) size);
1502 RETURN (BitmapNoMemory);
1508 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
1509 if ((value = NextInt(fstream)) < 0)
1510 RETURN (BitmapFileInvalid);
1512 if (!padding || ((bytes+2) % bytes_per_line))
1513 *(ptr++) = value >> 8;
1519 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
1520 if ((value = NextInt(fstream)) < 0)
1521 RETURN (BitmapFileInvalid);
1529 RETURN (BitmapFileInvalid);
1536 if (x_hot) *x_hot = hx;
1537 if (y_hot) *y_hot = hy;
1539 RETURN (BitmapSuccess);
1543 int read_bitmap_data_from_file (CONST char *filename, unsigned int *width,
1544 unsigned int *height, unsigned char **datap,
1545 int *x_hot, int *y_hot)
1550 if ((fstream = fopen (filename, "r")) == NULL) {
1551 return BitmapOpenFailed;
1553 status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot);
1557 #endif /* HAVE_X_WINDOWS */
1559 /* this table flips four bits around. */
1560 static int flip_table[] =
1562 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
1565 /* the bitmap data comes in the following format: Widths are padded to
1566 a multiple of 8. Scan lines are stored in increasing byte order
1567 from left to right, little-endian within a byte. 0 = white, 1 =
1568 black. It must be converted to the following format: Widths are
1569 padded to a multiple of 16. Scan lines are stored in increasing
1570 byte order from left to right, big-endian within a byte. 0 =
1571 black, 1 = white. */
1573 xbm_create_bitmap_from_data (HDC hdc, char *data,
1574 unsigned int width, unsigned int height,
1575 int mask, COLORREF fg, COLORREF bg)
1577 int old_width = (width + 7)/8;
1578 int new_width = BPLINE (2*((width + 15)/16));
1579 unsigned char *offset;
1581 unsigned char *new_data, *new_offset;
1583 BITMAPINFO* bmp_info =
1584 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
1590 new_data = (unsigned char *) xmalloc_and_zero (height * new_width);
1598 for (i=0; i<height; i++)
1600 offset = data + i*old_width;
1601 new_offset = new_data + i*new_width;
1603 for (j=0; j<old_width; j++)
1605 int byte = offset[j];
1606 new_offset[j] = ~ (unsigned char)
1607 ((flip_table[byte & 0xf] << 4) + flip_table[byte >> 4]);
1611 /* if we want a mask invert the bits */
1614 new_offset = &new_data[height * new_width];
1615 while (new_offset-- != new_data)
1617 *new_offset ^= 0xff;
1621 bmp_info->bmiHeader.biWidth=width;
1622 bmp_info->bmiHeader.biHeight=-(LONG)height;
1623 bmp_info->bmiHeader.biPlanes=1;
1624 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
1625 bmp_info->bmiHeader.biBitCount=1;
1626 bmp_info->bmiHeader.biCompression=BI_RGB;
1627 bmp_info->bmiHeader.biClrUsed = 2;
1628 bmp_info->bmiHeader.biClrImportant = 2;
1629 bmp_info->bmiHeader.biSizeImage = height * new_width;
1630 bmp_info->bmiColors[0].rgbRed = GetRValue (fg);
1631 bmp_info->bmiColors[0].rgbGreen = GetGValue (fg);
1632 bmp_info->bmiColors[0].rgbBlue = GetBValue (fg);
1633 bmp_info->bmiColors[0].rgbReserved = 0;
1634 bmp_info->bmiColors[1].rgbRed = GetRValue (bg);
1635 bmp_info->bmiColors[1].rgbGreen = GetGValue (bg);
1636 bmp_info->bmiColors[1].rgbBlue = GetBValue (bg);
1637 bmp_info->bmiColors[1].rgbReserved = 0;
1639 bitmap = CreateDIBSection (hdc,
1647 if (!bitmap || !bmp_buf)
1653 /* copy in the actual bitmap */
1654 memcpy (bmp_buf, new_data, height * new_width);
1660 /* Given inline data for a mono pixmap, initialize the given
1661 image instance accordingly. */
1664 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
1665 int width, int height,
1666 /* Note that data is in ext-format! */
1668 Lisp_Object instantiator,
1669 Lisp_Object pointer_fg,
1670 Lisp_Object pointer_bg,
1673 Lisp_Object mask_filename)
1675 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1676 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (device)));
1677 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
1678 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
1679 enum image_instance_type type;
1680 COLORREF black = PALETTERGB (0,0,0);
1681 COLORREF white = PALETTERGB (255,255,255);
1683 HDC hdc = FRAME_MSWINDOWS_CDC (f);
1685 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
1686 signal_simple_error ("Not an MS-Windows device", device);
1688 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
1689 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
1691 if (!NILP (foreground) || !NILP (background))
1692 type = IMAGE_COLOR_PIXMAP;
1694 type = IMAGE_MONO_PIXMAP;
1696 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
1697 type = IMAGE_MONO_PIXMAP;
1698 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1699 type = IMAGE_COLOR_PIXMAP;
1700 else if (dest_mask & IMAGE_POINTER_MASK)
1701 type = IMAGE_POINTER;
1703 incompatible_image_types (instantiator, dest_mask,
1704 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
1705 | IMAGE_POINTER_MASK);
1707 mswindows_initialize_dibitmap_image_instance (ii, type);
1709 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
1710 find_keyword_in_vector (instantiator, Q_file);
1711 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
1712 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
1713 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
1714 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
1715 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
1716 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = mask ? mask :
1717 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1718 TRUE, black, white);
1722 case IMAGE_MONO_PIXMAP:
1723 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1724 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1725 FALSE, black, black);
1728 case IMAGE_COLOR_PIXMAP:
1730 COLORREF fg = black;
1731 COLORREF bg = white;
1733 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
1735 Fmake_color_instance (foreground, device,
1736 encode_error_behavior_flag (ERROR_ME));
1738 if (COLOR_INSTANCEP (foreground))
1739 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
1741 if (!NILP (background) && !COLOR_INSTANCEP (background))
1743 Fmake_color_instance (background, device,
1744 encode_error_behavior_flag (ERROR_ME));
1746 if (COLOR_INSTANCEP (background))
1747 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
1749 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
1750 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
1752 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1753 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1760 COLORREF fg = black;
1761 COLORREF bg = white;
1763 if (NILP (foreground))
1764 foreground = pointer_fg;
1765 if (NILP (background))
1766 background = pointer_bg;
1768 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
1769 find_keyword_in_vector (instantiator, Q_hotspot_x);
1770 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
1771 find_keyword_in_vector (instantiator, Q_hotspot_y);
1772 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
1773 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
1774 if (COLOR_INSTANCEP (foreground))
1775 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
1776 if (COLOR_INSTANCEP (background))
1777 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
1779 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1780 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1782 mswindows_initialize_image_instance_icon (ii, TRUE);
1792 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
1793 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1794 int dest_mask, int width, int height,
1795 /* Note that data is in ext-format! */
1798 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
1799 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
1800 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1801 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME
1802 (XDEVICE (IMAGE_INSTANCE_DEVICE (ii))));
1803 HDC hdc = FRAME_MSWINDOWS_CDC (f);
1805 CONST char *gcc_may_you_rot_in_hell;
1807 if (!NILP (mask_data))
1809 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))),
1810 gcc_may_you_rot_in_hell);
1812 xbm_create_bitmap_from_data ( hdc,
1814 gcc_may_you_rot_in_hell,
1815 XINT (XCAR (mask_data)),
1816 XINT (XCAR (XCDR (mask_data))), FALSE,
1818 PALETTERGB (255,255,255));
1821 init_image_instance_from_xbm_inline (ii, width, height, bits,
1822 instantiator, pointer_fg, pointer_bg,
1823 dest_mask, mask, mask_file);
1826 /* Instantiate method for XBM's. */
1829 mswindows_xbm_instantiate (Lisp_Object image_instance,
1830 Lisp_Object instantiator,
1831 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1832 int dest_mask, Lisp_Object domain)
1834 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1835 CONST char *gcc_go_home;
1837 assert (!NILP (data));
1839 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (data))),
1842 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
1843 pointer_bg, dest_mask, XINT (XCAR (data)),
1844 XINT (XCAR (XCDR (data))), gcc_go_home);
1848 /**********************************************************************
1850 **********************************************************************/
1852 /* This is about to get redefined! */
1855 /* We have to define SYSV32 so that compface.h includes string.h
1856 instead of strings.h. */
1861 #include <compface.h>
1865 /* JMP_BUF cannot be used here because if it doesn't get defined
1866 to jmp_buf we end up with a conflicting type error with the
1867 definition in compface.h */
1868 extern jmp_buf comp_env;
1872 mswindows_xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1873 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1874 int dest_mask, Lisp_Object domain)
1876 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1878 char *p, *bits, *bp;
1879 CONST char * volatile emsg = 0;
1880 CONST char * volatile dstring;
1882 assert (!NILP (data));
1884 GET_C_STRING_BINARY_DATA_ALLOCA (data, dstring);
1886 if ((p = strchr (dstring, ':')))
1891 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
1892 if (!(stattis = setjmp (comp_env)))
1894 UnCompAll ((char *) dstring);
1901 emsg = "uncompface: internal error";
1904 emsg = "uncompface: insufficient or invalid data";
1907 emsg = "uncompface: excess data ignored";
1912 signal_simple_error_2 (emsg, data, Qimage);
1914 bp = bits = (char *) alloca (PIXELS / 8);
1916 /* the compface library exports char F[], which uses a single byte per
1917 pixel to represent a 48x48 bitmap. Yuck. */
1918 for (i = 0, p = F; i < (PIXELS / 8); ++i)
1921 /* reverse the bit order of each byte... */
1922 for (b = n = 0; b < 8; ++b)
1929 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
1930 pointer_bg, dest_mask, 48, 48, bits);
1932 #endif /* HAVE_XFACE */
1935 /************************************************************************/
1936 /* image instance methods */
1937 /************************************************************************/
1940 mswindows_print_image_instance (struct Lisp_Image_Instance *p,
1941 Lisp_Object printcharfun,
1946 switch (IMAGE_INSTANCE_TYPE (p))
1948 case IMAGE_MONO_PIXMAP:
1949 case IMAGE_COLOR_PIXMAP:
1951 sprintf (buf, " (0x%lx",
1952 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
1953 write_c_string (buf, printcharfun);
1954 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
1956 sprintf (buf, "/0x%lx",
1957 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
1958 write_c_string (buf, printcharfun);
1960 write_c_string (")", printcharfun);
1969 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
1971 if (DEVICE_LIVE_P (XDEVICE (p->device)))
1973 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET
1975 IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
1977 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
1978 DestroyWindow (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p));
1979 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0;
1983 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
1984 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
1985 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
1986 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
1987 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
1988 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
1989 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
1990 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
1991 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
2002 /************************************************************************/
2003 /* subwindow and widget support */
2004 /************************************************************************/
2006 /* unmap the image if it is a widget. This is used by redisplay via
2007 redisplay_unmap_subwindows */
2009 mswindows_unmap_subwindow (struct Lisp_Image_Instance *p)
2011 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
2013 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2016 SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE
2017 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
2021 /* map the subwindow. This is used by redisplay via
2022 redisplay_output_subwindow */
2024 mswindows_map_subwindow (struct Lisp_Image_Instance *p, int x, int y)
2026 /* ShowWindow (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), SW_SHOW);*/
2027 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2030 SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOSIZE
2031 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
2034 /* when you click on a widget you may activate another widget this
2035 needs to be checked and all appropriate widgets updated */
2037 mswindows_update_subwindow (struct Lisp_Image_Instance *p)
2039 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET)
2041 /* buttons checked or otherwise */
2042 if ( EQ (IMAGE_INSTANCE_WIDGET_TYPE (p), Qbutton))
2044 if (gui_item_selected_p (&IMAGE_INSTANCE_WIDGET_ITEM (p)))
2045 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2046 BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
2048 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2049 BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
2054 /* register widgets into our hastable so that we can cope with the
2055 callbacks. The hashtable is weak so deregistration is handled
2058 mswindows_register_widget_instance (Lisp_Object instance, Lisp_Object domain)
2060 Lisp_Object frame = FW_FRAME (domain);
2061 struct frame* f = XFRAME (frame);
2062 int id = gui_item_hash (FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f),
2063 &XIMAGE_INSTANCE_WIDGET_ITEM (instance),
2065 Fputhash (make_int (id),
2066 XIMAGE_INSTANCE_WIDGET_CALLBACK (instance),
2067 FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f));
2072 mswindows_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2073 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2074 int dest_mask, Lisp_Object domain)
2076 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2077 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
2078 struct device* d = XDEVICE (device);
2079 Lisp_Object frame = FW_FRAME (domain);
2082 if (!DEVICE_MSWINDOWS_P (d))
2083 signal_simple_error ("Not an mswindows device", device);
2085 /* have to set the type this late in case there is no device
2086 instantiation for a widget */
2087 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
2089 wnd = CreateWindow( "STATIC",
2092 0, /* starting x position */
2093 0, /* starting y position */
2094 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2095 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2096 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), /* parent window */
2099 GetWindowLong (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2103 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2104 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
2108 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
2109 struct Lisp_Image_Instance *p2, int depth)
2111 switch (IMAGE_INSTANCE_TYPE (p1))
2113 case IMAGE_MONO_PIXMAP:
2114 case IMAGE_COLOR_PIXMAP:
2116 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
2117 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
2128 static unsigned long
2129 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
2131 switch (IMAGE_INSTANCE_TYPE (p))
2133 case IMAGE_MONO_PIXMAP:
2134 case IMAGE_COLOR_PIXMAP:
2136 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
2143 /* Set all the slots in an image instance structure to reasonable
2144 default values. This is used somewhere within an instantiate
2145 method. It is assumed that the device slot within the image
2146 instance is already set -- this is the case when instantiate
2147 methods are called. */
2150 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
2151 enum image_instance_type type)
2153 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
2154 IMAGE_INSTANCE_TYPE (ii) = type;
2155 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
2156 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
2157 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
2158 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
2159 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
2160 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
2164 /************************************************************************/
2166 /************************************************************************/
2169 mswindows_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2170 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2171 int dest_mask, Lisp_Object domain,
2172 CONST char* class, int flags, int exflags)
2174 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2176 struct Lisp_Image_Instance *groupii = 0;
2177 Lisp_Object group = find_keyword_in_vector (instantiator, Q_group);
2179 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), style;
2180 struct device* d = XDEVICE (device);
2181 Lisp_Object frame = FW_FRAME (domain);
2185 struct gui_item* pgui = &IMAGE_INSTANCE_WIDGET_ITEM (ii);
2187 if (!DEVICE_MSWINDOWS_P (d))
2188 signal_simple_error ("Not an mswindows device", device);
2190 /* if the user specified another glyph as a group pick up the
2191 instance in our domain. */
2194 if (SYMBOLP (group))
2195 group = XSYMBOL (group)->value;
2196 group = glyph_image_instance (group, domain, ERROR_ME, 1);
2197 groupii = XIMAGE_INSTANCE (group);
2200 if (!gui_item_active_p (pgui))
2201 flags |= WS_DISABLED;
2203 style = pgui->style;
2205 if (!NILP (pgui->callback))
2207 id = mswindows_register_widget_instance (image_instance, domain);
2209 /* have to set the type this late in case there is no device
2210 instantiation for a widget */
2211 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
2212 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
2213 GET_C_STRING_OS_DATA_ALLOCA (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm);
2215 wnd = CreateWindowEx(
2216 exflags /* | WS_EX_NOPARENTNOTIFY*/,
2220 0, /* starting x position */
2221 0, /* starting y position */
2222 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2223 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2225 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2226 (HMENU)id, /* No menu */
2228 GetWindowLong (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2232 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
2233 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2234 /* set the widget font from the widget face */
2235 SendMessage (wnd, WM_SETFONT,
2236 (WPARAM)FONT_INSTANCE_MSWINDOWS_HFONT
2237 (XFONT_INSTANCE (widget_face_font_info
2239 IMAGE_INSTANCE_WIDGET_FACE (ii),
2241 MAKELPARAM (TRUE, 0));
2244 /* Instantiate a button widget. Unfortunately instantiated widgets are
2245 particular to a frame since they need to have a parent. It's not
2246 like images where you just select the image into the context you
2247 want to display it in and BitBlt it. So images instances can have a
2248 many-to-one relationship with things you see, whereas widgets can
2249 only be one-to-one (i.e. per frame) */
2251 mswindows_button_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2252 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2253 int dest_mask, Lisp_Object domain)
2255 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2257 int flags = BS_NOTIFY;
2259 struct gui_item* pgui = &IMAGE_INSTANCE_WIDGET_ITEM (ii);
2260 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image);
2262 if (!gui_item_active_p (pgui))
2263 flags |= WS_DISABLED;
2267 if (!IMAGE_INSTANCEP (glyph))
2268 glyph = glyph_image_instance (glyph, domain, ERROR_ME, 1);
2270 if (IMAGE_INSTANCEP (glyph))
2271 flags |= XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2272 BS_BITMAP : BS_ICON;
2275 style = pgui->style;
2277 if (EQ (style, Qradio))
2279 flags |= BS_RADIOBUTTON;
2281 else if (EQ (style, Qtoggle))
2283 flags |= BS_AUTOCHECKBOX;
2286 flags |= BS_DEFPUSHBUTTON;
2288 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2289 pointer_bg, dest_mask, domain, "BUTTON", flags,
2290 WS_EX_CONTROLPARENT);
2292 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2293 /* set the checked state */
2294 if (gui_item_selected_p (pgui))
2295 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
2297 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
2298 /* add the image if one was given */
2299 if (!NILP (glyph) && IMAGE_INSTANCEP (glyph))
2301 SendMessage (wnd, BM_SETIMAGE,
2302 (WPARAM) (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2303 IMAGE_BITMAP : IMAGE_ICON),
2304 (LPARAM) (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2305 XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) :
2306 XIMAGE_INSTANCE_MSWINDOWS_ICON (glyph)));
2310 /* instantiate an edit control */
2312 mswindows_edit_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2313 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2314 int dest_mask, Lisp_Object domain)
2316 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2317 pointer_bg, dest_mask, domain, "EDIT",
2318 ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP
2320 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2323 /* instantiate an edit control */
2325 mswindows_progress_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2326 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2327 int dest_mask, Lisp_Object domain)
2330 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2331 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2332 pointer_bg, dest_mask, domain, PROGRESS_CLASS,
2333 WS_TABSTOP | WS_BORDER | PBS_SMOOTH,
2334 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2335 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2336 /* set the colors */
2337 #ifdef PBS_SETBKCOLOR
2338 SendMessage (wnd, PBS_SETBKCOLOR, 0,
2339 (LPARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR
2342 (XIMAGE_INSTANCE_WIDGET_FACE (ii),
2343 XIMAGE_INSTANCE_SUBWINDOW_FRAME (ii))))));
2345 #ifdef PBS_SETBARCOLOR
2346 SendMessage (wnd, PBS_SETBARCOLOR, 0,
2347 (L:PARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR
2350 (XIMAGE_INSTANCE_WIDGET_FACE (ii),
2351 XIMAGE_INSTANCE_SUBWINDOW_FRAME (ii))))));
2355 /* instantiate a static control possible for putting other things in */
2357 mswindows_label_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2358 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2359 int dest_mask, Lisp_Object domain)
2361 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2362 pointer_bg, dest_mask, domain, "STATIC",
2363 0, WS_EX_STATICEDGE);
2367 /* instantiate a static control possible for putting other things in */
2369 mswindows_group_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2370 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2371 int dest_mask, Lisp_Object domain)
2373 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2374 pointer_bg, dest_mask, domain, "BUTTON",
2375 WS_GROUP | BS_GROUPBOX | WS_BORDER,
2380 /* instantiate a scrollbar control */
2382 mswindows_scrollbar_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2383 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2384 int dest_mask, Lisp_Object domain)
2386 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2387 pointer_bg, dest_mask, domain, "SCROLLBAR",
2392 /* instantiate a combo control */
2394 mswindows_combo_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2395 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2396 int dest_mask, Lisp_Object domain)
2398 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2402 /* Maybe ought to generalise this more but it may be very windows
2403 specific. In windows the window height of a combo box is the
2404 height when the combo box is open. Thus we need to set the height
2405 before creating the window and then reset it to a single line
2406 after the window is created so that redisplay does the right
2408 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2409 pointer_bg, dest_mask, domain, "COMBOBOX",
2410 WS_BORDER | WS_TABSTOP | CBS_DROPDOWN
2412 | CBS_HASSTRINGS | WS_VSCROLL,
2413 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2414 /* reset the height */
2415 widget_text_to_pixel_conversion (domain,
2416 IMAGE_INSTANCE_WIDGET_FACE (ii), 1, 0,
2417 &IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii), 0);
2418 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2419 /* add items to the combo box */
2420 SendMessage (wnd, CB_RESETCONTENT, 0, 0);
2421 LIST_LOOP (rest, Fplist_get (IMAGE_INSTANCE_WIDGET_PROPS (ii), Q_items, Qnil))
2424 GET_C_STRING_OS_DATA_ALLOCA (XCAR (rest), lparam);
2425 if (SendMessage (wnd, CB_ADDSTRING, 0, (LPARAM)lparam) == CB_ERR)
2426 signal_simple_error ("error adding combo entries", instantiator);
2430 /* get properties of a control */
2432 mswindows_widget_property (Lisp_Object image_instance, Lisp_Object prop)
2434 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2435 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2436 /* get the text from a control */
2437 if (EQ (prop, Q_text))
2439 Extcount len = SendMessage (wnd, WM_GETTEXTLENGTH, 0, 0);
2440 Extbyte* buf =alloca (len+1);
2442 SendMessage (wnd, WM_GETTEXT, (WPARAM)len+1, (LPARAM) buf);
2443 return build_ext_string (buf, FORMAT_OS);
2448 /* get properties of a button */
2450 mswindows_button_property (Lisp_Object image_instance, Lisp_Object prop)
2452 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2453 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2454 /* check the state of a button */
2455 if (EQ (prop, Q_selected))
2457 if (SendMessage (wnd, BM_GETSTATE, 0, 0) & BST_CHECKED)
2465 /* get properties of a combo box */
2467 mswindows_combo_property (Lisp_Object image_instance, Lisp_Object prop)
2469 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2470 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2471 /* get the text from a control */
2472 if (EQ (prop, Q_text))
2474 long item = SendMessage (wnd, CB_GETCURSEL, 0, 0);
2475 Extcount len = SendMessage (wnd, CB_GETLBTEXTLEN, (WPARAM)item, 0);
2476 Extbyte* buf = alloca (len+1);
2477 SendMessage (wnd, CB_GETLBTEXT, (WPARAM)item, (LPARAM)buf);
2478 return build_ext_string (buf, FORMAT_OS);
2483 /* set the properties of a control */
2485 mswindows_widget_set_property (Lisp_Object image_instance, Lisp_Object prop,
2488 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2490 if (EQ (prop, Q_text))
2494 GET_C_STRING_OS_DATA_ALLOCA (val, lparam);
2495 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2496 WM_SETTEXT, 0, (LPARAM)lparam);
2502 /* set the properties of a progres guage */
2504 mswindows_progress_set_property (Lisp_Object image_instance, Lisp_Object prop,
2507 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2509 if (EQ (prop, Q_percent))
2512 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2513 PBM_SETPOS, (WPARAM)XINT (val), 0);
2520 /************************************************************************/
2521 /* initialization */
2522 /************************************************************************/
2525 syms_of_glyphs_mswindows (void)
2527 defkeyword (&Q_resource_id, ":resource-id");
2528 defkeyword (&Q_resource_type, ":resource-type");
2532 console_type_create_glyphs_mswindows (void)
2536 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
2537 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
2538 CONSOLE_HAS_METHOD (mswindows, unmap_subwindow);
2539 CONSOLE_HAS_METHOD (mswindows, map_subwindow);
2540 CONSOLE_HAS_METHOD (mswindows, update_subwindow);
2541 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
2542 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
2543 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
2544 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
2548 image_instantiator_format_create_glyphs_mswindows (void)
2550 /* image-instantiator types */
2552 INITIALIZE_DEVICE_IIFORMAT (mswindows, xpm);
2553 IIFORMAT_HAS_DEVMETHOD (mswindows, xpm, instantiate);
2555 INITIALIZE_DEVICE_IIFORMAT (mswindows, xbm);
2556 IIFORMAT_HAS_DEVMETHOD (mswindows, xbm, instantiate);
2558 INITIALIZE_DEVICE_IIFORMAT (mswindows, xface);
2559 IIFORMAT_HAS_DEVMETHOD (mswindows, xface, instantiate);
2561 INITIALIZE_DEVICE_IIFORMAT (mswindows, button);
2562 IIFORMAT_HAS_DEVMETHOD (mswindows, button, property);
2563 IIFORMAT_HAS_DEVMETHOD (mswindows, button, instantiate);
2565 INITIALIZE_DEVICE_IIFORMAT (mswindows, edit);
2566 IIFORMAT_HAS_DEVMETHOD (mswindows, edit, instantiate);
2568 INITIALIZE_DEVICE_IIFORMAT (mswindows, subwindow);
2569 IIFORMAT_HAS_DEVMETHOD (mswindows, subwindow, instantiate);
2571 INITIALIZE_DEVICE_IIFORMAT (mswindows, widget);
2572 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, property);
2573 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, set_property);
2575 INITIALIZE_DEVICE_IIFORMAT (mswindows, group);
2576 IIFORMAT_HAS_DEVMETHOD (mswindows, group, instantiate);
2578 INITIALIZE_DEVICE_IIFORMAT (mswindows, label);
2579 IIFORMAT_HAS_DEVMETHOD (mswindows, label, instantiate);
2581 INITIALIZE_DEVICE_IIFORMAT (mswindows, combo);
2582 IIFORMAT_HAS_DEVMETHOD (mswindows, combo, property);
2583 IIFORMAT_HAS_DEVMETHOD (mswindows, combo, instantiate);
2585 INITIALIZE_DEVICE_IIFORMAT (mswindows, scrollbar);
2586 IIFORMAT_HAS_DEVMETHOD (mswindows, scrollbar, instantiate);
2588 INITIALIZE_DEVICE_IIFORMAT (mswindows, progress);
2589 IIFORMAT_HAS_DEVMETHOD (mswindows, progress, set_property);
2590 IIFORMAT_HAS_DEVMETHOD (mswindows, progress, instantiate);
2592 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
2594 IIFORMAT_HAS_METHOD (bmp, validate);
2595 IIFORMAT_HAS_METHOD (bmp, normalize);
2596 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
2597 IIFORMAT_HAS_METHOD (bmp, instantiate);
2599 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
2600 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
2602 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (mswindows_resource,
2603 "mswindows-resource");
2605 IIFORMAT_HAS_METHOD (mswindows_resource, validate);
2606 IIFORMAT_HAS_METHOD (mswindows_resource, normalize);
2607 IIFORMAT_HAS_METHOD (mswindows_resource, possible_dest_types);
2608 IIFORMAT_HAS_METHOD (mswindows_resource, instantiate);
2610 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_type,
2611 check_valid_resource_symbol);
2612 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_id, check_valid_resource_id);
2613 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_file, check_valid_string);
2617 vars_of_glyphs_mswindows (void)
2620 Fprovide (Qmswindows_resource);
2621 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
2622 A list of the directories in which mswindows bitmap files may be found.
2623 This is used by the `make-image-instance' function.
2625 Vmswindows_bitmap_file_path = Qnil;
2630 Fprovide (Qscrollbar);
2632 Fprovide (Qprogress);
2636 complex_vars_of_glyphs_mswindows (void)