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 draw block and hollow cursor as wide as the glyph
174 under it. For example, if a block cursor is over a tab, it will be
175 drawn as wide as that tab on the display. */
177 int x_stretch_cursor_p
;
179 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
181 int x_use_underline_position_properties
;
183 extern unsigned int msh_mousewheel
;
185 extern void free_frame_menubar ();
187 extern int w32_codepage_for_font (char *fontname
);
189 extern glyph_metric
*w32_BDF_TextMetric(bdffont
*fontp
,
190 unsigned char *text
, int dim
);
191 extern Lisp_Object Vwindow_system
;
193 #define x_any_window_to_frame x_window_to_frame
194 #define x_top_window_to_frame x_window_to_frame
197 /* This is display since w32 does not support multiple ones. */
198 struct w32_display_info one_w32_display_info
;
199 struct w32_display_info
*x_display_list
;
201 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
202 one for each element of w32_display_list and in the same order.
203 NAME is the name of the frame.
204 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
205 Lisp_Object w32_display_name_list
;
207 /* Frame being updated by update_frame. This is declared in term.c.
208 This is set by update_begin and looked at by all the
209 w32 functions. It is zero while not inside an update.
210 In that case, the w32 functions assume that `SELECTED_FRAME ()'
211 is the frame to apply to. */
212 extern struct frame
*updating_frame
;
214 /* This is a frame waiting to be autoraised, within w32_read_socket. */
215 struct frame
*pending_autoraise_frame
;
217 /* Nominal cursor position -- where to draw output.
218 HPOS and VPOS are window relative glyph matrix coordinates.
219 X and Y are window relative pixel coordinates. */
221 struct cursor_pos output_cursor
;
223 /* The handle of the frame that currently owns the system caret. */
224 HWND w32_system_caret_hwnd
;
225 int w32_system_caret_width
;
226 int w32_system_caret_height
;
227 int w32_system_caret_x
;
228 int w32_system_caret_y
;
230 /* Flag to enable Unicode output in case users wish to use programs
231 like Twinbridge on '95 rather than installed system level support
232 for Far East languages. */
233 int w32_enable_unicode_output
;
235 DWORD dwWindowsThreadId
= 0;
236 HANDLE hWindowsThread
= NULL
;
237 DWORD dwMainThreadId
= 0;
238 HANDLE hMainThread
= NULL
;
241 /* These definitions are new with Windows 95. */
242 #define SIF_RANGE 0x0001
243 #define SIF_PAGE 0x0002
244 #define SIF_POS 0x0004
245 #define SIF_DISABLENOSCROLL 0x0008
246 #define SIF_TRACKPOS 0x0010
247 #define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
249 typedef struct tagSCROLLINFO
258 } SCROLLINFO
, FAR
*LPSCROLLINFO
;
259 typedef SCROLLINFO CONST FAR
*LPCSCROLLINFO
;
262 /* Dynamic linking to new proportional scroll bar functions. */
263 int (PASCAL
*pfnSetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
, BOOL fRedraw
);
264 BOOL (PASCAL
*pfnGetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
);
266 int vertical_scroll_bar_min_handle
;
267 int vertical_scroll_bar_top_border
;
268 int vertical_scroll_bar_bottom_border
;
270 int last_scroll_bar_drag_pos
;
272 /* Mouse movement. */
274 /* Where the mouse was last time we reported a mouse event. */
276 FRAME_PTR last_mouse_frame
;
277 static RECT last_mouse_glyph
;
278 static Lisp_Object last_mouse_press_frame
;
280 Lisp_Object Vw32_num_mouse_buttons
;
282 Lisp_Object Vw32_swap_mouse_buttons
;
284 /* Control whether x_raise_frame also sets input focus. */
285 Lisp_Object Vw32_grab_focus_on_raise
;
287 /* Control whether Caps Lock affects non-ascii characters. */
288 Lisp_Object Vw32_capslock_is_shiftlock
;
290 /* Control whether right-alt and left-ctrl should be recognized as AltGr. */
291 Lisp_Object Vw32_recognize_altgr
;
293 /* The scroll bar in which the last motion event occurred.
295 If the last motion event occurred in a scroll bar, we set this
296 so w32_mouse_position can know whether to report a scroll bar motion or
299 If the last motion event didn't occur in a scroll bar, we set this
300 to Qnil, to tell w32_mouse_position to return an ordinary motion event. */
301 static Lisp_Object last_mouse_scroll_bar
;
302 static int last_mouse_scroll_bar_pos
;
304 /* This is a hack. We would really prefer that w32_mouse_position would
305 return the time associated with the position it returns, but there
306 doesn't seem to be any way to wrest the time-stamp from the server
307 along with the position query. So, we just keep track of the time
308 of the last movement we received, and return that in hopes that
309 it's somewhat accurate. */
311 static Time last_mouse_movement_time
;
313 /* Incremented by w32_read_socket whenever it really tries to read
317 static int volatile input_signal_count
;
319 static int input_signal_count
;
322 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
324 extern Lisp_Object Qface
, Qmouse_face
;
330 /* A mask of extra modifier bits to put into every keyboard char. */
332 extern int extra_keyboard_modifiers
;
334 /* Enumeration for overriding/changing the face to use for drawing
335 glyphs in x_draw_glyphs. */
337 enum draw_glyphs_face
347 static void x_update_window_end
P_ ((struct window
*, int, int));
348 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
349 void w32_delete_display
P_ ((struct w32_display_info
*));
350 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
351 int *, int *, Lisp_Object
));
352 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
353 int *, int *, int *, int *, int));
354 static void set_output_cursor
P_ ((struct cursor_pos
*));
355 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
356 int *, int *, int *, int));
357 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
358 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
359 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
360 static void w32_handle_tool_bar_click
P_ ((struct frame
*,
361 struct input_event
*));
362 static void show_mouse_face
P_ ((struct w32_display_info
*,
363 enum draw_glyphs_face
));
364 static int cursor_in_mouse_face_p
P_ ((struct window
*));
365 static int clear_mouse_face
P_ ((struct w32_display_info
*));
367 void x_lower_frame
P_ ((struct frame
*));
368 void x_scroll_bar_clear
P_ ((struct frame
*));
369 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
370 void x_raise_frame
P_ ((struct frame
*));
371 void x_set_window_size
P_ ((struct frame
*, int, int, int));
372 void x_wm_set_window_state
P_ ((struct frame
*, int));
373 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
374 void w32_initialize
P_ ((void));
375 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
376 int x_compute_min_glyph_bounds
P_ ((struct frame
*));
377 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
379 enum draw_glyphs_face
));
380 static void x_update_end
P_ ((struct frame
*));
381 static void w32_frame_up_to_date
P_ ((struct frame
*));
382 static void w32_set_terminal_modes
P_ ((void));
383 static void w32_reset_terminal_modes
P_ ((void));
384 static void w32_cursor_to
P_ ((int, int, int, int));
385 static void x_write_glyphs
P_ ((struct glyph
*, int));
386 static void x_clear_end_of_line
P_ ((int));
387 static void x_clear_frame
P_ ((void));
388 static void x_clear_cursor
P_ ((struct window
*));
389 static void frame_highlight
P_ ((struct frame
*));
390 static void frame_unhighlight
P_ ((struct frame
*));
391 static void w32_new_focus_frame
P_ ((struct w32_display_info
*,
393 static void w32_frame_rehighlight
P_ ((struct frame
*));
394 static void x_frame_rehighlight
P_ ((struct w32_display_info
*));
395 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
396 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
397 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
398 static int expose_window_tree
P_ ((struct window
*, RECT
*));
399 static int expose_window
P_ ((struct window
*, RECT
*));
400 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
401 RECT
*, enum glyph_row_area
));
402 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
404 void x_update_cursor
P_ ((struct frame
*, int));
405 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
406 static void x_update_window_cursor
P_ ((struct window
*, int));
407 static void x_erase_phys_cursor
P_ ((struct window
*));
408 void x_display_cursor
P_ ((struct window
*w
, int, int, int, int, int));
409 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
410 static void w32_draw_fringe_bitmap
P_ ((struct window
*, HDC hdc
,
412 enum fringe_bitmap_type
, int left_p
));
413 static void w32_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
415 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, RECT
*));
416 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*,
417 struct glyph_row
*));
418 static void notice_overwritten_cursor
P_ ((struct window
*,
420 int, int, int, int));
422 static Lisp_Object Qvendor_specific_keysyms
;
425 /***********************************************************************
427 ***********************************************************************/
431 /* This is a function useful for recording debugging information about
432 the sequence of occurrences in this file. */
440 struct record event_record
[100];
442 int event_record_index
;
444 record_event (locus
, type
)
448 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
449 event_record_index
= 0;
451 event_record
[event_record_index
].locus
= locus
;
452 event_record
[event_record_index
].type
= type
;
453 event_record_index
++;
459 void XChangeGC (void * ignore
, XGCValues
* gc
, unsigned long mask
,
462 if (mask
& GCForeground
)
463 gc
->foreground
= xgcv
->foreground
;
464 if (mask
& GCBackground
)
465 gc
->background
= xgcv
->background
;
467 gc
->font
= xgcv
->font
;
470 XGCValues
*XCreateGC (void * ignore
, Window window
, unsigned long mask
,
473 XGCValues
*gc
= (XGCValues
*) xmalloc (sizeof (XGCValues
));
474 bzero (gc
, sizeof (XGCValues
));
476 XChangeGC (ignore
, gc
, mask
, xgcv
);
481 void XGetGCValues (void* ignore
, XGCValues
*gc
,
482 unsigned long mask
, XGCValues
*xgcv
)
484 XChangeGC (ignore
, xgcv
, mask
, gc
);
488 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
492 HRGN clip_region
= CreateRectRgnIndirect (rect
);
493 SelectClipRgn (hdc
, clip_region
);
494 DeleteObject (clip_region
);
497 SelectClipRgn (hdc
, NULL
);
501 /* Draw a hollow rectangle at the specified position. */
503 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
504 int width
, int height
)
509 hb
= CreateSolidBrush (gc
->background
);
510 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
511 oldhb
= SelectObject (hdc
, hb
);
512 oldhp
= SelectObject (hdc
, hp
);
514 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
516 SelectObject (hdc
, oldhb
);
517 SelectObject (hdc
, oldhp
);
522 /* Draw a filled rectangle at the specified position. */
524 w32_fill_rect (f
, hdc
, pix
, lprect
)
532 hb
= CreateSolidBrush (pix
);
533 FillRect (hdc
, lprect
, hb
);
542 HDC hdc
= get_frame_dc (f
);
544 /* Under certain conditions, this can be called at startup with
545 a console frame pointer before the GUI frame is created. An HDC
546 of 0 indicates this. */
549 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
550 w32_clear_rect (f
, hdc
, &rect
);
553 release_frame_dc (f
, hdc
);
557 /***********************************************************************
558 Starting and ending an update
559 ***********************************************************************/
561 /* Start an update of frame F. This function is installed as a hook
562 for update_begin, i.e. it is called when update_begin is called.
563 This function is called prior to calls to x_update_window_begin for
564 each window being updated. */
570 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
572 if (! FRAME_W32_P (f
))
575 /* Regenerate display palette before drawing if list of requested
576 colors has changed. */
577 if (display_info
->regen_palette
)
579 w32_regenerate_palette (f
);
580 display_info
->regen_palette
= FALSE
;
585 /* Start update of window W. Set the global variable updated_window
586 to the window being updated and set output_cursor to the cursor
590 x_update_window_begin (w
)
593 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
594 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
597 set_output_cursor (&w
->cursor
);
601 if (f
== display_info
->mouse_face_mouse_frame
)
603 /* Don't do highlighting for mouse motion during the update. */
604 display_info
->mouse_face_defer
= 1;
606 /* If F needs to be redrawn, simply forget about any prior mouse
608 if (FRAME_GARBAGED_P (f
))
609 display_info
->mouse_face_window
= Qnil
;
611 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
612 their mouse_face_p flag set, which means that they are always
613 unequal to rows in a desired matrix which never have that
614 flag set. So, rows containing mouse-face glyphs are never
615 scrolled, and we don't have to switch the mouse highlight off
616 here to prevent it from being scrolled. */
618 /* Can we tell that this update does not affect the window
619 where the mouse highlight is? If so, no need to turn off.
620 Likewise, don't do anything if the frame is garbaged;
621 in that case, the frame's current matrix that we would use
622 is all wrong, and we will redisplay that line anyway. */
623 if (!NILP (display_info
->mouse_face_window
)
624 && w
== XWINDOW (display_info
->mouse_face_window
))
628 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
629 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
632 if (i
< w
->desired_matrix
->nrows
)
633 clear_mouse_face (display_info
);
642 /* Draw a vertical window border to the right of window W if W doesn't
643 have vertical scroll bars. */
646 x_draw_vertical_border (w
)
649 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
651 /* Redraw borders between horizontally adjacent windows. Don't
652 do it for frames with vertical scroll bars because either the
653 right scroll bar of a window, or the left scroll bar of its
654 neighbor will suffice as a border. */
655 if (!WINDOW_RIGHTMOST_P (w
)
656 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
661 window_box_edges (w
, -1, (int *) &r
.left
, (int *) &r
.top
,
662 (int *) &r
.right
, (int *) &r
.bottom
);
663 r
.left
= r
.right
+ FRAME_X_RIGHT_FRINGE_WIDTH (f
);
664 r
.right
= r
.left
+ 1;
667 hdc
= get_frame_dc (f
);
668 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
669 release_frame_dc (f
, hdc
);
674 /* End update of window W (which is equal to updated_window).
676 Draw vertical borders between horizontally adjacent windows, and
677 display W's cursor if CURSOR_ON_P is non-zero.
679 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
680 glyphs in mouse-face were overwritten. In that case we have to
681 make sure that the mouse-highlight is properly redrawn.
683 W may be a menu bar pseudo-window in case we don't have X toolkit
684 support. Such windows don't have a cursor, so don't display it
688 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
690 int cursor_on_p
, mouse_face_overwritten_p
;
692 struct w32_display_info
*dpyinfo
693 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
695 if (!w
->pseudo_window_p
)
700 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
702 output_cursor
.x
, output_cursor
.y
);
704 x_draw_vertical_border (w
);
708 /* If a row with mouse-face was overwritten, arrange for
709 XTframe_up_to_date to redisplay the mouse highlight. */
710 if (mouse_face_overwritten_p
)
712 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
713 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
714 dpyinfo
->mouse_face_window
= Qnil
;
717 updated_window
= NULL
;
721 /* End update of frame F. This function is installed as a hook in
728 if (! FRAME_W32_P (f
))
731 /* Mouse highlight may be displayed again. */
732 FRAME_W32_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
736 /* This function is called from various places in xdisp.c whenever a
737 complete update has been performed. The global variable
738 updated_window is not available here. */
741 w32_frame_up_to_date (f
)
746 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
747 if (dpyinfo
->mouse_face_deferred_gc
748 || f
== dpyinfo
->mouse_face_mouse_frame
)
751 if (dpyinfo
->mouse_face_mouse_frame
)
752 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
753 dpyinfo
->mouse_face_mouse_x
,
754 dpyinfo
->mouse_face_mouse_y
);
755 dpyinfo
->mouse_face_deferred_gc
= 0;
762 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
763 arrow bitmaps, or clear the fringes if no bitmaps are required
764 before DESIRED_ROW is made current. The window being updated is
765 found in updated_window. This function is called from
766 update_window_line only if it is known that there are differences
767 between bitmaps to be drawn between current row and DESIRED_ROW. */
770 x_after_update_window_line (desired_row
)
771 struct glyph_row
*desired_row
;
773 struct window
*w
= updated_window
;
779 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
782 x_draw_row_fringe_bitmaps (w
, desired_row
);
786 /* When a window has disappeared, make sure that no rest of
787 full-width rows stays visible in the internal border. Could
788 check here if updated_window is the leftmost/rightmost window,
789 but I guess it's not worth doing since vertically split windows
790 are almost never used, internal border is rarely set, and the
791 overhead is very small. */
792 if (windows_or_buffers_changed
793 && desired_row
->full_width_p
794 && (f
= XFRAME (w
->frame
),
795 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
797 && (height
= desired_row
->visible_height
,
800 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
801 /* Internal border is drawn below the tool bar. */
802 if (WINDOWP (f
->tool_bar_window
)
803 && w
== XWINDOW (f
->tool_bar_window
))
808 HDC hdc
= get_frame_dc (f
);
809 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
810 w32_clear_area (f
, hdc
, f
->output_data
.w32
->pixel_width
- width
,
812 release_frame_dc (f
, hdc
);
819 /* Draw the bitmap WHICH in one of the left or right fringes of
820 window W. ROW is the glyph row for which to display the bitmap; it
821 determines the vertical position at which the bitmap has to be
825 w32_draw_fringe_bitmap (w
, hdc
, row
, which
, left_p
)
828 struct glyph_row
*row
;
829 enum fringe_bitmap_type which
;
832 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
833 Window window
= FRAME_W32_WINDOW (f
);
841 /* Must clip because of partially visible lines. */
842 w32_clip_to_row (w
, row
, hdc
, 1);
844 /* Convert row to frame coordinates. */
845 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
849 case NO_FRINGE_BITMAP
:
854 case LEFT_TRUNCATION_BITMAP
:
860 case OVERLAY_ARROW_BITMAP
:
866 case RIGHT_TRUNCATION_BITMAP
:
872 case CONTINUED_LINE_BITMAP
:
873 wd
= continued_width
;
874 h
= continued_height
;
875 pixmap
= continued_bmp
;
878 case CONTINUATION_LINE_BITMAP
:
879 wd
= continuation_width
;
880 h
= continuation_height
;
881 pixmap
= continuation_bmp
;
886 h
= zv_height
- (y
% zv_period
);
894 /* Clip bitmap if too high. */
898 /* Set dy to the offset in the row to start drawing the bitmap. */
899 dy
= (row
->height
- h
) / 2;
901 /* Draw the bitmap. */
902 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
903 PREPARE_FACE_FOR_DISPLAY (f
, face
);
905 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
910 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
911 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
912 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
914 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
915 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
917 /* If W has a vertical border to its left, don't draw over it. */
918 int border
= ((XFASTINT (w
->left
) > 0
919 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
921 b1
= (window_box_left (w
, -1)
922 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
924 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
929 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
930 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
931 x
= (window_box_right (w
, -1)
932 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
933 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
935 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
937 b1
= window_box_right (w
, -1);
938 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
944 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
946 w32_fill_area (f
, hdc
, face
->background
,
948 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
951 row
->visible_height
);
954 if (which
== NO_FRINGE_BITMAP
)
957 compat_hdc
= CreateCompatibleDC (hdc
);
960 horig_obj
= SelectObject (compat_hdc
, pixmap
);
961 SetTextColor (hdc
, face
->background
);
962 SetBkColor (hdc
, face
->foreground
);
964 BitBlt (hdc
, x
, y
+ dy
, wd
, h
, compat_hdc
, 0,
965 (which
== ZV_LINE_BITMAP
? (row
->y
% zv_period
) : 0),
968 SelectObject (compat_hdc
, horig_obj
);
969 DeleteDC (compat_hdc
);
974 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
975 function with input blocked. */
978 x_draw_row_fringe_bitmaps (w
, row
)
980 struct glyph_row
*row
;
982 struct frame
*f
= XFRAME (w
->frame
);
983 enum fringe_bitmap_type bitmap
;
986 xassert (interrupt_input_blocked
);
988 /* If row is completely invisible, because of vscrolling, we
989 don't have to draw anything. */
990 if (row
->visible_height
<= 0)
993 hdc
= get_frame_dc (f
);
995 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
997 /* Decide which bitmap to draw in the left fringe. */
998 if (row
->overlay_arrow_p
)
999 bitmap
= OVERLAY_ARROW_BITMAP
;
1000 else if (row
->truncated_on_left_p
)
1001 bitmap
= LEFT_TRUNCATION_BITMAP
;
1002 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1003 bitmap
= CONTINUATION_LINE_BITMAP
;
1004 else if (row
->indicate_empty_line_p
)
1005 bitmap
= ZV_LINE_BITMAP
;
1007 bitmap
= NO_FRINGE_BITMAP
;
1009 w32_draw_fringe_bitmap (w
, hdc
, row
, bitmap
, 1);
1012 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1014 /* Decide which bitmap to draw in the right fringe. */
1015 if (row
->truncated_on_right_p
)
1016 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1017 else if (row
->continued_p
)
1018 bitmap
= CONTINUED_LINE_BITMAP
;
1019 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1020 bitmap
= ZV_LINE_BITMAP
;
1022 bitmap
= NO_FRINGE_BITMAP
;
1024 w32_draw_fringe_bitmap (w
, hdc
, row
, bitmap
, 0);
1027 release_frame_dc (f
, hdc
);
1031 /* This is called when starting Emacs and when restarting after
1032 suspend. When starting Emacs, no window is mapped. And nothing
1033 must be done to Emacs's own window if it is suspended (though that
1037 w32_set_terminal_modes (void)
1041 /* This is called when exiting or suspending Emacs. Exiting will make
1042 the W32 windows go away, and suspending requires no action. */
1045 w32_reset_terminal_modes (void)
1051 /***********************************************************************
1053 ***********************************************************************/
1055 /* Set the global variable output_cursor to CURSOR. All cursor
1056 positions are relative to updated_window. */
1059 set_output_cursor (cursor
)
1060 struct cursor_pos
*cursor
;
1062 output_cursor
.hpos
= cursor
->hpos
;
1063 output_cursor
.vpos
= cursor
->vpos
;
1064 output_cursor
.x
= cursor
->x
;
1065 output_cursor
.y
= cursor
->y
;
1069 /* Set a nominal cursor position.
1071 HPOS and VPOS are column/row positions in a window glyph matrix. X
1072 and Y are window text area relative pixel positions.
1074 If this is done during an update, updated_window will contain the
1075 window that is being updated and the position is the future output
1076 cursor position for that window. If updated_window is null, use
1077 selected_window and display the cursor at the given position. */
1080 w32_cursor_to (vpos
, hpos
, y
, x
)
1081 int vpos
, hpos
, y
, x
;
1085 /* If updated_window is not set, work on selected_window. */
1089 w
= XWINDOW (selected_window
);
1091 /* Set the output cursor. */
1092 output_cursor
.hpos
= hpos
;
1093 output_cursor
.vpos
= vpos
;
1094 output_cursor
.x
= x
;
1095 output_cursor
.y
= y
;
1097 /* If not called as part of an update, really display the cursor.
1098 This will also set the cursor position of W. */
1099 if (updated_window
== NULL
)
1102 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1109 /***********************************************************************
1111 ***********************************************************************/
1113 /* Function prototypes of this page. */
1115 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1119 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1120 int, wchar_t *, int));
1121 static XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*,
1123 enum w32_char_font_type
));
1124 static enum w32_char_font_type
1125 w32_encode_char
P_ ((int, wchar_t *, struct font_info
*, int *));
1126 static void x_append_glyph
P_ ((struct it
*));
1127 static void x_append_composite_glyph
P_ ((struct it
*));
1128 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1130 static void x_produce_glyphs
P_ ((struct it
*));
1131 static void x_produce_image_glyph
P_ ((struct it
*it
));
1134 /* Dealing with bits of wchar_t as if they were an XChar2B. */
1135 #define BUILD_WCHAR_T(byte1, byte2) \
1136 ((wchar_t)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff)))
1140 (((ch) & 0xff00) >> 8)
1146 /* Get metrics of character CHAR2B in FONT. Value is always non-null.
1147 If CHAR2B is not contained in FONT, the font's default character
1148 metric is returned. */
1151 w32_bdf_per_char_metric (font
, char2b
, dim
, pcm
)
1157 glyph_metric
* bdf_metric
;
1161 buf
[0] = (char)(*char2b
);
1164 buf
[0] = BYTE1 (*char2b
);
1165 buf
[1] = BYTE2 (*char2b
);
1168 bdf_metric
= w32_BDF_TextMetric (font
->bdf
, buf
, dim
);
1172 pcm
->width
= bdf_metric
->dwidth
;
1173 pcm
->lbearing
= bdf_metric
->bbox
;
1174 pcm
->rbearing
= bdf_metric
->dwidth
1175 - (bdf_metric
->bbox
+ bdf_metric
->bbw
);
1176 pcm
->ascent
= bdf_metric
->bboy
+ bdf_metric
->bbh
;
1177 pcm
->descent
= -bdf_metric
->bboy
;
1186 w32_native_per_char_metric (font
, char2b
, font_type
, pcm
)
1189 enum w32_char_font_type font_type
;
1192 HDC hdc
= GetDC (NULL
);
1194 BOOL retval
= FALSE
;
1196 xassert (font
&& char2b
);
1197 xassert (font
->hfont
);
1198 xassert (font_type
== UNICODE_FONT
|| font_type
== ANSI_FONT
);
1200 old_font
= SelectObject (hdc
, font
->hfont
);
1202 if ((font
->tm
.tmPitchAndFamily
& TMPF_TRUETYPE
) != 0)
1206 if (font_type
== UNICODE_FONT
)
1207 retval
= GetCharABCWidthsW (hdc
, *char2b
, *char2b
, &char_widths
);
1209 retval
= GetCharABCWidthsA (hdc
, *char2b
, *char2b
, &char_widths
);
1213 pcm
->width
= char_widths
.abcA
+ char_widths
.abcB
+ char_widths
.abcC
;
1214 pcm
->lbearing
= char_widths
.abcA
;
1215 pcm
->rbearing
= pcm
->width
- char_widths
.abcC
;
1216 pcm
->ascent
= FONT_BASE (font
);
1217 pcm
->descent
= FONT_DESCENT (font
);
1223 /* Either font is not a True-type font, or GetCharABCWidthsW
1224 failed (it is not supported on Windows 9x for instance), so we
1225 can't determine the full info we would like. All is not lost
1226 though - we can call GetTextExtentPoint32 to get rbearing and
1227 deduce width based on the font's per-string overhang. lbearing
1228 is assumed to be zero. */
1230 /* TODO: Some Thai characters (and other composites if Windows
1231 supports them) do have lbearing, and report their total width
1232 as zero. Need some way of handling them when
1233 GetCharABCWidthsW fails. */
1236 if (font_type
== UNICODE_FONT
)
1237 retval
= GetTextExtentPoint32W (hdc
, char2b
, 1, &sz
);
1239 retval
= GetTextExtentPoint32A (hdc
, (char*)char2b
, 1, &sz
);
1243 pcm
->width
= sz
.cx
- font
->tm
.tmOverhang
;
1244 pcm
->rbearing
= sz
.cx
;
1246 pcm
->ascent
= FONT_BASE (font
);
1247 pcm
->descent
= FONT_DESCENT (font
);
1252 if (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0)
1257 SelectObject (hdc
, old_font
);
1258 ReleaseDC (NULL
, hdc
);
1264 static XCharStruct
*
1265 w32_per_char_metric (font
, char2b
, font_type
)
1268 enum w32_char_font_type font_type
;
1270 /* The result metric information. */
1274 xassert (font
&& char2b
);
1275 xassert (font_type
!= UNKNOWN_FONT
);
1277 /* Handle the common cases quickly. */
1278 if (!font
->bdf
&& font
->per_char
== NULL
)
1279 /* TODO: determine whether char2b exists in font? */
1280 return &font
->max_bounds
;
1281 else if (!font
->bdf
&& *char2b
< 128)
1282 return &font
->per_char
[*char2b
];
1284 pcm
= &font
->scratch
;
1286 if (font_type
== BDF_1D_FONT
)
1287 retval
= w32_bdf_per_char_metric (font
, char2b
, 1, pcm
);
1288 else if (font_type
== BDF_2D_FONT
)
1289 retval
= w32_bdf_per_char_metric (font
, char2b
, 2, pcm
);
1291 retval
= w32_native_per_char_metric (font
, char2b
, font_type
, pcm
);
1300 w32_cache_char_metrics (font
)
1303 wchar_t char2b
= L
'x';
1305 /* Cache char metrics for the common cases. */
1308 /* TODO: determine whether font is fixed-pitch. */
1309 if (!w32_bdf_per_char_metric (font
, &char2b
, 1, &font
->max_bounds
))
1311 /* Use the font width and height as max bounds, as not all BDF
1312 fonts contain the letter 'x'. */
1313 font
->max_bounds
.width
= FONT_MAX_WIDTH (font
);
1314 font
->max_bounds
.lbearing
= -font
->bdf
->llx
;
1315 font
->max_bounds
.rbearing
= FONT_MAX_WIDTH (font
) - font
->bdf
->urx
;
1316 font
->max_bounds
.ascent
= FONT_BASE (font
);
1317 font
->max_bounds
.descent
= FONT_DESCENT (font
);
1322 if (((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
) != 0)
1323 /* Some fonts (eg DBCS fonts) are marked as fixed width even
1324 though they contain characters of different widths. */
1325 || (font
->tm
.tmMaxCharWidth
!= font
->tm
.tmAveCharWidth
))
1327 /* Font is not fixed pitch, so cache per_char info for the
1328 ASCII characters. It would be much more work, and probably
1329 not worth it, to cache other chars, since we may change
1330 between using Unicode and ANSI text drawing functions at
1334 font
->per_char
= xmalloc (128 * sizeof(XCharStruct
));
1335 for (i
= 0; i
< 128; i
++)
1338 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1339 &font
->per_char
[i
]);
1343 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1349 /* Determine if a font is double byte. */
1350 int w32_font_is_double_byte (XFontStruct
*font
)
1352 return font
->double_byte_p
;
1357 w32_use_unicode_for_codepage (codepage
)
1360 /* If the current codepage is supported, use Unicode for output. */
1361 return (w32_enable_unicode_output
1362 && codepage
!= CP_8BIT
1363 && (codepage
== CP_UNICODE
|| IsValidCodePage (codepage
)));
1366 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1367 the two-byte form of C. Encoding is returned in *CHAR2B. */
1369 static INLINE
enum w32_char_font_type
1370 w32_encode_char (c
, char2b
, font_info
, two_byte_p
)
1373 struct font_info
*font_info
;
1376 int charset
= CHAR_CHARSET (c
);
1380 XFontStruct
*font
= font_info
->font
;
1382 xassert (two_byte_p
);
1384 *two_byte_p
= w32_font_is_double_byte (font
);
1386 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1387 This may be either a program in a special encoder language or a
1389 if (font_info
->font_encoder
)
1391 /* It's a program. */
1392 struct ccl_program
*ccl
= font_info
->font_encoder
;
1394 if (CHARSET_DIMENSION (charset
) == 1)
1396 ccl
->reg
[0] = charset
;
1397 ccl
->reg
[1] = BYTE2 (*char2b
);
1401 ccl
->reg
[0] = charset
;
1402 ccl
->reg
[1] = BYTE1 (*char2b
);
1403 ccl
->reg
[2] = BYTE2 (*char2b
);
1406 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1408 /* We assume that MSBs are appropriately set/reset by CCL
1410 if (!*two_byte_p
) /* 1-byte font */
1411 *char2b
= BUILD_WCHAR_T (0, ccl
->reg
[1]);
1413 *char2b
= BUILD_WCHAR_T (ccl
->reg
[1], ccl
->reg
[2]);
1415 else if (font_info
->encoding
[charset
])
1417 /* Fixed encoding scheme. See fontset.h for the meaning of the
1418 encoding numbers. */
1419 int enc
= font_info
->encoding
[charset
];
1421 if ((enc
== 1 || enc
== 2)
1422 && CHARSET_DIMENSION (charset
) == 2)
1423 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
) | 0x80, BYTE2 (*char2b
));
1425 if (enc
== 1 || enc
== 3
1426 || (enc
== 4 && CHARSET_DIMENSION (charset
) == 1))
1427 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
), BYTE2 (*char2b
) | 0x80);
1432 ENCODE_SJIS (BYTE1 (*char2b
), BYTE2 (*char2b
),
1434 *char2b
= BUILD_WCHAR_T (sjis1
, sjis2
);
1437 codepage
= font_info
->codepage
;
1439 /* If charset is not ASCII or Latin-1, may need to move it into
1441 if ( font
&& !font
->bdf
&& w32_use_unicode_for_codepage (codepage
)
1442 && charset
!= CHARSET_ASCII
&& charset
!= charset_latin_iso8859_1
1443 && charset
!= CHARSET_8_BIT_CONTROL
&& charset
!= CHARSET_8_BIT_GRAPHIC
)
1446 temp
[0] = BYTE1 (*char2b
);
1447 temp
[1] = BYTE2 (*char2b
);
1449 if (codepage
!= CP_UNICODE
)
1452 MultiByteToWideChar (codepage
, 0, temp
, 2, char2b
, 1);
1454 MultiByteToWideChar (codepage
, 0, temp
+1, 1, char2b
, 1);
1460 return UNKNOWN_FONT
;
1461 else if (font
->bdf
&& CHARSET_DIMENSION (charset
) == 1)
1466 return UNICODE_FONT
;
1472 /* Get face and two-byte form of character C in face FACE_ID on frame
1473 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1474 means we want to display multibyte text. Value is a pointer to a
1475 realized face that is ready for display. */
1477 static INLINE
struct face
*
1478 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1484 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1488 /* Unibyte case. We don't have to encode, but we have to make
1489 sure to use a face suitable for unibyte. */
1490 *char2b
= BUILD_WCHAR_T (0, c
);
1491 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1492 face
= FACE_FROM_ID (f
, face_id
);
1494 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1496 /* Case of ASCII in a face known to fit ASCII. */
1497 *char2b
= BUILD_WCHAR_T (0, c
);
1501 int c1
, c2
, charset
;
1503 /* Split characters into bytes. If c2 is -1 afterwards, C is
1504 really a one-byte character so that byte1 is zero. */
1505 SPLIT_CHAR (c
, charset
, c1
, c2
);
1507 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1509 *char2b
= BUILD_WCHAR_T (0, c1
);
1511 /* Maybe encode the character in *CHAR2B. */
1512 if (face
->font
!= NULL
)
1514 struct font_info
*font_info
1515 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1517 w32_encode_char (c
, char2b
, font_info
, &multibyte_p
);
1521 /* Make sure X resources of the face are allocated. */
1522 xassert (face
!= NULL
);
1523 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1529 /* Get face and two-byte form of character glyph GLYPH on frame F.
1530 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1531 a pointer to a realized face that is ready for display. */
1533 static INLINE
struct face
*
1534 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1536 struct glyph
*glyph
;
1543 xassert (glyph
->type
== CHAR_GLYPH
);
1544 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1549 two_byte_p
= &dummy
;
1551 if (!glyph
->multibyte_p
)
1553 /* Unibyte case. We don't have to encode, but we have to make
1554 sure to use a face suitable for unibyte. */
1555 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1557 else if (glyph
->u
.ch
< 128
1558 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1560 /* Case of ASCII in a face known to fit ASCII. */
1561 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1565 int c1
, c2
, charset
;
1567 /* Split characters into bytes. If c2 is -1 afterwards, C is
1568 really a one-byte character so that byte1 is zero. */
1569 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1571 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1573 *char2b
= BUILD_WCHAR_T (0, c1
);
1575 /* Maybe encode the character in *CHAR2B. */
1576 if (charset
!= CHARSET_ASCII
)
1578 struct font_info
*font_info
1579 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1582 glyph
->w32_font_type
1583 = w32_encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
1588 /* Make sure X resources of the face are allocated. */
1589 xassert (face
!= NULL
);
1590 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1595 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1596 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1602 struct glyph
*glyph
;
1603 enum glyph_row_area area
= it
->area
;
1605 xassert (it
->glyph_row
);
1606 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1608 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1609 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1611 glyph
->charpos
= CHARPOS (it
->position
);
1612 glyph
->object
= it
->object
;
1613 glyph
->pixel_width
= it
->pixel_width
;
1614 glyph
->voffset
= it
->voffset
;
1615 glyph
->type
= CHAR_GLYPH
;
1616 glyph
->multibyte_p
= it
->multibyte_p
;
1617 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1618 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1619 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1620 || it
->phys_descent
> it
->descent
);
1621 glyph
->padding_p
= 0;
1622 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1623 glyph
->face_id
= it
->face_id
;
1624 glyph
->u
.ch
= it
->char_to_display
;
1625 glyph
->w32_font_type
= UNKNOWN_FONT
;
1626 ++it
->glyph_row
->used
[area
];
1630 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1631 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1634 x_append_composite_glyph (it
)
1637 struct glyph
*glyph
;
1638 enum glyph_row_area area
= it
->area
;
1640 xassert (it
->glyph_row
);
1642 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1643 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1645 glyph
->charpos
= CHARPOS (it
->position
);
1646 glyph
->object
= it
->object
;
1647 glyph
->pixel_width
= it
->pixel_width
;
1648 glyph
->voffset
= it
->voffset
;
1649 glyph
->type
= COMPOSITE_GLYPH
;
1650 glyph
->multibyte_p
= it
->multibyte_p
;
1651 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1652 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1653 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1654 || it
->phys_descent
> it
->descent
);
1655 glyph
->padding_p
= 0;
1656 glyph
->glyph_not_available_p
= 0;
1657 glyph
->face_id
= it
->face_id
;
1658 glyph
->u
.cmp_id
= it
->cmp_id
;
1659 glyph
->w32_font_type
= UNKNOWN_FONT
;
1660 ++it
->glyph_row
->used
[area
];
1665 /* Change IT->ascent and IT->height according to the setting of
1669 take_vertical_position_into_account (it
)
1674 if (it
->voffset
< 0)
1675 /* Increase the ascent so that we can display the text higher
1677 it
->ascent
+= abs (it
->voffset
);
1679 /* Increase the descent so that we can display the text lower
1681 it
->descent
+= it
->voffset
;
1686 /* Produce glyphs/get display metrics for the image IT is loaded with.
1687 See the description of struct display_iterator in dispextern.h for
1688 an overview of struct display_iterator. */
1691 x_produce_image_glyph (it
)
1697 xassert (it
->what
== IT_IMAGE
);
1699 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1700 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1703 /* Make sure X resources of the face and image are loaded. */
1704 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1705 prepare_image_for_display (it
->f
, img
);
1707 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1708 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1709 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1713 if (face
->box
!= FACE_NO_BOX
)
1715 if (face
->box_line_width
> 0)
1717 it
->ascent
+= face
->box_line_width
;
1718 it
->descent
+= face
->box_line_width
;
1721 if (it
->start_of_box_run_p
)
1722 it
->pixel_width
+= abs (face
->box_line_width
);
1723 if (it
->end_of_box_run_p
)
1724 it
->pixel_width
+= abs (face
->box_line_width
);
1727 take_vertical_position_into_account (it
);
1731 struct glyph
*glyph
;
1732 enum glyph_row_area area
= it
->area
;
1734 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1735 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1737 glyph
->charpos
= CHARPOS (it
->position
);
1738 glyph
->object
= it
->object
;
1739 glyph
->pixel_width
= it
->pixel_width
;
1740 glyph
->voffset
= it
->voffset
;
1741 glyph
->type
= IMAGE_GLYPH
;
1742 glyph
->multibyte_p
= it
->multibyte_p
;
1743 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1744 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1745 glyph
->overlaps_vertically_p
= 0;
1746 glyph
->padding_p
= 0;
1747 glyph
->glyph_not_available_p
= 0;
1748 glyph
->face_id
= it
->face_id
;
1749 glyph
->u
.img_id
= img
->id
;
1750 glyph
->w32_font_type
= UNKNOWN_FONT
;
1751 ++it
->glyph_row
->used
[area
];
1757 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1758 of the glyph, WIDTH and HEIGHT are the width and height of the
1759 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1760 ascent of the glyph (0 <= ASCENT <= 1). */
1763 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1769 struct glyph
*glyph
;
1770 enum glyph_row_area area
= it
->area
;
1772 xassert (ascent
>= 0 && ascent
<= 1);
1774 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1775 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1777 glyph
->charpos
= CHARPOS (it
->position
);
1778 glyph
->object
= object
;
1779 glyph
->pixel_width
= width
;
1780 glyph
->voffset
= it
->voffset
;
1781 glyph
->type
= STRETCH_GLYPH
;
1782 glyph
->multibyte_p
= it
->multibyte_p
;
1783 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1784 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1785 glyph
->overlaps_vertically_p
= 0;
1786 glyph
->padding_p
= 0;
1787 glyph
->glyph_not_available_p
= 0;
1788 glyph
->face_id
= it
->face_id
;
1789 glyph
->u
.stretch
.ascent
= height
* ascent
;
1790 glyph
->u
.stretch
.height
= height
;
1791 glyph
->w32_font_type
= UNKNOWN_FONT
;
1792 ++it
->glyph_row
->used
[area
];
1797 /* Produce a stretch glyph for iterator IT. IT->object is the value
1798 of the glyph property displayed. The value must be a list
1799 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1802 1. `:width WIDTH' specifies that the space should be WIDTH *
1803 canonical char width wide. WIDTH may be an integer or floating
1806 2. `:relative-width FACTOR' specifies that the width of the stretch
1807 should be computed from the width of the first character having the
1808 `glyph' property, and should be FACTOR times that width.
1810 3. `:align-to HPOS' specifies that the space should be wide enough
1811 to reach HPOS, a value in canonical character units.
1813 Exactly one of the above pairs must be present.
1815 4. `:height HEIGHT' specifies that the height of the stretch produced
1816 should be HEIGHT, measured in canonical character units.
1818 5. `:relative-height FACTOR' specifies that the height of the
1819 stretch should be FACTOR times the height of the characters having
1822 Either none or exactly one of 4 or 5 must be present.
1824 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1825 of the stretch should be used for the ascent of the stretch.
1826 ASCENT must be in the range 0 <= ASCENT <= 100. */
1829 ((INTEGERP (X) || FLOATP (X)) \
1835 x_produce_stretch_glyph (it
)
1838 /* (space :width WIDTH :height HEIGHT. */
1840 extern Lisp_Object Qspace
;
1842 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1843 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1844 extern Lisp_Object QCalign_to
;
1845 Lisp_Object prop
, plist
;
1846 double width
= 0, height
= 0, ascent
= 0;
1847 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1848 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1850 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1852 /* List should start with `space'. */
1853 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1854 plist
= XCDR (it
->object
);
1856 /* Compute the width of the stretch. */
1857 if (prop
= Fplist_get (plist
, QCwidth
),
1859 /* Absolute width `:width WIDTH' specified and valid. */
1860 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1861 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1864 /* Relative width `:relative-width FACTOR' specified and valid.
1865 Compute the width of the characters having the `glyph'
1868 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1871 if (it
->multibyte_p
)
1873 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1874 - IT_BYTEPOS (*it
));
1875 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1878 it2
.c
= *p
, it2
.len
= 1;
1880 it2
.glyph_row
= NULL
;
1881 it2
.what
= IT_CHARACTER
;
1882 x_produce_glyphs (&it2
);
1883 width
= NUMVAL (prop
) * it2
.pixel_width
;
1885 else if (prop
= Fplist_get (plist
, QCalign_to
),
1887 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1889 /* Nothing specified -> width defaults to canonical char width. */
1890 width
= CANON_X_UNIT (it
->f
);
1892 /* Compute height. */
1893 if (prop
= Fplist_get (plist
, QCheight
),
1895 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1896 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1898 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1900 height
= FONT_HEIGHT (font
);
1902 /* Compute percentage of height used for ascent. If
1903 `:ascent ASCENT' is present and valid, use that. Otherwise,
1904 derive the ascent from the font in use. */
1905 if (prop
= Fplist_get (plist
, QCascent
),
1906 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1907 ascent
= NUMVAL (prop
) / 100.0;
1909 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
1918 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1919 if (!STRINGP (object
))
1920 object
= it
->w
->buffer
;
1921 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1924 it
->pixel_width
= width
;
1925 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1926 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1929 if (face
->box
!= FACE_NO_BOX
)
1931 if (face
->box_line_width
> 0)
1933 it
->ascent
+= face
->box_line_width
;
1934 it
->descent
+= face
->box_line_width
;
1937 if (it
->start_of_box_run_p
)
1938 it
->pixel_width
+= abs (face
->box_line_width
);
1939 if (it
->end_of_box_run_p
)
1940 it
->pixel_width
+= abs (face
->box_line_width
);
1943 take_vertical_position_into_account (it
);
1946 /* Return proper value to be used as baseline offset of font that has
1947 ASCENT and DESCENT to draw characters by the font at the vertical
1948 center of the line of frame F.
1950 Here, out task is to find the value of BOFF in the following figure;
1952 -------------------------+-----------+-
1953 -+-+---------+-+ | |
1955 | | | | F_ASCENT F_HEIGHT
1958 | | |-|-+------+-----------|------- baseline
1960 | |---------|-+-+ | |
1962 -+-+---------+-+ F_DESCENT |
1963 -------------------------+-----------+-
1965 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1966 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1967 DESCENT = FONT->descent
1968 HEIGHT = FONT_HEIGHT (FONT)
1969 F_DESCENT = (F->output_data.x->font->descent
1970 - F->output_data.x->baseline_offset)
1971 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1974 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1975 (FONT_DESCENT (FONT) \
1976 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1977 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1978 - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
1980 /* Produce glyphs/get display metrics for the display element IT is
1981 loaded with. See the description of struct display_iterator in
1982 dispextern.h for an overview of struct display_iterator. */
1985 x_produce_glyphs (it
)
1988 it
->glyph_not_available_p
= 0;
1990 if (it
->what
== IT_CHARACTER
)
1994 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1996 int font_not_found_p
;
1997 struct font_info
*font_info
;
1998 int boff
; /* baseline offset */
1999 /* We may change it->multibyte_p upon unibyte<->multibyte
2000 conversion. So, save the current value now and restore it
2003 Note: It seems that we don't have to record multibyte_p in
2004 struct glyph because the character code itself tells if or
2005 not the character is multibyte. Thus, in the future, we must
2006 consider eliminating the field `multibyte_p' in the struct
2009 int saved_multibyte_p
= it
->multibyte_p
;
2011 /* Maybe translate single-byte characters to multibyte, or the
2013 it
->char_to_display
= it
->c
;
2014 if (!ASCII_BYTE_P (it
->c
))
2016 if (unibyte_display_via_language_environment
2017 && SINGLE_BYTE_CHAR_P (it
->c
)
2019 || !NILP (Vnonascii_translation_table
)))
2021 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2022 it
->multibyte_p
= 1;
2023 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2024 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2026 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
2027 && !it
->multibyte_p
)
2029 it
->multibyte_p
= 1;
2030 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2031 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2035 /* Get font to use. Encode IT->char_to_display. */
2036 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2037 it
->face_id
, &char2b
,
2041 /* When no suitable font found, use the default font. */
2042 font_not_found_p
= font
== NULL
;
2043 if (font_not_found_p
)
2045 font
= FRAME_FONT (it
->f
);
2046 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2051 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2052 boff
= font_info
->baseline_offset
;
2053 if (font_info
->vertical_centering
)
2054 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2057 if (it
->char_to_display
>= ' '
2058 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
2060 /* Either unibyte or ASCII. */
2065 pcm
= w32_per_char_metric (font
, &char2b
,
2066 font
->bdf
? BDF_1D_FONT
: ANSI_FONT
);
2067 it
->ascent
= FONT_BASE (font
) + boff
;
2068 it
->descent
= FONT_DESCENT (font
) - boff
;
2072 it
->phys_ascent
= pcm
->ascent
+ boff
;
2073 it
->phys_descent
= pcm
->descent
- boff
;
2074 it
->pixel_width
= pcm
->width
;
2078 it
->glyph_not_available_p
= 1;
2079 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2080 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2081 it
->pixel_width
= FONT_WIDTH (font
);
2084 /* If this is a space inside a region of text with
2085 `space-width' property, change its width. */
2086 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
2088 it
->pixel_width
*= XFLOATINT (it
->space_width
);
2090 /* If face has a box, add the box thickness to the character
2091 height. If character has a box line to the left and/or
2092 right, add the box line width to the character's width. */
2093 if (face
->box
!= FACE_NO_BOX
)
2095 int thick
= face
->box_line_width
;
2099 it
->ascent
+= thick
;
2100 it
->descent
+= thick
;
2105 if (it
->start_of_box_run_p
)
2106 it
->pixel_width
+= thick
;
2107 if (it
->end_of_box_run_p
)
2108 it
->pixel_width
+= thick
;
2111 /* If face has an overline, add the height of the overline
2112 (1 pixel) and a 1 pixel margin to the character height. */
2113 if (face
->overline_p
)
2116 take_vertical_position_into_account (it
);
2118 /* If we have to actually produce glyphs, do it. */
2123 /* Translate a space with a `space-width' property
2124 into a stretch glyph. */
2125 double ascent
= (double) FONT_BASE (font
)
2126 / FONT_HEIGHT (font
);
2127 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2128 it
->ascent
+ it
->descent
, ascent
);
2131 x_append_glyph (it
);
2133 /* If characters with lbearing or rbearing are displayed
2134 in this line, record that fact in a flag of the
2135 glyph row. This is used to optimize X output code. */
2136 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
2137 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2140 else if (it
->char_to_display
== '\n')
2142 /* A newline has no width but we need the height of the line. */
2143 it
->pixel_width
= 0;
2145 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2146 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2148 if (face
->box
!= FACE_NO_BOX
2149 && face
->box_line_width
> 0)
2151 it
->ascent
+= face
->box_line_width
;
2152 it
->descent
+= face
->box_line_width
;
2155 else if (it
->char_to_display
== '\t')
2157 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
2158 int x
= it
->current_x
+ it
->continuation_lines_width
;
2159 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
2161 /* If the distance from the current position to the next tab
2162 stop is less than a canonical character width, use the
2163 tab stop after that. */
2164 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
2165 next_tab_x
+= tab_width
;
2167 it
->pixel_width
= next_tab_x
- x
;
2169 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2170 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2174 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2175 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2176 it
->ascent
+ it
->descent
, ascent
);
2181 /* A multi-byte character.
2182 If we found a font, this font should give us the right
2183 metrics. If we didn't find a font, use the frame's
2184 default font and calculate the width of the character
2185 from the charset width; this is what old redisplay code
2187 enum w32_char_font_type type
;
2189 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2194 type
= UNICODE_FONT
;
2196 pcm
= w32_per_char_metric (font
, &char2b
, type
);
2198 if (font_not_found_p
|| !pcm
)
2200 int charset
= CHAR_CHARSET (it
->char_to_display
);
2202 it
->glyph_not_available_p
= 1;
2203 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2204 * CHARSET_WIDTH (charset
));
2205 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2206 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2210 it
->pixel_width
= pcm
->width
;
2211 it
->phys_ascent
= pcm
->ascent
+ boff
;
2212 it
->phys_descent
= pcm
->descent
- boff
;
2214 && (pcm
->lbearing
< 0
2215 || pcm
->rbearing
> pcm
->width
))
2216 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2219 it
->ascent
= FONT_BASE (font
) + boff
;
2220 it
->descent
= FONT_DESCENT (font
) - boff
;
2221 if (face
->box
!= FACE_NO_BOX
)
2223 int thick
= face
->box_line_width
;
2227 it
->ascent
+= thick
;
2228 it
->descent
+= thick
;
2233 if (it
->start_of_box_run_p
)
2234 it
->pixel_width
+= thick
;
2235 if (it
->end_of_box_run_p
)
2236 it
->pixel_width
+= thick
;
2239 /* If face has an overline, add the height of the overline
2240 (1 pixel) and a 1 pixel margin to the character height. */
2241 if (face
->overline_p
)
2244 take_vertical_position_into_account (it
);
2247 x_append_glyph (it
);
2249 it
->multibyte_p
= saved_multibyte_p
;
2251 else if (it
->what
== IT_COMPOSITION
)
2253 /* Note: A composition is represented as one glyph in the
2254 glyph matrix. There are no padding glyphs. */
2257 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2259 int font_not_found_p
;
2260 struct font_info
*font_info
;
2261 int boff
; /* baseline offset */
2262 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2264 /* Maybe translate single-byte characters to multibyte. */
2265 it
->char_to_display
= it
->c
;
2266 if (unibyte_display_via_language_environment
2267 && SINGLE_BYTE_CHAR_P (it
->c
)
2270 && !NILP (Vnonascii_translation_table
))))
2272 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2275 /* Get face and font to use. Encode IT->char_to_display. */
2276 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2277 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2278 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2279 it
->face_id
, &char2b
, it
->multibyte_p
);
2282 /* When no suitable font found, use the default font. */
2283 font_not_found_p
= font
== NULL
;
2284 if (font_not_found_p
)
2286 font
= FRAME_FONT (it
->f
);
2287 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2292 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2293 boff
= font_info
->baseline_offset
;
2294 if (font_info
->vertical_centering
)
2295 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2298 /* There are no padding glyphs, so there is only one glyph to
2299 produce for the composition. Important is that pixel_width,
2300 ascent and descent are the values of what is drawn by
2301 draw_glyphs (i.e. the values of the overall glyphs composed). */
2304 /* If we have not yet calculated pixel size data of glyphs of
2305 the composition for the current face font, calculate them
2306 now. Theoretically, we have to check all fonts for the
2307 glyphs, but that requires much time and memory space. So,
2308 here we check only the font of the first glyph. This leads
2309 to incorrect display very rarely, and C-l (recenter) can
2310 correct the display anyway. */
2311 if (cmp
->font
!= (void *) font
)
2313 /* Ascent and descent of the font of the first character of
2314 this composition (adjusted by baseline offset). Ascent
2315 and descent of overall glyphs should not be less than
2316 them respectively. */
2317 int font_ascent
= FONT_BASE (font
) + boff
;
2318 int font_descent
= FONT_DESCENT (font
) - boff
;
2319 /* Bounding box of the overall glyphs. */
2320 int leftmost
, rightmost
, lowest
, highest
;
2321 int i
, width
, ascent
, descent
;
2322 enum w32_char_font_type font_type
;
2324 cmp
->font
= (void *) font
;
2326 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2327 font_type
= BDF_1D_FONT
;
2329 font_type
= BDF_2D_FONT
;
2331 font_type
= UNICODE_FONT
;
2333 /* Initialize the bounding box. */
2335 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2338 ascent
= pcm
->ascent
;
2339 descent
= pcm
->descent
;
2343 width
= FONT_WIDTH (font
);
2344 ascent
= FONT_BASE (font
);
2345 descent
= FONT_DESCENT (font
);
2349 lowest
= - descent
+ boff
;
2350 highest
= ascent
+ boff
;
2354 && font_info
->default_ascent
2355 && CHAR_TABLE_P (Vuse_default_ascent
)
2356 && !NILP (Faref (Vuse_default_ascent
,
2357 make_number (it
->char_to_display
))))
2358 highest
= font_info
->default_ascent
+ boff
;
2360 /* Draw the first glyph at the normal position. It may be
2361 shifted to right later if some other glyphs are drawn at
2363 cmp
->offsets
[0] = 0;
2364 cmp
->offsets
[1] = boff
;
2366 /* Set cmp->offsets for the remaining glyphs. */
2367 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2369 int left
, right
, btm
, top
;
2370 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2371 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2373 face
= FACE_FROM_ID (it
->f
, face_id
);
2374 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2379 font
= FRAME_FONT (it
->f
);
2380 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2386 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2387 boff
= font_info
->baseline_offset
;
2388 if (font_info
->vertical_centering
)
2389 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2392 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (ch
)) == 1)
2393 font_type
= BDF_1D_FONT
;
2395 font_type
= BDF_2D_FONT
;
2397 font_type
= UNICODE_FONT
;
2400 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2403 ascent
= pcm
->ascent
;
2404 descent
= pcm
->descent
;
2408 width
= FONT_WIDTH (font
);
2413 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2415 /* Relative composition with or without
2417 left
= (leftmost
+ rightmost
- width
) / 2;
2418 btm
= - descent
+ boff
;
2419 if (font_info
&& font_info
->relative_compose
2420 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2421 || NILP (Faref (Vignore_relative_composition
,
2422 make_number (ch
)))))
2425 if (- descent
>= font_info
->relative_compose
)
2426 /* One extra pixel between two glyphs. */
2428 else if (ascent
<= 0)
2429 /* One extra pixel between two glyphs. */
2430 btm
= lowest
- 1 - ascent
- descent
;
2435 /* A composition rule is specified by an integer
2436 value that encodes global and new reference
2437 points (GREF and NREF). GREF and NREF are
2438 specified by numbers as below:
2446 ---3---4---5--- baseline
2448 6---7---8 -- descent
2450 int rule
= COMPOSITION_RULE (cmp
, i
);
2451 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2453 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2454 grefx
= gref
% 3, nrefx
= nref
% 3;
2455 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2458 + grefx
* (rightmost
- leftmost
) / 2
2459 - nrefx
* width
/ 2);
2460 btm
= ((grefy
== 0 ? highest
2462 : grefy
== 2 ? lowest
2463 : (highest
+ lowest
) / 2)
2464 - (nrefy
== 0 ? ascent
+ descent
2465 : nrefy
== 1 ? descent
- boff
2467 : (ascent
+ descent
) / 2));
2470 cmp
->offsets
[i
* 2] = left
;
2471 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2473 /* Update the bounding box of the overall glyphs. */
2474 right
= left
+ width
;
2475 top
= btm
+ descent
+ ascent
;
2476 if (left
< leftmost
)
2478 if (right
> rightmost
)
2486 /* If there are glyphs whose x-offsets are negative,
2487 shift all glyphs to the right and make all x-offsets
2491 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2492 cmp
->offsets
[i
* 2] -= leftmost
;
2493 rightmost
-= leftmost
;
2496 cmp
->pixel_width
= rightmost
;
2497 cmp
->ascent
= highest
;
2498 cmp
->descent
= - lowest
;
2499 if (cmp
->ascent
< font_ascent
)
2500 cmp
->ascent
= font_ascent
;
2501 if (cmp
->descent
< font_descent
)
2502 cmp
->descent
= font_descent
;
2505 it
->pixel_width
= cmp
->pixel_width
;
2506 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2507 it
->descent
= it
->phys_descent
= cmp
->descent
;
2509 if (face
->box
!= FACE_NO_BOX
)
2511 int thick
= face
->box_line_width
;
2515 it
->ascent
+= thick
;
2516 it
->descent
+= thick
;
2521 if (it
->start_of_box_run_p
)
2522 it
->pixel_width
+= thick
;
2523 if (it
->end_of_box_run_p
)
2524 it
->pixel_width
+= thick
;
2527 /* If face has an overline, add the height of the overline
2528 (1 pixel) and a 1 pixel margin to the character height. */
2529 if (face
->overline_p
)
2532 take_vertical_position_into_account (it
);
2535 x_append_composite_glyph (it
);
2537 else if (it
->what
== IT_IMAGE
)
2538 x_produce_image_glyph (it
);
2539 else if (it
->what
== IT_STRETCH
)
2540 x_produce_stretch_glyph (it
);
2542 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2543 because this isn't true for images with `:ascent 100'. */
2544 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2545 if (it
->area
== TEXT_AREA
)
2546 it
->current_x
+= it
->pixel_width
;
2548 it
->descent
+= it
->extra_line_spacing
;
2550 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2551 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2552 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2553 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2557 /* Estimate the pixel height of the mode or top line on frame F.
2558 FACE_ID specifies what line's height to estimate. */
2561 x_estimate_mode_line_height (f
, face_id
)
2563 enum face_id face_id
;
2565 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2567 /* This function is called so early when Emacs starts that the face
2568 cache and mode line face are not yet initialized. */
2569 if (FRAME_FACE_CACHE (f
))
2571 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2575 height
= FONT_HEIGHT (face
->font
);
2576 if (face
->box_line_width
> 0)
2577 height
+= 2 * face
->box_line_width
;
2585 /***********************************************************************
2587 ***********************************************************************/
2589 /* A sequence of glyphs to be drawn in the same face.
2591 This data structure is not really completely X specific, so it
2592 could possibly, at least partially, be useful for other systems. It
2593 is currently not part of the external redisplay interface because
2594 it's not clear what other systems will need. */
2598 /* X-origin of the string. */
2601 /* Y-origin and y-position of the base line of this string. */
2604 /* The width of the string, not including a face extension. */
2607 /* The width of the string, including a face extension. */
2608 int background_width
;
2610 /* The height of this string. This is the height of the line this
2611 string is drawn in, and can be different from the height of the
2612 font the string is drawn in. */
2615 /* Number of pixels this string overwrites in front of its x-origin.
2616 This number is zero if the string has an lbearing >= 0; it is
2617 -lbearing, if the string has an lbearing < 0. */
2620 /* Number of pixels this string overwrites past its right-most
2621 nominal x-position, i.e. x + width. Zero if the string's
2622 rbearing is <= its nominal width, rbearing - width otherwise. */
2625 /* The frame on which the glyph string is drawn. */
2628 /* The window on which the glyph string is drawn. */
2631 /* X display and window for convenience. */
2634 /* The glyph row for which this string was built. It determines the
2635 y-origin and height of the string. */
2636 struct glyph_row
*row
;
2638 /* The area within row. */
2639 enum glyph_row_area area
;
2641 /* Characters to be drawn, and number of characters. */
2645 /* A face-override for drawing cursors, mouse face and similar. */
2646 enum draw_glyphs_face hl
;
2648 /* Face in which this string is to be drawn. */
2651 /* Font in which this string is to be drawn. */
2654 /* Font info for this string. */
2655 struct font_info
*font_info
;
2657 /* Non-null means this string describes (part of) a composition.
2658 All characters from char2b are drawn composed. */
2659 struct composition
*cmp
;
2661 /* Index of this glyph string's first character in the glyph
2662 definition of CMP. If this is zero, this glyph string describes
2663 the first character of a composition. */
2666 /* 1 means this glyph strings face has to be drawn to the right end
2667 of the window's drawing area. */
2668 unsigned extends_to_end_of_line_p
: 1;
2670 /* 1 means the background of this string has been drawn. */
2671 unsigned background_filled_p
: 1;
2673 /* 1 means glyph string must be drawn with 16-bit functions. */
2674 unsigned two_byte_p
: 1;
2676 /* 1 means that the original font determined for drawing this glyph
2677 string could not be loaded. The member `font' has been set to
2678 the frame's default font in this case. */
2679 unsigned font_not_found_p
: 1;
2681 /* 1 means that the face in which this glyph string is drawn has a
2683 unsigned stippled_p
: 1;
2685 /* 1 means only the foreground of this glyph string must be drawn,
2686 and we should use the physical height of the line this glyph
2687 string appears in as clip rect. */
2688 unsigned for_overlaps_p
: 1;
2690 /* The GC to use for drawing this glyph string. */
2695 /* A pointer to the first glyph in the string. This glyph
2696 corresponds to char2b[0]. Needed to draw rectangles if
2697 font_not_found_p is 1. */
2698 struct glyph
*first_glyph
;
2700 /* Image, if any. */
2703 struct glyph_string
*next
, *prev
;
2707 /* Encapsulate the different ways of displaying text under W32. */
2709 void W32_TEXTOUT (s
, x
, y
,chars
,nchars
)
2710 struct glyph_string
* s
;
2715 int charset_dim
= w32_font_is_double_byte (s
->gc
->font
) ? 2 : 1;
2716 if (s
->gc
->font
->bdf
)
2717 w32_BDF_TextOut (s
->gc
->font
->bdf
, s
->hdc
,
2718 x
, y
, (char *) chars
, charset_dim
,
2719 nchars
* charset_dim
, 0);
2720 else if (s
->first_glyph
->w32_font_type
== UNICODE_FONT
)
2721 ExtTextOutW (s
->hdc
, x
, y
, 0, NULL
, chars
, nchars
, NULL
);
2723 ExtTextOut (s
->hdc
, x
, y
, 0, NULL
, (char *) chars
,
2724 nchars
* charset_dim
, NULL
);
2730 x_dump_glyph_string (s
)
2731 struct glyph_string
*s
;
2733 fprintf (stderr
, "glyph string\n");
2734 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2735 s
->x
, s
->y
, s
->width
, s
->height
);
2736 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2737 fprintf (stderr
, " hl = %d\n", s
->hl
);
2738 fprintf (stderr
, " left overhang = %d, right = %d\n",
2739 s
->left_overhang
, s
->right_overhang
);
2740 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2741 fprintf (stderr
, " extends to end of line = %d\n",
2742 s
->extends_to_end_of_line_p
);
2743 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2744 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2747 #endif /* GLYPH_DEBUG */
2751 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2752 struct glyph_string
**,
2753 struct glyph_string
*,
2754 struct glyph_string
*));
2755 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2756 struct glyph_string
**,
2757 struct glyph_string
*,
2758 struct glyph_string
*));
2759 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2760 struct glyph_string
**,
2761 struct glyph_string
*));
2762 static int x_left_overwritten
P_ ((struct glyph_string
*));
2763 static int x_left_overwriting
P_ ((struct glyph_string
*));
2764 static int x_right_overwritten
P_ ((struct glyph_string
*));
2765 static int x_right_overwriting
P_ ((struct glyph_string
*));
2766 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2768 static void w32_init_glyph_string
P_ ((struct glyph_string
*, HDC hdc
,
2769 wchar_t *, struct window
*,
2771 enum glyph_row_area
, int,
2772 enum draw_glyphs_face
));
2773 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2774 enum glyph_row_area
, int, int,
2775 enum draw_glyphs_face
, int));
2776 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2777 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2778 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2780 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2781 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2782 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2783 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2784 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2785 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2786 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2787 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2788 static void w32_get_glyph_overhangs
P_ ((HDC hdc
, struct glyph
*,
2791 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2792 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
2793 static void w32_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2794 double, int, COLORREF
));
2795 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2796 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2797 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2798 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2799 static void w32_draw_image_foreground_1
P_ ((struct glyph_string
*, HBITMAP
));
2800 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2801 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2803 static void w32_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2804 int, int, int, int, RECT
*));
2805 static void w32_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2806 int, int, int, RECT
*));
2807 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2808 enum glyph_row_area
));
2809 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2811 enum glyph_row_area
, int, int));
2814 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2818 /* Append the list of glyph strings with head H and tail T to the list
2819 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2822 x_append_glyph_string_lists (head
, tail
, h
, t
)
2823 struct glyph_string
**head
, **tail
;
2824 struct glyph_string
*h
, *t
;
2838 /* Prepend the list of glyph strings with head H and tail T to the
2839 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2843 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2844 struct glyph_string
**head
, **tail
;
2845 struct glyph_string
*h
, *t
;
2859 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2860 Set *HEAD and *TAIL to the resulting list. */
2863 x_append_glyph_string (head
, tail
, s
)
2864 struct glyph_string
**head
, **tail
;
2865 struct glyph_string
*s
;
2867 s
->next
= s
->prev
= NULL
;
2868 x_append_glyph_string_lists (head
, tail
, s
, s
);
2872 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2877 struct glyph_string
*s
;
2879 if (s
->font
== FRAME_FONT (s
->f
)
2880 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2881 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2883 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
2886 /* Cursor on non-default face: must merge. */
2890 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
2891 xgcv
.foreground
= s
->face
->background
;
2893 /* If the glyph would be invisible, try a different foreground. */
2894 if (xgcv
.foreground
== xgcv
.background
)
2895 xgcv
.foreground
= s
->face
->foreground
;
2896 if (xgcv
.foreground
== xgcv
.background
)
2897 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
2898 if (xgcv
.foreground
== xgcv
.background
)
2899 xgcv
.foreground
= s
->face
->foreground
;
2901 /* Make sure the cursor is distinct from text in this face. */
2902 if (xgcv
.background
== s
->face
->background
2903 && xgcv
.foreground
== s
->face
->foreground
)
2905 xgcv
.background
= s
->face
->foreground
;
2906 xgcv
.foreground
= s
->face
->background
;
2909 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2910 xgcv
.font
= s
->font
;
2911 mask
= GCForeground
| GCBackground
| GCFont
;
2913 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2914 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2917 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2918 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
2920 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2925 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2928 x_set_mouse_face_gc (s
)
2929 struct glyph_string
*s
;
2934 /* What face has to be used last for the mouse face? */
2935 face_id
= FRAME_W32_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2936 face
= FACE_FROM_ID (s
->f
, face_id
);
2938 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2940 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2941 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2943 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2944 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2945 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2947 /* If font in this face is same as S->font, use it. */
2948 if (s
->font
== s
->face
->font
)
2949 s
->gc
= s
->face
->gc
;
2952 /* Otherwise construct scratch_cursor_gc with values from FACE
2957 xgcv
.background
= s
->face
->background
;
2958 xgcv
.foreground
= s
->face
->foreground
;
2959 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2960 xgcv
.font
= s
->font
;
2961 mask
= GCForeground
| GCBackground
| GCFont
;
2963 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2964 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2967 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2968 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
2970 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2973 xassert (s
->gc
!= 0);
2977 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2978 Faces to use in the mode line have already been computed when the
2979 matrix was built, so there isn't much to do, here. */
2982 x_set_mode_line_face_gc (s
)
2983 struct glyph_string
*s
;
2985 s
->gc
= s
->face
->gc
;
2989 /* Set S->gc of glyph string S for drawing that glyph string. Set
2990 S->stippled_p to a non-zero value if the face of S has a stipple
2994 x_set_glyph_string_gc (s
)
2995 struct glyph_string
*s
;
2997 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2999 if (s
->hl
== DRAW_NORMAL_TEXT
)
3001 s
->gc
= s
->face
->gc
;
3002 s
->stippled_p
= s
->face
->stipple
!= 0;
3004 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
3006 x_set_mode_line_face_gc (s
);
3007 s
->stippled_p
= s
->face
->stipple
!= 0;
3009 else if (s
->hl
== DRAW_CURSOR
)
3011 x_set_cursor_gc (s
);
3014 else if (s
->hl
== DRAW_MOUSE_FACE
)
3016 x_set_mouse_face_gc (s
);
3017 s
->stippled_p
= s
->face
->stipple
!= 0;
3019 else if (s
->hl
== DRAW_IMAGE_RAISED
3020 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3022 s
->gc
= s
->face
->gc
;
3023 s
->stippled_p
= s
->face
->stipple
!= 0;
3027 s
->gc
= s
->face
->gc
;
3028 s
->stippled_p
= s
->face
->stipple
!= 0;
3031 /* GC must have been set. */
3032 xassert (s
->gc
!= 0);
3036 /* Return in *R the clipping rectangle for glyph string S. */
3039 w32_get_glyph_string_clip_rect (s
, r
)
3040 struct glyph_string
*s
;
3043 int r_height
, r_width
;
3045 if (s
->row
->full_width_p
)
3047 /* Draw full-width. X coordinates are relative to S->w->left. */
3048 int canon_x
= CANON_X_UNIT (s
->f
);
3050 r
->left
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
3051 r_width
= XFASTINT (s
->w
->width
) * canon_x
;
3053 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
3055 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
3056 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
3060 r
->left
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
3062 /* Unless displaying a mode or menu bar line, which are always
3063 fully visible, clip to the visible part of the row. */
3064 if (s
->w
->pseudo_window_p
)
3065 r_height
= s
->row
->visible_height
;
3067 r_height
= s
->height
;
3071 /* This is a text line that may be partially visible. */
3072 r
->left
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
3073 r_width
= window_box_width (s
->w
, s
->area
);
3074 r_height
= s
->row
->visible_height
;
3077 /* If S draws overlapping rows, it's sufficient to use the top and
3078 bottom of the window for clipping because this glyph string
3079 intentionally draws over other lines. */
3080 if (s
->for_overlaps_p
)
3082 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3083 r_height
= window_text_bottom_y (s
->w
) - r
->top
;
3087 /* Don't use S->y for clipping because it doesn't take partially
3088 visible lines into account. For example, it can be negative for
3089 partially visible lines at the top of a window. */
3090 if (!s
->row
->full_width_p
3091 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
3092 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3094 r
->top
= max (0, s
->row
->y
);
3096 /* If drawing a tool-bar window, draw it over the internal border
3097 at the top of the window. */
3098 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
3099 r
->top
-= s
->f
->output_data
.w32
->internal_border_width
;
3102 r
->top
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->top
);
3104 r
->bottom
= r
->top
+ r_height
;
3105 r
->right
= r
->left
+ r_width
;
3109 /* Set clipping for output of glyph string S. S may be part of a mode
3110 line or menu if we don't have X toolkit support. */
3113 x_set_glyph_string_clipping (s
)
3114 struct glyph_string
*s
;
3117 w32_get_glyph_string_clip_rect (s
, &r
);
3118 w32_set_clip_rectangle (s
->hdc
, &r
);
3122 /* Compute left and right overhang of glyph string S. If S is a glyph
3123 string for a composition, assume overhangs don't exist. */
3126 x_compute_glyph_string_overhangs (s
)
3127 struct glyph_string
*s
;
3129 /* TODO: Windows does not appear to have a method for
3130 getting this info without getting the ABC widths for each
3131 individual character and working it out manually. */
3135 /* Compute overhangs and x-positions for glyph string S and its
3136 predecessors, or successors. X is the starting x-position for S.
3137 BACKWARD_P non-zero means process predecessors. */
3140 x_compute_overhangs_and_x (s
, x
, backward_p
)
3141 struct glyph_string
*s
;
3149 x_compute_glyph_string_overhangs (s
);
3159 x_compute_glyph_string_overhangs (s
);
3168 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
3169 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
3170 assumed to be zero. */
3173 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
)
3175 struct glyph
*glyph
;
3181 if (glyph
->type
== CHAR_GLYPH
)
3188 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
3192 && (pcm
= w32_per_char_metric (font
, &char2b
,
3193 glyph
->w32_font_type
)))
3195 if (pcm
->rbearing
> pcm
->width
)
3196 *right
= pcm
->rbearing
- pcm
->width
;
3197 if (pcm
->lbearing
< 0)
3198 *left
= -pcm
->lbearing
;
3205 x_get_glyph_overhangs (glyph
, f
, left
, right
)
3206 struct glyph
*glyph
;
3210 HDC hdc
= get_frame_dc (f
);
3211 /* Convert to unicode! */
3212 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
);
3213 release_frame_dc (f
, hdc
);
3217 /* Return the index of the first glyph preceding glyph string S that
3218 is overwritten by S because of S's left overhang. Value is -1
3219 if no glyphs are overwritten. */
3222 x_left_overwritten (s
)
3223 struct glyph_string
*s
;
3227 if (s
->left_overhang
)
3230 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3231 int first
= s
->first_glyph
- glyphs
;
3233 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3234 x
-= glyphs
[i
].pixel_width
;
3245 /* Return the index of the first glyph preceding glyph string S that
3246 is overwriting S because of its right overhang. Value is -1 if no
3247 glyph in front of S overwrites S. */
3250 x_left_overwriting (s
)
3251 struct glyph_string
*s
;
3254 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3255 int first
= s
->first_glyph
- glyphs
;
3259 for (i
= first
- 1; i
>= 0; --i
)
3262 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3265 x
-= glyphs
[i
].pixel_width
;
3272 /* Return the index of the last glyph following glyph string S that is
3273 not overwritten by S because of S's right overhang. Value is -1 if
3274 no such glyph is found. */
3277 x_right_overwritten (s
)
3278 struct glyph_string
*s
;
3282 if (s
->right_overhang
)
3285 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3286 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3287 int end
= s
->row
->used
[s
->area
];
3289 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3290 x
+= glyphs
[i
].pixel_width
;
3299 /* Return the index of the last glyph following glyph string S that
3300 overwrites S because of its left overhang. Value is negative
3301 if no such glyph is found. */
3304 x_right_overwriting (s
)
3305 struct glyph_string
*s
;
3308 int end
= s
->row
->used
[s
->area
];
3309 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3310 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3314 for (i
= first
; i
< end
; ++i
)
3317 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3320 x
+= glyphs
[i
].pixel_width
;
3327 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3330 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3331 struct glyph_string
*s
;
3339 /* Take clipping into account. */
3340 if (s
->gc
->clip_mask
== Rect
)
3342 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
3343 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
3344 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
3345 - s
->gc
->clip_rectangle
.left
);
3346 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
3347 - s
->gc
->clip_rectangle
.top
);
3350 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
3355 /* Draw the background of glyph_string S. If S->background_filled_p
3356 is non-zero don't draw it. FORCE_P non-zero means draw the
3357 background even if it wouldn't be drawn normally. This is used
3358 when a string preceding S draws into the background of S, or S
3359 contains the first component of a composition. */
3362 x_draw_glyph_string_background (s
, force_p
)
3363 struct glyph_string
*s
;
3366 /* Nothing to do if background has already been drawn or if it
3367 shouldn't be drawn in the first place. */
3368 if (!s
->background_filled_p
)
3370 int box_line_width
= max (s
->face
->box_line_width
, 0);
3372 #if 0 /* TODO: stipple */
3375 /* Fill background with a stipple pattern. */
3376 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3377 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3378 s
->y
+ box_line_width
,
3379 s
->background_width
,
3380 s
->height
- 2 * box_line_width
);
3381 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3382 s
->background_filled_p
= 1;
3386 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3387 || s
->font_not_found_p
3388 || s
->extends_to_end_of_line_p
3392 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3393 s
->background_width
,
3394 s
->height
- 2 * box_line_width
);
3395 s
->background_filled_p
= 1;
3401 /* Draw the foreground of glyph string S. */
3404 x_draw_glyph_string_foreground (s
)
3405 struct glyph_string
*s
;
3410 /* If first glyph of S has a left box line, start drawing the text
3411 of S to the right of that box line. */
3412 if (s
->face
->box
!= FACE_NO_BOX
3413 && s
->first_glyph
->left_box_line_p
)
3414 x
= s
->x
+ abs (s
->face
->box_line_width
);
3418 if (s
->for_overlaps_p
|| (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3419 SetBkMode (s
->hdc
, TRANSPARENT
);
3421 SetBkMode (s
->hdc
, OPAQUE
);
3423 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3424 SetBkColor (s
->hdc
, s
->gc
->background
);
3425 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3427 if (s
->font
&& s
->font
->hfont
)
3428 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3430 /* Draw characters of S as rectangles if S's font could not be
3432 if (s
->font_not_found_p
)
3434 for (i
= 0; i
< s
->nchars
; ++i
)
3436 struct glyph
*g
= s
->first_glyph
+ i
;
3438 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3440 x
+= g
->pixel_width
;
3445 char *char1b
= (char *) s
->char2b
;
3446 int boff
= s
->font_info
->baseline_offset
;
3448 if (s
->font_info
->vertical_centering
)
3449 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3451 /* If we can use 8-bit functions, condense S->char2b. */
3453 for (i
= 0; i
< s
->nchars
; ++i
)
3454 char1b
[i
] = BYTE2 (s
->char2b
[i
]);
3456 /* Draw text with TextOut and friends. */
3457 W32_TEXTOUT (s
, x
, s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3459 if (s
->font
&& s
->font
->hfont
)
3460 SelectObject (s
->hdc
, old_font
);
3463 /* Draw the foreground of composite glyph string S. */
3466 x_draw_composite_glyph_string_foreground (s
)
3467 struct glyph_string
*s
;
3472 /* If first glyph of S has a left box line, start drawing the text
3473 of S to the right of that box line. */
3474 if (s
->face
->box
!= FACE_NO_BOX
3475 && s
->first_glyph
->left_box_line_p
)
3476 x
= s
->x
+ abs (s
->face
->box_line_width
);
3480 /* S is a glyph string for a composition. S->gidx is the index of
3481 the first character drawn for glyphs of this composition.
3482 S->gidx == 0 means we are drawing the very first character of
3483 this composition. */
3485 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3486 SetBkColor (s
->hdc
, s
->gc
->background
);
3487 SetBkMode (s
->hdc
, TRANSPARENT
);
3488 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3490 if (s
->font
&& s
->font
->hfont
)
3491 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3493 /* Draw a rectangle for the composition if the font for the very
3494 first character of the composition could not be loaded. */
3495 if (s
->font_not_found_p
)
3498 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
3503 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3504 W32_TEXTOUT (s
, x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3505 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3508 if (s
->font
&& s
->font
->hfont
)
3509 SelectObject (s
->hdc
, old_font
);
3513 /* Brightness beyond which a color won't have its highlight brightness
3516 Nominally, highlight colors for `3d' faces are calculated by
3517 brightening an object's color by a constant scale factor, but this
3518 doesn't yield good results for dark colors, so for colors who's
3519 brightness is less than this value (on a scale of 0-255) have to
3520 use an additional additive factor.
3522 The value here is set so that the default menu-bar/mode-line color
3523 (grey75) will not have its highlights changed at all. */
3524 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
3527 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
3528 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3529 If this produces the same color as COLOR, try a color where all RGB
3530 values have DELTA added. Return the allocated color in *COLOR.
3531 DISPLAY is the X display, CMAP is the colormap to operate on.
3532 Value is non-zero if successful. */
3535 w32_alloc_lighter_color (f
, color
, factor
, delta
)
3544 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
3547 /* Change RGB values by specified FACTOR. Avoid overflow! */
3548 xassert (factor
>= 0);
3549 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
3550 min (0xff, factor
* GetGValue (*color
)),
3551 min (0xff, factor
* GetBValue (*color
)));
3553 /* Calculate brightness of COLOR. */
3554 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
3555 + GetBValue (*color
)) / 6;
3557 /* We only boost colors that are darker than
3558 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3559 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3560 /* Make an additive adjustment to NEW, because it's dark enough so
3561 that scaling by FACTOR alone isn't enough. */
3563 /* How far below the limit this color is (0 - 1, 1 being darker). */
3564 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3565 /* The additive adjustment. */
3566 int min_delta
= delta
* dimness
* factor
/ 2;
3569 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
3570 max (0, min (0xff, min_delta
- GetGValue (*color
))),
3571 max (0, min (0xff, min_delta
- GetBValue (*color
))));
3573 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
3574 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
3575 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
3579 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
3580 max (0, min (0xff, delta
+ GetGValue (*color
))),
3581 max (0, min (0xff, delta
+ GetBValue (*color
))));
3583 /* TODO: Map to palette and retry with delta if same? */
3584 /* TODO: Free colors (if using palette)? */
3595 /* Set up the foreground color for drawing relief lines of glyph
3596 string S. RELIEF is a pointer to a struct relief containing the GC
3597 with which lines will be drawn. Use a color that is FACTOR or
3598 DELTA lighter or darker than the relief's background which is found
3599 in S->f->output_data.x->relief_background. If such a color cannot
3600 be allocated, use DEFAULT_PIXEL, instead. */
3603 w32_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3605 struct relief
*relief
;
3608 COLORREF default_pixel
;
3611 struct w32_output
*di
= f
->output_data
.w32
;
3612 unsigned long mask
= GCForeground
;
3614 COLORREF background
= di
->relief_background
;
3615 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
3617 /* TODO: Free colors (if using palette)? */
3619 /* Allocate new color. */
3620 xgcv
.foreground
= default_pixel
;
3622 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
3624 relief
->allocated_p
= 1;
3625 xgcv
.foreground
= relief
->pixel
= pixel
;
3628 if (relief
->gc
== 0)
3630 #if 0 /* TODO: stipple */
3631 xgcv
.stipple
= dpyinfo
->gray
;
3634 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
3637 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
3641 /* Set up colors for the relief lines around glyph string S. */
3644 x_setup_relief_colors (s
)
3645 struct glyph_string
*s
;
3647 struct w32_output
*di
= s
->f
->output_data
.w32
;
3650 if (s
->face
->use_box_color_for_shadows_p
)
3651 color
= s
->face
->box_color
;
3652 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3654 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3655 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3657 color
= s
->gc
->background
;
3659 if (di
->white_relief
.gc
== 0
3660 || color
!= di
->relief_background
)
3662 di
->relief_background
= color
;
3663 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3664 WHITE_PIX_DEFAULT (s
->f
));
3665 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3666 BLACK_PIX_DEFAULT (s
->f
));
3671 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3672 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3673 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3674 relief. LEFT_P non-zero means draw a relief on the left side of
3675 the rectangle. RIGHT_P non-zero means draw a relief on the right
3676 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3680 w32_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3681 raised_p
, left_p
, right_p
, clip_rect
)
3683 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3688 HDC hdc
= get_frame_dc (f
);
3691 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3693 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3695 w32_set_clip_rectangle (hdc
, clip_rect
);
3698 for (i
= 0; i
< width
; ++i
)
3699 w32_fill_area (f
, hdc
, gc
.foreground
,
3700 left_x
+ i
* left_p
, top_y
+ i
,
3701 (right_x
+ 1 - i
* right_p
) - (left_x
+ i
* left_p
) + 1, 1);
3705 for (i
= 0; i
< width
; ++i
)
3706 w32_fill_area (f
, hdc
, gc
.foreground
,
3707 left_x
+ i
, top_y
+ i
, 1,
3708 (bottom_y
- i
) - (top_y
+ i
) + 2);
3711 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3713 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3716 for (i
= 0; i
< width
; ++i
)
3717 w32_fill_area (f
, hdc
, gc
.foreground
,
3718 left_x
+ i
* left_p
, bottom_y
- i
,
3719 (right_x
- i
* right_p
) - (left_x
+ i
* left_p
) + 2, 1);
3723 for (i
= 0; i
< width
; ++i
)
3724 w32_fill_area (f
, hdc
, gc
.foreground
,
3725 right_x
- i
, top_y
+ i
+ 1, 1,
3726 (bottom_y
- i
) - (top_y
+ i
));
3728 w32_set_clip_rectangle (hdc
, NULL
);
3730 release_frame_dc (f
, hdc
);
3734 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3735 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3736 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3737 left side of the rectangle. RIGHT_P non-zero means draw a line
3738 on the right side of the rectangle. CLIP_RECT is the clipping
3739 rectangle to use when drawing. */
3742 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3743 left_p
, right_p
, clip_rect
)
3744 struct glyph_string
*s
;
3745 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3748 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
3751 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3752 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3757 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3758 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3762 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3763 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3768 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3769 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3772 w32_set_clip_rectangle (s
->hdc
, NULL
);
3776 /* Draw a box around glyph string S. */
3779 x_draw_glyph_string_box (s
)
3780 struct glyph_string
*s
;
3782 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3783 int left_p
, right_p
;
3784 struct glyph
*last_glyph
;
3787 last_x
= window_box_right (s
->w
, s
->area
);
3788 if (s
->row
->full_width_p
3789 && !s
->w
->pseudo_window_p
)
3791 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
3792 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3793 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3796 /* The glyph that may have a right box line. */
3797 last_glyph
= (s
->cmp
|| s
->img
3799 : s
->first_glyph
+ s
->nchars
- 1);
3801 width
= abs (s
->face
->box_line_width
);
3802 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3804 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3806 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3808 bottom_y
= top_y
+ s
->height
- 1;
3810 left_p
= (s
->first_glyph
->left_box_line_p
3811 || (s
->hl
== DRAW_MOUSE_FACE
3813 || s
->prev
->hl
!= s
->hl
)));
3814 right_p
= (last_glyph
->right_box_line_p
3815 || (s
->hl
== DRAW_MOUSE_FACE
3817 || s
->next
->hl
!= s
->hl
)));
3819 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3821 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3822 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3823 left_p
, right_p
, &clip_rect
);
3826 x_setup_relief_colors (s
);
3827 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3828 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3833 /* Draw foreground of image glyph string S. */
3836 x_draw_image_foreground (s
)
3837 struct glyph_string
*s
;
3840 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3842 /* If first glyph of S has a left box line, start drawing it to the
3843 right of that line. */
3844 if (s
->face
->box
!= FACE_NO_BOX
3845 && s
->first_glyph
->left_box_line_p
)
3846 x
= s
->x
+ abs (s
->face
->box_line_width
);
3850 /* If there is a margin around the image, adjust x- and y-position
3852 x
+= s
->img
->hmargin
;
3853 y
+= s
->img
->vmargin
;
3859 #if 0 /* TODO: image mask */
3862 /* We can't set both a clip mask and use XSetClipRectangles
3863 because the latter also sets a clip mask. We also can't
3864 trust on the shape extension to be available
3865 (XShapeCombineRegion). So, compute the rectangle to draw
3867 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3870 XRectangle clip_rect
, image_rect
, r
;
3872 xgcv
.clip_mask
= s
->img
->mask
;
3873 xgcv
.clip_x_origin
= x
;
3874 xgcv
.clip_y_origin
= y
;
3875 xgcv
.function
= GXcopy
;
3876 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3878 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3881 image_rect
.width
= s
->img
->width
;
3882 image_rect
.height
= s
->img
->height
;
3883 if (IntersectRect (&r
, &clip_rect
, &image_rect
))
3884 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3885 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3890 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
3891 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
3892 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
3893 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
3894 x_set_glyph_string_clipping (s
);
3896 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3897 SetBkColor (s
->hdc
, s
->gc
->background
);
3898 #if 0 /* From w32bdf.c (which is from Meadow). */
3899 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3900 compat_hdc
, 0, 0, SRCCOPY
);
3901 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3902 compat_hdc
, 0, 0, 0xB8074A);
3904 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3905 compat_hdc
, 0, 0, 0xE20746);
3907 SelectObject (s
->hdc
, orig_brush
);
3908 DeleteObject (fg_brush
);
3909 SelectObject (compat_hdc
, orig_obj
);
3910 DeleteDC (compat_hdc
);
3912 /* When the image has a mask, we can expect that at
3913 least part of a mouse highlight or a block cursor will
3914 be visible. If the image doesn't have a mask, make
3915 a block cursor visible by drawing a rectangle around
3916 the image. I believe it's looking better if we do
3917 nothing here for mouse-face. */
3918 if (s
->hl
== DRAW_CURSOR
)
3919 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
3920 s
->img
->height
- 1);
3921 w32_set_clip_rectangle (s
->hdc
, NULL
);
3925 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
-1,
3926 s
->img
->height
- 1);
3928 RestoreDC (s
->hdc
,-1);
3933 /* Draw a relief around the image glyph string S. */
3936 x_draw_image_relief (s
)
3937 struct glyph_string
*s
;
3939 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3942 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3944 /* If first glyph of S has a left box line, start drawing it to the
3945 right of that line. */
3946 if (s
->face
->box
!= FACE_NO_BOX
3947 && s
->first_glyph
->left_box_line_p
)
3948 x
= s
->x
+ abs (s
->face
->box_line_width
);
3952 /* If there is a margin around the image, adjust x- and y-position
3954 x
+= s
->img
->hmargin
;
3955 y
+= s
->img
->vmargin
;
3957 if (s
->hl
== DRAW_IMAGE_SUNKEN
3958 || s
->hl
== DRAW_IMAGE_RAISED
)
3960 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3961 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3965 thick
= abs (s
->img
->relief
);
3966 raised_p
= s
->img
->relief
> 0;
3971 x1
= x
+ s
->img
->width
+ thick
- 1;
3972 y1
= y
+ s
->img
->height
+ thick
- 1;
3974 x_setup_relief_colors (s
);
3975 w32_get_glyph_string_clip_rect (s
, &r
);
3976 w32_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3980 /* Draw the foreground of image glyph string S to PIXMAP. */
3983 w32_draw_image_foreground_1 (s
, pixmap
)
3984 struct glyph_string
*s
;
3987 HDC hdc
= CreateCompatibleDC (s
->hdc
);
3988 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
3990 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3992 /* If first glyph of S has a left box line, start drawing it to the
3993 right of that line. */
3994 if (s
->face
->box
!= FACE_NO_BOX
3995 && s
->first_glyph
->left_box_line_p
)
3996 x
= abs (s
->face
->box_line_width
);
4000 /* If there is a margin around the image, adjust x- and y-position
4002 x
+= s
->img
->hmargin
;
4003 y
+= s
->img
->vmargin
;
4007 #if 0 /* TODO: image mask */
4010 /* We can't set both a clip mask and use XSetClipRectangles
4011 because the latter also sets a clip mask. We also can't
4012 trust on the shape extension to be available
4013 (XShapeCombineRegion). So, compute the rectangle to draw
4015 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4019 xgcv
.clip_mask
= s
->img
->mask
;
4020 xgcv
.clip_x_origin
= x
;
4021 xgcv
.clip_y_origin
= y
;
4022 xgcv
.function
= GXcopy
;
4023 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4025 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4026 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4027 XSetClipMask (s
->display
, s
->gc
, None
);
4032 HDC compat_hdc
= CreateCompatibleDC (hdc
);
4033 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4034 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
4035 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
4037 SetTextColor (hdc
, s
->gc
->foreground
);
4038 SetBkColor (hdc
, s
->gc
->background
);
4039 #if 0 /* From w32bdf.c (which is from Meadow). */
4040 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4041 compat_hdc
, 0, 0, SRCCOPY
);
4042 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4043 compat_hdc
, 0, 0, 0xB8074A);
4045 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4046 compat_hdc
, 0, 0, 0xE20746);
4048 SelectObject (hdc
, orig_brush
);
4049 DeleteObject (fg_brush
);
4050 SelectObject (compat_hdc
, orig_obj
);
4051 DeleteDC (compat_hdc
);
4053 /* When the image has a mask, we can expect that at
4054 least part of a mouse highlight or a block cursor will
4055 be visible. If the image doesn't have a mask, make
4056 a block cursor visible by drawing a rectangle around
4057 the image. I believe it's looking better if we do
4058 nothing here for mouse-face. */
4059 if (s
->hl
== DRAW_CURSOR
)
4060 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4061 s
->img
->height
- 1);
4065 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4066 s
->img
->height
- 1);
4068 SelectObject (hdc
, orig_hdc_obj
);
4073 /* Draw part of the background of glyph string S. X, Y, W, and H
4074 give the rectangle to draw. */
4077 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4078 struct glyph_string
*s
;
4081 #if 0 /* TODO: stipple */
4084 /* Fill background with a stipple pattern. */
4085 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4086 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4087 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4091 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4095 /* Draw image glyph string S.
4098 s->x +-------------------------
4101 | +-------------------------
4104 | | +-------------------
4110 x_draw_image_glyph_string (s
)
4111 struct glyph_string
*s
;
4114 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4115 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4119 height
= s
->height
- 2 * box_line_vwidth
;
4121 /* Fill background with face under the image. Do it only if row is
4122 taller than image or if image has a clip mask to reduce
4124 s
->stippled_p
= s
->face
->stipple
!= 0;
4125 if (height
> s
->img
->height
4128 #if 0 /* TODO: image mask */
4131 || s
->img
->pixmap
== 0
4132 || s
->width
!= s
->background_width
)
4134 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4135 x
= s
->x
+ box_line_hwidth
;
4139 y
= s
->y
+ box_line_vwidth
;
4140 #if 0 /* TODO: image mask */
4143 /* Create a pixmap as large as the glyph string. Fill it
4144 with the background color. Copy the image to it, using
4145 its mask. Copy the temporary pixmap to the display. */
4146 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4147 int depth
= DefaultDepthOfScreen (screen
);
4149 /* Create a pixmap as large as the glyph string. */
4150 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4151 s
->background_width
,
4154 /* Don't clip in the following because we're working on the
4156 XSetClipMask (s
->display
, s
->gc
, None
);
4158 /* Fill the pixmap with the background color/stipple. */
4161 /* Fill background with a stipple pattern. */
4162 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4163 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4164 0, 0, s
->background_width
, s
->height
);
4165 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4170 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4172 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4173 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4174 0, 0, s
->background_width
, s
->height
);
4175 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4180 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4182 s
->background_filled_p
= 1;
4185 /* Draw the foreground. */
4188 w32_draw_image_foreground_1 (s
, pixmap
);
4189 x_set_glyph_string_clipping (s
);
4191 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
4192 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4193 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
4194 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
4196 SetTextColor (s
->hdc
, s
->gc
->foreground
);
4197 SetBkColor (s
->hdc
, s
->gc
->background
);
4198 #if 0 /* From w32bdf.c (which is from Meadow). */
4199 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4200 compat_hdc
, 0, 0, SRCCOPY
);
4201 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4202 compat_hdc
, 0, 0, 0xB8074A);
4204 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4205 compat_hdc
, 0, 0, 0xE20746);
4207 SelectObject (s
->hdc
, orig_brush
);
4208 DeleteObject (fg_brush
);
4209 SelectObject (compat_hdc
, orig_obj
);
4210 DeleteDC (compat_hdc
);
4212 DeleteObject (pixmap
);
4216 x_draw_image_foreground (s
);
4218 /* If we must draw a relief around the image, do it. */
4220 || s
->hl
== DRAW_IMAGE_RAISED
4221 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4222 x_draw_image_relief (s
);
4226 /* Draw stretch glyph string S. */
4229 x_draw_stretch_glyph_string (s
)
4230 struct glyph_string
*s
;
4232 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4233 s
->stippled_p
= s
->face
->stipple
!= 0;
4235 if (s
->hl
== DRAW_CURSOR
4236 && !x_stretch_cursor_p
)
4238 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4239 as wide as the stretch glyph. */
4240 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4243 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4245 /* Clear rest using the GC of the original non-cursor face. */
4246 if (width
< s
->background_width
)
4248 XGCValues
*gc
= s
->face
->gc
;
4249 int x
= s
->x
+ width
, y
= s
->y
;
4250 int w
= s
->background_width
- width
, h
= s
->height
;
4254 if (s
->row
->mouse_face_p
4255 && cursor_in_mouse_face_p (s
->w
))
4257 x_set_mouse_face_gc (s
);
4263 w32_get_glyph_string_clip_rect (s
, &r
);
4264 w32_set_clip_rectangle (hdc
, &r
);
4266 #if 0 /* TODO: stipple */
4267 if (s
->face
->stipple
)
4269 /* Fill background with a stipple pattern. */
4270 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4271 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4272 XSetFillStyle (s
->display
, gc
, FillSolid
);
4277 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
4281 else if (!s
->background_filled_p
)
4282 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4285 s
->background_filled_p
= 1;
4289 /* Draw glyph string S. */
4292 x_draw_glyph_string (s
)
4293 struct glyph_string
*s
;
4295 int relief_drawn_p
= 0;
4297 /* If S draws into the background of its successor, draw the
4298 background of the successor first so that S can draw into it.
4299 This makes S->next use XDrawString instead of XDrawImageString. */
4300 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4302 xassert (s
->next
->img
== NULL
);
4303 x_set_glyph_string_gc (s
->next
);
4304 x_set_glyph_string_clipping (s
->next
);
4305 x_draw_glyph_string_background (s
->next
, 1);
4308 /* Set up S->gc, set clipping and draw S. */
4309 x_set_glyph_string_gc (s
);
4311 /* Draw relief (if any) in advance for char/composition so that the
4312 glyph string can be drawn over it. */
4313 if (!s
->for_overlaps_p
4314 && s
->face
->box
!= FACE_NO_BOX
4315 && (s
->first_glyph
->type
== CHAR_GLYPH
4316 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4319 x_set_glyph_string_clipping (s
);
4320 x_draw_glyph_string_background (s
, 1);
4321 x_draw_glyph_string_box (s
);
4322 x_set_glyph_string_clipping (s
);
4326 x_set_glyph_string_clipping (s
);
4328 switch (s
->first_glyph
->type
)
4331 x_draw_image_glyph_string (s
);
4335 x_draw_stretch_glyph_string (s
);
4339 if (s
->for_overlaps_p
)
4340 s
->background_filled_p
= 1;
4342 x_draw_glyph_string_background (s
, 0);
4343 x_draw_glyph_string_foreground (s
);
4346 case COMPOSITE_GLYPH
:
4347 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4348 s
->background_filled_p
= 1;
4350 x_draw_glyph_string_background (s
, 1);
4351 x_draw_composite_glyph_string_foreground (s
);
4358 if (!s
->for_overlaps_p
)
4360 /* Draw underline. */
4361 if (s
->face
->underline_p
4362 && (s
->font
->bdf
|| !s
->font
->tm
.tmUnderlined
))
4364 unsigned long h
= 1;
4365 unsigned long dy
= s
->height
- h
;
4367 /* TODO: Use font information for positioning and thickness
4368 of underline. See OUTLINETEXTMETRIC, and xterm.c. */
4369 if (s
->face
->underline_defaulted_p
)
4371 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4372 s
->y
+ dy
, s
->width
, 1);
4376 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4377 s
->y
+ dy
, s
->width
, 1);
4381 /* Draw overline. */
4382 if (s
->face
->overline_p
)
4384 unsigned long dy
= 0, h
= 1;
4386 if (s
->face
->overline_color_defaulted_p
)
4388 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4389 s
->y
+ dy
, s
->width
, h
);
4393 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4394 s
->y
+ dy
, s
->width
, h
);
4398 /* Draw strike-through. */
4399 if (s
->face
->strike_through_p
4400 && (s
->font
->bdf
|| !s
->font
->tm
.tmStruckOut
))
4402 unsigned long h
= 1;
4403 unsigned long dy
= (s
->height
- h
) / 2;
4405 if (s
->face
->strike_through_color_defaulted_p
)
4407 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
4412 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4413 s
->y
+ dy
, s
->width
, h
);
4418 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4419 x_draw_glyph_string_box (s
);
4422 /* Reset clipping. */
4423 w32_set_clip_rectangle (s
->hdc
, NULL
);
4427 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4428 struct face
**, int));
4431 /* Fill glyph string S with composition components specified by S->cmp.
4433 FACES is an array of faces for all components of this composition.
4434 S->gidx is the index of the first component for S.
4435 OVERLAPS_P non-zero means S should draw the foreground only, and
4436 use its physical height for clipping.
4438 Value is the index of a component not in S. */
4441 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4442 struct glyph_string
*s
;
4443 struct face
**faces
;
4450 s
->for_overlaps_p
= overlaps_p
;
4452 s
->face
= faces
[s
->gidx
];
4453 s
->font
= s
->face
->font
;
4454 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4456 /* For all glyphs of this composition, starting at the offset
4457 S->gidx, until we reach the end of the definition or encounter a
4458 glyph that requires the different face, add it to S. */
4460 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4463 /* All glyph strings for the same composition has the same width,
4464 i.e. the width set for the first component of the composition. */
4466 s
->width
= s
->first_glyph
->pixel_width
;
4468 /* If the specified font could not be loaded, use the frame's
4469 default font, but record the fact that we couldn't load it in
4470 the glyph string so that we can draw rectangles for the
4471 characters of the glyph string. */
4472 if (s
->font
== NULL
)
4474 s
->font_not_found_p
= 1;
4475 s
->font
= FRAME_FONT (s
->f
);
4478 /* Adjust base line for subscript/superscript text. */
4479 s
->ybase
+= s
->first_glyph
->voffset
;
4481 xassert (s
->face
&& s
->face
->gc
);
4483 /* This glyph string must always be drawn with 16-bit functions. */
4486 return s
->gidx
+ s
->nchars
;
4490 /* Fill glyph string S from a sequence of character glyphs.
4492 FACE_ID is the face id of the string. START is the index of the
4493 first glyph to consider, END is the index of the last + 1.
4494 OVERLAPS_P non-zero means S should draw the foreground only, and
4495 use its physical height for clipping.
4497 Value is the index of the first glyph not in S. */
4500 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4501 struct glyph_string
*s
;
4503 int start
, end
, overlaps_p
;
4505 struct glyph
*glyph
, *last
;
4507 int glyph_not_available_p
;
4509 xassert (s
->f
== XFRAME (s
->w
->frame
));
4510 xassert (s
->nchars
== 0);
4511 xassert (start
>= 0 && end
> start
);
4513 s
->for_overlaps_p
= overlaps_p
;
4514 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4515 last
= s
->row
->glyphs
[s
->area
] + end
;
4516 voffset
= glyph
->voffset
;
4518 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4521 && glyph
->type
== CHAR_GLYPH
4522 && glyph
->voffset
== voffset
4523 /* Same face id implies same font, nowadays. */
4524 && glyph
->face_id
== face_id
4525 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4529 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4530 s
->char2b
+ s
->nchars
,
4532 s
->two_byte_p
= two_byte_p
;
4534 xassert (s
->nchars
<= end
- start
);
4535 s
->width
+= glyph
->pixel_width
;
4539 s
->font
= s
->face
->font
;
4540 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4542 /* If the specified font could not be loaded, use the frame's font,
4543 but record the fact that we couldn't load it in
4544 S->font_not_found_p so that we can draw rectangles for the
4545 characters of the glyph string. */
4546 if (s
->font
== NULL
|| glyph_not_available_p
)
4548 s
->font_not_found_p
= 1;
4549 s
->font
= FRAME_FONT (s
->f
);
4552 /* Adjust base line for subscript/superscript text. */
4553 s
->ybase
+= voffset
;
4555 xassert (s
->face
&& s
->face
->gc
);
4556 return glyph
- s
->row
->glyphs
[s
->area
];
4560 /* Fill glyph string S from image glyph S->first_glyph. */
4563 x_fill_image_glyph_string (s
)
4564 struct glyph_string
*s
;
4566 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4567 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4569 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4570 s
->font
= s
->face
->font
;
4571 s
->width
= s
->first_glyph
->pixel_width
;
4573 /* Adjust base line for subscript/superscript text. */
4574 s
->ybase
+= s
->first_glyph
->voffset
;
4578 /* Fill glyph string S from a sequence of stretch glyphs.
4580 ROW is the glyph row in which the glyphs are found, AREA is the
4581 area within the row. START is the index of the first glyph to
4582 consider, END is the index of the last + 1.
4584 Value is the index of the first glyph not in S. */
4587 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4588 struct glyph_string
*s
;
4589 struct glyph_row
*row
;
4590 enum glyph_row_area area
;
4593 struct glyph
*glyph
, *last
;
4594 int voffset
, face_id
;
4596 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4598 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4599 last
= s
->row
->glyphs
[s
->area
] + end
;
4600 face_id
= glyph
->face_id
;
4601 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4602 s
->font
= s
->face
->font
;
4603 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4604 s
->width
= glyph
->pixel_width
;
4605 voffset
= glyph
->voffset
;
4609 && glyph
->type
== STRETCH_GLYPH
4610 && glyph
->voffset
== voffset
4611 && glyph
->face_id
== face_id
);
4613 s
->width
+= glyph
->pixel_width
;
4615 /* Adjust base line for subscript/superscript text. */
4616 s
->ybase
+= voffset
;
4619 return glyph
- s
->row
->glyphs
[s
->area
];
4623 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4624 of XChar2b structures for S; it can't be allocated in
4625 x_init_glyph_string because it must be allocated via `alloca'. W
4626 is the window on which S is drawn. ROW and AREA are the glyph row
4627 and area within the row from which S is constructed. START is the
4628 index of the first glyph structure covered by S. HL is a
4629 face-override for drawing S. */
4632 w32_init_glyph_string (s
, hdc
, char2b
, w
, row
, area
, start
, hl
)
4633 struct glyph_string
*s
;
4637 struct glyph_row
*row
;
4638 enum glyph_row_area area
;
4640 enum draw_glyphs_face hl
;
4642 bzero (s
, sizeof *s
);
4644 s
->f
= XFRAME (w
->frame
);
4646 s
->window
= FRAME_W32_WINDOW (s
->f
);
4651 s
->first_glyph
= row
->glyphs
[area
] + start
;
4652 s
->height
= row
->height
;
4653 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4655 /* Display the internal border below the tool-bar window. */
4656 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4657 s
->y
-= s
->f
->output_data
.w32
->internal_border_width
;
4659 s
->ybase
= s
->y
+ row
->ascent
;
4663 /* Set background width of glyph string S. START is the index of the
4664 first glyph following S. LAST_X is the right-most x-position + 1
4665 in the drawing area. */
4668 x_set_glyph_string_background_width (s
, start
, last_x
)
4669 struct glyph_string
*s
;
4673 /* If the face of this glyph string has to be drawn to the end of
4674 the drawing area, set S->extends_to_end_of_line_p. */
4675 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4677 if (start
== s
->row
->used
[s
->area
]
4678 && s
->area
== TEXT_AREA
4679 && ((s
->hl
== DRAW_NORMAL_TEXT
4680 && (s
->row
->fill_line_p
4681 || s
->face
->background
!= default_face
->background
4682 || s
->face
->stipple
!= default_face
->stipple
4683 || s
->row
->mouse_face_p
))
4684 || s
->hl
== DRAW_MOUSE_FACE
4685 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4686 && s
->row
->fill_line_p
)))
4687 s
->extends_to_end_of_line_p
= 1;
4689 /* If S extends its face to the end of the line, set its
4690 background_width to the distance to the right edge of the drawing
4692 if (s
->extends_to_end_of_line_p
)
4693 s
->background_width
= last_x
- s
->x
+ 1;
4695 s
->background_width
= s
->width
;
4699 /* Add a glyph string for a stretch glyph to the list of strings
4700 between HEAD and TAIL. START is the index of the stretch glyph in
4701 row area AREA of glyph row ROW. END is the index of the last glyph
4702 in that glyph row area. X is the current output position assigned
4703 to the new glyph string constructed. HL overrides that face of the
4704 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4705 is the right-most x-position of the drawing area. */
4707 #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4710 s = (struct glyph_string *) alloca (sizeof *s); \
4711 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4712 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4713 x_append_glyph_string (&HEAD, &TAIL, s); \
4719 /* Add a glyph string for an image glyph to the list of strings
4720 between HEAD and TAIL. START is the index of the image glyph in
4721 row area AREA of glyph row ROW. END is the index of the last glyph
4722 in that glyph row area. X is the current output position assigned
4723 to the new glyph string constructed. HL overrides that face of the
4724 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4725 is the right-most x-position of the drawing area. */
4727 #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4730 s = (struct glyph_string *) alloca (sizeof *s); \
4731 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4732 x_fill_image_glyph_string (s); \
4733 x_append_glyph_string (&HEAD, &TAIL, s); \
4740 /* Add a glyph string for a sequence of character glyphs to the list
4741 of strings between HEAD and TAIL. START is the index of the first
4742 glyph in row area AREA of glyph row ROW that is part of the new
4743 glyph string. END is the index of the last glyph in that glyph row
4744 area. X is the current output position assigned to the new glyph
4745 string constructed. HL overrides that face of the glyph; e.g. it
4746 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4747 right-most x-position of the drawing area. */
4749 #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4755 c = (ROW)->glyphs[AREA][START].u.ch; \
4756 face_id = (ROW)->glyphs[AREA][START].face_id; \
4758 s = (struct glyph_string *) alloca (sizeof *s); \
4759 char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \
4760 w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \
4761 x_append_glyph_string (&HEAD, &TAIL, s); \
4763 START = x_fill_glyph_string (s, face_id, START, END, \
4769 /* Add a glyph string for a composite sequence to the list of strings
4770 between HEAD and TAIL. START is the index of the first glyph in
4771 row area AREA of glyph row ROW that is part of the new glyph
4772 string. END is the index of the last glyph in that glyph row area.
4773 X is the current output position assigned to the new glyph string
4774 constructed. HL overrides that face of the glyph; e.g. it is
4775 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4776 x-position of the drawing area. */
4778 #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4780 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4781 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4782 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4783 struct composition *cmp = composition_table[cmp_id]; \
4784 int glyph_len = cmp->glyph_len; \
4786 struct face **faces; \
4787 struct glyph_string *first_s = NULL; \
4790 base_face = base_face->ascii_face; \
4791 char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \
4792 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4793 /* At first, fill in `char2b' and `faces'. */ \
4794 for (n = 0; n < glyph_len; n++) \
4796 int c = COMPOSITION_GLYPH (cmp, n); \
4797 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4798 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4799 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4800 this_face_id, char2b + n, 1); \
4803 /* Make glyph_strings for each glyph sequence that is drawable by \
4804 the same face, and append them to HEAD/TAIL. */ \
4805 for (n = 0; n < cmp->glyph_len;) \
4807 s = (struct glyph_string *) alloca (sizeof *s); \
4808 w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \
4809 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4817 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4825 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4826 of AREA of glyph row ROW on window W between indices START and END.
4827 HL overrides the face for drawing glyph strings, e.g. it is
4828 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4829 x-positions of the drawing area.
4831 This is an ugly monster macro construct because we must use alloca
4832 to allocate glyph strings (because x_draw_glyphs can be called
4835 #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4838 HEAD = TAIL = NULL; \
4839 while (START < END) \
4841 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4842 switch (first_glyph->type) \
4845 BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \
4846 HEAD, TAIL, HL, X, LAST_X, \
4850 case COMPOSITE_GLYPH: \
4851 BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \
4852 END, HEAD, TAIL, HL, X, \
4853 LAST_X, OVERLAPS_P); \
4856 case STRETCH_GLYPH: \
4857 BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\
4858 HEAD, TAIL, HL, X, LAST_X); \
4862 BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \
4863 HEAD, TAIL, HL, X, LAST_X); \
4870 x_set_glyph_string_background_width (s, START, LAST_X); \
4877 /* Draw glyphs between START and END in AREA of ROW on window W,
4878 starting at x-position X. X is relative to AREA in W. HL is a
4879 face-override with the following meaning:
4881 DRAW_NORMAL_TEXT draw normally
4882 DRAW_CURSOR draw in cursor face
4883 DRAW_MOUSE_FACE draw in mouse face.
4884 DRAW_INVERSE_VIDEO draw in mode line face
4885 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4886 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4888 If OVERLAPS_P is non-zero, draw only the foreground of characters
4889 and clip to the physical height of ROW.
4891 Value is the x-position reached, relative to AREA of W. */
4894 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
4897 struct glyph_row
*row
;
4898 enum glyph_row_area area
;
4900 enum draw_glyphs_face hl
;
4903 struct glyph_string
*head
, *tail
;
4904 struct glyph_string
*s
;
4905 int last_x
, area_width
;
4908 HDC hdc
= get_frame_dc (XFRAME (WINDOW_FRAME (w
)));
4910 /* Let's rather be paranoid than getting a SEGV. */
4911 end
= min (end
, row
->used
[area
]);
4912 start
= max (0, start
);
4913 start
= min (end
, start
);
4915 /* Translate X to frame coordinates. Set last_x to the right
4916 end of the drawing area. */
4917 if (row
->full_width_p
)
4919 /* X is relative to the left edge of W, without scroll bars
4921 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4922 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4925 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4926 last_x
= window_left_x
+ area_width
;
4928 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4930 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4931 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4937 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4938 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4942 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4943 area_width
= window_box_width (w
, area
);
4944 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4947 /* Build a doubly-linked list of glyph_string structures between
4948 head and tail from what we have to draw. Note that the macro
4949 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4950 the reason we use a separate variable `i'. */
4952 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4955 x_reached
= tail
->x
+ tail
->background_width
;
4959 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4960 the row, redraw some glyphs in front or following the glyph
4961 strings built above. */
4962 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4965 struct glyph_string
*h
, *t
;
4967 /* Compute overhangs for all glyph strings. */
4968 for (s
= head
; s
; s
= s
->next
)
4969 x_compute_glyph_string_overhangs (s
);
4971 /* Prepend glyph strings for glyphs in front of the first glyph
4972 string that are overwritten because of the first glyph
4973 string's left overhang. The background of all strings
4974 prepended must be drawn because the first glyph string
4976 i
= x_left_overwritten (head
);
4980 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, j
, start
, h
, t
,
4981 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4984 x_compute_overhangs_and_x (t
, head
->x
, 1);
4985 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4988 /* Prepend glyph strings for glyphs in front of the first glyph
4989 string that overwrite that glyph string because of their
4990 right overhang. For these strings, only the foreground must
4991 be drawn, because it draws over the glyph string at `head'.
4992 The background must not be drawn because this would overwrite
4993 right overhangs of preceding glyphs for which no glyph
4995 i
= x_left_overwriting (head
);
4998 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, start
, h
, t
,
4999 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5001 for (s
= h
; s
; s
= s
->next
)
5002 s
->background_filled_p
= 1;
5003 x_compute_overhangs_and_x (t
, head
->x
, 1);
5004 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5007 /* Append glyphs strings for glyphs following the last glyph
5008 string tail that are overwritten by tail. The background of
5009 these strings has to be drawn because tail's foreground draws
5011 i
= x_right_overwritten (tail
);
5014 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5015 DRAW_NORMAL_TEXT
, x
, last_x
,
5017 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5018 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5021 /* Append glyph strings for glyphs following the last glyph
5022 string tail that overwrite tail. The foreground of such
5023 glyphs has to be drawn because it writes into the background
5024 of tail. The background must not be drawn because it could
5025 paint over the foreground of following glyphs. */
5026 i
= x_right_overwriting (tail
);
5029 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5030 DRAW_NORMAL_TEXT
, x
, last_x
,
5032 for (s
= h
; s
; s
= s
->next
)
5033 s
->background_filled_p
= 1;
5034 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5035 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5039 /* Draw all strings. */
5040 for (s
= head
; s
; s
= s
->next
)
5041 x_draw_glyph_string (s
);
5043 if (area
== TEXT_AREA
5044 && !row
->full_width_p
5045 /* When drawing overlapping rows, only the glyph strings'
5046 foreground is drawn, which doesn't erase a cursor
5050 int x0
= head
? head
->x
: x
;
5051 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5053 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5054 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5056 if (!row
->full_width_p
&& XFASTINT (w
->left_margin_width
) != 0)
5058 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5059 x0
-= left_area_width
;
5060 x1
-= left_area_width
;
5063 notice_overwritten_cursor (w
, area
, x0
, x1
,
5064 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5067 /* Value is the x-position up to which drawn, relative to AREA of W.
5068 This doesn't include parts drawn because of overhangs. */
5069 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5070 if (!row
->full_width_p
)
5072 if (area
> LEFT_MARGIN_AREA
)
5073 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5074 if (area
> TEXT_AREA
)
5075 x_reached
-= window_box_width (w
, TEXT_AREA
);
5078 release_frame_dc (XFRAME (WINDOW_FRAME (w
)), hdc
);
5084 /* Fix the display of area AREA of overlapping row ROW in window W. */
5087 x_fix_overlapping_area (w
, row
, area
)
5089 struct glyph_row
*row
;
5090 enum glyph_row_area area
;
5096 if (area
== LEFT_MARGIN_AREA
)
5098 else if (area
== TEXT_AREA
)
5099 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5101 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5102 + window_box_width (w
, TEXT_AREA
));
5104 for (i
= 0; i
< row
->used
[area
];)
5106 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5108 int start
= i
, start_x
= x
;
5112 x
+= row
->glyphs
[area
][i
].pixel_width
;
5115 while (i
< row
->used
[area
]
5116 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5118 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5119 DRAW_NORMAL_TEXT
, 1);
5123 x
+= row
->glyphs
[area
][i
].pixel_width
;
5132 /* Output LEN glyphs starting at START at the nominal cursor position.
5133 Advance the nominal cursor over the text. The global variable
5134 updated_window contains the window being updated, updated_row is
5135 the glyph row being updated, and updated_area is the area of that
5136 row being updated. */
5139 x_write_glyphs (start
, len
)
5140 struct glyph
*start
;
5145 xassert (updated_window
&& updated_row
);
5150 hpos
= start
- updated_row
->glyphs
[updated_area
];
5151 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5152 updated_row
, updated_area
,
5154 DRAW_NORMAL_TEXT
, 0);
5158 /* Advance the output cursor. */
5159 output_cursor
.hpos
+= len
;
5160 output_cursor
.x
= x
;
5164 /* Insert LEN glyphs from START at the nominal cursor position. */
5167 x_insert_glyphs (start
, len
)
5168 struct glyph
*start
;
5173 int line_height
, shift_by_width
, shifted_region_width
;
5174 struct glyph_row
*row
;
5175 struct glyph
*glyph
;
5176 int frame_x
, frame_y
, hpos
;
5179 xassert (updated_window
&& updated_row
);
5182 f
= XFRAME (WINDOW_FRAME (w
));
5183 hdc
= get_frame_dc (f
);
5185 /* Get the height of the line we are in. */
5187 line_height
= row
->height
;
5189 /* Get the width of the glyphs to insert. */
5191 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5192 shift_by_width
+= glyph
->pixel_width
;
5194 /* Get the width of the region to shift right. */
5195 shifted_region_width
= (window_box_width (w
, updated_area
)
5200 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5201 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5202 BitBlt (hdc
, frame_x
+ shift_by_width
, frame_y
,
5203 shifted_region_width
, line_height
,
5204 hdc
, frame_x
, frame_y
, SRCCOPY
);
5206 /* Write the glyphs. */
5207 hpos
= start
- row
->glyphs
[updated_area
];
5208 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5209 DRAW_NORMAL_TEXT
, 0);
5211 /* Advance the output cursor. */
5212 output_cursor
.hpos
+= len
;
5213 output_cursor
.x
+= shift_by_width
;
5214 release_frame_dc (f
, hdc
);
5220 /* Delete N glyphs at the nominal cursor position. Not implemented
5232 f
= SELECTED_FRAME ();
5234 if (! FRAME_W32_P (f
))
5241 /* Erase the current text line from the nominal cursor position
5242 (inclusive) to pixel column TO_X (exclusive). The idea is that
5243 everything from TO_X onward is already erased.
5245 TO_X is a pixel position relative to updated_area of
5246 updated_window. TO_X == -1 means clear to the end of this area. */
5249 x_clear_end_of_line (to_x
)
5253 struct window
*w
= updated_window
;
5254 int max_x
, min_y
, max_y
;
5255 int from_x
, from_y
, to_y
;
5257 xassert (updated_window
&& updated_row
);
5258 f
= XFRAME (w
->frame
);
5260 if (updated_row
->full_width_p
)
5262 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5263 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5264 && !w
->pseudo_window_p
)
5265 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5268 max_x
= window_box_width (w
, updated_area
);
5269 max_y
= window_text_bottom_y (w
);
5271 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5272 of window. For TO_X > 0, truncate to end of drawing area. */
5278 to_x
= min (to_x
, max_x
);
5280 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5282 /* Notice if the cursor will be cleared by this operation. */
5283 if (!updated_row
->full_width_p
)
5284 notice_overwritten_cursor (w
, updated_area
,
5285 output_cursor
.x
, -1,
5287 MATRIX_ROW_BOTTOM_Y (updated_row
));
5289 from_x
= output_cursor
.x
;
5291 /* Translate to frame coordinates. */
5292 if (updated_row
->full_width_p
)
5294 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5295 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5299 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5300 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5303 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5304 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5305 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5307 /* Prevent inadvertently clearing to end of the X window. */
5308 if (to_x
> from_x
&& to_y
> from_y
)
5312 hdc
= get_frame_dc (f
);
5314 w32_clear_area (f
, hdc
, from_x
, from_y
, to_x
- from_x
, to_y
- from_y
);
5315 release_frame_dc (f
, hdc
);
5321 /* Clear entire frame. If updating_frame is non-null, clear that
5322 frame. Otherwise clear the selected frame. */
5332 f
= SELECTED_FRAME ();
5334 if (! FRAME_W32_P (f
))
5337 /* Clearing the frame will erase any cursor, so mark them all as no
5339 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5340 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5341 output_cursor
.x
= -1;
5343 /* We don't set the output cursor here because there will always
5344 follow an explicit cursor_to. */
5347 w32_clear_window (f
);
5349 /* We have to clear the scroll bars, too. If we have changed
5350 colors or something like that, then they should be notified. */
5351 x_scroll_bar_clear (f
);
5357 /* Make audible bell. */
5360 w32_ring_bell (void)
5364 f
= SELECTED_FRAME ();
5368 if (FRAME_W32_P (f
) && visible_bell
)
5371 HWND hwnd
= FRAME_W32_WINDOW (SELECTED_FRAME ());
5373 for (i
= 0; i
< 5; i
++)
5375 FlashWindow (hwnd
, TRUE
);
5378 FlashWindow (hwnd
, FALSE
);
5381 w32_sys_ring_bell ();
5387 /* Specify how many text lines, from the top of the window,
5388 should be affected by insert-lines and delete-lines operations.
5389 This, and those operations, are used only within an update
5390 that is bounded by calls to x_update_begin and x_update_end. */
5393 w32_set_terminal_window (n
)
5396 /* This function intentionally left blank. */
5401 /***********************************************************************
5403 ***********************************************************************/
5405 /* Perform an insert-lines or delete-lines operation, inserting N
5406 lines or deleting -N lines at vertical position VPOS. */
5409 x_ins_del_lines (vpos
, n
)
5417 f
= SELECTED_FRAME ();
5419 if (! FRAME_W32_P (f
))
5426 /* Scroll part of the display as described by RUN. */
5429 x_scroll_run (w
, run
)
5433 struct frame
*f
= XFRAME (w
->frame
);
5434 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5435 HDC hdc
= get_frame_dc (f
);
5437 /* Get frame-relative bounding box of the text display area of W,
5438 without mode lines. Include in this box the left and right
5440 window_box (w
, -1, &x
, &y
, &width
, &height
);
5441 width
+= FRAME_X_FRINGE_WIDTH (f
);
5442 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5444 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5445 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5446 bottom_y
= y
+ height
;
5450 /* Scrolling up. Make sure we don't copy part of the mode
5451 line at the bottom. */
5452 if (from_y
+ run
->height
> bottom_y
)
5453 height
= bottom_y
- from_y
;
5455 height
= run
->height
;
5459 /* Scolling down. Make sure we don't copy over the mode line.
5461 if (to_y
+ run
->height
> bottom_y
)
5462 height
= bottom_y
- to_y
;
5464 height
= run
->height
;
5469 /* Cursor off. Will be switched on again in x_update_window_end. */
5473 BitBlt (hdc
, x
, to_y
, width
, height
, hdc
, x
, from_y
, SRCCOPY
);
5476 release_frame_dc (f
, hdc
);
5481 /***********************************************************************
5483 ***********************************************************************/
5485 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5486 corner of the exposed rectangle. W and H are width and height of
5487 the exposed area. All are pixel values. W or H zero means redraw
5488 the entire frame. */
5491 expose_frame (f
, x
, y
, w
, h
)
5496 int mouse_face_overwritten_p
= 0;
5498 TRACE ((stderr
, "expose_frame "));
5500 /* No need to redraw if frame will be redrawn soon. */
5501 if (FRAME_GARBAGED_P (f
))
5503 TRACE ((stderr
, " garbaged\n"));
5507 /* If basic faces haven't been realized yet, there is no point in
5508 trying to redraw anything. This can happen when we get an expose
5509 event while Emacs is starting, e.g. by moving another window. */
5510 if (FRAME_FACE_CACHE (f
) == NULL
5511 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5513 TRACE ((stderr
, " no faces\n"));
5517 if (w
== 0 || h
== 0)
5520 r
.right
= CANON_X_UNIT (f
) * f
->width
;
5521 r
.bottom
= CANON_Y_UNIT (f
) * f
->height
;
5531 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.left
, r
.top
, r
.right
, r
.bottom
));
5532 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5534 if (WINDOWP (f
->tool_bar_window
))
5535 mouse_face_overwritten_p
5536 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5538 /* Some window managers support a focus-follows-mouse style with
5539 delayed raising of frames. Imagine a partially obscured frame,
5540 and moving the mouse into partially obscured mouse-face on that
5541 frame. The visible part of the mouse-face will be highlighted,
5542 then the WM raises the obscured frame. With at least one WM, KDE
5543 2.1, Emacs is not getting any event for the raising of the frame
5544 (even tried with SubstructureRedirectMask), only Expose events.
5545 These expose events will draw text normally, i.e. not
5546 highlighted. Which means we must redo the highlight here.
5547 Subsume it under ``we love X''. --gerd 2001-08-15 */
5548 /* Included in Windows version because Windows most likely does not
5549 do the right thing if any third party tool offers
5550 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
5551 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5553 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5554 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5556 int x
= dpyinfo
->mouse_face_mouse_x
;
5557 int y
= dpyinfo
->mouse_face_mouse_y
;
5558 clear_mouse_face (dpyinfo
);
5559 note_mouse_highlight (f
, x
, y
);
5565 /* Redraw (parts) of all windows in the window tree rooted at W that
5566 intersect R. R contains frame pixel coordinates. */
5569 expose_window_tree (w
, r
)
5573 struct frame
*f
= XFRAME (w
->frame
);
5574 int mouse_face_overwritten_p
= 0;
5576 while (w
&& !FRAME_GARBAGED_P (f
))
5578 if (!NILP (w
->hchild
))
5579 mouse_face_overwritten_p
5580 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5581 else if (!NILP (w
->vchild
))
5582 mouse_face_overwritten_p
5583 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5585 mouse_face_overwritten_p
|= expose_window (w
, r
);
5587 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5590 return mouse_face_overwritten_p
;
5594 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5595 which intersects rectangle R. R is in window-relative coordinates. */
5598 expose_area (w
, row
, r
, area
)
5600 struct glyph_row
*row
;
5602 enum glyph_row_area area
;
5604 struct glyph
*first
= row
->glyphs
[area
];
5605 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5607 int first_x
, start_x
, x
;
5609 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5610 /* If row extends face to end of line write the whole line. */
5611 x_draw_glyphs (w
, 0, row
, area
,
5613 DRAW_NORMAL_TEXT
, 0);
5616 /* Set START_X to the window-relative start position for drawing glyphs of
5617 AREA. The first glyph of the text area can be partially visible.
5618 The first glyphs of other areas cannot. */
5619 if (area
== LEFT_MARGIN_AREA
)
5621 else if (area
== TEXT_AREA
)
5622 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5624 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5625 + window_box_width (w
, TEXT_AREA
));
5628 /* Find the first glyph that must be redrawn. */
5630 && x
+ first
->pixel_width
< r
->left
)
5632 x
+= first
->pixel_width
;
5636 /* Find the last one. */
5642 x
+= last
->pixel_width
;
5648 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5649 first
- row
->glyphs
[area
],
5650 last
- row
->glyphs
[area
],
5651 DRAW_NORMAL_TEXT
, 0);
5656 /* Redraw the parts of the glyph row ROW on window W intersecting
5657 rectangle R. R is in window-relative coordinates. Value is
5658 non-zero if mouse face was overwritten. */
5661 expose_line (w
, row
, r
)
5663 struct glyph_row
*row
;
5666 xassert (row
->enabled_p
);
5668 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5669 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5670 DRAW_NORMAL_TEXT
, 0);
5673 if (row
->used
[LEFT_MARGIN_AREA
])
5674 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5675 if (row
->used
[TEXT_AREA
])
5676 expose_area (w
, row
, r
, TEXT_AREA
);
5677 if (row
->used
[RIGHT_MARGIN_AREA
])
5678 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5679 x_draw_row_fringe_bitmaps (w
, row
);
5682 return row
->mouse_face_p
;
5686 /* Return non-zero if W's cursor intersects rectangle R. */
5689 x_phys_cursor_in_rect_p (w
, r
)
5694 struct glyph
*cursor_glyph
;
5696 cursor_glyph
= get_phys_cursor_glyph (w
);
5699 cr
.left
= w
->phys_cursor
.x
;
5700 cr
.top
= w
->phys_cursor
.y
;
5701 cr
.right
= cr
.left
+ cursor_glyph
->pixel_width
;
5702 cr
.bottom
= cr
.top
+ w
->phys_cursor_height
;
5703 return IntersectRect (&result
, &cr
, r
);
5710 /* Redraw the part of window W intersection rectagle FR. Pixel
5711 coordinates in FR are frame relative. Call this function with
5712 input blocked. Value is non-zero if the exposure overwrites
5716 expose_window (w
, fr
)
5720 struct frame
*f
= XFRAME (w
->frame
);
5722 int mouse_face_overwritten_p
= 0;
5724 /* If window is not yet fully initialized, do nothing. This can
5725 happen when toolkit scroll bars are used and a window is split.
5726 Reconfiguring the scroll bar will generate an expose for a newly
5728 if (w
->current_matrix
== NULL
)
5731 /* When we're currently updating the window, display and current
5732 matrix usually don't agree. Arrange for a thorough display
5734 if (w
== updated_window
)
5736 SET_FRAME_GARBAGED (f
);
5740 /* Frame-relative pixel rectangle of W. */
5741 wr
.left
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
5742 wr
.top
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
5743 wr
.right
= wr
.left
+ XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5744 wr
.bottom
= wr
.top
+ XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
5746 if (IntersectRect(&r
, fr
, &wr
))
5748 int yb
= window_text_bottom_y (w
);
5749 struct glyph_row
*row
;
5750 int cursor_cleared_p
;
5752 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5753 r
.left
, r
.top
, r
.right
, r
.bottom
));
5755 /* Convert to window coordinates. */
5756 r
.left
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.left
);
5757 r
.right
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.right
);
5758 r
.top
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.top
);
5759 r
.bottom
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.bottom
);
5761 /* Turn off the cursor. */
5762 if (!w
->pseudo_window_p
5763 && x_phys_cursor_in_rect_p (w
, &r
))
5766 cursor_cleared_p
= 1;
5769 cursor_cleared_p
= 0;
5771 /* Find the first row intersecting the rectangle R. */
5772 for (row
= w
->current_matrix
->rows
;
5777 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
5779 if ((y0
>= r
.top
&& y0
< r
.bottom
)
5780 || (y1
> r
.top
&& y1
< r
.bottom
)
5781 || (r
.top
>= y0
&& r
.top
< y1
)
5782 || (r
.bottom
> y0
&& r
.bottom
< y1
))
5784 if (expose_line (w
, row
, &r
))
5785 mouse_face_overwritten_p
= 1;
5792 /* Display the mode line if there is one. */
5793 if (WINDOW_WANTS_MODELINE_P (w
)
5794 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5796 && row
->y
< r
.bottom
)
5798 if (expose_line (w
, row
, &r
))
5799 mouse_face_overwritten_p
= 1;
5802 if (!w
->pseudo_window_p
)
5804 /* Draw border between windows. */
5805 x_draw_vertical_border (w
);
5807 /* Turn the cursor on again. */
5808 if (cursor_cleared_p
)
5809 x_update_window_cursor (w
, 1);
5813 return mouse_face_overwritten_p
;
5821 x_update_cursor (f
, 1);
5825 frame_unhighlight (f
)
5828 x_update_cursor (f
, 1);
5831 /* The focus has changed. Update the frames as necessary to reflect
5832 the new situation. Note that we can't change the selected frame
5833 here, because the Lisp code we are interrupting might become confused.
5834 Each event gets marked with the frame in which it occurred, so the
5835 Lisp code can tell when the switch took place by examining the events. */
5838 x_new_focus_frame (dpyinfo
, frame
)
5839 struct w32_display_info
*dpyinfo
;
5840 struct frame
*frame
;
5842 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
5844 if (frame
!= dpyinfo
->w32_focus_frame
)
5846 /* Set this before calling other routines, so that they see
5847 the correct value of w32_focus_frame. */
5848 dpyinfo
->w32_focus_frame
= frame
;
5850 if (old_focus
&& old_focus
->auto_lower
)
5851 x_lower_frame (old_focus
);
5853 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
5854 pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
5856 pending_autoraise_frame
= 0;
5859 x_frame_rehighlight (dpyinfo
);
5862 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5865 x_mouse_leave (dpyinfo
)
5866 struct w32_display_info
*dpyinfo
;
5868 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
5871 /* The focus has changed, or we have redirected a frame's focus to
5872 another frame (this happens when a frame uses a surrogate
5873 mini-buffer frame). Shift the highlight as appropriate.
5875 The FRAME argument doesn't necessarily have anything to do with which
5876 frame is being highlighted or un-highlighted; we only use it to find
5877 the appropriate X display info. */
5880 w32_frame_rehighlight (frame
)
5881 struct frame
*frame
;
5883 if (! FRAME_W32_P (frame
))
5885 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame
));
5889 x_frame_rehighlight (dpyinfo
)
5890 struct w32_display_info
*dpyinfo
;
5892 struct frame
*old_highlight
= dpyinfo
->w32_highlight_frame
;
5894 if (dpyinfo
->w32_focus_frame
)
5896 dpyinfo
->w32_highlight_frame
5897 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
5898 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
5899 : dpyinfo
->w32_focus_frame
);
5900 if (! FRAME_LIVE_P (dpyinfo
->w32_highlight_frame
))
5902 FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
) = Qnil
;
5903 dpyinfo
->w32_highlight_frame
= dpyinfo
->w32_focus_frame
;
5907 dpyinfo
->w32_highlight_frame
= 0;
5909 if (dpyinfo
->w32_highlight_frame
!= old_highlight
)
5912 frame_unhighlight (old_highlight
);
5913 if (dpyinfo
->w32_highlight_frame
)
5914 frame_highlight (dpyinfo
->w32_highlight_frame
);
5918 /* Keyboard processing - modifier keys, etc. */
5920 /* Convert a keysym to its name. */
5923 x_get_keysym_name (keysym
)
5926 /* Make static so we can always return it */
5927 static char value
[100];
5930 GetKeyNameText (keysym
, value
, 100);
5938 /* Mouse clicks and mouse movement. Rah. */
5940 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5941 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5942 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5943 not force the value into range. */
5946 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5948 register int pix_x
, pix_y
;
5949 register int *x
, *y
;
5953 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
5954 if (NILP (Vwindow_system
))
5961 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5962 even for negative values. */
5964 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
5966 pix_y
-= (f
)->output_data
.w32
->line_height
- 1;
5968 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5969 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5973 bounds
->left
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5974 bounds
->top
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5975 bounds
->right
= bounds
->left
+ FONT_WIDTH (FRAME_FONT (f
)) - 1;
5976 bounds
->bottom
= bounds
->top
+ f
->output_data
.w32
->line_height
- 1;
5983 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5984 pix_x
= FRAME_WINDOW_WIDTH (f
);
5988 else if (pix_y
> f
->height
)
5997 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5998 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5999 can't tell the positions because W's display is not up to date,
6003 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6006 int *frame_x
, *frame_y
;
6010 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6011 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6013 if (display_completed
)
6015 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6016 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6017 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6023 *frame_x
+= glyph
->pixel_width
;
6031 *frame_y
= *frame_x
= 0;
6035 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6036 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6040 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
6041 the state in PUP. XBUTTON provides extra information for extended mouse
6042 button messages. Returns FALSE if unable to parse the message. */
6044 parse_button (message
, xbutton
, pbutton
, pup
)
6055 case WM_LBUTTONDOWN
:
6063 case WM_MBUTTONDOWN
:
6064 if (NILP (Vw32_swap_mouse_buttons
))
6071 if (NILP (Vw32_swap_mouse_buttons
))
6077 case WM_RBUTTONDOWN
:
6078 if (NILP (Vw32_swap_mouse_buttons
))
6085 if (NILP (Vw32_swap_mouse_buttons
))
6091 case WM_XBUTTONDOWN
:
6092 button
= xbutton
+ 2;
6096 button
= xbutton
+ 2;
6104 if (pbutton
) *pbutton
= button
;
6110 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6112 If the event is a button press, then note that we have grabbed
6116 construct_mouse_click (result
, msg
, f
)
6117 struct input_event
*result
;
6124 parse_button (msg
->msg
.message
, HIWORD (msg
->msg
.wParam
),
6127 /* Make the event type no_event; we'll change that when we decide
6129 result
->kind
= mouse_click
;
6130 result
->code
= button
;
6131 result
->timestamp
= msg
->msg
.time
;
6132 result
->modifiers
= (msg
->dwModifiers
6137 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
6138 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
6139 XSETFRAME (result
->frame_or_window
, f
);
6145 construct_mouse_wheel (result
, msg
, f
)
6146 struct input_event
*result
;
6151 result
->kind
= mouse_wheel
;
6152 result
->code
= (short) HIWORD (msg
->msg
.wParam
);
6153 result
->timestamp
= msg
->msg
.time
;
6154 result
->modifiers
= msg
->dwModifiers
;
6155 p
.x
= LOWORD (msg
->msg
.lParam
);
6156 p
.y
= HIWORD (msg
->msg
.lParam
);
6157 ScreenToClient (msg
->msg
.hwnd
, &p
);
6158 XSETINT (result
->x
, p
.x
);
6159 XSETINT (result
->y
, p
.y
);
6160 XSETFRAME (result
->frame_or_window
, f
);
6166 construct_drag_n_drop (result
, msg
, f
)
6167 struct input_event
*result
;
6179 result
->kind
= drag_n_drop
;
6181 result
->timestamp
= msg
->msg
.time
;
6182 result
->modifiers
= msg
->dwModifiers
;
6184 hdrop
= (HDROP
) msg
->msg
.wParam
;
6185 DragQueryPoint (hdrop
, &p
);
6188 p
.x
= LOWORD (msg
->msg
.lParam
);
6189 p
.y
= HIWORD (msg
->msg
.lParam
);
6190 ScreenToClient (msg
->msg
.hwnd
, &p
);
6193 XSETINT (result
->x
, p
.x
);
6194 XSETINT (result
->y
, p
.y
);
6196 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
6199 for (i
= 0; i
< num_files
; i
++)
6201 len
= DragQueryFile (hdrop
, i
, NULL
, 0);
6204 name
= alloca (len
+ 1);
6205 DragQueryFile (hdrop
, i
, name
, len
+ 1);
6206 files
= Fcons (build_string (name
), files
);
6211 XSETFRAME (frame
, f
);
6212 result
->frame_or_window
= Fcons (frame
, files
);
6218 /* Function to report a mouse movement to the mainstream Emacs code.
6219 The input handler calls this.
6221 We have received a mouse movement event, which is given in *event.
6222 If the mouse is over a different glyph than it was last time, tell
6223 the mainstream emacs code by setting mouse_moved. If not, ask for
6224 another motion event, so we can check again the next time it moves. */
6226 static MSG last_mouse_motion_event
;
6227 static Lisp_Object last_mouse_motion_frame
;
6229 static void remember_mouse_glyph
P_ ((struct frame
*, int, int));
6232 note_mouse_movement (frame
, msg
)
6236 int mouse_x
= LOWORD (msg
->lParam
);
6237 int mouse_y
= HIWORD (msg
->lParam
);
6239 last_mouse_movement_time
= msg
->time
;
6240 memcpy (&last_mouse_motion_event
, msg
, sizeof (last_mouse_motion_event
));
6241 XSETFRAME (last_mouse_motion_frame
, frame
);
6243 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
6245 frame
->mouse_moved
= 1;
6246 last_mouse_scroll_bar
= Qnil
;
6247 note_mouse_highlight (frame
, -1, -1);
6250 /* Has the mouse moved off the glyph it was on at the last sighting? */
6251 else if (mouse_x
< last_mouse_glyph
.left
6252 || mouse_x
> last_mouse_glyph
.right
6253 || mouse_y
< last_mouse_glyph
.top
6254 || mouse_y
> last_mouse_glyph
.bottom
)
6256 frame
->mouse_moved
= 1;
6257 last_mouse_scroll_bar
= Qnil
;
6258 note_mouse_highlight (frame
, mouse_x
, mouse_y
);
6259 /* Remember the mouse position here, as w32_mouse_position only
6260 gets called when mouse tracking is enabled but we also need
6261 to keep track of the mouse for help_echo and highlighting at
6263 remember_mouse_glyph (frame
, mouse_x
, mouse_y
);
6267 /* This is used for debugging, to turn off note_mouse_highlight. */
6269 int disable_mouse_highlight
;
6273 /************************************************************************
6275 ************************************************************************/
6277 /* Find the glyph under window-relative coordinates X/Y in window W.
6278 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6279 strings. Return in *HPOS and *VPOS the row and column number of
6280 the glyph found. Return in *AREA the glyph area containing X.
6281 Value is a pointer to the glyph found or null if X/Y is not on
6282 text, or we can't tell because W's current matrix is not up to
6285 static struct glyph
*
6286 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6289 int *hpos
, *vpos
, *area
;
6292 struct glyph
*glyph
, *end
;
6293 struct glyph_row
*row
= NULL
;
6294 int x0
, i
, left_area_width
;
6296 /* Find row containing Y. Give up if some row is not enabled. */
6297 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6299 row
= MATRIX_ROW (w
->current_matrix
, i
);
6300 if (!row
->enabled_p
)
6302 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6309 /* Give up if Y is not in the window. */
6310 if (i
== w
->current_matrix
->nrows
)
6313 /* Get the glyph area containing X. */
6314 if (w
->pseudo_window_p
)
6321 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6322 if (x
< left_area_width
)
6324 *area
= LEFT_MARGIN_AREA
;
6327 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6330 x0
= row
->x
+ left_area_width
;
6334 *area
= RIGHT_MARGIN_AREA
;
6335 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6339 /* Find glyph containing X. */
6340 glyph
= row
->glyphs
[*area
];
6341 end
= glyph
+ row
->used
[*area
];
6344 if (x
< x0
+ glyph
->pixel_width
)
6346 if (w
->pseudo_window_p
)
6348 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6352 x0
+= glyph
->pixel_width
;
6359 *hpos
= glyph
- row
->glyphs
[*area
];
6364 /* Convert frame-relative x/y to coordinates relative to window W.
6365 Takes pseudo-windows into account. */
6368 frame_to_window_pixel_xy (w
, x
, y
)
6372 if (w
->pseudo_window_p
)
6374 /* A pseudo-window is always full-width, and starts at the
6375 left edge of the frame, plus a frame border. */
6376 struct frame
*f
= XFRAME (w
->frame
);
6377 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6378 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6382 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6383 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6388 /* Take proper action when mouse has moved to the mode or header line of
6389 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6390 mode line. X is relative to the start of the text display area of
6391 W, so the width of fringes and scroll bars must be subtracted
6392 to get a position relative to the start of the mode line. */
6395 note_mode_line_highlight (w
, x
, mode_line_p
)
6399 struct frame
*f
= XFRAME (w
->frame
);
6400 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6401 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6402 struct glyph_row
*row
;
6405 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6407 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6411 struct glyph
*glyph
, *end
;
6412 Lisp_Object help
, map
;
6415 /* Find the glyph under X. */
6416 glyph
= row
->glyphs
[TEXT_AREA
];
6417 end
= glyph
+ row
->used
[TEXT_AREA
];
6418 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6419 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
6422 && x
>= x0
+ glyph
->pixel_width
)
6424 x0
+= glyph
->pixel_width
;
6429 && STRINGP (glyph
->object
)
6430 && XSTRING (glyph
->object
)->intervals
6431 && glyph
->charpos
>= 0
6432 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6434 /* If we're on a string with `help-echo' text property,
6435 arrange for the help to be displayed. This is done by
6436 setting the global variable help_echo to the help string. */
6437 help
= Fget_text_property (make_number (glyph
->charpos
),
6438 Qhelp_echo
, glyph
->object
);
6442 XSETWINDOW (help_echo_window
, w
);
6443 help_echo_object
= glyph
->object
;
6444 help_echo_pos
= glyph
->charpos
;
6447 /* Change the mouse pointer according to what is under X/Y. */
6448 map
= Fget_text_property (make_number (glyph
->charpos
),
6449 Qlocal_map
, glyph
->object
);
6451 cursor
= f
->output_data
.w32
->nontext_cursor
;
6454 map
= Fget_text_property (make_number (glyph
->charpos
),
6455 Qkeymap
, glyph
->object
);
6457 cursor
= f
->output_data
.w32
->nontext_cursor
;
6462 #if 0 /* TODO: mouse cursor */
6463 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6468 /* Take proper action when the mouse has moved to position X, Y on
6469 frame F as regards highlighting characters that have mouse-face
6470 properties. Also de-highlighting chars where the mouse was before.
6471 X and Y can be negative or out of range. */
6474 note_mouse_highlight (f
, x
, y
)
6478 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6484 /* When a menu is active, don't highlight because this looks odd. */
6485 if (popup_activated ())
6488 if (disable_mouse_highlight
6489 || !f
->glyphs_initialized_p
)
6492 dpyinfo
->mouse_face_mouse_x
= x
;
6493 dpyinfo
->mouse_face_mouse_y
= y
;
6494 dpyinfo
->mouse_face_mouse_frame
= f
;
6496 if (dpyinfo
->mouse_face_defer
)
6501 dpyinfo
->mouse_face_deferred_gc
= 1;
6505 /* Which window is that in? */
6506 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6508 /* If we were displaying active text in another window, clear that. */
6509 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6510 clear_mouse_face (dpyinfo
);
6512 /* Not on a window -> return. */
6513 if (!WINDOWP (window
))
6516 /* Reset help_echo. It will get recomputed below. */
6519 /* Convert to window-relative pixel coordinates. */
6520 w
= XWINDOW (window
);
6521 frame_to_window_pixel_xy (w
, &x
, &y
);
6523 /* Handle tool-bar window differently since it doesn't display a
6525 if (EQ (window
, f
->tool_bar_window
))
6527 note_tool_bar_highlight (f
, x
, y
);
6531 /* Mouse is on the mode or header line? */
6532 if (portion
== 1 || portion
== 3)
6534 note_mode_line_highlight (w
, x
, portion
== 1);
6537 #if 0 /* TODO: mouse cursor */
6539 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6541 cursor
= f
->output_data
.x
->text_cursor
;
6543 /* Are we in a window whose display is up to date?
6544 And verify the buffer's text has not changed. */
6545 b
= XBUFFER (w
->buffer
);
6546 if (/* Within text portion of the window. */
6548 && EQ (w
->window_end_valid
, w
->buffer
)
6549 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6550 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6552 int hpos
, vpos
, pos
, i
, area
;
6553 struct glyph
*glyph
;
6555 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6556 Lisp_Object
*overlay_vec
= NULL
;
6558 struct buffer
*obuf
;
6559 int obegv
, ozv
, same_region
;
6561 /* Find the glyph under X/Y. */
6562 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6564 /* Clear mouse face if X/Y not over text. */
6566 || area
!= TEXT_AREA
6567 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6569 clear_mouse_face (dpyinfo
);
6570 /* TODO: mouse cursor */
6574 pos
= glyph
->charpos
;
6575 object
= glyph
->object
;
6576 if (!STRINGP (object
) && !BUFFERP (object
))
6579 /* If we get an out-of-range value, return now; avoid an error. */
6580 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6583 /* Make the window's buffer temporarily current for
6584 overlays_at and compute_char_face. */
6585 obuf
= current_buffer
;
6592 /* Is this char mouse-active or does it have help-echo? */
6593 position
= make_number (pos
);
6595 if (BUFFERP (object
))
6597 /* Put all the overlays we want in a vector in overlay_vec.
6598 Store the length in len. If there are more than 10, make
6599 enough space for all, and try again. */
6601 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6602 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6603 if (noverlays
> len
)
6606 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6607 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6610 /* Sort overlays into increasing priority order. */
6611 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6616 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
6617 && vpos
>= dpyinfo
->mouse_face_beg_row
6618 && vpos
<= dpyinfo
->mouse_face_end_row
6619 && (vpos
> dpyinfo
->mouse_face_beg_row
6620 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6621 && (vpos
< dpyinfo
->mouse_face_end_row
6622 || hpos
< dpyinfo
->mouse_face_end_col
6623 || dpyinfo
->mouse_face_past_end
));
6625 /* TODO: if (same_region)
6628 /* Check mouse-face highlighting. */
6630 /* If there exists an overlay with mouse-face overlapping
6631 the one we are currently highlighting, we have to
6632 check if we enter the overlapping overlay, and then
6634 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6635 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6637 /* Find the highest priority overlay that has a mouse-face
6640 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
6642 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6643 if (!NILP (mouse_face
))
6644 overlay
= overlay_vec
[i
];
6647 /* If we're actually highlighting the same overlay as
6648 before, there's no need to do that again. */
6650 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
6651 goto check_help_echo
;
6653 dpyinfo
->mouse_face_overlay
= overlay
;
6655 /* Clear the display of the old active region, if any. */
6656 clear_mouse_face (dpyinfo
);
6657 /* TODO: mouse cursor changes. */
6659 /* If no overlay applies, get a text property. */
6661 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
6663 /* Handle the overlay case. */
6664 if (!NILP (overlay
))
6666 /* Find the range of text around this char that
6667 should be active. */
6668 Lisp_Object before
, after
;
6671 before
= Foverlay_start (overlay
);
6672 after
= Foverlay_end (overlay
);
6673 /* Record this as the current active region. */
6674 fast_find_position (w
, XFASTINT (before
),
6675 &dpyinfo
->mouse_face_beg_col
,
6676 &dpyinfo
->mouse_face_beg_row
,
6677 &dpyinfo
->mouse_face_beg_x
,
6678 &dpyinfo
->mouse_face_beg_y
, Qnil
);
6680 dpyinfo
->mouse_face_past_end
6681 = !fast_find_position (w
, XFASTINT (after
),
6682 &dpyinfo
->mouse_face_end_col
,
6683 &dpyinfo
->mouse_face_end_row
,
6684 &dpyinfo
->mouse_face_end_x
,
6685 &dpyinfo
->mouse_face_end_y
, Qnil
);
6686 dpyinfo
->mouse_face_window
= window
;
6688 dpyinfo
->mouse_face_face_id
6689 = face_at_buffer_position (w
, pos
, 0, 0,
6690 &ignore
, pos
+ 1, 1);
6692 /* Display it as active. */
6693 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6694 /* TODO: mouse cursor changes. */
6696 /* Handle the text property case. */
6697 else if (! NILP (mouse_face
) && BUFFERP (object
))
6699 /* Find the range of text around this char that
6700 should be active. */
6701 Lisp_Object before
, after
, beginning
, end
;
6704 beginning
= Fmarker_position (w
->start
);
6705 end
= make_number (BUF_Z (XBUFFER (object
))
6706 - XFASTINT (w
->window_end_pos
));
6708 = Fprevious_single_property_change (make_number (pos
+ 1),
6712 = Fnext_single_property_change (position
, Qmouse_face
,
6715 /* Record this as the current active region. */
6716 fast_find_position (w
, XFASTINT (before
),
6717 &dpyinfo
->mouse_face_beg_col
,
6718 &dpyinfo
->mouse_face_beg_row
,
6719 &dpyinfo
->mouse_face_beg_x
,
6720 &dpyinfo
->mouse_face_beg_y
, Qnil
);
6721 dpyinfo
->mouse_face_past_end
6722 = !fast_find_position (w
, XFASTINT (after
),
6723 &dpyinfo
->mouse_face_end_col
,
6724 &dpyinfo
->mouse_face_end_row
,
6725 &dpyinfo
->mouse_face_end_x
,
6726 &dpyinfo
->mouse_face_end_y
, Qnil
);
6727 dpyinfo
->mouse_face_window
= window
;
6729 if (BUFFERP (object
))
6730 dpyinfo
->mouse_face_face_id
6731 = face_at_buffer_position (w
, pos
, 0, 0,
6732 &ignore
, pos
+ 1, 1);
6734 /* Display it as active. */
6735 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6736 /* TODO: mouse cursor changes. */
6738 else if (!NILP (mouse_face
) && STRINGP (object
))
6743 b
= Fprevious_single_property_change (make_number (pos
+ 1),
6746 e
= Fnext_single_property_change (position
, Qmouse_face
,
6749 b
= make_number (0);
6751 e
= make_number (XSTRING (object
)->size
- 1);
6752 fast_find_string_pos (w
, XINT (b
), object
,
6753 &dpyinfo
->mouse_face_beg_col
,
6754 &dpyinfo
->mouse_face_beg_row
,
6755 &dpyinfo
->mouse_face_beg_x
,
6756 &dpyinfo
->mouse_face_beg_y
, 0);
6757 fast_find_string_pos (w
, XINT (e
), object
,
6758 &dpyinfo
->mouse_face_end_col
,
6759 &dpyinfo
->mouse_face_end_row
,
6760 &dpyinfo
->mouse_face_end_x
,
6761 &dpyinfo
->mouse_face_end_y
, 1);
6762 dpyinfo
->mouse_face_past_end
= 0;
6763 dpyinfo
->mouse_face_window
= window
;
6764 dpyinfo
->mouse_face_face_id
6765 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
6767 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6768 /* TODO: mouse cursor changes. */
6770 else if (STRINGP (object
) && NILP (mouse_face
))
6772 /* A string which doesn't have mouse-face, but
6773 the text ``under'' it might have. */
6774 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
6775 int start
= MATRIX_ROW_START_CHARPOS (r
);
6777 pos
= string_buffer_position (w
, object
, start
);
6779 mouse_face
= get_char_property_and_overlay (make_number (pos
),
6783 if (!NILP (mouse_face
) && !NILP (overlay
))
6785 Lisp_Object before
= Foverlay_start (overlay
);
6786 Lisp_Object after
= Foverlay_end (overlay
);
6789 /* Note that we might not be able to find position
6790 BEFORE in the glyph matrix if the overlay is
6791 entirely covered by a `display' property. In
6792 this case, we overshoot. So let's stop in
6793 the glyph matrix before glyphs for OBJECT. */
6794 fast_find_position (w
, XFASTINT (before
),
6795 &dpyinfo
->mouse_face_beg_col
,
6796 &dpyinfo
->mouse_face_beg_row
,
6797 &dpyinfo
->mouse_face_beg_x
,
6798 &dpyinfo
->mouse_face_beg_y
,
6801 dpyinfo
->mouse_face_past_end
6802 = !fast_find_position (w
, XFASTINT (after
),
6803 &dpyinfo
->mouse_face_end_col
,
6804 &dpyinfo
->mouse_face_end_row
,
6805 &dpyinfo
->mouse_face_end_x
,
6806 &dpyinfo
->mouse_face_end_y
,
6808 dpyinfo
->mouse_face_window
= window
;
6809 dpyinfo
->mouse_face_face_id
6810 = face_at_buffer_position (w
, pos
, 0, 0,
6811 &ignore
, pos
+ 1, 1);
6813 /* Display it as active. */
6814 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6815 /* TODO: mouse cursor changes. */
6822 /* Look for a `help-echo' property. */
6824 Lisp_Object help
, overlay
;
6826 /* Check overlays first. */
6827 help
= overlay
= Qnil
;
6828 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6830 overlay
= overlay_vec
[i
];
6831 help
= Foverlay_get (overlay
, Qhelp_echo
);
6837 help_echo_window
= window
;
6838 help_echo_object
= overlay
;
6839 help_echo_pos
= pos
;
6843 Lisp_Object object
= glyph
->object
;
6844 int charpos
= glyph
->charpos
;
6846 /* Try text properties. */
6847 if (STRINGP (object
)
6849 && charpos
< XSTRING (object
)->size
)
6851 help
= Fget_text_property (make_number (charpos
),
6852 Qhelp_echo
, object
);
6855 /* If the string itself doesn't specify a help-echo,
6856 see if the buffer text ``under'' it does. */
6858 = MATRIX_ROW (w
->current_matrix
, vpos
);
6859 int start
= MATRIX_ROW_START_CHARPOS (r
);
6860 int pos
= string_buffer_position (w
, object
, start
);
6863 help
= Fget_char_property (make_number (pos
),
6864 Qhelp_echo
, w
->buffer
);
6873 else if (BUFFERP (object
)
6876 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
6882 help_echo_window
= window
;
6883 help_echo_object
= object
;
6884 help_echo_pos
= charpos
;
6891 current_buffer
= obuf
;
6895 /* TODO: mouse cursor changes. */
6900 redo_mouse_highlight ()
6902 if (!NILP (last_mouse_motion_frame
)
6903 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6904 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6905 LOWORD (last_mouse_motion_event
.lParam
),
6906 HIWORD (last_mouse_motion_event
.lParam
));
6911 /***********************************************************************
6913 ***********************************************************************/
6915 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6916 struct glyph
**, int *, int *, int *));
6918 /* Tool-bar item index of the item on which a mouse button was pressed
6921 static int last_tool_bar_item
;
6924 /* Get information about the tool-bar item at position X/Y on frame F.
6925 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6926 the current matrix of the tool-bar window of F, or NULL if not
6927 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6928 item in F->tool_bar_items. Value is
6930 -1 if X/Y is not on a tool-bar item
6931 0 if X/Y is on the same item that was highlighted before.
6935 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6938 struct glyph
**glyph
;
6939 int *hpos
, *vpos
, *prop_idx
;
6941 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6942 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6945 /* Find the glyph under X/Y. */
6946 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
6950 /* Get the start of this tool-bar item's properties in
6951 f->tool_bar_items. */
6952 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6955 /* Is mouse on the highlighted item? */
6956 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6957 && *vpos
>= dpyinfo
->mouse_face_beg_row
6958 && *vpos
<= dpyinfo
->mouse_face_end_row
6959 && (*vpos
> dpyinfo
->mouse_face_beg_row
6960 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6961 && (*vpos
< dpyinfo
->mouse_face_end_row
6962 || *hpos
< dpyinfo
->mouse_face_end_col
6963 || dpyinfo
->mouse_face_past_end
))
6970 /* Handle mouse button event on the tool-bar of frame F, at
6971 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6975 w32_handle_tool_bar_click (f
, button_event
)
6977 struct input_event
*button_event
;
6979 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6980 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6981 int hpos
, vpos
, prop_idx
;
6982 struct glyph
*glyph
;
6983 Lisp_Object enabled_p
;
6984 int x
= XFASTINT (button_event
->x
);
6985 int y
= XFASTINT (button_event
->y
);
6987 /* If not on the highlighted tool-bar item, return. */
6988 frame_to_window_pixel_xy (w
, &x
, &y
);
6989 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6992 /* If item is disabled, do nothing. */
6993 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6994 if (NILP (enabled_p
))
6997 if (button_event
->kind
== mouse_click
)
6999 /* Show item in pressed state. */
7000 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7001 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7002 last_tool_bar_item
= prop_idx
;
7006 Lisp_Object key
, frame
;
7007 struct input_event event
;
7009 /* Show item in released state. */
7010 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7011 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7013 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7015 XSETFRAME (frame
, f
);
7016 event
.kind
= TOOL_BAR_EVENT
;
7017 event
.frame_or_window
= frame
;
7019 kbd_buffer_store_event (&event
);
7021 event
.kind
= TOOL_BAR_EVENT
;
7022 event
.frame_or_window
= frame
;
7024 event
.modifiers
= button_event
->modifiers
;
7025 kbd_buffer_store_event (&event
);
7026 last_tool_bar_item
= -1;
7031 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7032 tool-bar window-relative coordinates X/Y. Called from
7033 note_mouse_highlight. */
7036 note_tool_bar_highlight (f
, x
, y
)
7040 Lisp_Object window
= f
->tool_bar_window
;
7041 struct window
*w
= XWINDOW (window
);
7042 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7044 struct glyph
*glyph
;
7045 struct glyph_row
*row
;
7047 Lisp_Object enabled_p
;
7049 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7050 int mouse_down_p
, rc
;
7052 /* Function note_mouse_highlight is called with negative x(y
7053 values when mouse moves outside of the frame. */
7054 if (x
<= 0 || y
<= 0)
7056 clear_mouse_face (dpyinfo
);
7060 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7063 /* Not on tool-bar item. */
7064 clear_mouse_face (dpyinfo
);
7068 /* On same tool-bar item as before. */
7071 clear_mouse_face (dpyinfo
);
7073 /* Mouse is down, but on different tool-bar item? */
7074 mouse_down_p
= (dpyinfo
->grabbed
7075 && f
== last_mouse_frame
7076 && FRAME_LIVE_P (f
));
7078 && last_tool_bar_item
!= prop_idx
)
7081 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7082 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7084 /* If tool-bar item is not enabled, don't highlight it. */
7085 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7086 if (!NILP (enabled_p
))
7088 /* Compute the x-position of the glyph. In front and past the
7089 image is a space. We include this is the highlighted area. */
7090 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7091 for (i
= x
= 0; i
< hpos
; ++i
)
7092 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7094 /* Record this as the current active region. */
7095 dpyinfo
->mouse_face_beg_col
= hpos
;
7096 dpyinfo
->mouse_face_beg_row
= vpos
;
7097 dpyinfo
->mouse_face_beg_x
= x
;
7098 dpyinfo
->mouse_face_beg_y
= row
->y
;
7099 dpyinfo
->mouse_face_past_end
= 0;
7101 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7102 dpyinfo
->mouse_face_end_row
= vpos
;
7103 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7104 dpyinfo
->mouse_face_end_y
= row
->y
;
7105 dpyinfo
->mouse_face_window
= window
;
7106 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7108 /* Display it as active. */
7109 show_mouse_face (dpyinfo
, draw
);
7110 dpyinfo
->mouse_face_image_state
= draw
;
7115 /* Set help_echo to a help string.to display for this tool-bar item.
7116 w32_read_socket does the rest. */
7117 help_echo_object
= help_echo_window
= Qnil
;
7119 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7120 if (NILP (help_echo
))
7121 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7126 /* Find the glyph matrix position of buffer position CHARPOS in window
7127 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7128 current glyphs must be up to date. If CHARPOS is above window
7129 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7130 of last line in W. In the row containing CHARPOS, stop before glyphs
7131 having STOP as object. */
7133 #if 0 /* This is a version of fast_find_position that's more correct
7134 in the presence of hscrolling, for example. I didn't install
7135 it right away because the problem fixed is minor, it failed
7136 in 20.x as well, and I think it's too risky to install
7137 so near the release of 21.1. 2001-09-25 gerd. */
7140 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7143 int *hpos
, *vpos
, *x
, *y
;
7146 struct glyph_row
*row
, *first
;
7147 struct glyph
*glyph
, *end
;
7148 int i
, past_end
= 0;
7150 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7151 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7154 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7156 *x
= *y
= *hpos
= *vpos
= 0;
7161 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7168 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7170 glyph
= row
->glyphs
[TEXT_AREA
];
7171 end
= glyph
+ row
->used
[TEXT_AREA
];
7173 /* Skip over glyphs not having an object at the start of the row.
7174 These are special glyphs like truncation marks on terminal
7176 if (row
->displays_text_p
)
7178 && INTEGERP (glyph
->object
)
7179 && !EQ (stop
, glyph
->object
)
7180 && glyph
->charpos
< 0)
7182 *x
+= glyph
->pixel_width
;
7187 && !INTEGERP (glyph
->object
)
7188 && !EQ (stop
, glyph
->object
)
7189 && (!BUFFERP (glyph
->object
)
7190 || glyph
->charpos
< charpos
))
7192 *x
+= glyph
->pixel_width
;
7196 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7203 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7206 int *hpos
, *vpos
, *x
, *y
;
7211 int maybe_next_line_p
= 0;
7212 int line_start_position
;
7213 int yb
= window_text_bottom_y (w
);
7214 struct glyph_row
*row
, *best_row
;
7215 int row_vpos
, best_row_vpos
;
7218 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7219 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7223 if (row
->used
[TEXT_AREA
])
7224 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7226 line_start_position
= 0;
7228 if (line_start_position
> pos
)
7230 /* If the position sought is the end of the buffer,
7231 don't include the blank lines at the bottom of the window. */
7232 else if (line_start_position
== pos
7233 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7235 maybe_next_line_p
= 1;
7238 else if (line_start_position
> 0)
7241 best_row_vpos
= row_vpos
;
7244 if (row
->y
+ row
->height
>= yb
)
7251 /* Find the right column within BEST_ROW. */
7253 current_x
= best_row
->x
;
7254 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7256 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7257 int charpos
= glyph
->charpos
;
7259 if (BUFFERP (glyph
->object
))
7264 *vpos
= best_row_vpos
;
7269 else if (charpos
> pos
)
7272 else if (EQ (glyph
->object
, stop
))
7277 current_x
+= glyph
->pixel_width
;
7280 /* If we're looking for the end of the buffer,
7281 and we didn't find it in the line we scanned,
7282 use the start of the following line. */
7283 if (maybe_next_line_p
)
7288 current_x
= best_row
->x
;
7291 *vpos
= best_row_vpos
;
7292 *hpos
= lastcol
+ 1;
7301 /* Find the position of the glyph for position POS in OBJECT in
7302 window W's current matrix, and return in *X/*Y the pixel
7303 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7305 RIGHT_P non-zero means return the position of the right edge of the
7306 glyph, RIGHT_P zero means return the left edge position.
7308 If no glyph for POS exists in the matrix, return the position of
7309 the glyph with the next smaller position that is in the matrix, if
7310 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7311 exists in the matrix, return the position of the glyph with the
7312 next larger position in OBJECT.
7314 Value is non-zero if a glyph was found. */
7317 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7321 int *hpos
, *vpos
, *x
, *y
;
7324 int yb
= window_text_bottom_y (w
);
7325 struct glyph_row
*r
;
7326 struct glyph
*best_glyph
= NULL
;
7327 struct glyph_row
*best_row
= NULL
;
7330 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7331 r
->enabled_p
&& r
->y
< yb
;
7334 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7335 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7338 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7339 if (EQ (g
->object
, object
))
7341 if (g
->charpos
== pos
)
7348 else if (best_glyph
== NULL
7349 || ((abs (g
->charpos
- pos
)
7350 < abs (best_glyph
->charpos
- pos
))
7353 : g
->charpos
> pos
)))
7367 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7371 *x
+= best_glyph
->pixel_width
;
7376 *vpos
= best_row
- w
->current_matrix
->rows
;
7379 return best_glyph
!= NULL
;
7383 /* Display the active region described by mouse_face_*
7384 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7387 show_mouse_face (dpyinfo
, draw
)
7388 struct w32_display_info
*dpyinfo
;
7389 enum draw_glyphs_face draw
;
7391 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7392 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7394 if (/* If window is in the process of being destroyed, don't bother
7396 w
->current_matrix
!= NULL
7397 /* Recognize when we are called to operate on rows that don't exist
7398 anymore. This can happen when a window is split. */
7399 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7401 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7402 struct glyph_row
*row
, *first
, *last
;
7404 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7405 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7407 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7409 int start_hpos
, end_hpos
, start_x
;
7411 /* For all but the first row, the highlight starts at column 0. */
7414 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7415 start_x
= dpyinfo
->mouse_face_beg_x
;
7424 end_hpos
= dpyinfo
->mouse_face_end_col
;
7426 end_hpos
= row
->used
[TEXT_AREA
];
7428 if (end_hpos
> start_hpos
)
7430 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7431 start_hpos
, end_hpos
, draw
, 0);
7434 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
7438 /* When we've written over the cursor, arrange for it to
7439 be displayed again. */
7440 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
7441 x_display_cursor (w
, 1,
7442 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
7443 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
7446 #if 0 /* TODO: mouse cursor */
7447 /* Change the mouse cursor. */
7448 if (draw
== DRAW_NORMAL_TEXT
)
7449 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7450 f
->output_data
.x
->text_cursor
);
7451 else if (draw
== DRAW_MOUSE_FACE
)
7452 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7453 f
->output_data
.x
->cross_cursor
);
7455 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7456 f
->output_data
.x
->nontext_cursor
);
7460 /* Clear out the mouse-highlighted active region.
7461 Redraw it un-highlighted first. */
7464 clear_mouse_face (dpyinfo
)
7465 struct w32_display_info
*dpyinfo
;
7469 if (! NILP (dpyinfo
->mouse_face_window
))
7471 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7475 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7476 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7477 dpyinfo
->mouse_face_window
= Qnil
;
7478 dpyinfo
->mouse_face_overlay
= Qnil
;
7483 /* Clear any mouse-face on window W. This function is part of the
7484 redisplay interface, and is called from try_window_id and similar
7485 functions to ensure the mouse-highlight is off. */
7488 x_clear_mouse_face (w
)
7491 struct w32_display_info
*dpyinfo
7492 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
7496 XSETWINDOW (window
, w
);
7497 if (EQ (window
, dpyinfo
->mouse_face_window
))
7498 clear_mouse_face (dpyinfo
);
7503 /* Just discard the mouse face information for frame F, if any.
7504 This is used when the size of F is changed. */
7507 cancel_mouse_face (f
)
7511 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7513 window
= dpyinfo
->mouse_face_window
;
7514 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7516 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7517 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7518 dpyinfo
->mouse_face_window
= Qnil
;
7522 static struct scroll_bar
*x_window_to_scroll_bar ();
7523 static void x_scroll_bar_report_motion ();
7524 static int glyph_rect
P_ ((struct frame
*f
, int, int, RECT
*));
7527 /* Try to determine frame pixel position and size of the glyph under
7528 frame pixel coordinates X/Y on frame F . Return the position and
7529 size in *RECT. Value is non-zero if we could compute these
7533 glyph_rect (f
, x
, y
, rect
)
7539 int part
, found
= 0;
7541 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7544 struct window
*w
= XWINDOW (window
);
7545 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7546 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7548 frame_to_window_pixel_xy (w
, &x
, &y
);
7550 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7551 if (r
->y
+ r
->height
>= y
)
7553 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7554 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7557 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7558 if (gx
+ g
->pixel_width
>= x
)
7560 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7561 rect
->top
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7562 rect
->right
= rect
->left
+ g
->pixel_width
;
7563 rect
->bottom
= rect
->top
+ r
->height
;
7572 /* Record the position of the mouse in last_mouse_glyph. */
7574 remember_mouse_glyph (f1
, gx
, gy
)
7578 if (!glyph_rect (f1
, gx
, gy
, &last_mouse_glyph
))
7580 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7581 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7583 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7584 round down even for negative values. */
7590 /* This was the original code from XTmouse_position, but it seems
7591 to give the position of the glyph diagonally next to the one
7592 the mouse is over. */
7593 gx
= (gx
+ width
- 1) / width
* width
;
7594 gy
= (gy
+ height
- 1) / height
* height
;
7596 gx
= gx
/ width
* width
;
7597 gy
= gy
/ height
* height
;
7600 last_mouse_glyph
.left
= gx
;
7601 last_mouse_glyph
.top
= gy
;
7602 last_mouse_glyph
.right
= gx
+ width
;
7603 last_mouse_glyph
.bottom
= gy
+ height
;
7607 /* Return the current position of the mouse.
7608 *fp should be a frame which indicates which display to ask about.
7610 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7611 and *part to the frame, window, and scroll bar part that the mouse
7612 is over. Set *x and *y to the portion and whole of the mouse's
7613 position on the scroll bar.
7615 If the mouse movement started elsewhere, set *fp to the frame the
7616 mouse is on, *bar_window to nil, and *x and *y to the character cell
7619 Set *time to the server time-stamp for the time at which the mouse
7620 was at this position.
7622 Don't store anything if we don't have a valid set of values to report.
7624 This clears the mouse_moved flag, so we can wait for the next mouse
7628 w32_mouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7631 Lisp_Object
*bar_window
;
7632 enum scroll_bar_part
*part
;
7634 unsigned long *time
;
7640 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7641 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7646 Lisp_Object frame
, tail
;
7648 /* Clear the mouse-moved flag for every frame on this display. */
7649 FOR_EACH_FRAME (tail
, frame
)
7650 XFRAME (frame
)->mouse_moved
= 0;
7652 last_mouse_scroll_bar
= Qnil
;
7656 /* Now we have a position on the root; find the innermost window
7657 containing the pointer. */
7659 if (FRAME_W32_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7660 && FRAME_LIVE_P (last_mouse_frame
))
7662 /* If mouse was grabbed on a frame, give coords for that frame
7663 even if the mouse is now outside it. */
7664 f1
= last_mouse_frame
;
7668 /* Is window under mouse one of our frames? */
7669 f1
= x_any_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp
),
7670 WindowFromPoint (pt
));
7673 /* If not, is it one of our scroll bars? */
7676 struct scroll_bar
*bar
7677 = x_window_to_scroll_bar (WindowFromPoint (pt
));
7681 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7685 if (f1
== 0 && insist
> 0)
7686 f1
= SELECTED_FRAME ();
7690 /* Ok, we found a frame. Store all the values.
7691 last_mouse_glyph is a rectangle used to reduce the
7692 generation of mouse events. To not miss any motion
7693 events, we must divide the frame into rectangles of the
7694 size of the smallest character that could be displayed
7695 on it, i.e. into the same rectangles that matrices on
7696 the frame are divided into. */
7698 #if OLD_REDISPLAY_CODE
7699 int ignore1
, ignore2
;
7701 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7703 pixel_to_glyph_coords (f1
, pt
.x
, pt
.y
, &ignore1
, &ignore2
,
7705 FRAME_W32_DISPLAY_INFO (f1
)->grabbed
7708 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7709 remember_mouse_glyph (f1
, pt
.x
, pt
.y
);
7717 *time
= last_mouse_movement_time
;
7726 /* Scroll bar support. */
7728 /* Given a window ID, find the struct scroll_bar which manages it.
7729 This can be called in GC, so we have to make sure to strip off mark
7732 static struct scroll_bar
*
7733 x_window_to_scroll_bar (window_id
)
7738 for (tail
= Vframe_list
;
7739 XGCTYPE (tail
) == Lisp_Cons
;
7742 Lisp_Object frame
, bar
, condemned
;
7744 frame
= XCAR (tail
);
7745 /* All elements of Vframe_list should be frames. */
7746 if (! GC_FRAMEP (frame
))
7749 /* Scan this frame's scroll bar list for a scroll bar with the
7751 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7752 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7753 /* This trick allows us to search both the ordinary and
7754 condemned scroll bar lists with one loop. */
7755 ! GC_NILP (bar
) || (bar
= condemned
,
7758 bar
= XSCROLL_BAR (bar
)->next
)
7759 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7760 return XSCROLL_BAR (bar
);
7768 /* Set the thumb size and position of scroll bar BAR. We are currently
7769 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7772 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
)
7773 struct scroll_bar
*bar
;
7774 int portion
, position
, whole
;
7776 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7777 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7778 int sb_page
, sb_pos
;
7779 BOOL draggingp
= !NILP (bar
->dragging
) ? TRUE
: FALSE
;
7783 /* Position scroll bar at rock bottom if the bottom of the
7784 buffer is visible. This avoids shinking the thumb away
7785 to nothing if it is held at the bottom of the buffer. */
7786 if (position
+ portion
>= whole
)
7788 sb_page
= range
* (whole
- position
) / whole
7789 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7793 sb_page
= portion
* range
/ whole
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7794 sb_pos
= position
* range
/ whole
;
7804 if (pfnSetScrollInfo
)
7808 si
.cbSize
= sizeof (si
);
7809 /* Only update page size if currently dragging, to reduce
7812 si
.fMask
= SIF_PAGE
;
7814 si
.fMask
= SIF_PAGE
| SIF_POS
;
7818 pfnSetScrollInfo (w
, SB_CTL
, &si
, !draggingp
);
7821 SetScrollPos (w
, SB_CTL
, sb_pos
, !draggingp
);
7827 /************************************************************************
7828 Scroll bars, general
7829 ************************************************************************/
7832 my_create_scrollbar (f
, bar
)
7834 struct scroll_bar
* bar
;
7836 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
7837 WM_EMACS_CREATESCROLLBAR
, (WPARAM
) f
,
7841 //#define ATTACH_THREADS
7844 my_show_window (FRAME_PTR f
, HWND hwnd
, int how
)
7846 #ifndef ATTACH_THREADS
7847 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
7848 (WPARAM
) hwnd
, (LPARAM
) how
);
7850 return ShowWindow (hwnd
, how
);
7855 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
7856 int x
, int y
, int cx
, int cy
, UINT flags
)
7858 #ifndef ATTACH_THREADS
7860 pos
.hwndInsertAfter
= hwndAfter
;
7866 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
7868 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
7873 my_set_focus (f
, hwnd
)
7877 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
7882 my_set_foreground_window (hwnd
)
7885 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
7889 my_destroy_window (f
, hwnd
)
7893 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
7897 /* Create a scroll bar and return the scroll bar vector for it. W is
7898 the Emacs window on which to create the scroll bar. TOP, LEFT,
7899 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7902 static struct scroll_bar
*
7903 x_scroll_bar_create (w
, top
, left
, width
, height
)
7905 int top
, left
, width
, height
;
7907 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7909 struct scroll_bar
*bar
7910 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7914 XSETWINDOW (bar
->window
, w
);
7915 XSETINT (bar
->top
, top
);
7916 XSETINT (bar
->left
, left
);
7917 XSETINT (bar
->width
, width
);
7918 XSETINT (bar
->height
, height
);
7919 XSETINT (bar
->start
, 0);
7920 XSETINT (bar
->end
, 0);
7921 bar
->dragging
= Qnil
;
7923 /* Requires geometry to be set before call to create the real window */
7925 hwnd
= my_create_scrollbar (f
, bar
);
7927 if (pfnSetScrollInfo
)
7931 si
.cbSize
= sizeof (si
);
7934 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
7935 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7939 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
7943 SetScrollRange (hwnd
, SB_CTL
, 0,
7944 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
7945 SetScrollPos (hwnd
, SB_CTL
, 0, FALSE
);
7948 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
7950 /* Add bar to its frame's list of scroll bars. */
7951 bar
->next
= FRAME_SCROLL_BARS (f
);
7953 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7954 if (! NILP (bar
->next
))
7955 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7963 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7967 x_scroll_bar_remove (bar
)
7968 struct scroll_bar
*bar
;
7970 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7974 /* Destroy the window. */
7975 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
7977 /* Disassociate this scroll bar from its window. */
7978 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7983 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7984 that we are displaying PORTION characters out of a total of WHOLE
7985 characters, starting at POSITION. If WINDOW has no scroll bar,
7988 w32_set_vertical_scroll_bar (w
, portion
, whole
, position
)
7990 int portion
, whole
, position
;
7992 struct frame
*f
= XFRAME (w
->frame
);
7993 struct scroll_bar
*bar
;
7994 int top
, height
, left
, sb_left
, width
, sb_width
;
7995 int window_x
, window_y
, window_width
, window_height
;
7997 /* Get window dimensions. */
7998 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8000 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8001 height
= window_height
;
8003 /* Compute the left edge of the scroll bar area. */
8004 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8005 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8007 left
= XFASTINT (w
->left
);
8008 left
*= CANON_X_UNIT (f
);
8009 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8011 /* Compute the width of the scroll bar which might be less than
8012 the width of the area reserved for the scroll bar. */
8013 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8014 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8018 /* Compute the left edge of the scroll bar. */
8019 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8020 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8022 sb_left
= left
+ (width
- sb_width
) / 2;
8024 /* Does the scroll bar exist yet? */
8025 if (NILP (w
->vertical_scroll_bar
))
8029 if (width
> 0 && height
> 0)
8031 hdc
= get_frame_dc (f
);
8032 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
8033 release_frame_dc (f
, hdc
);
8037 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8041 /* It may just need to be moved and resized. */
8044 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8045 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
8047 /* If already correctly positioned, do nothing. */
8048 if ( XINT (bar
->left
) == sb_left
8049 && XINT (bar
->top
) == top
8050 && XINT (bar
->width
) == sb_width
8051 && XINT (bar
->height
) == height
)
8053 /* Redraw after clear_frame. */
8054 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
8055 InvalidateRect (hwnd
, NULL
, FALSE
);
8061 if (width
&& height
)
8063 hdc
= get_frame_dc (f
);
8064 /* Since Windows scroll bars are smaller than the space reserved
8065 for them on the frame, we have to clear "under" them. */
8066 w32_clear_area (f
, hdc
,
8071 release_frame_dc (f
, hdc
);
8073 /* Make sure scroll bar is "visible" before moving, to ensure the
8074 area of the parent window now exposed will be refreshed. */
8075 my_show_window (f
, hwnd
, SW_HIDE
);
8076 MoveWindow (hwnd
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8077 top
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8078 max (height
, 1), TRUE
);
8079 if (pfnSetScrollInfo
)
8083 si
.cbSize
= sizeof (si
);
8084 si
.fMask
= SIF_RANGE
;
8086 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
8087 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8089 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
8092 SetScrollRange (hwnd
, SB_CTL
, 0,
8093 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
8094 my_show_window (f
, hwnd
, SW_NORMAL
);
8095 // InvalidateRect (w, NULL, FALSE);
8097 /* Remember new settings. */
8098 XSETINT (bar
->left
, sb_left
);
8099 XSETINT (bar
->top
, top
);
8100 XSETINT (bar
->width
, sb_width
);
8101 XSETINT (bar
->height
, height
);
8106 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
8108 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8112 /* The following three hooks are used when we're doing a thorough
8113 redisplay of the frame. We don't explicitly know which scroll bars
8114 are going to be deleted, because keeping track of when windows go
8115 away is a real pain - "Can you say set-window-configuration, boys
8116 and girls?" Instead, we just assert at the beginning of redisplay
8117 that *all* scroll bars are to be removed, and then save a scroll bar
8118 from the fiery pit when we actually redisplay its window. */
8120 /* Arrange for all scroll bars on FRAME to be removed at the next call
8121 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8122 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8125 w32_condemn_scroll_bars (frame
)
8128 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8129 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8132 bar
= FRAME_SCROLL_BARS (frame
);
8133 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8134 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8135 XSCROLL_BAR (bar
)->prev
= Qnil
;
8136 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8137 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8138 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8143 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8144 Note that WINDOW isn't necessarily condemned at all. */
8147 w32_redeem_scroll_bar (window
)
8148 struct window
*window
;
8150 struct scroll_bar
*bar
;
8153 /* We can't redeem this window's scroll bar if it doesn't have one. */
8154 if (NILP (window
->vertical_scroll_bar
))
8157 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8159 /* Unlink it from the condemned list. */
8160 f
= XFRAME (WINDOW_FRAME (window
));
8161 if (NILP (bar
->prev
))
8163 /* If the prev pointer is nil, it must be the first in one of
8165 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8166 /* It's not condemned. Everything's fine. */
8168 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8169 window
->vertical_scroll_bar
))
8170 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8172 /* If its prev pointer is nil, it must be at the front of
8173 one or the other! */
8177 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8179 if (! NILP (bar
->next
))
8180 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8182 bar
->next
= FRAME_SCROLL_BARS (f
);
8184 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8185 if (! NILP (bar
->next
))
8186 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8189 /* Remove all scroll bars on FRAME that haven't been saved since the
8190 last call to `*condemn_scroll_bars_hook'. */
8193 w32_judge_scroll_bars (f
)
8196 Lisp_Object bar
, next
;
8198 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8200 /* Clear out the condemned list now so we won't try to process any
8201 more events on the hapless scroll bars. */
8202 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8204 for (; ! NILP (bar
); bar
= next
)
8206 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8208 x_scroll_bar_remove (b
);
8211 b
->next
= b
->prev
= Qnil
;
8214 /* Now there should be no references to the condemned scroll bars,
8215 and they should get garbage-collected. */
8218 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8219 is set to something other than no_event, it is enqueued.
8221 This may be called from a signal handler, so we have to ignore GC
8225 w32_scroll_bar_handle_click (bar
, msg
, emacs_event
)
8226 struct scroll_bar
*bar
;
8228 struct input_event
*emacs_event
;
8230 if (! GC_WINDOWP (bar
->window
))
8233 emacs_event
->kind
= w32_scroll_bar_click
;
8234 emacs_event
->code
= 0;
8235 /* not really meaningful to distinguish up/down */
8236 emacs_event
->modifiers
= msg
->dwModifiers
;
8237 emacs_event
->frame_or_window
= bar
->window
;
8238 emacs_event
->arg
= Qnil
;
8239 emacs_event
->timestamp
= msg
->msg
.time
;
8242 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8244 int dragging
= !NILP (bar
->dragging
);
8246 if (pfnGetScrollInfo
)
8250 si
.cbSize
= sizeof (si
);
8253 pfnGetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
8257 y
= GetScrollPos ((HWND
) msg
->msg
.lParam
, SB_CTL
);
8259 bar
->dragging
= Qnil
;
8262 last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
8264 switch (LOWORD (msg
->msg
.wParam
))
8267 emacs_event
->part
= scroll_bar_down_arrow
;
8270 emacs_event
->part
= scroll_bar_up_arrow
;
8273 emacs_event
->part
= scroll_bar_above_handle
;
8276 emacs_event
->part
= scroll_bar_below_handle
;
8279 emacs_event
->part
= scroll_bar_handle
;
8283 emacs_event
->part
= scroll_bar_handle
;
8287 case SB_THUMBPOSITION
:
8288 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
8289 y
= HIWORD (msg
->msg
.wParam
);
8291 emacs_event
->part
= scroll_bar_handle
;
8293 /* "Silently" update current position. */
8294 if (pfnSetScrollInfo
)
8298 si
.cbSize
= sizeof (si
);
8301 /* Remember apparent position (we actually lag behind the real
8302 position, so don't set that directly. */
8303 last_scroll_bar_drag_pos
= y
;
8305 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
8308 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, FALSE
);
8311 /* If this is the end of a drag sequence, then reset the scroll
8312 handle size to normal and do a final redraw. Otherwise do
8316 if (pfnSetScrollInfo
)
8319 int start
= XINT (bar
->start
);
8320 int end
= XINT (bar
->end
);
8322 si
.cbSize
= sizeof (si
);
8323 si
.fMask
= SIF_PAGE
| SIF_POS
;
8324 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8325 si
.nPos
= last_scroll_bar_drag_pos
;
8326 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
8329 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, TRUE
);
8333 emacs_event
->kind
= no_event
;
8337 XSETINT (emacs_event
->x
, y
);
8338 XSETINT (emacs_event
->y
, top_range
);
8344 /* Return information to the user about the current position of the mouse
8345 on the scroll bar. */
8348 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8350 Lisp_Object
*bar_window
;
8351 enum scroll_bar_part
*part
;
8353 unsigned long *time
;
8355 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8356 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
8357 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8359 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8364 *bar_window
= bar
->window
;
8366 if (pfnGetScrollInfo
)
8370 si
.cbSize
= sizeof (si
);
8371 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
8373 pfnGetScrollInfo (w
, SB_CTL
, &si
);
8375 top_range
= si
.nMax
- si
.nPage
+ 1;
8378 pos
= GetScrollPos (w
, SB_CTL
);
8380 switch (LOWORD (last_mouse_scroll_bar_pos
))
8382 case SB_THUMBPOSITION
:
8384 *part
= scroll_bar_handle
;
8385 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
8386 pos
= HIWORD (last_mouse_scroll_bar_pos
);
8389 *part
= scroll_bar_handle
;
8393 *part
= scroll_bar_handle
;
8398 XSETINT (*y
, top_range
);
8401 last_mouse_scroll_bar
= Qnil
;
8403 *time
= last_mouse_movement_time
;
8409 /* The screen has been cleared so we may have changed foreground or
8410 background colors, and the scroll bars may need to be redrawn.
8411 Clear out the scroll bars, and ask for expose events, so we can
8415 x_scroll_bar_clear (f
)
8420 /* We can have scroll bars even if this is 0,
8421 if we just turned off scroll bar mode.
8422 But in that case we should not clear them. */
8423 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8424 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8425 bar
= XSCROLL_BAR (bar
)->next
)
8427 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
8428 HDC hdc
= GetDC (window
);
8431 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
8432 arranges to refresh the scroll bar if hidden. */
8433 my_show_window (f
, window
, SW_HIDE
);
8435 GetClientRect (window
, &rect
);
8436 select_palette (f
, hdc
);
8437 w32_clear_rect (f
, hdc
, &rect
);
8438 deselect_palette (f
, hdc
);
8440 ReleaseDC (window
, hdc
);
8445 /* The main W32 event-reading loop - w32_read_socket. */
8447 /* Time stamp of enter window event. This is only used by w32_read_socket,
8448 but we have to put it out here, since static variables within functions
8449 sometimes don't work. */
8451 static Time enter_timestamp
;
8453 /* Record the last 100 characters stored
8454 to help debug the loss-of-chars-during-GC problem. */
8456 static int temp_index
;
8457 static short temp_buffer
[100];
8460 /* Read events coming from the W32 shell.
8461 This routine is called by the SIGIO handler.
8462 We return as soon as there are no more events to be read.
8464 Events representing keys are stored in buffer BUFP,
8465 which can hold up to NUMCHARS characters.
8466 We return the number of characters stored into the buffer,
8467 thus pretending to be `read'.
8469 EXPECTED is nonzero if the caller knows input is available.
8471 Some of these messages are reposted back to the message queue since the
8472 system calls the windows proc directly in a context where we cannot return
8473 the data nor can we guarantee the state we are in. So if we dispatch them
8474 we will get into an infinite loop. To prevent this from ever happening we
8475 will set a variable to indicate we are in the read_socket call and indicate
8476 which message we are processing since the windows proc gets called
8477 recursively with different messages by the system.
8481 w32_read_socket (sd
, bufp
, numchars
, expected
)
8483 /* register */ struct input_event
*bufp
;
8484 /* register */ int numchars
;
8488 int check_visibility
= 0;
8491 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
8493 if (interrupt_input_blocked
)
8495 interrupt_input_pending
= 1;
8499 interrupt_input_pending
= 0;
8502 /* So people can tell when we have read the available input. */
8503 input_signal_count
++;
8506 abort (); /* Don't think this happens. */
8508 /* TODO: tool-bars, ghostscript integration, mouse
8510 while (get_next_msg (&msg
, FALSE
))
8512 switch (msg
.msg
.message
)
8515 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8519 if (msg
.rect
.right
== msg
.rect
.left
||
8520 msg
.rect
.bottom
== msg
.rect
.top
)
8522 /* We may get paint messages even though the client
8523 area is clipped - these are not expose events. */
8524 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
8525 XSTRING (f
->name
)->data
));
8527 else if (f
->async_visible
!= 1)
8529 /* Definitely not obscured, so mark as visible. */
8530 f
->async_visible
= 1;
8531 f
->async_iconified
= 0;
8532 SET_FRAME_GARBAGED (f
);
8533 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
8534 XSTRING (f
->name
)->data
));
8536 /* WM_PAINT serves as MapNotify as well, so report
8537 visibility changes properly. */
8540 bufp
->kind
= deiconify_event
;
8541 XSETFRAME (bufp
->frame_or_window
, f
);
8547 else if (! NILP (Vframe_list
)
8548 && ! NILP (XCDR (Vframe_list
)))
8549 /* Force a redisplay sooner or later to update the
8550 frame titles in case this is the second frame. */
8551 record_asynch_buffer_change ();
8555 HDC hdc
= get_frame_dc (f
);
8557 /* Erase background again for safety. */
8558 w32_clear_rect (f
, hdc
, &msg
.rect
);
8559 release_frame_dc (f
, hdc
);
8563 msg
.rect
.right
- msg
.rect
.left
,
8564 msg
.rect
.bottom
- msg
.rect
.top
);
8569 case WM_INPUTLANGCHANGE
:
8570 /* Generate a language change event. */
8571 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8578 bufp
->kind
= language_change_event
;
8579 XSETFRAME (bufp
->frame_or_window
, f
);
8581 bufp
->code
= msg
.msg
.wParam
;
8582 bufp
->modifiers
= msg
.msg
.lParam
& 0xffff;
8591 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8593 if (f
&& !f
->iconified
)
8595 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8597 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8598 bufp
->kind
= non_ascii_keystroke
;
8599 bufp
->code
= msg
.msg
.wParam
;
8600 bufp
->modifiers
= msg
.dwModifiers
;
8601 XSETFRAME (bufp
->frame_or_window
, f
);
8603 bufp
->timestamp
= msg
.msg
.time
;
8612 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8614 if (f
&& !f
->iconified
)
8616 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8618 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8619 bufp
->kind
= ascii_keystroke
;
8620 bufp
->code
= msg
.msg
.wParam
;
8621 bufp
->modifiers
= msg
.dwModifiers
;
8622 XSETFRAME (bufp
->frame_or_window
, f
);
8624 bufp
->timestamp
= msg
.msg
.time
;
8632 previous_help_echo
= help_echo
;
8633 help_echo_object
= help_echo_window
= Qnil
;
8636 if (dpyinfo
->grabbed
&& last_mouse_frame
8637 && FRAME_LIVE_P (last_mouse_frame
))
8638 f
= last_mouse_frame
;
8640 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8643 note_mouse_movement (f
, &msg
.msg
);
8646 /* If we move outside the frame, then we're
8647 certainly no longer on any text in the frame. */
8648 clear_mouse_face (dpyinfo
);
8651 /* If the contents of the global variable help_echo
8652 has changed, generate a HELP_EVENT. */
8653 if (help_echo
!= previous_help_echo
)
8659 XSETFRAME (frame
, f
);
8663 any_help_event_p
= 1;
8664 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
8665 help_echo_window
, help_echo_object
,
8667 bufp
+= n
, count
+= n
, numchars
-= n
;
8671 case WM_LBUTTONDOWN
:
8673 case WM_MBUTTONDOWN
:
8675 case WM_RBUTTONDOWN
:
8677 case WM_XBUTTONDOWN
:
8680 /* If we decide we want to generate an event to be seen
8681 by the rest of Emacs, we put it here. */
8682 struct input_event emacs_event
;
8687 emacs_event
.kind
= no_event
;
8689 if (dpyinfo
->grabbed
&& last_mouse_frame
8690 && FRAME_LIVE_P (last_mouse_frame
))
8691 f
= last_mouse_frame
;
8693 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8697 construct_mouse_click (&emacs_event
, &msg
, f
);
8699 /* Is this in the tool-bar? */
8700 if (WINDOWP (f
->tool_bar_window
)
8701 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
8707 window
= window_from_coordinates (f
,
8711 if (EQ (window
, f
->tool_bar_window
))
8713 w32_handle_tool_bar_click (f
, &emacs_event
);
8719 if (!dpyinfo
->w32_focus_frame
8720 || f
== dpyinfo
->w32_focus_frame
8723 construct_mouse_click (bufp
, &msg
, f
);
8730 parse_button (msg
.msg
.message
, HIWORD (msg
.msg
.wParam
),
8735 dpyinfo
->grabbed
&= ~ (1 << button
);
8739 dpyinfo
->grabbed
|= (1 << button
);
8740 last_mouse_frame
= f
;
8741 /* Ignore any mouse motion that happened
8742 before this event; any subsequent mouse-movement
8743 Emacs events should reflect only motion after
8749 last_tool_bar_item
= -1;
8755 if (dpyinfo
->grabbed
&& last_mouse_frame
8756 && FRAME_LIVE_P (last_mouse_frame
))
8757 f
= last_mouse_frame
;
8759 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8763 if ((!dpyinfo
->w32_focus_frame
8764 || f
== dpyinfo
->w32_focus_frame
)
8767 construct_mouse_wheel (bufp
, &msg
, f
);
8776 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8780 construct_drag_n_drop (bufp
, &msg
, f
);
8789 struct scroll_bar
*bar
=
8790 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
);
8792 if (bar
&& numchars
>= 1)
8794 if (w32_scroll_bar_handle_click (bar
, &msg
, bufp
))
8804 case WM_WINDOWPOSCHANGED
:
8806 case WM_ACTIVATEAPP
:
8807 check_visibility
= 1;
8811 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8813 if (f
&& !f
->async_iconified
)
8817 x_real_positions (f
, &x
, &y
);
8818 f
->output_data
.w32
->left_pos
= x
;
8819 f
->output_data
.w32
->top_pos
= y
;
8822 check_visibility
= 1;
8826 /* wParam non-zero means Window is about to be shown, 0 means
8827 about to be hidden. */
8828 /* Redo the mouse-highlight after the tooltip has gone. */
8829 if (!msg
.msg
.wParam
&& msg
.msg
.hwnd
== tip_window
)
8832 redo_mouse_highlight ();
8835 /* If window has been obscured or exposed by another window
8836 being maximised or minimised/restored, then recheck
8837 visibility of all frames. Direct changes to our own
8838 windows get handled by WM_SIZE. */
8840 if (msg
.msg
.lParam
!= 0)
8841 check_visibility
= 1;
8844 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8845 f
->async_visible
= msg
.msg
.wParam
;
8849 check_visibility
= 1;
8853 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8855 /* Inform lisp of whether frame has been iconified etc. */
8858 switch (msg
.msg
.wParam
)
8860 case SIZE_MINIMIZED
:
8861 f
->async_visible
= 0;
8862 f
->async_iconified
= 1;
8864 bufp
->kind
= iconify_event
;
8865 XSETFRAME (bufp
->frame_or_window
, f
);
8872 case SIZE_MAXIMIZED
:
8874 f
->async_visible
= 1;
8875 f
->async_iconified
= 0;
8877 /* wait_reading_process_input will notice this and update
8878 the frame's display structures. */
8879 SET_FRAME_GARBAGED (f
);
8885 /* Reset top and left positions of the Window
8886 here since Windows sends a WM_MOVE message
8887 BEFORE telling us the Window is minimized
8888 when the Window is iconified, with 3000,3000
8890 x_real_positions (f
, &x
, &y
);
8891 f
->output_data
.w32
->left_pos
= x
;
8892 f
->output_data
.w32
->top_pos
= y
;
8894 bufp
->kind
= deiconify_event
;
8895 XSETFRAME (bufp
->frame_or_window
, f
);
8901 else if (! NILP (Vframe_list
)
8902 && ! NILP (XCDR (Vframe_list
)))
8903 /* Force a redisplay sooner or later
8904 to update the frame titles
8905 in case this is the second frame. */
8906 record_asynch_buffer_change ();
8911 if (f
&& !f
->async_iconified
&& msg
.msg
.wParam
!= SIZE_MINIMIZED
)
8919 GetClientRect (msg
.msg
.hwnd
, &rect
);
8921 height
= rect
.bottom
- rect
.top
;
8922 width
= rect
.right
- rect
.left
;
8924 rows
= PIXEL_TO_CHAR_HEIGHT (f
, height
);
8925 columns
= PIXEL_TO_CHAR_WIDTH (f
, width
);
8927 /* TODO: Clip size to the screen dimensions. */
8929 /* Even if the number of character rows and columns has
8930 not changed, the font size may have changed, so we need
8931 to check the pixel dimensions as well. */
8933 if (columns
!= f
->width
8934 || rows
!= f
->height
8935 || width
!= f
->output_data
.w32
->pixel_width
8936 || height
!= f
->output_data
.w32
->pixel_height
)
8938 change_frame_size (f
, rows
, columns
, 0, 1, 0);
8939 SET_FRAME_GARBAGED (f
);
8940 cancel_mouse_face (f
);
8941 f
->output_data
.w32
->pixel_width
= width
;
8942 f
->output_data
.w32
->pixel_height
= height
;
8943 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
8947 check_visibility
= 1;
8951 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8954 if (f
== dpyinfo
->mouse_face_mouse_frame
)
8956 /* If we move outside the frame, then we're
8957 certainly no longer on any text in the frame. */
8958 clear_mouse_face (dpyinfo
);
8959 dpyinfo
->mouse_face_mouse_frame
= 0;
8962 /* Generate a nil HELP_EVENT to cancel a help-echo.
8963 Do it only if there's something to cancel.
8964 Otherwise, the startup message is cleared when
8965 the mouse leaves the frame. */
8966 if (any_help_event_p
)
8971 XSETFRAME (frame
, f
);
8973 n
= gen_help_event (bufp
, numchars
,
8974 Qnil
, frame
, Qnil
, Qnil
, 0);
8975 bufp
+= n
, count
+= n
, numchars
-= n
;
8981 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8983 dpyinfo
->w32_focus_event_frame
= f
;
8986 x_new_focus_frame (dpyinfo
, f
);
8989 dpyinfo
->grabbed
= 0;
8990 check_visibility
= 1;
8994 /* TODO: some of this belongs in MOUSE_LEAVE */
8995 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8999 if (f
== dpyinfo
->w32_focus_event_frame
)
9000 dpyinfo
->w32_focus_event_frame
= 0;
9002 if (f
== dpyinfo
->w32_focus_frame
)
9003 x_new_focus_frame (dpyinfo
, 0);
9005 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9007 /* If we move outside the frame, then we're
9008 certainly no longer on any text in the frame. */
9009 clear_mouse_face (dpyinfo
);
9010 dpyinfo
->mouse_face_mouse_frame
= 0;
9013 /* Generate a nil HELP_EVENT to cancel a help-echo.
9014 Do it only if there's something to cancel.
9015 Otherwise, the startup message is cleared when
9016 the mouse leaves the frame. */
9017 if (any_help_event_p
)
9022 XSETFRAME (frame
, f
);
9024 n
= gen_help_event (bufp
, numchars
,
9025 Qnil
, frame
, Qnil
, Qnil
, 0);
9026 bufp
+= n
, count
+= n
, numchars
-=n
;
9030 dpyinfo
->grabbed
= 0;
9031 check_visibility
= 1;
9035 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9042 bufp
->kind
= delete_window_event
;
9043 XSETFRAME (bufp
->frame_or_window
, f
);
9052 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9059 bufp
->kind
= menu_bar_activate_event
;
9060 XSETFRAME (bufp
->frame_or_window
, f
);
9069 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9073 extern void menubar_selection_callback
9074 (FRAME_PTR f
, void * client_data
);
9075 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
9078 check_visibility
= 1;
9081 case WM_DISPLAYCHANGE
:
9082 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9086 dpyinfo
->width
= (short) LOWORD (msg
.msg
.lParam
);
9087 dpyinfo
->height
= (short) HIWORD (msg
.msg
.lParam
);
9088 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
9089 DebPrint (("display change: %d %d\n", dpyinfo
->width
,
9093 check_visibility
= 1;
9097 /* Check for messages registered at runtime. */
9098 if (msg
.msg
.message
== msh_mousewheel
)
9100 if (dpyinfo
->grabbed
&& last_mouse_frame
9101 && FRAME_LIVE_P (last_mouse_frame
))
9102 f
= last_mouse_frame
;
9104 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
9108 if ((!dpyinfo
->w32_focus_frame
9109 || f
== dpyinfo
->w32_focus_frame
)
9112 construct_mouse_wheel (bufp
, &msg
, f
);
9123 /* If the focus was just given to an autoraising frame,
9125 /* ??? This ought to be able to handle more than one such frame. */
9126 if (pending_autoraise_frame
)
9128 x_raise_frame (pending_autoraise_frame
);
9129 pending_autoraise_frame
= 0;
9132 /* Check which frames are still visisble, if we have enqueued any user
9133 events or been notified of events that may affect visibility. We
9134 do this here because there doesn't seem to be any direct
9135 notification from Windows that the visibility of a window has
9136 changed (at least, not in all cases). */
9137 if (count
> 0 || check_visibility
)
9139 Lisp_Object tail
, frame
;
9141 FOR_EACH_FRAME (tail
, frame
)
9143 FRAME_PTR f
= XFRAME (frame
);
9144 /* The tooltip has been drawn already. Avoid the
9145 SET_FRAME_GARBAGED below. */
9146 if (EQ (frame
, tip_frame
))
9149 /* Check "visible" frames and mark each as obscured or not.
9150 Note that async_visible is nonzero for unobscured and
9151 obscured frames, but zero for hidden and iconified frames. */
9152 if (FRAME_W32_P (f
) && f
->async_visible
)
9158 /* Query clipping rectangle for the entire window area
9159 (GetWindowDC), not just the client portion (GetDC).
9160 Otherwise, the scrollbars and menubar aren't counted as
9161 part of the visible area of the frame, and we may think
9162 the frame is obscured when really a scrollbar is still
9163 visible and gets WM_PAINT messages above. */
9164 hdc
= GetWindowDC (FRAME_W32_WINDOW (f
));
9165 GetClipBox (hdc
, &clipbox
);
9166 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
9169 if (clipbox
.right
== clipbox
.left
9170 || clipbox
.bottom
== clipbox
.top
)
9172 /* Frame has become completely obscured so mark as
9173 such (we do this by setting async_visible to 2 so
9174 that FRAME_VISIBLE_P is still true, but redisplay
9176 f
->async_visible
= 2;
9178 if (!FRAME_OBSCURED_P (f
))
9180 DebPrint (("frame %p (%s) obscured\n", f
,
9181 XSTRING (f
->name
)->data
));
9186 /* Frame is not obscured, so mark it as such. */
9187 f
->async_visible
= 1;
9189 if (FRAME_OBSCURED_P (f
))
9191 SET_FRAME_GARBAGED (f
);
9192 DebPrint (("obscured frame %p (%s) found to be visible\n", f
,
9193 XSTRING (f
->name
)->data
));
9195 /* Force a redisplay sooner or later. */
9196 record_asynch_buffer_change ();
9210 /***********************************************************************
9212 ***********************************************************************/
9214 /* Notice if the text cursor of window W has been overwritten by a
9215 drawing operation that outputs glyphs starting at START_X and
9216 ending at END_X in the line given by output_cursor.vpos.
9217 Coordinates are area-relative. END_X < 0 means all the rest
9218 of the line after START_X has been written. */
9221 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
9223 enum glyph_row_area area
;
9226 if (area
== TEXT_AREA
9227 && w
->phys_cursor_on_p
9228 && y0
<= w
->phys_cursor
.y
9229 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
9230 && x0
<= w
->phys_cursor
.x
9231 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
9232 w
->phys_cursor_on_p
= 0;
9236 /* Set clipping for output in glyph row ROW. W is the window in which
9237 we operate. GC is the graphics context to set clipping in.
9238 WHOLE_LINE_P non-zero means include the areas used for truncation
9239 mark display and alike in the clipping rectangle.
9241 ROW may be a text row or, e.g., a mode line. Text rows must be
9242 clipped to the interior of the window dedicated to text display,
9243 mode lines must be clipped to the whole window. */
9246 w32_clip_to_row (w
, row
, hdc
, whole_line_p
)
9248 struct glyph_row
*row
;
9252 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9254 int window_x
, window_y
, window_width
, window_height
;
9256 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9258 clip_rect
.left
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
9259 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
9260 clip_rect
.top
= max (clip_rect
.top
, window_y
);
9261 clip_rect
.right
= clip_rect
.left
+ window_width
;
9262 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
9264 /* If clipping to the whole line, including trunc marks, extend
9265 the rectangle to the left and increase its width. */
9268 clip_rect
.left
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
9269 clip_rect
.right
+= FRAME_X_FRINGE_WIDTH (f
);
9272 w32_set_clip_rectangle (hdc
, &clip_rect
);
9276 /* Draw a hollow box cursor on window W in glyph row ROW. */
9279 x_draw_hollow_cursor (w
, row
)
9281 struct glyph_row
*row
;
9283 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9287 struct glyph
*cursor_glyph
;
9288 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
9290 /* Compute frame-relative coordinates from window-relative
9292 rect
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9293 rect
.top
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9294 + row
->ascent
- w
->phys_cursor_ascent
);
9295 rect
.bottom
= rect
.top
+ row
->height
- 1;
9297 /* Get the glyph the cursor is on. If we can't tell because
9298 the current matrix is invalid or such, give up. */
9299 cursor_glyph
= get_phys_cursor_glyph (w
);
9300 if (cursor_glyph
== NULL
)
9303 /* Compute the width of the rectangle to draw. If on a stretch
9304 glyph, and `x-stretch-block-cursor' is nil, don't draw a
9305 rectangle as wide as the glyph, but use a canonical character
9307 wd
= cursor_glyph
->pixel_width
- 1;
9308 if (cursor_glyph
->type
== STRETCH_GLYPH
9309 && !x_stretch_cursor_p
)
9310 wd
= min (CANON_X_UNIT (f
), wd
);
9312 rect
.right
= rect
.left
+ wd
;
9313 hdc
= get_frame_dc (f
);
9314 FrameRect (hdc
, &rect
, hb
);
9317 release_frame_dc (f
, hdc
);
9321 /* Draw a bar cursor on window W in glyph row ROW.
9323 Implementation note: One would like to draw a bar cursor with an
9324 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9325 Unfortunately, I didn't find a font yet that has this property set.
9329 x_draw_bar_cursor (w
, row
, width
)
9331 struct glyph_row
*row
;
9334 struct frame
*f
= XFRAME (w
->frame
);
9335 struct glyph
*cursor_glyph
;
9339 /* If cursor is out of bounds, don't draw garbage. This can happen
9340 in mini-buffer windows when switching between echo area glyphs
9342 cursor_glyph
= get_phys_cursor_glyph (w
);
9343 if (cursor_glyph
== NULL
)
9346 /* If on an image, draw like a normal cursor. That's usually better
9347 visible than drawing a bar, esp. if the image is large so that
9348 the bar might not be in the window. */
9349 if (cursor_glyph
->type
== IMAGE_GLYPH
)
9351 struct glyph_row
*row
;
9352 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
9353 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
9357 COLORREF cursor_color
= f
->output_data
.w32
->cursor_pixel
;
9358 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
9361 width
= f
->output_data
.w32
->cursor_width
;
9363 /* If the glyph's background equals the color we normally draw
9364 the bar cursor in, the bar cursor in its normal color is
9365 invisible. Use the glyph's foreground color instead in this
9366 case, on the assumption that the glyph's colors are chosen so
9367 that the glyph is legible. */
9368 if (face
->background
== cursor_color
)
9369 cursor_color
= face
->foreground
;
9371 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9372 hdc
= get_frame_dc (f
);
9373 w32_clip_to_row (w
, row
, hdc
, 0);
9374 w32_fill_area (f
, hdc
, cursor_color
, x
,
9375 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9376 min (cursor_glyph
->pixel_width
, width
),
9378 release_frame_dc (f
, hdc
);
9383 /* Clear the cursor of window W to background color, and mark the
9384 cursor as not shown. This is used when the text where the cursor
9385 is is about to be rewritten. */
9391 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9392 x_update_window_cursor (w
, 0);
9396 /* Draw the cursor glyph of window W in glyph row ROW. See the
9397 comment of x_draw_glyphs for the meaning of HL. */
9400 x_draw_phys_cursor_glyph (w
, row
, hl
)
9402 struct glyph_row
*row
;
9403 enum draw_glyphs_face hl
;
9405 /* If cursor hpos is out of bounds, don't draw garbage. This can
9406 happen in mini-buffer windows when switching between echo area
9407 glyphs and mini-buffer. */
9408 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9410 int on_p
= w
->phys_cursor_on_p
;
9411 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9412 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9414 w
->phys_cursor_on_p
= on_p
;
9416 /* When we erase the cursor, and ROW is overlapped by other
9417 rows, make sure that these overlapping parts of other rows
9419 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9421 if (row
> w
->current_matrix
->rows
9422 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9423 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9425 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9426 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9427 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9433 /* Erase the image of a cursor of window W from the screen. */
9436 x_erase_phys_cursor (w
)
9439 struct frame
*f
= XFRAME (w
->frame
);
9440 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9441 int hpos
= w
->phys_cursor
.hpos
;
9442 int vpos
= w
->phys_cursor
.vpos
;
9443 int mouse_face_here_p
= 0;
9444 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9445 struct glyph_row
*cursor_row
;
9446 struct glyph
*cursor_glyph
;
9447 enum draw_glyphs_face hl
;
9449 /* No cursor displayed or row invalidated => nothing to do on the
9451 if (w
->phys_cursor_type
== NO_CURSOR
)
9452 goto mark_cursor_off
;
9454 /* VPOS >= active_glyphs->nrows means that window has been resized.
9455 Don't bother to erase the cursor. */
9456 if (vpos
>= active_glyphs
->nrows
)
9457 goto mark_cursor_off
;
9459 /* If row containing cursor is marked invalid, there is nothing we
9461 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9462 if (!cursor_row
->enabled_p
)
9463 goto mark_cursor_off
;
9465 /* This can happen when the new row is shorter than the old one.
9466 In this case, either x_draw_glyphs or clear_end_of_line
9467 should have cleared the cursor. Note that we wouldn't be
9468 able to erase the cursor in this case because we don't have a
9469 cursor glyph at hand. */
9470 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9471 goto mark_cursor_off
;
9473 /* If the cursor is in the mouse face area, redisplay that when
9474 we clear the cursor. */
9475 if (! NILP (dpyinfo
->mouse_face_window
)
9476 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9477 && (vpos
> dpyinfo
->mouse_face_beg_row
9478 || (vpos
== dpyinfo
->mouse_face_beg_row
9479 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9480 && (vpos
< dpyinfo
->mouse_face_end_row
9481 || (vpos
== dpyinfo
->mouse_face_end_row
9482 && hpos
< dpyinfo
->mouse_face_end_col
))
9483 /* Don't redraw the cursor's spot in mouse face if it is at the
9484 end of a line (on a newline). The cursor appears there, but
9485 mouse highlighting does not. */
9486 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9487 mouse_face_here_p
= 1;
9489 /* Maybe clear the display under the cursor. */
9490 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9493 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9496 cursor_glyph
= get_phys_cursor_glyph (w
);
9497 if (cursor_glyph
== NULL
)
9498 goto mark_cursor_off
;
9500 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9502 hdc
= get_frame_dc (f
);
9503 w32_clear_area (f
, hdc
, x
,
9504 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9506 cursor_glyph
->pixel_width
,
9507 cursor_row
->visible_height
);
9508 release_frame_dc (f
, hdc
);
9511 /* Erase the cursor by redrawing the character underneath it. */
9512 if (mouse_face_here_p
)
9513 hl
= DRAW_MOUSE_FACE
;
9515 hl
= DRAW_NORMAL_TEXT
;
9516 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9519 w
->phys_cursor_on_p
= 0;
9520 w
->phys_cursor_type
= NO_CURSOR
;
9524 /* Non-zero if physical cursor of window W is within mouse face. */
9527 cursor_in_mouse_face_p (w
)
9530 struct w32_display_info
*dpyinfo
9531 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
9532 int in_mouse_face
= 0;
9534 if (WINDOWP (dpyinfo
->mouse_face_window
)
9535 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
9537 int hpos
= w
->phys_cursor
.hpos
;
9538 int vpos
= w
->phys_cursor
.vpos
;
9540 if (vpos
>= dpyinfo
->mouse_face_beg_row
9541 && vpos
<= dpyinfo
->mouse_face_end_row
9542 && (vpos
> dpyinfo
->mouse_face_beg_row
9543 || hpos
>= dpyinfo
->mouse_face_beg_col
)
9544 && (vpos
< dpyinfo
->mouse_face_end_row
9545 || hpos
< dpyinfo
->mouse_face_end_col
9546 || dpyinfo
->mouse_face_past_end
))
9550 return in_mouse_face
;
9554 /* Display or clear cursor of window W. If ON is zero, clear the
9555 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9556 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9559 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9561 int on
, hpos
, vpos
, x
, y
;
9563 struct frame
*f
= XFRAME (w
->frame
);
9564 int new_cursor_type
;
9565 int new_cursor_width
;
9566 struct glyph_matrix
*current_glyphs
;
9567 struct glyph_row
*glyph_row
;
9568 struct glyph
*glyph
;
9569 int cursor_non_selected
;
9570 int active_cursor
= 1;
9572 /* This is pointless on invisible frames, and dangerous on garbaged
9573 windows and frames; in the latter case, the frame or window may
9574 be in the midst of changing its size, and x and y may be off the
9576 if (! FRAME_VISIBLE_P (f
)
9577 || FRAME_GARBAGED_P (f
)
9578 || vpos
>= w
->current_matrix
->nrows
9579 || hpos
>= w
->current_matrix
->matrix_w
)
9582 /* If cursor is off and we want it off, return quickly. */
9583 if (!on
&& !w
->phys_cursor_on_p
)
9586 current_glyphs
= w
->current_matrix
;
9587 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9588 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9590 /* If cursor row is not enabled, we don't really know where to
9591 display the cursor. */
9592 if (!glyph_row
->enabled_p
)
9594 w
->phys_cursor_on_p
= 0;
9598 xassert (interrupt_input_blocked
);
9600 /* Set new_cursor_type to the cursor we want to be displayed. In a
9601 mini-buffer window, we want the cursor only to appear if we are
9602 reading input from this window. For the selected window, we want
9603 the cursor type given by the frame parameter. If explicitly
9604 marked off, draw no cursor. In all other cases, we want a hollow
9607 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
9609 new_cursor_width
= -1;
9610 if (cursor_in_echo_area
9611 && FRAME_HAS_MINIBUF_P (f
)
9612 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
9614 if (w
== XWINDOW (echo_area_window
))
9615 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9618 if (cursor_non_selected
)
9619 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9621 new_cursor_type
= NO_CURSOR
;
9627 if (f
!= FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
9628 || w
!= XWINDOW (f
->selected_window
))
9632 if (MINI_WINDOW_P (w
)
9633 || !cursor_non_selected
9634 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
9635 new_cursor_type
= NO_CURSOR
;
9637 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9639 else if (w
->cursor_off_p
)
9640 new_cursor_type
= NO_CURSOR
;
9643 struct buffer
*b
= XBUFFER (w
->buffer
);
9645 if (EQ (b
->cursor_type
, Qt
))
9646 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9648 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
9653 /* If cursor is currently being shown and we don't want it to be or
9654 it is in the wrong place, or the cursor type is not what we want,
9656 if (w
->phys_cursor_on_p
9658 || w
->phys_cursor
.x
!= x
9659 || w
->phys_cursor
.y
!= y
9660 || new_cursor_type
!= w
->phys_cursor_type
))
9661 x_erase_phys_cursor (w
);
9663 /* If the cursor is now invisible and we want it to be visible,
9665 if (on
&& !w
->phys_cursor_on_p
)
9667 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9668 w
->phys_cursor_height
= glyph_row
->height
;
9670 /* Set phys_cursor_.* before x_draw_.* is called because some
9671 of them may need the information. */
9672 w
->phys_cursor
.x
= x
;
9673 w
->phys_cursor
.y
= glyph_row
->y
;
9674 w
->phys_cursor
.hpos
= hpos
;
9675 w
->phys_cursor
.vpos
= vpos
;
9676 w
->phys_cursor_type
= new_cursor_type
;
9677 w
->phys_cursor_on_p
= 1;
9679 /* If this is the active cursor, we need to track it with the
9680 system caret, so third party software like screen magnifiers
9681 and speech synthesizers can follow the cursor. */
9684 struct glyph
* cursor_glyph
= get_phys_cursor_glyph (w
);
9687 HWND hwnd
= FRAME_W32_WINDOW (f
);
9688 int caret_width
= cursor_glyph
->pixel_width
;
9690 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9692 = (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9693 + glyph_row
->ascent
- w
->phys_cursor_ascent
);
9695 /* If the size of the active cursor changed, destroy the old
9697 if (w32_system_caret_hwnd
9698 && (w32_system_caret_height
!= w
->phys_cursor_height
9699 || w32_system_caret_width
!= caret_width
))
9700 PostMessage (hwnd
, WM_EMACS_DESTROY_CARET
, 0, 0);
9702 if (!w32_system_caret_hwnd
)
9704 w32_system_caret_height
= w
->phys_cursor_height
;
9705 w32_system_caret_width
= caret_width
;
9708 /* Move the system caret. */
9709 PostMessage (hwnd
, WM_EMACS_TRACK_CARET
, 0, 0);
9713 switch (new_cursor_type
)
9715 case HOLLOW_BOX_CURSOR
:
9716 x_draw_hollow_cursor (w
, glyph_row
);
9719 case FILLED_BOX_CURSOR
:
9720 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9724 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
9737 /* Display the cursor on window W, or clear it. X and Y are window
9738 relative pixel coordinates. HPOS and VPOS are glyph matrix
9739 positions. If W is not the selected window, display a hollow
9740 cursor. ON non-zero means display the cursor at X, Y which
9741 correspond to HPOS, VPOS, otherwise it is cleared. */
9744 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9746 int on
, hpos
, vpos
, x
, y
;
9749 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9754 /* Display the cursor on window W, or clear it, according to ON_P.
9755 Don't change the cursor's position. */
9758 x_update_cursor (f
, on_p
)
9762 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9766 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9767 in the window tree rooted at W. */
9770 x_update_cursor_in_window_tree (w
, on_p
)
9776 if (!NILP (w
->hchild
))
9777 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9778 else if (!NILP (w
->vchild
))
9779 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9781 x_update_window_cursor (w
, on_p
);
9783 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9788 /* Switch the display of W's cursor on or off, according to the value
9792 x_update_window_cursor (w
, on
)
9796 /* Don't update cursor in windows whose frame is in the process
9797 of being deleted. */
9798 if (w
->current_matrix
)
9801 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
,
9802 w
->phys_cursor
.vpos
, w
->phys_cursor
.x
,
9814 x_bitmap_icon (f
, icon
)
9820 if (FRAME_W32_WINDOW (f
) == 0)
9824 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
9825 else if (STRINGP (icon
))
9826 hicon
= LoadImage (NULL
, (LPCTSTR
) XSTRING (icon
)->data
, IMAGE_ICON
, 0, 0,
9827 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
9828 else if (SYMBOLP (icon
))
9832 if (EQ (icon
, intern ("application")))
9833 name
= (LPCTSTR
) IDI_APPLICATION
;
9834 else if (EQ (icon
, intern ("hand")))
9835 name
= (LPCTSTR
) IDI_HAND
;
9836 else if (EQ (icon
, intern ("question")))
9837 name
= (LPCTSTR
) IDI_QUESTION
;
9838 else if (EQ (icon
, intern ("exclamation")))
9839 name
= (LPCTSTR
) IDI_EXCLAMATION
;
9840 else if (EQ (icon
, intern ("asterisk")))
9841 name
= (LPCTSTR
) IDI_ASTERISK
;
9842 else if (EQ (icon
, intern ("winlogo")))
9843 name
= (LPCTSTR
) IDI_WINLOGO
;
9847 hicon
= LoadIcon (NULL
, name
);
9855 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
9862 /************************************************************************
9864 ************************************************************************/
9866 /* Display Error Handling functions not used on W32. Listing them here
9867 helps diff stay in step when comparing w32term.c with xterm.c.
9869 x_error_catcher (display, error)
9870 x_catch_errors (dpy)
9871 x_catch_errors_unwind (old_val)
9872 x_check_errors (dpy, format)
9873 x_had_errors_p (dpy)
9874 x_clear_errors (dpy)
9875 x_uncatch_errors (dpy, count)
9877 x_connection_signal (signalnum)
9878 x_connection_closed (dpy, error_message)
9879 x_error_quitter (display, error)
9880 x_error_handler (display, error)
9881 x_io_error_quitter (display)
9886 /* Changing the font of the frame. */
9888 /* Give frame F the font named FONTNAME as its default font, and
9889 return the full name of that font. FONTNAME may be a wildcard
9890 pattern; in that case, we choose some font that fits the pattern.
9891 The return value shows which font we chose. */
9894 x_new_font (f
, fontname
)
9896 register char *fontname
;
9898 struct font_info
*fontp
9899 = FS_LOAD_FONT (f
, 0, fontname
, -1);
9904 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
9905 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
9906 FRAME_FONTSET (f
) = -1;
9908 /* Compute the scroll bar width in character columns. */
9909 if (f
->scroll_bar_pixel_width
> 0)
9911 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9912 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
9916 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9917 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
9920 /* Now make the frame display the given font. */
9921 if (FRAME_W32_WINDOW (f
) != 0)
9923 frame_update_line_height (f
);
9924 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9925 x_set_window_size (f
, 0, f
->width
, f
->height
);
9928 /* If we are setting a new frame's font for the first time,
9929 there are no faces yet, so this font's height is the line height. */
9930 f
->output_data
.w32
->line_height
= FONT_HEIGHT (FRAME_FONT (f
));
9932 return build_string (fontp
->full_name
);
9935 /* Give frame F the fontset named FONTSETNAME as its default font, and
9936 return the full name of that fontset. FONTSETNAME may be a wildcard
9937 pattern; in that case, we choose some fontset that fits the pattern.
9938 The return value shows which fontset we chose. */
9941 x_new_fontset (f
, fontsetname
)
9945 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
9951 if (FRAME_FONTSET (f
) == fontset
)
9952 /* This fontset is already set in frame F. There's nothing more
9954 return fontset_name (fontset
);
9956 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
9958 if (!STRINGP (result
))
9959 /* Can't load ASCII font. */
9962 /* Since x_new_font doesn't update any fontset information, do it now. */
9963 FRAME_FONTSET(f
) = fontset
;
9965 return build_string (fontsetname
);
9968 /* Compute actual fringe widths */
9971 x_compute_fringe_widths (f
, redraw
)
9975 int o_left
= f
->output_data
.w32
->left_fringe_width
;
9976 int o_right
= f
->output_data
.w32
->right_fringe_width
;
9977 int o_cols
= f
->output_data
.w32
->fringe_cols
;
9979 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
9980 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
9981 int left_fringe_width
, right_fringe_width
;
9983 if (!NILP (left_fringe
))
9984 left_fringe
= Fcdr (left_fringe
);
9985 if (!NILP (right_fringe
))
9986 right_fringe
= Fcdr (right_fringe
);
9988 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
9989 XINT (left_fringe
));
9990 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
9991 XINT (right_fringe
));
9993 if (left_fringe_width
|| right_fringe_width
)
9995 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
9996 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
9997 int conf_wid
= left_wid
+ right_wid
;
9998 int font_wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
9999 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
10000 int real_wid
= cols
* font_wid
;
10001 if (left_wid
&& right_wid
)
10003 if (left_fringe_width
< 0)
10005 /* Left fringe width is fixed, adjust right fringe if necessary */
10006 f
->output_data
.w32
->left_fringe_width
= left_wid
;
10007 f
->output_data
.w32
->right_fringe_width
= real_wid
- left_wid
;
10009 else if (right_fringe_width
< 0)
10011 /* Right fringe width is fixed, adjust left fringe if necessary */
10012 f
->output_data
.w32
->left_fringe_width
= real_wid
- right_wid
;
10013 f
->output_data
.w32
->right_fringe_width
= right_wid
;
10017 /* Adjust both fringes with an equal amount.
10018 Note that we are doing integer arithmetic here, so don't
10019 lose a pixel if the total width is an odd number. */
10020 int fill
= real_wid
- conf_wid
;
10021 f
->output_data
.w32
->left_fringe_width
= left_wid
+ fill
/2;
10022 f
->output_data
.w32
->right_fringe_width
= right_wid
+ fill
- fill
/2;
10025 else if (left_fringe_width
)
10027 f
->output_data
.w32
->left_fringe_width
= real_wid
;
10028 f
->output_data
.w32
->right_fringe_width
= 0;
10032 f
->output_data
.w32
->left_fringe_width
= 0;
10033 f
->output_data
.w32
->right_fringe_width
= real_wid
;
10035 f
->output_data
.w32
->fringe_cols
= cols
;
10036 f
->output_data
.w32
->fringes_extra
= real_wid
;
10040 f
->output_data
.w32
->left_fringe_width
= 0;
10041 f
->output_data
.w32
->right_fringe_width
= 0;
10042 f
->output_data
.w32
->fringe_cols
= 0;
10043 f
->output_data
.w32
->fringes_extra
= 0;
10046 if (redraw
&& FRAME_VISIBLE_P (f
))
10047 if (o_left
!= f
->output_data
.w32
->left_fringe_width
||
10048 o_right
!= f
->output_data
.w32
->right_fringe_width
||
10049 o_cols
!= f
->output_data
.w32
->fringe_cols
)
10053 /***********************************************************************
10054 TODO: W32 Input Methods
10055 ***********************************************************************/
10056 /* Listing missing functions from xterm.c helps diff stay in step.
10058 xim_destroy_callback (xim, client_data, call_data)
10059 xim_open_dpy (dpyinfo, resource_name)
10061 xim_instantiate_callback (display, client_data, call_data)
10062 xim_initialize (dpyinfo, resource_name)
10063 xim_close_dpy (dpyinfo)
10068 /* Calculate the absolute position in frame F
10069 from its current recorded position values and gravity. */
10072 x_calc_absolute_position (f
)
10076 int flags
= f
->output_data
.w32
->size_hint_flags
;
10080 /* Find the position of the outside upper-left corner of
10081 the inner window, with respect to the outer window.
10082 But do this only if we will need the results. */
10083 if (f
->output_data
.w32
->parent_desc
!= FRAME_W32_DISPLAY_INFO (f
)->root_window
)
10086 MapWindowPoints (FRAME_W32_WINDOW (f
),
10087 f
->output_data
.w32
->parent_desc
,
10094 rt
.left
= rt
.right
= rt
.top
= rt
.bottom
= 0;
10097 AdjustWindowRect(&rt
, f
->output_data
.w32
->dwStyle
,
10098 FRAME_EXTERNAL_MENU_BAR (f
));
10101 pt
.x
+= (rt
.right
- rt
.left
);
10102 pt
.y
+= (rt
.bottom
- rt
.top
);
10105 /* Treat negative positions as relative to the leftmost bottommost
10106 position that fits on the screen. */
10107 if (flags
& XNegative
)
10108 f
->output_data
.w32
->left_pos
= (FRAME_W32_DISPLAY_INFO (f
)->width
10109 - 2 * f
->output_data
.w32
->border_width
- pt
.x
10111 + f
->output_data
.w32
->left_pos
);
10113 if (flags
& YNegative
)
10114 f
->output_data
.w32
->top_pos
= (FRAME_W32_DISPLAY_INFO (f
)->height
10115 - 2 * f
->output_data
.w32
->border_width
- pt
.y
10117 + f
->output_data
.w32
->top_pos
);
10118 /* The left_pos and top_pos
10119 are now relative to the top and left screen edges,
10120 so the flags should correspond. */
10121 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10124 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
10125 to really change the position, and 0 when calling from
10126 x_make_frame_visible (in that case, XOFF and YOFF are the current
10127 position values). It is -1 when calling from x_set_frame_parameters,
10128 which means, do adjust for borders but don't change the gravity. */
10131 x_set_offset (f
, xoff
, yoff
, change_gravity
)
10133 register int xoff
, yoff
;
10134 int change_gravity
;
10136 int modified_top
, modified_left
;
10138 if (change_gravity
> 0)
10140 f
->output_data
.w32
->top_pos
= yoff
;
10141 f
->output_data
.w32
->left_pos
= xoff
;
10142 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10144 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
10146 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
10147 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
10149 x_calc_absolute_position (f
);
10152 x_wm_set_size_hint (f
, (long) 0, 0);
10154 modified_left
= f
->output_data
.w32
->left_pos
;
10155 modified_top
= f
->output_data
.w32
->top_pos
;
10157 my_set_window_pos (FRAME_W32_WINDOW (f
),
10159 modified_left
, modified_top
,
10161 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
10165 /* Call this to change the size of frame F's x-window.
10166 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
10167 for this size change and subsequent size changes.
10168 Otherwise we leave the window gravity unchanged. */
10171 x_set_window_size (f
, change_gravity
, cols
, rows
)
10173 int change_gravity
;
10176 int pixelwidth
, pixelheight
;
10180 check_frame_size (f
, &rows
, &cols
);
10181 f
->output_data
.w32
->vertical_scroll_bar_extra
10182 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
10184 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
10186 x_compute_fringe_widths (f
, 0);
10188 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
10189 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
10191 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
10192 x_wm_set_size_hint (f
, (long) 0, 0);
10197 rect
.left
= rect
.top
= 0;
10198 rect
.right
= pixelwidth
;
10199 rect
.bottom
= pixelheight
;
10201 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
,
10202 FRAME_EXTERNAL_MENU_BAR (f
));
10204 my_set_window_pos (FRAME_W32_WINDOW (f
),
10207 rect
.right
- rect
.left
,
10208 rect
.bottom
- rect
.top
,
10209 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10212 /* Now, strictly speaking, we can't be sure that this is accurate,
10213 but the window manager will get around to dealing with the size
10214 change request eventually, and we'll hear how it went when the
10215 ConfigureNotify event gets here.
10217 We could just not bother storing any of this information here,
10218 and let the ConfigureNotify event set everything up, but that
10219 might be kind of confusing to the Lisp code, since size changes
10220 wouldn't be reported in the frame parameters until some random
10221 point in the future when the ConfigureNotify event arrives.
10223 We pass 1 for DELAY since we can't run Lisp code inside of
10225 change_frame_size (f
, rows
, cols
, 0, 1, 0);
10226 PIXEL_WIDTH (f
) = pixelwidth
;
10227 PIXEL_HEIGHT (f
) = pixelheight
;
10229 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10230 receive in the ConfigureNotify event; if we get what we asked
10231 for, then the event won't cause the screen to become garbaged, so
10232 we have to make sure to do it here. */
10233 SET_FRAME_GARBAGED (f
);
10235 /* If cursor was outside the new size, mark it as off. */
10236 mark_window_cursors_off (XWINDOW (f
->root_window
));
10238 /* Clear out any recollection of where the mouse highlighting was,
10239 since it might be in a place that's outside the new frame size.
10240 Actually checking whether it is outside is a pain in the neck,
10241 so don't try--just let the highlighting be done afresh with new size. */
10242 cancel_mouse_face (f
);
10247 /* Mouse warping. */
10249 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
10252 x_set_mouse_position (f
, x
, y
)
10258 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.w32
->font
) / 2;
10259 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.w32
->line_height
/ 2;
10261 if (pix_x
< 0) pix_x
= 0;
10262 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
10264 if (pix_y
< 0) pix_y
= 0;
10265 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
10267 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
10271 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
10280 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
10281 pt
.x
= rect
.left
+ pix_x
;
10282 pt
.y
= rect
.top
+ pix_y
;
10283 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
10285 SetCursorPos (pt
.x
, pt
.y
);
10291 /* focus shifting, raising and lowering. */
10294 x_focus_on_frame (f
)
10297 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
10299 /* Give input focus to frame. */
10302 /* Try not to change its Z-order if possible. */
10303 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
10304 my_set_focus (f
, FRAME_W32_WINDOW (f
));
10307 my_set_foreground_window (FRAME_W32_WINDOW (f
));
10312 x_unfocus_frame (f
)
10317 /* Raise frame F. */
10324 /* Strictly speaking, raise-frame should only change the frame's Z
10325 order, leaving input focus unchanged. This is reasonable behaviour
10326 on X where the usual policy is point-to-focus. However, this
10327 behaviour would be very odd on Windows where the usual policy is
10330 On X, if the mouse happens to be over the raised frame, it gets
10331 input focus anyway (so the window with focus will never be
10332 completely obscured) - if not, then just moving the mouse over it
10333 is sufficient to give it focus. On Windows, the user must actually
10334 click on the frame (preferrably the title bar so as not to move
10335 point), which is more awkward. Also, no other Windows program
10336 raises a window to the top but leaves another window (possibly now
10337 completely obscured) with input focus.
10339 Because there is a system setting on Windows that allows the user
10340 to choose the point to focus policy, we make the strict semantics
10341 optional, but by default we grab focus when raising. */
10343 if (NILP (Vw32_grab_focus_on_raise
))
10345 /* The obvious call to my_set_window_pos doesn't work if Emacs is
10346 not already the foreground application: the frame is raised
10347 above all other frames belonging to us, but not above the
10348 current top window. To achieve that, we have to resort to this
10349 more cumbersome method. */
10351 HDWP handle
= BeginDeferWindowPos (2);
10354 DeferWindowPos (handle
,
10355 FRAME_W32_WINDOW (f
),
10358 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10360 DeferWindowPos (handle
,
10361 GetForegroundWindow (),
10362 FRAME_W32_WINDOW (f
),
10364 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10366 EndDeferWindowPos (handle
);
10371 my_set_foreground_window (FRAME_W32_WINDOW (f
));
10377 /* Lower frame F. */
10383 my_set_window_pos (FRAME_W32_WINDOW (f
),
10386 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
10391 w32_frame_raise_lower (f
, raise_flag
)
10395 if (! FRAME_W32_P (f
))
10404 /* Change of visibility. */
10406 /* This tries to wait until the frame is really visible.
10407 However, if the window manager asks the user where to position
10408 the frame, this will return before the user finishes doing that.
10409 The frame will not actually be visible at that time,
10410 but it will become visible later when the window manager
10411 finishes with it. */
10414 x_make_frame_visible (f
)
10421 type
= x_icon_type (f
);
10423 x_bitmap_icon (f
, type
);
10425 if (! FRAME_VISIBLE_P (f
))
10427 /* We test FRAME_GARBAGED_P here to make sure we don't
10428 call x_set_offset a second time
10429 if we get to x_make_frame_visible a second time
10430 before the window gets really visible. */
10431 if (! FRAME_ICONIFIED_P (f
)
10432 && ! f
->output_data
.w32
->asked_for_visible
)
10433 x_set_offset (f
, f
->output_data
.w32
->left_pos
, f
->output_data
.w32
->top_pos
, 0);
10435 f
->output_data
.w32
->asked_for_visible
= 1;
10437 // my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW);
10438 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_SHOWNORMAL
);
10441 /* Synchronize to ensure Emacs knows the frame is visible
10442 before we do anything else. We do this loop with input not blocked
10443 so that incoming events are handled. */
10448 /* This must come after we set COUNT. */
10451 XSETFRAME (frame
, f
);
10453 /* Wait until the frame is visible. Process X events until a
10454 MapNotify event has been seen, or until we think we won't get a
10455 MapNotify at all.. */
10456 for (count
= input_signal_count
+ 10;
10457 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
10459 /* Force processing of queued events. */
10460 /* TODO: x_sync equivalent? */
10462 /* Machines that do polling rather than SIGIO have been observed
10463 to go into a busy-wait here. So we'll fake an alarm signal
10464 to let the handler know that there's something to be read.
10465 We used to raise a real alarm, but it seems that the handler
10466 isn't always enabled here. This is probably a bug. */
10467 if (input_polling_used ())
10469 /* It could be confusing if a real alarm arrives while processing
10470 the fake one. Turn it off and let the handler reset it. */
10471 int old_poll_suppress_count
= poll_suppress_count
;
10472 poll_suppress_count
= 1;
10473 poll_for_input_1 ();
10474 poll_suppress_count
= old_poll_suppress_count
;
10477 FRAME_SAMPLE_VISIBILITY (f
);
10481 /* Change from mapped state to withdrawn state. */
10483 /* Make the frame visible (mapped and not iconified). */
10485 x_make_frame_invisible (f
)
10488 /* Don't keep the highlight on an invisible frame. */
10489 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
10490 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
10494 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
10496 /* We can't distinguish this from iconification
10497 just by the event that we get from the server.
10498 So we can't win using the usual strategy of letting
10499 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
10500 and synchronize with the server to make sure we agree. */
10502 FRAME_ICONIFIED_P (f
) = 0;
10503 f
->async_visible
= 0;
10504 f
->async_iconified
= 0;
10509 /* Change window state from mapped to iconified. */
10512 x_iconify_frame (f
)
10517 /* Don't keep the highlight on an invisible frame. */
10518 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
10519 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
10521 if (f
->async_iconified
)
10526 type
= x_icon_type (f
);
10528 x_bitmap_icon (f
, type
);
10530 /* Simulate the user minimizing the frame. */
10531 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
10537 /* Free X resources of frame F. */
10540 x_free_frame_resources (f
)
10543 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10547 if (FRAME_W32_WINDOW (f
))
10548 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
10550 free_frame_menubar (f
);
10552 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
10553 unload_color (f
, f
->output_data
.x
->background_pixel
);
10554 unload_color (f
, f
->output_data
.w32
->cursor_pixel
);
10555 unload_color (f
, f
->output_data
.w32
->cursor_foreground_pixel
);
10556 unload_color (f
, f
->output_data
.w32
->border_pixel
);
10557 unload_color (f
, f
->output_data
.w32
->mouse_pixel
);
10558 if (f
->output_data
.w32
->white_relief
.allocated_p
)
10559 unload_color (f
, f
->output_data
.w32
->white_relief
.pixel
);
10560 if (f
->output_data
.w32
->black_relief
.allocated_p
)
10561 unload_color (f
, f
->output_data
.w32
->black_relief
.pixel
);
10563 if (FRAME_FACE_CACHE (f
))
10564 free_frame_faces (f
);
10566 xfree (f
->output_data
.w32
);
10567 f
->output_data
.w32
= NULL
;
10569 if (f
== dpyinfo
->w32_focus_frame
)
10570 dpyinfo
->w32_focus_frame
= 0;
10571 if (f
== dpyinfo
->w32_focus_event_frame
)
10572 dpyinfo
->w32_focus_event_frame
= 0;
10573 if (f
== dpyinfo
->w32_highlight_frame
)
10574 dpyinfo
->w32_highlight_frame
= 0;
10576 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10578 dpyinfo
->mouse_face_beg_row
10579 = dpyinfo
->mouse_face_beg_col
= -1;
10580 dpyinfo
->mouse_face_end_row
10581 = dpyinfo
->mouse_face_end_col
= -1;
10582 dpyinfo
->mouse_face_window
= Qnil
;
10583 dpyinfo
->mouse_face_deferred_gc
= 0;
10584 dpyinfo
->mouse_face_mouse_frame
= 0;
10591 /* Destroy the window of frame F. */
10593 x_destroy_window (f
)
10596 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10598 x_free_frame_resources (f
);
10600 dpyinfo
->reference_count
--;
10604 /* Setting window manager hints. */
10606 /* Set the normal size hints for the window manager, for frame F.
10607 FLAGS is the flags word to use--or 0 meaning preserve the flags
10608 that the window now has.
10609 If USER_POSITION is nonzero, we set the USPosition
10610 flag (this is useful when FLAGS is 0). */
10612 x_wm_set_size_hint (f
, flags
, user_position
)
10617 Window window
= FRAME_W32_WINDOW (f
);
10621 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
10622 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
10623 SetWindowLong (window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
10624 SetWindowLong (window
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
10629 /* Window manager things */
10630 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10632 int icon_x
, icon_y
;
10635 Window window
= FRAME_W32_WINDOW (f
);
10637 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
10638 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
10639 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
10641 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
10646 /***********************************************************************
10648 ***********************************************************************/
10650 /* The following functions are listed here to help diff stay in step
10651 with xterm.c. See w32fns.c for definitions.
10653 x_get_font_info (f, font_idx)
10654 x_list_fonts (f, pattern, size, maxnames)
10660 /* Check that FONT is valid on frame F. It is if it can be found in F's
10664 x_check_font (f
, font
)
10669 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10671 xassert (font
!= NULL
);
10673 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10674 if (dpyinfo
->font_table
[i
].name
10675 && font
== dpyinfo
->font_table
[i
].font
)
10678 xassert (i
< dpyinfo
->n_fonts
);
10681 #endif /* GLYPH_DEBUG != 0 */
10683 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10684 Note: There are (broken) X fonts out there with invalid XFontStruct
10685 min_bounds contents. For example, handa@etl.go.jp reports that
10686 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10687 have font->min_bounds.width == 0. */
10690 x_font_min_bounds (font
, w
, h
)
10695 * TODO: Windows does not appear to offer min bound, only
10696 * average and maximum width, and maximum height.
10698 *h
= FONT_HEIGHT (font
);
10699 *w
= FONT_WIDTH (font
);
10703 /* Compute the smallest character width and smallest font height over
10704 all fonts available on frame F. Set the members smallest_char_width
10705 and smallest_font_height in F's x_display_info structure to
10706 the values computed. Value is non-zero if smallest_font_height or
10707 smallest_char_width become smaller than they were before. */
10710 x_compute_min_glyph_bounds (f
)
10714 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10716 int old_width
= dpyinfo
->smallest_char_width
;
10717 int old_height
= dpyinfo
->smallest_font_height
;
10719 dpyinfo
->smallest_font_height
= 100000;
10720 dpyinfo
->smallest_char_width
= 100000;
10722 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10723 if (dpyinfo
->font_table
[i
].name
)
10725 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10728 font
= (XFontStruct
*) fontp
->font
;
10729 xassert (font
!= (XFontStruct
*) ~0);
10730 x_font_min_bounds (font
, &w
, &h
);
10732 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10733 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10736 xassert (dpyinfo
->smallest_char_width
> 0
10737 && dpyinfo
->smallest_font_height
> 0);
10739 return (dpyinfo
->n_fonts
== 1
10740 || dpyinfo
->smallest_char_width
< old_width
10741 || dpyinfo
->smallest_font_height
< old_height
);
10744 /* The following functions are listed here to help diff stay in step
10745 with xterm.c. See w32fns.c for definitions.
10747 x_load_font (f, fontname, size)
10748 x_query_font (f, fontname)
10749 x_find_ccl_program (fontp)
10753 /***********************************************************************
10755 ***********************************************************************/
10757 static int w32_initialized
= 0;
10760 w32_initialize_display_info (display_name
)
10761 Lisp_Object display_name
;
10763 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
10765 bzero (dpyinfo
, sizeof (*dpyinfo
));
10767 /* Put it on w32_display_name_list. */
10768 w32_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10769 w32_display_name_list
);
10770 dpyinfo
->name_list_element
= XCAR (w32_display_name_list
);
10772 dpyinfo
->w32_id_name
10773 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
10774 + XSTRING (Vsystem_name
)->size
10776 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
10777 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
10779 /* Default Console mode values - overridden when running in GUI mode
10780 with values obtained from system metrics. */
10783 dpyinfo
->height_in
= 1;
10784 dpyinfo
->width_in
= 1;
10785 dpyinfo
->n_planes
= 1;
10786 dpyinfo
->n_cbits
= 4;
10787 dpyinfo
->n_fonts
= 0;
10788 dpyinfo
->smallest_font_height
= 1;
10789 dpyinfo
->smallest_char_width
= 1;
10791 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10792 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10793 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10794 dpyinfo
->mouse_face_window
= Qnil
;
10795 dpyinfo
->mouse_face_overlay
= Qnil
;
10796 /* TODO: dpyinfo->gray */
10800 struct w32_display_info
*
10801 w32_term_init (display_name
, xrm_option
, resource_name
)
10802 Lisp_Object display_name
;
10804 char *resource_name
;
10806 struct w32_display_info
*dpyinfo
;
10811 if (!w32_initialized
)
10814 w32_initialized
= 1;
10825 argv
[argc
++] = "-xrm";
10826 argv
[argc
++] = xrm_option
;
10830 w32_initialize_display_info (display_name
);
10832 dpyinfo
= &one_w32_display_info
;
10834 /* Put this display on the chain. */
10835 dpyinfo
->next
= x_display_list
;
10836 x_display_list
= dpyinfo
;
10838 hdc
= GetDC (GetDesktopWindow ());
10840 dpyinfo
->height
= GetDeviceCaps (hdc
, VERTRES
);
10841 dpyinfo
->width
= GetDeviceCaps (hdc
, HORZRES
);
10842 dpyinfo
->root_window
= GetDesktopWindow ();
10843 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
10844 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
10845 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
10846 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
10847 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
10848 dpyinfo
->image_cache
= make_image_cache ();
10849 dpyinfo
->height_in
= dpyinfo
->height
/ dpyinfo
->resx
;
10850 dpyinfo
->width_in
= dpyinfo
->width
/ dpyinfo
->resy
;
10851 ReleaseDC (GetDesktopWindow (), hdc
);
10853 /* initialise palette with white and black */
10856 w32_defined_color (0, "white", &color
, 1);
10857 w32_defined_color (0, "black", &color
, 1);
10860 /* Create Row Bitmaps and store them for later use. */
10861 left_bmp
= CreateBitmap (left_width
, left_height
, 1, 1, left_bits
);
10862 ov_bmp
= CreateBitmap (ov_width
, ov_height
, 1, 1, ov_bits
);
10863 right_bmp
= CreateBitmap (right_width
, right_height
, 1, 1, right_bits
);
10864 continued_bmp
= CreateBitmap (continued_width
, continued_height
, 1,
10865 1, continued_bits
);
10866 continuation_bmp
= CreateBitmap (continuation_width
, continuation_height
,
10867 1, 1, continuation_bits
);
10868 zv_bmp
= CreateBitmap (zv_width
, zv_height
, 1, 1, zv_bits
);
10870 #ifndef F_SETOWN_BUG
10872 #ifdef F_SETOWN_SOCK_NEG
10873 /* stdin is a socket here */
10874 fcntl (connection
, F_SETOWN
, -getpid ());
10875 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10876 fcntl (connection
, F_SETOWN
, getpid ());
10877 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10878 #endif /* ! defined (F_SETOWN) */
10879 #endif /* F_SETOWN_BUG */
10882 if (interrupt_input
)
10883 init_sigio (connection
);
10884 #endif /* ! defined (SIGIO) */
10891 /* Get rid of display DPYINFO, assuming all frames are already gone. */
10894 x_delete_display (dpyinfo
)
10895 struct w32_display_info
*dpyinfo
;
10897 /* Discard this display from w32_display_name_list and w32_display_list.
10898 We can't use Fdelq because that can quit. */
10899 if (! NILP (w32_display_name_list
)
10900 && EQ (XCAR (w32_display_name_list
), dpyinfo
->name_list_element
))
10901 w32_display_name_list
= XCDR (w32_display_name_list
);
10906 tail
= w32_display_name_list
;
10907 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10909 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10911 XSETCDR (tail
, XCDR (XCDR (tail
)));
10914 tail
= XCDR (tail
);
10918 /* free palette table */
10920 struct w32_palette_entry
* plist
;
10922 plist
= dpyinfo
->color_list
;
10925 struct w32_palette_entry
* pentry
= plist
;
10926 plist
= plist
->next
;
10929 dpyinfo
->color_list
= NULL
;
10930 if (dpyinfo
->palette
)
10931 DeleteObject(dpyinfo
->palette
);
10933 xfree (dpyinfo
->font_table
);
10934 xfree (dpyinfo
->w32_id_name
);
10936 /* Destroy row bitmaps. */
10937 DeleteObject (left_bmp
);
10938 DeleteObject (ov_bmp
);
10939 DeleteObject (right_bmp
);
10940 DeleteObject (continued_bmp
);
10941 DeleteObject (continuation_bmp
);
10942 DeleteObject (zv_bmp
);
10945 /* Set up use of W32. */
10947 DWORD
w32_msg_worker ();
10950 x_flush (struct frame
* f
)
10951 { /* Nothing to do */ }
10953 static struct redisplay_interface w32_redisplay_interface
=
10958 x_clear_end_of_line
,
10960 x_after_update_window_line
,
10961 x_update_window_begin
,
10962 x_update_window_end
,
10965 x_clear_mouse_face
,
10966 x_get_glyph_overhangs
,
10967 x_fix_overlapping_area
10973 rif
= &w32_redisplay_interface
;
10975 /* MSVC does not type K&R functions with no arguments correctly, and
10976 so we must explicitly cast them. */
10977 clear_frame_hook
= (void (*)(void)) x_clear_frame
;
10978 ring_bell_hook
= (void (*)(void)) w32_ring_bell
;
10979 update_begin_hook
= x_update_begin
;
10980 update_end_hook
= x_update_end
;
10982 read_socket_hook
= w32_read_socket
;
10984 frame_up_to_date_hook
= w32_frame_up_to_date
;
10986 mouse_position_hook
= w32_mouse_position
;
10987 frame_rehighlight_hook
= w32_frame_rehighlight
;
10988 frame_raise_lower_hook
= w32_frame_raise_lower
;
10989 set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
10990 condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
10991 redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
10992 judge_scroll_bars_hook
= w32_judge_scroll_bars
;
10993 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
10995 scroll_region_ok
= 1; /* we'll scroll partial frames */
10996 char_ins_del_ok
= 1;
10997 line_ins_del_ok
= 1; /* we'll just blt 'em */
10998 fast_clear_end_of_line
= 1; /* X does this well */
10999 memory_below_frame
= 0; /* we don't remember what scrolls
11003 w32_system_caret_hwnd
= NULL
;
11004 w32_system_caret_height
= 0;
11005 w32_system_caret_width
= 0;
11006 w32_system_caret_x
= 0;
11007 w32_system_caret_y
= 0;
11009 last_tool_bar_item
= -1;
11010 any_help_event_p
= 0;
11012 /* Initialize input mode: interrupt_input off, no flow control, allow
11013 8 bit character input, standard quit char. */
11014 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
11016 /* Create the window thread - it will terminate itself or when the app terminates */
11020 dwMainThreadId
= GetCurrentThreadId ();
11021 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
11022 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
11024 /* Wait for thread to start */
11029 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
11031 hWindowsThread
= CreateThread (NULL
, 0,
11032 (LPTHREAD_START_ROUTINE
) w32_msg_worker
,
11033 0, 0, &dwWindowsThreadId
);
11035 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
11038 /* It is desirable that mainThread should have the same notion of
11039 focus window and active window as windowsThread. Unfortunately, the
11040 following call to AttachThreadInput, which should do precisely what
11041 we need, causes major problems when Emacs is linked as a console
11042 program. Unfortunately, we have good reasons for doing that, so
11043 instead we need to send messages to windowsThread to make some API
11044 calls for us (ones that affect, or depend on, the active/focus
11046 #ifdef ATTACH_THREADS
11047 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
11050 /* Dynamically link to optional system components. */
11052 HANDLE user_lib
= LoadLibrary ("user32.dll");
11054 #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn)
11056 /* New proportional scroll bar functions. */
11057 LOAD_PROC (SetScrollInfo
);
11058 LOAD_PROC (GetScrollInfo
);
11062 FreeLibrary (user_lib
);
11064 /* If using proportional scroll bars, ensure handle is at least 5 pixels;
11065 otherwise use the fixed height. */
11066 vertical_scroll_bar_min_handle
= (pfnSetScrollInfo
!= NULL
) ? 5 :
11067 GetSystemMetrics (SM_CYVTHUMB
);
11069 /* For either kind of scroll bar, take account of the arrows; these
11070 effectively form the border of the main scroll bar range. */
11071 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
11072 = GetSystemMetrics (SM_CYVSCROLL
);
11079 staticpro (&w32_display_name_list
);
11080 w32_display_name_list
= Qnil
;
11082 staticpro (&last_mouse_scroll_bar
);
11083 last_mouse_scroll_bar
= Qnil
;
11085 staticpro (&Qvendor_specific_keysyms
);
11086 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
11088 DEFVAR_INT ("w32-num-mouse-buttons",
11089 &Vw32_num_mouse_buttons
,
11090 doc
: /* Number of physical mouse buttons. */);
11091 Vw32_num_mouse_buttons
= Qnil
;
11093 DEFVAR_LISP ("w32-swap-mouse-buttons",
11094 &Vw32_swap_mouse_buttons
,
11095 doc
: /* Swap the mapping of middle and right mouse buttons.
11096 When nil, middle button is mouse-2 and right button is mouse-3. */);
11097 Vw32_swap_mouse_buttons
= Qnil
;
11099 DEFVAR_LISP ("w32-grab-focus-on-raise",
11100 &Vw32_grab_focus_on_raise
,
11101 doc
: /* Raised frame grabs input focus.
11102 When t, `raise-frame' grabs input focus as well. This fits well
11103 with the normal Windows click-to-focus policy, but might not be
11104 desirable when using a point-to-focus policy. */);
11105 Vw32_grab_focus_on_raise
= Qt
;
11107 DEFVAR_LISP ("w32-capslock-is-shiftlock",
11108 &Vw32_capslock_is_shiftlock
,
11109 doc
: /* Apply CapsLock state to non character input keys.
11110 When nil, CapsLock only affects normal character input keys. */);
11111 Vw32_capslock_is_shiftlock
= Qnil
;
11113 DEFVAR_LISP ("w32-recognize-altgr",
11114 &Vw32_recognize_altgr
,
11115 doc
: /* Recognize right-alt and left-ctrl as AltGr.
11116 When nil, the right-alt and left-ctrl key combination is
11117 interpreted normally. */);
11118 Vw32_recognize_altgr
= Qt
;
11120 DEFVAR_BOOL ("w32-enable-unicode-output",
11121 &w32_enable_unicode_output
,
11122 doc
: /* Enable the use of Unicode for text output if non-nil.
11123 Unicode output may prevent some third party applications for displaying
11124 Far-East Languages on Windows 95/98 from working properly.
11125 NT uses Unicode internally anyway, so this flag will probably have no
11126 affect on NT machines. */);
11127 w32_enable_unicode_output
= 1;
11130 staticpro (&help_echo
);
11131 help_echo_object
= Qnil
;
11132 staticpro (&help_echo_object
);
11133 help_echo_window
= Qnil
;
11134 staticpro (&help_echo_window
);
11135 previous_help_echo
= Qnil
;
11136 staticpro (&previous_help_echo
);
11137 help_echo_pos
= -1;
11139 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
11140 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
11141 For example, if a block cursor is over a tab, it will be drawn as
11142 wide as that tab on the display. */);
11143 x_stretch_cursor_p
= 0;
11145 #if 0 /* TODO: Setting underline position from font properties. */
11146 DEFVAR_BOOL ("x-use-underline-position-properties",
11147 &x_use_underline_position_properties
,
11148 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11149 nil means ignore them. If you encounter fonts with bogus
11150 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11151 to 4.1, set this to nil. */);
11152 x_use_underline_position_properties
= 1;
11155 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11156 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
11157 Vx_toolkit_scroll_bars
= Qt
;
11159 staticpro (&last_mouse_motion_frame
);
11160 last_mouse_motion_frame
= Qnil
;