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