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 | |
99012074 | 547 | each window being updated. */ |
ee78dc32 | 548 | |
96214669 | 549 | static void |
791f420f | 550 | x_update_begin (f) |
ee78dc32 GV |
551 | struct frame *f; |
552 | { | |
99012074 AI |
553 | struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); |
554 | ||
555 | /* Regenerate display palette before drawing if list of requested | |
556 | colors has changed. */ | |
557 | if (display_info->regen_palette) | |
558 | { | |
559 | w32_regenerate_palette (f); | |
560 | display_info->regen_palette = FALSE; | |
561 | } | |
791f420f | 562 | } |
ee78dc32 | 563 | |
791f420f JR |
564 | |
565 | /* Start update of window W. Set the global variable updated_window | |
566 | to the window being updated and set output_cursor to the cursor | |
567 | position of W. */ | |
568 | ||
569 | static void | |
570 | x_update_window_begin (w) | |
571 | struct window *w; | |
572 | { | |
573 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
574 | struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); | |
575 | ||
576 | updated_window = w; | |
577 | set_output_cursor (&w->cursor); | |
ee78dc32 GV |
578 | |
579 | BLOCK_INPUT; | |
580 | ||
791f420f | 581 | if (f == display_info->mouse_face_mouse_frame) |
ee78dc32 GV |
582 | { |
583 | /* Don't do highlighting for mouse motion during the update. */ | |
791f420f | 584 | display_info->mouse_face_defer = 1; |
ee78dc32 | 585 | |
9ef2e2cf JR |
586 | /* If F needs to be redrawn, simply forget about any prior mouse |
587 | highlighting. */ | |
ee78dc32 | 588 | if (FRAME_GARBAGED_P (f)) |
791f420f JR |
589 | display_info->mouse_face_window = Qnil; |
590 | ||
ec48c3a7 JR |
591 | #if 0 /* Rows in a current matrix containing glyphs in mouse-face have |
592 | their mouse_face_p flag set, which means that they are always | |
593 | unequal to rows in a desired matrix which never have that | |
594 | flag set. So, rows containing mouse-face glyphs are never | |
595 | scrolled, and we don't have to switch the mouse highlight off | |
596 | here to prevent it from being scrolled. */ | |
597 | ||
791f420f JR |
598 | /* Can we tell that this update does not affect the window |
599 | where the mouse highlight is? If so, no need to turn off. | |
600 | Likewise, don't do anything if the frame is garbaged; | |
601 | in that case, the frame's current matrix that we would use | |
602 | is all wrong, and we will redisplay that line anyway. */ | |
603 | if (!NILP (display_info->mouse_face_window) | |
604 | && w == XWINDOW (display_info->mouse_face_window)) | |
ee78dc32 | 605 | { |
791f420f | 606 | int i; |
ee78dc32 | 607 | |
791f420f JR |
608 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
609 | if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) | |
ee78dc32 GV |
610 | break; |
611 | ||
791f420f JR |
612 | if (i < w->desired_matrix->nrows) |
613 | clear_mouse_face (display_info); | |
ee78dc32 | 614 | } |
ec48c3a7 | 615 | #endif /* 0 */ |
ee78dc32 GV |
616 | } |
617 | ||
618 | UNBLOCK_INPUT; | |
619 | } | |
620 | ||
791f420f JR |
621 | |
622 | /* Draw a vertical window border to the right of window W if W doesn't | |
623 | have vertical scroll bars. */ | |
624 | ||
96214669 | 625 | static void |
791f420f JR |
626 | x_draw_vertical_border (w) |
627 | struct window *w; | |
ee78dc32 | 628 | { |
791f420f JR |
629 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
630 | ||
631 | /* Redraw borders between horizontally adjacent windows. Don't | |
632 | do it for frames with vertical scroll bars because either the | |
633 | right scroll bar of a window, or the left scroll bar of its | |
634 | neighbor will suffice as a border. */ | |
635 | if (!WINDOW_RIGHTMOST_P (w) | |
636 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
637 | { | |
638 | RECT r; | |
00fe468b | 639 | HDC hdc; |
ee78dc32 | 640 | |
791f420f JR |
641 | window_box_edges (w, -1, &r.left, &r.top, &r.right, &r.bottom); |
642 | r.left = r.right + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f); | |
643 | r.right = r.left + 1; | |
644 | r.bottom -= 1; | |
ee78dc32 | 645 | |
00fe468b | 646 | hdc = get_frame_dc (f); |
e4a52412 | 647 | w32_fill_rect (f, hdc, FRAME_FOREGROUND_PIXEL (f), &r); |
00fe468b | 648 | release_frame_dc (f, hdc); |
791f420f JR |
649 | } |
650 | } | |
ee78dc32 | 651 | |
791f420f | 652 | |
ec48c3a7 JR |
653 | /* End update of window W (which is equal to updated_window). |
654 | ||
655 | Draw vertical borders between horizontally adjacent windows, and | |
656 | display W's cursor if CURSOR_ON_P is non-zero. | |
657 | ||
658 | MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing | |
659 | glyphs in mouse-face were overwritten. In that case we have to | |
660 | make sure that the mouse-highlight is properly redrawn. | |
661 | ||
662 | W may be a menu bar pseudo-window in case we don't have X toolkit | |
663 | support. Such windows don't have a cursor, so don't display it | |
664 | here. */ | |
791f420f JR |
665 | |
666 | static void | |
ec48c3a7 | 667 | x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p) |
791f420f | 668 | struct window *w; |
ec48c3a7 | 669 | int cursor_on_p, mouse_face_overwritten_p; |
791f420f JR |
670 | { |
671 | if (!w->pseudo_window_p) | |
672 | { | |
ec48c3a7 JR |
673 | struct w32_display_info *dpyinfo |
674 | = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); | |
675 | ||
791f420f | 676 | BLOCK_INPUT; |
ec48c3a7 JR |
677 | |
678 | /* If a row with mouse-face was overwritten, arrange for | |
679 | XTframe_up_to_date to redisplay the mouse highlight. */ | |
680 | if (mouse_face_overwritten_p) | |
681 | { | |
682 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
683 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
684 | dpyinfo->mouse_face_window = Qnil; | |
685 | } | |
686 | ||
791f420f JR |
687 | if (cursor_on_p) |
688 | x_display_and_set_cursor (w, 1, output_cursor.hpos, | |
689 | output_cursor.vpos, | |
690 | output_cursor.x, output_cursor.y); | |
691 | x_draw_vertical_border (w); | |
692 | UNBLOCK_INPUT; | |
693 | } | |
694 | ||
695 | updated_window = NULL; | |
696 | } | |
697 | ||
9ef2e2cf JR |
698 | |
699 | /* End update of frame F. This function is installed as a hook in | |
700 | update_end. */ | |
701 | ||
791f420f JR |
702 | static void |
703 | x_update_end (f) | |
704 | struct frame *f; | |
705 | { | |
706 | /* Mouse highlight may be displayed again. */ | |
707 | FRAME_W32_DISPLAY_INFO (f)->mouse_face_defer = 0; | |
ee78dc32 GV |
708 | } |
709 | ||
9ef2e2cf | 710 | |
791f420f JR |
711 | /* This function is called from various places in xdisp.c whenever a |
712 | complete update has been performed. The global variable | |
713 | updated_window is not available here. */ | |
ee78dc32 | 714 | |
96214669 | 715 | static void |
fbd6baed | 716 | w32_frame_up_to_date (f) |
791f420f | 717 | struct frame *f; |
ee78dc32 | 718 | { |
791f420f | 719 | if (FRAME_W32_P (f)) |
ee78dc32 | 720 | { |
791f420f JR |
721 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
722 | if (dpyinfo->mouse_face_deferred_gc | |
723 | || f == dpyinfo->mouse_face_mouse_frame) | |
724 | { | |
725 | BLOCK_INPUT; | |
726 | if (dpyinfo->mouse_face_mouse_frame) | |
727 | note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, | |
728 | dpyinfo->mouse_face_mouse_x, | |
729 | dpyinfo->mouse_face_mouse_y); | |
730 | dpyinfo->mouse_face_deferred_gc = 0; | |
731 | UNBLOCK_INPUT; | |
732 | } | |
ee78dc32 GV |
733 | } |
734 | } | |
791f420f JR |
735 | |
736 | ||
737 | /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay | |
738 | arrow bitmaps, or clear the areas where they would be displayed | |
739 | before DESIRED_ROW is made current. The window being updated is | |
740 | found in updated_window. This function It is called from | |
741 | update_window_line only if it is known that there are differences | |
742 | between bitmaps to be drawn between current row and DESIRED_ROW. */ | |
743 | ||
744 | static void | |
745 | x_after_update_window_line (desired_row) | |
746 | struct glyph_row *desired_row; | |
747 | { | |
748 | struct window *w = updated_window; | |
749 | ||
750 | xassert (w); | |
751 | ||
752 | if (!desired_row->mode_line_p && !w->pseudo_window_p) | |
753 | { | |
754 | BLOCK_INPUT; | |
755 | x_draw_row_bitmaps (w, desired_row); | |
756 | ||
757 | /* When a window has disappeared, make sure that no rest of | |
758 | full-width rows stays visible in the internal border. */ | |
759 | if (windows_or_buffers_changed) | |
760 | { | |
761 | struct frame *f = XFRAME (w->frame); | |
762 | int width = FRAME_INTERNAL_BORDER_WIDTH (f); | |
763 | int height = desired_row->visible_height; | |
764 | int x = (window_box_right (w, -1) | |
765 | + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f)); | |
766 | int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); | |
00fe468b | 767 | HDC hdc = get_frame_dc (f); |
791f420f | 768 | |
00fe468b JR |
769 | w32_clear_area (f, hdc, x, y, width, height); |
770 | release_frame_dc (f, hdc); | |
791f420f JR |
771 | } |
772 | ||
773 | UNBLOCK_INPUT; | |
774 | } | |
775 | } | |
776 | ||
777 | ||
778 | /* Draw the bitmap WHICH in one of the areas to the left or right of | |
779 | window W. ROW is the glyph row for which to display the bitmap; it | |
780 | determines the vertical position at which the bitmap has to be | |
781 | drawn. */ | |
782 | ||
783 | static void | |
00fe468b | 784 | w32_draw_bitmap (w, hdc, row, which) |
791f420f | 785 | struct window *w; |
00fe468b | 786 | HDC hdc; |
791f420f JR |
787 | struct glyph_row *row; |
788 | enum bitmap_type which; | |
789 | { | |
790 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
791 | Window window = FRAME_W32_WINDOW (f); | |
791f420f JR |
792 | HDC compat_hdc; |
793 | int x, y, wd, h, dy; | |
791f420f JR |
794 | HBITMAP pixmap; |
795 | HBRUSH fg_brush, orig_brush; | |
796 | HANDLE horig_obj; | |
797 | struct face *face; | |
798 | ||
799 | /* Must clip because of partially visible lines. */ | |
800 | w32_clip_to_row (w, row, hdc, 1); | |
801 | ||
802 | switch (which) | |
803 | { | |
804 | case LEFT_TRUNCATION_BITMAP: | |
805 | wd = left_width; | |
806 | h = left_height; | |
f7737f5d | 807 | pixmap = left_bmp; |
791f420f JR |
808 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
809 | - wd | |
810 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
811 | break; | |
812 | ||
813 | case OVERLAY_ARROW_BITMAP: | |
814 | wd = ov_width; | |
815 | h = ov_height; | |
f7737f5d | 816 | pixmap = ov_bmp; |
791f420f JR |
817 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
818 | - wd | |
819 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
820 | break; | |
821 | ||
822 | case RIGHT_TRUNCATION_BITMAP: | |
823 | wd = right_width; | |
824 | h = right_height; | |
f7737f5d | 825 | pixmap = right_bmp; |
791f420f JR |
826 | x = window_box_right (w, -1); |
827 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; | |
828 | break; | |
829 | ||
830 | case CONTINUED_LINE_BITMAP: | |
831 | wd = continued_width; | |
832 | h = continued_height; | |
f7737f5d | 833 | pixmap = continued_bmp; |
791f420f JR |
834 | x = window_box_right (w, -1); |
835 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; | |
836 | break; | |
837 | ||
838 | case CONTINUATION_LINE_BITMAP: | |
839 | wd = continuation_width; | |
840 | h = continuation_height; | |
f7737f5d | 841 | pixmap = continuation_bmp; |
791f420f JR |
842 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
843 | - wd | |
844 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
845 | break; | |
846 | ||
847 | case ZV_LINE_BITMAP: | |
848 | wd = zv_width; | |
849 | h = zv_height; | |
f7737f5d | 850 | pixmap = zv_bmp; |
791f420f JR |
851 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) |
852 | - wd | |
853 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); | |
854 | break; | |
855 | ||
856 | default: | |
857 | abort (); | |
858 | } | |
859 | ||
860 | /* Convert to frame coordinates. Set dy to the offset in the row to | |
861 | start drawing the bitmap. */ | |
862 | y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
863 | dy = (row->height - h) / 2; | |
864 | ||
f7737f5d | 865 | /* Draw the bitmap. */ |
791f420f | 866 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); |
791f420f JR |
867 | |
868 | compat_hdc = CreateCompatibleDC (hdc); | |
869 | SaveDC (hdc); | |
92bb977f | 870 | fg_brush = CreateSolidBrush (face->foreground); |
791f420f JR |
871 | orig_brush = SelectObject (hdc, fg_brush); |
872 | horig_obj = SelectObject (compat_hdc, pixmap); | |
92bb977f JR |
873 | SetTextColor (hdc, face->foreground); |
874 | SetBkColor (hdc, face->background); | |
791f420f | 875 | #if 0 /* From w32bdf.c (which is from Meadow). */ |
92bb977f | 876 | /* Old versions - in case we find a reason to fall back on them. */ |
791f420f | 877 | BitBlt (hdc, x, y + dy, wd, h, compat_hdc, 0, 0, SRCCOPY); |
791f420f | 878 | BitBlt (hdc, x, y + dy, wd, h, compat_hdc, 0, 0, 0xB8074A); |
92bb977f JR |
879 | #else |
880 | BitBlt (hdc, x, y + dy, wd, h, compat_hdc, 0, 0, 0xE20746); | |
791f420f JR |
881 | #endif |
882 | SelectObject (compat_hdc, horig_obj); | |
883 | SelectObject (hdc, orig_brush); | |
791f420f JR |
884 | DeleteObject (fg_brush); |
885 | DeleteDC (compat_hdc); | |
886 | RestoreDC (hdc, -1); | |
791f420f JR |
887 | } |
888 | ||
889 | ||
890 | /* Draw flags bitmaps for glyph row ROW on window W. Call this | |
891 | function with input blocked. */ | |
892 | ||
893 | static void | |
894 | x_draw_row_bitmaps (w, row) | |
895 | struct window *w; | |
896 | struct glyph_row *row; | |
897 | { | |
898 | struct frame *f = XFRAME (w->frame); | |
899 | enum bitmap_type bitmap; | |
900 | struct face *face; | |
901 | int header_line_height = -1; | |
902 | HDC hdc = get_frame_dc (f); | |
903 | ||
904 | xassert (interrupt_input_blocked); | |
905 | ||
906 | /* If row is completely invisible, because of vscrolling, we | |
907 | don't have to draw anything. */ | |
908 | if (row->visible_height <= 0) | |
909 | return; | |
910 | ||
911 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); | |
912 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
913 | ||
914 | /* Decide which bitmap to draw at the left side. */ | |
915 | if (row->overlay_arrow_p) | |
916 | bitmap = OVERLAY_ARROW_BITMAP; | |
917 | else if (row->truncated_on_left_p) | |
918 | bitmap = LEFT_TRUNCATION_BITMAP; | |
919 | else if (MATRIX_ROW_CONTINUATION_LINE_P (row)) | |
920 | bitmap = CONTINUATION_LINE_BITMAP; | |
921 | else if (row->indicate_empty_line_p) | |
922 | bitmap = ZV_LINE_BITMAP; | |
923 | else | |
924 | bitmap = NO_BITMAP; | |
925 | ||
926 | /* Clear flags area if no bitmap to draw or if bitmap doesn't fill | |
927 | the flags area. */ | |
928 | if (bitmap == NO_BITMAP | |
929 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) | |
930 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) | |
931 | { | |
932 | /* If W has a vertical border to its left, don't draw over it. */ | |
933 | int border = ((XFASTINT (w->left) > 0 | |
934 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
935 | ? 1 : 0); | |
936 | int left = window_box_left (w, -1); | |
937 | ||
938 | if (header_line_height < 0) | |
939 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
940 | ||
941 | w32_fill_area (f, hdc, face->background, | |
942 | left - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) + border, | |
943 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
944 | row->y)), | |
945 | FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - border, | |
946 | row->visible_height); | |
947 | } | |
948 | ||
949 | /* Draw the left bitmap. */ | |
950 | if (bitmap != NO_BITMAP) | |
951 | w32_draw_bitmap (w, hdc, row, bitmap); | |
952 | ||
953 | /* Decide which bitmap to draw at the right side. */ | |
954 | if (row->truncated_on_right_p) | |
955 | bitmap = RIGHT_TRUNCATION_BITMAP; | |
956 | else if (row->continued_p) | |
957 | bitmap = CONTINUED_LINE_BITMAP; | |
958 | else | |
959 | bitmap = NO_BITMAP; | |
960 | ||
961 | /* Clear flags area if no bitmap to draw of if bitmap doesn't fill | |
962 | the flags area. */ | |
963 | if (bitmap == NO_BITMAP | |
964 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) | |
965 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) | |
966 | { | |
967 | int right = window_box_right (w, -1); | |
968 | ||
969 | if (header_line_height < 0) | |
970 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
971 | ||
972 | w32_fill_area (f, hdc, face->background, | |
973 | right, | |
974 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
975 | row->y)), | |
976 | FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f), | |
977 | row->visible_height); | |
978 | } | |
979 | ||
980 | /* Draw the right bitmap. */ | |
981 | if (bitmap != NO_BITMAP) | |
982 | w32_draw_bitmap (w, hdc, row, bitmap); | |
983 | ||
984 | release_frame_dc (f, hdc); | |
985 | } | |
986 | ||
ee78dc32 | 987 | \f |
791f420f JR |
988 | /*********************************************************************** |
989 | Line Highlighting | |
990 | ***********************************************************************/ | |
991 | ||
992 | /* External interface to control of standout mode. Not used for W32 | |
993 | frames. Aborts when called. */ | |
ee78dc32 | 994 | |
96214669 | 995 | static void |
fbd6baed | 996 | w32_reassert_line_highlight (new, vpos) |
ee78dc32 GV |
997 | int new, vpos; |
998 | { | |
791f420f | 999 | abort (); |
ee78dc32 GV |
1000 | } |
1001 | ||
791f420f JR |
1002 | /* Call this when about to modify line at position VPOS and change |
1003 | whether it is highlighted. Not used for W32 frames. Aborts when | |
1004 | called. */ | |
ee78dc32 | 1005 | |
96214669 | 1006 | static void |
791f420f JR |
1007 | x_change_line_highlight (new_highlight, vpos, y, first_unused_hpos) |
1008 | int new_highlight, vpos, y, first_unused_hpos; | |
ee78dc32 | 1009 | { |
791f420f | 1010 | abort (); |
ee78dc32 GV |
1011 | } |
1012 | ||
9ef2e2cf JR |
1013 | /* This is called when starting Emacs and when restarting after |
1014 | suspend. When starting Emacs, no window is mapped. And nothing | |
1015 | must be done to Emacs's own window if it is suspended (though that | |
1016 | rarely happens). */ | |
ee78dc32 | 1017 | |
96214669 GV |
1018 | static void |
1019 | w32_set_terminal_modes (void) | |
ee78dc32 GV |
1020 | { |
1021 | } | |
1022 | ||
9ef2e2cf JR |
1023 | /* This is called when exiting or suspending Emacs. Exiting will make |
1024 | the W32 windows go away, and suspending requires no action. */ | |
ee78dc32 | 1025 | |
96214669 GV |
1026 | static void |
1027 | w32_reset_terminal_modes (void) | |
ee78dc32 GV |
1028 | { |
1029 | } | |
791f420f | 1030 | |
9ef2e2cf | 1031 | |
ee78dc32 | 1032 | \f |
791f420f JR |
1033 | /*********************************************************************** |
1034 | Output Cursor | |
1035 | ***********************************************************************/ | |
1036 | ||
1037 | /* Set the global variable output_cursor to CURSOR. All cursor | |
1038 | positions are relative to updated_window. */ | |
9ef2e2cf | 1039 | |
791f420f JR |
1040 | static void |
1041 | set_output_cursor (cursor) | |
1042 | struct cursor_pos *cursor; | |
1043 | { | |
1044 | output_cursor.hpos = cursor->hpos; | |
1045 | output_cursor.vpos = cursor->vpos; | |
1046 | output_cursor.x = cursor->x; | |
1047 | output_cursor.y = cursor->y; | |
1048 | } | |
1049 | ||
1050 | ||
1051 | /* Set a nominal cursor position. | |
1052 | ||
1053 | HPOS and VPOS are column/row positions in a window glyph matrix. X | |
1054 | and Y are window text area relative pixel positions. | |
1055 | ||
1056 | If this is done during an update, updated_window will contain the | |
1057 | window that is being updated and the position is the future output | |
1058 | cursor position for that window. If updated_window is null, use | |
1059 | selected_window and display the cursor at the given position. */ | |
ee78dc32 | 1060 | |
96214669 | 1061 | static void |
791f420f JR |
1062 | w32_cursor_to (vpos, hpos, y, x) |
1063 | int vpos, hpos, y, x; | |
ee78dc32 | 1064 | { |
791f420f | 1065 | struct window *w; |
ee78dc32 | 1066 | |
791f420f JR |
1067 | /* If updated_window is not set, work on selected_window. */ |
1068 | if (updated_window) | |
1069 | w = updated_window; | |
1070 | else | |
1071 | w = XWINDOW (selected_window); | |
1072 | ||
1073 | /* Set the output cursor. */ | |
1074 | output_cursor.hpos = hpos; | |
1075 | output_cursor.vpos = vpos; | |
1076 | output_cursor.x = x; | |
1077 | output_cursor.y = y; | |
ee78dc32 | 1078 | |
791f420f JR |
1079 | /* If not called as part of an update, really display the cursor. |
1080 | This will also set the cursor position of W. */ | |
1081 | if (updated_window == NULL) | |
ee78dc32 GV |
1082 | { |
1083 | BLOCK_INPUT; | |
791f420f | 1084 | x_display_cursor (w, 1, hpos, vpos, x, y); |
ee78dc32 GV |
1085 | UNBLOCK_INPUT; |
1086 | } | |
1087 | } | |
791f420f | 1088 | |
9ef2e2cf | 1089 | |
ee78dc32 | 1090 | \f |
791f420f JR |
1091 | /*********************************************************************** |
1092 | Display Iterator | |
1093 | ***********************************************************************/ | |
1094 | ||
1095 | /* Function prototypes of this page. */ | |
1096 | ||
1097 | static struct face *x_get_glyph_face_and_encoding P_ ((struct frame *, | |
1098 | struct glyph *, | |
93ff4395 JR |
1099 | wchar_t *, |
1100 | int *)); | |
791f420f JR |
1101 | static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int, |
1102 | int, wchar_t *, int)); | |
82f9d565 | 1103 | static XCharStruct *w32_per_char_metric P_ ((XFontStruct *, |
9ef2e2cf JR |
1104 | wchar_t *, |
1105 | enum w32_char_font_type)); | |
1106 | static enum w32_char_font_type | |
1107 | w32_encode_char P_ ((int, wchar_t *, struct font_info *, int *)); | |
791f420f JR |
1108 | static void x_append_glyph P_ ((struct it *)); |
1109 | static void x_append_composite_glyph P_ ((struct it *)); | |
1110 | static void x_append_stretch_glyph P_ ((struct it *it, Lisp_Object, | |
1111 | int, int, double)); | |
1112 | static void x_produce_glyphs P_ ((struct it *)); | |
1113 | static void x_produce_image_glyph P_ ((struct it *it)); | |
a1b9438c | 1114 | |
a1b9438c | 1115 | |
791f420f JR |
1116 | /* Dealing with bits of wchar_t as if they were an XChar2B. */ |
1117 | #define BUILD_WCHAR_T(byte1, byte2) \ | |
1118 | ((wchar_t)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff))) | |
a1b9438c | 1119 | |
a1b9438c | 1120 | |
791f420f JR |
1121 | #define BYTE1(ch) \ |
1122 | (((ch) & 0xff00) >> 8) | |
a1b9438c | 1123 | |
791f420f JR |
1124 | #define BYTE2(ch) \ |
1125 | ((ch) & 0x00ff) | |
cabb23bc | 1126 | |
791f420f JR |
1127 | |
1128 | /* Get metrics of character CHAR2B in FONT. Value is always non-null. | |
1129 | If CHAR2B is not contained in FONT, the font's default character | |
9ef2e2cf | 1130 | metric is returned. */ |
791f420f | 1131 | |
82f9d565 AI |
1132 | static int |
1133 | w32_bdf_per_char_metric (font, char2b, dim, pcm) | |
9127e20e JR |
1134 | XFontStruct *font; |
1135 | wchar_t *char2b; | |
1136 | int dim; | |
82f9d565 | 1137 | XCharStruct * pcm; |
9127e20e JR |
1138 | { |
1139 | glyph_metric * bdf_metric; | |
1140 | char buf[2]; | |
9127e20e JR |
1141 | |
1142 | if (dim == 1) | |
4b99045f | 1143 | buf[0] = (char)(*char2b); |
9127e20e JR |
1144 | else |
1145 | { | |
1146 | buf[0] = BYTE1 (*char2b); | |
1147 | buf[1] = BYTE2 (*char2b); | |
1148 | } | |
1149 | ||
1150 | bdf_metric = w32_BDF_TextMetric (font->bdf, buf, dim); | |
1151 | ||
1152 | if (bdf_metric) | |
1153 | { | |
1154 | pcm->width = bdf_metric->dwidth; | |
1155 | pcm->lbearing = bdf_metric->bbox; | |
1156 | pcm->rbearing = bdf_metric->dwidth | |
1157 | - (bdf_metric->bbox + bdf_metric->bbw); | |
1158 | pcm->ascent = bdf_metric->bboy + bdf_metric->bbh; | |
00c96995 | 1159 | pcm->descent = -bdf_metric->bboy; |
82f9d565 AI |
1160 | |
1161 | return 1; | |
9127e20e | 1162 | } |
82f9d565 | 1163 | return 0; |
9127e20e JR |
1164 | } |
1165 | ||
1166 | ||
82f9d565 AI |
1167 | static int |
1168 | w32_native_per_char_metric (font, char2b, font_type, pcm) | |
791f420f JR |
1169 | XFontStruct *font; |
1170 | wchar_t *char2b; | |
9ef2e2cf | 1171 | enum w32_char_font_type font_type; |
82f9d565 | 1172 | XCharStruct * pcm; |
cabb23bc | 1173 | { |
82f9d565 AI |
1174 | HDC hdc = GetDC (NULL); |
1175 | HFONT old_font; | |
1176 | BOOL retval = FALSE; | |
cabb23bc | 1177 | |
791f420f | 1178 | xassert (font && char2b); |
82f9d565 AI |
1179 | xassert (font->hfont); |
1180 | xassert (font_type == UNICODE_FONT || font_type == ANSI_FONT); | |
cabb23bc | 1181 | |
82f9d565 | 1182 | old_font = SelectObject (hdc, font->hfont); |
791f420f | 1183 | |
dfaaaafb | 1184 | if ((font->tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0) |
791f420f | 1185 | { |
dfaaaafb AI |
1186 | ABC char_widths; |
1187 | ||
1188 | if (font_type == UNICODE_FONT) | |
1189 | retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths); | |
82f9d565 | 1190 | else |
dfaaaafb AI |
1191 | retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths); |
1192 | ||
1193 | if (retval) | |
1194 | { | |
1195 | pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC; | |
1196 | pcm->lbearing = char_widths.abcA; | |
1197 | pcm->rbearing = pcm->width - char_widths.abcC; | |
82f9d565 AI |
1198 | pcm->ascent = FONT_BASE (font); |
1199 | pcm->descent = FONT_DESCENT (font); | |
dfaaaafb | 1200 | } |
791f420f | 1201 | } |
82f9d565 AI |
1202 | |
1203 | if (!retval) | |
791f420f | 1204 | { |
82f9d565 AI |
1205 | /* Either font is not a True-type font, or GetCharABCWidthsW |
1206 | failed (it is not supported on Windows 9x for instance), so we | |
1207 | can't determine the full info we would like. All is not lost | |
1208 | though - we can call GetTextExtentPoint32 to get rbearing and | |
1209 | deduce width based on the font's per-string overhang. lbearing | |
1210 | is assumed to be zero. */ | |
01b220b6 JR |
1211 | |
1212 | /* TODO: Some Thai characters (and other composites if Windows | |
1213 | supports them) do have lbearing, and report their total width | |
1214 | as zero. Need some way of handling them when | |
1215 | GetCharABCWidthsW fails. */ | |
82f9d565 AI |
1216 | SIZE sz; |
1217 | ||
1218 | if (font_type == UNICODE_FONT) | |
1219 | retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz); | |
1220 | else | |
1221 | retval = GetTextExtentPoint32A (hdc, (char*)char2b, 1, &sz); | |
791f420f JR |
1222 | |
1223 | if (retval) | |
dfaaaafb | 1224 | { |
82f9d565 AI |
1225 | pcm->width = sz.cx - font->tm.tmOverhang; |
1226 | pcm->rbearing = sz.cx; | |
dfaaaafb | 1227 | pcm->lbearing = 0; |
82f9d565 AI |
1228 | pcm->ascent = FONT_BASE (font); |
1229 | pcm->descent = FONT_DESCENT (font); | |
dfaaaafb | 1230 | } |
791f420f JR |
1231 | } |
1232 | ||
791f420f | 1233 | |
93ff4395 JR |
1234 | if (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0) |
1235 | { | |
82f9d565 | 1236 | retval = FALSE; |
93ff4395 JR |
1237 | } |
1238 | ||
82f9d565 AI |
1239 | SelectObject (hdc, old_font); |
1240 | ReleaseDC (NULL, hdc); | |
1241 | ||
1242 | return retval; | |
1243 | } | |
1244 | ||
1245 | ||
1246 | static XCharStruct * | |
1247 | w32_per_char_metric (font, char2b, font_type) | |
1248 | XFontStruct *font; | |
1249 | wchar_t *char2b; | |
1250 | enum w32_char_font_type font_type; | |
1251 | { | |
1252 | /* The result metric information. */ | |
1253 | XCharStruct *pcm; | |
1254 | BOOL retval; | |
1255 | ||
1256 | xassert (font && char2b); | |
1257 | xassert (font_type != UNKNOWN_FONT); | |
1258 | ||
1259 | /* Handle the common cases quickly. */ | |
4b99045f | 1260 | if (!font->bdf && font->per_char == NULL) |
82f9d565 AI |
1261 | /* TODO: determine whether char2b exists in font? */ |
1262 | return &font->max_bounds; | |
4b99045f | 1263 | else if (!font->bdf && *char2b < 128) |
82f9d565 AI |
1264 | return &font->per_char[*char2b]; |
1265 | ||
1266 | pcm = &font->scratch; | |
1267 | ||
1268 | if (font_type == BDF_1D_FONT) | |
1269 | retval = w32_bdf_per_char_metric (font, char2b, 1, pcm); | |
1270 | else if (font_type == BDF_2D_FONT) | |
1271 | retval = w32_bdf_per_char_metric (font, char2b, 2, pcm); | |
1272 | else | |
1273 | retval = w32_native_per_char_metric (font, char2b, font_type, pcm); | |
1274 | ||
1275 | if (retval) | |
1276 | return pcm; | |
1277 | ||
1278 | return NULL; | |
1279 | } | |
1280 | ||
1281 | void | |
1282 | w32_cache_char_metrics (font) | |
1283 | XFontStruct *font; | |
1284 | { | |
1285 | wchar_t char2b = L'x'; | |
1286 | ||
1287 | /* Cache char metrics for the common cases. */ | |
1288 | if (font->bdf) | |
1289 | { | |
1290 | /* TODO: determine whether font is fixed-pitch. */ | |
00c96995 JR |
1291 | if (!w32_bdf_per_char_metric (font, &char2b, 1, &font->max_bounds)) |
1292 | { | |
1293 | /* Use the font width and height as max bounds, as not all BDF | |
1294 | fonts contain the letter 'x'. */ | |
1295 | font->max_bounds.width = FONT_MAX_WIDTH (font); | |
1296 | font->max_bounds.lbearing = -font->bdf->llx; | |
1297 | font->max_bounds.rbearing = FONT_MAX_WIDTH (font) - font->bdf->urx; | |
1298 | font->max_bounds.ascent = FONT_BASE (font); | |
1299 | font->max_bounds.descent = FONT_DESCENT (font); | |
1300 | } | |
82f9d565 AI |
1301 | } |
1302 | else | |
1303 | { | |
f1eed8ff JR |
1304 | if (((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) != 0) |
1305 | /* Some fonts (eg DBCS fonts) are marked as fixed width even | |
1306 | though they contain characters of different widths. */ | |
1307 | || (font->tm.tmMaxCharWidth != font->tm.tmAveCharWidth)) | |
82f9d565 AI |
1308 | { |
1309 | /* Font is not fixed pitch, so cache per_char info for the | |
1310 | ASCII characters. It would be much more work, and probably | |
1311 | not worth it, to cache other chars, since we may change | |
1312 | between using Unicode and ANSI text drawing functions at | |
1313 | run-time. */ | |
1314 | int i; | |
1315 | ||
1316 | font->per_char = xmalloc (128 * sizeof(XCharStruct)); | |
1317 | for (i = 0; i < 128; i++) | |
1318 | { | |
1319 | char2b = i; | |
1320 | w32_native_per_char_metric (font, &char2b, ANSI_FONT, | |
1321 | &font->per_char[i]); | |
1322 | } | |
1323 | } | |
1324 | else | |
1325 | w32_native_per_char_metric (font, &char2b, ANSI_FONT, | |
1326 | &font->max_bounds); | |
1327 | } | |
791f420f JR |
1328 | } |
1329 | ||
1330 | ||
9ef2e2cf JR |
1331 | /* Determine if a font is double byte. */ |
1332 | int w32_font_is_double_byte (XFontStruct *font) | |
1333 | { | |
1334 | return font->double_byte_p; | |
1335 | } | |
1336 | ||
1337 | ||
791f420f JR |
1338 | /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is |
1339 | the two-byte form of C. Encoding is returned in *CHAR2B. */ | |
1340 | ||
9ef2e2cf JR |
1341 | static INLINE enum w32_char_font_type |
1342 | w32_encode_char (c, char2b, font_info, two_byte_p) | |
791f420f JR |
1343 | int c; |
1344 | wchar_t *char2b; | |
1345 | struct font_info *font_info; | |
9ef2e2cf | 1346 | int * two_byte_p; |
791f420f JR |
1347 | { |
1348 | int charset = CHAR_CHARSET (c); | |
1349 | int codepage; | |
9ef2e2cf JR |
1350 | int unicode_p = 0; |
1351 | ||
791f420f JR |
1352 | XFontStruct *font = font_info->font; |
1353 | ||
9127e20e | 1354 | xassert (two_byte_p); |
9ef2e2cf JR |
1355 | |
1356 | *two_byte_p = w32_font_is_double_byte (font); | |
1357 | ||
791f420f JR |
1358 | /* FONT_INFO may define a scheme by which to encode byte1 and byte2. |
1359 | This may be either a program in a special encoder language or a | |
1360 | fixed encoding. */ | |
1361 | if (font_info->font_encoder) | |
1362 | { | |
1363 | /* It's a program. */ | |
1364 | struct ccl_program *ccl = font_info->font_encoder; | |
1365 | ||
1366 | if (CHARSET_DIMENSION (charset) == 1) | |
1367 | { | |
1368 | ccl->reg[0] = charset; | |
1369 | ccl->reg[1] = BYTE2 (*char2b); | |
1370 | } | |
1371 | else | |
1372 | { | |
1373 | ccl->reg[0] = charset; | |
1374 | ccl->reg[1] = BYTE1 (*char2b); | |
1375 | ccl->reg[2] = BYTE2 (*char2b); | |
1376 | } | |
1377 | ||
1378 | ccl_driver (ccl, NULL, NULL, 0, 0, NULL); | |
1379 | ||
1380 | /* We assume that MSBs are appropriately set/reset by CCL | |
1381 | program. */ | |
9ef2e2cf | 1382 | if (!*two_byte_p) /* 1-byte font */ |
791f420f | 1383 | *char2b = BUILD_WCHAR_T (0, ccl->reg[1]); |
791f420f JR |
1384 | else |
1385 | *char2b = BUILD_WCHAR_T (ccl->reg[1], ccl->reg[2]); | |
791f420f JR |
1386 | } |
1387 | else if (font_info->encoding[charset]) | |
1388 | { | |
1389 | /* Fixed encoding scheme. See fontset.h for the meaning of the | |
1390 | encoding numbers. */ | |
1391 | int enc = font_info->encoding[charset]; | |
1392 | ||
1393 | if ((enc == 1 || enc == 2) | |
1394 | && CHARSET_DIMENSION (charset) == 2) | |
1395 | *char2b = BUILD_WCHAR_T (BYTE1 (*char2b) | 0x80, BYTE2 (*char2b)); | |
1396 | ||
1397 | if (enc == 1 || enc == 3 | |
1398 | || (enc == 4 && CHARSET_DIMENSION (charset) == 1)) | |
1399 | *char2b = BUILD_WCHAR_T (BYTE1 (*char2b), BYTE2 (*char2b) | 0x80); | |
1400 | else if (enc == 4) | |
1401 | { | |
1402 | int sjis1, sjis2; | |
1403 | ||
1404 | ENCODE_SJIS (BYTE1 (*char2b), BYTE2 (*char2b), | |
1405 | sjis1, sjis2); | |
1406 | *char2b = BUILD_WCHAR_T (sjis1, sjis2); | |
1407 | } | |
1408 | } | |
1409 | codepage = w32_codepage_for_font (font_info->name); | |
1410 | ||
1411 | /* If charset is not ASCII or Latin-1, may need to move it into | |
1412 | Unicode space. */ | |
1413 | if ( font && !font->bdf && w32_use_unicode_for_codepage (codepage) | |
1414 | && charset != CHARSET_ASCII && charset != charset_latin_iso8859_1) | |
1415 | { | |
1416 | char temp[3]; | |
1417 | temp[0] = BYTE1 (*char2b); | |
1418 | temp[1] = BYTE2 (*char2b); | |
1419 | temp[2] = '\0'; | |
02f593f3 JR |
1420 | if (codepage != CP_UNICODE) |
1421 | { | |
1422 | if (temp[0]) | |
1423 | MultiByteToWideChar (codepage, 0, temp, 2, char2b, 1); | |
1424 | else | |
1425 | MultiByteToWideChar (codepage, 0, temp+1, 1, char2b, 1); | |
1426 | } | |
9ef2e2cf JR |
1427 | unicode_p = 1; |
1428 | *two_byte_p = 1; | |
1429 | } | |
1430 | if (!font) | |
1431 | return UNKNOWN_FONT; | |
9127e20e JR |
1432 | else if (font->bdf && CHARSET_DIMENSION (charset) == 1) |
1433 | return BDF_1D_FONT; | |
9ef2e2cf | 1434 | else if (font->bdf) |
9127e20e | 1435 | return BDF_2D_FONT; |
9ef2e2cf JR |
1436 | else if (unicode_p) |
1437 | return UNICODE_FONT; | |
1438 | else | |
1439 | return ANSI_FONT; | |
791f420f JR |
1440 | } |
1441 | ||
1442 | ||
1443 | /* Get face and two-byte form of character C in face FACE_ID on frame | |
1444 | F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero | |
1445 | means we want to display multibyte text. Value is a pointer to a | |
1446 | realized face that is ready for display. */ | |
1447 | ||
1448 | static INLINE struct face * | |
1449 | x_get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p) | |
1450 | struct frame *f; | |
1451 | int c, face_id; | |
1452 | wchar_t *char2b; | |
1453 | int multibyte_p; | |
1454 | { | |
1455 | struct face *face = FACE_FROM_ID (f, face_id); | |
1456 | ||
1457 | if (!multibyte_p) | |
1458 | { | |
1459 | /* Unibyte case. We don't have to encode, but we have to make | |
1460 | sure to use a face suitable for unibyte. */ | |
1461 | *char2b = BUILD_WCHAR_T (0, c); | |
93ff4395 JR |
1462 | face_id = FACE_FOR_CHAR (f, face, c); |
1463 | face = FACE_FROM_ID (f, face_id); | |
791f420f JR |
1464 | } |
1465 | else if (c < 128 && face_id < BASIC_FACE_ID_SENTINEL) | |
1466 | { | |
1467 | /* Case of ASCII in a face known to fit ASCII. */ | |
1468 | *char2b = BUILD_WCHAR_T (0, c); | |
1469 | } | |
1470 | else | |
1471 | { | |
1472 | int c1, c2, charset; | |
1473 | ||
1474 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1475 | really a one-byte character so that byte1 is zero. */ | |
1476 | SPLIT_CHAR (c, charset, c1, c2); | |
1477 | if (c2 > 0) | |
1478 | *char2b = BUILD_WCHAR_T (c1, c2); | |
1479 | else | |
1480 | *char2b = BUILD_WCHAR_T (0, c1); | |
791f420f JR |
1481 | |
1482 | /* Maybe encode the character in *CHAR2B. */ | |
93ff4395 | 1483 | if (face->font != NULL) |
791f420f JR |
1484 | { |
1485 | struct font_info *font_info | |
1486 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1487 | if (font_info) | |
9ef2e2cf | 1488 | w32_encode_char (c, char2b, font_info, &multibyte_p); |
791f420f JR |
1489 | } |
1490 | } | |
1491 | ||
1492 | /* Make sure X resources of the face are allocated. */ | |
1493 | xassert (face != NULL); | |
1494 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1495 | ||
1496 | return face; | |
1497 | } | |
1498 | ||
1499 | ||
1500 | /* Get face and two-byte form of character glyph GLYPH on frame F. | |
1501 | The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is | |
1502 | a pointer to a realized face that is ready for display. */ | |
1503 | ||
1504 | static INLINE struct face * | |
93ff4395 | 1505 | x_get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p) |
791f420f JR |
1506 | struct frame *f; |
1507 | struct glyph *glyph; | |
1508 | wchar_t *char2b; | |
93ff4395 | 1509 | int *two_byte_p; |
791f420f JR |
1510 | { |
1511 | struct face *face; | |
9ef2e2cf | 1512 | int dummy = 0; |
791f420f JR |
1513 | |
1514 | xassert (glyph->type == CHAR_GLYPH); | |
1515 | face = FACE_FROM_ID (f, glyph->face_id); | |
1516 | ||
93ff4395 JR |
1517 | if (two_byte_p) |
1518 | *two_byte_p = 0; | |
9ef2e2cf JR |
1519 | else |
1520 | two_byte_p = &dummy; | |
93ff4395 | 1521 | |
791f420f JR |
1522 | if (!glyph->multibyte_p) |
1523 | { | |
1524 | /* Unibyte case. We don't have to encode, but we have to make | |
1525 | sure to use a face suitable for unibyte. */ | |
1526 | *char2b = BUILD_WCHAR_T (0, glyph->u.ch); | |
1527 | } | |
1528 | else if (glyph->u.ch < 128 | |
1529 | && glyph->face_id < BASIC_FACE_ID_SENTINEL) | |
1530 | { | |
1531 | /* Case of ASCII in a face known to fit ASCII. */ | |
1532 | *char2b = BUILD_WCHAR_T (0, glyph->u.ch); | |
1533 | } | |
1534 | else | |
1535 | { | |
1536 | int c1, c2, charset; | |
1537 | ||
1538 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1539 | really a one-byte character so that byte1 is zero. */ | |
1540 | SPLIT_CHAR (glyph->u.ch, charset, c1, c2); | |
1541 | if (c2 > 0) | |
1542 | *char2b = BUILD_WCHAR_T (c1, c2); | |
1543 | else | |
1544 | *char2b = BUILD_WCHAR_T (0, c1); | |
1545 | ||
1546 | /* Maybe encode the character in *CHAR2B. */ | |
1547 | if (charset != CHARSET_ASCII) | |
1548 | { | |
1549 | struct font_info *font_info | |
1550 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1551 | if (font_info) | |
1552 | { | |
9ef2e2cf JR |
1553 | glyph->w32_font_type |
1554 | = w32_encode_char (glyph->u.ch, char2b, font_info, two_byte_p); | |
791f420f JR |
1555 | } |
1556 | } | |
1557 | } | |
1558 | ||
1559 | /* Make sure X resources of the face are allocated. */ | |
1560 | xassert (face != NULL); | |
1561 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1562 | return face; | |
1563 | } | |
1564 | ||
1565 | ||
1566 | /* Store one glyph for IT->char_to_display in IT->glyph_row. | |
1567 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1568 | ||
1569 | static INLINE void | |
1570 | x_append_glyph (it) | |
1571 | struct it *it; | |
1572 | { | |
1573 | struct glyph *glyph; | |
1574 | enum glyph_row_area area = it->area; | |
1575 | ||
1576 | xassert (it->glyph_row); | |
1577 | xassert (it->char_to_display != '\n' && it->char_to_display != '\t'); | |
1578 | ||
1579 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1580 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1581 | { | |
791f420f JR |
1582 | glyph->charpos = CHARPOS (it->position); |
1583 | glyph->object = it->object; | |
ec48c3a7 | 1584 | glyph->pixel_width = it->pixel_width; |
791f420f | 1585 | glyph->voffset = it->voffset; |
ec48c3a7 | 1586 | glyph->type = CHAR_GLYPH; |
791f420f | 1587 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1588 | glyph->left_box_line_p = it->start_of_box_run_p; |
1589 | glyph->right_box_line_p = it->end_of_box_run_p; | |
791f420f JR |
1590 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1591 | || it->phys_descent > it->descent); | |
ec48c3a7 | 1592 | glyph->padding_p = 0; |
93ff4395 | 1593 | glyph->glyph_not_available_p = it->glyph_not_available_p; |
ec48c3a7 JR |
1594 | glyph->face_id = it->face_id; |
1595 | glyph->u.ch = it->char_to_display; | |
1596 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1597 | ++it->glyph_row->used[area]; |
1598 | } | |
1599 | } | |
1600 | ||
1601 | /* Store one glyph for the composition IT->cmp_id in IT->glyph_row. | |
1602 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1603 | ||
1604 | static INLINE void | |
1605 | x_append_composite_glyph (it) | |
1606 | struct it *it; | |
1607 | { | |
1608 | struct glyph *glyph; | |
1609 | enum glyph_row_area area = it->area; | |
1610 | ||
1611 | xassert (it->glyph_row); | |
1612 | ||
1613 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1614 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1615 | { | |
791f420f JR |
1616 | glyph->charpos = CHARPOS (it->position); |
1617 | glyph->object = it->object; | |
ec48c3a7 | 1618 | glyph->pixel_width = it->pixel_width; |
791f420f | 1619 | glyph->voffset = it->voffset; |
ec48c3a7 | 1620 | glyph->type = COMPOSITE_GLYPH; |
791f420f | 1621 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1622 | glyph->left_box_line_p = it->start_of_box_run_p; |
1623 | glyph->right_box_line_p = it->end_of_box_run_p; | |
791f420f JR |
1624 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1625 | || it->phys_descent > it->descent); | |
ec48c3a7 JR |
1626 | glyph->padding_p = 0; |
1627 | glyph->glyph_not_available_p = 0; | |
1628 | glyph->face_id = it->face_id; | |
1629 | glyph->u.cmp_id = it->cmp_id; | |
1630 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1631 | ++it->glyph_row->used[area]; |
1632 | } | |
1633 | } | |
1634 | ||
1635 | ||
1636 | /* Change IT->ascent and IT->height according to the setting of | |
1637 | IT->voffset. */ | |
1638 | ||
1639 | static INLINE void | |
1640 | take_vertical_position_into_account (it) | |
1641 | struct it *it; | |
1642 | { | |
1643 | if (it->voffset) | |
1644 | { | |
1645 | if (it->voffset < 0) | |
1646 | /* Increase the ascent so that we can display the text higher | |
1647 | in the line. */ | |
1648 | it->ascent += abs (it->voffset); | |
1649 | else | |
1650 | /* Increase the descent so that we can display the text lower | |
1651 | in the line. */ | |
1652 | it->descent += it->voffset; | |
1653 | } | |
1654 | } | |
1655 | ||
1656 | ||
1657 | /* Produce glyphs/get display metrics for the image IT is loaded with. | |
1658 | See the description of struct display_iterator in dispextern.h for | |
1659 | an overview of struct display_iterator. */ | |
1660 | ||
1661 | static void | |
1662 | x_produce_image_glyph (it) | |
1663 | struct it *it; | |
1664 | { | |
1665 | struct image *img; | |
1666 | struct face *face; | |
1667 | ||
1668 | xassert (it->what == IT_IMAGE); | |
1669 | ||
1670 | face = FACE_FROM_ID (it->f, it->face_id); | |
1671 | img = IMAGE_FROM_ID (it->f, it->image_id); | |
1672 | xassert (img); | |
1673 | ||
1674 | /* Make sure X resources of the face and image are loaded. */ | |
1675 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1676 | prepare_image_for_display (it->f, img); | |
1677 | ||
9ef2e2cf | 1678 | it->ascent = it->phys_ascent = image_ascent (img, face); |
791f420f JR |
1679 | it->descent = it->phys_descent = img->height + 2 * img->margin - it->ascent; |
1680 | it->pixel_width = img->width + 2 * img->margin; | |
1681 | ||
1682 | it->nglyphs = 1; | |
1683 | ||
1684 | if (face->box != FACE_NO_BOX) | |
1685 | { | |
1686 | it->ascent += face->box_line_width; | |
1687 | it->descent += face->box_line_width; | |
1688 | ||
1689 | if (it->start_of_box_run_p) | |
1690 | it->pixel_width += face->box_line_width; | |
1691 | if (it->end_of_box_run_p) | |
1692 | it->pixel_width += face->box_line_width; | |
1693 | } | |
1694 | ||
1695 | take_vertical_position_into_account (it); | |
1696 | ||
1697 | if (it->glyph_row) | |
1698 | { | |
1699 | struct glyph *glyph; | |
1700 | enum glyph_row_area area = it->area; | |
1701 | ||
1702 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1703 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1704 | { | |
791f420f JR |
1705 | glyph->charpos = CHARPOS (it->position); |
1706 | glyph->object = it->object; | |
ec48c3a7 | 1707 | glyph->pixel_width = it->pixel_width; |
791f420f | 1708 | glyph->voffset = it->voffset; |
ec48c3a7 | 1709 | glyph->type = IMAGE_GLYPH; |
791f420f | 1710 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1711 | glyph->left_box_line_p = it->start_of_box_run_p; |
1712 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1713 | glyph->overlaps_vertically_p = 0; | |
1714 | glyph->padding_p = 0; | |
1715 | glyph->glyph_not_available_p = 0; | |
1716 | glyph->face_id = it->face_id; | |
1717 | glyph->u.img_id = img->id; | |
1718 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1719 | ++it->glyph_row->used[area]; |
1720 | } | |
1721 | } | |
1722 | } | |
1723 | ||
1724 | ||
1725 | /* Append a stretch glyph to IT->glyph_row. OBJECT is the source | |
1726 | of the glyph, WIDTH and HEIGHT are the width and height of the | |
1727 | stretch. ASCENT is the percentage/100 of HEIGHT to use for the | |
1728 | ascent of the glyph (0 <= ASCENT <= 1). */ | |
1729 | ||
1730 | static void | |
1731 | x_append_stretch_glyph (it, object, width, height, ascent) | |
1732 | struct it *it; | |
1733 | Lisp_Object object; | |
1734 | int width, height; | |
1735 | double ascent; | |
1736 | { | |
1737 | struct glyph *glyph; | |
1738 | enum glyph_row_area area = it->area; | |
1739 | ||
1740 | xassert (ascent >= 0 && ascent <= 1); | |
1741 | ||
1742 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1743 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1744 | { | |
791f420f JR |
1745 | glyph->charpos = CHARPOS (it->position); |
1746 | glyph->object = object; | |
ec48c3a7 | 1747 | glyph->pixel_width = width; |
791f420f | 1748 | glyph->voffset = it->voffset; |
ec48c3a7 | 1749 | glyph->type = STRETCH_GLYPH; |
791f420f | 1750 | glyph->multibyte_p = it->multibyte_p; |
ec48c3a7 JR |
1751 | glyph->left_box_line_p = it->start_of_box_run_p; |
1752 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1753 | glyph->overlaps_vertically_p = 0; | |
1754 | glyph->padding_p = 0; | |
1755 | glyph->glyph_not_available_p = 0; | |
1756 | glyph->face_id = it->face_id; | |
1757 | glyph->u.stretch.ascent = height * ascent; | |
1758 | glyph->u.stretch.height = height; | |
1759 | glyph->w32_font_type = UNKNOWN_FONT; | |
791f420f JR |
1760 | ++it->glyph_row->used[area]; |
1761 | } | |
1762 | } | |
1763 | ||
1764 | ||
1765 | /* Produce a stretch glyph for iterator IT. IT->object is the value | |
1766 | of the glyph property displayed. The value must be a list | |
1767 | `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs | |
1768 | being recognized: | |
1769 | ||
1770 | 1. `:width WIDTH' specifies that the space should be WIDTH * | |
1771 | canonical char width wide. WIDTH may be an integer or floating | |
1772 | point number. | |
1773 | ||
1774 | 2. `:relative-width FACTOR' specifies that the width of the stretch | |
1775 | should be computed from the width of the first character having the | |
1776 | `glyph' property, and should be FACTOR times that width. | |
1777 | ||
1778 | 3. `:align-to HPOS' specifies that the space should be wide enough | |
1779 | to reach HPOS, a value in canonical character units. | |
1780 | ||
1781 | Exactly one of the above pairs must be present. | |
1782 | ||
1783 | 4. `:height HEIGHT' specifies that the height of the stretch produced | |
1784 | should be HEIGHT, measured in canonical character units. | |
1785 | ||
1786 | 5. `:relative-height FACTOR' specifies that the height of the the | |
1787 | stretch should be FACTOR times the height of the characters having | |
1788 | the glyph property. | |
1789 | ||
1790 | Either none or exactly one of 4 or 5 must be present. | |
1791 | ||
1792 | 6. `:ascent ASCENT' specifies that ASCENT percent of the height | |
1793 | of the stretch should be used for the ascent of the stretch. | |
1794 | ASCENT must be in the range 0 <= ASCENT <= 100. */ | |
1795 | ||
1796 | #define NUMVAL(X) \ | |
1797 | ((INTEGERP (X) || FLOATP (X)) \ | |
1798 | ? XFLOATINT (X) \ | |
1799 | : - 1) | |
1800 | ||
1801 | ||
1802 | static void | |
1803 | x_produce_stretch_glyph (it) | |
1804 | struct it *it; | |
1805 | { | |
1806 | /* (space :width WIDTH :height HEIGHT. */ | |
1807 | extern Lisp_Object QCwidth, QCheight, QCascent, Qspace; | |
1808 | extern Lisp_Object QCrelative_width, QCrelative_height; | |
1809 | extern Lisp_Object QCalign_to; | |
1810 | Lisp_Object prop, plist; | |
1811 | double width = 0, height = 0, ascent = 0; | |
1812 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
1813 | XFontStruct *font = face->font ? face->font : FRAME_FONT (it->f); | |
1814 | ||
1815 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1816 | ||
1817 | /* List should start with `space'. */ | |
1818 | xassert (CONSP (it->object) && EQ (XCAR (it->object), Qspace)); | |
1819 | plist = XCDR (it->object); | |
1820 | ||
1821 | /* Compute the width of the stretch. */ | |
1822 | if (prop = Fplist_get (plist, QCwidth), | |
1823 | NUMVAL (prop) > 0) | |
1824 | /* Absolute width `:width WIDTH' specified and valid. */ | |
1825 | width = NUMVAL (prop) * CANON_X_UNIT (it->f); | |
1826 | else if (prop = Fplist_get (plist, QCrelative_width), | |
1827 | NUMVAL (prop) > 0) | |
1828 | { | |
1829 | /* Relative width `:relative-width FACTOR' specified and valid. | |
1830 | Compute the width of the characters having the `glyph' | |
1831 | property. */ | |
1832 | struct it it2; | |
1833 | unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); | |
1834 | ||
1835 | it2 = *it; | |
1836 | if (it->multibyte_p) | |
1837 | { | |
1838 | int maxlen = ((IT_BYTEPOS (*it) >= GPT ? ZV : GPT) | |
1839 | - IT_BYTEPOS (*it)); | |
1840 | it2.c = STRING_CHAR_AND_LENGTH (p, maxlen, it2.len); | |
1841 | } | |
1842 | else | |
1843 | it2.c = *p, it2.len = 1; | |
1844 | ||
1845 | it2.glyph_row = NULL; | |
1846 | it2.what = IT_CHARACTER; | |
1847 | x_produce_glyphs (&it2); | |
1848 | width = NUMVAL (prop) * it2.pixel_width; | |
1849 | } | |
1850 | else if (prop = Fplist_get (plist, QCalign_to), | |
1851 | NUMVAL (prop) > 0) | |
1852 | width = NUMVAL (prop) * CANON_X_UNIT (it->f) - it->current_x; | |
1853 | else | |
1854 | /* Nothing specified -> width defaults to canonical char width. */ | |
1855 | width = CANON_X_UNIT (it->f); | |
1856 | ||
1857 | /* Compute height. */ | |
1858 | if (prop = Fplist_get (plist, QCheight), | |
1859 | NUMVAL (prop) > 0) | |
1860 | height = NUMVAL (prop) * CANON_Y_UNIT (it->f); | |
1861 | else if (prop = Fplist_get (plist, QCrelative_height), | |
1862 | NUMVAL (prop) > 0) | |
1863 | height = FONT_HEIGHT (font) * NUMVAL (prop); | |
1864 | else | |
1865 | height = FONT_HEIGHT (font); | |
1866 | ||
1867 | /* Compute percentage of height used for ascent. If | |
1868 | `:ascent ASCENT' is present and valid, use that. Otherwise, | |
1869 | derive the ascent from the font in use. */ | |
1870 | if (prop = Fplist_get (plist, QCascent), | |
1871 | NUMVAL (prop) > 0 && NUMVAL (prop) <= 100) | |
1872 | ascent = NUMVAL (prop) / 100.0; | |
1873 | else | |
1874 | ascent = (double) FONT_BASE (font) / FONT_HEIGHT (font); | |
1875 | ||
1876 | if (width <= 0) | |
1877 | width = 1; | |
1878 | if (height <= 0) | |
1879 | height = 1; | |
1880 | ||
1881 | if (it->glyph_row) | |
1882 | { | |
1883 | Lisp_Object object = it->stack[it->sp - 1].string; | |
1884 | if (!STRINGP (object)) | |
1885 | object = it->w->buffer; | |
1886 | x_append_stretch_glyph (it, object, width, height, ascent); | |
1887 | } | |
1888 | ||
1889 | it->pixel_width = width; | |
1890 | it->ascent = it->phys_ascent = height * ascent; | |
1891 | it->descent = it->phys_descent = height - it->ascent; | |
1892 | it->nglyphs = 1; | |
1893 | ||
1894 | if (face->box != FACE_NO_BOX) | |
1895 | { | |
1896 | it->ascent += face->box_line_width; | |
1897 | it->descent += face->box_line_width; | |
1898 | ||
1899 | if (it->start_of_box_run_p) | |
1900 | it->pixel_width += face->box_line_width; | |
1901 | if (it->end_of_box_run_p) | |
1902 | it->pixel_width += face->box_line_width; | |
1903 | } | |
1904 | ||
1905 | take_vertical_position_into_account (it); | |
1906 | } | |
1907 | ||
1908 | /* Return proper value to be used as baseline offset of font that has | |
1909 | ASCENT and DESCENT to draw characters by the font at the vertical | |
1910 | center of the line of frame F. | |
1911 | ||
1912 | Here, out task is to find the value of BOFF in the following figure; | |
1913 | ||
1914 | -------------------------+-----------+- | |
1915 | -+-+---------+-+ | | | |
1916 | | | | | | | | |
1917 | | | | | F_ASCENT F_HEIGHT | |
1918 | | | | ASCENT | | | |
1919 | HEIGHT | | | | | | |
1920 | | | |-|-+------+-----------|------- baseline | |
1921 | | | | | BOFF | | | |
1922 | | |---------|-+-+ | | | |
1923 | | | | DESCENT | | | |
1924 | -+-+---------+-+ F_DESCENT | | |
1925 | -------------------------+-----------+- | |
1926 | ||
1927 | -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT | |
1928 | BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT | |
1929 | DESCENT = FONT->descent | |
1930 | HEIGHT = FONT_HEIGHT (FONT) | |
1931 | F_DESCENT = (F->output_data.x->font->descent | |
1932 | - F->output_data.x->baseline_offset) | |
1933 | F_HEIGHT = FRAME_LINE_HEIGHT (F) | |
1934 | */ | |
1935 | ||
1936 | #define VCENTER_BASELINE_OFFSET(FONT, F) \ | |
458f45fa KH |
1937 | (FONT_DESCENT (FONT) \ |
1938 | + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \ | |
1939 | + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \ | |
1940 | - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F))) | |
791f420f JR |
1941 | |
1942 | /* Produce glyphs/get display metrics for the display element IT is | |
1943 | loaded with. See the description of struct display_iterator in | |
1944 | dispextern.h for an overview of struct display_iterator. */ | |
1945 | ||
1946 | static void | |
1947 | x_produce_glyphs (it) | |
1948 | struct it *it; | |
1949 | { | |
93ff4395 JR |
1950 | it->glyph_not_available_p = 0; |
1951 | ||
791f420f JR |
1952 | if (it->what == IT_CHARACTER) |
1953 | { | |
1954 | wchar_t char2b; | |
1955 | XFontStruct *font; | |
93ff4395 | 1956 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
791f420f | 1957 | XCharStruct *pcm; |
93ff4395 | 1958 | int font_not_found_p; |
791f420f JR |
1959 | struct font_info *font_info; |
1960 | int boff; /* baseline offset */ | |
2d0c0bd7 JR |
1961 | /* We may change it->multibyte_p upon unibyte<->multibyte |
1962 | conversion. So, save the current value now and restore it | |
1963 | later. | |
1964 | ||
1965 | Note: It seems that we don't have to record multibyte_p in | |
1966 | struct glyph because the character code itself tells if or | |
1967 | not the character is multibyte. Thus, in the future, we must | |
1968 | consider eliminating the field `multibyte_p' in the struct | |
1969 | glyph. | |
1970 | */ | |
1971 | int saved_multibyte_p = it->multibyte_p; | |
791f420f | 1972 | |
93ff4395 JR |
1973 | /* Maybe translate single-byte characters to multibyte, or the |
1974 | other way. */ | |
791f420f | 1975 | it->char_to_display = it->c; |
93ff4395 JR |
1976 | if (!ASCII_BYTE_P (it->c)) |
1977 | { | |
1978 | if (unibyte_display_via_language_environment | |
1979 | && SINGLE_BYTE_CHAR_P (it->c) | |
1980 | && (it->c >= 0240 | |
1981 | || !NILP (Vnonascii_translation_table))) | |
1982 | { | |
1983 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
2d0c0bd7 | 1984 | it->multibyte_p = 1; |
93ff4395 JR |
1985 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1986 | face = FACE_FROM_ID (it->f, it->face_id); | |
1987 | } | |
1988 | else if (!SINGLE_BYTE_CHAR_P (it->c) | |
1989 | && !it->multibyte_p) | |
1990 | { | |
1991 | it->char_to_display = multibyte_char_to_unibyte (it->c, Qnil); | |
2d0c0bd7 | 1992 | it->multibyte_p = 0; |
93ff4395 JR |
1993 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1994 | face = FACE_FROM_ID (it->f, it->face_id); | |
1995 | } | |
1996 | } | |
791f420f | 1997 | |
93ff4395 JR |
1998 | /* Get font to use. Encode IT->char_to_display. */ |
1999 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
2000 | it->face_id, &char2b, | |
2001 | it->multibyte_p); | |
791f420f JR |
2002 | font = face->font; |
2003 | ||
2004 | /* When no suitable font found, use the default font. */ | |
2005 | font_not_found_p = font == NULL; | |
2006 | if (font_not_found_p) | |
2007 | { | |
2008 | font = FRAME_FONT (it->f); | |
2009 | boff = it->f->output_data.w32->baseline_offset; | |
2010 | font_info = NULL; | |
2011 | } | |
2012 | else | |
2013 | { | |
2014 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2015 | boff = font_info->baseline_offset; | |
2016 | if (font_info->vertical_centering) | |
2017 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2018 | } | |
2019 | ||
791f420f JR |
2020 | if (it->char_to_display >= ' ' |
2021 | && (!it->multibyte_p || it->char_to_display < 128)) | |
2022 | { | |
2023 | /* Either unibyte or ASCII. */ | |
2024 | int stretched_p; | |
2025 | ||
2026 | it->nglyphs = 1; | |
2027 | ||
82f9d565 | 2028 | pcm = w32_per_char_metric (font, &char2b, |
9127e20e | 2029 | font->bdf ? BDF_1D_FONT : ANSI_FONT); |
791f420f JR |
2030 | it->ascent = FONT_BASE (font) + boff; |
2031 | it->descent = FONT_DESCENT (font) - boff; | |
791f420f | 2032 | |
9ef2e2cf JR |
2033 | if (pcm) |
2034 | { | |
2035 | it->phys_ascent = pcm->ascent + boff; | |
2036 | it->phys_descent = pcm->descent - boff; | |
2037 | it->pixel_width = pcm->width; | |
2038 | } | |
2039 | else | |
2040 | { | |
2041 | it->glyph_not_available_p = 1; | |
9127e20e JR |
2042 | it->phys_ascent = FONT_BASE (font) + boff; |
2043 | it->phys_descent = FONT_DESCENT (font) - boff; | |
2044 | it->pixel_width = FONT_WIDTH (font); | |
9ef2e2cf JR |
2045 | } |
2046 | ||
791f420f JR |
2047 | /* If this is a space inside a region of text with |
2048 | `space-width' property, change its width. */ | |
2049 | stretched_p = it->char_to_display == ' ' && !NILP (it->space_width); | |
2050 | if (stretched_p) | |
2051 | it->pixel_width *= XFLOATINT (it->space_width); | |
2052 | ||
2053 | /* If face has a box, add the box thickness to the character | |
2054 | height. If character has a box line to the left and/or | |
2055 | right, add the box line width to the character's width. */ | |
2056 | if (face->box != FACE_NO_BOX) | |
2057 | { | |
2058 | int thick = face->box_line_width; | |
2059 | ||
2060 | it->ascent += thick; | |
2061 | it->descent += thick; | |
2062 | ||
2063 | if (it->start_of_box_run_p) | |
2064 | it->pixel_width += thick; | |
2065 | if (it->end_of_box_run_p) | |
2066 | it->pixel_width += thick; | |
2067 | } | |
2068 | ||
2069 | /* If face has an overline, add the height of the overline | |
2070 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2071 | if (face->overline_p) | |
2072 | it->ascent += 2; | |
2073 | ||
2074 | take_vertical_position_into_account (it); | |
2075 | ||
2076 | /* If we have to actually produce glyphs, do it. */ | |
2077 | if (it->glyph_row) | |
2078 | { | |
2079 | if (stretched_p) | |
2080 | { | |
2081 | /* Translate a space with a `space-width' property | |
2082 | into a stretch glyph. */ | |
2083 | double ascent = (double) FONT_BASE (font) | |
2084 | / FONT_HEIGHT (font); | |
2085 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
2086 | it->ascent + it->descent, ascent); | |
2087 | } | |
2088 | else | |
2089 | x_append_glyph (it); | |
2090 | ||
2091 | /* If characters with lbearing or rbearing are displayed | |
2092 | in this line, record that fact in a flag of the | |
2093 | glyph row. This is used to optimize X output code. */ | |
9ef2e2cf | 2094 | if (pcm && (pcm->lbearing < 0 || pcm->rbearing > pcm->width)) |
791f420f JR |
2095 | it->glyph_row->contains_overlapping_glyphs_p = 1; |
2096 | } | |
2097 | } | |
2098 | else if (it->char_to_display == '\n') | |
2099 | { | |
2100 | /* A newline has no width but we need the height of the line. */ | |
2101 | it->pixel_width = 0; | |
2102 | it->nglyphs = 0; | |
2103 | it->ascent = it->phys_ascent = FONT_BASE (font) + boff; | |
2104 | it->descent = it->phys_descent = FONT_DESCENT (font) - boff; | |
2105 | ||
2106 | if (face->box != FACE_NO_BOX) | |
2107 | { | |
2108 | int thick = face->box_line_width; | |
2109 | it->ascent += thick; | |
2110 | it->descent += thick; | |
2111 | } | |
2112 | } | |
2113 | else if (it->char_to_display == '\t') | |
2114 | { | |
2115 | int tab_width = it->tab_width * CANON_X_UNIT (it->f); | |
9ef2e2cf | 2116 | int x = it->current_x + it->continuation_lines_width; |
791f420f JR |
2117 | int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; |
2118 | ||
9127e20e JR |
2119 | /* If the distance from the current position to the next tab |
2120 | stop is less than a canonical character width, use the | |
2121 | tab stop after that. */ | |
2122 | if (next_tab_x - x < CANON_X_UNIT (it->f)) | |
2123 | next_tab_x += tab_width; | |
2124 | ||
791f420f JR |
2125 | it->pixel_width = next_tab_x - x; |
2126 | it->nglyphs = 1; | |
2127 | it->ascent = it->phys_ascent = FONT_BASE (font) + boff; | |
2128 | it->descent = it->phys_descent = FONT_DESCENT (font) - boff; | |
2129 | ||
2130 | if (it->glyph_row) | |
2131 | { | |
2132 | double ascent = (double) it->ascent / (it->ascent + it->descent); | |
2133 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
2134 | it->ascent + it->descent, ascent); | |
2135 | } | |
2136 | } | |
2137 | else | |
2138 | { | |
00fe468b JR |
2139 | /* A multi-byte character. |
2140 | If we found a font, this font should give us the right | |
791f420f JR |
2141 | metrics. If we didn't find a font, use the frame's |
2142 | default font and calculate the width of the character | |
2143 | from the charset width; this is what old redisplay code | |
2144 | did. */ | |
9127e20e JR |
2145 | enum w32_char_font_type type; |
2146 | ||
2147 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (it->c)) == 1) | |
2148 | type = BDF_1D_FONT; | |
2149 | else if (font->bdf) | |
2150 | type = BDF_2D_FONT; | |
2151 | else | |
2152 | type = UNICODE_FONT; | |
2153 | ||
82f9d565 | 2154 | pcm = w32_per_char_metric (font, &char2b, type); |
00fe468b | 2155 | |
93ff4395 JR |
2156 | if (font_not_found_p || !pcm) |
2157 | { | |
2158 | int charset = CHAR_CHARSET (it->char_to_display); | |
00fe468b | 2159 | |
93ff4395 JR |
2160 | it->glyph_not_available_p = 1; |
2161 | it->pixel_width = (FONT_WIDTH (FRAME_FONT (it->f)) | |
2162 | * CHARSET_WIDTH (charset)); | |
2163 | it->phys_ascent = FONT_BASE (font) + boff; | |
2164 | it->phys_descent = FONT_DESCENT (font) - boff; | |
2165 | } | |
2166 | else | |
2167 | { | |
9ef2e2cf | 2168 | it->pixel_width = pcm->width; |
93ff4395 JR |
2169 | it->phys_ascent = pcm->ascent + boff; |
2170 | it->phys_descent = pcm->descent - boff; | |
2171 | if (it->glyph_row | |
2172 | && (pcm->lbearing < 0 | |
2173 | || pcm->rbearing > pcm->width)) | |
2174 | it->glyph_row->contains_overlapping_glyphs_p = 1; | |
00fe468b | 2175 | } |
791f420f JR |
2176 | it->nglyphs = 1; |
2177 | it->ascent = FONT_BASE (font) + boff; | |
2178 | it->descent = FONT_DESCENT (font) - boff; | |
00fe468b | 2179 | |
791f420f JR |
2180 | if (face->box != FACE_NO_BOX) |
2181 | { | |
2182 | int thick = face->box_line_width; | |
2183 | it->ascent += thick; | |
2184 | it->descent += thick; | |
2185 | ||
2186 | if (it->start_of_box_run_p) | |
2187 | it->pixel_width += thick; | |
2188 | if (it->end_of_box_run_p) | |
2189 | it->pixel_width += thick; | |
2190 | } | |
2191 | ||
2192 | /* If face has an overline, add the height of the overline | |
2193 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2194 | if (face->overline_p) | |
2195 | it->ascent += 2; | |
2196 | ||
2197 | take_vertical_position_into_account (it); | |
2198 | ||
2199 | if (it->glyph_row) | |
2200 | x_append_glyph (it); | |
2201 | } | |
2d0c0bd7 | 2202 | it->multibyte_p = saved_multibyte_p; |
791f420f JR |
2203 | } |
2204 | else if (it->what == IT_COMPOSITION) | |
2205 | { | |
01b220b6 JR |
2206 | /* Note: A composition is represented as one glyph in the |
2207 | glyph matrix. There are no padding glyphs. */ | |
2208 | wchar_t char2b; | |
2209 | XFontStruct *font; | |
2210 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
2211 | XCharStruct *pcm; | |
2212 | int font_not_found_p; | |
2213 | struct font_info *font_info; | |
2214 | int boff; /* baseline offset */ | |
2215 | struct composition *cmp = composition_table[it->cmp_id]; | |
2216 | ||
2217 | /* Maybe translate single-byte characters to multibyte. */ | |
2218 | it->char_to_display = it->c; | |
2219 | if (unibyte_display_via_language_environment | |
2220 | && SINGLE_BYTE_CHAR_P (it->c) | |
2221 | && (it->c >= 0240 | |
2222 | || (it->c >= 0200 | |
2223 | && !NILP (Vnonascii_translation_table)))) | |
2224 | { | |
2225 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
2226 | } | |
2227 | ||
2228 | /* Get face and font to use. Encode IT->char_to_display. */ | |
2229 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); | |
2230 | face = FACE_FROM_ID (it->f, it->face_id); | |
2231 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
2232 | it->face_id, &char2b, it->multibyte_p); | |
2233 | font = face->font; | |
2234 | ||
2235 | /* When no suitable font found, use the default font. */ | |
2236 | font_not_found_p = font == NULL; | |
2237 | if (font_not_found_p) | |
2238 | { | |
2239 | font = FRAME_FONT (it->f); | |
2240 | boff = it->f->output_data.w32->baseline_offset; | |
2241 | font_info = NULL; | |
2242 | } | |
2243 | else | |
2244 | { | |
2245 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2246 | boff = font_info->baseline_offset; | |
2247 | if (font_info->vertical_centering) | |
2248 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2249 | } | |
2250 | ||
2251 | /* There are no padding glyphs, so there is only one glyph to | |
2252 | produce for the composition. Important is that pixel_width, | |
2253 | ascent and descent are the values of what is drawn by | |
2254 | draw_glyphs (i.e. the values of the overall glyphs composed). */ | |
2255 | it->nglyphs = 1; | |
2256 | ||
2257 | /* If we have not yet calculated pixel size data of glyphs of | |
2258 | the composition for the current face font, calculate them | |
2259 | now. Theoretically, we have to check all fonts for the | |
2260 | glyphs, but that requires much time and memory space. So, | |
2261 | here we check only the font of the first glyph. This leads | |
2262 | to incorrect display very rarely, and C-l (recenter) can | |
2263 | correct the display anyway. */ | |
2264 | if (cmp->font != (void *) font) | |
2265 | { | |
2266 | /* Ascent and descent of the font of the first character of | |
2267 | this composition (adjusted by baseline offset). Ascent | |
2268 | and descent of overall glyphs should not be less than | |
2269 | them respectively. */ | |
2270 | int font_ascent = FONT_BASE (font) + boff; | |
2271 | int font_descent = FONT_DESCENT (font) - boff; | |
2272 | /* Bounding box of the overall glyphs. */ | |
2273 | int leftmost, rightmost, lowest, highest; | |
2274 | int i, width, ascent, descent; | |
1521ce96 | 2275 | enum w32_char_font_type font_type; |
01b220b6 JR |
2276 | |
2277 | cmp->font = (void *) font; | |
2278 | ||
2279 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (it->c)) == 1) | |
2280 | font_type = BDF_1D_FONT; | |
2281 | else if (font->bdf) | |
2282 | font_type = BDF_2D_FONT; | |
2283 | else | |
2284 | font_type = UNICODE_FONT; | |
2285 | ||
2286 | /* Initialize the bounding box. */ | |
f201d732 JR |
2287 | if (font_info |
2288 | && (pcm = w32_per_char_metric (font, &char2b, font_type))) | |
01b220b6 JR |
2289 | { |
2290 | width = pcm->width; | |
2291 | ascent = pcm->ascent; | |
2292 | descent = pcm->descent; | |
2293 | } | |
2294 | else | |
2295 | { | |
2296 | width = FONT_WIDTH (font); | |
2297 | ascent = FONT_BASE (font); | |
2298 | descent = FONT_DESCENT (font); | |
2299 | } | |
2300 | ||
2301 | rightmost = width; | |
2302 | lowest = - descent + boff; | |
2303 | highest = ascent + boff; | |
2304 | leftmost = 0; | |
2305 | ||
2306 | if (font_info | |
2307 | && font_info->default_ascent | |
2308 | && CHAR_TABLE_P (Vuse_default_ascent) | |
2309 | && !NILP (Faref (Vuse_default_ascent, | |
2310 | make_number (it->char_to_display)))) | |
2311 | highest = font_info->default_ascent + boff; | |
2312 | ||
2313 | /* Draw the first glyph at the normal position. It may be | |
2314 | shifted to right later if some other glyphs are drawn at | |
2315 | the left. */ | |
2316 | cmp->offsets[0] = 0; | |
2317 | cmp->offsets[1] = boff; | |
2318 | ||
2319 | /* Set cmp->offsets for the remaining glyphs. */ | |
2320 | for (i = 1; i < cmp->glyph_len; i++) | |
2321 | { | |
2322 | int left, right, btm, top; | |
2323 | int ch = COMPOSITION_GLYPH (cmp, i); | |
2324 | int face_id = FACE_FOR_CHAR (it->f, face, ch); | |
2325 | ||
2326 | face = FACE_FROM_ID (it->f, face_id); | |
2327 | x_get_char_face_and_encoding (it->f, ch, face->id, &char2b, | |
2328 | it->multibyte_p); | |
2329 | font = face->font; | |
2330 | if (font == NULL) | |
2331 | { | |
2332 | font = FRAME_FONT (it->f); | |
2333 | boff = it->f->output_data.w32->baseline_offset; | |
2334 | font_info = NULL; | |
2335 | } | |
2336 | else | |
2337 | { | |
2338 | font_info | |
2339 | = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2340 | boff = font_info->baseline_offset; | |
2341 | if (font_info->vertical_centering) | |
2342 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2343 | } | |
2344 | ||
2345 | if (font->bdf && CHARSET_DIMENSION (CHAR_CHARSET (ch)) == 1) | |
2346 | font_type = BDF_1D_FONT; | |
2347 | else if (font->bdf) | |
2348 | font_type = BDF_2D_FONT; | |
2349 | else | |
2350 | font_type = UNICODE_FONT; | |
2351 | ||
f201d732 JR |
2352 | if (font_info |
2353 | && (pcm = w32_per_char_metric (font, &char2b, font_type))) | |
01b220b6 JR |
2354 | { |
2355 | width = pcm->width; | |
2356 | ascent = pcm->ascent; | |
2357 | descent = pcm->descent; | |
2358 | } | |
2359 | else | |
2360 | { | |
2361 | width = FONT_WIDTH (font); | |
f201d732 JR |
2362 | ascent = 1; |
2363 | descent = 0; | |
01b220b6 JR |
2364 | } |
2365 | ||
2366 | if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) | |
2367 | { | |
2368 | /* Relative composition with or without | |
2369 | alternate chars. */ | |
2370 | left = (leftmost + rightmost - width) / 2; | |
2371 | btm = - descent + boff; | |
2372 | if (font_info && font_info->relative_compose | |
2373 | && (! CHAR_TABLE_P (Vignore_relative_composition) | |
2374 | || NILP (Faref (Vignore_relative_composition, | |
2375 | make_number (ch))))) | |
2376 | { | |
2377 | ||
2378 | if (- descent >= font_info->relative_compose) | |
2379 | /* One extra pixel between two glyphs. */ | |
2380 | btm = highest + 1; | |
2381 | else if (ascent <= 0) | |
2382 | /* One extra pixel between two glyphs. */ | |
2383 | btm = lowest - 1 - ascent - descent; | |
2384 | } | |
2385 | } | |
2386 | else | |
2387 | { | |
2388 | /* A composition rule is specified by an integer | |
2389 | value that encodes global and new reference | |
2390 | points (GREF and NREF). GREF and NREF are | |
2391 | specified by numbers as below: | |
2392 | ||
2393 | 0---1---2 -- ascent | |
2394 | | | | |
2395 | | | | |
2396 | | | | |
2397 | 9--10--11 -- center | |
2398 | | | | |
2399 | ---3---4---5--- baseline | |
2400 | | | | |
2401 | 6---7---8 -- descent | |
2402 | */ | |
2403 | int rule = COMPOSITION_RULE (cmp, i); | |
2404 | int gref, nref, grefx, grefy, nrefx, nrefy; | |
2405 | ||
2406 | COMPOSITION_DECODE_RULE (rule, gref, nref); | |
2407 | grefx = gref % 3, nrefx = nref % 3; | |
2408 | grefy = gref / 3, nrefy = nref / 3; | |
2409 | ||
2410 | left = (leftmost | |
2411 | + grefx * (rightmost - leftmost) / 2 | |
2412 | - nrefx * width / 2); | |
2413 | btm = ((grefy == 0 ? highest | |
2414 | : grefy == 1 ? 0 | |
2415 | : grefy == 2 ? lowest | |
2416 | : (highest + lowest) / 2) | |
2417 | - (nrefy == 0 ? ascent + descent | |
2418 | : nrefy == 1 ? descent - boff | |
2419 | : nrefy == 2 ? 0 | |
2420 | : (ascent + descent) / 2)); | |
2421 | } | |
2422 | ||
2423 | cmp->offsets[i * 2] = left; | |
2424 | cmp->offsets[i * 2 + 1] = btm + descent; | |
2425 | ||
2426 | /* Update the bounding box of the overall glyphs. */ | |
2427 | right = left + width; | |
2428 | top = btm + descent + ascent; | |
2429 | if (left < leftmost) | |
2430 | leftmost = left; | |
2431 | if (right > rightmost) | |
2432 | rightmost = right; | |
2433 | if (top > highest) | |
2434 | highest = top; | |
2435 | if (btm < lowest) | |
2436 | lowest = btm; | |
2437 | } | |
2438 | ||
2439 | /* If there are glyphs whose x-offsets are negative, | |
2440 | shift all glyphs to the right and make all x-offsets | |
2441 | non-negative. */ | |
2442 | if (leftmost < 0) | |
2443 | { | |
2444 | for (i = 0; i < cmp->glyph_len; i++) | |
2445 | cmp->offsets[i * 2] -= leftmost; | |
2446 | rightmost -= leftmost; | |
2447 | } | |
2448 | ||
2449 | cmp->pixel_width = rightmost; | |
2450 | cmp->ascent = highest; | |
2451 | cmp->descent = - lowest; | |
2452 | if (cmp->ascent < font_ascent) | |
2453 | cmp->ascent = font_ascent; | |
2454 | if (cmp->descent < font_descent) | |
2455 | cmp->descent = font_descent; | |
2456 | } | |
2457 | ||
2458 | it->pixel_width = cmp->pixel_width; | |
2459 | it->ascent = it->phys_ascent = cmp->ascent; | |
2460 | it->descent = it->phys_descent = cmp->descent; | |
2461 | ||
2462 | if (face->box != FACE_NO_BOX) | |
2463 | { | |
2464 | int thick = face->box_line_width; | |
2465 | it->ascent += thick; | |
2466 | it->descent += thick; | |
2467 | ||
2468 | if (it->start_of_box_run_p) | |
2469 | it->pixel_width += thick; | |
2470 | if (it->end_of_box_run_p) | |
2471 | it->pixel_width += thick; | |
2472 | } | |
2473 | ||
2474 | /* If face has an overline, add the height of the overline | |
2475 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2476 | if (face->overline_p) | |
2477 | it->ascent += 2; | |
2478 | ||
2479 | take_vertical_position_into_account (it); | |
2480 | ||
2481 | if (it->glyph_row) | |
2482 | x_append_composite_glyph (it); | |
791f420f JR |
2483 | } |
2484 | else if (it->what == IT_IMAGE) | |
2485 | x_produce_image_glyph (it); | |
2486 | else if (it->what == IT_STRETCH) | |
2487 | x_produce_stretch_glyph (it); | |
2488 | ||
2489 | /* Accumulate dimensions. */ | |
2490 | xassert (it->ascent >= 0 && it->descent > 0); | |
2491 | if (it->area == TEXT_AREA) | |
2492 | it->current_x += it->pixel_width; | |
2493 | ||
9ef2e2cf JR |
2494 | it->descent += it->extra_line_spacing; |
2495 | ||
791f420f JR |
2496 | it->max_ascent = max (it->max_ascent, it->ascent); |
2497 | it->max_descent = max (it->max_descent, it->descent); | |
2498 | it->max_phys_ascent = max (it->max_phys_ascent, it->phys_ascent); | |
2499 | it->max_phys_descent = max (it->max_phys_descent, it->phys_descent); | |
2500 | } | |
2501 | ||
2502 | ||
2503 | /* Estimate the pixel height of the mode or top line on frame F. | |
2504 | FACE_ID specifies what line's height to estimate. */ | |
2505 | ||
2506 | int | |
2507 | x_estimate_mode_line_height (f, face_id) | |
2508 | struct frame *f; | |
2509 | enum face_id face_id; | |
2510 | { | |
250cfece | 2511 | int height = FONT_HEIGHT (FRAME_FONT (f)); |
791f420f JR |
2512 | |
2513 | /* This function is called so early when Emacs starts that the face | |
2514 | cache and mode line face are not yet initialized. */ | |
2515 | if (FRAME_FACE_CACHE (f)) | |
2516 | { | |
2517 | struct face *face = FACE_FROM_ID (f, face_id); | |
9ef2e2cf | 2518 | if (face) |
250cfece JR |
2519 | { |
2520 | if (face->font) | |
2521 | height = FONT_HEIGHT (face->font); | |
2522 | height += 2 * face->box_line_width; | |
2523 | } | |
2524 | ||
791f420f JR |
2525 | } |
2526 | ||
2527 | return height; | |
2528 | } | |
cabb23bc | 2529 | |
cabb23bc | 2530 | \f |
791f420f JR |
2531 | |
2532 | BOOL | |
2533 | w32_use_unicode_for_codepage (codepage) | |
2534 | int codepage; | |
2535 | { | |
2536 | /* If the current codepage is supported, use Unicode for output. */ | |
2537 | return (w32_enable_unicode_output | |
02f593f3 JR |
2538 | && codepage != CP_8BIT |
2539 | && (codepage == CP_UNICODE || IsValidCodePage (codepage))); | |
791f420f JR |
2540 | } |
2541 | ||
2542 | \f | |
2543 | /*********************************************************************** | |
2544 | Glyph display | |
2545 | ***********************************************************************/ | |
2546 | ||
2547 | /* A sequence of glyphs to be drawn in the same face. | |
2548 | ||
2549 | This data structure is not really completely X specific, so it | |
2550 | could possibly, at least partially, be useful for other systems. It | |
2551 | is currently not part of the external redisplay interface because | |
2552 | it's not clear what other systems will need. */ | |
2553 | ||
2554 | struct glyph_string | |
2555 | { | |
2556 | /* X-origin of the string. */ | |
2557 | int x; | |
2558 | ||
2559 | /* Y-origin and y-position of the base line of this string. */ | |
2560 | int y, ybase; | |
2561 | ||
2562 | /* The width of the string, not including a face extension. */ | |
2563 | int width; | |
2564 | ||
2565 | /* The width of the string, including a face extension. */ | |
2566 | int background_width; | |
2567 | ||
2568 | /* The height of this string. This is the height of the line this | |
2569 | string is drawn in, and can be different from the height of the | |
2570 | font the string is drawn in. */ | |
2571 | int height; | |
2572 | ||
2573 | /* Number of pixels this string overwrites in front of its x-origin. | |
2574 | This number is zero if the string has an lbearing >= 0; it is | |
2575 | -lbearing, if the string has an lbearing < 0. */ | |
2576 | int left_overhang; | |
2577 | ||
2578 | /* Number of pixels this string overwrites past its right-most | |
2579 | nominal x-position, i.e. x + width. Zero if the string's | |
2580 | rbearing is <= its nominal width, rbearing - width otherwise. */ | |
2581 | int right_overhang; | |
2582 | ||
2583 | /* The frame on which the glyph string is drawn. */ | |
2584 | struct frame *f; | |
2585 | ||
2586 | /* The window on which the glyph string is drawn. */ | |
2587 | struct window *w; | |
2588 | ||
2589 | /* X display and window for convenience. */ | |
2590 | Window window; | |
2591 | ||
2592 | /* The glyph row for which this string was built. It determines the | |
2593 | y-origin and height of the string. */ | |
2594 | struct glyph_row *row; | |
2595 | ||
2596 | /* The area within row. */ | |
2597 | enum glyph_row_area area; | |
2598 | ||
2599 | /* Characters to be drawn, and number of characters. */ | |
2600 | wchar_t *char2b; | |
2601 | int nchars; | |
2602 | ||
791f420f JR |
2603 | /* A face-override for drawing cursors, mouse face and similar. */ |
2604 | enum draw_glyphs_face hl; | |
2605 | ||
2606 | /* Face in which this string is to be drawn. */ | |
2607 | struct face *face; | |
2608 | ||
2609 | /* Font in which this string is to be drawn. */ | |
2610 | XFontStruct *font; | |
2611 | ||
2612 | /* Font info for this string. */ | |
2613 | struct font_info *font_info; | |
2614 | ||
2615 | /* Non-null means this string describes (part of) a composition. | |
2616 | All characters from char2b are drawn composed. */ | |
2617 | struct composition *cmp; | |
2618 | ||
2619 | /* Index of this glyph string's first character in the glyph | |
2620 | definition of CMP. If this is zero, this glyph string describes | |
2621 | the first character of a composition. */ | |
2622 | int gidx; | |
2623 | ||
2624 | /* 1 means this glyph strings face has to be drawn to the right end | |
2625 | of the window's drawing area. */ | |
2626 | unsigned extends_to_end_of_line_p : 1; | |
2627 | ||
2628 | /* 1 means the background of this string has been drawn. */ | |
2629 | unsigned background_filled_p : 1; | |
2630 | ||
2631 | /* 1 means glyph string must be drawn with 16-bit functions. */ | |
2632 | unsigned two_byte_p : 1; | |
2633 | ||
2634 | /* 1 means that the original font determined for drawing this glyph | |
2635 | string could not be loaded. The member `font' has been set to | |
2636 | the frame's default font in this case. */ | |
2637 | unsigned font_not_found_p : 1; | |
2638 | ||
2639 | /* 1 means that the face in which this glyph string is drawn has a | |
2640 | stipple pattern. */ | |
2641 | unsigned stippled_p : 1; | |
2642 | ||
2643 | /* 1 means only the foreground of this glyph string must be drawn, | |
2644 | and we should use the physical height of the line this glyph | |
2645 | string appears in as clip rect. */ | |
2646 | unsigned for_overlaps_p : 1; | |
2647 | ||
2648 | /* The GC to use for drawing this glyph string. */ | |
2649 | XGCValues *gc; | |
2650 | ||
2651 | HDC hdc; | |
2652 | ||
2653 | /* A pointer to the first glyph in the string. This glyph | |
2654 | corresponds to char2b[0]. Needed to draw rectangles if | |
2655 | font_not_found_p is 1. */ | |
2656 | struct glyph *first_glyph; | |
2657 | ||
2658 | /* Image, if any. */ | |
2659 | struct image *img; | |
2660 | ||
2661 | struct glyph_string *next, *prev; | |
2662 | }; | |
2663 | ||
2664 | ||
9ef2e2cf | 2665 | /* Encapsulate the different ways of displaying text under W32. */ |
791f420f | 2666 | |
9127e20e | 2667 | void W32_TEXTOUT (s, x, y,chars,nchars) |
791f420f JR |
2668 | struct glyph_string * s; |
2669 | int x, y; | |
2670 | wchar_t * chars; | |
2671 | int nchars; | |
2672 | { | |
9ef2e2cf | 2673 | int charset_dim = w32_font_is_double_byte (s->gc->font) ? 2 : 1; |
791f420f JR |
2674 | if (s->gc->font->bdf) |
2675 | w32_BDF_TextOut (s->gc->font->bdf, s->hdc, | |
00c96995 JR |
2676 | x, y, (char *) chars, charset_dim, |
2677 | nchars * charset_dim, 0); | |
9ef2e2cf | 2678 | else if (s->first_glyph->w32_font_type == UNICODE_FONT) |
791f420f JR |
2679 | ExtTextOutW (s->hdc, x, y, 0, NULL, chars, nchars, NULL); |
2680 | else | |
2681 | ExtTextOut (s->hdc, x, y, 0, NULL, (char *) chars, | |
9ef2e2cf | 2682 | nchars * charset_dim, NULL); |
791f420f JR |
2683 | } |
2684 | ||
2685 | #if 0 | |
2686 | ||
2687 | static void | |
2688 | x_dump_glyph_string (s) | |
2689 | struct glyph_string *s; | |
2690 | { | |
2691 | fprintf (stderr, "glyph string\n"); | |
2692 | fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", | |
2693 | s->x, s->y, s->width, s->height); | |
2694 | fprintf (stderr, " ybase = %d\n", s->ybase); | |
2695 | fprintf (stderr, " hl = %d\n", s->hl); | |
2696 | fprintf (stderr, " left overhang = %d, right = %d\n", | |
2697 | s->left_overhang, s->right_overhang); | |
2698 | fprintf (stderr, " nchars = %d\n", s->nchars); | |
2699 | fprintf (stderr, " extends to end of line = %d\n", | |
2700 | s->extends_to_end_of_line_p); | |
2701 | fprintf (stderr, " font height = %d\n", FONT_HEIGHT (s->font)); | |
2702 | fprintf (stderr, " bg width = %d\n", s->background_width); | |
2703 | } | |
2704 | ||
2705 | #endif /* GLYPH_DEBUG */ | |
2706 | ||
2707 | ||
2708 | ||
2709 | static void x_append_glyph_string_lists P_ ((struct glyph_string **, | |
2710 | struct glyph_string **, | |
2711 | struct glyph_string *, | |
2712 | struct glyph_string *)); | |
2713 | static void x_prepend_glyph_string_lists P_ ((struct glyph_string **, | |
2714 | struct glyph_string **, | |
2715 | struct glyph_string *, | |
2716 | struct glyph_string *)); | |
2717 | static void x_append_glyph_string P_ ((struct glyph_string **, | |
2718 | struct glyph_string **, | |
2719 | struct glyph_string *)); | |
2720 | static int x_left_overwritten P_ ((struct glyph_string *)); | |
2721 | static int x_left_overwriting P_ ((struct glyph_string *)); | |
2722 | static int x_right_overwritten P_ ((struct glyph_string *)); | |
2723 | static int x_right_overwriting P_ ((struct glyph_string *)); | |
2724 | static int x_fill_glyph_string P_ ((struct glyph_string *, int, int, | |
2725 | int, int)); | |
2726 | static void w32_init_glyph_string P_ ((struct glyph_string *, HDC hdc, | |
2727 | wchar_t *, struct window *, | |
2728 | struct glyph_row *, | |
2729 | enum glyph_row_area, int, | |
2730 | enum draw_glyphs_face)); | |
2731 | static int x_draw_glyphs P_ ((struct window *, int , struct glyph_row *, | |
2732 | enum glyph_row_area, int, int, | |
2733 | enum draw_glyphs_face, int *, int *, int)); | |
2734 | static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); | |
2735 | static void x_set_glyph_string_gc P_ ((struct glyph_string *)); | |
2736 | static void x_draw_glyph_string_background P_ ((struct glyph_string *, | |
2737 | int)); | |
2738 | static void x_draw_glyph_string_foreground P_ ((struct glyph_string *)); | |
2739 | static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *)); | |
791f420f JR |
2740 | static void x_draw_glyph_string_box P_ ((struct glyph_string *)); |
2741 | static void x_draw_glyph_string P_ ((struct glyph_string *)); | |
2742 | static void x_compute_glyph_string_overhangs P_ ((struct glyph_string *)); | |
2743 | static void x_set_cursor_gc P_ ((struct glyph_string *)); | |
2744 | static void x_set_mode_line_face_gc P_ ((struct glyph_string *)); | |
2745 | static void x_set_mouse_face_gc P_ ((struct glyph_string *)); | |
2746 | static void w32_get_glyph_overhangs P_ ((HDC hdc, struct glyph *, | |
2747 | struct frame *, | |
9ef2e2cf | 2748 | int *, int *)); |
791f420f JR |
2749 | static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int)); |
2750 | static int w32_alloc_lighter_color (struct frame *, COLORREF *, double, int); | |
2751 | static void w32_setup_relief_color P_ ((struct frame *, struct relief *, | |
2752 | double, int, COLORREF)); | |
2753 | static void x_setup_relief_colors P_ ((struct glyph_string *)); | |
2754 | static void x_draw_image_glyph_string P_ ((struct glyph_string *)); | |
2755 | static void x_draw_image_relief P_ ((struct glyph_string *)); | |
2756 | static void x_draw_image_foreground P_ ((struct glyph_string *)); | |
2757 | static void w32_draw_image_foreground_1 P_ ((struct glyph_string *, HBITMAP)); | |
2758 | static void x_fill_image_glyph_string P_ ((struct glyph_string *)); | |
2759 | static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, | |
2760 | int, int, int)); | |
2761 | static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int, | |
2762 | int, int, int, int, RECT *)); | |
2763 | static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, | |
2764 | int, int, int, RECT *)); | |
2765 | static void x_fix_overlapping_area P_ ((struct window *, struct glyph_row *, | |
2766 | enum glyph_row_area)); | |
2767 | ||
2768 | ||
2769 | /* Append the list of glyph strings with head H and tail T to the list | |
2770 | with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ | |
2771 | ||
2772 | static INLINE void | |
2773 | x_append_glyph_string_lists (head, tail, h, t) | |
2774 | struct glyph_string **head, **tail; | |
2775 | struct glyph_string *h, *t; | |
2776 | { | |
2777 | if (h) | |
2778 | { | |
2779 | if (*head) | |
2780 | (*tail)->next = h; | |
2781 | else | |
2782 | *head = h; | |
2783 | h->prev = *tail; | |
2784 | *tail = t; | |
2785 | } | |
2786 | } | |
2787 | ||
2788 | ||
2789 | /* Prepend the list of glyph strings with head H and tail T to the | |
2790 | list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the | |
2791 | result. */ | |
2792 | ||
2793 | static INLINE void | |
2794 | x_prepend_glyph_string_lists (head, tail, h, t) | |
2795 | struct glyph_string **head, **tail; | |
2796 | struct glyph_string *h, *t; | |
2797 | { | |
2798 | if (h) | |
2799 | { | |
2800 | if (*head) | |
2801 | (*head)->prev = t; | |
2802 | else | |
2803 | *tail = t; | |
2804 | t->next = *head; | |
2805 | *head = h; | |
2806 | } | |
2807 | } | |
2808 | ||
2809 | ||
2810 | /* Append glyph string S to the list with head *HEAD and tail *TAIL. | |
2811 | Set *HEAD and *TAIL to the resulting list. */ | |
2812 | ||
2813 | static INLINE void | |
2814 | x_append_glyph_string (head, tail, s) | |
2815 | struct glyph_string **head, **tail; | |
2816 | struct glyph_string *s; | |
2817 | { | |
2818 | s->next = s->prev = NULL; | |
2819 | x_append_glyph_string_lists (head, tail, s, s); | |
2820 | } | |
2821 | ||
2822 | ||
2823 | /* Set S->gc to a suitable GC for drawing glyph string S in cursor | |
2824 | face. */ | |
2825 | ||
2826 | static void | |
2827 | x_set_cursor_gc (s) | |
2828 | struct glyph_string *s; | |
2829 | { | |
2830 | if (s->font == FRAME_FONT (s->f) | |
2831 | && s->face->background == FRAME_BACKGROUND_PIXEL (s->f) | |
2832 | && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f) | |
2833 | && !s->cmp) | |
2834 | s->gc = s->f->output_data.w32->cursor_gc; | |
2835 | else | |
2836 | { | |
2837 | /* Cursor on non-default face: must merge. */ | |
2838 | XGCValues xgcv; | |
2839 | unsigned long mask; | |
2840 | ||
2841 | xgcv.background = s->f->output_data.w32->cursor_pixel; | |
2842 | xgcv.foreground = s->face->background; | |
2843 | ||
2844 | /* If the glyph would be invisible, try a different foreground. */ | |
2845 | if (xgcv.foreground == xgcv.background) | |
2846 | xgcv.foreground = s->face->foreground; | |
2847 | if (xgcv.foreground == xgcv.background) | |
2848 | xgcv.foreground = s->f->output_data.w32->cursor_foreground_pixel; | |
2849 | if (xgcv.foreground == xgcv.background) | |
2850 | xgcv.foreground = s->face->foreground; | |
2851 | ||
2852 | /* Make sure the cursor is distinct from text in this face. */ | |
2853 | if (xgcv.background == s->face->background | |
2854 | && xgcv.foreground == s->face->foreground) | |
2855 | { | |
2856 | xgcv.background = s->face->foreground; | |
2857 | xgcv.foreground = s->face->background; | |
2858 | } | |
2859 | ||
2860 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2861 | xgcv.font = s->font; | |
2862 | mask = GCForeground | GCBackground | GCFont; | |
2863 | ||
2864 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2865 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2866 | mask, &xgcv); | |
2867 | else | |
2868 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2869 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
2870 | ||
2871 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2872 | } | |
2873 | } | |
2874 | ||
2875 | ||
2876 | /* Set up S->gc of glyph string S for drawing text in mouse face. */ | |
2877 | ||
2878 | static void | |
2879 | x_set_mouse_face_gc (s) | |
2880 | struct glyph_string *s; | |
2881 | { | |
2882 | int face_id; | |
93ff4395 | 2883 | struct face *face; |
791f420f JR |
2884 | |
2885 | /* What face has to be used for the mouse face? */ | |
2886 | face_id = FRAME_W32_DISPLAY_INFO (s->f)->mouse_face_face_id; | |
93ff4395 JR |
2887 | face = FACE_FROM_ID (s->f, face_id); |
2888 | face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch); | |
791f420f JR |
2889 | s->face = FACE_FROM_ID (s->f, face_id); |
2890 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); | |
2891 | ||
2892 | /* If font in this face is same as S->font, use it. */ | |
2893 | if (s->font == s->face->font) | |
2894 | s->gc = s->face->gc; | |
2895 | else | |
2896 | { | |
2897 | /* Otherwise construct scratch_cursor_gc with values from FACE | |
2898 | but font FONT. */ | |
2899 | XGCValues xgcv; | |
2900 | unsigned long mask; | |
2901 | ||
2902 | xgcv.background = s->face->background; | |
2903 | xgcv.foreground = s->face->foreground; | |
2904 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2905 | xgcv.font = s->font; | |
2906 | mask = GCForeground | GCBackground | GCFont; | |
2907 | ||
2908 | if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2909 | XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2910 | mask, &xgcv); | |
2911 | else | |
2912 | FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2913 | = XCreateGC (NULL, s->window, mask, &xgcv); | |
2914 | ||
2915 | s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2916 | } | |
2917 | ||
2918 | xassert (s->gc != 0); | |
2919 | } | |
2920 | ||
2921 | ||
2922 | /* Set S->gc of glyph string S to a GC suitable for drawing a mode line. | |
2923 | Faces to use in the mode line have already been computed when the | |
2924 | matrix was built, so there isn't much to do, here. */ | |
2925 | ||
2926 | static INLINE void | |
2927 | x_set_mode_line_face_gc (s) | |
2928 | struct glyph_string *s; | |
2929 | { | |
2930 | s->gc = s->face->gc; | |
791f420f JR |
2931 | } |
2932 | ||
2933 | ||
2934 | /* Set S->gc of glyph string S for drawing that glyph string. Set | |
2935 | S->stippled_p to a non-zero value if the face of S has a stipple | |
2936 | pattern. */ | |
2937 | ||
2938 | static INLINE void | |
2939 | x_set_glyph_string_gc (s) | |
2940 | struct glyph_string *s; | |
2941 | { | |
ec48c3a7 JR |
2942 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); |
2943 | ||
791f420f JR |
2944 | if (s->hl == DRAW_NORMAL_TEXT) |
2945 | { | |
2946 | s->gc = s->face->gc; | |
2947 | s->stippled_p = s->face->stipple != 0; | |
2948 | } | |
2949 | else if (s->hl == DRAW_INVERSE_VIDEO) | |
2950 | { | |
2951 | x_set_mode_line_face_gc (s); | |
2952 | s->stippled_p = s->face->stipple != 0; | |
2953 | } | |
2954 | else if (s->hl == DRAW_CURSOR) | |
2955 | { | |
2956 | x_set_cursor_gc (s); | |
2957 | s->stippled_p = 0; | |
2958 | } | |
2959 | else if (s->hl == DRAW_MOUSE_FACE) | |
2960 | { | |
2961 | x_set_mouse_face_gc (s); | |
2962 | s->stippled_p = s->face->stipple != 0; | |
2963 | } | |
2964 | else if (s->hl == DRAW_IMAGE_RAISED | |
2965 | || s->hl == DRAW_IMAGE_SUNKEN) | |
2966 | { | |
2967 | s->gc = s->face->gc; | |
2968 | s->stippled_p = s->face->stipple != 0; | |
2969 | } | |
2970 | else | |
2971 | { | |
2972 | s->gc = s->face->gc; | |
2973 | s->stippled_p = s->face->stipple != 0; | |
2974 | } | |
2975 | ||
2976 | /* GC must have been set. */ | |
2977 | xassert (s->gc != 0); | |
2978 | } | |
2979 | ||
2980 | ||
2981 | /* Return in *R the clipping rectangle for glyph string S. */ | |
2982 | ||
2983 | static void | |
2984 | w32_get_glyph_string_clip_rect (s, r) | |
2985 | struct glyph_string *s; | |
2986 | RECT *r; | |
2987 | { | |
2988 | int r_height, r_width; | |
2989 | ||
2990 | if (s->row->full_width_p) | |
2991 | { | |
2992 | /* Draw full-width. X coordinates are relative to S->w->left. */ | |
2993 | int canon_x = CANON_X_UNIT (s->f); | |
2994 | ||
2995 | r->left = WINDOW_LEFT_MARGIN (s->w) * canon_x; | |
2996 | r_width = XFASTINT (s->w->width) * canon_x; | |
2997 | ||
2998 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (s->f)) | |
2999 | { | |
3000 | int width = FRAME_SCROLL_BAR_WIDTH (s->f) * canon_x; | |
3001 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s->f)) | |
3002 | r->left -= width; | |
3003 | } | |
3004 | ||
3005 | r->left += FRAME_INTERNAL_BORDER_WIDTH (s->f); | |
3006 | ||
3007 | /* Unless displaying a mode or menu bar line, which are always | |
3008 | fully visible, clip to the visible part of the row. */ | |
3009 | if (s->w->pseudo_window_p) | |
3010 | r_height = s->row->visible_height; | |
3011 | else | |
3012 | r_height = s->height; | |
3013 | } | |
3014 | else | |
3015 | { | |
3016 | /* This is a text line that may be partially visible. */ | |
3017 | r->left = WINDOW_AREA_TO_FRAME_PIXEL_X (s->w, s->area, 0); | |
3018 | r_width = window_box_width (s->w, s->area); | |
3019 | r_height = s->row->visible_height; | |
3020 | } | |
3021 | ||
3022 | /* Don't use S->y for clipping because it doesn't take partially | |
3023 | visible lines into account. For example, it can be negative for | |
3024 | partially visible lines at the top of a window. */ | |
3025 | if (!s->row->full_width_p | |
3026 | && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s->w, s->row)) | |
3027 | r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); | |
3028 | else | |
3029 | r->top = max (0, s->row->y); | |
3030 | ||
3031 | /* If drawing a tool-bar window, draw it over the internal border | |
3032 | at the top of the window. */ | |
3033 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
3034 | r->top -= s->f->output_data.w32->internal_border_width; | |
3035 | ||
3036 | /* If S draws overlapping rows, it's sufficient to use the top and | |
3037 | bottom of the window for clipping because this glyph string | |
3038 | intentionally draws over other lines. */ | |
3039 | if (s->for_overlaps_p) | |
3040 | { | |
3041 | r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); | |
3042 | r_height = window_text_bottom_y (s->w) - r->top; | |
3043 | } | |
3044 | ||
3045 | r->top = WINDOW_TO_FRAME_PIXEL_Y (s->w, r->top); | |
3046 | ||
3047 | r->bottom = r->top + r_height; | |
3048 | r->right = r->left + r_width; | |
3049 | } | |
3050 | ||
3051 | ||
3052 | /* Set clipping for output of glyph string S. S may be part of a mode | |
3053 | line or menu if we don't have X toolkit support. */ | |
3054 | ||
3055 | static INLINE void | |
3056 | x_set_glyph_string_clipping (s) | |
3057 | struct glyph_string *s; | |
3058 | { | |
3059 | RECT r; | |
3060 | w32_get_glyph_string_clip_rect (s, &r); | |
3061 | w32_set_clip_rectangle (s->hdc, &r); | |
3062 | } | |
3063 | ||
3064 | ||
3065 | /* Compute left and right overhang of glyph string S. If S is a glyph | |
3066 | string for a composition, assume overhangs don't exist. */ | |
3067 | ||
3068 | static INLINE void | |
3069 | x_compute_glyph_string_overhangs (s) | |
3070 | struct glyph_string *s; | |
3071 | { | |
01b220b6 | 3072 | /* TODO: Windows does not appear to have a method for |
158cba56 JR |
3073 | getting this info without getting the ABC widths for each |
3074 | individual character and working it out manually. */ | |
791f420f JR |
3075 | } |
3076 | ||
3077 | ||
3078 | /* Compute overhangs and x-positions for glyph string S and its | |
3079 | predecessors, or successors. X is the starting x-position for S. | |
3080 | BACKWARD_P non-zero means process predecessors. */ | |
3081 | ||
3082 | static void | |
3083 | x_compute_overhangs_and_x (s, x, backward_p) | |
3084 | struct glyph_string *s; | |
3085 | int x; | |
3086 | int backward_p; | |
3087 | { | |
3088 | if (backward_p) | |
3089 | { | |
3090 | while (s) | |
3091 | { | |
3092 | x_compute_glyph_string_overhangs (s); | |
3093 | x -= s->width; | |
3094 | s->x = x; | |
3095 | s = s->prev; | |
3096 | } | |
3097 | } | |
3098 | else | |
3099 | { | |
3100 | while (s) | |
3101 | { | |
3102 | x_compute_glyph_string_overhangs (s); | |
3103 | s->x = x; | |
3104 | x += s->width; | |
3105 | s = s->next; | |
3106 | } | |
3107 | } | |
3108 | } | |
3109 | ||
3110 | ||
3111 | /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on | |
3112 | frame F. Overhangs of glyphs other than type CHAR_GLYPH are | |
3113 | assumed to be zero. */ | |
3114 | ||
3115 | static void | |
9ef2e2cf | 3116 | w32_get_glyph_overhangs (hdc, glyph, f, left, right) |
00fe468b | 3117 | HDC hdc; |
791f420f JR |
3118 | struct glyph *glyph; |
3119 | struct frame *f; | |
9ef2e2cf | 3120 | int *left, *right; |
791f420f JR |
3121 | { |
3122 | int c; | |
791f420f JR |
3123 | |
3124 | *left = *right = 0; | |
3125 | ||
3126 | if (glyph->type == CHAR_GLYPH) | |
3127 | { | |
3128 | XFontStruct *font; | |
3129 | struct face *face; | |
791f420f | 3130 | wchar_t char2b; |
93ff4395 JR |
3131 | XCharStruct *pcm; |
3132 | ||
3133 | face = x_get_glyph_face_and_encoding (f, glyph, &char2b, NULL); | |
791f420f | 3134 | font = face->font; |
9ef2e2cf | 3135 | |
93ff4395 | 3136 | if (font |
82f9d565 | 3137 | && (pcm = w32_per_char_metric (font, &char2b, |
9ef2e2cf | 3138 | glyph->w32_font_type))) |
791f420f | 3139 | { |
791f420f JR |
3140 | if (pcm->rbearing > pcm->width) |
3141 | *right = pcm->rbearing - pcm->width; | |
3142 | if (pcm->lbearing < 0) | |
3143 | *left = -pcm->lbearing; | |
3144 | } | |
3145 | } | |
791f420f JR |
3146 | } |
3147 | ||
3148 | ||
3149 | static void | |
3150 | x_get_glyph_overhangs (glyph, f, left, right) | |
3151 | struct glyph *glyph; | |
3152 | struct frame *f; | |
3153 | int *left, *right; | |
3154 | { | |
3155 | HDC hdc = get_frame_dc (f); | |
9ef2e2cf JR |
3156 | /* Convert to unicode! */ |
3157 | w32_get_glyph_overhangs (hdc, glyph, f, left, right); | |
791f420f JR |
3158 | release_frame_dc (f, hdc); |
3159 | } | |
3160 | ||
3161 | ||
3162 | /* Return the index of the first glyph preceding glyph string S that | |
3163 | is overwritten by S because of S's left overhang. Value is -1 | |
3164 | if no glyphs are overwritten. */ | |
3165 | ||
3166 | static int | |
3167 | x_left_overwritten (s) | |
3168 | struct glyph_string *s; | |
3169 | { | |
3170 | int k; | |
3171 | ||
3172 | if (s->left_overhang) | |
3173 | { | |
3174 | int x = 0, i; | |
3175 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3176 | int first = s->first_glyph - glyphs; | |
3177 | ||
3178 | for (i = first - 1; i >= 0 && x > -s->left_overhang; --i) | |
3179 | x -= glyphs[i].pixel_width; | |
3180 | ||
3181 | k = i + 1; | |
3182 | } | |
3183 | else | |
3184 | k = -1; | |
3185 | ||
3186 | return k; | |
3187 | } | |
3188 | ||
3189 | ||
3190 | /* Return the index of the first glyph preceding glyph string S that | |
3191 | is overwriting S because of its right overhang. Value is -1 if no | |
3192 | glyph in front of S overwrites S. */ | |
3193 | ||
3194 | static int | |
3195 | x_left_overwriting (s) | |
3196 | struct glyph_string *s; | |
3197 | { | |
3198 | int i, k, x; | |
3199 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3200 | int first = s->first_glyph - glyphs; | |
3201 | ||
3202 | k = -1; | |
3203 | x = 0; | |
3204 | for (i = first - 1; i >= 0; --i) | |
3205 | { | |
3206 | int left, right; | |
9ef2e2cf | 3207 | w32_get_glyph_overhangs (s->hdc, glyphs + i, s->f, &left, &right); |
791f420f JR |
3208 | if (x + right > 0) |
3209 | k = i; | |
3210 | x -= glyphs[i].pixel_width; | |
3211 | } | |
3212 | ||
3213 | return k; | |
3214 | } | |
3215 | ||
3216 | ||
3217 | /* Return the index of the last glyph following glyph string S that is | |
3218 | not overwritten by S because of S's right overhang. Value is -1 if | |
3219 | no such glyph is found. */ | |
3220 | ||
3221 | static int | |
3222 | x_right_overwritten (s) | |
3223 | struct glyph_string *s; | |
3224 | { | |
3225 | int k = -1; | |
3226 | ||
3227 | if (s->right_overhang) | |
3228 | { | |
3229 | int x = 0, i; | |
3230 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3231 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); | |
3232 | int end = s->row->used[s->area]; | |
3233 | ||
3234 | for (i = first; i < end && s->right_overhang > x; ++i) | |
3235 | x += glyphs[i].pixel_width; | |
3236 | ||
3237 | k = i; | |
3238 | } | |
3239 | ||
3240 | return k; | |
3241 | } | |
3242 | ||
3243 | ||
3244 | /* Return the index of the last glyph following glyph string S that | |
3245 | overwrites S because of its left overhang. Value is negative | |
3246 | if no such glyph is found. */ | |
3247 | ||
3248 | static int | |
3249 | x_right_overwriting (s) | |
3250 | struct glyph_string *s; | |
3251 | { | |
3252 | int i, k, x; | |
3253 | int end = s->row->used[s->area]; | |
3254 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3255 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); | |
3256 | ||
3257 | k = -1; | |
3258 | x = 0; | |
3259 | for (i = first; i < end; ++i) | |
3260 | { | |
3261 | int left, right; | |
9ef2e2cf | 3262 | w32_get_glyph_overhangs (s->hdc, glyphs + i, s->f, &left, &right); |
791f420f JR |
3263 | if (x - left < 0) |
3264 | k = i; | |
3265 | x += glyphs[i].pixel_width; | |
3266 | } | |
3267 | ||
3268 | return k; | |
3269 | } | |
3270 | ||
3271 | ||
3272 | /* Fill rectangle X, Y, W, H with background color of glyph string S. */ | |
3273 | ||
3274 | static INLINE void | |
3275 | x_clear_glyph_string_rect (s, x, y, w, h) | |
3276 | struct glyph_string *s; | |
3277 | int x, y, w, h; | |
3278 | { | |
3279 | int real_x = x; | |
3280 | int real_y = y; | |
3281 | int real_w = w; | |
3282 | int real_h = h; | |
3283 | #if 0 | |
3284 | /* Take clipping into account. */ | |
3285 | if (s->gc->clip_mask == Rect) | |
3286 | { | |
3287 | real_x = max (real_x, s->gc->clip_rectangle.left); | |
3288 | real_y = max (real_y, s->gc->clip_rectangle.top); | |
3289 | real_w = min (real_w, s->gc->clip_rectangle.right | |
3290 | - s->gc->clip_rectangle.left); | |
3291 | real_h = min (real_h, s->gc->clip_rectangle.bottom | |
3292 | - s->gc->clip_rectangle.top); | |
3293 | } | |
3294 | #endif | |
3295 | w32_fill_area (s->f, s->hdc, s->gc->background, real_x, real_y, | |
3296 | real_w, real_h); | |
3297 | } | |
3298 | ||
3299 | ||
3300 | /* Draw the background of glyph_string S. If S->background_filled_p | |
3301 | is non-zero don't draw it. FORCE_P non-zero means draw the | |
3302 | background even if it wouldn't be drawn normally. This is used | |
3303 | when a string preceding S draws into the background of S, or S | |
3304 | contains the first component of a composition. */ | |
3305 | ||
3306 | static void | |
3307 | x_draw_glyph_string_background (s, force_p) | |
3308 | struct glyph_string *s; | |
3309 | int force_p; | |
3310 | { | |
3311 | /* Nothing to do if background has already been drawn or if it | |
3312 | shouldn't be drawn in the first place. */ | |
3313 | if (!s->background_filled_p) | |
3314 | { | |
01b220b6 | 3315 | #if 0 /* TODO: stipple */ |
791f420f JR |
3316 | if (s->stippled_p) |
3317 | { | |
3318 | /* Fill background with a stipple pattern. */ | |
3319 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
3320 | XFillRectangle (s->display, s->window, s->gc, s->x, | |
3321 | s->y + s->face->box_line_width, | |
3322 | s->background_width, | |
3323 | s->height - 2 * s->face->box_line_width); | |
3324 | XSetFillStyle (s->display, s->gc, FillSolid); | |
3325 | s->background_filled_p = 1; | |
3326 | } | |
3327 | else | |
3328 | #endif | |
3329 | if (FONT_HEIGHT (s->font) < s->height - 2 * s->face->box_line_width | |
3330 | || s->font_not_found_p | |
3331 | || s->extends_to_end_of_line_p | |
9127e20e | 3332 | || s->font->bdf |
791f420f JR |
3333 | || force_p) |
3334 | { | |
3335 | x_clear_glyph_string_rect (s, s->x, s->y + s->face->box_line_width, | |
3336 | s->background_width, | |
3337 | s->height - 2 * s->face->box_line_width); | |
3338 | s->background_filled_p = 1; | |
3339 | } | |
3340 | } | |
3341 | } | |
3342 | ||
3343 | ||
3344 | /* Draw the foreground of glyph string S. */ | |
3345 | ||
3346 | static void | |
3347 | x_draw_glyph_string_foreground (s) | |
3348 | struct glyph_string *s; | |
3349 | { | |
3350 | int i, x; | |
01b220b6 | 3351 | HFONT old_font; |
791f420f JR |
3352 | |
3353 | /* If first glyph of S has a left box line, start drawing the text | |
3354 | of S to the right of that box line. */ | |
3355 | if (s->face->box != FACE_NO_BOX | |
3356 | && s->first_glyph->left_box_line_p) | |
3357 | x = s->x + s->face->box_line_width; | |
3358 | else | |
3359 | x = s->x; | |
3360 | ||
3361 | if (s->for_overlaps_p || (s->background_filled_p && s->hl != DRAW_CURSOR)) | |
3362 | SetBkMode (s->hdc, TRANSPARENT); | |
3363 | else | |
3364 | SetBkMode (s->hdc, OPAQUE); | |
3365 | ||
3366 | SetTextColor (s->hdc, s->gc->foreground); | |
3367 | SetBkColor (s->hdc, s->gc->background); | |
3368 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | |
3369 | ||
3370 | if (s->font && s->font->hfont) | |
01b220b6 | 3371 | old_font = SelectObject (s->hdc, s->font->hfont); |
791f420f JR |
3372 | |
3373 | /* Draw characters of S as rectangles if S's font could not be | |
3374 | loaded. */ | |
3375 | if (s->font_not_found_p) | |
3376 | { | |
3377 | for (i = 0; i < s->nchars; ++i) | |
3378 | { | |
3379 | struct glyph *g = s->first_glyph + i; | |
3380 | ||
3381 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, g->pixel_width - 1, | |
3382 | s->height - 1); | |
3383 | x += g->pixel_width; | |
3384 | } | |
3385 | } | |
3386 | else | |
3387 | { | |
3388 | char *char1b = (char *) s->char2b; | |
3389 | int boff = s->font_info->baseline_offset; | |
3390 | ||
3391 | if (s->font_info->vertical_centering) | |
3392 | boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; | |
3393 | ||
3394 | /* If we can use 8-bit functions, condense S->char2b. */ | |
3395 | if (!s->two_byte_p) | |
3396 | for (i = 0; i < s->nchars; ++i) | |
3397 | char1b[i] = BYTE2 (s->char2b[i]); | |
3398 | ||
3399 | /* Draw text with TextOut and friends. */ | |
3400 | W32_TEXTOUT (s, x, s->ybase - boff, s->char2b, s->nchars); | |
3401 | } | |
01b220b6 JR |
3402 | if (s->font && s->font->hfont) |
3403 | SelectObject (s->hdc, old_font); | |
791f420f JR |
3404 | } |
3405 | ||
3406 | /* Draw the foreground of composite glyph string S. */ | |
3407 | ||
3408 | static void | |
3409 | x_draw_composite_glyph_string_foreground (s) | |
3410 | struct glyph_string *s; | |
3411 | { | |
3412 | int i, x; | |
01b220b6 | 3413 | HFONT old_font; |
791f420f JR |
3414 | |
3415 | /* If first glyph of S has a left box line, start drawing the text | |
3416 | of S to the right of that box line. */ | |
3417 | if (s->face->box != FACE_NO_BOX | |
3418 | && s->first_glyph->left_box_line_p) | |
3419 | x = s->x + s->face->box_line_width; | |
3420 | else | |
3421 | x = s->x; | |
3422 | ||
3423 | /* S is a glyph string for a composition. S->gidx is the index of | |
3424 | the first character drawn for glyphs of this composition. | |
3425 | S->gidx == 0 means we are drawing the very first character of | |
3426 | this composition. */ | |
3427 | ||
3428 | SetTextColor (s->hdc, s->gc->foreground); | |
3429 | SetBkColor (s->hdc, s->gc->background); | |
3430 | SetBkMode (s->hdc, TRANSPARENT); | |
3431 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | |
3432 | ||
01b220b6 JR |
3433 | if (s->font && s->font->hfont) |
3434 | old_font = SelectObject (s->hdc, s->font->hfont); | |
3435 | ||
791f420f JR |
3436 | /* Draw a rectangle for the composition if the font for the very |
3437 | first character of the composition could not be loaded. */ | |
3438 | if (s->font_not_found_p) | |
3439 | { | |
3440 | if (s->gidx == 0) | |
3441 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1, | |
3442 | s->height - 1); | |
3443 | } | |
3444 | else | |
3445 | { | |
3446 | for (i = 0; i < s->nchars; i++, ++s->gidx) | |
01b220b6 JR |
3447 | W32_TEXTOUT (s, x + s->cmp->offsets[s->gidx * 2], |
3448 | s->ybase - s->cmp->offsets[s->gidx * 2 + 1], | |
3449 | s->char2b + i, 1); | |
791f420f | 3450 | } |
01b220b6 JR |
3451 | if (s->font && s->font->hfont) |
3452 | SelectObject (s->hdc, old_font); | |
791f420f JR |
3453 | } |
3454 | ||
e5fa381b JR |
3455 | |
3456 | /* Brightness beyond which a color won't have its highlight brightness | |
3457 | boosted. | |
3458 | ||
3459 | Nominally, highlight colors for `3d' faces are calculated by | |
3460 | brightening an object's color by a constant scale factor, but this | |
3461 | doesn't yield good results for dark colors, so for colors who's | |
3462 | brightness is less than this value (on a scale of 0-255) have to | |
3463 | use an additional additive factor. | |
3464 | ||
3465 | The value here is set so that the default menu-bar/mode-line color | |
3466 | (grey75) will not have its highlights changed at all. */ | |
3467 | #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187 | |
3468 | ||
3469 | ||
791f420f JR |
3470 | /* Allocate a color which is lighter or darker than *COLOR by FACTOR |
3471 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
3472 | If this produces the same color as COLOR, try a color where all RGB | |
3473 | values have DELTA added. Return the allocated color in *COLOR. | |
3474 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
3475 | Value is non-zero if successful. */ | |
3476 | ||
3477 | static int | |
3478 | w32_alloc_lighter_color (f, color, factor, delta) | |
3479 | struct frame *f; | |
3480 | COLORREF *color; | |
3481 | double factor; | |
3482 | int delta; | |
3483 | { | |
3484 | COLORREF new; | |
e5fa381b JR |
3485 | long bright; |
3486 | ||
3487 | /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */ | |
3488 | delta /= 256; | |
791f420f JR |
3489 | |
3490 | /* Change RGB values by specified FACTOR. Avoid overflow! */ | |
3491 | xassert (factor >= 0); | |
3492 | new = PALETTERGB (min (0xff, factor * GetRValue (*color)), | |
3493 | min (0xff, factor * GetGValue (*color)), | |
3494 | min (0xff, factor * GetBValue (*color))); | |
e5fa381b JR |
3495 | |
3496 | /* Calculate brightness of COLOR. */ | |
3497 | bright = (2 * GetRValue (*color) + 3 * GetGValue (*color) | |
3498 | + GetBValue (*color)) / 6; | |
3499 | ||
3500 | /* We only boost colors that are darker than | |
3501 | HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */ | |
3502 | if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT) | |
3503 | /* Make an additive adjustment to NEW, because it's dark enough so | |
3504 | that scaling by FACTOR alone isn't enough. */ | |
3505 | { | |
3506 | /* How far below the limit this color is (0 - 1, 1 being darker). */ | |
3507 | double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT; | |
3508 | /* The additive adjustment. */ | |
3509 | int min_delta = delta * dimness * factor / 2; | |
3510 | ||
3511 | if (factor < 1) | |
3512 | new = PALETTERGB (max (0, min (0xff, min_delta - GetRValue (*color))), | |
3513 | max (0, min (0xff, min_delta - GetGValue (*color))), | |
3514 | max (0, min (0xff, min_delta - GetBValue (*color)))); | |
3515 | else | |
3516 | new = PALETTERGB (max (0, min (0xff, min_delta + GetRValue (*color))), | |
3517 | max (0, min (0xff, min_delta + GetGValue (*color))), | |
3518 | max (0, min (0xff, min_delta + GetBValue (*color)))); | |
3519 | } | |
3520 | ||
791f420f JR |
3521 | if (new == *color) |
3522 | new = PALETTERGB (max (0, min (0xff, delta + GetRValue (*color))), | |
3523 | max (0, min (0xff, delta + GetGValue (*color))), | |
3524 | max (0, min (0xff, delta + GetBValue (*color)))); | |
3525 | ||
01b220b6 JR |
3526 | /* TODO: Map to palette and retry with delta if same? */ |
3527 | /* TODO: Free colors (if using palette)? */ | |
93ff4395 | 3528 | |
791f420f JR |
3529 | if (new == *color) |
3530 | return 0; | |
3531 | ||
3532 | *color = new; | |
3533 | ||
3534 | return 1; | |
3535 | } | |
3536 | ||
3537 | ||
3538 | /* Set up the foreground color for drawing relief lines of glyph | |
3539 | string S. RELIEF is a pointer to a struct relief containing the GC | |
3540 | with which lines will be drawn. Use a color that is FACTOR or | |
3541 | DELTA lighter or darker than the relief's background which is found | |
3542 | in S->f->output_data.x->relief_background. If such a color cannot | |
3543 | be allocated, use DEFAULT_PIXEL, instead. */ | |
3544 | ||
3545 | static void | |
3546 | w32_setup_relief_color (f, relief, factor, delta, default_pixel) | |
3547 | struct frame *f; | |
3548 | struct relief *relief; | |
3549 | double factor; | |
3550 | int delta; | |
3551 | COLORREF default_pixel; | |
3552 | { | |
3553 | XGCValues xgcv; | |
3554 | struct w32_output *di = f->output_data.w32; | |
3555 | unsigned long mask = GCForeground; | |
3556 | COLORREF pixel; | |
3557 | COLORREF background = di->relief_background; | |
3558 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
3559 | ||
01b220b6 | 3560 | /* TODO: Free colors (if using palette)? */ |
93ff4395 | 3561 | |
791f420f JR |
3562 | /* Allocate new color. */ |
3563 | xgcv.foreground = default_pixel; | |
3564 | pixel = background; | |
3565 | if (w32_alloc_lighter_color (f, &pixel, factor, delta)) | |
3566 | { | |
3567 | relief->allocated_p = 1; | |
3568 | xgcv.foreground = relief->pixel = pixel; | |
3569 | } | |
3570 | ||
3571 | if (relief->gc == 0) | |
3572 | { | |
01b220b6 | 3573 | #if 0 /* TODO: stipple */ |
791f420f JR |
3574 | xgcv.stipple = dpyinfo->gray; |
3575 | mask |= GCStipple; | |
3576 | #endif | |
3577 | relief->gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &xgcv); | |
3578 | } | |
3579 | else | |
3580 | XChangeGC (NULL, relief->gc, mask, &xgcv); | |
3581 | } | |
3582 | ||
3583 | ||
3584 | /* Set up colors for the relief lines around glyph string S. */ | |
3585 | ||
3586 | static void | |
3587 | x_setup_relief_colors (s) | |
3588 | struct glyph_string *s; | |
3589 | { | |
3590 | struct w32_output *di = s->f->output_data.w32; | |
3591 | COLORREF color; | |
3592 | ||
3593 | if (s->face->use_box_color_for_shadows_p) | |
3594 | color = s->face->box_color; | |
3595 | else | |
3596 | color = s->gc->background; | |
3597 | ||
3598 | if (di->white_relief.gc == 0 | |
3599 | || color != di->relief_background) | |
3600 | { | |
3601 | di->relief_background = color; | |
3602 | w32_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000, | |
3603 | WHITE_PIX_DEFAULT (s->f)); | |
3604 | w32_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000, | |
3605 | BLACK_PIX_DEFAULT (s->f)); | |
3606 | } | |
3607 | } | |
3608 | ||
3609 | ||
3610 | /* Draw a relief on frame F inside the rectangle given by LEFT_X, | |
3611 | TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief | |
3612 | to draw, it must be >= 0. RAISED_P non-zero means draw a raised | |
3613 | relief. LEFT_P non-zero means draw a relief on the left side of | |
3614 | the rectangle. RIGHT_P non-zero means draw a relief on the right | |
3615 | side of the rectangle. CLIP_RECT is the clipping rectangle to use | |
3616 | when drawing. */ | |
3617 | ||
3618 | static void | |
3619 | w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, | |
3620 | raised_p, left_p, right_p, clip_rect) | |
3621 | struct frame *f; | |
3622 | int left_x, top_y, right_x, bottom_y, left_p, right_p, raised_p; | |
3623 | RECT *clip_rect; | |
3624 | { | |
3625 | int i; | |
3626 | XGCValues gc; | |
3627 | HDC hdc = get_frame_dc (f); | |
3628 | ||
3629 | if (raised_p) | |
e5fa381b | 3630 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
791f420f | 3631 | else |
e5fa381b | 3632 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f JR |
3633 | |
3634 | w32_set_clip_rectangle (hdc, clip_rect); | |
3635 | ||
3636 | /* Top. */ | |
3637 | for (i = 0; i < width; ++i) | |
3638 | { | |
3639 | w32_fill_area (f, hdc, gc.foreground, | |
3640 | left_x + i * left_p, top_y + i, | |
3641 | (right_x + 1 - i * right_p) - (left_x + i * left_p), 1); | |
3642 | } | |
3643 | ||
3644 | /* Left. */ | |
3645 | if (left_p) | |
3646 | for (i = 0; i < width; ++i) | |
3647 | { | |
3648 | w32_fill_area (f, hdc, gc.foreground, | |
3649 | left_x + i, top_y + i, 1, | |
3650 | (bottom_y - i) - (top_y + i)); | |
3651 | } | |
3652 | ||
3653 | w32_set_clip_rectangle (hdc, NULL); | |
3654 | ||
3655 | if (raised_p) | |
e5fa381b | 3656 | gc.foreground = f->output_data.w32->black_relief.gc->foreground; |
791f420f | 3657 | else |
e5fa381b JR |
3658 | gc.foreground = f->output_data.w32->white_relief.gc->foreground; |
3659 | ||
791f420f JR |
3660 | |
3661 | w32_set_clip_rectangle (hdc, clip_rect); | |
3662 | ||
3663 | /* Bottom. */ | |
3664 | for (i = 0; i < width; ++i) | |
3665 | { | |
3666 | w32_fill_area (f, hdc, gc.foreground, | |
3667 | left_x + i * left_p, bottom_y - i, | |
3668 | (right_x + 1 - i * right_p) - left_x + i * left_p, 1); | |
3669 | } | |
3670 | ||
3671 | /* Right. */ | |
3672 | if (right_p) | |
3673 | for (i = 0; i < width; ++i) | |
3674 | { | |
3675 | w32_fill_area (f, hdc, gc.foreground, | |
3676 | right_x - i, top_y + i + 1, 1, | |
3677 | (bottom_y - i) - (top_y + i + 1)); | |
3678 | } | |
3679 | ||
3680 | w32_set_clip_rectangle (hdc, NULL); | |
3681 | ||
3682 | release_frame_dc (f, hdc); | |
3683 | } | |
3684 | ||
3685 | ||
3686 | /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y, | |
3687 | RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to | |
3688 | draw, it must be >= 0. LEFT_P non-zero means draw a line on the | |
3689 | left side of the rectangle. RIGHT_P non-zero means draw a line | |
3690 | on the right side of the rectangle. CLIP_RECT is the clipping | |
3691 | rectangle to use when drawing. */ | |
3692 | ||
3693 | static void | |
3694 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3695 | left_p, right_p, clip_rect) | |
3696 | struct glyph_string *s; | |
3697 | int left_x, top_y, right_x, bottom_y, width, left_p, right_p; | |
3698 | RECT *clip_rect; | |
3699 | { | |
00fe468b | 3700 | w32_set_clip_rectangle (s->hdc, clip_rect); |
791f420f JR |
3701 | |
3702 | /* Top. */ | |
00fe468b | 3703 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3704 | left_x, top_y, right_x - left_x + 1, width); |
791f420f JR |
3705 | |
3706 | /* Left. */ | |
3707 | if (left_p) | |
3708 | { | |
00fe468b | 3709 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3710 | left_x, top_y, width, bottom_y - top_y + 1); |
791f420f JR |
3711 | } |
3712 | ||
3713 | /* Bottom. */ | |
00fe468b | 3714 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3715 | left_x, bottom_y - width + 1, right_x - left_x + 1, width); |
791f420f JR |
3716 | |
3717 | /* Right. */ | |
3718 | if (right_p) | |
3719 | { | |
00fe468b | 3720 | w32_fill_area (s->f, s->hdc, s->face->box_color, |
2d0c0bd7 | 3721 | right_x - width + 1, top_y, width, bottom_y - top_y + 1); |
791f420f JR |
3722 | } |
3723 | ||
00fe468b | 3724 | w32_set_clip_rectangle (s->hdc, NULL); |
791f420f JR |
3725 | } |
3726 | ||
3727 | ||
3728 | /* Draw a box around glyph string S. */ | |
3729 | ||
3730 | static void | |
3731 | x_draw_glyph_string_box (s) | |
3732 | struct glyph_string *s; | |
3733 | { | |
3734 | int width, left_x, right_x, top_y, bottom_y, last_x, raised_p; | |
3735 | int left_p, right_p; | |
3736 | struct glyph *last_glyph; | |
3737 | RECT clip_rect; | |
3738 | ||
3739 | last_x = window_box_right (s->w, s->area); | |
3740 | if (s->row->full_width_p | |
3741 | && !s->w->pseudo_window_p) | |
3742 | { | |
3743 | last_x += FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s->f); | |
3744 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s->f)) | |
3745 | last_x += FRAME_SCROLL_BAR_WIDTH (s->f) * CANON_X_UNIT (s->f); | |
3746 | } | |
3747 | ||
3748 | /* The glyph that may have a right box line. */ | |
3749 | last_glyph = (s->cmp || s->img | |
3750 | ? s->first_glyph | |
3751 | : s->first_glyph + s->nchars - 1); | |
3752 | ||
3753 | width = s->face->box_line_width; | |
3754 | raised_p = s->face->box == FACE_RAISED_BOX; | |
3755 | left_x = s->x; | |
3756 | right_x = ((s->row->full_width_p | |
3757 | ? last_x - 1 | |
3758 | : min (last_x, s->x + s->background_width) - 1)); | |
3759 | top_y = s->y; | |
3760 | bottom_y = top_y + s->height - 1; | |
3761 | ||
3762 | left_p = (s->first_glyph->left_box_line_p | |
3763 | || (s->hl == DRAW_MOUSE_FACE | |
3764 | && (s->prev == NULL | |
3765 | || s->prev->hl != s->hl))); | |
3766 | right_p = (last_glyph->right_box_line_p | |
3767 | || (s->hl == DRAW_MOUSE_FACE | |
3768 | && (s->next == NULL | |
3769 | || s->next->hl != s->hl))); | |
3770 | ||
3771 | w32_get_glyph_string_clip_rect (s, &clip_rect); | |
3772 | ||
3773 | if (s->face->box == FACE_SIMPLE_BOX) | |
3774 | w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3775 | left_p, right_p, &clip_rect); | |
3776 | else | |
3777 | { | |
3778 | x_setup_relief_colors (s); | |
3779 | w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, | |
3780 | width, raised_p, left_p, right_p, &clip_rect); | |
3781 | } | |
3782 | } | |
3783 | ||
3784 | ||
3785 | /* Draw foreground of image glyph string S. */ | |
3786 | ||
3787 | static void | |
3788 | x_draw_image_foreground (s) | |
3789 | struct glyph_string *s; | |
3790 | { | |
3791 | int x; | |
9ef2e2cf | 3792 | int y = s->ybase - image_ascent (s->img, s->face); |
791f420f JR |
3793 | |
3794 | /* If first glyph of S has a left box line, start drawing it to the | |
3795 | right of that line. */ | |
3796 | if (s->face->box != FACE_NO_BOX | |
3797 | && s->first_glyph->left_box_line_p) | |
3798 | x = s->x + s->face->box_line_width; | |
3799 | else | |
3800 | x = s->x; | |
3801 | ||
3802 | /* If there is a margin around the image, adjust x- and y-position | |
3803 | by that margin. */ | |
3804 | if (s->img->margin) | |
3805 | { | |
3806 | x += s->img->margin; | |
3807 | y += s->img->margin; | |
3808 | } | |
3809 | ||
3810 | SaveDC (s->hdc); | |
3811 | ||
3812 | if (s->img->pixmap) | |
3813 | { | |
01b220b6 | 3814 | #if 0 /* TODO: image mask */ |
791f420f JR |
3815 | if (s->img->mask) |
3816 | { | |
3817 | /* We can't set both a clip mask and use XSetClipRectangles | |
3818 | because the latter also sets a clip mask. We also can't | |
3819 | trust on the shape extension to be available | |
3820 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3821 | manually. */ | |
3822 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3823 | | GCFunction); | |
3824 | XGCValues xgcv; | |
3825 | XRectangle clip_rect, image_rect, r; | |
3826 | ||
3827 | xgcv.clip_mask = s->img->mask; | |
3828 | xgcv.clip_x_origin = x; | |
3829 | xgcv.clip_y_origin = y; | |
3830 | xgcv.function = GXcopy; | |
3831 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3832 | ||
3833 | w32_get_glyph_string_clip_rect (s, &clip_rect); | |
3834 | image_rect.x = x; | |
3835 | image_rect.y = y; | |
3836 | image_rect.width = s->img->width; | |
3837 | image_rect.height = s->img->height; | |
158cba56 | 3838 | if (IntersectRect (&r, &clip_rect, &image_rect)) |
791f420f JR |
3839 | XCopyArea (s->display, s->img->pixmap, s->window, s->gc, |
3840 | r.x - x, r.y - y, r.width, r.height, r.x, r.y); | |
3841 | } | |
3842 | else | |
3843 | #endif | |
3844 | { | |
3845 | HDC compat_hdc = CreateCompatibleDC (s->hdc); | |
3846 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
3847 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
3848 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
158cba56 | 3849 | x_set_glyph_string_clipping (s); |
791f420f JR |
3850 | |
3851 | SetTextColor (s->hdc, s->gc->foreground); | |
3852 | SetBkColor (s->hdc, s->gc->background); | |
3853 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
3854 | BitBlt (s->hdc, x, y, s->img->width, s->img->height, | |
3855 | compat_hdc, 0, 0, SRCCOPY); | |
3856 | #else | |
3857 | BitBlt (s->hdc, x, y, s->img->width, s->img->height, | |
3858 | compat_hdc, 0, 0, 0xB8074A); | |
3859 | #endif | |
3860 | SelectObject (s->hdc, orig_brush); | |
3861 | DeleteObject (fg_brush); | |
3862 | SelectObject (compat_hdc, orig_obj); | |
3863 | DeleteDC (compat_hdc); | |
3864 | ||
3865 | /* When the image has a mask, we can expect that at | |
3866 | least part of a mouse highlight or a block cursor will | |
3867 | be visible. If the image doesn't have a mask, make | |
3868 | a block cursor visible by drawing a rectangle around | |
3869 | the image. I believe it's looking better if we do | |
3870 | nothing here for mouse-face. */ | |
3871 | if (s->hl == DRAW_CURSOR) | |
3872 | w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width - 1, | |
3873 | s->img->height - 1); | |
9127e20e | 3874 | w32_set_clip_rectangle (s->hdc, NULL); |
791f420f JR |
3875 | } |
3876 | } | |
3877 | else | |
3878 | w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width -1, | |
3879 | s->img->height - 1); | |
ee78dc32 | 3880 | |
791f420f JR |
3881 | RestoreDC (s->hdc ,-1); |
3882 | } | |
ee78dc32 | 3883 | |
791f420f JR |
3884 | |
3885 | ||
3886 | /* Draw a relief around the image glyph string S. */ | |
3887 | ||
3888 | static void | |
3889 | x_draw_image_relief (s) | |
3890 | struct glyph_string *s; | |
3891 | { | |
3892 | int x0, y0, x1, y1, thick, raised_p; | |
3893 | RECT r; | |
3894 | int x; | |
9ef2e2cf JR |
3895 | int y = s->ybase - image_ascent (s->img, s->face); |
3896 | ||
791f420f JR |
3897 | /* If first glyph of S has a left box line, start drawing it to the |
3898 | right of that line. */ | |
3899 | if (s->face->box != FACE_NO_BOX | |
3900 | && s->first_glyph->left_box_line_p) | |
3901 | x = s->x + s->face->box_line_width; | |
3902 | else | |
3903 | x = s->x; | |
3904 | ||
3905 | /* If there is a margin around the image, adjust x- and y-position | |
3906 | by that margin. */ | |
3907 | if (s->img->margin) | |
3908 | { | |
3909 | x += s->img->margin; | |
3910 | y += s->img->margin; | |
3911 | } | |
3912 | ||
3913 | if (s->hl == DRAW_IMAGE_SUNKEN | |
3914 | || s->hl == DRAW_IMAGE_RAISED) | |
3915 | { | |
3916 | thick = tool_bar_button_relief > 0 ? tool_bar_button_relief : 3; | |
3917 | raised_p = s->hl == DRAW_IMAGE_RAISED; | |
3918 | } | |
3919 | else | |
ee78dc32 | 3920 | { |
791f420f JR |
3921 | thick = abs (s->img->relief); |
3922 | raised_p = s->img->relief > 0; | |
3923 | } | |
3924 | ||
3925 | x0 = x - thick; | |
3926 | y0 = y - thick; | |
3927 | x1 = x + s->img->width + thick - 1; | |
3928 | y1 = y + s->img->height + thick - 1; | |
3929 | ||
3930 | x_setup_relief_colors (s); | |
3931 | w32_get_glyph_string_clip_rect (s, &r); | |
3932 | w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); | |
3933 | } | |
ee78dc32 | 3934 | |
791f420f JR |
3935 | |
3936 | /* Draw the foreground of image glyph string S to PIXMAP. */ | |
3937 | ||
3938 | static void | |
3939 | w32_draw_image_foreground_1 (s, pixmap) | |
3940 | struct glyph_string *s; | |
3941 | HBITMAP pixmap; | |
3942 | { | |
3943 | HDC hdc = CreateCompatibleDC (s->hdc); | |
3944 | HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap); | |
3945 | int x; | |
9ef2e2cf | 3946 | int y = s->ybase - s->y - image_ascent (s->img, s->face); |
791f420f JR |
3947 | |
3948 | /* If first glyph of S has a left box line, start drawing it to the | |
3949 | right of that line. */ | |
3950 | if (s->face->box != FACE_NO_BOX | |
3951 | && s->first_glyph->left_box_line_p) | |
3952 | x = s->face->box_line_width; | |
3953 | else | |
3954 | x = 0; | |
3955 | ||
3956 | /* If there is a margin around the image, adjust x- and y-position | |
3957 | by that margin. */ | |
3958 | if (s->img->margin) | |
3959 | { | |
3960 | x += s->img->margin; | |
3961 | y += s->img->margin; | |
3962 | } | |
3963 | ||
3964 | if (s->img->pixmap) | |
3965 | { | |
01b220b6 | 3966 | #if 0 /* TODO: image mask */ |
791f420f JR |
3967 | if (s->img->mask) |
3968 | { | |
3969 | /* We can't set both a clip mask and use XSetClipRectangles | |
3970 | because the latter also sets a clip mask. We also can't | |
3971 | trust on the shape extension to be available | |
3972 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3973 | manually. */ | |
3974 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3975 | | GCFunction); | |
3976 | XGCValues xgcv; | |
3977 | ||
3978 | xgcv.clip_mask = s->img->mask; | |
3979 | xgcv.clip_x_origin = x; | |
3980 | xgcv.clip_y_origin = y; | |
3981 | xgcv.function = GXcopy; | |
3982 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3983 | ||
3984 | XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, | |
3985 | 0, 0, s->img->width, s->img->height, x, y); | |
3986 | XSetClipMask (s->display, s->gc, None); | |
3987 | } | |
3988 | else | |
3989 | #endif | |
ef0e360f | 3990 | { |
791f420f JR |
3991 | HDC compat_hdc = CreateCompatibleDC (hdc); |
3992 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
3993 | HBRUSH orig_brush = SelectObject (hdc, fg_brush); | |
3994 | HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); | |
3995 | ||
3996 | SetTextColor (hdc, s->gc->foreground); | |
3997 | SetBkColor (hdc, s->gc->background); | |
3998 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
3999 | BitBlt (hdc, x, y, s->img->width, s->img->height, | |
4000 | compat_hdc, 0, 0, SRCCOPY); | |
4001 | #else | |
4002 | BitBlt (hdc, x, y, s->img->width, s->img->height, | |
4003 | compat_hdc, 0, 0, 0xB8074A); | |
4004 | #endif | |
4005 | SelectObject (hdc, orig_brush); | |
4006 | DeleteObject (fg_brush); | |
4007 | SelectObject (compat_hdc, orig_obj); | |
4008 | DeleteDC (compat_hdc); | |
4009 | ||
4010 | /* When the image has a mask, we can expect that at | |
4011 | least part of a mouse highlight or a block cursor will | |
4012 | be visible. If the image doesn't have a mask, make | |
4013 | a block cursor visible by drawing a rectangle around | |
4014 | the image. I believe it's looking better if we do | |
4015 | nothing here for mouse-face. */ | |
4016 | if (s->hl == DRAW_CURSOR) | |
4017 | w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, | |
4018 | s->img->height - 1); | |
ef0e360f | 4019 | } |
791f420f JR |
4020 | } |
4021 | else | |
4022 | w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, | |
4023 | s->img->height - 1); | |
4024 | ||
4025 | SelectObject (hdc, orig_hdc_obj); | |
4026 | DeleteDC (hdc); | |
4027 | } | |
4028 | ||
4029 | ||
4030 | /* Draw part of the background of glyph string S. X, Y, W, and H | |
4031 | give the rectangle to draw. */ | |
4032 | ||
4033 | static void | |
4034 | x_draw_glyph_string_bg_rect (s, x, y, w, h) | |
4035 | struct glyph_string *s; | |
4036 | int x, y, w, h; | |
4037 | { | |
01b220b6 | 4038 | #if 0 /* TODO: stipple */ |
791f420f JR |
4039 | if (s->stippled_p) |
4040 | { | |
4041 | /* Fill background with a stipple pattern. */ | |
4042 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4043 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
4044 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4045 | } | |
4046 | else | |
4047 | #endif | |
4048 | x_clear_glyph_string_rect (s, x, y, w, h); | |
4049 | } | |
4050 | ||
4051 | ||
4052 | /* Draw image glyph string S. | |
4053 | ||
4054 | s->y | |
4055 | s->x +------------------------- | |
4056 | | s->face->box | |
4057 | | | |
4058 | | +------------------------- | |
4059 | | | s->img->margin | |
4060 | | | | |
4061 | | | +------------------- | |
4062 | | | | the image | |
cabb23bc | 4063 | |
791f420f JR |
4064 | */ |
4065 | ||
4066 | static void | |
4067 | x_draw_image_glyph_string (s) | |
4068 | struct glyph_string *s; | |
4069 | { | |
4070 | int x, y; | |
4071 | int box_line_width = s->face->box_line_width; | |
4072 | int margin = s->img->margin; | |
4073 | int height; | |
4074 | HBITMAP pixmap = 0; | |
4075 | ||
4076 | height = s->height - 2 * box_line_width; | |
4077 | ||
4078 | /* Fill background with face under the image. Do it only if row is | |
4079 | taller than image or if image has a clip mask to reduce | |
4080 | flickering. */ | |
4081 | s->stippled_p = s->face->stipple != 0; | |
4082 | if (height > s->img->height | |
4083 | || margin | |
01b220b6 | 4084 | #if 0 /* TODO: image mask */ |
791f420f JR |
4085 | || s->img->mask |
4086 | #endif | |
4087 | || s->img->pixmap == 0 | |
4088 | || s->width != s->background_width) | |
4089 | { | |
4090 | if (box_line_width && s->first_glyph->left_box_line_p) | |
4091 | x = s->x + box_line_width; | |
4092 | else | |
4093 | x = s->x; | |
4094 | ||
4095 | y = s->y + box_line_width; | |
01b220b6 | 4096 | #if 0 /* TODO: image mask */ |
791f420f | 4097 | if (s->img->mask) |
ee78dc32 | 4098 | { |
791f420f JR |
4099 | /* Create a pixmap as large as the glyph string Fill it with |
4100 | the background color. Copy the image to it, using its | |
4101 | mask. Copy the temporary pixmap to the display. */ | |
4102 | Screen *screen = FRAME_X_SCREEN (s->f); | |
4103 | int depth = DefaultDepthOfScreen (screen); | |
4104 | ||
4105 | /* Create a pixmap as large as the glyph string. */ | |
4106 | pixmap = XCreatePixmap (s->display, s->window, | |
4107 | s->background_width, | |
4108 | s->height, depth); | |
4109 | ||
4110 | /* Don't clip in the following because we're working on the | |
4111 | pixmap. */ | |
4112 | XSetClipMask (s->display, s->gc, None); | |
ee78dc32 | 4113 | |
791f420f JR |
4114 | /* Fill the pixmap with the background color/stipple. */ |
4115 | if (s->stippled_p) | |
4116 | { | |
4117 | /* Fill background with a stipple pattern. */ | |
4118 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4119 | XFillRectangle (s->display, pixmap, s->gc, | |
4120 | 0, 0, s->background_width, s->height); | |
4121 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4122 | } | |
ef0e360f | 4123 | else |
791f420f JR |
4124 | { |
4125 | XGCValues xgcv; | |
4126 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, | |
4127 | &xgcv); | |
4128 | XSetForeground (s->display, s->gc, xgcv.background); | |
4129 | XFillRectangle (s->display, pixmap, s->gc, | |
4130 | 0, 0, s->background_width, s->height); | |
4131 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4132 | } | |
ee78dc32 | 4133 | } |
791f420f JR |
4134 | else |
4135 | #endif | |
791f420f JR |
4136 | x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height); |
4137 | ||
4138 | s->background_filled_p = 1; | |
4139 | } | |
ee78dc32 | 4140 | |
791f420f JR |
4141 | /* Draw the foreground. */ |
4142 | if (pixmap != 0) | |
4143 | { | |
4144 | w32_draw_image_foreground_1 (s, pixmap); | |
4145 | x_set_glyph_string_clipping (s); | |
ee78dc32 | 4146 | { |
791f420f JR |
4147 | HDC compat_hdc = CreateCompatibleDC (s->hdc); |
4148 | HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); | |
4149 | HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); | |
4150 | HGDIOBJ orig_obj = SelectObject (compat_hdc, pixmap); | |
4151 | ||
4152 | SetTextColor (s->hdc, s->gc->foreground); | |
4153 | SetBkColor (s->hdc, s->gc->background); | |
4154 | #if 0 /* From w32bdf.c (which is from Meadow). */ | |
4155 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, | |
4156 | compat_hdc, 0, 0, SRCCOPY); | |
4157 | #else | |
4158 | BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, | |
4159 | compat_hdc, 0, 0, 0xB8074A); | |
4160 | #endif | |
4161 | SelectObject (s->hdc, orig_brush); | |
4162 | DeleteObject (fg_brush); | |
4163 | SelectObject (compat_hdc, orig_obj); | |
4164 | DeleteDC (compat_hdc); | |
4165 | } | |
4166 | DeleteObject (pixmap); | |
4167 | pixmap = 0; | |
4168 | } | |
4169 | else | |
4170 | x_draw_image_foreground (s); | |
ee78dc32 | 4171 | |
791f420f JR |
4172 | /* If we must draw a relief around the image, do it. */ |
4173 | if (s->img->relief | |
4174 | || s->hl == DRAW_IMAGE_RAISED | |
4175 | || s->hl == DRAW_IMAGE_SUNKEN) | |
4176 | x_draw_image_relief (s); | |
4177 | } | |
ee78dc32 | 4178 | |
cabb23bc | 4179 | |
791f420f | 4180 | /* Draw stretch glyph string S. */ |
cabb23bc | 4181 | |
791f420f JR |
4182 | static void |
4183 | x_draw_stretch_glyph_string (s) | |
4184 | struct glyph_string *s; | |
4185 | { | |
4186 | xassert (s->first_glyph->type == STRETCH_GLYPH); | |
4187 | s->stippled_p = s->face->stipple != 0; | |
65c4903c | 4188 | |
791f420f JR |
4189 | if (s->hl == DRAW_CURSOR |
4190 | && !x_stretch_cursor_p) | |
4191 | { | |
4192 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor | |
4193 | as wide as the stretch glyph. */ | |
4194 | int width = min (CANON_X_UNIT (s->f), s->background_width); | |
cabb23bc | 4195 | |
791f420f JR |
4196 | /* Draw cursor. */ |
4197 | x_draw_glyph_string_bg_rect (s, s->x, s->y, width, s->height); | |
cabb23bc | 4198 | |
791f420f JR |
4199 | /* Clear rest using the GC of the original non-cursor face. */ |
4200 | if (width < s->background_width) | |
4201 | { | |
4202 | XGCValues *gc = s->face->gc; | |
4203 | int x = s->x + width, y = s->y; | |
4204 | int w = s->background_width - width, h = s->height; | |
4205 | RECT r; | |
4206 | HDC hdc = s->hdc; | |
4207 | w32_get_glyph_string_clip_rect (s, &r); | |
4208 | w32_set_clip_rectangle (hdc, &r); | |
4209 | ||
01b220b6 | 4210 | #if 0 /* TODO: stipple */ |
791f420f JR |
4211 | if (s->face->stipple) |
4212 | { | |
4213 | /* Fill background with a stipple pattern. */ | |
4214 | XSetFillStyle (s->display, gc, FillOpaqueStippled); | |
4215 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
4216 | XSetFillStyle (s->display, gc, FillSolid); | |
4217 | } | |
4218 | else | |
4219 | #endif | |
4220 | { | |
4221 | w32_fill_area (s->f, s->hdc, gc->background, x, y, w, h); | |
4222 | } | |
4223 | } | |
4224 | } | |
4225 | else | |
4226 | x_draw_glyph_string_bg_rect (s, s->x, s->y, s->background_width, | |
4227 | s->height); | |
4228 | ||
4229 | s->background_filled_p = 1; | |
4230 | } | |
cabb23bc | 4231 | |
cabb23bc | 4232 | |
791f420f JR |
4233 | /* Draw glyph string S. */ |
4234 | ||
4235 | static void | |
4236 | x_draw_glyph_string (s) | |
4237 | struct glyph_string *s; | |
4238 | { | |
4239 | /* If S draws into the background of its successor, draw the | |
4240 | background of the successor first so that S can draw into it. | |
4241 | This makes S->next use XDrawString instead of XDrawImageString. */ | |
4242 | if (s->next && s->right_overhang && !s->for_overlaps_p) | |
4243 | { | |
4244 | xassert (s->next->img == NULL); | |
4245 | x_set_glyph_string_gc (s->next); | |
4246 | x_set_glyph_string_clipping (s->next); | |
4247 | x_draw_glyph_string_background (s->next, 1); | |
4248 | } | |
4249 | ||
4250 | /* Set up S->gc, set clipping and draw S. */ | |
4251 | x_set_glyph_string_gc (s); | |
4252 | x_set_glyph_string_clipping (s); | |
4253 | ||
4254 | switch (s->first_glyph->type) | |
4255 | { | |
4256 | case IMAGE_GLYPH: | |
4257 | x_draw_image_glyph_string (s); | |
4258 | break; | |
4259 | ||
4260 | case STRETCH_GLYPH: | |
4261 | x_draw_stretch_glyph_string (s); | |
4262 | break; | |
4263 | ||
4264 | case CHAR_GLYPH: | |
4265 | if (s->for_overlaps_p) | |
4266 | s->background_filled_p = 1; | |
4267 | else | |
4268 | x_draw_glyph_string_background (s, 0); | |
4269 | x_draw_glyph_string_foreground (s); | |
4270 | break; | |
4271 | ||
4272 | case COMPOSITE_GLYPH: | |
4273 | if (s->for_overlaps_p || s->gidx > 0) | |
4274 | s->background_filled_p = 1; | |
4275 | else | |
4276 | x_draw_glyph_string_background (s, 1); | |
4277 | x_draw_composite_glyph_string_foreground (s); | |
4278 | break; | |
4279 | ||
4280 | default: | |
4281 | abort (); | |
4282 | } | |
4283 | ||
4284 | if (!s->for_overlaps_p) | |
4285 | { | |
4286 | /* Draw underline. */ | |
9ef2e2cf JR |
4287 | if (s->face->underline_p |
4288 | && (s->font->bdf || !s->font->tm.tmUnderlined)) | |
791f420f JR |
4289 | { |
4290 | unsigned long h = 1; | |
4291 | unsigned long dy = s->height - h; | |
4292 | ||
4293 | if (s->face->underline_defaulted_p) | |
4294 | { | |
4295 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
4296 | s->y + dy, s->width, 1); | |
4297 | } | |
4298 | else | |
4299 | { | |
4300 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4301 | s->y + dy, s->width, 1); | |
4302 | } | |
4303 | } | |
4304 | ||
4305 | /* Draw overline. */ | |
4306 | if (s->face->overline_p) | |
4307 | { | |
4308 | unsigned long dy = 0, h = 1; | |
4309 | ||
4310 | if (s->face->overline_color_defaulted_p) | |
4311 | { | |
4312 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, | |
4313 | s->y + dy, s->width, h); | |
4314 | } | |
4315 | else | |
4316 | { | |
4317 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4318 | s->y + dy, s->width, h); | |
4319 | } | |
4320 | } | |
4321 | ||
4322 | /* Draw strike-through. */ | |
9ef2e2cf JR |
4323 | if (s->face->strike_through_p |
4324 | && (s->font->bdf || !s->font->tm.tmStruckOut)) | |
791f420f JR |
4325 | { |
4326 | unsigned long h = 1; | |
4327 | unsigned long dy = (s->height - h) / 2; | |
4328 | ||
4329 | if (s->face->strike_through_color_defaulted_p) | |
4330 | { | |
4331 | w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, s->y + dy, | |
4332 | s->width, h); | |
4333 | } | |
4334 | else | |
4335 | { | |
4336 | w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x, | |
4337 | s->y + dy, s->width, h); | |
4338 | } | |
4339 | } | |
4340 | ||
4341 | /* Draw relief. */ | |
4342 | if (s->face->box != FACE_NO_BOX) | |
4343 | x_draw_glyph_string_box (s); | |
4344 | } | |
4345 | ||
4346 | /* Reset clipping. */ | |
4347 | w32_set_clip_rectangle (s->hdc, NULL); | |
4348 | } | |
4349 | ||
4350 | ||
4351 | static int x_fill_composite_glyph_string P_ ((struct glyph_string *, | |
4352 | struct face **, int)); | |
4353 | ||
4354 | ||
4355 | /* Load glyph string S with a composition components specified by S->cmp. | |
4356 | FACES is an array of faces for all components of this composition. | |
4357 | S->gidx is the index of the first component for S. | |
4358 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
4359 | use its lines physical height for clipping. | |
4360 | ||
4361 | Value is the index of a component not in S. */ | |
4362 | ||
4363 | static int | |
4364 | x_fill_composite_glyph_string (s, faces, overlaps_p) | |
4365 | struct glyph_string *s; | |
4366 | struct face **faces; | |
4367 | int overlaps_p; | |
4368 | { | |
4369 | int i; | |
4370 | ||
4371 | xassert (s); | |
4372 | ||
4373 | s->for_overlaps_p = overlaps_p; | |
4374 | ||
4375 | s->face = faces[s->gidx]; | |
4376 | s->font = s->face->font; | |
4377 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4378 | ||
4379 | /* For all glyphs of this composition, starting at the offset | |
4380 | S->gidx, until we reach the end of the definition or encounter a | |
4381 | glyph that requires the different face, add it to S. */ | |
4382 | ++s->nchars; | |
4383 | for (i = s->gidx + 1; i < s->cmp->glyph_len && faces[i] == s->face; ++i) | |
4384 | ++s->nchars; | |
4385 | ||
4386 | /* All glyph strings for the same composition has the same width, | |
4387 | i.e. the width set for the first component of the composition. */ | |
4388 | ||
4389 | s->width = s->first_glyph->pixel_width; | |
4390 | ||
4391 | /* If the specified font could not be loaded, use the frame's | |
4392 | default font, but record the fact that we couldn't load it in | |
4393 | the glyph string so that we can draw rectangles for the | |
4394 | characters of the glyph string. */ | |
4395 | if (s->font == NULL) | |
4396 | { | |
4397 | s->font_not_found_p = 1; | |
4398 | s->font = FRAME_FONT (s->f); | |
4399 | } | |
4400 | ||
4401 | /* Adjust base line for subscript/superscript text. */ | |
4402 | s->ybase += s->first_glyph->voffset; | |
4403 | ||
4404 | xassert (s->face && s->face->gc); | |
4405 | ||
4406 | /* This glyph string must always be drawn with 16-bit functions. */ | |
4407 | s->two_byte_p = 1; | |
4408 | ||
4409 | return s->gidx + s->nchars; | |
4410 | } | |
4411 | ||
4412 | ||
4413 | /* Load glyph string S with a sequence of characters. | |
4414 | FACE_ID is the face id of the string. START is the index of the | |
4415 | first glyph to consider, END is the index of the last + 1. | |
4416 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
4417 | use its lines physical height for clipping. | |
4418 | ||
4419 | Value is the index of the first glyph not in S. */ | |
4420 | ||
4421 | static int | |
4422 | x_fill_glyph_string (s, face_id, start, end, overlaps_p) | |
4423 | struct glyph_string *s; | |
4424 | int face_id; | |
4425 | int start, end, overlaps_p; | |
4426 | { | |
4427 | struct glyph *glyph, *last; | |
4428 | int voffset; | |
93ff4395 | 4429 | int glyph_not_available_p; |
791f420f JR |
4430 | |
4431 | xassert (s->f == XFRAME (s->w->frame)); | |
4432 | xassert (s->nchars == 0); | |
4433 | xassert (start >= 0 && end > start); | |
4434 | ||
4435 | s->for_overlaps_p = overlaps_p; | |
791f420f JR |
4436 | glyph = s->row->glyphs[s->area] + start; |
4437 | last = s->row->glyphs[s->area] + end; | |
4438 | voffset = glyph->voffset; | |
93ff4395 JR |
4439 | |
4440 | glyph_not_available_p = glyph->glyph_not_available_p; | |
4441 | ||
791f420f JR |
4442 | while (glyph < last |
4443 | && glyph->type == CHAR_GLYPH | |
4444 | && glyph->voffset == voffset | |
93ff4395 JR |
4445 | /* Same face id implies same font, nowadays. */ |
4446 | && glyph->face_id == face_id | |
4447 | && glyph->glyph_not_available_p == glyph_not_available_p) | |
791f420f | 4448 | { |
93ff4395 JR |
4449 | int two_byte_p; |
4450 | ||
791f420f | 4451 | s->face = x_get_glyph_face_and_encoding (s->f, glyph, |
93ff4395 JR |
4452 | s->char2b + s->nchars, |
4453 | &two_byte_p); | |
4454 | s->two_byte_p = two_byte_p; | |
791f420f JR |
4455 | ++s->nchars; |
4456 | xassert (s->nchars <= end - start); | |
4457 | s->width += glyph->pixel_width; | |
4458 | ++glyph; | |
4459 | } | |
4460 | ||
4461 | s->font = s->face->font; | |
4462 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4463 | ||
4464 | /* If the specified font could not be loaded, use the frame's font, | |
4465 | but record the fact that we couldn't load it in | |
4466 | S->font_not_found_p so that we can draw rectangles for the | |
4467 | characters of the glyph string. */ | |
93ff4395 | 4468 | if (s->font == NULL || glyph_not_available_p) |
791f420f JR |
4469 | { |
4470 | s->font_not_found_p = 1; | |
4471 | s->font = FRAME_FONT (s->f); | |
4472 | } | |
4473 | ||
4474 | /* Adjust base line for subscript/superscript text. */ | |
4475 | s->ybase += voffset; | |
4476 | ||
4477 | xassert (s->face && s->face->gc); | |
4478 | return glyph - s->row->glyphs[s->area]; | |
4479 | } | |
4480 | ||
4481 | ||
4482 | /* Fill glyph string S from image glyph S->first_glyph. */ | |
4483 | ||
4484 | static void | |
4485 | x_fill_image_glyph_string (s) | |
4486 | struct glyph_string *s; | |
4487 | { | |
4488 | xassert (s->first_glyph->type == IMAGE_GLYPH); | |
4489 | s->img = IMAGE_FROM_ID (s->f, s->first_glyph->u.img_id); | |
4490 | xassert (s->img); | |
4491 | s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id); | |
4492 | s->font = s->face->font; | |
4493 | s->width = s->first_glyph->pixel_width; | |
4494 | ||
4495 | /* Adjust base line for subscript/superscript text. */ | |
4496 | s->ybase += s->first_glyph->voffset; | |
4497 | } | |
4498 | ||
4499 | ||
ec48c3a7 | 4500 | /* Fill glyph string S from a sequence of stretch glyphs. |
791f420f | 4501 | |
ec48c3a7 JR |
4502 | ROW is the glyph row in which the glyphs are found, AREA is the |
4503 | area within the row. START is the index of the first glyph to | |
4504 | consider, END is the index of the last + 1. | |
4505 | ||
4506 | Value is the index of the first glyph not in S. */ | |
4507 | ||
4508 | static int | |
4509 | x_fill_stretch_glyph_string (s, row, area, start, end) | |
791f420f | 4510 | struct glyph_string *s; |
ec48c3a7 JR |
4511 | struct glyph_row *row; |
4512 | enum glyph_row_area area; | |
4513 | int start, end; | |
791f420f | 4514 | { |
ec48c3a7 JR |
4515 | struct glyph *glyph, *last; |
4516 | int voffset, face_id; | |
4517 | ||
791f420f | 4518 | xassert (s->first_glyph->type == STRETCH_GLYPH); |
ec48c3a7 JR |
4519 | |
4520 | glyph = s->row->glyphs[s->area] + start; | |
4521 | last = s->row->glyphs[s->area] + end; | |
4522 | face_id = glyph->face_id; | |
4523 | s->face = FACE_FROM_ID (s->f, face_id); | |
791f420f | 4524 | s->font = s->face->font; |
ec48c3a7 JR |
4525 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); |
4526 | s->width = glyph->pixel_width; | |
4527 | voffset = glyph->voffset; | |
4528 | ||
4529 | for (++glyph; | |
4530 | (glyph < last | |
4531 | && glyph->type == STRETCH_GLYPH | |
4532 | && glyph->voffset == voffset | |
4533 | && glyph->face_id == face_id); | |
4534 | ++glyph) | |
4535 | s->width += glyph->pixel_width; | |
791f420f JR |
4536 | |
4537 | /* Adjust base line for subscript/superscript text. */ | |
ec48c3a7 JR |
4538 | s->ybase += voffset; |
4539 | ||
4540 | xassert (s->face && s->face->gc); | |
4541 | return glyph - s->row->glyphs[s->area]; | |
791f420f JR |
4542 | } |
4543 | ||
4544 | ||
4545 | /* Initialize glyph string S. CHAR2B is a suitably allocated vector | |
4546 | of XChar2b structures for S; it can't be allocated in | |
4547 | x_init_glyph_string because it must be allocated via `alloca'. W | |
4548 | is the window on which S is drawn. ROW and AREA are the glyph row | |
4549 | and area within the row from which S is constructed. START is the | |
4550 | index of the first glyph structure covered by S. HL is a | |
4551 | face-override for drawing S. */ | |
4552 | ||
4553 | static void | |
4554 | w32_init_glyph_string (s, hdc, char2b, w, row, area, start, hl) | |
4555 | struct glyph_string *s; | |
4556 | HDC hdc; | |
4557 | wchar_t *char2b; | |
4558 | struct window *w; | |
4559 | struct glyph_row *row; | |
4560 | enum glyph_row_area area; | |
4561 | int start; | |
4562 | enum draw_glyphs_face hl; | |
4563 | { | |
4564 | bzero (s, sizeof *s); | |
4565 | s->w = w; | |
4566 | s->f = XFRAME (w->frame); | |
4567 | s->hdc = hdc; | |
4568 | s->window = FRAME_W32_WINDOW (s->f); | |
4569 | s->char2b = char2b; | |
4570 | s->hl = hl; | |
4571 | s->row = row; | |
4572 | s->area = area; | |
4573 | s->first_glyph = row->glyphs[area] + start; | |
4574 | s->height = row->height; | |
4575 | s->y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
4576 | ||
4577 | /* Display the internal border below the tool-bar window. */ | |
4578 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
4579 | s->y -= s->f->output_data.w32->internal_border_width; | |
4580 | ||
4581 | s->ybase = s->y + row->ascent; | |
4582 | } | |
4583 | ||
4584 | ||
4585 | /* Set background width of glyph string S. START is the index of the | |
4586 | first glyph following S. LAST_X is the right-most x-position + 1 | |
4587 | in the drawing area. */ | |
4588 | ||
4589 | static INLINE void | |
4590 | x_set_glyph_string_background_width (s, start, last_x) | |
4591 | struct glyph_string *s; | |
4592 | int start; | |
4593 | int last_x; | |
4594 | { | |
4595 | /* If the face of this glyph string has to be drawn to the end of | |
4596 | the drawing area, set S->extends_to_end_of_line_p. */ | |
4597 | struct face *default_face = FACE_FROM_ID (s->f, DEFAULT_FACE_ID); | |
4598 | ||
4599 | if (start == s->row->used[s->area] | |
4600 | && s->hl == DRAW_NORMAL_TEXT | |
4601 | && ((s->area == TEXT_AREA && s->row->fill_line_p) | |
4602 | || s->face->background != default_face->background | |
4603 | || s->face->stipple != default_face->stipple)) | |
4604 | s->extends_to_end_of_line_p = 1; | |
4605 | ||
4606 | /* If S extends its face to the end of the line, set its | |
4607 | background_width to the distance to the right edge of the drawing | |
4608 | area. */ | |
4609 | if (s->extends_to_end_of_line_p) | |
4610 | s->background_width = last_x - s->x + 1; | |
4611 | else | |
4612 | s->background_width = s->width; | |
4613 | } | |
4614 | ||
4615 | ||
4616 | /* Add a glyph string for a stretch glyph to the list of strings | |
4617 | between HEAD and TAIL. START is the index of the stretch glyph in | |
4618 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4619 | in that glyph row area. X is the current output position assigned | |
4620 | to the new glyph string constructed. HL overrides that face of the | |
4621 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4622 | is the right-most x-position of the drawing area. */ | |
4623 | ||
4624 | #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
4625 | do \ | |
4626 | { \ | |
4627 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4628 | w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \ | |
ec48c3a7 | 4629 | START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \ |
791f420f | 4630 | x_append_glyph_string (&HEAD, &TAIL, s); \ |
791f420f JR |
4631 | s->x = (X); \ |
4632 | } \ | |
4633 | while (0) | |
4634 | ||
4635 | ||
4636 | /* Add a glyph string for an image glyph to the list of strings | |
4637 | between HEAD and TAIL. START is the index of the image glyph in | |
4638 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4639 | in that glyph row area. X is the current output position assigned | |
4640 | to the new glyph string constructed. HL overrides that face of the | |
4641 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4642 | is the right-most x-position of the drawing area. */ | |
4643 | ||
4644 | #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
4645 | do \ | |
4646 | { \ | |
4647 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4648 | w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \ | |
4649 | x_fill_image_glyph_string (s); \ | |
4650 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
4651 | ++START; \ | |
4652 | s->x = (X); \ | |
4653 | } \ | |
4654 | while (0) | |
4655 | ||
4656 | ||
4657 | /* Add a glyph string for a sequence of character glyphs to the list | |
4658 | of strings between HEAD and TAIL. START is the index of the first | |
4659 | glyph in row area AREA of glyph row ROW that is part of the new | |
4660 | glyph string. END is the index of the last glyph in that glyph row | |
4661 | area. X is the current output position assigned to the new glyph | |
4662 | string constructed. HL overrides that face of the glyph; e.g. it | |
4663 | is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the | |
4664 | right-most x-position of the drawing area. */ | |
4665 | ||
4666 | #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4667 | do \ | |
4668 | { \ | |
ec48c3a7 | 4669 | int c, face_id; \ |
791f420f JR |
4670 | wchar_t *char2b; \ |
4671 | \ | |
4672 | c = (ROW)->glyphs[AREA][START].u.ch; \ | |
791f420f | 4673 | face_id = (ROW)->glyphs[AREA][START].face_id; \ |
9ef2e2cf | 4674 | \ |
791f420f JR |
4675 | s = (struct glyph_string *) alloca (sizeof *s); \ |
4676 | char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \ | |
4677 | w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \ | |
4678 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
791f420f JR |
4679 | s->x = (X); \ |
4680 | START = x_fill_glyph_string (s, face_id, START, END, \ | |
4681 | OVERLAPS_P); \ | |
4682 | } \ | |
4683 | while (0) | |
4684 | ||
4685 | ||
4686 | /* Add a glyph string for a composite sequence to the list of strings | |
4687 | between HEAD and TAIL. START is the index of the first glyph in | |
4688 | row area AREA of glyph row ROW that is part of the new glyph | |
4689 | string. END is the index of the last glyph in that glyph row area. | |
4690 | X is the current output position assigned to the new glyph string | |
4691 | constructed. HL overrides that face of the glyph; e.g. it is | |
4692 | DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most | |
4693 | x-position of the drawing area. */ | |
4694 | ||
4695 | #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4696 | do { \ | |
4697 | int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \ | |
4698 | int face_id = (ROW)->glyphs[AREA][START].face_id; \ | |
93ff4395 | 4699 | struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \ |
791f420f JR |
4700 | struct composition *cmp = composition_table[cmp_id]; \ |
4701 | int glyph_len = cmp->glyph_len; \ | |
4702 | wchar_t *char2b; \ | |
4703 | struct face **faces; \ | |
4704 | struct glyph_string *first_s = NULL; \ | |
4705 | int n; \ | |
4706 | \ | |
93ff4395 | 4707 | base_face = base_face->ascii_face; \ |
791f420f JR |
4708 | char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \ |
4709 | faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \ | |
4710 | /* At first, fill in `char2b' and `faces'. */ \ | |
4711 | for (n = 0; n < glyph_len; n++) \ | |
4712 | { \ | |
4713 | int c = COMPOSITION_GLYPH (cmp, n); \ | |
93ff4395 JR |
4714 | int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \ |
4715 | faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \ | |
4716 | x_get_char_face_and_encoding (XFRAME (w->frame), c, \ | |
4717 | this_face_id, char2b + n, 1); \ | |
791f420f JR |
4718 | } \ |
4719 | \ | |
4720 | /* Make glyph_strings for each glyph sequence that is drawable by \ | |
4721 | the same face, and append them to HEAD/TAIL. */ \ | |
4722 | for (n = 0; n < cmp->glyph_len;) \ | |
4723 | { \ | |
4724 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4725 | w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \ | |
4726 | x_append_glyph_string (&(HEAD), &(TAIL), s); \ | |
4727 | s->cmp = cmp; \ | |
4728 | s->gidx = n; \ | |
791f420f JR |
4729 | s->x = (X); \ |
4730 | \ | |
4731 | if (n == 0) \ | |
4732 | first_s = s; \ | |
4733 | \ | |
4734 | n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \ | |
4735 | } \ | |
4736 | \ | |
4737 | ++START; \ | |
4738 | s = first_s; \ | |
4739 | } while (0) | |
4740 | ||
9ef2e2cf | 4741 | |
791f420f JR |
4742 | /* Build a list of glyph strings between HEAD and TAIL for the glyphs |
4743 | of AREA of glyph row ROW on window W between indices START and END. | |
4744 | HL overrides the face for drawing glyph strings, e.g. it is | |
4745 | DRAW_CURSOR to draw a cursor. X and LAST_X are start and end | |
4746 | x-positions of the drawing area. | |
4747 | ||
4748 | This is an ugly monster macro construct because we must use alloca | |
4749 | to allocate glyph strings (because x_draw_glyphs can be called | |
4750 | asynchronously). */ | |
4751 | ||
4752 | #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ | |
4753 | do \ | |
4754 | { \ | |
4755 | HEAD = TAIL = NULL; \ | |
4756 | while (START < END) \ | |
4757 | { \ | |
4758 | struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \ | |
4759 | switch (first_glyph->type) \ | |
4760 | { \ | |
4761 | case CHAR_GLYPH: \ | |
4762 | BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \ | |
4763 | HEAD, TAIL, HL, X, LAST_X, \ | |
4764 | OVERLAPS_P); \ | |
4765 | break; \ | |
4766 | \ | |
4767 | case COMPOSITE_GLYPH: \ | |
4768 | BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \ | |
4769 | END, HEAD, TAIL, HL, X, \ | |
4770 | LAST_X, OVERLAPS_P); \ | |
4771 | break; \ | |
4772 | \ | |
4773 | case STRETCH_GLYPH: \ | |
4774 | BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\ | |
4775 | HEAD, TAIL, HL, X, LAST_X); \ | |
4776 | break; \ | |
4777 | \ | |
4778 | case IMAGE_GLYPH: \ | |
4779 | BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \ | |
4780 | HEAD, TAIL, HL, X, LAST_X); \ | |
4781 | break; \ | |
4782 | \ | |
4783 | default: \ | |
4784 | abort (); \ | |
4785 | } \ | |
4786 | \ | |
4787 | x_set_glyph_string_background_width (s, START, LAST_X); \ | |
4788 | (X) += s->width; \ | |
4789 | } \ | |
4790 | } \ | |
4791 | while (0) | |
4792 | ||
4793 | ||
4794 | /* Draw glyphs between START and END in AREA of ROW on window W, | |
4795 | starting at x-position X. X is relative to AREA in W. HL is a | |
4796 | face-override with the following meaning: | |
4797 | ||
4798 | DRAW_NORMAL_TEXT draw normally | |
4799 | DRAW_CURSOR draw in cursor face | |
4800 | DRAW_MOUSE_FACE draw in mouse face. | |
4801 | DRAW_INVERSE_VIDEO draw in mode line face | |
4802 | DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it | |
4803 | DRAW_IMAGE_RAISED draw an image with a raised relief around it | |
4804 | ||
4805 | If REAL_START is non-null, return in *REAL_START the real starting | |
4806 | position for display. This can be different from START in case | |
4807 | overlapping glyphs must be displayed. If REAL_END is non-null, | |
4808 | return in *REAL_END the real end position for display. This can be | |
4809 | different from END in case overlapping glyphs must be displayed. | |
4810 | ||
4811 | If OVERLAPS_P is non-zero, draw only the foreground of characters | |
4812 | and clip to the physical height of ROW. | |
4813 | ||
4814 | Value is the x-position reached, relative to AREA of W. */ | |
4815 | ||
4816 | static int | |
4817 | x_draw_glyphs (w, x, row, area, start, end, hl, real_start, real_end, | |
4818 | overlaps_p) | |
4819 | struct window *w; | |
4820 | int x; | |
4821 | struct glyph_row *row; | |
4822 | enum glyph_row_area area; | |
4823 | int start, end; | |
4824 | enum draw_glyphs_face hl; | |
4825 | int *real_start, *real_end; | |
4826 | int overlaps_p; | |
4827 | { | |
4828 | struct glyph_string *head, *tail; | |
4829 | struct glyph_string *s; | |
4830 | int last_x, area_width; | |
4831 | int x_reached; | |
4832 | int i, j; | |
4833 | HDC hdc = get_frame_dc (XFRAME (WINDOW_FRAME (w))); | |
4834 | ||
4835 | /* Let's rather be paranoid than getting a SEGV. */ | |
791f420f | 4836 | end = min (end, row->used[area]); |
9127e20e JR |
4837 | start = max (0, start); |
4838 | start = min (end, start); | |
4839 | ||
791f420f JR |
4840 | if (real_start) |
4841 | *real_start = start; | |
4842 | if (real_end) | |
4843 | *real_end = end; | |
4844 | ||
4845 | /* Translate X to frame coordinates. Set last_x to the right | |
4846 | end of the drawing area. */ | |
4847 | if (row->full_width_p) | |
4848 | { | |
791f420f JR |
4849 | /* X is relative to the left edge of W, without scroll bars |
4850 | or flag areas. */ | |
ec48c3a7 | 4851 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
791f420f JR |
4852 | /* int width = FRAME_FLAGS_AREA_WIDTH (f); */ |
4853 | int window_left_x = WINDOW_LEFT_MARGIN (w) * CANON_X_UNIT (f); | |
ee78dc32 | 4854 | |
791f420f JR |
4855 | x += window_left_x; |
4856 | area_width = XFASTINT (w->width) * CANON_X_UNIT (f); | |
4857 | last_x = window_left_x + area_width; | |
ee78dc32 | 4858 | |
791f420f JR |
4859 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
4860 | { | |
4861 | int width = FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
4862 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
4863 | last_x += width; | |
4864 | else | |
4865 | x -= width; | |
4866 | } | |
ee78dc32 | 4867 | |
791f420f JR |
4868 | x += FRAME_INTERNAL_BORDER_WIDTH (f); |
4869 | last_x -= FRAME_INTERNAL_BORDER_WIDTH (f); | |
4870 | } | |
4871 | else | |
4872 | { | |
4873 | x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, x); | |
4874 | area_width = window_box_width (w, area); | |
4875 | last_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, area_width); | |
4876 | } | |
e12ca9c2 | 4877 | |
791f420f JR |
4878 | /* Build a doubly-linked list of glyph_string structures between |
4879 | head and tail from what we have to draw. Note that the macro | |
4880 | BUILD_GLYPH_STRINGS will modify its start parameter. That's | |
4881 | the reason we use a separate variable `i'. */ | |
4882 | i = start; | |
4883 | BUILD_GLYPH_STRINGS (hdc, w, row, area, i, end, head, tail, hl, x, last_x, | |
4884 | overlaps_p); | |
791f420f JR |
4885 | if (tail) |
4886 | x_reached = tail->x + tail->background_width; | |
4887 | else | |
4888 | x_reached = x; | |
e12ca9c2 | 4889 | |
791f420f JR |
4890 | /* If there are any glyphs with lbearing < 0 or rbearing > width in |
4891 | the row, redraw some glyphs in front or following the glyph | |
4892 | strings built above. */ | |
9127e20e | 4893 | if (head && !overlaps_p && row->contains_overlapping_glyphs_p) |
791f420f JR |
4894 | { |
4895 | int dummy_x = 0; | |
4896 | struct glyph_string *h, *t; | |
4897 | ||
4898 | /* Compute overhangs for all glyph strings. */ | |
4899 | for (s = head; s; s = s->next) | |
4900 | x_compute_glyph_string_overhangs (s); | |
4901 | ||
4902 | /* Prepend glyph strings for glyphs in front of the first glyph | |
4903 | string that are overwritten because of the first glyph | |
4904 | string's left overhang. The background of all strings | |
4905 | prepended must be drawn because the first glyph string | |
4906 | draws over it. */ | |
4907 | i = x_left_overwritten (head); | |
4908 | if (i >= 0) | |
4909 | { | |
4910 | j = i; | |
4911 | BUILD_GLYPH_STRINGS (hdc, w, row, area, j, start, h, t, | |
4912 | DRAW_NORMAL_TEXT, dummy_x, last_x, | |
4913 | overlaps_p); | |
4914 | start = i; | |
4915 | if (real_start) | |
4916 | *real_start = start; | |
4917 | x_compute_overhangs_and_x (t, head->x, 1); | |
4918 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4919 | } | |
ee78dc32 | 4920 | |
791f420f JR |
4921 | /* Prepend glyph strings for glyphs in front of the first glyph |
4922 | string that overwrite that glyph string because of their | |
4923 | right overhang. For these strings, only the foreground must | |
4924 | be drawn, because it draws over the glyph string at `head'. | |
4925 | The background must not be drawn because this would overwrite | |
4926 | right overhangs of preceding glyphs for which no glyph | |
4927 | strings exist. */ | |
4928 | i = x_left_overwriting (head); | |
4929 | if (i >= 0) | |
4930 | { | |
4931 | BUILD_GLYPH_STRINGS (hdc, w, row, area, i, start, h, t, | |
4932 | DRAW_NORMAL_TEXT, dummy_x, last_x, | |
4933 | overlaps_p); | |
791f420f JR |
4934 | for (s = h; s; s = s->next) |
4935 | s->background_filled_p = 1; | |
4936 | if (real_start) | |
4937 | *real_start = i; | |
4938 | x_compute_overhangs_and_x (t, head->x, 1); | |
4939 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4940 | } | |
cabb23bc | 4941 | |
791f420f JR |
4942 | /* Append glyphs strings for glyphs following the last glyph |
4943 | string tail that are overwritten by tail. The background of | |
4944 | these strings has to be drawn because tail's foreground draws | |
4945 | over it. */ | |
4946 | i = x_right_overwritten (tail); | |
4947 | if (i >= 0) | |
4948 | { | |
4949 | BUILD_GLYPH_STRINGS (hdc, w, row, area, end, i, h, t, | |
4950 | DRAW_NORMAL_TEXT, x, last_x, | |
4951 | overlaps_p); | |
791f420f JR |
4952 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); |
4953 | x_append_glyph_string_lists (&head, &tail, h, t); | |
4954 | if (real_end) | |
4955 | *real_end = i; | |
4956 | } | |
cabb23bc | 4957 | |
791f420f JR |
4958 | /* Append glyph strings for glyphs following the last glyph |
4959 | string tail that overwrite tail. The foreground of such | |
4960 | glyphs has to be drawn because it writes into the background | |
4961 | of tail. The background must not be drawn because it could | |
4962 | paint over the foreground of following glyphs. */ | |
4963 | i = x_right_overwriting (tail); | |
4964 | if (i >= 0) | |
4965 | { | |
4966 | BUILD_GLYPH_STRINGS (hdc, w, row, area, end, i, h, t, | |
4967 | DRAW_NORMAL_TEXT, x, last_x, | |
4968 | overlaps_p); | |
791f420f JR |
4969 | for (s = h; s; s = s->next) |
4970 | s->background_filled_p = 1; | |
4971 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); | |
4972 | x_append_glyph_string_lists (&head, &tail, h, t); | |
4973 | if (real_end) | |
4974 | *real_end = i; | |
4975 | } | |
4976 | } | |
cabb23bc | 4977 | |
791f420f JR |
4978 | /* Draw all strings. */ |
4979 | for (s = head; s; s = s->next) | |
4980 | x_draw_glyph_string (s); | |
cabb23bc | 4981 | |
791f420f JR |
4982 | /* Value is the x-position up to which drawn, relative to AREA of W. |
4983 | This doesn't include parts drawn because of overhangs. */ | |
4984 | x_reached = FRAME_TO_WINDOW_PIXEL_X (w, x_reached); | |
4985 | if (!row->full_width_p) | |
4986 | { | |
4987 | if (area > LEFT_MARGIN_AREA) | |
4988 | x_reached -= window_box_width (w, LEFT_MARGIN_AREA); | |
4989 | if (area > TEXT_AREA) | |
4990 | x_reached -= window_box_width (w, TEXT_AREA); | |
4991 | } | |
cabb23bc | 4992 | |
791f420f | 4993 | release_frame_dc (XFRAME (WINDOW_FRAME (w)), hdc); |
65c4903c | 4994 | |
791f420f JR |
4995 | return x_reached; |
4996 | } | |
65c4903c | 4997 | |
cabb23bc | 4998 | |
791f420f JR |
4999 | /* Fix the display of area AREA of overlapping row ROW in window W. */ |
5000 | ||
5001 | static void | |
5002 | x_fix_overlapping_area (w, row, area) | |
5003 | struct window *w; | |
5004 | struct glyph_row *row; | |
5005 | enum glyph_row_area area; | |
5006 | { | |
5007 | int i, x; | |
5008 | ||
5009 | BLOCK_INPUT; | |
5010 | ||
5011 | if (area == LEFT_MARGIN_AREA) | |
5012 | x = 0; | |
5013 | else if (area == TEXT_AREA) | |
5014 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5015 | else | |
5016 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5017 | + window_box_width (w, TEXT_AREA)); | |
b1ae662f | 5018 | |
791f420f JR |
5019 | for (i = 0; i < row->used[area];) |
5020 | { | |
5021 | if (row->glyphs[area][i].overlaps_vertically_p) | |
ee78dc32 | 5022 | { |
791f420f | 5023 | int start = i, start_x = x; |
ee78dc32 | 5024 | |
791f420f JR |
5025 | do |
5026 | { | |
5027 | x += row->glyphs[area][i].pixel_width; | |
5028 | ++i; | |
5029 | } | |
5030 | while (i < row->used[area] | |
5031 | && row->glyphs[area][i].overlaps_vertically_p); | |
cabb23bc | 5032 | |
791f420f JR |
5033 | x_draw_glyphs (w, start_x, row, area, start, i, |
5034 | (row->inverse_p | |
5035 | ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT), | |
5036 | NULL, NULL, 1); | |
5037 | } | |
5038 | else | |
5039 | { | |
5040 | x += row->glyphs[area][i].pixel_width; | |
5041 | ++i; | |
5042 | } | |
5043 | } | |
5044 | ||
5045 | UNBLOCK_INPUT; | |
ee78dc32 GV |
5046 | } |
5047 | ||
ee78dc32 | 5048 | |
791f420f JR |
5049 | /* Output LEN glyphs starting at START at the nominal cursor position. |
5050 | Advance the nominal cursor over the text. The global variable | |
5051 | updated_window contains the window being updated, updated_row is | |
5052 | the glyph row being updated, and updated_area is the area of that | |
5053 | row being updated. */ | |
ee78dc32 | 5054 | |
96214669 | 5055 | static void |
791f420f JR |
5056 | x_write_glyphs (start, len) |
5057 | struct glyph *start; | |
ee78dc32 GV |
5058 | int len; |
5059 | { | |
791f420f | 5060 | int x, hpos, real_start, real_end; |
ee78dc32 | 5061 | |
791f420f | 5062 | xassert (updated_window && updated_row); |
ee78dc32 | 5063 | BLOCK_INPUT; |
791f420f JR |
5064 | |
5065 | /* Write glyphs. */ | |
ee78dc32 | 5066 | |
791f420f JR |
5067 | hpos = start - updated_row->glyphs[updated_area]; |
5068 | x = x_draw_glyphs (updated_window, output_cursor.x, | |
5069 | updated_row, updated_area, | |
5070 | hpos, hpos + len, | |
5071 | (updated_row->inverse_p | |
5072 | ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT), | |
5073 | &real_start, &real_end, 0); | |
5074 | ||
5075 | /* If we drew over the cursor, note that it is not visible any more. */ | |
5076 | note_overwritten_text_cursor (updated_window, real_start, | |
5077 | real_end - real_start); | |
5078 | ||
5079 | UNBLOCK_INPUT; | |
5080 | ||
5081 | /* Advance the output cursor. */ | |
5082 | output_cursor.hpos += len; | |
5083 | output_cursor.x = x; | |
5084 | } | |
ee78dc32 | 5085 | |
ee78dc32 | 5086 | |
791f420f | 5087 | /* Insert LEN glyphs from START at the nominal cursor position. */ |
ee78dc32 | 5088 | |
791f420f JR |
5089 | static void |
5090 | x_insert_glyphs (start, len) | |
5091 | struct glyph *start; | |
5092 | register int len; | |
5093 | { | |
5094 | struct frame *f; | |
5095 | struct window *w; | |
5096 | int line_height, shift_by_width, shifted_region_width; | |
5097 | struct glyph_row *row; | |
5098 | struct glyph *glyph; | |
5099 | int frame_x, frame_y, hpos, real_start, real_end; | |
5100 | HDC hdc; | |
5101 | ||
5102 | xassert (updated_window && updated_row); | |
5103 | BLOCK_INPUT; | |
5104 | w = updated_window; | |
5105 | f = XFRAME (WINDOW_FRAME (w)); | |
5106 | hdc = get_frame_dc (f); | |
5107 | ||
5108 | /* Get the height of the line we are in. */ | |
5109 | row = updated_row; | |
5110 | line_height = row->height; | |
5111 | ||
5112 | /* Get the width of the glyphs to insert. */ | |
5113 | shift_by_width = 0; | |
5114 | for (glyph = start; glyph < start + len; ++glyph) | |
5115 | shift_by_width += glyph->pixel_width; | |
5116 | ||
5117 | /* Get the width of the region to shift right. */ | |
5118 | shifted_region_width = (window_box_width (w, updated_area) | |
5119 | - output_cursor.x | |
5120 | - shift_by_width); | |
5121 | ||
5122 | /* Shift right. */ | |
5123 | frame_x = WINDOW_TO_FRAME_PIXEL_X (w, output_cursor.x); | |
5124 | frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); | |
5125 | BitBlt (hdc, frame_x + shift_by_width, frame_y, | |
5126 | shifted_region_width, line_height, | |
5127 | hdc, frame_x, frame_y, SRCCOPY); | |
5128 | ||
5129 | /* Write the glyphs. */ | |
5130 | hpos = start - row->glyphs[updated_area]; | |
5131 | x_draw_glyphs (w, output_cursor.x, row, updated_area, hpos, hpos + len, | |
5132 | DRAW_NORMAL_TEXT, &real_start, &real_end, 0); | |
5133 | note_overwritten_text_cursor (w, real_start, real_end - real_start); | |
5134 | ||
5135 | /* Advance the output cursor. */ | |
5136 | output_cursor.hpos += len; | |
5137 | output_cursor.x += shift_by_width; | |
5138 | release_frame_dc (f, hdc); | |
ee78dc32 GV |
5139 | |
5140 | UNBLOCK_INPUT; | |
5141 | } | |
791f420f JR |
5142 | |
5143 | ||
5144 | /* Delete N glyphs at the nominal cursor position. Not implemented | |
5145 | for X frames. */ | |
ee78dc32 | 5146 | |
96214669 | 5147 | static void |
791f420f JR |
5148 | x_delete_glyphs (n) |
5149 | register int n; | |
ee78dc32 | 5150 | { |
791f420f JR |
5151 | abort (); |
5152 | } | |
ee78dc32 | 5153 | |
ee78dc32 | 5154 | |
791f420f JR |
5155 | /* Erase the current text line from the nominal cursor position |
5156 | (inclusive) to pixel column TO_X (exclusive). The idea is that | |
5157 | everything from TO_X onward is already erased. | |
ee78dc32 | 5158 | |
791f420f JR |
5159 | TO_X is a pixel position relative to updated_area of |
5160 | updated_window. TO_X == -1 means clear to the end of this area. */ | |
11606873 | 5161 | |
791f420f JR |
5162 | static void |
5163 | x_clear_end_of_line (to_x) | |
5164 | int to_x; | |
5165 | { | |
5166 | struct frame *f; | |
5167 | struct window *w = updated_window; | |
5168 | int max_x, min_y, max_y; | |
5169 | int from_x, from_y, to_y; | |
5170 | ||
5171 | xassert (updated_window && updated_row); | |
5172 | f = XFRAME (w->frame); | |
5173 | ||
5174 | if (updated_row->full_width_p) | |
5175 | { | |
5176 | max_x = XFASTINT (w->width) * CANON_X_UNIT (f); | |
5177 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f) | |
5178 | && !w->pseudo_window_p) | |
5179 | max_x += FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
5180 | } | |
5181 | else | |
5182 | max_x = window_box_width (w, updated_area); | |
5183 | max_y = window_text_bottom_y (w); | |
ee78dc32 | 5184 | |
791f420f JR |
5185 | /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end |
5186 | of window. For TO_X > 0, truncate to end of drawing area. */ | |
5187 | if (to_x == 0) | |
5188 | return; | |
5189 | else if (to_x < 0) | |
5190 | to_x = max_x; | |
5191 | else | |
5192 | to_x = min (to_x, max_x); | |
ee78dc32 | 5193 | |
791f420f JR |
5194 | to_y = min (max_y, output_cursor.y + updated_row->height); |
5195 | ||
ee78dc32 | 5196 | /* Notice if the cursor will be cleared by this operation. */ |
791f420f JR |
5197 | if (!updated_row->full_width_p) |
5198 | note_overwritten_text_cursor (w, output_cursor.hpos, -1); | |
ee78dc32 | 5199 | |
791f420f JR |
5200 | from_x = output_cursor.x; |
5201 | ||
5202 | /* Translate to frame coordinates. */ | |
5203 | if (updated_row->full_width_p) | |
5204 | { | |
5205 | from_x = WINDOW_TO_FRAME_PIXEL_X (w, from_x); | |
5206 | to_x = WINDOW_TO_FRAME_PIXEL_X (w, to_x); | |
5207 | } | |
5208 | else | |
5209 | { | |
5210 | from_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, from_x); | |
5211 | to_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, to_x); | |
5212 | } | |
5213 | ||
5214 | min_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
5215 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, max (min_y, output_cursor.y)); | |
5216 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, to_y); | |
5217 | ||
5218 | /* Prevent inadvertently clearing to end of the X window. */ | |
5219 | if (to_x > from_x && to_y > from_y) | |
5220 | { | |
00fe468b | 5221 | HDC hdc; |
791f420f | 5222 | BLOCK_INPUT; |
00fe468b JR |
5223 | hdc = get_frame_dc (f); |
5224 | ||
5225 | w32_clear_area (f, hdc, from_x, from_y, to_x - from_x, to_y - from_y); | |
5226 | release_frame_dc (f, hdc); | |
791f420f JR |
5227 | UNBLOCK_INPUT; |
5228 | } | |
ee78dc32 GV |
5229 | } |
5230 | ||
791f420f JR |
5231 | |
5232 | /* Clear entire frame. If updating_frame is non-null, clear that | |
5233 | frame. Otherwise clear the selected frame. */ | |
5234 | ||
96214669 | 5235 | static void |
791f420f | 5236 | x_clear_frame () |
ee78dc32 | 5237 | { |
791f420f | 5238 | struct frame *f; |
ee78dc32 | 5239 | |
791f420f JR |
5240 | if (updating_frame) |
5241 | f = updating_frame; | |
5242 | else | |
5243 | f = SELECTED_FRAME (); | |
ee78dc32 | 5244 | |
791f420f JR |
5245 | /* Clearing the frame will erase any cursor, so mark them all as no |
5246 | longer visible. */ | |
5247 | mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
5248 | output_cursor.hpos = output_cursor.vpos = 0; | |
5249 | output_cursor.x = -1; | |
ee78dc32 | 5250 | |
791f420f JR |
5251 | /* We don't set the output cursor here because there will always |
5252 | follow an explicit cursor_to. */ | |
ee78dc32 GV |
5253 | BLOCK_INPUT; |
5254 | ||
fbd6baed | 5255 | w32_clear_window (f); |
ee78dc32 GV |
5256 | |
5257 | /* We have to clear the scroll bars, too. If we have changed | |
5258 | colors or something like that, then they should be notified. */ | |
5259 | x_scroll_bar_clear (f); | |
5260 | ||
5261 | UNBLOCK_INPUT; | |
5262 | } | |
791f420f | 5263 | |
ee78dc32 GV |
5264 | \f |
5265 | /* Make audible bell. */ | |
5266 | ||
96214669 GV |
5267 | static void |
5268 | w32_ring_bell (void) | |
ee78dc32 GV |
5269 | { |
5270 | BLOCK_INPUT; | |
5271 | ||
5272 | if (visible_bell) | |
8331e676 GV |
5273 | { |
5274 | int i; | |
791f420f | 5275 | HWND hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); |
8331e676 GV |
5276 | |
5277 | for (i = 0; i < 5; i++) | |
5278 | { | |
5279 | FlashWindow (hwnd, TRUE); | |
5280 | Sleep (10); | |
5281 | } | |
5282 | FlashWindow (hwnd, FALSE); | |
5283 | } | |
ee78dc32 | 5284 | else |
fbd6baed | 5285 | w32_sys_ring_bell (); |
ee78dc32 GV |
5286 | |
5287 | UNBLOCK_INPUT; | |
ee78dc32 | 5288 | } |
791f420f | 5289 | |
ee78dc32 | 5290 | \f |
791f420f JR |
5291 | /* Specify how many text lines, from the top of the window, |
5292 | should be affected by insert-lines and delete-lines operations. | |
5293 | This, and those operations, are used only within an update | |
5294 | that is bounded by calls to x_update_begin and x_update_end. */ | |
ee78dc32 | 5295 | |
96214669 | 5296 | static void |
791f420f JR |
5297 | w32_set_terminal_window (n) |
5298 | register int n; | |
ee78dc32 | 5299 | { |
791f420f | 5300 | /* This function intentionally left blank. */ |
ee78dc32 | 5301 | } |
791f420f JR |
5302 | \f |
5303 | ||
5304 | \f | |
5305 | /*********************************************************************** | |
5306 | Line Dance | |
5307 | ***********************************************************************/ | |
5308 | ||
5309 | /* Perform an insert-lines or delete-lines operation, inserting N | |
5310 | lines or deleting -N lines at vertical position VPOS. */ | |
ee78dc32 | 5311 | |
96214669 | 5312 | static void |
791f420f JR |
5313 | x_ins_del_lines (vpos, n) |
5314 | int vpos, n; | |
ee78dc32 GV |
5315 | { |
5316 | abort (); | |
5317 | } | |
791f420f JR |
5318 | |
5319 | ||
5320 | /* Scroll part of the display as described by RUN. */ | |
5321 | ||
5322 | static void | |
5323 | x_scroll_run (w, run) | |
5324 | struct window *w; | |
5325 | struct run *run; | |
5326 | { | |
5327 | struct frame *f = XFRAME (w->frame); | |
5328 | int x, y, width, height, from_y, to_y, bottom_y; | |
5329 | HDC hdc = get_frame_dc (f); | |
5330 | ||
5331 | /* Get frame-relative bounding box of the text display area of W, | |
5332 | without mode lines. Include in this box the flags areas to the | |
5333 | left and right of W. */ | |
5334 | window_box (w, -1, &x, &y, &width, &height); | |
5335 | width += FRAME_X_FLAGS_AREA_WIDTH (f); | |
5336 | x -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); | |
5337 | ||
5338 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y); | |
5339 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y); | |
5340 | bottom_y = y + height; | |
5341 | ||
5342 | if (to_y < from_y) | |
5343 | { | |
5344 | /* Scrolling up. Make sure we don't copy part of the mode | |
5345 | line at the bottom. */ | |
5346 | if (from_y + run->height > bottom_y) | |
5347 | height = bottom_y - from_y; | |
5348 | else | |
5349 | height = run->height; | |
5350 | } | |
5351 | else | |
5352 | { | |
5353 | /* Scolling down. Make sure we don't copy over the mode line. | |
5354 | at the bottom. */ | |
5355 | if (to_y + run->height > bottom_y) | |
5356 | height = bottom_y - to_y; | |
5357 | else | |
5358 | height = run->height; | |
5359 | } | |
5360 | ||
5361 | BLOCK_INPUT; | |
5362 | ||
5363 | /* Cursor off. Will be switched on again in x_update_window_end. */ | |
5364 | updated_window = w; | |
5365 | x_clear_cursor (w); | |
5366 | ||
5367 | BitBlt (hdc, x, to_y, width, height, hdc, x, from_y, SRCCOPY); | |
5368 | ||
5369 | UNBLOCK_INPUT; | |
5370 | release_frame_dc (f, hdc); | |
5371 | } | |
5372 | ||
9ef2e2cf | 5373 | |
ee78dc32 | 5374 | \f |
791f420f JR |
5375 | /*********************************************************************** |
5376 | Exposure Events | |
5377 | ***********************************************************************/ | |
5378 | ||
5379 | /* Redisplay an exposed area of frame F. X and Y are the upper-left | |
5380 | corner of the exposed rectangle. W and H are width and height of | |
5381 | the exposed area. All are pixel values. W or H zero means redraw | |
5382 | the entire frame. */ | |
ee78dc32 | 5383 | |
96214669 | 5384 | static void |
791f420f JR |
5385 | expose_frame (f, x, y, w, h) |
5386 | struct frame *f; | |
5387 | int x, y, w, h; | |
ee78dc32 | 5388 | { |
791f420f JR |
5389 | RECT r; |
5390 | ||
5391 | TRACE ((stderr, "expose_frame ")); | |
5392 | ||
5393 | /* No need to redraw if frame will be redrawn soon. */ | |
5394 | if (FRAME_GARBAGED_P (f)) | |
5395 | { | |
5396 | TRACE ((stderr, " garbaged\n")); | |
5397 | return; | |
5398 | } | |
5399 | ||
5400 | /* If basic faces haven't been realized yet, there is no point in | |
5401 | trying to redraw anything. This can happen when we get an expose | |
5402 | event while Emacs is starting, e.g. by moving another window. */ | |
5403 | if (FRAME_FACE_CACHE (f) == NULL | |
5404 | || FRAME_FACE_CACHE (f)->used < BASIC_FACE_ID_SENTINEL) | |
5405 | { | |
5406 | TRACE ((stderr, " no faces\n")); | |
5407 | return; | |
5408 | } | |
5409 | ||
5410 | if (w == 0 || h == 0) | |
5411 | { | |
5412 | r.left = r.top = 0; | |
5413 | r.right = CANON_X_UNIT (f) * f->width; | |
5414 | r.bottom = CANON_Y_UNIT (f) * f->height; | |
5415 | } | |
5416 | else | |
5417 | { | |
5418 | r.left = x; | |
5419 | r.top = y; | |
5420 | r.right = x + w; | |
5421 | r.bottom = y + h; | |
5422 | } | |
5423 | ||
5424 | TRACE ((stderr, "(%d, %d, %d, %d)\n", r.left, r.top, r.right, r.bottom)); | |
5425 | expose_window_tree (XWINDOW (f->root_window), &r); | |
5426 | ||
5427 | if (WINDOWP (f->tool_bar_window)) | |
5428 | { | |
5429 | struct window *w = XWINDOW (f->tool_bar_window); | |
5430 | RECT window_rect; | |
5431 | RECT intersection_rect; | |
5432 | int window_x, window_y, window_width, window_height; | |
5433 | ||
5434 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); | |
5435 | window_rect.left = window_x; | |
5436 | window_rect.top = window_y; | |
5437 | window_rect.right = window_x + window_width; | |
5438 | window_rect.bottom = window_y + window_height; | |
5439 | ||
158cba56 | 5440 | if (IntersectRect (&intersection_rect, &r, &window_rect)) |
791f420f JR |
5441 | expose_window (w, &intersection_rect); |
5442 | } | |
5443 | } | |
5444 | ||
5445 | ||
5446 | /* Redraw (parts) of all windows in the window tree rooted at W that | |
5447 | intersect R. R contains frame pixel coordinates. */ | |
5448 | ||
5449 | static void | |
5450 | expose_window_tree (w, r) | |
5451 | struct window *w; | |
5452 | RECT *r; | |
5453 | { | |
5454 | while (w) | |
5455 | { | |
5456 | if (!NILP (w->hchild)) | |
5457 | expose_window_tree (XWINDOW (w->hchild), r); | |
5458 | else if (!NILP (w->vchild)) | |
5459 | expose_window_tree (XWINDOW (w->vchild), r); | |
5460 | else | |
5461 | { | |
5462 | RECT window_rect; | |
5463 | RECT intersection_rect; | |
5464 | struct frame *f = XFRAME (w->frame); | |
5465 | int window_x, window_y, window_width, window_height; | |
5466 | ||
5467 | /* Frame-relative pixel rectangle of W. */ | |
5468 | window_box (w, -1, &window_x, &window_y, &window_width, | |
5469 | &window_height); | |
5470 | window_rect.left | |
5471 | = (window_x | |
5472 | - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) | |
5473 | - FRAME_LEFT_SCROLL_BAR_WIDTH (f) * CANON_Y_UNIT (f)); | |
5474 | window_rect.top = window_y; | |
5475 | window_rect.right = window_rect.left | |
5476 | + (window_width | |
5477 | + FRAME_X_FLAGS_AREA_WIDTH (f) | |
5478 | + FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f)); | |
5479 | window_rect.bottom = window_rect.top | |
5480 | + window_height + CURRENT_MODE_LINE_HEIGHT (w); | |
5481 | ||
158cba56 | 5482 | if (IntersectRect (&intersection_rect, r, &window_rect)) |
791f420f JR |
5483 | expose_window (w, &intersection_rect); |
5484 | } | |
5485 | ||
5486 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
5487 | } | |
5488 | } | |
5489 | ||
5490 | ||
5491 | /* Redraw the part of glyph row area AREA of glyph row ROW on window W | |
5492 | which intersects rectangle R. R is in window-relative coordinates. */ | |
5493 | ||
5494 | static void | |
5495 | expose_area (w, row, r, area) | |
5496 | struct window *w; | |
5497 | struct glyph_row *row; | |
5498 | RECT *r; | |
5499 | enum glyph_row_area area; | |
5500 | { | |
791f420f JR |
5501 | struct glyph *first = row->glyphs[area]; |
5502 | struct glyph *end = row->glyphs[area] + row->used[area]; | |
5503 | struct glyph *last; | |
2df85294 | 5504 | int first_x, start_x, x; |
791f420f JR |
5505 | |
5506 | /* Set x to the window-relative start position for drawing glyphs of | |
5507 | AREA. The first glyph of the text area can be partially visible. | |
5508 | The first glyphs of other areas cannot. */ | |
5509 | if (area == LEFT_MARGIN_AREA) | |
5510 | x = 0; | |
5511 | else if (area == TEXT_AREA) | |
5512 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5513 | else | |
5514 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5515 | + window_box_width (w, TEXT_AREA)); | |
5516 | ||
5517 | if (area == TEXT_AREA && row->fill_line_p) | |
5518 | /* If row extends face to end of line write the whole line. */ | |
5519 | x_draw_glyphs (w, x, row, area, | |
5520 | 0, row->used[area], | |
5521 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
5522 | NULL, NULL, 0); | |
5523 | else | |
5524 | { | |
2df85294 JR |
5525 | /* Set START_X to the window-relative start position for drawing glyphs of |
5526 | AREA. The first glyph of the text area can be partially visible. | |
5527 | The first glyphs of other areas cannot. */ | |
5528 | if (area == LEFT_MARGIN_AREA) | |
5529 | start_x = 0; | |
5530 | else if (area == TEXT_AREA) | |
5531 | start_x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5532 | else | |
5533 | start_x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5534 | + window_box_width (w, TEXT_AREA)); | |
5535 | x = start_x; | |
5536 | ||
791f420f JR |
5537 | /* Find the first glyph that must be redrawn. */ |
5538 | while (first < end | |
5539 | && x + first->pixel_width < r->left) | |
5540 | { | |
5541 | x += first->pixel_width; | |
5542 | ++first; | |
5543 | } | |
5544 | ||
5545 | /* Find the last one. */ | |
5546 | last = first; | |
5547 | first_x = x; | |
5548 | while (last < end | |
5549 | && x < r->right) | |
5550 | { | |
5551 | x += last->pixel_width; | |
5552 | ++last; | |
5553 | } | |
2df85294 | 5554 | |
791f420f JR |
5555 | /* Repaint. */ |
5556 | if (last > first) | |
f201d732 | 5557 | x_draw_glyphs (w, first_x - start_x, row, area, |
791f420f JR |
5558 | first - row->glyphs[area], |
5559 | last - row->glyphs[area], | |
5560 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
5561 | NULL, NULL, 0); | |
5562 | } | |
5563 | } | |
5564 | ||
5565 | ||
5566 | /* Redraw the parts of the glyph row ROW on window W intersecting | |
5567 | rectangle R. R is in window-relative coordinates. */ | |
ee78dc32 | 5568 | |
791f420f JR |
5569 | static void |
5570 | expose_line (w, row, r) | |
5571 | struct window *w; | |
5572 | struct glyph_row *row; | |
5573 | RECT *r; | |
5574 | { | |
5575 | xassert (row->enabled_p); | |
5576 | ||
5577 | if (row->mode_line_p || w->pseudo_window_p) | |
5578 | x_draw_glyphs (w, 0, row, TEXT_AREA, 0, row->used[TEXT_AREA], | |
5579 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
5580 | NULL, NULL, 0); | |
ee78dc32 | 5581 | else |
791f420f JR |
5582 | { |
5583 | if (row->used[LEFT_MARGIN_AREA]) | |
5584 | expose_area (w, row, r, LEFT_MARGIN_AREA); | |
5585 | if (row->used[TEXT_AREA]) | |
5586 | expose_area (w, row, r, TEXT_AREA); | |
5587 | if (row->used[RIGHT_MARGIN_AREA]) | |
5588 | expose_area (w, row, r, RIGHT_MARGIN_AREA); | |
5589 | x_draw_row_bitmaps (w, row); | |
5590 | } | |
ee78dc32 | 5591 | } |
ee78dc32 | 5592 | |
ee78dc32 | 5593 | |
791f420f | 5594 | /* Return non-zero if W's cursor intersects rectangle R. */ |
96214669 | 5595 | |
791f420f JR |
5596 | static int |
5597 | x_phys_cursor_in_rect_p (w, r) | |
5598 | struct window *w; | |
5599 | RECT *r; | |
ee78dc32 | 5600 | { |
791f420f JR |
5601 | RECT cr, result; |
5602 | struct glyph *cursor_glyph; | |
ee78dc32 | 5603 | |
791f420f JR |
5604 | cursor_glyph = get_phys_cursor_glyph (w); |
5605 | if (cursor_glyph) | |
ee78dc32 | 5606 | { |
791f420f JR |
5607 | cr.left = w->phys_cursor.x; |
5608 | cr.top = w->phys_cursor.y; | |
5609 | cr.right = cr.left + cursor_glyph->pixel_width; | |
5610 | cr.bottom = cr.top + w->phys_cursor_height; | |
158cba56 | 5611 | return IntersectRect (&result, &cr, r); |
ee78dc32 GV |
5612 | } |
5613 | else | |
791f420f | 5614 | return 0; |
ee78dc32 GV |
5615 | } |
5616 | ||
791f420f JR |
5617 | |
5618 | /* Redraw a rectangle of window W. R is a rectangle in window | |
5619 | relative coordinates. Call this function with input blocked. */ | |
5620 | ||
ee78dc32 | 5621 | static void |
791f420f JR |
5622 | expose_window (w, r) |
5623 | struct window *w; | |
5624 | RECT *r; | |
ee78dc32 | 5625 | { |
791f420f JR |
5626 | struct glyph_row *row; |
5627 | int y; | |
5628 | int yb = window_text_bottom_y (w); | |
5629 | int cursor_cleared_p; | |
5630 | ||
5631 | /* If window is not yet fully initialized, do nothing. This can | |
5632 | happen when toolkit scroll bars are used and a window is split. | |
5633 | Reconfiguring the scroll bar will generate an expose for a newly | |
5634 | created window. */ | |
5635 | if (w->current_matrix == NULL) | |
ee78dc32 GV |
5636 | return; |
5637 | ||
791f420f JR |
5638 | TRACE ((stderr, "expose_window (%d, %d, %d, %d)\n", |
5639 | r->left, r->top, r->right, r->bottom)); | |
ee78dc32 | 5640 | |
791f420f JR |
5641 | /* Convert to window coordinates. */ |
5642 | r->left = FRAME_TO_WINDOW_PIXEL_X (w, r->left); | |
5643 | r->top = FRAME_TO_WINDOW_PIXEL_Y (w, r->top); | |
5644 | r->right = FRAME_TO_WINDOW_PIXEL_X (w, r->right); | |
5645 | r->bottom = FRAME_TO_WINDOW_PIXEL_Y (w, r->bottom); | |
ee78dc32 | 5646 | |
791f420f JR |
5647 | /* Turn off the cursor. */ |
5648 | if (!w->pseudo_window_p | |
5649 | && x_phys_cursor_in_rect_p (w, r)) | |
5650 | { | |
5651 | x_clear_cursor (w); | |
5652 | cursor_cleared_p = 1; | |
5653 | } | |
5654 | else | |
5655 | cursor_cleared_p = 0; | |
5656 | ||
5657 | /* Find the first row intersecting the rectangle R. */ | |
5658 | row = w->current_matrix->rows; | |
5659 | y = 0; | |
5660 | while (row->enabled_p | |
5661 | && y < yb | |
5662 | && y + row->height < r->top) | |
5663 | { | |
5664 | y += row->height; | |
5665 | ++row; | |
5666 | } | |
5667 | ||
5668 | /* Display the text in the rectangle, one text line at a time. */ | |
5669 | while (row->enabled_p | |
5670 | && y < yb | |
5671 | && y < r->bottom) | |
5672 | { | |
5673 | expose_line (w, row, r); | |
5674 | y += row->height; | |
5675 | ++row; | |
5676 | } | |
ee78dc32 | 5677 | |
791f420f JR |
5678 | /* Display the mode line if there is one. */ |
5679 | if (WINDOW_WANTS_MODELINE_P (w) | |
5680 | && (row = MATRIX_MODE_LINE_ROW (w->current_matrix), | |
5681 | row->enabled_p) | |
5682 | && row->y < r->bottom) | |
5683 | expose_line (w, row, r); | |
689004fa | 5684 | |
791f420f JR |
5685 | if (!w->pseudo_window_p) |
5686 | { | |
5687 | /* Draw border between windows. */ | |
5688 | x_draw_vertical_border (w); | |
5689 | ||
5690 | /* Turn the cursor on again. */ | |
5691 | if (cursor_cleared_p) | |
5692 | x_update_window_cursor (w, 1); | |
5693 | } | |
ee78dc32 | 5694 | } |
ee78dc32 | 5695 | |
ee78dc32 GV |
5696 | \f |
5697 | static void | |
5698 | frame_highlight (f) | |
5699 | struct frame *f; | |
5700 | { | |
791f420f | 5701 | x_update_cursor (f, 1); |
ee78dc32 GV |
5702 | } |
5703 | ||
5704 | static void | |
5705 | frame_unhighlight (f) | |
5706 | struct frame *f; | |
5707 | { | |
791f420f | 5708 | x_update_cursor (f, 1); |
ee78dc32 GV |
5709 | } |
5710 | ||
ee78dc32 GV |
5711 | /* The focus has changed. Update the frames as necessary to reflect |
5712 | the new situation. Note that we can't change the selected frame | |
5713 | here, because the Lisp code we are interrupting might become confused. | |
5714 | Each event gets marked with the frame in which it occurred, so the | |
5715 | Lisp code can tell when the switch took place by examining the events. */ | |
5716 | ||
9ef2e2cf | 5717 | static void |
ee78dc32 | 5718 | x_new_focus_frame (dpyinfo, frame) |
fbd6baed | 5719 | struct w32_display_info *dpyinfo; |
ee78dc32 GV |
5720 | struct frame *frame; |
5721 | { | |
fbd6baed | 5722 | struct frame *old_focus = dpyinfo->w32_focus_frame; |
ee78dc32 | 5723 | |
fbd6baed | 5724 | if (frame != dpyinfo->w32_focus_frame) |
ee78dc32 GV |
5725 | { |
5726 | /* Set this before calling other routines, so that they see | |
fbd6baed GV |
5727 | the correct value of w32_focus_frame. */ |
5728 | dpyinfo->w32_focus_frame = frame; | |
ee78dc32 GV |
5729 | |
5730 | if (old_focus && old_focus->auto_lower) | |
5731 | x_lower_frame (old_focus); | |
5732 | ||
fbd6baed GV |
5733 | if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise) |
5734 | pending_autoraise_frame = dpyinfo->w32_focus_frame; | |
ee78dc32 GV |
5735 | else |
5736 | pending_autoraise_frame = 0; | |
5737 | } | |
5738 | ||
5739 | x_frame_rehighlight (dpyinfo); | |
5740 | } | |
5741 | ||
5742 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ | |
5743 | ||
5744 | void | |
5745 | x_mouse_leave (dpyinfo) | |
fbd6baed | 5746 | struct w32_display_info *dpyinfo; |
ee78dc32 | 5747 | { |
fbd6baed | 5748 | x_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame); |
ee78dc32 GV |
5749 | } |
5750 | ||
5751 | /* The focus has changed, or we have redirected a frame's focus to | |
5752 | another frame (this happens when a frame uses a surrogate | |
9ef2e2cf | 5753 | mini-buffer frame). Shift the highlight as appropriate. |
ee78dc32 GV |
5754 | |
5755 | The FRAME argument doesn't necessarily have anything to do with which | |
9ef2e2cf JR |
5756 | frame is being highlighted or un-highlighted; we only use it to find |
5757 | the appropriate X display info. */ | |
5758 | ||
ee78dc32 | 5759 | static void |
fbd6baed | 5760 | w32_frame_rehighlight (frame) |
ee78dc32 GV |
5761 | struct frame *frame; |
5762 | { | |
fbd6baed | 5763 | x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame)); |
ee78dc32 GV |
5764 | } |
5765 | ||
5766 | static void | |
5767 | x_frame_rehighlight (dpyinfo) | |
fbd6baed | 5768 | struct w32_display_info *dpyinfo; |
ee78dc32 | 5769 | { |
fbd6baed | 5770 | struct frame *old_highlight = dpyinfo->w32_highlight_frame; |
ee78dc32 | 5771 | |
fbd6baed | 5772 | if (dpyinfo->w32_focus_frame) |
ee78dc32 | 5773 | { |
fbd6baed GV |
5774 | dpyinfo->w32_highlight_frame |
5775 | = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame))) | |
5776 | ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame)) | |
5777 | : dpyinfo->w32_focus_frame); | |
5778 | if (! FRAME_LIVE_P (dpyinfo->w32_highlight_frame)) | |
ee78dc32 | 5779 | { |
fbd6baed GV |
5780 | FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame) = Qnil; |
5781 | dpyinfo->w32_highlight_frame = dpyinfo->w32_focus_frame; | |
ee78dc32 GV |
5782 | } |
5783 | } | |
5784 | else | |
fbd6baed | 5785 | dpyinfo->w32_highlight_frame = 0; |
ee78dc32 | 5786 | |
fbd6baed | 5787 | if (dpyinfo->w32_highlight_frame != old_highlight) |
ee78dc32 GV |
5788 | { |
5789 | if (old_highlight) | |
5790 | frame_unhighlight (old_highlight); | |
fbd6baed GV |
5791 | if (dpyinfo->w32_highlight_frame) |
5792 | frame_highlight (dpyinfo->w32_highlight_frame); | |
ee78dc32 GV |
5793 | } |
5794 | } | |
5795 | \f | |
5796 | /* Keyboard processing - modifier keys, etc. */ | |
5797 | ||
5798 | /* Convert a keysym to its name. */ | |
5799 | ||
5800 | char * | |
5801 | x_get_keysym_name (keysym) | |
5802 | int keysym; | |
5803 | { | |
5804 | /* Make static so we can always return it */ | |
5805 | static char value[100]; | |
5806 | ||
5807 | BLOCK_INPUT; | |
9127e20e | 5808 | GetKeyNameText (keysym, value, 100); |
ee78dc32 GV |
5809 | UNBLOCK_INPUT; |
5810 | ||
5811 | return value; | |
5812 | } | |
9ef2e2cf JR |
5813 | |
5814 | ||
ee78dc32 GV |
5815 | \f |
5816 | /* Mouse clicks and mouse movement. Rah. */ | |
5817 | ||
9ef2e2cf JR |
5818 | /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph |
5819 | co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the | |
5820 | glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do | |
5821 | not force the value into range. */ | |
ee78dc32 GV |
5822 | |
5823 | void | |
5824 | pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip) | |
5825 | FRAME_PTR f; | |
5826 | register int pix_x, pix_y; | |
5827 | register int *x, *y; | |
5828 | RECT *bounds; | |
5829 | int noclip; | |
5830 | { | |
52cf03a1 GV |
5831 | /* Support tty mode: if Vwindow_system is nil, behave correctly. */ |
5832 | if (NILP (Vwindow_system)) | |
5833 | { | |
5834 | *x = pix_x; | |
5835 | *y = pix_y; | |
5836 | return; | |
5837 | } | |
5838 | ||
ee78dc32 GV |
5839 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down |
5840 | even for negative values. */ | |
5841 | if (pix_x < 0) | |
9127e20e | 5842 | pix_x -= FONT_WIDTH (FRAME_FONT (f)) - 1; |
ee78dc32 | 5843 | if (pix_y < 0) |
fbd6baed | 5844 | pix_y -= (f)->output_data.w32->line_height - 1; |
ee78dc32 GV |
5845 | |
5846 | pix_x = PIXEL_TO_CHAR_COL (f, pix_x); | |
5847 | pix_y = PIXEL_TO_CHAR_ROW (f, pix_y); | |
5848 | ||
5849 | if (bounds) | |
5850 | { | |
5851 | bounds->left = CHAR_TO_PIXEL_COL (f, pix_x); | |
5852 | bounds->top = CHAR_TO_PIXEL_ROW (f, pix_y); | |
9127e20e | 5853 | bounds->right = bounds->left + FONT_WIDTH (FRAME_FONT (f)) - 1; |
fbd6baed | 5854 | bounds->bottom = bounds->top + f->output_data.w32->line_height - 1; |
ee78dc32 GV |
5855 | } |
5856 | ||
5857 | if (!noclip) | |
5858 | { | |
5859 | if (pix_x < 0) | |
5860 | pix_x = 0; | |
ec48c3a7 JR |
5861 | else if (pix_x > FRAME_WINDOW_WIDTH (f)) |
5862 | pix_x = FRAME_WINDOW_WIDTH (f); | |
ee78dc32 GV |
5863 | |
5864 | if (pix_y < 0) | |
5865 | pix_y = 0; | |
5866 | else if (pix_y > f->height) | |
5867 | pix_y = f->height; | |
5868 | } | |
5869 | ||
5870 | *x = pix_x; | |
5871 | *y = pix_y; | |
5872 | } | |
5873 | ||
791f420f JR |
5874 | |
5875 | /* Given HPOS/VPOS in the current matrix of W, return corresponding | |
5876 | frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we | |
5877 | can't tell the positions because W's display is not up to date, | |
5878 | return 0. */ | |
5879 | ||
5880 | int | |
5881 | glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y) | |
5882 | struct window *w; | |
5883 | int hpos, vpos; | |
5884 | int *frame_x, *frame_y; | |
ee78dc32 | 5885 | { |
791f420f JR |
5886 | int success_p; |
5887 | ||
5888 | xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w); | |
5889 | xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h); | |
5890 | ||
5891 | if (display_completed) | |
52cf03a1 | 5892 | { |
791f420f JR |
5893 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos); |
5894 | struct glyph *glyph = row->glyphs[TEXT_AREA]; | |
5895 | struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]); | |
5896 | ||
5897 | *frame_y = row->y; | |
5898 | *frame_x = row->x; | |
5899 | while (glyph < end) | |
5900 | { | |
5901 | *frame_x += glyph->pixel_width; | |
5902 | ++glyph; | |
5903 | } | |
5904 | ||
5905 | success_p = 1; | |
5906 | } | |
5907 | else | |
5908 | { | |
5909 | *frame_y = *frame_x = 0; | |
5910 | success_p = 0; | |
52cf03a1 GV |
5911 | } |
5912 | ||
791f420f JR |
5913 | *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y); |
5914 | *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x); | |
5915 | return success_p; | |
ee78dc32 GV |
5916 | } |
5917 | ||
5918 | BOOL | |
5919 | parse_button (message, pbutton, pup) | |
5920 | int message; | |
5921 | int * pbutton; | |
5922 | int * pup; | |
5923 | { | |
5924 | int button = 0; | |
5925 | int up = 0; | |
5926 | ||
5927 | switch (message) | |
5928 | { | |
5929 | case WM_LBUTTONDOWN: | |
5930 | button = 0; | |
5931 | up = 0; | |
5932 | break; | |
5933 | case WM_LBUTTONUP: | |
5934 | button = 0; | |
5935 | up = 1; | |
5936 | break; | |
5937 | case WM_MBUTTONDOWN: | |
fbd6baed | 5938 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5939 | button = 1; |
5940 | else | |
5941 | button = 2; | |
ee78dc32 GV |
5942 | up = 0; |
5943 | break; | |
5944 | case WM_MBUTTONUP: | |
fbd6baed | 5945 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5946 | button = 1; |
5947 | else | |
5948 | button = 2; | |
ee78dc32 GV |
5949 | up = 1; |
5950 | break; | |
5951 | case WM_RBUTTONDOWN: | |
fbd6baed | 5952 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5953 | button = 2; |
5954 | else | |
5955 | button = 1; | |
ee78dc32 GV |
5956 | up = 0; |
5957 | break; | |
5958 | case WM_RBUTTONUP: | |
fbd6baed | 5959 | if (NILP (Vw32_swap_mouse_buttons)) |
52cf03a1 GV |
5960 | button = 2; |
5961 | else | |
5962 | button = 1; | |
ee78dc32 GV |
5963 | up = 1; |
5964 | break; | |
5965 | default: | |
5966 | return (FALSE); | |
5967 | } | |
5968 | ||
5969 | if (pup) *pup = up; | |
5970 | if (pbutton) *pbutton = button; | |
5971 | ||
5972 | return (TRUE); | |
5973 | } | |
5974 | ||
5975 | ||
5976 | /* Prepare a mouse-event in *RESULT for placement in the input queue. | |
5977 | ||
5978 | If the event is a button press, then note that we have grabbed | |
5979 | the mouse. */ | |
5980 | ||
ec48c3a7 | 5981 | static Lisp_Object |
ee78dc32 GV |
5982 | construct_mouse_click (result, msg, f) |
5983 | struct input_event *result; | |
fbd6baed | 5984 | W32Msg *msg; |
ee78dc32 GV |
5985 | struct frame *f; |
5986 | { | |
5987 | int button; | |
5988 | int up; | |
5989 | ||
5990 | parse_button (msg->msg.message, &button, &up); | |
5991 | ||
5992 | /* Make the event type no_event; we'll change that when we decide | |
5993 | otherwise. */ | |
5994 | result->kind = mouse_click; | |
5995 | result->code = button; | |
5996 | result->timestamp = msg->msg.time; | |
5997 | result->modifiers = (msg->dwModifiers | |
5998 | | (up | |
5999 | ? up_modifier | |
6000 | : down_modifier)); | |
6001 | ||
ec48c3a7 JR |
6002 | XSETINT (result->x, LOWORD (msg->msg.lParam)); |
6003 | XSETINT (result->y, HIWORD (msg->msg.lParam)); | |
6004 | XSETFRAME (result->frame_or_window, f); | |
6005 | result->arg = Qnil; | |
6006 | return Qnil; | |
ee78dc32 GV |
6007 | } |
6008 | ||
ec48c3a7 | 6009 | static Lisp_Object |
689004fa GV |
6010 | construct_mouse_wheel (result, msg, f) |
6011 | struct input_event *result; | |
6012 | W32Msg *msg; | |
6013 | struct frame *f; | |
6014 | { | |
6015 | POINT p; | |
6016 | result->kind = mouse_wheel; | |
6017 | result->code = (short) HIWORD (msg->msg.wParam); | |
6018 | result->timestamp = msg->msg.time; | |
6019 | result->modifiers = msg->dwModifiers; | |
6020 | p.x = LOWORD (msg->msg.lParam); | |
6021 | p.y = HIWORD (msg->msg.lParam); | |
9127e20e | 6022 | ScreenToClient (msg->msg.hwnd, &p); |
689004fa GV |
6023 | XSETINT (result->x, p.x); |
6024 | XSETINT (result->y, p.y); | |
6025 | XSETFRAME (result->frame_or_window, f); | |
7e889510 | 6026 | result->arg = Qnil; |
ec48c3a7 | 6027 | return Qnil; |
689004fa GV |
6028 | } |
6029 | ||
ec48c3a7 | 6030 | static Lisp_Object |
12857dfd RS |
6031 | construct_drag_n_drop (result, msg, f) |
6032 | struct input_event *result; | |
6033 | W32Msg *msg; | |
6034 | struct frame *f; | |
6035 | { | |
6036 | Lisp_Object files; | |
6037 | Lisp_Object frame; | |
6038 | HDROP hdrop; | |
6039 | POINT p; | |
6040 | WORD num_files; | |
6041 | char *name; | |
6042 | int i, len; | |
6043 | ||
6044 | result->kind = drag_n_drop; | |
6045 | result->code = 0; | |
6046 | result->timestamp = msg->msg.time; | |
6047 | result->modifiers = msg->dwModifiers; | |
6048 | ||
fb9cc9cc AI |
6049 | hdrop = (HDROP) msg->msg.wParam; |
6050 | DragQueryPoint (hdrop, &p); | |
6051 | ||
e12ca9c2 | 6052 | #if 0 |
12857dfd RS |
6053 | p.x = LOWORD (msg->msg.lParam); |
6054 | p.y = HIWORD (msg->msg.lParam); | |
6055 | ScreenToClient (msg->msg.hwnd, &p); | |
e12ca9c2 AI |
6056 | #endif |
6057 | ||
12857dfd RS |
6058 | XSETINT (result->x, p.x); |
6059 | XSETINT (result->y, p.y); | |
6060 | ||
12857dfd RS |
6061 | num_files = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); |
6062 | files = Qnil; | |
6063 | ||
6064 | for (i = 0; i < num_files; i++) | |
6065 | { | |
6066 | len = DragQueryFile (hdrop, i, NULL, 0); | |
6067 | if (len <= 0) | |
6068 | continue; | |
6069 | name = alloca (len + 1); | |
6070 | DragQueryFile (hdrop, i, name, len + 1); | |
6071 | files = Fcons (build_string (name), files); | |
6072 | } | |
6073 | ||
6074 | DragFinish (hdrop); | |
6075 | ||
6076 | XSETFRAME (frame, f); | |
6077 | result->frame_or_window = Fcons (frame, files); | |
7e889510 | 6078 | result->arg = Qnil; |
ec48c3a7 | 6079 | return Qnil; |
12857dfd RS |
6080 | } |
6081 | ||
ee78dc32 GV |
6082 | \f |
6083 | /* Function to report a mouse movement to the mainstream Emacs code. | |
6084 | The input handler calls this. | |
6085 | ||
6086 | We have received a mouse movement event, which is given in *event. | |
6087 | If the mouse is over a different glyph than it was last time, tell | |
6088 | the mainstream emacs code by setting mouse_moved. If not, ask for | |
6089 | another motion event, so we can check again the next time it moves. */ | |
6090 | ||
791f420f JR |
6091 | static MSG last_mouse_motion_event; |
6092 | static Lisp_Object last_mouse_motion_frame; | |
6093 | ||
ee78dc32 GV |
6094 | static void |
6095 | note_mouse_movement (frame, msg) | |
6096 | FRAME_PTR frame; | |
6097 | MSG *msg; | |
6098 | { | |
6099 | last_mouse_movement_time = msg->time; | |
791f420f JR |
6100 | memcpy (&last_mouse_motion_event, msg, sizeof (last_mouse_motion_event)); |
6101 | XSETFRAME (last_mouse_motion_frame, frame); | |
ee78dc32 | 6102 | |
fbd6baed | 6103 | if (msg->hwnd != FRAME_W32_WINDOW (frame)) |
ee78dc32 GV |
6104 | { |
6105 | frame->mouse_moved = 1; | |
6106 | last_mouse_scroll_bar = Qnil; | |
ee78dc32 GV |
6107 | note_mouse_highlight (frame, -1, -1); |
6108 | } | |
6109 | ||
6110 | /* Has the mouse moved off the glyph it was on at the last sighting? */ | |
6111 | else if (LOWORD (msg->lParam) < last_mouse_glyph.left | |
6112 | || LOWORD (msg->lParam) > last_mouse_glyph.right | |
9bf7b6aa | 6113 | || HIWORD (msg->lParam) < last_mouse_glyph.top |
ee78dc32 GV |
6114 | || HIWORD (msg->lParam) > last_mouse_glyph.bottom) |
6115 | { | |
6116 | frame->mouse_moved = 1; | |
6117 | last_mouse_scroll_bar = Qnil; | |
6118 | ||
6119 | note_mouse_highlight (frame, LOWORD (msg->lParam), HIWORD (msg->lParam)); | |
6120 | } | |
6121 | } | |
6122 | ||
6123 | /* This is used for debugging, to turn off note_mouse_highlight. */ | |
9ef2e2cf | 6124 | |
791f420f JR |
6125 | int disable_mouse_highlight; |
6126 | ||
6127 | ||
6128 | \f | |
6129 | /************************************************************************ | |
6130 | Mouse Face | |
6131 | ************************************************************************/ | |
6132 | ||
6133 | /* Find the glyph under window-relative coordinates X/Y in window W. | |
6134 | Consider only glyphs from buffer text, i.e. no glyphs from overlay | |
6135 | strings. Return in *HPOS and *VPOS the row and column number of | |
6136 | the glyph found. Return in *AREA the glyph area containing X. | |
6137 | Value is a pointer to the glyph found or null if X/Y is not on | |
6138 | text, or we can't tell because W's current matrix is not up to | |
6139 | date. */ | |
6140 | ||
6141 | static struct glyph * | |
6142 | x_y_to_hpos_vpos (w, x, y, hpos, vpos, area) | |
6143 | struct window *w; | |
6144 | int x, y; | |
6145 | int *hpos, *vpos, *area; | |
6146 | { | |
6147 | struct glyph *glyph, *end; | |
ec48c3a7 | 6148 | struct glyph_row *row = NULL; |
791f420f JR |
6149 | int x0, i, left_area_width; |
6150 | ||
6151 | /* Find row containing Y. Give up if some row is not enabled. */ | |
6152 | for (i = 0; i < w->current_matrix->nrows; ++i) | |
6153 | { | |
6154 | row = MATRIX_ROW (w->current_matrix, i); | |
6155 | if (!row->enabled_p) | |
6156 | return NULL; | |
6157 | if (y >= row->y && y < MATRIX_ROW_BOTTOM_Y (row)) | |
6158 | break; | |
6159 | } | |
6160 | ||
6161 | *vpos = i; | |
6162 | *hpos = 0; | |
6163 | ||
6164 | /* Give up if Y is not in the window. */ | |
6165 | if (i == w->current_matrix->nrows) | |
6166 | return NULL; | |
6167 | ||
6168 | /* Get the glyph area containing X. */ | |
6169 | if (w->pseudo_window_p) | |
6170 | { | |
6171 | *area = TEXT_AREA; | |
6172 | x0 = 0; | |
6173 | } | |
6174 | else | |
6175 | { | |
6176 | left_area_width = window_box_width (w, LEFT_MARGIN_AREA); | |
6177 | if (x < left_area_width) | |
6178 | { | |
6179 | *area = LEFT_MARGIN_AREA; | |
6180 | x0 = 0; | |
6181 | } | |
6182 | else if (x < left_area_width + window_box_width (w, TEXT_AREA)) | |
6183 | { | |
6184 | *area = TEXT_AREA; | |
6185 | x0 = row->x + left_area_width; | |
6186 | } | |
6187 | else | |
6188 | { | |
6189 | *area = RIGHT_MARGIN_AREA; | |
6190 | x0 = left_area_width + window_box_width (w, TEXT_AREA); | |
6191 | } | |
6192 | } | |
6193 | ||
6194 | /* Find glyph containing X. */ | |
6195 | glyph = row->glyphs[*area]; | |
6196 | end = glyph + row->used[*area]; | |
6197 | while (glyph < end) | |
6198 | { | |
6199 | if (x < x0 + glyph->pixel_width) | |
6200 | { | |
6201 | if (w->pseudo_window_p) | |
6202 | break; | |
6203 | else if (BUFFERP (glyph->object)) | |
6204 | break; | |
6205 | } | |
6206 | ||
6207 | x0 += glyph->pixel_width; | |
6208 | ++glyph; | |
6209 | } | |
6210 | ||
6211 | if (glyph == end) | |
6212 | return NULL; | |
6213 | ||
6214 | *hpos = glyph - row->glyphs[*area]; | |
6215 | return glyph; | |
6216 | } | |
6217 | ||
6218 | ||
6219 | /* Convert frame-relative x/y to coordinates relative to window W. | |
6220 | Takes pseudo-windows into account. */ | |
6221 | ||
6222 | static void | |
6223 | frame_to_window_pixel_xy (w, x, y) | |
6224 | struct window *w; | |
6225 | int *x, *y; | |
6226 | { | |
6227 | if (w->pseudo_window_p) | |
6228 | { | |
6229 | /* A pseudo-window is always full-width, and starts at the | |
6230 | left edge of the frame, plus a frame border. */ | |
6231 | struct frame *f = XFRAME (w->frame); | |
6232 | *x -= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f); | |
6233 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6234 | } | |
6235 | else | |
6236 | { | |
6237 | *x = FRAME_TO_WINDOW_PIXEL_X (w, *x); | |
6238 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6239 | } | |
6240 | } | |
6241 | ||
6242 | ||
6243 | /* Take proper action when mouse has moved to the mode or top line of | |
6244 | window W, x-position X. MODE_LINE_P non-zero means mouse is on the | |
6245 | mode line. X is relative to the start of the text display area of | |
6246 | W, so the width of bitmap areas and scroll bars must be subtracted | |
6247 | to get a position relative to the start of the mode line. */ | |
6248 | ||
6249 | static void | |
6250 | note_mode_line_highlight (w, x, mode_line_p) | |
6251 | struct window *w; | |
6252 | int x, mode_line_p; | |
6253 | { | |
6254 | struct frame *f = XFRAME (w->frame); | |
6255 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6256 | Cursor cursor = dpyinfo->vertical_scroll_bar_cursor; | |
6257 | struct glyph_row *row; | |
6258 | ||
6259 | if (mode_line_p) | |
6260 | row = MATRIX_MODE_LINE_ROW (w->current_matrix); | |
6261 | else | |
6262 | row = MATRIX_HEADER_LINE_ROW (w->current_matrix); | |
6263 | ||
6264 | if (row->enabled_p) | |
6265 | { | |
6266 | struct glyph *glyph, *end; | |
6267 | Lisp_Object help, map; | |
6268 | int x0; | |
6269 | ||
6270 | /* Find the glyph under X. */ | |
6271 | glyph = row->glyphs[TEXT_AREA]; | |
6272 | end = glyph + row->used[TEXT_AREA]; | |
6273 | x0 = - (FRAME_LEFT_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f) | |
6274 | + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f)); | |
6275 | while (glyph < end | |
6276 | && x >= x0 + glyph->pixel_width) | |
6277 | { | |
6278 | x0 += glyph->pixel_width; | |
6279 | ++glyph; | |
6280 | } | |
6281 | ||
6282 | if (glyph < end | |
6283 | && STRINGP (glyph->object) | |
6284 | && XSTRING (glyph->object)->intervals | |
6285 | && glyph->charpos >= 0 | |
6286 | && glyph->charpos < XSTRING (glyph->object)->size) | |
6287 | { | |
6288 | /* If we're on a string with `help-echo' text property, | |
6289 | arrange for the help to be displayed. This is done by | |
6290 | setting the global variable help_echo to the help string. */ | |
6291 | help = Fget_text_property (make_number (glyph->charpos), | |
6292 | Qhelp_echo, glyph->object); | |
b7e80413 | 6293 | if (!NILP (help)) |
ec48c3a7 JR |
6294 | { |
6295 | help_echo = help; | |
158cba56 | 6296 | XSETWINDOW (help_echo_window, w); |
ec48c3a7 JR |
6297 | help_echo_object = glyph->object; |
6298 | help_echo_pos = glyph->charpos; | |
6299 | } | |
791f420f JR |
6300 | |
6301 | /* Change the mouse pointer according to what is under X/Y. */ | |
6302 | map = Fget_text_property (make_number (glyph->charpos), | |
6303 | Qlocal_map, glyph->object); | |
02067692 | 6304 | if (KEYMAPP (map)) |
791f420f JR |
6305 | cursor = f->output_data.w32->nontext_cursor; |
6306 | } | |
6307 | } | |
9ef2e2cf | 6308 | |
01b220b6 | 6309 | #if 0 /* TODO: mouse cursor */ |
791f420f JR |
6310 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor); |
6311 | #endif | |
6312 | } | |
ee78dc32 | 6313 | |
9ef2e2cf JR |
6314 | |
6315 | /* Take proper action when the mouse has moved to position X, Y on | |
6316 | frame F as regards highlighting characters that have mouse-face | |
6317 | properties. Also de-highlighting chars where the mouse was before. | |
ee78dc32 GV |
6318 | X and Y can be negative or out of range. */ |
6319 | ||
6320 | static void | |
6321 | note_mouse_highlight (f, x, y) | |
9ef2e2cf | 6322 | struct frame *f; |
ee78dc32 GV |
6323 | int x, y; |
6324 | { | |
791f420f JR |
6325 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
6326 | int portion; | |
ee78dc32 GV |
6327 | Lisp_Object window; |
6328 | struct window *w; | |
6329 | ||
791f420f JR |
6330 | /* When a menu is active, don't highlight because this looks odd. */ |
6331 | if (popup_activated ()) | |
6332 | return; | |
6333 | ||
9ef2e2cf JR |
6334 | if (disable_mouse_highlight |
6335 | || !f->glyphs_initialized_p) | |
ee78dc32 GV |
6336 | return; |
6337 | ||
791f420f JR |
6338 | dpyinfo->mouse_face_mouse_x = x; |
6339 | dpyinfo->mouse_face_mouse_y = y; | |
6340 | dpyinfo->mouse_face_mouse_frame = f; | |
ee78dc32 | 6341 | |
791f420f | 6342 | if (dpyinfo->mouse_face_defer) |
ee78dc32 GV |
6343 | return; |
6344 | ||
6345 | if (gc_in_progress) | |
6346 | { | |
791f420f | 6347 | dpyinfo->mouse_face_deferred_gc = 1; |
ee78dc32 GV |
6348 | return; |
6349 | } | |
6350 | ||
ee78dc32 | 6351 | /* Which window is that in? */ |
791f420f | 6352 | window = window_from_coordinates (f, x, y, &portion, 1); |
ee78dc32 GV |
6353 | |
6354 | /* If we were displaying active text in another window, clear that. */ | |
791f420f JR |
6355 | if (! EQ (window, dpyinfo->mouse_face_window)) |
6356 | clear_mouse_face (dpyinfo); | |
6357 | ||
6358 | /* Not on a window -> return. */ | |
6359 | if (!WINDOWP (window)) | |
6360 | return; | |
6361 | ||
6362 | /* Convert to window-relative pixel coordinates. */ | |
6363 | w = XWINDOW (window); | |
6364 | frame_to_window_pixel_xy (w, &x, &y); | |
6365 | ||
6366 | /* Handle tool-bar window differently since it doesn't display a | |
6367 | buffer. */ | |
6368 | if (EQ (window, f->tool_bar_window)) | |
6369 | { | |
6370 | note_tool_bar_highlight (f, x, y); | |
6371 | return; | |
6372 | } | |
6373 | ||
6374 | if (portion == 1 || portion == 3) | |
6375 | { | |
6376 | /* Mouse is on the mode or top line. */ | |
6377 | note_mode_line_highlight (w, x, portion == 1); | |
6378 | return; | |
6379 | } | |
01b220b6 | 6380 | #if 0 /* TODO: mouse cursor */ |
250cfece JR |
6381 | else if (portion == 2) |
6382 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
6383 | f->output_data.x->horizontal_drag_cursor); | |
791f420f JR |
6384 | else |
6385 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
6386 | f->output_data.x->text_cursor); | |
6387 | #endif | |
ee78dc32 GV |
6388 | |
6389 | /* Are we in a window whose display is up to date? | |
6390 | And verify the buffer's text has not changed. */ | |
9ef2e2cf | 6391 | if (/* Within text portion of the window. */ |
791f420f | 6392 | portion == 0 |
ee78dc32 | 6393 | && EQ (w->window_end_valid, w->buffer) |
9ef2e2cf JR |
6394 | && XFASTINT (w->last_modified) == BUF_MODIFF (XBUFFER (w->buffer)) |
6395 | && (XFASTINT (w->last_overlay_modified) | |
6396 | == BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)))) | |
ee78dc32 | 6397 | { |
791f420f JR |
6398 | int hpos, vpos, pos, i, area; |
6399 | struct glyph *glyph; | |
6400 | ||
6401 | /* Find the glyph under X/Y. */ | |
6402 | glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &area); | |
6403 | ||
6404 | /* Clear mouse face if X/Y not over text. */ | |
6405 | if (glyph == NULL | |
6406 | || area != TEXT_AREA | |
6407 | || !MATRIX_ROW (w->current_matrix, vpos)->displays_text_p) | |
6408 | { | |
6409 | clear_mouse_face (dpyinfo); | |
6410 | return; | |
6411 | } | |
6412 | ||
6413 | pos = glyph->charpos; | |
6414 | xassert (w->pseudo_window_p || BUFFERP (glyph->object)); | |
6415 | ||
6416 | /* Check for mouse-face and help-echo. */ | |
6417 | { | |
6418 | Lisp_Object mouse_face, overlay, position; | |
6419 | Lisp_Object *overlay_vec; | |
6420 | int len, noverlays; | |
6421 | struct buffer *obuf; | |
6422 | int obegv, ozv; | |
6423 | ||
6424 | /* If we get an out-of-range value, return now; avoid an error. */ | |
6425 | if (pos > BUF_Z (XBUFFER (w->buffer))) | |
6426 | return; | |
6427 | ||
6428 | /* Make the window's buffer temporarily current for | |
6429 | overlays_at and compute_char_face. */ | |
6430 | obuf = current_buffer; | |
6431 | current_buffer = XBUFFER (w->buffer); | |
6432 | obegv = BEGV; | |
6433 | ozv = ZV; | |
6434 | BEGV = BEG; | |
6435 | ZV = Z; | |
6436 | ||
6437 | /* Is this char mouse-active or does it have help-echo? */ | |
6438 | XSETINT (position, pos); | |
6439 | ||
6440 | /* Put all the overlays we want in a vector in overlay_vec. | |
6441 | Store the length in len. If there are more than 10, make | |
6442 | enough space for all, and try again. */ | |
6443 | len = 10; | |
6444 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
46636545 | 6445 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL, 0); |
791f420f JR |
6446 | if (noverlays > len) |
6447 | { | |
6448 | len = noverlays; | |
6449 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
46636545 | 6450 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL,0); |
791f420f JR |
6451 | } |
6452 | ||
158cba56 | 6453 | /* Sort overlays into increasing priority order. */ |
791f420f JR |
6454 | noverlays = sort_overlays (overlay_vec, noverlays, w); |
6455 | ||
6456 | /* Check mouse-face highlighting. */ | |
6457 | if (! (EQ (window, dpyinfo->mouse_face_window) | |
6458 | && vpos >= dpyinfo->mouse_face_beg_row | |
6459 | && vpos <= dpyinfo->mouse_face_end_row | |
6460 | && (vpos > dpyinfo->mouse_face_beg_row | |
6461 | || hpos >= dpyinfo->mouse_face_beg_col) | |
6462 | && (vpos < dpyinfo->mouse_face_end_row | |
6463 | || hpos < dpyinfo->mouse_face_end_col | |
6464 | || dpyinfo->mouse_face_past_end))) | |
6465 | { | |
6466 | /* Clear the display of the old active region, if any. */ | |
6467 | clear_mouse_face (dpyinfo); | |
6468 | ||
6469 | /* Find the highest priority overlay that has a mouse-face prop. */ | |
6470 | overlay = Qnil; | |
158cba56 | 6471 | for (i = noverlays - 1; i >= 0; --i) |
791f420f JR |
6472 | { |
6473 | mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face); | |
6474 | if (!NILP (mouse_face)) | |
6475 | { | |
6476 | overlay = overlay_vec[i]; | |
6477 | break; | |
6478 | } | |
6479 | } | |
6480 | ||
6481 | /* If no overlay applies, get a text property. */ | |
6482 | if (NILP (overlay)) | |
6483 | mouse_face = Fget_text_property (position, Qmouse_face, w->buffer); | |
6484 | ||
6485 | /* Handle the overlay case. */ | |
6486 | if (! NILP (overlay)) | |
6487 | { | |
6488 | /* Find the range of text around this char that | |
6489 | should be active. */ | |
6490 | Lisp_Object before, after; | |
6491 | int ignore; | |
6492 | ||
6493 | before = Foverlay_start (overlay); | |
6494 | after = Foverlay_end (overlay); | |
6495 | /* Record this as the current active region. */ | |
6496 | fast_find_position (w, XFASTINT (before), | |
6497 | &dpyinfo->mouse_face_beg_col, | |
6498 | &dpyinfo->mouse_face_beg_row, | |
6499 | &dpyinfo->mouse_face_beg_x, | |
6500 | &dpyinfo->mouse_face_beg_y); | |
6501 | dpyinfo->mouse_face_past_end | |
6502 | = !fast_find_position (w, XFASTINT (after), | |
6503 | &dpyinfo->mouse_face_end_col, | |
6504 | &dpyinfo->mouse_face_end_row, | |
6505 | &dpyinfo->mouse_face_end_x, | |
6506 | &dpyinfo->mouse_face_end_y); | |
6507 | dpyinfo->mouse_face_window = window; | |
6508 | dpyinfo->mouse_face_face_id | |
6509 | = face_at_buffer_position (w, pos, 0, 0, | |
6510 | &ignore, pos + 1, 1); | |
6511 | ||
6512 | /* Display it as active. */ | |
6513 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6514 | } | |
6515 | /* Handle the text property case. */ | |
6516 | else if (! NILP (mouse_face)) | |
6517 | { | |
6518 | /* Find the range of text around this char that | |
6519 | should be active. */ | |
6520 | Lisp_Object before, after, beginning, end; | |
6521 | int ignore; | |
6522 | ||
6523 | beginning = Fmarker_position (w->start); | |
6524 | XSETINT (end, (BUF_Z (XBUFFER (w->buffer)) | |
6525 | - XFASTINT (w->window_end_pos))); | |
6526 | before | |
6527 | = Fprevious_single_property_change (make_number (pos + 1), | |
6528 | Qmouse_face, | |
6529 | w->buffer, beginning); | |
6530 | after | |
6531 | = Fnext_single_property_change (position, Qmouse_face, | |
6532 | w->buffer, end); | |
6533 | /* Record this as the current active region. */ | |
6534 | fast_find_position (w, XFASTINT (before), | |
6535 | &dpyinfo->mouse_face_beg_col, | |
6536 | &dpyinfo->mouse_face_beg_row, | |
6537 | &dpyinfo->mouse_face_beg_x, | |
6538 | &dpyinfo->mouse_face_beg_y); | |
6539 | dpyinfo->mouse_face_past_end | |
6540 | = !fast_find_position (w, XFASTINT (after), | |
6541 | &dpyinfo->mouse_face_end_col, | |
6542 | &dpyinfo->mouse_face_end_row, | |
6543 | &dpyinfo->mouse_face_end_x, | |
6544 | &dpyinfo->mouse_face_end_y); | |
6545 | dpyinfo->mouse_face_window = window; | |
6546 | dpyinfo->mouse_face_face_id | |
6547 | = face_at_buffer_position (w, pos, 0, 0, | |
6548 | &ignore, pos + 1, 1); | |
6549 | ||
6550 | /* Display it as active. */ | |
6551 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6552 | } | |
6553 | } | |
6554 | ||
6555 | /* Look for a `help-echo' property. */ | |
6556 | { | |
158cba56 | 6557 | Lisp_Object help, overlay; |
791f420f JR |
6558 | |
6559 | /* Check overlays first. */ | |
6560 | help = Qnil; | |
158cba56 JR |
6561 | for (i = noverlays - 1; i >= 0 && NILP (help); --i) |
6562 | { | |
6563 | overlay = overlay_vec[i]; | |
6564 | help = Foverlay_get (overlay, Qhelp_echo); | |
6565 | } | |
ec48c3a7 JR |
6566 | |
6567 | if (!NILP (help)) | |
6568 | { | |
6569 | help_echo = help; | |
158cba56 JR |
6570 | help_echo_window = window; |
6571 | help_echo_object = overlay; | |
ec48c3a7 JR |
6572 | help_echo_pos = pos; |
6573 | } | |
6574 | else | |
6575 | { | |
6576 | /* Try text properties. */ | |
6577 | if ((STRINGP (glyph->object) | |
791f420f JR |
6578 | && glyph->charpos >= 0 |
6579 | && glyph->charpos < XSTRING (glyph->object)->size) | |
6580 | || (BUFFERP (glyph->object) | |
6581 | && glyph->charpos >= BEGV | |
ec48c3a7 JR |
6582 | && glyph->charpos < ZV)) |
6583 | help = Fget_text_property (make_number (glyph->charpos), | |
6584 | Qhelp_echo, glyph->object); | |
791f420f | 6585 | |
ec48c3a7 JR |
6586 | if (!NILP (help)) |
6587 | { | |
6588 | help_echo = help; | |
158cba56 | 6589 | help_echo_window = window; |
ec48c3a7 JR |
6590 | help_echo_object = glyph->object; |
6591 | help_echo_pos = glyph->charpos; | |
6592 | } | |
6593 | } | |
791f420f JR |
6594 | } |
6595 | ||
6596 | BEGV = obegv; | |
6597 | ZV = ozv; | |
6598 | current_buffer = obuf; | |
6599 | } | |
6600 | } | |
6601 | } | |
6602 | ||
791f420f JR |
6603 | static void |
6604 | redo_mouse_highlight () | |
6605 | { | |
6606 | if (!NILP (last_mouse_motion_frame) | |
6607 | && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) | |
6608 | note_mouse_highlight (XFRAME (last_mouse_motion_frame), | |
6609 | LOWORD (last_mouse_motion_event.lParam), | |
6610 | HIWORD (last_mouse_motion_event.lParam)); | |
6611 | } | |
6612 | ||
6613 | ||
6614 | \f | |
6615 | /*********************************************************************** | |
6616 | Tool-bars | |
6617 | ***********************************************************************/ | |
6618 | ||
6619 | static int x_tool_bar_item P_ ((struct frame *, int, int, | |
6620 | struct glyph **, int *, int *, int *)); | |
6621 | ||
6622 | /* Tool-bar item index of the item on which a mouse button was pressed | |
6623 | or -1. */ | |
6624 | ||
6625 | static int last_tool_bar_item; | |
6626 | ||
6627 | ||
6628 | /* Get information about the tool-bar item at position X/Y on frame F. | |
6629 | Return in *GLYPH a pointer to the glyph of the tool-bar item in | |
6630 | the current matrix of the tool-bar window of F, or NULL if not | |
6631 | on a tool-bar item. Return in *PROP_IDX the index of the tool-bar | |
d417b5e0 | 6632 | item in F->tool_bar_items. Value is |
791f420f JR |
6633 | |
6634 | -1 if X/Y is not on a tool-bar item | |
6635 | 0 if X/Y is on the same item that was highlighted before. | |
6636 | 1 otherwise. */ | |
6637 | ||
6638 | static int | |
6639 | x_tool_bar_item (f, x, y, glyph, hpos, vpos, prop_idx) | |
6640 | struct frame *f; | |
6641 | int x, y; | |
6642 | struct glyph **glyph; | |
6643 | int *hpos, *vpos, *prop_idx; | |
6644 | { | |
6645 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6646 | struct window *w = XWINDOW (f->tool_bar_window); | |
6647 | int area; | |
6648 | ||
6649 | /* Find the glyph under X/Y. */ | |
6650 | *glyph = x_y_to_hpos_vpos (w, x, y, hpos, vpos, &area); | |
6651 | if (*glyph == NULL) | |
6652 | return -1; | |
6653 | ||
6654 | /* Get the start of this tool-bar item's properties in | |
d417b5e0 | 6655 | f->tool_bar_items. */ |
791f420f JR |
6656 | if (!tool_bar_item_info (f, *glyph, prop_idx)) |
6657 | return -1; | |
6658 | ||
6659 | /* Is mouse on the highlighted item? */ | |
6660 | if (EQ (f->tool_bar_window, dpyinfo->mouse_face_window) | |
6661 | && *vpos >= dpyinfo->mouse_face_beg_row | |
6662 | && *vpos <= dpyinfo->mouse_face_end_row | |
6663 | && (*vpos > dpyinfo->mouse_face_beg_row | |
6664 | || *hpos >= dpyinfo->mouse_face_beg_col) | |
6665 | && (*vpos < dpyinfo->mouse_face_end_row | |
6666 | || *hpos < dpyinfo->mouse_face_end_col | |
6667 | || dpyinfo->mouse_face_past_end)) | |
6668 | return 0; | |
6669 | ||
6670 | return 1; | |
6671 | } | |
6672 | ||
6673 | ||
9ef2e2cf | 6674 | /* Handle mouse button event on the tool-bar of frame F, at |
791f420f JR |
6675 | frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress |
6676 | or ButtonRelase. */ | |
6677 | ||
6678 | static void | |
6679 | w32_handle_tool_bar_click (f, button_event) | |
6680 | struct frame *f; | |
6681 | struct input_event *button_event; | |
6682 | { | |
6683 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6684 | struct window *w = XWINDOW (f->tool_bar_window); | |
6685 | int hpos, vpos, prop_idx; | |
6686 | struct glyph *glyph; | |
6687 | Lisp_Object enabled_p; | |
6688 | int x = XFASTINT (button_event->x); | |
6689 | int y = XFASTINT (button_event->y); | |
6690 | ||
6691 | /* If not on the highlighted tool-bar item, return. */ | |
6692 | frame_to_window_pixel_xy (w, &x, &y); | |
6693 | if (x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx) != 0) | |
6694 | return; | |
6695 | ||
6696 | /* If item is disabled, do nothing. */ | |
d417b5e0 | 6697 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
791f420f JR |
6698 | if (NILP (enabled_p)) |
6699 | return; | |
6700 | ||
6701 | if (button_event->kind == mouse_click) | |
6702 | { | |
6703 | /* Show item in pressed state. */ | |
6704 | show_mouse_face (dpyinfo, DRAW_IMAGE_SUNKEN); | |
6705 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_SUNKEN; | |
6706 | last_tool_bar_item = prop_idx; | |
6707 | } | |
6708 | else | |
6709 | { | |
6710 | Lisp_Object key, frame; | |
6711 | struct input_event event; | |
6712 | ||
6713 | /* Show item in released state. */ | |
6714 | show_mouse_face (dpyinfo, DRAW_IMAGE_RAISED); | |
6715 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_RAISED; | |
6716 | ||
d417b5e0 | 6717 | key = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_KEY); |
791f420f JR |
6718 | |
6719 | XSETFRAME (frame, f); | |
6720 | event.kind = TOOL_BAR_EVENT; | |
c8b33aa6 GM |
6721 | event.frame_or_window = frame; |
6722 | event.arg = frame; | |
791f420f JR |
6723 | kbd_buffer_store_event (&event); |
6724 | ||
6725 | event.kind = TOOL_BAR_EVENT; | |
c8b33aa6 GM |
6726 | event.frame_or_window = frame; |
6727 | event.arg = key; | |
791f420f JR |
6728 | event.modifiers = button_event->modifiers; |
6729 | kbd_buffer_store_event (&event); | |
6730 | last_tool_bar_item = -1; | |
6731 | } | |
6732 | } | |
6733 | ||
6734 | ||
9ef2e2cf | 6735 | /* Possibly highlight a tool-bar item on frame F when mouse moves to |
791f420f JR |
6736 | tool-bar window-relative coordinates X/Y. Called from |
6737 | note_mouse_highlight. */ | |
6738 | ||
6739 | static void | |
6740 | note_tool_bar_highlight (f, x, y) | |
6741 | struct frame *f; | |
6742 | int x, y; | |
6743 | { | |
6744 | Lisp_Object window = f->tool_bar_window; | |
6745 | struct window *w = XWINDOW (window); | |
6746 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
6747 | int hpos, vpos; | |
6748 | struct glyph *glyph; | |
6749 | struct glyph_row *row; | |
6750 | int i; | |
6751 | Lisp_Object enabled_p; | |
6752 | int prop_idx; | |
6753 | enum draw_glyphs_face draw = DRAW_IMAGE_RAISED; | |
6754 | int mouse_down_p, rc; | |
6755 | ||
6756 | /* Function note_mouse_highlight is called with negative x(y | |
6757 | values when mouse moves outside of the frame. */ | |
6758 | if (x <= 0 || y <= 0) | |
6759 | { | |
6760 | clear_mouse_face (dpyinfo); | |
6761 | return; | |
6762 | } | |
6763 | ||
6764 | rc = x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx); | |
6765 | if (rc < 0) | |
6766 | { | |
6767 | /* Not on tool-bar item. */ | |
6768 | clear_mouse_face (dpyinfo); | |
6769 | return; | |
6770 | } | |
6771 | else if (rc == 0) | |
6772 | /* On same tool-bar item as before. */ | |
6773 | goto set_help_echo; | |
ee78dc32 | 6774 | |
791f420f JR |
6775 | clear_mouse_face (dpyinfo); |
6776 | ||
6777 | /* Mouse is down, but on different tool-bar item? */ | |
6778 | mouse_down_p = (dpyinfo->grabbed | |
6779 | && f == last_mouse_frame | |
6780 | && FRAME_LIVE_P (f)); | |
6781 | if (mouse_down_p | |
6782 | && last_tool_bar_item != prop_idx) | |
6783 | return; | |
ee78dc32 | 6784 | |
791f420f JR |
6785 | dpyinfo->mouse_face_image_state = DRAW_NORMAL_TEXT; |
6786 | draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED; | |
6787 | ||
6788 | /* If tool-bar item is not enabled, don't highlight it. */ | |
d417b5e0 | 6789 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
791f420f JR |
6790 | if (!NILP (enabled_p)) |
6791 | { | |
6792 | /* Compute the x-position of the glyph. In front and past the | |
6793 | image is a space. We include this is the highlighted area. */ | |
6794 | row = MATRIX_ROW (w->current_matrix, vpos); | |
6795 | for (i = x = 0; i < hpos; ++i) | |
6796 | x += row->glyphs[TEXT_AREA][i].pixel_width; | |
6797 | ||
6798 | /* Record this as the current active region. */ | |
6799 | dpyinfo->mouse_face_beg_col = hpos; | |
6800 | dpyinfo->mouse_face_beg_row = vpos; | |
6801 | dpyinfo->mouse_face_beg_x = x; | |
6802 | dpyinfo->mouse_face_beg_y = row->y; | |
6803 | dpyinfo->mouse_face_past_end = 0; | |
6804 | ||
6805 | dpyinfo->mouse_face_end_col = hpos + 1; | |
6806 | dpyinfo->mouse_face_end_row = vpos; | |
6807 | dpyinfo->mouse_face_end_x = x + glyph->pixel_width; | |
6808 | dpyinfo->mouse_face_end_y = row->y; | |
6809 | dpyinfo->mouse_face_window = window; | |
6810 | dpyinfo->mouse_face_face_id = TOOL_BAR_FACE_ID; | |
6811 | ||
6812 | /* Display it as active. */ | |
6813 | show_mouse_face (dpyinfo, draw); | |
6814 | dpyinfo->mouse_face_image_state = draw; | |
ee78dc32 | 6815 | } |
791f420f JR |
6816 | |
6817 | set_help_echo: | |
6818 | ||
6819 | /* Set help_echo to a help string.to display for this tool-bar item. | |
6820 | w32_read_socket does the rest. */ | |
158cba56 | 6821 | help_echo_object = help_echo_window = Qnil; |
ec48c3a7 | 6822 | help_echo_pos = -1; |
d417b5e0 | 6823 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_HELP); |
b7e80413 | 6824 | if (NILP (help_echo)) |
d417b5e0 | 6825 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_CAPTION); |
ee78dc32 | 6826 | } |
ee78dc32 | 6827 | |
9ef2e2cf | 6828 | |
791f420f JR |
6829 | \f |
6830 | /* Find the glyph matrix position of buffer position POS in window W. | |
6831 | *HPOS, *VPOS, *X, and *Y are set to the positions found. W's | |
6832 | current glyphs must be up to date. If POS is above window start | |
6833 | return (0, 0, 0, 0). If POS is after end of W, return end of | |
6834 | last line in W. */ | |
ee78dc32 GV |
6835 | |
6836 | static int | |
791f420f JR |
6837 | fast_find_position (w, pos, hpos, vpos, x, y) |
6838 | struct window *w; | |
ee78dc32 | 6839 | int pos; |
791f420f | 6840 | int *hpos, *vpos, *x, *y; |
ee78dc32 | 6841 | { |
ee78dc32 | 6842 | int i; |
ee78dc32 | 6843 | int lastcol; |
791f420f JR |
6844 | int maybe_next_line_p = 0; |
6845 | int line_start_position; | |
6846 | int yb = window_text_bottom_y (w); | |
6847 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, 0); | |
6848 | struct glyph_row *best_row = row; | |
6849 | int row_vpos = 0, best_row_vpos = 0; | |
6850 | int current_x; | |
6851 | ||
6852 | while (row->y < yb) | |
ee78dc32 | 6853 | { |
791f420f JR |
6854 | if (row->used[TEXT_AREA]) |
6855 | line_start_position = row->glyphs[TEXT_AREA]->charpos; | |
6856 | else | |
6857 | line_start_position = 0; | |
6858 | ||
6859 | if (line_start_position > pos) | |
ee78dc32 GV |
6860 | break; |
6861 | /* If the position sought is the end of the buffer, | |
6862 | don't include the blank lines at the bottom of the window. */ | |
791f420f JR |
6863 | else if (line_start_position == pos |
6864 | && pos == BUF_ZV (XBUFFER (w->buffer))) | |
ee78dc32 | 6865 | { |
791f420f | 6866 | maybe_next_line_p = 1; |
ee78dc32 GV |
6867 | break; |
6868 | } | |
791f420f JR |
6869 | else if (line_start_position > 0) |
6870 | { | |
6871 | best_row = row; | |
6872 | best_row_vpos = row_vpos; | |
6873 | } | |
6874 | ||
9ef2e2cf JR |
6875 | if (row->y + row->height >= yb) |
6876 | break; | |
6877 | ||
791f420f JR |
6878 | ++row; |
6879 | ++row_vpos; | |
ee78dc32 GV |
6880 | } |
6881 | ||
791f420f JR |
6882 | /* Find the right column within BEST_ROW. */ |
6883 | lastcol = 0; | |
6884 | current_x = best_row->x; | |
6885 | for (i = 0; i < best_row->used[TEXT_AREA]; i++) | |
ee78dc32 | 6886 | { |
791f420f JR |
6887 | struct glyph *glyph = best_row->glyphs[TEXT_AREA] + i; |
6888 | int charpos; | |
6889 | ||
6890 | charpos = glyph->charpos; | |
6891 | if (charpos == pos) | |
ee78dc32 | 6892 | { |
791f420f JR |
6893 | *hpos = i; |
6894 | *vpos = best_row_vpos; | |
6895 | *x = current_x; | |
6896 | *y = best_row->y; | |
ee78dc32 GV |
6897 | return 1; |
6898 | } | |
791f420f | 6899 | else if (charpos > pos) |
ee78dc32 | 6900 | break; |
791f420f JR |
6901 | else if (charpos > 0) |
6902 | lastcol = i; | |
6903 | ||
6904 | current_x += glyph->pixel_width; | |
ee78dc32 GV |
6905 | } |
6906 | ||
6907 | /* If we're looking for the end of the buffer, | |
6908 | and we didn't find it in the line we scanned, | |
6909 | use the start of the following line. */ | |
791f420f | 6910 | if (maybe_next_line_p) |
ee78dc32 | 6911 | { |
791f420f JR |
6912 | ++best_row; |
6913 | ++best_row_vpos; | |
6914 | lastcol = 0; | |
6915 | current_x = best_row->x; | |
ee78dc32 GV |
6916 | } |
6917 | ||
791f420f JR |
6918 | *vpos = best_row_vpos; |
6919 | *hpos = lastcol + 1; | |
6920 | *x = current_x; | |
6921 | *y = best_row->y; | |
ee78dc32 GV |
6922 | return 0; |
6923 | } | |
6924 | ||
791f420f | 6925 | |
ee78dc32 GV |
6926 | /* Display the active region described by mouse_face_* |
6927 | in its mouse-face if HL > 0, in its normal face if HL = 0. */ | |
6928 | ||
6929 | static void | |
791f420f | 6930 | show_mouse_face (dpyinfo, draw) |
fbd6baed | 6931 | struct w32_display_info *dpyinfo; |
791f420f | 6932 | enum draw_glyphs_face draw; |
ee78dc32 GV |
6933 | { |
6934 | struct window *w = XWINDOW (dpyinfo->mouse_face_window); | |
791f420f | 6935 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
ee78dc32 | 6936 | int i; |
791f420f JR |
6937 | int cursor_off_p = 0; |
6938 | struct cursor_pos saved_cursor; | |
6939 | ||
6940 | saved_cursor = output_cursor; | |
6941 | ||
6942 | /* If window is in the process of being destroyed, don't bother | |
6943 | to do anything. */ | |
6944 | if (w->current_matrix == NULL) | |
6945 | goto set_x_cursor; | |
6946 | ||
6947 | /* Recognize when we are called to operate on rows that don't exist | |
6948 | anymore. This can happen when a window is split. */ | |
6949 | if (dpyinfo->mouse_face_end_row >= w->current_matrix->nrows) | |
6950 | goto set_x_cursor; | |
6951 | ||
6952 | set_output_cursor (&w->phys_cursor); | |
6953 | ||
6954 | /* Note that mouse_face_beg_row etc. are window relative. */ | |
6955 | for (i = dpyinfo->mouse_face_beg_row; | |
6956 | i <= dpyinfo->mouse_face_end_row; | |
6957 | i++) | |
6958 | { | |
6959 | int start_hpos, end_hpos, start_x; | |
6960 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, i); | |
6961 | ||
6962 | /* Don't do anything if row doesn't have valid contents. */ | |
6963 | if (!row->enabled_p) | |
6964 | continue; | |
6965 | ||
6966 | /* For all but the first row, the highlight starts at column 0. */ | |
6967 | if (i == dpyinfo->mouse_face_beg_row) | |
6968 | { | |
6969 | start_hpos = dpyinfo->mouse_face_beg_col; | |
6970 | start_x = dpyinfo->mouse_face_beg_x; | |
6971 | } | |
6972 | else | |
6973 | { | |
6974 | start_hpos = 0; | |
6975 | start_x = 0; | |
6976 | } | |
6977 | ||
6978 | if (i == dpyinfo->mouse_face_end_row) | |
6979 | end_hpos = dpyinfo->mouse_face_end_col; | |
6980 | else | |
6981 | end_hpos = row->used[TEXT_AREA]; | |
6982 | ||
6983 | /* If the cursor's in the text we are about to rewrite, turn the | |
6984 | cursor off. */ | |
6985 | if (!w->pseudo_window_p | |
6986 | && i == output_cursor.vpos | |
6987 | && output_cursor.hpos >= start_hpos - 1 | |
6988 | && output_cursor.hpos <= end_hpos) | |
ee78dc32 | 6989 | { |
791f420f JR |
6990 | x_update_window_cursor (w, 0); |
6991 | cursor_off_p = 1; | |
ee78dc32 GV |
6992 | } |
6993 | ||
791f420f | 6994 | if (end_hpos > start_hpos) |
ec48c3a7 JR |
6995 | { |
6996 | row->mouse_face_p = draw == DRAW_MOUSE_FACE; | |
6997 | x_draw_glyphs (w, start_x, row, TEXT_AREA, | |
6998 | start_hpos, end_hpos, draw, NULL, NULL, 0); | |
6999 | } | |
ee78dc32 GV |
7000 | } |
7001 | ||
7002 | /* If we turned the cursor off, turn it back on. */ | |
791f420f JR |
7003 | if (cursor_off_p) |
7004 | x_display_cursor (w, 1, | |
7005 | output_cursor.hpos, output_cursor.vpos, | |
7006 | output_cursor.x, output_cursor.y); | |
7007 | ||
7008 | output_cursor = saved_cursor; | |
7009 | ||
7010 | set_x_cursor: | |
01b220b6 | 7011 | #if 0 /* TODO: mouse cursor */ |
791f420f JR |
7012 | /* Change the mouse cursor. */ |
7013 | if (draw == DRAW_NORMAL_TEXT) | |
7014 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7015 | f->output_data.x->text_cursor); | |
7016 | else if (draw == DRAW_MOUSE_FACE) | |
7017 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7018 | f->output_data.x->cross_cursor); | |
ee78dc32 | 7019 | else |
791f420f JR |
7020 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7021 | f->output_data.x->nontext_cursor); | |
7022 | #endif | |
7023 | ; | |
ee78dc32 GV |
7024 | } |
7025 | ||
7026 | /* Clear out the mouse-highlighted active region. | |
9ef2e2cf | 7027 | Redraw it un-highlighted first. */ |
ee78dc32 | 7028 | |
791f420f | 7029 | void |
ee78dc32 | 7030 | clear_mouse_face (dpyinfo) |
fbd6baed | 7031 | struct w32_display_info *dpyinfo; |
ee78dc32 | 7032 | { |
25badd7a | 7033 | if (!NILP (tip_frame)) |
791f420f JR |
7034 | return; |
7035 | ||
ee78dc32 | 7036 | if (! NILP (dpyinfo->mouse_face_window)) |
791f420f | 7037 | show_mouse_face (dpyinfo, DRAW_NORMAL_TEXT); |
ee78dc32 GV |
7038 | |
7039 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7040 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7041 | dpyinfo->mouse_face_window = Qnil; | |
7042 | } | |
31d4844a | 7043 | |
ec48c3a7 JR |
7044 | |
7045 | /* Clear any mouse-face on window W. This function is part of the | |
7046 | redisplay interface, and is called from try_window_id and similar | |
7047 | functions to ensure the mouse-highlight is off. */ | |
7048 | ||
7049 | static void | |
7050 | x_clear_mouse_face (w) | |
7051 | struct window *w; | |
7052 | { | |
7053 | struct w32_display_info *dpyinfo | |
7054 | = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame)); | |
7055 | Lisp_Object window; | |
7056 | ||
9127e20e | 7057 | BLOCK_INPUT; |
ec48c3a7 JR |
7058 | XSETWINDOW (window, w); |
7059 | if (EQ (window, dpyinfo->mouse_face_window)) | |
7060 | clear_mouse_face (dpyinfo); | |
9127e20e | 7061 | UNBLOCK_INPUT; |
ec48c3a7 JR |
7062 | } |
7063 | ||
7064 | ||
31d4844a KH |
7065 | /* Just discard the mouse face information for frame F, if any. |
7066 | This is used when the size of F is changed. */ | |
7067 | ||
7068 | void | |
7069 | cancel_mouse_face (f) | |
7070 | FRAME_PTR f; | |
7071 | { | |
7072 | Lisp_Object window; | |
7073 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
7074 | ||
7075 | window = dpyinfo->mouse_face_window; | |
7076 | if (! NILP (window) && XFRAME (XWINDOW (window)->frame) == f) | |
7077 | { | |
7078 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7079 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7080 | dpyinfo->mouse_face_window = Qnil; | |
7081 | } | |
7082 | } | |
ee78dc32 | 7083 | \f |
9ef2e2cf | 7084 | static struct scroll_bar *x_window_to_scroll_bar (); |
ee78dc32 GV |
7085 | static void x_scroll_bar_report_motion (); |
7086 | ||
7087 | /* Return the current position of the mouse. | |
7088 | *fp should be a frame which indicates which display to ask about. | |
7089 | ||
7090 | If the mouse movement started in a scroll bar, set *fp, *bar_window, | |
7091 | and *part to the frame, window, and scroll bar part that the mouse | |
7092 | is over. Set *x and *y to the portion and whole of the mouse's | |
7093 | position on the scroll bar. | |
7094 | ||
7095 | If the mouse movement started elsewhere, set *fp to the frame the | |
7096 | mouse is on, *bar_window to nil, and *x and *y to the character cell | |
7097 | the mouse is over. | |
7098 | ||
9ef2e2cf | 7099 | Set *time to the server time-stamp for the time at which the mouse |
ee78dc32 GV |
7100 | was at this position. |
7101 | ||
7102 | Don't store anything if we don't have a valid set of values to report. | |
7103 | ||
7104 | This clears the mouse_moved flag, so we can wait for the next mouse | |
9ef2e2cf | 7105 | movement. */ |
ee78dc32 GV |
7106 | |
7107 | static void | |
fbd6baed | 7108 | w32_mouse_position (fp, insist, bar_window, part, x, y, time) |
ee78dc32 GV |
7109 | FRAME_PTR *fp; |
7110 | int insist; | |
7111 | Lisp_Object *bar_window; | |
7112 | enum scroll_bar_part *part; | |
7113 | Lisp_Object *x, *y; | |
7114 | unsigned long *time; | |
7115 | { | |
7116 | FRAME_PTR f1; | |
7117 | ||
7118 | BLOCK_INPUT; | |
7119 | ||
95fa970d | 7120 | if (! NILP (last_mouse_scroll_bar) && insist == 0) |
ee78dc32 GV |
7121 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); |
7122 | else | |
7123 | { | |
7124 | POINT pt; | |
7125 | ||
7126 | Lisp_Object frame, tail; | |
7127 | ||
7128 | /* Clear the mouse-moved flag for every frame on this display. */ | |
7129 | FOR_EACH_FRAME (tail, frame) | |
7130 | XFRAME (frame)->mouse_moved = 0; | |
7131 | ||
7132 | last_mouse_scroll_bar = Qnil; | |
7133 | ||
7134 | GetCursorPos (&pt); | |
7135 | ||
7136 | /* Now we have a position on the root; find the innermost window | |
7137 | containing the pointer. */ | |
7138 | { | |
fbd6baed | 7139 | if (FRAME_W32_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame |
ee78dc32 GV |
7140 | && FRAME_LIVE_P (last_mouse_frame)) |
7141 | { | |
08712a41 AI |
7142 | /* If mouse was grabbed on a frame, give coords for that frame |
7143 | even if the mouse is now outside it. */ | |
ee78dc32 GV |
7144 | f1 = last_mouse_frame; |
7145 | } | |
7146 | else | |
7147 | { | |
08712a41 | 7148 | /* Is window under mouse one of our frames? */ |
9127e20e JR |
7149 | f1 = x_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp), |
7150 | WindowFromPoint (pt)); | |
ee78dc32 GV |
7151 | } |
7152 | ||
7153 | /* If not, is it one of our scroll bars? */ | |
7154 | if (! f1) | |
7155 | { | |
9127e20e JR |
7156 | struct scroll_bar *bar |
7157 | = x_window_to_scroll_bar (WindowFromPoint (pt)); | |
ee78dc32 GV |
7158 | |
7159 | if (bar) | |
7160 | { | |
7161 | f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
7162 | } | |
7163 | } | |
7164 | ||
95fa970d | 7165 | if (f1 == 0 && insist > 0) |
791f420f | 7166 | f1 = SELECTED_FRAME (); |
ee78dc32 GV |
7167 | |
7168 | if (f1) | |
7169 | { | |
791f420f JR |
7170 | /* Ok, we found a frame. Store all the values. |
7171 | last_mouse_glyph is a rectangle used to reduce the | |
7172 | generation of mouse events. To not miss any motion | |
7173 | events, we must divide the frame into rectangles of the | |
7174 | size of the smallest character that could be displayed | |
7175 | on it, i.e. into the same rectangles that matrices on | |
7176 | the frame are divided into. */ | |
7177 | ||
7178 | #if OLD_REDISPLAY_CODE | |
ee78dc32 GV |
7179 | int ignore1, ignore2; |
7180 | ||
fbd6baed | 7181 | ScreenToClient (FRAME_W32_WINDOW (f1), &pt); |
ee78dc32 | 7182 | |
ee78dc32 GV |
7183 | pixel_to_glyph_coords (f1, pt.x, pt.y, &ignore1, &ignore2, |
7184 | &last_mouse_glyph, | |
fbd6baed | 7185 | FRAME_W32_DISPLAY_INFO (f1)->grabbed |
ee78dc32 | 7186 | || insist); |
791f420f JR |
7187 | #else |
7188 | ScreenToClient (FRAME_W32_WINDOW (f1), &pt); | |
7189 | { | |
7190 | int width = FRAME_SMALLEST_CHAR_WIDTH (f1); | |
7191 | int height = FRAME_SMALLEST_FONT_HEIGHT (f1); | |
7192 | int x = pt.x; | |
7193 | int y = pt.y; | |
7194 | ||
7195 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to | |
7196 | round down even for negative values. */ | |
7197 | if (x < 0) | |
7198 | x -= width - 1; | |
7199 | if (y < 0) | |
7200 | y -= height - 1; | |
7201 | ||
7202 | last_mouse_glyph.left = (x + width - 1) / width * width; | |
7203 | last_mouse_glyph.top = (y + height - 1) / height * height; | |
7204 | last_mouse_glyph.right = last_mouse_glyph.left + width; | |
7205 | last_mouse_glyph.bottom = last_mouse_glyph.top + height; | |
7206 | } | |
7207 | #endif | |
ee78dc32 GV |
7208 | |
7209 | *bar_window = Qnil; | |
7210 | *part = 0; | |
7211 | *fp = f1; | |
7212 | XSETINT (*x, pt.x); | |
7213 | XSETINT (*y, pt.y); | |
7214 | *time = last_mouse_movement_time; | |
7215 | } | |
7216 | } | |
7217 | } | |
7218 | ||
7219 | UNBLOCK_INPUT; | |
7220 | } | |
791f420f | 7221 | |
ee78dc32 GV |
7222 | \f |
7223 | /* Scroll bar support. */ | |
7224 | ||
ec48c3a7 | 7225 | /* Given a window ID, find the struct scroll_bar which manages it. |
ee78dc32 GV |
7226 | This can be called in GC, so we have to make sure to strip off mark |
7227 | bits. */ | |
9ef2e2cf JR |
7228 | |
7229 | static struct scroll_bar * | |
ee78dc32 GV |
7230 | x_window_to_scroll_bar (window_id) |
7231 | Window window_id; | |
7232 | { | |
791f420f | 7233 | Lisp_Object tail; |
ee78dc32 GV |
7234 | |
7235 | for (tail = Vframe_list; | |
7236 | XGCTYPE (tail) == Lisp_Cons; | |
8e713be6 | 7237 | tail = XCDR (tail)) |
ee78dc32 GV |
7238 | { |
7239 | Lisp_Object frame, bar, condemned; | |
7240 | ||
8e713be6 | 7241 | frame = XCAR (tail); |
ee78dc32 GV |
7242 | /* All elements of Vframe_list should be frames. */ |
7243 | if (! GC_FRAMEP (frame)) | |
7244 | abort (); | |
7245 | ||
7246 | /* Scan this frame's scroll bar list for a scroll bar with the | |
7247 | right window ID. */ | |
7248 | condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); | |
7249 | for (bar = FRAME_SCROLL_BARS (XFRAME (frame)); | |
7250 | /* This trick allows us to search both the ordinary and | |
7251 | condemned scroll bar lists with one loop. */ | |
7252 | ! GC_NILP (bar) || (bar = condemned, | |
7253 | condemned = Qnil, | |
7254 | ! GC_NILP (bar)); | |
7255 | bar = XSCROLL_BAR (bar)->next) | |
fbd6baed | 7256 | if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)) == window_id) |
ee78dc32 GV |
7257 | return XSCROLL_BAR (bar); |
7258 | } | |
7259 | ||
7260 | return 0; | |
7261 | } | |
7262 | ||
791f420f JR |
7263 | |
7264 | \f | |
7265 | /* Set the thumb size and position of scroll bar BAR. We are currently | |
7266 | displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
7267 | ||
7268 | static void | |
7269 | w32_set_scroll_bar_thumb (bar, portion, position, whole) | |
7270 | struct scroll_bar *bar; | |
7271 | int portion, position, whole; | |
7272 | { | |
7273 | Window w = SCROLL_BAR_W32_WINDOW (bar); | |
7274 | int range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | |
7275 | int sb_page, sb_pos; | |
7276 | BOOL draggingp = !NILP (bar->dragging) ? TRUE : FALSE; | |
7277 | ||
7278 | if (whole) | |
7279 | { | |
7280 | /* Position scroll bar at rock bottom if the bottom of the | |
7281 | buffer is visible. This avoids shinking the thumb away | |
7282 | to nothing if it is held at the bottom of the buffer. */ | |
7283 | if (position + portion >= whole) | |
7284 | { | |
7285 | sb_page = range * (whole - position) / whole | |
7286 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
7287 | sb_pos = range; | |
7288 | } | |
7289 | ||
7290 | sb_page = portion * range / whole + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
7291 | sb_pos = position * range / whole; | |
7292 | } | |
7293 | else | |
7294 | { | |
7295 | sb_page = range; | |
7296 | sb_pos = 0; | |
7297 | } | |
7298 | ||
7299 | BLOCK_INPUT; | |
7300 | ||
7301 | if (pfnSetScrollInfo) | |
7302 | { | |
7303 | SCROLLINFO si; | |
7304 | ||
7305 | si.cbSize = sizeof (si); | |
7306 | /* Only update page size if currently dragging, to reduce | |
7307 | flicker effects. */ | |
7308 | if (draggingp) | |
7309 | si.fMask = SIF_PAGE; | |
7310 | else | |
7311 | si.fMask = SIF_PAGE | SIF_POS; | |
7312 | si.nPage = sb_page; | |
7313 | si.nPos = sb_pos; | |
7314 | ||
7315 | pfnSetScrollInfo (w, SB_CTL, &si, !draggingp); | |
7316 | } | |
7317 | else | |
7318 | SetScrollPos (w, SB_CTL, sb_pos, !draggingp); | |
7319 | ||
7320 | UNBLOCK_INPUT; | |
7321 | } | |
7322 | ||
7323 | \f | |
7324 | /************************************************************************ | |
7325 | Scroll bars, general | |
7326 | ************************************************************************/ | |
7327 | ||
ee78dc32 GV |
7328 | HWND |
7329 | my_create_scrollbar (f, bar) | |
7330 | struct frame * f; | |
7331 | struct scroll_bar * bar; | |
7332 | { | |
689004fa GV |
7333 | return (HWND) SendMessage (FRAME_W32_WINDOW (f), |
7334 | WM_EMACS_CREATESCROLLBAR, (WPARAM) f, | |
7335 | (LPARAM) bar); | |
ee78dc32 GV |
7336 | } |
7337 | ||
52cf03a1 GV |
7338 | //#define ATTACH_THREADS |
7339 | ||
689004fa GV |
7340 | BOOL |
7341 | my_show_window (FRAME_PTR f, HWND hwnd, int how) | |
52cf03a1 GV |
7342 | { |
7343 | #ifndef ATTACH_THREADS | |
689004fa GV |
7344 | return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW, |
7345 | (WPARAM) hwnd, (LPARAM) how); | |
52cf03a1 | 7346 | #else |
689004fa | 7347 | return ShowWindow (hwnd, how); |
52cf03a1 GV |
7348 | #endif |
7349 | } | |
7350 | ||
7351 | void | |
7352 | my_set_window_pos (HWND hwnd, HWND hwndAfter, | |
689004fa | 7353 | int x, int y, int cx, int cy, UINT flags) |
52cf03a1 GV |
7354 | { |
7355 | #ifndef ATTACH_THREADS | |
689004fa GV |
7356 | WINDOWPOS pos; |
7357 | pos.hwndInsertAfter = hwndAfter; | |
52cf03a1 GV |
7358 | pos.x = x; |
7359 | pos.y = y; | |
7360 | pos.cx = cx; | |
7361 | pos.cy = cy; | |
7362 | pos.flags = flags; | |
7363 | SendMessage (hwnd, WM_EMACS_SETWINDOWPOS, (WPARAM) &pos, 0); | |
7364 | #else | |
7365 | SetWindowPos (hwnd, hwndAfter, x, y, cx, cy, flags); | |
7366 | #endif | |
7367 | } | |
7368 | ||
ec48c3a7 | 7369 | void |
689004fa GV |
7370 | my_set_focus (f, hwnd) |
7371 | struct frame * f; | |
7372 | HWND hwnd; | |
7373 | { | |
7374 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SETFOCUS, | |
7375 | (WPARAM) hwnd, 0); | |
7376 | } | |
7377 | ||
ec48c3a7 | 7378 | void |
ef0e360f GV |
7379 | my_set_foreground_window (hwnd) |
7380 | HWND hwnd; | |
7381 | { | |
7382 | SendMessage (hwnd, WM_EMACS_SETFOREGROUND, (WPARAM) hwnd, 0); | |
7383 | } | |
7384 | ||
ee78dc32 GV |
7385 | void |
7386 | my_destroy_window (f, hwnd) | |
7387 | struct frame * f; | |
7388 | HWND hwnd; | |
7389 | { | |
fbd6baed | 7390 | SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_DESTROYWINDOW, |
ee78dc32 GV |
7391 | (WPARAM) hwnd, 0); |
7392 | } | |
7393 | ||
791f420f JR |
7394 | /* Create a scroll bar and return the scroll bar vector for it. W is |
7395 | the Emacs window on which to create the scroll bar. TOP, LEFT, | |
7396 | WIDTH and HEIGHT are.the pixel coordinates and dimensions of the | |
7397 | scroll bar. */ | |
7398 | ||
ee78dc32 | 7399 | static struct scroll_bar * |
791f420f JR |
7400 | x_scroll_bar_create (w, top, left, width, height) |
7401 | struct window *w; | |
ee78dc32 GV |
7402 | int top, left, width, height; |
7403 | { | |
791f420f JR |
7404 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
7405 | HWND hwnd; | |
ee78dc32 GV |
7406 | struct scroll_bar *bar |
7407 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | |
ee78dc32 GV |
7408 | |
7409 | BLOCK_INPUT; | |
7410 | ||
791f420f | 7411 | XSETWINDOW (bar->window, w); |
ee78dc32 GV |
7412 | XSETINT (bar->top, top); |
7413 | XSETINT (bar->left, left); | |
7414 | XSETINT (bar->width, width); | |
7415 | XSETINT (bar->height, height); | |
7416 | XSETINT (bar->start, 0); | |
7417 | XSETINT (bar->end, 0); | |
7418 | bar->dragging = Qnil; | |
7419 | ||
7420 | /* Requires geometry to be set before call to create the real window */ | |
7421 | ||
7422 | hwnd = my_create_scrollbar (f, bar); | |
7423 | ||
689004fa GV |
7424 | if (pfnSetScrollInfo) |
7425 | { | |
7426 | SCROLLINFO si; | |
7427 | ||
7428 | si.cbSize = sizeof (si); | |
7429 | si.fMask = SIF_ALL; | |
7430 | si.nMin = 0; | |
791f420f JR |
7431 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) |
7432 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
689004fa GV |
7433 | si.nPage = si.nMax; |
7434 | si.nPos = 0; | |
7435 | ||
7436 | pfnSetScrollInfo (hwnd, SB_CTL, &si, FALSE); | |
7437 | } | |
7438 | else | |
7439 | { | |
791f420f JR |
7440 | SetScrollRange (hwnd, SB_CTL, 0, |
7441 | VERTICAL_SCROLL_BAR_TOP_RANGE (f, height), FALSE); | |
689004fa GV |
7442 | SetScrollPos (hwnd, SB_CTL, 0, FALSE); |
7443 | } | |
ee78dc32 | 7444 | |
fbd6baed | 7445 | SET_SCROLL_BAR_W32_WINDOW (bar, hwnd); |
ee78dc32 GV |
7446 | |
7447 | /* Add bar to its frame's list of scroll bars. */ | |
7448 | bar->next = FRAME_SCROLL_BARS (f); | |
7449 | bar->prev = Qnil; | |
7450 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
7451 | if (! NILP (bar->next)) | |
7452 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
7453 | ||
7454 | UNBLOCK_INPUT; | |
7455 | ||
7456 | return bar; | |
7457 | } | |
7458 | ||
ee78dc32 | 7459 | |
791f420f JR |
7460 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to |
7461 | nil. */ | |
ee78dc32 | 7462 | |
ee78dc32 GV |
7463 | static void |
7464 | x_scroll_bar_remove (bar) | |
7465 | struct scroll_bar *bar; | |
7466 | { | |
7467 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
7468 | ||
7469 | BLOCK_INPUT; | |
7470 | ||
7471 | /* Destroy the window. */ | |
fbd6baed | 7472 | my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar)); |
ee78dc32 GV |
7473 | |
7474 | /* Disassociate this scroll bar from its window. */ | |
7475 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | |
7476 | ||
7477 | UNBLOCK_INPUT; | |
7478 | } | |
7479 | ||
7480 | /* Set the handle of the vertical scroll bar for WINDOW to indicate | |
7481 | that we are displaying PORTION characters out of a total of WHOLE | |
7482 | characters, starting at POSITION. If WINDOW has no scroll bar, | |
7483 | create one. */ | |
7484 | static void | |
791f420f JR |
7485 | w32_set_vertical_scroll_bar (w, portion, whole, position) |
7486 | struct window *w; | |
ee78dc32 GV |
7487 | int portion, whole, position; |
7488 | { | |
791f420f | 7489 | struct frame *f = XFRAME (w->frame); |
ee78dc32 | 7490 | struct scroll_bar *bar; |
9ef2e2cf | 7491 | int top, height, left, sb_left, width, sb_width; |
791f420f JR |
7492 | int window_x, window_y, window_width, window_height; |
7493 | ||
7494 | /* Get window dimensions. */ | |
7495 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); | |
7496 | top = window_y; | |
7497 | width = FRAME_SCROLL_BAR_COLS (f) * CANON_X_UNIT (f); | |
7498 | height = window_height; | |
7499 | ||
7500 | /* Compute the left edge of the scroll bar area. */ | |
7501 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
7502 | left = XINT (w->left) + XINT (w->width) - FRAME_SCROLL_BAR_COLS (f); | |
7503 | else | |
7504 | left = XFASTINT (w->left); | |
7505 | left *= CANON_X_UNIT (f); | |
7506 | left += FRAME_INTERNAL_BORDER_WIDTH (f); | |
7507 | ||
7508 | /* Compute the width of the scroll bar which might be less than | |
7509 | the width of the area reserved for the scroll bar. */ | |
7510 | if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0) | |
7511 | sb_width = FRAME_SCROLL_BAR_PIXEL_WIDTH (f); | |
7512 | else | |
7513 | sb_width = width; | |
ee78dc32 | 7514 | |
791f420f JR |
7515 | /* Compute the left edge of the scroll bar. */ |
7516 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
7517 | sb_left = left + width - sb_width - (width - sb_width) / 2; | |
ee78dc32 | 7518 | else |
791f420f JR |
7519 | sb_left = left + (width - sb_width) / 2; |
7520 | ||
7521 | /* Does the scroll bar exist yet? */ | |
7522 | if (NILP (w->vertical_scroll_bar)) | |
ee78dc32 | 7523 | { |
00fe468b | 7524 | HDC hdc; |
791f420f | 7525 | BLOCK_INPUT; |
00fe468b JR |
7526 | hdc = get_frame_dc (f); |
7527 | w32_clear_area (f, hdc, left, top, width, height); | |
7528 | release_frame_dc (f, hdc); | |
791f420f | 7529 | UNBLOCK_INPUT; |
00fe468b | 7530 | |
791f420f | 7531 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); |
ee78dc32 | 7532 | } |
791f420f JR |
7533 | else |
7534 | { | |
7535 | /* It may just need to be moved and resized. */ | |
7536 | HWND hwnd; | |
7537 | ||
7538 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | |
7539 | hwnd = SCROLL_BAR_W32_WINDOW (bar); | |
7540 | ||
7541 | /* If already correctly positioned, do nothing. */ | |
7542 | if ( XINT (bar->left) == sb_left | |
7543 | && XINT (bar->top) == top | |
7544 | && XINT (bar->width) == sb_width | |
7545 | && XINT (bar->height) == height ) | |
7546 | { | |
7547 | /* Redraw after clear_frame. */ | |
7548 | if (!my_show_window (f, hwnd, SW_NORMAL)) | |
7549 | InvalidateRect (hwnd, NULL, FALSE); | |
7550 | } | |
7551 | else | |
7552 | { | |
00fe468b | 7553 | HDC hdc; |
791f420f JR |
7554 | BLOCK_INPUT; |
7555 | ||
00fe468b | 7556 | hdc = get_frame_dc (f); |
791f420f JR |
7557 | /* Since Windows scroll bars are smaller than the space reserved |
7558 | for them on the frame, we have to clear "under" them. */ | |
00fe468b | 7559 | w32_clear_area (f, hdc, |
791f420f JR |
7560 | left, |
7561 | top, | |
7562 | width, | |
7563 | height); | |
00fe468b | 7564 | release_frame_dc (f, hdc); |
791f420f JR |
7565 | |
7566 | /* Make sure scroll bar is "visible" before moving, to ensure the | |
7567 | area of the parent window now exposed will be refreshed. */ | |
7568 | my_show_window (f, hwnd, SW_HIDE); | |
7569 | MoveWindow (hwnd, sb_left, top, | |
7570 | sb_width, height, TRUE); | |
7571 | if (pfnSetScrollInfo) | |
7572 | { | |
7573 | SCROLLINFO si; | |
ee78dc32 | 7574 | |
791f420f JR |
7575 | si.cbSize = sizeof (si); |
7576 | si.fMask = SIF_RANGE; | |
7577 | si.nMin = 0; | |
7578 | si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height) | |
7579 | + VERTICAL_SCROLL_BAR_MIN_HANDLE; | |
ee78dc32 | 7580 | |
00fe468b | 7581 | pfnSetScrollInfo (hwnd, SB_CTL, &si, FALSE); |
791f420f JR |
7582 | } |
7583 | else | |
00fe468b | 7584 | SetScrollRange (hwnd, SB_CTL, 0, |
791f420f JR |
7585 | VERTICAL_SCROLL_BAR_TOP_RANGE (f, height), FALSE); |
7586 | my_show_window (f, hwnd, SW_NORMAL); | |
7587 | // InvalidateRect (w, NULL, FALSE); | |
7588 | ||
7589 | /* Remember new settings. */ | |
7590 | XSETINT (bar->left, sb_left); | |
7591 | XSETINT (bar->top, top); | |
7592 | XSETINT (bar->width, sb_width); | |
7593 | XSETINT (bar->height, height); | |
7594 | ||
7595 | UNBLOCK_INPUT; | |
7596 | } | |
7597 | } | |
7598 | w32_set_scroll_bar_thumb (bar, portion, position, whole); | |
ee78dc32 | 7599 | |
791f420f | 7600 | XSETVECTOR (w->vertical_scroll_bar, bar); |
ee78dc32 GV |
7601 | } |
7602 | ||
7603 | ||
7604 | /* The following three hooks are used when we're doing a thorough | |
7605 | redisplay of the frame. We don't explicitly know which scroll bars | |
7606 | are going to be deleted, because keeping track of when windows go | |
7607 | away is a real pain - "Can you say set-window-configuration, boys | |
7608 | and girls?" Instead, we just assert at the beginning of redisplay | |
7609 | that *all* scroll bars are to be removed, and then save a scroll bar | |
7610 | from the fiery pit when we actually redisplay its window. */ | |
7611 | ||
7612 | /* Arrange for all scroll bars on FRAME to be removed at the next call | |
7613 | to `*judge_scroll_bars_hook'. A scroll bar may be spared if | |
9ef2e2cf JR |
7614 | `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ |
7615 | ||
ee78dc32 | 7616 | static void |
fbd6baed | 7617 | w32_condemn_scroll_bars (frame) |
ee78dc32 GV |
7618 | FRAME_PTR frame; |
7619 | { | |
ef0e360f GV |
7620 | /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ |
7621 | while (! NILP (FRAME_SCROLL_BARS (frame))) | |
7622 | { | |
7623 | Lisp_Object bar; | |
7624 | bar = FRAME_SCROLL_BARS (frame); | |
7625 | FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next; | |
7626 | XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame); | |
7627 | XSCROLL_BAR (bar)->prev = Qnil; | |
7628 | if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame))) | |
7629 | XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar; | |
7630 | FRAME_CONDEMNED_SCROLL_BARS (frame) = bar; | |
7631 | } | |
ee78dc32 GV |
7632 | } |
7633 | ||
9ef2e2cf | 7634 | /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle. |
ee78dc32 GV |
7635 | Note that WINDOW isn't necessarily condemned at all. */ |
7636 | static void | |
fbd6baed | 7637 | w32_redeem_scroll_bar (window) |
ee78dc32 GV |
7638 | struct window *window; |
7639 | { | |
7640 | struct scroll_bar *bar; | |
7641 | ||
7642 | /* We can't redeem this window's scroll bar if it doesn't have one. */ | |
7643 | if (NILP (window->vertical_scroll_bar)) | |
7644 | abort (); | |
7645 | ||
7646 | bar = XSCROLL_BAR (window->vertical_scroll_bar); | |
7647 | ||
ef0e360f GV |
7648 | /* Unlink it from the condemned list. */ |
7649 | { | |
7650 | FRAME_PTR f = XFRAME (WINDOW_FRAME (window)); | |
7651 | ||
7652 | if (NILP (bar->prev)) | |
7653 | { | |
7654 | /* If the prev pointer is nil, it must be the first in one of | |
7655 | the lists. */ | |
7656 | if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar)) | |
7657 | /* It's not condemned. Everything's fine. */ | |
7658 | return; | |
7659 | else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f), | |
7660 | window->vertical_scroll_bar)) | |
7661 | FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next; | |
7662 | else | |
7663 | /* If its prev pointer is nil, it must be at the front of | |
7664 | one or the other! */ | |
7665 | abort (); | |
7666 | } | |
7667 | else | |
7668 | XSCROLL_BAR (bar->prev)->next = bar->next; | |
7669 | ||
7670 | if (! NILP (bar->next)) | |
7671 | XSCROLL_BAR (bar->next)->prev = bar->prev; | |
7672 | ||
7673 | bar->next = FRAME_SCROLL_BARS (f); | |
7674 | bar->prev = Qnil; | |
7675 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
7676 | if (! NILP (bar->next)) | |
7677 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
7678 | } | |
ee78dc32 GV |
7679 | } |
7680 | ||
7681 | /* Remove all scroll bars on FRAME that haven't been saved since the | |
7682 | last call to `*condemn_scroll_bars_hook'. */ | |
9ef2e2cf | 7683 | |
ee78dc32 | 7684 | static void |
fbd6baed | 7685 | w32_judge_scroll_bars (f) |
ee78dc32 GV |
7686 | FRAME_PTR f; |
7687 | { | |
7688 | Lisp_Object bar, next; | |
7689 | ||
7690 | bar = FRAME_CONDEMNED_SCROLL_BARS (f); | |
7691 | ||
7692 | /* Clear out the condemned list now so we won't try to process any | |
7693 | more events on the hapless scroll bars. */ | |
7694 | FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil; | |
7695 | ||
7696 | for (; ! NILP (bar); bar = next) | |
7697 | { | |
7698 | struct scroll_bar *b = XSCROLL_BAR (bar); | |
7699 | ||
7700 | x_scroll_bar_remove (b); | |
7701 | ||
7702 | next = b->next; | |
7703 | b->next = b->prev = Qnil; | |
7704 | } | |
7705 | ||
7706 | /* Now there should be no references to the condemned scroll bars, | |
7707 | and they should get garbage-collected. */ | |
7708 | } | |
7709 | ||
7710 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind | |
7711 | is set to something other than no_event, it is enqueued. | |
7712 | ||
7713 | This may be called from a signal handler, so we have to ignore GC | |
7714 | mark bits. */ | |
2c28562d | 7715 | |
52cf03a1 | 7716 | static int |
ee78dc32 GV |
7717 | x_scroll_bar_handle_click (bar, msg, emacs_event) |
7718 | struct scroll_bar *bar; | |
fbd6baed | 7719 | W32Msg *msg; |
ee78dc32 GV |
7720 | struct input_event *emacs_event; |
7721 | { | |
7722 | if (! GC_WINDOWP (bar->window)) | |
7723 | abort (); | |
7724 | ||
fbd6baed | 7725 | emacs_event->kind = w32_scroll_bar_click; |
ee78dc32 | 7726 | emacs_event->code = 0; |
52cf03a1 GV |
7727 | /* not really meaningful to distinguish up/down */ |
7728 | emacs_event->modifiers = msg->dwModifiers; | |
ee78dc32 | 7729 | emacs_event->frame_or_window = bar->window; |
7e889510 | 7730 | emacs_event->arg = Qnil; |
ee78dc32 GV |
7731 | emacs_event->timestamp = msg->msg.time; |
7732 | ||
7733 | { | |
791f420f | 7734 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
689004fa GV |
7735 | int y; |
7736 | int dragging = !NILP (bar->dragging); | |
7737 | ||
7738 | if (pfnGetScrollInfo) | |
7739 | { | |
7740 | SCROLLINFO si; | |
7741 | ||
7742 | si.cbSize = sizeof (si); | |
7743 | si.fMask = SIF_POS; | |
7744 | ||
7745 | pfnGetScrollInfo ((HWND) msg->msg.lParam, SB_CTL, &si); | |
7746 | y = si.nPos; | |
7747 | } | |
7748 | else | |
7749 | y = GetScrollPos ((HWND) msg->msg.lParam, SB_CTL); | |
7750 | ||
7751 | bar->dragging = Qnil; | |
ee78dc32 | 7752 | |
9ef2e2cf JR |
7753 | |
7754 | last_mouse_scroll_bar_pos = msg->msg.wParam; | |
7755 | ||
ee78dc32 | 7756 | switch (LOWORD (msg->msg.wParam)) |
2c28562d | 7757 | { |
2c28562d | 7758 | case SB_LINEDOWN: |
52cf03a1 | 7759 | emacs_event->part = scroll_bar_down_arrow; |
ee78dc32 | 7760 | break; |
2c28562d | 7761 | case SB_LINEUP: |
52cf03a1 | 7762 | emacs_event->part = scroll_bar_up_arrow; |
ee78dc32 | 7763 | break; |
2c28562d | 7764 | case SB_PAGEUP: |
ee78dc32 GV |
7765 | emacs_event->part = scroll_bar_above_handle; |
7766 | break; | |
2c28562d | 7767 | case SB_PAGEDOWN: |
ee78dc32 GV |
7768 | emacs_event->part = scroll_bar_below_handle; |
7769 | break; | |
2c28562d | 7770 | case SB_TOP: |
ee78dc32 GV |
7771 | emacs_event->part = scroll_bar_handle; |
7772 | y = 0; | |
7773 | break; | |
2c28562d | 7774 | case SB_BOTTOM: |
ee78dc32 GV |
7775 | emacs_event->part = scroll_bar_handle; |
7776 | y = top_range; | |
7777 | break; | |
689004fa | 7778 | case SB_THUMBTRACK: |
2c28562d | 7779 | case SB_THUMBPOSITION: |
791f420f JR |
7780 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
7781 | y = HIWORD (msg->msg.wParam); | |
689004fa | 7782 | bar->dragging = Qt; |
ee78dc32 | 7783 | emacs_event->part = scroll_bar_handle; |
689004fa GV |
7784 | |
7785 | /* "Silently" update current position. */ | |
7786 | if (pfnSetScrollInfo) | |
7787 | { | |
7788 | SCROLLINFO si; | |
7789 | ||
7790 | si.cbSize = sizeof (si); | |
7791 | si.fMask = SIF_POS; | |
689004fa GV |
7792 | si.nPos = y; |
7793 | /* Remember apparent position (we actually lag behind the real | |
7794 | position, so don't set that directly. */ | |
7795 | last_scroll_bar_drag_pos = y; | |
7796 | ||
7797 | pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, FALSE); | |
7798 | } | |
7799 | else | |
7800 | SetScrollPos (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, y, FALSE); | |
ee78dc32 | 7801 | break; |
2c28562d | 7802 | case SB_ENDSCROLL: |
689004fa GV |
7803 | /* If this is the end of a drag sequence, then reset the scroll |
7804 | handle size to normal and do a final redraw. Otherwise do | |
7805 | nothing. */ | |
7806 | if (dragging) | |
7807 | { | |
7808 | if (pfnSetScrollInfo) | |
7809 | { | |
7810 | SCROLLINFO si; | |
7811 | int start = XINT (bar->start); | |
7812 | int end = XINT (bar->end); | |
7813 | ||
7814 | si.cbSize = sizeof (si); | |
7815 | si.fMask = SIF_PAGE | SIF_POS; | |
791f420f | 7816 | si.nPage = end - start + VERTICAL_SCROLL_BAR_MIN_HANDLE; |
689004fa | 7817 | si.nPos = last_scroll_bar_drag_pos; |
689004fa GV |
7818 | pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, TRUE); |
7819 | } | |
7820 | else | |
7821 | SetScrollPos (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, y, TRUE); | |
7822 | } | |
7823 | /* fall through */ | |
2c28562d | 7824 | default: |
689004fa | 7825 | emacs_event->kind = no_event; |
52cf03a1 | 7826 | return FALSE; |
2c28562d | 7827 | } |
52cf03a1 | 7828 | |
ee78dc32 GV |
7829 | XSETINT (emacs_event->x, y); |
7830 | XSETINT (emacs_event->y, top_range); | |
52cf03a1 GV |
7831 | |
7832 | return TRUE; | |
ee78dc32 GV |
7833 | } |
7834 | } | |
7835 | ||
7836 | /* Return information to the user about the current position of the mouse | |
7837 | on the scroll bar. */ | |
9ef2e2cf | 7838 | |
ee78dc32 GV |
7839 | static void |
7840 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) | |
7841 | FRAME_PTR *fp; | |
7842 | Lisp_Object *bar_window; | |
7843 | enum scroll_bar_part *part; | |
7844 | Lisp_Object *x, *y; | |
7845 | unsigned long *time; | |
7846 | { | |
7847 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); | |
fbd6baed | 7848 | Window w = SCROLL_BAR_W32_WINDOW (bar); |
ee78dc32 GV |
7849 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
7850 | int pos; | |
791f420f | 7851 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
ee78dc32 GV |
7852 | |
7853 | BLOCK_INPUT; | |
7854 | ||
7855 | *fp = f; | |
7856 | *bar_window = bar->window; | |
7857 | ||
689004fa GV |
7858 | if (pfnGetScrollInfo) |
7859 | { | |
7860 | SCROLLINFO si; | |
7861 | ||
7862 | si.cbSize = sizeof (si); | |
7863 | si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; | |
7864 | ||
7865 | pfnGetScrollInfo (w, SB_CTL, &si); | |
7866 | pos = si.nPos; | |
7867 | top_range = si.nMax - si.nPage + 1; | |
7868 | } | |
7869 | else | |
7870 | pos = GetScrollPos (w, SB_CTL); | |
ee78dc32 GV |
7871 | |
7872 | switch (LOWORD (last_mouse_scroll_bar_pos)) | |
7873 | { | |
7874 | case SB_THUMBPOSITION: | |
7875 | case SB_THUMBTRACK: | |
7876 | *part = scroll_bar_handle; | |
791f420f | 7877 | if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff) |
ee78dc32 GV |
7878 | pos = HIWORD (last_mouse_scroll_bar_pos); |
7879 | break; | |
7880 | case SB_LINEDOWN: | |
7881 | *part = scroll_bar_handle; | |
7882 | pos++; | |
7883 | break; | |
7884 | default: | |
7885 | *part = scroll_bar_handle; | |
7886 | break; | |
7887 | } | |
7888 | ||
9127e20e JR |
7889 | XSETINT (*x, pos); |
7890 | XSETINT (*y, top_range); | |
ee78dc32 GV |
7891 | |
7892 | f->mouse_moved = 0; | |
7893 | last_mouse_scroll_bar = Qnil; | |
7894 | ||
7895 | *time = last_mouse_movement_time; | |
7896 | ||
7897 | UNBLOCK_INPUT; | |
7898 | } | |
7899 | ||
9ef2e2cf | 7900 | |
ee78dc32 GV |
7901 | /* The screen has been cleared so we may have changed foreground or |
7902 | background colors, and the scroll bars may need to be redrawn. | |
7903 | Clear out the scroll bars, and ask for expose events, so we can | |
7904 | redraw them. */ | |
9ef2e2cf | 7905 | |
791f420f | 7906 | void |
ee78dc32 | 7907 | x_scroll_bar_clear (f) |
9ef2e2cf | 7908 | FRAME_PTR f; |
ee78dc32 | 7909 | { |
ee78dc32 GV |
7910 | Lisp_Object bar; |
7911 | ||
9ef2e2cf JR |
7912 | /* We can have scroll bars even if this is 0, |
7913 | if we just turned off scroll bar mode. | |
7914 | But in that case we should not clear them. */ | |
7915 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
7916 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
7917 | bar = XSCROLL_BAR (bar)->next) | |
7918 | { | |
7919 | HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)); | |
7920 | HDC hdc = GetDC (window); | |
7921 | RECT rect; | |
52cf03a1 | 7922 | |
9ef2e2cf JR |
7923 | /* Hide scroll bar until ready to repaint. x_scroll_bar_move |
7924 | arranges to refresh the scroll bar if hidden. */ | |
7925 | my_show_window (f, window, SW_HIDE); | |
689004fa | 7926 | |
9ef2e2cf JR |
7927 | GetClientRect (window, &rect); |
7928 | select_palette (f, hdc); | |
7929 | w32_clear_rect (f, hdc, &rect); | |
7930 | deselect_palette (f, hdc); | |
689004fa | 7931 | |
9ef2e2cf JR |
7932 | ReleaseDC (window, hdc); |
7933 | } | |
52cf03a1 GV |
7934 | } |
7935 | ||
7936 | show_scroll_bars (f, how) | |
7937 | FRAME_PTR f; | |
7938 | int how; | |
7939 | { | |
7940 | Lisp_Object bar; | |
7941 | ||
7942 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
7943 | bar = XSCROLL_BAR (bar)->next) | |
7944 | { | |
fbd6baed | 7945 | HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)); |
689004fa | 7946 | my_show_window (f, window, how); |
52cf03a1 | 7947 | } |
ee78dc32 GV |
7948 | } |
7949 | ||
7950 | \f | |
fbd6baed | 7951 | /* The main W32 event-reading loop - w32_read_socket. */ |
ee78dc32 | 7952 | |
9ef2e2cf | 7953 | /* Time stamp of enter window event. This is only used by w32_read_socket, |
ee78dc32 GV |
7954 | but we have to put it out here, since static variables within functions |
7955 | sometimes don't work. */ | |
9ef2e2cf | 7956 | |
ee78dc32 GV |
7957 | static Time enter_timestamp; |
7958 | ||
7959 | /* Record the last 100 characters stored | |
7960 | to help debug the loss-of-chars-during-GC problem. */ | |
9ef2e2cf JR |
7961 | |
7962 | static int temp_index; | |
7963 | static short temp_buffer[100]; | |
ee78dc32 | 7964 | |
afd153f0 | 7965 | |
fbd6baed | 7966 | /* Read events coming from the W32 shell. |
ee78dc32 GV |
7967 | This routine is called by the SIGIO handler. |
7968 | We return as soon as there are no more events to be read. | |
7969 | ||
7970 | Events representing keys are stored in buffer BUFP, | |
7971 | which can hold up to NUMCHARS characters. | |
7972 | We return the number of characters stored into the buffer, | |
7973 | thus pretending to be `read'. | |
7974 | ||
ee78dc32 GV |
7975 | EXPECTED is nonzero if the caller knows input is available. |
7976 | ||
7977 | Some of these messages are reposted back to the message queue since the | |
e9e23e23 GV |
7978 | system calls the windows proc directly in a context where we cannot return |
7979 | the data nor can we guarantee the state we are in. So if we dispatch them | |
ee78dc32 GV |
7980 | we will get into an infinite loop. To prevent this from ever happening we |
7981 | will set a variable to indicate we are in the read_socket call and indicate | |
e9e23e23 GV |
7982 | which message we are processing since the windows proc gets called |
7983 | recursively with different messages by the system. | |
ee78dc32 GV |
7984 | */ |
7985 | ||
7986 | int | |
3aad7613 | 7987 | w32_read_socket (sd, bufp, numchars, expected) |
ee78dc32 | 7988 | register int sd; |
9ef2e2cf JR |
7989 | /* register */ struct input_event *bufp; |
7990 | /* register */ int numchars; | |
ee78dc32 GV |
7991 | int expected; |
7992 | { | |
7993 | int count = 0; | |
689004fa | 7994 | int check_visibility = 0; |
fbd6baed | 7995 | W32Msg msg; |
ee78dc32 | 7996 | struct frame *f; |
fbd6baed | 7997 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
ee78dc32 GV |
7998 | |
7999 | if (interrupt_input_blocked) | |
8000 | { | |
8001 | interrupt_input_pending = 1; | |
8002 | return -1; | |
8003 | } | |
8004 | ||
8005 | interrupt_input_pending = 0; | |
8006 | BLOCK_INPUT; | |
8007 | ||
8008 | /* So people can tell when we have read the available input. */ | |
8009 | input_signal_count++; | |
8010 | ||
8011 | if (numchars <= 0) | |
8012 | abort (); /* Don't think this happens. */ | |
8013 | ||
01b220b6 | 8014 | /* TODO: tooltips, tool-bars, ghostscript integration, mouse |
791f420f | 8015 | cursors. */ |
52cf03a1 | 8016 | while (get_next_msg (&msg, FALSE)) |
ee78dc32 GV |
8017 | { |
8018 | switch (msg.msg.message) | |
8019 | { | |
ee78dc32 | 8020 | case WM_PAINT: |
ee78dc32 GV |
8021 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); |
8022 | ||
8023 | if (f) | |
8024 | { | |
014b6ea1 GV |
8025 | if (msg.rect.right == msg.rect.left || |
8026 | msg.rect.bottom == msg.rect.top) | |
ee78dc32 | 8027 | { |
014b6ea1 GV |
8028 | /* We may get paint messages even though the client |
8029 | area is clipped - these are not expose events. */ | |
8030 | DebPrint (("clipped frame %04x (%s) got WM_PAINT\n", f, | |
8031 | XSTRING (f->name)->data)); | |
8032 | } | |
8033 | else if (f->async_visible != 1) | |
8034 | { | |
8035 | /* Definitely not obscured, so mark as visible. */ | |
ee78dc32 GV |
8036 | f->async_visible = 1; |
8037 | f->async_iconified = 0; | |
8038 | SET_FRAME_GARBAGED (f); | |
014b6ea1 GV |
8039 | DebPrint (("frame %04x (%s) reexposed\n", f, |
8040 | XSTRING (f->name)->data)); | |
689004fa GV |
8041 | |
8042 | /* WM_PAINT serves as MapNotify as well, so report | |
8043 | visibility changes properly. */ | |
8044 | if (f->iconified) | |
8045 | { | |
8046 | bufp->kind = deiconify_event; | |
8047 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8048 | bufp->arg = Qnil; |
689004fa GV |
8049 | bufp++; |
8050 | count++; | |
8051 | numchars--; | |
8052 | } | |
9127e20e | 8053 | else if (! NILP (Vframe_list) |
8e713be6 | 8054 | && ! NILP (XCDR (Vframe_list))) |
689004fa GV |
8055 | /* Force a redisplay sooner or later to update the |
8056 | frame titles in case this is the second frame. */ | |
8057 | record_asynch_buffer_change (); | |
ee78dc32 GV |
8058 | } |
8059 | else | |
8060 | { | |
00fe468b JR |
8061 | HDC hdc = get_frame_dc (f); |
8062 | ||
97e6de38 | 8063 | /* Erase background again for safety. */ |
00fe468b JR |
8064 | w32_clear_rect (f, hdc, &msg.rect); |
8065 | release_frame_dc (f, hdc); | |
791f420f JR |
8066 | expose_frame (f, |
8067 | msg.rect.left, | |
8068 | msg.rect.top, | |
8069 | msg.rect.right - msg.rect.left, | |
8070 | msg.rect.bottom - msg.rect.top); | |
ee78dc32 GV |
8071 | } |
8072 | } | |
52cf03a1 | 8073 | break; |
689004fa | 8074 | |
f98169a0 GV |
8075 | case WM_INPUTLANGCHANGE: |
8076 | /* Generate a language change event. */ | |
8077 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8078 | ||
8079 | if (f) | |
8080 | { | |
8081 | if (numchars == 0) | |
8082 | abort (); | |
8083 | ||
8084 | bufp->kind = language_change_event; | |
8085 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8086 | bufp->arg = Qnil; |
f98169a0 GV |
8087 | bufp->code = msg.msg.wParam; |
8088 | bufp->modifiers = msg.msg.lParam & 0xffff; | |
8089 | bufp++; | |
8090 | count++; | |
8091 | numchars--; | |
8092 | } | |
8093 | break; | |
8094 | ||
ee78dc32 GV |
8095 | case WM_KEYDOWN: |
8096 | case WM_SYSKEYDOWN: | |
8097 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8098 | ||
8099 | if (f && !f->iconified) | |
8100 | { | |
8101 | if (temp_index == sizeof temp_buffer / sizeof (short)) | |
8102 | temp_index = 0; | |
8103 | temp_buffer[temp_index++] = msg.msg.wParam; | |
8104 | bufp->kind = non_ascii_keystroke; | |
8105 | bufp->code = msg.msg.wParam; | |
f98169a0 | 8106 | bufp->modifiers = msg.dwModifiers; |
ee78dc32 | 8107 | XSETFRAME (bufp->frame_or_window, f); |
7e889510 | 8108 | bufp->arg = Qnil; |
ee78dc32 GV |
8109 | bufp->timestamp = msg.msg.time; |
8110 | bufp++; | |
8111 | numchars--; | |
8112 | count++; | |
8113 | } | |
8114 | break; | |
689004fa | 8115 | |
ee78dc32 GV |
8116 | case WM_SYSCHAR: |
8117 | case WM_CHAR: | |
8118 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8119 | ||
8120 | if (f && !f->iconified) | |
8121 | { | |
f98169a0 GV |
8122 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
8123 | temp_index = 0; | |
8124 | temp_buffer[temp_index++] = msg.msg.wParam; | |
8125 | bufp->kind = ascii_keystroke; | |
8126 | bufp->code = msg.msg.wParam; | |
8127 | bufp->modifiers = msg.dwModifiers; | |
8128 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8129 | bufp->arg = Qnil; |
f98169a0 GV |
8130 | bufp->timestamp = msg.msg.time; |
8131 | bufp++; | |
8132 | numchars--; | |
8133 | count++; | |
ee78dc32 GV |
8134 | } |
8135 | break; | |
689004fa | 8136 | |
ee78dc32 | 8137 | case WM_MOUSEMOVE: |
791f420f | 8138 | previous_help_echo = help_echo; |
158cba56 JR |
8139 | help_echo = help_echo_object = help_echo_window = Qnil; |
8140 | help_echo_pos = -1; | |
791f420f | 8141 | |
ee78dc32 GV |
8142 | if (dpyinfo->grabbed && last_mouse_frame |
8143 | && FRAME_LIVE_P (last_mouse_frame)) | |
8144 | f = last_mouse_frame; | |
8145 | else | |
8146 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8147 | ||
8148 | if (f) | |
8149 | note_mouse_movement (f, &msg.msg); | |
8150 | else | |
791f420f JR |
8151 | { |
8152 | /* If we move outside the frame, then we're | |
8153 | certainly no longer on any text in the frame. */ | |
8154 | clear_mouse_face (FRAME_W32_DISPLAY_INFO (f)); | |
8155 | } | |
8156 | ||
8157 | /* If the contents of the global variable help_echo | |
8158 | has changed, generate a HELP_EVENT. */ | |
b7e80413 SM |
8159 | if (!NILP (help_echo) |
8160 | || !NILP (previous_help_echo)) | |
791f420f JR |
8161 | { |
8162 | Lisp_Object frame; | |
ec48c3a7 | 8163 | int n; |
791f420f JR |
8164 | |
8165 | if (f) | |
8166 | XSETFRAME (frame, f); | |
8167 | else | |
8168 | frame = Qnil; | |
8169 | ||
8170 | any_help_event_p = 1; | |
b4165314 GM |
8171 | n = gen_help_event (bufp, numchars, help_echo, frame, |
8172 | help_echo_window, help_echo_object, | |
8173 | help_echo_pos); | |
ec48c3a7 | 8174 | bufp += n, count += n, numchars -= n; |
791f420f JR |
8175 | } |
8176 | break; | |
689004fa | 8177 | |
ee78dc32 GV |
8178 | case WM_LBUTTONDOWN: |
8179 | case WM_LBUTTONUP: | |
8180 | case WM_MBUTTONDOWN: | |
8181 | case WM_MBUTTONUP: | |
8182 | case WM_RBUTTONDOWN: | |
8183 | case WM_RBUTTONUP: | |
8184 | { | |
791f420f JR |
8185 | /* If we decide we want to generate an event to be seen |
8186 | by the rest of Emacs, we put it here. */ | |
8187 | struct input_event emacs_event; | |
8188 | int tool_bar_p = 0; | |
ee78dc32 GV |
8189 | int button; |
8190 | int up; | |
791f420f JR |
8191 | |
8192 | emacs_event.kind = no_event; | |
ee78dc32 GV |
8193 | |
8194 | if (dpyinfo->grabbed && last_mouse_frame | |
8195 | && FRAME_LIVE_P (last_mouse_frame)) | |
8196 | f = last_mouse_frame; | |
8197 | else | |
8198 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8199 | ||
8200 | if (f) | |
8201 | { | |
791f420f JR |
8202 | construct_mouse_click (&emacs_event, &msg, f); |
8203 | ||
8204 | /* Is this in the tool-bar? */ | |
8205 | if (WINDOWP (f->tool_bar_window) | |
8206 | && XFASTINT (XWINDOW (f->tool_bar_window)->height)) | |
8207 | { | |
8208 | Lisp_Object window; | |
8209 | int p, x, y; | |
8210 | ||
8211 | /* Set x and y. */ | |
8212 | window = window_from_coordinates (f, | |
8213 | emacs_event.x, | |
8214 | emacs_event.y, | |
8215 | &p, 1); | |
8216 | if (EQ (window, f->tool_bar_window)) | |
8217 | { | |
8218 | w32_handle_tool_bar_click (f, &emacs_event); | |
8219 | tool_bar_p = 1; | |
8220 | } | |
8221 | } | |
8222 | ||
8223 | if (!tool_bar_p) | |
8224 | if (!dpyinfo->w32_focus_frame | |
8225 | || f == dpyinfo->w32_focus_frame | |
8226 | && (numchars >= 1)) | |
8227 | { | |
8228 | construct_mouse_click (bufp, &msg, f); | |
8229 | bufp++; | |
8230 | count++; | |
8231 | numchars--; | |
8232 | } | |
ee78dc32 GV |
8233 | } |
8234 | ||
8235 | parse_button (msg.msg.message, &button, &up); | |
8236 | ||
8237 | if (up) | |
8238 | { | |
8239 | dpyinfo->grabbed &= ~ (1 << button); | |
8240 | } | |
8241 | else | |
8242 | { | |
8243 | dpyinfo->grabbed |= (1 << button); | |
8244 | last_mouse_frame = f; | |
791f420f JR |
8245 | /* Ignore any mouse motion that happened |
8246 | before this event; any subsequent mouse-movement | |
8247 | Emacs events should reflect only motion after | |
8248 | the ButtonPress. */ | |
8249 | if (f != 0) | |
8250 | f->mouse_moved = 0; | |
8251 | ||
8252 | if (!tool_bar_p) | |
8253 | last_tool_bar_item = -1; | |
ee78dc32 | 8254 | } |
689004fa | 8255 | break; |
ee78dc32 GV |
8256 | } |
8257 | ||
689004fa GV |
8258 | case WM_MOUSEWHEEL: |
8259 | if (dpyinfo->grabbed && last_mouse_frame | |
8260 | && FRAME_LIVE_P (last_mouse_frame)) | |
8261 | f = last_mouse_frame; | |
8262 | else | |
8263 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8264 | ||
8265 | if (f) | |
8266 | { | |
8267 | if ((!dpyinfo->w32_focus_frame | |
8268 | || f == dpyinfo->w32_focus_frame) | |
8269 | && (numchars >= 1)) | |
8270 | { | |
8271 | construct_mouse_wheel (bufp, &msg, f); | |
8272 | bufp++; | |
8273 | count++; | |
8274 | numchars--; | |
8275 | } | |
8276 | } | |
ee78dc32 | 8277 | break; |
689004fa | 8278 | |
93ff4395 JR |
8279 | case WM_MENUSELECT: |
8280 | { | |
8281 | HMENU menu = (HMENU) msg.msg.lParam; | |
8282 | UINT menu_item = (UINT) LOWORD (msg.msg.wParam); | |
8283 | UINT flags = (UINT) HIWORD (msg.msg.wParam); | |
9ef2e2cf | 8284 | |
93ff4395 JR |
8285 | w32_menu_display_help (menu, menu_item, flags); |
8286 | } | |
8287 | break; | |
8288 | ||
12857dfd RS |
8289 | case WM_DROPFILES: |
8290 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8291 | ||
8292 | if (f) | |
8293 | { | |
8294 | construct_drag_n_drop (bufp, &msg, f); | |
8295 | bufp++; | |
8296 | count++; | |
8297 | numchars--; | |
8298 | } | |
8299 | break; | |
8300 | ||
ee78dc32 GV |
8301 | case WM_VSCROLL: |
8302 | { | |
689004fa GV |
8303 | struct scroll_bar *bar = |
8304 | x_window_to_scroll_bar ((HWND)msg.msg.lParam); | |
ee78dc32 GV |
8305 | |
8306 | if (bar && numchars >= 1) | |
8307 | { | |
52cf03a1 GV |
8308 | if (x_scroll_bar_handle_click (bar, &msg, bufp)) |
8309 | { | |
8310 | bufp++; | |
8311 | count++; | |
8312 | numchars--; | |
8313 | } | |
ee78dc32 | 8314 | } |
689004fa | 8315 | break; |
ee78dc32 GV |
8316 | } |
8317 | ||
689004fa GV |
8318 | case WM_WINDOWPOSCHANGED: |
8319 | case WM_ACTIVATE: | |
8320 | case WM_ACTIVATEAPP: | |
8321 | check_visibility = 1; | |
ee78dc32 | 8322 | break; |
689004fa | 8323 | |
ee78dc32 GV |
8324 | case WM_MOVE: |
8325 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8326 | ||
8327 | if (f && !f->async_iconified) | |
8328 | { | |
689004fa GV |
8329 | int x, y; |
8330 | ||
8331 | x_real_positions (f, &x, &y); | |
8332 | f->output_data.w32->left_pos = x; | |
8333 | f->output_data.w32->top_pos = y; | |
ee78dc32 | 8334 | } |
689004fa GV |
8335 | |
8336 | check_visibility = 1; | |
8337 | break; | |
8338 | ||
8339 | case WM_SHOWWINDOW: | |
8340 | /* If window has been obscured or exposed by another window | |
8341 | being maximised or minimised/restored, then recheck | |
8342 | visibility of all frames. Direct changes to our own | |
8343 | windows get handled by WM_SIZE. */ | |
8344 | #if 0 | |
8345 | if (msg.msg.lParam != 0) | |
8346 | check_visibility = 1; | |
8347 | else | |
8348 | { | |
8349 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8350 | f->async_visible = msg.msg.wParam; | |
8351 | } | |
8352 | #endif | |
8353 | ||
8354 | check_visibility = 1; | |
ee78dc32 | 8355 | break; |
689004fa | 8356 | |
ee78dc32 GV |
8357 | case WM_SIZE: |
8358 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8359 | ||
689004fa GV |
8360 | /* Inform lisp of whether frame has been iconified etc. */ |
8361 | if (f) | |
ee78dc32 | 8362 | { |
689004fa | 8363 | switch (msg.msg.wParam) |
ee78dc32 | 8364 | { |
689004fa GV |
8365 | case SIZE_MINIMIZED: |
8366 | f->async_visible = 0; | |
ee78dc32 GV |
8367 | f->async_iconified = 1; |
8368 | ||
8369 | bufp->kind = iconify_event; | |
8370 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8371 | bufp->arg = Qnil; |
ee78dc32 GV |
8372 | bufp++; |
8373 | count++; | |
8374 | numchars--; | |
689004fa GV |
8375 | break; |
8376 | ||
8377 | case SIZE_MAXIMIZED: | |
8378 | case SIZE_RESTORED: | |
ee78dc32 GV |
8379 | f->async_visible = 1; |
8380 | f->async_iconified = 0; | |
8381 | ||
8382 | /* wait_reading_process_input will notice this and update | |
8383 | the frame's display structures. */ | |
8384 | SET_FRAME_GARBAGED (f); | |
8385 | ||
8386 | if (f->iconified) | |
8387 | { | |
31d4844a KH |
8388 | int x, y; |
8389 | ||
8390 | /* Reset top and left positions of the Window | |
8391 | here since Windows sends a WM_MOVE message | |
8392 | BEFORE telling us the Window is minimized | |
8393 | when the Window is iconified, with 3000,3000 | |
8394 | as the co-ords. */ | |
8395 | x_real_positions (f, &x, &y); | |
8396 | f->output_data.w32->left_pos = x; | |
8397 | f->output_data.w32->top_pos = y; | |
8398 | ||
ee78dc32 GV |
8399 | bufp->kind = deiconify_event; |
8400 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8401 | bufp->arg = Qnil; |
ee78dc32 GV |
8402 | bufp++; |
8403 | count++; | |
8404 | numchars--; | |
8405 | } | |
9ef2e2cf JR |
8406 | else if (! NILP (Vframe_list) |
8407 | && ! NILP (XCDR (Vframe_list))) | |
ee78dc32 GV |
8408 | /* Force a redisplay sooner or later |
8409 | to update the frame titles | |
8410 | in case this is the second frame. */ | |
8411 | record_asynch_buffer_change (); | |
689004fa | 8412 | break; |
ee78dc32 | 8413 | } |
ee78dc32 | 8414 | } |
689004fa | 8415 | |
ef0e360f GV |
8416 | if (f && !f->async_iconified && msg.msg.wParam != SIZE_MINIMIZED) |
8417 | { | |
8418 | RECT rect; | |
8419 | int rows; | |
8420 | int columns; | |
8421 | int width; | |
8422 | int height; | |
8423 | ||
9127e20e | 8424 | GetClientRect (msg.msg.hwnd, &rect); |
ef0e360f GV |
8425 | |
8426 | height = rect.bottom - rect.top; | |
8427 | width = rect.right - rect.left; | |
8428 | ||
8429 | rows = PIXEL_TO_CHAR_HEIGHT (f, height); | |
8430 | columns = PIXEL_TO_CHAR_WIDTH (f, width); | |
8431 | ||
8432 | /* TODO: Clip size to the screen dimensions. */ | |
8433 | ||
8434 | /* Even if the number of character rows and columns has | |
8435 | not changed, the font size may have changed, so we need | |
8436 | to check the pixel dimensions as well. */ | |
8437 | ||
8438 | if (columns != f->width | |
8439 | || rows != f->height | |
8440 | || width != f->output_data.w32->pixel_width | |
8441 | || height != f->output_data.w32->pixel_height) | |
8442 | { | |
791f420f | 8443 | change_frame_size (f, rows, columns, 0, 1, 0); |
ef0e360f | 8444 | SET_FRAME_GARBAGED (f); |
31d4844a | 8445 | cancel_mouse_face (f); |
ef0e360f GV |
8446 | f->output_data.w32->pixel_width = width; |
8447 | f->output_data.w32->pixel_height = height; | |
8448 | f->output_data.w32->win_gravity = NorthWestGravity; | |
8449 | } | |
8450 | } | |
8451 | ||
689004fa GV |
8452 | check_visibility = 1; |
8453 | break; | |
8454 | ||
8455 | case WM_SETFOCUS: | |
791f420f JR |
8456 | f = x_any_window_to_frame (dpyinfo, msg.msg.hwnd); |
8457 | ||
8458 | dpyinfo->w32_focus_event_frame = f; | |
8459 | ||
8460 | if (f) | |
8461 | x_new_focus_frame (dpyinfo, f); | |
8462 | ||
8463 | ||
8464 | dpyinfo->grabbed = 0; | |
8465 | check_visibility = 1; | |
8466 | break; | |
8467 | ||
689004fa | 8468 | case WM_KILLFOCUS: |
01b220b6 | 8469 | /* TODO: some of this belongs in MOUSE_LEAVE */ |
791f420f | 8470 | f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd); |
08712a41 | 8471 | |
791f420f JR |
8472 | if (f) |
8473 | { | |
8474 | Lisp_Object frame; | |
8475 | ||
8476 | if (f == dpyinfo->w32_focus_event_frame) | |
8477 | dpyinfo->w32_focus_event_frame = 0; | |
8478 | ||
8479 | if (f == dpyinfo->w32_focus_frame) | |
8480 | x_new_focus_frame (dpyinfo, 0); | |
8481 | ||
8482 | if (f == dpyinfo->mouse_face_mouse_frame) | |
8483 | { | |
8484 | /* If we move outside the frame, then we're | |
8485 | certainly no longer on any text in the frame. */ | |
8486 | clear_mouse_face (dpyinfo); | |
8487 | dpyinfo->mouse_face_mouse_frame = 0; | |
8488 | } | |
9ef2e2cf | 8489 | |
791f420f JR |
8490 | /* Generate a nil HELP_EVENT to cancel a help-echo. |
8491 | Do it only if there's something to cancel. | |
8492 | Otherwise, the startup message is cleared when | |
8493 | the mouse leaves the frame. */ | |
8494 | if (any_help_event_p) | |
8495 | { | |
ec48c3a7 JR |
8496 | int n; |
8497 | ||
791f420f | 8498 | XSETFRAME (frame, f); |
b4165314 GM |
8499 | n = gen_help_event (bufp, numchars, Qnil, frame, |
8500 | Qnil, Qnil, 0); | |
ec48c3a7 | 8501 | bufp += n, count += n, numchars -=n; |
791f420f JR |
8502 | } |
8503 | } | |
689004fa | 8504 | |
08712a41 | 8505 | dpyinfo->grabbed = 0; |
689004fa | 8506 | check_visibility = 1; |
ee78dc32 | 8507 | break; |
689004fa | 8508 | |
ee78dc32 GV |
8509 | case WM_CLOSE: |
8510 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8511 | ||
8512 | if (f) | |
8513 | { | |
8514 | if (numchars == 0) | |
8515 | abort (); | |
8516 | ||
8517 | bufp->kind = delete_window_event; | |
8518 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8519 | bufp->arg = Qnil; |
ee78dc32 GV |
8520 | bufp++; |
8521 | count++; | |
8522 | numchars--; | |
8523 | } | |
689004fa GV |
8524 | break; |
8525 | ||
8526 | case WM_INITMENU: | |
8527 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8528 | ||
8529 | if (f) | |
8530 | { | |
8531 | if (numchars == 0) | |
8532 | abort (); | |
ee78dc32 | 8533 | |
689004fa GV |
8534 | bufp->kind = menu_bar_activate_event; |
8535 | XSETFRAME (bufp->frame_or_window, f); | |
7e889510 | 8536 | bufp->arg = Qnil; |
689004fa GV |
8537 | bufp++; |
8538 | count++; | |
8539 | numchars--; | |
8540 | } | |
ee78dc32 | 8541 | break; |
689004fa | 8542 | |
ee78dc32 GV |
8543 | case WM_COMMAND: |
8544 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
014b6ea1 | 8545 | |
ee78dc32 GV |
8546 | if (f) |
8547 | { | |
f98169a0 GV |
8548 | extern void menubar_selection_callback |
8549 | (FRAME_PTR f, void * client_data); | |
014b6ea1 | 8550 | menubar_selection_callback (f, (void *)msg.msg.wParam); |
ee78dc32 | 8551 | } |
689004fa GV |
8552 | |
8553 | check_visibility = 1; | |
8554 | break; | |
8555 | ||
8556 | case WM_DISPLAYCHANGE: | |
8557 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8558 | ||
8559 | if (f) | |
8560 | { | |
8561 | dpyinfo->width = (short) LOWORD (msg.msg.lParam); | |
8562 | dpyinfo->height = (short) HIWORD (msg.msg.lParam); | |
8563 | dpyinfo->n_cbits = msg.msg.wParam; | |
8564 | DebPrint (("display change: %d %d\n", dpyinfo->width, | |
8565 | dpyinfo->height)); | |
8566 | } | |
8567 | ||
8568 | check_visibility = 1; | |
ee78dc32 | 8569 | break; |
e7efd97e GV |
8570 | |
8571 | default: | |
8572 | /* Check for messages registered at runtime. */ | |
8573 | if (msg.msg.message == msh_mousewheel) | |
8574 | { | |
8575 | if (dpyinfo->grabbed && last_mouse_frame | |
8576 | && FRAME_LIVE_P (last_mouse_frame)) | |
8577 | f = last_mouse_frame; | |
8578 | else | |
8579 | f = x_window_to_frame (dpyinfo, msg.msg.hwnd); | |
8580 | ||
8581 | if (f) | |
8582 | { | |
8583 | if ((!dpyinfo->w32_focus_frame | |
8584 | || f == dpyinfo->w32_focus_frame) | |
8585 | && (numchars >= 1)) | |
8586 | { | |
8587 | construct_mouse_wheel (bufp, &msg, f); | |
8588 | bufp++; | |
8589 | count++; | |
8590 | numchars--; | |
8591 | } | |
8592 | } | |
8593 | } | |
8594 | break; | |
ee78dc32 GV |
8595 | } |
8596 | } | |
8597 | ||
8598 | /* If the focus was just given to an autoraising frame, | |
8599 | raise it now. */ | |
8600 | /* ??? This ought to be able to handle more than one such frame. */ | |
8601 | if (pending_autoraise_frame) | |
8602 | { | |
8603 | x_raise_frame (pending_autoraise_frame); | |
8604 | pending_autoraise_frame = 0; | |
8605 | } | |
8606 | ||
689004fa GV |
8607 | /* Check which frames are still visisble, if we have enqueued any user |
8608 | events or been notified of events that may affect visibility. We | |
8609 | do this here because there doesn't seem to be any direct | |
8610 | notification from Windows that the visibility of a window has | |
8611 | changed (at least, not in all cases). */ | |
8612 | if (count > 0 || check_visibility) | |
8613 | { | |
8614 | Lisp_Object tail, frame; | |
8615 | ||
8616 | FOR_EACH_FRAME (tail, frame) | |
8617 | { | |
8618 | FRAME_PTR f = XFRAME (frame); | |
8619 | /* Check "visible" frames and mark each as obscured or not. | |
8620 | Note that async_visible is nonzero for unobscured and | |
8621 | obscured frames, but zero for hidden and iconified frames. */ | |
8622 | if (FRAME_W32_P (f) && f->async_visible) | |
8623 | { | |
8624 | RECT clipbox; | |
8625 | HDC hdc = get_frame_dc (f); | |
8626 | GetClipBox (hdc, &clipbox); | |
8627 | release_frame_dc (f, hdc); | |
8628 | ||
8629 | if (clipbox.right == clipbox.left | |
8630 | || clipbox.bottom == clipbox.top) | |
8631 | { | |
8632 | /* Frame has become completely obscured so mark as | |
8633 | such (we do this by setting async_visible to 2 so | |
8634 | that FRAME_VISIBLE_P is still true, but redisplay | |
8635 | will skip it). */ | |
8636 | f->async_visible = 2; | |
8637 | ||
8638 | if (!FRAME_OBSCURED_P (f)) | |
8639 | { | |
8640 | DebPrint (("frame %04x (%s) obscured\n", f, | |
8641 | XSTRING (f->name)->data)); | |
8642 | } | |
8643 | } | |
8644 | else | |
8645 | { | |
8646 | /* Frame is not obscured, so mark it as such. */ | |
8647 | f->async_visible = 1; | |
8648 | ||
8649 | if (FRAME_OBSCURED_P (f)) | |
8650 | { | |
8651 | SET_FRAME_GARBAGED (f); | |
8652 | DebPrint (("frame %04x (%s) reexposed\n", f, | |
8653 | XSTRING (f->name)->data)); | |
8654 | ||
8655 | /* Force a redisplay sooner or later. */ | |
8656 | record_asynch_buffer_change (); | |
8657 | } | |
8658 | } | |
8659 | } | |
8660 | } | |
8661 | } | |
8662 | ||
ee78dc32 GV |
8663 | UNBLOCK_INPUT; |
8664 | return count; | |
8665 | } | |
791f420f | 8666 | |
9ef2e2cf JR |
8667 | |
8668 | ||
ee78dc32 | 8669 | \f |
791f420f JR |
8670 | /*********************************************************************** |
8671 | Text Cursor | |
8672 | ***********************************************************************/ | |
8673 | ||
8674 | /* Note if the text cursor of window W has been overwritten by a | |
8675 | drawing operation that outputs N glyphs starting at HPOS in the | |
8676 | line given by output_cursor.vpos. N < 0 means all the rest of the | |
8677 | line after HPOS has been written. */ | |
8678 | ||
8679 | static void | |
8680 | note_overwritten_text_cursor (w, hpos, n) | |
8681 | struct window *w; | |
8682 | int hpos, n; | |
8683 | { | |
8684 | if (updated_area == TEXT_AREA | |
8685 | && output_cursor.vpos == w->phys_cursor.vpos | |
8686 | && hpos <= w->phys_cursor.hpos | |
8687 | && (n < 0 | |
8688 | || hpos + n > w->phys_cursor.hpos)) | |
8689 | w->phys_cursor_on_p = 0; | |
8690 | } | |
8691 | ||
ee78dc32 | 8692 | |
791f420f JR |
8693 | /* Set clipping for output in glyph row ROW. W is the window in which |
8694 | we operate. GC is the graphics context to set clipping in. | |
8695 | WHOLE_LINE_P non-zero means include the areas used for truncation | |
8696 | mark display and alike in the clipping rectangle. | |
ee78dc32 | 8697 | |
791f420f JR |
8698 | ROW may be a text row or, e.g., a mode line. Text rows must be |
8699 | clipped to the interior of the window dedicated to text display, | |
8700 | mode lines must be clipped to the whole window. */ | |
ee78dc32 GV |
8701 | |
8702 | static void | |
791f420f JR |
8703 | w32_clip_to_row (w, row, hdc, whole_line_p) |
8704 | struct window *w; | |
8705 | struct glyph_row *row; | |
8706 | HDC hdc; | |
8707 | int whole_line_p; | |
ee78dc32 | 8708 | { |
791f420f JR |
8709 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
8710 | RECT clip_rect; | |
8711 | int window_x, window_y, window_width, window_height; | |
52cf03a1 | 8712 | |
791f420f | 8713 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); |
52cf03a1 | 8714 | |
791f420f JR |
8715 | clip_rect.left = WINDOW_TO_FRAME_PIXEL_X (w, 0); |
8716 | clip_rect.top = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
8717 | clip_rect.top = max (clip_rect.top, window_y); | |
8718 | clip_rect.right = clip_rect.left + window_width; | |
8719 | clip_rect.bottom = clip_rect.top + row->visible_height; | |
8720 | ||
8721 | /* If clipping to the whole line, including trunc marks, extend | |
9ef2e2cf | 8722 | the rectangle to the left and increase its width. */ |
791f420f JR |
8723 | if (whole_line_p) |
8724 | { | |
8725 | clip_rect.left -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); | |
8726 | clip_rect.right += FRAME_X_FLAGS_AREA_WIDTH (f); | |
8727 | } | |
8728 | ||
8729 | w32_set_clip_rectangle (hdc, &clip_rect); | |
ee78dc32 GV |
8730 | } |
8731 | ||
791f420f JR |
8732 | |
8733 | /* Draw a hollow box cursor on window W in glyph row ROW. */ | |
ee78dc32 GV |
8734 | |
8735 | static void | |
791f420f JR |
8736 | x_draw_hollow_cursor (w, row) |
8737 | struct window *w; | |
8738 | struct glyph_row *row; | |
ee78dc32 | 8739 | { |
791f420f | 8740 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
988646fc | 8741 | HDC hdc; |
791f420f JR |
8742 | RECT rect; |
8743 | int wd; | |
8744 | struct glyph *cursor_glyph; | |
8745 | HBRUSH hb = CreateSolidBrush (f->output_data.w32->cursor_pixel); | |
8746 | ||
8747 | /* Compute frame-relative coordinates from window-relative | |
8748 | coordinates. */ | |
8749 | rect.left = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | |
8750 | rect.top = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) | |
8751 | + row->ascent - w->phys_cursor_ascent); | |
8752 | rect.bottom = rect.top + row->height - 1; | |
8753 | ||
8754 | /* Get the glyph the cursor is on. If we can't tell because | |
8755 | the current matrix is invalid or such, give up. */ | |
8756 | cursor_glyph = get_phys_cursor_glyph (w); | |
8757 | if (cursor_glyph == NULL) | |
ee78dc32 GV |
8758 | return; |
8759 | ||
791f420f JR |
8760 | /* Compute the width of the rectangle to draw. If on a stretch |
8761 | glyph, and `x-stretch-block-cursor' is nil, don't draw a | |
8762 | rectangle as wide as the glyph, but use a canonical character | |
8763 | width instead. */ | |
8764 | wd = cursor_glyph->pixel_width - 1; | |
8765 | if (cursor_glyph->type == STRETCH_GLYPH | |
8766 | && !x_stretch_cursor_p) | |
8767 | wd = min (CANON_X_UNIT (f), wd); | |
8768 | ||
8769 | rect.right = rect.left + wd; | |
988646fc | 8770 | hdc = get_frame_dc (f); |
791f420f JR |
8771 | FrameRect (hdc, &rect, hb); |
8772 | DeleteObject (hb); | |
8773 | ||
8774 | release_frame_dc (f, hdc); | |
ee78dc32 GV |
8775 | } |
8776 | ||
791f420f JR |
8777 | |
8778 | /* Draw a bar cursor on window W in glyph row ROW. | |
8779 | ||
8780 | Implementation note: One would like to draw a bar cursor with an | |
8781 | angle equal to the one given by the font property XA_ITALIC_ANGLE. | |
8782 | Unfortunately, I didn't find a font yet that has this property set. | |
8783 | --gerd. */ | |
ee78dc32 GV |
8784 | |
8785 | static void | |
9ef2e2cf | 8786 | x_draw_bar_cursor (w, row, width) |
791f420f JR |
8787 | struct window *w; |
8788 | struct glyph_row *row; | |
9ef2e2cf | 8789 | int width; |
ee78dc32 | 8790 | { |
791f420f JR |
8791 | /* If cursor hpos is out of bounds, don't draw garbage. This can |
8792 | happen in mini-buffer windows when switching between echo area | |
8793 | glyphs and mini-buffer. */ | |
8794 | if (w->phys_cursor.hpos < row->used[TEXT_AREA]) | |
8795 | { | |
8796 | struct frame *f = XFRAME (w->frame); | |
8797 | struct glyph *cursor_glyph; | |
8798 | int x; | |
00fe468b | 8799 | HDC hdc; |
791f420f JR |
8800 | |
8801 | cursor_glyph = get_phys_cursor_glyph (w); | |
8802 | if (cursor_glyph == NULL) | |
8803 | return; | |
8804 | ||
158cba56 JR |
8805 | /* If on an image, draw like a normal cursor. That's usually better |
8806 | visible than drawing a bar, esp. if the image is large so that | |
8807 | the bar might not be in the window. */ | |
8808 | if (cursor_glyph->type == IMAGE_GLYPH) | |
8809 | { | |
8810 | struct glyph_row *row; | |
8811 | row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos); | |
8812 | x_draw_phys_cursor_glyph (w, row, DRAW_CURSOR); | |
8813 | } | |
8814 | else | |
8815 | { | |
791f420f | 8816 | |
158cba56 | 8817 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
9ef2e2cf | 8818 | |
158cba56 JR |
8819 | if (width < 0) |
8820 | width = f->output_data.w32->cursor_width; | |
8821 | ||
8822 | hdc = get_frame_dc (f); | |
8823 | w32_fill_area (f, hdc, f->output_data.w32->cursor_pixel, | |
8824 | x, | |
8825 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y), | |
8826 | min (cursor_glyph->pixel_width, width), | |
8827 | row->height); | |
8828 | release_frame_dc (f, hdc); | |
8829 | } | |
791f420f | 8830 | } |
ee78dc32 GV |
8831 | } |
8832 | ||
791f420f JR |
8833 | |
8834 | /* Clear the cursor of window W to background color, and mark the | |
8835 | cursor as not shown. This is used when the text where the cursor | |
8836 | is is about to be rewritten. */ | |
8837 | ||
ee78dc32 | 8838 | static void |
791f420f JR |
8839 | x_clear_cursor (w) |
8840 | struct window *w; | |
ee78dc32 | 8841 | { |
791f420f JR |
8842 | if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p) |
8843 | x_update_window_cursor (w, 0); | |
8844 | } | |
ee78dc32 | 8845 | |
ee78dc32 | 8846 | |
791f420f JR |
8847 | /* Draw the cursor glyph of window W in glyph row ROW. See the |
8848 | comment of x_draw_glyphs for the meaning of HL. */ | |
ee78dc32 | 8849 | |
791f420f JR |
8850 | static void |
8851 | x_draw_phys_cursor_glyph (w, row, hl) | |
8852 | struct window *w; | |
8853 | struct glyph_row *row; | |
8854 | enum draw_glyphs_face hl; | |
8855 | { | |
8856 | /* If cursor hpos is out of bounds, don't draw garbage. This can | |
8857 | happen in mini-buffer windows when switching between echo area | |
8858 | glyphs and mini-buffer. */ | |
8859 | if (w->phys_cursor.hpos < row->used[TEXT_AREA]) | |
ee78dc32 | 8860 | { |
791f420f JR |
8861 | x_draw_glyphs (w, w->phys_cursor.x, row, TEXT_AREA, |
8862 | w->phys_cursor.hpos, w->phys_cursor.hpos + 1, | |
8863 | hl, 0, 0, 0); | |
8864 | ||
8865 | /* When we erase the cursor, and ROW is overlapped by other | |
8866 | rows, make sure that these overlapping parts of other rows | |
8867 | are redrawn. */ | |
8868 | if (hl == DRAW_NORMAL_TEXT && row->overlapped_p) | |
8869 | { | |
8870 | if (row > w->current_matrix->rows | |
8871 | && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1)) | |
8872 | x_fix_overlapping_area (w, row - 1, TEXT_AREA); | |
8873 | ||
8874 | if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w) | |
8875 | && MATRIX_ROW_OVERLAPS_PRED_P (row + 1)) | |
8876 | x_fix_overlapping_area (w, row + 1, TEXT_AREA); | |
8877 | } | |
ee78dc32 | 8878 | } |
791f420f | 8879 | } |
ee78dc32 | 8880 | |
791f420f JR |
8881 | |
8882 | /* Erase the image of a cursor of window W from the screen. */ | |
8883 | ||
8884 | static void | |
8885 | x_erase_phys_cursor (w) | |
8886 | struct window *w; | |
8887 | { | |
8888 | struct frame *f = XFRAME (w->frame); | |
8889 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
8890 | int hpos = w->phys_cursor.hpos; | |
8891 | int vpos = w->phys_cursor.vpos; | |
8892 | int mouse_face_here_p = 0; | |
8893 | struct glyph_matrix *active_glyphs = w->current_matrix; | |
8894 | struct glyph_row *cursor_row; | |
8895 | struct glyph *cursor_glyph; | |
8896 | enum draw_glyphs_face hl; | |
8897 | ||
8898 | /* No cursor displayed or row invalidated => nothing to do on the | |
8899 | screen. */ | |
8900 | if (w->phys_cursor_type == NO_CURSOR) | |
8901 | goto mark_cursor_off; | |
8902 | ||
8903 | /* VPOS >= active_glyphs->nrows means that window has been resized. | |
8904 | Don't bother to erase the cursor. */ | |
8905 | if (vpos >= active_glyphs->nrows) | |
8906 | goto mark_cursor_off; | |
8907 | ||
8908 | /* If row containing cursor is marked invalid, there is nothing we | |
8909 | can do. */ | |
8910 | cursor_row = MATRIX_ROW (active_glyphs, vpos); | |
8911 | if (!cursor_row->enabled_p) | |
8912 | goto mark_cursor_off; | |
8913 | ||
8914 | /* This can happen when the new row is shorter than the old one. | |
8915 | In this case, either x_draw_glyphs or clear_end_of_line | |
8916 | should have cleared the cursor. Note that we wouldn't be | |
8917 | able to erase the cursor in this case because we don't have a | |
8918 | cursor glyph at hand. */ | |
8919 | if (w->phys_cursor.hpos >= cursor_row->used[TEXT_AREA]) | |
8920 | goto mark_cursor_off; | |
8921 | ||
8922 | /* If the cursor is in the mouse face area, redisplay that when | |
8923 | we clear the cursor. */ | |
8924 | if (w == XWINDOW (dpyinfo->mouse_face_window) | |
8925 | && (vpos > dpyinfo->mouse_face_beg_row | |
8926 | || (vpos == dpyinfo->mouse_face_beg_row | |
8927 | && hpos >= dpyinfo->mouse_face_beg_col)) | |
8928 | && (vpos < dpyinfo->mouse_face_end_row | |
8929 | || (vpos == dpyinfo->mouse_face_end_row | |
8930 | && hpos < dpyinfo->mouse_face_end_col)) | |
8931 | /* Don't redraw the cursor's spot in mouse face if it is at the | |
8932 | end of a line (on a newline). The cursor appears there, but | |
8933 | mouse highlighting does not. */ | |
8934 | && cursor_row->used[TEXT_AREA] > hpos) | |
8935 | mouse_face_here_p = 1; | |
8936 | ||
8937 | /* Maybe clear the display under the cursor. */ | |
8938 | if (w->phys_cursor_type == HOLLOW_BOX_CURSOR) | |
ee78dc32 | 8939 | { |
791f420f JR |
8940 | int x; |
8941 | int header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
00fe468b | 8942 | HDC hdc; |
ee78dc32 | 8943 | |
791f420f JR |
8944 | cursor_glyph = get_phys_cursor_glyph (w); |
8945 | if (cursor_glyph == NULL) | |
8946 | goto mark_cursor_off; | |
ee78dc32 | 8947 | |
791f420f | 8948 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
00fe468b JR |
8949 | |
8950 | hdc = get_frame_dc (f); | |
8951 | w32_clear_area (f, hdc, x, | |
791f420f JR |
8952 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, |
8953 | cursor_row->y)), | |
8954 | cursor_glyph->pixel_width, | |
8955 | cursor_row->visible_height); | |
00fe468b | 8956 | release_frame_dc (f, hdc); |
ee78dc32 | 8957 | } |
791f420f JR |
8958 | |
8959 | /* Erase the cursor by redrawing the character underneath it. */ | |
8960 | if (mouse_face_here_p) | |
8961 | hl = DRAW_MOUSE_FACE; | |
8962 | else if (cursor_row->inverse_p) | |
8963 | hl = DRAW_INVERSE_VIDEO; | |
8964 | else | |
8965 | hl = DRAW_NORMAL_TEXT; | |
8966 | x_draw_phys_cursor_glyph (w, cursor_row, hl); | |
8967 | ||
8968 | mark_cursor_off: | |
8969 | w->phys_cursor_on_p = 0; | |
8970 | w->phys_cursor_type = NO_CURSOR; | |
ee78dc32 GV |
8971 | } |
8972 | ||
8973 | ||
791f420f JR |
8974 | /* Display or clear cursor of window W. If ON is zero, clear the |
8975 | cursor. If it is non-zero, display the cursor. If ON is nonzero, | |
8976 | where to put the cursor is specified by HPOS, VPOS, X and Y. */ | |
ee78dc32 | 8977 | |
791f420f JR |
8978 | void |
8979 | x_display_and_set_cursor (w, on, hpos, vpos, x, y) | |
8980 | struct window *w; | |
8981 | int on, hpos, vpos, x, y; | |
ee78dc32 | 8982 | { |
791f420f JR |
8983 | struct frame *f = XFRAME (w->frame); |
8984 | int new_cursor_type; | |
9ef2e2cf | 8985 | int new_cursor_width; |
791f420f JR |
8986 | struct glyph_matrix *current_glyphs; |
8987 | struct glyph_row *glyph_row; | |
8988 | struct glyph *glyph; | |
ee78dc32 GV |
8989 | |
8990 | /* This is pointless on invisible frames, and dangerous on garbaged | |
791f420f JR |
8991 | windows and frames; in the latter case, the frame or window may |
8992 | be in the midst of changing its size, and x and y may be off the | |
8993 | window. */ | |
8994 | if (! FRAME_VISIBLE_P (f) | |
8995 | || FRAME_GARBAGED_P (f) | |
8996 | || vpos >= w->current_matrix->nrows | |
8997 | || hpos >= w->current_matrix->matrix_w) | |
ee78dc32 GV |
8998 | return; |
8999 | ||
9000 | /* If cursor is off and we want it off, return quickly. */ | |
791f420f | 9001 | if (!on && !w->phys_cursor_on_p) |
ee78dc32 GV |
9002 | return; |
9003 | ||
791f420f JR |
9004 | current_glyphs = w->current_matrix; |
9005 | glyph_row = MATRIX_ROW (current_glyphs, vpos); | |
9006 | glyph = glyph_row->glyphs[TEXT_AREA] + hpos; | |
9007 | ||
9008 | /* If cursor row is not enabled, we don't really know where to | |
9009 | display the cursor. */ | |
9010 | if (!glyph_row->enabled_p) | |
9011 | { | |
9012 | w->phys_cursor_on_p = 0; | |
9013 | return; | |
9014 | } | |
9015 | ||
9016 | xassert (interrupt_input_blocked); | |
9017 | ||
9018 | /* Set new_cursor_type to the cursor we want to be displayed. In a | |
9019 | mini-buffer window, we want the cursor only to appear if we are | |
9020 | reading input from this window. For the selected window, we want | |
9021 | the cursor type given by the frame parameter. If explicitly | |
9022 | marked off, draw no cursor. In all other cases, we want a hollow | |
9023 | box cursor. */ | |
9ef2e2cf | 9024 | new_cursor_width = -1; |
791f420f JR |
9025 | if (cursor_in_echo_area |
9026 | && FRAME_HAS_MINIBUF_P (f) | |
9027 | && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window)) | |
9028 | { | |
9029 | if (w == XWINDOW (echo_area_window)) | |
9030 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
9031 | else | |
9032 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
9033 | } | |
9034 | else | |
9035 | { | |
9036 | if (w != XWINDOW (selected_window) | |
9037 | || f != FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame) | |
9038 | { | |
a2bc11d4 JR |
9039 | extern int cursor_in_non_selected_windows; |
9040 | ||
9127e20e JR |
9041 | if (MINI_WINDOW_P (w) |
9042 | || !cursor_in_non_selected_windows | |
9043 | || NILP (XBUFFER (w->buffer)->cursor_type)) | |
791f420f JR |
9044 | new_cursor_type = NO_CURSOR; |
9045 | else | |
9046 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
9047 | } | |
9048 | else if (w->cursor_off_p) | |
9049 | new_cursor_type = NO_CURSOR; | |
9050 | else | |
9ef2e2cf JR |
9051 | { |
9052 | struct buffer *b = XBUFFER (w->buffer); | |
9053 | ||
9054 | if (EQ (b->cursor_type, Qt)) | |
9055 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
9056 | else | |
9057 | new_cursor_type = x_specified_cursor_type (b->cursor_type, | |
9058 | &new_cursor_width); | |
9059 | } | |
791f420f JR |
9060 | } |
9061 | ||
9062 | /* If cursor is currently being shown and we don't want it to be or | |
9063 | it is in the wrong place, or the cursor type is not what we want, | |
ee78dc32 | 9064 | erase it. */ |
791f420f | 9065 | if (w->phys_cursor_on_p |
ee78dc32 | 9066 | && (!on |
791f420f JR |
9067 | || w->phys_cursor.x != x |
9068 | || w->phys_cursor.y != y | |
9069 | || new_cursor_type != w->phys_cursor_type)) | |
9070 | x_erase_phys_cursor (w); | |
9071 | ||
9072 | /* If the cursor is now invisible and we want it to be visible, | |
9073 | display it. */ | |
9074 | if (on && !w->phys_cursor_on_p) | |
9075 | { | |
9076 | w->phys_cursor_ascent = glyph_row->ascent; | |
9077 | w->phys_cursor_height = glyph_row->height; | |
9078 | ||
9079 | /* Set phys_cursor_.* before x_draw_.* is called because some | |
9080 | of them may need the information. */ | |
9081 | w->phys_cursor.x = x; | |
9082 | w->phys_cursor.y = glyph_row->y; | |
9083 | w->phys_cursor.hpos = hpos; | |
9084 | w->phys_cursor.vpos = vpos; | |
9085 | w->phys_cursor_type = new_cursor_type; | |
9086 | w->phys_cursor_on_p = 1; | |
9087 | ||
9088 | switch (new_cursor_type) | |
ee78dc32 | 9089 | { |
791f420f JR |
9090 | case HOLLOW_BOX_CURSOR: |
9091 | x_draw_hollow_cursor (w, glyph_row); | |
9092 | break; | |
9093 | ||
9094 | case FILLED_BOX_CURSOR: | |
9095 | x_draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR); | |
9096 | break; | |
9097 | ||
9098 | case BAR_CURSOR: | |
9ef2e2cf | 9099 | x_draw_bar_cursor (w, glyph_row, new_cursor_width); |
791f420f | 9100 | break; |
ee78dc32 | 9101 | |
791f420f JR |
9102 | case NO_CURSOR: |
9103 | break; | |
9104 | ||
9105 | default: | |
9106 | abort (); | |
9107 | } | |
ee78dc32 GV |
9108 | } |
9109 | } | |
9110 | ||
689004fa | 9111 | |
791f420f JR |
9112 | /* Display the cursor on window W, or clear it. X and Y are window |
9113 | relative pixel coordinates. HPOS and VPOS are glyph matrix | |
9114 | positions. If W is not the selected window, display a hollow | |
9115 | cursor. ON non-zero means display the cursor at X, Y which | |
9116 | correspond to HPOS, VPOS, otherwise it is cleared. */ | |
9117 | ||
9118 | void | |
9119 | x_display_cursor (w, on, hpos, vpos, x, y) | |
9120 | struct window *w; | |
9121 | int on, hpos, vpos, x, y; | |
ee78dc32 GV |
9122 | { |
9123 | BLOCK_INPUT; | |
791f420f JR |
9124 | x_display_and_set_cursor (w, on, hpos, vpos, x, y); |
9125 | UNBLOCK_INPUT; | |
9126 | } | |
9127 | ||
9128 | ||
9129 | /* Display the cursor on window W, or clear it, according to ON_P. | |
9130 | Don't change the cursor's position. */ | |
9131 | ||
9132 | void | |
9133 | x_update_cursor (f, on_p) | |
9134 | struct frame *f; | |
9135 | int on_p; | |
9136 | { | |
9137 | x_update_cursor_in_window_tree (XWINDOW (f->root_window), on_p); | |
9138 | } | |
9139 | ||
9140 | ||
9141 | /* Call x_update_window_cursor with parameter ON_P on all leaf windows | |
9142 | in the window tree rooted at W. */ | |
ee78dc32 | 9143 | |
791f420f JR |
9144 | static void |
9145 | x_update_cursor_in_window_tree (w, on_p) | |
9146 | struct window *w; | |
9147 | int on_p; | |
9148 | { | |
9149 | while (w) | |
689004fa | 9150 | { |
791f420f JR |
9151 | if (!NILP (w->hchild)) |
9152 | x_update_cursor_in_window_tree (XWINDOW (w->hchild), on_p); | |
9153 | else if (!NILP (w->vchild)) | |
9154 | x_update_cursor_in_window_tree (XWINDOW (w->vchild), on_p); | |
9155 | else | |
9156 | x_update_window_cursor (w, on_p); | |
9157 | ||
9158 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
689004fa | 9159 | } |
791f420f | 9160 | } |
689004fa | 9161 | |
ee78dc32 | 9162 | |
791f420f JR |
9163 | /* Switch the display of W's cursor on or off, according to the value |
9164 | of ON. */ | |
9165 | ||
9166 | static void | |
9167 | x_update_window_cursor (w, on) | |
9168 | struct window *w; | |
9169 | int on; | |
9170 | { | |
9ef2e2cf JR |
9171 | /* Don't update cursor in windows whose frame is in the process |
9172 | of being deleted. */ | |
9173 | if (w->current_matrix) | |
9174 | { | |
9175 | BLOCK_INPUT; | |
9176 | x_display_and_set_cursor (w, on, w->phys_cursor.hpos, | |
9177 | w->phys_cursor.vpos, w->phys_cursor.x, | |
9178 | w->phys_cursor.y); | |
9179 | UNBLOCK_INPUT; | |
9180 | } | |
ee78dc32 | 9181 | } |
791f420f JR |
9182 | |
9183 | ||
9ef2e2cf | 9184 | |
ee78dc32 | 9185 | \f |
7f5d1df8 GV |
9186 | /* Icons. */ |
9187 | ||
9188 | int | |
9189 | x_bitmap_icon (f, icon) | |
9190 | struct frame *f; | |
9191 | Lisp_Object icon; | |
9192 | { | |
9193 | int mask, bitmap_id; | |
9194 | Window icon_window; | |
9195 | HANDLE hicon; | |
9196 | ||
9197 | if (FRAME_W32_WINDOW (f) == 0) | |
9198 | return 1; | |
9199 | ||
9200 | if (NILP (icon)) | |
9201 | hicon = LoadIcon (hinst, EMACS_CLASS); | |
9202 | else if (STRINGP (icon)) | |
9203 | hicon = LoadImage (NULL, (LPCTSTR) XSTRING (icon)->data, IMAGE_ICON, 0, 0, | |
9204 | LR_DEFAULTSIZE | LR_LOADFROMFILE); | |
9205 | else if (SYMBOLP (icon)) | |
9206 | { | |
9207 | LPCTSTR name; | |
9208 | ||
9209 | if (EQ (icon, intern ("application"))) | |
9210 | name = (LPCTSTR) IDI_APPLICATION; | |
9211 | else if (EQ (icon, intern ("hand"))) | |
9212 | name = (LPCTSTR) IDI_HAND; | |
9213 | else if (EQ (icon, intern ("question"))) | |
9214 | name = (LPCTSTR) IDI_QUESTION; | |
9215 | else if (EQ (icon, intern ("exclamation"))) | |
9216 | name = (LPCTSTR) IDI_EXCLAMATION; | |
9217 | else if (EQ (icon, intern ("asterisk"))) | |
9218 | name = (LPCTSTR) IDI_ASTERISK; | |
9219 | else if (EQ (icon, intern ("winlogo"))) | |
9220 | name = (LPCTSTR) IDI_WINLOGO; | |
9221 | else | |
9222 | return 1; | |
9223 | ||
9224 | hicon = LoadIcon (NULL, name); | |
9225 | } | |
9226 | else | |
9227 | return 1; | |
9228 | ||
9229 | if (hicon == NULL) | |
9230 | return 1; | |
9231 | ||
791f420f JR |
9232 | PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_BIG, |
9233 | (LPARAM) hicon); | |
7f5d1df8 GV |
9234 | |
9235 | return 0; | |
9236 | } | |
9237 | ||
9238 | \f | |
ee78dc32 GV |
9239 | /* Changing the font of the frame. */ |
9240 | ||
9241 | /* Give frame F the font named FONTNAME as its default font, and | |
9242 | return the full name of that font. FONTNAME may be a wildcard | |
9243 | pattern; in that case, we choose some font that fits the pattern. | |
9244 | The return value shows which font we chose. */ | |
9245 | ||
9246 | Lisp_Object | |
9247 | x_new_font (f, fontname) | |
9248 | struct frame *f; | |
9249 | register char *fontname; | |
9250 | { | |
cabb23bc | 9251 | struct font_info *fontp |
93ff4395 | 9252 | = FS_LOAD_FONT (f, 0, fontname, -1); |
ee78dc32 | 9253 | |
cabb23bc | 9254 | if (!fontp) |
791f420f | 9255 | return Qnil; |
ee78dc32 | 9256 | |
cabb23bc | 9257 | FRAME_FONT (f) = (XFontStruct *) (fontp->font); |
791f420f | 9258 | FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset; |
cabb23bc | 9259 | FRAME_FONTSET (f) = -1; |
ee78dc32 GV |
9260 | |
9261 | /* Compute the scroll bar width in character columns. */ | |
9262 | if (f->scroll_bar_pixel_width > 0) | |
9263 | { | |
ec48c3a7 | 9264 | int wid = FONT_WIDTH (FRAME_FONT (f)); |
ee78dc32 GV |
9265 | f->scroll_bar_cols = (f->scroll_bar_pixel_width + wid-1) / wid; |
9266 | } | |
9267 | else | |
ec48c3a7 JR |
9268 | { |
9269 | int wid = FONT_WIDTH (FRAME_FONT (f)); | |
9270 | f->scroll_bar_cols = (14 + wid - 1) / wid; | |
9271 | } | |
ee78dc32 GV |
9272 | |
9273 | /* Now make the frame display the given font. */ | |
fbd6baed | 9274 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 GV |
9275 | { |
9276 | frame_update_line_height (f); | |
9277 | x_set_window_size (f, 0, f->width, f->height); | |
9278 | } | |
9279 | else | |
9280 | /* If we are setting a new frame's font for the first time, | |
9281 | there are no faces yet, so this font's height is the line height. */ | |
ec48c3a7 | 9282 | f->output_data.w32->line_height = FONT_HEIGHT (FRAME_FONT (f)); |
ee78dc32 | 9283 | |
791f420f | 9284 | return build_string (fontp->full_name); |
ee78dc32 GV |
9285 | } |
9286 | \f | |
cabb23bc GV |
9287 | /* Give frame F the fontset named FONTSETNAME as its default font, and |
9288 | return the full name of that fontset. FONTSETNAME may be a wildcard | |
9289 | pattern; in that case, we choose some fontset that fits the pattern. | |
9290 | The return value shows which fontset we chose. */ | |
9291 | ||
9292 | Lisp_Object | |
9293 | x_new_fontset (f, fontsetname) | |
9294 | struct frame *f; | |
9295 | char *fontsetname; | |
9296 | { | |
93ff4395 | 9297 | int fontset = fs_query_fontset (build_string (fontsetname), 0); |
cabb23bc | 9298 | Lisp_Object result; |
93ff4395 | 9299 | char *fontname; |
cabb23bc GV |
9300 | |
9301 | if (fontset < 0) | |
9302 | return Qnil; | |
9303 | ||
9304 | if (FRAME_FONTSET (f) == fontset) | |
9305 | /* This fontset is already set in frame F. There's nothing more | |
9306 | to do. */ | |
93ff4395 | 9307 | return fontset_name (fontset); |
cabb23bc | 9308 | |
93ff4395 | 9309 | result = x_new_font (f, (XSTRING (fontset_ascii (fontset))->data)); |
cabb23bc GV |
9310 | |
9311 | if (!STRINGP (result)) | |
9312 | /* Can't load ASCII font. */ | |
9313 | return Qnil; | |
9314 | ||
9315 | /* Since x_new_font doesn't update any fontset information, do it now. */ | |
9316 | FRAME_FONTSET(f) = fontset; | |
cabb23bc GV |
9317 | |
9318 | return build_string (fontsetname); | |
9319 | } | |
791f420f JR |
9320 | |
9321 | ||
9322 | #if GLYPH_DEBUG | |
9323 | ||
9324 | /* Check that FONT is valid on frame F. It is if it can be found in F's | |
9325 | font table. */ | |
9326 | ||
9327 | static void | |
9328 | x_check_font (f, font) | |
9329 | struct frame *f; | |
9330 | XFontStruct *font; | |
9331 | { | |
9332 | int i; | |
9333 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
9334 | ||
9335 | xassert (font != NULL); | |
9336 | ||
9337 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
9338 | if (dpyinfo->font_table[i].name | |
9339 | && font == dpyinfo->font_table[i].font) | |
9340 | break; | |
9341 | ||
9342 | xassert (i < dpyinfo->n_fonts); | |
9343 | } | |
9344 | ||
9345 | #endif /* GLYPH_DEBUG != 0 */ | |
9346 | ||
9347 | /* Set *W to the minimum width, *H to the minimum font height of FONT. | |
9348 | Note: There are (broken) X fonts out there with invalid XFontStruct | |
9349 | min_bounds contents. For example, handa@etl.go.jp reports that | |
9350 | "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts | |
9351 | have font->min_bounds.width == 0. */ | |
9352 | ||
9353 | static INLINE void | |
9354 | x_font_min_bounds (font, w, h) | |
9355 | XFontStruct *font; | |
9356 | int *w, *h; | |
9357 | { | |
158cba56 | 9358 | /* |
01b220b6 | 9359 | * TODO: Windows does not appear to offer min bound, only |
158cba56 JR |
9360 | * average and maximum width, and maximum height. |
9361 | */ | |
791f420f JR |
9362 | *h = FONT_HEIGHT (font); |
9363 | *w = FONT_WIDTH (font); | |
791f420f JR |
9364 | } |
9365 | ||
9366 | ||
9367 | /* Compute the smallest character width and smallest font height over | |
9368 | all fonts available on frame F. Set the members smallest_char_width | |
9369 | and smallest_font_height in F's x_display_info structure to | |
9370 | the values computed. Value is non-zero if smallest_font_height or | |
9371 | smallest_char_width become smaller than they were before. */ | |
9372 | ||
9373 | int | |
9374 | x_compute_min_glyph_bounds (f) | |
9375 | struct frame *f; | |
9376 | { | |
9377 | int i; | |
9378 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
9379 | XFontStruct *font; | |
9380 | int old_width = dpyinfo->smallest_char_width; | |
9381 | int old_height = dpyinfo->smallest_font_height; | |
9382 | ||
9383 | dpyinfo->smallest_font_height = 100000; | |
9384 | dpyinfo->smallest_char_width = 100000; | |
9385 | ||
9386 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
9387 | if (dpyinfo->font_table[i].name) | |
9388 | { | |
9389 | struct font_info *fontp = dpyinfo->font_table + i; | |
9390 | int w, h; | |
9391 | ||
9392 | font = (XFontStruct *) fontp->font; | |
9393 | xassert (font != (XFontStruct *) ~0); | |
9394 | x_font_min_bounds (font, &w, &h); | |
9395 | ||
9396 | dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h); | |
9397 | dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w); | |
9398 | } | |
9399 | ||
9400 | xassert (dpyinfo->smallest_char_width > 0 | |
9401 | && dpyinfo->smallest_font_height > 0); | |
9402 | ||
9403 | return (dpyinfo->n_fonts == 1 | |
9404 | || dpyinfo->smallest_char_width < old_width | |
9405 | || dpyinfo->smallest_font_height < old_height); | |
9406 | } | |
9407 | ||
cabb23bc | 9408 | \f |
689004fa GV |
9409 | /* Calculate the absolute position in frame F |
9410 | from its current recorded position values and gravity. */ | |
9411 | ||
9ef2e2cf | 9412 | void |
ee78dc32 GV |
9413 | x_calc_absolute_position (f) |
9414 | struct frame *f; | |
9415 | { | |
791f420f | 9416 | Window child; |
ee78dc32 | 9417 | POINT pt; |
fbd6baed | 9418 | int flags = f->output_data.w32->size_hint_flags; |
ee78dc32 GV |
9419 | |
9420 | pt.x = pt.y = 0; | |
9421 | ||
9422 | /* Find the position of the outside upper-left corner of | |
9423 | the inner window, with respect to the outer window. */ | |
fbd6baed | 9424 | if (f->output_data.w32->parent_desc != FRAME_W32_DISPLAY_INFO (f)->root_window) |
ee78dc32 GV |
9425 | { |
9426 | BLOCK_INPUT; | |
fbd6baed GV |
9427 | MapWindowPoints (FRAME_W32_WINDOW (f), |
9428 | f->output_data.w32->parent_desc, | |
ee78dc32 GV |
9429 | &pt, 1); |
9430 | UNBLOCK_INPUT; | |
9431 | } | |
9432 | ||
9433 | { | |
9434 | RECT rt; | |
9435 | rt.left = rt.right = rt.top = rt.bottom = 0; | |
9436 | ||
9437 | BLOCK_INPUT; | |
fbd6baed | 9438 | AdjustWindowRect(&rt, f->output_data.w32->dwStyle, |
97c23857 | 9439 | FRAME_EXTERNAL_MENU_BAR (f)); |
ee78dc32 GV |
9440 | UNBLOCK_INPUT; |
9441 | ||
9442 | pt.x += (rt.right - rt.left); | |
9443 | pt.y += (rt.bottom - rt.top); | |
9444 | } | |
9445 | ||
9446 | /* Treat negative positions as relative to the leftmost bottommost | |
9447 | position that fits on the screen. */ | |
9448 | if (flags & XNegative) | |
fbd6baed GV |
9449 | f->output_data.w32->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width |
9450 | - 2 * f->output_data.w32->border_width - pt.x | |
ee78dc32 | 9451 | - PIXEL_WIDTH (f) |
fbd6baed | 9452 | + f->output_data.w32->left_pos); |
158cba56 | 9453 | |
ee78dc32 | 9454 | if (flags & YNegative) |
fbd6baed GV |
9455 | f->output_data.w32->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height |
9456 | - 2 * f->output_data.w32->border_width - pt.y | |
ee78dc32 | 9457 | - PIXEL_HEIGHT (f) |
fbd6baed | 9458 | + f->output_data.w32->top_pos); |
ee78dc32 GV |
9459 | /* The left_pos and top_pos |
9460 | are now relative to the top and left screen edges, | |
9461 | so the flags should correspond. */ | |
fbd6baed | 9462 | f->output_data.w32->size_hint_flags &= ~ (XNegative | YNegative); |
ee78dc32 GV |
9463 | } |
9464 | ||
9465 | /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position, | |
9466 | to really change the position, and 0 when calling from | |
9467 | x_make_frame_visible (in that case, XOFF and YOFF are the current | |
9468 | position values). It is -1 when calling from x_set_frame_parameters, | |
9469 | which means, do adjust for borders but don't change the gravity. */ | |
9470 | ||
9ef2e2cf | 9471 | void |
ee78dc32 GV |
9472 | x_set_offset (f, xoff, yoff, change_gravity) |
9473 | struct frame *f; | |
9474 | register int xoff, yoff; | |
9475 | int change_gravity; | |
9476 | { | |
9477 | int modified_top, modified_left; | |
9478 | ||
9479 | if (change_gravity > 0) | |
9480 | { | |
fbd6baed GV |
9481 | f->output_data.w32->top_pos = yoff; |
9482 | f->output_data.w32->left_pos = xoff; | |
9483 | f->output_data.w32->size_hint_flags &= ~ (XNegative | YNegative); | |
ee78dc32 | 9484 | if (xoff < 0) |
fbd6baed | 9485 | f->output_data.w32->size_hint_flags |= XNegative; |
ee78dc32 | 9486 | if (yoff < 0) |
fbd6baed GV |
9487 | f->output_data.w32->size_hint_flags |= YNegative; |
9488 | f->output_data.w32->win_gravity = NorthWestGravity; | |
ee78dc32 GV |
9489 | } |
9490 | x_calc_absolute_position (f); | |
9491 | ||
9492 | BLOCK_INPUT; | |
9493 | x_wm_set_size_hint (f, (long) 0, 0); | |
9494 | ||
fbd6baed GV |
9495 | modified_left = f->output_data.w32->left_pos; |
9496 | modified_top = f->output_data.w32->top_pos; | |
ee78dc32 | 9497 | |
fbd6baed | 9498 | my_set_window_pos (FRAME_W32_WINDOW (f), |
52cf03a1 GV |
9499 | NULL, |
9500 | modified_left, modified_top, | |
cabb23bc | 9501 | 0, 0, |
689004fa | 9502 | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); |
ee78dc32 GV |
9503 | UNBLOCK_INPUT; |
9504 | } | |
9505 | ||
9506 | /* Call this to change the size of frame F's x-window. | |
9507 | If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity | |
9508 | for this size change and subsequent size changes. | |
9509 | Otherwise we leave the window gravity unchanged. */ | |
791f420f | 9510 | void |
ee78dc32 GV |
9511 | x_set_window_size (f, change_gravity, cols, rows) |
9512 | struct frame *f; | |
9513 | int change_gravity; | |
9514 | int cols, rows; | |
9515 | { | |
9516 | int pixelwidth, pixelheight; | |
9517 | ||
9518 | BLOCK_INPUT; | |
9519 | ||
9520 | check_frame_size (f, &rows, &cols); | |
fbd6baed | 9521 | f->output_data.w32->vertical_scroll_bar_extra |
ee78dc32 GV |
9522 | = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f) |
9523 | ? 0 | |
fbd6baed | 9524 | : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->output_data.w32->font))); |
791f420f JR |
9525 | f->output_data.w32->flags_areas_extra |
9526 | = FRAME_FLAGS_AREA_WIDTH (f); | |
ee78dc32 GV |
9527 | pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols); |
9528 | pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows); | |
9529 | ||
fbd6baed | 9530 | f->output_data.w32->win_gravity = NorthWestGravity; |
ee78dc32 GV |
9531 | x_wm_set_size_hint (f, (long) 0, 0); |
9532 | ||
9533 | { | |
9534 | RECT rect; | |
9535 | ||
9536 | rect.left = rect.top = 0; | |
9537 | rect.right = pixelwidth; | |
9538 | rect.bottom = pixelheight; | |
9539 | ||
fbd6baed | 9540 | AdjustWindowRect(&rect, f->output_data.w32->dwStyle, |
97c23857 | 9541 | FRAME_EXTERNAL_MENU_BAR (f)); |
ee78dc32 | 9542 | |
fbd6baed | 9543 | my_set_window_pos (FRAME_W32_WINDOW (f), |
52cf03a1 GV |
9544 | NULL, |
9545 | 0, 0, | |
689004fa GV |
9546 | rect.right - rect.left, |
9547 | rect.bottom - rect.top, | |
9548 | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); | |
ee78dc32 GV |
9549 | } |
9550 | ||
9551 | /* Now, strictly speaking, we can't be sure that this is accurate, | |
9552 | but the window manager will get around to dealing with the size | |
9553 | change request eventually, and we'll hear how it went when the | |
9554 | ConfigureNotify event gets here. | |
9555 | ||
9556 | We could just not bother storing any of this information here, | |
9557 | and let the ConfigureNotify event set everything up, but that | |
ec48c3a7 | 9558 | might be kind of confusing to the Lisp code, since size changes |
ee78dc32 | 9559 | wouldn't be reported in the frame parameters until some random |
791f420f JR |
9560 | point in the future when the ConfigureNotify event arrives. |
9561 | ||
9562 | We pass 1 for DELAY since we can't run Lisp code inside of | |
9563 | a BLOCK_INPUT. */ | |
9564 | change_frame_size (f, rows, cols, 0, 1, 0); | |
ee78dc32 GV |
9565 | PIXEL_WIDTH (f) = pixelwidth; |
9566 | PIXEL_HEIGHT (f) = pixelheight; | |
9567 | ||
689004fa GV |
9568 | /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to |
9569 | receive in the ConfigureNotify event; if we get what we asked | |
9570 | for, then the event won't cause the screen to become garbaged, so | |
9571 | we have to make sure to do it here. */ | |
9572 | SET_FRAME_GARBAGED (f); | |
9573 | ||
ee78dc32 | 9574 | /* If cursor was outside the new size, mark it as off. */ |
791f420f | 9575 | mark_window_cursors_off (XWINDOW (f->root_window)); |
ee78dc32 | 9576 | |
689004fa GV |
9577 | /* Clear out any recollection of where the mouse highlighting was, |
9578 | since it might be in a place that's outside the new frame size. | |
9579 | Actually checking whether it is outside is a pain in the neck, | |
9580 | so don't try--just let the highlighting be done afresh with new size. */ | |
31d4844a KH |
9581 | cancel_mouse_face (f); |
9582 | ||
ee78dc32 GV |
9583 | UNBLOCK_INPUT; |
9584 | } | |
9585 | \f | |
9586 | /* Mouse warping. */ | |
9587 | ||
ec48c3a7 JR |
9588 | void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y); |
9589 | ||
9590 | void | |
9591 | x_set_mouse_position (f, x, y) | |
9592 | struct frame *f; | |
9593 | int x, y; | |
9594 | { | |
9595 | int pix_x, pix_y; | |
9596 | ||
9597 | pix_x = CHAR_TO_PIXEL_COL (f, x) + FONT_WIDTH (f->output_data.w32->font) / 2; | |
9598 | pix_y = CHAR_TO_PIXEL_ROW (f, y) + f->output_data.w32->line_height / 2; | |
9599 | ||
9600 | if (pix_x < 0) pix_x = 0; | |
9601 | if (pix_x > PIXEL_WIDTH (f)) pix_x = PIXEL_WIDTH (f); | |
9602 | ||
9603 | if (pix_y < 0) pix_y = 0; | |
9604 | if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f); | |
9605 | ||
9606 | x_set_mouse_pixel_position (f, pix_x, pix_y); | |
9607 | } | |
9608 | ||
1bcd16f2 MB |
9609 | void |
9610 | x_set_mouse_pixel_position (f, pix_x, pix_y) | |
9611 | struct frame *f; | |
9612 | int pix_x, pix_y; | |
9613 | { | |
689004fa GV |
9614 | RECT rect; |
9615 | POINT pt; | |
9616 | ||
1bcd16f2 MB |
9617 | BLOCK_INPUT; |
9618 | ||
689004fa GV |
9619 | GetClientRect (FRAME_W32_WINDOW (f), &rect); |
9620 | pt.x = rect.left + pix_x; | |
9621 | pt.y = rect.top + pix_y; | |
9622 | ClientToScreen (FRAME_W32_WINDOW (f), &pt); | |
1bcd16f2 | 9623 | |
689004fa | 9624 | SetCursorPos (pt.x, pt.y); |
1bcd16f2 MB |
9625 | |
9626 | UNBLOCK_INPUT; | |
9627 | } | |
9628 | ||
ee78dc32 GV |
9629 | \f |
9630 | /* focus shifting, raising and lowering. */ | |
9631 | ||
ec48c3a7 | 9632 | void |
ee78dc32 GV |
9633 | x_focus_on_frame (f) |
9634 | struct frame *f; | |
9635 | { | |
689004fa GV |
9636 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
9637 | ||
9638 | /* Give input focus to frame. */ | |
9639 | BLOCK_INPUT; | |
9640 | #if 0 | |
9641 | /* Try not to change its Z-order if possible. */ | |
9642 | if (x_window_to_frame (dpyinfo, GetForegroundWindow ())) | |
9643 | my_set_focus (f, FRAME_W32_WINDOW (f)); | |
9644 | else | |
9645 | #endif | |
ef0e360f | 9646 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa | 9647 | UNBLOCK_INPUT; |
ee78dc32 GV |
9648 | } |
9649 | ||
ec48c3a7 | 9650 | void |
ee78dc32 GV |
9651 | x_unfocus_frame (f) |
9652 | struct frame *f; | |
9653 | { | |
9654 | } | |
9655 | ||
9656 | /* Raise frame F. */ | |
791f420f | 9657 | void |
ee78dc32 GV |
9658 | x_raise_frame (f) |
9659 | struct frame *f; | |
9660 | { | |
689004fa GV |
9661 | BLOCK_INPUT; |
9662 | ||
9663 | /* Strictly speaking, raise-frame should only change the frame's Z | |
9664 | order, leaving input focus unchanged. This is reasonable behaviour | |
9665 | on X where the usual policy is point-to-focus. However, this | |
9666 | behaviour would be very odd on Windows where the usual policy is | |
9667 | click-to-focus. | |
9668 | ||
9669 | On X, if the mouse happens to be over the raised frame, it gets | |
9670 | input focus anyway (so the window with focus will never be | |
9671 | completely obscured) - if not, then just moving the mouse over it | |
9672 | is sufficient to give it focus. On Windows, the user must actually | |
9673 | click on the frame (preferrably the title bar so as not to move | |
9674 | point), which is more awkward. Also, no other Windows program | |
9675 | raises a window to the top but leaves another window (possibly now | |
9676 | completely obscured) with input focus. | |
9677 | ||
9678 | Because there is a system setting on Windows that allows the user | |
9679 | to choose the point to focus policy, we make the strict semantics | |
9680 | optional, but by default we grab focus when raising. */ | |
9681 | ||
9682 | if (NILP (Vw32_grab_focus_on_raise)) | |
ee78dc32 | 9683 | { |
689004fa GV |
9684 | /* The obvious call to my_set_window_pos doesn't work if Emacs is |
9685 | not already the foreground application: the frame is raised | |
9686 | above all other frames belonging to us, but not above the | |
9687 | current top window. To achieve that, we have to resort to this | |
9688 | more cumbersome method. */ | |
9689 | ||
9690 | HDWP handle = BeginDeferWindowPos (2); | |
9691 | if (handle) | |
9692 | { | |
9693 | DeferWindowPos (handle, | |
9694 | FRAME_W32_WINDOW (f), | |
9695 | HWND_TOP, | |
9696 | 0, 0, 0, 0, | |
9697 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
9698 | ||
9699 | DeferWindowPos (handle, | |
9700 | GetForegroundWindow (), | |
9701 | FRAME_W32_WINDOW (f), | |
9702 | 0, 0, 0, 0, | |
9703 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
9704 | ||
9705 | EndDeferWindowPos (handle); | |
9706 | } | |
ee78dc32 | 9707 | } |
689004fa GV |
9708 | else |
9709 | { | |
ef0e360f | 9710 | my_set_foreground_window (FRAME_W32_WINDOW (f)); |
689004fa GV |
9711 | } |
9712 | ||
9713 | UNBLOCK_INPUT; | |
ee78dc32 GV |
9714 | } |
9715 | ||
9716 | /* Lower frame F. */ | |
791f420f | 9717 | void |
ee78dc32 GV |
9718 | x_lower_frame (f) |
9719 | struct frame *f; | |
9720 | { | |
689004fa GV |
9721 | BLOCK_INPUT; |
9722 | my_set_window_pos (FRAME_W32_WINDOW (f), | |
9723 | HWND_BOTTOM, | |
9724 | 0, 0, 0, 0, | |
9725 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | |
9726 | UNBLOCK_INPUT; | |
ee78dc32 GV |
9727 | } |
9728 | ||
9729 | static void | |
ec48c3a7 | 9730 | w32_frame_raise_lower (f, raise_flag) |
ee78dc32 | 9731 | FRAME_PTR f; |
ec48c3a7 | 9732 | int raise_flag; |
ee78dc32 | 9733 | { |
ec48c3a7 | 9734 | if (raise_flag) |
ee78dc32 GV |
9735 | x_raise_frame (f); |
9736 | else | |
9737 | x_lower_frame (f); | |
9738 | } | |
9739 | \f | |
9740 | /* Change of visibility. */ | |
9741 | ||
9742 | /* This tries to wait until the frame is really visible. | |
9743 | However, if the window manager asks the user where to position | |
9744 | the frame, this will return before the user finishes doing that. | |
9745 | The frame will not actually be visible at that time, | |
9746 | but it will become visible later when the window manager | |
9747 | finishes with it. */ | |
9748 | ||
ec48c3a7 | 9749 | void |
ee78dc32 GV |
9750 | x_make_frame_visible (f) |
9751 | struct frame *f; | |
9752 | { | |
7f5d1df8 GV |
9753 | Lisp_Object type; |
9754 | ||
ee78dc32 GV |
9755 | BLOCK_INPUT; |
9756 | ||
7f5d1df8 GV |
9757 | type = x_icon_type (f); |
9758 | if (!NILP (type)) | |
9759 | x_bitmap_icon (f, type); | |
9760 | ||
ee78dc32 GV |
9761 | if (! FRAME_VISIBLE_P (f)) |
9762 | { | |
9763 | /* We test FRAME_GARBAGED_P here to make sure we don't | |
9764 | call x_set_offset a second time | |
9765 | if we get to x_make_frame_visible a second time | |
9766 | before the window gets really visible. */ | |
9767 | if (! FRAME_ICONIFIED_P (f) | |
fbd6baed | 9768 | && ! f->output_data.w32->asked_for_visible) |
fbd6baed | 9769 | x_set_offset (f, f->output_data.w32->left_pos, f->output_data.w32->top_pos, 0); |
ee78dc32 | 9770 | |
fbd6baed | 9771 | f->output_data.w32->asked_for_visible = 1; |
52cf03a1 | 9772 | |
689004fa GV |
9773 | // my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW); |
9774 | my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL); | |
ee78dc32 GV |
9775 | } |
9776 | ||
9777 | /* Synchronize to ensure Emacs knows the frame is visible | |
9778 | before we do anything else. We do this loop with input not blocked | |
9779 | so that incoming events are handled. */ | |
9780 | { | |
9781 | Lisp_Object frame; | |
791f420f | 9782 | int count; |
ee78dc32 GV |
9783 | |
9784 | /* This must come after we set COUNT. */ | |
9785 | UNBLOCK_INPUT; | |
9786 | ||
9787 | XSETFRAME (frame, f); | |
9788 | ||
791f420f JR |
9789 | /* Wait until the frame is visible. Process X events until a |
9790 | MapNotify event has been seen, or until we think we won't get a | |
9791 | MapNotify at all.. */ | |
9792 | for (count = input_signal_count + 10; | |
9793 | input_signal_count < count && !FRAME_VISIBLE_P (f);) | |
ee78dc32 | 9794 | { |
791f420f | 9795 | /* Force processing of queued events. */ |
01b220b6 | 9796 | /* TODO: x_sync equivalent? */ |
791f420f | 9797 | |
ee78dc32 GV |
9798 | /* Machines that do polling rather than SIGIO have been observed |
9799 | to go into a busy-wait here. So we'll fake an alarm signal | |
9800 | to let the handler know that there's something to be read. | |
9801 | We used to raise a real alarm, but it seems that the handler | |
9802 | isn't always enabled here. This is probably a bug. */ | |
9803 | if (input_polling_used ()) | |
9804 | { | |
9805 | /* It could be confusing if a real alarm arrives while processing | |
9806 | the fake one. Turn it off and let the handler reset it. */ | |
a9b4e0ec AI |
9807 | int old_poll_suppress_count = poll_suppress_count; |
9808 | poll_suppress_count = 1; | |
9809 | poll_for_input_1 (); | |
9810 | poll_suppress_count = old_poll_suppress_count; | |
ee78dc32 | 9811 | } |
ee78dc32 GV |
9812 | } |
9813 | FRAME_SAMPLE_VISIBILITY (f); | |
9814 | } | |
9815 | } | |
9816 | ||
9817 | /* Change from mapped state to withdrawn state. */ | |
9818 | ||
9819 | /* Make the frame visible (mapped and not iconified). */ | |
9820 | ||
9821 | x_make_frame_invisible (f) | |
9822 | struct frame *f; | |
9823 | { | |
ee78dc32 | 9824 | /* Don't keep the highlight on an invisible frame. */ |
fbd6baed GV |
9825 | if (FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame == f) |
9826 | FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame = 0; | |
ee78dc32 GV |
9827 | |
9828 | BLOCK_INPUT; | |
9829 | ||
689004fa | 9830 | my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE); |
ee78dc32 GV |
9831 | |
9832 | /* We can't distinguish this from iconification | |
9833 | just by the event that we get from the server. | |
9834 | So we can't win using the usual strategy of letting | |
9835 | FRAME_SAMPLE_VISIBILITY set this. So do it by hand, | |
9836 | and synchronize with the server to make sure we agree. */ | |
9837 | f->visible = 0; | |
9838 | FRAME_ICONIFIED_P (f) = 0; | |
9839 | f->async_visible = 0; | |
9840 | f->async_iconified = 0; | |
9841 | ||
9842 | UNBLOCK_INPUT; | |
9843 | } | |
9844 | ||
9845 | /* Change window state from mapped to iconified. */ | |
9846 | ||
52cf03a1 GV |
9847 | void |
9848 | x_iconify_frame (f) | |
ee78dc32 GV |
9849 | struct frame *f; |
9850 | { | |
9851 | int result; | |
7f5d1df8 | 9852 | Lisp_Object type; |
ee78dc32 GV |
9853 | |
9854 | /* Don't keep the highlight on an invisible frame. */ | |
fbd6baed GV |
9855 | if (FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame == f) |
9856 | FRAME_W32_DISPLAY_INFO (f)->w32_highlight_frame = 0; | |
ee78dc32 GV |
9857 | |
9858 | if (f->async_iconified) | |
9859 | return; | |
9860 | ||
9861 | BLOCK_INPUT; | |
9862 | ||
7f5d1df8 GV |
9863 | type = x_icon_type (f); |
9864 | if (!NILP (type)) | |
9865 | x_bitmap_icon (f, type); | |
9866 | ||
689004fa | 9867 | /* Simulate the user minimizing the frame. */ |
4934bcdd | 9868 | SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0); |
ee78dc32 GV |
9869 | |
9870 | UNBLOCK_INPUT; | |
9871 | } | |
9872 | \f | |
25badd7a | 9873 | /* Free X resources of frame F. */ |
ee78dc32 | 9874 | |
25badd7a AI |
9875 | void |
9876 | x_free_frame_resources (f) | |
ee78dc32 GV |
9877 | struct frame *f; |
9878 | { | |
fbd6baed | 9879 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
ee78dc32 GV |
9880 | |
9881 | BLOCK_INPUT; | |
9882 | ||
25badd7a AI |
9883 | if (FRAME_W32_WINDOW (f)) |
9884 | my_destroy_window (f, FRAME_W32_WINDOW (f)); | |
9885 | ||
ee78dc32 | 9886 | free_frame_menubar (f); |
ee78dc32 | 9887 | |
25badd7a AI |
9888 | unload_color (f, f->output_data.x->foreground_pixel); |
9889 | unload_color (f, f->output_data.x->background_pixel); | |
9890 | unload_color (f, f->output_data.w32->cursor_pixel); | |
9891 | unload_color (f, f->output_data.w32->cursor_foreground_pixel); | |
9892 | unload_color (f, f->output_data.w32->border_pixel); | |
9893 | unload_color (f, f->output_data.w32->mouse_pixel); | |
9894 | ||
9895 | if (FRAME_FACE_CACHE (f)) | |
9896 | free_frame_faces (f); | |
9897 | ||
fbd6baed | 9898 | xfree (f->output_data.w32); |
25badd7a AI |
9899 | f->output_data.w32 = NULL; |
9900 | ||
fbd6baed GV |
9901 | if (f == dpyinfo->w32_focus_frame) |
9902 | dpyinfo->w32_focus_frame = 0; | |
9903 | if (f == dpyinfo->w32_focus_event_frame) | |
9904 | dpyinfo->w32_focus_event_frame = 0; | |
9905 | if (f == dpyinfo->w32_highlight_frame) | |
9906 | dpyinfo->w32_highlight_frame = 0; | |
ee78dc32 | 9907 | |
ee78dc32 GV |
9908 | if (f == dpyinfo->mouse_face_mouse_frame) |
9909 | { | |
9910 | dpyinfo->mouse_face_beg_row | |
9911 | = dpyinfo->mouse_face_beg_col = -1; | |
9912 | dpyinfo->mouse_face_end_row | |
9913 | = dpyinfo->mouse_face_end_col = -1; | |
9914 | dpyinfo->mouse_face_window = Qnil; | |
25badd7a AI |
9915 | dpyinfo->mouse_face_deferred_gc = 0; |
9916 | dpyinfo->mouse_face_mouse_frame = 0; | |
ee78dc32 GV |
9917 | } |
9918 | ||
9919 | UNBLOCK_INPUT; | |
9920 | } | |
25badd7a AI |
9921 | |
9922 | ||
9923 | /* Destroy the window of frame F. */ | |
9924 | ||
9925 | x_destroy_window (f) | |
9926 | struct frame *f; | |
9927 | { | |
9928 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
9929 | ||
9930 | x_free_frame_resources (f); | |
9931 | ||
9932 | dpyinfo->reference_count--; | |
9933 | } | |
ee78dc32 GV |
9934 | \f |
9935 | /* Setting window manager hints. */ | |
9936 | ||
9937 | /* Set the normal size hints for the window manager, for frame F. | |
9938 | FLAGS is the flags word to use--or 0 meaning preserve the flags | |
9939 | that the window now has. | |
9940 | If USER_POSITION is nonzero, we set the USPosition | |
9941 | flag (this is useful when FLAGS is 0). */ | |
791f420f | 9942 | void |
ee78dc32 GV |
9943 | x_wm_set_size_hint (f, flags, user_position) |
9944 | struct frame *f; | |
9945 | long flags; | |
9946 | int user_position; | |
9947 | { | |
fbd6baed | 9948 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 | 9949 | |
97c23857 | 9950 | enter_crit (); |
ee78dc32 | 9951 | |
689004fa GV |
9952 | SetWindowLong (window, WND_FONTWIDTH_INDEX, FONT_WIDTH (f->output_data.w32->font)); |
9953 | SetWindowLong (window, WND_LINEHEIGHT_INDEX, f->output_data.w32->line_height); | |
9954 | SetWindowLong (window, WND_BORDER_INDEX, f->output_data.w32->internal_border_width); | |
9955 | SetWindowLong (window, WND_SCROLLBAR_INDEX, f->output_data.w32->vertical_scroll_bar_extra); | |
ee78dc32 | 9956 | |
97c23857 | 9957 | leave_crit (); |
ee78dc32 GV |
9958 | } |
9959 | ||
9960 | /* Window manager things */ | |
9961 | x_wm_set_icon_position (f, icon_x, icon_y) | |
9962 | struct frame *f; | |
9963 | int icon_x, icon_y; | |
9964 | { | |
9965 | #if 0 | |
fbd6baed | 9966 | Window window = FRAME_W32_WINDOW (f); |
ee78dc32 GV |
9967 | |
9968 | f->display.x->wm_hints.flags |= IconPositionHint; | |
9969 | f->display.x->wm_hints.icon_x = icon_x; | |
9970 | f->display.x->wm_hints.icon_y = icon_y; | |
9971 | ||
9972 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints); | |
9973 | #endif | |
9974 | } | |
9975 | ||
9ef2e2cf | 9976 | |
ee78dc32 | 9977 | \f |
791f420f JR |
9978 | /*********************************************************************** |
9979 | Initialization | |
9980 | ***********************************************************************/ | |
ee78dc32 | 9981 | |
fbd6baed | 9982 | static int w32_initialized = 0; |
ee78dc32 | 9983 | |
f7737f5d JR |
9984 | void |
9985 | w32_initialize_display_info (display_name) | |
9986 | Lisp_Object display_name; | |
9987 | { | |
9988 | struct w32_display_info *dpyinfo = &one_w32_display_info; | |
9989 | ||
9990 | bzero (dpyinfo, sizeof (*dpyinfo)); | |
9991 | ||
9992 | /* Put it on w32_display_name_list. */ | |
9993 | w32_display_name_list = Fcons (Fcons (display_name, Qnil), | |
9994 | w32_display_name_list); | |
9995 | dpyinfo->name_list_element = XCAR (w32_display_name_list); | |
9996 | ||
9997 | dpyinfo->w32_id_name | |
9998 | = (char *) xmalloc (XSTRING (Vinvocation_name)->size | |
9999 | + XSTRING (Vsystem_name)->size | |
10000 | + 2); | |
10001 | sprintf (dpyinfo->w32_id_name, "%s@%s", | |
10002 | XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data); | |
10003 | ||
10004 | /* Default Console mode values - overridden when running in GUI mode | |
10005 | with values obtained from system metrics. */ | |
10006 | dpyinfo->resx = 1; | |
10007 | dpyinfo->resy = 1; | |
10008 | dpyinfo->height_in = 1; | |
10009 | dpyinfo->width_in = 1; | |
10010 | dpyinfo->n_planes = 1; | |
10011 | dpyinfo->n_cbits = 4; | |
10012 | dpyinfo->n_fonts = 0; | |
10013 | dpyinfo->smallest_font_height = 1; | |
10014 | dpyinfo->smallest_char_width = 1; | |
10015 | ||
10016 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
10017 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
10018 | dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; | |
10019 | dpyinfo->mouse_face_window = Qnil; | |
10020 | ||
01b220b6 | 10021 | /* TODO: dpyinfo->gray */ |
f7737f5d JR |
10022 | |
10023 | } | |
10024 | ||
fbd6baed GV |
10025 | struct w32_display_info * |
10026 | w32_term_init (display_name, xrm_option, resource_name) | |
ee78dc32 GV |
10027 | Lisp_Object display_name; |
10028 | char *xrm_option; | |
10029 | char *resource_name; | |
10030 | { | |
fbd6baed | 10031 | struct w32_display_info *dpyinfo; |
ee78dc32 | 10032 | HDC hdc; |
97c23857 | 10033 | |
ee78dc32 GV |
10034 | BLOCK_INPUT; |
10035 | ||
fbd6baed | 10036 | if (!w32_initialized) |
ee78dc32 | 10037 | { |
fbd6baed GV |
10038 | w32_initialize (); |
10039 | w32_initialized = 1; | |
ee78dc32 GV |
10040 | } |
10041 | ||
10042 | { | |
10043 | int argc = 0; | |
10044 | char *argv[3]; | |
10045 | ||
10046 | argv[0] = ""; | |
10047 | argc = 1; | |
10048 | if (xrm_option) | |
10049 | { | |
10050 | argv[argc++] = "-xrm"; | |
10051 | argv[argc++] = xrm_option; | |
10052 | } | |
10053 | } | |
10054 | ||
f7737f5d | 10055 | w32_initialize_display_info (display_name); |
ee78dc32 | 10056 | |
f7737f5d | 10057 | dpyinfo = &one_w32_display_info; |
ee78dc32 | 10058 | |
52cf03a1 | 10059 | hdc = GetDC (GetDesktopWindow ()); |
791f420f | 10060 | |
ee78dc32 GV |
10061 | dpyinfo->height = GetDeviceCaps (hdc, VERTRES); |
10062 | dpyinfo->width = GetDeviceCaps (hdc, HORZRES); | |
10063 | dpyinfo->root_window = GetDesktopWindow (); | |
10064 | dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES); | |
10065 | dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL); | |
55689ab1 JR |
10066 | dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX); |
10067 | dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY); | |
52cf03a1 | 10068 | dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE; |
791f420f | 10069 | dpyinfo->image_cache = make_image_cache (); |
55689ab1 JR |
10070 | dpyinfo->height_in = dpyinfo->height / dpyinfo->resx; |
10071 | dpyinfo->width_in = dpyinfo->width / dpyinfo->resy; | |
ee78dc32 | 10072 | ReleaseDC (GetDesktopWindow (), hdc); |
52cf03a1 GV |
10073 | |
10074 | /* initialise palette with white and black */ | |
10075 | { | |
10076 | COLORREF color; | |
55689ab1 JR |
10077 | w32_defined_color (0, "white", &color, 1); |
10078 | w32_defined_color (0, "black", &color, 1); | |
52cf03a1 GV |
10079 | } |
10080 | ||
f7737f5d JR |
10081 | /* Create Row Bitmaps and store them for later use. */ |
10082 | left_bmp = CreateBitmap (left_width, left_height, 1, 1, left_bits); | |
10083 | ov_bmp = CreateBitmap (ov_width, ov_height, 1, 1, ov_bits); | |
10084 | right_bmp = CreateBitmap (right_width, right_height, 1, 1, right_bits); | |
10085 | continued_bmp = CreateBitmap (continued_width, continued_height, 1, | |
10086 | 1, continued_bits); | |
10087 | continuation_bmp = CreateBitmap (continuation_width, continuation_height, | |
10088 | 1, 1, continuation_bits); | |
10089 | zv_bmp = CreateBitmap (zv_width, zv_height, 1, 1, zv_bits); | |
10090 | ||
ee78dc32 GV |
10091 | #ifndef F_SETOWN_BUG |
10092 | #ifdef F_SETOWN | |
10093 | #ifdef F_SETOWN_SOCK_NEG | |
10094 | /* stdin is a socket here */ | |
10095 | fcntl (connection, F_SETOWN, -getpid ()); | |
10096 | #else /* ! defined (F_SETOWN_SOCK_NEG) */ | |
10097 | fcntl (connection, F_SETOWN, getpid ()); | |
10098 | #endif /* ! defined (F_SETOWN_SOCK_NEG) */ | |
10099 | #endif /* ! defined (F_SETOWN) */ | |
10100 | #endif /* F_SETOWN_BUG */ | |
10101 | ||
10102 | #ifdef SIGIO | |
10103 | if (interrupt_input) | |
10104 | init_sigio (connection); | |
10105 | #endif /* ! defined (SIGIO) */ | |
10106 | ||
10107 | UNBLOCK_INPUT; | |
10108 | ||
10109 | return dpyinfo; | |
10110 | } | |
10111 | \f | |
10112 | /* Get rid of display DPYINFO, assuming all frames are already gone. */ | |
10113 | ||
10114 | void | |
10115 | x_delete_display (dpyinfo) | |
fbd6baed | 10116 | struct w32_display_info *dpyinfo; |
ee78dc32 | 10117 | { |
fbd6baed | 10118 | /* Discard this display from w32_display_name_list and w32_display_list. |
ee78dc32 | 10119 | We can't use Fdelq because that can quit. */ |
fbd6baed | 10120 | if (! NILP (w32_display_name_list) |
8e713be6 KR |
10121 | && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element)) |
10122 | w32_display_name_list = XCDR (w32_display_name_list); | |
ee78dc32 GV |
10123 | else |
10124 | { | |
10125 | Lisp_Object tail; | |
10126 | ||
fbd6baed | 10127 | tail = w32_display_name_list; |
8e713be6 | 10128 | while (CONSP (tail) && CONSP (XCDR (tail))) |
ee78dc32 | 10129 | { |
f7737f5d | 10130 | if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element)) |
ee78dc32 | 10131 | { |
8e713be6 | 10132 | XCDR (tail) = XCDR (XCDR (tail)); |
ee78dc32 GV |
10133 | break; |
10134 | } | |
8e713be6 | 10135 | tail = XCDR (tail); |
ee78dc32 GV |
10136 | } |
10137 | } | |
10138 | ||
52cf03a1 GV |
10139 | /* free palette table */ |
10140 | { | |
fbd6baed | 10141 | struct w32_palette_entry * plist; |
52cf03a1 GV |
10142 | |
10143 | plist = dpyinfo->color_list; | |
10144 | while (plist) | |
10145 | { | |
fbd6baed | 10146 | struct w32_palette_entry * pentry = plist; |
52cf03a1 | 10147 | plist = plist->next; |
9127e20e | 10148 | xfree (pentry); |
52cf03a1 GV |
10149 | } |
10150 | dpyinfo->color_list = NULL; | |
10151 | if (dpyinfo->palette) | |
10152 | DeleteObject(dpyinfo->palette); | |
10153 | } | |
ee78dc32 | 10154 | xfree (dpyinfo->font_table); |
fbd6baed | 10155 | xfree (dpyinfo->w32_id_name); |
f7737f5d JR |
10156 | |
10157 | /* Destroy row bitmaps. */ | |
10158 | DeleteObject (left_bmp); | |
10159 | DeleteObject (ov_bmp); | |
10160 | DeleteObject (right_bmp); | |
10161 | DeleteObject (continued_bmp); | |
10162 | DeleteObject (continuation_bmp); | |
10163 | DeleteObject (zv_bmp); | |
ee78dc32 GV |
10164 | } |
10165 | \f | |
fbd6baed | 10166 | /* Set up use of W32. */ |
ee78dc32 | 10167 | |
689004fa | 10168 | DWORD w32_msg_worker (); |
ee78dc32 | 10169 | |
791f420f JR |
10170 | void |
10171 | x_flush (struct frame * f) | |
10172 | { /* Nothing to do */ } | |
10173 | ||
10174 | static struct redisplay_interface w32_redisplay_interface = | |
10175 | { | |
10176 | x_produce_glyphs, | |
10177 | x_write_glyphs, | |
10178 | x_insert_glyphs, | |
10179 | x_clear_end_of_line, | |
10180 | x_scroll_run, | |
10181 | x_after_update_window_line, | |
10182 | x_update_window_begin, | |
10183 | x_update_window_end, | |
10184 | w32_cursor_to, | |
10185 | x_flush, | |
ec48c3a7 | 10186 | x_clear_mouse_face, |
791f420f JR |
10187 | x_get_glyph_overhangs, |
10188 | x_fix_overlapping_area | |
10189 | }; | |
10190 | ||
10191 | void | |
fbd6baed GV |
10192 | w32_initialize () |
10193 | { | |
791f420f JR |
10194 | rif = &w32_redisplay_interface; |
10195 | ||
96214669 GV |
10196 | /* MSVC does not type K&R functions with no arguments correctly, and |
10197 | so we must explicitly cast them. */ | |
791f420f JR |
10198 | clear_frame_hook = (void (*)(void)) x_clear_frame; |
10199 | ins_del_lines_hook = x_ins_del_lines; | |
10200 | change_line_highlight_hook = x_change_line_highlight; | |
10201 | delete_glyphs_hook = x_delete_glyphs; | |
96214669 GV |
10202 | ring_bell_hook = (void (*)(void)) w32_ring_bell; |
10203 | reset_terminal_modes_hook = (void (*)(void)) w32_reset_terminal_modes; | |
10204 | set_terminal_modes_hook = (void (*)(void)) w32_set_terminal_modes; | |
791f420f JR |
10205 | update_begin_hook = x_update_begin; |
10206 | update_end_hook = x_update_end; | |
fbd6baed | 10207 | set_terminal_window_hook = w32_set_terminal_window; |
ee78dc32 | 10208 | read_socket_hook = w32_read_socket; |
fbd6baed | 10209 | frame_up_to_date_hook = w32_frame_up_to_date; |
fbd6baed GV |
10210 | reassert_line_highlight_hook = w32_reassert_line_highlight; |
10211 | mouse_position_hook = w32_mouse_position; | |
10212 | frame_rehighlight_hook = w32_frame_rehighlight; | |
10213 | frame_raise_lower_hook = w32_frame_raise_lower; | |
10214 | set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar; | |
10215 | condemn_scroll_bars_hook = w32_condemn_scroll_bars; | |
10216 | redeem_scroll_bar_hook = w32_redeem_scroll_bar; | |
10217 | judge_scroll_bars_hook = w32_judge_scroll_bars; | |
791f420f | 10218 | estimate_mode_line_height_hook = x_estimate_mode_line_height; |
ee78dc32 GV |
10219 | |
10220 | scroll_region_ok = 1; /* we'll scroll partial frames */ | |
10221 | char_ins_del_ok = 0; /* just as fast to write the line */ | |
10222 | line_ins_del_ok = 1; /* we'll just blt 'em */ | |
10223 | fast_clear_end_of_line = 1; /* X does this well */ | |
10224 | memory_below_frame = 0; /* we don't remember what scrolls | |
10225 | off the bottom */ | |
10226 | baud_rate = 19200; | |
10227 | ||
791f420f JR |
10228 | last_tool_bar_item = -1; |
10229 | any_help_event_p = 0; | |
10230 | ||
689004fa GV |
10231 | /* Initialize input mode: interrupt_input off, no flow control, allow |
10232 | 8 bit character input, standard quit char. */ | |
10233 | Fset_input_mode (Qnil, Qnil, make_number (2), Qnil); | |
ee78dc32 GV |
10234 | |
10235 | /* Create the window thread - it will terminate itself or when the app terminates */ | |
10236 | ||
10237 | init_crit (); | |
10238 | ||
10239 | dwMainThreadId = GetCurrentThreadId (); | |
10240 | DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), | |
10241 | GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS); | |
10242 | ||
10243 | /* Wait for thread to start */ | |
10244 | ||
10245 | { | |
10246 | MSG msg; | |
10247 | ||
10248 | PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); | |
10249 | ||
e9e23e23 | 10250 | hWindowsThread = CreateThread (NULL, 0, |
689004fa | 10251 | (LPTHREAD_START_ROUTINE) w32_msg_worker, |
e9e23e23 | 10252 | 0, 0, &dwWindowsThreadId); |
ee78dc32 GV |
10253 | |
10254 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
10255 | } | |
10256 | ||
52cf03a1 | 10257 | /* It is desirable that mainThread should have the same notion of |
e9e23e23 | 10258 | focus window and active window as windowsThread. Unfortunately, the |
52cf03a1 GV |
10259 | following call to AttachThreadInput, which should do precisely what |
10260 | we need, causes major problems when Emacs is linked as a console | |
10261 | program. Unfortunately, we have good reasons for doing that, so | |
e9e23e23 | 10262 | instead we need to send messages to windowsThread to make some API |
52cf03a1 GV |
10263 | calls for us (ones that affect, or depend on, the active/focus |
10264 | window state. */ | |
10265 | #ifdef ATTACH_THREADS | |
e9e23e23 | 10266 | AttachThreadInput (dwMainThreadId, dwWindowsThreadId, TRUE); |
52cf03a1 | 10267 | #endif |
689004fa GV |
10268 | |
10269 | /* Dynamically link to optional system components. */ | |
10270 | { | |
10271 | HANDLE user_lib = LoadLibrary ("user32.dll"); | |
10272 | ||
10273 | #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn) | |
10274 | ||
10275 | /* New proportional scroll bar functions. */ | |
9127e20e JR |
10276 | LOAD_PROC (SetScrollInfo); |
10277 | LOAD_PROC (GetScrollInfo); | |
689004fa GV |
10278 | |
10279 | #undef LOAD_PROC | |
10280 | ||
10281 | FreeLibrary (user_lib); | |
10282 | ||
10283 | /* If using proportional scroll bars, ensure handle is at least 5 pixels; | |
10284 | otherwise use the fixed height. */ | |
10285 | vertical_scroll_bar_min_handle = (pfnSetScrollInfo != NULL) ? 5 : | |
10286 | GetSystemMetrics (SM_CYVTHUMB); | |
10287 | ||
10288 | /* For either kind of scroll bar, take account of the arrows; these | |
10289 | effectively form the border of the main scroll bar range. */ | |
10290 | vertical_scroll_bar_top_border = vertical_scroll_bar_bottom_border | |
10291 | = GetSystemMetrics (SM_CYVSCROLL); | |
10292 | } | |
ee78dc32 GV |
10293 | } |
10294 | ||
10295 | void | |
fbd6baed | 10296 | syms_of_w32term () |
ee78dc32 | 10297 | { |
fbd6baed GV |
10298 | staticpro (&w32_display_name_list); |
10299 | w32_display_name_list = Qnil; | |
ee78dc32 GV |
10300 | |
10301 | staticpro (&last_mouse_scroll_bar); | |
10302 | last_mouse_scroll_bar = Qnil; | |
10303 | ||
10304 | staticpro (&Qvendor_specific_keysyms); | |
10305 | Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); | |
52cf03a1 | 10306 | |
fbd6baed GV |
10307 | DEFVAR_INT ("w32-num-mouse-buttons", |
10308 | &Vw32_num_mouse_buttons, | |
52cf03a1 | 10309 | "Number of physical mouse buttons."); |
fbd6baed | 10310 | Vw32_num_mouse_buttons = Qnil; |
52cf03a1 | 10311 | |
fbd6baed GV |
10312 | DEFVAR_LISP ("w32-swap-mouse-buttons", |
10313 | &Vw32_swap_mouse_buttons, | |
52cf03a1 GV |
10314 | "Swap the mapping of middle and right mouse buttons.\n\ |
10315 | When nil, middle button is mouse-2 and right button is mouse-3."); | |
fbd6baed | 10316 | Vw32_swap_mouse_buttons = Qnil; |
689004fa GV |
10317 | |
10318 | DEFVAR_LISP ("w32-grab-focus-on-raise", | |
10319 | &Vw32_grab_focus_on_raise, | |
10320 | "Raised frame grabs input focus.\n\ | |
10321 | When t, `raise-frame' grabs input focus as well. This fits well\n\ | |
10322 | with the normal Windows click-to-focus policy, but might not be\n\ | |
10323 | desirable when using a point-to-focus policy."); | |
10324 | Vw32_grab_focus_on_raise = Qt; | |
10325 | ||
10326 | DEFVAR_LISP ("w32-capslock-is-shiftlock", | |
10327 | &Vw32_capslock_is_shiftlock, | |
10328 | "Apply CapsLock state to non character input keys.\n\ | |
10329 | When nil, CapsLock only affects normal character input keys."); | |
10330 | Vw32_capslock_is_shiftlock = Qnil; | |
ef0e360f GV |
10331 | |
10332 | DEFVAR_LISP ("w32-recognize-altgr", | |
10333 | &Vw32_recognize_altgr, | |
10334 | "Recognize right-alt and left-ctrl as AltGr.\n\ | |
10335 | When nil, the right-alt and left-ctrl key combination is\n\ | |
10336 | interpreted normally."); | |
10337 | Vw32_recognize_altgr = Qt; | |
bc6af935 | 10338 | |
484fa2c1 GV |
10339 | DEFVAR_BOOL ("w32-enable-unicode-output", |
10340 | &w32_enable_unicode_output, | |
10341 | "Enable the use of Unicode for text output if non-nil.\n\ | |
cabb23bc GV |
10342 | Unicode output may prevent some third party applications for displaying\n\ |
10343 | Far-East Languages on Windows 95/98 from working properly.\n\ | |
10344 | NT uses Unicode internally anyway, so this flag will probably have no\n\ | |
10345 | affect on NT machines."); | |
484fa2c1 | 10346 | w32_enable_unicode_output = 1; |
a1b9438c | 10347 | |
791f420f | 10348 | help_echo = Qnil; |
ec48c3a7 JR |
10349 | staticpro (&help_echo); |
10350 | help_echo_object = Qnil; | |
10351 | staticpro (&help_echo_object); | |
158cba56 JR |
10352 | help_echo_window = Qnil; |
10353 | staticpro (&help_echo_window); | |
791f420f | 10354 | previous_help_echo = Qnil; |
ec48c3a7 | 10355 | staticpro (&previous_help_echo); |
158cba56 | 10356 | help_echo_pos = -1; |
791f420f JR |
10357 | |
10358 | DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p, | |
10359 | "*Non-nil means draw block cursor as wide as the glyph under it.\n\ | |
10360 | For example, if a block cursor is over a tab, it will be drawn as\n\ | |
10361 | wide as that tab on the display."); | |
10362 | x_stretch_cursor_p = 0; | |
10363 | ||
10364 | DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p, | |
10365 | "If not nil, Emacs uses toolkit scroll bars."); | |
10366 | x_toolkit_scroll_bars_p = 1; | |
10367 | ||
10368 | staticpro (&last_mouse_motion_frame); | |
10369 | last_mouse_motion_frame = Qnil; | |
ee78dc32 | 10370 | } |