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