Mercurial > hg > xemacs-beta
comparison src/device-msw.c @ 428:3ecd8885ac67 r21-2-22
Import from CVS: tag r21-2-22
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:28:15 +0200 |
parents | |
children | 8de8e3f6228a |
comparison
equal
deleted
inserted
replaced
427:0a0253eac470 | 428:3ecd8885ac67 |
---|---|
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. | |
28 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0. | |
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" | |
40 #include "sysdep.h" | |
41 | |
42 /* win32 DDE management library globals */ | |
43 #ifdef HAVE_DRAGNDROP | |
44 DWORD mswindows_dde_mlid; | |
45 HSZ mswindows_dde_service; | |
46 HSZ mswindows_dde_topic_system; | |
47 HSZ mswindows_dde_item_open; | |
48 #endif | |
49 | |
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; | |
53 | |
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; | |
58 | |
59 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win; | |
60 | |
61 | |
62 /************************************************************************/ | |
63 /* helpers */ | |
64 /************************************************************************/ | |
65 | |
66 static Lisp_Object | |
67 build_syscolor_string (int index) | |
68 { | |
69 DWORD clr; | |
70 char buf[16]; | |
71 | |
72 if (index < 0) | |
73 return Qnil; | |
74 | |
75 clr = GetSysColor (index); | |
76 sprintf (buf, "#%02X%02X%02X", | |
77 GetRValue (clr), | |
78 GetGValue (clr), | |
79 GetBValue (clr)); | |
80 return build_string (buf); | |
81 } | |
82 | |
83 static Lisp_Object | |
84 build_syscolor_cons (int index1, int index2) | |
85 { | |
86 Lisp_Object color1, color2; | |
87 struct gcpro gcpro1; | |
88 GCPRO1 (color1); | |
89 color1 = build_syscolor_string (index1); | |
90 color2 = build_syscolor_string (index2); | |
91 RETURN_UNGCPRO (Fcons (color1, color2)); | |
92 } | |
93 | |
94 static Lisp_Object | |
95 build_sysmetrics_cons (int index1, int index2) | |
96 { | |
97 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)), | |
98 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2))); | |
99 } | |
100 | |
101 | |
102 | |
103 /************************************************************************/ | |
104 /* methods */ | |
105 /************************************************************************/ | |
106 | |
107 static void | |
108 mswindows_init_device (struct device *d, Lisp_Object props) | |
109 { | |
110 WNDCLASSEX wc; | |
111 HDC hdc; | |
112 | |
113 DEVICE_CLASS (d) = Qcolor; | |
114 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1; | |
115 init_baud_rate (d); | |
116 init_one_device (d); | |
117 | |
118 d->device_data = xnew_and_zero (struct mswindows_device); | |
119 hdc = CreateCompatibleDC (NULL); | |
120 assert (hdc!=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); | |
132 DeleteDC (hdc); | |
133 | |
134 mswindows_enumerate_fonts (d); | |
135 | |
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; | |
140 wc.cbClsExtra = 0; | |
141 wc.cbWndExtra = MSWINDOWS_WINDOW_EXTRA_BYTES; | |
142 /* This must match whatever is passed to CreateWIndowEx, NULL is ok | |
143 for this. */ | |
144 wc.hInstance = NULL; | |
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 | |
148 take over */ | |
149 wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); | |
150 wc.lpszMenuName = NULL; | |
151 | |
152 wc.lpszClassName = XEMACS_CLASS; | |
153 wc.hIconSm = LoadImage (GetModuleHandle (NULL), XEMACS_CLASS, | |
154 IMAGE_ICON, 16, 16, 0); | |
155 RegisterClassEx (&wc); | |
156 | |
157 #ifdef HAVE_WIDGETS | |
158 xzero (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; | |
163 wc.hInstance = NULL; | |
164 RegisterClassEx (&wc); | |
165 #endif | |
166 | |
167 #ifdef HAVE_TOOLBARS | |
168 InitCommonControls (); | |
169 #endif | |
170 } | |
171 | |
172 static void | |
173 mswindows_finish_init_device (struct device *d, Lisp_Object props) | |
174 { | |
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); | |
182 | |
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); | |
188 #endif | |
189 } | |
190 | |
191 static void | |
192 mswindows_delete_device (struct device *d) | |
193 { | |
194 struct mswindows_font_enum *fontlist, *next; | |
195 | |
196 fontlist = DEVICE_MSWINDOWS_FONTLIST (d); | |
197 while (fontlist) | |
198 { | |
199 next = fontlist->next; | |
200 free (fontlist); | |
201 fontlist = next; | |
202 } | |
203 | |
204 #ifdef HAVE_DRAGNDROP | |
205 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER); | |
206 DdeUninitialize (mswindows_dde_mlid); | |
207 #endif | |
208 | |
209 free (d->device_data); | |
210 } | |
211 | |
212 static Lisp_Object | |
213 mswindows_device_system_metrics (struct device *d, | |
214 enum device_metrics m) | |
215 { | |
216 switch (m) | |
217 { | |
218 case DM_size_device: | |
219 return Fcons (make_int (DEVICE_MSWINDOWS_HORZRES(d)), | |
220 make_int (DEVICE_MSWINDOWS_VERTRES(d))); | |
221 break; | |
222 case DM_size_device_mm: | |
223 return Fcons (make_int (DEVICE_MSWINDOWS_HORZSIZE(d)), | |
224 make_int (DEVICE_MSWINDOWS_VERTSIZE(d))); | |
225 break; | |
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 | |
229 therefore useless */ | |
230 return make_int (DEVICE_MSWINDOWS_BITSPIXEL(d)); | |
231 break; | |
232 case DM_num_color_cells: | |
233 return make_int (DEVICE_MSWINDOWS_CELLS(d)); | |
234 break; | |
235 | |
236 /*** Colors ***/ | |
237 #define FROB(met, index1, index2) \ | |
238 case DM_##met: \ | |
239 return build_syscolor_cons (index1, index2); | |
240 | |
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); | |
255 #undef FROB | |
256 | |
257 /*** Sizes ***/ | |
258 #define FROB(met, index1, index2) \ | |
259 case DM_##met: \ | |
260 return build_sysmetrics_cons (index1, index2); | |
261 | |
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); | |
267 #undef FROB | |
268 | |
269 case DM_size_workspace: | |
270 { | |
271 RECT rc; | |
272 SystemParametersInfo (SPI_GETWORKAREA, 0, &rc, 0); | |
273 return Fcons (make_int (rc.right - rc.left), | |
274 make_int (rc.bottom - rc.top)); | |
275 } | |
276 /* | |
277 case DM_size_toolbar: | |
278 case DM_size_toolbar_button: | |
279 case DM_size_toolbar_border: | |
280 */ | |
281 | |
282 /*** Features ***/ | |
283 #define FROB(met, index) \ | |
284 case DM_##met: \ | |
285 return make_int (GetSystemMetrics (index)); | |
286 | |
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); | |
292 #undef FROB | |
293 | |
294 } | |
295 | |
296 /* Do not know such property */ | |
297 return Qunbound; | |
298 } | |
299 | |
300 static unsigned int | |
301 mswindows_device_implementation_flags (void) | |
302 { | |
303 return XDEVIMPF_PIXEL_GEOMETRY; | |
304 } | |
305 | |
306 | |
307 /************************************************************************/ | |
308 /* initialization */ | |
309 /************************************************************************/ | |
310 | |
311 void | |
312 syms_of_device_mswindows (void) | |
313 { | |
314 defsymbol (&Qinit_pre_mswindows_win, "init-pre-mswindows-win"); | |
315 defsymbol (&Qinit_post_mswindows_win, "init-post-mswindows-win"); | |
316 } | |
317 | |
318 void | |
319 console_type_create_device_mswindows (void) | |
320 { | |
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); | |
327 } | |
328 | |
329 void | |
330 vars_of_device_mswindows (void) | |
331 { | |
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. | |
335 */ ); | |
336 Vmswindows_downcase_file_names = Qnil; | |
337 | |
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. | |
343 */ ); | |
344 Vmswindows_get_true_file_attributes = Qnil; | |
345 } |