267
|
1 /* mswindows-specific Lisp objects.
|
280
|
2 Copyright (C) 1998 Andy Piper.
|
267
|
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"
|
286
|
29
|
|
30 #define OEMRESOURCE /* Define OCR_ and friend constants */
|
267
|
31 #include "console-msw.h"
|
|
32 #include "glyphs-msw.h"
|
|
33 #include "objects-msw.h"
|
|
34
|
|
35 #include "buffer.h"
|
|
36 #include "frame.h"
|
|
37 #include "insdel.h"
|
|
38 #include "opaque.h"
|
|
39 #include "sysfile.h"
|
|
40 #include "faces.h"
|
|
41 #include "imgproc.h"
|
|
42
|
|
43 #ifdef FILE_CODING
|
|
44 #include "file-coding.h"
|
|
45 #endif
|
288
|
46 #include <stdio.h>
|
|
47 #include <ctype.h>
|
|
48
|
267
|
49
|
|
50 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
|
|
51 Lisp_Object Qbmp;
|
|
52 Lisp_Object Vmswindows_bitmap_file_path;
|
282
|
53 static COLORREF transparent_color = RGB (1,1,1);
|
267
|
54
|
286
|
55 DEFINE_IMAGE_INSTANTIATOR_FORMAT (resource);
|
284
|
56 Lisp_Object Q_resource_type, Q_resource_id;
|
|
57
|
267
|
58 static void
|
|
59 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
60 enum image_instance_type type);
|
282
|
61 static void
|
|
62 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
|
|
63 struct frame* f);
|
267
|
64
|
269
|
65 COLORREF mswindows_string_to_color (CONST char *name);
|
267
|
66
|
288
|
67 #define BPLINE(width) ((int)(~3UL & (unsigned long)((width) +3)))
|
|
68
|
267
|
69 /************************************************************************/
|
|
70 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/
|
|
71 /* proper display */
|
|
72 /************************************************************************/
|
278
|
73 static BITMAPINFO* convert_EImage_to_DIBitmap (Lisp_Object device,
|
|
74 int width, int height,
|
|
75 unsigned char *pic,
|
|
76 int *bit_count,
|
|
77 unsigned char** bmp_data)
|
267
|
78 {
|
|
79 struct device *d = XDEVICE (device);
|
269
|
80 int i,j;
|
267
|
81 RGBQUAD* colortbl;
|
|
82 int ncolors;
|
|
83 BITMAPINFO* bmp_info;
|
269
|
84 unsigned char *ip, *dp;
|
267
|
85
|
269
|
86 if (DEVICE_MSWINDOWS_BITSPIXEL (d) > 0)
|
267
|
87 {
|
288
|
88 int bpline = BPLINE(width * 3);
|
267
|
89 /* FIXME: we can do this because 24bpp implies no colour table, once
|
|
90 * we start paletizing this is no longer true. The X versions of
|
|
91 * this function quantises to 256 colours or bit masks down to a
|
|
92 * long. Windows can actually handle rgb triples in the raw so I
|
272
|
93 * don't see much point trying to optimize down to the best
|
267
|
94 * structure - unless it has memory / color allocation implications
|
|
95 * .... */
|
269
|
96 bmp_info=xnew_and_zero (BITMAPINFO);
|
267
|
97
|
|
98 if (!bmp_info)
|
|
99 {
|
|
100 return NULL;
|
|
101 }
|
|
102
|
|
103 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */
|
|
104 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */
|
|
105 bmp_info->bmiHeader.biSizeImage=width*height*3;
|
|
106
|
|
107 /* bitmap data needs to be in blue, green, red triples - in that
|
|
108 order, eimage is in RGB format so we need to convert */
|
272
|
109 *bmp_data = xnew_array_and_zero (unsigned char, bpline * height);
|
278
|
110 *bit_count = bpline * height;
|
267
|
111
|
|
112 if (!bmp_data)
|
|
113 {
|
272
|
114 xfree (bmp_info);
|
267
|
115 return NULL;
|
|
116 }
|
272
|
117
|
|
118 ip = pic;
|
|
119 for (i = height-1; i >= 0; i--) {
|
|
120 dp = (*bmp_data) + (i * bpline);
|
|
121 for (j = 0; j < width; j++) {
|
|
122 dp[2] =*ip++;
|
|
123 dp[1] =*ip++;
|
|
124 *dp =*ip++;
|
|
125 dp += 3;
|
267
|
126 }
|
272
|
127 }
|
267
|
128 }
|
|
129 else /* scale to 256 colors */
|
|
130 {
|
272
|
131 int rd,gr,bl;
|
267
|
132 quant_table *qtable;
|
288
|
133 int bpline = BPLINE (width * 3);
|
267
|
134 /* Quantize the image and get a histogram while we're at it.
|
|
135 Do this first to save memory */
|
269
|
136 qtable = build_EImage_quantable(pic, width, height, 256);
|
267
|
137 if (qtable == NULL) return NULL;
|
|
138
|
|
139 /* use our quantize table to allocate the colors */
|
|
140 ncolors = qtable->num_active_colors;
|
272
|
141 bmp_info=(BITMAPINFO*)xmalloc_and_zero (sizeof(BITMAPINFOHEADER) +
|
267
|
142 sizeof(RGBQUAD) * ncolors);
|
|
143 if (!bmp_info)
|
|
144 {
|
272
|
145 xfree (qtable);
|
267
|
146 return NULL;
|
|
147 }
|
|
148
|
|
149 colortbl=(RGBQUAD*)(((unsigned char*)bmp_info)+sizeof(BITMAPINFOHEADER));
|
|
150
|
|
151 bmp_info->bmiHeader.biBitCount=8;
|
|
152 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
153 bmp_info->bmiHeader.biSizeImage=bpline*height;
|
|
154 bmp_info->bmiHeader.biClrUsed=ncolors;
|
|
155 bmp_info->bmiHeader.biClrImportant=ncolors;
|
|
156
|
|
157 *bmp_data = (unsigned char *) xmalloc_and_zero (bpline * height);
|
|
158 *bit_count = bpline * height;
|
|
159
|
|
160 if (!*bmp_data)
|
|
161 {
|
269
|
162 xfree (qtable);
|
|
163 xfree (bmp_info);
|
267
|
164 return NULL;
|
|
165 }
|
|
166
|
|
167 /* build up an RGBQUAD colortable */
|
|
168 for (i = 0; i < qtable->num_active_colors; i++) {
|
286
|
169 colortbl[i].rgbRed = (BYTE) qtable->rm[i];
|
|
170 colortbl[i].rgbGreen = (BYTE) qtable->gm[i];
|
|
171 colortbl[i].rgbBlue = (BYTE) qtable->bm[i];
|
267
|
172 colortbl[i].rgbReserved = 0;
|
|
173 }
|
|
174
|
|
175 /* now build up the data. picture has to be upside-down and
|
|
176 back-to-front for msw bitmaps */
|
|
177 ip = pic;
|
|
178 for (i = height-1; i >= 0; i--) {
|
|
179 dp = (*bmp_data) + (i * bpline);
|
|
180 for (j = 0; j < width; j++) {
|
|
181 rd = *ip++;
|
|
182 gr = *ip++;
|
|
183 bl = *ip++;
|
269
|
184 *dp++ = QUANT_GET_COLOR (qtable,rd,gr,bl);
|
267
|
185 }
|
|
186 }
|
269
|
187 xfree (qtable);
|
267
|
188 }
|
|
189 /* fix up the standard stuff */
|
|
190 bmp_info->bmiHeader.biWidth=width;
|
|
191 bmp_info->bmiHeader.biHeight=height;
|
|
192 bmp_info->bmiHeader.biPlanes=1;
|
|
193 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
269
|
194 bmp_info->bmiHeader.biXPelsPerMeter=0; /* unless you know better */
|
|
195 bmp_info->bmiHeader.biYPelsPerMeter=0;
|
267
|
196
|
|
197 return bmp_info;
|
|
198 }
|
|
199
|
|
200 /* Given a pixmap filename, look through all of the "standard" places
|
|
201 where the file might be located. Return a full pathname if found;
|
|
202 otherwise, return Qnil. */
|
|
203
|
280
|
204 static Lisp_Object
|
278
|
205 mswindows_locate_pixmap_file (Lisp_Object name)
|
267
|
206 {
|
|
207 /* This function can GC if IN_REDISPLAY is false */
|
276
|
208 Lisp_Object found;
|
267
|
209
|
|
210 /* Check non-absolute pathnames with a directory component relative to
|
|
211 the search path; that's the way Xt does it. */
|
269
|
212 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) ||
|
267
|
213 (XSTRING_BYTE (name, 0) == '.' &&
|
269
|
214 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 1)) ||
|
267
|
215 (XSTRING_BYTE (name, 1) == '.' &&
|
269
|
216 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 2)))))))
|
267
|
217 {
|
|
218 if (!NILP (Ffile_readable_p (name)))
|
|
219 return name;
|
|
220 else
|
|
221 return Qnil;
|
|
222 }
|
|
223
|
276
|
224 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
225 {
|
|
226 Lisp_Object temp = list1 (Vdata_directory);
|
|
227 struct gcpro gcpro1;
|
267
|
228
|
276
|
229 GCPRO1 (temp);
|
|
230 locate_file (temp, name, "", &found, R_OK);
|
|
231 UNGCPRO;
|
|
232 }
|
267
|
233
|
276
|
234 return found;
|
267
|
235 }
|
|
236
|
|
237
|
|
238 /* Initialize an image instance from a bitmap
|
|
239
|
|
240 DEST_MASK specifies the mask of allowed image types.
|
|
241
|
|
242 If this fails, signal an error. INSTANTIATOR is only used
|
|
243 in the error message. */
|
|
244
|
|
245 static void
|
|
246 init_image_instance_from_dibitmap (struct Lisp_Image_Instance *ii,
|
|
247 BITMAPINFO *bmp_info,
|
|
248 int dest_mask,
|
|
249 void *bmp_data,
|
|
250 int bmp_bits,
|
282
|
251 Lisp_Object instantiator,
|
|
252 int x_hot, int y_hot,
|
|
253 int create_mask)
|
267
|
254 {
|
|
255 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
256 struct device *d = XDEVICE (device);
|
288
|
257 struct frame *f;
|
267
|
258 void* bmp_buf=0;
|
282
|
259 int type;
|
267
|
260 HBITMAP bitmap;
|
269
|
261 HDC hdc;
|
267
|
262
|
|
263 if (!DEVICE_MSWINDOWS_P (d))
|
|
264 signal_simple_error ("Not an mswindows device", device);
|
|
265
|
|
266 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
267 signal_simple_error ("No selected frame on mswindows device", device);
|
|
268
|
288
|
269 f = XFRAME (DEVICE_SELECTED_FRAME (d));
|
|
270
|
282
|
271 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
272 type = IMAGE_COLOR_PIXMAP;
|
|
273 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
274 type = IMAGE_POINTER;
|
|
275 else
|
267
|
276 incompatible_image_types (instantiator, dest_mask,
|
282
|
277 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
|
288
|
278 hdc = FRAME_MSWINDOWS_CDC (f);
|
267
|
279
|
269
|
280 bitmap=CreateDIBSection (hdc,
|
267
|
281 bmp_info,
|
|
282 DIB_RGB_COLORS,
|
|
283 &bmp_buf,
|
|
284 0,0);
|
|
285
|
|
286 if (!bitmap || !bmp_buf)
|
|
287 signal_simple_error ("Unable to create bitmap", instantiator);
|
|
288
|
|
289 /* copy in the actual bitmap */
|
269
|
290 memcpy (bmp_buf, bmp_data, bmp_bits);
|
267
|
291
|
282
|
292 mswindows_initialize_dibitmap_image_instance (ii, type);
|
267
|
293
|
|
294 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
295 find_keyword_in_vector (instantiator, Q_file);
|
|
296
|
|
297 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap;
|
282
|
298 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
|
267
|
299 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth;
|
|
300 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight;
|
|
301 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount;
|
282
|
302 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), x_hot);
|
|
303 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), y_hot);
|
|
304
|
|
305 if (create_mask)
|
|
306 {
|
|
307 mswindows_initialize_image_instance_mask (ii, f);
|
|
308 }
|
|
309
|
|
310 if (type == IMAGE_POINTER)
|
|
311 {
|
|
312 mswindows_initialize_image_instance_icon(ii, TRUE);
|
|
313 }
|
267
|
314 }
|
|
315
|
278
|
316 static void
|
|
317 mswindows_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
|
|
318 int width, int height,
|
|
319 unsigned char *eimage,
|
|
320 int dest_mask,
|
|
321 Lisp_Object instantiator,
|
|
322 Lisp_Object domain)
|
|
323 {
|
|
324 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
325 BITMAPINFO* bmp_info;
|
|
326 unsigned char* bmp_data;
|
|
327 int bmp_bits;
|
|
328 COLORREF bkcolor;
|
|
329
|
|
330 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
331 signal_simple_error ("Not an mswindows device", device);
|
|
332
|
|
333 /* this is a hack but MaskBlt and TransparentBlt are not supported
|
|
334 on most windows variants */
|
|
335 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
336 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
|
|
337
|
|
338 /* build a bitmap from the eimage */
|
|
339 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
340 &bmp_bits, &bmp_data)))
|
|
341 {
|
|
342 signal_simple_error ("EImage to DIBitmap conversion failed",
|
|
343 instantiator);
|
|
344 }
|
|
345
|
|
346 /* Now create the pixmap and set up the image instance */
|
|
347 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
282
|
348 bmp_data, bmp_bits, instantiator,
|
|
349 0, 0, 0);
|
278
|
350
|
|
351 xfree (bmp_info);
|
|
352 xfree (bmp_data);
|
|
353 }
|
|
354
|
282
|
355 static void set_mono_pixel ( unsigned char* bits,
|
|
356 int bpline, int height,
|
|
357 int x, int y, int white )
|
|
358 {
|
|
359 int index;
|
|
360 unsigned char bitnum;
|
|
361 /* Find the byte on which this scanline begins */
|
|
362 index = (height - y - 1) * bpline;
|
|
363 /* Find the byte containing this pixel */
|
|
364 index += (x >> 3);
|
|
365 /* Which bit is it? */
|
|
366 bitnum = (unsigned char)( 7 - (x % 8) );
|
|
367 if( white ) /* Turn it on */
|
|
368 bits[index] |= (1<<bitnum);
|
|
369 else /* Turn it off */
|
|
370 bits[index] &= ~(1<<bitnum);
|
|
371 }
|
|
372
|
|
373 static void
|
|
374 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
|
|
375 struct frame* f)
|
276
|
376 {
|
284
|
377 HBITMAP mask;
|
|
378 HGDIOBJ old = NULL;
|
276
|
379 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
288
|
380 unsigned char* dibits;
|
282
|
381 BITMAPINFO* bmp_info =
|
284
|
382 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
|
282
|
383 int i, j;
|
|
384 int height = IMAGE_INSTANCE_PIXMAP_HEIGHT (image);
|
276
|
385
|
288
|
386 void* and_bits;
|
|
387 int maskbpline = BPLINE (((IMAGE_INSTANCE_PIXMAP_WIDTH (image)+7)/8));
|
|
388 int bpline = BPLINE (IMAGE_INSTANCE_PIXMAP_WIDTH (image) * 3);
|
|
389
|
|
390 if (!bmp_info)
|
|
391 return;
|
282
|
392
|
|
393 bmp_info->bmiHeader.biWidth=IMAGE_INSTANCE_PIXMAP_WIDTH (image);
|
|
394 bmp_info->bmiHeader.biHeight = height;
|
|
395 bmp_info->bmiHeader.biPlanes=1;
|
|
396 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
|
397 bmp_info->bmiHeader.biBitCount=1;
|
|
398 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
399 bmp_info->bmiHeader.biClrUsed = 2;
|
|
400 bmp_info->bmiHeader.biClrImportant = 2;
|
288
|
401 bmp_info->bmiHeader.biSizeImage = height * maskbpline;
|
282
|
402 bmp_info->bmiColors[0].rgbRed = 0;
|
|
403 bmp_info->bmiColors[0].rgbGreen = 0;
|
|
404 bmp_info->bmiColors[0].rgbBlue = 0;
|
|
405 bmp_info->bmiColors[0].rgbReserved = 0;
|
|
406 bmp_info->bmiColors[1].rgbRed = 255;
|
|
407 bmp_info->bmiColors[1].rgbGreen = 255;
|
|
408 bmp_info->bmiColors[1].rgbBlue = 255;
|
|
409 bmp_info->bmiColors[0].rgbReserved = 0;
|
|
410
|
|
411 if (!(mask = CreateDIBSection (hcdc,
|
|
412 bmp_info,
|
|
413 DIB_RGB_COLORS,
|
|
414 &and_bits,
|
|
415 0,0)))
|
276
|
416 {
|
282
|
417 xfree (bmp_info);
|
|
418 return;
|
276
|
419 }
|
|
420
|
284
|
421 old = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (image));
|
288
|
422 /* build up an in-memory set of bits to mess with */
|
|
423 xzero (*bmp_info);
|
|
424
|
|
425 bmp_info->bmiHeader.biWidth=IMAGE_INSTANCE_PIXMAP_WIDTH (image);
|
|
426 bmp_info->bmiHeader.biHeight = -height;
|
|
427 bmp_info->bmiHeader.biPlanes=1;
|
|
428 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
|
429 bmp_info->bmiHeader.biBitCount=24;
|
|
430 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
431 bmp_info->bmiHeader.biClrUsed = 0;
|
|
432 bmp_info->bmiHeader.biClrImportant = 0;
|
|
433 bmp_info->bmiHeader.biSizeImage = height * bpline;
|
|
434
|
|
435 dibits = xmalloc_and_zero (bpline * height);
|
|
436 if (GetDIBits (hcdc,
|
|
437 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image),
|
|
438 0,
|
|
439 height,
|
|
440 dibits,
|
|
441 bmp_info,
|
|
442 DIB_RGB_COLORS) <= 0)
|
|
443 {
|
|
444 xfree (bmp_info);
|
|
445 return;
|
|
446 }
|
|
447
|
|
448 /* now set the colored bits in the mask and transparent ones to
|
|
449 black in the original */
|
282
|
450 for(i=0; i<IMAGE_INSTANCE_PIXMAP_WIDTH (image); i++)
|
|
451 {
|
|
452 for(j=0; j<height; j++)
|
|
453 {
|
288
|
454 unsigned char* idx = &dibits[j * bpline + i * 3];
|
|
455
|
|
456 if( RGB (idx[2], idx[1], idx[0]) == transparent_color )
|
282
|
457 {
|
288
|
458 idx[0] = idx[1] = idx[2] = 0;
|
|
459 set_mono_pixel( and_bits, maskbpline, height, i, j, TRUE );
|
282
|
460 }
|
|
461 else
|
|
462 {
|
288
|
463 set_mono_pixel( and_bits, maskbpline, height, i, j, FALSE );
|
282
|
464 }
|
|
465 }
|
276
|
466 }
|
|
467
|
288
|
468 SetDIBits (hcdc,
|
|
469 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image),
|
|
470 0,
|
|
471 height,
|
|
472 dibits,
|
|
473 bmp_info,
|
|
474 DIB_RGB_COLORS);
|
|
475
|
|
476 xfree (bmp_info);
|
|
477 xfree (dibits);
|
|
478
|
284
|
479 SelectObject(hcdc, old);
|
282
|
480
|
|
481 IMAGE_INSTANCE_MSWINDOWS_MASK (image) = mask;
|
|
482 }
|
|
483
|
|
484 void
|
|
485 mswindows_initialize_image_instance_icon (struct Lisp_Image_Instance* image,
|
|
486 int cursor)
|
|
487 {
|
|
488 ICONINFO x_icon;
|
|
489
|
|
490 /* we rely on windows to do any resizing necessary */
|
|
491 x_icon.fIcon=cursor ? FALSE : TRUE;
|
|
492 x_icon.xHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image));
|
|
493 x_icon.yHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image));
|
|
494 x_icon.hbmMask=IMAGE_INSTANCE_MSWINDOWS_MASK (image);
|
|
495 x_icon.hbmColor=IMAGE_INSTANCE_MSWINDOWS_BITMAP (image);
|
276
|
496
|
282
|
497 IMAGE_INSTANCE_MSWINDOWS_ICON (image)=
|
276
|
498 CreateIconIndirect (&x_icon);
|
|
499 }
|
|
500
|
286
|
501 HBITMAP
|
|
502 mswindows_create_resized_bitmap (struct Lisp_Image_Instance* ii,
|
|
503 struct frame* f,
|
|
504 int newx, int newy)
|
276
|
505 {
|
286
|
506 HBITMAP newbmp;
|
|
507 HGDIOBJ old1, old2;
|
276
|
508 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
|
509 HDC hdcDst = CreateCompatibleDC (hcdc);
|
|
510
|
286
|
511 old1 = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
276
|
512
|
284
|
513 newbmp = CreateCompatibleBitmap (hcdc, newx, newy);
|
276
|
514
|
286
|
515 old2 = SelectObject (hdcDst, newbmp);
|
276
|
516
|
284
|
517 if (!StretchBlt (hdcDst, 0, 0, newx, newy,
|
|
518 hcdc, 0, 0,
|
|
519 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
520 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
521 SRCCOPY))
|
276
|
522 {
|
286
|
523 return 0;
|
276
|
524 }
|
284
|
525
|
286
|
526 SelectObject (hdcDst, old2);
|
|
527 SelectObject (hcdc, old1);
|
|
528 DeleteDC (hdcDst);
|
|
529
|
|
530 return newbmp;
|
|
531 }
|
|
532
|
|
533 HBITMAP
|
|
534 mswindows_create_resized_mask (struct Lisp_Image_Instance* ii,
|
|
535 struct frame* f,
|
|
536 int newx, int newy)
|
|
537 {
|
284
|
538 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
|
|
539 {
|
286
|
540 HBITMAP newmask;
|
|
541 HGDIOBJ old1, old2;
|
|
542 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
|
543 HDC hdcDst = CreateCompatibleDC (hcdc);
|
|
544
|
|
545 old1 = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
|
284
|
546 newmask = CreateCompatibleBitmap(hcdc, newx, newy);
|
286
|
547 old2 = SelectObject (hdcDst, newmask);
|
284
|
548
|
|
549 if (!StretchBlt(hdcDst, 0, 0, newx, newy,
|
|
550 hcdc, 0, 0,
|
|
551 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
552 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
553 SRCCOPY))
|
|
554 {
|
286
|
555 return NULL;
|
284
|
556 }
|
286
|
557
|
|
558 SelectObject (hdcDst, old2);
|
|
559 SelectObject (hcdc, old1);
|
|
560
|
|
561 DeleteDC (hdcDst);
|
|
562
|
|
563 return newmask;
|
284
|
564 }
|
|
565
|
286
|
566 return NULL;
|
|
567 }
|
|
568
|
|
569 int
|
|
570 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii,
|
|
571 struct frame* f,
|
|
572 int newx, int newy)
|
|
573 {
|
|
574 HBITMAP newbmp = mswindows_create_resized_bitmap (ii, f, newx, newy);
|
|
575 HBITMAP newmask = mswindows_create_resized_mask (ii, f, newx, newy);
|
|
576
|
|
577 if (!newbmp)
|
|
578 return FALSE;
|
276
|
579
|
|
580 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii))
|
|
581 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
|
582 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
|
|
583 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
|
|
584
|
|
585 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp;
|
284
|
586 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newmask;
|
276
|
587 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx;
|
|
588 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy;
|
|
589
|
|
590 return TRUE;
|
|
591 }
|
|
592
|
267
|
593 /**********************************************************************
|
|
594 * XPM *
|
|
595 **********************************************************************/
|
|
596
|
|
597 #ifdef HAVE_XPM
|
280
|
598
|
|
599 struct color_symbol
|
|
600 {
|
|
601 char* name;
|
|
602 COLORREF color;
|
|
603 };
|
|
604
|
|
605 static struct color_symbol*
|
|
606 extract_xpm_color_names (Lisp_Object device,
|
|
607 Lisp_Object domain,
|
|
608 Lisp_Object color_symbol_alist,
|
|
609 int* nsymbols)
|
|
610 {
|
|
611 /* This function can GC */
|
|
612 Lisp_Object rest;
|
|
613 Lisp_Object results = Qnil;
|
|
614 int i, j;
|
|
615 struct color_symbol *colortbl;
|
|
616 struct gcpro gcpro1, gcpro2;
|
|
617
|
|
618 GCPRO2 (results, device);
|
|
619
|
|
620 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
621 error happens we don't lose any malloc()ed data, or more importantly,
|
|
622 leave any pixels allocated in the server. */
|
|
623 i = 0;
|
|
624 LIST_LOOP (rest, color_symbol_alist)
|
|
625 {
|
|
626 Lisp_Object cons = XCAR (rest);
|
|
627 Lisp_Object name = XCAR (cons);
|
|
628 Lisp_Object value = XCDR (cons);
|
|
629 if (NILP (value))
|
|
630 continue;
|
|
631 if (STRINGP (value))
|
|
632 value =
|
|
633 Fmake_color_instance
|
|
634 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
|
|
635 else
|
|
636 {
|
|
637 assert (COLOR_SPECIFIERP (value));
|
|
638 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
|
639 }
|
|
640 if (NILP (value))
|
|
641 continue;
|
|
642 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
643 i++;
|
|
644 }
|
|
645 UNGCPRO; /* no more evaluation */
|
|
646
|
|
647 *nsymbols=i;
|
|
648 if (i == 0) return 0;
|
|
649
|
|
650 colortbl = xnew_array_and_zero (struct color_symbol, i);
|
|
651
|
|
652 for (j=0; j<i; j++)
|
|
653 {
|
|
654 Lisp_Object cons = XCAR (results);
|
|
655 colortbl[j].color =
|
|
656 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
657
|
|
658 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons));
|
|
659 free_cons (XCONS (cons));
|
|
660 cons = results;
|
|
661 results = XCDR (results);
|
|
662 free_cons (XCONS (cons));
|
|
663 }
|
|
664 return colortbl;
|
|
665 }
|
|
666
|
269
|
667 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer,
|
276
|
668 unsigned char** data,
|
|
669 int* width, int* height,
|
|
670 int* x_hot, int* y_hot,
|
282
|
671 int* transp,
|
|
672 struct color_symbol* color_symbols,
|
280
|
673 int nsymbols)
|
267
|
674 {
|
|
675 XpmImage xpmimage;
|
|
676 XpmInfo xpminfo;
|
280
|
677 int result, i, j, transp_idx, maskbpline;
|
267
|
678 unsigned char* dptr;
|
|
679 unsigned int* sptr;
|
|
680 COLORREF color; /* the american spelling virus hits again .. */
|
|
681 COLORREF* colortbl;
|
|
682
|
272
|
683 xzero (xpmimage);
|
|
684 xzero (xpminfo);
|
276
|
685 xpminfo.valuemask=XpmHotspot;
|
282
|
686 *transp=FALSE;
|
276
|
687
|
269
|
688 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
|
267
|
689 &xpmimage,
|
|
690 &xpminfo);
|
269
|
691 switch (result)
|
267
|
692 {
|
|
693 case XpmSuccess:
|
|
694 break;
|
|
695 case XpmFileInvalid:
|
|
696 {
|
|
697 signal_simple_error ("invalid XPM data", image);
|
|
698 }
|
|
699 case XpmNoMemory:
|
|
700 {
|
|
701 signal_double_file_error ("Parsing pixmap data",
|
|
702 "out of memory", image);
|
|
703 }
|
|
704 default:
|
|
705 {
|
|
706 signal_double_file_error_2 ("Parsing pixmap data",
|
|
707 "unknown error code",
|
|
708 make_int (result), image);
|
|
709 }
|
|
710 }
|
|
711
|
|
712 *width = xpmimage.width;
|
|
713 *height = xpmimage.height;
|
288
|
714 maskbpline = BPLINE (((~7UL & (unsigned long)(*width + 7)) / 8));
|
276
|
715
|
|
716 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
|
267
|
717
|
|
718 if (!*data)
|
|
719 {
|
269
|
720 XpmFreeXpmImage (&xpmimage);
|
|
721 XpmFreeXpmInfo (&xpminfo);
|
267
|
722 return 0;
|
|
723 }
|
|
724
|
|
725 /* build a color table to speed things up */
|
|
726 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
|
|
727 if (!colortbl)
|
|
728 {
|
269
|
729 xfree (*data);
|
|
730 XpmFreeXpmImage (&xpmimage);
|
|
731 XpmFreeXpmInfo (&xpminfo);
|
267
|
732 return 0;
|
|
733 }
|
|
734
|
|
735 for (i=0; i<xpmimage.ncolors; i++)
|
|
736 {
|
288
|
737 /* goto alert!!!! */
|
|
738 /* pick up symbolic colors in preference */
|
|
739 if (xpmimage.colorTable[i].symbolic)
|
280
|
740 {
|
288
|
741 if (!strcasecmp (xpmimage.colorTable[i].symbolic,"BgColor")
|
|
742 ||
|
|
743 !strcasecmp (xpmimage.colorTable[i].symbolic,"None"))
|
280
|
744 {
|
288
|
745 *transp=TRUE;
|
|
746 colortbl[i]=transparent_color;
|
|
747 transp_idx=i;
|
|
748 goto label_found_color;
|
280
|
749 }
|
288
|
750 else if (color_symbols)
|
280
|
751 {
|
288
|
752 for (j = 0; j<nsymbols; j++)
|
280
|
753 {
|
288
|
754 if (!strcmp (xpmimage.colorTable[i].symbolic,
|
|
755 color_symbols[j].name ))
|
|
756 {
|
|
757 colortbl[i]=color_symbols[j].color;
|
|
758 goto label_found_color;
|
|
759 }
|
280
|
760 }
|
|
761 }
|
288
|
762 else if (xpmimage.colorTable[i].c_color == 0)
|
|
763 {
|
|
764 goto label_no_color;
|
|
765 }
|
280
|
766 }
|
288
|
767 /* pick up transparencies */
|
|
768 if (!strcasecmp (xpmimage.colorTable[i].c_color,"None"))
|
267
|
769 {
|
282
|
770 *transp=TRUE;
|
|
771 colortbl[i]=transparent_color;
|
276
|
772 transp_idx=i;
|
288
|
773 goto label_found_color;
|
267
|
774 }
|
288
|
775 /* finally pick up a normal color spec */
|
|
776 if (xpmimage.colorTable[i].c_color)
|
267
|
777 {
|
|
778 colortbl[i]=
|
269
|
779 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
|
288
|
780 goto label_found_color;
|
267
|
781 }
|
288
|
782
|
|
783 label_no_color:
|
|
784 xfree (*data);
|
|
785 xfree (colortbl);
|
|
786 XpmFreeXpmImage (&xpmimage);
|
|
787 XpmFreeXpmInfo (&xpminfo);
|
|
788 return 0;
|
|
789
|
|
790 label_found_color:;
|
267
|
791 }
|
|
792
|
|
793 /* convert the image */
|
|
794 sptr=xpmimage.data;
|
|
795 dptr=*data;
|
|
796 for (i = 0; i< *width * *height; i++)
|
|
797 {
|
|
798 color = colortbl[*sptr++];
|
|
799
|
|
800 /* split out the 0x02bbggrr colorref into an rgb triple */
|
269
|
801 *dptr++=GetRValue (color); /* red */
|
|
802 *dptr++=GetGValue (color); /* green */
|
|
803 *dptr++=GetBValue (color); /* blue */
|
267
|
804 }
|
|
805
|
276
|
806 *x_hot=xpminfo.x_hotspot;
|
|
807 *y_hot=xpminfo.y_hotspot;
|
|
808
|
269
|
809 XpmFreeXpmImage (&xpmimage);
|
|
810 XpmFreeXpmInfo (&xpminfo);
|
|
811 xfree (colortbl);
|
267
|
812 return TRUE;
|
|
813 }
|
|
814
|
280
|
815 static void
|
267
|
816 mswindows_xpm_instantiate (Lisp_Object image_instance,
|
|
817 Lisp_Object instantiator,
|
|
818 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
819 int dest_mask, Lisp_Object domain)
|
|
820 {
|
|
821 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
822 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
823 CONST Extbyte *bytes;
|
|
824 Extcount len;
|
|
825 unsigned char *eimage;
|
276
|
826 int width, height, x_hot, y_hot;
|
267
|
827 BITMAPINFO* bmp_info;
|
|
828 unsigned char* bmp_data;
|
|
829 int bmp_bits;
|
282
|
830 int nsymbols=0, transp;
|
280
|
831 struct color_symbol* color_symbols=NULL;
|
267
|
832
|
|
833 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
280
|
834 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
835 Q_color_symbols);
|
267
|
836
|
|
837 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
838 signal_simple_error ("Not an mswindows device", device);
|
|
839
|
|
840 assert (!NILP (data));
|
|
841
|
|
842 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
843
|
280
|
844 /* in case we have color symbols */
|
|
845 color_symbols = extract_xpm_color_names (device, domain,
|
|
846 color_symbol_alist, &nsymbols);
|
|
847
|
267
|
848 /* convert to an eimage to make processing easier */
|
269
|
849 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
|
282
|
850 &x_hot, &y_hot, &transp, color_symbols, nsymbols))
|
267
|
851 {
|
|
852 signal_simple_error ("XPM to EImage conversion failed",
|
|
853 image_instance);
|
|
854 }
|
|
855
|
280
|
856 if (color_symbols)
|
|
857 xfree(color_symbols);
|
|
858
|
267
|
859 /* build a bitmap from the eimage */
|
278
|
860 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
861 &bmp_bits, &bmp_data)))
|
267
|
862 {
|
|
863 signal_simple_error ("XPM to EImage conversion failed",
|
|
864 image_instance);
|
|
865 }
|
269
|
866 xfree (eimage);
|
267
|
867
|
|
868 /* Now create the pixmap and set up the image instance */
|
|
869 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
282
|
870 bmp_data, bmp_bits, instantiator,
|
|
871 x_hot, y_hot, transp);
|
267
|
872
|
269
|
873 xfree (bmp_info);
|
|
874 xfree (bmp_data);
|
267
|
875 }
|
|
876 #endif /* HAVE_XPM */
|
|
877
|
|
878 /**********************************************************************
|
|
879 * BMP *
|
|
880 **********************************************************************/
|
|
881
|
|
882 static void
|
|
883 bmp_validate (Lisp_Object instantiator)
|
|
884 {
|
|
885 file_or_data_must_be_present (instantiator);
|
|
886 }
|
|
887
|
|
888 static Lisp_Object
|
|
889 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
890 {
|
|
891 return simple_image_type_normalize (inst, console_type, Qbmp);
|
|
892 }
|
|
893
|
|
894 static int
|
|
895 bmp_possible_dest_types (void)
|
|
896 {
|
|
897 return IMAGE_COLOR_PIXMAP_MASK;
|
|
898 }
|
|
899
|
|
900 static void
|
|
901 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
902 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
903 int dest_mask, Lisp_Object domain)
|
|
904 {
|
|
905 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
906 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
907 CONST Extbyte *bytes;
|
|
908 Extcount len;
|
|
909 BITMAPFILEHEADER* bmp_file_header;
|
|
910 BITMAPINFO* bmp_info;
|
|
911 void* bmp_data;
|
|
912 int bmp_bits;
|
|
913 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
914
|
|
915 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
916 signal_simple_error ("Not an mswindows device", device);
|
|
917
|
|
918 assert (!NILP (data));
|
|
919
|
|
920 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
921
|
|
922 /* Then slurp the image into memory, decoding along the way.
|
|
923 The result is the image in a simple one-byte-per-pixel
|
|
924 format. */
|
|
925
|
|
926 bmp_file_header=(BITMAPFILEHEADER*)bytes;
|
|
927 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
|
|
928 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
|
|
929 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
|
|
930
|
|
931 /* Now create the pixmap and set up the image instance */
|
|
932 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
282
|
933 bmp_data, bmp_bits, instantiator,
|
|
934 0, 0, 0);
|
267
|
935 }
|
|
936
|
|
937
|
284
|
938 /**********************************************************************
|
286
|
939 * RESOURCES *
|
284
|
940 **********************************************************************/
|
|
941
|
|
942 static void
|
286
|
943 resource_validate (Lisp_Object instantiator)
|
284
|
944 {
|
|
945 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
|
|
946 &&
|
|
947 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
|
|
948 ||
|
|
949 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
|
|
950 signal_simple_error ("Must supply :file, :resource-id and :resource-type",
|
|
951 instantiator);
|
|
952 }
|
|
953
|
|
954 static Lisp_Object
|
286
|
955 resource_normalize (Lisp_Object inst, Lisp_Object console_type)
|
284
|
956 {
|
|
957 /* This function can call lisp */
|
|
958 Lisp_Object file = Qnil;
|
|
959 struct gcpro gcpro1, gcpro2;
|
|
960 Lisp_Object alist = Qnil;
|
|
961
|
|
962 GCPRO2 (file, alist);
|
|
963
|
|
964 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
965 console_type);
|
|
966
|
|
967 if (CONSP (file)) /* failure locating filename */
|
|
968 signal_double_file_error ("Opening pixmap file",
|
|
969 "no such file or directory",
|
|
970 Fcar (file));
|
|
971
|
|
972 if (NILP (file)) /* no conversion necessary */
|
|
973 RETURN_UNGCPRO (inst);
|
|
974
|
|
975 alist = tagged_vector_to_alist (inst);
|
|
976
|
|
977 {
|
|
978 alist = remassq_no_quit (Q_file, alist);
|
|
979 alist = Fcons (Fcons (Q_file, file), alist);
|
|
980 }
|
|
981
|
|
982 {
|
286
|
983 Lisp_Object result = alist_to_tagged_vector (Qresource, alist);
|
284
|
984 free_alist (alist);
|
|
985 RETURN_UNGCPRO (result);
|
|
986 }
|
|
987 }
|
|
988
|
|
989 static int
|
286
|
990 resource_possible_dest_types (void)
|
284
|
991 {
|
|
992 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
|
|
993 }
|
|
994
|
|
995 typedef struct
|
|
996 {
|
|
997 char *name;
|
|
998 int resource_id;
|
|
999 } resource_t;
|
|
1000
|
|
1001 #ifndef OCR_ICOCUR
|
|
1002 #define OCR_ICOCUR 32647
|
|
1003 #define OIC_SAMPLE 32512
|
|
1004 #define OIC_HAND 32513
|
|
1005 #define OIC_QUES 32514
|
|
1006 #define OIC_BANG 32515
|
|
1007 #define OIC_NOTE 32516
|
|
1008 #define OIC_WINLOGO 32517
|
|
1009 #define LR_SHARED 0x8000
|
|
1010 #endif
|
|
1011
|
286
|
1012 static CONST resource_t bitmap_table[] =
|
284
|
1013 {
|
|
1014 /* bitmaps */
|
|
1015 { "close", OBM_CLOSE },
|
|
1016 { "uparrow", OBM_UPARROW },
|
|
1017 { "dnarrow", OBM_DNARROW },
|
|
1018 { "rgarrow", OBM_RGARROW },
|
|
1019 { "lfarrow", OBM_LFARROW },
|
|
1020 { "reduce", OBM_REDUCE },
|
|
1021 { "zoom", OBM_ZOOM },
|
|
1022 { "restore", OBM_RESTORE },
|
|
1023 { "reduced", OBM_REDUCED },
|
|
1024 { "zoomd", OBM_ZOOMD },
|
|
1025 { "restored", OBM_RESTORED },
|
|
1026 { "uparrowd", OBM_UPARROWD },
|
|
1027 { "dnarrowd", OBM_DNARROWD },
|
|
1028 { "rgarrowd", OBM_RGARROWD },
|
|
1029 { "lfarrowd", OBM_LFARROWD },
|
|
1030 { "mnarrow", OBM_MNARROW },
|
|
1031 { "combo", OBM_COMBO },
|
|
1032 { "uparrowi", OBM_UPARROWI },
|
|
1033 { "dnarrowi", OBM_DNARROWI },
|
|
1034 { "rgarrowi", OBM_RGARROWI },
|
|
1035 { "lfarrowi", OBM_LFARROWI },
|
|
1036 { "size", OBM_SIZE },
|
|
1037 { "btsize", OBM_BTSIZE },
|
|
1038 { "check", OBM_CHECK },
|
|
1039 { "cehckboxes", OBM_CHECKBOXES },
|
|
1040 { "btncorners" , OBM_BTNCORNERS },
|
286
|
1041 {0}
|
|
1042 };
|
|
1043
|
|
1044 static CONST resource_t cursor_table[] =
|
|
1045 {
|
284
|
1046 /* cursors */
|
|
1047 { "normal", OCR_NORMAL },
|
|
1048 { "ibeam", OCR_IBEAM },
|
|
1049 { "wait", OCR_WAIT },
|
|
1050 { "cross", OCR_CROSS },
|
|
1051 { "up", OCR_UP },
|
|
1052 /* { "icon", OCR_ICON }, */
|
|
1053 { "sizenwse", OCR_SIZENWSE },
|
|
1054 { "sizenesw", OCR_SIZENESW },
|
|
1055 { "sizewe", OCR_SIZEWE },
|
|
1056 { "sizens", OCR_SIZENS },
|
|
1057 { "sizeall", OCR_SIZEALL },
|
|
1058 /* { "icour", OCR_ICOCUR }, */
|
|
1059 { "no", OCR_NO },
|
286
|
1060 { 0 }
|
|
1061 };
|
|
1062
|
|
1063 static CONST resource_t icon_table[] =
|
|
1064 {
|
284
|
1065 /* icons */
|
|
1066 { "sample", OIC_SAMPLE },
|
|
1067 { "hand", OIC_HAND },
|
|
1068 { "ques", OIC_QUES },
|
|
1069 { "bang", OIC_BANG },
|
|
1070 { "note", OIC_NOTE },
|
|
1071 { "winlogo", OIC_WINLOGO },
|
|
1072 {0}
|
|
1073 };
|
|
1074
|
286
|
1075 static int resource_name_to_resource (Lisp_Object name, int type)
|
284
|
1076 {
|
286
|
1077 CONST resource_t* res = (type == IMAGE_CURSOR ? cursor_table
|
|
1078 : type == IMAGE_ICON ? icon_table
|
|
1079 : bitmap_table);
|
284
|
1080
|
|
1081 if (INTP (name))
|
|
1082 {
|
|
1083 return XINT (name);
|
|
1084 }
|
|
1085 else if (!STRINGP (name))
|
|
1086 {
|
|
1087 signal_simple_error ("invalid resource identifier", name);
|
|
1088 }
|
|
1089
|
|
1090 do {
|
|
1091 if (!strcasecmp ((char*)res->name, XSTRING_DATA (name)))
|
|
1092 return res->resource_id;
|
|
1093 } while ((++res)->name);
|
|
1094 return 0;
|
|
1095 }
|
|
1096
|
286
|
1097 static int
|
|
1098 resource_symbol_to_type (Lisp_Object data)
|
|
1099 {
|
|
1100 if (EQ (data, Qcursor))
|
|
1101 return IMAGE_CURSOR;
|
|
1102 else if (EQ (data, Qicon))
|
|
1103 return IMAGE_ICON;
|
|
1104 else if (EQ (data, Qbitmap))
|
|
1105 return IMAGE_BITMAP;
|
|
1106 else
|
|
1107 return 0;
|
|
1108 }
|
|
1109
|
284
|
1110 static void
|
286
|
1111 resource_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
284
|
1112 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1113 int dest_mask, Lisp_Object domain)
|
|
1114 {
|
|
1115 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1116 unsigned int type = 0;
|
|
1117 HANDLE himage = NULL;
|
|
1118 LPCTSTR resid=0;
|
286
|
1119 HINSTANCE hinst = NULL;
|
|
1120 ICONINFO iconinfo;
|
284
|
1121 int iitype=0;
|
286
|
1122 char* fname=0;
|
284
|
1123 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1124
|
|
1125 Lisp_Object file = find_keyword_in_vector (instantiator, Q_file);
|
|
1126 Lisp_Object resource_type = find_keyword_in_vector (instantiator,
|
|
1127 Q_resource_type);
|
|
1128 Lisp_Object resource_id = find_keyword_in_vector (instantiator,
|
|
1129 Q_resource_id);
|
|
1130
|
286
|
1131 xzero (iconinfo);
|
|
1132
|
284
|
1133 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
1134 signal_simple_error ("Not an mswindows device", device);
|
|
1135
|
286
|
1136 type = resource_symbol_to_type (resource_type);
|
284
|
1137
|
|
1138 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_CURSOR)
|
|
1139 iitype = IMAGE_POINTER;
|
|
1140 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1141 iitype = IMAGE_COLOR_PIXMAP;
|
|
1142 else
|
|
1143 incompatible_image_types (instantiator, dest_mask,
|
|
1144 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
|
|
1145
|
286
|
1146 /* mess with the keyword info we were provided with */
|
284
|
1147 if (!NILP (file))
|
286
|
1148 {
|
|
1149 #ifdef __CYGWIN32__
|
|
1150 CYGWIN_WIN32_PATH (XSTRING_DATA (file), fname);
|
|
1151 #else
|
|
1152 /* #### FIXME someone who knows ... */
|
|
1153 fname = XSTRING_DATA (file);
|
|
1154 #endif
|
|
1155
|
|
1156 if (NILP (resource_id))
|
|
1157 resid = (LPCTSTR)fname;
|
|
1158 else
|
|
1159 {
|
|
1160 hinst = LoadLibraryEx (fname, NULL,
|
|
1161 LOAD_LIBRARY_AS_DATAFILE);
|
|
1162 resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
|
|
1163 type));
|
|
1164
|
|
1165 if (!resid)
|
|
1166 resid = XSTRING_DATA (resource_id);
|
|
1167 }
|
|
1168 }
|
|
1169 else if (!(resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
|
|
1170 type))))
|
|
1171 signal_simple_error ("invalid resource identifier", resource_id);
|
284
|
1172
|
|
1173 /* load the image */
|
286
|
1174 if (!(himage = LoadImage (hinst, resid, type, 0, 0,
|
284
|
1175 LR_CREATEDIBSECTION | LR_DEFAULTSIZE |
|
|
1176 LR_SHARED |
|
|
1177 (!NILP (file) ? LR_LOADFROMFILE : 0))))
|
|
1178 {
|
|
1179 signal_simple_error ("cannot load image", instantiator);
|
|
1180 }
|
|
1181
|
286
|
1182 if (hinst)
|
|
1183 FreeLibrary (hinst);
|
|
1184
|
284
|
1185 mswindows_initialize_dibitmap_image_instance (ii, iitype);
|
|
1186
|
|
1187 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = file;
|
|
1188 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) =
|
286
|
1189 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CXCURSOR : SM_CXICON);
|
284
|
1190 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) =
|
286
|
1191 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CYCURSOR : SM_CYICON);
|
|
1192 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
|
|
1193
|
|
1194 /* hey, we've got an icon type thing so we can reverse engineer the
|
|
1195 bitmap and mask */
|
|
1196 if (type != IMAGE_BITMAP)
|
|
1197 {
|
|
1198 GetIconInfo (himage, &iconinfo);
|
|
1199 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = iconinfo.hbmColor;
|
|
1200 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = iconinfo.hbmMask;
|
|
1201 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), iconinfo.xHotspot);
|
|
1202 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), iconinfo.yHotspot);
|
|
1203 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = himage;
|
|
1204 }
|
|
1205 else
|
|
1206 {
|
|
1207 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = NULL;
|
|
1208 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = himage;
|
|
1209 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
|
|
1210 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
|
|
1211 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
|
|
1212 }
|
284
|
1213 }
|
|
1214
|
286
|
1215 static void
|
|
1216 check_valid_resource_symbol (Lisp_Object data)
|
284
|
1217 {
|
|
1218 CHECK_SYMBOL (data);
|
286
|
1219 if (!resource_symbol_to_type (data))
|
|
1220 signal_simple_error ("invalid resource type", data);
|
|
1221 }
|
|
1222
|
|
1223 static void
|
|
1224 check_valid_resource_id (Lisp_Object data)
|
|
1225 {
|
|
1226 if (!resource_name_to_resource (data, IMAGE_CURSOR)
|
|
1227 &&
|
|
1228 !resource_name_to_resource (data, IMAGE_ICON)
|
|
1229 &&
|
|
1230 !resource_name_to_resource (data, IMAGE_BITMAP))
|
|
1231 signal_simple_error ("invalid resource identifier", data);
|
284
|
1232 }
|
|
1233
|
|
1234 void
|
|
1235 check_valid_string_or_int (Lisp_Object data)
|
|
1236 {
|
|
1237 if (!INTP (data))
|
|
1238 CHECK_STRING (data);
|
|
1239 else
|
|
1240 CHECK_INT (data);
|
|
1241 }
|
|
1242
|
288
|
1243 /**********************************************************************
|
|
1244 * XBM *
|
|
1245 **********************************************************************/
|
|
1246 #ifndef HAVE_X_WINDOWS
|
|
1247 /* $XConsortium: RdBitF.c,v 1.10 94/04/17 20:16:13 kaleb Exp $ */
|
|
1248
|
|
1249 /*
|
|
1250
|
|
1251 Copyright (c) 1988 X Consortium
|
|
1252
|
|
1253 Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1254 of this software and associated documentation files (the "Software"), to deal
|
|
1255 in the Software without restriction, including without limitation the rights
|
|
1256 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1257 copies of the Software, and to permit persons to whom the Software is
|
|
1258 furnished to do so, subject to the following conditions:
|
|
1259
|
|
1260 The above copyright notice and this permission notice shall be included in
|
|
1261 all copies or substantial portions of the Software.
|
|
1262
|
|
1263 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1264 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1265 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1266 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
1267 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
1268 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1269
|
|
1270 Except as contained in this notice, the name of the X Consortium shall not be
|
|
1271 used in advertising or otherwise to promote the sale, use or other dealings
|
|
1272 in this Software without prior written authorization from the X Consortium.
|
|
1273
|
|
1274 */
|
|
1275
|
|
1276 /*
|
|
1277 * This file contains miscellaneous utility routines and is not part of the
|
|
1278 * Xlib standard.
|
|
1279 *
|
|
1280 * Public entry points:
|
|
1281 *
|
|
1282 * XmuReadBitmapData read data from FILE descriptor
|
|
1283 * XmuReadBitmapDataFromFile read X10 or X11 format bitmap files
|
|
1284 * and return data
|
|
1285 *
|
|
1286 * Note that this file and ../X/XRdBitF.c look very similar.... Keep them
|
|
1287 * that way (but don't use common source code so that people can have one
|
|
1288 * without the other).
|
|
1289 */
|
|
1290
|
|
1291
|
|
1292 /*
|
|
1293 * Based on an optimized version provided by Jim Becker, Auguest 5, 1988.
|
|
1294 */
|
|
1295 #ifndef BitmapSuccess
|
|
1296 #define BitmapSuccess 0
|
|
1297 #define BitmapOpenFailed 1
|
|
1298 #define BitmapFileInvalid 2
|
|
1299 #define BitmapNoMemory 3
|
|
1300 #endif
|
|
1301 #define MAX_SIZE 255
|
|
1302
|
|
1303 /* shared data for the image read/parse logic */
|
|
1304 static short hexTable[256]; /* conversion value */
|
|
1305 static int initialized = FALSE; /* easier to fill in at run time */
|
|
1306
|
|
1307 /*
|
|
1308 * Table index for the hex values. Initialized once, first time.
|
|
1309 * Used for translation value or delimiter significance lookup.
|
|
1310 */
|
|
1311 static void initHexTable()
|
|
1312 {
|
|
1313 /*
|
|
1314 * We build the table at run time for several reasons:
|
|
1315 *
|
|
1316 * 1. portable to non-ASCII machines.
|
|
1317 * 2. still reentrant since we set the init flag after setting table.
|
|
1318 * 3. easier to extend.
|
|
1319 * 4. less prone to bugs.
|
|
1320 */
|
|
1321 hexTable['0'] = 0; hexTable['1'] = 1;
|
|
1322 hexTable['2'] = 2; hexTable['3'] = 3;
|
|
1323 hexTable['4'] = 4; hexTable['5'] = 5;
|
|
1324 hexTable['6'] = 6; hexTable['7'] = 7;
|
|
1325 hexTable['8'] = 8; hexTable['9'] = 9;
|
|
1326 hexTable['A'] = 10; hexTable['B'] = 11;
|
|
1327 hexTable['C'] = 12; hexTable['D'] = 13;
|
|
1328 hexTable['E'] = 14; hexTable['F'] = 15;
|
|
1329 hexTable['a'] = 10; hexTable['b'] = 11;
|
|
1330 hexTable['c'] = 12; hexTable['d'] = 13;
|
|
1331 hexTable['e'] = 14; hexTable['f'] = 15;
|
|
1332
|
|
1333 /* delimiters of significance are flagged w/ negative value */
|
|
1334 hexTable[' '] = -1; hexTable[','] = -1;
|
|
1335 hexTable['}'] = -1; hexTable['\n'] = -1;
|
|
1336 hexTable['\t'] = -1;
|
|
1337
|
|
1338 initialized = TRUE;
|
|
1339 }
|
|
1340
|
|
1341 /*
|
|
1342 * read next hex value in the input stream, return -1 if EOF
|
|
1343 */
|
|
1344 static int NextInt ( FILE *fstream )
|
|
1345 {
|
|
1346 int ch;
|
|
1347 int value = 0;
|
|
1348 int gotone = 0;
|
|
1349 int done = 0;
|
|
1350
|
|
1351 /* loop, accumulate hex value until find delimiter */
|
|
1352 /* skip any initial delimiters found in read stream */
|
|
1353
|
|
1354 while (!done) {
|
|
1355 ch = getc(fstream);
|
|
1356 if (ch == EOF) {
|
|
1357 value = -1;
|
|
1358 done++;
|
|
1359 } else {
|
|
1360 /* trim high bits, check type and accumulate */
|
|
1361 ch &= 0xff;
|
|
1362 if (isascii(ch) && isxdigit(ch)) {
|
|
1363 value = (value << 4) + hexTable[ch];
|
|
1364 gotone++;
|
|
1365 } else if ((hexTable[ch]) < 0 && gotone)
|
|
1366 done++;
|
|
1367 }
|
|
1368 }
|
|
1369 return value;
|
|
1370 }
|
|
1371
|
|
1372
|
|
1373 /*
|
|
1374 * The data returned by the following routine is always in left-most byte
|
|
1375 * first and left-most bit first. If it doesn't return BitmapSuccess then
|
|
1376 * its arguments won't have been touched. This routine should look as much
|
|
1377 * like the Xlib routine XReadBitmapfile as possible.
|
|
1378 */
|
|
1379 int read_bitmap_data (fstream, width, height, datap, x_hot, y_hot)
|
|
1380 FILE *fstream; /* handle on file */
|
|
1381 unsigned int *width, *height; /* RETURNED */
|
|
1382 unsigned char **datap; /* RETURNED */
|
|
1383 int *x_hot, *y_hot; /* RETURNED */
|
|
1384 {
|
|
1385 unsigned char *data = NULL; /* working variable */
|
|
1386 char line[MAX_SIZE]; /* input line from file */
|
|
1387 int size; /* number of bytes of data */
|
|
1388 char name_and_type[MAX_SIZE]; /* an input line */
|
|
1389 char *type; /* for parsing */
|
|
1390 int value; /* from an input line */
|
|
1391 int version10p; /* boolean, old format */
|
|
1392 int padding; /* to handle alignment */
|
|
1393 int bytes_per_line; /* per scanline of data */
|
|
1394 unsigned int ww = 0; /* width */
|
|
1395 unsigned int hh = 0; /* height */
|
|
1396 int hx = -1; /* x hotspot */
|
|
1397 int hy = -1; /* y hotspot */
|
|
1398
|
|
1399 #define Xmalloc(size) malloc(size)
|
|
1400
|
|
1401 /* first time initialization */
|
|
1402 if (initialized == FALSE) initHexTable();
|
|
1403
|
|
1404 /* error cleanup and return macro */
|
|
1405 #define RETURN(code) { if (data) free (data); return code; }
|
|
1406
|
|
1407 while (fgets(line, MAX_SIZE, fstream)) {
|
|
1408 if (strlen(line) == MAX_SIZE-1) {
|
|
1409 RETURN (BitmapFileInvalid);
|
|
1410 }
|
|
1411 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
|
|
1412 if (!(type = strrchr(name_and_type, '_')))
|
|
1413 type = name_and_type;
|
|
1414 else
|
|
1415 type++;
|
|
1416
|
|
1417 if (!strcmp("width", type))
|
|
1418 ww = (unsigned int) value;
|
|
1419 if (!strcmp("height", type))
|
|
1420 hh = (unsigned int) value;
|
|
1421 if (!strcmp("hot", type)) {
|
|
1422 if (type-- == name_and_type || type-- == name_and_type)
|
|
1423 continue;
|
|
1424 if (!strcmp("x_hot", type))
|
|
1425 hx = value;
|
|
1426 if (!strcmp("y_hot", type))
|
|
1427 hy = value;
|
|
1428 }
|
|
1429 continue;
|
|
1430 }
|
|
1431
|
|
1432 if (sscanf(line, "static short %s = {", name_and_type) == 1)
|
|
1433 version10p = 1;
|
|
1434 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
|
|
1435 version10p = 0;
|
|
1436 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
|
|
1437 version10p = 0;
|
|
1438 else
|
|
1439 continue;
|
|
1440
|
|
1441 if (!(type = strrchr(name_and_type, '_')))
|
|
1442 type = name_and_type;
|
|
1443 else
|
|
1444 type++;
|
|
1445
|
|
1446 if (strcmp("bits[]", type))
|
|
1447 continue;
|
|
1448
|
|
1449 if (!ww || !hh)
|
|
1450 RETURN (BitmapFileInvalid);
|
|
1451
|
|
1452 if ((ww % 16) && ((ww % 16) < 9) && version10p)
|
|
1453 padding = 1;
|
|
1454 else
|
|
1455 padding = 0;
|
|
1456
|
|
1457 bytes_per_line = (ww+7)/8 + padding;
|
|
1458
|
|
1459 size = bytes_per_line * hh;
|
|
1460 data = (unsigned char *) Xmalloc ((unsigned int) size);
|
|
1461 if (!data)
|
|
1462 RETURN (BitmapNoMemory);
|
|
1463
|
|
1464 if (version10p) {
|
|
1465 unsigned char *ptr;
|
|
1466 int bytes;
|
|
1467
|
|
1468 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
|
|
1469 if ((value = NextInt(fstream)) < 0)
|
|
1470 RETURN (BitmapFileInvalid);
|
|
1471 *(ptr++) = value;
|
|
1472 if (!padding || ((bytes+2) % bytes_per_line))
|
|
1473 *(ptr++) = value >> 8;
|
|
1474 }
|
|
1475 } else {
|
|
1476 unsigned char *ptr;
|
|
1477 int bytes;
|
|
1478
|
|
1479 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
|
|
1480 if ((value = NextInt(fstream)) < 0)
|
|
1481 RETURN (BitmapFileInvalid);
|
|
1482 *ptr=value;
|
|
1483 }
|
|
1484 }
|
|
1485 break;
|
|
1486 } /* end while */
|
|
1487
|
|
1488 if (data == NULL) {
|
|
1489 RETURN (BitmapFileInvalid);
|
|
1490 }
|
|
1491
|
|
1492 *datap = data;
|
|
1493 data = NULL;
|
|
1494 *width = ww;
|
|
1495 *height = hh;
|
|
1496 if (x_hot) *x_hot = hx;
|
|
1497 if (y_hot) *y_hot = hy;
|
|
1498
|
|
1499 RETURN (BitmapSuccess);
|
|
1500 }
|
|
1501
|
|
1502
|
|
1503 int read_bitmap_data_from_file (CONST char *filename, unsigned int *width,
|
|
1504 unsigned int *height, unsigned char **datap,
|
|
1505 int *x_hot, int *y_hot)
|
|
1506 {
|
|
1507 FILE *fstream;
|
|
1508 int status;
|
|
1509
|
|
1510 if ((fstream = fopen (filename, "r")) == NULL) {
|
|
1511 return BitmapOpenFailed;
|
|
1512 }
|
|
1513 status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot);
|
|
1514 fclose (fstream);
|
|
1515 return status;
|
|
1516 }
|
|
1517 #endif /* HAVE_X_WINDOWS */
|
|
1518
|
|
1519 /* this table flips four bits around. */
|
|
1520 static int flip_table[] =
|
|
1521 {
|
|
1522 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
|
|
1523 };
|
|
1524
|
|
1525 /* the bitmap data comes in the following format: Widths are padded to
|
|
1526 a multiple of 8. Scan lines are stored in increasing byte order
|
|
1527 from left to right, little-endian within a byte. 0 = white, 1 =
|
|
1528 black. It must be converted to the following format: Widths are
|
|
1529 padded to a multiple of 16. Scan lines are stored in increasing
|
|
1530 byte order from left to right, big-endian within a byte. 0 =
|
|
1531 black, 1 = white. */
|
290
|
1532 HBITMAP
|
|
1533 xbm_create_bitmap_from_data (HDC hdc, char *data,
|
|
1534 unsigned int width, unsigned int height,
|
|
1535 int mask, COLORREF fg, COLORREF bg)
|
288
|
1536 {
|
|
1537 int old_width = (width + 7)/8;
|
|
1538 int new_width = 2*((width + 15)/16);
|
|
1539 unsigned char *offset;
|
290
|
1540 void *bmp_buf = 0;
|
288
|
1541 unsigned char *new_data, *new_offset;
|
290
|
1542 int i, j;
|
|
1543 BITMAPINFO* bmp_info =
|
|
1544 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
|
|
1545 HBITMAP bitmap;
|
288
|
1546
|
290
|
1547 if (!bmp_info)
|
|
1548 return NULL;
|
|
1549
|
|
1550 new_data = (unsigned char *) xmalloc (height * new_width);
|
|
1551
|
|
1552 if (!new_data)
|
|
1553 {
|
|
1554 xfree (bmp_info);
|
|
1555 return NULL;
|
|
1556 }
|
|
1557
|
288
|
1558 for (i=0; i<height; i++)
|
|
1559 {
|
|
1560 offset = data + i*old_width;
|
|
1561 new_offset = new_data + i*new_width;
|
290
|
1562
|
288
|
1563 new_offset[new_width - 1] = 0; /* there may be an extra byte
|
|
1564 that needs to be padded */
|
|
1565 for (j=0; j<old_width; j++)
|
|
1566 {
|
|
1567 int byte = offset[j];
|
|
1568 new_offset[j] = ~ (unsigned char)
|
|
1569 ((flip_table[byte & 0xf] << 4) + flip_table[byte >> 4]);
|
|
1570 }
|
|
1571 }
|
290
|
1572
|
|
1573 /* if we want a mask invert the bits */
|
|
1574 if (!mask)
|
|
1575 {
|
|
1576 new_offset = &new_data[height * new_width];
|
|
1577 while (new_offset-- != new_data)
|
|
1578 {
|
|
1579 *new_offset ^= 0xff;
|
|
1580 }
|
|
1581 }
|
|
1582
|
|
1583 bmp_info->bmiHeader.biWidth=width;
|
|
1584 bmp_info->bmiHeader.biHeight=-height;
|
|
1585 bmp_info->bmiHeader.biPlanes=1;
|
|
1586 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
|
1587 bmp_info->bmiHeader.biBitCount=1;
|
|
1588 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
1589 bmp_info->bmiHeader.biClrUsed = 2;
|
|
1590 bmp_info->bmiHeader.biClrImportant = 2;
|
|
1591 bmp_info->bmiHeader.biSizeImage = height * new_width;
|
|
1592 bmp_info->bmiColors[0].rgbRed = GetRValue (fg);
|
|
1593 bmp_info->bmiColors[0].rgbGreen = GetGValue (fg);
|
|
1594 bmp_info->bmiColors[0].rgbBlue = GetBValue (fg);
|
|
1595 bmp_info->bmiColors[0].rgbReserved = 0;
|
|
1596 bmp_info->bmiColors[1].rgbRed = GetRValue (bg);
|
|
1597 bmp_info->bmiColors[1].rgbGreen = GetGValue (bg);
|
|
1598 bmp_info->bmiColors[1].rgbBlue = GetBValue (bg);
|
|
1599 bmp_info->bmiColors[1].rgbReserved = 0;
|
|
1600
|
|
1601 bitmap = CreateDIBSection (hdc,
|
|
1602 bmp_info,
|
|
1603 DIB_RGB_COLORS,
|
|
1604 &bmp_buf,
|
|
1605 0,0);
|
|
1606
|
|
1607 xfree (bmp_info);
|
|
1608
|
|
1609 if (!bitmap || !bmp_buf)
|
|
1610 {
|
|
1611 xfree (new_data);
|
|
1612 return NULL;
|
|
1613 }
|
|
1614
|
|
1615 /* copy in the actual bitmap */
|
|
1616 memcpy (bmp_buf, new_data, height * new_width);
|
288
|
1617 xfree (new_data);
|
|
1618
|
290
|
1619 return bitmap;
|
288
|
1620 }
|
|
1621
|
|
1622 /* Given inline data for a mono pixmap, initialize the given
|
|
1623 image instance accordingly. */
|
|
1624
|
|
1625 static void
|
|
1626 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
|
|
1627 int width, int height,
|
|
1628 /* Note that data is in ext-format! */
|
|
1629 CONST char *bits,
|
|
1630 Lisp_Object instantiator,
|
|
1631 Lisp_Object pointer_fg,
|
|
1632 Lisp_Object pointer_bg,
|
|
1633 int dest_mask,
|
|
1634 HBITMAP mask,
|
|
1635 Lisp_Object mask_filename)
|
|
1636 {
|
|
1637 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
290
|
1638 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (device)));
|
288
|
1639 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1640 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
|
|
1641 enum image_instance_type type;
|
290
|
1642 COLORREF black = PALETTERGB (0,0,0);
|
|
1643 COLORREF white = PALETTERGB (255,255,255);
|
|
1644
|
|
1645 HDC hdc = FRAME_MSWINDOWS_CDC (f);
|
288
|
1646
|
|
1647 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
1648 signal_simple_error ("Not an MS-Windows device", device);
|
|
1649
|
|
1650 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
|
|
1651 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
1652 {
|
|
1653 if (!NILP (foreground) || !NILP (background))
|
|
1654 type = IMAGE_COLOR_PIXMAP;
|
|
1655 else
|
|
1656 type = IMAGE_MONO_PIXMAP;
|
|
1657 }
|
|
1658 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
1659 type = IMAGE_MONO_PIXMAP;
|
|
1660 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1661 type = IMAGE_COLOR_PIXMAP;
|
|
1662 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
1663 type = IMAGE_POINTER;
|
|
1664 else
|
|
1665 incompatible_image_types (instantiator, dest_mask,
|
|
1666 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
1667 | IMAGE_POINTER_MASK);
|
|
1668
|
|
1669 mswindows_initialize_dibitmap_image_instance (ii, type);
|
290
|
1670
|
288
|
1671 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
1672 find_keyword_in_vector (instantiator, Q_file);
|
290
|
1673 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
1674 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
1675 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
|
288
|
1676 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
|
|
1677 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
|
290
|
1678 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = mask ? mask :
|
|
1679 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
|
|
1680 TRUE, black, white);
|
288
|
1681
|
|
1682 switch (type)
|
|
1683 {
|
|
1684 case IMAGE_MONO_PIXMAP:
|
290
|
1685 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
|
|
1686 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
|
|
1687 FALSE, black, black);
|
288
|
1688 break;
|
|
1689
|
|
1690 case IMAGE_COLOR_PIXMAP:
|
|
1691 {
|
290
|
1692 COLORREF fg = black;
|
|
1693 COLORREF bg = white;
|
288
|
1694
|
|
1695 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
|
|
1696 foreground =
|
|
1697 Fmake_color_instance (foreground, device,
|
|
1698 encode_error_behavior_flag (ERROR_ME));
|
|
1699
|
|
1700 if (COLOR_INSTANCEP (foreground))
|
|
1701 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
|
|
1702
|
|
1703 if (!NILP (background) && !COLOR_INSTANCEP (background))
|
|
1704 background =
|
|
1705 Fmake_color_instance (background, device,
|
|
1706 encode_error_behavior_flag (ERROR_ME));
|
|
1707
|
|
1708 if (COLOR_INSTANCEP (background))
|
|
1709 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
|
|
1710
|
|
1711 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
1712 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
290
|
1713
|
|
1714 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
|
|
1715 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
|
|
1716 FALSE, fg, black);
|
288
|
1717 }
|
|
1718 break;
|
|
1719
|
|
1720 case IMAGE_POINTER:
|
|
1721 {
|
290
|
1722 COLORREF fg = black;
|
|
1723 COLORREF bg = white;
|
|
1724
|
288
|
1725 if (NILP (foreground))
|
|
1726 foreground = pointer_fg;
|
|
1727 if (NILP (background))
|
|
1728 background = pointer_bg;
|
|
1729
|
290
|
1730 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii),
|
|
1731 find_keyword_in_vector (instantiator, Q_hotspot_x));
|
|
1732 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii),
|
|
1733 find_keyword_in_vector (instantiator, Q_hotspot_y));
|
288
|
1734 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
1735 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
290
|
1736 if (COLOR_INSTANCEP (foreground))
|
|
1737 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground));
|
|
1738 if (COLOR_INSTANCEP (background))
|
|
1739 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background));
|
|
1740
|
|
1741 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) =
|
|
1742 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height,
|
|
1743 TRUE, fg, black);
|
|
1744 mswindows_initialize_image_instance_icon (ii, TRUE);
|
288
|
1745 }
|
|
1746 break;
|
|
1747
|
|
1748 default:
|
|
1749 abort ();
|
|
1750 }
|
|
1751 }
|
|
1752
|
|
1753 static void
|
|
1754 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1755 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1756 int dest_mask, int width, int height,
|
|
1757 /* Note that data is in ext-format! */
|
|
1758 CONST char *bits)
|
|
1759 {
|
|
1760 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
|
|
1761 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
|
|
1762 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
290
|
1763 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME
|
|
1764 (XDEVICE (IMAGE_INSTANCE_DEVICE (ii))));
|
|
1765 HDC hdc = FRAME_MSWINDOWS_CDC (f);
|
288
|
1766 HBITMAP mask = 0;
|
|
1767 CONST char *gcc_may_you_rot_in_hell;
|
|
1768
|
|
1769 if (!NILP (mask_data))
|
|
1770 {
|
|
1771 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))),
|
|
1772 gcc_may_you_rot_in_hell);
|
|
1773 mask =
|
290
|
1774 xbm_create_bitmap_from_data ( hdc,
|
|
1775 (unsigned char *)
|
288
|
1776 gcc_may_you_rot_in_hell,
|
|
1777 XINT (XCAR (mask_data)),
|
290
|
1778 XINT (XCAR (XCDR (mask_data))), FALSE,
|
|
1779 PALETTERGB (0,0,0),
|
|
1780 PALETTERGB (255,255,255));
|
288
|
1781 }
|
|
1782
|
|
1783 init_image_instance_from_xbm_inline (ii, width, height, bits,
|
|
1784 instantiator, pointer_fg, pointer_bg,
|
|
1785 dest_mask, mask, mask_file);
|
|
1786 }
|
|
1787
|
|
1788 /* Instantiate method for XBM's. */
|
|
1789
|
|
1790 static void
|
|
1791 mswindows_xbm_instantiate (Lisp_Object image_instance,
|
|
1792 Lisp_Object instantiator,
|
|
1793 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1794 int dest_mask, Lisp_Object domain)
|
|
1795 {
|
|
1796 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1797 CONST char *gcc_go_home;
|
|
1798
|
|
1799 assert (!NILP (data));
|
|
1800
|
|
1801 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (data))),
|
|
1802 gcc_go_home);
|
|
1803
|
|
1804 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1805 pointer_bg, dest_mask, XINT (XCAR (data)),
|
|
1806 XINT (XCAR (XCDR (data))), gcc_go_home);
|
|
1807 }
|
|
1808
|
284
|
1809
|
267
|
1810 /************************************************************************/
|
|
1811 /* image instance methods */
|
|
1812 /************************************************************************/
|
|
1813
|
|
1814 static void
|
|
1815 mswindows_print_image_instance (struct Lisp_Image_Instance *p,
|
|
1816 Lisp_Object printcharfun,
|
|
1817 int escapeflag)
|
|
1818 {
|
|
1819 char buf[100];
|
|
1820
|
|
1821 switch (IMAGE_INSTANCE_TYPE (p))
|
|
1822 {
|
|
1823 case IMAGE_MONO_PIXMAP:
|
|
1824 case IMAGE_COLOR_PIXMAP:
|
|
1825 case IMAGE_POINTER:
|
|
1826 sprintf (buf, " (0x%lx",
|
|
1827 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
|
1828 write_c_string (buf, printcharfun);
|
|
1829 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
1830 {
|
|
1831 sprintf (buf, "/0x%lx",
|
|
1832 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
1833 write_c_string (buf, printcharfun);
|
|
1834 }
|
|
1835 write_c_string (")", printcharfun);
|
|
1836 break;
|
|
1837 default:
|
|
1838 break;
|
|
1839 }
|
|
1840 }
|
|
1841
|
|
1842 static void
|
|
1843 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
1844 {
|
|
1845 if (!p->data)
|
|
1846 return;
|
|
1847
|
|
1848 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
1849 {
|
|
1850 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
|
269
|
1851 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
267
|
1852 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
|
272
|
1853 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
1854 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
1855 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
|
|
1856 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
|
|
1857 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
|
|
1858 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
|
267
|
1859 }
|
|
1860
|
|
1861 xfree (p->data);
|
|
1862 p->data = 0;
|
|
1863 }
|
|
1864
|
|
1865 static int
|
|
1866 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
1867 struct Lisp_Image_Instance *p2, int depth)
|
|
1868 {
|
|
1869 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
1870 {
|
|
1871 case IMAGE_MONO_PIXMAP:
|
|
1872 case IMAGE_COLOR_PIXMAP:
|
|
1873 case IMAGE_POINTER:
|
|
1874 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
|
|
1875 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
|
|
1876 return 0;
|
|
1877 break;
|
|
1878 default:
|
|
1879 break;
|
|
1880 }
|
|
1881
|
|
1882 return 1;
|
|
1883 }
|
|
1884
|
|
1885 static unsigned long
|
|
1886 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
1887 {
|
|
1888 switch (IMAGE_INSTANCE_TYPE (p))
|
|
1889 {
|
|
1890 case IMAGE_MONO_PIXMAP:
|
|
1891 case IMAGE_COLOR_PIXMAP:
|
|
1892 case IMAGE_POINTER:
|
|
1893 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
|
|
1894 default:
|
|
1895 return 0;
|
|
1896 }
|
|
1897 }
|
|
1898
|
|
1899 /* Set all the slots in an image instance structure to reasonable
|
|
1900 default values. This is used somewhere within an instantiate
|
|
1901 method. It is assumed that the device slot within the image
|
|
1902 instance is already set -- this is the case when instantiate
|
|
1903 methods are called. */
|
|
1904
|
|
1905 static void
|
|
1906 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
1907 enum image_instance_type type)
|
|
1908 {
|
|
1909 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
|
|
1910 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
1911 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
1912 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
1913 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
1914 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
1915 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
1916 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
1917 }
|
|
1918
|
|
1919
|
|
1920 /************************************************************************/
|
|
1921 /* initialization */
|
|
1922 /************************************************************************/
|
|
1923
|
|
1924 void
|
|
1925 syms_of_glyphs_mswindows (void)
|
|
1926 {
|
284
|
1927 defkeyword (&Q_resource_id, ":resource-id");
|
|
1928 defkeyword (&Q_resource_type, ":resource-type");
|
267
|
1929 }
|
|
1930
|
|
1931 void
|
|
1932 console_type_create_glyphs_mswindows (void)
|
|
1933 {
|
|
1934 /* image methods */
|
|
1935
|
|
1936 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
|
|
1937 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
|
|
1938 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
|
|
1939 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
|
278
|
1940 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
|
|
1941 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
|
280
|
1942 #ifdef HAVE_XPM
|
|
1943 CONSOLE_HAS_METHOD (mswindows, xpm_instantiate);
|
|
1944 #endif
|
288
|
1945 CONSOLE_HAS_METHOD (mswindows, xbm_instantiate);
|
267
|
1946 }
|
|
1947
|
|
1948 void
|
|
1949 image_instantiator_format_create_glyphs_mswindows (void)
|
|
1950 {
|
|
1951 /* image-instantiator types */
|
|
1952
|
|
1953 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
|
|
1954
|
|
1955 IIFORMAT_HAS_METHOD (bmp, validate);
|
|
1956 IIFORMAT_HAS_METHOD (bmp, normalize);
|
|
1957 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
|
|
1958 IIFORMAT_HAS_METHOD (bmp, instantiate);
|
|
1959
|
|
1960 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
|
|
1961 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
|
284
|
1962
|
286
|
1963 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (resource, "resource");
|
284
|
1964
|
286
|
1965 IIFORMAT_HAS_METHOD (resource, validate);
|
|
1966 IIFORMAT_HAS_METHOD (resource, normalize);
|
|
1967 IIFORMAT_HAS_METHOD (resource, possible_dest_types);
|
|
1968 IIFORMAT_HAS_METHOD (resource, instantiate);
|
284
|
1969
|
286
|
1970 IIFORMAT_VALID_KEYWORD (resource, Q_resource_type,
|
|
1971 check_valid_resource_symbol);
|
|
1972 IIFORMAT_VALID_KEYWORD (resource, Q_resource_id, check_valid_resource_id);
|
|
1973 IIFORMAT_VALID_KEYWORD (resource, Q_file, check_valid_string);
|
267
|
1974 }
|
|
1975
|
|
1976 void
|
|
1977 vars_of_glyphs_mswindows (void)
|
|
1978 {
|
|
1979 Fprovide (Qbmp);
|
286
|
1980 Fprovide (Qresource);
|
267
|
1981 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
|
|
1982 A list of the directories in which mswindows bitmap files may be found.
|
|
1983 This is used by the `make-image-instance' function.
|
|
1984 */ );
|
|
1985 Vmswindows_bitmap_file_path = Qnil;
|
|
1986 }
|
|
1987
|
|
1988 void
|
|
1989 complex_vars_of_glyphs_mswindows (void)
|
|
1990 {
|
|
1991 }
|