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