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