Mercurial > hg > xemacs-beta
comparison src/glyphs-msw.c @ 267:966663fcf606 r20-5b32
Import from CVS: tag r20-5b32
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:26:29 +0200 |
parents | |
children | b2472a1930f2 |
comparison
equal
deleted
inserted
replaced
266:18d185df8c54 | 267:966663fcf606 |
---|---|
1 /* mswindows-specific Lisp objects. | |
2 Copyright (C) 1998 Free Software Foundation, Inc. | |
3 | |
4 This file is part of XEmacs. | |
5 | |
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 | |
9 later version. | |
10 | |
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 | |
14 for more details. | |
15 | |
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. */ | |
20 | |
21 /* Synched up with: Not in FSF. */ | |
22 | |
23 /* written by Andy Piper <andyp@parallax.co.uk> plagerising buts from | |
24 glyphs-x.c */ | |
25 | |
26 #include <config.h> | |
27 #include "lisp.h" | |
28 #include "lstream.h" | |
29 #include "console-msw.h" | |
30 #include "glyphs-msw.h" | |
31 #include "objects-msw.h" | |
32 | |
33 #include "buffer.h" | |
34 #include "frame.h" | |
35 #include "insdel.h" | |
36 #include "opaque.h" | |
37 #include "sysfile.h" | |
38 #include "faces.h" | |
39 #include "imgproc.h" | |
40 | |
41 #ifdef HAVE_XPM | |
42 #include <X11/xpm.h> | |
43 #endif | |
44 | |
45 #ifdef FILE_CODING | |
46 #include "file-coding.h" | |
47 #endif | |
48 | |
49 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp); | |
50 Lisp_Object Qbmp; | |
51 Lisp_Object Vmswindows_bitmap_file_path; | |
52 | |
53 static void | |
54 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii, | |
55 enum image_instance_type type); | |
56 | |
57 COLORREF mswindows_string_to_color(CONST char *name); | |
58 | |
59 /************************************************************************/ | |
60 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/ | |
61 /* proper display */ | |
62 /************************************************************************/ | |
63 BITMAPINFO* EImage2DIBitmap(Lisp_Object device, int width, int height, | |
64 unsigned char *pic, | |
65 int *bit_count, | |
66 unsigned char** bmp_data) | |
67 { | |
68 struct device *d = XDEVICE (device); | |
69 int i; | |
70 RGBQUAD* colortbl; | |
71 int ncolors; | |
72 BITMAPINFO* bmp_info; | |
73 | |
74 if (DEVICE_MSWINDOWS_BITSPIXEL(d) > 16) | |
75 { | |
76 /* FIXME: we can do this because 24bpp implies no colour table, once | |
77 * we start paletizing this is no longer true. The X versions of | |
78 * this function quantises to 256 colours or bit masks down to a | |
79 * long. Windows can actually handle rgb triples in the raw so I | |
80 * don't see much point trying to optimise down to the best | |
81 * structure - unless it has memory / color allocation implications | |
82 * .... */ | |
83 bmp_info=xnew_and_zero(BITMAPINFO); | |
84 | |
85 if (!bmp_info) | |
86 { | |
87 return NULL; | |
88 } | |
89 | |
90 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */ | |
91 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */ | |
92 bmp_info->bmiHeader.biSizeImage=width*height*3; | |
93 | |
94 /* bitmap data needs to be in blue, green, red triples - in that | |
95 order, eimage is in RGB format so we need to convert */ | |
96 *bmp_data = xnew_array_and_zero (unsigned char, width * height * 3); | |
97 *bit_count = width * height * 3; | |
98 | |
99 if (!bmp_data) | |
100 { | |
101 xfree(bmp_info); | |
102 return NULL; | |
103 } | |
104 for (i=0; i<width*height; i++) | |
105 { | |
106 (*bmp_data)[2]=*pic; | |
107 (*bmp_data)[1]= pic[1]; | |
108 **bmp_data = pic[2]; | |
109 (*bmp_data) += 3; | |
110 } | |
111 } | |
112 else /* scale to 256 colors */ | |
113 { | |
114 int rd,gr,bl, j; | |
115 unsigned char *ip, *dp; | |
116 quant_table *qtable; | |
117 int bpline= (int)(~3UL & (unsigned long)(width +3)); | |
118 /* Quantize the image and get a histogram while we're at it. | |
119 Do this first to save memory */ | |
120 qtable = EImage_build_quantable(pic, width, height, 256); | |
121 if (qtable == NULL) return NULL; | |
122 | |
123 /* use our quantize table to allocate the colors */ | |
124 ncolors = qtable->num_active_colors; | |
125 bmp_info=(BITMAPINFO*)xmalloc_and_zero(sizeof(BITMAPINFOHEADER) + | |
126 sizeof(RGBQUAD) * ncolors); | |
127 if (!bmp_info) | |
128 { | |
129 xfree(qtable); | |
130 return NULL; | |
131 } | |
132 | |
133 colortbl=(RGBQUAD*)(((unsigned char*)bmp_info)+sizeof(BITMAPINFOHEADER)); | |
134 | |
135 bmp_info->bmiHeader.biBitCount=8; | |
136 bmp_info->bmiHeader.biCompression=BI_RGB; | |
137 bmp_info->bmiHeader.biSizeImage=bpline*height; | |
138 bmp_info->bmiHeader.biClrUsed=ncolors; | |
139 bmp_info->bmiHeader.biClrImportant=ncolors; | |
140 | |
141 *bmp_data = (unsigned char *) xmalloc_and_zero (bpline * height); | |
142 *bit_count = bpline * height; | |
143 | |
144 if (!*bmp_data) | |
145 { | |
146 xfree(qtable); | |
147 xfree(bmp_info); | |
148 return NULL; | |
149 } | |
150 | |
151 /* build up an RGBQUAD colortable */ | |
152 for (i = 0; i < qtable->num_active_colors; i++) { | |
153 colortbl[i].rgbRed = qtable->rm[i]; | |
154 colortbl[i].rgbGreen = qtable->gm[i]; | |
155 colortbl[i].rgbBlue = qtable->bm[i]; | |
156 colortbl[i].rgbReserved = 0; | |
157 } | |
158 | |
159 /* now build up the data. picture has to be upside-down and | |
160 back-to-front for msw bitmaps */ | |
161 ip = pic; | |
162 for (i = height-1; i >= 0; i--) { | |
163 dp = (*bmp_data) + (i * bpline); | |
164 for (j = 0; j < width; j++) { | |
165 rd = *ip++; | |
166 gr = *ip++; | |
167 bl = *ip++; | |
168 *dp++ = QUANT_GET_COLOR(qtable,rd,gr,bl); | |
169 } | |
170 } | |
171 xfree(qtable); | |
172 } | |
173 /* fix up the standard stuff */ | |
174 bmp_info->bmiHeader.biWidth=width; | |
175 bmp_info->bmiHeader.biHeight=height; | |
176 bmp_info->bmiHeader.biPlanes=1; | |
177 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); | |
178 bmp_info->bmiHeader.biXPelsPerMeter=3779; /* unless you know better */ | |
179 bmp_info->bmiHeader.biYPelsPerMeter=3779; | |
180 | |
181 return bmp_info; | |
182 } | |
183 | |
184 /* Given a pixmap filename, look through all of the "standard" places | |
185 where the file might be located. Return a full pathname if found; | |
186 otherwise, return Qnil. */ | |
187 | |
188 static Lisp_Object | |
189 locate_pixmap_file (Lisp_Object name) | |
190 { | |
191 /* This function can GC if IN_REDISPLAY is false */ | |
192 | |
193 /* Check non-absolute pathnames with a directory component relative to | |
194 the search path; that's the way Xt does it. */ | |
195 /* #### Unix-specific */ | |
196 if (XSTRING_BYTE (name, 0) == '/' || | |
197 (XSTRING_BYTE (name, 0) == '.' && | |
198 (XSTRING_BYTE (name, 1) == '/' || | |
199 (XSTRING_BYTE (name, 1) == '.' && | |
200 (XSTRING_BYTE (name, 2) == '/'))))) | |
201 { | |
202 if (!NILP (Ffile_readable_p (name))) | |
203 return name; | |
204 else | |
205 return Qnil; | |
206 } | |
207 | |
208 if (!NILP(Vmswindows_bitmap_file_path)) | |
209 { | |
210 Lisp_Object found; | |
211 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0) | |
212 { | |
213 Lisp_Object temp = list1 (Vdata_directory); | |
214 struct gcpro gcpro1; | |
215 | |
216 GCPRO1 (temp); | |
217 locate_file (temp, name, "", &found, R_OK); | |
218 UNGCPRO; | |
219 } | |
220 | |
221 return found; | |
222 } | |
223 else | |
224 return Qnil; | |
225 } | |
226 | |
227 /* If INSTANTIATOR refers to inline data, return Qnil. | |
228 If INSTANTIATOR refers to data in a file, return the full filename | |
229 if it exists; otherwise, return a cons of (filename). | |
230 | |
231 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the | |
232 keywords used to look up the file and inline data, | |
233 respectively, in the instantiator. Normally these would | |
234 be Q_file and Q_data, but might be different for mask data. */ | |
235 | |
236 static Lisp_Object | |
237 potential_pixmap_file_instantiator (Lisp_Object instantiator, | |
238 Lisp_Object file_keyword, | |
239 Lisp_Object data_keyword) | |
240 { | |
241 Lisp_Object file; | |
242 Lisp_Object data; | |
243 | |
244 assert (VECTORP (instantiator)); | |
245 | |
246 data = find_keyword_in_vector (instantiator, data_keyword); | |
247 file = find_keyword_in_vector (instantiator, file_keyword); | |
248 | |
249 if (!NILP (file) && NILP (data)) | |
250 { | |
251 Lisp_Object retval = locate_pixmap_file (file); | |
252 if (!NILP (retval)) | |
253 return retval; | |
254 else | |
255 return Fcons (file, Qnil); /* should have been file */ | |
256 } | |
257 | |
258 return Qnil; | |
259 } | |
260 | |
261 static Lisp_Object | |
262 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type, | |
263 Lisp_Object image_type_tag) | |
264 { | |
265 /* This function can call lisp */ | |
266 Lisp_Object file = Qnil; | |
267 struct gcpro gcpro1, gcpro2; | |
268 Lisp_Object alist = Qnil; | |
269 | |
270 GCPRO2 (file, alist); | |
271 | |
272 /* Now, convert any file data into inline data. At the end of this, | |
273 `data' will contain the inline data (if any) or Qnil, and `file' | |
274 will contain the name this data was derived from (if known) or | |
275 Qnil. | |
276 | |
277 Note that if we cannot generate any regular inline data, we | |
278 skip out. */ | |
279 | |
280 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data); | |
281 | |
282 if (CONSP (file)) /* failure locating filename */ | |
283 signal_double_file_error ("Opening pixmap file", | |
284 "no such file or directory", | |
285 Fcar (file)); | |
286 | |
287 if (NILP (file)) /* no conversion necessary */ | |
288 RETURN_UNGCPRO (inst); | |
289 | |
290 alist = tagged_vector_to_alist (inst); | |
291 | |
292 { | |
293 Lisp_Object data = make_string_from_file (file); | |
294 alist = remassq_no_quit (Q_file, alist); | |
295 /* there can't be a :data at this point. */ | |
296 alist = Fcons (Fcons (Q_file, file), | |
297 Fcons (Fcons (Q_data, data), alist)); | |
298 } | |
299 | |
300 { | |
301 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist); | |
302 free_alist (alist); | |
303 RETURN_UNGCPRO (result); | |
304 } | |
305 } | |
306 | |
307 | |
308 /* Initialize an image instance from a bitmap | |
309 | |
310 DEST_MASK specifies the mask of allowed image types. | |
311 | |
312 If this fails, signal an error. INSTANTIATOR is only used | |
313 in the error message. */ | |
314 | |
315 static void | |
316 init_image_instance_from_dibitmap (struct Lisp_Image_Instance *ii, | |
317 BITMAPINFO *bmp_info, | |
318 int dest_mask, | |
319 void *bmp_data, | |
320 int bmp_bits, | |
321 Lisp_Object instantiator) | |
322 { | |
323 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | |
324 struct device *d = XDEVICE (device); | |
325 struct frame *f = XFRAME (DEVICE_SELECTED_FRAME(d)); | |
326 void* bmp_buf=0; | |
327 HBITMAP bitmap; | |
328 HDC hdc, cdc; | |
329 | |
330 if (!DEVICE_MSWINDOWS_P (d)) | |
331 signal_simple_error ("Not an mswindows device", device); | |
332 | |
333 if (NILP (DEVICE_SELECTED_FRAME (d))) | |
334 signal_simple_error ("No selected frame on mswindows device", device); | |
335 | |
336 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK)) | |
337 incompatible_image_types (instantiator, dest_mask, | |
338 IMAGE_COLOR_PIXMAP_MASK); | |
339 hdc = FRAME_MSWINDOWS_DC (f); | |
340 | |
341 bitmap=CreateDIBSection(hdc, | |
342 bmp_info, | |
343 DIB_RGB_COLORS, | |
344 &bmp_buf, | |
345 0,0); | |
346 | |
347 if (!bitmap || !bmp_buf) | |
348 signal_simple_error ("Unable to create bitmap", instantiator); | |
349 | |
350 /* copy in the actual bitmap */ | |
351 memcpy(bmp_buf, bmp_data, bmp_bits); | |
352 | |
353 /* create a memory dc */ | |
354 cdc = CreateCompatibleDC(hdc); | |
355 | |
356 mswindows_initialize_dibitmap_image_instance (ii, IMAGE_COLOR_PIXMAP); | |
357 | |
358 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = | |
359 find_keyword_in_vector (instantiator, Q_file); | |
360 | |
361 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap; | |
362 IMAGE_INSTANCE_MSWINDOWS_DC (ii) = cdc; | |
363 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth; | |
364 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight; | |
365 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount; | |
366 } | |
367 | |
368 /********************************************************************** | |
369 * XPM * | |
370 **********************************************************************/ | |
371 | |
372 #ifdef HAVE_XPM | |
373 static int xpm_to_eimage(Lisp_Object image, CONST Extbyte *buffer, | |
374 unsigned char** data, | |
375 int* width, int* height, | |
376 COLORREF bg) | |
377 { | |
378 XpmImage xpmimage; | |
379 XpmInfo xpminfo; | |
380 int result, i; | |
381 unsigned char* dptr; | |
382 unsigned int* sptr; | |
383 COLORREF color; /* the american spelling virus hits again .. */ | |
384 COLORREF* colortbl; | |
385 | |
386 memset (&xpmimage, 0, sizeof (xpmimage)); | |
387 memset (&xpminfo, 0, sizeof (xpmimage)); | |
388 | |
389 result = XpmCreateXpmImageFromBuffer((char*)buffer, | |
390 &xpmimage, | |
391 &xpminfo); | |
392 switch(result) | |
393 { | |
394 case XpmSuccess: | |
395 break; | |
396 case XpmFileInvalid: | |
397 { | |
398 signal_simple_error ("invalid XPM data", image); | |
399 } | |
400 case XpmNoMemory: | |
401 { | |
402 signal_double_file_error ("Parsing pixmap data", | |
403 "out of memory", image); | |
404 } | |
405 default: | |
406 { | |
407 signal_double_file_error_2 ("Parsing pixmap data", | |
408 "unknown error code", | |
409 make_int (result), image); | |
410 } | |
411 } | |
412 | |
413 *width = xpmimage.width; | |
414 *height = xpmimage.height; | |
415 | |
416 *data = xnew_array_and_zero (unsigned char, *width * *height * 3); | |
417 if (!*data) | |
418 { | |
419 XpmFreeXpmImage(&xpmimage); | |
420 XpmFreeXpmInfo(&xpminfo); | |
421 return 0; | |
422 } | |
423 | |
424 /* build a color table to speed things up */ | |
425 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors); | |
426 if (!colortbl) | |
427 { | |
428 xfree(*data); | |
429 XpmFreeXpmImage(&xpmimage); | |
430 XpmFreeXpmInfo(&xpminfo); | |
431 return 0; | |
432 } | |
433 | |
434 for (i=0; i<xpmimage.ncolors; i++) | |
435 { | |
436 /* pick up transparencies */ | |
437 if (!strcmp(xpmimage.colorTable[i].c_color,"None")) | |
438 { | |
439 colortbl[i]=bg; | |
440 } | |
441 else | |
442 { | |
443 colortbl[i]= | |
444 mswindows_string_to_color(xpmimage.colorTable[i].c_color); | |
445 } | |
446 } | |
447 | |
448 /* convert the image */ | |
449 sptr=xpmimage.data; | |
450 dptr=*data; | |
451 for (i = 0; i< *width * *height; i++) | |
452 { | |
453 color = colortbl[*sptr++]; | |
454 | |
455 /* split out the 0x02bbggrr colorref into an rgb triple */ | |
456 *dptr++=GetRValue(color); /* red */ | |
457 *dptr++=GetGValue(color); /* green */ | |
458 *dptr++=GetBValue(color); /* blue */ | |
459 } | |
460 | |
461 XpmFreeXpmImage(&xpmimage); | |
462 XpmFreeXpmInfo(&xpminfo); | |
463 xfree(colortbl); | |
464 return TRUE; | |
465 } | |
466 | |
467 void | |
468 mswindows_xpm_instantiate (Lisp_Object image_instance, | |
469 Lisp_Object instantiator, | |
470 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | |
471 int dest_mask, Lisp_Object domain) | |
472 { | |
473 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | |
474 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | |
475 CONST Extbyte *bytes; | |
476 Extcount len; | |
477 unsigned char *eimage; | |
478 int width, height; | |
479 BITMAPINFO* bmp_info; | |
480 unsigned char* bmp_data; | |
481 int bmp_bits; | |
482 COLORREF bkcolor; | |
483 | |
484 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
485 | |
486 if (!DEVICE_MSWINDOWS_P (XDEVICE (device))) | |
487 signal_simple_error ("Not an mswindows device", device); | |
488 | |
489 assert (!NILP (data)); | |
490 | |
491 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); | |
492 | |
493 /* this is a hack but MaskBlt and TransparentBlt are not supported | |
494 on most windows variants */ | |
495 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR | |
496 (XCOLOR_INSTANCE (FACE_BACKGROUND(Vdefault_face, domain))); | |
497 | |
498 /* convert to an eimage to make processing easier */ | |
499 if (!xpm_to_eimage(image_instance, bytes, &eimage, &width, &height, | |
500 bkcolor)) | |
501 { | |
502 signal_simple_error ("XPM to EImage conversion failed", | |
503 image_instance); | |
504 } | |
505 | |
506 /* build a bitmap from the eimage */ | |
507 if (!(bmp_info=EImage2DIBitmap(device, width, height, eimage, | |
508 &bmp_bits, &bmp_data))) | |
509 { | |
510 signal_simple_error ("XPM to EImage conversion failed", | |
511 image_instance); | |
512 } | |
513 xfree(eimage); | |
514 | |
515 /* Now create the pixmap and set up the image instance */ | |
516 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, | |
517 bmp_data, bmp_bits, instantiator); | |
518 | |
519 xfree(bmp_info); | |
520 xfree(bmp_data); | |
521 } | |
522 #endif /* HAVE_XPM */ | |
523 | |
524 /********************************************************************** | |
525 * BMP * | |
526 **********************************************************************/ | |
527 | |
528 static void | |
529 bmp_validate (Lisp_Object instantiator) | |
530 { | |
531 file_or_data_must_be_present (instantiator); | |
532 } | |
533 | |
534 static Lisp_Object | |
535 bmp_normalize (Lisp_Object inst, Lisp_Object console_type) | |
536 { | |
537 return simple_image_type_normalize (inst, console_type, Qbmp); | |
538 } | |
539 | |
540 static int | |
541 bmp_possible_dest_types (void) | |
542 { | |
543 return IMAGE_COLOR_PIXMAP_MASK; | |
544 } | |
545 | |
546 static void | |
547 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | |
548 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | |
549 int dest_mask, Lisp_Object domain) | |
550 { | |
551 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | |
552 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | |
553 CONST Extbyte *bytes; | |
554 Extcount len; | |
555 BITMAPFILEHEADER* bmp_file_header; | |
556 BITMAPINFO* bmp_info; | |
557 void* bmp_data; | |
558 int bmp_bits; | |
559 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
560 | |
561 if (!DEVICE_MSWINDOWS_P (XDEVICE (device))) | |
562 signal_simple_error ("Not an mswindows device", device); | |
563 | |
564 assert (!NILP (data)); | |
565 | |
566 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); | |
567 | |
568 /* Then slurp the image into memory, decoding along the way. | |
569 The result is the image in a simple one-byte-per-pixel | |
570 format. */ | |
571 | |
572 bmp_file_header=(BITMAPFILEHEADER*)bytes; | |
573 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER)); | |
574 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits; | |
575 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits; | |
576 | |
577 /* Now create the pixmap and set up the image instance */ | |
578 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, | |
579 bmp_data, bmp_bits, instantiator); | |
580 } | |
581 | |
582 | |
583 /************************************************************************/ | |
584 /* image instance methods */ | |
585 /************************************************************************/ | |
586 | |
587 static void | |
588 mswindows_print_image_instance (struct Lisp_Image_Instance *p, | |
589 Lisp_Object printcharfun, | |
590 int escapeflag) | |
591 { | |
592 char buf[100]; | |
593 | |
594 switch (IMAGE_INSTANCE_TYPE (p)) | |
595 { | |
596 case IMAGE_MONO_PIXMAP: | |
597 case IMAGE_COLOR_PIXMAP: | |
598 case IMAGE_POINTER: | |
599 sprintf (buf, " (0x%lx", | |
600 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p)); | |
601 write_c_string (buf, printcharfun); | |
602 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p)) | |
603 { | |
604 sprintf (buf, "/0x%lx", | |
605 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p)); | |
606 write_c_string (buf, printcharfun); | |
607 } | |
608 write_c_string (")", printcharfun); | |
609 break; | |
610 default: | |
611 break; | |
612 } | |
613 } | |
614 | |
615 static void | |
616 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p) | |
617 { | |
618 if (!p->data) | |
619 return; | |
620 | |
621 if (DEVICE_LIVE_P (XDEVICE (p->device))) | |
622 { | |
623 if (IMAGE_INSTANCE_MSWINDOWS_DC (p)) | |
624 DeleteDC(IMAGE_INSTANCE_MSWINDOWS_DC (p)); | |
625 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p)) | |
626 DeleteObject(IMAGE_INSTANCE_MSWINDOWS_BITMAP (p)); | |
627 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0; | |
628 IMAGE_INSTANCE_MSWINDOWS_DC (p) = 0; | |
629 } | |
630 | |
631 xfree (p->data); | |
632 p->data = 0; | |
633 } | |
634 | |
635 static int | |
636 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1, | |
637 struct Lisp_Image_Instance *p2, int depth) | |
638 { | |
639 switch (IMAGE_INSTANCE_TYPE (p1)) | |
640 { | |
641 case IMAGE_MONO_PIXMAP: | |
642 case IMAGE_COLOR_PIXMAP: | |
643 case IMAGE_POINTER: | |
644 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1) | |
645 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2)) | |
646 return 0; | |
647 break; | |
648 default: | |
649 break; | |
650 } | |
651 | |
652 return 1; | |
653 } | |
654 | |
655 static unsigned long | |
656 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth) | |
657 { | |
658 switch (IMAGE_INSTANCE_TYPE (p)) | |
659 { | |
660 case IMAGE_MONO_PIXMAP: | |
661 case IMAGE_COLOR_PIXMAP: | |
662 case IMAGE_POINTER: | |
663 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p); | |
664 default: | |
665 return 0; | |
666 } | |
667 } | |
668 | |
669 /* Set all the slots in an image instance structure to reasonable | |
670 default values. This is used somewhere within an instantiate | |
671 method. It is assumed that the device slot within the image | |
672 instance is already set -- this is the case when instantiate | |
673 methods are called. */ | |
674 | |
675 static void | |
676 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii, | |
677 enum image_instance_type type) | |
678 { | |
679 ii->data = xnew_and_zero (struct mswindows_image_instance_data); | |
680 IMAGE_INSTANCE_TYPE (ii) = type; | |
681 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil; | |
682 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil; | |
683 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil; | |
684 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil; | |
685 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil; | |
686 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil; | |
687 } | |
688 | |
689 | |
690 /************************************************************************/ | |
691 /* initialization */ | |
692 /************************************************************************/ | |
693 | |
694 void | |
695 syms_of_glyphs_mswindows (void) | |
696 { | |
697 } | |
698 | |
699 void | |
700 console_type_create_glyphs_mswindows (void) | |
701 { | |
702 /* image methods */ | |
703 | |
704 CONSOLE_HAS_METHOD (mswindows, print_image_instance); | |
705 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance); | |
706 CONSOLE_HAS_METHOD (mswindows, image_instance_equal); | |
707 CONSOLE_HAS_METHOD (mswindows, image_instance_hash); | |
708 } | |
709 | |
710 void | |
711 image_instantiator_format_create_glyphs_mswindows (void) | |
712 { | |
713 /* image-instantiator types */ | |
714 | |
715 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp"); | |
716 | |
717 IIFORMAT_HAS_METHOD (bmp, validate); | |
718 IIFORMAT_HAS_METHOD (bmp, normalize); | |
719 IIFORMAT_HAS_METHOD (bmp, possible_dest_types); | |
720 IIFORMAT_HAS_METHOD (bmp, instantiate); | |
721 | |
722 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string); | |
723 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string); | |
724 } | |
725 | |
726 void | |
727 vars_of_glyphs_mswindows (void) | |
728 { | |
729 Fprovide (Qbmp); | |
730 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /* | |
731 A list of the directories in which mswindows bitmap files may be found. | |
732 This is used by the `make-image-instance' function. | |
733 */ ); | |
734 Vmswindows_bitmap_file_path = Qnil; | |
735 } | |
736 | |
737 void | |
738 complex_vars_of_glyphs_mswindows (void) | |
739 { | |
740 } | |
741 |