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"
|
|
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 FILE_CODING
|
|
42 #include "file-coding.h"
|
|
43 #endif
|
|
44
|
|
45 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
|
|
46 Lisp_Object Qbmp;
|
|
47 Lisp_Object Vmswindows_bitmap_file_path;
|
282
|
48 static COLORREF transparent_color = RGB (1,1,1);
|
267
|
49
|
284
|
50 DEFINE_IMAGE_INSTANTIATOR_FORMAT (cursor);
|
|
51 Lisp_Object Qcursor;
|
|
52 Lisp_Object Q_resource_type, Q_resource_id;
|
|
53
|
267
|
54 static void
|
|
55 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
56 enum image_instance_type type);
|
282
|
57 static void
|
|
58 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
|
|
59 struct frame* f);
|
267
|
60
|
269
|
61 COLORREF mswindows_string_to_color (CONST char *name);
|
267
|
62
|
|
63 /************************************************************************/
|
|
64 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/
|
|
65 /* proper display */
|
|
66 /************************************************************************/
|
278
|
67 static BITMAPINFO* convert_EImage_to_DIBitmap (Lisp_Object device,
|
|
68 int width, int height,
|
|
69 unsigned char *pic,
|
|
70 int *bit_count,
|
|
71 unsigned char** bmp_data)
|
267
|
72 {
|
|
73 struct device *d = XDEVICE (device);
|
269
|
74 int i,j;
|
267
|
75 RGBQUAD* colortbl;
|
|
76 int ncolors;
|
|
77 BITMAPINFO* bmp_info;
|
269
|
78 unsigned char *ip, *dp;
|
267
|
79
|
269
|
80 if (DEVICE_MSWINDOWS_BITSPIXEL (d) > 0)
|
267
|
81 {
|
269
|
82 int bpline=(int)(~3UL & (unsigned long)((width*3) +3));
|
267
|
83 /* FIXME: we can do this because 24bpp implies no colour table, once
|
|
84 * we start paletizing this is no longer true. The X versions of
|
|
85 * this function quantises to 256 colours or bit masks down to a
|
|
86 * long. Windows can actually handle rgb triples in the raw so I
|
272
|
87 * don't see much point trying to optimize down to the best
|
267
|
88 * structure - unless it has memory / color allocation implications
|
|
89 * .... */
|
269
|
90 bmp_info=xnew_and_zero (BITMAPINFO);
|
267
|
91
|
|
92 if (!bmp_info)
|
|
93 {
|
|
94 return NULL;
|
|
95 }
|
|
96
|
|
97 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */
|
|
98 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */
|
|
99 bmp_info->bmiHeader.biSizeImage=width*height*3;
|
|
100
|
|
101 /* bitmap data needs to be in blue, green, red triples - in that
|
|
102 order, eimage is in RGB format so we need to convert */
|
272
|
103 *bmp_data = xnew_array_and_zero (unsigned char, bpline * height);
|
278
|
104 *bit_count = bpline * height;
|
267
|
105
|
|
106 if (!bmp_data)
|
|
107 {
|
272
|
108 xfree (bmp_info);
|
267
|
109 return NULL;
|
|
110 }
|
272
|
111
|
|
112 ip = pic;
|
|
113 for (i = height-1; i >= 0; i--) {
|
|
114 dp = (*bmp_data) + (i * bpline);
|
|
115 for (j = 0; j < width; j++) {
|
|
116 dp[2] =*ip++;
|
|
117 dp[1] =*ip++;
|
|
118 *dp =*ip++;
|
|
119 dp += 3;
|
267
|
120 }
|
272
|
121 }
|
267
|
122 }
|
|
123 else /* scale to 256 colors */
|
|
124 {
|
272
|
125 int rd,gr,bl;
|
267
|
126 quant_table *qtable;
|
|
127 int bpline= (int)(~3UL & (unsigned long)(width +3));
|
|
128 /* Quantize the image and get a histogram while we're at it.
|
|
129 Do this first to save memory */
|
269
|
130 qtable = build_EImage_quantable(pic, width, height, 256);
|
267
|
131 if (qtable == NULL) return NULL;
|
|
132
|
|
133 /* use our quantize table to allocate the colors */
|
|
134 ncolors = qtable->num_active_colors;
|
272
|
135 bmp_info=(BITMAPINFO*)xmalloc_and_zero (sizeof(BITMAPINFOHEADER) +
|
267
|
136 sizeof(RGBQUAD) * ncolors);
|
|
137 if (!bmp_info)
|
|
138 {
|
272
|
139 xfree (qtable);
|
267
|
140 return NULL;
|
|
141 }
|
|
142
|
|
143 colortbl=(RGBQUAD*)(((unsigned char*)bmp_info)+sizeof(BITMAPINFOHEADER));
|
|
144
|
|
145 bmp_info->bmiHeader.biBitCount=8;
|
|
146 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
147 bmp_info->bmiHeader.biSizeImage=bpline*height;
|
|
148 bmp_info->bmiHeader.biClrUsed=ncolors;
|
|
149 bmp_info->bmiHeader.biClrImportant=ncolors;
|
|
150
|
|
151 *bmp_data = (unsigned char *) xmalloc_and_zero (bpline * height);
|
|
152 *bit_count = bpline * height;
|
|
153
|
|
154 if (!*bmp_data)
|
|
155 {
|
269
|
156 xfree (qtable);
|
|
157 xfree (bmp_info);
|
267
|
158 return NULL;
|
|
159 }
|
|
160
|
|
161 /* build up an RGBQUAD colortable */
|
|
162 for (i = 0; i < qtable->num_active_colors; i++) {
|
|
163 colortbl[i].rgbRed = qtable->rm[i];
|
|
164 colortbl[i].rgbGreen = qtable->gm[i];
|
|
165 colortbl[i].rgbBlue = qtable->bm[i];
|
|
166 colortbl[i].rgbReserved = 0;
|
|
167 }
|
|
168
|
|
169 /* now build up the data. picture has to be upside-down and
|
|
170 back-to-front for msw bitmaps */
|
|
171 ip = pic;
|
|
172 for (i = height-1; i >= 0; i--) {
|
|
173 dp = (*bmp_data) + (i * bpline);
|
|
174 for (j = 0; j < width; j++) {
|
|
175 rd = *ip++;
|
|
176 gr = *ip++;
|
|
177 bl = *ip++;
|
269
|
178 *dp++ = QUANT_GET_COLOR (qtable,rd,gr,bl);
|
267
|
179 }
|
|
180 }
|
269
|
181 xfree (qtable);
|
267
|
182 }
|
|
183 /* fix up the standard stuff */
|
|
184 bmp_info->bmiHeader.biWidth=width;
|
|
185 bmp_info->bmiHeader.biHeight=height;
|
|
186 bmp_info->bmiHeader.biPlanes=1;
|
|
187 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
269
|
188 bmp_info->bmiHeader.biXPelsPerMeter=0; /* unless you know better */
|
|
189 bmp_info->bmiHeader.biYPelsPerMeter=0;
|
267
|
190
|
|
191 return bmp_info;
|
|
192 }
|
|
193
|
|
194 /* Given a pixmap filename, look through all of the "standard" places
|
|
195 where the file might be located. Return a full pathname if found;
|
|
196 otherwise, return Qnil. */
|
|
197
|
280
|
198 static Lisp_Object
|
278
|
199 mswindows_locate_pixmap_file (Lisp_Object name)
|
267
|
200 {
|
|
201 /* This function can GC if IN_REDISPLAY is false */
|
276
|
202 Lisp_Object found;
|
267
|
203
|
|
204 /* Check non-absolute pathnames with a directory component relative to
|
|
205 the search path; that's the way Xt does it. */
|
269
|
206 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) ||
|
267
|
207 (XSTRING_BYTE (name, 0) == '.' &&
|
269
|
208 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 1)) ||
|
267
|
209 (XSTRING_BYTE (name, 1) == '.' &&
|
269
|
210 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 2)))))))
|
267
|
211 {
|
|
212 if (!NILP (Ffile_readable_p (name)))
|
|
213 return name;
|
|
214 else
|
|
215 return Qnil;
|
|
216 }
|
|
217
|
276
|
218 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
219 {
|
|
220 Lisp_Object temp = list1 (Vdata_directory);
|
|
221 struct gcpro gcpro1;
|
267
|
222
|
276
|
223 GCPRO1 (temp);
|
|
224 locate_file (temp, name, "", &found, R_OK);
|
|
225 UNGCPRO;
|
|
226 }
|
267
|
227
|
276
|
228 return found;
|
267
|
229 }
|
|
230
|
|
231
|
|
232 /* Initialize an image instance from a bitmap
|
|
233
|
|
234 DEST_MASK specifies the mask of allowed image types.
|
|
235
|
|
236 If this fails, signal an error. INSTANTIATOR is only used
|
|
237 in the error message. */
|
|
238
|
|
239 static void
|
|
240 init_image_instance_from_dibitmap (struct Lisp_Image_Instance *ii,
|
|
241 BITMAPINFO *bmp_info,
|
|
242 int dest_mask,
|
|
243 void *bmp_data,
|
|
244 int bmp_bits,
|
282
|
245 Lisp_Object instantiator,
|
|
246 int x_hot, int y_hot,
|
|
247 int create_mask)
|
267
|
248 {
|
|
249 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
250 struct device *d = XDEVICE (device);
|
269
|
251 struct frame *f = XFRAME (DEVICE_SELECTED_FRAME (d));
|
267
|
252 void* bmp_buf=0;
|
282
|
253 int type;
|
267
|
254 HBITMAP bitmap;
|
269
|
255 HDC hdc;
|
267
|
256
|
|
257 if (!DEVICE_MSWINDOWS_P (d))
|
|
258 signal_simple_error ("Not an mswindows device", device);
|
|
259
|
|
260 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
261 signal_simple_error ("No selected frame on mswindows device", device);
|
|
262
|
282
|
263 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
264 type = IMAGE_COLOR_PIXMAP;
|
|
265 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
266 type = IMAGE_POINTER;
|
|
267 else
|
267
|
268 incompatible_image_types (instantiator, dest_mask,
|
282
|
269 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
|
267
|
270 hdc = FRAME_MSWINDOWS_DC (f);
|
|
271
|
269
|
272 bitmap=CreateDIBSection (hdc,
|
267
|
273 bmp_info,
|
|
274 DIB_RGB_COLORS,
|
|
275 &bmp_buf,
|
|
276 0,0);
|
|
277
|
|
278 if (!bitmap || !bmp_buf)
|
|
279 signal_simple_error ("Unable to create bitmap", instantiator);
|
|
280
|
|
281 /* copy in the actual bitmap */
|
269
|
282 memcpy (bmp_buf, bmp_data, bmp_bits);
|
267
|
283
|
282
|
284 mswindows_initialize_dibitmap_image_instance (ii, type);
|
267
|
285
|
|
286 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
287 find_keyword_in_vector (instantiator, Q_file);
|
|
288
|
|
289 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap;
|
282
|
290 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
|
267
|
291 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth;
|
|
292 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight;
|
|
293 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount;
|
282
|
294 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), x_hot);
|
|
295 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), y_hot);
|
|
296
|
|
297 if (create_mask)
|
|
298 {
|
|
299 mswindows_initialize_image_instance_mask (ii, f);
|
|
300 }
|
|
301
|
|
302 if (type == IMAGE_POINTER)
|
|
303 {
|
|
304 mswindows_initialize_image_instance_icon(ii, TRUE);
|
|
305 }
|
267
|
306 }
|
|
307
|
278
|
308 static void
|
|
309 mswindows_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
|
|
310 int width, int height,
|
|
311 unsigned char *eimage,
|
|
312 int dest_mask,
|
|
313 Lisp_Object instantiator,
|
|
314 Lisp_Object domain)
|
|
315 {
|
|
316 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
317 BITMAPINFO* bmp_info;
|
|
318 unsigned char* bmp_data;
|
|
319 int bmp_bits;
|
|
320 COLORREF bkcolor;
|
|
321
|
|
322 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
323 signal_simple_error ("Not an mswindows device", device);
|
|
324
|
|
325 /* this is a hack but MaskBlt and TransparentBlt are not supported
|
|
326 on most windows variants */
|
|
327 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
328 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
|
|
329
|
|
330 /* build a bitmap from the eimage */
|
|
331 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
332 &bmp_bits, &bmp_data)))
|
|
333 {
|
|
334 signal_simple_error ("EImage to DIBitmap conversion failed",
|
|
335 instantiator);
|
|
336 }
|
|
337
|
|
338 /* Now create the pixmap and set up the image instance */
|
|
339 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
282
|
340 bmp_data, bmp_bits, instantiator,
|
|
341 0, 0, 0);
|
278
|
342
|
|
343 xfree (bmp_info);
|
|
344 xfree (bmp_data);
|
|
345 }
|
|
346
|
282
|
347 static void set_mono_pixel ( unsigned char* bits,
|
|
348 int bpline, int height,
|
|
349 int x, int y, int white )
|
|
350 {
|
|
351 int index;
|
|
352 unsigned char bitnum;
|
|
353 /* Find the byte on which this scanline begins */
|
|
354 index = (height - y - 1) * bpline;
|
|
355 /* Find the byte containing this pixel */
|
|
356 index += (x >> 3);
|
|
357 /* Which bit is it? */
|
|
358 bitnum = (unsigned char)( 7 - (x % 8) );
|
|
359 if( white ) /* Turn it on */
|
|
360 bits[index] |= (1<<bitnum);
|
|
361 else /* Turn it off */
|
|
362 bits[index] &= ~(1<<bitnum);
|
|
363 }
|
|
364
|
|
365 static void
|
|
366 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
|
|
367 struct frame* f)
|
276
|
368 {
|
284
|
369 HBITMAP mask;
|
|
370 HGDIOBJ old = NULL;
|
276
|
371 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
282
|
372 BITMAPINFO* bmp_info =
|
284
|
373 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD));
|
282
|
374 int i, j;
|
|
375 int height = IMAGE_INSTANCE_PIXMAP_HEIGHT (image);
|
276
|
376
|
282
|
377 void* and_bits;
|
|
378 int bpline= (int)(~3UL & (unsigned long)
|
|
379 (((IMAGE_INSTANCE_PIXMAP_WIDTH (image)+7)/8) +3));
|
|
380
|
|
381 bmp_info->bmiHeader.biWidth=IMAGE_INSTANCE_PIXMAP_WIDTH (image);
|
|
382 bmp_info->bmiHeader.biHeight = height;
|
|
383 bmp_info->bmiHeader.biPlanes=1;
|
|
384 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
|
385 bmp_info->bmiHeader.biBitCount=1;
|
|
386 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
387 bmp_info->bmiHeader.biClrUsed = 2;
|
|
388 bmp_info->bmiHeader.biClrImportant = 2;
|
|
389 bmp_info->bmiHeader.biSizeImage = height * bpline;
|
|
390 bmp_info->bmiColors[0].rgbRed = 0;
|
|
391 bmp_info->bmiColors[0].rgbGreen = 0;
|
|
392 bmp_info->bmiColors[0].rgbBlue = 0;
|
|
393 bmp_info->bmiColors[0].rgbReserved = 0;
|
|
394 bmp_info->bmiColors[1].rgbRed = 255;
|
|
395 bmp_info->bmiColors[1].rgbGreen = 255;
|
|
396 bmp_info->bmiColors[1].rgbBlue = 255;
|
|
397 bmp_info->bmiColors[0].rgbReserved = 0;
|
|
398
|
|
399 if (!(mask = CreateDIBSection (hcdc,
|
|
400 bmp_info,
|
|
401 DIB_RGB_COLORS,
|
|
402 &and_bits,
|
|
403 0,0)))
|
276
|
404 {
|
282
|
405 xfree (bmp_info);
|
|
406 return;
|
276
|
407 }
|
|
408
|
282
|
409 xfree (bmp_info);
|
284
|
410 old = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (image));
|
276
|
411
|
282
|
412 for(i=0; i<IMAGE_INSTANCE_PIXMAP_WIDTH (image); i++)
|
|
413 {
|
|
414 for(j=0; j<height; j++)
|
|
415 {
|
|
416 if( GetPixel( hcdc, i, j ) == transparent_color )
|
|
417 {
|
|
418 SetPixel( hcdc, i, j, RGB (0,0,0));
|
|
419 set_mono_pixel( and_bits, bpline, height, i, j, TRUE );
|
|
420 }
|
|
421 else
|
|
422 {
|
|
423 set_mono_pixel( and_bits, bpline, height, i, j, FALSE );
|
|
424 }
|
|
425 }
|
276
|
426 }
|
|
427
|
282
|
428 GdiFlush();
|
284
|
429 SelectObject(hcdc, old);
|
282
|
430
|
|
431 IMAGE_INSTANCE_MSWINDOWS_MASK (image) = mask;
|
|
432 }
|
|
433
|
|
434 void
|
|
435 mswindows_initialize_image_instance_icon (struct Lisp_Image_Instance* image,
|
|
436 int cursor)
|
|
437 {
|
|
438 ICONINFO x_icon;
|
|
439
|
|
440 /* we rely on windows to do any resizing necessary */
|
|
441 x_icon.fIcon=cursor ? FALSE : TRUE;
|
|
442 x_icon.xHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image));
|
|
443 x_icon.yHotspot=XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image));
|
|
444 x_icon.hbmMask=IMAGE_INSTANCE_MSWINDOWS_MASK (image);
|
|
445 x_icon.hbmColor=IMAGE_INSTANCE_MSWINDOWS_BITMAP (image);
|
276
|
446
|
282
|
447 IMAGE_INSTANCE_MSWINDOWS_ICON (image)=
|
276
|
448 CreateIconIndirect (&x_icon);
|
|
449 }
|
|
450
|
|
451 int
|
|
452 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii,
|
|
453 struct frame* f,
|
|
454 int newx, int newy)
|
|
455 {
|
284
|
456 HBITMAP newbmp, newmask=NULL;
|
276
|
457 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
|
458 HDC hdcDst = CreateCompatibleDC (hcdc);
|
|
459
|
284
|
460 SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
276
|
461
|
284
|
462 newbmp = CreateCompatibleBitmap (hcdc, newx, newy);
|
276
|
463
|
284
|
464 DeleteObject (SelectObject (hdcDst, newbmp) );
|
276
|
465
|
284
|
466 if (!StretchBlt (hdcDst, 0, 0, newx, newy,
|
|
467 hcdc, 0, 0,
|
|
468 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
469 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
470 SRCCOPY))
|
276
|
471 {
|
|
472 return FALSE;
|
|
473 }
|
284
|
474
|
|
475 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
|
|
476 {
|
|
477 SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
|
|
478 newmask = CreateCompatibleBitmap(hcdc, newx, newy);
|
|
479 SelectObject (hdcDst, newmask);
|
|
480
|
|
481 if (!StretchBlt(hdcDst, 0, 0, newx, newy,
|
|
482 hcdc, 0, 0,
|
|
483 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
484 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
485 SRCCOPY))
|
|
486 {
|
|
487 return FALSE;
|
|
488 }
|
|
489 }
|
|
490
|
|
491 SelectObject (hdcDst, 0);
|
|
492 SelectObject (hcdc, 0);
|
276
|
493
|
|
494 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii))
|
|
495 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
|
496 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
|
|
497 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
|
|
498
|
|
499 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp;
|
284
|
500 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newmask;
|
276
|
501 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx;
|
|
502 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy;
|
|
503
|
284
|
504 DeleteDC (hdcDst);
|
276
|
505
|
|
506 return TRUE;
|
|
507 }
|
|
508
|
267
|
509 /**********************************************************************
|
|
510 * XPM *
|
|
511 **********************************************************************/
|
|
512
|
|
513 #ifdef HAVE_XPM
|
280
|
514
|
|
515 struct color_symbol
|
|
516 {
|
|
517 char* name;
|
|
518 COLORREF color;
|
|
519 };
|
|
520
|
|
521 static struct color_symbol*
|
|
522 extract_xpm_color_names (Lisp_Object device,
|
|
523 Lisp_Object domain,
|
|
524 Lisp_Object color_symbol_alist,
|
|
525 int* nsymbols)
|
|
526 {
|
|
527 /* This function can GC */
|
|
528 Lisp_Object rest;
|
|
529 Lisp_Object results = Qnil;
|
|
530 int i, j;
|
|
531 struct color_symbol *colortbl;
|
|
532 struct gcpro gcpro1, gcpro2;
|
|
533
|
|
534 GCPRO2 (results, device);
|
|
535
|
|
536 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
537 error happens we don't lose any malloc()ed data, or more importantly,
|
|
538 leave any pixels allocated in the server. */
|
|
539 i = 0;
|
|
540 LIST_LOOP (rest, color_symbol_alist)
|
|
541 {
|
|
542 Lisp_Object cons = XCAR (rest);
|
|
543 Lisp_Object name = XCAR (cons);
|
|
544 Lisp_Object value = XCDR (cons);
|
|
545 if (NILP (value))
|
|
546 continue;
|
|
547 if (STRINGP (value))
|
|
548 value =
|
|
549 Fmake_color_instance
|
|
550 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
|
|
551 else
|
|
552 {
|
|
553 assert (COLOR_SPECIFIERP (value));
|
|
554 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
|
555 }
|
|
556 if (NILP (value))
|
|
557 continue;
|
|
558 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
559 i++;
|
|
560 }
|
|
561 UNGCPRO; /* no more evaluation */
|
|
562
|
|
563 *nsymbols=i;
|
|
564 if (i == 0) return 0;
|
|
565
|
|
566 colortbl = xnew_array_and_zero (struct color_symbol, i);
|
|
567
|
|
568 for (j=0; j<i; j++)
|
|
569 {
|
|
570 Lisp_Object cons = XCAR (results);
|
|
571 colortbl[j].color =
|
|
572 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
573
|
|
574 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons));
|
|
575 free_cons (XCONS (cons));
|
|
576 cons = results;
|
|
577 results = XCDR (results);
|
|
578 free_cons (XCONS (cons));
|
|
579 }
|
|
580 return colortbl;
|
|
581 }
|
|
582
|
269
|
583 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer,
|
276
|
584 unsigned char** data,
|
|
585 int* width, int* height,
|
|
586 int* x_hot, int* y_hot,
|
282
|
587 int* transp,
|
|
588 struct color_symbol* color_symbols,
|
280
|
589 int nsymbols)
|
267
|
590 {
|
|
591 XpmImage xpmimage;
|
|
592 XpmInfo xpminfo;
|
280
|
593 int result, i, j, transp_idx, maskbpline;
|
267
|
594 unsigned char* dptr;
|
|
595 unsigned int* sptr;
|
|
596 COLORREF color; /* the american spelling virus hits again .. */
|
|
597 COLORREF* colortbl;
|
|
598
|
272
|
599 xzero (xpmimage);
|
|
600 xzero (xpminfo);
|
276
|
601 xpminfo.valuemask=XpmHotspot;
|
282
|
602 *transp=FALSE;
|
276
|
603
|
269
|
604 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
|
267
|
605 &xpmimage,
|
|
606 &xpminfo);
|
269
|
607 switch (result)
|
267
|
608 {
|
|
609 case XpmSuccess:
|
|
610 break;
|
|
611 case XpmFileInvalid:
|
|
612 {
|
|
613 signal_simple_error ("invalid XPM data", image);
|
|
614 }
|
|
615 case XpmNoMemory:
|
|
616 {
|
|
617 signal_double_file_error ("Parsing pixmap data",
|
|
618 "out of memory", image);
|
|
619 }
|
|
620 default:
|
|
621 {
|
|
622 signal_double_file_error_2 ("Parsing pixmap data",
|
|
623 "unknown error code",
|
|
624 make_int (result), image);
|
|
625 }
|
|
626 }
|
|
627
|
|
628 *width = xpmimage.width;
|
|
629 *height = xpmimage.height;
|
276
|
630 maskbpline = (int)(~3UL & (unsigned long)
|
|
631 (((~7UL & (unsigned long)(*width + 7)) / 8) + 3));
|
|
632
|
|
633 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
|
267
|
634
|
|
635 if (!*data)
|
|
636 {
|
269
|
637 XpmFreeXpmImage (&xpmimage);
|
|
638 XpmFreeXpmInfo (&xpminfo);
|
267
|
639 return 0;
|
|
640 }
|
|
641
|
|
642 /* build a color table to speed things up */
|
|
643 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
|
|
644 if (!colortbl)
|
|
645 {
|
269
|
646 xfree (*data);
|
|
647 XpmFreeXpmImage (&xpmimage);
|
|
648 XpmFreeXpmInfo (&xpminfo);
|
267
|
649 return 0;
|
|
650 }
|
|
651
|
|
652 for (i=0; i<xpmimage.ncolors; i++)
|
|
653 {
|
280
|
654 /* pick up symbolic colors */
|
|
655 if (xpmimage.colorTable[i].c_color == 0
|
|
656 &&
|
|
657 xpmimage.colorTable[i].symbolic != 0)
|
|
658 {
|
|
659 if (!color_symbols)
|
|
660 {
|
|
661 xfree (*data);
|
|
662 xfree (colortbl);
|
|
663 XpmFreeXpmImage (&xpmimage);
|
|
664 XpmFreeXpmInfo (&xpminfo);
|
|
665 return 0;
|
|
666 }
|
|
667 for (j = 0; j<nsymbols; j++)
|
|
668 {
|
|
669 if (!strcmp (xpmimage.colorTable[i].symbolic,
|
|
670 color_symbols[j].name ))
|
|
671 {
|
|
672 colortbl[i]=color_symbols[j].color;
|
|
673 }
|
|
674 }
|
|
675 }
|
267
|
676 /* pick up transparencies */
|
282
|
677 else if (!strcasecmp (xpmimage.colorTable[i].c_color,"None")
|
|
678 ||
|
284
|
679 (xpmimage.colorTable[i].symbolic
|
|
680 &&
|
|
681 (!strcasecmp (xpmimage.colorTable[i].symbolic,"BgColor")
|
|
682 ||
|
|
683 !strcasecmp (xpmimage.colorTable[i].symbolic,"None"))))
|
267
|
684 {
|
282
|
685 *transp=TRUE;
|
|
686 colortbl[i]=transparent_color;
|
276
|
687 transp_idx=i;
|
267
|
688 }
|
|
689 else
|
|
690 {
|
|
691 colortbl[i]=
|
269
|
692 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
|
267
|
693 }
|
|
694 }
|
|
695
|
|
696 /* convert the image */
|
|
697 sptr=xpmimage.data;
|
|
698 dptr=*data;
|
|
699 for (i = 0; i< *width * *height; i++)
|
|
700 {
|
|
701 color = colortbl[*sptr++];
|
|
702
|
|
703 /* split out the 0x02bbggrr colorref into an rgb triple */
|
269
|
704 *dptr++=GetRValue (color); /* red */
|
|
705 *dptr++=GetGValue (color); /* green */
|
|
706 *dptr++=GetBValue (color); /* blue */
|
267
|
707 }
|
|
708
|
276
|
709 *x_hot=xpminfo.x_hotspot;
|
|
710 *y_hot=xpminfo.y_hotspot;
|
|
711
|
269
|
712 XpmFreeXpmImage (&xpmimage);
|
|
713 XpmFreeXpmInfo (&xpminfo);
|
|
714 xfree (colortbl);
|
267
|
715 return TRUE;
|
|
716 }
|
|
717
|
280
|
718 static void
|
267
|
719 mswindows_xpm_instantiate (Lisp_Object image_instance,
|
|
720 Lisp_Object instantiator,
|
|
721 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
722 int dest_mask, Lisp_Object domain)
|
|
723 {
|
|
724 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
725 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
726 CONST Extbyte *bytes;
|
|
727 Extcount len;
|
|
728 unsigned char *eimage;
|
276
|
729 int width, height, x_hot, y_hot;
|
267
|
730 BITMAPINFO* bmp_info;
|
|
731 unsigned char* bmp_data;
|
|
732 int bmp_bits;
|
282
|
733 int nsymbols=0, transp;
|
280
|
734 struct color_symbol* color_symbols=NULL;
|
267
|
735
|
|
736 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
280
|
737 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
738 Q_color_symbols);
|
267
|
739
|
|
740 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
741 signal_simple_error ("Not an mswindows device", device);
|
|
742
|
|
743 assert (!NILP (data));
|
|
744
|
|
745 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
746
|
280
|
747 /* in case we have color symbols */
|
|
748 color_symbols = extract_xpm_color_names (device, domain,
|
|
749 color_symbol_alist, &nsymbols);
|
|
750
|
267
|
751 /* convert to an eimage to make processing easier */
|
269
|
752 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
|
282
|
753 &x_hot, &y_hot, &transp, color_symbols, nsymbols))
|
267
|
754 {
|
|
755 signal_simple_error ("XPM to EImage conversion failed",
|
|
756 image_instance);
|
|
757 }
|
|
758
|
280
|
759 if (color_symbols)
|
|
760 xfree(color_symbols);
|
|
761
|
267
|
762 /* build a bitmap from the eimage */
|
278
|
763 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
764 &bmp_bits, &bmp_data)))
|
267
|
765 {
|
|
766 signal_simple_error ("XPM to EImage conversion failed",
|
|
767 image_instance);
|
|
768 }
|
269
|
769 xfree (eimage);
|
267
|
770
|
|
771 /* Now create the pixmap and set up the image instance */
|
|
772 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
282
|
773 bmp_data, bmp_bits, instantiator,
|
|
774 x_hot, y_hot, transp);
|
267
|
775
|
269
|
776 xfree (bmp_info);
|
|
777 xfree (bmp_data);
|
267
|
778 }
|
|
779 #endif /* HAVE_XPM */
|
|
780
|
|
781 /**********************************************************************
|
|
782 * BMP *
|
|
783 **********************************************************************/
|
|
784
|
|
785 static void
|
|
786 bmp_validate (Lisp_Object instantiator)
|
|
787 {
|
|
788 file_or_data_must_be_present (instantiator);
|
|
789 }
|
|
790
|
|
791 static Lisp_Object
|
|
792 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
793 {
|
|
794 return simple_image_type_normalize (inst, console_type, Qbmp);
|
|
795 }
|
|
796
|
|
797 static int
|
|
798 bmp_possible_dest_types (void)
|
|
799 {
|
|
800 return IMAGE_COLOR_PIXMAP_MASK;
|
|
801 }
|
|
802
|
|
803 static void
|
|
804 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
805 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
806 int dest_mask, Lisp_Object domain)
|
|
807 {
|
|
808 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
809 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
810 CONST Extbyte *bytes;
|
|
811 Extcount len;
|
|
812 BITMAPFILEHEADER* bmp_file_header;
|
|
813 BITMAPINFO* bmp_info;
|
|
814 void* bmp_data;
|
|
815 int bmp_bits;
|
|
816 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
817
|
|
818 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
819 signal_simple_error ("Not an mswindows device", device);
|
|
820
|
|
821 assert (!NILP (data));
|
|
822
|
|
823 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
824
|
|
825 /* Then slurp the image into memory, decoding along the way.
|
|
826 The result is the image in a simple one-byte-per-pixel
|
|
827 format. */
|
|
828
|
|
829 bmp_file_header=(BITMAPFILEHEADER*)bytes;
|
|
830 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
|
|
831 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
|
|
832 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
|
|
833
|
|
834 /* Now create the pixmap and set up the image instance */
|
|
835 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
282
|
836 bmp_data, bmp_bits, instantiator,
|
|
837 0, 0, 0);
|
267
|
838 }
|
|
839
|
|
840
|
284
|
841 /**********************************************************************
|
|
842 * CURSORS *
|
|
843 **********************************************************************/
|
|
844
|
|
845 static void
|
|
846 cursor_validate (Lisp_Object instantiator)
|
|
847 {
|
|
848 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
|
|
849 &&
|
|
850 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
|
|
851 ||
|
|
852 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
|
|
853 signal_simple_error ("Must supply :file, :resource-id and :resource-type",
|
|
854 instantiator);
|
|
855 }
|
|
856
|
|
857 static Lisp_Object
|
|
858 cursor_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
859 {
|
|
860 /* This function can call lisp */
|
|
861 Lisp_Object file = Qnil;
|
|
862 struct gcpro gcpro1, gcpro2;
|
|
863 Lisp_Object alist = Qnil;
|
|
864
|
|
865 GCPRO2 (file, alist);
|
|
866
|
|
867 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
868 console_type);
|
|
869
|
|
870 if (CONSP (file)) /* failure locating filename */
|
|
871 signal_double_file_error ("Opening pixmap file",
|
|
872 "no such file or directory",
|
|
873 Fcar (file));
|
|
874
|
|
875 if (NILP (file)) /* no conversion necessary */
|
|
876 RETURN_UNGCPRO (inst);
|
|
877
|
|
878 alist = tagged_vector_to_alist (inst);
|
|
879
|
|
880 {
|
|
881 alist = remassq_no_quit (Q_file, alist);
|
|
882 alist = Fcons (Fcons (Q_file, file), alist);
|
|
883 }
|
|
884
|
|
885 {
|
|
886 Lisp_Object result = alist_to_tagged_vector (Qcursor, alist);
|
|
887 free_alist (alist);
|
|
888 RETURN_UNGCPRO (result);
|
|
889 }
|
|
890 }
|
|
891
|
|
892 static int
|
|
893 cursor_possible_dest_types (void)
|
|
894 {
|
|
895 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
|
|
896 }
|
|
897
|
|
898 typedef struct
|
|
899 {
|
|
900 char *name;
|
|
901 int resource_id;
|
|
902 } resource_t;
|
|
903
|
|
904 #ifndef OCR_ICOCUR
|
|
905 #define OCR_ICOCUR 32647
|
|
906 #define OIC_SAMPLE 32512
|
|
907 #define OIC_HAND 32513
|
|
908 #define OIC_QUES 32514
|
|
909 #define OIC_BANG 32515
|
|
910 #define OIC_NOTE 32516
|
|
911 #define OIC_WINLOGO 32517
|
|
912 #define LR_SHARED 0x8000
|
|
913 #endif
|
|
914
|
|
915 static CONST resource_t resource_table[] =
|
|
916 {
|
|
917 /* bitmaps */
|
|
918 { "close", OBM_CLOSE },
|
|
919 { "uparrow", OBM_UPARROW },
|
|
920 { "dnarrow", OBM_DNARROW },
|
|
921 { "rgarrow", OBM_RGARROW },
|
|
922 { "lfarrow", OBM_LFARROW },
|
|
923 { "reduce", OBM_REDUCE },
|
|
924 { "zoom", OBM_ZOOM },
|
|
925 { "restore", OBM_RESTORE },
|
|
926 { "reduced", OBM_REDUCED },
|
|
927 { "zoomd", OBM_ZOOMD },
|
|
928 { "restored", OBM_RESTORED },
|
|
929 { "uparrowd", OBM_UPARROWD },
|
|
930 { "dnarrowd", OBM_DNARROWD },
|
|
931 { "rgarrowd", OBM_RGARROWD },
|
|
932 { "lfarrowd", OBM_LFARROWD },
|
|
933 { "mnarrow", OBM_MNARROW },
|
|
934 { "combo", OBM_COMBO },
|
|
935 { "uparrowi", OBM_UPARROWI },
|
|
936 { "dnarrowi", OBM_DNARROWI },
|
|
937 { "rgarrowi", OBM_RGARROWI },
|
|
938 { "lfarrowi", OBM_LFARROWI },
|
|
939 { "size", OBM_SIZE },
|
|
940 { "btsize", OBM_BTSIZE },
|
|
941 { "check", OBM_CHECK },
|
|
942 { "cehckboxes", OBM_CHECKBOXES },
|
|
943 { "btncorners" , OBM_BTNCORNERS },
|
|
944 /* cursors */
|
|
945 { "normal", OCR_NORMAL },
|
|
946 { "ibeam", OCR_IBEAM },
|
|
947 { "wait", OCR_WAIT },
|
|
948 { "cross", OCR_CROSS },
|
|
949 { "up", OCR_UP },
|
|
950 /* { "icon", OCR_ICON }, */
|
|
951 { "sizenwse", OCR_SIZENWSE },
|
|
952 { "sizenesw", OCR_SIZENESW },
|
|
953 { "sizewe", OCR_SIZEWE },
|
|
954 { "sizens", OCR_SIZENS },
|
|
955 { "sizeall", OCR_SIZEALL },
|
|
956 /* { "icour", OCR_ICOCUR }, */
|
|
957 { "no", OCR_NO },
|
|
958 /* icons */
|
|
959 { "sample", OIC_SAMPLE },
|
|
960 { "hand", OIC_HAND },
|
|
961 { "ques", OIC_QUES },
|
|
962 { "bang", OIC_BANG },
|
|
963 { "note", OIC_NOTE },
|
|
964 { "winlogo", OIC_WINLOGO },
|
|
965 {0}
|
|
966 };
|
|
967
|
|
968 static int cursor_name_to_resource (Lisp_Object name)
|
|
969 {
|
|
970 CONST resource_t* res = resource_table;
|
|
971
|
|
972 if (INTP (name))
|
|
973 {
|
|
974 return XINT (name);
|
|
975 }
|
|
976 else if (!STRINGP (name))
|
|
977 {
|
|
978 signal_simple_error ("invalid resource identifier", name);
|
|
979 }
|
|
980
|
|
981 do {
|
|
982 if (!strcasecmp ((char*)res->name, XSTRING_DATA (name)))
|
|
983 return res->resource_id;
|
|
984 } while ((++res)->name);
|
|
985 return 0;
|
|
986 }
|
|
987
|
|
988 static void
|
|
989 cursor_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
990 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
991 int dest_mask, Lisp_Object domain)
|
|
992 {
|
|
993 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
994 unsigned int type = 0;
|
|
995 HANDLE himage = NULL;
|
|
996 LPCTSTR resid=0;
|
|
997 int iitype=0;
|
|
998 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
999
|
|
1000 Lisp_Object file = find_keyword_in_vector (instantiator, Q_file);
|
|
1001 Lisp_Object resource_type = find_keyword_in_vector (instantiator,
|
|
1002 Q_resource_type);
|
|
1003 Lisp_Object resource_id = find_keyword_in_vector (instantiator,
|
|
1004 Q_resource_id);
|
|
1005
|
|
1006 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
1007 signal_simple_error ("Not an mswindows device", device);
|
|
1008
|
|
1009 assert (!NILP (resource_type) && !NILP (resource_id));
|
|
1010
|
|
1011 /* check the resource type */
|
|
1012 if (!SYMBOLP (resource_type))
|
|
1013 {
|
|
1014 signal_simple_error ("invalid resource type", resource_type);
|
|
1015 }
|
|
1016 if (!strcmp ((char *) string_data (XSYMBOL (resource_type)->name),
|
|
1017 "bitmap"))
|
|
1018 type = IMAGE_BITMAP;
|
|
1019 else if (!strcmp ((char *) string_data (XSYMBOL (resource_type)->name),
|
|
1020 "cursor"))
|
|
1021 type = IMAGE_CURSOR;
|
|
1022 else if (!strcmp ((char *) string_data (XSYMBOL (resource_type)->name),
|
|
1023 "icon"))
|
|
1024 type = IMAGE_ICON;
|
|
1025 else
|
|
1026 signal_simple_error ("invalid resource type", resource_type);
|
|
1027
|
|
1028 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_CURSOR)
|
|
1029 iitype = IMAGE_POINTER;
|
|
1030 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1031 iitype = IMAGE_COLOR_PIXMAP;
|
|
1032 else
|
|
1033 incompatible_image_types (instantiator, dest_mask,
|
|
1034 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
|
|
1035
|
|
1036 if (!NILP (file))
|
|
1037 resid = (LPCTSTR)XSTRING_DATA (file);
|
|
1038 else if (!(resid = MAKEINTRESOURCE(cursor_name_to_resource (resource_id))))
|
|
1039 signal_simple_error ("invalid resource id", resource_id);
|
|
1040
|
|
1041 /* load the image */
|
|
1042 if (!(himage = LoadImage (NULL, resid, type, 0, 0,
|
|
1043 LR_CREATEDIBSECTION | LR_DEFAULTSIZE |
|
|
1044 LR_SHARED |
|
|
1045 (!NILP (file) ? LR_LOADFROMFILE : 0))))
|
|
1046 {
|
|
1047 signal_simple_error ("cannot load image", instantiator);
|
|
1048 }
|
|
1049
|
|
1050 mswindows_initialize_dibitmap_image_instance (ii, iitype);
|
|
1051
|
|
1052 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = file;
|
|
1053 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = (type==IMAGE_BITMAP ? himage : NULL);
|
|
1054 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL;
|
|
1055 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = (type!=IMAGE_BITMAP ? himage : NULL);
|
|
1056 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) =
|
|
1057 (type == IMAGE_CURSOR ? SM_CXCURSOR : SM_CXICON);
|
|
1058 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) =
|
|
1059 (type == IMAGE_CURSOR ? SM_CYCURSOR : SM_CYICON);
|
|
1060 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 0;
|
|
1061 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0);
|
|
1062 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0);
|
|
1063 }
|
|
1064
|
|
1065 void
|
|
1066 check_valid_symbol (Lisp_Object data)
|
|
1067 {
|
|
1068 CHECK_SYMBOL (data);
|
|
1069 }
|
|
1070
|
|
1071 void
|
|
1072 check_valid_string_or_int (Lisp_Object data)
|
|
1073 {
|
|
1074 if (!INTP (data))
|
|
1075 CHECK_STRING (data);
|
|
1076 else
|
|
1077 CHECK_INT (data);
|
|
1078 }
|
|
1079
|
|
1080
|
267
|
1081 /************************************************************************/
|
|
1082 /* image instance methods */
|
|
1083 /************************************************************************/
|
|
1084
|
|
1085 static void
|
|
1086 mswindows_print_image_instance (struct Lisp_Image_Instance *p,
|
|
1087 Lisp_Object printcharfun,
|
|
1088 int escapeflag)
|
|
1089 {
|
|
1090 char buf[100];
|
|
1091
|
|
1092 switch (IMAGE_INSTANCE_TYPE (p))
|
|
1093 {
|
|
1094 case IMAGE_MONO_PIXMAP:
|
|
1095 case IMAGE_COLOR_PIXMAP:
|
|
1096 case IMAGE_POINTER:
|
|
1097 sprintf (buf, " (0x%lx",
|
|
1098 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
|
1099 write_c_string (buf, printcharfun);
|
|
1100 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
1101 {
|
|
1102 sprintf (buf, "/0x%lx",
|
|
1103 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
1104 write_c_string (buf, printcharfun);
|
|
1105 }
|
|
1106 write_c_string (")", printcharfun);
|
|
1107 break;
|
|
1108 default:
|
|
1109 break;
|
|
1110 }
|
|
1111 }
|
|
1112
|
|
1113 static void
|
|
1114 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
1115 {
|
|
1116 if (!p->data)
|
|
1117 return;
|
|
1118
|
|
1119 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
1120 {
|
|
1121 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
|
269
|
1122 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
267
|
1123 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
|
272
|
1124 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
1125 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
1126 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
|
|
1127 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
|
|
1128 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
|
|
1129 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
|
267
|
1130 }
|
|
1131
|
|
1132 xfree (p->data);
|
|
1133 p->data = 0;
|
|
1134 }
|
|
1135
|
|
1136 static int
|
|
1137 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
1138 struct Lisp_Image_Instance *p2, int depth)
|
|
1139 {
|
|
1140 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
1141 {
|
|
1142 case IMAGE_MONO_PIXMAP:
|
|
1143 case IMAGE_COLOR_PIXMAP:
|
|
1144 case IMAGE_POINTER:
|
|
1145 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
|
|
1146 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
|
|
1147 return 0;
|
|
1148 break;
|
|
1149 default:
|
|
1150 break;
|
|
1151 }
|
|
1152
|
|
1153 return 1;
|
|
1154 }
|
|
1155
|
|
1156 static unsigned long
|
|
1157 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
1158 {
|
|
1159 switch (IMAGE_INSTANCE_TYPE (p))
|
|
1160 {
|
|
1161 case IMAGE_MONO_PIXMAP:
|
|
1162 case IMAGE_COLOR_PIXMAP:
|
|
1163 case IMAGE_POINTER:
|
|
1164 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
|
|
1165 default:
|
|
1166 return 0;
|
|
1167 }
|
|
1168 }
|
|
1169
|
|
1170 /* Set all the slots in an image instance structure to reasonable
|
|
1171 default values. This is used somewhere within an instantiate
|
|
1172 method. It is assumed that the device slot within the image
|
|
1173 instance is already set -- this is the case when instantiate
|
|
1174 methods are called. */
|
|
1175
|
|
1176 static void
|
|
1177 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
1178 enum image_instance_type type)
|
|
1179 {
|
|
1180 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
|
|
1181 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
1182 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
1183 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
1184 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
1185 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
1186 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
1187 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
1188 }
|
|
1189
|
|
1190
|
|
1191 /************************************************************************/
|
|
1192 /* initialization */
|
|
1193 /************************************************************************/
|
|
1194
|
|
1195 void
|
|
1196 syms_of_glyphs_mswindows (void)
|
|
1197 {
|
284
|
1198 defkeyword (&Q_resource_id, ":resource-id");
|
|
1199 defkeyword (&Q_resource_type, ":resource-type");
|
267
|
1200 }
|
|
1201
|
|
1202 void
|
|
1203 console_type_create_glyphs_mswindows (void)
|
|
1204 {
|
|
1205 /* image methods */
|
|
1206
|
|
1207 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
|
|
1208 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
|
|
1209 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
|
|
1210 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
|
278
|
1211 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
|
|
1212 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
|
280
|
1213 #ifdef HAVE_XPM
|
|
1214 CONSOLE_HAS_METHOD (mswindows, xpm_instantiate);
|
|
1215 #endif
|
267
|
1216 }
|
|
1217
|
|
1218 void
|
|
1219 image_instantiator_format_create_glyphs_mswindows (void)
|
|
1220 {
|
|
1221 /* image-instantiator types */
|
|
1222
|
|
1223 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
|
|
1224
|
|
1225 IIFORMAT_HAS_METHOD (bmp, validate);
|
|
1226 IIFORMAT_HAS_METHOD (bmp, normalize);
|
|
1227 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
|
|
1228 IIFORMAT_HAS_METHOD (bmp, instantiate);
|
|
1229
|
|
1230 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
|
|
1231 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
|
284
|
1232
|
|
1233 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor, "cursor");
|
|
1234
|
|
1235 IIFORMAT_HAS_METHOD (cursor, validate);
|
|
1236 IIFORMAT_HAS_METHOD (cursor, normalize);
|
|
1237 IIFORMAT_HAS_METHOD (cursor, possible_dest_types);
|
|
1238 IIFORMAT_HAS_METHOD (cursor, instantiate);
|
|
1239
|
|
1240 IIFORMAT_VALID_KEYWORD (cursor, Q_resource_type, check_valid_symbol);
|
|
1241 IIFORMAT_VALID_KEYWORD (cursor, Q_resource_id, check_valid_string_or_int);
|
|
1242 IIFORMAT_VALID_KEYWORD (cursor, Q_file, check_valid_string);
|
267
|
1243 }
|
|
1244
|
|
1245 void
|
|
1246 vars_of_glyphs_mswindows (void)
|
|
1247 {
|
|
1248 Fprovide (Qbmp);
|
284
|
1249 Fprovide (Qcursor);
|
267
|
1250 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
|
|
1251 A list of the directories in which mswindows bitmap files may be found.
|
|
1252 This is used by the `make-image-instance' function.
|
|
1253 */ );
|
|
1254 Vmswindows_bitmap_file_path = Qnil;
|
|
1255 }
|
|
1256
|
|
1257 void
|
|
1258 complex_vars_of_glyphs_mswindows (void)
|
|
1259 {
|
|
1260 }
|