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