Commit | Line | Data |
---|---|---|
e9e23e23 | 1 | /* Implementation of GUI terminal on the Microsoft W32 API. |
9ef2e2cf JR |
2 | Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000 |
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" |
ee78dc32 GV |
38 | |
39 | #include <ctype.h> | |
40 | #include <errno.h> | |
41 | #include <setjmp.h> | |
42 | #include <sys/stat.h> | |
43 | ||
38006079 | 44 | #include "keyboard.h" |
ee78dc32 GV |
45 | #include "frame.h" |
46 | #include "dispextern.h" | |
93ff4395 | 47 | #include "fontset.h" |
ee78dc32 GV |
48 | #include "termhooks.h" |
49 | #include "termopts.h" | |
50 | #include "termchar.h" | |
51 | #include "gnu.h" | |
52 | #include "disptab.h" | |
53 | #include "buffer.h" | |
54 | #include "window.h" | |
ee78dc32 | 55 | #include "intervals.h" |
791f420f | 56 | #include "composite.h" |
ef0e360f | 57 | #include "coding.h" |
ee78dc32 | 58 | |
03887dd3 KH |
59 | #undef min |
60 | #undef max | |
61 | #define min(x, y) (((x) < (y)) ? (x) : (y)) | |
62 | #define max(x, y) (((x) > (y)) ? (x) : (y)) | |
63 | ||
791f420f JR |
64 | #define abs(x) ((x) < 0 ? -(x) : (x)) |
65 | ||
66 | #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER)) | |
67 | ||
68 | \f | |
69 | /* Bitmaps for truncated lines. */ | |
70 | ||
71 | enum bitmap_type | |
72 | { | |
73 | NO_BITMAP, | |
74 | LEFT_TRUNCATION_BITMAP, | |
75 | RIGHT_TRUNCATION_BITMAP, | |
76 | OVERLAY_ARROW_BITMAP, | |
77 | CONTINUED_LINE_BITMAP, | |
78 | CONTINUATION_LINE_BITMAP, | |
79 | ZV_LINE_BITMAP | |
80 | }; | |
81 | ||
82 | /* Bitmaps are all unsigned short, as Windows requires bitmap data to | |
83 | be Word aligned. For some reason they are horizontally reflected | |
84 | compared to how they appear on X, so changes in xterm.c should be | |
85 | reflected here. */ | |
86 | ||
87 | /* Bitmap drawn to indicate lines not displaying text if | |
88 | `indicate-empty-lines' is non-nil. */ | |
89 | ||
90 | #define zv_width 8 | |
91 | #define zv_height 8 | |
92 | static unsigned short zv_bits[] = { | |
93 | 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00}; | |
f7737f5d | 94 | static HBITMAP zv_bmp; |
791f420f JR |
95 | |
96 | /* An arrow like this: `<-'. */ | |
97 | ||
98 | #define left_width 8 | |
99 | #define left_height 8 | |
100 | static unsigned short left_bits[] = { | |
101 | 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18}; | |
f7737f5d | 102 | static HBITMAP left_bmp; |
791f420f JR |
103 | |
104 | /* Right truncation arrow bitmap `->'. */ | |
105 | ||
106 | #define right_width 8 | |
107 | #define right_height 8 | |
108 | static unsigned short right_bits[] = { | |
109 | 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18}; | |
f7737f5d | 110 | static HBITMAP right_bmp; |
791f420f JR |
111 | |
112 | /* Marker for continued lines. */ | |
113 | ||
114 | #define continued_width 8 | |
115 | #define continued_height 8 | |
116 | static unsigned short continued_bits[] = { | |
117 | 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e}; | |
f7737f5d | 118 | static HBITMAP continued_bmp; |
791f420f JR |
119 | |
120 | /* Marker for continuation lines. */ | |
121 | ||
122 | #define continuation_width 8 | |
123 | #define continuation_height 8 | |
124 | static unsigned short continuation_bits[] = { | |
125 | 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c}; | |
f7737f5d | 126 | static HBITMAP continuation_bmp; |
791f420f JR |
127 | |
128 | /* Overlay arrow bitmap. */ | |
129 | ||
130 | #if 0 | |
131 | /* A bomb. */ | |
132 | #define ov_width 8 | |
133 | #define ov_height 8 | |
134 | static unsigned short ov_bits[] = { | |
135 | 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c}; | |
136 | #else | |
137 | /* A triangular arrow. */ | |
138 | #define ov_width 8 | |
139 | #define ov_height 8 | |
140 | static unsigned short ov_bits[] = { | |
141 | 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0}; | |
791f420f | 142 | #endif |
f7737f5d | 143 | static HBITMAP ov_bmp; |
791f420f JR |
144 | |
145 | extern Lisp_Object Qhelp_echo; | |
146 | ||
147 | \f | |
148 | /* Non-zero means Emacs uses toolkit scroll bars. */ | |
149 | ||
150 | int x_toolkit_scroll_bars_p; | |
151 | ||
152 | /* If a string, w32_read_socket generates an event to display that string. | |
153 | (The display is done in read_char.) */ | |
154 | ||
155 | static Lisp_Object help_echo; | |
158cba56 | 156 | static Lisp_Object help_echo_window; |
ec48c3a7 JR |
157 | static Lisp_Object help_echo_object; |
158 | static int help_echo_pos; | |
791f420f JR |
159 | |
160 | /* Temporary variable for w32_read_socket. */ | |
161 | ||
162 | static Lisp_Object previous_help_echo; | |
163 | ||
164 | /* Non-zero means that a HELP_EVENT has been generated since Emacs | |
165 | start. */ | |
166 | ||
167 | static int any_help_event_p; | |
168 | ||
169 | /* Non-zero means draw block and hollow cursor as wide as the glyph | |
170 | under it. For example, if a block cursor is over a tab, it will be | |
171 | drawn as wide as that tab on the display. */ | |
172 | ||
173 | int x_stretch_cursor_p; | |
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; | |
ee78dc32 GV |
193 | |
194 | /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE), | |
fbd6baed | 195 | one for each element of w32_display_list and in the same order. |
ee78dc32 GV |
196 | NAME is the name of the frame. |
197 | FONT-LIST-CACHE records previous values returned by x-list-fonts. */ | |
fbd6baed | 198 | Lisp_Object w32_display_name_list; |
ee78dc32 GV |
199 | |
200 | /* Frame being updated by update_frame. This is declared in term.c. | |
201 | This is set by update_begin and looked at by all the | |
fbd6baed | 202 | w32 functions. It is zero while not inside an update. |
791f420f | 203 | In that case, the w32 functions assume that `SELECTED_FRAME ()' |
ee78dc32 GV |
204 | is the frame to apply to. */ |
205 | extern struct frame *updating_frame; | |
206 | ||
207 | /* This is a frame waiting to be autoraised, within w32_read_socket. */ | |
208 | struct frame *pending_autoraise_frame; | |
209 | ||
ee78dc32 | 210 | /* Nominal cursor position -- where to draw output. |
791f420f JR |
211 | HPOS and VPOS are window relative glyph matrix coordinates. |
212 | X and Y are window relative pixel coordinates. */ | |
ee78dc32 | 213 | |
791f420f | 214 | struct cursor_pos output_cursor; |
ee78dc32 | 215 | |
484fa2c1 | 216 | /* Flag to enable Unicode output in case users wish to use programs |
cabb23bc GV |
217 | like Twinbridge on '95 rather than installed system level support |
218 | for Far East languages. */ | |
484fa2c1 | 219 | int w32_enable_unicode_output; |
cabb23bc | 220 | |
e9e23e23 GV |
221 | DWORD dwWindowsThreadId = 0; |
222 | HANDLE hWindowsThread = NULL; | |
ee78dc32 GV |
223 | DWORD dwMainThreadId = 0; |
224 | HANDLE hMainThread = NULL; | |
225 | ||
689004fa GV |
226 | #ifndef SIF_ALL |
227 | /* These definitions are new with Windows 95. */ | |
228 | #define SIF_RANGE 0x0001 | |
229 | #define SIF_PAGE 0x0002 | |
230 | #define SIF_POS 0x0004 | |
231 | #define SIF_DISABLENOSCROLL 0x0008 | |
232 | #define SIF_TRACKPOS 0x0010 | |
233 | #define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS) | |
234 | ||
235 | typedef struct tagSCROLLINFO | |
236 | { | |
237 | UINT cbSize; | |
238 | UINT fMask; | |
239 | int nMin; | |
240 | int nMax; | |
241 | UINT nPage; | |
242 | int nPos; | |
243 | int nTrackPos; | |
244 | } SCROLLINFO, FAR *LPSCROLLINFO; | |
245 | typedef SCROLLINFO CONST FAR *LPCSCROLLINFO; | |
246 | #endif /* SIF_ALL */ | |
247 | ||
248 | /* Dynamic linking to new proportional scroll bar functions. */ | |
249 | int (PASCAL *pfnSetScrollInfo) (HWND hwnd, int fnBar, LPSCROLLINFO lpsi, BOOL fRedraw); | |
250 | BOOL (PASCAL *pfnGetScrollInfo) (HWND hwnd, int fnBar, LPSCROLLINFO lpsi); | |
251 | ||
252 | int vertical_scroll_bar_min_handle; | |
253 | int vertical_scroll_bar_top_border; | |
254 | int vertical_scroll_bar_bottom_border; | |
255 | ||
256 | int last_scroll_bar_drag_pos; | |
257 | ||
ee78dc32 GV |
258 | /* Mouse movement. */ |
259 | ||
260 | /* Where the mouse was last time we reported a mouse event. */ | |
9ef2e2cf | 261 | |
791f420f | 262 | FRAME_PTR last_mouse_frame; |
ee78dc32 | 263 | static RECT last_mouse_glyph; |
791f420f | 264 | static Lisp_Object last_mouse_press_frame; |
ee78dc32 | 265 | |
fbd6baed | 266 | Lisp_Object Vw32_num_mouse_buttons; |
52cf03a1 | 267 | |
fbd6baed | 268 | Lisp_Object Vw32_swap_mouse_buttons; |
52cf03a1 | 269 | |
689004fa GV |
270 | /* Control whether x_raise_frame also sets input focus. */ |
271 | Lisp_Object Vw32_grab_focus_on_raise; | |
272 | ||
273 | /* Control whether Caps Lock affects non-ascii characters. */ | |
274 | Lisp_Object Vw32_capslock_is_shiftlock; | |
275 | ||
ef0e360f GV |
276 | /* Control whether right-alt and left-ctrl should be recognized as AltGr. */ |
277 | Lisp_Object Vw32_recognize_altgr; | |
278 | ||
ee78dc32 GV |
279 | /* The scroll bar in which the last motion event occurred. |
280 | ||
281 | If the last motion event occurred in a scroll bar, we set this | |
fbd6baed | 282 | so w32_mouse_position can know whether to report a scroll bar motion or |
ee78dc32 GV |
283 | an ordinary motion. |
284 | ||
285 | If the last motion event didn't occur in a scroll bar, we set this | |
fbd6baed | 286 | to Qnil, to tell w32_mouse_position to return an ordinary motion event. */ |
9ef2e2cf JR |
287 | static Lisp_Object last_mouse_scroll_bar; |
288 | static int last_mouse_scroll_bar_pos; | |
ee78dc32 | 289 | |
fbd6baed | 290 | /* This is a hack. We would really prefer that w32_mouse_position would |
ee78dc32 | 291 | return the time associated with the position it returns, but there |
9ef2e2cf | 292 | doesn't seem to be any way to wrest the time-stamp from the server |
ee78dc32 GV |
293 | along with the position query. So, we just keep track of the time |
294 | of the last movement we received, and return that in hopes that | |
295 | it's somewhat accurate. */ | |
ee78dc32 | 296 | |
9ef2e2cf JR |
297 | static Time last_mouse_movement_time; |
298 | ||
299 | /* Incremented by w32_read_socket whenever it really tries to read | |
300 | events. */ | |
a1b9438c | 301 | |
ee78dc32 GV |
302 | #ifdef __STDC__ |
303 | static int volatile input_signal_count; | |
304 | #else | |
305 | static int input_signal_count; | |
306 | #endif | |
307 | ||
308 | extern Lisp_Object Vcommand_line_args, Vsystem_name; | |
309 | ||
310 | extern Lisp_Object Qface, Qmouse_face; | |
311 | ||
38006079 | 312 | #ifndef USE_CRT_DLL |
ee78dc32 | 313 | extern int errno; |
38006079 | 314 | #endif |
ee78dc32 GV |
315 | |
316 | /* A mask of extra modifier bits to put into every keyboard char. */ | |
9ef2e2cf | 317 | |
ee78dc32 GV |
318 | extern int extra_keyboard_modifiers; |
319 | ||
791f420f JR |
320 | /* Enumeration for overriding/changing the face to use for drawing |
321 | glyphs in x_draw_glyphs. */ | |
322 | ||
323 | enum draw_glyphs_face | |
324 | { | |
325 | DRAW_NORMAL_TEXT, | |
326 | DRAW_INVERSE_VIDEO, | |
327 | DRAW_CURSOR, | |
328 | DRAW_MOUSE_FACE, | |
329 | DRAW_IMAGE_RAISED, | |
330 | DRAW_IMAGE_SUNKEN | |
331 | }; | |
332 | ||
38006079 | 333 | static void x_update_window_end P_ ((struct window *, int, int)); |
791f420f JR |
334 | static void frame_to_window_pixel_xy P_ ((struct window *, int *, int *)); |
335 | void w32_delete_display P_ ((struct w32_display_info *)); | |
336 | static int fast_find_position P_ ((struct window *, int, int *, int *, | |
337 | int *, int *)); | |
338 | static void set_output_cursor P_ ((struct cursor_pos *)); | |
339 | static struct glyph *x_y_to_hpos_vpos P_ ((struct window *, int, int, | |
340 | int *, int *, int *)); | |
341 | static void note_mode_line_highlight P_ ((struct window *, int, int)); | |
342 | static void x_check_font P_ ((struct frame *, XFontStruct *)); | |
343 | static void note_mouse_highlight P_ ((struct frame *, int, int)); | |
344 | static void note_tool_bar_highlight P_ ((struct frame *f, int, int)); | |
345 | static void w32_handle_tool_bar_click P_ ((struct frame *, | |
346 | struct input_event *)); | |
347 | static void show_mouse_face P_ ((struct w32_display_info *, | |
348 | enum draw_glyphs_face)); | |
349 | void clear_mouse_face P_ ((struct w32_display_info *)); | |
350 | ||
351 | void x_lower_frame P_ ((struct frame *)); | |
352 | void x_scroll_bar_clear P_ ((struct frame *)); | |
353 | void x_wm_set_size_hint P_ ((struct frame *, long, int)); | |
354 | void x_raise_frame P_ ((struct frame *)); | |
355 | void x_set_window_size P_ ((struct frame *, int, int, int)); | |
356 | void x_wm_set_window_state P_ ((struct frame *, int)); | |
357 | void x_wm_set_icon_pixmap P_ ((struct frame *, int)); | |
358 | void w32_initialize P_ ((void)); | |
359 | static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); | |
360 | int x_compute_min_glyph_bounds P_ ((struct frame *)); | |
361 | static void x_draw_phys_cursor_glyph P_ ((struct window *, | |
362 | struct glyph_row *, | |
363 | enum draw_glyphs_face)); | |
364 | static void x_update_end P_ ((struct frame *)); | |
365 | static void w32_frame_up_to_date P_ ((struct frame *)); | |
366 | static void w32_reassert_line_highlight P_ ((int, int)); | |
367 | static void x_change_line_highlight P_ ((int, int, int, int)); | |
368 | static void w32_set_terminal_modes P_ ((void)); | |
369 | static void w32_reset_terminal_modes P_ ((void)); | |
370 | static void w32_cursor_to P_ ((int, int, int, int)); | |
371 | static void x_write_glyphs P_ ((struct glyph *, int)); | |
372 | static void x_clear_end_of_line P_ ((int)); | |
373 | static void x_clear_frame P_ ((void)); | |
374 | static void x_clear_cursor P_ ((struct window *)); | |
375 | static void frame_highlight P_ ((struct frame *)); | |
376 | static void frame_unhighlight P_ ((struct frame *)); | |
377 | static void w32_new_focus_frame P_ ((struct w32_display_info *, | |
378 | struct frame *)); | |
379 | static void w32_frame_rehighlight P_ ((struct frame *)); | |
380 | static void x_frame_rehighlight P_ ((struct w32_display_info *)); | |
381 | static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); | |
9ef2e2cf | 382 | static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int)); |
791f420f JR |
383 | static void expose_frame P_ ((struct frame *, int, int, int, int)); |
384 | static void expose_window_tree P_ ((struct window *, RECT *)); | |
385 | static void expose_window P_ ((struct window *, RECT *)); | |
386 | static void expose_area P_ ((struct window *, struct glyph_row *, | |
387 | RECT *, enum glyph_row_area)); | |
388 | static void expose_line P_ ((struct window *, struct glyph_row *, | |
389 | RECT *)); | |
390 | void x_update_cursor P_ ((struct frame *, int)); | |
391 | static void x_update_cursor_in_window_tree P_ ((struct window *, int)); | |
392 | static void x_update_window_cursor P_ ((struct window *, int)); | |
393 | static void x_erase_phys_cursor P_ ((struct window *)); | |
394 | void x_display_cursor P_ ((struct window *w, int, int, int, int, int)); | |
395 | void x_display_and_set_cursor P_ ((struct window *, int, int, int, int, int)); | |
396 | static void w32_draw_bitmap P_ ((struct window *, HDC hdc, struct glyph_row *, | |
397 | enum bitmap_type)); | |
398 | static int x_phys_cursor_in_rect_p P_ ((struct window *, RECT *)); | |
399 | static void x_draw_row_bitmaps P_ ((struct window *, struct glyph_row *)); | |
400 | static void note_overwritten_text_cursor P_ ((struct window *, int, int)); | |
401 | static void w32_clip_to_row P_ ((struct window *, struct glyph_row *, | |
402 | HDC, int)); | |
403 | ||
ee78dc32 GV |
404 | static Lisp_Object Qvendor_specific_keysyms; |
405 | ||
ee78dc32 | 406 | \f |
9ef2e2cf JR |
407 | /*********************************************************************** |
408 | Debugging | |
409 | ***********************************************************************/ | |
410 | ||
ee78dc32 | 411 | #if 0 |
9ef2e2cf JR |
412 | |
413 | /* This is a function useful for recording debugging information about | |
414 | the sequence of occurrences in this file. */ | |
ee78dc32 GV |
415 | |
416 | struct record | |
417 | { | |
418 | char *locus; | |
419 | int type; | |
420 | }; | |
421 | ||
422 | struct record event_record[100]; | |
423 | ||
424 | int event_record_index; | |
425 | ||
426 | record_event (locus, type) | |
427 | char *locus; | |
428 | int type; | |
429 | { | |
430 | if (event_record_index == sizeof (event_record) / sizeof (struct record)) | |
431 | event_record_index = 0; | |
432 | ||
433 | event_record[event_record_index].locus = locus; | |
434 | event_record[event_record_index].type = type; | |
435 | event_record_index++; | |
436 | } | |
437 | ||
438 | #endif /* 0 */ | |
439 | \f | |
791f420f JR |
440 | |
441 | void XChangeGC (void * ignore, XGCValues* gc, unsigned long mask, | |
442 | XGCValues *xgcv) | |
443 | { | |
444 | if (mask & GCForeground) | |
445 | gc->foreground = xgcv->foreground; | |
446 | if (mask & GCBackground) | |
447 | gc->background = xgcv->background; | |
448 | if (mask & GCFont) | |
449 | gc->font = xgcv->font; | |
450 | } | |
451 | ||
452 | XGCValues *XCreateGC (void * ignore, Window window, unsigned long mask, | |
453 | XGCValues *xgcv) | |
454 | { | |
455 | XGCValues *gc = (XGCValues *) xmalloc (sizeof (XGCValues)); | |
456 | bzero (gc, sizeof (XGCValues)); | |
457 | ||
458 | XChangeGC (ignore, gc, mask, xgcv); | |
459 | ||
460 | return gc; | |
461 | } | |
462 | ||
463 | void XGetGCValues (void* ignore, XGCValues *gc, | |
464 | unsigned long mask, XGCValues *xgcv) | |
465 | { | |
466 | XChangeGC (ignore, xgcv, mask, gc); | |
467 | } | |
468 | ||
791f420f JR |
469 | static void |
470 | w32_set_clip_rectangle (HDC hdc, RECT *rect) | |
471 | { | |
472 | if (rect) | |
473 | { | |
474 | HRGN clip_region = CreateRectRgnIndirect (rect); | |
475 | SelectClipRgn (hdc, clip_region); | |
476 | DeleteObject (clip_region); | |
477 | } | |
478 | else | |
479 | SelectClipRgn (hdc, NULL); | |
480 | } | |
481 | ||
791f420f JR |
482 | |
483 | /* Draw a hollow rectangle at the specified position. */ | |
484 | void | |
485 | w32_draw_rectangle (HDC hdc, XGCValues *gc, int x, int y, | |
486 | int width, int height) | |
487 | { | |
488 | HBRUSH hb, oldhb; | |
489 | HPEN hp, oldhp; | |
490 | ||
491 | hb = CreateSolidBrush (gc->background); | |
492 | hp = CreatePen (PS_SOLID, 0, gc->foreground); | |
493 | oldhb = SelectObject (hdc, hb); | |
494 | oldhp = SelectObject (hdc, hp); | |
495 | ||
496 | Rectangle (hdc, x, y, x + width, y + height); | |
497 | ||
498 | SelectObject (hdc, oldhb); | |
499 | SelectObject (hdc, oldhp); | |
500 | DeleteObject (hb); | |
501 | DeleteObject (hp); | |
502 | } | |
503 | ||
504 | /* Draw a filled rectangle at the specified position. */ | |
ee78dc32 | 505 | void |
00fe468b | 506 | w32_fill_rect (f, hdc, pix, lprect) |
ee78dc32 | 507 | FRAME_PTR f; |
00fe468b | 508 | HDC hdc; |
ee78dc32 GV |
509 | COLORREF pix; |
510 | RECT * lprect; | |
511 | { | |
ee78dc32 | 512 | HBRUSH hb; |
ee78dc32 | 513 | RECT rect; |
791f420f | 514 | |
ee78dc32 | 515 | hb = CreateSolidBrush (pix); |
ee78dc32 | 516 | FillRect (hdc, lprect, hb); |
ee78dc32 | 517 | DeleteObject (hb); |
ee78dc32 GV |
518 | } |
519 | ||
520 | void | |
fbd6baed | 521 | w32_clear_window (f) |
ee78dc32 GV |
522 | FRAME_PTR f; |
523 | { | |
524 | RECT rect; | |
00fe468b | 525 | HDC hdc = get_frame_dc (f); |
52cf03a1 | 526 | |
e4a52412 JR |
527 | /* Under certain conditions, this can be called at startup with |
528 | a console frame pointer before the GUI frame is created. An HDC | |
529 | of 0 indicates this. */ | |
530 | if (hdc) | |
531 | { | |
532 | GetClientRect (FRAME_W32_WINDOW (f), &rect); | |
533 | w32_clear_rect (f, hdc, &rect); | |
534 | } | |
535 | ||
00fe468b | 536 | release_frame_dc (f, hdc); |
ee78dc32 GV |
537 | } |
538 | ||
539 | \f | |
791f420f JR |
540 | /*********************************************************************** |
541 | Starting and ending an update | |
542 | ***********************************************************************/ | |
543 | ||
544 | /* Start an update of frame F. This function is installed as a hook | |
545 | for update_begin, i.e. it is called when update_begin is called. | |
546 | This function is called prior to calls to x_update_window_begin for | |
547 | each window being updated. Currently, there is nothing to do here | |
548 | because all interesting stuff is done on a window basis. */ | |
ee78dc32 | 549 | |
96214669 | 550 | static void |
791f420f | 551 | x_update_begin (f) |
ee78dc32 GV |
552 | struct frame *f; |
553 | { | |
791f420f JR |
554 | /* Nothing to do. We have to do something though, otherwise the |
555 | function gets optimized away and the hook is no longer valid. */ | |
556 | struct frame *cf = f; | |
557 | } | |
ee78dc32 | 558 | |
791f420f JR |
559 | |
560 | /* Start update of window W. Set the global variable updated_window | |
561 | to the window being updated and set output_cursor to the cursor | |
562 | position of W. */ | |
563 | ||
564 | static void | |
565 | x_update_window_begin (w) | |
566 | struct window *w; | |
567 | { | |
568 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
569 | struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); | |
570 | ||
571 | updated_window = w; | |
572 | set_output_cursor (&w->cursor); | |
ee78dc32 GV |
573 | |
574 | BLOCK_INPUT; | |
575 | ||
52cf03a1 GV |
576 | /* Regenerate display palette before drawing if list of requested |
577 | colors has changed. */ | |
791f420f | 578 | if (display_info->regen_palette) |
52cf03a1 | 579 | { |
fbd6baed | 580 | w32_regenerate_palette (f); |
791f420f | 581 | display_info->regen_palette = FALSE; |
52cf03a1 GV |
582 | } |
583 | ||
791f420f | 584 | if (f == display_info->mouse_face_mouse_frame) |
ee78dc32 GV |
585 | { |
586 | /* Don't do highlighting for mouse motion during the update. */ | |
791f420f | 587 | display_info->mouse_face_defer = 1; |
ee78dc32 | 588 | |
9ef2e2cf JR |
589 | /* If F needs to be redrawn, simply forget about any prior mouse |
590 | highlighting. */ | |
ee78dc32 | 591 | if (FRAME_GARBAGED_P (f)) |
791f420f JR |
592 | display_info->mouse_face_window = Qnil; |
593 | ||
ec48c3a7 JR |
594 | #if 0 /* Rows in a current matrix containing glyphs in mouse-face have |
595 | their mouse_face_p flag set, which means that they are always | |
596 | unequal to rows in a desired matrix which never have that | |
597 | flag set. So, rows containing mouse-face glyphs are never | |
598 | scrolled, and we don't have to switch the mouse highlight off | |
599 | here to prevent it from being scrolled. */ | |
600 | ||
791f420f JR |
601 | /* Can we tell that this update does not affect the window |
602 | where the mouse highlight is? If so, no need to turn off. | |
603 | Likewise, don't do anything if the frame is garbaged; | |
604 | in that case, the frame's current matrix that we would use | |
605 | is all wrong, and we will redisplay that line anyway. */ | |
606 | if (!NILP (display_info->mouse_face_window) | |
607 | && w == XWINDOW (display_info->mouse_face_window)) | |
ee78dc32 | 608 | { |
791f420f | 609 | int i; |
ee78dc32 | 610 | |
791f420f JR |
611 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
612 | if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) | |
ee78dc32 GV |
613 | break; |
614 | ||
791f420f JR |
615 | if (i < w->desired_matrix->nrows) |
616 | clear_mouse_face (display_info); | |
ee78dc32 | 617 | } |
ec48c3a7 | 618 | #endif /* 0 */ |
ee78dc32 GV |
619 | } |
620 | ||
621 | UNBLOCK_INPUT; | |
622 | } | |
623 | ||
791f420f JR |
624 | |
625 | /* Draw a vertical window border to the right of window W if W doesn't | |
626 | have vertical scroll bars. */ | |
627 | ||
96214669 | 628 | static void |
791f420f JR |
629 | x_draw_vertical_border (w) |
630 | struct window *w; | |
ee78dc32 | 631 | { |
791f420f JR |
632 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
633 | ||
634 | /* Redraw borders between horizontally adjacent windows. Don't | |
635 | do it for frames with vertical scroll bars because either the | |
636 | right scroll bar of a window, or the left scroll bar of its | |
637 | neighbor will suffice as a border. */ | |
638 | if (!WINDOW_RIGHTMOST_P (w) | |
639 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
640 | { | |
641 | RECT r; | |
00fe468b | 642 | HDC hdc; |
ee78dc32 | 643 | |
791f420f JR |
644 | window_box_edges (w, -1, &r.left, &r.top, &r.right, &r.bottom); |
645 | r.left = r.right + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f); | |
646 | r.right = r.left + 1; | |
647 | r.bottom -= 1; | |
ee78dc32 | 648 | |
00fe468b | 649 | hdc = get_frame_dc (f); |
e4a52412 | 650 | w32_fill_rect (f, hdc, FRAME_FOREGROUND_PIXEL (f), &r); |
00fe468b | 651 | release_frame_dc (f, hdc); |
791f420f JR |
652 | } |
653 | } | |
ee78dc32 | 654 | |
791f420f | 655 | |
ec48c3a7 JR |
656 | /* End update of window W (which is equal to updated_window). |
657 | ||
658 | Draw vertical borders between horizontally adjacent windows, and | |
659 | display W's cursor if CURSOR_ON_P is non-zero. | |
660 | ||
661 | MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing | |
662 | glyphs in mouse-face were overwritten. In that case we have to | |
663 | make sure that the mouse-highlight is properly redrawn. | |
664 | ||
665 | W may be a menu bar pseudo-window in case we don't have X toolkit | |
666 | support. Such windows don't have a cursor, so don't display it | |
667 | here. */ | |
791f420f JR |
668 | |
669 | static void | |
ec48c3a7 | 670 | x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p) |
791f420f | 671 | struct window *w; |
ec48c3a7 | 672 | int cursor_on_p, mouse_face_overwritten_p; |
791f420f JR |
673 | { |
674 | if (!w->pseudo_window_p) | |
675 | { | |
ec48c3a7 JR |
676 | struct w32_display_info *dpyinfo |
677 | = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); | |
678 | ||
791f420f | 679 | BLOCK_INPUT; |
ec48c3a7 JR |
680 | |
681 | /* If a row with mouse-face was overwritten, arrange for | |
682 | XTframe_up_to_date to redisplay the mouse highlight. */ | |
683 | if (mouse_face_overwritten_p) | |
684 | { | |
685 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
686 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
687 | dpyinfo->mouse_face_window = Qnil; | |
688 | } | |
689 | ||
791f420f JR |
690 | if (cursor_on_p) |
691 | x_display_and_set_cursor (w, 1, output_cursor.hpos, | |
692 | output_cursor.vpos, | |
693 | output_cursor.x, output_cursor.y); | |
694 | x_draw_vertical_border (w); | |
695 | UNBLOCK_INPUT; | |
696 | } | |
697 | ||
698 | updated_window = NULL; | |
699 | } | |
700 | ||
9ef2e2cf JR |
701 | |
702 | /* End update of frame F. This function is installed as a hook in | |
703 | update_end. */ | |
704 | ||
791f420f JR |
705 | static void |
706 | x_update_end (f) | |
707 | struct frame *f; | |
708 | { | |
709 | /* Mouse highlight may be displayed again. */ | |
710 | FRAME_W32_DISPLAY_INFO (f)->mouse_face_defer = 0; | |
ee78dc32 GV |
711 | } |
712 | ||
9ef2e2cf | 713 | |
791f420f JR |
714 | /* This function is called from various places in xdisp.c whenever a |
715 | complete update has been performed. The global variable | |
716 | updated_window is not available here. */ | |
ee78dc32 | 717 | |
96214669 | 718 | static void |
fbd6baed | 719 | w32_frame_up_to_date (f) |
791f420f | 720 | struct frame *f; |
ee78dc32 | 721 | { |
791f420f | 722 | if (FRAME_W32_P (f)) |
ee78dc32 | 723 | { |
791f420f JR |
724 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
725 | if (dpyinfo->mouse_face_deferred_gc | |
726 | || f == dpyinfo->mouse_face_mouse_frame) | |
727 | { | |
728 | BLOCK_INPUT; | |
729 | if (dpyinfo->mouse_face_mouse_frame) | |
730 | note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, | |
731 | dpyinfo->mouse_face_mouse_x, | |
732 | dpyinfo->mouse_face_mouse_y); | |
733 | dpyinfo->mouse_face_deferred_gc = 0; | |
734 | UNBLOCK_INPUT; | |
735 | } | |
ee78dc32 GV |
736 | } |
737 | } | |
791f420f JR |
738 | |
739 | ||
740 | /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay | |
741 | arrow bitmaps, or clear the areas where they would be displayed | |
742 | before DESIRED_ROW is made current. The window being updated is | |
743 | found in updated_window. This function It is called from | |
744 | update_window_line only if it is known that there are differences | |
745 | between bitmaps to be drawn between current row and DESIRED_ROW. */ | |
746 | ||
747 | static void | |
748 | x_after_update_window_line (desired_row) | |
749 | struct glyph_row *desired_row; | |
750 | { | |
751 | struct window *w = updated_window; | |
752 | ||
753 | xassert (w); | |
754 | ||
755 | if (!desired_row->mode_line_p && !w->pseudo_window_p) | |
756 | { | |
757 | BLOCK_INPUT; | |
758 | x_draw_row_bitmaps (w, desired_row); | |
759 | ||
760 | /* When a window has disappeared, make sure that no rest of | |
761 | full-width rows stays visible in the internal border. */ | |
762 | if (windows_or_buffers_changed) | |
763 | { | |
764 | struct frame *f = XFRAME (w->frame); | |
765 | int width = FRAME_INTERNAL_BORDER_WIDTH (f); | |
766 | int height = desired_row->visible_height; | |
767 | int x = (window_box_right (w, -1) | |
768 | + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f)); | |
769 | int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); | |
00fe468b | 770 | HDC hdc = get_frame_dc (f); |
791f420f | 771 | |
00fe468b JR |
772 | w32_clear_area (f, hdc, x, y, width, height); |
773 | release_frame_dc (f, hdc); | |
791f420f JR |
774 | } |
775 | ||
776 | UNBLOCK_INPUT; | |
777 | } | |
778 | } | |
779 | ||
780 | ||
781 | /* Draw the bitmap WHICH in one of the areas to the left or right of | |
782 | window W. ROW is the glyph row for which to display the bitmap; it | |
783 | determines the vertical position at which the bitmap has to be | |
784 | drawn. */ | |
785 | ||
786 | static void | |
00fe468b | 787 | w32_draw_bitmap (w, hdc, row, which) |
791f420f | 788 | struct window *w; |
00fe468b | 789 | HDC hdc; |
791f420f JR |
790 | struct glyph_row *row; |
791 | enum bitmap_type which; | |
792 | { | |
793 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
794 | Window window = FRAME_W32_WINDOW (f); | |
791f420f JR |
795 | HDC compat_hdc; |
796 | int x, y, wd, h, dy; | |
791f420f JR |
797 | HBITMAP pixmap; |
798 | HBRUSH fg_brush, orig_brush; | |
799 | HANDLE horig_obj; | |
800 | struct face *face; | |
801 | ||
802 | /* Must clip because of partially visible lines. */ | |
803 | w32_clip_to_row (w, row, hdc, 1); | |
804 | ||
805 | switch (which) | |
806 | { | |
807 | case LEFT_TRUNCATION_BITMAP: | |
808 | wd = left_width; | |
809 | h = left_height; | |
f7737f5d | 810 | pixmap = left_bmp; |
791f420f JR |
811 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
812 | - wd | |
813 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
814 | break; | |
815 | ||
816 | case OVERLAY_ARROW_BITMAP: | |
817 | wd = ov_width; | |
818 | h = ov_height; | |
f7737f5d | 819 | pixmap = ov_bmp; |
791f420f JR |
820 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
821 | - wd | |
822 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
823 | break; | |
824 | ||
825 | case RIGHT_TRUNCATION_BITMAP: | |
826 | wd = right_width; | |
827 | h = right_height; | |
f7737f5d | 828 | pixmap = right_bmp; |
791f420f JR |
829 | x = window_box_right (w, -1); |
830 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; | |
831 | break; | |
832 | ||
833 | case CONTINUED_LINE_BITMAP: | |
834 | wd = continued_width; | |
835 | h = continued_height; | |
f7737f5d | 836 | pixmap = continued_bmp; |
791f420f JR |
837 | x = window_box_right (w, -1); |
838 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; | |
839 | break; | |
840 | ||
841 | case CONTINUATION_LINE_BITMAP: | |
842 | wd = continuation_width; | |
843 | h = continuation_height; | |
f7737f5d | 844 | pixmap = continuation_bmp; |
791f420f JR |
845 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
846 | - wd | |
847 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
848 | break; | |
849 | ||
850 | case ZV_LINE_BITMAP: | |
851 | wd = zv_width; | |
852 | h = zv_height; | |
f7737f5d | 853 | pixmap = zv_bmp; |
791f420f JR |
854 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
855 | - wd | |
856 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
857 | break; | |
858 | ||
859 | default: | |
860 | abort (); | |
861 | } | |
862 | ||
863 | /* Convert to frame coordinates. Set dy to the offset in the row to | |
864 | start drawing the bitmap. */ | |
865 | y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
866 | dy = (row->height - h) / 2; | |
867 | ||
f7737f5d | 868 | /* Draw the bitmap. */ |
791f420f | 869 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); |
791f420f JR |
870 | |
871 | compat_hdc = CreateCompatibleDC (hdc); | |
872 | SaveDC (hdc); | |
92bb977f | 873 | fg_brush = CreateSolidBrush (face->foreground); |
791f420f JR |
874 | orig_brush = SelectObject (hdc, fg_brush); |
875 | horig_obj = SelectObject (compat_hdc, pixmap); | |
92bb977f JR |
876 | SetTextColor (hdc, face->foreground); |
877 | SetBkColor (hdc, face->background); | |
791f420f | 878 | #if 0 /* From w32bdf.c (which is from Meadow). */ |
92bb977f | 879 | /* Old versions - in case we find a reason to fall back on them. */ |
791f420f | 880 | BitBlt (hdc, x, y + dy, wd, h, compat_hdc, 0, 0, SRCCOPY); |
791f420f | 881 | BitBlt (hdc, x, y + dy, wd, h, compat_hdc, 0, 0, 0xB8074A); |
92bb977f JR |
882 | #else |
883 | BitBlt (hdc, x, y + dy, wd, h, compat_hdc, 0, 0, 0xE20746); | |
791f420f JR |
884 | #endif |
885 | SelectObject (compat_hdc, horig_obj); | |
886 | SelectObject (hdc, orig_brush); | |
791f420f JR |
887 | DeleteObject (fg_brush); |
888 | DeleteDC (compat_hdc); | |
889 | RestoreDC (hdc, -1); | |
791f420f JR |
890 | } |
891 | ||
892 | ||
893 | /* Draw flags bitmaps for glyph row ROW on window W. Call this | |
894 | function with input blocked. */ | |
895 | ||
896 | static void | |
897 | x_draw_row_bitmaps (w, row) | |
898 | struct window *w; | |
899 | struct glyph_row *row; | |
900 | { | |
901 | struct frame *f = XFRAME (w->frame); | |
902 | enum bitmap_type bitmap; | |
903 | struct face *face; | |
904 | int header_line_height = -1; | |
905 | HDC hdc = get_frame_dc (f); | |
906 | ||
907 | xassert (interrupt_input_blocked); | |
908 | ||
909 | /* If row is completely invisible, because of vscrolling, we | |
910 | don't have to draw anything. */ | |
911 | if (row->visible_height <= 0) | |
912 | return; | |
913 | ||
914 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); | |
915 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
916 | ||
917 | /* Decide which bitmap to draw at the left side. */ | |
918 | if (row->overlay_arrow_p) | |
919 | bitmap = OVERLAY_ARROW_BITMAP; | |
920 | else if (row->truncated_on_left_p) | |
921 | bitmap = LEFT_TRUNCATION_BITMAP; | |
922 | else if (MATRIX_ROW_CONTINUATION_LINE_P (row)) | |
923 | bitmap = CONTINUATION_LINE_BITMAP; | |
924 | else if (row->indicate_empty_line_p) | |
925 | bitmap = ZV_LINE_BITMAP; | |
926 | else | |
927 | bitmap = NO_BITMAP; | |
928 | ||
929 | /* Clear flags area if no bitmap to draw or if bitmap doesn't fill | |
930 | the flags area. */ | |
931 | if (bitmap == NO_BITMAP | |
932 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) | |
933 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) | |
934 | { | |
935 | /* If W has a vertical border to its left, don't draw over it. */ | |
936 | int border = ((XFASTINT (w->left) > 0 | |
937 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
938 | ? 1 : 0); | |
939 | int left = window_box_left (w, -1); | |
940 | ||
941 | if (header_line_height < 0) | |
942 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
943 | ||
944 | w32_fill_area (f, hdc, face->background, | |
945 | left - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) + border, | |
946 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
947 | row->y)), | |
948 | FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - border, | |
949 | row->visible_height); | |
950 | } | |
951 | ||
952 | /* Draw the left bitmap. */ | |
953 | if (bitmap != NO_BITMAP) | |
954 | w32_draw_bitmap (w, hdc, row, bitmap); | |
955 | ||
956 | /* Decide which bitmap to draw at the right side. */ | |
957 | if (row->truncated_on_right_p) | |
958 | bitmap = RIGHT_TRUNCATION_BITMAP; | |
959 | else if (row->continued_p) | |
960 | bitmap = CONTINUED_LINE_BITMAP; | |
961 | else | |
962 | bitmap = NO_BITMAP; | |
963 | ||
964 | /* Clear flags area if no bitmap to draw of if bitmap doesn't fill | |
965 | the flags area. */ | |
966 | if (bitmap == NO_BITMAP | |
967 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) | |
968 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) | |
969 | { | |
970 | int right = window_box_right (w, -1); | |
971 | ||
972 | if (header_line_height < 0) | |
973 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
974 | ||
975 | w32_fill_area (f, hdc, face->background, | |
976 | right, | |
977 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
978 | row->y)), | |
979 | FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f), | |
980 | row->visible_height); | |
981 | } | |
982 | ||
983 | /* Draw the right bitmap. */ | |
984 | if (bitmap != NO_BITMAP) | |
985 | w32_draw_bitmap (w, hdc, row, bitmap); | |
986 | ||
987 | release_frame_dc (f, hdc); | |
988 | } | |
989 | ||
ee78dc32 | 990 | \f |
791f420f JR |
991 | /*********************************************************************** |
992 | Line Highlighting | |
993 | ***********************************************************************/ | |
994 | ||
995 | /* External interface to control of standout mode. Not used for W32 | |
996 | frames. Aborts when called. */ | |
ee78dc32 | 997 | |
96214669 | 998 | static void |
fbd6baed | 999 | w32_reassert_line_highlight (new, vpos) |
ee78dc32 GV |
1000 | int new, vpos; |
1001 | { | |
791f420f | 1002 | abort (); |
ee78dc32 GV |
1003 | } |
1004 | ||
791f420f JR |
1005 | /* Call this when about to modify line at position VPOS and change |
1006 | whether it is highlighted. Not used for W32 frames. Aborts when | |
1007 | called. */ | |
ee78dc32 | 1008 | |
96214669 | 1009 | static void |
791f420f JR |
1010 | x_change_line_highlight (new_highlight, vpos, y, first_unused_hpos) |
1011 | int new_highlight, vpos, y, first_unused_hpos; | |
ee78dc32 | 1012 | { |
791f420f | 1013 | abort (); |
ee78dc32 GV |
1014 | } |
1015 | ||
9ef2e2cf JR |
1016 | /* This is called when starting Emacs and when restarting after |
1017 | suspend. When starting Emacs, no window is mapped. And nothing | |
1018 | must be done to Emacs's own window if it is suspended (though that | |
1019 | rarely happens). */ | |
ee78dc32 | 1020 | |
96214669 GV |
1021 | static void |
1022 | w32_set_terminal_modes (void) | |
ee78dc32 GV |
1023 | { |
1024 | } | |
1025 | ||
9ef2e2cf JR |
1026 | /* This is called when exiting or suspending Emacs. Exiting will make |
1027 | the W32 windows go away, and suspending requires no action. */ | |
ee78dc32 | 1028 | |
96214669 GV |
1029 | static void |
1030 | w32_reset_terminal_modes (void) | |
ee78dc32 GV |
1031 | { |
1032 | } | |
791f420f | 1033 | |
9ef2e2cf | 1034 | |
ee78dc32 | 1035 | \f |
791f420f JR |
1036 | /*********************************************************************** |
1037 | Output Cursor | |
1038 | ***********************************************************************/ | |
1039 | ||
1040 | /* Set the global variable output_cursor to CURSOR. All cursor | |
1041 | positions are relative to updated_window. */ | |
9ef2e2cf | 1042 | |
791f420f JR |
1043 | static void |
1044 | set_output_cursor (cursor) | |
1045 | struct cursor_pos *cursor; | |
1046 | { | |
1047 | output_cursor.hpos = cursor->hpos; | |
1048 | output_cursor.vpos = cursor->vpos; | |
1049 | output_cursor.x = cursor->x; | |
1050 | output_cursor.y = cursor->y; | |
1051 | } | |
1052 | ||
1053 | ||
1054 | /* Set a nominal cursor position. | |
1055 | ||
1056 | HPOS and VPOS are column/row positions in a window glyph matrix. X | |
1057 | and Y are window text area relative pixel positions. | |
1058 | ||
1059 | If this is done during an update, updated_window will contain the | |
1060 | window that is being updated and the position is the future output | |
1061 | cursor position for that window. If updated_window is null, use | |
1062 | selected_window and display the cursor at the given position. */ | |
ee78dc32 | 1063 | |
96214669 | 1064 | static void |
791f420f JR |
1065 | w32_cursor_to (vpos, hpos, y, x) |
1066 | int vpos, hpos, y, x; | |
ee78dc32 | 1067 | { |
791f420f | 1068 | struct window *w; |
ee78dc32 | 1069 | |
791f420f JR |
1070 | /* If updated_window is not set, work on selected_window. */ |
1071 | if (updated_window) | |
1072 | w = updated_window; | |
1073 | else | |
1074 | w = XWINDOW (selected_window); | |
1075 | ||
1076 | /* Set the output cursor. */ | |
1077 | output_cursor.hpos = hpos; | |
1078 | output_cursor.vpos = vpos; | |
1079 | output_cursor.x = x; | |
1080 | output_cursor.y = y; | |
ee78dc32 | 1081 | |
791f420f JR |
1082 | /* If not called as part of an update, really display the cursor. |
1083 | This will also set the cursor position of W. */ | |
1084 | if (updated_window == NULL) | |
ee78dc32 GV |
1085 | { |
1086 | BLOCK_INPUT; | |
791f420f | 1087 | x_display_cursor (w, 1, hpos, vpos, x, y); |
ee78dc32 GV |
1088 | UNBLOCK_INPUT; |
1089 | } | |
1090 | } | |
791f420f | 1091 | |
9ef2e2cf | 1092 | |
ee78dc32 | 1093 | \f |
791f420f JR |
1094 | /*********************************************************************** |
1095 | Display Iterator | |
1096 | ***********************************************************************/ | |
1097 | ||
1098 | /* Function prototypes of this page. */ | |
1099 | ||
1100 | static struct face *x_get_glyph_face_and_encoding P_ ((struct frame *, | |
1101 | struct glyph *, | |
93ff4395 JR |
1102 | wchar_t *, |
1103 | int *)); | |
791f420f JR |
1104 | static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int, |
1105 | int, wchar_t *, int)); | |
82f9d565 | 1106 | static XCharStruct *w32_per_char_metric P_ ((XFontStruct *, |
9ef2e2cf JR |
1107 | wchar_t *, |
1108 | enum w32_char_font_type)); | |
1109 | static enum w32_char_font_type | |
1110 | w32_encode_char P_ ((int, wchar_t *, struct font_info *, int *)); | |
791f420f JR |
1111 | static void x_append_glyph P_ ((struct it *)); |
1112 | static void x_append_composite_glyph P_ ((struct it *)); | |
1113 | static void x_append_stretch_glyph P_ ((struct it *it, Lisp_Object, | |
1114 | int, int, double)); | |
1115 | static void x_produce_glyphs P_ ((struct it *)); | |
1116 | static void x_produce_image_glyph P_ ((struct it *it)); | |
a1b9438c | 1117 | |
a1b9438c | 1118 | |
791f420f JR |
1119 | /* Dealing with bits of wchar_t as if they were an XChar2B. */ |
1120 | #define BUILD_WCHAR_T(byte1, byte2) \ | |
1121 | ((wchar_t)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff))) | |
a1b9438c | 1122 | |
a1b9438c | 1123 | |
791f420f JR |
1124 | #define BYTE1(ch) \ |
1125 | (((ch) & 0xff00) >> 8) | |
a1b9438c | 1126 | |
791f420f JR |
1127 | #define BYTE2(ch) \ |
1128 | ((ch) & 0x00ff) | |
cabb23bc | 1129 | |
791f420f JR |
1130 | |
1131 | /* Get metrics of character CHAR2B in FONT. Value is always non-null. | |
1132 | If CHAR2B is not contained in FONT, the font's default character | |
9ef2e2cf | 1133 | metric is returned. */ |
791f420f | 1134 | |
82f9d565 AI |
1135 | static int |
1136 | w32_bdf_per_char_metric (font, char2b, dim, pcm) | |
9127e20e JR |
1137 | XFontStruct *font; |
1138 | wchar_t *char2b; | |
1139 | int dim; | |
82f9d565 | 1140 | XCharStruct * pcm; |
9127e20e JR |
1141 | { |
1142 | glyph_metric * bdf_metric; | |
1143 | char buf[2]; | |
9127e20e JR |
1144 | |
1145 | if (dim == 1) | |
4b99045f | 1146 | buf[0] = (char)(*char2b); |
9127e20e JR |
1147 | else |
1148 | { | |
1149 | buf[0] = BYTE1 (*char2b); | |
1150 | buf[1] = BYTE2 (*char2b); | |
1151 | } | |
1152 | ||
1153 | bdf_metric = w32_BDF_TextMetric (font->bdf, buf, dim); | |
1154 | ||
1155 | if (bdf_metric) | |
1156 | { | |
1157 | pcm->width = bdf_metric->dwidth; | |
1158 | pcm->lbearing = bdf_metric->bbox; | |
1159 | pcm->rbearing = bdf_metric->dwidth | |
1160 | - (bdf_metric->bbox + bdf_metric->bbw); | |
1161 | pcm->ascent = bdf_metric->bboy + bdf_metric->bbh; | |
00c96995 | 1162 | pcm->descent = -bdf_metric->bboy; |
82f9d565 AI |
1163 | |
1164 | return 1; | |
9127e20e | 1165 | } |
82f9d565 | 1166 | return 0; |
9127e20e JR |
1167 | } |
1168 | ||
1169 | ||
82f9d565 AI |
1170 | static int |
1171 | w32_native_per_char_metric (font, char2b, font_type, pcm) | |
791f420f JR |
1172 | XFontStruct *font; |
1173 | wchar_t *char2b; | |
9ef2e2cf | 1174 | enum w32_char_font_type font_type; |
82f9d565 | 1175 | XCharStruct * pcm; |
cabb23bc | 1176 | { |
82f9d565 AI |
1177 | HDC hdc = GetDC (NULL); |
1178 | HFONT old_font; | |
1179 | BOOL retval = FALSE; | |
cabb23bc | 1180 | |
791f420f | 1181 | xassert (font && char2b); |
82f9d565 AI |
1182 | xassert (font->hfont); |
1183 | xassert (font_type == UNICODE_FONT || font_type == ANSI_FONT); | |
cabb23bc | 1184 | |
82f9d565 | 1185 | old_font = SelectObject (hdc, font->hfont); |
791f420f | 1186 | |
dfaaaafb | 1187 | if ((font->tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0) |
791f420f | 1188 | { |
dfaaaafb AI |
1189 | ABC char_widths; |
1190 | ||
1191 | if (font_type == UNICODE_FONT) | |
1192 | retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths); | |
82f9d565 | 1193 | else |
dfaaaafb AI |
1194 | retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths); |
1195 | ||
1196 | if (retval) | |
1197 | { | |
1198 | pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC; | |
1199 | pcm->lbearing = char_widths.abcA; | |
1200 | pcm->rbearing = pcm->width - char_widths.abcC; | |
82f9d565 AI |
1201 | pcm->ascent = FONT_BASE (font); |
1202 | pcm->descent = FONT_DESCENT (font); | |
dfaaaafb | 1203 | } |
791f420f | 1204 | } |
82f9d565 AI |
1205 | |
1206 | if (!retval) | |
791f420f | 1207 | { |
82f9d565 AI |
1208 | /* Either font is not a True-type font, or GetCharABCWidthsW |
1209 | failed (it is not supported on Windows 9x for instance), so we | |
1210 | can't determine the full info we would like. All is not lost | |
1211 | though - we can call GetTextExtentPoint32 to get rbearing and | |
1212 | deduce width based on the font's per-string overhang. lbearing | |
1213 | is assumed to be zero. */ | |
01b220b6 JR |
1214 | |
1215 | /* TODO: Some Thai characters (and other composites if Windows | |
1216 | supports them) do have lbearing, and report their total width | |
1217 | as zero. Need some way of handling them when | |
1218 | GetCharABCWidthsW fails. */ | |
82f9d565 AI |
1219 | SIZE sz; |
1220 | ||
1221 | if (font_type == UNICODE_FONT) | |
1222 | retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz); | |
1223 | else | |
1224 | retval = GetTextExtentPoint32A (hdc, (char*)char2b, 1, &sz); | |
791f420f JR |
1225 | |
1226 | if (retval) | |
dfaaaafb | 1227 | { |
82f9d565 AI |
1228 | pcm->width = sz.cx - font->tm.tmOverhang; |
1229 | pcm->rbearing = sz.cx; | |
dfaaaafb | 1230 | pcm->lbearing = 0; |
82f9d565 AI |
1231 | pcm->ascent = FONT_BASE (font); |
1232 | pcm->descent = FONT_DESCENT (font); | |
dfaaaafb | 1233 | } |
791f420f JR |
1234 | } |
1235 | ||
791f420f | 1236 | |
93ff4395 JR |
1237 | if (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0) |
1238 | { | |
82f9d565 | 1239 | retval = FALSE; |
93ff4395 JR |
1240 | } |
1241 | ||
82f9d565 AI |
1242 | SelectObject (hdc, old_font); |
1243 | ReleaseDC (NULL, hdc); | |
1244 | ||
1245 | return retval; | |
1246 | } | |
1247 | ||
1248 | ||
1249 | static XCharStruct * | |
1250 | w32_per_char_metric (font, char2b, font_type) | |
1251 | XFontStruct *font; | |
1252 | wchar_t *char2b; | |
1253 | enum w32_char_font_type font_type; | |
1254 | { | |
1255 | /* The result metric information. */ | |
1256 | XCharStruct *pcm; | |
1257 | BOOL retval; | |
1258 | ||
1259 | xassert (font && char2b); | |
1260 | xassert (font_type != UNKNOWN_FONT); | |
1261 | ||
1262 | /* Handle the common cases quickly. */ | |
4b99045f | 1263 | if (!font->bdf && font->per_char == NULL) |
82f9d565 AI |
1264 | /* TODO: determine whether char2b exists in font? */ |
1265 | return &font->max_bounds; | |
4b99045f | 1266 | else if (!font->bdf && *char2b < 128) |
82f9d565 AI |
1267 | return &font->per_char[*char2b]; |
1268 | ||
1269 | pcm = &font->scratch; | |
1270 | ||
1271 | if (font_type == BDF_1D_FONT) | |
1272 | retval = w32_bdf_per_char_metric (font, char2b, 1, pcm); | |
1273 | else if (font_type == BDF_2D_FONT) | |
1274 | retval = w32_bdf_per_char_metric (font, char2b, 2, pcm); | |
1275 | else | |
1276 | retval = w32_native_per_char_metric (font, char2b, font_type, pcm); | |
1277 | ||
1278 | if (retval) | |
1279 | return pcm; | |
1280 | ||
1281 | return NULL; | |
1282 | } | |
1283 | ||
1284 | void | |
1285 | w32_cache_char_metrics (font) | |
1286 | XFontStruct *font; | |
1287 | { | |
1288 | wchar_t char2b = L'x'; | |
1289 | ||
1290 | /* Cache char metrics for the common cases. */ | |
1291 | if (font->bdf) | |
1292 | { | |
1293 | /* TODO: determine whether font is fixed-pitch. */ | |
00c96995 JR |
1294 | if (!w32_bdf_per_char_metric (font, &char2b, 1, &font->max_bounds)) |
1295 | { | |
1296 | /* Use the font width and height as max bounds, as not all BDF | |
1297 | fonts contain the letter 'x'. */ | |
1298 | font->max_bounds.width = FONT_MAX_WIDTH (font); | |
1299 | font->max_bounds.lbearing = -font->bdf->llx; | |
1300 | font->max_bounds.rbearing = FONT_MAX_WIDTH (font) - font->bdf->urx; | |
1301 | font->max_bounds.ascent = FONT_BASE (font); | |
1302 | font->max_bounds.descent = FONT_DESCENT (font); | |
1303 | } | |
82f9d565 AI |
1304 | } |
1305 | else | |
1306 | { | |
f1eed8ff JR |
1307 | if (((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) != 0) |
1308 | /* Some fonts (eg DBCS fonts) are marked as fixed width even | |
1309 | though they contain characters of different widths. */ | |
1310 | || (font->tm.tmMaxCharWidth != font->tm.tmAveCharWidth)) | |
82f9d565 AI |
1311 | { |
1312 | /* Font is not fixed pitch, so cache per_char info for the | |
1313 | ASCII characters. It would be much more work, and probably | |
1314 | not worth it, to cache other chars, since we may change | |
1315 | between using Unicode and ANSI text drawing functions at | |
1316 | run-time. */ | |
1317 | int i; | |
1318 | ||
1319 | font->per_char = xmalloc (128 * sizeof(XCharStruct)); | |
1320 | for (i = 0; i < 128; i++) | |
1321 | { | |
1322 | char2b = i; | |
1323 | w32_native_per_char_metric (font, &char2b, ANSI_FONT, | |
1324 | &font->per_char[i]); | |
1325 | } | |
1326 | } | |
1327 | else | |
1328 | w32_native_per_char_metric (font, &char2b, ANSI_FONT, | |
1329 | &font->max_bounds); | |
1330 | } | |
791f420f JR |
1331 | } |
1332 | ||
1333 | ||
9ef2e2cf JR |
1334 | /* Determine if a font is double byte. */ |
1335 | int w32_font_is_double_byte (XFontStruct *font) | |
1336 | { | |
1337 | return font->double_byte_p; | |
1338 | } | |
1339 | ||
1340 | ||
791f420f JR |
1341 | /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is |
1342 | the two-byte form of C. Encoding is returned in *CHAR2B. */ | |
1343 | ||
9ef2e2cf JR |
1344 | static INLINE enum w32_char_font_type |
1345 | w32_encode_char (c, char2b, font_info, two_byte_p) | |
791f420f JR |
1346 | int c; |
1347 | wchar_t *char2b; | |
1348 | struct font_info *font_info; | |
9ef2e2cf | 1349 | int * two_byte_p; |
791f420f JR |
1350 | { |
1351 | int charset = CHAR_CHARSET (c); | |
1352 | int codepage; | |
9ef2e2cf JR |
1353 | int unicode_p = 0; |
1354 | ||
791f420f JR |
1355 | XFontStruct *font = font_info->font; |
1356 | ||
9127e20e | 1357 | xassert (two_byte_p); |
9ef2e2cf JR |
1358 | |
1359 | *two_byte_p = w32_font_is_double_byte (font); | |
1360 | ||
791f420f JR |
1361 | /* FONT_INFO may define a scheme by which to encode byte1 and byte2. |
1362 | This may be either a program in a special encoder language or a | |
1363 | fixed encoding. */ | |
1364 | if (font_info->font_encoder) | |
1365 | { | |
1366 | /* It's a program. */ | |
1367 | struct ccl_program *ccl = font_info->font_encoder; | |
1368 | ||
1369 | if (CHARSET_DIMENSION (charset) == 1) | |
1370 | { | |
1371 | ccl->reg[0] = charset; | |
1372 | ccl->reg[1] = BYTE2 (*char2b); | |
1373 | } | |
1374 | else | |
1375 | { | |
1376 | ccl->reg[0] = charset; | |
1377 | ccl->reg[1] = BYTE1 (*char2b); | |
1378 | ccl->reg[2] = BYTE2 (*char2b); | |
1379 | } | |
1380 | ||
1381 | ccl_driver (ccl, NULL, NULL, 0, 0, NULL); | |
1382 | ||
1383 | /* We assume that MSBs are appropriately set/reset by CCL | |
1384 | program. */ | |
9ef2e2cf | 1385 | if (!*two_byte_p) /* 1-byte font */ |
791f420f | 1386 | *char2b = BUILD_WCHAR_T (0, ccl->reg[1]); |
791f420f JR |
1387 | else |
1388 | *char2b = BUILD_WCHAR_T (ccl->reg[1], ccl->reg[2]); | |
791f420f JR |
1389 | } |
1390 | else if (font_info->encoding[charset]) | |
1391 | { | |
1392 | /* Fixed encoding scheme. See fontset.h for the meaning of the | |
1393 | encoding numbers. */ | |
1394 | int enc = font_info->encoding[charset]; | |
1395 | ||
1396 | if ((enc == 1 || enc == 2) | |
1397 | && CHARSET_DIMENSION (charset) == 2) | |
1398 | *char2b = BUILD_WCHAR_T (BYTE1 (*char2b) | 0x80, BYTE2 (*char2b)); | |
1399 | ||
1400 | if (enc == 1 || enc == 3 | |
1401 | || (enc == 4 && CHARSET_DIMENSION (charset) == 1)) | |
1402 | *char2b = BUILD_WCHAR_T (BYTE1 (*char2b), BYTE2 (*char2b) | 0x80); | |
1403 | else if (enc == 4) | |
1404 | { | |
1405 | int sjis1, sjis2; | |
1406 | ||
1407 | ENCODE_SJIS (BYTE1 (*char2b), BYTE2 (*char2b), | |
1408 | sjis1, sjis2); | |
1409 | *char2b = BUILD_WCHAR_T (sjis1, sjis2); | |
1410 | } | |
1411 | } | |
1412 | codepage = w32_codepage_for_font (font_info->name); | |
1413 | ||
1414 | /* If charset is not ASCII or Latin-1, may need to move it into | |
1415 | Unicode space. */ | |
1416 | if ( font && !font->bdf && w32_use_unicode_for_codepage (codepage) | |
1417 | && charset != CHARSET_ASCII && charset != charset_latin_iso8859_1) | |
1418 | { | |
1419 | char temp[3]; | |
1420 | temp[0] = BYTE1 (*char2b); | |
1421 | temp[1] = BYTE2 (*char2b); | |
1422 | temp[2] = '\0'; | |
02f593f3 JR |
1423 | if (codepage != CP_UNICODE) |
1424 | { | |
1425 | if (temp[0]) | |
1426 | MultiByteToWideChar (codepage, 0, temp, 2, char2b, 1); | |
1427 | else | |
1428 | MultiByteToWideChar (codepage, 0, temp+1, 1, char2b, 1); | |
1429 | } | |
9ef2e2cf JR |
1430 | unicode_p = 1; |
1431 | *two_byte_p = 1; | |
1432 | } | |
1433 | if (!font) | |
1434 | return UNKNOWN_FONT; | |
9127e20e JR |
1435 | else if (font->bdf && CHARSET_DIMENSION (charset) == 1) |
1436 | return BDF_1D_FONT; | |
9ef2e2cf | 1437 | else if (font->bdf) |
9127e20e | 1438 | return BDF_2D_FONT; |
9ef2e2cf JR |
1439 | else if (unicode_p) |
1440 | return UNICODE_FONT; | |
1441 | else | |
1442 | return ANSI_FONT; | |
791f420f JR |
1443 | } |
1444 | ||
1445 | ||
1446 | /* Get face and two-byte form of character C in face FACE_ID on frame | |
1447 | F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero | |
1448 | means we want to display multibyte text. Value is a pointer to a | |
1449 | realized face that is ready for display. */ | |
1450 | ||
1451 | static INLINE struct face * | |
1452 | x_get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p) | |
1453 | struct frame *f; | |
1454 | int c, face_id; | |
1455 | wchar_t *char2b; | |
1456 | int multibyte_p; | |
1457 | { | |
1458 | struct face *face = FACE_FROM_ID (f, face_id); | |
1459 | ||
1460 | if (!multibyte_p) | |
1461 | { | |
1462 | /* Unibyte case. We don't have to encode, but we have to make | |
1463 | sure to use a face suitable for unibyte. */ | |
1464 | *char2b = BUILD_WCHAR_T (0, c); | |
93ff4395 JR |
1465 | face_id = FACE_FOR_CHAR (f, face, c); |
1466 | face = FACE_FROM_ID (f, face_id); | |
791f420f JR |
1467 | } |
1468 | else if (c < 128 && face_id < BASIC_FACE_ID_SENTINEL) | |
1469 | { | |
1470 | /* Case of ASCII in a face known to fit ASCII. */ | |
1471 | *char2b = BUILD_WCHAR_T (0, c); | |
1472 | } | |
1473 | else | |
1474 | { | |
1475 | int c1, c2, charset; | |
1476 | ||
1477 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1478 | really a one-byte character so that byte1 is zero. */ | |
1479 | SPLIT_CHAR (c, charset, c1, c2); | |
1480 | if (c2 > 0) | |
1481 | *char2b = BUILD_WCHAR_T (c1, c2); | |
1482 | else | |
1483 | *char2b = BUILD_WCHAR_T (0, c1); | |
791f420f JR |
1484 | |
1485 | /* Maybe encode the character in *CHAR2B. */ | |
93ff4395 | 1486 | if (face->font != NULL) |
791f420f JR |
1487 | { |
1488 | struct font_info *font_info | |
1489 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1490 | if (font_info) | |
9ef2e2cf | 1491 | w32_encode_char (c, char2b, font_info, &multibyte_p); |
791f420f JR |
1492 | } |
1493 | } | |
1494 | ||
1495 | /* Make sure X resources of the face are allocated. */ | |
1496 | xassert (face != NULL); | |
1497 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1498 | ||
1499 | return face; | |
1500 | } | |
1501 | ||
1502 | ||
1503 | /* Get face and two-byte form of character glyph GLYPH on frame F. | |
1504 | The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is | |
1505 | a pointer to a realized face that is ready for display. */ | |
1506 | ||
1507 | static INLINE struct face * | |
93ff4395 | 1508 | x_get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p) |
791f420f JR |
1509 | struct frame *f; |
1510 | struct glyph *glyph; | |
1511 | wchar_t *char2b; | |
93ff4395 | 1512 | int *two_byte_p; |
791f420f JR |
1513 | { |
1514 | struct face *face; | |
9ef2e2cf | 1515 | int dummy = 0; |
791f420f JR |
1516 | |
1517 | xassert (glyph->type == CHAR_GLYPH); | |
1518 | face = FACE_FROM_ID (f, glyph->face_id); | |
1519 | ||
93ff4395 JR |
1520 | if (two_byte_p) |
1521 | *two_byte_p = 0; | |
9ef2e2cf JR |
1522 | else |
1523 | two_byte_p = &dummy; | |
93ff4395 | 1524 | |
791f420f JR |
1525 | if (!glyph->multibyte_p) |
1526 | { | |
1527 | /* Unibyte case. We don't have to encode, but we have to make | |
1528 | sure to use a face suitable for unibyte. */ | |
1529 | *char2b = BUILD_WCHAR_T (0, glyph->u.ch); | |
1530 | } | |
1531 | else if (glyph->u.ch < 128 | |
1532 | && glyph->face_id < BASIC_FACE_ID_SENTINEL) | |
1533 | { | |
1534 | /* Case of ASCII in a face known to fit ASCII. */ | |
1535 | *char2b = BUILD_WCHAR_T (0, glyph->u.ch); | |
1536 | } | |
1537 | else | |
1538 | { | |
1539 | int c1, c2, charset; | |
1540 | ||
1541 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1542 | really a one-byte character so that byte1 is zero. */ | |
1543 | SPLIT_CHAR (glyph->u.ch, charset, c1, c2); | |
1544 | if (c2 > 0) | |
1545 | *char2b = BUILD_WCHAR_T (c1, c2); | |
1546 | else | |
1547 | *char2b = BUILD_WCHAR_T (0, c1); | |
1548 | ||
1549 | /* Maybe encode the character in *CHAR2B. */ | |
1550 | if (charset != CHARSET_ASCII) | |
1551 | { | |
1552 | struct font_info *font_info | |
1553 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1554 | if (font_info) | |
1555 | { | |
9ef2e2cf JR |
1556 | glyph->w32_font_type |
1557 | = w32_encode_char (glyph->u.ch, char2b, font_info, two_byte_p); | |
791f420f JR |
1558 | } |
1559 | } | |
1560 | } | |
1561 | ||
1562 | /* Make sure X resources of the face are allocated. */ | |
1563 | xassert (face != NULL); | |
1564 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1565 | return face; | |
1566 | } | |
1567 | ||
1568 | ||
1569 | /* Store one glyph for IT->char_to_display in IT->glyph_row. | |
1570 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1571 | ||
1572 | static INLINE void | |
1573 | x_append_glyph (it) | |
1574 | struct it *it; | |
1575 | { | |
1576 | struct glyph *glyph; | |
1577 | enum glyph_row_area area = it->area; | |
1578 | ||
1579 | xassert (it->glyph_row); | |
1580 | xassert (it->char_to_display != '\n' && it->char_to_display != '\t'); | |
1581 | ||
1582 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1583 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1584 | { | |
791f420f JR |
1585 | glyph->charpos = CHARPOS (it->position); |
1586 | glyph->object = it->object; | |
ec48c3a7 | 1587 | glyph->pixel_width = it->pixel_width; |
791f420f | 1588 | glyph->voffset = it->voffset; |
ec48c3a7 | 1589 | glyph->type = CHAR_GLYPH; |
791f420f | 1590 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1591 | glyph->left_box_line_p = it->start_of_box_run_p; |
1592 | glyph->right_box_line_p = it->end_of_box_run_p; | |
791f420f JR |
1593 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1594 | || it->phys_descent > it->descent); | |
ec48c3a7 | 1595 | glyph->padding_p = 0; |
93ff4395 | 1596 | glyph->glyph_not_available_p = it->glyph_not_available_p; |
ec48c3a7 JR |
1597 | glyph->face_id = it->face_id; |
1598 | glyph->u.ch = it->char_to_display; | |
1599 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1600 | ++it->glyph_row->used[area]; |
1601 | } | |
1602 | } | |
1603 | ||
1604 | /* Store one glyph for the composition IT->cmp_id in IT->glyph_row. | |
1605 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1606 | ||
1607 | static INLINE void | |
1608 | x_append_composite_glyph (it) | |
1609 | struct it *it; | |
1610 | { | |
1611 | struct glyph *glyph; | |
1612 | enum glyph_row_area area = it->area; | |
1613 | ||
1614 | xassert (it->glyph_row); | |
1615 | ||
1616 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1617 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1618 | { | |
791f420f JR |
1619 | glyph->charpos = CHARPOS (it->position); |
1620 | glyph->object = it->object; | |
ec48c3a7 | 1621 | glyph->pixel_width = it->pixel_width; |
791f420f | 1622 | glyph->voffset = it->voffset; |
ec48c3a7 | 1623 | glyph->type = COMPOSITE_GLYPH; |
791f420f | 1624 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1625 | glyph->left_box_line_p = it->start_of_box_run_p; |
1626 | glyph->right_box_line_p = it->end_of_box_run_p; | |
791f420f JR |
1627 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1628 | || it->phys_descent > it->descent); | |
ec48c3a7 JR |
1629 | glyph->padding_p = 0; |
1630 | glyph->glyph_not_available_p = 0; | |
1631 | glyph->face_id = it->face_id; | |
1632 | glyph->u.cmp_id = it->cmp_id; | |
1633 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1634 | ++it->glyph_row->used[area]; |
1635 | } | |
1636 | } | |
1637 | ||
1638 | ||
1639 | /* Change IT->ascent and IT->height according to the setting of | |
1640 | IT->voffset. */ | |
1641 | ||
1642 | static INLINE void | |
1643 | take_vertical_position_into_account (it) | |
1644 | struct it *it; | |
1645 | { | |
1646 | if (it->voffset) | |
1647 | { | |
1648 | if (it->voffset < 0) | |
1649 | /* Increase the ascent so that we can display the text higher | |
1650 | in the line. */ | |
1651 | it->ascent += abs (it->voffset); | |
1652 | else | |
1653 | /* Increase the descent so that we can display the text lower | |
1654 | in the line. */ | |
1655 | it->descent += it->voffset; | |
1656 | } | |
1657 | } | |
1658 | ||
1659 | ||
1660 | /* Produce glyphs/get display metrics for the image IT is loaded with. | |
1661 | See the description of struct display_iterator in dispextern.h for | |
1662 | an overview of struct display_iterator. */ | |
1663 | ||
1664 | static void | |
1665 | x_produce_image_glyph (it) | |
1666 | struct it *it; | |
1667 | { | |
1668 | struct image *img; | |
1669 | struct face *face; | |
1670 | ||
1671 | xassert (it->what == IT_IMAGE); | |
1672 | ||
1673 | face = FACE_FROM_ID (it->f, it->face_id); | |
1674 | img = IMAGE_FROM_ID (it->f, it->image_id); | |
1675 | xassert (img); | |
1676 | ||
1677 | /* Make sure X resources of the face and image are loaded. */ | |
1678 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1679 | prepare_image_for_display (it->f, img); | |
1680 | ||
9ef2e2cf | 1681 | it->ascent = it->phys_ascent = image_ascent (img, face); |
791f420f JR |
1682 | it->descent = it->phys_descent = img->height + 2 * img->margin - it->ascent; |
1683 | it->pixel_width = img->width + 2 * img->margin; | |
1684 | ||
1685 | it->nglyphs = 1; | |
1686 | ||
1687 | if (face->box != FACE_NO_BOX) | |
1688 | { | |
1689 | it->ascent += face->box_line_width; | |
1690 | it->descent += face->box_line_width; | |
1691 | ||
1692 | if (it->start_of_box_run_p) | |
1693 | it->pixel_width += face->box_line_width; | |
1694 | if (it->end_of_box_run_p) | |
1695 | it->pixel_width += face->box_line_width; | |
1696 | } | |
1697 | ||
1698 | take_vertical_position_into_account (it); | |
1699 | ||
1700 | if (it->glyph_row) | |
1701 | { | |
1702 | struct glyph *glyph; | |
1703 | enum glyph_row_area area = it->area; | |
1704 | ||
1705 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1706 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1707 | { | |
791f420f JR |
1708 | glyph->charpos = CHARPOS (it->position); |
1709 | glyph->object = it->object; | |
ec48c3a7 | 1710 | glyph->pixel_width = it->pixel_width; |
791f420f | 1711 | glyph->voffset = it->voffset; |
ec48c3a7 | 1712 | glyph->type = IMAGE_GLYPH; |
791f420f | 1713 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1714 | glyph->left_box_line_p = it->start_of_box_run_p; |
1715 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1716 | glyph->overlaps_vertically_p = 0; | |
1717 | glyph->padding_p = 0; | |
1718 | glyph->glyph_not_available_p = 0; | |
1719 | glyph->face_id = it->face_id; | |
1720 | glyph->u.img_id = img->id; | |
1721 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1722 | ++it->glyph_row->used[area]; |
1723 | } | |
1724 | } | |
1725 | } | |
1726 | ||
1727 | ||
1728 | /* Append a stretch glyph to IT->glyph_row. OBJECT is the source | |
1729 | of the glyph, WIDTH and HEIGHT are the width and height of the | |
1730 | stretch. ASCENT is the percentage/100 of HEIGHT to use for the | |
1731 | ascent of the glyph (0 <= ASCENT <= 1). */ | |
1732 | ||
1733 | static void | |
1734 | x_append_stretch_glyph (it, object, width, height, ascent) | |
1735 | struct it *it; | |
1736 | Lisp_Object object; | |
1737 | int width, height; | |
1738 | double ascent; | |
1739 | { | |
1740 | struct glyph *glyph; | |
1741 | enum glyph_row_area area = it->area; | |
1742 | ||
1743 | xassert (ascent >= 0 && ascent <= 1); | |
1744 | ||
1745 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1746 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1747 | { | |
791f420f JR |
1748 | glyph->charpos = CHARPOS (it->position); |
1749 | glyph->object = object; | |
ec48c3a7 | 1750 | glyph->pixel_width = width; |
791f420f | 1751 | glyph->voffset = it->voffset; |
ec48c3a7 | 1752 | glyph->type = STRETCH_GLYPH; |
791f420f | 1753 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1754 | glyph->left_box_line_p = it->start_of_box_run_p; |
1755 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1756 | glyph->overlaps_vertically_p = 0; | |
1757 | glyph->padding_p = 0; | |
1758 | glyph->glyph_not_available_p = 0; | |
1759 | glyph->face_id = it->face_id; | |
1760 | glyph->u.stretch.ascent = height * ascent; | |
1761 | glyph->u.stretch.height = height; | |
1762 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1763 | ++it->glyph_row->used[area]; |
1764 | } | |
1765 | } | |
1766 | ||
1767 | ||
1768 | /* Produce a stretch glyph for iterator IT. IT->object is the value | |
1769 | of the glyph property displayed. The value must be a list | |
1770 | `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs | |
1771 | being recognized: | |
1772 | ||
1773 | 1. `:width WIDTH' specifies that the space should be WIDTH * | |
1774 | canonical char width wide. WIDTH may be an integer or floating | |
1775 | point number. | |
1776 | ||
1777 | 2. `:relative-width FACTOR' specifies that the width of the stretch | |
1778 | should be computed from the width of the first character having the | |
1779 | `glyph' property, and should be FACTOR times that width. | |
1780 | ||
1781 | 3. `:align-to HPOS' specifies that the space should be wide enough | |
1782 | to reach HPOS, a value in canonical character units. | |
1783 | ||
1784 | Exactly one of the above pairs must be present. | |
1785 | ||
1786 | 4. `:height HEIGHT' specifies that the height of the stretch produced | |
1787 | should be HEIGHT, measured in canonical character units. | |
1788 | ||
1789 | 5. `:relative-height FACTOR' specifies that the height of the the | |
1790 | stretch should be FACTOR times the height of the characters having | |
1791 | the glyph property. | |
1792 | ||
1793 | Either none or exactly one of 4 or 5 must be present. | |
1794 | ||
1795 | 6. `:ascent ASCENT' specifies that ASCENT percent of the height | |
1796 | of the stretch should be used for the ascent of the stretch. | |
1797 | ASCENT must be in the range 0 <= ASCENT <= 100. */ | |
1798 | ||
1799 | #define NUMVAL(X) \ | |
1800 | ((INTEGERP (X) || FLOATP (X)) \ | |
1801 | ? XFLOATINT (X) \ | |
1802 | : - 1) | |
1803 | ||
1804 | ||
1805 | static void | |
1806 | x_produce_stretch_glyph (it) | |
1807 | struct it *it; | |
1808 | { | |
1809 | /* (space :width WIDTH :height HEIGHT. */ | |
1810 | extern Lisp_Object QCwidth, QCheight, QCascent, Qspace; | |
1811 | extern Lisp_Object QCrelative_width, QCrelative_height; | |
1812 | extern Lisp_Object QCalign_to; | |
1813 | Lisp_Object prop, plist; | |
1814 | double width = 0, height = 0, ascent = 0; | |
1815 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
1816 | XFontStruct *font = face->font ? face->font : FRAME_FONT (it->f); | |
1817 | ||
1818 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1819 | ||
1820 | /* List should start with `space'. */ | |
1821 | xassert (CONSP (it->object) && EQ (XCAR (it->object), Qspace)); | |
1822 | plist = XCDR (it->object); | |
1823 | ||
1824 | /* Compute the width of the stretch. */ | |
1825 | if (prop = Fplist_get (plist, QCwidth), | |
1826 | NUMVAL (prop) > 0) | |
1827 | /* Absolute width `:width WIDTH' specified and valid. */ | |
1828 | width = NUMVAL (prop) * CANON_X_UNIT (it->f); | |
1829 | else if (prop = Fplist_get (plist, QCrelative_width), | |
1830 | NUMVAL (prop) > 0) | |
1831 | { | |
1832 | /* Relative width `:relative-width FACTOR' specified and valid. | |
1833 | Compute the width of the characters having the `glyph' | |
1834 | property. */ | |
1835 | struct it it2; | |
1836 | unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); | |
1837 | ||
1838 | it2 = *it; | |
1839 | if (it->multibyte_p) | |
1840 | { | |
1841 | int maxlen = ((IT_BYTEPOS (*it) >= GPT ? ZV : GPT) | |
1842 | - IT_BYTEPOS (*it)); | |
1843 | it2.c = STRING_CHAR_AND_LENGTH (p, maxlen, it2.len); | |
1844 | } | |
1845 | else | |
1846 | it2.c = *p, it2.len = 1; | |
1847 | ||
1848 | it2.glyph_row = NULL; | |
1849 | it2.what = IT_CHARACTER; | |
1850 | x_produce_glyphs (&it2); | |
1851 | width = NUMVAL (prop) * it2.pixel_width; | |
1852 | } | |
1853 | else if (prop = Fplist_get (plist, QCalign_to), | |
1854 | NUMVAL (prop) > 0) | |
1855 | width = NUMVAL (prop) * CANON_X_UNIT (it->f) - it->current_x; | |
1856 | else | |
1857 | /* Nothing specified -> width defaults to canonical char width. */ | |
1858 | width = CANON_X_UNIT (it->f); | |
1859 | ||
1860 | /* Compute height. */ | |
1861 | if (prop = Fplist_get (plist, QCheight), | |
1862 | NUMVAL (prop) > 0) | |
1863 | height = NUMVAL (prop) * CANON_Y_UNIT (it->f); | |
1864 | else if (prop = Fplist_get (plist, QCrelative_height), | |
1865 | NUMVAL (prop) > 0) | |
1866 | height = FONT_HEIGHT (font) * NUMVAL (prop); | |
1867 | else | |
1868 | height = FONT_HEIGHT (font); | |
1869 | ||
1870 | /* Compute percentage of height used for ascent. If | |
1871 | `:ascent ASCENT' is present and valid, use that. Otherwise, | |
1872 | derive the ascent from the font in use. */ | |
1873 | if (prop = Fplist_get (plist, QCascent), | |
1874 | NUMVAL (prop) > 0 && NUMVAL (prop) <= 100) | |
1875 | ascent = NUMVAL (prop) / 100.0; | |
1876 | else | |
1877 | ascent = (double) FONT_BASE (font) / FONT_HEIGHT (font); | |
1878 | ||
1879 | if (width <= 0) | |
1880 | width = 1; | |
1881 | if (height <= 0) | |
1882 | height = 1; | |
1883 | ||
1884 | if (it->glyph_row) | |
1885 | { | |
1886 | Lisp_Object object = it->stack[it->sp - 1].string; | |
1887 | if (!STRINGP (object)) | |
1888 | object = it->w->buffer; | |
1889 | x_append_stretch_glyph (it, object, width, height, ascent); | |
1890 | } | |
1891 | ||
1892 | it->pixel_width = width; | |
1893 | it->ascent = it->phys_ascent = height * ascent; | |
1894 | it->descent = it->phys_descent = height - it->ascent; | |
1895 | it->nglyphs = 1; | |
1896 | ||
1897 | if (face->box != FACE_NO_BOX) | |
1898 | { | |
1899 | it->ascent += face->box_line_width; | |
1900 | it->descent += face->box_line_width; | |
1901 | ||
1902 | if (it->start_of_box_run_p) | |
1903 | it->pixel_width += face->box_line_width; | |
1904 | if (it->end_of_box_run_p) | |
1905 | it->pixel_width += face->box_line_width; | |
1906 | } | |
1907 | ||
1908 | take_vertical_position_into_account (it); | |
1909 | } | |
1910 | ||
1911 | /* Return proper value to be used as baseline offset of font that has | |
1912 | ASCENT and DESCENT to draw characters by the font at the vertical | |
1913 | center of the line of frame F. | |
1914 | ||
1915 | Here, out task is to find the value of BOFF in the following figure; | |
1916 | ||
1917 | -------------------------+-----------+- | |
1918 | -+-+---------+-+ | | | |
1919 | | | | | | | | |
1920 | | | | | F_ASCENT F_HEIGHT | |
1921 | | | | ASCENT | | | |
1922 | HEIGHT | | | | | | |
1923 | | | |-|-+------+-----------|------- baseline | |
1924 | | | | | BOFF | | | |
1925 | | |---------|-+-+ | | | |
1926 | | | | DESCENT | | | |
1927 | -+-+---------+-+ F_DESCENT | | |
1928 | -------------------------+-----------+- | |
1929 | ||
1930 | -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT | |
1931 | BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT | |
1932 | DESCENT = FONT->descent | |
1933 | HEIGHT = FONT_HEIGHT (FONT) | |
1934 | F_DESCENT = (F->output_data.x->font->descent | |
1935 | - F->output_data.x->baseline_offset) | |
1936 | F_HEIGHT = FRAME_LINE_HEIGHT (F) | |
1937 | */ | |
1938 | ||
1939 | #define VCENTER_BASELINE_OFFSET(FONT, F) \ | |
458f45fa KH |
1940 | (FONT_DESCENT (FONT) \ |
1941 | + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \ | |
1942 | + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \ | |
1943 | - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F))) | |
791f420f JR |
1944 | |
1945 | /* Produce glyphs/get display metrics for the display element IT is | |
1946 | loaded with. See the description of struct display_iterator in | |
1947 | dispextern.h for an overview of struct display_iterator. */ | |
1948 | ||
1949 | static void | |
1950 | x_produce_glyphs (it) | |
1951 | struct it *it; | |
1952 | { | |
93ff4395 JR |
1953 | it->glyph_not_available_p = 0; |
1954 | ||
791f420f JR |
1955 | if (it->what == IT_CHARACTER) |
1956 | { | |
1957 | wchar_t char2b; | |
1958 | XFontStruct *font; | |
93ff4395 | 1959 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
791f420f | 1960 | XCharStruct *pcm; |
93ff4395 | 1961 | int font_not_found_p; |
791f420f JR |
1962 | struct font_info *font_info; |
1963 | int boff; /* baseline offset */ | |
2d0c0bd7 JR |
1964 | /* We may change it->multibyte_p upon unibyte<->multibyte |
1965 | conversion. So, save the current value now and restore it | |
1966 | later. | |
1967 | ||
1968 | Note: It seems that we don't have to record multibyte_p in | |
1969 | struct glyph because the character code itself tells if or | |
1970 | not the character is multibyte. Thus, in the future, we must | |
1971 | consider eliminating the field `multibyte_p' in the struct | |
1972 | glyph. | |
1973 | */ | |
1974 | int saved_multibyte_p = it->multibyte_p; | |
791f420f | 1975 | |
93ff4395 JR |
1976 | /* Maybe translate single-byte characters to multibyte, or the |
1977 | other way. */ | |
791f420f | 1978 | it->char_to_display = it->c; |
93ff4395 JR |
1979 | if (!ASCII_BYTE_P (it->c)) |
1980 | { | |
1981 | if (unibyte_display_via_language_environment | |
1982 | && SINGLE_BYTE_CHAR_P (it->c) | |
1983 | && (it->c >= 0240 | |
1984 | || !NILP (Vnonascii_translation_table))) | |
1985 | { | |
1986 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
2d0c0bd7 | 1987 | it->multibyte_p = 1; |
93ff4395 JR |
1988 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1989 | face = FACE_FROM_ID (it->f, it->face_id); | |
1990 | } | |
1991 | else if (!SINGLE_BYTE_CHAR_P (it->c) | |
1992 | && !it->multibyte_p) | |
1993 | { | |
1994 | it->char_to_display = multibyte_char_to_unibyte (it->c, Qnil); | |
2d0c0bd7 | 1995 | it->multibyte_p = 0; |
93ff4395 JR |
1996 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1997 | face = FACE_FROM_ID (it->f, it->face_id); | |
1998 | } | |
1999 | } | |
791f420f | 2000 | |
93ff4395 JR |
2001 | /* Get font to use. Encode IT->char_to_display. */ |
2002 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
2003 | it->face_id, &char2b, | |
2004 | it->multibyte_p); | |
791f420f JR |
2005 | font = face->font; |
2006 | ||
2007 | /* When no suitable font found, use the default font. */ | |
2008 | font_not_found_p = font == NULL; | |
2009 | if (font_not_found_p) | |
2010 | { | |
2011 | font = FRAME_FONT (it->f); | |
2012 | boff = it->f->output_data.w32->baseline_offset; | |
2013 | font_info = NULL; | |
2014 | } | |
2015 | else | |
2016 | { | |
2017 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2018 | boff = font_info->baseline_offset; | |
2019 | if (font_info->vertical_centering) | |
2020 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2021 | } | |
2022 | ||
791f420f JR |
2023 | if (it->char_to_display >= ' ' |
2024 | && (!it->multibyte_p || it->char_to_display < 128)) | |
2025 | { | |
2026 | /* Either unibyte or ASCII. */ | |
2027 | int stretched_p; | |
2028 | ||
2029 | it->nglyphs = 1; | |
2030 | ||
82f9d565 | 2031 | pcm = w32_per_char_metric (font, &char2b, |
9127e20e | 2032 | font->bdf ? BDF_1D_FONT : ANSI_FONT); |
791f420f JR |
2033 | it->ascent = FONT_BASE (font) + boff; |
2034 | it->descent = FONT_DESCENT (font) - boff; | |
791f420f | 2035 | |
9ef2e2cf JR |
2036 | if (pcm) |
2037 | { | |
2038 | it->phys_ascent = pcm->ascent + boff; | |
2039 | it->phys_descent = pcm->descent - boff; | |
2040 | it->pixel_width = pcm->width; | |
2041 | } | |
2042 | else | |
2043 | { | |
2044 | it->glyph_not_available_p = 1; | |
9127e20e JR |
2045 | it->phys_ascent = FONT_BASE (font) + boff; |
2046 | it->phys_descent = FONT_DESCENT (font) - boff; | |
2047 | it->pixel_width = FONT_WIDTH (font); | |
9ef2e2cf JR |
2048 | } |
2049 | ||
791f420f JR |
2050 | /* If this is a space inside a region of text with |
2051 | `space-width' property, change its width. */ | |
2052 | stretched_p = it->char_to_display == ' ' && !NILP (it->space_width); | |
2053 | if (stretched_p) | |
2054 | it->pixel_width *= XFLOATINT (it->space_width); | |
2055 | ||
2056 | /* If face has a box, add the box thickness to the character | |
2057 | height. If character has a box line to the left and/or | |
2058 | right, add the box line width to the character's width. */ | |
2059 | if (face->box != FACE_NO_BOX) | |
2060 | { | |
2061 | int thick = face->box_line_width; | |
2062 | ||
2063 | it->ascent += thick; | |
2064 | it->descent += thick; | |
2065 | ||
2066 | if (it->start_of_box_run_p) | |
2067 | it->pixel_width += thick; | |
2068 | if (it->end_of_box_run_p) | |
2069 | it->pixel_width += thick; | |
2070 | } | |
2071 | ||
2072 | /* If face has an overline, add the height of the overline | |
2073 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2074 | if (face->overline_p) | |
2075 | it->ascent += 2; | |
2076 | ||
2077 | take_vertical_position_into_account (it); | |
2078 | ||
2079 | /* If we have to actually produce glyphs, do it. */ | |
2080 | if (it->glyph_row) | |
2081 | { | |
2082 | if (stretched_p) | |
2083 | { | |
2084 | /* Translate a space with a `space-width' property | |
2085 | into a stretch glyph. */ | |
2086 | double ascent = (double) FONT_BASE (font) | |
2087 | / FONT_HEIGHT (font); | |
2088 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
2089 | it->ascent + it->descent, ascent); | |
2090 | } | |
2091 | else | |
2092 | x_append_glyph (it); | |
2093 | ||
2094 | /* If characters with lbearing or rbearing are displayed | |
2095 | in this line, record that fact in a flag of the | |
2096 | glyph row. This is used to optimize X output code. */ | |
9ef2e2cf | 2097 | if (pcm && (pcm->lbearing < 0 || pcm->rbearing > pcm->width)) |
791f420f JR |
2098 | it->glyph_row->contains_overlapping_glyphs_p = 1; |
2099 | } | |
2100 | } | |
2101 | else if (it->char_to_display == '\n') | |
2102 | { | |
2103 | /* A newline has no width but we need the height of the line. */ | |
2104 | it->pixel_width = 0; | |
2105 | it->nglyphs = 0; | |
2106 | it->ascent = it->phys_ascent = FONT_BASE (font) + boff; | |
2107 | it->descent = it->phys_descent = FONT_DESCENT (font) - boff; | |
2108 | ||
2109 | if (face->box != FACE_NO_BOX) | |
2110 | { | |
2111 | int thick = face->box_line_width; | |
2112 | it->ascent += thick; | |
2113 | it->descent += thick; | |
2114 | } | |
2115 | } | |
2116 | else if (it->char_to_display == '\t') | |
2117 | { | |
2118 | int tab_width = it->tab_width * CANON_X_UNIT (it->f); | |
9ef2e2cf | 2119 | int x = it->current_x + it->continuation_lines_width; |
791f420f JR |
2120 | int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; |
2121 | ||
9127e20e JR |
2122 | /* If the distance from the current position to the next tab |
2123 | stop is less than a canonical character width, use the | |
2124 | tab stop after that. */ | |
2125 | if (next_tab_x - x < CANON_X_UNIT (it->f)) | |
2126 | next_tab_x += tab_width; | |
2127 | ||
791f420f JR |
2128 | it->pixel_width = next_tab_x - x; |
2129 | it->nglyphs = 1; | |
2130 | it->ascent = it->phys_ascent = FONT_BASE (font) + boff; | |
2131 | it->descent = it->phys_descent = FONT_DESCENT (font) - boff; | |
2132 | ||
2133 | if (it->glyph_row) | |
2134 | { | |
2135 | double ascent = (double) it->ascent / (it->ascent + it->descent); | |
2136 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
2137 | it->ascent + it->descent, ascent); | |
2138 | } | |
2139 | } | |
2140 | else | |
2141 | { | |
00fe468b JR |
2142 | /* A multi-byte character. |
2143 | If we found a font, this font should give us the right | |
791f420f JR |
2144 | metrics. If we didn't find a font, use the frame's |
2145 | default font and calculate the width of the character | |
2146 | from the charset width; this is what old redisplay code | |
2147 | did. */ | |
9127e20e JR |
2148 | enum w32_char_font_type type; |
2149 | ||
2150 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (it->c)) == 1) | |
2151 | type = BDF_1D_FONT; | |
2152 | else if (font->bdf) | |
2153 | type = BDF_2D_FONT; | |
2154 | else | |
2155 | type = UNICODE_FONT; | |
2156 | ||
82f9d565 | 2157 | pcm = w32_per_char_metric (font, &char2b, type); |
00fe468b | 2158 | |
93ff4395 JR |
2159 | if (font_not_found_p || !pcm) |
2160 | { | |
2161 | int charset = CHAR_CHARSET (it->char_to_display); | |
00fe468b | 2162 | |
93ff4395 JR |
2163 | it->glyph_not_available_p = 1; |
2164 | it->pixel_width = (FONT_WIDTH (FRAME_FONT (it->f)) | |
2165 | * CHARSET_WIDTH (charset)); | |
2166 | it->phys_ascent = FONT_BASE (font) + boff; | |
2167 | it->phys_descent = FONT_DESCENT (font) - boff; | |
2168 | } | |
2169 | else | |
2170 | { | |
9ef2e2cf | 2171 | it->pixel_width = pcm->width; |
93ff4395 JR |
2172 | it->phys_ascent = pcm->ascent + boff; |
2173 | it->phys_descent = pcm->descent - boff; | |
2174 | if (it->glyph_row | |
2175 | && (pcm->lbearing < 0 | |
2176 | || pcm->rbearing > pcm->width)) | |
2177 | it->glyph_row->contains_overlapping_glyphs_p = 1; | |
00fe468b | 2178 | } |
791f420f JR |
2179 | it->nglyphs = 1; |
2180 | it->ascent = FONT_BASE (font) + boff; | |
2181 | it->descent = FONT_DESCENT (font) - boff; | |
00fe468b | 2182 | |
791f420f JR |
2183 | if (face->box != FACE_NO_BOX) |
2184 | { | |
2185 | int thick = face->box_line_width; | |
2186 | it->ascent += thick; | |
2187 | it->descent += thick; | |
2188 | ||
2189 | if (it->start_of_box_run_p) | |
2190 | it->pixel_width += thick; | |
2191 | if (it->end_of_box_run_p) | |
2192 | it->pixel_width += thick; | |
2193 | } | |
2194 | ||
2195 | /* If face has an overline, add the height of the overline | |
2196 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2197 | if (face->overline_p) | |
2198 | it->ascent += 2; | |
2199 | ||
2200 | take_vertical_position_into_account (it); | |
2201 | ||
2202 | if (it->glyph_row) | |
2203 | x_append_glyph (it); | |
2204 | } | |
2d0c0bd7 | 2205 | it->multibyte_p = saved_multibyte_p; |
791f420f JR |
2206 | } |
2207 | else if (it->what == IT_COMPOSITION) | |
2208 | { | |
01b220b6 JR |
2209 | /* Note: A composition is represented as one glyph in the |
2210 | glyph matrix. There are no padding glyphs. */ | |
2211 | wchar_t char2b; | |
2212 | XFontStruct *font; | |
2213 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
2214 | XCharStruct *pcm; | |
2215 | int font_not_found_p; | |
2216 | struct font_info *font_info; | |
2217 | int boff; /* baseline offset */ | |
2218 | struct composition *cmp = composition_table[it->cmp_id]; | |
2219 | ||
2220 | /* Maybe translate single-byte characters to multibyte. */ | |
2221 | it->char_to_display = it->c; | |
2222 | if (unibyte_display_via_language_environment | |
2223 | && SINGLE_BYTE_CHAR_P (it->c) | |
2224 | && (it->c >= 0240 | |
2225 | || (it->c >= 0200 | |
2226 | && !NILP (Vnonascii_translation_table)))) | |
2227 | { | |
2228 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
2229 | } | |
2230 | ||
2231 | /* Get face and font to use. Encode IT->char_to_display. */ | |
2232 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); | |
2233 | face = FACE_FROM_ID (it->f, it->face_id); | |
2234 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
2235 | it->face_id, &char2b, it->multibyte_p); | |
2236 | font = face->font; | |
2237 | ||
2238 | /* When no suitable font found, use the default font. */ | |
2239 | font_not_found_p = font == NULL; | |
2240 | if (font_not_found_p) | |
2241 | { | |
2242 | font = FRAME_FONT (it->f); | |
2243 | boff = it->f->output_data.w32->baseline_offset; | |
2244 | font_info = NULL; | |
2245 | } | |
2246 | else | |
2247 | { | |
2248 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2249 | boff = font_info->baseline_offset; | |
2250 | if (font_info->vertical_centering) | |
2251 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2252 | } | |
2253 | ||
2254 | /* There are no padding glyphs, so there is only one glyph to | |
2255 | produce for the composition. Important is that pixel_width, | |
2256 | ascent and descent are the values of what is drawn by | |
2257 | draw_glyphs (i.e. the values of the overall glyphs composed). */ | |
2258 | it->nglyphs = 1; | |
2259 | ||
2260 | /* If we have not yet calculated pixel size data of glyphs of | |
2261 | the composition for the current face font, calculate them | |
2262 | now. Theoretically, we have to check all fonts for the | |
2263 | glyphs, but that requires much time and memory space. So, | |
2264 | here we check only the font of the first glyph. This leads | |
2265 | to incorrect display very rarely, and C-l (recenter) can | |
2266 | correct the display anyway. */ | |
2267 | if (cmp->font != (void *) font) | |
2268 | { | |
2269 | /* Ascent and descent of the font of the first character of | |
2270 | this composition (adjusted by baseline offset). Ascent | |
2271 | and descent of overall glyphs should not be less than | |
2272 | them respectively. */ | |
2273 | int font_ascent = FONT_BASE (font) + boff; | |
2274 | int font_descent = FONT_DESCENT (font) - boff; | |
2275 | /* Bounding box of the overall glyphs. */ | |
2276 | int leftmost, rightmost, lowest, highest; | |
2277 | int i, width, ascent, descent; | |
1521ce96 | 2278 | enum w32_char_font_type font_type; |
01b220b6 JR |
2279 | |
2280 | cmp->font = (void *) font; | |
2281 | ||
2282 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (it->c)) == 1) | |
2283 | font_type = BDF_1D_FONT; | |
2284 | else if (font->bdf) | |
2285 | font_type = BDF_2D_FONT; | |
2286 | else | |
2287 | font_type = UNICODE_FONT; | |
2288 | ||
2289 | /* Initialize the bounding box. */ | |
f201d732 JR |
2290 | if (font_info |
2291 | && (pcm = w32_per_char_metric (font, &char2b, font_type))) | |
01b220b6 JR |
2292 | { |
2293 | width = pcm->width; | |
2294 | ascent = pcm->ascent; | |
2295 | descent = pcm->descent; | |
2296 | } | |
2297 | else | |
2298 | { | |
2299 | width = FONT_WIDTH (font); | |
2300 | ascent = FONT_BASE (font); | |
2301 | descent = FONT_DESCENT (font); | |
2302 | } | |
2303 | ||
2304 | rightmost = width; | |
2305 | lowest = - descent + boff; | |
2306 | highest = ascent + boff; | |
2307 | leftmost = 0; | |
2308 | ||
2309 | if (font_info | |
2310 | && font_info->default_ascent | |
2311 | && CHAR_TABLE_P (Vuse_default_ascent) | |
2312 | && !NILP (Faref (Vuse_default_ascent, | |
2313 | make_number (it->char_to_display)))) | |
2314 | highest = font_info->default_ascent + boff; | |
2315 | ||
2316 | /* Draw the first glyph at the normal position. It may be | |
2317 | shifted to right later if some other glyphs are drawn at | |
2318 | the left. */ | |
2319 | cmp->offsets[0] = 0; | |
2320 | cmp->offsets[1] = boff; | |
2321 | ||
2322 | /* Set cmp->offsets for the remaining glyphs. */ | |
2323 | for (i = 1; i < cmp->glyph_len; i++) | |
2324 | { | |
2325 | int left, right, btm, top; | |
2326 | int ch = COMPOSITION_GLYPH (cmp, i); | |
2327 | int face_id = FACE_FOR_CHAR (it->f, face, ch); | |
2328 | ||
2329 | face = FACE_FROM_ID (it->f, face_id); | |
2330 | x_get_char_face_and_encoding (it->f, ch, face->id, &char2b, | |
2331 | it->multibyte_p); | |
2332 | font = face->font; | |
2333 | if (font == NULL) | |
2334 | { | |
2335 | font = FRAME_FONT (it->f); | |
2336 | boff = it->f->output_data.w32->baseline_offset; | |
2337 | font_info = NULL; | |
2338 | } | |
2339 | else | |
2340 | { | |
2341 | font_info | |
2342 | = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2343 | boff = font_info->baseline_offset; | |
2344 | if (font_info->vertical_centering) | |
2345 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2346 | } | |
2347 | ||
2348 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (ch)) == 1) | |
2349 | font_type = BDF_1D_FONT; | |
2350 | else if (font->bdf) | |
2351 | font_type = BDF_2D_FONT; | |
2352 | else | |
2353 | font_type = UNICODE_FONT; | |
2354 | ||
f201d732 JR |
2355 | if (font_info |
2356 | && (pcm = w32_per_char_metric (font, &char2b, font_type))) | |
01b220b6 JR |
2357 | { |
2358 | width = pcm->width; | |
2359 | ascent = pcm->ascent; | |
2360 | descent = pcm->descent; | |
2361 | } | |
2362 | else | |
2363 | { | |
2364 | width = FONT_WIDTH (font); | |
f201d732 JR |
2365 | ascent = 1; |
2366 | descent = 0; | |
01b220b6 JR |
2367 | } |
2368 | ||
2369 | if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) | |
2370 | { | |
2371 | /* Relative composition with or without | |
2372 | alternate chars. */ | |
2373 | left = (leftmost + rightmost - width) / 2; | |
2374 | btm = - descent + boff; | |
2375 | if (font_info && font_info->relative_compose | |
2376 | && (! CHAR_TABLE_P (Vignore_relative_composition) | |
2377 | || NILP (Faref (Vignore_relative_composition, | |
2378 | make_number (ch))))) | |
2379 | { | |
2380 | ||
2381 | if (- descent >= font_info->relative_compose) | |
2382 | /* One extra pixel between two glyphs. */ | |
2383 | btm = highest + 1; | |
2384 | else if (ascent <= 0) | |
2385 | /* One extra pixel between two glyphs. */ | |
2386 | btm = lowest - 1 - ascent - descent; | |
2387 | } | |
2388 | } | |
2389 | else | |
2390 | { | |
2391 | /* A composition rule is specified by an integer | |
2392 | value that encodes global and new reference | |
2393 | points (GREF and NREF). GREF and NREF are | |
2394 | specified by numbers as below: | |
2395 | ||
2396 | 0---1---2 -- ascent | |
2397 | | | | |
2398 | | | | |
2399 | | | | |
2400 | 9--10--11 -- center | |
2401 | | | | |
2402 | ---3---4---5--- baseline | |
2403 | | | | |
2404 | 6---7---8 -- descent | |
2405 | */ | |
2406 | int rule = COMPOSITION_RULE (cmp, i); | |
2407 | int gref, nref, grefx, grefy, nrefx, nrefy; | |
2408 | ||
2409 | COMPOSITION_DECODE_RULE (rule, gref, nref); | |
2410 | grefx = gref % 3, nrefx = nref % 3; | |
2411 | grefy = gref / 3, nrefy = nref / 3; | |
2412 | ||
2413 | left = (leftmost | |
2414 | + grefx * (rightmost - leftmost) / 2 | |
2415 | - nrefx * width / 2); | |
2416 | btm = ((grefy == 0 ? highest | |
2417 | : grefy == 1 ? 0 | |
2418 | : grefy == 2 ? lowest | |
2419 | : (highest + lowest) / 2) | |
2420 | - (nrefy == 0 ? ascent + descent | |
2421 | : nrefy == 1 ? descent - boff | |
2422 | : nrefy == 2 ? 0 | |
2423 | : (ascent + descent) / 2)); | |
2424 | } | |
2425 | ||
2426 | cmp->offsets[i * 2] = left; | |
2427 | cmp->offsets[i * 2 + 1] = btm + descent; | |
2428 | ||
2429 | /* Update the bounding box of the overall glyphs. */ | |
2430 | right = left + width; | |
2431 | top = btm + descent + ascent; | |
2432 | if (left < leftmost) | |
2433 | leftmost = left; | |
2434 | if (right > rightmost) | |
2435 | rightmost = right; | |
2436 | if (top > highest) | |
2437 | highest = top; | |
2438 | if (btm < lowest) | |
2439 | lowest = btm; | |
2440 | } | |
2441 | ||
2442 | /* If there are glyphs whose x-offsets are negative, | |
2443 | shift all glyphs to the right and make all x-offsets | |
2444 | non-negative. */ | |
2445 | if (leftmost < 0) | |
2446 | { | |
2447 | for (i = 0; i < cmp->glyph_len; i++) | |
2448 | cmp->offsets[i * 2] -= leftmost; | |
2449 | rightmost -= leftmost; | |
2450 | } | |
2451 | ||
2452 | cmp->pixel_width = rightmost; | |
2453 | cmp->ascent = highest; | |
2454 | cmp->descent = - lowest; | |
2455 | if (cmp->ascent < font_ascent) | |
2456 | cmp->ascent = font_ascent; | |
2457 | if (cmp->descent < font_descent) | |
2458 | cmp->descent = font_descent; | |
2459 | } | |
2460 | ||
2461 | it->pixel_width = cmp->pixel_width; | |
2462 | it->ascent = it->phys_ascent = cmp->ascent; | |
2463 | it->descent = it->phys_descent = cmp->descent; | |
2464 | ||
2465 | if (face->box != FACE_NO_BOX) | |
2466 | { | |
2467 | int thick = face->box_line_width; | |
2468 | it->ascent += thick; | |
2469 | it->descent += thick; | |
2470 | ||
2471 | if (it->start_of_box_run_p) | |
2472 | it->pixel_width += thick; | |
2473 | if (it->end_of_box_run_p) | |
2474 | it->pixel_width += thick; | |
2475 | } | |
2476 | ||
2477 | /* If face has an overline, add the height of the overline | |
2478 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2479 | if (face->overline_p) | |
2480 | it->ascent += 2; | |
2481 | ||
2482 | take_vertical_position_into_account (it); | |
2483 | ||
2484 | if (it->glyph_row) | |
2485 | x_append_composite_glyph (it); | |
791f420f JR |
2486 | } |
2487 | else if (it->what == IT_IMAGE) | |
2488 | x_produce_image_glyph (it); | |
2489 | else if (it->what == IT_STRETCH) | |
2490 | x_produce_stretch_glyph (it); | |
2491 | ||
2492 | /* Accumulate dimensions. */ | |
2493 | xassert (it->ascent >= 0 && it->descent > 0); | |
2494 | if (it->area == TEXT_AREA) | |
2495 | it->current_x += it->pixel_width; | |
2496 | ||
9ef2e2cf JR |
2497 | it->descent += it->extra_line_spacing; |
2498 | ||
791f420f JR |
2499 | it->max_ascent = max (it->max_ascent, it->ascent); |
2500 | it->max_descent = max (it->max_descent, it->descent); | |
2501 | it->max_phys_ascent = max (it->max_phys_ascent, it->phys_ascent); | |
2502 | it->max_phys_descent = max (it->max_phys_descent, it->phys_descent); | |
2503 | } | |
2504 | ||
2505 | ||
2506 | /* Estimate the pixel height of the mode or top line on frame F. | |
2507 | FACE_ID specifies what line's height to estimate. */ | |
2508 | ||
2509 | int | |
2510 | x_estimate_mode_line_height (f, face_id) | |
2511 | struct frame *f; | |
2512 | enum face_id face_id; | |
2513 | { | |
250cfece | 2514 | int height = FONT_HEIGHT (FRAME_FONT (f)); |
791f420f JR |
2515 | |
2516 | /* This function is called so early when Emacs starts that the face | |
2517 | cache and mode line face are not yet initialized. */ | |
2518 | if (FRAME_FACE_CACHE (f)) | |
2519 | { | |
2520 | struct face *face = FACE_FROM_ID (f, face_id); | |
9ef2e2cf | 2521 | if (face) |
250cfece JR |
2522 | { |
2523 | if (face->font) | |
2524 | height = FONT_HEIGHT (face->font); | |
2525 | height += 2 * face->box_line_width; | |
2526 | } | |
2527 | ||
791f420f JR |
2528 | } |
2529 | ||
2530 | return height; | |
2531 | } | |
cabb23bc | 2532 | |
cabb23bc | 2533 | \f |
791f420f JR |
2534 | |
2535 | BOOL | |
2536 | w32_use_unicode_for_codepage (codepage) | |
2537 | int codepage; | |
2538 | { | |
2539 | /* If the current codepage is supported, use Unicode for output. */ | |
2540 | return (w32_enable_unicode_output | |
02f593f3 JR |
2541 | && codepage != CP_8BIT |
2542 | && (codepage == CP_UNICODE || IsValidCodePage (codepage))); | |
791f420f JR |
2543 | } |
2544 | ||
2545 | \f | |
2546 | /*********************************************************************** | |
2547 | Glyph display | |
2548 | ***********************************************************************/ | |
2549 | ||
2550 | /* A sequence of glyphs to be drawn in the same face. | |
2551 | ||
2552 | This data structure is not really completely X specific, so it | |
2553 | could possibly, at least partially, be useful for other systems. It | |
2554 | is currently not part of the external redisplay interface because | |
2555 | it's not clear what other systems will need. */ | |
2556 | ||
2557 | struct glyph_string | |
2558 | { | |
2559 | /* X-origin of the string. */ | |
2560 | int x; | |
2561 | ||
2562 | /* Y-origin and y-position of the base line of this string. */ | |
2563 | int y, ybase; | |
2564 | ||
2565 | /* The width of the string, not including a face extension. */ | |
2566 | int width; | |
2567 | ||
2568 | /* The width of the string, including a face extension. */ | |
2569 | int background_width; | |
2570 | ||
2571 | /* The height of this string. This is the height of the line this | |
2572 | string is drawn in, and can be different from the height of the | |
2573 | font the string is drawn in. */ | |
2574 | int height; | |
2575 | ||
2576 | /* Number of pixels this string overwrites in front of its x-origin. | |
2577 | This number is zero if the string has an lbearing >= 0; it is | |
2578 | -lbearing, if the string has an lbearing < 0. */ | |
2579 | int left_overhang; | |
2580 | ||
2581 | /* Number of pixels this string overwrites past its right-most | |
2582 | nominal x-position, i.e. x + width. Zero if the string's | |
2583 | rbearing is <= its nominal width, rbearing - width otherwise. */ | |
2584 | int right_overhang; | |
2585 | ||
2586 | /* The frame on which the glyph string is drawn. */ | |
2587 | struct frame *f; | |
2588 | ||
2589 | /* The window on which the glyph string is drawn. */ | |
2590 | struct window *w; | |
2591 | ||
2592 | /* X display and window for convenience. */ | |
2593 | Window window; | |
2594 | ||
2595 | /* The glyph row for which this string was built. It determines the | |
2596 | y-origin and height of the string. */ | |
2597 | struct glyph_row *row; | |
2598 | ||
2599 | /* The area within row. */ | |
2600 | enum glyph_row_area area; | |
2601 | ||
2602 | /* Characters to be drawn, and number of characters. */ | |
2603 | wchar_t *char2b; | |
2604 | int nchars; | |
2605 | ||
791f420f JR |
2606 | /* A face-override for drawing cursors, mouse face and similar. */ |
2607 | enum draw_glyphs_face hl; | |
2608 | ||
2609 | /* Face in which this string is to be drawn. */ | |
2610 | struct face *face; | |
2611 | ||
2612 | /* Font in which this string is to be drawn. */ | |
2613 | XFontStruct *font; | |
2614 | ||
2615 | /* Font info for this string. */ | |
2616 | struct font_info *font_info; | |
2617 | ||
2618 | /* Non-null means this string describes (part of) a composition. | |
2619 | All characters from char2b are drawn composed. */ | |
2620 | struct composition *cmp; | |
2621 | ||
2622 | /* Index of this glyph string's first character in the glyph | |
2623 | definition of CMP. If this is zero, this glyph string describes | |
2624 | the first character of a composition. */ | |
2625 | int gidx; | |
2626 | ||
2627 | /* 1 means this glyph strings face has to be drawn to the right end | |
2628 | of the window's drawing area. */ | |
2629 | unsigned extends_to_end_of_line_p : 1; | |
2630 | ||
2631 | /* 1 means the background of this string has been drawn. */ | |
2632 | unsigned background_filled_p : 1; | |
2633 | ||
2634 | /* 1 means glyph string must be drawn with 16-bit functions. */ | |
2635 | unsigned two_byte_p : 1; | |
2636 | ||
2637 | /* 1 means that the original font determined for drawing this glyph | |
2638 | string could not be loaded. The member `font' has been set to | |
2639 | the frame's default font in this case. */ | |
2640 | unsigned font_not_found_p : 1; | |
2641 | ||
2642 | /* 1 means that the face in which this glyph string is drawn has a | |
2643 | stipple pattern. */ | |
2644 | unsigned stippled_p : 1; | |
2645 | ||
2646 | /* 1 means only the foreground of this glyph string must be drawn, | |
2647 | and we should use the physical height of the line this glyph | |
2648 | string appears in as clip rect. */ | |
2649 | unsigned for_overlaps_p : 1; | |
2650 | ||
2651 | /* The GC to use for drawing this glyph string. */ | |
2652 | XGCValues *gc; | |
2653 | ||
2654 | HDC hdc; | |
2655 | ||
2656 | /* A pointer to the first glyph in the string. This glyph | |
2657 | corresponds to char2b[0]. Needed to draw rectangles if | |
2658 | font_not_found_p is 1. */ | |
2659 | struct glyph *first_glyph; | |
2660 | ||
2661 | /* Image, if any. */ | |
2662 | struct image *img; | |
2663 | ||
2664 | struct glyph_string *next, *prev; | |
2665 | }; | |
2666 | ||
2667 | ||
9ef2e2cf | 2668 | /* Encapsulate the different ways of displaying text under W32. */ |
791f420f | 2669 | |
9127e20e | 2670 | void W32_TEXTOUT (s, x, y,chars,nchars) |
791f420f JR |
2671 | struct glyph_string * s; |
2672 | int x, y; | |
2673 | wchar_t * chars; | |
2674 | int nchars; | |
2675 | { | |
9ef2e2cf | 2676 | int charset_dim = w32_font_is_double_byte (s->gc->font) ? 2 : 1; |
791f420f JR |
2677 | if (s->gc->font->bdf) |
2678 | w32_BDF_TextOut (s->gc->font->bdf, s->hdc, | |
00c96995 JR |
2679 | x, y, (char *) chars, charset_dim, |
2680 | nchars * charset_dim, 0); | |
9ef2e2cf | 2681 | else if (s->first_glyph->w32_font_type == UNICODE_FONT) |
791f420f JR |
2682 | ExtTextOutW (s->hdc, x, y, 0, NULL, chars, nchars, NULL); |
2683 | else | |
2684 | ExtTextOut (s->hdc, x, y, 0, NULL, (char *) chars, | |
9ef2e2cf | 2685 | nchars * charset_dim, NULL); |
791f420f JR |
2686 | } |
2687 | ||
2688 | #if 0 | |
2689 | ||
2690 | static void | |
2691 | x_dump_glyph_string (s) | |
2692 | struct glyph_string *s; | |
2693 | { | |
2694 | fprintf (stderr, "glyph string\n"); | |
2695 | fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", | |
2696 | s->x, s->y, s->width, s->height); | |
2697 | fprintf (stderr, " ybase = %d\n", s->ybase); | |
2698 | fprintf (stderr, " hl = %d\n", s->hl); | |
2699 | fprintf (stderr, " left overhang = %d, right = %d\n", | |
2700 | s->left_overhang, s->right_overhang); | |
2701 | fprintf (stderr, " nchars = %d\n", s->nchars); | |
2702 | fprintf (stderr, " extends to end of line = %d\n", | |
2703 | s->extends_to_end_of_line_p); | |
2704 | fprintf (stderr, " font height = %d\n", FONT_HEIGHT (s->font)); | |
2705 | fprintf (stderr, " bg width = %d\n", s->background_width); | |
2706 | } | |
2707 | ||
2708 | #endif /* GLYPH_DEBUG */ | |
2709 | ||
2710 | ||
2711 | ||
2712 | static void x_append_glyph_string_lists P_ ((struct glyph_string **, | |
2713 | struct glyph_string **, | |
2714 | struct glyph_string *, | |
2715 | struct glyph_string *)); | |
2716 | static void x_prepend_glyph_string_lists P_ ((struct glyph_string **, | |
2717 | struct glyph_string **, | |
2718 | struct glyph_string *, | |
2719 | struct glyph_string *)); | |
2720 | static void x_append_glyph_string P_ ((struct glyph_string **, | |
2721 | struct glyph_string **, | |
2722 | struct glyph_string *)); | |
2723 | static int x_left_overwritten P_ ((struct glyph_string *)); | |
2724 | static int x_left_overwriting P_ ((struct glyph_string *)); | |
2725 | static int x_right_overwritten P_ ((struct glyph_string *)); | |
2726 | static int x_right_overwriting P_ ((struct glyph_string *)); | |
2727 | static int x_fill_glyph_string P_ ((struct glyph_string *, int, int, | |
2728 | int, int)); | |
2729 | static void w32_init_glyph_string P_ ((struct glyph_string *, HDC hdc, | |
2730 | wchar_t *, struct window *, | |
2731 | struct glyph_row *, | |
2732 | enum glyph_row_area, int, | |
2733 | enum draw_glyphs_face)); | |
2734 | static int x_draw_glyphs P_ ((struct window *, int , struct glyph_row *, | |
2735 | enum glyph_row_area, int, int, | |
2736 | enum draw_glyphs_face, int *, int *, int)); | |
2737 | static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); | |
2738 | static void x_set_glyph_string_gc P_ ((struct glyph_string *)); | |
2739 | static void x_draw_glyph_string_background P_ ((struct glyph_string *, | |
2740 | int)); | |
2741 | static void x_draw_glyph_string_foreground P_ ((struct glyph_string *)); | |
2742 | static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *)); | |
791f420f JR |
2743 | static void x_draw_glyph_string_box P_ ((struct glyph_string *)); |
2744 | static void x_draw_glyph_string P_ ((struct glyph_string *)); | |
2745 | static void x_compute_glyph_string_overhangs P_ ((struct glyph_string *)); | |
2746 | static void x_set_cursor_gc P_ ((struct glyph_string *)); | |
2747 | static void x_set_mode_line_face_gc P_ ((struct glyph_string *)); | |
2748 | static void x_set_mouse_face_gc P_ ((struct glyph_string *)); | |
2749 | static void w32_get_glyph_overhangs P_ ((HDC hdc, struct glyph *, | |
2750 | struct frame *, | |
9ef2e2cf | 2751 | int *, int *)); |
791f420f JR |
2752 | static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int)); |
2753 | static int w32_alloc_lighter_color (struct frame *, COLORREF *, double, int); | |
2754 | static void w32_setup_relief_color P_ ((struct frame *, struct relief *, | |
2755 | double, int, COLORREF)); | |
2756 | static void x_setup_relief_colors P_ ((struct glyph_string *)); | |
2757 | static void x_draw_image_glyph_string P_ ((struct glyph_string *)); | |
2758 | static void x_draw_image_relief P_ ((struct glyph_string *)); | |
2759 | static void x_draw_image_foreground P_ ((struct glyph_string *)); | |
2760 | static void w32_draw_image_foreground_1 P_ ((struct glyph_string *, HBITMAP)); | |
2761 | static void x_fill_image_glyph_string P_ ((struct glyph_string *)); | |
2762 | static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, | |
2763 | int, int, int)); | |
2764 | static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int, | |
2765 | int, int, int, int, RECT *)); | |
2766 | static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, | |
2767 | int, int, int, RECT *)); | |
2768 | static void x_fix_overlapping_area P_ ((struct window *, struct glyph_row *, | |
2769 | enum glyph_row_area)); | |
2770 | ||
2771 | ||
2772 | /* Append the list of glyph strings with head H and tail T to the list | |
2773 | with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ | |
2774 | ||
2775 | static INLINE void | |
2776 | x_append_glyph_string_lists (head, tail, h, t) | |
2777 | struct glyph_string **head, **tail; | |
2778 | struct glyph_string *h, *t; | |
2779 | { | |
2780 | if (h) | |
2781 | { | |
2782 | if (*head) | |
2783 | (*tail)->next = h; | |
2784 | else | |
2785 | *head = h; | |
2786 | h->prev = *tail; | |
2787 | *tail = t; | |
2788 | } | |
2789 | } | |
2790 | ||
2791 | ||
2792 | /* Prepend the list of glyph strings with head H and tail T to the | |
2793 | list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the | |
2794 | result. */ | |
2795 | ||
2796 | static INLINE void | |
2797 | x_prepend_glyph_string_lists (head, tail, h, t) | |
2798 | struct glyph_string **head, **tail; | |
2799 | struct glyph_string *h, *t; | |
2800 | { | |
2801 | if (h) | |
2802 | { | |
2803 | if (*head) | |
2804 | (*head)->prev = t; | |
2805 | else | |
2806 | *tail = t; | |
2807 | t->next = *head; | |
2808 | *head = h; | |
2809 | } | |
2810 | } | |
2811 | ||
2812 | ||
2813 | /* Append glyph string S to the list with head *HEAD and tail *TAIL. | |
2814 | Set *HEAD and *TAIL to the resulting list. */ | |
2815 | ||
2816 | static INLINE void | |
2817 | x_append_glyph_string (head, tail, s) | |
2818 | struct glyph_string **head, **tail; | |
2819 | struct glyph_string *s; | |
2820 | { | |
2821 | s->next = s->prev = NULL; | |
2822 | x_append_glyph_string_lists (head, tail, s, s); | |
2823 | } | |
2824 | ||
2825 | ||
2826 | /* Set S->gc to a suitable GC for drawing glyph string S in cursor | |
2827 | face. */ | |
2828 | ||
2829 | static void | |
2830 | x_set_cursor_gc (s) | |
2831 | struct glyph_string *s; | |
2832 | { | |
2833 | if (s->font == FRAME_FONT (s->f) | |
2834 | && s->face->background == FRAME_BACKGROUND_PIXEL (s->f) | |
2835 | && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f) | |
2836 | && !s->cmp) | |
2837 | s->gc = s->f->output_data.w32->cursor_gc; | |
2838 | else | |
2839 | { | |
2840 | /* Cursor on non-default face: must merge. */ | |
2841 | XGCValues xgcv; | |
2842 | unsigned long mask; | |
2843 | ||
2844 | xgcv.background = s->f->output_data.w32->cursor_pixel; | |
2845 | xgcv.foreground = s->face->background; | |
2846 | ||
2847 | /* If the glyph would be invisible, try a different foreground. */ | |
2848 | if (xgcv.foreground == xgcv.background) | |
2849 | xgcv.foreground = s->face->foreground; | |
2850 | if (xgcv.foreground == xgcv.background) | |
2851 | xgcv.foreground = s->f->output_data.w32->cursor_foreground_pixel; | |
2852 | if (xgcv.foreground == xgcv.background) | |
2853 | xgcv.foreground = s->face->foreground; | |
2854 | ||
2855 | /* Make sure the cursor is distinct from text in this face. */ | |
2856 | if (xgcv.background == s->face->background | |
2857 | && xgcv.foreground == s->face->foreground) | |
2858 | { | |
2859 | xgcv.background = s->face->foreground; | |
2860 | xgcv.foreground = s->face->background; | |
2861 | } | |
2862 | ||
2863 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2864 | xgcv.font = s->font; | |
2865 | mask = GCForeground | GCBackground | GCFont; | |
2866 | ||
2867 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2868 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2869 | mask, &xgcv); | |
2870 | else | |
2871 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2872 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
2873 | ||
2874 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2875 | } | |
2876 | } | |
2877 | ||
2878 | ||
2879 | /* Set up S->gc of glyph string S for drawing text in mouse face. */ | |
2880 | ||
2881 | static void | |
2882 | x_set_mouse_face_gc (s) | |
2883 | struct glyph_string *s; | |
2884 | { | |
2885 | int face_id; | |
93ff4395 | 2886 | struct face *face; |
791f420f JR |
2887 | |
2888 | /* What face has to be used for the mouse face? */ | |
2889 | face_id = FRAME_W32_DISPLAY_INFO (s->f)->mouse_face_face_id; | |
93ff4395 JR |
2890 | face = FACE_FROM_ID (s->f, face_id); |
2891 | face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch); | |
791f420f JR |
2892 | s->face = FACE_FROM_ID (s->f, face_id); |
2893 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); | |
2894 | ||
2895 | /* If font in this face is same as S->font, use it. */ | |
2896 | if (s->font == s->face->font) | |
2897 | s->gc = s->face->gc; | |
2898 | else | |
2899 | { | |
2900 | /* Otherwise construct scratch_cursor_gc with values from FACE | |
2901 | but font FONT. */ | |
2902 | XGCValues xgcv; | |
2903 | unsigned long mask; | |
2904 | ||
2905 | xgcv.background = s->face->background; | |
2906 | xgcv.foreground = s->face->foreground; | |
2907 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2908 | xgcv.font = s->font; | |
2909 | mask = GCForeground | GCBackground | GCFont; | |
2910 | ||
2911 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2912 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2913 | mask, &xgcv); | |
2914 | else | |
2915 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2916 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
2917 | ||
2918 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2919 | } | |
2920 | ||
2921 | xassert (s->gc != 0); | |
2922 | } | |
2923 | ||
2924 | ||
2925 | /* Set S->gc of glyph string S to a GC suitable for drawing a mode line. | |
2926 | Faces to use in the mode line have already been computed when the | |
2927 | matrix was built, so there isn't much to do, here. */ | |
2928 | ||
2929 | static INLINE void | |
2930 | x_set_mode_line_face_gc (s) | |
2931 | struct glyph_string *s; | |
2932 | { | |
2933 | s->gc = s->face->gc; | |
791f420f JR |
2934 | } |
2935 | ||
2936 | ||
2937 | /* Set S->gc of glyph string S for drawing that glyph string. Set | |
2938 | S->stippled_p to a non-zero value if the face of S has a stipple | |
2939 | pattern. */ | |
2940 | ||
2941 | static INLINE void | |
2942 | x_set_glyph_string_gc (s) | |
2943 | struct glyph_string *s; | |
2944 | { | |
ec48c3a7 JR |
2945 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); |
2946 | ||
791f420f JR |
2947 | if (s->hl == DRAW_NORMAL_TEXT) |
2948 | { | |
2949 | s->gc = s->face->gc; | |
2950 | s->stippled_p = s->face->stipple != 0; | |
2951 | } | |
2952 | else if (s->hl == DRAW_INVERSE_VIDEO) | |
2953 | { | |
2954 | x_set_mode_line_face_gc (s); | |
2955 | s->stippled_p = s->face->stipple != 0; | |
2956 | } | |
2957 | else if (s->hl == DRAW_CURSOR) | |
2958 | { | |
2959 | x_set_cursor_gc (s); | |
2960 | s->stippled_p = 0; | |
2961 | } | |
2962 | else if (s->hl == DRAW_MOUSE_FACE) | |
2963 | { | |
2964 | x_set_mouse_face_gc (s); | |
2965 | s->stippled_p = s->face->stipple != 0; | |
2966 | } | |
2967 | else if (s->hl == DRAW_IMAGE_RAISED | |
2968 | || s->hl == DRAW_IMAGE_SUNKEN) | |
2969 | { | |
2970 | s->gc = s->face->gc; | |
2971 | s->stippled_p = s->face->stipple != 0; | |
2972 | } | |
2973 | else | |
2974 | { | |
2975 | s->gc = s->face->gc; | |
2976 | s->stippled_p = s->face->stipple != 0; | |
2977 | } | |
2978 | ||
2979 | /* GC must have been set. */ | |
2980 | xassert (s->gc != 0); | |
2981 | } | |
2982 | ||
2983 | ||
2984 | /* Return in *R the clipping rectangle for glyph string S. */ | |
2985 | ||
2986 | static void | |
2987 | w32_get_glyph_string_clip_rect (s, r) | |
2988 | struct glyph_string *s; | |
2989 | RECT *r; | |
2990 | { | |
2991 | int r_height, r_width; | |
2992 | ||
2993 | if (s->row->full_width_p) | |
2994 | { | |
2995 | /* Draw full-width. X coordinates are relative to S->w->left. */ | |
2996 | int canon_x = CANON_X_UNIT (s->f); | |
2997 | ||
2998 | r->left = WINDOW_LEFT_MARGIN (s->w) * canon_x; | |
2999 | r_width = XFASTINT (s->w->width) * canon_x; | |
3000 | ||
3001 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (s->f)) | |
3002 | { | |
3003 | int width = FRAME_SCROLL_BAR_WIDTH (s->f) * canon_x; | |
3004 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s->f)) | |
3005 | r->left -= width; | |
3006 | } | |
3007 | ||
3008 | r->left += FRAME_INTERNAL_BORDER_WIDTH (s->f); | |
3009 | ||
3010 | /* Unless displaying a mode or menu bar line, which are always | |
3011 | fully visible, clip to the visible part of the row. */ | |
3012 | if (s->w->pseudo_window_p) | |
3013 | r_height = s->row->visible_height; | |
3014 | else | |
3015 | r_height = s->height; | |
3016 | } | |
3017 | else | |
3018 | { | |
3019 | /* This is a text line that may be partially visible. */ | |
3020 | r->left = WINDOW_AREA_TO_FRAME_PIXEL_X (s->w, s->area, 0); | |
3021 | r_width = window_box_width (s->w, s->area); | |
3022 | r_height = s->row->visible_height; | |
3023 | } | |
3024 | ||
3025 | /* Don't use S->y for clipping because it doesn't take partially | |
3026 | visible lines into account. For example, it can be negative for | |
3027 | partially visible lines at the top of a window. */ | |
3028 | if (!s->row->full_width_p | |
3029 | && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s->w, s->row)) | |
3030 | r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); | |
3031 | else | |
3032 | r->top = max (0, s->row->y); | |
3033 | ||
3034 | /* If drawing a tool-bar window, draw it over the internal border | |
3035 | at the top of the window. */ | |
3036 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
3037 | r->top -= s->f->output_data.w32->internal_border_width; | |
3038 | ||
3039 | /* If S draws overlapping rows, it's sufficient to use the top and | |
3040 | bottom of the window for clipping because this glyph string | |
3041 | intentionally draws over other lines. */ | |
3042 | if (s->for_overlaps_p) | |
3043 | { | |
3044 | r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); | |
3045 | r_height = window_text_bottom_y (s->w) - r->top; | |
3046 | } | |
3047 | ||
3048 | r->top = WINDOW_TO_FRAME_PIXEL_Y (s->w, r->top); | |
3049 | ||
3050 | r->bottom = r->top + r_height; | |
3051 | r->right = r->left + r_width; | |
3052 | } | |
3053 | ||
3054 | ||
3055 | /* Set clipping for output of glyph string S. S may be part of a mode | |
3056 | line or menu if we don't have X toolkit support. */ | |
3057 | ||
3058 | static INLINE void | |
3059 | x_set_glyph_string_clipping (s) | |
3060 | struct glyph_string *s; | |
3061 | { | |
3062 | RECT r; | |
3063 | w32_get_glyph_string_clip_rect (s, &r); | |
3064 | w32_set_clip_rectangle (s->hdc, &r); | |
3065 | } | |
3066 | ||
3067 | ||
3068 | /* Compute left and right overhang of glyph string S. If S is a glyph | |
3069 | string for a composition, assume overhangs don't exist. */ | |
3070 | ||
3071 | static INLINE void | |
3072 | x_compute_glyph_string_overhangs (s) | |
3073 | struct glyph_string *s; | |
3074 | { | |
01b220b6 | 3075 | /* TODO: Windows does not appear to have a method for |
158cba56 JR |
3076 | getting this info without getting the ABC widths for each |
3077 | individual character and working it out manually. */ | |
791f420f JR |
3078 | } |
3079 | ||
3080 | ||
3081 | /* Compute overhangs and x-positions for glyph string S and its | |
3082 | predecessors, or successors. X is the starting x-position for S. | |
3083 | BACKWARD_P non-zero means process predecessors. */ | |
3084 | ||
3085 | static void | |
3086 | x_compute_overhangs_and_x (s, x, backward_p) | |
3087 | struct glyph_string *s; | |
3088 | int x; | |
3089 | int backward_p; | |
3090 | { | |
3091 | if (backward_p) | |
3092 | { | |
3093 | while (s) | |
3094 | { | |
3095 | x_compute_glyph_string_overhangs (s); | |
3096 | x -= s->width; | |
3097 | s->x = x; | |
3098 | s = s->prev; | |
3099 | } | |
3100 | } | |
3101 | else | |
3102 | { | |
3103 | while (s) | |
3104 | { | |
3105 | x_compute_glyph_string_overhangs (s); | |
3106 | s->x = x; | |
3107 | x += s->width; | |
3108 | s = s->next; | |
3109 | } | |
3110 | } | |
3111 | } | |
3112 | ||
3113 | ||
3114 | /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on | |
3115 | frame F. Overhangs of glyphs other than type CHAR_GLYPH are | |
3116 | assumed to be zero. */ | |
3117 | ||
3118 | static void | |
9ef2e2cf | 3119 | w32_get_glyph_overhangs (hdc, glyph, f, left, right) |
00fe468b | 3120 | HDC hdc; |
791f420f JR |
3121 | struct glyph *glyph; |
3122 | struct frame *f; | |
9ef2e2cf | 3123 | int *left, *right; |
791f420f JR |
3124 | { |
3125 | int c; | |
791f420f JR |
3126 | |
3127 | *left = *right = 0; | |
3128 | ||
3129 | if (glyph->type == CHAR_GLYPH) | |
3130 | { | |
3131 | XFontStruct *font; | |
3132 | struct face *face; | |
791f420f | 3133 | wchar_t char2b; |
93ff4395 JR |
3134 | XCharStruct *pcm; |
3135 | ||
3136 | face = x_get_glyph_face_and_encoding (f, glyph, &char2b, NULL); | |
791f420f | 3137 | font = face->font; |
9ef2e2cf | 3138 | |
93ff4395 | 3139 | if (font |
82f9d565 | 3140 | && (pcm = w32_per_char_metric (font, &char2b, |
9ef2e2cf | 3141 | glyph->w32_font_type))) |
791f420f | 3142 | { |
791f420f JR |
3143 | if (pcm->rbearing > pcm->width) |
3144 | *right = pcm->rbearing - pcm->width; | |
3145 | if (pcm->lbearing < 0) | |
3146 | *left = -pcm->lbearing; | |
3147 | } | |
3148 | } | |
791f420f JR |
3149 | } |
3150 | ||
3151 | ||
3152 | static void | |
3153 | x_get_glyph_overhangs (glyph, f, left, right) | |
3154 | struct glyph *glyph; | |
3155 | struct frame *f; | |
3156 | int *left, *right; | |
3157 | { | |
3158 | HDC hdc = get_frame_dc (f); | |
9ef2e2cf JR |
3159 | /* Convert to unicode! */ |
3160 | w32_get_glyph_overhangs (hdc, glyph, f, left, right); | |
791f420f JR |
3161 | release_frame_dc (f, hdc); |
3162 | } | |
3163 | ||
3164 | ||
3165 | /* Return the index of the first glyph preceding glyph string S that | |
3166 | is overwritten by S because of S's left overhang. Value is -1 | |
3167 | if no glyphs are overwritten. */ | |
3168 | ||
3169 | static int | |
3170 | x_left_overwritten (s) | |
3171 | struct glyph_string *s; | |
3172 | { | |
3173 | int k; | |
3174 | ||
3175 | if (s->left_overhang) | |
3176 | { | |
3177 | int x = 0, i; | |
3178 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3179 | int first = s->first_glyph - glyphs; | |
3180 | ||
3181 | for (i = first - 1; i >= 0 && x > -s->left_overhang; --i) | |
3182 | x -= glyphs[i].pixel_width; | |
3183 | ||
3184 | k = i + 1; | |
3185 | } | |
3186 | else | |
3187 | k = -1; | |
3188 | ||
3189 | return k; | |
3190 | } | |
3191 | ||
3192 | ||
3193 | /* Return the index of the first glyph preceding glyph string S that | |
3194 | is overwriting S because of its right overhang. Value is -1 if no | |
3195 | glyph in front of S overwrites S. */ | |
3196 | ||
3197 | static int | |
3198 | x_left_overwriting (s) | |
3199 | struct glyph_string *s; | |
3200 | { | |
3201 | int i, k, x; | |
3202 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3203 | int first = s->first_glyph - glyphs; | |
3204 | ||
3205 | k = -1; | |
3206 | x = 0; | |
3207 | for (i = first - 1; i >= 0; --i) | |
3208 | { | |
3209 | int left, right; | |
9ef2e2cf | 3210 | w32_get_glyph_overhangs (s->hdc, glyphs + i, s->f, &left, &right); |
791f420f JR |
3211 | if (x + right > 0) |
3212 | k = i; | |
3213 | x -= glyphs[i].pixel_width; | |
3214 | } | |
3215 | ||
3216 | return k; | |
3217 | } | |
3218 | ||
3219 | ||
3220 | /* Return the index of the last glyph following glyph string S that is | |
3221 | not overwritten by S because of S's right overhang. Value is -1 if | |
3222 | no such glyph is found. */ | |
3223 | ||
3224 | static int | |
3225 | x_right_overwritten (s) | |
3226 | struct glyph_string *s; | |
3227 | { | |
3228 | int k = -1; | |
3229 | ||
3230 | if (s->right_overhang) | |
3231 | { | |
3232 | int x = 0, i; | |
3233 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3234 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); | |
3235 | int end = s->row->used[s->area]; | |
3236 | ||
3237 | for (i = first; i < end && s->right_overhang > x; ++i) | |
3238 | x += glyphs[i].pixel_width; | |
3239 | ||
3240 | k = i; | |
3241 | } | |
3242 | ||
3243 | return k; | |
3244 | } | |
3245 | ||
3246 | ||
3247 | /* Return the index of the last glyph following glyph string S that | |
3248 | overwrites S because of its left overhang. Value is negative | |
3249 | if no such glyph is found. */ | |
3250 | ||
3251 | static int | |
3252 | x_right_overwriting (s) | |
3253 | struct glyph_string *s; | |
3254 | { | |
3255 | int i, k, x; | |
3256 | int end = s->row->used[s->area]; | |
3257 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3258 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); | |
3259 | ||
3260 | k = -1; | |
3261 | x = 0; | |
3262 | for (i = first; i < end; ++i) | |
3263 | { | |
3264 | int left, right; | |
9ef2e2cf | 3265 | w32_get_glyph_overhangs (s->hdc, glyphs + i, s->f, &left, &right); |
791f420f JR |
3266 | if (x - left < 0) |
3267 | k = i; | |
3268 | x += glyphs[i].pixel_width; | |
3269 | } | |
3270 | ||
3271 | return k; | |
3272 | } | |
3273 | ||
3274 | ||
3275 | /* Fill rectangle X, Y, W, H with background color of glyph string S. */ | |
3276 | ||
3277 | static INLINE void | |
3278 | x_clear_glyph_string_rect (s, x, y, w, h) | |
3279 | struct glyph_string *s; | |
3280 | int x, y, w, h; | |
3281 | { | |
3282 | int real_x = x; | |
3283 | int real_y = y; | |
3284 | int real_w = w; | |
3285 | int real_h = h; | |
3286 | #if 0 | |
3287 | /* Take clipping into account. */ | |
3288 | if (s->gc->clip_mask == Rect) | |
3289 | { | |
3290 | real_x = max (real_x, s->gc->clip_rectangle.left); | |
3291 | real_y = max (real_y, s->gc->clip_rectangle.top); | |
3292 | real_w = min (real_w, s->gc->clip_rectangle.right | |
3293 | - s->gc->clip_rectangle.left); | |
3294 | real_h = min (real_h, s->gc->clip_rectangle.bottom | |
3295 | - s->gc->clip_rectangle.top); | |
3296 | } | |
3297 | #endif | |
3298 | w32_fill_area (s->f, s->hdc, s->gc->background, real_x, real_y, | |
3299 | real_w, real_h); | |
3300 | } | |
3301 | ||
3302 | ||
3303 | /* Draw the background of glyph_string S. If S->background_filled_p | |
3304 | is non-zero don't draw it. FORCE_P non-zero means draw the | |
3305 | background even if it wouldn't be drawn normally. This is used | |
3306 | when a string preceding S draws into the background of S, or S | |
3307 | contains the first component of a composition. */ | |
3308 | ||
3309 | static void | |
3310 | x_draw_glyph_string_background (s, force_p) | |
3311 | struct glyph_string *s; | |
3312 | int force_p; | |
3313 | { | |
3314 | /* Nothing to do if background has already been drawn or if it | |
3315 | shouldn't be drawn in the first place. */ | |
3316 | if (!s->background_filled_p) | |
3317 | { | |
01b220b6 | 3318 | #if 0 /* TODO: stipple */ |
791f420f JR |
3319 | if (s->stippled_p) |
3320 | { | |
3321 | /* Fill background with a stipple pattern. */ | |
3322 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
3323 | XFillRectangle (s->display, s->window, s->gc, s->x, | |
3324 | s->y + s->face->box_line_width, | |
3325 | s->background_width, | |
3326 | s->height - 2 * s->face->box_line_width); | |
3327 | XSetFillStyle (s->display, s->gc, FillSolid); | |
3328 | s->background_filled_p = 1; | |
3329 | } | |
3330 | else | |
3331 | #endif | |
3332 | if (FONT_HEIGHT (s->font) < s->height - 2 * s->face->box_line_width | |
3333 | || s->font_not_found_p | |
3334 | || s->extends_to_end_of_line_p | |
9127e20e | 3335 | || s->font->bdf |
791f420f JR |
3336 | || force_p) |
3337 | { | |
3338 | x_clear_glyph_string_rect (s, s->x, s->y + s->face->box_line_width, | |
3339 | s->background_width, | |
3340 | s->height - 2 * s->face->box_line_width); | |
3341 | s->background_filled_p = 1; | |
3342 | } | |
3343 | } | |
3344 | } | |
3345 | ||
3346 | ||
3347 | /* Draw the foreground of glyph string S. */ | |
3348 | ||
3349 | static void | |
3350 | x_draw_glyph_string_foreground (s) | |
3351 | struct glyph_string *s; | |
3352 | { | |
3353 | int i, x; | |
01b220b6 | 3354 | HFONT old_font; |
791f420f JR |
3355 | |
3356 | /* If first glyph of S has a left box line, start drawing the text | |
3357 | of S to the right of that box line. */ | |
3358 | if (s->face->box != FACE_NO_BOX | |
3359 | && s->first_glyph->left_box_line_p) | |
3360 | x = s->x + s->face->box_line_width; | |
3361 | else | |
3362 | x = s->x; | |
3363 | ||
3364 | if (s->for_overlaps_p || (s->background_filled_p && s->hl != DRAW_CURSOR)) | |
3365 | SetBkMode (s->hdc, TRANSPARENT); | |
3366 | else | |
3367 | SetBkMode (s->hdc, OPAQUE); | |
3368 | ||
3369 | SetTextColor (s->hdc, s->gc->foreground); | |
3370 | SetBkColor (s->hdc, s->gc->background); | |
3371 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | |
3372 | ||
3373 | if (s->font && s->font->hfont) | |
01b220b6 | 3374 | old_font = SelectObject (s->hdc, s->font->hfont); |
791f420f JR |
3375 | |
3376 | /* Draw characters of S as rectangles if S's font could not be | |
3377 | loaded. */ | |
3378 | if (s->font_not_found_p) | |
3379 | { | |
3380 | for (i = 0; i < s->nchars; ++i) | |
3381 | { | |
3382 | struct glyph *g = s->first_glyph + i; | |
3383 | ||
3384 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, g->pixel_width - 1, | |
3385 | s->height - 1); | |
3386 | x += g->pixel_width; | |
3387 | } | |
3388 | } | |
3389 | else | |
3390 | { | |
3391 | char *char1b = (char *) s->char2b; | |
3392 | int boff = s->font_info->baseline_offset; | |
3393 | ||
3394 | if (s->font_info->vertical_centering) | |
3395 | boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; | |
3396 | ||
3397 | /* If we can use 8-bit functions, condense S->char2b. */ | |
3398 | if (!s->two_byte_p) | |
3399 | for (i = 0; i < s->nchars; ++i) | |
3400 | char1b[i] = BYTE2 (s->char2b[i]); | |
3401 | ||
3402 | /* Draw text with TextOut and friends. */ | |
3403 | W32_TEXTOUT (s, x, s->ybase - boff, s->char2b, s->nchars); | |
3404 | } | |
01b220b6 JR |
3405 | if (s->font && s->font->hfont) |
3406 | SelectObject (s->hdc, old_font); | |
791f420f JR |
3407 | } |
3408 | ||
3409 | /* Draw the foreground of composite glyph string S. */ | |
3410 | ||
3411 | static void | |
3412 | x_draw_composite_glyph_string_foreground (s) | |
3413 | struct glyph_string *s; | |
3414 | { | |
3415 | int i, x; | |
01b220b6 | 3416 | HFONT old_font; |
791f420f JR |
3417 | |
3418 | /* If first glyph of S has a left box line, start drawing the text | |
3419 | of S to the right of that box line. */ | |
3420 | if (s->face->box != FACE_NO_BOX | |
3421 | && s->first_glyph->left_box_line_p) | |
3422 | x = s->x + s->face->box_line_width; | |
3423 | else | |
3424 | x = s->x; | |
3425 | ||
3426 | /* S is a glyph string for a composition. S->gidx is the index of | |
3427 | the first character drawn for glyphs of this composition. | |
3428 | S->gidx == 0 means we are drawing the very first character of | |
3429 | this composition. */ | |
3430 | ||
3431 | SetTextColor (s->hdc, s->gc->foreground); | |
3432 | SetBkColor (s->hdc, s->gc->background); | |
3433 | SetBkMode (s->hdc, TRANSPARENT); | |
3434 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | |
3435 | ||
01b220b6 JR |
3436 | if (s->font && s->font->hfont) |
3437 | old_font = SelectObject (s->hdc, s->font->hfont); | |
3438 | ||
791f420f JR |
3439 | /* Draw a rectangle for the composition if the font for the very |
3440 | first character of the composition could not be loaded. */ | |
3441 | if (s->font_not_found_p) | |
3442 | { | |
3443 | if (s->gidx == 0) | |
3444 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1, | |
3445 | s->height - 1); | |
3446 | } | |
3447 | else | |
3448 | { | |
3449 | for (i = 0; i < s->nchars; i++, ++s->gidx) | |
01b220b6 JR |
3450 | W32_TEXTOUT (s, x + s->cmp->offsets[s->gidx * 2], |
3451 | s->ybase - s->cmp->offsets[s->gidx * 2 + 1], | |
3452 | s->char2b + i, 1); | |
791f420f | 3453 | } |
01b220b6 JR |
3454 | if (s->font && s->font->hfont) |
3455 | SelectObject (s->hdc, old_font); | |
791f420f JR |
3456 | } |
3457 | ||
e5fa381b JR |
3458 | |
3459 | /* Brightness beyond which a color won't have its highlight brightness | |
3460 | boosted. | |
3461 | ||
3462 | Nominally, highlight colors for `3d' faces are calculated by | |
3463 | brightening an object's color by a constant scale factor, but this | |
3464 | doesn't yield good results for dark colors, so for colors who's | |
3465 | brightness is less than this value (on a scale of 0-255) have to | |
3466 | use an additional additive factor. | |
3467 | ||
3468 | The value here is set so that the default menu-bar/mode-line color | |
3469 | (grey75) will not have its highlights changed at all. */ | |
3470 | #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187 | |
3471 | ||
3472 | ||
791f420f JR |
3473 | /* Allocate a color which is lighter or darker than *COLOR by FACTOR |
3474 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
3475 | If this produces the same color as COLOR, try a color where all RGB | |
3476 | values have DELTA added. Return the allocated color in *COLOR. | |
3477 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
3478 | Value is non-zero if successful. */ | |
3479 | ||
3480 | static int | |
3481 | w32_alloc_lighter_color (f, color, factor, delta) | |
3482 | struct frame *f; | |
3483 | COLORREF *color; | |
3484 | double factor; | |
3485 | int delta; | |
3486 | { | |
3487 | COLORREF new; | |
e5fa381b JR |
3488 | long bright; |
3489 | ||
3490 | /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */ | |
3491 | delta /= 256; | |
791f420f JR |
3492 | |
3493 | /* Change RGB values by specified FACTOR. Avoid overflow! */ | |
3494 | xassert (factor >= 0); | |
3495 | new = PALETTERGB (min (0xff, factor * GetRValue (*color)), | |
3496 | min (0xff, factor * GetGValue (*color)), | |
3497 | min (0xff, factor * GetBValue (*color))); | |
e5fa381b JR |
3498 | |
3499 | /* Calculate brightness of COLOR. */ | |
3500 | bright = (2 * GetRValue (*color) + 3 * GetGValue (*color) | |
3501 | + GetBValue (*color)) / 6; | |
3502 | ||
3503 | /* We only boost colors that are darker than | |
3504 | HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */ | |
3505 | if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT) | |
3506 | /* Make an additive adjustment to NEW, because it's dark enough so | |
3507 | that scaling by FACTOR alone isn't enough. */ | |
3508 | { | |
3509 | /* How far below the limit this color is (0 - 1, 1 being darker). */ | |
3510 | double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT; | |
3511 | /* The additive adjustment. */ | |
3512 | int min_delta = delta * dimness * factor / 2; | |
3513 | ||
3514 | if (factor < 1) | |
3515 | new = PALETTERGB (max (0, min (0xff, min_delta - GetRValue (*color))), | |
3516 | max (0, min (0xff, min_delta - GetGValue (*color))), | |
3517 | max (0, min (0xff, min_delta - GetBValue (*color)))); | |
3518 | else | |
3519 | new = PALETTERGB (max (0, min (0xff, min_delta + GetRValue (*color))), | |
3520 | max (0, min (0xff, min_delta + GetGValue (*color))), | |
3521 | max (0, min (0xff, min_delta + GetBValue (*color)))); | |
3522 | } | |
3523 | ||
791f420f JR |
3524 | if (new == *color) |
3525 | new = PALETTERGB (max (0, min (0xff, delta + GetRValue (*color))), | |
3526 | max (0, min (0xff, delta + GetGValue (*color))), | |
3527 | max (0, min (0xff, delta + GetBValue (*color)))); | |
3528 | ||
01b220b6 JR |
3529 | /* TODO: Map to palette and retry with delta if same? */ |
3530 | /* TODO: Free colors (if using palette)? */ | |
93ff4395 | 3531 | |
791f420f JR |
3532 | if (new == *color) |
3533 | return 0; | |
3534 | ||
3535 | *color = new; | |
3536 | ||
3537 | return 1; | |
3538 | } | |
3539 | ||
3540 | ||
3541 | /* Set up the foreground color for drawing relief lines of glyph | |
3542 | string S. RELIEF is a pointer to a struct relief containing the GC | |
3543 | with which lines will be drawn. Use a color that is FACTOR or | |
3544 | DELTA lighter or darker than the relief's background which is found | |
3545 | in S->f->output_data.x->relief_background. If such a color cannot | |
3546 | be allocated, use DEFAULT_PIXEL, instead. */ | |
3547 | ||
3548 | static void | |
3549 | w32_setup_relief_color (f, relief, factor, delta, default_pixel) | |
3550 | struct frame *f; | |
3551 | struct relief *relief; | |
3552 | double factor; | |
3553 | int delta; | |
3554 | COLORREF default_pixel; | |
3555 | { | |
3556 | XGCValues xgcv; | |
3557 | struct w32_output *di = f->output_data.w32; | |
3558 | unsigned long mask = GCForeground; | |
3559 | COLORREF pixel; | |
3560 | COLORREF background = di->relief_background; | |
3561 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
3562 | ||
01b220b6 | 3563 | /* TODO: Free colors (if using palette)? */ |
93ff4395 | 3564 | |
791f420f JR |
3565 | /* Allocate new color. */ |
3566 | xgcv.foreground = default_pixel; | |
3567 | pixel = background; | |
3568 | if (w32_alloc_lighter_color (f, &pixel, factor, delta)) | |
3569 | { | |
3570 | relief->allocated_p = 1; | |
3571 | xgcv.foreground = relief->pixel = pixel; | |
3572 | } | |
3573 | ||
3574 | if (relief->gc == 0) | |
3575 | { | |
01b220b6 | 3576 | #if 0 /* TODO: stipple */ |
791f420f JR |
3577 | xgcv.stipple = dpyinfo->gray; |
3578 | mask |= GCStipple; | |
3579 | #endif | |
3580 | relief->gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &xgcv); | |
3581 | } | |
3582 | else | |
3583 | XChangeGC (NULL, relief->gc, mask, &xgcv); | |
3584 | } | |
3585 | ||
3586 | ||
3587 | /* Set up colors for the relief lines around glyph string S. */ | |
3588 | ||
3589 | static void | |
3590 | x_setup_relief_colors (s) | |
3591 | struct glyph_string *s; | |
3592 | { | |
3593 | struct w32_output *di = s->f->output_data.w32; | |
3594 | COLORREF color; | |
3595 | ||
3596 | if (s->face->use_box_color_for_shadows_p) | |
3597 | color = s->face->box_color; | |
3598 | else | |
3599 | color = s->gc->background; | |
3600 | ||
3601 | if (di->white_relief.gc == 0 | |
3602 | || color != di->relief_background) | |
3603 | { | |
3604 | di->relief_background = color; | |
3605 | w32_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000, | |
3606 | WHITE_PIX_DEFAULT (s->f)); | |
3607 | w32_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000, | |
3608 | BLACK_PIX_DEFAULT (s->f)); | |
3609 | } | |
3610 | } | |
3611 | ||
3612 | ||
3613 | /* Draw a relief on frame F inside the rectangle given by LEFT_X, | |
3614 | TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief | |
3615 | to draw, it must be >= 0. RAISED_P non-zero means draw a raised | |
3616 | relief. LEFT_P non-zero means draw a relief on the left side of | |
3617 | the rectangle. RIGHT_P non-zero means draw a relief on the right | |
3618 | side of the rectangle. CLIP_RECT is the clipping rectangle to use | |
3619 | when drawing. */ | |
3620 | ||
3621 | static void | |
3622 | w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, | |
3623 | raised_p, left_p, right_p, clip_rect) | |
3624 | struct frame *f; | |
3625 | int left_x, top_y, right_x, bottom_y, left_p, right_p, raised_p; | |
3626 | RECT *clip_rect; | |
3627 | { | |
3628 | int i; | |
3629 | XGCValues gc; | |
3630 | HDC hdc = get_frame_dc (f); | |
3631 | ||
3632 | if (raised_p) | |
e5fa381b | 3633 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
791f420f | 3634 | else |
e5fa381b | 3635 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f JR |
3636 | |
3637 | w32_set_clip_rectangle (hdc, clip_rect); | |
3638 | ||
3639 | /* Top. */ | |
3640 | for (i = 0; i < width; ++i) | |
3641 | { | |
3642 | w32_fill_area (f, hdc, gc.foreground, | |
3643 | left_x + i * left_p, top_y + i, | |
3644 | (right_x + 1 - i * right_p) - (left_x + i * left_p), 1); | |
3645 | } | |
3646 | ||
3647 | /* Left. */ | |
3648 | if (left_p) | |
3649 | for (i = 0; i < width; ++i) | |
3650 | { | |
3651 | w32_fill_area (f, hdc, gc.foreground, | |
3652 | left_x + i, top_y + i, 1, | |
3653 | (bottom_y - i) - (top_y + i)); | |
3654 | } | |
3655 | ||
3656 | w32_set_clip_rectangle (hdc, NULL); | |
3657 | ||
3658 | if (raised_p) | |
e5fa381b | 3659 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f | 3660 | else |
e5fa381b JR |
3661 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
3662 | ||
791f420f JR |
3663 | |
3664 | w32_set_clip_rectangle (hdc, clip_rect); | |
3665 | ||
3666 | /* Bottom. */ | |
3667 | for (i = 0; i < width; ++i) | |
3668 | { | |
3669 | w32_fill_area (f, hdc, gc.foreground, | |
3670 | left_x + i * left_p, bottom_y - i, | |
3671 | (right_x + 1 - i * right_p) - left_x + i * left_p, 1); | |
3672 | } | |
3673 | ||
3674 | /* Right. */ | |
3675 | if (right_p) | |
3676 | for (i = 0; i < width; ++i) | |
3677 | { | |
3678 | w32_fill_area (f, hdc, gc.foreground, | |
3679 | right_x - i, top_y + i + 1, 1, | |
3680 | (bottom_y - i) - (top_y + i + 1)); | |
3681 | } | |
3682 | ||
3683 | w32_set_clip_rectangle (hdc, NULL); | |
3684 | ||
3685 | release_frame_dc (f, hdc); | |
3686 | } | |
3687 | ||
3688 | ||
3689 | /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y, | |
3690 | RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to | |
3691 | draw, it must be >= 0. LEFT_P non-zero means draw a line on the | |
3692 | left side of the rectangle. RIGHT_P non-zero means draw a line | |
3693 | on the right side of the rectangle. CLIP_RECT is the clipping | |
3694 | rectangle to use when drawing. */ | |
3695 | ||
3696 | static void | |
3697 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3698 | left_p, right_p, clip_rect) | |
3699 | struct glyph_string *s; | |
3700 | int left_x, top_y, right_x, bottom_y, width, left_p, right_p; | |
3701 | RECT *clip_rect; | |
3702 | { | |
00fe468b | 3703 | w32_set_clip_rectangle (s->hdc, clip_rect); |
791f420f JR |
3704 | |
3705 | /* Top. */ | |
00fe468b | 3706 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3707 | left_x, top_y, right_x - left_x + 1, width); |
791f420f JR |
3708 | |
3709 | /* Left. */ | |
3710 | if (left_p) | |
3711 | { | |
00fe468b | 3712 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3713 | left_x, top_y, width, bottom_y - top_y + 1); |
791f420f JR |
3714 | } |
3715 | ||
3716 | /* Bottom. */ | |
00fe468b | 3717 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3718 | left_x, bottom_y - width + 1, right_x - left_x + 1, width); |
791f420f JR |
3719 | |
3720 | /* Right. */ | |
3721 | if (right_p) | |
3722 | { | |
00fe468b | 3723 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3724 | right_x - width + 1, top_y, width, bottom_y - top_y + 1); |
791f420f JR |
3725 | } |
3726 | ||
00fe468b | 3727 | w32_set_clip_rectangle (s->hdc, NULL); |
791f420f JR |
3728 | } |
3729 | ||
3730 | ||
3731 | /* Draw a box around glyph string S. */ | |
3732 | ||
3733 | static void | |
3734 | x_draw_glyph_string_box (s) | |
3735 | struct glyph_string *s; | |
3736 | { | |
3737 | int width, left_x, right_x, top_y, bottom_y, last_x, raised_p; | |
3738 | int left_p, right_p; | |
3739 | struct glyph *last_glyph; | |
3740 | RECT clip_rect; | |
3741 | ||
3742 | last_x = window_box_right (s->w, s->area); | |
3743 | if (s->row->full_width_p | |
3744 | && !s->w->pseudo_window_p) | |
3745 | { | |
3746 | last_x += FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s->f); | |
3747 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s->f)) | |
3748 | last_x += FRAME_SCROLL_BAR_WIDTH (s->f) * CANON_X_UNIT (s->f); | |
3749 | } | |
3750 | ||
3751 | /* The glyph that may have a right box line. */ | |
3752 | last_glyph = (s->cmp || s->img | |
3753 | ? s->first_glyph | |
3754 | : s->first_glyph + s->nchars - 1); | |
3755 | ||
3756 | width = s->face->box_line_width; | |
3757 | raised_p = s->face->box == FACE_RAISED_BOX; | |
3758 | left_x = s->x; | |
3759 | right_x = ((s->row->full_width_p | |
3760 | ? last_x - 1 | |
3761 | : min (last_x, s->x + s->background_width) - 1)); | |
3762 | top_y = s->y; | |
3763 | bottom_y = top_y + s->height - 1; | |
3764 | ||
3765 | left_p = (s->first_glyph->left_box_line_p | |
3766 | || (s->hl == DRAW_MOUSE_FACE | |
3767 | && (s->prev == NULL | |
3768 | || s->prev->hl != s->hl))); | |
3769 | right_p = (last_glyph->right_box_line_p | |
3770 | || (s->hl == DRAW_MOUSE_FACE | |
3771 | && (s->next == NULL | |
3772 | || s->next->hl != s->hl))); | |
3773 | ||
3774 | w32_get_glyph_string_clip_rect (s, &clip_rect); | |
3775 | ||
3776 | if (s->face->box == FACE_SIMPLE_BOX) | |
3777 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3778 | left_p, right_p, &clip_rect); | |
3779 | else | |
3780 | { | |
3781 | x_setup_relief_colors (s); | |
3782 | w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, | |
3783 | width, raised_p, left_p, right_p, &clip_rect); | |
3784 | } | |
3785 | } | |
3786 | ||
3787 | ||
3788 | /* Draw foreground of image glyph string S. */ | |
3789 | ||
3790 | static void | |
3791 | x_draw_image_foreground (s) | |
3792 | struct glyph_string *s; | |
3793 | { | |
3794 | int x; | |
9ef2e2cf | 3795 | int y = s->ybase - image_ascent (s->img, s->face); |
791f420f JR |
3796 | |
3797 | /* If first glyph of S has a left box line, start drawing it to the | |
3798 | right of that line. */ | |
3799 | if (s->face->box != FACE_NO_BOX | |
3800 | && s->first_glyph->left_box_line_p) | |
3801 | x = s->x + s->face->box_line_width; | |
3802 | else | |
3803 | x = s->x; | |
3804 | ||
3805 | /* If there is a margin around the image, adjust x- and y-position | |
3806 | by that margin. */ | |
3807 | if (s->img->margin) | |
3808 | { | |
3809 | x += s->img->margin; | |
3810 | y += s->img->margin; | |
3811 | } | |
3812 | ||
3813 | SaveDC (s->hdc); | |
3814 | ||
3815 | if (s->img->pixmap) | |
3816 | { | |
01b220b6 | 3817 | #if 0 /* TODO: image mask */ |
791f420f JR |
3818 | if (s->img->mask) |
3819 | { | |
3820 | /* We can't set both a clip mask and use XSetClipRectangles | |
3821 | because the latter also sets a clip mask. We also can't | |
3822 | trust on the shape extension to be available | |
3823 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3824 | manually. */ | |
3825 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3826 | | GCFunction); | |
3827 | XGCValues xgcv; | |
3828 | XRectangle clip_rect, image_rect, r; | |
3829 | ||
3830 | xgcv.clip_mask = s->img->mask; | |
3831 | xgcv.clip_x_origin = x; | |
3832 | xgcv.clip_y_origin = y; | |
3833 | xgcv.function = GXcopy; | |
3834 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3835 | ||
3836 | w32_get_glyph_string_clip_rect (s, &clip_rect); | |
3837 | image_rect.x = x; | |
3838 | image_rect.y = y; | |
3839 | image_rect.width = s->img->width; | |
3840 | image_rect.height = s->img->height; | |
158cba56 | 3841 | if (IntersectRect (&r, &clip_rect, &image_rect)) |
791f420f JR |
3842 | XCopyArea (s->display, s->img->pixmap, s->window, s->gc, |
3843 | r.x - x, r.y - y, r.width, r.height, r.x, r.y); | |
3844 | } | |
3845 | else | |
3846 | #endif | |
3847 | { | |
3848 | HDC compat_hdc = CreateCompatibleDC (s->hdc); | |
3849 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
3850 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
3851 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
158cba56 | 3852 | x_set_glyph_string_clipping (s); |
791f420f JR |
3853 | |
3854 | SetTextColor (s->hdc, s->gc->foreground); | |
3855 | SetBkColor (s->hdc, s->gc->background); | |
3856 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
3857 | BitBlt (s->hdc, x, y, s->img->width, s->img->height, | |
3858 | compat_hdc, 0, 0, SRCCOPY); | |
3859 | #else | |
3860 | BitBlt (s->hdc, x, y, s->img->width, s->img->height, | |
3861 | compat_hdc, 0, 0, 0xB8074A); | |
3862 | #endif | |
3863 | SelectObject (s->hdc, orig_brush); | |
3864 | DeleteObject (fg_brush); | |
3865 | SelectObject (compat_hdc, orig_obj); | |
3866 | DeleteDC (compat_hdc); | |
3867 | ||
3868 | /* When the image has a mask, we can expect that at | |
3869 | least part of a mouse highlight or a block cursor will | |
3870 | be visible. If the image doesn't have a mask, make | |
3871 | a block cursor visible by drawing a rectangle around | |
3872 | the image. I believe it's looking better if we do | |
3873 | nothing here for mouse-face. */ | |
3874 | if (s->hl == DRAW_CURSOR) | |
3875 | w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width - 1, | |
3876 | s->img->height - 1); | |
9127e20e | 3877 | w32_set_clip_rectangle (s->hdc, NULL); |
791f420f JR |
3878 | } |
3879 | } | |
3880 | else | |
3881 | w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width -1, | |
3882 | s->img->height - 1); | |
ee78dc32 | 3883 | |
791f420f JR |
3884 | RestoreDC (s->hdc ,-1); |
3885 | } | |
ee78dc32 | 3886 | |
791f420f JR |
3887 | |
3888 | ||
3889 | /* Draw a relief around the image glyph string S. */ | |
3890 | ||
3891 | static void | |
3892 | x_draw_image_relief (s) | |
3893 | struct glyph_string *s; | |
3894 | { | |
3895 | int x0, y0, x1, y1, thick, raised_p; | |
3896 | RECT r; | |
3897 | int x; | |
9ef2e2cf JR |
3898 | int y = s->ybase - image_ascent (s->img, s->face); |
3899 | ||
791f420f JR |
3900 | /* If first glyph of S has a left box line, start drawing it to the |
3901 | right of that line. */ | |
3902 | if (s->face->box != FACE_NO_BOX | |
3903 | && s->first_glyph->left_box_line_p) | |
3904 | x = s->x + s->face->box_line_width; | |
3905 | else | |
3906 | x = s->x; | |
3907 | ||
3908 | /* If there is a margin around the image, adjust x- and y-position | |
3909 | by that margin. */ | |
3910 | if (s->img->margin) | |
3911 | { | |
3912 | x += s->img->margin; | |
3913 | y += s->img->margin; | |
3914 | } | |
3915 | ||
3916 | if (s->hl == DRAW_IMAGE_SUNKEN | |
3917 | || s->hl == DRAW_IMAGE_RAISED) | |
3918 | { | |
3919 | thick = tool_bar_button_relief > 0 ? tool_bar_button_relief : 3; | |
3920 | raised_p = s->hl == DRAW_IMAGE_RAISED; | |
3921 | } | |
3922 | else | |
ee78dc32 | 3923 | { |
791f420f JR |
3924 | thick = abs (s->img->relief); |
3925 | raised_p = s->img->relief > 0; | |
3926 | } | |
3927 | ||
3928 | x0 = x - thick; | |
3929 | y0 = y - thick; | |
3930 | x1 = x + s->img->width + thick - 1; | |
3931 | y1 = y + s->img->height + thick - 1; | |
3932 | ||
3933 | x_setup_relief_colors (s); | |
3934 | w32_get_glyph_string_clip_rect (s, &r); | |
3935 | w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); | |
3936 | } | |
ee78dc32 | 3937 | |
791f420f JR |
3938 | |
3939 | /* Draw the foreground of image glyph string S to PIXMAP. */ | |
3940 | ||
3941 | static void | |
3942 | w32_draw_image_foreground_1 (s, pixmap) | |
3943 | struct glyph_string *s; | |
3944 | HBITMAP pixmap; | |
3945 | { | |
3946 | HDC hdc = CreateCompatibleDC (s->hdc); | |
3947 | HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap); | |
3948 | int x; | |
9ef2e2cf | 3949 | int y = s->ybase - s->y - image_ascent (s->img, s->face); |
791f420f JR |
3950 | |
3951 | /* If first glyph of S has a left box line, start drawing it to the | |
3952 | right of that line. */ | |
3953 | if (s->face->box != FACE_NO_BOX | |
3954 | && s->first_glyph->left_box_line_p) | |
3955 | x = s->face->box_line_width; | |
3956 | else | |
3957 | x = 0; | |
3958 | ||
3959 | /* If there is a margin around the image, adjust x- and y-position | |
3960 | by that margin. */ | |
3961 | if (s->img->margin) | |
3962 | { | |
3963 | x += s->img->margin; | |
3964 | y += s->img->margin; | |
3965 | } | |
3966 | ||
3967 | if (s->img->pixmap) | |
3968 | { | |
01b220b6 | 3969 | #if 0 /* TODO: image mask */ |
791f420f JR |
3970 | if (s->img->mask) |
3971 | { | |
3972 | /* We can't set both a clip mask and use XSetClipRectangles | |
3973 | because the latter also sets a clip mask. We also can't | |
3974 | trust on the shape extension to be available | |
3975 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3976 | manually. */ | |
3977 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3978 | | GCFunction); | |
3979 | XGCValues xgcv; | |
3980 | ||
3981 | xgcv.clip_mask = s->img->mask; | |
3982 | xgcv.clip_x_origin = x; | |
3983 | xgcv.clip_y_origin = y; | |
3984 | xgcv.function = GXcopy; | |
3985 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3986 | ||
3987 | XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, | |
3988 | 0, 0, s->img->width, s->img->height, x, y); | |
3989 | XSetClipMask (s->display, s->gc, None); | |
3990 | } | |
3991 | else | |
3992 | #endif | |
ef0e360f | 3993 | { |
791f420f JR |
3994 | HDC compat_hdc = CreateCompatibleDC (hdc); |
3995 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
3996 | HBRUSH orig_brush = SelectObject (hdc, fg_brush); | |
3997 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
3998 | ||
3999 | SetTextColor (hdc, s->gc->foreground); | |
4000 | SetBkColor (hdc, s->gc->background); | |
4001 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
4002 | BitBlt (hdc, x, y, s->img->width, s->img->height, | |
4003 | compat_hdc, 0, 0, SRCCOPY); | |
4004 | #else | |
4005 | BitBlt (hdc, x, y, s->img->width, s->img->height, | |
4006 | compat_hdc, 0, 0, 0xB8074A); | |
4007 | #endif | |
4008 | SelectObject (hdc, orig_brush); | |
4009 | DeleteObject (fg_brush); | |
4010 | SelectObject (compat_hdc, orig_obj); | |
4011 | DeleteDC (compat_hdc); | |
4012 | ||
4013 | /* When the image has a mask, we can expect that at | |
4014 | least part of a mouse highlight or a block cursor will | |
4015 | be visible. If the image doesn't have a mask, make | |
4016 | a block cursor visible by drawing a rectangle around | |
4017 | the image. I believe it's looking better if we do | |
4018 | nothing here for mouse-face. */ | |
4019 | if (s->hl == DRAW_CURSOR) | |
4020 | w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, | |
4021 | s->img->height - 1); | |
ef0e360f | 4022 | } |
791f420f JR |
4023 | } |
4024 | else | |
4025 | w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, | |
4026 | s->img->height - 1); | |
4027 | ||
4028 | SelectObject (hdc, orig_hdc_obj); | |
4029 | DeleteDC (hdc); | |
4030 | } | |
4031 | ||
4032 | ||
4033 | /* Draw part of the background of glyph string S. X, Y, W, and H | |
4034 | give the rectangle to draw. */ | |
4035 | ||
4036 | static void | |
4037 | x_draw_glyph_string_bg_rect (s, x, y, w, h) | |
4038 | struct glyph_string *s; | |
4039 | int x, y, w, h; | |
4040 | { | |
01b220b6 | 4041 | #if 0 /* TODO: stipple */ |
791f420f JR |
4042 | if (s->stippled_p) |
4043 | { | |
4044 | /* Fill background with a stipple pattern. */ | |
4045 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4046 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
4047 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4048 | } | |
4049 | else | |
4050 | #endif | |
4051 | x_clear_glyph_string_rect (s, x, y, w, h); | |
4052 | } | |
4053 | ||
4054 | ||
4055 | /* Draw image glyph string S. | |
4056 | ||
4057 | s->y | |
4058 | s->x +------------------------- | |
4059 | | s->face->box | |
4060 | | | |
4061 | | +------------------------- | |
4062 | | | s->img->margin | |
4063 | | | | |
4064 | | | +------------------- | |
4065 | | | | the image | |
cabb23bc | 4066 | |
791f420f JR |
4067 | */ |
4068 | ||
4069 | static void | |
4070 | x_draw_image_glyph_string (s) | |
4071 | struct glyph_string *s; | |
4072 | { | |
4073 | int x, y; | |
4074 | int box_line_width = s->face->box_line_width; | |
4075 | int margin = s->img->margin; | |
4076 | int height; | |
4077 | HBITMAP pixmap = 0; | |
4078 | ||
4079 | height = s->height - 2 * box_line_width; | |
4080 | ||
4081 | /* Fill background with face under the image. Do it only if row is | |
4082 | taller than image or if image has a clip mask to reduce | |
4083 | flickering. */ | |
4084 | s->stippled_p = s->face->stipple != 0; | |
4085 | if (height > s->img->height | |
4086 | || margin | |
01b220b6 | 4087 | #if 0 /* TODO: image mask */ |
791f420f JR |
4088 | || s->img->mask |
4089 | #endif | |
4090 | || s->img->pixmap == 0 | |
4091 | || s->width != s->background_width) | |
4092 | { | |
4093 | if (box_line_width && s->first_glyph->left_box_line_p) | |
4094 | x = s->x + box_line_width; | |
4095 | else | |
4096 | x = s->x; | |
4097 | ||
4098 | y = s->y + box_line_width; | |
01b220b6 | 4099 | #if 0 /* TODO: image mask */ |
791f420f | 4100 | if (s->img->mask) |
ee78dc32 | 4101 | { |
791f420f JR |
4102 | /* Create a pixmap as large as the glyph string Fill it with |
4103 | the background color. Copy the image to it, using its | |
4104 | mask. Copy the temporary pixmap to the display. */ | |
4105 | Screen *screen = FRAME_X_SCREEN (s->f); | |
4106 | int depth = DefaultDepthOfScreen (screen); | |
4107 | ||
4108 | /* Create a pixmap as large as the glyph string. */ | |
4109 | pixmap = XCreatePixmap (s->display, s->window, | |
4110 | s->background_width, | |
4111 | s->height, depth); | |
4112 | ||
4113 | /* Don't clip in the following because we're working on the | |
4114 | pixmap. */ | |
4115 | XSetClipMask (s->display, s->gc, None); | |
ee78dc32 | 4116 | |
791f420f JR |
4117 | /* Fill the pixmap with the background color/stipple. */ |
4118 | if (s->stippled_p) | |
4119 | { | |
4120 | /* Fill background with a stipple pattern. */ | |
4121 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4122 | XFillRectangle (s->display, pixmap, s->gc, | |
4123 | 0, 0, s->background_width, s->height); | |
4124 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4125 | } | |
ef0e360f | 4126 | else |
791f420f JR |
4127 | { |
4128 | XGCValues xgcv; | |
4129 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, | |
4130 | &xgcv); | |
4131 | XSetForeground (s->display, s->gc, xgcv.background); | |
4132 | XFillRectangle (s->display, pixmap, s->gc, | |
4133 | 0, 0, s->background_width, s->height); | |
4134 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4135 | } | |
ee78dc32 | 4136 | } |
791f420f JR |
4137 | else |
4138 | #endif | |
791f420f JR |
4139 | x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height); |
4140 | ||
4141 | s->background_filled_p = 1; | |
4142 | } | |
ee78dc32 | 4143 | |
791f420f JR |
4144 | /* Draw the foreground. */ |
4145 | if (pixmap != 0) | |
4146 | { | |
4147 | w32_draw_image_foreground_1 (s, pixmap); | |
4148 | x_set_glyph_string_clipping (s); | |
ee78dc32 | 4149 | { |
791f420f JR |
4150 | HDC compat_hdc = CreateCompatibleDC (s->hdc); |
4151 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
4152 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
4153 | HGDIOBJ orig_obj = SelectObject (compat_hdc, pixmap); | |
4154 | ||
4155 | SetTextColor (s->hdc, s->gc->foreground); | |
4156 | SetBkColor (s->hdc, s->gc->background); | |
4157 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
4158 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, | |
4159 | compat_hdc, 0, 0, SRCCOPY); | |
4160 | #else | |
4161 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, | |
4162 | compat_hdc, 0, 0, 0xB8074A); | |
4163 | #endif | |
4164 | SelectObject (s->hdc, orig_brush); | |
4165 | DeleteObject (fg_brush); | |
4166 | SelectObject (compat_hdc, orig_obj); | |
4167 | DeleteDC (compat_hdc); | |
4168 | } | |
4169 | DeleteObject (pixmap); | |
4170 | pixmap = 0; | |
4171 | } | |
4172 | else | |
4173 | x_draw_image_foreground (s); | |
ee78dc32 | 4174 | |
791f420f JR |
4175 | /* If we must draw a relief around the image, do it. */ |
4176 | if (s->img->relief | |
4177 | || s->hl == DRAW_IMAGE_RAISED | |
4178 | || s->hl == DRAW_IMAGE_SUNKEN) | |
4179 | x_draw_image_relief (s); | |
4180 | } | |
ee78dc32 | 4181 | |
cabb23bc | 4182 | |
791f420f | 4183 | /* Draw stretch glyph string S. */ |
cabb23bc | 4184 | |
791f420f JR |
4185 | static void |
4186 | x_draw_stretch_glyph_string (s) | |
4187 | struct glyph_string *s; | |
4188 | { | |
4189 | xassert (s->first_glyph->type == STRETCH_GLYPH); | |
4190 | s->stippled_p = s->face->stipple != 0; | |
65c4903c | 4191 | |
791f420f JR |
4192 | if (s->hl == DRAW_CURSOR |
4193 | && !x_stretch_cursor_p) | |
4194 | { | |
4195 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor | |
4196 | as wide as the stretch glyph. */ | |
4197 | int width = min (CANON_X_UNIT (s->f), s->background_width); | |
cabb23bc | 4198 | |
791f420f JR |
4199 | /* Draw cursor. */ |
4200 | x_draw_glyph_string_bg_rect (s, s->x, s->y, width, s->height); | |
cabb23bc | 4201 | |
791f420f JR |
4202 | /* Clear rest using the GC of the original non-cursor face. */ |
4203 | if (width < s->background_width) | |
4204 | { | |
4205 | XGCValues *gc = s->face->gc; | |
4206 | int x = s->x + width, y = s->y; | |
4207 | int w = s->background_width - width, h = s->height; | |
4208 | RECT r; | |
4209 | HDC hdc = s->hdc; | |
4210 | w32_get_glyph_string_clip_rect (s, &r); | |
4211 | w32_set_clip_rectangle (hdc, &r); | |
4212 | ||
01b220b6 | 4213 | #if 0 /* TODO: stipple */ |
791f420f JR |
4214 | if (s->face->stipple) |
4215 | { | |
4216 | /* Fill background with a stipple pattern. */ | |
4217 | XSetFillStyle (s->display, gc, FillOpaqueStippled); | |
4218 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
4219 | XSetFillStyle (s->display, gc, FillSolid); | |
4220 | } | |
4221 | else | |
4222 | #endif | |
4223 | { | |
4224 | w32_fill_area (s->f, s->hdc, gc->background, x, y, w, h); | |
4225 | } | |
4226 | } | |
4227 | } | |
4228 | else | |
4229 | x_draw_glyph_string_bg_rect (s, s->x, s->y, s->background_width, | |
4230 | s->height); | |
4231 | ||
4232 | s->background_filled_p = 1; | |
4233 | } | |
cabb23bc | 4234 | |
cabb23bc | 4235 | |
791f420f JR |
4236 | /* Draw glyph string S. */ |
4237 | ||
4238 | static void | |
4239 | x_draw_glyph_string (s) | |
4240 | struct glyph_string *s; | |
4241 | { | |
4242 | /* If S draws into the background of its successor, draw the | |
4243 | background of the successor first so that S can draw into it. | |
4244 | This makes S->next use XDrawString instead of XDrawImageString. */ | |
4245 | if (s->next && s->right_overhang && !s->for_overlaps_p) | |
4246 | { | |
4247 | xassert (s->next->img == NULL); | |
4248 | x_set_glyph_string_gc (s->next); | |
4249 | x_set_glyph_string_clipping (s->next); | |
4250 | x_draw_glyph_string_background (s->next, 1); | |
4251 | } | |
4252 | ||
4253 | /* Set up S->gc, set clipping and draw S. */ | |
4254 | x_set_glyph_string_gc (s); | |
4255 | x_set_glyph_string_clipping (s); | |
4256 | ||
4257 | switch (s->first_glyph->type) | |
4258 | { | |
4259 | case IMAGE_GLYPH: | |
4260 | x_draw_image_glyph_string (s); | |
4261 | break; | |
4262 | ||
4263 | case STRETCH_GLYPH: | |
4264 | x_draw_stretch_glyph_string (s); | |
4265 | break; | |
4266 | ||
4267 | case CHAR_GLYPH: | |
4268 | if (s->for_overlaps_p) | |
4269 | s->background_filled_p = 1; | |
4270 | else | |
4271 | x_draw_glyph_string_background (s, 0); | |
4272 | x_draw_glyph_string_foreground (s); | |
4273 | break; | |
4274 | ||
4275 | case COMPOSITE_GLYPH: | |
4276 | if (s->for_overlaps_p || s->gidx > 0) | |
4277 | s->background_filled_p = 1; | |
4278 | else | |
4279 | x_draw_glyph_string_background (s, 1); | |
4280 | x_draw_composite_glyph_string_foreground (s); | |
4281 | break; | |
4282 | ||
4283 | default: | |
4284 | abort (); | |
4285 | } | |
4286 | ||
4287 | if (!s->for_overlaps_p) | |
4288 | { | |
4289 | /* Draw underline. */ | |
9ef2e2cf JR |
4290 | if (s->face->underline_p |
4291 | && (s->font->bdf || !s->font->tm.tmUnderlined)) | |
791f420f JR |
4292 | { |
4293 | unsigned long h = 1; | |
4294 | unsigned long dy = s->height - h; | |
4295 | ||
4296 | if (s->face->underline_defaulted_p) | |
4297 | { | |
4298 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
4299 | s->y + dy, s->width, 1); | |
4300 | } | |
4301 | else | |
4302 | { | |
4303 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4304 | s->y + dy, s->width, 1); | |
4305 | } | |
4306 | } | |
4307 | ||
4308 | /* Draw overline. */ | |
4309 | if (s->face->overline_p) | |
4310 | { | |
4311 | unsigned long dy = 0, h = 1; | |
4312 | ||
4313 | if (s->face->overline_color_defaulted_p) | |
4314 | { | |
4315 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
4316 | s->y + dy, s->width, h); | |
4317 | } | |
4318 | else | |
4319 | { | |
4320 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4321 | s->y + dy, s->width, h); | |
4322 | } | |
4323 | } | |
4324 | ||
4325 | /* Draw strike-through. */ | |
9ef2e2cf JR |
4326 | if (s->face->strike_through_p |
4327 | && (s->font->bdf || !s->font->tm.tmStruckOut)) | |
791f420f JR |
4328 | { |
4329 | unsigned long h = 1; | |
4330 | unsigned long dy = (s->height - h) / 2; | |
4331 | ||
4332 | if (s->face->strike_through_color_defaulted_p) | |
4333 | { | |
4334 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, s->y + dy, | |
4335 | s->width, h); | |
4336 | } | |
4337 | else | |
4338 | { | |
4339 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4340 | s->y + dy, s->width, h); | |
4341 | } | |
4342 | } | |
4343 | ||
4344 | /* Draw relief. */ | |
4345 | if (s->face->box != FACE_NO_BOX) | |
4346 | x_draw_glyph_string_box (s); | |
4347 | } | |
4348 | ||
4349 | /* Reset clipping. */ | |
4350 | w32_set_clip_rectangle (s->hdc, NULL); | |
4351 | } | |
4352 | ||
4353 | ||
4354 | static int x_fill_composite_glyph_string P_ ((struct glyph_string *, | |
4355 | struct face **, int)); | |
4356 | ||
4357 | ||
4358 | /* Load glyph string S with a composition components specified by S->cmp. | |
4359 | FACES is an array of faces for all components of this composition. | |
4360 | S->gidx is the index of the first component for S. | |
4361 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
4362 | use its lines physical height for clipping. | |
4363 | ||
4364 | Value is the index of a component not in S. */ | |
4365 | ||
4366 | static int | |
4367 | x_fill_composite_glyph_string (s, faces, overlaps_p) | |
4368 | struct glyph_string *s; | |
4369 | struct face **faces; | |
4370 | int overlaps_p; | |
4371 | { | |
4372 | int i; | |
4373 | ||
4374 | xassert (s); | |
4375 | ||
4376 | s->for_overlaps_p = overlaps_p; | |
4377 | ||
4378 | s->face = faces[s->gidx]; | |
4379 | s->font = s->face->font; | |
4380 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4381 | ||
4382 | /* For all glyphs of this composition, starting at the offset | |
4383 | S->gidx, until we reach the end of the definition or encounter a | |
4384 | glyph that requires the different face, add it to S. */ | |
4385 | ++s->nchars; | |
4386 | for (i = s->gidx + 1; i < s->cmp->glyph_len && faces[i] == s->face; ++i) | |
4387 | ++s->nchars; | |
4388 | ||
4389 | /* All glyph strings for the same composition has the same width, | |
4390 | i.e. the width set for the first component of the composition. */ | |
4391 | ||
4392 | s->width = s->first_glyph->pixel_width; | |
4393 | ||
4394 | /* If the specified font could not be loaded, use the frame's | |
4395 | default font, but record the fact that we couldn't load it in | |
4396 | the glyph string so that we can draw rectangles for the | |
4397 | characters of the glyph string. */ | |
4398 | if (s->font == NULL) | |
4399 | { | |
4400 | s->font_not_found_p = 1; | |
4401 | s->font = FRAME_FONT (s->f); | |
4402 | } | |
4403 | ||
4404 | /* Adjust base line for subscript/superscript text. */ | |
4405 | s->ybase += s->first_glyph->voffset; | |
4406 | ||
4407 | xassert (s->face && s->face->gc); | |
4408 | ||
4409 | /* This glyph string must always be drawn with 16-bit functions. */ | |
4410 | s->two_byte_p = 1; | |
4411 | ||
4412 | return s->gidx + s->nchars; | |
4413 | } | |
4414 | ||
4415 | ||
4416 | /* Load glyph string S with a sequence of characters. | |
4417 | FACE_ID is the face id of the string. START is the index of the | |
4418 | first glyph to consider, END is the index of the last + 1. | |
4419 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
4420 | use its lines physical height for clipping. | |
4421 | ||
4422 | Value is the index of the first glyph not in S. */ | |
4423 | ||
4424 | static int | |
4425 | x_fill_glyph_string (s, face_id, start, end, overlaps_p) | |
4426 | struct glyph_string *s; | |
4427 | int face_id; | |
4428 | int start, end, overlaps_p; | |
4429 | { | |
4430 | struct glyph *glyph, *last; | |
4431 | int voffset; | |
93ff4395 | 4432 | int glyph_not_available_p; |
791f420f JR |
4433 | |
4434 | xassert (s->f == XFRAME (s->w->frame)); | |
4435 | xassert (s->nchars == 0); | |
4436 | xassert (start >= 0 && end > start); | |
4437 | ||
4438 | s->for_overlaps_p = overlaps_p; | |
791f420f JR |
4439 | glyph = s->row->glyphs[s->area] + start; |
4440 | last = s->row->glyphs[s->area] + end; | |
4441 | voffset = glyph->voffset; | |
93ff4395 JR |
4442 | |
4443 | glyph_not_available_p = glyph->glyph_not_available_p; | |
4444 | ||
791f420f JR |
4445 | while (glyph < last |
4446 | && glyph->type == CHAR_GLYPH | |
4447 | && glyph->voffset == voffset | |
93ff4395 JR |
4448 | /* Same face id implies same font, nowadays. */ |
4449 | && glyph->face_id == face_id | |
4450 | && glyph->glyph_not_available_p == glyph_not_available_p) | |
791f420f | 4451 | { |
93ff4395 JR |
4452 | int two_byte_p; |
4453 | ||
791f420f | 4454 | s->face = x_get_glyph_face_and_encoding (s->f, glyph, |
93ff4395 JR |
4455 | s->char2b + s->nchars, |
4456 | &two_byte_p); | |
4457 | s->two_byte_p = two_byte_p; | |
791f420f JR |
4458 | ++s->nchars; |
4459 | xassert (s->nchars <= end - start); | |
4460 | s->width += glyph->pixel_width; | |
4461 | ++glyph; | |
4462 | } | |
4463 | ||
4464 | s->font = s->face->font; | |
4465 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4466 | ||
4467 | /* If the specified font could not be loaded, use the frame's font, | |
4468 | but record the fact that we couldn't load it in | |
4469 | S->font_not_found_p so that we can draw rectangles for the | |
4470 | characters of the glyph string. */ | |
93ff4395 | 4471 | if (s->font == NULL || glyph_not_available_p) |
791f420f JR |
4472 | { |
4473 | s->font_not_found_p = 1; | |
4474 | s->font = FRAME_FONT (s->f); | |
4475 | } | |
4476 | ||
4477 | /* Adjust base line for subscript/superscript text. */ | |
4478 | s->ybase += voffset; | |
4479 | ||
4480 | xassert (s->face && s->face->gc); | |
4481 | return glyph - s->row->glyphs[s->area]; | |
4482 | } | |
4483 | ||
4484 | ||
4485 | /* Fill glyph string S from image glyph S->first_glyph. */ | |
4486 | ||
4487 | static void | |
4488 | x_fill_image_glyph_string (s) | |
4489 | struct glyph_string *s; | |
4490 | { | |
4491 | xassert (s->first_glyph->type == IMAGE_GLYPH); | |
4492 | s->img = IMAGE_FROM_ID (s->f, s->first_glyph->u.img_id); | |
4493 | xassert (s->img); | |
4494 | s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id); | |
4495 | s->font = s->face->font; | |
4496 | s->width = s->first_glyph->pixel_width; | |
4497 | ||
4498 | /* Adjust base line for subscript/superscript text. */ | |
4499 | s->ybase += s->first_glyph->voffset; | |
4500 | } | |
4501 | ||
4502 | ||
ec48c3a7 | 4503 | /* Fill glyph string S from a sequence of stretch glyphs. |
791f420f | 4504 | |
ec48c3a7 JR |
4505 | ROW is the glyph row in which the glyphs are found, AREA is the |
4506 | area within the row. START is the index of the first glyph to | |
4507 | consider, END is the index of the last + 1. | |
4508 | ||
4509 | Value is the index of the first glyph not in S. */ | |
4510 | ||
4511 | static int | |
4512 | x_fill_stretch_glyph_string (s, row, area, start, end) | |
791f420f | 4513 | struct glyph_string *s; |
ec48c3a7 JR |
4514 | struct glyph_row *row; |
4515 | enum glyph_row_area area; | |
4516 | int start, end; | |
791f420f | 4517 | { |
ec48c3a7 JR |
4518 | struct glyph *glyph, *last; |
4519 | int voffset, face_id; | |
4520 | ||
791f420f | 4521 | xassert (s->first_glyph->type == STRETCH_GLYPH); |
ec48c3a7 JR |
4522 | |
4523 | glyph = s->row->glyphs[s->area] + start; | |
4524 | last = s->row->glyphs[s->area] + end; | |
4525 | face_id = glyph->face_id; | |
4526 | s->face = FACE_FROM_ID (s->f, face_id); | |
791f420f | 4527 | s->font = s->face->font; |
ec48c3a7 JR |
4528 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); |
4529 | s->width = glyph->pixel_width; | |
4530 | voffset = glyph->voffset; | |
4531 | ||
4532 | for (++glyph; | |
4533 | (glyph < last | |
4534 | && glyph->type == STRETCH_GLYPH | |
4535 | && glyph->voffset == voffset | |
4536 | && glyph->face_id == face_id); | |
4537 | ++glyph) | |
4538 | s->width += glyph->pixel_width; | |
791f420f JR |
4539 | |
4540 | /* Adjust base line for subscript/superscript text. */ | |
ec48c3a7 JR |
4541 | s->ybase += voffset; |
4542 | ||
4543 | xassert (s->face && s->face->gc); | |
4544 | return glyph - s->row->glyphs[s->area]; | |
791f420f JR |
4545 | } |
4546 | ||
4547 | ||
4548 | /* Initialize glyph string S. CHAR2B is a suitably allocated vector | |
4549 | of XChar2b structures for S; it can't be allocated in | |
4550 | x_init_glyph_string because it must be allocated via `alloca'. W | |
4551 | is the window on which S is drawn. ROW and AREA are the glyph row | |
4552 | and area within the row from which S is constructed. START is the | |
4553 | index of the first glyph structure covered by S. HL is a | |
4554 | face-override for drawing S. */ | |
4555 | ||
4556 | static void | |
4557 | w32_init_glyph_string (s, hdc, char2b, w, row, area, start, hl) | |
4558 | struct glyph_string *s; | |
4559 | HDC hdc; | |
4560 | wchar_t *char2b; | |
4561 | struct window *w; | |
4562 | struct glyph_row *row; | |
4563 | enum glyph_row_area area; | |
4564 | int start; | |
4565 | enum draw_glyphs_face hl; | |
4566 | { | |
4567 | bzero (s, sizeof *s); | |
4568 | s->w = w; | |
4569 | s->f = XFRAME (w->frame); | |
4570 | s->hdc = hdc; | |
4571 | s->window = FRAME_W32_WINDOW (s->f); | |
4572 | s->char2b = char2b; | |
4573 | s->hl = hl; | |
4574 | s->row = row; | |
4575 | s->area = area; | |
4576 | s->first_glyph = row->glyphs[area] + start; | |
4577 | s->height = row->height; | |
4578 | s->y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
4579 | ||
4580 | /* Display the internal border below the tool-bar window. */ | |
4581 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
4582 | s->y -= s->f->output_data.w32->internal_border_width; | |
4583 | ||
4584 | s->ybase = s->y + row->ascent; | |
4585 | } | |
4586 | ||
4587 | ||
4588 | /* Set background width of glyph string S. START is the index of the | |
4589 | first glyph following S. LAST_X is the right-most x-position + 1 | |
4590 | in the drawing area. */ | |
4591 | ||
4592 | static INLINE void | |
4593 | x_set_glyph_string_background_width (s, start, last_x) | |
4594 | struct glyph_string *s; | |
4595 | int start; | |
4596 | int last_x; | |
4597 | { | |
4598 | /* If the face of this glyph string has to be drawn to the end of | |
4599 | the drawing area, set S->extends_to_end_of_line_p. */ | |
4600 | struct face *default_face = FACE_FROM_ID (s->f, DEFAULT_FACE_ID); | |
4601 | ||
4602 | if (start == s->row->used[s->area] | |
4603 | && s->hl == DRAW_NORMAL_TEXT | |
4604 | && ((s->area == TEXT_AREA && s->row->fill_line_p) | |
4605 | || s->face->background != default_face->background | |
4606 | || s->face->stipple != default_face->stipple)) | |
4607 | s->extends_to_end_of_line_p = 1; | |
4608 | ||
4609 | /* If S extends its face to the end of the line, set its | |
4610 | background_width to the distance to the right edge of the drawing | |
4611 | area. */ | |
4612 | if (s->extends_to_end_of_line_p) | |
4613 | s->background_width = last_x - s->x + 1; | |
4614 | else | |
4615 | s->background_width = s->width; | |
4616 | } | |
4617 | ||
4618 | ||
4619 | /* Add a glyph string for a stretch glyph to the list of strings | |
4620 | between HEAD and TAIL. START is the index of the stretch glyph in | |
4621 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4622 | in that glyph row area. X is the current output position assigned | |
4623 | to the new glyph string constructed. HL overrides that face of the | |
4624 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4625 | is the right-most x-position of the drawing area. */ | |
4626 | ||
4627 | #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
4628 | do \ | |
4629 | { \ | |
4630 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4631 | w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \ | |
ec48c3a7 | 4632 | START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \ |
791f420f | 4633 | x_append_glyph_string (&HEAD, &TAIL, s); \ |
791f420f JR |
4634 | s->x = (X); \ |
4635 | } \ | |
4636 | while (0) | |
4637 | ||
4638 | ||
4639 | /* Add a glyph string for an image glyph to the list of strings | |
4640 | between HEAD and TAIL. START is the index of the image glyph in | |
4641 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4642 | in that glyph row area. X is the current output position assigned | |
4643 | to the new glyph string constructed. HL overrides that face of the | |
4644 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4645 | is the right-most x-position of the drawing area. */ | |
4646 | ||
4647 | #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
4648 | do \ | |
4649 | { \ | |
4650 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4651 | w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \ | |
4652 | x_fill_image_glyph_string (s); \ | |
4653 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
4654 | ++START; \ | |
4655 | s->x = (X); \ | |
4656 | } \ | |
4657 | while (0) | |
4658 | ||
4659 | ||
4660 | /* Add a glyph string for a sequence of character glyphs to the list | |
4661 | of strings between HEAD and TAIL. START is the index of the first | |
4662 | glyph in row area AREA of glyph row ROW that is part of the new | |
4663 | glyph string. END is the index of the last glyph in that glyph row | |
4664 | area. X is the current output position assigned to the new glyph | |
4665 | string constructed. HL overrides that face of the glyph; e.g. it | |
4666 | is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the | |
4667 | right-most x-position of the drawing area. */ | |
4668 | ||
4669 | #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4670 | do \ | |
4671 | { \ | |
ec48c3a7 | 4672 | int c, face_id; \ |
791f420f JR |
4673 | wchar_t *char2b; \ |
4674 | \ | |
4675 | c = (ROW)->glyphs[AREA][START].u.ch; \ | |
791f420f | 4676 | face_id = (ROW)->glyphs[AREA][START].face_id; \ |
9ef2e2cf | 4677 | \ |
791f420f JR |
4678 | s = (struct glyph_string *) alloca (sizeof *s); \ |
4679 | char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \ | |
4680 | w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \ | |
4681 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
791f420f JR |
4682 | s->x = (X); \ |
4683 | START = x_fill_glyph_string (s, face_id, START, END, \ | |
4684 | OVERLAPS_P); \ | |
4685 | } \ | |
4686 | while (0) | |
4687 | ||
4688 | ||
4689 | /* Add a glyph string for a composite sequence to the list of strings | |
4690 | between HEAD and TAIL. START is the index of the first glyph in | |
4691 | row area AREA of glyph row ROW that is part of the new glyph | |
4692 | string. END is the index of the last glyph in that glyph row area. | |
4693 | X is the current output position assigned to the new glyph string | |
4694 | constructed. HL overrides that face of the glyph; e.g. it is | |
4695 | DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most | |
4696 | x-position of the drawing area. */ | |
4697 | ||
4698 | #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4699 | do { \ | |
4700 | int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \ | |
4701 | int face_id = (ROW)->glyphs[AREA][START].face_id; \ | |
93ff4395 | 4702 | struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \ |
791f420f JR |
4703 | struct composition *cmp = composition_table[cmp_id]; \ |
4704 | int glyph_len = cmp->glyph_len; \ | |
4705 | wchar_t *char2b; \ | |
4706 | struct face **faces; \ | |
4707 | struct glyph_string *first_s = NULL; \ | |
4708 | int n; \ | |
4709 | \ | |
93ff4395 | 4710 | base_face = base_face->ascii_face; \ |
791f420f JR |
4711 | char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \ |
4712 | faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \ | |
4713 | /* At first, fill in `char2b' and `faces'. */ \ | |
4714 | for (n = 0; n < glyph_len; n++) \ | |
4715 | { \ | |
4716 | int c = COMPOSITION_GLYPH (cmp, n); \ | |
93ff4395 JR |
4717 | int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \ |
4718 | faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \ | |
4719 | x_get_char_face_and_encoding (XFRAME (w->frame), c, \ | |
4720 | this_face_id, char2b + n, 1); \ | |
791f420f JR |
4721 | } \ |
4722 | \ | |
4723 | /* Make glyph_strings for each glyph sequence that is drawable by \ | |
4724 | the same face, and append them to HEAD/TAIL. */ \ | |
4725 | for (n = 0; n < cmp->glyph_len;) \ | |
4726 | { \ | |
4727 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4728 | w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \ | |
4729 | x_append_glyph_string (&(HEAD), &(TAIL), s); \ | |
4730 | s->cmp = cmp; \ | |
4731 | s->gidx = n; \ | |
791f420f JR |
4732 | s->x = (X); \ |
4733 | \ | |
4734 | if (n == 0) \ | |
4735 | first_s = s; \ | |
4736 | \ | |
4737 | n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \ | |
4738 | } \ | |
4739 | \ | |
4740 | ++START; \ | |
4741 | s = first_s; \ | |
4742 | } while (0) | |
4743 | ||
9ef2e2cf | 4744 | |
791f420f JR |
4745 | /* Build a list of glyph strings between HEAD and TAIL for the glyphs |
4746 | of AREA of glyph row ROW on window W between indices START and END. | |
4747 | HL overrides the face for drawing glyph strings, e.g. it is | |
4748 | DRAW_CURSOR to draw a cursor. X and LAST_X are start and end | |
4749 | x-positions of the drawing area. | |
4750 | ||
4751 | This is an ugly monster macro construct because we must use alloca | |
4752 | to allocate glyph strings (because x_draw_glyphs can be called | |
4753 | asynchronously). */ | |
4754 | ||
4755 | #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4756 | do \ | |
4757 | { \ | |
4758 | HEAD = TAIL = NULL; \ | |
4759 | while (START < END) \ | |
4760 | { \ | |
4761 | struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \ | |
4762 | switch (first_glyph->type) \ | |
4763 | { \ | |
4764 | case CHAR_GLYPH: \ | |
4765 | BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \ | |
4766 | HEAD, TAIL, HL, X, LAST_X, \ | |
4767 | OVERLAPS_P); \ | |
4768 | break; \ | |
4769 | \ | |
4770 | case COMPOSITE_GLYPH: \ | |
4771 | BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \ | |
4772 | END, HEAD, TAIL, HL, X, \ | |
4773 | LAST_X, OVERLAPS_P); \ | |
4774 | break; \ | |
4775 | \ | |
4776 | case STRETCH_GLYPH: \ | |
4777 | BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\ | |
4778 | HEAD, TAIL, HL, X, LAST_X); \ | |
4779 | break; \ | |
4780 | \ | |
4781 | case IMAGE_GLYPH: \ | |
4782 | BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \ | |
4783 | HEAD, TAIL, HL, X, LAST_X); \ | |
4784 | break; \ | |
4785 | \ | |
4786 | default: \ | |
4787 | abort (); \ | |
4788 | } \ | |
4789 | \ | |
4790 | x_set_glyph_string_background_width (s, START, LAST_X); \ | |
4791 | (X) += s->width; \ | |
4792 | } \ | |
4793 | } \ | |
4794 | while (0) | |
4795 | ||
4796 | ||
4797 | /* Draw glyphs between START and END in AREA of ROW on window W, | |
4798 | starting at x-position X. X is relative to AREA in W. HL is a | |
4799 | face-override with the following meaning: | |
4800 | ||
4801 | DRAW_NORMAL_TEXT draw normally | |
4802 | DRAW_CURSOR draw in cursor face | |
4803 | DRAW_MOUSE_FACE draw in mouse face. | |
4804 | DRAW_INVERSE_VIDEO draw in mode line face | |
4805 | DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it | |
4806 | DRAW_IMAGE_RAISED draw an image with a raised relief around it | |
4807 | ||
4808 | If REAL_START is non-null, return in *REAL_START the real starting | |
4809 | position for display. This can be different from START in case | |
4810 | overlapping glyphs must be displayed. If REAL_END is non-null, | |
4811 | return in *REAL_END the real end position for display. This can be | |
4812 | different from END in case overlapping glyphs must be displayed. | |
4813 | ||
4814 | If OVERLAPS_P is non-zero, draw only the foreground of characters | |
4815 | and clip to the physical height of ROW. | |
4816 | ||
4817 | Value is the x-position reached, relative to AREA of W. */ | |
4818 | ||
4819 | static int | |
4820 | x_draw_glyphs (w, x, row, area, start, end, hl, real_start, real_end, | |
4821 | overlaps_p) | |
4822 | struct window *w; | |
4823 | int x; | |
4824 | struct glyph_row *row; | |
4825 | enum glyph_row_area area; | |
4826 | int start, end; | |
4827 | enum draw_glyphs_face hl; | |
4828 | int *real_start, *real_end; | |
4829 | int overlaps_p; | |
4830 | { | |
4831 | struct glyph_string *head, *tail; | |
4832 | struct glyph_string *s; | |
4833 | int last_x, area_width; | |
4834 | int x_reached; | |
4835 | int i, j; | |
4836 | HDC hdc = get_frame_dc (XFRAME (WINDOW_FRAME (w))); | |
4837 | ||
4838 | /* Let's rather be paranoid than getting a SEGV. */ | |
791f420f | 4839 | end = min (end, row->used[area]); |
9127e20e JR |
4840 | start = max (0, start); |
4841 | start = min (end, start); | |
4842 | ||
791f420f JR |
4843 | if (real_start) |
4844 | *real_start = start; | |
4845 | if (real_end) | |
4846 | *real_end = end; | |
4847 | ||
4848 | /* Translate X to frame coordinates. Set last_x to the right | |
4849 | end of the drawing area. */ | |
4850 | if (row->full_width_p) | |
4851 | { | |
791f420f JR |
4852 | /* X is relative to the left edge of W, without scroll bars |
4853 | or flag areas. */ | |
ec48c3a7 | 4854 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
791f420f JR |
4855 | /* int width = FRAME_FLAGS_AREA_WIDTH (f); */ |
4856 | int window_left_x = WINDOW_LEFT_MARGIN (w) * CANON_X_UNIT (f); | |
ee78dc32 | 4857 | |
791f420f JR |
4858 | x += window_left_x; |
4859 | area_width = XFASTINT (w->width) * CANON_X_UNIT (f); | |
4860 | last_x = window_left_x + area_width; | |
ee78dc32 | 4861 | |
791f420f JR |
4862 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
4863 | { | |
4864 | int width = FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
4865 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
4866 | last_x += width; | |
4867 | else | |
4868 | x -= width; | |
4869 | } | |
ee78dc32 | 4870 | |
791f420f JR |
4871 | x += FRAME_INTERNAL_BORDER_WIDTH (f); |
4872 | last_x -= FRAME_INTERNAL_BORDER_WIDTH (f); | |
4873 | } | |
4874 | else | |
4875 | { | |
4876 | x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, x); | |
4877 | area_width = window_box_width (w, area); | |
4878 | last_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, area_width); | |
4879 | } | |
e12ca9c2 | 4880 | |
791f420f JR |
4881 | /* Build a doubly-linked list of glyph_string structures between |
4882 | head and tail from what we have to draw. Note that the macro | |
4883 | BUILD_GLYPH_STRINGS will modify its start parameter. That's | |
4884 | the reason we use a separate variable `i'. */ | |
4885 | i = start; | |
4886 | BUILD_GLYPH_STRINGS (hdc, w, row, area, i, end, head, tail, hl, x, last_x, | |
4887 | overlaps_p); | |
791f420f JR |
4888 | if (tail) |
4889 | x_reached = tail->x + tail->background_width; | |
4890 | else | |
4891 | x_reached = x; | |
e12ca9c2 | 4892 | |
791f420f JR |
4893 | /* If there are any glyphs with lbearing < 0 or rbearing > width in |
4894 | the row, redraw some glyphs in front or following the glyph | |
4895 | strings built above. */ | |
9127e20e | 4896 | if (head && !overlaps_p && row->contains_overlapping_glyphs_p) |
791f420f JR |
4897 | { |
4898 | int dummy_x = 0; | |
4899 | struct glyph_string *h, *t; | |
4900 | ||
4901 | /* Compute overhangs for all glyph strings. */ | |
4902 | for (s = head; s; s = s->next) | |
4903 | x_compute_glyph_string_overhangs (s); | |
4904 | ||
4905 | /* Prepend glyph strings for glyphs in front of the first glyph | |
4906 | string that are overwritten because of the first glyph | |
4907 | string's left overhang. The background of all strings | |
4908 | prepended must be drawn because the first glyph string | |
4909 | draws over it. */ | |
4910 | i = x_left_overwritten (head); | |
4911 | if (i >= 0) | |
4912 | { | |
4913 | j = i; | |
4914 | BUILD_GLYPH_STRINGS (hdc, w, row, area, j, start, h, t, | |
4915 | DRAW_NORMAL_TEXT, dummy_x, last_x, | |
4916 | overlaps_p); | |
4917 | start = i; | |
4918 | if (real_start) | |
4919 | *real_start = start; | |
4920 | x_compute_overhangs_and_x (t, head->x, 1); | |
4921 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4922 | } | |
ee78dc32 | 4923 | |
791f420f JR |
4924 | /* Prepend glyph strings for glyphs in front of the first glyph |
4925 | string that overwrite that glyph string because of their | |
4926 | right overhang. For these strings, only the foreground must | |
4927 | be drawn, because it draws over the glyph string at `head'. | |
4928 | The background must not be drawn because this would overwrite | |
4929 | right overhangs of preceding glyphs for which no glyph | |
4930 | strings exist. */ | |
4931 | i = x_left_overwriting (head); | |
4932 | if (i >= 0) | |
4933 | { | |
4934 | BUILD_GLYPH_STRINGS (hdc, w, row, area, i, start, h, t, | |
4935 | DRAW_NORMAL_TEXT, dummy_x, last_x, | |
4936 | overlaps_p); | |
791f420f JR |
4937 | for (s = h; s; s = s->next) |
4938 | s->background_filled_p = 1; | |
4939 | if (real_start) | |
4940 | *real_start = i; | |
4941 | x_compute_overhangs_and_x (t, head->x, 1); | |
4942 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4943 | } | |
cabb23bc | 4944 | |
791f420f JR |
4945 | /* Append glyphs strings for glyphs following the last glyph |
4946 | string tail that are overwritten by tail. The background of | |
4947 | these strings has to be drawn because tail's foreground draws | |
4948 | over it. */ | |
4949 | i = x_right_overwritten (tail); | |
4950 | if (i >= 0) | |
4951 | { | |
4952 | BUILD_GLYPH_STRINGS (hdc, w, row, area, end, i, h, t, | |
4953 | DRAW_NORMAL_TEXT, x, last_x, | |
4954 | overlaps_p); | |
791f420f JR |
4955 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); |
4956 | x_append_glyph_string_lists (&head, &tail, h, t); | |
4957 | if (real_end) | |
4958 | *real_end = i; | |
4959 | } | |
cabb23bc | 4960 | |
791f420f JR |
4961 | /* Append glyph strings for glyphs following the last glyph |
4962 | string tail that overwrite tail. The foreground of such | |
4963 | glyphs has to be drawn because it writes into the background | |
4964 | of tail. The background must not be drawn because it could | |
4965 | paint over the foreground of following glyphs. */ | |
4966 | i = x_right_overwriting (tail); | |
4967 | if (i >= 0) | |
4968 | { | |
4969 | BUILD_GLYPH_STRINGS (hdc, w, row, area, end, i, h, t, | |
4970 | DRAW_NORMAL_TEXT, x, last_x, | |
4971 | overlaps_p); | |
791f420f JR |
4972 | for (s = h; s; s = s->next) |
4973 | s->background_filled_p = 1; | |
4974 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); | |
4975 | x_append_glyph_string_lists (&head, &tail, h, t); | |
4976 | if (real_end) | |
4977 | *real_end = i; | |
4978 | } | |
4979 | } | |
cabb23bc | 4980 | |
791f420f JR |
4981 | /* Draw all strings. */ |
4982 | for (s = head; s; s = s->next) | |
4983 | x_draw_glyph_string (s); | |
cabb23bc | 4984 | |
791f420f JR |
4985 | /* Value is the x-position up to which drawn, relative to AREA of W. |
4986 | This doesn't include parts drawn because of overhangs. */ | |
4987 | x_reached = FRAME_TO_WINDOW_PIXEL_X (w, x_reached); | |
4988 | if (!row->full_width_p) | |
4989 | { | |
4990 | if (area > LEFT_MARGIN_AREA) | |
4991 | x_reached -= window_box_width (w, LEFT_MARGIN_AREA); | |
4992 | if (area > TEXT_AREA) | |
4993 | x_reached -= window_box_width (w, TEXT_AREA); | |
4994 | } | |
cabb23bc | 4995 | |
791f420f | 4996 | release_frame_dc (XFRAME (WINDOW_FRAME (w)), hdc); |
65c4903c | 4997 | |
791f420f JR |
4998 | return x_reached; |
4999 | } | |
65c4903c | 5000 | |
cabb23bc | 5001 | |
791f420f JR |
5002 | /* Fix the display of area AREA of overlapping row ROW in window W. */ |
5003 | ||
5004 | static void | |
5005 | x_fix_overlapping_area (w, row, area) | |
5006 | struct window *w; | |
5007 | struct glyph_row *row; | |
5008 | enum glyph_row_area area; | |
5009 | { | |
5010 | int i, x; | |
5011 | ||
5012 | BLOCK_INPUT; | |
5013 | ||
5014 | if (area == LEFT_MARGIN_AREA) | |
5015 | x = 0; | |
5016 | else if (area == TEXT_AREA) | |
5017 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5018 | else | |
5019 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5020 | + window_box_width (w, TEXT_AREA)); | |
b1ae662f | 5021 | |
791f420f JR |
5022 | for (i = 0; i < row->used[area];) |
5023 | { | |
5024 | if (row->glyphs[area][i].overlaps_vertically_p) | |
ee78dc32 | 5025 | { |
791f420f | 5026 | int start = i, start_x = x; |
ee78dc32 | 5027 | |
791f420f JR |
5028 | do |
5029 | { | |
5030 | x += row->glyphs[area][i].pixel_width; | |
5031 | ++i; | |
5032 | } | |
5033 | while (i < row->used[area] | |
5034 | && row->glyphs[area][i].overlaps_vertically_p); | |
cabb23bc | 5035 | |
791f420f JR |
5036 | x_draw_glyphs (w, start_x, row, area, start, i, |
5037 | (row->inverse_p | |
5038 | ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT), | |
5039 | NULL, NULL, 1); | |
5040 | } | |
5041 | else | |
5042 | { | |
5043 | x += row->glyphs[area][i].pixel_width; | |
5044 | ++i; | |
5045 | } | |
5046 | } | |
5047 | ||
5048 | UNBLOCK_INPUT; | |
ee78dc32 GV |
5049 | } |
5050 | ||
ee78dc32 | 5051 | |
791f420f JR |
5052 | /* Output LEN glyphs starting at START at the nominal cursor position. |
5053 | Advance the nominal cursor over the text. The global variable | |
5054 | updated_window contains the window being updated, updated_row is | |
5055 | the glyph row being updated, and updated_area is the area of that | |
5056 | row being updated. */ | |
ee78dc32 | 5057 | |
96214669 | 5058 | static void |
791f420f JR |
5059 | x_write_glyphs (start, len) |
5060 | struct glyph *start; | |
ee78dc32 GV |
5061 | int len; |
5062 | { | |
791f420f | 5063 | int x, hpos, real_start, real_end; |
ee78dc32 | 5064 | |
791f420f | 5065 | xassert (updated_window && updated_row); |
ee78dc32 | 5066 | BLOCK_INPUT; |
791f420f JR |
5067 | |
5068 | /* Write glyphs. */ | |
ee78dc32 | 5069 | |
791f420f JR |
5070 | hpos = start - updated_row->glyphs[updated_area]; |
5071 | x = x_draw_glyphs (updated_window, output_cursor.x, | |
5072 | updated_row, updated_area, | |
5073 | hpos, hpos + len, | |
5074 | (updated_row->inverse_p | |
5075 | ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT), | |
5076 | &real_start, &real_end, 0); | |
5077 | ||
5078 | /* If we drew over the cursor, note that it is not visible any more. */ | |
5079 | note_overwritten_text_cursor (updated_window, real_start, | |
5080 | real_end - real_start); | |
5081 | ||
5082 | UNBLOCK_INPUT; | |
5083 | ||
5084 | /* Advance the output cursor. */ | |
5085 | output_cursor.hpos += len; | |
5086 | output_cursor.x = x; | |
5087 | } | |
ee78dc32 | 5088 | |
ee78dc32 | 5089 | |
791f420f | 5090 | /* Insert LEN glyphs from START at the nominal cursor position. */ |
ee78dc32 | 5091 | |
791f420f JR |
5092 | static void |
5093 | x_insert_glyphs (start, len) | |
5094 | struct glyph *start; | |
5095 | register int len; | |
5096 | { | |
5097 | struct frame *f; | |
5098 | struct window *w; | |
5099 | int line_height, shift_by_width, shifted_region_width; | |
5100 | struct glyph_row *row; | |
5101 | struct glyph *glyph; | |
5102 | int frame_x, frame_y, hpos, real_start, real_end; | |
5103 | HDC hdc; | |
5104 | ||
5105 | xassert (updated_window && updated_row); | |
5106 | BLOCK_INPUT; | |
5107 | w = updated_window; | |
5108 | f = XFRAME (WINDOW_FRAME (w)); | |
5109 | hdc = get_frame_dc (f); | |
5110 | ||
5111 | /* Get the height of the line we are in. */ | |
5112 | row = updated_row; | |
5113 | line_height = row->height; | |
5114 | ||
5115 | /* Get the width of the glyphs to insert. */ | |
5116 | shift_by_width = 0; | |
5117 | for (glyph = start; glyph < start + len; ++glyph) | |
5118 | shift_by_width += glyph->pixel_width; | |
5119 | ||
5120 | /* Get the width of the region to shift right. */ | |
5121 | shifted_region_width = (window_box_width (w, updated_area) | |
5122 | - output_cursor.x | |
5123 | - shift_by_width); | |
5124 | ||
5125 | /* Shift right. */ | |
5126 | frame_x = WINDOW_TO_FRAME_PIXEL_X (w, output_cursor.x); | |
5127 | frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); | |
5128 | BitBlt (hdc, frame_x + shift_by_width, frame_y, | |
5129 | shifted_region_width, line_height, | |
5130 | hdc, frame_x, frame_y, SRCCOPY); | |
5131 | ||
5132 | /* Write the glyphs. */ | |
5133 | hpos = start - row->glyphs[updated_area]; | |
5134 | x_draw_glyphs (w, output_cursor.x, row, updated_area, hpos, hpos + len, | |
5135 | DRAW_NORMAL_TEXT, &real_start, &real_end, 0); | |
5136 | note_overwritten_text_cursor (w, real_start, real_end - real_start); | |
5137 | ||
5138 | /* Advance the output cursor. */ | |
5139 | output_cursor.hpos += len; | |
5140 | output_cursor.x += shift_by_width; | |
5141 | release_frame_dc (f, hdc); | |
ee78dc32 GV |
5142 | |
5143 | UNBLOCK_INPUT; | |
5144 | } | |
791f420f JR |
5145 | |
5146 | ||
5147 | /* Delete N glyphs at the nominal cursor position. Not implemented | |
5148 | for X frames. */ | |
ee78dc32 | 5149 | |
96214669 | 5150 | static void |
791f420f JR |
5151 | x_delete_glyphs (n) |
5152 | register int n; | |
ee78dc32 | 5153 | { |
791f420f JR |
5154 | abort (); |
5155 | } | |
ee78dc32 | 5156 | |
ee78dc32 | 5157 | |
791f420f JR |
5158 | /* Erase the current text line from the nominal cursor position |
5159 | (inclusive) to pixel column TO_X (exclusive). The idea is that | |
5160 | everything from TO_X onward is already erased. | |
ee78dc32 | 5161 | |
791f420f JR |
5162 | TO_X is a pixel position relative to updated_area of |
5163 | updated_window. TO_X == -1 means clear to the end of this area. */ | |
11606873 | 5164 | |
791f420f JR |
5165 | static void |
5166 | x_clear_end_of_line (to_x) | |
5167 | int to_x; | |
5168 | { | |
5169 | struct frame *f; | |
5170 | struct window *w = updated_window; | |
5171 | int max_x, min_y, max_y; | |
5172 | int from_x, from_y, to_y; | |
5173 | ||
5174 | xassert (updated_window && updated_row); | |
5175 | f = XFRAME (w->frame); | |
5176 | ||
5177 | if (updated_row->full_width_p) | |
5178 | { | |
5179 | max_x = XFASTINT (w->width) * CANON_X_UNIT (f); | |
5180 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f) | |
5181 | && !w->pseudo_window_p) | |
5182 | max_x += FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
5183 | } | |
5184 | else | |
5185 | max_x = window_box_width (w, updated_area); | |
5186 | max_y = window_text_bottom_y (w); | |
ee78dc32 | 5187 | |
791f420f JR |
5188 | /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end |
5189 | of window. For TO_X > 0, truncate to end of drawing area. */ | |
5190 | if (to_x == 0) | |
5191 | return; | |
5192 | else if (to_x < 0) | |
5193 | to_x = max_x; | |
5194 | else | |
5195 | to_x = min (to_x, max_x); | |
ee78dc32 | 5196 | |
791f420f JR |
5197 | to_y = min (max_y, output_cursor.y + updated_row->height); |
5198 | ||
ee78dc32 | 5199 | /* Notice if the cursor will be cleared by this operation. */ |
791f420f JR |
5200 | if (!updated_row->full_width_p) |
5201 | note_overwritten_text_cursor (w, output_cursor.hpos, -1); | |
ee78dc32 | 5202 | |
791f420f JR |
5203 | from_x = output_cursor.x; |
5204 | ||
5205 | /* Translate to frame coordinates. */ | |
5206 | if (updated_row->full_width_p) | |
5207 | { | |
5208 | from_x = WINDOW_TO_FRAME_PIXEL_X (w, from_x); | |
5209 | to_x = WINDOW_TO_FRAME_PIXEL_X (w, to_x); | |
5210 | } | |
5211 | else | |
5212 | { | |
5213 | from_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, from_x); | |
5214 | to_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, to_x); | |
5215 | } | |
5216 | ||
5217 | min_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
5218 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, max (min_y, output_cursor.y)); | |
5219 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, to_y); | |
5220 | ||
5221 | /* Prevent inadvertently clearing to end of the X window. */ | |
5222 | if (to_x > from_x && to_y > from_y) | |
5223 | { | |
00fe468b | 5224 | HDC hdc; |
791f420f | 5225 | BLOCK_INPUT; |
00fe468b JR |
5226 | hdc = get_frame_dc (f); |
5227 | ||
5228 | w32_clear_area (f, hdc, from_x, from_y, to_x - from_x, to_y - from_y); | |
5229 | release_frame_dc (f, hdc); | |
791f420f JR |
5230 | UNBLOCK_INPUT; |
5231 | } | |
ee78dc32 GV |
5232 | } |
5233 | ||
791f420f JR |
5234 | |
5235 | /* Clear entire frame. If updating_frame is non-null, clear that | |
5236 | frame. Otherwise clear the selected frame. */ | |
5237 | ||
96214669 | 5238 | static void |
791f420f | 5239 | x_clear_frame () |
ee78dc32 | 5240 | { |
791f420f | 5241 | struct frame *f; |
ee78dc32 | 5242 | |
791f420f JR |
5243 | if (updating_frame) |
5244 | f = updating_frame; | |
5245 | else | |
5246 | f = SELECTED_FRAME (); | |
ee78dc32 | 5247 | |
791f420f JR |
5248 | /* Clearing the frame will erase any cursor, so mark them all as no |
5249 | longer visible. */ | |
5250 | mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
5251 | output_cursor.hpos = output_cursor.vpos = 0; | |
5252 | output_cursor.x = -1; | |
ee78dc32 | 5253 | |
791f420f JR |
5254 | /* We don't set the output cursor here because there will always |
5255 | follow an explicit cursor_to. */ | |
ee78dc32 GV |
5256 | BLOCK_INPUT; |
5257 | ||
fbd6baed | 5258 | w32_clear_window (f); |
ee78dc32 GV |
5259 | |
5260 | /* We have to clear the scroll bars, too. If we have changed | |
5261 | colors or something like that, then they should be notified. */ | |
5262 | x_scroll_bar_clear (f); | |
5263 | ||
5264 | UNBLOCK_INPUT; | |
5265 | } | |
791f420f | 5266 | |
ee78dc32 GV |
5267 | \f |
5268 | /* Make audible bell. */ | |
5269 | ||
96214669 GV |
5270 | static void |
5271 | w32_ring_bell (void) | |
ee78dc32 GV |
5272 | { |
5273 | BLOCK_INPUT; | |
5274 | ||
5275 | if (visible_bell) | |
8331e676 GV |
5276 | { |
5277 | int i; | |
791f420f | 5278 | HWND hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); |
8331e676 GV |
5279 | |
5280 | for (i = 0; i < 5; i++) | |
5281 | { | |
5282 | FlashWindow (hwnd, TRUE); | |
5283 | Sleep (10); | |
5284 | } | |
5285 | FlashWindow (hwnd, FALSE); | |
5286 | } | |
ee78dc32 | 5287 | else |
fbd6baed | 5288 | w32_sys_ring_bell (); |
ee78dc32 GV |
5289 | |
5290 | UNBLOCK_INPUT; | |
ee78dc32 | 5291 | } |
791f420f | 5292 | |
ee78dc32 | 5293 | \f |
791f420f JR |
5294 | /* Specify how many text lines, from the top of the window, |
5295 | should be affected by insert-lines and delete-lines operations. | |
5296 | This, and those operations, are used only within an update | |
5297 | that is bounded by calls to x_update_begin and x_update_end. */ | |
ee78dc32 | 5298 | |
96214669 | 5299 | static void |
791f420f JR |
5300 | w32_set_terminal_window (n) |
5301 | register int n; | |
ee78dc32 | 5302 | { |
791f420f | 5303 | /* This function intentionally left blank. */ |
ee78dc32 | 5304 | } |
791f420f JR |
5305 | \f |
5306 | ||
5307 | \f | |
5308 | /*********************************************************************** | |
5309 | Line Dance | |
5310 | ***********************************************************************/ | |
5311 | ||
5312 | /* Perform an insert-lines or delete-lines operation, inserting N | |
5313 | lines or deleting -N lines at vertical position VPOS. */ | |
ee78dc32 | 5314 | |
96214669 | 5315 | static void |
791f420f JR |
5316 | x_ins_del_lines (vpos, n) |
5317 | int vpos, n; | |
ee78dc32 GV |
5318 | { |
5319 | abort (); | |
5320 | } | |
791f420f JR |
5321 | |
5322 | ||
5323 | /* Scroll part of the display as described by RUN. */ | |
5324 | ||
5325 | static void | |
5326 | x_scroll_run (w, run) | |
5327 | struct window *w; | |
5328 | struct run *run; | |
5329 | { | |
5330 | struct frame *f = XFRAME (w->frame); | |
5331 | int x, y, width, height, from_y, to_y, bottom_y; | |
5332 | HDC hdc = get_frame_dc (f); | |
5333 | ||
5334 | /* Get frame-relative bounding box of the text display area of W, | |
5335 | without mode lines. Include in this box the flags areas to the | |
5336 | left and right of W. */ | |
5337 | window_box (w, -1, &x, &y, &width, &height); | |
5338 | width += FRAME_X_FLAGS_AREA_WIDTH (f); | |
5339 | x -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); | |
5340 | ||
5341 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y); | |
5342 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y); | |
5343 | bottom_y = y + height; | |
5344 | ||
5345 | if (to_y < from_y) | |
5346 | { | |
5347 | /* Scrolling up. Make sure we don't copy part of the mode | |
5348 | line at the bottom. */ | |
5349 | if (from_y + run->height > bottom_y) | |
5350 | height = bottom_y - from_y; | |
5351 | else | |
5352 | height = run->height; | |
5353 | } | |
5354 | else | |
5355 | { | |
5356 | /* Scolling down. Make sure we don't copy over the mode line. | |
5357 | at the bottom. */ | |
5358 | if (to_y + run->height > bottom_y) | |
5359 | height = bottom_y - to_y; | |
5360 | else | |
5361 | height = run->height; | |
5362 | } | |
5363 | ||
5364 | BLOCK_INPUT; | |
5365 | ||
5366 | /* Cursor off. Will be switched on again in x_update_window_end. */ | |
5367 | updated_window = w; | |
5368 | x_clear_cursor (w); | |
5369 | ||
5370 | BitBlt (hdc, x, to_y, width, height, hdc, x, from_y, SRCCOPY); | |
5371 | ||
5372 | UNBLOCK_INPUT; | |
5373 | release_frame_dc (f, hdc); | |
5374 | } | |
5375 | ||
9ef2e2cf | 5376 | |
ee78dc32 | 5377 | \f |
791f420f JR |
5378 | /*********************************************************************** |
5379 | Exposure Events | |
5380 | ***********************************************************************/ | |
5381 | ||
5382 | /* Redisplay an exposed area of frame F. X and Y are the upper-left | |
5383 | corner of the exposed rectangle. W and H are width and height of | |
5384 | the exposed area. All are pixel values. W or H zero means redraw | |
5385 | the entire frame. */ | |
ee78dc32 | 5386 | |
96214669 | 5387 | static void |
791f420f JR |
5388 | expose_frame (f, x, y, w, h) |
5389 | struct frame *f; | |
5390 | int x, y, w, h; | |
ee78dc32 | 5391 | { |
791f420f JR |
5392 | RECT r; |
5393 | ||
5394 | TRACE ((stderr, "expose_frame ")); | |
5395 | ||
5396 | /* No need to redraw if frame will be redrawn soon. */ | |
5397 | if (FRAME_GARBAGED_P (f)) | |
5398 | { | |
5399 | TRACE ((stderr, " garbaged\n")); | |
5400 | return; | |
5401 | } | |
5402 | ||
5403 | /* If basic faces haven't been realized yet, there is no point in | |
5404 | trying to redraw anything. This can happen when we get an expose | |
5405 | event while Emacs is starting, e.g. by moving another window. */ | |
5406 | if (FRAME_FACE_CACHE (f) == NULL | |
5407 | || FRAME_FACE_CACHE (f)->used < BASIC_FACE_ID_SENTINEL) | |
5408 | { | |
5409 | TRACE ((stderr, " no faces\n")); | |
5410 | return; | |
5411 | } | |
5412 | ||
5413 | if (w == 0 || h == 0) | |
5414 | { | |
5415 | r.left = r.top = 0; | |
5416 | r.right = CANON_X_UNIT (f) * f->width; | |
5417 | r.bottom = CANON_Y_UNIT (f) * f->height; | |
5418 | } | |
5419 | else | |
5420 | { | |
5421 | r.left = x; | |
5422 | r.top = y; | |
5423 | r.right = x + w; | |
5424 | r.bottom = y + h; | |
5425 | } | |
5426 | ||
5427 | TRACE ((stderr, "(%d, %d, %d, %d)\n", r.left, r.top, r.right, r.bottom)); | |
5428 | expose_window_tree (XWINDOW (f->root_window), &r); | |
5429 | ||
5430 | if (WINDOWP (f->tool_bar_window)) | |
5431 | { | |
5432 | struct window *w = XWINDOW (f->tool_bar_window); | |
5433 | RECT window_rect; | |
5434 | RECT intersection_rect; | |
5435 | int window_x, window_y, window_width, window_height; | |
5436 | ||
5437 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); | |
5438 | window_rect.left = window_x; | |
5439 | window_rect.top = window_y; | |
5440 | window_rect.right = window_x + window_width; | |
5441 | window_rect.bottom = window_y + window_height; | |
5442 | ||
158cba56 | 5443 | if (IntersectRect (&intersection_rect, &r, &window_rect)) |
791f420f JR |
5444 | expose_window (w, &intersection_rect); |
5445 | } | |
5446 | } | |
5447 | ||
5448 | ||
5449 | /* Redraw (parts) of all windows in the window tree rooted at W that | |
5450 | intersect R. R contains frame pixel coordinates. */ | |
5451 | ||
5452 | static void | |
5453 | expose_window_tree (w, r) | |
5454 | struct window *w; | |
5455 | RECT *r; | |
5456 | { | |
5457 | while (w) | |
5458 | { | |
5459 | if (!NILP (w->hchild)) | |
5460 | expose_window_tree (XWINDOW (w->hchild), r); | |
5461 | else if (!NILP (w->vchild)) | |
5462 | expose_window_tree (XWINDOW (w->vchild), r); | |
5463 | else | |
5464 | { | |
5465 | RECT window_rect; | |
5466 | RECT intersection_rect; | |
5467 | struct frame *f = XFRAME (w->frame); | |
5468 | int window_x, window_y, window_width, window_height; | |
5469 | ||
5470 | /* Frame-relative pixel rectangle of W. */ | |
5471 | window_box (w, -1, &window_x, &window_y, &window_width, | |
5472 | &window_height); | |
5473 | window_rect.left | |
5474 | = (window_x | |
5475 | - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) | |
5476 | - FRAME_LEFT_SCROLL_BAR_WIDTH (f) * CANON_Y_UNIT (f)); | |
5477 | window_rect.top = window_y; | |
5478 | window_rect.right = window_rect.left | |
5479 | + (window_width | |
5480 | + FRAME_X_FLAGS_AREA_WIDTH (f) | |
5481 | + FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f)); | |
5482 | window_rect.bottom = window_rect.top | |
5483 | + window_height + CURRENT_MODE_LINE_HEIGHT (w); | |
5484 | ||
158cba56 | 5485 | if (IntersectRect (&intersection_rect, r, &window_rect)) |
791f420f JR |
5486 | expose_window (w, &intersection_rect); |
5487 | } | |
5488 | ||
5489 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
5490 | } | |
5491 | } | |
5492 | ||
5493 | ||
5494 | /* Redraw the part of glyph row area AREA of glyph row ROW on window W | |
5495 | which intersects rectangle R. R is in window-relative coordinates. */ | |
5496 | ||
5497 | static void | |
5498 | expose_area (w, row, r, area) | |
5499 | struct window *w; | |
5500 | struct glyph_row *row; | |
5501 | RECT *r; | |
5502 | enum glyph_row_area area; | |
5503 | { | |
791f420f JR |
5504 | struct glyph *first = row->glyphs[area]; |
5505 | struct glyph *end = row->glyphs[area] + row->used[area]; | |
5506 | struct glyph *last; | |
2df85294 | 5507 | int first_x, start_x, x; |
791f420f JR |
5508 | |
5509 | /* Set x to the window-relative start position for drawing glyphs of | |
5510 | AREA. The first glyph of the text area can be partially visible. | |
5511 | The first glyphs of other areas cannot. */ | |
5512 | if (area == LEFT_MARGIN_AREA) | |
5513 | x = 0; | |
5514 | else if (area == TEXT_AREA) | |
5515 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5516 | else | |
5517 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5518 | + window_box_width (w, TEXT_AREA)); | |
5519 | ||
5520 | if (area == TEXT_AREA && row->fill_line_p) | |
5521 | /* If row extends face to end of line write the whole line. */ | |
5522 | x_draw_glyphs (w, x, row, area, | |
5523 | 0, row->used[area], | |
5524 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
5525 | NULL, NULL, 0); | |
5526 | else | |
5527 | { | |
2df85294 JR |
5528 | /* Set START_X to the window-relative start position for drawing glyphs of |
5529 | AREA. The first glyph of the text area can be partially visible. | |
5530 | The first glyphs of other areas cannot. */ | |
5531 | if (area == LEFT_MARGIN_AREA) | |
5532 | start_x = 0; | |
5533 | else if (area == TEXT_AREA) | |
5534 | start_x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5535 | else | |
5536 | start_x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5537 | + window_box_width (w, TEXT_AREA)); | |
5538 | x = start_x; | |
5539 | ||
791f420f JR |
5540 | /* Find the first glyph that must be redrawn. */ |
5541 | while (first < end | |
5542 | && x + first->pixel_width < r->left) | |
5543 | { | |
5544 | x += first->pixel_width; | |
5545 | ++first; | |
5546 | } | |
5547 | ||
5548 | /* Find the last one. */ | |
5549 | last = first; | |
5550 | first_x = x; | |
5551 | while (last < end | |
5552 | && x < r->right) | |
5553 | { | |
5554 | x += last->pixel_width; | |
5555 | ++last; | |
5556 | } | |
2df85294 | 5557 | |
791f420f JR |
5558 | /* Repaint. */ |
5559 | if (last > first) | |
f201d732 | 5560 | x_draw_glyphs (w, first_x - start_x, row, area, |
791f420f JR |
5561 | first - row->glyphs[area], |
5562 | last - row->glyphs[area], | |
5563 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
5564 | NULL, NULL, 0); | |
5565 | } | |
5566 | } | |
5567 | ||
5568 | ||
5569 | /* Redraw the parts of the glyph row ROW on window W intersecting | |
5570 | rectangle R. R is in window-relative coordinates. */ | |
ee78dc32 | 5571 | |
791f420f JR |
5572 | static void |
5573 | expose_line (w, row, r) | |
5574 | struct window *w; | |
5575 | struct glyph_row *row; | |
5576 | RECT *r; | |
5577 | { | |
5578 | xassert (row->enabled_p); | |
5579 | ||
5580 | if (row->mode_line_p || w->pseudo_window_p) | |
5581 | x_draw_glyphs (w, 0, row, TEXT_AREA, 0, row->used[TEXT_AREA], | |
5582 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
5583 | NULL, NULL, 0); | |
ee78dc32 | 5584 | else |
791f420f JR |
5585 | { |
5586 | if (row->used[LEFT_MARGIN_AREA]) | |
5587 | expose_area (w, row, r, LEFT_MARGIN_AREA); | |
5588 | if (row->used[TEXT_AREA]) | |
5589 | expose_area (w, row, r, TEXT_AREA); | |
5590 | if (row->used[RIGHT_MARGIN_AREA]) | |
5591 | expose_area (w, row, r, RIGHT_MARGIN_AREA); | |
5592 | x_draw_row_bitmaps (w, row); | |
5593 | } | |
ee78dc32 | 5594 | } |
ee78dc32 | 5595 | |
ee78dc32 | 5596 | |
791f420f | 5597 | /* Return non-zero if W's cursor intersects rectangle R. */ |
96214669 | 5598 | |
791f420f JR |
5599 | static int |
5600 | x_phys_cursor_in_rect_p (w, r) | |
5601 | struct window *w; | |
5602 | RECT *r; | |
ee78dc32 | 5603 | { |
791f420f JR |
5604 | RECT cr, result; |
5605 | struct glyph *cursor_glyph; | |
ee78dc32 | 5606 | |
791f420f JR |
5607 | cursor_glyph = get_phys_cursor_glyph (w); |
5608 | if (cursor_glyph) | |
ee78dc32 | 5609 | { |
791f420f JR |
5610 | cr.left = w->phys_cursor.x; |
5611 | cr.top = w->phys_cursor.y; | |
5612 | cr.right = cr.left + cursor_glyph->pixel_width; | |
5613 | cr.bottom = cr.top + w->phys_cursor_height; | |
158cba56 | 5614 | return IntersectRect (&result, &cr, r); |
ee78dc32 GV |
5615 | } |
5616 | else | |
791f420f | 5617 | return 0; |
ee78dc32 GV |
5618 | } |
5619 | ||
791f420f JR |
5620 | |
5621 | /* Redraw a rectangle of window W. R is a rectangle in window | |
5622 | relative coordinates. Call this function with input blocked. */ | |
5623 | ||
ee78dc32 | 5624 | static void |
791f420f JR |
5625 | expose_window (w, r) |
5626 | struct window *w; | |
5627 | RECT *r; | |
ee78dc32 | 5628 | { |
791f420f JR |
5629 | struct glyph_row *row; |
5630 | int y; | |
5631 | int yb = window_text_bottom_y (w); | |
5632 | int cursor_cleared_p; | |
5633 | ||
5634 | /* If window is not yet fully initialized, do nothing. This can | |
5635 | happen when toolkit scroll bars are used and a window is split. | |
5636 | Reconfiguring the scroll bar will generate an expose for a newly | |
5637 | created window. */ | |
5638 | if (w->current_matrix == NULL) | |
ee78dc32 GV |
5639 | return; |
5640 | ||
791f420f JR |
5641 | TRACE ((stderr, "expose_window (%d, %d, %d, %d)\n", |
5642 | r->left, r->top, r->right, r->bottom)); | |
ee78dc32 | 5643 | |
791f420f JR |
5644 | /* Convert to window coordinates. */ |
5645 | r->left = FRAME_TO_WINDOW_PIXEL_X (w, r->left); | |
5646 | r->top = FRAME_TO_WINDOW_PIXEL_Y (w, r->top); | |
5647 | r->right = FRAME_TO_WINDOW_PIXEL_X (w, r->right); | |
5648 | r->bottom = FRAME_TO_WINDOW_PIXEL_Y (w, r->bottom); | |
ee78dc32 | 5649 | |
791f420f JR |
5650 | /* Turn off the cursor. */ |
5651 | if (!w->pseudo_window_p | |
5652 | && x_phys_cursor_in_rect_p (w, r)) | |
5653 | { | |
5654 | x_clear_cursor (w); | |
5655 | cursor_cleared_p = 1; | |
5656 | } | |
5657 | else | |
5658 | cursor_cleared_p = 0; | |
5659 | ||
5660 | /* Find the first row intersecting the rectangle R. */ | |
5661 | row = w->current_matrix->rows; | |
5662 | y = 0; | |
5663 | while (row->enabled_p | |
5664 | && y < yb | |
5665 | && y + row->height < r->top) | |
5666 | { | |
5667 | y += row->height; | |
5668 | ++row; | |
5669 | } | |
5670 | ||
5671 | /* Display the text in the rectangle, one text line at a time. */ | |
5672 | while (row->enabled_p | |
5673 | && y < yb | |
5674 | && y < r->bottom) | |
5675 | { | |
5676 | expose_line (w, row, r); | |
5677 | y += row->height; | |
5678 | ++row; | |
5679 | } | |
ee78dc32 | 5680 | |
791f420f JR |
5681 | /* Display the mode line if there is one. */ |
5682 | if (WINDOW_WANTS_MODELINE_P (w) | |
5683 | && (row = MATRIX_MODE_LINE_ROW (w->current_matrix), | |
5684 | row->enabled_p) | |
5685 | && row->y < r->bottom) | |
5686 | expose_line (w, row, r); | |
689004fa | 5687 | |
791f420f JR |
5688 | if (!w->pseudo_window_p) |
5689 | { | |
5690 | /* Draw border between windows. */ | |
5691 | x_draw_vertical_border (w); | |
5692 | ||
5693 | /* Turn the cursor on again. */ | |
5694 | if (cursor_cleared_p) | |
5695 | x_update_window_cursor (w, 1); | |
5696 | } | |
ee78dc32 | 5697 | } |
ee78dc32 | 5698 | |
ee78dc32 GV |
5699 | \f |
5700 | static void | |
5701 | frame_highlight (f) | |
5702 | struct frame *f; | |
5703 | { | |
791f420f | 5704 | x_update_cursor (f, 1); |
ee78dc32 GV |
5705 | } |
5706 | ||
5707 | static void | |
5708 | frame_unhighlight (f) | |
5709 | struct frame *f; | |
5710 | { | |
791f420f | 5711 | x_update_cursor (f, 1); |
ee78dc32 GV |
5712 | } |
5713 | ||
ee78dc32 GV |
5714 | /* The focus has changed. Update the frames as necessary to reflect |
5715 | the new situation. Note that we can't change the selected frame | |
5716 | here, because the Lisp code we are interrupting might become confused. | |
5717 | Each event gets marked with the frame in which it occurred, so the | |
5718 | Lisp code can tell when the switch took place by examining the events. */ | |
5719 | ||
9ef2e2cf | 5720 | static void |
ee78dc32 | 5721 | x_new_focus_frame (dpyinfo, frame) |
fbd6baed | 5722 | struct w32_display_info *dpyinfo; |
ee78dc32 GV |
5723 | struct frame *frame; |
5724 | { | |
fbd6baed | 5725 | struct frame *old_focus = dpyinfo->w32_focus_frame; |
ee78dc32 | 5726 | |
fbd6baed | 5727 | if (frame != dpyinfo->w32_focus_frame) |
ee78dc32 GV |
5728 | { |
5729 | /* Set this before calling other routines, so that they see | |
fbd6baed GV |
5730 | the correct value of w32_focus_frame. */ |
5731 | dpyinfo->w32_focus_frame = frame; | |
ee78dc32 GV |
5732 | |
5733 | if (old_focus && old_focus->auto_lower) | |
5734 | x_lower_frame (old_focus); | |
5735 | ||
fbd6baed GV |
5736 | if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise) |
5737 | pending_autoraise_frame = dpyinfo->w32_focus_frame; | |
ee78dc32 GV |
5738 | else |
5739 | pending_autoraise_frame = 0; | |
5740 | } | |
5741 | ||
5742 | x_frame_rehighlight (dpyinfo); | |
5743 | } | |
5744 | ||
5745 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ | |
5746 | ||
5747 | void | |
5748 | x_mouse_leave (dpyinfo) | |
fbd6baed | 5749 | struct w32_display_info *dpyinfo; |
ee78dc32 | 5750 | { |
fbd6baed | 5751 | x_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame); |
ee78dc32 GV |
5752 | } |
5753 | ||
5754 | /* The focus has changed, or we have redirected a frame's focus to | |
5755 | another frame (this happens when a frame uses a surrogate | |
9ef2e2cf | 5756 | mini-buffer frame). Shift the highlight as appropriate. |
ee78dc32 GV |
5757 | |
5758 | The FRAME argument doesn't necessarily have anything to do with which | |
9ef2e2cf JR |
5759 | frame is being highlighted or un-highlighted; we only use it to find |
5760 | the appropriate X display info. */ | |
5761 | ||
ee78dc32 | 5762 | static void |
fbd6baed | 5763 | w32_frame_rehighlight (frame) |
ee78dc32 GV |
5764 | struct frame *frame; |
5765 | { | |
fbd6baed | 5766 | x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame)); |
ee78dc32 GV |
5767 | } |
5768 | ||
5769 | static void | |
5770 | x_frame_rehighlight (dpyinfo) | |
fbd6baed | 5771 | struct w32_display_info *dpyinfo; |
ee78dc32 | 5772 | { |
fbd6baed | 5773 | struct frame *old_highlight = dpyinfo->w32_highlight_frame; |
ee78dc32 | 5774 | |
fbd6baed | 5775 | if (dpyinfo->w32_focus_frame) |
ee78dc32 | 5776 | { |
fbd6baed GV |
5777 | dpyinfo->w32_highlight_frame |
5778 | = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame))) | |
5779 | ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame)) | |
5780 | : dpyinfo->w32_focus_frame); | |
5781 | if (! FRAME_LIVE_P (dpyinfo->w32_highlight_frame)) | |
ee78dc32 | 5782 | { |
fbd6baed GV |
5783 | FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame) = Qnil; |
5784 | dpyinfo->w32_highlight_frame = dpyinfo->w32_focus_frame; | |
ee78dc32 GV |
5785 | } |
5786 | } | |
5787 | else | |
fbd6baed | 5788 | dpyinfo->w32_highlight_frame = 0; |
ee78dc32 | 5789 | |
fbd6baed | 5790 | if (dpyinfo->w32_highlight_frame != old_highlight) |
ee78dc32 GV |
5791 | { |
5792 | if (old_highlight) | |
5793 | frame_unhighlight (old_highlight); | |
fbd6baed GV |
5794 | if (dpyinfo->w32_highlight_frame) |
5795 | frame_highlight (dpyinfo->w32_highlight_frame); | |
ee78dc32 GV |
5796 | } |
5797 | } | |
5798 | \f | |
5799 | /* Keyboard processing - modifier keys, etc. */ | |
5800 | ||
5801 | /* Convert a keysym to its name. */ | |
5802 | ||
5803 | char * | |
5804 | x_get_keysym_name (keysym) | |
5805 | int keysym; | |
5806 | { | |
5807 | /* Make static so we can always return it */ | |
5808 | static char value[100]; | |
5809 | ||
5810 | BLOCK_INPUT; | |
9127e20e | 5811 | GetKeyNameText (keysym, value, 100); |
ee78dc32 GV |
5812 | UNBLOCK_INPUT; |
5813 | ||
5814 | return value; | |
5815 | } | |
9ef2e2cf JR |
5816 | |
5817 | ||
ee78dc32 GV |
5818 | \f |
5819 | /* Mouse clicks and mouse movement. Rah. */ | |
5820 | ||
9ef2e2cf JR |
5821 | /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph |
5822 | co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the | |
5823 | glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do | |
5824 | not force the value into range. */ | |
ee78dc32 GV |
5825 | |
5826 | void | |
5827 | pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip) | |
5828 | FRAME_PTR f; | |
5829 | register int pix_x, pix_y; | |
5830 | register int *x, *y; | |
5831 | RECT *bounds; | |
5832 | int noclip; | |
5833 | { | |
52cf03a1 GV |
5834 | /* Support tty mode: if Vwindow_system is nil, behave correctly. */ |
5835 | if (NILP (Vwindow_system)) | |
5836 | { | |
5837 | *x = pix_x; | |
5838 | *y = pix_y; | |
5839 | return; | |
5840 | } | |
5841 | ||
ee78dc32 GV |
5842 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down |
5843 | even for negative values. */ | |
5844 | if (pix_x < 0) | |
9127e20e | 5845 | pix_x -= FONT_WIDTH (FRAME_FONT (f)) - 1; |
ee78dc32 | 5846 | if (pix_y < 0) |
fbd6baed | 5847 | pix_y -= (f)->output_data.w32->line_height - 1; |
ee78dc32 GV |
5848 | |
5849 | pix_x = PIXEL_TO_CHAR_COL (f, pix_x); | |
5850 | pix_y = PIXEL_TO_CHAR_ROW (f, pix_y); | |
5851 | ||
5852 | if (bounds) | |
5853 | { | |
5854 | bounds->left = CHAR_TO_PIXEL_COL (f, pix_x); | |
5855 | bounds->top = CHAR_TO_PIXEL_ROW (f, pix_y); | |
9127e20e | 5856 | bounds->right = bounds->left + FONT_WIDTH (FRAME_FONT (f)) - 1; |
fbd6baed | 5857 | bounds->bottom = bounds->top + f->output_data.w32->line_height - 1; |
ee78dc32 GV |
5858 | } |
5859 | ||
5860 | if (!noclip) | |
5861 | { | |
5862 | if (pix_x < 0) | |
5863 | pix_x = 0; | |
ec48c3a7 JR |
5864 | else if (pix_x > FRAME_WINDOW_WIDTH (f)) |
5865 | pix_x = FRAME_WINDOW_WIDTH (f); | |
ee78dc32 GV |
5866 | |
5867 | if (pix_y < 0) | |
5868 | pix_y = 0; | |
5869 | else if (pix_y > f->height) | |
5870 | pix_y = f->height; | |
5871 | } | |
5872 | ||
5873 | *x = pix_x; | |
5874 | *y = pix_y; | |
5875 | } | |
5876 | ||
791f420f JR |
5877 | |
5878 | /* Given HPOS/VPOS in the current matrix of W, return corresponding | |
5879 | frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we | |
5880 | can't tell the positions because W's display is not up to date, | |
5881 | return 0. */ | |
5882 | ||
5883 | int | |
5884 | glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y) | |
5885 | struct window *w; | |
5886 | int hpos, vpos; | |
5887 | int *frame_x, *frame_y; | |
ee78dc32 | 5888 | { |
791f420f JR |
5889 | int success_p; |
5890 | ||
5891 | xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w); | |
5892 | xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h); | |
5893 | ||
5894 | if (display_completed) | |
52cf03a1 | 5895 | { |
791f420f JR |
5896 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos); |
5897 | struct glyph *glyph = row->glyphs[TEXT_AREA]; | |
5898 | struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]); | |
5899 | ||
5900 | *frame_y = row->y; | |
5901 | *frame_x = row->x; | |
5902 | while (glyph < end) | |
5903 | { | |
5904 | *frame_x += glyph->pixel_width; | |
5905 | ++glyph; | |
5906 | } | |
5907 | ||
5908 | success_p = 1; | |
5909 | } | |
5910 | else | |
5911 | { | |
5912 | *frame_y = *frame_x = 0; | |
5913 | success_p = 0; | |
52cf03a1 GV |
5914 | } |
5915 | ||
791f420f JR |
5916 | *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y); |
5917 | *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x); | |
5918 | return success_p; | |
ee78dc32 GV |
5919 | } |
5920 | ||
5921 | BOOL | |
5922 | parse_button (message, pbutton, pup) | |
5923 | int message; | |
5924 | int * pbutton; | |
5925 | int * pup; | |
5926 | { | |
5927 | int button = 0; | |
5928 | int up = 0; | |
5929 | ||
5930 | switch (message) | |
5931 | { | |
5932 | case WM_LBUTTONDOWN: | |
5933 | button = 0; | |
5934 | up = 0; | |
5935 | break; | |
5936 | case WM_LBUTTONUP: | |
5937 | button = 0; | |
5938 | up = 1; | |
5939 | break; | |
5940 | case WM_MBUTTONDOWN: | |
fbd6baed | 5941 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5942 | button = 1; |
5943 | else | |
5944 | button = 2; | |
ee78dc32 GV |
5945 | up = 0; |
5946 | break; | |
5947 | case WM_MBUTTONUP: | |
fbd6baed | 5948 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5949 | button = 1; |
5950 | else | |
5951 | button = 2; | |
ee78dc32 GV |
5952 | up = 1; |
5953 | break; | |
5954 | case WM_RBUTTONDOWN: | |
fbd6baed | 5955 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5956 | button = 2; |
5957 | else | |
5958 | button = 1; | |
ee78dc32 GV |
5959 | up = 0; |
5960 | break; | |
5961 | case WM_RBUTTONUP: | |
fbd6baed | 5962 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5963 | button = 2; |
5964 | else | |
5965 | button = 1; | |
ee78dc32 GV |
5966 | up = 1; |
5967 | break; | |
5968 | default: | |
5969 | return (FALSE); | |
5970 | } | |
5971 | ||
5972 | if (pup) *pup = up; | |
5973 | if (pbutton) *pbutton = button; | |
5974 | ||
5975 | return (TRUE); | |
5976 | } | |
5977 | ||
5978 | ||
5979 | /* Prepare a mouse-event in *RESULT for placement in the input queue. | |
5980 | ||
5981 | If the event is a button press, then note that we have grabbed | |
5982 | the mouse. */ | |
5983 | ||
ec48c3a7 | 5984 | static Lisp_Object |
ee78dc32 GV |
5985 | construct_mouse_click (result, msg, f) |
5986 | struct input_event *result; | |
fbd6baed | 5987 | W32Msg *msg; |
ee78dc32 GV |
5988 | struct frame *f; |
5989 | { | |
5990 | int button; | |
5991 | int up; | |
5992 | ||
5993 | parse_button (msg->msg.message, &button, &up); | |
5994 | ||
5995 | /* Make the event type no_event; we'll change that when we decide | |
5996 | otherwise. */ | |
5997 | result->kind = mouse_click; | |
5998 | result->code = button; | |
5999 | result->timestamp = msg->msg.time; | |
6000 | result->modifiers = (msg->dwModifiers | |
6001 | | (up | |
6002 | ? up_modifier | |
6003 | : down_modifier)); | |
6004 | ||
ec48c3a7 JR |
6005 | XSETINT (result->x, LOWORD (msg->msg.lParam)); |
6006 | XSETINT (result->y, HIWORD (msg->msg.lParam)); | |
6007 | XSETFRAME (result->frame_or_window, f); | |
6008 | result->arg = Qnil; | |
6009 | return Qnil; | |
ee78dc32 GV |
6010 | } |
6011 | ||
ec48c3a7 | 6012 | static Lisp_Object |
689004fa GV |
6013 | construct_mouse_wheel (result, msg, f) |
6014 | struct input_event *result; | |
6015 | W32Msg *msg; | |
6016 | struct frame *f; | |
6017 | { | |
6018 | POINT p; | |
6019 | result->kind = mouse_wheel; | |
6020 | result->code = (short) HIWORD (msg->msg.wParam); | |
6021 | result->timestamp = msg->msg.time; | |
6022 | result->modifiers = msg->dwModifiers; | |
6023 | p.x = LOWORD (msg->msg.lParam); | |
6024 | p.y = HIWORD (msg->msg.lParam); | |
9127e20e | 6025 | ScreenToClient (msg->msg.hwnd, &p); |
689004fa GV |
6026 | XSETINT (result->x, p.x); |
6027 | XSETINT (result->y, p.y); | |
6028 | XSETFRAME (result->frame_or_window, f); | |
7e889510 | 6029 | result->arg = Qnil; |
ec48c3a7 | 6030 | return Qnil; |
689004fa GV |
6031 | } |
6032 | ||
ec48c3a7 | 6033 | static Lisp_Object |
12857dfd RS |
6034 | construct_drag_n_drop (result, msg, f) |
6035 | struct input_event *result; | |
6036 | W32Msg *msg; | |
6037 | struct frame *f; | |
6038 | { | |
6039 | Lisp_Object files; | |
6040 | Lisp_Object frame; | |
6041 | HDROP hdrop; | |
6042 | POINT p; | |
6043 | WORD num_files; | |
6044 | char *name; | |
6045 | int i, len; | |
6046 | ||
6047 | result->kind = drag_n_drop; | |
6048 | result->code = 0; | |
6049 | result->timestamp = msg->msg.time; | |
6050 | result->modifiers = msg->dwModifiers; | |
6051 | ||
fb9cc9cc AI |
6052 | hdrop = (HDROP) msg->msg.wParam; |
6053 | DragQueryPoint (hdrop, &p); | |
6054 | ||
e12ca9c2 | 6055 | #if 0 |
12857dfd RS |
6056 | p.x = LOWORD (msg->msg.lParam); |
6057 | p.y = HIWORD (msg->msg.lParam); | |
6058 | ScreenToClient (msg->msg.hwnd, &p); | |
e12ca9c2 AI |
6059 | #endif |
6060 | ||
12857dfd RS |
6061 | XSETINT (result->x, p.x); |
6062 | XSETINT (result->y, p.y); | |
6063 | ||
12857dfd RS |
6064 | num_files = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); |
6065 | files = Qnil; | |
6066 | ||
6067 | for (i = 0; i < num_files; i++) | |
6068 | { | |
6069 | len = DragQueryFile (hdrop, i, NULL, 0); | |
6070 | if (len <= 0) | |
6071 | continue; | |
6072 | name = alloca (len + 1); | |
6073 | DragQueryFile (hdrop, i, name, len + 1); | |
6074 | files = Fcons (build_string (name), files); | |
6075 | } | |
6076 | ||
6077 | DragFinish (hdrop); | |
6078 | ||
6079 | XSETFRAME (frame, f); | |
6080 | result->frame_or_window = Fcons (frame, files); | |
7e889510 | 6081 | result->arg = Qnil; |
ec48c3a7 | 6082 | return Qnil; |
12857dfd RS |
6083 | } |
6084 | ||
ee78dc32 GV |
6085 | \f |
6086 | /* Function to report a mouse movement to the mainstream Emacs code. | |
6087 | The input handler calls this. | |
6088 | ||
6089 | We have received a mouse movement event, which is given in *event. | |
6090 | If the mouse is over a different glyph than it was last time, tell | |
6091 | the mainstream emacs code by setting mouse_moved. If not, ask for | |
6092 | another motion event, so we can check again the next time it moves. */ | |
6093 | ||
791f420f JR |
6094 | static MSG last_mouse_motion_event; |
6095 | static Lisp_Object last_mouse_motion_frame; | |
6096 | ||
ee78dc32 GV |
6097 | static void |
6098 | note_mouse_movement (frame, msg) | |
6099 | FRAME_PTR frame; | |
6100 | MSG *msg; | |
6101 | { | |
6102 | last_mouse_movement_time = msg->time; | |
791f420f JR |
6103 | memcpy (&last_mouse_motion_event, msg, sizeof (last_mouse_motion_event)); |
6104 | XSETFRAME (last_mouse_motion_frame, frame); | |
ee78dc32 | 6105 | |
fbd6baed | 6106 | if (msg->hwnd != FRAME_W32_WINDOW (frame)) |
ee78dc32 GV |
6107 | { |
6108 | frame->mouse_moved = 1; | |
6109 | last_mouse_scroll_bar = Qnil; | |
ee78dc32 GV |
6110 | note_mouse_highlight (frame, -1, -1); |
6111 | } | |
6112 | ||
6113 | /* Has the mouse moved off the glyph it was on at the last sighting? */ | |
6114 | else if (LOWORD (msg->lParam) < last_mouse_glyph.left | |
6115 | || LOWORD (msg->lParam) > last_mouse_glyph.right | |
9bf7b6aa | 6116 | || HIWORD (msg->lParam) < last_mouse_glyph.top |
ee78dc32 GV |
6117 | || HIWORD (msg->lParam) > last_mouse_glyph.bottom) |
6118 | { | |
6119 | frame->mouse_moved = 1; | |
6120 | last_mouse_scroll_bar = Qnil; | |
6121 | ||
6122 | note_mouse_highlight (frame, LOWORD (msg->lParam), HIWORD (msg->lParam)); | |
6123 | } | |
6124 | } | |
6125 | ||
6126 | /* This is used for debugging, to turn off note_mouse_highlight. */ | |
9ef2e2cf | 6127 | |
791f420f JR |
6128 | int disable_mouse_highlight; |
6129 | ||
6130 | ||
6131 | \f | |
6132 | /************************************************************************ | |
6133 | Mouse Face | |
6134 | ************************************************************************/ | |
6135 | ||
6136 | /* Find the glyph under window-relative coordinates X/Y in window W. | |
6137 | Consider only glyphs from buffer text, i.e. no glyphs from overlay | |
6138 | strings. Return in *HPOS and *VPOS the row and column number of | |
6139 | the glyph found. Return in *AREA the glyph area containing X. | |
6140 | Value is a pointer to the glyph found or null if X/Y is not on | |
6141 | text, or we can't tell because W's current matrix is not up to | |
6142 | date. */ | |
6143 | ||
6144 | static struct glyph * | |
6145 | x_y_to_hpos_vpos (w, x, y, hpos, vpos, area) | |
6146 | struct window *w; | |
6147 | int x, y; | |
6148 | int *hpos, *vpos, *area; | |
6149 | { | |
6150 | struct glyph *glyph, *end; | |
ec48c3a7 | 6151 | struct glyph_row *row = NULL; |
791f420f JR |
6152 | int x0, i, left_area_width; |
6153 | ||
6154 | /* Find row containing Y. Give up if some row is not enabled. */ | |
6155 | for (i = 0; i < w->current_matrix->nrows; ++i) | |
6156 | { | |
6157 | row = MATRIX_ROW (w->current_matrix, i); | |
6158 | if (!row->enabled_p) | |
6159 | return NULL; | |
6160 | if (y >= row->y && y < MATRIX_ROW_BOTTOM_Y (row)) | |
6161 | break; | |
6162 | } | |
6163 | ||
6164 | *vpos = i; | |
6165 | *hpos = 0; | |
6166 | ||
6167 | /* Give up if Y is not in the window. */ | |
6168 | if (i == w->current_matrix->nrows) | |
6169 | return NULL; | |
6170 | ||
6171 | /* Get the glyph area containing X. */ | |
6172 | if (w->pseudo_window_p) | |
6173 | { | |
6174 | *area = TEXT_AREA; | |
6175 | x0 = 0; | |
6176 | } | |
6177 | else | |
6178 | { | |
6179 | left_area_width = window_box_width (w, LEFT_MARGIN_AREA); | |
6180 | if (x < left_area_width) | |
6181 | { | |
6182 | *area = LEFT_MARGIN_AREA; | |
6183 | x0 = 0; | |
6184 | } | |
6185 | else if (x < left_area_width + window_box_width (w, TEXT_AREA)) | |
6186 | { | |
6187 | *area = TEXT_AREA; | |
6188 | x0 = row->x + left_area_width; | |
6189 | } | |
6190 | else | |
6191 | { | |
6192 | *area = RIGHT_MARGIN_AREA; | |
6193 | x0 = left_area_width + window_box_width (w, TEXT_AREA); | |
6194 | } | |
6195 | } | |
6196 | ||
6197 | /* Find glyph containing X. */ | |
6198 | glyph = row->glyphs[*area]; | |
6199 | end = glyph + row->used[*area]; | |
6200 | while (glyph < end) | |
6201 | { | |
6202 | if (x < x0 + glyph->pixel_width) | |
6203 | { | |
6204 | if (w->pseudo_window_p) | |
6205 | break; | |
6206 | else if (BUFFERP (glyph->object)) | |
6207 | break; | |
6208 | } | |
6209 | ||
6210 | x0 += glyph->pixel_width; | |
6211 | ++glyph; | |
6212 | } | |
6213 | ||
6214 | if (glyph == end) | |
6215 | return NULL; | |
6216 | ||
6217 | *hpos = glyph - row->glyphs[*area]; | |
6218 | return glyph; | |
6219 | } | |
6220 | ||
6221 | ||
6222 | /* Convert frame-relative x/y to coordinates relative to window W. | |
6223 | Takes pseudo-windows into account. */ | |
6224 | ||
6225 | static void | |
6226 | frame_to_window_pixel_xy (w, x, y) | |
6227 | struct window *w; | |
6228 | int *x, *y; | |
6229 | { | |
6230 | if (w->pseudo_window_p) | |
6231 | { | |
6232 | /* A pseudo-window is always full-width, and starts at the | |
6233 | left edge of the frame, plus a frame border. */ | |
6234 | struct frame *f = XFRAME (w->frame); | |
6235 | *x -= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f); | |
6236 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6237 | } | |
6238 | else | |
6239 | { | |
6240 | *x = FRAME_TO_WINDOW_PIXEL_X (w, *x); | |
6241 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6242 | } | |
6243 | } | |
6244 | ||
6245 | ||
6246 | /* Take proper action when mouse has moved to the mode or top line of | |
6247 | window W, x-position X. MODE_LINE_P non-zero means mouse is on the | |
6248 | mode line. X is relative to the start of the text display area of | |
6249 | W, so the width of bitmap areas and scroll bars must be subtracted | |
6250 | to get a position relative to the start of the mode line. */ | |
6251 | ||
6252 | static void | |
6253 | note_mode_line_highlight (w, x, mode_line_p) | |
6254 | struct window *w; | |
6255 | int x, mode_line_p; | |
6256 | { | |
6257 | struct frame *f = XFRAME (w->frame); | |
6258 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6259 | Cursor cursor = dpyinfo->vertical_scroll_bar_cursor; | |
6260 | struct glyph_row *row; | |
6261 | ||
6262 | if (mode_line_p) | |
6263 | row = MATRIX_MODE_LINE_ROW (w->current_matrix); | |
6264 | else | |
6265 | row = MATRIX_HEADER_LINE_ROW (w->current_matrix); | |
6266 | ||
6267 | if (row->enabled_p) | |
6268 | { | |
6269 | struct glyph *glyph, *end; | |
6270 | Lisp_Object help, map; | |
6271 | int x0; | |
6272 | ||
6273 | /* Find the glyph under X. */ | |
6274 | glyph = row->glyphs[TEXT_AREA]; | |
6275 | end = glyph + row->used[TEXT_AREA]; | |
6276 | x0 = - (FRAME_LEFT_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f) | |
6277 | + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f)); | |
6278 | while (glyph < end | |
6279 | && x >= x0 + glyph->pixel_width) | |
6280 | { | |
6281 | x0 += glyph->pixel_width; | |
6282 | ++glyph; | |
6283 | } | |
6284 | ||
6285 | if (glyph < end | |
6286 | && STRINGP (glyph->object) | |
6287 | && XSTRING (glyph->object)->intervals | |
6288 | && glyph->charpos >= 0 | |
6289 | && glyph->charpos < XSTRING (glyph->object)->size) | |
6290 | { | |
6291 | /* If we're on a string with `help-echo' text property, | |
6292 | arrange for the help to be displayed. This is done by | |
6293 | setting the global variable help_echo to the help string. */ | |
6294 | help = Fget_text_property (make_number (glyph->charpos), | |
6295 | Qhelp_echo, glyph->object); | |
b7e80413 | 6296 | if (!NILP (help)) |
ec48c3a7 JR |
6297 | { |
6298 | help_echo = help; | |
158cba56 | 6299 | XSETWINDOW (help_echo_window, w); |
ec48c3a7 JR |
6300 | help_echo_object = glyph->object; |
6301 | help_echo_pos = glyph->charpos; | |
6302 | } | |
791f420f JR |
6303 | |
6304 | /* Change the mouse pointer according to what is under X/Y. */ | |
6305 | map = Fget_text_property (make_number (glyph->charpos), | |
6306 | Qlocal_map, glyph->object); | |
02067692 | 6307 | if (KEYMAPP (map)) |
791f420f JR |
6308 | cursor = f->output_data.w32->nontext_cursor; |
6309 | } | |
6310 | } | |
9ef2e2cf | 6311 | |
01b220b6 | 6312 | #if 0 /* TODO: mouse cursor */ |
791f420f JR |
6313 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor); |
6314 | #endif | |
6315 | } | |
ee78dc32 | 6316 | |
9ef2e2cf JR |
6317 | |
6318 | /* Take proper action when the mouse has moved to position X, Y on | |
6319 | frame F as regards highlighting characters that have mouse-face | |
6320 | properties. Also de-highlighting chars where the mouse was before. | |
ee78dc32 GV |
6321 | X and Y can be negative or out of range. */ |
6322 | ||
6323 | static void | |
6324 | note_mouse_highlight (f, x, y) | |
9ef2e2cf | 6325 | struct frame *f; |
ee78dc32 GV |
6326 | int x, y; |
6327 | { | |
791f420f JR |
6328 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
6329 | int portion; | |
ee78dc32 GV |
6330 | Lisp_Object window; |
6331 | struct window *w; | |
6332 | ||
791f420f JR |
6333 | /* When a menu is active, don't highlight because this looks odd. */ |
6334 | if (popup_activated ()) | |
6335 | return; | |
6336 | ||
9ef2e2cf JR |
6337 | if (disable_mouse_highlight |
6338 | || !f->glyphs_initialized_p) | |
ee78dc32 GV |
6339 | return; |
6340 | ||
791f420f JR |
6341 | dpyinfo->mouse_face_mouse_x = x; |
6342 | dpyinfo->mouse_face_mouse_y = y; | |
6343 | dpyinfo->mouse_face_mouse_frame = f; | |
ee78dc32 | 6344 | |
791f420f | 6345 | if (dpyinfo->mouse_face_defer) |
ee78dc32 GV |
6346 | return; |
6347 | ||
6348 | if (gc_in_progress) | |
6349 | { | |
791f420f | 6350 | dpyinfo->mouse_face_deferred_gc = 1; |
ee78dc32 GV |
6351 | return; |
6352 | } | |
6353 | ||
ee78dc32 | 6354 | /* Which window is that in? */ |
791f420f | 6355 | window = window_from_coordinates (f, x, y, &portion, 1); |
ee78dc32 GV |
6356 | |
6357 | /* If we were displaying active text in another window, clear that. */ | |
791f420f JR |
6358 | if (! EQ (window, dpyinfo->mouse_face_window)) |
6359 | clear_mouse_face (dpyinfo); | |
6360 | ||
6361 | /* Not on a window -> return. */ | |
6362 | if (!WINDOWP (window)) | |
6363 | return; | |
6364 | ||
6365 | /* Convert to window-relative pixel coordinates. */ | |
6366 | w = XWINDOW (window); | |
6367 | frame_to_window_pixel_xy (w, &x, &y); | |
6368 | ||
6369 | /* Handle tool-bar window differently since it doesn't display a | |
6370 | buffer. */ | |
6371 | if (EQ (window, f->tool_bar_window)) | |
6372 | { | |
6373 | note_tool_bar_highlight (f, x, y); | |
6374 | return; | |
6375 | } | |
6376 | ||
6377 | if (portion == 1 || portion == 3) | |
6378 | { | |
6379 | /* Mouse is on the mode or top line. */ | |
6380 | note_mode_line_highlight (w, x, portion == 1); | |
6381 | return; | |
6382 | } | |
01b220b6 | 6383 | #if 0 /* TODO: mouse cursor */ |
250cfece JR |
6384 | else if (portion == 2) |
6385 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
6386 | f->output_data.x->horizontal_drag_cursor); | |
791f420f JR |
6387 | else |
6388 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
6389 | f->output_data.x->text_cursor); | |
6390 | #endif | |
ee78dc32 GV |
6391 | |
6392 | /* Are we in a window whose display is up to date? | |
6393 | And verify the buffer's text has not changed. */ | |
9ef2e2cf | 6394 | if (/* Within text portion of the window. */ |
791f420f | 6395 | portion == 0 |
ee78dc32 | 6396 | && EQ (w->window_end_valid, w->buffer) |
9ef2e2cf JR |
6397 | && XFASTINT (w->last_modified) == BUF_MODIFF (XBUFFER (w->buffer)) |
6398 | && (XFASTINT (w->last_overlay_modified) | |
6399 | == BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)))) | |
ee78dc32 | 6400 | { |
791f420f JR |
6401 | int hpos, vpos, pos, i, area; |
6402 | struct glyph *glyph; | |
6403 | ||
6404 | /* Find the glyph under X/Y. */ | |
6405 | glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &area); | |
6406 | ||
6407 | /* Clear mouse face if X/Y not over text. */ | |
6408 | if (glyph == NULL | |
6409 | || area != TEXT_AREA | |
6410 | || !MATRIX_ROW (w->current_matrix, vpos)->displays_text_p) | |
6411 | { | |
6412 | clear_mouse_face (dpyinfo); | |
6413 | return; | |
6414 | } | |
6415 | ||
6416 | pos = glyph->charpos; | |
6417 | xassert (w->pseudo_window_p || BUFFERP (glyph->object)); | |
6418 | ||
6419 | /* Check for mouse-face and help-echo. */ | |
6420 | { | |
6421 | Lisp_Object mouse_face, overlay, position; | |
6422 | Lisp_Object *overlay_vec; | |
6423 | int len, noverlays; | |
6424 | struct buffer *obuf; | |
6425 | int obegv, ozv; | |
6426 | ||
6427 | /* If we get an out-of-range value, return now; avoid an error. */ | |
6428 | if (pos > BUF_Z (XBUFFER (w->buffer))) | |
6429 | return; | |
6430 | ||
6431 | /* Make the window's buffer temporarily current for | |
6432 | overlays_at and compute_char_face. */ | |
6433 | obuf = current_buffer; | |
6434 | current_buffer = XBUFFER (w->buffer); | |
6435 | obegv = BEGV; | |
6436 | ozv = ZV; | |
6437 | BEGV = BEG; | |
6438 | ZV = Z; | |
6439 | ||
6440 | /* Is this char mouse-active or does it have help-echo? */ | |
6441 | XSETINT (position, pos); | |
6442 | ||
6443 | /* Put all the overlays we want in a vector in overlay_vec. | |
6444 | Store the length in len. If there are more than 10, make | |
6445 | enough space for all, and try again. */ | |
6446 | len = 10; | |
6447 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
46636545 | 6448 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL, 0); |
791f420f JR |
6449 | if (noverlays > len) |
6450 | { | |
6451 | len = noverlays; | |
6452 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
46636545 | 6453 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL,0); |
791f420f JR |
6454 | } |
6455 | ||
158cba56 | 6456 | /* Sort overlays into increasing priority order. */ |
791f420f JR |
6457 | noverlays = sort_overlays (overlay_vec, noverlays, w); |
6458 | ||
6459 | /* Check mouse-face highlighting. */ | |
6460 | if (! (EQ (window, dpyinfo->mouse_face_window) | |
6461 | && vpos >= dpyinfo->mouse_face_beg_row | |
6462 | && vpos <= dpyinfo->mouse_face_end_row | |
6463 | && (vpos > dpyinfo->mouse_face_beg_row | |
6464 | || hpos >= dpyinfo->mouse_face_beg_col) | |
6465 | && (vpos < dpyinfo->mouse_face_end_row | |
6466 | || hpos < dpyinfo->mouse_face_end_col | |
6467 | || dpyinfo->mouse_face_past_end))) | |
6468 | { | |
6469 | /* Clear the display of the old active region, if any. */ | |
6470 | clear_mouse_face (dpyinfo); | |
6471 | ||
6472 | /* Find the highest priority overlay that has a mouse-face prop. */ | |
6473 | overlay = Qnil; | |
158cba56 | 6474 | for (i = noverlays - 1; i >= 0; --i) |
791f420f JR |
6475 | { |
6476 | mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face); | |
6477 | if (!NILP (mouse_face)) | |
6478 | { | |
6479 | overlay = overlay_vec[i]; | |
6480 | break; | |
6481 | } | |
6482 | } | |
6483 | ||
6484 | /* If no overlay applies, get a text property. */ | |
6485 | if (NILP (overlay)) | |
6486 | mouse_face = Fget_text_property (position, Qmouse_face, w->buffer); | |
6487 | ||
6488 | /* Handle the overlay case. */ | |
6489 | if (! NILP (overlay)) | |
6490 | { | |
6491 | /* Find the range of text around this char that | |
6492 | should be active. */ | |
6493 | Lisp_Object before, after; | |
6494 | int ignore; | |
6495 | ||
6496 | before = Foverlay_start (overlay); | |
6497 | after = Foverlay_end (overlay); | |
6498 | /* Record this as the current active region. */ | |
6499 | fast_find_position (w, XFASTINT (before), | |
6500 | &dpyinfo->mouse_face_beg_col, | |
6501 | &dpyinfo->mouse_face_beg_row, | |
6502 | &dpyinfo->mouse_face_beg_x, | |
6503 | &dpyinfo->mouse_face_beg_y); | |
6504 | dpyinfo->mouse_face_past_end | |
6505 | = !fast_find_position (w, XFASTINT (after), | |
6506 | &dpyinfo->mouse_face_end_col, | |
6507 | &dpyinfo->mouse_face_end_row, | |
6508 | &dpyinfo->mouse_face_end_x, | |
6509 | &dpyinfo->mouse_face_end_y); | |
6510 | dpyinfo->mouse_face_window = window; | |
6511 | dpyinfo->mouse_face_face_id | |
6512 | = face_at_buffer_position (w, pos, 0, 0, | |
6513 | &ignore, pos + 1, 1); | |
6514 | ||
6515 | /* Display it as active. */ | |
6516 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6517 | } | |
6518 | /* Handle the text property case. */ | |
6519 | else if (! NILP (mouse_face)) | |
6520 | { | |
6521 | /* Find the range of text around this char that | |
6522 | should be active. */ | |
6523 | Lisp_Object before, after, beginning, end; | |
6524 | int ignore; | |
6525 | ||
6526 | beginning = Fmarker_position (w->start); | |
6527 | XSETINT (end, (BUF_Z (XBUFFER (w->buffer)) | |
6528 | - XFASTINT (w->window_end_pos))); | |
6529 | before | |
6530 | = Fprevious_single_property_change (make_number (pos + 1), | |
6531 | Qmouse_face, | |
6532 | w->buffer, beginning); | |
6533 | after | |
6534 | = Fnext_single_property_change (position, Qmouse_face, | |
6535 | w->buffer, end); | |
6536 | /* Record this as the current active region. */ | |
6537 | fast_find_position (w, XFASTINT (before), | |
6538 | &dpyinfo->mouse_face_beg_col, | |
6539 | &dpyinfo->mouse_face_beg_row, | |
6540 | &dpyinfo->mouse_face_beg_x, | |
6541 | &dpyinfo->mouse_face_beg_y); | |
6542 | dpyinfo->mouse_face_past_end | |
6543 | = !fast_find_position (w, XFASTINT (after), | |
6544 | &dpyinfo->mouse_face_end_col, | |
6545 | &dpyinfo->mouse_face_end_row, | |
6546 | &dpyinfo->mouse_face_end_x, | |
6547 | &dpyinfo->mouse_face_end_y); | |
6548 | dpyinfo->mouse_face_window = window; | |
6549 | dpyinfo->mouse_face_face_id | |
6550 | = face_at_buffer_position (w, pos, 0, 0, | |
6551 | &ignore, pos + 1, 1); | |
6552 | ||
6553 | /* Display it as active. */ | |
6554 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6555 | } | |
6556 | } | |
6557 | ||
6558 | /* Look for a `help-echo' property. */ | |
6559 | { | |
158cba56 | 6560 | Lisp_Object help, overlay; |
791f420f JR |
6561 | |
6562 | /* Check overlays first. */ | |
6563 | help = Qnil; | |
158cba56 JR |
6564 | for (i = noverlays - 1; i >= 0 && NILP (help); --i) |
6565 | { | |
6566 | overlay = overlay_vec[i]; | |
6567 | help = Foverlay_get (overlay, Qhelp_echo); | |
6568 | } | |
ec48c3a7 JR |
6569 | |
6570 | if (!NILP (help)) | |
6571 | { | |
6572 | help_echo = help; | |
158cba56 JR |
6573 | help_echo_window = window; |
6574 | help_echo_object = overlay; | |
ec48c3a7 JR |
6575 | help_echo_pos = pos; |
6576 | } | |
6577 | else | |
6578 | { | |
6579 | /* Try text properties. */ | |
6580 | if ((STRINGP (glyph->object) | |
791f420f JR |
6581 | && glyph->charpos >= 0 |
6582 | && glyph->charpos < XSTRING (glyph->object)->size) | |
6583 | || (BUFFERP (glyph->object) | |
6584 | && glyph->charpos >= BEGV | |
ec48c3a7 JR |
6585 | && glyph->charpos < ZV)) |
6586 | help = Fget_text_property (make_number (glyph->charpos), | |
6587 | Qhelp_echo, glyph->object); | |
791f420f | 6588 | |
ec48c3a7 JR |
6589 | if (!NILP (help)) |
6590 | { | |
6591 | help_echo = help; | |
158cba56 | 6592 | help_echo_window = window; |
ec48c3a7 JR |
6593 | help_echo_object = glyph->object; |
6594 | help_echo_pos = glyph->charpos; | |
6595 | } | |
6596 | } | |
791f420f JR |
6597 | } |
6598 | ||
6599 | BEGV = obegv; | |
6600 | ZV = ozv; | |
6601 | current_buffer = obuf; | |
6602 | } | |
6603 | } | |
6604 | } | |
6605 | ||
791f420f JR |
6606 | static void |
6607 | redo_mouse_highlight () | |
6608 | { | |
6609 | if (!NILP (last_mouse_motion_frame) | |
6610 | && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) | |
6611 | note_mouse_highlight (XFRAME (last_mouse_motion_frame), | |
6612 | LOWORD (last_mouse_motion_event.lParam), | |
6613 | HIWORD (last_mouse_motion_event.lParam)); | |
6614 | } | |
6615 | ||
6616 | ||
6617 | \f | |
6618 | /*********************************************************************** | |
6619 | Tool-bars | |
6620 | ***********************************************************************/ | |
6621 | ||
6622 | static int x_tool_bar_item P_ ((struct frame *, int, int, | |
6623 | struct glyph **, int *, int *, int *)); | |
6624 | ||
6625 | /* Tool-bar item index of the item on which a mouse button was pressed | |
6626 | or -1. */ | |
6627 | ||
6628 | static int last_tool_bar_item; | |
6629 | ||
6630 | ||
6631 | /* Get information about the tool-bar item at position X/Y on frame F. | |
6632 | Return in *GLYPH a pointer to the glyph of the tool-bar item in | |
6633 | the current matrix of the tool-bar window of F, or NULL if not | |
6634 | on a tool-bar item. Return in *PROP_IDX the index of the tool-bar | |
d417b5e0 | 6635 | item in F->tool_bar_items. Value is |
791f420f JR |
6636 | |
6637 | -1 if X/Y is not on a tool-bar item | |
6638 | 0 if X/Y is on the same item that was highlighted before. | |
6639 | 1 otherwise. */ | |
6640 | ||
6641 | static int | |
6642 | x_tool_bar_item (f, x, y, glyph, hpos, vpos, prop_idx) | |
6643 | struct frame *f; | |
6644 | int x, y; | |
6645 | struct glyph **glyph; | |
6646 | int *hpos, *vpos, *prop_idx; | |
6647 | { | |
6648 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6649 | struct window *w = XWINDOW (f->tool_bar_window); | |
6650 | int area; | |
6651 | ||
6652 | /* Find the glyph under X/Y. */ | |
6653 | *glyph = x_y_to_hpos_vpos (w, x, y, hpos, vpos, &area); | |
6654 | if (*glyph == NULL) | |
6655 | return -1; | |
6656 | ||
6657 | /* Get the start of this tool-bar item's properties in | |
d417b5e0 | 6658 | f->tool_bar_items. */ |
791f420f JR |
6659 | if (!tool_bar_item_info (f, *glyph, prop_idx)) |
6660 | return -1; | |
6661 | ||
6662 | /* Is mouse on the highlighted item? */ | |
6663 | if (EQ (f->tool_bar_window, dpyinfo->mouse_face_window) | |
6664 | && *vpos >= dpyinfo->mouse_face_beg_row | |
6665 | && *vpos <= dpyinfo->mouse_face_end_row | |
6666 | && (*vpos > dpyinfo->mouse_face_beg_row | |
6667 | || *hpos >= dpyinfo->mouse_face_beg_col) | |
6668 | && (*vpos < dpyinfo->mouse_face_end_row | |
6669 | || *hpos < dpyinfo->mouse_face_end_col | |
6670 | || dpyinfo->mouse_face_past_end)) | |
6671 | return 0; | |
6672 | ||
6673 | return 1; | |
6674 | } | |
6675 | ||
6676 | ||
9ef2e2cf | 6677 | /* Handle mouse button event on the tool-bar of frame F, at |
791f420f JR |
6678 | frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress |
6679 | or ButtonRelase. */ | |
6680 | ||
6681 | static void | |
6682 | w32_handle_tool_bar_click (f, button_event) | |
6683 | struct frame *f; | |
6684 | struct input_event *button_event; | |
6685 | { | |
6686 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6687 | struct window *w = XWINDOW (f->tool_bar_window); | |
6688 | int hpos, vpos, prop_idx; | |
6689 | struct glyph *glyph; | |
6690 | Lisp_Object enabled_p; | |
6691 | int x = XFASTINT (button_event->x); | |
6692 | int y = XFASTINT (button_event->y); | |
6693 | ||
6694 | /* If not on the highlighted tool-bar item, return. */ | |
6695 | frame_to_window_pixel_xy (w, &x, &y); | |
6696 | if (x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx) != 0) | |
6697 | return; | |
6698 | ||
6699 | /* If item is disabled, do nothing. */ | |
d417b5e0 | 6700 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
791f420f JR |
6701 | if (NILP (enabled_p)) |
6702 | return; | |
6703 | ||
6704 | if (button_event->kind == mouse_click) | |
6705 | { | |
6706 | /* Show item in pressed state. */ | |
6707 | show_mouse_face (dpyinfo, DRAW_IMAGE_SUNKEN); | |
6708 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_SUNKEN; | |
6709 | last_tool_bar_item = prop_idx; | |
6710 | } | |
6711 | else | |
6712 | { | |
6713 | Lisp_Object key, frame; | |
6714 | struct input_event event; | |
6715 | ||
6716 | /* Show item in released state. */ | |
6717 | show_mouse_face (dpyinfo, DRAW_IMAGE_RAISED); | |
6718 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_RAISED; | |
6719 | ||
d417b5e0 | 6720 | key = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_KEY); |
791f420f JR |
6721 | |
6722 | XSETFRAME (frame, f); | |
6723 | event.kind = TOOL_BAR_EVENT; | |
c8b33aa6 GM |
6724 | event.frame_or_window = frame; |
6725 | event.arg = frame; | |
791f420f JR |
6726 | kbd_buffer_store_event (&event); |
6727 | ||
6728 | event.kind = TOOL_BAR_EVENT; | |
c8b33aa6 GM |
6729 | event.frame_or_window = frame; |
6730 | event.arg = key; | |
791f420f JR |
6731 | event.modifiers = button_event->modifiers; |
6732 | kbd_buffer_store_event (&event); | |
6733 | last_tool_bar_item = -1; | |
6734 | } | |
6735 | } | |
6736 | ||
6737 | ||
9ef2e2cf | 6738 | /* Possibly highlight a tool-bar item on frame F when mouse moves to |
791f420f JR |
6739 | tool-bar window-relative coordinates X/Y. Called from |
6740 | note_mouse_highlight. */ | |
6741 | ||
6742 | static void | |
6743 | note_tool_bar_highlight (f, x, y) | |
6744 | struct frame *f; | |
6745 | int x, y; | |
6746 | { | |
6747 | Lisp_Object window = f->tool_bar_window; | |
6748 | struct window *w = XWINDOW (window); | |
6749 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6750 | int hpos, vpos; | |
6751 | struct glyph *glyph; | |
6752 | struct glyph_row *row; | |
6753 | int i; | |
6754 | Lisp_Object enabled_p; | |
6755 | int prop_idx; | |
6756 | enum draw_glyphs_face draw = DRAW_IMAGE_RAISED; | |
6757 | int mouse_down_p, rc; | |
6758 | ||
6759 | /* Function note_mouse_highlight is called with negative x(y | |
6760 | values when mouse moves outside of the frame. */ | |
6761 | if (x <= 0 || y <= 0) | |
6762 | { | |
6763 | clear_mouse_face (dpyinfo); | |
6764 | return; | |
6765 | } | |
6766 | ||
6767 | rc = x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx); | |
6768 | if (rc < 0) | |
6769 | { | |
6770 | /* Not on tool-bar item. */ | |
6771 | clear_mouse_face (dpyinfo); | |
6772 | return; | |
6773 | } | |
6774 | else if (rc == 0) | |
6775 | /* On same tool-bar item as before. */ | |
6776 | goto set_help_echo; | |
ee78dc32 | 6777 | |
791f420f JR |
6778 | clear_mouse_face (dpyinfo); |
6779 | ||
6780 | /* Mouse is down, but on different tool-bar item? */ | |
6781 | mouse_down_p = (dpyinfo->grabbed | |
6782 | && f == last_mouse_frame | |
6783 | && FRAME_LIVE_P (f)); | |
6784 | if (mouse_down_p | |
6785 | && last_tool_bar_item != prop_idx) | |
6786 | return; | |
ee78dc32 | 6787 | |
791f420f JR |
6788 | dpyinfo->mouse_face_image_state = DRAW_NORMAL_TEXT; |
6789 | draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED; | |
6790 | ||
6791 | /* If tool-bar item is not enabled, don't highlight it. */ | |
d417b5e0 | 6792 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
791f420f JR |
6793 | if (!NILP (enabled_p)) |
6794 | { | |
6795 | /* Compute the x-position of the glyph. In front and past the | |
6796 | image is a space. We include this is the highlighted area. */ | |
6797 | row = MATRIX_ROW (w->current_matrix, vpos); | |
6798 | for (i = x = 0; i < hpos; ++i) | |
6799 | x += row->glyphs[TEXT_AREA][i].pixel_width; | |
6800 | ||
6801 | /* Record this as the current active region. */ | |
6802 | dpyinfo->mouse_face_beg_col = hpos; | |
6803 | dpyinfo->mouse_face_beg_row = vpos; | |
6804 | dpyinfo->mouse_face_beg_x = x; | |
6805 | dpyinfo->mouse_face_beg_y = row->y; | |
6806 | dpyinfo->mouse_face_past_end = 0; | |
6807 | ||
6808 | dpyinfo->mouse_face_end_col = hpos + 1; | |
6809 | dpyinfo->mouse_face_end_row = vpos; | |
6810 | dpyinfo->mouse_face_end_x = x + glyph->pixel_width; | |
6811 | dpyinfo->mouse_face_end_y = row->y; | |
6812 | dpyinfo->mouse_face_window = window; | |
6813 | dpyinfo->mouse_face_face_id = TOOL_BAR_FACE_ID; | |
6814 | ||
6815 | /* Display it as active. */ | |
6816 | show_mouse_face (dpyinfo, draw); | |
6817 | dpyinfo->mouse_face_image_state = draw; | |
ee78dc32 | 6818 | } |
791f420f JR |
6819 | |
6820 | set_help_echo: | |
6821 | ||
6822 | /* Set help_echo to a help string.to display for this tool-bar item. | |
6823 | w32_read_socket does the rest. */ | |
158cba56 | 6824 | help_echo_object = help_echo_window = Qnil; |
ec48c3a7 | 6825 | help_echo_pos = -1; |
d417b5e0 | 6826 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_HELP); |
b7e80413 | 6827 | if (NILP (help_echo)) |
d417b5e0 | 6828 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_CAPTION); |
ee78dc32 | 6829 | } |
ee78dc32 | 6830 | |
9ef2e2cf | 6831 | |
791f420f JR |
6832 | \f |
6833 | /* Find the glyph matrix position of buffer position POS in window W. | |
6834 | *HPOS, *VPOS, *X, and *Y are set to the positions found. W's | |
6835 | current glyphs must be up to date. If POS is above window start | |
6836 | return (0, 0, 0, 0). If POS is after end of W, return end of | |
6837 | last line in W. */ | |
ee78dc32 GV |
6838 | |
6839 | static int | |
791f420f JR |
6840 | fast_find_position (w, pos, hpos, vpos, x, y) |
6841 | struct window *w; | |
ee78dc32 | 6842 | int pos; |
791f420f | 6843 | int *hpos, *vpos, *x, *y; |
ee78dc32 | 6844 | { |
ee78dc32 | 6845 | int i; |
ee78dc32 | 6846 | int lastcol; |
791f420f JR |
6847 | int maybe_next_line_p = 0; |
6848 | int line_start_position; | |
6849 | int yb = window_text_bottom_y (w); | |
6850 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, 0); | |
6851 | struct glyph_row *best_row = row; | |
6852 | int row_vpos = 0, best_row_vpos = 0; | |
6853 | int current_x; | |
6854 | ||
6855 | while (row->y < yb) | |
ee78dc32 | 6856 | { |
791f420f JR |
6857 | if (row->used[TEXT_AREA]) |
6858 | line_start_position = row->glyphs[TEXT_AREA]->charpos; | |
6859 | else | |
6860 | line_start_position = 0; | |
6861 | ||
6862 | if (line_start_position > pos) | |
ee78dc32 GV |
6863 | break; |
6864 | /* If the position sought is the end of the buffer, | |
6865 | don't include the blank lines at the bottom of the window. */ | |
791f420f JR |
6866 | else if (line_start_position == pos |
6867 | && pos == BUF_ZV (XBUFFER (w->buffer))) | |
ee78dc32 | 6868 | { |
791f420f | 6869 | maybe_next_line_p = 1; |
ee78dc32 GV |
6870 | break; |
6871 | } | |
791f420f JR |
6872 | else if (line_start_position > 0) |
6873 | { | |
6874 | best_row = row; | |
6875 | best_row_vpos = row_vpos; | |
6876 | } | |
6877 | ||
9ef2e2cf JR |
6878 | if (row->y + row->height >= yb) |
6879 | break; | |
6880 | ||
791f420f JR |
6881 | ++row; |
6882 | ++row_vpos; | |
ee78dc32 GV |
6883 | } |
6884 | ||
791f420f JR |
6885 | /* Find the right column within BEST_ROW. */ |
6886 | lastcol = 0; | |
6887 | current_x = best_row->x; | |
6888 | for (i = 0; i < best_row->used[TEXT_AREA]; i++) | |
ee78dc32 | 6889 | { |
791f420f JR |
6890 | struct glyph *glyph = best_row->glyphs[TEXT_AREA] + i; |
6891 | int charpos; | |
6892 | ||
6893 | charpos = glyph->charpos; | |
6894 | if (charpos == pos) | |
ee78dc32 | 6895 | { |
791f420f JR |
6896 | *hpos = i; |
6897 | *vpos = best_row_vpos; | |
6898 | *x = current_x; | |
6899 | *y = best_row->y; | |
ee78dc32 GV |
6900 | return 1; |
6901 | } | |
791f420f | 6902 | else if (charpos > pos) |
ee78dc32 | 6903 | break; |
791f420f JR |
6904 | else if (charpos > 0) |
6905 | lastcol = i; | |
6906 | ||
6907 | current_x += glyph->pixel_width; | |
ee78dc32 GV |
6908 | } |
6909 | ||
6910 | /* If we're looking for the end of the buffer, | |
6911 | and we didn't find it in the line we scanned, | |
6912 | use the start of the following line. */ | |
791f420f | 6913 | if (maybe_next_line_p) |
ee78dc32 | 6914 | { |
791f420f JR |
6915 | ++best_row; |
6916 | ++best_row_vpos; | |
6917 | lastcol = 0; | |
6918 | current_x = best_row->x; | |
ee78dc32 GV |
6919 | } |
6920 | ||
791f420f JR |
6921 | *vpos = best_row_vpos; |
6922 | *hpos = lastcol + 1; | |
6923 | *x = current_x; | |
6924 | *y = best_row->y; | |
ee78dc32 GV |
6925 | return 0; |
6926 | } | |
6927 | ||
791f420f | 6928 | |
ee78dc32 GV |
6929 | /* Display the active region described by mouse_face_* |
6930 | in its mouse-face if HL > 0, in its normal face if HL = 0. */ | |
6931 | ||
6932 | static void | |
791f420f | 6933 | show_mouse_face (dpyinfo, draw) |
fbd6baed | 6934 | struct w32_display_info *dpyinfo; |
791f420f | 6935 | enum draw_glyphs_face draw; |
ee78dc32 GV |
6936 | { |
6937 | struct window *w = XWINDOW (dpyinfo->mouse_face_window); | |
791f420f | 6938 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
ee78dc32 | 6939 | int i; |
791f420f JR |
6940 | int cursor_off_p = 0; |
6941 | struct cursor_pos saved_cursor; | |
6942 | ||
6943 | saved_cursor = output_cursor; | |
6944 | ||
6945 | /* If window is in the process of being destroyed, don't bother | |
6946 | to do anything. */ | |
6947 | if (w->current_matrix == NULL) | |
6948 | goto set_x_cursor; | |
6949 | ||
6950 | /* Recognize when we are called to operate on rows that don't exist | |
6951 | anymore. This can happen when a window is split. */ | |
6952 | if (dpyinfo->mouse_face_end_row >= w->current_matrix->nrows) | |
6953 | goto set_x_cursor; | |
6954 | ||
6955 | set_output_cursor (&w->phys_cursor); | |
6956 | ||
6957 | /* Note that mouse_face_beg_row etc. are window relative. */ | |
6958 | for (i = dpyinfo->mouse_face_beg_row; | |
6959 | i <= dpyinfo->mouse_face_end_row; | |
6960 | i++) | |
6961 | { | |
6962 | int start_hpos, end_hpos, start_x; | |
6963 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, i); | |
6964 | ||
6965 | /* Don't do anything if row doesn't have valid contents. */ | |
6966 | if (!row->enabled_p) | |
6967 | continue; | |
6968 | ||
6969 | /* For all but the first row, the highlight starts at column 0. */ | |
6970 | if (i == dpyinfo->mouse_face_beg_row) | |
6971 | { | |
6972 | start_hpos = dpyinfo->mouse_face_beg_col; | |
6973 | start_x = dpyinfo->mouse_face_beg_x; | |
6974 | } | |
6975 | else | |
6976 | { | |
6977 | start_hpos = 0; | |
6978 | start_x = 0; | |
6979 | } | |
6980 | ||
6981 | if (i == dpyinfo->mouse_face_end_row) | |
6982 | end_hpos = dpyinfo->mouse_face_end_col; | |
6983 | else | |
6984 | end_hpos = row->used[TEXT_AREA]; | |
6985 | ||
6986 | /* If the cursor's in the text we are about to rewrite, turn the | |
6987 | cursor off. */ | |
6988 | if (!w->pseudo_window_p | |
6989 | && i == output_cursor.vpos | |
6990 | && output_cursor.hpos >= start_hpos - 1 | |
6991 | && output_cursor.hpos <= end_hpos) | |
ee78dc32 | 6992 | { |
791f420f JR |
6993 | x_update_window_cursor (w, 0); |
6994 | cursor_off_p = 1; | |
ee78dc32 GV |
6995 | } |
6996 | ||
791f420f | 6997 | if (end_hpos > start_hpos) |
ec48c3a7 JR |
6998 | { |
6999 | row->mouse_face_p = draw == DRAW_MOUSE_FACE; | |
7000 | x_draw_glyphs (w, start_x, row, TEXT_AREA, | |
7001 | start_hpos, end_hpos, draw, NULL, NULL, 0); | |
7002 | } | |
ee78dc32 GV |
7003 | } |
7004 | ||
7005 | /* If we turned the cursor off, turn it back on. */ | |
791f420f JR |
7006 | if (cursor_off_p) |
7007 | x_display_cursor (w, 1, | |
7008 | output_cursor.hpos, output_cursor.vpos, | |
7009 | output_cursor.x, output_cursor.y); | |
7010 | ||
7011 | output_cursor = saved_cursor; | |
7012 | ||
7013 | set_x_cursor: | |
01b220b6 | 7014 | #if 0 /* TODO: mouse cursor */ |
791f420f JR |
7015 | /* Change the mouse cursor. */ |
7016 | if (draw == DRAW_NORMAL_TEXT) | |
7017 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7018 | f->output_data.x->text_cursor); | |
7019 | else if (draw == DRAW_MOUSE_FACE) | |
7020 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7021 | f->output_data.x->cross_cursor); | |
ee78dc32 | 7022 | else |
791f420f JR |
7023 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7024 | f->output_data.x->nontext_cursor); | |
7025 | #endif | |
7026 | ; | |
ee78dc32 GV |
7027 | } |
7028 | ||
7029 | /* Clear out the mouse-highlighted active region. | |
9ef2e2cf | 7030 | Redraw it un-highlighted first. */ |
ee78dc32 | 7031 | |
791f420f | 7032 | void |
ee78dc32 | 7033 | clear_mouse_face (dpyinfo) |
fbd6baed | 7034 | struct w32_display_info *dpyinfo; |
ee78dc32 | 7035 | { |
791f420f JR |
7036 | if (tip_frame) |
7037 | return; | |
7038 | ||
ee78dc32 | 7039 | if (! NILP (dpyinfo->mouse_face_window)) |
791f420f | 7040 | show_mouse_face (dpyinfo, DRAW_NORMAL_TEXT); |
ee78dc32 GV |
7041 | |
7042 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7043 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7044 | dpyinfo->mouse_face_window = Qnil; | |
7045 | } | |
31d4844a | 7046 | |
ec48c3a7 JR |
7047 | |
7048 | /* Clear any mouse-face on window W. This function is part of the | |
7049 | redisplay interface, and is called from try_window_id and similar | |
7050 | functions to ensure the mouse-highlight is off. */ | |
7051 | ||
7052 | static void | |
7053 | x_clear_mouse_face (w) | |
7054 | struct window *w; | |
7055 | { | |
7056 | struct w32_display_info *dpyinfo | |
7057 | = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); | |
7058 | Lisp_Object window; | |
7059 | ||
9127e20e | 7060 | BLOCK_INPUT; |
ec48c3a7 JR |
7061 | XSETWINDOW (window, w); |
7062 | if (EQ (window, dpyinfo->mouse_face_window)) | |
7063 | clear_mouse_face (dpyinfo); | |
9127e20e | 7064 | UNBLOCK_INPUT; |
ec48c3a7 JR |
7065 | } |
7066 | ||
7067 | ||
31d4844a KH |
7068 | /* Just discard the mouse face information for frame F, if any. |
7069 | This is used when the size of F is changed. */ | |
7070 | ||
7071 | void | |
7072 | cancel_mouse_face (f) | |
7073 | FRAME_PTR f; | |
7074 | { | |
7075 | Lisp_Object window; | |
7076 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
7077 | ||
7078 | window = dpyinfo->mouse_face_window; | |
7079 | if (! NILP (window) && XFRAME (XWINDOW (window)->frame) == f) | |
7080 | { | |
7081 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7082 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7083 | dpyinfo->mouse_face_window = Qnil; | |
7084 | } | |
7085 | } | |
ee78dc32 | 7086 | \f |
9ef2e2cf | 7087 | static struct scroll_bar *x_window_to_scroll_bar (); |
ee78dc32 GV |
7088 | static void x_scroll_bar_report_motion (); |
7089 | ||
7090 | /* Return the current position of the mouse. | |
7091 | *fp should be a frame which indicates which display to ask about. | |
7092 | ||
7093 | If the mouse movement started in a scroll bar, set *fp, *bar_window, | |
7094 | and *part to the frame, window, and scroll bar part that the mouse | |
7095 | is over. Set *x and *y to the portion and whole of the mouse's | |
7096 | position on the scroll bar. | |
7097 | ||
7098 | If the mouse movement started elsewhere, set *fp to the frame the | |
7099 | mouse is on, *bar_window to nil, and *x and *y to the character cell | |
7100 | the mouse is over. | |
7101 | ||
9ef2e2cf | 7102 | Set *time to the server time-stamp for the time at which the mouse |
ee78dc32 GV |
7103 | was at this position. |
7104 | ||
7105 | Don't store anything if we don't have a valid set of values to report. | |
7106 | ||
7107 | This clears the mouse_moved flag, so we can wait for the next mouse | |
9ef2e2cf | 7108 | movement. */ |
ee78dc32 GV |
7109 | |
7110 | static void | |
fbd6baed | 7111 | w32_mouse_position (fp, insist, bar_window, part, x, y, time) |
ee78dc32 GV |
7112 | FRAME_PTR *fp; |
7113 | int insist; | |
7114 | Lisp_Object *bar_window; | |
7115 | enum scroll_bar_part *part; | |
7116 | Lisp_Object *x, *y; | |
7117 | unsigned long *time; | |
7118 | { | |
7119 | FRAME_PTR f1; | |
7120 | ||
7121 | BLOCK_INPUT; | |
7122 | ||
95fa970d | 7123 | if (! NILP (last_mouse_scroll_bar) && insist == 0) |
ee78dc32 GV |
7124 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); |
7125 | else | |
7126 | { | |
7127 | POINT pt; | |
7128 | ||
7129 | Lisp_Object frame, tail; | |
7130 | ||
7131 | /* Clear the mouse-moved flag for every frame on this display. */ | |
7132 | FOR_EACH_FRAME (tail, frame) | |
7133 | XFRAME (frame)->mouse_moved = 0; | |
7134 | ||
7135 | last_mouse_scroll_bar = Qnil; | |
7136 | ||
7137 | GetCursorPos (&pt); | |
7138 | ||
7139 | /* Now we have a position on the root; find the innermost window | |
7140 | containing the pointer. */ | |
7141 | { | |
fbd6baed | 7142 | if (FRAME_W32_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame |
ee78dc32 GV |
7143 | && FRAME_LIVE_P (last_mouse_frame)) |
7144 | { | |
08712a41 AI |
7145 | /* If mouse was grabbed on a frame, give coords for that frame |
7146 | even if the mouse is now outside it. */ | |
ee78dc32 GV |
7147 | f1 = last_mouse_frame; |
7148 | } | |
7149 | else | |
7150 | { | |
08712a41 | 7151 | /* Is window under mouse one of our frames? */ |
9127e20e JR |
7152 | f1 = x_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp), |
7153 | WindowFromPoint (pt)); | |
ee78dc32 GV |
7154 | } |
7155 | ||
7156 | /* If not, is it one of our scroll bars? */ | |
7157 | if (! f1) | |
7158 | { | |
9127e20e JR |
7159 | struct scroll_bar *bar |
7160 | = x_window_to_scroll_bar (WindowFromPoint (pt)); | |
ee78dc32 GV |
7161 | |
7162 | if (bar) | |
7163 | { | |
7164 | f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
7165 | } | |
7166 | } | |
7167 | ||
95fa970d | 7168 | if (f1 == 0 && insist > 0) |
791f420f | 7169 | f1 = SELECTED_FRAME (); |
ee78dc32 GV |
7170 | |
7171 | if (f1) | |
7172 | { | |
791f420f JR |
7173 | /* Ok, we found a frame. Store all the values. |
7174 | last_mouse_glyph is a rectangle used to reduce the | |
7175 | generation of mouse events. To not miss any motion | |
7176 | events, we must divide the frame into rectangles of the | |
7177 | size of the smallest character that could be displayed | |
7178 | on it, i.e. into the same rectangles that matrices on | |
7179 | the frame are divided into. */ | |
7180 | ||
7181 | #if OLD_REDISPLAY_CODE | |
ee78dc32 GV |
7182 | int ignore1, ignore2; |
7183 | ||
fbd6baed | 7184 | ScreenToClient (FRAME_W32_WINDOW (f1), &pt); |
ee78dc32 | 7185 | |
ee78dc32 GV |
7186 | pixel_to_glyph_coords (f1, pt.x, pt.y, &ignore1, &ignore2, |
7187 | &last_mouse_glyph, | |
fbd6baed | 7188 | FRAME_W32_DISPLAY_INFO (f1)->grabbed |
ee78dc32 | 7189 | || insist); |
791f420f JR |
7190 | #else |
7191 | ScreenToClient (FRAME_W32_WINDOW (f1), &pt); | |
7192 | { | |
7193 | int width = FRAME_SMALLEST_CHAR_WIDTH (f1); | |
7194 | int height = FRAME_SMALLEST_FONT_HEIGHT (f1); | |
7195 | int x = pt.x; | |
7196 | int y = pt.y; | |
7197 | ||
7198 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to | |
7199 | round down even for negative values. */ | |
7200 | if (x < 0) | |
7201 | x -= width - 1; | |
7202 | if (y < 0) | |
7203 | y -= height - 1; | |
7204 | ||
7205 | last_mouse_glyph.left = (x + width - 1) / width * width; | |
7206 | last_mouse_glyph.top = (y + height - 1) / height * height; | |
7207 | last_mouse_glyph.right = last_mouse_glyph.left + width; | |
7208 | last_mouse_glyph.bottom = last_mouse_glyph.top + height; | |
7209 | } | |
7210 | #endif | |
ee78dc32 GV |
7211 | |
7212 | *bar_window = Qnil; | |
7213 | *part = 0; | |
7214 | *fp = f1; | |
7215 | XSETINT (*x, pt.x); | |
7216 | XSETINT (*y, pt.y); | |
7217 | *time = last_mouse_movement_time; | |
7218 | } | |
7219 | } | |
7220 | } | |
7221 | ||
7222 | UNBLOCK_INPUT; | |
7223 | } | |
791f420f | 7224 | |
ee78dc32 GV |
7225 | \f |
7226 | /* Scroll bar support. */ | |
7227 | ||
ec48c3a7 | 7228 | /* Given a window ID, find the struct scroll_bar which manages it. |
ee78dc32 GV |
7229 | This can be called in GC, so we have to make sure to strip off mark |
7230 | bits. */ | |
9ef2e2cf JR |
7231 | |
7232 | static struct scroll_bar * | |
ee78dc32 GV |
7233 | x_window_to_scroll_bar (window_id) |
7234 | Window window_id; | |
7235 | { | |
791f420f | 7236 | Lisp_Object tail; |
ee78dc32 GV |
7237 | |
7238 | for (tail = Vframe_list; | |
7239 | XGCTYPE (tail) == Lisp_Cons; | |
8e713be6 | 7240 | tail = XCDR (tail)) |
ee78dc32 GV |
7241 | { |
7242 | Lisp_Object frame, bar, condemned; | |
7243 | ||
8e713be6 | 7244 | frame = XCAR (tail); |
ee78dc32 GV |
7245 | /* All elements of Vframe_list should be frames. */ |
7246 | if (! GC_FRAMEP (frame)) | |
7247 | abort (); | |
7248 | ||
7249 | /* Scan this frame's scroll bar list for a scroll bar with the | |
7250 | right window ID. */ | |
7251 | condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); | |
7252 | for (bar = FRAME_SCROLL_BARS (XFRAME (frame)); | |
7253 | /* This trick allows us to search both the ordinary and | |
7254 | condemned scroll bar lists with one loop. */ | |
7255 | ! GC_NILP (bar) || (bar = condemned, | |
7256 | condemned = Qnil, | |
7257 | ! GC_NILP (bar)); | |
7258 | bar = XSCROLL_BAR (bar)->next) | |
fbd6baed | 7259 | if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)) == window_id) |
ee78dc32 GV |
7260 | return XSCROLL_BAR (bar); |
7261 | } | |
7262 | ||
7263 | return 0; | |
7264 | } | |
7265 | ||
791f420f JR |
7266 | |
7267 | \f | |
7268 | /* Set the thumb size and position of scroll bar BAR. We are currently | |
7269 | displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
7270 | ||
7271 | static void | |
7272 | w32_set_scroll_bar_thumb (bar, portion, position, whole) | |
7273 | struct scroll_bar *bar; | |
7274 | int portion, position, whole; | |
7275 | { | |
7276 | Window w = SCROLL_BAR_W32_WINDOW (bar); | |
7277 | int range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | |
7278 | int sb_page, sb_pos; | |
7279 | BOOL draggingp = !NILP (bar->dragging) ? TRUE : FALSE; | |
7280 | ||
7281 | if (whole) | |
7282 | { | |
7283 | /* Position scroll bar at rock bottom if the bottom of the | |
7284 | buffer is visible. This avoids shinking the thumb away | |
7285 | to nothing if it is held at the bottom of the buffer. */ | |
7286 | if (position + portion >= whole) | |
7287 | { | |
7288 | sb_page = range * (whole - position) / whole | |
7289 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
7290 | sb_pos = range; | |
7291 | } | |
7292 | ||
7293 | sb_page = portion * range / whole + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
7294 | sb_pos = position * range / whole; | |
7295 | } | |
7296 | else | |
7297 | { | |
7298 | sb_page = range; | |
7299 | sb_pos = 0; | |
7300 | } | |
7301 | ||
7302 | BLOCK_INPUT; | |
7303 | ||
7304 | if (pfnSetScrollInfo) | |
7305 | { | |
7306 | SCROLLINFO si; | |
7307 | ||
7308 | si.cbSize = sizeof (si); | |
7309 | /* Only update page size if currently dragging, to reduce | |
7310 | flicker effects. */ | |
7311 | if (draggingp) | |
7312 | si.fMask = SIF_PAGE; | |
7313 | else | |
7314 | si.fMask = SIF_PAGE | SIF_POS; | |
7315 | si.nPage = sb_page; | |
7316 | si.nPos = sb_pos; | |
7317 | ||
7318 | pfnSetScrollInfo (w, SB_CTL, &si, !draggingp); | |
7319 | } | |
7320 | else | |
7321 | SetScrollPos (w, SB_CTL, sb_pos, !draggingp); | |
7322 | ||
7323 | UNBLOCK_INPUT; | |
7324 | } | |
7325 | ||
7326 | \f | |
7327 | /************************************************************************ | |
7328 | Scroll bars, general | |
7329 | ************************************************************************/ | |
7330 | ||
ee78dc32 GV |
7331 | HWND |
7332 | my_create_scrollbar (f, bar) | |
7333 | struct frame * f; | |
7334 | struct scroll_bar * bar; | |
7335 | { | |
689004fa GV |
7336 | return (HWND) SendMessage (FRAME_W32_WINDOW (f), |
7337 | WM_EMACS_CREATESCROLLBAR, (WPARAM) f, | |
7338 | (LPARAM) bar); | |
ee78dc32 GV |
7339 | } |
7340 | ||
52cf03a1 GV |
7341 | //#define ATTACH_THREADS |
7342 | ||
689004fa GV |
7343 | BOOL |
7344 | my_show_window (FRAME_PTR f, HWND hwnd, int how) | |
52cf03a1 GV |
7345 | { |
7346 | #ifndef ATTACH_THREADS | |
689004fa GV |
7347 | return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW, |
7348 | (WPARAM) hwnd, (LPARAM) how); | |
52cf03a1 | 7349 | #else |
689004fa | 7350 | return ShowWindow (hwnd, how); |
52cf03a1 GV |
7351 | #endif |
7352 | } | |
7353 | ||
7354 | void | |
7355 | my_set_window_pos (HWND hwnd, HWND hwndAfter, | |
689004fa | 7356 | int x, int y, int cx, int cy, UINT flags) |
52cf03a1 GV |
7357 | { |
7358 | #ifndef ATTACH_THREADS | |
689004fa GV |
7359 | WINDOWPOS pos; |
7360 | pos.hwndInsertAfter = hwndAfter; | |
52cf03a1 GV |
7361 | pos.x = x; |
7362 | pos.y = y; | |
7363 | pos.cx = cx; | |
7364 | pos.cy = cy; | |
7365 | pos.flags = flags; | |
7366 | SendMessage (hwnd, WM_EMACS_SETWINDOWPOS, (WPARAM) &pos, 0); | |
7367 | #else | |
7368 | SetWindowPos (hwnd, hwndAfter, x, y, cx, cy, flags); | |
7369 | #endif | |
7370 | } | |
7371 | ||
ec48c3a7 | 7372 | void |
689004fa GV |
7373 | my_set_focus (f, hwnd) |
7374 | struct frame * f; | |
7375 | HWND hwnd; | |
7376 | { | |
7377 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SETFOCUS, | |
7378 | (WPARAM) hwnd, 0); | |
7379 | } | |
7380 | ||
ec48c3a7 | 7381 | void |
ef0e360f GV |
7382 | my_set_foreground_window (hwnd) |
7383 | HWND hwnd; | |
7384 | { | |
7385 | SendMessage (hwnd, WM_EMACS_SETFOREGROUND, (WPARAM) hwnd, 0); | |
7386 | } | |
7387 | ||
ee78dc32 GV |
7388 | void |
7389 | my_destroy_window (f, hwnd) | |
7390 | struct frame * f; | |
7391 | HWND hwnd; | |
7392 | { | |
fbd6baed | 7393 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_DESTROYWINDOW, |
ee78dc32 GV |
7394 | (WPARAM) hwnd, 0); |
7395 | } | |
7396 | ||
791f420f JR |
7397 | /* Create a scroll bar and return the scroll bar vector for it. W is |
7398 | the Emacs window on which to create the scroll bar. TOP, LEFT, | |
7399 | WIDTH and HEIGHT are.the pixel coordinates and dimensions of the | |
7400 | scroll bar. */ | |
7401 | ||
ee78dc32 | 7402 | static struct scroll_bar * |
791f420f JR |
7403 | x_scroll_bar_create (w, top, left, width, height) |
7404 | struct window *w; | |
ee78dc32 GV |
7405 | int top, left, width, height; |
7406 | { | |
791f420f JR |
7407 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
7408 | HWND hwnd; | |
ee78dc32 GV |
7409 | struct scroll_bar *bar |
7410 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | |
ee78dc32 GV |
7411 | |
7412 | BLOCK_INPUT; | |
7413 | ||
791f420f | 7414 | XSETWINDOW (bar->window, w); |
ee78dc32 GV |
7415 | XSETINT (bar->top, top); |
7416 | XSETINT (bar->left, left); | |
7417 | XSETINT (bar->width, width); | |
7418 | XSETINT (bar->height, height); | |
7419 | XSETINT (bar->start, 0); | |
7420 | XSETINT (bar->end, 0); | |
7421 | bar->dragging = Qnil; | |
7422 | ||
7423 | /* Requires geometry to be set before call to create the real window */ | |
7424 | ||
7425 | hwnd = my_create_scrollbar (f, bar); | |
7426 | ||
689004fa GV |
7427 | if (pfnSetScrollInfo) |
7428 | { | |
7429 | SCROLLINFO si; | |
7430 | ||
7431 | si.cbSize = sizeof (si); | |
7432 | si.fMask = SIF_ALL; | |
7433 | si.nMin = 0; | |
791f420f JR |
7434 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) |
7435 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
689004fa GV |
7436 | si.nPage = si.nMax; |
7437 | si.nPos = 0; | |
7438 | ||
7439 | pfnSetScrollInfo (hwnd, SB_CTL, &si, FALSE); | |
7440 | } | |
7441 | else | |
7442 | { | |
791f420f JR |
7443 | SetScrollRange (hwnd, SB_CTL, 0, |
7444 | VERTICAL_SCROLL_BAR_TOP_RANGE (f, height), FALSE); | |
689004fa GV |
7445 | SetScrollPos (hwnd, SB_CTL, 0, FALSE); |
7446 | } | |
ee78dc32 | 7447 | |
fbd6baed | 7448 | SET_SCROLL_BAR_W32_WINDOW (bar, hwnd); |
ee78dc32 GV |
7449 | |
7450 | /* Add bar to its frame's list of scroll bars. */ | |
7451 | bar->next = FRAME_SCROLL_BARS (f); | |
7452 | bar->prev = Qnil; | |
7453 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
7454 | if (! NILP (bar->next)) | |
7455 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
7456 | ||
7457 | UNBLOCK_INPUT; | |
7458 | ||
7459 | return bar; | |
7460 | } | |
7461 | ||
ee78dc32 | 7462 | |
791f420f JR |
7463 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to |
7464 | nil. */ | |
ee78dc32 | 7465 | |
ee78dc32 GV |
7466 | static void |
7467 | x_scroll_bar_remove (bar) | |
7468 | struct scroll_bar *bar; | |
7469 | { | |
7470 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
7471 | ||
7472 | BLOCK_INPUT; | |
7473 | ||
7474 | /* Destroy the window. */ | |
fbd6baed | 7475 | my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar)); |
ee78dc32 GV |
7476 | |
7477 | /* Disassociate this scroll bar from its window. */ | |
7478 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | |
7479 | ||
7480 | UNBLOCK_INPUT; | |
7481 | } | |
7482 | ||
7483 | /* Set the handle of the vertical scroll bar for WINDOW to indicate | |
7484 | that we are displaying PORTION characters out of a total of WHOLE | |
7485 | characters, starting at POSITION. If WINDOW has no scroll bar, | |
7486 | create one. */ | |
7487 | static void | |
791f420f JR |
7488 | w32_set_vertical_scroll_bar (w, portion, whole, position) |
7489 | struct window *w; | |
ee78dc32 GV |
7490 | int portion, whole, position; |
7491 | { | |
791f420f | 7492 | struct frame *f = XFRAME (w->frame); |
ee78dc32 | 7493 | struct scroll_bar *bar; |
9ef2e2cf | 7494 | int top, height, left, sb_left, width, sb_width; |
791f420f JR |
7495 | int window_x, window_y, window_width, window_height; |
7496 | ||
7497 | /* Get window dimensions. */ | |
7498 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); | |
7499 | top = window_y; | |
7500 | width = FRAME_SCROLL_BAR_COLS (f) * CANON_X_UNIT (f); | |
7501 | height = window_height; | |
7502 | ||
7503 | /* Compute the left edge of the scroll bar area. */ | |
7504 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
7505 | left = XINT (w->left) + XINT (w->width) - FRAME_SCROLL_BAR_COLS (f); | |
7506 | else | |
7507 | left = XFASTINT (w->left); | |
7508 | left *= CANON_X_UNIT (f); | |
7509 | left += FRAME_INTERNAL_BORDER_WIDTH (f); | |
7510 | ||
7511 | /* Compute the width of the scroll bar which might be less than | |
7512 | the width of the area reserved for the scroll bar. */ | |
7513 | if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0) | |
7514 | sb_width = FRAME_SCROLL_BAR_PIXEL_WIDTH (f); | |
7515 | else | |
7516 | sb_width = width; | |
ee78dc32 | 7517 | |
791f420f JR |
7518 | /* Compute the left edge of the scroll bar. */ |
7519 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
7520 | sb_left = left + width - sb_width - (width - sb_width) / 2; | |
ee78dc32 | 7521 | else |
791f420f JR |
7522 | sb_left = left + (width - sb_width) / 2; |
7523 | ||
7524 | /* Does the scroll bar exist yet? */ | |
7525 | if (NILP (w->vertical_scroll_bar)) | |
ee78dc32 | 7526 | { |
00fe468b | 7527 | HDC hdc; |
791f420f | 7528 | BLOCK_INPUT; |
00fe468b JR |
7529 | hdc = get_frame_dc (f); |
7530 | w32_clear_area (f, hdc, left, top, width, height); | |
7531 | release_frame_dc (f, hdc); | |
791f420f | 7532 | UNBLOCK_INPUT; |
00fe468b | 7533 | |
791f420f | 7534 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); |
ee78dc32 | 7535 | } |
791f420f JR |
7536 | else |
7537 | { | |
7538 | /* It may just need to be moved and resized. */ | |
7539 | HWND hwnd; | |
7540 | ||
7541 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | |
7542 | hwnd = SCROLL_BAR_W32_WINDOW (bar); | |
7543 | ||
7544 | /* If already correctly positioned, do nothing. */ | |
7545 | if ( XINT (bar->left) == sb_left | |
7546 | && XINT (bar->top) == top | |
7547 | && XINT (bar->width) == sb_width | |
7548 | && XINT (bar->height) == height ) | |
7549 | { | |
7550 | /* Redraw after clear_frame. */ | |
7551 | if (!my_show_window (f, hwnd, SW_NORMAL)) | |
7552 | InvalidateRect (hwnd, NULL, FALSE); | |
7553 | } | |
7554 | else | |
7555 | { | |
00fe468b | 7556 | HDC hdc; |
791f420f JR |
7557 | BLOCK_INPUT; |
7558 | ||
00fe468b | 7559 | hdc = get_frame_dc (f); |
791f420f JR |
7560 | /* Since Windows scroll bars are smaller than the space reserved |
7561 | for them on the frame, we have to clear "under" them. */ | |
00fe468b | 7562 | w32_clear_area (f, hdc, |
791f420f JR |
7563 | left, |
7564 | top, | |
7565 | width, | |
7566 | height); | |
00fe468b | 7567 | release_frame_dc (f, hdc); |
791f420f JR |
7568 | |
7569 | /* Make sure scroll bar is "visible" before moving, to ensure the | |
7570 | area of the parent window now exposed will be refreshed. */ | |
7571 | my_show_window (f, hwnd, SW_HIDE); | |
7572 | MoveWindow (hwnd, sb_left, top, | |
7573 | sb_width, height, TRUE); | |
7574 | if (pfnSetScrollInfo) | |
7575 | { | |
7576 | SCROLLINFO si; | |
ee78dc32 | 7577 | |
791f420f JR |
7578 | si.cbSize = sizeof (si); |
7579 | si.fMask = SIF_RANGE; | |
7580 | si.nMin = 0; | |
7581 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) | |
7582 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
ee78dc32 | 7583 | |
00fe468b | 7584 | pfnSetScrollInfo (hwnd, SB_CTL, &si, FALSE); |
791f420f JR |
7585 | } |
7586 | else | |
00fe468b | 7587 | SetScrollRange (hwnd, SB_CTL, 0, |
791f420f JR |
7588 | VERTICAL_SCROLL_BAR_TOP_RANGE (f, height), FALSE); |
7589 | my_show_window (f, hwnd, SW_NORMAL); | |
7590 | // InvalidateRect (w, NULL, FALSE); | |
7591 | ||
7592 | /* Remember new settings. */ | |
7593 | XSETINT (bar->left, sb_left); | |
7594 | XSETINT (bar->top, top); | |
7595 | XSETINT (bar->width, sb_width); | |
7596 | XSETINT (bar->height, height); | |
7597 | ||
7598 | UNBLOCK_INPUT; | |
7599 | } | |
7600 | } | |
7601 | w32_set_scroll_bar_thumb (bar, portion, position, whole); | |
ee78dc32 | 7602 | |
791f420f | 7603 | XSETVECTOR (w->vertical_scroll_bar, bar); |
ee78dc32 GV |
7604 | } |
7605 | ||
7606 | ||
7607 | /* The following three hooks are used when we're doing a thorough | |
7608 | redisplay of the frame. We don't explicitly know which scroll bars | |
7609 | are going to be deleted, because keeping track of when windows go | |
7610 | away is a real pain - "Can you say set-window-configuration, boys | |
7611 | and girls?" Instead, we just assert at the beginning of redisplay | |
7612 | that *all* scroll bars are to be removed, and then save a scroll bar | |
7613 | from the fiery pit when we actually redisplay its window. */ | |
7614 | ||
7615 | /* Arrange for all scroll bars on FRAME to be removed at the next call | |
7616 | to `*judge_scroll_bars_hook'. A scroll bar may be spared if | |
9ef2e2cf JR |
7617 | `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ |
7618 | ||
ee78dc32 | 7619 | static void |
fbd6baed | 7620 | w32_condemn_scroll_bars (frame) |
ee78dc32 GV |
7621 | FRAME_PTR frame; |
7622 | { | |
ef0e360f GV |
7623 | /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ |
7624 | while (! NILP (FRAME_SCROLL_BARS (frame))) | |
7625 | { | |
7626 | Lisp_Object bar; | |
7627 | bar = FRAME_SCROLL_BARS (frame); | |
7628 | FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next; | |
7629 | XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame); | |
7630 | XSCROLL_BAR (bar)->prev = Qnil; | |
7631 | if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame))) | |
7632 | XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar; | |
7633 | FRAME_CONDEMNED_SCROLL_BARS (frame) = bar; | |
7634 | } | |
ee78dc32 GV |
7635 | } |
7636 | ||
9ef2e2cf | 7637 | /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle. |
ee78dc32 GV |
7638 | Note that WINDOW isn't necessarily condemned at all. */ |
7639 | static void | |
fbd6baed | 7640 | w32_redeem_scroll_bar (window) |
ee78dc32 GV |
7641 | struct window *window; |
7642 | { | |
7643 | struct scroll_bar *bar; | |
7644 | ||
7645 | /* We can't redeem this window's scroll bar if it doesn't have one. */ | |
7646 | if (NILP (window->vertical_scroll_bar)) | |
7647 | abort (); | |
7648 | ||
7649 | bar = XSCROLL_BAR (window->vertical_scroll_bar); | |
7650 | ||
ef0e360f GV |
7651 | /* Unlink it from the condemned list. */ |
7652 | { | |
7653 | FRAME_PTR f = XFRAME (WINDOW_FRAME (window)); | |
7654 | ||
7655 | if (NILP (bar->prev)) | |
7656 | { | |
7657 | /* If the prev pointer is nil, it must be the first in one of | |
7658 | the lists. */ | |
7659 | if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar)) | |
7660 | /* It's not condemned. Everything's fine. */ | |
7661 | return; | |
7662 | else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f), | |
7663 | window->vertical_scroll_bar)) | |
7664 | FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next; | |
7665 | else | |
7666 | /* If its prev pointer is nil, it must be at the front of | |
7667 | one or the other! */ | |
7668 | abort (); | |
7669 | } | |
7670 | else | |
7671 | XSCROLL_BAR (bar->prev)->next = bar->next; | |
7672 | ||
7673 | if (! NILP (bar->next)) | |
7674 | XSCROLL_BAR (bar->next)->prev = bar->prev; | |
7675 | ||
7676 | bar->next = FRAME_SCROLL_BARS (f); | |
7677 | bar->prev = Qnil; | |
7678 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
7679 | if (! NILP (bar->next)) | |
7680 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
7681 | } | |
ee78dc32 GV |
7682 | } |
7683 | ||
7684 | /* Remove all scroll bars on FRAME that haven't been saved since the | |
7685 | last call to `*condemn_scroll_bars_hook'. */ | |
9ef2e2cf | 7686 | |
ee78dc32 | 7687 | static void |
fbd6baed | 7688 | w32_judge_scroll_bars (f) |
ee78dc32 GV |
7689 | FRAME_PTR f; |
7690 | { | |
7691 | Lisp_Object bar, next; | |
7692 | ||
7693 | bar = FRAME_CONDEMNED_SCROLL_BARS (f); | |
7694 | ||
7695 | /* Clear out the condemned list now so we won't try to process any | |
7696 | more events on the hapless scroll bars. */ | |
7697 | FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil; | |
7698 | ||
7699 | for (; ! NILP (bar); bar = next) | |
7700 | { | |
7701 | struct scroll_bar *b = XSCROLL_BAR (bar); | |
7702 | ||
7703 | x_scroll_bar_remove (b); | |
7704 | ||
7705 | next = b->next; | |
7706 | b->next = b->prev = Qnil; | |
7707 | } | |
7708 | ||
7709 | /* Now there should be no references to the condemned scroll bars, | |
7710 | and they should get garbage-collected. */ | |
7711 | } | |
7712 | ||
7713 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind | |
7714 | is set to something other than no_event, it is enqueued. | |
7715 | ||
7716 | This may be called from a signal handler, so we have to ignore GC | |
7717 | mark bits. */ | |
2c28562d | 7718 | |
52cf03a1 | 7719 | static int |
ee78dc32 GV |
7720 | x_scroll_bar_handle_click (bar, msg, emacs_event) |
7721 | struct scroll_bar *bar; | |
fbd6baed | 7722 | W32Msg *msg; |
ee78dc32 GV |
7723 | struct input_event *emacs_event; |
7724 | { | |
7725 | if (! GC_WINDOWP (bar->window)) | |
7726 | abort (); | |
7727 | ||
fbd6baed | 7728 | emacs_event->kind = w32_scroll_bar_click; |
ee78dc32 | 7729 | emacs_event->code = 0; |
52cf03a1 GV |
7730 | /* not really meaningful to distinguish up/down */ |
7731 | emacs_event->modifiers = msg->dwModifiers; | |
ee78dc32 | 7732 | emacs_event->frame_or_window = bar->window; |
7e889510 | 7733 | emacs_event->arg = Qnil; |
ee78dc32 GV |
7734 | emacs_event->timestamp = msg->msg.time; |
7735 | ||
7736 | { | |
791f420f | 7737 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
689004fa GV |
7738 | int y; |
7739 | int dragging = !NILP (bar->dragging); | |
7740 | ||
7741 | if (pfnGetScrollInfo) | |
7742 | { | |
7743 | SCROLLINFO si; | |
7744 | ||
7745 | si.cbSize = sizeof (si); | |
7746 | si.fMask = SIF_POS; | |
7747 | ||
7748 | pfnGetScrollInfo ((HWND) msg->msg.lParam, SB_CTL, &si); | |
7749 | y = si.nPos; | |
7750 | } | |
7751 | else | |
7752 | y = GetScrollPos ((HWND) msg->msg.lParam, SB_CTL); | |
7753 | ||
7754 | bar->dragging = Qnil; | |
ee78dc32 | 7755 | |
9ef2e2cf JR |
7756 | |
7757 | last_mouse_scroll_bar_pos = msg->msg.wParam; | |
7758 | ||
ee78dc32 | 7759 | switch (LOWORD (msg->msg.wParam)) |
2c28562d | 7760 | { |
2c28562d | 7761 | case SB_LINEDOWN: |
52cf03a1 | 7762 | emacs_event->part = scroll_bar_down_arrow; |
ee78dc32 | 7763 | break; |
2c28562d | 7764 | case SB_LINEUP: |
52cf03a1 | 7765 | emacs_event->part = scroll_bar_up_arrow; |
ee78dc32 | 7766 | break; |
2c28562d | 7767 | case SB_PAGEUP: |
ee78dc32 GV |
7768 | emacs_event->part = scroll_bar_above_handle; |
7769 | break; | |
2c28562d | 7770 | case SB_PAGEDOWN: |
ee78dc32 GV |
7771 | emacs_event->part = scroll_bar_below_handle; |
7772 | break; | |
2c28562d | 7773 | case SB_TOP: |
ee78dc32 GV |
7774 | emacs_event->part = scroll_bar_handle; |
7775 | y = 0; | |
7776 | break; | |
2c28562d | 7777 | case SB_BOTTOM: |
ee78dc32 GV |
7778 | emacs_event->part = scroll_bar_handle; |
7779 | y = top_range; | |
7780 | break; | |
689004fa | 7781 | case SB_THUMBTRACK: |
2c28562d | 7782 | case SB_THUMBPOSITION: |
791f420f JR |
7783 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
7784 | y = HIWORD (msg->msg.wParam); | |
689004fa | 7785 | bar->dragging = Qt; |
ee78dc32 | 7786 | emacs_event->part = scroll_bar_handle; |
689004fa GV |
7787 | |
7788 | /* "Silently" update current position. */ | |
7789 | if (pfnSetScrollInfo) | |
7790 | { | |
7791 | SCROLLINFO si; | |
7792 | ||
7793 | si.cbSize = sizeof (si); | |
7794 | si.fMask = SIF_POS; | |
689004fa GV |
7795 | si.nPos = y; |
7796 | /* Remember apparent position (we actually lag behind the real | |
7797 | position, so don't set that directly. */ | |
7798 | last_scroll_bar_drag_pos = y; | |
7799 | ||
7800 | pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, FALSE); | |
7801 | } | |
7802 | else | |
7803 | SetScrollPos (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, y, FALSE); | |
ee78dc32 | 7804 | break; |
2c28562d | 7805 | case SB_ENDSCROLL: |
689004fa GV |
7806 | /* If this is the end of a drag sequence, then reset the scroll |
7807 | handle size to normal and do a final redraw. Otherwise do | |
7808 | nothing. */ | |
7809 | if (dragging) | |
7810 | { | |
7811 | if (pfnSetScrollInfo) | |
7812 | { | |
7813 | SCROLLINFO si; | |
7814 | int start = XINT (bar->start); | |
7815 | int end = XINT (bar->end); | |
7816 | ||
7817 | si.cbSize = sizeof (si); | |
7818 | si.fMask = SIF_PAGE | SIF_POS; | |
791f420f | 7819 | si.nPage = end - start + VERTICAL_SCROLL_BAR_MIN_HANDLE; |
689004fa | 7820 | si.nPos = last_scroll_bar_drag_pos; |
689004fa GV |
7821 | pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, TRUE); |
7822 | } | |
7823 | else | |
7824 | SetScrollPos (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, y, TRUE); | |
7825 | } | |
7826 | /* fall through */ | |
2c28562d | 7827 | default: |
689004fa | 7828 | emacs_event->kind = no_event; |
52cf03a1 | 7829 | return FALSE; |
2c28562d | 7830 | } |
52cf03a1 | 7831 | |
ee78dc32 GV |
7832 | XSETINT (emacs_event->x, y); |
7833 | XSETINT (emacs_event->y, top_range); | |
52cf03a1 GV |
7834 | |
7835 | return TRUE; | |
ee78dc32 GV |
7836 | } |
7837 | } | |
7838 | ||
7839 | /* Return information to the user about the current position of the mouse | |
7840 | on the scroll bar. */ | |
9ef2e2cf | 7841 | |
ee78dc32 GV |
7842 | static void |
7843 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) | |
7844 | FRAME_PTR *fp; | |
7845 | Lisp_Object *bar_window; | |
7846 | enum scroll_bar_part *part; | |
7847 | Lisp_Object *x, *y; | |
7848 | unsigned long *time; | |
7849 | { | |
7850 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); | |
fbd6baed | 7851 | Window w = SCROLL_BAR_W32_WINDOW (bar); |
ee78dc32 GV |
7852 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
7853 | int pos; | |
791f420f | 7854 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
ee78dc32 GV |
7855 | |
7856 | BLOCK_INPUT; | |
7857 | ||
7858 | *fp = f; | |
7859 | *bar_window = bar->window; | |
7860 | ||
689004fa GV |
7861 | if (pfnGetScrollInfo) |
7862 | { | |
7863 | SCROLLINFO si; | |
7864 | ||
7865 | si.cbSize = sizeof (si); | |
7866 | si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; | |
7867 | ||
7868 | pfnGetScrollInfo (w, SB_CTL, &si); | |
7869 | pos = si.nPos; | |
7870 | top_range = si.nMax - si.nPage + 1; | |
7871 | } | |
7872 | else | |
7873 | pos = GetScrollPos (w, SB_CTL); | |
ee78dc32 GV |
7874 | |
7875 | switch (LOWORD (last_mouse_scroll_bar_pos)) | |
7876 | { | |
7877 | case SB_THUMBPOSITION: | |
7878 | case SB_THUMBTRACK: | |
7879 | *part = scroll_bar_handle; | |
791f420f | 7880 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
ee78dc32 GV |
7881 | pos = HIWORD (last_mouse_scroll_bar_pos); |
7882 | break; | |
7883 | case SB_LINEDOWN: | |
7884 | *part = scroll_bar_handle; | |
7885 | pos++; | |
7886 | break; | |
7887 | default: | |
7888 | *part = scroll_bar_handle; | |
7889 | break; | |
7890 | } | |
7891 | ||
9127e20e JR |
7892 | XSETINT (*x, pos); |
7893 | XSETINT (*y, top_range); | |
ee78dc32 GV |
7894 | |
7895 | f->mouse_moved = 0; | |
7896 | last_mouse_scroll_bar = Qnil; | |
7897 | ||
7898 | *time = last_mouse_movement_time; | |
7899 | ||
7900 | UNBLOCK_INPUT; | |
7901 | } | |
7902 | ||
9ef2e2cf | 7903 | |
ee78dc32 GV |
7904 | /* The screen has been cleared so we may have changed foreground or |
7905 | background colors, and the scroll bars may need to be redrawn. | |
7906 | Clear out the scroll bars, and ask for expose events, so we can | |
7907 | redraw them. */ | |
9ef2e2cf | 7908 | |
791f420f | 7909 | void |
ee78dc32 | 7910 | x_scroll_bar_clear (f) |
9ef2e2cf | 7911 | FRAME_PTR f; |
ee78dc32 | 7912 | { |
ee78dc32 GV |
7913 | Lisp_Object bar; |
7914 | ||
9ef2e2cf JR |
7915 | /* We can have scroll bars even if this is 0, |
7916 | if we just turned off scroll bar mode. | |
7917 | But in that case we should not clear them. */ | |
7918 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
7919 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
7920 | bar = XSCROLL_BAR (bar)->next) | |
7921 | { | |
7922 | HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)); | |
7923 | HDC hdc = GetDC (window); | |
7924 | RECT rect; | |
52cf03a1 | 7925 | |
9ef2e2cf JR |
7926 | /* Hide scroll bar until ready to repaint. x_scroll_bar_move |
7927 | arranges to refresh the scroll bar if hidden. */ | |
7928 | my_show_window (f, window, SW_HIDE); | |
689004fa | 7929 | |
9ef2e2cf JR |
7930 | GetClientRect (window, &rect); |
7931 | select_palette (f, hdc); | |
7932 | w32_clear_rect (f, hdc, &rect); | |
7933 | deselect_palette (f, hdc); | |
689004fa | 7934 | |
9ef2e2cf JR |
7935 | ReleaseDC (window, hdc); |
7936 | } | |
52cf03a1 GV |
7937 | } |
7938 | ||
7939 | show_scroll_bars (f, how) | |
7940 | FRAME_PTR f; | |
7941 | int how; | |
7942 | { | |
7943 | Lisp_Object bar; | |
7944 | ||
7945 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
7946 | bar = XSCROLL_BAR (bar)->next) | |
7947 | { | |
fbd6baed | 7948 | HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)); |
689004fa | 7949 | my_show_window (f, window, how); |
52cf03a1 | 7950 | } |
ee78dc32 GV |
7951 | } |
7952 | ||
7953 | \f | |
fbd6baed | 7954 | /* The main W32 event-reading loop - w32_read_socket. */ |
ee78dc32 | 7955 | |
9ef2e2cf | 7956 | /* Time stamp of enter window event. This is only used by w32_read_socket, |
ee78dc32 GV |
7957 | but we have to put it out here, since static variables within functions |
7958 | sometimes don't work. */ | |
9ef2e2cf | 7959 | |
ee78dc32 GV |
7960 | static Time enter_timestamp; |
7961 | ||
7962 | /* Record the last 100 characters stored | |
7963 | to help debug the loss-of-chars-during-GC problem. */ | |
9ef2e2cf JR |
7964 | |
7965 | static int temp_index; | |
7966 | static short temp_buffer[100]; | |
ee78dc32 | 7967 | |
afd153f0 | 7968 | |
fbd6baed | 7969 | /* Read events coming from the W32 shell. |
ee78dc32 GV |
7970 | This routine is called by the SIGIO handler. |
7971 | We return as soon as there are no more events to be read. | |
7972 | ||
7973 | Events representing keys are stored in buffer BUFP, | |
7974 | which can hold up to NUMCHARS characters. | |
7975 | We return the number of characters stored into the buffer, | |
7976 | thus pretending to be `read'. | |
7977 | ||
ee78dc32 GV |
7978 | EXPECTED is nonzero if the caller knows input is available. |
7979 | ||
7980 | Some of these messages are reposted back to the message queue since the | |
e9e23e23 GV |
7981 | system calls the windows proc directly in a context where we cannot return |
7982 | the data nor can we guarantee the state we are in. So if we dispatch them | |
ee78dc32 GV |
7983 | we will get into an infinite loop. To prevent this from ever happening we |
7984 | will set a variable to indicate we are in the read_socket call and indicate | |
e9e23e23 GV |
7985 | which message we are processing since the windows proc gets called |
7986 | recursively with different messages by the system. | |
ee78dc32 GV |
7987 | */ |
7988 | ||
7989 | int | |
3aad7613 | 7990 | w32_read_socket (sd, bufp, numchars, expected) |
ee78dc32 | 7991 | register int sd; |
9ef2e2cf JR |
7992 | /* register */ struct input_event *bufp; |
7993 | /* register */ int numchars; | |
ee78dc32 GV |
7994 | int expected; |
7995 | { | |
7996 | int count = 0; | |
689004fa | 7997 | int check_visibility = 0; |
fbd6baed | 7998 | W32Msg msg; |
ee78dc32 | 7999 | struct frame *f; |
fbd6baed | 8000 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
ee78dc32 GV |
8001 | |
8002 | if (interrupt_input_blocked) | |
8003 | { | |
8004 | interrupt_input_pending = 1; | |
8005 | return -1; | |
8006 | } | |
8007 | ||
8008 | interrupt_input_pending = 0; | |
8009 | BLOCK_INPUT; | |
8010 | ||
8011 | /* So people can tell when we have read the available input. */ | |
8012 | input_signal_count++; | |
8013 | ||
8014 | if (numchars <= 0) | |
8015 | abort (); /* Don't think this happens. */ | |
8016 | ||
01b220b6 | 8017 | /* TODO: tooltips, tool-bars, ghostscript integration, mouse |
791f420f | 8018 | cursors. */ |
52cf03a1 | 8019 | while (get_next_msg (&msg, FALSE)) |
ee78dc32 GV |
8020 | { |
8021 | switch (msg.msg.message) | |
8022 | { | |
ee78dc32 | 8023 | case WM_PAINT: |
ee78dc32 GV |
8024 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); |
8025 | ||
8026 | if (f) | |
8027 | { | |
014b6ea1 GV |
8028 | if (msg.rect.right == msg.rect.left || |
8029 | msg.rect.bottom == msg.rect.top) | |
ee78dc32 | 8030 | { |
014b6ea1 GV |
8031 | /* We may get paint messages even though the client |
8032 | area is clipped - these are not expose events. */ | |
8033 | DebPrint (("clipped frame %04x (%s) got WM_PAINT\n", f, | |
8034 | XSTRING (f->name)->data)); | |
8035 | } | |
8036 | else if (f->async_visible != 1) | |
8037 | { | |
8038 | /* Definitely not obscured, so mark as visible. */ | |
ee78dc32 GV |
8039 | f->async_visible = 1; |
8040 | f->async_iconified = 0; | |
8041 | SET_FRAME_GARBAGED (f); | |
014b6ea1 GV |
8042 | DebPrint (("frame %04x (%s) reexposed\n", f, |
8043 | XSTRING (f->name)->data)); | |
689004fa GV |
8044 | |
8045 | /* WM_PAINT serves as MapNotify as well, so report | |
8046 | visibility changes properly. */ | |
8047 | if (f->iconified) | |
8048 | { | |
8049 | bufp->kind = deiconify_event; | |
8050 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8051 | bufp->arg = Qnil; |
689004fa GV |
8052 | bufp++; |
8053 | count++; | |
8054 | numchars--; | |
8055 | } | |
9127e20e | 8056 | else if (! NILP (Vframe_list) |
8e713be6 | 8057 | && ! NILP (XCDR (Vframe_list))) |
689004fa GV |
8058 | /* Force a redisplay sooner or later to update the |
8059 | frame titles in case this is the second frame. */ | |
8060 | record_asynch_buffer_change (); | |
ee78dc32 GV |
8061 | } |
8062 | else | |
8063 | { | |
00fe468b JR |
8064 | HDC hdc = get_frame_dc (f); |
8065 | ||
97e6de38 | 8066 | /* Erase background again for safety. */ |
00fe468b JR |
8067 | w32_clear_rect (f, hdc, &msg.rect); |
8068 | release_frame_dc (f, hdc); | |
791f420f JR |
8069 | expose_frame (f, |
8070 | msg.rect.left, | |
8071 | msg.rect.top, | |
8072 | msg.rect.right - msg.rect.left, | |
8073 | msg.rect.bottom - msg.rect.top); | |
ee78dc32 GV |
8074 | } |
8075 | } | |
52cf03a1 | 8076 | break; |
689004fa | 8077 | |
f98169a0 GV |
8078 | case WM_INPUTLANGCHANGE: |
8079 | /* Generate a language change event. */ | |
8080 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8081 | ||
8082 | if (f) | |
8083 | { | |
8084 | if (numchars == 0) | |
8085 | abort (); | |
8086 | ||
8087 | bufp->kind = language_change_event; | |
8088 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8089 | bufp->arg = Qnil; |
f98169a0 GV |
8090 | bufp->code = msg.msg.wParam; |
8091 | bufp->modifiers = msg.msg.lParam & 0xffff; | |
8092 | bufp++; | |
8093 | count++; | |
8094 | numchars--; | |
8095 | } | |
8096 | break; | |
8097 | ||
ee78dc32 GV |
8098 | case WM_KEYDOWN: |
8099 | case WM_SYSKEYDOWN: | |
8100 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8101 | ||
8102 | if (f && !f->iconified) | |
8103 | { | |
8104 | if (temp_index == sizeof temp_buffer / sizeof (short)) | |
8105 | temp_index = 0; | |
8106 | temp_buffer[temp_index++] = msg.msg.wParam; | |
8107 | bufp->kind = non_ascii_keystroke; | |
8108 | bufp->code = msg.msg.wParam; | |
f98169a0 | 8109 | bufp->modifiers = msg.dwModifiers; |
ee78dc32 | 8110 | XSETFRAME (bufp->frame_or_window, f); |
7e889510 | 8111 | bufp->arg = Qnil; |
ee78dc32 GV |
8112 | bufp->timestamp = msg.msg.time; |
8113 | bufp++; | |
8114 | numchars--; | |
8115 | count++; | |
8116 | } | |
8117 | break; | |
689004fa | 8118 | |
ee78dc32 GV |
8119 | case WM_SYSCHAR: |
8120 | case WM_CHAR: | |
8121 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8122 | ||
8123 | if (f && !f->iconified) | |
8124 | { | |
f98169a0 GV |
8125 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
8126 | temp_index = 0; | |
8127 | temp_buffer[temp_index++] = msg.msg.wParam; | |
8128 | bufp->kind = ascii_keystroke; | |
8129 | bufp->code = msg.msg.wParam; | |
8130 | bufp->modifiers = msg.dwModifiers; | |
8131 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8132 | bufp->arg = Qnil; |
f98169a0 GV |
8133 | bufp->timestamp = msg.msg.time; |
8134 | bufp++; | |
8135 | numchars--; | |
8136 | count++; | |
ee78dc32 GV |
8137 | } |
8138 | break; | |
689004fa | 8139 | |
ee78dc32 | 8140 | case WM_MOUSEMOVE: |
791f420f | 8141 | previous_help_echo = help_echo; |
158cba56 JR |
8142 | help_echo = help_echo_object = help_echo_window = Qnil; |
8143 | help_echo_pos = -1; | |
791f420f | 8144 | |
ee78dc32 GV |
8145 | if (dpyinfo->grabbed && last_mouse_frame |
8146 | && FRAME_LIVE_P (last_mouse_frame)) | |
8147 | f = last_mouse_frame; | |
8148 | else | |
8149 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8150 | ||
8151 | if (f) | |
8152 | note_mouse_movement (f, &msg.msg); | |
8153 | else | |
791f420f JR |
8154 | { |
8155 | /* If we move outside the frame, then we're | |
8156 | certainly no longer on any text in the frame. */ | |
8157 | clear_mouse_face (FRAME_W32_DISPLAY_INFO (f)); | |
8158 | } | |
8159 | ||
8160 | /* If the contents of the global variable help_echo | |
8161 | has changed, generate a HELP_EVENT. */ | |
b7e80413 SM |
8162 | if (!NILP (help_echo) |
8163 | || !NILP (previous_help_echo)) | |
791f420f JR |
8164 | { |
8165 | Lisp_Object frame; | |
ec48c3a7 | 8166 | int n; |
791f420f JR |
8167 | |
8168 | if (f) | |
8169 | XSETFRAME (frame, f); | |
8170 | else | |
8171 | frame = Qnil; | |
8172 | ||
8173 | any_help_event_p = 1; | |
b4165314 GM |
8174 | n = gen_help_event (bufp, numchars, help_echo, frame, |
8175 | help_echo_window, help_echo_object, | |
8176 | help_echo_pos); | |
ec48c3a7 | 8177 | bufp += n, count += n, numchars -= n; |
791f420f JR |
8178 | } |
8179 | break; | |
689004fa | 8180 | |
ee78dc32 GV |
8181 | case WM_LBUTTONDOWN: |
8182 | case WM_LBUTTONUP: | |
8183 | case WM_MBUTTONDOWN: | |
8184 | case WM_MBUTTONUP: | |
8185 | case WM_RBUTTONDOWN: | |
8186 | case WM_RBUTTONUP: | |
8187 | { | |
791f420f JR |
8188 | /* If we decide we want to generate an event to be seen |
8189 | by the rest of Emacs, we put it here. */ | |
8190 | struct input_event emacs_event; | |
8191 | int tool_bar_p = 0; | |
ee78dc32 GV |
8192 | int button; |
8193 | int up; | |
791f420f JR |
8194 | |
8195 | emacs_event.kind = no_event; | |
ee78dc32 GV |
8196 | |
8197 | if (dpyinfo->grabbed && last_mouse_frame | |
8198 | && FRAME_LIVE_P (last_mouse_frame)) | |
8199 | f = last_mouse_frame; | |
8200 | else | |
8201 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8202 | ||
8203 | if (f) | |
8204 | { | |
791f420f JR |
8205 | construct_mouse_click (&emacs_event, &msg, f); |
8206 | ||
8207 | /* Is this in the tool-bar? */ | |
8208 | if (WINDOWP (f->tool_bar_window) | |
8209 | && XFASTINT (XWINDOW (f->tool_bar_window)->height)) | |
8210 | { | |
8211 | Lisp_Object window; | |
8212 | int p, x, y; | |
8213 | ||
8214 | /* Set x and y. */ | |
8215 | window = window_from_coordinates (f, | |
8216 | emacs_event.x, | |
8217 | emacs_event.y, | |
8218 | &p, 1); | |
8219 | if (EQ (window, f->tool_bar_window)) | |
8220 | { | |
8221 | w32_handle_tool_bar_click (f, &emacs_event); | |
8222 | tool_bar_p = 1; | |
8223 | } | |
8224 | } | |
8225 | ||
8226 | if (!tool_bar_p) | |
8227 | if (!dpyinfo->w32_focus_frame | |
8228 | || f == dpyinfo->w32_focus_frame | |
8229 | && (numchars >= 1)) | |
8230 | { | |
8231 | construct_mouse_click (bufp, &msg, f); | |
8232 | bufp++; | |
8233 | count++; | |
8234 | numchars--; | |
8235 | } | |
ee78dc32 GV |
8236 | } |
8237 | ||
8238 | parse_button (msg.msg.message, &button, &up); | |
8239 | ||
8240 | if (up) | |
8241 | { | |
8242 | dpyinfo->grabbed &= ~ (1 << button); | |
8243 | } | |
8244 | else | |
8245 | { | |
8246 | dpyinfo->grabbed |= (1 << button); | |
8247 | last_mouse_frame = f; | |
791f420f JR |
8248 | /* Ignore any mouse motion that happened |
8249 | before this event; any subsequent mouse-movement | |
8250 | Emacs events should reflect only motion after | |
8251 | the ButtonPress. */ | |
8252 | if (f != 0) | |
8253 | f->mouse_moved = 0; | |
8254 | ||
8255 | if (!tool_bar_p) | |
8256 | last_tool_bar_item = -1; | |
ee78dc32 | 8257 | } |
689004fa | 8258 | break; |
ee78dc32 GV |
8259 | } |
8260 | ||
689004fa GV |
8261 | case WM_MOUSEWHEEL: |
8262 | if (dpyinfo->grabbed && last_mouse_frame | |
8263 | && FRAME_LIVE_P (last_mouse_frame)) | |
8264 | f = last_mouse_frame; | |
8265 | else | |
8266 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8267 | ||
8268 | if (f) | |
8269 | { | |
8270 | if ((!dpyinfo->w32_focus_frame | |
8271 | || f == dpyinfo->w32_focus_frame) | |
8272 | && (numchars >= 1)) | |
8273 | { | |
8274 | construct_mouse_wheel (bufp, &msg, f); | |
8275 | bufp++; | |
8276 | count++; | |
8277 | numchars--; | |
8278 | } | |
8279 | } | |
ee78dc32 | 8280 | break; |
689004fa | 8281 | |
93ff4395 JR |
8282 | case WM_MENUSELECT: |
8283 | { | |
8284 | HMENU menu = (HMENU) msg.msg.lParam; | |
8285 | UINT menu_item = (UINT) LOWORD (msg.msg.wParam); | |
8286 | UINT flags = (UINT) HIWORD (msg.msg.wParam); | |
9ef2e2cf | 8287 | |
93ff4395 JR |
8288 | w32_menu_display_help (menu, menu_item, flags); |
8289 | } | |
8290 | break; | |
8291 | ||
12857dfd RS |
8292 | case WM_DROPFILES: |
8293 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8294 | ||
8295 | if (f) | |
8296 | { | |
8297 | construct_drag_n_drop (bufp, &msg, f); | |
8298 | bufp++; | |
8299 | count++; | |
8300 | numchars--; | |
8301 | } | |
8302 | break; | |
8303 | ||
ee78dc32 GV |
8304 | case WM_VSCROLL: |
8305 | { | |
689004fa GV |
8306 | struct scroll_bar *bar = |
8307 | x_window_to_scroll_bar ((HWND)msg.msg.lParam); | |
ee78dc32 GV |
8308 | |
8309 | if (bar && numchars >= 1) | |
8310 | { | |
52cf03a1 GV |
8311 | if (x_scroll_bar_handle_click (bar, &msg, bufp)) |
8312 | { | |
8313 | bufp++; | |
8314 | count++; | |
8315 | numchars--; | |
8316 | } | |
ee78dc32 | 8317 | } |
689004fa | 8318 | break; |
ee78dc32 GV |
8319 | } |
8320 | ||
689004fa GV |
8321 | case WM_WINDOWPOSCHANGED: |
8322 | case WM_ACTIVATE: | |
8323 | case WM_ACTIVATEAPP: | |
8324 | check_visibility = 1; | |
ee78dc32 | 8325 | break; |
689004fa | 8326 | |
ee78dc32 GV |
8327 | case WM_MOVE: |
8328 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8329 | ||
8330 | if (f && !f->async_iconified) | |
8331 | { | |
689004fa GV |
8332 | int x, y; |
8333 | ||
8334 | x_real_positions (f, &x, &y); | |
8335 | f->output_data.w32->left_pos = x; | |
8336 | f->output_data.w32->top_pos = y; | |
ee78dc32 | 8337 | } |
689004fa GV |
8338 | |
8339 | check_visibility = 1; | |
8340 | break; | |
8341 | ||
8342 | case WM_SHOWWINDOW: | |
8343 | /* If window has been obscured or exposed by another window | |
8344 | being maximised or minimised/restored, then recheck | |
8345 | visibility of all frames. Direct changes to our own | |
8346 | windows get handled by WM_SIZE. */ | |
8347 | #if 0 | |
8348 | if (msg.msg.lParam != 0) | |
8349 | check_visibility = 1; | |
8350 | else | |
8351 | { | |
8352 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8353 | f->async_visible = msg.msg.wParam; | |
8354 | } | |
8355 | #endif | |
8356 | ||
8357 | check_visibility = 1; | |
ee78dc32 | 8358 | break; |
689004fa | 8359 | |
ee78dc32 GV |
8360 | case WM_SIZE: |
8361 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8362 | ||
689004fa GV |
8363 | /* Inform lisp of whether frame has been iconified etc. */ |
8364 | if (f) | |
ee78dc32 | 8365 | { |
689004fa | 8366 | switch (msg.msg.wParam) |
ee78dc32 | 8367 | { |
689004fa GV |
8368 | case SIZE_MINIMIZED: |
8369 | f->async_visible = 0; | |
ee78dc32 GV |
8370 | f->async_iconified = 1; |
8371 | ||
8372 | bufp->kind = iconify_event; | |
8373 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8374 | bufp->arg = Qnil; |
ee78dc32 GV |
8375 | bufp++; |
8376 | count++; | |
8377 | numchars--; | |
689004fa GV |
8378 | break; |
8379 | ||
8380 | case SIZE_MAXIMIZED: | |
8381 | case SIZE_RESTORED: | |
ee78dc32 GV |
8382 | f->async_visible = 1; |
8383 | f->async_iconified = 0; | |
8384 | ||
8385 | /* wait_reading_process_input will notice this and update | |
8386 | the frame's display structures. */ | |
8387 | SET_FRAME_GARBAGED (f); | |
8388 | ||
8389 | if (f->iconified) | |
8390 | { | |
31d4844a KH |
8391 | int x, y; |
8392 | ||
8393 | /* Reset top and left positions of the Window | |
8394 | here since Windows sends a WM_MOVE message | |
8395 | BEFORE telling us the Window is minimized | |
8396 | when the Window is iconified, with 3000,3000 | |
8397 | as the co-ords. */ | |
8398 | x_real_positions (f, &x, &y); | |
8399 | f->output_data.w32->left_pos = x; | |
8400 | f->output_data.w32->top_pos = y; | |
8401 | ||
ee78dc32 GV |
8402 | bufp->kind = deiconify_event; |
8403 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8404 | bufp->arg = Qnil; |
ee78dc32 GV |
8405 | bufp++; |
8406 | count++; | |
8407 | numchars--; | |
8408 | } | |
9ef2e2cf JR |
8409 | else if (! NILP (Vframe_list) |
8410 | && ! NILP (XCDR (Vframe_list))) | |
ee78dc32 GV |
8411 | /* Force a redisplay sooner or later |
8412 | to update the frame titles | |
8413 | in case this is the second frame. */ | |
8414 | record_asynch_buffer_change (); | |
689004fa | 8415 | break; |
ee78dc32 | 8416 | } |
ee78dc32 | 8417 | } |
689004fa | 8418 | |
ef0e360f GV |
8419 | if (f && !f->async_iconified && msg.msg.wParam != SIZE_MINIMIZED) |
8420 | { | |
8421 | RECT rect; | |
8422 | int rows; | |
8423 | int columns; | |
8424 | int width; | |
8425 | int height; | |
8426 | ||
9127e20e | 8427 | GetClientRect (msg.msg.hwnd, &rect); |
ef0e360f GV |
8428 | |
8429 | height = rect.bottom - rect.top; | |
8430 | width = rect.right - rect.left; | |
8431 | ||
8432 | rows = PIXEL_TO_CHAR_HEIGHT (f, height); | |
8433 | columns = PIXEL_TO_CHAR_WIDTH (f, width); | |
8434 | ||
8435 | /* TODO: Clip size to the screen dimensions. */ | |
8436 | ||
8437 | /* Even if the number of character rows and columns has | |
8438 | not changed, the font size may have changed, so we need | |
8439 | to check the pixel dimensions as well. */ | |
8440 | ||
8441 | if (columns != f->width | |
8442 | || rows != f->height | |
8443 | || width != f->output_data.w32->pixel_width | |
8444 | || height != f->output_data.w32->pixel_height) | |
8445 | { | |
791f420f | 8446 | change_frame_size (f, rows, columns, 0, 1, 0); |
ef0e360f | 8447 | SET_FRAME_GARBAGED (f); |
31d4844a | 8448 | cancel_mouse_face (f); |
ef0e360f GV |
8449 | f->output_data.w32->pixel_width = width; |
8450 | f->output_data.w32->pixel_height = height; | |
8451 | f->output_data.w32->win_gravity = NorthWestGravity; | |
8452 | } | |
8453 | } | |
8454 | ||
689004fa GV |
8455 | check_visibility = 1; |
8456 | break; | |
8457 | ||
8458 | case WM_SETFOCUS: | |
791f420f JR |
8459 | f = x_any_window_to_frame (dpyinfo, msg.msg.hwnd); |
8460 | ||
8461 | dpyinfo->w32_focus_event_frame = f; | |
8462 | ||
8463 | if (f) | |
8464 | x_new_focus_frame (dpyinfo, f); | |
8465 | ||
8466 | ||
8467 | dpyinfo->grabbed = 0; | |
8468 | check_visibility = 1; | |
8469 | break; | |
8470 | ||
689004fa | 8471 | case WM_KILLFOCUS: |
01b220b6 | 8472 | /* TODO: some of this belongs in MOUSE_LEAVE */ |
791f420f | 8473 | f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd); |
08712a41 | 8474 | |
791f420f JR |
8475 | if (f) |
8476 | { | |
8477 | Lisp_Object frame; | |
8478 | ||
8479 | if (f == dpyinfo->w32_focus_event_frame) | |
8480 | dpyinfo->w32_focus_event_frame = 0; | |
8481 | ||
8482 | if (f == dpyinfo->w32_focus_frame) | |
8483 | x_new_focus_frame (dpyinfo, 0); | |
8484 | ||
8485 | if (f == dpyinfo->mouse_face_mouse_frame) | |
8486 | { | |
8487 | /* If we move outside the frame, then we're | |
8488 | certainly no longer on any text in the frame. */ | |
8489 | clear_mouse_face (dpyinfo); | |
8490 | dpyinfo->mouse_face_mouse_frame = 0; | |
8491 | } | |
9ef2e2cf | 8492 | |
791f420f JR |
8493 | /* Generate a nil HELP_EVENT to cancel a help-echo. |
8494 | Do it only if there's something to cancel. | |
8495 | Otherwise, the startup message is cleared when | |
8496 | the mouse leaves the frame. */ | |
8497 | if (any_help_event_p) | |
8498 | { | |
ec48c3a7 JR |
8499 | int n; |
8500 | ||
791f420f | 8501 | XSETFRAME (frame, f); |
b4165314 GM |
8502 | n = gen_help_event (bufp, numchars, Qnil, frame, |
8503 | Qnil, Qnil, 0); | |
ec48c3a7 | 8504 | bufp += n, count += n, numchars -=n; |
791f420f JR |
8505 | } |
8506 | } | |
689004fa | 8507 | |
08712a41 | 8508 | dpyinfo->grabbed = 0; |
689004fa | 8509 | check_visibility = 1; |
ee78dc32 | 8510 | break; |
689004fa | 8511 | |
ee78dc32 GV |
8512 | case WM_CLOSE: |
8513 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8514 | ||
8515 | if (f) | |
8516 | { | |
8517 | if (numchars == 0) | |
8518 | abort (); | |
8519 | ||
8520 | bufp->kind = delete_window_event; | |
8521 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8522 | bufp->arg = Qnil; |
ee78dc32 GV |
8523 | bufp++; |
8524 | count++; | |
8525 | numchars--; | |
8526 | } | |
689004fa GV |
8527 | break; |
8528 | ||
8529 | case WM_INITMENU: | |
8530 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8531 | ||
8532 | if (f) | |
8533 | { | |
8534 | if (numchars == 0) | |
8535 | abort (); | |
ee78dc32 | 8536 | |
689004fa GV |
8537 | bufp->kind = menu_bar_activate_event; |
8538 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8539 | bufp->arg = Qnil; |
689004fa GV |
8540 | bufp++; |
8541 | count++; | |
8542 | numchars--; | |
8543 | } | |
ee78dc32 | 8544 | break; |
689004fa | 8545 | |
ee78dc32 GV |
8546 | case WM_COMMAND: |
8547 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
014b6ea1 | 8548 | |
ee78dc32 GV |
8549 | if (f) |
8550 | { | |
f98169a0 GV |
8551 | extern void menubar_selection_callback |
8552 | (FRAME_PTR f, void * client_data); | |
014b6ea1 | 8553 | menubar_selection_callback (f, (void *)msg.msg.wParam); |
ee78dc32 | 8554 | } |
689004fa GV |
8555 | |
8556 | check_visibility = 1; | |
8557 | break; | |
8558 | ||
8559 | case WM_DISPLAYCHANGE: | |
8560 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8561 | ||
8562 | if (f) | |
8563 | { | |
8564 | dpyinfo->width = (short) LOWORD (msg.msg.lParam); | |
8565 | dpyinfo->height = (short) HIWORD (msg.msg.lParam); | |
8566 | dpyinfo->n_cbits = msg.msg.wParam; | |
8567 | DebPrint (("display change: %d %d\n", dpyinfo->width, | |
8568 | dpyinfo->height)); | |
8569 | } | |
8570 | ||
8571 | check_visibility = 1; | |
ee78dc32 | 8572 | break; |
e7efd97e GV |
8573 | |
8574 | default: | |
8575 | /* Check for messages registered at runtime. */ | |
8576 | if (msg.msg.message == msh_mousewheel) | |
8577 | { | |
8578 | if (dpyinfo->grabbed && last_mouse_frame | |
8579 | && FRAME_LIVE_P (last_mouse_frame)) | |
8580 | f = last_mouse_frame; | |
8581 | else | |
8582 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8583 | ||
8584 | if (f) | |
8585 | { | |
8586 | if ((!dpyinfo->w32_focus_frame | |
8587 | || f == dpyinfo->w32_focus_frame) | |
8588 | && (numchars >= 1)) | |
8589 | { | |
8590 | construct_mouse_wheel (bufp, &msg, f); | |
8591 | bufp++; | |
8592 | count++; | |
8593 | numchars--; | |
8594 | } | |
8595 | } | |
8596 | } | |
8597 | break; | |
ee78dc32 GV |
8598 | } |
8599 | } | |
8600 | ||
8601 | /* If the focus was just given to an autoraising frame, | |
8602 | raise it now. */ | |
8603 | /* ??? This ought to be able to handle more than one such frame. */ | |
8604 | if (pending_autoraise_frame) | |
8605 | { | |
8606 | x_raise_frame (pending_autoraise_frame); | |
8607 | pending_autoraise_frame = 0; | |
8608 | } | |
8609 | ||
689004fa GV |
8610 | /* Check which frames are still visisble, if we have enqueued any user |
8611 | events or been notified of events that may affect visibility. We | |
8612 | do this here because there doesn't seem to be any direct | |
8613 | notification from Windows that the visibility of a window has | |
8614 | changed (at least, not in all cases). */ | |
8615 | if (count > 0 || check_visibility) | |
8616 | { | |
8617 | Lisp_Object tail, frame; | |
8618 | ||
8619 | FOR_EACH_FRAME (tail, frame) | |
8620 | { | |
8621 | FRAME_PTR f = XFRAME (frame); | |
8622 | /* Check "visible" frames and mark each as obscured or not. | |
8623 | Note that async_visible is nonzero for unobscured and | |
8624 | obscured frames, but zero for hidden and iconified frames. */ | |
8625 | if (FRAME_W32_P (f) && f->async_visible) | |
8626 | { | |
8627 | RECT clipbox; | |
8628 | HDC hdc = get_frame_dc (f); | |
8629 | GetClipBox (hdc, &clipbox); | |
8630 | release_frame_dc (f, hdc); | |
8631 | ||
8632 | if (clipbox.right == clipbox.left | |
8633 | || clipbox.bottom == clipbox.top) | |
8634 | { | |
8635 | /* Frame has become completely obscured so mark as | |
8636 | such (we do this by setting async_visible to 2 so | |
8637 | that FRAME_VISIBLE_P is still true, but redisplay | |
8638 | will skip it). */ | |
8639 | f->async_visible = 2; | |
8640 | ||
8641 | if (!FRAME_OBSCURED_P (f)) | |
8642 | { | |
8643 | DebPrint (("frame %04x (%s) obscured\n", f, | |
8644 | XSTRING (f->name)->data)); | |
8645 | } | |
8646 | } | |
8647 | else | |
8648 | { | |
8649 | /* Frame is not obscured, so mark it as such. */ | |
8650 | f->async_visible = 1; | |
8651 | ||
8652 | if (FRAME_OBSCURED_P (f)) | |
8653 | { | |
8654 | SET_FRAME_GARBAGED (f); | |
8655 | DebPrint (("frame %04x (%s) reexposed\n", f, | |
8656 | XSTRING (f->name)->data)); | |
8657 | ||
8658 | /* Force a redisplay sooner or later. */ | |
8659 | record_asynch_buffer_change (); | |
8660 | } | |
8661 | } | |
8662 | } | |
8663 | } | |
8664 | } | |
8665 | ||
ee78dc32 GV |
8666 | UNBLOCK_INPUT; |
8667 | return count; | |
8668 | } | |
791f420f | 8669 | |
9ef2e2cf JR |
8670 | |
8671 | ||
ee78dc32 | 8672 | \f |
791f420f JR |
8673 | /*********************************************************************** |
8674 | Text Cursor | |
8675 | ***********************************************************************/ | |
8676 | ||
8677 | /* Note if the text cursor of window W has been overwritten by a | |
8678 | drawing operation that outputs N glyphs starting at HPOS in the | |
8679 | line given by output_cursor.vpos. N < 0 means all the rest of the | |
8680 | line after HPOS has been written. */ | |
8681 | ||
8682 | static void | |
8683 | note_overwritten_text_cursor (w, hpos, n) | |
8684 | struct window *w; | |
8685 | int hpos, n; | |
8686 | { | |
8687 | if (updated_area == TEXT_AREA | |
8688 | && output_cursor.vpos == w->phys_cursor.vpos | |
8689 | && hpos <= w->phys_cursor.hpos | |
8690 | && (n < 0 | |
8691 | || hpos + n > w->phys_cursor.hpos)) | |
8692 | w->phys_cursor_on_p = 0; | |
8693 | } | |
8694 | ||
ee78dc32 | 8695 | |
791f420f JR |
8696 | /* Set clipping for output in glyph row ROW. W is the window in which |
8697 | we operate. GC is the graphics context to set clipping in. | |
8698 | WHOLE_LINE_P non-zero means include the areas used for truncation | |
8699 | mark display and alike in the clipping rectangle. | |
ee78dc32 | 8700 | |
791f420f JR |
8701 | ROW may be a text row or, e.g., a mode line. Text rows must be |
8702 | clipped to the interior of the window dedicated to text display, | |
8703 | mode lines must be clipped to the whole window. */ | |
ee78dc32 GV |
8704 | |
8705 | static void | |
791f420f JR |
8706 | w32_clip_to_row (w, row, hdc, whole_line_p) |
8707 | struct window *w; | |
8708 | struct glyph_row *row; | |
8709 | HDC hdc; | |
8710 | int whole_line_p; | |
ee78dc32 | 8711 | { |
791f420f JR |
8712 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
8713 | RECT clip_rect; | |
8714 | int window_x, window_y, window_width, window_height; | |
52cf03a1 | 8715 | |
791f420f | 8716 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); |
52cf03a1 | 8717 | |
791f420f JR |
8718 | clip_rect.left = WINDOW_TO_FRAME_PIXEL_X (w, 0); |
8719 | clip_rect.top = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
8720 | clip_rect.top = max (clip_rect.top, window_y); | |
8721 | clip_rect.right = clip_rect.left + window_width; | |
8722 | clip_rect.bottom = clip_rect.top + row->visible_height; | |
8723 | ||
8724 | /* If clipping to the whole line, including trunc marks, extend | |
9ef2e2cf | 8725 | the rectangle to the left and increase its width. */ |
791f420f JR |
8726 | if (whole_line_p) |
8727 | { | |
8728 | clip_rect.left -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); | |
8729 | clip_rect.right += FRAME_X_FLAGS_AREA_WIDTH (f); | |
8730 | } | |
8731 | ||
8732 | w32_set_clip_rectangle (hdc, &clip_rect); | |
ee78dc32 GV |
8733 | } |
8734 | ||
791f420f JR |
8735 | |
8736 | /* Draw a hollow box cursor on window W in glyph row ROW. */ | |
ee78dc32 GV |
8737 | |
8738 | static void | |
791f420f JR |
8739 | x_draw_hollow_cursor (w, row) |
8740 | struct window *w; | |
8741 | struct glyph_row *row; | |
ee78dc32 | 8742 | { |
791f420f JR |
8743 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
8744 | HDC hdc = get_frame_dc (f); | |
8745 | RECT rect; | |
8746 | int wd; | |
8747 | struct glyph *cursor_glyph; | |
8748 | HBRUSH hb = CreateSolidBrush (f->output_data.w32->cursor_pixel); | |
8749 | ||
8750 | /* Compute frame-relative coordinates from window-relative | |
8751 | coordinates. */ | |
8752 | rect.left = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | |
8753 | rect.top = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) | |
8754 | + row->ascent - w->phys_cursor_ascent); | |
8755 | rect.bottom = rect.top + row->height - 1; | |
8756 | ||
8757 | /* Get the glyph the cursor is on. If we can't tell because | |
8758 | the current matrix is invalid or such, give up. */ | |
8759 | cursor_glyph = get_phys_cursor_glyph (w); | |
8760 | if (cursor_glyph == NULL) | |
ee78dc32 GV |
8761 | return; |
8762 | ||
791f420f JR |
8763 | /* Compute the width of the rectangle to draw. If on a stretch |
8764 | glyph, and `x-stretch-block-cursor' is nil, don't draw a | |
8765 | rectangle as wide as the glyph, but use a canonical character | |
8766 | width instead. */ | |
8767 | wd = cursor_glyph->pixel_width - 1; | |
8768 | if (cursor_glyph->type == STRETCH_GLYPH | |
8769 | && !x_stretch_cursor_p) | |
8770 | wd = min (CANON_X_UNIT (f), wd); | |
8771 | ||
8772 | rect.right = rect.left + wd; | |
8773 | ||
8774 | FrameRect (hdc, &rect, hb); | |
8775 | DeleteObject (hb); | |
8776 | ||
8777 | release_frame_dc (f, hdc); | |
ee78dc32 GV |
8778 | } |
8779 | ||
791f420f JR |
8780 | |
8781 | /* Draw a bar cursor on window W in glyph row ROW. | |
8782 | ||
8783 | Implementation note: One would like to draw a bar cursor with an | |
8784 | angle equal to the one given by the font property XA_ITALIC_ANGLE. | |
8785 | Unfortunately, I didn't find a font yet that has this property set. | |
8786 | --gerd. */ | |
ee78dc32 GV |
8787 | |
8788 | static void | |
9ef2e2cf | 8789 | x_draw_bar_cursor (w, row, width) |
791f420f JR |
8790 | struct window *w; |
8791 | struct glyph_row *row; | |
9ef2e2cf | 8792 | int width; |
ee78dc32 | 8793 | { |
791f420f JR |
8794 | /* If cursor hpos is out of bounds, don't draw garbage. This can |
8795 | happen in mini-buffer windows when switching between echo area | |
8796 | glyphs and mini-buffer. */ | |
8797 | if (w->phys_cursor.hpos < row->used[TEXT_AREA]) | |
8798 | { | |
8799 | struct frame *f = XFRAME (w->frame); | |
8800 | struct glyph *cursor_glyph; | |
8801 | int x; | |
00fe468b | 8802 | HDC hdc; |
791f420f JR |
8803 | |
8804 | cursor_glyph = get_phys_cursor_glyph (w); | |
8805 | if (cursor_glyph == NULL) | |
8806 | return; | |
8807 | ||
158cba56 JR |
8808 | /* If on an image, draw like a normal cursor. That's usually better |
8809 | visible than drawing a bar, esp. if the image is large so that | |
8810 | the bar might not be in the window. */ | |
8811 | if (cursor_glyph->type == IMAGE_GLYPH) | |
8812 | { | |
8813 | struct glyph_row *row; | |
8814 | row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos); | |
8815 | x_draw_phys_cursor_glyph (w, row, DRAW_CURSOR); | |
8816 | } | |
8817 | else | |
8818 | { | |
791f420f | 8819 | |
158cba56 | 8820 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
9ef2e2cf | 8821 | |
158cba56 JR |
8822 | if (width < 0) |
8823 | width = f->output_data.w32->cursor_width; | |
8824 | ||
8825 | hdc = get_frame_dc (f); | |
8826 | w32_fill_area (f, hdc, f->output_data.w32->cursor_pixel, | |
8827 | x, | |
8828 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y), | |
8829 | min (cursor_glyph->pixel_width, width), | |
8830 | row->height); | |
8831 | release_frame_dc (f, hdc); | |
8832 | } | |
791f420f | 8833 | } |
ee78dc32 GV |
8834 | } |
8835 | ||
791f420f JR |
8836 | |
8837 | /* Clear the cursor of window W to background color, and mark the | |
8838 | cursor as not shown. This is used when the text where the cursor | |
8839 | is is about to be rewritten. */ | |
8840 | ||
ee78dc32 | 8841 | static void |
791f420f JR |
8842 | x_clear_cursor (w) |
8843 | struct window *w; | |
ee78dc32 | 8844 | { |
791f420f JR |
8845 | if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p) |
8846 | x_update_window_cursor (w, 0); | |
8847 | } | |
ee78dc32 | 8848 | |
ee78dc32 | 8849 | |
791f420f JR |
8850 | /* Draw the cursor glyph of window W in glyph row ROW. See the |
8851 | comment of x_draw_glyphs for the meaning of HL. */ | |
ee78dc32 | 8852 | |
791f420f JR |
8853 | static void |
8854 | x_draw_phys_cursor_glyph (w, row, hl) | |
8855 | struct window *w; | |
8856 | struct glyph_row *row; | |
8857 | enum draw_glyphs_face hl; | |
8858 | { | |
8859 | /* If cursor hpos is out of bounds, don't draw garbage. This can | |
8860 | happen in mini-buffer windows when switching between echo area | |
8861 | glyphs and mini-buffer. */ | |
8862 | if (w->phys_cursor.hpos < row->used[TEXT_AREA]) | |
ee78dc32 | 8863 | { |
791f420f JR |
8864 | x_draw_glyphs (w, w->phys_cursor.x, row, TEXT_AREA, |
8865 | w->phys_cursor.hpos, w->phys_cursor.hpos + 1, | |
8866 | hl, 0, 0, 0); | |
8867 | ||
8868 | /* When we erase the cursor, and ROW is overlapped by other | |
8869 | rows, make sure that these overlapping parts of other rows | |
8870 | are redrawn. */ | |
8871 | if (hl == DRAW_NORMAL_TEXT && row->overlapped_p) | |
8872 | { | |
8873 | if (row > w->current_matrix->rows | |
8874 | && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1)) | |
8875 | x_fix_overlapping_area (w, row - 1, TEXT_AREA); | |
8876 | ||
8877 | if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w) | |
8878 | && MATRIX_ROW_OVERLAPS_PRED_P (row + 1)) | |
8879 | x_fix_overlapping_area (w, row + 1, TEXT_AREA); | |
8880 | } | |
ee78dc32 | 8881 | } |
791f420f | 8882 | } |
ee78dc32 | 8883 | |
791f420f JR |
8884 | |
8885 | /* Erase the image of a cursor of window W from the screen. */ | |
8886 | ||
8887 | static void | |
8888 | x_erase_phys_cursor (w) | |
8889 | struct window *w; | |
8890 | { | |
8891 | struct frame *f = XFRAME (w->frame); | |
8892 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
8893 | int hpos = w->phys_cursor.hpos; | |
8894 | int vpos = w->phys_cursor.vpos; | |
8895 | int mouse_face_here_p = 0; | |
8896 | struct glyph_matrix *active_glyphs = w->current_matrix; | |
8897 | struct glyph_row *cursor_row; | |
8898 | struct glyph *cursor_glyph; | |
8899 | enum draw_glyphs_face hl; | |
8900 | ||
8901 | /* No cursor displayed or row invalidated => nothing to do on the | |
8902 | screen. */ | |
8903 | if (w->phys_cursor_type == NO_CURSOR) | |
8904 | goto mark_cursor_off; | |
8905 | ||
8906 | /* VPOS >= active_glyphs->nrows means that window has been resized. | |
8907 | Don't bother to erase the cursor. */ | |
8908 | if (vpos >= active_glyphs->nrows) | |
8909 | goto mark_cursor_off; | |
8910 | ||
8911 | /* If row containing cursor is marked invalid, there is nothing we | |
8912 | can do. */ | |
8913 | cursor_row = MATRIX_ROW (active_glyphs, vpos); | |
8914 | if (!cursor_row->enabled_p) | |
8915 | goto mark_cursor_off; | |
8916 | ||
8917 | /* This can happen when the new row is shorter than the old one. | |
8918 | In this case, either x_draw_glyphs or clear_end_of_line | |
8919 | should have cleared the cursor. Note that we wouldn't be | |
8920 | able to erase the cursor in this case because we don't have a | |
8921 | cursor glyph at hand. */ | |
8922 | if (w->phys_cursor.hpos >= cursor_row->used[TEXT_AREA]) | |
8923 | goto mark_cursor_off; | |
8924 | ||
8925 | /* If the cursor is in the mouse face area, redisplay that when | |
8926 | we clear the cursor. */ | |
8927 | if (w == XWINDOW (dpyinfo->mouse_face_window) | |
8928 | && (vpos > dpyinfo->mouse_face_beg_row | |
8929 | || (vpos == dpyinfo->mouse_face_beg_row | |
8930 | && hpos >= dpyinfo->mouse_face_beg_col)) | |
8931 | && (vpos < dpyinfo->mouse_face_end_row | |
8932 | || (vpos == dpyinfo->mouse_face_end_row | |
8933 | && hpos < dpyinfo->mouse_face_end_col)) | |
8934 | /* Don't redraw the cursor's spot in mouse face if it is at the | |
8935 | end of a line (on a newline). The cursor appears there, but | |
8936 | mouse highlighting does not. */ | |
8937 | && cursor_row->used[TEXT_AREA] > hpos) | |
8938 | mouse_face_here_p = 1; | |
8939 | ||
8940 | /* Maybe clear the display under the cursor. */ | |
8941 | if (w->phys_cursor_type == HOLLOW_BOX_CURSOR) | |
ee78dc32 | 8942 | { |
791f420f JR |
8943 | int x; |
8944 | int header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
00fe468b | 8945 | HDC hdc; |
ee78dc32 | 8946 | |
791f420f JR |
8947 | cursor_glyph = get_phys_cursor_glyph (w); |
8948 | if (cursor_glyph == NULL) | |
8949 | goto mark_cursor_off; | |
ee78dc32 | 8950 | |
791f420f | 8951 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
00fe468b JR |
8952 | |
8953 | hdc = get_frame_dc (f); | |
8954 | w32_clear_area (f, hdc, x, | |
791f420f JR |
8955 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, |
8956 | cursor_row->y)), | |
8957 | cursor_glyph->pixel_width, | |
8958 | cursor_row->visible_height); | |
00fe468b | 8959 | release_frame_dc (f, hdc); |
ee78dc32 | 8960 | } |
791f420f JR |
8961 | |
8962 | /* Erase the cursor by redrawing the character underneath it. */ | |
8963 | if (mouse_face_here_p) | |
8964 | hl = DRAW_MOUSE_FACE; | |
8965 | else if (cursor_row->inverse_p) | |
8966 | hl = DRAW_INVERSE_VIDEO; | |
8967 | else | |
8968 | hl = DRAW_NORMAL_TEXT; | |
8969 | x_draw_phys_cursor_glyph (w, cursor_row, hl); | |
8970 | ||
8971 | mark_cursor_off: | |
8972 | w->phys_cursor_on_p = 0; | |
8973 | w->phys_cursor_type = NO_CURSOR; | |
ee78dc32 GV |
8974 | } |
8975 | ||
8976 | ||
791f420f JR |
8977 | /* Display or clear cursor of window W. If ON is zero, clear the |
8978 | cursor. If it is non-zero, display the cursor. If ON is nonzero, | |
8979 | where to put the cursor is specified by HPOS, VPOS, X and Y. */ | |
ee78dc32 | 8980 | |
791f420f JR |
8981 | void |
8982 | x_display_and_set_cursor (w, on, hpos, vpos, x, y) | |
8983 | struct window *w; | |
8984 | int on, hpos, vpos, x, y; | |
ee78dc32 | 8985 | { |
791f420f JR |
8986 | struct frame *f = XFRAME (w->frame); |
8987 | int new_cursor_type; | |
9ef2e2cf | 8988 | int new_cursor_width; |
791f420f JR |
8989 | struct glyph_matrix *current_glyphs; |
8990 | struct glyph_row *glyph_row; | |
8991 | struct glyph *glyph; | |
ee78dc32 GV |
8992 | |
8993 | /* This is pointless on invisible frames, and dangerous on garbaged | |
791f420f JR |
8994 | windows and frames; in the latter case, the frame or window may |
8995 | be in the midst of changing its size, and x and y may be off the | |
8996 | window. */ | |
8997 | if (! FRAME_VISIBLE_P (f) | |
8998 | || FRAME_GARBAGED_P (f) | |
8999 | || vpos >= w->current_matrix->nrows | |
9000 | || hpos >= w->current_matrix->matrix_w) | |
ee78dc32 GV |
9001 | return; |
9002 | ||
9003 | /* If cursor is off and we want it off, return quickly. */ | |
791f420f | 9004 | if (!on && !w->phys_cursor_on_p) |
ee78dc32 GV |
9005 | return; |
9006 | ||
791f420f JR |
9007 | current_glyphs = w->current_matrix; |
9008 | glyph_row = MATRIX_ROW (current_glyphs, vpos); | |
9009 | glyph = glyph_row->glyphs[TEXT_AREA] + hpos; | |
9010 | ||
9011 | /* If cursor row is not enabled, we don't really know where to | |
9012 | display the cursor. */ | |
9013 | if (!glyph_row->enabled_p) | |
9014 | { | |
9015 | w->phys_cursor_on_p = 0; | |
9016 | return; | |
9017 | } | |
9018 | ||
9019 | xassert (interrupt_input_blocked); | |
9020 | ||
9021 | /* Set new_cursor_type to the cursor we want to be displayed. In a | |
9022 | mini-buffer window, we want the cursor only to appear if we are | |
9023 | reading input from this window. For the selected window, we want | |
9024 | the cursor type given by the frame parameter. If explicitly | |
9025 | marked off, draw no cursor. In all other cases, we want a hollow | |
9026 | box cursor. */ | |
9ef2e2cf | 9027 | new_cursor_width = -1; |
791f420f JR |
9028 | if (cursor_in_echo_area |
9029 | && FRAME_HAS_MINIBUF_P (f) | |
9030 | && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window)) | |
9031 | { | |
9032 | if (w == XWINDOW (echo_area_window)) | |
9033 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
9034 | else | |
9035 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
9036 | } | |
9037 | else | |
9038 | { | |
9039 | if (w != XWINDOW (selected_window) | |
9040 | || f != FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame) | |
9041 | { | |
a2bc11d4 JR |
9042 | extern int cursor_in_non_selected_windows; |
9043 | ||
9127e20e JR |
9044 | if (MINI_WINDOW_P (w) |
9045 | || !cursor_in_non_selected_windows | |
9046 | || NILP (XBUFFER (w->buffer)->cursor_type)) | |
791f420f JR |
9047 | new_cursor_type = NO_CURSOR; |
9048 | else | |
9049 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
9050 | } | |
9051 | else if (w->cursor_off_p) | |
9052 | new_cursor_type = NO_CURSOR; | |
9053 | else | |
9ef2e2cf JR |
9054 | { |
9055 | struct buffer *b = XBUFFER (w->buffer); | |
9056 | ||
9057 | if (EQ (b->cursor_type, Qt)) | |
9058 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
9059 | else | |
9060 | new_cursor_type = x_specified_cursor_type (b->cursor_type, | |
9061 | &new_cursor_width); | |
9062 | } | |
791f420f JR |
9063 | } |
9064 | ||
9065 | /* If cursor is currently being shown and we don't want it to be or | |
9066 | it is in the wrong place, or the cursor type is not what we want, | |
ee78dc32 | 9067 | erase it. */ |
791f420f | 9068 | if (w->phys_cursor_on_p |
ee78dc32 | 9069 | && (!on |
791f420f JR |
9070 | || w->phys_cursor.x != x |
9071 | || w->phys_cursor.y != y | |
9072 | || new_cursor_type != w->phys_cursor_type)) | |
9073 | x_erase_phys_cursor (w); | |
9074 | ||
9075 | /* If the cursor is now invisible and we want it to be visible, | |
9076 | display it. */ | |
9077 | if (on && !w->phys_cursor_on_p) | |
9078 | { | |
9079 | w->phys_cursor_ascent = glyph_row->ascent; | |
9080 | w->phys_cursor_height = glyph_row->height; | |
9081 | ||
9082 | /* Set phys_cursor_.* before x_draw_.* is called because some | |
9083 | of them may need the information. */ | |
9084 | w->phys_cursor.x = x; | |
9085 | w->phys_cursor.y = glyph_row->y; | |
9086 | w->phys_cursor.hpos = hpos; | |
9087 | w->phys_cursor.vpos = vpos; | |
9088 | w->phys_cursor_type = new_cursor_type; | |
9089 | w->phys_cursor_on_p = 1; | |
9090 | ||
9091 | switch (new_cursor_type) | |
ee78dc32 | 9092 | { |
791f420f JR |
9093 | case HOLLOW_BOX_CURSOR: |
9094 | x_draw_hollow_cursor (w, glyph_row); | |
9095 | break; | |
9096 | ||
9097 | case FILLED_BOX_CURSOR: | |
9098 | x_draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR); | |
9099 | break; | |
9100 | ||
9101 | case BAR_CURSOR: | |
9ef2e2cf | 9102 | x_draw_bar_cursor (w, glyph_row, new_cursor_width); |
791f420f | 9103 | break; |
ee78dc32 | 9104 | |
791f420f JR |
9105 | case NO_CURSOR: |
9106 | break; | |
9107 | ||
9108 | default: | |
9109 | abort (); | |
9110 | } | |
ee78dc32 GV |
9111 | } |
9112 | } | |
9113 | ||
689004fa | 9114 | |
791f420f JR |
9115 | /* Display the cursor on window W, or clear it. X and Y are window |
9116 | relative pixel coordinates. HPOS and VPOS are glyph matrix | |
9117 | positions. If W is not the selected window, display a hollow | |
9118 | cursor. ON non-zero means display the cursor at X, Y which | |
9119 | correspond to HPOS, VPOS, otherwise it is cleared. */ | |
9120 | ||
9121 | void | |
9122 | x_display_cursor (w, on, hpos, vpos, x, y) | |
9123 | struct window *w; | |
9124 | int on, hpos, vpos, x, y; | |
ee78dc32 GV |
9125 | { |
9126 | BLOCK_INPUT; | |
791f420f JR |
9127 | x_display_and_set_cursor (w, on, hpos, vpos, x, y); |
9128 | UNBLOCK_INPUT; | |
9129 | } | |
9130 | ||
9131 | ||
9132 | /* Display the cursor on window W, or clear it, according to ON_P. | |
9133 | Don't change the cursor's position. */ | |
9134 | ||
9135 | void | |
9136 | x_update_cursor (f, on_p) | |
9137 | struct frame *f; | |
9138 | int on_p; | |
9139 | { | |
9140 | x_update_cursor_in_window_tree (XWINDOW (f->root_window), on_p); | |
9141 | } | |
9142 | ||
9143 | ||
9144 | /* Call x_update_window_cursor with parameter ON_P on all leaf windows | |
9145 | in the window tree rooted at W. */ | |
ee78dc32 | 9146 | |
791f420f JR |
9147 | static void |
9148 | x_update_cursor_in_window_tree (w, on_p) | |
9149 | struct window *w; | |
9150 | int on_p; | |
9151 | { | |
9152 | while (w) | |
689004fa | 9153 | { |
791f420f JR |
9154 | if (!NILP (w->hchild)) |
9155 | x_update_cursor_in_window_tree (XWINDOW (w->hchild), on_p); | |
9156 | else if (!NILP (w->vchild)) | |
9157 | x_update_cursor_in_window_tree (XWINDOW (w->vchild), on_p); | |
9158 | else | |
9159 | x_update_window_cursor (w, on_p); | |
9160 | ||
9161 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
689004fa | 9162 | } |
791f420f | 9163 | } |
689004fa | 9164 | |
ee78dc32 | 9165 | |
791f420f JR |
9166 | /* Switch the display of W's cursor on or off, according to the value |
9167 | of ON. */ | |
9168 | ||
9169 | static void | |
9170 | x_update_window_cursor (w, on) | |
9171 | struct window *w; | |
9172 | int on; | |
9173 | { | |
9ef2e2cf JR |
9174 | /* Don't update cursor in windows whose frame is in the process |
9175 | of being deleted. */ | |
9176 | if (w->current_matrix) | |
9177 | { | |
9178 | BLOCK_INPUT; | |
9179 | x_display_and_set_cursor (w, on, w->phys_cursor.hpos, | |
9180 | w->phys_cursor.vpos, w->phys_cursor.x, | |
9181 | w->phys_cursor.y); | |
9182 | UNBLOCK_INPUT; | |
9183 | } | |
ee78dc32 | 9184 | } |
791f420f JR |
9185 | |
9186 | ||
9ef2e2cf | 9187 | |
ee78dc32 | 9188 | \f |
7f5d1df8 GV |
9189 | /* Icons. */ |
9190 | ||
9191 | int | |
9192 | x_bitmap_icon (f, icon) | |
9193 | struct frame *f; | |
9194 | Lisp_Object icon; | |
9195 | { | |
9196 | int mask, bitmap_id; | |
9197 | Window icon_window; | |
9198 | HANDLE hicon; | |
9199 | ||
9200 | if (FRAME_W32_WINDOW (f) == 0) | |
9201 | return 1; | |
9202 | ||
9203 | if (NILP (icon)) | |
9204 | hicon = LoadIcon (hinst, EMACS_CLASS); | |
9205 | else if (STRINGP (icon)) | |
9206 | hicon = LoadImage (NULL, (LPCTSTR) XSTRING (icon)->data, IMAGE_ICON, 0, 0, | |
9207 | LR_DEFAULTSIZE | LR_LOADFROMFILE); | |
9208 | else if (SYMBOLP (icon)) | |
9209 | { | |
9210 | LPCTSTR name; | |
9211 | ||
9212 | if (EQ (icon, intern ("application"))) | |
9213 | name = (LPCTSTR) IDI_APPLICATION; | |
9214 | else if (EQ (icon, intern ("hand"))) | |
9215 | name = (LPCTSTR) IDI_HAND; | |
9216 | else if (EQ (icon, intern ("question"))) | |
9217 | name = (LPCTSTR) IDI_QUESTION; | |
9218 | else if (EQ (icon, intern ("exclamation"))) | |
9219 | name = (LPCTSTR) IDI_EXCLAMATION; | |
9220 | else if (EQ (icon, intern ("asterisk"))) | |
9221 | name = (LPCTSTR) IDI_ASTERISK; | |
9222 | else if (EQ (icon, intern ("winlogo"))) | |
9223 | name = (LPCTSTR) IDI_WINLOGO; | |
9224 | else | |
9225 | return 1; | |
9226 | ||
9227 | hicon = LoadIcon (NULL, name); | |
9228 | } | |
9229 | else | |
9230 | return 1; | |
9231 | ||
9232 | if (hicon == NULL) | |
9233 | return 1; | |
9234 | ||
791f420f JR |
9235 | PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_BIG, |
9236 | (LPARAM) hicon); | |
7f5d1df8 GV |
9237 | |
9238 | return 0; | |
9239 | } | |
9240 | ||
9241 | \f | |
ee78dc32 GV |
9242 | /* Changing the font of the frame. */ |
9243 | ||
9244 | /* Give frame F the font named FONTNAME as its default font, and | |
9245 | return the full name of that font. FONTNAME may be a wildcard | |
9246 | pattern; in that case, we choose some font that fits the pattern. | |
9247 | The return value shows which font we chose. */ | |
9248 | ||
9249 | Lisp_Object | |
9250 | x_new_font (f, fontname) | |
9251 | struct frame *f; | |
9252 | register char *fontname; | |
9253 | { | |
cabb23bc | 9254 | struct font_info *fontp |
93ff4395 | 9255 | = FS_LOAD_FONT (f, 0, fontname, -1); |
ee78dc32 | 9256 | |
cabb23bc | 9257 | if (!fontp) |
791f420f | 9258 | return Qnil; |
ee78dc32 | 9259 | |
cabb23bc | 9260 | FRAME_FONT (f) = (XFontStruct *) (fontp->font); |
791f420f | 9261 | FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset; |
cabb23bc | 9262 | FRAME_FONTSET (f) = -1; |
ee78dc32 GV |
9263 | |
9264 | /* Compute the scroll bar width in character columns. */ | |
9265 | if (f->scroll_bar_pixel_width > 0) | |
9266 | { | |
ec48c3a7 | 9267 | int wid = FONT_WIDTH (FRAME_FONT (f)); |
ee78dc32 GV |
9268 | f->scroll_bar_cols = (f->scroll_bar_pixel_width + wid-1) / wid; |
9269 | } | |
9270 | else | |
ec48c3a7 JR |
9271 | { |
9272 | int wid = FONT_WIDTH (FRAME_FONT (f)); | |
9273 | f->scroll_bar_cols = (14 + wid - 1) / wid; | |
9274 | } | |
ee78dc32 GV |
9275 | |
9276 | /* Now make the frame display the given font. */ | |
fbd6baed | 9277 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 GV |
9278 | { |
9279 | frame_update_line_height (f); | |
9280 | x_set_window_size (f, 0, f->width, f->height); | |
9281 | } | |
9282 | else | |
9283 | /* If we are setting a new frame's font for the first time, | |
9284 | there are no faces yet, so this font's height is the line height. */ | |
ec48c3a7 | 9285 | f->output_data.w32->line_height = FONT_HEIGHT (FRAME_FONT (f)); |
ee78dc32 | 9286 | |
791f420f | 9287 | return build_string (fontp->full_name); |
ee78dc32 GV |
9288 | } |
9289 | \f | |
cabb23bc GV |
9290 | /* Give frame F the fontset named FONTSETNAME as its default font, and |
9291 | return the full name of that fontset. FONTSETNAME may be a wildcard | |
9292 | pattern; in that case, we choose some fontset that fits the pattern. | |
9293 | The return value shows which fontset we chose. */ | |
9294 | ||
9295 | Lisp_Object | |
9296 | x_new_fontset (f, fontsetname) | |
9297 | struct frame *f; | |
9298 | char *fontsetname; | |
9299 | { | |
93ff4395 | 9300 | int fontset = fs_query_fontset (build_string (fontsetname), 0); |
cabb23bc | 9301 | Lisp_Object result; |
93ff4395 | 9302 | char *fontname; |
cabb23bc GV |
9303 | |
9304 | if (fontset < 0) | |
9305 | return Qnil; | |
9306 | ||
9307 | if (FRAME_FONTSET (f) == fontset) | |
9308 | /* This fontset is already set in frame F. There's nothing more | |
9309 | to do. */ | |
93ff4395 | 9310 | return fontset_name (fontset); |
cabb23bc | 9311 | |
93ff4395 | 9312 | result = x_new_font (f, (XSTRING (fontset_ascii (fontset))->data)); |
cabb23bc GV |
9313 | |
9314 | if (!STRINGP (result)) | |
9315 | /* Can't load ASCII font. */ | |
9316 | return Qnil; | |
9317 | ||
9318 | /* Since x_new_font doesn't update any fontset information, do it now. */ | |
9319 | FRAME_FONTSET(f) = fontset; | |
cabb23bc GV |
9320 | |
9321 | return build_string (fontsetname); | |
9322 | } | |
791f420f JR |
9323 | |
9324 | ||
9325 | #if GLYPH_DEBUG | |
9326 | ||
9327 | /* Check that FONT is valid on frame F. It is if it can be found in F's | |
9328 | font table. */ | |
9329 | ||
9330 | static void | |
9331 | x_check_font (f, font) | |
9332 | struct frame *f; | |
9333 | XFontStruct *font; | |
9334 | { | |
9335 | int i; | |
9336 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
9337 | ||
9338 | xassert (font != NULL); | |
9339 | ||
9340 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
9341 | if (dpyinfo->font_table[i].name | |
9342 | && font == dpyinfo->font_table[i].font) | |
9343 | break; | |
9344 | ||
9345 | xassert (i < dpyinfo->n_fonts); | |
9346 | } | |
9347 | ||
9348 | #endif /* GLYPH_DEBUG != 0 */ | |
9349 | ||
9350 | /* Set *W to the minimum width, *H to the minimum font height of FONT. | |
9351 | Note: There are (broken) X fonts out there with invalid XFontStruct | |
9352 | min_bounds contents. For example, handa@etl.go.jp reports that | |
9353 | "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts | |
9354 | have font->min_bounds.width == 0. */ | |
9355 | ||
9356 | static INLINE void | |
9357 | x_font_min_bounds (font, w, h) | |
9358 | XFontStruct *font; | |
9359 | int *w, *h; | |
9360 | { | |
158cba56 | 9361 | /* |
01b220b6 | 9362 | * TODO: Windows does not appear to offer min bound, only |
158cba56 JR |
9363 | * average and maximum width, and maximum height. |
9364 | */ | |
791f420f JR |
9365 | *h = FONT_HEIGHT (font); |
9366 | *w = FONT_WIDTH (font); | |
791f420f JR |
9367 | } |
9368 | ||
9369 | ||
9370 | /* Compute the smallest character width and smallest font height over | |
9371 | all fonts available on frame F. Set the members smallest_char_width | |
9372 | and smallest_font_height in F's x_display_info structure to | |
9373 | the values computed. Value is non-zero if smallest_font_height or | |
9374 | smallest_char_width become smaller than they were before. */ | |
9375 | ||
9376 | int | |
9377 | x_compute_min_glyph_bounds (f) | |
9378 | struct frame *f; | |
9379 | { | |
9380 | int i; | |
9381 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
9382 | XFontStruct *font; | |
9383 | int old_width = dpyinfo->smallest_char_width; | |
9384 | int old_height = dpyinfo->smallest_font_height; | |
9385 | ||
9386 | dpyinfo->smallest_font_height = 100000; | |
9387 | dpyinfo->smallest_char_width = 100000; | |
9388 | ||
9389 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
9390 | if (dpyinfo->font_table[i].name) | |
9391 | { | |
9392 | struct font_info *fontp = dpyinfo->font_table + i; | |
9393 | int w, h; | |
9394 | ||
9395 | font = (XFontStruct *) fontp->font; | |
9396 | xassert (font != (XFontStruct *) ~0); | |
9397 | x_font_min_bounds (font, &w, &h); | |
9398 | ||
9399 | dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h); | |
9400 | dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w); | |
9401 | } | |
9402 | ||
9403 | xassert (dpyinfo->smallest_char_width > 0 | |
9404 | && dpyinfo->smallest_font_height > 0); | |
9405 | ||
9406 | return (dpyinfo->n_fonts == 1 | |
9407 | || dpyinfo->smallest_char_width < old_width | |
9408 | || dpyinfo->smallest_font_height < old_height); | |
9409 | } | |
9410 | ||
cabb23bc | 9411 | \f |
689004fa GV |
9412 | /* Calculate the absolute position in frame F |
9413 | from its current recorded position values and gravity. */ | |
9414 | ||
9ef2e2cf | 9415 | void |
ee78dc32 GV |
9416 | x_calc_absolute_position (f) |
9417 | struct frame *f; | |
9418 | { | |
791f420f | 9419 | Window child; |
ee78dc32 | 9420 | POINT pt; |
fbd6baed | 9421 | int flags = f->output_data.w32->size_hint_flags; |
ee78dc32 GV |
9422 | |
9423 | pt.x = pt.y = 0; | |
9424 | ||
9425 | /* Find the position of the outside upper-left corner of | |
9426 | the inner window, with respect to the outer window. */ | |
fbd6baed | 9427 | if (f->output_data.w32->parent_desc != FRAME_W32_DISPLAY_INFO (f)->root_window) |
ee78dc32 GV |
9428 | { |
9429 | BLOCK_INPUT; | |
fbd6baed GV |
9430 | MapWindowPoints (FRAME_W32_WINDOW (f), |
9431 | f->output_data.w32->parent_desc, | |
ee78dc32 GV |
9432 | &pt, 1); |
9433 | UNBLOCK_INPUT; | |
9434 | } | |
9435 | ||
9436 | { | |
9437 | RECT rt; | |
9438 | rt.left = rt.right = rt.top = rt.bottom = 0; | |
9439 | ||
9440 | BLOCK_INPUT; | |
fbd6baed | 9441 | AdjustWindowRect(&rt, f->output_data.w32->dwStyle, |
97c23857 | 9442 | FRAME_EXTERNAL_MENU_BAR (f)); |
ee78dc32 GV |
9443 | UNBLOCK_INPUT; |
9444 | ||
9445 | pt.x += (rt.right - rt.left); | |
9446 | pt.y += (rt.bottom - rt.top); | |
9447 | } | |
9448 | ||
9449 | /* Treat negative positions as relative to the leftmost bottommost | |
9450 | position that fits on the screen. */ | |
9451 | if (flags & XNegative) | |
fbd6baed GV |
9452 | f->output_data.w32->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width |
9453 | - 2 * f->output_data.w32->border_width - pt.x | |
ee78dc32 | 9454 | - PIXEL_WIDTH (f) |
fbd6baed | 9455 | + f->output_data.w32->left_pos); |
158cba56 | 9456 | |
ee78dc32 | 9457 | if (flags & YNegative) |
fbd6baed GV |
9458 | f->output_data.w32->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height |
9459 | - 2 * f->output_data.w32->border_width - pt.y | |
ee78dc32 | 9460 | - PIXEL_HEIGHT (f) |
fbd6baed | 9461 | + f->output_data.w32->top_pos); |
ee78dc32 GV |
9462 | /* The left_pos and top_pos |
9463 | are now relative to the top and left screen edges, | |
9464 | so the flags should correspond. */ | |
fbd6baed | 9465 | f->output_data.w32->size_hint_flags &= ~ (XNegative | YNegative); |
ee78dc32 GV |
9466 | } |
9467 | ||
9468 | /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position, | |
9469 | to really change the position, and 0 when calling from | |
9470 | x_make_frame_visible (in that case, XOFF and YOFF are the current | |
9471 | position values). It is -1 when calling from x_set_frame_parameters, | |
9472 | which means, do adjust for borders but don't change the gravity. */ | |
9473 | ||
9ef2e2cf | 9474 | void |
ee78dc32 GV |
9475 | x_set_offset (f, xoff, yoff, change_gravity) |
9476 | struct frame *f; | |
9477 | register int xoff, yoff; | |
9478 | int change_gravity; | |
9479 | { | |
9480 | int modified_top, modified_left; | |
9481 | ||
9482 | if (change_gravity > 0) | |
9483 | { | |
fbd6baed GV |
9484 | f->output_data.w32->top_pos = yoff; |
9485 | f->output_data.w32->left_pos = xoff; | |
9486 | f->output_data.w32->size_hint_flags &= ~ (XNegative | YNegative); | |
ee78dc32 | 9487 | if (xoff < 0) |
fbd6baed | 9488 | f->output_data.w32->size_hint_flags |= XNegative; |
ee78dc32 | 9489 | if (yoff < 0) |
fbd6baed GV |
9490 | f->output_data.w32->size_hint_flags |= YNegative; |
9491 | f->output_data.w32->win_gravity = NorthWestGravity; | |
ee78dc32 GV |
9492 | } |
9493 | x_calc_absolute_position (f); | |
9494 | ||
9495 | BLOCK_INPUT; | |
9496 | x_wm_set_size_hint (f, (long) 0, 0); | |
9497 | ||
fbd6baed GV |
9498 | modified_left = f->output_data.w32->left_pos; |
9499 | modified_top = f->output_data.w32->top_pos; | |
ee78dc32 | 9500 | |
fbd6baed | 9501 | my_set_window_pos (FRAME_W32_WINDOW (f), |
52cf03a1 GV |
9502 | NULL, |
9503 | modified_left, modified_top, | |
cabb23bc | 9504 | 0, 0, |
689004fa | 9505 | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); |
ee78dc32 GV |
9506 | UNBLOCK_INPUT; |
9507 | } | |
9508 | ||
9509 | /* Call this to change the size of frame F's x-window. | |
9510 | If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity | |
9511 | for this size change and subsequent size changes. | |
9512 | Otherwise we leave the window gravity unchanged. */ | |
791f420f | 9513 | void |
ee78dc32 GV |
9514 | x_set_window_size (f, change_gravity, cols, rows) |
9515 | struct frame *f; | |
9516 | int change_gravity; | |
9517 | int cols, rows; | |
9518 | { | |
9519 | int pixelwidth, pixelheight; | |
9520 | ||
9521 | BLOCK_INPUT; | |
9522 | ||
9523 | check_frame_size (f, &rows, &cols); | |
fbd6baed | 9524 | f->output_data.w32->vertical_scroll_bar_extra |
ee78dc32 GV |
9525 | = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f) |
9526 | ? 0 | |
fbd6baed | 9527 | : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->output_data.w32->font))); |
791f420f JR |
9528 | f->output_data.w32->flags_areas_extra |
9529 | = FRAME_FLAGS_AREA_WIDTH (f); | |
ee78dc32 GV |
9530 | pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols); |
9531 | pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows); | |
9532 | ||
fbd6baed | 9533 | f->output_data.w32->win_gravity = NorthWestGravity; |
ee78dc32 GV |
9534 | x_wm_set_size_hint (f, (long) 0, 0); |
9535 | ||
9536 | { | |
9537 | RECT rect; | |
9538 | ||
9539 | rect.left = rect.top = 0; | |
9540 | rect.right = pixelwidth; | |
9541 | rect.bottom = pixelheight; | |
9542 | ||
fbd6baed | 9543 | AdjustWindowRect(&rect, f->output_data.w32->dwStyle, |
97c23857 | 9544 | FRAME_EXTERNAL_MENU_BAR (f)); |
ee78dc32 | 9545 | |
fbd6baed | 9546 | my_set_window_pos (FRAME_W32_WINDOW (f), |
52cf03a1 GV |
9547 | NULL, |
9548 | 0, 0, | |
689004fa GV |
9549 | rect.right - rect.left, |
9550 | rect.bottom - rect.top, | |
9551 | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); | |
ee78dc32 GV |
9552 | } |
9553 | ||
9554 | /* Now, strictly speaking, we can't be sure that this is accurate, | |
9555 | but the window manager will get around to dealing with the size | |
9556 | change request eventually, and we'll hear how it went when the | |
9557 | ConfigureNotify event gets here. | |
9558 | ||
9559 | We could just not bother storing any of this information here, | |
9560 | and let the ConfigureNotify event set everything up, but that | |
ec48c3a7 | 9561 | might be kind of confusing to the Lisp code, since size changes |
ee78dc32 | 9562 | wouldn't be reported in the frame parameters until some random |
791f420f JR |
9563 | point in the future when the ConfigureNotify event arrives. |
9564 | ||
9565 | We pass 1 for DELAY since we can't run Lisp code inside of | |
9566 | a BLOCK_INPUT. */ | |
9567 | change_frame_size (f, rows, cols, 0, 1, 0); | |
ee78dc32 GV |
9568 | PIXEL_WIDTH (f) = pixelwidth; |
9569 | PIXEL_HEIGHT (f) = pixelheight; | |
9570 | ||
689004fa GV |
9571 | /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to |
9572 | receive in the ConfigureNotify event; if we get what we asked | |
9573 | for, then the event won't cause the screen to become garbaged, so | |
9574 | we have to make sure to do it here. */ | |
9575 | SET_FRAME_GARBAGED (f); | |
9576 | ||
ee78dc32 | 9577 | /* If cursor was outside the new size, mark it as off. */ |
791f420f | 9578 | mark_window_cursors_off (XWINDOW (f->root_window)); |
ee78dc32 | 9579 | |
689004fa GV |
9580 | /* Clear out any recollection of where the mouse highlighting was, |
9581 | since it might be in a place that's outside the new frame size. | |
9582 | Actually checking whether it is outside is a pain in the neck, | |
9583 | so don't try--just let the highlighting be done afresh with new size. */ | |
31d4844a KH |
9584 | cancel_mouse_face (f); |
9585 | ||
ee78dc32 GV |
9586 | UNBLOCK_INPUT; |
9587 | } | |
9588 | \f | |
9589 | /* Mouse warping. */ | |
9590 | ||
ec48c3a7 JR |
9591 | void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y); |
9592 | ||
9593 | void | |
9594 | x_set_mouse_position (f, x, y) | |
9595 | struct frame *f; | |
9596 | int x, y; | |
9597 | { | |
9598 | int pix_x, pix_y; | |
9599 | ||
9600 | pix_x = CHAR_TO_PIXEL_COL (f, x) + FONT_WIDTH (f->output_data.w32->font) / 2; | |
9601 | pix_y = CHAR_TO_PIXEL_ROW (f, y) + f->output_data.w32->line_height / 2; | |
9602 | ||
9603 | if (pix_x < 0) pix_x = 0; | |
9604 | if (pix_x > PIXEL_WIDTH (f)) pix_x = PIXEL_WIDTH (f); | |
9605 | ||
9606 | if (pix_y < 0) pix_y = 0; | |
9607 | if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f); | |
9608 | ||
9609 | x_set_mouse_pixel_position (f, pix_x, pix_y); | |
9610 | } | |
9611 | ||
1bcd16f2 MB |
9612 | void |
9613 | x_set_mouse_pixel_position (f, pix_x, pix_y) | |
9614 | struct frame *f; | |
9615 | int pix_x, pix_y; | |
9616 | { | |
689004fa GV |
9617 | RECT rect; |
9618 | POINT pt; | |
9619 | ||
1bcd16f2 MB |
9620 | BLOCK_INPUT; |
9621 | ||
689004fa GV |
9622 | GetClientRect (FRAME_W32_WINDOW (f), &rect); |
9623 | pt.x = rect.left + pix_x; | |
9624 | pt.y = rect.top + pix_y; | |
9625 | ClientToScreen (FRAME_W32_WINDOW (f), &pt); | |
1bcd16f2 | 9626 | |
689004fa | 9627 | SetCursorPos (pt.x, pt.y); |
1bcd16f2 MB |
9628 | |
9629 | UNBLOCK_INPUT; | |
9630 | } | |
9631 | ||
ee78dc32 GV |
9632 | \f |
9633 | /* focus shifting, raising and lowering. */ | |
9634 | ||
ec48c3a7 | 9635 | void |
ee78dc32 GV |
9636 | x_focus_on_frame (f) |
9637 | struct frame *f; | |
9638 | { | |
689004fa GV |
9639 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
9640 | ||
9641 | /* Give input focus to frame. */ | |
9642 | BLOCK_INPUT; | |
9643 | #if 0 | |
9644 | /* Try not to change its Z-order if possible. */ | |
9645 | if (x_window_to_frame (dpyinfo, GetForegroundWindow ())) | |
9646 | my_set_focus (f, FRAME_W32_WINDOW (f)); | |
9647 | else | |
9648 | #endif | |
ef0e360f | 9649 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa | 9650 | UNBLOCK_INPUT; |
ee78dc32 GV |
9651 | } |
9652 | ||
ec48c3a7 | 9653 | void |
ee78dc32 GV |
9654 | x_unfocus_frame (f) |
9655 | struct frame *f; | |
9656 | { | |
9657 | } | |
9658 | ||
9659 | /* Raise frame F. */ | |
791f420f | 9660 | void |
ee78dc32 GV |
9661 | x_raise_frame (f) |
9662 | struct frame *f; | |
9663 | { | |
689004fa GV |
9664 | BLOCK_INPUT; |
9665 | ||
9666 | /* Strictly speaking, raise-frame should only change the frame's Z | |
9667 | order, leaving input focus unchanged. This is reasonable behaviour | |
9668 | on X where the usual policy is point-to-focus. However, this | |
9669 | behaviour would be very odd on Windows where the usual policy is | |
9670 | click-to-focus. | |
9671 | ||
9672 | On X, if the mouse happens to be over the raised frame, it gets | |
9673 | input focus anyway (so the window with focus will never be | |
9674 | completely obscured) - if not, then just moving the mouse over it | |
9675 | is sufficient to give it focus. On Windows, the user must actually | |
9676 | click on the frame (preferrably the title bar so as not to move | |
9677 | point), which is more awkward. Also, no other Windows program | |
9678 | raises a window to the top but leaves another window (possibly now | |
9679 | completely obscured) with input focus. | |
9680 | ||
9681 | Because there is a system setting on Windows that allows the user | |
9682 | to choose the point to focus policy, we make the strict semantics | |
9683 | optional, but by default we grab focus when raising. */ | |
9684 | ||
9685 | if (NILP (Vw32_grab_focus_on_raise)) | |
ee78dc32 | 9686 | { |
689004fa GV |
9687 | /* The obvious call to my_set_window_pos doesn't work if Emacs is |
9688 | not already the foreground application: the frame is raised | |
9689 | above all other frames belonging to us, but not above the | |
9690 | current top window. To achieve that, we have to resort to this | |
9691 | more cumbersome method. */ | |
9692 | ||
9693 | HDWP handle = BeginDeferWindowPos (2); | |
9694 | if (handle) | |
9695 | { | |
9696 | DeferWindowPos (handle, | |
9697 | FRAME_W32_WINDOW (f), | |
9698 | HWND_TOP, | |
9699 | 0, 0, 0, 0, | |
9700 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
9701 | ||
9702 | DeferWindowPos (handle, | |
9703 | GetForegroundWindow (), | |
9704 | FRAME_W32_WINDOW (f), | |
9705 | 0, 0, 0, 0, | |
9706 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
9707 | ||
9708 | EndDeferWindowPos (handle); | |
9709 | } | |
ee78dc32 | 9710 | } |
689004fa GV |
9711 | else |
9712 | { | |
ef0e360f | 9713 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa GV |
9714 | } |
9715 | ||
9716 | UNBLOCK_INPUT; | |
ee78dc32 GV |
9717 | } |
9718 | ||
9719 | /* Lower frame F. */ | |
791f420f | 9720 | void |
ee78dc32 GV |
9721 | x_lower_frame (f) |
9722 | struct frame *f; | |
9723 | { | |
689004fa GV |
9724 | BLOCK_INPUT; |
9725 | my_set_window_pos (FRAME_W32_WINDOW (f), | |
9726 | HWND_BOTTOM, | |
9727 | 0, 0, 0, 0, | |
9728 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
9729 | UNBLOCK_INPUT; | |
ee78dc32 GV |
9730 | } |
9731 | ||
9732 | static void | |
ec48c3a7 | 9733 | w32_frame_raise_lower (f, raise_flag) |
ee78dc32 | 9734 | FRAME_PTR f; |
ec48c3a7 | 9735 | int raise_flag; |
ee78dc32 | 9736 | { |
ec48c3a7 | 9737 | if (raise_flag) |
ee78dc32 GV |
9738 | x_raise_frame (f); |
9739 | else | |
9740 | x_lower_frame (f); | |
9741 | } | |
9742 | \f | |
9743 | /* Change of visibility. */ | |
9744 | ||
9745 | /* This tries to wait until the frame is really visible. | |
9746 | However, if the window manager asks the user where to position | |
9747 | the frame, this will return before the user finishes doing that. | |
9748 | The frame will not actually be visible at that time, | |
9749 | but it will become visible later when the window manager | |
9750 | finishes with it. */ | |
9751 | ||
ec48c3a7 | 9752 | void |
ee78dc32 GV |
9753 | x_make_frame_visible (f) |
9754 | struct frame *f; | |
9755 | { | |
7f5d1df8 GV |
9756 | Lisp_Object type; |
9757 | ||
ee78dc32 GV |
9758 | BLOCK_INPUT; |
9759 | ||
7f5d1df8 GV |
9760 | type = x_icon_type (f); |
9761 | if (!NILP (type)) | |
9762 | x_bitmap_icon (f, type); | |
9763 | ||
ee78dc32 GV |
9764 | if (! FRAME_VISIBLE_P (f)) |
9765 | { | |
9766 | /* We test FRAME_GARBAGED_P here to make sure we don't | |
9767 | call x_set_offset a second time | |
9768 | if we get to x_make_frame_visible a second time | |
9769 | before the window gets really visible. */ | |
9770 | if (! FRAME_ICONIFIED_P (f) | |
fbd6baed | 9771 | && ! f->output_data.w32->asked_for_visible) |
fbd6baed | 9772 | x_set_offset (f, f->output_data.w32->left_pos, f->output_data.w32->top_pos, 0); |
ee78dc32 | 9773 | |
fbd6baed | 9774 | f->output_data.w32->asked_for_visible = 1; |
52cf03a1 | 9775 | |
689004fa GV |
9776 | // my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW); |
9777 | my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL); | |
ee78dc32 GV |
9778 | } |
9779 | ||
9780 | /* Synchronize to ensure Emacs knows the frame is visible | |
9781 | before we do anything else. We do this loop with input not blocked | |
9782 | so that incoming events are handled. */ | |
9783 | { | |
9784 | Lisp_Object frame; | |
791f420f | 9785 | int count; |
ee78dc32 GV |
9786 | |
9787 | /* This must come after we set COUNT. */ | |
9788 | UNBLOCK_INPUT; | |
9789 | ||
9790 | XSETFRAME (frame, f); | |
9791 | ||
791f420f JR |
9792 | /* Wait until the frame is visible. Process X events until a |
9793 | MapNotify event has been seen, or until we think we won't get a | |
9794 | MapNotify at all.. */ | |
9795 | for (count = input_signal_count + 10; | |
9796 | input_signal_count < count && !FRAME_VISIBLE_P (f);) | |
ee78dc32 | 9797 | { |
791f420f | 9798 | /* Force processing of queued events. */ |
01b220b6 | 9799 | /* TODO: x_sync equivalent? */ |
791f420f | 9800 | |
ee78dc32 GV |
9801 | /* Machines that do polling rather than SIGIO have been observed |
9802 | to go into a busy-wait here. So we'll fake an alarm signal | |
9803 | to let the handler know that there's something to be read. | |
9804 | We used to raise a real alarm, but it seems that the handler | |
9805 | isn't always enabled here. This is probably a bug. */ | |
9806 | if (input_polling_used ()) | |
9807 | { | |
9808 | /* It could be confusing if a real alarm arrives while processing | |
9809 | the fake one. Turn it off and let the handler reset it. */ | |
a9b4e0ec AI |
9810 | int old_poll_suppress_count = poll_suppress_count; |
9811 | poll_suppress_count = 1; | |
9812 | poll_for_input_1 (); | |
9813 | poll_suppress_count = old_poll_suppress_count; | |
ee78dc32 | 9814 | } |
ee78dc32 GV |
9815 | } |
9816 | FRAME_SAMPLE_VISIBILITY (f); | |
9817 | } | |
9818 | } | |
9819 | ||
9820 | /* Change from mapped state to withdrawn state. */ | |
9821 | ||
9822 | /* Make the frame visible (mapped and not iconified). */ | |
9823 | ||
9824 | x_make_frame_invisible (f) | |
9825 | struct frame *f; | |
9826 | { | |
ee78dc32 | 9827 | /* Don't keep the highlight on an invisible frame. */ |
fbd6baed GV |
9828 | if (FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame == f) |
9829 | FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame = 0; | |
ee78dc32 GV |
9830 | |
9831 | BLOCK_INPUT; | |
9832 | ||
689004fa | 9833 | my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE); |
ee78dc32 GV |
9834 | |
9835 | /* We can't distinguish this from iconification | |
9836 | just by the event that we get from the server. | |
9837 | So we can't win using the usual strategy of letting | |
9838 | FRAME_SAMPLE_VISIBILITY set this. So do it by hand, | |
9839 | and synchronize with the server to make sure we agree. */ | |
9840 | f->visible = 0; | |
9841 | FRAME_ICONIFIED_P (f) = 0; | |
9842 | f->async_visible = 0; | |
9843 | f->async_iconified = 0; | |
9844 | ||
9845 | UNBLOCK_INPUT; | |
9846 | } | |
9847 | ||
9848 | /* Change window state from mapped to iconified. */ | |
9849 | ||
52cf03a1 GV |
9850 | void |
9851 | x_iconify_frame (f) | |
ee78dc32 GV |
9852 | struct frame *f; |
9853 | { | |
9854 | int result; | |
7f5d1df8 | 9855 | Lisp_Object type; |
ee78dc32 GV |
9856 | |
9857 | /* Don't keep the highlight on an invisible frame. */ | |
fbd6baed GV |
9858 | if (FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame == f) |
9859 | FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame = 0; | |
ee78dc32 GV |
9860 | |
9861 | if (f->async_iconified) | |
9862 | return; | |
9863 | ||
9864 | BLOCK_INPUT; | |
9865 | ||
7f5d1df8 GV |
9866 | type = x_icon_type (f); |
9867 | if (!NILP (type)) | |
9868 | x_bitmap_icon (f, type); | |
9869 | ||
689004fa | 9870 | /* Simulate the user minimizing the frame. */ |
4934bcdd | 9871 | SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0); |
ee78dc32 GV |
9872 | |
9873 | UNBLOCK_INPUT; | |
9874 | } | |
9875 | \f | |
9876 | /* Destroy the window of frame F. */ | |
9877 | ||
9878 | x_destroy_window (f) | |
9879 | struct frame *f; | |
9880 | { | |
fbd6baed | 9881 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
ee78dc32 GV |
9882 | |
9883 | BLOCK_INPUT; | |
9884 | ||
fbd6baed | 9885 | my_destroy_window (f, FRAME_W32_WINDOW (f)); |
ee78dc32 GV |
9886 | free_frame_menubar (f); |
9887 | free_frame_faces (f); | |
9888 | ||
fbd6baed GV |
9889 | xfree (f->output_data.w32); |
9890 | f->output_data.w32 = 0; | |
9891 | if (f == dpyinfo->w32_focus_frame) | |
9892 | dpyinfo->w32_focus_frame = 0; | |
9893 | if (f == dpyinfo->w32_focus_event_frame) | |
9894 | dpyinfo->w32_focus_event_frame = 0; | |
9895 | if (f == dpyinfo->w32_highlight_frame) | |
9896 | dpyinfo->w32_highlight_frame = 0; | |
ee78dc32 GV |
9897 | |
9898 | dpyinfo->reference_count--; | |
9899 | ||
9900 | if (f == dpyinfo->mouse_face_mouse_frame) | |
9901 | { | |
9902 | dpyinfo->mouse_face_beg_row | |
9903 | = dpyinfo->mouse_face_beg_col = -1; | |
9904 | dpyinfo->mouse_face_end_row | |
9905 | = dpyinfo->mouse_face_end_col = -1; | |
9906 | dpyinfo->mouse_face_window = Qnil; | |
9907 | } | |
9908 | ||
9909 | UNBLOCK_INPUT; | |
9910 | } | |
9911 | \f | |
9912 | /* Setting window manager hints. */ | |
9913 | ||
9914 | /* Set the normal size hints for the window manager, for frame F. | |
9915 | FLAGS is the flags word to use--or 0 meaning preserve the flags | |
9916 | that the window now has. | |
9917 | If USER_POSITION is nonzero, we set the USPosition | |
9918 | flag (this is useful when FLAGS is 0). */ | |
791f420f | 9919 | void |
ee78dc32 GV |
9920 | x_wm_set_size_hint (f, flags, user_position) |
9921 | struct frame *f; | |
9922 | long flags; | |
9923 | int user_position; | |
9924 | { | |
fbd6baed | 9925 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 | 9926 | |
97c23857 | 9927 | enter_crit (); |
ee78dc32 | 9928 | |
689004fa GV |
9929 | SetWindowLong (window, WND_FONTWIDTH_INDEX, FONT_WIDTH (f->output_data.w32->font)); |
9930 | SetWindowLong (window, WND_LINEHEIGHT_INDEX, f->output_data.w32->line_height); | |
9931 | SetWindowLong (window, WND_BORDER_INDEX, f->output_data.w32->internal_border_width); | |
9932 | SetWindowLong (window, WND_SCROLLBAR_INDEX, f->output_data.w32->vertical_scroll_bar_extra); | |
ee78dc32 | 9933 | |
97c23857 | 9934 | leave_crit (); |
ee78dc32 GV |
9935 | } |
9936 | ||
9937 | /* Window manager things */ | |
9938 | x_wm_set_icon_position (f, icon_x, icon_y) | |
9939 | struct frame *f; | |
9940 | int icon_x, icon_y; | |
9941 | { | |
9942 | #if 0 | |
fbd6baed | 9943 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 GV |
9944 | |
9945 | f->display.x->wm_hints.flags |= IconPositionHint; | |
9946 | f->display.x->wm_hints.icon_x = icon_x; | |
9947 | f->display.x->wm_hints.icon_y = icon_y; | |
9948 | ||
9949 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints); | |
9950 | #endif | |
9951 | } | |
9952 | ||
9ef2e2cf | 9953 | |
ee78dc32 | 9954 | \f |
791f420f JR |
9955 | /*********************************************************************** |
9956 | Initialization | |
9957 | ***********************************************************************/ | |
ee78dc32 | 9958 | |
fbd6baed | 9959 | static int w32_initialized = 0; |
ee78dc32 | 9960 | |
f7737f5d JR |
9961 | void |
9962 | w32_initialize_display_info (display_name) | |
9963 | Lisp_Object display_name; | |
9964 | { | |
9965 | struct w32_display_info *dpyinfo = &one_w32_display_info; | |
9966 | ||
9967 | bzero (dpyinfo, sizeof (*dpyinfo)); | |
9968 | ||
9969 | /* Put it on w32_display_name_list. */ | |
9970 | w32_display_name_list = Fcons (Fcons (display_name, Qnil), | |
9971 | w32_display_name_list); | |
9972 | dpyinfo->name_list_element = XCAR (w32_display_name_list); | |
9973 | ||
9974 | dpyinfo->w32_id_name | |
9975 | = (char *) xmalloc (XSTRING (Vinvocation_name)->size | |
9976 | + XSTRING (Vsystem_name)->size | |
9977 | + 2); | |
9978 | sprintf (dpyinfo->w32_id_name, "%s@%s", | |
9979 | XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data); | |
9980 | ||
9981 | /* Default Console mode values - overridden when running in GUI mode | |
9982 | with values obtained from system metrics. */ | |
9983 | dpyinfo->resx = 1; | |
9984 | dpyinfo->resy = 1; | |
9985 | dpyinfo->height_in = 1; | |
9986 | dpyinfo->width_in = 1; | |
9987 | dpyinfo->n_planes = 1; | |
9988 | dpyinfo->n_cbits = 4; | |
9989 | dpyinfo->n_fonts = 0; | |
9990 | dpyinfo->smallest_font_height = 1; | |
9991 | dpyinfo->smallest_char_width = 1; | |
9992 | ||
9993 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
9994 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
9995 | dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; | |
9996 | dpyinfo->mouse_face_window = Qnil; | |
9997 | ||
01b220b6 | 9998 | /* TODO: dpyinfo->gray */ |
f7737f5d JR |
9999 | |
10000 | } | |
10001 | ||
fbd6baed GV |
10002 | struct w32_display_info * |
10003 | w32_term_init (display_name, xrm_option, resource_name) | |
ee78dc32 GV |
10004 | Lisp_Object display_name; |
10005 | char *xrm_option; | |
10006 | char *resource_name; | |
10007 | { | |
fbd6baed | 10008 | struct w32_display_info *dpyinfo; |
ee78dc32 | 10009 | HDC hdc; |
97c23857 | 10010 | |
ee78dc32 GV |
10011 | BLOCK_INPUT; |
10012 | ||
fbd6baed | 10013 | if (!w32_initialized) |
ee78dc32 | 10014 | { |
fbd6baed GV |
10015 | w32_initialize (); |
10016 | w32_initialized = 1; | |
ee78dc32 GV |
10017 | } |
10018 | ||
10019 | { | |
10020 | int argc = 0; | |
10021 | char *argv[3]; | |
10022 | ||
10023 | argv[0] = ""; | |
10024 | argc = 1; | |
10025 | if (xrm_option) | |
10026 | { | |
10027 | argv[argc++] = "-xrm"; | |
10028 | argv[argc++] = xrm_option; | |
10029 | } | |
10030 | } | |
10031 | ||
f7737f5d | 10032 | w32_initialize_display_info (display_name); |
ee78dc32 | 10033 | |
f7737f5d | 10034 | dpyinfo = &one_w32_display_info; |
ee78dc32 | 10035 | |
52cf03a1 | 10036 | hdc = GetDC (GetDesktopWindow ()); |
791f420f | 10037 | |
ee78dc32 GV |
10038 | dpyinfo->height = GetDeviceCaps (hdc, VERTRES); |
10039 | dpyinfo->width = GetDeviceCaps (hdc, HORZRES); | |
10040 | dpyinfo->root_window = GetDesktopWindow (); | |
10041 | dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES); | |
10042 | dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL); | |
55689ab1 JR |
10043 | dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX); |
10044 | dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY); | |
52cf03a1 | 10045 | dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE; |
791f420f | 10046 | dpyinfo->image_cache = make_image_cache (); |
55689ab1 JR |
10047 | dpyinfo->height_in = dpyinfo->height / dpyinfo->resx; |
10048 | dpyinfo->width_in = dpyinfo->width / dpyinfo->resy; | |
ee78dc32 | 10049 | ReleaseDC (GetDesktopWindow (), hdc); |
52cf03a1 GV |
10050 | |
10051 | /* initialise palette with white and black */ | |
10052 | { | |
10053 | COLORREF color; | |
55689ab1 JR |
10054 | w32_defined_color (0, "white", &color, 1); |
10055 | w32_defined_color (0, "black", &color, 1); | |
52cf03a1 GV |
10056 | } |
10057 | ||
f7737f5d JR |
10058 | /* Create Row Bitmaps and store them for later use. */ |
10059 | left_bmp = CreateBitmap (left_width, left_height, 1, 1, left_bits); | |
10060 | ov_bmp = CreateBitmap (ov_width, ov_height, 1, 1, ov_bits); | |
10061 | right_bmp = CreateBitmap (right_width, right_height, 1, 1, right_bits); | |
10062 | continued_bmp = CreateBitmap (continued_width, continued_height, 1, | |
10063 | 1, continued_bits); | |
10064 | continuation_bmp = CreateBitmap (continuation_width, continuation_height, | |
10065 | 1, 1, continuation_bits); | |
10066 | zv_bmp = CreateBitmap (zv_width, zv_height, 1, 1, zv_bits); | |
10067 | ||
ee78dc32 GV |
10068 | #ifndef F_SETOWN_BUG |
10069 | #ifdef F_SETOWN | |
10070 | #ifdef F_SETOWN_SOCK_NEG | |
10071 | /* stdin is a socket here */ | |
10072 | fcntl (connection, F_SETOWN, -getpid ()); | |
10073 | #else /* ! defined (F_SETOWN_SOCK_NEG) */ | |
10074 | fcntl (connection, F_SETOWN, getpid ()); | |
10075 | #endif /* ! defined (F_SETOWN_SOCK_NEG) */ | |
10076 | #endif /* ! defined (F_SETOWN) */ | |
10077 | #endif /* F_SETOWN_BUG */ | |
10078 | ||
10079 | #ifdef SIGIO | |
10080 | if (interrupt_input) | |
10081 | init_sigio (connection); | |
10082 | #endif /* ! defined (SIGIO) */ | |
10083 | ||
10084 | UNBLOCK_INPUT; | |
10085 | ||
10086 | return dpyinfo; | |
10087 | } | |
10088 | \f | |
10089 | /* Get rid of display DPYINFO, assuming all frames are already gone. */ | |
10090 | ||
10091 | void | |
10092 | x_delete_display (dpyinfo) | |
fbd6baed | 10093 | struct w32_display_info *dpyinfo; |
ee78dc32 | 10094 | { |
fbd6baed | 10095 | /* Discard this display from w32_display_name_list and w32_display_list. |
ee78dc32 | 10096 | We can't use Fdelq because that can quit. */ |
fbd6baed | 10097 | if (! NILP (w32_display_name_list) |
8e713be6 KR |
10098 | && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element)) |
10099 | w32_display_name_list = XCDR (w32_display_name_list); | |
ee78dc32 GV |
10100 | else |
10101 | { | |
10102 | Lisp_Object tail; | |
10103 | ||
fbd6baed | 10104 | tail = w32_display_name_list; |
8e713be6 | 10105 | while (CONSP (tail) && CONSP (XCDR (tail))) |
ee78dc32 | 10106 | { |
f7737f5d | 10107 | if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element)) |
ee78dc32 | 10108 | { |
8e713be6 | 10109 | XCDR (tail) = XCDR (XCDR (tail)); |
ee78dc32 GV |
10110 | break; |
10111 | } | |
8e713be6 | 10112 | tail = XCDR (tail); |
ee78dc32 GV |
10113 | } |
10114 | } | |
10115 | ||
52cf03a1 GV |
10116 | /* free palette table */ |
10117 | { | |
fbd6baed | 10118 | struct w32_palette_entry * plist; |
52cf03a1 GV |
10119 | |
10120 | plist = dpyinfo->color_list; | |
10121 | while (plist) | |
10122 | { | |
fbd6baed | 10123 | struct w32_palette_entry * pentry = plist; |
52cf03a1 | 10124 | plist = plist->next; |
9127e20e | 10125 | xfree (pentry); |
52cf03a1 GV |
10126 | } |
10127 | dpyinfo->color_list = NULL; | |
10128 | if (dpyinfo->palette) | |
10129 | DeleteObject(dpyinfo->palette); | |
10130 | } | |
ee78dc32 | 10131 | xfree (dpyinfo->font_table); |
fbd6baed | 10132 | xfree (dpyinfo->w32_id_name); |
f7737f5d JR |
10133 | |
10134 | /* Destroy row bitmaps. */ | |
10135 | DeleteObject (left_bmp); | |
10136 | DeleteObject (ov_bmp); | |
10137 | DeleteObject (right_bmp); | |
10138 | DeleteObject (continued_bmp); | |
10139 | DeleteObject (continuation_bmp); | |
10140 | DeleteObject (zv_bmp); | |
ee78dc32 GV |
10141 | } |
10142 | \f | |
fbd6baed | 10143 | /* Set up use of W32. */ |
ee78dc32 | 10144 | |
689004fa | 10145 | DWORD w32_msg_worker (); |
ee78dc32 | 10146 | |
791f420f JR |
10147 | void |
10148 | x_flush (struct frame * f) | |
10149 | { /* Nothing to do */ } | |
10150 | ||
10151 | static struct redisplay_interface w32_redisplay_interface = | |
10152 | { | |
10153 | x_produce_glyphs, | |
10154 | x_write_glyphs, | |
10155 | x_insert_glyphs, | |
10156 | x_clear_end_of_line, | |
10157 | x_scroll_run, | |
10158 | x_after_update_window_line, | |
10159 | x_update_window_begin, | |
10160 | x_update_window_end, | |
10161 | w32_cursor_to, | |
10162 | x_flush, | |
ec48c3a7 | 10163 | x_clear_mouse_face, |
791f420f JR |
10164 | x_get_glyph_overhangs, |
10165 | x_fix_overlapping_area | |
10166 | }; | |
10167 | ||
10168 | void | |
fbd6baed GV |
10169 | w32_initialize () |
10170 | { | |
791f420f JR |
10171 | rif = &w32_redisplay_interface; |
10172 | ||
96214669 GV |
10173 | /* MSVC does not type K&R functions with no arguments correctly, and |
10174 | so we must explicitly cast them. */ | |
791f420f JR |
10175 | clear_frame_hook = (void (*)(void)) x_clear_frame; |
10176 | ins_del_lines_hook = x_ins_del_lines; | |
10177 | change_line_highlight_hook = x_change_line_highlight; | |
10178 | delete_glyphs_hook = x_delete_glyphs; | |
96214669 GV |
10179 | ring_bell_hook = (void (*)(void)) w32_ring_bell; |
10180 | reset_terminal_modes_hook = (void (*)(void)) w32_reset_terminal_modes; | |
10181 | set_terminal_modes_hook = (void (*)(void)) w32_set_terminal_modes; | |
791f420f JR |
10182 | update_begin_hook = x_update_begin; |
10183 | update_end_hook = x_update_end; | |
fbd6baed | 10184 | set_terminal_window_hook = w32_set_terminal_window; |
ee78dc32 | 10185 | read_socket_hook = w32_read_socket; |
fbd6baed | 10186 | frame_up_to_date_hook = w32_frame_up_to_date; |
fbd6baed GV |
10187 | reassert_line_highlight_hook = w32_reassert_line_highlight; |
10188 | mouse_position_hook = w32_mouse_position; | |
10189 | frame_rehighlight_hook = w32_frame_rehighlight; | |
10190 | frame_raise_lower_hook = w32_frame_raise_lower; | |
10191 | set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar; | |
10192 | condemn_scroll_bars_hook = w32_condemn_scroll_bars; | |
10193 | redeem_scroll_bar_hook = w32_redeem_scroll_bar; | |
10194 | judge_scroll_bars_hook = w32_judge_scroll_bars; | |
791f420f | 10195 | estimate_mode_line_height_hook = x_estimate_mode_line_height; |
ee78dc32 GV |
10196 | |
10197 | scroll_region_ok = 1; /* we'll scroll partial frames */ | |
10198 | char_ins_del_ok = 0; /* just as fast to write the line */ | |
10199 | line_ins_del_ok = 1; /* we'll just blt 'em */ | |
10200 | fast_clear_end_of_line = 1; /* X does this well */ | |
10201 | memory_below_frame = 0; /* we don't remember what scrolls | |
10202 | off the bottom */ | |
10203 | baud_rate = 19200; | |
10204 | ||
791f420f JR |
10205 | last_tool_bar_item = -1; |
10206 | any_help_event_p = 0; | |
10207 | ||
689004fa GV |
10208 | /* Initialize input mode: interrupt_input off, no flow control, allow |
10209 | 8 bit character input, standard quit char. */ | |
10210 | Fset_input_mode (Qnil, Qnil, make_number (2), Qnil); | |
ee78dc32 GV |
10211 | |
10212 | /* Create the window thread - it will terminate itself or when the app terminates */ | |
10213 | ||
10214 | init_crit (); | |
10215 | ||
10216 | dwMainThreadId = GetCurrentThreadId (); | |
10217 | DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), | |
10218 | GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS); | |
10219 | ||
10220 | /* Wait for thread to start */ | |
10221 | ||
10222 | { | |
10223 | MSG msg; | |
10224 | ||
10225 | PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); | |
10226 | ||
e9e23e23 | 10227 | hWindowsThread = CreateThread (NULL, 0, |
689004fa | 10228 | (LPTHREAD_START_ROUTINE) w32_msg_worker, |
e9e23e23 | 10229 | 0, 0, &dwWindowsThreadId); |
ee78dc32 GV |
10230 | |
10231 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
10232 | } | |
10233 | ||
52cf03a1 | 10234 | /* It is desirable that mainThread should have the same notion of |
e9e23e23 | 10235 | focus window and active window as windowsThread. Unfortunately, the |
52cf03a1 GV |
10236 | following call to AttachThreadInput, which should do precisely what |
10237 | we need, causes major problems when Emacs is linked as a console | |
10238 | program. Unfortunately, we have good reasons for doing that, so | |
e9e23e23 | 10239 | instead we need to send messages to windowsThread to make some API |
52cf03a1 GV |
10240 | calls for us (ones that affect, or depend on, the active/focus |
10241 | window state. */ | |
10242 | #ifdef ATTACH_THREADS | |
e9e23e23 | 10243 | AttachThreadInput (dwMainThreadId, dwWindowsThreadId, TRUE); |
52cf03a1 | 10244 | #endif |
689004fa GV |
10245 | |
10246 | /* Dynamically link to optional system components. */ | |
10247 | { | |
10248 | HANDLE user_lib = LoadLibrary ("user32.dll"); | |
10249 | ||
10250 | #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn) | |
10251 | ||
10252 | /* New proportional scroll bar functions. */ | |
9127e20e JR |
10253 | LOAD_PROC (SetScrollInfo); |
10254 | LOAD_PROC (GetScrollInfo); | |
689004fa GV |
10255 | |
10256 | #undef LOAD_PROC | |
10257 | ||
10258 | FreeLibrary (user_lib); | |
10259 | ||
10260 | /* If using proportional scroll bars, ensure handle is at least 5 pixels; | |
10261 | otherwise use the fixed height. */ | |
10262 | vertical_scroll_bar_min_handle = (pfnSetScrollInfo != NULL) ? 5 : | |
10263 | GetSystemMetrics (SM_CYVTHUMB); | |
10264 | ||
10265 | /* For either kind of scroll bar, take account of the arrows; these | |
10266 | effectively form the border of the main scroll bar range. */ | |
10267 | vertical_scroll_bar_top_border = vertical_scroll_bar_bottom_border | |
10268 | = GetSystemMetrics (SM_CYVSCROLL); | |
10269 | } | |
ee78dc32 GV |
10270 | } |
10271 | ||
10272 | void | |
fbd6baed | 10273 | syms_of_w32term () |
ee78dc32 | 10274 | { |
fbd6baed GV |
10275 | staticpro (&w32_display_name_list); |
10276 | w32_display_name_list = Qnil; | |
ee78dc32 GV |
10277 | |
10278 | staticpro (&last_mouse_scroll_bar); | |
10279 | last_mouse_scroll_bar = Qnil; | |
10280 | ||
10281 | staticpro (&Qvendor_specific_keysyms); | |
10282 | Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); | |
52cf03a1 | 10283 | |
fbd6baed GV |
10284 | DEFVAR_INT ("w32-num-mouse-buttons", |
10285 | &Vw32_num_mouse_buttons, | |
52cf03a1 | 10286 | "Number of physical mouse buttons."); |
fbd6baed | 10287 | Vw32_num_mouse_buttons = Qnil; |
52cf03a1 | 10288 | |
fbd6baed GV |
10289 | DEFVAR_LISP ("w32-swap-mouse-buttons", |
10290 | &Vw32_swap_mouse_buttons, | |
52cf03a1 GV |
10291 | "Swap the mapping of middle and right mouse buttons.\n\ |
10292 | When nil, middle button is mouse-2 and right button is mouse-3."); | |
fbd6baed | 10293 | Vw32_swap_mouse_buttons = Qnil; |
689004fa GV |
10294 | |
10295 | DEFVAR_LISP ("w32-grab-focus-on-raise", | |
10296 | &Vw32_grab_focus_on_raise, | |
10297 | "Raised frame grabs input focus.\n\ | |
10298 | When t, `raise-frame' grabs input focus as well. This fits well\n\ | |
10299 | with the normal Windows click-to-focus policy, but might not be\n\ | |
10300 | desirable when using a point-to-focus policy."); | |
10301 | Vw32_grab_focus_on_raise = Qt; | |
10302 | ||
10303 | DEFVAR_LISP ("w32-capslock-is-shiftlock", | |
10304 | &Vw32_capslock_is_shiftlock, | |
10305 | "Apply CapsLock state to non character input keys.\n\ | |
10306 | When nil, CapsLock only affects normal character input keys."); | |
10307 | Vw32_capslock_is_shiftlock = Qnil; | |
ef0e360f GV |
10308 | |
10309 | DEFVAR_LISP ("w32-recognize-altgr", | |
10310 | &Vw32_recognize_altgr, | |
10311 | "Recognize right-alt and left-ctrl as AltGr.\n\ | |
10312 | When nil, the right-alt and left-ctrl key combination is\n\ | |
10313 | interpreted normally."); | |
10314 | Vw32_recognize_altgr = Qt; | |
bc6af935 | 10315 | |
484fa2c1 GV |
10316 | DEFVAR_BOOL ("w32-enable-unicode-output", |
10317 | &w32_enable_unicode_output, | |
10318 | "Enable the use of Unicode for text output if non-nil.\n\ | |
cabb23bc GV |
10319 | Unicode output may prevent some third party applications for displaying\n\ |
10320 | Far-East Languages on Windows 95/98 from working properly.\n\ | |
10321 | NT uses Unicode internally anyway, so this flag will probably have no\n\ | |
10322 | affect on NT machines."); | |
484fa2c1 | 10323 | w32_enable_unicode_output = 1; |
a1b9438c | 10324 | |
791f420f | 10325 | help_echo = Qnil; |
ec48c3a7 JR |
10326 | staticpro (&help_echo); |
10327 | help_echo_object = Qnil; | |
10328 | staticpro (&help_echo_object); | |
158cba56 JR |
10329 | help_echo_window = Qnil; |
10330 | staticpro (&help_echo_window); | |
791f420f | 10331 | previous_help_echo = Qnil; |
ec48c3a7 | 10332 | staticpro (&previous_help_echo); |
158cba56 | 10333 | help_echo_pos = -1; |
791f420f JR |
10334 | |
10335 | DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p, | |
10336 | "*Non-nil means draw block cursor as wide as the glyph under it.\n\ | |
10337 | For example, if a block cursor is over a tab, it will be drawn as\n\ | |
10338 | wide as that tab on the display."); | |
10339 | x_stretch_cursor_p = 0; | |
10340 | ||
10341 | DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p, | |
10342 | "If not nil, Emacs uses toolkit scroll bars."); | |
10343 | x_toolkit_scroll_bars_p = 1; | |
10344 | ||
10345 | staticpro (&last_mouse_motion_frame); | |
10346 | last_mouse_motion_frame = Qnil; | |
ee78dc32 | 10347 | } |