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