Commit | Line | Data |
---|---|---|
e9e23e23 | 1 | /* Implementation of GUI terminal on the Microsoft W32 API. |
c2cc16fa | 2 | Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001 |
9ef2e2cf | 3 | Free Software Foundation, Inc. |
ee78dc32 GV |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9ef2e2cf JR |
18 | along with GNU Emacs; see the file COPYING. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
1fb87c77 | 20 | Boston, MA 02111-1307, USA. */ |
ee78dc32 | 21 | |
ee78dc32 | 22 | #include <config.h> |
68c45bf0 | 23 | #include <signal.h> |
ee78dc32 | 24 | #include <stdio.h> |
791f420f | 25 | #include <stdlib.h> |
ee78dc32 | 26 | #include "lisp.h" |
2091aeb2 | 27 | #include "charset.h" |
ee78dc32 GV |
28 | #include "blockinput.h" |
29 | ||
e12ca9c2 | 30 | #include "w32heap.h" |
689004fa | 31 | #include "w32term.h" |
791f420f | 32 | #include "w32bdf.h" |
12857dfd | 33 | #include <shellapi.h> |
ee78dc32 GV |
34 | |
35 | #include "systty.h" | |
36 | #include "systime.h" | |
f7737f5d | 37 | #include "atimer.h" |
8feddab4 | 38 | #include "keymap.h" |
ee78dc32 GV |
39 | |
40 | #include <ctype.h> | |
41 | #include <errno.h> | |
42 | #include <setjmp.h> | |
43 | #include <sys/stat.h> | |
44 | ||
38006079 | 45 | #include "keyboard.h" |
ee78dc32 GV |
46 | #include "frame.h" |
47 | #include "dispextern.h" | |
93ff4395 | 48 | #include "fontset.h" |
ee78dc32 GV |
49 | #include "termhooks.h" |
50 | #include "termopts.h" | |
51 | #include "termchar.h" | |
52 | #include "gnu.h" | |
53 | #include "disptab.h" | |
54 | #include "buffer.h" | |
55 | #include "window.h" | |
ee78dc32 | 56 | #include "intervals.h" |
791f420f | 57 | #include "composite.h" |
ef0e360f | 58 | #include "coding.h" |
ee78dc32 | 59 | |
791f420f JR |
60 | #define abs(x) ((x) < 0 ? -(x) : (x)) |
61 | ||
62 | #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER)) | |
63 | ||
64 | \f | |
65 | /* Bitmaps for truncated lines. */ | |
66 | ||
67 | enum bitmap_type | |
68 | { | |
69 | NO_BITMAP, | |
70 | LEFT_TRUNCATION_BITMAP, | |
71 | RIGHT_TRUNCATION_BITMAP, | |
72 | OVERLAY_ARROW_BITMAP, | |
73 | CONTINUED_LINE_BITMAP, | |
74 | CONTINUATION_LINE_BITMAP, | |
75 | ZV_LINE_BITMAP | |
76 | }; | |
77 | ||
78 | /* Bitmaps are all unsigned short, as Windows requires bitmap data to | |
79 | be Word aligned. For some reason they are horizontally reflected | |
80 | compared to how they appear on X, so changes in xterm.c should be | |
81 | reflected here. */ | |
82 | ||
83 | /* Bitmap drawn to indicate lines not displaying text if | |
84 | `indicate-empty-lines' is non-nil. */ | |
85 | ||
86 | #define zv_width 8 | |
87 | #define zv_height 8 | |
88 | static unsigned short zv_bits[] = { | |
89 | 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00}; | |
f7737f5d | 90 | static HBITMAP zv_bmp; |
791f420f JR |
91 | |
92 | /* An arrow like this: `<-'. */ | |
93 | ||
94 | #define left_width 8 | |
95 | #define left_height 8 | |
96 | static unsigned short left_bits[] = { | |
97 | 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18}; | |
f7737f5d | 98 | static HBITMAP left_bmp; |
791f420f JR |
99 | |
100 | /* Right truncation arrow bitmap `->'. */ | |
101 | ||
102 | #define right_width 8 | |
103 | #define right_height 8 | |
104 | static unsigned short right_bits[] = { | |
105 | 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18}; | |
f7737f5d | 106 | static HBITMAP right_bmp; |
791f420f JR |
107 | |
108 | /* Marker for continued lines. */ | |
109 | ||
110 | #define continued_width 8 | |
111 | #define continued_height 8 | |
112 | static unsigned short continued_bits[] = { | |
113 | 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e}; | |
f7737f5d | 114 | static HBITMAP continued_bmp; |
791f420f JR |
115 | |
116 | /* Marker for continuation lines. */ | |
117 | ||
118 | #define continuation_width 8 | |
119 | #define continuation_height 8 | |
120 | static unsigned short continuation_bits[] = { | |
121 | 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c}; | |
f7737f5d | 122 | static HBITMAP continuation_bmp; |
791f420f JR |
123 | |
124 | /* Overlay arrow bitmap. */ | |
125 | ||
126 | #if 0 | |
127 | /* A bomb. */ | |
128 | #define ov_width 8 | |
129 | #define ov_height 8 | |
130 | static unsigned short ov_bits[] = { | |
131 | 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c}; | |
132 | #else | |
133 | /* A triangular arrow. */ | |
134 | #define ov_width 8 | |
135 | #define ov_height 8 | |
136 | static unsigned short ov_bits[] = { | |
137 | 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0}; | |
791f420f | 138 | #endif |
f7737f5d | 139 | static HBITMAP ov_bmp; |
791f420f JR |
140 | |
141 | extern Lisp_Object Qhelp_echo; | |
142 | ||
143 | \f | |
5bf04520 | 144 | /* Non-nil means Emacs uses toolkit scroll bars. */ |
791f420f | 145 | |
5bf04520 | 146 | Lisp_Object Vx_toolkit_scroll_bars; |
791f420f JR |
147 | |
148 | /* If a string, w32_read_socket generates an event to display that string. | |
149 | (The display is done in read_char.) */ | |
150 | ||
151 | static Lisp_Object help_echo; | |
158cba56 | 152 | static Lisp_Object help_echo_window; |
ec48c3a7 JR |
153 | static Lisp_Object help_echo_object; |
154 | static int help_echo_pos; | |
791f420f JR |
155 | |
156 | /* Temporary variable for w32_read_socket. */ | |
157 | ||
158 | static Lisp_Object previous_help_echo; | |
159 | ||
160 | /* Non-zero means that a HELP_EVENT has been generated since Emacs | |
161 | start. */ | |
162 | ||
163 | static int any_help_event_p; | |
164 | ||
165 | /* Non-zero means draw block and hollow cursor as wide as the glyph | |
166 | under it. For example, if a block cursor is over a tab, it will be | |
167 | drawn as wide as that tab on the display. */ | |
168 | ||
169 | int x_stretch_cursor_p; | |
170 | ||
9f5a911b JR |
171 | /* Non-zero means make use of UNDERLINE_POSITION font properties. */ |
172 | ||
173 | int x_use_underline_position_properties; | |
174 | ||
e7efd97e GV |
175 | extern unsigned int msh_mousewheel; |
176 | ||
ee78dc32 GV |
177 | extern void free_frame_menubar (); |
178 | ||
93ff4395 JR |
179 | extern void w32_menu_display_help (HMENU menu, UINT menu_item, UINT flags); |
180 | ||
9ef2e2cf JR |
181 | extern int w32_codepage_for_font (char *fontname); |
182 | ||
82f9d565 AI |
183 | extern glyph_metric *w32_BDF_TextMetric(bdffont *fontp, |
184 | unsigned char *text, int dim); | |
52cf03a1 GV |
185 | extern Lisp_Object Vwindow_system; |
186 | ||
ee78dc32 GV |
187 | #define x_any_window_to_frame x_window_to_frame |
188 | #define x_top_window_to_frame x_window_to_frame | |
189 | ||
190 | \f | |
fbd6baed GV |
191 | /* This is display since w32 does not support multiple ones. */ |
192 | struct w32_display_info one_w32_display_info; | |
8c3b00cb | 193 | struct w32_display_info *x_display_list; |
ee78dc32 GV |
194 | |
195 | /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE), | |
fbd6baed | 196 | one for each element of w32_display_list and in the same order. |
ee78dc32 GV |
197 | NAME is the name of the frame. |
198 | FONT-LIST-CACHE records previous values returned by x-list-fonts. */ | |
fbd6baed | 199 | Lisp_Object w32_display_name_list; |
ee78dc32 GV |
200 | |
201 | /* Frame being updated by update_frame. This is declared in term.c. | |
202 | This is set by update_begin and looked at by all the | |
fbd6baed | 203 | w32 functions. It is zero while not inside an update. |
791f420f | 204 | In that case, the w32 functions assume that `SELECTED_FRAME ()' |
ee78dc32 GV |
205 | is the frame to apply to. */ |
206 | extern struct frame *updating_frame; | |
207 | ||
208 | /* This is a frame waiting to be autoraised, within w32_read_socket. */ | |
209 | struct frame *pending_autoraise_frame; | |
210 | ||
ee78dc32 | 211 | /* Nominal cursor position -- where to draw output. |
791f420f JR |
212 | HPOS and VPOS are window relative glyph matrix coordinates. |
213 | X and Y are window relative pixel coordinates. */ | |
ee78dc32 | 214 | |
791f420f | 215 | struct cursor_pos output_cursor; |
ee78dc32 | 216 | |
abb15ebd JR |
217 | /* The handle of the frame that currently owns the system caret. */ |
218 | HWND w32_system_caret_hwnd; | |
219 | int w32_system_caret_width; | |
220 | int w32_system_caret_height; | |
221 | int w32_system_caret_x; | |
222 | int w32_system_caret_y; | |
223 | ||
484fa2c1 | 224 | /* Flag to enable Unicode output in case users wish to use programs |
cabb23bc GV |
225 | like Twinbridge on '95 rather than installed system level support |
226 | for Far East languages. */ | |
484fa2c1 | 227 | int w32_enable_unicode_output; |
cabb23bc | 228 | |
e9e23e23 GV |
229 | DWORD dwWindowsThreadId = 0; |
230 | HANDLE hWindowsThread = NULL; | |
ee78dc32 GV |
231 | DWORD dwMainThreadId = 0; |
232 | HANDLE hMainThread = NULL; | |
233 | ||
689004fa GV |
234 | #ifndef SIF_ALL |
235 | /* These definitions are new with Windows 95. */ | |
236 | #define SIF_RANGE 0x0001 | |
237 | #define SIF_PAGE 0x0002 | |
238 | #define SIF_POS 0x0004 | |
239 | #define SIF_DISABLENOSCROLL 0x0008 | |
240 | #define SIF_TRACKPOS 0x0010 | |
241 | #define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS) | |
242 | ||
243 | typedef struct tagSCROLLINFO | |
244 | { | |
245 | UINT cbSize; | |
246 | UINT fMask; | |
247 | int nMin; | |
248 | int nMax; | |
249 | UINT nPage; | |
250 | int nPos; | |
251 | int nTrackPos; | |
252 | } SCROLLINFO, FAR *LPSCROLLINFO; | |
253 | typedef SCROLLINFO CONST FAR *LPCSCROLLINFO; | |
254 | #endif /* SIF_ALL */ | |
255 | ||
256 | /* Dynamic linking to new proportional scroll bar functions. */ | |
257 | int (PASCAL *pfnSetScrollInfo) (HWND hwnd, int fnBar, LPSCROLLINFO lpsi, BOOL fRedraw); | |
258 | BOOL (PASCAL *pfnGetScrollInfo) (HWND hwnd, int fnBar, LPSCROLLINFO lpsi); | |
259 | ||
260 | int vertical_scroll_bar_min_handle; | |
261 | int vertical_scroll_bar_top_border; | |
262 | int vertical_scroll_bar_bottom_border; | |
263 | ||
264 | int last_scroll_bar_drag_pos; | |
265 | ||
ee78dc32 GV |
266 | /* Mouse movement. */ |
267 | ||
268 | /* Where the mouse was last time we reported a mouse event. */ | |
9ef2e2cf | 269 | |
791f420f | 270 | FRAME_PTR last_mouse_frame; |
ee78dc32 | 271 | static RECT last_mouse_glyph; |
791f420f | 272 | static Lisp_Object last_mouse_press_frame; |
ee78dc32 | 273 | |
fbd6baed | 274 | Lisp_Object Vw32_num_mouse_buttons; |
52cf03a1 | 275 | |
fbd6baed | 276 | Lisp_Object Vw32_swap_mouse_buttons; |
52cf03a1 | 277 | |
689004fa GV |
278 | /* Control whether x_raise_frame also sets input focus. */ |
279 | Lisp_Object Vw32_grab_focus_on_raise; | |
280 | ||
281 | /* Control whether Caps Lock affects non-ascii characters. */ | |
282 | Lisp_Object Vw32_capslock_is_shiftlock; | |
283 | ||
ef0e360f GV |
284 | /* Control whether right-alt and left-ctrl should be recognized as AltGr. */ |
285 | Lisp_Object Vw32_recognize_altgr; | |
286 | ||
ee78dc32 GV |
287 | /* The scroll bar in which the last motion event occurred. |
288 | ||
289 | If the last motion event occurred in a scroll bar, we set this | |
fbd6baed | 290 | so w32_mouse_position can know whether to report a scroll bar motion or |
ee78dc32 GV |
291 | an ordinary motion. |
292 | ||
293 | If the last motion event didn't occur in a scroll bar, we set this | |
fbd6baed | 294 | to Qnil, to tell w32_mouse_position to return an ordinary motion event. */ |
9ef2e2cf JR |
295 | static Lisp_Object last_mouse_scroll_bar; |
296 | static int last_mouse_scroll_bar_pos; | |
ee78dc32 | 297 | |
fbd6baed | 298 | /* This is a hack. We would really prefer that w32_mouse_position would |
ee78dc32 | 299 | return the time associated with the position it returns, but there |
9ef2e2cf | 300 | doesn't seem to be any way to wrest the time-stamp from the server |
ee78dc32 GV |
301 | along with the position query. So, we just keep track of the time |
302 | of the last movement we received, and return that in hopes that | |
303 | it's somewhat accurate. */ | |
ee78dc32 | 304 | |
9ef2e2cf JR |
305 | static Time last_mouse_movement_time; |
306 | ||
307 | /* Incremented by w32_read_socket whenever it really tries to read | |
308 | events. */ | |
a1b9438c | 309 | |
ee78dc32 GV |
310 | #ifdef __STDC__ |
311 | static int volatile input_signal_count; | |
312 | #else | |
313 | static int input_signal_count; | |
314 | #endif | |
315 | ||
316 | extern Lisp_Object Vcommand_line_args, Vsystem_name; | |
317 | ||
318 | extern Lisp_Object Qface, Qmouse_face; | |
319 | ||
38006079 | 320 | #ifndef USE_CRT_DLL |
ee78dc32 | 321 | extern int errno; |
38006079 | 322 | #endif |
ee78dc32 GV |
323 | |
324 | /* A mask of extra modifier bits to put into every keyboard char. */ | |
9ef2e2cf | 325 | |
ee78dc32 GV |
326 | extern int extra_keyboard_modifiers; |
327 | ||
791f420f JR |
328 | /* Enumeration for overriding/changing the face to use for drawing |
329 | glyphs in x_draw_glyphs. */ | |
330 | ||
331 | enum draw_glyphs_face | |
332 | { | |
333 | DRAW_NORMAL_TEXT, | |
334 | DRAW_INVERSE_VIDEO, | |
335 | DRAW_CURSOR, | |
336 | DRAW_MOUSE_FACE, | |
337 | DRAW_IMAGE_RAISED, | |
338 | DRAW_IMAGE_SUNKEN | |
339 | }; | |
340 | ||
38006079 | 341 | static void x_update_window_end P_ ((struct window *, int, int)); |
791f420f JR |
342 | static void frame_to_window_pixel_xy P_ ((struct window *, int *, int *)); |
343 | void w32_delete_display P_ ((struct w32_display_info *)); | |
344 | static int fast_find_position P_ ((struct window *, int, int *, int *, | |
9f5a911b JR |
345 | int *, int *, Lisp_Object)); |
346 | static int fast_find_string_pos P_ ((struct window *, int, Lisp_Object, | |
347 | int *, int *, int *, int *, int)); | |
791f420f JR |
348 | static void set_output_cursor P_ ((struct cursor_pos *)); |
349 | static struct glyph *x_y_to_hpos_vpos P_ ((struct window *, int, int, | |
9f5a911b | 350 | int *, int *, int *, int)); |
791f420f | 351 | static void note_mode_line_highlight P_ ((struct window *, int, int)); |
791f420f JR |
352 | static void note_mouse_highlight P_ ((struct frame *, int, int)); |
353 | static void note_tool_bar_highlight P_ ((struct frame *f, int, int)); | |
354 | static void w32_handle_tool_bar_click P_ ((struct frame *, | |
355 | struct input_event *)); | |
356 | static void show_mouse_face P_ ((struct w32_display_info *, | |
357 | enum draw_glyphs_face)); | |
9f5a911b JR |
358 | static int cursor_in_mouse_face_p P_ ((struct window *)); |
359 | static int clear_mouse_face P_ ((struct w32_display_info *)); | |
791f420f JR |
360 | |
361 | void x_lower_frame P_ ((struct frame *)); | |
362 | void x_scroll_bar_clear P_ ((struct frame *)); | |
363 | void x_wm_set_size_hint P_ ((struct frame *, long, int)); | |
364 | void x_raise_frame P_ ((struct frame *)); | |
365 | void x_set_window_size P_ ((struct frame *, int, int, int)); | |
366 | void x_wm_set_window_state P_ ((struct frame *, int)); | |
367 | void x_wm_set_icon_pixmap P_ ((struct frame *, int)); | |
368 | void w32_initialize P_ ((void)); | |
369 | static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); | |
370 | int x_compute_min_glyph_bounds P_ ((struct frame *)); | |
371 | static void x_draw_phys_cursor_glyph P_ ((struct window *, | |
372 | struct glyph_row *, | |
373 | enum draw_glyphs_face)); | |
374 | static void x_update_end P_ ((struct frame *)); | |
375 | static void w32_frame_up_to_date P_ ((struct frame *)); | |
791f420f JR |
376 | static void w32_set_terminal_modes P_ ((void)); |
377 | static void w32_reset_terminal_modes P_ ((void)); | |
378 | static void w32_cursor_to P_ ((int, int, int, int)); | |
379 | static void x_write_glyphs P_ ((struct glyph *, int)); | |
380 | static void x_clear_end_of_line P_ ((int)); | |
381 | static void x_clear_frame P_ ((void)); | |
382 | static void x_clear_cursor P_ ((struct window *)); | |
383 | static void frame_highlight P_ ((struct frame *)); | |
384 | static void frame_unhighlight P_ ((struct frame *)); | |
385 | static void w32_new_focus_frame P_ ((struct w32_display_info *, | |
386 | struct frame *)); | |
387 | static void w32_frame_rehighlight P_ ((struct frame *)); | |
388 | static void x_frame_rehighlight P_ ((struct w32_display_info *)); | |
389 | static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); | |
9ef2e2cf | 390 | static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int)); |
791f420f | 391 | static void expose_frame P_ ((struct frame *, int, int, int, int)); |
9f5a911b JR |
392 | static int expose_window_tree P_ ((struct window *, RECT *)); |
393 | static int expose_window P_ ((struct window *, RECT *)); | |
791f420f JR |
394 | static void expose_area P_ ((struct window *, struct glyph_row *, |
395 | RECT *, enum glyph_row_area)); | |
9f5a911b JR |
396 | static int expose_line P_ ((struct window *, struct glyph_row *, |
397 | RECT *)); | |
791f420f JR |
398 | void x_update_cursor P_ ((struct frame *, int)); |
399 | static void x_update_cursor_in_window_tree P_ ((struct window *, int)); | |
400 | static void x_update_window_cursor P_ ((struct window *, int)); | |
401 | static void x_erase_phys_cursor P_ ((struct window *)); | |
402 | void x_display_cursor P_ ((struct window *w, int, int, int, int, int)); | |
403 | void x_display_and_set_cursor P_ ((struct window *, int, int, int, int, int)); | |
404 | static void w32_draw_bitmap P_ ((struct window *, HDC hdc, struct glyph_row *, | |
405 | enum bitmap_type)); | |
c2cc16fa JR |
406 | static void w32_clip_to_row P_ ((struct window *, struct glyph_row *, |
407 | HDC, int)); | |
791f420f JR |
408 | static int x_phys_cursor_in_rect_p P_ ((struct window *, RECT *)); |
409 | static void x_draw_row_bitmaps P_ ((struct window *, struct glyph_row *)); | |
410 | static void note_overwritten_text_cursor P_ ((struct window *, int, int)); | |
791f420f | 411 | |
ee78dc32 GV |
412 | static Lisp_Object Qvendor_specific_keysyms; |
413 | ||
ee78dc32 | 414 | \f |
9ef2e2cf JR |
415 | /*********************************************************************** |
416 | Debugging | |
417 | ***********************************************************************/ | |
418 | ||
ee78dc32 | 419 | #if 0 |
9ef2e2cf JR |
420 | |
421 | /* This is a function useful for recording debugging information about | |
422 | the sequence of occurrences in this file. */ | |
ee78dc32 GV |
423 | |
424 | struct record | |
425 | { | |
426 | char *locus; | |
427 | int type; | |
428 | }; | |
429 | ||
430 | struct record event_record[100]; | |
431 | ||
432 | int event_record_index; | |
433 | ||
434 | record_event (locus, type) | |
435 | char *locus; | |
436 | int type; | |
437 | { | |
438 | if (event_record_index == sizeof (event_record) / sizeof (struct record)) | |
439 | event_record_index = 0; | |
440 | ||
441 | event_record[event_record_index].locus = locus; | |
442 | event_record[event_record_index].type = type; | |
443 | event_record_index++; | |
444 | } | |
445 | ||
446 | #endif /* 0 */ | |
447 | \f | |
791f420f JR |
448 | |
449 | void XChangeGC (void * ignore, XGCValues* gc, unsigned long mask, | |
450 | XGCValues *xgcv) | |
451 | { | |
452 | if (mask & GCForeground) | |
453 | gc->foreground = xgcv->foreground; | |
454 | if (mask & GCBackground) | |
455 | gc->background = xgcv->background; | |
456 | if (mask & GCFont) | |
457 | gc->font = xgcv->font; | |
458 | } | |
459 | ||
460 | XGCValues *XCreateGC (void * ignore, Window window, unsigned long mask, | |
461 | XGCValues *xgcv) | |
462 | { | |
463 | XGCValues *gc = (XGCValues *) xmalloc (sizeof (XGCValues)); | |
464 | bzero (gc, sizeof (XGCValues)); | |
465 | ||
466 | XChangeGC (ignore, gc, mask, xgcv); | |
467 | ||
468 | return gc; | |
469 | } | |
470 | ||
471 | void XGetGCValues (void* ignore, XGCValues *gc, | |
472 | unsigned long mask, XGCValues *xgcv) | |
473 | { | |
474 | XChangeGC (ignore, xgcv, mask, gc); | |
475 | } | |
476 | ||
791f420f JR |
477 | static void |
478 | w32_set_clip_rectangle (HDC hdc, RECT *rect) | |
479 | { | |
480 | if (rect) | |
481 | { | |
482 | HRGN clip_region = CreateRectRgnIndirect (rect); | |
483 | SelectClipRgn (hdc, clip_region); | |
484 | DeleteObject (clip_region); | |
485 | } | |
486 | else | |
487 | SelectClipRgn (hdc, NULL); | |
488 | } | |
489 | ||
791f420f JR |
490 | |
491 | /* Draw a hollow rectangle at the specified position. */ | |
492 | void | |
493 | w32_draw_rectangle (HDC hdc, XGCValues *gc, int x, int y, | |
494 | int width, int height) | |
495 | { | |
496 | HBRUSH hb, oldhb; | |
497 | HPEN hp, oldhp; | |
498 | ||
499 | hb = CreateSolidBrush (gc->background); | |
500 | hp = CreatePen (PS_SOLID, 0, gc->foreground); | |
501 | oldhb = SelectObject (hdc, hb); | |
502 | oldhp = SelectObject (hdc, hp); | |
503 | ||
504 | Rectangle (hdc, x, y, x + width, y + height); | |
505 | ||
506 | SelectObject (hdc, oldhb); | |
507 | SelectObject (hdc, oldhp); | |
508 | DeleteObject (hb); | |
509 | DeleteObject (hp); | |
510 | } | |
511 | ||
512 | /* Draw a filled rectangle at the specified position. */ | |
ee78dc32 | 513 | void |
00fe468b | 514 | w32_fill_rect (f, hdc, pix, lprect) |
ee78dc32 | 515 | FRAME_PTR f; |
00fe468b | 516 | HDC hdc; |
ee78dc32 GV |
517 | COLORREF pix; |
518 | RECT * lprect; | |
519 | { | |
ee78dc32 | 520 | HBRUSH hb; |
791f420f | 521 | |
ee78dc32 | 522 | hb = CreateSolidBrush (pix); |
ee78dc32 | 523 | FillRect (hdc, lprect, hb); |
ee78dc32 | 524 | DeleteObject (hb); |
ee78dc32 GV |
525 | } |
526 | ||
527 | void | |
fbd6baed | 528 | w32_clear_window (f) |
ee78dc32 GV |
529 | FRAME_PTR f; |
530 | { | |
531 | RECT rect; | |
00fe468b | 532 | HDC hdc = get_frame_dc (f); |
52cf03a1 | 533 | |
e4a52412 JR |
534 | /* Under certain conditions, this can be called at startup with |
535 | a console frame pointer before the GUI frame is created. An HDC | |
536 | of 0 indicates this. */ | |
537 | if (hdc) | |
538 | { | |
539 | GetClientRect (FRAME_W32_WINDOW (f), &rect); | |
540 | w32_clear_rect (f, hdc, &rect); | |
541 | } | |
542 | ||
00fe468b | 543 | release_frame_dc (f, hdc); |
ee78dc32 GV |
544 | } |
545 | ||
546 | \f | |
791f420f JR |
547 | /*********************************************************************** |
548 | Starting and ending an update | |
549 | ***********************************************************************/ | |
550 | ||
551 | /* Start an update of frame F. This function is installed as a hook | |
552 | for update_begin, i.e. it is called when update_begin is called. | |
553 | This function is called prior to calls to x_update_window_begin for | |
99012074 | 554 | each window being updated. */ |
ee78dc32 | 555 | |
96214669 | 556 | static void |
791f420f | 557 | x_update_begin (f) |
ee78dc32 GV |
558 | struct frame *f; |
559 | { | |
99012074 AI |
560 | struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); |
561 | ||
7e6ac5b9 AI |
562 | if (! FRAME_W32_P (f)) |
563 | return; | |
564 | ||
99012074 AI |
565 | /* Regenerate display palette before drawing if list of requested |
566 | colors has changed. */ | |
567 | if (display_info->regen_palette) | |
568 | { | |
569 | w32_regenerate_palette (f); | |
570 | display_info->regen_palette = FALSE; | |
571 | } | |
791f420f | 572 | } |
ee78dc32 | 573 | |
791f420f JR |
574 | |
575 | /* Start update of window W. Set the global variable updated_window | |
576 | to the window being updated and set output_cursor to the cursor | |
577 | position of W. */ | |
578 | ||
579 | static void | |
580 | x_update_window_begin (w) | |
581 | struct window *w; | |
582 | { | |
583 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
584 | struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); | |
585 | ||
586 | updated_window = w; | |
587 | set_output_cursor (&w->cursor); | |
ee78dc32 GV |
588 | |
589 | BLOCK_INPUT; | |
590 | ||
791f420f | 591 | if (f == display_info->mouse_face_mouse_frame) |
ee78dc32 GV |
592 | { |
593 | /* Don't do highlighting for mouse motion during the update. */ | |
791f420f | 594 | display_info->mouse_face_defer = 1; |
ee78dc32 | 595 | |
9ef2e2cf JR |
596 | /* If F needs to be redrawn, simply forget about any prior mouse |
597 | highlighting. */ | |
ee78dc32 | 598 | if (FRAME_GARBAGED_P (f)) |
791f420f JR |
599 | display_info->mouse_face_window = Qnil; |
600 | ||
ec48c3a7 JR |
601 | #if 0 /* Rows in a current matrix containing glyphs in mouse-face have |
602 | their mouse_face_p flag set, which means that they are always | |
603 | unequal to rows in a desired matrix which never have that | |
604 | flag set. So, rows containing mouse-face glyphs are never | |
605 | scrolled, and we don't have to switch the mouse highlight off | |
606 | here to prevent it from being scrolled. */ | |
607 | ||
791f420f JR |
608 | /* Can we tell that this update does not affect the window |
609 | where the mouse highlight is? If so, no need to turn off. | |
610 | Likewise, don't do anything if the frame is garbaged; | |
611 | in that case, the frame's current matrix that we would use | |
612 | is all wrong, and we will redisplay that line anyway. */ | |
613 | if (!NILP (display_info->mouse_face_window) | |
614 | && w == XWINDOW (display_info->mouse_face_window)) | |
ee78dc32 | 615 | { |
791f420f | 616 | int i; |
ee78dc32 | 617 | |
791f420f JR |
618 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
619 | if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) | |
ee78dc32 GV |
620 | break; |
621 | ||
791f420f JR |
622 | if (i < w->desired_matrix->nrows) |
623 | clear_mouse_face (display_info); | |
ee78dc32 | 624 | } |
ec48c3a7 | 625 | #endif /* 0 */ |
ee78dc32 GV |
626 | } |
627 | ||
628 | UNBLOCK_INPUT; | |
629 | } | |
630 | ||
791f420f JR |
631 | |
632 | /* Draw a vertical window border to the right of window W if W doesn't | |
633 | have vertical scroll bars. */ | |
634 | ||
96214669 | 635 | static void |
791f420f JR |
636 | x_draw_vertical_border (w) |
637 | struct window *w; | |
ee78dc32 | 638 | { |
791f420f JR |
639 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
640 | ||
641 | /* Redraw borders between horizontally adjacent windows. Don't | |
642 | do it for frames with vertical scroll bars because either the | |
643 | right scroll bar of a window, or the left scroll bar of its | |
644 | neighbor will suffice as a border. */ | |
645 | if (!WINDOW_RIGHTMOST_P (w) | |
646 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
647 | { | |
648 | RECT r; | |
00fe468b | 649 | HDC hdc; |
ee78dc32 | 650 | |
9f5a911b JR |
651 | window_box_edges (w, -1, (int *) &r.left, (int *) &r.top, |
652 | (int *) &r.right, (int *) &r.bottom); | |
791f420f JR |
653 | r.left = r.right + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f); |
654 | r.right = r.left + 1; | |
655 | r.bottom -= 1; | |
ee78dc32 | 656 | |
00fe468b | 657 | hdc = get_frame_dc (f); |
e4a52412 | 658 | w32_fill_rect (f, hdc, FRAME_FOREGROUND_PIXEL (f), &r); |
00fe468b | 659 | release_frame_dc (f, hdc); |
791f420f JR |
660 | } |
661 | } | |
ee78dc32 | 662 | |
791f420f | 663 | |
ec48c3a7 JR |
664 | /* End update of window W (which is equal to updated_window). |
665 | ||
666 | Draw vertical borders between horizontally adjacent windows, and | |
667 | display W's cursor if CURSOR_ON_P is non-zero. | |
668 | ||
669 | MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing | |
670 | glyphs in mouse-face were overwritten. In that case we have to | |
671 | make sure that the mouse-highlight is properly redrawn. | |
672 | ||
673 | W may be a menu bar pseudo-window in case we don't have X toolkit | |
674 | support. Such windows don't have a cursor, so don't display it | |
675 | here. */ | |
791f420f JR |
676 | |
677 | static void | |
ec48c3a7 | 678 | x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p) |
791f420f | 679 | struct window *w; |
ec48c3a7 | 680 | int cursor_on_p, mouse_face_overwritten_p; |
791f420f | 681 | { |
9f5a911b JR |
682 | struct w32_display_info *dpyinfo |
683 | = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); | |
684 | ||
791f420f JR |
685 | if (!w->pseudo_window_p) |
686 | { | |
687 | BLOCK_INPUT; | |
ec48c3a7 | 688 | |
791f420f JR |
689 | if (cursor_on_p) |
690 | x_display_and_set_cursor (w, 1, output_cursor.hpos, | |
691 | output_cursor.vpos, | |
692 | output_cursor.x, output_cursor.y); | |
c2cc16fa | 693 | |
791f420f JR |
694 | x_draw_vertical_border (w); |
695 | UNBLOCK_INPUT; | |
696 | } | |
9f5a911b JR |
697 | |
698 | /* If a row with mouse-face was overwritten, arrange for | |
699 | XTframe_up_to_date to redisplay the mouse highlight. */ | |
700 | if (mouse_face_overwritten_p) | |
701 | { | |
702 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
703 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
704 | dpyinfo->mouse_face_window = Qnil; | |
705 | } | |
706 | ||
791f420f JR |
707 | updated_window = NULL; |
708 | } | |
709 | ||
9ef2e2cf JR |
710 | |
711 | /* End update of frame F. This function is installed as a hook in | |
712 | update_end. */ | |
713 | ||
791f420f JR |
714 | static void |
715 | x_update_end (f) | |
716 | struct frame *f; | |
717 | { | |
7e6ac5b9 AI |
718 | if (! FRAME_W32_P (f)) |
719 | return; | |
720 | ||
791f420f JR |
721 | /* Mouse highlight may be displayed again. */ |
722 | FRAME_W32_DISPLAY_INFO (f)->mouse_face_defer = 0; | |
ee78dc32 GV |
723 | } |
724 | ||
9ef2e2cf | 725 | |
791f420f JR |
726 | /* This function is called from various places in xdisp.c whenever a |
727 | complete update has been performed. The global variable | |
728 | updated_window is not available here. */ | |
ee78dc32 | 729 | |
96214669 | 730 | static void |
fbd6baed | 731 | w32_frame_up_to_date (f) |
791f420f | 732 | struct frame *f; |
ee78dc32 | 733 | { |
791f420f | 734 | if (FRAME_W32_P (f)) |
ee78dc32 | 735 | { |
791f420f JR |
736 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
737 | if (dpyinfo->mouse_face_deferred_gc | |
738 | || f == dpyinfo->mouse_face_mouse_frame) | |
739 | { | |
740 | BLOCK_INPUT; | |
741 | if (dpyinfo->mouse_face_mouse_frame) | |
742 | note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, | |
743 | dpyinfo->mouse_face_mouse_x, | |
744 | dpyinfo->mouse_face_mouse_y); | |
745 | dpyinfo->mouse_face_deferred_gc = 0; | |
746 | UNBLOCK_INPUT; | |
747 | } | |
ee78dc32 GV |
748 | } |
749 | } | |
791f420f JR |
750 | |
751 | ||
752 | /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay | |
753 | arrow bitmaps, or clear the areas where they would be displayed | |
754 | before DESIRED_ROW is made current. The window being updated is | |
755 | found in updated_window. This function It is called from | |
756 | update_window_line only if it is known that there are differences | |
757 | between bitmaps to be drawn between current row and DESIRED_ROW. */ | |
758 | ||
759 | static void | |
760 | x_after_update_window_line (desired_row) | |
761 | struct glyph_row *desired_row; | |
762 | { | |
763 | struct window *w = updated_window; | |
764 | ||
765 | xassert (w); | |
766 | ||
767 | if (!desired_row->mode_line_p && !w->pseudo_window_p) | |
768 | { | |
49be9f70 JR |
769 | struct frame *f; |
770 | int width; | |
771 | ||
791f420f JR |
772 | BLOCK_INPUT; |
773 | x_draw_row_bitmaps (w, desired_row); | |
774 | ||
775 | /* When a window has disappeared, make sure that no rest of | |
776 | full-width rows stays visible in the internal border. */ | |
49be9f70 JR |
777 | if (windows_or_buffers_changed |
778 | && (f = XFRAME (w->frame), | |
779 | width = FRAME_INTERNAL_BORDER_WIDTH (f), | |
780 | width != 0)) | |
791f420f | 781 | { |
791f420f JR |
782 | int height = desired_row->visible_height; |
783 | int x = (window_box_right (w, -1) | |
784 | + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f)); | |
785 | int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); | |
00fe468b | 786 | HDC hdc = get_frame_dc (f); |
791f420f | 787 | |
00fe468b JR |
788 | w32_clear_area (f, hdc, x, y, width, height); |
789 | release_frame_dc (f, hdc); | |
791f420f JR |
790 | } |
791 | ||
792 | UNBLOCK_INPUT; | |
793 | } | |
794 | } | |
795 | ||
796 | ||
797 | /* Draw the bitmap WHICH in one of the areas to the left or right of | |
798 | window W. ROW is the glyph row for which to display the bitmap; it | |
799 | determines the vertical position at which the bitmap has to be | |
800 | drawn. */ | |
801 | ||
802 | static void | |
00fe468b | 803 | w32_draw_bitmap (w, hdc, row, which) |
791f420f | 804 | struct window *w; |
00fe468b | 805 | HDC hdc; |
791f420f JR |
806 | struct glyph_row *row; |
807 | enum bitmap_type which; | |
808 | { | |
809 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
810 | Window window = FRAME_W32_WINDOW (f); | |
791f420f JR |
811 | HDC compat_hdc; |
812 | int x, y, wd, h, dy; | |
791f420f | 813 | HBITMAP pixmap; |
791f420f JR |
814 | HANDLE horig_obj; |
815 | struct face *face; | |
816 | ||
817 | /* Must clip because of partially visible lines. */ | |
818 | w32_clip_to_row (w, row, hdc, 1); | |
819 | ||
820 | switch (which) | |
821 | { | |
822 | case LEFT_TRUNCATION_BITMAP: | |
823 | wd = left_width; | |
824 | h = left_height; | |
f7737f5d | 825 | pixmap = left_bmp; |
791f420f JR |
826 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
827 | - wd | |
828 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
829 | break; | |
830 | ||
831 | case OVERLAY_ARROW_BITMAP: | |
832 | wd = ov_width; | |
833 | h = ov_height; | |
f7737f5d | 834 | pixmap = ov_bmp; |
791f420f JR |
835 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
836 | - wd | |
837 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
838 | break; | |
839 | ||
840 | case RIGHT_TRUNCATION_BITMAP: | |
841 | wd = right_width; | |
842 | h = right_height; | |
f7737f5d | 843 | pixmap = right_bmp; |
791f420f JR |
844 | x = window_box_right (w, -1); |
845 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; | |
846 | break; | |
847 | ||
848 | case CONTINUED_LINE_BITMAP: | |
849 | wd = continued_width; | |
850 | h = continued_height; | |
f7737f5d | 851 | pixmap = continued_bmp; |
791f420f JR |
852 | x = window_box_right (w, -1); |
853 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; | |
854 | break; | |
855 | ||
856 | case CONTINUATION_LINE_BITMAP: | |
857 | wd = continuation_width; | |
858 | h = continuation_height; | |
f7737f5d | 859 | pixmap = continuation_bmp; |
791f420f JR |
860 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
861 | - wd | |
862 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
863 | break; | |
864 | ||
865 | case ZV_LINE_BITMAP: | |
866 | wd = zv_width; | |
867 | h = zv_height; | |
f7737f5d | 868 | pixmap = zv_bmp; |
791f420f JR |
869 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
870 | - wd | |
871 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
872 | break; | |
873 | ||
874 | default: | |
875 | abort (); | |
876 | } | |
877 | ||
878 | /* Convert to frame coordinates. Set dy to the offset in the row to | |
879 | start drawing the bitmap. */ | |
880 | y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
881 | dy = (row->height - h) / 2; | |
882 | ||
f7737f5d | 883 | /* Draw the bitmap. */ |
791f420f | 884 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); |
791f420f JR |
885 | |
886 | compat_hdc = CreateCompatibleDC (hdc); | |
887 | SaveDC (hdc); | |
9436cdf9 | 888 | |
791f420f | 889 | horig_obj = SelectObject (compat_hdc, pixmap); |
9436cdf9 JR |
890 | SetTextColor (hdc, face->background); |
891 | SetBkColor (hdc, face->foreground); | |
892 | ||
791f420f | 893 | BitBlt (hdc, x, y + dy, wd, h, compat_hdc, 0, 0, SRCCOPY); |
9436cdf9 | 894 | |
791f420f | 895 | SelectObject (compat_hdc, horig_obj); |
791f420f JR |
896 | DeleteDC (compat_hdc); |
897 | RestoreDC (hdc, -1); | |
791f420f JR |
898 | } |
899 | ||
900 | ||
901 | /* Draw flags bitmaps for glyph row ROW on window W. Call this | |
902 | function with input blocked. */ | |
903 | ||
904 | static void | |
905 | x_draw_row_bitmaps (w, row) | |
906 | struct window *w; | |
907 | struct glyph_row *row; | |
908 | { | |
909 | struct frame *f = XFRAME (w->frame); | |
910 | enum bitmap_type bitmap; | |
911 | struct face *face; | |
912 | int header_line_height = -1; | |
fccb8288 | 913 | HDC hdc; |
791f420f JR |
914 | |
915 | xassert (interrupt_input_blocked); | |
916 | ||
917 | /* If row is completely invisible, because of vscrolling, we | |
918 | don't have to draw anything. */ | |
919 | if (row->visible_height <= 0) | |
920 | return; | |
921 | ||
922 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); | |
923 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
924 | ||
925 | /* Decide which bitmap to draw at the left side. */ | |
926 | if (row->overlay_arrow_p) | |
927 | bitmap = OVERLAY_ARROW_BITMAP; | |
928 | else if (row->truncated_on_left_p) | |
929 | bitmap = LEFT_TRUNCATION_BITMAP; | |
930 | else if (MATRIX_ROW_CONTINUATION_LINE_P (row)) | |
931 | bitmap = CONTINUATION_LINE_BITMAP; | |
932 | else if (row->indicate_empty_line_p) | |
933 | bitmap = ZV_LINE_BITMAP; | |
934 | else | |
935 | bitmap = NO_BITMAP; | |
936 | ||
fccb8288 EZ |
937 | hdc = get_frame_dc (f); |
938 | ||
791f420f JR |
939 | /* Clear flags area if no bitmap to draw or if bitmap doesn't fill |
940 | the flags area. */ | |
941 | if (bitmap == NO_BITMAP | |
942 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) | |
943 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) | |
944 | { | |
945 | /* If W has a vertical border to its left, don't draw over it. */ | |
946 | int border = ((XFASTINT (w->left) > 0 | |
947 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
948 | ? 1 : 0); | |
949 | int left = window_box_left (w, -1); | |
950 | ||
951 | if (header_line_height < 0) | |
952 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
953 | ||
954 | w32_fill_area (f, hdc, face->background, | |
955 | left - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) + border, | |
956 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
957 | row->y)), | |
958 | FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - border, | |
959 | row->visible_height); | |
960 | } | |
961 | ||
962 | /* Draw the left bitmap. */ | |
963 | if (bitmap != NO_BITMAP) | |
964 | w32_draw_bitmap (w, hdc, row, bitmap); | |
965 | ||
966 | /* Decide which bitmap to draw at the right side. */ | |
967 | if (row->truncated_on_right_p) | |
968 | bitmap = RIGHT_TRUNCATION_BITMAP; | |
969 | else if (row->continued_p) | |
970 | bitmap = CONTINUED_LINE_BITMAP; | |
971 | else | |
972 | bitmap = NO_BITMAP; | |
973 | ||
974 | /* Clear flags area if no bitmap to draw of if bitmap doesn't fill | |
975 | the flags area. */ | |
976 | if (bitmap == NO_BITMAP | |
977 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) | |
978 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) | |
979 | { | |
980 | int right = window_box_right (w, -1); | |
981 | ||
982 | if (header_line_height < 0) | |
983 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
984 | ||
985 | w32_fill_area (f, hdc, face->background, | |
986 | right, | |
987 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
988 | row->y)), | |
989 | FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f), | |
990 | row->visible_height); | |
991 | } | |
992 | ||
993 | /* Draw the right bitmap. */ | |
994 | if (bitmap != NO_BITMAP) | |
995 | w32_draw_bitmap (w, hdc, row, bitmap); | |
996 | ||
997 | release_frame_dc (f, hdc); | |
998 | } | |
999 | ||
ee78dc32 | 1000 | \f |
9ef2e2cf JR |
1001 | /* This is called when starting Emacs and when restarting after |
1002 | suspend. When starting Emacs, no window is mapped. And nothing | |
1003 | must be done to Emacs's own window if it is suspended (though that | |
1004 | rarely happens). */ | |
ee78dc32 | 1005 | |
96214669 GV |
1006 | static void |
1007 | w32_set_terminal_modes (void) | |
ee78dc32 GV |
1008 | { |
1009 | } | |
1010 | ||
9ef2e2cf JR |
1011 | /* This is called when exiting or suspending Emacs. Exiting will make |
1012 | the W32 windows go away, and suspending requires no action. */ | |
ee78dc32 | 1013 | |
96214669 GV |
1014 | static void |
1015 | w32_reset_terminal_modes (void) | |
ee78dc32 GV |
1016 | { |
1017 | } | |
791f420f | 1018 | |
9ef2e2cf | 1019 | |
ee78dc32 | 1020 | \f |
791f420f JR |
1021 | /*********************************************************************** |
1022 | Output Cursor | |
1023 | ***********************************************************************/ | |
1024 | ||
1025 | /* Set the global variable output_cursor to CURSOR. All cursor | |
1026 | positions are relative to updated_window. */ | |
9ef2e2cf | 1027 | |
791f420f JR |
1028 | static void |
1029 | set_output_cursor (cursor) | |
1030 | struct cursor_pos *cursor; | |
1031 | { | |
1032 | output_cursor.hpos = cursor->hpos; | |
1033 | output_cursor.vpos = cursor->vpos; | |
1034 | output_cursor.x = cursor->x; | |
1035 | output_cursor.y = cursor->y; | |
1036 | } | |
1037 | ||
1038 | ||
1039 | /* Set a nominal cursor position. | |
1040 | ||
1041 | HPOS and VPOS are column/row positions in a window glyph matrix. X | |
1042 | and Y are window text area relative pixel positions. | |
1043 | ||
1044 | If this is done during an update, updated_window will contain the | |
1045 | window that is being updated and the position is the future output | |
1046 | cursor position for that window. If updated_window is null, use | |
1047 | selected_window and display the cursor at the given position. */ | |
ee78dc32 | 1048 | |
96214669 | 1049 | static void |
791f420f JR |
1050 | w32_cursor_to (vpos, hpos, y, x) |
1051 | int vpos, hpos, y, x; | |
ee78dc32 | 1052 | { |
791f420f | 1053 | struct window *w; |
ee78dc32 | 1054 | |
791f420f JR |
1055 | /* If updated_window is not set, work on selected_window. */ |
1056 | if (updated_window) | |
1057 | w = updated_window; | |
1058 | else | |
1059 | w = XWINDOW (selected_window); | |
1060 | ||
1061 | /* Set the output cursor. */ | |
1062 | output_cursor.hpos = hpos; | |
1063 | output_cursor.vpos = vpos; | |
1064 | output_cursor.x = x; | |
1065 | output_cursor.y = y; | |
ee78dc32 | 1066 | |
791f420f JR |
1067 | /* If not called as part of an update, really display the cursor. |
1068 | This will also set the cursor position of W. */ | |
1069 | if (updated_window == NULL) | |
ee78dc32 GV |
1070 | { |
1071 | BLOCK_INPUT; | |
791f420f | 1072 | x_display_cursor (w, 1, hpos, vpos, x, y); |
ee78dc32 GV |
1073 | UNBLOCK_INPUT; |
1074 | } | |
1075 | } | |
791f420f | 1076 | |
9ef2e2cf | 1077 | |
ee78dc32 | 1078 | \f |
791f420f JR |
1079 | /*********************************************************************** |
1080 | Display Iterator | |
1081 | ***********************************************************************/ | |
1082 | ||
1083 | /* Function prototypes of this page. */ | |
1084 | ||
1085 | static struct face *x_get_glyph_face_and_encoding P_ ((struct frame *, | |
1086 | struct glyph *, | |
93ff4395 JR |
1087 | wchar_t *, |
1088 | int *)); | |
791f420f JR |
1089 | static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int, |
1090 | int, wchar_t *, int)); | |
82f9d565 | 1091 | static XCharStruct *w32_per_char_metric P_ ((XFontStruct *, |
9ef2e2cf JR |
1092 | wchar_t *, |
1093 | enum w32_char_font_type)); | |
1094 | static enum w32_char_font_type | |
1095 | w32_encode_char P_ ((int, wchar_t *, struct font_info *, int *)); | |
791f420f JR |
1096 | static void x_append_glyph P_ ((struct it *)); |
1097 | static void x_append_composite_glyph P_ ((struct it *)); | |
1098 | static void x_append_stretch_glyph P_ ((struct it *it, Lisp_Object, | |
1099 | int, int, double)); | |
1100 | static void x_produce_glyphs P_ ((struct it *)); | |
1101 | static void x_produce_image_glyph P_ ((struct it *it)); | |
a1b9438c | 1102 | |
a1b9438c | 1103 | |
791f420f JR |
1104 | /* Dealing with bits of wchar_t as if they were an XChar2B. */ |
1105 | #define BUILD_WCHAR_T(byte1, byte2) \ | |
1106 | ((wchar_t)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff))) | |
a1b9438c | 1107 | |
a1b9438c | 1108 | |
791f420f JR |
1109 | #define BYTE1(ch) \ |
1110 | (((ch) & 0xff00) >> 8) | |
a1b9438c | 1111 | |
791f420f JR |
1112 | #define BYTE2(ch) \ |
1113 | ((ch) & 0x00ff) | |
cabb23bc | 1114 | |
791f420f JR |
1115 | |
1116 | /* Get metrics of character CHAR2B in FONT. Value is always non-null. | |
1117 | If CHAR2B is not contained in FONT, the font's default character | |
9ef2e2cf | 1118 | metric is returned. */ |
791f420f | 1119 | |
82f9d565 AI |
1120 | static int |
1121 | w32_bdf_per_char_metric (font, char2b, dim, pcm) | |
9127e20e JR |
1122 | XFontStruct *font; |
1123 | wchar_t *char2b; | |
1124 | int dim; | |
82f9d565 | 1125 | XCharStruct * pcm; |
9127e20e JR |
1126 | { |
1127 | glyph_metric * bdf_metric; | |
1128 | char buf[2]; | |
9127e20e JR |
1129 | |
1130 | if (dim == 1) | |
4b99045f | 1131 | buf[0] = (char)(*char2b); |
9127e20e JR |
1132 | else |
1133 | { | |
1134 | buf[0] = BYTE1 (*char2b); | |
1135 | buf[1] = BYTE2 (*char2b); | |
1136 | } | |
1137 | ||
1138 | bdf_metric = w32_BDF_TextMetric (font->bdf, buf, dim); | |
1139 | ||
1140 | if (bdf_metric) | |
1141 | { | |
1142 | pcm->width = bdf_metric->dwidth; | |
1143 | pcm->lbearing = bdf_metric->bbox; | |
1144 | pcm->rbearing = bdf_metric->dwidth | |
1145 | - (bdf_metric->bbox + bdf_metric->bbw); | |
1146 | pcm->ascent = bdf_metric->bboy + bdf_metric->bbh; | |
00c96995 | 1147 | pcm->descent = -bdf_metric->bboy; |
82f9d565 AI |
1148 | |
1149 | return 1; | |
9127e20e | 1150 | } |
82f9d565 | 1151 | return 0; |
9127e20e JR |
1152 | } |
1153 | ||
1154 | ||
82f9d565 AI |
1155 | static int |
1156 | w32_native_per_char_metric (font, char2b, font_type, pcm) | |
791f420f JR |
1157 | XFontStruct *font; |
1158 | wchar_t *char2b; | |
9ef2e2cf | 1159 | enum w32_char_font_type font_type; |
82f9d565 | 1160 | XCharStruct * pcm; |
cabb23bc | 1161 | { |
82f9d565 AI |
1162 | HDC hdc = GetDC (NULL); |
1163 | HFONT old_font; | |
1164 | BOOL retval = FALSE; | |
cabb23bc | 1165 | |
791f420f | 1166 | xassert (font && char2b); |
82f9d565 AI |
1167 | xassert (font->hfont); |
1168 | xassert (font_type == UNICODE_FONT || font_type == ANSI_FONT); | |
cabb23bc | 1169 | |
82f9d565 | 1170 | old_font = SelectObject (hdc, font->hfont); |
791f420f | 1171 | |
dfaaaafb | 1172 | if ((font->tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0) |
791f420f | 1173 | { |
dfaaaafb AI |
1174 | ABC char_widths; |
1175 | ||
1176 | if (font_type == UNICODE_FONT) | |
1177 | retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths); | |
82f9d565 | 1178 | else |
dfaaaafb AI |
1179 | retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths); |
1180 | ||
1181 | if (retval) | |
1182 | { | |
1183 | pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC; | |
1184 | pcm->lbearing = char_widths.abcA; | |
1185 | pcm->rbearing = pcm->width - char_widths.abcC; | |
82f9d565 AI |
1186 | pcm->ascent = FONT_BASE (font); |
1187 | pcm->descent = FONT_DESCENT (font); | |
dfaaaafb | 1188 | } |
791f420f | 1189 | } |
82f9d565 AI |
1190 | |
1191 | if (!retval) | |
791f420f | 1192 | { |
82f9d565 AI |
1193 | /* Either font is not a True-type font, or GetCharABCWidthsW |
1194 | failed (it is not supported on Windows 9x for instance), so we | |
1195 | can't determine the full info we would like. All is not lost | |
1196 | though - we can call GetTextExtentPoint32 to get rbearing and | |
1197 | deduce width based on the font's per-string overhang. lbearing | |
1198 | is assumed to be zero. */ | |
01b220b6 JR |
1199 | |
1200 | /* TODO: Some Thai characters (and other composites if Windows | |
1201 | supports them) do have lbearing, and report their total width | |
1202 | as zero. Need some way of handling them when | |
1203 | GetCharABCWidthsW fails. */ | |
82f9d565 AI |
1204 | SIZE sz; |
1205 | ||
1206 | if (font_type == UNICODE_FONT) | |
1207 | retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz); | |
1208 | else | |
1209 | retval = GetTextExtentPoint32A (hdc, (char*)char2b, 1, &sz); | |
791f420f JR |
1210 | |
1211 | if (retval) | |
dfaaaafb | 1212 | { |
82f9d565 AI |
1213 | pcm->width = sz.cx - font->tm.tmOverhang; |
1214 | pcm->rbearing = sz.cx; | |
dfaaaafb | 1215 | pcm->lbearing = 0; |
82f9d565 AI |
1216 | pcm->ascent = FONT_BASE (font); |
1217 | pcm->descent = FONT_DESCENT (font); | |
dfaaaafb | 1218 | } |
791f420f JR |
1219 | } |
1220 | ||
791f420f | 1221 | |
93ff4395 JR |
1222 | if (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0) |
1223 | { | |
82f9d565 | 1224 | retval = FALSE; |
93ff4395 JR |
1225 | } |
1226 | ||
82f9d565 AI |
1227 | SelectObject (hdc, old_font); |
1228 | ReleaseDC (NULL, hdc); | |
1229 | ||
1230 | return retval; | |
1231 | } | |
1232 | ||
1233 | ||
1234 | static XCharStruct * | |
1235 | w32_per_char_metric (font, char2b, font_type) | |
1236 | XFontStruct *font; | |
1237 | wchar_t *char2b; | |
1238 | enum w32_char_font_type font_type; | |
1239 | { | |
1240 | /* The result metric information. */ | |
1241 | XCharStruct *pcm; | |
1242 | BOOL retval; | |
1243 | ||
1244 | xassert (font && char2b); | |
1245 | xassert (font_type != UNKNOWN_FONT); | |
1246 | ||
1247 | /* Handle the common cases quickly. */ | |
4b99045f | 1248 | if (!font->bdf && font->per_char == NULL) |
82f9d565 AI |
1249 | /* TODO: determine whether char2b exists in font? */ |
1250 | return &font->max_bounds; | |
4b99045f | 1251 | else if (!font->bdf && *char2b < 128) |
82f9d565 AI |
1252 | return &font->per_char[*char2b]; |
1253 | ||
1254 | pcm = &font->scratch; | |
1255 | ||
1256 | if (font_type == BDF_1D_FONT) | |
1257 | retval = w32_bdf_per_char_metric (font, char2b, 1, pcm); | |
1258 | else if (font_type == BDF_2D_FONT) | |
1259 | retval = w32_bdf_per_char_metric (font, char2b, 2, pcm); | |
1260 | else | |
1261 | retval = w32_native_per_char_metric (font, char2b, font_type, pcm); | |
1262 | ||
1263 | if (retval) | |
1264 | return pcm; | |
1265 | ||
1266 | return NULL; | |
1267 | } | |
1268 | ||
1269 | void | |
1270 | w32_cache_char_metrics (font) | |
1271 | XFontStruct *font; | |
1272 | { | |
1273 | wchar_t char2b = L'x'; | |
1274 | ||
1275 | /* Cache char metrics for the common cases. */ | |
1276 | if (font->bdf) | |
1277 | { | |
1278 | /* TODO: determine whether font is fixed-pitch. */ | |
00c96995 JR |
1279 | if (!w32_bdf_per_char_metric (font, &char2b, 1, &font->max_bounds)) |
1280 | { | |
1281 | /* Use the font width and height as max bounds, as not all BDF | |
1282 | fonts contain the letter 'x'. */ | |
1283 | font->max_bounds.width = FONT_MAX_WIDTH (font); | |
1284 | font->max_bounds.lbearing = -font->bdf->llx; | |
1285 | font->max_bounds.rbearing = FONT_MAX_WIDTH (font) - font->bdf->urx; | |
1286 | font->max_bounds.ascent = FONT_BASE (font); | |
1287 | font->max_bounds.descent = FONT_DESCENT (font); | |
1288 | } | |
82f9d565 AI |
1289 | } |
1290 | else | |
1291 | { | |
f1eed8ff JR |
1292 | if (((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) != 0) |
1293 | /* Some fonts (eg DBCS fonts) are marked as fixed width even | |
1294 | though they contain characters of different widths. */ | |
1295 | || (font->tm.tmMaxCharWidth != font->tm.tmAveCharWidth)) | |
82f9d565 AI |
1296 | { |
1297 | /* Font is not fixed pitch, so cache per_char info for the | |
1298 | ASCII characters. It would be much more work, and probably | |
1299 | not worth it, to cache other chars, since we may change | |
1300 | between using Unicode and ANSI text drawing functions at | |
1301 | run-time. */ | |
1302 | int i; | |
1303 | ||
1304 | font->per_char = xmalloc (128 * sizeof(XCharStruct)); | |
1305 | for (i = 0; i < 128; i++) | |
1306 | { | |
1307 | char2b = i; | |
1308 | w32_native_per_char_metric (font, &char2b, ANSI_FONT, | |
1309 | &font->per_char[i]); | |
1310 | } | |
1311 | } | |
1312 | else | |
1313 | w32_native_per_char_metric (font, &char2b, ANSI_FONT, | |
1314 | &font->max_bounds); | |
1315 | } | |
791f420f JR |
1316 | } |
1317 | ||
1318 | ||
9ef2e2cf JR |
1319 | /* Determine if a font is double byte. */ |
1320 | int w32_font_is_double_byte (XFontStruct *font) | |
1321 | { | |
1322 | return font->double_byte_p; | |
1323 | } | |
1324 | ||
1325 | ||
d6ff54d5 JR |
1326 | static BOOL |
1327 | w32_use_unicode_for_codepage (codepage) | |
1328 | int codepage; | |
1329 | { | |
1330 | /* If the current codepage is supported, use Unicode for output. */ | |
1331 | return (w32_enable_unicode_output | |
1332 | && codepage != CP_8BIT | |
1333 | && (codepage == CP_UNICODE || IsValidCodePage (codepage))); | |
1334 | } | |
1335 | ||
791f420f JR |
1336 | /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is |
1337 | the two-byte form of C. Encoding is returned in *CHAR2B. */ | |
1338 | ||
9ef2e2cf JR |
1339 | static INLINE enum w32_char_font_type |
1340 | w32_encode_char (c, char2b, font_info, two_byte_p) | |
791f420f JR |
1341 | int c; |
1342 | wchar_t *char2b; | |
1343 | struct font_info *font_info; | |
9ef2e2cf | 1344 | int * two_byte_p; |
791f420f JR |
1345 | { |
1346 | int charset = CHAR_CHARSET (c); | |
1347 | int codepage; | |
9ef2e2cf JR |
1348 | int unicode_p = 0; |
1349 | ||
791f420f JR |
1350 | XFontStruct *font = font_info->font; |
1351 | ||
9127e20e | 1352 | xassert (two_byte_p); |
9ef2e2cf JR |
1353 | |
1354 | *two_byte_p = w32_font_is_double_byte (font); | |
1355 | ||
791f420f JR |
1356 | /* FONT_INFO may define a scheme by which to encode byte1 and byte2. |
1357 | This may be either a program in a special encoder language or a | |
1358 | fixed encoding. */ | |
1359 | if (font_info->font_encoder) | |
1360 | { | |
1361 | /* It's a program. */ | |
1362 | struct ccl_program *ccl = font_info->font_encoder; | |
1363 | ||
1364 | if (CHARSET_DIMENSION (charset) == 1) | |
1365 | { | |
1366 | ccl->reg[0] = charset; | |
1367 | ccl->reg[1] = BYTE2 (*char2b); | |
1368 | } | |
1369 | else | |
1370 | { | |
1371 | ccl->reg[0] = charset; | |
1372 | ccl->reg[1] = BYTE1 (*char2b); | |
1373 | ccl->reg[2] = BYTE2 (*char2b); | |
1374 | } | |
1375 | ||
1376 | ccl_driver (ccl, NULL, NULL, 0, 0, NULL); | |
1377 | ||
1378 | /* We assume that MSBs are appropriately set/reset by CCL | |
1379 | program. */ | |
9ef2e2cf | 1380 | if (!*two_byte_p) /* 1-byte font */ |
791f420f | 1381 | *char2b = BUILD_WCHAR_T (0, ccl->reg[1]); |
791f420f JR |
1382 | else |
1383 | *char2b = BUILD_WCHAR_T (ccl->reg[1], ccl->reg[2]); | |
791f420f JR |
1384 | } |
1385 | else if (font_info->encoding[charset]) | |
1386 | { | |
1387 | /* Fixed encoding scheme. See fontset.h for the meaning of the | |
1388 | encoding numbers. */ | |
1389 | int enc = font_info->encoding[charset]; | |
1390 | ||
1391 | if ((enc == 1 || enc == 2) | |
1392 | && CHARSET_DIMENSION (charset) == 2) | |
1393 | *char2b = BUILD_WCHAR_T (BYTE1 (*char2b) | 0x80, BYTE2 (*char2b)); | |
1394 | ||
1395 | if (enc == 1 || enc == 3 | |
1396 | || (enc == 4 && CHARSET_DIMENSION (charset) == 1)) | |
1397 | *char2b = BUILD_WCHAR_T (BYTE1 (*char2b), BYTE2 (*char2b) | 0x80); | |
1398 | else if (enc == 4) | |
1399 | { | |
1400 | int sjis1, sjis2; | |
1401 | ||
1402 | ENCODE_SJIS (BYTE1 (*char2b), BYTE2 (*char2b), | |
1403 | sjis1, sjis2); | |
1404 | *char2b = BUILD_WCHAR_T (sjis1, sjis2); | |
1405 | } | |
1406 | } | |
0e804d38 | 1407 | codepage = font_info->codepage; |
791f420f JR |
1408 | |
1409 | /* If charset is not ASCII or Latin-1, may need to move it into | |
1410 | Unicode space. */ | |
1411 | if ( font && !font->bdf && w32_use_unicode_for_codepage (codepage) | |
49be9f70 JR |
1412 | && charset != CHARSET_ASCII && charset != charset_latin_iso8859_1 |
1413 | && charset != CHARSET_8_BIT_CONTROL && charset != CHARSET_8_BIT_GRAPHIC) | |
791f420f JR |
1414 | { |
1415 | char temp[3]; | |
1416 | temp[0] = BYTE1 (*char2b); | |
1417 | temp[1] = BYTE2 (*char2b); | |
1418 | temp[2] = '\0'; | |
02f593f3 JR |
1419 | if (codepage != CP_UNICODE) |
1420 | { | |
1421 | if (temp[0]) | |
1422 | MultiByteToWideChar (codepage, 0, temp, 2, char2b, 1); | |
1423 | else | |
1424 | MultiByteToWideChar (codepage, 0, temp+1, 1, char2b, 1); | |
1425 | } | |
9ef2e2cf JR |
1426 | unicode_p = 1; |
1427 | *two_byte_p = 1; | |
1428 | } | |
1429 | if (!font) | |
1430 | return UNKNOWN_FONT; | |
9127e20e JR |
1431 | else if (font->bdf && CHARSET_DIMENSION (charset) == 1) |
1432 | return BDF_1D_FONT; | |
9ef2e2cf | 1433 | else if (font->bdf) |
9127e20e | 1434 | return BDF_2D_FONT; |
9ef2e2cf JR |
1435 | else if (unicode_p) |
1436 | return UNICODE_FONT; | |
1437 | else | |
1438 | return ANSI_FONT; | |
791f420f JR |
1439 | } |
1440 | ||
1441 | ||
1442 | /* Get face and two-byte form of character C in face FACE_ID on frame | |
1443 | F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero | |
1444 | means we want to display multibyte text. Value is a pointer to a | |
1445 | realized face that is ready for display. */ | |
1446 | ||
1447 | static INLINE struct face * | |
1448 | x_get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p) | |
1449 | struct frame *f; | |
1450 | int c, face_id; | |
1451 | wchar_t *char2b; | |
1452 | int multibyte_p; | |
1453 | { | |
1454 | struct face *face = FACE_FROM_ID (f, face_id); | |
1455 | ||
1456 | if (!multibyte_p) | |
1457 | { | |
1458 | /* Unibyte case. We don't have to encode, but we have to make | |
1459 | sure to use a face suitable for unibyte. */ | |
1460 | *char2b = BUILD_WCHAR_T (0, c); | |
93ff4395 JR |
1461 | face_id = FACE_FOR_CHAR (f, face, c); |
1462 | face = FACE_FROM_ID (f, face_id); | |
791f420f JR |
1463 | } |
1464 | else if (c < 128 && face_id < BASIC_FACE_ID_SENTINEL) | |
1465 | { | |
1466 | /* Case of ASCII in a face known to fit ASCII. */ | |
1467 | *char2b = BUILD_WCHAR_T (0, c); | |
1468 | } | |
1469 | else | |
1470 | { | |
1471 | int c1, c2, charset; | |
1472 | ||
1473 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1474 | really a one-byte character so that byte1 is zero. */ | |
1475 | SPLIT_CHAR (c, charset, c1, c2); | |
1476 | if (c2 > 0) | |
1477 | *char2b = BUILD_WCHAR_T (c1, c2); | |
1478 | else | |
1479 | *char2b = BUILD_WCHAR_T (0, c1); | |
791f420f JR |
1480 | |
1481 | /* Maybe encode the character in *CHAR2B. */ | |
93ff4395 | 1482 | if (face->font != NULL) |
791f420f JR |
1483 | { |
1484 | struct font_info *font_info | |
1485 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1486 | if (font_info) | |
9ef2e2cf | 1487 | w32_encode_char (c, char2b, font_info, &multibyte_p); |
791f420f JR |
1488 | } |
1489 | } | |
1490 | ||
1491 | /* Make sure X resources of the face are allocated. */ | |
1492 | xassert (face != NULL); | |
1493 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1494 | ||
1495 | return face; | |
1496 | } | |
1497 | ||
1498 | ||
1499 | /* Get face and two-byte form of character glyph GLYPH on frame F. | |
1500 | The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is | |
1501 | a pointer to a realized face that is ready for display. */ | |
1502 | ||
1503 | static INLINE struct face * | |
93ff4395 | 1504 | x_get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p) |
791f420f JR |
1505 | struct frame *f; |
1506 | struct glyph *glyph; | |
1507 | wchar_t *char2b; | |
93ff4395 | 1508 | int *two_byte_p; |
791f420f JR |
1509 | { |
1510 | struct face *face; | |
9ef2e2cf | 1511 | int dummy = 0; |
791f420f JR |
1512 | |
1513 | xassert (glyph->type == CHAR_GLYPH); | |
1514 | face = FACE_FROM_ID (f, glyph->face_id); | |
1515 | ||
93ff4395 JR |
1516 | if (two_byte_p) |
1517 | *two_byte_p = 0; | |
9ef2e2cf JR |
1518 | else |
1519 | two_byte_p = &dummy; | |
93ff4395 | 1520 | |
791f420f JR |
1521 | if (!glyph->multibyte_p) |
1522 | { | |
1523 | /* Unibyte case. We don't have to encode, but we have to make | |
1524 | sure to use a face suitable for unibyte. */ | |
1525 | *char2b = BUILD_WCHAR_T (0, glyph->u.ch); | |
1526 | } | |
1527 | else if (glyph->u.ch < 128 | |
1528 | && glyph->face_id < BASIC_FACE_ID_SENTINEL) | |
1529 | { | |
1530 | /* Case of ASCII in a face known to fit ASCII. */ | |
1531 | *char2b = BUILD_WCHAR_T (0, glyph->u.ch); | |
1532 | } | |
1533 | else | |
1534 | { | |
1535 | int c1, c2, charset; | |
1536 | ||
1537 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1538 | really a one-byte character so that byte1 is zero. */ | |
1539 | SPLIT_CHAR (glyph->u.ch, charset, c1, c2); | |
1540 | if (c2 > 0) | |
1541 | *char2b = BUILD_WCHAR_T (c1, c2); | |
1542 | else | |
1543 | *char2b = BUILD_WCHAR_T (0, c1); | |
1544 | ||
1545 | /* Maybe encode the character in *CHAR2B. */ | |
1546 | if (charset != CHARSET_ASCII) | |
1547 | { | |
1548 | struct font_info *font_info | |
1549 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1550 | if (font_info) | |
1551 | { | |
9ef2e2cf JR |
1552 | glyph->w32_font_type |
1553 | = w32_encode_char (glyph->u.ch, char2b, font_info, two_byte_p); | |
791f420f JR |
1554 | } |
1555 | } | |
1556 | } | |
1557 | ||
1558 | /* Make sure X resources of the face are allocated. */ | |
1559 | xassert (face != NULL); | |
1560 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1561 | return face; | |
1562 | } | |
1563 | ||
1564 | ||
1565 | /* Store one glyph for IT->char_to_display in IT->glyph_row. | |
1566 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1567 | ||
1568 | static INLINE void | |
1569 | x_append_glyph (it) | |
1570 | struct it *it; | |
1571 | { | |
1572 | struct glyph *glyph; | |
1573 | enum glyph_row_area area = it->area; | |
1574 | ||
1575 | xassert (it->glyph_row); | |
1576 | xassert (it->char_to_display != '\n' && it->char_to_display != '\t'); | |
1577 | ||
1578 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1579 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1580 | { | |
791f420f JR |
1581 | glyph->charpos = CHARPOS (it->position); |
1582 | glyph->object = it->object; | |
ec48c3a7 | 1583 | glyph->pixel_width = it->pixel_width; |
791f420f | 1584 | glyph->voffset = it->voffset; |
ec48c3a7 | 1585 | glyph->type = CHAR_GLYPH; |
791f420f | 1586 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1587 | glyph->left_box_line_p = it->start_of_box_run_p; |
1588 | glyph->right_box_line_p = it->end_of_box_run_p; | |
791f420f JR |
1589 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1590 | || it->phys_descent > it->descent); | |
ec48c3a7 | 1591 | glyph->padding_p = 0; |
93ff4395 | 1592 | glyph->glyph_not_available_p = it->glyph_not_available_p; |
ec48c3a7 JR |
1593 | glyph->face_id = it->face_id; |
1594 | glyph->u.ch = it->char_to_display; | |
1595 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1596 | ++it->glyph_row->used[area]; |
1597 | } | |
1598 | } | |
1599 | ||
1600 | /* Store one glyph for the composition IT->cmp_id in IT->glyph_row. | |
1601 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1602 | ||
1603 | static INLINE void | |
1604 | x_append_composite_glyph (it) | |
1605 | struct it *it; | |
1606 | { | |
1607 | struct glyph *glyph; | |
1608 | enum glyph_row_area area = it->area; | |
1609 | ||
1610 | xassert (it->glyph_row); | |
1611 | ||
1612 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1613 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1614 | { | |
791f420f JR |
1615 | glyph->charpos = CHARPOS (it->position); |
1616 | glyph->object = it->object; | |
ec48c3a7 | 1617 | glyph->pixel_width = it->pixel_width; |
791f420f | 1618 | glyph->voffset = it->voffset; |
ec48c3a7 | 1619 | glyph->type = COMPOSITE_GLYPH; |
791f420f | 1620 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1621 | glyph->left_box_line_p = it->start_of_box_run_p; |
1622 | glyph->right_box_line_p = it->end_of_box_run_p; | |
791f420f JR |
1623 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1624 | || it->phys_descent > it->descent); | |
ec48c3a7 JR |
1625 | glyph->padding_p = 0; |
1626 | glyph->glyph_not_available_p = 0; | |
1627 | glyph->face_id = it->face_id; | |
1628 | glyph->u.cmp_id = it->cmp_id; | |
1629 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1630 | ++it->glyph_row->used[area]; |
1631 | } | |
1632 | } | |
1633 | ||
1634 | ||
1635 | /* Change IT->ascent and IT->height according to the setting of | |
1636 | IT->voffset. */ | |
1637 | ||
1638 | static INLINE void | |
1639 | take_vertical_position_into_account (it) | |
1640 | struct it *it; | |
1641 | { | |
1642 | if (it->voffset) | |
1643 | { | |
1644 | if (it->voffset < 0) | |
1645 | /* Increase the ascent so that we can display the text higher | |
1646 | in the line. */ | |
1647 | it->ascent += abs (it->voffset); | |
1648 | else | |
1649 | /* Increase the descent so that we can display the text lower | |
1650 | in the line. */ | |
1651 | it->descent += it->voffset; | |
1652 | } | |
1653 | } | |
1654 | ||
1655 | ||
1656 | /* Produce glyphs/get display metrics for the image IT is loaded with. | |
1657 | See the description of struct display_iterator in dispextern.h for | |
1658 | an overview of struct display_iterator. */ | |
1659 | ||
1660 | static void | |
1661 | x_produce_image_glyph (it) | |
1662 | struct it *it; | |
1663 | { | |
1664 | struct image *img; | |
1665 | struct face *face; | |
1666 | ||
1667 | xassert (it->what == IT_IMAGE); | |
1668 | ||
1669 | face = FACE_FROM_ID (it->f, it->face_id); | |
1670 | img = IMAGE_FROM_ID (it->f, it->image_id); | |
1671 | xassert (img); | |
1672 | ||
1673 | /* Make sure X resources of the face and image are loaded. */ | |
1674 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1675 | prepare_image_for_display (it->f, img); | |
1676 | ||
9ef2e2cf | 1677 | it->ascent = it->phys_ascent = image_ascent (img, face); |
d6ff54d5 JR |
1678 | it->descent = it->phys_descent = img->height + 2 * img->vmargin - it->ascent; |
1679 | it->pixel_width = img->width + 2 * img->hmargin; | |
791f420f JR |
1680 | |
1681 | it->nglyphs = 1; | |
1682 | ||
1683 | if (face->box != FACE_NO_BOX) | |
1684 | { | |
60222d69 AI |
1685 | if (face->box_line_width > 0) |
1686 | { | |
1687 | it->ascent += face->box_line_width; | |
1688 | it->descent += face->box_line_width; | |
1689 | } | |
791f420f JR |
1690 | |
1691 | if (it->start_of_box_run_p) | |
60222d69 | 1692 | it->pixel_width += abs (face->box_line_width); |
791f420f | 1693 | if (it->end_of_box_run_p) |
60222d69 | 1694 | it->pixel_width += abs (face->box_line_width); |
791f420f JR |
1695 | } |
1696 | ||
1697 | take_vertical_position_into_account (it); | |
1698 | ||
1699 | if (it->glyph_row) | |
1700 | { | |
1701 | struct glyph *glyph; | |
1702 | enum glyph_row_area area = it->area; | |
1703 | ||
1704 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1705 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1706 | { | |
791f420f JR |
1707 | glyph->charpos = CHARPOS (it->position); |
1708 | glyph->object = it->object; | |
ec48c3a7 | 1709 | glyph->pixel_width = it->pixel_width; |
791f420f | 1710 | glyph->voffset = it->voffset; |
ec48c3a7 | 1711 | glyph->type = IMAGE_GLYPH; |
791f420f | 1712 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1713 | glyph->left_box_line_p = it->start_of_box_run_p; |
1714 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1715 | glyph->overlaps_vertically_p = 0; | |
1716 | glyph->padding_p = 0; | |
1717 | glyph->glyph_not_available_p = 0; | |
1718 | glyph->face_id = it->face_id; | |
1719 | glyph->u.img_id = img->id; | |
1720 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1721 | ++it->glyph_row->used[area]; |
1722 | } | |
1723 | } | |
1724 | } | |
1725 | ||
1726 | ||
1727 | /* Append a stretch glyph to IT->glyph_row. OBJECT is the source | |
1728 | of the glyph, WIDTH and HEIGHT are the width and height of the | |
1729 | stretch. ASCENT is the percentage/100 of HEIGHT to use for the | |
1730 | ascent of the glyph (0 <= ASCENT <= 1). */ | |
1731 | ||
1732 | static void | |
1733 | x_append_stretch_glyph (it, object, width, height, ascent) | |
1734 | struct it *it; | |
1735 | Lisp_Object object; | |
1736 | int width, height; | |
1737 | double ascent; | |
1738 | { | |
1739 | struct glyph *glyph; | |
1740 | enum glyph_row_area area = it->area; | |
1741 | ||
1742 | xassert (ascent >= 0 && ascent <= 1); | |
1743 | ||
1744 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1745 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1746 | { | |
791f420f JR |
1747 | glyph->charpos = CHARPOS (it->position); |
1748 | glyph->object = object; | |
ec48c3a7 | 1749 | glyph->pixel_width = width; |
791f420f | 1750 | glyph->voffset = it->voffset; |
ec48c3a7 | 1751 | glyph->type = STRETCH_GLYPH; |
791f420f | 1752 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1753 | glyph->left_box_line_p = it->start_of_box_run_p; |
1754 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1755 | glyph->overlaps_vertically_p = 0; | |
1756 | glyph->padding_p = 0; | |
1757 | glyph->glyph_not_available_p = 0; | |
1758 | glyph->face_id = it->face_id; | |
1759 | glyph->u.stretch.ascent = height * ascent; | |
1760 | glyph->u.stretch.height = height; | |
1761 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1762 | ++it->glyph_row->used[area]; |
1763 | } | |
1764 | } | |
1765 | ||
1766 | ||
1767 | /* Produce a stretch glyph for iterator IT. IT->object is the value | |
1768 | of the glyph property displayed. The value must be a list | |
1769 | `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs | |
1770 | being recognized: | |
1771 | ||
1772 | 1. `:width WIDTH' specifies that the space should be WIDTH * | |
1773 | canonical char width wide. WIDTH may be an integer or floating | |
1774 | point number. | |
1775 | ||
1776 | 2. `:relative-width FACTOR' specifies that the width of the stretch | |
1777 | should be computed from the width of the first character having the | |
1778 | `glyph' property, and should be FACTOR times that width. | |
1779 | ||
1780 | 3. `:align-to HPOS' specifies that the space should be wide enough | |
1781 | to reach HPOS, a value in canonical character units. | |
1782 | ||
1783 | Exactly one of the above pairs must be present. | |
1784 | ||
1785 | 4. `:height HEIGHT' specifies that the height of the stretch produced | |
1786 | should be HEIGHT, measured in canonical character units. | |
1787 | ||
1788 | 5. `:relative-height FACTOR' specifies that the height of the the | |
1789 | stretch should be FACTOR times the height of the characters having | |
1790 | the glyph property. | |
1791 | ||
1792 | Either none or exactly one of 4 or 5 must be present. | |
1793 | ||
1794 | 6. `:ascent ASCENT' specifies that ASCENT percent of the height | |
1795 | of the stretch should be used for the ascent of the stretch. | |
1796 | ASCENT must be in the range 0 <= ASCENT <= 100. */ | |
1797 | ||
1798 | #define NUMVAL(X) \ | |
1799 | ((INTEGERP (X) || FLOATP (X)) \ | |
1800 | ? XFLOATINT (X) \ | |
1801 | : - 1) | |
1802 | ||
1803 | ||
1804 | static void | |
1805 | x_produce_stretch_glyph (it) | |
1806 | struct it *it; | |
1807 | { | |
1808 | /* (space :width WIDTH :height HEIGHT. */ | |
c2cc16fa JR |
1809 | #if GLYPH_DEBUG |
1810 | extern Lisp_Object Qspace; | |
1811 | #endif | |
1812 | extern Lisp_Object QCwidth, QCheight, QCascent; | |
791f420f JR |
1813 | extern Lisp_Object QCrelative_width, QCrelative_height; |
1814 | extern Lisp_Object QCalign_to; | |
1815 | Lisp_Object prop, plist; | |
1816 | double width = 0, height = 0, ascent = 0; | |
1817 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
1818 | XFontStruct *font = face->font ? face->font : FRAME_FONT (it->f); | |
1819 | ||
1820 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1821 | ||
1822 | /* List should start with `space'. */ | |
1823 | xassert (CONSP (it->object) && EQ (XCAR (it->object), Qspace)); | |
1824 | plist = XCDR (it->object); | |
1825 | ||
1826 | /* Compute the width of the stretch. */ | |
1827 | if (prop = Fplist_get (plist, QCwidth), | |
1828 | NUMVAL (prop) > 0) | |
1829 | /* Absolute width `:width WIDTH' specified and valid. */ | |
1830 | width = NUMVAL (prop) * CANON_X_UNIT (it->f); | |
1831 | else if (prop = Fplist_get (plist, QCrelative_width), | |
1832 | NUMVAL (prop) > 0) | |
1833 | { | |
1834 | /* Relative width `:relative-width FACTOR' specified and valid. | |
1835 | Compute the width of the characters having the `glyph' | |
1836 | property. */ | |
1837 | struct it it2; | |
1838 | unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); | |
1839 | ||
1840 | it2 = *it; | |
1841 | if (it->multibyte_p) | |
1842 | { | |
1843 | int maxlen = ((IT_BYTEPOS (*it) >= GPT ? ZV : GPT) | |
1844 | - IT_BYTEPOS (*it)); | |
1845 | it2.c = STRING_CHAR_AND_LENGTH (p, maxlen, it2.len); | |
1846 | } | |
1847 | else | |
1848 | it2.c = *p, it2.len = 1; | |
1849 | ||
1850 | it2.glyph_row = NULL; | |
1851 | it2.what = IT_CHARACTER; | |
1852 | x_produce_glyphs (&it2); | |
1853 | width = NUMVAL (prop) * it2.pixel_width; | |
1854 | } | |
1855 | else if (prop = Fplist_get (plist, QCalign_to), | |
1856 | NUMVAL (prop) > 0) | |
1857 | width = NUMVAL (prop) * CANON_X_UNIT (it->f) - it->current_x; | |
1858 | else | |
1859 | /* Nothing specified -> width defaults to canonical char width. */ | |
1860 | width = CANON_X_UNIT (it->f); | |
1861 | ||
1862 | /* Compute height. */ | |
1863 | if (prop = Fplist_get (plist, QCheight), | |
1864 | NUMVAL (prop) > 0) | |
1865 | height = NUMVAL (prop) * CANON_Y_UNIT (it->f); | |
1866 | else if (prop = Fplist_get (plist, QCrelative_height), | |
1867 | NUMVAL (prop) > 0) | |
1868 | height = FONT_HEIGHT (font) * NUMVAL (prop); | |
1869 | else | |
1870 | height = FONT_HEIGHT (font); | |
1871 | ||
1872 | /* Compute percentage of height used for ascent. If | |
1873 | `:ascent ASCENT' is present and valid, use that. Otherwise, | |
1874 | derive the ascent from the font in use. */ | |
1875 | if (prop = Fplist_get (plist, QCascent), | |
1876 | NUMVAL (prop) > 0 && NUMVAL (prop) <= 100) | |
1877 | ascent = NUMVAL (prop) / 100.0; | |
1878 | else | |
1879 | ascent = (double) FONT_BASE (font) / FONT_HEIGHT (font); | |
1880 | ||
1881 | if (width <= 0) | |
1882 | width = 1; | |
1883 | if (height <= 0) | |
1884 | height = 1; | |
1885 | ||
1886 | if (it->glyph_row) | |
1887 | { | |
1888 | Lisp_Object object = it->stack[it->sp - 1].string; | |
1889 | if (!STRINGP (object)) | |
1890 | object = it->w->buffer; | |
1891 | x_append_stretch_glyph (it, object, width, height, ascent); | |
1892 | } | |
1893 | ||
1894 | it->pixel_width = width; | |
1895 | it->ascent = it->phys_ascent = height * ascent; | |
1896 | it->descent = it->phys_descent = height - it->ascent; | |
1897 | it->nglyphs = 1; | |
1898 | ||
1899 | if (face->box != FACE_NO_BOX) | |
1900 | { | |
60222d69 AI |
1901 | if (face->box_line_width > 0) |
1902 | { | |
1903 | it->ascent += face->box_line_width; | |
1904 | it->descent += face->box_line_width; | |
1905 | } | |
791f420f JR |
1906 | |
1907 | if (it->start_of_box_run_p) | |
60222d69 | 1908 | it->pixel_width += abs (face->box_line_width); |
791f420f | 1909 | if (it->end_of_box_run_p) |
60222d69 | 1910 | it->pixel_width += abs (face->box_line_width); |
791f420f JR |
1911 | } |
1912 | ||
1913 | take_vertical_position_into_account (it); | |
1914 | } | |
1915 | ||
1916 | /* Return proper value to be used as baseline offset of font that has | |
1917 | ASCENT and DESCENT to draw characters by the font at the vertical | |
1918 | center of the line of frame F. | |
1919 | ||
1920 | Here, out task is to find the value of BOFF in the following figure; | |
1921 | ||
1922 | -------------------------+-----------+- | |
1923 | -+-+---------+-+ | | | |
1924 | | | | | | | | |
1925 | | | | | F_ASCENT F_HEIGHT | |
1926 | | | | ASCENT | | | |
1927 | HEIGHT | | | | | | |
1928 | | | |-|-+------+-----------|------- baseline | |
1929 | | | | | BOFF | | | |
1930 | | |---------|-+-+ | | | |
1931 | | | | DESCENT | | | |
1932 | -+-+---------+-+ F_DESCENT | | |
1933 | -------------------------+-----------+- | |
1934 | ||
1935 | -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT | |
1936 | BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT | |
1937 | DESCENT = FONT->descent | |
1938 | HEIGHT = FONT_HEIGHT (FONT) | |
1939 | F_DESCENT = (F->output_data.x->font->descent | |
1940 | - F->output_data.x->baseline_offset) | |
1941 | F_HEIGHT = FRAME_LINE_HEIGHT (F) | |
1942 | */ | |
1943 | ||
1944 | #define VCENTER_BASELINE_OFFSET(FONT, F) \ | |
458f45fa KH |
1945 | (FONT_DESCENT (FONT) \ |
1946 | + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \ | |
1947 | + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \ | |
1948 | - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F))) | |
791f420f JR |
1949 | |
1950 | /* Produce glyphs/get display metrics for the display element IT is | |
1951 | loaded with. See the description of struct display_iterator in | |
1952 | dispextern.h for an overview of struct display_iterator. */ | |
1953 | ||
1954 | static void | |
1955 | x_produce_glyphs (it) | |
1956 | struct it *it; | |
1957 | { | |
93ff4395 JR |
1958 | it->glyph_not_available_p = 0; |
1959 | ||
791f420f JR |
1960 | if (it->what == IT_CHARACTER) |
1961 | { | |
1962 | wchar_t char2b; | |
1963 | XFontStruct *font; | |
93ff4395 | 1964 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
791f420f | 1965 | XCharStruct *pcm; |
93ff4395 | 1966 | int font_not_found_p; |
791f420f JR |
1967 | struct font_info *font_info; |
1968 | int boff; /* baseline offset */ | |
2d0c0bd7 JR |
1969 | /* We may change it->multibyte_p upon unibyte<->multibyte |
1970 | conversion. So, save the current value now and restore it | |
1971 | later. | |
1972 | ||
1973 | Note: It seems that we don't have to record multibyte_p in | |
1974 | struct glyph because the character code itself tells if or | |
1975 | not the character is multibyte. Thus, in the future, we must | |
1976 | consider eliminating the field `multibyte_p' in the struct | |
1977 | glyph. | |
1978 | */ | |
1979 | int saved_multibyte_p = it->multibyte_p; | |
791f420f | 1980 | |
93ff4395 JR |
1981 | /* Maybe translate single-byte characters to multibyte, or the |
1982 | other way. */ | |
791f420f | 1983 | it->char_to_display = it->c; |
93ff4395 JR |
1984 | if (!ASCII_BYTE_P (it->c)) |
1985 | { | |
1986 | if (unibyte_display_via_language_environment | |
1987 | && SINGLE_BYTE_CHAR_P (it->c) | |
1988 | && (it->c >= 0240 | |
1989 | || !NILP (Vnonascii_translation_table))) | |
1990 | { | |
1991 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
2d0c0bd7 | 1992 | it->multibyte_p = 1; |
93ff4395 JR |
1993 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1994 | face = FACE_FROM_ID (it->f, it->face_id); | |
1995 | } | |
1996 | else if (!SINGLE_BYTE_CHAR_P (it->c) | |
1997 | && !it->multibyte_p) | |
1998 | { | |
9f5a911b | 1999 | it->multibyte_p = 1; |
93ff4395 JR |
2000 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
2001 | face = FACE_FROM_ID (it->f, it->face_id); | |
2002 | } | |
2003 | } | |
791f420f | 2004 | |
93ff4395 JR |
2005 | /* Get font to use. Encode IT->char_to_display. */ |
2006 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
2007 | it->face_id, &char2b, | |
2008 | it->multibyte_p); | |
791f420f JR |
2009 | font = face->font; |
2010 | ||
2011 | /* When no suitable font found, use the default font. */ | |
2012 | font_not_found_p = font == NULL; | |
2013 | if (font_not_found_p) | |
2014 | { | |
2015 | font = FRAME_FONT (it->f); | |
2016 | boff = it->f->output_data.w32->baseline_offset; | |
2017 | font_info = NULL; | |
2018 | } | |
2019 | else | |
2020 | { | |
2021 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2022 | boff = font_info->baseline_offset; | |
2023 | if (font_info->vertical_centering) | |
2024 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2025 | } | |
2026 | ||
791f420f JR |
2027 | if (it->char_to_display >= ' ' |
2028 | && (!it->multibyte_p || it->char_to_display < 128)) | |
2029 | { | |
2030 | /* Either unibyte or ASCII. */ | |
2031 | int stretched_p; | |
2032 | ||
2033 | it->nglyphs = 1; | |
2034 | ||
82f9d565 | 2035 | pcm = w32_per_char_metric (font, &char2b, |
9127e20e | 2036 | font->bdf ? BDF_1D_FONT : ANSI_FONT); |
791f420f JR |
2037 | it->ascent = FONT_BASE (font) + boff; |
2038 | it->descent = FONT_DESCENT (font) - boff; | |
791f420f | 2039 | |
9ef2e2cf JR |
2040 | if (pcm) |
2041 | { | |
2042 | it->phys_ascent = pcm->ascent + boff; | |
2043 | it->phys_descent = pcm->descent - boff; | |
2044 | it->pixel_width = pcm->width; | |
2045 | } | |
2046 | else | |
2047 | { | |
2048 | it->glyph_not_available_p = 1; | |
9127e20e JR |
2049 | it->phys_ascent = FONT_BASE (font) + boff; |
2050 | it->phys_descent = FONT_DESCENT (font) - boff; | |
2051 | it->pixel_width = FONT_WIDTH (font); | |
9ef2e2cf JR |
2052 | } |
2053 | ||
791f420f JR |
2054 | /* If this is a space inside a region of text with |
2055 | `space-width' property, change its width. */ | |
2056 | stretched_p = it->char_to_display == ' ' && !NILP (it->space_width); | |
2057 | if (stretched_p) | |
2058 | it->pixel_width *= XFLOATINT (it->space_width); | |
2059 | ||
2060 | /* If face has a box, add the box thickness to the character | |
2061 | height. If character has a box line to the left and/or | |
2062 | right, add the box line width to the character's width. */ | |
2063 | if (face->box != FACE_NO_BOX) | |
2064 | { | |
2065 | int thick = face->box_line_width; | |
2066 | ||
60222d69 AI |
2067 | if (thick > 0) |
2068 | { | |
2069 | it->ascent += thick; | |
2070 | it->descent += thick; | |
2071 | } | |
2072 | else | |
2073 | thick = -thick; | |
791f420f JR |
2074 | |
2075 | if (it->start_of_box_run_p) | |
2076 | it->pixel_width += thick; | |
2077 | if (it->end_of_box_run_p) | |
2078 | it->pixel_width += thick; | |
2079 | } | |
2080 | ||
2081 | /* If face has an overline, add the height of the overline | |
2082 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2083 | if (face->overline_p) | |
2084 | it->ascent += 2; | |
2085 | ||
2086 | take_vertical_position_into_account (it); | |
2087 | ||
2088 | /* If we have to actually produce glyphs, do it. */ | |
2089 | if (it->glyph_row) | |
2090 | { | |
2091 | if (stretched_p) | |
2092 | { | |
2093 | /* Translate a space with a `space-width' property | |
2094 | into a stretch glyph. */ | |
2095 | double ascent = (double) FONT_BASE (font) | |
2096 | / FONT_HEIGHT (font); | |
2097 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
2098 | it->ascent + it->descent, ascent); | |
2099 | } | |
2100 | else | |
2101 | x_append_glyph (it); | |
2102 | ||
2103 | /* If characters with lbearing or rbearing are displayed | |
2104 | in this line, record that fact in a flag of the | |
2105 | glyph row. This is used to optimize X output code. */ | |
9ef2e2cf | 2106 | if (pcm && (pcm->lbearing < 0 || pcm->rbearing > pcm->width)) |
791f420f JR |
2107 | it->glyph_row->contains_overlapping_glyphs_p = 1; |
2108 | } | |
2109 | } | |
2110 | else if (it->char_to_display == '\n') | |
2111 | { | |
2112 | /* A newline has no width but we need the height of the line. */ | |
2113 | it->pixel_width = 0; | |
2114 | it->nglyphs = 0; | |
2115 | it->ascent = it->phys_ascent = FONT_BASE (font) + boff; | |
2116 | it->descent = it->phys_descent = FONT_DESCENT (font) - boff; | |
2117 | ||
60222d69 AI |
2118 | if (face->box != FACE_NO_BOX |
2119 | && face->box_line_width > 0) | |
791f420f | 2120 | { |
60222d69 AI |
2121 | it->ascent += face->box_line_width; |
2122 | it->descent += face->box_line_width; | |
791f420f JR |
2123 | } |
2124 | } | |
2125 | else if (it->char_to_display == '\t') | |
2126 | { | |
2127 | int tab_width = it->tab_width * CANON_X_UNIT (it->f); | |
9ef2e2cf | 2128 | int x = it->current_x + it->continuation_lines_width; |
791f420f JR |
2129 | int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; |
2130 | ||
9127e20e JR |
2131 | /* If the distance from the current position to the next tab |
2132 | stop is less than a canonical character width, use the | |
2133 | tab stop after that. */ | |
2134 | if (next_tab_x - x < CANON_X_UNIT (it->f)) | |
2135 | next_tab_x += tab_width; | |
2136 | ||
791f420f JR |
2137 | it->pixel_width = next_tab_x - x; |
2138 | it->nglyphs = 1; | |
2139 | it->ascent = it->phys_ascent = FONT_BASE (font) + boff; | |
2140 | it->descent = it->phys_descent = FONT_DESCENT (font) - boff; | |
2141 | ||
2142 | if (it->glyph_row) | |
2143 | { | |
2144 | double ascent = (double) it->ascent / (it->ascent + it->descent); | |
2145 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
2146 | it->ascent + it->descent, ascent); | |
2147 | } | |
2148 | } | |
2149 | else | |
2150 | { | |
00fe468b JR |
2151 | /* A multi-byte character. |
2152 | If we found a font, this font should give us the right | |
791f420f JR |
2153 | metrics. If we didn't find a font, use the frame's |
2154 | default font and calculate the width of the character | |
2155 | from the charset width; this is what old redisplay code | |
2156 | did. */ | |
9127e20e JR |
2157 | enum w32_char_font_type type; |
2158 | ||
2159 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (it->c)) == 1) | |
2160 | type = BDF_1D_FONT; | |
2161 | else if (font->bdf) | |
2162 | type = BDF_2D_FONT; | |
2163 | else | |
2164 | type = UNICODE_FONT; | |
2165 | ||
82f9d565 | 2166 | pcm = w32_per_char_metric (font, &char2b, type); |
00fe468b | 2167 | |
93ff4395 JR |
2168 | if (font_not_found_p || !pcm) |
2169 | { | |
2170 | int charset = CHAR_CHARSET (it->char_to_display); | |
00fe468b | 2171 | |
93ff4395 JR |
2172 | it->glyph_not_available_p = 1; |
2173 | it->pixel_width = (FONT_WIDTH (FRAME_FONT (it->f)) | |
2174 | * CHARSET_WIDTH (charset)); | |
2175 | it->phys_ascent = FONT_BASE (font) + boff; | |
2176 | it->phys_descent = FONT_DESCENT (font) - boff; | |
2177 | } | |
2178 | else | |
2179 | { | |
9ef2e2cf | 2180 | it->pixel_width = pcm->width; |
93ff4395 JR |
2181 | it->phys_ascent = pcm->ascent + boff; |
2182 | it->phys_descent = pcm->descent - boff; | |
2183 | if (it->glyph_row | |
2184 | && (pcm->lbearing < 0 | |
2185 | || pcm->rbearing > pcm->width)) | |
2186 | it->glyph_row->contains_overlapping_glyphs_p = 1; | |
00fe468b | 2187 | } |
791f420f JR |
2188 | it->nglyphs = 1; |
2189 | it->ascent = FONT_BASE (font) + boff; | |
2190 | it->descent = FONT_DESCENT (font) - boff; | |
791f420f JR |
2191 | if (face->box != FACE_NO_BOX) |
2192 | { | |
2193 | int thick = face->box_line_width; | |
60222d69 AI |
2194 | |
2195 | if (thick > 0) | |
2196 | { | |
2197 | it->ascent += thick; | |
2198 | it->descent += thick; | |
2199 | } | |
2200 | else | |
2201 | thick = - thick; | |
791f420f JR |
2202 | |
2203 | if (it->start_of_box_run_p) | |
2204 | it->pixel_width += thick; | |
2205 | if (it->end_of_box_run_p) | |
2206 | it->pixel_width += thick; | |
2207 | } | |
2208 | ||
2209 | /* If face has an overline, add the height of the overline | |
2210 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2211 | if (face->overline_p) | |
2212 | it->ascent += 2; | |
2213 | ||
2214 | take_vertical_position_into_account (it); | |
2215 | ||
2216 | if (it->glyph_row) | |
2217 | x_append_glyph (it); | |
2218 | } | |
2d0c0bd7 | 2219 | it->multibyte_p = saved_multibyte_p; |
791f420f JR |
2220 | } |
2221 | else if (it->what == IT_COMPOSITION) | |
2222 | { | |
01b220b6 JR |
2223 | /* Note: A composition is represented as one glyph in the |
2224 | glyph matrix. There are no padding glyphs. */ | |
2225 | wchar_t char2b; | |
2226 | XFontStruct *font; | |
2227 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
2228 | XCharStruct *pcm; | |
2229 | int font_not_found_p; | |
2230 | struct font_info *font_info; | |
2231 | int boff; /* baseline offset */ | |
2232 | struct composition *cmp = composition_table[it->cmp_id]; | |
2233 | ||
2234 | /* Maybe translate single-byte characters to multibyte. */ | |
2235 | it->char_to_display = it->c; | |
2236 | if (unibyte_display_via_language_environment | |
2237 | && SINGLE_BYTE_CHAR_P (it->c) | |
2238 | && (it->c >= 0240 | |
2239 | || (it->c >= 0200 | |
2240 | && !NILP (Vnonascii_translation_table)))) | |
2241 | { | |
2242 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
2243 | } | |
2244 | ||
2245 | /* Get face and font to use. Encode IT->char_to_display. */ | |
2246 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); | |
2247 | face = FACE_FROM_ID (it->f, it->face_id); | |
2248 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
2249 | it->face_id, &char2b, it->multibyte_p); | |
2250 | font = face->font; | |
2251 | ||
2252 | /* When no suitable font found, use the default font. */ | |
2253 | font_not_found_p = font == NULL; | |
2254 | if (font_not_found_p) | |
2255 | { | |
2256 | font = FRAME_FONT (it->f); | |
2257 | boff = it->f->output_data.w32->baseline_offset; | |
2258 | font_info = NULL; | |
2259 | } | |
2260 | else | |
2261 | { | |
2262 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2263 | boff = font_info->baseline_offset; | |
2264 | if (font_info->vertical_centering) | |
2265 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2266 | } | |
2267 | ||
2268 | /* There are no padding glyphs, so there is only one glyph to | |
2269 | produce for the composition. Important is that pixel_width, | |
2270 | ascent and descent are the values of what is drawn by | |
2271 | draw_glyphs (i.e. the values of the overall glyphs composed). */ | |
2272 | it->nglyphs = 1; | |
2273 | ||
2274 | /* If we have not yet calculated pixel size data of glyphs of | |
2275 | the composition for the current face font, calculate them | |
2276 | now. Theoretically, we have to check all fonts for the | |
2277 | glyphs, but that requires much time and memory space. So, | |
2278 | here we check only the font of the first glyph. This leads | |
2279 | to incorrect display very rarely, and C-l (recenter) can | |
2280 | correct the display anyway. */ | |
2281 | if (cmp->font != (void *) font) | |
2282 | { | |
2283 | /* Ascent and descent of the font of the first character of | |
2284 | this composition (adjusted by baseline offset). Ascent | |
2285 | and descent of overall glyphs should not be less than | |
2286 | them respectively. */ | |
2287 | int font_ascent = FONT_BASE (font) + boff; | |
2288 | int font_descent = FONT_DESCENT (font) - boff; | |
2289 | /* Bounding box of the overall glyphs. */ | |
2290 | int leftmost, rightmost, lowest, highest; | |
2291 | int i, width, ascent, descent; | |
1521ce96 | 2292 | enum w32_char_font_type font_type; |
01b220b6 JR |
2293 | |
2294 | cmp->font = (void *) font; | |
2295 | ||
2296 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (it->c)) == 1) | |
2297 | font_type = BDF_1D_FONT; | |
2298 | else if (font->bdf) | |
2299 | font_type = BDF_2D_FONT; | |
2300 | else | |
2301 | font_type = UNICODE_FONT; | |
2302 | ||
2303 | /* Initialize the bounding box. */ | |
f201d732 JR |
2304 | if (font_info |
2305 | && (pcm = w32_per_char_metric (font, &char2b, font_type))) | |
01b220b6 JR |
2306 | { |
2307 | width = pcm->width; | |
2308 | ascent = pcm->ascent; | |
2309 | descent = pcm->descent; | |
2310 | } | |
2311 | else | |
2312 | { | |
2313 | width = FONT_WIDTH (font); | |
2314 | ascent = FONT_BASE (font); | |
2315 | descent = FONT_DESCENT (font); | |
2316 | } | |
2317 | ||
2318 | rightmost = width; | |
2319 | lowest = - descent + boff; | |
2320 | highest = ascent + boff; | |
2321 | leftmost = 0; | |
2322 | ||
2323 | if (font_info | |
2324 | && font_info->default_ascent | |
2325 | && CHAR_TABLE_P (Vuse_default_ascent) | |
2326 | && !NILP (Faref (Vuse_default_ascent, | |
2327 | make_number (it->char_to_display)))) | |
2328 | highest = font_info->default_ascent + boff; | |
2329 | ||
2330 | /* Draw the first glyph at the normal position. It may be | |
2331 | shifted to right later if some other glyphs are drawn at | |
2332 | the left. */ | |
2333 | cmp->offsets[0] = 0; | |
2334 | cmp->offsets[1] = boff; | |
2335 | ||
2336 | /* Set cmp->offsets for the remaining glyphs. */ | |
2337 | for (i = 1; i < cmp->glyph_len; i++) | |
2338 | { | |
2339 | int left, right, btm, top; | |
2340 | int ch = COMPOSITION_GLYPH (cmp, i); | |
2341 | int face_id = FACE_FOR_CHAR (it->f, face, ch); | |
2342 | ||
2343 | face = FACE_FROM_ID (it->f, face_id); | |
2344 | x_get_char_face_and_encoding (it->f, ch, face->id, &char2b, | |
2345 | it->multibyte_p); | |
2346 | font = face->font; | |
2347 | if (font == NULL) | |
2348 | { | |
2349 | font = FRAME_FONT (it->f); | |
2350 | boff = it->f->output_data.w32->baseline_offset; | |
2351 | font_info = NULL; | |
2352 | } | |
2353 | else | |
2354 | { | |
2355 | font_info | |
2356 | = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2357 | boff = font_info->baseline_offset; | |
2358 | if (font_info->vertical_centering) | |
2359 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2360 | } | |
2361 | ||
2362 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (ch)) == 1) | |
2363 | font_type = BDF_1D_FONT; | |
2364 | else if (font->bdf) | |
2365 | font_type = BDF_2D_FONT; | |
2366 | else | |
2367 | font_type = UNICODE_FONT; | |
2368 | ||
f201d732 JR |
2369 | if (font_info |
2370 | && (pcm = w32_per_char_metric (font, &char2b, font_type))) | |
01b220b6 JR |
2371 | { |
2372 | width = pcm->width; | |
2373 | ascent = pcm->ascent; | |
2374 | descent = pcm->descent; | |
2375 | } | |
2376 | else | |
2377 | { | |
2378 | width = FONT_WIDTH (font); | |
f201d732 JR |
2379 | ascent = 1; |
2380 | descent = 0; | |
01b220b6 JR |
2381 | } |
2382 | ||
2383 | if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) | |
2384 | { | |
2385 | /* Relative composition with or without | |
2386 | alternate chars. */ | |
2387 | left = (leftmost + rightmost - width) / 2; | |
2388 | btm = - descent + boff; | |
2389 | if (font_info && font_info->relative_compose | |
2390 | && (! CHAR_TABLE_P (Vignore_relative_composition) | |
2391 | || NILP (Faref (Vignore_relative_composition, | |
2392 | make_number (ch))))) | |
2393 | { | |
2394 | ||
2395 | if (- descent >= font_info->relative_compose) | |
2396 | /* One extra pixel between two glyphs. */ | |
2397 | btm = highest + 1; | |
2398 | else if (ascent <= 0) | |
2399 | /* One extra pixel between two glyphs. */ | |
2400 | btm = lowest - 1 - ascent - descent; | |
2401 | } | |
2402 | } | |
2403 | else | |
2404 | { | |
2405 | /* A composition rule is specified by an integer | |
2406 | value that encodes global and new reference | |
2407 | points (GREF and NREF). GREF and NREF are | |
2408 | specified by numbers as below: | |
2409 | ||
2410 | 0---1---2 -- ascent | |
2411 | | | | |
2412 | | | | |
2413 | | | | |
2414 | 9--10--11 -- center | |
2415 | | | | |
2416 | ---3---4---5--- baseline | |
2417 | | | | |
2418 | 6---7---8 -- descent | |
2419 | */ | |
2420 | int rule = COMPOSITION_RULE (cmp, i); | |
2421 | int gref, nref, grefx, grefy, nrefx, nrefy; | |
2422 | ||
2423 | COMPOSITION_DECODE_RULE (rule, gref, nref); | |
2424 | grefx = gref % 3, nrefx = nref % 3; | |
2425 | grefy = gref / 3, nrefy = nref / 3; | |
2426 | ||
2427 | left = (leftmost | |
2428 | + grefx * (rightmost - leftmost) / 2 | |
2429 | - nrefx * width / 2); | |
2430 | btm = ((grefy == 0 ? highest | |
2431 | : grefy == 1 ? 0 | |
2432 | : grefy == 2 ? lowest | |
2433 | : (highest + lowest) / 2) | |
2434 | - (nrefy == 0 ? ascent + descent | |
2435 | : nrefy == 1 ? descent - boff | |
2436 | : nrefy == 2 ? 0 | |
2437 | : (ascent + descent) / 2)); | |
2438 | } | |
2439 | ||
2440 | cmp->offsets[i * 2] = left; | |
2441 | cmp->offsets[i * 2 + 1] = btm + descent; | |
2442 | ||
2443 | /* Update the bounding box of the overall glyphs. */ | |
2444 | right = left + width; | |
2445 | top = btm + descent + ascent; | |
2446 | if (left < leftmost) | |
2447 | leftmost = left; | |
2448 | if (right > rightmost) | |
2449 | rightmost = right; | |
2450 | if (top > highest) | |
2451 | highest = top; | |
2452 | if (btm < lowest) | |
2453 | lowest = btm; | |
2454 | } | |
2455 | ||
2456 | /* If there are glyphs whose x-offsets are negative, | |
2457 | shift all glyphs to the right and make all x-offsets | |
2458 | non-negative. */ | |
2459 | if (leftmost < 0) | |
2460 | { | |
2461 | for (i = 0; i < cmp->glyph_len; i++) | |
2462 | cmp->offsets[i * 2] -= leftmost; | |
2463 | rightmost -= leftmost; | |
2464 | } | |
2465 | ||
2466 | cmp->pixel_width = rightmost; | |
2467 | cmp->ascent = highest; | |
2468 | cmp->descent = - lowest; | |
2469 | if (cmp->ascent < font_ascent) | |
2470 | cmp->ascent = font_ascent; | |
2471 | if (cmp->descent < font_descent) | |
2472 | cmp->descent = font_descent; | |
2473 | } | |
2474 | ||
2475 | it->pixel_width = cmp->pixel_width; | |
2476 | it->ascent = it->phys_ascent = cmp->ascent; | |
2477 | it->descent = it->phys_descent = cmp->descent; | |
2478 | ||
2479 | if (face->box != FACE_NO_BOX) | |
2480 | { | |
2481 | int thick = face->box_line_width; | |
60222d69 AI |
2482 | |
2483 | if (thick > 0) | |
2484 | { | |
2485 | it->ascent += thick; | |
2486 | it->descent += thick; | |
2487 | } | |
2488 | else | |
2489 | thick = - thick; | |
01b220b6 JR |
2490 | |
2491 | if (it->start_of_box_run_p) | |
2492 | it->pixel_width += thick; | |
2493 | if (it->end_of_box_run_p) | |
2494 | it->pixel_width += thick; | |
2495 | } | |
2496 | ||
2497 | /* If face has an overline, add the height of the overline | |
2498 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2499 | if (face->overline_p) | |
2500 | it->ascent += 2; | |
2501 | ||
2502 | take_vertical_position_into_account (it); | |
2503 | ||
2504 | if (it->glyph_row) | |
2505 | x_append_composite_glyph (it); | |
791f420f JR |
2506 | } |
2507 | else if (it->what == IT_IMAGE) | |
2508 | x_produce_image_glyph (it); | |
2509 | else if (it->what == IT_STRETCH) | |
2510 | x_produce_stretch_glyph (it); | |
2511 | ||
c2cc16fa JR |
2512 | /* Accumulate dimensions. Note: can't assume that it->descent > 0 |
2513 | because this isn't true for images with `:ascent 100'. */ | |
2514 | xassert (it->ascent >= 0 && it->descent >= 0); | |
791f420f JR |
2515 | if (it->area == TEXT_AREA) |
2516 | it->current_x += it->pixel_width; | |
2517 | ||
9ef2e2cf JR |
2518 | it->descent += it->extra_line_spacing; |
2519 | ||
791f420f JR |
2520 | it->max_ascent = max (it->max_ascent, it->ascent); |
2521 | it->max_descent = max (it->max_descent, it->descent); | |
2522 | it->max_phys_ascent = max (it->max_phys_ascent, it->phys_ascent); | |
2523 | it->max_phys_descent = max (it->max_phys_descent, it->phys_descent); | |
2524 | } | |
2525 | ||
2526 | ||
2527 | /* Estimate the pixel height of the mode or top line on frame F. | |
2528 | FACE_ID specifies what line's height to estimate. */ | |
2529 | ||
2530 | int | |
2531 | x_estimate_mode_line_height (f, face_id) | |
2532 | struct frame *f; | |
2533 | enum face_id face_id; | |
2534 | { | |
250cfece | 2535 | int height = FONT_HEIGHT (FRAME_FONT (f)); |
791f420f JR |
2536 | |
2537 | /* This function is called so early when Emacs starts that the face | |
2538 | cache and mode line face are not yet initialized. */ | |
2539 | if (FRAME_FACE_CACHE (f)) | |
2540 | { | |
2541 | struct face *face = FACE_FROM_ID (f, face_id); | |
9ef2e2cf | 2542 | if (face) |
250cfece JR |
2543 | { |
2544 | if (face->font) | |
2545 | height = FONT_HEIGHT (face->font); | |
60222d69 AI |
2546 | if (face->box_line_width > 0) |
2547 | height += 2 * face->box_line_width; | |
250cfece | 2548 | } |
791f420f JR |
2549 | } |
2550 | ||
2551 | return height; | |
2552 | } | |
cabb23bc | 2553 | |
cabb23bc | 2554 | \f |
791f420f JR |
2555 | /*********************************************************************** |
2556 | Glyph display | |
2557 | ***********************************************************************/ | |
2558 | ||
2559 | /* A sequence of glyphs to be drawn in the same face. | |
2560 | ||
2561 | This data structure is not really completely X specific, so it | |
2562 | could possibly, at least partially, be useful for other systems. It | |
2563 | is currently not part of the external redisplay interface because | |
2564 | it's not clear what other systems will need. */ | |
2565 | ||
2566 | struct glyph_string | |
2567 | { | |
2568 | /* X-origin of the string. */ | |
2569 | int x; | |
2570 | ||
2571 | /* Y-origin and y-position of the base line of this string. */ | |
2572 | int y, ybase; | |
2573 | ||
2574 | /* The width of the string, not including a face extension. */ | |
2575 | int width; | |
2576 | ||
2577 | /* The width of the string, including a face extension. */ | |
2578 | int background_width; | |
2579 | ||
2580 | /* The height of this string. This is the height of the line this | |
2581 | string is drawn in, and can be different from the height of the | |
2582 | font the string is drawn in. */ | |
2583 | int height; | |
2584 | ||
2585 | /* Number of pixels this string overwrites in front of its x-origin. | |
2586 | This number is zero if the string has an lbearing >= 0; it is | |
2587 | -lbearing, if the string has an lbearing < 0. */ | |
2588 | int left_overhang; | |
2589 | ||
2590 | /* Number of pixels this string overwrites past its right-most | |
2591 | nominal x-position, i.e. x + width. Zero if the string's | |
2592 | rbearing is <= its nominal width, rbearing - width otherwise. */ | |
2593 | int right_overhang; | |
2594 | ||
2595 | /* The frame on which the glyph string is drawn. */ | |
2596 | struct frame *f; | |
2597 | ||
2598 | /* The window on which the glyph string is drawn. */ | |
2599 | struct window *w; | |
2600 | ||
2601 | /* X display and window for convenience. */ | |
2602 | Window window; | |
2603 | ||
2604 | /* The glyph row for which this string was built. It determines the | |
2605 | y-origin and height of the string. */ | |
2606 | struct glyph_row *row; | |
2607 | ||
2608 | /* The area within row. */ | |
2609 | enum glyph_row_area area; | |
2610 | ||
2611 | /* Characters to be drawn, and number of characters. */ | |
2612 | wchar_t *char2b; | |
2613 | int nchars; | |
2614 | ||
791f420f JR |
2615 | /* A face-override for drawing cursors, mouse face and similar. */ |
2616 | enum draw_glyphs_face hl; | |
2617 | ||
2618 | /* Face in which this string is to be drawn. */ | |
2619 | struct face *face; | |
2620 | ||
2621 | /* Font in which this string is to be drawn. */ | |
2622 | XFontStruct *font; | |
2623 | ||
2624 | /* Font info for this string. */ | |
2625 | struct font_info *font_info; | |
2626 | ||
2627 | /* Non-null means this string describes (part of) a composition. | |
2628 | All characters from char2b are drawn composed. */ | |
2629 | struct composition *cmp; | |
2630 | ||
2631 | /* Index of this glyph string's first character in the glyph | |
2632 | definition of CMP. If this is zero, this glyph string describes | |
2633 | the first character of a composition. */ | |
2634 | int gidx; | |
2635 | ||
2636 | /* 1 means this glyph strings face has to be drawn to the right end | |
2637 | of the window's drawing area. */ | |
2638 | unsigned extends_to_end_of_line_p : 1; | |
2639 | ||
2640 | /* 1 means the background of this string has been drawn. */ | |
2641 | unsigned background_filled_p : 1; | |
2642 | ||
2643 | /* 1 means glyph string must be drawn with 16-bit functions. */ | |
2644 | unsigned two_byte_p : 1; | |
2645 | ||
2646 | /* 1 means that the original font determined for drawing this glyph | |
2647 | string could not be loaded. The member `font' has been set to | |
2648 | the frame's default font in this case. */ | |
2649 | unsigned font_not_found_p : 1; | |
2650 | ||
2651 | /* 1 means that the face in which this glyph string is drawn has a | |
2652 | stipple pattern. */ | |
2653 | unsigned stippled_p : 1; | |
2654 | ||
2655 | /* 1 means only the foreground of this glyph string must be drawn, | |
2656 | and we should use the physical height of the line this glyph | |
2657 | string appears in as clip rect. */ | |
2658 | unsigned for_overlaps_p : 1; | |
2659 | ||
2660 | /* The GC to use for drawing this glyph string. */ | |
2661 | XGCValues *gc; | |
2662 | ||
2663 | HDC hdc; | |
2664 | ||
2665 | /* A pointer to the first glyph in the string. This glyph | |
2666 | corresponds to char2b[0]. Needed to draw rectangles if | |
2667 | font_not_found_p is 1. */ | |
2668 | struct glyph *first_glyph; | |
2669 | ||
2670 | /* Image, if any. */ | |
2671 | struct image *img; | |
2672 | ||
2673 | struct glyph_string *next, *prev; | |
2674 | }; | |
2675 | ||
2676 | ||
9ef2e2cf | 2677 | /* Encapsulate the different ways of displaying text under W32. */ |
791f420f | 2678 | |
9127e20e | 2679 | void W32_TEXTOUT (s, x, y,chars,nchars) |
791f420f JR |
2680 | struct glyph_string * s; |
2681 | int x, y; | |
2682 | wchar_t * chars; | |
2683 | int nchars; | |
2684 | { | |
9ef2e2cf | 2685 | int charset_dim = w32_font_is_double_byte (s->gc->font) ? 2 : 1; |
791f420f JR |
2686 | if (s->gc->font->bdf) |
2687 | w32_BDF_TextOut (s->gc->font->bdf, s->hdc, | |
00c96995 JR |
2688 | x, y, (char *) chars, charset_dim, |
2689 | nchars * charset_dim, 0); | |
9ef2e2cf | 2690 | else if (s->first_glyph->w32_font_type == UNICODE_FONT) |
791f420f JR |
2691 | ExtTextOutW (s->hdc, x, y, 0, NULL, chars, nchars, NULL); |
2692 | else | |
2693 | ExtTextOut (s->hdc, x, y, 0, NULL, (char *) chars, | |
9ef2e2cf | 2694 | nchars * charset_dim, NULL); |
791f420f JR |
2695 | } |
2696 | ||
9f5a911b | 2697 | #if GLYPH_DEBUG |
791f420f JR |
2698 | |
2699 | static void | |
2700 | x_dump_glyph_string (s) | |
2701 | struct glyph_string *s; | |
2702 | { | |
2703 | fprintf (stderr, "glyph string\n"); | |
2704 | fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", | |
2705 | s->x, s->y, s->width, s->height); | |
2706 | fprintf (stderr, " ybase = %d\n", s->ybase); | |
2707 | fprintf (stderr, " hl = %d\n", s->hl); | |
2708 | fprintf (stderr, " left overhang = %d, right = %d\n", | |
2709 | s->left_overhang, s->right_overhang); | |
2710 | fprintf (stderr, " nchars = %d\n", s->nchars); | |
2711 | fprintf (stderr, " extends to end of line = %d\n", | |
2712 | s->extends_to_end_of_line_p); | |
2713 | fprintf (stderr, " font height = %d\n", FONT_HEIGHT (s->font)); | |
2714 | fprintf (stderr, " bg width = %d\n", s->background_width); | |
2715 | } | |
2716 | ||
2717 | #endif /* GLYPH_DEBUG */ | |
2718 | ||
2719 | ||
2720 | ||
2721 | static void x_append_glyph_string_lists P_ ((struct glyph_string **, | |
2722 | struct glyph_string **, | |
2723 | struct glyph_string *, | |
2724 | struct glyph_string *)); | |
2725 | static void x_prepend_glyph_string_lists P_ ((struct glyph_string **, | |
2726 | struct glyph_string **, | |
2727 | struct glyph_string *, | |
2728 | struct glyph_string *)); | |
2729 | static void x_append_glyph_string P_ ((struct glyph_string **, | |
2730 | struct glyph_string **, | |
2731 | struct glyph_string *)); | |
2732 | static int x_left_overwritten P_ ((struct glyph_string *)); | |
2733 | static int x_left_overwriting P_ ((struct glyph_string *)); | |
2734 | static int x_right_overwritten P_ ((struct glyph_string *)); | |
2735 | static int x_right_overwriting P_ ((struct glyph_string *)); | |
c2cc16fa JR |
2736 | static int x_fill_glyph_string P_ ((struct glyph_string *, int, int, int, |
2737 | int)); | |
791f420f | 2738 | static void w32_init_glyph_string P_ ((struct glyph_string *, HDC hdc, |
c2cc16fa JR |
2739 | wchar_t *, struct window *, |
2740 | struct glyph_row *, | |
2741 | enum glyph_row_area, int, | |
2742 | enum draw_glyphs_face)); | |
791f420f JR |
2743 | static int x_draw_glyphs P_ ((struct window *, int , struct glyph_row *, |
2744 | enum glyph_row_area, int, int, | |
2745 | enum draw_glyphs_face, int *, int *, int)); | |
2746 | static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); | |
2747 | static void x_set_glyph_string_gc P_ ((struct glyph_string *)); | |
2748 | static void x_draw_glyph_string_background P_ ((struct glyph_string *, | |
2749 | int)); | |
2750 | static void x_draw_glyph_string_foreground P_ ((struct glyph_string *)); | |
2751 | static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *)); | |
791f420f JR |
2752 | static void x_draw_glyph_string_box P_ ((struct glyph_string *)); |
2753 | static void x_draw_glyph_string P_ ((struct glyph_string *)); | |
2754 | static void x_compute_glyph_string_overhangs P_ ((struct glyph_string *)); | |
2755 | static void x_set_cursor_gc P_ ((struct glyph_string *)); | |
2756 | static void x_set_mode_line_face_gc P_ ((struct glyph_string *)); | |
2757 | static void x_set_mouse_face_gc P_ ((struct glyph_string *)); | |
2758 | static void w32_get_glyph_overhangs P_ ((HDC hdc, struct glyph *, | |
2759 | struct frame *, | |
9ef2e2cf | 2760 | int *, int *)); |
791f420f JR |
2761 | static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int)); |
2762 | static int w32_alloc_lighter_color (struct frame *, COLORREF *, double, int); | |
2763 | static void w32_setup_relief_color P_ ((struct frame *, struct relief *, | |
2764 | double, int, COLORREF)); | |
2765 | static void x_setup_relief_colors P_ ((struct glyph_string *)); | |
2766 | static void x_draw_image_glyph_string P_ ((struct glyph_string *)); | |
2767 | static void x_draw_image_relief P_ ((struct glyph_string *)); | |
2768 | static void x_draw_image_foreground P_ ((struct glyph_string *)); | |
2769 | static void w32_draw_image_foreground_1 P_ ((struct glyph_string *, HBITMAP)); | |
2770 | static void x_fill_image_glyph_string P_ ((struct glyph_string *)); | |
2771 | static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, | |
2772 | int, int, int)); | |
2773 | static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int, | |
2774 | int, int, int, int, RECT *)); | |
2775 | static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, | |
2776 | int, int, int, RECT *)); | |
2777 | static void x_fix_overlapping_area P_ ((struct window *, struct glyph_row *, | |
2778 | enum glyph_row_area)); | |
c2cc16fa JR |
2779 | static int x_fill_stretch_glyph_string P_ ((struct glyph_string *, |
2780 | struct glyph_row *, | |
2781 | enum glyph_row_area, int, int)); | |
2782 | ||
2783 | #if GLYPH_DEBUG | |
2784 | static void x_check_font P_ ((struct frame *, XFontStruct *)); | |
2785 | #endif | |
791f420f JR |
2786 | |
2787 | ||
2788 | /* Append the list of glyph strings with head H and tail T to the list | |
2789 | with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ | |
2790 | ||
2791 | static INLINE void | |
2792 | x_append_glyph_string_lists (head, tail, h, t) | |
2793 | struct glyph_string **head, **tail; | |
2794 | struct glyph_string *h, *t; | |
2795 | { | |
2796 | if (h) | |
2797 | { | |
2798 | if (*head) | |
2799 | (*tail)->next = h; | |
2800 | else | |
2801 | *head = h; | |
2802 | h->prev = *tail; | |
2803 | *tail = t; | |
2804 | } | |
2805 | } | |
2806 | ||
2807 | ||
2808 | /* Prepend the list of glyph strings with head H and tail T to the | |
2809 | list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the | |
2810 | result. */ | |
2811 | ||
2812 | static INLINE void | |
2813 | x_prepend_glyph_string_lists (head, tail, h, t) | |
2814 | struct glyph_string **head, **tail; | |
2815 | struct glyph_string *h, *t; | |
2816 | { | |
2817 | if (h) | |
2818 | { | |
2819 | if (*head) | |
2820 | (*head)->prev = t; | |
2821 | else | |
2822 | *tail = t; | |
2823 | t->next = *head; | |
2824 | *head = h; | |
2825 | } | |
2826 | } | |
2827 | ||
2828 | ||
2829 | /* Append glyph string S to the list with head *HEAD and tail *TAIL. | |
2830 | Set *HEAD and *TAIL to the resulting list. */ | |
2831 | ||
2832 | static INLINE void | |
2833 | x_append_glyph_string (head, tail, s) | |
2834 | struct glyph_string **head, **tail; | |
2835 | struct glyph_string *s; | |
2836 | { | |
2837 | s->next = s->prev = NULL; | |
2838 | x_append_glyph_string_lists (head, tail, s, s); | |
2839 | } | |
2840 | ||
2841 | ||
2842 | /* Set S->gc to a suitable GC for drawing glyph string S in cursor | |
2843 | face. */ | |
2844 | ||
2845 | static void | |
2846 | x_set_cursor_gc (s) | |
2847 | struct glyph_string *s; | |
2848 | { | |
2849 | if (s->font == FRAME_FONT (s->f) | |
2850 | && s->face->background == FRAME_BACKGROUND_PIXEL (s->f) | |
2851 | && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f) | |
2852 | && !s->cmp) | |
2853 | s->gc = s->f->output_data.w32->cursor_gc; | |
2854 | else | |
2855 | { | |
2856 | /* Cursor on non-default face: must merge. */ | |
2857 | XGCValues xgcv; | |
2858 | unsigned long mask; | |
2859 | ||
2860 | xgcv.background = s->f->output_data.w32->cursor_pixel; | |
2861 | xgcv.foreground = s->face->background; | |
2862 | ||
2863 | /* If the glyph would be invisible, try a different foreground. */ | |
2864 | if (xgcv.foreground == xgcv.background) | |
2865 | xgcv.foreground = s->face->foreground; | |
2866 | if (xgcv.foreground == xgcv.background) | |
2867 | xgcv.foreground = s->f->output_data.w32->cursor_foreground_pixel; | |
2868 | if (xgcv.foreground == xgcv.background) | |
2869 | xgcv.foreground = s->face->foreground; | |
2870 | ||
2871 | /* Make sure the cursor is distinct from text in this face. */ | |
2872 | if (xgcv.background == s->face->background | |
2873 | && xgcv.foreground == s->face->foreground) | |
2874 | { | |
2875 | xgcv.background = s->face->foreground; | |
2876 | xgcv.foreground = s->face->background; | |
2877 | } | |
2878 | ||
2879 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2880 | xgcv.font = s->font; | |
2881 | mask = GCForeground | GCBackground | GCFont; | |
2882 | ||
2883 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2884 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2885 | mask, &xgcv); | |
2886 | else | |
2887 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2888 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
2889 | ||
2890 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2891 | } | |
2892 | } | |
2893 | ||
2894 | ||
2895 | /* Set up S->gc of glyph string S for drawing text in mouse face. */ | |
2896 | ||
2897 | static void | |
2898 | x_set_mouse_face_gc (s) | |
2899 | struct glyph_string *s; | |
2900 | { | |
2901 | int face_id; | |
93ff4395 | 2902 | struct face *face; |
791f420f | 2903 | |
c2cc16fa | 2904 | /* What face has to be used last for the mouse face? */ |
791f420f | 2905 | face_id = FRAME_W32_DISPLAY_INFO (s->f)->mouse_face_face_id; |
93ff4395 | 2906 | face = FACE_FROM_ID (s->f, face_id); |
c2cc16fa JR |
2907 | if (face == NULL) |
2908 | face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); | |
2909 | ||
2910 | if (s->first_glyph->type == CHAR_GLYPH) | |
2911 | face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch); | |
2912 | else | |
2913 | face_id = FACE_FOR_CHAR (s->f, face, 0); | |
791f420f JR |
2914 | s->face = FACE_FROM_ID (s->f, face_id); |
2915 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); | |
2916 | ||
2917 | /* If font in this face is same as S->font, use it. */ | |
2918 | if (s->font == s->face->font) | |
2919 | s->gc = s->face->gc; | |
2920 | else | |
2921 | { | |
2922 | /* Otherwise construct scratch_cursor_gc with values from FACE | |
2923 | but font FONT. */ | |
2924 | XGCValues xgcv; | |
2925 | unsigned long mask; | |
2926 | ||
2927 | xgcv.background = s->face->background; | |
2928 | xgcv.foreground = s->face->foreground; | |
2929 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2930 | xgcv.font = s->font; | |
2931 | mask = GCForeground | GCBackground | GCFont; | |
2932 | ||
2933 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2934 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2935 | mask, &xgcv); | |
2936 | else | |
2937 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2938 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
2939 | ||
2940 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2941 | } | |
2942 | ||
2943 | xassert (s->gc != 0); | |
2944 | } | |
2945 | ||
2946 | ||
2947 | /* Set S->gc of glyph string S to a GC suitable for drawing a mode line. | |
2948 | Faces to use in the mode line have already been computed when the | |
2949 | matrix was built, so there isn't much to do, here. */ | |
2950 | ||
2951 | static INLINE void | |
2952 | x_set_mode_line_face_gc (s) | |
2953 | struct glyph_string *s; | |
2954 | { | |
2955 | s->gc = s->face->gc; | |
791f420f JR |
2956 | } |
2957 | ||
2958 | ||
2959 | /* Set S->gc of glyph string S for drawing that glyph string. Set | |
2960 | S->stippled_p to a non-zero value if the face of S has a stipple | |
2961 | pattern. */ | |
2962 | ||
2963 | static INLINE void | |
2964 | x_set_glyph_string_gc (s) | |
2965 | struct glyph_string *s; | |
2966 | { | |
ec48c3a7 JR |
2967 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); |
2968 | ||
791f420f JR |
2969 | if (s->hl == DRAW_NORMAL_TEXT) |
2970 | { | |
2971 | s->gc = s->face->gc; | |
2972 | s->stippled_p = s->face->stipple != 0; | |
2973 | } | |
2974 | else if (s->hl == DRAW_INVERSE_VIDEO) | |
2975 | { | |
2976 | x_set_mode_line_face_gc (s); | |
2977 | s->stippled_p = s->face->stipple != 0; | |
2978 | } | |
2979 | else if (s->hl == DRAW_CURSOR) | |
2980 | { | |
2981 | x_set_cursor_gc (s); | |
2982 | s->stippled_p = 0; | |
2983 | } | |
2984 | else if (s->hl == DRAW_MOUSE_FACE) | |
2985 | { | |
2986 | x_set_mouse_face_gc (s); | |
2987 | s->stippled_p = s->face->stipple != 0; | |
2988 | } | |
2989 | else if (s->hl == DRAW_IMAGE_RAISED | |
2990 | || s->hl == DRAW_IMAGE_SUNKEN) | |
2991 | { | |
2992 | s->gc = s->face->gc; | |
2993 | s->stippled_p = s->face->stipple != 0; | |
2994 | } | |
2995 | else | |
2996 | { | |
2997 | s->gc = s->face->gc; | |
2998 | s->stippled_p = s->face->stipple != 0; | |
2999 | } | |
3000 | ||
3001 | /* GC must have been set. */ | |
3002 | xassert (s->gc != 0); | |
3003 | } | |
3004 | ||
3005 | ||
3006 | /* Return in *R the clipping rectangle for glyph string S. */ | |
3007 | ||
3008 | static void | |
3009 | w32_get_glyph_string_clip_rect (s, r) | |
3010 | struct glyph_string *s; | |
3011 | RECT *r; | |
3012 | { | |
3013 | int r_height, r_width; | |
3014 | ||
3015 | if (s->row->full_width_p) | |
3016 | { | |
3017 | /* Draw full-width. X coordinates are relative to S->w->left. */ | |
3018 | int canon_x = CANON_X_UNIT (s->f); | |
3019 | ||
3020 | r->left = WINDOW_LEFT_MARGIN (s->w) * canon_x; | |
3021 | r_width = XFASTINT (s->w->width) * canon_x; | |
3022 | ||
3023 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (s->f)) | |
3024 | { | |
3025 | int width = FRAME_SCROLL_BAR_WIDTH (s->f) * canon_x; | |
3026 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s->f)) | |
3027 | r->left -= width; | |
3028 | } | |
3029 | ||
3030 | r->left += FRAME_INTERNAL_BORDER_WIDTH (s->f); | |
3031 | ||
3032 | /* Unless displaying a mode or menu bar line, which are always | |
3033 | fully visible, clip to the visible part of the row. */ | |
3034 | if (s->w->pseudo_window_p) | |
3035 | r_height = s->row->visible_height; | |
3036 | else | |
3037 | r_height = s->height; | |
3038 | } | |
3039 | else | |
3040 | { | |
3041 | /* This is a text line that may be partially visible. */ | |
3042 | r->left = WINDOW_AREA_TO_FRAME_PIXEL_X (s->w, s->area, 0); | |
3043 | r_width = window_box_width (s->w, s->area); | |
3044 | r_height = s->row->visible_height; | |
3045 | } | |
3046 | ||
791f420f JR |
3047 | /* If S draws overlapping rows, it's sufficient to use the top and |
3048 | bottom of the window for clipping because this glyph string | |
3049 | intentionally draws over other lines. */ | |
3050 | if (s->for_overlaps_p) | |
3051 | { | |
3052 | r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); | |
3053 | r_height = window_text_bottom_y (s->w) - r->top; | |
3054 | } | |
9f5a911b JR |
3055 | else |
3056 | { | |
3057 | /* Don't use S->y for clipping because it doesn't take partially | |
3058 | visible lines into account. For example, it can be negative for | |
3059 | partially visible lines at the top of a window. */ | |
3060 | if (!s->row->full_width_p | |
3061 | && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s->w, s->row)) | |
3062 | r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); | |
3063 | else | |
3064 | r->top = max (0, s->row->y); | |
3065 | ||
3066 | /* If drawing a tool-bar window, draw it over the internal border | |
3067 | at the top of the window. */ | |
3068 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
3069 | r->top -= s->f->output_data.w32->internal_border_width; | |
3070 | } | |
3071 | ||
791f420f JR |
3072 | r->top = WINDOW_TO_FRAME_PIXEL_Y (s->w, r->top); |
3073 | ||
3074 | r->bottom = r->top + r_height; | |
3075 | r->right = r->left + r_width; | |
3076 | } | |
3077 | ||
3078 | ||
3079 | /* Set clipping for output of glyph string S. S may be part of a mode | |
3080 | line or menu if we don't have X toolkit support. */ | |
3081 | ||
3082 | static INLINE void | |
3083 | x_set_glyph_string_clipping (s) | |
3084 | struct glyph_string *s; | |
3085 | { | |
3086 | RECT r; | |
3087 | w32_get_glyph_string_clip_rect (s, &r); | |
3088 | w32_set_clip_rectangle (s->hdc, &r); | |
3089 | } | |
3090 | ||
3091 | ||
3092 | /* Compute left and right overhang of glyph string S. If S is a glyph | |
3093 | string for a composition, assume overhangs don't exist. */ | |
3094 | ||
3095 | static INLINE void | |
3096 | x_compute_glyph_string_overhangs (s) | |
3097 | struct glyph_string *s; | |
3098 | { | |
01b220b6 | 3099 | /* TODO: Windows does not appear to have a method for |
158cba56 JR |
3100 | getting this info without getting the ABC widths for each |
3101 | individual character and working it out manually. */ | |
791f420f JR |
3102 | } |
3103 | ||
3104 | ||
3105 | /* Compute overhangs and x-positions for glyph string S and its | |
3106 | predecessors, or successors. X is the starting x-position for S. | |
3107 | BACKWARD_P non-zero means process predecessors. */ | |
3108 | ||
3109 | static void | |
3110 | x_compute_overhangs_and_x (s, x, backward_p) | |
3111 | struct glyph_string *s; | |
3112 | int x; | |
3113 | int backward_p; | |
3114 | { | |
3115 | if (backward_p) | |
3116 | { | |
3117 | while (s) | |
3118 | { | |
3119 | x_compute_glyph_string_overhangs (s); | |
3120 | x -= s->width; | |
3121 | s->x = x; | |
3122 | s = s->prev; | |
3123 | } | |
3124 | } | |
3125 | else | |
3126 | { | |
3127 | while (s) | |
3128 | { | |
3129 | x_compute_glyph_string_overhangs (s); | |
3130 | s->x = x; | |
3131 | x += s->width; | |
3132 | s = s->next; | |
3133 | } | |
3134 | } | |
3135 | } | |
3136 | ||
3137 | ||
3138 | /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on | |
3139 | frame F. Overhangs of glyphs other than type CHAR_GLYPH are | |
3140 | assumed to be zero. */ | |
3141 | ||
3142 | static void | |
9ef2e2cf | 3143 | w32_get_glyph_overhangs (hdc, glyph, f, left, right) |
00fe468b | 3144 | HDC hdc; |
791f420f JR |
3145 | struct glyph *glyph; |
3146 | struct frame *f; | |
9ef2e2cf | 3147 | int *left, *right; |
791f420f | 3148 | { |
791f420f JR |
3149 | *left = *right = 0; |
3150 | ||
3151 | if (glyph->type == CHAR_GLYPH) | |
3152 | { | |
3153 | XFontStruct *font; | |
3154 | struct face *face; | |
791f420f | 3155 | wchar_t char2b; |
93ff4395 JR |
3156 | XCharStruct *pcm; |
3157 | ||
3158 | face = x_get_glyph_face_and_encoding (f, glyph, &char2b, NULL); | |
791f420f | 3159 | font = face->font; |
9ef2e2cf | 3160 | |
93ff4395 | 3161 | if (font |
82f9d565 | 3162 | && (pcm = w32_per_char_metric (font, &char2b, |
9ef2e2cf | 3163 | glyph->w32_font_type))) |
791f420f | 3164 | { |
791f420f JR |
3165 | if (pcm->rbearing > pcm->width) |
3166 | *right = pcm->rbearing - pcm->width; | |
3167 | if (pcm->lbearing < 0) | |
3168 | *left = -pcm->lbearing; | |
3169 | } | |
3170 | } | |
791f420f JR |
3171 | } |
3172 | ||
3173 | ||
3174 | static void | |
3175 | x_get_glyph_overhangs (glyph, f, left, right) | |
3176 | struct glyph *glyph; | |
3177 | struct frame *f; | |
3178 | int *left, *right; | |
3179 | { | |
3180 | HDC hdc = get_frame_dc (f); | |
9ef2e2cf JR |
3181 | /* Convert to unicode! */ |
3182 | w32_get_glyph_overhangs (hdc, glyph, f, left, right); | |
791f420f JR |
3183 | release_frame_dc (f, hdc); |
3184 | } | |
3185 | ||
3186 | ||
3187 | /* Return the index of the first glyph preceding glyph string S that | |
3188 | is overwritten by S because of S's left overhang. Value is -1 | |
3189 | if no glyphs are overwritten. */ | |
3190 | ||
3191 | static int | |
3192 | x_left_overwritten (s) | |
3193 | struct glyph_string *s; | |
3194 | { | |
3195 | int k; | |
3196 | ||
3197 | if (s->left_overhang) | |
3198 | { | |
3199 | int x = 0, i; | |
3200 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3201 | int first = s->first_glyph - glyphs; | |
3202 | ||
3203 | for (i = first - 1; i >= 0 && x > -s->left_overhang; --i) | |
3204 | x -= glyphs[i].pixel_width; | |
3205 | ||
3206 | k = i + 1; | |
3207 | } | |
3208 | else | |
3209 | k = -1; | |
3210 | ||
3211 | return k; | |
3212 | } | |
3213 | ||
3214 | ||
3215 | /* Return the index of the first glyph preceding glyph string S that | |
3216 | is overwriting S because of its right overhang. Value is -1 if no | |
3217 | glyph in front of S overwrites S. */ | |
3218 | ||
3219 | static int | |
3220 | x_left_overwriting (s) | |
3221 | struct glyph_string *s; | |
3222 | { | |
3223 | int i, k, x; | |
3224 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3225 | int first = s->first_glyph - glyphs; | |
3226 | ||
3227 | k = -1; | |
3228 | x = 0; | |
3229 | for (i = first - 1; i >= 0; --i) | |
3230 | { | |
3231 | int left, right; | |
9ef2e2cf | 3232 | w32_get_glyph_overhangs (s->hdc, glyphs + i, s->f, &left, &right); |
791f420f JR |
3233 | if (x + right > 0) |
3234 | k = i; | |
3235 | x -= glyphs[i].pixel_width; | |
3236 | } | |
3237 | ||
3238 | return k; | |
3239 | } | |
3240 | ||
3241 | ||
3242 | /* Return the index of the last glyph following glyph string S that is | |
3243 | not overwritten by S because of S's right overhang. Value is -1 if | |
3244 | no such glyph is found. */ | |
3245 | ||
3246 | static int | |
3247 | x_right_overwritten (s) | |
3248 | struct glyph_string *s; | |
3249 | { | |
3250 | int k = -1; | |
3251 | ||
3252 | if (s->right_overhang) | |
3253 | { | |
3254 | int x = 0, i; | |
3255 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3256 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); | |
3257 | int end = s->row->used[s->area]; | |
3258 | ||
3259 | for (i = first; i < end && s->right_overhang > x; ++i) | |
3260 | x += glyphs[i].pixel_width; | |
3261 | ||
3262 | k = i; | |
3263 | } | |
3264 | ||
3265 | return k; | |
3266 | } | |
3267 | ||
3268 | ||
3269 | /* Return the index of the last glyph following glyph string S that | |
3270 | overwrites S because of its left overhang. Value is negative | |
3271 | if no such glyph is found. */ | |
3272 | ||
3273 | static int | |
3274 | x_right_overwriting (s) | |
3275 | struct glyph_string *s; | |
3276 | { | |
3277 | int i, k, x; | |
3278 | int end = s->row->used[s->area]; | |
3279 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3280 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); | |
3281 | ||
3282 | k = -1; | |
3283 | x = 0; | |
3284 | for (i = first; i < end; ++i) | |
3285 | { | |
3286 | int left, right; | |
9ef2e2cf | 3287 | w32_get_glyph_overhangs (s->hdc, glyphs + i, s->f, &left, &right); |
791f420f JR |
3288 | if (x - left < 0) |
3289 | k = i; | |
3290 | x += glyphs[i].pixel_width; | |
3291 | } | |
3292 | ||
3293 | return k; | |
3294 | } | |
3295 | ||
3296 | ||
3297 | /* Fill rectangle X, Y, W, H with background color of glyph string S. */ | |
3298 | ||
3299 | static INLINE void | |
3300 | x_clear_glyph_string_rect (s, x, y, w, h) | |
3301 | struct glyph_string *s; | |
3302 | int x, y, w, h; | |
3303 | { | |
3304 | int real_x = x; | |
3305 | int real_y = y; | |
3306 | int real_w = w; | |
3307 | int real_h = h; | |
3308 | #if 0 | |
3309 | /* Take clipping into account. */ | |
3310 | if (s->gc->clip_mask == Rect) | |
3311 | { | |
3312 | real_x = max (real_x, s->gc->clip_rectangle.left); | |
3313 | real_y = max (real_y, s->gc->clip_rectangle.top); | |
3314 | real_w = min (real_w, s->gc->clip_rectangle.right | |
3315 | - s->gc->clip_rectangle.left); | |
3316 | real_h = min (real_h, s->gc->clip_rectangle.bottom | |
3317 | - s->gc->clip_rectangle.top); | |
3318 | } | |
3319 | #endif | |
3320 | w32_fill_area (s->f, s->hdc, s->gc->background, real_x, real_y, | |
3321 | real_w, real_h); | |
3322 | } | |
3323 | ||
3324 | ||
3325 | /* Draw the background of glyph_string S. If S->background_filled_p | |
3326 | is non-zero don't draw it. FORCE_P non-zero means draw the | |
3327 | background even if it wouldn't be drawn normally. This is used | |
3328 | when a string preceding S draws into the background of S, or S | |
3329 | contains the first component of a composition. */ | |
3330 | ||
3331 | static void | |
3332 | x_draw_glyph_string_background (s, force_p) | |
3333 | struct glyph_string *s; | |
3334 | int force_p; | |
3335 | { | |
3336 | /* Nothing to do if background has already been drawn or if it | |
3337 | shouldn't be drawn in the first place. */ | |
3338 | if (!s->background_filled_p) | |
3339 | { | |
60222d69 AI |
3340 | int box_line_width = max (s->face->box_line_width, 0); |
3341 | ||
01b220b6 | 3342 | #if 0 /* TODO: stipple */ |
791f420f JR |
3343 | if (s->stippled_p) |
3344 | { | |
3345 | /* Fill background with a stipple pattern. */ | |
3346 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
3347 | XFillRectangle (s->display, s->window, s->gc, s->x, | |
60222d69 | 3348 | s->y + box_line_width, |
791f420f | 3349 | s->background_width, |
60222d69 | 3350 | s->height - 2 * box_line_width); |
791f420f JR |
3351 | XSetFillStyle (s->display, s->gc, FillSolid); |
3352 | s->background_filled_p = 1; | |
3353 | } | |
3354 | else | |
3355 | #endif | |
60222d69 | 3356 | if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width |
791f420f JR |
3357 | || s->font_not_found_p |
3358 | || s->extends_to_end_of_line_p | |
9127e20e | 3359 | || s->font->bdf |
791f420f JR |
3360 | || force_p) |
3361 | { | |
60222d69 | 3362 | x_clear_glyph_string_rect (s, s->x, s->y + box_line_width, |
791f420f | 3363 | s->background_width, |
60222d69 | 3364 | s->height - 2 * box_line_width); |
791f420f JR |
3365 | s->background_filled_p = 1; |
3366 | } | |
3367 | } | |
3368 | } | |
3369 | ||
3370 | ||
3371 | /* Draw the foreground of glyph string S. */ | |
3372 | ||
3373 | static void | |
3374 | x_draw_glyph_string_foreground (s) | |
3375 | struct glyph_string *s; | |
3376 | { | |
3377 | int i, x; | |
01b220b6 | 3378 | HFONT old_font; |
791f420f JR |
3379 | |
3380 | /* If first glyph of S has a left box line, start drawing the text | |
3381 | of S to the right of that box line. */ | |
3382 | if (s->face->box != FACE_NO_BOX | |
3383 | && s->first_glyph->left_box_line_p) | |
60222d69 | 3384 | x = s->x + abs (s->face->box_line_width); |
791f420f JR |
3385 | else |
3386 | x = s->x; | |
3387 | ||
3388 | if (s->for_overlaps_p || (s->background_filled_p && s->hl != DRAW_CURSOR)) | |
3389 | SetBkMode (s->hdc, TRANSPARENT); | |
3390 | else | |
3391 | SetBkMode (s->hdc, OPAQUE); | |
3392 | ||
3393 | SetTextColor (s->hdc, s->gc->foreground); | |
3394 | SetBkColor (s->hdc, s->gc->background); | |
3395 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | |
3396 | ||
3397 | if (s->font && s->font->hfont) | |
01b220b6 | 3398 | old_font = SelectObject (s->hdc, s->font->hfont); |
791f420f JR |
3399 | |
3400 | /* Draw characters of S as rectangles if S's font could not be | |
3401 | loaded. */ | |
3402 | if (s->font_not_found_p) | |
3403 | { | |
3404 | for (i = 0; i < s->nchars; ++i) | |
3405 | { | |
3406 | struct glyph *g = s->first_glyph + i; | |
3407 | ||
3408 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, g->pixel_width - 1, | |
3409 | s->height - 1); | |
3410 | x += g->pixel_width; | |
3411 | } | |
3412 | } | |
3413 | else | |
3414 | { | |
3415 | char *char1b = (char *) s->char2b; | |
3416 | int boff = s->font_info->baseline_offset; | |
3417 | ||
3418 | if (s->font_info->vertical_centering) | |
3419 | boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; | |
3420 | ||
3421 | /* If we can use 8-bit functions, condense S->char2b. */ | |
3422 | if (!s->two_byte_p) | |
3423 | for (i = 0; i < s->nchars; ++i) | |
3424 | char1b[i] = BYTE2 (s->char2b[i]); | |
3425 | ||
3426 | /* Draw text with TextOut and friends. */ | |
3427 | W32_TEXTOUT (s, x, s->ybase - boff, s->char2b, s->nchars); | |
3428 | } | |
01b220b6 JR |
3429 | if (s->font && s->font->hfont) |
3430 | SelectObject (s->hdc, old_font); | |
791f420f JR |
3431 | } |
3432 | ||
3433 | /* Draw the foreground of composite glyph string S. */ | |
3434 | ||
3435 | static void | |
3436 | x_draw_composite_glyph_string_foreground (s) | |
3437 | struct glyph_string *s; | |
3438 | { | |
3439 | int i, x; | |
01b220b6 | 3440 | HFONT old_font; |
791f420f JR |
3441 | |
3442 | /* If first glyph of S has a left box line, start drawing the text | |
3443 | of S to the right of that box line. */ | |
3444 | if (s->face->box != FACE_NO_BOX | |
3445 | && s->first_glyph->left_box_line_p) | |
60222d69 | 3446 | x = s->x + abs (s->face->box_line_width); |
791f420f JR |
3447 | else |
3448 | x = s->x; | |
3449 | ||
3450 | /* S is a glyph string for a composition. S->gidx is the index of | |
3451 | the first character drawn for glyphs of this composition. | |
3452 | S->gidx == 0 means we are drawing the very first character of | |
3453 | this composition. */ | |
3454 | ||
3455 | SetTextColor (s->hdc, s->gc->foreground); | |
3456 | SetBkColor (s->hdc, s->gc->background); | |
3457 | SetBkMode (s->hdc, TRANSPARENT); | |
3458 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | |
3459 | ||
01b220b6 JR |
3460 | if (s->font && s->font->hfont) |
3461 | old_font = SelectObject (s->hdc, s->font->hfont); | |
3462 | ||
791f420f JR |
3463 | /* Draw a rectangle for the composition if the font for the very |
3464 | first character of the composition could not be loaded. */ | |
3465 | if (s->font_not_found_p) | |
3466 | { | |
3467 | if (s->gidx == 0) | |
3468 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1, | |
3469 | s->height - 1); | |
3470 | } | |
3471 | else | |
3472 | { | |
3473 | for (i = 0; i < s->nchars; i++, ++s->gidx) | |
01b220b6 JR |
3474 | W32_TEXTOUT (s, x + s->cmp->offsets[s->gidx * 2], |
3475 | s->ybase - s->cmp->offsets[s->gidx * 2 + 1], | |
3476 | s->char2b + i, 1); | |
791f420f | 3477 | } |
01b220b6 JR |
3478 | if (s->font && s->font->hfont) |
3479 | SelectObject (s->hdc, old_font); | |
791f420f JR |
3480 | } |
3481 | ||
e5fa381b JR |
3482 | |
3483 | /* Brightness beyond which a color won't have its highlight brightness | |
3484 | boosted. | |
3485 | ||
3486 | Nominally, highlight colors for `3d' faces are calculated by | |
3487 | brightening an object's color by a constant scale factor, but this | |
3488 | doesn't yield good results for dark colors, so for colors who's | |
3489 | brightness is less than this value (on a scale of 0-255) have to | |
3490 | use an additional additive factor. | |
3491 | ||
3492 | The value here is set so that the default menu-bar/mode-line color | |
3493 | (grey75) will not have its highlights changed at all. */ | |
3494 | #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187 | |
3495 | ||
3496 | ||
791f420f JR |
3497 | /* Allocate a color which is lighter or darker than *COLOR by FACTOR |
3498 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
3499 | If this produces the same color as COLOR, try a color where all RGB | |
3500 | values have DELTA added. Return the allocated color in *COLOR. | |
3501 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
3502 | Value is non-zero if successful. */ | |
3503 | ||
3504 | static int | |
3505 | w32_alloc_lighter_color (f, color, factor, delta) | |
3506 | struct frame *f; | |
3507 | COLORREF *color; | |
3508 | double factor; | |
3509 | int delta; | |
3510 | { | |
3511 | COLORREF new; | |
e5fa381b JR |
3512 | long bright; |
3513 | ||
3514 | /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */ | |
3515 | delta /= 256; | |
791f420f JR |
3516 | |
3517 | /* Change RGB values by specified FACTOR. Avoid overflow! */ | |
3518 | xassert (factor >= 0); | |
3519 | new = PALETTERGB (min (0xff, factor * GetRValue (*color)), | |
3520 | min (0xff, factor * GetGValue (*color)), | |
3521 | min (0xff, factor * GetBValue (*color))); | |
e5fa381b JR |
3522 | |
3523 | /* Calculate brightness of COLOR. */ | |
3524 | bright = (2 * GetRValue (*color) + 3 * GetGValue (*color) | |
3525 | + GetBValue (*color)) / 6; | |
3526 | ||
3527 | /* We only boost colors that are darker than | |
3528 | HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */ | |
3529 | if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT) | |
3530 | /* Make an additive adjustment to NEW, because it's dark enough so | |
3531 | that scaling by FACTOR alone isn't enough. */ | |
3532 | { | |
3533 | /* How far below the limit this color is (0 - 1, 1 being darker). */ | |
3534 | double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT; | |
3535 | /* The additive adjustment. */ | |
3536 | int min_delta = delta * dimness * factor / 2; | |
3537 | ||
3538 | if (factor < 1) | |
3539 | new = PALETTERGB (max (0, min (0xff, min_delta - GetRValue (*color))), | |
3540 | max (0, min (0xff, min_delta - GetGValue (*color))), | |
3541 | max (0, min (0xff, min_delta - GetBValue (*color)))); | |
3542 | else | |
3543 | new = PALETTERGB (max (0, min (0xff, min_delta + GetRValue (*color))), | |
3544 | max (0, min (0xff, min_delta + GetGValue (*color))), | |
3545 | max (0, min (0xff, min_delta + GetBValue (*color)))); | |
3546 | } | |
3547 | ||
791f420f JR |
3548 | if (new == *color) |
3549 | new = PALETTERGB (max (0, min (0xff, delta + GetRValue (*color))), | |
3550 | max (0, min (0xff, delta + GetGValue (*color))), | |
3551 | max (0, min (0xff, delta + GetBValue (*color)))); | |
3552 | ||
01b220b6 JR |
3553 | /* TODO: Map to palette and retry with delta if same? */ |
3554 | /* TODO: Free colors (if using palette)? */ | |
93ff4395 | 3555 | |
791f420f JR |
3556 | if (new == *color) |
3557 | return 0; | |
3558 | ||
3559 | *color = new; | |
3560 | ||
3561 | return 1; | |
3562 | } | |
3563 | ||
3564 | ||
3565 | /* Set up the foreground color for drawing relief lines of glyph | |
3566 | string S. RELIEF is a pointer to a struct relief containing the GC | |
3567 | with which lines will be drawn. Use a color that is FACTOR or | |
3568 | DELTA lighter or darker than the relief's background which is found | |
3569 | in S->f->output_data.x->relief_background. If such a color cannot | |
3570 | be allocated, use DEFAULT_PIXEL, instead. */ | |
3571 | ||
3572 | static void | |
3573 | w32_setup_relief_color (f, relief, factor, delta, default_pixel) | |
3574 | struct frame *f; | |
3575 | struct relief *relief; | |
3576 | double factor; | |
3577 | int delta; | |
3578 | COLORREF default_pixel; | |
3579 | { | |
3580 | XGCValues xgcv; | |
3581 | struct w32_output *di = f->output_data.w32; | |
3582 | unsigned long mask = GCForeground; | |
3583 | COLORREF pixel; | |
3584 | COLORREF background = di->relief_background; | |
3585 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
3586 | ||
01b220b6 | 3587 | /* TODO: Free colors (if using palette)? */ |
93ff4395 | 3588 | |
791f420f JR |
3589 | /* Allocate new color. */ |
3590 | xgcv.foreground = default_pixel; | |
3591 | pixel = background; | |
3592 | if (w32_alloc_lighter_color (f, &pixel, factor, delta)) | |
3593 | { | |
3594 | relief->allocated_p = 1; | |
3595 | xgcv.foreground = relief->pixel = pixel; | |
3596 | } | |
3597 | ||
3598 | if (relief->gc == 0) | |
3599 | { | |
01b220b6 | 3600 | #if 0 /* TODO: stipple */ |
791f420f JR |
3601 | xgcv.stipple = dpyinfo->gray; |
3602 | mask |= GCStipple; | |
3603 | #endif | |
3604 | relief->gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &xgcv); | |
3605 | } | |
3606 | else | |
3607 | XChangeGC (NULL, relief->gc, mask, &xgcv); | |
3608 | } | |
3609 | ||
3610 | ||
3611 | /* Set up colors for the relief lines around glyph string S. */ | |
3612 | ||
3613 | static void | |
3614 | x_setup_relief_colors (s) | |
3615 | struct glyph_string *s; | |
3616 | { | |
3617 | struct w32_output *di = s->f->output_data.w32; | |
3618 | COLORREF color; | |
3619 | ||
3620 | if (s->face->use_box_color_for_shadows_p) | |
3621 | color = s->face->box_color; | |
3622 | else | |
3623 | color = s->gc->background; | |
3624 | ||
3625 | if (di->white_relief.gc == 0 | |
3626 | || color != di->relief_background) | |
3627 | { | |
3628 | di->relief_background = color; | |
3629 | w32_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000, | |
3630 | WHITE_PIX_DEFAULT (s->f)); | |
3631 | w32_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000, | |
3632 | BLACK_PIX_DEFAULT (s->f)); | |
3633 | } | |
3634 | } | |
3635 | ||
3636 | ||
3637 | /* Draw a relief on frame F inside the rectangle given by LEFT_X, | |
3638 | TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief | |
3639 | to draw, it must be >= 0. RAISED_P non-zero means draw a raised | |
3640 | relief. LEFT_P non-zero means draw a relief on the left side of | |
3641 | the rectangle. RIGHT_P non-zero means draw a relief on the right | |
3642 | side of the rectangle. CLIP_RECT is the clipping rectangle to use | |
3643 | when drawing. */ | |
3644 | ||
3645 | static void | |
3646 | w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, | |
3647 | raised_p, left_p, right_p, clip_rect) | |
3648 | struct frame *f; | |
3649 | int left_x, top_y, right_x, bottom_y, left_p, right_p, raised_p; | |
3650 | RECT *clip_rect; | |
3651 | { | |
3652 | int i; | |
3653 | XGCValues gc; | |
3654 | HDC hdc = get_frame_dc (f); | |
3655 | ||
3656 | if (raised_p) | |
e5fa381b | 3657 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
791f420f | 3658 | else |
e5fa381b | 3659 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f JR |
3660 | |
3661 | w32_set_clip_rectangle (hdc, clip_rect); | |
3662 | ||
3663 | /* Top. */ | |
3664 | for (i = 0; i < width; ++i) | |
9f5a911b JR |
3665 | w32_fill_area (f, hdc, gc.foreground, |
3666 | left_x + i * left_p, top_y + i, | |
3667 | (right_x + 1 - i * right_p) - (left_x + i * left_p), 1); | |
791f420f JR |
3668 | |
3669 | /* Left. */ | |
3670 | if (left_p) | |
3671 | for (i = 0; i < width; ++i) | |
9f5a911b JR |
3672 | w32_fill_area (f, hdc, gc.foreground, |
3673 | left_x + i, top_y + i, 1, | |
3674 | (bottom_y - i + 1) - (top_y + i)); | |
791f420f JR |
3675 | |
3676 | if (raised_p) | |
e5fa381b | 3677 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f | 3678 | else |
e5fa381b | 3679 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
791f420f JR |
3680 | |
3681 | /* Bottom. */ | |
3682 | for (i = 0; i < width; ++i) | |
9f5a911b JR |
3683 | w32_fill_area (f, hdc, gc.foreground, |
3684 | left_x + i * left_p, bottom_y - i, | |
3685 | (right_x + 2 - i * right_p) - (left_x + i * left_p), 1); | |
791f420f JR |
3686 | |
3687 | /* Right. */ | |
3688 | if (right_p) | |
3689 | for (i = 0; i < width; ++i) | |
9f5a911b JR |
3690 | w32_fill_area (f, hdc, gc.foreground, |
3691 | right_x - i, top_y + i + 1, 1, | |
3692 | (bottom_y - i) - (top_y + i + 1)); | |
791f420f JR |
3693 | |
3694 | w32_set_clip_rectangle (hdc, NULL); | |
3695 | ||
3696 | release_frame_dc (f, hdc); | |
3697 | } | |
3698 | ||
3699 | ||
3700 | /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y, | |
3701 | RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to | |
3702 | draw, it must be >= 0. LEFT_P non-zero means draw a line on the | |
3703 | left side of the rectangle. RIGHT_P non-zero means draw a line | |
3704 | on the right side of the rectangle. CLIP_RECT is the clipping | |
3705 | rectangle to use when drawing. */ | |
3706 | ||
3707 | static void | |
3708 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3709 | left_p, right_p, clip_rect) | |
3710 | struct glyph_string *s; | |
3711 | int left_x, top_y, right_x, bottom_y, width, left_p, right_p; | |
3712 | RECT *clip_rect; | |
3713 | { | |
00fe468b | 3714 | w32_set_clip_rectangle (s->hdc, clip_rect); |
791f420f JR |
3715 | |
3716 | /* Top. */ | |
00fe468b | 3717 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3718 | left_x, top_y, right_x - left_x + 1, width); |
791f420f JR |
3719 | |
3720 | /* Left. */ | |
3721 | if (left_p) | |
3722 | { | |
00fe468b | 3723 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3724 | left_x, top_y, width, bottom_y - top_y + 1); |
791f420f JR |
3725 | } |
3726 | ||
3727 | /* Bottom. */ | |
00fe468b | 3728 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3729 | left_x, bottom_y - width + 1, right_x - left_x + 1, width); |
791f420f JR |
3730 | |
3731 | /* Right. */ | |
3732 | if (right_p) | |
3733 | { | |
00fe468b | 3734 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3735 | right_x - width + 1, top_y, width, bottom_y - top_y + 1); |
791f420f JR |
3736 | } |
3737 | ||
00fe468b | 3738 | w32_set_clip_rectangle (s->hdc, NULL); |
791f420f JR |
3739 | } |
3740 | ||
3741 | ||
3742 | /* Draw a box around glyph string S. */ | |
3743 | ||
3744 | static void | |
3745 | x_draw_glyph_string_box (s) | |
3746 | struct glyph_string *s; | |
3747 | { | |
3748 | int width, left_x, right_x, top_y, bottom_y, last_x, raised_p; | |
3749 | int left_p, right_p; | |
3750 | struct glyph *last_glyph; | |
3751 | RECT clip_rect; | |
3752 | ||
3753 | last_x = window_box_right (s->w, s->area); | |
3754 | if (s->row->full_width_p | |
3755 | && !s->w->pseudo_window_p) | |
3756 | { | |
3757 | last_x += FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s->f); | |
3758 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s->f)) | |
3759 | last_x += FRAME_SCROLL_BAR_WIDTH (s->f) * CANON_X_UNIT (s->f); | |
3760 | } | |
3761 | ||
3762 | /* The glyph that may have a right box line. */ | |
3763 | last_glyph = (s->cmp || s->img | |
3764 | ? s->first_glyph | |
3765 | : s->first_glyph + s->nchars - 1); | |
3766 | ||
60222d69 | 3767 | width = abs (s->face->box_line_width); |
791f420f JR |
3768 | raised_p = s->face->box == FACE_RAISED_BOX; |
3769 | left_x = s->x; | |
9f5a911b | 3770 | right_x = ((s->row->full_width_p && s->extends_to_end_of_line_p |
791f420f JR |
3771 | ? last_x - 1 |
3772 | : min (last_x, s->x + s->background_width) - 1)); | |
3773 | top_y = s->y; | |
3774 | bottom_y = top_y + s->height - 1; | |
3775 | ||
3776 | left_p = (s->first_glyph->left_box_line_p | |
3777 | || (s->hl == DRAW_MOUSE_FACE | |
3778 | && (s->prev == NULL | |
3779 | || s->prev->hl != s->hl))); | |
3780 | right_p = (last_glyph->right_box_line_p | |
3781 | || (s->hl == DRAW_MOUSE_FACE | |
3782 | && (s->next == NULL | |
3783 | || s->next->hl != s->hl))); | |
3784 | ||
3785 | w32_get_glyph_string_clip_rect (s, &clip_rect); | |
3786 | ||
3787 | if (s->face->box == FACE_SIMPLE_BOX) | |
3788 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3789 | left_p, right_p, &clip_rect); | |
3790 | else | |
3791 | { | |
3792 | x_setup_relief_colors (s); | |
3793 | w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, | |
3794 | width, raised_p, left_p, right_p, &clip_rect); | |
3795 | } | |
3796 | } | |
3797 | ||
3798 | ||
3799 | /* Draw foreground of image glyph string S. */ | |
3800 | ||
3801 | static void | |
3802 | x_draw_image_foreground (s) | |
3803 | struct glyph_string *s; | |
3804 | { | |
3805 | int x; | |
9ef2e2cf | 3806 | int y = s->ybase - image_ascent (s->img, s->face); |
791f420f JR |
3807 | |
3808 | /* If first glyph of S has a left box line, start drawing it to the | |
3809 | right of that line. */ | |
3810 | if (s->face->box != FACE_NO_BOX | |
3811 | && s->first_glyph->left_box_line_p) | |
60222d69 | 3812 | x = s->x + abs (s->face->box_line_width); |
791f420f JR |
3813 | else |
3814 | x = s->x; | |
3815 | ||
3816 | /* If there is a margin around the image, adjust x- and y-position | |
3817 | by that margin. */ | |
d6ff54d5 JR |
3818 | x += s->img->hmargin; |
3819 | y += s->img->vmargin; | |
791f420f JR |
3820 | |
3821 | SaveDC (s->hdc); | |
3822 | ||
3823 | if (s->img->pixmap) | |
3824 | { | |
01b220b6 | 3825 | #if 0 /* TODO: image mask */ |
791f420f JR |
3826 | if (s->img->mask) |
3827 | { | |
3828 | /* We can't set both a clip mask and use XSetClipRectangles | |
3829 | because the latter also sets a clip mask. We also can't | |
3830 | trust on the shape extension to be available | |
3831 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3832 | manually. */ | |
3833 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3834 | | GCFunction); | |
3835 | XGCValues xgcv; | |
3836 | XRectangle clip_rect, image_rect, r; | |
3837 | ||
3838 | xgcv.clip_mask = s->img->mask; | |
3839 | xgcv.clip_x_origin = x; | |
3840 | xgcv.clip_y_origin = y; | |
3841 | xgcv.function = GXcopy; | |
3842 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3843 | ||
3844 | w32_get_glyph_string_clip_rect (s, &clip_rect); | |
3845 | image_rect.x = x; | |
3846 | image_rect.y = y; | |
3847 | image_rect.width = s->img->width; | |
3848 | image_rect.height = s->img->height; | |
158cba56 | 3849 | if (IntersectRect (&r, &clip_rect, &image_rect)) |
791f420f JR |
3850 | XCopyArea (s->display, s->img->pixmap, s->window, s->gc, |
3851 | r.x - x, r.y - y, r.width, r.height, r.x, r.y); | |
3852 | } | |
3853 | else | |
3854 | #endif | |
3855 | { | |
3856 | HDC compat_hdc = CreateCompatibleDC (s->hdc); | |
3857 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
3858 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
3859 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
158cba56 | 3860 | x_set_glyph_string_clipping (s); |
791f420f JR |
3861 | |
3862 | SetTextColor (s->hdc, s->gc->foreground); | |
3863 | SetBkColor (s->hdc, s->gc->background); | |
3864 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
3865 | BitBlt (s->hdc, x, y, s->img->width, s->img->height, | |
3866 | compat_hdc, 0, 0, SRCCOPY); | |
791f420f JR |
3867 | BitBlt (s->hdc, x, y, s->img->width, s->img->height, |
3868 | compat_hdc, 0, 0, 0xB8074A); | |
9436cdf9 JR |
3869 | #else |
3870 | BitBlt (s->hdc, x, y, s->img->width, s->img->height, | |
3871 | compat_hdc, 0, 0, 0xE20746); | |
791f420f JR |
3872 | #endif |
3873 | SelectObject (s->hdc, orig_brush); | |
3874 | DeleteObject (fg_brush); | |
3875 | SelectObject (compat_hdc, orig_obj); | |
3876 | DeleteDC (compat_hdc); | |
3877 | ||
3878 | /* When the image has a mask, we can expect that at | |
3879 | least part of a mouse highlight or a block cursor will | |
3880 | be visible. If the image doesn't have a mask, make | |
3881 | a block cursor visible by drawing a rectangle around | |
3882 | the image. I believe it's looking better if we do | |
3883 | nothing here for mouse-face. */ | |
3884 | if (s->hl == DRAW_CURSOR) | |
3885 | w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width - 1, | |
3886 | s->img->height - 1); | |
9127e20e | 3887 | w32_set_clip_rectangle (s->hdc, NULL); |
791f420f JR |
3888 | } |
3889 | } | |
3890 | else | |
3891 | w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width -1, | |
3892 | s->img->height - 1); | |
ee78dc32 | 3893 | |
791f420f JR |
3894 | RestoreDC (s->hdc ,-1); |
3895 | } | |
ee78dc32 | 3896 | |
791f420f JR |
3897 | |
3898 | ||
3899 | /* Draw a relief around the image glyph string S. */ | |
3900 | ||
3901 | static void | |
3902 | x_draw_image_relief (s) | |
3903 | struct glyph_string *s; | |
3904 | { | |
3905 | int x0, y0, x1, y1, thick, raised_p; | |
3906 | RECT r; | |
3907 | int x; | |
9ef2e2cf JR |
3908 | int y = s->ybase - image_ascent (s->img, s->face); |
3909 | ||
791f420f JR |
3910 | /* If first glyph of S has a left box line, start drawing it to the |
3911 | right of that line. */ | |
3912 | if (s->face->box != FACE_NO_BOX | |
3913 | && s->first_glyph->left_box_line_p) | |
60222d69 | 3914 | x = s->x + abs (s->face->box_line_width); |
791f420f JR |
3915 | else |
3916 | x = s->x; | |
3917 | ||
3918 | /* If there is a margin around the image, adjust x- and y-position | |
3919 | by that margin. */ | |
d6ff54d5 JR |
3920 | x += s->img->hmargin; |
3921 | y += s->img->vmargin; | |
791f420f JR |
3922 | |
3923 | if (s->hl == DRAW_IMAGE_SUNKEN | |
3924 | || s->hl == DRAW_IMAGE_RAISED) | |
3925 | { | |
3926 | thick = tool_bar_button_relief > 0 ? tool_bar_button_relief : 3; | |
3927 | raised_p = s->hl == DRAW_IMAGE_RAISED; | |
3928 | } | |
3929 | else | |
ee78dc32 | 3930 | { |
791f420f JR |
3931 | thick = abs (s->img->relief); |
3932 | raised_p = s->img->relief > 0; | |
3933 | } | |
3934 | ||
3935 | x0 = x - thick; | |
3936 | y0 = y - thick; | |
3937 | x1 = x + s->img->width + thick - 1; | |
3938 | y1 = y + s->img->height + thick - 1; | |
3939 | ||
3940 | x_setup_relief_colors (s); | |
3941 | w32_get_glyph_string_clip_rect (s, &r); | |
3942 | w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); | |
3943 | } | |
ee78dc32 | 3944 | |
791f420f JR |
3945 | |
3946 | /* Draw the foreground of image glyph string S to PIXMAP. */ | |
3947 | ||
3948 | static void | |
3949 | w32_draw_image_foreground_1 (s, pixmap) | |
3950 | struct glyph_string *s; | |
3951 | HBITMAP pixmap; | |
3952 | { | |
3953 | HDC hdc = CreateCompatibleDC (s->hdc); | |
3954 | HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap); | |
3955 | int x; | |
9ef2e2cf | 3956 | int y = s->ybase - s->y - image_ascent (s->img, s->face); |
791f420f JR |
3957 | |
3958 | /* If first glyph of S has a left box line, start drawing it to the | |
3959 | right of that line. */ | |
3960 | if (s->face->box != FACE_NO_BOX | |
3961 | && s->first_glyph->left_box_line_p) | |
60222d69 | 3962 | x = abs (s->face->box_line_width); |
791f420f JR |
3963 | else |
3964 | x = 0; | |
3965 | ||
3966 | /* If there is a margin around the image, adjust x- and y-position | |
3967 | by that margin. */ | |
d6ff54d5 JR |
3968 | x += s->img->hmargin; |
3969 | y += s->img->vmargin; | |
791f420f JR |
3970 | |
3971 | if (s->img->pixmap) | |
3972 | { | |
01b220b6 | 3973 | #if 0 /* TODO: image mask */ |
791f420f JR |
3974 | if (s->img->mask) |
3975 | { | |
3976 | /* We can't set both a clip mask and use XSetClipRectangles | |
3977 | because the latter also sets a clip mask. We also can't | |
3978 | trust on the shape extension to be available | |
3979 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3980 | manually. */ | |
3981 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3982 | | GCFunction); | |
3983 | XGCValues xgcv; | |
3984 | ||
3985 | xgcv.clip_mask = s->img->mask; | |
3986 | xgcv.clip_x_origin = x; | |
3987 | xgcv.clip_y_origin = y; | |
3988 | xgcv.function = GXcopy; | |
3989 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3990 | ||
3991 | XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, | |
3992 | 0, 0, s->img->width, s->img->height, x, y); | |
3993 | XSetClipMask (s->display, s->gc, None); | |
3994 | } | |
3995 | else | |
3996 | #endif | |
ef0e360f | 3997 | { |
791f420f JR |
3998 | HDC compat_hdc = CreateCompatibleDC (hdc); |
3999 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
4000 | HBRUSH orig_brush = SelectObject (hdc, fg_brush); | |
4001 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
4002 | ||
4003 | SetTextColor (hdc, s->gc->foreground); | |
4004 | SetBkColor (hdc, s->gc->background); | |
4005 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
4006 | BitBlt (hdc, x, y, s->img->width, s->img->height, | |
4007 | compat_hdc, 0, 0, SRCCOPY); | |
791f420f JR |
4008 | BitBlt (hdc, x, y, s->img->width, s->img->height, |
4009 | compat_hdc, 0, 0, 0xB8074A); | |
9436cdf9 JR |
4010 | #else |
4011 | BitBlt (hdc, x, y, s->img->width, s->img->height, | |
4012 | compat_hdc, 0, 0, 0xE20746); | |
791f420f JR |
4013 | #endif |
4014 | SelectObject (hdc, orig_brush); | |
4015 | DeleteObject (fg_brush); | |
4016 | SelectObject (compat_hdc, orig_obj); | |
4017 | DeleteDC (compat_hdc); | |
4018 | ||
4019 | /* When the image has a mask, we can expect that at | |
4020 | least part of a mouse highlight or a block cursor will | |
4021 | be visible. If the image doesn't have a mask, make | |
4022 | a block cursor visible by drawing a rectangle around | |
4023 | the image. I believe it's looking better if we do | |
4024 | nothing here for mouse-face. */ | |
4025 | if (s->hl == DRAW_CURSOR) | |
4026 | w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, | |
4027 | s->img->height - 1); | |
ef0e360f | 4028 | } |
791f420f JR |
4029 | } |
4030 | else | |
4031 | w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, | |
4032 | s->img->height - 1); | |
4033 | ||
4034 | SelectObject (hdc, orig_hdc_obj); | |
4035 | DeleteDC (hdc); | |
4036 | } | |
4037 | ||
4038 | ||
4039 | /* Draw part of the background of glyph string S. X, Y, W, and H | |
4040 | give the rectangle to draw. */ | |
4041 | ||
4042 | static void | |
4043 | x_draw_glyph_string_bg_rect (s, x, y, w, h) | |
4044 | struct glyph_string *s; | |
4045 | int x, y, w, h; | |
4046 | { | |
01b220b6 | 4047 | #if 0 /* TODO: stipple */ |
791f420f JR |
4048 | if (s->stippled_p) |
4049 | { | |
4050 | /* Fill background with a stipple pattern. */ | |
4051 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4052 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
4053 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4054 | } | |
4055 | else | |
4056 | #endif | |
4057 | x_clear_glyph_string_rect (s, x, y, w, h); | |
4058 | } | |
4059 | ||
4060 | ||
4061 | /* Draw image glyph string S. | |
4062 | ||
4063 | s->y | |
4064 | s->x +------------------------- | |
4065 | | s->face->box | |
4066 | | | |
4067 | | +------------------------- | |
d6ff54d5 | 4068 | | | s->img->vmargin |
791f420f JR |
4069 | | | |
4070 | | | +------------------- | |
4071 | | | | the image | |
cabb23bc | 4072 | |
791f420f JR |
4073 | */ |
4074 | ||
4075 | static void | |
4076 | x_draw_image_glyph_string (s) | |
4077 | struct glyph_string *s; | |
4078 | { | |
4079 | int x, y; | |
60222d69 AI |
4080 | int box_line_hwidth = abs (s->face->box_line_width); |
4081 | int box_line_vwidth = max (s->face->box_line_width, 0); | |
791f420f JR |
4082 | int height; |
4083 | HBITMAP pixmap = 0; | |
4084 | ||
60222d69 | 4085 | height = s->height - 2 * box_line_vwidth; |
791f420f JR |
4086 | |
4087 | /* Fill background with face under the image. Do it only if row is | |
4088 | taller than image or if image has a clip mask to reduce | |
4089 | flickering. */ | |
4090 | s->stippled_p = s->face->stipple != 0; | |
4091 | if (height > s->img->height | |
d6ff54d5 | 4092 | || s->img->hmargin |
c2cc16fa | 4093 | || s->img->vmargin |
01b220b6 | 4094 | #if 0 /* TODO: image mask */ |
791f420f JR |
4095 | || s->img->mask |
4096 | #endif | |
4097 | || s->img->pixmap == 0 | |
4098 | || s->width != s->background_width) | |
4099 | { | |
60222d69 AI |
4100 | if (box_line_hwidth && s->first_glyph->left_box_line_p) |
4101 | x = s->x + box_line_hwidth; | |
791f420f JR |
4102 | else |
4103 | x = s->x; | |
4104 | ||
60222d69 | 4105 | y = s->y + box_line_vwidth; |
01b220b6 | 4106 | #if 0 /* TODO: image mask */ |
791f420f | 4107 | if (s->img->mask) |
ee78dc32 | 4108 | { |
c2cc16fa JR |
4109 | /* Create a pixmap as large as the glyph string. Fill it |
4110 | with the background color. Copy the image to it, using | |
4111 | its mask. Copy the temporary pixmap to the display. */ | |
791f420f JR |
4112 | Screen *screen = FRAME_X_SCREEN (s->f); |
4113 | int depth = DefaultDepthOfScreen (screen); | |
4114 | ||
4115 | /* Create a pixmap as large as the glyph string. */ | |
4116 | pixmap = XCreatePixmap (s->display, s->window, | |
4117 | s->background_width, | |
4118 | s->height, depth); | |
4119 | ||
4120 | /* Don't clip in the following because we're working on the | |
4121 | pixmap. */ | |
4122 | XSetClipMask (s->display, s->gc, None); | |
ee78dc32 | 4123 | |
791f420f JR |
4124 | /* Fill the pixmap with the background color/stipple. */ |
4125 | if (s->stippled_p) | |
4126 | { | |
4127 | /* Fill background with a stipple pattern. */ | |
4128 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4129 | XFillRectangle (s->display, pixmap, s->gc, | |
4130 | 0, 0, s->background_width, s->height); | |
4131 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4132 | } | |
ef0e360f | 4133 | else |
791f420f JR |
4134 | { |
4135 | XGCValues xgcv; | |
4136 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, | |
4137 | &xgcv); | |
4138 | XSetForeground (s->display, s->gc, xgcv.background); | |
4139 | XFillRectangle (s->display, pixmap, s->gc, | |
4140 | 0, 0, s->background_width, s->height); | |
4141 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4142 | } | |
ee78dc32 | 4143 | } |
791f420f JR |
4144 | else |
4145 | #endif | |
791f420f JR |
4146 | x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height); |
4147 | ||
4148 | s->background_filled_p = 1; | |
4149 | } | |
ee78dc32 | 4150 | |
791f420f JR |
4151 | /* Draw the foreground. */ |
4152 | if (pixmap != 0) | |
4153 | { | |
4154 | w32_draw_image_foreground_1 (s, pixmap); | |
4155 | x_set_glyph_string_clipping (s); | |
ee78dc32 | 4156 | { |
791f420f JR |
4157 | HDC compat_hdc = CreateCompatibleDC (s->hdc); |
4158 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
4159 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
4160 | HGDIOBJ orig_obj = SelectObject (compat_hdc, pixmap); | |
4161 | ||
4162 | SetTextColor (s->hdc, s->gc->foreground); | |
4163 | SetBkColor (s->hdc, s->gc->background); | |
4164 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
4165 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, | |
4166 | compat_hdc, 0, 0, SRCCOPY); | |
791f420f JR |
4167 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, |
4168 | compat_hdc, 0, 0, 0xB8074A); | |
9436cdf9 JR |
4169 | #else |
4170 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, | |
4171 | compat_hdc, 0, 0, 0xE20746); | |
791f420f JR |
4172 | #endif |
4173 | SelectObject (s->hdc, orig_brush); | |
4174 | DeleteObject (fg_brush); | |
4175 | SelectObject (compat_hdc, orig_obj); | |
4176 | DeleteDC (compat_hdc); | |
4177 | } | |
4178 | DeleteObject (pixmap); | |
4179 | pixmap = 0; | |
4180 | } | |
4181 | else | |
4182 | x_draw_image_foreground (s); | |
ee78dc32 | 4183 | |
791f420f JR |
4184 | /* If we must draw a relief around the image, do it. */ |
4185 | if (s->img->relief | |
4186 | || s->hl == DRAW_IMAGE_RAISED | |
4187 | || s->hl == DRAW_IMAGE_SUNKEN) | |
4188 | x_draw_image_relief (s); | |
4189 | } | |
ee78dc32 | 4190 | |
cabb23bc | 4191 | |
791f420f | 4192 | /* Draw stretch glyph string S. */ |
cabb23bc | 4193 | |
791f420f JR |
4194 | static void |
4195 | x_draw_stretch_glyph_string (s) | |
4196 | struct glyph_string *s; | |
4197 | { | |
4198 | xassert (s->first_glyph->type == STRETCH_GLYPH); | |
4199 | s->stippled_p = s->face->stipple != 0; | |
65c4903c | 4200 | |
791f420f JR |
4201 | if (s->hl == DRAW_CURSOR |
4202 | && !x_stretch_cursor_p) | |
4203 | { | |
4204 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor | |
4205 | as wide as the stretch glyph. */ | |
4206 | int width = min (CANON_X_UNIT (s->f), s->background_width); | |
cabb23bc | 4207 | |
791f420f JR |
4208 | /* Draw cursor. */ |
4209 | x_draw_glyph_string_bg_rect (s, s->x, s->y, width, s->height); | |
cabb23bc | 4210 | |
791f420f JR |
4211 | /* Clear rest using the GC of the original non-cursor face. */ |
4212 | if (width < s->background_width) | |
4213 | { | |
4214 | XGCValues *gc = s->face->gc; | |
4215 | int x = s->x + width, y = s->y; | |
4216 | int w = s->background_width - width, h = s->height; | |
4217 | RECT r; | |
4218 | HDC hdc = s->hdc; | |
9f5a911b JR |
4219 | |
4220 | if (s->row->mouse_face_p | |
4221 | && cursor_in_mouse_face_p (s->w)) | |
4222 | { | |
4223 | x_set_mouse_face_gc (s); | |
4224 | gc = s->gc; | |
4225 | } | |
4226 | else | |
4227 | gc = s->face->gc; | |
4228 | ||
791f420f JR |
4229 | w32_get_glyph_string_clip_rect (s, &r); |
4230 | w32_set_clip_rectangle (hdc, &r); | |
4231 | ||
01b220b6 | 4232 | #if 0 /* TODO: stipple */ |
791f420f JR |
4233 | if (s->face->stipple) |
4234 | { | |
4235 | /* Fill background with a stipple pattern. */ | |
4236 | XSetFillStyle (s->display, gc, FillOpaqueStippled); | |
4237 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
4238 | XSetFillStyle (s->display, gc, FillSolid); | |
4239 | } | |
4240 | else | |
4241 | #endif | |
4242 | { | |
4243 | w32_fill_area (s->f, s->hdc, gc->background, x, y, w, h); | |
4244 | } | |
4245 | } | |
4246 | } | |
9f5a911b | 4247 | else if (!s->background_filled_p) |
791f420f JR |
4248 | x_draw_glyph_string_bg_rect (s, s->x, s->y, s->background_width, |
4249 | s->height); | |
4250 | ||
4251 | s->background_filled_p = 1; | |
4252 | } | |
cabb23bc | 4253 | |
cabb23bc | 4254 | |
791f420f JR |
4255 | /* Draw glyph string S. */ |
4256 | ||
4257 | static void | |
4258 | x_draw_glyph_string (s) | |
4259 | struct glyph_string *s; | |
4260 | { | |
858a55c1 AI |
4261 | int relief_drawn_p = 0; |
4262 | ||
791f420f JR |
4263 | /* If S draws into the background of its successor, draw the |
4264 | background of the successor first so that S can draw into it. | |
4265 | This makes S->next use XDrawString instead of XDrawImageString. */ | |
4266 | if (s->next && s->right_overhang && !s->for_overlaps_p) | |
4267 | { | |
4268 | xassert (s->next->img == NULL); | |
4269 | x_set_glyph_string_gc (s->next); | |
4270 | x_set_glyph_string_clipping (s->next); | |
4271 | x_draw_glyph_string_background (s->next, 1); | |
4272 | } | |
4273 | ||
4274 | /* Set up S->gc, set clipping and draw S. */ | |
4275 | x_set_glyph_string_gc (s); | |
791f420f | 4276 | |
858a55c1 AI |
4277 | /* Draw relief (if any) in advance for char/composition so that the |
4278 | glyph string can be drawn over it. */ | |
4279 | if (!s->for_overlaps_p | |
4280 | && s->face->box != FACE_NO_BOX | |
4281 | && (s->first_glyph->type == CHAR_GLYPH | |
4282 | || s->first_glyph->type == COMPOSITE_GLYPH)) | |
4283 | ||
4284 | { | |
9f5a911b | 4285 | x_set_glyph_string_clipping (s); |
858a55c1 AI |
4286 | x_draw_glyph_string_background (s, 1); |
4287 | x_draw_glyph_string_box (s); | |
9f5a911b | 4288 | x_set_glyph_string_clipping (s); |
858a55c1 AI |
4289 | relief_drawn_p = 1; |
4290 | } | |
9f5a911b JR |
4291 | else |
4292 | x_set_glyph_string_clipping (s); | |
858a55c1 | 4293 | |
791f420f JR |
4294 | switch (s->first_glyph->type) |
4295 | { | |
4296 | case IMAGE_GLYPH: | |
4297 | x_draw_image_glyph_string (s); | |
4298 | break; | |
4299 | ||
4300 | case STRETCH_GLYPH: | |
4301 | x_draw_stretch_glyph_string (s); | |
4302 | break; | |
4303 | ||
4304 | case CHAR_GLYPH: | |
4305 | if (s->for_overlaps_p) | |
4306 | s->background_filled_p = 1; | |
4307 | else | |
4308 | x_draw_glyph_string_background (s, 0); | |
4309 | x_draw_glyph_string_foreground (s); | |
4310 | break; | |
4311 | ||
4312 | case COMPOSITE_GLYPH: | |
4313 | if (s->for_overlaps_p || s->gidx > 0) | |
4314 | s->background_filled_p = 1; | |
4315 | else | |
4316 | x_draw_glyph_string_background (s, 1); | |
4317 | x_draw_composite_glyph_string_foreground (s); | |
4318 | break; | |
4319 | ||
4320 | default: | |
4321 | abort (); | |
4322 | } | |
4323 | ||
4324 | if (!s->for_overlaps_p) | |
4325 | { | |
4326 | /* Draw underline. */ | |
9ef2e2cf JR |
4327 | if (s->face->underline_p |
4328 | && (s->font->bdf || !s->font->tm.tmUnderlined)) | |
791f420f JR |
4329 | { |
4330 | unsigned long h = 1; | |
4331 | unsigned long dy = s->height - h; | |
4332 | ||
9f5a911b JR |
4333 | /* TODO: Use font information for positioning and thickness |
4334 | of underline. See OUTLINETEXTMETRIC, and xterm.c. */ | |
791f420f JR |
4335 | if (s->face->underline_defaulted_p) |
4336 | { | |
4337 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
4338 | s->y + dy, s->width, 1); | |
4339 | } | |
4340 | else | |
4341 | { | |
4342 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4343 | s->y + dy, s->width, 1); | |
4344 | } | |
4345 | } | |
4346 | ||
4347 | /* Draw overline. */ | |
4348 | if (s->face->overline_p) | |
4349 | { | |
4350 | unsigned long dy = 0, h = 1; | |
4351 | ||
4352 | if (s->face->overline_color_defaulted_p) | |
4353 | { | |
4354 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
4355 | s->y + dy, s->width, h); | |
4356 | } | |
4357 | else | |
4358 | { | |
4359 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4360 | s->y + dy, s->width, h); | |
4361 | } | |
4362 | } | |
4363 | ||
4364 | /* Draw strike-through. */ | |
9ef2e2cf JR |
4365 | if (s->face->strike_through_p |
4366 | && (s->font->bdf || !s->font->tm.tmStruckOut)) | |
791f420f JR |
4367 | { |
4368 | unsigned long h = 1; | |
4369 | unsigned long dy = (s->height - h) / 2; | |
4370 | ||
4371 | if (s->face->strike_through_color_defaulted_p) | |
4372 | { | |
4373 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, s->y + dy, | |
4374 | s->width, h); | |
4375 | } | |
4376 | else | |
4377 | { | |
4378 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4379 | s->y + dy, s->width, h); | |
4380 | } | |
4381 | } | |
4382 | ||
4383 | /* Draw relief. */ | |
858a55c1 | 4384 | if (!relief_drawn_p && s->face->box != FACE_NO_BOX) |
791f420f JR |
4385 | x_draw_glyph_string_box (s); |
4386 | } | |
4387 | ||
4388 | /* Reset clipping. */ | |
4389 | w32_set_clip_rectangle (s->hdc, NULL); | |
4390 | } | |
4391 | ||
4392 | ||
4393 | static int x_fill_composite_glyph_string P_ ((struct glyph_string *, | |
4394 | struct face **, int)); | |
4395 | ||
4396 | ||
c2cc16fa JR |
4397 | /* Fill glyph string S with composition components specified by S->cmp. |
4398 | ||
791f420f JR |
4399 | FACES is an array of faces for all components of this composition. |
4400 | S->gidx is the index of the first component for S. | |
4401 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
c2cc16fa | 4402 | use its physical height for clipping. |
791f420f JR |
4403 | |
4404 | Value is the index of a component not in S. */ | |
4405 | ||
4406 | static int | |
4407 | x_fill_composite_glyph_string (s, faces, overlaps_p) | |
4408 | struct glyph_string *s; | |
4409 | struct face **faces; | |
4410 | int overlaps_p; | |
4411 | { | |
4412 | int i; | |
4413 | ||
4414 | xassert (s); | |
4415 | ||
4416 | s->for_overlaps_p = overlaps_p; | |
4417 | ||
4418 | s->face = faces[s->gidx]; | |
4419 | s->font = s->face->font; | |
4420 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4421 | ||
4422 | /* For all glyphs of this composition, starting at the offset | |
4423 | S->gidx, until we reach the end of the definition or encounter a | |
4424 | glyph that requires the different face, add it to S. */ | |
4425 | ++s->nchars; | |
4426 | for (i = s->gidx + 1; i < s->cmp->glyph_len && faces[i] == s->face; ++i) | |
4427 | ++s->nchars; | |
4428 | ||
4429 | /* All glyph strings for the same composition has the same width, | |
4430 | i.e. the width set for the first component of the composition. */ | |
4431 | ||
4432 | s->width = s->first_glyph->pixel_width; | |
4433 | ||
4434 | /* If the specified font could not be loaded, use the frame's | |
4435 | default font, but record the fact that we couldn't load it in | |
4436 | the glyph string so that we can draw rectangles for the | |
4437 | characters of the glyph string. */ | |
4438 | if (s->font == NULL) | |
4439 | { | |
4440 | s->font_not_found_p = 1; | |
4441 | s->font = FRAME_FONT (s->f); | |
4442 | } | |
4443 | ||
4444 | /* Adjust base line for subscript/superscript text. */ | |
4445 | s->ybase += s->first_glyph->voffset; | |
4446 | ||
4447 | xassert (s->face && s->face->gc); | |
4448 | ||
4449 | /* This glyph string must always be drawn with 16-bit functions. */ | |
4450 | s->two_byte_p = 1; | |
4451 | ||
4452 | return s->gidx + s->nchars; | |
4453 | } | |
4454 | ||
4455 | ||
c2cc16fa JR |
4456 | /* Fill glyph string S from a sequence of character glyphs. |
4457 | ||
791f420f JR |
4458 | FACE_ID is the face id of the string. START is the index of the |
4459 | first glyph to consider, END is the index of the last + 1. | |
4460 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
c2cc16fa | 4461 | use its physical height for clipping. |
791f420f JR |
4462 | |
4463 | Value is the index of the first glyph not in S. */ | |
4464 | ||
4465 | static int | |
4466 | x_fill_glyph_string (s, face_id, start, end, overlaps_p) | |
4467 | struct glyph_string *s; | |
4468 | int face_id; | |
4469 | int start, end, overlaps_p; | |
4470 | { | |
4471 | struct glyph *glyph, *last; | |
4472 | int voffset; | |
93ff4395 | 4473 | int glyph_not_available_p; |
791f420f JR |
4474 | |
4475 | xassert (s->f == XFRAME (s->w->frame)); | |
4476 | xassert (s->nchars == 0); | |
4477 | xassert (start >= 0 && end > start); | |
4478 | ||
4479 | s->for_overlaps_p = overlaps_p; | |
791f420f JR |
4480 | glyph = s->row->glyphs[s->area] + start; |
4481 | last = s->row->glyphs[s->area] + end; | |
4482 | voffset = glyph->voffset; | |
93ff4395 JR |
4483 | |
4484 | glyph_not_available_p = glyph->glyph_not_available_p; | |
4485 | ||
791f420f JR |
4486 | while (glyph < last |
4487 | && glyph->type == CHAR_GLYPH | |
4488 | && glyph->voffset == voffset | |
93ff4395 JR |
4489 | /* Same face id implies same font, nowadays. */ |
4490 | && glyph->face_id == face_id | |
4491 | && glyph->glyph_not_available_p == glyph_not_available_p) | |
791f420f | 4492 | { |
93ff4395 JR |
4493 | int two_byte_p; |
4494 | ||
791f420f | 4495 | s->face = x_get_glyph_face_and_encoding (s->f, glyph, |
93ff4395 JR |
4496 | s->char2b + s->nchars, |
4497 | &two_byte_p); | |
4498 | s->two_byte_p = two_byte_p; | |
791f420f JR |
4499 | ++s->nchars; |
4500 | xassert (s->nchars <= end - start); | |
4501 | s->width += glyph->pixel_width; | |
4502 | ++glyph; | |
4503 | } | |
4504 | ||
4505 | s->font = s->face->font; | |
4506 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4507 | ||
4508 | /* If the specified font could not be loaded, use the frame's font, | |
4509 | but record the fact that we couldn't load it in | |
4510 | S->font_not_found_p so that we can draw rectangles for the | |
4511 | characters of the glyph string. */ | |
93ff4395 | 4512 | if (s->font == NULL || glyph_not_available_p) |
791f420f JR |
4513 | { |
4514 | s->font_not_found_p = 1; | |
4515 | s->font = FRAME_FONT (s->f); | |
4516 | } | |
4517 | ||
4518 | /* Adjust base line for subscript/superscript text. */ | |
4519 | s->ybase += voffset; | |
4520 | ||
4521 | xassert (s->face && s->face->gc); | |
4522 | return glyph - s->row->glyphs[s->area]; | |
4523 | } | |
4524 | ||
4525 | ||
4526 | /* Fill glyph string S from image glyph S->first_glyph. */ | |
4527 | ||
4528 | static void | |
4529 | x_fill_image_glyph_string (s) | |
4530 | struct glyph_string *s; | |
4531 | { | |
4532 | xassert (s->first_glyph->type == IMAGE_GLYPH); | |
4533 | s->img = IMAGE_FROM_ID (s->f, s->first_glyph->u.img_id); | |
4534 | xassert (s->img); | |
4535 | s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id); | |
4536 | s->font = s->face->font; | |
4537 | s->width = s->first_glyph->pixel_width; | |
4538 | ||
4539 | /* Adjust base line for subscript/superscript text. */ | |
4540 | s->ybase += s->first_glyph->voffset; | |
4541 | } | |
4542 | ||
4543 | ||
ec48c3a7 | 4544 | /* Fill glyph string S from a sequence of stretch glyphs. |
791f420f | 4545 | |
ec48c3a7 JR |
4546 | ROW is the glyph row in which the glyphs are found, AREA is the |
4547 | area within the row. START is the index of the first glyph to | |
4548 | consider, END is the index of the last + 1. | |
4549 | ||
4550 | Value is the index of the first glyph not in S. */ | |
4551 | ||
4552 | static int | |
4553 | x_fill_stretch_glyph_string (s, row, area, start, end) | |
791f420f | 4554 | struct glyph_string *s; |
ec48c3a7 JR |
4555 | struct glyph_row *row; |
4556 | enum glyph_row_area area; | |
4557 | int start, end; | |
791f420f | 4558 | { |
ec48c3a7 JR |
4559 | struct glyph *glyph, *last; |
4560 | int voffset, face_id; | |
4561 | ||
791f420f | 4562 | xassert (s->first_glyph->type == STRETCH_GLYPH); |
ec48c3a7 JR |
4563 | |
4564 | glyph = s->row->glyphs[s->area] + start; | |
4565 | last = s->row->glyphs[s->area] + end; | |
4566 | face_id = glyph->face_id; | |
4567 | s->face = FACE_FROM_ID (s->f, face_id); | |
791f420f | 4568 | s->font = s->face->font; |
ec48c3a7 JR |
4569 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); |
4570 | s->width = glyph->pixel_width; | |
4571 | voffset = glyph->voffset; | |
4572 | ||
4573 | for (++glyph; | |
4574 | (glyph < last | |
4575 | && glyph->type == STRETCH_GLYPH | |
4576 | && glyph->voffset == voffset | |
4577 | && glyph->face_id == face_id); | |
4578 | ++glyph) | |
4579 | s->width += glyph->pixel_width; | |
791f420f JR |
4580 | |
4581 | /* Adjust base line for subscript/superscript text. */ | |
ec48c3a7 JR |
4582 | s->ybase += voffset; |
4583 | ||
9f5a911b | 4584 | xassert (s->face); |
ec48c3a7 | 4585 | return glyph - s->row->glyphs[s->area]; |
791f420f JR |
4586 | } |
4587 | ||
4588 | ||
4589 | /* Initialize glyph string S. CHAR2B is a suitably allocated vector | |
4590 | of XChar2b structures for S; it can't be allocated in | |
4591 | x_init_glyph_string because it must be allocated via `alloca'. W | |
4592 | is the window on which S is drawn. ROW and AREA are the glyph row | |
4593 | and area within the row from which S is constructed. START is the | |
4594 | index of the first glyph structure covered by S. HL is a | |
4595 | face-override for drawing S. */ | |
4596 | ||
4597 | static void | |
4598 | w32_init_glyph_string (s, hdc, char2b, w, row, area, start, hl) | |
4599 | struct glyph_string *s; | |
4600 | HDC hdc; | |
4601 | wchar_t *char2b; | |
4602 | struct window *w; | |
4603 | struct glyph_row *row; | |
4604 | enum glyph_row_area area; | |
4605 | int start; | |
4606 | enum draw_glyphs_face hl; | |
4607 | { | |
4608 | bzero (s, sizeof *s); | |
4609 | s->w = w; | |
4610 | s->f = XFRAME (w->frame); | |
4611 | s->hdc = hdc; | |
4612 | s->window = FRAME_W32_WINDOW (s->f); | |
4613 | s->char2b = char2b; | |
4614 | s->hl = hl; | |
4615 | s->row = row; | |
4616 | s->area = area; | |
4617 | s->first_glyph = row->glyphs[area] + start; | |
4618 | s->height = row->height; | |
4619 | s->y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
4620 | ||
4621 | /* Display the internal border below the tool-bar window. */ | |
4622 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
4623 | s->y -= s->f->output_data.w32->internal_border_width; | |
4624 | ||
4625 | s->ybase = s->y + row->ascent; | |
4626 | } | |
4627 | ||
4628 | ||
4629 | /* Set background width of glyph string S. START is the index of the | |
4630 | first glyph following S. LAST_X is the right-most x-position + 1 | |
4631 | in the drawing area. */ | |
4632 | ||
4633 | static INLINE void | |
4634 | x_set_glyph_string_background_width (s, start, last_x) | |
4635 | struct glyph_string *s; | |
4636 | int start; | |
4637 | int last_x; | |
4638 | { | |
4639 | /* If the face of this glyph string has to be drawn to the end of | |
4640 | the drawing area, set S->extends_to_end_of_line_p. */ | |
4641 | struct face *default_face = FACE_FROM_ID (s->f, DEFAULT_FACE_ID); | |
4642 | ||
4643 | if (start == s->row->used[s->area] | |
5b844253 | 4644 | && s->area == TEXT_AREA |
f4fccc1e EZ |
4645 | && ((s->hl == DRAW_NORMAL_TEXT |
4646 | && (s->row->fill_line_p | |
4647 | || s->face->background != default_face->background | |
4648 | || s->face->stipple != default_face->stipple | |
4649 | || s->row->mouse_face_p)) | |
4650 | || s->hl == DRAW_MOUSE_FACE)) | |
791f420f JR |
4651 | s->extends_to_end_of_line_p = 1; |
4652 | ||
4653 | /* If S extends its face to the end of the line, set its | |
4654 | background_width to the distance to the right edge of the drawing | |
4655 | area. */ | |
4656 | if (s->extends_to_end_of_line_p) | |
4657 | s->background_width = last_x - s->x + 1; | |
4658 | else | |
4659 | s->background_width = s->width; | |
4660 | } | |
4661 | ||
4662 | ||
4663 | /* Add a glyph string for a stretch glyph to the list of strings | |
4664 | between HEAD and TAIL. START is the index of the stretch glyph in | |
4665 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4666 | in that glyph row area. X is the current output position assigned | |
4667 | to the new glyph string constructed. HL overrides that face of the | |
4668 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4669 | is the right-most x-position of the drawing area. */ | |
4670 | ||
4671 | #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
4672 | do \ | |
4673 | { \ | |
4674 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4675 | w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \ | |
ec48c3a7 | 4676 | START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \ |
791f420f | 4677 | x_append_glyph_string (&HEAD, &TAIL, s); \ |
791f420f JR |
4678 | s->x = (X); \ |
4679 | } \ | |
4680 | while (0) | |
4681 | ||
4682 | ||
4683 | /* Add a glyph string for an image glyph to the list of strings | |
4684 | between HEAD and TAIL. START is the index of the image glyph in | |
4685 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4686 | in that glyph row area. X is the current output position assigned | |
4687 | to the new glyph string constructed. HL overrides that face of the | |
4688 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4689 | is the right-most x-position of the drawing area. */ | |
4690 | ||
4691 | #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
4692 | do \ | |
4693 | { \ | |
4694 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4695 | w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \ | |
4696 | x_fill_image_glyph_string (s); \ | |
4697 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
4698 | ++START; \ | |
4699 | s->x = (X); \ | |
4700 | } \ | |
4701 | while (0) | |
4702 | ||
4703 | ||
4704 | /* Add a glyph string for a sequence of character glyphs to the list | |
4705 | of strings between HEAD and TAIL. START is the index of the first | |
4706 | glyph in row area AREA of glyph row ROW that is part of the new | |
4707 | glyph string. END is the index of the last glyph in that glyph row | |
4708 | area. X is the current output position assigned to the new glyph | |
4709 | string constructed. HL overrides that face of the glyph; e.g. it | |
4710 | is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the | |
4711 | right-most x-position of the drawing area. */ | |
4712 | ||
4713 | #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4714 | do \ | |
4715 | { \ | |
ec48c3a7 | 4716 | int c, face_id; \ |
791f420f JR |
4717 | wchar_t *char2b; \ |
4718 | \ | |
4719 | c = (ROW)->glyphs[AREA][START].u.ch; \ | |
791f420f | 4720 | face_id = (ROW)->glyphs[AREA][START].face_id; \ |
9ef2e2cf | 4721 | \ |
791f420f JR |
4722 | s = (struct glyph_string *) alloca (sizeof *s); \ |
4723 | char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \ | |
4724 | w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \ | |
4725 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
791f420f JR |
4726 | s->x = (X); \ |
4727 | START = x_fill_glyph_string (s, face_id, START, END, \ | |
4728 | OVERLAPS_P); \ | |
4729 | } \ | |
4730 | while (0) | |
4731 | ||
4732 | ||
4733 | /* Add a glyph string for a composite sequence to the list of strings | |
4734 | between HEAD and TAIL. START is the index of the first glyph in | |
4735 | row area AREA of glyph row ROW that is part of the new glyph | |
4736 | string. END is the index of the last glyph in that glyph row area. | |
4737 | X is the current output position assigned to the new glyph string | |
4738 | constructed. HL overrides that face of the glyph; e.g. it is | |
4739 | DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most | |
4740 | x-position of the drawing area. */ | |
4741 | ||
4742 | #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4743 | do { \ | |
4744 | int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \ | |
4745 | int face_id = (ROW)->glyphs[AREA][START].face_id; \ | |
93ff4395 | 4746 | struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \ |
791f420f JR |
4747 | struct composition *cmp = composition_table[cmp_id]; \ |
4748 | int glyph_len = cmp->glyph_len; \ | |
4749 | wchar_t *char2b; \ | |
4750 | struct face **faces; \ | |
4751 | struct glyph_string *first_s = NULL; \ | |
4752 | int n; \ | |
4753 | \ | |
93ff4395 | 4754 | base_face = base_face->ascii_face; \ |
791f420f JR |
4755 | char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \ |
4756 | faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \ | |
4757 | /* At first, fill in `char2b' and `faces'. */ \ | |
4758 | for (n = 0; n < glyph_len; n++) \ | |
4759 | { \ | |
4760 | int c = COMPOSITION_GLYPH (cmp, n); \ | |
93ff4395 JR |
4761 | int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \ |
4762 | faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \ | |
4763 | x_get_char_face_and_encoding (XFRAME (w->frame), c, \ | |
4764 | this_face_id, char2b + n, 1); \ | |
791f420f JR |
4765 | } \ |
4766 | \ | |
4767 | /* Make glyph_strings for each glyph sequence that is drawable by \ | |
4768 | the same face, and append them to HEAD/TAIL. */ \ | |
4769 | for (n = 0; n < cmp->glyph_len;) \ | |
4770 | { \ | |
4771 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4772 | w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \ | |
4773 | x_append_glyph_string (&(HEAD), &(TAIL), s); \ | |
4774 | s->cmp = cmp; \ | |
4775 | s->gidx = n; \ | |
791f420f JR |
4776 | s->x = (X); \ |
4777 | \ | |
4778 | if (n == 0) \ | |
4779 | first_s = s; \ | |
4780 | \ | |
4781 | n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \ | |
4782 | } \ | |
4783 | \ | |
4784 | ++START; \ | |
4785 | s = first_s; \ | |
4786 | } while (0) | |
4787 | ||
9ef2e2cf | 4788 | |
791f420f JR |
4789 | /* Build a list of glyph strings between HEAD and TAIL for the glyphs |
4790 | of AREA of glyph row ROW on window W between indices START and END. | |
4791 | HL overrides the face for drawing glyph strings, e.g. it is | |
4792 | DRAW_CURSOR to draw a cursor. X and LAST_X are start and end | |
4793 | x-positions of the drawing area. | |
4794 | ||
4795 | This is an ugly monster macro construct because we must use alloca | |
4796 | to allocate glyph strings (because x_draw_glyphs can be called | |
4797 | asynchronously). */ | |
4798 | ||
4799 | #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4800 | do \ | |
4801 | { \ | |
4802 | HEAD = TAIL = NULL; \ | |
4803 | while (START < END) \ | |
4804 | { \ | |
4805 | struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \ | |
4806 | switch (first_glyph->type) \ | |
4807 | { \ | |
4808 | case CHAR_GLYPH: \ | |
4809 | BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \ | |
4810 | HEAD, TAIL, HL, X, LAST_X, \ | |
4811 | OVERLAPS_P); \ | |
4812 | break; \ | |
4813 | \ | |
4814 | case COMPOSITE_GLYPH: \ | |
4815 | BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \ | |
4816 | END, HEAD, TAIL, HL, X, \ | |
4817 | LAST_X, OVERLAPS_P); \ | |
4818 | break; \ | |
4819 | \ | |
4820 | case STRETCH_GLYPH: \ | |
4821 | BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\ | |
4822 | HEAD, TAIL, HL, X, LAST_X); \ | |
4823 | break; \ | |
4824 | \ | |
4825 | case IMAGE_GLYPH: \ | |
4826 | BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \ | |
4827 | HEAD, TAIL, HL, X, LAST_X); \ | |
4828 | break; \ | |
4829 | \ | |
4830 | default: \ | |
4831 | abort (); \ | |
4832 | } \ | |
4833 | \ | |
4834 | x_set_glyph_string_background_width (s, START, LAST_X); \ | |
4835 | (X) += s->width; \ | |
4836 | } \ | |
4837 | } \ | |
4838 | while (0) | |
4839 | ||
4840 | ||
4841 | /* Draw glyphs between START and END in AREA of ROW on window W, | |
4842 | starting at x-position X. X is relative to AREA in W. HL is a | |
4843 | face-override with the following meaning: | |
4844 | ||
4845 | DRAW_NORMAL_TEXT draw normally | |
4846 | DRAW_CURSOR draw in cursor face | |
4847 | DRAW_MOUSE_FACE draw in mouse face. | |
4848 | DRAW_INVERSE_VIDEO draw in mode line face | |
4849 | DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it | |
4850 | DRAW_IMAGE_RAISED draw an image with a raised relief around it | |
4851 | ||
4852 | If REAL_START is non-null, return in *REAL_START the real starting | |
4853 | position for display. This can be different from START in case | |
4854 | overlapping glyphs must be displayed. If REAL_END is non-null, | |
4855 | return in *REAL_END the real end position for display. This can be | |
4856 | different from END in case overlapping glyphs must be displayed. | |
4857 | ||
4858 | If OVERLAPS_P is non-zero, draw only the foreground of characters | |
4859 | and clip to the physical height of ROW. | |
4860 | ||
4861 | Value is the x-position reached, relative to AREA of W. */ | |
4862 | ||
4863 | static int | |
4864 | x_draw_glyphs (w, x, row, area, start, end, hl, real_start, real_end, | |
4865 | overlaps_p) | |
4866 | struct window *w; | |
4867 | int x; | |
4868 | struct glyph_row *row; | |
4869 | enum glyph_row_area area; | |
4870 | int start, end; | |
4871 | enum draw_glyphs_face hl; | |
4872 | int *real_start, *real_end; | |
4873 | int overlaps_p; | |
4874 | { | |
4875 | struct glyph_string *head, *tail; | |
4876 | struct glyph_string *s; | |
4877 | int last_x, area_width; | |
4878 | int x_reached; | |
4879 | int i, j; | |
4880 | HDC hdc = get_frame_dc (XFRAME (WINDOW_FRAME (w))); | |
4881 | ||
4882 | /* Let's rather be paranoid than getting a SEGV. */ | |
791f420f | 4883 | end = min (end, row->used[area]); |
9127e20e JR |
4884 | start = max (0, start); |
4885 | start = min (end, start); | |
791f420f JR |
4886 | if (real_start) |
4887 | *real_start = start; | |
4888 | if (real_end) | |
4889 | *real_end = end; | |
4890 | ||
4891 | /* Translate X to frame coordinates. Set last_x to the right | |
4892 | end of the drawing area. */ | |
4893 | if (row->full_width_p) | |
4894 | { | |
791f420f JR |
4895 | /* X is relative to the left edge of W, without scroll bars |
4896 | or flag areas. */ | |
ec48c3a7 | 4897 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
791f420f JR |
4898 | /* int width = FRAME_FLAGS_AREA_WIDTH (f); */ |
4899 | int window_left_x = WINDOW_LEFT_MARGIN (w) * CANON_X_UNIT (f); | |
ee78dc32 | 4900 | |
791f420f JR |
4901 | x += window_left_x; |
4902 | area_width = XFASTINT (w->width) * CANON_X_UNIT (f); | |
4903 | last_x = window_left_x + area_width; | |
ee78dc32 | 4904 | |
791f420f JR |
4905 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
4906 | { | |
4907 | int width = FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
4908 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
4909 | last_x += width; | |
4910 | else | |
4911 | x -= width; | |
4912 | } | |
ee78dc32 | 4913 | |
791f420f JR |
4914 | x += FRAME_INTERNAL_BORDER_WIDTH (f); |
4915 | last_x -= FRAME_INTERNAL_BORDER_WIDTH (f); | |
4916 | } | |
4917 | else | |
4918 | { | |
4919 | x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, x); | |
4920 | area_width = window_box_width (w, area); | |
4921 | last_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, area_width); | |
4922 | } | |
e12ca9c2 | 4923 | |
791f420f JR |
4924 | /* Build a doubly-linked list of glyph_string structures between |
4925 | head and tail from what we have to draw. Note that the macro | |
4926 | BUILD_GLYPH_STRINGS will modify its start parameter. That's | |
4927 | the reason we use a separate variable `i'. */ | |
4928 | i = start; | |
4929 | BUILD_GLYPH_STRINGS (hdc, w, row, area, i, end, head, tail, hl, x, last_x, | |
4930 | overlaps_p); | |
791f420f JR |
4931 | if (tail) |
4932 | x_reached = tail->x + tail->background_width; | |
4933 | else | |
4934 | x_reached = x; | |
e12ca9c2 | 4935 | |
791f420f JR |
4936 | /* If there are any glyphs with lbearing < 0 or rbearing > width in |
4937 | the row, redraw some glyphs in front or following the glyph | |
4938 | strings built above. */ | |
9127e20e | 4939 | if (head && !overlaps_p && row->contains_overlapping_glyphs_p) |
791f420f JR |
4940 | { |
4941 | int dummy_x = 0; | |
4942 | struct glyph_string *h, *t; | |
4943 | ||
4944 | /* Compute overhangs for all glyph strings. */ | |
4945 | for (s = head; s; s = s->next) | |
4946 | x_compute_glyph_string_overhangs (s); | |
4947 | ||
4948 | /* Prepend glyph strings for glyphs in front of the first glyph | |
4949 | string that are overwritten because of the first glyph | |
4950 | string's left overhang. The background of all strings | |
4951 | prepended must be drawn because the first glyph string | |
4952 | draws over it. */ | |
4953 | i = x_left_overwritten (head); | |
4954 | if (i >= 0) | |
4955 | { | |
4956 | j = i; | |
4957 | BUILD_GLYPH_STRINGS (hdc, w, row, area, j, start, h, t, | |
4958 | DRAW_NORMAL_TEXT, dummy_x, last_x, | |
4959 | overlaps_p); | |
4960 | start = i; | |
4961 | if (real_start) | |
4962 | *real_start = start; | |
4963 | x_compute_overhangs_and_x (t, head->x, 1); | |
4964 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4965 | } | |
ee78dc32 | 4966 | |
791f420f JR |
4967 | /* Prepend glyph strings for glyphs in front of the first glyph |
4968 | string that overwrite that glyph string because of their | |
4969 | right overhang. For these strings, only the foreground must | |
4970 | be drawn, because it draws over the glyph string at `head'. | |
4971 | The background must not be drawn because this would overwrite | |
4972 | right overhangs of preceding glyphs for which no glyph | |
4973 | strings exist. */ | |
4974 | i = x_left_overwriting (head); | |
4975 | if (i >= 0) | |
4976 | { | |
4977 | BUILD_GLYPH_STRINGS (hdc, w, row, area, i, start, h, t, | |
4978 | DRAW_NORMAL_TEXT, dummy_x, last_x, | |
4979 | overlaps_p); | |
791f420f JR |
4980 | for (s = h; s; s = s->next) |
4981 | s->background_filled_p = 1; | |
4982 | if (real_start) | |
4983 | *real_start = i; | |
4984 | x_compute_overhangs_and_x (t, head->x, 1); | |
4985 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4986 | } | |
cabb23bc | 4987 | |
791f420f JR |
4988 | /* Append glyphs strings for glyphs following the last glyph |
4989 | string tail that are overwritten by tail. The background of | |
4990 | these strings has to be drawn because tail's foreground draws | |
4991 | over it. */ | |
4992 | i = x_right_overwritten (tail); | |
4993 | if (i >= 0) | |
4994 | { | |
4995 | BUILD_GLYPH_STRINGS (hdc, w, row, area, end, i, h, t, | |
4996 | DRAW_NORMAL_TEXT, x, last_x, | |
4997 | overlaps_p); | |
791f420f JR |
4998 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); |
4999 | x_append_glyph_string_lists (&head, &tail, h, t); | |
5000 | if (real_end) | |
5001 | *real_end = i; | |
5002 | } | |
cabb23bc | 5003 | |
791f420f JR |
5004 | /* Append glyph strings for glyphs following the last glyph |
5005 | string tail that overwrite tail. The foreground of such | |
5006 | glyphs has to be drawn because it writes into the background | |
5007 | of tail. The background must not be drawn because it could | |
5008 | paint over the foreground of following glyphs. */ | |
5009 | i = x_right_overwriting (tail); | |
5010 | if (i >= 0) | |
5011 | { | |
5012 | BUILD_GLYPH_STRINGS (hdc, w, row, area, end, i, h, t, | |
5013 | DRAW_NORMAL_TEXT, x, last_x, | |
5014 | overlaps_p); | |
791f420f JR |
5015 | for (s = h; s; s = s->next) |
5016 | s->background_filled_p = 1; | |
5017 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); | |
5018 | x_append_glyph_string_lists (&head, &tail, h, t); | |
5019 | if (real_end) | |
5020 | *real_end = i; | |
5021 | } | |
5022 | } | |
cabb23bc | 5023 | |
791f420f JR |
5024 | /* Draw all strings. */ |
5025 | for (s = head; s; s = s->next) | |
5026 | x_draw_glyph_string (s); | |
cabb23bc | 5027 | |
791f420f JR |
5028 | /* Value is the x-position up to which drawn, relative to AREA of W. |
5029 | This doesn't include parts drawn because of overhangs. */ | |
5030 | x_reached = FRAME_TO_WINDOW_PIXEL_X (w, x_reached); | |
5031 | if (!row->full_width_p) | |
5032 | { | |
5033 | if (area > LEFT_MARGIN_AREA) | |
5034 | x_reached -= window_box_width (w, LEFT_MARGIN_AREA); | |
5035 | if (area > TEXT_AREA) | |
5036 | x_reached -= window_box_width (w, TEXT_AREA); | |
5037 | } | |
cabb23bc | 5038 | |
791f420f | 5039 | release_frame_dc (XFRAME (WINDOW_FRAME (w)), hdc); |
65c4903c | 5040 | |
791f420f JR |
5041 | return x_reached; |
5042 | } | |
65c4903c | 5043 | |
cabb23bc | 5044 | |
791f420f JR |
5045 | /* Fix the display of area AREA of overlapping row ROW in window W. */ |
5046 | ||
5047 | static void | |
5048 | x_fix_overlapping_area (w, row, area) | |
5049 | struct window *w; | |
5050 | struct glyph_row *row; | |
5051 | enum glyph_row_area area; | |
5052 | { | |
5053 | int i, x; | |
5054 | ||
5055 | BLOCK_INPUT; | |
5056 | ||
5057 | if (area == LEFT_MARGIN_AREA) | |
5058 | x = 0; | |
5059 | else if (area == TEXT_AREA) | |
5060 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5061 | else | |
5062 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5063 | + window_box_width (w, TEXT_AREA)); | |
b1ae662f | 5064 | |
791f420f JR |
5065 | for (i = 0; i < row->used[area];) |
5066 | { | |
5067 | if (row->glyphs[area][i].overlaps_vertically_p) | |
ee78dc32 | 5068 | { |
791f420f | 5069 | int start = i, start_x = x; |
ee78dc32 | 5070 | |
791f420f JR |
5071 | do |
5072 | { | |
5073 | x += row->glyphs[area][i].pixel_width; | |
5074 | ++i; | |
5075 | } | |
5076 | while (i < row->used[area] | |
5077 | && row->glyphs[area][i].overlaps_vertically_p); | |
cabb23bc | 5078 | |
791f420f | 5079 | x_draw_glyphs (w, start_x, row, area, start, i, |
e617a35b | 5080 | DRAW_NORMAL_TEXT, |
791f420f JR |
5081 | NULL, NULL, 1); |
5082 | } | |
5083 | else | |
5084 | { | |
5085 | x += row->glyphs[area][i].pixel_width; | |
5086 | ++i; | |
5087 | } | |
5088 | } | |
5089 | ||
5090 | UNBLOCK_INPUT; | |
ee78dc32 GV |
5091 | } |
5092 | ||
ee78dc32 | 5093 | |
791f420f JR |
5094 | /* Output LEN glyphs starting at START at the nominal cursor position. |
5095 | Advance the nominal cursor over the text. The global variable | |
5096 | updated_window contains the window being updated, updated_row is | |
5097 | the glyph row being updated, and updated_area is the area of that | |
5098 | row being updated. */ | |
ee78dc32 | 5099 | |
96214669 | 5100 | static void |
791f420f JR |
5101 | x_write_glyphs (start, len) |
5102 | struct glyph *start; | |
ee78dc32 GV |
5103 | int len; |
5104 | { | |
791f420f | 5105 | int x, hpos, real_start, real_end; |
ee78dc32 | 5106 | |
791f420f | 5107 | xassert (updated_window && updated_row); |
ee78dc32 | 5108 | BLOCK_INPUT; |
791f420f JR |
5109 | |
5110 | /* Write glyphs. */ | |
ee78dc32 | 5111 | |
791f420f JR |
5112 | hpos = start - updated_row->glyphs[updated_area]; |
5113 | x = x_draw_glyphs (updated_window, output_cursor.x, | |
5114 | updated_row, updated_area, | |
5115 | hpos, hpos + len, | |
e617a35b | 5116 | DRAW_NORMAL_TEXT, |
791f420f JR |
5117 | &real_start, &real_end, 0); |
5118 | ||
5119 | /* If we drew over the cursor, note that it is not visible any more. */ | |
5120 | note_overwritten_text_cursor (updated_window, real_start, | |
5121 | real_end - real_start); | |
5122 | ||
5123 | UNBLOCK_INPUT; | |
5124 | ||
5125 | /* Advance the output cursor. */ | |
5126 | output_cursor.hpos += len; | |
5127 | output_cursor.x = x; | |
5128 | } | |
ee78dc32 | 5129 | |
ee78dc32 | 5130 | |
791f420f | 5131 | /* Insert LEN glyphs from START at the nominal cursor position. */ |
ee78dc32 | 5132 | |
791f420f JR |
5133 | static void |
5134 | x_insert_glyphs (start, len) | |
5135 | struct glyph *start; | |
5136 | register int len; | |
5137 | { | |
5138 | struct frame *f; | |
5139 | struct window *w; | |
5140 | int line_height, shift_by_width, shifted_region_width; | |
5141 | struct glyph_row *row; | |
5142 | struct glyph *glyph; | |
5143 | int frame_x, frame_y, hpos, real_start, real_end; | |
5144 | HDC hdc; | |
5145 | ||
5146 | xassert (updated_window && updated_row); | |
5147 | BLOCK_INPUT; | |
5148 | w = updated_window; | |
5149 | f = XFRAME (WINDOW_FRAME (w)); | |
5150 | hdc = get_frame_dc (f); | |
5151 | ||
5152 | /* Get the height of the line we are in. */ | |
5153 | row = updated_row; | |
5154 | line_height = row->height; | |
5155 | ||
5156 | /* Get the width of the glyphs to insert. */ | |
5157 | shift_by_width = 0; | |
5158 | for (glyph = start; glyph < start + len; ++glyph) | |
5159 | shift_by_width += glyph->pixel_width; | |
5160 | ||
5161 | /* Get the width of the region to shift right. */ | |
5162 | shifted_region_width = (window_box_width (w, updated_area) | |
5163 | - output_cursor.x | |
5164 | - shift_by_width); | |
5165 | ||
5166 | /* Shift right. */ | |
5b844253 | 5167 | frame_x = window_box_left (w, updated_area) + output_cursor.x; |
791f420f JR |
5168 | frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); |
5169 | BitBlt (hdc, frame_x + shift_by_width, frame_y, | |
5170 | shifted_region_width, line_height, | |
5171 | hdc, frame_x, frame_y, SRCCOPY); | |
5172 | ||
5173 | /* Write the glyphs. */ | |
5174 | hpos = start - row->glyphs[updated_area]; | |
5175 | x_draw_glyphs (w, output_cursor.x, row, updated_area, hpos, hpos + len, | |
5176 | DRAW_NORMAL_TEXT, &real_start, &real_end, 0); | |
5177 | note_overwritten_text_cursor (w, real_start, real_end - real_start); | |
5178 | ||
5179 | /* Advance the output cursor. */ | |
5180 | output_cursor.hpos += len; | |
5181 | output_cursor.x += shift_by_width; | |
5182 | release_frame_dc (f, hdc); | |
ee78dc32 GV |
5183 | |
5184 | UNBLOCK_INPUT; | |
5185 | } | |
791f420f JR |
5186 | |
5187 | ||
5188 | /* Delete N glyphs at the nominal cursor position. Not implemented | |
5189 | for X frames. */ | |
ee78dc32 | 5190 | |
96214669 | 5191 | static void |
791f420f JR |
5192 | x_delete_glyphs (n) |
5193 | register int n; | |
ee78dc32 | 5194 | { |
7e6ac5b9 AI |
5195 | struct frame *f; |
5196 | ||
5197 | if (updating_frame) | |
5198 | f = updating_frame; | |
5199 | else | |
5200 | f = SELECTED_FRAME (); | |
5201 | ||
5202 | if (! FRAME_W32_P (f)) | |
5203 | return; | |
5204 | ||
791f420f JR |
5205 | abort (); |
5206 | } | |
ee78dc32 | 5207 | |
ee78dc32 | 5208 | |
791f420f JR |
5209 | /* Erase the current text line from the nominal cursor position |
5210 | (inclusive) to pixel column TO_X (exclusive). The idea is that | |
5211 | everything from TO_X onward is already erased. | |
ee78dc32 | 5212 | |
791f420f JR |
5213 | TO_X is a pixel position relative to updated_area of |
5214 | updated_window. TO_X == -1 means clear to the end of this area. */ | |
11606873 | 5215 | |
791f420f JR |
5216 | static void |
5217 | x_clear_end_of_line (to_x) | |
5218 | int to_x; | |
5219 | { | |
5220 | struct frame *f; | |
5221 | struct window *w = updated_window; | |
5222 | int max_x, min_y, max_y; | |
5223 | int from_x, from_y, to_y; | |
5224 | ||
5225 | xassert (updated_window && updated_row); | |
5226 | f = XFRAME (w->frame); | |
5227 | ||
5228 | if (updated_row->full_width_p) | |
5229 | { | |
5230 | max_x = XFASTINT (w->width) * CANON_X_UNIT (f); | |
5231 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f) | |
5232 | && !w->pseudo_window_p) | |
5233 | max_x += FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
5234 | } | |
5235 | else | |
5236 | max_x = window_box_width (w, updated_area); | |
5237 | max_y = window_text_bottom_y (w); | |
ee78dc32 | 5238 | |
791f420f JR |
5239 | /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end |
5240 | of window. For TO_X > 0, truncate to end of drawing area. */ | |
5241 | if (to_x == 0) | |
5242 | return; | |
5243 | else if (to_x < 0) | |
5244 | to_x = max_x; | |
5245 | else | |
5246 | to_x = min (to_x, max_x); | |
ee78dc32 | 5247 | |
791f420f JR |
5248 | to_y = min (max_y, output_cursor.y + updated_row->height); |
5249 | ||
ee78dc32 | 5250 | /* Notice if the cursor will be cleared by this operation. */ |
791f420f JR |
5251 | if (!updated_row->full_width_p) |
5252 | note_overwritten_text_cursor (w, output_cursor.hpos, -1); | |
ee78dc32 | 5253 | |
791f420f JR |
5254 | from_x = output_cursor.x; |
5255 | ||
5256 | /* Translate to frame coordinates. */ | |
5257 | if (updated_row->full_width_p) | |
5258 | { | |
5259 | from_x = WINDOW_TO_FRAME_PIXEL_X (w, from_x); | |
5260 | to_x = WINDOW_TO_FRAME_PIXEL_X (w, to_x); | |
5261 | } | |
5262 | else | |
5263 | { | |
5264 | from_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, from_x); | |
5265 | to_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, to_x); | |
5266 | } | |
5267 | ||
5268 | min_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
5269 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, max (min_y, output_cursor.y)); | |
5270 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, to_y); | |
5271 | ||
5272 | /* Prevent inadvertently clearing to end of the X window. */ | |
5273 | if (to_x > from_x && to_y > from_y) | |
5274 | { | |
00fe468b | 5275 | HDC hdc; |
791f420f | 5276 | BLOCK_INPUT; |
00fe468b JR |
5277 | hdc = get_frame_dc (f); |
5278 | ||
5279 | w32_clear_area (f, hdc, from_x, from_y, to_x - from_x, to_y - from_y); | |
5280 | release_frame_dc (f, hdc); | |
791f420f JR |
5281 | UNBLOCK_INPUT; |
5282 | } | |
ee78dc32 GV |
5283 | } |
5284 | ||
791f420f JR |
5285 | |
5286 | /* Clear entire frame. If updating_frame is non-null, clear that | |
5287 | frame. Otherwise clear the selected frame. */ | |
5288 | ||
96214669 | 5289 | static void |
791f420f | 5290 | x_clear_frame () |
ee78dc32 | 5291 | { |
791f420f | 5292 | struct frame *f; |
ee78dc32 | 5293 | |
791f420f JR |
5294 | if (updating_frame) |
5295 | f = updating_frame; | |
5296 | else | |
5297 | f = SELECTED_FRAME (); | |
ee78dc32 | 5298 | |
7e6ac5b9 AI |
5299 | if (! FRAME_W32_P (f)) |
5300 | return; | |
5301 | ||
791f420f JR |
5302 | /* Clearing the frame will erase any cursor, so mark them all as no |
5303 | longer visible. */ | |
5304 | mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
5305 | output_cursor.hpos = output_cursor.vpos = 0; | |
5306 | output_cursor.x = -1; | |
ee78dc32 | 5307 | |
791f420f JR |
5308 | /* We don't set the output cursor here because there will always |
5309 | follow an explicit cursor_to. */ | |
ee78dc32 GV |
5310 | BLOCK_INPUT; |
5311 | ||
fbd6baed | 5312 | w32_clear_window (f); |
ee78dc32 GV |
5313 | |
5314 | /* We have to clear the scroll bars, too. If we have changed | |
5315 | colors or something like that, then they should be notified. */ | |
5316 | x_scroll_bar_clear (f); | |
5317 | ||
5318 | UNBLOCK_INPUT; | |
5319 | } | |
791f420f | 5320 | |
ee78dc32 GV |
5321 | \f |
5322 | /* Make audible bell. */ | |
5323 | ||
96214669 GV |
5324 | static void |
5325 | w32_ring_bell (void) | |
ee78dc32 | 5326 | { |
7e6ac5b9 AI |
5327 | struct frame *f; |
5328 | ||
5329 | f = SELECTED_FRAME (); | |
5330 | ||
ee78dc32 GV |
5331 | BLOCK_INPUT; |
5332 | ||
0f32f023 | 5333 | if (FRAME_W32_P (f) && visible_bell) |
8331e676 GV |
5334 | { |
5335 | int i; | |
791f420f | 5336 | HWND hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); |
8331e676 GV |
5337 | |
5338 | for (i = 0; i < 5; i++) | |
5339 | { | |
5340 | FlashWindow (hwnd, TRUE); | |
5341 | Sleep (10); | |
5342 | } | |
5343 | FlashWindow (hwnd, FALSE); | |
5344 | } | |
ee78dc32 | 5345 | else |
fbd6baed | 5346 | w32_sys_ring_bell (); |
ee78dc32 GV |
5347 | |
5348 | UNBLOCK_INPUT; | |
ee78dc32 | 5349 | } |
791f420f | 5350 | |
ee78dc32 | 5351 | \f |
791f420f JR |
5352 | /* Specify how many text lines, from the top of the window, |
5353 | should be affected by insert-lines and delete-lines operations. | |
5354 | This, and those operations, are used only within an update | |
5355 | that is bounded by calls to x_update_begin and x_update_end. */ | |
ee78dc32 | 5356 | |
96214669 | 5357 | static void |
791f420f JR |
5358 | w32_set_terminal_window (n) |
5359 | register int n; | |
ee78dc32 | 5360 | { |
791f420f | 5361 | /* This function intentionally left blank. */ |
ee78dc32 | 5362 | } |
791f420f JR |
5363 | \f |
5364 | ||
5365 | \f | |
5366 | /*********************************************************************** | |
5367 | Line Dance | |
5368 | ***********************************************************************/ | |
5369 | ||
5370 | /* Perform an insert-lines or delete-lines operation, inserting N | |
5371 | lines or deleting -N lines at vertical position VPOS. */ | |
ee78dc32 | 5372 | |
96214669 | 5373 | static void |
791f420f JR |
5374 | x_ins_del_lines (vpos, n) |
5375 | int vpos, n; | |
ee78dc32 | 5376 | { |
7e6ac5b9 AI |
5377 | struct frame *f; |
5378 | ||
5379 | if (updating_frame) | |
5380 | f = updating_frame; | |
5381 | else | |
5382 | f = SELECTED_FRAME (); | |
5383 | ||
5384 | if (! FRAME_W32_P (f)) | |
5385 | return; | |
5386 | ||
ee78dc32 GV |
5387 | abort (); |
5388 | } | |
791f420f JR |
5389 | |
5390 | ||
5391 | /* Scroll part of the display as described by RUN. */ | |
5392 | ||
5393 | static void | |
5394 | x_scroll_run (w, run) | |
5395 | struct window *w; | |
5396 | struct run *run; | |
5397 | { | |
5398 | struct frame *f = XFRAME (w->frame); | |
5399 | int x, y, width, height, from_y, to_y, bottom_y; | |
5400 | HDC hdc = get_frame_dc (f); | |
5401 | ||
5402 | /* Get frame-relative bounding box of the text display area of W, | |
5403 | without mode lines. Include in this box the flags areas to the | |
5404 | left and right of W. */ | |
5405 | window_box (w, -1, &x, &y, &width, &height); | |
5406 | width += FRAME_X_FLAGS_AREA_WIDTH (f); | |
5407 | x -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); | |
5408 | ||
5409 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y); | |
5410 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y); | |
5411 | bottom_y = y + height; | |
5412 | ||
5413 | if (to_y < from_y) | |
5414 | { | |
5415 | /* Scrolling up. Make sure we don't copy part of the mode | |
5416 | line at the bottom. */ | |
5417 | if (from_y + run->height > bottom_y) | |
5418 | height = bottom_y - from_y; | |
5419 | else | |
5420 | height = run->height; | |
5421 | } | |
5422 | else | |
5423 | { | |
5424 | /* Scolling down. Make sure we don't copy over the mode line. | |
5425 | at the bottom. */ | |
5426 | if (to_y + run->height > bottom_y) | |
5427 | height = bottom_y - to_y; | |
5428 | else | |
5429 | height = run->height; | |
5430 | } | |
5431 | ||
5432 | BLOCK_INPUT; | |
5433 | ||
5434 | /* Cursor off. Will be switched on again in x_update_window_end. */ | |
5435 | updated_window = w; | |
5436 | x_clear_cursor (w); | |
5437 | ||
5438 | BitBlt (hdc, x, to_y, width, height, hdc, x, from_y, SRCCOPY); | |
5439 | ||
5440 | UNBLOCK_INPUT; | |
5441 | release_frame_dc (f, hdc); | |
5442 | } | |
5443 | ||
9ef2e2cf | 5444 | |
ee78dc32 | 5445 | \f |
791f420f JR |
5446 | /*********************************************************************** |
5447 | Exposure Events | |
5448 | ***********************************************************************/ | |
5449 | ||
5450 | /* Redisplay an exposed area of frame F. X and Y are the upper-left | |
5451 | corner of the exposed rectangle. W and H are width and height of | |
5452 | the exposed area. All are pixel values. W or H zero means redraw | |
5453 | the entire frame. */ | |
ee78dc32 | 5454 | |
96214669 | 5455 | static void |
791f420f JR |
5456 | expose_frame (f, x, y, w, h) |
5457 | struct frame *f; | |
5458 | int x, y, w, h; | |
ee78dc32 | 5459 | { |
791f420f | 5460 | RECT r; |
9f5a911b | 5461 | int mouse_face_overwritten_p = 0; |
791f420f JR |
5462 | |
5463 | TRACE ((stderr, "expose_frame ")); | |
5464 | ||
5465 | /* No need to redraw if frame will be redrawn soon. */ | |
5466 | if (FRAME_GARBAGED_P (f)) | |
5467 | { | |
5468 | TRACE ((stderr, " garbaged\n")); | |
5469 | return; | |
5470 | } | |
5471 | ||
5472 | /* If basic faces haven't been realized yet, there is no point in | |
5473 | trying to redraw anything. This can happen when we get an expose | |
5474 | event while Emacs is starting, e.g. by moving another window. */ | |
5475 | if (FRAME_FACE_CACHE (f) == NULL | |
5476 | || FRAME_FACE_CACHE (f)->used < BASIC_FACE_ID_SENTINEL) | |
5477 | { | |
5478 | TRACE ((stderr, " no faces\n")); | |
5479 | return; | |
5480 | } | |
5481 | ||
5482 | if (w == 0 || h == 0) | |
5483 | { | |
5484 | r.left = r.top = 0; | |
5485 | r.right = CANON_X_UNIT (f) * f->width; | |
5486 | r.bottom = CANON_Y_UNIT (f) * f->height; | |
5487 | } | |
5488 | else | |
5489 | { | |
5490 | r.left = x; | |
5491 | r.top = y; | |
5492 | r.right = x + w; | |
5493 | r.bottom = y + h; | |
5494 | } | |
5495 | ||
5496 | TRACE ((stderr, "(%d, %d, %d, %d)\n", r.left, r.top, r.right, r.bottom)); | |
9f5a911b | 5497 | mouse_face_overwritten_p = expose_window_tree (XWINDOW (f->root_window), &r); |
791f420f JR |
5498 | |
5499 | if (WINDOWP (f->tool_bar_window)) | |
9f5a911b JR |
5500 | mouse_face_overwritten_p |
5501 | |= expose_window (XWINDOW (f->tool_bar_window), &r); | |
5502 | ||
5503 | /* Some window managers support a focus-follows-mouse style with | |
5504 | delayed raising of frames. Imagine a partially obscured frame, | |
5505 | and moving the mouse into partially obscured mouse-face on that | |
5506 | frame. The visible part of the mouse-face will be highlighted, | |
5507 | then the WM raises the obscured frame. With at least one WM, KDE | |
5508 | 2.1, Emacs is not getting any event for the raising of the frame | |
5509 | (even tried with SubstructureRedirectMask), only Expose events. | |
5510 | These expose events will draw text normally, i.e. not | |
5511 | highlighted. Which means we must redo the highlight here. | |
5512 | Subsume it under ``we love X''. --gerd 2001-08-15 */ | |
5513 | /* Included in Windows version because Windows most likely does not | |
5514 | do the right thing if any third party tool offers | |
5515 | focus-follows-mouse with delayed raise. --jason 2001-10-12 */ | |
5516 | if (mouse_face_overwritten_p && !FRAME_GARBAGED_P (f)) | |
791f420f | 5517 | { |
9f5a911b JR |
5518 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
5519 | if (f == dpyinfo->mouse_face_mouse_frame) | |
5520 | { | |
5521 | int x = dpyinfo->mouse_face_mouse_x; | |
5522 | int y = dpyinfo->mouse_face_mouse_y; | |
5523 | clear_mouse_face (dpyinfo); | |
5524 | note_mouse_highlight (f, x, y); | |
5525 | } | |
791f420f JR |
5526 | } |
5527 | } | |
5528 | ||
5529 | ||
5530 | /* Redraw (parts) of all windows in the window tree rooted at W that | |
5531 | intersect R. R contains frame pixel coordinates. */ | |
5532 | ||
9f5a911b | 5533 | static int |
791f420f JR |
5534 | expose_window_tree (w, r) |
5535 | struct window *w; | |
5536 | RECT *r; | |
5537 | { | |
9f5a911b JR |
5538 | struct frame *f = XFRAME (w->frame); |
5539 | int mouse_face_overwritten_p = 0; | |
5540 | ||
5541 | while (w && !FRAME_GARBAGED_P (f)) | |
791f420f JR |
5542 | { |
5543 | if (!NILP (w->hchild)) | |
9f5a911b JR |
5544 | mouse_face_overwritten_p |
5545 | |= expose_window_tree (XWINDOW (w->hchild), r); | |
791f420f | 5546 | else if (!NILP (w->vchild)) |
9f5a911b JR |
5547 | mouse_face_overwritten_p |
5548 | |= expose_window_tree (XWINDOW (w->vchild), r); | |
791f420f | 5549 | else |
9f5a911b | 5550 | mouse_face_overwritten_p |= expose_window (w, r); |
791f420f | 5551 | |
9f5a911b | 5552 | w = NILP (w->next) ? NULL : XWINDOW (w->next); |
791f420f | 5553 | } |
9f5a911b JR |
5554 | |
5555 | return mouse_face_overwritten_p; | |
791f420f JR |
5556 | } |
5557 | ||
5558 | ||
5559 | /* Redraw the part of glyph row area AREA of glyph row ROW on window W | |
5560 | which intersects rectangle R. R is in window-relative coordinates. */ | |
5561 | ||
5562 | static void | |
5563 | expose_area (w, row, r, area) | |
5564 | struct window *w; | |
5565 | struct glyph_row *row; | |
5566 | RECT *r; | |
5567 | enum glyph_row_area area; | |
5568 | { | |
791f420f JR |
5569 | struct glyph *first = row->glyphs[area]; |
5570 | struct glyph *end = row->glyphs[area] + row->used[area]; | |
5571 | struct glyph *last; | |
2df85294 | 5572 | int first_x, start_x, x; |
791f420f | 5573 | |
791f420f JR |
5574 | if (area == TEXT_AREA && row->fill_line_p) |
5575 | /* If row extends face to end of line write the whole line. */ | |
c2cc16fa | 5576 | x_draw_glyphs (w, 0, row, area, |
791f420f | 5577 | 0, row->used[area], |
e617a35b | 5578 | DRAW_NORMAL_TEXT, |
791f420f JR |
5579 | NULL, NULL, 0); |
5580 | else | |
5581 | { | |
2df85294 JR |
5582 | /* Set START_X to the window-relative start position for drawing glyphs of |
5583 | AREA. The first glyph of the text area can be partially visible. | |
5584 | The first glyphs of other areas cannot. */ | |
5585 | if (area == LEFT_MARGIN_AREA) | |
5586 | start_x = 0; | |
5587 | else if (area == TEXT_AREA) | |
5588 | start_x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5589 | else | |
5590 | start_x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5591 | + window_box_width (w, TEXT_AREA)); | |
5592 | x = start_x; | |
5593 | ||
791f420f JR |
5594 | /* Find the first glyph that must be redrawn. */ |
5595 | while (first < end | |
5596 | && x + first->pixel_width < r->left) | |
5597 | { | |
5598 | x += first->pixel_width; | |
5599 | ++first; | |
5600 | } | |
5601 | ||
5602 | /* Find the last one. */ | |
5603 | last = first; | |
5604 | first_x = x; | |
5605 | while (last < end | |
5606 | && x < r->right) | |
5607 | { | |
5608 | x += last->pixel_width; | |
5609 | ++last; | |
5610 | } | |
2df85294 | 5611 | |
791f420f JR |
5612 | /* Repaint. */ |
5613 | if (last > first) | |
f201d732 | 5614 | x_draw_glyphs (w, first_x - start_x, row, area, |
791f420f JR |
5615 | first - row->glyphs[area], |
5616 | last - row->glyphs[area], | |
e617a35b | 5617 | DRAW_NORMAL_TEXT, |
791f420f JR |
5618 | NULL, NULL, 0); |
5619 | } | |
5620 | } | |
5621 | ||
5622 | ||
5623 | /* Redraw the parts of the glyph row ROW on window W intersecting | |
9f5a911b JR |
5624 | rectangle R. R is in window-relative coordinates. Value is |
5625 | non-zero if mouse face was overwritten. */ | |
ee78dc32 | 5626 | |
9f5a911b | 5627 | static int |
791f420f JR |
5628 | expose_line (w, row, r) |
5629 | struct window *w; | |
5630 | struct glyph_row *row; | |
5631 | RECT *r; | |
5632 | { | |
5633 | xassert (row->enabled_p); | |
5634 | ||
5635 | if (row->mode_line_p || w->pseudo_window_p) | |
5636 | x_draw_glyphs (w, 0, row, TEXT_AREA, 0, row->used[TEXT_AREA], | |
e617a35b | 5637 | DRAW_NORMAL_TEXT, NULL, NULL, 0); |
ee78dc32 | 5638 | else |
791f420f JR |
5639 | { |
5640 | if (row->used[LEFT_MARGIN_AREA]) | |
5641 | expose_area (w, row, r, LEFT_MARGIN_AREA); | |
5642 | if (row->used[TEXT_AREA]) | |
5643 | expose_area (w, row, r, TEXT_AREA); | |
5644 | if (row->used[RIGHT_MARGIN_AREA]) | |
5645 | expose_area (w, row, r, RIGHT_MARGIN_AREA); | |
5646 | x_draw_row_bitmaps (w, row); | |
5647 | } | |
9f5a911b JR |
5648 | |
5649 | return row->mouse_face_p; | |
ee78dc32 | 5650 | } |
ee78dc32 | 5651 | |
ee78dc32 | 5652 | |
791f420f | 5653 | /* Return non-zero if W's cursor intersects rectangle R. */ |
96214669 | 5654 | |
791f420f JR |
5655 | static int |
5656 | x_phys_cursor_in_rect_p (w, r) | |
5657 | struct window *w; | |
5658 | RECT *r; | |
ee78dc32 | 5659 | { |
791f420f JR |
5660 | RECT cr, result; |
5661 | struct glyph *cursor_glyph; | |
ee78dc32 | 5662 | |
791f420f JR |
5663 | cursor_glyph = get_phys_cursor_glyph (w); |
5664 | if (cursor_glyph) | |
ee78dc32 | 5665 | { |
791f420f JR |
5666 | cr.left = w->phys_cursor.x; |
5667 | cr.top = w->phys_cursor.y; | |
5668 | cr.right = cr.left + cursor_glyph->pixel_width; | |
5669 | cr.bottom = cr.top + w->phys_cursor_height; | |
158cba56 | 5670 | return IntersectRect (&result, &cr, r); |
ee78dc32 GV |
5671 | } |
5672 | else | |
791f420f | 5673 | return 0; |
ee78dc32 GV |
5674 | } |
5675 | ||
791f420f | 5676 | |
9f5a911b JR |
5677 | /* Redraw the part of window W intersection rectagle FR. Pixel |
5678 | coordinates in FR are frame relative. Call this function with | |
5679 | input blocked. Value is non-zero if the exposure overwrites | |
5680 | mouse-face. */ | |
791f420f | 5681 | |
9f5a911b JR |
5682 | static int |
5683 | expose_window (w, fr) | |
791f420f | 5684 | struct window *w; |
9f5a911b | 5685 | RECT *fr; |
ee78dc32 | 5686 | { |
9f5a911b JR |
5687 | struct frame *f = XFRAME (w->frame); |
5688 | RECT wr, r; | |
5689 | int mouse_face_overwritten_p = 0; | |
791f420f JR |
5690 | |
5691 | /* If window is not yet fully initialized, do nothing. This can | |
5692 | happen when toolkit scroll bars are used and a window is split. | |
5693 | Reconfiguring the scroll bar will generate an expose for a newly | |
5694 | created window. */ | |
9f5a911b JR |
5695 | if (w->current_matrix == NULL) |
5696 | return 0; | |
ee78dc32 | 5697 | |
9f5a911b JR |
5698 | /* When we're currently updating the window, display and current |
5699 | matrix usually don't agree. Arrange for a thorough display | |
5700 | later. */ | |
5701 | if (w == updated_window) | |
791f420f | 5702 | { |
9f5a911b JR |
5703 | SET_FRAME_GARBAGED (f); |
5704 | return 0; | |
791f420f | 5705 | } |
791f420f | 5706 | |
9f5a911b JR |
5707 | /* Frame-relative pixel rectangle of W. */ |
5708 | wr.left = XFASTINT (w->left) * CANON_X_UNIT (f); | |
5709 | wr.top = XFASTINT (w->top) * CANON_Y_UNIT (f); | |
5710 | wr.right = wr.left + XFASTINT (w->width) * CANON_X_UNIT (f); | |
5711 | wr.bottom = wr.top + XFASTINT (w->height) * CANON_Y_UNIT (f); | |
5712 | ||
5713 | if (IntersectRect(&r, fr, &wr)) | |
791f420f | 5714 | { |
9f5a911b JR |
5715 | int yb = window_text_bottom_y (w); |
5716 | struct glyph_row *row; | |
5717 | int cursor_cleared_p; | |
ee78dc32 | 5718 | |
9f5a911b JR |
5719 | TRACE ((stderr, "expose_window (%d, %d, %d, %d)\n", |
5720 | r.left, r.top, r.right, r.bottom)); | |
689004fa | 5721 | |
9f5a911b JR |
5722 | /* Convert to window coordinates. */ |
5723 | r.left = FRAME_TO_WINDOW_PIXEL_X (w, r.left); | |
5724 | r.right = FRAME_TO_WINDOW_PIXEL_X (w, r.right); | |
5725 | r.top = FRAME_TO_WINDOW_PIXEL_Y (w, r.top); | |
5726 | r.bottom = FRAME_TO_WINDOW_PIXEL_Y (w, r.bottom); | |
5727 | ||
5728 | /* Turn off the cursor. */ | |
5729 | if (!w->pseudo_window_p | |
5730 | && x_phys_cursor_in_rect_p (w, &r)) | |
5731 | { | |
5732 | x_clear_cursor (w); | |
5733 | cursor_cleared_p = 1; | |
5734 | } | |
5735 | else | |
5736 | cursor_cleared_p = 0; | |
5737 | ||
5738 | /* Find the first row intersecting the rectangle R. */ | |
5739 | for (row = w->current_matrix->rows; | |
5740 | row->enabled_p; | |
5741 | ++row) | |
5742 | { | |
5743 | int y0 = row->y; | |
5744 | int y1 = MATRIX_ROW_BOTTOM_Y (row); | |
5745 | ||
5746 | if ((y0 >= r.top && y0 < r.bottom) | |
5747 | || (y1 > r.top && y1 < r.bottom) | |
5748 | || (r.top >= y0 && r.top < y1) | |
5749 | || (r.bottom > y0 && r.bottom < y1)) | |
5750 | { | |
5751 | if (expose_line (w, row, &r)) | |
5752 | mouse_face_overwritten_p = 1; | |
5753 | } | |
5754 | ||
5755 | if (y1 >= yb) | |
5756 | break; | |
5757 | } | |
5758 | ||
5759 | /* Display the mode line if there is one. */ | |
5760 | if (WINDOW_WANTS_MODELINE_P (w) | |
5761 | && (row = MATRIX_MODE_LINE_ROW (w->current_matrix), | |
5762 | row->enabled_p) | |
5763 | && row->y < r.bottom) | |
5764 | { | |
5765 | if (expose_line (w, row, &r)) | |
5766 | mouse_face_overwritten_p = 1; | |
5767 | } | |
5768 | ||
5769 | if (!w->pseudo_window_p) | |
5770 | { | |
5771 | /* Draw border between windows. */ | |
5772 | x_draw_vertical_border (w); | |
5773 | ||
5774 | /* Turn the cursor on again. */ | |
5775 | if (cursor_cleared_p) | |
5776 | x_update_window_cursor (w, 1); | |
5777 | } | |
791f420f | 5778 | } |
9f5a911b JR |
5779 | |
5780 | return mouse_face_overwritten_p; | |
ee78dc32 | 5781 | } |
ee78dc32 | 5782 | |
ee78dc32 GV |
5783 | \f |
5784 | static void | |
5785 | frame_highlight (f) | |
5786 | struct frame *f; | |
5787 | { | |
791f420f | 5788 | x_update_cursor (f, 1); |
ee78dc32 GV |
5789 | } |
5790 | ||
5791 | static void | |
5792 | frame_unhighlight (f) | |
5793 | struct frame *f; | |
5794 | { | |
791f420f | 5795 | x_update_cursor (f, 1); |
ee78dc32 GV |
5796 | } |
5797 | ||
ee78dc32 GV |
5798 | /* The focus has changed. Update the frames as necessary to reflect |
5799 | the new situation. Note that we can't change the selected frame | |
5800 | here, because the Lisp code we are interrupting might become confused. | |
5801 | Each event gets marked with the frame in which it occurred, so the | |
5802 | Lisp code can tell when the switch took place by examining the events. */ | |
5803 | ||
9ef2e2cf | 5804 | static void |
ee78dc32 | 5805 | x_new_focus_frame (dpyinfo, frame) |
fbd6baed | 5806 | struct w32_display_info *dpyinfo; |
ee78dc32 GV |
5807 | struct frame *frame; |
5808 | { | |
fbd6baed | 5809 | struct frame *old_focus = dpyinfo->w32_focus_frame; |
ee78dc32 | 5810 | |
fbd6baed | 5811 | if (frame != dpyinfo->w32_focus_frame) |
ee78dc32 GV |
5812 | { |
5813 | /* Set this before calling other routines, so that they see | |
fbd6baed GV |
5814 | the correct value of w32_focus_frame. */ |
5815 | dpyinfo->w32_focus_frame = frame; | |
ee78dc32 GV |
5816 | |
5817 | if (old_focus && old_focus->auto_lower) | |
5818 | x_lower_frame (old_focus); | |
5819 | ||
fbd6baed GV |
5820 | if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise) |
5821 | pending_autoraise_frame = dpyinfo->w32_focus_frame; | |
ee78dc32 GV |
5822 | else |
5823 | pending_autoraise_frame = 0; | |
5824 | } | |
5825 | ||
5826 | x_frame_rehighlight (dpyinfo); | |
5827 | } | |
5828 | ||
5829 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ | |
5830 | ||
5831 | void | |
5832 | x_mouse_leave (dpyinfo) | |
fbd6baed | 5833 | struct w32_display_info *dpyinfo; |
ee78dc32 | 5834 | { |
fbd6baed | 5835 | x_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame); |
ee78dc32 GV |
5836 | } |
5837 | ||
5838 | /* The focus has changed, or we have redirected a frame's focus to | |
5839 | another frame (this happens when a frame uses a surrogate | |
9ef2e2cf | 5840 | mini-buffer frame). Shift the highlight as appropriate. |
ee78dc32 GV |
5841 | |
5842 | The FRAME argument doesn't necessarily have anything to do with which | |
9ef2e2cf JR |
5843 | frame is being highlighted or un-highlighted; we only use it to find |
5844 | the appropriate X display info. */ | |
5845 | ||
ee78dc32 | 5846 | static void |
fbd6baed | 5847 | w32_frame_rehighlight (frame) |
ee78dc32 GV |
5848 | struct frame *frame; |
5849 | { | |
7e6ac5b9 AI |
5850 | if (! FRAME_W32_P (frame)) |
5851 | return; | |
fbd6baed | 5852 | x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame)); |
ee78dc32 GV |
5853 | } |
5854 | ||
5855 | static void | |
5856 | x_frame_rehighlight (dpyinfo) | |
fbd6baed | 5857 | struct w32_display_info *dpyinfo; |
ee78dc32 | 5858 | { |
fbd6baed | 5859 | struct frame *old_highlight = dpyinfo->w32_highlight_frame; |
ee78dc32 | 5860 | |
fbd6baed | 5861 | if (dpyinfo->w32_focus_frame) |
ee78dc32 | 5862 | { |
fbd6baed GV |
5863 | dpyinfo->w32_highlight_frame |
5864 | = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame))) | |
5865 | ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame)) | |
5866 | : dpyinfo->w32_focus_frame); | |
5867 | if (! FRAME_LIVE_P (dpyinfo->w32_highlight_frame)) | |
ee78dc32 | 5868 | { |
fbd6baed GV |
5869 | FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame) = Qnil; |
5870 | dpyinfo->w32_highlight_frame = dpyinfo->w32_focus_frame; | |
ee78dc32 GV |
5871 | } |
5872 | } | |
5873 | else | |
fbd6baed | 5874 | dpyinfo->w32_highlight_frame = 0; |
ee78dc32 | 5875 | |
fbd6baed | 5876 | if (dpyinfo->w32_highlight_frame != old_highlight) |
ee78dc32 GV |
5877 | { |
5878 | if (old_highlight) | |
5879 | frame_unhighlight (old_highlight); | |
fbd6baed GV |
5880 | if (dpyinfo->w32_highlight_frame) |
5881 | frame_highlight (dpyinfo->w32_highlight_frame); | |
ee78dc32 GV |
5882 | } |
5883 | } | |
5884 | \f | |
5885 | /* Keyboard processing - modifier keys, etc. */ | |
5886 | ||
5887 | /* Convert a keysym to its name. */ | |
5888 | ||
5889 | char * | |
5890 | x_get_keysym_name (keysym) | |
5891 | int keysym; | |
5892 | { | |
5893 | /* Make static so we can always return it */ | |
5894 | static char value[100]; | |
5895 | ||
5896 | BLOCK_INPUT; | |
9127e20e | 5897 | GetKeyNameText (keysym, value, 100); |
ee78dc32 GV |
5898 | UNBLOCK_INPUT; |
5899 | ||
5900 | return value; | |
5901 | } | |
9ef2e2cf JR |
5902 | |
5903 | ||
ee78dc32 GV |
5904 | \f |
5905 | /* Mouse clicks and mouse movement. Rah. */ | |
5906 | ||
9ef2e2cf JR |
5907 | /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph |
5908 | co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the | |
5909 | glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do | |
5910 | not force the value into range. */ | |
ee78dc32 GV |
5911 | |
5912 | void | |
5913 | pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip) | |
5914 | FRAME_PTR f; | |
5915 | register int pix_x, pix_y; | |
5916 | register int *x, *y; | |
5917 | RECT *bounds; | |
5918 | int noclip; | |
5919 | { | |
52cf03a1 GV |
5920 | /* Support tty mode: if Vwindow_system is nil, behave correctly. */ |
5921 | if (NILP (Vwindow_system)) | |
5922 | { | |
5923 | *x = pix_x; | |
5924 | *y = pix_y; | |
5925 | return; | |
5926 | } | |
5927 | ||
ee78dc32 GV |
5928 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down |
5929 | even for negative values. */ | |
5930 | if (pix_x < 0) | |
9127e20e | 5931 | pix_x -= FONT_WIDTH (FRAME_FONT (f)) - 1; |
ee78dc32 | 5932 | if (pix_y < 0) |
fbd6baed | 5933 | pix_y -= (f)->output_data.w32->line_height - 1; |
ee78dc32 GV |
5934 | |
5935 | pix_x = PIXEL_TO_CHAR_COL (f, pix_x); | |
5936 | pix_y = PIXEL_TO_CHAR_ROW (f, pix_y); | |
5937 | ||
5938 | if (bounds) | |
5939 | { | |
5940 | bounds->left = CHAR_TO_PIXEL_COL (f, pix_x); | |
5941 | bounds->top = CHAR_TO_PIXEL_ROW (f, pix_y); | |
9127e20e | 5942 | bounds->right = bounds->left + FONT_WIDTH (FRAME_FONT (f)) - 1; |
fbd6baed | 5943 | bounds->bottom = bounds->top + f->output_data.w32->line_height - 1; |
ee78dc32 GV |
5944 | } |
5945 | ||
5946 | if (!noclip) | |
5947 | { | |
5948 | if (pix_x < 0) | |
5949 | pix_x = 0; | |
ec48c3a7 JR |
5950 | else if (pix_x > FRAME_WINDOW_WIDTH (f)) |
5951 | pix_x = FRAME_WINDOW_WIDTH (f); | |
ee78dc32 GV |
5952 | |
5953 | if (pix_y < 0) | |
5954 | pix_y = 0; | |
5955 | else if (pix_y > f->height) | |
5956 | pix_y = f->height; | |
5957 | } | |
5958 | ||
5959 | *x = pix_x; | |
5960 | *y = pix_y; | |
5961 | } | |
5962 | ||
791f420f JR |
5963 | |
5964 | /* Given HPOS/VPOS in the current matrix of W, return corresponding | |
5965 | frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we | |
5966 | can't tell the positions because W's display is not up to date, | |
5967 | return 0. */ | |
5968 | ||
5969 | int | |
5970 | glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y) | |
5971 | struct window *w; | |
5972 | int hpos, vpos; | |
5973 | int *frame_x, *frame_y; | |
ee78dc32 | 5974 | { |
791f420f JR |
5975 | int success_p; |
5976 | ||
5977 | xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w); | |
5978 | xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h); | |
5979 | ||
5980 | if (display_completed) | |
52cf03a1 | 5981 | { |
791f420f JR |
5982 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos); |
5983 | struct glyph *glyph = row->glyphs[TEXT_AREA]; | |
5984 | struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]); | |
5985 | ||
5986 | *frame_y = row->y; | |
5987 | *frame_x = row->x; | |
5988 | while (glyph < end) | |
5989 | { | |
5990 | *frame_x += glyph->pixel_width; | |
5991 | ++glyph; | |
5992 | } | |
5993 | ||
5994 | success_p = 1; | |
5995 | } | |
5996 | else | |
5997 | { | |
5998 | *frame_y = *frame_x = 0; | |
5999 | success_p = 0; | |
52cf03a1 GV |
6000 | } |
6001 | ||
791f420f JR |
6002 | *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y); |
6003 | *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x); | |
6004 | return success_p; | |
ee78dc32 GV |
6005 | } |
6006 | ||
6007 | BOOL | |
6008 | parse_button (message, pbutton, pup) | |
6009 | int message; | |
6010 | int * pbutton; | |
6011 | int * pup; | |
6012 | { | |
6013 | int button = 0; | |
6014 | int up = 0; | |
6015 | ||
6016 | switch (message) | |
6017 | { | |
6018 | case WM_LBUTTONDOWN: | |
6019 | button = 0; | |
6020 | up = 0; | |
6021 | break; | |
6022 | case WM_LBUTTONUP: | |
6023 | button = 0; | |
6024 | up = 1; | |
6025 | break; | |
6026 | case WM_MBUTTONDOWN: | |
fbd6baed | 6027 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
6028 | button = 1; |
6029 | else | |
6030 | button = 2; | |
ee78dc32 GV |
6031 | up = 0; |
6032 | break; | |
6033 | case WM_MBUTTONUP: | |
fbd6baed | 6034 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
6035 | button = 1; |
6036 | else | |
6037 | button = 2; | |
ee78dc32 GV |
6038 | up = 1; |
6039 | break; | |
6040 | case WM_RBUTTONDOWN: | |
fbd6baed | 6041 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
6042 | button = 2; |
6043 | else | |
6044 | button = 1; | |
ee78dc32 GV |
6045 | up = 0; |
6046 | break; | |
6047 | case WM_RBUTTONUP: | |
fbd6baed | 6048 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
6049 | button = 2; |
6050 | else | |
6051 | button = 1; | |
ee78dc32 GV |
6052 | up = 1; |
6053 | break; | |
6054 | default: | |
6055 | return (FALSE); | |
6056 | } | |
6057 | ||
6058 | if (pup) *pup = up; | |
6059 | if (pbutton) *pbutton = button; | |
6060 | ||
6061 | return (TRUE); | |
6062 | } | |
6063 | ||
6064 | ||
6065 | /* Prepare a mouse-event in *RESULT for placement in the input queue. | |
6066 | ||
6067 | If the event is a button press, then note that we have grabbed | |
6068 | the mouse. */ | |
6069 | ||
ec48c3a7 | 6070 | static Lisp_Object |
ee78dc32 GV |
6071 | construct_mouse_click (result, msg, f) |
6072 | struct input_event *result; | |
fbd6baed | 6073 | W32Msg *msg; |
ee78dc32 GV |
6074 | struct frame *f; |
6075 | { | |
6076 | int button; | |
6077 | int up; | |
6078 | ||
6079 | parse_button (msg->msg.message, &button, &up); | |
6080 | ||
6081 | /* Make the event type no_event; we'll change that when we decide | |
6082 | otherwise. */ | |
6083 | result->kind = mouse_click; | |
6084 | result->code = button; | |
6085 | result->timestamp = msg->msg.time; | |
6086 | result->modifiers = (msg->dwModifiers | |
6087 | | (up | |
6088 | ? up_modifier | |
6089 | : down_modifier)); | |
6090 | ||
ec48c3a7 JR |
6091 | XSETINT (result->x, LOWORD (msg->msg.lParam)); |
6092 | XSETINT (result->y, HIWORD (msg->msg.lParam)); | |
6093 | XSETFRAME (result->frame_or_window, f); | |
6094 | result->arg = Qnil; | |
6095 | return Qnil; | |
ee78dc32 GV |
6096 | } |
6097 | ||
ec48c3a7 | 6098 | static Lisp_Object |
689004fa GV |
6099 | construct_mouse_wheel (result, msg, f) |
6100 | struct input_event *result; | |
6101 | W32Msg *msg; | |
6102 | struct frame *f; | |
6103 | { | |
6104 | POINT p; | |
6105 | result->kind = mouse_wheel; | |
6106 | result->code = (short) HIWORD (msg->msg.wParam); | |
6107 | result->timestamp = msg->msg.time; | |
6108 | result->modifiers = msg->dwModifiers; | |
6109 | p.x = LOWORD (msg->msg.lParam); | |
6110 | p.y = HIWORD (msg->msg.lParam); | |
9127e20e | 6111 | ScreenToClient (msg->msg.hwnd, &p); |
689004fa GV |
6112 | XSETINT (result->x, p.x); |
6113 | XSETINT (result->y, p.y); | |
6114 | XSETFRAME (result->frame_or_window, f); | |
7e889510 | 6115 | result->arg = Qnil; |
ec48c3a7 | 6116 | return Qnil; |
689004fa GV |
6117 | } |
6118 | ||
ec48c3a7 | 6119 | static Lisp_Object |
12857dfd RS |
6120 | construct_drag_n_drop (result, msg, f) |
6121 | struct input_event *result; | |
6122 | W32Msg *msg; | |
6123 | struct frame *f; | |
6124 | { | |
6125 | Lisp_Object files; | |
6126 | Lisp_Object frame; | |
6127 | HDROP hdrop; | |
6128 | POINT p; | |
6129 | WORD num_files; | |
6130 | char *name; | |
6131 | int i, len; | |
6132 | ||
6133 | result->kind = drag_n_drop; | |
6134 | result->code = 0; | |
6135 | result->timestamp = msg->msg.time; | |
6136 | result->modifiers = msg->dwModifiers; | |
6137 | ||
fb9cc9cc AI |
6138 | hdrop = (HDROP) msg->msg.wParam; |
6139 | DragQueryPoint (hdrop, &p); | |
6140 | ||
e12ca9c2 | 6141 | #if 0 |
12857dfd RS |
6142 | p.x = LOWORD (msg->msg.lParam); |
6143 | p.y = HIWORD (msg->msg.lParam); | |
6144 | ScreenToClient (msg->msg.hwnd, &p); | |
e12ca9c2 AI |
6145 | #endif |
6146 | ||
12857dfd RS |
6147 | XSETINT (result->x, p.x); |
6148 | XSETINT (result->y, p.y); | |
6149 | ||
12857dfd RS |
6150 | num_files = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); |
6151 | files = Qnil; | |
6152 | ||
6153 | for (i = 0; i < num_files; i++) | |
6154 | { | |
6155 | len = DragQueryFile (hdrop, i, NULL, 0); | |
6156 | if (len <= 0) | |
6157 | continue; | |
6158 | name = alloca (len + 1); | |
6159 | DragQueryFile (hdrop, i, name, len + 1); | |
6160 | files = Fcons (build_string (name), files); | |
6161 | } | |
6162 | ||
6163 | DragFinish (hdrop); | |
6164 | ||
6165 | XSETFRAME (frame, f); | |
6166 | result->frame_or_window = Fcons (frame, files); | |
7e889510 | 6167 | result->arg = Qnil; |
ec48c3a7 | 6168 | return Qnil; |
12857dfd RS |
6169 | } |
6170 | ||
ee78dc32 GV |
6171 | \f |
6172 | /* Function to report a mouse movement to the mainstream Emacs code. | |
6173 | The input handler calls this. | |
6174 | ||
6175 | We have received a mouse movement event, which is given in *event. | |
6176 | If the mouse is over a different glyph than it was last time, tell | |
6177 | the mainstream emacs code by setting mouse_moved. If not, ask for | |
6178 | another motion event, so we can check again the next time it moves. */ | |
6179 | ||
791f420f JR |
6180 | static MSG last_mouse_motion_event; |
6181 | static Lisp_Object last_mouse_motion_frame; | |
6182 | ||
9f5a911b JR |
6183 | static void remember_mouse_glyph P_ ((struct frame *, int, int)); |
6184 | ||
ee78dc32 GV |
6185 | static void |
6186 | note_mouse_movement (frame, msg) | |
6187 | FRAME_PTR frame; | |
6188 | MSG *msg; | |
6189 | { | |
9f5a911b JR |
6190 | int mouse_x = LOWORD (msg->lParam); |
6191 | int mouse_y = HIWORD (msg->lParam); | |
6192 | ||
ee78dc32 | 6193 | last_mouse_movement_time = msg->time; |
791f420f JR |
6194 | memcpy (&last_mouse_motion_event, msg, sizeof (last_mouse_motion_event)); |
6195 | XSETFRAME (last_mouse_motion_frame, frame); | |
ee78dc32 | 6196 | |
fbd6baed | 6197 | if (msg->hwnd != FRAME_W32_WINDOW (frame)) |
ee78dc32 GV |
6198 | { |
6199 | frame->mouse_moved = 1; | |
6200 | last_mouse_scroll_bar = Qnil; | |
ee78dc32 GV |
6201 | note_mouse_highlight (frame, -1, -1); |
6202 | } | |
6203 | ||
6204 | /* Has the mouse moved off the glyph it was on at the last sighting? */ | |
9f5a911b JR |
6205 | else if (mouse_x < last_mouse_glyph.left |
6206 | || mouse_x > last_mouse_glyph.right | |
6207 | || mouse_y < last_mouse_glyph.top | |
6208 | || mouse_y > last_mouse_glyph.bottom) | |
ee78dc32 GV |
6209 | { |
6210 | frame->mouse_moved = 1; | |
6211 | last_mouse_scroll_bar = Qnil; | |
9f5a911b JR |
6212 | note_mouse_highlight (frame, mouse_x, mouse_y); |
6213 | /* Remember the mouse position here, as w32_mouse_position only | |
6214 | gets called when mouse tracking is enabled but we also need | |
6215 | to keep track of the mouse for help_echo and highlighting at | |
6216 | other times. */ | |
6217 | remember_mouse_glyph (frame, mouse_x, mouse_y); | |
ee78dc32 GV |
6218 | } |
6219 | } | |
6220 | ||
6221 | /* This is used for debugging, to turn off note_mouse_highlight. */ | |
9ef2e2cf | 6222 | |
791f420f JR |
6223 | int disable_mouse_highlight; |
6224 | ||
6225 | ||
6226 | \f | |
6227 | /************************************************************************ | |
6228 | Mouse Face | |
6229 | ************************************************************************/ | |
6230 | ||
6231 | /* Find the glyph under window-relative coordinates X/Y in window W. | |
6232 | Consider only glyphs from buffer text, i.e. no glyphs from overlay | |
6233 | strings. Return in *HPOS and *VPOS the row and column number of | |
6234 | the glyph found. Return in *AREA the glyph area containing X. | |
6235 | Value is a pointer to the glyph found or null if X/Y is not on | |
6236 | text, or we can't tell because W's current matrix is not up to | |
6237 | date. */ | |
6238 | ||
6239 | static struct glyph * | |
9f5a911b | 6240 | x_y_to_hpos_vpos (w, x, y, hpos, vpos, area, buffer_only_p) |
791f420f JR |
6241 | struct window *w; |
6242 | int x, y; | |
6243 | int *hpos, *vpos, *area; | |
9f5a911b | 6244 | int buffer_only_p; |
791f420f JR |
6245 | { |
6246 | struct glyph *glyph, *end; | |
ec48c3a7 | 6247 | struct glyph_row *row = NULL; |
791f420f JR |
6248 | int x0, i, left_area_width; |
6249 | ||
6250 | /* Find row containing Y. Give up if some row is not enabled. */ | |
6251 | for (i = 0; i < w->current_matrix->nrows; ++i) | |
6252 | { | |
6253 | row = MATRIX_ROW (w->current_matrix, i); | |
6254 | if (!row->enabled_p) | |
6255 | return NULL; | |
6256 | if (y >= row->y && y < MATRIX_ROW_BOTTOM_Y (row)) | |
6257 | break; | |
6258 | } | |
6259 | ||
6260 | *vpos = i; | |
6261 | *hpos = 0; | |
6262 | ||
6263 | /* Give up if Y is not in the window. */ | |
6264 | if (i == w->current_matrix->nrows) | |
6265 | return NULL; | |
6266 | ||
6267 | /* Get the glyph area containing X. */ | |
6268 | if (w->pseudo_window_p) | |
6269 | { | |
6270 | *area = TEXT_AREA; | |
6271 | x0 = 0; | |
6272 | } | |
6273 | else | |
6274 | { | |
6275 | left_area_width = window_box_width (w, LEFT_MARGIN_AREA); | |
6276 | if (x < left_area_width) | |
6277 | { | |
6278 | *area = LEFT_MARGIN_AREA; | |
6279 | x0 = 0; | |
6280 | } | |
6281 | else if (x < left_area_width + window_box_width (w, TEXT_AREA)) | |
6282 | { | |
6283 | *area = TEXT_AREA; | |
6284 | x0 = row->x + left_area_width; | |
6285 | } | |
6286 | else | |
6287 | { | |
6288 | *area = RIGHT_MARGIN_AREA; | |
6289 | x0 = left_area_width + window_box_width (w, TEXT_AREA); | |
6290 | } | |
6291 | } | |
6292 | ||
6293 | /* Find glyph containing X. */ | |
6294 | glyph = row->glyphs[*area]; | |
6295 | end = glyph + row->used[*area]; | |
6296 | while (glyph < end) | |
6297 | { | |
6298 | if (x < x0 + glyph->pixel_width) | |
6299 | { | |
6300 | if (w->pseudo_window_p) | |
6301 | break; | |
9f5a911b | 6302 | else if (!buffer_only_p || BUFFERP (glyph->object)) |
791f420f JR |
6303 | break; |
6304 | } | |
6305 | ||
6306 | x0 += glyph->pixel_width; | |
6307 | ++glyph; | |
6308 | } | |
6309 | ||
6310 | if (glyph == end) | |
6311 | return NULL; | |
6312 | ||
6313 | *hpos = glyph - row->glyphs[*area]; | |
6314 | return glyph; | |
6315 | } | |
6316 | ||
6317 | ||
6318 | /* Convert frame-relative x/y to coordinates relative to window W. | |
6319 | Takes pseudo-windows into account. */ | |
6320 | ||
6321 | static void | |
6322 | frame_to_window_pixel_xy (w, x, y) | |
6323 | struct window *w; | |
6324 | int *x, *y; | |
6325 | { | |
6326 | if (w->pseudo_window_p) | |
6327 | { | |
6328 | /* A pseudo-window is always full-width, and starts at the | |
6329 | left edge of the frame, plus a frame border. */ | |
6330 | struct frame *f = XFRAME (w->frame); | |
6331 | *x -= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f); | |
6332 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6333 | } | |
6334 | else | |
6335 | { | |
6336 | *x = FRAME_TO_WINDOW_PIXEL_X (w, *x); | |
6337 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6338 | } | |
6339 | } | |
6340 | ||
6341 | ||
c2cc16fa | 6342 | /* Take proper action when mouse has moved to the mode or header line of |
791f420f JR |
6343 | window W, x-position X. MODE_LINE_P non-zero means mouse is on the |
6344 | mode line. X is relative to the start of the text display area of | |
6345 | W, so the width of bitmap areas and scroll bars must be subtracted | |
6346 | to get a position relative to the start of the mode line. */ | |
6347 | ||
6348 | static void | |
6349 | note_mode_line_highlight (w, x, mode_line_p) | |
6350 | struct window *w; | |
6351 | int x, mode_line_p; | |
6352 | { | |
6353 | struct frame *f = XFRAME (w->frame); | |
6354 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6355 | Cursor cursor = dpyinfo->vertical_scroll_bar_cursor; | |
6356 | struct glyph_row *row; | |
6357 | ||
6358 | if (mode_line_p) | |
6359 | row = MATRIX_MODE_LINE_ROW (w->current_matrix); | |
6360 | else | |
6361 | row = MATRIX_HEADER_LINE_ROW (w->current_matrix); | |
6362 | ||
6363 | if (row->enabled_p) | |
6364 | { | |
6365 | struct glyph *glyph, *end; | |
6366 | Lisp_Object help, map; | |
6367 | int x0; | |
6368 | ||
6369 | /* Find the glyph under X. */ | |
6370 | glyph = row->glyphs[TEXT_AREA]; | |
6371 | end = glyph + row->used[TEXT_AREA]; | |
6372 | x0 = - (FRAME_LEFT_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f) | |
6373 | + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f)); | |
c2cc16fa | 6374 | |
791f420f JR |
6375 | while (glyph < end |
6376 | && x >= x0 + glyph->pixel_width) | |
6377 | { | |
6378 | x0 += glyph->pixel_width; | |
6379 | ++glyph; | |
6380 | } | |
6381 | ||
6382 | if (glyph < end | |
6383 | && STRINGP (glyph->object) | |
6384 | && XSTRING (glyph->object)->intervals | |
6385 | && glyph->charpos >= 0 | |
6386 | && glyph->charpos < XSTRING (glyph->object)->size) | |
6387 | { | |
6388 | /* If we're on a string with `help-echo' text property, | |
6389 | arrange for the help to be displayed. This is done by | |
6390 | setting the global variable help_echo to the help string. */ | |
6391 | help = Fget_text_property (make_number (glyph->charpos), | |
6392 | Qhelp_echo, glyph->object); | |
b7e80413 | 6393 | if (!NILP (help)) |
ec48c3a7 JR |
6394 | { |
6395 | help_echo = help; | |
158cba56 | 6396 | XSETWINDOW (help_echo_window, w); |
ec48c3a7 JR |
6397 | help_echo_object = glyph->object; |
6398 | help_echo_pos = glyph->charpos; | |
6399 | } | |
791f420f JR |
6400 | |
6401 | /* Change the mouse pointer according to what is under X/Y. */ | |
6402 | map = Fget_text_property (make_number (glyph->charpos), | |
6403 | Qlocal_map, glyph->object); | |
02067692 | 6404 | if (KEYMAPP (map)) |
791f420f | 6405 | cursor = f->output_data.w32->nontext_cursor; |
c2cc16fa JR |
6406 | else |
6407 | { | |
6408 | map = Fget_text_property (make_number (glyph->charpos), | |
6409 | Qkeymap, glyph->object); | |
6410 | if (KEYMAPP (map)) | |
6411 | cursor = f->output_data.w32->nontext_cursor; | |
6412 | } | |
791f420f JR |
6413 | } |
6414 | } | |
9ef2e2cf | 6415 | |
01b220b6 | 6416 | #if 0 /* TODO: mouse cursor */ |
791f420f JR |
6417 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor); |
6418 | #endif | |
6419 | } | |
ee78dc32 | 6420 | |
9ef2e2cf JR |
6421 | |
6422 | /* Take proper action when the mouse has moved to position X, Y on | |
6423 | frame F as regards highlighting characters that have mouse-face | |
6424 | properties. Also de-highlighting chars where the mouse was before. | |
ee78dc32 GV |
6425 | X and Y can be negative or out of range. */ |
6426 | ||
6427 | static void | |
6428 | note_mouse_highlight (f, x, y) | |
9ef2e2cf | 6429 | struct frame *f; |
ee78dc32 GV |
6430 | int x, y; |
6431 | { | |
791f420f JR |
6432 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
6433 | int portion; | |
ee78dc32 GV |
6434 | Lisp_Object window; |
6435 | struct window *w; | |
9f5a911b | 6436 | struct buffer *b; |
ee78dc32 | 6437 | |
791f420f JR |
6438 | /* When a menu is active, don't highlight because this looks odd. */ |
6439 | if (popup_activated ()) | |
6440 | return; | |
6441 | ||
9ef2e2cf JR |
6442 | if (disable_mouse_highlight |
6443 | || !f->glyphs_initialized_p) | |
ee78dc32 GV |
6444 | return; |
6445 | ||
791f420f JR |
6446 | dpyinfo->mouse_face_mouse_x = x; |
6447 | dpyinfo->mouse_face_mouse_y = y; | |
6448 | dpyinfo->mouse_face_mouse_frame = f; | |
ee78dc32 | 6449 | |
791f420f | 6450 | if (dpyinfo->mouse_face_defer) |
ee78dc32 GV |
6451 | return; |
6452 | ||
6453 | if (gc_in_progress) | |
6454 | { | |
791f420f | 6455 | dpyinfo->mouse_face_deferred_gc = 1; |
ee78dc32 GV |
6456 | return; |
6457 | } | |
6458 | ||
ee78dc32 | 6459 | /* Which window is that in? */ |
791f420f | 6460 | window = window_from_coordinates (f, x, y, &portion, 1); |
ee78dc32 GV |
6461 | |
6462 | /* If we were displaying active text in another window, clear that. */ | |
791f420f JR |
6463 | if (! EQ (window, dpyinfo->mouse_face_window)) |
6464 | clear_mouse_face (dpyinfo); | |
6465 | ||
6466 | /* Not on a window -> return. */ | |
6467 | if (!WINDOWP (window)) | |
6468 | return; | |
6469 | ||
abb15ebd JR |
6470 | /* Reset help_echo. It will get recomputed below. */ |
6471 | help_echo = Qnil; | |
6472 | ||
791f420f JR |
6473 | /* Convert to window-relative pixel coordinates. */ |
6474 | w = XWINDOW (window); | |
6475 | frame_to_window_pixel_xy (w, &x, &y); | |
6476 | ||
6477 | /* Handle tool-bar window differently since it doesn't display a | |
6478 | buffer. */ | |
6479 | if (EQ (window, f->tool_bar_window)) | |
6480 | { | |
6481 | note_tool_bar_highlight (f, x, y); | |
6482 | return; | |
6483 | } | |
6484 | ||
9f5a911b | 6485 | /* Mouse is on the mode or header line? */ |
791f420f JR |
6486 | if (portion == 1 || portion == 3) |
6487 | { | |
791f420f JR |
6488 | note_mode_line_highlight (w, x, portion == 1); |
6489 | return; | |
6490 | } | |
01b220b6 | 6491 | #if 0 /* TODO: mouse cursor */ |
9f5a911b JR |
6492 | if (portion == 2) |
6493 | cursor = f->output_data.x->horizontal_drag_cursor; | |
791f420f | 6494 | else |
9f5a911b | 6495 | cursor = f->output_data.x->text_cursor; |
791f420f | 6496 | #endif |
ee78dc32 GV |
6497 | /* Are we in a window whose display is up to date? |
6498 | And verify the buffer's text has not changed. */ | |
9f5a911b | 6499 | b = XBUFFER (w->buffer); |
9ef2e2cf | 6500 | if (/* Within text portion of the window. */ |
791f420f | 6501 | portion == 0 |
ee78dc32 | 6502 | && EQ (w->window_end_valid, w->buffer) |
9f5a911b JR |
6503 | && XFASTINT (w->last_modified) == BUF_MODIFF (b) |
6504 | && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b)) | |
ee78dc32 | 6505 | { |
791f420f JR |
6506 | int hpos, vpos, pos, i, area; |
6507 | struct glyph *glyph; | |
9f5a911b JR |
6508 | Lisp_Object object; |
6509 | Lisp_Object mouse_face = Qnil, overlay = Qnil, position; | |
6510 | Lisp_Object *overlay_vec = NULL; | |
6511 | int len, noverlays; | |
6512 | struct buffer *obuf; | |
6513 | int obegv, ozv, same_region; | |
791f420f JR |
6514 | |
6515 | /* Find the glyph under X/Y. */ | |
9f5a911b | 6516 | glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &area, 0); |
791f420f JR |
6517 | |
6518 | /* Clear mouse face if X/Y not over text. */ | |
6519 | if (glyph == NULL | |
6520 | || area != TEXT_AREA | |
6521 | || !MATRIX_ROW (w->current_matrix, vpos)->displays_text_p) | |
6522 | { | |
6523 | clear_mouse_face (dpyinfo); | |
9f5a911b JR |
6524 | /* TODO: mouse cursor */ |
6525 | goto set_cursor; | |
791f420f JR |
6526 | } |
6527 | ||
6528 | pos = glyph->charpos; | |
9f5a911b JR |
6529 | object = glyph->object; |
6530 | if (!STRINGP (object) && !BUFFERP (object)) | |
6531 | goto set_cursor; | |
6532 | ||
6533 | /* If we get an out-of-range value, return now; avoid an error. */ | |
6534 | if (BUFFERP (object) && pos > BUF_Z (b)) | |
6535 | goto set_cursor; | |
6536 | ||
6537 | /* Make the window's buffer temporarily current for | |
6538 | overlays_at and compute_char_face. */ | |
6539 | obuf = current_buffer; | |
6540 | current_buffer = b; | |
6541 | obegv = BEGV; | |
6542 | ozv = ZV; | |
6543 | BEGV = BEG; | |
6544 | ZV = Z; | |
6545 | ||
6546 | /* Is this char mouse-active or does it have help-echo? */ | |
6547 | position = make_number (pos); | |
6548 | ||
6549 | if (BUFFERP (object)) | |
6550 | { | |
6551 | /* Put all the overlays we want in a vector in overlay_vec. | |
6552 | Store the length in len. If there are more than 10, make | |
6553 | enough space for all, and try again. */ | |
6554 | len = 10; | |
6555 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
6556 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL, 0); | |
6557 | if (noverlays > len) | |
6558 | { | |
6559 | len = noverlays; | |
6560 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
6561 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL,0); | |
6562 | } | |
6563 | ||
6564 | /* Sort overlays into increasing priority order. */ | |
6565 | noverlays = sort_overlays (overlay_vec, noverlays, w); | |
6566 | } | |
6567 | else | |
6568 | noverlays = 0; | |
6569 | ||
6570 | same_region = (EQ (window, dpyinfo->mouse_face_window) | |
6571 | && vpos >= dpyinfo->mouse_face_beg_row | |
6572 | && vpos <= dpyinfo->mouse_face_end_row | |
6573 | && (vpos > dpyinfo->mouse_face_beg_row | |
6574 | || hpos >= dpyinfo->mouse_face_beg_col) | |
6575 | && (vpos < dpyinfo->mouse_face_end_row | |
6576 | || hpos < dpyinfo->mouse_face_end_col | |
6577 | || dpyinfo->mouse_face_past_end)); | |
6578 | ||
6579 | /* TODO: if (same_region) | |
6580 | mouse cursor */ | |
6581 | ||
6582 | /* Check mouse-face highlighting. */ | |
6583 | if (! same_region | |
6584 | /* If there exists an overlay with mouse-face overlapping | |
6585 | the one we are currently highlighting, we have to | |
6586 | check if we enter the overlapping overlay, and then | |
6587 | highlight that. */ | |
6588 | || (OVERLAYP (dpyinfo->mouse_face_overlay) | |
6589 | && mouse_face_overlay_overlaps (dpyinfo->mouse_face_overlay))) | |
6590 | { | |
6591 | /* Find the highest priority overlay that has a mouse-face | |
6592 | property. */ | |
6593 | overlay = Qnil; | |
6594 | for (i = noverlays - 1; i >= 0 && NILP (overlay); --i) | |
6595 | { | |
6596 | mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face); | |
6597 | if (!NILP (mouse_face)) | |
6598 | overlay = overlay_vec[i]; | |
6599 | } | |
791f420f | 6600 | |
9f5a911b JR |
6601 | /* If we're actually highlighting the same overlay as |
6602 | before, there's no need to do that again. */ | |
6603 | if (!NILP (overlay) | |
6604 | && EQ (overlay, dpyinfo->mouse_face_overlay)) | |
6605 | goto check_help_echo; | |
6606 | ||
6607 | dpyinfo->mouse_face_overlay = overlay; | |
6608 | ||
6609 | /* Clear the display of the old active region, if any. */ | |
6610 | clear_mouse_face (dpyinfo); | |
6611 | /* TODO: mouse cursor changes. */ | |
6612 | ||
6613 | /* If no overlay applies, get a text property. */ | |
6614 | if (NILP (overlay)) | |
6615 | mouse_face = Fget_text_property (position, Qmouse_face, object); | |
6616 | ||
6617 | /* Handle the overlay case. */ | |
6618 | if (!NILP (overlay)) | |
6619 | { | |
6620 | /* Find the range of text around this char that | |
6621 | should be active. */ | |
6622 | Lisp_Object before, after; | |
6623 | int ignore; | |
6624 | ||
6625 | before = Foverlay_start (overlay); | |
6626 | after = Foverlay_end (overlay); | |
6627 | /* Record this as the current active region. */ | |
6628 | fast_find_position (w, XFASTINT (before), | |
6629 | &dpyinfo->mouse_face_beg_col, | |
6630 | &dpyinfo->mouse_face_beg_row, | |
6631 | &dpyinfo->mouse_face_beg_x, | |
6632 | &dpyinfo->mouse_face_beg_y, Qnil); | |
6633 | ||
6634 | dpyinfo->mouse_face_past_end | |
6635 | = !fast_find_position (w, XFASTINT (after), | |
6636 | &dpyinfo->mouse_face_end_col, | |
6637 | &dpyinfo->mouse_face_end_row, | |
6638 | &dpyinfo->mouse_face_end_x, | |
6639 | &dpyinfo->mouse_face_end_y, Qnil); | |
6640 | dpyinfo->mouse_face_window = window; | |
6641 | ||
6642 | dpyinfo->mouse_face_face_id | |
6643 | = face_at_buffer_position (w, pos, 0, 0, | |
6644 | &ignore, pos + 1, 1); | |
6645 | ||
6646 | /* Display it as active. */ | |
6647 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6648 | /* TODO: mouse cursor changes. */ | |
6649 | } | |
6650 | /* Handle the text property case. */ | |
6651 | else if (! NILP (mouse_face) && BUFFERP (object)) | |
6652 | { | |
6653 | /* Find the range of text around this char that | |
6654 | should be active. */ | |
6655 | Lisp_Object before, after, beginning, end; | |
6656 | int ignore; | |
6657 | ||
6658 | beginning = Fmarker_position (w->start); | |
6659 | end = make_number (BUF_Z (XBUFFER (object)) | |
6660 | - XFASTINT (w->window_end_pos)); | |
6661 | before | |
6662 | = Fprevious_single_property_change (make_number (pos + 1), | |
6663 | Qmouse_face, | |
6664 | object, beginning); | |
6665 | after | |
6666 | = Fnext_single_property_change (position, Qmouse_face, | |
6667 | object, end); | |
6668 | ||
6669 | /* Record this as the current active region. */ | |
6670 | fast_find_position (w, XFASTINT (before), | |
6671 | &dpyinfo->mouse_face_beg_col, | |
6672 | &dpyinfo->mouse_face_beg_row, | |
6673 | &dpyinfo->mouse_face_beg_x, | |
6674 | &dpyinfo->mouse_face_beg_y, Qnil); | |
6675 | dpyinfo->mouse_face_past_end | |
6676 | = !fast_find_position (w, XFASTINT (after), | |
6677 | &dpyinfo->mouse_face_end_col, | |
6678 | &dpyinfo->mouse_face_end_row, | |
6679 | &dpyinfo->mouse_face_end_x, | |
6680 | &dpyinfo->mouse_face_end_y, Qnil); | |
6681 | dpyinfo->mouse_face_window = window; | |
6682 | ||
6683 | if (BUFFERP (object)) | |
6684 | dpyinfo->mouse_face_face_id | |
6685 | = face_at_buffer_position (w, pos, 0, 0, | |
6686 | &ignore, pos + 1, 1); | |
6687 | ||
6688 | /* Display it as active. */ | |
6689 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6690 | /* TODO: mouse cursor changes. */ | |
6691 | } | |
6692 | else if (!NILP (mouse_face) && STRINGP (object)) | |
6693 | { | |
6694 | Lisp_Object b, e; | |
6695 | int ignore; | |
6696 | ||
6697 | b = Fprevious_single_property_change (make_number (pos + 1), | |
6698 | Qmouse_face, | |
6699 | object, Qnil); | |
6700 | e = Fnext_single_property_change (position, Qmouse_face, | |
6701 | object, Qnil); | |
6702 | if (NILP (b)) | |
6703 | b = make_number (0); | |
6704 | if (NILP (e)) | |
6705 | e = make_number (XSTRING (object)->size - 1); | |
6706 | fast_find_string_pos (w, XINT (b), object, | |
6707 | &dpyinfo->mouse_face_beg_col, | |
6708 | &dpyinfo->mouse_face_beg_row, | |
6709 | &dpyinfo->mouse_face_beg_x, | |
6710 | &dpyinfo->mouse_face_beg_y, 0); | |
6711 | fast_find_string_pos (w, XINT (e), object, | |
6712 | &dpyinfo->mouse_face_end_col, | |
6713 | &dpyinfo->mouse_face_end_row, | |
6714 | &dpyinfo->mouse_face_end_x, | |
6715 | &dpyinfo->mouse_face_end_y, 1); | |
6716 | dpyinfo->mouse_face_past_end = 0; | |
6717 | dpyinfo->mouse_face_window = window; | |
6718 | dpyinfo->mouse_face_face_id | |
6719 | = face_at_string_position (w, object, pos, 0, 0, 0, &ignore, | |
6720 | glyph->face_id, 1); | |
6721 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6722 | /* TODO: mouse cursor changes. */ | |
6723 | } | |
6724 | else if (STRINGP (object) && NILP (mouse_face)) | |
6725 | { | |
6726 | /* A string which doesn't have mouse-face, but | |
6727 | the text ``under'' it might have. */ | |
6728 | struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos); | |
6729 | int start = MATRIX_ROW_START_CHARPOS (r); | |
6730 | ||
6731 | pos = string_buffer_position (w, object, start); | |
6732 | if (pos > 0) | |
6733 | mouse_face = get_char_property_and_overlay (make_number (pos), | |
6734 | Qmouse_face, | |
6735 | w->buffer, | |
6736 | &overlay); | |
6737 | if (!NILP (mouse_face) && !NILP (overlay)) | |
6738 | { | |
6739 | Lisp_Object before = Foverlay_start (overlay); | |
6740 | Lisp_Object after = Foverlay_end (overlay); | |
6741 | Lisp_Object ignore; | |
6742 | ||
6743 | /* Note that we might not be able to find position | |
6744 | BEFORE in the glyph matrix if the overlay is | |
6745 | entirely covered by a `display' property. In | |
6746 | this case, we overshoot. So let's stop in | |
6747 | the glyph matrix before glyphs for OBJECT. */ | |
6748 | fast_find_position (w, XFASTINT (before), | |
6749 | &dpyinfo->mouse_face_beg_col, | |
6750 | &dpyinfo->mouse_face_beg_row, | |
6751 | &dpyinfo->mouse_face_beg_x, | |
6752 | &dpyinfo->mouse_face_beg_y, | |
6753 | object); | |
6754 | ||
6755 | dpyinfo->mouse_face_past_end | |
6756 | = !fast_find_position (w, XFASTINT (after), | |
6757 | &dpyinfo->mouse_face_end_col, | |
6758 | &dpyinfo->mouse_face_end_row, | |
6759 | &dpyinfo->mouse_face_end_x, | |
6760 | &dpyinfo->mouse_face_end_y, | |
6761 | Qnil); | |
6762 | dpyinfo->mouse_face_window = window; | |
6763 | dpyinfo->mouse_face_face_id | |
6764 | = face_at_buffer_position (w, pos, 0, 0, | |
6765 | &ignore, pos + 1, 1); | |
6766 | ||
6767 | /* Display it as active. */ | |
6768 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6769 | /* TODO: mouse cursor changes. */ | |
6770 | } | |
6771 | } | |
6772 | } | |
6773 | ||
6774 | check_help_echo: | |
6775 | ||
6776 | /* Look for a `help-echo' property. */ | |
791f420f | 6777 | { |
9f5a911b JR |
6778 | Lisp_Object help, overlay; |
6779 | ||
6780 | /* Check overlays first. */ | |
6781 | help = overlay = Qnil; | |
6782 | for (i = noverlays - 1; i >= 0 && NILP (help); --i) | |
791f420f | 6783 | { |
9f5a911b JR |
6784 | overlay = overlay_vec[i]; |
6785 | help = Foverlay_get (overlay, Qhelp_echo); | |
791f420f JR |
6786 | } |
6787 | ||
9f5a911b | 6788 | if (!NILP (help)) |
791f420f | 6789 | { |
9f5a911b JR |
6790 | help_echo = help; |
6791 | help_echo_window = window; | |
6792 | help_echo_object = overlay; | |
6793 | help_echo_pos = pos; | |
6794 | } | |
6795 | else | |
6796 | { | |
6797 | Lisp_Object object = glyph->object; | |
6798 | int charpos = glyph->charpos; | |
ec48c3a7 | 6799 | |
9f5a911b JR |
6800 | /* Try text properties. */ |
6801 | if (STRINGP (object) | |
6802 | && charpos >= 0 | |
6803 | && charpos < XSTRING (object)->size) | |
6804 | { | |
6805 | help = Fget_text_property (make_number (charpos), | |
6806 | Qhelp_echo, object); | |
6807 | if (NILP (help)) | |
6808 | { | |
6809 | /* If the string itself doesn't specify a help-echo, | |
6810 | see if the buffer text ``under'' it does. */ | |
6811 | struct glyph_row *r | |
6812 | = MATRIX_ROW (w->current_matrix, vpos); | |
6813 | int start = MATRIX_ROW_START_CHARPOS (r); | |
6814 | int pos = string_buffer_position (w, object, start); | |
6815 | if (pos > 0) | |
6816 | { | |
6817 | help = Fget_char_property (make_number (pos), | |
6818 | Qhelp_echo, w->buffer); | |
6819 | if (!NILP (help)) | |
6820 | { | |
6821 | charpos = pos; | |
6822 | object = w->buffer; | |
6823 | } | |
6824 | } | |
6825 | } | |
6826 | } | |
6827 | else if (BUFFERP (object) | |
6828 | && charpos >= BEGV | |
6829 | && charpos < ZV) | |
6830 | help = Fget_text_property (make_number (charpos), Qhelp_echo, | |
6831 | object); | |
791f420f | 6832 | |
9f5a911b JR |
6833 | if (!NILP (help)) |
6834 | { | |
6835 | help_echo = help; | |
6836 | help_echo_window = window; | |
6837 | help_echo_object = object; | |
6838 | help_echo_pos = charpos; | |
6839 | } | |
6840 | } | |
791f420f | 6841 | } |
9f5a911b JR |
6842 | |
6843 | BEGV = obegv; | |
6844 | ZV = ozv; | |
6845 | current_buffer = obuf; | |
791f420f | 6846 | } |
9f5a911b JR |
6847 | |
6848 | set_cursor: | |
6849 | /* TODO: mouse cursor changes. */ | |
6850 | ; | |
791f420f JR |
6851 | } |
6852 | ||
791f420f JR |
6853 | static void |
6854 | redo_mouse_highlight () | |
6855 | { | |
6856 | if (!NILP (last_mouse_motion_frame) | |
6857 | && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) | |
6858 | note_mouse_highlight (XFRAME (last_mouse_motion_frame), | |
6859 | LOWORD (last_mouse_motion_event.lParam), | |
6860 | HIWORD (last_mouse_motion_event.lParam)); | |
6861 | } | |
6862 | ||
6863 | ||
6864 | \f | |
6865 | /*********************************************************************** | |
6866 | Tool-bars | |
6867 | ***********************************************************************/ | |
6868 | ||
6869 | static int x_tool_bar_item P_ ((struct frame *, int, int, | |
6870 | struct glyph **, int *, int *, int *)); | |
6871 | ||
6872 | /* Tool-bar item index of the item on which a mouse button was pressed | |
6873 | or -1. */ | |
6874 | ||
6875 | static int last_tool_bar_item; | |
6876 | ||
6877 | ||
6878 | /* Get information about the tool-bar item at position X/Y on frame F. | |
6879 | Return in *GLYPH a pointer to the glyph of the tool-bar item in | |
6880 | the current matrix of the tool-bar window of F, or NULL if not | |
6881 | on a tool-bar item. Return in *PROP_IDX the index of the tool-bar | |
d417b5e0 | 6882 | item in F->tool_bar_items. Value is |
791f420f JR |
6883 | |
6884 | -1 if X/Y is not on a tool-bar item | |
6885 | 0 if X/Y is on the same item that was highlighted before. | |
6886 | 1 otherwise. */ | |
6887 | ||
6888 | static int | |
6889 | x_tool_bar_item (f, x, y, glyph, hpos, vpos, prop_idx) | |
6890 | struct frame *f; | |
6891 | int x, y; | |
6892 | struct glyph **glyph; | |
6893 | int *hpos, *vpos, *prop_idx; | |
6894 | { | |
6895 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6896 | struct window *w = XWINDOW (f->tool_bar_window); | |
6897 | int area; | |
6898 | ||
6899 | /* Find the glyph under X/Y. */ | |
9f5a911b | 6900 | *glyph = x_y_to_hpos_vpos (w, x, y, hpos, vpos, &area, 0); |
791f420f JR |
6901 | if (*glyph == NULL) |
6902 | return -1; | |
6903 | ||
6904 | /* Get the start of this tool-bar item's properties in | |
d417b5e0 | 6905 | f->tool_bar_items. */ |
791f420f JR |
6906 | if (!tool_bar_item_info (f, *glyph, prop_idx)) |
6907 | return -1; | |
6908 | ||
6909 | /* Is mouse on the highlighted item? */ | |
6910 | if (EQ (f->tool_bar_window, dpyinfo->mouse_face_window) | |
6911 | && *vpos >= dpyinfo->mouse_face_beg_row | |
6912 | && *vpos <= dpyinfo->mouse_face_end_row | |
6913 | && (*vpos > dpyinfo->mouse_face_beg_row | |
6914 | || *hpos >= dpyinfo->mouse_face_beg_col) | |
6915 | && (*vpos < dpyinfo->mouse_face_end_row | |
6916 | || *hpos < dpyinfo->mouse_face_end_col | |
6917 | || dpyinfo->mouse_face_past_end)) | |
6918 | return 0; | |
6919 | ||
6920 | return 1; | |
6921 | } | |
6922 | ||
6923 | ||
9ef2e2cf | 6924 | /* Handle mouse button event on the tool-bar of frame F, at |
791f420f JR |
6925 | frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress |
6926 | or ButtonRelase. */ | |
6927 | ||
6928 | static void | |
6929 | w32_handle_tool_bar_click (f, button_event) | |
6930 | struct frame *f; | |
6931 | struct input_event *button_event; | |
6932 | { | |
6933 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6934 | struct window *w = XWINDOW (f->tool_bar_window); | |
6935 | int hpos, vpos, prop_idx; | |
6936 | struct glyph *glyph; | |
6937 | Lisp_Object enabled_p; | |
6938 | int x = XFASTINT (button_event->x); | |
6939 | int y = XFASTINT (button_event->y); | |
6940 | ||
6941 | /* If not on the highlighted tool-bar item, return. */ | |
6942 | frame_to_window_pixel_xy (w, &x, &y); | |
6943 | if (x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx) != 0) | |
6944 | return; | |
6945 | ||
6946 | /* If item is disabled, do nothing. */ | |
d417b5e0 | 6947 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
791f420f JR |
6948 | if (NILP (enabled_p)) |
6949 | return; | |
6950 | ||
6951 | if (button_event->kind == mouse_click) | |
6952 | { | |
6953 | /* Show item in pressed state. */ | |
6954 | show_mouse_face (dpyinfo, DRAW_IMAGE_SUNKEN); | |
6955 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_SUNKEN; | |
6956 | last_tool_bar_item = prop_idx; | |
6957 | } | |
6958 | else | |
6959 | { | |
6960 | Lisp_Object key, frame; | |
6961 | struct input_event event; | |
6962 | ||
6963 | /* Show item in released state. */ | |
6964 | show_mouse_face (dpyinfo, DRAW_IMAGE_RAISED); | |
6965 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_RAISED; | |
6966 | ||
d417b5e0 | 6967 | key = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_KEY); |
791f420f JR |
6968 | |
6969 | XSETFRAME (frame, f); | |
6970 | event.kind = TOOL_BAR_EVENT; | |
c8b33aa6 GM |
6971 | event.frame_or_window = frame; |
6972 | event.arg = frame; | |
791f420f JR |
6973 | kbd_buffer_store_event (&event); |
6974 | ||
6975 | event.kind = TOOL_BAR_EVENT; | |
c8b33aa6 GM |
6976 | event.frame_or_window = frame; |
6977 | event.arg = key; | |
791f420f JR |
6978 | event.modifiers = button_event->modifiers; |
6979 | kbd_buffer_store_event (&event); | |
6980 | last_tool_bar_item = -1; | |
6981 | } | |
6982 | } | |
6983 | ||
6984 | ||
9ef2e2cf | 6985 | /* Possibly highlight a tool-bar item on frame F when mouse moves to |
791f420f JR |
6986 | tool-bar window-relative coordinates X/Y. Called from |
6987 | note_mouse_highlight. */ | |
6988 | ||
6989 | static void | |
6990 | note_tool_bar_highlight (f, x, y) | |
6991 | struct frame *f; | |
6992 | int x, y; | |
6993 | { | |
6994 | Lisp_Object window = f->tool_bar_window; | |
6995 | struct window *w = XWINDOW (window); | |
6996 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6997 | int hpos, vpos; | |
6998 | struct glyph *glyph; | |
6999 | struct glyph_row *row; | |
7000 | int i; | |
7001 | Lisp_Object enabled_p; | |
7002 | int prop_idx; | |
7003 | enum draw_glyphs_face draw = DRAW_IMAGE_RAISED; | |
7004 | int mouse_down_p, rc; | |
7005 | ||
7006 | /* Function note_mouse_highlight is called with negative x(y | |
7007 | values when mouse moves outside of the frame. */ | |
7008 | if (x <= 0 || y <= 0) | |
7009 | { | |
7010 | clear_mouse_face (dpyinfo); | |
7011 | return; | |
7012 | } | |
7013 | ||
7014 | rc = x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx); | |
7015 | if (rc < 0) | |
7016 | { | |
7017 | /* Not on tool-bar item. */ | |
7018 | clear_mouse_face (dpyinfo); | |
7019 | return; | |
7020 | } | |
7021 | else if (rc == 0) | |
7022 | /* On same tool-bar item as before. */ | |
7023 | goto set_help_echo; | |
ee78dc32 | 7024 | |
791f420f JR |
7025 | clear_mouse_face (dpyinfo); |
7026 | ||
7027 | /* Mouse is down, but on different tool-bar item? */ | |
7028 | mouse_down_p = (dpyinfo->grabbed | |
7029 | && f == last_mouse_frame | |
7030 | && FRAME_LIVE_P (f)); | |
7031 | if (mouse_down_p | |
7032 | && last_tool_bar_item != prop_idx) | |
7033 | return; | |
ee78dc32 | 7034 | |
791f420f JR |
7035 | dpyinfo->mouse_face_image_state = DRAW_NORMAL_TEXT; |
7036 | draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED; | |
7037 | ||
7038 | /* If tool-bar item is not enabled, don't highlight it. */ | |
d417b5e0 | 7039 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
791f420f JR |
7040 | if (!NILP (enabled_p)) |
7041 | { | |
7042 | /* Compute the x-position of the glyph. In front and past the | |
7043 | image is a space. We include this is the highlighted area. */ | |
7044 | row = MATRIX_ROW (w->current_matrix, vpos); | |
7045 | for (i = x = 0; i < hpos; ++i) | |
7046 | x += row->glyphs[TEXT_AREA][i].pixel_width; | |
7047 | ||
7048 | /* Record this as the current active region. */ | |
7049 | dpyinfo->mouse_face_beg_col = hpos; | |
7050 | dpyinfo->mouse_face_beg_row = vpos; | |
7051 | dpyinfo->mouse_face_beg_x = x; | |
7052 | dpyinfo->mouse_face_beg_y = row->y; | |
7053 | dpyinfo->mouse_face_past_end = 0; | |
7054 | ||
7055 | dpyinfo->mouse_face_end_col = hpos + 1; | |
7056 | dpyinfo->mouse_face_end_row = vpos; | |
7057 | dpyinfo->mouse_face_end_x = x + glyph->pixel_width; | |
7058 | dpyinfo->mouse_face_end_y = row->y; | |
7059 | dpyinfo->mouse_face_window = window; | |
7060 | dpyinfo->mouse_face_face_id = TOOL_BAR_FACE_ID; | |
7061 | ||
7062 | /* Display it as active. */ | |
7063 | show_mouse_face (dpyinfo, draw); | |
7064 | dpyinfo->mouse_face_image_state = draw; | |
ee78dc32 | 7065 | } |
791f420f JR |
7066 | |
7067 | set_help_echo: | |
7068 | ||
7069 | /* Set help_echo to a help string.to display for this tool-bar item. | |
7070 | w32_read_socket does the rest. */ | |
158cba56 | 7071 | help_echo_object = help_echo_window = Qnil; |
ec48c3a7 | 7072 | help_echo_pos = -1; |
d417b5e0 | 7073 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_HELP); |
b7e80413 | 7074 | if (NILP (help_echo)) |
d417b5e0 | 7075 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_CAPTION); |
ee78dc32 | 7076 | } |
ee78dc32 | 7077 | |
9ef2e2cf | 7078 | |
791f420f | 7079 | \f |
9f5a911b JR |
7080 | /* Find the glyph matrix position of buffer position CHARPOS in window |
7081 | *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's | |
7082 | current glyphs must be up to date. If CHARPOS is above window | |
7083 | start return (0, 0, 0, 0). If CHARPOS is after end of W, return end | |
7084 | of last line in W. In the row containing CHARPOS, stop before glyphs | |
7085 | having STOP as object. */ | |
7086 | ||
7087 | #if 0 /* This is a version of fast_find_position that's more correct | |
7088 | in the presence of hscrolling, for example. I didn't install | |
7089 | it right away because the problem fixed is minor, it failed | |
7090 | in 20.x as well, and I think it's too risky to install | |
7091 | so near the release of 21.1. 2001-09-25 gerd. */ | |
ee78dc32 GV |
7092 | |
7093 | static int | |
9f5a911b JR |
7094 | fast_find_position (w, charpos, hpos, vpos, x, y, stop) |
7095 | struct window *w; | |
7096 | int charpos; | |
7097 | int *hpos, *vpos, *x, *y; | |
7098 | Lisp_Object stop; | |
7099 | { | |
7100 | struct glyph_row *row, *first; | |
7101 | struct glyph *glyph, *end; | |
7102 | int i, past_end = 0; | |
7103 | ||
7104 | first = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
62e33982 | 7105 | row = row_containing_pos (w, charpos, first, NULL, 0); |
9f5a911b JR |
7106 | if (row == NULL) |
7107 | { | |
7108 | if (charpos < MATRIX_ROW_START_CHARPOS (first)) | |
7109 | { | |
7110 | *x = *y = *hpos = *vpos = 0; | |
7111 | return 0; | |
7112 | } | |
7113 | else | |
7114 | { | |
7115 | row = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); | |
7116 | past_end = 1; | |
7117 | } | |
7118 | } | |
7119 | ||
7120 | *x = row->x; | |
7121 | *y = row->y; | |
7122 | *vpos = MATRIX_ROW_VPOS (row, w->current_matrix); | |
7123 | ||
7124 | glyph = row->glyphs[TEXT_AREA]; | |
7125 | end = glyph + row->used[TEXT_AREA]; | |
7126 | ||
7127 | /* Skip over glyphs not having an object at the start of the row. | |
7128 | These are special glyphs like truncation marks on terminal | |
7129 | frames. */ | |
7130 | if (row->displays_text_p) | |
7131 | while (glyph < end | |
7132 | && INTEGERP (glyph->object) | |
7133 | && !EQ (stop, glyph->object) | |
7134 | && glyph->charpos < 0) | |
7135 | { | |
7136 | *x += glyph->pixel_width; | |
7137 | ++glyph; | |
7138 | } | |
7139 | ||
7140 | while (glyph < end | |
7141 | && !INTEGERP (glyph->object) | |
7142 | && !EQ (stop, glyph->object) | |
7143 | && (!BUFFERP (glyph->object) | |
7144 | || glyph->charpos < charpos)) | |
7145 | { | |
7146 | *x += glyph->pixel_width; | |
7147 | ++glyph; | |
7148 | } | |
7149 | ||
7150 | *hpos = glyph - row->glyphs[TEXT_AREA]; | |
7151 | return past_end; | |
7152 | } | |
7153 | ||
7154 | #else /* not 0 */ | |
7155 | ||
7156 | static int | |
7157 | fast_find_position (w, pos, hpos, vpos, x, y, stop) | |
791f420f | 7158 | struct window *w; |
ee78dc32 | 7159 | int pos; |
791f420f | 7160 | int *hpos, *vpos, *x, *y; |
9f5a911b | 7161 | Lisp_Object stop; |
ee78dc32 | 7162 | { |
ee78dc32 | 7163 | int i; |
ee78dc32 | 7164 | int lastcol; |
791f420f JR |
7165 | int maybe_next_line_p = 0; |
7166 | int line_start_position; | |
7167 | int yb = window_text_bottom_y (w); | |
9f5a911b JR |
7168 | struct glyph_row *row, *best_row; |
7169 | int row_vpos, best_row_vpos; | |
791f420f JR |
7170 | int current_x; |
7171 | ||
9f5a911b JR |
7172 | row = best_row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); |
7173 | row_vpos = best_row_vpos = MATRIX_ROW_VPOS (row, w->current_matrix); | |
7174 | ||
791f420f | 7175 | while (row->y < yb) |
ee78dc32 | 7176 | { |
791f420f JR |
7177 | if (row->used[TEXT_AREA]) |
7178 | line_start_position = row->glyphs[TEXT_AREA]->charpos; | |
7179 | else | |
7180 | line_start_position = 0; | |
7181 | ||
7182 | if (line_start_position > pos) | |
ee78dc32 GV |
7183 | break; |
7184 | /* If the position sought is the end of the buffer, | |
7185 | don't include the blank lines at the bottom of the window. */ | |
791f420f JR |
7186 | else if (line_start_position == pos |
7187 | && pos == BUF_ZV (XBUFFER (w->buffer))) | |
ee78dc32 | 7188 | { |
791f420f | 7189 | maybe_next_line_p = 1; |
ee78dc32 GV |
7190 | break; |
7191 | } | |
791f420f JR |
7192 | else if (line_start_position > 0) |
7193 | { | |
7194 | best_row = row; | |
7195 | best_row_vpos = row_vpos; | |
7196 | } | |
7197 | ||
9ef2e2cf JR |
7198 | if (row->y + row->height >= yb) |
7199 | break; | |
7200 | ||
791f420f JR |
7201 | ++row; |
7202 | ++row_vpos; | |
ee78dc32 GV |
7203 | } |
7204 | ||
791f420f JR |
7205 | /* Find the right column within BEST_ROW. */ |
7206 | lastcol = 0; | |
7207 | current_x = best_row->x; | |
7208 | for (i = 0; i < best_row->used[TEXT_AREA]; i++) | |
ee78dc32 | 7209 | { |
791f420f | 7210 | struct glyph *glyph = best_row->glyphs[TEXT_AREA] + i; |
9f5a911b | 7211 | int charpos = glyph->charpos; |
791f420f | 7212 | |
9f5a911b | 7213 | if (BUFFERP (glyph->object)) |
ee78dc32 | 7214 | { |
9f5a911b JR |
7215 | if (charpos == pos) |
7216 | { | |
7217 | *hpos = i; | |
7218 | *vpos = best_row_vpos; | |
7219 | *x = current_x; | |
7220 | *y = best_row->y; | |
7221 | return 1; | |
7222 | } | |
7223 | else if (charpos > pos) | |
7224 | break; | |
ee78dc32 | 7225 | } |
9f5a911b | 7226 | else if (EQ (glyph->object, stop)) |
ee78dc32 | 7227 | break; |
791f420f | 7228 | |
9f5a911b JR |
7229 | if (charpos > 0) |
7230 | lastcol = i; | |
791f420f | 7231 | current_x += glyph->pixel_width; |
ee78dc32 GV |
7232 | } |
7233 | ||
7234 | /* If we're looking for the end of the buffer, | |
7235 | and we didn't find it in the line we scanned, | |
7236 | use the start of the following line. */ | |
791f420f | 7237 | if (maybe_next_line_p) |
ee78dc32 | 7238 | { |
791f420f JR |
7239 | ++best_row; |
7240 | ++best_row_vpos; | |
7241 | lastcol = 0; | |
7242 | current_x = best_row->x; | |
ee78dc32 GV |
7243 | } |
7244 | ||
791f420f JR |
7245 | *vpos = best_row_vpos; |
7246 | *hpos = lastcol + 1; | |
7247 | *x = current_x; | |
7248 | *y = best_row->y; | |
ee78dc32 GV |
7249 | return 0; |
7250 | } | |
7251 | ||
9f5a911b JR |
7252 | #endif /* not 0 */ |
7253 | ||
7254 | ||
7255 | /* Find the position of the the glyph for position POS in OBJECT in | |
7256 | window W's current matrix, and return in *X/*Y the pixel | |
7257 | coordinates, and return in *HPOS/*VPOS the column/row of the glyph. | |
7258 | ||
7259 | RIGHT_P non-zero means return the position of the right edge of the | |
7260 | glyph, RIGHT_P zero means return the left edge position. | |
7261 | ||
7262 | If no glyph for POS exists in the matrix, return the position of | |
7263 | the glyph with the next smaller position that is in the matrix, if | |
7264 | RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS | |
7265 | exists in the matrix, return the position of the glyph with the | |
7266 | next larger position in OBJECT. | |
7267 | ||
7268 | Value is non-zero if a glyph was found. */ | |
7269 | ||
7270 | static int | |
7271 | fast_find_string_pos (w, pos, object, hpos, vpos, x, y, right_p) | |
7272 | struct window *w; | |
7273 | int pos; | |
7274 | Lisp_Object object; | |
7275 | int *hpos, *vpos, *x, *y; | |
7276 | int right_p; | |
7277 | { | |
7278 | int yb = window_text_bottom_y (w); | |
7279 | struct glyph_row *r; | |
7280 | struct glyph *best_glyph = NULL; | |
7281 | struct glyph_row *best_row = NULL; | |
7282 | int best_x = 0; | |
7283 | ||
7284 | for (r = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
7285 | r->enabled_p && r->y < yb; | |
7286 | ++r) | |
7287 | { | |
7288 | struct glyph *g = r->glyphs[TEXT_AREA]; | |
7289 | struct glyph *e = g + r->used[TEXT_AREA]; | |
7290 | int gx; | |
7291 | ||
7292 | for (gx = r->x; g < e; gx += g->pixel_width, ++g) | |
7293 | if (EQ (g->object, object)) | |
7294 | { | |
7295 | if (g->charpos == pos) | |
7296 | { | |
7297 | best_glyph = g; | |
7298 | best_x = gx; | |
7299 | best_row = r; | |
7300 | goto found; | |
7301 | } | |
7302 | else if (best_glyph == NULL | |
7303 | || ((abs (g->charpos - pos) | |
7304 | < abs (best_glyph->charpos - pos)) | |
7305 | && (right_p | |
7306 | ? g->charpos < pos | |
7307 | : g->charpos > pos))) | |
7308 | { | |
7309 | best_glyph = g; | |
7310 | best_x = gx; | |
7311 | best_row = r; | |
7312 | } | |
7313 | } | |
7314 | } | |
7315 | ||
7316 | found: | |
7317 | ||
7318 | if (best_glyph) | |
7319 | { | |
7320 | *x = best_x; | |
7321 | *hpos = best_glyph - best_row->glyphs[TEXT_AREA]; | |
7322 | ||
7323 | if (right_p) | |
7324 | { | |
7325 | *x += best_glyph->pixel_width; | |
7326 | ++*hpos; | |
7327 | } | |
7328 | ||
7329 | *y = best_row->y; | |
7330 | *vpos = best_row - w->current_matrix->rows; | |
7331 | } | |
7332 | ||
7333 | return best_glyph != NULL; | |
7334 | } | |
7335 | ||
791f420f | 7336 | |
ee78dc32 GV |
7337 | /* Display the active region described by mouse_face_* |
7338 | in its mouse-face if HL > 0, in its normal face if HL = 0. */ | |
7339 | ||
7340 | static void | |
791f420f | 7341 | show_mouse_face (dpyinfo, draw) |
fbd6baed | 7342 | struct w32_display_info *dpyinfo; |
791f420f | 7343 | enum draw_glyphs_face draw; |
ee78dc32 GV |
7344 | { |
7345 | struct window *w = XWINDOW (dpyinfo->mouse_face_window); | |
791f420f | 7346 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
ee78dc32 | 7347 | int i; |
791f420f JR |
7348 | int cursor_off_p = 0; |
7349 | struct cursor_pos saved_cursor; | |
7350 | ||
7351 | saved_cursor = output_cursor; | |
7352 | ||
7353 | /* If window is in the process of being destroyed, don't bother | |
7354 | to do anything. */ | |
7355 | if (w->current_matrix == NULL) | |
7356 | goto set_x_cursor; | |
7357 | ||
7358 | /* Recognize when we are called to operate on rows that don't exist | |
7359 | anymore. This can happen when a window is split. */ | |
7360 | if (dpyinfo->mouse_face_end_row >= w->current_matrix->nrows) | |
7361 | goto set_x_cursor; | |
7362 | ||
7363 | set_output_cursor (&w->phys_cursor); | |
7364 | ||
7365 | /* Note that mouse_face_beg_row etc. are window relative. */ | |
7366 | for (i = dpyinfo->mouse_face_beg_row; | |
7367 | i <= dpyinfo->mouse_face_end_row; | |
7368 | i++) | |
7369 | { | |
7370 | int start_hpos, end_hpos, start_x; | |
7371 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, i); | |
7372 | ||
7373 | /* Don't do anything if row doesn't have valid contents. */ | |
7374 | if (!row->enabled_p) | |
7375 | continue; | |
7376 | ||
7377 | /* For all but the first row, the highlight starts at column 0. */ | |
7378 | if (i == dpyinfo->mouse_face_beg_row) | |
7379 | { | |
7380 | start_hpos = dpyinfo->mouse_face_beg_col; | |
7381 | start_x = dpyinfo->mouse_face_beg_x; | |
7382 | } | |
7383 | else | |
7384 | { | |
7385 | start_hpos = 0; | |
7386 | start_x = 0; | |
7387 | } | |
7388 | ||
7389 | if (i == dpyinfo->mouse_face_end_row) | |
7390 | end_hpos = dpyinfo->mouse_face_end_col; | |
7391 | else | |
7392 | end_hpos = row->used[TEXT_AREA]; | |
7393 | ||
7394 | /* If the cursor's in the text we are about to rewrite, turn the | |
7395 | cursor off. */ | |
7396 | if (!w->pseudo_window_p | |
7397 | && i == output_cursor.vpos | |
7398 | && output_cursor.hpos >= start_hpos - 1 | |
7399 | && output_cursor.hpos <= end_hpos) | |
ee78dc32 | 7400 | { |
791f420f JR |
7401 | x_update_window_cursor (w, 0); |
7402 | cursor_off_p = 1; | |
ee78dc32 GV |
7403 | } |
7404 | ||
791f420f | 7405 | if (end_hpos > start_hpos) |
ec48c3a7 | 7406 | { |
ec48c3a7 JR |
7407 | x_draw_glyphs (w, start_x, row, TEXT_AREA, |
7408 | start_hpos, end_hpos, draw, NULL, NULL, 0); | |
9f5a911b | 7409 | row->mouse_face_p = draw == DRAW_MOUSE_FACE || DRAW_IMAGE_RAISED; |
ec48c3a7 | 7410 | } |
ee78dc32 GV |
7411 | } |
7412 | ||
7413 | /* If we turned the cursor off, turn it back on. */ | |
791f420f JR |
7414 | if (cursor_off_p) |
7415 | x_display_cursor (w, 1, | |
7416 | output_cursor.hpos, output_cursor.vpos, | |
7417 | output_cursor.x, output_cursor.y); | |
7418 | ||
7419 | output_cursor = saved_cursor; | |
7420 | ||
7421 | set_x_cursor: | |
01b220b6 | 7422 | #if 0 /* TODO: mouse cursor */ |
791f420f JR |
7423 | /* Change the mouse cursor. */ |
7424 | if (draw == DRAW_NORMAL_TEXT) | |
7425 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7426 | f->output_data.x->text_cursor); | |
7427 | else if (draw == DRAW_MOUSE_FACE) | |
7428 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7429 | f->output_data.x->cross_cursor); | |
ee78dc32 | 7430 | else |
791f420f JR |
7431 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7432 | f->output_data.x->nontext_cursor); | |
7433 | #endif | |
7434 | ; | |
ee78dc32 GV |
7435 | } |
7436 | ||
7437 | /* Clear out the mouse-highlighted active region. | |
9ef2e2cf | 7438 | Redraw it un-highlighted first. */ |
ee78dc32 | 7439 | |
9f5a911b | 7440 | static int |
ee78dc32 | 7441 | clear_mouse_face (dpyinfo) |
fbd6baed | 7442 | struct w32_display_info *dpyinfo; |
ee78dc32 | 7443 | { |
9f5a911b | 7444 | int cleared = 0; |
791f420f | 7445 | |
ee78dc32 | 7446 | if (! NILP (dpyinfo->mouse_face_window)) |
9f5a911b JR |
7447 | { |
7448 | show_mouse_face (dpyinfo, DRAW_NORMAL_TEXT); | |
7449 | cleared = 1; | |
7450 | } | |
ee78dc32 GV |
7451 | |
7452 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7453 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7454 | dpyinfo->mouse_face_window = Qnil; | |
9f5a911b JR |
7455 | dpyinfo->mouse_face_overlay = Qnil; |
7456 | return cleared; | |
ee78dc32 | 7457 | } |
31d4844a | 7458 | |
ec48c3a7 JR |
7459 | |
7460 | /* Clear any mouse-face on window W. This function is part of the | |
7461 | redisplay interface, and is called from try_window_id and similar | |
7462 | functions to ensure the mouse-highlight is off. */ | |
7463 | ||
7464 | static void | |
7465 | x_clear_mouse_face (w) | |
7466 | struct window *w; | |
7467 | { | |
7468 | struct w32_display_info *dpyinfo | |
7469 | = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); | |
7470 | Lisp_Object window; | |
7471 | ||
9127e20e | 7472 | BLOCK_INPUT; |
ec48c3a7 JR |
7473 | XSETWINDOW (window, w); |
7474 | if (EQ (window, dpyinfo->mouse_face_window)) | |
7475 | clear_mouse_face (dpyinfo); | |
9127e20e | 7476 | UNBLOCK_INPUT; |
ec48c3a7 JR |
7477 | } |
7478 | ||
7479 | ||
31d4844a KH |
7480 | /* Just discard the mouse face information for frame F, if any. |
7481 | This is used when the size of F is changed. */ | |
7482 | ||
7483 | void | |
7484 | cancel_mouse_face (f) | |
7485 | FRAME_PTR f; | |
7486 | { | |
7487 | Lisp_Object window; | |
7488 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
7489 | ||
7490 | window = dpyinfo->mouse_face_window; | |
7491 | if (! NILP (window) && XFRAME (XWINDOW (window)->frame) == f) | |
7492 | { | |
7493 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7494 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7495 | dpyinfo->mouse_face_window = Qnil; | |
7496 | } | |
7497 | } | |
ee78dc32 | 7498 | \f |
9ef2e2cf | 7499 | static struct scroll_bar *x_window_to_scroll_bar (); |
ee78dc32 | 7500 | static void x_scroll_bar_report_motion (); |
9f5a911b JR |
7501 | static int glyph_rect P_ ((struct frame *f, int, int, RECT *)); |
7502 | ||
7503 | ||
7504 | /* Try to determine frame pixel position and size of the glyph under | |
7505 | frame pixel coordinates X/Y on frame F . Return the position and | |
7506 | size in *RECT. Value is non-zero if we could compute these | |
7507 | values. */ | |
7508 | ||
7509 | static int | |
7510 | glyph_rect (f, x, y, rect) | |
7511 | struct frame *f; | |
7512 | int x, y; | |
7513 | RECT *rect; | |
7514 | { | |
7515 | Lisp_Object window; | |
7516 | int part, found = 0; | |
7517 | ||
7518 | window = window_from_coordinates (f, x, y, &part, 0); | |
7519 | if (!NILP (window)) | |
7520 | { | |
7521 | struct window *w = XWINDOW (window); | |
7522 | struct glyph_row *r = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
7523 | struct glyph_row *end = r + w->current_matrix->nrows - 1; | |
7524 | int area; | |
7525 | ||
7526 | frame_to_window_pixel_xy (w, &x, &y); | |
7527 | ||
7528 | for (; !found && r < end && r->enabled_p; ++r) | |
7529 | if (r->y + r->height >= y) | |
7530 | { | |
7531 | struct glyph *g = r->glyphs[TEXT_AREA]; | |
7532 | struct glyph *end = g + r->used[TEXT_AREA]; | |
7533 | int gx; | |
7534 | ||
7535 | for (gx = r->x; !found && g < end; gx += g->pixel_width, ++g) | |
7536 | if (gx + g->pixel_width >= x) | |
7537 | { | |
7538 | rect->left = WINDOW_TO_FRAME_PIXEL_X (w, gx); | |
7539 | rect->top = WINDOW_TO_FRAME_PIXEL_Y (w, r->y); | |
7540 | rect->right = rect->left + g->pixel_width; | |
7541 | rect->bottom = rect->top + r->height; | |
7542 | found = 1; | |
7543 | } | |
7544 | } | |
7545 | } | |
7546 | ||
7547 | return found; | |
7548 | } | |
7549 | ||
7550 | /* Record the position of the mouse in last_mouse_glyph. */ | |
565153ff JR |
7551 | static void |
7552 | remember_mouse_glyph (f1, gx, gy) | |
9f5a911b JR |
7553 | struct frame * f1; |
7554 | int gx, gy; | |
7555 | { | |
7556 | if (!glyph_rect (f1, gx, gy, &last_mouse_glyph)) | |
7557 | { | |
7558 | int width = FRAME_SMALLEST_CHAR_WIDTH (f1); | |
7559 | int height = FRAME_SMALLEST_FONT_HEIGHT (f1); | |
7560 | ||
7561 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to | |
7562 | round down even for negative values. */ | |
7563 | if (gx < 0) | |
7564 | gx -= width - 1; | |
7565 | if (gy < 0) | |
7566 | gy -= height - 1; | |
7567 | #if 0 | |
7568 | /* This was the original code from XTmouse_position, but it seems | |
7569 | to give the position of the glyph diagonally next to the one | |
7570 | the mouse is over. */ | |
7571 | gx = (gx + width - 1) / width * width; | |
7572 | gy = (gy + height - 1) / height * height; | |
7573 | #else | |
7574 | gx = gx / width * width; | |
7575 | gy = gy / height * height; | |
7576 | #endif | |
7577 | ||
7578 | last_mouse_glyph.left = gx; | |
7579 | last_mouse_glyph.top = gy; | |
7580 | last_mouse_glyph.right = gx + width; | |
7581 | last_mouse_glyph.bottom = gy + height; | |
7582 | } | |
7583 | } | |
ee78dc32 GV |
7584 | |
7585 | /* Return the current position of the mouse. | |
7586 | *fp should be a frame which indicates which display to ask about. | |
7587 | ||
7588 | If the mouse movement started in a scroll bar, set *fp, *bar_window, | |
7589 | and *part to the frame, window, and scroll bar part that the mouse | |
7590 | is over. Set *x and *y to the portion and whole of the mouse's | |
7591 | position on the scroll bar. | |
7592 | ||
7593 | If the mouse movement started elsewhere, set *fp to the frame the | |
7594 | mouse is on, *bar_window to nil, and *x and *y to the character cell | |
7595 | the mouse is over. | |
7596 | ||
9ef2e2cf | 7597 | Set *time to the server time-stamp for the time at which the mouse |
ee78dc32 GV |
7598 | was at this position. |
7599 | ||
7600 | Don't store anything if we don't have a valid set of values to report. | |
7601 | ||
7602 | This clears the mouse_moved flag, so we can wait for the next mouse | |
9ef2e2cf | 7603 | movement. */ |
ee78dc32 GV |
7604 | |
7605 | static void | |
fbd6baed | 7606 | w32_mouse_position (fp, insist, bar_window, part, x, y, time) |
ee78dc32 GV |
7607 | FRAME_PTR *fp; |
7608 | int insist; | |
7609 | Lisp_Object *bar_window; | |
7610 | enum scroll_bar_part *part; | |
7611 | Lisp_Object *x, *y; | |
7612 | unsigned long *time; | |
7613 | { | |
7614 | FRAME_PTR f1; | |
7615 | ||
7616 | BLOCK_INPUT; | |
7617 | ||
95fa970d | 7618 | if (! NILP (last_mouse_scroll_bar) && insist == 0) |
ee78dc32 GV |
7619 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); |
7620 | else | |
7621 | { | |
7622 | POINT pt; | |
7623 | ||
7624 | Lisp_Object frame, tail; | |
7625 | ||
7626 | /* Clear the mouse-moved flag for every frame on this display. */ | |
7627 | FOR_EACH_FRAME (tail, frame) | |
7628 | XFRAME (frame)->mouse_moved = 0; | |
7629 | ||
7630 | last_mouse_scroll_bar = Qnil; | |
7631 | ||
7632 | GetCursorPos (&pt); | |
7633 | ||
7634 | /* Now we have a position on the root; find the innermost window | |
7635 | containing the pointer. */ | |
7636 | { | |
fbd6baed | 7637 | if (FRAME_W32_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame |
ee78dc32 GV |
7638 | && FRAME_LIVE_P (last_mouse_frame)) |
7639 | { | |
08712a41 AI |
7640 | /* If mouse was grabbed on a frame, give coords for that frame |
7641 | even if the mouse is now outside it. */ | |
ee78dc32 GV |
7642 | f1 = last_mouse_frame; |
7643 | } | |
7644 | else | |
7645 | { | |
08712a41 | 7646 | /* Is window under mouse one of our frames? */ |
9f5a911b | 7647 | f1 = x_any_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp), |
9127e20e | 7648 | WindowFromPoint (pt)); |
ee78dc32 GV |
7649 | } |
7650 | ||
7651 | /* If not, is it one of our scroll bars? */ | |
7652 | if (! f1) | |
7653 | { | |
9127e20e JR |
7654 | struct scroll_bar *bar |
7655 | = x_window_to_scroll_bar (WindowFromPoint (pt)); | |
ee78dc32 GV |
7656 | |
7657 | if (bar) | |
7658 | { | |
7659 | f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
7660 | } | |
7661 | } | |
7662 | ||
95fa970d | 7663 | if (f1 == 0 && insist > 0) |
791f420f | 7664 | f1 = SELECTED_FRAME (); |
ee78dc32 GV |
7665 | |
7666 | if (f1) | |
7667 | { | |
791f420f JR |
7668 | /* Ok, we found a frame. Store all the values. |
7669 | last_mouse_glyph is a rectangle used to reduce the | |
7670 | generation of mouse events. To not miss any motion | |
7671 | events, we must divide the frame into rectangles of the | |
7672 | size of the smallest character that could be displayed | |
7673 | on it, i.e. into the same rectangles that matrices on | |
7674 | the frame are divided into. */ | |
7675 | ||
7676 | #if OLD_REDISPLAY_CODE | |
ee78dc32 GV |
7677 | int ignore1, ignore2; |
7678 | ||
fbd6baed | 7679 | ScreenToClient (FRAME_W32_WINDOW (f1), &pt); |
ee78dc32 | 7680 | |
ee78dc32 GV |
7681 | pixel_to_glyph_coords (f1, pt.x, pt.y, &ignore1, &ignore2, |
7682 | &last_mouse_glyph, | |
fbd6baed | 7683 | FRAME_W32_DISPLAY_INFO (f1)->grabbed |
ee78dc32 | 7684 | || insist); |
791f420f JR |
7685 | #else |
7686 | ScreenToClient (FRAME_W32_WINDOW (f1), &pt); | |
9f5a911b | 7687 | remember_mouse_glyph (f1, pt.x, pt.y); |
791f420f | 7688 | #endif |
ee78dc32 GV |
7689 | |
7690 | *bar_window = Qnil; | |
7691 | *part = 0; | |
7692 | *fp = f1; | |
7693 | XSETINT (*x, pt.x); | |
7694 | XSETINT (*y, pt.y); | |
7695 | *time = last_mouse_movement_time; | |
7696 | } | |
7697 | } | |
7698 | } | |
7699 | ||
7700 | UNBLOCK_INPUT; | |
7701 | } | |
791f420f | 7702 | |
ee78dc32 GV |
7703 | \f |
7704 | /* Scroll bar support. */ | |
7705 | ||
ec48c3a7 | 7706 | /* Given a window ID, find the struct scroll_bar which manages it. |
ee78dc32 GV |
7707 | This can be called in GC, so we have to make sure to strip off mark |
7708 | bits. */ | |
9ef2e2cf JR |
7709 | |
7710 | static struct scroll_bar * | |
ee78dc32 GV |
7711 | x_window_to_scroll_bar (window_id) |
7712 | Window window_id; | |
7713 | { | |
791f420f | 7714 | Lisp_Object tail; |
ee78dc32 GV |
7715 | |
7716 | for (tail = Vframe_list; | |
7717 | XGCTYPE (tail) == Lisp_Cons; | |
8e713be6 | 7718 | tail = XCDR (tail)) |
ee78dc32 GV |
7719 | { |
7720 | Lisp_Object frame, bar, condemned; | |
7721 | ||
8e713be6 | 7722 | frame = XCAR (tail); |
ee78dc32 GV |
7723 | /* All elements of Vframe_list should be frames. */ |
7724 | if (! GC_FRAMEP (frame)) | |
7725 | abort (); | |
7726 | ||
7727 | /* Scan this frame's scroll bar list for a scroll bar with the | |
7728 | right window ID. */ | |
7729 | condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); | |
7730 | for (bar = FRAME_SCROLL_BARS (XFRAME (frame)); | |
7731 | /* This trick allows us to search both the ordinary and | |
7732 | condemned scroll bar lists with one loop. */ | |
7733 | ! GC_NILP (bar) || (bar = condemned, | |
7734 | condemned = Qnil, | |
7735 | ! GC_NILP (bar)); | |
7736 | bar = XSCROLL_BAR (bar)->next) | |
fbd6baed | 7737 | if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)) == window_id) |
ee78dc32 GV |
7738 | return XSCROLL_BAR (bar); |
7739 | } | |
7740 | ||
7741 | return 0; | |
7742 | } | |
7743 | ||
791f420f JR |
7744 | |
7745 | \f | |
7746 | /* Set the thumb size and position of scroll bar BAR. We are currently | |
7747 | displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
7748 | ||
7749 | static void | |
7750 | w32_set_scroll_bar_thumb (bar, portion, position, whole) | |
7751 | struct scroll_bar *bar; | |
7752 | int portion, position, whole; | |
7753 | { | |
7754 | Window w = SCROLL_BAR_W32_WINDOW (bar); | |
d8e675f5 | 7755 | double range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
791f420f JR |
7756 | int sb_page, sb_pos; |
7757 | BOOL draggingp = !NILP (bar->dragging) ? TRUE : FALSE; | |
7758 | ||
7759 | if (whole) | |
7760 | { | |
7761 | /* Position scroll bar at rock bottom if the bottom of the | |
7762 | buffer is visible. This avoids shinking the thumb away | |
7763 | to nothing if it is held at the bottom of the buffer. */ | |
7764 | if (position + portion >= whole) | |
7765 | { | |
7766 | sb_page = range * (whole - position) / whole | |
7767 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
7768 | sb_pos = range; | |
7769 | } | |
7770 | ||
7771 | sb_page = portion * range / whole + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
7772 | sb_pos = position * range / whole; | |
7773 | } | |
7774 | else | |
7775 | { | |
7776 | sb_page = range; | |
7777 | sb_pos = 0; | |
7778 | } | |
7779 | ||
7780 | BLOCK_INPUT; | |
7781 | ||
7782 | if (pfnSetScrollInfo) | |
7783 | { | |
7784 | SCROLLINFO si; | |
7785 | ||
7786 | si.cbSize = sizeof (si); | |
7787 | /* Only update page size if currently dragging, to reduce | |
7788 | flicker effects. */ | |
7789 | if (draggingp) | |
7790 | si.fMask = SIF_PAGE; | |
7791 | else | |
7792 | si.fMask = SIF_PAGE | SIF_POS; | |
7793 | si.nPage = sb_page; | |
7794 | si.nPos = sb_pos; | |
7795 | ||
7796 | pfnSetScrollInfo (w, SB_CTL, &si, !draggingp); | |
7797 | } | |
7798 | else | |
7799 | SetScrollPos (w, SB_CTL, sb_pos, !draggingp); | |
7800 | ||
7801 | UNBLOCK_INPUT; | |
7802 | } | |
7803 | ||
7804 | \f | |
7805 | /************************************************************************ | |
7806 | Scroll bars, general | |
7807 | ************************************************************************/ | |
7808 | ||
ee78dc32 GV |
7809 | HWND |
7810 | my_create_scrollbar (f, bar) | |
7811 | struct frame * f; | |
7812 | struct scroll_bar * bar; | |
7813 | { | |
689004fa GV |
7814 | return (HWND) SendMessage (FRAME_W32_WINDOW (f), |
7815 | WM_EMACS_CREATESCROLLBAR, (WPARAM) f, | |
7816 | (LPARAM) bar); | |
ee78dc32 GV |
7817 | } |
7818 | ||
52cf03a1 GV |
7819 | //#define ATTACH_THREADS |
7820 | ||
689004fa GV |
7821 | BOOL |
7822 | my_show_window (FRAME_PTR f, HWND hwnd, int how) | |
52cf03a1 GV |
7823 | { |
7824 | #ifndef ATTACH_THREADS | |
689004fa GV |
7825 | return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW, |
7826 | (WPARAM) hwnd, (LPARAM) how); | |
52cf03a1 | 7827 | #else |
689004fa | 7828 | return ShowWindow (hwnd, how); |
52cf03a1 GV |
7829 | #endif |
7830 | } | |
7831 | ||
7832 | void | |
7833 | my_set_window_pos (HWND hwnd, HWND hwndAfter, | |
689004fa | 7834 | int x, int y, int cx, int cy, UINT flags) |
52cf03a1 GV |
7835 | { |
7836 | #ifndef ATTACH_THREADS | |
689004fa GV |
7837 | WINDOWPOS pos; |
7838 | pos.hwndInsertAfter = hwndAfter; | |
52cf03a1 GV |
7839 | pos.x = x; |
7840 | pos.y = y; | |
7841 | pos.cx = cx; | |
7842 | pos.cy = cy; | |
7843 | pos.flags = flags; | |
7844 | SendMessage (hwnd, WM_EMACS_SETWINDOWPOS, (WPARAM) &pos, 0); | |
7845 | #else | |
7846 | SetWindowPos (hwnd, hwndAfter, x, y, cx, cy, flags); | |
7847 | #endif | |
7848 | } | |
7849 | ||
ec48c3a7 | 7850 | void |
689004fa GV |
7851 | my_set_focus (f, hwnd) |
7852 | struct frame * f; | |
7853 | HWND hwnd; | |
7854 | { | |
7855 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SETFOCUS, | |
7856 | (WPARAM) hwnd, 0); | |
7857 | } | |
7858 | ||
ec48c3a7 | 7859 | void |
ef0e360f GV |
7860 | my_set_foreground_window (hwnd) |
7861 | HWND hwnd; | |
7862 | { | |
7863 | SendMessage (hwnd, WM_EMACS_SETFOREGROUND, (WPARAM) hwnd, 0); | |
7864 | } | |
7865 | ||
ee78dc32 GV |
7866 | void |
7867 | my_destroy_window (f, hwnd) | |
7868 | struct frame * f; | |
7869 | HWND hwnd; | |
7870 | { | |
fbd6baed | 7871 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_DESTROYWINDOW, |
ee78dc32 GV |
7872 | (WPARAM) hwnd, 0); |
7873 | } | |
7874 | ||
791f420f JR |
7875 | /* Create a scroll bar and return the scroll bar vector for it. W is |
7876 | the Emacs window on which to create the scroll bar. TOP, LEFT, | |
7877 | WIDTH and HEIGHT are.the pixel coordinates and dimensions of the | |
7878 | scroll bar. */ | |
7879 | ||
ee78dc32 | 7880 | static struct scroll_bar * |
791f420f JR |
7881 | x_scroll_bar_create (w, top, left, width, height) |
7882 | struct window *w; | |
ee78dc32 GV |
7883 | int top, left, width, height; |
7884 | { | |
791f420f JR |
7885 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
7886 | HWND hwnd; | |
ee78dc32 GV |
7887 | struct scroll_bar *bar |
7888 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | |
ee78dc32 GV |
7889 | |
7890 | BLOCK_INPUT; | |
7891 | ||
791f420f | 7892 | XSETWINDOW (bar->window, w); |
ee78dc32 GV |
7893 | XSETINT (bar->top, top); |
7894 | XSETINT (bar->left, left); | |
7895 | XSETINT (bar->width, width); | |
7896 | XSETINT (bar->height, height); | |
7897 | XSETINT (bar->start, 0); | |
7898 | XSETINT (bar->end, 0); | |
7899 | bar->dragging = Qnil; | |
7900 | ||
7901 | /* Requires geometry to be set before call to create the real window */ | |
7902 | ||
7903 | hwnd = my_create_scrollbar (f, bar); | |
7904 | ||
689004fa GV |
7905 | if (pfnSetScrollInfo) |
7906 | { | |
7907 | SCROLLINFO si; | |
7908 | ||
7909 | si.cbSize = sizeof (si); | |
7910 | si.fMask = SIF_ALL; | |
7911 | si.nMin = 0; | |
791f420f JR |
7912 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) |
7913 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
689004fa GV |
7914 | si.nPage = si.nMax; |
7915 | si.nPos = 0; | |
7916 | ||
7917 | pfnSetScrollInfo (hwnd, SB_CTL, &si, FALSE); | |
7918 | } | |
7919 | else | |
7920 | { | |
791f420f JR |
7921 | SetScrollRange (hwnd, SB_CTL, 0, |
7922 | VERTICAL_SCROLL_BAR_TOP_RANGE (f, height), FALSE); | |
689004fa GV |
7923 | SetScrollPos (hwnd, SB_CTL, 0, FALSE); |
7924 | } | |
ee78dc32 | 7925 | |
fbd6baed | 7926 | SET_SCROLL_BAR_W32_WINDOW (bar, hwnd); |
ee78dc32 GV |
7927 | |
7928 | /* Add bar to its frame's list of scroll bars. */ | |
7929 | bar->next = FRAME_SCROLL_BARS (f); | |
7930 | bar->prev = Qnil; | |
7931 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
7932 | if (! NILP (bar->next)) | |
7933 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
7934 | ||
7935 | UNBLOCK_INPUT; | |
7936 | ||
7937 | return bar; | |
7938 | } | |
7939 | ||
ee78dc32 | 7940 | |
791f420f JR |
7941 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to |
7942 | nil. */ | |
ee78dc32 | 7943 | |
ee78dc32 GV |
7944 | static void |
7945 | x_scroll_bar_remove (bar) | |
7946 | struct scroll_bar *bar; | |
7947 | { | |
7948 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
7949 | ||
7950 | BLOCK_INPUT; | |
7951 | ||
7952 | /* Destroy the window. */ | |
fbd6baed | 7953 | my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar)); |
ee78dc32 GV |
7954 | |
7955 | /* Disassociate this scroll bar from its window. */ | |
7956 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | |
7957 | ||
7958 | UNBLOCK_INPUT; | |
7959 | } | |
7960 | ||
7961 | /* Set the handle of the vertical scroll bar for WINDOW to indicate | |
7962 | that we are displaying PORTION characters out of a total of WHOLE | |
7963 | characters, starting at POSITION. If WINDOW has no scroll bar, | |
7964 | create one. */ | |
7965 | static void | |
791f420f JR |
7966 | w32_set_vertical_scroll_bar (w, portion, whole, position) |
7967 | struct window *w; | |
ee78dc32 GV |
7968 | int portion, whole, position; |
7969 | { | |
791f420f | 7970 | struct frame *f = XFRAME (w->frame); |
ee78dc32 | 7971 | struct scroll_bar *bar; |
9ef2e2cf | 7972 | int top, height, left, sb_left, width, sb_width; |
791f420f JR |
7973 | int window_x, window_y, window_width, window_height; |
7974 | ||
7975 | /* Get window dimensions. */ | |
7976 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); | |
7977 | top = window_y; | |
7978 | width = FRAME_SCROLL_BAR_COLS (f) * CANON_X_UNIT (f); | |
7979 | height = window_height; | |
7980 | ||
7981 | /* Compute the left edge of the scroll bar area. */ | |
7982 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
7983 | left = XINT (w->left) + XINT (w->width) - FRAME_SCROLL_BAR_COLS (f); | |
7984 | else | |
7985 | left = XFASTINT (w->left); | |
7986 | left *= CANON_X_UNIT (f); | |
7987 | left += FRAME_INTERNAL_BORDER_WIDTH (f); | |
7988 | ||
7989 | /* Compute the width of the scroll bar which might be less than | |
7990 | the width of the area reserved for the scroll bar. */ | |
7991 | if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0) | |
7992 | sb_width = FRAME_SCROLL_BAR_PIXEL_WIDTH (f); | |
7993 | else | |
7994 | sb_width = width; | |
ee78dc32 | 7995 | |
791f420f JR |
7996 | /* Compute the left edge of the scroll bar. */ |
7997 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
7998 | sb_left = left + width - sb_width - (width - sb_width) / 2; | |
ee78dc32 | 7999 | else |
791f420f JR |
8000 | sb_left = left + (width - sb_width) / 2; |
8001 | ||
8002 | /* Does the scroll bar exist yet? */ | |
8003 | if (NILP (w->vertical_scroll_bar)) | |
ee78dc32 | 8004 | { |
00fe468b | 8005 | HDC hdc; |
791f420f | 8006 | BLOCK_INPUT; |
9f5a911b JR |
8007 | if (width && height) |
8008 | { | |
8009 | hdc = get_frame_dc (f); | |
8010 | w32_clear_area (f, hdc, left, top, width, height); | |
8011 | release_frame_dc (f, hdc); | |
8012 | } | |
791f420f | 8013 | UNBLOCK_INPUT; |
00fe468b | 8014 | |
791f420f | 8015 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); |
ee78dc32 | 8016 | } |
791f420f JR |
8017 | else |
8018 | { | |
8019 | /* It may just need to be moved and resized. */ | |
8020 | HWND hwnd; | |
8021 | ||
8022 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | |
8023 | hwnd = SCROLL_BAR_W32_WINDOW (bar); | |
8024 | ||
8025 | /* If already correctly positioned, do nothing. */ | |
8026 | if ( XINT (bar->left) == sb_left | |
8027 | && XINT (bar->top) == top | |
8028 | && XINT (bar->width) == sb_width | |
8029 | && XINT (bar->height) == height ) | |
8030 | { | |
8031 | /* Redraw after clear_frame. */ | |
8032 | if (!my_show_window (f, hwnd, SW_NORMAL)) | |
8033 | InvalidateRect (hwnd, NULL, FALSE); | |
8034 | } | |
8035 | else | |
8036 | { | |
00fe468b | 8037 | HDC hdc; |
791f420f | 8038 | BLOCK_INPUT; |
9f5a911b JR |
8039 | if (width && height) |
8040 | { | |
8041 | hdc = get_frame_dc (f); | |
8042 | /* Since Windows scroll bars are smaller than the space reserved | |
8043 | for them on the frame, we have to clear "under" them. */ | |
8044 | w32_clear_area (f, hdc, | |
8045 | left, | |
8046 | top, | |
8047 | width, | |
8048 | height); | |
8049 | release_frame_dc (f, hdc); | |
8050 | } | |
791f420f JR |
8051 | /* Make sure scroll bar is "visible" before moving, to ensure the |
8052 | area of the parent window now exposed will be refreshed. */ | |
8053 | my_show_window (f, hwnd, SW_HIDE); | |
9f5a911b JR |
8054 | MoveWindow (hwnd, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, |
8055 | top, sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
8056 | max (height, 1), TRUE); | |
791f420f JR |
8057 | if (pfnSetScrollInfo) |
8058 | { | |
8059 | SCROLLINFO si; | |
ee78dc32 | 8060 | |
791f420f JR |
8061 | si.cbSize = sizeof (si); |
8062 | si.fMask = SIF_RANGE; | |
8063 | si.nMin = 0; | |
8064 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) | |
8065 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
ee78dc32 | 8066 | |
00fe468b | 8067 | pfnSetScrollInfo (hwnd, SB_CTL, &si, FALSE); |
791f420f JR |
8068 | } |
8069 | else | |
00fe468b | 8070 | SetScrollRange (hwnd, SB_CTL, 0, |
791f420f JR |
8071 | VERTICAL_SCROLL_BAR_TOP_RANGE (f, height), FALSE); |
8072 | my_show_window (f, hwnd, SW_NORMAL); | |
8073 | // InvalidateRect (w, NULL, FALSE); | |
8074 | ||
8075 | /* Remember new settings. */ | |
8076 | XSETINT (bar->left, sb_left); | |
8077 | XSETINT (bar->top, top); | |
8078 | XSETINT (bar->width, sb_width); | |
8079 | XSETINT (bar->height, height); | |
8080 | ||
8081 | UNBLOCK_INPUT; | |
8082 | } | |
8083 | } | |
8084 | w32_set_scroll_bar_thumb (bar, portion, position, whole); | |
ee78dc32 | 8085 | |
791f420f | 8086 | XSETVECTOR (w->vertical_scroll_bar, bar); |
ee78dc32 GV |
8087 | } |
8088 | ||
8089 | ||
8090 | /* The following three hooks are used when we're doing a thorough | |
8091 | redisplay of the frame. We don't explicitly know which scroll bars | |
8092 | are going to be deleted, because keeping track of when windows go | |
8093 | away is a real pain - "Can you say set-window-configuration, boys | |
8094 | and girls?" Instead, we just assert at the beginning of redisplay | |
8095 | that *all* scroll bars are to be removed, and then save a scroll bar | |
8096 | from the fiery pit when we actually redisplay its window. */ | |
8097 | ||
8098 | /* Arrange for all scroll bars on FRAME to be removed at the next call | |
8099 | to `*judge_scroll_bars_hook'. A scroll bar may be spared if | |
9ef2e2cf JR |
8100 | `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ |
8101 | ||
ee78dc32 | 8102 | static void |
fbd6baed | 8103 | w32_condemn_scroll_bars (frame) |
ee78dc32 GV |
8104 | FRAME_PTR frame; |
8105 | { | |
ef0e360f GV |
8106 | /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ |
8107 | while (! NILP (FRAME_SCROLL_BARS (frame))) | |
8108 | { | |
8109 | Lisp_Object bar; | |
8110 | bar = FRAME_SCROLL_BARS (frame); | |
8111 | FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next; | |
8112 | XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame); | |
8113 | XSCROLL_BAR (bar)->prev = Qnil; | |
8114 | if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame))) | |
8115 | XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar; | |
8116 | FRAME_CONDEMNED_SCROLL_BARS (frame) = bar; | |
8117 | } | |
ee78dc32 GV |
8118 | } |
8119 | ||
c2cc16fa | 8120 | |
9ef2e2cf | 8121 | /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle. |
ee78dc32 | 8122 | Note that WINDOW isn't necessarily condemned at all. */ |
c2cc16fa | 8123 | |
ee78dc32 | 8124 | static void |
fbd6baed | 8125 | w32_redeem_scroll_bar (window) |
ee78dc32 GV |
8126 | struct window *window; |
8127 | { | |
8128 | struct scroll_bar *bar; | |
c2cc16fa | 8129 | struct frame *f; |
ee78dc32 GV |
8130 | |
8131 | /* We can't redeem this window's scroll bar if it doesn't have one. */ | |
8132 | if (NILP (window->vertical_scroll_bar)) | |
8133 | abort (); | |
8134 | ||
8135 | bar = XSCROLL_BAR (window->vertical_scroll_bar); | |
8136 | ||
ef0e360f | 8137 | /* Unlink it from the condemned list. */ |
c2cc16fa JR |
8138 | f = XFRAME (WINDOW_FRAME (window)); |
8139 | if (NILP (bar->prev)) | |
8140 | { | |
8141 | /* If the prev pointer is nil, it must be the first in one of | |
8142 | the lists. */ | |
8143 | if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar)) | |
8144 | /* It's not condemned. Everything's fine. */ | |
8145 | return; | |
8146 | else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f), | |
8147 | window->vertical_scroll_bar)) | |
8148 | FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next; | |
8149 | else | |
8150 | /* If its prev pointer is nil, it must be at the front of | |
8151 | one or the other! */ | |
8152 | abort (); | |
8153 | } | |
8154 | else | |
8155 | XSCROLL_BAR (bar->prev)->next = bar->next; | |
ef0e360f | 8156 | |
c2cc16fa JR |
8157 | if (! NILP (bar->next)) |
8158 | XSCROLL_BAR (bar->next)->prev = bar->prev; | |
ef0e360f | 8159 | |
c2cc16fa JR |
8160 | bar->next = FRAME_SCROLL_BARS (f); |
8161 | bar->prev = Qnil; | |
8162 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
8163 | if (! NILP (bar->next)) | |
8164 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
ee78dc32 GV |
8165 | } |
8166 | ||
8167 | /* Remove all scroll bars on FRAME that haven't been saved since the | |
8168 | last call to `*condemn_scroll_bars_hook'. */ | |
9ef2e2cf | 8169 | |
ee78dc32 | 8170 | static void |
fbd6baed | 8171 | w32_judge_scroll_bars (f) |
ee78dc32 GV |
8172 | FRAME_PTR f; |
8173 | { | |
8174 | Lisp_Object bar, next; | |
8175 | ||
8176 | bar = FRAME_CONDEMNED_SCROLL_BARS (f); | |
8177 | ||
8178 | /* Clear out the condemned list now so we won't try to process any | |
8179 | more events on the hapless scroll bars. */ | |
8180 | FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil; | |
8181 | ||
8182 | for (; ! NILP (bar); bar = next) | |
8183 | { | |
8184 | struct scroll_bar *b = XSCROLL_BAR (bar); | |
8185 | ||
8186 | x_scroll_bar_remove (b); | |
8187 | ||
8188 | next = b->next; | |
8189 | b->next = b->prev = Qnil; | |
8190 | } | |
8191 | ||
8192 | /* Now there should be no references to the condemned scroll bars, | |
8193 | and they should get garbage-collected. */ | |
8194 | } | |
8195 | ||
8196 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind | |
8197 | is set to something other than no_event, it is enqueued. | |
8198 | ||
8199 | This may be called from a signal handler, so we have to ignore GC | |
8200 | mark bits. */ | |
2c28562d | 8201 | |
52cf03a1 | 8202 | static int |
c2cc16fa | 8203 | w32_scroll_bar_handle_click (bar, msg, emacs_event) |
ee78dc32 | 8204 | struct scroll_bar *bar; |
fbd6baed | 8205 | W32Msg *msg; |
ee78dc32 GV |
8206 | struct input_event *emacs_event; |
8207 | { | |
8208 | if (! GC_WINDOWP (bar->window)) | |
8209 | abort (); | |
8210 | ||
fbd6baed | 8211 | emacs_event->kind = w32_scroll_bar_click; |
ee78dc32 | 8212 | emacs_event->code = 0; |
52cf03a1 GV |
8213 | /* not really meaningful to distinguish up/down */ |
8214 | emacs_event->modifiers = msg->dwModifiers; | |
ee78dc32 | 8215 | emacs_event->frame_or_window = bar->window; |
7e889510 | 8216 | emacs_event->arg = Qnil; |
ee78dc32 GV |
8217 | emacs_event->timestamp = msg->msg.time; |
8218 | ||
8219 | { | |
791f420f | 8220 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
689004fa GV |
8221 | int y; |
8222 | int dragging = !NILP (bar->dragging); | |
8223 | ||
8224 | if (pfnGetScrollInfo) | |
8225 | { | |
8226 | SCROLLINFO si; | |
8227 | ||
8228 | si.cbSize = sizeof (si); | |
8229 | si.fMask = SIF_POS; | |
8230 | ||
8231 | pfnGetScrollInfo ((HWND) msg->msg.lParam, SB_CTL, &si); | |
8232 | y = si.nPos; | |
8233 | } | |
8234 | else | |
8235 | y = GetScrollPos ((HWND) msg->msg.lParam, SB_CTL); | |
8236 | ||
8237 | bar->dragging = Qnil; | |
ee78dc32 | 8238 | |
9ef2e2cf JR |
8239 | |
8240 | last_mouse_scroll_bar_pos = msg->msg.wParam; | |
8241 | ||
ee78dc32 | 8242 | switch (LOWORD (msg->msg.wParam)) |
2c28562d | 8243 | { |
2c28562d | 8244 | case SB_LINEDOWN: |
52cf03a1 | 8245 | emacs_event->part = scroll_bar_down_arrow; |
ee78dc32 | 8246 | break; |
2c28562d | 8247 | case SB_LINEUP: |
52cf03a1 | 8248 | emacs_event->part = scroll_bar_up_arrow; |
ee78dc32 | 8249 | break; |
2c28562d | 8250 | case SB_PAGEUP: |
ee78dc32 GV |
8251 | emacs_event->part = scroll_bar_above_handle; |
8252 | break; | |
2c28562d | 8253 | case SB_PAGEDOWN: |
ee78dc32 GV |
8254 | emacs_event->part = scroll_bar_below_handle; |
8255 | break; | |
2c28562d | 8256 | case SB_TOP: |
ee78dc32 GV |
8257 | emacs_event->part = scroll_bar_handle; |
8258 | y = 0; | |
8259 | break; | |
2c28562d | 8260 | case SB_BOTTOM: |
ee78dc32 GV |
8261 | emacs_event->part = scroll_bar_handle; |
8262 | y = top_range; | |
8263 | break; | |
689004fa | 8264 | case SB_THUMBTRACK: |
2c28562d | 8265 | case SB_THUMBPOSITION: |
791f420f JR |
8266 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
8267 | y = HIWORD (msg->msg.wParam); | |
689004fa | 8268 | bar->dragging = Qt; |
ee78dc32 | 8269 | emacs_event->part = scroll_bar_handle; |
689004fa GV |
8270 | |
8271 | /* "Silently" update current position. */ | |
8272 | if (pfnSetScrollInfo) | |
8273 | { | |
8274 | SCROLLINFO si; | |
8275 | ||
8276 | si.cbSize = sizeof (si); | |
8277 | si.fMask = SIF_POS; | |
689004fa GV |
8278 | si.nPos = y; |
8279 | /* Remember apparent position (we actually lag behind the real | |
8280 | position, so don't set that directly. */ | |
8281 | last_scroll_bar_drag_pos = y; | |
8282 | ||
8283 | pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, FALSE); | |
8284 | } | |
8285 | else | |
8286 | SetScrollPos (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, y, FALSE); | |
ee78dc32 | 8287 | break; |
2c28562d | 8288 | case SB_ENDSCROLL: |
689004fa GV |
8289 | /* If this is the end of a drag sequence, then reset the scroll |
8290 | handle size to normal and do a final redraw. Otherwise do | |
8291 | nothing. */ | |
8292 | if (dragging) | |
8293 | { | |
8294 | if (pfnSetScrollInfo) | |
8295 | { | |
8296 | SCROLLINFO si; | |
8297 | int start = XINT (bar->start); | |
8298 | int end = XINT (bar->end); | |
8299 | ||
8300 | si.cbSize = sizeof (si); | |
8301 | si.fMask = SIF_PAGE | SIF_POS; | |
791f420f | 8302 | si.nPage = end - start + VERTICAL_SCROLL_BAR_MIN_HANDLE; |
689004fa | 8303 | si.nPos = last_scroll_bar_drag_pos; |
689004fa GV |
8304 | pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, TRUE); |
8305 | } | |
8306 | else | |
8307 | SetScrollPos (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, y, TRUE); | |
8308 | } | |
8309 | /* fall through */ | |
2c28562d | 8310 | default: |
689004fa | 8311 | emacs_event->kind = no_event; |
52cf03a1 | 8312 | return FALSE; |
2c28562d | 8313 | } |
52cf03a1 | 8314 | |
ee78dc32 GV |
8315 | XSETINT (emacs_event->x, y); |
8316 | XSETINT (emacs_event->y, top_range); | |
52cf03a1 GV |
8317 | |
8318 | return TRUE; | |
ee78dc32 GV |
8319 | } |
8320 | } | |
8321 | ||
8322 | /* Return information to the user about the current position of the mouse | |
8323 | on the scroll bar. */ | |
9ef2e2cf | 8324 | |
ee78dc32 GV |
8325 | static void |
8326 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) | |
8327 | FRAME_PTR *fp; | |
8328 | Lisp_Object *bar_window; | |
8329 | enum scroll_bar_part *part; | |
8330 | Lisp_Object *x, *y; | |
8331 | unsigned long *time; | |
8332 | { | |
8333 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); | |
fbd6baed | 8334 | Window w = SCROLL_BAR_W32_WINDOW (bar); |
ee78dc32 GV |
8335 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
8336 | int pos; | |
791f420f | 8337 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
ee78dc32 GV |
8338 | |
8339 | BLOCK_INPUT; | |
8340 | ||
8341 | *fp = f; | |
8342 | *bar_window = bar->window; | |
8343 | ||
689004fa GV |
8344 | if (pfnGetScrollInfo) |
8345 | { | |
8346 | SCROLLINFO si; | |
8347 | ||
8348 | si.cbSize = sizeof (si); | |
8349 | si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; | |
8350 | ||
8351 | pfnGetScrollInfo (w, SB_CTL, &si); | |
8352 | pos = si.nPos; | |
8353 | top_range = si.nMax - si.nPage + 1; | |
8354 | } | |
8355 | else | |
8356 | pos = GetScrollPos (w, SB_CTL); | |
ee78dc32 GV |
8357 | |
8358 | switch (LOWORD (last_mouse_scroll_bar_pos)) | |
8359 | { | |
8360 | case SB_THUMBPOSITION: | |
8361 | case SB_THUMBTRACK: | |
8362 | *part = scroll_bar_handle; | |
791f420f | 8363 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
ee78dc32 GV |
8364 | pos = HIWORD (last_mouse_scroll_bar_pos); |
8365 | break; | |
8366 | case SB_LINEDOWN: | |
8367 | *part = scroll_bar_handle; | |
8368 | pos++; | |
8369 | break; | |
8370 | default: | |
8371 | *part = scroll_bar_handle; | |
8372 | break; | |
8373 | } | |
8374 | ||
9127e20e JR |
8375 | XSETINT (*x, pos); |
8376 | XSETINT (*y, top_range); | |
ee78dc32 GV |
8377 | |
8378 | f->mouse_moved = 0; | |
8379 | last_mouse_scroll_bar = Qnil; | |
8380 | ||
8381 | *time = last_mouse_movement_time; | |
8382 | ||
8383 | UNBLOCK_INPUT; | |
8384 | } | |
8385 | ||
9ef2e2cf | 8386 | |
ee78dc32 GV |
8387 | /* The screen has been cleared so we may have changed foreground or |
8388 | background colors, and the scroll bars may need to be redrawn. | |
8389 | Clear out the scroll bars, and ask for expose events, so we can | |
8390 | redraw them. */ | |
9ef2e2cf | 8391 | |
791f420f | 8392 | void |
ee78dc32 | 8393 | x_scroll_bar_clear (f) |
9ef2e2cf | 8394 | FRAME_PTR f; |
ee78dc32 | 8395 | { |
ee78dc32 GV |
8396 | Lisp_Object bar; |
8397 | ||
9ef2e2cf JR |
8398 | /* We can have scroll bars even if this is 0, |
8399 | if we just turned off scroll bar mode. | |
8400 | But in that case we should not clear them. */ | |
8401 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
8402 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
8403 | bar = XSCROLL_BAR (bar)->next) | |
8404 | { | |
8405 | HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)); | |
8406 | HDC hdc = GetDC (window); | |
8407 | RECT rect; | |
52cf03a1 | 8408 | |
9ef2e2cf JR |
8409 | /* Hide scroll bar until ready to repaint. x_scroll_bar_move |
8410 | arranges to refresh the scroll bar if hidden. */ | |
8411 | my_show_window (f, window, SW_HIDE); | |
689004fa | 8412 | |
9ef2e2cf JR |
8413 | GetClientRect (window, &rect); |
8414 | select_palette (f, hdc); | |
8415 | w32_clear_rect (f, hdc, &rect); | |
8416 | deselect_palette (f, hdc); | |
689004fa | 8417 | |
9ef2e2cf JR |
8418 | ReleaseDC (window, hdc); |
8419 | } | |
52cf03a1 GV |
8420 | } |
8421 | ||
ee78dc32 | 8422 | \f |
fbd6baed | 8423 | /* The main W32 event-reading loop - w32_read_socket. */ |
ee78dc32 | 8424 | |
9ef2e2cf | 8425 | /* Time stamp of enter window event. This is only used by w32_read_socket, |
ee78dc32 GV |
8426 | but we have to put it out here, since static variables within functions |
8427 | sometimes don't work. */ | |
9ef2e2cf | 8428 | |
ee78dc32 GV |
8429 | static Time enter_timestamp; |
8430 | ||
8431 | /* Record the last 100 characters stored | |
8432 | to help debug the loss-of-chars-during-GC problem. */ | |
9ef2e2cf JR |
8433 | |
8434 | static int temp_index; | |
8435 | static short temp_buffer[100]; | |
ee78dc32 | 8436 | |
afd153f0 | 8437 | |
fbd6baed | 8438 | /* Read events coming from the W32 shell. |
ee78dc32 GV |
8439 | This routine is called by the SIGIO handler. |
8440 | We return as soon as there are no more events to be read. | |
8441 | ||
8442 | Events representing keys are stored in buffer BUFP, | |
8443 | which can hold up to NUMCHARS characters. | |
8444 | We return the number of characters stored into the buffer, | |
8445 | thus pretending to be `read'. | |
8446 | ||
ee78dc32 GV |
8447 | EXPECTED is nonzero if the caller knows input is available. |
8448 | ||
8449 | Some of these messages are reposted back to the message queue since the | |
e9e23e23 GV |
8450 | system calls the windows proc directly in a context where we cannot return |
8451 | the data nor can we guarantee the state we are in. So if we dispatch them | |
ee78dc32 GV |
8452 | we will get into an infinite loop. To prevent this from ever happening we |
8453 | will set a variable to indicate we are in the read_socket call and indicate | |
e9e23e23 GV |
8454 | which message we are processing since the windows proc gets called |
8455 | recursively with different messages by the system. | |
ee78dc32 GV |
8456 | */ |
8457 | ||
8458 | int | |
3aad7613 | 8459 | w32_read_socket (sd, bufp, numchars, expected) |
ee78dc32 | 8460 | register int sd; |
9ef2e2cf JR |
8461 | /* register */ struct input_event *bufp; |
8462 | /* register */ int numchars; | |
ee78dc32 GV |
8463 | int expected; |
8464 | { | |
8465 | int count = 0; | |
689004fa | 8466 | int check_visibility = 0; |
fbd6baed | 8467 | W32Msg msg; |
ee78dc32 | 8468 | struct frame *f; |
fbd6baed | 8469 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
ee78dc32 GV |
8470 | |
8471 | if (interrupt_input_blocked) | |
8472 | { | |
8473 | interrupt_input_pending = 1; | |
8474 | return -1; | |
8475 | } | |
8476 | ||
8477 | interrupt_input_pending = 0; | |
8478 | BLOCK_INPUT; | |
8479 | ||
8480 | /* So people can tell when we have read the available input. */ | |
8481 | input_signal_count++; | |
8482 | ||
8483 | if (numchars <= 0) | |
8484 | abort (); /* Don't think this happens. */ | |
8485 | ||
01b220b6 | 8486 | /* TODO: tooltips, tool-bars, ghostscript integration, mouse |
791f420f | 8487 | cursors. */ |
52cf03a1 | 8488 | while (get_next_msg (&msg, FALSE)) |
ee78dc32 GV |
8489 | { |
8490 | switch (msg.msg.message) | |
8491 | { | |
ee78dc32 | 8492 | case WM_PAINT: |
9f5a911b | 8493 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); |
ee78dc32 | 8494 | |
9f5a911b JR |
8495 | if (f) |
8496 | { | |
8497 | if (msg.rect.right == msg.rect.left || | |
8498 | msg.rect.bottom == msg.rect.top) | |
8499 | { | |
8500 | /* We may get paint messages even though the client | |
8501 | area is clipped - these are not expose events. */ | |
8502 | DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f, | |
8503 | XSTRING (f->name)->data)); | |
8504 | } | |
8505 | else if (f->async_visible != 1) | |
8506 | { | |
8507 | /* Definitely not obscured, so mark as visible. */ | |
8508 | f->async_visible = 1; | |
8509 | f->async_iconified = 0; | |
8510 | SET_FRAME_GARBAGED (f); | |
8511 | DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f, | |
8512 | XSTRING (f->name)->data)); | |
8513 | ||
8514 | /* WM_PAINT serves as MapNotify as well, so report | |
8515 | visibility changes properly. */ | |
8516 | if (f->iconified) | |
8517 | { | |
8518 | bufp->kind = deiconify_event; | |
8519 | XSETFRAME (bufp->frame_or_window, f); | |
8520 | bufp->arg = Qnil; | |
8521 | bufp++; | |
8522 | count++; | |
8523 | numchars--; | |
8524 | } | |
8525 | else if (! NILP (Vframe_list) | |
8526 | && ! NILP (XCDR (Vframe_list))) | |
8527 | /* Force a redisplay sooner or later to update the | |
8528 | frame titles in case this is the second frame. */ | |
8529 | record_asynch_buffer_change (); | |
8530 | } | |
8531 | else | |
8532 | { | |
8533 | HDC hdc = get_frame_dc (f); | |
8534 | ||
8535 | /* Erase background again for safety. */ | |
8536 | w32_clear_rect (f, hdc, &msg.rect); | |
8537 | release_frame_dc (f, hdc); | |
8538 | expose_frame (f, | |
8539 | msg.rect.left, | |
8540 | msg.rect.top, | |
8541 | msg.rect.right - msg.rect.left, | |
8542 | msg.rect.bottom - msg.rect.top); | |
8543 | } | |
8544 | } | |
52cf03a1 | 8545 | break; |
689004fa | 8546 | |
f98169a0 GV |
8547 | case WM_INPUTLANGCHANGE: |
8548 | /* Generate a language change event. */ | |
8549 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8550 | ||
8551 | if (f) | |
8552 | { | |
8553 | if (numchars == 0) | |
8554 | abort (); | |
8555 | ||
8556 | bufp->kind = language_change_event; | |
8557 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8558 | bufp->arg = Qnil; |
f98169a0 GV |
8559 | bufp->code = msg.msg.wParam; |
8560 | bufp->modifiers = msg.msg.lParam & 0xffff; | |
8561 | bufp++; | |
8562 | count++; | |
8563 | numchars--; | |
8564 | } | |
8565 | break; | |
8566 | ||
ee78dc32 GV |
8567 | case WM_KEYDOWN: |
8568 | case WM_SYSKEYDOWN: | |
8569 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8570 | ||
8571 | if (f && !f->iconified) | |
8572 | { | |
8573 | if (temp_index == sizeof temp_buffer / sizeof (short)) | |
8574 | temp_index = 0; | |
8575 | temp_buffer[temp_index++] = msg.msg.wParam; | |
8576 | bufp->kind = non_ascii_keystroke; | |
8577 | bufp->code = msg.msg.wParam; | |
f98169a0 | 8578 | bufp->modifiers = msg.dwModifiers; |
ee78dc32 | 8579 | XSETFRAME (bufp->frame_or_window, f); |
7e889510 | 8580 | bufp->arg = Qnil; |
ee78dc32 GV |
8581 | bufp->timestamp = msg.msg.time; |
8582 | bufp++; | |
8583 | numchars--; | |
8584 | count++; | |
8585 | } | |
8586 | break; | |
689004fa | 8587 | |
ee78dc32 GV |
8588 | case WM_SYSCHAR: |
8589 | case WM_CHAR: | |
8590 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8591 | ||
8592 | if (f && !f->iconified) | |
8593 | { | |
f98169a0 GV |
8594 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
8595 | temp_index = 0; | |
8596 | temp_buffer[temp_index++] = msg.msg.wParam; | |
8597 | bufp->kind = ascii_keystroke; | |
8598 | bufp->code = msg.msg.wParam; | |
8599 | bufp->modifiers = msg.dwModifiers; | |
8600 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8601 | bufp->arg = Qnil; |
f98169a0 GV |
8602 | bufp->timestamp = msg.msg.time; |
8603 | bufp++; | |
8604 | numchars--; | |
8605 | count++; | |
ee78dc32 GV |
8606 | } |
8607 | break; | |
689004fa | 8608 | |
ee78dc32 | 8609 | case WM_MOUSEMOVE: |
791f420f | 8610 | previous_help_echo = help_echo; |
9f5a911b | 8611 | help_echo_object = help_echo_window = Qnil; |
158cba56 | 8612 | help_echo_pos = -1; |
791f420f | 8613 | |
ee78dc32 GV |
8614 | if (dpyinfo->grabbed && last_mouse_frame |
8615 | && FRAME_LIVE_P (last_mouse_frame)) | |
8616 | f = last_mouse_frame; | |
8617 | else | |
8618 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8619 | ||
8620 | if (f) | |
8621 | note_mouse_movement (f, &msg.msg); | |
8622 | else | |
791f420f JR |
8623 | { |
8624 | /* If we move outside the frame, then we're | |
8625 | certainly no longer on any text in the frame. */ | |
5b844253 | 8626 | clear_mouse_face (dpyinfo); |
791f420f JR |
8627 | } |
8628 | ||
8629 | /* If the contents of the global variable help_echo | |
8630 | has changed, generate a HELP_EVENT. */ | |
9f5a911b | 8631 | if (help_echo != previous_help_echo) |
791f420f JR |
8632 | { |
8633 | Lisp_Object frame; | |
ec48c3a7 | 8634 | int n; |
791f420f JR |
8635 | |
8636 | if (f) | |
8637 | XSETFRAME (frame, f); | |
8638 | else | |
8639 | frame = Qnil; | |
8640 | ||
8641 | any_help_event_p = 1; | |
b4165314 GM |
8642 | n = gen_help_event (bufp, numchars, help_echo, frame, |
8643 | help_echo_window, help_echo_object, | |
8644 | help_echo_pos); | |
ec48c3a7 | 8645 | bufp += n, count += n, numchars -= n; |
791f420f JR |
8646 | } |
8647 | break; | |
689004fa | 8648 | |
ee78dc32 GV |
8649 | case WM_LBUTTONDOWN: |
8650 | case WM_LBUTTONUP: | |
8651 | case WM_MBUTTONDOWN: | |
8652 | case WM_MBUTTONUP: | |
8653 | case WM_RBUTTONDOWN: | |
8654 | case WM_RBUTTONUP: | |
8655 | { | |
791f420f JR |
8656 | /* If we decide we want to generate an event to be seen |
8657 | by the rest of Emacs, we put it here. */ | |
8658 | struct input_event emacs_event; | |
8659 | int tool_bar_p = 0; | |
ee78dc32 GV |
8660 | int button; |
8661 | int up; | |
791f420f JR |
8662 | |
8663 | emacs_event.kind = no_event; | |
ee78dc32 GV |
8664 | |
8665 | if (dpyinfo->grabbed && last_mouse_frame | |
8666 | && FRAME_LIVE_P (last_mouse_frame)) | |
8667 | f = last_mouse_frame; | |
8668 | else | |
8669 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8670 | ||
8671 | if (f) | |
8672 | { | |
791f420f JR |
8673 | construct_mouse_click (&emacs_event, &msg, f); |
8674 | ||
8675 | /* Is this in the tool-bar? */ | |
8676 | if (WINDOWP (f->tool_bar_window) | |
8677 | && XFASTINT (XWINDOW (f->tool_bar_window)->height)) | |
8678 | { | |
8679 | Lisp_Object window; | |
d6ff54d5 | 8680 | int p; |
791f420f JR |
8681 | |
8682 | /* Set x and y. */ | |
8683 | window = window_from_coordinates (f, | |
8684 | emacs_event.x, | |
8685 | emacs_event.y, | |
8686 | &p, 1); | |
8687 | if (EQ (window, f->tool_bar_window)) | |
8688 | { | |
8689 | w32_handle_tool_bar_click (f, &emacs_event); | |
8690 | tool_bar_p = 1; | |
8691 | } | |
8692 | } | |
8693 | ||
8694 | if (!tool_bar_p) | |
8695 | if (!dpyinfo->w32_focus_frame | |
8696 | || f == dpyinfo->w32_focus_frame | |
8697 | && (numchars >= 1)) | |
8698 | { | |
8699 | construct_mouse_click (bufp, &msg, f); | |
8700 | bufp++; | |
8701 | count++; | |
8702 | numchars--; | |
8703 | } | |
ee78dc32 GV |
8704 | } |
8705 | ||
8706 | parse_button (msg.msg.message, &button, &up); | |
8707 | ||
8708 | if (up) | |
8709 | { | |
8710 | dpyinfo->grabbed &= ~ (1 << button); | |
8711 | } | |
8712 | else | |
8713 | { | |
8714 | dpyinfo->grabbed |= (1 << button); | |
8715 | last_mouse_frame = f; | |
791f420f JR |
8716 | /* Ignore any mouse motion that happened |
8717 | before this event; any subsequent mouse-movement | |
8718 | Emacs events should reflect only motion after | |
8719 | the ButtonPress. */ | |
8720 | if (f != 0) | |
8721 | f->mouse_moved = 0; | |
8722 | ||
8723 | if (!tool_bar_p) | |
8724 | last_tool_bar_item = -1; | |
ee78dc32 | 8725 | } |
689004fa | 8726 | break; |
ee78dc32 GV |
8727 | } |
8728 | ||
689004fa GV |
8729 | case WM_MOUSEWHEEL: |
8730 | if (dpyinfo->grabbed && last_mouse_frame | |
8731 | && FRAME_LIVE_P (last_mouse_frame)) | |
8732 | f = last_mouse_frame; | |
8733 | else | |
8734 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8735 | ||
8736 | if (f) | |
8737 | { | |
8738 | if ((!dpyinfo->w32_focus_frame | |
8739 | || f == dpyinfo->w32_focus_frame) | |
8740 | && (numchars >= 1)) | |
8741 | { | |
8742 | construct_mouse_wheel (bufp, &msg, f); | |
8743 | bufp++; | |
8744 | count++; | |
8745 | numchars--; | |
8746 | } | |
8747 | } | |
ee78dc32 | 8748 | break; |
689004fa | 8749 | |
93ff4395 JR |
8750 | case WM_MENUSELECT: |
8751 | { | |
8752 | HMENU menu = (HMENU) msg.msg.lParam; | |
8753 | UINT menu_item = (UINT) LOWORD (msg.msg.wParam); | |
8754 | UINT flags = (UINT) HIWORD (msg.msg.wParam); | |
9ef2e2cf | 8755 | |
93ff4395 JR |
8756 | w32_menu_display_help (menu, menu_item, flags); |
8757 | } | |
8758 | break; | |
8759 | ||
12857dfd RS |
8760 | case WM_DROPFILES: |
8761 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8762 | ||
8763 | if (f) | |
8764 | { | |
8765 | construct_drag_n_drop (bufp, &msg, f); | |
8766 | bufp++; | |
8767 | count++; | |
8768 | numchars--; | |
8769 | } | |
8770 | break; | |
8771 | ||
ee78dc32 GV |
8772 | case WM_VSCROLL: |
8773 | { | |
689004fa GV |
8774 | struct scroll_bar *bar = |
8775 | x_window_to_scroll_bar ((HWND)msg.msg.lParam); | |
ee78dc32 GV |
8776 | |
8777 | if (bar && numchars >= 1) | |
8778 | { | |
c2cc16fa | 8779 | if (w32_scroll_bar_handle_click (bar, &msg, bufp)) |
52cf03a1 GV |
8780 | { |
8781 | bufp++; | |
8782 | count++; | |
8783 | numchars--; | |
8784 | } | |
ee78dc32 | 8785 | } |
689004fa | 8786 | break; |
ee78dc32 GV |
8787 | } |
8788 | ||
689004fa GV |
8789 | case WM_WINDOWPOSCHANGED: |
8790 | case WM_ACTIVATE: | |
8791 | case WM_ACTIVATEAPP: | |
8792 | check_visibility = 1; | |
ee78dc32 | 8793 | break; |
689004fa | 8794 | |
ee78dc32 GV |
8795 | case WM_MOVE: |
8796 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8797 | ||
8798 | if (f && !f->async_iconified) | |
8799 | { | |
689004fa GV |
8800 | int x, y; |
8801 | ||
8802 | x_real_positions (f, &x, &y); | |
8803 | f->output_data.w32->left_pos = x; | |
8804 | f->output_data.w32->top_pos = y; | |
ee78dc32 | 8805 | } |
689004fa GV |
8806 | |
8807 | check_visibility = 1; | |
8808 | break; | |
8809 | ||
8810 | case WM_SHOWWINDOW: | |
8811 | /* If window has been obscured or exposed by another window | |
8812 | being maximised or minimised/restored, then recheck | |
8813 | visibility of all frames. Direct changes to our own | |
8814 | windows get handled by WM_SIZE. */ | |
8815 | #if 0 | |
8816 | if (msg.msg.lParam != 0) | |
8817 | check_visibility = 1; | |
8818 | else | |
8819 | { | |
8820 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8821 | f->async_visible = msg.msg.wParam; | |
8822 | } | |
8823 | #endif | |
8824 | ||
8825 | check_visibility = 1; | |
ee78dc32 | 8826 | break; |
689004fa | 8827 | |
ee78dc32 GV |
8828 | case WM_SIZE: |
8829 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8830 | ||
689004fa GV |
8831 | /* Inform lisp of whether frame has been iconified etc. */ |
8832 | if (f) | |
ee78dc32 | 8833 | { |
689004fa | 8834 | switch (msg.msg.wParam) |
ee78dc32 | 8835 | { |
689004fa GV |
8836 | case SIZE_MINIMIZED: |
8837 | f->async_visible = 0; | |
ee78dc32 GV |
8838 | f->async_iconified = 1; |
8839 | ||
8840 | bufp->kind = iconify_event; | |
8841 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8842 | bufp->arg = Qnil; |
ee78dc32 GV |
8843 | bufp++; |
8844 | count++; | |
8845 | numchars--; | |
689004fa GV |
8846 | break; |
8847 | ||
8848 | case SIZE_MAXIMIZED: | |
8849 | case SIZE_RESTORED: | |
ee78dc32 GV |
8850 | f->async_visible = 1; |
8851 | f->async_iconified = 0; | |
8852 | ||
8853 | /* wait_reading_process_input will notice this and update | |
8854 | the frame's display structures. */ | |
8855 | SET_FRAME_GARBAGED (f); | |
8856 | ||
8857 | if (f->iconified) | |
8858 | { | |
31d4844a KH |
8859 | int x, y; |
8860 | ||
8861 | /* Reset top and left positions of the Window | |
8862 | here since Windows sends a WM_MOVE message | |
8863 | BEFORE telling us the Window is minimized | |
8864 | when the Window is iconified, with 3000,3000 | |
8865 | as the co-ords. */ | |
8866 | x_real_positions (f, &x, &y); | |
8867 | f->output_data.w32->left_pos = x; | |
8868 | f->output_data.w32->top_pos = y; | |
8869 | ||
ee78dc32 GV |
8870 | bufp->kind = deiconify_event; |
8871 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8872 | bufp->arg = Qnil; |
ee78dc32 GV |
8873 | bufp++; |
8874 | count++; | |
8875 | numchars--; | |
8876 | } | |
9ef2e2cf JR |
8877 | else if (! NILP (Vframe_list) |
8878 | && ! NILP (XCDR (Vframe_list))) | |
ee78dc32 GV |
8879 | /* Force a redisplay sooner or later |
8880 | to update the frame titles | |
8881 | in case this is the second frame. */ | |
8882 | record_asynch_buffer_change (); | |
689004fa | 8883 | break; |
ee78dc32 | 8884 | } |
ee78dc32 | 8885 | } |
689004fa | 8886 | |
ef0e360f GV |
8887 | if (f && !f->async_iconified && msg.msg.wParam != SIZE_MINIMIZED) |
8888 | { | |
8889 | RECT rect; | |
8890 | int rows; | |
8891 | int columns; | |
8892 | int width; | |
8893 | int height; | |
8894 | ||
9127e20e | 8895 | GetClientRect (msg.msg.hwnd, &rect); |
ef0e360f GV |
8896 | |
8897 | height = rect.bottom - rect.top; | |
8898 | width = rect.right - rect.left; | |
8899 | ||
8900 | rows = PIXEL_TO_CHAR_HEIGHT (f, height); | |
8901 | columns = PIXEL_TO_CHAR_WIDTH (f, width); | |
8902 | ||
8903 | /* TODO: Clip size to the screen dimensions. */ | |
8904 | ||
8905 | /* Even if the number of character rows and columns has | |
8906 | not changed, the font size may have changed, so we need | |
8907 | to check the pixel dimensions as well. */ | |
8908 | ||
8909 | if (columns != f->width | |
8910 | || rows != f->height | |
8911 | || width != f->output_data.w32->pixel_width | |
8912 | || height != f->output_data.w32->pixel_height) | |
8913 | { | |
791f420f | 8914 | change_frame_size (f, rows, columns, 0, 1, 0); |
ef0e360f | 8915 | SET_FRAME_GARBAGED (f); |
31d4844a | 8916 | cancel_mouse_face (f); |
ef0e360f GV |
8917 | f->output_data.w32->pixel_width = width; |
8918 | f->output_data.w32->pixel_height = height; | |
8919 | f->output_data.w32->win_gravity = NorthWestGravity; | |
8920 | } | |
8921 | } | |
8922 | ||
689004fa GV |
8923 | check_visibility = 1; |
8924 | break; | |
8925 | ||
8926 | case WM_SETFOCUS: | |
791f420f JR |
8927 | f = x_any_window_to_frame (dpyinfo, msg.msg.hwnd); |
8928 | ||
8929 | dpyinfo->w32_focus_event_frame = f; | |
8930 | ||
8931 | if (f) | |
8932 | x_new_focus_frame (dpyinfo, f); | |
8933 | ||
8934 | ||
8935 | dpyinfo->grabbed = 0; | |
8936 | check_visibility = 1; | |
8937 | break; | |
8938 | ||
689004fa | 8939 | case WM_KILLFOCUS: |
01b220b6 | 8940 | /* TODO: some of this belongs in MOUSE_LEAVE */ |
791f420f | 8941 | f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd); |
08712a41 | 8942 | |
791f420f JR |
8943 | if (f) |
8944 | { | |
791f420f JR |
8945 | if (f == dpyinfo->w32_focus_event_frame) |
8946 | dpyinfo->w32_focus_event_frame = 0; | |
8947 | ||
8948 | if (f == dpyinfo->w32_focus_frame) | |
8949 | x_new_focus_frame (dpyinfo, 0); | |
8950 | ||
8951 | if (f == dpyinfo->mouse_face_mouse_frame) | |
8952 | { | |
8953 | /* If we move outside the frame, then we're | |
8954 | certainly no longer on any text in the frame. */ | |
8955 | clear_mouse_face (dpyinfo); | |
8956 | dpyinfo->mouse_face_mouse_frame = 0; | |
8957 | } | |
9ef2e2cf | 8958 | |
791f420f JR |
8959 | /* Generate a nil HELP_EVENT to cancel a help-echo. |
8960 | Do it only if there's something to cancel. | |
8961 | Otherwise, the startup message is cleared when | |
8962 | the mouse leaves the frame. */ | |
8963 | if (any_help_event_p) | |
8964 | { | |
c2cc16fa | 8965 | Lisp_Object frame; |
ec48c3a7 JR |
8966 | int n; |
8967 | ||
791f420f | 8968 | XSETFRAME (frame, f); |
c2cc16fa JR |
8969 | help_echo = Qnil; |
8970 | n = gen_help_event (bufp, numchars, | |
8971 | Qnil, frame, Qnil, Qnil, 0); | |
ec48c3a7 | 8972 | bufp += n, count += n, numchars -=n; |
791f420f JR |
8973 | } |
8974 | } | |
689004fa | 8975 | |
08712a41 | 8976 | dpyinfo->grabbed = 0; |
689004fa | 8977 | check_visibility = 1; |
ee78dc32 | 8978 | break; |
689004fa | 8979 | |
ee78dc32 GV |
8980 | case WM_CLOSE: |
8981 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8982 | ||
8983 | if (f) | |
8984 | { | |
8985 | if (numchars == 0) | |
8986 | abort (); | |
8987 | ||
8988 | bufp->kind = delete_window_event; | |
8989 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8990 | bufp->arg = Qnil; |
ee78dc32 GV |
8991 | bufp++; |
8992 | count++; | |
8993 | numchars--; | |
8994 | } | |
689004fa GV |
8995 | break; |
8996 | ||
8997 | case WM_INITMENU: | |
8998 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8999 | ||
9000 | if (f) | |
9001 | { | |
9002 | if (numchars == 0) | |
9003 | abort (); | |
ee78dc32 | 9004 | |
689004fa GV |
9005 | bufp->kind = menu_bar_activate_event; |
9006 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 9007 | bufp->arg = Qnil; |
689004fa GV |
9008 | bufp++; |
9009 | count++; | |
9010 | numchars--; | |
9011 | } | |
ee78dc32 | 9012 | break; |
689004fa | 9013 | |
ee78dc32 GV |
9014 | case WM_COMMAND: |
9015 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
014b6ea1 | 9016 | |
ee78dc32 GV |
9017 | if (f) |
9018 | { | |
f98169a0 GV |
9019 | extern void menubar_selection_callback |
9020 | (FRAME_PTR f, void * client_data); | |
014b6ea1 | 9021 | menubar_selection_callback (f, (void *)msg.msg.wParam); |
ee78dc32 | 9022 | } |
689004fa GV |
9023 | |
9024 | check_visibility = 1; | |
9025 | break; | |
9026 | ||
9027 | case WM_DISPLAYCHANGE: | |
9028 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
9029 | ||
9030 | if (f) | |
9031 | { | |
9032 | dpyinfo->width = (short) LOWORD (msg.msg.lParam); | |
9033 | dpyinfo->height = (short) HIWORD (msg.msg.lParam); | |
9034 | dpyinfo->n_cbits = msg.msg.wParam; | |
9035 | DebPrint (("display change: %d %d\n", dpyinfo->width, | |
9036 | dpyinfo->height)); | |
9037 | } | |
9038 | ||
9039 | check_visibility = 1; | |
ee78dc32 | 9040 | break; |
e7efd97e GV |
9041 | |
9042 | default: | |
9043 | /* Check for messages registered at runtime. */ | |
9044 | if (msg.msg.message == msh_mousewheel) | |
9045 | { | |
9046 | if (dpyinfo->grabbed && last_mouse_frame | |
9047 | && FRAME_LIVE_P (last_mouse_frame)) | |
9048 | f = last_mouse_frame; | |
9049 | else | |
9050 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
9051 | ||
9052 | if (f) | |
9053 | { | |
9054 | if ((!dpyinfo->w32_focus_frame | |
9055 | || f == dpyinfo->w32_focus_frame) | |
9056 | && (numchars >= 1)) | |
9057 | { | |
9058 | construct_mouse_wheel (bufp, &msg, f); | |
9059 | bufp++; | |
9060 | count++; | |
9061 | numchars--; | |
9062 | } | |
9063 | } | |
9064 | } | |
9065 | break; | |
ee78dc32 GV |
9066 | } |
9067 | } | |
9068 | ||
9069 | /* If the focus was just given to an autoraising frame, | |
9070 | raise it now. */ | |
9071 | /* ??? This ought to be able to handle more than one such frame. */ | |
9072 | if (pending_autoraise_frame) | |
9073 | { | |
9074 | x_raise_frame (pending_autoraise_frame); | |
9075 | pending_autoraise_frame = 0; | |
9076 | } | |
9077 | ||
689004fa GV |
9078 | /* Check which frames are still visisble, if we have enqueued any user |
9079 | events or been notified of events that may affect visibility. We | |
9080 | do this here because there doesn't seem to be any direct | |
9081 | notification from Windows that the visibility of a window has | |
9082 | changed (at least, not in all cases). */ | |
9083 | if (count > 0 || check_visibility) | |
9084 | { | |
9085 | Lisp_Object tail, frame; | |
9086 | ||
9087 | FOR_EACH_FRAME (tail, frame) | |
9088 | { | |
9089 | FRAME_PTR f = XFRAME (frame); | |
9090 | /* Check "visible" frames and mark each as obscured or not. | |
9091 | Note that async_visible is nonzero for unobscured and | |
9092 | obscured frames, but zero for hidden and iconified frames. */ | |
9093 | if (FRAME_W32_P (f) && f->async_visible) | |
9094 | { | |
9095 | RECT clipbox; | |
66e5868a AI |
9096 | HDC hdc; |
9097 | ||
9098 | enter_crit (); | |
9099 | /* Query clipping rectangle for the entire window area | |
9100 | (GetWindowDC), not just the client portion (GetDC). | |
9101 | Otherwise, the scrollbars and menubar aren't counted as | |
9102 | part of the visible area of the frame, and we may think | |
9103 | the frame is obscured when really a scrollbar is still | |
9104 | visible and gets WM_PAINT messages above. */ | |
9105 | hdc = GetWindowDC (FRAME_W32_WINDOW (f)); | |
689004fa | 9106 | GetClipBox (hdc, &clipbox); |
66e5868a AI |
9107 | ReleaseDC (FRAME_W32_WINDOW (f), hdc); |
9108 | leave_crit (); | |
689004fa GV |
9109 | |
9110 | if (clipbox.right == clipbox.left | |
9111 | || clipbox.bottom == clipbox.top) | |
9112 | { | |
9113 | /* Frame has become completely obscured so mark as | |
9114 | such (we do this by setting async_visible to 2 so | |
9115 | that FRAME_VISIBLE_P is still true, but redisplay | |
9116 | will skip it). */ | |
9117 | f->async_visible = 2; | |
9118 | ||
9119 | if (!FRAME_OBSCURED_P (f)) | |
9120 | { | |
8f860180 | 9121 | DebPrint (("frame %p (%s) obscured\n", f, |
689004fa GV |
9122 | XSTRING (f->name)->data)); |
9123 | } | |
9124 | } | |
9125 | else | |
9126 | { | |
9127 | /* Frame is not obscured, so mark it as such. */ | |
9128 | f->async_visible = 1; | |
9129 | ||
9130 | if (FRAME_OBSCURED_P (f)) | |
9131 | { | |
9132 | SET_FRAME_GARBAGED (f); | |
8f860180 | 9133 | DebPrint (("obscured frame %p (%s) found to be visible\n", f, |
689004fa GV |
9134 | XSTRING (f->name)->data)); |
9135 | ||
9136 | /* Force a redisplay sooner or later. */ | |
9137 | record_asynch_buffer_change (); | |
9138 | } | |
9139 | } | |
9140 | } | |
9141 | } | |
9142 | } | |
9143 | ||
ee78dc32 GV |
9144 | UNBLOCK_INPUT; |
9145 | return count; | |
9146 | } | |
791f420f | 9147 | |
9ef2e2cf JR |
9148 | |
9149 | ||
ee78dc32 | 9150 | \f |
791f420f JR |
9151 | /*********************************************************************** |
9152 | Text Cursor | |
9153 | ***********************************************************************/ | |
9154 | ||
9155 | /* Note if the text cursor of window W has been overwritten by a | |
9156 | drawing operation that outputs N glyphs starting at HPOS in the | |
9157 | line given by output_cursor.vpos. N < 0 means all the rest of the | |
9158 | line after HPOS has been written. */ | |
9159 | ||
9160 | static void | |
9161 | note_overwritten_text_cursor (w, hpos, n) | |
9162 | struct window *w; | |
9163 | int hpos, n; | |
9164 | { | |
9165 | if (updated_area == TEXT_AREA | |
9166 | && output_cursor.vpos == w->phys_cursor.vpos | |
9167 | && hpos <= w->phys_cursor.hpos | |
9168 | && (n < 0 | |
9169 | || hpos + n > w->phys_cursor.hpos)) | |
9170 | w->phys_cursor_on_p = 0; | |
9171 | } | |
9172 | ||
ee78dc32 | 9173 | |
791f420f JR |
9174 | /* Set clipping for output in glyph row ROW. W is the window in which |
9175 | we operate. GC is the graphics context to set clipping in. | |
9176 | WHOLE_LINE_P non-zero means include the areas used for truncation | |
9177 | mark display and alike in the clipping rectangle. | |
ee78dc32 | 9178 | |
791f420f JR |
9179 | ROW may be a text row or, e.g., a mode line. Text rows must be |
9180 | clipped to the interior of the window dedicated to text display, | |
9181 | mode lines must be clipped to the whole window. */ | |
ee78dc32 GV |
9182 | |
9183 | static void | |
791f420f JR |
9184 | w32_clip_to_row (w, row, hdc, whole_line_p) |
9185 | struct window *w; | |
9186 | struct glyph_row *row; | |
9187 | HDC hdc; | |
9188 | int whole_line_p; | |
ee78dc32 | 9189 | { |
791f420f JR |
9190 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
9191 | RECT clip_rect; | |
9192 | int window_x, window_y, window_width, window_height; | |
52cf03a1 | 9193 | |
791f420f | 9194 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); |
52cf03a1 | 9195 | |
791f420f JR |
9196 | clip_rect.left = WINDOW_TO_FRAME_PIXEL_X (w, 0); |
9197 | clip_rect.top = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
9198 | clip_rect.top = max (clip_rect.top, window_y); | |
9199 | clip_rect.right = clip_rect.left + window_width; | |
9200 | clip_rect.bottom = clip_rect.top + row->visible_height; | |
9201 | ||
9202 | /* If clipping to the whole line, including trunc marks, extend | |
9ef2e2cf | 9203 | the rectangle to the left and increase its width. */ |
791f420f JR |
9204 | if (whole_line_p) |
9205 | { | |
9206 | clip_rect.left -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); | |
9207 | clip_rect.right += FRAME_X_FLAGS_AREA_WIDTH (f); | |
9208 | } | |
9209 | ||
9210 | w32_set_clip_rectangle (hdc, &clip_rect); | |
ee78dc32 GV |
9211 | } |
9212 | ||
791f420f JR |
9213 | |
9214 | /* Draw a hollow box cursor on window W in glyph row ROW. */ | |
ee78dc32 GV |
9215 | |
9216 | static void | |
791f420f JR |
9217 | x_draw_hollow_cursor (w, row) |
9218 | struct window *w; | |
9219 | struct glyph_row *row; | |
ee78dc32 | 9220 | { |
791f420f | 9221 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
988646fc | 9222 | HDC hdc; |
791f420f JR |
9223 | RECT rect; |
9224 | int wd; | |
9225 | struct glyph *cursor_glyph; | |
9226 | HBRUSH hb = CreateSolidBrush (f->output_data.w32->cursor_pixel); | |
9227 | ||
9228 | /* Compute frame-relative coordinates from window-relative | |
9229 | coordinates. */ | |
9230 | rect.left = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | |
9231 | rect.top = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) | |
9232 | + row->ascent - w->phys_cursor_ascent); | |
9233 | rect.bottom = rect.top + row->height - 1; | |
9234 | ||
9235 | /* Get the glyph the cursor is on. If we can't tell because | |
9236 | the current matrix is invalid or such, give up. */ | |
9237 | cursor_glyph = get_phys_cursor_glyph (w); | |
9238 | if (cursor_glyph == NULL) | |
ee78dc32 GV |
9239 | return; |
9240 | ||
791f420f JR |
9241 | /* Compute the width of the rectangle to draw. If on a stretch |
9242 | glyph, and `x-stretch-block-cursor' is nil, don't draw a | |
9243 | rectangle as wide as the glyph, but use a canonical character | |
9244 | width instead. */ | |
9245 | wd = cursor_glyph->pixel_width - 1; | |
9246 | if (cursor_glyph->type == STRETCH_GLYPH | |
9247 | && !x_stretch_cursor_p) | |
9248 | wd = min (CANON_X_UNIT (f), wd); | |
9249 | ||
9250 | rect.right = rect.left + wd; | |
988646fc | 9251 | hdc = get_frame_dc (f); |
791f420f JR |
9252 | FrameRect (hdc, &rect, hb); |
9253 | DeleteObject (hb); | |
9254 | ||
9255 | release_frame_dc (f, hdc); | |
ee78dc32 GV |
9256 | } |
9257 | ||
791f420f JR |
9258 | |
9259 | /* Draw a bar cursor on window W in glyph row ROW. | |
9260 | ||
9261 | Implementation note: One would like to draw a bar cursor with an | |
9262 | angle equal to the one given by the font property XA_ITALIC_ANGLE. | |
9263 | Unfortunately, I didn't find a font yet that has this property set. | |
9264 | --gerd. */ | |
ee78dc32 GV |
9265 | |
9266 | static void | |
9ef2e2cf | 9267 | x_draw_bar_cursor (w, row, width) |
791f420f JR |
9268 | struct window *w; |
9269 | struct glyph_row *row; | |
9ef2e2cf | 9270 | int width; |
ee78dc32 | 9271 | { |
c2cc16fa JR |
9272 | struct frame *f = XFRAME (w->frame); |
9273 | struct glyph *cursor_glyph; | |
9274 | int x; | |
9275 | HDC hdc; | |
791f420f | 9276 | |
c2cc16fa JR |
9277 | /* If cursor is out of bounds, don't draw garbage. This can happen |
9278 | in mini-buffer windows when switching between echo area glyphs | |
9279 | and mini-buffer. */ | |
9280 | cursor_glyph = get_phys_cursor_glyph (w); | |
9281 | if (cursor_glyph == NULL) | |
9282 | return; | |
9ef2e2cf | 9283 | |
c2cc16fa JR |
9284 | /* If on an image, draw like a normal cursor. That's usually better |
9285 | visible than drawing a bar, esp. if the image is large so that | |
9286 | the bar might not be in the window. */ | |
9287 | if (cursor_glyph->type == IMAGE_GLYPH) | |
9288 | { | |
9289 | struct glyph_row *row; | |
9290 | row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos); | |
9291 | x_draw_phys_cursor_glyph (w, row, DRAW_CURSOR); | |
9292 | } | |
9293 | else | |
9294 | { | |
9295 | if (width < 0) | |
9296 | width = f->output_data.w32->cursor_width; | |
158cba56 | 9297 | |
c2cc16fa JR |
9298 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
9299 | hdc = get_frame_dc (f); | |
9300 | w32_clip_to_row (w, row, hdc, 0); | |
9301 | w32_fill_area (f, hdc, f->output_data.w32->cursor_pixel, | |
9302 | x, | |
9303 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y), | |
9304 | min (cursor_glyph->pixel_width, width), | |
9305 | row->height); | |
9306 | release_frame_dc (f, hdc); | |
791f420f | 9307 | } |
ee78dc32 GV |
9308 | } |
9309 | ||
791f420f JR |
9310 | |
9311 | /* Clear the cursor of window W to background color, and mark the | |
9312 | cursor as not shown. This is used when the text where the cursor | |
9313 | is is about to be rewritten. */ | |
9314 | ||
ee78dc32 | 9315 | static void |
791f420f JR |
9316 | x_clear_cursor (w) |
9317 | struct window *w; | |
ee78dc32 | 9318 | { |
791f420f JR |
9319 | if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p) |
9320 | x_update_window_cursor (w, 0); | |
9321 | } | |
ee78dc32 | 9322 | |
ee78dc32 | 9323 | |
791f420f JR |
9324 | /* Draw the cursor glyph of window W in glyph row ROW. See the |
9325 | comment of x_draw_glyphs for the meaning of HL. */ | |
ee78dc32 | 9326 | |
791f420f JR |
9327 | static void |
9328 | x_draw_phys_cursor_glyph (w, row, hl) | |
9329 | struct window *w; | |
9330 | struct glyph_row *row; | |
9331 | enum draw_glyphs_face hl; | |
9332 | { | |
9333 | /* If cursor hpos is out of bounds, don't draw garbage. This can | |
9334 | happen in mini-buffer windows when switching between echo area | |
9335 | glyphs and mini-buffer. */ | |
9336 | if (w->phys_cursor.hpos < row->used[TEXT_AREA]) | |
ee78dc32 | 9337 | { |
791f420f JR |
9338 | x_draw_glyphs (w, w->phys_cursor.x, row, TEXT_AREA, |
9339 | w->phys_cursor.hpos, w->phys_cursor.hpos + 1, | |
9340 | hl, 0, 0, 0); | |
9341 | ||
9342 | /* When we erase the cursor, and ROW is overlapped by other | |
9343 | rows, make sure that these overlapping parts of other rows | |
9344 | are redrawn. */ | |
9345 | if (hl == DRAW_NORMAL_TEXT && row->overlapped_p) | |
9346 | { | |
9347 | if (row > w->current_matrix->rows | |
9348 | && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1)) | |
9349 | x_fix_overlapping_area (w, row - 1, TEXT_AREA); | |
9350 | ||
9351 | if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w) | |
9352 | && MATRIX_ROW_OVERLAPS_PRED_P (row + 1)) | |
9353 | x_fix_overlapping_area (w, row + 1, TEXT_AREA); | |
9354 | } | |
ee78dc32 | 9355 | } |
791f420f | 9356 | } |
ee78dc32 | 9357 | |
791f420f JR |
9358 | |
9359 | /* Erase the image of a cursor of window W from the screen. */ | |
9360 | ||
9361 | static void | |
9362 | x_erase_phys_cursor (w) | |
9363 | struct window *w; | |
9364 | { | |
9365 | struct frame *f = XFRAME (w->frame); | |
9366 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
9367 | int hpos = w->phys_cursor.hpos; | |
9368 | int vpos = w->phys_cursor.vpos; | |
9369 | int mouse_face_here_p = 0; | |
9370 | struct glyph_matrix *active_glyphs = w->current_matrix; | |
9371 | struct glyph_row *cursor_row; | |
9372 | struct glyph *cursor_glyph; | |
9373 | enum draw_glyphs_face hl; | |
9374 | ||
9375 | /* No cursor displayed or row invalidated => nothing to do on the | |
9376 | screen. */ | |
9377 | if (w->phys_cursor_type == NO_CURSOR) | |
9378 | goto mark_cursor_off; | |
9379 | ||
9380 | /* VPOS >= active_glyphs->nrows means that window has been resized. | |
9381 | Don't bother to erase the cursor. */ | |
9382 | if (vpos >= active_glyphs->nrows) | |
9383 | goto mark_cursor_off; | |
9384 | ||
9385 | /* If row containing cursor is marked invalid, there is nothing we | |
9386 | can do. */ | |
9387 | cursor_row = MATRIX_ROW (active_glyphs, vpos); | |
9388 | if (!cursor_row->enabled_p) | |
9389 | goto mark_cursor_off; | |
9390 | ||
9391 | /* This can happen when the new row is shorter than the old one. | |
9392 | In this case, either x_draw_glyphs or clear_end_of_line | |
9393 | should have cleared the cursor. Note that we wouldn't be | |
9394 | able to erase the cursor in this case because we don't have a | |
9395 | cursor glyph at hand. */ | |
9396 | if (w->phys_cursor.hpos >= cursor_row->used[TEXT_AREA]) | |
9397 | goto mark_cursor_off; | |
9398 | ||
9399 | /* If the cursor is in the mouse face area, redisplay that when | |
9400 | we clear the cursor. */ | |
c2cc16fa JR |
9401 | if (! NILP (dpyinfo->mouse_face_window) |
9402 | && w == XWINDOW (dpyinfo->mouse_face_window) | |
791f420f JR |
9403 | && (vpos > dpyinfo->mouse_face_beg_row |
9404 | || (vpos == dpyinfo->mouse_face_beg_row | |
9405 | && hpos >= dpyinfo->mouse_face_beg_col)) | |
9406 | && (vpos < dpyinfo->mouse_face_end_row | |
9407 | || (vpos == dpyinfo->mouse_face_end_row | |
9408 | && hpos < dpyinfo->mouse_face_end_col)) | |
9409 | /* Don't redraw the cursor's spot in mouse face if it is at the | |
9410 | end of a line (on a newline). The cursor appears there, but | |
9411 | mouse highlighting does not. */ | |
9412 | && cursor_row->used[TEXT_AREA] > hpos) | |
9413 | mouse_face_here_p = 1; | |
9414 | ||
9415 | /* Maybe clear the display under the cursor. */ | |
9416 | if (w->phys_cursor_type == HOLLOW_BOX_CURSOR) | |
ee78dc32 | 9417 | { |
791f420f JR |
9418 | int x; |
9419 | int header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
00fe468b | 9420 | HDC hdc; |
ee78dc32 | 9421 | |
791f420f JR |
9422 | cursor_glyph = get_phys_cursor_glyph (w); |
9423 | if (cursor_glyph == NULL) | |
9424 | goto mark_cursor_off; | |
ee78dc32 | 9425 | |
791f420f | 9426 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
00fe468b JR |
9427 | |
9428 | hdc = get_frame_dc (f); | |
9429 | w32_clear_area (f, hdc, x, | |
791f420f JR |
9430 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, |
9431 | cursor_row->y)), | |
9432 | cursor_glyph->pixel_width, | |
9433 | cursor_row->visible_height); | |
00fe468b | 9434 | release_frame_dc (f, hdc); |
ee78dc32 | 9435 | } |
791f420f JR |
9436 | |
9437 | /* Erase the cursor by redrawing the character underneath it. */ | |
9438 | if (mouse_face_here_p) | |
9439 | hl = DRAW_MOUSE_FACE; | |
791f420f JR |
9440 | else |
9441 | hl = DRAW_NORMAL_TEXT; | |
9442 | x_draw_phys_cursor_glyph (w, cursor_row, hl); | |
9443 | ||
9444 | mark_cursor_off: | |
9445 | w->phys_cursor_on_p = 0; | |
9446 | w->phys_cursor_type = NO_CURSOR; | |
ee78dc32 GV |
9447 | } |
9448 | ||
9449 | ||
9f5a911b JR |
9450 | /* Non-zero if physical cursor of window W is within mouse face. */ |
9451 | ||
9452 | static int | |
9453 | cursor_in_mouse_face_p (w) | |
9454 | struct window *w; | |
9455 | { | |
9456 | struct w32_display_info *dpyinfo | |
9457 | = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); | |
9458 | int in_mouse_face = 0; | |
9459 | ||
9460 | if (WINDOWP (dpyinfo->mouse_face_window) | |
9461 | && XWINDOW (dpyinfo->mouse_face_window) == w) | |
9462 | { | |
9463 | int hpos = w->phys_cursor.hpos; | |
9464 | int vpos = w->phys_cursor.vpos; | |
9465 | ||
9466 | if (vpos >= dpyinfo->mouse_face_beg_row | |
9467 | && vpos <= dpyinfo->mouse_face_end_row | |
9468 | && (vpos > dpyinfo->mouse_face_beg_row | |
9469 | || hpos >= dpyinfo->mouse_face_beg_col) | |
9470 | && (vpos < dpyinfo->mouse_face_end_row | |
9471 | || hpos < dpyinfo->mouse_face_end_col | |
9472 | || dpyinfo->mouse_face_past_end)) | |
9473 | in_mouse_face = 1; | |
9474 | } | |
9475 | ||
9476 | return in_mouse_face; | |
9477 | } | |
9478 | ||
9479 | ||
791f420f JR |
9480 | /* Display or clear cursor of window W. If ON is zero, clear the |
9481 | cursor. If it is non-zero, display the cursor. If ON is nonzero, | |
9482 | where to put the cursor is specified by HPOS, VPOS, X and Y. */ | |
ee78dc32 | 9483 | |
791f420f JR |
9484 | void |
9485 | x_display_and_set_cursor (w, on, hpos, vpos, x, y) | |
9486 | struct window *w; | |
9487 | int on, hpos, vpos, x, y; | |
ee78dc32 | 9488 | { |
791f420f JR |
9489 | struct frame *f = XFRAME (w->frame); |
9490 | int new_cursor_type; | |
9ef2e2cf | 9491 | int new_cursor_width; |
791f420f JR |
9492 | struct glyph_matrix *current_glyphs; |
9493 | struct glyph_row *glyph_row; | |
9494 | struct glyph *glyph; | |
34368a22 | 9495 | int cursor_non_selected; |
abb15ebd | 9496 | int active_cursor = 1; |
ee78dc32 GV |
9497 | |
9498 | /* This is pointless on invisible frames, and dangerous on garbaged | |
791f420f JR |
9499 | windows and frames; in the latter case, the frame or window may |
9500 | be in the midst of changing its size, and x and y may be off the | |
9501 | window. */ | |
9502 | if (! FRAME_VISIBLE_P (f) | |
9503 | || FRAME_GARBAGED_P (f) | |
9504 | || vpos >= w->current_matrix->nrows | |
9505 | || hpos >= w->current_matrix->matrix_w) | |
ee78dc32 GV |
9506 | return; |
9507 | ||
9508 | /* If cursor is off and we want it off, return quickly. */ | |
791f420f | 9509 | if (!on && !w->phys_cursor_on_p) |
ee78dc32 GV |
9510 | return; |
9511 | ||
791f420f JR |
9512 | current_glyphs = w->current_matrix; |
9513 | glyph_row = MATRIX_ROW (current_glyphs, vpos); | |
9514 | glyph = glyph_row->glyphs[TEXT_AREA] + hpos; | |
9515 | ||
9516 | /* If cursor row is not enabled, we don't really know where to | |
9517 | display the cursor. */ | |
9518 | if (!glyph_row->enabled_p) | |
9519 | { | |
9520 | w->phys_cursor_on_p = 0; | |
9521 | return; | |
9522 | } | |
9523 | ||
9524 | xassert (interrupt_input_blocked); | |
9525 | ||
9526 | /* Set new_cursor_type to the cursor we want to be displayed. In a | |
9527 | mini-buffer window, we want the cursor only to appear if we are | |
9528 | reading input from this window. For the selected window, we want | |
9529 | the cursor type given by the frame parameter. If explicitly | |
9530 | marked off, draw no cursor. In all other cases, we want a hollow | |
9531 | box cursor. */ | |
34368a22 | 9532 | cursor_non_selected |
b116830b | 9533 | = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows, |
34368a22 | 9534 | w->buffer)); |
9ef2e2cf | 9535 | new_cursor_width = -1; |
791f420f JR |
9536 | if (cursor_in_echo_area |
9537 | && FRAME_HAS_MINIBUF_P (f) | |
9538 | && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window)) | |
9539 | { | |
9540 | if (w == XWINDOW (echo_area_window)) | |
9541 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
9542 | else | |
abb15ebd JR |
9543 | { |
9544 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
9545 | active_cursor = 0; | |
9546 | } | |
791f420f JR |
9547 | } |
9548 | else | |
9549 | { | |
49be9f70 JR |
9550 | if (f != FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame |
9551 | || w != XWINDOW (f->selected_window)) | |
791f420f | 9552 | { |
abb15ebd | 9553 | active_cursor = 0; |
a2bc11d4 | 9554 | |
9127e20e | 9555 | if (MINI_WINDOW_P (w) |
34368a22 | 9556 | || !cursor_non_selected |
9127e20e | 9557 | || NILP (XBUFFER (w->buffer)->cursor_type)) |
791f420f JR |
9558 | new_cursor_type = NO_CURSOR; |
9559 | else | |
9560 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
9561 | } | |
9562 | else if (w->cursor_off_p) | |
9563 | new_cursor_type = NO_CURSOR; | |
9564 | else | |
9ef2e2cf JR |
9565 | { |
9566 | struct buffer *b = XBUFFER (w->buffer); | |
9567 | ||
9568 | if (EQ (b->cursor_type, Qt)) | |
9569 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
9570 | else | |
9571 | new_cursor_type = x_specified_cursor_type (b->cursor_type, | |
9572 | &new_cursor_width); | |
9573 | } | |
791f420f JR |
9574 | } |
9575 | ||
9576 | /* If cursor is currently being shown and we don't want it to be or | |
9577 | it is in the wrong place, or the cursor type is not what we want, | |
ee78dc32 | 9578 | erase it. */ |
791f420f | 9579 | if (w->phys_cursor_on_p |
ee78dc32 | 9580 | && (!on |
791f420f JR |
9581 | || w->phys_cursor.x != x |
9582 | || w->phys_cursor.y != y | |
9583 | || new_cursor_type != w->phys_cursor_type)) | |
9584 | x_erase_phys_cursor (w); | |
9585 | ||
9586 | /* If the cursor is now invisible and we want it to be visible, | |
9587 | display it. */ | |
9588 | if (on && !w->phys_cursor_on_p) | |
9589 | { | |
9590 | w->phys_cursor_ascent = glyph_row->ascent; | |
9591 | w->phys_cursor_height = glyph_row->height; | |
9592 | ||
9593 | /* Set phys_cursor_.* before x_draw_.* is called because some | |
9594 | of them may need the information. */ | |
9595 | w->phys_cursor.x = x; | |
9596 | w->phys_cursor.y = glyph_row->y; | |
9597 | w->phys_cursor.hpos = hpos; | |
9598 | w->phys_cursor.vpos = vpos; | |
9599 | w->phys_cursor_type = new_cursor_type; | |
9600 | w->phys_cursor_on_p = 1; | |
9601 | ||
abb15ebd JR |
9602 | /* If this is the active cursor, we need to track it with the |
9603 | system caret, so third party software like screen magnifiers | |
9604 | and speech synthesizers can follow the cursor. */ | |
9605 | if (active_cursor) | |
9606 | { | |
9607 | HWND hwnd = FRAME_W32_WINDOW (f); | |
9608 | ||
9609 | struct glyph * cursor_glyph = get_phys_cursor_glyph (w); | |
9610 | int caret_width = cursor_glyph->pixel_width; | |
9611 | w32_system_caret_x | |
9612 | = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | |
9613 | w32_system_caret_y | |
9614 | = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) | |
9615 | + glyph_row->ascent - w->phys_cursor_ascent); | |
9616 | ||
9617 | /* If the size of the active cursor changed, destroy the old | |
9618 | system caret. */ | |
9619 | if (w32_system_caret_hwnd | |
9620 | && (w32_system_caret_height != w->phys_cursor_height | |
9621 | || w32_system_caret_width != caret_width)) | |
9622 | PostMessage (hwnd, WM_EMACS_DESTROY_CARET, NULL, NULL); | |
9623 | ||
9624 | if (!w32_system_caret_hwnd) | |
9625 | { | |
9626 | w32_system_caret_height = w->phys_cursor_height; | |
9627 | w32_system_caret_width = caret_width; | |
9628 | } | |
9629 | ||
9630 | /* Move the system caret. */ | |
9631 | PostMessage (hwnd, WM_EMACS_TRACK_CARET, NULL, NULL); | |
9632 | } | |
9633 | ||
791f420f | 9634 | switch (new_cursor_type) |
ee78dc32 | 9635 | { |
791f420f JR |
9636 | case HOLLOW_BOX_CURSOR: |
9637 | x_draw_hollow_cursor (w, glyph_row); | |
9638 | break; | |
9639 | ||
9640 | case FILLED_BOX_CURSOR: | |
9641 | x_draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR); | |
9642 | break; | |
9643 | ||
9644 | case BAR_CURSOR: | |
9ef2e2cf | 9645 | x_draw_bar_cursor (w, glyph_row, new_cursor_width); |
791f420f | 9646 | break; |
ee78dc32 | 9647 | |
791f420f JR |
9648 | case NO_CURSOR: |
9649 | break; | |
9650 | ||
9651 | default: | |
9652 | abort (); | |
9653 | } | |
ee78dc32 GV |
9654 | } |
9655 | } | |
9656 | ||
689004fa | 9657 | |
791f420f JR |
9658 | /* Display the cursor on window W, or clear it. X and Y are window |
9659 | relative pixel coordinates. HPOS and VPOS are glyph matrix | |
9660 | positions. If W is not the selected window, display a hollow | |
9661 | cursor. ON non-zero means display the cursor at X, Y which | |
9662 | correspond to HPOS, VPOS, otherwise it is cleared. */ | |
9663 | ||
9664 | void | |
9665 | x_display_cursor (w, on, hpos, vpos, x, y) | |
9666 | struct window *w; | |
9667 | int on, hpos, vpos, x, y; | |
ee78dc32 GV |
9668 | { |
9669 | BLOCK_INPUT; | |
791f420f JR |
9670 | x_display_and_set_cursor (w, on, hpos, vpos, x, y); |
9671 | UNBLOCK_INPUT; | |
9672 | } | |
9673 | ||
9674 | ||
9675 | /* Display the cursor on window W, or clear it, according to ON_P. | |
9676 | Don't change the cursor's position. */ | |
9677 | ||
9678 | void | |
9679 | x_update_cursor (f, on_p) | |
9680 | struct frame *f; | |
9681 | int on_p; | |
9682 | { | |
9683 | x_update_cursor_in_window_tree (XWINDOW (f->root_window), on_p); | |
9684 | } | |
9685 | ||
9686 | ||
9687 | /* Call x_update_window_cursor with parameter ON_P on all leaf windows | |
9688 | in the window tree rooted at W. */ | |
ee78dc32 | 9689 | |
791f420f JR |
9690 | static void |
9691 | x_update_cursor_in_window_tree (w, on_p) | |
9692 | struct window *w; | |
9693 | int on_p; | |
9694 | { | |
9695 | while (w) | |
689004fa | 9696 | { |
791f420f JR |
9697 | if (!NILP (w->hchild)) |
9698 | x_update_cursor_in_window_tree (XWINDOW (w->hchild), on_p); | |
9699 | else if (!NILP (w->vchild)) | |
9700 | x_update_cursor_in_window_tree (XWINDOW (w->vchild), on_p); | |
9701 | else | |
9702 | x_update_window_cursor (w, on_p); | |
9703 | ||
9704 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
689004fa | 9705 | } |
791f420f | 9706 | } |
689004fa | 9707 | |
ee78dc32 | 9708 | |
791f420f JR |
9709 | /* Switch the display of W's cursor on or off, according to the value |
9710 | of ON. */ | |
9711 | ||
9712 | static void | |
9713 | x_update_window_cursor (w, on) | |
9714 | struct window *w; | |
9715 | int on; | |
9716 | { | |
9ef2e2cf JR |
9717 | /* Don't update cursor in windows whose frame is in the process |
9718 | of being deleted. */ | |
9719 | if (w->current_matrix) | |
9720 | { | |
9721 | BLOCK_INPUT; | |
9722 | x_display_and_set_cursor (w, on, w->phys_cursor.hpos, | |
9723 | w->phys_cursor.vpos, w->phys_cursor.x, | |
9724 | w->phys_cursor.y); | |
9725 | UNBLOCK_INPUT; | |
9726 | } | |
ee78dc32 | 9727 | } |
791f420f JR |
9728 | |
9729 | ||
9ef2e2cf | 9730 | |
ee78dc32 | 9731 | \f |
7f5d1df8 GV |
9732 | /* Icons. */ |
9733 | ||
9734 | int | |
9735 | x_bitmap_icon (f, icon) | |
9736 | struct frame *f; | |
9737 | Lisp_Object icon; | |
9738 | { | |
7f5d1df8 GV |
9739 | HANDLE hicon; |
9740 | ||
9741 | if (FRAME_W32_WINDOW (f) == 0) | |
9742 | return 1; | |
9743 | ||
9744 | if (NILP (icon)) | |
9745 | hicon = LoadIcon (hinst, EMACS_CLASS); | |
9746 | else if (STRINGP (icon)) | |
9747 | hicon = LoadImage (NULL, (LPCTSTR) XSTRING (icon)->data, IMAGE_ICON, 0, 0, | |
9748 | LR_DEFAULTSIZE | LR_LOADFROMFILE); | |
9749 | else if (SYMBOLP (icon)) | |
9750 | { | |
9751 | LPCTSTR name; | |
9752 | ||
9753 | if (EQ (icon, intern ("application"))) | |
9754 | name = (LPCTSTR) IDI_APPLICATION; | |
9755 | else if (EQ (icon, intern ("hand"))) | |
9756 | name = (LPCTSTR) IDI_HAND; | |
9757 | else if (EQ (icon, intern ("question"))) | |
9758 | name = (LPCTSTR) IDI_QUESTION; | |
9759 | else if (EQ (icon, intern ("exclamation"))) | |
9760 | name = (LPCTSTR) IDI_EXCLAMATION; | |
9761 | else if (EQ (icon, intern ("asterisk"))) | |
9762 | name = (LPCTSTR) IDI_ASTERISK; | |
9763 | else if (EQ (icon, intern ("winlogo"))) | |
9764 | name = (LPCTSTR) IDI_WINLOGO; | |
9765 | else | |
9766 | return 1; | |
9767 | ||
9768 | hicon = LoadIcon (NULL, name); | |
9769 | } | |
9770 | else | |
9771 | return 1; | |
9772 | ||
9773 | if (hicon == NULL) | |
9774 | return 1; | |
9775 | ||
791f420f JR |
9776 | PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_BIG, |
9777 | (LPARAM) hicon); | |
7f5d1df8 GV |
9778 | |
9779 | return 0; | |
9780 | } | |
9781 | ||
9782 | \f | |
c2cc16fa JR |
9783 | /************************************************************************ |
9784 | Handling X errors | |
9785 | ************************************************************************/ | |
9786 | ||
9787 | /* Display Error Handling functions not used on W32. Listing them here | |
9788 | helps diff stay in step when comparing w32term.c with xterm.c. | |
9789 | ||
9790 | x_error_catcher (display, error) | |
9791 | x_catch_errors (dpy) | |
9792 | x_catch_errors_unwind (old_val) | |
9793 | x_check_errors (dpy, format) | |
9794 | x_had_errors_p (dpy) | |
9795 | x_clear_errors (dpy) | |
9796 | x_uncatch_errors (dpy, count) | |
9797 | x_trace_wire () | |
9798 | x_connection_signal (signalnum) | |
9799 | x_connection_closed (dpy, error_message) | |
9800 | x_error_quitter (display, error) | |
9801 | x_error_handler (display, error) | |
9802 | x_io_error_quitter (display) | |
9803 | ||
9804 | */ | |
9805 | ||
9806 | \f | |
ee78dc32 GV |
9807 | /* Changing the font of the frame. */ |
9808 | ||
9809 | /* Give frame F the font named FONTNAME as its default font, and | |
9810 | return the full name of that font. FONTNAME may be a wildcard | |
9811 | pattern; in that case, we choose some font that fits the pattern. | |
9812 | The return value shows which font we chose. */ | |
9813 | ||
9814 | Lisp_Object | |
9815 | x_new_font (f, fontname) | |
9816 | struct frame *f; | |
9817 | register char *fontname; | |
9818 | { | |
cabb23bc | 9819 | struct font_info *fontp |
93ff4395 | 9820 | = FS_LOAD_FONT (f, 0, fontname, -1); |
ee78dc32 | 9821 | |
cabb23bc | 9822 | if (!fontp) |
791f420f | 9823 | return Qnil; |
ee78dc32 | 9824 | |
cabb23bc | 9825 | FRAME_FONT (f) = (XFontStruct *) (fontp->font); |
791f420f | 9826 | FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset; |
cabb23bc | 9827 | FRAME_FONTSET (f) = -1; |
ee78dc32 GV |
9828 | |
9829 | /* Compute the scroll bar width in character columns. */ | |
9830 | if (f->scroll_bar_pixel_width > 0) | |
9831 | { | |
ec48c3a7 | 9832 | int wid = FONT_WIDTH (FRAME_FONT (f)); |
ee78dc32 GV |
9833 | f->scroll_bar_cols = (f->scroll_bar_pixel_width + wid-1) / wid; |
9834 | } | |
9835 | else | |
ec48c3a7 JR |
9836 | { |
9837 | int wid = FONT_WIDTH (FRAME_FONT (f)); | |
9838 | f->scroll_bar_cols = (14 + wid - 1) / wid; | |
9839 | } | |
ee78dc32 GV |
9840 | |
9841 | /* Now make the frame display the given font. */ | |
fbd6baed | 9842 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 GV |
9843 | { |
9844 | frame_update_line_height (f); | |
49be9f70 JR |
9845 | if (NILP (tip_frame) || XFRAME (tip_frame) != f) |
9846 | x_set_window_size (f, 0, f->width, f->height); | |
ee78dc32 GV |
9847 | } |
9848 | else | |
9849 | /* If we are setting a new frame's font for the first time, | |
9850 | there are no faces yet, so this font's height is the line height. */ | |
ec48c3a7 | 9851 | f->output_data.w32->line_height = FONT_HEIGHT (FRAME_FONT (f)); |
ee78dc32 | 9852 | |
791f420f | 9853 | return build_string (fontp->full_name); |
ee78dc32 GV |
9854 | } |
9855 | \f | |
cabb23bc GV |
9856 | /* Give frame F the fontset named FONTSETNAME as its default font, and |
9857 | return the full name of that fontset. FONTSETNAME may be a wildcard | |
9858 | pattern; in that case, we choose some fontset that fits the pattern. | |
9859 | The return value shows which fontset we chose. */ | |
9860 | ||
9861 | Lisp_Object | |
9862 | x_new_fontset (f, fontsetname) | |
9863 | struct frame *f; | |
9864 | char *fontsetname; | |
9865 | { | |
93ff4395 | 9866 | int fontset = fs_query_fontset (build_string (fontsetname), 0); |
cabb23bc GV |
9867 | Lisp_Object result; |
9868 | ||
9869 | if (fontset < 0) | |
9870 | return Qnil; | |
9871 | ||
9872 | if (FRAME_FONTSET (f) == fontset) | |
9873 | /* This fontset is already set in frame F. There's nothing more | |
9874 | to do. */ | |
93ff4395 | 9875 | return fontset_name (fontset); |
cabb23bc | 9876 | |
93ff4395 | 9877 | result = x_new_font (f, (XSTRING (fontset_ascii (fontset))->data)); |
cabb23bc GV |
9878 | |
9879 | if (!STRINGP (result)) | |
9880 | /* Can't load ASCII font. */ | |
9881 | return Qnil; | |
9882 | ||
9883 | /* Since x_new_font doesn't update any fontset information, do it now. */ | |
9884 | FRAME_FONTSET(f) = fontset; | |
cabb23bc GV |
9885 | |
9886 | return build_string (fontsetname); | |
9887 | } | |
791f420f | 9888 | |
c2cc16fa JR |
9889 | \f |
9890 | /*********************************************************************** | |
9891 | TODO: W32 Input Methods | |
9892 | ***********************************************************************/ | |
9893 | /* Listing missing functions from xterm.c helps diff stay in step. | |
791f420f | 9894 | |
c2cc16fa JR |
9895 | xim_destroy_callback (xim, client_data, call_data) |
9896 | xim_open_dpy (dpyinfo, resource_name) | |
9897 | struct xim_inst_t | |
9898 | xim_instantiate_callback (display, client_data, call_data) | |
9899 | xim_initialize (dpyinfo, resource_name) | |
9900 | xim_close_dpy (dpyinfo) | |
791f420f | 9901 | |
c2cc16fa | 9902 | */ |
791f420f | 9903 | |
cabb23bc | 9904 | \f |
689004fa GV |
9905 | /* Calculate the absolute position in frame F |
9906 | from its current recorded position values and gravity. */ | |
9907 | ||
9ef2e2cf | 9908 | void |
ee78dc32 GV |
9909 | x_calc_absolute_position (f) |
9910 | struct frame *f; | |
9911 | { | |
ee78dc32 | 9912 | POINT pt; |
fbd6baed | 9913 | int flags = f->output_data.w32->size_hint_flags; |
ee78dc32 GV |
9914 | |
9915 | pt.x = pt.y = 0; | |
9916 | ||
9917 | /* Find the position of the outside upper-left corner of | |
c2cc16fa JR |
9918 | the inner window, with respect to the outer window. |
9919 | But do this only if we will need the results. */ | |
fbd6baed | 9920 | if (f->output_data.w32->parent_desc != FRAME_W32_DISPLAY_INFO (f)->root_window) |
ee78dc32 GV |
9921 | { |
9922 | BLOCK_INPUT; | |
fbd6baed GV |
9923 | MapWindowPoints (FRAME_W32_WINDOW (f), |
9924 | f->output_data.w32->parent_desc, | |
ee78dc32 GV |
9925 | &pt, 1); |
9926 | UNBLOCK_INPUT; | |
9927 | } | |
9928 | ||
9929 | { | |
9930 | RECT rt; | |
9931 | rt.left = rt.right = rt.top = rt.bottom = 0; | |
9932 | ||
9933 | BLOCK_INPUT; | |
fbd6baed | 9934 | AdjustWindowRect(&rt, f->output_data.w32->dwStyle, |
97c23857 | 9935 | FRAME_EXTERNAL_MENU_BAR (f)); |
ee78dc32 GV |
9936 | UNBLOCK_INPUT; |
9937 | ||
9938 | pt.x += (rt.right - rt.left); | |
9939 | pt.y += (rt.bottom - rt.top); | |
9940 | } | |
9941 | ||
9942 | /* Treat negative positions as relative to the leftmost bottommost | |
9943 | position that fits on the screen. */ | |
9944 | if (flags & XNegative) | |
fbd6baed GV |
9945 | f->output_data.w32->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width |
9946 | - 2 * f->output_data.w32->border_width - pt.x | |
ee78dc32 | 9947 | - PIXEL_WIDTH (f) |
fbd6baed | 9948 | + f->output_data.w32->left_pos); |
158cba56 | 9949 | |
ee78dc32 | 9950 | if (flags & YNegative) |
fbd6baed GV |
9951 | f->output_data.w32->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height |
9952 | - 2 * f->output_data.w32->border_width - pt.y | |
ee78dc32 | 9953 | - PIXEL_HEIGHT (f) |
fbd6baed | 9954 | + f->output_data.w32->top_pos); |
ee78dc32 GV |
9955 | /* The left_pos and top_pos |
9956 | are now relative to the top and left screen edges, | |
9957 | so the flags should correspond. */ | |
fbd6baed | 9958 | f->output_data.w32->size_hint_flags &= ~ (XNegative | YNegative); |
ee78dc32 GV |
9959 | } |
9960 | ||
9961 | /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position, | |
9962 | to really change the position, and 0 when calling from | |
9963 | x_make_frame_visible (in that case, XOFF and YOFF are the current | |
9964 | position values). It is -1 when calling from x_set_frame_parameters, | |
9965 | which means, do adjust for borders but don't change the gravity. */ | |
9966 | ||
9ef2e2cf | 9967 | void |
ee78dc32 GV |
9968 | x_set_offset (f, xoff, yoff, change_gravity) |
9969 | struct frame *f; | |
9970 | register int xoff, yoff; | |
9971 | int change_gravity; | |
9972 | { | |
9973 | int modified_top, modified_left; | |
9974 | ||
9975 | if (change_gravity > 0) | |
9976 | { | |
fbd6baed GV |
9977 | f->output_data.w32->top_pos = yoff; |
9978 | f->output_data.w32->left_pos = xoff; | |
9979 | f->output_data.w32->size_hint_flags &= ~ (XNegative | YNegative); | |
ee78dc32 | 9980 | if (xoff < 0) |
fbd6baed | 9981 | f->output_data.w32->size_hint_flags |= XNegative; |
ee78dc32 | 9982 | if (yoff < 0) |
fbd6baed GV |
9983 | f->output_data.w32->size_hint_flags |= YNegative; |
9984 | f->output_data.w32->win_gravity = NorthWestGravity; | |
ee78dc32 GV |
9985 | } |
9986 | x_calc_absolute_position (f); | |
9987 | ||
9988 | BLOCK_INPUT; | |
9989 | x_wm_set_size_hint (f, (long) 0, 0); | |
9990 | ||
fbd6baed GV |
9991 | modified_left = f->output_data.w32->left_pos; |
9992 | modified_top = f->output_data.w32->top_pos; | |
ee78dc32 | 9993 | |
fbd6baed | 9994 | my_set_window_pos (FRAME_W32_WINDOW (f), |
52cf03a1 GV |
9995 | NULL, |
9996 | modified_left, modified_top, | |
cabb23bc | 9997 | 0, 0, |
689004fa | 9998 | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); |
ee78dc32 GV |
9999 | UNBLOCK_INPUT; |
10000 | } | |
10001 | ||
10002 | /* Call this to change the size of frame F's x-window. | |
10003 | If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity | |
10004 | for this size change and subsequent size changes. | |
10005 | Otherwise we leave the window gravity unchanged. */ | |
c2cc16fa | 10006 | |
791f420f | 10007 | void |
ee78dc32 GV |
10008 | x_set_window_size (f, change_gravity, cols, rows) |
10009 | struct frame *f; | |
10010 | int change_gravity; | |
10011 | int cols, rows; | |
10012 | { | |
10013 | int pixelwidth, pixelheight; | |
10014 | ||
10015 | BLOCK_INPUT; | |
10016 | ||
10017 | check_frame_size (f, &rows, &cols); | |
fbd6baed | 10018 | f->output_data.w32->vertical_scroll_bar_extra |
ee78dc32 GV |
10019 | = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f) |
10020 | ? 0 | |
fbd6baed | 10021 | : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->output_data.w32->font))); |
791f420f JR |
10022 | f->output_data.w32->flags_areas_extra |
10023 | = FRAME_FLAGS_AREA_WIDTH (f); | |
ee78dc32 GV |
10024 | pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols); |
10025 | pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows); | |
10026 | ||
fbd6baed | 10027 | f->output_data.w32->win_gravity = NorthWestGravity; |
ee78dc32 GV |
10028 | x_wm_set_size_hint (f, (long) 0, 0); |
10029 | ||
10030 | { | |
10031 | RECT rect; | |
10032 | ||
10033 | rect.left = rect.top = 0; | |
10034 | rect.right = pixelwidth; | |
10035 | rect.bottom = pixelheight; | |
10036 | ||
fbd6baed | 10037 | AdjustWindowRect(&rect, f->output_data.w32->dwStyle, |
97c23857 | 10038 | FRAME_EXTERNAL_MENU_BAR (f)); |
ee78dc32 | 10039 | |
fbd6baed | 10040 | my_set_window_pos (FRAME_W32_WINDOW (f), |
52cf03a1 GV |
10041 | NULL, |
10042 | 0, 0, | |
689004fa GV |
10043 | rect.right - rect.left, |
10044 | rect.bottom - rect.top, | |
10045 | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); | |
ee78dc32 GV |
10046 | } |
10047 | ||
10048 | /* Now, strictly speaking, we can't be sure that this is accurate, | |
10049 | but the window manager will get around to dealing with the size | |
10050 | change request eventually, and we'll hear how it went when the | |
10051 | ConfigureNotify event gets here. | |
10052 | ||
10053 | We could just not bother storing any of this information here, | |
10054 | and let the ConfigureNotify event set everything up, but that | |
ec48c3a7 | 10055 | might be kind of confusing to the Lisp code, since size changes |
ee78dc32 | 10056 | wouldn't be reported in the frame parameters until some random |
791f420f JR |
10057 | point in the future when the ConfigureNotify event arrives. |
10058 | ||
10059 | We pass 1 for DELAY since we can't run Lisp code inside of | |
10060 | a BLOCK_INPUT. */ | |
10061 | change_frame_size (f, rows, cols, 0, 1, 0); | |
ee78dc32 GV |
10062 | PIXEL_WIDTH (f) = pixelwidth; |
10063 | PIXEL_HEIGHT (f) = pixelheight; | |
10064 | ||
689004fa GV |
10065 | /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to |
10066 | receive in the ConfigureNotify event; if we get what we asked | |
10067 | for, then the event won't cause the screen to become garbaged, so | |
10068 | we have to make sure to do it here. */ | |
10069 | SET_FRAME_GARBAGED (f); | |
10070 | ||
ee78dc32 | 10071 | /* If cursor was outside the new size, mark it as off. */ |
791f420f | 10072 | mark_window_cursors_off (XWINDOW (f->root_window)); |
ee78dc32 | 10073 | |
689004fa GV |
10074 | /* Clear out any recollection of where the mouse highlighting was, |
10075 | since it might be in a place that's outside the new frame size. | |
10076 | Actually checking whether it is outside is a pain in the neck, | |
10077 | so don't try--just let the highlighting be done afresh with new size. */ | |
31d4844a KH |
10078 | cancel_mouse_face (f); |
10079 | ||
ee78dc32 GV |
10080 | UNBLOCK_INPUT; |
10081 | } | |
10082 | \f | |
10083 | /* Mouse warping. */ | |
10084 | ||
ec48c3a7 JR |
10085 | void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y); |
10086 | ||
10087 | void | |
10088 | x_set_mouse_position (f, x, y) | |
10089 | struct frame *f; | |
10090 | int x, y; | |
10091 | { | |
10092 | int pix_x, pix_y; | |
10093 | ||
10094 | pix_x = CHAR_TO_PIXEL_COL (f, x) + FONT_WIDTH (f->output_data.w32->font) / 2; | |
10095 | pix_y = CHAR_TO_PIXEL_ROW (f, y) + f->output_data.w32->line_height / 2; | |
10096 | ||
10097 | if (pix_x < 0) pix_x = 0; | |
10098 | if (pix_x > PIXEL_WIDTH (f)) pix_x = PIXEL_WIDTH (f); | |
10099 | ||
10100 | if (pix_y < 0) pix_y = 0; | |
10101 | if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f); | |
10102 | ||
10103 | x_set_mouse_pixel_position (f, pix_x, pix_y); | |
10104 | } | |
10105 | ||
1bcd16f2 MB |
10106 | void |
10107 | x_set_mouse_pixel_position (f, pix_x, pix_y) | |
10108 | struct frame *f; | |
10109 | int pix_x, pix_y; | |
10110 | { | |
689004fa GV |
10111 | RECT rect; |
10112 | POINT pt; | |
10113 | ||
1bcd16f2 MB |
10114 | BLOCK_INPUT; |
10115 | ||
689004fa GV |
10116 | GetClientRect (FRAME_W32_WINDOW (f), &rect); |
10117 | pt.x = rect.left + pix_x; | |
10118 | pt.y = rect.top + pix_y; | |
10119 | ClientToScreen (FRAME_W32_WINDOW (f), &pt); | |
1bcd16f2 | 10120 | |
689004fa | 10121 | SetCursorPos (pt.x, pt.y); |
1bcd16f2 MB |
10122 | |
10123 | UNBLOCK_INPUT; | |
10124 | } | |
10125 | ||
ee78dc32 GV |
10126 | \f |
10127 | /* focus shifting, raising and lowering. */ | |
10128 | ||
ec48c3a7 | 10129 | void |
ee78dc32 GV |
10130 | x_focus_on_frame (f) |
10131 | struct frame *f; | |
10132 | { | |
689004fa GV |
10133 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
10134 | ||
10135 | /* Give input focus to frame. */ | |
10136 | BLOCK_INPUT; | |
10137 | #if 0 | |
10138 | /* Try not to change its Z-order if possible. */ | |
10139 | if (x_window_to_frame (dpyinfo, GetForegroundWindow ())) | |
10140 | my_set_focus (f, FRAME_W32_WINDOW (f)); | |
10141 | else | |
10142 | #endif | |
ef0e360f | 10143 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa | 10144 | UNBLOCK_INPUT; |
ee78dc32 GV |
10145 | } |
10146 | ||
ec48c3a7 | 10147 | void |
ee78dc32 GV |
10148 | x_unfocus_frame (f) |
10149 | struct frame *f; | |
10150 | { | |
10151 | } | |
10152 | ||
10153 | /* Raise frame F. */ | |
791f420f | 10154 | void |
ee78dc32 GV |
10155 | x_raise_frame (f) |
10156 | struct frame *f; | |
10157 | { | |
689004fa GV |
10158 | BLOCK_INPUT; |
10159 | ||
10160 | /* Strictly speaking, raise-frame should only change the frame's Z | |
10161 | order, leaving input focus unchanged. This is reasonable behaviour | |
10162 | on X where the usual policy is point-to-focus. However, this | |
10163 | behaviour would be very odd on Windows where the usual policy is | |
10164 | click-to-focus. | |
10165 | ||
10166 | On X, if the mouse happens to be over the raised frame, it gets | |
10167 | input focus anyway (so the window with focus will never be | |
10168 | completely obscured) - if not, then just moving the mouse over it | |
10169 | is sufficient to give it focus. On Windows, the user must actually | |
10170 | click on the frame (preferrably the title bar so as not to move | |
10171 | point), which is more awkward. Also, no other Windows program | |
10172 | raises a window to the top but leaves another window (possibly now | |
10173 | completely obscured) with input focus. | |
10174 | ||
10175 | Because there is a system setting on Windows that allows the user | |
10176 | to choose the point to focus policy, we make the strict semantics | |
10177 | optional, but by default we grab focus when raising. */ | |
10178 | ||
10179 | if (NILP (Vw32_grab_focus_on_raise)) | |
ee78dc32 | 10180 | { |
689004fa GV |
10181 | /* The obvious call to my_set_window_pos doesn't work if Emacs is |
10182 | not already the foreground application: the frame is raised | |
10183 | above all other frames belonging to us, but not above the | |
10184 | current top window. To achieve that, we have to resort to this | |
10185 | more cumbersome method. */ | |
10186 | ||
10187 | HDWP handle = BeginDeferWindowPos (2); | |
10188 | if (handle) | |
10189 | { | |
10190 | DeferWindowPos (handle, | |
10191 | FRAME_W32_WINDOW (f), | |
10192 | HWND_TOP, | |
10193 | 0, 0, 0, 0, | |
10194 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
10195 | ||
10196 | DeferWindowPos (handle, | |
10197 | GetForegroundWindow (), | |
10198 | FRAME_W32_WINDOW (f), | |
10199 | 0, 0, 0, 0, | |
10200 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
10201 | ||
10202 | EndDeferWindowPos (handle); | |
10203 | } | |
ee78dc32 | 10204 | } |
689004fa GV |
10205 | else |
10206 | { | |
ef0e360f | 10207 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa GV |
10208 | } |
10209 | ||
10210 | UNBLOCK_INPUT; | |
ee78dc32 GV |
10211 | } |
10212 | ||
10213 | /* Lower frame F. */ | |
791f420f | 10214 | void |
ee78dc32 GV |
10215 | x_lower_frame (f) |
10216 | struct frame *f; | |
10217 | { | |
689004fa GV |
10218 | BLOCK_INPUT; |
10219 | my_set_window_pos (FRAME_W32_WINDOW (f), | |
10220 | HWND_BOTTOM, | |
10221 | 0, 0, 0, 0, | |
10222 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
10223 | UNBLOCK_INPUT; | |
ee78dc32 GV |
10224 | } |
10225 | ||
10226 | static void | |
ec48c3a7 | 10227 | w32_frame_raise_lower (f, raise_flag) |
ee78dc32 | 10228 | FRAME_PTR f; |
ec48c3a7 | 10229 | int raise_flag; |
ee78dc32 | 10230 | { |
7e6ac5b9 AI |
10231 | if (! FRAME_W32_P (f)) |
10232 | return; | |
10233 | ||
ec48c3a7 | 10234 | if (raise_flag) |
ee78dc32 GV |
10235 | x_raise_frame (f); |
10236 | else | |
10237 | x_lower_frame (f); | |
10238 | } | |
10239 | \f | |
10240 | /* Change of visibility. */ | |
10241 | ||
10242 | /* This tries to wait until the frame is really visible. | |
10243 | However, if the window manager asks the user where to position | |
10244 | the frame, this will return before the user finishes doing that. | |
10245 | The frame will not actually be visible at that time, | |
10246 | but it will become visible later when the window manager | |
10247 | finishes with it. */ | |
10248 | ||
ec48c3a7 | 10249 | void |
ee78dc32 GV |
10250 | x_make_frame_visible (f) |
10251 | struct frame *f; | |
10252 | { | |
7f5d1df8 GV |
10253 | Lisp_Object type; |
10254 | ||
ee78dc32 GV |
10255 | BLOCK_INPUT; |
10256 | ||
7f5d1df8 GV |
10257 | type = x_icon_type (f); |
10258 | if (!NILP (type)) | |
10259 | x_bitmap_icon (f, type); | |
10260 | ||
ee78dc32 GV |
10261 | if (! FRAME_VISIBLE_P (f)) |
10262 | { | |
10263 | /* We test FRAME_GARBAGED_P here to make sure we don't | |
10264 | call x_set_offset a second time | |
10265 | if we get to x_make_frame_visible a second time | |
10266 | before the window gets really visible. */ | |
10267 | if (! FRAME_ICONIFIED_P (f) | |
fbd6baed | 10268 | && ! f->output_data.w32->asked_for_visible) |
fbd6baed | 10269 | x_set_offset (f, f->output_data.w32->left_pos, f->output_data.w32->top_pos, 0); |
ee78dc32 | 10270 | |
fbd6baed | 10271 | f->output_data.w32->asked_for_visible = 1; |
52cf03a1 | 10272 | |
689004fa GV |
10273 | // my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW); |
10274 | my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL); | |
ee78dc32 GV |
10275 | } |
10276 | ||
10277 | /* Synchronize to ensure Emacs knows the frame is visible | |
10278 | before we do anything else. We do this loop with input not blocked | |
10279 | so that incoming events are handled. */ | |
10280 | { | |
10281 | Lisp_Object frame; | |
791f420f | 10282 | int count; |
ee78dc32 GV |
10283 | |
10284 | /* This must come after we set COUNT. */ | |
10285 | UNBLOCK_INPUT; | |
10286 | ||
10287 | XSETFRAME (frame, f); | |
10288 | ||
791f420f JR |
10289 | /* Wait until the frame is visible. Process X events until a |
10290 | MapNotify event has been seen, or until we think we won't get a | |
10291 | MapNotify at all.. */ | |
10292 | for (count = input_signal_count + 10; | |
10293 | input_signal_count < count && !FRAME_VISIBLE_P (f);) | |
ee78dc32 | 10294 | { |
791f420f | 10295 | /* Force processing of queued events. */ |
01b220b6 | 10296 | /* TODO: x_sync equivalent? */ |
791f420f | 10297 | |
ee78dc32 GV |
10298 | /* Machines that do polling rather than SIGIO have been observed |
10299 | to go into a busy-wait here. So we'll fake an alarm signal | |
10300 | to let the handler know that there's something to be read. | |
10301 | We used to raise a real alarm, but it seems that the handler | |
10302 | isn't always enabled here. This is probably a bug. */ | |
10303 | if (input_polling_used ()) | |
10304 | { | |
10305 | /* It could be confusing if a real alarm arrives while processing | |
10306 | the fake one. Turn it off and let the handler reset it. */ | |
a9b4e0ec AI |
10307 | int old_poll_suppress_count = poll_suppress_count; |
10308 | poll_suppress_count = 1; | |
10309 | poll_for_input_1 (); | |
10310 | poll_suppress_count = old_poll_suppress_count; | |
ee78dc32 | 10311 | } |
ee78dc32 GV |
10312 | } |
10313 | FRAME_SAMPLE_VISIBILITY (f); | |
10314 | } | |
10315 | } | |
10316 | ||
10317 | /* Change from mapped state to withdrawn state. */ | |
10318 | ||
10319 | /* Make the frame visible (mapped and not iconified). */ | |
10320 | ||
10321 | x_make_frame_invisible (f) | |
10322 | struct frame *f; | |
10323 | { | |
ee78dc32 | 10324 | /* Don't keep the highlight on an invisible frame. */ |
fbd6baed GV |
10325 | if (FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame == f) |
10326 | FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame = 0; | |
ee78dc32 GV |
10327 | |
10328 | BLOCK_INPUT; | |
10329 | ||
689004fa | 10330 | my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE); |
ee78dc32 GV |
10331 | |
10332 | /* We can't distinguish this from iconification | |
10333 | just by the event that we get from the server. | |
10334 | So we can't win using the usual strategy of letting | |
10335 | FRAME_SAMPLE_VISIBILITY set this. So do it by hand, | |
10336 | and synchronize with the server to make sure we agree. */ | |
10337 | f->visible = 0; | |
10338 | FRAME_ICONIFIED_P (f) = 0; | |
10339 | f->async_visible = 0; | |
10340 | f->async_iconified = 0; | |
10341 | ||
10342 | UNBLOCK_INPUT; | |
10343 | } | |
10344 | ||
10345 | /* Change window state from mapped to iconified. */ | |
10346 | ||
52cf03a1 GV |
10347 | void |
10348 | x_iconify_frame (f) | |
ee78dc32 GV |
10349 | struct frame *f; |
10350 | { | |
7f5d1df8 | 10351 | Lisp_Object type; |
ee78dc32 GV |
10352 | |
10353 | /* Don't keep the highlight on an invisible frame. */ | |
fbd6baed GV |
10354 | if (FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame == f) |
10355 | FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame = 0; | |
ee78dc32 GV |
10356 | |
10357 | if (f->async_iconified) | |
10358 | return; | |
10359 | ||
10360 | BLOCK_INPUT; | |
10361 | ||
7f5d1df8 GV |
10362 | type = x_icon_type (f); |
10363 | if (!NILP (type)) | |
10364 | x_bitmap_icon (f, type); | |
10365 | ||
689004fa | 10366 | /* Simulate the user minimizing the frame. */ |
4934bcdd | 10367 | SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0); |
ee78dc32 GV |
10368 | |
10369 | UNBLOCK_INPUT; | |
10370 | } | |
c2cc16fa | 10371 | |
ee78dc32 | 10372 | \f |
25badd7a | 10373 | /* Free X resources of frame F. */ |
ee78dc32 | 10374 | |
25badd7a AI |
10375 | void |
10376 | x_free_frame_resources (f) | |
ee78dc32 GV |
10377 | struct frame *f; |
10378 | { | |
fbd6baed | 10379 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
ee78dc32 GV |
10380 | |
10381 | BLOCK_INPUT; | |
10382 | ||
25badd7a AI |
10383 | if (FRAME_W32_WINDOW (f)) |
10384 | my_destroy_window (f, FRAME_W32_WINDOW (f)); | |
10385 | ||
ee78dc32 | 10386 | free_frame_menubar (f); |
ee78dc32 | 10387 | |
25badd7a AI |
10388 | unload_color (f, f->output_data.x->foreground_pixel); |
10389 | unload_color (f, f->output_data.x->background_pixel); | |
10390 | unload_color (f, f->output_data.w32->cursor_pixel); | |
10391 | unload_color (f, f->output_data.w32->cursor_foreground_pixel); | |
10392 | unload_color (f, f->output_data.w32->border_pixel); | |
10393 | unload_color (f, f->output_data.w32->mouse_pixel); | |
c2cc16fa JR |
10394 | if (f->output_data.w32->white_relief.allocated_p) |
10395 | unload_color (f, f->output_data.w32->white_relief.pixel); | |
10396 | if (f->output_data.w32->black_relief.allocated_p) | |
10397 | unload_color (f, f->output_data.w32->black_relief.pixel); | |
10398 | ||
25badd7a AI |
10399 | if (FRAME_FACE_CACHE (f)) |
10400 | free_frame_faces (f); | |
10401 | ||
fbd6baed | 10402 | xfree (f->output_data.w32); |
25badd7a AI |
10403 | f->output_data.w32 = NULL; |
10404 | ||
fbd6baed GV |
10405 | if (f == dpyinfo->w32_focus_frame) |
10406 | dpyinfo->w32_focus_frame = 0; | |
10407 | if (f == dpyinfo->w32_focus_event_frame) | |
10408 | dpyinfo->w32_focus_event_frame = 0; | |
10409 | if (f == dpyinfo->w32_highlight_frame) | |
10410 | dpyinfo->w32_highlight_frame = 0; | |
ee78dc32 | 10411 | |
ee78dc32 GV |
10412 | if (f == dpyinfo->mouse_face_mouse_frame) |
10413 | { | |
10414 | dpyinfo->mouse_face_beg_row | |
10415 | = dpyinfo->mouse_face_beg_col = -1; | |
10416 | dpyinfo->mouse_face_end_row | |
10417 | = dpyinfo->mouse_face_end_col = -1; | |
10418 | dpyinfo->mouse_face_window = Qnil; | |
25badd7a AI |
10419 | dpyinfo->mouse_face_deferred_gc = 0; |
10420 | dpyinfo->mouse_face_mouse_frame = 0; | |
ee78dc32 GV |
10421 | } |
10422 | ||
10423 | UNBLOCK_INPUT; | |
10424 | } | |
25badd7a AI |
10425 | |
10426 | ||
10427 | /* Destroy the window of frame F. */ | |
10428 | ||
10429 | x_destroy_window (f) | |
10430 | struct frame *f; | |
10431 | { | |
10432 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
10433 | ||
10434 | x_free_frame_resources (f); | |
10435 | ||
10436 | dpyinfo->reference_count--; | |
10437 | } | |
c2cc16fa | 10438 | |
ee78dc32 GV |
10439 | \f |
10440 | /* Setting window manager hints. */ | |
10441 | ||
10442 | /* Set the normal size hints for the window manager, for frame F. | |
10443 | FLAGS is the flags word to use--or 0 meaning preserve the flags | |
10444 | that the window now has. | |
10445 | If USER_POSITION is nonzero, we set the USPosition | |
10446 | flag (this is useful when FLAGS is 0). */ | |
791f420f | 10447 | void |
ee78dc32 GV |
10448 | x_wm_set_size_hint (f, flags, user_position) |
10449 | struct frame *f; | |
10450 | long flags; | |
10451 | int user_position; | |
10452 | { | |
fbd6baed | 10453 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 | 10454 | |
97c23857 | 10455 | enter_crit (); |
ee78dc32 | 10456 | |
689004fa GV |
10457 | SetWindowLong (window, WND_FONTWIDTH_INDEX, FONT_WIDTH (f->output_data.w32->font)); |
10458 | SetWindowLong (window, WND_LINEHEIGHT_INDEX, f->output_data.w32->line_height); | |
10459 | SetWindowLong (window, WND_BORDER_INDEX, f->output_data.w32->internal_border_width); | |
10460 | SetWindowLong (window, WND_SCROLLBAR_INDEX, f->output_data.w32->vertical_scroll_bar_extra); | |
ee78dc32 | 10461 | |
97c23857 | 10462 | leave_crit (); |
ee78dc32 GV |
10463 | } |
10464 | ||
10465 | /* Window manager things */ | |
10466 | x_wm_set_icon_position (f, icon_x, icon_y) | |
10467 | struct frame *f; | |
10468 | int icon_x, icon_y; | |
10469 | { | |
10470 | #if 0 | |
fbd6baed | 10471 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 GV |
10472 | |
10473 | f->display.x->wm_hints.flags |= IconPositionHint; | |
10474 | f->display.x->wm_hints.icon_x = icon_x; | |
10475 | f->display.x->wm_hints.icon_y = icon_y; | |
10476 | ||
10477 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints); | |
10478 | #endif | |
10479 | } | |
10480 | ||
c2cc16fa JR |
10481 | \f |
10482 | /*********************************************************************** | |
10483 | Fonts | |
10484 | ***********************************************************************/ | |
10485 | ||
10486 | /* The following functions are listed here to help diff stay in step | |
10487 | with xterm.c. See w32fns.c for definitions. | |
10488 | ||
10489 | x_get_font_info (f, font_idx) | |
10490 | x_list_fonts (f, pattern, size, maxnames) | |
10491 | ||
10492 | */ | |
10493 | ||
10494 | #if GLYPH_DEBUG | |
10495 | ||
10496 | /* Check that FONT is valid on frame F. It is if it can be found in F's | |
10497 | font table. */ | |
10498 | ||
10499 | static void | |
10500 | x_check_font (f, font) | |
10501 | struct frame *f; | |
10502 | XFontStruct *font; | |
10503 | { | |
10504 | int i; | |
10505 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
10506 | ||
10507 | xassert (font != NULL); | |
9ef2e2cf | 10508 | |
c2cc16fa JR |
10509 | for (i = 0; i < dpyinfo->n_fonts; i++) |
10510 | if (dpyinfo->font_table[i].name | |
10511 | && font == dpyinfo->font_table[i].font) | |
10512 | break; | |
10513 | ||
10514 | xassert (i < dpyinfo->n_fonts); | |
10515 | } | |
10516 | ||
10517 | #endif /* GLYPH_DEBUG != 0 */ | |
10518 | ||
10519 | /* Set *W to the minimum width, *H to the minimum font height of FONT. | |
10520 | Note: There are (broken) X fonts out there with invalid XFontStruct | |
10521 | min_bounds contents. For example, handa@etl.go.jp reports that | |
10522 | "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts | |
10523 | have font->min_bounds.width == 0. */ | |
10524 | ||
10525 | static INLINE void | |
10526 | x_font_min_bounds (font, w, h) | |
10527 | XFontStruct *font; | |
10528 | int *w, *h; | |
10529 | { | |
10530 | /* | |
10531 | * TODO: Windows does not appear to offer min bound, only | |
10532 | * average and maximum width, and maximum height. | |
10533 | */ | |
10534 | *h = FONT_HEIGHT (font); | |
10535 | *w = FONT_WIDTH (font); | |
10536 | } | |
10537 | ||
10538 | ||
10539 | /* Compute the smallest character width and smallest font height over | |
10540 | all fonts available on frame F. Set the members smallest_char_width | |
10541 | and smallest_font_height in F's x_display_info structure to | |
10542 | the values computed. Value is non-zero if smallest_font_height or | |
10543 | smallest_char_width become smaller than they were before. */ | |
10544 | ||
10545 | int | |
10546 | x_compute_min_glyph_bounds (f) | |
10547 | struct frame *f; | |
10548 | { | |
10549 | int i; | |
10550 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
10551 | XFontStruct *font; | |
10552 | int old_width = dpyinfo->smallest_char_width; | |
10553 | int old_height = dpyinfo->smallest_font_height; | |
10554 | ||
10555 | dpyinfo->smallest_font_height = 100000; | |
10556 | dpyinfo->smallest_char_width = 100000; | |
10557 | ||
10558 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
10559 | if (dpyinfo->font_table[i].name) | |
10560 | { | |
10561 | struct font_info *fontp = dpyinfo->font_table + i; | |
10562 | int w, h; | |
10563 | ||
10564 | font = (XFontStruct *) fontp->font; | |
10565 | xassert (font != (XFontStruct *) ~0); | |
10566 | x_font_min_bounds (font, &w, &h); | |
10567 | ||
10568 | dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h); | |
10569 | dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w); | |
10570 | } | |
10571 | ||
10572 | xassert (dpyinfo->smallest_char_width > 0 | |
10573 | && dpyinfo->smallest_font_height > 0); | |
10574 | ||
10575 | return (dpyinfo->n_fonts == 1 | |
10576 | || dpyinfo->smallest_char_width < old_width | |
10577 | || dpyinfo->smallest_font_height < old_height); | |
10578 | } | |
10579 | ||
10580 | /* The following functions are listed here to help diff stay in step | |
10581 | with xterm.c. See w32fns.c for definitions. | |
10582 | ||
10583 | x_load_font (f, fontname, size) | |
10584 | x_query_font (f, fontname) | |
10585 | x_find_ccl_program (fontp) | |
10586 | ||
10587 | */ | |
ee78dc32 | 10588 | \f |
791f420f JR |
10589 | /*********************************************************************** |
10590 | Initialization | |
10591 | ***********************************************************************/ | |
ee78dc32 | 10592 | |
fbd6baed | 10593 | static int w32_initialized = 0; |
ee78dc32 | 10594 | |
f7737f5d JR |
10595 | void |
10596 | w32_initialize_display_info (display_name) | |
10597 | Lisp_Object display_name; | |
10598 | { | |
10599 | struct w32_display_info *dpyinfo = &one_w32_display_info; | |
10600 | ||
10601 | bzero (dpyinfo, sizeof (*dpyinfo)); | |
10602 | ||
10603 | /* Put it on w32_display_name_list. */ | |
10604 | w32_display_name_list = Fcons (Fcons (display_name, Qnil), | |
10605 | w32_display_name_list); | |
10606 | dpyinfo->name_list_element = XCAR (w32_display_name_list); | |
10607 | ||
10608 | dpyinfo->w32_id_name | |
10609 | = (char *) xmalloc (XSTRING (Vinvocation_name)->size | |
10610 | + XSTRING (Vsystem_name)->size | |
10611 | + 2); | |
10612 | sprintf (dpyinfo->w32_id_name, "%s@%s", | |
10613 | XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data); | |
10614 | ||
10615 | /* Default Console mode values - overridden when running in GUI mode | |
10616 | with values obtained from system metrics. */ | |
10617 | dpyinfo->resx = 1; | |
10618 | dpyinfo->resy = 1; | |
10619 | dpyinfo->height_in = 1; | |
10620 | dpyinfo->width_in = 1; | |
10621 | dpyinfo->n_planes = 1; | |
10622 | dpyinfo->n_cbits = 4; | |
10623 | dpyinfo->n_fonts = 0; | |
10624 | dpyinfo->smallest_font_height = 1; | |
10625 | dpyinfo->smallest_char_width = 1; | |
10626 | ||
10627 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
10628 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
10629 | dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; | |
10630 | dpyinfo->mouse_face_window = Qnil; | |
9f5a911b | 10631 | dpyinfo->mouse_face_overlay = Qnil; |
01b220b6 | 10632 | /* TODO: dpyinfo->gray */ |
f7737f5d JR |
10633 | |
10634 | } | |
10635 | ||
fbd6baed GV |
10636 | struct w32_display_info * |
10637 | w32_term_init (display_name, xrm_option, resource_name) | |
ee78dc32 GV |
10638 | Lisp_Object display_name; |
10639 | char *xrm_option; | |
10640 | char *resource_name; | |
10641 | { | |
fbd6baed | 10642 | struct w32_display_info *dpyinfo; |
ee78dc32 | 10643 | HDC hdc; |
97c23857 | 10644 | |
ee78dc32 GV |
10645 | BLOCK_INPUT; |
10646 | ||
fbd6baed | 10647 | if (!w32_initialized) |
ee78dc32 | 10648 | { |
fbd6baed GV |
10649 | w32_initialize (); |
10650 | w32_initialized = 1; | |
ee78dc32 GV |
10651 | } |
10652 | ||
10653 | { | |
10654 | int argc = 0; | |
10655 | char *argv[3]; | |
10656 | ||
10657 | argv[0] = ""; | |
10658 | argc = 1; | |
10659 | if (xrm_option) | |
10660 | { | |
10661 | argv[argc++] = "-xrm"; | |
10662 | argv[argc++] = xrm_option; | |
10663 | } | |
10664 | } | |
10665 | ||
f7737f5d | 10666 | w32_initialize_display_info (display_name); |
ee78dc32 | 10667 | |
f7737f5d | 10668 | dpyinfo = &one_w32_display_info; |
8c3b00cb AI |
10669 | |
10670 | /* Put this display on the chain. */ | |
10671 | dpyinfo->next = x_display_list; | |
10672 | x_display_list = dpyinfo; | |
ee78dc32 | 10673 | |
52cf03a1 | 10674 | hdc = GetDC (GetDesktopWindow ()); |
791f420f | 10675 | |
ee78dc32 GV |
10676 | dpyinfo->height = GetDeviceCaps (hdc, VERTRES); |
10677 | dpyinfo->width = GetDeviceCaps (hdc, HORZRES); | |
10678 | dpyinfo->root_window = GetDesktopWindow (); | |
10679 | dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES); | |
10680 | dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL); | |
55689ab1 JR |
10681 | dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX); |
10682 | dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY); | |
52cf03a1 | 10683 | dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE; |
791f420f | 10684 | dpyinfo->image_cache = make_image_cache (); |
55689ab1 JR |
10685 | dpyinfo->height_in = dpyinfo->height / dpyinfo->resx; |
10686 | dpyinfo->width_in = dpyinfo->width / dpyinfo->resy; | |
ee78dc32 | 10687 | ReleaseDC (GetDesktopWindow (), hdc); |
52cf03a1 GV |
10688 | |
10689 | /* initialise palette with white and black */ | |
10690 | { | |
10691 | COLORREF color; | |
55689ab1 JR |
10692 | w32_defined_color (0, "white", &color, 1); |
10693 | w32_defined_color (0, "black", &color, 1); | |
52cf03a1 GV |
10694 | } |
10695 | ||
f7737f5d JR |
10696 | /* Create Row Bitmaps and store them for later use. */ |
10697 | left_bmp = CreateBitmap (left_width, left_height, 1, 1, left_bits); | |
10698 | ov_bmp = CreateBitmap (ov_width, ov_height, 1, 1, ov_bits); | |
10699 | right_bmp = CreateBitmap (right_width, right_height, 1, 1, right_bits); | |
10700 | continued_bmp = CreateBitmap (continued_width, continued_height, 1, | |
10701 | 1, continued_bits); | |
10702 | continuation_bmp = CreateBitmap (continuation_width, continuation_height, | |
10703 | 1, 1, continuation_bits); | |
10704 | zv_bmp = CreateBitmap (zv_width, zv_height, 1, 1, zv_bits); | |
10705 | ||
ee78dc32 GV |
10706 | #ifndef F_SETOWN_BUG |
10707 | #ifdef F_SETOWN | |
10708 | #ifdef F_SETOWN_SOCK_NEG | |
10709 | /* stdin is a socket here */ | |
10710 | fcntl (connection, F_SETOWN, -getpid ()); | |
10711 | #else /* ! defined (F_SETOWN_SOCK_NEG) */ | |
10712 | fcntl (connection, F_SETOWN, getpid ()); | |
10713 | #endif /* ! defined (F_SETOWN_SOCK_NEG) */ | |
10714 | #endif /* ! defined (F_SETOWN) */ | |
10715 | #endif /* F_SETOWN_BUG */ | |
10716 | ||
10717 | #ifdef SIGIO | |
10718 | if (interrupt_input) | |
10719 | init_sigio (connection); | |
10720 | #endif /* ! defined (SIGIO) */ | |
10721 | ||
10722 | UNBLOCK_INPUT; | |
10723 | ||
10724 | return dpyinfo; | |
10725 | } | |
10726 | \f | |
10727 | /* Get rid of display DPYINFO, assuming all frames are already gone. */ | |
10728 | ||
10729 | void | |
10730 | x_delete_display (dpyinfo) | |
fbd6baed | 10731 | struct w32_display_info *dpyinfo; |
ee78dc32 | 10732 | { |
fbd6baed | 10733 | /* Discard this display from w32_display_name_list and w32_display_list. |
ee78dc32 | 10734 | We can't use Fdelq because that can quit. */ |
fbd6baed | 10735 | if (! NILP (w32_display_name_list) |
8e713be6 KR |
10736 | && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element)) |
10737 | w32_display_name_list = XCDR (w32_display_name_list); | |
ee78dc32 GV |
10738 | else |
10739 | { | |
10740 | Lisp_Object tail; | |
10741 | ||
fbd6baed | 10742 | tail = w32_display_name_list; |
8e713be6 | 10743 | while (CONSP (tail) && CONSP (XCDR (tail))) |
ee78dc32 | 10744 | { |
f7737f5d | 10745 | if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element)) |
ee78dc32 | 10746 | { |
f3fbd155 | 10747 | XSETCDR (tail, XCDR (XCDR (tail))); |
ee78dc32 GV |
10748 | break; |
10749 | } | |
8e713be6 | 10750 | tail = XCDR (tail); |
ee78dc32 GV |
10751 | } |
10752 | } | |
10753 | ||
52cf03a1 GV |
10754 | /* free palette table */ |
10755 | { | |
fbd6baed | 10756 | struct w32_palette_entry * plist; |
52cf03a1 GV |
10757 | |
10758 | plist = dpyinfo->color_list; | |
10759 | while (plist) | |
10760 | { | |
fbd6baed | 10761 | struct w32_palette_entry * pentry = plist; |
52cf03a1 | 10762 | plist = plist->next; |
9127e20e | 10763 | xfree (pentry); |
52cf03a1 GV |
10764 | } |
10765 | dpyinfo->color_list = NULL; | |
10766 | if (dpyinfo->palette) | |
10767 | DeleteObject(dpyinfo->palette); | |
10768 | } | |
ee78dc32 | 10769 | xfree (dpyinfo->font_table); |
fbd6baed | 10770 | xfree (dpyinfo->w32_id_name); |
f7737f5d JR |
10771 | |
10772 | /* Destroy row bitmaps. */ | |
10773 | DeleteObject (left_bmp); | |
10774 | DeleteObject (ov_bmp); | |
10775 | DeleteObject (right_bmp); | |
10776 | DeleteObject (continued_bmp); | |
10777 | DeleteObject (continuation_bmp); | |
10778 | DeleteObject (zv_bmp); | |
ee78dc32 GV |
10779 | } |
10780 | \f | |
fbd6baed | 10781 | /* Set up use of W32. */ |
ee78dc32 | 10782 | |
689004fa | 10783 | DWORD w32_msg_worker (); |
ee78dc32 | 10784 | |
791f420f JR |
10785 | void |
10786 | x_flush (struct frame * f) | |
10787 | { /* Nothing to do */ } | |
10788 | ||
10789 | static struct redisplay_interface w32_redisplay_interface = | |
10790 | { | |
10791 | x_produce_glyphs, | |
10792 | x_write_glyphs, | |
10793 | x_insert_glyphs, | |
10794 | x_clear_end_of_line, | |
10795 | x_scroll_run, | |
10796 | x_after_update_window_line, | |
10797 | x_update_window_begin, | |
10798 | x_update_window_end, | |
10799 | w32_cursor_to, | |
10800 | x_flush, | |
ec48c3a7 | 10801 | x_clear_mouse_face, |
791f420f JR |
10802 | x_get_glyph_overhangs, |
10803 | x_fix_overlapping_area | |
10804 | }; | |
10805 | ||
10806 | void | |
fbd6baed GV |
10807 | w32_initialize () |
10808 | { | |
791f420f JR |
10809 | rif = &w32_redisplay_interface; |
10810 | ||
96214669 GV |
10811 | /* MSVC does not type K&R functions with no arguments correctly, and |
10812 | so we must explicitly cast them. */ | |
791f420f | 10813 | clear_frame_hook = (void (*)(void)) x_clear_frame; |
96214669 | 10814 | ring_bell_hook = (void (*)(void)) w32_ring_bell; |
791f420f JR |
10815 | update_begin_hook = x_update_begin; |
10816 | update_end_hook = x_update_end; | |
0f32f023 | 10817 | |
ee78dc32 | 10818 | read_socket_hook = w32_read_socket; |
0f32f023 | 10819 | |
fbd6baed | 10820 | frame_up_to_date_hook = w32_frame_up_to_date; |
0f32f023 | 10821 | |
fbd6baed GV |
10822 | mouse_position_hook = w32_mouse_position; |
10823 | frame_rehighlight_hook = w32_frame_rehighlight; | |
10824 | frame_raise_lower_hook = w32_frame_raise_lower; | |
10825 | set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar; | |
10826 | condemn_scroll_bars_hook = w32_condemn_scroll_bars; | |
10827 | redeem_scroll_bar_hook = w32_redeem_scroll_bar; | |
10828 | judge_scroll_bars_hook = w32_judge_scroll_bars; | |
791f420f | 10829 | estimate_mode_line_height_hook = x_estimate_mode_line_height; |
ee78dc32 GV |
10830 | |
10831 | scroll_region_ok = 1; /* we'll scroll partial frames */ | |
49be9f70 | 10832 | char_ins_del_ok = 1; |
ee78dc32 GV |
10833 | line_ins_del_ok = 1; /* we'll just blt 'em */ |
10834 | fast_clear_end_of_line = 1; /* X does this well */ | |
10835 | memory_below_frame = 0; /* we don't remember what scrolls | |
10836 | off the bottom */ | |
10837 | baud_rate = 19200; | |
10838 | ||
abb15ebd JR |
10839 | w32_system_caret_hwnd = NULL; |
10840 | w32_system_caret_height = 0; | |
10841 | w32_system_caret_width = 0; | |
10842 | w32_system_caret_x = 0; | |
10843 | w32_system_caret_y = 0; | |
10844 | ||
791f420f JR |
10845 | last_tool_bar_item = -1; |
10846 | any_help_event_p = 0; | |
10847 | ||
689004fa GV |
10848 | /* Initialize input mode: interrupt_input off, no flow control, allow |
10849 | 8 bit character input, standard quit char. */ | |
10850 | Fset_input_mode (Qnil, Qnil, make_number (2), Qnil); | |
ee78dc32 GV |
10851 | |
10852 | /* Create the window thread - it will terminate itself or when the app terminates */ | |
10853 | ||
10854 | init_crit (); | |
10855 | ||
10856 | dwMainThreadId = GetCurrentThreadId (); | |
10857 | DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), | |
10858 | GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS); | |
10859 | ||
10860 | /* Wait for thread to start */ | |
10861 | ||
10862 | { | |
10863 | MSG msg; | |
10864 | ||
10865 | PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); | |
10866 | ||
e9e23e23 | 10867 | hWindowsThread = CreateThread (NULL, 0, |
689004fa | 10868 | (LPTHREAD_START_ROUTINE) w32_msg_worker, |
e9e23e23 | 10869 | 0, 0, &dwWindowsThreadId); |
ee78dc32 GV |
10870 | |
10871 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
10872 | } | |
10873 | ||
52cf03a1 | 10874 | /* It is desirable that mainThread should have the same notion of |
e9e23e23 | 10875 | focus window and active window as windowsThread. Unfortunately, the |
52cf03a1 GV |
10876 | following call to AttachThreadInput, which should do precisely what |
10877 | we need, causes major problems when Emacs is linked as a console | |
10878 | program. Unfortunately, we have good reasons for doing that, so | |
e9e23e23 | 10879 | instead we need to send messages to windowsThread to make some API |
52cf03a1 GV |
10880 | calls for us (ones that affect, or depend on, the active/focus |
10881 | window state. */ | |
10882 | #ifdef ATTACH_THREADS | |
e9e23e23 | 10883 | AttachThreadInput (dwMainThreadId, dwWindowsThreadId, TRUE); |
52cf03a1 | 10884 | #endif |
689004fa GV |
10885 | |
10886 | /* Dynamically link to optional system components. */ | |
10887 | { | |
10888 | HANDLE user_lib = LoadLibrary ("user32.dll"); | |
10889 | ||
10890 | #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn) | |
10891 | ||
10892 | /* New proportional scroll bar functions. */ | |
9127e20e JR |
10893 | LOAD_PROC (SetScrollInfo); |
10894 | LOAD_PROC (GetScrollInfo); | |
689004fa GV |
10895 | |
10896 | #undef LOAD_PROC | |
10897 | ||
10898 | FreeLibrary (user_lib); | |
10899 | ||
10900 | /* If using proportional scroll bars, ensure handle is at least 5 pixels; | |
10901 | otherwise use the fixed height. */ | |
10902 | vertical_scroll_bar_min_handle = (pfnSetScrollInfo != NULL) ? 5 : | |
10903 | GetSystemMetrics (SM_CYVTHUMB); | |
10904 | ||
10905 | /* For either kind of scroll bar, take account of the arrows; these | |
10906 | effectively form the border of the main scroll bar range. */ | |
10907 | vertical_scroll_bar_top_border = vertical_scroll_bar_bottom_border | |
10908 | = GetSystemMetrics (SM_CYVSCROLL); | |
10909 | } | |
ee78dc32 GV |
10910 | } |
10911 | ||
10912 | void | |
fbd6baed | 10913 | syms_of_w32term () |
ee78dc32 | 10914 | { |
fbd6baed GV |
10915 | staticpro (&w32_display_name_list); |
10916 | w32_display_name_list = Qnil; | |
ee78dc32 GV |
10917 | |
10918 | staticpro (&last_mouse_scroll_bar); | |
10919 | last_mouse_scroll_bar = Qnil; | |
10920 | ||
10921 | staticpro (&Qvendor_specific_keysyms); | |
10922 | Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); | |
52cf03a1 | 10923 | |
fbd6baed GV |
10924 | DEFVAR_INT ("w32-num-mouse-buttons", |
10925 | &Vw32_num_mouse_buttons, | |
52cf03a1 | 10926 | "Number of physical mouse buttons."); |
fbd6baed | 10927 | Vw32_num_mouse_buttons = Qnil; |
52cf03a1 | 10928 | |
fbd6baed GV |
10929 | DEFVAR_LISP ("w32-swap-mouse-buttons", |
10930 | &Vw32_swap_mouse_buttons, | |
52cf03a1 GV |
10931 | "Swap the mapping of middle and right mouse buttons.\n\ |
10932 | When nil, middle button is mouse-2 and right button is mouse-3."); | |
fbd6baed | 10933 | Vw32_swap_mouse_buttons = Qnil; |
689004fa GV |
10934 | |
10935 | DEFVAR_LISP ("w32-grab-focus-on-raise", | |
10936 | &Vw32_grab_focus_on_raise, | |
10937 | "Raised frame grabs input focus.\n\ | |
10938 | When t, `raise-frame' grabs input focus as well. This fits well\n\ | |
10939 | with the normal Windows click-to-focus policy, but might not be\n\ | |
10940 | desirable when using a point-to-focus policy."); | |
10941 | Vw32_grab_focus_on_raise = Qt; | |
10942 | ||
10943 | DEFVAR_LISP ("w32-capslock-is-shiftlock", | |
10944 | &Vw32_capslock_is_shiftlock, | |
10945 | "Apply CapsLock state to non character input keys.\n\ | |
10946 | When nil, CapsLock only affects normal character input keys."); | |
10947 | Vw32_capslock_is_shiftlock = Qnil; | |
ef0e360f GV |
10948 | |
10949 | DEFVAR_LISP ("w32-recognize-altgr", | |
10950 | &Vw32_recognize_altgr, | |
10951 | "Recognize right-alt and left-ctrl as AltGr.\n\ | |
10952 | When nil, the right-alt and left-ctrl key combination is\n\ | |
10953 | interpreted normally."); | |
10954 | Vw32_recognize_altgr = Qt; | |
bc6af935 | 10955 | |
484fa2c1 GV |
10956 | DEFVAR_BOOL ("w32-enable-unicode-output", |
10957 | &w32_enable_unicode_output, | |
10958 | "Enable the use of Unicode for text output if non-nil.\n\ | |
cabb23bc GV |
10959 | Unicode output may prevent some third party applications for displaying\n\ |
10960 | Far-East Languages on Windows 95/98 from working properly.\n\ | |
10961 | NT uses Unicode internally anyway, so this flag will probably have no\n\ | |
10962 | affect on NT machines."); | |
484fa2c1 | 10963 | w32_enable_unicode_output = 1; |
a1b9438c | 10964 | |
791f420f | 10965 | help_echo = Qnil; |
ec48c3a7 JR |
10966 | staticpro (&help_echo); |
10967 | help_echo_object = Qnil; | |
10968 | staticpro (&help_echo_object); | |
158cba56 JR |
10969 | help_echo_window = Qnil; |
10970 | staticpro (&help_echo_window); | |
791f420f | 10971 | previous_help_echo = Qnil; |
ec48c3a7 | 10972 | staticpro (&previous_help_echo); |
158cba56 | 10973 | help_echo_pos = -1; |
791f420f JR |
10974 | |
10975 | DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p, | |
10976 | "*Non-nil means draw block cursor as wide as the glyph under it.\n\ | |
10977 | For example, if a block cursor is over a tab, it will be drawn as\n\ | |
10978 | wide as that tab on the display."); | |
10979 | x_stretch_cursor_p = 0; | |
10980 | ||
9f5a911b JR |
10981 | #if 0 /* TODO: Setting underline position from font properties. */ |
10982 | DEFVAR_BOOL ("x-use-underline-position-properties", | |
10983 | &x_use_underline_position_properties, | |
10984 | "*Non-nil means make use of UNDERLINE_POSITION font properties.\n\ | |
10985 | Nil means ignore them. If you encounter fonts with bogus\n\ | |
10986 | UNDERLINE_POSITION font properties, for example 7x13 on XFree prior\n\ | |
10987 | to 4.1, set this to nil."); | |
10988 | x_use_underline_position_properties = 1; | |
10989 | #endif | |
10990 | ||
5bf04520 | 10991 | DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, |
791f420f | 10992 | "If not nil, Emacs uses toolkit scroll bars."); |
5bf04520 | 10993 | Vx_toolkit_scroll_bars = Qt; |
791f420f JR |
10994 | |
10995 | staticpro (&last_mouse_motion_frame); | |
10996 | last_mouse_motion_frame = Qnil; | |
ee78dc32 | 10997 | } |