Commit | Line | Data |
---|---|---|
e9e23e23 | 1 | /* Implementation of GUI terminal on the Microsoft W32 API. |
feade168 KS |
2 | Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, |
3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, | |
76b6f707 | 4 | 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
ee78dc32 GV |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
9ec0b715 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
ee78dc32 | 9 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
ee78dc32 GV |
12 | |
13 | GNU Emacs is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
ee78dc32 | 20 | |
ee78dc32 | 21 | #include <config.h> |
68c45bf0 | 22 | #include <signal.h> |
ee78dc32 | 23 | #include <stdio.h> |
791f420f | 24 | #include <stdlib.h> |
ee78dc32 GV |
25 | #include "lisp.h" |
26 | #include "blockinput.h" | |
689004fa | 27 | #include "w32term.h" |
ee78dc32 GV |
28 | |
29 | #include "systty.h" | |
30 | #include "systime.h" | |
31 | ||
32 | #include <ctype.h> | |
33 | #include <errno.h> | |
ee78dc32 GV |
34 | #include <sys/stat.h> |
35 | ||
66f30e44 JR |
36 | #include "charset.h" |
37 | #include "character.h" | |
38 | #include "coding.h" | |
39 | #include "ccl.h" | |
ee78dc32 GV |
40 | #include "frame.h" |
41 | #include "dispextern.h" | |
93ff4395 | 42 | #include "fontset.h" |
ee78dc32 GV |
43 | #include "termhooks.h" |
44 | #include "termopts.h" | |
45 | #include "termchar.h" | |
ee78dc32 GV |
46 | #include "disptab.h" |
47 | #include "buffer.h" | |
48 | #include "window.h" | |
66f30e44 | 49 | #include "keyboard.h" |
ee78dc32 | 50 | #include "intervals.h" |
66f30e44 JR |
51 | #include "process.h" |
52 | #include "atimer.h" | |
53 | #include "keymap.h" | |
54 | ||
55 | #include "w32heap.h" | |
66f30e44 | 56 | #include <shellapi.h> |
ee78dc32 | 57 | |
027f6f90 | 58 | #include "font.h" |
ef39ccbb | 59 | #include "w32font.h" |
791f420f | 60 | \f |
33c34bea | 61 | /* Fringe bitmaps. */ |
791f420f | 62 | |
0e9e9a2c KS |
63 | static int max_fringe_bmp = 0; |
64 | static HBITMAP *fringe_bmp = 0; | |
791f420f | 65 | |
5bf04520 | 66 | /* Non-nil means Emacs uses toolkit scroll bars. */ |
791f420f | 67 | |
5bf04520 | 68 | Lisp_Object Vx_toolkit_scroll_bars; |
791f420f | 69 | |
706ddb8f | 70 | /* Temporary variables for w32_read_socket. */ |
791f420f | 71 | |
706ddb8f JR |
72 | static int last_mousemove_x = 0; |
73 | static int last_mousemove_y = 0; | |
791f420f | 74 | |
af3a05ed JR |
75 | /* Define GET_WHEEL_DELTA_WPARAM macro if system headers don't. */ |
76 | #ifndef GET_WHEEL_DELTA_WPARAM | |
77 | #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam)) | |
78 | #endif | |
79 | ||
791f420f JR |
80 | /* Non-zero means that a HELP_EVENT has been generated since Emacs |
81 | start. */ | |
82 | ||
83 | static int any_help_event_p; | |
84 | ||
a18bb28d JR |
85 | /* Last window where we saw the mouse. Used by mouse-autoselect-window. */ |
86 | static Lisp_Object last_window; | |
87 | ||
d1f535d2 | 88 | /* Non-zero means make use of UNDERLINE_POSITION font properties. */ |
099b6577 EZ |
89 | int x_use_underline_position_properties; |
90 | ||
30f27523 KS |
91 | /* Non-zero means to draw the underline at the same place as the descent line. */ |
92 | ||
93 | int x_underline_at_descent_line; | |
94 | ||
e7efd97e GV |
95 | extern unsigned int msh_mousewheel; |
96 | ||
ee78dc32 GV |
97 | extern void free_frame_menubar (); |
98 | ||
9ef2e2cf | 99 | extern int w32_codepage_for_font (char *fontname); |
2bf04b9d | 100 | extern Cursor w32_load_cursor (LPCTSTR name); |
9ef2e2cf | 101 | |
52cf03a1 GV |
102 | extern Lisp_Object Vwindow_system; |
103 | ||
ee78dc32 GV |
104 | #define x_any_window_to_frame x_window_to_frame |
105 | #define x_top_window_to_frame x_window_to_frame | |
106 | ||
107 | \f | |
fbd6baed GV |
108 | /* This is display since w32 does not support multiple ones. */ |
109 | struct w32_display_info one_w32_display_info; | |
8c3b00cb | 110 | struct w32_display_info *x_display_list; |
ee78dc32 GV |
111 | |
112 | /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE), | |
fbd6baed | 113 | one for each element of w32_display_list and in the same order. |
ee78dc32 GV |
114 | NAME is the name of the frame. |
115 | FONT-LIST-CACHE records previous values returned by x-list-fonts. */ | |
fbd6baed | 116 | Lisp_Object w32_display_name_list; |
ee78dc32 | 117 | |
41375f89 JR |
118 | |
119 | #ifndef GLYPHSET | |
120 | /* Pre Windows 2000, this was not available, but define it here so | |
121 | that Emacs compiled on such a platform will run on newer versions. */ | |
122 | ||
123 | typedef struct tagWCRANGE | |
124 | { | |
125 | WCHAR wcLow; | |
126 | USHORT cGlyphs; | |
127 | } WCRANGE; | |
128 | ||
65a6ff8f | 129 | typedef struct tagGLYPHSET |
41375f89 JR |
130 | { |
131 | DWORD cbThis; | |
132 | DWORD flAccel; | |
133 | DWORD cGlyphsSupported; | |
134 | DWORD cRanges; | |
135 | WCRANGE ranges[1]; | |
65a6ff8f | 136 | } GLYPHSET; |
41375f89 JR |
137 | |
138 | #endif | |
139 | ||
8b61a891 | 140 | /* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */ |
ff90fbde | 141 | BOOL (WINAPI *pfnSetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD); |
8b61a891 JR |
142 | |
143 | #ifndef LWA_ALPHA | |
144 | #define LWA_ALPHA 0x02 | |
145 | #endif | |
ec7e221c JR |
146 | /* WS_EX_LAYERED is defined unconditionally by MingW, but only for W2K and |
147 | later targets by MSVC headers. */ | |
148 | #ifndef WS_EX_LAYERED | |
149 | #define WS_EX_LAYERED 0x80000 | |
150 | #endif | |
41375f89 | 151 | |
ee78dc32 GV |
152 | /* Frame being updated by update_frame. This is declared in term.c. |
153 | This is set by update_begin and looked at by all the | |
fbd6baed | 154 | w32 functions. It is zero while not inside an update. |
791f420f | 155 | In that case, the w32 functions assume that `SELECTED_FRAME ()' |
ee78dc32 GV |
156 | is the frame to apply to. */ |
157 | extern struct frame *updating_frame; | |
158 | ||
159 | /* This is a frame waiting to be autoraised, within w32_read_socket. */ | |
160 | struct frame *pending_autoraise_frame; | |
161 | ||
abb15ebd JR |
162 | /* The handle of the frame that currently owns the system caret. */ |
163 | HWND w32_system_caret_hwnd; | |
abb15ebd JR |
164 | int w32_system_caret_height; |
165 | int w32_system_caret_x; | |
166 | int w32_system_caret_y; | |
99558ce8 | 167 | int w32_use_visible_system_caret; |
abb15ebd | 168 | |
e9e23e23 GV |
169 | DWORD dwWindowsThreadId = 0; |
170 | HANDLE hWindowsThread = NULL; | |
ee78dc32 GV |
171 | DWORD dwMainThreadId = 0; |
172 | HANDLE hMainThread = NULL; | |
173 | ||
689004fa GV |
174 | int vertical_scroll_bar_min_handle; |
175 | int vertical_scroll_bar_top_border; | |
176 | int vertical_scroll_bar_bottom_border; | |
177 | ||
178 | int last_scroll_bar_drag_pos; | |
179 | ||
ee78dc32 GV |
180 | /* Mouse movement. */ |
181 | ||
182 | /* Where the mouse was last time we reported a mouse event. */ | |
ee78dc32 | 183 | static RECT last_mouse_glyph; |
d3499758 | 184 | static FRAME_PTR last_mouse_glyph_frame; |
791f420f | 185 | static Lisp_Object last_mouse_press_frame; |
ee78dc32 | 186 | |
e597eb7d | 187 | int w32_num_mouse_buttons; |
52cf03a1 | 188 | |
fbd6baed | 189 | Lisp_Object Vw32_swap_mouse_buttons; |
52cf03a1 | 190 | |
689004fa GV |
191 | /* Control whether x_raise_frame also sets input focus. */ |
192 | Lisp_Object Vw32_grab_focus_on_raise; | |
193 | ||
194 | /* Control whether Caps Lock affects non-ascii characters. */ | |
195 | Lisp_Object Vw32_capslock_is_shiftlock; | |
196 | ||
ef0e360f GV |
197 | /* Control whether right-alt and left-ctrl should be recognized as AltGr. */ |
198 | Lisp_Object Vw32_recognize_altgr; | |
199 | ||
ee78dc32 GV |
200 | /* The scroll bar in which the last motion event occurred. |
201 | ||
202 | If the last motion event occurred in a scroll bar, we set this | |
fbd6baed | 203 | so w32_mouse_position can know whether to report a scroll bar motion or |
ee78dc32 GV |
204 | an ordinary motion. |
205 | ||
206 | If the last motion event didn't occur in a scroll bar, we set this | |
fbd6baed | 207 | to Qnil, to tell w32_mouse_position to return an ordinary motion event. */ |
9ef2e2cf JR |
208 | static Lisp_Object last_mouse_scroll_bar; |
209 | static int last_mouse_scroll_bar_pos; | |
ee78dc32 | 210 | |
fbd6baed | 211 | /* This is a hack. We would really prefer that w32_mouse_position would |
ee78dc32 | 212 | return the time associated with the position it returns, but there |
9ef2e2cf | 213 | doesn't seem to be any way to wrest the time-stamp from the server |
ee78dc32 GV |
214 | along with the position query. So, we just keep track of the time |
215 | of the last movement we received, and return that in hopes that | |
216 | it's somewhat accurate. */ | |
9ef2e2cf JR |
217 | static Time last_mouse_movement_time; |
218 | ||
219 | /* Incremented by w32_read_socket whenever it really tries to read | |
220 | events. */ | |
ee78dc32 GV |
221 | #ifdef __STDC__ |
222 | static int volatile input_signal_count; | |
223 | #else | |
224 | static int input_signal_count; | |
225 | #endif | |
226 | ||
227 | extern Lisp_Object Vcommand_line_args, Vsystem_name; | |
228 | ||
38006079 | 229 | #ifndef USE_CRT_DLL |
ee78dc32 | 230 | extern int errno; |
38006079 | 231 | #endif |
ee78dc32 GV |
232 | |
233 | /* A mask of extra modifier bits to put into every keyboard char. */ | |
31ade731 | 234 | extern EMACS_INT extra_keyboard_modifiers; |
ee78dc32 | 235 | |
13087e59 JR |
236 | /* Keyboard code page - may be changed by language-change events. */ |
237 | static int keyboard_codepage; | |
238 | ||
38006079 | 239 | static void x_update_window_end P_ ((struct window *, int, int)); |
791f420f JR |
240 | static void w32_handle_tool_bar_click P_ ((struct frame *, |
241 | struct input_event *)); | |
1bb8a291 | 242 | static void w32_define_cursor P_ ((Window, Cursor)); |
791f420f JR |
243 | |
244 | void x_lower_frame P_ ((struct frame *)); | |
245 | void x_scroll_bar_clear P_ ((struct frame *)); | |
246 | void x_wm_set_size_hint P_ ((struct frame *, long, int)); | |
247 | void x_raise_frame P_ ((struct frame *)); | |
248 | void x_set_window_size P_ ((struct frame *, int, int, int)); | |
249 | void x_wm_set_window_state P_ ((struct frame *, int)); | |
250 | void x_wm_set_icon_pixmap P_ ((struct frame *, int)); | |
1bb8a291 | 251 | static void w32_initialize P_ ((void)); |
791f420f JR |
252 | static void x_update_end P_ ((struct frame *)); |
253 | static void w32_frame_up_to_date P_ ((struct frame *)); | |
4a418b10 JR |
254 | static void w32_set_terminal_modes P_ ((struct terminal *)); |
255 | static void w32_reset_terminal_modes P_ ((struct terminal *)); | |
256 | static void x_clear_frame P_ ((struct frame *)); | |
791f420f JR |
257 | static void frame_highlight P_ ((struct frame *)); |
258 | static void frame_unhighlight P_ ((struct frame *)); | |
73dc743c JR |
259 | static void x_new_focus_frame P_ ((struct w32_display_info *, |
260 | struct frame *)); | |
55131bef JR |
261 | static void x_focus_changed P_ ((int, int, struct w32_display_info *, |
262 | struct frame *, struct input_event *)); | |
263 | static void w32_detect_focus_change P_ ((struct w32_display_info *, | |
264 | W32Msg *, struct input_event *)); | |
791f420f JR |
265 | static void w32_frame_rehighlight P_ ((struct frame *)); |
266 | static void x_frame_rehighlight P_ ((struct w32_display_info *)); | |
267 | static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); | |
70fa9f1f JR |
268 | static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int, |
269 | enum text_cursor_kinds)); | |
b5a2e277 | 270 | static void w32_clip_to_row P_ ((struct window *, struct glyph_row *, int, HDC)); |
14d050df JB |
271 | static BOOL my_show_window P_ ((struct frame *, HWND, int)); |
272 | static void my_set_window_pos P_ ((HWND, HWND, int, int, int, int, UINT)); | |
273 | static void my_set_focus P_ ((struct frame *, HWND)); | |
274 | static void my_set_foreground_window P_ ((HWND)); | |
275 | static void my_destroy_window P_ ((struct frame *, HWND)); | |
791f420f | 276 | |
ee78dc32 GV |
277 | static Lisp_Object Qvendor_specific_keysyms; |
278 | ||
ee78dc32 | 279 | \f |
9ef2e2cf JR |
280 | /*********************************************************************** |
281 | Debugging | |
282 | ***********************************************************************/ | |
283 | ||
ee78dc32 | 284 | #if 0 |
9ef2e2cf JR |
285 | |
286 | /* This is a function useful for recording debugging information about | |
287 | the sequence of occurrences in this file. */ | |
ee78dc32 | 288 | |
d67d1627 | 289 | struct record |
ee78dc32 GV |
290 | { |
291 | char *locus; | |
292 | int type; | |
293 | }; | |
294 | ||
295 | struct record event_record[100]; | |
296 | ||
297 | int event_record_index; | |
298 | ||
299 | record_event (locus, type) | |
300 | char *locus; | |
301 | int type; | |
302 | { | |
303 | if (event_record_index == sizeof (event_record) / sizeof (struct record)) | |
304 | event_record_index = 0; | |
305 | ||
306 | event_record[event_record_index].locus = locus; | |
307 | event_record[event_record_index].type = type; | |
308 | event_record_index++; | |
309 | } | |
310 | ||
311 | #endif /* 0 */ | |
312 | \f | |
791f420f | 313 | |
c65fd370 RS |
314 | void |
315 | XChangeGC (void * ignore, XGCValues* gc, unsigned long mask, | |
316 | XGCValues *xgcv) | |
791f420f JR |
317 | { |
318 | if (mask & GCForeground) | |
319 | gc->foreground = xgcv->foreground; | |
320 | if (mask & GCBackground) | |
321 | gc->background = xgcv->background; | |
322 | if (mask & GCFont) | |
323 | gc->font = xgcv->font; | |
324 | } | |
325 | ||
326 | XGCValues *XCreateGC (void * ignore, Window window, unsigned long mask, | |
327 | XGCValues *xgcv) | |
328 | { | |
329 | XGCValues *gc = (XGCValues *) xmalloc (sizeof (XGCValues)); | |
330 | bzero (gc, sizeof (XGCValues)); | |
331 | ||
332 | XChangeGC (ignore, gc, mask, xgcv); | |
333 | ||
334 | return gc; | |
335 | } | |
336 | ||
c65fd370 RS |
337 | void |
338 | XGetGCValues (void* ignore, XGCValues *gc, | |
791f420f JR |
339 | unsigned long mask, XGCValues *xgcv) |
340 | { | |
341 | XChangeGC (ignore, xgcv, mask, gc); | |
342 | } | |
343 | ||
791f420f JR |
344 | static void |
345 | w32_set_clip_rectangle (HDC hdc, RECT *rect) | |
346 | { | |
347 | if (rect) | |
348 | { | |
349 | HRGN clip_region = CreateRectRgnIndirect (rect); | |
350 | SelectClipRgn (hdc, clip_region); | |
351 | DeleteObject (clip_region); | |
352 | } | |
353 | else | |
354 | SelectClipRgn (hdc, NULL); | |
355 | } | |
356 | ||
791f420f JR |
357 | |
358 | /* Draw a hollow rectangle at the specified position. */ | |
359 | void | |
360 | w32_draw_rectangle (HDC hdc, XGCValues *gc, int x, int y, | |
361 | int width, int height) | |
362 | { | |
363 | HBRUSH hb, oldhb; | |
364 | HPEN hp, oldhp; | |
365 | ||
366 | hb = CreateSolidBrush (gc->background); | |
367 | hp = CreatePen (PS_SOLID, 0, gc->foreground); | |
368 | oldhb = SelectObject (hdc, hb); | |
369 | oldhp = SelectObject (hdc, hp); | |
370 | ||
371 | Rectangle (hdc, x, y, x + width, y + height); | |
372 | ||
373 | SelectObject (hdc, oldhb); | |
374 | SelectObject (hdc, oldhp); | |
375 | DeleteObject (hb); | |
376 | DeleteObject (hp); | |
377 | } | |
378 | ||
379 | /* Draw a filled rectangle at the specified position. */ | |
d67d1627 | 380 | void |
00fe468b | 381 | w32_fill_rect (f, hdc, pix, lprect) |
ee78dc32 | 382 | FRAME_PTR f; |
00fe468b | 383 | HDC hdc; |
ee78dc32 GV |
384 | COLORREF pix; |
385 | RECT * lprect; | |
386 | { | |
ee78dc32 | 387 | HBRUSH hb; |
791f420f | 388 | |
ee78dc32 | 389 | hb = CreateSolidBrush (pix); |
ee78dc32 | 390 | FillRect (hdc, lprect, hb); |
ee78dc32 | 391 | DeleteObject (hb); |
ee78dc32 GV |
392 | } |
393 | ||
d67d1627 | 394 | void |
fbd6baed | 395 | w32_clear_window (f) |
ee78dc32 GV |
396 | FRAME_PTR f; |
397 | { | |
398 | RECT rect; | |
00fe468b | 399 | HDC hdc = get_frame_dc (f); |
52cf03a1 | 400 | |
e4a52412 JR |
401 | /* Under certain conditions, this can be called at startup with |
402 | a console frame pointer before the GUI frame is created. An HDC | |
403 | of 0 indicates this. */ | |
404 | if (hdc) | |
405 | { | |
406 | GetClientRect (FRAME_W32_WINDOW (f), &rect); | |
407 | w32_clear_rect (f, hdc, &rect); | |
408 | } | |
409 | ||
00fe468b | 410 | release_frame_dc (f, hdc); |
ee78dc32 GV |
411 | } |
412 | ||
8b61a891 JR |
413 | #define OPAQUE_FRAME 255 |
414 | ||
415 | void | |
416 | x_set_frame_alpha (f) | |
417 | struct frame *f; | |
418 | { | |
419 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
420 | double alpha = 1.0; | |
421 | double alpha_min = 1.0; | |
422 | BYTE opac; | |
423 | LONG ex_style; | |
424 | HWND window = FRAME_W32_WINDOW (f); | |
425 | ||
426 | /* Older versions of Windows do not support transparency. */ | |
427 | if (!pfnSetLayeredWindowAttributes) | |
428 | return; | |
429 | ||
430 | if (dpyinfo->x_highlight_frame == f) | |
431 | alpha = f->alpha[0]; | |
432 | else | |
433 | alpha = f->alpha[1]; | |
434 | ||
435 | if (FLOATP (Vframe_alpha_lower_limit)) | |
436 | alpha_min = XFLOAT_DATA (Vframe_alpha_lower_limit); | |
437 | else if (INTEGERP (Vframe_alpha_lower_limit)) | |
438 | alpha_min = (XINT (Vframe_alpha_lower_limit)) / 100.0; | |
439 | ||
2f8e69cc CY |
440 | if (alpha < 0.0) |
441 | return; | |
442 | else if (alpha > 1.0) | |
8b61a891 JR |
443 | alpha = 1.0; |
444 | else if (alpha < alpha_min && alpha_min <= 1.0) | |
445 | alpha = alpha_min; | |
446 | ||
447 | opac = alpha * OPAQUE_FRAME; | |
448 | ||
449 | ex_style = GetWindowLong (window, GWL_EXSTYLE); | |
450 | ||
451 | if (opac == OPAQUE_FRAME) | |
4e179b19 | 452 | ex_style &= ~WS_EX_LAYERED; |
8b61a891 JR |
453 | else |
454 | ex_style |= WS_EX_LAYERED; | |
455 | ||
456 | SetWindowLong (window, GWL_EXSTYLE, ex_style); | |
457 | ||
458 | if (opac != OPAQUE_FRAME) | |
459 | pfnSetLayeredWindowAttributes (window, 0, opac, LWA_ALPHA); | |
460 | } | |
461 | ||
b89c78a5 CY |
462 | int |
463 | x_display_pixel_height (dpyinfo) | |
464 | struct w32_display_info *dpyinfo; | |
465 | { | |
cb4a3e42 JR |
466 | HDC dc = GetDC (NULL); |
467 | int pixels = GetDeviceCaps (dc, VERTRES); | |
468 | ReleaseDC (NULL, dc); | |
469 | return pixels; | |
b89c78a5 CY |
470 | } |
471 | ||
472 | int | |
473 | x_display_pixel_width (dpyinfo) | |
474 | struct w32_display_info *dpyinfo; | |
475 | { | |
cb4a3e42 JR |
476 | HDC dc = GetDC (NULL); |
477 | int pixels = GetDeviceCaps (dc, HORZRES); | |
478 | ReleaseDC (NULL, dc); | |
479 | return pixels; | |
b89c78a5 CY |
480 | } |
481 | ||
ee78dc32 | 482 | \f |
791f420f JR |
483 | /*********************************************************************** |
484 | Starting and ending an update | |
485 | ***********************************************************************/ | |
d67d1627 | 486 | |
791f420f JR |
487 | /* Start an update of frame F. This function is installed as a hook |
488 | for update_begin, i.e. it is called when update_begin is called. | |
489 | This function is called prior to calls to x_update_window_begin for | |
99012074 | 490 | each window being updated. */ |
ee78dc32 | 491 | |
96214669 | 492 | static void |
791f420f | 493 | x_update_begin (f) |
ee78dc32 GV |
494 | struct frame *f; |
495 | { | |
99012074 AI |
496 | struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); |
497 | ||
7e6ac5b9 AI |
498 | if (! FRAME_W32_P (f)) |
499 | return; | |
500 | ||
99012074 AI |
501 | /* Regenerate display palette before drawing if list of requested |
502 | colors has changed. */ | |
503 | if (display_info->regen_palette) | |
504 | { | |
505 | w32_regenerate_palette (f); | |
506 | display_info->regen_palette = FALSE; | |
507 | } | |
791f420f | 508 | } |
ee78dc32 | 509 | |
791f420f JR |
510 | |
511 | /* Start update of window W. Set the global variable updated_window | |
512 | to the window being updated and set output_cursor to the cursor | |
513 | position of W. */ | |
514 | ||
515 | static void | |
516 | x_update_window_begin (w) | |
517 | struct window *w; | |
518 | { | |
519 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
520 | struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); | |
521 | ||
99558ce8 | 522 | /* Hide the system caret during an update. */ |
9785d95b BK |
523 | if (w32_use_visible_system_caret && w32_system_caret_hwnd) |
524 | { | |
525 | SendMessage (w32_system_caret_hwnd, WM_EMACS_HIDE_CARET, 0, 0); | |
526 | } | |
99558ce8 | 527 | |
791f420f JR |
528 | updated_window = w; |
529 | set_output_cursor (&w->cursor); | |
ee78dc32 GV |
530 | |
531 | BLOCK_INPUT; | |
532 | ||
791f420f | 533 | if (f == display_info->mouse_face_mouse_frame) |
ee78dc32 GV |
534 | { |
535 | /* Don't do highlighting for mouse motion during the update. */ | |
791f420f | 536 | display_info->mouse_face_defer = 1; |
ee78dc32 | 537 | |
9ef2e2cf JR |
538 | /* If F needs to be redrawn, simply forget about any prior mouse |
539 | highlighting. */ | |
ee78dc32 | 540 | if (FRAME_GARBAGED_P (f)) |
791f420f JR |
541 | display_info->mouse_face_window = Qnil; |
542 | ||
ec48c3a7 JR |
543 | #if 0 /* Rows in a current matrix containing glyphs in mouse-face have |
544 | their mouse_face_p flag set, which means that they are always | |
545 | unequal to rows in a desired matrix which never have that | |
546 | flag set. So, rows containing mouse-face glyphs are never | |
547 | scrolled, and we don't have to switch the mouse highlight off | |
548 | here to prevent it from being scrolled. */ | |
d67d1627 | 549 | |
791f420f JR |
550 | /* Can we tell that this update does not affect the window |
551 | where the mouse highlight is? If so, no need to turn off. | |
552 | Likewise, don't do anything if the frame is garbaged; | |
553 | in that case, the frame's current matrix that we would use | |
554 | is all wrong, and we will redisplay that line anyway. */ | |
555 | if (!NILP (display_info->mouse_face_window) | |
556 | && w == XWINDOW (display_info->mouse_face_window)) | |
ee78dc32 | 557 | { |
791f420f | 558 | int i; |
ee78dc32 | 559 | |
791f420f JR |
560 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
561 | if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) | |
ee78dc32 GV |
562 | break; |
563 | ||
791f420f JR |
564 | if (i < w->desired_matrix->nrows) |
565 | clear_mouse_face (display_info); | |
ee78dc32 | 566 | } |
ec48c3a7 | 567 | #endif /* 0 */ |
ee78dc32 GV |
568 | } |
569 | ||
570 | UNBLOCK_INPUT; | |
571 | } | |
572 | ||
89271099 | 573 | /* Draw a vertical window border from (x,y0) to (x,y1) */ |
791f420f | 574 | |
96214669 | 575 | static void |
89271099 | 576 | w32_draw_vertical_window_border (w, x, y0, y1) |
791f420f | 577 | struct window *w; |
89271099 | 578 | int x, y0, y1; |
ee78dc32 | 579 | { |
791f420f | 580 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
89271099 KS |
581 | RECT r; |
582 | HDC hdc; | |
cf2c08ca | 583 | struct face *face; |
1c64a4a2 | 584 | |
89271099 KS |
585 | r.left = x; |
586 | r.right = x + 1; | |
587 | r.top = y0; | |
588 | r.bottom = y1; | |
d67d1627 | 589 | |
89271099 | 590 | hdc = get_frame_dc (f); |
cf2c08ca EZ |
591 | face = FACE_FROM_ID (f, VERTICAL_BORDER_FACE_ID); |
592 | if (face) | |
593 | w32_fill_rect (f, hdc, face->foreground, &r); | |
594 | else | |
595 | w32_fill_rect (f, hdc, FRAME_FOREGROUND_PIXEL (f), &r); | |
596 | ||
89271099 | 597 | release_frame_dc (f, hdc); |
791f420f | 598 | } |
ee78dc32 | 599 | |
d67d1627 | 600 | |
ec48c3a7 JR |
601 | /* End update of window W (which is equal to updated_window). |
602 | ||
603 | Draw vertical borders between horizontally adjacent windows, and | |
604 | display W's cursor if CURSOR_ON_P is non-zero. | |
605 | ||
606 | MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing | |
607 | glyphs in mouse-face were overwritten. In that case we have to | |
608 | make sure that the mouse-highlight is properly redrawn. | |
609 | ||
610 | W may be a menu bar pseudo-window in case we don't have X toolkit | |
611 | support. Such windows don't have a cursor, so don't display it | |
612 | here. */ | |
791f420f JR |
613 | |
614 | static void | |
ec48c3a7 | 615 | x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p) |
791f420f | 616 | struct window *w; |
ec48c3a7 | 617 | int cursor_on_p, mouse_face_overwritten_p; |
791f420f | 618 | { |
89271099 | 619 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); |
9f5a911b | 620 | |
791f420f JR |
621 | if (!w->pseudo_window_p) |
622 | { | |
623 | BLOCK_INPUT; | |
ec48c3a7 | 624 | |
791f420f | 625 | if (cursor_on_p) |
89271099 KS |
626 | display_and_set_cursor (w, 1, output_cursor.hpos, |
627 | output_cursor.vpos, | |
628 | output_cursor.x, output_cursor.y); | |
d67d1627 | 629 | |
f94a2622 KS |
630 | if (draw_window_fringes (w, 1)) |
631 | x_draw_vertical_border (w); | |
6b61353c | 632 | |
791f420f JR |
633 | UNBLOCK_INPUT; |
634 | } | |
9f5a911b JR |
635 | |
636 | /* If a row with mouse-face was overwritten, arrange for | |
637 | XTframe_up_to_date to redisplay the mouse highlight. */ | |
638 | if (mouse_face_overwritten_p) | |
639 | { | |
640 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
641 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
642 | dpyinfo->mouse_face_window = Qnil; | |
643 | } | |
644 | ||
99558ce8 JR |
645 | /* Unhide the caret. This won't actually show the cursor, unless it |
646 | was visible before the corresponding call to HideCaret in | |
647 | x_update_window_begin. */ | |
9785d95b BK |
648 | if (w32_use_visible_system_caret && w32_system_caret_hwnd) |
649 | { | |
650 | SendMessage (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0); | |
651 | } | |
99558ce8 | 652 | |
791f420f JR |
653 | updated_window = NULL; |
654 | } | |
655 | ||
9ef2e2cf JR |
656 | |
657 | /* End update of frame F. This function is installed as a hook in | |
658 | update_end. */ | |
659 | ||
791f420f JR |
660 | static void |
661 | x_update_end (f) | |
662 | struct frame *f; | |
663 | { | |
7e6ac5b9 AI |
664 | if (! FRAME_W32_P (f)) |
665 | return; | |
666 | ||
791f420f JR |
667 | /* Mouse highlight may be displayed again. */ |
668 | FRAME_W32_DISPLAY_INFO (f)->mouse_face_defer = 0; | |
ee78dc32 GV |
669 | } |
670 | ||
9ef2e2cf | 671 | |
791f420f JR |
672 | /* This function is called from various places in xdisp.c whenever a |
673 | complete update has been performed. The global variable | |
674 | updated_window is not available here. */ | |
ee78dc32 | 675 | |
96214669 | 676 | static void |
fbd6baed | 677 | w32_frame_up_to_date (f) |
791f420f | 678 | struct frame *f; |
ee78dc32 | 679 | { |
791f420f | 680 | if (FRAME_W32_P (f)) |
ee78dc32 | 681 | { |
791f420f | 682 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
89271099 | 683 | |
791f420f JR |
684 | if (dpyinfo->mouse_face_deferred_gc |
685 | || f == dpyinfo->mouse_face_mouse_frame) | |
686 | { | |
687 | BLOCK_INPUT; | |
688 | if (dpyinfo->mouse_face_mouse_frame) | |
689 | note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, | |
690 | dpyinfo->mouse_face_mouse_x, | |
691 | dpyinfo->mouse_face_mouse_y); | |
692 | dpyinfo->mouse_face_deferred_gc = 0; | |
693 | UNBLOCK_INPUT; | |
694 | } | |
ee78dc32 GV |
695 | } |
696 | } | |
791f420f JR |
697 | |
698 | ||
699 | /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay | |
33c34bea | 700 | arrow bitmaps, or clear the fringes if no bitmaps are required |
791f420f | 701 | before DESIRED_ROW is made current. The window being updated is |
b71b8111 | 702 | found in updated_window. This function is called from |
791f420f JR |
703 | update_window_line only if it is known that there are differences |
704 | between bitmaps to be drawn between current row and DESIRED_ROW. */ | |
705 | ||
706 | static void | |
707 | x_after_update_window_line (desired_row) | |
708 | struct glyph_row *desired_row; | |
709 | { | |
710 | struct window *w = updated_window; | |
6ff3e5e3 JR |
711 | struct frame *f; |
712 | int width, height; | |
713 | ||
791f420f | 714 | xassert (w); |
d67d1627 | 715 | |
791f420f | 716 | if (!desired_row->mode_line_p && !w->pseudo_window_p) |
6b61353c | 717 | desired_row->redraw_fringe_bitmaps_p = 1; |
791f420f | 718 | |
6ff3e5e3 JR |
719 | /* When a window has disappeared, make sure that no rest of |
720 | full-width rows stays visible in the internal border. Could | |
721 | check here if updated_window is the leftmost/rightmost window, | |
722 | but I guess it's not worth doing since vertically split windows | |
723 | are almost never used, internal border is rarely set, and the | |
724 | overhead is very small. */ | |
725 | if (windows_or_buffers_changed | |
726 | && desired_row->full_width_p | |
727 | && (f = XFRAME (w->frame), | |
728 | width = FRAME_INTERNAL_BORDER_WIDTH (f), | |
729 | width != 0) | |
730 | && (height = desired_row->visible_height, | |
731 | height > 0)) | |
732 | { | |
733 | int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); | |
89271099 | 734 | |
6ff3e5e3 JR |
735 | /* Internal border is drawn below the tool bar. */ |
736 | if (WINDOWP (f->tool_bar_window) | |
737 | && w == XWINDOW (f->tool_bar_window)) | |
738 | y -= width; | |
739 | ||
740 | BLOCK_INPUT; | |
741 | { | |
742 | HDC hdc = get_frame_dc (f); | |
743 | w32_clear_area (f, hdc, 0, y, width, height); | |
62e50ec6 | 744 | w32_clear_area (f, hdc, FRAME_PIXEL_WIDTH (f) - width, |
6ff3e5e3 JR |
745 | y, width, height); |
746 | release_frame_dc (f, hdc); | |
747 | } | |
791f420f JR |
748 | UNBLOCK_INPUT; |
749 | } | |
750 | } | |
751 | ||
752 | ||
33c34bea | 753 | /* Draw the bitmap WHICH in one of the left or right fringes of |
791f420f JR |
754 | window W. ROW is the glyph row for which to display the bitmap; it |
755 | determines the vertical position at which the bitmap has to be | |
756 | drawn. */ | |
757 | ||
758 | static void | |
b6ae1532 | 759 | w32_draw_fringe_bitmap (w, row, p) |
791f420f | 760 | struct window *w; |
791f420f | 761 | struct glyph_row *row; |
b6ae1532 | 762 | struct draw_fringe_bitmap_params *p; |
791f420f JR |
763 | { |
764 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
b6ae1532 KS |
765 | HDC hdc; |
766 | struct face *face = p->face; | |
6b61353c | 767 | int rowY; |
b6ae1532 KS |
768 | |
769 | hdc = get_frame_dc (f); | |
791f420f | 770 | |
06929222 YM |
771 | if (!p->overlay_p) |
772 | { | |
773 | int bx = p->bx, by = p->by, nx = p->nx, ny = p->ny; | |
774 | ||
775 | /* If the fringe is adjacent to the left (right) scroll bar of a | |
776 | leftmost (rightmost, respectively) window, then extend its | |
777 | background to the gap between the fringe and the bar. */ | |
778 | if ((WINDOW_LEFTMOST_P (w) | |
779 | && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) | |
780 | || (WINDOW_RIGHTMOST_P (w) | |
781 | && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w))) | |
782 | { | |
783 | int sb_width = WINDOW_CONFIG_SCROLL_BAR_WIDTH (w); | |
784 | ||
785 | if (sb_width > 0) | |
786 | { | |
787 | int left = WINDOW_SCROLL_BAR_AREA_X (w); | |
788 | int width = (WINDOW_CONFIG_SCROLL_BAR_COLS (w) | |
789 | * FRAME_COLUMN_WIDTH (f)); | |
790 | ||
791 | if (bx < 0) | |
792 | { | |
793 | /* Bitmap fills the fringe. */ | |
794 | if (left + width == p->x) | |
795 | bx = left + sb_width; | |
796 | else if (p->x + p->wd == left) | |
797 | bx = left; | |
798 | if (bx >= 0) | |
799 | { | |
800 | int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w); | |
801 | ||
802 | nx = width - sb_width; | |
803 | by = WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
804 | row->y)); | |
805 | ny = row->visible_height; | |
806 | } | |
807 | } | |
808 | else | |
809 | { | |
810 | if (left + width == bx) | |
811 | { | |
812 | bx = left + sb_width; | |
813 | nx += width - sb_width; | |
814 | } | |
815 | else if (bx + nx == left) | |
816 | nx += width - sb_width; | |
817 | } | |
818 | } | |
819 | } | |
820 | ||
821 | if (bx >= 0 && nx > 0) | |
822 | w32_fill_area (f, hdc, face->background, bx, by, nx, ny); | |
823 | } | |
824 | ||
791f420f | 825 | /* Must clip because of partially visible lines. */ |
6b61353c KH |
826 | rowY = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); |
827 | if (p->y < rowY) | |
828 | { | |
829 | /* Adjust position of "bottom aligned" bitmap on partially | |
830 | visible last row. */ | |
831 | int oldY = row->y; | |
832 | int oldVH = row->visible_height; | |
833 | row->visible_height = p->h; | |
834 | row->y -= rowY - p->y; | |
b5a2e277 | 835 | w32_clip_to_row (w, row, -1, hdc); |
6b61353c KH |
836 | row->y = oldY; |
837 | row->visible_height = oldVH; | |
838 | } | |
839 | else | |
b5a2e277 | 840 | w32_clip_to_row (w, row, -1, hdc); |
791f420f | 841 | |
0e9e9a2c | 842 | if (p->which && p->which < max_fringe_bmp) |
b6ae1532 KS |
843 | { |
844 | HBITMAP pixmap = fringe_bmp[p->which]; | |
845 | HDC compat_hdc; | |
846 | HANDLE horig_obj; | |
791f420f | 847 | |
b6ae1532 | 848 | compat_hdc = CreateCompatibleDC (hdc); |
6b61353c | 849 | |
b6ae1532 | 850 | SaveDC (hdc); |
791f420f | 851 | |
b6ae1532 | 852 | horig_obj = SelectObject (compat_hdc, pixmap); |
fccb8288 | 853 | |
6b61353c KH |
854 | /* Paint overlays transparently. */ |
855 | if (p->overlay_p) | |
856 | { | |
857 | HBRUSH h_brush, h_orig_brush; | |
858 | ||
859 | SetTextColor (hdc, BLACK_PIX_DEFAULT (f)); | |
860 | SetBkColor (hdc, WHITE_PIX_DEFAULT (f)); | |
861 | h_brush = CreateSolidBrush (face->foreground); | |
862 | h_orig_brush = SelectObject (hdc, h_brush); | |
863 | ||
864 | BitBlt (hdc, p->x, p->y, p->wd, p->h, | |
865 | compat_hdc, 0, p->dh, | |
866 | DSTINVERT); | |
867 | BitBlt (hdc, p->x, p->y, p->wd, p->h, | |
868 | compat_hdc, 0, p->dh, | |
869 | 0x2E064A); | |
870 | BitBlt (hdc, p->x, p->y, p->wd, p->h, | |
871 | compat_hdc, 0, p->dh, | |
872 | DSTINVERT); | |
873 | ||
874 | SelectObject (hdc, h_orig_brush); | |
875 | DeleteObject (h_brush); | |
876 | } | |
877 | else | |
878 | { | |
879 | SetTextColor (hdc, face->background); | |
880 | SetBkColor (hdc, (p->cursor_p | |
881 | ? f->output_data.w32->cursor_pixel | |
882 | : face->foreground)); | |
883 | ||
884 | BitBlt (hdc, p->x, p->y, p->wd, p->h, | |
885 | compat_hdc, 0, p->dh, | |
886 | SRCCOPY); | |
887 | } | |
791f420f | 888 | |
b6ae1532 KS |
889 | SelectObject (compat_hdc, horig_obj); |
890 | DeleteDC (compat_hdc); | |
891 | RestoreDC (hdc, -1); | |
d33c49e8 | 892 | } |
791f420f | 893 | |
b6ae1532 | 894 | w32_set_clip_rectangle (hdc, NULL); |
791f420f | 895 | |
791f420f JR |
896 | release_frame_dc (f, hdc); |
897 | } | |
898 | ||
6b61353c KH |
899 | static void |
900 | w32_define_fringe_bitmap (which, bits, h, wd) | |
901 | int which; | |
902 | unsigned short *bits; | |
903 | int h, wd; | |
904 | { | |
0e9e9a2c KS |
905 | if (which >= max_fringe_bmp) |
906 | { | |
907 | int i = max_fringe_bmp; | |
908 | max_fringe_bmp = which + 20; | |
909 | fringe_bmp = (HBITMAP *) xrealloc (fringe_bmp, max_fringe_bmp * sizeof (HBITMAP)); | |
910 | while (i < max_fringe_bmp) | |
911 | fringe_bmp[i++] = 0; | |
912 | } | |
913 | ||
6b61353c KH |
914 | fringe_bmp[which] = CreateBitmap (wd, h, 1, 1, bits); |
915 | } | |
916 | ||
917 | static void | |
918 | w32_destroy_fringe_bitmap (which) | |
919 | int which; | |
920 | { | |
0e9e9a2c KS |
921 | if (which >= max_fringe_bmp) |
922 | return; | |
923 | ||
6b61353c KH |
924 | if (fringe_bmp[which]) |
925 | DeleteObject (fringe_bmp[which]); | |
926 | fringe_bmp[which] = 0; | |
927 | } | |
928 | ||
929 | ||
ee78dc32 | 930 | \f |
9ef2e2cf JR |
931 | /* This is called when starting Emacs and when restarting after |
932 | suspend. When starting Emacs, no window is mapped. And nothing | |
933 | must be done to Emacs's own window if it is suspended (though that | |
934 | rarely happens). */ | |
ee78dc32 | 935 | |
96214669 | 936 | static void |
4a418b10 | 937 | w32_set_terminal_modes (struct terminal *term) |
ee78dc32 GV |
938 | { |
939 | } | |
940 | ||
9ef2e2cf JR |
941 | /* This is called when exiting or suspending Emacs. Exiting will make |
942 | the W32 windows go away, and suspending requires no action. */ | |
ee78dc32 | 943 | |
96214669 | 944 | static void |
4a418b10 | 945 | w32_reset_terminal_modes (struct terminal *term) |
ee78dc32 GV |
946 | { |
947 | } | |
791f420f | 948 | |
9ef2e2cf | 949 | |
ee78dc32 | 950 | \f |
791f420f JR |
951 | /*********************************************************************** |
952 | Display Iterator | |
953 | ***********************************************************************/ | |
954 | ||
955 | /* Function prototypes of this page. */ | |
956 | ||
791f420f JR |
957 | static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); |
958 | static void x_set_glyph_string_gc P_ ((struct glyph_string *)); | |
959 | static void x_draw_glyph_string_background P_ ((struct glyph_string *, | |
960 | int)); | |
961 | static void x_draw_glyph_string_foreground P_ ((struct glyph_string *)); | |
962 | static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *)); | |
791f420f JR |
963 | static void x_draw_glyph_string_box P_ ((struct glyph_string *)); |
964 | static void x_draw_glyph_string P_ ((struct glyph_string *)); | |
791f420f JR |
965 | static void x_set_cursor_gc P_ ((struct glyph_string *)); |
966 | static void x_set_mode_line_face_gc P_ ((struct glyph_string *)); | |
967 | static void x_set_mouse_face_gc P_ ((struct glyph_string *)); | |
791f420f JR |
968 | static int w32_alloc_lighter_color (struct frame *, COLORREF *, double, int); |
969 | static void w32_setup_relief_color P_ ((struct frame *, struct relief *, | |
970 | double, int, COLORREF)); | |
971 | static void x_setup_relief_colors P_ ((struct glyph_string *)); | |
972 | static void x_draw_image_glyph_string P_ ((struct glyph_string *)); | |
973 | static void x_draw_image_relief P_ ((struct glyph_string *)); | |
974 | static void x_draw_image_foreground P_ ((struct glyph_string *)); | |
975 | static void w32_draw_image_foreground_1 P_ ((struct glyph_string *, HBITMAP)); | |
791f420f JR |
976 | static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, |
977 | int, int, int)); | |
978 | static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int, | |
cb0b194a KS |
979 | int, int, int, int, int, int, |
980 | RECT *)); | |
791f420f JR |
981 | static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, |
982 | int, int, int, RECT *)); | |
c2cc16fa | 983 | |
d67d1627 | 984 | |
791f420f JR |
985 | /* Set S->gc to a suitable GC for drawing glyph string S in cursor |
986 | face. */ | |
987 | ||
988 | static void | |
989 | x_set_cursor_gc (s) | |
990 | struct glyph_string *s; | |
991 | { | |
992 | if (s->font == FRAME_FONT (s->f) | |
993 | && s->face->background == FRAME_BACKGROUND_PIXEL (s->f) | |
994 | && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f) | |
995 | && !s->cmp) | |
996 | s->gc = s->f->output_data.w32->cursor_gc; | |
997 | else | |
998 | { | |
999 | /* Cursor on non-default face: must merge. */ | |
1000 | XGCValues xgcv; | |
1001 | unsigned long mask; | |
1002 | ||
1003 | xgcv.background = s->f->output_data.w32->cursor_pixel; | |
1004 | xgcv.foreground = s->face->background; | |
1005 | ||
1006 | /* If the glyph would be invisible, try a different foreground. */ | |
1007 | if (xgcv.foreground == xgcv.background) | |
1008 | xgcv.foreground = s->face->foreground; | |
1009 | if (xgcv.foreground == xgcv.background) | |
1010 | xgcv.foreground = s->f->output_data.w32->cursor_foreground_pixel; | |
1011 | if (xgcv.foreground == xgcv.background) | |
1012 | xgcv.foreground = s->face->foreground; | |
1013 | ||
1014 | /* Make sure the cursor is distinct from text in this face. */ | |
1015 | if (xgcv.background == s->face->background | |
1016 | && xgcv.foreground == s->face->foreground) | |
1017 | { | |
1018 | xgcv.background = s->face->foreground; | |
1019 | xgcv.foreground = s->face->background; | |
1020 | } | |
1021 | ||
1022 | IF_DEBUG (x_check_font (s->f, s->font)); | |
1023 | xgcv.font = s->font; | |
1024 | mask = GCForeground | GCBackground | GCFont; | |
1025 | ||
1026 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
1027 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
1028 | mask, &xgcv); | |
1029 | else | |
1030 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
1031 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
1032 | ||
1033 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
1034 | } | |
1035 | } | |
1036 | ||
1037 | ||
1038 | /* Set up S->gc of glyph string S for drawing text in mouse face. */ | |
d67d1627 | 1039 | |
791f420f JR |
1040 | static void |
1041 | x_set_mouse_face_gc (s) | |
1042 | struct glyph_string *s; | |
d67d1627 | 1043 | { |
791f420f | 1044 | int face_id; |
93ff4395 | 1045 | struct face *face; |
791f420f | 1046 | |
c2cc16fa | 1047 | /* What face has to be used last for the mouse face? */ |
791f420f | 1048 | face_id = FRAME_W32_DISPLAY_INFO (s->f)->mouse_face_face_id; |
93ff4395 | 1049 | face = FACE_FROM_ID (s->f, face_id); |
c2cc16fa JR |
1050 | if (face == NULL) |
1051 | face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); | |
d67d1627 | 1052 | |
c2cc16fa | 1053 | if (s->first_glyph->type == CHAR_GLYPH) |
14ee5d4c | 1054 | face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch, -1, Qnil); |
c2cc16fa | 1055 | else |
14ee5d4c | 1056 | face_id = FACE_FOR_CHAR (s->f, face, 0, -1, Qnil); |
791f420f JR |
1057 | s->face = FACE_FROM_ID (s->f, face_id); |
1058 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); | |
1059 | ||
1060 | /* If font in this face is same as S->font, use it. */ | |
1061 | if (s->font == s->face->font) | |
1062 | s->gc = s->face->gc; | |
1063 | else | |
1064 | { | |
1065 | /* Otherwise construct scratch_cursor_gc with values from FACE | |
1066 | but font FONT. */ | |
1067 | XGCValues xgcv; | |
1068 | unsigned long mask; | |
d67d1627 | 1069 | |
791f420f JR |
1070 | xgcv.background = s->face->background; |
1071 | xgcv.foreground = s->face->foreground; | |
1072 | IF_DEBUG (x_check_font (s->f, s->font)); | |
1073 | xgcv.font = s->font; | |
1074 | mask = GCForeground | GCBackground | GCFont; | |
d67d1627 | 1075 | |
791f420f JR |
1076 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) |
1077 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
1078 | mask, &xgcv); | |
1079 | else | |
1080 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
1081 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
d67d1627 | 1082 | |
791f420f JR |
1083 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; |
1084 | } | |
1085 | ||
1086 | xassert (s->gc != 0); | |
1087 | } | |
1088 | ||
1089 | ||
1090 | /* Set S->gc of glyph string S to a GC suitable for drawing a mode line. | |
1091 | Faces to use in the mode line have already been computed when the | |
1092 | matrix was built, so there isn't much to do, here. */ | |
1093 | ||
1094 | static INLINE void | |
1095 | x_set_mode_line_face_gc (s) | |
1096 | struct glyph_string *s; | |
d67d1627 | 1097 | { |
791f420f | 1098 | s->gc = s->face->gc; |
791f420f JR |
1099 | } |
1100 | ||
1101 | ||
1102 | /* Set S->gc of glyph string S for drawing that glyph string. Set | |
1103 | S->stippled_p to a non-zero value if the face of S has a stipple | |
1104 | pattern. */ | |
1105 | ||
1106 | static INLINE void | |
1107 | x_set_glyph_string_gc (s) | |
1108 | struct glyph_string *s; | |
1109 | { | |
ec48c3a7 | 1110 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); |
d67d1627 | 1111 | |
791f420f JR |
1112 | if (s->hl == DRAW_NORMAL_TEXT) |
1113 | { | |
1114 | s->gc = s->face->gc; | |
1115 | s->stippled_p = s->face->stipple != 0; | |
1116 | } | |
1117 | else if (s->hl == DRAW_INVERSE_VIDEO) | |
1118 | { | |
1119 | x_set_mode_line_face_gc (s); | |
1120 | s->stippled_p = s->face->stipple != 0; | |
1121 | } | |
1122 | else if (s->hl == DRAW_CURSOR) | |
1123 | { | |
1124 | x_set_cursor_gc (s); | |
1125 | s->stippled_p = 0; | |
1126 | } | |
1127 | else if (s->hl == DRAW_MOUSE_FACE) | |
1128 | { | |
1129 | x_set_mouse_face_gc (s); | |
1130 | s->stippled_p = s->face->stipple != 0; | |
1131 | } | |
1132 | else if (s->hl == DRAW_IMAGE_RAISED | |
1133 | || s->hl == DRAW_IMAGE_SUNKEN) | |
1134 | { | |
1135 | s->gc = s->face->gc; | |
1136 | s->stippled_p = s->face->stipple != 0; | |
1137 | } | |
1138 | else | |
1139 | { | |
1140 | s->gc = s->face->gc; | |
1141 | s->stippled_p = s->face->stipple != 0; | |
1142 | } | |
1143 | ||
1144 | /* GC must have been set. */ | |
1145 | xassert (s->gc != 0); | |
1146 | } | |
1147 | ||
1148 | ||
791f420f JR |
1149 | /* Set clipping for output of glyph string S. S may be part of a mode |
1150 | line or menu if we don't have X toolkit support. */ | |
1151 | ||
1152 | static INLINE void | |
1153 | x_set_glyph_string_clipping (s) | |
1154 | struct glyph_string *s; | |
1155 | { | |
3ca3504a | 1156 | RECT *r = s->clip; |
3ca3504a JR |
1157 | int n = get_glyph_string_clip_rects (s, r, 2); |
1158 | ||
1159 | if (n == 1) | |
1160 | w32_set_clip_rectangle (s->hdc, r); | |
1161 | else if (n > 1) | |
1162 | { | |
1163 | HRGN full_clip, clip1, clip2; | |
1164 | clip1 = CreateRectRgnIndirect (r); | |
1165 | clip2 = CreateRectRgnIndirect (r + 1); | |
1166 | if (CombineRgn (full_clip, clip1, clip2, RGN_OR) != ERROR) | |
1167 | { | |
1168 | SelectClipRgn (s->hdc, full_clip); | |
1169 | } | |
1170 | DeleteObject (clip1); | |
1171 | DeleteObject (clip2); | |
1172 | DeleteObject (full_clip); | |
1173 | } | |
3ca3504a | 1174 | s->num_clips = n; |
791f420f JR |
1175 | } |
1176 | ||
027f6f90 JR |
1177 | /* Set SRC's clipping for output of glyph string DST. This is called |
1178 | when we are drawing DST's left_overhang or right_overhang only in | |
1179 | the area of SRC. */ | |
1180 | ||
1181 | static void | |
1182 | x_set_glyph_string_clipping_exactly (src, dst) | |
1183 | struct glyph_string *src, *dst; | |
1184 | { | |
1185 | RECT r; | |
1186 | ||
ef39ccbb KH |
1187 | r.left = src->x; |
1188 | r.right = r.left + src->width; | |
1189 | r.top = src->y; | |
1190 | r.bottom = r.top + src->height; | |
1191 | dst->clip[0] = r; | |
1192 | dst->num_clips = 1; | |
027f6f90 JR |
1193 | w32_set_clip_rectangle (dst->hdc, &r); |
1194 | } | |
791f420f | 1195 | |
6b6bd726 | 1196 | /* RIF: |
ef39ccbb | 1197 | Compute left and right overhang of glyph string S. */ |
791f420f | 1198 | |
6b6bd726 KS |
1199 | static void |
1200 | w32_compute_glyph_string_overhangs (s) | |
791f420f JR |
1201 | struct glyph_string *s; |
1202 | { | |
cf907d69 | 1203 | if (s->cmp == NULL |
ef39ccbb KH |
1204 | && s->first_glyph->type == CHAR_GLYPH |
1205 | && !s->font_not_found_p) | |
cf907d69 | 1206 | { |
ef39ccbb KH |
1207 | unsigned *code = alloca (sizeof (unsigned) * s->nchars); |
1208 | struct font *font = s->font; | |
1209 | struct font_metrics metrics; | |
1210 | int i; | |
cf907d69 | 1211 | |
ef39ccbb KH |
1212 | for (i = 0; i < s->nchars; i++) |
1213 | code[i] = s->char2b[i]; | |
1214 | font->driver->text_extents (font, code, s->nchars, &metrics); | |
1215 | s->right_overhang = (metrics.rbearing > metrics.width | |
1216 | ? metrics.rbearing - metrics.width : 0); | |
1217 | s->left_overhang = metrics.lbearing < 0 ? -metrics.lbearing : 0; | |
cf907d69 JR |
1218 | } |
1219 | else if (s->cmp) | |
1220 | { | |
1221 | s->right_overhang = s->cmp->rbearing - s->cmp->pixel_width; | |
1222 | s->left_overhang = -s->cmp->lbearing; | |
1223 | } | |
791f420f JR |
1224 | } |
1225 | ||
791f420f JR |
1226 | /* Fill rectangle X, Y, W, H with background color of glyph string S. */ |
1227 | ||
1228 | static INLINE void | |
1229 | x_clear_glyph_string_rect (s, x, y, w, h) | |
1230 | struct glyph_string *s; | |
1231 | int x, y, w, h; | |
1232 | { | |
1233 | int real_x = x; | |
1234 | int real_y = y; | |
1235 | int real_w = w; | |
1236 | int real_h = h; | |
1237 | #if 0 | |
1238 | /* Take clipping into account. */ | |
1239 | if (s->gc->clip_mask == Rect) | |
1240 | { | |
1241 | real_x = max (real_x, s->gc->clip_rectangle.left); | |
1242 | real_y = max (real_y, s->gc->clip_rectangle.top); | |
1243 | real_w = min (real_w, s->gc->clip_rectangle.right | |
1244 | - s->gc->clip_rectangle.left); | |
1245 | real_h = min (real_h, s->gc->clip_rectangle.bottom | |
1246 | - s->gc->clip_rectangle.top); | |
1247 | } | |
1248 | #endif | |
1249 | w32_fill_area (s->f, s->hdc, s->gc->background, real_x, real_y, | |
1250 | real_w, real_h); | |
1251 | } | |
1252 | ||
1253 | ||
1254 | /* Draw the background of glyph_string S. If S->background_filled_p | |
1255 | is non-zero don't draw it. FORCE_P non-zero means draw the | |
1256 | background even if it wouldn't be drawn normally. This is used | |
1257 | when a string preceding S draws into the background of S, or S | |
1258 | contains the first component of a composition. */ | |
1259 | ||
1260 | static void | |
1261 | x_draw_glyph_string_background (s, force_p) | |
1262 | struct glyph_string *s; | |
1263 | int force_p; | |
1264 | { | |
1265 | /* Nothing to do if background has already been drawn or if it | |
1266 | shouldn't be drawn in the first place. */ | |
1267 | if (!s->background_filled_p) | |
1268 | { | |
60222d69 AI |
1269 | int box_line_width = max (s->face->box_line_width, 0); |
1270 | ||
01b220b6 | 1271 | #if 0 /* TODO: stipple */ |
791f420f JR |
1272 | if (s->stippled_p) |
1273 | { | |
1274 | /* Fill background with a stipple pattern. */ | |
1275 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
1276 | XFillRectangle (s->display, s->window, s->gc, s->x, | |
60222d69 | 1277 | s->y + box_line_width, |
791f420f | 1278 | s->background_width, |
60222d69 | 1279 | s->height - 2 * box_line_width); |
791f420f JR |
1280 | XSetFillStyle (s->display, s->gc, FillSolid); |
1281 | s->background_filled_p = 1; | |
1282 | } | |
1283 | else | |
1284 | #endif | |
60222d69 | 1285 | if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width |
791f420f JR |
1286 | || s->font_not_found_p |
1287 | || s->extends_to_end_of_line_p | |
1288 | || force_p) | |
1289 | { | |
60222d69 | 1290 | x_clear_glyph_string_rect (s, s->x, s->y + box_line_width, |
791f420f | 1291 | s->background_width, |
60222d69 | 1292 | s->height - 2 * box_line_width); |
791f420f JR |
1293 | s->background_filled_p = 1; |
1294 | } | |
1295 | } | |
1296 | } | |
1297 | ||
1298 | ||
1299 | /* Draw the foreground of glyph string S. */ | |
1300 | ||
1301 | static void | |
1302 | x_draw_glyph_string_foreground (s) | |
1303 | struct glyph_string *s; | |
1304 | { | |
1305 | int i, x; | |
1306 | ||
1307 | /* If first glyph of S has a left box line, start drawing the text | |
1308 | of S to the right of that box line. */ | |
1309 | if (s->face->box != FACE_NO_BOX | |
1310 | && s->first_glyph->left_box_line_p) | |
1ea40aa2 | 1311 | x = s->x + eabs (s->face->box_line_width); |
791f420f JR |
1312 | else |
1313 | x = s->x; | |
1314 | ||
791f420f JR |
1315 | SetTextColor (s->hdc, s->gc->foreground); |
1316 | SetBkColor (s->hdc, s->gc->background); | |
1317 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | |
1318 | ||
791f420f JR |
1319 | /* Draw characters of S as rectangles if S's font could not be |
1320 | loaded. */ | |
1321 | if (s->font_not_found_p) | |
1322 | { | |
1323 | for (i = 0; i < s->nchars; ++i) | |
1324 | { | |
1325 | struct glyph *g = s->first_glyph + i; | |
1326 | ||
1327 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, g->pixel_width - 1, | |
1328 | s->height - 1); | |
1329 | x += g->pixel_width; | |
1330 | } | |
1331 | } | |
ef39ccbb | 1332 | else |
027f6f90 | 1333 | { |
c35f9821 JR |
1334 | struct font *font = s->font; |
1335 | int boff = font->baseline_offset; | |
027f6f90 | 1336 | int y; |
c35f9821 JR |
1337 | HFONT old_font; |
1338 | ||
1339 | old_font = SelectObject (s->hdc, FONT_HANDLE (font)); | |
027f6f90 | 1340 | |
c35f9821 JR |
1341 | if (font->vertical_centering) |
1342 | boff = VCENTER_BASELINE_OFFSET (font, s->f) - boff; | |
027f6f90 JR |
1343 | |
1344 | y = s->ybase - boff; | |
1345 | if (s->for_overlaps | |
1346 | || (s->background_filled_p && s->hl != DRAW_CURSOR)) | |
c35f9821 | 1347 | font->driver->draw (s, 0, s->nchars, x, y, 0); |
027f6f90 | 1348 | else |
c35f9821 | 1349 | font->driver->draw (s, 0, s->nchars, x, y, 1); |
027f6f90 | 1350 | if (s->face->overstrike) |
c35f9821 | 1351 | font->driver->draw (s, 0, s->nchars, x + 1, y, 0); |
791f420f | 1352 | |
c35f9821 JR |
1353 | SelectObject (s->hdc, old_font); |
1354 | } | |
791f420f JR |
1355 | } |
1356 | ||
1357 | /* Draw the foreground of composite glyph string S. */ | |
1358 | ||
1359 | static void | |
1360 | x_draw_composite_glyph_string_foreground (s) | |
1361 | struct glyph_string *s; | |
1362 | { | |
027f6f90 | 1363 | int i, j, x; |
2b107652 | 1364 | struct font *font = s->font; |
791f420f JR |
1365 | |
1366 | /* If first glyph of S has a left box line, start drawing the text | |
1367 | of S to the right of that box line. */ | |
027f6f90 | 1368 | if (s->face && s->face->box != FACE_NO_BOX |
791f420f | 1369 | && s->first_glyph->left_box_line_p) |
1ea40aa2 | 1370 | x = s->x + eabs (s->face->box_line_width); |
791f420f JR |
1371 | else |
1372 | x = s->x; | |
1373 | ||
2b107652 KH |
1374 | /* S is a glyph string for a composition. S->cmp_from is the index |
1375 | of the first character drawn for glyphs of this composition. | |
1376 | S->cmp_from == 0 means we are drawing the very first character of | |
791f420f JR |
1377 | this composition. */ |
1378 | ||
1379 | SetTextColor (s->hdc, s->gc->foreground); | |
1380 | SetBkColor (s->hdc, s->gc->background); | |
791f420f JR |
1381 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); |
1382 | ||
1383 | /* Draw a rectangle for the composition if the font for the very | |
1384 | first character of the composition could not be loaded. */ | |
1385 | if (s->font_not_found_p) | |
1386 | { | |
2b107652 | 1387 | if (s->cmp_from == 0) |
791f420f JR |
1388 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1, |
1389 | s->height - 1); | |
1390 | } | |
2b107652 KH |
1391 | else if (! s->first_glyph->u.cmp.automatic) |
1392 | { | |
1393 | int y = s->ybase; | |
1394 | int width = 0; | |
1395 | HFONT old_font; | |
1396 | ||
1397 | old_font = SelectObject (s->hdc, FONT_HANDLE (font)); | |
1398 | ||
1399 | for (i = 0, j = s->cmp_from; i < s->nchars; i++, j++) | |
1400 | if (COMPOSITION_GLYPH (s->cmp, j) != '\t') | |
1401 | { | |
1402 | int xx = x + s->cmp->offsets[j * 2]; | |
1403 | int yy = y - s->cmp->offsets[j * 2 + 1]; | |
1404 | ||
1405 | font->driver->draw (s, j, j + 1, xx, yy, 0); | |
1406 | if (s->face->overstrike) | |
1407 | font->driver->draw (s, j, j + 1, xx + 1, yy, 0); | |
1408 | } | |
1409 | SelectObject (s->hdc, old_font); | |
1410 | } | |
c35f9821 | 1411 | else |
791f420f | 1412 | { |
2b107652 KH |
1413 | Lisp_Object gstring = composition_gstring_from_id (s->cmp_id); |
1414 | Lisp_Object glyph; | |
027f6f90 JR |
1415 | int y = s->ybase; |
1416 | int width = 0; | |
c35f9821 JR |
1417 | HFONT old_font; |
1418 | ||
1419 | old_font = SelectObject (s->hdc, FONT_HANDLE (font)); | |
027f6f90 | 1420 | |
2b107652 | 1421 | for (i = j = s->cmp_from; i < s->cmp_to; i++) |
a18bb28d | 1422 | { |
2b107652 KH |
1423 | glyph = LGSTRING_GLYPH (gstring, i); |
1424 | if (NILP (LGLYPH_ADJUSTMENT (glyph))) | |
1425 | width += LGLYPH_WIDTH (glyph); | |
1426 | else | |
027f6f90 | 1427 | { |
027f6f90 JR |
1428 | int xoff, yoff, wadjust; |
1429 | ||
2b107652 | 1430 | if (j < i) |
027f6f90 | 1431 | { |
2b107652 | 1432 | font->driver->draw (s, j, i, x, y, 0); |
027f6f90 JR |
1433 | x += width; |
1434 | } | |
2b107652 KH |
1435 | xoff = LGLYPH_XOFF (glyph); |
1436 | yoff = LGLYPH_YOFF (glyph); | |
1437 | wadjust = LGLYPH_WADJUST (glyph); | |
027f6f90 | 1438 | font->driver->draw (s, i, i + 1, x + xoff, y + yoff, 0); |
0c16681f | 1439 | x += wadjust; |
2b107652 | 1440 | j = i + 1; |
027f6f90 JR |
1441 | width = 0; |
1442 | } | |
a18bb28d | 1443 | } |
2b107652 KH |
1444 | if (j < i) |
1445 | font->driver->draw (s, j, i, x, y, 0); | |
1446 | ||
c35f9821 | 1447 | SelectObject (s->hdc, old_font); |
791f420f JR |
1448 | } |
1449 | } | |
1450 | ||
e5fa381b JR |
1451 | |
1452 | /* Brightness beyond which a color won't have its highlight brightness | |
1453 | boosted. | |
1454 | ||
1455 | Nominally, highlight colors for `3d' faces are calculated by | |
1456 | brightening an object's color by a constant scale factor, but this | |
1457 | doesn't yield good results for dark colors, so for colors who's | |
1458 | brightness is less than this value (on a scale of 0-255) have to | |
1459 | use an additional additive factor. | |
1460 | ||
1461 | The value here is set so that the default menu-bar/mode-line color | |
1462 | (grey75) will not have its highlights changed at all. */ | |
1463 | #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187 | |
1464 | ||
1465 | ||
791f420f JR |
1466 | /* Allocate a color which is lighter or darker than *COLOR by FACTOR |
1467 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
1468 | If this produces the same color as COLOR, try a color where all RGB | |
1469 | values have DELTA added. Return the allocated color in *COLOR. | |
1470 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
1471 | Value is non-zero if successful. */ | |
1472 | ||
1473 | static int | |
1474 | w32_alloc_lighter_color (f, color, factor, delta) | |
1475 | struct frame *f; | |
1476 | COLORREF *color; | |
1477 | double factor; | |
1478 | int delta; | |
1479 | { | |
1480 | COLORREF new; | |
e5fa381b JR |
1481 | long bright; |
1482 | ||
1483 | /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */ | |
1484 | delta /= 256; | |
791f420f JR |
1485 | |
1486 | /* Change RGB values by specified FACTOR. Avoid overflow! */ | |
1487 | xassert (factor >= 0); | |
1488 | new = PALETTERGB (min (0xff, factor * GetRValue (*color)), | |
1489 | min (0xff, factor * GetGValue (*color)), | |
1490 | min (0xff, factor * GetBValue (*color))); | |
e5fa381b JR |
1491 | |
1492 | /* Calculate brightness of COLOR. */ | |
1493 | bright = (2 * GetRValue (*color) + 3 * GetGValue (*color) | |
1494 | + GetBValue (*color)) / 6; | |
1495 | ||
1496 | /* We only boost colors that are darker than | |
1497 | HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */ | |
1498 | if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT) | |
1499 | /* Make an additive adjustment to NEW, because it's dark enough so | |
1500 | that scaling by FACTOR alone isn't enough. */ | |
1501 | { | |
1502 | /* How far below the limit this color is (0 - 1, 1 being darker). */ | |
1503 | double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT; | |
1504 | /* The additive adjustment. */ | |
1505 | int min_delta = delta * dimness * factor / 2; | |
d67d1627 | 1506 | |
e5fa381b JR |
1507 | if (factor < 1) |
1508 | new = PALETTERGB (max (0, min (0xff, min_delta - GetRValue (*color))), | |
1509 | max (0, min (0xff, min_delta - GetGValue (*color))), | |
1510 | max (0, min (0xff, min_delta - GetBValue (*color)))); | |
1511 | else | |
1512 | new = PALETTERGB (max (0, min (0xff, min_delta + GetRValue (*color))), | |
1513 | max (0, min (0xff, min_delta + GetGValue (*color))), | |
1514 | max (0, min (0xff, min_delta + GetBValue (*color)))); | |
1515 | } | |
d67d1627 | 1516 | |
791f420f JR |
1517 | if (new == *color) |
1518 | new = PALETTERGB (max (0, min (0xff, delta + GetRValue (*color))), | |
1519 | max (0, min (0xff, delta + GetGValue (*color))), | |
1520 | max (0, min (0xff, delta + GetBValue (*color)))); | |
1521 | ||
01b220b6 JR |
1522 | /* TODO: Map to palette and retry with delta if same? */ |
1523 | /* TODO: Free colors (if using palette)? */ | |
93ff4395 | 1524 | |
791f420f JR |
1525 | if (new == *color) |
1526 | return 0; | |
1527 | ||
1528 | *color = new; | |
1529 | ||
1530 | return 1; | |
1531 | } | |
1532 | ||
8b7d0a16 JR |
1533 | /* On frame F, translate pixel colors to RGB values for the NCOLORS |
1534 | colors in COLORS. On W32, we no longer try to map colors to | |
1535 | a palette. */ | |
1536 | void | |
1537 | x_query_colors (f, colors, ncolors) | |
1538 | struct frame *f; | |
1539 | XColor *colors; | |
1540 | int ncolors; | |
1541 | { | |
1542 | int i; | |
1543 | ||
1544 | for (i = 0; i < ncolors; i++) | |
1545 | { | |
1546 | DWORD pixel = colors[i].pixel; | |
1547 | /* Convert to a 16 bit value in range 0 - 0xffff. */ | |
1548 | colors[i].red = GetRValue (pixel) * 257; | |
1549 | colors[i].green = GetGValue (pixel) * 257; | |
1550 | colors[i].blue = GetBValue (pixel) * 257; | |
1551 | } | |
1552 | } | |
1553 | ||
1554 | void | |
1555 | x_query_color (f, color) | |
1556 | struct frame *f; | |
1557 | XColor *color; | |
1558 | { | |
1559 | x_query_colors (f, color, 1); | |
1560 | } | |
1561 | ||
791f420f JR |
1562 | |
1563 | /* Set up the foreground color for drawing relief lines of glyph | |
1564 | string S. RELIEF is a pointer to a struct relief containing the GC | |
1565 | with which lines will be drawn. Use a color that is FACTOR or | |
1566 | DELTA lighter or darker than the relief's background which is found | |
1567 | in S->f->output_data.x->relief_background. If such a color cannot | |
1568 | be allocated, use DEFAULT_PIXEL, instead. */ | |
d67d1627 | 1569 | |
791f420f JR |
1570 | static void |
1571 | w32_setup_relief_color (f, relief, factor, delta, default_pixel) | |
1572 | struct frame *f; | |
1573 | struct relief *relief; | |
1574 | double factor; | |
1575 | int delta; | |
1576 | COLORREF default_pixel; | |
1577 | { | |
1578 | XGCValues xgcv; | |
1579 | struct w32_output *di = f->output_data.w32; | |
1580 | unsigned long mask = GCForeground; | |
1581 | COLORREF pixel; | |
1582 | COLORREF background = di->relief_background; | |
1583 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
1584 | ||
01b220b6 | 1585 | /* TODO: Free colors (if using palette)? */ |
93ff4395 | 1586 | |
791f420f JR |
1587 | /* Allocate new color. */ |
1588 | xgcv.foreground = default_pixel; | |
1589 | pixel = background; | |
1590 | if (w32_alloc_lighter_color (f, &pixel, factor, delta)) | |
1591 | { | |
1592 | relief->allocated_p = 1; | |
1593 | xgcv.foreground = relief->pixel = pixel; | |
1594 | } | |
d67d1627 | 1595 | |
791f420f JR |
1596 | if (relief->gc == 0) |
1597 | { | |
01b220b6 | 1598 | #if 0 /* TODO: stipple */ |
791f420f JR |
1599 | xgcv.stipple = dpyinfo->gray; |
1600 | mask |= GCStipple; | |
1601 | #endif | |
1602 | relief->gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &xgcv); | |
1603 | } | |
1604 | else | |
1605 | XChangeGC (NULL, relief->gc, mask, &xgcv); | |
1606 | } | |
1607 | ||
1608 | ||
1609 | /* Set up colors for the relief lines around glyph string S. */ | |
1610 | ||
1611 | static void | |
1612 | x_setup_relief_colors (s) | |
1613 | struct glyph_string *s; | |
1614 | { | |
1615 | struct w32_output *di = s->f->output_data.w32; | |
1616 | COLORREF color; | |
1617 | ||
1618 | if (s->face->use_box_color_for_shadows_p) | |
1619 | color = s->face->box_color; | |
6ff3e5e3 | 1620 | else if (s->first_glyph->type == IMAGE_GLYPH |
6637c996 | 1621 | && s->img->pixmap |
6ff3e5e3 JR |
1622 | && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0)) |
1623 | color = IMAGE_BACKGROUND (s->img, s->f, 0); | |
791f420f JR |
1624 | else |
1625 | color = s->gc->background; | |
1626 | ||
1627 | if (di->white_relief.gc == 0 | |
1628 | || color != di->relief_background) | |
1629 | { | |
1630 | di->relief_background = color; | |
1631 | w32_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000, | |
1632 | WHITE_PIX_DEFAULT (s->f)); | |
1633 | w32_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000, | |
1634 | BLACK_PIX_DEFAULT (s->f)); | |
1635 | } | |
1636 | } | |
1637 | ||
1638 | ||
1639 | /* Draw a relief on frame F inside the rectangle given by LEFT_X, | |
1640 | TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief | |
1641 | to draw, it must be >= 0. RAISED_P non-zero means draw a raised | |
1642 | relief. LEFT_P non-zero means draw a relief on the left side of | |
1643 | the rectangle. RIGHT_P non-zero means draw a relief on the right | |
1644 | side of the rectangle. CLIP_RECT is the clipping rectangle to use | |
1645 | when drawing. */ | |
1646 | ||
1647 | static void | |
1648 | w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, | |
cb0b194a | 1649 | raised_p, top_p, bot_p, left_p, right_p, clip_rect) |
791f420f | 1650 | struct frame *f; |
cb0b194a KS |
1651 | int left_x, top_y, right_x, bottom_y, width; |
1652 | int top_p, bot_p, left_p, right_p, raised_p; | |
791f420f JR |
1653 | RECT *clip_rect; |
1654 | { | |
1655 | int i; | |
1656 | XGCValues gc; | |
1657 | HDC hdc = get_frame_dc (f); | |
1658 | ||
1659 | if (raised_p) | |
e5fa381b | 1660 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
791f420f | 1661 | else |
e5fa381b | 1662 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f JR |
1663 | |
1664 | w32_set_clip_rectangle (hdc, clip_rect); | |
1665 | ||
1666 | /* Top. */ | |
cb0b194a KS |
1667 | if (top_p) |
1668 | for (i = 0; i < width; ++i) | |
1669 | w32_fill_area (f, hdc, gc.foreground, | |
1670 | left_x + i * left_p, top_y + i, | |
1671 | right_x - left_x - i * (left_p + right_p ) + 1, 1); | |
791f420f JR |
1672 | |
1673 | /* Left. */ | |
1674 | if (left_p) | |
1675 | for (i = 0; i < width; ++i) | |
9f5a911b JR |
1676 | w32_fill_area (f, hdc, gc.foreground, |
1677 | left_x + i, top_y + i, 1, | |
df3bd29d | 1678 | bottom_y - top_y - 2 * i + 1); |
791f420f JR |
1679 | |
1680 | if (raised_p) | |
e5fa381b | 1681 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f | 1682 | else |
e5fa381b | 1683 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
d67d1627 | 1684 | |
791f420f | 1685 | /* Bottom. */ |
cb0b194a KS |
1686 | if (bot_p) |
1687 | for (i = 0; i < width; ++i) | |
1688 | w32_fill_area (f, hdc, gc.foreground, | |
1689 | left_x + i * left_p, bottom_y - i, | |
1690 | right_x - left_x - i * (left_p + right_p) + 1, 1); | |
791f420f JR |
1691 | |
1692 | /* Right. */ | |
1693 | if (right_p) | |
1694 | for (i = 0; i < width; ++i) | |
9f5a911b JR |
1695 | w32_fill_area (f, hdc, gc.foreground, |
1696 | right_x - i, top_y + i + 1, 1, | |
df3bd29d | 1697 | bottom_y - top_y - 2 * i - 1); |
791f420f JR |
1698 | |
1699 | w32_set_clip_rectangle (hdc, NULL); | |
d67d1627 | 1700 | |
791f420f JR |
1701 | release_frame_dc (f, hdc); |
1702 | } | |
1703 | ||
1704 | ||
1705 | /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y, | |
1706 | RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to | |
1707 | draw, it must be >= 0. LEFT_P non-zero means draw a line on the | |
1708 | left side of the rectangle. RIGHT_P non-zero means draw a line | |
1709 | on the right side of the rectangle. CLIP_RECT is the clipping | |
1710 | rectangle to use when drawing. */ | |
1711 | ||
1712 | static void | |
1713 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
1714 | left_p, right_p, clip_rect) | |
1715 | struct glyph_string *s; | |
1716 | int left_x, top_y, right_x, bottom_y, width, left_p, right_p; | |
1717 | RECT *clip_rect; | |
1718 | { | |
00fe468b | 1719 | w32_set_clip_rectangle (s->hdc, clip_rect); |
d67d1627 | 1720 | |
791f420f | 1721 | /* Top. */ |
00fe468b | 1722 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 1723 | left_x, top_y, right_x - left_x + 1, width); |
791f420f JR |
1724 | |
1725 | /* Left. */ | |
1726 | if (left_p) | |
1727 | { | |
00fe468b | 1728 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 1729 | left_x, top_y, width, bottom_y - top_y + 1); |
791f420f | 1730 | } |
d67d1627 | 1731 | |
791f420f | 1732 | /* Bottom. */ |
00fe468b | 1733 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 1734 | left_x, bottom_y - width + 1, right_x - left_x + 1, width); |
d67d1627 | 1735 | |
791f420f JR |
1736 | /* Right. */ |
1737 | if (right_p) | |
1738 | { | |
00fe468b | 1739 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 1740 | right_x - width + 1, top_y, width, bottom_y - top_y + 1); |
791f420f JR |
1741 | } |
1742 | ||
00fe468b | 1743 | w32_set_clip_rectangle (s->hdc, NULL); |
791f420f JR |
1744 | } |
1745 | ||
1746 | ||
1747 | /* Draw a box around glyph string S. */ | |
1748 | ||
1749 | static void | |
1750 | x_draw_glyph_string_box (s) | |
1751 | struct glyph_string *s; | |
1752 | { | |
1753 | int width, left_x, right_x, top_y, bottom_y, last_x, raised_p; | |
1754 | int left_p, right_p; | |
1755 | struct glyph *last_glyph; | |
1756 | RECT clip_rect; | |
1757 | ||
82ead4b1 KS |
1758 | last_x = ((s->row->full_width_p && !s->w->pseudo_window_p) |
1759 | ? WINDOW_RIGHT_EDGE_X (s->w) | |
1760 | : window_box_right (s->w, s->area)); | |
d67d1627 | 1761 | |
791f420f JR |
1762 | /* The glyph that may have a right box line. */ |
1763 | last_glyph = (s->cmp || s->img | |
1764 | ? s->first_glyph | |
1765 | : s->first_glyph + s->nchars - 1); | |
1766 | ||
1ea40aa2 | 1767 | width = eabs (s->face->box_line_width); |
791f420f JR |
1768 | raised_p = s->face->box == FACE_RAISED_BOX; |
1769 | left_x = s->x; | |
9f5a911b | 1770 | right_x = ((s->row->full_width_p && s->extends_to_end_of_line_p |
791f420f JR |
1771 | ? last_x - 1 |
1772 | : min (last_x, s->x + s->background_width) - 1)); | |
1773 | top_y = s->y; | |
1774 | bottom_y = top_y + s->height - 1; | |
1775 | ||
1776 | left_p = (s->first_glyph->left_box_line_p | |
1777 | || (s->hl == DRAW_MOUSE_FACE | |
1778 | && (s->prev == NULL | |
1779 | || s->prev->hl != s->hl))); | |
1780 | right_p = (last_glyph->right_box_line_p | |
1781 | || (s->hl == DRAW_MOUSE_FACE | |
1782 | && (s->next == NULL | |
1783 | || s->next->hl != s->hl))); | |
d67d1627 | 1784 | |
89271099 | 1785 | get_glyph_string_clip_rect (s, &clip_rect); |
791f420f JR |
1786 | |
1787 | if (s->face->box == FACE_SIMPLE_BOX) | |
1788 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
1789 | left_p, right_p, &clip_rect); | |
1790 | else | |
1791 | { | |
1792 | x_setup_relief_colors (s); | |
1793 | w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, | |
cb0b194a | 1794 | width, raised_p, 1, 1, left_p, right_p, &clip_rect); |
791f420f JR |
1795 | } |
1796 | } | |
1797 | ||
1798 | ||
1799 | /* Draw foreground of image glyph string S. */ | |
1800 | ||
1801 | static void | |
1802 | x_draw_image_foreground (s) | |
1803 | struct glyph_string *s; | |
1804 | { | |
cb0b194a KS |
1805 | int x = s->x; |
1806 | int y = s->ybase - image_ascent (s->img, s->face, &s->slice); | |
791f420f JR |
1807 | |
1808 | /* If first glyph of S has a left box line, start drawing it to the | |
1809 | right of that line. */ | |
1810 | if (s->face->box != FACE_NO_BOX | |
cb0b194a KS |
1811 | && s->first_glyph->left_box_line_p |
1812 | && s->slice.x == 0) | |
1ea40aa2 | 1813 | x += eabs (s->face->box_line_width); |
791f420f JR |
1814 | |
1815 | /* If there is a margin around the image, adjust x- and y-position | |
1816 | by that margin. */ | |
cb0b194a KS |
1817 | if (s->slice.x == 0) |
1818 | x += s->img->hmargin; | |
1819 | if (s->slice.y == 0) | |
1820 | y += s->img->vmargin; | |
791f420f JR |
1821 | |
1822 | SaveDC (s->hdc); | |
1823 | ||
1824 | if (s->img->pixmap) | |
1825 | { | |
d30591dc JR |
1826 | HDC compat_hdc = CreateCompatibleDC (s->hdc); |
1827 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
1828 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
1829 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
1830 | SetBkColor (compat_hdc, RGB (255, 255, 255)); | |
1831 | SetTextColor (s->hdc, RGB (0, 0, 0)); | |
1832 | x_set_glyph_string_clipping (s); | |
1833 | ||
791f420f JR |
1834 | if (s->img->mask) |
1835 | { | |
d30591dc JR |
1836 | HDC mask_dc = CreateCompatibleDC (s->hdc); |
1837 | HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask); | |
1838 | ||
1839 | SetTextColor (s->hdc, RGB (255, 255, 255)); | |
1840 | SetBkColor (s->hdc, RGB (0, 0, 0)); | |
1841 | ||
cb0b194a KS |
1842 | BitBlt (s->hdc, x, y, s->slice.width, s->slice.height, |
1843 | compat_hdc, s->slice.x, s->slice.y, SRCINVERT); | |
1844 | BitBlt (s->hdc, x, y, s->slice.width, s->slice.height, | |
1845 | mask_dc, s->slice.x, s->slice.y, SRCAND); | |
1846 | BitBlt (s->hdc, x, y, s->slice.width, s->slice.height, | |
1847 | compat_hdc, s->slice.x, s->slice.y, SRCINVERT); | |
d30591dc JR |
1848 | |
1849 | SelectObject (mask_dc, mask_orig_obj); | |
1850 | DeleteDC (mask_dc); | |
791f420f JR |
1851 | } |
1852 | else | |
791f420f | 1853 | { |
d30591dc JR |
1854 | SetTextColor (s->hdc, s->gc->foreground); |
1855 | SetBkColor (s->hdc, s->gc->background); | |
1856 | ||
cb0b194a KS |
1857 | BitBlt (s->hdc, x, y, s->slice.width, s->slice.height, |
1858 | compat_hdc, s->slice.x, s->slice.y, SRCCOPY); | |
791f420f JR |
1859 | |
1860 | /* When the image has a mask, we can expect that at | |
1861 | least part of a mouse highlight or a block cursor will | |
1862 | be visible. If the image doesn't have a mask, make | |
1863 | a block cursor visible by drawing a rectangle around | |
1864 | the image. I believe it's looking better if we do | |
1865 | nothing here for mouse-face. */ | |
1866 | if (s->hl == DRAW_CURSOR) | |
c65eff23 KS |
1867 | { |
1868 | int r = s->img->relief; | |
1869 | if (r < 0) r = -r; | |
1870 | w32_draw_rectangle (s->hdc, s->gc, x - r, y - r , | |
cb0b194a KS |
1871 | s->slice.width + r*2 - 1, |
1872 | s->slice.height + r*2 - 1); | |
c65eff23 | 1873 | } |
791f420f | 1874 | } |
d30591dc JR |
1875 | |
1876 | w32_set_clip_rectangle (s->hdc, NULL); | |
1877 | SelectObject (s->hdc, orig_brush); | |
1878 | DeleteObject (fg_brush); | |
1879 | SelectObject (compat_hdc, orig_obj); | |
1880 | DeleteDC (compat_hdc); | |
791f420f JR |
1881 | } |
1882 | else | |
cb0b194a KS |
1883 | w32_draw_rectangle (s->hdc, s->gc, x, y, |
1884 | s->slice.width - 1, s->slice.height - 1); | |
ee78dc32 | 1885 | |
791f420f JR |
1886 | RestoreDC (s->hdc ,-1); |
1887 | } | |
ee78dc32 | 1888 | |
791f420f | 1889 | |
791f420f JR |
1890 | /* Draw a relief around the image glyph string S. */ |
1891 | ||
1892 | static void | |
1893 | x_draw_image_relief (s) | |
1894 | struct glyph_string *s; | |
1895 | { | |
1896 | int x0, y0, x1, y1, thick, raised_p; | |
1897 | RECT r; | |
cb0b194a KS |
1898 | int x = s->x; |
1899 | int y = s->ybase - image_ascent (s->img, s->face, &s->slice); | |
d67d1627 | 1900 | |
791f420f JR |
1901 | /* If first glyph of S has a left box line, start drawing it to the |
1902 | right of that line. */ | |
1903 | if (s->face->box != FACE_NO_BOX | |
cb0b194a KS |
1904 | && s->first_glyph->left_box_line_p |
1905 | && s->slice.x == 0) | |
1ea40aa2 | 1906 | x += eabs (s->face->box_line_width); |
d67d1627 | 1907 | |
791f420f JR |
1908 | /* If there is a margin around the image, adjust x- and y-position |
1909 | by that margin. */ | |
cb0b194a KS |
1910 | if (s->slice.x == 0) |
1911 | x += s->img->hmargin; | |
1912 | if (s->slice.y == 0) | |
1913 | y += s->img->vmargin; | |
d67d1627 | 1914 | |
791f420f JR |
1915 | if (s->hl == DRAW_IMAGE_SUNKEN |
1916 | || s->hl == DRAW_IMAGE_RAISED) | |
1917 | { | |
6637c996 | 1918 | thick = tool_bar_button_relief >= 0 ? tool_bar_button_relief : DEFAULT_TOOL_BAR_BUTTON_RELIEF; |
791f420f JR |
1919 | raised_p = s->hl == DRAW_IMAGE_RAISED; |
1920 | } | |
1921 | else | |
ee78dc32 | 1922 | { |
1ea40aa2 | 1923 | thick = eabs (s->img->relief); |
791f420f JR |
1924 | raised_p = s->img->relief > 0; |
1925 | } | |
d67d1627 | 1926 | |
791f420f JR |
1927 | x0 = x - thick; |
1928 | y0 = y - thick; | |
cb0b194a KS |
1929 | x1 = x + s->slice.width + thick - 1; |
1930 | y1 = y + s->slice.height + thick - 1; | |
d67d1627 | 1931 | |
791f420f | 1932 | x_setup_relief_colors (s); |
89271099 | 1933 | get_glyph_string_clip_rect (s, &r); |
cb0b194a KS |
1934 | w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, |
1935 | s->slice.y == 0, | |
1936 | s->slice.y + s->slice.height == s->img->height, | |
1937 | s->slice.x == 0, | |
1938 | s->slice.x + s->slice.width == s->img->width, | |
1939 | &r); | |
791f420f | 1940 | } |
ee78dc32 | 1941 | |
791f420f JR |
1942 | |
1943 | /* Draw the foreground of image glyph string S to PIXMAP. */ | |
1944 | ||
1945 | static void | |
1946 | w32_draw_image_foreground_1 (s, pixmap) | |
1947 | struct glyph_string *s; | |
1948 | HBITMAP pixmap; | |
1949 | { | |
1950 | HDC hdc = CreateCompatibleDC (s->hdc); | |
1951 | HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap); | |
cb0b194a KS |
1952 | int x = 0; |
1953 | int y = s->ybase - s->y - image_ascent (s->img, s->face, &s->slice); | |
791f420f JR |
1954 | |
1955 | /* If first glyph of S has a left box line, start drawing it to the | |
1956 | right of that line. */ | |
1957 | if (s->face->box != FACE_NO_BOX | |
cb0b194a KS |
1958 | && s->first_glyph->left_box_line_p |
1959 | && s->slice.x == 0) | |
1ea40aa2 | 1960 | x += eabs (s->face->box_line_width); |
791f420f JR |
1961 | |
1962 | /* If there is a margin around the image, adjust x- and y-position | |
1963 | by that margin. */ | |
cb0b194a KS |
1964 | if (s->slice.x == 0) |
1965 | x += s->img->hmargin; | |
1966 | if (s->slice.y == 0) | |
1967 | y += s->img->vmargin; | |
791f420f JR |
1968 | |
1969 | if (s->img->pixmap) | |
1970 | { | |
d30591dc JR |
1971 | HDC compat_hdc = CreateCompatibleDC (hdc); |
1972 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
1973 | HBRUSH orig_brush = SelectObject (hdc, fg_brush); | |
1974 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
1975 | ||
791f420f JR |
1976 | if (s->img->mask) |
1977 | { | |
d30591dc JR |
1978 | HDC mask_dc = CreateCompatibleDC (hdc); |
1979 | HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask); | |
1980 | ||
1981 | SetTextColor (hdc, RGB (0, 0, 0)); | |
1982 | SetBkColor (hdc, RGB (255, 255, 255)); | |
cb0b194a KS |
1983 | BitBlt (hdc, x, y, s->slice.width, s->slice.height, |
1984 | compat_hdc, s->slice.x, s->slice.y, SRCINVERT); | |
1985 | BitBlt (hdc, x, y, s->slice.width, s->slice.height, | |
1986 | mask_dc, s->slice.x, s->slice.y, SRCAND); | |
1987 | BitBlt (hdc, x, y, s->slice.width, s->slice.height, | |
1988 | compat_hdc, s->slice.x, s->slice.y, SRCINVERT); | |
d30591dc JR |
1989 | |
1990 | SelectObject (mask_dc, mask_orig_obj); | |
1991 | DeleteDC (mask_dc); | |
791f420f JR |
1992 | } |
1993 | else | |
ef0e360f | 1994 | { |
d30591dc JR |
1995 | SetTextColor (hdc, s->gc->foreground); |
1996 | SetBkColor (hdc, s->gc->background); | |
1997 | ||
cb0b194a KS |
1998 | BitBlt (hdc, x, y, s->slice.width, s->slice.height, |
1999 | compat_hdc, s->slice.x, s->slice.y, SRCCOPY); | |
791f420f JR |
2000 | |
2001 | /* When the image has a mask, we can expect that at | |
2002 | least part of a mouse highlight or a block cursor will | |
2003 | be visible. If the image doesn't have a mask, make | |
2004 | a block cursor visible by drawing a rectangle around | |
2005 | the image. I believe it's looking better if we do | |
2006 | nothing here for mouse-face. */ | |
2007 | if (s->hl == DRAW_CURSOR) | |
c65eff23 KS |
2008 | { |
2009 | int r = s->img->relief; | |
2010 | if (r < 0) r = -r; | |
cb0b194a KS |
2011 | w32_draw_rectangle (hdc, s->gc, x - r, y - r, |
2012 | s->slice.width + r*2 - 1, | |
2013 | s->slice.height + r*2 - 1); | |
c65eff23 | 2014 | } |
ef0e360f | 2015 | } |
d30591dc JR |
2016 | |
2017 | SelectObject (hdc, orig_brush); | |
2018 | DeleteObject (fg_brush); | |
2019 | SelectObject (compat_hdc, orig_obj); | |
2020 | DeleteDC (compat_hdc); | |
791f420f JR |
2021 | } |
2022 | else | |
cb0b194a KS |
2023 | w32_draw_rectangle (hdc, s->gc, x, y, |
2024 | s->slice.width - 1, s->slice.height - 1); | |
791f420f JR |
2025 | |
2026 | SelectObject (hdc, orig_hdc_obj); | |
2027 | DeleteDC (hdc); | |
2028 | } | |
2029 | ||
2030 | ||
2031 | /* Draw part of the background of glyph string S. X, Y, W, and H | |
2032 | give the rectangle to draw. */ | |
2033 | ||
2034 | static void | |
2035 | x_draw_glyph_string_bg_rect (s, x, y, w, h) | |
2036 | struct glyph_string *s; | |
2037 | int x, y, w, h; | |
2038 | { | |
01b220b6 | 2039 | #if 0 /* TODO: stipple */ |
791f420f JR |
2040 | if (s->stippled_p) |
2041 | { | |
2042 | /* Fill background with a stipple pattern. */ | |
2043 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
2044 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
2045 | XSetFillStyle (s->display, s->gc, FillSolid); | |
2046 | } | |
2047 | else | |
2048 | #endif | |
2049 | x_clear_glyph_string_rect (s, x, y, w, h); | |
2050 | } | |
2051 | ||
2052 | ||
d67d1627 | 2053 | /* Draw image glyph string S. |
791f420f JR |
2054 | |
2055 | s->y | |
2056 | s->x +------------------------- | |
2057 | | s->face->box | |
2058 | | | |
2059 | | +------------------------- | |
d6ff54d5 | 2060 | | | s->img->vmargin |
791f420f JR |
2061 | | | |
2062 | | | +------------------- | |
2063 | | | | the image | |
cabb23bc | 2064 | |
791f420f JR |
2065 | */ |
2066 | ||
2067 | static void | |
2068 | x_draw_image_glyph_string (s) | |
2069 | struct glyph_string *s; | |
2070 | { | |
2071 | int x, y; | |
1ea40aa2 | 2072 | int box_line_hwidth = eabs (s->face->box_line_width); |
60222d69 | 2073 | int box_line_vwidth = max (s->face->box_line_width, 0); |
791f420f JR |
2074 | int height; |
2075 | HBITMAP pixmap = 0; | |
2076 | ||
60222d69 | 2077 | height = s->height - 2 * box_line_vwidth; |
791f420f JR |
2078 | |
2079 | /* Fill background with face under the image. Do it only if row is | |
2080 | taller than image or if image has a clip mask to reduce | |
2081 | flickering. */ | |
2082 | s->stippled_p = s->face->stipple != 0; | |
cb0b194a | 2083 | if (height > s->slice.height |
d6ff54d5 | 2084 | || s->img->hmargin |
c2cc16fa | 2085 | || s->img->vmargin |
791f420f | 2086 | || s->img->mask |
791f420f JR |
2087 | || s->img->pixmap == 0 |
2088 | || s->width != s->background_width) | |
2089 | { | |
cb0b194a KS |
2090 | x = s->x; |
2091 | if (s->first_glyph->left_box_line_p | |
2092 | && s->slice.x == 0) | |
2093 | x += box_line_hwidth; | |
2094 | ||
2095 | y = s->y; | |
2096 | if (s->slice.y == 0) | |
2097 | y += box_line_vwidth; | |
d67d1627 | 2098 | |
d30591dc | 2099 | #if 0 /* TODO: figure out if we need to do this on Windows. */ |
791f420f | 2100 | if (s->img->mask) |
ee78dc32 | 2101 | { |
c2cc16fa JR |
2102 | /* Create a pixmap as large as the glyph string. Fill it |
2103 | with the background color. Copy the image to it, using | |
2104 | its mask. Copy the temporary pixmap to the display. */ | |
791f420f JR |
2105 | Screen *screen = FRAME_X_SCREEN (s->f); |
2106 | int depth = DefaultDepthOfScreen (screen); | |
2107 | ||
2108 | /* Create a pixmap as large as the glyph string. */ | |
2109 | pixmap = XCreatePixmap (s->display, s->window, | |
2110 | s->background_width, | |
2111 | s->height, depth); | |
d67d1627 | 2112 | |
791f420f JR |
2113 | /* Don't clip in the following because we're working on the |
2114 | pixmap. */ | |
2115 | XSetClipMask (s->display, s->gc, None); | |
ee78dc32 | 2116 | |
791f420f JR |
2117 | /* Fill the pixmap with the background color/stipple. */ |
2118 | if (s->stippled_p) | |
2119 | { | |
2120 | /* Fill background with a stipple pattern. */ | |
2121 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
2122 | XFillRectangle (s->display, pixmap, s->gc, | |
2123 | 0, 0, s->background_width, s->height); | |
2124 | XSetFillStyle (s->display, s->gc, FillSolid); | |
2125 | } | |
ef0e360f | 2126 | else |
791f420f JR |
2127 | { |
2128 | XGCValues xgcv; | |
2129 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, | |
2130 | &xgcv); | |
2131 | XSetForeground (s->display, s->gc, xgcv.background); | |
2132 | XFillRectangle (s->display, pixmap, s->gc, | |
2133 | 0, 0, s->background_width, s->height); | |
2134 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
2135 | } | |
ee78dc32 | 2136 | } |
791f420f JR |
2137 | else |
2138 | #endif | |
791f420f | 2139 | x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height); |
d67d1627 | 2140 | |
791f420f JR |
2141 | s->background_filled_p = 1; |
2142 | } | |
ee78dc32 | 2143 | |
791f420f JR |
2144 | /* Draw the foreground. */ |
2145 | if (pixmap != 0) | |
2146 | { | |
2147 | w32_draw_image_foreground_1 (s, pixmap); | |
2148 | x_set_glyph_string_clipping (s); | |
ee78dc32 | 2149 | { |
791f420f JR |
2150 | HDC compat_hdc = CreateCompatibleDC (s->hdc); |
2151 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
2152 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
2153 | HGDIOBJ orig_obj = SelectObject (compat_hdc, pixmap); | |
2154 | ||
2155 | SetTextColor (s->hdc, s->gc->foreground); | |
2156 | SetBkColor (s->hdc, s->gc->background); | |
791f420f JR |
2157 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, |
2158 | compat_hdc, 0, 0, SRCCOPY); | |
d30591dc | 2159 | |
791f420f JR |
2160 | SelectObject (s->hdc, orig_brush); |
2161 | DeleteObject (fg_brush); | |
2162 | SelectObject (compat_hdc, orig_obj); | |
2163 | DeleteDC (compat_hdc); | |
2164 | } | |
2165 | DeleteObject (pixmap); | |
2166 | pixmap = 0; | |
2167 | } | |
2168 | else | |
2169 | x_draw_image_foreground (s); | |
ee78dc32 | 2170 | |
791f420f JR |
2171 | /* If we must draw a relief around the image, do it. */ |
2172 | if (s->img->relief | |
2173 | || s->hl == DRAW_IMAGE_RAISED | |
2174 | || s->hl == DRAW_IMAGE_SUNKEN) | |
2175 | x_draw_image_relief (s); | |
2176 | } | |
ee78dc32 | 2177 | |
cabb23bc | 2178 | |
791f420f | 2179 | /* Draw stretch glyph string S. */ |
cabb23bc | 2180 | |
791f420f JR |
2181 | static void |
2182 | x_draw_stretch_glyph_string (s) | |
2183 | struct glyph_string *s; | |
2184 | { | |
2185 | xassert (s->first_glyph->type == STRETCH_GLYPH); | |
65c4903c | 2186 | |
791f420f JR |
2187 | if (s->hl == DRAW_CURSOR |
2188 | && !x_stretch_cursor_p) | |
2189 | { | |
2190 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor | |
2191 | as wide as the stretch glyph. */ | |
e8f6b0db KS |
2192 | int width, background_width = s->background_width; |
2193 | int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA); | |
2194 | ||
2195 | if (x < left_x) | |
2196 | { | |
2197 | background_width -= left_x - x; | |
2198 | x = left_x; | |
2199 | } | |
2200 | width = min (FRAME_COLUMN_WIDTH (s->f), background_width); | |
cabb23bc | 2201 | |
791f420f | 2202 | /* Draw cursor. */ |
e8f6b0db | 2203 | x_draw_glyph_string_bg_rect (s, x, s->y, width, s->height); |
cabb23bc | 2204 | |
791f420f | 2205 | /* Clear rest using the GC of the original non-cursor face. */ |
e8f6b0db | 2206 | if (width < background_width) |
791f420f JR |
2207 | { |
2208 | XGCValues *gc = s->face->gc; | |
e8f6b0db KS |
2209 | int y = s->y; |
2210 | int w = background_width - width, h = s->height; | |
791f420f JR |
2211 | RECT r; |
2212 | HDC hdc = s->hdc; | |
9f5a911b | 2213 | |
e8f6b0db | 2214 | x += width; |
9f5a911b JR |
2215 | if (s->row->mouse_face_p |
2216 | && cursor_in_mouse_face_p (s->w)) | |
2217 | { | |
2218 | x_set_mouse_face_gc (s); | |
2219 | gc = s->gc; | |
2220 | } | |
2221 | else | |
2222 | gc = s->face->gc; | |
d67d1627 | 2223 | |
89271099 | 2224 | get_glyph_string_clip_rect (s, &r); |
791f420f JR |
2225 | w32_set_clip_rectangle (hdc, &r); |
2226 | ||
01b220b6 | 2227 | #if 0 /* TODO: stipple */ |
791f420f JR |
2228 | if (s->face->stipple) |
2229 | { | |
2230 | /* Fill background with a stipple pattern. */ | |
2231 | XSetFillStyle (s->display, gc, FillOpaqueStippled); | |
2232 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
2233 | XSetFillStyle (s->display, gc, FillSolid); | |
2234 | } | |
2235 | else | |
2236 | #endif | |
2237 | { | |
2238 | w32_fill_area (s->f, s->hdc, gc->background, x, y, w, h); | |
2239 | } | |
2240 | } | |
2241 | } | |
9f5a911b | 2242 | else if (!s->background_filled_p) |
e8f6b0db KS |
2243 | { |
2244 | int background_width = s->background_width; | |
2245 | int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA); | |
2246 | ||
6c693929 KS |
2247 | /* Don't draw into left margin, fringe or scrollbar area |
2248 | except for header line and mode line. */ | |
2249 | if (x < left_x && !s->row->mode_line_p) | |
e8f6b0db KS |
2250 | { |
2251 | background_width -= left_x - x; | |
2252 | x = left_x; | |
2253 | } | |
2254 | if (background_width > 0) | |
2255 | x_draw_glyph_string_bg_rect (s, x, s->y, background_width, s->height); | |
5e6b6dcd | 2256 | } |
d67d1627 | 2257 | |
791f420f JR |
2258 | s->background_filled_p = 1; |
2259 | } | |
cabb23bc | 2260 | |
cabb23bc | 2261 | |
791f420f JR |
2262 | /* Draw glyph string S. */ |
2263 | ||
2264 | static void | |
2265 | x_draw_glyph_string (s) | |
2266 | struct glyph_string *s; | |
2267 | { | |
858a55c1 AI |
2268 | int relief_drawn_p = 0; |
2269 | ||
791f420f JR |
2270 | /* If S draws into the background of its successor, draw the |
2271 | background of the successor first so that S can draw into it. | |
2272 | This makes S->next use XDrawString instead of XDrawImageString. */ | |
c2ded1b7 | 2273 | if (s->next && s->right_overhang && !s->for_overlaps) |
791f420f | 2274 | { |
027f6f90 JR |
2275 | int width; |
2276 | struct glyph_string *next; | |
e3f81cd5 CY |
2277 | for (width = 0, next = s->next; |
2278 | next && width < s->right_overhang; | |
027f6f90 JR |
2279 | width += next->width, next = next->next) |
2280 | if (next->first_glyph->type != IMAGE_GLYPH) | |
2281 | { | |
2282 | x_set_glyph_string_gc (next); | |
2283 | x_set_glyph_string_clipping (next); | |
85bdc6d2 CY |
2284 | if (next->first_glyph->type == STRETCH_GLYPH) |
2285 | x_draw_stretch_glyph_string (next); | |
2286 | else | |
2287 | x_draw_glyph_string_background (next, 1); | |
3ca3504a | 2288 | next->num_clips = 0; |
027f6f90 | 2289 | } |
791f420f JR |
2290 | } |
2291 | ||
2292 | /* Set up S->gc, set clipping and draw S. */ | |
2293 | x_set_glyph_string_gc (s); | |
791f420f | 2294 | |
858a55c1 AI |
2295 | /* Draw relief (if any) in advance for char/composition so that the |
2296 | glyph string can be drawn over it. */ | |
c2ded1b7 | 2297 | if (!s->for_overlaps |
858a55c1 AI |
2298 | && s->face->box != FACE_NO_BOX |
2299 | && (s->first_glyph->type == CHAR_GLYPH | |
2300 | || s->first_glyph->type == COMPOSITE_GLYPH)) | |
2301 | ||
2302 | { | |
9f5a911b | 2303 | x_set_glyph_string_clipping (s); |
858a55c1 AI |
2304 | x_draw_glyph_string_background (s, 1); |
2305 | x_draw_glyph_string_box (s); | |
9f5a911b | 2306 | x_set_glyph_string_clipping (s); |
858a55c1 AI |
2307 | relief_drawn_p = 1; |
2308 | } | |
a6e0b7e5 JR |
2309 | else if (!s->clip_head /* draw_glyphs didn't specify a clip mask. */ |
2310 | && !s->clip_tail | |
2311 | && ((s->prev && s->prev->hl != s->hl && s->left_overhang) | |
2312 | || (s->next && s->next->hl != s->hl && s->right_overhang))) | |
027f6f90 JR |
2313 | /* We must clip just this glyph. left_overhang part has already |
2314 | drawn when s->prev was drawn, and right_overhang part will be | |
2315 | drawn later when s->next is drawn. */ | |
2316 | x_set_glyph_string_clipping_exactly (s, s); | |
9f5a911b JR |
2317 | else |
2318 | x_set_glyph_string_clipping (s); | |
858a55c1 | 2319 | |
791f420f JR |
2320 | switch (s->first_glyph->type) |
2321 | { | |
2322 | case IMAGE_GLYPH: | |
2323 | x_draw_image_glyph_string (s); | |
2324 | break; | |
2325 | ||
2326 | case STRETCH_GLYPH: | |
2327 | x_draw_stretch_glyph_string (s); | |
2328 | break; | |
2329 | ||
2330 | case CHAR_GLYPH: | |
c2ded1b7 | 2331 | if (s->for_overlaps) |
791f420f JR |
2332 | s->background_filled_p = 1; |
2333 | else | |
2334 | x_draw_glyph_string_background (s, 0); | |
2335 | x_draw_glyph_string_foreground (s); | |
2336 | break; | |
2337 | ||
2338 | case COMPOSITE_GLYPH: | |
2b107652 KH |
2339 | if (s->for_overlaps || (s->cmp_from > 0 |
2340 | && ! s->first_glyph->u.cmp.automatic)) | |
791f420f JR |
2341 | s->background_filled_p = 1; |
2342 | else | |
2343 | x_draw_glyph_string_background (s, 1); | |
2344 | x_draw_composite_glyph_string_foreground (s); | |
2345 | break; | |
2346 | ||
2347 | default: | |
2348 | abort (); | |
2349 | } | |
2350 | ||
c2ded1b7 | 2351 | if (!s->for_overlaps) |
791f420f JR |
2352 | { |
2353 | /* Draw underline. */ | |
ef39ccbb | 2354 | if (s->face->underline_p) |
791f420f | 2355 | { |
ef39ccbb | 2356 | unsigned long thickness, position; |
b70be253 | 2357 | int y; |
791f420f | 2358 | |
ef39ccbb | 2359 | if (s->prev && s->prev->face->underline_p) |
30f27523 | 2360 | { |
ef39ccbb KH |
2361 | /* We use the same underline style as the previous one. */ |
2362 | thickness = s->prev->underline_thickness; | |
2363 | position = s->prev->underline_position; | |
2364 | } | |
2365 | else | |
2366 | { | |
2367 | /* Get the underline thickness. Default is 1 pixel. */ | |
2368 | if (s->font && s->font->underline_thickness > 0) | |
2369 | thickness = s->font->underline_thickness; | |
2370 | else | |
2371 | thickness = 1; | |
2372 | if (x_underline_at_descent_line) | |
505ecc49 | 2373 | position = (s->height - thickness) - (s->ybase - s->y); |
ef39ccbb | 2374 | else |
027f6f90 | 2375 | { |
ef39ccbb KH |
2376 | /* Get the underline position. This is the recommended |
2377 | vertical offset in pixels from the baseline to the top of | |
2378 | the underline. This is a signed value according to the | |
2379 | specs, and its default is | |
2380 | ||
2381 | ROUND ((maximum_descent) / 2), with | |
2382 | ROUND (x) = floor (x + 0.5) */ | |
2383 | ||
2384 | if (x_use_underline_position_properties | |
2385 | && s->font && s->font->underline_position >= 0) | |
2386 | position = s->font->underline_position; | |
2387 | else if (s->font) | |
2388 | position = (s->font->descent + 1) / 2; | |
027f6f90 | 2389 | } |
2a3bd2e1 | 2390 | position = max (position, underline_minimum_offset); |
30f27523 | 2391 | } |
efdf1b43 KH |
2392 | /* Check the sanity of thickness and position. We should |
2393 | avoid drawing underline out of the current line area. */ | |
2394 | if (s->y + s->height <= s->ybase + position) | |
505ecc49 | 2395 | position = (s->height - 1) - (s->ybase - s->y); |
efdf1b43 KH |
2396 | if (s->y + s->height < s->ybase + position + thickness) |
2397 | thickness = (s->y + s->height) - (s->ybase + position); | |
71b76547 KH |
2398 | s->underline_thickness = thickness; |
2399 | s->underline_position =position; | |
ef39ccbb | 2400 | y = s->ybase + position; |
791f420f JR |
2401 | if (s->face->underline_defaulted_p) |
2402 | { | |
2403 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
9a01ee33 | 2404 | y, s->width, 1); |
791f420f JR |
2405 | } |
2406 | else | |
2407 | { | |
2408 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
9a01ee33 | 2409 | y, s->width, 1); |
791f420f JR |
2410 | } |
2411 | } | |
791f420f JR |
2412 | /* Draw overline. */ |
2413 | if (s->face->overline_p) | |
2414 | { | |
2415 | unsigned long dy = 0, h = 1; | |
2416 | ||
2417 | if (s->face->overline_color_defaulted_p) | |
027f6f90 JR |
2418 | { |
2419 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
9a01ee33 | 2420 | s->y + dy, s->width, h); |
027f6f90 | 2421 | } |
791f420f JR |
2422 | else |
2423 | { | |
59508699 | 2424 | w32_fill_area (s->f, s->hdc, s->face->overline_color, s->x, |
9a01ee33 | 2425 | s->y + dy, s->width, h); |
791f420f JR |
2426 | } |
2427 | } | |
2428 | ||
2429 | /* Draw strike-through. */ | |
9ef2e2cf | 2430 | if (s->face->strike_through_p |
c35f9821 | 2431 | && !FONT_TEXTMETRIC(s->font).tmStruckOut) |
791f420f JR |
2432 | { |
2433 | unsigned long h = 1; | |
2434 | unsigned long dy = (s->height - h) / 2; | |
2435 | ||
2436 | if (s->face->strike_through_color_defaulted_p) | |
2437 | { | |
2438 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, s->y + dy, | |
2439 | s->width, h); | |
2440 | } | |
2441 | else | |
2442 | { | |
def7fa34 | 2443 | w32_fill_area (s->f, s->hdc, s->face->strike_through_color, s->x, |
791f420f JR |
2444 | s->y + dy, s->width, h); |
2445 | } | |
2446 | } | |
2447 | ||
027f6f90 | 2448 | /* Draw relief if not yet drawn. */ |
858a55c1 | 2449 | if (!relief_drawn_p && s->face->box != FACE_NO_BOX) |
791f420f | 2450 | x_draw_glyph_string_box (s); |
027f6f90 JR |
2451 | |
2452 | if (s->prev) | |
2453 | { | |
2454 | struct glyph_string *prev; | |
2455 | ||
2456 | for (prev = s->prev; prev; prev = prev->prev) | |
2457 | if (prev->hl != s->hl | |
2458 | && prev->x + prev->width + prev->right_overhang > s->x) | |
2459 | { | |
2460 | /* As prev was drawn while clipped to its own area, we | |
2461 | must draw the right_overhang part using s->hl now. */ | |
2462 | enum draw_glyphs_face save = prev->hl; | |
2463 | ||
2464 | prev->hl = s->hl; | |
2465 | x_set_glyph_string_gc (prev); | |
2466 | x_set_glyph_string_clipping_exactly (s, prev); | |
2467 | if (prev->first_glyph->type == CHAR_GLYPH) | |
2468 | x_draw_glyph_string_foreground (prev); | |
2469 | else | |
2470 | x_draw_composite_glyph_string_foreground (prev); | |
2471 | w32_set_clip_rectangle (prev->hdc, NULL); | |
2472 | prev->hl = save; | |
3ca3504a | 2473 | prev->num_clips = 0; |
027f6f90 JR |
2474 | } |
2475 | } | |
2476 | ||
2477 | if (s->next) | |
2478 | { | |
2479 | struct glyph_string *next; | |
2480 | ||
2481 | for (next = s->next; next; next = next->next) | |
2482 | if (next->hl != s->hl | |
2483 | && next->x - next->left_overhang < s->x + s->width) | |
2484 | { | |
2485 | /* As next will be drawn while clipped to its own area, | |
2486 | we must draw the left_overhang part using s->hl now. */ | |
2487 | enum draw_glyphs_face save = next->hl; | |
2488 | ||
2489 | next->hl = s->hl; | |
2490 | x_set_glyph_string_gc (next); | |
2491 | x_set_glyph_string_clipping_exactly (s, next); | |
2492 | if (next->first_glyph->type == CHAR_GLYPH) | |
2493 | x_draw_glyph_string_foreground (next); | |
2494 | else | |
2495 | x_draw_composite_glyph_string_foreground (next); | |
2496 | w32_set_clip_rectangle (next->hdc, NULL); | |
2497 | next->hl = save; | |
3ca3504a | 2498 | next->num_clips = 0; |
027f6f90 JR |
2499 | } |
2500 | } | |
791f420f JR |
2501 | } |
2502 | ||
2503 | /* Reset clipping. */ | |
2504 | w32_set_clip_rectangle (s->hdc, NULL); | |
3ca3504a | 2505 | s->num_clips = 0; |
791f420f JR |
2506 | } |
2507 | ||
2508 | ||
89271099 | 2509 | /* Shift display to make room for inserted glyphs. */ |
ee78dc32 | 2510 | |
89271099 KS |
2511 | void |
2512 | w32_shift_glyphs_for_insert (f, x, y, width, height, shift_by) | |
2513 | struct frame *f; | |
2514 | int x, y, width, height, shift_by; | |
791f420f | 2515 | { |
791f420f JR |
2516 | HDC hdc; |
2517 | ||
791f420f | 2518 | hdc = get_frame_dc (f); |
89271099 KS |
2519 | BitBlt (hdc, x + shift_by, y, width, height, |
2520 | hdc, x, y, SRCCOPY); | |
791f420f | 2521 | |
791f420f | 2522 | release_frame_dc (f, hdc); |
ee78dc32 | 2523 | } |
791f420f JR |
2524 | |
2525 | ||
2526 | /* Delete N glyphs at the nominal cursor position. Not implemented | |
2527 | for X frames. */ | |
ee78dc32 | 2528 | |
96214669 | 2529 | static void |
4a418b10 JR |
2530 | x_delete_glyphs (f, n) |
2531 | struct frame *f; | |
791f420f | 2532 | register int n; |
ee78dc32 | 2533 | { |
7e6ac5b9 AI |
2534 | if (! FRAME_W32_P (f)) |
2535 | return; | |
2536 | ||
791f420f JR |
2537 | abort (); |
2538 | } | |
ee78dc32 | 2539 | |
ee78dc32 | 2540 | |
791f420f JR |
2541 | /* Clear entire frame. If updating_frame is non-null, clear that |
2542 | frame. Otherwise clear the selected frame. */ | |
2543 | ||
96214669 | 2544 | static void |
4a418b10 | 2545 | x_clear_frame (struct frame *f) |
ee78dc32 | 2546 | { |
7e6ac5b9 AI |
2547 | if (! FRAME_W32_P (f)) |
2548 | return; | |
2549 | ||
791f420f JR |
2550 | /* Clearing the frame will erase any cursor, so mark them all as no |
2551 | longer visible. */ | |
2552 | mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
2553 | output_cursor.hpos = output_cursor.vpos = 0; | |
2554 | output_cursor.x = -1; | |
ee78dc32 | 2555 | |
791f420f JR |
2556 | /* We don't set the output cursor here because there will always |
2557 | follow an explicit cursor_to. */ | |
ee78dc32 GV |
2558 | BLOCK_INPUT; |
2559 | ||
fbd6baed | 2560 | w32_clear_window (f); |
ee78dc32 GV |
2561 | |
2562 | /* We have to clear the scroll bars, too. If we have changed | |
2563 | colors or something like that, then they should be notified. */ | |
2564 | x_scroll_bar_clear (f); | |
2565 | ||
2566 | UNBLOCK_INPUT; | |
2567 | } | |
791f420f | 2568 | |
ee78dc32 GV |
2569 | \f |
2570 | /* Make audible bell. */ | |
2571 | ||
96214669 | 2572 | static void |
4a418b10 | 2573 | w32_ring_bell (struct frame *f) |
ee78dc32 GV |
2574 | { |
2575 | BLOCK_INPUT; | |
2576 | ||
0f32f023 | 2577 | if (FRAME_W32_P (f) && visible_bell) |
8331e676 GV |
2578 | { |
2579 | int i; | |
4a418b10 | 2580 | HWND hwnd = FRAME_W32_WINDOW (f); |
8331e676 | 2581 | |
d67d1627 | 2582 | for (i = 0; i < 5; i++) |
8331e676 GV |
2583 | { |
2584 | FlashWindow (hwnd, TRUE); | |
2585 | Sleep (10); | |
2586 | } | |
2587 | FlashWindow (hwnd, FALSE); | |
2588 | } | |
ee78dc32 | 2589 | else |
4a418b10 | 2590 | w32_sys_ring_bell (f); |
ee78dc32 GV |
2591 | |
2592 | UNBLOCK_INPUT; | |
ee78dc32 | 2593 | } |
791f420f | 2594 | |
ee78dc32 | 2595 | \f |
791f420f JR |
2596 | /* Specify how many text lines, from the top of the window, |
2597 | should be affected by insert-lines and delete-lines operations. | |
2598 | This, and those operations, are used only within an update | |
2599 | that is bounded by calls to x_update_begin and x_update_end. */ | |
ee78dc32 | 2600 | |
96214669 | 2601 | static void |
791f420f JR |
2602 | w32_set_terminal_window (n) |
2603 | register int n; | |
ee78dc32 | 2604 | { |
791f420f | 2605 | /* This function intentionally left blank. */ |
ee78dc32 | 2606 | } |
791f420f JR |
2607 | |
2608 | \f | |
2609 | /*********************************************************************** | |
2610 | Line Dance | |
2611 | ***********************************************************************/ | |
2612 | ||
2613 | /* Perform an insert-lines or delete-lines operation, inserting N | |
2614 | lines or deleting -N lines at vertical position VPOS. */ | |
ee78dc32 | 2615 | |
96214669 | 2616 | static void |
4a418b10 JR |
2617 | x_ins_del_lines (f, vpos, n) |
2618 | struct frame *f; | |
791f420f | 2619 | int vpos, n; |
ee78dc32 | 2620 | { |
7e6ac5b9 AI |
2621 | if (! FRAME_W32_P (f)) |
2622 | return; | |
2623 | ||
ee78dc32 GV |
2624 | abort (); |
2625 | } | |
791f420f JR |
2626 | |
2627 | ||
2628 | /* Scroll part of the display as described by RUN. */ | |
2629 | ||
2630 | static void | |
2631 | x_scroll_run (w, run) | |
2632 | struct window *w; | |
2633 | struct run *run; | |
2634 | { | |
2635 | struct frame *f = XFRAME (w->frame); | |
2636 | int x, y, width, height, from_y, to_y, bottom_y; | |
4d6e8199 JR |
2637 | HWND hwnd = FRAME_W32_WINDOW (f); |
2638 | HRGN expect_dirty; | |
791f420f JR |
2639 | |
2640 | /* Get frame-relative bounding box of the text display area of W, | |
33c34bea KS |
2641 | without mode lines. Include in this box the left and right |
2642 | fringes of W. */ | |
791f420f | 2643 | window_box (w, -1, &x, &y, &width, &height); |
791f420f JR |
2644 | |
2645 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y); | |
2646 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y); | |
2647 | bottom_y = y + height; | |
2648 | ||
2649 | if (to_y < from_y) | |
2650 | { | |
2651 | /* Scrolling up. Make sure we don't copy part of the mode | |
2652 | line at the bottom. */ | |
2653 | if (from_y + run->height > bottom_y) | |
2654 | height = bottom_y - from_y; | |
2655 | else | |
2656 | height = run->height; | |
4d6e8199 | 2657 | expect_dirty = CreateRectRgn (x, y + height, x + width, bottom_y); |
791f420f JR |
2658 | } |
2659 | else | |
2660 | { | |
2661 | /* Scolling down. Make sure we don't copy over the mode line. | |
2662 | at the bottom. */ | |
2663 | if (to_y + run->height > bottom_y) | |
2664 | height = bottom_y - to_y; | |
2665 | else | |
2666 | height = run->height; | |
4d6e8199 | 2667 | expect_dirty = CreateRectRgn (x, y, x + width, to_y); |
791f420f JR |
2668 | } |
2669 | ||
2670 | BLOCK_INPUT; | |
d67d1627 | 2671 | |
791f420f JR |
2672 | /* Cursor off. Will be switched on again in x_update_window_end. */ |
2673 | updated_window = w; | |
2674 | x_clear_cursor (w); | |
2675 | ||
4d6e8199 JR |
2676 | { |
2677 | RECT from; | |
2678 | RECT to; | |
2679 | HRGN dirty = CreateRectRgn (0, 0, 0, 0); | |
2680 | HRGN combined = CreateRectRgn (0, 0, 0, 0); | |
2681 | ||
2682 | from.left = to.left = x; | |
2683 | from.right = to.right = x + width; | |
2684 | from.top = from_y; | |
2685 | from.bottom = from_y + height; | |
2686 | to.top = y; | |
2687 | to.bottom = bottom_y; | |
2688 | ||
2689 | ScrollWindowEx (hwnd, 0, to_y - from_y, &from, &to, dirty, | |
2690 | NULL, SW_INVALIDATE); | |
2691 | ||
2692 | /* Combine this with what we expect to be dirty. This covers the | |
2693 | case where not all of the region we expect is actually dirty. */ | |
2694 | CombineRgn (combined, dirty, expect_dirty, RGN_OR); | |
2695 | ||
2696 | /* If the dirty region is not what we expected, redraw the entire frame. */ | |
2697 | if (!EqualRgn (combined, expect_dirty)) | |
2698 | SET_FRAME_GARBAGED (f); | |
e8ac5d88 JR |
2699 | |
2700 | DeleteObject (dirty); | |
2701 | DeleteObject (combined); | |
4d6e8199 JR |
2702 | } |
2703 | ||
791f420f | 2704 | UNBLOCK_INPUT; |
e8ac5d88 | 2705 | DeleteObject (expect_dirty); |
791f420f JR |
2706 | } |
2707 | ||
9ef2e2cf | 2708 | |
ee78dc32 | 2709 | \f |
791f420f JR |
2710 | /*********************************************************************** |
2711 | Exposure Events | |
2712 | ***********************************************************************/ | |
d67d1627 | 2713 | |
96214669 | 2714 | static void |
89271099 | 2715 | frame_highlight (f) |
791f420f | 2716 | struct frame *f; |
ee78dc32 | 2717 | { |
89271099 | 2718 | x_update_cursor (f, 1); |
8b61a891 | 2719 | x_set_frame_alpha (f); |
89271099 | 2720 | } |
791f420f | 2721 | |
89271099 KS |
2722 | static void |
2723 | frame_unhighlight (f) | |
2724 | struct frame *f; | |
2725 | { | |
2726 | x_update_cursor (f, 1); | |
8b61a891 | 2727 | x_set_frame_alpha (f); |
89271099 | 2728 | } |
791f420f | 2729 | |
89271099 KS |
2730 | /* The focus has changed. Update the frames as necessary to reflect |
2731 | the new situation. Note that we can't change the selected frame | |
2732 | here, because the Lisp code we are interrupting might become confused. | |
2733 | Each event gets marked with the frame in which it occurred, so the | |
2734 | Lisp code can tell when the switch took place by examining the events. */ | |
791f420f | 2735 | |
89271099 KS |
2736 | static void |
2737 | x_new_focus_frame (dpyinfo, frame) | |
2738 | struct w32_display_info *dpyinfo; | |
2739 | struct frame *frame; | |
2740 | { | |
2741 | struct frame *old_focus = dpyinfo->w32_focus_frame; | |
791f420f | 2742 | |
89271099 | 2743 | if (frame != dpyinfo->w32_focus_frame) |
791f420f | 2744 | { |
89271099 KS |
2745 | /* Set this before calling other routines, so that they see |
2746 | the correct value of w32_focus_frame. */ | |
2747 | dpyinfo->w32_focus_frame = frame; | |
791f420f | 2748 | |
89271099 KS |
2749 | if (old_focus && old_focus->auto_lower) |
2750 | x_lower_frame (old_focus); | |
791f420f | 2751 | |
89271099 KS |
2752 | if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise) |
2753 | pending_autoraise_frame = dpyinfo->w32_focus_frame; | |
2df85294 | 2754 | else |
89271099 | 2755 | pending_autoraise_frame = 0; |
791f420f | 2756 | } |
89271099 KS |
2757 | |
2758 | x_frame_rehighlight (dpyinfo); | |
791f420f JR |
2759 | } |
2760 | ||
55131bef JR |
2761 | |
2762 | /* Handle FocusIn and FocusOut state changes for FRAME. | |
2763 | If FRAME has focus and there exists more than one frame, puts | |
2764 | a FOCUS_IN_EVENT into *BUFP. */ | |
2765 | ||
2766 | static void | |
2767 | x_focus_changed (type, state, dpyinfo, frame, bufp) | |
2768 | int type; | |
2769 | int state; | |
2770 | struct w32_display_info *dpyinfo; | |
2771 | struct frame *frame; | |
2772 | struct input_event *bufp; | |
2773 | { | |
2774 | if (type == WM_SETFOCUS) | |
2775 | { | |
2776 | if (dpyinfo->w32_focus_event_frame != frame) | |
2777 | { | |
2778 | x_new_focus_frame (dpyinfo, frame); | |
2779 | dpyinfo->w32_focus_event_frame = frame; | |
2780 | ||
2781 | /* Don't stop displaying the initial startup message | |
2782 | for a switch-frame event we don't need. */ | |
8e50cc2d SM |
2783 | if (NILP (Vterminal_frame) |
2784 | && CONSP (Vframe_list) | |
2785 | && !NILP (XCDR (Vframe_list))) | |
55131bef JR |
2786 | { |
2787 | bufp->kind = FOCUS_IN_EVENT; | |
2788 | XSETFRAME (bufp->frame_or_window, frame); | |
2789 | } | |
2790 | } | |
2791 | ||
2792 | frame->output_data.x->focus_state |= state; | |
2793 | ||
2794 | /* TODO: IME focus? */ | |
2795 | } | |
2796 | else if (type == WM_KILLFOCUS) | |
2797 | { | |
2798 | frame->output_data.x->focus_state &= ~state; | |
2799 | ||
2800 | if (dpyinfo->w32_focus_event_frame == frame) | |
2801 | { | |
2802 | dpyinfo->w32_focus_event_frame = 0; | |
2803 | x_new_focus_frame (dpyinfo, 0); | |
2804 | } | |
2805 | ||
2806 | /* TODO: IME focus? */ | |
2807 | } | |
2808 | } | |
2809 | ||
2810 | ||
2811 | /* The focus may have changed. Figure out if it is a real focus change, | |
2812 | by checking both FocusIn/Out and Enter/LeaveNotify events. | |
2813 | ||
2814 | Returns FOCUS_IN_EVENT event in *BUFP. */ | |
2815 | ||
2816 | static void | |
2817 | w32_detect_focus_change (dpyinfo, event, bufp) | |
2818 | struct w32_display_info *dpyinfo; | |
2819 | W32Msg *event; | |
2820 | struct input_event *bufp; | |
2821 | { | |
2822 | struct frame *frame; | |
2823 | ||
2824 | frame = x_any_window_to_frame (dpyinfo, event->msg.hwnd); | |
2825 | if (! frame) | |
2826 | return; | |
2827 | ||
2828 | /* On w32, this is only called from focus events, so no switch needed. */ | |
2829 | x_focus_changed (event->msg.message, | |
2830 | (event->msg.message == WM_KILLFOCUS ? | |
2831 | FOCUS_IMPLICIT : FOCUS_EXPLICIT), | |
2832 | dpyinfo, frame, bufp); | |
2833 | } | |
2834 | ||
2835 | ||
89271099 | 2836 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ |
ee78dc32 GV |
2837 | |
2838 | void | |
2839 | x_mouse_leave (dpyinfo) | |
fbd6baed | 2840 | struct w32_display_info *dpyinfo; |
ee78dc32 | 2841 | { |
fbd6baed | 2842 | x_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame); |
ee78dc32 GV |
2843 | } |
2844 | ||
2845 | /* The focus has changed, or we have redirected a frame's focus to | |
2846 | another frame (this happens when a frame uses a surrogate | |
9ef2e2cf | 2847 | mini-buffer frame). Shift the highlight as appropriate. |
ee78dc32 GV |
2848 | |
2849 | The FRAME argument doesn't necessarily have anything to do with which | |
9ef2e2cf JR |
2850 | frame is being highlighted or un-highlighted; we only use it to find |
2851 | the appropriate X display info. */ | |
2852 | ||
ee78dc32 | 2853 | static void |
fbd6baed | 2854 | w32_frame_rehighlight (frame) |
ee78dc32 GV |
2855 | struct frame *frame; |
2856 | { | |
7e6ac5b9 AI |
2857 | if (! FRAME_W32_P (frame)) |
2858 | return; | |
fbd6baed | 2859 | x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame)); |
ee78dc32 GV |
2860 | } |
2861 | ||
2862 | static void | |
2863 | x_frame_rehighlight (dpyinfo) | |
fbd6baed | 2864 | struct w32_display_info *dpyinfo; |
ee78dc32 | 2865 | { |
4baaed0f | 2866 | struct frame *old_highlight = dpyinfo->x_highlight_frame; |
ee78dc32 | 2867 | |
fbd6baed | 2868 | if (dpyinfo->w32_focus_frame) |
ee78dc32 | 2869 | { |
4baaed0f | 2870 | dpyinfo->x_highlight_frame |
8e50cc2d | 2871 | = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame))) |
fbd6baed GV |
2872 | ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame)) |
2873 | : dpyinfo->w32_focus_frame); | |
4baaed0f | 2874 | if (! FRAME_LIVE_P (dpyinfo->x_highlight_frame)) |
ee78dc32 | 2875 | { |
fbd6baed | 2876 | FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame) = Qnil; |
4baaed0f | 2877 | dpyinfo->x_highlight_frame = dpyinfo->w32_focus_frame; |
ee78dc32 GV |
2878 | } |
2879 | } | |
2880 | else | |
4baaed0f | 2881 | dpyinfo->x_highlight_frame = 0; |
ee78dc32 | 2882 | |
4baaed0f | 2883 | if (dpyinfo->x_highlight_frame != old_highlight) |
ee78dc32 GV |
2884 | { |
2885 | if (old_highlight) | |
2886 | frame_unhighlight (old_highlight); | |
4baaed0f KS |
2887 | if (dpyinfo->x_highlight_frame) |
2888 | frame_highlight (dpyinfo->x_highlight_frame); | |
ee78dc32 GV |
2889 | } |
2890 | } | |
2891 | \f | |
2892 | /* Keyboard processing - modifier keys, etc. */ | |
2893 | ||
2894 | /* Convert a keysym to its name. */ | |
2895 | ||
2896 | char * | |
2897 | x_get_keysym_name (keysym) | |
2898 | int keysym; | |
2899 | { | |
2900 | /* Make static so we can always return it */ | |
2901 | static char value[100]; | |
2902 | ||
2903 | BLOCK_INPUT; | |
9127e20e | 2904 | GetKeyNameText (keysym, value, 100); |
ee78dc32 GV |
2905 | UNBLOCK_INPUT; |
2906 | ||
2907 | return value; | |
2908 | } | |
9ef2e2cf | 2909 | |
13087e59 JR |
2910 | static int codepage_for_locale(LCID locale) |
2911 | { | |
2912 | char cp[20]; | |
2913 | ||
2914 | if (GetLocaleInfo (locale, LOCALE_IDEFAULTANSICODEPAGE, cp, 20) > 0) | |
2915 | return atoi (cp); | |
2916 | else | |
2917 | return CP_ACP; | |
2918 | } | |
9ef2e2cf | 2919 | |
ee78dc32 GV |
2920 | \f |
2921 | /* Mouse clicks and mouse movement. Rah. */ | |
2922 | ||
53823ab9 JR |
2923 | /* Parse a button MESSAGE. The button index is returned in PBUTTON, and |
2924 | the state in PUP. XBUTTON provides extra information for extended mouse | |
2925 | button messages. Returns FALSE if unable to parse the message. */ | |
d67d1627 | 2926 | BOOL |
53823ab9 | 2927 | parse_button (message, xbutton, pbutton, pup) |
ee78dc32 | 2928 | int message; |
53823ab9 | 2929 | int xbutton; |
ee78dc32 GV |
2930 | int * pbutton; |
2931 | int * pup; | |
2932 | { | |
2933 | int button = 0; | |
2934 | int up = 0; | |
d67d1627 | 2935 | |
ee78dc32 GV |
2936 | switch (message) |
2937 | { | |
2938 | case WM_LBUTTONDOWN: | |
2939 | button = 0; | |
2940 | up = 0; | |
2941 | break; | |
2942 | case WM_LBUTTONUP: | |
2943 | button = 0; | |
2944 | up = 1; | |
2945 | break; | |
2946 | case WM_MBUTTONDOWN: | |
fbd6baed | 2947 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
2948 | button = 1; |
2949 | else | |
2950 | button = 2; | |
ee78dc32 GV |
2951 | up = 0; |
2952 | break; | |
2953 | case WM_MBUTTONUP: | |
fbd6baed | 2954 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
2955 | button = 1; |
2956 | else | |
2957 | button = 2; | |
ee78dc32 GV |
2958 | up = 1; |
2959 | break; | |
2960 | case WM_RBUTTONDOWN: | |
fbd6baed | 2961 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
2962 | button = 2; |
2963 | else | |
2964 | button = 1; | |
ee78dc32 GV |
2965 | up = 0; |
2966 | break; | |
2967 | case WM_RBUTTONUP: | |
fbd6baed | 2968 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
2969 | button = 2; |
2970 | else | |
2971 | button = 1; | |
ee78dc32 GV |
2972 | up = 1; |
2973 | break; | |
53823ab9 JR |
2974 | case WM_XBUTTONDOWN: |
2975 | button = xbutton + 2; | |
2976 | up = 0; | |
2977 | break; | |
2978 | case WM_XBUTTONUP: | |
2979 | button = xbutton + 2; | |
2980 | up = 1; | |
2981 | break; | |
ee78dc32 GV |
2982 | default: |
2983 | return (FALSE); | |
2984 | } | |
d67d1627 | 2985 | |
ee78dc32 GV |
2986 | if (pup) *pup = up; |
2987 | if (pbutton) *pbutton = button; | |
d67d1627 | 2988 | |
ee78dc32 GV |
2989 | return (TRUE); |
2990 | } | |
2991 | ||
2992 | ||
2993 | /* Prepare a mouse-event in *RESULT for placement in the input queue. | |
2994 | ||
2995 | If the event is a button press, then note that we have grabbed | |
2996 | the mouse. */ | |
2997 | ||
ec48c3a7 | 2998 | static Lisp_Object |
ee78dc32 GV |
2999 | construct_mouse_click (result, msg, f) |
3000 | struct input_event *result; | |
fbd6baed | 3001 | W32Msg *msg; |
ee78dc32 GV |
3002 | struct frame *f; |
3003 | { | |
3004 | int button; | |
3005 | int up; | |
3006 | ||
53823ab9 JR |
3007 | parse_button (msg->msg.message, HIWORD (msg->msg.wParam), |
3008 | &button, &up); | |
ee78dc32 | 3009 | |
3b8f9651 | 3010 | /* Make the event type NO_EVENT; we'll change that when we decide |
ee78dc32 | 3011 | otherwise. */ |
3b8f9651 | 3012 | result->kind = MOUSE_CLICK_EVENT; |
ee78dc32 GV |
3013 | result->code = button; |
3014 | result->timestamp = msg->msg.time; | |
3015 | result->modifiers = (msg->dwModifiers | |
3016 | | (up | |
3017 | ? up_modifier | |
3018 | : down_modifier)); | |
3019 | ||
ec48c3a7 JR |
3020 | XSETINT (result->x, LOWORD (msg->msg.lParam)); |
3021 | XSETINT (result->y, HIWORD (msg->msg.lParam)); | |
3022 | XSETFRAME (result->frame_or_window, f); | |
3023 | result->arg = Qnil; | |
3024 | return Qnil; | |
ee78dc32 GV |
3025 | } |
3026 | ||
ec48c3a7 | 3027 | static Lisp_Object |
689004fa GV |
3028 | construct_mouse_wheel (result, msg, f) |
3029 | struct input_event *result; | |
3030 | W32Msg *msg; | |
3031 | struct frame *f; | |
3032 | { | |
3033 | POINT p; | |
637ad49d JR |
3034 | int delta; |
3035 | ||
1526bc23 JR |
3036 | result->kind = msg->msg.message == WM_MOUSEHWHEEL ? HORIZ_WHEEL_EVENT |
3037 | : WHEEL_EVENT; | |
637ad49d | 3038 | result->code = 0; |
689004fa | 3039 | result->timestamp = msg->msg.time; |
637ad49d JR |
3040 | |
3041 | /* A WHEEL_DELTA positive value indicates that the wheel was rotated | |
3042 | forward, away from the user (up); a negative value indicates that | |
3043 | the wheel was rotated backward, toward the user (down). */ | |
3044 | delta = GET_WHEEL_DELTA_WPARAM (msg->msg.wParam); | |
3045 | ||
3046 | /* The up and down modifiers indicate if the wheel was rotated up or | |
3047 | down based on WHEEL_DELTA value. */ | |
3048 | result->modifiers = (msg->dwModifiers | |
3049 | | ((delta < 0 ) ? down_modifier : up_modifier)); | |
3050 | ||
8b03732e JR |
3051 | /* With multiple monitors, we can legitimately get negative |
3052 | coordinates, so cast to short to interpret them correctly. */ | |
3053 | p.x = (short) LOWORD (msg->msg.lParam); | |
3054 | p.y = (short) HIWORD (msg->msg.lParam); | |
9127e20e | 3055 | ScreenToClient (msg->msg.hwnd, &p); |
689004fa GV |
3056 | XSETINT (result->x, p.x); |
3057 | XSETINT (result->y, p.y); | |
3058 | XSETFRAME (result->frame_or_window, f); | |
7e889510 | 3059 | result->arg = Qnil; |
ec48c3a7 | 3060 | return Qnil; |
689004fa GV |
3061 | } |
3062 | ||
ec48c3a7 | 3063 | static Lisp_Object |
12857dfd RS |
3064 | construct_drag_n_drop (result, msg, f) |
3065 | struct input_event *result; | |
3066 | W32Msg *msg; | |
3067 | struct frame *f; | |
3068 | { | |
3069 | Lisp_Object files; | |
3070 | Lisp_Object frame; | |
3071 | HDROP hdrop; | |
3072 | POINT p; | |
3073 | WORD num_files; | |
89271099 KS |
3074 | char *name; |
3075 | int i, len; | |
d67d1627 | 3076 | |
89271099 KS |
3077 | result->kind = DRAG_N_DROP_EVENT; |
3078 | result->code = 0; | |
3079 | result->timestamp = msg->msg.time; | |
3080 | result->modifiers = msg->dwModifiers; | |
791f420f | 3081 | |
89271099 KS |
3082 | hdrop = (HDROP) msg->msg.wParam; |
3083 | DragQueryPoint (hdrop, &p); | |
791f420f | 3084 | |
89271099 KS |
3085 | #if 0 |
3086 | p.x = LOWORD (msg->msg.lParam); | |
3087 | p.y = HIWORD (msg->msg.lParam); | |
3088 | ScreenToClient (msg->msg.hwnd, &p); | |
3089 | #endif | |
791f420f | 3090 | |
89271099 KS |
3091 | XSETINT (result->x, p.x); |
3092 | XSETINT (result->y, p.y); | |
791f420f | 3093 | |
89271099 KS |
3094 | num_files = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); |
3095 | files = Qnil; | |
ee78dc32 | 3096 | |
89271099 KS |
3097 | for (i = 0; i < num_files; i++) |
3098 | { | |
3099 | len = DragQueryFile (hdrop, i, NULL, 0); | |
3100 | if (len <= 0) | |
3101 | continue; | |
3102 | name = alloca (len + 1); | |
3103 | DragQueryFile (hdrop, i, name, len + 1); | |
3104 | files = Fcons (DECODE_FILE (build_string (name)), files); | |
ee78dc32 GV |
3105 | } |
3106 | ||
89271099 | 3107 | DragFinish (hdrop); |
2bf04b9d | 3108 | |
89271099 | 3109 | XSETFRAME (frame, f); |
00cff0a1 YM |
3110 | result->frame_or_window = frame; |
3111 | result->arg = files; | |
89271099 | 3112 | return Qnil; |
ee78dc32 GV |
3113 | } |
3114 | ||
89271099 KS |
3115 | \f |
3116 | /* Function to report a mouse movement to the mainstream Emacs code. | |
3117 | The input handler calls this. | |
ee78dc32 | 3118 | |
89271099 KS |
3119 | We have received a mouse movement event, which is given in *event. |
3120 | If the mouse is over a different glyph than it was last time, tell | |
3121 | the mainstream emacs code by setting mouse_moved. If not, ask for | |
3122 | another motion event, so we can check again the next time it moves. */ | |
31d4844a | 3123 | |
89271099 KS |
3124 | static MSG last_mouse_motion_event; |
3125 | static Lisp_Object last_mouse_motion_frame; | |
ec48c3a7 | 3126 | |
fc5c7550 | 3127 | static int |
89271099 KS |
3128 | note_mouse_movement (frame, msg) |
3129 | FRAME_PTR frame; | |
3130 | MSG *msg; | |
ec48c3a7 | 3131 | { |
89271099 KS |
3132 | int mouse_x = LOWORD (msg->lParam); |
3133 | int mouse_y = HIWORD (msg->lParam); | |
ec48c3a7 | 3134 | |
89271099 KS |
3135 | last_mouse_movement_time = msg->time; |
3136 | memcpy (&last_mouse_motion_event, msg, sizeof (last_mouse_motion_event)); | |
3137 | XSETFRAME (last_mouse_motion_frame, frame); | |
31d4844a | 3138 | |
027f6f90 JR |
3139 | if (!FRAME_X_OUTPUT (frame)) |
3140 | return 0; | |
3141 | ||
89271099 KS |
3142 | if (msg->hwnd != FRAME_W32_WINDOW (frame)) |
3143 | { | |
3144 | frame->mouse_moved = 1; | |
3145 | last_mouse_scroll_bar = Qnil; | |
3146 | note_mouse_highlight (frame, -1, -1); | |
d3499758 | 3147 | last_mouse_glyph_frame = 0; |
fc5c7550 | 3148 | return 1; |
89271099 | 3149 | } |
31d4844a | 3150 | |
89271099 | 3151 | /* Has the mouse moved off the glyph it was on at the last sighting? */ |
d3499758 JR |
3152 | if (frame != last_mouse_glyph_frame |
3153 | || mouse_x < last_mouse_glyph.left | |
fc5c7550 YM |
3154 | || mouse_x >= last_mouse_glyph.right |
3155 | || mouse_y < last_mouse_glyph.top | |
3156 | || mouse_y >= last_mouse_glyph.bottom) | |
31d4844a | 3157 | { |
89271099 KS |
3158 | frame->mouse_moved = 1; |
3159 | last_mouse_scroll_bar = Qnil; | |
3160 | note_mouse_highlight (frame, mouse_x, mouse_y); | |
3161 | /* Remember the mouse position here, as w32_mouse_position only | |
3162 | gets called when mouse tracking is enabled but we also need | |
3163 | to keep track of the mouse for help_echo and highlighting at | |
3164 | other times. */ | |
1bb92eca | 3165 | remember_mouse_glyph (frame, mouse_x, mouse_y, &last_mouse_glyph); |
d3499758 | 3166 | last_mouse_glyph_frame = frame; |
fc5c7550 | 3167 | return 1; |
31d4844a | 3168 | } |
fc5c7550 YM |
3169 | |
3170 | return 0; | |
31d4844a | 3171 | } |
89271099 | 3172 | |
ee78dc32 | 3173 | \f |
89271099 KS |
3174 | /************************************************************************ |
3175 | Mouse Face | |
3176 | ************************************************************************/ | |
3177 | ||
9ef2e2cf | 3178 | static struct scroll_bar *x_window_to_scroll_bar (); |
ee78dc32 | 3179 | static void x_scroll_bar_report_motion (); |
549808db | 3180 | static void x_check_fullscreen P_ ((struct frame *)); |
9f5a911b | 3181 | |
89271099 KS |
3182 | static void |
3183 | redo_mouse_highlight () | |
3184 | { | |
3185 | if (!NILP (last_mouse_motion_frame) | |
3186 | && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) | |
3187 | note_mouse_highlight (XFRAME (last_mouse_motion_frame), | |
3188 | LOWORD (last_mouse_motion_event.lParam), | |
3189 | HIWORD (last_mouse_motion_event.lParam)); | |
3190 | } | |
3191 | ||
1bb8a291 | 3192 | static void |
89271099 KS |
3193 | w32_define_cursor (window, cursor) |
3194 | Window window; | |
3195 | Cursor cursor; | |
3196 | { | |
3197 | PostMessage (window, WM_EMACS_SETCURSOR, (WPARAM) cursor, 0); | |
3198 | } | |
ee78dc32 GV |
3199 | /* Return the current position of the mouse. |
3200 | *fp should be a frame which indicates which display to ask about. | |
3201 | ||
3202 | If the mouse movement started in a scroll bar, set *fp, *bar_window, | |
3203 | and *part to the frame, window, and scroll bar part that the mouse | |
3204 | is over. Set *x and *y to the portion and whole of the mouse's | |
3205 | position on the scroll bar. | |
3206 | ||
3207 | If the mouse movement started elsewhere, set *fp to the frame the | |
3208 | mouse is on, *bar_window to nil, and *x and *y to the character cell | |
3209 | the mouse is over. | |
3210 | ||
9ef2e2cf | 3211 | Set *time to the server time-stamp for the time at which the mouse |
ee78dc32 GV |
3212 | was at this position. |
3213 | ||
3214 | Don't store anything if we don't have a valid set of values to report. | |
3215 | ||
3216 | This clears the mouse_moved flag, so we can wait for the next mouse | |
9ef2e2cf | 3217 | movement. */ |
ee78dc32 GV |
3218 | |
3219 | static void | |
fbd6baed | 3220 | w32_mouse_position (fp, insist, bar_window, part, x, y, time) |
ee78dc32 GV |
3221 | FRAME_PTR *fp; |
3222 | int insist; | |
3223 | Lisp_Object *bar_window; | |
3224 | enum scroll_bar_part *part; | |
3225 | Lisp_Object *x, *y; | |
3226 | unsigned long *time; | |
3227 | { | |
3228 | FRAME_PTR f1; | |
3229 | ||
3230 | BLOCK_INPUT; | |
3231 | ||
95fa970d | 3232 | if (! NILP (last_mouse_scroll_bar) && insist == 0) |
ee78dc32 GV |
3233 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); |
3234 | else | |
3235 | { | |
3236 | POINT pt; | |
3237 | ||
3238 | Lisp_Object frame, tail; | |
3239 | ||
3240 | /* Clear the mouse-moved flag for every frame on this display. */ | |
3241 | FOR_EACH_FRAME (tail, frame) | |
3242 | XFRAME (frame)->mouse_moved = 0; | |
3243 | ||
3244 | last_mouse_scroll_bar = Qnil; | |
d67d1627 | 3245 | |
ee78dc32 GV |
3246 | GetCursorPos (&pt); |
3247 | ||
3248 | /* Now we have a position on the root; find the innermost window | |
3249 | containing the pointer. */ | |
3250 | { | |
fbd6baed | 3251 | if (FRAME_W32_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame |
ee78dc32 GV |
3252 | && FRAME_LIVE_P (last_mouse_frame)) |
3253 | { | |
08712a41 AI |
3254 | /* If mouse was grabbed on a frame, give coords for that frame |
3255 | even if the mouse is now outside it. */ | |
ee78dc32 GV |
3256 | f1 = last_mouse_frame; |
3257 | } | |
3258 | else | |
3259 | { | |
08712a41 | 3260 | /* Is window under mouse one of our frames? */ |
9f5a911b | 3261 | f1 = x_any_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp), |
9127e20e | 3262 | WindowFromPoint (pt)); |
ee78dc32 GV |
3263 | } |
3264 | ||
3265 | /* If not, is it one of our scroll bars? */ | |
3266 | if (! f1) | |
3267 | { | |
9127e20e JR |
3268 | struct scroll_bar *bar |
3269 | = x_window_to_scroll_bar (WindowFromPoint (pt)); | |
ee78dc32 GV |
3270 | |
3271 | if (bar) | |
3272 | { | |
3273 | f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
3274 | } | |
3275 | } | |
3276 | ||
95fa970d | 3277 | if (f1 == 0 && insist > 0) |
791f420f | 3278 | f1 = SELECTED_FRAME (); |
ee78dc32 GV |
3279 | |
3280 | if (f1) | |
3281 | { | |
791f420f JR |
3282 | /* Ok, we found a frame. Store all the values. |
3283 | last_mouse_glyph is a rectangle used to reduce the | |
3284 | generation of mouse events. To not miss any motion | |
3285 | events, we must divide the frame into rectangles of the | |
3286 | size of the smallest character that could be displayed | |
3287 | on it, i.e. into the same rectangles that matrices on | |
3288 | the frame are divided into. */ | |
3289 | ||
791f420f | 3290 | ScreenToClient (FRAME_W32_WINDOW (f1), &pt); |
1bb92eca | 3291 | remember_mouse_glyph (f1, pt.x, pt.y, &last_mouse_glyph); |
d3499758 | 3292 | last_mouse_glyph_frame = f1; |
ee78dc32 GV |
3293 | |
3294 | *bar_window = Qnil; | |
3295 | *part = 0; | |
3296 | *fp = f1; | |
3297 | XSETINT (*x, pt.x); | |
3298 | XSETINT (*y, pt.y); | |
3299 | *time = last_mouse_movement_time; | |
3300 | } | |
3301 | } | |
3302 | } | |
3303 | ||
3304 | UNBLOCK_INPUT; | |
3305 | } | |
791f420f | 3306 | |
ee78dc32 | 3307 | \f |
89271099 KS |
3308 | /*********************************************************************** |
3309 | Tool-bars | |
3310 | ***********************************************************************/ | |
3311 | ||
3312 | /* Handle mouse button event on the tool-bar of frame F, at | |
3313 | frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress | |
3314 | or ButtonRelase. */ | |
3315 | ||
3316 | static void | |
3317 | w32_handle_tool_bar_click (f, button_event) | |
3318 | struct frame *f; | |
3319 | struct input_event *button_event; | |
3320 | { | |
3321 | int x = XFASTINT (button_event->x); | |
3322 | int y = XFASTINT (button_event->y); | |
3323 | ||
3324 | if (button_event->modifiers & down_modifier) | |
3325 | handle_tool_bar_click (f, x, y, 1, 0); | |
3326 | else | |
3327 | handle_tool_bar_click (f, x, y, 0, | |
3328 | button_event->modifiers & ~up_modifier); | |
3329 | } | |
3330 | ||
3331 | ||
3332 | \f | |
3333 | /*********************************************************************** | |
3334 | Scroll bars | |
3335 | ***********************************************************************/ | |
3336 | ||
ee78dc32 GV |
3337 | /* Scroll bar support. */ |
3338 | ||
ec48c3a7 | 3339 | /* Given a window ID, find the struct scroll_bar which manages it. |
ee78dc32 GV |
3340 | This can be called in GC, so we have to make sure to strip off mark |
3341 | bits. */ | |
9ef2e2cf JR |
3342 | |
3343 | static struct scroll_bar * | |
ee78dc32 GV |
3344 | x_window_to_scroll_bar (window_id) |
3345 | Window window_id; | |
3346 | { | |
791f420f | 3347 | Lisp_Object tail; |
ee78dc32 | 3348 | |
8e50cc2d | 3349 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
ee78dc32 GV |
3350 | { |
3351 | Lisp_Object frame, bar, condemned; | |
3352 | ||
8e713be6 | 3353 | frame = XCAR (tail); |
ee78dc32 | 3354 | /* All elements of Vframe_list should be frames. */ |
8e50cc2d | 3355 | if (! FRAMEP (frame)) |
ee78dc32 GV |
3356 | abort (); |
3357 | ||
3358 | /* Scan this frame's scroll bar list for a scroll bar with the | |
3359 | right window ID. */ | |
3360 | condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); | |
3361 | for (bar = FRAME_SCROLL_BARS (XFRAME (frame)); | |
3362 | /* This trick allows us to search both the ordinary and | |
3363 | condemned scroll bar lists with one loop. */ | |
8e50cc2d | 3364 | ! NILP (bar) || (bar = condemned, |
ee78dc32 | 3365 | condemned = Qnil, |
8e50cc2d | 3366 | ! NILP (bar)); |
ee78dc32 | 3367 | bar = XSCROLL_BAR (bar)->next) |
fbd6baed | 3368 | if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)) == window_id) |
ee78dc32 GV |
3369 | return XSCROLL_BAR (bar); |
3370 | } | |
3371 | ||
3372 | return 0; | |
3373 | } | |
3374 | ||
791f420f JR |
3375 | |
3376 | \f | |
3377 | /* Set the thumb size and position of scroll bar BAR. We are currently | |
3378 | displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
3379 | ||
3380 | static void | |
3381 | w32_set_scroll_bar_thumb (bar, portion, position, whole) | |
3382 | struct scroll_bar *bar; | |
3383 | int portion, position, whole; | |
3384 | { | |
3385 | Window w = SCROLL_BAR_W32_WINDOW (bar); | |
feade168 KS |
3386 | /* We use the whole scroll-bar height in the calculations below, to |
3387 | avoid strange effects like scrolling backwards when just clicking | |
3388 | on the handle (without moving it). */ | |
3389 | double range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) | |
3390 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
791f420f JR |
3391 | int sb_page, sb_pos; |
3392 | BOOL draggingp = !NILP (bar->dragging) ? TRUE : FALSE; | |
818a1a5d | 3393 | SCROLLINFO si; |
791f420f | 3394 | |
feade168 KS |
3395 | /* We used to change the nPage setting while dragging the handle, |
3396 | but that had very strange effects (such as scrolling backwards | |
3397 | while dragging downwards). | |
3398 | ||
3399 | Now, we don't change the nPage setting while dragging unless we | |
3400 | get near to the end of the buffer, in which case we often have to | |
3401 | resize the handle to "go all the way". */ | |
3402 | ||
3403 | if (draggingp) | |
791f420f | 3404 | { |
feade168 KS |
3405 | int near_bottom_p; |
3406 | BLOCK_INPUT; | |
3407 | si.cbSize = sizeof (si); | |
3408 | si.fMask = SIF_POS | SIF_PAGE; | |
3409 | GetScrollInfo(w, SB_CTL, &si); | |
3410 | near_bottom_p = si.nPos + si.nPage >= range; | |
3411 | UNBLOCK_INPUT; | |
3412 | if (!near_bottom_p) | |
3413 | return; | |
3414 | } | |
f65aa365 | 3415 | |
791f420f JR |
3416 | if (whole) |
3417 | { | |
3418 | /* Position scroll bar at rock bottom if the bottom of the | |
3419 | buffer is visible. This avoids shinking the thumb away | |
3420 | to nothing if it is held at the bottom of the buffer. */ | |
feade168 KS |
3421 | if (position + portion >= whole && !draggingp) |
3422 | { | |
3423 | sb_page = range * (whole - position) / whole; | |
3424 | sb_pos = range; | |
3425 | } | |
3426 | else | |
3427 | { | |
3428 | sb_pos = position * range / whole; | |
3429 | sb_page = (min (portion, (whole - position)) * range) / whole; | |
3430 | } | |
791f420f JR |
3431 | } |
3432 | else | |
3433 | { | |
3434 | sb_page = range; | |
3435 | sb_pos = 0; | |
3436 | } | |
3437 | ||
feade168 KS |
3438 | sb_page = max (sb_page, VERTICAL_SCROLL_BAR_MIN_HANDLE); |
3439 | ||
791f420f JR |
3440 | BLOCK_INPUT; |
3441 | ||
818a1a5d | 3442 | si.cbSize = sizeof (si); |
feade168 | 3443 | si.fMask = SIF_PAGE | SIF_POS; |
818a1a5d JR |
3444 | si.nPage = sb_page; |
3445 | si.nPos = sb_pos; | |
3446 | ||
feade168 | 3447 | SetScrollInfo (w, SB_CTL, &si, TRUE); |
791f420f JR |
3448 | |
3449 | UNBLOCK_INPUT; | |
3450 | } | |
3451 | ||
3452 | \f | |
3453 | /************************************************************************ | |
3454 | Scroll bars, general | |
3455 | ************************************************************************/ | |
d67d1627 | 3456 | |
decb374a | 3457 | static HWND |
ee78dc32 GV |
3458 | my_create_scrollbar (f, bar) |
3459 | struct frame * f; | |
3460 | struct scroll_bar * bar; | |
3461 | { | |
689004fa | 3462 | return (HWND) SendMessage (FRAME_W32_WINDOW (f), |
d67d1627 | 3463 | WM_EMACS_CREATESCROLLBAR, (WPARAM) f, |
689004fa | 3464 | (LPARAM) bar); |
ee78dc32 GV |
3465 | } |
3466 | ||
ab76d376 | 3467 | /*#define ATTACH_THREADS*/ |
52cf03a1 | 3468 | |
14d050df | 3469 | static BOOL |
689004fa | 3470 | my_show_window (FRAME_PTR f, HWND hwnd, int how) |
52cf03a1 GV |
3471 | { |
3472 | #ifndef ATTACH_THREADS | |
689004fa GV |
3473 | return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW, |
3474 | (WPARAM) hwnd, (LPARAM) how); | |
52cf03a1 | 3475 | #else |
689004fa | 3476 | return ShowWindow (hwnd, how); |
52cf03a1 GV |
3477 | #endif |
3478 | } | |
3479 | ||
14d050df | 3480 | static void |
52cf03a1 | 3481 | my_set_window_pos (HWND hwnd, HWND hwndAfter, |
689004fa | 3482 | int x, int y, int cx, int cy, UINT flags) |
52cf03a1 GV |
3483 | { |
3484 | #ifndef ATTACH_THREADS | |
689004fa GV |
3485 | WINDOWPOS pos; |
3486 | pos.hwndInsertAfter = hwndAfter; | |
52cf03a1 GV |
3487 | pos.x = x; |
3488 | pos.y = y; | |
3489 | pos.cx = cx; | |
3490 | pos.cy = cy; | |
3491 | pos.flags = flags; | |
3492 | SendMessage (hwnd, WM_EMACS_SETWINDOWPOS, (WPARAM) &pos, 0); | |
3493 | #else | |
3494 | SetWindowPos (hwnd, hwndAfter, x, y, cx, cy, flags); | |
3495 | #endif | |
3496 | } | |
3497 | ||
14d050df | 3498 | static void |
689004fa GV |
3499 | my_set_focus (f, hwnd) |
3500 | struct frame * f; | |
3501 | HWND hwnd; | |
3502 | { | |
d67d1627 | 3503 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SETFOCUS, |
689004fa GV |
3504 | (WPARAM) hwnd, 0); |
3505 | } | |
3506 | ||
14d050df | 3507 | static void |
ef0e360f GV |
3508 | my_set_foreground_window (hwnd) |
3509 | HWND hwnd; | |
3510 | { | |
3511 | SendMessage (hwnd, WM_EMACS_SETFOREGROUND, (WPARAM) hwnd, 0); | |
3512 | } | |
3513 | ||
14d050df JB |
3514 | |
3515 | static void | |
ee78dc32 GV |
3516 | my_destroy_window (f, hwnd) |
3517 | struct frame * f; | |
3518 | HWND hwnd; | |
3519 | { | |
d67d1627 | 3520 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_DESTROYWINDOW, |
ee78dc32 GV |
3521 | (WPARAM) hwnd, 0); |
3522 | } | |
3523 | ||
791f420f JR |
3524 | /* Create a scroll bar and return the scroll bar vector for it. W is |
3525 | the Emacs window on which to create the scroll bar. TOP, LEFT, | |
3526 | WIDTH and HEIGHT are.the pixel coordinates and dimensions of the | |
3527 | scroll bar. */ | |
3528 | ||
ee78dc32 | 3529 | static struct scroll_bar * |
791f420f JR |
3530 | x_scroll_bar_create (w, top, left, width, height) |
3531 | struct window *w; | |
ee78dc32 GV |
3532 | int top, left, width, height; |
3533 | { | |
791f420f JR |
3534 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
3535 | HWND hwnd; | |
818a1a5d | 3536 | SCROLLINFO si; |
ee78dc32 GV |
3537 | struct scroll_bar *bar |
3538 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | |
ee78dc32 GV |
3539 | |
3540 | BLOCK_INPUT; | |
3541 | ||
791f420f | 3542 | XSETWINDOW (bar->window, w); |
ee78dc32 GV |
3543 | XSETINT (bar->top, top); |
3544 | XSETINT (bar->left, left); | |
3545 | XSETINT (bar->width, width); | |
3546 | XSETINT (bar->height, height); | |
3547 | XSETINT (bar->start, 0); | |
3548 | XSETINT (bar->end, 0); | |
3549 | bar->dragging = Qnil; | |
06929222 | 3550 | bar->fringe_extended_p = Qnil; |
ee78dc32 GV |
3551 | |
3552 | /* Requires geometry to be set before call to create the real window */ | |
3553 | ||
3554 | hwnd = my_create_scrollbar (f, bar); | |
3555 | ||
818a1a5d JR |
3556 | si.cbSize = sizeof (si); |
3557 | si.fMask = SIF_ALL; | |
3558 | si.nMin = 0; | |
3559 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) | |
3560 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
3561 | si.nPage = si.nMax; | |
3562 | si.nPos = 0; | |
689004fa | 3563 | |
818a1a5d | 3564 | SetScrollInfo (hwnd, SB_CTL, &si, FALSE); |
ee78dc32 | 3565 | |
fbd6baed | 3566 | SET_SCROLL_BAR_W32_WINDOW (bar, hwnd); |
ee78dc32 GV |
3567 | |
3568 | /* Add bar to its frame's list of scroll bars. */ | |
3569 | bar->next = FRAME_SCROLL_BARS (f); | |
3570 | bar->prev = Qnil; | |
3571 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
3572 | if (! NILP (bar->next)) | |
3573 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
3574 | ||
3575 | UNBLOCK_INPUT; | |
3576 | ||
3577 | return bar; | |
3578 | } | |
3579 | ||
ee78dc32 | 3580 | |
791f420f JR |
3581 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to |
3582 | nil. */ | |
ee78dc32 | 3583 | |
ee78dc32 GV |
3584 | static void |
3585 | x_scroll_bar_remove (bar) | |
3586 | struct scroll_bar *bar; | |
3587 | { | |
3588 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
3589 | ||
3590 | BLOCK_INPUT; | |
3591 | ||
3592 | /* Destroy the window. */ | |
fbd6baed | 3593 | my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar)); |
ee78dc32 GV |
3594 | |
3595 | /* Disassociate this scroll bar from its window. */ | |
3596 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | |
3597 | ||
3598 | UNBLOCK_INPUT; | |
3599 | } | |
3600 | ||
3601 | /* Set the handle of the vertical scroll bar for WINDOW to indicate | |
3602 | that we are displaying PORTION characters out of a total of WHOLE | |
3603 | characters, starting at POSITION. If WINDOW has no scroll bar, | |
3604 | create one. */ | |
3605 | static void | |
791f420f JR |
3606 | w32_set_vertical_scroll_bar (w, portion, whole, position) |
3607 | struct window *w; | |
ee78dc32 GV |
3608 | int portion, whole, position; |
3609 | { | |
791f420f | 3610 | struct frame *f = XFRAME (w->frame); |
ee78dc32 | 3611 | struct scroll_bar *bar; |
9ef2e2cf | 3612 | int top, height, left, sb_left, width, sb_width; |
62e50ec6 | 3613 | int window_y, window_height; |
06929222 | 3614 | int fringe_extended_p; |
791f420f JR |
3615 | |
3616 | /* Get window dimensions. */ | |
62e50ec6 | 3617 | window_box (w, -1, 0, &window_y, 0, &window_height); |
791f420f | 3618 | top = window_y; |
62e50ec6 | 3619 | width = WINDOW_CONFIG_SCROLL_BAR_COLS (w) * FRAME_COLUMN_WIDTH (f); |
791f420f JR |
3620 | height = window_height; |
3621 | ||
3622 | /* Compute the left edge of the scroll bar area. */ | |
62e50ec6 | 3623 | left = WINDOW_SCROLL_BAR_AREA_X (w); |
791f420f JR |
3624 | |
3625 | /* Compute the width of the scroll bar which might be less than | |
3626 | the width of the area reserved for the scroll bar. */ | |
62e50ec6 KS |
3627 | if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) > 0) |
3628 | sb_width = WINDOW_CONFIG_SCROLL_BAR_WIDTH (w); | |
791f420f JR |
3629 | else |
3630 | sb_width = width; | |
ee78dc32 | 3631 | |
791f420f | 3632 | /* Compute the left edge of the scroll bar. */ |
62e50ec6 | 3633 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)) |
06929222 | 3634 | sb_left = left + (WINDOW_RIGHTMOST_P (w) ? width - sb_width : 0); |
ee78dc32 | 3635 | else |
06929222 YM |
3636 | sb_left = left + (WINDOW_LEFTMOST_P (w) ? 0 : width - sb_width); |
3637 | ||
3638 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) | |
3639 | fringe_extended_p = (WINDOW_LEFTMOST_P (w) | |
3640 | && WINDOW_LEFT_FRINGE_WIDTH (w) | |
3641 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | |
3642 | || WINDOW_LEFT_MARGIN_COLS (w) == 0)); | |
ee78dc32 | 3643 | else |
06929222 YM |
3644 | fringe_extended_p = (WINDOW_RIGHTMOST_P (w) |
3645 | && WINDOW_RIGHT_FRINGE_WIDTH (w) | |
3646 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | |
3647 | || WINDOW_RIGHT_MARGIN_COLS (w) == 0)); | |
791f420f JR |
3648 | |
3649 | /* Does the scroll bar exist yet? */ | |
3650 | if (NILP (w->vertical_scroll_bar)) | |
ee78dc32 | 3651 | { |
00fe468b | 3652 | HDC hdc; |
791f420f | 3653 | BLOCK_INPUT; |
6ff3e5e3 | 3654 | if (width > 0 && height > 0) |
9f5a911b JR |
3655 | { |
3656 | hdc = get_frame_dc (f); | |
06929222 YM |
3657 | if (fringe_extended_p) |
3658 | w32_clear_area (f, hdc, sb_left, top, sb_width, height); | |
3659 | else | |
3660 | w32_clear_area (f, hdc, left, top, width, height); | |
9f5a911b JR |
3661 | release_frame_dc (f, hdc); |
3662 | } | |
791f420f | 3663 | UNBLOCK_INPUT; |
00fe468b | 3664 | |
791f420f | 3665 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); |
ee78dc32 | 3666 | } |
791f420f JR |
3667 | else |
3668 | { | |
d67d1627 | 3669 | /* It may just need to be moved and resized. */ |
791f420f JR |
3670 | HWND hwnd; |
3671 | ||
3672 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | |
3673 | hwnd = SCROLL_BAR_W32_WINDOW (bar); | |
3674 | ||
3675 | /* If already correctly positioned, do nothing. */ | |
3676 | if ( XINT (bar->left) == sb_left | |
3677 | && XINT (bar->top) == top | |
3678 | && XINT (bar->width) == sb_width | |
06929222 YM |
3679 | && XINT (bar->height) == height |
3680 | && !NILP (bar->fringe_extended_p) == fringe_extended_p ) | |
791f420f JR |
3681 | { |
3682 | /* Redraw after clear_frame. */ | |
3683 | if (!my_show_window (f, hwnd, SW_NORMAL)) | |
3684 | InvalidateRect (hwnd, NULL, FALSE); | |
3685 | } | |
3686 | else | |
3687 | { | |
00fe468b | 3688 | HDC hdc; |
818a1a5d JR |
3689 | SCROLLINFO si; |
3690 | ||
791f420f | 3691 | BLOCK_INPUT; |
9f5a911b JR |
3692 | if (width && height) |
3693 | { | |
3694 | hdc = get_frame_dc (f); | |
3695 | /* Since Windows scroll bars are smaller than the space reserved | |
3696 | for them on the frame, we have to clear "under" them. */ | |
06929222 YM |
3697 | if (fringe_extended_p) |
3698 | w32_clear_area (f, hdc, sb_left, top, sb_width, height); | |
3699 | else | |
3700 | w32_clear_area (f, hdc, left, top, width, height); | |
9f5a911b JR |
3701 | release_frame_dc (f, hdc); |
3702 | } | |
791f420f JR |
3703 | /* Make sure scroll bar is "visible" before moving, to ensure the |
3704 | area of the parent window now exposed will be refreshed. */ | |
3705 | my_show_window (f, hwnd, SW_HIDE); | |
9f5a911b JR |
3706 | MoveWindow (hwnd, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, |
3707 | top, sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
3708 | max (height, 1), TRUE); | |
ee78dc32 | 3709 | |
818a1a5d JR |
3710 | si.cbSize = sizeof (si); |
3711 | si.fMask = SIF_RANGE; | |
3712 | si.nMin = 0; | |
3713 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) | |
3714 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
3715 | ||
3716 | SetScrollInfo (hwnd, SB_CTL, &si, FALSE); | |
ee78dc32 | 3717 | |
791f420f | 3718 | my_show_window (f, hwnd, SW_NORMAL); |
ab76d376 | 3719 | /* InvalidateRect (w, NULL, FALSE); */ |
791f420f JR |
3720 | |
3721 | /* Remember new settings. */ | |
3722 | XSETINT (bar->left, sb_left); | |
3723 | XSETINT (bar->top, top); | |
3724 | XSETINT (bar->width, sb_width); | |
3725 | XSETINT (bar->height, height); | |
3726 | ||
3727 | UNBLOCK_INPUT; | |
3728 | } | |
3729 | } | |
06929222 YM |
3730 | bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil; |
3731 | ||
791f420f | 3732 | w32_set_scroll_bar_thumb (bar, portion, position, whole); |
ee78dc32 | 3733 | |
791f420f | 3734 | XSETVECTOR (w->vertical_scroll_bar, bar); |
ee78dc32 GV |
3735 | } |
3736 | ||
3737 | ||
3738 | /* The following three hooks are used when we're doing a thorough | |
3739 | redisplay of the frame. We don't explicitly know which scroll bars | |
3740 | are going to be deleted, because keeping track of when windows go | |
3741 | away is a real pain - "Can you say set-window-configuration, boys | |
3742 | and girls?" Instead, we just assert at the beginning of redisplay | |
3743 | that *all* scroll bars are to be removed, and then save a scroll bar | |
3744 | from the fiery pit when we actually redisplay its window. */ | |
3745 | ||
3746 | /* Arrange for all scroll bars on FRAME to be removed at the next call | |
3747 | to `*judge_scroll_bars_hook'. A scroll bar may be spared if | |
9ef2e2cf JR |
3748 | `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ |
3749 | ||
ee78dc32 | 3750 | static void |
fbd6baed | 3751 | w32_condemn_scroll_bars (frame) |
ee78dc32 GV |
3752 | FRAME_PTR frame; |
3753 | { | |
ef0e360f GV |
3754 | /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ |
3755 | while (! NILP (FRAME_SCROLL_BARS (frame))) | |
3756 | { | |
3757 | Lisp_Object bar; | |
3758 | bar = FRAME_SCROLL_BARS (frame); | |
3759 | FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next; | |
3760 | XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame); | |
3761 | XSCROLL_BAR (bar)->prev = Qnil; | |
3762 | if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame))) | |
3763 | XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar; | |
3764 | FRAME_CONDEMNED_SCROLL_BARS (frame) = bar; | |
3765 | } | |
ee78dc32 GV |
3766 | } |
3767 | ||
c2cc16fa | 3768 | |
9ef2e2cf | 3769 | /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle. |
ee78dc32 | 3770 | Note that WINDOW isn't necessarily condemned at all. */ |
c2cc16fa | 3771 | |
ee78dc32 | 3772 | static void |
fbd6baed | 3773 | w32_redeem_scroll_bar (window) |
ee78dc32 GV |
3774 | struct window *window; |
3775 | { | |
3776 | struct scroll_bar *bar; | |
c2cc16fa | 3777 | struct frame *f; |
ee78dc32 GV |
3778 | |
3779 | /* We can't redeem this window's scroll bar if it doesn't have one. */ | |
3780 | if (NILP (window->vertical_scroll_bar)) | |
3781 | abort (); | |
3782 | ||
3783 | bar = XSCROLL_BAR (window->vertical_scroll_bar); | |
3784 | ||
ef0e360f | 3785 | /* Unlink it from the condemned list. */ |
c2cc16fa JR |
3786 | f = XFRAME (WINDOW_FRAME (window)); |
3787 | if (NILP (bar->prev)) | |
3788 | { | |
3789 | /* If the prev pointer is nil, it must be the first in one of | |
3790 | the lists. */ | |
3791 | if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar)) | |
3792 | /* It's not condemned. Everything's fine. */ | |
3793 | return; | |
3794 | else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f), | |
3795 | window->vertical_scroll_bar)) | |
3796 | FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next; | |
3797 | else | |
3798 | /* If its prev pointer is nil, it must be at the front of | |
3799 | one or the other! */ | |
3800 | abort (); | |
3801 | } | |
3802 | else | |
3803 | XSCROLL_BAR (bar->prev)->next = bar->next; | |
ef0e360f | 3804 | |
c2cc16fa JR |
3805 | if (! NILP (bar->next)) |
3806 | XSCROLL_BAR (bar->next)->prev = bar->prev; | |
ef0e360f | 3807 | |
c2cc16fa JR |
3808 | bar->next = FRAME_SCROLL_BARS (f); |
3809 | bar->prev = Qnil; | |
3810 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
3811 | if (! NILP (bar->next)) | |
3812 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
ee78dc32 GV |
3813 | } |
3814 | ||
3815 | /* Remove all scroll bars on FRAME that haven't been saved since the | |
3816 | last call to `*condemn_scroll_bars_hook'. */ | |
9ef2e2cf | 3817 | |
ee78dc32 | 3818 | static void |
fbd6baed | 3819 | w32_judge_scroll_bars (f) |
ee78dc32 GV |
3820 | FRAME_PTR f; |
3821 | { | |
3822 | Lisp_Object bar, next; | |
3823 | ||
3824 | bar = FRAME_CONDEMNED_SCROLL_BARS (f); | |
3825 | ||
3826 | /* Clear out the condemned list now so we won't try to process any | |
3827 | more events on the hapless scroll bars. */ | |
3828 | FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil; | |
3829 | ||
3830 | for (; ! NILP (bar); bar = next) | |
3831 | { | |
3832 | struct scroll_bar *b = XSCROLL_BAR (bar); | |
3833 | ||
3834 | x_scroll_bar_remove (b); | |
3835 | ||
3836 | next = b->next; | |
3837 | b->next = b->prev = Qnil; | |
3838 | } | |
3839 | ||
3840 | /* Now there should be no references to the condemned scroll bars, | |
3841 | and they should get garbage-collected. */ | |
3842 | } | |
3843 | ||
3844 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind | |
3b8f9651 | 3845 | is set to something other than NO_EVENT, it is enqueued. |
ee78dc32 GV |
3846 | |
3847 | This may be called from a signal handler, so we have to ignore GC | |
3848 | mark bits. */ | |
2c28562d | 3849 | |
52cf03a1 | 3850 | static int |
c2cc16fa | 3851 | w32_scroll_bar_handle_click (bar, msg, emacs_event) |
ee78dc32 | 3852 | struct scroll_bar *bar; |
fbd6baed | 3853 | W32Msg *msg; |
ee78dc32 GV |
3854 | struct input_event *emacs_event; |
3855 | { | |
8e50cc2d | 3856 | if (! WINDOWP (bar->window)) |
ee78dc32 GV |
3857 | abort (); |
3858 | ||
4b219faa | 3859 | emacs_event->kind = SCROLL_BAR_CLICK_EVENT; |
ee78dc32 | 3860 | emacs_event->code = 0; |
52cf03a1 GV |
3861 | /* not really meaningful to distinguish up/down */ |
3862 | emacs_event->modifiers = msg->dwModifiers; | |
ee78dc32 | 3863 | emacs_event->frame_or_window = bar->window; |
7e889510 | 3864 | emacs_event->arg = Qnil; |
ee78dc32 GV |
3865 | emacs_event->timestamp = msg->msg.time; |
3866 | ||
3867 | { | |
791f420f | 3868 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
689004fa GV |
3869 | int y; |
3870 | int dragging = !NILP (bar->dragging); | |
818a1a5d | 3871 | SCROLLINFO si; |
689004fa | 3872 | |
818a1a5d JR |
3873 | si.cbSize = sizeof (si); |
3874 | si.fMask = SIF_POS; | |
689004fa | 3875 | |
818a1a5d JR |
3876 | GetScrollInfo ((HWND) msg->msg.lParam, SB_CTL, &si); |
3877 | y = si.nPos; | |
689004fa GV |
3878 | |
3879 | bar->dragging = Qnil; | |
ee78dc32 | 3880 | |
9ef2e2cf JR |
3881 | |
3882 | last_mouse_scroll_bar_pos = msg->msg.wParam; | |
d67d1627 | 3883 | |
ee78dc32 | 3884 | switch (LOWORD (msg->msg.wParam)) |
2c28562d | 3885 | { |
2c28562d | 3886 | case SB_LINEDOWN: |
52cf03a1 | 3887 | emacs_event->part = scroll_bar_down_arrow; |
ee78dc32 | 3888 | break; |
2c28562d | 3889 | case SB_LINEUP: |
52cf03a1 | 3890 | emacs_event->part = scroll_bar_up_arrow; |
ee78dc32 | 3891 | break; |
2c28562d | 3892 | case SB_PAGEUP: |
ee78dc32 GV |
3893 | emacs_event->part = scroll_bar_above_handle; |
3894 | break; | |
2c28562d | 3895 | case SB_PAGEDOWN: |
ee78dc32 GV |
3896 | emacs_event->part = scroll_bar_below_handle; |
3897 | break; | |
2c28562d | 3898 | case SB_TOP: |
ee78dc32 GV |
3899 | emacs_event->part = scroll_bar_handle; |
3900 | y = 0; | |
3901 | break; | |
2c28562d | 3902 | case SB_BOTTOM: |
ee78dc32 GV |
3903 | emacs_event->part = scroll_bar_handle; |
3904 | y = top_range; | |
3905 | break; | |
689004fa | 3906 | case SB_THUMBTRACK: |
2c28562d | 3907 | case SB_THUMBPOSITION: |
791f420f JR |
3908 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
3909 | y = HIWORD (msg->msg.wParam); | |
689004fa | 3910 | bar->dragging = Qt; |
ee78dc32 | 3911 | emacs_event->part = scroll_bar_handle; |
689004fa GV |
3912 | |
3913 | /* "Silently" update current position. */ | |
818a1a5d JR |
3914 | { |
3915 | SCROLLINFO si; | |
689004fa | 3916 | |
818a1a5d JR |
3917 | si.cbSize = sizeof (si); |
3918 | si.fMask = SIF_POS; | |
3919 | si.nPos = y; | |
3920 | /* Remember apparent position (we actually lag behind the real | |
3921 | position, so don't set that directly. */ | |
3922 | last_scroll_bar_drag_pos = y; | |
689004fa | 3923 | |
818a1a5d JR |
3924 | SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, FALSE); |
3925 | } | |
ee78dc32 | 3926 | break; |
2c28562d | 3927 | case SB_ENDSCROLL: |
689004fa GV |
3928 | /* If this is the end of a drag sequence, then reset the scroll |
3929 | handle size to normal and do a final redraw. Otherwise do | |
3930 | nothing. */ | |
3931 | if (dragging) | |
3932 | { | |
818a1a5d JR |
3933 | SCROLLINFO si; |
3934 | int start = XINT (bar->start); | |
3935 | int end = XINT (bar->end); | |
3936 | ||
3937 | si.cbSize = sizeof (si); | |
3938 | si.fMask = SIF_PAGE | SIF_POS; | |
3939 | si.nPage = end - start + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
3940 | si.nPos = last_scroll_bar_drag_pos; | |
3941 | SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, TRUE); | |
689004fa GV |
3942 | } |
3943 | /* fall through */ | |
2c28562d | 3944 | default: |
3b8f9651 | 3945 | emacs_event->kind = NO_EVENT; |
52cf03a1 | 3946 | return FALSE; |
2c28562d | 3947 | } |
52cf03a1 | 3948 | |
ee78dc32 GV |
3949 | XSETINT (emacs_event->x, y); |
3950 | XSETINT (emacs_event->y, top_range); | |
52cf03a1 GV |
3951 | |
3952 | return TRUE; | |
ee78dc32 GV |
3953 | } |
3954 | } | |
3955 | ||
3956 | /* Return information to the user about the current position of the mouse | |
3957 | on the scroll bar. */ | |
9ef2e2cf | 3958 | |
ee78dc32 GV |
3959 | static void |
3960 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) | |
3961 | FRAME_PTR *fp; | |
3962 | Lisp_Object *bar_window; | |
3963 | enum scroll_bar_part *part; | |
3964 | Lisp_Object *x, *y; | |
3965 | unsigned long *time; | |
3966 | { | |
3967 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); | |
fbd6baed | 3968 | Window w = SCROLL_BAR_W32_WINDOW (bar); |
ee78dc32 GV |
3969 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
3970 | int pos; | |
791f420f | 3971 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
818a1a5d | 3972 | SCROLLINFO si; |
ee78dc32 GV |
3973 | |
3974 | BLOCK_INPUT; | |
3975 | ||
3976 | *fp = f; | |
3977 | *bar_window = bar->window; | |
3978 | ||
818a1a5d JR |
3979 | si.cbSize = sizeof (si); |
3980 | si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; | |
689004fa | 3981 | |
818a1a5d JR |
3982 | GetScrollInfo (w, SB_CTL, &si); |
3983 | pos = si.nPos; | |
3984 | top_range = si.nMax - si.nPage + 1; | |
ee78dc32 GV |
3985 | |
3986 | switch (LOWORD (last_mouse_scroll_bar_pos)) | |
3987 | { | |
3988 | case SB_THUMBPOSITION: | |
3989 | case SB_THUMBTRACK: | |
3990 | *part = scroll_bar_handle; | |
791f420f | 3991 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
ee78dc32 GV |
3992 | pos = HIWORD (last_mouse_scroll_bar_pos); |
3993 | break; | |
3994 | case SB_LINEDOWN: | |
3995 | *part = scroll_bar_handle; | |
3996 | pos++; | |
3997 | break; | |
3998 | default: | |
3999 | *part = scroll_bar_handle; | |
4000 | break; | |
4001 | } | |
4002 | ||
9127e20e JR |
4003 | XSETINT (*x, pos); |
4004 | XSETINT (*y, top_range); | |
ee78dc32 GV |
4005 | |
4006 | f->mouse_moved = 0; | |
4007 | last_mouse_scroll_bar = Qnil; | |
4008 | ||
4009 | *time = last_mouse_movement_time; | |
4010 | ||
4011 | UNBLOCK_INPUT; | |
4012 | } | |
4013 | ||
9ef2e2cf | 4014 | |
ee78dc32 GV |
4015 | /* The screen has been cleared so we may have changed foreground or |
4016 | background colors, and the scroll bars may need to be redrawn. | |
4017 | Clear out the scroll bars, and ask for expose events, so we can | |
4018 | redraw them. */ | |
9ef2e2cf | 4019 | |
791f420f | 4020 | void |
ee78dc32 | 4021 | x_scroll_bar_clear (f) |
9ef2e2cf | 4022 | FRAME_PTR f; |
ee78dc32 | 4023 | { |
ee78dc32 GV |
4024 | Lisp_Object bar; |
4025 | ||
9ef2e2cf JR |
4026 | /* We can have scroll bars even if this is 0, |
4027 | if we just turned off scroll bar mode. | |
4028 | But in that case we should not clear them. */ | |
4029 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
4030 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
4031 | bar = XSCROLL_BAR (bar)->next) | |
4032 | { | |
4033 | HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)); | |
4034 | HDC hdc = GetDC (window); | |
4035 | RECT rect; | |
52cf03a1 | 4036 | |
9ef2e2cf JR |
4037 | /* Hide scroll bar until ready to repaint. x_scroll_bar_move |
4038 | arranges to refresh the scroll bar if hidden. */ | |
4039 | my_show_window (f, window, SW_HIDE); | |
689004fa | 4040 | |
9ef2e2cf JR |
4041 | GetClientRect (window, &rect); |
4042 | select_palette (f, hdc); | |
4043 | w32_clear_rect (f, hdc, &rect); | |
4044 | deselect_palette (f, hdc); | |
689004fa | 4045 | |
9ef2e2cf JR |
4046 | ReleaseDC (window, hdc); |
4047 | } | |
52cf03a1 GV |
4048 | } |
4049 | ||
ee78dc32 | 4050 | \f |
fbd6baed | 4051 | /* The main W32 event-reading loop - w32_read_socket. */ |
ee78dc32 GV |
4052 | |
4053 | /* Record the last 100 characters stored | |
4054 | to help debug the loss-of-chars-during-GC problem. */ | |
9ef2e2cf JR |
4055 | |
4056 | static int temp_index; | |
4057 | static short temp_buffer[100]; | |
ee78dc32 | 4058 | |
2e3566d8 JR |
4059 | /* Temporarily store lead byte of DBCS input sequences. */ |
4060 | static char dbcs_lead = 0; | |
afd153f0 | 4061 | |
fbd6baed | 4062 | /* Read events coming from the W32 shell. |
ee78dc32 GV |
4063 | This routine is called by the SIGIO handler. |
4064 | We return as soon as there are no more events to be read. | |
4065 | ||
ee78dc32 GV |
4066 | We return the number of characters stored into the buffer, |
4067 | thus pretending to be `read'. | |
4068 | ||
d67d1627 | 4069 | EXPECTED is nonzero if the caller knows input is available. |
ee78dc32 GV |
4070 | |
4071 | Some of these messages are reposted back to the message queue since the | |
d67d1627 | 4072 | system calls the windows proc directly in a context where we cannot return |
decb374a | 4073 | the data nor can we guarantee the state we are in. So if we dispatch them |
ee78dc32 GV |
4074 | we will get into an infinite loop. To prevent this from ever happening we |
4075 | will set a variable to indicate we are in the read_socket call and indicate | |
d67d1627 | 4076 | which message we are processing since the windows proc gets called |
e9e23e23 | 4077 | recursively with different messages by the system. |
ee78dc32 GV |
4078 | */ |
4079 | ||
4080 | int | |
6b61353c | 4081 | w32_read_socket (sd, expected, hold_quit) |
ee78dc32 | 4082 | register int sd; |
ee78dc32 | 4083 | int expected; |
6b61353c | 4084 | struct input_event *hold_quit; |
ee78dc32 GV |
4085 | { |
4086 | int count = 0; | |
689004fa | 4087 | int check_visibility = 0; |
fbd6baed | 4088 | W32Msg msg; |
ee78dc32 | 4089 | struct frame *f; |
fbd6baed | 4090 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
ee78dc32 GV |
4091 | |
4092 | if (interrupt_input_blocked) | |
4093 | { | |
4094 | interrupt_input_pending = 1; | |
4095 | return -1; | |
4096 | } | |
4097 | ||
4098 | interrupt_input_pending = 0; | |
4099 | BLOCK_INPUT; | |
4100 | ||
4101 | /* So people can tell when we have read the available input. */ | |
4102 | input_signal_count++; | |
4103 | ||
07c07cfe | 4104 | /* TODO: ghostscript integration. */ |
52cf03a1 | 4105 | while (get_next_msg (&msg, FALSE)) |
ee78dc32 | 4106 | { |
6b61353c KH |
4107 | struct input_event inev; |
4108 | int do_help = 0; | |
4109 | ||
4110 | EVENT_INIT (inev); | |
4111 | inev.kind = NO_EVENT; | |
4112 | inev.arg = Qnil; | |
4113 | ||
ee78dc32 GV |
4114 | switch (msg.msg.message) |
4115 | { | |
f7b146dc | 4116 | case WM_EMACS_PAINT: |
9f5a911b | 4117 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); |
ee78dc32 | 4118 | |
d67d1627 | 4119 | if (f) |
9f5a911b JR |
4120 | { |
4121 | if (msg.rect.right == msg.rect.left || | |
4122 | msg.rect.bottom == msg.rect.top) | |
4123 | { | |
4124 | /* We may get paint messages even though the client | |
4125 | area is clipped - these are not expose events. */ | |
4126 | DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f, | |
d5db4077 | 4127 | SDATA (f->name))); |
9f5a911b JR |
4128 | } |
4129 | else if (f->async_visible != 1) | |
4130 | { | |
4131 | /* Definitely not obscured, so mark as visible. */ | |
4132 | f->async_visible = 1; | |
4133 | f->async_iconified = 0; | |
4134 | SET_FRAME_GARBAGED (f); | |
4135 | DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f, | |
d5db4077 | 4136 | SDATA (f->name))); |
9f5a911b JR |
4137 | |
4138 | /* WM_PAINT serves as MapNotify as well, so report | |
4139 | visibility changes properly. */ | |
4140 | if (f->iconified) | |
4141 | { | |
6b61353c KH |
4142 | inev.kind = DEICONIFY_EVENT; |
4143 | XSETFRAME (inev.frame_or_window, f); | |
9f5a911b JR |
4144 | } |
4145 | else if (! NILP (Vframe_list) | |
4146 | && ! NILP (XCDR (Vframe_list))) | |
4147 | /* Force a redisplay sooner or later to update the | |
4148 | frame titles in case this is the second frame. */ | |
4149 | record_asynch_buffer_change (); | |
4150 | } | |
4151 | else | |
4152 | { | |
4153 | HDC hdc = get_frame_dc (f); | |
4154 | ||
4155 | /* Erase background again for safety. */ | |
4156 | w32_clear_rect (f, hdc, &msg.rect); | |
4157 | release_frame_dc (f, hdc); | |
4158 | expose_frame (f, | |
4159 | msg.rect.left, | |
4160 | msg.rect.top, | |
4161 | msg.rect.right - msg.rect.left, | |
4162 | msg.rect.bottom - msg.rect.top); | |
4163 | } | |
4164 | } | |
52cf03a1 | 4165 | break; |
689004fa | 4166 | |
f98169a0 GV |
4167 | case WM_INPUTLANGCHANGE: |
4168 | /* Generate a language change event. */ | |
4169 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
4170 | ||
13087e59 JR |
4171 | /* lParam contains the input lang ID. Use it to update our |
4172 | record of the keyboard codepage. */ | |
4173 | keyboard_codepage = codepage_for_locale ((LCID)(msg.msg.lParam | |
4174 | & 0xffff)); | |
4175 | ||
f98169a0 GV |
4176 | if (f) |
4177 | { | |
6b61353c KH |
4178 | inev.kind = LANGUAGE_CHANGE_EVENT; |
4179 | XSETFRAME (inev.frame_or_window, f); | |
4180 | inev.code = msg.msg.wParam; | |
4181 | inev.modifiers = msg.msg.lParam & 0xffff; | |
f98169a0 GV |
4182 | } |
4183 | break; | |
4184 | ||
ee78dc32 GV |
4185 | case WM_KEYDOWN: |
4186 | case WM_SYSKEYDOWN: | |
4187 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4188 | |
ee78dc32 GV |
4189 | if (f && !f->iconified) |
4190 | { | |
442a3a96 KS |
4191 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) |
4192 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | |
3d26a7c2 | 4193 | { |
3d26a7c2 | 4194 | clear_mouse_face (dpyinfo); |
6b61353c | 4195 | dpyinfo->mouse_face_hidden = 1; |
3d26a7c2 KS |
4196 | } |
4197 | ||
ee78dc32 GV |
4198 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
4199 | temp_index = 0; | |
4200 | temp_buffer[temp_index++] = msg.msg.wParam; | |
6b61353c KH |
4201 | inev.kind = NON_ASCII_KEYSTROKE_EVENT; |
4202 | inev.code = msg.msg.wParam; | |
4203 | inev.modifiers = msg.dwModifiers; | |
4204 | XSETFRAME (inev.frame_or_window, f); | |
4205 | inev.timestamp = msg.msg.time; | |
ee78dc32 GV |
4206 | } |
4207 | break; | |
689004fa | 4208 | |
a60b0333 | 4209 | case WM_UNICHAR: |
ee78dc32 GV |
4210 | case WM_SYSCHAR: |
4211 | case WM_CHAR: | |
4212 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4213 | |
ee78dc32 GV |
4214 | if (f && !f->iconified) |
4215 | { | |
442a3a96 KS |
4216 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) |
4217 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | |
3d26a7c2 | 4218 | { |
3d26a7c2 | 4219 | clear_mouse_face (dpyinfo); |
6b61353c | 4220 | dpyinfo->mouse_face_hidden = 1; |
3d26a7c2 KS |
4221 | } |
4222 | ||
f98169a0 GV |
4223 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
4224 | temp_index = 0; | |
4225 | temp_buffer[temp_index++] = msg.msg.wParam; | |
480cb5d2 JR |
4226 | |
4227 | inev.modifiers = msg.dwModifiers; | |
4228 | XSETFRAME (inev.frame_or_window, f); | |
4229 | inev.timestamp = msg.msg.time; | |
4230 | ||
a60b0333 JR |
4231 | if (msg.msg.message == WM_UNICHAR) |
4232 | { | |
a60b0333 JR |
4233 | inev.code = msg.msg.wParam; |
4234 | } | |
480cb5d2 JR |
4235 | else if (msg.msg.wParam < 256) |
4236 | { | |
4237 | wchar_t code; | |
4238 | char dbcs[2]; | |
4239 | dbcs[0] = 0; | |
4240 | dbcs[1] = (char) msg.msg.wParam; | |
4241 | ||
4242 | if (dbcs_lead) | |
4243 | { | |
4244 | dbcs[0] = dbcs_lead; | |
4245 | dbcs_lead = 0; | |
13087e59 JR |
4246 | if (!MultiByteToWideChar (keyboard_codepage, 0, |
4247 | dbcs, 2, &code, 1)) | |
480cb5d2 JR |
4248 | { |
4249 | /* Garbage */ | |
4250 | DebPrint (("Invalid DBCS sequence: %d %d\n", | |
4251 | dbcs[0], dbcs[1])); | |
4252 | inev.kind = NO_EVENT; | |
4253 | break; | |
4254 | } | |
4255 | } | |
13087e59 JR |
4256 | else if (IsDBCSLeadByteEx (keyboard_codepage, |
4257 | (BYTE) msg.msg.wParam)) | |
480cb5d2 JR |
4258 | { |
4259 | dbcs_lead = (char) msg.msg.wParam; | |
4260 | inev.kind = NO_EVENT; | |
4261 | break; | |
4262 | } | |
4263 | else | |
4264 | { | |
13087e59 JR |
4265 | if (!MultiByteToWideChar (keyboard_codepage, 0, |
4266 | &dbcs[1], 1, &code, 1)) | |
480cb5d2 JR |
4267 | { |
4268 | /* What to do with garbage? */ | |
4269 | DebPrint (("Invalid character: %d\n", dbcs[1])); | |
4270 | inev.kind = NO_EVENT; | |
4271 | break; | |
4272 | } | |
4273 | } | |
4274 | inev.code = code; | |
4275 | } | |
a60b0333 JR |
4276 | else |
4277 | { | |
480cb5d2 JR |
4278 | /* Windows shouldn't generate WM_CHAR events above 0xFF |
4279 | in non-Unicode message handlers. */ | |
4280 | DebPrint (("Non-byte WM_CHAR: %d\n", msg.msg.wParam)); | |
4281 | inev.kind = NO_EVENT; | |
4282 | break; | |
a60b0333 | 4283 | } |
480cb5d2 JR |
4284 | inev.kind = inev.code < 128 ? ASCII_KEYSTROKE_EVENT |
4285 | : MULTIBYTE_CHAR_KEYSTROKE_EVENT; | |
ee78dc32 GV |
4286 | } |
4287 | break; | |
689004fa | 4288 | |
4b219faa JR |
4289 | case WM_APPCOMMAND: |
4290 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
4291 | ||
4292 | if (f && !f->iconified) | |
4293 | { | |
4294 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) | |
4295 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | |
4296 | { | |
4297 | clear_mouse_face (dpyinfo); | |
4298 | dpyinfo->mouse_face_hidden = 1; | |
4299 | } | |
4300 | ||
4301 | if (temp_index == sizeof temp_buffer / sizeof (short)) | |
4302 | temp_index = 0; | |
4303 | temp_buffer[temp_index++] = msg.msg.wParam; | |
4304 | inev.kind = MULTIMEDIA_KEY_EVENT; | |
4305 | inev.code = GET_APPCOMMAND_LPARAM(msg.msg.lParam); | |
4306 | inev.modifiers = msg.dwModifiers; | |
4307 | XSETFRAME (inev.frame_or_window, f); | |
4308 | inev.timestamp = msg.msg.time; | |
4309 | } | |
4310 | break; | |
65a6ff8f | 4311 | |
ee78dc32 | 4312 | case WM_MOUSEMOVE: |
706ddb8f JR |
4313 | /* Ignore non-movement. */ |
4314 | { | |
4315 | int x = LOWORD (msg.msg.lParam); | |
4316 | int y = HIWORD (msg.msg.lParam); | |
4317 | if (x == last_mousemove_x && y == last_mousemove_y) | |
4318 | break; | |
4319 | last_mousemove_x = x; | |
4320 | last_mousemove_y = y; | |
4321 | } | |
4322 | ||
89271099 | 4323 | previous_help_echo_string = help_echo_string; |
fc5c7550 | 4324 | help_echo_string = Qnil; |
791f420f | 4325 | |
ee78dc32 GV |
4326 | if (dpyinfo->grabbed && last_mouse_frame |
4327 | && FRAME_LIVE_P (last_mouse_frame)) | |
4328 | f = last_mouse_frame; | |
4329 | else | |
4330 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4331 | |
3d26a7c2 KS |
4332 | if (dpyinfo->mouse_face_hidden) |
4333 | { | |
4334 | dpyinfo->mouse_face_hidden = 0; | |
4335 | clear_mouse_face (dpyinfo); | |
4336 | } | |
4337 | ||
ee78dc32 | 4338 | if (f) |
a18bb28d JR |
4339 | { |
4340 | /* Generate SELECT_WINDOW_EVENTs when needed. */ | |
92b23323 | 4341 | if (!NILP (Vmouse_autoselect_window)) |
a18bb28d JR |
4342 | { |
4343 | Lisp_Object window; | |
a18bb28d JR |
4344 | int x = LOWORD (msg.msg.lParam); |
4345 | int y = HIWORD (msg.msg.lParam); | |
4346 | ||
62e50ec6 | 4347 | window = window_from_coordinates (f, x, y, 0, 0, 0, 0); |
a18bb28d JR |
4348 | |
4349 | /* Window will be selected only when it is not | |
4350 | selected now and last mouse movement event was | |
4351 | not in it. Minibuffer window will be selected | |
e0f24100 | 4352 | only when it is active. */ |
a18bb28d JR |
4353 | if (WINDOWP(window) |
4354 | && !EQ (window, last_window) | |
74a9b36f MR |
4355 | && !EQ (window, selected_window) |
4356 | /* For click-to-focus window managers | |
4357 | create event iff we don't leave the | |
4358 | selected frame. */ | |
4359 | && (focus_follows_mouse | |
4360 | || (EQ (XWINDOW (window)->frame, | |
4361 | XWINDOW (selected_window)->frame)))) | |
a18bb28d | 4362 | { |
6b61353c KH |
4363 | inev.kind = SELECT_WINDOW_EVENT; |
4364 | inev.frame_or_window = window; | |
a18bb28d JR |
4365 | } |
4366 | ||
4367 | last_window=window; | |
4368 | } | |
fc5c7550 YM |
4369 | if (!note_mouse_movement (f, &msg.msg)) |
4370 | help_echo_string = previous_help_echo_string; | |
a18bb28d | 4371 | } |
ee78dc32 | 4372 | else |
791f420f JR |
4373 | { |
4374 | /* If we move outside the frame, then we're | |
4375 | certainly no longer on any text in the frame. */ | |
5b844253 | 4376 | clear_mouse_face (dpyinfo); |
791f420f JR |
4377 | } |
4378 | ||
89271099 | 4379 | /* If the contents of the global variable help_echo_string |
791f420f | 4380 | has changed, generate a HELP_EVENT. */ |
e597eb7d JR |
4381 | #if 0 /* The below is an invalid comparison when USE_LISP_UNION_TYPE. |
4382 | But it was originally changed to this to fix a bug, so I have | |
4383 | not removed it completely in case the bug is still there. */ | |
89271099 KS |
4384 | if (help_echo_string != previous_help_echo_string || |
4385 | (!NILP (help_echo_string) && !STRINGP (help_echo_string) && f->mouse_moved)) | |
e597eb7d JR |
4386 | #else /* This is what xterm.c does. */ |
4387 | if (!NILP (help_echo_string) | |
4388 | || !NILP (previous_help_echo_string)) | |
6b61353c | 4389 | do_help = 1; |
e597eb7d | 4390 | #endif |
791f420f | 4391 | break; |
689004fa | 4392 | |
ee78dc32 GV |
4393 | case WM_LBUTTONDOWN: |
4394 | case WM_LBUTTONUP: | |
4395 | case WM_MBUTTONDOWN: | |
4396 | case WM_MBUTTONUP: | |
4397 | case WM_RBUTTONDOWN: | |
4398 | case WM_RBUTTONUP: | |
53823ab9 JR |
4399 | case WM_XBUTTONDOWN: |
4400 | case WM_XBUTTONUP: | |
ee78dc32 | 4401 | { |
791f420f JR |
4402 | /* If we decide we want to generate an event to be seen |
4403 | by the rest of Emacs, we put it here. */ | |
791f420f | 4404 | int tool_bar_p = 0; |
ee78dc32 GV |
4405 | int button; |
4406 | int up; | |
791f420f | 4407 | |
ee78dc32 GV |
4408 | if (dpyinfo->grabbed && last_mouse_frame |
4409 | && FRAME_LIVE_P (last_mouse_frame)) | |
4410 | f = last_mouse_frame; | |
4411 | else | |
4412 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4413 | |
ee78dc32 GV |
4414 | if (f) |
4415 | { | |
6b61353c | 4416 | construct_mouse_click (&inev, &msg, f); |
d67d1627 | 4417 | |
791f420f JR |
4418 | /* Is this in the tool-bar? */ |
4419 | if (WINDOWP (f->tool_bar_window) | |
62e50ec6 | 4420 | && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window))) |
791f420f JR |
4421 | { |
4422 | Lisp_Object window; | |
6b61353c KH |
4423 | int x = XFASTINT (inev.x); |
4424 | int y = XFASTINT (inev.y); | |
791f420f | 4425 | |
62e50ec6 | 4426 | window = window_from_coordinates (f, x, y, 0, 0, 0, 1); |
b8b47c19 | 4427 | |
791f420f JR |
4428 | if (EQ (window, f->tool_bar_window)) |
4429 | { | |
6b61353c | 4430 | w32_handle_tool_bar_click (f, &inev); |
791f420f JR |
4431 | tool_bar_p = 1; |
4432 | } | |
4433 | } | |
4434 | ||
6b61353c KH |
4435 | if (tool_bar_p |
4436 | || (dpyinfo->w32_focus_frame | |
4437 | && f != dpyinfo->w32_focus_frame)) | |
4438 | inev.kind = NO_EVENT; | |
ee78dc32 | 4439 | } |
d67d1627 | 4440 | |
53823ab9 JR |
4441 | parse_button (msg.msg.message, HIWORD (msg.msg.wParam), |
4442 | &button, &up); | |
4443 | ||
ee78dc32 GV |
4444 | if (up) |
4445 | { | |
4446 | dpyinfo->grabbed &= ~ (1 << button); | |
4447 | } | |
4448 | else | |
4449 | { | |
4450 | dpyinfo->grabbed |= (1 << button); | |
4451 | last_mouse_frame = f; | |
791f420f JR |
4452 | /* Ignore any mouse motion that happened |
4453 | before this event; any subsequent mouse-movement | |
4454 | Emacs events should reflect only motion after | |
4455 | the ButtonPress. */ | |
4456 | if (f != 0) | |
4457 | f->mouse_moved = 0; | |
4458 | ||
4459 | if (!tool_bar_p) | |
4460 | last_tool_bar_item = -1; | |
ee78dc32 | 4461 | } |
689004fa | 4462 | break; |
ee78dc32 | 4463 | } |
d67d1627 | 4464 | |
1c64a4a2 | 4465 | case WM_MOUSEWHEEL: |
1526bc23 | 4466 | case WM_MOUSEHWHEEL: |
1c64a4a2 | 4467 | { |
1c64a4a2 JB |
4468 | if (dpyinfo->grabbed && last_mouse_frame |
4469 | && FRAME_LIVE_P (last_mouse_frame)) | |
4470 | f = last_mouse_frame; | |
4471 | else | |
4472 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
4473 | ||
4474 | if (f) | |
4475 | { | |
1c64a4a2 | 4476 | |
6b61353c KH |
4477 | if (!dpyinfo->w32_focus_frame |
4478 | || f == dpyinfo->w32_focus_frame) | |
1c64a4a2 | 4479 | { |
637ad49d | 4480 | /* Emit an Emacs wheel-up/down event. */ |
6b61353c | 4481 | construct_mouse_wheel (&inev, &msg, f); |
1c64a4a2 | 4482 | } |
637ad49d JR |
4483 | /* Ignore any mouse motion that happened before this |
4484 | event; any subsequent mouse-movement Emacs events | |
4485 | should reflect only motion after the | |
db9cd97a | 4486 | ButtonPress. */ |
637ad49d | 4487 | f->mouse_moved = 0; |
1c64a4a2 | 4488 | } |
637ad49d JR |
4489 | last_mouse_frame = f; |
4490 | last_tool_bar_item = -1; | |
1c64a4a2 | 4491 | } |
ee78dc32 | 4492 | break; |
689004fa | 4493 | |
12857dfd RS |
4494 | case WM_DROPFILES: |
4495 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
4496 | ||
4497 | if (f) | |
6b61353c | 4498 | construct_drag_n_drop (&inev, &msg, f); |
12857dfd RS |
4499 | break; |
4500 | ||
ee78dc32 GV |
4501 | case WM_VSCROLL: |
4502 | { | |
689004fa GV |
4503 | struct scroll_bar *bar = |
4504 | x_window_to_scroll_bar ((HWND)msg.msg.lParam); | |
d67d1627 | 4505 | |
6b61353c KH |
4506 | if (bar) |
4507 | w32_scroll_bar_handle_click (bar, &msg, &inev); | |
689004fa | 4508 | break; |
ee78dc32 | 4509 | } |
d67d1627 | 4510 | |
689004fa | 4511 | case WM_WINDOWPOSCHANGED: |
549808db JR |
4512 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); |
4513 | if (f) | |
4514 | { | |
62e50ec6 KS |
4515 | if (f->want_fullscreen & FULLSCREEN_WAIT) |
4516 | f->want_fullscreen &= ~(FULLSCREEN_WAIT|FULLSCREEN_BOTH); | |
549808db JR |
4517 | } |
4518 | check_visibility = 1; | |
4519 | break; | |
4520 | ||
689004fa GV |
4521 | case WM_ACTIVATE: |
4522 | case WM_ACTIVATEAPP: | |
549808db JR |
4523 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); |
4524 | if (f) | |
4525 | x_check_fullscreen (f); | |
689004fa | 4526 | check_visibility = 1; |
ee78dc32 | 4527 | break; |
689004fa | 4528 | |
ee78dc32 GV |
4529 | case WM_MOVE: |
4530 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4531 | |
ee78dc32 GV |
4532 | if (f && !f->async_iconified) |
4533 | { | |
689004fa GV |
4534 | int x, y; |
4535 | ||
4536 | x_real_positions (f, &x, &y); | |
62e50ec6 KS |
4537 | f->left_pos = x; |
4538 | f->top_pos = y; | |
ee78dc32 | 4539 | } |
689004fa GV |
4540 | |
4541 | check_visibility = 1; | |
4542 | break; | |
4543 | ||
4544 | case WM_SHOWWINDOW: | |
b71b8111 JR |
4545 | /* wParam non-zero means Window is about to be shown, 0 means |
4546 | about to be hidden. */ | |
4547 | /* Redo the mouse-highlight after the tooltip has gone. */ | |
4548 | if (!msg.msg.wParam && msg.msg.hwnd == tip_window) | |
4549 | { | |
4550 | tip_window = NULL; | |
4551 | redo_mouse_highlight (); | |
4552 | } | |
4553 | ||
689004fa GV |
4554 | /* If window has been obscured or exposed by another window |
4555 | being maximised or minimised/restored, then recheck | |
4556 | visibility of all frames. Direct changes to our own | |
4557 | windows get handled by WM_SIZE. */ | |
4558 | #if 0 | |
4559 | if (msg.msg.lParam != 0) | |
4560 | check_visibility = 1; | |
4561 | else | |
4562 | { | |
4563 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
4564 | f->async_visible = msg.msg.wParam; | |
4565 | } | |
4566 | #endif | |
4567 | ||
4568 | check_visibility = 1; | |
ee78dc32 | 4569 | break; |
689004fa | 4570 | |
ee78dc32 GV |
4571 | case WM_SIZE: |
4572 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4573 | |
689004fa GV |
4574 | /* Inform lisp of whether frame has been iconified etc. */ |
4575 | if (f) | |
ee78dc32 | 4576 | { |
689004fa | 4577 | switch (msg.msg.wParam) |
ee78dc32 | 4578 | { |
689004fa GV |
4579 | case SIZE_MINIMIZED: |
4580 | f->async_visible = 0; | |
ee78dc32 | 4581 | f->async_iconified = 1; |
d67d1627 | 4582 | |
6b61353c KH |
4583 | inev.kind = ICONIFY_EVENT; |
4584 | XSETFRAME (inev.frame_or_window, f); | |
689004fa GV |
4585 | break; |
4586 | ||
4587 | case SIZE_MAXIMIZED: | |
4588 | case SIZE_RESTORED: | |
ee78dc32 GV |
4589 | f->async_visible = 1; |
4590 | f->async_iconified = 0; | |
d67d1627 | 4591 | |
d64b707c | 4592 | /* wait_reading_process_output will notice this and update |
ee78dc32 GV |
4593 | the frame's display structures. */ |
4594 | SET_FRAME_GARBAGED (f); | |
d67d1627 | 4595 | |
ee78dc32 GV |
4596 | if (f->iconified) |
4597 | { | |
31d4844a KH |
4598 | int x, y; |
4599 | ||
4600 | /* Reset top and left positions of the Window | |
4601 | here since Windows sends a WM_MOVE message | |
4602 | BEFORE telling us the Window is minimized | |
4603 | when the Window is iconified, with 3000,3000 | |
4604 | as the co-ords. */ | |
4605 | x_real_positions (f, &x, &y); | |
62e50ec6 KS |
4606 | f->left_pos = x; |
4607 | f->top_pos = y; | |
31d4844a | 4608 | |
6b61353c KH |
4609 | inev.kind = DEICONIFY_EVENT; |
4610 | XSETFRAME (inev.frame_or_window, f); | |
ee78dc32 | 4611 | } |
9ef2e2cf JR |
4612 | else if (! NILP (Vframe_list) |
4613 | && ! NILP (XCDR (Vframe_list))) | |
ee78dc32 GV |
4614 | /* Force a redisplay sooner or later |
4615 | to update the frame titles | |
4616 | in case this is the second frame. */ | |
4617 | record_asynch_buffer_change (); | |
689004fa | 4618 | break; |
ee78dc32 | 4619 | } |
ee78dc32 | 4620 | } |
689004fa | 4621 | |
ef0e360f GV |
4622 | if (f && !f->async_iconified && msg.msg.wParam != SIZE_MINIMIZED) |
4623 | { | |
4624 | RECT rect; | |
4625 | int rows; | |
4626 | int columns; | |
4627 | int width; | |
4628 | int height; | |
d67d1627 | 4629 | |
9127e20e | 4630 | GetClientRect (msg.msg.hwnd, &rect); |
d67d1627 | 4631 | |
ef0e360f GV |
4632 | height = rect.bottom - rect.top; |
4633 | width = rect.right - rect.left; | |
d67d1627 | 4634 | |
62e50ec6 KS |
4635 | rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); |
4636 | columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); | |
d67d1627 | 4637 | |
ef0e360f | 4638 | /* TODO: Clip size to the screen dimensions. */ |
d67d1627 | 4639 | |
ef0e360f GV |
4640 | /* Even if the number of character rows and columns has |
4641 | not changed, the font size may have changed, so we need | |
4642 | to check the pixel dimensions as well. */ | |
d67d1627 | 4643 | |
62e50ec6 KS |
4644 | if (columns != FRAME_COLS (f) |
4645 | || rows != FRAME_LINES (f) | |
4646 | || width != FRAME_PIXEL_WIDTH (f) | |
4647 | || height != FRAME_PIXEL_HEIGHT (f)) | |
ef0e360f | 4648 | { |
791f420f | 4649 | change_frame_size (f, rows, columns, 0, 1, 0); |
ef0e360f | 4650 | SET_FRAME_GARBAGED (f); |
31d4844a | 4651 | cancel_mouse_face (f); |
62e50ec6 KS |
4652 | FRAME_PIXEL_WIDTH (f) = width; |
4653 | FRAME_PIXEL_HEIGHT (f) = height; | |
4654 | f->win_gravity = NorthWestGravity; | |
ef0e360f GV |
4655 | } |
4656 | } | |
4657 | ||
689004fa GV |
4658 | check_visibility = 1; |
4659 | break; | |
4660 | ||
1576fbfa JR |
4661 | case WM_MOUSELEAVE: |
4662 | f = x_any_window_to_frame (dpyinfo, msg.msg.hwnd); | |
4663 | if (f) | |
4664 | { | |
4665 | if (f == dpyinfo->mouse_face_mouse_frame) | |
4666 | { | |
4667 | /* If we move outside the frame, then we're | |
4668 | certainly no longer on any text in the frame. */ | |
4669 | clear_mouse_face (dpyinfo); | |
4670 | dpyinfo->mouse_face_mouse_frame = 0; | |
4671 | } | |
4672 | ||
4673 | /* Generate a nil HELP_EVENT to cancel a help-echo. | |
4674 | Do it only if there's something to cancel. | |
4675 | Otherwise, the startup message is cleared when | |
4676 | the mouse leaves the frame. */ | |
4677 | if (any_help_event_p) | |
6b61353c | 4678 | do_help = -1; |
1576fbfa JR |
4679 | } |
4680 | break; | |
d67d1627 | 4681 | |
689004fa | 4682 | case WM_SETFOCUS: |
55131bef | 4683 | w32_detect_focus_change (dpyinfo, &msg, &inev); |
791f420f | 4684 | |
791f420f JR |
4685 | dpyinfo->grabbed = 0; |
4686 | check_visibility = 1; | |
4687 | break; | |
4688 | ||
689004fa | 4689 | case WM_KILLFOCUS: |
791f420f | 4690 | f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd); |
08712a41 | 4691 | |
791f420f JR |
4692 | if (f) |
4693 | { | |
791f420f JR |
4694 | if (f == dpyinfo->w32_focus_event_frame) |
4695 | dpyinfo->w32_focus_event_frame = 0; | |
4696 | ||
4697 | if (f == dpyinfo->w32_focus_frame) | |
4698 | x_new_focus_frame (dpyinfo, 0); | |
4699 | ||
4700 | if (f == dpyinfo->mouse_face_mouse_frame) | |
4701 | { | |
4702 | /* If we move outside the frame, then we're | |
4703 | certainly no longer on any text in the frame. */ | |
4704 | clear_mouse_face (dpyinfo); | |
4705 | dpyinfo->mouse_face_mouse_frame = 0; | |
4706 | } | |
9ef2e2cf | 4707 | |
791f420f JR |
4708 | /* Generate a nil HELP_EVENT to cancel a help-echo. |
4709 | Do it only if there's something to cancel. | |
4710 | Otherwise, the startup message is cleared when | |
4711 | the mouse leaves the frame. */ | |
4712 | if (any_help_event_p) | |
6b61353c | 4713 | do_help = -1; |
791f420f | 4714 | } |
689004fa | 4715 | |
08712a41 | 4716 | dpyinfo->grabbed = 0; |
689004fa | 4717 | check_visibility = 1; |
ee78dc32 | 4718 | break; |
689004fa | 4719 | |
ee78dc32 GV |
4720 | case WM_CLOSE: |
4721 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4722 | |
ee78dc32 GV |
4723 | if (f) |
4724 | { | |
6b61353c KH |
4725 | inev.kind = DELETE_WINDOW_EVENT; |
4726 | XSETFRAME (inev.frame_or_window, f); | |
ee78dc32 | 4727 | } |
689004fa GV |
4728 | break; |
4729 | ||
4730 | case WM_INITMENU: | |
4731 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
d67d1627 | 4732 | |
689004fa GV |
4733 | if (f) |
4734 | { | |
6b61353c KH |
4735 | inev.kind = MENU_BAR_ACTIVATE_EVENT; |
4736 | XSETFRAME (inev.frame_or_window, f); | |
689004fa | 4737 | } |
ee78dc32 | 4738 | break; |
689004fa | 4739 | |
ee78dc32 GV |
4740 | case WM_COMMAND: |
4741 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
014b6ea1 | 4742 | |
ee78dc32 GV |
4743 | if (f) |
4744 | { | |
f98169a0 GV |
4745 | extern void menubar_selection_callback |
4746 | (FRAME_PTR f, void * client_data); | |
014b6ea1 | 4747 | menubar_selection_callback (f, (void *)msg.msg.wParam); |
ee78dc32 | 4748 | } |
689004fa GV |
4749 | |
4750 | check_visibility = 1; | |
4751 | break; | |
4752 | ||
4753 | case WM_DISPLAYCHANGE: | |
4754 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
4755 | ||
d67d1627 | 4756 | if (f) |
689004fa | 4757 | { |
689004fa | 4758 | dpyinfo->n_cbits = msg.msg.wParam; |
b89c78a5 CY |
4759 | DebPrint (("display change: %d %d\n", |
4760 | (short) LOWORD (msg.msg.lParam), | |
4761 | (short) HIWORD (msg.msg.lParam))); | |
689004fa | 4762 | } |
d67d1627 | 4763 | |
689004fa | 4764 | check_visibility = 1; |
ee78dc32 | 4765 | break; |
e7efd97e GV |
4766 | |
4767 | default: | |
e471b241 | 4768 | /* Check for messages registered at runtime. */ |
e7efd97e GV |
4769 | if (msg.msg.message == msh_mousewheel) |
4770 | { | |
e471b241 | 4771 | /* Forward MSH_MOUSEWHEEL as WM_MOUSEWHEEL. */ |
66f30e44 | 4772 | msg.msg.message = WM_MOUSEWHEEL; |
e471b241 | 4773 | prepend_msg (&msg); |
e7efd97e GV |
4774 | } |
4775 | break; | |
ee78dc32 | 4776 | } |
6b61353c KH |
4777 | |
4778 | if (inev.kind != NO_EVENT) | |
4779 | { | |
4780 | kbd_buffer_store_event_hold (&inev, hold_quit); | |
4781 | count++; | |
4782 | } | |
4783 | ||
4784 | if (do_help | |
4785 | && !(hold_quit && hold_quit->kind != NO_EVENT)) | |
4786 | { | |
4787 | Lisp_Object frame; | |
4788 | ||
4789 | if (f) | |
4790 | XSETFRAME (frame, f); | |
4791 | else | |
4792 | frame = Qnil; | |
4793 | ||
4794 | if (do_help > 0) | |
4795 | { | |
e597eb7d | 4796 | if (NILP (help_echo_string)) |
6b61353c KH |
4797 | { |
4798 | help_echo_object = help_echo_window = Qnil; | |
4799 | help_echo_pos = -1; | |
4800 | } | |
4801 | ||
4802 | any_help_event_p = 1; | |
4803 | gen_help_event (help_echo_string, frame, help_echo_window, | |
4804 | help_echo_object, help_echo_pos); | |
4805 | } | |
4806 | else | |
4807 | { | |
4808 | help_echo_string = Qnil; | |
4809 | gen_help_event (Qnil, frame, Qnil, Qnil, 0); | |
4810 | } | |
4811 | count++; | |
4812 | } | |
ee78dc32 GV |
4813 | } |
4814 | ||
4815 | /* If the focus was just given to an autoraising frame, | |
4816 | raise it now. */ | |
4817 | /* ??? This ought to be able to handle more than one such frame. */ | |
4818 | if (pending_autoraise_frame) | |
4819 | { | |
4820 | x_raise_frame (pending_autoraise_frame); | |
4821 | pending_autoraise_frame = 0; | |
4822 | } | |
4823 | ||
689004fa GV |
4824 | /* Check which frames are still visisble, if we have enqueued any user |
4825 | events or been notified of events that may affect visibility. We | |
4826 | do this here because there doesn't seem to be any direct | |
4827 | notification from Windows that the visibility of a window has | |
4828 | changed (at least, not in all cases). */ | |
4829 | if (count > 0 || check_visibility) | |
4830 | { | |
4831 | Lisp_Object tail, frame; | |
4832 | ||
4833 | FOR_EACH_FRAME (tail, frame) | |
1c64a4a2 JB |
4834 | { |
4835 | FRAME_PTR f = XFRAME (frame); | |
4836 | /* The tooltip has been drawn already. Avoid the | |
4837 | SET_FRAME_GARBAGED below. */ | |
4838 | if (EQ (frame, tip_frame)) | |
4839 | continue; | |
4840 | ||
4841 | /* Check "visible" frames and mark each as obscured or not. | |
4842 | Note that async_visible is nonzero for unobscured and | |
4843 | obscured frames, but zero for hidden and iconified frames. */ | |
4844 | if (FRAME_W32_P (f) && f->async_visible) | |
4845 | { | |
4846 | RECT clipbox; | |
4847 | HDC hdc; | |
4848 | ||
4849 | enter_crit (); | |
4850 | /* Query clipping rectangle for the entire window area | |
4851 | (GetWindowDC), not just the client portion (GetDC). | |
4852 | Otherwise, the scrollbars and menubar aren't counted as | |
4853 | part of the visible area of the frame, and we may think | |
4854 | the frame is obscured when really a scrollbar is still | |
4855 | visible and gets WM_PAINT messages above. */ | |
4856 | hdc = GetWindowDC (FRAME_W32_WINDOW (f)); | |
4857 | GetClipBox (hdc, &clipbox); | |
4858 | ReleaseDC (FRAME_W32_WINDOW (f), hdc); | |
4859 | leave_crit (); | |
4860 | ||
4861 | if (clipbox.right == clipbox.left | |
4862 | || clipbox.bottom == clipbox.top) | |
4863 | { | |
4864 | /* Frame has become completely obscured so mark as | |
4865 | such (we do this by setting async_visible to 2 so | |
4866 | that FRAME_VISIBLE_P is still true, but redisplay | |
4867 | will skip it). */ | |
4868 | f->async_visible = 2; | |
689004fa | 4869 | |
1c64a4a2 JB |
4870 | if (!FRAME_OBSCURED_P (f)) |
4871 | { | |
4872 | DebPrint (("frame %p (%s) obscured\n", f, | |
4873 | SDATA (f->name))); | |
4874 | } | |
4875 | } | |
4876 | else | |
4877 | { | |
4878 | /* Frame is not obscured, so mark it as such. */ | |
4879 | f->async_visible = 1; | |
689004fa | 4880 | |
1c64a4a2 JB |
4881 | if (FRAME_OBSCURED_P (f)) |
4882 | { | |
4883 | SET_FRAME_GARBAGED (f); | |
4884 | DebPrint (("obscured frame %p (%s) found to be visible\n", f, | |
4885 | SDATA (f->name))); | |
689004fa | 4886 | |
1c64a4a2 JB |
4887 | /* Force a redisplay sooner or later. */ |
4888 | record_asynch_buffer_change (); | |
4889 | } | |
4890 | } | |
4891 | } | |
4892 | } | |
689004fa GV |
4893 | } |
4894 | ||
ee78dc32 GV |
4895 | UNBLOCK_INPUT; |
4896 | return count; | |
4897 | } | |
791f420f | 4898 | |
9ef2e2cf | 4899 | |
ee78dc32 | 4900 | \f |
791f420f JR |
4901 | /*********************************************************************** |
4902 | Text Cursor | |
4903 | ***********************************************************************/ | |
4904 | ||
791f420f JR |
4905 | /* Set clipping for output in glyph row ROW. W is the window in which |
4906 | we operate. GC is the graphics context to set clipping in. | |
ee78dc32 | 4907 | |
791f420f JR |
4908 | ROW may be a text row or, e.g., a mode line. Text rows must be |
4909 | clipped to the interior of the window dedicated to text display, | |
4910 | mode lines must be clipped to the whole window. */ | |
ee78dc32 GV |
4911 | |
4912 | static void | |
b5a2e277 | 4913 | w32_clip_to_row (w, row, area, hdc) |
791f420f JR |
4914 | struct window *w; |
4915 | struct glyph_row *row; | |
b5a2e277 | 4916 | int area; |
791f420f | 4917 | HDC hdc; |
ee78dc32 | 4918 | { |
791f420f JR |
4919 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
4920 | RECT clip_rect; | |
b5a2e277 | 4921 | int window_x, window_y, window_width; |
52cf03a1 | 4922 | |
b5a2e277 | 4923 | window_box (w, area, &window_x, &window_y, &window_width, 0); |
52cf03a1 | 4924 | |
b5a2e277 | 4925 | clip_rect.left = window_x; |
791f420f JR |
4926 | clip_rect.top = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); |
4927 | clip_rect.top = max (clip_rect.top, window_y); | |
4928 | clip_rect.right = clip_rect.left + window_width; | |
4929 | clip_rect.bottom = clip_rect.top + row->visible_height; | |
4930 | ||
791f420f | 4931 | w32_set_clip_rectangle (hdc, &clip_rect); |
ee78dc32 GV |
4932 | } |
4933 | ||
791f420f JR |
4934 | |
4935 | /* Draw a hollow box cursor on window W in glyph row ROW. */ | |
ee78dc32 GV |
4936 | |
4937 | static void | |
791f420f JR |
4938 | x_draw_hollow_cursor (w, row) |
4939 | struct window *w; | |
4940 | struct glyph_row *row; | |
ee78dc32 | 4941 | { |
791f420f | 4942 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
988646fc | 4943 | HDC hdc; |
791f420f | 4944 | RECT rect; |
b756209d | 4945 | int left, top, h; |
791f420f JR |
4946 | struct glyph *cursor_glyph; |
4947 | HBRUSH hb = CreateSolidBrush (f->output_data.w32->cursor_pixel); | |
4948 | ||
07c07cfe JR |
4949 | /* Get the glyph the cursor is on. If we can't tell because |
4950 | the current matrix is invalid or such, give up. */ | |
4951 | cursor_glyph = get_phys_cursor_glyph (w); | |
4952 | if (cursor_glyph == NULL) | |
4953 | return; | |
4954 | ||
4d91ce74 | 4955 | /* Compute frame-relative coordinates for phys cursor. */ |
b756209d EZ |
4956 | get_phys_cursor_geometry (w, row, cursor_glyph, &left, &top, &h); |
4957 | rect.left = left; | |
4958 | rect.top = top; | |
07c07cfe | 4959 | rect.bottom = rect.top + h; |
4d91ce74 | 4960 | rect.right = rect.left + w->phys_cursor_width; |
ee78dc32 | 4961 | |
988646fc | 4962 | hdc = get_frame_dc (f); |
a18bb28d | 4963 | /* Set clipping, draw the rectangle, and reset clipping again. */ |
b5a2e277 | 4964 | w32_clip_to_row (w, row, TEXT_AREA, hdc); |
791f420f JR |
4965 | FrameRect (hdc, &rect, hb); |
4966 | DeleteObject (hb); | |
a18bb28d | 4967 | w32_set_clip_rectangle (hdc, NULL); |
791f420f | 4968 | release_frame_dc (f, hdc); |
ee78dc32 GV |
4969 | } |
4970 | ||
791f420f JR |
4971 | |
4972 | /* Draw a bar cursor on window W in glyph row ROW. | |
4973 | ||
4974 | Implementation note: One would like to draw a bar cursor with an | |
4975 | angle equal to the one given by the font property XA_ITALIC_ANGLE. | |
4976 | Unfortunately, I didn't find a font yet that has this property set. | |
4977 | --gerd. */ | |
ee78dc32 GV |
4978 | |
4979 | static void | |
17456df1 | 4980 | x_draw_bar_cursor (w, row, width, kind) |
791f420f JR |
4981 | struct window *w; |
4982 | struct glyph_row *row; | |
9ef2e2cf | 4983 | int width; |
17456df1 | 4984 | enum text_cursor_kinds kind; |
ee78dc32 | 4985 | { |
c2cc16fa JR |
4986 | struct frame *f = XFRAME (w->frame); |
4987 | struct glyph *cursor_glyph; | |
791f420f | 4988 | |
c2cc16fa JR |
4989 | /* If cursor is out of bounds, don't draw garbage. This can happen |
4990 | in mini-buffer windows when switching between echo area glyphs | |
4991 | and mini-buffer. */ | |
4992 | cursor_glyph = get_phys_cursor_glyph (w); | |
4993 | if (cursor_glyph == NULL) | |
4994 | return; | |
9ef2e2cf | 4995 | |
c2cc16fa JR |
4996 | /* If on an image, draw like a normal cursor. That's usually better |
4997 | visible than drawing a bar, esp. if the image is large so that | |
4998 | the bar might not be in the window. */ | |
4999 | if (cursor_glyph->type == IMAGE_GLYPH) | |
5000 | { | |
5001 | struct glyph_row *row; | |
5002 | row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos); | |
89271099 | 5003 | draw_phys_cursor_glyph (w, row, DRAW_CURSOR); |
c2cc16fa JR |
5004 | } |
5005 | else | |
5006 | { | |
6ff3e5e3 JR |
5007 | COLORREF cursor_color = f->output_data.w32->cursor_pixel; |
5008 | struct face *face = FACE_FROM_ID (f, cursor_glyph->face_id); | |
705af33f JR |
5009 | int x; |
5010 | HDC hdc; | |
6ff3e5e3 | 5011 | |
6ff3e5e3 JR |
5012 | /* If the glyph's background equals the color we normally draw |
5013 | the bar cursor in, the bar cursor in its normal color is | |
5014 | invisible. Use the glyph's foreground color instead in this | |
5015 | case, on the assumption that the glyph's colors are chosen so | |
5016 | that the glyph is legible. */ | |
5017 | if (face->background == cursor_color) | |
5018 | cursor_color = face->foreground; | |
5019 | ||
c2cc16fa | 5020 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
a18bb28d | 5021 | |
c2cc16fa | 5022 | hdc = get_frame_dc (f); |
b5a2e277 | 5023 | w32_clip_to_row (w, row, TEXT_AREA, hdc); |
17456df1 JR |
5024 | |
5025 | if (kind == BAR_CURSOR) | |
5026 | { | |
705af33f JR |
5027 | if (width < 0) |
5028 | width = FRAME_CURSOR_WIDTH (f); | |
5029 | width = min (cursor_glyph->pixel_width, width); | |
5030 | ||
5031 | w->phys_cursor_width = width; | |
5032 | ||
17456df1 JR |
5033 | w32_fill_area (f, hdc, cursor_color, x, |
5034 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y), | |
5035 | width, row->height); | |
5036 | } | |
5037 | else | |
5038 | { | |
705af33f JR |
5039 | int dummy_x, dummy_y, dummy_h; |
5040 | ||
5041 | if (width < 0) | |
5042 | width = row->height; | |
5043 | ||
5044 | width = min (row->height, width); | |
5045 | ||
5046 | get_phys_cursor_geometry (w, row, cursor_glyph, &dummy_x, | |
5047 | &dummy_y, &dummy_h); | |
17456df1 JR |
5048 | w32_fill_area (f, hdc, cursor_color, x, |
5049 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y + | |
5050 | row->height - width), | |
705af33f | 5051 | w->phys_cursor_width, width); |
17456df1 | 5052 | } |
a18bb28d JR |
5053 | |
5054 | w32_set_clip_rectangle (hdc, NULL); | |
c2cc16fa | 5055 | release_frame_dc (f, hdc); |
791f420f | 5056 | } |
ee78dc32 GV |
5057 | } |
5058 | ||
791f420f | 5059 | |
89271099 | 5060 | /* RIF: Define cursor CURSOR on frame F. */ |
791f420f | 5061 | |
ee78dc32 | 5062 | static void |
89271099 KS |
5063 | w32_define_frame_cursor (f, cursor) |
5064 | struct frame *f; | |
5065 | Cursor cursor; | |
ee78dc32 | 5066 | { |
89271099 | 5067 | w32_define_cursor (FRAME_W32_WINDOW (f), cursor); |
791f420f | 5068 | } |
ee78dc32 | 5069 | |
ee78dc32 | 5070 | |
89271099 | 5071 | /* RIF: Clear area on frame F. */ |
ee78dc32 | 5072 | |
791f420f | 5073 | static void |
89271099 KS |
5074 | w32_clear_frame_area (f, x, y, width, height) |
5075 | struct frame *f; | |
5076 | int x, y, width, height; | |
791f420f | 5077 | { |
89271099 | 5078 | HDC hdc; |
791f420f | 5079 | |
89271099 KS |
5080 | hdc = get_frame_dc (f); |
5081 | w32_clear_area (f, hdc, x, y, width, height); | |
5082 | release_frame_dc (f, hdc); | |
791f420f | 5083 | } |
ee78dc32 | 5084 | |
89271099 | 5085 | /* RIF: Draw or clear cursor on window W. */ |
791f420f JR |
5086 | |
5087 | static void | |
e5a3b7d9 | 5088 | w32_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, active_p) |
791f420f | 5089 | struct window *w; |
89271099 | 5090 | struct glyph_row *glyph_row; |
e5a3b7d9 KS |
5091 | int x, y; |
5092 | int cursor_type, cursor_width; | |
5093 | int on_p, active_p; | |
ee78dc32 | 5094 | { |
e5a3b7d9 | 5095 | if (on_p) |
791f420f | 5096 | { |
99558ce8 JR |
5097 | /* If the user wants to use the system caret, make sure our own |
5098 | cursor remains invisible. */ | |
5099 | if (w32_use_visible_system_caret) | |
5100 | { | |
6b61353c KH |
5101 | /* Call to erase_phys_cursor here seems to use the |
5102 | wrong values of w->phys_cursor, as they have been | |
5103 | overwritten before this function was called. */ | |
99558ce8 | 5104 | if (w->phys_cursor_type != NO_CURSOR) |
89271099 | 5105 | erase_phys_cursor (w); |
99558ce8 | 5106 | |
e5a3b7d9 | 5107 | cursor_type = w->phys_cursor_type = NO_CURSOR; |
e1429afe | 5108 | w->phys_cursor_width = -1; |
99558ce8 JR |
5109 | } |
5110 | else | |
e1429afe | 5111 | { |
e5a3b7d9 | 5112 | w->phys_cursor_type = cursor_type; |
e1429afe | 5113 | } |
99558ce8 | 5114 | |
791f420f JR |
5115 | w->phys_cursor_on_p = 1; |
5116 | ||
abb15ebd JR |
5117 | /* If this is the active cursor, we need to track it with the |
5118 | system caret, so third party software like screen magnifiers | |
5119 | and speech synthesizers can follow the cursor. */ | |
e5a3b7d9 | 5120 | if (active_p) |
abb15ebd | 5121 | { |
0648dde0 | 5122 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
99558ce8 | 5123 | HWND hwnd = FRAME_W32_WINDOW (f); |
abb15ebd | 5124 | |
99558ce8 JR |
5125 | w32_system_caret_x |
5126 | = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | |
5127 | w32_system_caret_y | |
5128 | = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) | |
5129 | + glyph_row->ascent - w->phys_cursor_ascent); | |
5130 | ||
5131 | /* If the size of the active cursor changed, destroy the old | |
5132 | system caret. */ | |
5133 | if (w32_system_caret_hwnd | |
5134 | && (w32_system_caret_height != w->phys_cursor_height)) | |
5135 | PostMessage (hwnd, WM_EMACS_DESTROY_CARET, 0, 0); | |
5136 | ||
5137 | w32_system_caret_height = w->phys_cursor_height; | |
5138 | ||
5139 | /* Move the system caret. */ | |
5140 | PostMessage (hwnd, WM_EMACS_TRACK_CARET, 0, 0); | |
abb15ebd JR |
5141 | } |
5142 | ||
6b61353c KH |
5143 | if (glyph_row->exact_window_width_line_p |
5144 | && w->phys_cursor.hpos >= glyph_row->used[TEXT_AREA]) | |
5145 | { | |
5146 | glyph_row->cursor_in_fringe_p = 1; | |
5147 | draw_fringe_bitmap (w, glyph_row, 0); | |
5148 | return; | |
5149 | } | |
5150 | ||
e5a3b7d9 | 5151 | switch (cursor_type) |
ee78dc32 | 5152 | { |
791f420f JR |
5153 | case HOLLOW_BOX_CURSOR: |
5154 | x_draw_hollow_cursor (w, glyph_row); | |
5155 | break; | |
5156 | ||
5157 | case FILLED_BOX_CURSOR: | |
89271099 | 5158 | draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR); |
791f420f JR |
5159 | break; |
5160 | ||
5161 | case BAR_CURSOR: | |
e5a3b7d9 | 5162 | x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR); |
17456df1 JR |
5163 | break; |
5164 | ||
5165 | case HBAR_CURSOR: | |
e5a3b7d9 | 5166 | x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR); |
791f420f | 5167 | break; |
ee78dc32 | 5168 | |
791f420f | 5169 | case NO_CURSOR: |
a18bb28d | 5170 | w->phys_cursor_width = 0; |
791f420f JR |
5171 | break; |
5172 | ||
5173 | default: | |
5174 | abort (); | |
5175 | } | |
ee78dc32 GV |
5176 | } |
5177 | } | |
5178 | ||
689004fa | 5179 | |
ee78dc32 | 5180 | \f |
7f5d1df8 GV |
5181 | /* Icons. */ |
5182 | ||
5183 | int | |
5184 | x_bitmap_icon (f, icon) | |
5185 | struct frame *f; | |
5186 | Lisp_Object icon; | |
5187 | { | |
945a75f8 JR |
5188 | HANDLE main_icon; |
5189 | HANDLE small_icon = NULL; | |
7f5d1df8 GV |
5190 | |
5191 | if (FRAME_W32_WINDOW (f) == 0) | |
5192 | return 1; | |
5193 | ||
5194 | if (NILP (icon)) | |
945a75f8 | 5195 | main_icon = LoadIcon (hinst, EMACS_CLASS); |
7f5d1df8 | 5196 | else if (STRINGP (icon)) |
945a75f8 JR |
5197 | { |
5198 | /* Load the main icon from the named file. */ | |
5199 | main_icon = LoadImage (NULL, (LPCTSTR) SDATA (icon), IMAGE_ICON, 0, 0, | |
5200 | LR_DEFAULTSIZE | LR_LOADFROMFILE); | |
5201 | /* Try to load a small icon to go with it. */ | |
5202 | small_icon = LoadImage (NULL, (LPCSTR) SDATA (icon), IMAGE_ICON, | |
5203 | GetSystemMetrics (SM_CXSMICON), | |
5204 | GetSystemMetrics (SM_CYSMICON), | |
5205 | LR_LOADFROMFILE); | |
5206 | } | |
7f5d1df8 GV |
5207 | else if (SYMBOLP (icon)) |
5208 | { | |
5209 | LPCTSTR name; | |
5210 | ||
5211 | if (EQ (icon, intern ("application"))) | |
5212 | name = (LPCTSTR) IDI_APPLICATION; | |
5213 | else if (EQ (icon, intern ("hand"))) | |
5214 | name = (LPCTSTR) IDI_HAND; | |
5215 | else if (EQ (icon, intern ("question"))) | |
5216 | name = (LPCTSTR) IDI_QUESTION; | |
5217 | else if (EQ (icon, intern ("exclamation"))) | |
5218 | name = (LPCTSTR) IDI_EXCLAMATION; | |
5219 | else if (EQ (icon, intern ("asterisk"))) | |
5220 | name = (LPCTSTR) IDI_ASTERISK; | |
5221 | else if (EQ (icon, intern ("winlogo"))) | |
5222 | name = (LPCTSTR) IDI_WINLOGO; | |
5223 | else | |
5224 | return 1; | |
5225 | ||
945a75f8 | 5226 | main_icon = LoadIcon (NULL, name); |
7f5d1df8 GV |
5227 | } |
5228 | else | |
5229 | return 1; | |
5230 | ||
945a75f8 | 5231 | if (main_icon == NULL) |
7f5d1df8 GV |
5232 | return 1; |
5233 | ||
791f420f | 5234 | PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_BIG, |
945a75f8 JR |
5235 | (LPARAM) main_icon); |
5236 | ||
5237 | /* If there is a small icon that goes with it, set that too. */ | |
5238 | if (small_icon) | |
5239 | PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_SMALL, | |
5240 | (LPARAM) small_icon); | |
7f5d1df8 GV |
5241 | |
5242 | return 0; | |
5243 | } | |
5244 | ||
5245 | \f | |
c2cc16fa JR |
5246 | /************************************************************************ |
5247 | Handling X errors | |
5248 | ************************************************************************/ | |
5249 | ||
5250 | /* Display Error Handling functions not used on W32. Listing them here | |
5251 | helps diff stay in step when comparing w32term.c with xterm.c. | |
5252 | ||
5253 | x_error_catcher (display, error) | |
5254 | x_catch_errors (dpy) | |
5255 | x_catch_errors_unwind (old_val) | |
5256 | x_check_errors (dpy, format) | |
16ca6226 EZ |
5257 | x_fully_uncatch_errors () |
5258 | x_catching_errors () | |
c2cc16fa JR |
5259 | x_had_errors_p (dpy) |
5260 | x_clear_errors (dpy) | |
5261 | x_uncatch_errors (dpy, count) | |
5262 | x_trace_wire () | |
5263 | x_connection_signal (signalnum) | |
5264 | x_connection_closed (dpy, error_message) | |
5265 | x_error_quitter (display, error) | |
5266 | x_error_handler (display, error) | |
5267 | x_io_error_quitter (display) | |
5268 | ||
5269 | */ | |
5270 | ||
5271 | \f | |
ee78dc32 GV |
5272 | /* Changing the font of the frame. */ |
5273 | ||
027f6f90 | 5274 | Lisp_Object |
ef39ccbb | 5275 | x_new_font (f, font_object, fontset) |
027f6f90 | 5276 | struct frame *f; |
027f6f90 | 5277 | Lisp_Object font_object; |
ef39ccbb | 5278 | int fontset; |
027f6f90 | 5279 | { |
ef39ccbb | 5280 | struct font *font = XFONT_OBJECT (font_object); |
027f6f90 | 5281 | |
ef39ccbb KH |
5282 | if (fontset < 0) |
5283 | fontset = fontset_from_font (font_object); | |
5284 | FRAME_FONTSET (f) = fontset; | |
5285 | if (FRAME_FONT (f) == font) | |
027f6f90 JR |
5286 | /* This font is already set in frame F. There's nothing more to |
5287 | do. */ | |
f9c34147 | 5288 | return font_object; |
027f6f90 | 5289 | |
ef39ccbb KH |
5290 | FRAME_FONT (f) = font; |
5291 | FRAME_BASELINE_OFFSET (f) = font->baseline_offset; | |
5292 | FRAME_COLUMN_WIDTH (f) = font->average_width; | |
5293 | FRAME_SPACE_WIDTH (f) = font->space_width; | |
5294 | FRAME_LINE_HEIGHT (f) = font->height; | |
027f6f90 JR |
5295 | |
5296 | compute_fringe_widths (f, 1); | |
5297 | ||
5298 | /* Compute the scroll bar width in character columns. */ | |
5299 | if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0) | |
5300 | { | |
5301 | int wid = FRAME_COLUMN_WIDTH (f); | |
5302 | FRAME_CONFIG_SCROLL_BAR_COLS (f) | |
5303 | = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid - 1) / wid; | |
5304 | } | |
5305 | else | |
5306 | { | |
5307 | int wid = FRAME_COLUMN_WIDTH (f); | |
5308 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid; | |
5309 | } | |
5310 | ||
5311 | /* Now make the frame display the given font. */ | |
5312 | if (FRAME_X_WINDOW (f) != 0) | |
5313 | { | |
5314 | /* Don't change the size of a tip frame; there's no point in | |
5315 | doing it because it's done in Fx_show_tip, and it leads to | |
5316 | problems because the tip frame has no widget. */ | |
5317 | if (NILP (tip_frame) || XFRAME (tip_frame) != f) | |
5318 | x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f)); | |
5319 | } | |
5320 | ||
f9c34147 | 5321 | /* X version sets font of input methods here also. */ |
027f6f90 | 5322 | |
f9c34147 | 5323 | return font_object; |
027f6f90 | 5324 | } |
027f6f90 | 5325 | |
c2cc16fa JR |
5326 | \f |
5327 | /*********************************************************************** | |
5328 | TODO: W32 Input Methods | |
5329 | ***********************************************************************/ | |
5330 | /* Listing missing functions from xterm.c helps diff stay in step. | |
791f420f | 5331 | |
c2cc16fa JR |
5332 | xim_destroy_callback (xim, client_data, call_data) |
5333 | xim_open_dpy (dpyinfo, resource_name) | |
5334 | struct xim_inst_t | |
5335 | xim_instantiate_callback (display, client_data, call_data) | |
5336 | xim_initialize (dpyinfo, resource_name) | |
5337 | xim_close_dpy (dpyinfo) | |
791f420f | 5338 | |
c2cc16fa | 5339 | */ |
791f420f | 5340 | |
cabb23bc | 5341 | \f |
689004fa GV |
5342 | /* Calculate the absolute position in frame F |
5343 | from its current recorded position values and gravity. */ | |
5344 | ||
9ef2e2cf | 5345 | void |
ee78dc32 GV |
5346 | x_calc_absolute_position (f) |
5347 | struct frame *f; | |
5348 | { | |
62e50ec6 | 5349 | int flags = f->size_hint_flags; |
ee78dc32 | 5350 | |
83676aa2 KS |
5351 | /* The sum of the widths of the frame's left and right borders, and |
5352 | the sum of the heights of the frame's top and bottom borders (in | |
5353 | pixels) drawn by Windows. */ | |
5354 | unsigned int left_right_borders_width, top_bottom_borders_height; | |
5355 | ||
5356 | /* Try to get the actual values of these two variables. We compute | |
5357 | the border width (height) by subtracting the width (height) of | |
5358 | the frame's client area from the width (height) of the frame's | |
5359 | entire window. */ | |
5360 | WINDOWPLACEMENT wp = { 0 }; | |
5361 | RECT client_rect = { 0 }; | |
5362 | ||
5363 | if (GetWindowPlacement (FRAME_W32_WINDOW (f), &wp) | |
5364 | && GetClientRect (FRAME_W32_WINDOW (f), &client_rect)) | |
5365 | { | |
5366 | left_right_borders_width = | |
5367 | (wp.rcNormalPosition.right - wp.rcNormalPosition.left) - | |
5368 | (client_rect.right - client_rect.left); | |
5369 | ||
5370 | top_bottom_borders_height = | |
5371 | (wp.rcNormalPosition.bottom - wp.rcNormalPosition.top) - | |
5372 | (client_rect.bottom - client_rect.top); | |
5373 | } | |
5374 | else | |
5375 | { | |
5376 | /* Use sensible default values. */ | |
5377 | left_right_borders_width = 8; | |
5378 | top_bottom_borders_height = 32; | |
5379 | } | |
5380 | ||
5381 | /* Treat negative positions as relative to the rightmost bottommost | |
ee78dc32 GV |
5382 | position that fits on the screen. */ |
5383 | if (flags & XNegative) | |
b89c78a5 | 5384 | f->left_pos = (x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f)) |
62e50ec6 | 5385 | - FRAME_PIXEL_WIDTH (f) |
83676aa2 KS |
5386 | + f->left_pos |
5387 | - (left_right_borders_width - 1)); | |
158cba56 | 5388 | |
ee78dc32 | 5389 | if (flags & YNegative) |
b89c78a5 | 5390 | f->top_pos = (x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f)) |
62e50ec6 | 5391 | - FRAME_PIXEL_HEIGHT (f) |
83676aa2 KS |
5392 | + f->top_pos |
5393 | - (top_bottom_borders_height - 1)); | |
5394 | ||
5395 | /* The left_pos and top_pos are now relative to the top and left | |
5396 | screen edges, so the flags should correspond. */ | |
62e50ec6 | 5397 | f->size_hint_flags &= ~ (XNegative | YNegative); |
ee78dc32 GV |
5398 | } |
5399 | ||
5400 | /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position, | |
5401 | to really change the position, and 0 when calling from | |
5402 | x_make_frame_visible (in that case, XOFF and YOFF are the current | |
5403 | position values). It is -1 when calling from x_set_frame_parameters, | |
5404 | which means, do adjust for borders but don't change the gravity. */ | |
5405 | ||
9ef2e2cf | 5406 | void |
ee78dc32 GV |
5407 | x_set_offset (f, xoff, yoff, change_gravity) |
5408 | struct frame *f; | |
5409 | register int xoff, yoff; | |
5410 | int change_gravity; | |
5411 | { | |
5412 | int modified_top, modified_left; | |
5413 | ||
5414 | if (change_gravity > 0) | |
5415 | { | |
62e50ec6 KS |
5416 | f->top_pos = yoff; |
5417 | f->left_pos = xoff; | |
5418 | f->size_hint_flags &= ~ (XNegative | YNegative); | |
ee78dc32 | 5419 | if (xoff < 0) |
62e50ec6 | 5420 | f->size_hint_flags |= XNegative; |
ee78dc32 | 5421 | if (yoff < 0) |
62e50ec6 KS |
5422 | f->size_hint_flags |= YNegative; |
5423 | f->win_gravity = NorthWestGravity; | |
ee78dc32 GV |
5424 | } |
5425 | x_calc_absolute_position (f); | |
5426 | ||
5427 | BLOCK_INPUT; | |
5428 | x_wm_set_size_hint (f, (long) 0, 0); | |
5429 | ||
62e50ec6 KS |
5430 | modified_left = f->left_pos; |
5431 | modified_top = f->top_pos; | |
ee78dc32 | 5432 | |
fbd6baed | 5433 | my_set_window_pos (FRAME_W32_WINDOW (f), |
52cf03a1 GV |
5434 | NULL, |
5435 | modified_left, modified_top, | |
cabb23bc | 5436 | 0, 0, |
689004fa | 5437 | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); |
ee78dc32 GV |
5438 | UNBLOCK_INPUT; |
5439 | } | |
5440 | ||
549808db JR |
5441 | |
5442 | /* Check if we need to resize the frame due to a fullscreen request. | |
5443 | If so needed, resize the frame. */ | |
5444 | static void | |
5445 | x_check_fullscreen (f) | |
5446 | struct frame *f; | |
5447 | { | |
62e50ec6 | 5448 | if (f->want_fullscreen & FULLSCREEN_BOTH) |
549808db JR |
5449 | { |
5450 | int width, height, ign; | |
d67d1627 | 5451 | |
62e50ec6 | 5452 | x_real_positions (f, &f->left_pos, &f->top_pos); |
549808db JR |
5453 | |
5454 | x_fullscreen_adjust (f, &width, &height, &ign, &ign); | |
d67d1627 | 5455 | |
549808db | 5456 | /* We do not need to move the window, it shall be taken care of |
66f30e44 | 5457 | when setting WM manager hints. */ |
62e50ec6 | 5458 | if (FRAME_COLS (f) != width || FRAME_LINES (f) != height) |
549808db JR |
5459 | { |
5460 | change_frame_size (f, height, width, 0, 1, 0); | |
5461 | SET_FRAME_GARBAGED (f); | |
5462 | cancel_mouse_face (f); | |
5463 | ||
5464 | /* Wait for the change of frame size to occur */ | |
62e50ec6 | 5465 | f->want_fullscreen |= FULLSCREEN_WAIT; |
549808db JR |
5466 | } |
5467 | } | |
5468 | } | |
5469 | ||
ee78dc32 GV |
5470 | /* Call this to change the size of frame F's x-window. |
5471 | If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity | |
5472 | for this size change and subsequent size changes. | |
5473 | Otherwise we leave the window gravity unchanged. */ | |
c2cc16fa | 5474 | |
791f420f | 5475 | void |
ee78dc32 GV |
5476 | x_set_window_size (f, change_gravity, cols, rows) |
5477 | struct frame *f; | |
5478 | int change_gravity; | |
5479 | int cols, rows; | |
5480 | { | |
5481 | int pixelwidth, pixelheight; | |
d67d1627 | 5482 | |
ee78dc32 | 5483 | BLOCK_INPUT; |
d67d1627 | 5484 | |
ee78dc32 | 5485 | check_frame_size (f, &rows, &cols); |
62e50ec6 KS |
5486 | f->scroll_bar_actual_width |
5487 | = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f); | |
d33c49e8 | 5488 | |
b6ae1532 | 5489 | compute_fringe_widths (f, 0); |
d33c49e8 | 5490 | |
62e50ec6 KS |
5491 | pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols); |
5492 | pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows); | |
d67d1627 | 5493 | |
62e50ec6 | 5494 | f->win_gravity = NorthWestGravity; |
ee78dc32 | 5495 | x_wm_set_size_hint (f, (long) 0, 0); |
d67d1627 | 5496 | |
ee78dc32 GV |
5497 | { |
5498 | RECT rect; | |
5499 | ||
5500 | rect.left = rect.top = 0; | |
5501 | rect.right = pixelwidth; | |
5502 | rect.bottom = pixelheight; | |
d67d1627 | 5503 | |
fbd6baed | 5504 | AdjustWindowRect(&rect, f->output_data.w32->dwStyle, |
97c23857 | 5505 | FRAME_EXTERNAL_MENU_BAR (f)); |
d67d1627 | 5506 | |
fbd6baed | 5507 | my_set_window_pos (FRAME_W32_WINDOW (f), |
d67d1627 | 5508 | NULL, |
52cf03a1 | 5509 | 0, 0, |
689004fa GV |
5510 | rect.right - rect.left, |
5511 | rect.bottom - rect.top, | |
5512 | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); | |
ee78dc32 | 5513 | } |
d67d1627 | 5514 | |
f8d1a163 JR |
5515 | #if 0 |
5516 | /* The following mirrors what is done in xterm.c. It appears to be | |
5517 | for informing lisp of the new size immediately, while the actual | |
5518 | resize will happen asynchronously. But on Windows, the menu bar | |
5519 | automatically wraps when the frame is too narrow to contain it, | |
5520 | and that causes any calculations made here to come out wrong. The | |
fffa137c | 5521 | end is some nasty buggy behavior, including the potential loss |
f8d1a163 JR |
5522 | of the minibuffer. |
5523 | ||
5524 | Disabling this code is either not sufficient to fix the problems | |
5525 | completely, or it causes fresh problems, but at least it removes | |
5526 | the most problematic symptom of the minibuffer becoming unusable. | |
5527 | ||
5528 | ----------------------------------------------------------------- | |
5529 | ||
5530 | Now, strictly speaking, we can't be sure that this is accurate, | |
ee78dc32 GV |
5531 | but the window manager will get around to dealing with the size |
5532 | change request eventually, and we'll hear how it went when the | |
5533 | ConfigureNotify event gets here. | |
d67d1627 | 5534 | |
ee78dc32 GV |
5535 | We could just not bother storing any of this information here, |
5536 | and let the ConfigureNotify event set everything up, but that | |
ec48c3a7 | 5537 | might be kind of confusing to the Lisp code, since size changes |
ee78dc32 | 5538 | wouldn't be reported in the frame parameters until some random |
791f420f JR |
5539 | point in the future when the ConfigureNotify event arrives. |
5540 | ||
5541 | We pass 1 for DELAY since we can't run Lisp code inside of | |
5542 | a BLOCK_INPUT. */ | |
5543 | change_frame_size (f, rows, cols, 0, 1, 0); | |
62e50ec6 KS |
5544 | FRAME_PIXEL_WIDTH (f) = pixelwidth; |
5545 | FRAME_PIXEL_HEIGHT (f) = pixelheight; | |
ee78dc32 | 5546 | |
689004fa GV |
5547 | /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to |
5548 | receive in the ConfigureNotify event; if we get what we asked | |
5549 | for, then the event won't cause the screen to become garbaged, so | |
5550 | we have to make sure to do it here. */ | |
5551 | SET_FRAME_GARBAGED (f); | |
5552 | ||
ee78dc32 | 5553 | /* If cursor was outside the new size, mark it as off. */ |
791f420f | 5554 | mark_window_cursors_off (XWINDOW (f->root_window)); |
ee78dc32 | 5555 | |
689004fa | 5556 | /* Clear out any recollection of where the mouse highlighting was, |
d67d1627 | 5557 | since it might be in a place that's outside the new frame size. |
689004fa GV |
5558 | Actually checking whether it is outside is a pain in the neck, |
5559 | so don't try--just let the highlighting be done afresh with new size. */ | |
31d4844a | 5560 | cancel_mouse_face (f); |
f8d1a163 | 5561 | #endif |
31d4844a | 5562 | |
ee78dc32 GV |
5563 | UNBLOCK_INPUT; |
5564 | } | |
5565 | \f | |
5566 | /* Mouse warping. */ | |
5567 | ||
ec48c3a7 JR |
5568 | void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y); |
5569 | ||
5570 | void | |
5571 | x_set_mouse_position (f, x, y) | |
5572 | struct frame *f; | |
5573 | int x, y; | |
5574 | { | |
5575 | int pix_x, pix_y; | |
5576 | ||
62e50ec6 KS |
5577 | pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2; |
5578 | pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2; | |
ec48c3a7 JR |
5579 | |
5580 | if (pix_x < 0) pix_x = 0; | |
62e50ec6 | 5581 | if (pix_x > FRAME_PIXEL_WIDTH (f)) pix_x = FRAME_PIXEL_WIDTH (f); |
ec48c3a7 JR |
5582 | |
5583 | if (pix_y < 0) pix_y = 0; | |
62e50ec6 | 5584 | if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f); |
ec48c3a7 JR |
5585 | |
5586 | x_set_mouse_pixel_position (f, pix_x, pix_y); | |
5587 | } | |
5588 | ||
1bcd16f2 MB |
5589 | void |
5590 | x_set_mouse_pixel_position (f, pix_x, pix_y) | |
5591 | struct frame *f; | |
5592 | int pix_x, pix_y; | |
5593 | { | |
689004fa GV |
5594 | RECT rect; |
5595 | POINT pt; | |
5596 | ||
1bcd16f2 MB |
5597 | BLOCK_INPUT; |
5598 | ||
689004fa GV |
5599 | GetClientRect (FRAME_W32_WINDOW (f), &rect); |
5600 | pt.x = rect.left + pix_x; | |
5601 | pt.y = rect.top + pix_y; | |
5602 | ClientToScreen (FRAME_W32_WINDOW (f), &pt); | |
1bcd16f2 | 5603 | |
689004fa | 5604 | SetCursorPos (pt.x, pt.y); |
1bcd16f2 MB |
5605 | |
5606 | UNBLOCK_INPUT; | |
5607 | } | |
5608 | ||
ee78dc32 GV |
5609 | \f |
5610 | /* focus shifting, raising and lowering. */ | |
5611 | ||
ec48c3a7 | 5612 | void |
ee78dc32 GV |
5613 | x_focus_on_frame (f) |
5614 | struct frame *f; | |
5615 | { | |
689004fa GV |
5616 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
5617 | ||
5618 | /* Give input focus to frame. */ | |
5619 | BLOCK_INPUT; | |
5620 | #if 0 | |
5621 | /* Try not to change its Z-order if possible. */ | |
5622 | if (x_window_to_frame (dpyinfo, GetForegroundWindow ())) | |
5623 | my_set_focus (f, FRAME_W32_WINDOW (f)); | |
5624 | else | |
5625 | #endif | |
ef0e360f | 5626 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa | 5627 | UNBLOCK_INPUT; |
ee78dc32 GV |
5628 | } |
5629 | ||
ec48c3a7 | 5630 | void |
ee78dc32 GV |
5631 | x_unfocus_frame (f) |
5632 | struct frame *f; | |
5633 | { | |
5634 | } | |
5635 | ||
5636 | /* Raise frame F. */ | |
791f420f | 5637 | void |
ee78dc32 GV |
5638 | x_raise_frame (f) |
5639 | struct frame *f; | |
5640 | { | |
689004fa GV |
5641 | BLOCK_INPUT; |
5642 | ||
5643 | /* Strictly speaking, raise-frame should only change the frame's Z | |
fffa137c | 5644 | order, leaving input focus unchanged. This is reasonable behavior |
689004fa | 5645 | on X where the usual policy is point-to-focus. However, this |
fffa137c | 5646 | behavior would be very odd on Windows where the usual policy is |
689004fa GV |
5647 | click-to-focus. |
5648 | ||
5649 | On X, if the mouse happens to be over the raised frame, it gets | |
5650 | input focus anyway (so the window with focus will never be | |
5651 | completely obscured) - if not, then just moving the mouse over it | |
5652 | is sufficient to give it focus. On Windows, the user must actually | |
5653 | click on the frame (preferrably the title bar so as not to move | |
5654 | point), which is more awkward. Also, no other Windows program | |
5655 | raises a window to the top but leaves another window (possibly now | |
5656 | completely obscured) with input focus. | |
5657 | ||
5658 | Because there is a system setting on Windows that allows the user | |
5659 | to choose the point to focus policy, we make the strict semantics | |
5660 | optional, but by default we grab focus when raising. */ | |
5661 | ||
5662 | if (NILP (Vw32_grab_focus_on_raise)) | |
ee78dc32 | 5663 | { |
689004fa GV |
5664 | /* The obvious call to my_set_window_pos doesn't work if Emacs is |
5665 | not already the foreground application: the frame is raised | |
5666 | above all other frames belonging to us, but not above the | |
5667 | current top window. To achieve that, we have to resort to this | |
5668 | more cumbersome method. */ | |
5669 | ||
5670 | HDWP handle = BeginDeferWindowPos (2); | |
5671 | if (handle) | |
5672 | { | |
5673 | DeferWindowPos (handle, | |
5674 | FRAME_W32_WINDOW (f), | |
5675 | HWND_TOP, | |
5676 | 0, 0, 0, 0, | |
5677 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
5678 | ||
5679 | DeferWindowPos (handle, | |
5680 | GetForegroundWindow (), | |
5681 | FRAME_W32_WINDOW (f), | |
5682 | 0, 0, 0, 0, | |
5683 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
5684 | ||
5685 | EndDeferWindowPos (handle); | |
5686 | } | |
ee78dc32 | 5687 | } |
689004fa GV |
5688 | else |
5689 | { | |
ef0e360f | 5690 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa GV |
5691 | } |
5692 | ||
5693 | UNBLOCK_INPUT; | |
ee78dc32 GV |
5694 | } |
5695 | ||
5696 | /* Lower frame F. */ | |
791f420f | 5697 | void |
ee78dc32 GV |
5698 | x_lower_frame (f) |
5699 | struct frame *f; | |
5700 | { | |
689004fa GV |
5701 | BLOCK_INPUT; |
5702 | my_set_window_pos (FRAME_W32_WINDOW (f), | |
5703 | HWND_BOTTOM, | |
5704 | 0, 0, 0, 0, | |
5705 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
5706 | UNBLOCK_INPUT; | |
ee78dc32 GV |
5707 | } |
5708 | ||
5709 | static void | |
ec48c3a7 | 5710 | w32_frame_raise_lower (f, raise_flag) |
ee78dc32 | 5711 | FRAME_PTR f; |
ec48c3a7 | 5712 | int raise_flag; |
ee78dc32 | 5713 | { |
7e6ac5b9 AI |
5714 | if (! FRAME_W32_P (f)) |
5715 | return; | |
5716 | ||
ec48c3a7 | 5717 | if (raise_flag) |
ee78dc32 GV |
5718 | x_raise_frame (f); |
5719 | else | |
5720 | x_lower_frame (f); | |
5721 | } | |
5722 | \f | |
5723 | /* Change of visibility. */ | |
5724 | ||
5725 | /* This tries to wait until the frame is really visible. | |
5726 | However, if the window manager asks the user where to position | |
5727 | the frame, this will return before the user finishes doing that. | |
5728 | The frame will not actually be visible at that time, | |
5729 | but it will become visible later when the window manager | |
5730 | finishes with it. */ | |
5731 | ||
ec48c3a7 | 5732 | void |
ee78dc32 GV |
5733 | x_make_frame_visible (f) |
5734 | struct frame *f; | |
5735 | { | |
7f5d1df8 GV |
5736 | Lisp_Object type; |
5737 | ||
ee78dc32 GV |
5738 | BLOCK_INPUT; |
5739 | ||
7f5d1df8 GV |
5740 | type = x_icon_type (f); |
5741 | if (!NILP (type)) | |
5742 | x_bitmap_icon (f, type); | |
5743 | ||
ee78dc32 GV |
5744 | if (! FRAME_VISIBLE_P (f)) |
5745 | { | |
5746 | /* We test FRAME_GARBAGED_P here to make sure we don't | |
5747 | call x_set_offset a second time | |
5748 | if we get to x_make_frame_visible a second time | |
5749 | before the window gets really visible. */ | |
5750 | if (! FRAME_ICONIFIED_P (f) | |
fbd6baed | 5751 | && ! f->output_data.w32->asked_for_visible) |
8958048c EZ |
5752 | { |
5753 | RECT workarea_rect; | |
5754 | RECT window_rect; | |
5755 | ||
5756 | /* Adjust vertical window position in order to avoid being | |
5757 | covered by a task bar placed at the bottom of the desktop. */ | |
5758 | SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea_rect, 0); | |
5759 | GetWindowRect(FRAME_W32_WINDOW(f), &window_rect); | |
5760 | if (window_rect.bottom > workarea_rect.bottom | |
5761 | && window_rect.top > workarea_rect.top) | |
5762 | f->top_pos = max (window_rect.top | |
5763 | - window_rect.bottom + workarea_rect.bottom, | |
5764 | workarea_rect.top); | |
5765 | ||
5766 | x_set_offset (f, f->left_pos, f->top_pos, 0); | |
5767 | } | |
ee78dc32 | 5768 | |
fbd6baed | 5769 | f->output_data.w32->asked_for_visible = 1; |
52cf03a1 | 5770 | |
12f71857 JR |
5771 | /* The first of these seems to give more expected behavior, but |
5772 | was added as a commented out line in Sept 1997, with the | |
5773 | second version remaining uncommented. There may have been | |
5774 | some problem with it that led to it not being enabled, | |
5775 | so the old version remains commented out below in case we | |
5776 | decide we need to go back to it [23.0.60 2008-06-09]. */ | |
5777 | my_show_window (f, FRAME_W32_WINDOW (f), | |
5778 | f->async_iconified ? SW_RESTORE : SW_SHOW); | |
5779 | /* my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL); */ | |
ee78dc32 GV |
5780 | } |
5781 | ||
5782 | /* Synchronize to ensure Emacs knows the frame is visible | |
5783 | before we do anything else. We do this loop with input not blocked | |
5784 | so that incoming events are handled. */ | |
5785 | { | |
5786 | Lisp_Object frame; | |
791f420f | 5787 | int count; |
ee78dc32 GV |
5788 | |
5789 | /* This must come after we set COUNT. */ | |
5790 | UNBLOCK_INPUT; | |
5791 | ||
5792 | XSETFRAME (frame, f); | |
5793 | ||
791f420f JR |
5794 | /* Wait until the frame is visible. Process X events until a |
5795 | MapNotify event has been seen, or until we think we won't get a | |
5796 | MapNotify at all.. */ | |
5797 | for (count = input_signal_count + 10; | |
5798 | input_signal_count < count && !FRAME_VISIBLE_P (f);) | |
ee78dc32 | 5799 | { |
791f420f | 5800 | /* Force processing of queued events. */ |
01b220b6 | 5801 | /* TODO: x_sync equivalent? */ |
791f420f | 5802 | |
ee78dc32 GV |
5803 | /* Machines that do polling rather than SIGIO have been observed |
5804 | to go into a busy-wait here. So we'll fake an alarm signal | |
5805 | to let the handler know that there's something to be read. | |
5806 | We used to raise a real alarm, but it seems that the handler | |
5807 | isn't always enabled here. This is probably a bug. */ | |
5808 | if (input_polling_used ()) | |
5809 | { | |
5810 | /* It could be confusing if a real alarm arrives while processing | |
5811 | the fake one. Turn it off and let the handler reset it. */ | |
a9b4e0ec AI |
5812 | int old_poll_suppress_count = poll_suppress_count; |
5813 | poll_suppress_count = 1; | |
5814 | poll_for_input_1 (); | |
5815 | poll_suppress_count = old_poll_suppress_count; | |
ee78dc32 | 5816 | } |
ee78dc32 GV |
5817 | } |
5818 | FRAME_SAMPLE_VISIBILITY (f); | |
5819 | } | |
5820 | } | |
5821 | ||
5822 | /* Change from mapped state to withdrawn state. */ | |
5823 | ||
5824 | /* Make the frame visible (mapped and not iconified). */ | |
5825 | ||
5826 | x_make_frame_invisible (f) | |
5827 | struct frame *f; | |
5828 | { | |
ee78dc32 | 5829 | /* Don't keep the highlight on an invisible frame. */ |
4baaed0f KS |
5830 | if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f) |
5831 | FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0; | |
d67d1627 | 5832 | |
ee78dc32 | 5833 | BLOCK_INPUT; |
d67d1627 | 5834 | |
689004fa | 5835 | my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE); |
d67d1627 | 5836 | |
ee78dc32 GV |
5837 | /* We can't distinguish this from iconification |
5838 | just by the event that we get from the server. | |
5839 | So we can't win using the usual strategy of letting | |
5840 | FRAME_SAMPLE_VISIBILITY set this. So do it by hand, | |
5841 | and synchronize with the server to make sure we agree. */ | |
5842 | f->visible = 0; | |
5843 | FRAME_ICONIFIED_P (f) = 0; | |
5844 | f->async_visible = 0; | |
5845 | f->async_iconified = 0; | |
d67d1627 | 5846 | |
ee78dc32 GV |
5847 | UNBLOCK_INPUT; |
5848 | } | |
5849 | ||
5850 | /* Change window state from mapped to iconified. */ | |
5851 | ||
52cf03a1 GV |
5852 | void |
5853 | x_iconify_frame (f) | |
ee78dc32 GV |
5854 | struct frame *f; |
5855 | { | |
7f5d1df8 | 5856 | Lisp_Object type; |
ee78dc32 GV |
5857 | |
5858 | /* Don't keep the highlight on an invisible frame. */ | |
4baaed0f KS |
5859 | if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f) |
5860 | FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0; | |
ee78dc32 GV |
5861 | |
5862 | if (f->async_iconified) | |
5863 | return; | |
5864 | ||
5865 | BLOCK_INPUT; | |
5866 | ||
7f5d1df8 GV |
5867 | type = x_icon_type (f); |
5868 | if (!NILP (type)) | |
5869 | x_bitmap_icon (f, type); | |
5870 | ||
689004fa | 5871 | /* Simulate the user minimizing the frame. */ |
4934bcdd | 5872 | SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0); |
ee78dc32 GV |
5873 | |
5874 | UNBLOCK_INPUT; | |
5875 | } | |
c2cc16fa | 5876 | |
ee78dc32 | 5877 | \f |
25badd7a | 5878 | /* Free X resources of frame F. */ |
ee78dc32 | 5879 | |
25badd7a AI |
5880 | void |
5881 | x_free_frame_resources (f) | |
ee78dc32 GV |
5882 | struct frame *f; |
5883 | { | |
fbd6baed | 5884 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
ee78dc32 GV |
5885 | |
5886 | BLOCK_INPUT; | |
5887 | ||
ef39ccbb KH |
5888 | /* We must free faces before destroying windows because some |
5889 | font-driver (e.g. xft) access a window while finishing a | |
5890 | face. */ | |
5891 | if (FRAME_FACE_CACHE (f)) | |
5892 | free_frame_faces (f); | |
027f6f90 | 5893 | |
25badd7a AI |
5894 | if (FRAME_W32_WINDOW (f)) |
5895 | my_destroy_window (f, FRAME_W32_WINDOW (f)); | |
d67d1627 | 5896 | |
ee78dc32 | 5897 | free_frame_menubar (f); |
ee78dc32 | 5898 | |
5bcee7ef KL |
5899 | unload_color (f, FRAME_FOREGROUND_PIXEL (f)); |
5900 | unload_color (f, FRAME_BACKGROUND_PIXEL (f)); | |
25badd7a AI |
5901 | unload_color (f, f->output_data.w32->cursor_pixel); |
5902 | unload_color (f, f->output_data.w32->cursor_foreground_pixel); | |
5903 | unload_color (f, f->output_data.w32->border_pixel); | |
5904 | unload_color (f, f->output_data.w32->mouse_pixel); | |
c2cc16fa JR |
5905 | if (f->output_data.w32->white_relief.allocated_p) |
5906 | unload_color (f, f->output_data.w32->white_relief.pixel); | |
5907 | if (f->output_data.w32->black_relief.allocated_p) | |
5908 | unload_color (f, f->output_data.w32->black_relief.pixel); | |
5909 | ||
25badd7a AI |
5910 | if (FRAME_FACE_CACHE (f)) |
5911 | free_frame_faces (f); | |
d67d1627 | 5912 | |
fbd6baed | 5913 | xfree (f->output_data.w32); |
25badd7a | 5914 | f->output_data.w32 = NULL; |
d67d1627 | 5915 | |
fbd6baed GV |
5916 | if (f == dpyinfo->w32_focus_frame) |
5917 | dpyinfo->w32_focus_frame = 0; | |
5918 | if (f == dpyinfo->w32_focus_event_frame) | |
5919 | dpyinfo->w32_focus_event_frame = 0; | |
4baaed0f KS |
5920 | if (f == dpyinfo->x_highlight_frame) |
5921 | dpyinfo->x_highlight_frame = 0; | |
ee78dc32 | 5922 | |
ee78dc32 GV |
5923 | if (f == dpyinfo->mouse_face_mouse_frame) |
5924 | { | |
5925 | dpyinfo->mouse_face_beg_row | |
5926 | = dpyinfo->mouse_face_beg_col = -1; | |
5927 | dpyinfo->mouse_face_end_row | |
5928 | = dpyinfo->mouse_face_end_col = -1; | |
5929 | dpyinfo->mouse_face_window = Qnil; | |
25badd7a AI |
5930 | dpyinfo->mouse_face_deferred_gc = 0; |
5931 | dpyinfo->mouse_face_mouse_frame = 0; | |
ee78dc32 GV |
5932 | } |
5933 | ||
5934 | UNBLOCK_INPUT; | |
5935 | } | |
25badd7a AI |
5936 | |
5937 | ||
5938 | /* Destroy the window of frame F. */ | |
4a418b10 | 5939 | void |
25badd7a AI |
5940 | x_destroy_window (f) |
5941 | struct frame *f; | |
5942 | { | |
5943 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
5944 | ||
5945 | x_free_frame_resources (f); | |
25badd7a AI |
5946 | dpyinfo->reference_count--; |
5947 | } | |
c2cc16fa | 5948 | |
ee78dc32 GV |
5949 | \f |
5950 | /* Setting window manager hints. */ | |
5951 | ||
5952 | /* Set the normal size hints for the window manager, for frame F. | |
5953 | FLAGS is the flags word to use--or 0 meaning preserve the flags | |
5954 | that the window now has. | |
5955 | If USER_POSITION is nonzero, we set the USPosition | |
5956 | flag (this is useful when FLAGS is 0). */ | |
791f420f | 5957 | void |
ee78dc32 GV |
5958 | x_wm_set_size_hint (f, flags, user_position) |
5959 | struct frame *f; | |
5960 | long flags; | |
5961 | int user_position; | |
5962 | { | |
fbd6baed | 5963 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 | 5964 | |
97c23857 | 5965 | enter_crit (); |
ee78dc32 | 5966 | |
62e50ec6 KS |
5967 | SetWindowLong (window, WND_FONTWIDTH_INDEX, FRAME_COLUMN_WIDTH (f)); |
5968 | SetWindowLong (window, WND_LINEHEIGHT_INDEX, FRAME_LINE_HEIGHT (f)); | |
5969 | SetWindowLong (window, WND_BORDER_INDEX, FRAME_INTERNAL_BORDER_WIDTH (f)); | |
5970 | SetWindowLong (window, WND_SCROLLBAR_INDEX, f->scroll_bar_actual_width); | |
ee78dc32 | 5971 | |
97c23857 | 5972 | leave_crit (); |
ee78dc32 GV |
5973 | } |
5974 | ||
5975 | /* Window manager things */ | |
c65fd370 RS |
5976 | void |
5977 | x_wm_set_icon_position (f, icon_x, icon_y) | |
ee78dc32 GV |
5978 | struct frame *f; |
5979 | int icon_x, icon_y; | |
5980 | { | |
5981 | #if 0 | |
fbd6baed | 5982 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 GV |
5983 | |
5984 | f->display.x->wm_hints.flags |= IconPositionHint; | |
5985 | f->display.x->wm_hints.icon_x = icon_x; | |
5986 | f->display.x->wm_hints.icon_y = icon_y; | |
5987 | ||
5988 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints); | |
5989 | #endif | |
5990 | } | |
5991 | ||
c2cc16fa | 5992 | \f |
791f420f JR |
5993 | /*********************************************************************** |
5994 | Initialization | |
5995 | ***********************************************************************/ | |
ee78dc32 | 5996 | |
fbd6baed | 5997 | static int w32_initialized = 0; |
ee78dc32 | 5998 | |
f7737f5d JR |
5999 | void |
6000 | w32_initialize_display_info (display_name) | |
6001 | Lisp_Object display_name; | |
6002 | { | |
6003 | struct w32_display_info *dpyinfo = &one_w32_display_info; | |
6004 | ||
6005 | bzero (dpyinfo, sizeof (*dpyinfo)); | |
6006 | ||
6007 | /* Put it on w32_display_name_list. */ | |
6008 | w32_display_name_list = Fcons (Fcons (display_name, Qnil), | |
6009 | w32_display_name_list); | |
6010 | dpyinfo->name_list_element = XCAR (w32_display_name_list); | |
d67d1627 | 6011 | |
f7737f5d | 6012 | dpyinfo->w32_id_name |
d5db4077 KR |
6013 | = (char *) xmalloc (SCHARS (Vinvocation_name) |
6014 | + SCHARS (Vsystem_name) | |
f7737f5d JR |
6015 | + 2); |
6016 | sprintf (dpyinfo->w32_id_name, "%s@%s", | |
d5db4077 | 6017 | SDATA (Vinvocation_name), SDATA (Vsystem_name)); |
f7737f5d JR |
6018 | |
6019 | /* Default Console mode values - overridden when running in GUI mode | |
6020 | with values obtained from system metrics. */ | |
6021 | dpyinfo->resx = 1; | |
6022 | dpyinfo->resy = 1; | |
f7737f5d JR |
6023 | dpyinfo->n_planes = 1; |
6024 | dpyinfo->n_cbits = 4; | |
6025 | dpyinfo->n_fonts = 0; | |
6026 | dpyinfo->smallest_font_height = 1; | |
6027 | dpyinfo->smallest_char_width = 1; | |
6028 | ||
6029 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
6030 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
6031 | dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; | |
6032 | dpyinfo->mouse_face_window = Qnil; | |
9f5a911b | 6033 | dpyinfo->mouse_face_overlay = Qnil; |
3d26a7c2 | 6034 | dpyinfo->mouse_face_hidden = 0; |
2bf04b9d JR |
6035 | |
6036 | dpyinfo->vertical_scroll_bar_cursor = w32_load_cursor (IDC_ARROW); | |
01b220b6 | 6037 | /* TODO: dpyinfo->gray */ |
f7737f5d JR |
6038 | |
6039 | } | |
6040 | ||
c13a8a91 JB |
6041 | /* Create an xrdb-style database of resources to supercede registry settings. |
6042 | The database is just a concatenation of C strings, finished by an additional | |
decb374a | 6043 | \0. The strings are submitted to some basic normalization, so |
c13a8a91 JB |
6044 | |
6045 | [ *]option[ *]:[ *]value... | |
6046 | ||
6047 | becomes | |
6048 | ||
6049 | option:value... | |
6050 | ||
6051 | but any whitespace following value is not removed. */ | |
6052 | ||
6053 | static char * | |
6054 | w32_make_rdb (xrm_option) | |
6055 | char *xrm_option; | |
6056 | { | |
6057 | char *buffer = xmalloc (strlen (xrm_option) + 2); | |
6058 | char *current = buffer; | |
6059 | char ch; | |
6060 | int in_option = 1; | |
6061 | int before_value = 0; | |
6062 | ||
6063 | do { | |
6064 | ch = *xrm_option++; | |
6065 | ||
6066 | if (ch == '\n') | |
6067 | { | |
6068 | *current++ = '\0'; | |
6069 | in_option = 1; | |
6070 | before_value = 0; | |
6071 | } | |
6072 | else if (ch != ' ') | |
6073 | { | |
6074 | *current++ = ch; | |
6075 | if (in_option && (ch == ':')) | |
6076 | { | |
6077 | in_option = 0; | |
6078 | before_value = 1; | |
6079 | } | |
6080 | else if (before_value) | |
6081 | { | |
6082 | before_value = 0; | |
6083 | } | |
6084 | } | |
6085 | else if (!(in_option || before_value)) | |
6086 | { | |
6087 | *current++ = ch; | |
6088 | } | |
6089 | } while (ch); | |
6090 | ||
6091 | *current = '\0'; | |
6092 | ||
6093 | return buffer; | |
6094 | } | |
6095 | ||
4a418b10 JR |
6096 | void |
6097 | x_flush (struct frame * f) | |
6098 | { /* Nothing to do */ } | |
6099 | ||
6100 | ||
6101 | extern frame_parm_handler w32_frame_parm_handlers[]; | |
6102 | ||
6103 | static struct redisplay_interface w32_redisplay_interface = | |
6104 | { | |
6105 | w32_frame_parm_handlers, | |
6106 | x_produce_glyphs, | |
6107 | x_write_glyphs, | |
6108 | x_insert_glyphs, | |
6109 | x_clear_end_of_line, | |
6110 | x_scroll_run, | |
6111 | x_after_update_window_line, | |
6112 | x_update_window_begin, | |
6113 | x_update_window_end, | |
6114 | x_cursor_to, | |
6115 | x_flush, | |
6116 | 0, /* flush_display_optional */ | |
6117 | x_clear_window_mouse_face, | |
e5e29349 | 6118 | x_get_glyph_overhangs, |
4a418b10 JR |
6119 | x_fix_overlapping_area, |
6120 | w32_draw_fringe_bitmap, | |
6121 | w32_define_fringe_bitmap, | |
6122 | w32_destroy_fringe_bitmap, | |
cf907d69 | 6123 | w32_compute_glyph_string_overhangs, |
4a418b10 JR |
6124 | x_draw_glyph_string, |
6125 | w32_define_frame_cursor, | |
6126 | w32_clear_frame_area, | |
6127 | w32_draw_window_cursor, | |
6128 | w32_draw_vertical_window_border, | |
6129 | w32_shift_glyphs_for_insert | |
6130 | }; | |
6131 | ||
6132 | static void x_delete_terminal (struct terminal *term); | |
6133 | ||
6134 | static struct terminal * | |
6135 | w32_create_terminal (struct w32_display_info *dpyinfo) | |
6136 | { | |
6137 | struct terminal *terminal; | |
def7fa34 | 6138 | |
4a418b10 JR |
6139 | terminal = create_terminal (); |
6140 | ||
6141 | terminal->type = output_w32; | |
6142 | terminal->display_info.w32 = dpyinfo; | |
6143 | dpyinfo->terminal = terminal; | |
6144 | ||
6145 | /* MSVC does not type K&R functions with no arguments correctly, and | |
6146 | so we must explicitly cast them. */ | |
6147 | terminal->clear_frame_hook = x_clear_frame; | |
6148 | terminal->ins_del_lines_hook = x_ins_del_lines; | |
6149 | terminal->delete_glyphs_hook = x_delete_glyphs; | |
6150 | terminal->ring_bell_hook = w32_ring_bell; | |
6151 | terminal->reset_terminal_modes_hook = w32_reset_terminal_modes; | |
6152 | terminal->set_terminal_modes_hook = w32_set_terminal_modes; | |
6153 | terminal->update_begin_hook = x_update_begin; | |
6154 | terminal->update_end_hook = x_update_end; | |
6155 | terminal->set_terminal_window_hook = w32_set_terminal_window; | |
6156 | terminal->read_socket_hook = w32_read_socket; | |
6157 | terminal->frame_up_to_date_hook = w32_frame_up_to_date; | |
6158 | terminal->mouse_position_hook = w32_mouse_position; | |
6159 | terminal->frame_rehighlight_hook = w32_frame_rehighlight; | |
6160 | terminal->frame_raise_lower_hook = w32_frame_raise_lower; | |
6161 | // terminal->fullscreen_hook = XTfullscreen_hook; | |
6162 | terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar; | |
6163 | terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars; | |
6164 | terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar; | |
6165 | terminal->judge_scroll_bars_hook = w32_judge_scroll_bars; | |
6166 | ||
6167 | terminal->delete_frame_hook = x_destroy_window; | |
6168 | terminal->delete_terminal_hook = x_delete_terminal; | |
def7fa34 | 6169 | |
4a418b10 JR |
6170 | terminal->rif = &w32_redisplay_interface; |
6171 | terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */ | |
6172 | terminal->char_ins_del_ok = 1; | |
6173 | terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */ | |
6174 | terminal->fast_clear_end_of_line = 1; /* X does this well. */ | |
6175 | terminal->memory_below_frame = 0; /* We don't remember what scrolls | |
6176 | off the bottom. */ | |
6177 | ||
1526bc23 JR |
6178 | /* We don't yet support separate terminals on W32, so don't try to share |
6179 | keyboards between virtual terminals that are on the same physical | |
6180 | terminal like X does. */ | |
6181 | terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); | |
6182 | init_kboard (terminal->kboard); | |
70b8d0a4 | 6183 | terminal->kboard->Vwindow_system = intern ("w32"); |
1526bc23 JR |
6184 | terminal->kboard->next_kboard = all_kboards; |
6185 | all_kboards = terminal->kboard; | |
6186 | /* Don't let the initial kboard remain current longer than necessary. | |
6187 | That would cause problems if a file loaded on startup tries to | |
6188 | prompt in the mini-buffer. */ | |
6189 | if (current_kboard == initial_kboard) | |
6190 | current_kboard = terminal->kboard; | |
6191 | terminal->kboard->reference_count++; | |
1526bc23 | 6192 | |
4a418b10 JR |
6193 | return terminal; |
6194 | } | |
6195 | ||
6196 | static void | |
6197 | x_delete_terminal (struct terminal *terminal) | |
6198 | { | |
6199 | struct w32_display_info *dpyinfo = terminal->display_info.w32; | |
6200 | int i; | |
6201 | ||
e2749141 | 6202 | /* Protect against recursive calls. delete_frame in |
4a418b10 | 6203 | delete_terminal calls us back when it deletes our last frame. */ |
adc54316 | 6204 | if (!terminal->name) |
4a418b10 JR |
6205 | return; |
6206 | ||
6207 | BLOCK_INPUT; | |
4a418b10 JR |
6208 | |
6209 | x_delete_display (dpyinfo); | |
6210 | UNBLOCK_INPUT; | |
6211 | } | |
6212 | ||
fbd6baed GV |
6213 | struct w32_display_info * |
6214 | w32_term_init (display_name, xrm_option, resource_name) | |
ee78dc32 GV |
6215 | Lisp_Object display_name; |
6216 | char *xrm_option; | |
6217 | char *resource_name; | |
6218 | { | |
fbd6baed | 6219 | struct w32_display_info *dpyinfo; |
4a418b10 | 6220 | struct terminal *terminal; |
ee78dc32 | 6221 | HDC hdc; |
d67d1627 | 6222 | |
ee78dc32 | 6223 | BLOCK_INPUT; |
d67d1627 | 6224 | |
fbd6baed | 6225 | if (!w32_initialized) |
ee78dc32 | 6226 | { |
fbd6baed GV |
6227 | w32_initialize (); |
6228 | w32_initialized = 1; | |
ee78dc32 | 6229 | } |
d67d1627 | 6230 | |
f7737f5d | 6231 | w32_initialize_display_info (display_name); |
ee78dc32 | 6232 | |
f7737f5d | 6233 | dpyinfo = &one_w32_display_info; |
4a418b10 JR |
6234 | terminal = w32_create_terminal (dpyinfo); |
6235 | ||
6236 | /* Set the name of the terminal. */ | |
6237 | terminal->name = (char *) xmalloc (SBYTES (display_name) + 1); | |
6238 | strncpy (terminal->name, SDATA (display_name), SBYTES (display_name)); | |
6239 | terminal->name[SBYTES (display_name)] = 0; | |
8c3b00cb | 6240 | |
c13a8a91 JB |
6241 | dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL; |
6242 | ||
8c3b00cb AI |
6243 | /* Put this display on the chain. */ |
6244 | dpyinfo->next = x_display_list; | |
6245 | x_display_list = dpyinfo; | |
d67d1627 | 6246 | |
cb4a3e42 | 6247 | hdc = GetDC (NULL); |
791f420f | 6248 | |
ee78dc32 GV |
6249 | dpyinfo->root_window = GetDesktopWindow (); |
6250 | dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES); | |
6251 | dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL); | |
55689ab1 JR |
6252 | dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX); |
6253 | dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY); | |
52cf03a1 | 6254 | dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE; |
cb4a3e42 | 6255 | ReleaseDC (NULL, hdc); |
52cf03a1 GV |
6256 | |
6257 | /* initialise palette with white and black */ | |
6258 | { | |
316ed821 | 6259 | XColor color; |
55689ab1 JR |
6260 | w32_defined_color (0, "white", &color, 1); |
6261 | w32_defined_color (0, "black", &color, 1); | |
52cf03a1 GV |
6262 | } |
6263 | ||
543c3ccd JR |
6264 | /* Add the default keyboard. */ |
6265 | add_keyboard_wait_descriptor (0); | |
6266 | ||
b6ae1532 KS |
6267 | /* Create Fringe Bitmaps and store them for later use. |
6268 | ||
6269 | On W32, bitmaps are all unsigned short, as Windows requires | |
6270 | bitmap data to be Word aligned. For some reason they are | |
6271 | horizontally reflected compared to how they appear on X, so we | |
6272 | need to bitswap and convert to unsigned shorts before creating | |
6273 | the bitmaps. */ | |
09b69f01 | 6274 | w32_init_fringe (terminal->rif); |
f7737f5d | 6275 | |
ee78dc32 | 6276 | #ifdef F_SETOWN |
ee78dc32 | 6277 | fcntl (connection, F_SETOWN, getpid ()); |
ee78dc32 | 6278 | #endif /* ! defined (F_SETOWN) */ |
ee78dc32 GV |
6279 | |
6280 | #ifdef SIGIO | |
6281 | if (interrupt_input) | |
6282 | init_sigio (connection); | |
6283 | #endif /* ! defined (SIGIO) */ | |
6284 | ||
6285 | UNBLOCK_INPUT; | |
6286 | ||
6287 | return dpyinfo; | |
6288 | } | |
6289 | \f | |
6290 | /* Get rid of display DPYINFO, assuming all frames are already gone. */ | |
ee78dc32 GV |
6291 | void |
6292 | x_delete_display (dpyinfo) | |
fbd6baed | 6293 | struct w32_display_info *dpyinfo; |
ee78dc32 | 6294 | { |
fbd6baed | 6295 | /* Discard this display from w32_display_name_list and w32_display_list. |
ee78dc32 | 6296 | We can't use Fdelq because that can quit. */ |
fbd6baed | 6297 | if (! NILP (w32_display_name_list) |
8e713be6 KR |
6298 | && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element)) |
6299 | w32_display_name_list = XCDR (w32_display_name_list); | |
ee78dc32 GV |
6300 | else |
6301 | { | |
6302 | Lisp_Object tail; | |
6303 | ||
fbd6baed | 6304 | tail = w32_display_name_list; |
8e713be6 | 6305 | while (CONSP (tail) && CONSP (XCDR (tail))) |
ee78dc32 | 6306 | { |
f7737f5d | 6307 | if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element)) |
ee78dc32 | 6308 | { |
f3fbd155 | 6309 | XSETCDR (tail, XCDR (XCDR (tail))); |
ee78dc32 GV |
6310 | break; |
6311 | } | |
8e713be6 | 6312 | tail = XCDR (tail); |
ee78dc32 GV |
6313 | } |
6314 | } | |
6315 | ||
52cf03a1 GV |
6316 | /* free palette table */ |
6317 | { | |
fbd6baed | 6318 | struct w32_palette_entry * plist; |
52cf03a1 GV |
6319 | |
6320 | plist = dpyinfo->color_list; | |
6321 | while (plist) | |
6322 | { | |
fbd6baed | 6323 | struct w32_palette_entry * pentry = plist; |
52cf03a1 | 6324 | plist = plist->next; |
9127e20e | 6325 | xfree (pentry); |
52cf03a1 GV |
6326 | } |
6327 | dpyinfo->color_list = NULL; | |
6328 | if (dpyinfo->palette) | |
6329 | DeleteObject(dpyinfo->palette); | |
6330 | } | |
fbd6baed | 6331 | xfree (dpyinfo->w32_id_name); |
f7737f5d | 6332 | |
6b61353c | 6333 | w32_reset_fringes (); |
ee78dc32 GV |
6334 | } |
6335 | \f | |
fbd6baed | 6336 | /* Set up use of W32. */ |
ee78dc32 | 6337 | |
b0d4e0c7 | 6338 | DWORD WINAPI w32_msg_worker (void * arg); |
ee78dc32 | 6339 | |
1bb8a291 | 6340 | static void |
fbd6baed GV |
6341 | w32_initialize () |
6342 | { | |
ff90fbde JR |
6343 | HANDLE shell; |
6344 | HRESULT (WINAPI * set_user_model) (PCWSTR); | |
6345 | ||
ee78dc32 GV |
6346 | baud_rate = 19200; |
6347 | ||
abb15ebd JR |
6348 | w32_system_caret_hwnd = NULL; |
6349 | w32_system_caret_height = 0; | |
abb15ebd JR |
6350 | w32_system_caret_x = 0; |
6351 | w32_system_caret_y = 0; | |
6352 | ||
ff90fbde JR |
6353 | /* On Windows 7 and later, we need to set the user model ID |
6354 | to associate emacsclient launched files with Emacs frames | |
6355 | in the UI. */ | |
6356 | shell = GetModuleHandle ("shell32.dll"); | |
6357 | if (shell) | |
6358 | { | |
6359 | set_user_model | |
6360 | = (void *) GetProcAddress (shell, | |
6361 | "SetCurrentProcessExplicitAppUserModelID"); | |
6362 | ||
6363 | /* If the function is defined, then we are running on Windows 7 | |
6364 | or newer, and the UI uses this to group related windows | |
6365 | together. Since emacs, runemacs, emacsclient are related, we | |
6366 | want them grouped even though the executables are different, | |
6367 | so we need to set a consistent ID between them. */ | |
6368 | if (set_user_model) | |
6369 | set_user_model (L"GNU.Emacs"); | |
6370 | } | |
6371 | ||
c2baa2b6 JR |
6372 | /* Initialize w32_use_visible_system_caret based on whether a screen |
6373 | reader is in use. */ | |
6374 | if (!SystemParametersInfo (SPI_GETSCREENREADER, 0, | |
6375 | &w32_use_visible_system_caret, 0)) | |
6376 | w32_use_visible_system_caret = 0; | |
6377 | ||
791f420f JR |
6378 | last_tool_bar_item = -1; |
6379 | any_help_event_p = 0; | |
6380 | ||
689004fa GV |
6381 | /* Initialize input mode: interrupt_input off, no flow control, allow |
6382 | 8 bit character input, standard quit char. */ | |
6383 | Fset_input_mode (Qnil, Qnil, make_number (2), Qnil); | |
ee78dc32 | 6384 | |
13087e59 | 6385 | { |
46534e1e JR |
6386 | DWORD input_locale_id = (DWORD) GetKeyboardLayout (0); |
6387 | keyboard_codepage = codepage_for_locale ((LCID) (input_locale_id & 0xffff)); | |
13087e59 | 6388 | } |
ee78dc32 | 6389 | |
13087e59 JR |
6390 | /* Create the window thread - it will terminate itself when the app |
6391 | terminates */ | |
ee78dc32 GV |
6392 | init_crit (); |
6393 | ||
6394 | dwMainThreadId = GetCurrentThreadId (); | |
d67d1627 | 6395 | DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), |
ee78dc32 GV |
6396 | GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS); |
6397 | ||
6398 | /* Wait for thread to start */ | |
ee78dc32 GV |
6399 | { |
6400 | MSG msg; | |
6401 | ||
6402 | PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); | |
6403 | ||
d67d1627 | 6404 | hWindowsThread = CreateThread (NULL, 0, |
b0d4e0c7 JR |
6405 | w32_msg_worker, |
6406 | 0, 0, &dwWindowsThreadId); | |
ee78dc32 GV |
6407 | |
6408 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
6409 | } | |
d67d1627 | 6410 | |
52cf03a1 | 6411 | /* It is desirable that mainThread should have the same notion of |
e9e23e23 | 6412 | focus window and active window as windowsThread. Unfortunately, the |
52cf03a1 GV |
6413 | following call to AttachThreadInput, which should do precisely what |
6414 | we need, causes major problems when Emacs is linked as a console | |
6415 | program. Unfortunately, we have good reasons for doing that, so | |
e9e23e23 | 6416 | instead we need to send messages to windowsThread to make some API |
52cf03a1 | 6417 | calls for us (ones that affect, or depend on, the active/focus |
65a6ff8f | 6418 | window state.) */ |
52cf03a1 | 6419 | #ifdef ATTACH_THREADS |
e9e23e23 | 6420 | AttachThreadInput (dwMainThreadId, dwWindowsThreadId, TRUE); |
52cf03a1 | 6421 | #endif |
689004fa | 6422 | |
33e40ce7 | 6423 | /* Dynamically link to optional system components. */ |
689004fa | 6424 | { |
ff90fbde | 6425 | HMODULE user_lib = GetModuleHandle ("user32.dll"); |
689004fa | 6426 | |
41375f89 | 6427 | #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn) |
689004fa | 6428 | |
8b61a891 | 6429 | LOAD_PROC (user_lib, SetLayeredWindowAttributes); |
65a6ff8f | 6430 | |
689004fa GV |
6431 | #undef LOAD_PROC |
6432 | ||
33e40ce7 JR |
6433 | /* Ensure scrollbar handle is at least 5 pixels. */ |
6434 | vertical_scroll_bar_min_handle = 5; | |
689004fa GV |
6435 | |
6436 | /* For either kind of scroll bar, take account of the arrows; these | |
6437 | effectively form the border of the main scroll bar range. */ | |
6438 | vertical_scroll_bar_top_border = vertical_scroll_bar_bottom_border | |
6439 | = GetSystemMetrics (SM_CYVSCROLL); | |
6440 | } | |
ee78dc32 GV |
6441 | } |
6442 | ||
6443 | void | |
fbd6baed | 6444 | syms_of_w32term () |
ee78dc32 | 6445 | { |
fbd6baed GV |
6446 | staticpro (&w32_display_name_list); |
6447 | w32_display_name_list = Qnil; | |
ee78dc32 GV |
6448 | |
6449 | staticpro (&last_mouse_scroll_bar); | |
6450 | last_mouse_scroll_bar = Qnil; | |
6451 | ||
5f33dbf7 | 6452 | DEFSYM (Qvendor_specific_keysyms, "vendor-specific-keysyms"); |
52cf03a1 | 6453 | |
fbd6baed | 6454 | DEFVAR_INT ("w32-num-mouse-buttons", |
e597eb7d | 6455 | &w32_num_mouse_buttons, |
33f09670 | 6456 | doc: /* Number of physical mouse buttons. */); |
e597eb7d | 6457 | w32_num_mouse_buttons = 2; |
52cf03a1 | 6458 | |
fbd6baed GV |
6459 | DEFVAR_LISP ("w32-swap-mouse-buttons", |
6460 | &Vw32_swap_mouse_buttons, | |
33f09670 JR |
6461 | doc: /* Swap the mapping of middle and right mouse buttons. |
6462 | When nil, middle button is mouse-2 and right button is mouse-3. */); | |
fbd6baed | 6463 | Vw32_swap_mouse_buttons = Qnil; |
689004fa GV |
6464 | |
6465 | DEFVAR_LISP ("w32-grab-focus-on-raise", | |
6466 | &Vw32_grab_focus_on_raise, | |
33f09670 JR |
6467 | doc: /* Raised frame grabs input focus. |
6468 | When t, `raise-frame' grabs input focus as well. This fits well | |
6469 | with the normal Windows click-to-focus policy, but might not be | |
6470 | desirable when using a point-to-focus policy. */); | |
689004fa GV |
6471 | Vw32_grab_focus_on_raise = Qt; |
6472 | ||
6473 | DEFVAR_LISP ("w32-capslock-is-shiftlock", | |
6474 | &Vw32_capslock_is_shiftlock, | |
33f09670 JR |
6475 | doc: /* Apply CapsLock state to non character input keys. |
6476 | When nil, CapsLock only affects normal character input keys. */); | |
689004fa | 6477 | Vw32_capslock_is_shiftlock = Qnil; |
ef0e360f GV |
6478 | |
6479 | DEFVAR_LISP ("w32-recognize-altgr", | |
6480 | &Vw32_recognize_altgr, | |
33f09670 JR |
6481 | doc: /* Recognize right-alt and left-ctrl as AltGr. |
6482 | When nil, the right-alt and left-ctrl key combination is | |
d67d1627 | 6483 | interpreted normally. */); |
ef0e360f | 6484 | Vw32_recognize_altgr = Qt; |
bc6af935 | 6485 | |
99558ce8 JR |
6486 | DEFVAR_BOOL ("w32-use-visible-system-caret", |
6487 | &w32_use_visible_system_caret, | |
6488 | doc: /* Flag to make the system caret visible. | |
6489 | When this is non-nil, Emacs will indicate the position of point by | |
6490 | using the system caret instead of drawing its own cursor. Some screen | |
6491 | reader software does not track the system cursor properly when it is | |
6492 | invisible, and gets confused by Emacs drawing its own cursor, so this | |
d67d1627 | 6493 | variable is initialized to t when Emacs detects that screen reader |
99558ce8 JR |
6494 | software is running as it starts up. |
6495 | ||
6496 | When this variable is set, other variables affecting the appearance of | |
6497 | the cursor have no effect. */); | |
6498 | ||
c2baa2b6 | 6499 | w32_use_visible_system_caret = 0; |
99558ce8 | 6500 | |
099b6577 EZ |
6501 | /* We don't yet support this, but defining this here avoids whining |
6502 | from cus-start.el and other places, like "M-x set-variable". */ | |
6503 | DEFVAR_BOOL ("x-use-underline-position-properties", | |
6504 | &x_use_underline_position_properties, | |
6505 | doc: /* *Non-nil means make use of UNDERLINE_POSITION font properties. | |
e1e4b63b | 6506 | A value of nil means ignore them. If you encounter fonts with bogus |
099b6577 | 6507 | UNDERLINE_POSITION font properties, for example 7x13 on XFree prior |
9f995a76 | 6508 | to 4.1, set this to nil. */); |
099b6577 EZ |
6509 | x_use_underline_position_properties = 0; |
6510 | ||
30f27523 KS |
6511 | DEFVAR_BOOL ("x-underline-at-descent-line", |
6512 | &x_underline_at_descent_line, | |
6513 | doc: /* *Non-nil means to draw the underline at the same place as the descent line. | |
e1e4b63b JB |
6514 | A value of nil means to draw the underline according to the value of the |
6515 | variable `x-use-underline-position-properties', which is usually at the | |
6516 | baseline level. The default value is nil. */); | |
30f27523 KS |
6517 | x_underline_at_descent_line = 0; |
6518 | ||
5bf04520 | 6519 | DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, |
33f09670 | 6520 | doc: /* If not nil, Emacs uses toolkit scroll bars. */); |
5bf04520 | 6521 | Vx_toolkit_scroll_bars = Qt; |
791f420f JR |
6522 | |
6523 | staticpro (&last_mouse_motion_frame); | |
6524 | last_mouse_motion_frame = Qnil; | |
ee78dc32 | 6525 | } |
6b61353c KH |
6526 | |
6527 | /* arch-tag: 5fa70624-ab86-499c-8a85-473958ee4646 | |
6528 | (do not change this comment) */ |