comparison src/device-msw.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 3ecd8885ac67
children abe6d1db359e
comparison
equal deleted inserted replaced
439:357dd071b03c 440:8de8e3f6228a
36 #include "console-stream.h" 36 #include "console-stream.h"
37 #include "events.h" 37 #include "events.h"
38 #include "faces.h" 38 #include "faces.h"
39 #include "frame.h" 39 #include "frame.h"
40 #include "sysdep.h" 40 #include "sysdep.h"
41
42 #include <winspool.h>
41 43
42 /* win32 DDE management library globals */ 44 /* win32 DDE management library globals */
43 #ifdef HAVE_DRAGNDROP 45 #ifdef HAVE_DRAGNDROP
44 DWORD mswindows_dde_mlid; 46 DWORD mswindows_dde_mlid;
45 HSZ mswindows_dde_service; 47 HSZ mswindows_dde_service;
62 /************************************************************************/ 64 /************************************************************************/
63 /* helpers */ 65 /* helpers */
64 /************************************************************************/ 66 /************************************************************************/
65 67
66 static Lisp_Object 68 static Lisp_Object
67 build_syscolor_string (int index) 69 build_syscolor_string (int idx)
68 { 70 {
69 DWORD clr; 71 DWORD clr;
70 char buf[16]; 72 char buf[16];
71 73
72 if (index < 0) 74 if (idx < 0)
73 return Qnil; 75 return Qnil;
74 76
75 clr = GetSysColor (index); 77 clr = GetSysColor (idx);
76 sprintf (buf, "#%02X%02X%02X", 78 sprintf (buf, "#%02X%02X%02X",
77 GetRValue (clr), 79 GetRValue (clr),
78 GetGValue (clr), 80 GetGValue (clr),
79 GetBValue (clr)); 81 GetBValue (clr));
80 return build_string (buf); 82 return build_string (buf);
96 { 98 {
97 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)), 99 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)),
98 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2))); 100 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2)));
99 } 101 }
100 102
103 static Lisp_Object
104 build_devicecaps_cons (HDC hdc, int index1, int index2)
105 {
106 return Fcons (index1 < 0 ? Qnil : make_int (GetDeviceCaps (hdc, index1)),
107 index2 < 0 ? Qnil : make_int (GetDeviceCaps (hdc, index2)));
108 }
109
101 110
102 111
103 /************************************************************************/ 112 /************************************************************************/
104 /* methods */ 113 /* display methods */
105 /************************************************************************/ 114 /************************************************************************/
106 115
107 static void 116 static void
108 mswindows_init_device (struct device *d, Lisp_Object props) 117 mswindows_init_device (struct device *d, Lisp_Object props)
109 { 118 {
127 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES); 136 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES);
128 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES); 137 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES);
129 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE); 138 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE);
130 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE); 139 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE);
131 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL); 140 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL);
141 DEVICE_MSWINDOWS_FONTLIST (d) = mswindows_enumerate_fonts (hdc);
142
132 DeleteDC (hdc); 143 DeleteDC (hdc);
133
134 mswindows_enumerate_fonts (d);
135 144
136 /* Register the main window class */ 145 /* Register the main window class */
137 wc.cbSize = sizeof (WNDCLASSEX); 146 wc.cbSize = sizeof (WNDCLASSEX);
138 wc.style = CS_OWNDC; /* One DC per window */ 147 wc.style = CS_OWNDC; /* One DC per window */
139 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc; 148 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc;
162 wc.lpszClassName = XEMACS_CONTROL_CLASS; 171 wc.lpszClassName = XEMACS_CONTROL_CLASS;
163 wc.hInstance = NULL; 172 wc.hInstance = NULL;
164 RegisterClassEx (&wc); 173 RegisterClassEx (&wc);
165 #endif 174 #endif
166 175
167 #ifdef HAVE_TOOLBARS 176 #if defined (HAVE_TOOLBARS) || defined (HAVE_WIDGETS)
168 InitCommonControls (); 177 InitCommonControls ();
169 #endif 178 #endif
170 } 179 }
171 180
172 static void 181 static void
189 } 198 }
190 199
191 static void 200 static void
192 mswindows_delete_device (struct device *d) 201 mswindows_delete_device (struct device *d)
193 { 202 {
194 struct mswindows_font_enum *fontlist, *next;
195
196 fontlist = DEVICE_MSWINDOWS_FONTLIST (d);
197 while (fontlist)
198 {
199 next = fontlist->next;
200 free (fontlist);
201 fontlist = next;
202 }
203
204 #ifdef HAVE_DRAGNDROP 203 #ifdef HAVE_DRAGNDROP
205 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER); 204 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER);
206 DdeUninitialize (mswindows_dde_mlid); 205 DdeUninitialize (mswindows_dde_mlid);
207 #endif 206 #endif
208 207
209 free (d->device_data); 208 free (d->device_data);
209 }
210
211 static void
212 mswindows_mark_device (struct device *d)
213 {
214 mark_object (DEVICE_MSWINDOWS_FONTLIST (d));
210 } 215 }
211 216
212 static Lisp_Object 217 static Lisp_Object
213 mswindows_device_system_metrics (struct device *d, 218 mswindows_device_system_metrics (struct device *d,
214 enum device_metrics m) 219 enum device_metrics m)
216 switch (m) 221 switch (m)
217 { 222 {
218 case DM_size_device: 223 case DM_size_device:
219 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)), 224 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)),
220 make_int (DEVICE_MSWINDOWS_VERTRES(d))); 225 make_int (DEVICE_MSWINDOWS_VERTRES(d)));
226 break;
227 case DM_device_dpi:
228 return Fcons (make_int (DEVICE_MSWINDOWS_LOGPIXELSX(d)),
229 make_int (DEVICE_MSWINDOWS_LOGPIXELSY(d)));
221 break; 230 break;
222 case DM_size_device_mm: 231 case DM_size_device_mm:
223 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)), 232 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)),
224 make_int (DEVICE_MSWINDOWS_VERTSIZE(d))); 233 make_int (DEVICE_MSWINDOWS_VERTSIZE(d)));
225 break; 234 break;
303 return XDEVIMPF_PIXEL_GEOMETRY; 312 return XDEVIMPF_PIXEL_GEOMETRY;
304 } 313 }
305 314
306 315
307 /************************************************************************/ 316 /************************************************************************/
317 /* printer methods */
318 /************************************************************************/
319
320 static void
321 signal_open_printer_error (struct device *d)
322 {
323 signal_simple_error ("Failed to open printer", DEVICE_CONNECTION (d));
324 }
325
326 static void
327 msprinter_init_device (struct device *d, Lisp_Object props)
328 {
329 char* printer_name;
330
331 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1;
332
333 CHECK_STRING (DEVICE_CONNECTION (d));
334
335 TO_EXTERNAL_FORMAT (LISP_STRING, DEVICE_CONNECTION (d),
336 C_STRING_ALLOCA, printer_name,
337 Qctext);
338
339 d->device_data = xnew_and_zero (struct msprinter_device);
340
341 DEVICE_MSPRINTER_NAME(d) = xstrdup (printer_name);
342
343 if (!OpenPrinter (printer_name, &DEVICE_MSPRINTER_HPRINTER (d), NULL))
344 {
345 DEVICE_MSPRINTER_HPRINTER (d) = NULL;
346 signal_open_printer_error (d);
347 }
348
349 DEVICE_MSPRINTER_HDC (d) = CreateDC ("WINSPOOL", printer_name,
350 NULL, NULL);
351 if (DEVICE_MSPRINTER_HDC (d) == NULL)
352 signal_open_printer_error (d);
353
354 /* Determinie DEVMODE size and store the default DEVMODE */
355 DEVICE_MSPRINTER_DEVMODE_SIZE(d) =
356 DocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER(d),
357 printer_name, NULL, NULL, 0);
358 if (DEVICE_MSPRINTER_DEVMODE_SIZE(d) <= 0)
359 signal_open_printer_error (d);
360
361 DEVICE_MSPRINTER_DEVMODE(d) = xmalloc (DEVICE_MSPRINTER_DEVMODE_SIZE(d));
362 DocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER(d),
363 printer_name, DEVICE_MSPRINTER_DEVMODE(d),
364 NULL, DM_OUT_BUFFER);
365
366 /* We do not use printer fon list as we do with the display
367 device. Rather, we allow GDI to pick the closest match to the
368 display font. */
369 DEVICE_MSPRINTER_FONTLIST (d) = Qnil;
370
371 DEVICE_CLASS (d) = (GetDeviceCaps (DEVICE_MSPRINTER_HDC (d), BITSPIXEL)
372 * GetDeviceCaps (DEVICE_MSPRINTER_HDC (d), PLANES)
373 > 1) ? Qcolor : Qmono;
374 }
375
376 static Lisp_Object
377 msprinter_device_system_metrics (struct device *d,
378 enum device_metrics m)
379 {
380 switch (m)
381 {
382 /* Device sizes - pixel and mm */
383 #define FROB(met, index1, index2) \
384 case DM_##met: \
385 return build_devicecaps_cons \
386 (DEVICE_MSPRINTER_HDC(d), index1, index2);
387
388 FROB (size_device, PHYSICALWIDTH, PHYSICALHEIGHT);
389 FROB (size_device_mm, HORZSIZE, VERTSIZE);
390 FROB (size_workspace, HORZRES, VERTRES);
391 FROB (offset_workspace, PHYSICALOFFSETX, PHYSICALOFFSETY);
392 FROB (device_dpi, LOGPIXELSX, LOGPIXELSY);
393 #undef FROB
394
395 case DM_num_bit_planes:
396 /* this is what X means by bitplanes therefore we ought to be
397 consistent. num planes is always 1 under mswindows and
398 therefore useless */
399 return make_int (GetDeviceCaps (DEVICE_MSPRINTER_HDC(d), BITSPIXEL));
400
401 case DM_num_color_cells: /* Prnters are non-palette devices */
402 case DM_slow_device: /* Animation would be a really bad idea */
403 case DM_security: /* Not provided by windows */
404 return Qzero;
405 }
406
407 /* Do not know such property */
408 return Qunbound;
409 }
410
411 static void
412 msprinter_delete_device (struct device *d)
413 {
414 if (d->device_data)
415 {
416 if (DEVICE_MSPRINTER_HPRINTER (d))
417 ClosePrinter (DEVICE_MSPRINTER_HPRINTER (d));
418 if (DEVICE_MSPRINTER_HDC (d))
419 DeleteDC (DEVICE_MSPRINTER_HDC (d));
420 if (DEVICE_MSPRINTER_NAME (d))
421 free (DEVICE_MSPRINTER_NAME (d));
422 if (DEVICE_MSPRINTER_DEVMODE (d))
423 free (DEVICE_MSPRINTER_DEVMODE (d));
424 if (DEVICE_MSPRINTER_DEVMODE_MIRROR (d))
425 free (DEVICE_MSPRINTER_DEVMODE_MIRROR (d));
426
427 free (d->device_data);
428 }
429 }
430
431 static void
432 msprinter_mark_device (struct device *d)
433 {
434 mark_object (DEVICE_MSPRINTER_FONTLIST (d));
435 }
436
437 static unsigned int
438 msprinter_device_implementation_flags (void)
439 {
440 return ( XDEVIMPF_PIXEL_GEOMETRY
441 | XDEVIMPF_IS_A_PRINTER
442 | XDEVIMPF_NO_AUTO_REDISPLAY
443 | XDEVIMPF_FRAMELESS_OK );
444 }
445
446
447 /************************************************************************/
448 /* printer external functions */
449 /************************************************************************/
450
451 /*
452 * Return a copy of default DEVMODE. The copy returned is in
453 * a static buffer which will be overwritten by next call.
454 */
455 DEVMODE*
456 msprinter_get_devmode_copy (struct device *d)
457 {
458 assert (DEVICE_MSPRINTER_P (d));
459
460 if (DEVICE_MSPRINTER_DEVMODE_MIRROR(d) == NULL)
461 DEVICE_MSPRINTER_DEVMODE_MIRROR(d) =
462 xmalloc (DEVICE_MSPRINTER_DEVMODE_SIZE(d));
463
464 memcpy (DEVICE_MSPRINTER_DEVMODE_MIRROR(d),
465 DEVICE_MSPRINTER_DEVMODE(d),
466 DEVICE_MSPRINTER_DEVMODE_SIZE(d));
467
468 return DEVICE_MSPRINTER_DEVMODE_MIRROR(d);
469 }
470
471 /*
472 * Apply settings from the DEVMODE. The settings are considered
473 * incremental to the default DEVMODE, so that changes in the
474 * passed structure supercede parameters of the printer.
475 *
476 * The passed structure is overwritten by the fuction call;
477 * complete printer settings are returned.
478 */
479 void
480 msprinter_apply_devmode (struct device *d, DEVMODE *devmode)
481 {
482 assert (DEVICE_MSPRINTER_P (d));
483
484 DocumentProperties (NULL,
485 DEVICE_MSPRINTER_HPRINTER(d),
486 DEVICE_MSPRINTER_NAME(d),
487 devmode, devmode,
488 DM_IN_BUFFER | DM_OUT_BUFFER);
489
490 ResetDC (DEVICE_MSPRINTER_HDC (d), devmode);
491 }
492
493
494 /************************************************************************/
308 /* initialization */ 495 /* initialization */
309 /************************************************************************/ 496 /************************************************************************/
310 497
311 void 498 void
312 syms_of_device_mswindows (void) 499 syms_of_device_mswindows (void)
318 void 505 void
319 console_type_create_device_mswindows (void) 506 console_type_create_device_mswindows (void)
320 { 507 {
321 CONSOLE_HAS_METHOD (mswindows, init_device); 508 CONSOLE_HAS_METHOD (mswindows, init_device);
322 CONSOLE_HAS_METHOD (mswindows, finish_init_device); 509 CONSOLE_HAS_METHOD (mswindows, finish_init_device);
323 /* CONSOLE_HAS_METHOD (mswindows, mark_device); */ 510 CONSOLE_HAS_METHOD (mswindows, mark_device);
324 CONSOLE_HAS_METHOD (mswindows, delete_device); 511 CONSOLE_HAS_METHOD (mswindows, delete_device);
325 CONSOLE_HAS_METHOD (mswindows, device_system_metrics); 512 CONSOLE_HAS_METHOD (mswindows, device_system_metrics);
326 CONSOLE_HAS_METHOD (mswindows, device_implementation_flags); 513 CONSOLE_HAS_METHOD (mswindows, device_implementation_flags);
327 } 514
515 CONSOLE_HAS_METHOD (msprinter, init_device);
516 CONSOLE_HAS_METHOD (msprinter, mark_device);
517 CONSOLE_HAS_METHOD (msprinter, delete_device);
518 CONSOLE_HAS_METHOD (msprinter, device_system_metrics);
519 CONSOLE_HAS_METHOD (msprinter, device_implementation_flags);
520 }
521
328 522
329 void 523 void
330 vars_of_device_mswindows (void) 524 vars_of_device_mswindows (void)
331 { 525 {
332 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /* 526 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*