comparison src/device-msw.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children a86b2b5e0111
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
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;
140 wc.cbClsExtra = 0; 149 wc.cbClsExtra = 0;
141 wc.cbWndExtra = MSWINDOWS_WINDOW_EXTRA_BYTES; 150 wc.cbWndExtra = MSWINDOWS_WINDOW_EXTRA_BYTES;
142 wc.hInstance = NULL; /* ? */ 151 /* This must match whatever is passed to CreateWIndowEx, NULL is ok
152 for this. */
153 wc.hInstance = NULL;
143 wc.hIcon = LoadIcon (GetModuleHandle(NULL), XEMACS_CLASS); 154 wc.hIcon = LoadIcon (GetModuleHandle(NULL), XEMACS_CLASS);
144 wc.hCursor = LoadCursor (NULL, IDC_ARROW); 155 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
145 /* Background brush is only used during sizing, when XEmacs cannot 156 /* Background brush is only used during sizing, when XEmacs cannot
146 take over */ 157 take over */
147 wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); 158 wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
149 160
150 wc.lpszClassName = XEMACS_CLASS; 161 wc.lpszClassName = XEMACS_CLASS;
151 wc.hIconSm = LoadImage (GetModuleHandle (NULL), XEMACS_CLASS, 162 wc.hIconSm = LoadImage (GetModuleHandle (NULL), XEMACS_CLASS,
152 IMAGE_ICON, 16, 16, 0); 163 IMAGE_ICON, 16, 16, 0);
153 RegisterClassEx (&wc); 164 RegisterClassEx (&wc);
154 #ifdef HAVE_TOOLBARS 165
166 #ifdef HAVE_WIDGETS
167 xzero (wc);
168 /* Register the main window class */
169 wc.cbSize = sizeof (WNDCLASSEX);
170 wc.lpfnWndProc = (WNDPROC) mswindows_control_wnd_proc;
171 wc.lpszClassName = XEMACS_CONTROL_CLASS;
172 wc.hInstance = NULL;
173 RegisterClassEx (&wc);
174 #endif
175
176 #if defined (HAVE_TOOLBARS) || defined (HAVE_WIDGETS)
155 InitCommonControls (); 177 InitCommonControls ();
156 #endif 178 #endif
157 } 179 }
158 180
159 static void 181 static void
176 } 198 }
177 199
178 static void 200 static void
179 mswindows_delete_device (struct device *d) 201 mswindows_delete_device (struct device *d)
180 { 202 {
181 struct mswindows_font_enum *fontlist, *next;
182
183 fontlist = DEVICE_MSWINDOWS_FONTLIST (d);
184 while (fontlist)
185 {
186 next = fontlist->next;
187 free (fontlist);
188 fontlist = next;
189 }
190
191 #ifdef HAVE_DRAGNDROP 203 #ifdef HAVE_DRAGNDROP
192 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER); 204 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER);
193 DdeUninitialize (mswindows_dde_mlid); 205 DdeUninitialize (mswindows_dde_mlid);
194 #endif 206 #endif
195 207
196 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));
197 } 215 }
198 216
199 static Lisp_Object 217 static Lisp_Object
200 mswindows_device_system_metrics (struct device *d, 218 mswindows_device_system_metrics (struct device *d,
201 enum device_metrics m) 219 enum device_metrics m)
203 switch (m) 221 switch (m)
204 { 222 {
205 case DM_size_device: 223 case DM_size_device:
206 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)), 224 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)),
207 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)));
208 break; 230 break;
209 case DM_size_device_mm: 231 case DM_size_device_mm:
210 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)), 232 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)),
211 make_int (DEVICE_MSWINDOWS_VERTSIZE(d))); 233 make_int (DEVICE_MSWINDOWS_VERTSIZE(d)));
212 break; 234 break;
290 return XDEVIMPF_PIXEL_GEOMETRY; 312 return XDEVIMPF_PIXEL_GEOMETRY;
291 } 313 }
292 314
293 315
294 /************************************************************************/ 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 /************************************************************************/
295 /* initialization */ 495 /* initialization */
296 /************************************************************************/ 496 /************************************************************************/
297 497
298 void 498 void
299 syms_of_device_mswindows (void) 499 syms_of_device_mswindows (void)
300 { 500 {
301 defsymbol (&Qinit_pre_mswindows_win, "init-pre-mswindows-win"); 501 defsymbol (&Qinit_pre_mswindows_win, "init-pre-mswindows-win");
302 defsymbol (&Qinit_post_mswindows_win, "init-post-mswindows-win"); 502 defsymbol (&Qinit_post_mswindows_win, "init-post-mswindows-win");
303 503 }
504
505 void
506 console_type_create_device_mswindows (void)
507 {
508 CONSOLE_HAS_METHOD (mswindows, init_device);
509 CONSOLE_HAS_METHOD (mswindows, finish_init_device);
510 CONSOLE_HAS_METHOD (mswindows, mark_device);
511 CONSOLE_HAS_METHOD (mswindows, delete_device);
512 CONSOLE_HAS_METHOD (mswindows, device_system_metrics);
513 CONSOLE_HAS_METHOD (mswindows, device_implementation_flags);
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
522
523 void
524 vars_of_device_mswindows (void)
525 {
304 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /* 526 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*
305 Non-nil means convert all-upper case file names to lower case. 527 Non-nil means convert all-upper case file names to lower case.
306 This applies when performing completions and file name expansion.*/ ); 528 This applies when performing completions and file name expansion.
529 */ );
307 Vmswindows_downcase_file_names = Qnil; 530 Vmswindows_downcase_file_names = Qnil;
308 531
309 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /* 532 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /*
310 "Non-nil means determine accurate link count in file-attributes. 533 Non-nil means determine accurate link count in file-attributes.
311 This option slows down file-attributes noticeably, so is disabled by 534 This option slows down file-attributes noticeably, so is disabled by
312 default. Note that it is only useful for files on NTFS volumes, 535 default. Note that it is only useful for files on NTFS volumes,
313 where hard links are supported. 536 where hard links are supported.
314 */ ); 537 */ );
315 Vmswindows_get_true_file_attributes = Qnil; 538 Vmswindows_get_true_file_attributes = Qnil;
316 } 539 }
317
318 void
319 console_type_create_device_mswindows (void)
320 {
321 CONSOLE_HAS_METHOD (mswindows, init_device);
322 CONSOLE_HAS_METHOD (mswindows, finish_init_device);
323 /* CONSOLE_HAS_METHOD (mswindows, mark_device); */
324 CONSOLE_HAS_METHOD (mswindows, delete_device);
325 CONSOLE_HAS_METHOD (mswindows, device_system_metrics);
326 CONSOLE_HAS_METHOD (mswindows, device_implementation_flags);
327 }
328
329 void
330 vars_of_device_mswindows (void)
331 {
332 }