Mercurial > hg > xemacs-beta
annotate src/device-msw.c @ 5118:e0db3c197671 ben-lisp-object
merge up to latest default branch, doesn't compile yet
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sat, 26 Dec 2009 21:18:49 -0600 |
parents | 3742ea8250b5 e34711681f30 |
children | d1247f3cc363 |
rev | line source |
---|---|
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 | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
63 Lisp_Object Qmake_device_early_mswindows_entry_point, |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
64 Qmake_device_late_mswindows_entry_point; |
442 | 65 Lisp_Object Qdevmodep; |
428 | 66 |
510 | 67 static Lisp_Object Q_allow_selection; |
68 static Lisp_Object Q_allow_pages; | |
69 static Lisp_Object Q_selected_page_button; | |
70 static Lisp_Object Qselected_page_button; | |
71 | |
1204 | 72 static const struct memory_description mswindows_device_data_description_1 [] = { |
73 { XD_LISP_OBJECT, offsetof (struct mswindows_device, fontlist) }, | |
74 { XD_END } | |
75 }; | |
76 | |
3092 | 77 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
78 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("mswindows-device", mswindows_device, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
79 0, mswindows_device_data_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
80 Lisp_Mswindows_Device); |
3092 | 81 #else /* not NEW_GC */ |
1204 | 82 extern const struct sized_memory_description mswindows_device_data_description; |
83 | |
84 const struct sized_memory_description mswindows_device_data_description = { | |
85 sizeof (struct mswindows_device), mswindows_device_data_description_1 | |
86 }; | |
3092 | 87 #endif /* not NEW_GC */ |
1204 | 88 |
1346 | 89 static const struct memory_description msprinter_device_data_description_1 [] = { |
90 { XD_LISP_OBJECT, offsetof (struct msprinter_device, name) }, | |
91 { XD_LISP_OBJECT, offsetof (struct msprinter_device, devmode) }, | |
92 { XD_LISP_OBJECT, offsetof (struct msprinter_device, fontlist) }, | |
93 { XD_END } | |
94 }; | |
95 | |
3092 | 96 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
97 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("msprinter-device", msprinter_device, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
98 0, msprinter_device_data_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
99 Lisp_Msprinter_Device); |
3092 | 100 #else /* not NEW_GC */ |
1346 | 101 extern const struct sized_memory_description msprinter_device_data_description; |
102 | |
103 const struct sized_memory_description msprinter_device_data_description = { | |
104 sizeof (struct msprinter_device), msprinter_device_data_description_1 | |
105 }; | |
3092 | 106 #endif /* not NEW_GC */ |
1346 | 107 |
771 | 108 static Lisp_Object allocate_devmode (DEVMODEW *src_devmode, int do_copy, |
109 Lisp_Object src_name, struct device *d); | |
428 | 110 |
111 /************************************************************************/ | |
112 /* helpers */ | |
113 /************************************************************************/ | |
114 | |
115 static Lisp_Object | |
440 | 116 build_syscolor_string (int idx) |
428 | 117 { |
442 | 118 return (idx < 0 ? Qnil : mswindows_color_to_string (GetSysColor (idx))); |
428 | 119 } |
120 | |
121 static Lisp_Object | |
122 build_syscolor_cons (int index1, int index2) | |
123 { | |
124 Lisp_Object color1, color2; | |
125 struct gcpro gcpro1; | |
126 GCPRO1 (color1); | |
127 color1 = build_syscolor_string (index1); | |
128 color2 = build_syscolor_string (index2); | |
129 RETURN_UNGCPRO (Fcons (color1, color2)); | |
130 } | |
131 | |
132 static Lisp_Object | |
133 build_sysmetrics_cons (int index1, int index2) | |
134 { | |
135 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)), | |
136 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2))); | |
137 } | |
138 | |
440 | 139 static Lisp_Object |
140 build_devicecaps_cons (HDC hdc, int index1, int index2) | |
141 { | |
142 return Fcons (index1 < 0 ? Qnil : make_int (GetDeviceCaps (hdc, index1)), | |
143 index2 < 0 ? Qnil : make_int (GetDeviceCaps (hdc, index2))); | |
144 } | |
145 | |
428 | 146 |
147 /************************************************************************/ | |
440 | 148 /* display methods */ |
428 | 149 /************************************************************************/ |
150 | |
151 static void | |
2286 | 152 mswindows_init_device (struct device *d, Lisp_Object UNUSED (props)) |
428 | 153 { |
154 HDC hdc; | |
771 | 155 WNDCLASSEXW wc; |
428 | 156 |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
157 call0 (Qmake_device_early_mswindows_entry_point); |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
158 |
428 | 159 DEVICE_CLASS (d) = Qcolor; |
160 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1; | |
161 init_baud_rate (d); | |
162 init_one_device (d); | |
163 | |
3092 | 164 #ifdef NEW_GC |
165 d->device_data = alloc_lrecord_type (struct mswindows_device, | |
166 &lrecord_mswindows_device); | |
167 #else /* not NEW_GC */ | |
428 | 168 d->device_data = xnew_and_zero (struct mswindows_device); |
3092 | 169 #endif /* not NEW_GC */ |
428 | 170 hdc = CreateCompatibleDC (NULL); |
771 | 171 assert (hdc != NULL); |
172 DEVICE_MSWINDOWS_HCDC (d) = hdc; | |
440 | 173 DEVICE_MSWINDOWS_FONTLIST (d) = mswindows_enumerate_fonts (hdc); |
442 | 174 DEVICE_MSWINDOWS_UPDATE_TICK (d) = GetTickCount (); |
428 | 175 |
176 /* Register the main window class */ | |
771 | 177 wc.cbSize = sizeof (wc); |
428 | 178 wc.style = CS_OWNDC; /* One DC per window */ |
179 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc; | |
180 wc.cbClsExtra = 0; | |
181 wc.cbWndExtra = MSWINDOWS_WINDOW_EXTRA_BYTES; | |
182 /* This must match whatever is passed to CreateWIndowEx, NULL is ok | |
183 for this. */ | |
771 | 184 wc.hInstance = NULL; |
185 wc.hIcon = qxeLoadIcon (qxeGetModuleHandle (NULL), XETEXT (XEMACS_CLASS)); | |
186 wc.hCursor = qxeLoadCursor (NULL, IDC_ARROW); | |
428 | 187 /* Background brush is only used during sizing, when XEmacs cannot |
188 take over */ | |
771 | 189 wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1); |
428 | 190 wc.lpszMenuName = NULL; |
191 | |
771 | 192 wc.lpszClassName = (XELPTSTR) XETEXT (XEMACS_CLASS); |
193 wc.hIconSm = (HICON) qxeLoadImage (qxeGetModuleHandle (NULL), | |
194 XETEXT (XEMACS_CLASS), | |
195 IMAGE_ICON, 16, 16, 0); | |
196 qxeRegisterClassEx (&wc); | |
428 | 197 |
198 #ifdef HAVE_WIDGETS | |
199 xzero (wc); | |
200 /* Register the main window class */ | |
771 | 201 wc.cbSize = sizeof (wc); |
428 | 202 wc.lpfnWndProc = (WNDPROC) mswindows_control_wnd_proc; |
771 | 203 wc.lpszClassName = (XELPTSTR) XETEXT (XEMACS_CONTROL_CLASS); |
428 | 204 wc.hInstance = NULL; |
771 | 205 qxeRegisterClassEx (&wc); |
428 | 206 #endif |
207 | |
440 | 208 #if defined (HAVE_TOOLBARS) || defined (HAVE_WIDGETS) |
428 | 209 InitCommonControls (); |
210 #endif | |
211 } | |
212 | |
657 | 213 #ifdef HAVE_DRAGNDROP |
428 | 214 static void |
771 | 215 mswindows_init_dde (void) |
428 | 216 { |
217 /* Initialize DDE management library and our related globals. We execute a | |
771 | 218 * dde Open ("file") by simulating a drop, so this depends on dnd support. */ |
442 | 219 |
428 | 220 mswindows_dde_mlid = 0; |
659 | 221 mswindows_dde_enable = 0; |
771 | 222 qxeDdeInitialize (&mswindows_dde_mlid, (PFNCALLBACK)mswindows_dde_callback, |
903 | 223 APPCMD_FILTERINITS|CBF_FAIL_SELFCONNECTIONS| |
224 CBF_FAIL_POKES|CBF_SKIP_ALLNOTIFICATIONS, | |
771 | 225 0); |
226 | |
227 mswindows_dde_service = | |
228 qxeDdeCreateStringHandle (mswindows_dde_mlid, | |
229 XETEXT (XEMACS_CLASS), | |
230 XEUNICODE_P ? CP_WINUNICODE : CP_WINANSI); | |
231 /* The following strings we Unicode-ize ourselves: | |
232 -- SZDDESYS_TOPIC is system-provided | |
903 | 233 -- MSWINDOWS_DDE_TOPIC_EVAL is defined by us |
234 -- MSWINDOWS_DDE_ITEM_RESULT is defined by us | |
771 | 235 -- MSWINDOWS_DDE_ITEM_OPEN is used in internal-format comparisons |
236 */ | |
237 mswindows_dde_topic_system = | |
238 qxeDdeCreateStringHandle (mswindows_dde_mlid, | |
239 XETEXT (SZDDESYS_TOPIC), | |
240 XEUNICODE_P ? CP_WINUNICODE : CP_WINANSI); | |
903 | 241 mswindows_dde_topic_eval = |
242 qxeDdeCreateStringHandle (mswindows_dde_mlid, | |
243 XETEXT (MSWINDOWS_DDE_TOPIC_EVAL), | |
244 XEUNICODE_P ? CP_WINUNICODE : CP_WINANSI); | |
245 mswindows_dde_item_result = | |
246 qxeDdeCreateStringHandle (mswindows_dde_mlid, | |
247 XETEXT (MSWINDOWS_DDE_ITEM_RESULT), | |
248 XEUNICODE_P ? CP_WINUNICODE : CP_WINANSI); | |
771 | 249 mswindows_dde_item_open = |
250 qxeDdeCreateStringHandle (mswindows_dde_mlid, | |
251 XETEXT (MSWINDOWS_DDE_ITEM_OPEN), | |
252 XEUNICODE_P ? CP_WINUNICODE : CP_WINANSI); | |
428 | 253 DdeNameService (mswindows_dde_mlid, mswindows_dde_service, 0L, DNS_REGISTER); |
657 | 254 } |
771 | 255 #endif /* HAVE_DRAGNDROP */ |
657 | 256 |
257 void | |
771 | 258 init_mswindows_dde_very_early (void) |
657 | 259 { |
771 | 260 #if !defined (NO_CYGWIN_COM_SUPPORT) |
261 /* Needed by SHBrowseForFolder, so do it always */ | |
262 CoInitialize (NULL); | |
263 #endif | |
264 | |
657 | 265 #ifdef HAVE_DRAGNDROP |
266 /* Initializing dde when the device is created is too late - the | |
267 client will give up waiting. Instead we initialize here and tell | |
268 the client we're too busy until the rest of initialization has | |
269 happened. */ | |
771 | 270 mswindows_init_dde (); |
657 | 271 #endif |
272 } | |
273 | |
274 static void | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
275 mswindows_finish_init_device (struct device *d, |
2286 | 276 Lisp_Object UNUSED (props)) |
657 | 277 { |
278 #ifdef HAVE_DRAGNDROP | |
279 /* Tell pending clients we are ready. */ | |
280 mswindows_dde_enable = 1; | |
428 | 281 #endif |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
282 call1 (Qmake_device_late_mswindows_entry_point, wrap_device(d)); |
428 | 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 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1208 DEFINE_NODUMP_LISP_OBJECT ("msprinter-settings", devmode, |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1209 mark_devmode, print_devmode, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1210 finalize_devmode, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1211 equal_devmode, hash_devmode, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1212 devmode_description, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1213 Lisp_Devmode); |
934 | 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 { |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1219 Lisp_Object obj = ALLOC_LISP_OBJECT (devmode); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1220 Lisp_Devmode *dm = XDEVMODE (obj); |
442 | 1221 |
1222 if (d) | |
793 | 1223 dm->device = wrap_device (d); |
442 | 1224 else |
1225 dm->device = Qnil; | |
1226 | |
771 | 1227 dm->printer_name = src_name; |
442 | 1228 |
1229 if (src_devmode != NULL && do_copy) | |
1230 { | |
771 | 1231 dm->devmode = (DEVMODEW*) xmalloc (DEVMODE_SIZE (src_devmode)); |
442 | 1232 memcpy (dm->devmode, src_devmode, DEVMODE_SIZE (src_devmode)); |
1233 } | |
1234 else | |
1235 { | |
1236 dm->devmode = src_devmode; | |
1237 } | |
1238 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1239 return obj; |
442 | 1240 } |
1241 | |
1242 DEFUN ("msprinter-settings-copy", Fmsprinter_settings_copy, 1, 1, 0, /* | |
1243 Create and returns an exact copy of a printer settings object. | |
1244 */ | |
1245 (settings)) | |
1246 { | |
1247 Lisp_Devmode *dm; | |
1248 | |
1249 CHECK_DEVMODE (settings); | |
1250 dm = XDEVMODE (settings); | |
1251 | |
1252 return allocate_devmode (dm->devmode, 1, dm->printer_name, NULL); | |
1253 } | |
1254 | |
1255 DEFUN ("msprinter-settings-despecialize", Fmsprinter_settings_despecialize, 1, 1, 0, /* | |
1256 Erase printer-specific settings from a printer settings object. | |
1257 */ | |
1258 (settings)) | |
1259 { | |
1260 Lisp_Devmode *ldm; | |
771 | 1261 DEVMODEW *dm; |
442 | 1262 |
1263 CHECK_DEVMODE (settings); | |
1264 ldm = XDEVMODE (settings); | |
1265 | |
1266 if (!NILP (ldm->device)) | |
1267 invalid_operation ("The object is currently selected into a device", | |
1268 settings); | |
1269 | |
1270 dm = ldm->devmode; | |
1271 | |
1272 /* #### TODO. Either remove references to device specific bins, | |
1273 paper sizes etc, or signal an error of they are present. */ | |
440 | 1274 |
442 | 1275 dm->dmDriverExtra = 0; |
1276 dm->dmDeviceName[0] = '\0'; | |
1277 | |
771 | 1278 ldm->printer_name = Qnil; |
442 | 1279 |
1280 return Qnil; | |
1281 } | |
1282 | |
1283 DEFUN ("mswindows-get-default-printer", Fmswindows_get_default_printer, 0, 0, 0, /* | |
1284 Return name of the default printer, as string, on nil if there is no default. | |
1285 */ | |
1286 ()) | |
1287 { | |
1288 return msprinter_default_printer (); | |
1289 } | |
1290 | |
1291 static void | |
1292 signal_enum_printer_error (void) | |
1293 { | |
1294 invalid_operation ("Error enumerating printers", make_int (GetLastError ())); | |
1295 } | |
1296 | |
1297 DEFUN ("mswindows-printer-list", Fmswindows_printer_list, 0, 0, 0, /* | |
1298 Return a list of string names of installed printers. | |
1299 If there is a default printer, it is returned as the first element of | |
1300 the list. If there is no default printer, the first element of the | |
1301 list will be nil. The rest of elements are guaranteed to have string | |
1302 values. Return value is nil if there are no printers installed. | |
1303 */ | |
1304 ()) | |
1305 { | |
1306 int have_nt, ok; | |
1307 BYTE *data_buf, dummy_byte; | |
665 | 1308 Bytecount enum_entry_size; |
442 | 1309 DWORD enum_flags, enum_level, bytes_needed, num_printers; |
1310 struct gcpro gcpro1, gcpro2; | |
1311 Lisp_Object result = Qnil, def_printer = Qnil; | |
1312 | |
1313 /* Determine OS flavor, to use the fastest enumeration method available */ | |
771 | 1314 have_nt = !mswindows_windows9x_p; |
442 | 1315 enum_flags = PRINTER_ENUM_LOCAL | (have_nt ? PRINTER_ENUM_CONNECTIONS : 0); |
1316 enum_level = have_nt ? 4 : 5; | |
771 | 1317 enum_entry_size = (have_nt ? sizeof (PRINTER_INFO_4) : |
1318 sizeof (PRINTER_INFO_5)); | |
442 | 1319 |
1320 /* Allocate memory for printer enum structure */ | |
771 | 1321 ok = qxeEnumPrinters (enum_flags, NULL, enum_level, &dummy_byte, 1, |
1322 &bytes_needed, &num_printers); | |
442 | 1323 if (ok) |
1324 /* No printers, if just 1 byte is enough */ | |
1325 return Qnil; | |
1326 | |
1327 if (GetLastError () != ERROR_INSUFFICIENT_BUFFER) | |
1328 signal_enum_printer_error (); | |
1329 | |
2367 | 1330 data_buf = alloca_array (BYTE, bytes_needed); |
771 | 1331 ok = qxeEnumPrinters (enum_flags, NULL, enum_level, data_buf, bytes_needed, |
1332 &bytes_needed, &num_printers); | |
442 | 1333 if (!ok) |
1334 signal_enum_printer_error (); | |
1335 | |
1336 if (num_printers == 0) | |
1337 /* Strange but... */ | |
1338 return Qnil; | |
1339 | |
1340 GCPRO2 (result, def_printer); | |
1341 | |
1342 while (num_printers--) | |
1343 { | |
771 | 1344 Extbyte *printer_name; |
442 | 1345 if (have_nt) |
1346 { | |
771 | 1347 PRINTER_INFO_4 *info = (PRINTER_INFO_4 *) data_buf; |
1348 printer_name = (Extbyte *) info->pPrinterName; | |
442 | 1349 } |
1350 else | |
1351 { | |
771 | 1352 PRINTER_INFO_5 *info = (PRINTER_INFO_5 *) data_buf; |
1353 printer_name = (Extbyte *) info->pPrinterName; | |
442 | 1354 } |
1355 data_buf += enum_entry_size; | |
1356 | |
771 | 1357 result = Fcons (build_tstr_string (printer_name), result); |
442 | 1358 } |
1359 | |
1360 def_printer = msprinter_default_printer (); | |
1361 result = Fdelete (def_printer, result); | |
1362 result = Fcons (def_printer, result); | |
1363 | |
1364 RETURN_UNGCPRO (result); | |
440 | 1365 } |
1366 | |
1367 | |
1368 /************************************************************************/ | |
428 | 1369 /* initialization */ |
1370 /************************************************************************/ | |
1371 | |
1372 void | |
1373 syms_of_device_mswindows (void) | |
1374 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1375 INIT_LISP_OBJECT (devmode); |
442 | 1376 |
3092 | 1377 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1378 INIT_LISP_OBJECT (mswindows_device); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1379 INIT_LISP_OBJECT (msprinter_device); |
3092 | 1380 #endif /* NEW_GC */ |
1381 | |
442 | 1382 DEFSUBR (Fmsprinter_get_settings); |
1383 DEFSUBR (Fmsprinter_select_settings); | |
1384 DEFSUBR (Fmsprinter_apply_settings); | |
1385 DEFSUBR (Fmsprinter_settings_copy); | |
1386 DEFSUBR (Fmsprinter_settings_despecialize); | |
1387 DEFSUBR (Fmswindows_get_default_printer); | |
1388 DEFSUBR (Fmswindows_printer_list); | |
1389 | |
510 | 1390 DEFKEYWORD (Q_allow_selection); |
1391 DEFKEYWORD (Q_allow_pages); | |
1392 DEFKEYWORD (Q_selected_page_button); | |
1393 DEFSYMBOL (Qselected_page_button); | |
1394 | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1395 DEFSYMBOL (Qmake_device_early_mswindows_entry_point); |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1396 DEFSYMBOL ( Qmake_device_late_mswindows_entry_point); |
428 | 1397 } |
1398 | |
1399 void | |
1400 console_type_create_device_mswindows (void) | |
1401 { | |
1402 CONSOLE_HAS_METHOD (mswindows, init_device); | |
1403 CONSOLE_HAS_METHOD (mswindows, finish_init_device); | |
440 | 1404 CONSOLE_HAS_METHOD (mswindows, mark_device); |
428 | 1405 CONSOLE_HAS_METHOD (mswindows, delete_device); |
1406 CONSOLE_HAS_METHOD (mswindows, device_system_metrics); | |
545 | 1407 CONSOLE_IMPLEMENTATION_FLAGS (mswindows, XDEVIMPF_PIXEL_GEOMETRY); |
440 | 1408 |
1409 CONSOLE_HAS_METHOD (msprinter, init_device); | |
1410 CONSOLE_HAS_METHOD (msprinter, mark_device); | |
1411 CONSOLE_HAS_METHOD (msprinter, delete_device); | |
1412 CONSOLE_HAS_METHOD (msprinter, device_system_metrics); | |
545 | 1413 CONSOLE_IMPLEMENTATION_FLAGS (msprinter, (XDEVIMPF_PIXEL_GEOMETRY |
1414 | XDEVIMPF_IS_A_PRINTER | |
1415 | XDEVIMPF_NO_AUTO_REDISPLAY | |
1416 | XDEVIMPF_DONT_PREEMPT_REDISPLAY | |
1417 | XDEVIMPF_FRAMELESS_OK)); | |
428 | 1418 } |
1419 | |
440 | 1420 |
428 | 1421 void |
1422 vars_of_device_mswindows (void) | |
1423 { | |
1424 } |