213
|
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.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
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
|
|
10 later version.
|
|
11
|
|
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
|
|
15 for more details.
|
|
16
|
|
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. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* Authorship:
|
|
25
|
|
26 Original authors: Jamie Zawinski and the FSF
|
|
27 Rewritten by Ben Wing and Chuck Thompson.
|
272
|
28 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
|
213
|
29 */
|
|
30
|
|
31
|
|
32 #include <config.h>
|
|
33 #include "lisp.h"
|
|
34
|
|
35 #include "console-msw.h"
|
|
36 #include "console-stream.h"
|
|
37 #include "events.h"
|
|
38 #include "faces.h"
|
|
39 #include "frame.h"
|
249
|
40 #include "sysdep.h"
|
|
41
|
280
|
42 #ifndef __CYGWIN32__
|
|
43 #include <commctrl.h>
|
|
44 #endif
|
|
45
|
249
|
46 /* win32 DDE management library globals */
|
284
|
47 #ifdef HAVE_DRAGNDROP
|
249
|
48 DWORD mswindows_dde_mlid;
|
|
49 HSZ mswindows_dde_service;
|
|
50 HSZ mswindows_dde_topic_system;
|
|
51 HSZ mswindows_dde_item_open;
|
284
|
52 #endif
|
213
|
53
|
263
|
54 /* Control conversion of upper case file names to lower case.
|
|
55 nil means no, t means yes. */
|
|
56 Lisp_Object Vmswindows_downcase_file_names;
|
|
57
|
|
58 /* Control whether stat() attempts to determine file type and link count
|
|
59 exactly, at the expense of slower operation. Since true hard links
|
|
60 are supported on NTFS volumes, this is only relevant on NT. */
|
|
61 Lisp_Object Vmswindows_get_true_file_attributes;
|
|
62
|
213
|
63 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win;
|
|
64
|
294
|
65 struct font_enum_t
|
|
66 {
|
|
67 HDC hdc;
|
|
68 struct device *d;
|
|
69 };
|
|
70
|
|
71
|
|
72 /************************************************************************/
|
|
73 /* helpers */
|
|
74 /************************************************************************/
|
|
75
|
|
76 static int CALLBACK
|
|
77 font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
|
|
78 int FontType, struct font_enum_t *font_enum)
|
|
79 {
|
|
80 struct mswindows_font_enum *fontlist, **fonthead;
|
|
81 char fontname[MSW_FONTSIZE];
|
|
82
|
|
83 /* The enumerated font weights are not to be trusted because:
|
|
84 * a) lpelfe->elfStyle is only filled in for TrueType fonts.
|
|
85 * b) Not all Bold and Italic styles of all fonts (inluding some Vector,
|
|
86 * Truetype and Raster fonts) are enumerated.
|
|
87 * I guess that fonts for which Bold and Italic styles are generated
|
|
88 * 'on-the-fly' are not enumerated. It would be overly restrictive to
|
|
89 * disallow Bold And Italic weights for these fonts, so we just leave
|
|
90 * weights unspecified. This means that we have to weed out duplicates of
|
|
91 * those fonts that do get enumerated with different weights. */
|
|
92
|
|
93 if (FontType == 0 /*vector*/ || FontType == TRUETYPE_FONTTYPE)
|
|
94 /* Scalable, so leave pointsize blank */
|
|
95 sprintf (fontname, "%s::::%s", lpelfe->elfLogFont.lfFaceName,
|
|
96 lpelfe->elfScript);
|
|
97 else
|
|
98 /* Formula for pointsize->height from LOGFONT docs in Platform SDK */
|
|
99 sprintf (fontname, "%s::%d::%s", lpelfe->elfLogFont.lfFaceName,
|
|
100 MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading,
|
|
101 72, DEVICE_MSWINDOWS_LOGPIXELSY (font_enum->d)),
|
|
102 lpelfe->elfScript);
|
|
103
|
|
104 fonthead = &DEVICE_MSWINDOWS_FONTLIST (font_enum->d);
|
|
105 fontlist = *fonthead;
|
|
106 while (fontlist)
|
|
107 if (!strcmp (fontname, fontlist->fontname))
|
|
108 return 1; /* found a duplicate */
|
|
109 else
|
|
110 fontlist = fontlist->next;
|
|
111
|
|
112 /* Insert entry at head */
|
|
113 fontlist = *fonthead;
|
|
114 *fonthead = xmalloc (sizeof (struct mswindows_font_enum));
|
|
115 if (*fonthead == NULL)
|
|
116 {
|
|
117 *fonthead = fontlist;
|
|
118 return 0;
|
|
119 }
|
|
120 strcpy ((*fonthead)->fontname, fontname);
|
|
121 (*fonthead)->next = fontlist;
|
|
122 return 1;
|
|
123 }
|
|
124
|
|
125 static int CALLBACK
|
|
126 font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
|
|
127 int FontType, struct font_enum_t *font_enum)
|
|
128 {
|
|
129 /* This function gets called once per facename per character set.
|
|
130 * We call a second callback to enumerate the fonts in each facename */
|
|
131 return EnumFontFamiliesEx (font_enum->hdc, &lpelfe->elfLogFont,
|
|
132 (FONTENUMPROC) font_enum_callback_2,
|
|
133 (LPARAM) font_enum, 0);
|
|
134 }
|
|
135
|
|
136 static Lisp_Object
|
|
137 build_syscolor_string (int index)
|
|
138 {
|
|
139 DWORD clr;
|
|
140 char buf[16];
|
|
141
|
|
142 if (index < 0)
|
|
143 return Qnil;
|
|
144
|
|
145 clr = GetSysColor (index);
|
|
146 sprintf (buf, "#%02X%02X%02X",
|
|
147 GetRValue (clr),
|
|
148 GetGValue (clr),
|
|
149 GetBValue (clr));
|
|
150 return build_string (buf);
|
|
151 }
|
|
152
|
|
153 static Lisp_Object
|
|
154 build_syscolor_cons (int index1, int index2)
|
|
155 {
|
|
156 Lisp_Object color1, color2;
|
|
157 struct gcpro gcpro1;
|
|
158 GCPRO1 (color1);
|
|
159 color1 = build_syscolor_string (index1);
|
|
160 color2 = build_syscolor_string (index2);
|
|
161 RETURN_UNGCPRO (Fcons (color1, color2));
|
|
162 }
|
|
163
|
|
164 static Lisp_Object
|
|
165 build_sysmetrics_cons (int index1, int index2)
|
|
166 {
|
|
167 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)),
|
|
168 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2)));
|
|
169 }
|
|
170
|
|
171
|
|
172
|
|
173 /************************************************************************/
|
|
174 /* methods */
|
|
175 /************************************************************************/
|
|
176
|
213
|
177 static void
|
|
178 mswindows_init_device (struct device *d, Lisp_Object props)
|
|
179 {
|
249
|
180 WNDCLASSEX wc;
|
213
|
181 HDC hdc;
|
294
|
182 LOGFONT logfont;
|
|
183 struct font_enum_t font_enum;
|
213
|
184
|
294
|
185 DEVICE_CLASS (d) = Qcolor;
|
213
|
186 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1;
|
|
187 init_baud_rate (d);
|
|
188 init_one_device (d);
|
|
189
|
|
190 d->device_data = xnew_and_zero (struct mswindows_device);
|
294
|
191 hdc = CreateCompatibleDC (NULL);
|
|
192 assert (hdc!=NULL);
|
213
|
193 DEVICE_MSWINDOWS_LOGPIXELSX(d) = GetDeviceCaps(hdc, LOGPIXELSX);
|
|
194 DEVICE_MSWINDOWS_LOGPIXELSY(d) = GetDeviceCaps(hdc, LOGPIXELSY);
|
|
195 DEVICE_MSWINDOWS_PLANES(d) = GetDeviceCaps(hdc, PLANES);
|
294
|
196 /* #### SIZEPALETTE only valid if RC_PALETTE bit set in RASTERCAPS,
|
213
|
197 what should we return for a non-palette-based device? */
|
|
198 DEVICE_MSWINDOWS_CELLS(d) = GetDeviceCaps(hdc, SIZEPALETTE);
|
|
199 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES);
|
|
200 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES);
|
|
201 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE);
|
|
202 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE);
|
267
|
203 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL);
|
213
|
204
|
294
|
205 DEVICE_MSWINDOWS_FONTLIST (d) = NULL;
|
|
206 logfont.lfCharSet = DEFAULT_CHARSET;
|
|
207 logfont.lfFaceName[0] = '\0';
|
|
208 logfont.lfPitchAndFamily = DEFAULT_PITCH;
|
|
209 font_enum.hdc = hdc;
|
|
210 font_enum.d = d;
|
|
211 EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1,
|
|
212 (LPARAM) (&font_enum), 0);
|
|
213 DeleteDC (hdc);
|
223
|
214
|
|
215 /* Register the main window class */
|
249
|
216 wc.cbSize = sizeof (WNDCLASSEX);
|
223
|
217 wc.style = CS_OWNDC; /* One DC per window */
|
|
218 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc;
|
|
219 wc.cbClsExtra = 0;
|
|
220 wc.cbWndExtra = MSWINDOWS_WINDOW_EXTRA_BYTES;
|
|
221 wc.hInstance = NULL; /* ? */
|
227
|
222 wc.hIcon = LoadIcon (GetModuleHandle(NULL), XEMACS_CLASS);
|
223
|
223 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
|
|
224 /* Background brush is only used during sizing, when XEmacs cannot
|
|
225 take over */
|
|
226 wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
|
|
227 wc.lpszMenuName = NULL;
|
288
|
228
|
223
|
229 wc.lpszClassName = XEMACS_CLASS;
|
249
|
230 wc.hIconSm = LoadImage (GetModuleHandle (NULL), XEMACS_CLASS,
|
|
231 IMAGE_ICON, 16, 16, 0);
|
|
232 RegisterClassEx (&wc);
|
278
|
233 #ifdef HAVE_TOOLBARS
|
|
234 InitCommonControls ();
|
|
235 #endif
|
249
|
236 }
|
|
237
|
|
238 static void
|
|
239 mswindows_finish_init_device (struct device *d, Lisp_Object props)
|
|
240 {
|
284
|
241 /* Initialise DDE management library and our related globals. We execute a
|
|
242 * dde Open("file") by simulating a drop, so this depends on dnd support. */
|
|
243 #ifdef HAVE_DRAGNDROP
|
249
|
244 mswindows_dde_mlid = 0;
|
278
|
245 DdeInitialize (&mswindows_dde_mlid, (PFNCALLBACK)mswindows_dde_callback,
|
249
|
246 APPCMD_FILTERINITS|CBF_FAIL_SELFCONNECTIONS|CBF_FAIL_ADVISES|
|
|
247 CBF_FAIL_POKES|CBF_FAIL_REQUESTS|CBF_SKIP_ALLNOTIFICATIONS, 0);
|
|
248
|
|
249 mswindows_dde_service = DdeCreateStringHandle (mswindows_dde_mlid, XEMACS_CLASS, 0);
|
|
250 mswindows_dde_topic_system = DdeCreateStringHandle (mswindows_dde_mlid, SZDDESYS_TOPIC, 0);
|
|
251 mswindows_dde_item_open = DdeCreateStringHandle (mswindows_dde_mlid,
|
|
252 TEXT(MSWINDOWS_DDE_ITEM_OPEN), 0);
|
|
253 DdeNameService (mswindows_dde_mlid, mswindows_dde_service, 0L, DNS_REGISTER);
|
284
|
254 #endif
|
249
|
255 }
|
|
256
|
|
257 static void
|
|
258 mswindows_delete_device (struct device *d)
|
|
259 {
|
294
|
260 struct mswindows_font_enum *fontlist, *next;
|
|
261
|
|
262 fontlist = DEVICE_MSWINDOWS_FONTLIST (d);
|
|
263 while (fontlist)
|
|
264 {
|
|
265 next = fontlist->next;
|
|
266 free (fontlist);
|
|
267 fontlist = next;
|
|
268 }
|
|
269
|
284
|
270 #ifdef HAVE_DRAGNDROP
|
249
|
271 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER);
|
|
272 DdeUninitialize (mswindows_dde_mlid);
|
284
|
273 #endif
|
|
274
|
294
|
275 free (d->device_data);
|
213
|
276 }
|
|
277
|
282
|
278 static Lisp_Object
|
|
279 mswindows_device_system_metrics (struct device *d,
|
|
280 enum device_metrics m)
|
213
|
281 {
|
282
|
282 switch (m)
|
|
283 {
|
284
|
284 case DM_size_device:
|
282
|
285 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)),
|
|
286 make_int (DEVICE_MSWINDOWS_VERTRES(d)));
|
|
287 break;
|
284
|
288 case DM_size_device_mm:
|
282
|
289 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)),
|
|
290 make_int (DEVICE_MSWINDOWS_VERTSIZE(d)));
|
|
291 break;
|
284
|
292 case DM_num_bit_planes:
|
288
|
293 /* this is what X means by bitplanes therefore we ought to be
|
|
294 consistent. num planes is always 1 under mswindows and
|
|
295 therefore useless */
|
|
296 return make_int (DEVICE_MSWINDOWS_BITSPIXEL(d));
|
282
|
297 break;
|
284
|
298 case DM_num_color_cells:
|
282
|
299 return make_int (DEVICE_MSWINDOWS_CELLS(d));
|
|
300 break;
|
284
|
301
|
|
302 /*** Colors ***/
|
|
303 #define FROB(met, index1, index2) \
|
|
304 case DM_##met: \
|
|
305 return build_syscolor_cons (index1, index2);
|
|
306
|
|
307 FROB (color_default, COLOR_WINDOW, COLOR_WINDOWTEXT);
|
|
308 FROB (color_select, COLOR_HIGHLIGHT, COLOR_HIGHLIGHTTEXT);
|
|
309 FROB (color_balloon, COLOR_INFOBK, COLOR_INFOTEXT);
|
|
310 FROB (color_3d_face, COLOR_3DFACE, COLOR_BTNTEXT);
|
|
311 FROB (color_3d_light, COLOR_3DLIGHT, COLOR_3DHILIGHT);
|
|
312 FROB (color_3d_dark, COLOR_3DSHADOW, COLOR_3DDKSHADOW);
|
|
313 FROB (color_menu, COLOR_MENU, COLOR_MENUTEXT);
|
|
314 FROB (color_menu_highlight, COLOR_HIGHLIGHT, COLOR_HIGHLIGHTTEXT);
|
|
315 FROB (color_menu_button, COLOR_MENU, COLOR_MENUTEXT);
|
|
316 FROB (color_menu_disabled, COLOR_MENU, COLOR_GRAYTEXT);
|
|
317 FROB (color_toolbar, COLOR_BTNFACE, COLOR_BTNTEXT);
|
|
318 FROB (color_scrollbar, COLOR_SCROLLBAR, COLOR_CAPTIONTEXT);
|
|
319 FROB (color_desktop, -1, COLOR_DESKTOP);
|
|
320 FROB (color_workspace, -1, COLOR_APPWORKSPACE);
|
|
321 #undef FROB
|
|
322
|
|
323 /*** Sizes ***/
|
|
324 #define FROB(met, index1, index2) \
|
|
325 case DM_##met: \
|
|
326 return build_sysmetrics_cons (index1, index2);
|
|
327
|
|
328 FROB (size_cursor, SM_CXCURSOR, SM_CYCURSOR);
|
|
329 FROB (size_scrollbar, SM_CXVSCROLL, SM_CYHSCROLL);
|
|
330 FROB (size_menu, -1, SM_CYMENU);
|
|
331 FROB (size_icon, SM_CXICON, SM_CYICON);
|
|
332 FROB (size_icon_small, SM_CXSMICON, SM_CYSMICON);
|
|
333 #undef FROB
|
|
334
|
|
335 case DM_size_workspace:
|
|
336 {
|
|
337 RECT rc;
|
|
338 SystemParametersInfo (SPI_GETWORKAREA, 0, &rc, 0);
|
|
339 return Fcons (make_int (rc.right - rc.left),
|
|
340 make_int (rc.bottom - rc.top));
|
|
341 }
|
|
342 /*
|
|
343 case DM_size_toolbar:
|
|
344 case DM_size_toolbar_button:
|
|
345 case DM_size_toolbar_border:
|
|
346 */
|
|
347
|
|
348 /*** Features ***/
|
|
349 #define FROB(met, index) \
|
|
350 case DM_##met: \
|
|
351 return make_int (GetSystemMetrics (index));
|
|
352
|
|
353 FROB (mouse_buttons, SM_CMOUSEBUTTONS);
|
|
354 FROB (swap_buttons, SM_SWAPBUTTON);
|
|
355 FROB (show_sounds, SM_SHOWSOUNDS);
|
|
356 FROB (slow_device, SM_SLOWMACHINE);
|
|
357 FROB (security, SM_SECURE);
|
|
358 #undef FROB
|
|
359
|
282
|
360 }
|
213
|
361
|
282
|
362 /* Do not know such property */
|
284
|
363 return Qunbound;
|
213
|
364 }
|
|
365
|
269
|
366 static unsigned int
|
|
367 mswindows_device_implementation_flags (void)
|
|
368 {
|
|
369 return XDEVIMPF_PIXEL_GEOMETRY;
|
|
370 }
|
294
|
371
|
213
|
372
|
|
373 /************************************************************************/
|
|
374 /* initialization */
|
|
375 /************************************************************************/
|
|
376
|
|
377 void
|
|
378 syms_of_device_mswindows (void)
|
|
379 {
|
|
380 defsymbol (&Qinit_pre_mswindows_win, "init-pre-mswindows-win");
|
|
381 defsymbol (&Qinit_post_mswindows_win, "init-post-mswindows-win");
|
263
|
382
|
|
383 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*
|
|
384 Non-nil means convert all-upper case file names to lower case.
|
|
385 This applies when performing completions and file name expansion.*/ );
|
|
386 Vmswindows_downcase_file_names = Qnil;
|
|
387
|
|
388 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /*
|
|
389 "Non-nil means determine accurate link count in file-attributes.
|
|
390 This option slows down file-attributes noticeably, so is disabled by
|
|
391 default. Note that it is only useful for files on NTFS volumes,
|
|
392 where hard links are supported.
|
|
393 */ );
|
|
394 Vmswindows_get_true_file_attributes = Qnil;
|
213
|
395 }
|
|
396
|
|
397 void
|
|
398 console_type_create_device_mswindows (void)
|
|
399 {
|
|
400 CONSOLE_HAS_METHOD (mswindows, init_device);
|
249
|
401 CONSOLE_HAS_METHOD (mswindows, finish_init_device);
|
213
|
402 /* CONSOLE_HAS_METHOD (mswindows, mark_device); */
|
249
|
403 CONSOLE_HAS_METHOD (mswindows, delete_device);
|
282
|
404 CONSOLE_HAS_METHOD (mswindows, device_system_metrics);
|
269
|
405 CONSOLE_HAS_METHOD (mswindows, device_implementation_flags);
|
213
|
406 }
|
|
407
|
|
408 void
|
|
409 vars_of_device_mswindows (void)
|
|
410 {
|
|
411 }
|