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 /* This must match whatever is passed to CreateWIndowEx, NULL is ok
145 wc.hIcon = LoadIcon (GetModuleHandle(NULL), XEMACS_CLASS);
146 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
147 /* Background brush is only used during sizing, when XEmacs cannot
149 wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
150 wc.lpszMenuName = NULL;
152 wc.lpszClassName = XEMACS_CLASS;
153 wc.hIconSm = LoadImage (GetModuleHandle (NULL), XEMACS_CLASS,
154 IMAGE_ICON, 16, 16, 0);
155 RegisterClassEx (&wc);
159 /* Register the main window class */
160 wc.cbSize = sizeof (WNDCLASSEX);
161 wc.lpfnWndProc = (WNDPROC) mswindows_control_wnd_proc;
162 wc.lpszClassName = XEMACS_CONTROL_CLASS;
164 RegisterClassEx (&wc);
168 InitCommonControls ();
173 mswindows_finish_init_device (struct device *d, Lisp_Object props)
175 /* Initialize DDE management library and our related globals. We execute a
176 * dde Open("file") by simulating a drop, so this depends on dnd support. */
177 #ifdef HAVE_DRAGNDROP
178 mswindows_dde_mlid = 0;
179 DdeInitialize (&mswindows_dde_mlid, (PFNCALLBACK)mswindows_dde_callback,
180 APPCMD_FILTERINITS|CBF_FAIL_SELFCONNECTIONS|CBF_FAIL_ADVISES|
181 CBF_FAIL_POKES|CBF_FAIL_REQUESTS|CBF_SKIP_ALLNOTIFICATIONS, 0);
183 mswindows_dde_service = DdeCreateStringHandle (mswindows_dde_mlid, XEMACS_CLASS, 0);
184 mswindows_dde_topic_system = DdeCreateStringHandle (mswindows_dde_mlid, SZDDESYS_TOPIC, 0);
185 mswindows_dde_item_open = DdeCreateStringHandle (mswindows_dde_mlid,
186 TEXT(MSWINDOWS_DDE_ITEM_OPEN), 0);
187 DdeNameService (mswindows_dde_mlid, mswindows_dde_service, 0L, DNS_REGISTER);
192 mswindows_delete_device (struct device *d)
194 struct mswindows_font_enum *fontlist, *next;
196 fontlist = DEVICE_MSWINDOWS_FONTLIST (d);
199 next = fontlist->next;
204 #ifdef HAVE_DRAGNDROP
205 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER);
206 DdeUninitialize (mswindows_dde_mlid);
209 free (d->device_data);
213 mswindows_device_system_metrics (struct device *d,
214 enum device_metrics m)
219 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)),
220 make_int (DEVICE_MSWINDOWS_VERTRES(d)));
222 case DM_size_device_mm:
223 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)),
224 make_int (DEVICE_MSWINDOWS_VERTSIZE(d)));
226 case DM_num_bit_planes:
227 /* this is what X means by bitplanes therefore we ought to be
228 consistent. num planes is always 1 under mswindows and
230 return make_int (DEVICE_MSWINDOWS_BITSPIXEL(d));
232 case DM_num_color_cells:
233 return make_int (DEVICE_MSWINDOWS_CELLS(d));
237 #define FROB(met, index1, index2) \
239 return build_syscolor_cons (index1, index2);
241 FROB (color_default, COLOR_WINDOW, COLOR_WINDOWTEXT);
242 FROB (color_select, COLOR_HIGHLIGHT, COLOR_HIGHLIGHTTEXT);
243 FROB (color_balloon, COLOR_INFOBK, COLOR_INFOTEXT);
244 FROB (color_3d_face, COLOR_3DFACE, COLOR_BTNTEXT);
245 FROB (color_3d_light, COLOR_3DLIGHT, COLOR_3DHILIGHT);
246 FROB (color_3d_dark, COLOR_3DSHADOW, COLOR_3DDKSHADOW);
247 FROB (color_menu, COLOR_MENU, COLOR_MENUTEXT);
248 FROB (color_menu_highlight, COLOR_HIGHLIGHT, COLOR_HIGHLIGHTTEXT);
249 FROB (color_menu_button, COLOR_MENU, COLOR_MENUTEXT);
250 FROB (color_menu_disabled, COLOR_MENU, COLOR_GRAYTEXT);
251 FROB (color_toolbar, COLOR_BTNFACE, COLOR_BTNTEXT);
252 FROB (color_scrollbar, COLOR_SCROLLBAR, COLOR_CAPTIONTEXT);
253 FROB (color_desktop, -1, COLOR_DESKTOP);
254 FROB (color_workspace, -1, COLOR_APPWORKSPACE);
258 #define FROB(met, index1, index2) \
260 return build_sysmetrics_cons (index1, index2);
262 FROB (size_cursor, SM_CXCURSOR, SM_CYCURSOR);
263 FROB (size_scrollbar, SM_CXVSCROLL, SM_CYHSCROLL);
264 FROB (size_menu, -1, SM_CYMENU);
265 FROB (size_icon, SM_CXICON, SM_CYICON);
266 FROB (size_icon_small, SM_CXSMICON, SM_CYSMICON);
269 case DM_size_workspace:
272 SystemParametersInfo (SPI_GETWORKAREA, 0, &rc, 0);
273 return Fcons (make_int (rc.right - rc.left),
274 make_int (rc.bottom - rc.top));
277 case DM_size_toolbar:
278 case DM_size_toolbar_button:
279 case DM_size_toolbar_border:
283 #define FROB(met, index) \
285 return make_int (GetSystemMetrics (index));
287 FROB (mouse_buttons, SM_CMOUSEBUTTONS);
288 FROB (swap_buttons, SM_SWAPBUTTON);
289 FROB (show_sounds, SM_SHOWSOUNDS);
290 FROB (slow_device, SM_SLOWMACHINE);
291 FROB (security, SM_SECURE);
296 /* Do not know such property */
301 mswindows_device_implementation_flags (void)
303 return XDEVIMPF_PIXEL_GEOMETRY;
307 /************************************************************************/
309 /************************************************************************/
312 syms_of_device_mswindows (void)
314 defsymbol (&Qinit_pre_mswindows_win, "init-pre-mswindows-win");
315 defsymbol (&Qinit_post_mswindows_win, "init-post-mswindows-win");
319 console_type_create_device_mswindows (void)
321 CONSOLE_HAS_METHOD (mswindows, init_device);
322 CONSOLE_HAS_METHOD (mswindows, finish_init_device);
323 /* CONSOLE_HAS_METHOD (mswindows, mark_device); */
324 CONSOLE_HAS_METHOD (mswindows, delete_device);
325 CONSOLE_HAS_METHOD (mswindows, device_system_metrics);
326 CONSOLE_HAS_METHOD (mswindows, device_implementation_flags);
330 vars_of_device_mswindows (void)
332 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*
333 Non-nil means convert all-upper case file names to lower case.
334 This applies when performing completions and file name expansion.
336 Vmswindows_downcase_file_names = Qnil;
338 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /*
339 Non-nil means determine accurate link count in file-attributes.
340 This option slows down file-attributes noticeably, so is disabled by
341 default. Note that it is only useful for files on NTFS volumes,
342 where hard links are supported.
344 Vmswindows_get_true_file_attributes = Qnil;