1 /* Implementation of GUI terminal on the Microsoft W32 API.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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)
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.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "blockinput.h"
47 #include "dispextern.h"
49 #include "termhooks.h"
56 #include "intervals.h"
57 #include "composite.h"
60 #define abs(x) ((x) < 0 ? -(x) : (x))
62 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
67 enum fringe_bitmap_type
70 LEFT_TRUNCATION_BITMAP
,
71 RIGHT_TRUNCATION_BITMAP
,
73 CONTINUED_LINE_BITMAP
,
74 CONTINUATION_LINE_BITMAP
,
78 /* Bitmaps are all unsigned short, as Windows requires bitmap data to
79 be Word aligned. For some reason they are horizontally reflected
80 compared to how they appear on X, so changes in xterm.c should be
83 /* Bitmap drawn to indicate lines not displaying text if
84 `indicate-empty-lines' is non-nil. */
89 static unsigned char zv_bits
[] = {
90 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
91 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
92 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
93 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
94 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
95 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
96 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
97 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
98 static HBITMAP zv_bmp
;
100 /* An arrow like this: `<-'. */
103 #define left_height 8
104 static unsigned short left_bits
[] = {
105 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
106 static HBITMAP left_bmp
;
108 /* Right truncation arrow bitmap `->'. */
110 #define right_width 8
111 #define right_height 8
112 static unsigned short right_bits
[] = {
113 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
114 static HBITMAP right_bmp
;
116 /* Marker for continued lines. */
118 #define continued_width 8
119 #define continued_height 8
120 static unsigned short continued_bits
[] = {
121 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
122 static HBITMAP continued_bmp
;
124 /* Marker for continuation lines. */
126 #define continuation_width 8
127 #define continuation_height 8
128 static unsigned short continuation_bits
[] = {
129 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
130 static HBITMAP continuation_bmp
;
132 /* Overlay arrow bitmap. */
138 static unsigned short ov_bits
[] = {
139 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c};
141 /* A triangular arrow. */
144 static unsigned short ov_bits
[] = {
145 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
147 static HBITMAP ov_bmp
;
149 extern Lisp_Object Qhelp_echo
;
152 /* Non-nil means Emacs uses toolkit scroll bars. */
154 Lisp_Object Vx_toolkit_scroll_bars
;
156 /* If a string, w32_read_socket generates an event to display that string.
157 (The display is done in read_char.) */
159 static Lisp_Object help_echo
;
160 static Lisp_Object help_echo_window
;
161 static Lisp_Object help_echo_object
;
162 static int help_echo_pos
;
164 /* Temporary variable for w32_read_socket. */
166 static Lisp_Object previous_help_echo
;
168 /* Non-zero means that a HELP_EVENT has been generated since Emacs
171 static int any_help_event_p
;
173 /* Non-zero means autoselect window with the mouse cursor. */
175 int x_autoselect_window_p
;
177 /* Non-zero means draw block and hollow cursor as wide as the glyph
178 under it. For example, if a block cursor is over a tab, it will be
179 drawn as wide as that tab on the display. */
181 int x_stretch_cursor_p
;
183 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
185 int x_use_underline_position_properties
;
187 extern unsigned int msh_mousewheel
;
189 extern void free_frame_menubar ();
191 extern int w32_codepage_for_font (char *fontname
);
193 extern glyph_metric
*w32_BDF_TextMetric(bdffont
*fontp
,
194 unsigned char *text
, int dim
);
195 extern Lisp_Object Vwindow_system
;
197 #define x_any_window_to_frame x_window_to_frame
198 #define x_top_window_to_frame x_window_to_frame
201 /* This is display since w32 does not support multiple ones. */
202 struct w32_display_info one_w32_display_info
;
203 struct w32_display_info
*x_display_list
;
205 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
206 one for each element of w32_display_list and in the same order.
207 NAME is the name of the frame.
208 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
209 Lisp_Object w32_display_name_list
;
211 /* Frame being updated by update_frame. This is declared in term.c.
212 This is set by update_begin and looked at by all the
213 w32 functions. It is zero while not inside an update.
214 In that case, the w32 functions assume that `SELECTED_FRAME ()'
215 is the frame to apply to. */
216 extern struct frame
*updating_frame
;
218 /* This is a frame waiting to be autoraised, within w32_read_socket. */
219 struct frame
*pending_autoraise_frame
;
221 /* Nominal cursor position -- where to draw output.
222 HPOS and VPOS are window relative glyph matrix coordinates.
223 X and Y are window relative pixel coordinates. */
225 struct cursor_pos output_cursor
;
227 /* The handle of the frame that currently owns the system caret. */
228 HWND w32_system_caret_hwnd
;
229 int w32_system_caret_height
;
230 int w32_system_caret_x
;
231 int w32_system_caret_y
;
232 int w32_use_visible_system_caret
;
234 /* Flag to enable Unicode output in case users wish to use programs
235 like Twinbridge on '95 rather than installed system level support
236 for Far East languages. */
237 int w32_enable_unicode_output
;
239 DWORD dwWindowsThreadId
= 0;
240 HANDLE hWindowsThread
= NULL
;
241 DWORD dwMainThreadId
= 0;
242 HANDLE hMainThread
= NULL
;
245 /* These definitions are new with Windows 95. */
246 #define SIF_RANGE 0x0001
247 #define SIF_PAGE 0x0002
248 #define SIF_POS 0x0004
249 #define SIF_DISABLENOSCROLL 0x0008
250 #define SIF_TRACKPOS 0x0010
251 #define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
253 typedef struct tagSCROLLINFO
262 } SCROLLINFO
, FAR
*LPSCROLLINFO
;
263 typedef SCROLLINFO CONST FAR
*LPCSCROLLINFO
;
266 /* Dynamic linking to new proportional scroll bar functions. */
267 int (PASCAL
*pfnSetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
, BOOL fRedraw
);
268 BOOL (PASCAL
*pfnGetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
);
270 int vertical_scroll_bar_min_handle
;
271 int vertical_scroll_bar_top_border
;
272 int vertical_scroll_bar_bottom_border
;
274 int last_scroll_bar_drag_pos
;
276 /* Mouse movement. */
278 /* Where the mouse was last time we reported a mouse event. */
280 FRAME_PTR last_mouse_frame
;
281 static RECT last_mouse_glyph
;
282 static Lisp_Object last_mouse_press_frame
;
284 Lisp_Object Vw32_num_mouse_buttons
;
286 Lisp_Object Vw32_swap_mouse_buttons
;
288 /* Control whether x_raise_frame also sets input focus. */
289 Lisp_Object Vw32_grab_focus_on_raise
;
291 /* Control whether Caps Lock affects non-ascii characters. */
292 Lisp_Object Vw32_capslock_is_shiftlock
;
294 /* Control whether right-alt and left-ctrl should be recognized as AltGr. */
295 Lisp_Object Vw32_recognize_altgr
;
297 /* The scroll bar in which the last motion event occurred.
299 If the last motion event occurred in a scroll bar, we set this
300 so w32_mouse_position can know whether to report a scroll bar motion or
303 If the last motion event didn't occur in a scroll bar, we set this
304 to Qnil, to tell w32_mouse_position to return an ordinary motion event. */
305 static Lisp_Object last_mouse_scroll_bar
;
306 static int last_mouse_scroll_bar_pos
;
308 /* This is a hack. We would really prefer that w32_mouse_position would
309 return the time associated with the position it returns, but there
310 doesn't seem to be any way to wrest the time-stamp from the server
311 along with the position query. So, we just keep track of the time
312 of the last movement we received, and return that in hopes that
313 it's somewhat accurate. */
315 static Time last_mouse_movement_time
;
317 /* Incremented by w32_read_socket whenever it really tries to read
321 static int volatile input_signal_count
;
323 static int input_signal_count
;
326 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
328 extern Lisp_Object Qface
, Qmouse_face
;
334 /* A mask of extra modifier bits to put into every keyboard char. */
336 extern int extra_keyboard_modifiers
;
338 /* Enumeration for overriding/changing the face to use for drawing
339 glyphs in x_draw_glyphs. */
341 enum draw_glyphs_face
351 static void x_update_window_end
P_ ((struct window
*, int, int));
352 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
353 void w32_delete_display
P_ ((struct w32_display_info
*));
354 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
355 int *, int *, Lisp_Object
));
356 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
357 int *, int *, int *, int *, int));
358 static void set_output_cursor
P_ ((struct cursor_pos
*));
359 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
360 int *, int *, int *, int));
361 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
362 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
363 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
364 static void w32_handle_tool_bar_click
P_ ((struct frame
*,
365 struct input_event
*));
366 static void show_mouse_face
P_ ((struct w32_display_info
*,
367 enum draw_glyphs_face
));
368 static int cursor_in_mouse_face_p
P_ ((struct window
*));
369 static int clear_mouse_face
P_ ((struct w32_display_info
*));
371 void x_lower_frame
P_ ((struct frame
*));
372 void x_scroll_bar_clear
P_ ((struct frame
*));
373 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
374 void x_raise_frame
P_ ((struct frame
*));
375 void x_set_window_size
P_ ((struct frame
*, int, int, int));
376 void x_wm_set_window_state
P_ ((struct frame
*, int));
377 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
378 void w32_initialize
P_ ((void));
379 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
380 int x_compute_min_glyph_bounds
P_ ((struct frame
*));
381 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
383 enum draw_glyphs_face
));
384 static void x_update_end
P_ ((struct frame
*));
385 static void w32_frame_up_to_date
P_ ((struct frame
*));
386 static void w32_set_terminal_modes
P_ ((void));
387 static void w32_reset_terminal_modes
P_ ((void));
388 static void w32_cursor_to
P_ ((int, int, int, int));
389 static void x_write_glyphs
P_ ((struct glyph
*, int));
390 static void x_clear_end_of_line
P_ ((int));
391 static void x_clear_frame
P_ ((void));
392 static void x_clear_cursor
P_ ((struct window
*));
393 static void frame_highlight
P_ ((struct frame
*));
394 static void frame_unhighlight
P_ ((struct frame
*));
395 static void x_new_focus_frame
P_ ((struct w32_display_info
*,
397 static void w32_frame_rehighlight
P_ ((struct frame
*));
398 static void x_frame_rehighlight
P_ ((struct w32_display_info
*));
399 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
400 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
401 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
402 static int expose_window_tree
P_ ((struct window
*, RECT
*));
403 static int expose_window
P_ ((struct window
*, RECT
*));
404 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
405 RECT
*, enum glyph_row_area
));
406 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
408 void x_update_cursor
P_ ((struct frame
*, int));
409 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
410 static void x_update_window_cursor
P_ ((struct window
*, int));
411 static void x_erase_phys_cursor
P_ ((struct window
*));
412 void x_display_cursor
P_ ((struct window
*w
, int, int, int, int, int));
413 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
414 static void w32_draw_fringe_bitmap
P_ ((struct window
*, HDC hdc
,
416 enum fringe_bitmap_type
, int left_p
));
417 static void w32_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
419 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, RECT
*));
420 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*,
421 struct glyph_row
*));
422 static void notice_overwritten_cursor
P_ ((struct window
*,
424 int, int, int, int));
426 static Lisp_Object Qvendor_specific_keysyms
;
429 /***********************************************************************
431 ***********************************************************************/
435 /* This is a function useful for recording debugging information about
436 the sequence of occurrences in this file. */
444 struct record event_record
[100];
446 int event_record_index
;
448 record_event (locus
, type
)
452 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
453 event_record_index
= 0;
455 event_record
[event_record_index
].locus
= locus
;
456 event_record
[event_record_index
].type
= type
;
457 event_record_index
++;
463 void XChangeGC (void * ignore
, XGCValues
* gc
, unsigned long mask
,
466 if (mask
& GCForeground
)
467 gc
->foreground
= xgcv
->foreground
;
468 if (mask
& GCBackground
)
469 gc
->background
= xgcv
->background
;
471 gc
->font
= xgcv
->font
;
474 XGCValues
*XCreateGC (void * ignore
, Window window
, unsigned long mask
,
477 XGCValues
*gc
= (XGCValues
*) xmalloc (sizeof (XGCValues
));
478 bzero (gc
, sizeof (XGCValues
));
480 XChangeGC (ignore
, gc
, mask
, xgcv
);
485 void XGetGCValues (void* ignore
, XGCValues
*gc
,
486 unsigned long mask
, XGCValues
*xgcv
)
488 XChangeGC (ignore
, xgcv
, mask
, gc
);
492 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
496 HRGN clip_region
= CreateRectRgnIndirect (rect
);
497 SelectClipRgn (hdc
, clip_region
);
498 DeleteObject (clip_region
);
501 SelectClipRgn (hdc
, NULL
);
505 /* Draw a hollow rectangle at the specified position. */
507 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
508 int width
, int height
)
513 hb
= CreateSolidBrush (gc
->background
);
514 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
515 oldhb
= SelectObject (hdc
, hb
);
516 oldhp
= SelectObject (hdc
, hp
);
518 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
520 SelectObject (hdc
, oldhb
);
521 SelectObject (hdc
, oldhp
);
526 /* Draw a filled rectangle at the specified position. */
528 w32_fill_rect (f
, hdc
, pix
, lprect
)
536 hb
= CreateSolidBrush (pix
);
537 FillRect (hdc
, lprect
, hb
);
546 HDC hdc
= get_frame_dc (f
);
548 /* Under certain conditions, this can be called at startup with
549 a console frame pointer before the GUI frame is created. An HDC
550 of 0 indicates this. */
553 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
554 w32_clear_rect (f
, hdc
, &rect
);
557 release_frame_dc (f
, hdc
);
561 /***********************************************************************
562 Starting and ending an update
563 ***********************************************************************/
565 /* Start an update of frame F. This function is installed as a hook
566 for update_begin, i.e. it is called when update_begin is called.
567 This function is called prior to calls to x_update_window_begin for
568 each window being updated. */
574 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
576 if (! FRAME_W32_P (f
))
579 /* Regenerate display palette before drawing if list of requested
580 colors has changed. */
581 if (display_info
->regen_palette
)
583 w32_regenerate_palette (f
);
584 display_info
->regen_palette
= FALSE
;
589 /* Start update of window W. Set the global variable updated_window
590 to the window being updated and set output_cursor to the cursor
594 x_update_window_begin (w
)
597 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
598 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
600 /* Hide the system caret during an update. */
601 if (w32_use_visible_system_caret
)
602 SendMessage (w32_system_caret_hwnd
, WM_EMACS_HIDE_CARET
, 0, 0);
605 set_output_cursor (&w
->cursor
);
609 if (f
== display_info
->mouse_face_mouse_frame
)
611 /* Don't do highlighting for mouse motion during the update. */
612 display_info
->mouse_face_defer
= 1;
614 /* If F needs to be redrawn, simply forget about any prior mouse
616 if (FRAME_GARBAGED_P (f
))
617 display_info
->mouse_face_window
= Qnil
;
619 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
620 their mouse_face_p flag set, which means that they are always
621 unequal to rows in a desired matrix which never have that
622 flag set. So, rows containing mouse-face glyphs are never
623 scrolled, and we don't have to switch the mouse highlight off
624 here to prevent it from being scrolled. */
626 /* Can we tell that this update does not affect the window
627 where the mouse highlight is? If so, no need to turn off.
628 Likewise, don't do anything if the frame is garbaged;
629 in that case, the frame's current matrix that we would use
630 is all wrong, and we will redisplay that line anyway. */
631 if (!NILP (display_info
->mouse_face_window
)
632 && w
== XWINDOW (display_info
->mouse_face_window
))
636 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
637 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
640 if (i
< w
->desired_matrix
->nrows
)
641 clear_mouse_face (display_info
);
650 /* Draw a vertical window border to the right of window W if W doesn't
651 have vertical scroll bars. */
654 x_draw_vertical_border (w
)
657 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
659 /* Redraw borders between horizontally adjacent windows. Don't
660 do it for frames with vertical scroll bars because either the
661 right scroll bar of a window, or the left scroll bar of its
662 neighbor will suffice as a border. */
663 if (!WINDOW_RIGHTMOST_P (w
)
664 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
669 window_box_edges (w
, -1, (int *) &r
.left
, (int *) &r
.top
,
670 (int *) &r
.right
, (int *) &r
.bottom
);
671 r
.left
= r
.right
+ FRAME_X_RIGHT_FRINGE_WIDTH (f
);
672 r
.right
= r
.left
+ 1;
675 hdc
= get_frame_dc (f
);
676 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
677 release_frame_dc (f
, hdc
);
682 /* End update of window W (which is equal to updated_window).
684 Draw vertical borders between horizontally adjacent windows, and
685 display W's cursor if CURSOR_ON_P is non-zero.
687 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
688 glyphs in mouse-face were overwritten. In that case we have to
689 make sure that the mouse-highlight is properly redrawn.
691 W may be a menu bar pseudo-window in case we don't have X toolkit
692 support. Such windows don't have a cursor, so don't display it
696 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
698 int cursor_on_p
, mouse_face_overwritten_p
;
700 struct w32_display_info
*dpyinfo
701 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
703 if (!w
->pseudo_window_p
)
708 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
710 output_cursor
.x
, output_cursor
.y
);
712 x_draw_vertical_border (w
);
716 /* If a row with mouse-face was overwritten, arrange for
717 XTframe_up_to_date to redisplay the mouse highlight. */
718 if (mouse_face_overwritten_p
)
720 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
721 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
722 dpyinfo
->mouse_face_window
= Qnil
;
725 /* Unhide the caret. This won't actually show the cursor, unless it
726 was visible before the corresponding call to HideCaret in
727 x_update_window_begin. */
728 if (w32_use_visible_system_caret
)
729 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
731 updated_window
= NULL
;
735 /* End update of frame F. This function is installed as a hook in
742 if (! FRAME_W32_P (f
))
745 /* Mouse highlight may be displayed again. */
746 FRAME_W32_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
750 /* This function is called from various places in xdisp.c whenever a
751 complete update has been performed. The global variable
752 updated_window is not available here. */
755 w32_frame_up_to_date (f
)
760 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
761 if (dpyinfo
->mouse_face_deferred_gc
762 || f
== dpyinfo
->mouse_face_mouse_frame
)
765 if (dpyinfo
->mouse_face_mouse_frame
)
766 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
767 dpyinfo
->mouse_face_mouse_x
,
768 dpyinfo
->mouse_face_mouse_y
);
769 dpyinfo
->mouse_face_deferred_gc
= 0;
776 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
777 arrow bitmaps, or clear the fringes if no bitmaps are required
778 before DESIRED_ROW is made current. The window being updated is
779 found in updated_window. This function is called from
780 update_window_line only if it is known that there are differences
781 between bitmaps to be drawn between current row and DESIRED_ROW. */
784 x_after_update_window_line (desired_row
)
785 struct glyph_row
*desired_row
;
787 struct window
*w
= updated_window
;
793 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
796 x_draw_row_fringe_bitmaps (w
, desired_row
);
800 /* When a window has disappeared, make sure that no rest of
801 full-width rows stays visible in the internal border. Could
802 check here if updated_window is the leftmost/rightmost window,
803 but I guess it's not worth doing since vertically split windows
804 are almost never used, internal border is rarely set, and the
805 overhead is very small. */
806 if (windows_or_buffers_changed
807 && desired_row
->full_width_p
808 && (f
= XFRAME (w
->frame
),
809 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
811 && (height
= desired_row
->visible_height
,
814 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
815 /* Internal border is drawn below the tool bar. */
816 if (WINDOWP (f
->tool_bar_window
)
817 && w
== XWINDOW (f
->tool_bar_window
))
822 HDC hdc
= get_frame_dc (f
);
823 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
824 w32_clear_area (f
, hdc
, f
->output_data
.w32
->pixel_width
- width
,
826 release_frame_dc (f
, hdc
);
833 /* Draw the bitmap WHICH in one of the left or right fringes of
834 window W. ROW is the glyph row for which to display the bitmap; it
835 determines the vertical position at which the bitmap has to be
839 w32_draw_fringe_bitmap (w
, hdc
, row
, which
, left_p
)
842 struct glyph_row
*row
;
843 enum fringe_bitmap_type which
;
846 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
847 Window window
= FRAME_W32_WINDOW (f
);
855 /* Must clip because of partially visible lines. */
856 w32_clip_to_row (w
, row
, hdc
, 1);
858 /* Convert row to frame coordinates. */
859 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
863 case NO_FRINGE_BITMAP
:
868 case LEFT_TRUNCATION_BITMAP
:
874 case OVERLAY_ARROW_BITMAP
:
880 case RIGHT_TRUNCATION_BITMAP
:
886 case CONTINUED_LINE_BITMAP
:
887 wd
= continued_width
;
888 h
= continued_height
;
889 pixmap
= continued_bmp
;
892 case CONTINUATION_LINE_BITMAP
:
893 wd
= continuation_width
;
894 h
= continuation_height
;
895 pixmap
= continuation_bmp
;
900 h
= zv_height
- (y
% zv_period
);
908 /* Clip bitmap if too high. */
912 /* Set dy to the offset in the row to start drawing the bitmap. */
913 dy
= (row
->height
- h
) / 2;
915 /* Draw the bitmap. */
916 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
917 PREPARE_FACE_FOR_DISPLAY (f
, face
);
919 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
924 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
925 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
926 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
928 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
929 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
931 /* If W has a vertical border to its left, don't draw over it. */
932 int border
= ((XFASTINT (w
->left
) > 0
933 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
935 b1
= (window_box_left (w
, -1)
936 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
938 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
943 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
944 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
945 x
= (window_box_right (w
, -1)
946 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
947 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
949 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
951 b1
= window_box_right (w
, -1);
952 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
958 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
960 w32_fill_area (f
, hdc
, face
->background
,
962 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
965 row
->visible_height
);
968 if (which
== NO_FRINGE_BITMAP
)
971 compat_hdc
= CreateCompatibleDC (hdc
);
974 horig_obj
= SelectObject (compat_hdc
, pixmap
);
975 SetTextColor (hdc
, face
->background
);
976 SetBkColor (hdc
, face
->foreground
);
978 BitBlt (hdc
, x
, y
+ dy
, wd
, h
, compat_hdc
, 0,
979 (which
== ZV_LINE_BITMAP
? (row
->y
% zv_period
) : 0),
982 SelectObject (compat_hdc
, horig_obj
);
983 DeleteDC (compat_hdc
);
988 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
989 function with input blocked. */
992 x_draw_row_fringe_bitmaps (w
, row
)
994 struct glyph_row
*row
;
996 struct frame
*f
= XFRAME (w
->frame
);
997 enum fringe_bitmap_type bitmap
;
1000 xassert (interrupt_input_blocked
);
1002 /* If row is completely invisible, because of vscrolling, we
1003 don't have to draw anything. */
1004 if (row
->visible_height
<= 0)
1007 hdc
= get_frame_dc (f
);
1009 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1011 /* Decide which bitmap to draw in the left fringe. */
1012 if (row
->overlay_arrow_p
)
1013 bitmap
= OVERLAY_ARROW_BITMAP
;
1014 else if (row
->truncated_on_left_p
)
1015 bitmap
= LEFT_TRUNCATION_BITMAP
;
1016 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1017 bitmap
= CONTINUATION_LINE_BITMAP
;
1018 else if (row
->indicate_empty_line_p
)
1019 bitmap
= ZV_LINE_BITMAP
;
1021 bitmap
= NO_FRINGE_BITMAP
;
1023 w32_draw_fringe_bitmap (w
, hdc
, row
, bitmap
, 1);
1026 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1028 /* Decide which bitmap to draw in the right fringe. */
1029 if (row
->truncated_on_right_p
)
1030 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1031 else if (row
->continued_p
)
1032 bitmap
= CONTINUED_LINE_BITMAP
;
1033 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1034 bitmap
= ZV_LINE_BITMAP
;
1036 bitmap
= NO_FRINGE_BITMAP
;
1038 w32_draw_fringe_bitmap (w
, hdc
, row
, bitmap
, 0);
1041 release_frame_dc (f
, hdc
);
1045 /* This is called when starting Emacs and when restarting after
1046 suspend. When starting Emacs, no window is mapped. And nothing
1047 must be done to Emacs's own window if it is suspended (though that
1051 w32_set_terminal_modes (void)
1055 /* This is called when exiting or suspending Emacs. Exiting will make
1056 the W32 windows go away, and suspending requires no action. */
1059 w32_reset_terminal_modes (void)
1065 /***********************************************************************
1067 ***********************************************************************/
1069 /* Set the global variable output_cursor to CURSOR. All cursor
1070 positions are relative to updated_window. */
1073 set_output_cursor (cursor
)
1074 struct cursor_pos
*cursor
;
1076 output_cursor
.hpos
= cursor
->hpos
;
1077 output_cursor
.vpos
= cursor
->vpos
;
1078 output_cursor
.x
= cursor
->x
;
1079 output_cursor
.y
= cursor
->y
;
1083 /* Set a nominal cursor position.
1085 HPOS and VPOS are column/row positions in a window glyph matrix. X
1086 and Y are window text area relative pixel positions.
1088 If this is done during an update, updated_window will contain the
1089 window that is being updated and the position is the future output
1090 cursor position for that window. If updated_window is null, use
1091 selected_window and display the cursor at the given position. */
1094 w32_cursor_to (vpos
, hpos
, y
, x
)
1095 int vpos
, hpos
, y
, x
;
1099 /* If updated_window is not set, work on selected_window. */
1103 w
= XWINDOW (selected_window
);
1105 /* Set the output cursor. */
1106 output_cursor
.hpos
= hpos
;
1107 output_cursor
.vpos
= vpos
;
1108 output_cursor
.x
= x
;
1109 output_cursor
.y
= y
;
1111 /* If not called as part of an update, really display the cursor.
1112 This will also set the cursor position of W. */
1113 if (updated_window
== NULL
)
1116 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1123 /***********************************************************************
1125 ***********************************************************************/
1127 /* Function prototypes of this page. */
1129 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1133 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1134 int, wchar_t *, int));
1135 static XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*,
1137 enum w32_char_font_type
));
1138 static enum w32_char_font_type
1139 w32_encode_char
P_ ((int, wchar_t *, struct font_info
*, int *));
1140 static void x_append_glyph
P_ ((struct it
*));
1141 static void x_append_composite_glyph
P_ ((struct it
*));
1142 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1144 static void x_produce_glyphs
P_ ((struct it
*));
1145 static void x_produce_image_glyph
P_ ((struct it
*it
));
1148 /* Dealing with bits of wchar_t as if they were an XChar2B. */
1149 #define BUILD_WCHAR_T(byte1, byte2) \
1150 ((wchar_t)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff)))
1154 (((ch) & 0xff00) >> 8)
1160 /* Get metrics of character CHAR2B in FONT. Value is always non-null.
1161 If CHAR2B is not contained in FONT, the font's default character
1162 metric is returned. */
1165 w32_bdf_per_char_metric (font
, char2b
, dim
, pcm
)
1171 glyph_metric
* bdf_metric
;
1175 buf
[0] = (char)(*char2b
);
1178 buf
[0] = BYTE1 (*char2b
);
1179 buf
[1] = BYTE2 (*char2b
);
1182 bdf_metric
= w32_BDF_TextMetric (font
->bdf
, buf
, dim
);
1186 pcm
->width
= bdf_metric
->dwidth
;
1187 pcm
->lbearing
= bdf_metric
->bbox
;
1188 pcm
->rbearing
= bdf_metric
->dwidth
1189 - (bdf_metric
->bbox
+ bdf_metric
->bbw
);
1190 pcm
->ascent
= bdf_metric
->bboy
+ bdf_metric
->bbh
;
1191 pcm
->descent
= -bdf_metric
->bboy
;
1200 w32_native_per_char_metric (font
, char2b
, font_type
, pcm
)
1203 enum w32_char_font_type font_type
;
1206 HDC hdc
= GetDC (NULL
);
1208 BOOL retval
= FALSE
;
1210 xassert (font
&& char2b
);
1211 xassert (font
->hfont
);
1212 xassert (font_type
== UNICODE_FONT
|| font_type
== ANSI_FONT
);
1214 old_font
= SelectObject (hdc
, font
->hfont
);
1216 if ((font
->tm
.tmPitchAndFamily
& TMPF_TRUETYPE
) != 0)
1220 if (font_type
== UNICODE_FONT
)
1221 retval
= GetCharABCWidthsW (hdc
, *char2b
, *char2b
, &char_widths
);
1223 retval
= GetCharABCWidthsA (hdc
, *char2b
, *char2b
, &char_widths
);
1228 /* Disabled until we can find a way to get the right results
1229 on all versions of Windows. */
1231 /* Don't trust the ABC widths. For synthesized fonts they are
1232 wrong, and so is the result of GetCharWidth()! */
1234 GetCharWidth (hdc
, *char2b
, *char2b
, &real_width
);
1236 pcm
->width
= char_widths
.abcA
+ char_widths
.abcB
+ char_widths
.abcC
;
1238 /* As far as I can tell, this is the best way to determine what
1239 ExtTextOut will do with the broken font. */
1240 if (pcm
->width
!= real_width
)
1241 pcm
->width
= (pcm
->width
+ real_width
) / 2;
1243 pcm
->lbearing
= char_widths
.abcA
;
1244 pcm
->rbearing
= char_widths
.abcA
+ char_widths
.abcB
;
1245 pcm
->ascent
= FONT_BASE (font
);
1246 pcm
->descent
= FONT_DESCENT (font
);
1252 /* Either font is not a True-type font, or GetCharABCWidthsW
1253 failed (it is not supported on Windows 9x for instance), so we
1254 can't determine the full info we would like. All is not lost
1255 though - we can call GetTextExtentPoint32 to get rbearing and
1256 deduce width based on the font's per-string overhang. lbearing
1257 is assumed to be zero. */
1259 /* TODO: Some Thai characters (and other composites if Windows
1260 supports them) do have lbearing, and report their total width
1261 as zero. Need some way of handling them when
1262 GetCharABCWidthsW fails. */
1265 if (font_type
== UNICODE_FONT
)
1266 retval
= GetTextExtentPoint32W (hdc
, char2b
, 1, &sz
);
1268 retval
= GetTextExtentPoint32A (hdc
, (char*)char2b
, 1, &sz
);
1272 pcm
->width
= sz
.cx
- font
->tm
.tmOverhang
;
1273 pcm
->rbearing
= sz
.cx
;
1275 pcm
->ascent
= FONT_BASE (font
);
1276 pcm
->descent
= FONT_DESCENT (font
);
1281 if (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0)
1286 SelectObject (hdc
, old_font
);
1287 ReleaseDC (NULL
, hdc
);
1293 static XCharStruct
*
1294 w32_per_char_metric (font
, char2b
, font_type
)
1297 enum w32_char_font_type font_type
;
1299 /* The result metric information. */
1303 xassert (font
&& char2b
);
1304 xassert (font_type
!= UNKNOWN_FONT
);
1306 /* Handle the common cases quickly. */
1307 if (!font
->bdf
&& font
->per_char
== NULL
)
1308 /* TODO: determine whether char2b exists in font? */
1309 return &font
->max_bounds
;
1310 else if (!font
->bdf
&& *char2b
< 128)
1311 return &font
->per_char
[*char2b
];
1313 pcm
= &font
->scratch
;
1315 if (font_type
== BDF_1D_FONT
)
1316 retval
= w32_bdf_per_char_metric (font
, char2b
, 1, pcm
);
1317 else if (font_type
== BDF_2D_FONT
)
1318 retval
= w32_bdf_per_char_metric (font
, char2b
, 2, pcm
);
1320 retval
= w32_native_per_char_metric (font
, char2b
, font_type
, pcm
);
1329 w32_cache_char_metrics (font
)
1332 wchar_t char2b
= L
'x';
1334 /* Cache char metrics for the common cases. */
1337 /* TODO: determine whether font is fixed-pitch. */
1338 if (!w32_bdf_per_char_metric (font
, &char2b
, 1, &font
->max_bounds
))
1340 /* Use the font width and height as max bounds, as not all BDF
1341 fonts contain the letter 'x'. */
1342 font
->max_bounds
.width
= FONT_MAX_WIDTH (font
);
1343 font
->max_bounds
.lbearing
= -font
->bdf
->llx
;
1344 font
->max_bounds
.rbearing
= FONT_MAX_WIDTH (font
) - font
->bdf
->urx
;
1345 font
->max_bounds
.ascent
= FONT_BASE (font
);
1346 font
->max_bounds
.descent
= FONT_DESCENT (font
);
1351 if (((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
) != 0)
1352 /* Some fonts (eg DBCS fonts) are marked as fixed width even
1353 though they contain characters of different widths. */
1354 || (font
->tm
.tmMaxCharWidth
!= font
->tm
.tmAveCharWidth
))
1356 /* Font is not fixed pitch, so cache per_char info for the
1357 ASCII characters. It would be much more work, and probably
1358 not worth it, to cache other chars, since we may change
1359 between using Unicode and ANSI text drawing functions at
1363 font
->per_char
= xmalloc (128 * sizeof(XCharStruct
));
1364 for (i
= 0; i
< 128; i
++)
1367 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1368 &font
->per_char
[i
]);
1372 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1378 /* Determine if a font is double byte. */
1379 int w32_font_is_double_byte (XFontStruct
*font
)
1381 return font
->double_byte_p
;
1386 w32_use_unicode_for_codepage (codepage
)
1389 /* If the current codepage is supported, use Unicode for output. */
1390 return (w32_enable_unicode_output
1391 && codepage
!= CP_8BIT
1392 && (codepage
== CP_UNICODE
|| IsValidCodePage (codepage
)));
1395 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1396 the two-byte form of C. Encoding is returned in *CHAR2B. */
1398 static INLINE
enum w32_char_font_type
1399 w32_encode_char (c
, char2b
, font_info
, two_byte_p
)
1402 struct font_info
*font_info
;
1405 int charset
= CHAR_CHARSET (c
);
1409 XFontStruct
*font
= font_info
->font
;
1411 xassert (two_byte_p
);
1413 *two_byte_p
= w32_font_is_double_byte (font
);
1415 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1416 This may be either a program in a special encoder language or a
1418 if (font_info
->font_encoder
)
1420 /* It's a program. */
1421 struct ccl_program
*ccl
= font_info
->font_encoder
;
1423 if (CHARSET_DIMENSION (charset
) == 1)
1425 ccl
->reg
[0] = charset
;
1426 ccl
->reg
[1] = BYTE2 (*char2b
);
1430 ccl
->reg
[0] = charset
;
1431 ccl
->reg
[1] = BYTE1 (*char2b
);
1432 ccl
->reg
[2] = BYTE2 (*char2b
);
1435 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1437 /* We assume that MSBs are appropriately set/reset by CCL
1439 if (!*two_byte_p
) /* 1-byte font */
1440 *char2b
= BUILD_WCHAR_T (0, ccl
->reg
[1]);
1442 *char2b
= BUILD_WCHAR_T (ccl
->reg
[1], ccl
->reg
[2]);
1444 else if (font_info
->encoding
[charset
])
1446 /* Fixed encoding scheme. See fontset.h for the meaning of the
1447 encoding numbers. */
1448 int enc
= font_info
->encoding
[charset
];
1450 if ((enc
== 1 || enc
== 2)
1451 && CHARSET_DIMENSION (charset
) == 2)
1452 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
) | 0x80, BYTE2 (*char2b
));
1454 if (enc
== 1 || enc
== 3
1455 || (enc
== 4 && CHARSET_DIMENSION (charset
) == 1))
1456 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
), BYTE2 (*char2b
) | 0x80);
1461 ENCODE_SJIS (BYTE1 (*char2b
), BYTE2 (*char2b
),
1463 *char2b
= BUILD_WCHAR_T (sjis1
, sjis2
);
1466 codepage
= font_info
->codepage
;
1468 /* If charset is not ASCII or Latin-1, may need to move it into
1470 if ( font
&& !font
->bdf
&& w32_use_unicode_for_codepage (codepage
)
1471 && charset
!= CHARSET_ASCII
&& charset
!= charset_latin_iso8859_1
1472 && charset
!= CHARSET_8_BIT_CONTROL
&& charset
!= CHARSET_8_BIT_GRAPHIC
)
1475 temp
[0] = BYTE1 (*char2b
);
1476 temp
[1] = BYTE2 (*char2b
);
1478 if (codepage
!= CP_UNICODE
)
1481 MultiByteToWideChar (codepage
, 0, temp
, 2, char2b
, 1);
1483 MultiByteToWideChar (codepage
, 0, temp
+1, 1, char2b
, 1);
1489 return UNKNOWN_FONT
;
1490 else if (font
->bdf
&& CHARSET_DIMENSION (charset
) == 1)
1495 return UNICODE_FONT
;
1501 /* Get face and two-byte form of character C in face FACE_ID on frame
1502 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1503 means we want to display multibyte text. Value is a pointer to a
1504 realized face that is ready for display. */
1506 static INLINE
struct face
*
1507 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1513 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1517 /* Unibyte case. We don't have to encode, but we have to make
1518 sure to use a face suitable for unibyte. */
1519 *char2b
= BUILD_WCHAR_T (0, c
);
1520 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1521 face
= FACE_FROM_ID (f
, face_id
);
1523 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1525 /* Case of ASCII in a face known to fit ASCII. */
1526 *char2b
= BUILD_WCHAR_T (0, c
);
1530 int c1
, c2
, charset
;
1532 /* Split characters into bytes. If c2 is -1 afterwards, C is
1533 really a one-byte character so that byte1 is zero. */
1534 SPLIT_CHAR (c
, charset
, c1
, c2
);
1536 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1538 *char2b
= BUILD_WCHAR_T (0, c1
);
1540 /* Maybe encode the character in *CHAR2B. */
1541 if (face
->font
!= NULL
)
1543 struct font_info
*font_info
1544 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1546 w32_encode_char (c
, char2b
, font_info
, &multibyte_p
);
1550 /* Make sure X resources of the face are allocated. */
1551 xassert (face
!= NULL
);
1552 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1558 /* Get face and two-byte form of character glyph GLYPH on frame F.
1559 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1560 a pointer to a realized face that is ready for display. */
1562 static INLINE
struct face
*
1563 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1565 struct glyph
*glyph
;
1572 xassert (glyph
->type
== CHAR_GLYPH
);
1573 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1578 two_byte_p
= &dummy
;
1580 if (!glyph
->multibyte_p
)
1582 /* Unibyte case. We don't have to encode, but we have to make
1583 sure to use a face suitable for unibyte. */
1584 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1586 else if (glyph
->u
.ch
< 128
1587 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1589 /* Case of ASCII in a face known to fit ASCII. */
1590 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1594 int c1
, c2
, charset
;
1596 /* Split characters into bytes. If c2 is -1 afterwards, C is
1597 really a one-byte character so that byte1 is zero. */
1598 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1600 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1602 *char2b
= BUILD_WCHAR_T (0, c1
);
1604 /* Maybe encode the character in *CHAR2B. */
1605 if (charset
!= CHARSET_ASCII
)
1607 struct font_info
*font_info
1608 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1611 glyph
->w32_font_type
1612 = w32_encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
1617 /* Make sure X resources of the face are allocated. */
1618 xassert (face
!= NULL
);
1619 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1624 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1625 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1631 struct glyph
*glyph
;
1632 enum glyph_row_area area
= it
->area
;
1634 xassert (it
->glyph_row
);
1635 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1637 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1638 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1640 glyph
->charpos
= CHARPOS (it
->position
);
1641 glyph
->object
= it
->object
;
1642 glyph
->pixel_width
= it
->pixel_width
;
1643 glyph
->voffset
= it
->voffset
;
1644 glyph
->type
= CHAR_GLYPH
;
1645 glyph
->multibyte_p
= it
->multibyte_p
;
1646 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1647 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1648 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1649 || it
->phys_descent
> it
->descent
);
1650 glyph
->padding_p
= 0;
1651 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1652 glyph
->face_id
= it
->face_id
;
1653 glyph
->u
.ch
= it
->char_to_display
;
1654 glyph
->w32_font_type
= UNKNOWN_FONT
;
1655 ++it
->glyph_row
->used
[area
];
1659 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1660 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1663 x_append_composite_glyph (it
)
1666 struct glyph
*glyph
;
1667 enum glyph_row_area area
= it
->area
;
1669 xassert (it
->glyph_row
);
1671 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1672 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1674 glyph
->charpos
= CHARPOS (it
->position
);
1675 glyph
->object
= it
->object
;
1676 glyph
->pixel_width
= it
->pixel_width
;
1677 glyph
->voffset
= it
->voffset
;
1678 glyph
->type
= COMPOSITE_GLYPH
;
1679 glyph
->multibyte_p
= it
->multibyte_p
;
1680 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1681 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1682 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1683 || it
->phys_descent
> it
->descent
);
1684 glyph
->padding_p
= 0;
1685 glyph
->glyph_not_available_p
= 0;
1686 glyph
->face_id
= it
->face_id
;
1687 glyph
->u
.cmp_id
= it
->cmp_id
;
1688 glyph
->w32_font_type
= UNKNOWN_FONT
;
1689 ++it
->glyph_row
->used
[area
];
1694 /* Change IT->ascent and IT->height according to the setting of
1698 take_vertical_position_into_account (it
)
1703 if (it
->voffset
< 0)
1704 /* Increase the ascent so that we can display the text higher
1706 it
->ascent
+= abs (it
->voffset
);
1708 /* Increase the descent so that we can display the text lower
1710 it
->descent
+= it
->voffset
;
1715 /* Produce glyphs/get display metrics for the image IT is loaded with.
1716 See the description of struct display_iterator in dispextern.h for
1717 an overview of struct display_iterator. */
1720 x_produce_image_glyph (it
)
1726 xassert (it
->what
== IT_IMAGE
);
1728 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1729 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1732 /* Make sure X resources of the face and image are loaded. */
1733 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1734 prepare_image_for_display (it
->f
, img
);
1736 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1737 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1738 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1742 if (face
->box
!= FACE_NO_BOX
)
1744 if (face
->box_line_width
> 0)
1746 it
->ascent
+= face
->box_line_width
;
1747 it
->descent
+= face
->box_line_width
;
1750 if (it
->start_of_box_run_p
)
1751 it
->pixel_width
+= abs (face
->box_line_width
);
1752 if (it
->end_of_box_run_p
)
1753 it
->pixel_width
+= abs (face
->box_line_width
);
1756 take_vertical_position_into_account (it
);
1760 struct glyph
*glyph
;
1761 enum glyph_row_area area
= it
->area
;
1763 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1764 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1766 glyph
->charpos
= CHARPOS (it
->position
);
1767 glyph
->object
= it
->object
;
1768 glyph
->pixel_width
= it
->pixel_width
;
1769 glyph
->voffset
= it
->voffset
;
1770 glyph
->type
= IMAGE_GLYPH
;
1771 glyph
->multibyte_p
= it
->multibyte_p
;
1772 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1773 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1774 glyph
->overlaps_vertically_p
= 0;
1775 glyph
->padding_p
= 0;
1776 glyph
->glyph_not_available_p
= 0;
1777 glyph
->face_id
= it
->face_id
;
1778 glyph
->u
.img_id
= img
->id
;
1779 glyph
->w32_font_type
= UNKNOWN_FONT
;
1780 ++it
->glyph_row
->used
[area
];
1786 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1787 of the glyph, WIDTH and HEIGHT are the width and height of the
1788 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1789 ascent of the glyph (0 <= ASCENT <= 1). */
1792 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1798 struct glyph
*glyph
;
1799 enum glyph_row_area area
= it
->area
;
1801 xassert (ascent
>= 0 && ascent
<= 1);
1803 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1804 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1806 glyph
->charpos
= CHARPOS (it
->position
);
1807 glyph
->object
= object
;
1808 glyph
->pixel_width
= width
;
1809 glyph
->voffset
= it
->voffset
;
1810 glyph
->type
= STRETCH_GLYPH
;
1811 glyph
->multibyte_p
= it
->multibyte_p
;
1812 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1813 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1814 glyph
->overlaps_vertically_p
= 0;
1815 glyph
->padding_p
= 0;
1816 glyph
->glyph_not_available_p
= 0;
1817 glyph
->face_id
= it
->face_id
;
1818 glyph
->u
.stretch
.ascent
= height
* ascent
;
1819 glyph
->u
.stretch
.height
= height
;
1820 glyph
->w32_font_type
= UNKNOWN_FONT
;
1821 ++it
->glyph_row
->used
[area
];
1826 /* Produce a stretch glyph for iterator IT. IT->object is the value
1827 of the glyph property displayed. The value must be a list
1828 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1831 1. `:width WIDTH' specifies that the space should be WIDTH *
1832 canonical char width wide. WIDTH may be an integer or floating
1835 2. `:relative-width FACTOR' specifies that the width of the stretch
1836 should be computed from the width of the first character having the
1837 `glyph' property, and should be FACTOR times that width.
1839 3. `:align-to HPOS' specifies that the space should be wide enough
1840 to reach HPOS, a value in canonical character units.
1842 Exactly one of the above pairs must be present.
1844 4. `:height HEIGHT' specifies that the height of the stretch produced
1845 should be HEIGHT, measured in canonical character units.
1847 5. `:relative-height FACTOR' specifies that the height of the
1848 stretch should be FACTOR times the height of the characters having
1851 Either none or exactly one of 4 or 5 must be present.
1853 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1854 of the stretch should be used for the ascent of the stretch.
1855 ASCENT must be in the range 0 <= ASCENT <= 100. */
1858 ((INTEGERP (X) || FLOATP (X)) \
1864 x_produce_stretch_glyph (it
)
1867 /* (space :width WIDTH :height HEIGHT. */
1869 extern Lisp_Object Qspace
;
1871 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1872 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1873 extern Lisp_Object QCalign_to
;
1874 Lisp_Object prop
, plist
;
1875 double width
= 0, height
= 0, ascent
= 0;
1876 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1877 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1879 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1881 /* List should start with `space'. */
1882 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1883 plist
= XCDR (it
->object
);
1885 /* Compute the width of the stretch. */
1886 if (prop
= Fplist_get (plist
, QCwidth
),
1888 /* Absolute width `:width WIDTH' specified and valid. */
1889 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1890 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1893 /* Relative width `:relative-width FACTOR' specified and valid.
1894 Compute the width of the characters having the `glyph'
1897 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1900 if (it
->multibyte_p
)
1902 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1903 - IT_BYTEPOS (*it
));
1904 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1907 it2
.c
= *p
, it2
.len
= 1;
1909 it2
.glyph_row
= NULL
;
1910 it2
.what
= IT_CHARACTER
;
1911 x_produce_glyphs (&it2
);
1912 width
= NUMVAL (prop
) * it2
.pixel_width
;
1914 else if (prop
= Fplist_get (plist
, QCalign_to
),
1916 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1918 /* Nothing specified -> width defaults to canonical char width. */
1919 width
= CANON_X_UNIT (it
->f
);
1921 /* Compute height. */
1922 if (prop
= Fplist_get (plist
, QCheight
),
1924 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1925 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1927 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1929 height
= FONT_HEIGHT (font
);
1931 /* Compute percentage of height used for ascent. If
1932 `:ascent ASCENT' is present and valid, use that. Otherwise,
1933 derive the ascent from the font in use. */
1934 if (prop
= Fplist_get (plist
, QCascent
),
1935 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1936 ascent
= NUMVAL (prop
) / 100.0;
1938 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
1947 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1948 if (!STRINGP (object
))
1949 object
= it
->w
->buffer
;
1950 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1953 it
->pixel_width
= width
;
1954 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1955 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1958 if (face
->box
!= FACE_NO_BOX
)
1960 if (face
->box_line_width
> 0)
1962 it
->ascent
+= face
->box_line_width
;
1963 it
->descent
+= face
->box_line_width
;
1966 if (it
->start_of_box_run_p
)
1967 it
->pixel_width
+= abs (face
->box_line_width
);
1968 if (it
->end_of_box_run_p
)
1969 it
->pixel_width
+= abs (face
->box_line_width
);
1972 take_vertical_position_into_account (it
);
1975 /* Return proper value to be used as baseline offset of font that has
1976 ASCENT and DESCENT to draw characters by the font at the vertical
1977 center of the line of frame F.
1979 Here, out task is to find the value of BOFF in the following figure;
1981 -------------------------+-----------+-
1982 -+-+---------+-+ | |
1984 | | | | F_ASCENT F_HEIGHT
1987 | | |-|-+------+-----------|------- baseline
1989 | |---------|-+-+ | |
1991 -+-+---------+-+ F_DESCENT |
1992 -------------------------+-----------+-
1994 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1995 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1996 DESCENT = FONT->descent
1997 HEIGHT = FONT_HEIGHT (FONT)
1998 F_DESCENT = (F->output_data.x->font->descent
1999 - F->output_data.x->baseline_offset)
2000 F_HEIGHT = FRAME_LINE_HEIGHT (F)
2003 #define VCENTER_BASELINE_OFFSET(FONT, F) \
2004 (FONT_DESCENT (FONT) \
2005 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
2006 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
2007 - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
2009 /* Produce glyphs/get display metrics for the display element IT is
2010 loaded with. See the description of struct display_iterator in
2011 dispextern.h for an overview of struct display_iterator. */
2014 x_produce_glyphs (it
)
2017 it
->glyph_not_available_p
= 0;
2019 if (it
->what
== IT_CHARACTER
)
2023 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2025 int font_not_found_p
;
2026 struct font_info
*font_info
;
2027 int boff
; /* baseline offset */
2028 /* We may change it->multibyte_p upon unibyte<->multibyte
2029 conversion. So, save the current value now and restore it
2032 Note: It seems that we don't have to record multibyte_p in
2033 struct glyph because the character code itself tells if or
2034 not the character is multibyte. Thus, in the future, we must
2035 consider eliminating the field `multibyte_p' in the struct
2038 int saved_multibyte_p
= it
->multibyte_p
;
2040 /* Maybe translate single-byte characters to multibyte, or the
2042 it
->char_to_display
= it
->c
;
2043 if (!ASCII_BYTE_P (it
->c
))
2045 if (unibyte_display_via_language_environment
2046 && SINGLE_BYTE_CHAR_P (it
->c
)
2048 || !NILP (Vnonascii_translation_table
)))
2050 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2051 it
->multibyte_p
= 1;
2052 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2053 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2055 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
2056 && !it
->multibyte_p
)
2058 it
->multibyte_p
= 1;
2059 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2060 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2064 /* Get font to use. Encode IT->char_to_display. */
2065 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2066 it
->face_id
, &char2b
,
2070 /* When no suitable font found, use the default font. */
2071 font_not_found_p
= font
== NULL
;
2072 if (font_not_found_p
)
2074 font
= FRAME_FONT (it
->f
);
2075 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2080 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2081 boff
= font_info
->baseline_offset
;
2082 if (font_info
->vertical_centering
)
2083 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2086 if (it
->char_to_display
>= ' '
2087 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
2089 /* Either unibyte or ASCII. */
2094 pcm
= w32_per_char_metric (font
, &char2b
,
2095 font
->bdf
? BDF_1D_FONT
: ANSI_FONT
);
2096 it
->ascent
= FONT_BASE (font
) + boff
;
2097 it
->descent
= FONT_DESCENT (font
) - boff
;
2101 it
->phys_ascent
= pcm
->ascent
+ boff
;
2102 it
->phys_descent
= pcm
->descent
- boff
;
2103 it
->pixel_width
= pcm
->width
;
2107 it
->glyph_not_available_p
= 1;
2108 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2109 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2110 it
->pixel_width
= FONT_WIDTH (font
);
2113 /* If this is a space inside a region of text with
2114 `space-width' property, change its width. */
2115 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
2117 it
->pixel_width
*= XFLOATINT (it
->space_width
);
2119 /* If face has a box, add the box thickness to the character
2120 height. If character has a box line to the left and/or
2121 right, add the box line width to the character's width. */
2122 if (face
->box
!= FACE_NO_BOX
)
2124 int thick
= face
->box_line_width
;
2128 it
->ascent
+= thick
;
2129 it
->descent
+= thick
;
2134 if (it
->start_of_box_run_p
)
2135 it
->pixel_width
+= thick
;
2136 if (it
->end_of_box_run_p
)
2137 it
->pixel_width
+= thick
;
2140 /* If face has an overline, add the height of the overline
2141 (1 pixel) and a 1 pixel margin to the character height. */
2142 if (face
->overline_p
)
2145 take_vertical_position_into_account (it
);
2147 /* If we have to actually produce glyphs, do it. */
2152 /* Translate a space with a `space-width' property
2153 into a stretch glyph. */
2154 double ascent
= (double) FONT_BASE (font
)
2155 / FONT_HEIGHT (font
);
2156 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2157 it
->ascent
+ it
->descent
, ascent
);
2160 x_append_glyph (it
);
2162 /* If characters with lbearing or rbearing are displayed
2163 in this line, record that fact in a flag of the
2164 glyph row. This is used to optimize X output code. */
2165 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
2166 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2169 else if (it
->char_to_display
== '\n')
2171 /* A newline has no width but we need the height of the line. */
2172 it
->pixel_width
= 0;
2174 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2175 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2177 if (face
->box
!= FACE_NO_BOX
2178 && face
->box_line_width
> 0)
2180 it
->ascent
+= face
->box_line_width
;
2181 it
->descent
+= face
->box_line_width
;
2184 else if (it
->char_to_display
== '\t')
2186 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
2187 int x
= it
->current_x
+ it
->continuation_lines_width
;
2188 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
2190 /* If the distance from the current position to the next tab
2191 stop is less than a canonical character width, use the
2192 tab stop after that. */
2193 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
2194 next_tab_x
+= tab_width
;
2196 it
->pixel_width
= next_tab_x
- x
;
2198 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2199 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2203 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2204 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2205 it
->ascent
+ it
->descent
, ascent
);
2210 /* A multi-byte character.
2211 If we found a font, this font should give us the right
2212 metrics. If we didn't find a font, use the frame's
2213 default font and calculate the width of the character
2214 from the charset width; this is what old redisplay code
2216 enum w32_char_font_type type
;
2218 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2223 type
= UNICODE_FONT
;
2225 pcm
= w32_per_char_metric (font
, &char2b
, type
);
2227 if (font_not_found_p
|| !pcm
)
2229 int charset
= CHAR_CHARSET (it
->char_to_display
);
2231 it
->glyph_not_available_p
= 1;
2232 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2233 * CHARSET_WIDTH (charset
));
2234 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2235 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2239 it
->pixel_width
= pcm
->width
;
2240 it
->phys_ascent
= pcm
->ascent
+ boff
;
2241 it
->phys_descent
= pcm
->descent
- boff
;
2243 && (pcm
->lbearing
< 0
2244 || pcm
->rbearing
> pcm
->width
))
2245 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2248 it
->ascent
= FONT_BASE (font
) + boff
;
2249 it
->descent
= FONT_DESCENT (font
) - boff
;
2250 if (face
->box
!= FACE_NO_BOX
)
2252 int thick
= face
->box_line_width
;
2256 it
->ascent
+= thick
;
2257 it
->descent
+= thick
;
2262 if (it
->start_of_box_run_p
)
2263 it
->pixel_width
+= thick
;
2264 if (it
->end_of_box_run_p
)
2265 it
->pixel_width
+= thick
;
2268 /* If face has an overline, add the height of the overline
2269 (1 pixel) and a 1 pixel margin to the character height. */
2270 if (face
->overline_p
)
2273 take_vertical_position_into_account (it
);
2276 x_append_glyph (it
);
2278 it
->multibyte_p
= saved_multibyte_p
;
2280 else if (it
->what
== IT_COMPOSITION
)
2282 /* Note: A composition is represented as one glyph in the
2283 glyph matrix. There are no padding glyphs. */
2286 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2288 int font_not_found_p
;
2289 struct font_info
*font_info
;
2290 int boff
; /* baseline offset */
2291 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2293 /* Maybe translate single-byte characters to multibyte. */
2294 it
->char_to_display
= it
->c
;
2295 if (unibyte_display_via_language_environment
2296 && SINGLE_BYTE_CHAR_P (it
->c
)
2299 && !NILP (Vnonascii_translation_table
))))
2301 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2304 /* Get face and font to use. Encode IT->char_to_display. */
2305 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2306 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2307 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2308 it
->face_id
, &char2b
, it
->multibyte_p
);
2311 /* When no suitable font found, use the default font. */
2312 font_not_found_p
= font
== NULL
;
2313 if (font_not_found_p
)
2315 font
= FRAME_FONT (it
->f
);
2316 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2321 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2322 boff
= font_info
->baseline_offset
;
2323 if (font_info
->vertical_centering
)
2324 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2327 /* There are no padding glyphs, so there is only one glyph to
2328 produce for the composition. Important is that pixel_width,
2329 ascent and descent are the values of what is drawn by
2330 draw_glyphs (i.e. the values of the overall glyphs composed). */
2333 /* If we have not yet calculated pixel size data of glyphs of
2334 the composition for the current face font, calculate them
2335 now. Theoretically, we have to check all fonts for the
2336 glyphs, but that requires much time and memory space. So,
2337 here we check only the font of the first glyph. This leads
2338 to incorrect display very rarely, and C-l (recenter) can
2339 correct the display anyway. */
2340 if (cmp
->font
!= (void *) font
)
2342 /* Ascent and descent of the font of the first character of
2343 this composition (adjusted by baseline offset). Ascent
2344 and descent of overall glyphs should not be less than
2345 them respectively. */
2346 int font_ascent
= FONT_BASE (font
) + boff
;
2347 int font_descent
= FONT_DESCENT (font
) - boff
;
2348 /* Bounding box of the overall glyphs. */
2349 int leftmost
, rightmost
, lowest
, highest
;
2350 int i
, width
, ascent
, descent
;
2351 enum w32_char_font_type font_type
;
2353 cmp
->font
= (void *) font
;
2355 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2356 font_type
= BDF_1D_FONT
;
2358 font_type
= BDF_2D_FONT
;
2360 font_type
= UNICODE_FONT
;
2362 /* Initialize the bounding box. */
2364 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2367 ascent
= pcm
->ascent
;
2368 descent
= pcm
->descent
;
2372 width
= FONT_WIDTH (font
);
2373 ascent
= FONT_BASE (font
);
2374 descent
= FONT_DESCENT (font
);
2378 lowest
= - descent
+ boff
;
2379 highest
= ascent
+ boff
;
2383 && font_info
->default_ascent
2384 && CHAR_TABLE_P (Vuse_default_ascent
)
2385 && !NILP (Faref (Vuse_default_ascent
,
2386 make_number (it
->char_to_display
))))
2387 highest
= font_info
->default_ascent
+ boff
;
2389 /* Draw the first glyph at the normal position. It may be
2390 shifted to right later if some other glyphs are drawn at
2392 cmp
->offsets
[0] = 0;
2393 cmp
->offsets
[1] = boff
;
2395 /* Set cmp->offsets for the remaining glyphs. */
2396 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2398 int left
, right
, btm
, top
;
2399 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2400 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2402 face
= FACE_FROM_ID (it
->f
, face_id
);
2403 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2408 font
= FRAME_FONT (it
->f
);
2409 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2415 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2416 boff
= font_info
->baseline_offset
;
2417 if (font_info
->vertical_centering
)
2418 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2421 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (ch
)) == 1)
2422 font_type
= BDF_1D_FONT
;
2424 font_type
= BDF_2D_FONT
;
2426 font_type
= UNICODE_FONT
;
2429 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2432 ascent
= pcm
->ascent
;
2433 descent
= pcm
->descent
;
2437 width
= FONT_WIDTH (font
);
2442 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2444 /* Relative composition with or without
2446 left
= (leftmost
+ rightmost
- width
) / 2;
2447 btm
= - descent
+ boff
;
2448 if (font_info
&& font_info
->relative_compose
2449 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2450 || NILP (Faref (Vignore_relative_composition
,
2451 make_number (ch
)))))
2454 if (- descent
>= font_info
->relative_compose
)
2455 /* One extra pixel between two glyphs. */
2457 else if (ascent
<= 0)
2458 /* One extra pixel between two glyphs. */
2459 btm
= lowest
- 1 - ascent
- descent
;
2464 /* A composition rule is specified by an integer
2465 value that encodes global and new reference
2466 points (GREF and NREF). GREF and NREF are
2467 specified by numbers as below:
2475 ---3---4---5--- baseline
2477 6---7---8 -- descent
2479 int rule
= COMPOSITION_RULE (cmp
, i
);
2480 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2482 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2483 grefx
= gref
% 3, nrefx
= nref
% 3;
2484 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2487 + grefx
* (rightmost
- leftmost
) / 2
2488 - nrefx
* width
/ 2);
2489 btm
= ((grefy
== 0 ? highest
2491 : grefy
== 2 ? lowest
2492 : (highest
+ lowest
) / 2)
2493 - (nrefy
== 0 ? ascent
+ descent
2494 : nrefy
== 1 ? descent
- boff
2496 : (ascent
+ descent
) / 2));
2499 cmp
->offsets
[i
* 2] = left
;
2500 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2502 /* Update the bounding box of the overall glyphs. */
2503 right
= left
+ width
;
2504 top
= btm
+ descent
+ ascent
;
2505 if (left
< leftmost
)
2507 if (right
> rightmost
)
2515 /* If there are glyphs whose x-offsets are negative,
2516 shift all glyphs to the right and make all x-offsets
2520 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2521 cmp
->offsets
[i
* 2] -= leftmost
;
2522 rightmost
-= leftmost
;
2525 cmp
->pixel_width
= rightmost
;
2526 cmp
->ascent
= highest
;
2527 cmp
->descent
= - lowest
;
2528 if (cmp
->ascent
< font_ascent
)
2529 cmp
->ascent
= font_ascent
;
2530 if (cmp
->descent
< font_descent
)
2531 cmp
->descent
= font_descent
;
2534 it
->pixel_width
= cmp
->pixel_width
;
2535 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2536 it
->descent
= it
->phys_descent
= cmp
->descent
;
2538 if (face
->box
!= FACE_NO_BOX
)
2540 int thick
= face
->box_line_width
;
2544 it
->ascent
+= thick
;
2545 it
->descent
+= thick
;
2550 if (it
->start_of_box_run_p
)
2551 it
->pixel_width
+= thick
;
2552 if (it
->end_of_box_run_p
)
2553 it
->pixel_width
+= thick
;
2556 /* If face has an overline, add the height of the overline
2557 (1 pixel) and a 1 pixel margin to the character height. */
2558 if (face
->overline_p
)
2561 take_vertical_position_into_account (it
);
2564 x_append_composite_glyph (it
);
2566 else if (it
->what
== IT_IMAGE
)
2567 x_produce_image_glyph (it
);
2568 else if (it
->what
== IT_STRETCH
)
2569 x_produce_stretch_glyph (it
);
2571 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2572 because this isn't true for images with `:ascent 100'. */
2573 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2574 if (it
->area
== TEXT_AREA
)
2575 it
->current_x
+= it
->pixel_width
;
2577 it
->descent
+= it
->extra_line_spacing
;
2579 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2580 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2581 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2582 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2586 /* Estimate the pixel height of the mode or top line on frame F.
2587 FACE_ID specifies what line's height to estimate. */
2590 x_estimate_mode_line_height (f
, face_id
)
2592 enum face_id face_id
;
2594 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2596 /* This function is called so early when Emacs starts that the face
2597 cache and mode line face are not yet initialized. */
2598 if (FRAME_FACE_CACHE (f
))
2600 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2604 height
= FONT_HEIGHT (face
->font
);
2605 if (face
->box_line_width
> 0)
2606 height
+= 2 * face
->box_line_width
;
2614 /***********************************************************************
2616 ***********************************************************************/
2618 /* A sequence of glyphs to be drawn in the same face.
2620 This data structure is not really completely X specific, so it
2621 could possibly, at least partially, be useful for other systems. It
2622 is currently not part of the external redisplay interface because
2623 it's not clear what other systems will need. */
2627 /* X-origin of the string. */
2630 /* Y-origin and y-position of the base line of this string. */
2633 /* The width of the string, not including a face extension. */
2636 /* The width of the string, including a face extension. */
2637 int background_width
;
2639 /* The height of this string. This is the height of the line this
2640 string is drawn in, and can be different from the height of the
2641 font the string is drawn in. */
2644 /* Number of pixels this string overwrites in front of its x-origin.
2645 This number is zero if the string has an lbearing >= 0; it is
2646 -lbearing, if the string has an lbearing < 0. */
2649 /* Number of pixels this string overwrites past its right-most
2650 nominal x-position, i.e. x + width. Zero if the string's
2651 rbearing is <= its nominal width, rbearing - width otherwise. */
2654 /* The frame on which the glyph string is drawn. */
2657 /* The window on which the glyph string is drawn. */
2660 /* X display and window for convenience. */
2663 /* The glyph row for which this string was built. It determines the
2664 y-origin and height of the string. */
2665 struct glyph_row
*row
;
2667 /* The area within row. */
2668 enum glyph_row_area area
;
2670 /* Characters to be drawn, and number of characters. */
2674 /* A face-override for drawing cursors, mouse face and similar. */
2675 enum draw_glyphs_face hl
;
2677 /* Face in which this string is to be drawn. */
2680 /* Font in which this string is to be drawn. */
2683 /* Font info for this string. */
2684 struct font_info
*font_info
;
2686 /* Non-null means this string describes (part of) a composition.
2687 All characters from char2b are drawn composed. */
2688 struct composition
*cmp
;
2690 /* Index of this glyph string's first character in the glyph
2691 definition of CMP. If this is zero, this glyph string describes
2692 the first character of a composition. */
2695 /* 1 means this glyph strings face has to be drawn to the right end
2696 of the window's drawing area. */
2697 unsigned extends_to_end_of_line_p
: 1;
2699 /* 1 means the background of this string has been drawn. */
2700 unsigned background_filled_p
: 1;
2702 /* 1 means glyph string must be drawn with 16-bit functions. */
2703 unsigned two_byte_p
: 1;
2705 /* 1 means that the original font determined for drawing this glyph
2706 string could not be loaded. The member `font' has been set to
2707 the frame's default font in this case. */
2708 unsigned font_not_found_p
: 1;
2710 /* 1 means that the face in which this glyph string is drawn has a
2712 unsigned stippled_p
: 1;
2714 /* 1 means only the foreground of this glyph string must be drawn,
2715 and we should use the physical height of the line this glyph
2716 string appears in as clip rect. */
2717 unsigned for_overlaps_p
: 1;
2719 /* The GC to use for drawing this glyph string. */
2724 /* A pointer to the first glyph in the string. This glyph
2725 corresponds to char2b[0]. Needed to draw rectangles if
2726 font_not_found_p is 1. */
2727 struct glyph
*first_glyph
;
2729 /* Image, if any. */
2732 struct glyph_string
*next
, *prev
;
2736 /* Encapsulate the different ways of displaying text under W32. */
2739 w32_text_out (s
, x
, y
,chars
,nchars
)
2740 struct glyph_string
* s
;
2745 int charset_dim
= w32_font_is_double_byte (s
->gc
->font
) ? 2 : 1;
2746 if (s
->gc
->font
->bdf
)
2747 w32_BDF_TextOut (s
->gc
->font
->bdf
, s
->hdc
,
2748 x
, y
, (char *) chars
, charset_dim
,
2749 nchars
* charset_dim
, 0);
2750 else if (s
->first_glyph
->w32_font_type
== UNICODE_FONT
)
2751 ExtTextOutW (s
->hdc
, x
, y
, 0, NULL
, chars
, nchars
, NULL
);
2753 ExtTextOutA (s
->hdc
, x
, y
, 0, NULL
, (char *) chars
,
2754 nchars
* charset_dim
, NULL
);
2760 x_dump_glyph_string (s
)
2761 struct glyph_string
*s
;
2763 fprintf (stderr
, "glyph string\n");
2764 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2765 s
->x
, s
->y
, s
->width
, s
->height
);
2766 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2767 fprintf (stderr
, " hl = %d\n", s
->hl
);
2768 fprintf (stderr
, " left overhang = %d, right = %d\n",
2769 s
->left_overhang
, s
->right_overhang
);
2770 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2771 fprintf (stderr
, " extends to end of line = %d\n",
2772 s
->extends_to_end_of_line_p
);
2773 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2774 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2777 #endif /* GLYPH_DEBUG */
2781 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2782 struct glyph_string
**,
2783 struct glyph_string
*,
2784 struct glyph_string
*));
2785 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2786 struct glyph_string
**,
2787 struct glyph_string
*,
2788 struct glyph_string
*));
2789 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2790 struct glyph_string
**,
2791 struct glyph_string
*));
2792 static int x_left_overwritten
P_ ((struct glyph_string
*));
2793 static int x_left_overwriting
P_ ((struct glyph_string
*));
2794 static int x_right_overwritten
P_ ((struct glyph_string
*));
2795 static int x_right_overwriting
P_ ((struct glyph_string
*));
2796 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2798 static void w32_init_glyph_string
P_ ((struct glyph_string
*, HDC hdc
,
2799 wchar_t *, struct window
*,
2801 enum glyph_row_area
, int,
2802 enum draw_glyphs_face
));
2803 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2804 enum glyph_row_area
, int, int,
2805 enum draw_glyphs_face
, int));
2806 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2807 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2808 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2810 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2811 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2812 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2813 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2814 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2815 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2816 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2817 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2818 static void w32_get_glyph_overhangs
P_ ((HDC hdc
, struct glyph
*,
2821 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2822 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
2823 static void w32_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2824 double, int, COLORREF
));
2825 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2826 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2827 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2828 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2829 static void w32_draw_image_foreground_1
P_ ((struct glyph_string
*, HBITMAP
));
2830 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2831 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2833 static void w32_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2834 int, int, int, int, RECT
*));
2835 static void w32_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2836 int, int, int, RECT
*));
2837 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2838 enum glyph_row_area
));
2839 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2841 enum glyph_row_area
, int, int));
2844 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2848 /* Append the list of glyph strings with head H and tail T to the list
2849 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2852 x_append_glyph_string_lists (head
, tail
, h
, t
)
2853 struct glyph_string
**head
, **tail
;
2854 struct glyph_string
*h
, *t
;
2868 /* Prepend the list of glyph strings with head H and tail T to the
2869 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2873 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2874 struct glyph_string
**head
, **tail
;
2875 struct glyph_string
*h
, *t
;
2889 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2890 Set *HEAD and *TAIL to the resulting list. */
2893 x_append_glyph_string (head
, tail
, s
)
2894 struct glyph_string
**head
, **tail
;
2895 struct glyph_string
*s
;
2897 s
->next
= s
->prev
= NULL
;
2898 x_append_glyph_string_lists (head
, tail
, s
, s
);
2902 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2907 struct glyph_string
*s
;
2909 if (s
->font
== FRAME_FONT (s
->f
)
2910 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2911 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2913 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
2916 /* Cursor on non-default face: must merge. */
2920 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
2921 xgcv
.foreground
= s
->face
->background
;
2923 /* If the glyph would be invisible, try a different foreground. */
2924 if (xgcv
.foreground
== xgcv
.background
)
2925 xgcv
.foreground
= s
->face
->foreground
;
2926 if (xgcv
.foreground
== xgcv
.background
)
2927 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
2928 if (xgcv
.foreground
== xgcv
.background
)
2929 xgcv
.foreground
= s
->face
->foreground
;
2931 /* Make sure the cursor is distinct from text in this face. */
2932 if (xgcv
.background
== s
->face
->background
2933 && xgcv
.foreground
== s
->face
->foreground
)
2935 xgcv
.background
= s
->face
->foreground
;
2936 xgcv
.foreground
= s
->face
->background
;
2939 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2940 xgcv
.font
= s
->font
;
2941 mask
= GCForeground
| GCBackground
| GCFont
;
2943 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2944 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2947 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2948 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
2950 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2955 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2958 x_set_mouse_face_gc (s
)
2959 struct glyph_string
*s
;
2964 /* What face has to be used last for the mouse face? */
2965 face_id
= FRAME_W32_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2966 face
= FACE_FROM_ID (s
->f
, face_id
);
2968 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2970 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2971 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2973 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2974 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2975 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2977 /* If font in this face is same as S->font, use it. */
2978 if (s
->font
== s
->face
->font
)
2979 s
->gc
= s
->face
->gc
;
2982 /* Otherwise construct scratch_cursor_gc with values from FACE
2987 xgcv
.background
= s
->face
->background
;
2988 xgcv
.foreground
= s
->face
->foreground
;
2989 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2990 xgcv
.font
= s
->font
;
2991 mask
= GCForeground
| GCBackground
| GCFont
;
2993 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2994 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2997 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2998 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
3000 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
3003 xassert (s
->gc
!= 0);
3007 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
3008 Faces to use in the mode line have already been computed when the
3009 matrix was built, so there isn't much to do, here. */
3012 x_set_mode_line_face_gc (s
)
3013 struct glyph_string
*s
;
3015 s
->gc
= s
->face
->gc
;
3019 /* Set S->gc of glyph string S for drawing that glyph string. Set
3020 S->stippled_p to a non-zero value if the face of S has a stipple
3024 x_set_glyph_string_gc (s
)
3025 struct glyph_string
*s
;
3027 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
3029 if (s
->hl
== DRAW_NORMAL_TEXT
)
3031 s
->gc
= s
->face
->gc
;
3032 s
->stippled_p
= s
->face
->stipple
!= 0;
3034 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
3036 x_set_mode_line_face_gc (s
);
3037 s
->stippled_p
= s
->face
->stipple
!= 0;
3039 else if (s
->hl
== DRAW_CURSOR
)
3041 x_set_cursor_gc (s
);
3044 else if (s
->hl
== DRAW_MOUSE_FACE
)
3046 x_set_mouse_face_gc (s
);
3047 s
->stippled_p
= s
->face
->stipple
!= 0;
3049 else if (s
->hl
== DRAW_IMAGE_RAISED
3050 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3052 s
->gc
= s
->face
->gc
;
3053 s
->stippled_p
= s
->face
->stipple
!= 0;
3057 s
->gc
= s
->face
->gc
;
3058 s
->stippled_p
= s
->face
->stipple
!= 0;
3061 /* GC must have been set. */
3062 xassert (s
->gc
!= 0);
3066 /* Return in *R the clipping rectangle for glyph string S. */
3069 w32_get_glyph_string_clip_rect (s
, r
)
3070 struct glyph_string
*s
;
3073 int r_height
, r_width
;
3075 if (s
->row
->full_width_p
)
3077 /* Draw full-width. X coordinates are relative to S->w->left. */
3078 int canon_x
= CANON_X_UNIT (s
->f
);
3080 r
->left
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
3081 r_width
= XFASTINT (s
->w
->width
) * canon_x
;
3083 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
3085 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
3086 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
3090 r
->left
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
3092 /* Unless displaying a mode or menu bar line, which are always
3093 fully visible, clip to the visible part of the row. */
3094 if (s
->w
->pseudo_window_p
)
3095 r_height
= s
->row
->visible_height
;
3097 r_height
= s
->height
;
3101 /* This is a text line that may be partially visible. */
3102 r
->left
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
3103 r_width
= window_box_width (s
->w
, s
->area
);
3104 r_height
= s
->row
->visible_height
;
3107 /* If S draws overlapping rows, it's sufficient to use the top and
3108 bottom of the window for clipping because this glyph string
3109 intentionally draws over other lines. */
3110 if (s
->for_overlaps_p
)
3112 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3113 r_height
= window_text_bottom_y (s
->w
) - r
->top
;
3117 /* Don't use S->y for clipping because it doesn't take partially
3118 visible lines into account. For example, it can be negative for
3119 partially visible lines at the top of a window. */
3120 if (!s
->row
->full_width_p
3121 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
3122 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3124 r
->top
= max (0, s
->row
->y
);
3126 /* If drawing a tool-bar window, draw it over the internal border
3127 at the top of the window. */
3128 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
3129 r
->top
-= s
->f
->output_data
.w32
->internal_border_width
;
3132 r
->top
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->top
);
3134 r
->bottom
= r
->top
+ r_height
;
3135 r
->right
= r
->left
+ r_width
;
3139 /* Set clipping for output of glyph string S. S may be part of a mode
3140 line or menu if we don't have X toolkit support. */
3143 x_set_glyph_string_clipping (s
)
3144 struct glyph_string
*s
;
3147 w32_get_glyph_string_clip_rect (s
, &r
);
3148 w32_set_clip_rectangle (s
->hdc
, &r
);
3152 /* Compute left and right overhang of glyph string S. If S is a glyph
3153 string for a composition, assume overhangs don't exist. */
3156 x_compute_glyph_string_overhangs (s
)
3157 struct glyph_string
*s
;
3159 /* TODO: Windows does not appear to have a method for
3160 getting this info without getting the ABC widths for each
3161 individual character and working it out manually. */
3165 /* Compute overhangs and x-positions for glyph string S and its
3166 predecessors, or successors. X is the starting x-position for S.
3167 BACKWARD_P non-zero means process predecessors. */
3170 x_compute_overhangs_and_x (s
, x
, backward_p
)
3171 struct glyph_string
*s
;
3179 x_compute_glyph_string_overhangs (s
);
3189 x_compute_glyph_string_overhangs (s
);
3198 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
3199 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
3200 assumed to be zero. */
3203 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
)
3205 struct glyph
*glyph
;
3211 if (glyph
->type
== CHAR_GLYPH
)
3218 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
3222 && (pcm
= w32_per_char_metric (font
, &char2b
,
3223 glyph
->w32_font_type
)))
3225 if (pcm
->rbearing
> pcm
->width
)
3226 *right
= pcm
->rbearing
- pcm
->width
;
3227 if (pcm
->lbearing
< 0)
3228 *left
= -pcm
->lbearing
;
3235 x_get_glyph_overhangs (glyph
, f
, left
, right
)
3236 struct glyph
*glyph
;
3240 HDC hdc
= get_frame_dc (f
);
3241 /* Convert to unicode! */
3242 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
);
3243 release_frame_dc (f
, hdc
);
3247 /* Return the index of the first glyph preceding glyph string S that
3248 is overwritten by S because of S's left overhang. Value is -1
3249 if no glyphs are overwritten. */
3252 x_left_overwritten (s
)
3253 struct glyph_string
*s
;
3257 if (s
->left_overhang
)
3260 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3261 int first
= s
->first_glyph
- glyphs
;
3263 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3264 x
-= glyphs
[i
].pixel_width
;
3275 /* Return the index of the first glyph preceding glyph string S that
3276 is overwriting S because of its right overhang. Value is -1 if no
3277 glyph in front of S overwrites S. */
3280 x_left_overwriting (s
)
3281 struct glyph_string
*s
;
3284 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3285 int first
= s
->first_glyph
- glyphs
;
3289 for (i
= first
- 1; i
>= 0; --i
)
3292 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3295 x
-= glyphs
[i
].pixel_width
;
3302 /* Return the index of the last glyph following glyph string S that is
3303 not overwritten by S because of S's right overhang. Value is -1 if
3304 no such glyph is found. */
3307 x_right_overwritten (s
)
3308 struct glyph_string
*s
;
3312 if (s
->right_overhang
)
3315 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3316 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3317 int end
= s
->row
->used
[s
->area
];
3319 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3320 x
+= glyphs
[i
].pixel_width
;
3329 /* Return the index of the last glyph following glyph string S that
3330 overwrites S because of its left overhang. Value is negative
3331 if no such glyph is found. */
3334 x_right_overwriting (s
)
3335 struct glyph_string
*s
;
3338 int end
= s
->row
->used
[s
->area
];
3339 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3340 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3344 for (i
= first
; i
< end
; ++i
)
3347 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3350 x
+= glyphs
[i
].pixel_width
;
3357 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3360 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3361 struct glyph_string
*s
;
3369 /* Take clipping into account. */
3370 if (s
->gc
->clip_mask
== Rect
)
3372 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
3373 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
3374 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
3375 - s
->gc
->clip_rectangle
.left
);
3376 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
3377 - s
->gc
->clip_rectangle
.top
);
3380 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
3385 /* Draw the background of glyph_string S. If S->background_filled_p
3386 is non-zero don't draw it. FORCE_P non-zero means draw the
3387 background even if it wouldn't be drawn normally. This is used
3388 when a string preceding S draws into the background of S, or S
3389 contains the first component of a composition. */
3392 x_draw_glyph_string_background (s
, force_p
)
3393 struct glyph_string
*s
;
3396 /* Nothing to do if background has already been drawn or if it
3397 shouldn't be drawn in the first place. */
3398 if (!s
->background_filled_p
)
3400 int box_line_width
= max (s
->face
->box_line_width
, 0);
3402 #if 0 /* TODO: stipple */
3405 /* Fill background with a stipple pattern. */
3406 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3407 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3408 s
->y
+ box_line_width
,
3409 s
->background_width
,
3410 s
->height
- 2 * box_line_width
);
3411 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3412 s
->background_filled_p
= 1;
3416 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3417 || s
->font_not_found_p
3418 || s
->extends_to_end_of_line_p
3422 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3423 s
->background_width
,
3424 s
->height
- 2 * box_line_width
);
3425 s
->background_filled_p
= 1;
3431 /* Draw the foreground of glyph string S. */
3434 x_draw_glyph_string_foreground (s
)
3435 struct glyph_string
*s
;
3440 /* If first glyph of S has a left box line, start drawing the text
3441 of S to the right of that box line. */
3442 if (s
->face
->box
!= FACE_NO_BOX
3443 && s
->first_glyph
->left_box_line_p
)
3444 x
= s
->x
+ abs (s
->face
->box_line_width
);
3448 if (s
->for_overlaps_p
|| (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3449 SetBkMode (s
->hdc
, TRANSPARENT
);
3451 SetBkMode (s
->hdc
, OPAQUE
);
3453 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3454 SetBkColor (s
->hdc
, s
->gc
->background
);
3455 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3457 if (s
->font
&& s
->font
->hfont
)
3458 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3460 /* Draw characters of S as rectangles if S's font could not be
3462 if (s
->font_not_found_p
)
3464 for (i
= 0; i
< s
->nchars
; ++i
)
3466 struct glyph
*g
= s
->first_glyph
+ i
;
3468 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3470 x
+= g
->pixel_width
;
3475 char *char1b
= (char *) s
->char2b
;
3476 int boff
= s
->font_info
->baseline_offset
;
3478 if (s
->font_info
->vertical_centering
)
3479 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3481 /* If we can use 8-bit functions, condense S->char2b. */
3483 for (i
= 0; i
< s
->nchars
; ++i
)
3484 char1b
[i
] = BYTE2 (s
->char2b
[i
]);
3486 /* Draw text with TextOut and friends. */
3487 w32_text_out (s
, x
, s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3489 if (s
->font
&& s
->font
->hfont
)
3490 SelectObject (s
->hdc
, old_font
);
3493 /* Draw the foreground of composite glyph string S. */
3496 x_draw_composite_glyph_string_foreground (s
)
3497 struct glyph_string
*s
;
3502 /* If first glyph of S has a left box line, start drawing the text
3503 of S to the right of that box line. */
3504 if (s
->face
->box
!= FACE_NO_BOX
3505 && s
->first_glyph
->left_box_line_p
)
3506 x
= s
->x
+ abs (s
->face
->box_line_width
);
3510 /* S is a glyph string for a composition. S->gidx is the index of
3511 the first character drawn for glyphs of this composition.
3512 S->gidx == 0 means we are drawing the very first character of
3513 this composition. */
3515 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3516 SetBkColor (s
->hdc
, s
->gc
->background
);
3517 SetBkMode (s
->hdc
, TRANSPARENT
);
3518 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3520 if (s
->font
&& s
->font
->hfont
)
3521 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3523 /* Draw a rectangle for the composition if the font for the very
3524 first character of the composition could not be loaded. */
3525 if (s
->font_not_found_p
)
3528 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
3533 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3534 w32_text_out (s
, x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3535 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3538 if (s
->font
&& s
->font
->hfont
)
3539 SelectObject (s
->hdc
, old_font
);
3543 /* Brightness beyond which a color won't have its highlight brightness
3546 Nominally, highlight colors for `3d' faces are calculated by
3547 brightening an object's color by a constant scale factor, but this
3548 doesn't yield good results for dark colors, so for colors who's
3549 brightness is less than this value (on a scale of 0-255) have to
3550 use an additional additive factor.
3552 The value here is set so that the default menu-bar/mode-line color
3553 (grey75) will not have its highlights changed at all. */
3554 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
3557 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
3558 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3559 If this produces the same color as COLOR, try a color where all RGB
3560 values have DELTA added. Return the allocated color in *COLOR.
3561 DISPLAY is the X display, CMAP is the colormap to operate on.
3562 Value is non-zero if successful. */
3565 w32_alloc_lighter_color (f
, color
, factor
, delta
)
3574 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
3577 /* Change RGB values by specified FACTOR. Avoid overflow! */
3578 xassert (factor
>= 0);
3579 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
3580 min (0xff, factor
* GetGValue (*color
)),
3581 min (0xff, factor
* GetBValue (*color
)));
3583 /* Calculate brightness of COLOR. */
3584 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
3585 + GetBValue (*color
)) / 6;
3587 /* We only boost colors that are darker than
3588 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3589 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3590 /* Make an additive adjustment to NEW, because it's dark enough so
3591 that scaling by FACTOR alone isn't enough. */
3593 /* How far below the limit this color is (0 - 1, 1 being darker). */
3594 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3595 /* The additive adjustment. */
3596 int min_delta
= delta
* dimness
* factor
/ 2;
3599 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
3600 max (0, min (0xff, min_delta
- GetGValue (*color
))),
3601 max (0, min (0xff, min_delta
- GetBValue (*color
))));
3603 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
3604 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
3605 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
3609 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
3610 max (0, min (0xff, delta
+ GetGValue (*color
))),
3611 max (0, min (0xff, delta
+ GetBValue (*color
))));
3613 /* TODO: Map to palette and retry with delta if same? */
3614 /* TODO: Free colors (if using palette)? */
3625 /* Set up the foreground color for drawing relief lines of glyph
3626 string S. RELIEF is a pointer to a struct relief containing the GC
3627 with which lines will be drawn. Use a color that is FACTOR or
3628 DELTA lighter or darker than the relief's background which is found
3629 in S->f->output_data.x->relief_background. If such a color cannot
3630 be allocated, use DEFAULT_PIXEL, instead. */
3633 w32_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3635 struct relief
*relief
;
3638 COLORREF default_pixel
;
3641 struct w32_output
*di
= f
->output_data
.w32
;
3642 unsigned long mask
= GCForeground
;
3644 COLORREF background
= di
->relief_background
;
3645 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
3647 /* TODO: Free colors (if using palette)? */
3649 /* Allocate new color. */
3650 xgcv
.foreground
= default_pixel
;
3652 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
3654 relief
->allocated_p
= 1;
3655 xgcv
.foreground
= relief
->pixel
= pixel
;
3658 if (relief
->gc
== 0)
3660 #if 0 /* TODO: stipple */
3661 xgcv
.stipple
= dpyinfo
->gray
;
3664 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
3667 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
3671 /* Set up colors for the relief lines around glyph string S. */
3674 x_setup_relief_colors (s
)
3675 struct glyph_string
*s
;
3677 struct w32_output
*di
= s
->f
->output_data
.w32
;
3680 if (s
->face
->use_box_color_for_shadows_p
)
3681 color
= s
->face
->box_color
;
3682 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3684 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3685 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3687 color
= s
->gc
->background
;
3689 if (di
->white_relief
.gc
== 0
3690 || color
!= di
->relief_background
)
3692 di
->relief_background
= color
;
3693 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3694 WHITE_PIX_DEFAULT (s
->f
));
3695 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3696 BLACK_PIX_DEFAULT (s
->f
));
3701 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3702 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3703 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3704 relief. LEFT_P non-zero means draw a relief on the left side of
3705 the rectangle. RIGHT_P non-zero means draw a relief on the right
3706 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3710 w32_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3711 raised_p
, left_p
, right_p
, clip_rect
)
3713 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3718 HDC hdc
= get_frame_dc (f
);
3721 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3723 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3725 w32_set_clip_rectangle (hdc
, clip_rect
);
3728 for (i
= 0; i
< width
; ++i
)
3729 w32_fill_area (f
, hdc
, gc
.foreground
,
3730 left_x
+ i
* left_p
, top_y
+ i
,
3731 (right_x
+ 1 - i
* right_p
) - (left_x
+ i
* left_p
) + 1, 1);
3735 for (i
= 0; i
< width
; ++i
)
3736 w32_fill_area (f
, hdc
, gc
.foreground
,
3737 left_x
+ i
, top_y
+ i
, 1,
3738 (bottom_y
- i
) - (top_y
+ i
) + 2);
3741 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3743 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3746 for (i
= 0; i
< width
; ++i
)
3747 w32_fill_area (f
, hdc
, gc
.foreground
,
3748 left_x
+ i
* left_p
, bottom_y
- i
,
3749 (right_x
- i
* right_p
) - (left_x
+ i
* left_p
) + 2, 1);
3753 for (i
= 0; i
< width
; ++i
)
3754 w32_fill_area (f
, hdc
, gc
.foreground
,
3755 right_x
- i
, top_y
+ i
+ 1, 1,
3756 (bottom_y
- i
) - (top_y
+ i
));
3758 w32_set_clip_rectangle (hdc
, NULL
);
3760 release_frame_dc (f
, hdc
);
3764 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3765 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3766 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3767 left side of the rectangle. RIGHT_P non-zero means draw a line
3768 on the right side of the rectangle. CLIP_RECT is the clipping
3769 rectangle to use when drawing. */
3772 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3773 left_p
, right_p
, clip_rect
)
3774 struct glyph_string
*s
;
3775 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3778 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
3781 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3782 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3787 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3788 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3792 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3793 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3798 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3799 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3802 w32_set_clip_rectangle (s
->hdc
, NULL
);
3806 /* Draw a box around glyph string S. */
3809 x_draw_glyph_string_box (s
)
3810 struct glyph_string
*s
;
3812 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3813 int left_p
, right_p
;
3814 struct glyph
*last_glyph
;
3817 last_x
= window_box_right (s
->w
, s
->area
);
3818 if (s
->row
->full_width_p
3819 && !s
->w
->pseudo_window_p
)
3821 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
3822 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3823 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3826 /* The glyph that may have a right box line. */
3827 last_glyph
= (s
->cmp
|| s
->img
3829 : s
->first_glyph
+ s
->nchars
- 1);
3831 width
= abs (s
->face
->box_line_width
);
3832 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3834 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3836 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3838 bottom_y
= top_y
+ s
->height
- 1;
3840 left_p
= (s
->first_glyph
->left_box_line_p
3841 || (s
->hl
== DRAW_MOUSE_FACE
3843 || s
->prev
->hl
!= s
->hl
)));
3844 right_p
= (last_glyph
->right_box_line_p
3845 || (s
->hl
== DRAW_MOUSE_FACE
3847 || s
->next
->hl
!= s
->hl
)));
3849 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3851 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3852 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3853 left_p
, right_p
, &clip_rect
);
3856 x_setup_relief_colors (s
);
3857 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3858 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3863 /* Draw foreground of image glyph string S. */
3866 x_draw_image_foreground (s
)
3867 struct glyph_string
*s
;
3870 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3872 /* If first glyph of S has a left box line, start drawing it to the
3873 right of that line. */
3874 if (s
->face
->box
!= FACE_NO_BOX
3875 && s
->first_glyph
->left_box_line_p
)
3876 x
= s
->x
+ abs (s
->face
->box_line_width
);
3880 /* If there is a margin around the image, adjust x- and y-position
3882 x
+= s
->img
->hmargin
;
3883 y
+= s
->img
->vmargin
;
3889 #if 0 /* TODO: image mask */
3892 /* We can't set both a clip mask and use XSetClipRectangles
3893 because the latter also sets a clip mask. We also can't
3894 trust on the shape extension to be available
3895 (XShapeCombineRegion). So, compute the rectangle to draw
3897 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3900 XRectangle clip_rect
, image_rect
, r
;
3902 xgcv
.clip_mask
= s
->img
->mask
;
3903 xgcv
.clip_x_origin
= x
;
3904 xgcv
.clip_y_origin
= y
;
3905 xgcv
.function
= GXcopy
;
3906 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3908 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3911 image_rect
.width
= s
->img
->width
;
3912 image_rect
.height
= s
->img
->height
;
3913 if (IntersectRect (&r
, &clip_rect
, &image_rect
))
3914 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3915 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3920 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
3921 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
3922 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
3923 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
3924 x_set_glyph_string_clipping (s
);
3926 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3927 SetBkColor (s
->hdc
, s
->gc
->background
);
3928 #if 0 /* From w32bdf.c (which is from Meadow). */
3929 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3930 compat_hdc
, 0, 0, SRCCOPY
);
3931 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3932 compat_hdc
, 0, 0, 0xB8074A);
3934 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3935 compat_hdc
, 0, 0, 0xE20746);
3937 SelectObject (s
->hdc
, orig_brush
);
3938 DeleteObject (fg_brush
);
3939 SelectObject (compat_hdc
, orig_obj
);
3940 DeleteDC (compat_hdc
);
3942 /* When the image has a mask, we can expect that at
3943 least part of a mouse highlight or a block cursor will
3944 be visible. If the image doesn't have a mask, make
3945 a block cursor visible by drawing a rectangle around
3946 the image. I believe it's looking better if we do
3947 nothing here for mouse-face. */
3948 if (s
->hl
== DRAW_CURSOR
)
3949 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
3950 s
->img
->height
- 1);
3951 w32_set_clip_rectangle (s
->hdc
, NULL
);
3955 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
-1,
3956 s
->img
->height
- 1);
3958 RestoreDC (s
->hdc
,-1);
3963 /* Draw a relief around the image glyph string S. */
3966 x_draw_image_relief (s
)
3967 struct glyph_string
*s
;
3969 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3972 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3974 /* If first glyph of S has a left box line, start drawing it to the
3975 right of that line. */
3976 if (s
->face
->box
!= FACE_NO_BOX
3977 && s
->first_glyph
->left_box_line_p
)
3978 x
= s
->x
+ abs (s
->face
->box_line_width
);
3982 /* If there is a margin around the image, adjust x- and y-position
3984 x
+= s
->img
->hmargin
;
3985 y
+= s
->img
->vmargin
;
3987 if (s
->hl
== DRAW_IMAGE_SUNKEN
3988 || s
->hl
== DRAW_IMAGE_RAISED
)
3990 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3991 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3995 thick
= abs (s
->img
->relief
);
3996 raised_p
= s
->img
->relief
> 0;
4001 x1
= x
+ s
->img
->width
+ thick
- 1;
4002 y1
= y
+ s
->img
->height
+ thick
- 1;
4004 x_setup_relief_colors (s
);
4005 w32_get_glyph_string_clip_rect (s
, &r
);
4006 w32_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4010 /* Draw the foreground of image glyph string S to PIXMAP. */
4013 w32_draw_image_foreground_1 (s
, pixmap
)
4014 struct glyph_string
*s
;
4017 HDC hdc
= CreateCompatibleDC (s
->hdc
);
4018 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
4020 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4022 /* If first glyph of S has a left box line, start drawing it to the
4023 right of that line. */
4024 if (s
->face
->box
!= FACE_NO_BOX
4025 && s
->first_glyph
->left_box_line_p
)
4026 x
= abs (s
->face
->box_line_width
);
4030 /* If there is a margin around the image, adjust x- and y-position
4032 x
+= s
->img
->hmargin
;
4033 y
+= s
->img
->vmargin
;
4037 #if 0 /* TODO: image mask */
4040 /* We can't set both a clip mask and use XSetClipRectangles
4041 because the latter also sets a clip mask. We also can't
4042 trust on the shape extension to be available
4043 (XShapeCombineRegion). So, compute the rectangle to draw
4045 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4049 xgcv
.clip_mask
= s
->img
->mask
;
4050 xgcv
.clip_x_origin
= x
;
4051 xgcv
.clip_y_origin
= y
;
4052 xgcv
.function
= GXcopy
;
4053 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4055 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4056 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4057 XSetClipMask (s
->display
, s
->gc
, None
);
4062 HDC compat_hdc
= CreateCompatibleDC (hdc
);
4063 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4064 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
4065 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
4067 SetTextColor (hdc
, s
->gc
->foreground
);
4068 SetBkColor (hdc
, s
->gc
->background
);
4069 #if 0 /* From w32bdf.c (which is from Meadow). */
4070 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4071 compat_hdc
, 0, 0, SRCCOPY
);
4072 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4073 compat_hdc
, 0, 0, 0xB8074A);
4075 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4076 compat_hdc
, 0, 0, 0xE20746);
4078 SelectObject (hdc
, orig_brush
);
4079 DeleteObject (fg_brush
);
4080 SelectObject (compat_hdc
, orig_obj
);
4081 DeleteDC (compat_hdc
);
4083 /* When the image has a mask, we can expect that at
4084 least part of a mouse highlight or a block cursor will
4085 be visible. If the image doesn't have a mask, make
4086 a block cursor visible by drawing a rectangle around
4087 the image. I believe it's looking better if we do
4088 nothing here for mouse-face. */
4089 if (s
->hl
== DRAW_CURSOR
)
4090 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4091 s
->img
->height
- 1);
4095 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4096 s
->img
->height
- 1);
4098 SelectObject (hdc
, orig_hdc_obj
);
4103 /* Draw part of the background of glyph string S. X, Y, W, and H
4104 give the rectangle to draw. */
4107 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4108 struct glyph_string
*s
;
4111 #if 0 /* TODO: stipple */
4114 /* Fill background with a stipple pattern. */
4115 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4116 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4117 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4121 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4125 /* Draw image glyph string S.
4128 s->x +-------------------------
4131 | +-------------------------
4134 | | +-------------------
4140 x_draw_image_glyph_string (s
)
4141 struct glyph_string
*s
;
4144 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4145 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4149 height
= s
->height
- 2 * box_line_vwidth
;
4151 /* Fill background with face under the image. Do it only if row is
4152 taller than image or if image has a clip mask to reduce
4154 s
->stippled_p
= s
->face
->stipple
!= 0;
4155 if (height
> s
->img
->height
4158 #if 0 /* TODO: image mask */
4161 || s
->img
->pixmap
== 0
4162 || s
->width
!= s
->background_width
)
4164 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4165 x
= s
->x
+ box_line_hwidth
;
4169 y
= s
->y
+ box_line_vwidth
;
4170 #if 0 /* TODO: image mask */
4173 /* Create a pixmap as large as the glyph string. Fill it
4174 with the background color. Copy the image to it, using
4175 its mask. Copy the temporary pixmap to the display. */
4176 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4177 int depth
= DefaultDepthOfScreen (screen
);
4179 /* Create a pixmap as large as the glyph string. */
4180 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4181 s
->background_width
,
4184 /* Don't clip in the following because we're working on the
4186 XSetClipMask (s
->display
, s
->gc
, None
);
4188 /* Fill the pixmap with the background color/stipple. */
4191 /* Fill background with a stipple pattern. */
4192 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4193 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4194 0, 0, s
->background_width
, s
->height
);
4195 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4200 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4202 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4203 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4204 0, 0, s
->background_width
, s
->height
);
4205 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4210 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4212 s
->background_filled_p
= 1;
4215 /* Draw the foreground. */
4218 w32_draw_image_foreground_1 (s
, pixmap
);
4219 x_set_glyph_string_clipping (s
);
4221 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
4222 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4223 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
4224 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
4226 SetTextColor (s
->hdc
, s
->gc
->foreground
);
4227 SetBkColor (s
->hdc
, s
->gc
->background
);
4228 #if 0 /* From w32bdf.c (which is from Meadow). */
4229 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4230 compat_hdc
, 0, 0, SRCCOPY
);
4231 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4232 compat_hdc
, 0, 0, 0xB8074A);
4234 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4235 compat_hdc
, 0, 0, 0xE20746);
4237 SelectObject (s
->hdc
, orig_brush
);
4238 DeleteObject (fg_brush
);
4239 SelectObject (compat_hdc
, orig_obj
);
4240 DeleteDC (compat_hdc
);
4242 DeleteObject (pixmap
);
4246 x_draw_image_foreground (s
);
4248 /* If we must draw a relief around the image, do it. */
4250 || s
->hl
== DRAW_IMAGE_RAISED
4251 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4252 x_draw_image_relief (s
);
4256 /* Draw stretch glyph string S. */
4259 x_draw_stretch_glyph_string (s
)
4260 struct glyph_string
*s
;
4262 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4263 s
->stippled_p
= s
->face
->stipple
!= 0;
4265 if (s
->hl
== DRAW_CURSOR
4266 && !x_stretch_cursor_p
)
4268 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4269 as wide as the stretch glyph. */
4270 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4273 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4275 /* Clear rest using the GC of the original non-cursor face. */
4276 if (width
< s
->background_width
)
4278 XGCValues
*gc
= s
->face
->gc
;
4279 int x
= s
->x
+ width
, y
= s
->y
;
4280 int w
= s
->background_width
- width
, h
= s
->height
;
4284 if (s
->row
->mouse_face_p
4285 && cursor_in_mouse_face_p (s
->w
))
4287 x_set_mouse_face_gc (s
);
4293 w32_get_glyph_string_clip_rect (s
, &r
);
4294 w32_set_clip_rectangle (hdc
, &r
);
4296 #if 0 /* TODO: stipple */
4297 if (s
->face
->stipple
)
4299 /* Fill background with a stipple pattern. */
4300 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4301 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4302 XSetFillStyle (s
->display
, gc
, FillSolid
);
4307 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
4311 else if (!s
->background_filled_p
)
4312 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4315 s
->background_filled_p
= 1;
4319 /* Draw glyph string S. */
4322 x_draw_glyph_string (s
)
4323 struct glyph_string
*s
;
4325 int relief_drawn_p
= 0;
4327 /* If S draws into the background of its successor, draw the
4328 background of the successor first so that S can draw into it.
4329 This makes S->next use XDrawString instead of XDrawImageString. */
4330 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4332 xassert (s
->next
->img
== NULL
);
4333 x_set_glyph_string_gc (s
->next
);
4334 x_set_glyph_string_clipping (s
->next
);
4335 x_draw_glyph_string_background (s
->next
, 1);
4338 /* Set up S->gc, set clipping and draw S. */
4339 x_set_glyph_string_gc (s
);
4341 /* Draw relief (if any) in advance for char/composition so that the
4342 glyph string can be drawn over it. */
4343 if (!s
->for_overlaps_p
4344 && s
->face
->box
!= FACE_NO_BOX
4345 && (s
->first_glyph
->type
== CHAR_GLYPH
4346 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4349 x_set_glyph_string_clipping (s
);
4350 x_draw_glyph_string_background (s
, 1);
4351 x_draw_glyph_string_box (s
);
4352 x_set_glyph_string_clipping (s
);
4356 x_set_glyph_string_clipping (s
);
4358 switch (s
->first_glyph
->type
)
4361 x_draw_image_glyph_string (s
);
4365 x_draw_stretch_glyph_string (s
);
4369 if (s
->for_overlaps_p
)
4370 s
->background_filled_p
= 1;
4372 x_draw_glyph_string_background (s
, 0);
4373 x_draw_glyph_string_foreground (s
);
4376 case COMPOSITE_GLYPH
:
4377 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4378 s
->background_filled_p
= 1;
4380 x_draw_glyph_string_background (s
, 1);
4381 x_draw_composite_glyph_string_foreground (s
);
4388 if (!s
->for_overlaps_p
)
4390 /* Draw underline. */
4391 if (s
->face
->underline_p
4392 && (s
->font
->bdf
|| !s
->font
->tm
.tmUnderlined
))
4394 unsigned long h
= 1;
4395 unsigned long dy
= s
->height
- h
;
4397 /* TODO: Use font information for positioning and thickness
4398 of underline. See OUTLINETEXTMETRIC, and xterm.c. */
4399 if (s
->face
->underline_defaulted_p
)
4401 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4402 s
->y
+ dy
, s
->width
, 1);
4406 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4407 s
->y
+ dy
, s
->width
, 1);
4411 /* Draw overline. */
4412 if (s
->face
->overline_p
)
4414 unsigned long dy
= 0, h
= 1;
4416 if (s
->face
->overline_color_defaulted_p
)
4418 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4419 s
->y
+ dy
, s
->width
, h
);
4423 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4424 s
->y
+ dy
, s
->width
, h
);
4428 /* Draw strike-through. */
4429 if (s
->face
->strike_through_p
4430 && (s
->font
->bdf
|| !s
->font
->tm
.tmStruckOut
))
4432 unsigned long h
= 1;
4433 unsigned long dy
= (s
->height
- h
) / 2;
4435 if (s
->face
->strike_through_color_defaulted_p
)
4437 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
4442 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4443 s
->y
+ dy
, s
->width
, h
);
4448 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4449 x_draw_glyph_string_box (s
);
4452 /* Reset clipping. */
4453 w32_set_clip_rectangle (s
->hdc
, NULL
);
4457 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4458 struct face
**, int));
4461 /* Fill glyph string S with composition components specified by S->cmp.
4463 FACES is an array of faces for all components of this composition.
4464 S->gidx is the index of the first component for S.
4465 OVERLAPS_P non-zero means S should draw the foreground only, and
4466 use its physical height for clipping.
4468 Value is the index of a component not in S. */
4471 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4472 struct glyph_string
*s
;
4473 struct face
**faces
;
4480 s
->for_overlaps_p
= overlaps_p
;
4482 s
->face
= faces
[s
->gidx
];
4483 s
->font
= s
->face
->font
;
4484 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4486 /* For all glyphs of this composition, starting at the offset
4487 S->gidx, until we reach the end of the definition or encounter a
4488 glyph that requires the different face, add it to S. */
4490 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4493 /* All glyph strings for the same composition has the same width,
4494 i.e. the width set for the first component of the composition. */
4496 s
->width
= s
->first_glyph
->pixel_width
;
4498 /* If the specified font could not be loaded, use the frame's
4499 default font, but record the fact that we couldn't load it in
4500 the glyph string so that we can draw rectangles for the
4501 characters of the glyph string. */
4502 if (s
->font
== NULL
)
4504 s
->font_not_found_p
= 1;
4505 s
->font
= FRAME_FONT (s
->f
);
4508 /* Adjust base line for subscript/superscript text. */
4509 s
->ybase
+= s
->first_glyph
->voffset
;
4511 xassert (s
->face
&& s
->face
->gc
);
4513 /* This glyph string must always be drawn with 16-bit functions. */
4516 return s
->gidx
+ s
->nchars
;
4520 /* Fill glyph string S from a sequence of character glyphs.
4522 FACE_ID is the face id of the string. START is the index of the
4523 first glyph to consider, END is the index of the last + 1.
4524 OVERLAPS_P non-zero means S should draw the foreground only, and
4525 use its physical height for clipping.
4527 Value is the index of the first glyph not in S. */
4530 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4531 struct glyph_string
*s
;
4533 int start
, end
, overlaps_p
;
4535 struct glyph
*glyph
, *last
;
4537 int glyph_not_available_p
;
4539 xassert (s
->f
== XFRAME (s
->w
->frame
));
4540 xassert (s
->nchars
== 0);
4541 xassert (start
>= 0 && end
> start
);
4543 s
->for_overlaps_p
= overlaps_p
;
4544 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4545 last
= s
->row
->glyphs
[s
->area
] + end
;
4546 voffset
= glyph
->voffset
;
4548 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4551 && glyph
->type
== CHAR_GLYPH
4552 && glyph
->voffset
== voffset
4553 /* Same face id implies same font, nowadays. */
4554 && glyph
->face_id
== face_id
4555 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4559 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4560 s
->char2b
+ s
->nchars
,
4562 s
->two_byte_p
= two_byte_p
;
4564 xassert (s
->nchars
<= end
- start
);
4565 s
->width
+= glyph
->pixel_width
;
4569 s
->font
= s
->face
->font
;
4570 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4572 /* If the specified font could not be loaded, use the frame's font,
4573 but record the fact that we couldn't load it in
4574 S->font_not_found_p so that we can draw rectangles for the
4575 characters of the glyph string. */
4576 if (s
->font
== NULL
|| glyph_not_available_p
)
4578 s
->font_not_found_p
= 1;
4579 s
->font
= FRAME_FONT (s
->f
);
4582 /* Adjust base line for subscript/superscript text. */
4583 s
->ybase
+= voffset
;
4585 xassert (s
->face
&& s
->face
->gc
);
4586 return glyph
- s
->row
->glyphs
[s
->area
];
4590 /* Fill glyph string S from image glyph S->first_glyph. */
4593 x_fill_image_glyph_string (s
)
4594 struct glyph_string
*s
;
4596 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4597 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4599 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4600 s
->font
= s
->face
->font
;
4601 s
->width
= s
->first_glyph
->pixel_width
;
4603 /* Adjust base line for subscript/superscript text. */
4604 s
->ybase
+= s
->first_glyph
->voffset
;
4608 /* Fill glyph string S from a sequence of stretch glyphs.
4610 ROW is the glyph row in which the glyphs are found, AREA is the
4611 area within the row. START is the index of the first glyph to
4612 consider, END is the index of the last + 1.
4614 Value is the index of the first glyph not in S. */
4617 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4618 struct glyph_string
*s
;
4619 struct glyph_row
*row
;
4620 enum glyph_row_area area
;
4623 struct glyph
*glyph
, *last
;
4624 int voffset
, face_id
;
4626 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4628 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4629 last
= s
->row
->glyphs
[s
->area
] + end
;
4630 face_id
= glyph
->face_id
;
4631 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4632 s
->font
= s
->face
->font
;
4633 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4634 s
->width
= glyph
->pixel_width
;
4635 voffset
= glyph
->voffset
;
4639 && glyph
->type
== STRETCH_GLYPH
4640 && glyph
->voffset
== voffset
4641 && glyph
->face_id
== face_id
);
4643 s
->width
+= glyph
->pixel_width
;
4645 /* Adjust base line for subscript/superscript text. */
4646 s
->ybase
+= voffset
;
4649 return glyph
- s
->row
->glyphs
[s
->area
];
4653 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4654 of XChar2b structures for S; it can't be allocated in
4655 x_init_glyph_string because it must be allocated via `alloca'. W
4656 is the window on which S is drawn. ROW and AREA are the glyph row
4657 and area within the row from which S is constructed. START is the
4658 index of the first glyph structure covered by S. HL is a
4659 face-override for drawing S. */
4662 w32_init_glyph_string (s
, hdc
, char2b
, w
, row
, area
, start
, hl
)
4663 struct glyph_string
*s
;
4667 struct glyph_row
*row
;
4668 enum glyph_row_area area
;
4670 enum draw_glyphs_face hl
;
4672 bzero (s
, sizeof *s
);
4674 s
->f
= XFRAME (w
->frame
);
4676 s
->window
= FRAME_W32_WINDOW (s
->f
);
4681 s
->first_glyph
= row
->glyphs
[area
] + start
;
4682 s
->height
= row
->height
;
4683 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4685 /* Display the internal border below the tool-bar window. */
4686 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4687 s
->y
-= s
->f
->output_data
.w32
->internal_border_width
;
4689 s
->ybase
= s
->y
+ row
->ascent
;
4693 /* Set background width of glyph string S. START is the index of the
4694 first glyph following S. LAST_X is the right-most x-position + 1
4695 in the drawing area. */
4698 x_set_glyph_string_background_width (s
, start
, last_x
)
4699 struct glyph_string
*s
;
4703 /* If the face of this glyph string has to be drawn to the end of
4704 the drawing area, set S->extends_to_end_of_line_p. */
4705 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4707 if (start
== s
->row
->used
[s
->area
]
4708 && s
->area
== TEXT_AREA
4709 && ((s
->hl
== DRAW_NORMAL_TEXT
4710 && (s
->row
->fill_line_p
4711 || s
->face
->background
!= default_face
->background
4712 || s
->face
->stipple
!= default_face
->stipple
4713 || s
->row
->mouse_face_p
))
4714 || s
->hl
== DRAW_MOUSE_FACE
4715 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4716 && s
->row
->fill_line_p
)))
4717 s
->extends_to_end_of_line_p
= 1;
4719 /* If S extends its face to the end of the line, set its
4720 background_width to the distance to the right edge of the drawing
4722 if (s
->extends_to_end_of_line_p
)
4723 s
->background_width
= last_x
- s
->x
+ 1;
4725 s
->background_width
= s
->width
;
4729 /* Add a glyph string for a stretch glyph to the list of strings
4730 between HEAD and TAIL. START is the index of the stretch glyph in
4731 row area AREA of glyph row ROW. END is the index of the last glyph
4732 in that glyph row area. X is the current output position assigned
4733 to the new glyph string constructed. HL overrides that face of the
4734 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4735 is the right-most x-position of the drawing area. */
4737 #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4740 s = (struct glyph_string *) alloca (sizeof *s); \
4741 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4742 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4743 x_append_glyph_string (&HEAD, &TAIL, s); \
4749 /* Add a glyph string for an image glyph to the list of strings
4750 between HEAD and TAIL. START is the index of the image glyph in
4751 row area AREA of glyph row ROW. END is the index of the last glyph
4752 in that glyph row area. X is the current output position assigned
4753 to the new glyph string constructed. HL overrides that face of the
4754 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4755 is the right-most x-position of the drawing area. */
4757 #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4760 s = (struct glyph_string *) alloca (sizeof *s); \
4761 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4762 x_fill_image_glyph_string (s); \
4763 x_append_glyph_string (&HEAD, &TAIL, s); \
4770 /* Add a glyph string for a sequence of character glyphs to the list
4771 of strings between HEAD and TAIL. START is the index of the first
4772 glyph in row area AREA of glyph row ROW that is part of the new
4773 glyph string. END is the index of the last glyph in that glyph row
4774 area. X is the current output position assigned to the new glyph
4775 string constructed. HL overrides that face of the glyph; e.g. it
4776 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4777 right-most x-position of the drawing area. */
4779 #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4785 c = (ROW)->glyphs[AREA][START].u.ch; \
4786 face_id = (ROW)->glyphs[AREA][START].face_id; \
4788 s = (struct glyph_string *) alloca (sizeof *s); \
4789 char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \
4790 w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \
4791 x_append_glyph_string (&HEAD, &TAIL, s); \
4793 START = x_fill_glyph_string (s, face_id, START, END, \
4799 /* Add a glyph string for a composite sequence to the list of strings
4800 between HEAD and TAIL. START is the index of the first glyph in
4801 row area AREA of glyph row ROW that is part of the new glyph
4802 string. END is the index of the last glyph in that glyph row area.
4803 X is the current output position assigned to the new glyph string
4804 constructed. HL overrides that face of the glyph; e.g. it is
4805 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4806 x-position of the drawing area. */
4808 #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4810 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4811 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4812 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4813 struct composition *cmp = composition_table[cmp_id]; \
4814 int glyph_len = cmp->glyph_len; \
4816 struct face **faces; \
4817 struct glyph_string *first_s = NULL; \
4820 base_face = base_face->ascii_face; \
4821 char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \
4822 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4823 /* At first, fill in `char2b' and `faces'. */ \
4824 for (n = 0; n < glyph_len; n++) \
4826 int c = COMPOSITION_GLYPH (cmp, n); \
4827 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4828 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4829 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4830 this_face_id, char2b + n, 1); \
4833 /* Make glyph_strings for each glyph sequence that is drawable by \
4834 the same face, and append them to HEAD/TAIL. */ \
4835 for (n = 0; n < cmp->glyph_len;) \
4837 s = (struct glyph_string *) alloca (sizeof *s); \
4838 w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \
4839 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4847 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4855 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4856 of AREA of glyph row ROW on window W between indices START and END.
4857 HL overrides the face for drawing glyph strings, e.g. it is
4858 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4859 x-positions of the drawing area.
4861 This is an ugly monster macro construct because we must use alloca
4862 to allocate glyph strings (because x_draw_glyphs can be called
4865 #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4868 HEAD = TAIL = NULL; \
4869 while (START < END) \
4871 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4872 switch (first_glyph->type) \
4875 BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \
4876 HEAD, TAIL, HL, X, LAST_X, \
4880 case COMPOSITE_GLYPH: \
4881 BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \
4882 END, HEAD, TAIL, HL, X, \
4883 LAST_X, OVERLAPS_P); \
4886 case STRETCH_GLYPH: \
4887 BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\
4888 HEAD, TAIL, HL, X, LAST_X); \
4892 BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \
4893 HEAD, TAIL, HL, X, LAST_X); \
4900 x_set_glyph_string_background_width (s, START, LAST_X); \
4907 /* Draw glyphs between START and END in AREA of ROW on window W,
4908 starting at x-position X. X is relative to AREA in W. HL is a
4909 face-override with the following meaning:
4911 DRAW_NORMAL_TEXT draw normally
4912 DRAW_CURSOR draw in cursor face
4913 DRAW_MOUSE_FACE draw in mouse face.
4914 DRAW_INVERSE_VIDEO draw in mode line face
4915 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4916 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4918 If OVERLAPS_P is non-zero, draw only the foreground of characters
4919 and clip to the physical height of ROW.
4921 Value is the x-position reached, relative to AREA of W. */
4924 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
4927 struct glyph_row
*row
;
4928 enum glyph_row_area area
;
4930 enum draw_glyphs_face hl
;
4933 struct glyph_string
*head
, *tail
;
4934 struct glyph_string
*s
;
4935 int last_x
, area_width
;
4938 HDC hdc
= get_frame_dc (XFRAME (WINDOW_FRAME (w
)));
4940 /* Let's rather be paranoid than getting a SEGV. */
4941 end
= min (end
, row
->used
[area
]);
4942 start
= max (0, start
);
4943 start
= min (end
, start
);
4945 /* Translate X to frame coordinates. Set last_x to the right
4946 end of the drawing area. */
4947 if (row
->full_width_p
)
4949 /* X is relative to the left edge of W, without scroll bars
4951 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4952 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4955 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4956 last_x
= window_left_x
+ area_width
;
4958 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4960 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4961 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4967 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4968 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4972 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4973 area_width
= window_box_width (w
, area
);
4974 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4977 /* Build a doubly-linked list of glyph_string structures between
4978 head and tail from what we have to draw. Note that the macro
4979 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4980 the reason we use a separate variable `i'. */
4982 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4985 x_reached
= tail
->x
+ tail
->background_width
;
4989 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4990 the row, redraw some glyphs in front or following the glyph
4991 strings built above. */
4992 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4995 struct glyph_string
*h
, *t
;
4997 /* Compute overhangs for all glyph strings. */
4998 for (s
= head
; s
; s
= s
->next
)
4999 x_compute_glyph_string_overhangs (s
);
5001 /* Prepend glyph strings for glyphs in front of the first glyph
5002 string that are overwritten because of the first glyph
5003 string's left overhang. The background of all strings
5004 prepended must be drawn because the first glyph string
5006 i
= x_left_overwritten (head
);
5010 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, j
, start
, h
, t
,
5011 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5014 x_compute_overhangs_and_x (t
, head
->x
, 1);
5015 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5018 /* Prepend glyph strings for glyphs in front of the first glyph
5019 string that overwrite that glyph string because of their
5020 right overhang. For these strings, only the foreground must
5021 be drawn, because it draws over the glyph string at `head'.
5022 The background must not be drawn because this would overwrite
5023 right overhangs of preceding glyphs for which no glyph
5025 i
= x_left_overwriting (head
);
5028 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, start
, h
, t
,
5029 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5031 for (s
= h
; s
; s
= s
->next
)
5032 s
->background_filled_p
= 1;
5033 x_compute_overhangs_and_x (t
, head
->x
, 1);
5034 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5037 /* Append glyphs strings for glyphs following the last glyph
5038 string tail that are overwritten by tail. The background of
5039 these strings has to be drawn because tail's foreground draws
5041 i
= x_right_overwritten (tail
);
5044 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5045 DRAW_NORMAL_TEXT
, x
, last_x
,
5047 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5048 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5051 /* Append glyph strings for glyphs following the last glyph
5052 string tail that overwrite tail. The foreground of such
5053 glyphs has to be drawn because it writes into the background
5054 of tail. The background must not be drawn because it could
5055 paint over the foreground of following glyphs. */
5056 i
= x_right_overwriting (tail
);
5059 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5060 DRAW_NORMAL_TEXT
, x
, last_x
,
5062 for (s
= h
; s
; s
= s
->next
)
5063 s
->background_filled_p
= 1;
5064 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5065 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5069 /* Draw all strings. */
5070 for (s
= head
; s
; s
= s
->next
)
5071 x_draw_glyph_string (s
);
5073 if (area
== TEXT_AREA
5074 && !row
->full_width_p
5075 /* When drawing overlapping rows, only the glyph strings'
5076 foreground is drawn, which doesn't erase a cursor
5080 int x0
= head
? head
->x
: x
;
5081 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5083 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5084 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5086 if (!row
->full_width_p
&& XFASTINT (w
->left_margin_width
) != 0)
5088 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5089 x0
-= left_area_width
;
5090 x1
-= left_area_width
;
5093 notice_overwritten_cursor (w
, area
, x0
, x1
,
5094 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5097 /* Value is the x-position up to which drawn, relative to AREA of W.
5098 This doesn't include parts drawn because of overhangs. */
5099 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5100 if (!row
->full_width_p
)
5102 if (area
> LEFT_MARGIN_AREA
)
5103 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5104 if (area
> TEXT_AREA
)
5105 x_reached
-= window_box_width (w
, TEXT_AREA
);
5108 release_frame_dc (XFRAME (WINDOW_FRAME (w
)), hdc
);
5114 /* Fix the display of area AREA of overlapping row ROW in window W. */
5117 x_fix_overlapping_area (w
, row
, area
)
5119 struct glyph_row
*row
;
5120 enum glyph_row_area area
;
5126 if (area
== LEFT_MARGIN_AREA
)
5128 else if (area
== TEXT_AREA
)
5129 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5131 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5132 + window_box_width (w
, TEXT_AREA
));
5134 for (i
= 0; i
< row
->used
[area
];)
5136 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5138 int start
= i
, start_x
= x
;
5142 x
+= row
->glyphs
[area
][i
].pixel_width
;
5145 while (i
< row
->used
[area
]
5146 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5148 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5149 DRAW_NORMAL_TEXT
, 1);
5153 x
+= row
->glyphs
[area
][i
].pixel_width
;
5162 /* Output LEN glyphs starting at START at the nominal cursor position.
5163 Advance the nominal cursor over the text. The global variable
5164 updated_window contains the window being updated, updated_row is
5165 the glyph row being updated, and updated_area is the area of that
5166 row being updated. */
5169 x_write_glyphs (start
, len
)
5170 struct glyph
*start
;
5175 xassert (updated_window
&& updated_row
);
5180 hpos
= start
- updated_row
->glyphs
[updated_area
];
5181 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5182 updated_row
, updated_area
,
5184 DRAW_NORMAL_TEXT
, 0);
5188 /* Advance the output cursor. */
5189 output_cursor
.hpos
+= len
;
5190 output_cursor
.x
= x
;
5194 /* Insert LEN glyphs from START at the nominal cursor position. */
5197 x_insert_glyphs (start
, len
)
5198 struct glyph
*start
;
5203 int line_height
, shift_by_width
, shifted_region_width
;
5204 struct glyph_row
*row
;
5205 struct glyph
*glyph
;
5206 int frame_x
, frame_y
, hpos
;
5209 xassert (updated_window
&& updated_row
);
5212 f
= XFRAME (WINDOW_FRAME (w
));
5213 hdc
= get_frame_dc (f
);
5215 /* Get the height of the line we are in. */
5217 line_height
= row
->height
;
5219 /* Get the width of the glyphs to insert. */
5221 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5222 shift_by_width
+= glyph
->pixel_width
;
5224 /* Get the width of the region to shift right. */
5225 shifted_region_width
= (window_box_width (w
, updated_area
)
5230 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5231 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5232 BitBlt (hdc
, frame_x
+ shift_by_width
, frame_y
,
5233 shifted_region_width
, line_height
,
5234 hdc
, frame_x
, frame_y
, SRCCOPY
);
5236 /* Write the glyphs. */
5237 hpos
= start
- row
->glyphs
[updated_area
];
5238 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5239 DRAW_NORMAL_TEXT
, 0);
5241 /* Advance the output cursor. */
5242 output_cursor
.hpos
+= len
;
5243 output_cursor
.x
+= shift_by_width
;
5244 release_frame_dc (f
, hdc
);
5250 /* Delete N glyphs at the nominal cursor position. Not implemented
5262 f
= SELECTED_FRAME ();
5264 if (! FRAME_W32_P (f
))
5271 /* Erase the current text line from the nominal cursor position
5272 (inclusive) to pixel column TO_X (exclusive). The idea is that
5273 everything from TO_X onward is already erased.
5275 TO_X is a pixel position relative to updated_area of
5276 updated_window. TO_X == -1 means clear to the end of this area. */
5279 x_clear_end_of_line (to_x
)
5283 struct window
*w
= updated_window
;
5284 int max_x
, min_y
, max_y
;
5285 int from_x
, from_y
, to_y
;
5287 xassert (updated_window
&& updated_row
);
5288 f
= XFRAME (w
->frame
);
5290 if (updated_row
->full_width_p
)
5292 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5293 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5294 && !w
->pseudo_window_p
)
5295 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5298 max_x
= window_box_width (w
, updated_area
);
5299 max_y
= window_text_bottom_y (w
);
5301 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5302 of window. For TO_X > 0, truncate to end of drawing area. */
5308 to_x
= min (to_x
, max_x
);
5310 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5312 /* Notice if the cursor will be cleared by this operation. */
5313 if (!updated_row
->full_width_p
)
5314 notice_overwritten_cursor (w
, updated_area
,
5315 output_cursor
.x
, -1,
5317 MATRIX_ROW_BOTTOM_Y (updated_row
));
5319 from_x
= output_cursor
.x
;
5321 /* Translate to frame coordinates. */
5322 if (updated_row
->full_width_p
)
5324 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5325 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5329 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5330 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5333 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5334 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5335 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5337 /* Prevent inadvertently clearing to end of the X window. */
5338 if (to_x
> from_x
&& to_y
> from_y
)
5342 hdc
= get_frame_dc (f
);
5344 w32_clear_area (f
, hdc
, from_x
, from_y
, to_x
- from_x
, to_y
- from_y
);
5345 release_frame_dc (f
, hdc
);
5351 /* Clear entire frame. If updating_frame is non-null, clear that
5352 frame. Otherwise clear the selected frame. */
5362 f
= SELECTED_FRAME ();
5364 if (! FRAME_W32_P (f
))
5367 /* Clearing the frame will erase any cursor, so mark them all as no
5369 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5370 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5371 output_cursor
.x
= -1;
5373 /* We don't set the output cursor here because there will always
5374 follow an explicit cursor_to. */
5377 w32_clear_window (f
);
5379 /* We have to clear the scroll bars, too. If we have changed
5380 colors or something like that, then they should be notified. */
5381 x_scroll_bar_clear (f
);
5387 /* Make audible bell. */
5390 w32_ring_bell (void)
5394 f
= SELECTED_FRAME ();
5398 if (FRAME_W32_P (f
) && visible_bell
)
5401 HWND hwnd
= FRAME_W32_WINDOW (SELECTED_FRAME ());
5403 for (i
= 0; i
< 5; i
++)
5405 FlashWindow (hwnd
, TRUE
);
5408 FlashWindow (hwnd
, FALSE
);
5411 w32_sys_ring_bell ();
5417 /* Specify how many text lines, from the top of the window,
5418 should be affected by insert-lines and delete-lines operations.
5419 This, and those operations, are used only within an update
5420 that is bounded by calls to x_update_begin and x_update_end. */
5423 w32_set_terminal_window (n
)
5426 /* This function intentionally left blank. */
5431 /***********************************************************************
5433 ***********************************************************************/
5435 /* Perform an insert-lines or delete-lines operation, inserting N
5436 lines or deleting -N lines at vertical position VPOS. */
5439 x_ins_del_lines (vpos
, n
)
5447 f
= SELECTED_FRAME ();
5449 if (! FRAME_W32_P (f
))
5456 /* Scroll part of the display as described by RUN. */
5459 x_scroll_run (w
, run
)
5463 struct frame
*f
= XFRAME (w
->frame
);
5464 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5465 HWND hwnd
= FRAME_W32_WINDOW (f
);
5468 /* Get frame-relative bounding box of the text display area of W,
5469 without mode lines. Include in this box the left and right
5471 window_box (w
, -1, &x
, &y
, &width
, &height
);
5472 width
+= FRAME_X_FRINGE_WIDTH (f
);
5473 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5475 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5476 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5477 bottom_y
= y
+ height
;
5481 /* Scrolling up. Make sure we don't copy part of the mode
5482 line at the bottom. */
5483 if (from_y
+ run
->height
> bottom_y
)
5484 height
= bottom_y
- from_y
;
5486 height
= run
->height
;
5487 expect_dirty
= CreateRectRgn (x
, y
+ height
, x
+ width
, bottom_y
);
5491 /* Scolling down. Make sure we don't copy over the mode line.
5493 if (to_y
+ run
->height
> bottom_y
)
5494 height
= bottom_y
- to_y
;
5496 height
= run
->height
;
5497 expect_dirty
= CreateRectRgn (x
, y
, x
+ width
, to_y
);
5502 /* Cursor off. Will be switched on again in x_update_window_end. */
5509 HRGN dirty
= CreateRectRgn (0, 0, 0, 0);
5510 HRGN combined
= CreateRectRgn (0, 0, 0, 0);
5512 from
.left
= to
.left
= x
;
5513 from
.right
= to
.right
= x
+ width
;
5515 from
.bottom
= from_y
+ height
;
5517 to
.bottom
= bottom_y
;
5519 ScrollWindowEx (hwnd
, 0, to_y
- from_y
, &from
, &to
, dirty
,
5520 NULL
, SW_INVALIDATE
);
5522 /* Combine this with what we expect to be dirty. This covers the
5523 case where not all of the region we expect is actually dirty. */
5524 CombineRgn (combined
, dirty
, expect_dirty
, RGN_OR
);
5526 /* If the dirty region is not what we expected, redraw the entire frame. */
5527 if (!EqualRgn (combined
, expect_dirty
))
5528 SET_FRAME_GARBAGED (f
);
5536 /***********************************************************************
5538 ***********************************************************************/
5540 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5541 corner of the exposed rectangle. W and H are width and height of
5542 the exposed area. All are pixel values. W or H zero means redraw
5543 the entire frame. */
5546 expose_frame (f
, x
, y
, w
, h
)
5551 int mouse_face_overwritten_p
= 0;
5553 TRACE ((stderr
, "expose_frame "));
5555 /* No need to redraw if frame will be redrawn soon. */
5556 if (FRAME_GARBAGED_P (f
))
5558 TRACE ((stderr
, " garbaged\n"));
5562 /* If basic faces haven't been realized yet, there is no point in
5563 trying to redraw anything. This can happen when we get an expose
5564 event while Emacs is starting, e.g. by moving another window. */
5565 if (FRAME_FACE_CACHE (f
) == NULL
5566 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5568 TRACE ((stderr
, " no faces\n"));
5572 if (w
== 0 || h
== 0)
5575 r
.right
= CANON_X_UNIT (f
) * f
->width
;
5576 r
.bottom
= CANON_Y_UNIT (f
) * f
->height
;
5586 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.left
, r
.top
, r
.right
, r
.bottom
));
5587 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5589 if (WINDOWP (f
->tool_bar_window
))
5590 mouse_face_overwritten_p
5591 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5593 /* Some window managers support a focus-follows-mouse style with
5594 delayed raising of frames. Imagine a partially obscured frame,
5595 and moving the mouse into partially obscured mouse-face on that
5596 frame. The visible part of the mouse-face will be highlighted,
5597 then the WM raises the obscured frame. With at least one WM, KDE
5598 2.1, Emacs is not getting any event for the raising of the frame
5599 (even tried with SubstructureRedirectMask), only Expose events.
5600 These expose events will draw text normally, i.e. not
5601 highlighted. Which means we must redo the highlight here.
5602 Subsume it under ``we love X''. --gerd 2001-08-15 */
5603 /* Included in Windows version because Windows most likely does not
5604 do the right thing if any third party tool offers
5605 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
5606 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5608 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5609 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5611 int x
= dpyinfo
->mouse_face_mouse_x
;
5612 int y
= dpyinfo
->mouse_face_mouse_y
;
5613 clear_mouse_face (dpyinfo
);
5614 note_mouse_highlight (f
, x
, y
);
5620 /* Redraw (parts) of all windows in the window tree rooted at W that
5621 intersect R. R contains frame pixel coordinates. */
5624 expose_window_tree (w
, r
)
5628 struct frame
*f
= XFRAME (w
->frame
);
5629 int mouse_face_overwritten_p
= 0;
5631 while (w
&& !FRAME_GARBAGED_P (f
))
5633 if (!NILP (w
->hchild
))
5634 mouse_face_overwritten_p
5635 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5636 else if (!NILP (w
->vchild
))
5637 mouse_face_overwritten_p
5638 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5640 mouse_face_overwritten_p
|= expose_window (w
, r
);
5642 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5645 return mouse_face_overwritten_p
;
5649 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5650 which intersects rectangle R. R is in window-relative coordinates. */
5653 expose_area (w
, row
, r
, area
)
5655 struct glyph_row
*row
;
5657 enum glyph_row_area area
;
5659 struct glyph
*first
= row
->glyphs
[area
];
5660 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5662 int first_x
, start_x
, x
;
5664 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5665 /* If row extends face to end of line write the whole line. */
5666 x_draw_glyphs (w
, 0, row
, area
,
5668 DRAW_NORMAL_TEXT
, 0);
5671 /* Set START_X to the window-relative start position for drawing glyphs of
5672 AREA. The first glyph of the text area can be partially visible.
5673 The first glyphs of other areas cannot. */
5674 if (area
== LEFT_MARGIN_AREA
)
5676 else if (area
== TEXT_AREA
)
5677 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5679 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5680 + window_box_width (w
, TEXT_AREA
));
5683 /* Find the first glyph that must be redrawn. */
5685 && x
+ first
->pixel_width
< r
->left
)
5687 x
+= first
->pixel_width
;
5691 /* Find the last one. */
5697 x
+= last
->pixel_width
;
5703 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5704 first
- row
->glyphs
[area
],
5705 last
- row
->glyphs
[area
],
5706 DRAW_NORMAL_TEXT
, 0);
5711 /* Redraw the parts of the glyph row ROW on window W intersecting
5712 rectangle R. R is in window-relative coordinates. Value is
5713 non-zero if mouse face was overwritten. */
5716 expose_line (w
, row
, r
)
5718 struct glyph_row
*row
;
5721 xassert (row
->enabled_p
);
5723 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5724 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5725 DRAW_NORMAL_TEXT
, 0);
5728 if (row
->used
[LEFT_MARGIN_AREA
])
5729 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5730 if (row
->used
[TEXT_AREA
])
5731 expose_area (w
, row
, r
, TEXT_AREA
);
5732 if (row
->used
[RIGHT_MARGIN_AREA
])
5733 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5734 x_draw_row_fringe_bitmaps (w
, row
);
5737 return row
->mouse_face_p
;
5741 /* Return non-zero if W's cursor intersects rectangle R. */
5744 x_phys_cursor_in_rect_p (w
, r
)
5749 struct glyph
*cursor_glyph
;
5751 cursor_glyph
= get_phys_cursor_glyph (w
);
5754 cr
.left
= w
->phys_cursor
.x
;
5755 cr
.top
= w
->phys_cursor
.y
;
5756 cr
.right
= cr
.left
+ cursor_glyph
->pixel_width
;
5757 cr
.bottom
= cr
.top
+ w
->phys_cursor_height
;
5758 return IntersectRect (&result
, &cr
, r
);
5765 /* Redraw the part of window W intersection rectagle FR. Pixel
5766 coordinates in FR are frame relative. Call this function with
5767 input blocked. Value is non-zero if the exposure overwrites
5771 expose_window (w
, fr
)
5775 struct frame
*f
= XFRAME (w
->frame
);
5777 int mouse_face_overwritten_p
= 0;
5779 /* If window is not yet fully initialized, do nothing. This can
5780 happen when toolkit scroll bars are used and a window is split.
5781 Reconfiguring the scroll bar will generate an expose for a newly
5783 if (w
->current_matrix
== NULL
)
5786 /* When we're currently updating the window, display and current
5787 matrix usually don't agree. Arrange for a thorough display
5789 if (w
== updated_window
)
5791 SET_FRAME_GARBAGED (f
);
5795 /* Frame-relative pixel rectangle of W. */
5796 wr
.left
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
5797 wr
.top
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
5798 wr
.right
= wr
.left
+ XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5799 wr
.bottom
= wr
.top
+ XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
5801 if (IntersectRect(&r
, fr
, &wr
))
5803 int yb
= window_text_bottom_y (w
);
5804 struct glyph_row
*row
;
5805 int cursor_cleared_p
;
5807 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5808 r
.left
, r
.top
, r
.right
, r
.bottom
));
5810 /* Convert to window coordinates. */
5811 r
.left
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.left
);
5812 r
.right
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.right
);
5813 r
.top
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.top
);
5814 r
.bottom
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.bottom
);
5816 /* Turn off the cursor. */
5817 if (!w
->pseudo_window_p
5818 && x_phys_cursor_in_rect_p (w
, &r
))
5821 cursor_cleared_p
= 1;
5824 cursor_cleared_p
= 0;
5826 /* Find the first row intersecting the rectangle R. */
5827 for (row
= w
->current_matrix
->rows
;
5832 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
5834 if ((y0
>= r
.top
&& y0
< r
.bottom
)
5835 || (y1
> r
.top
&& y1
< r
.bottom
)
5836 || (r
.top
>= y0
&& r
.top
< y1
)
5837 || (r
.bottom
> y0
&& r
.bottom
< y1
))
5839 if (expose_line (w
, row
, &r
))
5840 mouse_face_overwritten_p
= 1;
5847 /* Display the mode line if there is one. */
5848 if (WINDOW_WANTS_MODELINE_P (w
)
5849 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5851 && row
->y
< r
.bottom
)
5853 if (expose_line (w
, row
, &r
))
5854 mouse_face_overwritten_p
= 1;
5857 if (!w
->pseudo_window_p
)
5859 /* Draw border between windows. */
5860 x_draw_vertical_border (w
);
5862 /* Turn the cursor on again. */
5863 if (cursor_cleared_p
)
5864 x_update_window_cursor (w
, 1);
5868 return mouse_face_overwritten_p
;
5876 x_update_cursor (f
, 1);
5880 frame_unhighlight (f
)
5883 x_update_cursor (f
, 1);
5886 /* The focus has changed. Update the frames as necessary to reflect
5887 the new situation. Note that we can't change the selected frame
5888 here, because the Lisp code we are interrupting might become confused.
5889 Each event gets marked with the frame in which it occurred, so the
5890 Lisp code can tell when the switch took place by examining the events. */
5893 x_new_focus_frame (dpyinfo
, frame
)
5894 struct w32_display_info
*dpyinfo
;
5895 struct frame
*frame
;
5897 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
5899 if (frame
!= dpyinfo
->w32_focus_frame
)
5901 /* Set this before calling other routines, so that they see
5902 the correct value of w32_focus_frame. */
5903 dpyinfo
->w32_focus_frame
= frame
;
5905 if (old_focus
&& old_focus
->auto_lower
)
5906 x_lower_frame (old_focus
);
5908 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
5909 pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
5911 pending_autoraise_frame
= 0;
5914 x_frame_rehighlight (dpyinfo
);
5917 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5920 x_mouse_leave (dpyinfo
)
5921 struct w32_display_info
*dpyinfo
;
5923 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
5926 /* The focus has changed, or we have redirected a frame's focus to
5927 another frame (this happens when a frame uses a surrogate
5928 mini-buffer frame). Shift the highlight as appropriate.
5930 The FRAME argument doesn't necessarily have anything to do with which
5931 frame is being highlighted or un-highlighted; we only use it to find
5932 the appropriate X display info. */
5935 w32_frame_rehighlight (frame
)
5936 struct frame
*frame
;
5938 if (! FRAME_W32_P (frame
))
5940 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame
));
5944 x_frame_rehighlight (dpyinfo
)
5945 struct w32_display_info
*dpyinfo
;
5947 struct frame
*old_highlight
= dpyinfo
->w32_highlight_frame
;
5949 if (dpyinfo
->w32_focus_frame
)
5951 dpyinfo
->w32_highlight_frame
5952 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
5953 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
5954 : dpyinfo
->w32_focus_frame
);
5955 if (! FRAME_LIVE_P (dpyinfo
->w32_highlight_frame
))
5957 FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
) = Qnil
;
5958 dpyinfo
->w32_highlight_frame
= dpyinfo
->w32_focus_frame
;
5962 dpyinfo
->w32_highlight_frame
= 0;
5964 if (dpyinfo
->w32_highlight_frame
!= old_highlight
)
5967 frame_unhighlight (old_highlight
);
5968 if (dpyinfo
->w32_highlight_frame
)
5969 frame_highlight (dpyinfo
->w32_highlight_frame
);
5973 /* Keyboard processing - modifier keys, etc. */
5975 /* Convert a keysym to its name. */
5978 x_get_keysym_name (keysym
)
5981 /* Make static so we can always return it */
5982 static char value
[100];
5985 GetKeyNameText (keysym
, value
, 100);
5993 /* Mouse clicks and mouse movement. Rah. */
5995 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5996 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5997 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5998 not force the value into range. */
6001 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6003 register int pix_x
, pix_y
;
6004 register int *x
, *y
;
6008 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
6009 if (NILP (Vwindow_system
))
6016 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6017 even for negative values. */
6019 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
6021 pix_y
-= (f
)->output_data
.w32
->line_height
- 1;
6023 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6024 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6028 bounds
->left
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6029 bounds
->top
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6030 bounds
->right
= bounds
->left
+ FONT_WIDTH (FRAME_FONT (f
)) - 1;
6031 bounds
->bottom
= bounds
->top
+ f
->output_data
.w32
->line_height
- 1;
6038 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6039 pix_x
= FRAME_WINDOW_WIDTH (f
);
6043 else if (pix_y
> f
->height
)
6052 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6053 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6054 can't tell the positions because W's display is not up to date,
6058 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6061 int *frame_x
, *frame_y
;
6065 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6066 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6068 if (display_completed
)
6070 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6071 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6072 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6078 *frame_x
+= glyph
->pixel_width
;
6086 *frame_y
= *frame_x
= 0;
6090 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6091 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6095 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
6096 the state in PUP. XBUTTON provides extra information for extended mouse
6097 button messages. Returns FALSE if unable to parse the message. */
6099 parse_button (message
, xbutton
, pbutton
, pup
)
6110 case WM_LBUTTONDOWN
:
6118 case WM_MBUTTONDOWN
:
6119 if (NILP (Vw32_swap_mouse_buttons
))
6126 if (NILP (Vw32_swap_mouse_buttons
))
6132 case WM_RBUTTONDOWN
:
6133 if (NILP (Vw32_swap_mouse_buttons
))
6140 if (NILP (Vw32_swap_mouse_buttons
))
6146 case WM_XBUTTONDOWN
:
6147 button
= xbutton
+ 2;
6151 button
= xbutton
+ 2;
6159 if (pbutton
) *pbutton
= button
;
6165 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6167 If the event is a button press, then note that we have grabbed
6171 construct_mouse_click (result
, msg
, f
)
6172 struct input_event
*result
;
6179 parse_button (msg
->msg
.message
, HIWORD (msg
->msg
.wParam
),
6182 /* Make the event type no_event; we'll change that when we decide
6184 result
->kind
= mouse_click
;
6185 result
->code
= button
;
6186 result
->timestamp
= msg
->msg
.time
;
6187 result
->modifiers
= (msg
->dwModifiers
6192 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
6193 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
6194 XSETFRAME (result
->frame_or_window
, f
);
6200 construct_mouse_wheel (result
, msg
, f
)
6201 struct input_event
*result
;
6206 result
->kind
= mouse_wheel
;
6207 result
->code
= (short) HIWORD (msg
->msg
.wParam
);
6208 result
->timestamp
= msg
->msg
.time
;
6209 result
->modifiers
= msg
->dwModifiers
;
6210 p
.x
= LOWORD (msg
->msg
.lParam
);
6211 p
.y
= HIWORD (msg
->msg
.lParam
);
6212 ScreenToClient (msg
->msg
.hwnd
, &p
);
6213 XSETINT (result
->x
, p
.x
);
6214 XSETINT (result
->y
, p
.y
);
6215 XSETFRAME (result
->frame_or_window
, f
);
6221 construct_drag_n_drop (result
, msg
, f
)
6222 struct input_event
*result
;
6234 result
->kind
= drag_n_drop
;
6236 result
->timestamp
= msg
->msg
.time
;
6237 result
->modifiers
= msg
->dwModifiers
;
6239 hdrop
= (HDROP
) msg
->msg
.wParam
;
6240 DragQueryPoint (hdrop
, &p
);
6243 p
.x
= LOWORD (msg
->msg
.lParam
);
6244 p
.y
= HIWORD (msg
->msg
.lParam
);
6245 ScreenToClient (msg
->msg
.hwnd
, &p
);
6248 XSETINT (result
->x
, p
.x
);
6249 XSETINT (result
->y
, p
.y
);
6251 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
6254 for (i
= 0; i
< num_files
; i
++)
6256 len
= DragQueryFile (hdrop
, i
, NULL
, 0);
6259 name
= alloca (len
+ 1);
6260 DragQueryFile (hdrop
, i
, name
, len
+ 1);
6261 files
= Fcons (build_string (name
), files
);
6266 XSETFRAME (frame
, f
);
6267 result
->frame_or_window
= Fcons (frame
, files
);
6273 /* Function to report a mouse movement to the mainstream Emacs code.
6274 The input handler calls this.
6276 We have received a mouse movement event, which is given in *event.
6277 If the mouse is over a different glyph than it was last time, tell
6278 the mainstream emacs code by setting mouse_moved. If not, ask for
6279 another motion event, so we can check again the next time it moves. */
6281 static MSG last_mouse_motion_event
;
6282 static Lisp_Object last_mouse_motion_frame
;
6284 static void remember_mouse_glyph
P_ ((struct frame
*, int, int));
6287 note_mouse_movement (frame
, msg
)
6291 int mouse_x
= LOWORD (msg
->lParam
);
6292 int mouse_y
= HIWORD (msg
->lParam
);
6294 last_mouse_movement_time
= msg
->time
;
6295 memcpy (&last_mouse_motion_event
, msg
, sizeof (last_mouse_motion_event
));
6296 XSETFRAME (last_mouse_motion_frame
, frame
);
6298 if (x_autoselect_window_p
)
6302 static Lisp_Object last_window
;
6304 window
= window_from_coordinates (frame
, mouse_x
, mouse_y
, &area
, 0);
6306 /* Window will be selected only when it is not selected now and
6307 last mouse movement event was not in it. Minubuffer window
6308 will be selected iff it is active. */
6309 if (!EQ (window
, last_window
)
6310 && !EQ (window
, selected_window
)
6311 && (!MINI_WINDOW_P (XWINDOW (window
))
6312 || (EQ (window
, minibuf_window
) && minibuf_level
> 0)))
6313 Fselect_window (window
);
6318 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
6320 frame
->mouse_moved
= 1;
6321 last_mouse_scroll_bar
= Qnil
;
6322 note_mouse_highlight (frame
, -1, -1);
6325 /* Has the mouse moved off the glyph it was on at the last sighting? */
6326 else if (mouse_x
< last_mouse_glyph
.left
6327 || mouse_x
> last_mouse_glyph
.right
6328 || mouse_y
< last_mouse_glyph
.top
6329 || mouse_y
> last_mouse_glyph
.bottom
)
6331 frame
->mouse_moved
= 1;
6332 last_mouse_scroll_bar
= Qnil
;
6333 note_mouse_highlight (frame
, mouse_x
, mouse_y
);
6334 /* Remember the mouse position here, as w32_mouse_position only
6335 gets called when mouse tracking is enabled but we also need
6336 to keep track of the mouse for help_echo and highlighting at
6338 remember_mouse_glyph (frame
, mouse_x
, mouse_y
);
6343 /************************************************************************
6345 ************************************************************************/
6347 /* Find the glyph under window-relative coordinates X/Y in window W.
6348 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6349 strings. Return in *HPOS and *VPOS the row and column number of
6350 the glyph found. Return in *AREA the glyph area containing X.
6351 Value is a pointer to the glyph found or null if X/Y is not on
6352 text, or we can't tell because W's current matrix is not up to
6355 static struct glyph
*
6356 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6359 int *hpos
, *vpos
, *area
;
6362 struct glyph
*glyph
, *end
;
6363 struct glyph_row
*row
= NULL
;
6364 int x0
, i
, left_area_width
;
6366 /* Find row containing Y. Give up if some row is not enabled. */
6367 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6369 row
= MATRIX_ROW (w
->current_matrix
, i
);
6370 if (!row
->enabled_p
)
6372 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6379 /* Give up if Y is not in the window. */
6380 if (i
== w
->current_matrix
->nrows
)
6383 /* Get the glyph area containing X. */
6384 if (w
->pseudo_window_p
)
6391 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6392 if (x
< left_area_width
)
6394 *area
= LEFT_MARGIN_AREA
;
6397 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6400 x0
= row
->x
+ left_area_width
;
6404 *area
= RIGHT_MARGIN_AREA
;
6405 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6409 /* Find glyph containing X. */
6410 glyph
= row
->glyphs
[*area
];
6411 end
= glyph
+ row
->used
[*area
];
6414 if (x
< x0
+ glyph
->pixel_width
)
6416 if (w
->pseudo_window_p
)
6418 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6422 x0
+= glyph
->pixel_width
;
6429 *hpos
= glyph
- row
->glyphs
[*area
];
6434 /* Convert frame-relative x/y to coordinates relative to window W.
6435 Takes pseudo-windows into account. */
6438 frame_to_window_pixel_xy (w
, x
, y
)
6442 if (w
->pseudo_window_p
)
6444 /* A pseudo-window is always full-width, and starts at the
6445 left edge of the frame, plus a frame border. */
6446 struct frame
*f
= XFRAME (w
->frame
);
6447 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6448 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6452 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6453 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6458 /* Take proper action when mouse has moved to the mode or header line of
6459 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6460 mode line. X is relative to the start of the text display area of
6461 W, so the width of fringes and scroll bars must be subtracted
6462 to get a position relative to the start of the mode line. */
6465 note_mode_line_highlight (w
, x
, mode_line_p
)
6469 struct frame
*f
= XFRAME (w
->frame
);
6470 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6471 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6472 struct glyph_row
*row
;
6475 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6477 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6481 struct glyph
*glyph
, *end
;
6482 Lisp_Object help
, map
;
6485 /* Find the glyph under X. */
6486 glyph
= row
->glyphs
[TEXT_AREA
];
6487 end
= glyph
+ row
->used
[TEXT_AREA
];
6488 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6489 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
6492 && x
>= x0
+ glyph
->pixel_width
)
6494 x0
+= glyph
->pixel_width
;
6499 && STRINGP (glyph
->object
)
6500 && XSTRING (glyph
->object
)->intervals
6501 && glyph
->charpos
>= 0
6502 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6504 /* If we're on a string with `help-echo' text property,
6505 arrange for the help to be displayed. This is done by
6506 setting the global variable help_echo to the help string. */
6507 help
= Fget_text_property (make_number (glyph
->charpos
),
6508 Qhelp_echo
, glyph
->object
);
6512 XSETWINDOW (help_echo_window
, w
);
6513 help_echo_object
= glyph
->object
;
6514 help_echo_pos
= glyph
->charpos
;
6517 /* Change the mouse pointer according to what is under X/Y. */
6518 map
= Fget_text_property (make_number (glyph
->charpos
),
6519 Qlocal_map
, glyph
->object
);
6521 cursor
= f
->output_data
.w32
->nontext_cursor
;
6524 map
= Fget_text_property (make_number (glyph
->charpos
),
6525 Qkeymap
, glyph
->object
);
6527 cursor
= f
->output_data
.w32
->nontext_cursor
;
6532 #if 0 /* TODO: mouse cursor */
6533 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6538 /* Take proper action when the mouse has moved to position X, Y on
6539 frame F as regards highlighting characters that have mouse-face
6540 properties. Also de-highlighting chars where the mouse was before.
6541 X and Y can be negative or out of range. */
6544 note_mouse_highlight (f
, x
, y
)
6548 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6554 /* When a menu is active, don't highlight because this looks odd. */
6555 if (popup_activated ())
6558 if (NILP (Vmouse_highlight
)
6559 || !f
->glyphs_initialized_p
)
6562 dpyinfo
->mouse_face_mouse_x
= x
;
6563 dpyinfo
->mouse_face_mouse_y
= y
;
6564 dpyinfo
->mouse_face_mouse_frame
= f
;
6566 if (dpyinfo
->mouse_face_defer
)
6571 dpyinfo
->mouse_face_deferred_gc
= 1;
6575 /* Which window is that in? */
6576 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6578 /* If we were displaying active text in another window, clear that. */
6579 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6580 clear_mouse_face (dpyinfo
);
6582 /* Not on a window -> return. */
6583 if (!WINDOWP (window
))
6586 /* Reset help_echo. It will get recomputed below. */
6589 /* Convert to window-relative pixel coordinates. */
6590 w
= XWINDOW (window
);
6591 frame_to_window_pixel_xy (w
, &x
, &y
);
6593 /* Handle tool-bar window differently since it doesn't display a
6595 if (EQ (window
, f
->tool_bar_window
))
6597 note_tool_bar_highlight (f
, x
, y
);
6601 /* Mouse is on the mode or header line? */
6602 if (portion
== 1 || portion
== 3)
6604 note_mode_line_highlight (w
, x
, portion
== 1);
6607 #if 0 /* TODO: mouse cursor */
6609 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6611 cursor
= f
->output_data
.x
->text_cursor
;
6613 /* Are we in a window whose display is up to date?
6614 And verify the buffer's text has not changed. */
6615 b
= XBUFFER (w
->buffer
);
6616 if (/* Within text portion of the window. */
6618 && EQ (w
->window_end_valid
, w
->buffer
)
6619 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6620 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6622 int hpos
, vpos
, pos
, i
, area
;
6623 struct glyph
*glyph
;
6625 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6626 Lisp_Object
*overlay_vec
= NULL
;
6628 struct buffer
*obuf
;
6629 int obegv
, ozv
, same_region
;
6631 /* Find the glyph under X/Y. */
6632 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6634 /* Clear mouse face if X/Y not over text. */
6636 || area
!= TEXT_AREA
6637 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6639 clear_mouse_face (dpyinfo
);
6640 /* TODO: mouse cursor */
6644 pos
= glyph
->charpos
;
6645 object
= glyph
->object
;
6646 if (!STRINGP (object
) && !BUFFERP (object
))
6649 /* If we get an out-of-range value, return now; avoid an error. */
6650 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6653 /* Make the window's buffer temporarily current for
6654 overlays_at and compute_char_face. */
6655 obuf
= current_buffer
;
6662 /* Is this char mouse-active or does it have help-echo? */
6663 position
= make_number (pos
);
6665 if (BUFFERP (object
))
6667 /* Put all the overlays we want in a vector in overlay_vec.
6668 Store the length in len. If there are more than 10, make
6669 enough space for all, and try again. */
6671 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6672 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6673 if (noverlays
> len
)
6676 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6677 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6680 /* Sort overlays into increasing priority order. */
6681 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6686 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
6687 && vpos
>= dpyinfo
->mouse_face_beg_row
6688 && vpos
<= dpyinfo
->mouse_face_end_row
6689 && (vpos
> dpyinfo
->mouse_face_beg_row
6690 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6691 && (vpos
< dpyinfo
->mouse_face_end_row
6692 || hpos
< dpyinfo
->mouse_face_end_col
6693 || dpyinfo
->mouse_face_past_end
));
6695 /* TODO: if (same_region)
6698 /* Check mouse-face highlighting. */
6700 /* If there exists an overlay with mouse-face overlapping
6701 the one we are currently highlighting, we have to
6702 check if we enter the overlapping overlay, and then
6704 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6705 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6707 /* Find the highest priority overlay that has a mouse-face
6710 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
6712 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6713 if (!NILP (mouse_face
))
6714 overlay
= overlay_vec
[i
];
6717 /* If we're actually highlighting the same overlay as
6718 before, there's no need to do that again. */
6720 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
6721 goto check_help_echo
;
6723 dpyinfo
->mouse_face_overlay
= overlay
;
6725 /* Clear the display of the old active region, if any. */
6726 clear_mouse_face (dpyinfo
);
6727 /* TODO: mouse cursor changes. */
6729 /* If no overlay applies, get a text property. */
6731 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
6733 /* Handle the overlay case. */
6734 if (!NILP (overlay
))
6736 /* Find the range of text around this char that
6737 should be active. */
6738 Lisp_Object before
, after
;
6741 before
= Foverlay_start (overlay
);
6742 after
= Foverlay_end (overlay
);
6743 /* Record this as the current active region. */
6744 fast_find_position (w
, XFASTINT (before
),
6745 &dpyinfo
->mouse_face_beg_col
,
6746 &dpyinfo
->mouse_face_beg_row
,
6747 &dpyinfo
->mouse_face_beg_x
,
6748 &dpyinfo
->mouse_face_beg_y
, Qnil
);
6750 dpyinfo
->mouse_face_past_end
6751 = !fast_find_position (w
, XFASTINT (after
),
6752 &dpyinfo
->mouse_face_end_col
,
6753 &dpyinfo
->mouse_face_end_row
,
6754 &dpyinfo
->mouse_face_end_x
,
6755 &dpyinfo
->mouse_face_end_y
, Qnil
);
6756 dpyinfo
->mouse_face_window
= window
;
6758 dpyinfo
->mouse_face_face_id
6759 = face_at_buffer_position (w
, pos
, 0, 0,
6760 &ignore
, pos
+ 1, 1);
6762 /* Display it as active. */
6763 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6764 /* TODO: mouse cursor changes. */
6766 /* Handle the text property case. */
6767 else if (! NILP (mouse_face
) && BUFFERP (object
))
6769 /* Find the range of text around this char that
6770 should be active. */
6771 Lisp_Object before
, after
, beginning
, end
;
6774 beginning
= Fmarker_position (w
->start
);
6775 end
= make_number (BUF_Z (XBUFFER (object
))
6776 - XFASTINT (w
->window_end_pos
));
6778 = Fprevious_single_property_change (make_number (pos
+ 1),
6782 = Fnext_single_property_change (position
, Qmouse_face
,
6785 /* Record this as the current active region. */
6786 fast_find_position (w
, XFASTINT (before
),
6787 &dpyinfo
->mouse_face_beg_col
,
6788 &dpyinfo
->mouse_face_beg_row
,
6789 &dpyinfo
->mouse_face_beg_x
,
6790 &dpyinfo
->mouse_face_beg_y
, Qnil
);
6791 dpyinfo
->mouse_face_past_end
6792 = !fast_find_position (w
, XFASTINT (after
),
6793 &dpyinfo
->mouse_face_end_col
,
6794 &dpyinfo
->mouse_face_end_row
,
6795 &dpyinfo
->mouse_face_end_x
,
6796 &dpyinfo
->mouse_face_end_y
, Qnil
);
6797 dpyinfo
->mouse_face_window
= window
;
6799 if (BUFFERP (object
))
6800 dpyinfo
->mouse_face_face_id
6801 = face_at_buffer_position (w
, pos
, 0, 0,
6802 &ignore
, pos
+ 1, 1);
6804 /* Display it as active. */
6805 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6806 /* TODO: mouse cursor changes. */
6808 else if (!NILP (mouse_face
) && STRINGP (object
))
6813 b
= Fprevious_single_property_change (make_number (pos
+ 1),
6816 e
= Fnext_single_property_change (position
, Qmouse_face
,
6819 b
= make_number (0);
6821 e
= make_number (XSTRING (object
)->size
- 1);
6822 fast_find_string_pos (w
, XINT (b
), object
,
6823 &dpyinfo
->mouse_face_beg_col
,
6824 &dpyinfo
->mouse_face_beg_row
,
6825 &dpyinfo
->mouse_face_beg_x
,
6826 &dpyinfo
->mouse_face_beg_y
, 0);
6827 fast_find_string_pos (w
, XINT (e
), object
,
6828 &dpyinfo
->mouse_face_end_col
,
6829 &dpyinfo
->mouse_face_end_row
,
6830 &dpyinfo
->mouse_face_end_x
,
6831 &dpyinfo
->mouse_face_end_y
, 1);
6832 dpyinfo
->mouse_face_past_end
= 0;
6833 dpyinfo
->mouse_face_window
= window
;
6834 dpyinfo
->mouse_face_face_id
6835 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
6837 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6838 /* TODO: mouse cursor changes. */
6840 else if (STRINGP (object
) && NILP (mouse_face
))
6842 /* A string which doesn't have mouse-face, but
6843 the text ``under'' it might have. */
6844 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
6845 int start
= MATRIX_ROW_START_CHARPOS (r
);
6847 pos
= string_buffer_position (w
, object
, start
);
6849 mouse_face
= get_char_property_and_overlay (make_number (pos
),
6853 if (!NILP (mouse_face
) && !NILP (overlay
))
6855 Lisp_Object before
= Foverlay_start (overlay
);
6856 Lisp_Object after
= Foverlay_end (overlay
);
6859 /* Note that we might not be able to find position
6860 BEFORE in the glyph matrix if the overlay is
6861 entirely covered by a `display' property. In
6862 this case, we overshoot. So let's stop in
6863 the glyph matrix before glyphs for OBJECT. */
6864 fast_find_position (w
, XFASTINT (before
),
6865 &dpyinfo
->mouse_face_beg_col
,
6866 &dpyinfo
->mouse_face_beg_row
,
6867 &dpyinfo
->mouse_face_beg_x
,
6868 &dpyinfo
->mouse_face_beg_y
,
6871 dpyinfo
->mouse_face_past_end
6872 = !fast_find_position (w
, XFASTINT (after
),
6873 &dpyinfo
->mouse_face_end_col
,
6874 &dpyinfo
->mouse_face_end_row
,
6875 &dpyinfo
->mouse_face_end_x
,
6876 &dpyinfo
->mouse_face_end_y
,
6878 dpyinfo
->mouse_face_window
= window
;
6879 dpyinfo
->mouse_face_face_id
6880 = face_at_buffer_position (w
, pos
, 0, 0,
6881 &ignore
, pos
+ 1, 1);
6883 /* Display it as active. */
6884 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6885 /* TODO: mouse cursor changes. */
6892 /* Look for a `help-echo' property. */
6894 Lisp_Object help
, overlay
;
6896 /* Check overlays first. */
6897 help
= overlay
= Qnil
;
6898 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6900 overlay
= overlay_vec
[i
];
6901 help
= Foverlay_get (overlay
, Qhelp_echo
);
6907 help_echo_window
= window
;
6908 help_echo_object
= overlay
;
6909 help_echo_pos
= pos
;
6913 Lisp_Object object
= glyph
->object
;
6914 int charpos
= glyph
->charpos
;
6916 /* Try text properties. */
6917 if (STRINGP (object
)
6919 && charpos
< XSTRING (object
)->size
)
6921 help
= Fget_text_property (make_number (charpos
),
6922 Qhelp_echo
, object
);
6925 /* If the string itself doesn't specify a help-echo,
6926 see if the buffer text ``under'' it does. */
6928 = MATRIX_ROW (w
->current_matrix
, vpos
);
6929 int start
= MATRIX_ROW_START_CHARPOS (r
);
6930 int pos
= string_buffer_position (w
, object
, start
);
6933 help
= Fget_char_property (make_number (pos
),
6934 Qhelp_echo
, w
->buffer
);
6943 else if (BUFFERP (object
)
6946 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
6952 help_echo_window
= window
;
6953 help_echo_object
= object
;
6954 help_echo_pos
= charpos
;
6961 current_buffer
= obuf
;
6965 /* TODO: mouse cursor changes. */
6970 redo_mouse_highlight ()
6972 if (!NILP (last_mouse_motion_frame
)
6973 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6974 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6975 LOWORD (last_mouse_motion_event
.lParam
),
6976 HIWORD (last_mouse_motion_event
.lParam
));
6981 /***********************************************************************
6983 ***********************************************************************/
6985 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6986 struct glyph
**, int *, int *, int *));
6988 /* Tool-bar item index of the item on which a mouse button was pressed
6991 static int last_tool_bar_item
;
6994 /* Get information about the tool-bar item at position X/Y on frame F.
6995 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6996 the current matrix of the tool-bar window of F, or NULL if not
6997 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6998 item in F->tool_bar_items. Value is
7000 -1 if X/Y is not on a tool-bar item
7001 0 if X/Y is on the same item that was highlighted before.
7005 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7008 struct glyph
**glyph
;
7009 int *hpos
, *vpos
, *prop_idx
;
7011 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7012 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7015 /* Find the glyph under X/Y. */
7016 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7020 /* Get the start of this tool-bar item's properties in
7021 f->tool_bar_items. */
7022 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7025 /* Is mouse on the highlighted item? */
7026 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7027 && *vpos
>= dpyinfo
->mouse_face_beg_row
7028 && *vpos
<= dpyinfo
->mouse_face_end_row
7029 && (*vpos
> dpyinfo
->mouse_face_beg_row
7030 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7031 && (*vpos
< dpyinfo
->mouse_face_end_row
7032 || *hpos
< dpyinfo
->mouse_face_end_col
7033 || dpyinfo
->mouse_face_past_end
))
7040 /* Handle mouse button event on the tool-bar of frame F, at
7041 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7045 w32_handle_tool_bar_click (f
, button_event
)
7047 struct input_event
*button_event
;
7049 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7050 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7051 int hpos
, vpos
, prop_idx
;
7052 struct glyph
*glyph
;
7053 Lisp_Object enabled_p
;
7054 int x
= XFASTINT (button_event
->x
);
7055 int y
= XFASTINT (button_event
->y
);
7057 /* If not on the highlighted tool-bar item, return. */
7058 frame_to_window_pixel_xy (w
, &x
, &y
);
7059 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7062 /* If item is disabled, do nothing. */
7063 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7064 if (NILP (enabled_p
))
7067 if (button_event
->kind
== mouse_click
)
7069 /* Show item in pressed state. */
7070 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7071 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7072 last_tool_bar_item
= prop_idx
;
7076 Lisp_Object key
, frame
;
7077 struct input_event event
;
7079 /* Show item in released state. */
7080 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7081 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7083 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7085 XSETFRAME (frame
, f
);
7086 event
.kind
= TOOL_BAR_EVENT
;
7087 event
.frame_or_window
= frame
;
7089 kbd_buffer_store_event (&event
);
7091 event
.kind
= TOOL_BAR_EVENT
;
7092 event
.frame_or_window
= frame
;
7094 event
.modifiers
= button_event
->modifiers
;
7095 kbd_buffer_store_event (&event
);
7096 last_tool_bar_item
= -1;
7101 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7102 tool-bar window-relative coordinates X/Y. Called from
7103 note_mouse_highlight. */
7106 note_tool_bar_highlight (f
, x
, y
)
7110 Lisp_Object window
= f
->tool_bar_window
;
7111 struct window
*w
= XWINDOW (window
);
7112 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7114 struct glyph
*glyph
;
7115 struct glyph_row
*row
;
7117 Lisp_Object enabled_p
;
7119 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7120 int mouse_down_p
, rc
;
7122 /* Function note_mouse_highlight is called with negative x(y
7123 values when mouse moves outside of the frame. */
7124 if (x
<= 0 || y
<= 0)
7126 clear_mouse_face (dpyinfo
);
7130 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7133 /* Not on tool-bar item. */
7134 clear_mouse_face (dpyinfo
);
7138 /* On same tool-bar item as before. */
7141 clear_mouse_face (dpyinfo
);
7143 /* Mouse is down, but on different tool-bar item? */
7144 mouse_down_p
= (dpyinfo
->grabbed
7145 && f
== last_mouse_frame
7146 && FRAME_LIVE_P (f
));
7148 && last_tool_bar_item
!= prop_idx
)
7151 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7152 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7154 /* If tool-bar item is not enabled, don't highlight it. */
7155 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7156 if (!NILP (enabled_p
))
7158 /* Compute the x-position of the glyph. In front and past the
7159 image is a space. We include this is the highlighted area. */
7160 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7161 for (i
= x
= 0; i
< hpos
; ++i
)
7162 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7164 /* Record this as the current active region. */
7165 dpyinfo
->mouse_face_beg_col
= hpos
;
7166 dpyinfo
->mouse_face_beg_row
= vpos
;
7167 dpyinfo
->mouse_face_beg_x
= x
;
7168 dpyinfo
->mouse_face_beg_y
= row
->y
;
7169 dpyinfo
->mouse_face_past_end
= 0;
7171 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7172 dpyinfo
->mouse_face_end_row
= vpos
;
7173 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7174 dpyinfo
->mouse_face_end_y
= row
->y
;
7175 dpyinfo
->mouse_face_window
= window
;
7176 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7178 /* Display it as active. */
7179 show_mouse_face (dpyinfo
, draw
);
7180 dpyinfo
->mouse_face_image_state
= draw
;
7185 /* Set help_echo to a help string.to display for this tool-bar item.
7186 w32_read_socket does the rest. */
7187 help_echo_object
= help_echo_window
= Qnil
;
7189 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7190 if (NILP (help_echo
))
7191 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7196 /* Find the glyph matrix position of buffer position CHARPOS in window
7197 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7198 current glyphs must be up to date. If CHARPOS is above window
7199 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7200 of last line in W. In the row containing CHARPOS, stop before glyphs
7201 having STOP as object. */
7203 #if 0 /* This is a version of fast_find_position that's more correct
7204 in the presence of hscrolling, for example. I didn't install
7205 it right away because the problem fixed is minor, it failed
7206 in 20.x as well, and I think it's too risky to install
7207 so near the release of 21.1. 2001-09-25 gerd. */
7210 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7213 int *hpos
, *vpos
, *x
, *y
;
7216 struct glyph_row
*row
, *first
;
7217 struct glyph
*glyph
, *end
;
7218 int i
, past_end
= 0;
7220 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7221 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7224 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7226 *x
= *y
= *hpos
= *vpos
= 0;
7231 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7238 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7240 glyph
= row
->glyphs
[TEXT_AREA
];
7241 end
= glyph
+ row
->used
[TEXT_AREA
];
7243 /* Skip over glyphs not having an object at the start of the row.
7244 These are special glyphs like truncation marks on terminal
7246 if (row
->displays_text_p
)
7248 && INTEGERP (glyph
->object
)
7249 && !EQ (stop
, glyph
->object
)
7250 && glyph
->charpos
< 0)
7252 *x
+= glyph
->pixel_width
;
7257 && !INTEGERP (glyph
->object
)
7258 && !EQ (stop
, glyph
->object
)
7259 && (!BUFFERP (glyph
->object
)
7260 || glyph
->charpos
< charpos
))
7262 *x
+= glyph
->pixel_width
;
7266 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7273 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7276 int *hpos
, *vpos
, *x
, *y
;
7281 int maybe_next_line_p
= 0;
7282 int line_start_position
;
7283 int yb
= window_text_bottom_y (w
);
7284 struct glyph_row
*row
, *best_row
;
7285 int row_vpos
, best_row_vpos
;
7288 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7289 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7293 if (row
->used
[TEXT_AREA
])
7294 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7296 line_start_position
= 0;
7298 if (line_start_position
> pos
)
7300 /* If the position sought is the end of the buffer,
7301 don't include the blank lines at the bottom of the window. */
7302 else if (line_start_position
== pos
7303 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7305 maybe_next_line_p
= 1;
7308 else if (line_start_position
> 0)
7311 best_row_vpos
= row_vpos
;
7314 if (row
->y
+ row
->height
>= yb
)
7321 /* Find the right column within BEST_ROW. */
7323 current_x
= best_row
->x
;
7324 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7326 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7327 int charpos
= glyph
->charpos
;
7329 if (BUFFERP (glyph
->object
))
7334 *vpos
= best_row_vpos
;
7339 else if (charpos
> pos
)
7342 else if (EQ (glyph
->object
, stop
))
7347 current_x
+= glyph
->pixel_width
;
7350 /* If we're looking for the end of the buffer,
7351 and we didn't find it in the line we scanned,
7352 use the start of the following line. */
7353 if (maybe_next_line_p
)
7358 current_x
= best_row
->x
;
7361 *vpos
= best_row_vpos
;
7362 *hpos
= lastcol
+ 1;
7371 /* Find the position of the glyph for position POS in OBJECT in
7372 window W's current matrix, and return in *X/*Y the pixel
7373 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7375 RIGHT_P non-zero means return the position of the right edge of the
7376 glyph, RIGHT_P zero means return the left edge position.
7378 If no glyph for POS exists in the matrix, return the position of
7379 the glyph with the next smaller position that is in the matrix, if
7380 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7381 exists in the matrix, return the position of the glyph with the
7382 next larger position in OBJECT.
7384 Value is non-zero if a glyph was found. */
7387 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7391 int *hpos
, *vpos
, *x
, *y
;
7394 int yb
= window_text_bottom_y (w
);
7395 struct glyph_row
*r
;
7396 struct glyph
*best_glyph
= NULL
;
7397 struct glyph_row
*best_row
= NULL
;
7400 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7401 r
->enabled_p
&& r
->y
< yb
;
7404 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7405 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7408 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7409 if (EQ (g
->object
, object
))
7411 if (g
->charpos
== pos
)
7418 else if (best_glyph
== NULL
7419 || ((abs (g
->charpos
- pos
)
7420 < abs (best_glyph
->charpos
- pos
))
7423 : g
->charpos
> pos
)))
7437 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7441 *x
+= best_glyph
->pixel_width
;
7446 *vpos
= best_row
- w
->current_matrix
->rows
;
7449 return best_glyph
!= NULL
;
7453 /* Display the active region described by mouse_face_*
7454 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7457 show_mouse_face (dpyinfo
, draw
)
7458 struct w32_display_info
*dpyinfo
;
7459 enum draw_glyphs_face draw
;
7461 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7462 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7464 if (/* If window is in the process of being destroyed, don't bother
7466 w
->current_matrix
!= NULL
7467 /* Don't update mouse highlight if hidden */
7468 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
7469 /* Recognize when we are called to operate on rows that don't exist
7470 anymore. This can happen when a window is split. */
7471 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7473 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7474 struct glyph_row
*row
, *first
, *last
;
7476 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7477 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7479 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7481 int start_hpos
, end_hpos
, start_x
;
7483 /* For all but the first row, the highlight starts at column 0. */
7486 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7487 start_x
= dpyinfo
->mouse_face_beg_x
;
7496 end_hpos
= dpyinfo
->mouse_face_end_col
;
7498 end_hpos
= row
->used
[TEXT_AREA
];
7500 if (end_hpos
> start_hpos
)
7502 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7503 start_hpos
, end_hpos
, draw
, 0);
7506 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
7510 /* When we've written over the cursor, arrange for it to
7511 be displayed again. */
7512 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
7513 x_display_cursor (w
, 1,
7514 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
7515 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
7518 #if 0 /* TODO: mouse cursor */
7519 /* Change the mouse cursor. */
7520 if (draw
== DRAW_NORMAL_TEXT
)
7521 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7522 f
->output_data
.x
->text_cursor
);
7523 else if (draw
== DRAW_MOUSE_FACE
)
7524 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7525 f
->output_data
.x
->cross_cursor
);
7527 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7528 f
->output_data
.x
->nontext_cursor
);
7532 /* Clear out the mouse-highlighted active region.
7533 Redraw it un-highlighted first. */
7536 clear_mouse_face (dpyinfo
)
7537 struct w32_display_info
*dpyinfo
;
7541 if (! NILP (dpyinfo
->mouse_face_window
))
7543 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7547 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7548 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7549 dpyinfo
->mouse_face_window
= Qnil
;
7550 dpyinfo
->mouse_face_overlay
= Qnil
;
7555 /* Clear any mouse-face on window W. This function is part of the
7556 redisplay interface, and is called from try_window_id and similar
7557 functions to ensure the mouse-highlight is off. */
7560 x_clear_mouse_face (w
)
7563 struct w32_display_info
*dpyinfo
7564 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
7568 XSETWINDOW (window
, w
);
7569 if (EQ (window
, dpyinfo
->mouse_face_window
))
7570 clear_mouse_face (dpyinfo
);
7575 /* Just discard the mouse face information for frame F, if any.
7576 This is used when the size of F is changed. */
7579 cancel_mouse_face (f
)
7583 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7585 window
= dpyinfo
->mouse_face_window
;
7586 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7588 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7589 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7590 dpyinfo
->mouse_face_window
= Qnil
;
7594 static struct scroll_bar
*x_window_to_scroll_bar ();
7595 static void x_scroll_bar_report_motion ();
7596 static void x_check_fullscreen
P_ ((struct frame
*));
7597 static void x_check_fullscreen_move
P_ ((struct frame
*));
7598 static int glyph_rect
P_ ((struct frame
*f
, int, int, RECT
*));
7601 /* Try to determine frame pixel position and size of the glyph under
7602 frame pixel coordinates X/Y on frame F . Return the position and
7603 size in *RECT. Value is non-zero if we could compute these
7607 glyph_rect (f
, x
, y
, rect
)
7615 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7618 struct window
*w
= XWINDOW (window
);
7619 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7620 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7622 frame_to_window_pixel_xy (w
, &x
, &y
);
7624 for (; r
< end
&& r
->enabled_p
; ++r
)
7625 if (r
->y
<= y
&& r
->y
+ r
->height
> y
)
7627 /* Found the row at y. */
7628 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7629 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7632 rect
->top
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7633 rect
->bottom
= rect
->top
+ r
->height
;
7637 /* x is to the left of the first glyph in the row. */
7638 rect
->left
= XINT (w
->left
);
7639 rect
->right
= WINDOW_TO_FRAME_PIXEL_X (w
, r
->x
);
7643 for (gx
= r
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
7644 if (gx
<= x
&& gx
+ g
->pixel_width
> x
)
7646 /* x is on a glyph. */
7647 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7648 rect
->right
= rect
->left
+ g
->pixel_width
;
7652 /* x is to the right of the last glyph in the row. */
7653 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7654 rect
->right
= XINT (w
->left
) + XINT (w
->width
);
7659 /* The y is not on any row. */
7663 /* Record the position of the mouse in last_mouse_glyph. */
7665 remember_mouse_glyph (f1
, gx
, gy
)
7669 if (!glyph_rect (f1
, gx
, gy
, &last_mouse_glyph
))
7671 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7672 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7674 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7675 round down even for negative values. */
7681 /* This was the original code from XTmouse_position, but it seems
7682 to give the position of the glyph diagonally next to the one
7683 the mouse is over. */
7684 gx
= (gx
+ width
- 1) / width
* width
;
7685 gy
= (gy
+ height
- 1) / height
* height
;
7687 gx
= gx
/ width
* width
;
7688 gy
= gy
/ height
* height
;
7691 last_mouse_glyph
.left
= gx
;
7692 last_mouse_glyph
.top
= gy
;
7693 last_mouse_glyph
.right
= gx
+ width
;
7694 last_mouse_glyph
.bottom
= gy
+ height
;
7698 /* Return the current position of the mouse.
7699 *fp should be a frame which indicates which display to ask about.
7701 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7702 and *part to the frame, window, and scroll bar part that the mouse
7703 is over. Set *x and *y to the portion and whole of the mouse's
7704 position on the scroll bar.
7706 If the mouse movement started elsewhere, set *fp to the frame the
7707 mouse is on, *bar_window to nil, and *x and *y to the character cell
7710 Set *time to the server time-stamp for the time at which the mouse
7711 was at this position.
7713 Don't store anything if we don't have a valid set of values to report.
7715 This clears the mouse_moved flag, so we can wait for the next mouse
7719 w32_mouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7722 Lisp_Object
*bar_window
;
7723 enum scroll_bar_part
*part
;
7725 unsigned long *time
;
7731 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7732 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7737 Lisp_Object frame
, tail
;
7739 /* Clear the mouse-moved flag for every frame on this display. */
7740 FOR_EACH_FRAME (tail
, frame
)
7741 XFRAME (frame
)->mouse_moved
= 0;
7743 last_mouse_scroll_bar
= Qnil
;
7747 /* Now we have a position on the root; find the innermost window
7748 containing the pointer. */
7750 if (FRAME_W32_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7751 && FRAME_LIVE_P (last_mouse_frame
))
7753 /* If mouse was grabbed on a frame, give coords for that frame
7754 even if the mouse is now outside it. */
7755 f1
= last_mouse_frame
;
7759 /* Is window under mouse one of our frames? */
7760 f1
= x_any_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp
),
7761 WindowFromPoint (pt
));
7764 /* If not, is it one of our scroll bars? */
7767 struct scroll_bar
*bar
7768 = x_window_to_scroll_bar (WindowFromPoint (pt
));
7772 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7776 if (f1
== 0 && insist
> 0)
7777 f1
= SELECTED_FRAME ();
7781 /* Ok, we found a frame. Store all the values.
7782 last_mouse_glyph is a rectangle used to reduce the
7783 generation of mouse events. To not miss any motion
7784 events, we must divide the frame into rectangles of the
7785 size of the smallest character that could be displayed
7786 on it, i.e. into the same rectangles that matrices on
7787 the frame are divided into. */
7789 #if OLD_REDISPLAY_CODE
7790 int ignore1
, ignore2
;
7792 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7794 pixel_to_glyph_coords (f1
, pt
.x
, pt
.y
, &ignore1
, &ignore2
,
7796 FRAME_W32_DISPLAY_INFO (f1
)->grabbed
7799 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7800 remember_mouse_glyph (f1
, pt
.x
, pt
.y
);
7808 *time
= last_mouse_movement_time
;
7817 /* Scroll bar support. */
7819 /* Given a window ID, find the struct scroll_bar which manages it.
7820 This can be called in GC, so we have to make sure to strip off mark
7823 static struct scroll_bar
*
7824 x_window_to_scroll_bar (window_id
)
7829 for (tail
= Vframe_list
;
7830 XGCTYPE (tail
) == Lisp_Cons
;
7833 Lisp_Object frame
, bar
, condemned
;
7835 frame
= XCAR (tail
);
7836 /* All elements of Vframe_list should be frames. */
7837 if (! GC_FRAMEP (frame
))
7840 /* Scan this frame's scroll bar list for a scroll bar with the
7842 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7843 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7844 /* This trick allows us to search both the ordinary and
7845 condemned scroll bar lists with one loop. */
7846 ! GC_NILP (bar
) || (bar
= condemned
,
7849 bar
= XSCROLL_BAR (bar
)->next
)
7850 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7851 return XSCROLL_BAR (bar
);
7859 /* Set the thumb size and position of scroll bar BAR. We are currently
7860 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7863 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
)
7864 struct scroll_bar
*bar
;
7865 int portion
, position
, whole
;
7867 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7868 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7869 int sb_page
, sb_pos
;
7870 BOOL draggingp
= !NILP (bar
->dragging
) ? TRUE
: FALSE
;
7874 /* Position scroll bar at rock bottom if the bottom of the
7875 buffer is visible. This avoids shinking the thumb away
7876 to nothing if it is held at the bottom of the buffer. */
7877 if (position
+ portion
>= whole
)
7879 sb_page
= range
* (whole
- position
) / whole
7880 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7884 sb_page
= portion
* range
/ whole
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7885 sb_pos
= position
* range
/ whole
;
7895 if (pfnSetScrollInfo
)
7899 si
.cbSize
= sizeof (si
);
7900 /* Only update page size if currently dragging, to reduce
7903 si
.fMask
= SIF_PAGE
;
7905 si
.fMask
= SIF_PAGE
| SIF_POS
;
7909 pfnSetScrollInfo (w
, SB_CTL
, &si
, !draggingp
);
7912 SetScrollPos (w
, SB_CTL
, sb_pos
, !draggingp
);
7918 /************************************************************************
7919 Scroll bars, general
7920 ************************************************************************/
7923 my_create_scrollbar (f
, bar
)
7925 struct scroll_bar
* bar
;
7927 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
7928 WM_EMACS_CREATESCROLLBAR
, (WPARAM
) f
,
7932 /*#define ATTACH_THREADS*/
7935 my_show_window (FRAME_PTR f
, HWND hwnd
, int how
)
7937 #ifndef ATTACH_THREADS
7938 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
7939 (WPARAM
) hwnd
, (LPARAM
) how
);
7941 return ShowWindow (hwnd
, how
);
7946 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
7947 int x
, int y
, int cx
, int cy
, UINT flags
)
7949 #ifndef ATTACH_THREADS
7951 pos
.hwndInsertAfter
= hwndAfter
;
7957 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
7959 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
7964 my_set_focus (f
, hwnd
)
7968 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
7973 my_set_foreground_window (hwnd
)
7976 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
7980 my_destroy_window (f
, hwnd
)
7984 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
7988 /* Create a scroll bar and return the scroll bar vector for it. W is
7989 the Emacs window on which to create the scroll bar. TOP, LEFT,
7990 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7993 static struct scroll_bar
*
7994 x_scroll_bar_create (w
, top
, left
, width
, height
)
7996 int top
, left
, width
, height
;
7998 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8000 struct scroll_bar
*bar
8001 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8005 XSETWINDOW (bar
->window
, w
);
8006 XSETINT (bar
->top
, top
);
8007 XSETINT (bar
->left
, left
);
8008 XSETINT (bar
->width
, width
);
8009 XSETINT (bar
->height
, height
);
8010 XSETINT (bar
->start
, 0);
8011 XSETINT (bar
->end
, 0);
8012 bar
->dragging
= Qnil
;
8014 /* Requires geometry to be set before call to create the real window */
8016 hwnd
= my_create_scrollbar (f
, bar
);
8018 if (pfnSetScrollInfo
)
8022 si
.cbSize
= sizeof (si
);
8025 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
8026 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8030 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
8034 SetScrollRange (hwnd
, SB_CTL
, 0,
8035 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
8036 SetScrollPos (hwnd
, SB_CTL
, 0, FALSE
);
8039 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
8041 /* Add bar to its frame's list of scroll bars. */
8042 bar
->next
= FRAME_SCROLL_BARS (f
);
8044 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8045 if (! NILP (bar
->next
))
8046 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8054 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8058 x_scroll_bar_remove (bar
)
8059 struct scroll_bar
*bar
;
8061 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8065 /* Destroy the window. */
8066 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
8068 /* Disassociate this scroll bar from its window. */
8069 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8074 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8075 that we are displaying PORTION characters out of a total of WHOLE
8076 characters, starting at POSITION. If WINDOW has no scroll bar,
8079 w32_set_vertical_scroll_bar (w
, portion
, whole
, position
)
8081 int portion
, whole
, position
;
8083 struct frame
*f
= XFRAME (w
->frame
);
8084 struct scroll_bar
*bar
;
8085 int top
, height
, left
, sb_left
, width
, sb_width
;
8086 int window_x
, window_y
, window_width
, window_height
;
8088 /* Get window dimensions. */
8089 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8091 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8092 height
= window_height
;
8094 /* Compute the left edge of the scroll bar area. */
8095 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8096 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8098 left
= XFASTINT (w
->left
);
8099 left
*= CANON_X_UNIT (f
);
8100 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8102 /* Compute the width of the scroll bar which might be less than
8103 the width of the area reserved for the scroll bar. */
8104 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8105 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8109 /* Compute the left edge of the scroll bar. */
8110 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8111 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8113 sb_left
= left
+ (width
- sb_width
) / 2;
8115 /* Does the scroll bar exist yet? */
8116 if (NILP (w
->vertical_scroll_bar
))
8120 if (width
> 0 && height
> 0)
8122 hdc
= get_frame_dc (f
);
8123 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
8124 release_frame_dc (f
, hdc
);
8128 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8132 /* It may just need to be moved and resized. */
8135 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8136 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
8138 /* If already correctly positioned, do nothing. */
8139 if ( XINT (bar
->left
) == sb_left
8140 && XINT (bar
->top
) == top
8141 && XINT (bar
->width
) == sb_width
8142 && XINT (bar
->height
) == height
)
8144 /* Redraw after clear_frame. */
8145 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
8146 InvalidateRect (hwnd
, NULL
, FALSE
);
8152 if (width
&& height
)
8154 hdc
= get_frame_dc (f
);
8155 /* Since Windows scroll bars are smaller than the space reserved
8156 for them on the frame, we have to clear "under" them. */
8157 w32_clear_area (f
, hdc
,
8162 release_frame_dc (f
, hdc
);
8164 /* Make sure scroll bar is "visible" before moving, to ensure the
8165 area of the parent window now exposed will be refreshed. */
8166 my_show_window (f
, hwnd
, SW_HIDE
);
8167 MoveWindow (hwnd
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8168 top
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8169 max (height
, 1), TRUE
);
8170 if (pfnSetScrollInfo
)
8174 si
.cbSize
= sizeof (si
);
8175 si
.fMask
= SIF_RANGE
;
8177 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
8178 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8180 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
8183 SetScrollRange (hwnd
, SB_CTL
, 0,
8184 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
8185 my_show_window (f
, hwnd
, SW_NORMAL
);
8186 /* InvalidateRect (w, NULL, FALSE); */
8188 /* Remember new settings. */
8189 XSETINT (bar
->left
, sb_left
);
8190 XSETINT (bar
->top
, top
);
8191 XSETINT (bar
->width
, sb_width
);
8192 XSETINT (bar
->height
, height
);
8197 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
8199 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8203 /* The following three hooks are used when we're doing a thorough
8204 redisplay of the frame. We don't explicitly know which scroll bars
8205 are going to be deleted, because keeping track of when windows go
8206 away is a real pain - "Can you say set-window-configuration, boys
8207 and girls?" Instead, we just assert at the beginning of redisplay
8208 that *all* scroll bars are to be removed, and then save a scroll bar
8209 from the fiery pit when we actually redisplay its window. */
8211 /* Arrange for all scroll bars on FRAME to be removed at the next call
8212 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8213 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8216 w32_condemn_scroll_bars (frame
)
8219 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8220 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8223 bar
= FRAME_SCROLL_BARS (frame
);
8224 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8225 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8226 XSCROLL_BAR (bar
)->prev
= Qnil
;
8227 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8228 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8229 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8234 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8235 Note that WINDOW isn't necessarily condemned at all. */
8238 w32_redeem_scroll_bar (window
)
8239 struct window
*window
;
8241 struct scroll_bar
*bar
;
8244 /* We can't redeem this window's scroll bar if it doesn't have one. */
8245 if (NILP (window
->vertical_scroll_bar
))
8248 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8250 /* Unlink it from the condemned list. */
8251 f
= XFRAME (WINDOW_FRAME (window
));
8252 if (NILP (bar
->prev
))
8254 /* If the prev pointer is nil, it must be the first in one of
8256 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8257 /* It's not condemned. Everything's fine. */
8259 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8260 window
->vertical_scroll_bar
))
8261 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8263 /* If its prev pointer is nil, it must be at the front of
8264 one or the other! */
8268 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8270 if (! NILP (bar
->next
))
8271 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8273 bar
->next
= FRAME_SCROLL_BARS (f
);
8275 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8276 if (! NILP (bar
->next
))
8277 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8280 /* Remove all scroll bars on FRAME that haven't been saved since the
8281 last call to `*condemn_scroll_bars_hook'. */
8284 w32_judge_scroll_bars (f
)
8287 Lisp_Object bar
, next
;
8289 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8291 /* Clear out the condemned list now so we won't try to process any
8292 more events on the hapless scroll bars. */
8293 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8295 for (; ! NILP (bar
); bar
= next
)
8297 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8299 x_scroll_bar_remove (b
);
8302 b
->next
= b
->prev
= Qnil
;
8305 /* Now there should be no references to the condemned scroll bars,
8306 and they should get garbage-collected. */
8309 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8310 is set to something other than no_event, it is enqueued.
8312 This may be called from a signal handler, so we have to ignore GC
8316 w32_scroll_bar_handle_click (bar
, msg
, emacs_event
)
8317 struct scroll_bar
*bar
;
8319 struct input_event
*emacs_event
;
8321 if (! GC_WINDOWP (bar
->window
))
8324 emacs_event
->kind
= w32_scroll_bar_click
;
8325 emacs_event
->code
= 0;
8326 /* not really meaningful to distinguish up/down */
8327 emacs_event
->modifiers
= msg
->dwModifiers
;
8328 emacs_event
->frame_or_window
= bar
->window
;
8329 emacs_event
->arg
= Qnil
;
8330 emacs_event
->timestamp
= msg
->msg
.time
;
8333 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8335 int dragging
= !NILP (bar
->dragging
);
8337 if (pfnGetScrollInfo
)
8341 si
.cbSize
= sizeof (si
);
8344 pfnGetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
8348 y
= GetScrollPos ((HWND
) msg
->msg
.lParam
, SB_CTL
);
8350 bar
->dragging
= Qnil
;
8353 last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
8355 switch (LOWORD (msg
->msg
.wParam
))
8358 emacs_event
->part
= scroll_bar_down_arrow
;
8361 emacs_event
->part
= scroll_bar_up_arrow
;
8364 emacs_event
->part
= scroll_bar_above_handle
;
8367 emacs_event
->part
= scroll_bar_below_handle
;
8370 emacs_event
->part
= scroll_bar_handle
;
8374 emacs_event
->part
= scroll_bar_handle
;
8378 case SB_THUMBPOSITION
:
8379 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
8380 y
= HIWORD (msg
->msg
.wParam
);
8382 emacs_event
->part
= scroll_bar_handle
;
8384 /* "Silently" update current position. */
8385 if (pfnSetScrollInfo
)
8389 si
.cbSize
= sizeof (si
);
8392 /* Remember apparent position (we actually lag behind the real
8393 position, so don't set that directly. */
8394 last_scroll_bar_drag_pos
= y
;
8396 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
8399 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, FALSE
);
8402 /* If this is the end of a drag sequence, then reset the scroll
8403 handle size to normal and do a final redraw. Otherwise do
8407 if (pfnSetScrollInfo
)
8410 int start
= XINT (bar
->start
);
8411 int end
= XINT (bar
->end
);
8413 si
.cbSize
= sizeof (si
);
8414 si
.fMask
= SIF_PAGE
| SIF_POS
;
8415 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8416 si
.nPos
= last_scroll_bar_drag_pos
;
8417 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
8420 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, TRUE
);
8424 emacs_event
->kind
= no_event
;
8428 XSETINT (emacs_event
->x
, y
);
8429 XSETINT (emacs_event
->y
, top_range
);
8435 /* Return information to the user about the current position of the mouse
8436 on the scroll bar. */
8439 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8441 Lisp_Object
*bar_window
;
8442 enum scroll_bar_part
*part
;
8444 unsigned long *time
;
8446 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8447 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
8448 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8450 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8455 *bar_window
= bar
->window
;
8457 if (pfnGetScrollInfo
)
8461 si
.cbSize
= sizeof (si
);
8462 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
8464 pfnGetScrollInfo (w
, SB_CTL
, &si
);
8466 top_range
= si
.nMax
- si
.nPage
+ 1;
8469 pos
= GetScrollPos (w
, SB_CTL
);
8471 switch (LOWORD (last_mouse_scroll_bar_pos
))
8473 case SB_THUMBPOSITION
:
8475 *part
= scroll_bar_handle
;
8476 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
8477 pos
= HIWORD (last_mouse_scroll_bar_pos
);
8480 *part
= scroll_bar_handle
;
8484 *part
= scroll_bar_handle
;
8489 XSETINT (*y
, top_range
);
8492 last_mouse_scroll_bar
= Qnil
;
8494 *time
= last_mouse_movement_time
;
8500 /* The screen has been cleared so we may have changed foreground or
8501 background colors, and the scroll bars may need to be redrawn.
8502 Clear out the scroll bars, and ask for expose events, so we can
8506 x_scroll_bar_clear (f
)
8511 /* We can have scroll bars even if this is 0,
8512 if we just turned off scroll bar mode.
8513 But in that case we should not clear them. */
8514 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8515 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8516 bar
= XSCROLL_BAR (bar
)->next
)
8518 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
8519 HDC hdc
= GetDC (window
);
8522 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
8523 arranges to refresh the scroll bar if hidden. */
8524 my_show_window (f
, window
, SW_HIDE
);
8526 GetClientRect (window
, &rect
);
8527 select_palette (f
, hdc
);
8528 w32_clear_rect (f
, hdc
, &rect
);
8529 deselect_palette (f
, hdc
);
8531 ReleaseDC (window
, hdc
);
8536 /* The main W32 event-reading loop - w32_read_socket. */
8538 /* Record the last 100 characters stored
8539 to help debug the loss-of-chars-during-GC problem. */
8541 static int temp_index
;
8542 static short temp_buffer
[100];
8545 /* Read events coming from the W32 shell.
8546 This routine is called by the SIGIO handler.
8547 We return as soon as there are no more events to be read.
8549 Events representing keys are stored in buffer BUFP,
8550 which can hold up to NUMCHARS characters.
8551 We return the number of characters stored into the buffer,
8552 thus pretending to be `read'.
8554 EXPECTED is nonzero if the caller knows input is available.
8556 Some of these messages are reposted back to the message queue since the
8557 system calls the windows proc directly in a context where we cannot return
8558 the data nor can we guarantee the state we are in. So if we dispatch them
8559 we will get into an infinite loop. To prevent this from ever happening we
8560 will set a variable to indicate we are in the read_socket call and indicate
8561 which message we are processing since the windows proc gets called
8562 recursively with different messages by the system.
8566 w32_read_socket (sd
, bufp
, numchars
, expected
)
8568 /* register */ struct input_event
*bufp
;
8569 /* register */ int numchars
;
8573 int check_visibility
= 0;
8576 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
8578 if (interrupt_input_blocked
)
8580 interrupt_input_pending
= 1;
8584 interrupt_input_pending
= 0;
8587 /* So people can tell when we have read the available input. */
8588 input_signal_count
++;
8591 abort (); /* Don't think this happens. */
8593 /* TODO: tool-bars, ghostscript integration, mouse
8595 while (get_next_msg (&msg
, FALSE
))
8597 switch (msg
.msg
.message
)
8600 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8604 if (msg
.rect
.right
== msg
.rect
.left
||
8605 msg
.rect
.bottom
== msg
.rect
.top
)
8607 /* We may get paint messages even though the client
8608 area is clipped - these are not expose events. */
8609 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
8610 XSTRING (f
->name
)->data
));
8612 else if (f
->async_visible
!= 1)
8614 /* Definitely not obscured, so mark as visible. */
8615 f
->async_visible
= 1;
8616 f
->async_iconified
= 0;
8617 SET_FRAME_GARBAGED (f
);
8618 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
8619 XSTRING (f
->name
)->data
));
8621 /* WM_PAINT serves as MapNotify as well, so report
8622 visibility changes properly. */
8625 bufp
->kind
= deiconify_event
;
8626 XSETFRAME (bufp
->frame_or_window
, f
);
8632 else if (! NILP (Vframe_list
)
8633 && ! NILP (XCDR (Vframe_list
)))
8634 /* Force a redisplay sooner or later to update the
8635 frame titles in case this is the second frame. */
8636 record_asynch_buffer_change ();
8640 HDC hdc
= get_frame_dc (f
);
8642 /* Erase background again for safety. */
8643 w32_clear_rect (f
, hdc
, &msg
.rect
);
8644 release_frame_dc (f
, hdc
);
8648 msg
.rect
.right
- msg
.rect
.left
,
8649 msg
.rect
.bottom
- msg
.rect
.top
);
8654 case WM_INPUTLANGCHANGE
:
8655 /* Generate a language change event. */
8656 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8663 bufp
->kind
= language_change_event
;
8664 XSETFRAME (bufp
->frame_or_window
, f
);
8666 bufp
->code
= msg
.msg
.wParam
;
8667 bufp
->modifiers
= msg
.msg
.lParam
& 0xffff;
8676 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8678 if (f
&& !f
->iconified
)
8680 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
8682 dpyinfo
->mouse_face_hidden
= 1;
8683 clear_mouse_face (dpyinfo
);
8686 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8688 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8689 bufp
->kind
= non_ascii_keystroke
;
8690 bufp
->code
= msg
.msg
.wParam
;
8691 bufp
->modifiers
= msg
.dwModifiers
;
8692 XSETFRAME (bufp
->frame_or_window
, f
);
8694 bufp
->timestamp
= msg
.msg
.time
;
8703 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8705 if (f
&& !f
->iconified
)
8707 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
8709 dpyinfo
->mouse_face_hidden
= 1;
8710 clear_mouse_face (dpyinfo
);
8713 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8715 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8716 bufp
->kind
= ascii_keystroke
;
8717 bufp
->code
= msg
.msg
.wParam
;
8718 bufp
->modifiers
= msg
.dwModifiers
;
8719 XSETFRAME (bufp
->frame_or_window
, f
);
8721 bufp
->timestamp
= msg
.msg
.time
;
8729 previous_help_echo
= help_echo
;
8730 help_echo_object
= help_echo_window
= Qnil
;
8733 if (dpyinfo
->grabbed
&& last_mouse_frame
8734 && FRAME_LIVE_P (last_mouse_frame
))
8735 f
= last_mouse_frame
;
8737 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8739 if (dpyinfo
->mouse_face_hidden
)
8741 dpyinfo
->mouse_face_hidden
= 0;
8742 clear_mouse_face (dpyinfo
);
8746 note_mouse_movement (f
, &msg
.msg
);
8749 /* If we move outside the frame, then we're
8750 certainly no longer on any text in the frame. */
8751 clear_mouse_face (dpyinfo
);
8754 /* If the contents of the global variable help_echo
8755 has changed, generate a HELP_EVENT. */
8756 if (help_echo
!= previous_help_echo
)
8762 XSETFRAME (frame
, f
);
8766 any_help_event_p
= 1;
8767 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
8768 help_echo_window
, help_echo_object
,
8770 bufp
+= n
, count
+= n
, numchars
-= n
;
8774 case WM_LBUTTONDOWN
:
8776 case WM_MBUTTONDOWN
:
8778 case WM_RBUTTONDOWN
:
8780 case WM_XBUTTONDOWN
:
8783 /* If we decide we want to generate an event to be seen
8784 by the rest of Emacs, we put it here. */
8785 struct input_event emacs_event
;
8790 emacs_event
.kind
= no_event
;
8792 if (dpyinfo
->grabbed
&& last_mouse_frame
8793 && FRAME_LIVE_P (last_mouse_frame
))
8794 f
= last_mouse_frame
;
8796 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8800 construct_mouse_click (&emacs_event
, &msg
, f
);
8802 /* Is this in the tool-bar? */
8803 if (WINDOWP (f
->tool_bar_window
)
8804 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
8810 window
= window_from_coordinates (f
,
8814 if (EQ (window
, f
->tool_bar_window
))
8816 w32_handle_tool_bar_click (f
, &emacs_event
);
8822 if (!dpyinfo
->w32_focus_frame
8823 || f
== dpyinfo
->w32_focus_frame
8826 construct_mouse_click (bufp
, &msg
, f
);
8833 parse_button (msg
.msg
.message
, HIWORD (msg
.msg
.wParam
),
8838 dpyinfo
->grabbed
&= ~ (1 << button
);
8842 dpyinfo
->grabbed
|= (1 << button
);
8843 last_mouse_frame
= f
;
8844 /* Ignore any mouse motion that happened
8845 before this event; any subsequent mouse-movement
8846 Emacs events should reflect only motion after
8852 last_tool_bar_item
= -1;
8858 if (dpyinfo
->grabbed
&& last_mouse_frame
8859 && FRAME_LIVE_P (last_mouse_frame
))
8860 f
= last_mouse_frame
;
8862 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8866 if ((!dpyinfo
->w32_focus_frame
8867 || f
== dpyinfo
->w32_focus_frame
)
8870 construct_mouse_wheel (bufp
, &msg
, f
);
8879 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8883 construct_drag_n_drop (bufp
, &msg
, f
);
8892 struct scroll_bar
*bar
=
8893 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
);
8895 if (bar
&& numchars
>= 1)
8897 if (w32_scroll_bar_handle_click (bar
, &msg
, bufp
))
8907 case WM_WINDOWPOSCHANGED
:
8908 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8911 x_check_fullscreen_move(f
);
8912 if (f
->output_data
.w32
->want_fullscreen
& FULLSCREEN_WAIT
)
8913 f
->output_data
.w32
->want_fullscreen
&=
8914 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
8916 check_visibility
= 1;
8920 case WM_ACTIVATEAPP
:
8921 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8923 x_check_fullscreen (f
);
8924 check_visibility
= 1;
8928 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8930 if (f
&& !f
->async_iconified
)
8934 x_real_positions (f
, &x
, &y
);
8935 f
->output_data
.w32
->left_pos
= x
;
8936 f
->output_data
.w32
->top_pos
= y
;
8939 check_visibility
= 1;
8943 /* wParam non-zero means Window is about to be shown, 0 means
8944 about to be hidden. */
8945 /* Redo the mouse-highlight after the tooltip has gone. */
8946 if (!msg
.msg
.wParam
&& msg
.msg
.hwnd
== tip_window
)
8949 redo_mouse_highlight ();
8952 /* If window has been obscured or exposed by another window
8953 being maximised or minimised/restored, then recheck
8954 visibility of all frames. Direct changes to our own
8955 windows get handled by WM_SIZE. */
8957 if (msg
.msg
.lParam
!= 0)
8958 check_visibility
= 1;
8961 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8962 f
->async_visible
= msg
.msg
.wParam
;
8966 check_visibility
= 1;
8970 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8972 /* Inform lisp of whether frame has been iconified etc. */
8975 switch (msg
.msg
.wParam
)
8977 case SIZE_MINIMIZED
:
8978 f
->async_visible
= 0;
8979 f
->async_iconified
= 1;
8981 bufp
->kind
= iconify_event
;
8982 XSETFRAME (bufp
->frame_or_window
, f
);
8989 case SIZE_MAXIMIZED
:
8991 f
->async_visible
= 1;
8992 f
->async_iconified
= 0;
8994 /* wait_reading_process_input will notice this and update
8995 the frame's display structures. */
8996 SET_FRAME_GARBAGED (f
);
9002 /* Reset top and left positions of the Window
9003 here since Windows sends a WM_MOVE message
9004 BEFORE telling us the Window is minimized
9005 when the Window is iconified, with 3000,3000
9007 x_real_positions (f
, &x
, &y
);
9008 f
->output_data
.w32
->left_pos
= x
;
9009 f
->output_data
.w32
->top_pos
= y
;
9011 bufp
->kind
= deiconify_event
;
9012 XSETFRAME (bufp
->frame_or_window
, f
);
9018 else if (! NILP (Vframe_list
)
9019 && ! NILP (XCDR (Vframe_list
)))
9020 /* Force a redisplay sooner or later
9021 to update the frame titles
9022 in case this is the second frame. */
9023 record_asynch_buffer_change ();
9028 if (f
&& !f
->async_iconified
&& msg
.msg
.wParam
!= SIZE_MINIMIZED
)
9036 GetClientRect (msg
.msg
.hwnd
, &rect
);
9038 height
= rect
.bottom
- rect
.top
;
9039 width
= rect
.right
- rect
.left
;
9041 rows
= PIXEL_TO_CHAR_HEIGHT (f
, height
);
9042 columns
= PIXEL_TO_CHAR_WIDTH (f
, width
);
9044 /* TODO: Clip size to the screen dimensions. */
9046 /* Even if the number of character rows and columns has
9047 not changed, the font size may have changed, so we need
9048 to check the pixel dimensions as well. */
9050 if (columns
!= f
->width
9051 || rows
!= f
->height
9052 || width
!= f
->output_data
.w32
->pixel_width
9053 || height
!= f
->output_data
.w32
->pixel_height
)
9055 change_frame_size (f
, rows
, columns
, 0, 1, 0);
9056 SET_FRAME_GARBAGED (f
);
9057 cancel_mouse_face (f
);
9058 f
->output_data
.w32
->pixel_width
= width
;
9059 f
->output_data
.w32
->pixel_height
= height
;
9060 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
9064 check_visibility
= 1;
9068 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9071 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9073 /* If we move outside the frame, then we're
9074 certainly no longer on any text in the frame. */
9075 clear_mouse_face (dpyinfo
);
9076 dpyinfo
->mouse_face_mouse_frame
= 0;
9079 /* Generate a nil HELP_EVENT to cancel a help-echo.
9080 Do it only if there's something to cancel.
9081 Otherwise, the startup message is cleared when
9082 the mouse leaves the frame. */
9083 if (any_help_event_p
)
9088 XSETFRAME (frame
, f
);
9090 n
= gen_help_event (bufp
, numchars
,
9091 Qnil
, frame
, Qnil
, Qnil
, 0);
9092 bufp
+= n
, count
+= n
, numchars
-= n
;
9098 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9100 dpyinfo
->w32_focus_event_frame
= f
;
9103 x_new_focus_frame (dpyinfo
, f
);
9106 dpyinfo
->grabbed
= 0;
9107 check_visibility
= 1;
9111 /* TODO: some of this belongs in MOUSE_LEAVE */
9112 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9116 if (f
== dpyinfo
->w32_focus_event_frame
)
9117 dpyinfo
->w32_focus_event_frame
= 0;
9119 if (f
== dpyinfo
->w32_focus_frame
)
9120 x_new_focus_frame (dpyinfo
, 0);
9122 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9124 /* If we move outside the frame, then we're
9125 certainly no longer on any text in the frame. */
9126 clear_mouse_face (dpyinfo
);
9127 dpyinfo
->mouse_face_mouse_frame
= 0;
9130 /* Generate a nil HELP_EVENT to cancel a help-echo.
9131 Do it only if there's something to cancel.
9132 Otherwise, the startup message is cleared when
9133 the mouse leaves the frame. */
9134 if (any_help_event_p
)
9139 XSETFRAME (frame
, f
);
9141 n
= gen_help_event (bufp
, numchars
,
9142 Qnil
, frame
, Qnil
, Qnil
, 0);
9143 bufp
+= n
, count
+= n
, numchars
-=n
;
9147 dpyinfo
->grabbed
= 0;
9148 check_visibility
= 1;
9152 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9159 bufp
->kind
= delete_window_event
;
9160 XSETFRAME (bufp
->frame_or_window
, f
);
9169 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9176 bufp
->kind
= menu_bar_activate_event
;
9177 XSETFRAME (bufp
->frame_or_window
, f
);
9186 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9190 extern void menubar_selection_callback
9191 (FRAME_PTR f
, void * client_data
);
9192 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
9195 check_visibility
= 1;
9198 case WM_DISPLAYCHANGE
:
9199 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9203 dpyinfo
->width
= (short) LOWORD (msg
.msg
.lParam
);
9204 dpyinfo
->height
= (short) HIWORD (msg
.msg
.lParam
);
9205 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
9206 DebPrint (("display change: %d %d\n", dpyinfo
->width
,
9210 check_visibility
= 1;
9214 /* Check for messages registered at runtime. */
9215 if (msg
.msg
.message
== msh_mousewheel
)
9217 if (dpyinfo
->grabbed
&& last_mouse_frame
9218 && FRAME_LIVE_P (last_mouse_frame
))
9219 f
= last_mouse_frame
;
9221 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9225 if ((!dpyinfo
->w32_focus_frame
9226 || f
== dpyinfo
->w32_focus_frame
)
9229 construct_mouse_wheel (bufp
, &msg
, f
);
9240 /* If the focus was just given to an autoraising frame,
9242 /* ??? This ought to be able to handle more than one such frame. */
9243 if (pending_autoraise_frame
)
9245 x_raise_frame (pending_autoraise_frame
);
9246 pending_autoraise_frame
= 0;
9249 /* Check which frames are still visisble, if we have enqueued any user
9250 events or been notified of events that may affect visibility. We
9251 do this here because there doesn't seem to be any direct
9252 notification from Windows that the visibility of a window has
9253 changed (at least, not in all cases). */
9254 if (count
> 0 || check_visibility
)
9256 Lisp_Object tail
, frame
;
9258 FOR_EACH_FRAME (tail
, frame
)
9260 FRAME_PTR f
= XFRAME (frame
);
9261 /* The tooltip has been drawn already. Avoid the
9262 SET_FRAME_GARBAGED below. */
9263 if (EQ (frame
, tip_frame
))
9266 /* Check "visible" frames and mark each as obscured or not.
9267 Note that async_visible is nonzero for unobscured and
9268 obscured frames, but zero for hidden and iconified frames. */
9269 if (FRAME_W32_P (f
) && f
->async_visible
)
9275 /* Query clipping rectangle for the entire window area
9276 (GetWindowDC), not just the client portion (GetDC).
9277 Otherwise, the scrollbars and menubar aren't counted as
9278 part of the visible area of the frame, and we may think
9279 the frame is obscured when really a scrollbar is still
9280 visible and gets WM_PAINT messages above. */
9281 hdc
= GetWindowDC (FRAME_W32_WINDOW (f
));
9282 GetClipBox (hdc
, &clipbox
);
9283 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
9286 if (clipbox
.right
== clipbox
.left
9287 || clipbox
.bottom
== clipbox
.top
)
9289 /* Frame has become completely obscured so mark as
9290 such (we do this by setting async_visible to 2 so
9291 that FRAME_VISIBLE_P is still true, but redisplay
9293 f
->async_visible
= 2;
9295 if (!FRAME_OBSCURED_P (f
))
9297 DebPrint (("frame %p (%s) obscured\n", f
,
9298 XSTRING (f
->name
)->data
));
9303 /* Frame is not obscured, so mark it as such. */
9304 f
->async_visible
= 1;
9306 if (FRAME_OBSCURED_P (f
))
9308 SET_FRAME_GARBAGED (f
);
9309 DebPrint (("obscured frame %p (%s) found to be visible\n", f
,
9310 XSTRING (f
->name
)->data
));
9312 /* Force a redisplay sooner or later. */
9313 record_asynch_buffer_change ();
9327 /***********************************************************************
9329 ***********************************************************************/
9331 /* Notice if the text cursor of window W has been overwritten by a
9332 drawing operation that outputs glyphs starting at START_X and
9333 ending at END_X in the line given by output_cursor.vpos.
9334 Coordinates are area-relative. END_X < 0 means all the rest
9335 of the line after START_X has been written. */
9338 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
9340 enum glyph_row_area area
;
9343 if (area
== TEXT_AREA
9344 && w
->phys_cursor_on_p
9345 && y0
<= w
->phys_cursor
.y
9346 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
9347 && x0
<= w
->phys_cursor
.x
9348 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
9349 w
->phys_cursor_on_p
= 0;
9353 /* Set clipping for output in glyph row ROW. W is the window in which
9354 we operate. GC is the graphics context to set clipping in.
9355 WHOLE_LINE_P non-zero means include the areas used for truncation
9356 mark display and alike in the clipping rectangle.
9358 ROW may be a text row or, e.g., a mode line. Text rows must be
9359 clipped to the interior of the window dedicated to text display,
9360 mode lines must be clipped to the whole window. */
9363 w32_clip_to_row (w
, row
, hdc
, whole_line_p
)
9365 struct glyph_row
*row
;
9369 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9371 int window_x
, window_y
, window_width
, window_height
;
9373 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9375 clip_rect
.left
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
9376 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
9377 clip_rect
.top
= max (clip_rect
.top
, window_y
);
9378 clip_rect
.right
= clip_rect
.left
+ window_width
;
9379 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
9381 /* If clipping to the whole line, including trunc marks, extend
9382 the rectangle to the left and increase its width. */
9385 clip_rect
.left
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
9386 clip_rect
.right
+= FRAME_X_FRINGE_WIDTH (f
);
9389 w32_set_clip_rectangle (hdc
, &clip_rect
);
9393 /* Draw a hollow box cursor on window W in glyph row ROW. */
9396 x_draw_hollow_cursor (w
, row
)
9398 struct glyph_row
*row
;
9400 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9404 struct glyph
*cursor_glyph
;
9405 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
9407 /* Compute frame-relative coordinates from window-relative
9409 rect
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9410 rect
.top
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9411 + row
->ascent
- w
->phys_cursor_ascent
);
9412 rect
.bottom
= rect
.top
+ row
->height
- 1;
9414 /* Get the glyph the cursor is on. If we can't tell because
9415 the current matrix is invalid or such, give up. */
9416 cursor_glyph
= get_phys_cursor_glyph (w
);
9417 if (cursor_glyph
== NULL
)
9420 /* Compute the width of the rectangle to draw. If on a stretch
9421 glyph, and `x-stretch-block-cursor' is nil, don't draw a
9422 rectangle as wide as the glyph, but use a canonical character
9424 wd
= cursor_glyph
->pixel_width
- 1;
9425 if (cursor_glyph
->type
== STRETCH_GLYPH
9426 && !x_stretch_cursor_p
)
9427 wd
= min (CANON_X_UNIT (f
), wd
);
9429 rect
.right
= rect
.left
+ wd
;
9430 hdc
= get_frame_dc (f
);
9431 FrameRect (hdc
, &rect
, hb
);
9434 release_frame_dc (f
, hdc
);
9438 /* Draw a bar cursor on window W in glyph row ROW.
9440 Implementation note: One would like to draw a bar cursor with an
9441 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9442 Unfortunately, I didn't find a font yet that has this property set.
9446 x_draw_bar_cursor (w
, row
, width
)
9448 struct glyph_row
*row
;
9451 struct frame
*f
= XFRAME (w
->frame
);
9452 struct glyph
*cursor_glyph
;
9456 /* If cursor is out of bounds, don't draw garbage. This can happen
9457 in mini-buffer windows when switching between echo area glyphs
9459 cursor_glyph
= get_phys_cursor_glyph (w
);
9460 if (cursor_glyph
== NULL
)
9463 /* If on an image, draw like a normal cursor. That's usually better
9464 visible than drawing a bar, esp. if the image is large so that
9465 the bar might not be in the window. */
9466 if (cursor_glyph
->type
== IMAGE_GLYPH
)
9468 struct glyph_row
*row
;
9469 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
9470 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
9474 COLORREF cursor_color
= f
->output_data
.w32
->cursor_pixel
;
9475 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
9478 width
= f
->output_data
.w32
->cursor_width
;
9480 /* If the glyph's background equals the color we normally draw
9481 the bar cursor in, the bar cursor in its normal color is
9482 invisible. Use the glyph's foreground color instead in this
9483 case, on the assumption that the glyph's colors are chosen so
9484 that the glyph is legible. */
9485 if (face
->background
== cursor_color
)
9486 cursor_color
= face
->foreground
;
9488 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9489 hdc
= get_frame_dc (f
);
9490 w32_clip_to_row (w
, row
, hdc
, 0);
9491 w32_fill_area (f
, hdc
, cursor_color
, x
,
9492 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9493 min (cursor_glyph
->pixel_width
, width
),
9495 release_frame_dc (f
, hdc
);
9500 /* Clear the cursor of window W to background color, and mark the
9501 cursor as not shown. This is used when the text where the cursor
9502 is is about to be rewritten. */
9508 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9509 x_update_window_cursor (w
, 0);
9513 /* Draw the cursor glyph of window W in glyph row ROW. See the
9514 comment of x_draw_glyphs for the meaning of HL. */
9517 x_draw_phys_cursor_glyph (w
, row
, hl
)
9519 struct glyph_row
*row
;
9520 enum draw_glyphs_face hl
;
9522 /* If cursor hpos is out of bounds, don't draw garbage. This can
9523 happen in mini-buffer windows when switching between echo area
9524 glyphs and mini-buffer. */
9525 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9527 int on_p
= w
->phys_cursor_on_p
;
9528 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9529 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9531 w
->phys_cursor_on_p
= on_p
;
9533 /* When we erase the cursor, and ROW is overlapped by other
9534 rows, make sure that these overlapping parts of other rows
9536 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9538 if (row
> w
->current_matrix
->rows
9539 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9540 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9542 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9543 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9544 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9550 /* Erase the image of a cursor of window W from the screen. */
9553 x_erase_phys_cursor (w
)
9556 struct frame
*f
= XFRAME (w
->frame
);
9557 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9558 int hpos
= w
->phys_cursor
.hpos
;
9559 int vpos
= w
->phys_cursor
.vpos
;
9560 int mouse_face_here_p
= 0;
9561 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9562 struct glyph_row
*cursor_row
;
9563 struct glyph
*cursor_glyph
;
9564 enum draw_glyphs_face hl
;
9566 /* No cursor displayed or row invalidated => nothing to do on the
9568 if (w
->phys_cursor_type
== NO_CURSOR
)
9569 goto mark_cursor_off
;
9571 /* VPOS >= active_glyphs->nrows means that window has been resized.
9572 Don't bother to erase the cursor. */
9573 if (vpos
>= active_glyphs
->nrows
)
9574 goto mark_cursor_off
;
9576 /* If row containing cursor is marked invalid, there is nothing we
9578 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9579 if (!cursor_row
->enabled_p
)
9580 goto mark_cursor_off
;
9582 /* If row is completely invisible, don't attempt to delete a cursor which
9583 isn't there. This may happen if cursor is at top of window, and
9584 we switch to a buffer with a header line in that window. */
9585 if (cursor_row
->visible_height
<= 0)
9586 goto mark_cursor_off
;
9588 /* This can happen when the new row is shorter than the old one.
9589 In this case, either x_draw_glyphs or clear_end_of_line
9590 should have cleared the cursor. Note that we wouldn't be
9591 able to erase the cursor in this case because we don't have a
9592 cursor glyph at hand. */
9593 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9594 goto mark_cursor_off
;
9596 /* If the cursor is in the mouse face area, redisplay that when
9597 we clear the cursor. */
9598 if (! NILP (dpyinfo
->mouse_face_window
)
9599 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9600 && (vpos
> dpyinfo
->mouse_face_beg_row
9601 || (vpos
== dpyinfo
->mouse_face_beg_row
9602 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9603 && (vpos
< dpyinfo
->mouse_face_end_row
9604 || (vpos
== dpyinfo
->mouse_face_end_row
9605 && hpos
< dpyinfo
->mouse_face_end_col
))
9606 /* Don't redraw the cursor's spot in mouse face if it is at the
9607 end of a line (on a newline). The cursor appears there, but
9608 mouse highlighting does not. */
9609 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9610 mouse_face_here_p
= 1;
9612 /* Maybe clear the display under the cursor. */
9613 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9616 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9619 cursor_glyph
= get_phys_cursor_glyph (w
);
9620 if (cursor_glyph
== NULL
)
9621 goto mark_cursor_off
;
9623 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9625 hdc
= get_frame_dc (f
);
9626 w32_clear_area (f
, hdc
, x
,
9627 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9629 cursor_glyph
->pixel_width
,
9630 cursor_row
->visible_height
);
9631 release_frame_dc (f
, hdc
);
9634 /* Erase the cursor by redrawing the character underneath it. */
9635 if (mouse_face_here_p
)
9636 hl
= DRAW_MOUSE_FACE
;
9638 hl
= DRAW_NORMAL_TEXT
;
9639 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9642 w
->phys_cursor_on_p
= 0;
9643 w
->phys_cursor_type
= NO_CURSOR
;
9647 /* Non-zero if physical cursor of window W is within mouse face. */
9650 cursor_in_mouse_face_p (w
)
9653 struct w32_display_info
*dpyinfo
9654 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
9655 int in_mouse_face
= 0;
9657 if (WINDOWP (dpyinfo
->mouse_face_window
)
9658 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
9660 int hpos
= w
->phys_cursor
.hpos
;
9661 int vpos
= w
->phys_cursor
.vpos
;
9663 if (vpos
>= dpyinfo
->mouse_face_beg_row
9664 && vpos
<= dpyinfo
->mouse_face_end_row
9665 && (vpos
> dpyinfo
->mouse_face_beg_row
9666 || hpos
>= dpyinfo
->mouse_face_beg_col
)
9667 && (vpos
< dpyinfo
->mouse_face_end_row
9668 || hpos
< dpyinfo
->mouse_face_end_col
9669 || dpyinfo
->mouse_face_past_end
))
9673 return in_mouse_face
;
9677 /* Display or clear cursor of window W. If ON is zero, clear the
9678 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9679 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9682 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9684 int on
, hpos
, vpos
, x
, y
;
9686 struct frame
*f
= XFRAME (w
->frame
);
9687 int new_cursor_type
;
9688 int new_cursor_width
;
9689 struct glyph_matrix
*current_glyphs
;
9690 struct glyph_row
*glyph_row
;
9691 struct glyph
*glyph
;
9692 int cursor_non_selected
;
9693 int active_cursor
= 1;
9695 /* This is pointless on invisible frames, and dangerous on garbaged
9696 windows and frames; in the latter case, the frame or window may
9697 be in the midst of changing its size, and x and y may be off the
9699 if (! FRAME_VISIBLE_P (f
)
9700 || FRAME_GARBAGED_P (f
)
9701 || vpos
>= w
->current_matrix
->nrows
9702 || hpos
>= w
->current_matrix
->matrix_w
)
9705 /* If cursor is off and we want it off, return quickly. */
9706 if (!on
&& !w
->phys_cursor_on_p
)
9709 current_glyphs
= w
->current_matrix
;
9710 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9711 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9713 /* If cursor row is not enabled, we don't really know where to
9714 display the cursor. */
9715 if (!glyph_row
->enabled_p
)
9717 w
->phys_cursor_on_p
= 0;
9721 xassert (interrupt_input_blocked
);
9723 /* Set new_cursor_type to the cursor we want to be displayed. In a
9724 mini-buffer window, we want the cursor only to appear if we are
9725 reading input from this window. For the selected window, we want
9726 the cursor type given by the frame parameter. If explicitly
9727 marked off, draw no cursor. In all other cases, we want a hollow
9730 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
9732 new_cursor_width
= -1;
9733 if (cursor_in_echo_area
9734 && FRAME_HAS_MINIBUF_P (f
)
9735 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
9737 if (w
== XWINDOW (echo_area_window
))
9738 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9741 if (cursor_non_selected
)
9742 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9744 new_cursor_type
= NO_CURSOR
;
9750 if (f
!= FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
9751 || w
!= XWINDOW (f
->selected_window
))
9755 if (MINI_WINDOW_P (w
)
9756 || !cursor_non_selected
9757 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
9758 new_cursor_type
= NO_CURSOR
;
9760 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9764 struct buffer
*b
= XBUFFER (w
->buffer
);
9766 if (EQ (b
->cursor_type
, Qt
))
9767 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9769 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
9771 if (w
->cursor_off_p
)
9773 if (new_cursor_type
== FILLED_BOX_CURSOR
)
9774 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9775 else if (new_cursor_type
== BAR_CURSOR
&& new_cursor_width
> 1)
9776 new_cursor_width
= 1;
9778 new_cursor_type
= NO_CURSOR
;
9783 /* If cursor is currently being shown and we don't want it to be or
9784 it is in the wrong place, or the cursor type is not what we want,
9786 if (w
->phys_cursor_on_p
9788 || w
->phys_cursor
.x
!= x
9789 || w
->phys_cursor
.y
!= y
9790 || new_cursor_type
!= w
->phys_cursor_type
9791 || (new_cursor_type
== BAR_CURSOR
9792 && new_cursor_width
!= w
->phys_cursor_width
)))
9793 x_erase_phys_cursor (w
);
9795 /* If the cursor is now invisible and we want it to be visible,
9797 if (on
&& !w
->phys_cursor_on_p
)
9799 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9800 w
->phys_cursor_height
= glyph_row
->height
;
9802 /* Set phys_cursor_.* before x_draw_.* is called because some
9803 of them may need the information. */
9804 w
->phys_cursor
.x
= x
;
9805 w
->phys_cursor
.y
= glyph_row
->y
;
9806 w
->phys_cursor
.hpos
= hpos
;
9807 w
->phys_cursor
.vpos
= vpos
;
9809 /* If the user wants to use the system caret, make sure our own
9810 cursor remains invisible. */
9811 if (w32_use_visible_system_caret
)
9813 if (w
->phys_cursor_type
!= NO_CURSOR
)
9814 x_erase_phys_cursor (w
);
9816 new_cursor_type
= w
->phys_cursor_type
= NO_CURSOR
;
9817 w
->phys_cursor_width
= -1;
9821 w
->phys_cursor_type
= new_cursor_type
;
9822 w
->phys_cursor_width
= new_cursor_width
;
9825 w
->phys_cursor_on_p
= 1;
9827 /* If this is the active cursor, we need to track it with the
9828 system caret, so third party software like screen magnifiers
9829 and speech synthesizers can follow the cursor. */
9832 HWND hwnd
= FRAME_W32_WINDOW (f
);
9835 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9837 = (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9838 + glyph_row
->ascent
- w
->phys_cursor_ascent
);
9840 /* If the size of the active cursor changed, destroy the old
9842 if (w32_system_caret_hwnd
9843 && (w32_system_caret_height
!= w
->phys_cursor_height
))
9844 PostMessage (hwnd
, WM_EMACS_DESTROY_CARET
, 0, 0);
9846 w32_system_caret_height
= w
->phys_cursor_height
;
9848 /* Move the system caret. */
9849 PostMessage (hwnd
, WM_EMACS_TRACK_CARET
, 0, 0);
9852 switch (new_cursor_type
)
9854 case HOLLOW_BOX_CURSOR
:
9855 x_draw_hollow_cursor (w
, glyph_row
);
9858 case FILLED_BOX_CURSOR
:
9859 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9863 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
9876 /* Display the cursor on window W, or clear it. X and Y are window
9877 relative pixel coordinates. HPOS and VPOS are glyph matrix
9878 positions. If W is not the selected window, display a hollow
9879 cursor. ON non-zero means display the cursor at X, Y which
9880 correspond to HPOS, VPOS, otherwise it is cleared. */
9883 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9885 int on
, hpos
, vpos
, x
, y
;
9888 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9893 /* Display the cursor on window W, or clear it, according to ON_P.
9894 Don't change the cursor's position. */
9897 x_update_cursor (f
, on_p
)
9901 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9905 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9906 in the window tree rooted at W. */
9909 x_update_cursor_in_window_tree (w
, on_p
)
9915 if (!NILP (w
->hchild
))
9916 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9917 else if (!NILP (w
->vchild
))
9918 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9920 x_update_window_cursor (w
, on_p
);
9922 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9927 /* Switch the display of W's cursor on or off, according to the value
9931 x_update_window_cursor (w
, on
)
9935 /* Don't update cursor in windows whose frame is in the process
9936 of being deleted. */
9937 if (w
->current_matrix
)
9940 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
,
9941 w
->phys_cursor
.vpos
, w
->phys_cursor
.x
,
9953 x_bitmap_icon (f
, icon
)
9959 if (FRAME_W32_WINDOW (f
) == 0)
9963 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
9964 else if (STRINGP (icon
))
9965 hicon
= LoadImage (NULL
, (LPCTSTR
) XSTRING (icon
)->data
, IMAGE_ICON
, 0, 0,
9966 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
9967 else if (SYMBOLP (icon
))
9971 if (EQ (icon
, intern ("application")))
9972 name
= (LPCTSTR
) IDI_APPLICATION
;
9973 else if (EQ (icon
, intern ("hand")))
9974 name
= (LPCTSTR
) IDI_HAND
;
9975 else if (EQ (icon
, intern ("question")))
9976 name
= (LPCTSTR
) IDI_QUESTION
;
9977 else if (EQ (icon
, intern ("exclamation")))
9978 name
= (LPCTSTR
) IDI_EXCLAMATION
;
9979 else if (EQ (icon
, intern ("asterisk")))
9980 name
= (LPCTSTR
) IDI_ASTERISK
;
9981 else if (EQ (icon
, intern ("winlogo")))
9982 name
= (LPCTSTR
) IDI_WINLOGO
;
9986 hicon
= LoadIcon (NULL
, name
);
9994 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
10001 /************************************************************************
10003 ************************************************************************/
10005 /* Display Error Handling functions not used on W32. Listing them here
10006 helps diff stay in step when comparing w32term.c with xterm.c.
10008 x_error_catcher (display, error)
10009 x_catch_errors (dpy)
10010 x_catch_errors_unwind (old_val)
10011 x_check_errors (dpy, format)
10012 x_had_errors_p (dpy)
10013 x_clear_errors (dpy)
10014 x_uncatch_errors (dpy, count)
10016 x_connection_signal (signalnum)
10017 x_connection_closed (dpy, error_message)
10018 x_error_quitter (display, error)
10019 x_error_handler (display, error)
10020 x_io_error_quitter (display)
10025 /* Changing the font of the frame. */
10027 /* Give frame F the font named FONTNAME as its default font, and
10028 return the full name of that font. FONTNAME may be a wildcard
10029 pattern; in that case, we choose some font that fits the pattern.
10030 The return value shows which font we chose. */
10033 x_new_font (f
, fontname
)
10035 register char *fontname
;
10037 struct font_info
*fontp
10038 = FS_LOAD_FONT (f
, 0, fontname
, -1);
10043 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
10044 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
10045 FRAME_FONTSET (f
) = -1;
10047 /* Compute the scroll bar width in character columns. */
10048 if (f
->scroll_bar_pixel_width
> 0)
10050 int wid
= FONT_WIDTH (FRAME_FONT (f
));
10051 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
10055 int wid
= FONT_WIDTH (FRAME_FONT (f
));
10056 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
10059 /* Now make the frame display the given font. */
10060 if (FRAME_W32_WINDOW (f
) != 0)
10062 frame_update_line_height (f
);
10063 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
10064 x_set_window_size (f
, 0, f
->width
, f
->height
);
10067 /* If we are setting a new frame's font for the first time,
10068 there are no faces yet, so this font's height is the line height. */
10069 f
->output_data
.w32
->line_height
= FONT_HEIGHT (FRAME_FONT (f
));
10071 return build_string (fontp
->full_name
);
10074 /* Give frame F the fontset named FONTSETNAME as its default font, and
10075 return the full name of that fontset. FONTSETNAME may be a wildcard
10076 pattern; in that case, we choose some fontset that fits the pattern.
10077 The return value shows which fontset we chose. */
10080 x_new_fontset (f
, fontsetname
)
10084 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
10085 Lisp_Object result
;
10090 if (FRAME_FONTSET (f
) == fontset
)
10091 /* This fontset is already set in frame F. There's nothing more
10093 return fontset_name (fontset
);
10095 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
10097 if (!STRINGP (result
))
10098 /* Can't load ASCII font. */
10101 /* Since x_new_font doesn't update any fontset information, do it now. */
10102 FRAME_FONTSET(f
) = fontset
;
10104 return build_string (fontsetname
);
10107 /* Compute actual fringe widths */
10110 x_compute_fringe_widths (f
, redraw
)
10114 int o_left
= f
->output_data
.w32
->left_fringe_width
;
10115 int o_right
= f
->output_data
.w32
->right_fringe_width
;
10116 int o_cols
= f
->output_data
.w32
->fringe_cols
;
10118 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
10119 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
10120 int left_fringe_width
, right_fringe_width
;
10122 if (!NILP (left_fringe
))
10123 left_fringe
= Fcdr (left_fringe
);
10124 if (!NILP (right_fringe
))
10125 right_fringe
= Fcdr (right_fringe
);
10127 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
10128 XINT (left_fringe
));
10129 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
10130 XINT (right_fringe
));
10132 if (left_fringe_width
|| right_fringe_width
)
10134 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
10135 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
10136 int conf_wid
= left_wid
+ right_wid
;
10137 int font_wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
10138 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
10139 int real_wid
= cols
* font_wid
;
10140 if (left_wid
&& right_wid
)
10142 if (left_fringe_width
< 0)
10144 /* Left fringe width is fixed, adjust right fringe if necessary */
10145 f
->output_data
.w32
->left_fringe_width
= left_wid
;
10146 f
->output_data
.w32
->right_fringe_width
= real_wid
- left_wid
;
10148 else if (right_fringe_width
< 0)
10150 /* Right fringe width is fixed, adjust left fringe if necessary */
10151 f
->output_data
.w32
->left_fringe_width
= real_wid
- right_wid
;
10152 f
->output_data
.w32
->right_fringe_width
= right_wid
;
10156 /* Adjust both fringes with an equal amount.
10157 Note that we are doing integer arithmetic here, so don't
10158 lose a pixel if the total width is an odd number. */
10159 int fill
= real_wid
- conf_wid
;
10160 f
->output_data
.w32
->left_fringe_width
= left_wid
+ fill
/2;
10161 f
->output_data
.w32
->right_fringe_width
= right_wid
+ fill
- fill
/2;
10164 else if (left_fringe_width
)
10166 f
->output_data
.w32
->left_fringe_width
= real_wid
;
10167 f
->output_data
.w32
->right_fringe_width
= 0;
10171 f
->output_data
.w32
->left_fringe_width
= 0;
10172 f
->output_data
.w32
->right_fringe_width
= real_wid
;
10174 f
->output_data
.w32
->fringe_cols
= cols
;
10175 f
->output_data
.w32
->fringes_extra
= real_wid
;
10179 f
->output_data
.w32
->left_fringe_width
= 0;
10180 f
->output_data
.w32
->right_fringe_width
= 0;
10181 f
->output_data
.w32
->fringe_cols
= 0;
10182 f
->output_data
.w32
->fringes_extra
= 0;
10185 if (redraw
&& FRAME_VISIBLE_P (f
))
10186 if (o_left
!= f
->output_data
.w32
->left_fringe_width
||
10187 o_right
!= f
->output_data
.w32
->right_fringe_width
||
10188 o_cols
!= f
->output_data
.w32
->fringe_cols
)
10192 /***********************************************************************
10193 TODO: W32 Input Methods
10194 ***********************************************************************/
10195 /* Listing missing functions from xterm.c helps diff stay in step.
10197 xim_destroy_callback (xim, client_data, call_data)
10198 xim_open_dpy (dpyinfo, resource_name)
10200 xim_instantiate_callback (display, client_data, call_data)
10201 xim_initialize (dpyinfo, resource_name)
10202 xim_close_dpy (dpyinfo)
10207 /* Calculate the absolute position in frame F
10208 from its current recorded position values and gravity. */
10211 x_calc_absolute_position (f
)
10215 int flags
= f
->output_data
.w32
->size_hint_flags
;
10219 /* Find the position of the outside upper-left corner of
10220 the inner window, with respect to the outer window.
10221 But do this only if we will need the results. */
10222 if (f
->output_data
.w32
->parent_desc
!= FRAME_W32_DISPLAY_INFO (f
)->root_window
)
10225 MapWindowPoints (FRAME_W32_WINDOW (f
),
10226 f
->output_data
.w32
->parent_desc
,
10233 rt
.left
= rt
.right
= rt
.top
= rt
.bottom
= 0;
10236 AdjustWindowRect(&rt
, f
->output_data
.w32
->dwStyle
,
10237 FRAME_EXTERNAL_MENU_BAR (f
));
10240 pt
.x
+= (rt
.right
- rt
.left
);
10241 pt
.y
+= (rt
.bottom
- rt
.top
);
10244 /* Treat negative positions as relative to the leftmost bottommost
10245 position that fits on the screen. */
10246 if (flags
& XNegative
)
10247 f
->output_data
.w32
->left_pos
= (FRAME_W32_DISPLAY_INFO (f
)->width
10248 - 2 * f
->output_data
.w32
->border_width
- pt
.x
10250 + f
->output_data
.w32
->left_pos
);
10252 if (flags
& YNegative
)
10253 f
->output_data
.w32
->top_pos
= (FRAME_W32_DISPLAY_INFO (f
)->height
10254 - 2 * f
->output_data
.w32
->border_width
- pt
.y
10256 + f
->output_data
.w32
->top_pos
);
10257 /* The left_pos and top_pos
10258 are now relative to the top and left screen edges,
10259 so the flags should correspond. */
10260 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10263 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
10264 to really change the position, and 0 when calling from
10265 x_make_frame_visible (in that case, XOFF and YOFF are the current
10266 position values). It is -1 when calling from x_set_frame_parameters,
10267 which means, do adjust for borders but don't change the gravity. */
10270 x_set_offset (f
, xoff
, yoff
, change_gravity
)
10272 register int xoff
, yoff
;
10273 int change_gravity
;
10275 int modified_top
, modified_left
;
10277 if (change_gravity
> 0)
10279 f
->output_data
.w32
->top_pos
= yoff
;
10280 f
->output_data
.w32
->left_pos
= xoff
;
10281 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10283 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
10285 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
10286 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
10288 x_calc_absolute_position (f
);
10291 x_wm_set_size_hint (f
, (long) 0, 0);
10293 modified_left
= f
->output_data
.w32
->left_pos
;
10294 modified_top
= f
->output_data
.w32
->top_pos
;
10296 my_set_window_pos (FRAME_W32_WINDOW (f
),
10298 modified_left
, modified_top
,
10300 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
10305 /* Check if we need to resize the frame due to a fullscreen request.
10306 If so needed, resize the frame. */
10308 x_check_fullscreen (f
)
10311 if (f
->output_data
.w32
->want_fullscreen
& FULLSCREEN_BOTH
)
10313 int width
, height
, ign
;
10315 x_real_positions (f
, &f
->output_data
.w32
->left_pos
,
10316 &f
->output_data
.w32
->top_pos
);
10318 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
10320 /* We do not need to move the window, it shall be taken care of
10321 when setting WM manager hints.
10322 If the frame is visible already, the position is checked by
10323 x_check_fullscreen_move. */
10324 if (f
->width
!= width
|| f
->height
!= height
)
10326 change_frame_size (f
, height
, width
, 0, 1, 0);
10327 SET_FRAME_GARBAGED (f
);
10328 cancel_mouse_face (f
);
10330 /* Wait for the change of frame size to occur */
10331 f
->output_data
.w32
->want_fullscreen
|= FULLSCREEN_WAIT
;
10336 /* If frame parameters are set after the frame is mapped, we need to move
10337 the window. This is done in xfns.c.
10338 Some window managers moves the window to the right position, some
10339 moves the outer window manager window to the specified position.
10340 Here we check that we are in the right spot. If not, make a second
10341 move, assuming we are dealing with the second kind of window manager. */
10343 x_check_fullscreen_move (f
)
10346 if (f
->output_data
.w32
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
10348 int expect_top
= f
->output_data
.w32
->top_pos
;
10349 int expect_left
= f
->output_data
.w32
->left_pos
;
10351 if (f
->output_data
.w32
->want_fullscreen
& FULLSCREEN_HEIGHT
)
10353 if (f
->output_data
.w32
->want_fullscreen
& FULLSCREEN_WIDTH
)
10356 if (expect_top
!= f
->output_data
.w32
->top_pos
10357 || expect_left
!= f
->output_data
.w32
->left_pos
)
10358 x_set_offset (f
, expect_left
, expect_top
, 1);
10360 /* Just do this once */
10361 f
->output_data
.w32
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
10366 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
10367 wanted positions of the WM window (not emacs window).
10368 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
10369 window (FRAME_X_WINDOW).
10372 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
10379 int newwidth
= f
->width
, newheight
= f
->height
;
10381 *top_pos
= f
->output_data
.w32
->top_pos
;
10382 *left_pos
= f
->output_data
.w32
->left_pos
;
10384 if (f
->output_data
.w32
->want_fullscreen
& FULLSCREEN_HEIGHT
)
10388 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
10389 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
10390 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
10391 - f
->output_data
.w32
->y_pixels_diff
;
10392 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
10396 if (f
->output_data
.w32
->want_fullscreen
& FULLSCREEN_WIDTH
)
10400 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
10401 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
10402 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
10403 - f
->output_data
.w32
->x_pixels_diff
;
10404 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
10409 *height
= newheight
;
10413 /* Call this to change the size of frame F's x-window.
10414 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
10415 for this size change and subsequent size changes.
10416 Otherwise we leave the window gravity unchanged. */
10419 x_set_window_size (f
, change_gravity
, cols
, rows
)
10421 int change_gravity
;
10424 int pixelwidth
, pixelheight
;
10428 check_frame_size (f
, &rows
, &cols
);
10429 f
->output_data
.w32
->vertical_scroll_bar_extra
10430 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
10432 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
10434 x_compute_fringe_widths (f
, 0);
10436 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
10437 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
10439 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
10440 x_wm_set_size_hint (f
, (long) 0, 0);
10445 rect
.left
= rect
.top
= 0;
10446 rect
.right
= pixelwidth
;
10447 rect
.bottom
= pixelheight
;
10449 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
,
10450 FRAME_EXTERNAL_MENU_BAR (f
));
10452 my_set_window_pos (FRAME_W32_WINDOW (f
),
10455 rect
.right
- rect
.left
,
10456 rect
.bottom
- rect
.top
,
10457 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10460 /* Now, strictly speaking, we can't be sure that this is accurate,
10461 but the window manager will get around to dealing with the size
10462 change request eventually, and we'll hear how it went when the
10463 ConfigureNotify event gets here.
10465 We could just not bother storing any of this information here,
10466 and let the ConfigureNotify event set everything up, but that
10467 might be kind of confusing to the Lisp code, since size changes
10468 wouldn't be reported in the frame parameters until some random
10469 point in the future when the ConfigureNotify event arrives.
10471 We pass 1 for DELAY since we can't run Lisp code inside of
10473 change_frame_size (f
, rows
, cols
, 0, 1, 0);
10474 PIXEL_WIDTH (f
) = pixelwidth
;
10475 PIXEL_HEIGHT (f
) = pixelheight
;
10477 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10478 receive in the ConfigureNotify event; if we get what we asked
10479 for, then the event won't cause the screen to become garbaged, so
10480 we have to make sure to do it here. */
10481 SET_FRAME_GARBAGED (f
);
10483 /* If cursor was outside the new size, mark it as off. */
10484 mark_window_cursors_off (XWINDOW (f
->root_window
));
10486 /* Clear out any recollection of where the mouse highlighting was,
10487 since it might be in a place that's outside the new frame size.
10488 Actually checking whether it is outside is a pain in the neck,
10489 so don't try--just let the highlighting be done afresh with new size. */
10490 cancel_mouse_face (f
);
10495 /* Mouse warping. */
10497 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
10500 x_set_mouse_position (f
, x
, y
)
10506 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.w32
->font
) / 2;
10507 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.w32
->line_height
/ 2;
10509 if (pix_x
< 0) pix_x
= 0;
10510 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
10512 if (pix_y
< 0) pix_y
= 0;
10513 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
10515 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
10519 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
10528 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
10529 pt
.x
= rect
.left
+ pix_x
;
10530 pt
.y
= rect
.top
+ pix_y
;
10531 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
10533 SetCursorPos (pt
.x
, pt
.y
);
10539 /* focus shifting, raising and lowering. */
10542 x_focus_on_frame (f
)
10545 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
10547 /* Give input focus to frame. */
10550 /* Try not to change its Z-order if possible. */
10551 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
10552 my_set_focus (f
, FRAME_W32_WINDOW (f
));
10555 my_set_foreground_window (FRAME_W32_WINDOW (f
));
10560 x_unfocus_frame (f
)
10565 /* Raise frame F. */
10572 /* Strictly speaking, raise-frame should only change the frame's Z
10573 order, leaving input focus unchanged. This is reasonable behaviour
10574 on X where the usual policy is point-to-focus. However, this
10575 behaviour would be very odd on Windows where the usual policy is
10578 On X, if the mouse happens to be over the raised frame, it gets
10579 input focus anyway (so the window with focus will never be
10580 completely obscured) - if not, then just moving the mouse over it
10581 is sufficient to give it focus. On Windows, the user must actually
10582 click on the frame (preferrably the title bar so as not to move
10583 point), which is more awkward. Also, no other Windows program
10584 raises a window to the top but leaves another window (possibly now
10585 completely obscured) with input focus.
10587 Because there is a system setting on Windows that allows the user
10588 to choose the point to focus policy, we make the strict semantics
10589 optional, but by default we grab focus when raising. */
10591 if (NILP (Vw32_grab_focus_on_raise
))
10593 /* The obvious call to my_set_window_pos doesn't work if Emacs is
10594 not already the foreground application: the frame is raised
10595 above all other frames belonging to us, but not above the
10596 current top window. To achieve that, we have to resort to this
10597 more cumbersome method. */
10599 HDWP handle
= BeginDeferWindowPos (2);
10602 DeferWindowPos (handle
,
10603 FRAME_W32_WINDOW (f
),
10606 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10608 DeferWindowPos (handle
,
10609 GetForegroundWindow (),
10610 FRAME_W32_WINDOW (f
),
10612 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10614 EndDeferWindowPos (handle
);
10619 my_set_foreground_window (FRAME_W32_WINDOW (f
));
10625 /* Lower frame F. */
10631 my_set_window_pos (FRAME_W32_WINDOW (f
),
10634 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10639 w32_frame_raise_lower (f
, raise_flag
)
10643 if (! FRAME_W32_P (f
))
10652 /* Change of visibility. */
10654 /* This tries to wait until the frame is really visible.
10655 However, if the window manager asks the user where to position
10656 the frame, this will return before the user finishes doing that.
10657 The frame will not actually be visible at that time,
10658 but it will become visible later when the window manager
10659 finishes with it. */
10662 x_make_frame_visible (f
)
10669 type
= x_icon_type (f
);
10671 x_bitmap_icon (f
, type
);
10673 if (! FRAME_VISIBLE_P (f
))
10675 /* We test FRAME_GARBAGED_P here to make sure we don't
10676 call x_set_offset a second time
10677 if we get to x_make_frame_visible a second time
10678 before the window gets really visible. */
10679 if (! FRAME_ICONIFIED_P (f
)
10680 && ! f
->output_data
.w32
->asked_for_visible
)
10681 x_set_offset (f
, f
->output_data
.w32
->left_pos
, f
->output_data
.w32
->top_pos
, 0);
10683 f
->output_data
.w32
->asked_for_visible
= 1;
10685 /* my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW); */
10686 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_SHOWNORMAL
);
10689 /* Synchronize to ensure Emacs knows the frame is visible
10690 before we do anything else. We do this loop with input not blocked
10691 so that incoming events are handled. */
10696 /* This must come after we set COUNT. */
10699 XSETFRAME (frame
, f
);
10701 /* Wait until the frame is visible. Process X events until a
10702 MapNotify event has been seen, or until we think we won't get a
10703 MapNotify at all.. */
10704 for (count
= input_signal_count
+ 10;
10705 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
10707 /* Force processing of queued events. */
10708 /* TODO: x_sync equivalent? */
10710 /* Machines that do polling rather than SIGIO have been observed
10711 to go into a busy-wait here. So we'll fake an alarm signal
10712 to let the handler know that there's something to be read.
10713 We used to raise a real alarm, but it seems that the handler
10714 isn't always enabled here. This is probably a bug. */
10715 if (input_polling_used ())
10717 /* It could be confusing if a real alarm arrives while processing
10718 the fake one. Turn it off and let the handler reset it. */
10719 int old_poll_suppress_count
= poll_suppress_count
;
10720 poll_suppress_count
= 1;
10721 poll_for_input_1 ();
10722 poll_suppress_count
= old_poll_suppress_count
;
10725 FRAME_SAMPLE_VISIBILITY (f
);
10729 /* Change from mapped state to withdrawn state. */
10731 /* Make the frame visible (mapped and not iconified). */
10733 x_make_frame_invisible (f
)
10736 /* Don't keep the highlight on an invisible frame. */
10737 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
10738 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
10742 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
10744 /* We can't distinguish this from iconification
10745 just by the event that we get from the server.
10746 So we can't win using the usual strategy of letting
10747 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
10748 and synchronize with the server to make sure we agree. */
10750 FRAME_ICONIFIED_P (f
) = 0;
10751 f
->async_visible
= 0;
10752 f
->async_iconified
= 0;
10757 /* Change window state from mapped to iconified. */
10760 x_iconify_frame (f
)
10765 /* Don't keep the highlight on an invisible frame. */
10766 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
10767 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
10769 if (f
->async_iconified
)
10774 type
= x_icon_type (f
);
10776 x_bitmap_icon (f
, type
);
10778 /* Simulate the user minimizing the frame. */
10779 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
10785 /* Free X resources of frame F. */
10788 x_free_frame_resources (f
)
10791 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10795 if (FRAME_W32_WINDOW (f
))
10796 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
10798 free_frame_menubar (f
);
10800 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
10801 unload_color (f
, f
->output_data
.x
->background_pixel
);
10802 unload_color (f
, f
->output_data
.w32
->cursor_pixel
);
10803 unload_color (f
, f
->output_data
.w32
->cursor_foreground_pixel
);
10804 unload_color (f
, f
->output_data
.w32
->border_pixel
);
10805 unload_color (f
, f
->output_data
.w32
->mouse_pixel
);
10806 if (f
->output_data
.w32
->white_relief
.allocated_p
)
10807 unload_color (f
, f
->output_data
.w32
->white_relief
.pixel
);
10808 if (f
->output_data
.w32
->black_relief
.allocated_p
)
10809 unload_color (f
, f
->output_data
.w32
->black_relief
.pixel
);
10811 if (FRAME_FACE_CACHE (f
))
10812 free_frame_faces (f
);
10814 xfree (f
->output_data
.w32
);
10815 f
->output_data
.w32
= NULL
;
10817 if (f
== dpyinfo
->w32_focus_frame
)
10818 dpyinfo
->w32_focus_frame
= 0;
10819 if (f
== dpyinfo
->w32_focus_event_frame
)
10820 dpyinfo
->w32_focus_event_frame
= 0;
10821 if (f
== dpyinfo
->w32_highlight_frame
)
10822 dpyinfo
->w32_highlight_frame
= 0;
10824 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10826 dpyinfo
->mouse_face_beg_row
10827 = dpyinfo
->mouse_face_beg_col
= -1;
10828 dpyinfo
->mouse_face_end_row
10829 = dpyinfo
->mouse_face_end_col
= -1;
10830 dpyinfo
->mouse_face_window
= Qnil
;
10831 dpyinfo
->mouse_face_deferred_gc
= 0;
10832 dpyinfo
->mouse_face_mouse_frame
= 0;
10839 /* Destroy the window of frame F. */
10841 x_destroy_window (f
)
10844 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10846 x_free_frame_resources (f
);
10848 dpyinfo
->reference_count
--;
10852 /* Setting window manager hints. */
10854 /* Set the normal size hints for the window manager, for frame F.
10855 FLAGS is the flags word to use--or 0 meaning preserve the flags
10856 that the window now has.
10857 If USER_POSITION is nonzero, we set the USPosition
10858 flag (this is useful when FLAGS is 0). */
10860 x_wm_set_size_hint (f
, flags
, user_position
)
10865 Window window
= FRAME_W32_WINDOW (f
);
10869 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
10870 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
10871 SetWindowLong (window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
10872 SetWindowLong (window
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
10877 /* Window manager things */
10878 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10880 int icon_x
, icon_y
;
10883 Window window
= FRAME_W32_WINDOW (f
);
10885 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
10886 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
10887 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
10889 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
10894 /***********************************************************************
10896 ***********************************************************************/
10898 /* The following functions are listed here to help diff stay in step
10899 with xterm.c. See w32fns.c for definitions.
10901 x_get_font_info (f, font_idx)
10902 x_list_fonts (f, pattern, size, maxnames)
10908 /* Check that FONT is valid on frame F. It is if it can be found in F's
10912 x_check_font (f
, font
)
10917 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10919 xassert (font
!= NULL
);
10921 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10922 if (dpyinfo
->font_table
[i
].name
10923 && font
== dpyinfo
->font_table
[i
].font
)
10926 xassert (i
< dpyinfo
->n_fonts
);
10929 #endif /* GLYPH_DEBUG != 0 */
10931 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10932 Note: There are (broken) X fonts out there with invalid XFontStruct
10933 min_bounds contents. For example, handa@etl.go.jp reports that
10934 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10935 have font->min_bounds.width == 0. */
10938 x_font_min_bounds (font
, w
, h
)
10943 * TODO: Windows does not appear to offer min bound, only
10944 * average and maximum width, and maximum height.
10946 *h
= FONT_HEIGHT (font
);
10947 *w
= FONT_WIDTH (font
);
10951 /* Compute the smallest character width and smallest font height over
10952 all fonts available on frame F. Set the members smallest_char_width
10953 and smallest_font_height in F's x_display_info structure to
10954 the values computed. Value is non-zero if smallest_font_height or
10955 smallest_char_width become smaller than they were before. */
10958 x_compute_min_glyph_bounds (f
)
10962 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10964 int old_width
= dpyinfo
->smallest_char_width
;
10965 int old_height
= dpyinfo
->smallest_font_height
;
10967 dpyinfo
->smallest_font_height
= 100000;
10968 dpyinfo
->smallest_char_width
= 100000;
10970 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10971 if (dpyinfo
->font_table
[i
].name
)
10973 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10976 font
= (XFontStruct
*) fontp
->font
;
10977 xassert (font
!= (XFontStruct
*) ~0);
10978 x_font_min_bounds (font
, &w
, &h
);
10980 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10981 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10984 xassert (dpyinfo
->smallest_char_width
> 0
10985 && dpyinfo
->smallest_font_height
> 0);
10987 return (dpyinfo
->n_fonts
== 1
10988 || dpyinfo
->smallest_char_width
< old_width
10989 || dpyinfo
->smallest_font_height
< old_height
);
10992 /* The following functions are listed here to help diff stay in step
10993 with xterm.c. See w32fns.c for definitions.
10995 x_load_font (f, fontname, size)
10996 x_query_font (f, fontname)
10997 x_find_ccl_program (fontp)
11001 /***********************************************************************
11003 ***********************************************************************/
11005 static int w32_initialized
= 0;
11008 w32_initialize_display_info (display_name
)
11009 Lisp_Object display_name
;
11011 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
11013 bzero (dpyinfo
, sizeof (*dpyinfo
));
11015 /* Put it on w32_display_name_list. */
11016 w32_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
11017 w32_display_name_list
);
11018 dpyinfo
->name_list_element
= XCAR (w32_display_name_list
);
11020 dpyinfo
->w32_id_name
11021 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
11022 + XSTRING (Vsystem_name
)->size
11024 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
11025 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
11027 /* Default Console mode values - overridden when running in GUI mode
11028 with values obtained from system metrics. */
11031 dpyinfo
->height_in
= 1;
11032 dpyinfo
->width_in
= 1;
11033 dpyinfo
->n_planes
= 1;
11034 dpyinfo
->n_cbits
= 4;
11035 dpyinfo
->n_fonts
= 0;
11036 dpyinfo
->smallest_font_height
= 1;
11037 dpyinfo
->smallest_char_width
= 1;
11039 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
11040 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
11041 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
11042 dpyinfo
->mouse_face_window
= Qnil
;
11043 dpyinfo
->mouse_face_overlay
= Qnil
;
11044 dpyinfo
->mouse_face_hidden
= 0;
11045 /* TODO: dpyinfo->gray */
11049 struct w32_display_info
*
11050 w32_term_init (display_name
, xrm_option
, resource_name
)
11051 Lisp_Object display_name
;
11053 char *resource_name
;
11055 struct w32_display_info
*dpyinfo
;
11060 if (!w32_initialized
)
11063 w32_initialized
= 1;
11074 argv
[argc
++] = "-xrm";
11075 argv
[argc
++] = xrm_option
;
11079 w32_initialize_display_info (display_name
);
11081 dpyinfo
= &one_w32_display_info
;
11083 /* Put this display on the chain. */
11084 dpyinfo
->next
= x_display_list
;
11085 x_display_list
= dpyinfo
;
11087 hdc
= GetDC (GetDesktopWindow ());
11089 dpyinfo
->height
= GetDeviceCaps (hdc
, VERTRES
);
11090 dpyinfo
->width
= GetDeviceCaps (hdc
, HORZRES
);
11091 dpyinfo
->root_window
= GetDesktopWindow ();
11092 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
11093 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
11094 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
11095 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
11096 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
11097 dpyinfo
->image_cache
= make_image_cache ();
11098 dpyinfo
->height_in
= dpyinfo
->height
/ dpyinfo
->resx
;
11099 dpyinfo
->width_in
= dpyinfo
->width
/ dpyinfo
->resy
;
11100 ReleaseDC (GetDesktopWindow (), hdc
);
11102 /* initialise palette with white and black */
11105 w32_defined_color (0, "white", &color
, 1);
11106 w32_defined_color (0, "black", &color
, 1);
11109 /* Create Row Bitmaps and store them for later use. */
11110 left_bmp
= CreateBitmap (left_width
, left_height
, 1, 1, left_bits
);
11111 ov_bmp
= CreateBitmap (ov_width
, ov_height
, 1, 1, ov_bits
);
11112 right_bmp
= CreateBitmap (right_width
, right_height
, 1, 1, right_bits
);
11113 continued_bmp
= CreateBitmap (continued_width
, continued_height
, 1,
11114 1, continued_bits
);
11115 continuation_bmp
= CreateBitmap (continuation_width
, continuation_height
,
11116 1, 1, continuation_bits
);
11117 zv_bmp
= CreateBitmap (zv_width
, zv_height
, 1, 1, zv_bits
);
11119 #ifndef F_SETOWN_BUG
11121 #ifdef F_SETOWN_SOCK_NEG
11122 /* stdin is a socket here */
11123 fcntl (connection
, F_SETOWN
, -getpid ());
11124 #else /* ! defined (F_SETOWN_SOCK_NEG) */
11125 fcntl (connection
, F_SETOWN
, getpid ());
11126 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
11127 #endif /* ! defined (F_SETOWN) */
11128 #endif /* F_SETOWN_BUG */
11131 if (interrupt_input
)
11132 init_sigio (connection
);
11133 #endif /* ! defined (SIGIO) */
11140 /* Get rid of display DPYINFO, assuming all frames are already gone. */
11143 x_delete_display (dpyinfo
)
11144 struct w32_display_info
*dpyinfo
;
11146 /* Discard this display from w32_display_name_list and w32_display_list.
11147 We can't use Fdelq because that can quit. */
11148 if (! NILP (w32_display_name_list
)
11149 && EQ (XCAR (w32_display_name_list
), dpyinfo
->name_list_element
))
11150 w32_display_name_list
= XCDR (w32_display_name_list
);
11155 tail
= w32_display_name_list
;
11156 while (CONSP (tail
) && CONSP (XCDR (tail
)))
11158 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
11160 XSETCDR (tail
, XCDR (XCDR (tail
)));
11163 tail
= XCDR (tail
);
11167 /* free palette table */
11169 struct w32_palette_entry
* plist
;
11171 plist
= dpyinfo
->color_list
;
11174 struct w32_palette_entry
* pentry
= plist
;
11175 plist
= plist
->next
;
11178 dpyinfo
->color_list
= NULL
;
11179 if (dpyinfo
->palette
)
11180 DeleteObject(dpyinfo
->palette
);
11182 xfree (dpyinfo
->font_table
);
11183 xfree (dpyinfo
->w32_id_name
);
11185 /* Destroy row bitmaps. */
11186 DeleteObject (left_bmp
);
11187 DeleteObject (ov_bmp
);
11188 DeleteObject (right_bmp
);
11189 DeleteObject (continued_bmp
);
11190 DeleteObject (continuation_bmp
);
11191 DeleteObject (zv_bmp
);
11194 /* Set up use of W32. */
11196 DWORD
w32_msg_worker ();
11199 x_flush (struct frame
* f
)
11200 { /* Nothing to do */ }
11202 static struct redisplay_interface w32_redisplay_interface
=
11207 x_clear_end_of_line
,
11209 x_after_update_window_line
,
11210 x_update_window_begin
,
11211 x_update_window_end
,
11214 x_clear_mouse_face
,
11215 x_get_glyph_overhangs
,
11216 x_fix_overlapping_area
11222 rif
= &w32_redisplay_interface
;
11224 /* MSVC does not type K&R functions with no arguments correctly, and
11225 so we must explicitly cast them. */
11226 clear_frame_hook
= (void (*)(void)) x_clear_frame
;
11227 ring_bell_hook
= (void (*)(void)) w32_ring_bell
;
11228 update_begin_hook
= x_update_begin
;
11229 update_end_hook
= x_update_end
;
11231 read_socket_hook
= w32_read_socket
;
11233 frame_up_to_date_hook
= w32_frame_up_to_date
;
11235 mouse_position_hook
= w32_mouse_position
;
11236 frame_rehighlight_hook
= w32_frame_rehighlight
;
11237 frame_raise_lower_hook
= w32_frame_raise_lower
;
11238 set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
11239 condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
11240 redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
11241 judge_scroll_bars_hook
= w32_judge_scroll_bars
;
11242 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
11244 scroll_region_ok
= 1; /* we'll scroll partial frames */
11245 char_ins_del_ok
= 1;
11246 line_ins_del_ok
= 1; /* we'll just blt 'em */
11247 fast_clear_end_of_line
= 1; /* X does this well */
11248 memory_below_frame
= 0; /* we don't remember what scrolls
11252 w32_system_caret_hwnd
= NULL
;
11253 w32_system_caret_height
= 0;
11254 w32_system_caret_x
= 0;
11255 w32_system_caret_y
= 0;
11257 last_tool_bar_item
= -1;
11258 any_help_event_p
= 0;
11260 /* Initialize input mode: interrupt_input off, no flow control, allow
11261 8 bit character input, standard quit char. */
11262 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
11264 /* Create the window thread - it will terminate itself or when the app terminates */
11268 dwMainThreadId
= GetCurrentThreadId ();
11269 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
11270 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
11272 /* Wait for thread to start */
11277 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
11279 hWindowsThread
= CreateThread (NULL
, 0,
11280 (LPTHREAD_START_ROUTINE
) w32_msg_worker
,
11281 0, 0, &dwWindowsThreadId
);
11283 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
11286 /* It is desirable that mainThread should have the same notion of
11287 focus window and active window as windowsThread. Unfortunately, the
11288 following call to AttachThreadInput, which should do precisely what
11289 we need, causes major problems when Emacs is linked as a console
11290 program. Unfortunately, we have good reasons for doing that, so
11291 instead we need to send messages to windowsThread to make some API
11292 calls for us (ones that affect, or depend on, the active/focus
11294 #ifdef ATTACH_THREADS
11295 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
11298 /* Dynamically link to optional system components. */
11300 HANDLE user_lib
= LoadLibrary ("user32.dll");
11302 #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn)
11304 /* New proportional scroll bar functions. */
11305 LOAD_PROC (SetScrollInfo
);
11306 LOAD_PROC (GetScrollInfo
);
11310 FreeLibrary (user_lib
);
11312 /* If using proportional scroll bars, ensure handle is at least 5 pixels;
11313 otherwise use the fixed height. */
11314 vertical_scroll_bar_min_handle
= (pfnSetScrollInfo
!= NULL
) ? 5 :
11315 GetSystemMetrics (SM_CYVTHUMB
);
11317 /* For either kind of scroll bar, take account of the arrows; these
11318 effectively form the border of the main scroll bar range. */
11319 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
11320 = GetSystemMetrics (SM_CYVSCROLL
);
11327 staticpro (&w32_display_name_list
);
11328 w32_display_name_list
= Qnil
;
11330 staticpro (&last_mouse_scroll_bar
);
11331 last_mouse_scroll_bar
= Qnil
;
11333 staticpro (&Qvendor_specific_keysyms
);
11334 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
11336 DEFVAR_INT ("w32-num-mouse-buttons",
11337 &Vw32_num_mouse_buttons
,
11338 doc
: /* Number of physical mouse buttons. */);
11339 Vw32_num_mouse_buttons
= Qnil
;
11341 DEFVAR_LISP ("w32-swap-mouse-buttons",
11342 &Vw32_swap_mouse_buttons
,
11343 doc
: /* Swap the mapping of middle and right mouse buttons.
11344 When nil, middle button is mouse-2 and right button is mouse-3. */);
11345 Vw32_swap_mouse_buttons
= Qnil
;
11347 DEFVAR_LISP ("w32-grab-focus-on-raise",
11348 &Vw32_grab_focus_on_raise
,
11349 doc
: /* Raised frame grabs input focus.
11350 When t, `raise-frame' grabs input focus as well. This fits well
11351 with the normal Windows click-to-focus policy, but might not be
11352 desirable when using a point-to-focus policy. */);
11353 Vw32_grab_focus_on_raise
= Qt
;
11355 DEFVAR_LISP ("w32-capslock-is-shiftlock",
11356 &Vw32_capslock_is_shiftlock
,
11357 doc
: /* Apply CapsLock state to non character input keys.
11358 When nil, CapsLock only affects normal character input keys. */);
11359 Vw32_capslock_is_shiftlock
= Qnil
;
11361 DEFVAR_LISP ("w32-recognize-altgr",
11362 &Vw32_recognize_altgr
,
11363 doc
: /* Recognize right-alt and left-ctrl as AltGr.
11364 When nil, the right-alt and left-ctrl key combination is
11365 interpreted normally. */);
11366 Vw32_recognize_altgr
= Qt
;
11368 DEFVAR_BOOL ("w32-enable-unicode-output",
11369 &w32_enable_unicode_output
,
11370 doc
: /* Enable the use of Unicode for text output if non-nil.
11371 Unicode output may prevent some third party applications for displaying
11372 Far-East Languages on Windows 95/98 from working properly.
11373 NT uses Unicode internally anyway, so this flag will probably have no
11374 affect on NT machines. */);
11375 w32_enable_unicode_output
= 1;
11378 staticpro (&help_echo
);
11379 help_echo_object
= Qnil
;
11380 staticpro (&help_echo_object
);
11381 help_echo_window
= Qnil
;
11382 staticpro (&help_echo_window
);
11383 previous_help_echo
= Qnil
;
11384 staticpro (&previous_help_echo
);
11385 help_echo_pos
= -1;
11387 DEFVAR_BOOL ("x-autoselect-window", &x_autoselect_window_p
,
11388 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
11389 x_autoselect_window_p
= 0;
11391 DEFVAR_BOOL ("w32-use-visible-system-caret",
11392 &w32_use_visible_system_caret
,
11393 doc
: /* Flag to make the system caret visible.
11394 When this is non-nil, Emacs will indicate the position of point by
11395 using the system caret instead of drawing its own cursor. Some screen
11396 reader software does not track the system cursor properly when it is
11397 invisible, and gets confused by Emacs drawing its own cursor, so this
11398 variable is initialized to t when Emacs detects that screen reader
11399 software is running as it starts up.
11401 When this variable is set, other variables affecting the appearance of
11402 the cursor have no effect. */);
11404 /* Initialize w32_use_visible_system_caret based on whether a screen
11405 reader is in use. */
11406 if (!SystemParametersInfo (SPI_GETSCREENREADER
, 0,
11407 &w32_use_visible_system_caret
, 0))
11408 w32_use_visible_system_caret
= 0;
11410 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
11411 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
11412 For example, if a block cursor is over a tab, it will be drawn as
11413 wide as that tab on the display. */);
11414 x_stretch_cursor_p
= 0;
11416 #if 0 /* TODO: Setting underline position from font properties. */
11417 DEFVAR_BOOL ("x-use-underline-position-properties",
11418 &x_use_underline_position_properties
,
11419 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11420 nil means ignore them. If you encounter fonts with bogus
11421 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11422 to 4.1, set this to nil. */);
11423 x_use_underline_position_properties
= 1;
11426 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11427 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
11428 Vx_toolkit_scroll_bars
= Qt
;
11430 staticpro (&last_mouse_motion_frame
);
11431 last_mouse_motion_frame
= Qnil
;