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