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.
5 This file is part of XEmacs.
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Synched up with: Not in FSF. */
26 Original authors: Jamie Zawinski and the FSF
27 Rewritten by Ben Wing and Chuck Thompson.
28 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
35 #include "console-msw.h"
36 #include "console-stream.h"
42 /* win32 DDE management library globals */
44 DWORD mswindows_dde_mlid;
45 HSZ mswindows_dde_service;
46 HSZ mswindows_dde_topic_system;
47 HSZ mswindows_dde_item_open;
50 /* Control conversion of upper case file names to lower case.
51 nil means no, t means yes. */
52 Lisp_Object Vmswindows_downcase_file_names;
54 /* Control whether stat() attempts to determine file type and link count
55 exactly, at the expense of slower operation. Since true hard links
56 are supported on NTFS volumes, this is only relevant on NT. */
57 Lisp_Object Vmswindows_get_true_file_attributes;
59 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win;
62 /************************************************************************/
64 /************************************************************************/
67 build_syscolor_string (int index)
75 clr = GetSysColor (index);
76 sprintf (buf, "#%02X%02X%02X",
80 return build_string (buf);
84 build_syscolor_cons (int index1, int index2)
86 Lisp_Object color1, color2;
89 color1 = build_syscolor_string (index1);
90 color2 = build_syscolor_string (index2);
91 RETURN_UNGCPRO (Fcons (color1, color2));
95 build_sysmetrics_cons (int index1, int index2)
97 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)),
98 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2)));
103 /************************************************************************/
105 /************************************************************************/
108 mswindows_init_device (struct device *d, Lisp_Object props)
113 DEVICE_CLASS (d) = Qcolor;
114 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1;
118 d->device_data = xnew_and_zero (struct mswindows_device);
119 hdc = CreateCompatibleDC (NULL);
121 DEVICE_MSWINDOWS_LOGPIXELSX(d) = GetDeviceCaps(hdc, LOGPIXELSX);
122 DEVICE_MSWINDOWS_LOGPIXELSY(d) = GetDeviceCaps(hdc, LOGPIXELSY);
123 DEVICE_MSWINDOWS_PLANES(d) = GetDeviceCaps(hdc, PLANES);
124 /* #### SIZEPALETTE only valid if RC_PALETTE bit set in RASTERCAPS,
125 what should we return for a non-palette-based device? */
126 DEVICE_MSWINDOWS_CELLS(d) = GetDeviceCaps(hdc, SIZEPALETTE);
127 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES);
128 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES);
129 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE);
130 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE);
131 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL);
134 mswindows_enumerate_fonts (d);
136 /* Register the main window class */
137 wc.cbSize = sizeof (WNDCLASSEX);
138 wc.style = CS_OWNDC; /* One DC per window */
139 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc;
141 wc.cbWndExtra = MSWINDOWS_WINDOW_EXTRA_BYTES;
142 wc.hInstance = NULL; /* ? */
143 wc.hIcon = LoadIcon (GetModuleHandle(NULL), XEMACS_CLASS);
144 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
145 /* Background brush is only used during sizing, when XEmacs cannot
147 wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
148 wc.lpszMenuName = NULL;
150 wc.lpszClassName = XEMACS_CLASS;
151 wc.hIconSm = LoadImage (GetModuleHandle (NULL), XEMACS_CLASS,
152 IMAGE_ICON, 16, 16, 0);
153 RegisterClassEx (&wc);
155 InitCommonControls ();
160 mswindows_finish_init_device (struct device *d, Lisp_Object props)
162 /* Initialize DDE management library and our related globals. We execute a
163 * dde Open("file") by simulating a drop, so this depends on dnd support. */
164 #ifdef HAVE_DRAGNDROP
165 mswindows_dde_mlid = 0;
166 DdeInitialize (&mswindows_dde_mlid, (PFNCALLBACK)mswindows_dde_callback,
167 APPCMD_FILTERINITS|CBF_FAIL_SELFCONNECTIONS|CBF_FAIL_ADVISES|
168 CBF_FAIL_POKES|CBF_FAIL_REQUESTS|CBF_SKIP_ALLNOTIFICATIONS, 0);
170 mswindows_dde_service = DdeCreateStringHandle (mswindows_dde_mlid, XEMACS_CLASS, 0);
171 mswindows_dde_topic_system = DdeCreateStringHandle (mswindows_dde_mlid, SZDDESYS_TOPIC, 0);
172 mswindows_dde_item_open = DdeCreateStringHandle (mswindows_dde_mlid,
173 TEXT(MSWINDOWS_DDE_ITEM_OPEN), 0);
174 DdeNameService (mswindows_dde_mlid, mswindows_dde_service, 0L, DNS_REGISTER);
179 mswindows_delete_device (struct device *d)
181 struct mswindows_font_enum *fontlist, *next;
183 fontlist = DEVICE_MSWINDOWS_FONTLIST (d);
186 next = fontlist->next;
191 #ifdef HAVE_DRAGNDROP
192 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER);
193 DdeUninitialize (mswindows_dde_mlid);
196 free (d->device_data);
200 mswindows_device_system_metrics (struct device *d,
201 enum device_metrics m)
206 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)),
207 make_int (DEVICE_MSWINDOWS_VERTRES(d)));
209 case DM_size_device_mm:
210 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)),
211 make_int (DEVICE_MSWINDOWS_VERTSIZE(d)));
213 case DM_num_bit_planes:
214 /* this is what X means by bitplanes therefore we ought to be
215 consistent. num planes is always 1 under mswindows and
217 return make_int (DEVICE_MSWINDOWS_BITSPIXEL(d));
219 case DM_num_color_cells:
220 return make_int (DEVICE_MSWINDOWS_CELLS(d));
224 #define FROB(met, index1, index2) \
226 return build_syscolor_cons (index1, index2);
228 FROB (color_default, COLOR_WINDOW, COLOR_WINDOWTEXT);
229 FROB (color_select, COLOR_HIGHLIGHT, COLOR_HIGHLIGHTTEXT);
230 FROB (color_balloon, COLOR_INFOBK, COLOR_INFOTEXT);
231 FROB (color_3d_face, COLOR_3DFACE, COLOR_BTNTEXT);
232 FROB (color_3d_light, COLOR_3DLIGHT, COLOR_3DHILIGHT);
233 FROB (color_3d_dark, COLOR_3DSHADOW, COLOR_3DDKSHADOW);
234 FROB (color_menu, COLOR_MENU, COLOR_MENUTEXT);
235 FROB (color_menu_highlight, COLOR_HIGHLIGHT, COLOR_HIGHLIGHTTEXT);
236 FROB (color_menu_button, COLOR_MENU, COLOR_MENUTEXT);
237 FROB (color_menu_disabled, COLOR_MENU, COLOR_GRAYTEXT);
238 FROB (color_toolbar, COLOR_BTNFACE, COLOR_BTNTEXT);
239 FROB (color_scrollbar, COLOR_SCROLLBAR, COLOR_CAPTIONTEXT);
240 FROB (color_desktop, -1, COLOR_DESKTOP);
241 FROB (color_workspace, -1, COLOR_APPWORKSPACE);
245 #define FROB(met, index1, index2) \
247 return build_sysmetrics_cons (index1, index2);
249 FROB (size_cursor, SM_CXCURSOR, SM_CYCURSOR);
250 FROB (size_scrollbar, SM_CXVSCROLL, SM_CYHSCROLL);
251 FROB (size_menu, -1, SM_CYMENU);
252 FROB (size_icon, SM_CXICON, SM_CYICON);
253 FROB (size_icon_small, SM_CXSMICON, SM_CYSMICON);
256 case DM_size_workspace:
259 SystemParametersInfo (SPI_GETWORKAREA, 0, &rc, 0);
260 return Fcons (make_int (rc.right - rc.left),
261 make_int (rc.bottom - rc.top));
264 case DM_size_toolbar:
265 case DM_size_toolbar_button:
266 case DM_size_toolbar_border:
270 #define FROB(met, index) \
272 return make_int (GetSystemMetrics (index));
274 FROB (mouse_buttons, SM_CMOUSEBUTTONS);
275 FROB (swap_buttons, SM_SWAPBUTTON);
276 FROB (show_sounds, SM_SHOWSOUNDS);
277 FROB (slow_device, SM_SLOWMACHINE);
278 FROB (security, SM_SECURE);
283 /* Do not know such property */
288 mswindows_device_implementation_flags (void)
290 return XDEVIMPF_PIXEL_GEOMETRY;
294 /************************************************************************/
296 /************************************************************************/
299 syms_of_device_mswindows (void)
301 defsymbol (&Qinit_pre_mswindows_win, "init-pre-mswindows-win");
302 defsymbol (&Qinit_post_mswindows_win, "init-post-mswindows-win");
306 console_type_create_device_mswindows (void)
308 CONSOLE_HAS_METHOD (mswindows, init_device);
309 CONSOLE_HAS_METHOD (mswindows, finish_init_device);
310 /* CONSOLE_HAS_METHOD (mswindows, mark_device); */
311 CONSOLE_HAS_METHOD (mswindows, delete_device);
312 CONSOLE_HAS_METHOD (mswindows, device_system_metrics);
313 CONSOLE_HAS_METHOD (mswindows, device_implementation_flags);
317 vars_of_device_mswindows (void)
319 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*
320 Non-nil means convert all-upper case file names to lower case.
321 This applies when performing completions and file name expansion.
323 Vmswindows_downcase_file_names = Qnil;
325 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /*
326 Non-nil means determine accurate link count in file-attributes.
327 This option slows down file-attributes noticeably, so is disabled by
328 default. Note that it is only useful for files on NTFS volumes,
329 where hard links are supported.
331 Vmswindows_get_true_file_attributes = Qnil;