1 /* mswindows-specific glyph objects.
2 Copyright (C) 1998, 1999, 2000 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
56 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing);
57 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string);
58 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
59 DECLARE_IMAGE_INSTANTIATOR_FORMAT (inherit);
60 DECLARE_IMAGE_INSTANTIATOR_FORMAT (layout);
62 DECLARE_IMAGE_INSTANTIATOR_FORMAT (jpeg);
65 DECLARE_IMAGE_INSTANTIATOR_FORMAT (tiff);
68 DECLARE_IMAGE_INSTANTIATOR_FORMAT (png);
71 DECLARE_IMAGE_INSTANTIATOR_FORMAT (gif);
74 DEFINE_DEVICE_IIFORMAT (mswindows, xpm);
75 DEFINE_DEVICE_IIFORMAT (msprinter, xpm);
77 DEFINE_DEVICE_IIFORMAT (mswindows, xbm);
78 DEFINE_DEVICE_IIFORMAT (msprinter, xbm);
80 DEFINE_DEVICE_IIFORMAT (mswindows, xface);
81 DEFINE_DEVICE_IIFORMAT (msprinter, xface);
83 DEFINE_DEVICE_IIFORMAT (mswindows, button);
84 DEFINE_DEVICE_IIFORMAT (mswindows, edit_field);
85 DEFINE_DEVICE_IIFORMAT (mswindows, subwindow);
86 DEFINE_DEVICE_IIFORMAT (mswindows, widget);
87 DEFINE_DEVICE_IIFORMAT (mswindows, label);
88 DEFINE_DEVICE_IIFORMAT (mswindows, scrollbar);
89 DEFINE_DEVICE_IIFORMAT (mswindows, combo_box);
90 DEFINE_DEVICE_IIFORMAT (mswindows, progress_gauge);
91 DEFINE_DEVICE_IIFORMAT (mswindows, tree_view);
92 DEFINE_DEVICE_IIFORMAT (mswindows, tab_control);
94 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
96 Lisp_Object Vmswindows_bitmap_file_path;
97 static COLORREF transparent_color = RGB (1,1,1);
99 DEFINE_IMAGE_INSTANTIATOR_FORMAT (mswindows_resource);
100 Lisp_Object Q_resource_type, Q_resource_id;
101 Lisp_Object Qmswindows_resource;
104 mswindows_initialize_dibitmap_image_instance (Lisp_Image_Instance *ii,
106 enum image_instance_type type);
108 mswindows_initialize_image_instance_mask (Lisp_Image_Instance* image,
112 * Given device D, retrieve compatible device context. D can be either
113 * mswindows or an msprinter device.
116 get_device_compdc (struct device *d)
118 if (DEVICE_MSWINDOWS_P (d))
119 return DEVICE_MSWINDOWS_HCDC (d);
121 return DEVICE_MSPRINTER_HCDC (d);
125 * Initialize image instance pixel sizes in II. For a display bitmap,
126 * these will be same as real bitmap sizes. For a printer bitmap,
127 * these will be scaled up so that the bitmap is proportionally enlarged
128 * when output to printer. Redisplay code takes care of scaling, to
129 * conserve memory we do not really scale bitmaps. Set the watermark
131 * #### Add support for unscalable bitmaps.
133 static void init_image_instance_geometry (Lisp_Image_Instance *ii)
135 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
136 struct device *d = XDEVICE (device);
138 if (/* #### Scaleable && */ DEVICE_MSPRINTER_P (d))
140 HDC printer_dc = DEVICE_MSPRINTER_HCDC (d);
141 HDC display_dc = CreateCompatibleDC (NULL);
142 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) =
143 MulDiv (IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii),
144 GetDeviceCaps (printer_dc, LOGPIXELSX),
145 GetDeviceCaps (display_dc, LOGPIXELSX));
146 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) =
147 MulDiv (IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii),
148 GetDeviceCaps (printer_dc, LOGPIXELSY),
149 GetDeviceCaps (display_dc, LOGPIXELSY));
153 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) =
154 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii);
155 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) =
156 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii);
160 #define BPLINE(width) ((int)(~3UL & (unsigned long)((width) +3)))
162 /************************************************************************/
163 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/
165 /************************************************************************/
166 static BITMAPINFO* convert_EImage_to_DIBitmap (Lisp_Object device,
167 int width, int height,
170 unsigned char** bmp_data)
172 struct device *d = XDEVICE (device);
176 BITMAPINFO* bmp_info;
177 unsigned char *ip, *dp;
179 if (GetDeviceCaps (get_device_compdc (d), BITSPIXEL) > 0)
181 int bpline = BPLINE(width * 3);
182 /* FIXME: we can do this because 24bpp implies no color table, once
183 * we start palettizing this is no longer true. The X versions of
184 * this function quantises to 256 colors or bit masks down to a
185 * long. Windows can actually handle rgb triples in the raw so I
186 * don't see much point trying to optimize down to the best
187 * structure - unless it has memory / color allocation implications
189 bmp_info=xnew_and_zero (BITMAPINFO);
196 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */
197 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */
198 bmp_info->bmiHeader.biSizeImage=width*height*3;
200 /* bitmap data needs to be in blue, green, red triples - in that
201 order, eimage is in RGB format so we need to convert */
202 *bmp_data = xnew_array_and_zero (unsigned char, bpline * height);
203 *bit_count = bpline * height;
212 for (i = height-1; i >= 0; i--) {
213 dp = (*bmp_data) + (i * bpline);
214 for (j = 0; j < width; j++) {
222 else /* scale to 256 colors */
226 int bpline = BPLINE (width * 3);
227 /* Quantize the image and get a histogram while we're at it.
228 Do this first to save memory */
229 qtable = build_EImage_quantable(pic, width, height, 256);
230 if (qtable == NULL) return NULL;
232 /* use our quantize table to allocate the colors */
233 ncolors = qtable->num_active_colors;
234 bmp_info=(BITMAPINFO*)xmalloc_and_zero (sizeof(BITMAPINFOHEADER) +
235 sizeof(RGBQUAD) * ncolors);
242 colortbl=(RGBQUAD*)(((unsigned char*)bmp_info)+sizeof(BITMAPINFOHEADER));
244 bmp_info->bmiHeader.biBitCount=8;
245 bmp_info->bmiHeader.biCompression=BI_RGB;
246 bmp_info->bmiHeader.biSizeImage=bpline*height;
247 bmp_info->bmiHeader.biClrUsed=ncolors;
248 bmp_info->bmiHeader.biClrImportant=ncolors;
250 *bmp_data = (unsigned char *) xmalloc_and_zero (bpline * height);
251 *bit_count = bpline * height;
260 /* build up an RGBQUAD colortable */
261 for (i = 0; i < qtable->num_active_colors; i++)
263 colortbl[i].rgbRed = (BYTE) qtable->rm[i];
264 colortbl[i].rgbGreen = (BYTE) qtable->gm[i];
265 colortbl[i].rgbBlue = (BYTE) qtable->bm[i];
266 colortbl[i].rgbReserved = 0;
269 /* now build up the data. picture has to be upside-down and
270 back-to-front for msw bitmaps */
272 for (i = height-1; i >= 0; i--)
274 dp = (*bmp_data) + (i * bpline);
275 for (j = 0; j < width; j++)
280 *dp++ = QUANT_GET_COLOR (qtable,rd,gr,bl);
285 /* fix up the standard stuff */
286 bmp_info->bmiHeader.biWidth=width;
287 bmp_info->bmiHeader.biHeight=height;
288 bmp_info->bmiHeader.biPlanes=1;
289 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
290 bmp_info->bmiHeader.biXPelsPerMeter=0; /* unless you know better */
291 bmp_info->bmiHeader.biYPelsPerMeter=0;
296 /* Given a pixmap filename, look through all of the "standard" places
297 where the file might be located. Return a full pathname if found;
298 otherwise, return Qnil. */
301 mswindows_locate_pixmap_file (Lisp_Object name)
303 /* This function can GC if IN_REDISPLAY is false */
306 /* Check non-absolute pathnames with a directory component relative to
307 the search path; that's the way Xt does it. */
308 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) ||
309 (XSTRING_BYTE (name, 0) == '.' &&
310 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 1)) ||
311 (XSTRING_BYTE (name, 1) == '.' &&
312 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 2)))))))
314 if (!NILP (Ffile_readable_p (name)))
315 return Fexpand_file_name (name, Qnil);
320 if (locate_file (Vmswindows_bitmap_file_path, name, Qnil, &found, R_OK) < 0)
322 Lisp_Object temp = list1 (Vdata_directory);
326 locate_file (temp, name, Qnil, &found, R_OK);
334 /* Initialize an image instance from a bitmap
336 DEST_MASK specifies the mask of allowed image types.
338 If this fails, signal an error. INSTANTIATOR is only used
339 in the error message. */
342 init_image_instance_from_dibitmap (Lisp_Image_Instance *ii,
343 BITMAPINFO *bmp_info,
348 Lisp_Object instantiator,
349 int x_hot, int y_hot,
352 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
353 struct device *d = XDEVICE (device);
355 enum image_instance_type type;
359 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
360 type = IMAGE_COLOR_PIXMAP;
361 else if (dest_mask & IMAGE_POINTER_MASK)
362 type = IMAGE_POINTER;
364 incompatible_image_types (instantiator, dest_mask,
365 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
367 hdc = get_device_compdc (d);
368 bitmap = CreateDIBSection (hdc,
374 if (!bitmap || !bmp_buf)
375 signal_simple_error ("Unable to create bitmap", instantiator);
377 /* copy in the actual bitmap */
378 memcpy (bmp_buf, bmp_data, bmp_bits);
380 mswindows_initialize_dibitmap_image_instance (ii, slices, type);
382 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
383 find_keyword_in_vector (instantiator, Q_file);
385 /* Fixup a set of bitmaps. */
386 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap;
388 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
389 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii) =
390 bmp_info->bmiHeader.biWidth;
391 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii) =
392 bmp_info->bmiHeader.biHeight;
393 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount;
394 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), x_hot);
395 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), y_hot);
396 init_image_instance_geometry (ii);
400 mswindows_initialize_image_instance_mask (ii, hdc);
403 if (type == IMAGE_POINTER)
405 mswindows_initialize_image_instance_icon(ii, TRUE);
410 image_instance_add_dibitmap (Lisp_Image_Instance *ii,
411 BITMAPINFO *bmp_info,
415 Lisp_Object instantiator)
417 struct device *d = XDEVICE (IMAGE_INSTANCE_DEVICE (ii));
420 HBITMAP bitmap = CreateDIBSection (get_device_compdc (d),
426 if (!bitmap || !bmp_buf)
427 signal_simple_error ("Unable to create bitmap", instantiator);
429 /* copy in the actual bitmap */
430 memcpy (bmp_buf, bmp_data, bmp_bits);
431 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (ii, slice) = bitmap;
435 mswindows_init_image_instance_from_eimage (Lisp_Image_Instance *ii,
436 int width, int height,
438 unsigned char *eimage,
440 Lisp_Object instantiator,
443 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
444 BITMAPINFO* bmp_info;
445 unsigned char* bmp_data;
450 CHECK_MSGDI_DEVICE (device);
452 /* this is a hack but MaskBlt and TransparentBlt are not supported
453 on most windows variants */
454 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
455 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
457 for (slice = 0; slice < slices; slice++)
459 /* build a bitmap from the eimage */
460 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height,
461 eimage + (width * height * 3 * slice),
462 &bmp_bits, &bmp_data)))
464 signal_simple_error ("EImage to DIBitmap conversion failed",
468 /* Now create the pixmap and set up the image instance */
470 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
471 bmp_data, bmp_bits, slices, instantiator,
474 image_instance_add_dibitmap (ii, bmp_info, bmp_data, bmp_bits, slice,
483 set_mono_pixel (unsigned char* bits,
484 int bpline, int height,
485 int x, int y, int white)
488 unsigned char bitnum;
489 /* Find the byte on which this scanline begins */
490 i = (height - y - 1) * bpline;
491 /* Find the byte containing this pixel */
493 /* Which bit is it? */
494 bitnum = (unsigned char) (7 - (x & 7));
495 if (white) /* Turn it on */
496 bits[i] |= (1 << bitnum);
497 else /* Turn it off */
498 bits[i] &= ~(1 << bitnum);
502 mswindows_initialize_image_instance_mask (Lisp_Image_Instance* image,
507 unsigned char *dibits, *and_bits;
508 BITMAPINFO *bmp_info =
509 (BITMAPINFO*) xmalloc_and_zero (sizeof (BITMAPINFO) + sizeof (RGBQUAD));
511 int height = IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (image);
513 int maskbpline = BPLINE ((IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image) + 7) / 8);
514 int bpline = BPLINE (IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image) * 3);
519 bmp_info->bmiHeader.biWidth=IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image);
520 bmp_info->bmiHeader.biHeight = height;
521 bmp_info->bmiHeader.biPlanes = 1;
522 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
523 bmp_info->bmiHeader.biBitCount = 1;
524 bmp_info->bmiHeader.biCompression = BI_RGB;
525 bmp_info->bmiHeader.biClrUsed = 2;
526 bmp_info->bmiHeader.biClrImportant = 2;
527 bmp_info->bmiHeader.biSizeImage = height * maskbpline;
528 bmp_info->bmiColors[0].rgbRed = 0;
529 bmp_info->bmiColors[0].rgbGreen = 0;
530 bmp_info->bmiColors[0].rgbBlue = 0;
531 bmp_info->bmiColors[0].rgbReserved = 0;
532 bmp_info->bmiColors[1].rgbRed = 255;
533 bmp_info->bmiColors[1].rgbGreen = 255;
534 bmp_info->bmiColors[1].rgbBlue = 255;
535 bmp_info->bmiColors[0].rgbReserved = 0;
537 if (!(mask = CreateDIBSection (hcdc,
547 old = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (image));
548 /* build up an in-memory set of bits to mess with */
551 bmp_info->bmiHeader.biWidth = IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image);
552 bmp_info->bmiHeader.biHeight = -height;
553 bmp_info->bmiHeader.biPlanes = 1;
554 bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
555 bmp_info->bmiHeader.biBitCount = 24;
556 bmp_info->bmiHeader.biCompression = BI_RGB;
557 bmp_info->bmiHeader.biClrUsed = 0;
558 bmp_info->bmiHeader.biClrImportant = 0;
559 bmp_info->bmiHeader.biSizeImage = height * bpline;
561 dibits = (unsigned char*) xmalloc_and_zero (bpline * height);
563 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image),
568 DIB_RGB_COLORS) <= 0)
574 /* now set the colored bits in the mask and transparent ones to
575 black in the original */
576 for (i = 0; i < IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image); i++)
578 for (j=0; j<height; j++)
580 unsigned char* idx = &dibits[j * bpline + i * 3];
582 if (RGB (idx[2], idx[1], idx[0]) == transparent_color)
584 idx[0] = idx[1] = idx[2] = 0;
585 set_mono_pixel (and_bits, maskbpline, height, i, j, TRUE);
589 set_mono_pixel (and_bits, maskbpline, height, i, j, FALSE);
595 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image),
605 SelectObject(hcdc, old);
607 IMAGE_INSTANCE_MSWINDOWS_MASK (image) = mask;
611 mswindows_initialize_image_instance_icon (Lisp_Image_Instance* image,
616 /* we rely on windows to do any resizing necessary */
617 x_icon.fIcon=cursor ? FALSE : TRUE;
618 x_icon.xHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image));
619 x_icon.yHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image));
620 x_icon.hbmMask=IMAGE_INSTANCE_MSWINDOWS_MASK (image);
621 x_icon.hbmColor=IMAGE_INSTANCE_MSWINDOWS_BITMAP (image);
623 IMAGE_INSTANCE_MSWINDOWS_ICON (image)=
624 CreateIconIndirect (&x_icon);
628 create_resized_bitmap (HBITMAP curbmp, struct frame *f,
635 HDC hcdc = get_device_compdc (XDEVICE (FRAME_DEVICE (f)));
636 HDC hdcDst = CreateCompatibleDC (hcdc);
638 old1 = SelectObject (hcdc, curbmp);
640 newbmp = CreateCompatibleBitmap (hcdc, newx, newy);
642 old2 = SelectObject (hdcDst, newbmp);
644 if (!StretchBlt (hdcDst, 0, 0, newx, newy,
650 DeleteObject (newbmp);
655 SelectObject (hdcDst, old2);
656 SelectObject (hcdc, old1);
663 mswindows_create_resized_bitmap (Lisp_Image_Instance* ii,
667 return create_resized_bitmap (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii),
669 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii),
670 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii),
675 mswindows_create_resized_mask (Lisp_Image_Instance* ii,
679 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii) == NULL)
682 return create_resized_bitmap (IMAGE_INSTANCE_MSWINDOWS_MASK (ii),
684 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii),
685 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii),
689 #if 0 /* Currently unused */
690 /* #### Warining: This function is not correct anymore with
691 resizable printer bitmaps. If you uncomment it, clean it. --kkm */
693 mswindows_resize_dibitmap_instance (Lisp_Image_Instance* ii,
697 HBITMAP newbmp = mswindows_create_resized_bitmap (ii, f, newx, newy);
698 HBITMAP newmask = mswindows_create_resized_mask (ii, f, newx, newy);
703 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii))
704 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
705 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
706 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
708 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp;
709 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newmask;
710 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx;
711 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy;
717 /**********************************************************************
719 **********************************************************************/
729 static struct color_symbol*
730 extract_xpm_color_names (Lisp_Object device,
732 Lisp_Object color_symbol_alist,
735 /* This function can GC */
737 Lisp_Object results = Qnil;
739 struct color_symbol *colortbl;
740 struct gcpro gcpro1, gcpro2;
742 GCPRO2 (results, device);
744 /* We built up results to be (("name" . #<color>) ...) so that if an
745 error happens we don't lose any malloc()ed data, or more importantly,
746 leave any pixels allocated in the server. */
748 LIST_LOOP (rest, color_symbol_alist)
750 Lisp_Object cons = XCAR (rest);
751 Lisp_Object name = XCAR (cons);
752 Lisp_Object value = XCDR (cons);
758 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
761 assert (COLOR_SPECIFIERP (value));
762 value = Fspecifier_instance (value, domain, Qnil, Qnil);
766 results = noseeum_cons (noseeum_cons (name, value), results);
769 UNGCPRO; /* no more evaluation */
772 if (i == 0) return 0;
774 colortbl = xnew_array_and_zero (struct color_symbol, i);
778 Lisp_Object cons = XCAR (results);
780 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
782 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (cons),
783 C_STRING_ALLOCA, colortbl[j].name,
785 colortbl[j].name = xstrdup (colortbl[j].name); /* mustn't lose this when we return */
786 free_cons (XCONS (cons));
788 results = XCDR (results);
789 free_cons (XCONS (cons));
794 static int xpm_to_eimage (Lisp_Object image, const Extbyte *buffer,
795 unsigned char** data,
796 int* width, int* height,
797 int* x_hot, int* y_hot,
799 struct color_symbol* color_symbols,
804 int result, i, j, transp_idx, maskbpline;
807 COLORREF color; /* the american spelling virus hits again .. */
812 xpminfo.valuemask=XpmHotspot;
815 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
824 signal_simple_error ("Invalid XPM data", image);
828 signal_double_file_error ("Parsing pixmap data",
829 "out of memory", image);
833 signal_double_file_error_2 ("Parsing pixmap data",
835 make_int (result), image);
839 *width = xpmimage.width;
840 *height = xpmimage.height;
841 maskbpline = BPLINE ((~7UL & (unsigned long)(*width + 7)) / 8);
843 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
847 XpmFreeXpmImage (&xpmimage);
848 XpmFreeXpmInfo (&xpminfo);
852 /* build a color table to speed things up */
853 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
857 XpmFreeXpmImage (&xpmimage);
858 XpmFreeXpmInfo (&xpminfo);
862 for (i=0; i<xpmimage.ncolors; i++)
865 /* pick up symbolic colors in preference */
866 if (xpmimage.colorTable[i].symbolic)
868 if (!strcasecmp (xpmimage.colorTable[i].symbolic,"BgColor")
870 !strcasecmp (xpmimage.colorTable[i].symbolic,"None"))
873 colortbl[i]=transparent_color;
875 goto label_found_color;
877 else if (color_symbols)
879 for (j = 0; j<nsymbols; j++)
881 if (!strcmp (xpmimage.colorTable[i].symbolic,
882 color_symbols[j].name ))
884 colortbl[i]=color_symbols[j].color;
885 goto label_found_color;
889 else if (xpmimage.colorTable[i].c_color == 0)
894 /* pick up transparencies */
895 if (!strcasecmp (xpmimage.colorTable[i].c_color,"None"))
898 colortbl[i]=transparent_color;
900 goto label_found_color;
902 /* finally pick up a normal color spec */
903 if (xpmimage.colorTable[i].c_color)
906 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
907 goto label_found_color;
913 XpmFreeXpmImage (&xpmimage);
914 XpmFreeXpmInfo (&xpminfo);
920 /* convert the image */
923 for (i = 0; i< *width * *height; i++)
925 color = colortbl[*sptr++];
927 /* split out the 0x02bbggrr colorref into an rgb triple */
928 *dptr++=GetRValue (color); /* red */
929 *dptr++=GetGValue (color); /* green */
930 *dptr++=GetBValue (color); /* blue */
933 *x_hot=xpminfo.x_hotspot;
934 *y_hot=xpminfo.y_hotspot;
936 XpmFreeXpmImage (&xpmimage);
937 XpmFreeXpmInfo (&xpminfo);
943 mswindows_xpm_instantiate (Lisp_Object image_instance,
944 Lisp_Object instantiator,
945 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
946 int dest_mask, Lisp_Object domain)
948 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
949 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
950 const Extbyte *bytes;
952 unsigned char *eimage;
953 int width, height, x_hot, y_hot;
954 BITMAPINFO* bmp_info;
955 unsigned char* bmp_data;
957 int nsymbols=0, transp;
958 struct color_symbol* color_symbols=NULL;
960 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
961 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
964 CHECK_MSGDI_DEVICE (device);
966 assert (!NILP (data));
968 TO_EXTERNAL_FORMAT (LISP_STRING, data,
969 ALLOCA, (bytes, len),
972 /* in case we have color symbols */
973 color_symbols = extract_xpm_color_names (device, domain,
974 color_symbol_alist, &nsymbols);
976 /* convert to an eimage to make processing easier */
977 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
978 &x_hot, &y_hot, &transp, color_symbols, nsymbols))
980 signal_simple_error ("XPM to EImage conversion failed",
988 xfree (color_symbols[nsymbols].name);
990 xfree(color_symbols);
993 /* build a bitmap from the eimage */
994 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
995 &bmp_bits, &bmp_data)))
997 signal_simple_error ("XPM to EImage conversion failed",
1002 /* Now create the pixmap and set up the image instance */
1003 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
1004 bmp_data, bmp_bits, 1, instantiator,
1005 x_hot, y_hot, transp);
1010 #endif /* HAVE_XPM */
1012 /**********************************************************************
1014 **********************************************************************/
1017 bmp_validate (Lisp_Object instantiator)
1019 file_or_data_must_be_present (instantiator);
1023 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
1025 return simple_image_type_normalize (inst, console_type, Qbmp);
1029 bmp_possible_dest_types (void)
1031 return IMAGE_COLOR_PIXMAP_MASK;
1035 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1036 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1037 int dest_mask, Lisp_Object domain)
1039 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1040 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1041 const Extbyte *bytes;
1043 BITMAPFILEHEADER* bmp_file_header;
1044 BITMAPINFO* bmp_info;
1047 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1049 CHECK_MSGDI_DEVICE (device);
1051 assert (!NILP (data));
1053 TO_EXTERNAL_FORMAT (LISP_STRING, data,
1054 ALLOCA, (bytes, len),
1057 /* Then slurp the image into memory, decoding along the way.
1058 The result is the image in a simple one-byte-per-pixel
1061 bmp_file_header=(BITMAPFILEHEADER*)bytes;
1062 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
1063 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
1064 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
1066 /* Now create the pixmap and set up the image instance */
1067 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
1068 bmp_data, bmp_bits, 1, instantiator,
1073 /**********************************************************************
1075 **********************************************************************/
1078 mswindows_resource_validate (Lisp_Object instantiator)
1080 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
1082 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
1084 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
1085 signal_simple_error ("Must supply :file, :resource-id and :resource-type",
1090 mswindows_resource_normalize (Lisp_Object inst, Lisp_Object console_type)
1092 /* This function can call lisp */
1093 Lisp_Object file = Qnil;
1094 struct gcpro gcpro1, gcpro2;
1095 Lisp_Object alist = Qnil;
1097 GCPRO2 (file, alist);
1099 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
1102 if (CONSP (file)) /* failure locating filename */
1103 signal_double_file_error ("Opening pixmap file",
1104 "no such file or directory",
1107 if (NILP (file)) /* no conversion necessary */
1108 RETURN_UNGCPRO (inst);
1110 alist = tagged_vector_to_alist (inst);
1113 alist = remassq_no_quit (Q_file, alist);
1114 alist = Fcons (Fcons (Q_file, file), alist);
1118 Lisp_Object result = alist_to_tagged_vector (Qmswindows_resource, alist);
1120 RETURN_UNGCPRO (result);
1125 mswindows_resource_possible_dest_types (void)
1127 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
1137 #define OCR_ICOCUR 32647
1138 #define OIC_SAMPLE 32512
1139 #define OIC_HAND 32513
1140 #define OIC_QUES 32514
1141 #define OIC_BANG 32515
1142 #define OIC_NOTE 32516
1143 #define OIC_WINLOGO 32517
1144 #if defined (__CYGWIN32__) && CYGWIN_VERSION_DLL_MAJOR < 21
1145 #define LR_SHARED 0x8000
1149 static const resource_t bitmap_table[] =
1152 { "close", OBM_CLOSE },
1153 { "uparrow", OBM_UPARROW },
1154 { "dnarrow", OBM_DNARROW },
1155 { "rgarrow", OBM_RGARROW },
1156 { "lfarrow", OBM_LFARROW },
1157 { "reduce", OBM_REDUCE },
1158 { "zoom", OBM_ZOOM },
1159 { "restore", OBM_RESTORE },
1160 { "reduced", OBM_REDUCED },
1161 { "zoomd", OBM_ZOOMD },
1162 { "restored", OBM_RESTORED },
1163 { "uparrowd", OBM_UPARROWD },
1164 { "dnarrowd", OBM_DNARROWD },
1165 { "rgarrowd", OBM_RGARROWD },
1166 { "lfarrowd", OBM_LFARROWD },
1167 { "mnarrow", OBM_MNARROW },
1168 { "combo", OBM_COMBO },
1169 { "uparrowi", OBM_UPARROWI },
1170 { "dnarrowi", OBM_DNARROWI },
1171 { "rgarrowi", OBM_RGARROWI },
1172 { "lfarrowi", OBM_LFARROWI },
1173 { "size", OBM_SIZE },
1174 { "btsize", OBM_BTSIZE },
1175 { "check", OBM_CHECK },
1176 { "checkboxes", OBM_CHECKBOXES },
1177 { "btncorners" , OBM_BTNCORNERS },
1181 static const resource_t cursor_table[] =
1184 { "normal", OCR_NORMAL },
1185 { "ibeam", OCR_IBEAM },
1186 { "wait", OCR_WAIT },
1187 { "cross", OCR_CROSS },
1189 /* { "icon", OCR_ICON }, */
1190 { "sizenwse", OCR_SIZENWSE },
1191 { "sizenesw", OCR_SIZENESW },
1192 { "sizewe", OCR_SIZEWE },
1193 { "sizens", OCR_SIZENS },
1194 { "sizeall", OCR_SIZEALL },
1195 /* { "icour", OCR_ICOCUR }, */
1200 static const resource_t icon_table[] =
1203 { "sample", OIC_SAMPLE },
1204 { "hand", OIC_HAND },
1205 { "ques", OIC_QUES },
1206 { "bang", OIC_BANG },
1207 { "note", OIC_NOTE },
1208 { "winlogo", OIC_WINLOGO },
1212 static int resource_name_to_resource (Lisp_Object name, int type)
1214 const resource_t* res = (type == IMAGE_CURSOR ? cursor_table
1215 : type == IMAGE_ICON ? icon_table
1222 else if (!STRINGP (name))
1224 signal_simple_error ("invalid resource identifier", name);
1229 TO_EXTERNAL_FORMAT (LISP_STRING, name,
1230 C_STRING_ALLOCA, nm,
1232 if (!strcasecmp ((char*)res->name, nm))
1233 return res->resource_id;
1234 } while ((++res)->name);
1239 resource_symbol_to_type (Lisp_Object data)
1241 if (EQ (data, Qcursor))
1242 return IMAGE_CURSOR;
1243 else if (EQ (data, Qicon))
1245 else if (EQ (data, Qbitmap))
1246 return IMAGE_BITMAP;
1252 mswindows_resource_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1253 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1254 int dest_mask, Lisp_Object domain)
1256 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1257 unsigned int type = 0;
1258 HANDLE himage = NULL;
1260 HINSTANCE hinst = NULL;
1262 enum image_instance_type iitype;
1264 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1266 Lisp_Object file = find_keyword_in_vector (instantiator, Q_file);
1267 Lisp_Object resource_type = find_keyword_in_vector (instantiator,
1269 Lisp_Object resource_id = find_keyword_in_vector (instantiator,
1274 CHECK_MSGDI_DEVICE (device);
1276 type = resource_symbol_to_type (resource_type);
1278 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_CURSOR)
1279 iitype = IMAGE_POINTER;
1280 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1281 iitype = IMAGE_COLOR_PIXMAP;
1283 incompatible_image_types (instantiator, dest_mask,
1284 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
1286 /* mess with the keyword info we were provided with */
1290 TO_EXTERNAL_FORMAT (LISP_STRING, file,
1294 CYGWIN_WIN32_PATH (f, fname);
1299 if (NILP (resource_id))
1300 resid = (LPCTSTR)fname;
1303 hinst = LoadLibraryEx (fname, NULL,
1304 LOAD_LIBRARY_AS_DATAFILE);
1305 resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1309 TO_EXTERNAL_FORMAT (LISP_STRING, resource_id,
1310 C_STRING_ALLOCA, resid,
1314 else if (!(resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1316 signal_simple_error ("Invalid resource identifier", resource_id);
1318 /* load the image */
1319 if (!(himage = LoadImage (hinst, resid, type, 0, 0,
1320 LR_CREATEDIBSECTION | LR_DEFAULTSIZE |
1322 (!NILP (file) ? LR_LOADFROMFILE : 0))))
1324 signal_simple_error ("Cannot load image", instantiator);
1328 FreeLibrary (hinst);
1330 mswindows_initialize_dibitmap_image_instance (ii, 1, iitype);
1332 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = file;
1333 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii) =
1334 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CXCURSOR : SM_CXICON);
1335 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii) =
1336 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CYCURSOR : SM_CYICON);
1337 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
1338 init_image_instance_geometry (ii);
1340 /* hey, we've got an icon type thing so we can reverse engineer the
1342 if (type != IMAGE_BITMAP)
1344 GetIconInfo ((HICON)himage, &iconinfo);
1345 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = iconinfo.hbmColor;
1346 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = iconinfo.hbmMask;
1347 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), iconinfo.xHotspot);
1348 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), iconinfo.yHotspot);
1349 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = (HICON) himage;
1353 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = NULL;
1354 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = (HBITMAP) himage;
1355 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
1356 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
1357 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
1362 check_valid_resource_symbol (Lisp_Object data)
1364 CHECK_SYMBOL (data);
1365 if (!resource_symbol_to_type (data))
1366 signal_simple_error ("invalid resource type", data);
1370 check_valid_resource_id (Lisp_Object data)
1372 if (!resource_name_to_resource (data, IMAGE_CURSOR)
1374 !resource_name_to_resource (data, IMAGE_ICON)
1376 !resource_name_to_resource (data, IMAGE_BITMAP))
1377 signal_simple_error ("invalid resource identifier", data);
1380 /**********************************************************************
1382 **********************************************************************/
1383 #ifndef HAVE_X_WINDOWS
1384 /* $XConsortium: RdBitF.c,v 1.10 94/04/17 20:16:13 kaleb Exp $ */
1388 Copyright (c) 1988 X Consortium
1390 Permission is hereby granted, free of charge, to any person obtaining a copy
1391 of this software and associated documentation files (the "Software"), to deal
1392 in the Software without restriction, including without limitation the rights
1393 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1394 copies of the Software, and to permit persons to whom the Software is
1395 furnished to do so, subject to the following conditions:
1397 The above copyright notice and this permission notice shall be included in
1398 all copies or substantial portions of the Software.
1400 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1401 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1402 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1403 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1404 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1405 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1407 Except as contained in this notice, the name of the X Consortium shall not be
1408 used in advertising or otherwise to promote the sale, use or other dealings
1409 in this Software without prior written authorization from the X Consortium.
1414 * This file contains miscellaneous utility routines and is not part of the
1417 * Public entry points:
1419 * XmuReadBitmapData read data from FILE descriptor
1420 * XmuReadBitmapDataFromFile read X10 or X11 format bitmap files
1423 * Note that this file and ../X/XRdBitF.c look very similar.... Keep them
1424 * that way (but don't use common source code so that people can have one
1425 * without the other).
1430 * Based on an optimized version provided by Jim Becker, August 5, 1988.
1432 #ifndef BitmapSuccess
1433 #define BitmapSuccess 0
1434 #define BitmapOpenFailed 1
1435 #define BitmapFileInvalid 2
1436 #define BitmapNoMemory 3
1438 #define MAX_SIZE 255
1440 /* shared data for the image read/parse logic */
1441 static short hexTable[256]; /* conversion value */
1442 static int initialized = FALSE; /* easier to fill in at run time */
1445 * Table index for the hex values. Initialized once, first time.
1446 * Used for translation value or delimiter significance lookup.
1452 * We build the table at run time for several reasons:
1454 * 1. portable to non-ASCII machines.
1455 * 2. still reentrant since we set the init flag after setting table.
1456 * 3. easier to extend.
1457 * 4. less prone to bugs.
1459 hexTable['0'] = 0; hexTable['1'] = 1;
1460 hexTable['2'] = 2; hexTable['3'] = 3;
1461 hexTable['4'] = 4; hexTable['5'] = 5;
1462 hexTable['6'] = 6; hexTable['7'] = 7;
1463 hexTable['8'] = 8; hexTable['9'] = 9;
1464 hexTable['A'] = 10; hexTable['B'] = 11;
1465 hexTable['C'] = 12; hexTable['D'] = 13;
1466 hexTable['E'] = 14; hexTable['F'] = 15;
1467 hexTable['a'] = 10; hexTable['b'] = 11;
1468 hexTable['c'] = 12; hexTable['d'] = 13;
1469 hexTable['e'] = 14; hexTable['f'] = 15;
1471 /* delimiters of significance are flagged w/ negative value */
1472 hexTable[' '] = -1; hexTable[','] = -1;
1473 hexTable['}'] = -1; hexTable['\n'] = -1;
1474 hexTable['\t'] = -1;
1480 * read next hex value in the input stream, return -1 if EOF
1483 NextInt (FILE *fstream)
1490 /* loop, accumulate hex value until find delimiter */
1491 /* skip any initial delimiters found in read stream */
1499 /* trim high bits, check type and accumulate */
1501 if (isascii(ch) && isxdigit(ch)) {
1502 value = (value << 4) + hexTable[ch];
1504 } else if ((hexTable[ch]) < 0 && gotone)
1513 * The data returned by the following routine is always in left-most byte
1514 * first and left-most bit first. If it doesn't return BitmapSuccess then
1515 * its arguments won't have been touched. This routine should look as much
1516 * like the Xlib routine XReadBitmapfile as possible.
1518 int read_bitmap_data (FILE* fstream, unsigned int *width,
1519 unsigned int *height, unsigned char **datap,
1520 int *x_hot, int *y_hot)
1522 unsigned char *data = NULL; /* working variable */
1523 char line[MAX_SIZE]; /* input line from file */
1524 int size; /* number of bytes of data */
1525 char name_and_type[MAX_SIZE]; /* an input line */
1526 char *type; /* for parsing */
1527 int value; /* from an input line */
1528 int version10p; /* boolean, old format */
1529 int padding; /* to handle alignment */
1530 int bytes_per_line; /* per scanline of data */
1531 unsigned int ww = 0; /* width */
1532 unsigned int hh = 0; /* height */
1533 int hx = -1; /* x hotspot */
1534 int hy = -1; /* y hotspot */
1536 #define Xmalloc(size) malloc(size)
1538 /* first time initialization */
1539 if (initialized == FALSE) initHexTable();
1541 /* error cleanup and return macro */
1542 #define RETURN(code) { if (data) free (data); return code; }
1544 while (fgets(line, MAX_SIZE, fstream)) {
1545 if (strlen(line) == MAX_SIZE-1) {
1546 RETURN (BitmapFileInvalid);
1548 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
1549 if (!(type = strrchr(name_and_type, '_')))
1550 type = name_and_type;
1554 if (!strcmp("width", type))
1555 ww = (unsigned int) value;
1556 if (!strcmp("height", type))
1557 hh = (unsigned int) value;
1558 if (!strcmp("hot", type)) {
1559 if (type-- == name_and_type || type-- == name_and_type)
1561 if (!strcmp("x_hot", type))
1563 if (!strcmp("y_hot", type))
1569 if (sscanf(line, "static short %s = {", name_and_type) == 1)
1571 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
1573 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
1578 if (!(type = strrchr(name_and_type, '_')))
1579 type = name_and_type;
1583 if (strcmp("bits[]", type))
1587 RETURN (BitmapFileInvalid);
1589 if ((ww % 16) && ((ww % 16) < 9) && version10p)
1594 bytes_per_line = (ww+7)/8 + padding;
1596 size = bytes_per_line * hh;
1597 data = (unsigned char *) Xmalloc ((unsigned int) size);
1599 RETURN (BitmapNoMemory);
1605 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
1606 if ((value = NextInt(fstream)) < 0)
1607 RETURN (BitmapFileInvalid);
1609 if (!padding || ((bytes+2) % bytes_per_line))
1610 *(ptr++) = value >> 8;
1616 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
1617 if ((value = NextInt(fstream)) < 0)
1618 RETURN (BitmapFileInvalid);
1626 RETURN (BitmapFileInvalid);
1633 if (x_hot) *x_hot = hx;
1634 if (y_hot) *y_hot = hy;
1636 RETURN (BitmapSuccess);
1640 int read_bitmap_data_from_file (const char *filename, unsigned int *width,
1641 unsigned int *height, unsigned char **datap,
1642 int *x_hot, int *y_hot)
1647 if ((fstream = fopen (filename, "r")) == NULL) {
1648 return BitmapOpenFailed;
1650 status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot);
1654 #endif /* HAVE_X_WINDOWS */
1656 /* this table flips four bits around. */
1657 static int flip_table[] =
1659 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
1662 /* the bitmap data comes in the following format: Widths are padded to
1663 a multiple of 8. Scan lines are stored in increasing byte order
1664 from left to right, little-endian within a byte. 0 = white, 1 =
1665 black. It must be converted to the following format: Widths are
1666 padded to a multiple of 16. Scan lines are stored in increasing
1667 byte order from left to right, big-endian within a byte. 0 =
1668 black, 1 = white. */
1670 xbm_create_bitmap_from_data (HDC hdc, char *data,
1671 unsigned int width, unsigned int height,
1672 int mask, COLORREF fg, COLORREF bg)
1674 int old_width = (width + 7)/8;
1675 int new_width = BPLINE (2*((width + 15)/16));
1676 unsigned char *offset;
1678 unsigned char *new_data, *new_offset;
1680 BITMAPINFO *bmp_info =
1681 (BITMAPINFO*) xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
1687 new_data = (unsigned char *) xmalloc_and_zero (height * new_width);
1695 for (i=0; i<height; i++)
1697 offset = data + i*old_width;
1698 new_offset = new_data + i*new_width;
1700 for (j=0; j<old_width; j++)
1702 int byte = offset[j];
1703 new_offset[j] = ~ (unsigned char)
1704 ((flip_table[byte & 0xf] << 4) + flip_table[byte >> 4]);
1708 /* if we want a mask invert the bits */
1711 new_offset = &new_data[height * new_width];
1712 while (new_offset-- != new_data)
1714 *new_offset ^= 0xff;
1718 bmp_info->bmiHeader.biWidth=width;
1719 bmp_info->bmiHeader.biHeight=-(LONG)height;
1720 bmp_info->bmiHeader.biPlanes=1;
1721 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
1722 bmp_info->bmiHeader.biBitCount=1;
1723 bmp_info->bmiHeader.biCompression=BI_RGB;
1724 bmp_info->bmiHeader.biClrUsed = 2;
1725 bmp_info->bmiHeader.biClrImportant = 2;
1726 bmp_info->bmiHeader.biSizeImage = height * new_width;
1727 bmp_info->bmiColors[0].rgbRed = GetRValue (fg);
1728 bmp_info->bmiColors[0].rgbGreen = GetGValue (fg);
1729 bmp_info->bmiColors[0].rgbBlue = GetBValue (fg);
1730 bmp_info->bmiColors[0].rgbReserved = 0;
1731 bmp_info->bmiColors[1].rgbRed = GetRValue (bg);
1732 bmp_info->bmiColors[1].rgbGreen = GetGValue (bg);
1733 bmp_info->bmiColors[1].rgbBlue = GetBValue (bg);
1734 bmp_info->bmiColors[1].rgbReserved = 0;
1736 bitmap = CreateDIBSection (hdc,
1744 if (!bitmap || !bmp_buf)
1750 /* copy in the actual bitmap */
1751 memcpy (bmp_buf, new_data, height * new_width);
1757 /* Given inline data for a mono pixmap, initialize the given
1758 image instance accordingly. */
1761 init_image_instance_from_xbm_inline (Lisp_Image_Instance *ii,
1762 int width, int height,
1763 /* Note that data is in ext-format! */
1765 Lisp_Object instantiator,
1766 Lisp_Object pointer_fg,
1767 Lisp_Object pointer_bg,
1770 Lisp_Object mask_filename)
1772 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1773 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
1774 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
1775 enum image_instance_type type;
1776 COLORREF black = PALETTERGB (0,0,0);
1777 COLORREF white = PALETTERGB (255,255,255);
1780 CHECK_MSGDI_DEVICE (device);
1782 hdc = get_device_compdc (XDEVICE (device));
1784 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
1785 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
1787 if (!NILP (foreground) || !NILP (background))
1788 type = IMAGE_COLOR_PIXMAP;
1790 type = IMAGE_MONO_PIXMAP;
1792 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
1793 type = IMAGE_MONO_PIXMAP;
1794 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1795 type = IMAGE_COLOR_PIXMAP;
1796 else if (dest_mask & IMAGE_POINTER_MASK)
1797 type = IMAGE_POINTER;
1799 incompatible_image_types (instantiator, dest_mask,
1800 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
1801 | IMAGE_POINTER_MASK);
1803 mswindows_initialize_dibitmap_image_instance (ii, 1, type);
1805 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
1806 find_keyword_in_vector (instantiator, Q_file);
1807 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii) = width;
1808 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii) = height;
1809 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
1810 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
1811 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
1812 init_image_instance_geometry (ii);
1814 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = mask ? mask :
1815 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1816 TRUE, black, white);
1820 case IMAGE_MONO_PIXMAP:
1821 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1822 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1823 FALSE, black, black);
1826 case IMAGE_COLOR_PIXMAP:
1828 COLORREF fg = black;
1829 COLORREF bg = white;
1831 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
1833 Fmake_color_instance (foreground, device,
1834 encode_error_behavior_flag (ERROR_ME));
1836 if (COLOR_INSTANCEP (foreground))
1837 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
1839 if (!NILP (background) && !COLOR_INSTANCEP (background))
1841 Fmake_color_instance (background, device,
1842 encode_error_behavior_flag (ERROR_ME));
1844 if (COLOR_INSTANCEP (background))
1845 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
1847 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
1848 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
1850 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1851 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1858 COLORREF fg = black;
1859 COLORREF bg = white;
1861 if (NILP (foreground))
1862 foreground = pointer_fg;
1863 if (NILP (background))
1864 background = pointer_bg;
1866 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
1867 find_keyword_in_vector (instantiator, Q_hotspot_x);
1868 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
1869 find_keyword_in_vector (instantiator, Q_hotspot_y);
1870 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
1871 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
1872 if (COLOR_INSTANCEP (foreground))
1873 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
1874 if (COLOR_INSTANCEP (background))
1875 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
1877 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
1878 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
1880 mswindows_initialize_image_instance_icon (ii, TRUE);
1890 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
1891 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1892 int dest_mask, int width, int height,
1893 /* Note that data is in ext-format! */
1896 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
1897 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
1898 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1899 HDC hdc = get_device_compdc (XDEVICE (IMAGE_INSTANCE_DEVICE (ii)));
1902 if (!NILP (mask_data))
1904 const char *ext_data;
1906 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (mask_data))),
1907 C_STRING_ALLOCA, ext_data,
1909 mask = xbm_create_bitmap_from_data (hdc,
1910 (unsigned char *) ext_data,
1911 XINT (XCAR (mask_data)),
1912 XINT (XCAR (XCDR (mask_data))),
1915 PALETTERGB (255,255,255));
1918 init_image_instance_from_xbm_inline (ii, width, height, bits,
1919 instantiator, pointer_fg, pointer_bg,
1920 dest_mask, mask, mask_file);
1923 /* Instantiate method for XBM's. */
1926 mswindows_xbm_instantiate (Lisp_Object image_instance,
1927 Lisp_Object instantiator,
1928 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1929 int dest_mask, Lisp_Object domain)
1931 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1932 const char *ext_data;
1934 assert (!NILP (data));
1936 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (data))),
1937 C_STRING_ALLOCA, ext_data,
1940 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
1941 pointer_bg, dest_mask, XINT (XCAR (data)),
1942 XINT (XCAR (XCDR (data))), ext_data);
1946 /**********************************************************************
1948 **********************************************************************/
1950 /* This is about to get redefined! */
1953 /* We have to define SYSV32 so that compface.h includes string.h
1954 instead of strings.h. */
1959 #include <compface.h>
1963 /* JMP_BUF cannot be used here because if it doesn't get defined
1964 to jmp_buf we end up with a conflicting type error with the
1965 definition in compface.h */
1966 extern jmp_buf comp_env;
1970 mswindows_xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1971 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1972 int dest_mask, Lisp_Object domain)
1974 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1976 char *p, *bits, *bp;
1977 const char * volatile emsg = 0;
1978 const char * volatile dstring;
1980 assert (!NILP (data));
1982 TO_EXTERNAL_FORMAT (LISP_STRING, data,
1983 C_STRING_ALLOCA, dstring,
1986 if ((p = strchr (dstring, ':')))
1991 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
1992 if (!(stattis = setjmp (comp_env)))
1994 UnCompAll ((char *) dstring);
2001 emsg = "uncompface: internal error";
2004 emsg = "uncompface: insufficient or invalid data";
2007 emsg = "uncompface: excess data ignored";
2012 signal_simple_error_2 (emsg, data, Qimage);
2014 bp = bits = (char *) alloca (PIXELS / 8);
2016 /* the compface library exports char F[], which uses a single byte per
2017 pixel to represent a 48x48 bitmap. Yuck. */
2018 for (i = 0, p = F; i < (PIXELS / 8); ++i)
2021 /* reverse the bit order of each byte... */
2022 for (b = n = 0; b < 8; ++b)
2029 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
2030 pointer_bg, dest_mask, 48, 48, bits);
2032 #endif /* HAVE_XFACE */
2035 /************************************************************************/
2036 /* image instance methods */
2037 /************************************************************************/
2040 mswindows_print_image_instance (Lisp_Image_Instance *p,
2041 Lisp_Object printcharfun,
2046 switch (IMAGE_INSTANCE_TYPE (p))
2048 case IMAGE_MONO_PIXMAP:
2049 case IMAGE_COLOR_PIXMAP:
2051 sprintf (buf, " (0x%lx",
2052 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
2053 write_c_string (buf, printcharfun);
2054 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
2056 sprintf (buf, "/0x%lx",
2057 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
2058 write_c_string (buf, printcharfun);
2060 write_c_string (")", printcharfun);
2068 #ifdef DEBUG_WIDGETS
2069 extern int debug_widget_instances;
2073 mswindows_finalize_image_instance (Lisp_Image_Instance *p)
2075 if (DEVICE_LIVE_P (XDEVICE (p->device)))
2077 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET
2079 IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
2081 #ifdef DEBUG_WIDGETS
2082 debug_widget_instances--;
2083 stderr_out ("widget destroyed, %d left\n", debug_widget_instances);
2085 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
2087 DestroyWindow (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p));
2088 DestroyWindow (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p));
2089 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0;
2095 if (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p))
2096 disable_glyph_animated_timeout (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p));
2098 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (p))
2100 for (i = 0; i < IMAGE_INSTANCE_PIXMAP_MAXSLICE (p); i++)
2102 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (p, i))
2103 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (p, i));
2104 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (p, i) = 0;
2106 xfree (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (p));
2107 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (p) = 0;
2109 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
2110 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
2111 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
2112 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
2113 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
2114 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
2125 /************************************************************************/
2126 /* subwindow and widget support */
2127 /************************************************************************/
2130 mswindows_widget_hfont (Lisp_Image_Instance *p,
2133 Lisp_Object face = IMAGE_INSTANCE_WIDGET_FACE (p);
2134 int under = FACE_UNDERLINE_P (face, domain);
2135 int strike = FACE_STRIKETHRU_P (face, domain);
2136 Lisp_Object font = query_string_font (IMAGE_INSTANCE_WIDGET_TEXT (p),
2139 return mswindows_get_hfont (XFONT_INSTANCE (font), under, strike);
2142 /* unmap the image if it is a widget. This is used by redisplay via
2143 redisplay_unmap_subwindows */
2145 mswindows_unmap_subwindow (Lisp_Image_Instance *p)
2147 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
2149 SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p),
2152 SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE
2153 | SWP_NOSENDCHANGING);
2154 if (GetFocus() == WIDGET_INSTANCE_MSWINDOWS_HANDLE (p))
2155 SetFocus (GetParent (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p)));
2159 /* map the subwindow. This is used by redisplay via
2160 redisplay_output_subwindow */
2162 mswindows_map_subwindow (Lisp_Image_Instance *p, int x, int y,
2163 struct display_glyph_area* dga)
2165 /* move the window before mapping it ... */
2166 SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p),
2168 x, y, dga->width, dga->height,
2170 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
2171 /* ... adjust the child ... */
2172 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2174 -dga->xoffset, -dga->yoffset, 0, 0,
2175 SWP_NOZORDER | SWP_NOSIZE
2176 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
2177 /* ... now map it - we are not allowed to move it at the same time. */
2178 SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p),
2181 SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE
2182 | SWP_SHOWWINDOW | SWP_NOCOPYBITS
2183 | SWP_NOSENDCHANGING);
2186 /* resize the subwindow instance */
2188 mswindows_resize_subwindow (Lisp_Image_Instance* ii, int w, int h)
2190 /* Set the size of the control .... */
2191 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2194 SWP_NOZORDER | SWP_NOMOVE
2195 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
2198 /* Simply resize the window here. */
2200 mswindows_update_subwindow (Lisp_Image_Instance *p)
2202 mswindows_resize_subwindow (p,
2203 IMAGE_INSTANCE_WIDTH (p),
2204 IMAGE_INSTANCE_HEIGHT (p));
2207 /* when you click on a widget you may activate another widget this
2208 needs to be checked and all appropriate widgets updated */
2210 mswindows_update_widget (Lisp_Image_Instance *p)
2212 /* Possibly update the face font and colors. */
2213 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (p)
2215 XFRAME (IMAGE_INSTANCE_SUBWINDOW_FRAME (p))->faces_changed
2217 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
2219 /* set the widget font from the widget face */
2220 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2222 (WPARAM) mswindows_widget_hfont
2223 (p, IMAGE_INSTANCE_SUBWINDOW_FRAME (p)),
2224 MAKELPARAM (TRUE, 0));
2226 /* Possibly update the dimensions. */
2227 if (IMAGE_INSTANCE_SIZE_CHANGED (p))
2229 mswindows_resize_subwindow (p,
2230 IMAGE_INSTANCE_WIDTH (p),
2231 IMAGE_INSTANCE_HEIGHT (p));
2233 /* Possibly update the text in the widget. */
2234 if (IMAGE_INSTANCE_TEXT_CHANGED (p))
2237 TO_EXTERNAL_FORMAT (LISP_STRING, IMAGE_INSTANCE_WIDGET_TEXT (p),
2238 C_STRING_ALLOCA, lparam,
2240 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
2241 WM_SETTEXT, 0, (LPARAM)lparam);
2245 /* register widgets into our hastable so that we can cope with the
2246 callbacks. The hashtable is weak so deregistration is handled
2249 mswindows_register_gui_item (Lisp_Object image_instance,
2250 Lisp_Object gui, Lisp_Object domain)
2252 Lisp_Object frame = FW_FRAME (domain);
2253 struct frame* f = XFRAME (frame);
2254 int id = gui_item_id_hash (FRAME_MSWINDOWS_WIDGET_HASH_TABLE2 (f),
2257 Fputhash (make_int (id), image_instance,
2258 FRAME_MSWINDOWS_WIDGET_HASH_TABLE1 (f));
2259 Fputhash (make_int (id), XGUI_ITEM (gui)->callback,
2260 FRAME_MSWINDOWS_WIDGET_HASH_TABLE2 (f));
2261 Fputhash (make_int (id), XGUI_ITEM (gui)->callback_ex,
2262 FRAME_MSWINDOWS_WIDGET_HASH_TABLE3 (f));
2267 mswindows_register_widget_instance (Lisp_Object instance, Lisp_Object domain)
2269 return mswindows_register_gui_item (instance,
2270 XIMAGE_INSTANCE_WIDGET_ITEM (instance),
2275 mswindows_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2276 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2277 int dest_mask, Lisp_Object domain)
2279 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2280 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
2281 Lisp_Object frame = FW_FRAME (domain);
2284 CHECK_MSWINDOWS_DEVICE (device);
2286 /* have to set the type this late in case there is no device
2287 instantiation for a widget */
2288 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
2289 /* Allocate space for the clip window */
2290 ii->data = xnew_and_zero (struct mswindows_subwindow_data);
2292 if ((IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii)
2295 XEMACS_CONTROL_CLASS,
2297 WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD,
2298 0, /* starting x position */
2299 0, /* starting y position */
2300 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2301 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2303 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2305 NULL, /* must be null for this class */
2307 signal_simple_error ("window creation failed with code",
2308 make_int (GetLastError()));
2310 wnd = CreateWindow( "STATIC",
2313 0, /* starting x position */
2314 0, /* starting y position */
2315 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2316 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2317 IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii),
2320 GetWindowLong (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2324 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2325 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
2329 mswindows_image_instance_equal (Lisp_Image_Instance *p1,
2330 Lisp_Image_Instance *p2, int depth)
2332 switch (IMAGE_INSTANCE_TYPE (p1))
2334 case IMAGE_MONO_PIXMAP:
2335 case IMAGE_COLOR_PIXMAP:
2337 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
2338 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
2349 static unsigned long
2350 mswindows_image_instance_hash (Lisp_Image_Instance *p, int depth)
2352 switch (IMAGE_INSTANCE_TYPE (p))
2354 case IMAGE_MONO_PIXMAP:
2355 case IMAGE_COLOR_PIXMAP:
2357 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
2364 /* Set all the slots in an image instance structure to reasonable
2365 default values. This is used somewhere within an instantiate
2366 method. It is assumed that the device slot within the image
2367 instance is already set -- this is the case when instantiate
2368 methods are called. */
2371 mswindows_initialize_dibitmap_image_instance (Lisp_Image_Instance *ii,
2373 enum image_instance_type type)
2375 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
2376 IMAGE_INSTANCE_TYPE (ii) = type;
2377 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
2378 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
2379 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
2380 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
2381 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
2382 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
2383 IMAGE_INSTANCE_PIXMAP_MAXSLICE (ii) = slices;
2384 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (ii) =
2385 xnew_array_and_zero (HBITMAP, slices);
2391 /************************************************************************/
2393 /************************************************************************/
2395 mswindows_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2396 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2397 int dest_mask, Lisp_Object domain,
2398 const char* class, int flags, int exflags)
2400 /* this function can call lisp */
2401 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2402 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), style;
2403 Lisp_Object frame = FW_FRAME (domain);
2407 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
2408 Lisp_Gui_Item* pgui = XGUI_ITEM (gui);
2410 CHECK_MSWINDOWS_DEVICE (device);
2412 if (!gui_item_active_p (gui))
2413 flags |= WS_DISABLED;
2415 style = pgui->style;
2417 if (!NILP (pgui->callback) || !NILP (pgui->callback_ex))
2419 id = mswindows_register_widget_instance (image_instance, domain);
2422 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
2423 TO_EXTERNAL_FORMAT (LISP_STRING, IMAGE_INSTANCE_WIDGET_TEXT (ii),
2424 C_STRING_ALLOCA, nm,
2427 /* allocate space for the clip window and then allocate the clip window */
2428 ii->data = xnew_and_zero (struct mswindows_subwindow_data);
2430 if ((IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii)
2432 WS_EX_CONTROLPARENT, /* EX flags */
2433 XEMACS_CONTROL_CLASS,
2435 WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD,
2436 0, /* starting x position */
2437 0, /* starting y position */
2438 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2439 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2441 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2442 (HMENU)id, /* No menu */
2443 NULL, /* must be null for this class */
2445 signal_simple_error ("window creation failed with code",
2446 make_int (GetLastError()));
2448 if ((wnd = CreateWindowEx(
2449 exflags /* | WS_EX_NOPARENTNOTIFY*/,
2452 flags | WS_CHILD | WS_VISIBLE,
2453 0, /* starting x position */
2454 0, /* starting y position */
2455 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2456 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2458 IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii),
2459 (HMENU)id, /* No menu */
2462 (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2465 signal_simple_error ("window creation failed with code",
2466 make_int (GetLastError()));
2468 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
2469 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2470 /* set the widget font from the widget face */
2471 SendMessage (wnd, WM_SETFONT,
2472 (WPARAM) mswindows_widget_hfont (ii, domain),
2473 MAKELPARAM (TRUE, 0));
2476 /* Instantiate a button widget. Unfortunately instantiated widgets are
2477 particular to a frame since they need to have a parent. It's not
2478 like images where you just select the image into the context you
2479 want to display it in and BitBlt it. So image instances can have a
2480 many-to-one relationship with things you see, whereas widgets can
2481 only be one-to-one (i.e. per frame) */
2483 mswindows_button_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2484 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2485 int dest_mask, Lisp_Object domain)
2487 /* This function can call lisp */
2488 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2490 int flags = WS_TABSTOP;/* BS_NOTIFY #### is needed to get exotic feedback
2491 only. Since we seem to want nothing beyond BN_CLICK,
2492 the style is perhaps not necessary -- kkm */
2494 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
2495 Lisp_Gui_Item* pgui = XGUI_ITEM (gui);
2496 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image);
2500 if (!IMAGE_INSTANCEP (glyph))
2501 glyph = glyph_image_instance (glyph, domain, ERROR_ME, 1);
2503 if (IMAGE_INSTANCEP (glyph))
2504 flags |= XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2505 BS_BITMAP : BS_ICON;
2508 style = pgui->style;
2510 /* #### consider using the default face for radio and toggle
2512 if (EQ (style, Qradio))
2514 flags |= BS_RADIOBUTTON;
2516 else if (EQ (style, Qtoggle))
2518 flags |= BS_AUTOCHECKBOX;
2522 flags |= BS_DEFPUSHBUTTON;
2525 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2526 pointer_bg, dest_mask, domain, "BUTTON",
2529 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2530 /* set the checked state */
2531 if (gui_item_selected_p (gui))
2532 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
2534 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
2535 /* add the image if one was given */
2536 if (!NILP (glyph) && IMAGE_INSTANCEP (glyph)
2538 IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (glyph)))
2540 SendMessage (wnd, BM_SETIMAGE,
2541 (WPARAM) (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2542 IMAGE_BITMAP : IMAGE_ICON),
2543 (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ?
2544 (LPARAM) XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) :
2545 (LPARAM) XIMAGE_INSTANCE_MSWINDOWS_ICON (glyph)));
2549 /* Update the state of a button. */
2551 mswindows_button_update (Lisp_Object image_instance)
2553 /* This function can GC if IN_REDISPLAY is false. */
2554 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2556 /* buttons checked or otherwise */
2557 if (gui_item_selected_p (IMAGE_INSTANCE_WIDGET_ITEM (ii)))
2558 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2559 BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
2561 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2562 BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
2565 /* instantiate an edit control */
2567 mswindows_edit_field_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2568 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2569 int dest_mask, Lisp_Object domain)
2571 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2572 pointer_bg, dest_mask, domain, "EDIT",
2573 ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP
2574 | WS_BORDER, WS_EX_CLIENTEDGE);
2577 /* instantiate a progress gauge */
2579 mswindows_progress_gauge_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2580 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2581 int dest_mask, Lisp_Object domain)
2584 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2585 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2586 pointer_bg, dest_mask, domain, PROGRESS_CLASS,
2587 WS_BORDER | PBS_SMOOTH, WS_EX_CLIENTEDGE);
2588 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2589 /* set the colors */
2590 #ifdef PBS_SETBKCOLOR
2591 SendMessage (wnd, PBS_SETBKCOLOR, 0,
2592 (LPARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR
2595 (XIMAGE_INSTANCE_WIDGET_FACE (ii),
2596 XIMAGE_INSTANCE_SUBWINDOW_FRAME (ii))))));
2598 #ifdef PBS_SETBARCOLOR
2599 SendMessage (wnd, PBS_SETBARCOLOR, 0,
2600 (L:PARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR
2603 (XIMAGE_INSTANCE_WIDGET_FACE (ii),
2604 XIMAGE_INSTANCE_SUBWINDOW_FRAME (ii))))));
2608 /* instantiate a tree view widget */
2609 static HTREEITEM add_tree_item (Lisp_Object image_instance,
2610 HWND wnd, HTREEITEM parent, Lisp_Object item,
2611 int children, Lisp_Object domain)
2613 TV_INSERTSTRUCT tvitem;
2616 tvitem.hParent = parent;
2617 tvitem.hInsertAfter = TVI_LAST;
2618 tvitem.item.mask = TVIF_TEXT | TVIF_CHILDREN;
2619 tvitem.item.cChildren = children;
2621 if (GUI_ITEMP (item))
2623 tvitem.item.lParam = mswindows_register_gui_item (image_instance,
2625 tvitem.item.mask |= TVIF_PARAM;
2626 TO_EXTERNAL_FORMAT (LISP_STRING, XGUI_ITEM (item)->name,
2627 C_STRING_ALLOCA, tvitem.item.pszText,
2631 TO_EXTERNAL_FORMAT (LISP_STRING, item,
2632 C_STRING_ALLOCA, tvitem.item.pszText,
2635 tvitem.item.cchTextMax = strlen (tvitem.item.pszText);
2637 if ((ret = (HTREEITEM)SendMessage (wnd, TVM_INSERTITEM,
2638 0, (LPARAM)&tvitem)) == 0)
2639 signal_simple_error ("error adding tree view entry", item);
2644 static void add_tree_item_list (Lisp_Object image_instance,
2645 HWND wnd, HTREEITEM parent, Lisp_Object list,
2650 /* get the first item */
2651 parent = add_tree_item (image_instance, wnd, parent, XCAR (list), TRUE, domain);
2652 /* recursively add items to the tree view */
2653 LIST_LOOP (rest, XCDR (list))
2655 if (LISTP (XCAR (rest)))
2656 add_tree_item_list (image_instance, wnd, parent, XCAR (rest), domain);
2658 add_tree_item (image_instance, wnd, parent, XCAR (rest), FALSE, domain);
2663 mswindows_tree_view_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2664 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2665 int dest_mask, Lisp_Object domain)
2670 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2671 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2672 pointer_bg, dest_mask, domain, WC_TREEVIEW,
2673 WS_TABSTOP | WS_BORDER | PBS_SMOOTH
2674 | TVS_HASLINES | TVS_HASBUTTONS,
2677 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2680 parent = add_tree_item (image_instance, wnd, NULL,
2681 XCAR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)),
2684 /* recursively add items to the tree view */
2685 /* add items to the tab */
2686 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
2688 if (LISTP (XCAR (rest)))
2689 add_tree_item_list (image_instance, wnd, parent, XCAR (rest), domain);
2691 add_tree_item (image_instance, wnd, parent, XCAR (rest), FALSE, domain);
2695 /* instantiate a tab control */
2696 static TC_ITEM* add_tab_item (Lisp_Object image_instance,
2697 HWND wnd, Lisp_Object item,
2698 Lisp_Object domain, int i)
2700 TC_ITEM tvitem, *ret;
2702 tvitem.mask = TCIF_TEXT;
2704 if (GUI_ITEMP (item))
2706 tvitem.lParam = mswindows_register_gui_item (image_instance,
2708 tvitem.mask |= TCIF_PARAM;
2709 TO_EXTERNAL_FORMAT (LISP_STRING, XGUI_ITEM (item)->name,
2710 C_STRING_ALLOCA, tvitem.pszText,
2715 CHECK_STRING (item);
2716 TO_EXTERNAL_FORMAT (LISP_STRING, item,
2717 C_STRING_ALLOCA, tvitem.pszText,
2721 tvitem.cchTextMax = strlen (tvitem.pszText);
2723 if ((ret = (TC_ITEM*)SendMessage (wnd, TCM_INSERTITEM,
2724 i, (LPARAM)&tvitem)) < 0)
2725 signal_simple_error ("error adding tab entry", item);
2731 mswindows_tab_control_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2732 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2733 int dest_mask, Lisp_Object domain)
2735 /* This function can call lisp */
2738 int i = 0, selected = 0;
2739 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2740 Lisp_Object orient = find_keyword_in_vector (instantiator, Q_orientation);
2741 unsigned int flags = WS_TABSTOP;
2743 if (EQ (orient, Qleft) || EQ (orient, Qright))
2745 flags |= TCS_VERTICAL | TCS_MULTILINE;
2747 if (EQ (orient, Qright) || EQ (orient, Qbottom))
2749 flags |= TCS_BOTTOM;
2752 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2753 pointer_bg, dest_mask, domain, WC_TABCONTROL,
2754 /* borders don't suit tabs so well */
2756 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2757 /* add items to the tab */
2758 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
2760 add_tab_item (image_instance, wnd, XCAR (rest), domain, i);
2761 if (gui_item_selected_p (XCAR (rest)))
2765 SendMessage (wnd, TCM_SETCURSEL, selected, 0);
2768 /* set the properties of a tab control */
2770 mswindows_tab_control_update (Lisp_Object image_instance)
2772 /* This function can GC if IN_REDISPLAY is false. */
2773 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2775 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
2777 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2778 int i = 0, selected = 0;
2781 /* delete the pre-existing items */
2782 SendMessage (wnd, TCM_DELETEALLITEMS, 0, 0);
2784 /* add items to the tab */
2785 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)))
2787 add_tab_item (image_instance, wnd, XCAR (rest),
2788 IMAGE_INSTANCE_SUBWINDOW_FRAME (ii), i);
2789 if (gui_item_selected_p (XCAR (rest)))
2793 SendMessage (wnd, TCM_SETCURSEL, selected, 0);
2797 /* instantiate a static control possible for putting other things in */
2799 mswindows_label_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2800 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2801 int dest_mask, Lisp_Object domain)
2803 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2804 pointer_bg, dest_mask, domain, "STATIC",
2805 0, WS_EX_STATICEDGE);
2808 /* instantiate a scrollbar control */
2810 mswindows_scrollbar_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2811 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2812 int dest_mask, Lisp_Object domain)
2814 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2815 pointer_bg, dest_mask, domain, "SCROLLBAR",
2816 WS_TABSTOP, WS_EX_CLIENTEDGE);
2819 /* instantiate a combo control */
2821 mswindows_combo_box_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2822 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2823 int dest_mask, Lisp_Object domain)
2825 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2828 Lisp_Object data = Fplist_get (find_keyword_in_vector (instantiator, Q_properties),
2832 /* Maybe ought to generalise this more but it may be very windows
2833 specific. In windows the window height of a combo box is the
2834 height when the combo box is open. Thus we need to set the height
2835 before creating the window and then reset it to a single line
2836 after the window is created so that redisplay does the right
2838 widget_instantiate (image_instance, instantiator, pointer_fg,
2839 pointer_bg, dest_mask, domain);
2841 /* We now have everything right apart from the height. */
2842 default_face_font_info (domain, 0, 0, &height, 0, 0);
2843 GET_LIST_LENGTH (data, len);
2845 height = (height + WIDGET_BORDER_HEIGHT * 2 ) * len;
2846 IMAGE_INSTANCE_HEIGHT (ii) = height;
2848 /* Now create the widget. */
2849 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2850 pointer_bg, dest_mask, domain, "COMBOBOX",
2851 WS_BORDER | WS_TABSTOP | CBS_DROPDOWN
2853 | CBS_HASSTRINGS | WS_VSCROLL,
2855 /* Reset the height. layout will probably do this safely, but better make sure. */
2856 image_instance_layout (image_instance,
2857 IMAGE_UNSPECIFIED_GEOMETRY,
2858 IMAGE_UNSPECIFIED_GEOMETRY,
2861 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2862 /* add items to the combo box */
2863 SendMessage (wnd, CB_RESETCONTENT, 0, 0);
2864 LIST_LOOP (rest, Fplist_get (IMAGE_INSTANCE_WIDGET_PROPS (ii), Q_items, Qnil))
2867 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (rest),
2868 C_STRING_ALLOCA, lparam,
2870 if (SendMessage (wnd, CB_ADDSTRING, 0, (LPARAM)lparam) == CB_ERR)
2871 signal_simple_error ("error adding combo entries", instantiator);
2875 /* get properties of a control */
2877 mswindows_widget_property (Lisp_Object image_instance, Lisp_Object prop)
2879 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2880 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2881 /* get the text from a control */
2882 if (EQ (prop, Q_text))
2884 Extcount len = SendMessage (wnd, WM_GETTEXTLENGTH, 0, 0);
2885 Extbyte *buf = (Extbyte*) alloca (len+1);
2887 SendMessage (wnd, WM_GETTEXT, (WPARAM)len+1, (LPARAM) buf);
2888 return build_ext_string (buf, Qnative);
2893 /* get properties of a button */
2895 mswindows_button_property (Lisp_Object image_instance, Lisp_Object prop)
2897 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2898 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2899 /* check the state of a button */
2900 if (EQ (prop, Q_selected))
2902 if (SendMessage (wnd, BM_GETSTATE, 0, 0) & BST_CHECKED)
2910 /* get properties of a combo box */
2912 mswindows_combo_box_property (Lisp_Object image_instance, Lisp_Object prop)
2914 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2915 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2916 /* get the text from a control */
2917 if (EQ (prop, Q_text))
2919 long item = SendMessage (wnd, CB_GETCURSEL, 0, 0);
2920 Extcount len = SendMessage (wnd, CB_GETLBTEXTLEN, (WPARAM)item, 0);
2921 Extbyte* buf = (Extbyte*) alloca (len+1);
2922 SendMessage (wnd, CB_GETLBTEXT, (WPARAM)item, (LPARAM)buf);
2923 return build_ext_string (buf, Qnative);
2928 /* set the properties of a progres guage */
2930 mswindows_progress_gauge_update (Lisp_Object image_instance)
2932 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2934 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
2937 #ifdef ERROR_CHECK_GLYPHS
2938 assert (GUI_ITEMP (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)));
2940 val = XGUI_ITEM (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii))->value;
2941 #ifdef DEBUG_WIDGET_OUTPUT
2942 printf ("progress gauge displayed value on %p updated to %ld\n",
2943 WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2947 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2948 PBM_SETPOS, (WPARAM)XINT (val), 0);
2953 mswindows_control_wnd_proc (HWND hwnd, UINT msg,
2954 WPARAM wParam, LPARAM lParam)
2960 case WM_CTLCOLORBTN:
2961 case WM_CTLCOLORLISTBOX:
2962 case WM_CTLCOLOREDIT:
2963 case WM_CTLCOLORSTATIC:
2964 case WM_CTLCOLORSCROLLBAR:
2966 return mswindows_wnd_proc (GetParent (hwnd), msg, wParam, lParam);
2968 return DefWindowProc (hwnd, msg, wParam, lParam);
2972 #endif /* HAVE_WIDGETS */
2975 /************************************************************************/
2976 /* initialization */
2977 /************************************************************************/
2980 syms_of_glyphs_mswindows (void)
2982 defkeyword (&Q_resource_id, ":resource-id");
2983 defkeyword (&Q_resource_type, ":resource-type");
2987 console_type_create_glyphs_mswindows (void)
2989 /* image methods - display */
2990 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
2991 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
2992 CONSOLE_HAS_METHOD (mswindows, unmap_subwindow);
2993 CONSOLE_HAS_METHOD (mswindows, map_subwindow);
2994 CONSOLE_HAS_METHOD (mswindows, update_subwindow);
2995 CONSOLE_HAS_METHOD (mswindows, resize_subwindow);
2996 CONSOLE_HAS_METHOD (mswindows, update_widget);
2997 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
2998 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
2999 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
3000 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
3002 /* image methods - printer */
3003 CONSOLE_INHERITS_METHOD (msprinter, mswindows, print_image_instance);
3004 CONSOLE_INHERITS_METHOD (msprinter, mswindows, finalize_image_instance);
3005 CONSOLE_INHERITS_METHOD (msprinter, mswindows, image_instance_equal);
3006 CONSOLE_INHERITS_METHOD (msprinter, mswindows, image_instance_hash);
3007 CONSOLE_INHERITS_METHOD (msprinter, mswindows, init_image_instance_from_eimage);
3008 CONSOLE_INHERITS_METHOD (msprinter, mswindows, locate_pixmap_file);
3012 image_instantiator_format_create_glyphs_mswindows (void)
3014 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, nothing);
3015 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, string);
3016 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, layout);
3017 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, formatted_string);
3018 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, inherit);
3019 /* image-instantiator types */
3020 INITIALIZE_DEVICE_IIFORMAT (mswindows, xbm);
3021 INITIALIZE_DEVICE_IIFORMAT (msprinter, xbm);
3022 IIFORMAT_HAS_DEVMETHOD (mswindows, xbm, instantiate);
3023 IIFORMAT_INHERITS_DEVMETHOD (msprinter, mswindows, xbm, instantiate);
3025 INITIALIZE_DEVICE_IIFORMAT (mswindows, xpm);
3026 INITIALIZE_DEVICE_IIFORMAT (msprinter, xpm);
3027 IIFORMAT_HAS_DEVMETHOD (mswindows, xpm, instantiate);
3028 IIFORMAT_INHERITS_DEVMETHOD (msprinter, mswindows, xpm, instantiate);
3031 INITIALIZE_DEVICE_IIFORMAT (mswindows, xface);
3032 INITIALIZE_DEVICE_IIFORMAT (msprinter, xface);
3033 IIFORMAT_HAS_DEVMETHOD (mswindows, xface, instantiate);
3034 IIFORMAT_INHERITS_DEVMETHOD (msprinter, mswindows, xface, instantiate);
3037 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, jpeg);
3040 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, tiff);
3043 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, png);
3046 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, gif);
3050 INITIALIZE_DEVICE_IIFORMAT (mswindows, button);
3051 IIFORMAT_HAS_DEVMETHOD (mswindows, button, property);
3052 IIFORMAT_HAS_DEVMETHOD (mswindows, button, instantiate);
3053 IIFORMAT_HAS_DEVMETHOD (mswindows, button, update);
3055 INITIALIZE_DEVICE_IIFORMAT (mswindows, edit_field);
3056 IIFORMAT_HAS_DEVMETHOD (mswindows, edit_field, instantiate);
3058 INITIALIZE_DEVICE_IIFORMAT (mswindows, subwindow);
3059 IIFORMAT_HAS_DEVMETHOD (mswindows, subwindow, instantiate);
3061 INITIALIZE_DEVICE_IIFORMAT (mswindows, widget);
3062 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, property);
3065 INITIALIZE_DEVICE_IIFORMAT (mswindows, label);
3066 IIFORMAT_HAS_DEVMETHOD (mswindows, label, instantiate);
3069 INITIALIZE_DEVICE_IIFORMAT (mswindows, combo_box);
3070 IIFORMAT_HAS_DEVMETHOD (mswindows, combo_box, property);
3071 IIFORMAT_HAS_DEVMETHOD (mswindows, combo_box, instantiate);
3074 INITIALIZE_DEVICE_IIFORMAT (mswindows, scrollbar);
3075 IIFORMAT_HAS_DEVMETHOD (mswindows, scrollbar, instantiate);
3077 /* progress gauge */
3078 INITIALIZE_DEVICE_IIFORMAT (mswindows, progress_gauge);
3079 IIFORMAT_HAS_DEVMETHOD (mswindows, progress_gauge, update);
3080 IIFORMAT_HAS_DEVMETHOD (mswindows, progress_gauge, instantiate);
3082 /* tree view widget */
3083 INITIALIZE_DEVICE_IIFORMAT (mswindows, tree_view);
3084 /* IIFORMAT_HAS_DEVMETHOD (mswindows, progress, set_property);*/
3085 IIFORMAT_HAS_DEVMETHOD (mswindows, tree_view, instantiate);
3087 /* tab control widget */
3088 INITIALIZE_DEVICE_IIFORMAT (mswindows, tab_control);
3089 IIFORMAT_HAS_DEVMETHOD (mswindows, tab_control, instantiate);
3090 IIFORMAT_HAS_DEVMETHOD (mswindows, tab_control, update);
3092 /* windows bitmap format */
3093 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
3094 IIFORMAT_HAS_METHOD (bmp, validate);
3095 IIFORMAT_HAS_METHOD (bmp, normalize);
3096 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
3097 IIFORMAT_HAS_METHOD (bmp, instantiate);
3099 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
3100 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
3101 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, bmp);
3103 /* mswindows resources */
3104 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (mswindows_resource,
3105 "mswindows-resource");
3107 IIFORMAT_HAS_METHOD (mswindows_resource, validate);
3108 IIFORMAT_HAS_METHOD (mswindows_resource, normalize);
3109 IIFORMAT_HAS_METHOD (mswindows_resource, possible_dest_types);
3110 IIFORMAT_HAS_METHOD (mswindows_resource, instantiate);
3112 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_type,
3113 check_valid_resource_symbol);
3114 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_id, check_valid_resource_id);
3115 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_file, check_valid_string);
3116 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, mswindows_resource);
3120 vars_of_glyphs_mswindows (void)
3122 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
3123 A list of the directories in which mswindows bitmap files may be found.
3124 This is used by the `make-image-instance' function.
3126 Vmswindows_bitmap_file_path = Qnil;
3130 complex_vars_of_glyphs_mswindows (void)