428
|
1 /* device functions for mswindows.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
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
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* Authorship:
|
|
25
|
|
26 Original authors: Jamie Zawinski and the FSF
|
|
27 Rewritten by Ben Wing and Chuck Thompson.
|
|
28 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
|
510
|
29 Print support added by Kirill Katsnelson, July 2000.
|
428
|
30 */
|
|
31
|
|
32
|
|
33 #include <config.h>
|
|
34 #include "lisp.h"
|
|
35
|
|
36 #include "console-msw.h"
|
|
37 #include "console-stream.h"
|
442
|
38 #include "objects-msw.h"
|
428
|
39 #include "events.h"
|
|
40 #include "faces.h"
|
|
41 #include "frame.h"
|
|
42 #include "sysdep.h"
|
|
43
|
442
|
44 #include <commdlg.h>
|
|
45
|
|
46 #if !(defined (CYGWIN) || defined(MINGW))
|
|
47 #include <objbase.h> /* For CoInitialize */
|
|
48 #endif
|
440
|
49
|
428
|
50 /* win32 DDE management library globals */
|
|
51 #ifdef HAVE_DRAGNDROP
|
|
52 DWORD mswindows_dde_mlid;
|
|
53 HSZ mswindows_dde_service;
|
|
54 HSZ mswindows_dde_topic_system;
|
|
55 HSZ mswindows_dde_item_open;
|
|
56 #endif
|
|
57
|
|
58 /* Control conversion of upper case file names to lower case.
|
|
59 nil means no, t means yes. */
|
|
60 Lisp_Object Vmswindows_downcase_file_names;
|
|
61
|
442
|
62 /* Control whether xemacs_stat() attempts to determine file type and link count
|
428
|
63 exactly, at the expense of slower operation. Since true hard links
|
|
64 are supported on NTFS volumes, this is only relevant on NT. */
|
|
65 Lisp_Object Vmswindows_get_true_file_attributes;
|
|
66
|
|
67 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win;
|
442
|
68 Lisp_Object Qdevmodep;
|
428
|
69
|
510
|
70 static Lisp_Object Q_allow_selection;
|
|
71 static Lisp_Object Q_allow_pages;
|
|
72 static Lisp_Object Q_selected_page_button;
|
|
73 static Lisp_Object Qselected_page_button;
|
|
74
|
442
|
75 static Lisp_Object allocate_devmode (DEVMODE* src_devmode, int do_copy,
|
|
76 char* src_name, struct device *d);
|
428
|
77
|
|
78 /************************************************************************/
|
|
79 /* helpers */
|
|
80 /************************************************************************/
|
|
81
|
|
82 static Lisp_Object
|
440
|
83 build_syscolor_string (int idx)
|
428
|
84 {
|
442
|
85 return (idx < 0 ? Qnil : mswindows_color_to_string (GetSysColor (idx)));
|
428
|
86 }
|
|
87
|
|
88 static Lisp_Object
|
|
89 build_syscolor_cons (int index1, int index2)
|
|
90 {
|
|
91 Lisp_Object color1, color2;
|
|
92 struct gcpro gcpro1;
|
|
93 GCPRO1 (color1);
|
|
94 color1 = build_syscolor_string (index1);
|
|
95 color2 = build_syscolor_string (index2);
|
|
96 RETURN_UNGCPRO (Fcons (color1, color2));
|
|
97 }
|
|
98
|
|
99 static Lisp_Object
|
|
100 build_sysmetrics_cons (int index1, int index2)
|
|
101 {
|
|
102 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)),
|
|
103 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2)));
|
|
104 }
|
|
105
|
440
|
106 static Lisp_Object
|
|
107 build_devicecaps_cons (HDC hdc, int index1, int index2)
|
|
108 {
|
|
109 return Fcons (index1 < 0 ? Qnil : make_int (GetDeviceCaps (hdc, index1)),
|
|
110 index2 < 0 ? Qnil : make_int (GetDeviceCaps (hdc, index2)));
|
|
111 }
|
|
112
|
428
|
113
|
|
114 /************************************************************************/
|
440
|
115 /* display methods */
|
428
|
116 /************************************************************************/
|
|
117
|
|
118 static void
|
|
119 mswindows_init_device (struct device *d, Lisp_Object props)
|
|
120 {
|
|
121 WNDCLASSEX wc;
|
|
122 HDC hdc;
|
|
123
|
|
124 DEVICE_CLASS (d) = Qcolor;
|
|
125 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1;
|
|
126 init_baud_rate (d);
|
|
127 init_one_device (d);
|
|
128
|
|
129 d->device_data = xnew_and_zero (struct mswindows_device);
|
|
130 hdc = CreateCompatibleDC (NULL);
|
|
131 assert (hdc!=NULL);
|
442
|
132 DEVICE_MSWINDOWS_HCDC(d) = hdc;
|
440
|
133 DEVICE_MSWINDOWS_FONTLIST (d) = mswindows_enumerate_fonts (hdc);
|
442
|
134 DEVICE_MSWINDOWS_UPDATE_TICK (d) = GetTickCount ();
|
428
|
135
|
|
136 /* Register the main window class */
|
|
137 wc.cbSize = sizeof (WNDCLASSEX);
|
|
138 wc.style = CS_OWNDC; /* One DC per window */
|
|
139 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc;
|
|
140 wc.cbClsExtra = 0;
|
|
141 wc.cbWndExtra = MSWINDOWS_WINDOW_EXTRA_BYTES;
|
|
142 /* This must match whatever is passed to CreateWIndowEx, NULL is ok
|
|
143 for this. */
|
442
|
144 wc.hInstance = NULL;
|
428
|
145 wc.hIcon = LoadIcon (GetModuleHandle(NULL), XEMACS_CLASS);
|
|
146 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
|
|
147 /* Background brush is only used during sizing, when XEmacs cannot
|
|
148 take over */
|
|
149 wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
|
|
150 wc.lpszMenuName = NULL;
|
|
151
|
|
152 wc.lpszClassName = XEMACS_CLASS;
|
442
|
153 if (xLoadImageA) /* not in NT 3.5 */
|
|
154 wc.hIconSm = (HICON) xLoadImageA (GetModuleHandle (NULL), XEMACS_CLASS,
|
|
155 IMAGE_ICON, 16, 16, 0);
|
|
156 else
|
|
157 wc.hIconSm = 0;
|
|
158
|
|
159 if (xRegisterClassExA) /* not in NT 3.5 */
|
|
160 xRegisterClassExA (&wc);
|
|
161 else
|
|
162 RegisterClassA ((WNDCLASS *) &wc.style);
|
428
|
163
|
|
164 #ifdef HAVE_WIDGETS
|
|
165 xzero (wc);
|
|
166 /* Register the main window class */
|
|
167 wc.cbSize = sizeof (WNDCLASSEX);
|
|
168 wc.lpfnWndProc = (WNDPROC) mswindows_control_wnd_proc;
|
|
169 wc.lpszClassName = XEMACS_CONTROL_CLASS;
|
|
170 wc.hInstance = NULL;
|
442
|
171 if (xRegisterClassExA) /* not in NT 3.5 */
|
|
172 xRegisterClassExA (&wc);
|
|
173 else
|
|
174 RegisterClassA ((WNDCLASS *) &wc.style);
|
428
|
175 #endif
|
|
176
|
440
|
177 #if defined (HAVE_TOOLBARS) || defined (HAVE_WIDGETS)
|
428
|
178 InitCommonControls ();
|
|
179 #endif
|
|
180 }
|
|
181
|
|
182 static void
|
|
183 mswindows_finish_init_device (struct device *d, Lisp_Object props)
|
|
184 {
|
|
185 /* Initialize DDE management library and our related globals. We execute a
|
|
186 * dde Open("file") by simulating a drop, so this depends on dnd support. */
|
|
187 #ifdef HAVE_DRAGNDROP
|
442
|
188 # if !(defined(CYGWIN) || defined(MINGW))
|
|
189 CoInitialize (NULL);
|
|
190 # endif
|
|
191
|
428
|
192 mswindows_dde_mlid = 0;
|
|
193 DdeInitialize (&mswindows_dde_mlid, (PFNCALLBACK)mswindows_dde_callback,
|
|
194 APPCMD_FILTERINITS|CBF_FAIL_SELFCONNECTIONS|CBF_FAIL_ADVISES|
|
442
|
195 CBF_FAIL_POKES|CBF_FAIL_REQUESTS|CBF_SKIP_ALLNOTIFICATIONS,
|
|
196 0);
|
|
197
|
|
198 mswindows_dde_service = DdeCreateStringHandle (mswindows_dde_mlid,
|
|
199 XEMACS_CLASS, 0);
|
|
200 mswindows_dde_topic_system = DdeCreateStringHandle (mswindows_dde_mlid,
|
|
201 SZDDESYS_TOPIC, 0);
|
428
|
202 mswindows_dde_item_open = DdeCreateStringHandle (mswindows_dde_mlid,
|
|
203 TEXT(MSWINDOWS_DDE_ITEM_OPEN), 0);
|
|
204 DdeNameService (mswindows_dde_mlid, mswindows_dde_service, 0L, DNS_REGISTER);
|
|
205 #endif
|
|
206 }
|
|
207
|
|
208 static void
|
|
209 mswindows_delete_device (struct device *d)
|
|
210 {
|
|
211 #ifdef HAVE_DRAGNDROP
|
442
|
212 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_UNREGISTER);
|
|
213 DdeFreeStringHandle (mswindows_dde_mlid, mswindows_dde_item_open);
|
|
214 DdeFreeStringHandle (mswindows_dde_mlid, mswindows_dde_topic_system);
|
|
215 DdeFreeStringHandle (mswindows_dde_mlid, mswindows_dde_service);
|
428
|
216 DdeUninitialize (mswindows_dde_mlid);
|
442
|
217
|
|
218 # if !(defined(CYGWIN) || defined(MINGW))
|
|
219 CoUninitialize ();
|
|
220 # endif
|
428
|
221 #endif
|
|
222
|
442
|
223 DeleteDC (DEVICE_MSWINDOWS_HCDC(d));
|
|
224 xfree (d->device_data);
|
|
225 }
|
|
226
|
|
227 void
|
|
228 mswindows_get_workspace_coords (RECT *rc)
|
|
229 {
|
|
230 SystemParametersInfo (SPI_GETWORKAREA, 0, rc, 0);
|
428
|
231 }
|
|
232
|
440
|
233 static void
|
|
234 mswindows_mark_device (struct device *d)
|
|
235 {
|
|
236 mark_object (DEVICE_MSWINDOWS_FONTLIST (d));
|
|
237 }
|
|
238
|
428
|
239 static Lisp_Object
|
|
240 mswindows_device_system_metrics (struct device *d,
|
|
241 enum device_metrics m)
|
|
242 {
|
442
|
243 const HDC hdc = DEVICE_MSWINDOWS_HCDC(d);
|
|
244
|
428
|
245 switch (m)
|
|
246 {
|
|
247 case DM_size_device:
|
442
|
248 return Fcons (make_int (GetDeviceCaps (hdc, HORZRES)),
|
|
249 make_int (GetDeviceCaps (hdc, VERTRES)));
|
428
|
250 break;
|
440
|
251 case DM_device_dpi:
|
442
|
252 return Fcons (make_int (GetDeviceCaps (hdc, LOGPIXELSX)),
|
|
253 make_int (GetDeviceCaps (hdc, LOGPIXELSY)));
|
440
|
254 break;
|
428
|
255 case DM_size_device_mm:
|
442
|
256 return Fcons (make_int (GetDeviceCaps (hdc, HORZSIZE)),
|
|
257 make_int (GetDeviceCaps (hdc, VERTSIZE)));
|
428
|
258 break;
|
|
259 case DM_num_bit_planes:
|
|
260 /* this is what X means by bitplanes therefore we ought to be
|
|
261 consistent. num planes is always 1 under mswindows and
|
|
262 therefore useless */
|
442
|
263 return make_int (GetDeviceCaps (hdc, BITSPIXEL));
|
428
|
264 break;
|
|
265 case DM_num_color_cells:
|
442
|
266 /* #### SIZEPALETTE only valid if RC_PALETTE bit set in RASTERCAPS,
|
|
267 what should we return for a non-palette-based device? */
|
|
268 return make_int (GetDeviceCaps (hdc, SIZEPALETTE));
|
428
|
269 break;
|
|
270
|
|
271 /*** Colors ***/
|
442
|
272 #define FROB(met, fore, back) \
|
428
|
273 case DM_##met: \
|
442
|
274 return build_syscolor_cons (fore, back);
|
|
275
|
|
276 FROB (color_default, COLOR_WINDOWTEXT, COLOR_WINDOW);
|
|
277 FROB (color_select, COLOR_HIGHLIGHTTEXT, COLOR_HIGHLIGHT);
|
|
278 FROB (color_balloon, COLOR_INFOTEXT, COLOR_INFOBK);
|
|
279 FROB (color_3d_face, COLOR_BTNTEXT, COLOR_BTNFACE);
|
|
280 FROB (color_3d_light, COLOR_3DHILIGHT, COLOR_3DLIGHT);
|
|
281 FROB (color_3d_dark, COLOR_3DDKSHADOW, COLOR_3DSHADOW);
|
|
282 FROB (color_menu, COLOR_MENUTEXT, COLOR_MENU);
|
|
283 FROB (color_menu_highlight, COLOR_HIGHLIGHTTEXT, COLOR_HIGHLIGHT);
|
|
284 FROB (color_menu_button, COLOR_MENUTEXT, COLOR_MENU);
|
|
285 FROB (color_menu_disabled, COLOR_GRAYTEXT, COLOR_MENU);
|
|
286 FROB (color_toolbar, COLOR_BTNTEXT, COLOR_BTNFACE);
|
|
287 FROB (color_scrollbar, COLOR_CAPTIONTEXT, COLOR_SCROLLBAR);
|
428
|
288 FROB (color_desktop, -1, COLOR_DESKTOP);
|
|
289 FROB (color_workspace, -1, COLOR_APPWORKSPACE);
|
|
290 #undef FROB
|
|
291
|
|
292 /*** Sizes ***/
|
|
293 #define FROB(met, index1, index2) \
|
|
294 case DM_##met: \
|
|
295 return build_sysmetrics_cons (index1, index2);
|
|
296
|
|
297 FROB (size_cursor, SM_CXCURSOR, SM_CYCURSOR);
|
|
298 FROB (size_scrollbar, SM_CXVSCROLL, SM_CYHSCROLL);
|
|
299 FROB (size_menu, -1, SM_CYMENU);
|
|
300 FROB (size_icon, SM_CXICON, SM_CYICON);
|
|
301 FROB (size_icon_small, SM_CXSMICON, SM_CYSMICON);
|
|
302 #undef FROB
|
|
303
|
|
304 case DM_size_workspace:
|
|
305 {
|
|
306 RECT rc;
|
442
|
307 mswindows_get_workspace_coords (&rc);
|
428
|
308 return Fcons (make_int (rc.right - rc.left),
|
|
309 make_int (rc.bottom - rc.top));
|
|
310 }
|
442
|
311
|
|
312 case DM_offset_workspace:
|
|
313 {
|
|
314 RECT rc;
|
|
315 mswindows_get_workspace_coords (&rc);
|
|
316 return Fcons (make_int (rc.left), make_int (rc.top));
|
|
317 }
|
|
318
|
428
|
319 /*
|
|
320 case DM_size_toolbar:
|
|
321 case DM_size_toolbar_button:
|
|
322 case DM_size_toolbar_border:
|
|
323 */
|
|
324
|
|
325 /*** Features ***/
|
|
326 #define FROB(met, index) \
|
|
327 case DM_##met: \
|
|
328 return make_int (GetSystemMetrics (index));
|
|
329
|
|
330 FROB (mouse_buttons, SM_CMOUSEBUTTONS);
|
|
331 FROB (swap_buttons, SM_SWAPBUTTON);
|
|
332 FROB (show_sounds, SM_SHOWSOUNDS);
|
|
333 FROB (slow_device, SM_SLOWMACHINE);
|
|
334 FROB (security, SM_SECURE);
|
|
335 #undef FROB
|
|
336
|
|
337 }
|
|
338
|
|
339 /* Do not know such property */
|
|
340 return Qunbound;
|
|
341 }
|
|
342
|
|
343
|
|
344 /************************************************************************/
|
442
|
345 /* printer helpers */
|
440
|
346 /************************************************************************/
|
|
347
|
|
348 static void
|
|
349 signal_open_printer_error (struct device *d)
|
|
350 {
|
442
|
351 invalid_operation ("Failed to open printer", DEVICE_CONNECTION (d));
|
|
352 }
|
|
353
|
|
354
|
|
355 /* Helper function */
|
|
356 static int
|
|
357 msprinter_init_device_internal (struct device *d, char* printer_name)
|
|
358 {
|
|
359 DEVICE_MSPRINTER_NAME(d) = xstrdup (printer_name);
|
|
360
|
|
361 if (!OpenPrinter (printer_name, &DEVICE_MSPRINTER_HPRINTER (d), NULL))
|
|
362 {
|
|
363 DEVICE_MSPRINTER_HPRINTER (d) = NULL;
|
|
364 return 0;
|
|
365 }
|
|
366
|
|
367 DEVICE_MSPRINTER_HDC (d) = CreateDC ("WINSPOOL", printer_name,
|
|
368 NULL, NULL);
|
|
369 if (DEVICE_MSPRINTER_HDC (d) == NULL)
|
|
370 return 0;
|
|
371
|
|
372 DEVICE_MSPRINTER_HCDC(d) =
|
|
373 CreateCompatibleDC (DEVICE_MSPRINTER_HDC (d));
|
|
374
|
|
375 DEVICE_CLASS (d) = (GetDeviceCaps (DEVICE_MSPRINTER_HDC (d), BITSPIXEL)
|
|
376 * GetDeviceCaps (DEVICE_MSPRINTER_HDC (d), PLANES)
|
|
377 > 1) ? Qcolor : Qmono;
|
|
378 return 1;
|
440
|
379 }
|
|
380
|
|
381 static void
|
442
|
382 msprinter_delete_device_internal (struct device *d)
|
|
383 {
|
|
384 if (DEVICE_MSPRINTER_HPRINTER (d))
|
|
385 ClosePrinter (DEVICE_MSPRINTER_HPRINTER (d));
|
|
386 if (DEVICE_MSPRINTER_HDC (d))
|
|
387 DeleteDC (DEVICE_MSPRINTER_HDC (d));
|
|
388 if (DEVICE_MSPRINTER_HCDC (d))
|
|
389 DeleteDC (DEVICE_MSPRINTER_HCDC (d));
|
|
390 if (DEVICE_MSPRINTER_NAME (d))
|
|
391 xfree (DEVICE_MSPRINTER_NAME (d));
|
|
392
|
|
393 DEVICE_MSPRINTER_FONTLIST (d) = Qnil;
|
|
394 }
|
|
395
|
|
396 static int
|
|
397 msprinter_reinit_device (struct device *d, char* devname)
|
|
398 {
|
|
399 msprinter_delete_device_internal (d);
|
|
400 return msprinter_init_device_internal (d, devname);
|
|
401 }
|
|
402
|
|
403 Lisp_Object
|
|
404 msprinter_default_printer (void)
|
|
405 {
|
|
406 Extbyte name[666];
|
578
|
407 Bufbyte *nameint;
|
442
|
408
|
|
409 if (GetProfileString (XETEXT ("windows"), XETEXT ("device"), NULL, name,
|
|
410 sizeof (name) / XETCHAR_SIZE) <= 0)
|
|
411 return Qnil;
|
|
412 EXTERNAL_TO_C_STRING (name, nameint, Qmswindows_tstr);
|
|
413
|
|
414 if (name[0] == '\0')
|
|
415 return Qnil;
|
|
416 strtok (name, ",");
|
|
417
|
|
418 return build_string (name);
|
|
419 }
|
|
420
|
|
421
|
|
422 /************************************************************************/
|
|
423 /* printer methods */
|
|
424 /************************************************************************/
|
|
425
|
|
426 static void
|
440
|
427 msprinter_init_device (struct device *d, Lisp_Object props)
|
|
428 {
|
|
429 char* printer_name;
|
442
|
430 DEVMODE *pdm;
|
|
431 size_t dm_size;
|
440
|
432
|
|
433 d->device_data = xnew_and_zero (struct msprinter_device);
|
|
434
|
442
|
435 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1;
|
|
436 DEVICE_MSPRINTER_DEVMODE(d) = Qnil;
|
440
|
437
|
|
438 /* We do not use printer fon list as we do with the display
|
|
439 device. Rather, we allow GDI to pick the closest match to the
|
|
440 display font. */
|
|
441 DEVICE_MSPRINTER_FONTLIST (d) = Qnil;
|
|
442
|
442
|
443 CHECK_STRING (DEVICE_CONNECTION (d));
|
|
444
|
|
445 TO_EXTERNAL_FORMAT (LISP_STRING, DEVICE_CONNECTION (d),
|
|
446 C_STRING_ALLOCA, printer_name,
|
|
447 Qmswindows_tstr);
|
|
448
|
|
449 if (!msprinter_init_device_internal (d, printer_name))
|
|
450 signal_open_printer_error (d);
|
|
451
|
|
452 /* Determine DEVMODE size and store the default DEVMODE */
|
|
453 dm_size = DocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER (d),
|
|
454 printer_name, NULL, NULL, 0);
|
|
455 if (dm_size <= 0)
|
|
456 signal_open_printer_error (d);
|
|
457
|
|
458 pdm = (DEVMODE*) xmalloc (dm_size);
|
552
|
459 if (DocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER(d),
|
|
460 printer_name, pdm,
|
|
461 NULL, DM_OUT_BUFFER) < 0)
|
|
462 signal_open_printer_error (d);
|
442
|
463
|
|
464 assert (DEVMODE_SIZE (pdm) <= dm_size);
|
|
465
|
|
466 DEVICE_MSPRINTER_DEVMODE(d) =
|
|
467 allocate_devmode (pdm, 0, printer_name, d);
|
|
468
|
|
469 }
|
|
470
|
|
471 static void
|
|
472 msprinter_delete_device (struct device *d)
|
|
473 {
|
|
474 if (d->device_data)
|
|
475 {
|
|
476 msprinter_delete_device_internal (d);
|
|
477
|
|
478 /* Disassociate the selected devmode with the device */
|
|
479 if (!NILP (DEVICE_MSPRINTER_DEVMODE (d)))
|
|
480 {
|
|
481 XDEVMODE (DEVICE_MSPRINTER_DEVMODE (d))->device = Qnil;
|
|
482 DEVICE_MSPRINTER_DEVMODE (d) = Qnil;
|
|
483 }
|
|
484
|
|
485 xfree (d->device_data);
|
|
486 }
|
440
|
487 }
|
|
488
|
|
489 static Lisp_Object
|
|
490 msprinter_device_system_metrics (struct device *d,
|
|
491 enum device_metrics m)
|
|
492 {
|
|
493 switch (m)
|
|
494 {
|
|
495 /* Device sizes - pixel and mm */
|
|
496 #define FROB(met, index1, index2) \
|
|
497 case DM_##met: \
|
|
498 return build_devicecaps_cons \
|
|
499 (DEVICE_MSPRINTER_HDC(d), index1, index2);
|
|
500
|
|
501 FROB (size_device, PHYSICALWIDTH, PHYSICALHEIGHT);
|
|
502 FROB (size_device_mm, HORZSIZE, VERTSIZE);
|
|
503 FROB (size_workspace, HORZRES, VERTRES);
|
|
504 FROB (offset_workspace, PHYSICALOFFSETX, PHYSICALOFFSETY);
|
|
505 FROB (device_dpi, LOGPIXELSX, LOGPIXELSY);
|
|
506 #undef FROB
|
|
507
|
|
508 case DM_num_bit_planes:
|
|
509 /* this is what X means by bitplanes therefore we ought to be
|
|
510 consistent. num planes is always 1 under mswindows and
|
|
511 therefore useless */
|
|
512 return make_int (GetDeviceCaps (DEVICE_MSPRINTER_HDC(d), BITSPIXEL));
|
|
513
|
442
|
514 case DM_num_color_cells: /* Printers are non-palette devices */
|
440
|
515 case DM_slow_device: /* Animation would be a really bad idea */
|
|
516 case DM_security: /* Not provided by windows */
|
|
517 return Qzero;
|
|
518 }
|
|
519
|
|
520 /* Do not know such property */
|
|
521 return Qunbound;
|
|
522 }
|
|
523
|
|
524 static void
|
|
525 msprinter_mark_device (struct device *d)
|
|
526 {
|
|
527 mark_object (DEVICE_MSPRINTER_FONTLIST (d));
|
442
|
528 mark_object (DEVICE_MSPRINTER_DEVMODE (d));
|
440
|
529 }
|
|
530
|
|
531
|
|
532 /************************************************************************/
|
442
|
533 /* printer Lisp subroutines */
|
440
|
534 /************************************************************************/
|
|
535
|
442
|
536 static void
|
|
537 global_free_2_maybe (HGLOBAL hg1, HGLOBAL hg2)
|
|
538 {
|
|
539 if (hg1 != NULL)
|
|
540 GlobalFree (hg1);
|
|
541 if (hg2 != NULL)
|
|
542 GlobalFree (hg2);
|
|
543 }
|
|
544
|
|
545 static HGLOBAL
|
|
546 devmode_to_hglobal (Lisp_Devmode *ldm)
|
|
547 {
|
|
548 HGLOBAL hg = GlobalAlloc (GHND, XDEVMODE_SIZE (ldm));
|
|
549 memcpy (GlobalLock (hg), ldm->devmode, XDEVMODE_SIZE (ldm));
|
|
550 GlobalUnlock (hg);
|
|
551 return hg;
|
|
552 }
|
|
553
|
|
554 /* Returns 0 if the printer has been deleted due to a fatal I/O error,
|
|
555 1 otherwise. */
|
|
556 static int
|
|
557 sync_printer_with_devmode (struct device* d, DEVMODE* devmode_in,
|
|
558 DEVMODE* devmode_out, char* devname)
|
440
|
559 {
|
442
|
560 /* Change connection if the device changed */
|
|
561 if (devname != NULL
|
|
562 && stricmp (devname, DEVICE_MSPRINTER_NAME(d)) != 0)
|
|
563 {
|
|
564 Lisp_Object new_connection = build_ext_string (devname, Qmswindows_tstr);
|
|
565 struct gcpro gcpro1;
|
|
566
|
|
567 GCPRO1 (new_connection);
|
|
568 DEVICE_CONNECTION (d) = Qnil;
|
|
569 if (!NILP (Ffind_device (new_connection, Qmsprinter)))
|
|
570 {
|
|
571 /* We are in trouble - second msprinter for the same device.
|
|
572 Nothing wrong on the Windows side, just forge a unique
|
|
573 connection name. Use the memory address of d as a unique
|
|
574 suffix. */
|
593
|
575 Extbyte *new_connext = (Extbyte *) alloca (strlen (devname + 11));
|
442
|
576 sprintf (new_connext, "%s:%X", devname, d->header.uid);
|
|
577 new_connection = build_ext_string (devname, Qmswindows_tstr);
|
|
578 }
|
|
579 DEVICE_CONNECTION (d) = new_connection;
|
|
580 UNGCPRO;
|
|
581
|
|
582 /* Reinitialize printer. The device can pop off in process */
|
|
583 if (!msprinter_reinit_device (d, devname))
|
|
584 {
|
|
585 /* Kaboom! */
|
|
586 delete_device_internal (d, 1, 0, 1);
|
|
587 return 0;
|
|
588 }
|
|
589 }
|
|
590
|
|
591 /* Apply the new devmode to the printer */
|
|
592 DocumentProperties (NULL,
|
|
593 DEVICE_MSPRINTER_HPRINTER(d),
|
|
594 DEVICE_MSPRINTER_NAME(d),
|
|
595 devmode_out, devmode_in,
|
|
596 DM_IN_BUFFER | DM_OUT_BUFFER);
|
440
|
597
|
442
|
598 /* #### ResetDC fails sometimes, Bill only knows why.
|
|
599 The solution below looks more like a workaround to me,
|
|
600 although it might be fine. --kkm */
|
|
601 if (ResetDC (DEVICE_MSPRINTER_HDC (d), devmode_out) == NULL)
|
|
602 {
|
|
603 DeleteDC (DEVICE_MSPRINTER_HDC (d));
|
|
604 DEVICE_MSPRINTER_HDC (d) =
|
|
605 CreateDC ("WINSPOOL", DEVICE_MSPRINTER_NAME(d), NULL, devmode_out);
|
|
606 }
|
|
607
|
|
608 return 1;
|
|
609 }
|
|
610
|
|
611 static void
|
|
612 handle_devmode_changes (Lisp_Devmode *ldm, HGLOBAL hDevNames, HGLOBAL hDevMode)
|
|
613 {
|
|
614 DEVNAMES* devnames = (DEVNAMES*) GlobalLock (hDevNames);
|
|
615 char *new_name = devnames ? (char*)devnames + devnames->wDeviceOffset : NULL;
|
|
616 DEVMODE* devmode = (DEVMODE*) GlobalLock (hDevMode);
|
|
617
|
|
618 /* Size and name may have changed */
|
593
|
619 ldm->devmode = (DEVMODE *) xrealloc (ldm->devmode, DEVMODE_SIZE (devmode));
|
442
|
620 if (new_name)
|
|
621 {
|
|
622 if (ldm->printer_name)
|
|
623 xfree (ldm->printer_name);
|
|
624 ldm->printer_name = xstrdup (new_name);
|
|
625 }
|
440
|
626
|
442
|
627 if (!NILP (ldm->device))
|
|
628 {
|
|
629 /* Apply the new devmode to the printer and get a compete one back */
|
|
630 struct device *d = XDEVICE (ldm->device);
|
|
631 if (!sync_printer_with_devmode (d, devmode, ldm->devmode, new_name))
|
|
632 {
|
|
633 global_free_2_maybe (hDevNames, hDevMode);
|
563
|
634 signal_error (Qio_error, "Printer device initialization I/O error, device deleted", Qunbound);
|
442
|
635 }
|
|
636 }
|
|
637 else
|
|
638 {
|
|
639 /* Just copy the devmode structure */
|
|
640 memcpy (ldm->devmode, devmode, DEVMODE_SIZE (devmode));
|
|
641 }
|
|
642 }
|
440
|
643
|
442
|
644 static void
|
|
645 ensure_not_printing (struct device *d)
|
|
646 {
|
|
647 if (!NILP (DEVICE_FRAME_LIST (d)))
|
|
648 {
|
|
649 Lisp_Object device;
|
|
650 XSETDEVICE (device, d);
|
|
651 invalid_operation ("Cannot change settings while print job is active",
|
|
652 device);
|
|
653 }
|
|
654 }
|
|
655
|
|
656 static Lisp_Devmode *
|
|
657 decode_devmode (Lisp_Object dev)
|
|
658 {
|
|
659 if (DEVMODEP (dev))
|
|
660 return XDEVMODE (dev);
|
|
661 else
|
|
662 {
|
|
663 ensure_not_printing (XDEVICE (dev));
|
|
664 return XDEVMODE (DEVICE_MSPRINTER_DEVMODE (XDEVICE (dev)));
|
|
665 }
|
440
|
666 }
|
|
667
|
|
668 /*
|
442
|
669 * DEV can be either a printer or devmode
|
440
|
670 */
|
442
|
671 static Lisp_Object
|
510
|
672 print_dialog_worker (Lisp_Object dev, DWORD flags)
|
442
|
673 {
|
|
674 Lisp_Devmode *ldm = decode_devmode (dev);
|
|
675 PRINTDLG pd;
|
|
676
|
|
677 memset (&pd, 0, sizeof (pd));
|
|
678 pd.lStructSize = sizeof (pd);
|
|
679 pd.hwndOwner = mswindows_get_selected_frame_hwnd ();
|
|
680 pd.hDevMode = devmode_to_hglobal (ldm);
|
510
|
681 pd.Flags = flags | PD_USEDEVMODECOPIESANDCOLLATE;
|
442
|
682 pd.nMinPage = 0;
|
|
683 pd.nMaxPage = 0xFFFF;
|
|
684
|
|
685 if (!PrintDlg (&pd))
|
|
686 {
|
|
687 global_free_2_maybe (pd.hDevNames, pd.hDevMode);
|
|
688 return Qnil;
|
|
689 }
|
|
690
|
|
691 handle_devmode_changes (ldm, pd.hDevNames, pd.hDevMode);
|
|
692
|
|
693 /* Finally, build the resulting plist */
|
|
694 {
|
|
695 Lisp_Object result = Qnil;
|
|
696 struct gcpro gcpro1;
|
|
697 GCPRO1 (result);
|
|
698
|
|
699 /* Do consing in reverse order.
|
|
700 Number of copies */
|
510
|
701 result = Fcons (Qcopies, Fcons (make_int (pd.nCopies), result));
|
442
|
702
|
|
703 /* Page range */
|
510
|
704 if (pd.Flags & PD_PAGENUMS)
|
442
|
705 {
|
|
706 result = Fcons (Qto_page, Fcons (make_int (pd.nToPage), result));
|
|
707 result = Fcons (Qfrom_page, Fcons (make_int (pd.nFromPage), result));
|
510
|
708 result = Fcons (Qselected_page_button, Fcons (Qpages, result));
|
442
|
709 }
|
510
|
710 else if (pd.Flags & PD_SELECTION)
|
|
711 result = Fcons (Qselected_page_button, Fcons (Qselection, result));
|
|
712 else
|
|
713 result = Fcons (Qselected_page_button, Fcons (Qall, result));
|
442
|
714
|
|
715 /* Device name */
|
510
|
716 result = Fcons (Qname, Fcons (build_ext_string (ldm->printer_name,
|
|
717 Qmswindows_tstr),
|
|
718 result));
|
442
|
719 UNGCPRO;
|
|
720
|
|
721 global_free_2_maybe (pd.hDevNames, pd.hDevMode);
|
|
722 return result;
|
|
723 }
|
|
724 }
|
|
725
|
|
726 Lisp_Object
|
510
|
727 mswindows_handle_print_dialog_box (struct frame *f, Lisp_Object keys)
|
442
|
728 {
|
|
729 Lisp_Object device = Qunbound, settings = Qunbound;
|
510
|
730 DWORD flags = PD_NOSELECTION;
|
442
|
731
|
|
732 {
|
|
733 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
|
734 {
|
|
735 if (EQ (key, Q_device))
|
|
736 {
|
|
737 device = wrap_device (decode_device (value));
|
|
738 CHECK_MSPRINTER_DEVICE (device);
|
|
739 }
|
|
740 else if (EQ (key, Q_printer_settings))
|
|
741 {
|
|
742 CHECK_DEVMODE (value);
|
|
743 settings = value;
|
|
744 }
|
510
|
745 else if (EQ (key, Q_allow_pages))
|
|
746 {
|
|
747 if (NILP (value))
|
|
748 flags |= PD_NOPAGENUMS;
|
|
749 }
|
|
750 else if (EQ (key, Q_allow_selection))
|
442
|
751 {
|
510
|
752 if (!NILP (value))
|
|
753 flags &= ~PD_NOSELECTION;
|
442
|
754 }
|
510
|
755 else if (EQ (key, Q_selected_page_button))
|
442
|
756 {
|
510
|
757 if (EQ (value, Qselection))
|
|
758 flags |= PD_SELECTION;
|
|
759 else if (EQ (value, Qpages))
|
|
760 flags |= PD_PAGENUMS;
|
|
761 else if (!EQ (value, Qall))
|
563
|
762 invalid_constant ("for :selected-page-button", value);
|
442
|
763 }
|
|
764 else
|
563
|
765 invalid_constant ("Unrecognized print-dialog keyword", key);
|
442
|
766 }
|
|
767 }
|
|
768
|
|
769 if ((UNBOUNDP (device) && UNBOUNDP (settings)) ||
|
|
770 (!UNBOUNDP (device) && !UNBOUNDP (settings)))
|
563
|
771 sferror ("Exactly one of :device and :printer-settings must be given",
|
442
|
772 keys);
|
|
773
|
510
|
774 return print_dialog_worker (!UNBOUNDP (device) ? device : settings, flags);
|
442
|
775 }
|
|
776
|
506
|
777 int
|
|
778 mswindows_get_default_margin (Lisp_Object prop)
|
|
779 {
|
|
780 if (EQ (prop, Qleft_margin)) return 1440;
|
|
781 if (EQ (prop, Qright_margin)) return 1440;
|
|
782 if (EQ (prop, Qtop_margin)) return 720;
|
|
783 if (EQ (prop, Qbottom_margin)) return 720;
|
|
784 abort ();
|
|
785 return 0;
|
|
786 }
|
|
787
|
442
|
788 static int
|
|
789 plist_get_margin (Lisp_Object plist, Lisp_Object prop)
|
|
790 {
|
506
|
791 Lisp_Object val =
|
|
792 Fplist_get (plist, prop, make_int (mswindows_get_default_margin (prop)));
|
442
|
793 if (!INTP (val))
|
|
794 invalid_argument ("Margin value must be an integer", val);
|
|
795
|
|
796 return MulDiv (XINT (val), 100, 144);
|
|
797 }
|
|
798
|
|
799 static Lisp_Object
|
|
800 plist_set_margin (Lisp_Object plist, Lisp_Object prop, int margin, int mm_p)
|
|
801 {
|
|
802 Lisp_Object val = make_int (MulDiv (margin, 144, mm_p ? 2450 : 100));
|
|
803 return Fcons (prop, Fcons (val, plist));
|
|
804 }
|
|
805
|
|
806 Lisp_Object
|
|
807 mswindows_handle_page_setup_dialog_box (struct frame *f, Lisp_Object keys)
|
|
808 {
|
|
809 Lisp_Object device = Qunbound, settings = Qunbound;
|
|
810 Lisp_Object plist = Qnil;
|
|
811
|
|
812 {
|
|
813 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
|
814 {
|
|
815 if (EQ (key, Q_device))
|
|
816 {
|
|
817 device = wrap_device (decode_device (value));
|
|
818 CHECK_MSPRINTER_DEVICE (device);
|
|
819 }
|
|
820 else if (EQ (key, Q_printer_settings))
|
|
821 {
|
|
822 CHECK_DEVMODE (value);
|
|
823 settings = value;
|
|
824 }
|
|
825 else if (EQ (key, Q_properties))
|
|
826 {
|
|
827 CHECK_LIST (value);
|
|
828 plist = value;
|
|
829 }
|
|
830 else
|
563
|
831 invalid_constant ("Unrecognized page-setup dialog keyword", key);
|
442
|
832 }
|
|
833 }
|
|
834
|
|
835 if ((UNBOUNDP (device) && UNBOUNDP (settings)) ||
|
|
836 (!UNBOUNDP (device) && !UNBOUNDP (settings)))
|
563
|
837 sferror ("Exactly one of :device and :printer-settings must be given",
|
442
|
838 keys);
|
|
839
|
|
840 if (UNBOUNDP (device))
|
|
841 device = settings;
|
|
842
|
|
843 {
|
|
844 Lisp_Devmode *ldm = decode_devmode (device);
|
|
845 PAGESETUPDLG pd;
|
|
846
|
|
847 memset (&pd, 0, sizeof (pd));
|
|
848 pd.lStructSize = sizeof (pd);
|
|
849 pd.hwndOwner = mswindows_get_selected_frame_hwnd ();
|
|
850 pd.Flags = PSD_MARGINS;
|
|
851 pd.rtMargin.left = plist_get_margin (plist, Qleft_margin);
|
|
852 pd.rtMargin.top = plist_get_margin (plist, Qtop_margin);
|
|
853 pd.rtMargin.right = plist_get_margin (plist, Qright_margin);
|
|
854 pd.rtMargin.bottom = plist_get_margin (plist, Qbottom_margin);
|
|
855 pd.hDevMode = devmode_to_hglobal (ldm);
|
|
856
|
|
857 if (!PageSetupDlg (&pd))
|
|
858 {
|
|
859 global_free_2_maybe (pd.hDevNames, pd.hDevMode);
|
|
860 return Qnil;
|
|
861 }
|
|
862
|
|
863 if (pd.hDevMode)
|
|
864 handle_devmode_changes (ldm, pd.hDevNames, pd.hDevMode);
|
|
865
|
|
866 /* Finally, build the resulting plist */
|
|
867 {
|
|
868 Lisp_Object result = Qnil;
|
|
869 int mm_p = pd.Flags & PSD_INHUNDREDTHSOFMILLIMETERS;
|
|
870 result = plist_set_margin (result, Qbottom_margin, pd.rtMargin.bottom,
|
|
871 mm_p);
|
|
872 result = plist_set_margin (result, Qright_margin, pd.rtMargin.right,
|
|
873 mm_p);
|
|
874 result = plist_set_margin (result, Qtop_margin, pd.rtMargin.top, mm_p);
|
|
875 result = plist_set_margin (result, Qleft_margin, pd.rtMargin.left, mm_p);
|
|
876 return result;
|
|
877 }
|
|
878 }
|
|
879 }
|
|
880
|
|
881 DEFUN ("msprinter-get-settings", Fmsprinter_get_settings, 1, 1, 0, /*
|
|
882 Return the settings object currently used by DEVICE.
|
|
883 The object returned is not a copy, but rather a pointer to the
|
|
884 original one. Use `msprinter-settings-copy' to create a copy of it.
|
|
885 */
|
|
886 (device))
|
|
887 {
|
|
888 struct device *d = decode_device (device);
|
|
889 XSETDEVICE (device, d);
|
|
890 CHECK_MSPRINTER_DEVICE (device);
|
|
891 return DEVICE_MSPRINTER_DEVMODE (d);
|
|
892 }
|
|
893
|
|
894 DEFUN ("msprinter-select-settings", Fmsprinter_select_settings, 2, 2, 0, /*
|
|
895 Select SETTINGS object into a DEVICE.
|
|
896 The settings from the settings object are immediately applied to the
|
|
897 printer, possibly changing even the target printer itself, and all
|
|
898 future changes are applied synchronously to the printer device and the
|
|
899 selected printer object, until a different settings object is selected
|
|
900 into the same printer.
|
|
901
|
|
902 A settings object can be selected to no more than one printer at a time.
|
|
903
|
|
904 If the supplied settings object is not specialized, it is specialized
|
|
905 for the printer immediately upon selection. The object can be
|
|
906 despecialized after it is unselected by calling the function
|
|
907 `msprinter-settings-despecialize'.
|
|
908
|
|
909 Return value is the previously selected settings object.
|
|
910 */
|
|
911 (device, settings))
|
440
|
912 {
|
442
|
913 Lisp_Devmode *ldm;
|
|
914 struct device *d = decode_device (device);
|
|
915
|
|
916 struct gcpro gcpro1;
|
|
917 GCPRO1 (settings);
|
|
918
|
|
919 XSETDEVICE (device, d);
|
|
920 CHECK_MSPRINTER_DEVICE (device);
|
|
921 CHECK_DEVMODE (settings);
|
|
922 ldm = XDEVMODE (settings);
|
|
923
|
|
924 if (!NILP (ldm->device))
|
|
925 invalid_operation ("The object is currently selected into a device",
|
|
926 settings);
|
|
927
|
|
928 /* If the object being selected is de-specialized, then its
|
|
929 size is perhaps not enough to receive the new devmode. We can ask
|
|
930 for printer's devmode size here, because despecialized settings
|
|
931 cannot force switching to a different printer, as they supply no
|
|
932 printer name at all. */
|
|
933 if (ldm->printer_name == NULL)
|
|
934 {
|
|
935 size_t dm_size =
|
|
936 DocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER(d),
|
|
937 DEVICE_MSPRINTER_NAME(d), NULL, NULL, 0);
|
|
938 if (dm_size <= 0)
|
563
|
939 signal_error (Qio_error,
|
|
940 "Unable to specialize settings, printer error",
|
|
941 device);
|
442
|
942
|
|
943 assert (XDEVMODE_SIZE (ldm) <= dm_size);
|
593
|
944 ldm->devmode = (DEVMODE *) xrealloc (ldm->devmode, dm_size);
|
442
|
945 }
|
|
946
|
|
947 /* If we bail out on signal here, no damage is done, except that
|
|
948 the storage for the DEVMODE structure might be reallocated to
|
|
949 hold a larger one - not a big deal */
|
|
950 if (!sync_printer_with_devmode (d, ldm->devmode, ldm->devmode,
|
|
951 ldm->printer_name))
|
563
|
952 signal_error (Qio_error,
|
|
953 "Printer device initialization I/O error, device deleted",
|
|
954 Qunbound);
|
442
|
955
|
|
956 if (ldm->printer_name == NULL)
|
|
957 ldm->printer_name = xstrdup (DEVICE_MSPRINTER_NAME(d));
|
|
958
|
|
959 {
|
|
960 Lisp_Object old_mode = DEVICE_MSPRINTER_DEVMODE (d);
|
|
961 ldm->device = device;
|
|
962 XDEVMODE (old_mode)->device = Qnil;
|
|
963 DEVICE_MSPRINTER_DEVMODE (d) = settings;
|
|
964 UNGCPRO;
|
|
965 return old_mode;
|
|
966 }
|
|
967 }
|
|
968
|
|
969 DEFUN ("msprinter-apply-settings", Fmsprinter_apply_settings, 2, 2, 0, /*
|
|
970 Apply settings from a SETTINGS object to a 'msprinter DEVICE.
|
|
971 The settings from the settings object are immediately applied to the
|
|
972 printer, possibly changing even the target printer itself. The SETTING
|
|
973 object is not modified, unlike `msprinter-select-settings', and the
|
|
974 supplied object is not changed. The changes are immediately recorded
|
|
975 into the settings object which is currently selected into the printer
|
|
976 device.
|
|
977
|
|
978 Return value is the currently selected settings object.
|
|
979 */
|
|
980 (device, settings))
|
|
981 {
|
|
982 Lisp_Devmode *ldm_current, *ldm_new;
|
|
983 struct device *d = decode_device (device);
|
|
984
|
|
985 struct gcpro gcpro1;
|
|
986 GCPRO1 (settings);
|
|
987
|
|
988 XSETDEVICE (device, d);
|
|
989 CHECK_MSPRINTER_DEVICE (device);
|
|
990 CHECK_DEVMODE (settings);
|
|
991 ldm_new = XDEVMODE (settings);
|
|
992 ldm_current = XDEVMODE (DEVICE_MSPRINTER_DEVMODE (d));
|
|
993
|
|
994 /* If the supplied devmode is not specialized, then the current
|
|
995 devmode size will always be sufficient, as the printer does
|
|
996 not change. If it is specialized, we must reallocate the current
|
|
997 devmode storage to match with the supplied one, as it has the right
|
|
998 size for the new printer, if it is going to change. The correct
|
|
999 way is to use the largest of the two though, to keep the old
|
|
1000 contents unchanged in case of preliminary exit.
|
|
1001 */
|
|
1002 if (ldm_new->printer_name)
|
|
1003 ldm_current->devmode =
|
|
1004 (DEVMODE*) xrealloc (ldm_current->devmode,
|
|
1005 max (XDEVMODE_SIZE (ldm_new),
|
|
1006 XDEVMODE_SIZE (ldm_current)));
|
|
1007
|
|
1008 if (!sync_printer_with_devmode (d, ldm_new->devmode,
|
|
1009 ldm_current->devmode,
|
|
1010 ldm_new->printer_name))
|
563
|
1011 signal_error (Qio_error,
|
|
1012 "Printer device initialization I/O error, device deleted",
|
|
1013 Qunbound);
|
442
|
1014
|
|
1015 if (ldm_new->printer_name != NULL)
|
|
1016 {
|
|
1017 xfree (ldm_current->printer_name);
|
|
1018 ldm_current->printer_name = xstrdup (ldm_new->printer_name);
|
|
1019 }
|
|
1020
|
446
|
1021 UNGCPRO;
|
442
|
1022 return DEVICE_MSPRINTER_DEVMODE (d);
|
|
1023 }
|
|
1024
|
|
1025 /************************************************************************/
|
|
1026 /* devmode */
|
|
1027 /************************************************************************/
|
|
1028
|
|
1029 static void
|
|
1030 print_devmode (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1031 int escapeflag)
|
|
1032 {
|
|
1033 char buf[100];
|
|
1034 Lisp_Devmode *dm = XDEVMODE (obj);
|
|
1035 if (print_readably)
|
563
|
1036 printing_unreadable_object ("#<msprinter-settings 0x%x>",
|
|
1037 dm->header.uid);
|
442
|
1038 write_c_string ("#<msprinter-settings", printcharfun);
|
|
1039 if (dm->printer_name)
|
|
1040 {
|
|
1041 write_c_string (" for \"", printcharfun);
|
|
1042 write_c_string (dm->printer_name, printcharfun);
|
|
1043 write_c_string ("\"", printcharfun);
|
|
1044 }
|
|
1045 if (!NILP (dm->device))
|
|
1046 {
|
|
1047 write_c_string (" (currently on ", printcharfun);
|
|
1048 print_internal (dm->device, printcharfun, 0);
|
|
1049 write_c_string (")", printcharfun);
|
|
1050 }
|
|
1051 sprintf (buf, " 0x%x>", dm->header.uid);
|
|
1052 write_c_string (buf, printcharfun);
|
|
1053 }
|
|
1054
|
|
1055 static void
|
|
1056 finalize_devmode (void *header, int for_disksave)
|
|
1057 {
|
|
1058 Lisp_Devmode *dm = (Lisp_Devmode *) header;
|
|
1059
|
|
1060 if (for_disksave)
|
|
1061 {
|
|
1062 Lisp_Object devmode;
|
|
1063 XSETDEVMODE (devmode, dm);
|
|
1064 invalid_operation
|
|
1065 ("Cannot dump XEmacs containing an msprinter-settings object",
|
|
1066 devmode);
|
|
1067 }
|
|
1068
|
|
1069 assert (NILP (dm->device));
|
|
1070
|
|
1071 if (dm->printer_name)
|
|
1072 xfree (dm->printer_name);
|
|
1073 }
|
|
1074
|
|
1075 static int
|
|
1076 equal_devmode (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
1077 {
|
|
1078 Lisp_Devmode *dm1 = XDEVMODE (obj1);
|
|
1079 Lisp_Devmode *dm2 = XDEVMODE (obj2);
|
440
|
1080
|
442
|
1081 if ((dm1->devmode != NULL) != (dm1->devmode != NULL))
|
|
1082 return 0;
|
|
1083 if (dm1->devmode == NULL)
|
|
1084 return 1;
|
|
1085 if (memcmp (dm1->devmode, dm2->devmode, XDEVMODE_SIZE (dm1)) != 0)
|
|
1086 return 0;
|
|
1087 if (dm1->printer_name == NULL || dm2->printer_name == NULL)
|
|
1088 return 1;
|
|
1089 return stricmp (dm1->printer_name, dm2->printer_name) == 0;
|
|
1090 }
|
|
1091
|
|
1092 static unsigned long
|
|
1093 hash_devmode (Lisp_Object obj, int depth)
|
|
1094 {
|
|
1095 Lisp_Devmode *dm = XDEVMODE (obj);
|
|
1096
|
|
1097 return HASH3 (XDEVMODE_SIZE (dm),
|
|
1098 dm->devmode ? memory_hash (dm->devmode, XDEVMODE_SIZE (dm))
|
|
1099 : 0,
|
|
1100 dm->printer_name ? string_hash (dm->printer_name) : 0);
|
|
1101 }
|
|
1102
|
|
1103 DEFINE_LRECORD_IMPLEMENTATION ("msprinter-settings", devmode,
|
|
1104 0/*mark*/, print_devmode, finalize_devmode,
|
|
1105 equal_devmode, hash_devmode, 0/*description*/,
|
|
1106 Lisp_Devmode);
|
|
1107 static Lisp_Object
|
|
1108 allocate_devmode (DEVMODE* src_devmode, int do_copy,
|
|
1109 char* src_name, struct device *d)
|
|
1110 {
|
|
1111 Lisp_Devmode *dm;
|
|
1112 Lisp_Object ob;
|
|
1113
|
|
1114 dm = alloc_lcrecord_type (Lisp_Devmode, &lrecord_devmode);
|
|
1115
|
|
1116 if (d)
|
|
1117 XSETDEVICE (dm->device, d);
|
|
1118 else
|
|
1119 dm->device = Qnil;
|
|
1120
|
|
1121 dm->printer_name = src_name ? xstrdup (src_name) : NULL;
|
|
1122
|
|
1123 if (src_devmode != NULL && do_copy)
|
|
1124 {
|
|
1125 dm->devmode = (DEVMODE*) xmalloc (DEVMODE_SIZE (src_devmode));
|
|
1126 memcpy (dm->devmode, src_devmode, DEVMODE_SIZE (src_devmode));
|
|
1127 }
|
|
1128 else
|
|
1129 {
|
|
1130 dm->devmode = src_devmode;
|
|
1131 }
|
|
1132
|
|
1133 XSETDEVMODE (ob, dm);
|
|
1134 return ob;
|
|
1135 }
|
|
1136
|
|
1137 DEFUN ("msprinter-settings-copy", Fmsprinter_settings_copy, 1, 1, 0, /*
|
|
1138 Create and returns an exact copy of a printer settings object.
|
|
1139 */
|
|
1140 (settings))
|
|
1141 {
|
|
1142 Lisp_Devmode *dm;
|
|
1143
|
|
1144 CHECK_DEVMODE (settings);
|
|
1145 dm = XDEVMODE (settings);
|
|
1146
|
|
1147 return allocate_devmode (dm->devmode, 1, dm->printer_name, NULL);
|
|
1148 }
|
|
1149
|
|
1150 DEFUN ("msprinter-settings-despecialize", Fmsprinter_settings_despecialize, 1, 1, 0, /*
|
|
1151 Erase printer-specific settings from a printer settings object.
|
|
1152 */
|
|
1153 (settings))
|
|
1154 {
|
|
1155 Lisp_Devmode *ldm;
|
|
1156 DEVMODE *dm;
|
|
1157
|
|
1158 CHECK_DEVMODE (settings);
|
|
1159 ldm = XDEVMODE (settings);
|
|
1160
|
|
1161 if (!NILP (ldm->device))
|
|
1162 invalid_operation ("The object is currently selected into a device",
|
|
1163 settings);
|
|
1164
|
|
1165 dm = ldm->devmode;
|
|
1166
|
|
1167 /* #### TODO. Either remove references to device specific bins,
|
|
1168 paper sizes etc, or signal an error of they are present. */
|
440
|
1169
|
442
|
1170 dm->dmDriverExtra = 0;
|
|
1171 dm->dmDeviceName[0] = '\0';
|
|
1172
|
|
1173 if (ldm->printer_name)
|
|
1174 xfree (ldm->printer_name);
|
|
1175
|
|
1176 return Qnil;
|
|
1177 }
|
|
1178
|
|
1179 DEFUN ("mswindows-get-default-printer", Fmswindows_get_default_printer, 0, 0, 0, /*
|
|
1180 Return name of the default printer, as string, on nil if there is no default.
|
|
1181 */
|
|
1182 ())
|
|
1183 {
|
|
1184 return msprinter_default_printer ();
|
|
1185 }
|
|
1186
|
|
1187 static void
|
|
1188 signal_enum_printer_error (void)
|
|
1189 {
|
|
1190 invalid_operation ("Error enumerating printers", make_int (GetLastError ()));
|
|
1191 }
|
|
1192
|
|
1193 DEFUN ("mswindows-printer-list", Fmswindows_printer_list, 0, 0, 0, /*
|
|
1194 Return a list of string names of installed printers.
|
|
1195 If there is a default printer, it is returned as the first element of
|
|
1196 the list. If there is no default printer, the first element of the
|
|
1197 list will be nil. The rest of elements are guaranteed to have string
|
|
1198 values. Return value is nil if there are no printers installed.
|
|
1199 */
|
|
1200 ())
|
|
1201 {
|
|
1202 int have_nt, ok;
|
|
1203 BYTE *data_buf, dummy_byte;
|
|
1204 size_t enum_entry_size;
|
|
1205 DWORD enum_flags, enum_level, bytes_needed, num_printers;
|
|
1206 struct gcpro gcpro1, gcpro2;
|
|
1207 Lisp_Object result = Qnil, def_printer = Qnil;
|
|
1208
|
|
1209 /* Determine OS flavor, to use the fastest enumeration method available */
|
|
1210 have_nt = !mswindows_windows9x_p ();
|
|
1211 enum_flags = PRINTER_ENUM_LOCAL | (have_nt ? PRINTER_ENUM_CONNECTIONS : 0);
|
|
1212 enum_level = have_nt ? 4 : 5;
|
|
1213 enum_entry_size = have_nt ? sizeof (PRINTER_INFO_4) : sizeof (PRINTER_INFO_5);
|
|
1214
|
|
1215 /* Allocate memory for printer enum structure */
|
|
1216 ok = EnumPrinters (enum_flags, NULL, enum_level, &dummy_byte, 1,
|
|
1217 &bytes_needed, &num_printers);
|
|
1218 if (ok)
|
|
1219 /* No printers, if just 1 byte is enough */
|
|
1220 return Qnil;
|
|
1221
|
|
1222 if (GetLastError () != ERROR_INSUFFICIENT_BUFFER)
|
|
1223 signal_enum_printer_error ();
|
|
1224
|
593
|
1225 data_buf = (BYTE *) alloca (bytes_needed);
|
442
|
1226 ok = EnumPrinters (enum_flags, NULL, enum_level, data_buf, bytes_needed,
|
|
1227 &bytes_needed, &num_printers);
|
|
1228 if (!ok)
|
|
1229 signal_enum_printer_error ();
|
|
1230
|
|
1231 if (num_printers == 0)
|
|
1232 /* Strange but... */
|
|
1233 return Qnil;
|
|
1234
|
|
1235 GCPRO2 (result, def_printer);
|
|
1236
|
|
1237 while (num_printers--)
|
|
1238 {
|
|
1239 LPCTSTR printer_name;
|
|
1240 if (have_nt)
|
|
1241 {
|
|
1242 PRINTER_INFO_4 *info = (PRINTER_INFO_4*) data_buf;
|
|
1243 printer_name = info->pPrinterName;
|
|
1244 }
|
|
1245 else
|
|
1246 {
|
|
1247 PRINTER_INFO_5 *info = (PRINTER_INFO_5*) data_buf;
|
|
1248 printer_name = info->pPrinterName;
|
|
1249 }
|
|
1250 data_buf += enum_entry_size;
|
|
1251
|
|
1252 result = Fcons (build_ext_string (printer_name, Qmswindows_tstr),
|
|
1253 result);
|
|
1254 }
|
|
1255
|
|
1256 def_printer = msprinter_default_printer ();
|
|
1257 result = Fdelete (def_printer, result);
|
|
1258 result = Fcons (def_printer, result);
|
|
1259
|
|
1260 RETURN_UNGCPRO (result);
|
440
|
1261 }
|
|
1262
|
|
1263
|
|
1264 /************************************************************************/
|
428
|
1265 /* initialization */
|
|
1266 /************************************************************************/
|
|
1267
|
|
1268 void
|
|
1269 syms_of_device_mswindows (void)
|
|
1270 {
|
442
|
1271 INIT_LRECORD_IMPLEMENTATION (devmode);
|
|
1272
|
|
1273 DEFSUBR (Fmsprinter_get_settings);
|
|
1274 DEFSUBR (Fmsprinter_select_settings);
|
|
1275 DEFSUBR (Fmsprinter_apply_settings);
|
|
1276 DEFSUBR (Fmsprinter_settings_copy);
|
|
1277 DEFSUBR (Fmsprinter_settings_despecialize);
|
|
1278 DEFSUBR (Fmswindows_get_default_printer);
|
|
1279 DEFSUBR (Fmswindows_printer_list);
|
|
1280
|
510
|
1281 DEFKEYWORD (Q_allow_selection);
|
|
1282 DEFKEYWORD (Q_allow_pages);
|
|
1283 DEFKEYWORD (Q_selected_page_button);
|
|
1284 DEFSYMBOL (Qselected_page_button);
|
|
1285
|
|
1286 DEFSYMBOL (Qinit_pre_mswindows_win);
|
|
1287 DEFSYMBOL (Qinit_post_mswindows_win);
|
428
|
1288 }
|
|
1289
|
|
1290 void
|
|
1291 console_type_create_device_mswindows (void)
|
|
1292 {
|
|
1293 CONSOLE_HAS_METHOD (mswindows, init_device);
|
|
1294 CONSOLE_HAS_METHOD (mswindows, finish_init_device);
|
440
|
1295 CONSOLE_HAS_METHOD (mswindows, mark_device);
|
428
|
1296 CONSOLE_HAS_METHOD (mswindows, delete_device);
|
|
1297 CONSOLE_HAS_METHOD (mswindows, device_system_metrics);
|
545
|
1298 CONSOLE_IMPLEMENTATION_FLAGS (mswindows, XDEVIMPF_PIXEL_GEOMETRY);
|
440
|
1299
|
|
1300 CONSOLE_HAS_METHOD (msprinter, init_device);
|
|
1301 CONSOLE_HAS_METHOD (msprinter, mark_device);
|
|
1302 CONSOLE_HAS_METHOD (msprinter, delete_device);
|
|
1303 CONSOLE_HAS_METHOD (msprinter, device_system_metrics);
|
545
|
1304 CONSOLE_IMPLEMENTATION_FLAGS (msprinter, (XDEVIMPF_PIXEL_GEOMETRY
|
|
1305 | XDEVIMPF_IS_A_PRINTER
|
|
1306 | XDEVIMPF_NO_AUTO_REDISPLAY
|
|
1307 | XDEVIMPF_DONT_PREEMPT_REDISPLAY
|
|
1308 | XDEVIMPF_FRAMELESS_OK));
|
428
|
1309 }
|
|
1310
|
440
|
1311
|
428
|
1312 void
|
|
1313 vars_of_device_mswindows (void)
|
|
1314 {
|
|
1315 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*
|
|
1316 Non-nil means convert all-upper case file names to lower case.
|
|
1317 This applies when performing completions and file name expansion.
|
|
1318 */ );
|
|
1319 Vmswindows_downcase_file_names = Qnil;
|
|
1320
|
|
1321 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /*
|
|
1322 Non-nil means determine accurate link count in file-attributes.
|
|
1323 This option slows down file-attributes noticeably, so is disabled by
|
|
1324 default. Note that it is only useful for files on NTFS volumes,
|
|
1325 where hard links are supported.
|
|
1326 */ );
|
|
1327 Vmswindows_get_true_file_attributes = Qnil;
|
|
1328 }
|