Mercurial > hg > xemacs-beta
annotate src/glyphs-msw.c @ 5898:2aeaf9bc7175
Regenerate configure.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Tue, 05 May 2015 04:06:37 +0900 |
parents | 56144c8593a8 |
children | 0f2338afbabf |
rev | line source |
---|---|
428 | 1 /* mswindows-specific glyph objects. |
438 | 2 Copyright (C) 1998, 1999, 2000 Andy Piper. |
2959 | 3 Copyright (C) 2001, 2002, 2003, 2004, 2005 Ben Wing. |
434 | 4 |
428 | 5 This file is part of XEmacs. |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5192
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5192
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5192
diff
changeset
|
10 option) any later version. |
428 | 11 |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5192
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: Not in FSF. */ | |
21 | |
771 | 22 /* This file apparently Mule-ized, 8-7-2000, but could stand review. */ |
23 | |
442 | 24 /* written by Andy Piper <andy@xemacs.org> plagiarising bits from |
428 | 25 glyphs-x.c */ |
26 | |
771 | 27 #define NEED_MSWINDOWS_COMMCTRL |
28 | |
428 | 29 #include <config.h> |
30 #include "lisp.h" | |
800 | 31 |
872 | 32 #include "device-impl.h" |
800 | 33 #include "elhash.h" |
34 #include "faces.h" | |
35 #include "file-coding.h" | |
872 | 36 #include "frame-impl.h" |
800 | 37 #include "gui.h" |
38 #include "imgproc.h" | |
39 #include "insdel.h" | |
428 | 40 #include "lstream.h" |
800 | 41 #include "opaque.h" |
42 #include "sysdep.h" | |
43 #include "sysfile.h" | |
44 #include "window.h" | |
428 | 45 |
872 | 46 #include "console-msw-impl.h" |
428 | 47 #include "glyphs-msw.h" |
5176
8b2f75cecb89
rename objects* (.c, .h and .el files) to fontcolor*
Ben Wing <ben@xemacs.org>
parents:
5047
diff
changeset
|
48 #include "fontcolor-msw-impl.h" |
428 | 49 |
50 #define WIDGET_GLYPH_SLOT 0 | |
51 | |
52 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing); | |
53 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string); | |
54 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string); | |
55 DECLARE_IMAGE_INSTANTIATOR_FORMAT (inherit); | |
56 #ifdef HAVE_JPEG | |
57 DECLARE_IMAGE_INSTANTIATOR_FORMAT (jpeg); | |
58 #endif | |
59 #ifdef HAVE_TIFF | |
60 DECLARE_IMAGE_INSTANTIATOR_FORMAT (tiff); | |
434 | 61 #endif |
428 | 62 #ifdef HAVE_PNG |
63 DECLARE_IMAGE_INSTANTIATOR_FORMAT (png); | |
434 | 64 #endif |
428 | 65 #ifdef HAVE_GIF |
66 DECLARE_IMAGE_INSTANTIATOR_FORMAT (gif); | |
434 | 67 #endif |
428 | 68 #ifdef HAVE_XPM |
69 DEFINE_DEVICE_IIFORMAT (mswindows, xpm); | |
442 | 70 DEFINE_DEVICE_IIFORMAT (msprinter, xpm); |
428 | 71 #endif |
72 DEFINE_DEVICE_IIFORMAT (mswindows, xbm); | |
442 | 73 DEFINE_DEVICE_IIFORMAT (msprinter, xbm); |
428 | 74 #ifdef HAVE_XFACE |
75 DEFINE_DEVICE_IIFORMAT (mswindows, xface); | |
442 | 76 DEFINE_DEVICE_IIFORMAT (msprinter, xface); |
428 | 77 #endif |
442 | 78 DECLARE_IMAGE_INSTANTIATOR_FORMAT (layout); |
79 DEFINE_DEVICE_IIFORMAT (mswindows, native_layout); | |
428 | 80 DEFINE_DEVICE_IIFORMAT (mswindows, button); |
81 DEFINE_DEVICE_IIFORMAT (mswindows, edit_field); | |
82 DEFINE_DEVICE_IIFORMAT (mswindows, subwindow); | |
83 DEFINE_DEVICE_IIFORMAT (mswindows, widget); | |
84 DEFINE_DEVICE_IIFORMAT (mswindows, label); | |
85 DEFINE_DEVICE_IIFORMAT (mswindows, scrollbar); | |
86 DEFINE_DEVICE_IIFORMAT (mswindows, combo_box); | |
87 DEFINE_DEVICE_IIFORMAT (mswindows, progress_gauge); | |
88 DEFINE_DEVICE_IIFORMAT (mswindows, tree_view); | |
89 DEFINE_DEVICE_IIFORMAT (mswindows, tab_control); | |
90 | |
91 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp); | |
92 Lisp_Object Qbmp; | |
93 Lisp_Object Vmswindows_bitmap_file_path; | |
94 static COLORREF transparent_color = RGB (1,1,1); | |
95 | |
96 DEFINE_IMAGE_INSTANTIATOR_FORMAT (mswindows_resource); | |
97 Lisp_Object Qmswindows_resource; | |
98 | |
99 static void | |
440 | 100 mswindows_initialize_dibitmap_image_instance (Lisp_Image_Instance *ii, |
428 | 101 int slices, |
102 enum image_instance_type type); | |
103 static void | |
771 | 104 mswindows_initialize_image_instance_mask (Lisp_Image_Instance *image, |
442 | 105 HDC hcdc); |
106 | |
107 /* | |
108 * Given device D, retrieve compatible device context. D can be either | |
109 * mswindows or an msprinter device. | |
110 */ | |
111 inline static HDC | |
112 get_device_compdc (struct device *d) | |
113 { | |
114 if (DEVICE_MSWINDOWS_P (d)) | |
115 return DEVICE_MSWINDOWS_HCDC (d); | |
116 else | |
117 return DEVICE_MSPRINTER_HCDC (d); | |
118 } | |
119 | |
120 /* | |
121 * Initialize image instance pixel sizes in II. For a display bitmap, | |
122 * these will be same as real bitmap sizes. For a printer bitmap, | |
123 * these will be scaled up so that the bitmap is proportionally enlarged | |
124 * when output to printer. Redisplay code takes care of scaling, to | |
125 * conserve memory we do not really scale bitmaps. Set the watermark | |
126 * only here. | |
127 * #### Add support for unscalable bitmaps. | |
128 */ | |
129 static void init_image_instance_geometry (Lisp_Image_Instance *ii) | |
130 { | |
131 struct device *d = DOMAIN_XDEVICE (ii->domain); | |
132 | |
133 if (/* #### Scaleable && */ DEVICE_MSPRINTER_P (d)) | |
134 { | |
135 HDC printer_dc = DEVICE_MSPRINTER_HCDC (d); | |
136 HDC display_dc = CreateCompatibleDC (NULL); | |
137 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = | |
138 MulDiv (IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii), | |
139 GetDeviceCaps (printer_dc, LOGPIXELSX), | |
140 GetDeviceCaps (display_dc, LOGPIXELSX)); | |
141 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = | |
142 MulDiv (IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii), | |
143 GetDeviceCaps (printer_dc, LOGPIXELSY), | |
144 GetDeviceCaps (display_dc, LOGPIXELSY)); | |
145 } | |
146 else | |
147 { | |
148 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = | |
149 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii); | |
150 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = | |
151 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii); | |
152 } | |
153 } | |
428 | 154 |
155 #define BPLINE(width) ((int)(~3UL & (unsigned long)((width) +3))) | |
156 | |
157 /************************************************************************/ | |
158 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/ | |
159 /* proper display */ | |
160 /************************************************************************/ | |
771 | 161 static BITMAPINFO *convert_EImage_to_DIBitmap (Lisp_Object device, |
428 | 162 int width, int height, |
2367 | 163 Binbyte *pic, |
428 | 164 int *bit_count, |
2367 | 165 Binbyte **bmp_data) |
428 | 166 { |
167 struct device *d = XDEVICE (device); | |
771 | 168 int i, j; |
169 RGBQUAD *colortbl; | |
170 int ncolors; | |
171 BITMAPINFO *bmp_info; | |
2367 | 172 Binbyte *ip, *dp; |
428 | 173 |
442 | 174 if (GetDeviceCaps (get_device_compdc (d), BITSPIXEL) > 0) |
428 | 175 { |
176 int bpline = BPLINE(width * 3); | |
177 /* FIXME: we can do this because 24bpp implies no color table, once | |
178 * we start palettizing this is no longer true. The X versions of | |
179 * this function quantises to 256 colors or bit masks down to a | |
180 * long. Windows can actually handle rgb triples in the raw so I | |
181 * don't see much point trying to optimize down to the best | |
182 * structure - unless it has memory / color allocation implications | |
183 * .... */ | |
771 | 184 bmp_info = xnew_and_zero (BITMAPINFO); |
434 | 185 |
428 | 186 if (!bmp_info) |
187 { | |
188 return NULL; | |
189 } | |
190 | |
771 | 191 bmp_info->bmiHeader.biBitCount = 24; /* just RGB triples for now */ |
192 bmp_info->bmiHeader.biCompression = BI_RGB; /* just RGB triples | |
193 for now */ | |
194 bmp_info->bmiHeader.biSizeImage = width * height * 3; | |
428 | 195 |
196 /* bitmap data needs to be in blue, green, red triples - in that | |
197 order, eimage is in RGB format so we need to convert */ | |
2367 | 198 *bmp_data = xnew_array_and_zero (Binbyte, bpline * height); |
428 | 199 *bit_count = bpline * height; |
200 | |
201 if (!bmp_data) | |
202 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
203 xfree (bmp_info); |
428 | 204 return NULL; |
205 } | |
206 | |
207 ip = pic; | |
208 for (i = height-1; i >= 0; i--) { | |
209 dp = (*bmp_data) + (i * bpline); | |
210 for (j = 0; j < width; j++) { | |
771 | 211 dp[2] = *ip++; |
212 dp[1] = *ip++; | |
213 *dp = *ip++; | |
428 | 214 dp += 3; |
215 } | |
216 } | |
217 } | |
218 else /* scale to 256 colors */ | |
219 { | |
220 int rd,gr,bl; | |
221 quant_table *qtable; | |
222 int bpline = BPLINE (width * 3); | |
223 /* Quantize the image and get a histogram while we're at it. | |
224 Do this first to save memory */ | |
225 qtable = build_EImage_quantable(pic, width, height, 256); | |
226 if (qtable == NULL) return NULL; | |
227 | |
228 /* use our quantize table to allocate the colors */ | |
229 ncolors = qtable->num_active_colors; | |
771 | 230 bmp_info = (BITMAPINFO *)xmalloc_and_zero (sizeof(BITMAPINFOHEADER) + |
428 | 231 sizeof(RGBQUAD) * ncolors); |
232 if (!bmp_info) | |
233 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
234 xfree (qtable); |
428 | 235 return NULL; |
236 } | |
237 | |
2367 | 238 colortbl = (RGBQUAD *) (((Binbyte *) bmp_info) + |
771 | 239 sizeof (BITMAPINFOHEADER)); |
240 | |
241 bmp_info->bmiHeader.biBitCount = 8; | |
242 bmp_info->bmiHeader.biCompression = BI_RGB; | |
243 bmp_info->bmiHeader.biSizeImage = bpline * height; | |
244 bmp_info->bmiHeader.biClrUsed = ncolors; | |
245 bmp_info->bmiHeader.biClrImportant = ncolors; | |
434 | 246 |
2367 | 247 *bmp_data = xnew_array_and_zero (Binbyte, bpline * height); |
428 | 248 *bit_count = bpline * height; |
249 | |
250 if (!*bmp_data) | |
251 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
252 xfree (qtable); |
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
253 xfree (bmp_info); |
428 | 254 return NULL; |
255 } | |
434 | 256 |
428 | 257 /* build up an RGBQUAD colortable */ |
442 | 258 for (i = 0; i < qtable->num_active_colors; i++) |
259 { | |
260 colortbl[i].rgbRed = (BYTE) qtable->rm[i]; | |
261 colortbl[i].rgbGreen = (BYTE) qtable->gm[i]; | |
262 colortbl[i].rgbBlue = (BYTE) qtable->bm[i]; | |
263 colortbl[i].rgbReserved = 0; | |
264 } | |
428 | 265 |
266 /* now build up the data. picture has to be upside-down and | |
267 back-to-front for msw bitmaps */ | |
268 ip = pic; | |
442 | 269 for (i = height-1; i >= 0; i--) |
270 { | |
271 dp = (*bmp_data) + (i * bpline); | |
272 for (j = 0; j < width; j++) | |
273 { | |
274 rd = *ip++; | |
275 gr = *ip++; | |
276 bl = *ip++; | |
277 *dp++ = QUANT_GET_COLOR (qtable,rd,gr,bl); | |
278 } | |
428 | 279 } |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
280 xfree (qtable); |
434 | 281 } |
428 | 282 /* fix up the standard stuff */ |
771 | 283 bmp_info->bmiHeader.biWidth = width; |
284 bmp_info->bmiHeader.biHeight = height; | |
285 bmp_info->bmiHeader.biPlanes = 1; | |
286 bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
287 bmp_info->bmiHeader.biXPelsPerMeter = 0; /* unless you know better */ | |
288 bmp_info->bmiHeader.biYPelsPerMeter = 0; | |
428 | 289 |
290 return bmp_info; | |
291 } | |
292 | |
293 /* Given a pixmap filename, look through all of the "standard" places | |
294 where the file might be located. Return a full pathname if found; | |
295 otherwise, return Qnil. */ | |
296 | |
297 static Lisp_Object | |
298 mswindows_locate_pixmap_file (Lisp_Object name) | |
299 { | |
300 /* This function can GC if IN_REDISPLAY is false */ | |
301 Lisp_Object found; | |
302 | |
303 /* Check non-absolute pathnames with a directory component relative to | |
304 the search path; that's the way Xt does it. */ | |
826 | 305 if (IS_DIRECTORY_SEP(string_byte (name, 0)) || |
306 (string_byte (name, 0) == '.' && | |
307 (IS_DIRECTORY_SEP(string_byte (name, 1)) || | |
308 (string_byte (name, 1) == '.' && | |
309 (IS_DIRECTORY_SEP(string_byte (name, 2))))))) | |
428 | 310 { |
311 if (!NILP (Ffile_readable_p (name))) | |
440 | 312 return Fexpand_file_name (name, Qnil); |
428 | 313 else |
314 return Qnil; | |
315 } | |
316 | |
317 if (locate_file (Vmswindows_bitmap_file_path, name, Qnil, &found, R_OK) < 0) | |
318 { | |
319 Lisp_Object temp = list1 (Vdata_directory); | |
320 struct gcpro gcpro1; | |
321 | |
322 GCPRO1 (temp); | |
323 locate_file (temp, name, Qnil, &found, R_OK); | |
324 UNGCPRO; | |
325 } | |
434 | 326 |
428 | 327 return found; |
328 } | |
329 | |
330 | |
331 /* Initialize an image instance from a bitmap | |
332 | |
333 DEST_MASK specifies the mask of allowed image types. | |
334 | |
335 If this fails, signal an error. INSTANTIATOR is only used | |
336 in the error message. */ | |
337 | |
338 static void | |
440 | 339 init_image_instance_from_dibitmap (Lisp_Image_Instance *ii, |
428 | 340 BITMAPINFO *bmp_info, |
341 int dest_mask, | |
342 void *bmp_data, | |
343 int bmp_bits, | |
344 int slices, | |
434 | 345 Lisp_Object instantiator, |
428 | 346 int x_hot, int y_hot, |
347 int create_mask) | |
348 { | |
442 | 349 struct device *d = XDEVICE (IMAGE_INSTANCE_DEVICE (ii)); |
771 | 350 void *bmp_buf = 0; |
442 | 351 enum image_instance_type type; |
428 | 352 HBITMAP bitmap; |
353 HDC hdc; | |
354 | |
355 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK) | |
356 type = IMAGE_COLOR_PIXMAP; | |
357 else if (dest_mask & IMAGE_POINTER_MASK) | |
358 type = IMAGE_POINTER; | |
434 | 359 else |
428 | 360 incompatible_image_types (instantiator, dest_mask, |
361 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK); | |
442 | 362 |
363 hdc = get_device_compdc (d); | |
364 bitmap = CreateDIBSection (hdc, | |
365 bmp_info, | |
366 DIB_RGB_COLORS, | |
367 &bmp_buf, | |
368 0, 0); | |
428 | 369 |
370 if (!bitmap || !bmp_buf) | |
563 | 371 signal_image_error ("Unable to create bitmap", instantiator); |
428 | 372 |
373 /* copy in the actual bitmap */ | |
374 memcpy (bmp_buf, bmp_data, bmp_bits); | |
375 | |
376 mswindows_initialize_dibitmap_image_instance (ii, slices, type); | |
377 | |
378 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = | |
379 find_keyword_in_vector (instantiator, Q_file); | |
380 | |
381 /* Fixup a set of bitmaps. */ | |
382 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap; | |
383 | |
384 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL; | |
442 | 385 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii) = |
386 bmp_info->bmiHeader.biWidth; | |
387 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii) = | |
388 bmp_info->bmiHeader.biHeight; | |
389 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount; | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
390 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_fixnum (x_hot); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
391 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_fixnum (y_hot); |
442 | 392 init_image_instance_geometry (ii); |
428 | 393 |
394 if (create_mask) | |
395 { | |
442 | 396 mswindows_initialize_image_instance_mask (ii, hdc); |
428 | 397 } |
434 | 398 |
428 | 399 if (type == IMAGE_POINTER) |
400 { | |
401 mswindows_initialize_image_instance_icon(ii, TRUE); | |
402 } | |
403 } | |
404 | |
405 static void | |
440 | 406 image_instance_add_dibitmap (Lisp_Image_Instance *ii, |
428 | 407 BITMAPINFO *bmp_info, |
408 void *bmp_data, | |
409 int bmp_bits, | |
410 int slice, | |
411 Lisp_Object instantiator) | |
412 { | |
442 | 413 struct device *d = XDEVICE (IMAGE_INSTANCE_DEVICE (ii)); |
771 | 414 void *bmp_buf = 0; |
442 | 415 |
416 HBITMAP bitmap = CreateDIBSection (get_device_compdc (d), | |
428 | 417 bmp_info, |
418 DIB_RGB_COLORS, | |
434 | 419 &bmp_buf, |
428 | 420 0,0); |
434 | 421 |
428 | 422 if (!bitmap || !bmp_buf) |
563 | 423 signal_image_error ("Unable to create bitmap", instantiator); |
428 | 424 |
425 /* copy in the actual bitmap */ | |
426 memcpy (bmp_buf, bmp_data, bmp_bits); | |
427 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (ii, slice) = bitmap; | |
428 } | |
429 | |
430 static void | |
440 | 431 mswindows_init_image_instance_from_eimage (Lisp_Image_Instance *ii, |
428 | 432 int width, int height, |
433 int slices, | |
2367 | 434 Binbyte *eimage, |
428 | 435 int dest_mask, |
436 Lisp_Object instantiator, | |
2959 | 437 Lisp_Object UNUSED (pointer_fg), |
438 Lisp_Object UNUSED (pointer_bg), | |
428 | 439 Lisp_Object domain) |
440 { | |
441 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | |
771 | 442 BITMAPINFO * bmp_info; |
2367 | 443 Binbyte * bmp_data; |
428 | 444 int bmp_bits; |
445 COLORREF bkcolor; | |
446 int slice; | |
434 | 447 |
442 | 448 CHECK_MSGDI_DEVICE (device); |
428 | 449 |
450 /* this is a hack but MaskBlt and TransparentBlt are not supported | |
451 on most windows variants */ | |
434 | 452 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR |
428 | 453 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain))); |
454 | |
455 for (slice = 0; slice < slices; slice++) | |
456 { | |
457 /* build a bitmap from the eimage */ | |
771 | 458 if (!(bmp_info = convert_EImage_to_DIBitmap (device, width, height, |
428 | 459 eimage + (width * height * 3 * slice), |
460 &bmp_bits, &bmp_data))) | |
461 { | |
563 | 462 signal_image_error ("EImage to DIBitmap conversion failed", |
463 instantiator); | |
428 | 464 } |
465 | |
466 /* Now create the pixmap and set up the image instance */ | |
467 if (slice == 0) | |
468 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, | |
469 bmp_data, bmp_bits, slices, instantiator, | |
470 0, 0, 0); | |
471 else | |
472 image_instance_add_dibitmap (ii, bmp_info, bmp_data, bmp_bits, slice, | |
473 instantiator); | |
434 | 474 |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
475 xfree (bmp_info); |
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
476 xfree (bmp_data); |
428 | 477 } |
478 } | |
479 | |
442 | 480 inline static void |
2367 | 481 set_mono_pixel (Binbyte *bits, |
442 | 482 int bpline, int height, |
483 int x, int y, int white) | |
434 | 484 { |
438 | 485 int i; |
2367 | 486 Binbyte bitnum; |
428 | 487 /* Find the byte on which this scanline begins */ |
438 | 488 i = (height - y - 1) * bpline; |
428 | 489 /* Find the byte containing this pixel */ |
438 | 490 i += (x >> 3); |
428 | 491 /* Which bit is it? */ |
2367 | 492 bitnum = (Binbyte) (7 - (x & 7)); |
442 | 493 if (white) /* Turn it on */ |
494 bits[i] |= (1 << bitnum); | |
495 else /* Turn it off */ | |
496 bits[i] &= ~(1 << bitnum); | |
434 | 497 } |
428 | 498 |
499 static void | |
771 | 500 mswindows_initialize_image_instance_mask (Lisp_Image_Instance *image, |
442 | 501 HDC hcdc) |
428 | 502 { |
503 HBITMAP mask; | |
504 HGDIOBJ old = NULL; | |
2367 | 505 Binbyte *dibits, *and_bits; |
442 | 506 BITMAPINFO *bmp_info = |
771 | 507 (BITMAPINFO *) xmalloc_and_zero (sizeof (BITMAPINFO) + sizeof (RGBQUAD)); |
428 | 508 int i, j; |
442 | 509 int height = IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (image); |
510 | |
511 int maskbpline = BPLINE ((IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image) + 7) / 8); | |
512 int bpline = BPLINE (IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image) * 3); | |
428 | 513 |
514 if (!bmp_info) | |
515 return; | |
516 | |
771 | 517 bmp_info->bmiHeader.biWidth = IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image); |
428 | 518 bmp_info->bmiHeader.biHeight = height; |
442 | 519 bmp_info->bmiHeader.biPlanes = 1; |
771 | 520 bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
442 | 521 bmp_info->bmiHeader.biBitCount = 1; |
522 bmp_info->bmiHeader.biCompression = BI_RGB; | |
434 | 523 bmp_info->bmiHeader.biClrUsed = 2; |
524 bmp_info->bmiHeader.biClrImportant = 2; | |
525 bmp_info->bmiHeader.biSizeImage = height * maskbpline; | |
428 | 526 bmp_info->bmiColors[0].rgbRed = 0; |
527 bmp_info->bmiColors[0].rgbGreen = 0; | |
528 bmp_info->bmiColors[0].rgbBlue = 0; | |
529 bmp_info->bmiColors[0].rgbReserved = 0; | |
530 bmp_info->bmiColors[1].rgbRed = 255; | |
531 bmp_info->bmiColors[1].rgbGreen = 255; | |
532 bmp_info->bmiColors[1].rgbBlue = 255; | |
533 bmp_info->bmiColors[0].rgbReserved = 0; | |
434 | 534 |
535 if (!(mask = CreateDIBSection (hcdc, | |
428 | 536 bmp_info, |
537 DIB_RGB_COLORS, | |
2367 | 538 /* The intermediate cast fools gcc into |
539 not outputting strict-aliasing | |
540 complaints */ | |
541 (void **) (void *) &and_bits, | |
428 | 542 0,0))) |
543 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
544 xfree (bmp_info); |
428 | 545 return; |
546 } | |
547 | |
548 old = SelectObject (hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (image)); | |
549 /* build up an in-memory set of bits to mess with */ | |
550 xzero (*bmp_info); | |
551 | |
442 | 552 bmp_info->bmiHeader.biWidth = IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image); |
428 | 553 bmp_info->bmiHeader.biHeight = -height; |
442 | 554 bmp_info->bmiHeader.biPlanes = 1; |
555 bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
556 bmp_info->bmiHeader.biBitCount = 24; | |
557 bmp_info->bmiHeader.biCompression = BI_RGB; | |
434 | 558 bmp_info->bmiHeader.biClrUsed = 0; |
559 bmp_info->bmiHeader.biClrImportant = 0; | |
428 | 560 bmp_info->bmiHeader.biSizeImage = height * bpline; |
561 | |
2367 | 562 dibits = xnew_array_and_zero (Binbyte, bpline * height); |
428 | 563 if (GetDIBits (hcdc, |
564 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image), | |
565 0, | |
566 height, | |
567 dibits, | |
568 bmp_info, | |
569 DIB_RGB_COLORS) <= 0) | |
570 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
571 xfree (bmp_info); |
428 | 572 return; |
573 } | |
574 | |
575 /* now set the colored bits in the mask and transparent ones to | |
576 black in the original */ | |
442 | 577 for (i = 0; i < IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (image); i++) |
434 | 578 { |
771 | 579 for (j = 0; j < height; j++) |
434 | 580 { |
2367 | 581 Binbyte *idx = &dibits[j * bpline + i * 3]; |
428 | 582 |
442 | 583 if (RGB (idx[2], idx[1], idx[0]) == transparent_color) |
434 | 584 { |
428 | 585 idx[0] = idx[1] = idx[2] = 0; |
442 | 586 set_mono_pixel (and_bits, maskbpline, height, i, j, TRUE); |
428 | 587 } |
434 | 588 else |
589 { | |
442 | 590 set_mono_pixel (and_bits, maskbpline, height, i, j, FALSE); |
428 | 591 } |
592 } | |
593 } | |
594 | |
595 SetDIBits (hcdc, | |
596 IMAGE_INSTANCE_MSWINDOWS_BITMAP (image), | |
597 0, | |
598 height, | |
599 dibits, | |
600 bmp_info, | |
601 DIB_RGB_COLORS); | |
602 | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
603 xfree (bmp_info); |
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
604 xfree (dibits); |
434 | 605 |
428 | 606 SelectObject(hcdc, old); |
607 | |
608 IMAGE_INSTANCE_MSWINDOWS_MASK (image) = mask; | |
609 } | |
610 | |
611 void | |
771 | 612 mswindows_initialize_image_instance_icon (Lisp_Image_Instance *image, |
428 | 613 int cursor) |
614 { | |
615 ICONINFO x_icon; | |
616 | |
617 /* we rely on windows to do any resizing necessary */ | |
771 | 618 x_icon.fIcon = cursor ? FALSE : TRUE; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
619 x_icon.xHotspot = XFIXNUM (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image)); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
620 x_icon.yHotspot = XFIXNUM (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image)); |
771 | 621 x_icon.hbmMask = IMAGE_INSTANCE_MSWINDOWS_MASK (image); |
622 x_icon.hbmColor = IMAGE_INSTANCE_MSWINDOWS_BITMAP (image); | |
434 | 623 |
428 | 624 IMAGE_INSTANCE_MSWINDOWS_ICON (image)= |
625 CreateIconIndirect (&x_icon); | |
626 } | |
627 | |
442 | 628 static HBITMAP |
629 create_resized_bitmap (HBITMAP curbmp, struct frame *f, | |
630 int curx, int cury, | |
631 int newx, int newy) | |
428 | 632 { |
633 HBITMAP newbmp; | |
634 HGDIOBJ old1, old2; | |
442 | 635 |
636 HDC hcdc = get_device_compdc (XDEVICE (FRAME_DEVICE (f))); | |
434 | 637 HDC hdcDst = CreateCompatibleDC (hcdc); |
638 | |
442 | 639 old1 = SelectObject (hcdc, curbmp); |
434 | 640 |
428 | 641 newbmp = CreateCompatibleBitmap (hcdc, newx, newy); |
642 | |
643 old2 = SelectObject (hdcDst, newbmp); | |
434 | 644 |
428 | 645 if (!StretchBlt (hdcDst, 0, 0, newx, newy, |
434 | 646 hcdc, 0, 0, |
442 | 647 curx, |
648 cury, | |
428 | 649 SRCCOPY)) |
650 { | |
651 DeleteObject (newbmp); | |
652 DeleteDC (hdcDst); | |
653 return 0; | |
654 } | |
655 | |
656 SelectObject (hdcDst, old2); | |
657 SelectObject (hcdc, old1); | |
658 DeleteDC (hdcDst); | |
659 | |
660 return newbmp; | |
661 } | |
662 | |
663 HBITMAP | |
771 | 664 mswindows_create_resized_bitmap (Lisp_Image_Instance *ii, |
665 struct frame *f, | |
442 | 666 int newx, int newy) |
667 { | |
668 return create_resized_bitmap (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii), | |
669 f, | |
670 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii), | |
671 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii), | |
672 newx, newy); | |
673 } | |
674 | |
675 HBITMAP | |
771 | 676 mswindows_create_resized_mask (Lisp_Image_Instance *ii, |
677 struct frame *f, | |
428 | 678 int newx, int newy) |
679 { | |
442 | 680 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii) == NULL) |
681 return NULL; | |
682 | |
683 return create_resized_bitmap (IMAGE_INSTANCE_MSWINDOWS_MASK (ii), | |
684 f, | |
685 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii), | |
686 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii), | |
687 newx, newy); | |
428 | 688 } |
689 | |
442 | 690 #if 0 /* Currently unused */ |
691 /* #### Warning: This function is not correct anymore with | |
692 resizable printer bitmaps. If you uncomment it, clean it. --kkm */ | |
428 | 693 int |
771 | 694 mswindows_resize_dibitmap_instance (Lisp_Image_Instance *ii, |
695 struct frame *f, | |
428 | 696 int newx, int newy) |
697 { | |
698 HBITMAP newbmp = mswindows_create_resized_bitmap (ii, f, newx, newy); | |
699 HBITMAP newmask = mswindows_create_resized_mask (ii, f, newx, newy); | |
700 | |
701 if (!newbmp) | |
702 return FALSE; | |
434 | 703 |
428 | 704 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)) |
705 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii)); | |
706 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii)) | |
707 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii)); | |
708 | |
709 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp; | |
710 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newmask; | |
711 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx; | |
712 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy; | |
713 | |
714 return TRUE; | |
715 } | |
442 | 716 #endif |
428 | 717 |
718 /********************************************************************** | |
719 * XPM * | |
720 **********************************************************************/ | |
721 | |
722 #ifdef HAVE_XPM | |
723 | |
724 struct color_symbol | |
725 { | |
867 | 726 Ibyte * name; |
428 | 727 COLORREF color; |
728 }; | |
729 | |
771 | 730 static struct color_symbol * |
428 | 731 extract_xpm_color_names (Lisp_Object device, |
732 Lisp_Object domain, | |
733 Lisp_Object color_symbol_alist, | |
771 | 734 int *nsymbols) |
428 | 735 { |
736 /* This function can GC */ | |
737 Lisp_Object rest; | |
738 Lisp_Object results = Qnil; | |
739 int i, j; | |
740 struct color_symbol *colortbl; | |
741 struct gcpro gcpro1, gcpro2; | |
742 | |
743 GCPRO2 (results, device); | |
744 | |
745 /* We built up results to be (("name" . #<color>) ...) so that if an | |
746 error happens we don't lose any malloc()ed data, or more importantly, | |
747 leave any pixels allocated in the server. */ | |
748 i = 0; | |
749 LIST_LOOP (rest, color_symbol_alist) | |
750 { | |
751 Lisp_Object cons = XCAR (rest); | |
752 Lisp_Object name = XCAR (cons); | |
753 Lisp_Object value = XCDR (cons); | |
754 if (NILP (value)) | |
755 continue; | |
756 if (STRINGP (value)) | |
757 value = | |
758 Fmake_color_instance | |
793 | 759 (value, device, encode_error_behavior_flag (ERROR_ME_DEBUG_WARN)); |
428 | 760 else |
761 { | |
762 assert (COLOR_SPECIFIERP (value)); | |
763 value = Fspecifier_instance (value, domain, Qnil, Qnil); | |
764 } | |
765 if (NILP (value)) | |
766 continue; | |
767 results = noseeum_cons (noseeum_cons (name, value), results); | |
768 i++; | |
769 } | |
770 UNGCPRO; /* no more evaluation */ | |
771 | |
771 | 772 *nsymbols = i; |
428 | 773 if (i == 0) return 0; |
774 | |
775 colortbl = xnew_array_and_zero (struct color_symbol, i); | |
776 | |
771 | 777 for (j = 0; j < i; j++) |
428 | 778 { |
779 Lisp_Object cons = XCAR (results); | |
434 | 780 colortbl[j].color = |
428 | 781 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons))); |
782 | |
771 | 783 /* mustn't lose this when we return */ |
784 colortbl[j].name = qxestrdup (XSTRING_DATA (XCAR (cons))); | |
853 | 785 free_cons (cons); |
428 | 786 cons = results; |
787 results = XCDR (results); | |
853 | 788 free_cons (cons); |
428 | 789 } |
790 return colortbl; | |
791 } | |
792 | |
442 | 793 static int xpm_to_eimage (Lisp_Object image, const Extbyte *buffer, |
2367 | 794 Binbyte **data, |
771 | 795 int *width, int *height, |
796 int *x_hot, int *y_hot, | |
797 int *transp, | |
798 struct color_symbol *color_symbols, | |
428 | 799 int nsymbols) |
800 { | |
801 XpmImage xpmimage; | |
802 XpmInfo xpminfo; | |
803 int result, i, j, transp_idx, maskbpline; | |
2367 | 804 Binbyte *dptr; |
771 | 805 unsigned int *sptr; |
428 | 806 COLORREF color; /* the american spelling virus hits again .. */ |
771 | 807 COLORREF *colortbl; |
428 | 808 |
809 xzero (xpmimage); | |
810 xzero (xpminfo); | |
771 | 811 xpminfo.valuemask = XpmHotspot; |
812 *transp = FALSE; | |
813 | |
814 result = XpmCreateXpmImageFromBuffer ((char *)buffer, | |
428 | 815 &xpmimage, |
816 &xpminfo); | |
817 switch (result) | |
818 { | |
819 case XpmSuccess: | |
820 break; | |
821 case XpmFileInvalid: | |
822 { | |
563 | 823 signal_image_error ("Invalid XPM data", image); |
428 | 824 } |
825 case XpmNoMemory: | |
826 { | |
563 | 827 signal_double_image_error ("Parsing pixmap data", |
828 "out of memory", image); | |
428 | 829 } |
830 default: | |
831 { | |
563 | 832 signal_double_image_error_2 ("Parsing pixmap data", |
833 "unknown error", | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
834 make_fixnum (result), image); |
428 | 835 } |
836 } | |
434 | 837 |
428 | 838 *width = xpmimage.width; |
839 *height = xpmimage.height; | |
434 | 840 maskbpline = BPLINE ((~7UL & (unsigned long)(*width + 7)) / 8); |
841 | |
2367 | 842 *data = xnew_array_and_zero (Binbyte, *width * *height * 3); |
428 | 843 |
844 if (!*data) | |
845 { | |
846 XpmFreeXpmImage (&xpmimage); | |
847 XpmFreeXpmInfo (&xpminfo); | |
848 return 0; | |
849 } | |
850 | |
851 /* build a color table to speed things up */ | |
852 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors); | |
853 if (!colortbl) | |
854 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
855 xfree (*data); |
428 | 856 XpmFreeXpmImage (&xpmimage); |
857 XpmFreeXpmInfo (&xpminfo); | |
858 return 0; | |
859 } | |
860 | |
771 | 861 for (i = 0; i < (int) xpmimage.ncolors; i++) |
428 | 862 { |
863 /* goto alert!!!! */ | |
864 /* pick up symbolic colors in preference */ | |
865 if (xpmimage.colorTable[i].symbolic) | |
866 { | |
771 | 867 if (!strcasecmp (xpmimage.colorTable[i].symbolic, "BgColor") |
428 | 868 || |
771 | 869 !strcasecmp (xpmimage.colorTable[i].symbolic, "None")) |
428 | 870 { |
771 | 871 *transp = TRUE; |
872 colortbl[i] = transparent_color; | |
873 transp_idx = i; | |
428 | 874 goto label_found_color; |
875 } | |
876 else if (color_symbols) | |
877 { | |
771 | 878 for (j = 0; j < nsymbols; j++) |
428 | 879 { |
2367 | 880 if (!qxestrcmp_ascii (color_symbols[j].name, |
771 | 881 xpmimage.colorTable[i].symbolic)) |
428 | 882 { |
771 | 883 colortbl[i] = color_symbols[j].color; |
428 | 884 goto label_found_color; |
885 } | |
886 } | |
887 } | |
888 else if (xpmimage.colorTable[i].c_color == 0) | |
889 { | |
890 goto label_no_color; | |
891 } | |
892 } | |
893 /* pick up transparencies */ | |
771 | 894 if (!strcasecmp (xpmimage.colorTable[i].c_color, "None")) |
428 | 895 { |
771 | 896 *transp = TRUE; |
897 colortbl[i] = transparent_color; | |
898 transp_idx = i; | |
428 | 899 goto label_found_color; |
900 } | |
901 /* finally pick up a normal color spec */ | |
902 if (xpmimage.colorTable[i].c_color) | |
903 { | |
904 colortbl[i]= | |
867 | 905 mswindows_string_to_color ((Ibyte *) |
771 | 906 xpmimage.colorTable[i].c_color); |
428 | 907 goto label_found_color; |
908 } | |
434 | 909 |
428 | 910 label_no_color: |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
911 xfree (*data); |
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
912 xfree (colortbl); |
428 | 913 XpmFreeXpmImage (&xpmimage); |
914 XpmFreeXpmInfo (&xpminfo); | |
915 return 0; | |
434 | 916 |
428 | 917 label_found_color:; |
918 } | |
919 | |
920 /* convert the image */ | |
771 | 921 sptr = xpmimage.data; |
922 dptr= *data; | |
428 | 923 for (i = 0; i< *width * *height; i++) |
924 { | |
925 color = colortbl[*sptr++]; | |
926 | |
927 /* split out the 0x02bbggrr colorref into an rgb triple */ | |
928 *dptr++=GetRValue (color); /* red */ | |
929 *dptr++=GetGValue (color); /* green */ | |
930 *dptr++=GetBValue (color); /* blue */ | |
931 } | |
932 | |
771 | 933 *x_hot = xpminfo.x_hotspot; |
934 *y_hot = xpminfo.y_hotspot; | |
428 | 935 |
936 XpmFreeXpmImage (&xpmimage); | |
937 XpmFreeXpmInfo (&xpminfo); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
938 xfree (colortbl); |
428 | 939 return TRUE; |
940 } | |
941 | |
942 static void | |
943 mswindows_xpm_instantiate (Lisp_Object image_instance, | |
944 Lisp_Object instantiator, | |
2286 | 945 Lisp_Object UNUSED (pointer_fg), |
946 Lisp_Object UNUSED (pointer_bg), | |
428 | 947 int dest_mask, Lisp_Object domain) |
948 { | |
440 | 949 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
428 | 950 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
442 | 951 const Extbyte *bytes; |
665 | 952 Bytecount len; |
2367 | 953 Binbyte *eimage; |
428 | 954 int width, height, x_hot, y_hot; |
955 BITMAPINFO* bmp_info; | |
2367 | 956 Binbyte* bmp_data; |
428 | 957 int bmp_bits; |
771 | 958 int nsymbols = 0, transp; |
959 struct color_symbol* color_symbols = NULL; | |
434 | 960 |
428 | 961 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
962 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator, | |
963 Q_color_symbols); | |
964 | |
442 | 965 CHECK_MSGDI_DEVICE (device); |
428 | 966 |
967 assert (!NILP (data)); | |
968 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
969 LISP_STRING_TO_SIZED_EXTERNAL (data, bytes, len, Qbinary); |
428 | 970 |
971 /* in case we have color symbols */ | |
972 color_symbols = extract_xpm_color_names (device, domain, | |
973 color_symbol_alist, &nsymbols); | |
974 | |
975 /* convert to an eimage to make processing easier */ | |
976 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height, | |
977 &x_hot, &y_hot, &transp, color_symbols, nsymbols)) | |
978 { | |
563 | 979 signal_image_error ("XPM to EImage conversion failed", |
980 image_instance); | |
428 | 981 } |
434 | 982 |
428 | 983 if (color_symbols) |
984 { | |
985 while (nsymbols--) | |
986 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
987 xfree (color_symbols[nsymbols].name); |
428 | 988 } |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
989 xfree (color_symbols); |
428 | 990 } |
434 | 991 |
428 | 992 /* build a bitmap from the eimage */ |
771 | 993 if (!(bmp_info = convert_EImage_to_DIBitmap (device, width, height, eimage, |
428 | 994 &bmp_bits, &bmp_data))) |
995 { | |
563 | 996 signal_image_error ("XPM to EImage conversion failed", |
997 image_instance); | |
428 | 998 } |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
999 xfree (eimage); |
428 | 1000 |
1001 /* Now create the pixmap and set up the image instance */ | |
1002 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, | |
1003 bmp_data, bmp_bits, 1, instantiator, | |
1004 x_hot, y_hot, transp); | |
1005 | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1006 xfree (bmp_info); |
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1007 xfree (bmp_data); |
428 | 1008 } |
1009 #endif /* HAVE_XPM */ | |
1010 | |
1011 /********************************************************************** | |
1012 * BMP * | |
1013 **********************************************************************/ | |
1014 | |
1015 static void | |
1016 bmp_validate (Lisp_Object instantiator) | |
1017 { | |
1018 file_or_data_must_be_present (instantiator); | |
1019 } | |
1020 | |
1021 static Lisp_Object | |
442 | 1022 bmp_normalize (Lisp_Object inst, Lisp_Object console_type, |
2286 | 1023 Lisp_Object UNUSED (dest_mask)) |
428 | 1024 { |
1025 return simple_image_type_normalize (inst, console_type, Qbmp); | |
1026 } | |
1027 | |
1028 static int | |
1029 bmp_possible_dest_types (void) | |
1030 { | |
1031 return IMAGE_COLOR_PIXMAP_MASK; | |
1032 } | |
1033 | |
1034 static void | |
1035 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | |
2286 | 1036 Lisp_Object UNUSED (pointer_fg), |
1037 Lisp_Object UNUSED (pointer_bg), | |
1038 int dest_mask, Lisp_Object UNUSED (domain)) | |
428 | 1039 { |
440 | 1040 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
428 | 1041 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
442 | 1042 const Extbyte *bytes; |
665 | 1043 Bytecount len; |
771 | 1044 BITMAPFILEHEADER * bmp_file_header; |
1045 BITMAPINFO * bmp_info; | |
1046 void * bmp_data; | |
428 | 1047 int bmp_bits; |
1048 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
1049 | |
442 | 1050 CHECK_MSGDI_DEVICE (device); |
428 | 1051 |
1052 assert (!NILP (data)); | |
1053 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1054 LISP_STRING_TO_SIZED_EXTERNAL (data, bytes, len, Qbinary); |
434 | 1055 |
428 | 1056 /* Then slurp the image into memory, decoding along the way. |
1057 The result is the image in a simple one-byte-per-pixel | |
1058 format. */ | |
434 | 1059 |
771 | 1060 bmp_file_header = (BITMAPFILEHEADER *)bytes; |
1061 bmp_info = (BITMAPINFO *)(bytes + sizeof(BITMAPFILEHEADER)); | |
1062 bmp_data = (Extbyte *)bytes + bmp_file_header->bfOffBits; | |
428 | 1063 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits; |
1064 | |
1065 /* Now create the pixmap and set up the image instance */ | |
1066 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask, | |
1067 bmp_data, bmp_bits, 1, instantiator, | |
1068 0, 0, 0); | |
1069 } | |
1070 | |
1071 | |
1072 /********************************************************************** | |
1073 * RESOURCES * | |
1074 **********************************************************************/ | |
1075 | |
1076 static void | |
1077 mswindows_resource_validate (Lisp_Object instantiator) | |
1078 { | |
563 | 1079 shared_resource_validate (instantiator); |
428 | 1080 } |
1081 | |
1082 static Lisp_Object | |
442 | 1083 mswindows_resource_normalize (Lisp_Object inst, Lisp_Object console_type, |
1084 Lisp_Object dest_mask) | |
428 | 1085 { |
563 | 1086 return shared_resource_normalize (inst, console_type, dest_mask, |
1087 Qmswindows_resource); | |
428 | 1088 } |
1089 | |
1090 static int | |
1091 mswindows_resource_possible_dest_types (void) | |
1092 { | |
1093 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK; | |
1094 } | |
1095 | |
434 | 1096 typedef struct |
428 | 1097 { |
4932 | 1098 const Ascbyte *name; |
428 | 1099 int resource_id; |
1100 } resource_t; | |
1101 | |
442 | 1102 static const resource_t bitmap_table[] = |
428 | 1103 { |
1104 /* bitmaps */ | |
1105 { "close", OBM_CLOSE }, | |
1106 { "uparrow", OBM_UPARROW }, | |
1107 { "dnarrow", OBM_DNARROW }, | |
1108 { "rgarrow", OBM_RGARROW }, | |
1109 { "lfarrow", OBM_LFARROW }, | |
1110 { "reduce", OBM_REDUCE }, | |
1111 { "zoom", OBM_ZOOM }, | |
1112 { "restore", OBM_RESTORE }, | |
1113 { "reduced", OBM_REDUCED }, | |
1114 { "zoomd", OBM_ZOOMD }, | |
1115 { "restored", OBM_RESTORED }, | |
1116 { "uparrowd", OBM_UPARROWD }, | |
1117 { "dnarrowd", OBM_DNARROWD }, | |
1118 { "rgarrowd", OBM_RGARROWD }, | |
1119 { "lfarrowd", OBM_LFARROWD }, | |
1120 { "mnarrow", OBM_MNARROW }, | |
1121 { "combo", OBM_COMBO }, | |
1122 { "uparrowi", OBM_UPARROWI }, | |
1123 { "dnarrowi", OBM_DNARROWI }, | |
1124 { "rgarrowi", OBM_RGARROWI }, | |
1125 { "lfarrowi", OBM_LFARROWI }, | |
1126 { "size", OBM_SIZE }, | |
1127 { "btsize", OBM_BTSIZE }, | |
1128 { "check", OBM_CHECK }, | |
1129 { "checkboxes", OBM_CHECKBOXES }, | |
1130 { "btncorners" , OBM_BTNCORNERS }, | |
1131 {0} | |
1132 }; | |
1133 | |
442 | 1134 static const resource_t cursor_table[] = |
428 | 1135 { |
1136 /* cursors */ | |
1137 { "normal", OCR_NORMAL }, | |
1138 { "ibeam", OCR_IBEAM }, | |
1139 { "wait", OCR_WAIT }, | |
1140 { "cross", OCR_CROSS }, | |
1141 { "up", OCR_UP }, | |
1142 /* { "icon", OCR_ICON }, */ | |
1143 { "sizenwse", OCR_SIZENWSE }, | |
1144 { "sizenesw", OCR_SIZENESW }, | |
1145 { "sizewe", OCR_SIZEWE }, | |
1146 { "sizens", OCR_SIZENS }, | |
1147 { "sizeall", OCR_SIZEALL }, | |
1148 /* { "icour", OCR_ICOCUR }, */ | |
1149 { "no", OCR_NO }, | |
1150 { 0 } | |
1151 }; | |
1152 | |
442 | 1153 static const resource_t icon_table[] = |
428 | 1154 { |
1155 /* icons */ | |
1156 { "sample", OIC_SAMPLE }, | |
1157 { "hand", OIC_HAND }, | |
1158 { "ques", OIC_QUES }, | |
1159 { "bang", OIC_BANG }, | |
1160 { "note", OIC_NOTE }, | |
1161 { "winlogo", OIC_WINLOGO }, | |
1162 {0} | |
1163 }; | |
1164 | |
771 | 1165 static int |
1166 resource_name_to_resource (Lisp_Object name, int type) | |
428 | 1167 { |
771 | 1168 const resource_t *res = (type == IMAGE_CURSOR ? cursor_table |
434 | 1169 : type == IMAGE_ICON ? icon_table |
428 | 1170 : bitmap_table); |
1171 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1172 if (FIXNUMP (name)) |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1173 return XFIXNUM (name); |
771 | 1174 else if (!STRINGP (name)) |
1175 invalid_argument ("invalid resource identifier", name); | |
1176 | |
1177 do | |
428 | 1178 { |
867 | 1179 if (!qxestrcasecmp_i18n ((Ibyte *) res->name, XSTRING_DATA (name))) |
771 | 1180 return res->resource_id; |
428 | 1181 } |
771 | 1182 while ((++res)->name); |
428 | 1183 return 0; |
1184 } | |
1185 | |
1186 static int | |
1187 resource_symbol_to_type (Lisp_Object data) | |
1188 { | |
1189 if (EQ (data, Qcursor)) | |
1190 return IMAGE_CURSOR; | |
1191 else if (EQ (data, Qicon)) | |
1192 return IMAGE_ICON; | |
1193 else if (EQ (data, Qbitmap)) | |
1194 return IMAGE_BITMAP; | |
1195 else | |
1196 return 0; | |
1197 } | |
1198 | |
1199 static void | |
502 | 1200 mswindows_resource_instantiate (Lisp_Object image_instance, |
1201 Lisp_Object instantiator, | |
2286 | 1202 Lisp_Object UNUSED (pointer_fg), |
1203 Lisp_Object UNUSED (pointer_bg), | |
1204 int dest_mask, Lisp_Object UNUSED (domain)) | |
428 | 1205 { |
440 | 1206 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
647 | 1207 int type = 0; |
428 | 1208 HANDLE himage = NULL; |
771 | 1209 Extbyte *resid = 0; |
428 | 1210 HINSTANCE hinst = NULL; |
1211 ICONINFO iconinfo; | |
442 | 1212 enum image_instance_type iitype; |
428 | 1213 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
1214 | |
1215 Lisp_Object file = find_keyword_in_vector (instantiator, Q_file); | |
434 | 1216 Lisp_Object resource_type = find_keyword_in_vector (instantiator, |
428 | 1217 Q_resource_type); |
434 | 1218 Lisp_Object resource_id = find_keyword_in_vector (instantiator, |
428 | 1219 Q_resource_id); |
1220 | |
1221 xzero (iconinfo); | |
1222 | |
442 | 1223 CHECK_MSGDI_DEVICE (device); |
428 | 1224 |
1225 type = resource_symbol_to_type (resource_type); | |
1226 | |
1227 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_CURSOR) | |
1228 iitype = IMAGE_POINTER; | |
1229 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK) | |
1230 iitype = IMAGE_COLOR_PIXMAP; | |
434 | 1231 else |
428 | 1232 incompatible_image_types (instantiator, dest_mask, |
1233 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK); | |
1234 | |
1235 /* mess with the keyword info we were provided with */ | |
1236 if (!NILP (file)) | |
1237 { | |
771 | 1238 Extbyte *fname; |
1239 | |
4834
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
2959
diff
changeset
|
1240 LISP_LOCAL_FILE_FORMAT_TO_TSTR (file, fname); |
434 | 1241 |
428 | 1242 if (NILP (resource_id)) |
771 | 1243 resid = fname; |
428 | 1244 else |
1245 { | |
771 | 1246 hinst = qxeLoadLibraryEx (fname, NULL, LOAD_LIBRARY_AS_DATAFILE); |
428 | 1247 resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id, |
771 | 1248 type)); |
434 | 1249 |
428 | 1250 if (!resid) |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1251 resid = LISP_STRING_TO_TSTR (resource_id); |
428 | 1252 } |
1253 } | |
1254 else if (!(resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id, | |
771 | 1255 type)))) |
563 | 1256 invalid_argument ("Invalid resource identifier", resource_id); |
434 | 1257 |
428 | 1258 /* load the image */ |
771 | 1259 if (!(himage = qxeLoadImage (hinst, resid, type, 0, 0, |
1260 LR_CREATEDIBSECTION | LR_DEFAULTSIZE | | |
1261 LR_SHARED | | |
1262 (!NILP (file) ? LR_LOADFROMFILE : 0)))) | |
1263 signal_image_error ("Cannot load image", instantiator); | |
428 | 1264 |
1265 if (hinst) | |
1266 FreeLibrary (hinst); | |
1267 | |
1268 mswindows_initialize_dibitmap_image_instance (ii, 1, iitype); | |
1269 | |
1270 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = file; | |
442 | 1271 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii) = |
428 | 1272 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CXCURSOR : SM_CXICON); |
442 | 1273 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii) = |
428 | 1274 GetSystemMetrics (type == IMAGE_CURSOR ? SM_CYCURSOR : SM_CYICON); |
1275 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1; | |
442 | 1276 init_image_instance_geometry (ii); |
428 | 1277 |
1278 /* hey, we've got an icon type thing so we can reverse engineer the | |
1279 bitmap and mask */ | |
1280 if (type != IMAGE_BITMAP) | |
1281 { | |
442 | 1282 GetIconInfo ((HICON)himage, &iconinfo); |
428 | 1283 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = iconinfo.hbmColor; |
1284 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = iconinfo.hbmMask; | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1285 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_fixnum (iconinfo.xHotspot); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1286 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_fixnum (iconinfo.yHotspot); |
442 | 1287 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = (HICON) himage; |
428 | 1288 } |
1289 else | |
1290 { | |
1291 IMAGE_INSTANCE_MSWINDOWS_ICON (ii) = NULL; | |
442 | 1292 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = (HBITMAP) himage; |
428 | 1293 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = NULL; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1294 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_fixnum (0); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1295 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_fixnum (0); |
428 | 1296 } |
1297 } | |
1298 | |
1299 static void | |
1300 check_valid_resource_symbol (Lisp_Object data) | |
1301 { | |
1302 CHECK_SYMBOL (data); | |
1303 if (!resource_symbol_to_type (data)) | |
563 | 1304 invalid_constant ("invalid resource type", data); |
428 | 1305 } |
1306 | |
1307 static void | |
1308 check_valid_resource_id (Lisp_Object data) | |
1309 { | |
1310 if (!resource_name_to_resource (data, IMAGE_CURSOR) | |
1311 && | |
1312 !resource_name_to_resource (data, IMAGE_ICON) | |
1313 && | |
1314 !resource_name_to_resource (data, IMAGE_BITMAP)) | |
563 | 1315 invalid_constant ("invalid resource identifier", data); |
428 | 1316 } |
1317 | |
771 | 1318 |
428 | 1319 /********************************************************************** |
1320 * XBM * | |
1321 **********************************************************************/ | |
771 | 1322 |
428 | 1323 /* this table flips four bits around. */ |
1324 static int flip_table[] = | |
1325 { | |
1326 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 | |
1327 }; | |
1328 | |
1329 /* the bitmap data comes in the following format: Widths are padded to | |
1330 a multiple of 8. Scan lines are stored in increasing byte order | |
1331 from left to right, little-endian within a byte. 0 = white, 1 = | |
1332 black. It must be converted to the following format: Widths are | |
1333 padded to a multiple of 16. Scan lines are stored in increasing | |
1334 byte order from left to right, big-endian within a byte. 0 = | |
1335 black, 1 = white. */ | |
438 | 1336 static HBITMAP |
2367 | 1337 xbm_create_bitmap_from_data (HDC hdc, const Binbyte *data, |
647 | 1338 int width, int height, |
428 | 1339 int mask, COLORREF fg, COLORREF bg) |
1340 { | |
1341 int old_width = (width + 7)/8; | |
771 | 1342 int new_width = BPLINE (2 * ((width + 15)/16)); |
2367 | 1343 const Binbyte *offset; |
428 | 1344 void *bmp_buf = 0; |
2367 | 1345 Binbyte *new_data, *new_offset; |
428 | 1346 int i, j; |
442 | 1347 BITMAPINFO *bmp_info = |
771 | 1348 (BITMAPINFO *) xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD)); |
428 | 1349 HBITMAP bitmap; |
1350 | |
1351 if (!bmp_info) | |
1352 return NULL; | |
434 | 1353 |
2367 | 1354 new_data = xnew_array_and_zero (Binbyte, height * new_width); |
434 | 1355 |
428 | 1356 if (!new_data) |
1357 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1358 xfree (bmp_info); |
428 | 1359 return NULL; |
1360 } | |
434 | 1361 |
771 | 1362 for (i = 0; i < height; i++) |
428 | 1363 { |
771 | 1364 offset = data + i * old_width; |
1365 new_offset = new_data + i * new_width; | |
1366 | |
1367 for (j = 0; j < old_width; j++) | |
428 | 1368 { |
771 | 1369 int bite = offset[j]; |
2367 | 1370 new_offset[j] = ~ (Binbyte) |
771 | 1371 ((flip_table[bite & 0xf] << 4) + flip_table[bite >> 4]); |
428 | 1372 } |
1373 } | |
1374 | |
1375 /* if we want a mask invert the bits */ | |
1376 if (!mask) | |
1377 { | |
1378 new_offset = &new_data[height * new_width]; | |
1379 while (new_offset-- != new_data) | |
1380 { | |
1381 *new_offset ^= 0xff; | |
1382 } | |
1383 } | |
1384 | |
771 | 1385 bmp_info->bmiHeader.biWidth = width; |
428 | 1386 bmp_info->bmiHeader.biHeight=-(LONG)height; |
771 | 1387 bmp_info->bmiHeader.biPlanes = 1; |
1388 bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
1389 bmp_info->bmiHeader.biBitCount = 1; | |
1390 bmp_info->bmiHeader.biCompression = BI_RGB; | |
434 | 1391 bmp_info->bmiHeader.biClrUsed = 2; |
1392 bmp_info->bmiHeader.biClrImportant = 2; | |
1393 bmp_info->bmiHeader.biSizeImage = height * new_width; | |
428 | 1394 bmp_info->bmiColors[0].rgbRed = GetRValue (fg); |
1395 bmp_info->bmiColors[0].rgbGreen = GetGValue (fg); | |
1396 bmp_info->bmiColors[0].rgbBlue = GetBValue (fg); | |
1397 bmp_info->bmiColors[0].rgbReserved = 0; | |
1398 bmp_info->bmiColors[1].rgbRed = GetRValue (bg); | |
1399 bmp_info->bmiColors[1].rgbGreen = GetGValue (bg); | |
1400 bmp_info->bmiColors[1].rgbBlue = GetBValue (bg); | |
1401 bmp_info->bmiColors[1].rgbReserved = 0; | |
434 | 1402 |
1403 bitmap = CreateDIBSection (hdc, | |
428 | 1404 bmp_info, |
1405 DIB_RGB_COLORS, | |
434 | 1406 &bmp_buf, |
428 | 1407 0,0); |
1408 | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1409 xfree (bmp_info); |
434 | 1410 |
428 | 1411 if (!bitmap || !bmp_buf) |
1412 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1413 xfree (new_data); |
428 | 1414 return NULL; |
1415 } | |
434 | 1416 |
428 | 1417 /* copy in the actual bitmap */ |
1418 memcpy (bmp_buf, new_data, height * new_width); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1419 xfree (new_data); |
428 | 1420 |
1421 return bitmap; | |
1422 } | |
1423 | |
1424 /* Given inline data for a mono pixmap, initialize the given | |
1425 image instance accordingly. */ | |
1426 | |
1427 static void | |
440 | 1428 init_image_instance_from_xbm_inline (Lisp_Image_Instance *ii, |
428 | 1429 int width, int height, |
2367 | 1430 const Binbyte *bits, |
428 | 1431 Lisp_Object instantiator, |
1432 Lisp_Object pointer_fg, | |
1433 Lisp_Object pointer_bg, | |
1434 int dest_mask, | |
1435 HBITMAP mask, | |
2286 | 1436 Lisp_Object UNUSED (mask_filename)) |
428 | 1437 { |
1438 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | |
1439 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground); | |
1440 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background); | |
1441 enum image_instance_type type; | |
1442 COLORREF black = PALETTERGB (0,0,0); | |
1443 COLORREF white = PALETTERGB (255,255,255); | |
442 | 1444 HDC hdc; |
1445 | |
1446 CHECK_MSGDI_DEVICE (device); | |
1447 | |
1448 hdc = get_device_compdc (XDEVICE (device)); | |
428 | 1449 |
1450 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) && | |
1451 (dest_mask & IMAGE_COLOR_PIXMAP_MASK)) | |
1452 { | |
1453 if (!NILP (foreground) || !NILP (background)) | |
1454 type = IMAGE_COLOR_PIXMAP; | |
1455 else | |
1456 type = IMAGE_MONO_PIXMAP; | |
1457 } | |
1458 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK) | |
1459 type = IMAGE_MONO_PIXMAP; | |
1460 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK) | |
1461 type = IMAGE_COLOR_PIXMAP; | |
1462 else if (dest_mask & IMAGE_POINTER_MASK) | |
1463 type = IMAGE_POINTER; | |
1464 else | |
1465 incompatible_image_types (instantiator, dest_mask, | |
1466 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK | |
1467 | IMAGE_POINTER_MASK); | |
1468 | |
1469 mswindows_initialize_dibitmap_image_instance (ii, 1, type); | |
434 | 1470 |
428 | 1471 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = |
1472 find_keyword_in_vector (instantiator, Q_file); | |
442 | 1473 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_WIDTH (ii) = width; |
1474 IMAGE_INSTANCE_MSWINDOWS_BITMAP_REAL_HEIGHT (ii) = height; | |
428 | 1475 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1476 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_fixnum (0); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1477 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_fixnum (0); |
442 | 1478 init_image_instance_geometry (ii); |
1479 | |
428 | 1480 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = mask ? mask : |
593 | 1481 xbm_create_bitmap_from_data (hdc, bits, width, height, TRUE, black, white); |
428 | 1482 |
1483 switch (type) | |
1484 { | |
1485 case IMAGE_MONO_PIXMAP: | |
434 | 1486 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = |
593 | 1487 xbm_create_bitmap_from_data (hdc, bits, width, height, |
428 | 1488 FALSE, black, black); |
1489 break; | |
1490 | |
1491 case IMAGE_COLOR_PIXMAP: | |
1492 { | |
1493 COLORREF fg = black; | |
1494 COLORREF bg = white; | |
1495 | |
1496 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground)) | |
1497 foreground = | |
1498 Fmake_color_instance (foreground, device, | |
1499 encode_error_behavior_flag (ERROR_ME)); | |
1500 | |
1501 if (COLOR_INSTANCEP (foreground)) | |
1502 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground)); | |
1503 | |
1504 if (!NILP (background) && !COLOR_INSTANCEP (background)) | |
1505 background = | |
1506 Fmake_color_instance (background, device, | |
1507 encode_error_behavior_flag (ERROR_ME)); | |
1508 | |
1509 if (COLOR_INSTANCEP (background)) | |
1510 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background)); | |
1511 | |
1512 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground; | |
1513 IMAGE_INSTANCE_PIXMAP_BG (ii) = background; | |
1514 | |
434 | 1515 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = |
593 | 1516 xbm_create_bitmap_from_data (hdc, bits, width, height, |
428 | 1517 FALSE, fg, black); |
1518 } | |
1519 break; | |
1520 | |
1521 case IMAGE_POINTER: | |
1522 { | |
1523 COLORREF fg = black; | |
1524 COLORREF bg = white; | |
1525 | |
1526 if (NILP (foreground)) | |
1527 foreground = pointer_fg; | |
1528 if (NILP (background)) | |
1529 background = pointer_bg; | |
1530 | |
434 | 1531 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = |
428 | 1532 find_keyword_in_vector (instantiator, Q_hotspot_x); |
434 | 1533 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = |
428 | 1534 find_keyword_in_vector (instantiator, Q_hotspot_y); |
1535 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground; | |
1536 IMAGE_INSTANCE_PIXMAP_BG (ii) = background; | |
1537 if (COLOR_INSTANCEP (foreground)) | |
1538 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground)); | |
1539 if (COLOR_INSTANCEP (background)) | |
1540 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background)); | |
1541 | |
434 | 1542 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = |
593 | 1543 xbm_create_bitmap_from_data (hdc, bits, width, height, |
428 | 1544 TRUE, fg, black); |
1545 mswindows_initialize_image_instance_icon (ii, TRUE); | |
1546 } | |
1547 break; | |
1548 | |
1549 default: | |
2500 | 1550 ABORT (); |
428 | 1551 } |
1552 } | |
1553 | |
1554 static void | |
1555 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator, | |
1556 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | |
1557 int dest_mask, int width, int height, | |
2367 | 1558 const Binbyte *bits) |
428 | 1559 { |
1560 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data); | |
1561 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file); | |
440 | 1562 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
442 | 1563 HDC hdc = get_device_compdc (XDEVICE (IMAGE_INSTANCE_DEVICE (ii))); |
428 | 1564 HBITMAP mask = 0; |
1565 | |
1566 if (!NILP (mask_data)) | |
1567 { | |
2367 | 1568 Binbyte *ext_data; |
440 | 1569 |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1570 ext_data = |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1571 (Binbyte *) LISP_STRING_TO_EXTERNAL (XCAR (XCDR (XCDR (mask_data))), |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1572 Qbinary); |
440 | 1573 mask = xbm_create_bitmap_from_data (hdc, |
593 | 1574 ext_data, |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1575 XFIXNUM (XCAR (mask_data)), |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1576 XFIXNUM (XCAR (XCDR (mask_data))), |
440 | 1577 FALSE, |
1578 PALETTERGB (0,0,0), | |
1579 PALETTERGB (255,255,255)); | |
428 | 1580 } |
1581 | |
1582 init_image_instance_from_xbm_inline (ii, width, height, bits, | |
1583 instantiator, pointer_fg, pointer_bg, | |
1584 dest_mask, mask, mask_file); | |
1585 } | |
1586 | |
1587 /* Instantiate method for XBM's. */ | |
1588 | |
1589 static void | |
434 | 1590 mswindows_xbm_instantiate (Lisp_Object image_instance, |
428 | 1591 Lisp_Object instantiator, |
1592 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | |
2286 | 1593 int dest_mask, Lisp_Object UNUSED (domain)) |
428 | 1594 { |
1595 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
2367 | 1596 const Binbyte *ext_data; |
428 | 1597 |
1598 assert (!NILP (data)); | |
1599 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1600 ext_data = |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1601 (const Binbyte *) LISP_STRING_TO_EXTERNAL (XCAR (XCDR (XCDR (data))), |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1602 Qbinary); |
428 | 1603 |
1604 xbm_instantiate_1 (image_instance, instantiator, pointer_fg, | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1605 pointer_bg, dest_mask, XFIXNUM (XCAR (data)), |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
1606 XFIXNUM (XCAR (XCDR (data))), ext_data); |
428 | 1607 } |
1608 | |
1609 #ifdef HAVE_XFACE | |
1610 /********************************************************************** | |
1611 * X-Face * | |
1612 **********************************************************************/ | |
1613 #if defined(EXTERN) | |
1614 /* This is about to get redefined! */ | |
1615 #undef EXTERN | |
1616 #endif | |
1617 /* We have to define SYSV32 so that compface.h includes string.h | |
1618 instead of strings.h. */ | |
1619 #define SYSV32 | |
1743 | 1620 BEGIN_C_DECLS |
2500 | 1621 #ifndef __STDC__ /* Needed to avoid prototype warnings */ |
1622 #define __STDC__ | |
1623 #endif | |
428 | 1624 #include <compface.h> |
1743 | 1625 END_C_DECLS |
1626 | |
428 | 1627 /* JMP_BUF cannot be used here because if it doesn't get defined |
1628 to jmp_buf we end up with a conflicting type error with the | |
1629 definition in compface.h */ | |
1630 extern jmp_buf comp_env; | |
1631 #undef SYSV32 | |
1632 | |
1633 static void | |
502 | 1634 mswindows_xface_instantiate (Lisp_Object image_instance, |
1635 Lisp_Object instantiator, | |
428 | 1636 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
2286 | 1637 int dest_mask, Lisp_Object UNUSED (domain)) |
428 | 1638 { |
1639 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
1640 int i, stattis; | |
2367 | 1641 Binbyte *p, *bits, *bp; |
867 | 1642 const CIbyte * volatile emsg = 0; |
2367 | 1643 const Binbyte * volatile dstring; |
428 | 1644 |
1645 assert (!NILP (data)); | |
1646 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1647 dstring = (const Binbyte *) LISP_STRING_TO_EXTERNAL (data, Qbinary); |
428 | 1648 |
2367 | 1649 if ((p = (Binbyte *) strchr ((char *) dstring, ':'))) |
428 | 1650 { |
1651 dstring = p + 1; | |
1652 } | |
1653 | |
1654 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */ | |
1655 if (!(stattis = setjmp (comp_env))) | |
1656 { | |
1657 UnCompAll ((char *) dstring); | |
1658 UnGenFace (); | |
1659 } | |
1660 | |
1661 switch (stattis) | |
1662 { | |
1663 case -2: | |
1664 emsg = "uncompface: internal error"; | |
1665 break; | |
1666 case -1: | |
1667 emsg = "uncompface: insufficient or invalid data"; | |
1668 break; | |
1669 case 1: | |
1670 emsg = "uncompface: excess data ignored"; | |
1671 break; | |
1672 } | |
1673 | |
1674 if (emsg) | |
563 | 1675 signal_image_error_2 (emsg, data, Qimage); |
428 | 1676 |
2367 | 1677 bp = bits = alloca_binbytes (PIXELS / 8); |
428 | 1678 |
1679 /* the compface library exports char F[], which uses a single byte per | |
1680 pixel to represent a 48x48 bitmap. Yuck. */ | |
2367 | 1681 for (i = 0, p = (Binbyte *) F; i < (PIXELS / 8); ++i) |
428 | 1682 { |
1683 int n, b; | |
1684 /* reverse the bit order of each byte... */ | |
1685 for (b = n = 0; b < 8; ++b) | |
1686 { | |
1687 n |= ((*p++) << b); | |
1688 } | |
2367 | 1689 *bp++ = (Binbyte) n; |
428 | 1690 } |
1691 | |
1692 xbm_instantiate_1 (image_instance, instantiator, pointer_fg, | |
1693 pointer_bg, dest_mask, 48, 48, bits); | |
1694 } | |
1695 #endif /* HAVE_XFACE */ | |
1696 | |
1697 | |
1698 /************************************************************************/ | |
1699 /* image instance methods */ | |
1700 /************************************************************************/ | |
1701 | |
1702 static void | |
440 | 1703 mswindows_print_image_instance (Lisp_Image_Instance *p, |
428 | 1704 Lisp_Object printcharfun, |
2286 | 1705 int UNUSED (escapeflag)) |
428 | 1706 { |
1707 switch (IMAGE_INSTANCE_TYPE (p)) | |
1708 { | |
1709 case IMAGE_MONO_PIXMAP: | |
1710 case IMAGE_COLOR_PIXMAP: | |
1711 case IMAGE_POINTER: | |
800 | 1712 write_fmt_string (printcharfun, " (0x%lx", |
1713 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p)); | |
428 | 1714 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p)) |
1715 { | |
800 | 1716 write_fmt_string (printcharfun, "/0x%lx", |
1717 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p)); | |
428 | 1718 } |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
1719 write_ascstring (printcharfun, ")"); |
428 | 1720 break; |
1721 | |
1722 default: | |
1723 break; | |
1724 } | |
1725 } | |
1726 | |
1727 #ifdef DEBUG_WIDGETS | |
1728 extern int debug_widget_instances; | |
1729 #endif | |
1730 | |
1731 static void | |
611 | 1732 finalize_destroy_window (void *win) |
1733 { | |
1734 DestroyWindow ((HWND) win); | |
1735 } | |
1736 | |
1737 static void | |
440 | 1738 mswindows_finalize_image_instance (Lisp_Image_Instance *p) |
428 | 1739 { |
442 | 1740 if (!p->data) |
1741 return; | |
1742 | |
1743 if (DEVICE_LIVE_P (XDEVICE (IMAGE_INSTANCE_DEVICE (p)))) | |
428 | 1744 { |
442 | 1745 if (image_instance_type_to_mask (IMAGE_INSTANCE_TYPE (p)) |
1746 & (IMAGE_WIDGET_MASK | IMAGE_SUBWINDOW_MASK)) | |
428 | 1747 { |
1748 #ifdef DEBUG_WIDGETS | |
1749 debug_widget_instances--; | |
1750 stderr_out ("widget destroyed, %d left\n", debug_widget_instances); | |
1751 #endif | |
1752 if (IMAGE_INSTANCE_SUBWINDOW_ID (p)) | |
1753 { | |
611 | 1754 /* DestroyWindow is not safe here, as it will send messages |
1755 to our window proc. */ | |
1756 register_post_gc_action | |
1757 (finalize_destroy_window, | |
1758 (void *) (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p))); | |
1759 register_post_gc_action | |
1760 (finalize_destroy_window, | |
1761 (void *) (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p))); | |
428 | 1762 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0; |
1763 } | |
1764 } | |
1765 else if (p->data) | |
1766 { | |
1767 int i; | |
1768 if (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p)) | |
1769 disable_glyph_animated_timeout (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p)); | |
1770 | |
1771 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (p)) | |
1772 { | |
1773 for (i = 0; i < IMAGE_INSTANCE_PIXMAP_MAXSLICE (p); i++) | |
1774 { | |
1775 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (p, i)) | |
1776 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (p, i)); | |
1777 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE (p, i) = 0; | |
1778 } | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1779 xfree (IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (p)); |
428 | 1780 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (p) = 0; |
1781 } | |
1782 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p)) | |
1783 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p)); | |
1784 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0; | |
1785 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p)) | |
1786 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p)); | |
1787 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0; | |
1788 } | |
1789 } | |
1790 | |
1791 if (p->data) | |
1792 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1793 xfree (p->data); |
428 | 1794 p->data = 0; |
1795 } | |
1796 } | |
1797 | |
1798 /************************************************************************/ | |
771 | 1799 /* subwindow and widget support */ |
428 | 1800 /************************************************************************/ |
1801 | |
771 | 1802 static Lisp_Object |
2333 | 1803 charset_of_text (Lisp_Object USED_IF_MULE (text)) |
771 | 1804 { |
1805 #ifdef MULE | |
867 | 1806 Ibyte *p; |
771 | 1807 |
1808 if (NILP (text)) | |
1809 return Vcharset_ascii; | |
1810 for (p = XSTRING_DATA (text); *p;) | |
1811 { | |
867 | 1812 Ichar c = itext_ichar (p); |
1813 if (!EQ (ichar_charset (c), Vcharset_ascii)) | |
1814 return ichar_charset (c); | |
1815 INC_IBYTEPTR (p); | |
771 | 1816 } |
1817 #endif /* MULE */ | |
1818 | |
1819 return Vcharset_ascii; | |
1820 } | |
1821 | |
1822 | |
440 | 1823 static HFONT |
771 | 1824 mswindows_widget_hfont (Lisp_Object face, |
1825 Lisp_Object domain, | |
1826 Lisp_Object text) | |
440 | 1827 { |
1828 int under = FACE_UNDERLINE_P (face, domain); | |
1829 int strike = FACE_STRIKETHRU_P (face, domain); | |
771 | 1830 Lisp_Object font; |
1831 struct face_cachel frame_cachel; | |
1832 struct face_cachel *cachel; | |
1833 Lisp_Object charset; | |
1834 | |
1835 reset_face_cachel (&frame_cachel); | |
1836 update_face_cachel_data (&frame_cachel, domain, face); | |
1837 cachel = &frame_cachel; | |
1838 /* !!#### This is a big hack. We return the first non-ASCII charset in | |
1839 the string, on the assumption that we can display ASCII characters in | |
1840 all fonts. We really need to draw the text of the widget ourselves; | |
1841 or perhaps there are fonts supporting lots of character sets? */ | |
1842 charset = charset_of_text (text); | |
1843 | |
1844 font = FACE_CACHEL_FONT (cachel, charset); | |
1845 | |
1846 if (!FONT_INSTANCEP (font)) | |
1847 font = ensure_face_cachel_contains_charset (cachel, domain, charset); | |
1848 | |
1849 if (EQ (font, Vthe_null_font_instance)) | |
1850 font = FACE_CACHEL_FONT (cachel, Vcharset_ascii); | |
440 | 1851 |
1852 return mswindows_get_hfont (XFONT_INSTANCE (font), under, strike); | |
1853 } | |
1854 | |
872 | 1855 #ifdef DEFER_WINDOW_POS |
1856 | |
442 | 1857 static HDWP |
1858 begin_defer_window_pos (struct frame *f) | |
1859 { | |
1860 if (FRAME_MSWINDOWS_DATA (f)->hdwp == 0) | |
1861 FRAME_MSWINDOWS_DATA (f)->hdwp = BeginDeferWindowPos (10); | |
1862 return FRAME_MSWINDOWS_DATA (f)->hdwp; | |
1863 } | |
1864 | |
872 | 1865 #endif |
1866 | |
428 | 1867 /* unmap the image if it is a widget. This is used by redisplay via |
1868 redisplay_unmap_subwindows */ | |
1869 static void | |
440 | 1870 mswindows_unmap_subwindow (Lisp_Image_Instance *p) |
428 | 1871 { |
1872 if (IMAGE_INSTANCE_SUBWINDOW_ID (p)) | |
1873 { | |
442 | 1874 #ifdef DEFER_WINDOW_POS |
1875 struct frame *f = XFRAME (IMAGE_INSTANCE_FRAME (p)); | |
1876 HDWP hdwp = begin_defer_window_pos (f); | |
1877 HDWP new_hdwp; | |
1878 new_hdwp = DeferWindowPos (hdwp, IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p), | |
1879 NULL, | |
1880 0, 0, 0, 0, | |
1881 SWP_HIDEWINDOW | SWP_NOACTIVATE | | |
1882 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | |
1883 /* Setting this flag causes the call to | |
1884 DeferWindowPos to fail with | |
1885 "Invalid parameter". I don't understand | |
1886 why we bother to try and set this | |
1887 anyway. -- ben */ | |
1888 /* | SWP_NOSENDCHANGING */ | |
1889 ); | |
1890 if (!new_hdwp) | |
1891 mswindows_output_last_error ("unmapping"); | |
1892 else | |
1893 hdwp = new_hdwp; | |
1894 FRAME_MSWINDOWS_DATA (f)->hdwp = hdwp; | |
1895 #else | |
434 | 1896 SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p), |
1897 NULL, | |
428 | 1898 0, 0, 0, 0, |
442 | 1899 SWP_HIDEWINDOW | SWP_NOACTIVATE | |
1900 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER ); | |
1901 #endif | |
440 | 1902 if (GetFocus() == WIDGET_INSTANCE_MSWINDOWS_HANDLE (p)) |
1903 SetFocus (GetParent (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p))); | |
428 | 1904 } |
1905 } | |
1906 | |
1907 /* map the subwindow. This is used by redisplay via | |
1908 redisplay_output_subwindow */ | |
1909 static void | |
440 | 1910 mswindows_map_subwindow (Lisp_Image_Instance *p, int x, int y, |
771 | 1911 struct display_glyph_area *dga) |
428 | 1912 { |
442 | 1913 #ifdef DEFER_WINDOW_POS |
1914 struct frame *f = XFRAME (IMAGE_INSTANCE_FRAME (p)); | |
1915 HDWP hdwp = begin_defer_window_pos (f); | |
1916 HDWP new_hdwp; | |
1917 #endif | |
428 | 1918 /* move the window before mapping it ... */ |
1919 SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p), | |
434 | 1920 NULL, |
428 | 1921 x, y, dga->width, dga->height, |
434 | 1922 SWP_NOZORDER |
428 | 1923 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING); |
1924 /* ... adjust the child ... */ | |
1925 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), | |
434 | 1926 NULL, |
428 | 1927 -dga->xoffset, -dga->yoffset, 0, 0, |
1928 SWP_NOZORDER | SWP_NOSIZE | |
1929 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING); | |
1930 /* ... now map it - we are not allowed to move it at the same time. */ | |
442 | 1931 if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p)) |
1932 { | |
1933 #ifdef DEFER_WINDOW_POS | |
1934 new_hdwp = DeferWindowPos | |
1935 (hdwp, | |
1936 IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p), | |
1937 NULL, 0, 0, 0, 0, | |
1938 SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | |
1939 | SWP_SHOWWINDOW | |
1940 /* | SWP_NOCOPYBITS */ | |
1941 /* Setting this flag causes the call to | |
1942 DeferWindowPos to fail with | |
1943 "Invalid parameter". I don't understand | |
1944 why we bother to try and set this | |
1945 anyway. -- ben */ | |
1946 /* | SWP_NOSENDCHANGING */ | |
1947 | SWP_NOACTIVATE); | |
1948 if (!new_hdwp) | |
1949 mswindows_output_last_error ("mapping"); | |
1950 else | |
1951 hdwp = new_hdwp; | |
1952 FRAME_MSWINDOWS_DATA (f)->hdwp = hdwp; | |
1953 #else | |
1954 SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p), | |
1955 NULL, | |
1956 0, 0, 0, 0, | |
1957 SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | |
1958 | SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOACTIVATE); | |
863 | 1959 |
1960 /* Doing this once does not seem to be enough, for instance when | |
1961 mapping the search dialog this gets called four times. If we | |
1962 only set on the first time through then the subwindow never | |
5384
3889ef128488
Fix misspelled words, and some grammar, across the entire source tree.
Jerry James <james@xemacs.org>
parents:
5192
diff
changeset
|
1963 gets focus as intended. However, doing this every time doesn't |
863 | 1964 seem so bad, after all we only need to redo this after the |
1965 focus changes - and if that happens resetting the initial | |
1966 focus doesn't seem so bad. */ | |
1967 if (IMAGE_INSTANCE_WANTS_INITIAL_FOCUS (p)) | |
1968 SetFocus (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p)); | |
442 | 1969 #endif |
1970 } | |
428 | 1971 } |
1972 | |
1973 /* resize the subwindow instance */ | |
434 | 1974 static void |
771 | 1975 mswindows_resize_subwindow (Lisp_Image_Instance *ii, int w, int h) |
428 | 1976 { |
1977 /* Set the size of the control .... */ | |
442 | 1978 if (!SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii), |
1979 NULL, | |
1980 0, 0, w, h, | |
1981 SWP_NOZORDER | SWP_NOMOVE | |
1982 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING)) | |
1983 mswindows_output_last_error ("resizing"); | |
1984 } | |
1985 | |
1986 /* Simply resize the window here. */ | |
1987 static void | |
1988 mswindows_redisplay_subwindow (Lisp_Image_Instance *p) | |
1989 { | |
1990 mswindows_resize_subwindow (p, | |
1991 IMAGE_INSTANCE_WIDTH (p), | |
1992 IMAGE_INSTANCE_HEIGHT (p)); | |
428 | 1993 } |
1994 | |
1995 /* when you click on a widget you may activate another widget this | |
1996 needs to be checked and all appropriate widgets updated */ | |
1997 static void | |
442 | 1998 mswindows_redisplay_widget (Lisp_Image_Instance *p) |
428 | 1999 { |
442 | 2000 /* Possibly update the face font and colors. */ |
2001 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (p)) | |
2002 && (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (p) | |
2003 || XFRAME (IMAGE_INSTANCE_FRAME (p))->faces_changed | |
2004 || IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))) | |
428 | 2005 { |
2006 /* set the widget font from the widget face */ | |
771 | 2007 qxeSendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), |
2008 WM_SETFONT, | |
2009 (WPARAM) mswindows_widget_hfont | |
2010 (IMAGE_INSTANCE_WIDGET_FACE (p), | |
2011 IMAGE_INSTANCE_FRAME (p), | |
2012 IMAGE_INSTANCE_WIDGET_TEXT (p)), | |
2013 MAKELPARAM (TRUE, 0)); | |
428 | 2014 } |
442 | 2015 /* Possibly update the dimensions. */ |
2016 if (IMAGE_INSTANCE_SIZE_CHANGED (p)) | |
2017 { | |
2018 mswindows_resize_subwindow (p, | |
2019 IMAGE_INSTANCE_WIDTH (p), | |
2020 IMAGE_INSTANCE_HEIGHT (p)); | |
2021 } | |
2022 /* Possibly update the text in the widget. */ | |
2023 if (IMAGE_INSTANCE_TEXT_CHANGED (p) | |
2024 && !NILP (IMAGE_INSTANCE_WIDGET_TEXT (p))) | |
2025 { | |
771 | 2026 Extbyte *lparam = 0; |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2027 lparam = LISP_STRING_TO_TSTR (IMAGE_INSTANCE_WIDGET_TEXT (p)); |
771 | 2028 qxeSendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), |
2029 WM_SETTEXT, 0, (LPARAM) lparam); | |
442 | 2030 } |
454 | 2031 /* Set active state. */ |
2032 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p)) | |
2033 { | |
2034 Lisp_Object item = IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (p); | |
771 | 2035 LONG style = qxeGetWindowLong |
454 | 2036 (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), |
2037 GWL_STYLE); | |
2038 | |
2039 if (CONSP (item)) | |
2040 item = XCAR (item); | |
2041 | |
1913 | 2042 if (gui_item_active_p (item)) |
771 | 2043 qxeSetWindowLong (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), |
2044 GWL_STYLE, style & ~WS_DISABLED); | |
454 | 2045 else |
771 | 2046 qxeSetWindowLong (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), |
2047 GWL_STYLE, style | WS_DISABLED); | |
454 | 2048 } |
428 | 2049 } |
2050 | |
771 | 2051 #ifdef HAVE_WIDGETS |
2052 | |
863 | 2053 /* Account for some of the limitations with widget images. */ |
2054 static int | |
2055 mswindows_widget_border_width (void) | |
2056 { | |
2057 return DEFAULT_WIDGET_BORDER_WIDTH; | |
2058 } | |
2059 | |
442 | 2060 /* register widgets into our hashtable so that we can cope with the |
428 | 2061 callbacks. The hashtable is weak so deregistration is handled |
2062 automatically */ | |
2063 static int | |
442 | 2064 mswindows_register_gui_item (Lisp_Object image_instance, |
2065 Lisp_Object gui, Lisp_Object domain) | |
428 | 2066 { |
442 | 2067 Lisp_Object frame = DOMAIN_FRAME (domain); |
771 | 2068 struct frame *f = XFRAME (frame); |
442 | 2069 int id = gui_item_id_hash (FRAME_MSWINDOWS_WIDGET_HASH_TABLE2 (f), |
428 | 2070 gui, |
2071 WIDGET_GLYPH_SLOT); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2072 Fputhash (make_fixnum (id), image_instance, |
442 | 2073 FRAME_MSWINDOWS_WIDGET_HASH_TABLE1 (f)); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2074 Fputhash (make_fixnum (id), XGUI_ITEM (gui)->callback, |
442 | 2075 FRAME_MSWINDOWS_WIDGET_HASH_TABLE2 (f)); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2076 Fputhash (make_fixnum (id), XGUI_ITEM (gui)->callback_ex, |
442 | 2077 FRAME_MSWINDOWS_WIDGET_HASH_TABLE3 (f)); |
428 | 2078 return id; |
2079 } | |
2080 | |
2081 static int | |
2082 mswindows_register_widget_instance (Lisp_Object instance, Lisp_Object domain) | |
2083 { | |
442 | 2084 return mswindows_register_gui_item (instance, |
2085 XIMAGE_INSTANCE_WIDGET_ITEM (instance), | |
428 | 2086 domain); |
2087 } | |
2088 | |
2089 static void | |
502 | 2090 mswindows_subwindow_instantiate (Lisp_Object image_instance, |
2286 | 2091 Lisp_Object UNUSED (instantiator), |
2092 Lisp_Object UNUSED (pointer_fg), | |
2093 Lisp_Object UNUSED (pointer_bg), | |
2094 int UNUSED (dest_mask), Lisp_Object domain) | |
428 | 2095 { |
440 | 2096 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
428 | 2097 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
442 | 2098 Lisp_Object frame = DOMAIN_FRAME (domain); |
428 | 2099 HWND wnd; |
2100 | |
442 | 2101 CHECK_MSWINDOWS_DEVICE (device); |
428 | 2102 |
2103 /* have to set the type this late in case there is no device | |
2104 instantiation for a widget */ | |
2105 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW; | |
2106 /* Allocate space for the clip window */ | |
2107 ii->data = xnew_and_zero (struct mswindows_subwindow_data); | |
2108 | |
2109 if ((IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii) | |
771 | 2110 = qxeCreateWindowEx ( |
2111 0, /* EX flags */ | |
2112 XETEXT (XEMACS_CONTROL_CLASS), | |
2113 0, /* text */ | |
2114 WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD, | |
2115 0, /* starting x position */ | |
2116 0, /* starting y position */ | |
2117 IMAGE_INSTANCE_WIDGET_WIDTH (ii), | |
2118 IMAGE_INSTANCE_WIDGET_HEIGHT (ii), | |
2119 /* parent window */ | |
2120 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), | |
2121 NULL, /* No menu */ | |
2122 NULL, /* must be null for this class */ | |
2123 NULL)) == NULL) | |
563 | 2124 gui_error ("window creation failed with code", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2125 make_fixnum (GetLastError())); |
428 | 2126 |
771 | 2127 wnd = qxeCreateWindow (XETEXT ("STATIC"), XETEXT (""), |
2128 WS_CHILD, | |
2129 0, /* starting x position */ | |
2130 0, /* starting y position */ | |
2131 IMAGE_INSTANCE_WIDGET_WIDTH (ii), | |
2132 IMAGE_INSTANCE_WIDGET_HEIGHT (ii), | |
2133 IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii), | |
2134 0, | |
2135 (HINSTANCE) | |
2136 qxeGetWindowLong | |
2137 (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), | |
2138 GWL_HINSTANCE), | |
2139 NULL); | |
2140 | |
5013 | 2141 qxeSetWindowLong (wnd, GWL_USERDATA, (LONG)STORE_LISP_IN_VOID(image_instance)); |
428 | 2142 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd; |
2143 } | |
2144 | |
771 | 2145 #endif /* HAVE_WIDGETS */ |
2146 | |
428 | 2147 static int |
440 | 2148 mswindows_image_instance_equal (Lisp_Image_Instance *p1, |
2286 | 2149 Lisp_Image_Instance *p2, int UNUSED (depth)) |
428 | 2150 { |
2151 switch (IMAGE_INSTANCE_TYPE (p1)) | |
2152 { | |
2153 case IMAGE_MONO_PIXMAP: | |
2154 case IMAGE_COLOR_PIXMAP: | |
2155 case IMAGE_POINTER: | |
434 | 2156 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1) |
428 | 2157 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2)) |
2158 return 0; | |
2159 break; | |
434 | 2160 |
428 | 2161 default: |
2162 break; | |
2163 } | |
2164 | |
2165 return 1; | |
2166 } | |
2167 | |
665 | 2168 static Hashcode |
5192
635f4b506855
Call internal_hash() with its new arg, Win32-specific code, fixing build
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2169 mswindows_image_instance_hash (Lisp_Image_Instance *p, int UNUSED (depth)) |
428 | 2170 { |
2171 switch (IMAGE_INSTANCE_TYPE (p)) | |
2172 { | |
2173 case IMAGE_MONO_PIXMAP: | |
2174 case IMAGE_COLOR_PIXMAP: | |
2175 case IMAGE_POINTER: | |
665 | 2176 return (Hashcode) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p); |
434 | 2177 |
428 | 2178 default: |
2179 return 0; | |
2180 } | |
2181 } | |
2182 | |
2183 /* Set all the slots in an image instance structure to reasonable | |
2184 default values. This is used somewhere within an instantiate | |
2185 method. It is assumed that the device slot within the image | |
2186 instance is already set -- this is the case when instantiate | |
2187 methods are called. */ | |
2188 | |
2189 static void | |
440 | 2190 mswindows_initialize_dibitmap_image_instance (Lisp_Image_Instance *ii, |
428 | 2191 int slices, |
2192 enum image_instance_type type) | |
2193 { | |
2194 ii->data = xnew_and_zero (struct mswindows_image_instance_data); | |
2195 IMAGE_INSTANCE_TYPE (ii) = type; | |
2196 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil; | |
2197 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil; | |
2198 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil; | |
2199 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil; | |
2200 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil; | |
2201 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil; | |
2202 IMAGE_INSTANCE_PIXMAP_MAXSLICE (ii) = slices; | |
434 | 2203 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICES (ii) = |
428 | 2204 xnew_array_and_zero (HBITMAP, slices); |
2205 } | |
2206 | |
2207 | |
2208 #ifdef HAVE_WIDGETS | |
2209 | |
2210 /************************************************************************/ | |
771 | 2211 /* widgets */ |
428 | 2212 /************************************************************************/ |
2213 static void | |
502 | 2214 mswindows_widget_instantiate (Lisp_Object image_instance, |
2286 | 2215 Lisp_Object UNUSED (instantiator), |
2216 Lisp_Object UNUSED (pointer_fg), | |
2217 Lisp_Object UNUSED (pointer_bg), | |
2218 int UNUSED (dest_mask), Lisp_Object domain, | |
1204 | 2219 const CIbyte *class_, int flags, int exflags) |
428 | 2220 { |
2221 /* this function can call lisp */ | |
440 | 2222 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
428 | 2223 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), style; |
442 | 2224 Lisp_Object frame = DOMAIN_FRAME (domain); |
771 | 2225 Extbyte *nm = 0; |
2226 Extbyte *classext; | |
428 | 2227 HWND wnd; |
2228 int id = 0xffff; | |
2229 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii); | |
771 | 2230 Lisp_Gui_Item *pgui = XGUI_ITEM (gui); |
428 | 2231 |
442 | 2232 CHECK_MSWINDOWS_DEVICE (device); |
428 | 2233 |
1913 | 2234 if (!gui_item_active_p (gui)) |
428 | 2235 flags |= WS_DISABLED; |
2236 | |
2237 style = pgui->style; | |
2238 | |
442 | 2239 if (!NILP (pgui->callback) || !NILP (pgui->callback_ex)) |
428 | 2240 { |
2241 id = mswindows_register_widget_instance (image_instance, domain); | |
2242 } | |
438 | 2243 |
428 | 2244 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii))) |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2245 nm = LISP_STRING_TO_TSTR (IMAGE_INSTANCE_WIDGET_TEXT (ii)); |
428 | 2246 |
2247 /* allocate space for the clip window and then allocate the clip window */ | |
2248 ii->data = xnew_and_zero (struct mswindows_subwindow_data); | |
2249 | |
2250 if ((IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii) | |
771 | 2251 = qxeCreateWindowEx (WS_EX_CONTROLPARENT, /* EX flags */ |
2252 XETEXT (XEMACS_CONTROL_CLASS), | |
2253 0, /* text */ | |
2254 WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD, | |
428 | 2255 0, /* starting x position */ |
2256 0, /* starting y position */ | |
2257 IMAGE_INSTANCE_WIDGET_WIDTH (ii), | |
2258 IMAGE_INSTANCE_WIDGET_HEIGHT (ii), | |
2259 /* parent window */ | |
771 | 2260 DOMAIN_MSWINDOWS_HANDLE (domain), |
428 | 2261 (HMENU)id, /* No menu */ |
771 | 2262 NULL, /* must be null for this class */ |
428 | 2263 NULL)) == NULL) |
563 | 2264 gui_error ("window creation failed with code", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2265 make_fixnum (GetLastError())); |
428 | 2266 |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2267 classext = ITEXT_TO_TSTR (class_); |
771 | 2268 |
2269 if ((wnd = qxeCreateWindowEx (exflags /* | WS_EX_NOPARENTNOTIFY*/, | |
2270 classext, | |
2271 nm, | |
2272 flags | WS_CHILD | WS_VISIBLE, | |
2273 0, /* starting x position */ | |
2274 0, /* starting y position */ | |
2275 IMAGE_INSTANCE_WIDGET_WIDTH (ii), | |
2276 IMAGE_INSTANCE_WIDGET_HEIGHT (ii), | |
2277 /* parent window */ | |
2278 IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (ii), | |
2279 (HMENU)id, /* No menu */ | |
2280 (HINSTANCE) | |
2281 qxeGetWindowLong | |
2282 (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), | |
2283 GWL_HINSTANCE), | |
2284 NULL)) == NULL) | |
2285 gui_error ("window creation failed with code", | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2286 make_fixnum (GetLastError())); |
771 | 2287 |
428 | 2288 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd; |
5013 | 2289 qxeSetWindowLong (wnd, GWL_USERDATA, (LONG)STORE_LISP_IN_VOID(image_instance)); |
428 | 2290 /* set the widget font from the widget face */ |
442 | 2291 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii))) |
771 | 2292 qxeSendMessage (wnd, WM_SETFONT, |
2293 (WPARAM) mswindows_widget_hfont | |
2294 (IMAGE_INSTANCE_WIDGET_FACE (ii), domain, | |
2295 IMAGE_INSTANCE_WIDGET_TEXT (ii)), | |
2296 MAKELPARAM (TRUE, 0)); | |
442 | 2297 } |
2298 | |
2299 /* Instantiate a native layout widget. */ | |
2300 static void | |
2301 mswindows_native_layout_instantiate (Lisp_Object image_instance, | |
2302 Lisp_Object instantiator, | |
502 | 2303 Lisp_Object pointer_fg, |
2304 Lisp_Object pointer_bg, | |
442 | 2305 int dest_mask, Lisp_Object domain) |
2306 { | |
2307 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | |
2308 | |
2309 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, | |
2310 pointer_bg, dest_mask, domain, "STATIC", | |
2311 /* Approximation to styles available with | |
2312 an XEmacs layout. */ | |
2313 (EQ (IMAGE_INSTANCE_LAYOUT_BORDER (ii), | |
2314 Qetched_in) || | |
2315 EQ (IMAGE_INSTANCE_LAYOUT_BORDER (ii), | |
2316 Qetched_out) || | |
2317 GLYPHP (IMAGE_INSTANCE_LAYOUT_BORDER (ii)) | |
2318 ? SS_ETCHEDFRAME : SS_SUNKEN) | DS_CONTROL, | |
2319 0); | |
428 | 2320 } |
2321 | |
2322 /* Instantiate a button widget. Unfortunately instantiated widgets are | |
2323 particular to a frame since they need to have a parent. It's not | |
2324 like images where you just select the image into the context you | |
438 | 2325 want to display it in and BitBlt it. So image instances can have a |
428 | 2326 many-to-one relationship with things you see, whereas widgets can |
2327 only be one-to-one (i.e. per frame) */ | |
2328 static void | |
502 | 2329 mswindows_button_instantiate (Lisp_Object image_instance, |
2330 Lisp_Object instantiator, | |
428 | 2331 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
2332 int dest_mask, Lisp_Object domain) | |
2333 { | |
442 | 2334 /* This function can call lisp */ |
440 | 2335 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
428 | 2336 HWND wnd; |
444 | 2337 int flags = WS_TABSTOP | BS_NOTIFY; |
2338 /* BS_NOTIFY #### is needed to get exotic feedback only. Since we | |
2339 seem to want nothing beyond BN_CLICK, the style is perhaps not | |
2340 necessary -- kkm */ | |
428 | 2341 Lisp_Object style; |
2342 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii); | |
771 | 2343 Lisp_Gui_Item *pgui = XGUI_ITEM (gui); |
428 | 2344 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image); |
2345 | |
2346 if (!NILP (glyph)) | |
2347 { | |
2348 if (!IMAGE_INSTANCEP (glyph)) | |
2349 glyph = glyph_image_instance (glyph, domain, ERROR_ME, 1); | |
2350 | |
2351 if (IMAGE_INSTANCEP (glyph)) | |
434 | 2352 flags |= XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ? |
428 | 2353 BS_BITMAP : BS_ICON; |
2354 } | |
2355 | |
2356 style = pgui->style; | |
2357 | |
438 | 2358 /* #### consider using the default face for radio and toggle |
2359 buttons. */ | |
428 | 2360 if (EQ (style, Qradio)) |
2361 { | |
2362 flags |= BS_RADIOBUTTON; | |
2363 } | |
2364 else if (EQ (style, Qtoggle)) | |
2365 { | |
2366 flags |= BS_AUTOCHECKBOX; | |
2367 } | |
2368 else | |
438 | 2369 { |
2370 flags |= BS_DEFPUSHBUTTON; | |
2371 } | |
428 | 2372 |
2373 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, | |
771 | 2374 pointer_bg, dest_mask, domain, |
2375 "BUTTON", flags, 0); | |
428 | 2376 |
2377 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); | |
2378 /* set the checked state */ | |
1913 | 2379 if (gui_item_selected_p (gui)) |
771 | 2380 qxeSendMessage (wnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0); |
428 | 2381 else |
771 | 2382 qxeSendMessage (wnd, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0); |
428 | 2383 /* add the image if one was given */ |
440 | 2384 if (!NILP (glyph) && IMAGE_INSTANCEP (glyph) |
2385 && | |
2386 IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (glyph))) | |
428 | 2387 { |
771 | 2388 qxeSendMessage (wnd, BM_SETIMAGE, |
2389 (WPARAM) (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ? | |
2390 IMAGE_BITMAP : IMAGE_ICON), | |
2391 (XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) ? | |
2392 (LPARAM) XIMAGE_INSTANCE_MSWINDOWS_BITMAP (glyph) : | |
2393 (LPARAM) XIMAGE_INSTANCE_MSWINDOWS_ICON (glyph))); | |
428 | 2394 } |
2395 } | |
2396 | |
442 | 2397 /* Update the state of a button. */ |
2398 static void | |
2399 mswindows_button_redisplay (Lisp_Object image_instance) | |
2400 { | |
2401 /* This function can GC if IN_REDISPLAY is false. */ | |
2402 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | |
2403 | |
2404 /* buttons checked or otherwise */ | |
1913 | 2405 if (gui_item_selected_p (IMAGE_INSTANCE_WIDGET_ITEM (ii))) |
771 | 2406 qxeSendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii), |
2407 BM_SETCHECK, (WPARAM)BST_CHECKED, 0); | |
442 | 2408 else |
771 | 2409 qxeSendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii), |
2410 BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0); | |
442 | 2411 } |
2412 | |
428 | 2413 /* instantiate an edit control */ |
2414 static void | |
502 | 2415 mswindows_edit_field_instantiate (Lisp_Object image_instance, |
2416 Lisp_Object instantiator, | |
2417 Lisp_Object pointer_fg, | |
2418 Lisp_Object pointer_bg, | |
2419 int dest_mask, Lisp_Object domain) | |
428 | 2420 { |
2421 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, | |
434 | 2422 pointer_bg, dest_mask, domain, "EDIT", |
428 | 2423 ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP |
438 | 2424 | WS_BORDER, WS_EX_CLIENTEDGE); |
428 | 2425 } |
2426 | |
2427 /* instantiate a progress gauge */ | |
2428 static void | |
502 | 2429 mswindows_progress_gauge_instantiate (Lisp_Object image_instance, |
2430 Lisp_Object instantiator, | |
2431 Lisp_Object pointer_fg, | |
2432 Lisp_Object pointer_bg, | |
2433 int dest_mask, Lisp_Object domain) | |
428 | 2434 { |
2435 HWND wnd; | |
440 | 2436 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
442 | 2437 Lisp_Object val; |
428 | 2438 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, |
434 | 2439 pointer_bg, dest_mask, domain, PROGRESS_CLASS, |
438 | 2440 WS_BORDER | PBS_SMOOTH, WS_EX_CLIENTEDGE); |
428 | 2441 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); |
2442 /* set the colors */ | |
502 | 2443 #if 0 /* #### fix this */ |
771 | 2444 qxeSendMessage (wnd, PBM_SETBKCOLOR, 0, |
2445 (LPARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR | |
2446 (XCOLOR_INSTANCE | |
2447 (FACE_BACKGROUND | |
2448 (XIMAGE_INSTANCE_WIDGET_FACE (ii), | |
2449 XIMAGE_INSTANCE_FRAME (ii)))))); | |
2450 qxeSendMessage (wnd, PBM_SETBARCOLOR, 0, | |
2451 (LPARAM) (COLOR_INSTANCE_MSWINDOWS_COLOR | |
2452 (XCOLOR_INSTANCE | |
2453 (FACE_FOREGROUND | |
2454 (XIMAGE_INSTANCE_WIDGET_FACE (ii), | |
2455 XIMAGE_INSTANCE_FRAME (ii)))))); | |
428 | 2456 #endif |
442 | 2457 val = XGUI_ITEM (IMAGE_INSTANCE_WIDGET_ITEMS (ii))->value; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2458 CHECK_FIXNUM (val); |
771 | 2459 qxeSendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii), |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2460 PBM_SETPOS, (WPARAM)XFIXNUM (val), 0); |
428 | 2461 } |
2462 | |
2463 /* instantiate a tree view widget */ | |
2464 static HTREEITEM add_tree_item (Lisp_Object image_instance, | |
2465 HWND wnd, HTREEITEM parent, Lisp_Object item, | |
2466 int children, Lisp_Object domain) | |
2467 { | |
2468 HTREEITEM ret; | |
771 | 2469 TV_INSERTSTRUCTW tvitem; |
428 | 2470 |
2471 tvitem.hParent = parent; | |
2472 tvitem.hInsertAfter = TVI_LAST; | |
2473 tvitem.item.mask = TVIF_TEXT | TVIF_CHILDREN; | |
2474 tvitem.item.cChildren = children; | |
771 | 2475 |
428 | 2476 if (GUI_ITEMP (item)) |
2477 { | |
771 | 2478 tvitem.item.lParam = |
2479 mswindows_register_gui_item (image_instance, item, domain); | |
428 | 2480 tvitem.item.mask |= TVIF_PARAM; |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2481 tvitem.item.pszText = |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2482 (LPWSTR) LISP_STRING_TO_TSTR (XGUI_ITEM (item)->name); |
428 | 2483 } |
2484 else | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2485 tvitem.item.pszText = (LPWSTR) LISP_STRING_TO_TSTR (item); |
771 | 2486 |
2421 | 2487 tvitem.item.cchTextMax = qxetcslen ((Extbyte *) tvitem.item.pszText); |
771 | 2488 |
2489 if ((ret = (HTREEITEM) qxeSendMessage (wnd, TVM_INSERTITEM, | |
2490 0, (LPARAM) &tvitem)) == 0) | |
563 | 2491 gui_error ("error adding tree view entry", item); |
428 | 2492 |
2493 return ret; | |
2494 } | |
2495 | |
2496 static void add_tree_item_list (Lisp_Object image_instance, | |
2497 HWND wnd, HTREEITEM parent, Lisp_Object list, | |
2498 Lisp_Object domain) | |
2499 { | |
2500 Lisp_Object rest; | |
2501 | |
2502 /* get the first item */ | |
2503 parent = add_tree_item (image_instance, wnd, parent, XCAR (list), TRUE, domain); | |
2504 /* recursively add items to the tree view */ | |
2505 LIST_LOOP (rest, XCDR (list)) | |
2506 { | |
2507 if (LISTP (XCAR (rest))) | |
2508 add_tree_item_list (image_instance, wnd, parent, XCAR (rest), domain); | |
2509 else | |
2510 add_tree_item (image_instance, wnd, parent, XCAR (rest), FALSE, domain); | |
2511 } | |
2512 } | |
2513 | |
2514 static void | |
502 | 2515 mswindows_tree_view_instantiate (Lisp_Object image_instance, |
2516 Lisp_Object instantiator, | |
2517 Lisp_Object pointer_fg, | |
2518 Lisp_Object pointer_bg, | |
2519 int dest_mask, Lisp_Object domain) | |
428 | 2520 { |
2521 Lisp_Object rest; | |
2522 HWND wnd; | |
2523 HTREEITEM parent; | |
440 | 2524 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
428 | 2525 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, |
434 | 2526 pointer_bg, dest_mask, domain, WC_TREEVIEW, |
428 | 2527 WS_TABSTOP | WS_BORDER | PBS_SMOOTH |
2528 | TVS_HASLINES | TVS_HASBUTTONS, | |
438 | 2529 WS_EX_CLIENTEDGE); |
428 | 2530 |
2531 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); | |
434 | 2532 |
428 | 2533 /* define a root */ |
434 | 2534 parent = add_tree_item (image_instance, wnd, NULL, |
2535 XCAR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)), | |
428 | 2536 TRUE, domain); |
434 | 2537 |
428 | 2538 /* recursively add items to the tree view */ |
2539 /* add items to the tab */ | |
2540 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii))) | |
2541 { | |
2542 if (LISTP (XCAR (rest))) | |
2543 add_tree_item_list (image_instance, wnd, parent, XCAR (rest), domain); | |
2544 else | |
2545 add_tree_item (image_instance, wnd, parent, XCAR (rest), FALSE, domain); | |
2546 } | |
2547 } | |
2548 | |
442 | 2549 /* Set the properties of a tree view. */ |
2550 static void | |
2551 mswindows_tree_view_redisplay (Lisp_Object image_instance) | |
2552 { | |
2553 /* This function can GC if IN_REDISPLAY is false. */ | |
2554 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | |
2555 | |
2556 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii)) | |
2557 { | |
2558 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); | |
2559 Lisp_Object rest; | |
2560 HTREEITEM parent; | |
2561 /* Delete previous items. */ | |
771 | 2562 qxeSendMessage (wnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT); |
442 | 2563 /* define a root */ |
2564 parent = add_tree_item (image_instance, wnd, NULL, | |
2565 XCAR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)), | |
2566 TRUE, IMAGE_INSTANCE_DOMAIN (ii)); | |
2567 | |
2568 /* recursively add items to the tree view */ | |
2569 /* add items to the tab */ | |
2570 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii))) | |
2571 { | |
2572 if (LISTP (XCAR (rest))) | |
2573 add_tree_item_list (image_instance, wnd, parent, XCAR (rest), | |
2574 IMAGE_INSTANCE_DOMAIN (ii)); | |
2575 else | |
2576 add_tree_item (image_instance, wnd, parent, XCAR (rest), FALSE, | |
2577 IMAGE_INSTANCE_DOMAIN (ii)); | |
2578 } | |
2579 } | |
2580 } | |
2581 | |
428 | 2582 /* instantiate a tab control */ |
442 | 2583 static int |
2584 add_tab_item (Lisp_Object image_instance, | |
2585 HWND wnd, Lisp_Object item, | |
2586 Lisp_Object domain, int i) | |
428 | 2587 { |
771 | 2588 TC_ITEMW tcitem; |
442 | 2589 int ret = 0; |
428 | 2590 |
771 | 2591 tcitem.mask = TCIF_TEXT; |
434 | 2592 |
428 | 2593 if (GUI_ITEMP (item)) |
2594 { | |
771 | 2595 tcitem.lParam = |
2596 mswindows_register_gui_item (image_instance, item, domain); | |
2597 tcitem.mask |= TCIF_PARAM; | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2598 tcitem.pszText = (XELPTSTR) LISP_STRING_TO_TSTR (XGUI_ITEM (item)->name); |
428 | 2599 } |
2600 else | |
2601 { | |
2602 CHECK_STRING (item); | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2603 tcitem.pszText = (XELPTSTR) LISP_STRING_TO_TSTR (item); |
428 | 2604 } |
2605 | |
2421 | 2606 tcitem.cchTextMax = qxetcslen ((Extbyte *) tcitem.pszText); |
771 | 2607 |
2608 if ((ret = qxeSendMessage (wnd, TCM_INSERTITEM, i, (LPARAM) &tcitem)) < 0) | |
563 | 2609 gui_error ("error adding tab entry", item); |
428 | 2610 |
2611 return ret; | |
2612 } | |
2613 | |
2614 static void | |
502 | 2615 mswindows_tab_control_instantiate (Lisp_Object image_instance, |
2616 Lisp_Object instantiator, | |
2617 Lisp_Object pointer_fg, | |
2618 Lisp_Object pointer_bg, | |
2619 int dest_mask, Lisp_Object domain) | |
428 | 2620 { |
442 | 2621 /* This function can call lisp */ |
428 | 2622 Lisp_Object rest; |
2623 HWND wnd; | |
442 | 2624 int i = 0, selected = 0; |
440 | 2625 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
438 | 2626 Lisp_Object orient = find_keyword_in_vector (instantiator, Q_orientation); |
2627 unsigned int flags = WS_TABSTOP; | |
2628 | |
2629 if (EQ (orient, Qleft) || EQ (orient, Qright)) | |
2630 { | |
2631 flags |= TCS_VERTICAL | TCS_MULTILINE; | |
2632 } | |
2633 if (EQ (orient, Qright) || EQ (orient, Qbottom)) | |
2634 { | |
2635 flags |= TCS_BOTTOM; | |
2636 } | |
2637 | |
428 | 2638 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, |
434 | 2639 pointer_bg, dest_mask, domain, WC_TABCONTROL, |
428 | 2640 /* borders don't suit tabs so well */ |
438 | 2641 flags, 0); |
428 | 2642 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); |
2643 /* add items to the tab */ | |
2644 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii))) | |
2645 { | |
442 | 2646 int idx = add_tab_item (image_instance, wnd, XCAR (rest), domain, i); |
2647 assert (idx == i); | |
1913 | 2648 if (gui_item_selected_p (XCAR (rest))) |
442 | 2649 selected = i; |
438 | 2650 i++; |
428 | 2651 } |
771 | 2652 qxeSendMessage (wnd, TCM_SETCURSEL, selected, 0); |
428 | 2653 } |
2654 | |
442 | 2655 /* Set the properties of a tab control. */ |
2656 static void | |
2657 mswindows_tab_control_redisplay (Lisp_Object image_instance) | |
428 | 2658 { |
442 | 2659 /* This function can GC if IN_REDISPLAY is false. */ |
440 | 2660 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
442 | 2661 #ifdef DEBUG_WIDGET_OUTPUT |
1318 | 2662 stderr_out ("tab control %p redisplayed\n", |
2663 IMAGE_INSTANCE_SUBWINDOW_ID (ii)); | |
442 | 2664 #endif |
2665 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) | |
2666 || | |
2667 IMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (ii)) | |
428 | 2668 { |
2669 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); | |
454 | 2670 int i = 0, selected_idx = 0; |
428 | 2671 Lisp_Object rest; |
442 | 2672 |
2673 assert (!NILP (IMAGE_INSTANCE_WIDGET_ITEMS (ii))); | |
2674 | |
2675 /* If only the order has changed then simply select the first | |
2676 one. This stops horrendous rebuilding of the tabs each time | |
2677 you click on one. */ | |
2678 if (tab_control_order_only_changed (image_instance)) | |
428 | 2679 { |
442 | 2680 Lisp_Object selected = |
2681 gui_item_list_find_selected | |
2682 (NILP (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)) ? | |
2683 XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)) : | |
2684 XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii))); | |
2685 | |
2686 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii))) | |
2687 { | |
1913 | 2688 if (gui_item_equal_sans_selected (XCAR (rest), selected, 0)) |
442 | 2689 { |
1318 | 2690 Lisp_Object old_selected = |
2691 gui_item_list_find_selected | |
442 | 2692 (XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii))); |
2693 | |
2694 /* Pick up the new selected item. */ | |
2695 XGUI_ITEM (old_selected)->selected = | |
2696 XGUI_ITEM (XCAR (rest))->selected; | |
2697 XGUI_ITEM (XCAR (rest))->selected = | |
2698 XGUI_ITEM (selected)->selected; | |
2699 /* We're not actually changing the items. */ | |
2700 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) = 0; | |
2701 IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii) = Qnil; | |
2702 | |
771 | 2703 qxeSendMessage (wnd, TCM_SETCURSEL, i, 0); |
442 | 2704 #ifdef DEBUG_WIDGET_OUTPUT |
2705 stderr_out ("tab control %p selected item %d\n", | |
1318 | 2706 IMAGE_INSTANCE_SUBWINDOW_ID (ii), i); |
442 | 2707 #endif |
2708 break; | |
2709 } | |
2710 i++; | |
2711 } | |
428 | 2712 } |
442 | 2713 else |
2714 { | |
2715 /* delete the pre-existing items */ | |
771 | 2716 qxeSendMessage (wnd, TCM_DELETEALLITEMS, 0, 0); |
442 | 2717 |
2718 /* add items to the tab */ | |
2719 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii))) | |
2720 { | |
2721 add_tab_item (image_instance, wnd, XCAR (rest), | |
2722 IMAGE_INSTANCE_FRAME (ii), i); | |
1913 | 2723 if (gui_item_selected_p (XCAR (rest))) |
454 | 2724 selected_idx = i; |
442 | 2725 i++; |
2726 } | |
771 | 2727 qxeSendMessage (wnd, TCM_SETCURSEL, selected_idx, 0); |
442 | 2728 } |
428 | 2729 } |
2730 } | |
2731 | |
2732 /* instantiate a static control possible for putting other things in */ | |
2733 static void | |
502 | 2734 mswindows_label_instantiate (Lisp_Object image_instance, |
2735 Lisp_Object instantiator, | |
428 | 2736 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
2737 int dest_mask, Lisp_Object domain) | |
2738 { | |
2739 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, | |
771 | 2740 pointer_bg, dest_mask, domain, |
2741 "STATIC", 0, WS_EX_STATICEDGE); | |
428 | 2742 } |
2743 | |
2744 /* instantiate a scrollbar control */ | |
2745 static void | |
502 | 2746 mswindows_scrollbar_instantiate (Lisp_Object image_instance, |
2747 Lisp_Object instantiator, | |
2748 Lisp_Object pointer_fg, | |
2749 Lisp_Object pointer_bg, | |
428 | 2750 int dest_mask, Lisp_Object domain) |
2751 { | |
2752 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, | |
771 | 2753 pointer_bg, dest_mask, domain, |
2754 "SCROLLBAR", WS_TABSTOP, WS_EX_CLIENTEDGE); | |
428 | 2755 } |
2756 | |
2757 /* instantiate a combo control */ | |
2758 static void | |
502 | 2759 mswindows_combo_box_instantiate (Lisp_Object image_instance, |
2760 Lisp_Object instantiator, | |
2761 Lisp_Object pointer_fg, | |
2762 Lisp_Object pointer_bg, | |
2763 int dest_mask, Lisp_Object domain) | |
428 | 2764 { |
440 | 2765 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
442 | 2766 HWND wnd; |
428 | 2767 Lisp_Object rest; |
442 | 2768 Lisp_Object items = find_keyword_in_vector (instantiator, Q_items); |
438 | 2769 int len, height; |
428 | 2770 |
2771 /* Maybe ought to generalise this more but it may be very windows | |
2772 specific. In windows the window height of a combo box is the | |
2773 height when the combo box is open. Thus we need to set the height | |
2774 before creating the window and then reset it to a single line | |
2775 after the window is created so that redisplay does the right | |
2776 thing. */ | |
438 | 2777 widget_instantiate (image_instance, instantiator, pointer_fg, |
2778 pointer_bg, dest_mask, domain); | |
2779 | |
2780 /* We now have everything right apart from the height. */ | |
5047
07dcc7000bbf
put width before height consistently, fix a real bug found in the process
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2781 default_face_font_info (domain, 0, 0, 0, &height, 0); |
442 | 2782 GET_LIST_LENGTH (items, len); |
438 | 2783 |
863 | 2784 height = (height + DEFAULT_WIDGET_BORDER_WIDTH * 2 ) * len; |
438 | 2785 IMAGE_INSTANCE_HEIGHT (ii) = height; |
440 | 2786 |
438 | 2787 /* Now create the widget. */ |
428 | 2788 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg, |
771 | 2789 pointer_bg, dest_mask, domain, |
2790 "COMBOBOX", | |
428 | 2791 WS_BORDER | WS_TABSTOP | CBS_DROPDOWN |
434 | 2792 | CBS_AUTOHSCROLL |
428 | 2793 | CBS_HASSTRINGS | WS_VSCROLL, |
438 | 2794 WS_EX_CLIENTEDGE); |
2795 /* Reset the height. layout will probably do this safely, but better make sure. */ | |
440 | 2796 image_instance_layout (image_instance, |
438 | 2797 IMAGE_UNSPECIFIED_GEOMETRY, |
2798 IMAGE_UNSPECIFIED_GEOMETRY, | |
442 | 2799 IMAGE_UNCHANGED_GEOMETRY, |
2800 IMAGE_UNCHANGED_GEOMETRY, | |
438 | 2801 domain); |
2802 | |
428 | 2803 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); |
2804 /* add items to the combo box */ | |
771 | 2805 qxeSendMessage (wnd, CB_RESETCONTENT, 0, 0); |
442 | 2806 LIST_LOOP (rest, items) |
428 | 2807 { |
771 | 2808 Extbyte *lparam; |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2809 lparam = LISP_STRING_TO_TSTR (XCAR (rest)); |
771 | 2810 if (qxeSendMessage (wnd, CB_ADDSTRING, 0, (LPARAM)lparam) == CB_ERR) |
563 | 2811 gui_error ("error adding combo entries", instantiator); |
428 | 2812 } |
2813 } | |
2814 | |
2815 /* get properties of a control */ | |
2816 static Lisp_Object | |
2817 mswindows_widget_property (Lisp_Object image_instance, Lisp_Object prop) | |
2818 { | |
440 | 2819 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
442 | 2820 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); |
428 | 2821 /* get the text from a control */ |
2822 if (EQ (prop, Q_text)) | |
2823 { | |
771 | 2824 Charcount tchar_len = qxeSendMessage (wnd, WM_GETTEXTLENGTH, 0, 0); |
2367 | 2825 Extbyte *buf = alloca_extbytes (XETCHAR_SIZE * (tchar_len + 1)); |
771 | 2826 |
2827 qxeSendMessage (wnd, WM_GETTEXT, (WPARAM)tchar_len + 1, (LPARAM) buf); | |
2828 return build_tstr_string (buf); | |
428 | 2829 } |
2830 return Qunbound; | |
2831 } | |
2832 | |
2833 /* get properties of a button */ | |
2834 static Lisp_Object | |
2835 mswindows_button_property (Lisp_Object image_instance, Lisp_Object prop) | |
2836 { | |
440 | 2837 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
442 | 2838 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); |
428 | 2839 /* check the state of a button */ |
2840 if (EQ (prop, Q_selected)) | |
2841 { | |
771 | 2842 if (qxeSendMessage (wnd, BM_GETSTATE, 0, 0) & BST_CHECKED) |
428 | 2843 return Qt; |
2844 else | |
2845 return Qnil; | |
2846 } | |
2847 return Qunbound; | |
2848 } | |
2849 | |
2850 /* get properties of a combo box */ | |
2851 static Lisp_Object | |
2852 mswindows_combo_box_property (Lisp_Object image_instance, Lisp_Object prop) | |
2853 { | |
440 | 2854 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
442 | 2855 HWND wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii); |
428 | 2856 /* get the text from a control */ |
2857 if (EQ (prop, Q_text)) | |
2858 { | |
771 | 2859 long item = qxeSendMessage (wnd, CB_GETCURSEL, 0, 0); |
2860 Charcount tchar_len = qxeSendMessage (wnd, CB_GETLBTEXTLEN, | |
2861 (WPARAM)item, 0); | |
2367 | 2862 Extbyte *buf = alloca_extbytes (XETCHAR_SIZE * (tchar_len + 1)); |
771 | 2863 qxeSendMessage (wnd, CB_GETLBTEXT, (WPARAM)item, (LPARAM) buf); |
2864 return build_tstr_string (buf); | |
428 | 2865 } |
2866 return Qunbound; | |
2867 } | |
2868 | |
442 | 2869 /* set the properties of a progress gauge */ |
2870 static void | |
2871 mswindows_progress_gauge_redisplay (Lisp_Object image_instance) | |
428 | 2872 { |
440 | 2873 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
428 | 2874 |
442 | 2875 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii)) |
428 | 2876 { |
442 | 2877 Lisp_Object val; |
2878 val = XGUI_ITEM (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii))->value; | |
2879 #ifdef DEBUG_WIDGET_OUTPUT | |
2880 stderr_out ("progress gauge displayed value on %p updated to %ld\n", | |
2881 WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii), | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2882 XFIXNUM(val)); |
442 | 2883 #endif |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2884 CHECK_FIXNUM (val); |
771 | 2885 qxeSendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii), |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5474
diff
changeset
|
2886 PBM_SETPOS, (WPARAM)XFIXNUM (val), 0); |
428 | 2887 } |
2888 } | |
2889 | |
2890 LRESULT WINAPI | |
438 | 2891 mswindows_control_wnd_proc (HWND hwnd, UINT msg, |
428 | 2892 WPARAM wParam, LPARAM lParam) |
2893 { | |
438 | 2894 switch (msg) |
428 | 2895 { |
2896 case WM_NOTIFY: | |
2897 case WM_COMMAND: | |
2898 case WM_CTLCOLORBTN: | |
2899 case WM_CTLCOLORLISTBOX: | |
2900 case WM_CTLCOLOREDIT: | |
2901 case WM_CTLCOLORSTATIC: | |
2902 case WM_CTLCOLORSCROLLBAR: | |
2903 | |
438 | 2904 return mswindows_wnd_proc (GetParent (hwnd), msg, wParam, lParam); |
428 | 2905 default: |
771 | 2906 return qxeDefWindowProc (hwnd, msg, wParam, lParam); |
2907 } | |
2908 } | |
2909 | |
2910 static void | |
2911 mswindows_widget_query_string_geometry (Lisp_Object string, Lisp_Object face, | |
2912 int *width, int *height, | |
2913 Lisp_Object domain) | |
2914 { | |
2915 if (height) | |
2916 query_string_geometry (string, face, 0, height, 0, domain); | |
2917 | |
2918 if (width) | |
2919 { | |
2920 HDC hdc = FRAME_MSWINDOWS_DC (DOMAIN_XFRAME (domain)); | |
2921 Extbyte *str; | |
2922 Bytecount len; | |
2923 SIZE size; | |
2924 | |
2925 SelectObject (hdc, mswindows_widget_hfont (face, domain, string)); | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2926 LISP_STRING_TO_SIZED_EXTERNAL (string, str, len, Qmswindows_tstr); |
771 | 2927 qxeGetTextExtentPoint32 (hdc, str, len / XETCHAR_SIZE, &size); |
2928 *width = size.cx; | |
428 | 2929 } |
2930 } | |
2931 | |
2932 #endif /* HAVE_WIDGETS */ | |
2933 | |
2934 | |
2935 /************************************************************************/ | |
2936 /* initialization */ | |
2937 /************************************************************************/ | |
2938 | |
2939 void | |
2940 syms_of_glyphs_mswindows (void) | |
2941 { | |
2942 } | |
2943 | |
2944 void | |
2945 console_type_create_glyphs_mswindows (void) | |
2946 { | |
442 | 2947 /* image methods - display */ |
428 | 2948 CONSOLE_HAS_METHOD (mswindows, print_image_instance); |
2949 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance); | |
2950 CONSOLE_HAS_METHOD (mswindows, unmap_subwindow); | |
2951 CONSOLE_HAS_METHOD (mswindows, map_subwindow); | |
442 | 2952 CONSOLE_HAS_METHOD (mswindows, redisplay_subwindow); |
2953 CONSOLE_HAS_METHOD (mswindows, resize_subwindow); | |
2954 CONSOLE_HAS_METHOD (mswindows, redisplay_widget); | |
428 | 2955 CONSOLE_HAS_METHOD (mswindows, image_instance_equal); |
2956 CONSOLE_HAS_METHOD (mswindows, image_instance_hash); | |
2957 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage); | |
2958 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file); | |
771 | 2959 #ifdef HAVE_WIDGETS |
2960 CONSOLE_HAS_METHOD (mswindows, widget_query_string_geometry); | |
863 | 2961 CONSOLE_HAS_METHOD (mswindows, widget_border_width); |
771 | 2962 #endif |
442 | 2963 |
2964 /* image methods - printer */ | |
2965 CONSOLE_INHERITS_METHOD (msprinter, mswindows, print_image_instance); | |
2966 CONSOLE_INHERITS_METHOD (msprinter, mswindows, finalize_image_instance); | |
2967 CONSOLE_INHERITS_METHOD (msprinter, mswindows, image_instance_equal); | |
2968 CONSOLE_INHERITS_METHOD (msprinter, mswindows, image_instance_hash); | |
771 | 2969 CONSOLE_INHERITS_METHOD (msprinter, mswindows, |
2970 init_image_instance_from_eimage); | |
442 | 2971 CONSOLE_INHERITS_METHOD (msprinter, mswindows, locate_pixmap_file); |
428 | 2972 } |
2973 | |
2974 void | |
2975 image_instantiator_format_create_glyphs_mswindows (void) | |
2976 { | |
442 | 2977 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, nothing); |
2978 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, string); | |
2979 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, formatted_string); | |
2980 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, inherit); | |
428 | 2981 /* image-instantiator types */ |
442 | 2982 INITIALIZE_DEVICE_IIFORMAT (mswindows, xbm); |
2983 INITIALIZE_DEVICE_IIFORMAT (msprinter, xbm); | |
2984 IIFORMAT_HAS_DEVMETHOD (mswindows, xbm, instantiate); | |
2985 IIFORMAT_INHERITS_DEVMETHOD (msprinter, mswindows, xbm, instantiate); | |
428 | 2986 #ifdef HAVE_XPM |
2987 INITIALIZE_DEVICE_IIFORMAT (mswindows, xpm); | |
442 | 2988 INITIALIZE_DEVICE_IIFORMAT (msprinter, xpm); |
428 | 2989 IIFORMAT_HAS_DEVMETHOD (mswindows, xpm, instantiate); |
442 | 2990 IIFORMAT_INHERITS_DEVMETHOD (msprinter, mswindows, xpm, instantiate); |
428 | 2991 #endif |
2992 #ifdef HAVE_XFACE | |
2993 INITIALIZE_DEVICE_IIFORMAT (mswindows, xface); | |
442 | 2994 INITIALIZE_DEVICE_IIFORMAT (msprinter, xface); |
428 | 2995 IIFORMAT_HAS_DEVMETHOD (mswindows, xface, instantiate); |
442 | 2996 IIFORMAT_INHERITS_DEVMETHOD (msprinter, mswindows, xface, instantiate); |
428 | 2997 #endif |
2998 #ifdef HAVE_JPEG | |
442 | 2999 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, jpeg); |
428 | 3000 #endif |
3001 #ifdef HAVE_TIFF | |
442 | 3002 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, tiff); |
434 | 3003 #endif |
428 | 3004 #ifdef HAVE_PNG |
442 | 3005 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, png); |
434 | 3006 #endif |
428 | 3007 #ifdef HAVE_GIF |
442 | 3008 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, gif); |
434 | 3009 #endif |
428 | 3010 #ifdef HAVE_WIDGETS |
442 | 3011 INITIALIZE_DEVICE_IIFORMAT (mswindows, widget); |
3012 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, property); | |
3013 /* layout widget */ | |
3014 IIFORMAT_VALID_CONSOLE (mswindows, layout); | |
3015 INITIALIZE_DEVICE_IIFORMAT (mswindows, native_layout); | |
3016 IIFORMAT_HAS_DEVMETHOD (mswindows, native_layout, instantiate); | |
428 | 3017 /* button widget */ |
3018 INITIALIZE_DEVICE_IIFORMAT (mswindows, button); | |
3019 IIFORMAT_HAS_DEVMETHOD (mswindows, button, property); | |
3020 IIFORMAT_HAS_DEVMETHOD (mswindows, button, instantiate); | |
442 | 3021 IIFORMAT_HAS_DEVMETHOD (mswindows, button, redisplay); |
3022 /* edit-field widget */ | |
428 | 3023 INITIALIZE_DEVICE_IIFORMAT (mswindows, edit_field); |
3024 IIFORMAT_HAS_DEVMETHOD (mswindows, edit_field, instantiate); | |
442 | 3025 /* subwindow */ |
428 | 3026 INITIALIZE_DEVICE_IIFORMAT (mswindows, subwindow); |
3027 IIFORMAT_HAS_DEVMETHOD (mswindows, subwindow, instantiate); | |
3028 /* label */ | |
3029 INITIALIZE_DEVICE_IIFORMAT (mswindows, label); | |
3030 IIFORMAT_HAS_DEVMETHOD (mswindows, label, instantiate); | |
3031 /* combo box */ | |
3032 INITIALIZE_DEVICE_IIFORMAT (mswindows, combo_box); | |
3033 IIFORMAT_HAS_DEVMETHOD (mswindows, combo_box, property); | |
3034 IIFORMAT_HAS_DEVMETHOD (mswindows, combo_box, instantiate); | |
3035 /* scrollbar */ | |
3036 INITIALIZE_DEVICE_IIFORMAT (mswindows, scrollbar); | |
3037 IIFORMAT_HAS_DEVMETHOD (mswindows, scrollbar, instantiate); | |
3038 /* progress gauge */ | |
3039 INITIALIZE_DEVICE_IIFORMAT (mswindows, progress_gauge); | |
442 | 3040 IIFORMAT_HAS_DEVMETHOD (mswindows, progress_gauge, redisplay); |
428 | 3041 IIFORMAT_HAS_DEVMETHOD (mswindows, progress_gauge, instantiate); |
3042 /* tree view widget */ | |
3043 INITIALIZE_DEVICE_IIFORMAT (mswindows, tree_view); | |
3044 IIFORMAT_HAS_DEVMETHOD (mswindows, tree_view, instantiate); | |
442 | 3045 IIFORMAT_HAS_DEVMETHOD (mswindows, tree_view, redisplay); |
428 | 3046 /* tab control widget */ |
3047 INITIALIZE_DEVICE_IIFORMAT (mswindows, tab_control); | |
3048 IIFORMAT_HAS_DEVMETHOD (mswindows, tab_control, instantiate); | |
442 | 3049 IIFORMAT_HAS_DEVMETHOD (mswindows, tab_control, redisplay); |
428 | 3050 #endif |
3051 /* windows bitmap format */ | |
3052 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp"); | |
3053 IIFORMAT_HAS_METHOD (bmp, validate); | |
3054 IIFORMAT_HAS_METHOD (bmp, normalize); | |
3055 IIFORMAT_HAS_METHOD (bmp, possible_dest_types); | |
3056 IIFORMAT_HAS_METHOD (bmp, instantiate); | |
3057 | |
3058 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string); | |
3059 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string); | |
442 | 3060 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, bmp); |
428 | 3061 |
3062 /* mswindows resources */ | |
3063 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (mswindows_resource, | |
3064 "mswindows-resource"); | |
3065 | |
3066 IIFORMAT_HAS_METHOD (mswindows_resource, validate); | |
3067 IIFORMAT_HAS_METHOD (mswindows_resource, normalize); | |
3068 IIFORMAT_HAS_METHOD (mswindows_resource, possible_dest_types); | |
3069 IIFORMAT_HAS_METHOD (mswindows_resource, instantiate); | |
3070 | |
434 | 3071 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_type, |
428 | 3072 check_valid_resource_symbol); |
3073 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_resource_id, check_valid_resource_id); | |
3074 IIFORMAT_VALID_KEYWORD (mswindows_resource, Q_file, check_valid_string); | |
442 | 3075 IIFORMAT_VALID_CONSOLE2 (mswindows, msprinter, mswindows_resource); |
428 | 3076 } |
3077 | |
3078 void | |
3079 vars_of_glyphs_mswindows (void) | |
3080 { | |
3081 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /* | |
3082 A list of the directories in which mswindows bitmap files may be found. | |
3083 This is used by the `make-image-instance' function. | |
3084 */ ); | |
3085 Vmswindows_bitmap_file_path = Qnil; | |
3086 } | |
3087 | |
3088 void | |
3089 complex_vars_of_glyphs_mswindows (void) | |
3090 { | |
3091 } |