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))
65 /* Bitmaps for truncated lines. */
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. */
88 static unsigned short zv_bits
[] = {
89 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00};
90 static HBITMAP zv_bmp
;
92 /* An arrow like this: `<-'. */
96 static unsigned short left_bits
[] = {
97 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
98 static HBITMAP left_bmp
;
100 /* Right truncation arrow bitmap `->'. */
102 #define right_width 8
103 #define right_height 8
104 static unsigned short right_bits
[] = {
105 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
106 static HBITMAP right_bmp
;
108 /* Marker for continued lines. */
110 #define continued_width 8
111 #define continued_height 8
112 static unsigned short continued_bits
[] = {
113 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
114 static HBITMAP continued_bmp
;
116 /* Marker for continuation lines. */
118 #define continuation_width 8
119 #define continuation_height 8
120 static unsigned short continuation_bits
[] = {
121 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
122 static HBITMAP continuation_bmp
;
124 /* Overlay arrow bitmap. */
130 static unsigned short ov_bits
[] = {
131 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c};
133 /* A triangular arrow. */
136 static unsigned short ov_bits
[] = {
137 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
139 static HBITMAP ov_bmp
;
141 extern Lisp_Object Qhelp_echo
;
144 /* Non-nil means Emacs uses toolkit scroll bars. */
146 Lisp_Object Vx_toolkit_scroll_bars
;
148 /* If a string, w32_read_socket generates an event to display that string.
149 (The display is done in read_char.) */
151 static Lisp_Object help_echo
;
152 static Lisp_Object help_echo_window
;
153 static Lisp_Object help_echo_object
;
154 static int help_echo_pos
;
156 /* Temporary variable for w32_read_socket. */
158 static Lisp_Object previous_help_echo
;
160 /* Non-zero means that a HELP_EVENT has been generated since Emacs
163 static int any_help_event_p
;
165 /* Non-zero means draw block and hollow cursor as wide as the glyph
166 under it. For example, if a block cursor is over a tab, it will be
167 drawn as wide as that tab on the display. */
169 int x_stretch_cursor_p
;
171 extern unsigned int msh_mousewheel
;
173 extern void free_frame_menubar ();
175 extern void w32_menu_display_help (HMENU menu
, UINT menu_item
, UINT flags
);
177 extern int w32_codepage_for_font (char *fontname
);
179 extern glyph_metric
*w32_BDF_TextMetric(bdffont
*fontp
,
180 unsigned char *text
, int dim
);
181 extern Lisp_Object Vwindow_system
;
183 #define x_any_window_to_frame x_window_to_frame
184 #define x_top_window_to_frame x_window_to_frame
187 /* This is display since w32 does not support multiple ones. */
188 struct w32_display_info one_w32_display_info
;
189 struct w32_display_info
*x_display_list
;
191 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
192 one for each element of w32_display_list and in the same order.
193 NAME is the name of the frame.
194 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
195 Lisp_Object w32_display_name_list
;
197 /* Frame being updated by update_frame. This is declared in term.c.
198 This is set by update_begin and looked at by all the
199 w32 functions. It is zero while not inside an update.
200 In that case, the w32 functions assume that `SELECTED_FRAME ()'
201 is the frame to apply to. */
202 extern struct frame
*updating_frame
;
204 /* This is a frame waiting to be autoraised, within w32_read_socket. */
205 struct frame
*pending_autoraise_frame
;
207 /* Nominal cursor position -- where to draw output.
208 HPOS and VPOS are window relative glyph matrix coordinates.
209 X and Y are window relative pixel coordinates. */
211 struct cursor_pos output_cursor
;
213 /* Flag to enable Unicode output in case users wish to use programs
214 like Twinbridge on '95 rather than installed system level support
215 for Far East languages. */
216 int w32_enable_unicode_output
;
218 DWORD dwWindowsThreadId
= 0;
219 HANDLE hWindowsThread
= NULL
;
220 DWORD dwMainThreadId
= 0;
221 HANDLE hMainThread
= NULL
;
224 /* These definitions are new with Windows 95. */
225 #define SIF_RANGE 0x0001
226 #define SIF_PAGE 0x0002
227 #define SIF_POS 0x0004
228 #define SIF_DISABLENOSCROLL 0x0008
229 #define SIF_TRACKPOS 0x0010
230 #define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
232 typedef struct tagSCROLLINFO
241 } SCROLLINFO
, FAR
*LPSCROLLINFO
;
242 typedef SCROLLINFO CONST FAR
*LPCSCROLLINFO
;
245 /* Dynamic linking to new proportional scroll bar functions. */
246 int (PASCAL
*pfnSetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
, BOOL fRedraw
);
247 BOOL (PASCAL
*pfnGetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
);
249 int vertical_scroll_bar_min_handle
;
250 int vertical_scroll_bar_top_border
;
251 int vertical_scroll_bar_bottom_border
;
253 int last_scroll_bar_drag_pos
;
255 /* Mouse movement. */
257 /* Where the mouse was last time we reported a mouse event. */
259 FRAME_PTR last_mouse_frame
;
260 static RECT last_mouse_glyph
;
261 static Lisp_Object last_mouse_press_frame
;
263 Lisp_Object Vw32_num_mouse_buttons
;
265 Lisp_Object Vw32_swap_mouse_buttons
;
267 /* Control whether x_raise_frame also sets input focus. */
268 Lisp_Object Vw32_grab_focus_on_raise
;
270 /* Control whether Caps Lock affects non-ascii characters. */
271 Lisp_Object Vw32_capslock_is_shiftlock
;
273 /* Control whether right-alt and left-ctrl should be recognized as AltGr. */
274 Lisp_Object Vw32_recognize_altgr
;
276 /* The scroll bar in which the last motion event occurred.
278 If the last motion event occurred in a scroll bar, we set this
279 so w32_mouse_position can know whether to report a scroll bar motion or
282 If the last motion event didn't occur in a scroll bar, we set this
283 to Qnil, to tell w32_mouse_position to return an ordinary motion event. */
284 static Lisp_Object last_mouse_scroll_bar
;
285 static int last_mouse_scroll_bar_pos
;
287 /* This is a hack. We would really prefer that w32_mouse_position would
288 return the time associated with the position it returns, but there
289 doesn't seem to be any way to wrest the time-stamp from the server
290 along with the position query. So, we just keep track of the time
291 of the last movement we received, and return that in hopes that
292 it's somewhat accurate. */
294 static Time last_mouse_movement_time
;
296 /* Incremented by w32_read_socket whenever it really tries to read
300 static int volatile input_signal_count
;
302 static int input_signal_count
;
305 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
307 extern Lisp_Object Qface
, Qmouse_face
;
313 /* A mask of extra modifier bits to put into every keyboard char. */
315 extern int extra_keyboard_modifiers
;
317 /* Enumeration for overriding/changing the face to use for drawing
318 glyphs in x_draw_glyphs. */
320 enum draw_glyphs_face
330 static void x_update_window_end
P_ ((struct window
*, int, int));
331 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
332 void w32_delete_display
P_ ((struct w32_display_info
*));
333 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
335 static void set_output_cursor
P_ ((struct cursor_pos
*));
336 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
337 int *, int *, int *));
338 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
339 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
340 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
341 static void w32_handle_tool_bar_click
P_ ((struct frame
*,
342 struct input_event
*));
343 static void show_mouse_face
P_ ((struct w32_display_info
*,
344 enum draw_glyphs_face
));
345 void clear_mouse_face
P_ ((struct w32_display_info
*));
347 void x_lower_frame
P_ ((struct frame
*));
348 void x_scroll_bar_clear
P_ ((struct frame
*));
349 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
350 void x_raise_frame
P_ ((struct frame
*));
351 void x_set_window_size
P_ ((struct frame
*, int, int, int));
352 void x_wm_set_window_state
P_ ((struct frame
*, int));
353 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
354 void w32_initialize
P_ ((void));
355 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
356 int x_compute_min_glyph_bounds
P_ ((struct frame
*));
357 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
359 enum draw_glyphs_face
));
360 static void x_update_end
P_ ((struct frame
*));
361 static void w32_frame_up_to_date
P_ ((struct frame
*));
362 static void w32_reassert_line_highlight
P_ ((int, int));
363 static void x_change_line_highlight
P_ ((int, int, int, int));
364 static void w32_set_terminal_modes
P_ ((void));
365 static void w32_reset_terminal_modes
P_ ((void));
366 static void w32_cursor_to
P_ ((int, int, int, int));
367 static void x_write_glyphs
P_ ((struct glyph
*, int));
368 static void x_clear_end_of_line
P_ ((int));
369 static void x_clear_frame
P_ ((void));
370 static void x_clear_cursor
P_ ((struct window
*));
371 static void frame_highlight
P_ ((struct frame
*));
372 static void frame_unhighlight
P_ ((struct frame
*));
373 static void w32_new_focus_frame
P_ ((struct w32_display_info
*,
375 static void w32_frame_rehighlight
P_ ((struct frame
*));
376 static void x_frame_rehighlight
P_ ((struct w32_display_info
*));
377 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
378 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
379 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
380 static void expose_window_tree
P_ ((struct window
*, RECT
*));
381 static void expose_window
P_ ((struct window
*, RECT
*));
382 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
383 RECT
*, enum glyph_row_area
));
384 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
386 void x_update_cursor
P_ ((struct frame
*, int));
387 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
388 static void x_update_window_cursor
P_ ((struct window
*, int));
389 static void x_erase_phys_cursor
P_ ((struct window
*));
390 void x_display_cursor
P_ ((struct window
*w
, int, int, int, int, int));
391 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
392 static void w32_draw_bitmap
P_ ((struct window
*, HDC hdc
, struct glyph_row
*,
394 static void w32_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
396 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, RECT
*));
397 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
398 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
400 static Lisp_Object Qvendor_specific_keysyms
;
403 /***********************************************************************
405 ***********************************************************************/
409 /* This is a function useful for recording debugging information about
410 the sequence of occurrences in this file. */
418 struct record event_record
[100];
420 int event_record_index
;
422 record_event (locus
, type
)
426 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
427 event_record_index
= 0;
429 event_record
[event_record_index
].locus
= locus
;
430 event_record
[event_record_index
].type
= type
;
431 event_record_index
++;
437 void XChangeGC (void * ignore
, XGCValues
* gc
, unsigned long mask
,
440 if (mask
& GCForeground
)
441 gc
->foreground
= xgcv
->foreground
;
442 if (mask
& GCBackground
)
443 gc
->background
= xgcv
->background
;
445 gc
->font
= xgcv
->font
;
448 XGCValues
*XCreateGC (void * ignore
, Window window
, unsigned long mask
,
451 XGCValues
*gc
= (XGCValues
*) xmalloc (sizeof (XGCValues
));
452 bzero (gc
, sizeof (XGCValues
));
454 XChangeGC (ignore
, gc
, mask
, xgcv
);
459 void XGetGCValues (void* ignore
, XGCValues
*gc
,
460 unsigned long mask
, XGCValues
*xgcv
)
462 XChangeGC (ignore
, xgcv
, mask
, gc
);
466 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
470 HRGN clip_region
= CreateRectRgnIndirect (rect
);
471 SelectClipRgn (hdc
, clip_region
);
472 DeleteObject (clip_region
);
475 SelectClipRgn (hdc
, NULL
);
479 /* Draw a hollow rectangle at the specified position. */
481 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
482 int width
, int height
)
487 hb
= CreateSolidBrush (gc
->background
);
488 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
489 oldhb
= SelectObject (hdc
, hb
);
490 oldhp
= SelectObject (hdc
, hp
);
492 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
494 SelectObject (hdc
, oldhb
);
495 SelectObject (hdc
, oldhp
);
500 /* Draw a filled rectangle at the specified position. */
502 w32_fill_rect (f
, hdc
, pix
, lprect
)
510 hb
= CreateSolidBrush (pix
);
511 FillRect (hdc
, lprect
, hb
);
520 HDC hdc
= get_frame_dc (f
);
522 /* Under certain conditions, this can be called at startup with
523 a console frame pointer before the GUI frame is created. An HDC
524 of 0 indicates this. */
527 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
528 w32_clear_rect (f
, hdc
, &rect
);
531 release_frame_dc (f
, hdc
);
535 /***********************************************************************
536 Starting and ending an update
537 ***********************************************************************/
539 /* Start an update of frame F. This function is installed as a hook
540 for update_begin, i.e. it is called when update_begin is called.
541 This function is called prior to calls to x_update_window_begin for
542 each window being updated. */
548 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
550 if (! FRAME_W32_P (f
))
553 /* Regenerate display palette before drawing if list of requested
554 colors has changed. */
555 if (display_info
->regen_palette
)
557 w32_regenerate_palette (f
);
558 display_info
->regen_palette
= FALSE
;
563 /* Start update of window W. Set the global variable updated_window
564 to the window being updated and set output_cursor to the cursor
568 x_update_window_begin (w
)
571 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
572 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
575 set_output_cursor (&w
->cursor
);
579 if (f
== display_info
->mouse_face_mouse_frame
)
581 /* Don't do highlighting for mouse motion during the update. */
582 display_info
->mouse_face_defer
= 1;
584 /* If F needs to be redrawn, simply forget about any prior mouse
586 if (FRAME_GARBAGED_P (f
))
587 display_info
->mouse_face_window
= Qnil
;
589 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
590 their mouse_face_p flag set, which means that they are always
591 unequal to rows in a desired matrix which never have that
592 flag set. So, rows containing mouse-face glyphs are never
593 scrolled, and we don't have to switch the mouse highlight off
594 here to prevent it from being scrolled. */
596 /* Can we tell that this update does not affect the window
597 where the mouse highlight is? If so, no need to turn off.
598 Likewise, don't do anything if the frame is garbaged;
599 in that case, the frame's current matrix that we would use
600 is all wrong, and we will redisplay that line anyway. */
601 if (!NILP (display_info
->mouse_face_window
)
602 && w
== XWINDOW (display_info
->mouse_face_window
))
606 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
607 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
610 if (i
< w
->desired_matrix
->nrows
)
611 clear_mouse_face (display_info
);
620 /* Draw a vertical window border to the right of window W if W doesn't
621 have vertical scroll bars. */
624 x_draw_vertical_border (w
)
627 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
629 /* Redraw borders between horizontally adjacent windows. Don't
630 do it for frames with vertical scroll bars because either the
631 right scroll bar of a window, or the left scroll bar of its
632 neighbor will suffice as a border. */
633 if (!WINDOW_RIGHTMOST_P (w
)
634 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
639 window_box_edges (w
, -1, &r
.left
, &r
.top
, &r
.right
, &r
.bottom
);
640 r
.left
= r
.right
+ FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
641 r
.right
= r
.left
+ 1;
644 hdc
= get_frame_dc (f
);
645 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
646 release_frame_dc (f
, hdc
);
651 /* End update of window W (which is equal to updated_window).
653 Draw vertical borders between horizontally adjacent windows, and
654 display W's cursor if CURSOR_ON_P is non-zero.
656 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
657 glyphs in mouse-face were overwritten. In that case we have to
658 make sure that the mouse-highlight is properly redrawn.
660 W may be a menu bar pseudo-window in case we don't have X toolkit
661 support. Such windows don't have a cursor, so don't display it
665 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
667 int cursor_on_p
, mouse_face_overwritten_p
;
669 if (!w
->pseudo_window_p
)
671 struct w32_display_info
*dpyinfo
672 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
676 /* If a row with mouse-face was overwritten, arrange for
677 XTframe_up_to_date to redisplay the mouse highlight. */
678 if (mouse_face_overwritten_p
)
680 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
681 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
682 dpyinfo
->mouse_face_window
= Qnil
;
686 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
688 output_cursor
.x
, output_cursor
.y
);
690 x_draw_vertical_border (w
);
694 updated_window
= NULL
;
698 /* End update of frame F. This function is installed as a hook in
705 if (! FRAME_W32_P (f
))
708 /* Mouse highlight may be displayed again. */
709 FRAME_W32_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
713 /* This function is called from various places in xdisp.c whenever a
714 complete update has been performed. The global variable
715 updated_window is not available here. */
718 w32_frame_up_to_date (f
)
723 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
724 if (dpyinfo
->mouse_face_deferred_gc
725 || f
== dpyinfo
->mouse_face_mouse_frame
)
728 if (dpyinfo
->mouse_face_mouse_frame
)
729 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
730 dpyinfo
->mouse_face_mouse_x
,
731 dpyinfo
->mouse_face_mouse_y
);
732 dpyinfo
->mouse_face_deferred_gc
= 0;
739 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
740 arrow bitmaps, or clear the areas where they would be displayed
741 before DESIRED_ROW is made current. The window being updated is
742 found in updated_window. This function It is called from
743 update_window_line only if it is known that there are differences
744 between bitmaps to be drawn between current row and DESIRED_ROW. */
747 x_after_update_window_line (desired_row
)
748 struct glyph_row
*desired_row
;
750 struct window
*w
= updated_window
;
754 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
760 x_draw_row_bitmaps (w
, desired_row
);
762 /* When a window has disappeared, make sure that no rest of
763 full-width rows stays visible in the internal border. */
764 if (windows_or_buffers_changed
765 && (f
= XFRAME (w
->frame
),
766 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
769 int height
= desired_row
->visible_height
;
770 int x
= (window_box_right (w
, -1)
771 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
772 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
773 HDC hdc
= get_frame_dc (f
);
775 w32_clear_area (f
, hdc
, x
, y
, width
, height
);
776 release_frame_dc (f
, hdc
);
784 /* Draw the bitmap WHICH in one of the areas to the left or right of
785 window W. ROW is the glyph row for which to display the bitmap; it
786 determines the vertical position at which the bitmap has to be
790 w32_draw_bitmap (w
, hdc
, row
, which
)
793 struct glyph_row
*row
;
794 enum bitmap_type which
;
796 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
797 Window window
= FRAME_W32_WINDOW (f
);
804 /* Must clip because of partially visible lines. */
805 w32_clip_to_row (w
, row
, hdc
, 1);
809 case LEFT_TRUNCATION_BITMAP
:
813 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
815 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
818 case OVERLAY_ARROW_BITMAP
:
822 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
824 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
827 case RIGHT_TRUNCATION_BITMAP
:
831 x
= window_box_right (w
, -1);
832 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
835 case CONTINUED_LINE_BITMAP
:
836 wd
= continued_width
;
837 h
= continued_height
;
838 pixmap
= continued_bmp
;
839 x
= window_box_right (w
, -1);
840 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
843 case CONTINUATION_LINE_BITMAP
:
844 wd
= continuation_width
;
845 h
= continuation_height
;
846 pixmap
= continuation_bmp
;
847 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
849 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
856 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
858 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
865 /* Convert to frame coordinates. Set dy to the offset in the row to
866 start drawing the bitmap. */
867 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
868 dy
= (row
->height
- h
) / 2;
870 /* Draw the bitmap. */
871 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
873 compat_hdc
= CreateCompatibleDC (hdc
);
876 horig_obj
= SelectObject (compat_hdc
, pixmap
);
877 SetTextColor (hdc
, face
->background
);
878 SetBkColor (hdc
, face
->foreground
);
880 BitBlt (hdc
, x
, y
+ dy
, wd
, h
, compat_hdc
, 0, 0, SRCCOPY
);
882 SelectObject (compat_hdc
, horig_obj
);
883 DeleteDC (compat_hdc
);
888 /* Draw flags bitmaps for glyph row ROW on window W. Call this
889 function with input blocked. */
892 x_draw_row_bitmaps (w
, row
)
894 struct glyph_row
*row
;
896 struct frame
*f
= XFRAME (w
->frame
);
897 enum bitmap_type bitmap
;
899 int header_line_height
= -1;
902 xassert (interrupt_input_blocked
);
904 /* If row is completely invisible, because of vscrolling, we
905 don't have to draw anything. */
906 if (row
->visible_height
<= 0)
909 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
910 PREPARE_FACE_FOR_DISPLAY (f
, face
);
912 /* Decide which bitmap to draw at the left side. */
913 if (row
->overlay_arrow_p
)
914 bitmap
= OVERLAY_ARROW_BITMAP
;
915 else if (row
->truncated_on_left_p
)
916 bitmap
= LEFT_TRUNCATION_BITMAP
;
917 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
918 bitmap
= CONTINUATION_LINE_BITMAP
;
919 else if (row
->indicate_empty_line_p
)
920 bitmap
= ZV_LINE_BITMAP
;
924 hdc
= get_frame_dc (f
);
926 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
928 if (bitmap
== NO_BITMAP
929 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
930 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
932 /* If W has a vertical border to its left, don't draw over it. */
933 int border
= ((XFASTINT (w
->left
) > 0
934 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
936 int left
= window_box_left (w
, -1);
938 if (header_line_height
< 0)
939 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
941 w32_fill_area (f
, hdc
, face
->background
,
942 left
- FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) + border
,
943 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
945 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
946 row
->visible_height
);
949 /* Draw the left bitmap. */
950 if (bitmap
!= NO_BITMAP
)
951 w32_draw_bitmap (w
, hdc
, row
, bitmap
);
953 /* Decide which bitmap to draw at the right side. */
954 if (row
->truncated_on_right_p
)
955 bitmap
= RIGHT_TRUNCATION_BITMAP
;
956 else if (row
->continued_p
)
957 bitmap
= CONTINUED_LINE_BITMAP
;
961 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
963 if (bitmap
== NO_BITMAP
964 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
965 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
967 int right
= window_box_right (w
, -1);
969 if (header_line_height
< 0)
970 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
972 w32_fill_area (f
, hdc
, face
->background
,
974 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
976 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
977 row
->visible_height
);
980 /* Draw the right bitmap. */
981 if (bitmap
!= NO_BITMAP
)
982 w32_draw_bitmap (w
, hdc
, row
, bitmap
);
984 release_frame_dc (f
, hdc
);
988 /***********************************************************************
990 ***********************************************************************/
992 /* External interface to control of standout mode. Not used for W32
993 frames. Aborts when called. */
996 w32_reassert_line_highlight (new, vpos
)
1004 f
= SELECTED_FRAME ();
1006 if (! FRAME_W32_P (f
))
1013 /* Call this when about to modify line at position VPOS and change
1014 whether it is highlighted. Not used for W32 frames. Aborts when
1018 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1019 int new_highlight
, vpos
, y
, first_unused_hpos
;
1026 f
= SELECTED_FRAME ();
1028 if (! FRAME_W32_P (f
))
1035 /* This is called when starting Emacs and when restarting after
1036 suspend. When starting Emacs, no window is mapped. And nothing
1037 must be done to Emacs's own window if it is suspended (though that
1041 w32_set_terminal_modes (void)
1045 /* This is called when exiting or suspending Emacs. Exiting will make
1046 the W32 windows go away, and suspending requires no action. */
1049 w32_reset_terminal_modes (void)
1055 /***********************************************************************
1057 ***********************************************************************/
1059 /* Set the global variable output_cursor to CURSOR. All cursor
1060 positions are relative to updated_window. */
1063 set_output_cursor (cursor
)
1064 struct cursor_pos
*cursor
;
1066 output_cursor
.hpos
= cursor
->hpos
;
1067 output_cursor
.vpos
= cursor
->vpos
;
1068 output_cursor
.x
= cursor
->x
;
1069 output_cursor
.y
= cursor
->y
;
1073 /* Set a nominal cursor position.
1075 HPOS and VPOS are column/row positions in a window glyph matrix. X
1076 and Y are window text area relative pixel positions.
1078 If this is done during an update, updated_window will contain the
1079 window that is being updated and the position is the future output
1080 cursor position for that window. If updated_window is null, use
1081 selected_window and display the cursor at the given position. */
1084 w32_cursor_to (vpos
, hpos
, y
, x
)
1085 int vpos
, hpos
, y
, x
;
1089 /* If updated_window is not set, work on selected_window. */
1093 w
= XWINDOW (selected_window
);
1095 /* Set the output cursor. */
1096 output_cursor
.hpos
= hpos
;
1097 output_cursor
.vpos
= vpos
;
1098 output_cursor
.x
= x
;
1099 output_cursor
.y
= y
;
1101 /* If not called as part of an update, really display the cursor.
1102 This will also set the cursor position of W. */
1103 if (updated_window
== NULL
)
1106 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1113 /***********************************************************************
1115 ***********************************************************************/
1117 /* Function prototypes of this page. */
1119 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1123 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1124 int, wchar_t *, int));
1125 static XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*,
1127 enum w32_char_font_type
));
1128 static enum w32_char_font_type
1129 w32_encode_char
P_ ((int, wchar_t *, struct font_info
*, int *));
1130 static void x_append_glyph
P_ ((struct it
*));
1131 static void x_append_composite_glyph
P_ ((struct it
*));
1132 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1134 static void x_produce_glyphs
P_ ((struct it
*));
1135 static void x_produce_image_glyph
P_ ((struct it
*it
));
1138 /* Dealing with bits of wchar_t as if they were an XChar2B. */
1139 #define BUILD_WCHAR_T(byte1, byte2) \
1140 ((wchar_t)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff)))
1144 (((ch) & 0xff00) >> 8)
1150 /* Get metrics of character CHAR2B in FONT. Value is always non-null.
1151 If CHAR2B is not contained in FONT, the font's default character
1152 metric is returned. */
1155 w32_bdf_per_char_metric (font
, char2b
, dim
, pcm
)
1161 glyph_metric
* bdf_metric
;
1165 buf
[0] = (char)(*char2b
);
1168 buf
[0] = BYTE1 (*char2b
);
1169 buf
[1] = BYTE2 (*char2b
);
1172 bdf_metric
= w32_BDF_TextMetric (font
->bdf
, buf
, dim
);
1176 pcm
->width
= bdf_metric
->dwidth
;
1177 pcm
->lbearing
= bdf_metric
->bbox
;
1178 pcm
->rbearing
= bdf_metric
->dwidth
1179 - (bdf_metric
->bbox
+ bdf_metric
->bbw
);
1180 pcm
->ascent
= bdf_metric
->bboy
+ bdf_metric
->bbh
;
1181 pcm
->descent
= -bdf_metric
->bboy
;
1190 w32_native_per_char_metric (font
, char2b
, font_type
, pcm
)
1193 enum w32_char_font_type font_type
;
1196 HDC hdc
= GetDC (NULL
);
1198 BOOL retval
= FALSE
;
1200 xassert (font
&& char2b
);
1201 xassert (font
->hfont
);
1202 xassert (font_type
== UNICODE_FONT
|| font_type
== ANSI_FONT
);
1204 old_font
= SelectObject (hdc
, font
->hfont
);
1206 if ((font
->tm
.tmPitchAndFamily
& TMPF_TRUETYPE
) != 0)
1210 if (font_type
== UNICODE_FONT
)
1211 retval
= GetCharABCWidthsW (hdc
, *char2b
, *char2b
, &char_widths
);
1213 retval
= GetCharABCWidthsA (hdc
, *char2b
, *char2b
, &char_widths
);
1217 pcm
->width
= char_widths
.abcA
+ char_widths
.abcB
+ char_widths
.abcC
;
1218 pcm
->lbearing
= char_widths
.abcA
;
1219 pcm
->rbearing
= pcm
->width
- char_widths
.abcC
;
1220 pcm
->ascent
= FONT_BASE (font
);
1221 pcm
->descent
= FONT_DESCENT (font
);
1227 /* Either font is not a True-type font, or GetCharABCWidthsW
1228 failed (it is not supported on Windows 9x for instance), so we
1229 can't determine the full info we would like. All is not lost
1230 though - we can call GetTextExtentPoint32 to get rbearing and
1231 deduce width based on the font's per-string overhang. lbearing
1232 is assumed to be zero. */
1234 /* TODO: Some Thai characters (and other composites if Windows
1235 supports them) do have lbearing, and report their total width
1236 as zero. Need some way of handling them when
1237 GetCharABCWidthsW fails. */
1240 if (font_type
== UNICODE_FONT
)
1241 retval
= GetTextExtentPoint32W (hdc
, char2b
, 1, &sz
);
1243 retval
= GetTextExtentPoint32A (hdc
, (char*)char2b
, 1, &sz
);
1247 pcm
->width
= sz
.cx
- font
->tm
.tmOverhang
;
1248 pcm
->rbearing
= sz
.cx
;
1250 pcm
->ascent
= FONT_BASE (font
);
1251 pcm
->descent
= FONT_DESCENT (font
);
1256 if (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0)
1261 SelectObject (hdc
, old_font
);
1262 ReleaseDC (NULL
, hdc
);
1268 static XCharStruct
*
1269 w32_per_char_metric (font
, char2b
, font_type
)
1272 enum w32_char_font_type font_type
;
1274 /* The result metric information. */
1278 xassert (font
&& char2b
);
1279 xassert (font_type
!= UNKNOWN_FONT
);
1281 /* Handle the common cases quickly. */
1282 if (!font
->bdf
&& font
->per_char
== NULL
)
1283 /* TODO: determine whether char2b exists in font? */
1284 return &font
->max_bounds
;
1285 else if (!font
->bdf
&& *char2b
< 128)
1286 return &font
->per_char
[*char2b
];
1288 pcm
= &font
->scratch
;
1290 if (font_type
== BDF_1D_FONT
)
1291 retval
= w32_bdf_per_char_metric (font
, char2b
, 1, pcm
);
1292 else if (font_type
== BDF_2D_FONT
)
1293 retval
= w32_bdf_per_char_metric (font
, char2b
, 2, pcm
);
1295 retval
= w32_native_per_char_metric (font
, char2b
, font_type
, pcm
);
1304 w32_cache_char_metrics (font
)
1307 wchar_t char2b
= L
'x';
1309 /* Cache char metrics for the common cases. */
1312 /* TODO: determine whether font is fixed-pitch. */
1313 if (!w32_bdf_per_char_metric (font
, &char2b
, 1, &font
->max_bounds
))
1315 /* Use the font width and height as max bounds, as not all BDF
1316 fonts contain the letter 'x'. */
1317 font
->max_bounds
.width
= FONT_MAX_WIDTH (font
);
1318 font
->max_bounds
.lbearing
= -font
->bdf
->llx
;
1319 font
->max_bounds
.rbearing
= FONT_MAX_WIDTH (font
) - font
->bdf
->urx
;
1320 font
->max_bounds
.ascent
= FONT_BASE (font
);
1321 font
->max_bounds
.descent
= FONT_DESCENT (font
);
1326 if (((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
) != 0)
1327 /* Some fonts (eg DBCS fonts) are marked as fixed width even
1328 though they contain characters of different widths. */
1329 || (font
->tm
.tmMaxCharWidth
!= font
->tm
.tmAveCharWidth
))
1331 /* Font is not fixed pitch, so cache per_char info for the
1332 ASCII characters. It would be much more work, and probably
1333 not worth it, to cache other chars, since we may change
1334 between using Unicode and ANSI text drawing functions at
1338 font
->per_char
= xmalloc (128 * sizeof(XCharStruct
));
1339 for (i
= 0; i
< 128; i
++)
1342 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1343 &font
->per_char
[i
]);
1347 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1353 /* Determine if a font is double byte. */
1354 int w32_font_is_double_byte (XFontStruct
*font
)
1356 return font
->double_byte_p
;
1361 w32_use_unicode_for_codepage (codepage
)
1364 /* If the current codepage is supported, use Unicode for output. */
1365 return (w32_enable_unicode_output
1366 && codepage
!= CP_8BIT
1367 && (codepage
== CP_UNICODE
|| IsValidCodePage (codepage
)));
1370 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1371 the two-byte form of C. Encoding is returned in *CHAR2B. */
1373 static INLINE
enum w32_char_font_type
1374 w32_encode_char (c
, char2b
, font_info
, two_byte_p
)
1377 struct font_info
*font_info
;
1380 int charset
= CHAR_CHARSET (c
);
1384 XFontStruct
*font
= font_info
->font
;
1386 xassert (two_byte_p
);
1388 *two_byte_p
= w32_font_is_double_byte (font
);
1390 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1391 This may be either a program in a special encoder language or a
1393 if (font_info
->font_encoder
)
1395 /* It's a program. */
1396 struct ccl_program
*ccl
= font_info
->font_encoder
;
1398 if (CHARSET_DIMENSION (charset
) == 1)
1400 ccl
->reg
[0] = charset
;
1401 ccl
->reg
[1] = BYTE2 (*char2b
);
1405 ccl
->reg
[0] = charset
;
1406 ccl
->reg
[1] = BYTE1 (*char2b
);
1407 ccl
->reg
[2] = BYTE2 (*char2b
);
1410 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1412 /* We assume that MSBs are appropriately set/reset by CCL
1414 if (!*two_byte_p
) /* 1-byte font */
1415 *char2b
= BUILD_WCHAR_T (0, ccl
->reg
[1]);
1417 *char2b
= BUILD_WCHAR_T (ccl
->reg
[1], ccl
->reg
[2]);
1419 else if (font_info
->encoding
[charset
])
1421 /* Fixed encoding scheme. See fontset.h for the meaning of the
1422 encoding numbers. */
1423 int enc
= font_info
->encoding
[charset
];
1425 if ((enc
== 1 || enc
== 2)
1426 && CHARSET_DIMENSION (charset
) == 2)
1427 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
) | 0x80, BYTE2 (*char2b
));
1429 if (enc
== 1 || enc
== 3
1430 || (enc
== 4 && CHARSET_DIMENSION (charset
) == 1))
1431 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
), BYTE2 (*char2b
) | 0x80);
1436 ENCODE_SJIS (BYTE1 (*char2b
), BYTE2 (*char2b
),
1438 *char2b
= BUILD_WCHAR_T (sjis1
, sjis2
);
1441 codepage
= w32_codepage_for_font (font_info
->name
);
1443 /* If charset is not ASCII or Latin-1, may need to move it into
1445 if ( font
&& !font
->bdf
&& w32_use_unicode_for_codepage (codepage
)
1446 && charset
!= CHARSET_ASCII
&& charset
!= charset_latin_iso8859_1
1447 && charset
!= CHARSET_8_BIT_CONTROL
&& charset
!= CHARSET_8_BIT_GRAPHIC
)
1450 temp
[0] = BYTE1 (*char2b
);
1451 temp
[1] = BYTE2 (*char2b
);
1453 if (codepage
!= CP_UNICODE
)
1456 MultiByteToWideChar (codepage
, 0, temp
, 2, char2b
, 1);
1458 MultiByteToWideChar (codepage
, 0, temp
+1, 1, char2b
, 1);
1464 return UNKNOWN_FONT
;
1465 else if (font
->bdf
&& CHARSET_DIMENSION (charset
) == 1)
1470 return UNICODE_FONT
;
1476 /* Get face and two-byte form of character C in face FACE_ID on frame
1477 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1478 means we want to display multibyte text. Value is a pointer to a
1479 realized face that is ready for display. */
1481 static INLINE
struct face
*
1482 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1488 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1492 /* Unibyte case. We don't have to encode, but we have to make
1493 sure to use a face suitable for unibyte. */
1494 *char2b
= BUILD_WCHAR_T (0, c
);
1495 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1496 face
= FACE_FROM_ID (f
, face_id
);
1498 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1500 /* Case of ASCII in a face known to fit ASCII. */
1501 *char2b
= BUILD_WCHAR_T (0, c
);
1505 int c1
, c2
, charset
;
1507 /* Split characters into bytes. If c2 is -1 afterwards, C is
1508 really a one-byte character so that byte1 is zero. */
1509 SPLIT_CHAR (c
, charset
, c1
, c2
);
1511 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1513 *char2b
= BUILD_WCHAR_T (0, c1
);
1515 /* Maybe encode the character in *CHAR2B. */
1516 if (face
->font
!= NULL
)
1518 struct font_info
*font_info
1519 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1521 w32_encode_char (c
, char2b
, font_info
, &multibyte_p
);
1525 /* Make sure X resources of the face are allocated. */
1526 xassert (face
!= NULL
);
1527 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1533 /* Get face and two-byte form of character glyph GLYPH on frame F.
1534 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1535 a pointer to a realized face that is ready for display. */
1537 static INLINE
struct face
*
1538 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1540 struct glyph
*glyph
;
1547 xassert (glyph
->type
== CHAR_GLYPH
);
1548 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1553 two_byte_p
= &dummy
;
1555 if (!glyph
->multibyte_p
)
1557 /* Unibyte case. We don't have to encode, but we have to make
1558 sure to use a face suitable for unibyte. */
1559 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1561 else if (glyph
->u
.ch
< 128
1562 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1564 /* Case of ASCII in a face known to fit ASCII. */
1565 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1569 int c1
, c2
, charset
;
1571 /* Split characters into bytes. If c2 is -1 afterwards, C is
1572 really a one-byte character so that byte1 is zero. */
1573 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1575 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1577 *char2b
= BUILD_WCHAR_T (0, c1
);
1579 /* Maybe encode the character in *CHAR2B. */
1580 if (charset
!= CHARSET_ASCII
)
1582 struct font_info
*font_info
1583 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1586 glyph
->w32_font_type
1587 = w32_encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
1592 /* Make sure X resources of the face are allocated. */
1593 xassert (face
!= NULL
);
1594 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1599 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1600 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1606 struct glyph
*glyph
;
1607 enum glyph_row_area area
= it
->area
;
1609 xassert (it
->glyph_row
);
1610 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1612 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1613 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1615 glyph
->charpos
= CHARPOS (it
->position
);
1616 glyph
->object
= it
->object
;
1617 glyph
->pixel_width
= it
->pixel_width
;
1618 glyph
->voffset
= it
->voffset
;
1619 glyph
->type
= CHAR_GLYPH
;
1620 glyph
->multibyte_p
= it
->multibyte_p
;
1621 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1622 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1623 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1624 || it
->phys_descent
> it
->descent
);
1625 glyph
->padding_p
= 0;
1626 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1627 glyph
->face_id
= it
->face_id
;
1628 glyph
->u
.ch
= it
->char_to_display
;
1629 glyph
->w32_font_type
= UNKNOWN_FONT
;
1630 ++it
->glyph_row
->used
[area
];
1634 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1635 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1638 x_append_composite_glyph (it
)
1641 struct glyph
*glyph
;
1642 enum glyph_row_area area
= it
->area
;
1644 xassert (it
->glyph_row
);
1646 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1647 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1649 glyph
->charpos
= CHARPOS (it
->position
);
1650 glyph
->object
= it
->object
;
1651 glyph
->pixel_width
= it
->pixel_width
;
1652 glyph
->voffset
= it
->voffset
;
1653 glyph
->type
= COMPOSITE_GLYPH
;
1654 glyph
->multibyte_p
= it
->multibyte_p
;
1655 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1656 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1657 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1658 || it
->phys_descent
> it
->descent
);
1659 glyph
->padding_p
= 0;
1660 glyph
->glyph_not_available_p
= 0;
1661 glyph
->face_id
= it
->face_id
;
1662 glyph
->u
.cmp_id
= it
->cmp_id
;
1663 glyph
->w32_font_type
= UNKNOWN_FONT
;
1664 ++it
->glyph_row
->used
[area
];
1669 /* Change IT->ascent and IT->height according to the setting of
1673 take_vertical_position_into_account (it
)
1678 if (it
->voffset
< 0)
1679 /* Increase the ascent so that we can display the text higher
1681 it
->ascent
+= abs (it
->voffset
);
1683 /* Increase the descent so that we can display the text lower
1685 it
->descent
+= it
->voffset
;
1690 /* Produce glyphs/get display metrics for the image IT is loaded with.
1691 See the description of struct display_iterator in dispextern.h for
1692 an overview of struct display_iterator. */
1695 x_produce_image_glyph (it
)
1701 xassert (it
->what
== IT_IMAGE
);
1703 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1704 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1707 /* Make sure X resources of the face and image are loaded. */
1708 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1709 prepare_image_for_display (it
->f
, img
);
1711 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1712 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1713 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1717 if (face
->box
!= FACE_NO_BOX
)
1719 if (face
->box_line_width
> 0)
1721 it
->ascent
+= face
->box_line_width
;
1722 it
->descent
+= face
->box_line_width
;
1725 if (it
->start_of_box_run_p
)
1726 it
->pixel_width
+= abs (face
->box_line_width
);
1727 if (it
->end_of_box_run_p
)
1728 it
->pixel_width
+= abs (face
->box_line_width
);
1731 take_vertical_position_into_account (it
);
1735 struct glyph
*glyph
;
1736 enum glyph_row_area area
= it
->area
;
1738 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1739 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1741 glyph
->charpos
= CHARPOS (it
->position
);
1742 glyph
->object
= it
->object
;
1743 glyph
->pixel_width
= it
->pixel_width
;
1744 glyph
->voffset
= it
->voffset
;
1745 glyph
->type
= IMAGE_GLYPH
;
1746 glyph
->multibyte_p
= it
->multibyte_p
;
1747 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1748 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1749 glyph
->overlaps_vertically_p
= 0;
1750 glyph
->padding_p
= 0;
1751 glyph
->glyph_not_available_p
= 0;
1752 glyph
->face_id
= it
->face_id
;
1753 glyph
->u
.img_id
= img
->id
;
1754 glyph
->w32_font_type
= UNKNOWN_FONT
;
1755 ++it
->glyph_row
->used
[area
];
1761 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1762 of the glyph, WIDTH and HEIGHT are the width and height of the
1763 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1764 ascent of the glyph (0 <= ASCENT <= 1). */
1767 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1773 struct glyph
*glyph
;
1774 enum glyph_row_area area
= it
->area
;
1776 xassert (ascent
>= 0 && ascent
<= 1);
1778 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1779 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1781 glyph
->charpos
= CHARPOS (it
->position
);
1782 glyph
->object
= object
;
1783 glyph
->pixel_width
= width
;
1784 glyph
->voffset
= it
->voffset
;
1785 glyph
->type
= STRETCH_GLYPH
;
1786 glyph
->multibyte_p
= it
->multibyte_p
;
1787 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1788 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1789 glyph
->overlaps_vertically_p
= 0;
1790 glyph
->padding_p
= 0;
1791 glyph
->glyph_not_available_p
= 0;
1792 glyph
->face_id
= it
->face_id
;
1793 glyph
->u
.stretch
.ascent
= height
* ascent
;
1794 glyph
->u
.stretch
.height
= height
;
1795 glyph
->w32_font_type
= UNKNOWN_FONT
;
1796 ++it
->glyph_row
->used
[area
];
1801 /* Produce a stretch glyph for iterator IT. IT->object is the value
1802 of the glyph property displayed. The value must be a list
1803 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1806 1. `:width WIDTH' specifies that the space should be WIDTH *
1807 canonical char width wide. WIDTH may be an integer or floating
1810 2. `:relative-width FACTOR' specifies that the width of the stretch
1811 should be computed from the width of the first character having the
1812 `glyph' property, and should be FACTOR times that width.
1814 3. `:align-to HPOS' specifies that the space should be wide enough
1815 to reach HPOS, a value in canonical character units.
1817 Exactly one of the above pairs must be present.
1819 4. `:height HEIGHT' specifies that the height of the stretch produced
1820 should be HEIGHT, measured in canonical character units.
1822 5. `:relative-height FACTOR' specifies that the height of the the
1823 stretch should be FACTOR times the height of the characters having
1826 Either none or exactly one of 4 or 5 must be present.
1828 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1829 of the stretch should be used for the ascent of the stretch.
1830 ASCENT must be in the range 0 <= ASCENT <= 100. */
1833 ((INTEGERP (X) || FLOATP (X)) \
1839 x_produce_stretch_glyph (it
)
1842 /* (space :width WIDTH :height HEIGHT. */
1844 extern Lisp_Object Qspace
;
1846 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1847 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1848 extern Lisp_Object QCalign_to
;
1849 Lisp_Object prop
, plist
;
1850 double width
= 0, height
= 0, ascent
= 0;
1851 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1852 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1854 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1856 /* List should start with `space'. */
1857 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1858 plist
= XCDR (it
->object
);
1860 /* Compute the width of the stretch. */
1861 if (prop
= Fplist_get (plist
, QCwidth
),
1863 /* Absolute width `:width WIDTH' specified and valid. */
1864 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1865 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1868 /* Relative width `:relative-width FACTOR' specified and valid.
1869 Compute the width of the characters having the `glyph'
1872 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1875 if (it
->multibyte_p
)
1877 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1878 - IT_BYTEPOS (*it
));
1879 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1882 it2
.c
= *p
, it2
.len
= 1;
1884 it2
.glyph_row
= NULL
;
1885 it2
.what
= IT_CHARACTER
;
1886 x_produce_glyphs (&it2
);
1887 width
= NUMVAL (prop
) * it2
.pixel_width
;
1889 else if (prop
= Fplist_get (plist
, QCalign_to
),
1891 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1893 /* Nothing specified -> width defaults to canonical char width. */
1894 width
= CANON_X_UNIT (it
->f
);
1896 /* Compute height. */
1897 if (prop
= Fplist_get (plist
, QCheight
),
1899 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1900 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1902 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1904 height
= FONT_HEIGHT (font
);
1906 /* Compute percentage of height used for ascent. If
1907 `:ascent ASCENT' is present and valid, use that. Otherwise,
1908 derive the ascent from the font in use. */
1909 if (prop
= Fplist_get (plist
, QCascent
),
1910 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1911 ascent
= NUMVAL (prop
) / 100.0;
1913 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
1922 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1923 if (!STRINGP (object
))
1924 object
= it
->w
->buffer
;
1925 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1928 it
->pixel_width
= width
;
1929 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1930 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1933 if (face
->box
!= FACE_NO_BOX
)
1935 if (face
->box_line_width
> 0)
1937 it
->ascent
+= face
->box_line_width
;
1938 it
->descent
+= face
->box_line_width
;
1941 if (it
->start_of_box_run_p
)
1942 it
->pixel_width
+= abs (face
->box_line_width
);
1943 if (it
->end_of_box_run_p
)
1944 it
->pixel_width
+= abs (face
->box_line_width
);
1947 take_vertical_position_into_account (it
);
1950 /* Return proper value to be used as baseline offset of font that has
1951 ASCENT and DESCENT to draw characters by the font at the vertical
1952 center of the line of frame F.
1954 Here, out task is to find the value of BOFF in the following figure;
1956 -------------------------+-----------+-
1957 -+-+---------+-+ | |
1959 | | | | F_ASCENT F_HEIGHT
1962 | | |-|-+------+-----------|------- baseline
1964 | |---------|-+-+ | |
1966 -+-+---------+-+ F_DESCENT |
1967 -------------------------+-----------+-
1969 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1970 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1971 DESCENT = FONT->descent
1972 HEIGHT = FONT_HEIGHT (FONT)
1973 F_DESCENT = (F->output_data.x->font->descent
1974 - F->output_data.x->baseline_offset)
1975 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1978 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1979 (FONT_DESCENT (FONT) \
1980 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1981 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1982 - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
1984 /* Produce glyphs/get display metrics for the display element IT is
1985 loaded with. See the description of struct display_iterator in
1986 dispextern.h for an overview of struct display_iterator. */
1989 x_produce_glyphs (it
)
1992 it
->glyph_not_available_p
= 0;
1994 if (it
->what
== IT_CHARACTER
)
1998 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2000 int font_not_found_p
;
2001 struct font_info
*font_info
;
2002 int boff
; /* baseline offset */
2003 /* We may change it->multibyte_p upon unibyte<->multibyte
2004 conversion. So, save the current value now and restore it
2007 Note: It seems that we don't have to record multibyte_p in
2008 struct glyph because the character code itself tells if or
2009 not the character is multibyte. Thus, in the future, we must
2010 consider eliminating the field `multibyte_p' in the struct
2013 int saved_multibyte_p
= it
->multibyte_p
;
2015 /* Maybe translate single-byte characters to multibyte, or the
2017 it
->char_to_display
= it
->c
;
2018 if (!ASCII_BYTE_P (it
->c
))
2020 if (unibyte_display_via_language_environment
2021 && SINGLE_BYTE_CHAR_P (it
->c
)
2023 || !NILP (Vnonascii_translation_table
)))
2025 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2026 it
->multibyte_p
= 1;
2027 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2028 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2030 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
2031 && !it
->multibyte_p
)
2033 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
2034 it
->multibyte_p
= 0;
2035 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2036 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2040 /* Get font to use. Encode IT->char_to_display. */
2041 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2042 it
->face_id
, &char2b
,
2046 /* When no suitable font found, use the default font. */
2047 font_not_found_p
= font
== NULL
;
2048 if (font_not_found_p
)
2050 font
= FRAME_FONT (it
->f
);
2051 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2056 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2057 boff
= font_info
->baseline_offset
;
2058 if (font_info
->vertical_centering
)
2059 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2062 if (it
->char_to_display
>= ' '
2063 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
2065 /* Either unibyte or ASCII. */
2070 pcm
= w32_per_char_metric (font
, &char2b
,
2071 font
->bdf
? BDF_1D_FONT
: ANSI_FONT
);
2072 it
->ascent
= FONT_BASE (font
) + boff
;
2073 it
->descent
= FONT_DESCENT (font
) - boff
;
2077 it
->phys_ascent
= pcm
->ascent
+ boff
;
2078 it
->phys_descent
= pcm
->descent
- boff
;
2079 it
->pixel_width
= pcm
->width
;
2083 it
->glyph_not_available_p
= 1;
2084 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2085 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2086 it
->pixel_width
= FONT_WIDTH (font
);
2089 /* If this is a space inside a region of text with
2090 `space-width' property, change its width. */
2091 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
2093 it
->pixel_width
*= XFLOATINT (it
->space_width
);
2095 /* If face has a box, add the box thickness to the character
2096 height. If character has a box line to the left and/or
2097 right, add the box line width to the character's width. */
2098 if (face
->box
!= FACE_NO_BOX
)
2100 int thick
= face
->box_line_width
;
2104 it
->ascent
+= thick
;
2105 it
->descent
+= thick
;
2110 if (it
->start_of_box_run_p
)
2111 it
->pixel_width
+= thick
;
2112 if (it
->end_of_box_run_p
)
2113 it
->pixel_width
+= thick
;
2116 /* If face has an overline, add the height of the overline
2117 (1 pixel) and a 1 pixel margin to the character height. */
2118 if (face
->overline_p
)
2121 take_vertical_position_into_account (it
);
2123 /* If we have to actually produce glyphs, do it. */
2128 /* Translate a space with a `space-width' property
2129 into a stretch glyph. */
2130 double ascent
= (double) FONT_BASE (font
)
2131 / FONT_HEIGHT (font
);
2132 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2133 it
->ascent
+ it
->descent
, ascent
);
2136 x_append_glyph (it
);
2138 /* If characters with lbearing or rbearing are displayed
2139 in this line, record that fact in a flag of the
2140 glyph row. This is used to optimize X output code. */
2141 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
2142 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2145 else if (it
->char_to_display
== '\n')
2147 /* A newline has no width but we need the height of the line. */
2148 it
->pixel_width
= 0;
2150 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2151 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2153 if (face
->box
!= FACE_NO_BOX
2154 && face
->box_line_width
> 0)
2156 it
->ascent
+= face
->box_line_width
;
2157 it
->descent
+= face
->box_line_width
;
2160 else if (it
->char_to_display
== '\t')
2162 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
2163 int x
= it
->current_x
+ it
->continuation_lines_width
;
2164 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
2166 /* If the distance from the current position to the next tab
2167 stop is less than a canonical character width, use the
2168 tab stop after that. */
2169 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
2170 next_tab_x
+= tab_width
;
2172 it
->pixel_width
= next_tab_x
- x
;
2174 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2175 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2179 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2180 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2181 it
->ascent
+ it
->descent
, ascent
);
2186 /* A multi-byte character.
2187 If we found a font, this font should give us the right
2188 metrics. If we didn't find a font, use the frame's
2189 default font and calculate the width of the character
2190 from the charset width; this is what old redisplay code
2192 enum w32_char_font_type type
;
2194 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2199 type
= UNICODE_FONT
;
2201 pcm
= w32_per_char_metric (font
, &char2b
, type
);
2203 if (font_not_found_p
|| !pcm
)
2205 int charset
= CHAR_CHARSET (it
->char_to_display
);
2207 it
->glyph_not_available_p
= 1;
2208 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2209 * CHARSET_WIDTH (charset
));
2210 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2211 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2215 it
->pixel_width
= pcm
->width
;
2216 it
->phys_ascent
= pcm
->ascent
+ boff
;
2217 it
->phys_descent
= pcm
->descent
- boff
;
2219 && (pcm
->lbearing
< 0
2220 || pcm
->rbearing
> pcm
->width
))
2221 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2224 it
->ascent
= FONT_BASE (font
) + boff
;
2225 it
->descent
= FONT_DESCENT (font
) - boff
;
2226 if (face
->box
!= FACE_NO_BOX
)
2228 int thick
= face
->box_line_width
;
2232 it
->ascent
+= thick
;
2233 it
->descent
+= thick
;
2238 if (it
->start_of_box_run_p
)
2239 it
->pixel_width
+= thick
;
2240 if (it
->end_of_box_run_p
)
2241 it
->pixel_width
+= thick
;
2244 /* If face has an overline, add the height of the overline
2245 (1 pixel) and a 1 pixel margin to the character height. */
2246 if (face
->overline_p
)
2249 take_vertical_position_into_account (it
);
2252 x_append_glyph (it
);
2254 it
->multibyte_p
= saved_multibyte_p
;
2256 else if (it
->what
== IT_COMPOSITION
)
2258 /* Note: A composition is represented as one glyph in the
2259 glyph matrix. There are no padding glyphs. */
2262 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2264 int font_not_found_p
;
2265 struct font_info
*font_info
;
2266 int boff
; /* baseline offset */
2267 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2269 /* Maybe translate single-byte characters to multibyte. */
2270 it
->char_to_display
= it
->c
;
2271 if (unibyte_display_via_language_environment
2272 && SINGLE_BYTE_CHAR_P (it
->c
)
2275 && !NILP (Vnonascii_translation_table
))))
2277 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2280 /* Get face and font to use. Encode IT->char_to_display. */
2281 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2282 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2283 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2284 it
->face_id
, &char2b
, it
->multibyte_p
);
2287 /* When no suitable font found, use the default font. */
2288 font_not_found_p
= font
== NULL
;
2289 if (font_not_found_p
)
2291 font
= FRAME_FONT (it
->f
);
2292 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2297 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2298 boff
= font_info
->baseline_offset
;
2299 if (font_info
->vertical_centering
)
2300 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2303 /* There are no padding glyphs, so there is only one glyph to
2304 produce for the composition. Important is that pixel_width,
2305 ascent and descent are the values of what is drawn by
2306 draw_glyphs (i.e. the values of the overall glyphs composed). */
2309 /* If we have not yet calculated pixel size data of glyphs of
2310 the composition for the current face font, calculate them
2311 now. Theoretically, we have to check all fonts for the
2312 glyphs, but that requires much time and memory space. So,
2313 here we check only the font of the first glyph. This leads
2314 to incorrect display very rarely, and C-l (recenter) can
2315 correct the display anyway. */
2316 if (cmp
->font
!= (void *) font
)
2318 /* Ascent and descent of the font of the first character of
2319 this composition (adjusted by baseline offset). Ascent
2320 and descent of overall glyphs should not be less than
2321 them respectively. */
2322 int font_ascent
= FONT_BASE (font
) + boff
;
2323 int font_descent
= FONT_DESCENT (font
) - boff
;
2324 /* Bounding box of the overall glyphs. */
2325 int leftmost
, rightmost
, lowest
, highest
;
2326 int i
, width
, ascent
, descent
;
2327 enum w32_char_font_type font_type
;
2329 cmp
->font
= (void *) font
;
2331 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2332 font_type
= BDF_1D_FONT
;
2334 font_type
= BDF_2D_FONT
;
2336 font_type
= UNICODE_FONT
;
2338 /* Initialize the bounding box. */
2340 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2343 ascent
= pcm
->ascent
;
2344 descent
= pcm
->descent
;
2348 width
= FONT_WIDTH (font
);
2349 ascent
= FONT_BASE (font
);
2350 descent
= FONT_DESCENT (font
);
2354 lowest
= - descent
+ boff
;
2355 highest
= ascent
+ boff
;
2359 && font_info
->default_ascent
2360 && CHAR_TABLE_P (Vuse_default_ascent
)
2361 && !NILP (Faref (Vuse_default_ascent
,
2362 make_number (it
->char_to_display
))))
2363 highest
= font_info
->default_ascent
+ boff
;
2365 /* Draw the first glyph at the normal position. It may be
2366 shifted to right later if some other glyphs are drawn at
2368 cmp
->offsets
[0] = 0;
2369 cmp
->offsets
[1] = boff
;
2371 /* Set cmp->offsets for the remaining glyphs. */
2372 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2374 int left
, right
, btm
, top
;
2375 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2376 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2378 face
= FACE_FROM_ID (it
->f
, face_id
);
2379 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2384 font
= FRAME_FONT (it
->f
);
2385 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2391 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2392 boff
= font_info
->baseline_offset
;
2393 if (font_info
->vertical_centering
)
2394 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2397 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (ch
)) == 1)
2398 font_type
= BDF_1D_FONT
;
2400 font_type
= BDF_2D_FONT
;
2402 font_type
= UNICODE_FONT
;
2405 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2408 ascent
= pcm
->ascent
;
2409 descent
= pcm
->descent
;
2413 width
= FONT_WIDTH (font
);
2418 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2420 /* Relative composition with or without
2422 left
= (leftmost
+ rightmost
- width
) / 2;
2423 btm
= - descent
+ boff
;
2424 if (font_info
&& font_info
->relative_compose
2425 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2426 || NILP (Faref (Vignore_relative_composition
,
2427 make_number (ch
)))))
2430 if (- descent
>= font_info
->relative_compose
)
2431 /* One extra pixel between two glyphs. */
2433 else if (ascent
<= 0)
2434 /* One extra pixel between two glyphs. */
2435 btm
= lowest
- 1 - ascent
- descent
;
2440 /* A composition rule is specified by an integer
2441 value that encodes global and new reference
2442 points (GREF and NREF). GREF and NREF are
2443 specified by numbers as below:
2451 ---3---4---5--- baseline
2453 6---7---8 -- descent
2455 int rule
= COMPOSITION_RULE (cmp
, i
);
2456 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2458 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2459 grefx
= gref
% 3, nrefx
= nref
% 3;
2460 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2463 + grefx
* (rightmost
- leftmost
) / 2
2464 - nrefx
* width
/ 2);
2465 btm
= ((grefy
== 0 ? highest
2467 : grefy
== 2 ? lowest
2468 : (highest
+ lowest
) / 2)
2469 - (nrefy
== 0 ? ascent
+ descent
2470 : nrefy
== 1 ? descent
- boff
2472 : (ascent
+ descent
) / 2));
2475 cmp
->offsets
[i
* 2] = left
;
2476 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2478 /* Update the bounding box of the overall glyphs. */
2479 right
= left
+ width
;
2480 top
= btm
+ descent
+ ascent
;
2481 if (left
< leftmost
)
2483 if (right
> rightmost
)
2491 /* If there are glyphs whose x-offsets are negative,
2492 shift all glyphs to the right and make all x-offsets
2496 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2497 cmp
->offsets
[i
* 2] -= leftmost
;
2498 rightmost
-= leftmost
;
2501 cmp
->pixel_width
= rightmost
;
2502 cmp
->ascent
= highest
;
2503 cmp
->descent
= - lowest
;
2504 if (cmp
->ascent
< font_ascent
)
2505 cmp
->ascent
= font_ascent
;
2506 if (cmp
->descent
< font_descent
)
2507 cmp
->descent
= font_descent
;
2510 it
->pixel_width
= cmp
->pixel_width
;
2511 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2512 it
->descent
= it
->phys_descent
= cmp
->descent
;
2514 if (face
->box
!= FACE_NO_BOX
)
2516 int thick
= face
->box_line_width
;
2520 it
->ascent
+= thick
;
2521 it
->descent
+= thick
;
2526 if (it
->start_of_box_run_p
)
2527 it
->pixel_width
+= thick
;
2528 if (it
->end_of_box_run_p
)
2529 it
->pixel_width
+= thick
;
2532 /* If face has an overline, add the height of the overline
2533 (1 pixel) and a 1 pixel margin to the character height. */
2534 if (face
->overline_p
)
2537 take_vertical_position_into_account (it
);
2540 x_append_composite_glyph (it
);
2542 else if (it
->what
== IT_IMAGE
)
2543 x_produce_image_glyph (it
);
2544 else if (it
->what
== IT_STRETCH
)
2545 x_produce_stretch_glyph (it
);
2547 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2548 because this isn't true for images with `:ascent 100'. */
2549 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2550 if (it
->area
== TEXT_AREA
)
2551 it
->current_x
+= it
->pixel_width
;
2553 it
->descent
+= it
->extra_line_spacing
;
2555 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2556 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2557 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2558 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2562 /* Estimate the pixel height of the mode or top line on frame F.
2563 FACE_ID specifies what line's height to estimate. */
2566 x_estimate_mode_line_height (f
, face_id
)
2568 enum face_id face_id
;
2570 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2572 /* This function is called so early when Emacs starts that the face
2573 cache and mode line face are not yet initialized. */
2574 if (FRAME_FACE_CACHE (f
))
2576 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2580 height
= FONT_HEIGHT (face
->font
);
2581 if (face
->box_line_width
> 0)
2582 height
+= 2 * face
->box_line_width
;
2590 /***********************************************************************
2592 ***********************************************************************/
2594 /* A sequence of glyphs to be drawn in the same face.
2596 This data structure is not really completely X specific, so it
2597 could possibly, at least partially, be useful for other systems. It
2598 is currently not part of the external redisplay interface because
2599 it's not clear what other systems will need. */
2603 /* X-origin of the string. */
2606 /* Y-origin and y-position of the base line of this string. */
2609 /* The width of the string, not including a face extension. */
2612 /* The width of the string, including a face extension. */
2613 int background_width
;
2615 /* The height of this string. This is the height of the line this
2616 string is drawn in, and can be different from the height of the
2617 font the string is drawn in. */
2620 /* Number of pixels this string overwrites in front of its x-origin.
2621 This number is zero if the string has an lbearing >= 0; it is
2622 -lbearing, if the string has an lbearing < 0. */
2625 /* Number of pixels this string overwrites past its right-most
2626 nominal x-position, i.e. x + width. Zero if the string's
2627 rbearing is <= its nominal width, rbearing - width otherwise. */
2630 /* The frame on which the glyph string is drawn. */
2633 /* The window on which the glyph string is drawn. */
2636 /* X display and window for convenience. */
2639 /* The glyph row for which this string was built. It determines the
2640 y-origin and height of the string. */
2641 struct glyph_row
*row
;
2643 /* The area within row. */
2644 enum glyph_row_area area
;
2646 /* Characters to be drawn, and number of characters. */
2650 /* A face-override for drawing cursors, mouse face and similar. */
2651 enum draw_glyphs_face hl
;
2653 /* Face in which this string is to be drawn. */
2656 /* Font in which this string is to be drawn. */
2659 /* Font info for this string. */
2660 struct font_info
*font_info
;
2662 /* Non-null means this string describes (part of) a composition.
2663 All characters from char2b are drawn composed. */
2664 struct composition
*cmp
;
2666 /* Index of this glyph string's first character in the glyph
2667 definition of CMP. If this is zero, this glyph string describes
2668 the first character of a composition. */
2671 /* 1 means this glyph strings face has to be drawn to the right end
2672 of the window's drawing area. */
2673 unsigned extends_to_end_of_line_p
: 1;
2675 /* 1 means the background of this string has been drawn. */
2676 unsigned background_filled_p
: 1;
2678 /* 1 means glyph string must be drawn with 16-bit functions. */
2679 unsigned two_byte_p
: 1;
2681 /* 1 means that the original font determined for drawing this glyph
2682 string could not be loaded. The member `font' has been set to
2683 the frame's default font in this case. */
2684 unsigned font_not_found_p
: 1;
2686 /* 1 means that the face in which this glyph string is drawn has a
2688 unsigned stippled_p
: 1;
2690 /* 1 means only the foreground of this glyph string must be drawn,
2691 and we should use the physical height of the line this glyph
2692 string appears in as clip rect. */
2693 unsigned for_overlaps_p
: 1;
2695 /* The GC to use for drawing this glyph string. */
2700 /* A pointer to the first glyph in the string. This glyph
2701 corresponds to char2b[0]. Needed to draw rectangles if
2702 font_not_found_p is 1. */
2703 struct glyph
*first_glyph
;
2705 /* Image, if any. */
2708 struct glyph_string
*next
, *prev
;
2712 /* Encapsulate the different ways of displaying text under W32. */
2714 void W32_TEXTOUT (s
, x
, y
,chars
,nchars
)
2715 struct glyph_string
* s
;
2720 int charset_dim
= w32_font_is_double_byte (s
->gc
->font
) ? 2 : 1;
2721 if (s
->gc
->font
->bdf
)
2722 w32_BDF_TextOut (s
->gc
->font
->bdf
, s
->hdc
,
2723 x
, y
, (char *) chars
, charset_dim
,
2724 nchars
* charset_dim
, 0);
2725 else if (s
->first_glyph
->w32_font_type
== UNICODE_FONT
)
2726 ExtTextOutW (s
->hdc
, x
, y
, 0, NULL
, chars
, nchars
, NULL
);
2728 ExtTextOut (s
->hdc
, x
, y
, 0, NULL
, (char *) chars
,
2729 nchars
* charset_dim
, NULL
);
2735 x_dump_glyph_string (s
)
2736 struct glyph_string
*s
;
2738 fprintf (stderr
, "glyph string\n");
2739 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2740 s
->x
, s
->y
, s
->width
, s
->height
);
2741 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2742 fprintf (stderr
, " hl = %d\n", s
->hl
);
2743 fprintf (stderr
, " left overhang = %d, right = %d\n",
2744 s
->left_overhang
, s
->right_overhang
);
2745 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2746 fprintf (stderr
, " extends to end of line = %d\n",
2747 s
->extends_to_end_of_line_p
);
2748 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2749 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2752 #endif /* GLYPH_DEBUG */
2756 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2757 struct glyph_string
**,
2758 struct glyph_string
*,
2759 struct glyph_string
*));
2760 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2761 struct glyph_string
**,
2762 struct glyph_string
*,
2763 struct glyph_string
*));
2764 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2765 struct glyph_string
**,
2766 struct glyph_string
*));
2767 static int x_left_overwritten
P_ ((struct glyph_string
*));
2768 static int x_left_overwriting
P_ ((struct glyph_string
*));
2769 static int x_right_overwritten
P_ ((struct glyph_string
*));
2770 static int x_right_overwriting
P_ ((struct glyph_string
*));
2771 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2773 static void w32_init_glyph_string
P_ ((struct glyph_string
*, HDC hdc
,
2774 wchar_t *, struct window
*,
2776 enum glyph_row_area
, int,
2777 enum draw_glyphs_face
));
2778 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2779 enum glyph_row_area
, int, int,
2780 enum draw_glyphs_face
, int *, int *, int));
2781 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2782 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2783 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2785 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2786 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2787 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2788 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2789 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2790 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2791 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2792 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2793 static void w32_get_glyph_overhangs
P_ ((HDC hdc
, struct glyph
*,
2796 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2797 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
2798 static void w32_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2799 double, int, COLORREF
));
2800 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2801 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2802 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2803 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2804 static void w32_draw_image_foreground_1
P_ ((struct glyph_string
*, HBITMAP
));
2805 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2806 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2808 static void w32_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2809 int, int, int, int, RECT
*));
2810 static void w32_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2811 int, int, int, RECT
*));
2812 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2813 enum glyph_row_area
));
2814 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2816 enum glyph_row_area
, int, int));
2819 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2823 /* Append the list of glyph strings with head H and tail T to the list
2824 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2827 x_append_glyph_string_lists (head
, tail
, h
, t
)
2828 struct glyph_string
**head
, **tail
;
2829 struct glyph_string
*h
, *t
;
2843 /* Prepend the list of glyph strings with head H and tail T to the
2844 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2848 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2849 struct glyph_string
**head
, **tail
;
2850 struct glyph_string
*h
, *t
;
2864 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2865 Set *HEAD and *TAIL to the resulting list. */
2868 x_append_glyph_string (head
, tail
, s
)
2869 struct glyph_string
**head
, **tail
;
2870 struct glyph_string
*s
;
2872 s
->next
= s
->prev
= NULL
;
2873 x_append_glyph_string_lists (head
, tail
, s
, s
);
2877 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2882 struct glyph_string
*s
;
2884 if (s
->font
== FRAME_FONT (s
->f
)
2885 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2886 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2888 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
2891 /* Cursor on non-default face: must merge. */
2895 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
2896 xgcv
.foreground
= s
->face
->background
;
2898 /* If the glyph would be invisible, try a different foreground. */
2899 if (xgcv
.foreground
== xgcv
.background
)
2900 xgcv
.foreground
= s
->face
->foreground
;
2901 if (xgcv
.foreground
== xgcv
.background
)
2902 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
2903 if (xgcv
.foreground
== xgcv
.background
)
2904 xgcv
.foreground
= s
->face
->foreground
;
2906 /* Make sure the cursor is distinct from text in this face. */
2907 if (xgcv
.background
== s
->face
->background
2908 && xgcv
.foreground
== s
->face
->foreground
)
2910 xgcv
.background
= s
->face
->foreground
;
2911 xgcv
.foreground
= s
->face
->background
;
2914 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2915 xgcv
.font
= s
->font
;
2916 mask
= GCForeground
| GCBackground
| GCFont
;
2918 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2919 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2922 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2923 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
2925 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2930 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2933 x_set_mouse_face_gc (s
)
2934 struct glyph_string
*s
;
2939 /* What face has to be used last for the mouse face? */
2940 face_id
= FRAME_W32_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2941 face
= FACE_FROM_ID (s
->f
, face_id
);
2943 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2945 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2946 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2948 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2949 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2950 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2952 /* If font in this face is same as S->font, use it. */
2953 if (s
->font
== s
->face
->font
)
2954 s
->gc
= s
->face
->gc
;
2957 /* Otherwise construct scratch_cursor_gc with values from FACE
2962 xgcv
.background
= s
->face
->background
;
2963 xgcv
.foreground
= s
->face
->foreground
;
2964 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2965 xgcv
.font
= s
->font
;
2966 mask
= GCForeground
| GCBackground
| GCFont
;
2968 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2969 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2972 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2973 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
2975 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2978 xassert (s
->gc
!= 0);
2982 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2983 Faces to use in the mode line have already been computed when the
2984 matrix was built, so there isn't much to do, here. */
2987 x_set_mode_line_face_gc (s
)
2988 struct glyph_string
*s
;
2990 s
->gc
= s
->face
->gc
;
2994 /* Set S->gc of glyph string S for drawing that glyph string. Set
2995 S->stippled_p to a non-zero value if the face of S has a stipple
2999 x_set_glyph_string_gc (s
)
3000 struct glyph_string
*s
;
3002 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
3004 if (s
->hl
== DRAW_NORMAL_TEXT
)
3006 s
->gc
= s
->face
->gc
;
3007 s
->stippled_p
= s
->face
->stipple
!= 0;
3009 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
3011 x_set_mode_line_face_gc (s
);
3012 s
->stippled_p
= s
->face
->stipple
!= 0;
3014 else if (s
->hl
== DRAW_CURSOR
)
3016 x_set_cursor_gc (s
);
3019 else if (s
->hl
== DRAW_MOUSE_FACE
)
3021 x_set_mouse_face_gc (s
);
3022 s
->stippled_p
= s
->face
->stipple
!= 0;
3024 else if (s
->hl
== DRAW_IMAGE_RAISED
3025 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3027 s
->gc
= s
->face
->gc
;
3028 s
->stippled_p
= s
->face
->stipple
!= 0;
3032 s
->gc
= s
->face
->gc
;
3033 s
->stippled_p
= s
->face
->stipple
!= 0;
3036 /* GC must have been set. */
3037 xassert (s
->gc
!= 0);
3041 /* Return in *R the clipping rectangle for glyph string S. */
3044 w32_get_glyph_string_clip_rect (s
, r
)
3045 struct glyph_string
*s
;
3048 int r_height
, r_width
;
3050 if (s
->row
->full_width_p
)
3052 /* Draw full-width. X coordinates are relative to S->w->left. */
3053 int canon_x
= CANON_X_UNIT (s
->f
);
3055 r
->left
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
3056 r_width
= XFASTINT (s
->w
->width
) * canon_x
;
3058 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
3060 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
3061 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
3065 r
->left
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
3067 /* Unless displaying a mode or menu bar line, which are always
3068 fully visible, clip to the visible part of the row. */
3069 if (s
->w
->pseudo_window_p
)
3070 r_height
= s
->row
->visible_height
;
3072 r_height
= s
->height
;
3076 /* This is a text line that may be partially visible. */
3077 r
->left
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
3078 r_width
= window_box_width (s
->w
, s
->area
);
3079 r_height
= s
->row
->visible_height
;
3082 /* Don't use S->y for clipping because it doesn't take partially
3083 visible lines into account. For example, it can be negative for
3084 partially visible lines at the top of a window. */
3085 if (!s
->row
->full_width_p
3086 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
3087 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3089 r
->top
= max (0, s
->row
->y
);
3091 /* If drawing a tool-bar window, draw it over the internal border
3092 at the top of the window. */
3093 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
3094 r
->top
-= s
->f
->output_data
.w32
->internal_border_width
;
3096 /* If S draws overlapping rows, it's sufficient to use the top and
3097 bottom of the window for clipping because this glyph string
3098 intentionally draws over other lines. */
3099 if (s
->for_overlaps_p
)
3101 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3102 r_height
= window_text_bottom_y (s
->w
) - r
->top
;
3105 r
->top
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->top
);
3107 r
->bottom
= r
->top
+ r_height
;
3108 r
->right
= r
->left
+ r_width
;
3112 /* Set clipping for output of glyph string S. S may be part of a mode
3113 line or menu if we don't have X toolkit support. */
3116 x_set_glyph_string_clipping (s
)
3117 struct glyph_string
*s
;
3120 w32_get_glyph_string_clip_rect (s
, &r
);
3121 w32_set_clip_rectangle (s
->hdc
, &r
);
3125 /* Compute left and right overhang of glyph string S. If S is a glyph
3126 string for a composition, assume overhangs don't exist. */
3129 x_compute_glyph_string_overhangs (s
)
3130 struct glyph_string
*s
;
3132 /* TODO: Windows does not appear to have a method for
3133 getting this info without getting the ABC widths for each
3134 individual character and working it out manually. */
3138 /* Compute overhangs and x-positions for glyph string S and its
3139 predecessors, or successors. X is the starting x-position for S.
3140 BACKWARD_P non-zero means process predecessors. */
3143 x_compute_overhangs_and_x (s
, x
, backward_p
)
3144 struct glyph_string
*s
;
3152 x_compute_glyph_string_overhangs (s
);
3162 x_compute_glyph_string_overhangs (s
);
3171 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
3172 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
3173 assumed to be zero. */
3176 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
)
3178 struct glyph
*glyph
;
3184 if (glyph
->type
== CHAR_GLYPH
)
3191 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
3195 && (pcm
= w32_per_char_metric (font
, &char2b
,
3196 glyph
->w32_font_type
)))
3198 if (pcm
->rbearing
> pcm
->width
)
3199 *right
= pcm
->rbearing
- pcm
->width
;
3200 if (pcm
->lbearing
< 0)
3201 *left
= -pcm
->lbearing
;
3208 x_get_glyph_overhangs (glyph
, f
, left
, right
)
3209 struct glyph
*glyph
;
3213 HDC hdc
= get_frame_dc (f
);
3214 /* Convert to unicode! */
3215 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
);
3216 release_frame_dc (f
, hdc
);
3220 /* Return the index of the first glyph preceding glyph string S that
3221 is overwritten by S because of S's left overhang. Value is -1
3222 if no glyphs are overwritten. */
3225 x_left_overwritten (s
)
3226 struct glyph_string
*s
;
3230 if (s
->left_overhang
)
3233 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3234 int first
= s
->first_glyph
- glyphs
;
3236 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3237 x
-= glyphs
[i
].pixel_width
;
3248 /* Return the index of the first glyph preceding glyph string S that
3249 is overwriting S because of its right overhang. Value is -1 if no
3250 glyph in front of S overwrites S. */
3253 x_left_overwriting (s
)
3254 struct glyph_string
*s
;
3257 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3258 int first
= s
->first_glyph
- glyphs
;
3262 for (i
= first
- 1; i
>= 0; --i
)
3265 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3268 x
-= glyphs
[i
].pixel_width
;
3275 /* Return the index of the last glyph following glyph string S that is
3276 not overwritten by S because of S's right overhang. Value is -1 if
3277 no such glyph is found. */
3280 x_right_overwritten (s
)
3281 struct glyph_string
*s
;
3285 if (s
->right_overhang
)
3288 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3289 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3290 int end
= s
->row
->used
[s
->area
];
3292 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3293 x
+= glyphs
[i
].pixel_width
;
3302 /* Return the index of the last glyph following glyph string S that
3303 overwrites S because of its left overhang. Value is negative
3304 if no such glyph is found. */
3307 x_right_overwriting (s
)
3308 struct glyph_string
*s
;
3311 int end
= s
->row
->used
[s
->area
];
3312 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3313 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3317 for (i
= first
; i
< end
; ++i
)
3320 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3323 x
+= glyphs
[i
].pixel_width
;
3330 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3333 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3334 struct glyph_string
*s
;
3342 /* Take clipping into account. */
3343 if (s
->gc
->clip_mask
== Rect
)
3345 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
3346 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
3347 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
3348 - s
->gc
->clip_rectangle
.left
);
3349 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
3350 - s
->gc
->clip_rectangle
.top
);
3353 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
3358 /* Draw the background of glyph_string S. If S->background_filled_p
3359 is non-zero don't draw it. FORCE_P non-zero means draw the
3360 background even if it wouldn't be drawn normally. This is used
3361 when a string preceding S draws into the background of S, or S
3362 contains the first component of a composition. */
3365 x_draw_glyph_string_background (s
, force_p
)
3366 struct glyph_string
*s
;
3369 /* Nothing to do if background has already been drawn or if it
3370 shouldn't be drawn in the first place. */
3371 if (!s
->background_filled_p
)
3373 int box_line_width
= max (s
->face
->box_line_width
, 0);
3375 #if 0 /* TODO: stipple */
3378 /* Fill background with a stipple pattern. */
3379 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3380 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3381 s
->y
+ box_line_width
,
3382 s
->background_width
,
3383 s
->height
- 2 * box_line_width
);
3384 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3385 s
->background_filled_p
= 1;
3389 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3390 || s
->font_not_found_p
3391 || s
->extends_to_end_of_line_p
3395 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3396 s
->background_width
,
3397 s
->height
- 2 * box_line_width
);
3398 s
->background_filled_p
= 1;
3404 /* Draw the foreground of glyph string S. */
3407 x_draw_glyph_string_foreground (s
)
3408 struct glyph_string
*s
;
3413 /* If first glyph of S has a left box line, start drawing the text
3414 of S to the right of that box line. */
3415 if (s
->face
->box
!= FACE_NO_BOX
3416 && s
->first_glyph
->left_box_line_p
)
3417 x
= s
->x
+ abs (s
->face
->box_line_width
);
3421 if (s
->for_overlaps_p
|| (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3422 SetBkMode (s
->hdc
, TRANSPARENT
);
3424 SetBkMode (s
->hdc
, OPAQUE
);
3426 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3427 SetBkColor (s
->hdc
, s
->gc
->background
);
3428 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3430 if (s
->font
&& s
->font
->hfont
)
3431 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3433 /* Draw characters of S as rectangles if S's font could not be
3435 if (s
->font_not_found_p
)
3437 for (i
= 0; i
< s
->nchars
; ++i
)
3439 struct glyph
*g
= s
->first_glyph
+ i
;
3441 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3443 x
+= g
->pixel_width
;
3448 char *char1b
= (char *) s
->char2b
;
3449 int boff
= s
->font_info
->baseline_offset
;
3451 if (s
->font_info
->vertical_centering
)
3452 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3454 /* If we can use 8-bit functions, condense S->char2b. */
3456 for (i
= 0; i
< s
->nchars
; ++i
)
3457 char1b
[i
] = BYTE2 (s
->char2b
[i
]);
3459 /* Draw text with TextOut and friends. */
3460 W32_TEXTOUT (s
, x
, s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3462 if (s
->font
&& s
->font
->hfont
)
3463 SelectObject (s
->hdc
, old_font
);
3466 /* Draw the foreground of composite glyph string S. */
3469 x_draw_composite_glyph_string_foreground (s
)
3470 struct glyph_string
*s
;
3475 /* If first glyph of S has a left box line, start drawing the text
3476 of S to the right of that box line. */
3477 if (s
->face
->box
!= FACE_NO_BOX
3478 && s
->first_glyph
->left_box_line_p
)
3479 x
= s
->x
+ abs (s
->face
->box_line_width
);
3483 /* S is a glyph string for a composition. S->gidx is the index of
3484 the first character drawn for glyphs of this composition.
3485 S->gidx == 0 means we are drawing the very first character of
3486 this composition. */
3488 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3489 SetBkColor (s
->hdc
, s
->gc
->background
);
3490 SetBkMode (s
->hdc
, TRANSPARENT
);
3491 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3493 if (s
->font
&& s
->font
->hfont
)
3494 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3496 /* Draw a rectangle for the composition if the font for the very
3497 first character of the composition could not be loaded. */
3498 if (s
->font_not_found_p
)
3501 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
3506 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3507 W32_TEXTOUT (s
, x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3508 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3511 if (s
->font
&& s
->font
->hfont
)
3512 SelectObject (s
->hdc
, old_font
);
3516 /* Brightness beyond which a color won't have its highlight brightness
3519 Nominally, highlight colors for `3d' faces are calculated by
3520 brightening an object's color by a constant scale factor, but this
3521 doesn't yield good results for dark colors, so for colors who's
3522 brightness is less than this value (on a scale of 0-255) have to
3523 use an additional additive factor.
3525 The value here is set so that the default menu-bar/mode-line color
3526 (grey75) will not have its highlights changed at all. */
3527 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
3530 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
3531 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3532 If this produces the same color as COLOR, try a color where all RGB
3533 values have DELTA added. Return the allocated color in *COLOR.
3534 DISPLAY is the X display, CMAP is the colormap to operate on.
3535 Value is non-zero if successful. */
3538 w32_alloc_lighter_color (f
, color
, factor
, delta
)
3547 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
3550 /* Change RGB values by specified FACTOR. Avoid overflow! */
3551 xassert (factor
>= 0);
3552 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
3553 min (0xff, factor
* GetGValue (*color
)),
3554 min (0xff, factor
* GetBValue (*color
)));
3556 /* Calculate brightness of COLOR. */
3557 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
3558 + GetBValue (*color
)) / 6;
3560 /* We only boost colors that are darker than
3561 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3562 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3563 /* Make an additive adjustment to NEW, because it's dark enough so
3564 that scaling by FACTOR alone isn't enough. */
3566 /* How far below the limit this color is (0 - 1, 1 being darker). */
3567 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3568 /* The additive adjustment. */
3569 int min_delta
= delta
* dimness
* factor
/ 2;
3572 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
3573 max (0, min (0xff, min_delta
- GetGValue (*color
))),
3574 max (0, min (0xff, min_delta
- GetBValue (*color
))));
3576 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
3577 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
3578 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
3582 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
3583 max (0, min (0xff, delta
+ GetGValue (*color
))),
3584 max (0, min (0xff, delta
+ GetBValue (*color
))));
3586 /* TODO: Map to palette and retry with delta if same? */
3587 /* TODO: Free colors (if using palette)? */
3598 /* Set up the foreground color for drawing relief lines of glyph
3599 string S. RELIEF is a pointer to a struct relief containing the GC
3600 with which lines will be drawn. Use a color that is FACTOR or
3601 DELTA lighter or darker than the relief's background which is found
3602 in S->f->output_data.x->relief_background. If such a color cannot
3603 be allocated, use DEFAULT_PIXEL, instead. */
3606 w32_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3608 struct relief
*relief
;
3611 COLORREF default_pixel
;
3614 struct w32_output
*di
= f
->output_data
.w32
;
3615 unsigned long mask
= GCForeground
;
3617 COLORREF background
= di
->relief_background
;
3618 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
3620 /* TODO: Free colors (if using palette)? */
3622 /* Allocate new color. */
3623 xgcv
.foreground
= default_pixel
;
3625 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
3627 relief
->allocated_p
= 1;
3628 xgcv
.foreground
= relief
->pixel
= pixel
;
3631 if (relief
->gc
== 0)
3633 #if 0 /* TODO: stipple */
3634 xgcv
.stipple
= dpyinfo
->gray
;
3637 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
3640 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
3644 /* Set up colors for the relief lines around glyph string S. */
3647 x_setup_relief_colors (s
)
3648 struct glyph_string
*s
;
3650 struct w32_output
*di
= s
->f
->output_data
.w32
;
3653 if (s
->face
->use_box_color_for_shadows_p
)
3654 color
= s
->face
->box_color
;
3656 color
= s
->gc
->background
;
3658 if (di
->white_relief
.gc
== 0
3659 || color
!= di
->relief_background
)
3661 di
->relief_background
= color
;
3662 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3663 WHITE_PIX_DEFAULT (s
->f
));
3664 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3665 BLACK_PIX_DEFAULT (s
->f
));
3670 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3671 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3672 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3673 relief. LEFT_P non-zero means draw a relief on the left side of
3674 the rectangle. RIGHT_P non-zero means draw a relief on the right
3675 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3679 w32_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3680 raised_p
, left_p
, right_p
, clip_rect
)
3682 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3687 HDC hdc
= get_frame_dc (f
);
3690 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3692 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3694 w32_set_clip_rectangle (hdc
, clip_rect
);
3697 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);
3706 for (i
= 0; i
< width
; ++i
)
3708 w32_fill_area (f
, hdc
, gc
.foreground
,
3709 left_x
+ i
, top_y
+ i
, 1,
3710 (bottom_y
- i
) - (top_y
+ i
));
3713 w32_set_clip_rectangle (hdc
, NULL
);
3716 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3718 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3721 w32_set_clip_rectangle (hdc
, clip_rect
);
3724 for (i
= 0; i
< width
; ++i
)
3726 w32_fill_area (f
, hdc
, gc
.foreground
,
3727 left_x
+ i
* left_p
, bottom_y
- i
,
3728 (right_x
+ 1 - i
* right_p
) - left_x
+ i
* left_p
, 1);
3733 for (i
= 0; i
< width
; ++i
)
3735 w32_fill_area (f
, hdc
, gc
.foreground
,
3736 right_x
- i
, top_y
+ i
+ 1, 1,
3737 (bottom_y
- i
) - (top_y
+ i
+ 1));
3740 w32_set_clip_rectangle (hdc
, NULL
);
3742 release_frame_dc (f
, hdc
);
3746 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3747 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3748 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3749 left side of the rectangle. RIGHT_P non-zero means draw a line
3750 on the right side of the rectangle. CLIP_RECT is the clipping
3751 rectangle to use when drawing. */
3754 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3755 left_p
, right_p
, clip_rect
)
3756 struct glyph_string
*s
;
3757 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3760 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
3763 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3764 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3769 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3770 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3774 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3775 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3780 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3781 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3784 w32_set_clip_rectangle (s
->hdc
, NULL
);
3788 /* Draw a box around glyph string S. */
3791 x_draw_glyph_string_box (s
)
3792 struct glyph_string
*s
;
3794 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3795 int left_p
, right_p
;
3796 struct glyph
*last_glyph
;
3799 last_x
= window_box_right (s
->w
, s
->area
);
3800 if (s
->row
->full_width_p
3801 && !s
->w
->pseudo_window_p
)
3803 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3804 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3805 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3808 /* The glyph that may have a right box line. */
3809 last_glyph
= (s
->cmp
|| s
->img
3811 : s
->first_glyph
+ s
->nchars
- 1);
3813 width
= abs (s
->face
->box_line_width
);
3814 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3816 right_x
= ((s
->row
->full_width_p
3818 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3820 bottom_y
= top_y
+ s
->height
- 1;
3822 left_p
= (s
->first_glyph
->left_box_line_p
3823 || (s
->hl
== DRAW_MOUSE_FACE
3825 || s
->prev
->hl
!= s
->hl
)));
3826 right_p
= (last_glyph
->right_box_line_p
3827 || (s
->hl
== DRAW_MOUSE_FACE
3829 || s
->next
->hl
!= s
->hl
)));
3831 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3833 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3834 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3835 left_p
, right_p
, &clip_rect
);
3838 x_setup_relief_colors (s
);
3839 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3840 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3845 /* Draw foreground of image glyph string S. */
3848 x_draw_image_foreground (s
)
3849 struct glyph_string
*s
;
3852 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3854 /* If first glyph of S has a left box line, start drawing it to the
3855 right of that line. */
3856 if (s
->face
->box
!= FACE_NO_BOX
3857 && s
->first_glyph
->left_box_line_p
)
3858 x
= s
->x
+ abs (s
->face
->box_line_width
);
3862 /* If there is a margin around the image, adjust x- and y-position
3864 x
+= s
->img
->hmargin
;
3865 y
+= s
->img
->vmargin
;
3871 #if 0 /* TODO: image mask */
3874 /* We can't set both a clip mask and use XSetClipRectangles
3875 because the latter also sets a clip mask. We also can't
3876 trust on the shape extension to be available
3877 (XShapeCombineRegion). So, compute the rectangle to draw
3879 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3882 XRectangle clip_rect
, image_rect
, r
;
3884 xgcv
.clip_mask
= s
->img
->mask
;
3885 xgcv
.clip_x_origin
= x
;
3886 xgcv
.clip_y_origin
= y
;
3887 xgcv
.function
= GXcopy
;
3888 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3890 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3893 image_rect
.width
= s
->img
->width
;
3894 image_rect
.height
= s
->img
->height
;
3895 if (IntersectRect (&r
, &clip_rect
, &image_rect
))
3896 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3897 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3902 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
3903 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
3904 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
3905 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
3906 x_set_glyph_string_clipping (s
);
3908 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3909 SetBkColor (s
->hdc
, s
->gc
->background
);
3910 #if 0 /* From w32bdf.c (which is from Meadow). */
3911 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3912 compat_hdc
, 0, 0, SRCCOPY
);
3913 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3914 compat_hdc
, 0, 0, 0xB8074A);
3916 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3917 compat_hdc
, 0, 0, 0xE20746);
3919 SelectObject (s
->hdc
, orig_brush
);
3920 DeleteObject (fg_brush
);
3921 SelectObject (compat_hdc
, orig_obj
);
3922 DeleteDC (compat_hdc
);
3924 /* When the image has a mask, we can expect that at
3925 least part of a mouse highlight or a block cursor will
3926 be visible. If the image doesn't have a mask, make
3927 a block cursor visible by drawing a rectangle around
3928 the image. I believe it's looking better if we do
3929 nothing here for mouse-face. */
3930 if (s
->hl
== DRAW_CURSOR
)
3931 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
3932 s
->img
->height
- 1);
3933 w32_set_clip_rectangle (s
->hdc
, NULL
);
3937 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
-1,
3938 s
->img
->height
- 1);
3940 RestoreDC (s
->hdc
,-1);
3945 /* Draw a relief around the image glyph string S. */
3948 x_draw_image_relief (s
)
3949 struct glyph_string
*s
;
3951 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3954 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3956 /* If first glyph of S has a left box line, start drawing it to the
3957 right of that line. */
3958 if (s
->face
->box
!= FACE_NO_BOX
3959 && s
->first_glyph
->left_box_line_p
)
3960 x
= s
->x
+ abs (s
->face
->box_line_width
);
3964 /* If there is a margin around the image, adjust x- and y-position
3966 x
+= s
->img
->hmargin
;
3967 y
+= s
->img
->vmargin
;
3969 if (s
->hl
== DRAW_IMAGE_SUNKEN
3970 || s
->hl
== DRAW_IMAGE_RAISED
)
3972 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3973 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3977 thick
= abs (s
->img
->relief
);
3978 raised_p
= s
->img
->relief
> 0;
3983 x1
= x
+ s
->img
->width
+ thick
- 1;
3984 y1
= y
+ s
->img
->height
+ thick
- 1;
3986 x_setup_relief_colors (s
);
3987 w32_get_glyph_string_clip_rect (s
, &r
);
3988 w32_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3992 /* Draw the foreground of image glyph string S to PIXMAP. */
3995 w32_draw_image_foreground_1 (s
, pixmap
)
3996 struct glyph_string
*s
;
3999 HDC hdc
= CreateCompatibleDC (s
->hdc
);
4000 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
4002 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4004 /* If first glyph of S has a left box line, start drawing it to the
4005 right of that line. */
4006 if (s
->face
->box
!= FACE_NO_BOX
4007 && s
->first_glyph
->left_box_line_p
)
4008 x
= abs (s
->face
->box_line_width
);
4012 /* If there is a margin around the image, adjust x- and y-position
4014 x
+= s
->img
->hmargin
;
4015 y
+= s
->img
->vmargin
;
4019 #if 0 /* TODO: image mask */
4022 /* We can't set both a clip mask and use XSetClipRectangles
4023 because the latter also sets a clip mask. We also can't
4024 trust on the shape extension to be available
4025 (XShapeCombineRegion). So, compute the rectangle to draw
4027 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4031 xgcv
.clip_mask
= s
->img
->mask
;
4032 xgcv
.clip_x_origin
= x
;
4033 xgcv
.clip_y_origin
= y
;
4034 xgcv
.function
= GXcopy
;
4035 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4037 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4038 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4039 XSetClipMask (s
->display
, s
->gc
, None
);
4044 HDC compat_hdc
= CreateCompatibleDC (hdc
);
4045 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4046 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
4047 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
4049 SetTextColor (hdc
, s
->gc
->foreground
);
4050 SetBkColor (hdc
, s
->gc
->background
);
4051 #if 0 /* From w32bdf.c (which is from Meadow). */
4052 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4053 compat_hdc
, 0, 0, SRCCOPY
);
4054 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4055 compat_hdc
, 0, 0, 0xB8074A);
4057 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4058 compat_hdc
, 0, 0, 0xE20746);
4060 SelectObject (hdc
, orig_brush
);
4061 DeleteObject (fg_brush
);
4062 SelectObject (compat_hdc
, orig_obj
);
4063 DeleteDC (compat_hdc
);
4065 /* When the image has a mask, we can expect that at
4066 least part of a mouse highlight or a block cursor will
4067 be visible. If the image doesn't have a mask, make
4068 a block cursor visible by drawing a rectangle around
4069 the image. I believe it's looking better if we do
4070 nothing here for mouse-face. */
4071 if (s
->hl
== DRAW_CURSOR
)
4072 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4073 s
->img
->height
- 1);
4077 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4078 s
->img
->height
- 1);
4080 SelectObject (hdc
, orig_hdc_obj
);
4085 /* Draw part of the background of glyph string S. X, Y, W, and H
4086 give the rectangle to draw. */
4089 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4090 struct glyph_string
*s
;
4093 #if 0 /* TODO: stipple */
4096 /* Fill background with a stipple pattern. */
4097 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4098 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4099 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4103 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4107 /* Draw image glyph string S.
4110 s->x +-------------------------
4113 | +-------------------------
4116 | | +-------------------
4122 x_draw_image_glyph_string (s
)
4123 struct glyph_string
*s
;
4126 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4127 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4131 height
= s
->height
- 2 * box_line_vwidth
;
4133 /* Fill background with face under the image. Do it only if row is
4134 taller than image or if image has a clip mask to reduce
4136 s
->stippled_p
= s
->face
->stipple
!= 0;
4137 if (height
> s
->img
->height
4140 #if 0 /* TODO: image mask */
4143 || s
->img
->pixmap
== 0
4144 || s
->width
!= s
->background_width
)
4146 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4147 x
= s
->x
+ box_line_hwidth
;
4151 y
= s
->y
+ box_line_vwidth
;
4152 #if 0 /* TODO: image mask */
4155 /* Create a pixmap as large as the glyph string. Fill it
4156 with the background color. Copy the image to it, using
4157 its mask. Copy the temporary pixmap to the display. */
4158 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4159 int depth
= DefaultDepthOfScreen (screen
);
4161 /* Create a pixmap as large as the glyph string. */
4162 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4163 s
->background_width
,
4166 /* Don't clip in the following because we're working on the
4168 XSetClipMask (s
->display
, s
->gc
, None
);
4170 /* Fill the pixmap with the background color/stipple. */
4173 /* Fill background with a stipple pattern. */
4174 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4175 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4176 0, 0, s
->background_width
, s
->height
);
4177 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4182 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4184 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4185 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4186 0, 0, s
->background_width
, s
->height
);
4187 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4192 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4194 s
->background_filled_p
= 1;
4197 /* Draw the foreground. */
4200 w32_draw_image_foreground_1 (s
, pixmap
);
4201 x_set_glyph_string_clipping (s
);
4203 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
4204 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4205 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
4206 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
4208 SetTextColor (s
->hdc
, s
->gc
->foreground
);
4209 SetBkColor (s
->hdc
, s
->gc
->background
);
4210 #if 0 /* From w32bdf.c (which is from Meadow). */
4211 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4212 compat_hdc
, 0, 0, SRCCOPY
);
4213 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4214 compat_hdc
, 0, 0, 0xB8074A);
4216 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4217 compat_hdc
, 0, 0, 0xE20746);
4219 SelectObject (s
->hdc
, orig_brush
);
4220 DeleteObject (fg_brush
);
4221 SelectObject (compat_hdc
, orig_obj
);
4222 DeleteDC (compat_hdc
);
4224 DeleteObject (pixmap
);
4228 x_draw_image_foreground (s
);
4230 /* If we must draw a relief around the image, do it. */
4232 || s
->hl
== DRAW_IMAGE_RAISED
4233 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4234 x_draw_image_relief (s
);
4238 /* Draw stretch glyph string S. */
4241 x_draw_stretch_glyph_string (s
)
4242 struct glyph_string
*s
;
4244 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4245 s
->stippled_p
= s
->face
->stipple
!= 0;
4247 if (s
->hl
== DRAW_CURSOR
4248 && !x_stretch_cursor_p
)
4250 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4251 as wide as the stretch glyph. */
4252 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4255 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4257 /* Clear rest using the GC of the original non-cursor face. */
4258 if (width
< s
->background_width
)
4260 XGCValues
*gc
= s
->face
->gc
;
4261 int x
= s
->x
+ width
, y
= s
->y
;
4262 int w
= s
->background_width
- width
, h
= s
->height
;
4265 w32_get_glyph_string_clip_rect (s
, &r
);
4266 w32_set_clip_rectangle (hdc
, &r
);
4268 #if 0 /* TODO: stipple */
4269 if (s
->face
->stipple
)
4271 /* Fill background with a stipple pattern. */
4272 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4273 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4274 XSetFillStyle (s
->display
, gc
, FillSolid
);
4279 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
4284 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4287 s
->background_filled_p
= 1;
4291 /* Draw glyph string S. */
4294 x_draw_glyph_string (s
)
4295 struct glyph_string
*s
;
4297 int relief_drawn_p
= 0;
4299 /* If S draws into the background of its successor, draw the
4300 background of the successor first so that S can draw into it.
4301 This makes S->next use XDrawString instead of XDrawImageString. */
4302 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4304 xassert (s
->next
->img
== NULL
);
4305 x_set_glyph_string_gc (s
->next
);
4306 x_set_glyph_string_clipping (s
->next
);
4307 x_draw_glyph_string_background (s
->next
, 1);
4310 /* Set up S->gc, set clipping and draw S. */
4311 x_set_glyph_string_gc (s
);
4312 x_set_glyph_string_clipping (s
);
4314 /* Draw relief (if any) in advance for char/composition so that the
4315 glyph string can be drawn over it. */
4316 if (!s
->for_overlaps_p
4317 && s
->face
->box
!= FACE_NO_BOX
4318 && (s
->first_glyph
->type
== CHAR_GLYPH
4319 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4322 x_draw_glyph_string_background (s
, 1);
4323 x_draw_glyph_string_box (s
);
4327 switch (s
->first_glyph
->type
)
4330 x_draw_image_glyph_string (s
);
4334 x_draw_stretch_glyph_string (s
);
4338 if (s
->for_overlaps_p
)
4339 s
->background_filled_p
= 1;
4341 x_draw_glyph_string_background (s
, 0);
4342 x_draw_glyph_string_foreground (s
);
4345 case COMPOSITE_GLYPH
:
4346 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4347 s
->background_filled_p
= 1;
4349 x_draw_glyph_string_background (s
, 1);
4350 x_draw_composite_glyph_string_foreground (s
);
4357 if (!s
->for_overlaps_p
)
4359 /* Draw underline. */
4360 if (s
->face
->underline_p
4361 && (s
->font
->bdf
|| !s
->font
->tm
.tmUnderlined
))
4363 unsigned long h
= 1;
4364 unsigned long dy
= s
->height
- h
;
4366 if (s
->face
->underline_defaulted_p
)
4368 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4369 s
->y
+ dy
, s
->width
, 1);
4373 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4374 s
->y
+ dy
, s
->width
, 1);
4378 /* Draw overline. */
4379 if (s
->face
->overline_p
)
4381 unsigned long dy
= 0, h
= 1;
4383 if (s
->face
->overline_color_defaulted_p
)
4385 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4386 s
->y
+ dy
, s
->width
, h
);
4390 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4391 s
->y
+ dy
, s
->width
, h
);
4395 /* Draw strike-through. */
4396 if (s
->face
->strike_through_p
4397 && (s
->font
->bdf
|| !s
->font
->tm
.tmStruckOut
))
4399 unsigned long h
= 1;
4400 unsigned long dy
= (s
->height
- h
) / 2;
4402 if (s
->face
->strike_through_color_defaulted_p
)
4404 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
4409 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4410 s
->y
+ dy
, s
->width
, h
);
4415 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4416 x_draw_glyph_string_box (s
);
4419 /* Reset clipping. */
4420 w32_set_clip_rectangle (s
->hdc
, NULL
);
4424 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4425 struct face
**, int));
4428 /* Fill glyph string S with composition components specified by S->cmp.
4430 FACES is an array of faces for all components of this composition.
4431 S->gidx is the index of the first component for S.
4432 OVERLAPS_P non-zero means S should draw the foreground only, and
4433 use its physical height for clipping.
4435 Value is the index of a component not in S. */
4438 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4439 struct glyph_string
*s
;
4440 struct face
**faces
;
4447 s
->for_overlaps_p
= overlaps_p
;
4449 s
->face
= faces
[s
->gidx
];
4450 s
->font
= s
->face
->font
;
4451 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4453 /* For all glyphs of this composition, starting at the offset
4454 S->gidx, until we reach the end of the definition or encounter a
4455 glyph that requires the different face, add it to S. */
4457 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4460 /* All glyph strings for the same composition has the same width,
4461 i.e. the width set for the first component of the composition. */
4463 s
->width
= s
->first_glyph
->pixel_width
;
4465 /* If the specified font could not be loaded, use the frame's
4466 default font, but record the fact that we couldn't load it in
4467 the glyph string so that we can draw rectangles for the
4468 characters of the glyph string. */
4469 if (s
->font
== NULL
)
4471 s
->font_not_found_p
= 1;
4472 s
->font
= FRAME_FONT (s
->f
);
4475 /* Adjust base line for subscript/superscript text. */
4476 s
->ybase
+= s
->first_glyph
->voffset
;
4478 xassert (s
->face
&& s
->face
->gc
);
4480 /* This glyph string must always be drawn with 16-bit functions. */
4483 return s
->gidx
+ s
->nchars
;
4487 /* Fill glyph string S from a sequence of character glyphs.
4489 FACE_ID is the face id of the string. START is the index of the
4490 first glyph to consider, END is the index of the last + 1.
4491 OVERLAPS_P non-zero means S should draw the foreground only, and
4492 use its physical height for clipping.
4494 Value is the index of the first glyph not in S. */
4497 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4498 struct glyph_string
*s
;
4500 int start
, end
, overlaps_p
;
4502 struct glyph
*glyph
, *last
;
4504 int glyph_not_available_p
;
4506 xassert (s
->f
== XFRAME (s
->w
->frame
));
4507 xassert (s
->nchars
== 0);
4508 xassert (start
>= 0 && end
> start
);
4510 s
->for_overlaps_p
= overlaps_p
;
4511 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4512 last
= s
->row
->glyphs
[s
->area
] + end
;
4513 voffset
= glyph
->voffset
;
4515 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4518 && glyph
->type
== CHAR_GLYPH
4519 && glyph
->voffset
== voffset
4520 /* Same face id implies same font, nowadays. */
4521 && glyph
->face_id
== face_id
4522 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4526 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4527 s
->char2b
+ s
->nchars
,
4529 s
->two_byte_p
= two_byte_p
;
4531 xassert (s
->nchars
<= end
- start
);
4532 s
->width
+= glyph
->pixel_width
;
4536 s
->font
= s
->face
->font
;
4537 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4539 /* If the specified font could not be loaded, use the frame's font,
4540 but record the fact that we couldn't load it in
4541 S->font_not_found_p so that we can draw rectangles for the
4542 characters of the glyph string. */
4543 if (s
->font
== NULL
|| glyph_not_available_p
)
4545 s
->font_not_found_p
= 1;
4546 s
->font
= FRAME_FONT (s
->f
);
4549 /* Adjust base line for subscript/superscript text. */
4550 s
->ybase
+= voffset
;
4552 xassert (s
->face
&& s
->face
->gc
);
4553 return glyph
- s
->row
->glyphs
[s
->area
];
4557 /* Fill glyph string S from image glyph S->first_glyph. */
4560 x_fill_image_glyph_string (s
)
4561 struct glyph_string
*s
;
4563 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4564 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4566 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4567 s
->font
= s
->face
->font
;
4568 s
->width
= s
->first_glyph
->pixel_width
;
4570 /* Adjust base line for subscript/superscript text. */
4571 s
->ybase
+= s
->first_glyph
->voffset
;
4575 /* Fill glyph string S from a sequence of stretch glyphs.
4577 ROW is the glyph row in which the glyphs are found, AREA is the
4578 area within the row. START is the index of the first glyph to
4579 consider, END is the index of the last + 1.
4581 Value is the index of the first glyph not in S. */
4584 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4585 struct glyph_string
*s
;
4586 struct glyph_row
*row
;
4587 enum glyph_row_area area
;
4590 struct glyph
*glyph
, *last
;
4591 int voffset
, face_id
;
4593 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4595 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4596 last
= s
->row
->glyphs
[s
->area
] + end
;
4597 face_id
= glyph
->face_id
;
4598 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4599 s
->font
= s
->face
->font
;
4600 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4601 s
->width
= glyph
->pixel_width
;
4602 voffset
= glyph
->voffset
;
4606 && glyph
->type
== STRETCH_GLYPH
4607 && glyph
->voffset
== voffset
4608 && glyph
->face_id
== face_id
);
4610 s
->width
+= glyph
->pixel_width
;
4612 /* Adjust base line for subscript/superscript text. */
4613 s
->ybase
+= voffset
;
4615 xassert (s
->face
&& s
->face
->gc
);
4616 return glyph
- s
->row
->glyphs
[s
->area
];
4620 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4621 of XChar2b structures for S; it can't be allocated in
4622 x_init_glyph_string because it must be allocated via `alloca'. W
4623 is the window on which S is drawn. ROW and AREA are the glyph row
4624 and area within the row from which S is constructed. START is the
4625 index of the first glyph structure covered by S. HL is a
4626 face-override for drawing S. */
4629 w32_init_glyph_string (s
, hdc
, char2b
, w
, row
, area
, start
, hl
)
4630 struct glyph_string
*s
;
4634 struct glyph_row
*row
;
4635 enum glyph_row_area area
;
4637 enum draw_glyphs_face hl
;
4639 bzero (s
, sizeof *s
);
4641 s
->f
= XFRAME (w
->frame
);
4643 s
->window
= FRAME_W32_WINDOW (s
->f
);
4648 s
->first_glyph
= row
->glyphs
[area
] + start
;
4649 s
->height
= row
->height
;
4650 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4652 /* Display the internal border below the tool-bar window. */
4653 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4654 s
->y
-= s
->f
->output_data
.w32
->internal_border_width
;
4656 s
->ybase
= s
->y
+ row
->ascent
;
4660 /* Set background width of glyph string S. START is the index of the
4661 first glyph following S. LAST_X is the right-most x-position + 1
4662 in the drawing area. */
4665 x_set_glyph_string_background_width (s
, start
, last_x
)
4666 struct glyph_string
*s
;
4670 /* If the face of this glyph string has to be drawn to the end of
4671 the drawing area, set S->extends_to_end_of_line_p. */
4672 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4674 if (start
== s
->row
->used
[s
->area
]
4675 && s
->area
== TEXT_AREA
4676 && ((s
->hl
== DRAW_NORMAL_TEXT
4677 && (s
->row
->fill_line_p
4678 || s
->face
->background
!= default_face
->background
4679 || s
->face
->stipple
!= default_face
->stipple
4680 || s
->row
->mouse_face_p
))
4681 || s
->hl
== DRAW_MOUSE_FACE
))
4682 s
->extends_to_end_of_line_p
= 1;
4684 /* If S extends its face to the end of the line, set its
4685 background_width to the distance to the right edge of the drawing
4687 if (s
->extends_to_end_of_line_p
)
4688 s
->background_width
= last_x
- s
->x
+ 1;
4690 s
->background_width
= s
->width
;
4694 /* Add a glyph string for a stretch glyph to the list of strings
4695 between HEAD and TAIL. START is the index of the stretch glyph in
4696 row area AREA of glyph row ROW. END is the index of the last glyph
4697 in that glyph row area. X is the current output position assigned
4698 to the new glyph string constructed. HL overrides that face of the
4699 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4700 is the right-most x-position of the drawing area. */
4702 #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4705 s = (struct glyph_string *) alloca (sizeof *s); \
4706 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4707 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4708 x_append_glyph_string (&HEAD, &TAIL, s); \
4714 /* Add a glyph string for an image glyph to the list of strings
4715 between HEAD and TAIL. START is the index of the image glyph in
4716 row area AREA of glyph row ROW. END is the index of the last glyph
4717 in that glyph row area. X is the current output position assigned
4718 to the new glyph string constructed. HL overrides that face of the
4719 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4720 is the right-most x-position of the drawing area. */
4722 #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4725 s = (struct glyph_string *) alloca (sizeof *s); \
4726 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4727 x_fill_image_glyph_string (s); \
4728 x_append_glyph_string (&HEAD, &TAIL, s); \
4735 /* Add a glyph string for a sequence of character glyphs to the list
4736 of strings between HEAD and TAIL. START is the index of the first
4737 glyph in row area AREA of glyph row ROW that is part of the new
4738 glyph string. END is the index of the last glyph in that glyph row
4739 area. X is the current output position assigned to the new glyph
4740 string constructed. HL overrides that face of the glyph; e.g. it
4741 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4742 right-most x-position of the drawing area. */
4744 #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4750 c = (ROW)->glyphs[AREA][START].u.ch; \
4751 face_id = (ROW)->glyphs[AREA][START].face_id; \
4753 s = (struct glyph_string *) alloca (sizeof *s); \
4754 char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \
4755 w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \
4756 x_append_glyph_string (&HEAD, &TAIL, s); \
4758 START = x_fill_glyph_string (s, face_id, START, END, \
4764 /* Add a glyph string for a composite sequence to the list of strings
4765 between HEAD and TAIL. START is the index of the first glyph in
4766 row area AREA of glyph row ROW that is part of the new glyph
4767 string. END is the index of the last glyph in that glyph row area.
4768 X is the current output position assigned to the new glyph string
4769 constructed. HL overrides that face of the glyph; e.g. it is
4770 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4771 x-position of the drawing area. */
4773 #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4775 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4776 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4777 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4778 struct composition *cmp = composition_table[cmp_id]; \
4779 int glyph_len = cmp->glyph_len; \
4781 struct face **faces; \
4782 struct glyph_string *first_s = NULL; \
4785 base_face = base_face->ascii_face; \
4786 char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \
4787 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4788 /* At first, fill in `char2b' and `faces'. */ \
4789 for (n = 0; n < glyph_len; n++) \
4791 int c = COMPOSITION_GLYPH (cmp, n); \
4792 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4793 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4794 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4795 this_face_id, char2b + n, 1); \
4798 /* Make glyph_strings for each glyph sequence that is drawable by \
4799 the same face, and append them to HEAD/TAIL. */ \
4800 for (n = 0; n < cmp->glyph_len;) \
4802 s = (struct glyph_string *) alloca (sizeof *s); \
4803 w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \
4804 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4812 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4820 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4821 of AREA of glyph row ROW on window W between indices START and END.
4822 HL overrides the face for drawing glyph strings, e.g. it is
4823 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4824 x-positions of the drawing area.
4826 This is an ugly monster macro construct because we must use alloca
4827 to allocate glyph strings (because x_draw_glyphs can be called
4830 #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4833 HEAD = TAIL = NULL; \
4834 while (START < END) \
4836 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4837 switch (first_glyph->type) \
4840 BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \
4841 HEAD, TAIL, HL, X, LAST_X, \
4845 case COMPOSITE_GLYPH: \
4846 BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \
4847 END, HEAD, TAIL, HL, X, \
4848 LAST_X, OVERLAPS_P); \
4851 case STRETCH_GLYPH: \
4852 BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\
4853 HEAD, TAIL, HL, X, LAST_X); \
4857 BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \
4858 HEAD, TAIL, HL, X, LAST_X); \
4865 x_set_glyph_string_background_width (s, START, LAST_X); \
4872 /* Draw glyphs between START and END in AREA of ROW on window W,
4873 starting at x-position X. X is relative to AREA in W. HL is a
4874 face-override with the following meaning:
4876 DRAW_NORMAL_TEXT draw normally
4877 DRAW_CURSOR draw in cursor face
4878 DRAW_MOUSE_FACE draw in mouse face.
4879 DRAW_INVERSE_VIDEO draw in mode line face
4880 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4881 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4883 If REAL_START is non-null, return in *REAL_START the real starting
4884 position for display. This can be different from START in case
4885 overlapping glyphs must be displayed. If REAL_END is non-null,
4886 return in *REAL_END the real end position for display. This can be
4887 different from END in case overlapping glyphs must be displayed.
4889 If OVERLAPS_P is non-zero, draw only the foreground of characters
4890 and clip to the physical height of ROW.
4892 Value is the x-position reached, relative to AREA of W. */
4895 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4899 struct glyph_row
*row
;
4900 enum glyph_row_area area
;
4902 enum draw_glyphs_face hl
;
4903 int *real_start
, *real_end
;
4906 struct glyph_string
*head
, *tail
;
4907 struct glyph_string
*s
;
4908 int last_x
, area_width
;
4911 HDC hdc
= get_frame_dc (XFRAME (WINDOW_FRAME (w
)));
4913 /* Let's rather be paranoid than getting a SEGV. */
4914 end
= min (end
, row
->used
[area
]);
4915 start
= max (0, start
);
4916 start
= min (end
, start
);
4918 *real_start
= start
;
4922 /* Translate X to frame coordinates. Set last_x to the right
4923 end of the drawing area. */
4924 if (row
->full_width_p
)
4926 /* X is relative to the left edge of W, without scroll bars
4928 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4929 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4930 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4933 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4934 last_x
= window_left_x
+ area_width
;
4936 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4938 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4939 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4945 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4946 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4950 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4951 area_width
= window_box_width (w
, area
);
4952 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4955 /* Build a doubly-linked list of glyph_string structures between
4956 head and tail from what we have to draw. Note that the macro
4957 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4958 the reason we use a separate variable `i'. */
4960 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4963 x_reached
= tail
->x
+ tail
->background_width
;
4967 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4968 the row, redraw some glyphs in front or following the glyph
4969 strings built above. */
4970 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4973 struct glyph_string
*h
, *t
;
4975 /* Compute overhangs for all glyph strings. */
4976 for (s
= head
; s
; s
= s
->next
)
4977 x_compute_glyph_string_overhangs (s
);
4979 /* Prepend glyph strings for glyphs in front of the first glyph
4980 string that are overwritten because of the first glyph
4981 string's left overhang. The background of all strings
4982 prepended must be drawn because the first glyph string
4984 i
= x_left_overwritten (head
);
4988 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, j
, start
, h
, t
,
4989 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4993 *real_start
= start
;
4994 x_compute_overhangs_and_x (t
, head
->x
, 1);
4995 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4998 /* Prepend glyph strings for glyphs in front of the first glyph
4999 string that overwrite that glyph string because of their
5000 right overhang. For these strings, only the foreground must
5001 be drawn, because it draws over the glyph string at `head'.
5002 The background must not be drawn because this would overwrite
5003 right overhangs of preceding glyphs for which no glyph
5005 i
= x_left_overwriting (head
);
5008 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, start
, h
, t
,
5009 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5011 for (s
= h
; s
; s
= s
->next
)
5012 s
->background_filled_p
= 1;
5015 x_compute_overhangs_and_x (t
, head
->x
, 1);
5016 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5019 /* Append glyphs strings for glyphs following the last glyph
5020 string tail that are overwritten by tail. The background of
5021 these strings has to be drawn because tail's foreground draws
5023 i
= x_right_overwritten (tail
);
5026 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5027 DRAW_NORMAL_TEXT
, x
, last_x
,
5029 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5030 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5035 /* Append glyph strings for glyphs following the last glyph
5036 string tail that overwrite tail. The foreground of such
5037 glyphs has to be drawn because it writes into the background
5038 of tail. The background must not be drawn because it could
5039 paint over the foreground of following glyphs. */
5040 i
= x_right_overwriting (tail
);
5043 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5044 DRAW_NORMAL_TEXT
, x
, last_x
,
5046 for (s
= h
; s
; s
= s
->next
)
5047 s
->background_filled_p
= 1;
5048 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5049 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5055 /* Draw all strings. */
5056 for (s
= head
; s
; s
= s
->next
)
5057 x_draw_glyph_string (s
);
5059 /* Value is the x-position up to which drawn, relative to AREA of W.
5060 This doesn't include parts drawn because of overhangs. */
5061 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5062 if (!row
->full_width_p
)
5064 if (area
> LEFT_MARGIN_AREA
)
5065 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5066 if (area
> TEXT_AREA
)
5067 x_reached
-= window_box_width (w
, TEXT_AREA
);
5070 release_frame_dc (XFRAME (WINDOW_FRAME (w
)), hdc
);
5076 /* Fix the display of area AREA of overlapping row ROW in window W. */
5079 x_fix_overlapping_area (w
, row
, area
)
5081 struct glyph_row
*row
;
5082 enum glyph_row_area area
;
5088 if (area
== LEFT_MARGIN_AREA
)
5090 else if (area
== TEXT_AREA
)
5091 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5093 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5094 + window_box_width (w
, TEXT_AREA
));
5096 for (i
= 0; i
< row
->used
[area
];)
5098 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5100 int start
= i
, start_x
= x
;
5104 x
+= row
->glyphs
[area
][i
].pixel_width
;
5107 while (i
< row
->used
[area
]
5108 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5110 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5112 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5117 x
+= row
->glyphs
[area
][i
].pixel_width
;
5126 /* Output LEN glyphs starting at START at the nominal cursor position.
5127 Advance the nominal cursor over the text. The global variable
5128 updated_window contains the window being updated, updated_row is
5129 the glyph row being updated, and updated_area is the area of that
5130 row being updated. */
5133 x_write_glyphs (start
, len
)
5134 struct glyph
*start
;
5137 int x
, hpos
, real_start
, real_end
;
5139 xassert (updated_window
&& updated_row
);
5144 hpos
= start
- updated_row
->glyphs
[updated_area
];
5145 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5146 updated_row
, updated_area
,
5148 (updated_row
->inverse_p
5149 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5150 &real_start
, &real_end
, 0);
5152 /* If we drew over the cursor, note that it is not visible any more. */
5153 note_overwritten_text_cursor (updated_window
, real_start
,
5154 real_end
- real_start
);
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
, real_start
, real_end
;
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
, &real_start
, &real_end
, 0);
5210 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5212 /* Advance the output cursor. */
5213 output_cursor
.hpos
+= len
;
5214 output_cursor
.x
+= shift_by_width
;
5215 release_frame_dc (f
, hdc
);
5221 /* Delete N glyphs at the nominal cursor position. Not implemented
5233 f
= SELECTED_FRAME ();
5235 if (! FRAME_W32_P (f
))
5242 /* Erase the current text line from the nominal cursor position
5243 (inclusive) to pixel column TO_X (exclusive). The idea is that
5244 everything from TO_X onward is already erased.
5246 TO_X is a pixel position relative to updated_area of
5247 updated_window. TO_X == -1 means clear to the end of this area. */
5250 x_clear_end_of_line (to_x
)
5254 struct window
*w
= updated_window
;
5255 int max_x
, min_y
, max_y
;
5256 int from_x
, from_y
, to_y
;
5258 xassert (updated_window
&& updated_row
);
5259 f
= XFRAME (w
->frame
);
5261 if (updated_row
->full_width_p
)
5263 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5264 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5265 && !w
->pseudo_window_p
)
5266 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5269 max_x
= window_box_width (w
, updated_area
);
5270 max_y
= window_text_bottom_y (w
);
5272 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5273 of window. For TO_X > 0, truncate to end of drawing area. */
5279 to_x
= min (to_x
, max_x
);
5281 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5283 /* Notice if the cursor will be cleared by this operation. */
5284 if (!updated_row
->full_width_p
)
5285 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5287 from_x
= output_cursor
.x
;
5289 /* Translate to frame coordinates. */
5290 if (updated_row
->full_width_p
)
5292 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5293 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5297 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5298 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5301 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5302 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5303 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5305 /* Prevent inadvertently clearing to end of the X window. */
5306 if (to_x
> from_x
&& to_y
> from_y
)
5310 hdc
= get_frame_dc (f
);
5312 w32_clear_area (f
, hdc
, from_x
, from_y
, to_x
- from_x
, to_y
- from_y
);
5313 release_frame_dc (f
, hdc
);
5319 /* Clear entire frame. If updating_frame is non-null, clear that
5320 frame. Otherwise clear the selected frame. */
5330 f
= SELECTED_FRAME ();
5332 if (! FRAME_W32_P (f
))
5335 /* Clearing the frame will erase any cursor, so mark them all as no
5337 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5338 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5339 output_cursor
.x
= -1;
5341 /* We don't set the output cursor here because there will always
5342 follow an explicit cursor_to. */
5345 w32_clear_window (f
);
5347 /* We have to clear the scroll bars, too. If we have changed
5348 colors or something like that, then they should be notified. */
5349 x_scroll_bar_clear (f
);
5355 /* Make audible bell. */
5358 w32_ring_bell (void)
5362 f
= SELECTED_FRAME ();
5366 if (FRAME_W32_P (f
) && visible_bell
)
5369 HWND hwnd
= FRAME_W32_WINDOW (SELECTED_FRAME ());
5371 for (i
= 0; i
< 5; i
++)
5373 FlashWindow (hwnd
, TRUE
);
5376 FlashWindow (hwnd
, FALSE
);
5379 w32_sys_ring_bell ();
5385 /* Specify how many text lines, from the top of the window,
5386 should be affected by insert-lines and delete-lines operations.
5387 This, and those operations, are used only within an update
5388 that is bounded by calls to x_update_begin and x_update_end. */
5391 w32_set_terminal_window (n
)
5394 /* This function intentionally left blank. */
5399 /***********************************************************************
5401 ***********************************************************************/
5403 /* Perform an insert-lines or delete-lines operation, inserting N
5404 lines or deleting -N lines at vertical position VPOS. */
5407 x_ins_del_lines (vpos
, n
)
5415 f
= SELECTED_FRAME ();
5417 if (! FRAME_W32_P (f
))
5424 /* Scroll part of the display as described by RUN. */
5427 x_scroll_run (w
, run
)
5431 struct frame
*f
= XFRAME (w
->frame
);
5432 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5433 HDC hdc
= get_frame_dc (f
);
5435 /* Get frame-relative bounding box of the text display area of W,
5436 without mode lines. Include in this box the flags areas to the
5437 left and right of W. */
5438 window_box (w
, -1, &x
, &y
, &width
, &height
);
5439 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5440 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5442 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5443 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5444 bottom_y
= y
+ height
;
5448 /* Scrolling up. Make sure we don't copy part of the mode
5449 line at the bottom. */
5450 if (from_y
+ run
->height
> bottom_y
)
5451 height
= bottom_y
- from_y
;
5453 height
= run
->height
;
5457 /* Scolling down. Make sure we don't copy over the mode line.
5459 if (to_y
+ run
->height
> bottom_y
)
5460 height
= bottom_y
- to_y
;
5462 height
= run
->height
;
5467 /* Cursor off. Will be switched on again in x_update_window_end. */
5471 BitBlt (hdc
, x
, to_y
, width
, height
, hdc
, x
, from_y
, SRCCOPY
);
5474 release_frame_dc (f
, hdc
);
5479 /***********************************************************************
5481 ***********************************************************************/
5483 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5484 corner of the exposed rectangle. W and H are width and height of
5485 the exposed area. All are pixel values. W or H zero means redraw
5486 the entire frame. */
5489 expose_frame (f
, x
, y
, w
, h
)
5495 TRACE ((stderr
, "expose_frame "));
5497 /* No need to redraw if frame will be redrawn soon. */
5498 if (FRAME_GARBAGED_P (f
))
5500 TRACE ((stderr
, " garbaged\n"));
5504 /* If basic faces haven't been realized yet, there is no point in
5505 trying to redraw anything. This can happen when we get an expose
5506 event while Emacs is starting, e.g. by moving another window. */
5507 if (FRAME_FACE_CACHE (f
) == NULL
5508 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5510 TRACE ((stderr
, " no faces\n"));
5514 if (w
== 0 || h
== 0)
5517 r
.right
= CANON_X_UNIT (f
) * f
->width
;
5518 r
.bottom
= CANON_Y_UNIT (f
) * f
->height
;
5528 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.left
, r
.top
, r
.right
, r
.bottom
));
5529 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5531 if (WINDOWP (f
->tool_bar_window
))
5533 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5535 RECT intersection_rect
;
5536 int window_x
, window_y
, window_width
, window_height
;
5538 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5539 window_rect
.left
= window_x
;
5540 window_rect
.top
= window_y
;
5541 window_rect
.right
= window_x
+ window_width
;
5542 window_rect
.bottom
= window_y
+ window_height
;
5544 if (IntersectRect (&intersection_rect
, &r
, &window_rect
))
5545 expose_window (w
, &intersection_rect
);
5550 /* Redraw (parts) of all windows in the window tree rooted at W that
5551 intersect R. R contains frame pixel coordinates. */
5554 expose_window_tree (w
, r
)
5560 if (!NILP (w
->hchild
))
5561 expose_window_tree (XWINDOW (w
->hchild
), r
);
5562 else if (!NILP (w
->vchild
))
5563 expose_window_tree (XWINDOW (w
->vchild
), r
);
5567 RECT intersection_rect
;
5568 struct frame
*f
= XFRAME (w
->frame
);
5569 int window_x
, window_y
, window_width
, window_height
;
5571 /* Frame-relative pixel rectangle of W. */
5572 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5576 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5577 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_Y_UNIT (f
));
5578 window_rect
.top
= window_y
;
5579 window_rect
.right
= window_rect
.left
5581 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5582 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5583 window_rect
.bottom
= window_rect
.top
5584 + window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5586 if (IntersectRect (&intersection_rect
, r
, &window_rect
))
5587 expose_window (w
, &intersection_rect
);
5590 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5595 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5596 which intersects rectangle R. R is in window-relative coordinates. */
5599 expose_area (w
, row
, r
, area
)
5601 struct glyph_row
*row
;
5603 enum glyph_row_area area
;
5605 struct glyph
*first
= row
->glyphs
[area
];
5606 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5608 int first_x
, start_x
, x
;
5610 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5611 /* If row extends face to end of line write the whole line. */
5612 x_draw_glyphs (w
, 0, row
, area
,
5614 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5618 /* Set START_X to the window-relative start position for drawing glyphs of
5619 AREA. The first glyph of the text area can be partially visible.
5620 The first glyphs of other areas cannot. */
5621 if (area
== LEFT_MARGIN_AREA
)
5623 else if (area
== TEXT_AREA
)
5624 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5626 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5627 + window_box_width (w
, TEXT_AREA
));
5630 /* Find the first glyph that must be redrawn. */
5632 && x
+ first
->pixel_width
< r
->left
)
5634 x
+= first
->pixel_width
;
5638 /* Find the last one. */
5644 x
+= last
->pixel_width
;
5650 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5651 first
- row
->glyphs
[area
],
5652 last
- row
->glyphs
[area
],
5653 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5659 /* Redraw the parts of the glyph row ROW on window W intersecting
5660 rectangle R. R is in window-relative coordinates. */
5663 expose_line (w
, row
, r
)
5665 struct glyph_row
*row
;
5668 xassert (row
->enabled_p
);
5670 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5671 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5672 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5676 if (row
->used
[LEFT_MARGIN_AREA
])
5677 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5678 if (row
->used
[TEXT_AREA
])
5679 expose_area (w
, row
, r
, TEXT_AREA
);
5680 if (row
->used
[RIGHT_MARGIN_AREA
])
5681 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5682 x_draw_row_bitmaps (w
, row
);
5687 /* Return non-zero if W's cursor intersects rectangle R. */
5690 x_phys_cursor_in_rect_p (w
, r
)
5695 struct glyph
*cursor_glyph
;
5697 cursor_glyph
= get_phys_cursor_glyph (w
);
5700 cr
.left
= w
->phys_cursor
.x
;
5701 cr
.top
= w
->phys_cursor
.y
;
5702 cr
.right
= cr
.left
+ cursor_glyph
->pixel_width
;
5703 cr
.bottom
= cr
.top
+ w
->phys_cursor_height
;
5704 return IntersectRect (&result
, &cr
, r
);
5711 /* Redraw a rectangle of window W. R is a rectangle in window
5712 relative coordinates. Call this function with input blocked. */
5715 expose_window (w
, r
)
5719 struct glyph_row
*row
;
5721 int yb
= window_text_bottom_y (w
);
5722 int cursor_cleared_p
;
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
|| w
== updated_window
)
5731 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5732 r
->left
, r
->top
, r
->right
, r
->bottom
));
5734 /* Convert to window coordinates. */
5735 r
->left
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->left
);
5736 r
->top
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->top
);
5737 r
->right
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->right
);
5738 r
->bottom
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->bottom
);
5740 /* Turn off the cursor. */
5741 if (!w
->pseudo_window_p
5742 && x_phys_cursor_in_rect_p (w
, r
))
5745 cursor_cleared_p
= 1;
5748 cursor_cleared_p
= 0;
5750 /* Find the first row intersecting the rectangle R. */
5751 row
= w
->current_matrix
->rows
;
5753 while (row
->enabled_p
5755 && y
+ row
->height
< r
->top
)
5761 /* Display the text in the rectangle, one text line at a time. */
5762 while (row
->enabled_p
5766 expose_line (w
, row
, r
);
5771 /* Display the mode line if there is one. */
5772 if (WINDOW_WANTS_MODELINE_P (w
)
5773 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5775 && row
->y
< r
->bottom
)
5776 expose_line (w
, row
, r
);
5778 if (!w
->pseudo_window_p
)
5780 /* Draw border between windows. */
5781 x_draw_vertical_border (w
);
5783 /* Turn the cursor on again. */
5784 if (cursor_cleared_p
)
5785 x_update_window_cursor (w
, 1);
5794 x_update_cursor (f
, 1);
5798 frame_unhighlight (f
)
5801 x_update_cursor (f
, 1);
5804 /* The focus has changed. Update the frames as necessary to reflect
5805 the new situation. Note that we can't change the selected frame
5806 here, because the Lisp code we are interrupting might become confused.
5807 Each event gets marked with the frame in which it occurred, so the
5808 Lisp code can tell when the switch took place by examining the events. */
5811 x_new_focus_frame (dpyinfo
, frame
)
5812 struct w32_display_info
*dpyinfo
;
5813 struct frame
*frame
;
5815 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
5817 if (frame
!= dpyinfo
->w32_focus_frame
)
5819 /* Set this before calling other routines, so that they see
5820 the correct value of w32_focus_frame. */
5821 dpyinfo
->w32_focus_frame
= frame
;
5823 if (old_focus
&& old_focus
->auto_lower
)
5824 x_lower_frame (old_focus
);
5826 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
5827 pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
5829 pending_autoraise_frame
= 0;
5832 x_frame_rehighlight (dpyinfo
);
5835 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5838 x_mouse_leave (dpyinfo
)
5839 struct w32_display_info
*dpyinfo
;
5841 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
5844 /* The focus has changed, or we have redirected a frame's focus to
5845 another frame (this happens when a frame uses a surrogate
5846 mini-buffer frame). Shift the highlight as appropriate.
5848 The FRAME argument doesn't necessarily have anything to do with which
5849 frame is being highlighted or un-highlighted; we only use it to find
5850 the appropriate X display info. */
5853 w32_frame_rehighlight (frame
)
5854 struct frame
*frame
;
5856 if (! FRAME_W32_P (frame
))
5858 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame
));
5862 x_frame_rehighlight (dpyinfo
)
5863 struct w32_display_info
*dpyinfo
;
5865 struct frame
*old_highlight
= dpyinfo
->w32_highlight_frame
;
5867 if (dpyinfo
->w32_focus_frame
)
5869 dpyinfo
->w32_highlight_frame
5870 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
5871 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
5872 : dpyinfo
->w32_focus_frame
);
5873 if (! FRAME_LIVE_P (dpyinfo
->w32_highlight_frame
))
5875 FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
) = Qnil
;
5876 dpyinfo
->w32_highlight_frame
= dpyinfo
->w32_focus_frame
;
5880 dpyinfo
->w32_highlight_frame
= 0;
5882 if (dpyinfo
->w32_highlight_frame
!= old_highlight
)
5885 frame_unhighlight (old_highlight
);
5886 if (dpyinfo
->w32_highlight_frame
)
5887 frame_highlight (dpyinfo
->w32_highlight_frame
);
5891 /* Keyboard processing - modifier keys, etc. */
5893 /* Convert a keysym to its name. */
5896 x_get_keysym_name (keysym
)
5899 /* Make static so we can always return it */
5900 static char value
[100];
5903 GetKeyNameText (keysym
, value
, 100);
5911 /* Mouse clicks and mouse movement. Rah. */
5913 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5914 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5915 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5916 not force the value into range. */
5919 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5921 register int pix_x
, pix_y
;
5922 register int *x
, *y
;
5926 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
5927 if (NILP (Vwindow_system
))
5934 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5935 even for negative values. */
5937 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
5939 pix_y
-= (f
)->output_data
.w32
->line_height
- 1;
5941 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5942 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5946 bounds
->left
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5947 bounds
->top
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5948 bounds
->right
= bounds
->left
+ FONT_WIDTH (FRAME_FONT (f
)) - 1;
5949 bounds
->bottom
= bounds
->top
+ f
->output_data
.w32
->line_height
- 1;
5956 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5957 pix_x
= FRAME_WINDOW_WIDTH (f
);
5961 else if (pix_y
> f
->height
)
5970 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5971 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5972 can't tell the positions because W's display is not up to date,
5976 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
5979 int *frame_x
, *frame_y
;
5983 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
5984 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
5986 if (display_completed
)
5988 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5989 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
5990 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
5996 *frame_x
+= glyph
->pixel_width
;
6004 *frame_y
= *frame_x
= 0;
6008 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6009 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6014 parse_button (message
, pbutton
, pup
)
6024 case WM_LBUTTONDOWN
:
6032 case WM_MBUTTONDOWN
:
6033 if (NILP (Vw32_swap_mouse_buttons
))
6040 if (NILP (Vw32_swap_mouse_buttons
))
6046 case WM_RBUTTONDOWN
:
6047 if (NILP (Vw32_swap_mouse_buttons
))
6054 if (NILP (Vw32_swap_mouse_buttons
))
6065 if (pbutton
) *pbutton
= button
;
6071 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6073 If the event is a button press, then note that we have grabbed
6077 construct_mouse_click (result
, msg
, f
)
6078 struct input_event
*result
;
6085 parse_button (msg
->msg
.message
, &button
, &up
);
6087 /* Make the event type no_event; we'll change that when we decide
6089 result
->kind
= mouse_click
;
6090 result
->code
= button
;
6091 result
->timestamp
= msg
->msg
.time
;
6092 result
->modifiers
= (msg
->dwModifiers
6097 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
6098 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
6099 XSETFRAME (result
->frame_or_window
, f
);
6105 construct_mouse_wheel (result
, msg
, f
)
6106 struct input_event
*result
;
6111 result
->kind
= mouse_wheel
;
6112 result
->code
= (short) HIWORD (msg
->msg
.wParam
);
6113 result
->timestamp
= msg
->msg
.time
;
6114 result
->modifiers
= msg
->dwModifiers
;
6115 p
.x
= LOWORD (msg
->msg
.lParam
);
6116 p
.y
= HIWORD (msg
->msg
.lParam
);
6117 ScreenToClient (msg
->msg
.hwnd
, &p
);
6118 XSETINT (result
->x
, p
.x
);
6119 XSETINT (result
->y
, p
.y
);
6120 XSETFRAME (result
->frame_or_window
, f
);
6126 construct_drag_n_drop (result
, msg
, f
)
6127 struct input_event
*result
;
6139 result
->kind
= drag_n_drop
;
6141 result
->timestamp
= msg
->msg
.time
;
6142 result
->modifiers
= msg
->dwModifiers
;
6144 hdrop
= (HDROP
) msg
->msg
.wParam
;
6145 DragQueryPoint (hdrop
, &p
);
6148 p
.x
= LOWORD (msg
->msg
.lParam
);
6149 p
.y
= HIWORD (msg
->msg
.lParam
);
6150 ScreenToClient (msg
->msg
.hwnd
, &p
);
6153 XSETINT (result
->x
, p
.x
);
6154 XSETINT (result
->y
, p
.y
);
6156 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
6159 for (i
= 0; i
< num_files
; i
++)
6161 len
= DragQueryFile (hdrop
, i
, NULL
, 0);
6164 name
= alloca (len
+ 1);
6165 DragQueryFile (hdrop
, i
, name
, len
+ 1);
6166 files
= Fcons (build_string (name
), files
);
6171 XSETFRAME (frame
, f
);
6172 result
->frame_or_window
= Fcons (frame
, files
);
6178 /* Function to report a mouse movement to the mainstream Emacs code.
6179 The input handler calls this.
6181 We have received a mouse movement event, which is given in *event.
6182 If the mouse is over a different glyph than it was last time, tell
6183 the mainstream emacs code by setting mouse_moved. If not, ask for
6184 another motion event, so we can check again the next time it moves. */
6186 static MSG last_mouse_motion_event
;
6187 static Lisp_Object last_mouse_motion_frame
;
6190 note_mouse_movement (frame
, msg
)
6194 last_mouse_movement_time
= msg
->time
;
6195 memcpy (&last_mouse_motion_event
, msg
, sizeof (last_mouse_motion_event
));
6196 XSETFRAME (last_mouse_motion_frame
, frame
);
6198 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
6200 frame
->mouse_moved
= 1;
6201 last_mouse_scroll_bar
= Qnil
;
6202 note_mouse_highlight (frame
, -1, -1);
6205 /* Has the mouse moved off the glyph it was on at the last sighting? */
6206 else if (LOWORD (msg
->lParam
) < last_mouse_glyph
.left
6207 || LOWORD (msg
->lParam
) > last_mouse_glyph
.right
6208 || HIWORD (msg
->lParam
) < last_mouse_glyph
.top
6209 || HIWORD (msg
->lParam
) > last_mouse_glyph
.bottom
)
6211 frame
->mouse_moved
= 1;
6212 last_mouse_scroll_bar
= Qnil
;
6213 note_mouse_highlight (frame
, LOWORD (msg
->lParam
), HIWORD (msg
->lParam
));
6217 /* This is used for debugging, to turn off note_mouse_highlight. */
6219 int disable_mouse_highlight
;
6223 /************************************************************************
6225 ************************************************************************/
6227 /* Find the glyph under window-relative coordinates X/Y in window W.
6228 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6229 strings. Return in *HPOS and *VPOS the row and column number of
6230 the glyph found. Return in *AREA the glyph area containing X.
6231 Value is a pointer to the glyph found or null if X/Y is not on
6232 text, or we can't tell because W's current matrix is not up to
6235 static struct glyph
*
6236 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6239 int *hpos
, *vpos
, *area
;
6241 struct glyph
*glyph
, *end
;
6242 struct glyph_row
*row
= NULL
;
6243 int x0
, i
, left_area_width
;
6245 /* Find row containing Y. Give up if some row is not enabled. */
6246 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6248 row
= MATRIX_ROW (w
->current_matrix
, i
);
6249 if (!row
->enabled_p
)
6251 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6258 /* Give up if Y is not in the window. */
6259 if (i
== w
->current_matrix
->nrows
)
6262 /* Get the glyph area containing X. */
6263 if (w
->pseudo_window_p
)
6270 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6271 if (x
< left_area_width
)
6273 *area
= LEFT_MARGIN_AREA
;
6276 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6279 x0
= row
->x
+ left_area_width
;
6283 *area
= RIGHT_MARGIN_AREA
;
6284 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6288 /* Find glyph containing X. */
6289 glyph
= row
->glyphs
[*area
];
6290 end
= glyph
+ row
->used
[*area
];
6293 if (x
< x0
+ glyph
->pixel_width
)
6295 if (w
->pseudo_window_p
)
6297 else if (BUFFERP (glyph
->object
))
6301 x0
+= glyph
->pixel_width
;
6308 *hpos
= glyph
- row
->glyphs
[*area
];
6313 /* Convert frame-relative x/y to coordinates relative to window W.
6314 Takes pseudo-windows into account. */
6317 frame_to_window_pixel_xy (w
, x
, y
)
6321 if (w
->pseudo_window_p
)
6323 /* A pseudo-window is always full-width, and starts at the
6324 left edge of the frame, plus a frame border. */
6325 struct frame
*f
= XFRAME (w
->frame
);
6326 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6327 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6331 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6332 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6337 /* Take proper action when mouse has moved to the mode or header line of
6338 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6339 mode line. X is relative to the start of the text display area of
6340 W, so the width of bitmap areas and scroll bars must be subtracted
6341 to get a position relative to the start of the mode line. */
6344 note_mode_line_highlight (w
, x
, mode_line_p
)
6348 struct frame
*f
= XFRAME (w
->frame
);
6349 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6350 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6351 struct glyph_row
*row
;
6354 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6356 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6360 struct glyph
*glyph
, *end
;
6361 Lisp_Object help
, map
;
6364 /* Find the glyph under X. */
6365 glyph
= row
->glyphs
[TEXT_AREA
];
6366 end
= glyph
+ row
->used
[TEXT_AREA
];
6367 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6368 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6371 && x
>= x0
+ glyph
->pixel_width
)
6373 x0
+= glyph
->pixel_width
;
6378 && STRINGP (glyph
->object
)
6379 && XSTRING (glyph
->object
)->intervals
6380 && glyph
->charpos
>= 0
6381 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6383 /* If we're on a string with `help-echo' text property,
6384 arrange for the help to be displayed. This is done by
6385 setting the global variable help_echo to the help string. */
6386 help
= Fget_text_property (make_number (glyph
->charpos
),
6387 Qhelp_echo
, glyph
->object
);
6391 XSETWINDOW (help_echo_window
, w
);
6392 help_echo_object
= glyph
->object
;
6393 help_echo_pos
= glyph
->charpos
;
6396 /* Change the mouse pointer according to what is under X/Y. */
6397 map
= Fget_text_property (make_number (glyph
->charpos
),
6398 Qlocal_map
, glyph
->object
);
6400 cursor
= f
->output_data
.w32
->nontext_cursor
;
6403 map
= Fget_text_property (make_number (glyph
->charpos
),
6404 Qkeymap
, glyph
->object
);
6406 cursor
= f
->output_data
.w32
->nontext_cursor
;
6411 #if 0 /* TODO: mouse cursor */
6412 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6417 /* Take proper action when the mouse has moved to position X, Y on
6418 frame F as regards highlighting characters that have mouse-face
6419 properties. Also de-highlighting chars where the mouse was before.
6420 X and Y can be negative or out of range. */
6423 note_mouse_highlight (f
, x
, y
)
6427 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6432 /* When a menu is active, don't highlight because this looks odd. */
6433 if (popup_activated ())
6436 if (disable_mouse_highlight
6437 || !f
->glyphs_initialized_p
)
6440 dpyinfo
->mouse_face_mouse_x
= x
;
6441 dpyinfo
->mouse_face_mouse_y
= y
;
6442 dpyinfo
->mouse_face_mouse_frame
= f
;
6444 if (dpyinfo
->mouse_face_defer
)
6449 dpyinfo
->mouse_face_deferred_gc
= 1;
6453 /* Which window is that in? */
6454 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6456 /* If we were displaying active text in another window, clear that. */
6457 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6458 clear_mouse_face (dpyinfo
);
6460 /* Not on a window -> return. */
6461 if (!WINDOWP (window
))
6464 /* Convert to window-relative pixel coordinates. */
6465 w
= XWINDOW (window
);
6466 frame_to_window_pixel_xy (w
, &x
, &y
);
6468 /* Handle tool-bar window differently since it doesn't display a
6470 if (EQ (window
, f
->tool_bar_window
))
6472 note_tool_bar_highlight (f
, x
, y
);
6476 if (portion
== 1 || portion
== 3)
6478 /* Mouse is on the mode or top line. */
6479 note_mode_line_highlight (w
, x
, portion
== 1);
6482 #if 0 /* TODO: mouse cursor */
6483 else if (portion
== 2)
6484 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6485 f
->output_data
.x
->horizontal_drag_cursor
);
6487 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6488 f
->output_data
.x
->text_cursor
);
6491 /* Are we in a window whose display is up to date?
6492 And verify the buffer's text has not changed. */
6493 if (/* Within text portion of the window. */
6495 && EQ (w
->window_end_valid
, w
->buffer
)
6496 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6497 && (XFASTINT (w
->last_overlay_modified
)
6498 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6500 int hpos
, vpos
, pos
, i
, area
;
6501 struct glyph
*glyph
;
6503 /* Find the glyph under X/Y. */
6504 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6506 /* Clear mouse face if X/Y not over text. */
6508 || area
!= TEXT_AREA
6509 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6511 clear_mouse_face (dpyinfo
);
6515 pos
= glyph
->charpos
;
6516 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6518 /* Check for mouse-face and help-echo. */
6520 Lisp_Object mouse_face
, overlay
, position
;
6521 Lisp_Object
*overlay_vec
;
6523 struct buffer
*obuf
;
6526 /* If we get an out-of-range value, return now; avoid an error. */
6527 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6530 /* Make the window's buffer temporarily current for
6531 overlays_at and compute_char_face. */
6532 obuf
= current_buffer
;
6533 current_buffer
= XBUFFER (w
->buffer
);
6539 /* Is this char mouse-active or does it have help-echo? */
6540 XSETINT (position
, pos
);
6542 /* Put all the overlays we want in a vector in overlay_vec.
6543 Store the length in len. If there are more than 10, make
6544 enough space for all, and try again. */
6546 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6547 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6548 if (noverlays
> len
)
6551 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6552 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6555 /* Sort overlays into increasing priority order. */
6556 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6558 /* Check mouse-face highlighting. */
6559 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6560 && vpos
>= dpyinfo
->mouse_face_beg_row
6561 && vpos
<= dpyinfo
->mouse_face_end_row
6562 && (vpos
> dpyinfo
->mouse_face_beg_row
6563 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6564 && (vpos
< dpyinfo
->mouse_face_end_row
6565 || hpos
< dpyinfo
->mouse_face_end_col
6566 || dpyinfo
->mouse_face_past_end
)))
6568 /* Clear the display of the old active region, if any. */
6569 clear_mouse_face (dpyinfo
);
6571 /* Find the highest priority overlay that has a mouse-face prop. */
6573 for (i
= noverlays
- 1; i
>= 0; --i
)
6575 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6576 if (!NILP (mouse_face
))
6578 overlay
= overlay_vec
[i
];
6583 /* If no overlay applies, get a text property. */
6585 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6587 /* Handle the overlay case. */
6588 if (! NILP (overlay
))
6590 /* Find the range of text around this char that
6591 should be active. */
6592 Lisp_Object before
, after
;
6595 before
= Foverlay_start (overlay
);
6596 after
= Foverlay_end (overlay
);
6597 /* Record this as the current active region. */
6598 fast_find_position (w
, XFASTINT (before
),
6599 &dpyinfo
->mouse_face_beg_col
,
6600 &dpyinfo
->mouse_face_beg_row
,
6601 &dpyinfo
->mouse_face_beg_x
,
6602 &dpyinfo
->mouse_face_beg_y
);
6603 dpyinfo
->mouse_face_past_end
6604 = !fast_find_position (w
, XFASTINT (after
),
6605 &dpyinfo
->mouse_face_end_col
,
6606 &dpyinfo
->mouse_face_end_row
,
6607 &dpyinfo
->mouse_face_end_x
,
6608 &dpyinfo
->mouse_face_end_y
);
6609 dpyinfo
->mouse_face_window
= window
;
6610 dpyinfo
->mouse_face_face_id
6611 = face_at_buffer_position (w
, pos
, 0, 0,
6612 &ignore
, pos
+ 1, 1);
6614 /* Display it as active. */
6615 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6617 /* Handle the text property case. */
6618 else if (! NILP (mouse_face
))
6620 /* Find the range of text around this char that
6621 should be active. */
6622 Lisp_Object before
, after
, beginning
, end
;
6625 beginning
= Fmarker_position (w
->start
);
6626 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6627 - XFASTINT (w
->window_end_pos
)));
6629 = Fprevious_single_property_change (make_number (pos
+ 1),
6631 w
->buffer
, beginning
);
6633 = Fnext_single_property_change (position
, Qmouse_face
,
6635 /* Record this as the current active region. */
6636 fast_find_position (w
, XFASTINT (before
),
6637 &dpyinfo
->mouse_face_beg_col
,
6638 &dpyinfo
->mouse_face_beg_row
,
6639 &dpyinfo
->mouse_face_beg_x
,
6640 &dpyinfo
->mouse_face_beg_y
);
6641 dpyinfo
->mouse_face_past_end
6642 = !fast_find_position (w
, XFASTINT (after
),
6643 &dpyinfo
->mouse_face_end_col
,
6644 &dpyinfo
->mouse_face_end_row
,
6645 &dpyinfo
->mouse_face_end_x
,
6646 &dpyinfo
->mouse_face_end_y
);
6647 dpyinfo
->mouse_face_window
= window
;
6648 dpyinfo
->mouse_face_face_id
6649 = face_at_buffer_position (w
, pos
, 0, 0,
6650 &ignore
, pos
+ 1, 1);
6652 /* Display it as active. */
6653 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6657 /* Look for a `help-echo' property. */
6659 Lisp_Object help
, overlay
;
6661 /* Check overlays first. */
6662 help
= overlay
= Qnil
;
6663 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6665 overlay
= overlay_vec
[i
];
6666 help
= Foverlay_get (overlay
, Qhelp_echo
);
6672 help_echo_window
= window
;
6673 help_echo_object
= overlay
;
6674 help_echo_pos
= pos
;
6678 /* Try text properties. */
6679 if ((STRINGP (glyph
->object
)
6680 && glyph
->charpos
>= 0
6681 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6682 || (BUFFERP (glyph
->object
)
6683 && glyph
->charpos
>= BEGV
6684 && glyph
->charpos
< ZV
))
6685 help
= Fget_text_property (make_number (glyph
->charpos
),
6686 Qhelp_echo
, glyph
->object
);
6691 help_echo_window
= window
;
6692 help_echo_object
= glyph
->object
;
6693 help_echo_pos
= glyph
->charpos
;
6700 current_buffer
= obuf
;
6706 redo_mouse_highlight ()
6708 if (!NILP (last_mouse_motion_frame
)
6709 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6710 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6711 LOWORD (last_mouse_motion_event
.lParam
),
6712 HIWORD (last_mouse_motion_event
.lParam
));
6717 /***********************************************************************
6719 ***********************************************************************/
6721 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6722 struct glyph
**, int *, int *, int *));
6724 /* Tool-bar item index of the item on which a mouse button was pressed
6727 static int last_tool_bar_item
;
6730 /* Get information about the tool-bar item at position X/Y on frame F.
6731 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6732 the current matrix of the tool-bar window of F, or NULL if not
6733 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6734 item in F->tool_bar_items. Value is
6736 -1 if X/Y is not on a tool-bar item
6737 0 if X/Y is on the same item that was highlighted before.
6741 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6744 struct glyph
**glyph
;
6745 int *hpos
, *vpos
, *prop_idx
;
6747 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6748 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6751 /* Find the glyph under X/Y. */
6752 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6756 /* Get the start of this tool-bar item's properties in
6757 f->tool_bar_items. */
6758 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6761 /* Is mouse on the highlighted item? */
6762 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6763 && *vpos
>= dpyinfo
->mouse_face_beg_row
6764 && *vpos
<= dpyinfo
->mouse_face_end_row
6765 && (*vpos
> dpyinfo
->mouse_face_beg_row
6766 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6767 && (*vpos
< dpyinfo
->mouse_face_end_row
6768 || *hpos
< dpyinfo
->mouse_face_end_col
6769 || dpyinfo
->mouse_face_past_end
))
6776 /* Handle mouse button event on the tool-bar of frame F, at
6777 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6781 w32_handle_tool_bar_click (f
, button_event
)
6783 struct input_event
*button_event
;
6785 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6786 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6787 int hpos
, vpos
, prop_idx
;
6788 struct glyph
*glyph
;
6789 Lisp_Object enabled_p
;
6790 int x
= XFASTINT (button_event
->x
);
6791 int y
= XFASTINT (button_event
->y
);
6793 /* If not on the highlighted tool-bar item, return. */
6794 frame_to_window_pixel_xy (w
, &x
, &y
);
6795 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6798 /* If item is disabled, do nothing. */
6799 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6800 if (NILP (enabled_p
))
6803 if (button_event
->kind
== mouse_click
)
6805 /* Show item in pressed state. */
6806 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6807 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6808 last_tool_bar_item
= prop_idx
;
6812 Lisp_Object key
, frame
;
6813 struct input_event event
;
6815 /* Show item in released state. */
6816 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6817 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6819 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
6821 XSETFRAME (frame
, f
);
6822 event
.kind
= TOOL_BAR_EVENT
;
6823 event
.frame_or_window
= frame
;
6825 kbd_buffer_store_event (&event
);
6827 event
.kind
= TOOL_BAR_EVENT
;
6828 event
.frame_or_window
= frame
;
6830 event
.modifiers
= button_event
->modifiers
;
6831 kbd_buffer_store_event (&event
);
6832 last_tool_bar_item
= -1;
6837 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6838 tool-bar window-relative coordinates X/Y. Called from
6839 note_mouse_highlight. */
6842 note_tool_bar_highlight (f
, x
, y
)
6846 Lisp_Object window
= f
->tool_bar_window
;
6847 struct window
*w
= XWINDOW (window
);
6848 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6850 struct glyph
*glyph
;
6851 struct glyph_row
*row
;
6853 Lisp_Object enabled_p
;
6855 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6856 int mouse_down_p
, rc
;
6858 /* Function note_mouse_highlight is called with negative x(y
6859 values when mouse moves outside of the frame. */
6860 if (x
<= 0 || y
<= 0)
6862 clear_mouse_face (dpyinfo
);
6866 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6869 /* Not on tool-bar item. */
6870 clear_mouse_face (dpyinfo
);
6874 /* On same tool-bar item as before. */
6877 clear_mouse_face (dpyinfo
);
6879 /* Mouse is down, but on different tool-bar item? */
6880 mouse_down_p
= (dpyinfo
->grabbed
6881 && f
== last_mouse_frame
6882 && FRAME_LIVE_P (f
));
6884 && last_tool_bar_item
!= prop_idx
)
6887 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6888 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6890 /* If tool-bar item is not enabled, don't highlight it. */
6891 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6892 if (!NILP (enabled_p
))
6894 /* Compute the x-position of the glyph. In front and past the
6895 image is a space. We include this is the highlighted area. */
6896 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6897 for (i
= x
= 0; i
< hpos
; ++i
)
6898 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6900 /* Record this as the current active region. */
6901 dpyinfo
->mouse_face_beg_col
= hpos
;
6902 dpyinfo
->mouse_face_beg_row
= vpos
;
6903 dpyinfo
->mouse_face_beg_x
= x
;
6904 dpyinfo
->mouse_face_beg_y
= row
->y
;
6905 dpyinfo
->mouse_face_past_end
= 0;
6907 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6908 dpyinfo
->mouse_face_end_row
= vpos
;
6909 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6910 dpyinfo
->mouse_face_end_y
= row
->y
;
6911 dpyinfo
->mouse_face_window
= window
;
6912 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6914 /* Display it as active. */
6915 show_mouse_face (dpyinfo
, draw
);
6916 dpyinfo
->mouse_face_image_state
= draw
;
6921 /* Set help_echo to a help string.to display for this tool-bar item.
6922 w32_read_socket does the rest. */
6923 help_echo_object
= help_echo_window
= Qnil
;
6925 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
6926 if (NILP (help_echo
))
6927 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
6932 /* Find the glyph matrix position of buffer position POS in window W.
6933 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6934 current glyphs must be up to date. If POS is above window start
6935 return (0, 0, 0, 0). If POS is after end of W, return end of
6939 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6942 int *hpos
, *vpos
, *x
, *y
;
6946 int maybe_next_line_p
= 0;
6947 int line_start_position
;
6948 int yb
= window_text_bottom_y (w
);
6949 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6950 struct glyph_row
*best_row
= row
;
6951 int row_vpos
= 0, best_row_vpos
= 0;
6956 if (row
->used
[TEXT_AREA
])
6957 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6959 line_start_position
= 0;
6961 if (line_start_position
> pos
)
6963 /* If the position sought is the end of the buffer,
6964 don't include the blank lines at the bottom of the window. */
6965 else if (line_start_position
== pos
6966 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6968 maybe_next_line_p
= 1;
6971 else if (line_start_position
> 0)
6974 best_row_vpos
= row_vpos
;
6977 if (row
->y
+ row
->height
>= yb
)
6984 /* Find the right column within BEST_ROW. */
6986 current_x
= best_row
->x
;
6987 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6989 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6992 charpos
= glyph
->charpos
;
6996 *vpos
= best_row_vpos
;
7001 else if (charpos
> pos
)
7003 else if (charpos
> 0)
7006 current_x
+= glyph
->pixel_width
;
7009 /* If we're looking for the end of the buffer,
7010 and we didn't find it in the line we scanned,
7011 use the start of the following line. */
7012 if (maybe_next_line_p
)
7017 current_x
= best_row
->x
;
7020 *vpos
= best_row_vpos
;
7021 *hpos
= lastcol
+ 1;
7028 /* Display the active region described by mouse_face_*
7029 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7032 show_mouse_face (dpyinfo
, draw
)
7033 struct w32_display_info
*dpyinfo
;
7034 enum draw_glyphs_face draw
;
7036 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7037 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7039 int cursor_off_p
= 0;
7040 struct cursor_pos saved_cursor
;
7042 saved_cursor
= output_cursor
;
7044 /* If window is in the process of being destroyed, don't bother
7046 if (w
->current_matrix
== NULL
)
7049 /* Recognize when we are called to operate on rows that don't exist
7050 anymore. This can happen when a window is split. */
7051 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7054 set_output_cursor (&w
->phys_cursor
);
7056 /* Note that mouse_face_beg_row etc. are window relative. */
7057 for (i
= dpyinfo
->mouse_face_beg_row
;
7058 i
<= dpyinfo
->mouse_face_end_row
;
7061 int start_hpos
, end_hpos
, start_x
;
7062 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7064 /* Don't do anything if row doesn't have valid contents. */
7065 if (!row
->enabled_p
)
7068 /* For all but the first row, the highlight starts at column 0. */
7069 if (i
== dpyinfo
->mouse_face_beg_row
)
7071 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7072 start_x
= dpyinfo
->mouse_face_beg_x
;
7080 if (i
== dpyinfo
->mouse_face_end_row
)
7081 end_hpos
= dpyinfo
->mouse_face_end_col
;
7083 end_hpos
= row
->used
[TEXT_AREA
];
7085 /* If the cursor's in the text we are about to rewrite, turn the
7087 if (!w
->pseudo_window_p
7088 && i
== output_cursor
.vpos
7089 && output_cursor
.hpos
>= start_hpos
- 1
7090 && output_cursor
.hpos
<= end_hpos
)
7092 x_update_window_cursor (w
, 0);
7096 if (end_hpos
> start_hpos
)
7098 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7099 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7100 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7104 /* If we turned the cursor off, turn it back on. */
7106 x_display_cursor (w
, 1,
7107 output_cursor
.hpos
, output_cursor
.vpos
,
7108 output_cursor
.x
, output_cursor
.y
);
7110 output_cursor
= saved_cursor
;
7113 #if 0 /* TODO: mouse cursor */
7114 /* Change the mouse cursor. */
7115 if (draw
== DRAW_NORMAL_TEXT
)
7116 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7117 f
->output_data
.x
->text_cursor
);
7118 else if (draw
== DRAW_MOUSE_FACE
)
7119 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7120 f
->output_data
.x
->cross_cursor
);
7122 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7123 f
->output_data
.x
->nontext_cursor
);
7128 /* Clear out the mouse-highlighted active region.
7129 Redraw it un-highlighted first. */
7132 clear_mouse_face (dpyinfo
)
7133 struct w32_display_info
*dpyinfo
;
7135 #if 0 /* This prevents redrawing tool bar items when changing from one
7136 to another while a tooltip is open, so don't do it. */
7137 if (!NILP (tip_frame
))
7141 if (! NILP (dpyinfo
->mouse_face_window
))
7142 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7144 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7145 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7146 dpyinfo
->mouse_face_window
= Qnil
;
7150 /* Clear any mouse-face on window W. This function is part of the
7151 redisplay interface, and is called from try_window_id and similar
7152 functions to ensure the mouse-highlight is off. */
7155 x_clear_mouse_face (w
)
7158 struct w32_display_info
*dpyinfo
7159 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
7163 XSETWINDOW (window
, w
);
7164 if (EQ (window
, dpyinfo
->mouse_face_window
))
7165 clear_mouse_face (dpyinfo
);
7170 /* Just discard the mouse face information for frame F, if any.
7171 This is used when the size of F is changed. */
7174 cancel_mouse_face (f
)
7178 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7180 window
= dpyinfo
->mouse_face_window
;
7181 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7183 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7184 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7185 dpyinfo
->mouse_face_window
= Qnil
;
7189 static struct scroll_bar
*x_window_to_scroll_bar ();
7190 static void x_scroll_bar_report_motion ();
7192 /* Return the current position of the mouse.
7193 *fp should be a frame which indicates which display to ask about.
7195 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7196 and *part to the frame, window, and scroll bar part that the mouse
7197 is over. Set *x and *y to the portion and whole of the mouse's
7198 position on the scroll bar.
7200 If the mouse movement started elsewhere, set *fp to the frame the
7201 mouse is on, *bar_window to nil, and *x and *y to the character cell
7204 Set *time to the server time-stamp for the time at which the mouse
7205 was at this position.
7207 Don't store anything if we don't have a valid set of values to report.
7209 This clears the mouse_moved flag, so we can wait for the next mouse
7213 w32_mouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7216 Lisp_Object
*bar_window
;
7217 enum scroll_bar_part
*part
;
7219 unsigned long *time
;
7225 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7226 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7231 Lisp_Object frame
, tail
;
7233 /* Clear the mouse-moved flag for every frame on this display. */
7234 FOR_EACH_FRAME (tail
, frame
)
7235 XFRAME (frame
)->mouse_moved
= 0;
7237 last_mouse_scroll_bar
= Qnil
;
7241 /* Now we have a position on the root; find the innermost window
7242 containing the pointer. */
7244 if (FRAME_W32_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7245 && FRAME_LIVE_P (last_mouse_frame
))
7247 /* If mouse was grabbed on a frame, give coords for that frame
7248 even if the mouse is now outside it. */
7249 f1
= last_mouse_frame
;
7253 /* Is window under mouse one of our frames? */
7254 f1
= x_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp
),
7255 WindowFromPoint (pt
));
7258 /* If not, is it one of our scroll bars? */
7261 struct scroll_bar
*bar
7262 = x_window_to_scroll_bar (WindowFromPoint (pt
));
7266 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7270 if (f1
== 0 && insist
> 0)
7271 f1
= SELECTED_FRAME ();
7275 /* Ok, we found a frame. Store all the values.
7276 last_mouse_glyph is a rectangle used to reduce the
7277 generation of mouse events. To not miss any motion
7278 events, we must divide the frame into rectangles of the
7279 size of the smallest character that could be displayed
7280 on it, i.e. into the same rectangles that matrices on
7281 the frame are divided into. */
7283 #if OLD_REDISPLAY_CODE
7284 int ignore1
, ignore2
;
7286 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7288 pixel_to_glyph_coords (f1
, pt
.x
, pt
.y
, &ignore1
, &ignore2
,
7290 FRAME_W32_DISPLAY_INFO (f1
)->grabbed
7293 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7295 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7296 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7300 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7301 round down even for negative values. */
7307 last_mouse_glyph
.left
= (x
+ width
- 1) / width
* width
;
7308 last_mouse_glyph
.top
= (y
+ height
- 1) / height
* height
;
7309 last_mouse_glyph
.right
= last_mouse_glyph
.left
+ width
;
7310 last_mouse_glyph
.bottom
= last_mouse_glyph
.top
+ height
;
7319 *time
= last_mouse_movement_time
;
7328 /* Scroll bar support. */
7330 /* Given a window ID, find the struct scroll_bar which manages it.
7331 This can be called in GC, so we have to make sure to strip off mark
7334 static struct scroll_bar
*
7335 x_window_to_scroll_bar (window_id
)
7340 for (tail
= Vframe_list
;
7341 XGCTYPE (tail
) == Lisp_Cons
;
7344 Lisp_Object frame
, bar
, condemned
;
7346 frame
= XCAR (tail
);
7347 /* All elements of Vframe_list should be frames. */
7348 if (! GC_FRAMEP (frame
))
7351 /* Scan this frame's scroll bar list for a scroll bar with the
7353 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7354 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7355 /* This trick allows us to search both the ordinary and
7356 condemned scroll bar lists with one loop. */
7357 ! GC_NILP (bar
) || (bar
= condemned
,
7360 bar
= XSCROLL_BAR (bar
)->next
)
7361 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7362 return XSCROLL_BAR (bar
);
7370 /* Set the thumb size and position of scroll bar BAR. We are currently
7371 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7374 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
)
7375 struct scroll_bar
*bar
;
7376 int portion
, position
, whole
;
7378 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7379 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7380 int sb_page
, sb_pos
;
7381 BOOL draggingp
= !NILP (bar
->dragging
) ? TRUE
: FALSE
;
7385 /* Position scroll bar at rock bottom if the bottom of the
7386 buffer is visible. This avoids shinking the thumb away
7387 to nothing if it is held at the bottom of the buffer. */
7388 if (position
+ portion
>= whole
)
7390 sb_page
= range
* (whole
- position
) / whole
7391 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7395 sb_page
= portion
* range
/ whole
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7396 sb_pos
= position
* range
/ whole
;
7406 if (pfnSetScrollInfo
)
7410 si
.cbSize
= sizeof (si
);
7411 /* Only update page size if currently dragging, to reduce
7414 si
.fMask
= SIF_PAGE
;
7416 si
.fMask
= SIF_PAGE
| SIF_POS
;
7420 pfnSetScrollInfo (w
, SB_CTL
, &si
, !draggingp
);
7423 SetScrollPos (w
, SB_CTL
, sb_pos
, !draggingp
);
7429 /************************************************************************
7430 Scroll bars, general
7431 ************************************************************************/
7434 my_create_scrollbar (f
, bar
)
7436 struct scroll_bar
* bar
;
7438 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
7439 WM_EMACS_CREATESCROLLBAR
, (WPARAM
) f
,
7443 //#define ATTACH_THREADS
7446 my_show_window (FRAME_PTR f
, HWND hwnd
, int how
)
7448 #ifndef ATTACH_THREADS
7449 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
7450 (WPARAM
) hwnd
, (LPARAM
) how
);
7452 return ShowWindow (hwnd
, how
);
7457 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
7458 int x
, int y
, int cx
, int cy
, UINT flags
)
7460 #ifndef ATTACH_THREADS
7462 pos
.hwndInsertAfter
= hwndAfter
;
7468 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
7470 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
7475 my_set_focus (f
, hwnd
)
7479 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
7484 my_set_foreground_window (hwnd
)
7487 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
7491 my_destroy_window (f
, hwnd
)
7495 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
7499 /* Create a scroll bar and return the scroll bar vector for it. W is
7500 the Emacs window on which to create the scroll bar. TOP, LEFT,
7501 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7504 static struct scroll_bar
*
7505 x_scroll_bar_create (w
, top
, left
, width
, height
)
7507 int top
, left
, width
, height
;
7509 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7511 struct scroll_bar
*bar
7512 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7516 XSETWINDOW (bar
->window
, w
);
7517 XSETINT (bar
->top
, top
);
7518 XSETINT (bar
->left
, left
);
7519 XSETINT (bar
->width
, width
);
7520 XSETINT (bar
->height
, height
);
7521 XSETINT (bar
->start
, 0);
7522 XSETINT (bar
->end
, 0);
7523 bar
->dragging
= Qnil
;
7525 /* Requires geometry to be set before call to create the real window */
7527 hwnd
= my_create_scrollbar (f
, bar
);
7529 if (pfnSetScrollInfo
)
7533 si
.cbSize
= sizeof (si
);
7536 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
7537 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7541 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
7545 SetScrollRange (hwnd
, SB_CTL
, 0,
7546 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
7547 SetScrollPos (hwnd
, SB_CTL
, 0, FALSE
);
7550 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
7552 /* Add bar to its frame's list of scroll bars. */
7553 bar
->next
= FRAME_SCROLL_BARS (f
);
7555 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7556 if (! NILP (bar
->next
))
7557 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7565 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7569 x_scroll_bar_remove (bar
)
7570 struct scroll_bar
*bar
;
7572 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7576 /* Destroy the window. */
7577 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
7579 /* Disassociate this scroll bar from its window. */
7580 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7585 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7586 that we are displaying PORTION characters out of a total of WHOLE
7587 characters, starting at POSITION. If WINDOW has no scroll bar,
7590 w32_set_vertical_scroll_bar (w
, portion
, whole
, position
)
7592 int portion
, whole
, position
;
7594 struct frame
*f
= XFRAME (w
->frame
);
7595 struct scroll_bar
*bar
;
7596 int top
, height
, left
, sb_left
, width
, sb_width
;
7597 int window_x
, window_y
, window_width
, window_height
;
7599 /* Get window dimensions. */
7600 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7602 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7603 height
= window_height
;
7605 /* Compute the left edge of the scroll bar area. */
7606 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7607 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
7609 left
= XFASTINT (w
->left
);
7610 left
*= CANON_X_UNIT (f
);
7611 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
7613 /* Compute the width of the scroll bar which might be less than
7614 the width of the area reserved for the scroll bar. */
7615 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
7616 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
7620 /* Compute the left edge of the scroll bar. */
7621 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7622 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
7624 sb_left
= left
+ (width
- sb_width
) / 2;
7626 /* Does the scroll bar exist yet? */
7627 if (NILP (w
->vertical_scroll_bar
))
7631 hdc
= get_frame_dc (f
);
7632 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
7633 release_frame_dc (f
, hdc
);
7636 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
7640 /* It may just need to be moved and resized. */
7643 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
7644 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
7646 /* If already correctly positioned, do nothing. */
7647 if ( XINT (bar
->left
) == sb_left
7648 && XINT (bar
->top
) == top
7649 && XINT (bar
->width
) == sb_width
7650 && XINT (bar
->height
) == height
)
7652 /* Redraw after clear_frame. */
7653 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
7654 InvalidateRect (hwnd
, NULL
, FALSE
);
7661 hdc
= get_frame_dc (f
);
7662 /* Since Windows scroll bars are smaller than the space reserved
7663 for them on the frame, we have to clear "under" them. */
7664 w32_clear_area (f
, hdc
,
7669 release_frame_dc (f
, hdc
);
7671 /* Make sure scroll bar is "visible" before moving, to ensure the
7672 area of the parent window now exposed will be refreshed. */
7673 my_show_window (f
, hwnd
, SW_HIDE
);
7674 MoveWindow (hwnd
, sb_left
, top
,
7675 sb_width
, height
, TRUE
);
7676 if (pfnSetScrollInfo
)
7680 si
.cbSize
= sizeof (si
);
7681 si
.fMask
= SIF_RANGE
;
7683 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
7684 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7686 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
7689 SetScrollRange (hwnd
, SB_CTL
, 0,
7690 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
7691 my_show_window (f
, hwnd
, SW_NORMAL
);
7692 // InvalidateRect (w, NULL, FALSE);
7694 /* Remember new settings. */
7695 XSETINT (bar
->left
, sb_left
);
7696 XSETINT (bar
->top
, top
);
7697 XSETINT (bar
->width
, sb_width
);
7698 XSETINT (bar
->height
, height
);
7703 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
7705 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
7709 /* The following three hooks are used when we're doing a thorough
7710 redisplay of the frame. We don't explicitly know which scroll bars
7711 are going to be deleted, because keeping track of when windows go
7712 away is a real pain - "Can you say set-window-configuration, boys
7713 and girls?" Instead, we just assert at the beginning of redisplay
7714 that *all* scroll bars are to be removed, and then save a scroll bar
7715 from the fiery pit when we actually redisplay its window. */
7717 /* Arrange for all scroll bars on FRAME to be removed at the next call
7718 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
7719 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
7722 w32_condemn_scroll_bars (frame
)
7725 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
7726 while (! NILP (FRAME_SCROLL_BARS (frame
)))
7729 bar
= FRAME_SCROLL_BARS (frame
);
7730 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
7731 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
7732 XSCROLL_BAR (bar
)->prev
= Qnil
;
7733 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
7734 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
7735 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
7740 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
7741 Note that WINDOW isn't necessarily condemned at all. */
7744 w32_redeem_scroll_bar (window
)
7745 struct window
*window
;
7747 struct scroll_bar
*bar
;
7750 /* We can't redeem this window's scroll bar if it doesn't have one. */
7751 if (NILP (window
->vertical_scroll_bar
))
7754 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
7756 /* Unlink it from the condemned list. */
7757 f
= XFRAME (WINDOW_FRAME (window
));
7758 if (NILP (bar
->prev
))
7760 /* If the prev pointer is nil, it must be the first in one of
7762 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
7763 /* It's not condemned. Everything's fine. */
7765 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
7766 window
->vertical_scroll_bar
))
7767 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
7769 /* If its prev pointer is nil, it must be at the front of
7770 one or the other! */
7774 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
7776 if (! NILP (bar
->next
))
7777 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
7779 bar
->next
= FRAME_SCROLL_BARS (f
);
7781 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7782 if (! NILP (bar
->next
))
7783 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7786 /* Remove all scroll bars on FRAME that haven't been saved since the
7787 last call to `*condemn_scroll_bars_hook'. */
7790 w32_judge_scroll_bars (f
)
7793 Lisp_Object bar
, next
;
7795 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
7797 /* Clear out the condemned list now so we won't try to process any
7798 more events on the hapless scroll bars. */
7799 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
7801 for (; ! NILP (bar
); bar
= next
)
7803 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
7805 x_scroll_bar_remove (b
);
7808 b
->next
= b
->prev
= Qnil
;
7811 /* Now there should be no references to the condemned scroll bars,
7812 and they should get garbage-collected. */
7815 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
7816 is set to something other than no_event, it is enqueued.
7818 This may be called from a signal handler, so we have to ignore GC
7822 w32_scroll_bar_handle_click (bar
, msg
, emacs_event
)
7823 struct scroll_bar
*bar
;
7825 struct input_event
*emacs_event
;
7827 if (! GC_WINDOWP (bar
->window
))
7830 emacs_event
->kind
= w32_scroll_bar_click
;
7831 emacs_event
->code
= 0;
7832 /* not really meaningful to distinguish up/down */
7833 emacs_event
->modifiers
= msg
->dwModifiers
;
7834 emacs_event
->frame_or_window
= bar
->window
;
7835 emacs_event
->arg
= Qnil
;
7836 emacs_event
->timestamp
= msg
->msg
.time
;
7839 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7841 int dragging
= !NILP (bar
->dragging
);
7843 if (pfnGetScrollInfo
)
7847 si
.cbSize
= sizeof (si
);
7850 pfnGetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
7854 y
= GetScrollPos ((HWND
) msg
->msg
.lParam
, SB_CTL
);
7856 bar
->dragging
= Qnil
;
7859 last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
7861 switch (LOWORD (msg
->msg
.wParam
))
7864 emacs_event
->part
= scroll_bar_down_arrow
;
7867 emacs_event
->part
= scroll_bar_up_arrow
;
7870 emacs_event
->part
= scroll_bar_above_handle
;
7873 emacs_event
->part
= scroll_bar_below_handle
;
7876 emacs_event
->part
= scroll_bar_handle
;
7880 emacs_event
->part
= scroll_bar_handle
;
7884 case SB_THUMBPOSITION
:
7885 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
7886 y
= HIWORD (msg
->msg
.wParam
);
7888 emacs_event
->part
= scroll_bar_handle
;
7890 /* "Silently" update current position. */
7891 if (pfnSetScrollInfo
)
7895 si
.cbSize
= sizeof (si
);
7898 /* Remember apparent position (we actually lag behind the real
7899 position, so don't set that directly. */
7900 last_scroll_bar_drag_pos
= y
;
7902 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
7905 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, FALSE
);
7908 /* If this is the end of a drag sequence, then reset the scroll
7909 handle size to normal and do a final redraw. Otherwise do
7913 if (pfnSetScrollInfo
)
7916 int start
= XINT (bar
->start
);
7917 int end
= XINT (bar
->end
);
7919 si
.cbSize
= sizeof (si
);
7920 si
.fMask
= SIF_PAGE
| SIF_POS
;
7921 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7922 si
.nPos
= last_scroll_bar_drag_pos
;
7923 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
7926 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, TRUE
);
7930 emacs_event
->kind
= no_event
;
7934 XSETINT (emacs_event
->x
, y
);
7935 XSETINT (emacs_event
->y
, top_range
);
7941 /* Return information to the user about the current position of the mouse
7942 on the scroll bar. */
7945 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
7947 Lisp_Object
*bar_window
;
7948 enum scroll_bar_part
*part
;
7950 unsigned long *time
;
7952 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
7953 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7954 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7956 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7961 *bar_window
= bar
->window
;
7963 if (pfnGetScrollInfo
)
7967 si
.cbSize
= sizeof (si
);
7968 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
7970 pfnGetScrollInfo (w
, SB_CTL
, &si
);
7972 top_range
= si
.nMax
- si
.nPage
+ 1;
7975 pos
= GetScrollPos (w
, SB_CTL
);
7977 switch (LOWORD (last_mouse_scroll_bar_pos
))
7979 case SB_THUMBPOSITION
:
7981 *part
= scroll_bar_handle
;
7982 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
7983 pos
= HIWORD (last_mouse_scroll_bar_pos
);
7986 *part
= scroll_bar_handle
;
7990 *part
= scroll_bar_handle
;
7995 XSETINT (*y
, top_range
);
7998 last_mouse_scroll_bar
= Qnil
;
8000 *time
= last_mouse_movement_time
;
8006 /* The screen has been cleared so we may have changed foreground or
8007 background colors, and the scroll bars may need to be redrawn.
8008 Clear out the scroll bars, and ask for expose events, so we can
8012 x_scroll_bar_clear (f
)
8017 /* We can have scroll bars even if this is 0,
8018 if we just turned off scroll bar mode.
8019 But in that case we should not clear them. */
8020 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8021 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8022 bar
= XSCROLL_BAR (bar
)->next
)
8024 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
8025 HDC hdc
= GetDC (window
);
8028 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
8029 arranges to refresh the scroll bar if hidden. */
8030 my_show_window (f
, window
, SW_HIDE
);
8032 GetClientRect (window
, &rect
);
8033 select_palette (f
, hdc
);
8034 w32_clear_rect (f
, hdc
, &rect
);
8035 deselect_palette (f
, hdc
);
8037 ReleaseDC (window
, hdc
);
8042 /* The main W32 event-reading loop - w32_read_socket. */
8044 /* Time stamp of enter window event. This is only used by w32_read_socket,
8045 but we have to put it out here, since static variables within functions
8046 sometimes don't work. */
8048 static Time enter_timestamp
;
8050 /* Record the last 100 characters stored
8051 to help debug the loss-of-chars-during-GC problem. */
8053 static int temp_index
;
8054 static short temp_buffer
[100];
8057 /* Read events coming from the W32 shell.
8058 This routine is called by the SIGIO handler.
8059 We return as soon as there are no more events to be read.
8061 Events representing keys are stored in buffer BUFP,
8062 which can hold up to NUMCHARS characters.
8063 We return the number of characters stored into the buffer,
8064 thus pretending to be `read'.
8066 EXPECTED is nonzero if the caller knows input is available.
8068 Some of these messages are reposted back to the message queue since the
8069 system calls the windows proc directly in a context where we cannot return
8070 the data nor can we guarantee the state we are in. So if we dispatch them
8071 we will get into an infinite loop. To prevent this from ever happening we
8072 will set a variable to indicate we are in the read_socket call and indicate
8073 which message we are processing since the windows proc gets called
8074 recursively with different messages by the system.
8078 w32_read_socket (sd
, bufp
, numchars
, expected
)
8080 /* register */ struct input_event
*bufp
;
8081 /* register */ int numchars
;
8085 int check_visibility
= 0;
8088 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
8090 if (interrupt_input_blocked
)
8092 interrupt_input_pending
= 1;
8096 interrupt_input_pending
= 0;
8099 /* So people can tell when we have read the available input. */
8100 input_signal_count
++;
8103 abort (); /* Don't think this happens. */
8105 /* TODO: tooltips, tool-bars, ghostscript integration, mouse
8107 while (get_next_msg (&msg
, FALSE
))
8109 switch (msg
.msg
.message
)
8112 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8116 if (msg
.rect
.right
== msg
.rect
.left
||
8117 msg
.rect
.bottom
== msg
.rect
.top
)
8119 /* We may get paint messages even though the client
8120 area is clipped - these are not expose events. */
8121 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
8122 XSTRING (f
->name
)->data
));
8124 else if (f
->async_visible
!= 1)
8126 /* Definitely not obscured, so mark as visible. */
8127 f
->async_visible
= 1;
8128 f
->async_iconified
= 0;
8129 SET_FRAME_GARBAGED (f
);
8130 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
8131 XSTRING (f
->name
)->data
));
8133 /* WM_PAINT serves as MapNotify as well, so report
8134 visibility changes properly. */
8137 bufp
->kind
= deiconify_event
;
8138 XSETFRAME (bufp
->frame_or_window
, f
);
8144 else if (! NILP (Vframe_list
)
8145 && ! NILP (XCDR (Vframe_list
)))
8146 /* Force a redisplay sooner or later to update the
8147 frame titles in case this is the second frame. */
8148 record_asynch_buffer_change ();
8152 HDC hdc
= get_frame_dc (f
);
8154 /* Erase background again for safety. */
8155 w32_clear_rect (f
, hdc
, &msg
.rect
);
8156 release_frame_dc (f
, hdc
);
8160 msg
.rect
.right
- msg
.rect
.left
,
8161 msg
.rect
.bottom
- msg
.rect
.top
);
8166 case WM_INPUTLANGCHANGE
:
8167 /* Generate a language change event. */
8168 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8175 bufp
->kind
= language_change_event
;
8176 XSETFRAME (bufp
->frame_or_window
, f
);
8178 bufp
->code
= msg
.msg
.wParam
;
8179 bufp
->modifiers
= msg
.msg
.lParam
& 0xffff;
8188 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8190 if (f
&& !f
->iconified
)
8192 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8194 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8195 bufp
->kind
= non_ascii_keystroke
;
8196 bufp
->code
= msg
.msg
.wParam
;
8197 bufp
->modifiers
= msg
.dwModifiers
;
8198 XSETFRAME (bufp
->frame_or_window
, f
);
8200 bufp
->timestamp
= msg
.msg
.time
;
8209 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8211 if (f
&& !f
->iconified
)
8213 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8215 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8216 bufp
->kind
= ascii_keystroke
;
8217 bufp
->code
= msg
.msg
.wParam
;
8218 bufp
->modifiers
= msg
.dwModifiers
;
8219 XSETFRAME (bufp
->frame_or_window
, f
);
8221 bufp
->timestamp
= msg
.msg
.time
;
8229 previous_help_echo
= help_echo
;
8230 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
8233 if (dpyinfo
->grabbed
&& last_mouse_frame
8234 && FRAME_LIVE_P (last_mouse_frame
))
8235 f
= last_mouse_frame
;
8237 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8240 note_mouse_movement (f
, &msg
.msg
);
8243 /* If we move outside the frame, then we're
8244 certainly no longer on any text in the frame. */
8245 clear_mouse_face (dpyinfo
);
8248 /* If the contents of the global variable help_echo
8249 has changed, generate a HELP_EVENT. */
8250 if (!NILP (help_echo
)
8251 || !NILP (previous_help_echo
))
8257 XSETFRAME (frame
, f
);
8261 any_help_event_p
= 1;
8262 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
8263 help_echo_window
, help_echo_object
,
8265 bufp
+= n
, count
+= n
, numchars
-= n
;
8269 case WM_LBUTTONDOWN
:
8271 case WM_MBUTTONDOWN
:
8273 case WM_RBUTTONDOWN
:
8276 /* If we decide we want to generate an event to be seen
8277 by the rest of Emacs, we put it here. */
8278 struct input_event emacs_event
;
8283 emacs_event
.kind
= no_event
;
8285 if (dpyinfo
->grabbed
&& last_mouse_frame
8286 && FRAME_LIVE_P (last_mouse_frame
))
8287 f
= last_mouse_frame
;
8289 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8293 construct_mouse_click (&emacs_event
, &msg
, f
);
8295 /* Is this in the tool-bar? */
8296 if (WINDOWP (f
->tool_bar_window
)
8297 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
8303 window
= window_from_coordinates (f
,
8307 if (EQ (window
, f
->tool_bar_window
))
8309 w32_handle_tool_bar_click (f
, &emacs_event
);
8315 if (!dpyinfo
->w32_focus_frame
8316 || f
== dpyinfo
->w32_focus_frame
8319 construct_mouse_click (bufp
, &msg
, f
);
8326 parse_button (msg
.msg
.message
, &button
, &up
);
8330 dpyinfo
->grabbed
&= ~ (1 << button
);
8334 dpyinfo
->grabbed
|= (1 << button
);
8335 last_mouse_frame
= f
;
8336 /* Ignore any mouse motion that happened
8337 before this event; any subsequent mouse-movement
8338 Emacs events should reflect only motion after
8344 last_tool_bar_item
= -1;
8350 if (dpyinfo
->grabbed
&& last_mouse_frame
8351 && FRAME_LIVE_P (last_mouse_frame
))
8352 f
= last_mouse_frame
;
8354 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8358 if ((!dpyinfo
->w32_focus_frame
8359 || f
== dpyinfo
->w32_focus_frame
)
8362 construct_mouse_wheel (bufp
, &msg
, f
);
8372 HMENU menu
= (HMENU
) msg
.msg
.lParam
;
8373 UINT menu_item
= (UINT
) LOWORD (msg
.msg
.wParam
);
8374 UINT flags
= (UINT
) HIWORD (msg
.msg
.wParam
);
8376 w32_menu_display_help (menu
, menu_item
, flags
);
8381 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8385 construct_drag_n_drop (bufp
, &msg
, f
);
8394 struct scroll_bar
*bar
=
8395 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
);
8397 if (bar
&& numchars
>= 1)
8399 if (w32_scroll_bar_handle_click (bar
, &msg
, bufp
))
8409 case WM_WINDOWPOSCHANGED
:
8411 case WM_ACTIVATEAPP
:
8412 check_visibility
= 1;
8416 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8418 if (f
&& !f
->async_iconified
)
8422 x_real_positions (f
, &x
, &y
);
8423 f
->output_data
.w32
->left_pos
= x
;
8424 f
->output_data
.w32
->top_pos
= y
;
8427 check_visibility
= 1;
8431 /* If window has been obscured or exposed by another window
8432 being maximised or minimised/restored, then recheck
8433 visibility of all frames. Direct changes to our own
8434 windows get handled by WM_SIZE. */
8436 if (msg
.msg
.lParam
!= 0)
8437 check_visibility
= 1;
8440 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8441 f
->async_visible
= msg
.msg
.wParam
;
8445 check_visibility
= 1;
8449 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8451 /* Inform lisp of whether frame has been iconified etc. */
8454 switch (msg
.msg
.wParam
)
8456 case SIZE_MINIMIZED
:
8457 f
->async_visible
= 0;
8458 f
->async_iconified
= 1;
8460 bufp
->kind
= iconify_event
;
8461 XSETFRAME (bufp
->frame_or_window
, f
);
8468 case SIZE_MAXIMIZED
:
8470 f
->async_visible
= 1;
8471 f
->async_iconified
= 0;
8473 /* wait_reading_process_input will notice this and update
8474 the frame's display structures. */
8475 SET_FRAME_GARBAGED (f
);
8481 /* Reset top and left positions of the Window
8482 here since Windows sends a WM_MOVE message
8483 BEFORE telling us the Window is minimized
8484 when the Window is iconified, with 3000,3000
8486 x_real_positions (f
, &x
, &y
);
8487 f
->output_data
.w32
->left_pos
= x
;
8488 f
->output_data
.w32
->top_pos
= y
;
8490 bufp
->kind
= deiconify_event
;
8491 XSETFRAME (bufp
->frame_or_window
, f
);
8497 else if (! NILP (Vframe_list
)
8498 && ! NILP (XCDR (Vframe_list
)))
8499 /* Force a redisplay sooner or later
8500 to update the frame titles
8501 in case this is the second frame. */
8502 record_asynch_buffer_change ();
8507 if (f
&& !f
->async_iconified
&& msg
.msg
.wParam
!= SIZE_MINIMIZED
)
8515 GetClientRect (msg
.msg
.hwnd
, &rect
);
8517 height
= rect
.bottom
- rect
.top
;
8518 width
= rect
.right
- rect
.left
;
8520 rows
= PIXEL_TO_CHAR_HEIGHT (f
, height
);
8521 columns
= PIXEL_TO_CHAR_WIDTH (f
, width
);
8523 /* TODO: Clip size to the screen dimensions. */
8525 /* Even if the number of character rows and columns has
8526 not changed, the font size may have changed, so we need
8527 to check the pixel dimensions as well. */
8529 if (columns
!= f
->width
8530 || rows
!= f
->height
8531 || width
!= f
->output_data
.w32
->pixel_width
8532 || height
!= f
->output_data
.w32
->pixel_height
)
8534 change_frame_size (f
, rows
, columns
, 0, 1, 0);
8535 SET_FRAME_GARBAGED (f
);
8536 cancel_mouse_face (f
);
8537 f
->output_data
.w32
->pixel_width
= width
;
8538 f
->output_data
.w32
->pixel_height
= height
;
8539 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
8543 check_visibility
= 1;
8547 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8549 dpyinfo
->w32_focus_event_frame
= f
;
8552 x_new_focus_frame (dpyinfo
, f
);
8555 dpyinfo
->grabbed
= 0;
8556 check_visibility
= 1;
8560 /* TODO: some of this belongs in MOUSE_LEAVE */
8561 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8565 if (f
== dpyinfo
->w32_focus_event_frame
)
8566 dpyinfo
->w32_focus_event_frame
= 0;
8568 if (f
== dpyinfo
->w32_focus_frame
)
8569 x_new_focus_frame (dpyinfo
, 0);
8571 if (f
== dpyinfo
->mouse_face_mouse_frame
)
8573 /* If we move outside the frame, then we're
8574 certainly no longer on any text in the frame. */
8575 clear_mouse_face (dpyinfo
);
8576 dpyinfo
->mouse_face_mouse_frame
= 0;
8579 /* Generate a nil HELP_EVENT to cancel a help-echo.
8580 Do it only if there's something to cancel.
8581 Otherwise, the startup message is cleared when
8582 the mouse leaves the frame. */
8583 if (any_help_event_p
)
8588 XSETFRAME (frame
, f
);
8590 n
= gen_help_event (bufp
, numchars
,
8591 Qnil
, frame
, Qnil
, Qnil
, 0);
8592 bufp
+= n
, count
+= n
, numchars
-=n
;
8596 dpyinfo
->grabbed
= 0;
8597 check_visibility
= 1;
8601 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8608 bufp
->kind
= delete_window_event
;
8609 XSETFRAME (bufp
->frame_or_window
, f
);
8618 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8625 bufp
->kind
= menu_bar_activate_event
;
8626 XSETFRAME (bufp
->frame_or_window
, f
);
8635 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8639 extern void menubar_selection_callback
8640 (FRAME_PTR f
, void * client_data
);
8641 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
8644 check_visibility
= 1;
8647 case WM_DISPLAYCHANGE
:
8648 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8652 dpyinfo
->width
= (short) LOWORD (msg
.msg
.lParam
);
8653 dpyinfo
->height
= (short) HIWORD (msg
.msg
.lParam
);
8654 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
8655 DebPrint (("display change: %d %d\n", dpyinfo
->width
,
8659 check_visibility
= 1;
8663 /* Check for messages registered at runtime. */
8664 if (msg
.msg
.message
== msh_mousewheel
)
8666 if (dpyinfo
->grabbed
&& last_mouse_frame
8667 && FRAME_LIVE_P (last_mouse_frame
))
8668 f
= last_mouse_frame
;
8670 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8674 if ((!dpyinfo
->w32_focus_frame
8675 || f
== dpyinfo
->w32_focus_frame
)
8678 construct_mouse_wheel (bufp
, &msg
, f
);
8689 /* If the focus was just given to an autoraising frame,
8691 /* ??? This ought to be able to handle more than one such frame. */
8692 if (pending_autoraise_frame
)
8694 x_raise_frame (pending_autoraise_frame
);
8695 pending_autoraise_frame
= 0;
8698 /* Check which frames are still visisble, if we have enqueued any user
8699 events or been notified of events that may affect visibility. We
8700 do this here because there doesn't seem to be any direct
8701 notification from Windows that the visibility of a window has
8702 changed (at least, not in all cases). */
8703 if (count
> 0 || check_visibility
)
8705 Lisp_Object tail
, frame
;
8707 FOR_EACH_FRAME (tail
, frame
)
8709 FRAME_PTR f
= XFRAME (frame
);
8710 /* Check "visible" frames and mark each as obscured or not.
8711 Note that async_visible is nonzero for unobscured and
8712 obscured frames, but zero for hidden and iconified frames. */
8713 if (FRAME_W32_P (f
) && f
->async_visible
)
8716 HDC hdc
= get_frame_dc (f
);
8717 GetClipBox (hdc
, &clipbox
);
8718 release_frame_dc (f
, hdc
);
8720 if (clipbox
.right
== clipbox
.left
8721 || clipbox
.bottom
== clipbox
.top
)
8723 /* Frame has become completely obscured so mark as
8724 such (we do this by setting async_visible to 2 so
8725 that FRAME_VISIBLE_P is still true, but redisplay
8727 f
->async_visible
= 2;
8729 if (!FRAME_OBSCURED_P (f
))
8731 DebPrint (("frame %p (%s) obscured\n", f
,
8732 XSTRING (f
->name
)->data
));
8737 /* Frame is not obscured, so mark it as such. */
8738 f
->async_visible
= 1;
8740 if (FRAME_OBSCURED_P (f
))
8742 SET_FRAME_GARBAGED (f
);
8743 DebPrint (("obscured frame %p (%s) found to be visible\n", f
,
8744 XSTRING (f
->name
)->data
));
8746 /* Force a redisplay sooner or later. */
8747 record_asynch_buffer_change ();
8761 /***********************************************************************
8763 ***********************************************************************/
8765 /* Note if the text cursor of window W has been overwritten by a
8766 drawing operation that outputs N glyphs starting at HPOS in the
8767 line given by output_cursor.vpos. N < 0 means all the rest of the
8768 line after HPOS has been written. */
8771 note_overwritten_text_cursor (w
, hpos
, n
)
8775 if (updated_area
== TEXT_AREA
8776 && output_cursor
.vpos
== w
->phys_cursor
.vpos
8777 && hpos
<= w
->phys_cursor
.hpos
8779 || hpos
+ n
> w
->phys_cursor
.hpos
))
8780 w
->phys_cursor_on_p
= 0;
8784 /* Set clipping for output in glyph row ROW. W is the window in which
8785 we operate. GC is the graphics context to set clipping in.
8786 WHOLE_LINE_P non-zero means include the areas used for truncation
8787 mark display and alike in the clipping rectangle.
8789 ROW may be a text row or, e.g., a mode line. Text rows must be
8790 clipped to the interior of the window dedicated to text display,
8791 mode lines must be clipped to the whole window. */
8794 w32_clip_to_row (w
, row
, hdc
, whole_line_p
)
8796 struct glyph_row
*row
;
8800 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8802 int window_x
, window_y
, window_width
, window_height
;
8804 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8806 clip_rect
.left
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
8807 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8808 clip_rect
.top
= max (clip_rect
.top
, window_y
);
8809 clip_rect
.right
= clip_rect
.left
+ window_width
;
8810 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
8812 /* If clipping to the whole line, including trunc marks, extend
8813 the rectangle to the left and increase its width. */
8816 clip_rect
.left
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
8817 clip_rect
.right
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
8820 w32_set_clip_rectangle (hdc
, &clip_rect
);
8824 /* Draw a hollow box cursor on window W in glyph row ROW. */
8827 x_draw_hollow_cursor (w
, row
)
8829 struct glyph_row
*row
;
8831 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8835 struct glyph
*cursor_glyph
;
8836 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
8838 /* Compute frame-relative coordinates from window-relative
8840 rect
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8841 rect
.top
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
8842 + row
->ascent
- w
->phys_cursor_ascent
);
8843 rect
.bottom
= rect
.top
+ row
->height
- 1;
8845 /* Get the glyph the cursor is on. If we can't tell because
8846 the current matrix is invalid or such, give up. */
8847 cursor_glyph
= get_phys_cursor_glyph (w
);
8848 if (cursor_glyph
== NULL
)
8851 /* Compute the width of the rectangle to draw. If on a stretch
8852 glyph, and `x-stretch-block-cursor' is nil, don't draw a
8853 rectangle as wide as the glyph, but use a canonical character
8855 wd
= cursor_glyph
->pixel_width
- 1;
8856 if (cursor_glyph
->type
== STRETCH_GLYPH
8857 && !x_stretch_cursor_p
)
8858 wd
= min (CANON_X_UNIT (f
), wd
);
8860 rect
.right
= rect
.left
+ wd
;
8861 hdc
= get_frame_dc (f
);
8862 FrameRect (hdc
, &rect
, hb
);
8865 release_frame_dc (f
, hdc
);
8869 /* Draw a bar cursor on window W in glyph row ROW.
8871 Implementation note: One would like to draw a bar cursor with an
8872 angle equal to the one given by the font property XA_ITALIC_ANGLE.
8873 Unfortunately, I didn't find a font yet that has this property set.
8877 x_draw_bar_cursor (w
, row
, width
)
8879 struct glyph_row
*row
;
8882 struct frame
*f
= XFRAME (w
->frame
);
8883 struct glyph
*cursor_glyph
;
8887 /* If cursor is out of bounds, don't draw garbage. This can happen
8888 in mini-buffer windows when switching between echo area glyphs
8890 cursor_glyph
= get_phys_cursor_glyph (w
);
8891 if (cursor_glyph
== NULL
)
8894 /* If on an image, draw like a normal cursor. That's usually better
8895 visible than drawing a bar, esp. if the image is large so that
8896 the bar might not be in the window. */
8897 if (cursor_glyph
->type
== IMAGE_GLYPH
)
8899 struct glyph_row
*row
;
8900 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
8901 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
8906 width
= f
->output_data
.w32
->cursor_width
;
8908 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8909 hdc
= get_frame_dc (f
);
8910 w32_clip_to_row (w
, row
, hdc
, 0);
8911 w32_fill_area (f
, hdc
, f
->output_data
.w32
->cursor_pixel
,
8913 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
8914 min (cursor_glyph
->pixel_width
, width
),
8916 release_frame_dc (f
, hdc
);
8921 /* Clear the cursor of window W to background color, and mark the
8922 cursor as not shown. This is used when the text where the cursor
8923 is is about to be rewritten. */
8929 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
8930 x_update_window_cursor (w
, 0);
8934 /* Draw the cursor glyph of window W in glyph row ROW. See the
8935 comment of x_draw_glyphs for the meaning of HL. */
8938 x_draw_phys_cursor_glyph (w
, row
, hl
)
8940 struct glyph_row
*row
;
8941 enum draw_glyphs_face hl
;
8943 /* If cursor hpos is out of bounds, don't draw garbage. This can
8944 happen in mini-buffer windows when switching between echo area
8945 glyphs and mini-buffer. */
8946 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
8948 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
8949 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
8952 /* When we erase the cursor, and ROW is overlapped by other
8953 rows, make sure that these overlapping parts of other rows
8955 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
8957 if (row
> w
->current_matrix
->rows
8958 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
8959 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
8961 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
8962 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
8963 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
8969 /* Erase the image of a cursor of window W from the screen. */
8972 x_erase_phys_cursor (w
)
8975 struct frame
*f
= XFRAME (w
->frame
);
8976 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
8977 int hpos
= w
->phys_cursor
.hpos
;
8978 int vpos
= w
->phys_cursor
.vpos
;
8979 int mouse_face_here_p
= 0;
8980 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
8981 struct glyph_row
*cursor_row
;
8982 struct glyph
*cursor_glyph
;
8983 enum draw_glyphs_face hl
;
8985 /* No cursor displayed or row invalidated => nothing to do on the
8987 if (w
->phys_cursor_type
== NO_CURSOR
)
8988 goto mark_cursor_off
;
8990 /* VPOS >= active_glyphs->nrows means that window has been resized.
8991 Don't bother to erase the cursor. */
8992 if (vpos
>= active_glyphs
->nrows
)
8993 goto mark_cursor_off
;
8995 /* If row containing cursor is marked invalid, there is nothing we
8997 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
8998 if (!cursor_row
->enabled_p
)
8999 goto mark_cursor_off
;
9001 /* This can happen when the new row is shorter than the old one.
9002 In this case, either x_draw_glyphs or clear_end_of_line
9003 should have cleared the cursor. Note that we wouldn't be
9004 able to erase the cursor in this case because we don't have a
9005 cursor glyph at hand. */
9006 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9007 goto mark_cursor_off
;
9009 /* If the cursor is in the mouse face area, redisplay that when
9010 we clear the cursor. */
9011 if (! NILP (dpyinfo
->mouse_face_window
)
9012 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9013 && (vpos
> dpyinfo
->mouse_face_beg_row
9014 || (vpos
== dpyinfo
->mouse_face_beg_row
9015 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9016 && (vpos
< dpyinfo
->mouse_face_end_row
9017 || (vpos
== dpyinfo
->mouse_face_end_row
9018 && hpos
< dpyinfo
->mouse_face_end_col
))
9019 /* Don't redraw the cursor's spot in mouse face if it is at the
9020 end of a line (on a newline). The cursor appears there, but
9021 mouse highlighting does not. */
9022 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9023 mouse_face_here_p
= 1;
9025 /* Maybe clear the display under the cursor. */
9026 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9029 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9032 cursor_glyph
= get_phys_cursor_glyph (w
);
9033 if (cursor_glyph
== NULL
)
9034 goto mark_cursor_off
;
9036 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9038 hdc
= get_frame_dc (f
);
9039 w32_clear_area (f
, hdc
, x
,
9040 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9042 cursor_glyph
->pixel_width
,
9043 cursor_row
->visible_height
);
9044 release_frame_dc (f
, hdc
);
9047 /* Erase the cursor by redrawing the character underneath it. */
9048 if (mouse_face_here_p
)
9049 hl
= DRAW_MOUSE_FACE
;
9050 else if (cursor_row
->inverse_p
)
9051 hl
= DRAW_INVERSE_VIDEO
;
9053 hl
= DRAW_NORMAL_TEXT
;
9054 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9057 w
->phys_cursor_on_p
= 0;
9058 w
->phys_cursor_type
= NO_CURSOR
;
9062 /* Display or clear cursor of window W. If ON is zero, clear the
9063 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9064 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9067 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9069 int on
, hpos
, vpos
, x
, y
;
9071 struct frame
*f
= XFRAME (w
->frame
);
9072 int new_cursor_type
;
9073 int new_cursor_width
;
9074 struct glyph_matrix
*current_glyphs
;
9075 struct glyph_row
*glyph_row
;
9076 struct glyph
*glyph
;
9078 /* This is pointless on invisible frames, and dangerous on garbaged
9079 windows and frames; in the latter case, the frame or window may
9080 be in the midst of changing its size, and x and y may be off the
9082 if (! FRAME_VISIBLE_P (f
)
9083 || FRAME_GARBAGED_P (f
)
9084 || vpos
>= w
->current_matrix
->nrows
9085 || hpos
>= w
->current_matrix
->matrix_w
)
9088 /* If cursor is off and we want it off, return quickly. */
9089 if (!on
&& !w
->phys_cursor_on_p
)
9092 current_glyphs
= w
->current_matrix
;
9093 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9094 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9096 /* If cursor row is not enabled, we don't really know where to
9097 display the cursor. */
9098 if (!glyph_row
->enabled_p
)
9100 w
->phys_cursor_on_p
= 0;
9104 xassert (interrupt_input_blocked
);
9106 /* Set new_cursor_type to the cursor we want to be displayed. In a
9107 mini-buffer window, we want the cursor only to appear if we are
9108 reading input from this window. For the selected window, we want
9109 the cursor type given by the frame parameter. If explicitly
9110 marked off, draw no cursor. In all other cases, we want a hollow
9112 new_cursor_width
= -1;
9113 if (cursor_in_echo_area
9114 && FRAME_HAS_MINIBUF_P (f
)
9115 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
9117 if (w
== XWINDOW (echo_area_window
))
9118 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9120 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9124 if (f
!= FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
9125 || w
!= XWINDOW (f
->selected_window
))
9127 extern int cursor_in_non_selected_windows
;
9129 if (MINI_WINDOW_P (w
)
9130 || !cursor_in_non_selected_windows
9131 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
9132 new_cursor_type
= NO_CURSOR
;
9134 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9136 else if (w
->cursor_off_p
)
9137 new_cursor_type
= NO_CURSOR
;
9140 struct buffer
*b
= XBUFFER (w
->buffer
);
9142 if (EQ (b
->cursor_type
, Qt
))
9143 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9145 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
9150 /* If cursor is currently being shown and we don't want it to be or
9151 it is in the wrong place, or the cursor type is not what we want,
9153 if (w
->phys_cursor_on_p
9155 || w
->phys_cursor
.x
!= x
9156 || w
->phys_cursor
.y
!= y
9157 || new_cursor_type
!= w
->phys_cursor_type
))
9158 x_erase_phys_cursor (w
);
9160 /* If the cursor is now invisible and we want it to be visible,
9162 if (on
&& !w
->phys_cursor_on_p
)
9164 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9165 w
->phys_cursor_height
= glyph_row
->height
;
9167 /* Set phys_cursor_.* before x_draw_.* is called because some
9168 of them may need the information. */
9169 w
->phys_cursor
.x
= x
;
9170 w
->phys_cursor
.y
= glyph_row
->y
;
9171 w
->phys_cursor
.hpos
= hpos
;
9172 w
->phys_cursor
.vpos
= vpos
;
9173 w
->phys_cursor_type
= new_cursor_type
;
9174 w
->phys_cursor_on_p
= 1;
9176 switch (new_cursor_type
)
9178 case HOLLOW_BOX_CURSOR
:
9179 x_draw_hollow_cursor (w
, glyph_row
);
9182 case FILLED_BOX_CURSOR
:
9183 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9187 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
9200 /* Display the cursor on window W, or clear it. X and Y are window
9201 relative pixel coordinates. HPOS and VPOS are glyph matrix
9202 positions. If W is not the selected window, display a hollow
9203 cursor. ON non-zero means display the cursor at X, Y which
9204 correspond to HPOS, VPOS, otherwise it is cleared. */
9207 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9209 int on
, hpos
, vpos
, x
, y
;
9212 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9217 /* Display the cursor on window W, or clear it, according to ON_P.
9218 Don't change the cursor's position. */
9221 x_update_cursor (f
, on_p
)
9225 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9229 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9230 in the window tree rooted at W. */
9233 x_update_cursor_in_window_tree (w
, on_p
)
9239 if (!NILP (w
->hchild
))
9240 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9241 else if (!NILP (w
->vchild
))
9242 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9244 x_update_window_cursor (w
, on_p
);
9246 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9251 /* Switch the display of W's cursor on or off, according to the value
9255 x_update_window_cursor (w
, on
)
9259 /* Don't update cursor in windows whose frame is in the process
9260 of being deleted. */
9261 if (w
->current_matrix
)
9264 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
,
9265 w
->phys_cursor
.vpos
, w
->phys_cursor
.x
,
9277 x_bitmap_icon (f
, icon
)
9283 if (FRAME_W32_WINDOW (f
) == 0)
9287 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
9288 else if (STRINGP (icon
))
9289 hicon
= LoadImage (NULL
, (LPCTSTR
) XSTRING (icon
)->data
, IMAGE_ICON
, 0, 0,
9290 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
9291 else if (SYMBOLP (icon
))
9295 if (EQ (icon
, intern ("application")))
9296 name
= (LPCTSTR
) IDI_APPLICATION
;
9297 else if (EQ (icon
, intern ("hand")))
9298 name
= (LPCTSTR
) IDI_HAND
;
9299 else if (EQ (icon
, intern ("question")))
9300 name
= (LPCTSTR
) IDI_QUESTION
;
9301 else if (EQ (icon
, intern ("exclamation")))
9302 name
= (LPCTSTR
) IDI_EXCLAMATION
;
9303 else if (EQ (icon
, intern ("asterisk")))
9304 name
= (LPCTSTR
) IDI_ASTERISK
;
9305 else if (EQ (icon
, intern ("winlogo")))
9306 name
= (LPCTSTR
) IDI_WINLOGO
;
9310 hicon
= LoadIcon (NULL
, name
);
9318 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
9325 /************************************************************************
9327 ************************************************************************/
9329 /* Display Error Handling functions not used on W32. Listing them here
9330 helps diff stay in step when comparing w32term.c with xterm.c.
9332 x_error_catcher (display, error)
9333 x_catch_errors (dpy)
9334 x_catch_errors_unwind (old_val)
9335 x_check_errors (dpy, format)
9336 x_had_errors_p (dpy)
9337 x_clear_errors (dpy)
9338 x_uncatch_errors (dpy, count)
9340 x_connection_signal (signalnum)
9341 x_connection_closed (dpy, error_message)
9342 x_error_quitter (display, error)
9343 x_error_handler (display, error)
9344 x_io_error_quitter (display)
9349 /* Changing the font of the frame. */
9351 /* Give frame F the font named FONTNAME as its default font, and
9352 return the full name of that font. FONTNAME may be a wildcard
9353 pattern; in that case, we choose some font that fits the pattern.
9354 The return value shows which font we chose. */
9357 x_new_font (f
, fontname
)
9359 register char *fontname
;
9361 struct font_info
*fontp
9362 = FS_LOAD_FONT (f
, 0, fontname
, -1);
9367 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
9368 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
9369 FRAME_FONTSET (f
) = -1;
9371 /* Compute the scroll bar width in character columns. */
9372 if (f
->scroll_bar_pixel_width
> 0)
9374 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9375 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
9379 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9380 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
9383 /* Now make the frame display the given font. */
9384 if (FRAME_W32_WINDOW (f
) != 0)
9386 frame_update_line_height (f
);
9387 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9388 x_set_window_size (f
, 0, f
->width
, f
->height
);
9391 /* If we are setting a new frame's font for the first time,
9392 there are no faces yet, so this font's height is the line height. */
9393 f
->output_data
.w32
->line_height
= FONT_HEIGHT (FRAME_FONT (f
));
9395 return build_string (fontp
->full_name
);
9398 /* Give frame F the fontset named FONTSETNAME as its default font, and
9399 return the full name of that fontset. FONTSETNAME may be a wildcard
9400 pattern; in that case, we choose some fontset that fits the pattern.
9401 The return value shows which fontset we chose. */
9404 x_new_fontset (f
, fontsetname
)
9408 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
9414 if (FRAME_FONTSET (f
) == fontset
)
9415 /* This fontset is already set in frame F. There's nothing more
9417 return fontset_name (fontset
);
9419 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
9421 if (!STRINGP (result
))
9422 /* Can't load ASCII font. */
9425 /* Since x_new_font doesn't update any fontset information, do it now. */
9426 FRAME_FONTSET(f
) = fontset
;
9428 return build_string (fontsetname
);
9432 /***********************************************************************
9433 TODO: W32 Input Methods
9434 ***********************************************************************/
9435 /* Listing missing functions from xterm.c helps diff stay in step.
9437 xim_destroy_callback (xim, client_data, call_data)
9438 xim_open_dpy (dpyinfo, resource_name)
9440 xim_instantiate_callback (display, client_data, call_data)
9441 xim_initialize (dpyinfo, resource_name)
9442 xim_close_dpy (dpyinfo)
9447 /* Calculate the absolute position in frame F
9448 from its current recorded position values and gravity. */
9451 x_calc_absolute_position (f
)
9455 int flags
= f
->output_data
.w32
->size_hint_flags
;
9459 /* Find the position of the outside upper-left corner of
9460 the inner window, with respect to the outer window.
9461 But do this only if we will need the results. */
9462 if (f
->output_data
.w32
->parent_desc
!= FRAME_W32_DISPLAY_INFO (f
)->root_window
)
9465 MapWindowPoints (FRAME_W32_WINDOW (f
),
9466 f
->output_data
.w32
->parent_desc
,
9473 rt
.left
= rt
.right
= rt
.top
= rt
.bottom
= 0;
9476 AdjustWindowRect(&rt
, f
->output_data
.w32
->dwStyle
,
9477 FRAME_EXTERNAL_MENU_BAR (f
));
9480 pt
.x
+= (rt
.right
- rt
.left
);
9481 pt
.y
+= (rt
.bottom
- rt
.top
);
9484 /* Treat negative positions as relative to the leftmost bottommost
9485 position that fits on the screen. */
9486 if (flags
& XNegative
)
9487 f
->output_data
.w32
->left_pos
= (FRAME_W32_DISPLAY_INFO (f
)->width
9488 - 2 * f
->output_data
.w32
->border_width
- pt
.x
9490 + f
->output_data
.w32
->left_pos
);
9492 if (flags
& YNegative
)
9493 f
->output_data
.w32
->top_pos
= (FRAME_W32_DISPLAY_INFO (f
)->height
9494 - 2 * f
->output_data
.w32
->border_width
- pt
.y
9496 + f
->output_data
.w32
->top_pos
);
9497 /* The left_pos and top_pos
9498 are now relative to the top and left screen edges,
9499 so the flags should correspond. */
9500 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9503 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
9504 to really change the position, and 0 when calling from
9505 x_make_frame_visible (in that case, XOFF and YOFF are the current
9506 position values). It is -1 when calling from x_set_frame_parameters,
9507 which means, do adjust for borders but don't change the gravity. */
9510 x_set_offset (f
, xoff
, yoff
, change_gravity
)
9512 register int xoff
, yoff
;
9515 int modified_top
, modified_left
;
9517 if (change_gravity
> 0)
9519 f
->output_data
.w32
->top_pos
= yoff
;
9520 f
->output_data
.w32
->left_pos
= xoff
;
9521 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9523 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
9525 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
9526 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
9528 x_calc_absolute_position (f
);
9531 x_wm_set_size_hint (f
, (long) 0, 0);
9533 modified_left
= f
->output_data
.w32
->left_pos
;
9534 modified_top
= f
->output_data
.w32
->top_pos
;
9536 my_set_window_pos (FRAME_W32_WINDOW (f
),
9538 modified_left
, modified_top
,
9540 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
9544 /* Call this to change the size of frame F's x-window.
9545 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9546 for this size change and subsequent size changes.
9547 Otherwise we leave the window gravity unchanged. */
9550 x_set_window_size (f
, change_gravity
, cols
, rows
)
9555 int pixelwidth
, pixelheight
;
9559 check_frame_size (f
, &rows
, &cols
);
9560 f
->output_data
.w32
->vertical_scroll_bar_extra
9561 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9563 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
9564 f
->output_data
.w32
->flags_areas_extra
9565 = FRAME_FLAGS_AREA_WIDTH (f
);
9566 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
9567 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
9569 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
9570 x_wm_set_size_hint (f
, (long) 0, 0);
9575 rect
.left
= rect
.top
= 0;
9576 rect
.right
= pixelwidth
;
9577 rect
.bottom
= pixelheight
;
9579 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
,
9580 FRAME_EXTERNAL_MENU_BAR (f
));
9582 my_set_window_pos (FRAME_W32_WINDOW (f
),
9585 rect
.right
- rect
.left
,
9586 rect
.bottom
- rect
.top
,
9587 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9590 /* Now, strictly speaking, we can't be sure that this is accurate,
9591 but the window manager will get around to dealing with the size
9592 change request eventually, and we'll hear how it went when the
9593 ConfigureNotify event gets here.
9595 We could just not bother storing any of this information here,
9596 and let the ConfigureNotify event set everything up, but that
9597 might be kind of confusing to the Lisp code, since size changes
9598 wouldn't be reported in the frame parameters until some random
9599 point in the future when the ConfigureNotify event arrives.
9601 We pass 1 for DELAY since we can't run Lisp code inside of
9603 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9604 PIXEL_WIDTH (f
) = pixelwidth
;
9605 PIXEL_HEIGHT (f
) = pixelheight
;
9607 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9608 receive in the ConfigureNotify event; if we get what we asked
9609 for, then the event won't cause the screen to become garbaged, so
9610 we have to make sure to do it here. */
9611 SET_FRAME_GARBAGED (f
);
9613 /* If cursor was outside the new size, mark it as off. */
9614 mark_window_cursors_off (XWINDOW (f
->root_window
));
9616 /* Clear out any recollection of where the mouse highlighting was,
9617 since it might be in a place that's outside the new frame size.
9618 Actually checking whether it is outside is a pain in the neck,
9619 so don't try--just let the highlighting be done afresh with new size. */
9620 cancel_mouse_face (f
);
9625 /* Mouse warping. */
9627 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
9630 x_set_mouse_position (f
, x
, y
)
9636 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.w32
->font
) / 2;
9637 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.w32
->line_height
/ 2;
9639 if (pix_x
< 0) pix_x
= 0;
9640 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
9642 if (pix_y
< 0) pix_y
= 0;
9643 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
9645 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
9649 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9658 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
9659 pt
.x
= rect
.left
+ pix_x
;
9660 pt
.y
= rect
.top
+ pix_y
;
9661 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
9663 SetCursorPos (pt
.x
, pt
.y
);
9669 /* focus shifting, raising and lowering. */
9672 x_focus_on_frame (f
)
9675 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
9677 /* Give input focus to frame. */
9680 /* Try not to change its Z-order if possible. */
9681 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
9682 my_set_focus (f
, FRAME_W32_WINDOW (f
));
9685 my_set_foreground_window (FRAME_W32_WINDOW (f
));
9695 /* Raise frame F. */
9702 /* Strictly speaking, raise-frame should only change the frame's Z
9703 order, leaving input focus unchanged. This is reasonable behaviour
9704 on X where the usual policy is point-to-focus. However, this
9705 behaviour would be very odd on Windows where the usual policy is
9708 On X, if the mouse happens to be over the raised frame, it gets
9709 input focus anyway (so the window with focus will never be
9710 completely obscured) - if not, then just moving the mouse over it
9711 is sufficient to give it focus. On Windows, the user must actually
9712 click on the frame (preferrably the title bar so as not to move
9713 point), which is more awkward. Also, no other Windows program
9714 raises a window to the top but leaves another window (possibly now
9715 completely obscured) with input focus.
9717 Because there is a system setting on Windows that allows the user
9718 to choose the point to focus policy, we make the strict semantics
9719 optional, but by default we grab focus when raising. */
9721 if (NILP (Vw32_grab_focus_on_raise
))
9723 /* The obvious call to my_set_window_pos doesn't work if Emacs is
9724 not already the foreground application: the frame is raised
9725 above all other frames belonging to us, but not above the
9726 current top window. To achieve that, we have to resort to this
9727 more cumbersome method. */
9729 HDWP handle
= BeginDeferWindowPos (2);
9732 DeferWindowPos (handle
,
9733 FRAME_W32_WINDOW (f
),
9736 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9738 DeferWindowPos (handle
,
9739 GetForegroundWindow (),
9740 FRAME_W32_WINDOW (f
),
9742 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9744 EndDeferWindowPos (handle
);
9749 my_set_foreground_window (FRAME_W32_WINDOW (f
));
9755 /* Lower frame F. */
9761 my_set_window_pos (FRAME_W32_WINDOW (f
),
9764 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9769 w32_frame_raise_lower (f
, raise_flag
)
9773 if (! FRAME_W32_P (f
))
9782 /* Change of visibility. */
9784 /* This tries to wait until the frame is really visible.
9785 However, if the window manager asks the user where to position
9786 the frame, this will return before the user finishes doing that.
9787 The frame will not actually be visible at that time,
9788 but it will become visible later when the window manager
9789 finishes with it. */
9792 x_make_frame_visible (f
)
9799 type
= x_icon_type (f
);
9801 x_bitmap_icon (f
, type
);
9803 if (! FRAME_VISIBLE_P (f
))
9805 /* We test FRAME_GARBAGED_P here to make sure we don't
9806 call x_set_offset a second time
9807 if we get to x_make_frame_visible a second time
9808 before the window gets really visible. */
9809 if (! FRAME_ICONIFIED_P (f
)
9810 && ! f
->output_data
.w32
->asked_for_visible
)
9811 x_set_offset (f
, f
->output_data
.w32
->left_pos
, f
->output_data
.w32
->top_pos
, 0);
9813 f
->output_data
.w32
->asked_for_visible
= 1;
9815 // my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW);
9816 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_SHOWNORMAL
);
9819 /* Synchronize to ensure Emacs knows the frame is visible
9820 before we do anything else. We do this loop with input not blocked
9821 so that incoming events are handled. */
9826 /* This must come after we set COUNT. */
9829 XSETFRAME (frame
, f
);
9831 /* Wait until the frame is visible. Process X events until a
9832 MapNotify event has been seen, or until we think we won't get a
9833 MapNotify at all.. */
9834 for (count
= input_signal_count
+ 10;
9835 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9837 /* Force processing of queued events. */
9838 /* TODO: x_sync equivalent? */
9840 /* Machines that do polling rather than SIGIO have been observed
9841 to go into a busy-wait here. So we'll fake an alarm signal
9842 to let the handler know that there's something to be read.
9843 We used to raise a real alarm, but it seems that the handler
9844 isn't always enabled here. This is probably a bug. */
9845 if (input_polling_used ())
9847 /* It could be confusing if a real alarm arrives while processing
9848 the fake one. Turn it off and let the handler reset it. */
9849 int old_poll_suppress_count
= poll_suppress_count
;
9850 poll_suppress_count
= 1;
9851 poll_for_input_1 ();
9852 poll_suppress_count
= old_poll_suppress_count
;
9855 FRAME_SAMPLE_VISIBILITY (f
);
9859 /* Change from mapped state to withdrawn state. */
9861 /* Make the frame visible (mapped and not iconified). */
9863 x_make_frame_invisible (f
)
9866 /* Don't keep the highlight on an invisible frame. */
9867 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
9868 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
9872 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
9874 /* We can't distinguish this from iconification
9875 just by the event that we get from the server.
9876 So we can't win using the usual strategy of letting
9877 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9878 and synchronize with the server to make sure we agree. */
9880 FRAME_ICONIFIED_P (f
) = 0;
9881 f
->async_visible
= 0;
9882 f
->async_iconified
= 0;
9887 /* Change window state from mapped to iconified. */
9895 /* Don't keep the highlight on an invisible frame. */
9896 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
9897 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
9899 if (f
->async_iconified
)
9904 type
= x_icon_type (f
);
9906 x_bitmap_icon (f
, type
);
9908 /* Simulate the user minimizing the frame. */
9909 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
9915 /* Free X resources of frame F. */
9918 x_free_frame_resources (f
)
9921 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9925 if (FRAME_W32_WINDOW (f
))
9926 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
9928 free_frame_menubar (f
);
9930 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
9931 unload_color (f
, f
->output_data
.x
->background_pixel
);
9932 unload_color (f
, f
->output_data
.w32
->cursor_pixel
);
9933 unload_color (f
, f
->output_data
.w32
->cursor_foreground_pixel
);
9934 unload_color (f
, f
->output_data
.w32
->border_pixel
);
9935 unload_color (f
, f
->output_data
.w32
->mouse_pixel
);
9936 if (f
->output_data
.w32
->white_relief
.allocated_p
)
9937 unload_color (f
, f
->output_data
.w32
->white_relief
.pixel
);
9938 if (f
->output_data
.w32
->black_relief
.allocated_p
)
9939 unload_color (f
, f
->output_data
.w32
->black_relief
.pixel
);
9941 if (FRAME_FACE_CACHE (f
))
9942 free_frame_faces (f
);
9944 xfree (f
->output_data
.w32
);
9945 f
->output_data
.w32
= NULL
;
9947 if (f
== dpyinfo
->w32_focus_frame
)
9948 dpyinfo
->w32_focus_frame
= 0;
9949 if (f
== dpyinfo
->w32_focus_event_frame
)
9950 dpyinfo
->w32_focus_event_frame
= 0;
9951 if (f
== dpyinfo
->w32_highlight_frame
)
9952 dpyinfo
->w32_highlight_frame
= 0;
9954 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9956 dpyinfo
->mouse_face_beg_row
9957 = dpyinfo
->mouse_face_beg_col
= -1;
9958 dpyinfo
->mouse_face_end_row
9959 = dpyinfo
->mouse_face_end_col
= -1;
9960 dpyinfo
->mouse_face_window
= Qnil
;
9961 dpyinfo
->mouse_face_deferred_gc
= 0;
9962 dpyinfo
->mouse_face_mouse_frame
= 0;
9969 /* Destroy the window of frame F. */
9971 x_destroy_window (f
)
9974 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9976 x_free_frame_resources (f
);
9978 dpyinfo
->reference_count
--;
9982 /* Setting window manager hints. */
9984 /* Set the normal size hints for the window manager, for frame F.
9985 FLAGS is the flags word to use--or 0 meaning preserve the flags
9986 that the window now has.
9987 If USER_POSITION is nonzero, we set the USPosition
9988 flag (this is useful when FLAGS is 0). */
9990 x_wm_set_size_hint (f
, flags
, user_position
)
9995 Window window
= FRAME_W32_WINDOW (f
);
9999 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
10000 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
10001 SetWindowLong (window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
10002 SetWindowLong (window
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
10007 /* Window manager things */
10008 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10010 int icon_x
, icon_y
;
10013 Window window
= FRAME_W32_WINDOW (f
);
10015 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
10016 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
10017 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
10019 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
10024 /***********************************************************************
10026 ***********************************************************************/
10028 /* The following functions are listed here to help diff stay in step
10029 with xterm.c. See w32fns.c for definitions.
10031 x_get_font_info (f, font_idx)
10032 x_list_fonts (f, pattern, size, maxnames)
10038 /* Check that FONT is valid on frame F. It is if it can be found in F's
10042 x_check_font (f
, font
)
10047 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10049 xassert (font
!= NULL
);
10051 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10052 if (dpyinfo
->font_table
[i
].name
10053 && font
== dpyinfo
->font_table
[i
].font
)
10056 xassert (i
< dpyinfo
->n_fonts
);
10059 #endif /* GLYPH_DEBUG != 0 */
10061 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10062 Note: There are (broken) X fonts out there with invalid XFontStruct
10063 min_bounds contents. For example, handa@etl.go.jp reports that
10064 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10065 have font->min_bounds.width == 0. */
10068 x_font_min_bounds (font
, w
, h
)
10073 * TODO: Windows does not appear to offer min bound, only
10074 * average and maximum width, and maximum height.
10076 *h
= FONT_HEIGHT (font
);
10077 *w
= FONT_WIDTH (font
);
10081 /* Compute the smallest character width and smallest font height over
10082 all fonts available on frame F. Set the members smallest_char_width
10083 and smallest_font_height in F's x_display_info structure to
10084 the values computed. Value is non-zero if smallest_font_height or
10085 smallest_char_width become smaller than they were before. */
10088 x_compute_min_glyph_bounds (f
)
10092 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10094 int old_width
= dpyinfo
->smallest_char_width
;
10095 int old_height
= dpyinfo
->smallest_font_height
;
10097 dpyinfo
->smallest_font_height
= 100000;
10098 dpyinfo
->smallest_char_width
= 100000;
10100 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10101 if (dpyinfo
->font_table
[i
].name
)
10103 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10106 font
= (XFontStruct
*) fontp
->font
;
10107 xassert (font
!= (XFontStruct
*) ~0);
10108 x_font_min_bounds (font
, &w
, &h
);
10110 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10111 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10114 xassert (dpyinfo
->smallest_char_width
> 0
10115 && dpyinfo
->smallest_font_height
> 0);
10117 return (dpyinfo
->n_fonts
== 1
10118 || dpyinfo
->smallest_char_width
< old_width
10119 || dpyinfo
->smallest_font_height
< old_height
);
10122 /* The following functions are listed here to help diff stay in step
10123 with xterm.c. See w32fns.c for definitions.
10125 x_load_font (f, fontname, size)
10126 x_query_font (f, fontname)
10127 x_find_ccl_program (fontp)
10131 /***********************************************************************
10133 ***********************************************************************/
10135 static int w32_initialized
= 0;
10138 w32_initialize_display_info (display_name
)
10139 Lisp_Object display_name
;
10141 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
10143 bzero (dpyinfo
, sizeof (*dpyinfo
));
10145 /* Put it on w32_display_name_list. */
10146 w32_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10147 w32_display_name_list
);
10148 dpyinfo
->name_list_element
= XCAR (w32_display_name_list
);
10150 dpyinfo
->w32_id_name
10151 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
10152 + XSTRING (Vsystem_name
)->size
10154 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
10155 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
10157 /* Default Console mode values - overridden when running in GUI mode
10158 with values obtained from system metrics. */
10161 dpyinfo
->height_in
= 1;
10162 dpyinfo
->width_in
= 1;
10163 dpyinfo
->n_planes
= 1;
10164 dpyinfo
->n_cbits
= 4;
10165 dpyinfo
->n_fonts
= 0;
10166 dpyinfo
->smallest_font_height
= 1;
10167 dpyinfo
->smallest_char_width
= 1;
10169 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10170 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10171 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10172 dpyinfo
->mouse_face_window
= Qnil
;
10174 /* TODO: dpyinfo->gray */
10178 struct w32_display_info
*
10179 w32_term_init (display_name
, xrm_option
, resource_name
)
10180 Lisp_Object display_name
;
10182 char *resource_name
;
10184 struct w32_display_info
*dpyinfo
;
10189 if (!w32_initialized
)
10192 w32_initialized
= 1;
10203 argv
[argc
++] = "-xrm";
10204 argv
[argc
++] = xrm_option
;
10208 w32_initialize_display_info (display_name
);
10210 dpyinfo
= &one_w32_display_info
;
10212 /* Put this display on the chain. */
10213 dpyinfo
->next
= x_display_list
;
10214 x_display_list
= dpyinfo
;
10216 hdc
= GetDC (GetDesktopWindow ());
10218 dpyinfo
->height
= GetDeviceCaps (hdc
, VERTRES
);
10219 dpyinfo
->width
= GetDeviceCaps (hdc
, HORZRES
);
10220 dpyinfo
->root_window
= GetDesktopWindow ();
10221 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
10222 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
10223 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
10224 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
10225 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
10226 dpyinfo
->image_cache
= make_image_cache ();
10227 dpyinfo
->height_in
= dpyinfo
->height
/ dpyinfo
->resx
;
10228 dpyinfo
->width_in
= dpyinfo
->width
/ dpyinfo
->resy
;
10229 ReleaseDC (GetDesktopWindow (), hdc
);
10231 /* initialise palette with white and black */
10234 w32_defined_color (0, "white", &color
, 1);
10235 w32_defined_color (0, "black", &color
, 1);
10238 /* Create Row Bitmaps and store them for later use. */
10239 left_bmp
= CreateBitmap (left_width
, left_height
, 1, 1, left_bits
);
10240 ov_bmp
= CreateBitmap (ov_width
, ov_height
, 1, 1, ov_bits
);
10241 right_bmp
= CreateBitmap (right_width
, right_height
, 1, 1, right_bits
);
10242 continued_bmp
= CreateBitmap (continued_width
, continued_height
, 1,
10243 1, continued_bits
);
10244 continuation_bmp
= CreateBitmap (continuation_width
, continuation_height
,
10245 1, 1, continuation_bits
);
10246 zv_bmp
= CreateBitmap (zv_width
, zv_height
, 1, 1, zv_bits
);
10248 #ifndef F_SETOWN_BUG
10250 #ifdef F_SETOWN_SOCK_NEG
10251 /* stdin is a socket here */
10252 fcntl (connection
, F_SETOWN
, -getpid ());
10253 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10254 fcntl (connection
, F_SETOWN
, getpid ());
10255 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10256 #endif /* ! defined (F_SETOWN) */
10257 #endif /* F_SETOWN_BUG */
10260 if (interrupt_input
)
10261 init_sigio (connection
);
10262 #endif /* ! defined (SIGIO) */
10269 /* Get rid of display DPYINFO, assuming all frames are already gone. */
10272 x_delete_display (dpyinfo
)
10273 struct w32_display_info
*dpyinfo
;
10275 /* Discard this display from w32_display_name_list and w32_display_list.
10276 We can't use Fdelq because that can quit. */
10277 if (! NILP (w32_display_name_list
)
10278 && EQ (XCAR (w32_display_name_list
), dpyinfo
->name_list_element
))
10279 w32_display_name_list
= XCDR (w32_display_name_list
);
10284 tail
= w32_display_name_list
;
10285 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10287 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10289 XSETCDR (tail
, XCDR (XCDR (tail
)));
10292 tail
= XCDR (tail
);
10296 /* free palette table */
10298 struct w32_palette_entry
* plist
;
10300 plist
= dpyinfo
->color_list
;
10303 struct w32_palette_entry
* pentry
= plist
;
10304 plist
= plist
->next
;
10307 dpyinfo
->color_list
= NULL
;
10308 if (dpyinfo
->palette
)
10309 DeleteObject(dpyinfo
->palette
);
10311 xfree (dpyinfo
->font_table
);
10312 xfree (dpyinfo
->w32_id_name
);
10314 /* Destroy row bitmaps. */
10315 DeleteObject (left_bmp
);
10316 DeleteObject (ov_bmp
);
10317 DeleteObject (right_bmp
);
10318 DeleteObject (continued_bmp
);
10319 DeleteObject (continuation_bmp
);
10320 DeleteObject (zv_bmp
);
10323 /* Set up use of W32. */
10325 DWORD
w32_msg_worker ();
10328 x_flush (struct frame
* f
)
10329 { /* Nothing to do */ }
10331 static struct redisplay_interface w32_redisplay_interface
=
10336 x_clear_end_of_line
,
10338 x_after_update_window_line
,
10339 x_update_window_begin
,
10340 x_update_window_end
,
10343 x_clear_mouse_face
,
10344 x_get_glyph_overhangs
,
10345 x_fix_overlapping_area
10351 rif
= &w32_redisplay_interface
;
10353 /* MSVC does not type K&R functions with no arguments correctly, and
10354 so we must explicitly cast them. */
10355 clear_frame_hook
= (void (*)(void)) x_clear_frame
;
10356 ring_bell_hook
= (void (*)(void)) w32_ring_bell
;
10357 update_begin_hook
= x_update_begin
;
10358 update_end_hook
= x_update_end
;
10360 read_socket_hook
= w32_read_socket
;
10362 frame_up_to_date_hook
= w32_frame_up_to_date
;
10364 mouse_position_hook
= w32_mouse_position
;
10365 frame_rehighlight_hook
= w32_frame_rehighlight
;
10366 frame_raise_lower_hook
= w32_frame_raise_lower
;
10367 set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
10368 condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
10369 redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
10370 judge_scroll_bars_hook
= w32_judge_scroll_bars
;
10371 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
10373 scroll_region_ok
= 1; /* we'll scroll partial frames */
10374 char_ins_del_ok
= 1;
10375 line_ins_del_ok
= 1; /* we'll just blt 'em */
10376 fast_clear_end_of_line
= 1; /* X does this well */
10377 memory_below_frame
= 0; /* we don't remember what scrolls
10381 last_tool_bar_item
= -1;
10382 any_help_event_p
= 0;
10384 /* Initialize input mode: interrupt_input off, no flow control, allow
10385 8 bit character input, standard quit char. */
10386 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
10388 /* Create the window thread - it will terminate itself or when the app terminates */
10392 dwMainThreadId
= GetCurrentThreadId ();
10393 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
10394 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
10396 /* Wait for thread to start */
10401 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
10403 hWindowsThread
= CreateThread (NULL
, 0,
10404 (LPTHREAD_START_ROUTINE
) w32_msg_worker
,
10405 0, 0, &dwWindowsThreadId
);
10407 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
10410 /* It is desirable that mainThread should have the same notion of
10411 focus window and active window as windowsThread. Unfortunately, the
10412 following call to AttachThreadInput, which should do precisely what
10413 we need, causes major problems when Emacs is linked as a console
10414 program. Unfortunately, we have good reasons for doing that, so
10415 instead we need to send messages to windowsThread to make some API
10416 calls for us (ones that affect, or depend on, the active/focus
10418 #ifdef ATTACH_THREADS
10419 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
10422 /* Dynamically link to optional system components. */
10424 HANDLE user_lib
= LoadLibrary ("user32.dll");
10426 #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn)
10428 /* New proportional scroll bar functions. */
10429 LOAD_PROC (SetScrollInfo
);
10430 LOAD_PROC (GetScrollInfo
);
10434 FreeLibrary (user_lib
);
10436 /* If using proportional scroll bars, ensure handle is at least 5 pixels;
10437 otherwise use the fixed height. */
10438 vertical_scroll_bar_min_handle
= (pfnSetScrollInfo
!= NULL
) ? 5 :
10439 GetSystemMetrics (SM_CYVTHUMB
);
10441 /* For either kind of scroll bar, take account of the arrows; these
10442 effectively form the border of the main scroll bar range. */
10443 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
10444 = GetSystemMetrics (SM_CYVSCROLL
);
10451 staticpro (&w32_display_name_list
);
10452 w32_display_name_list
= Qnil
;
10454 staticpro (&last_mouse_scroll_bar
);
10455 last_mouse_scroll_bar
= Qnil
;
10457 staticpro (&Qvendor_specific_keysyms
);
10458 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
10460 DEFVAR_INT ("w32-num-mouse-buttons",
10461 &Vw32_num_mouse_buttons
,
10462 "Number of physical mouse buttons.");
10463 Vw32_num_mouse_buttons
= Qnil
;
10465 DEFVAR_LISP ("w32-swap-mouse-buttons",
10466 &Vw32_swap_mouse_buttons
,
10467 "Swap the mapping of middle and right mouse buttons.\n\
10468 When nil, middle button is mouse-2 and right button is mouse-3.");
10469 Vw32_swap_mouse_buttons
= Qnil
;
10471 DEFVAR_LISP ("w32-grab-focus-on-raise",
10472 &Vw32_grab_focus_on_raise
,
10473 "Raised frame grabs input focus.\n\
10474 When t, `raise-frame' grabs input focus as well. This fits well\n\
10475 with the normal Windows click-to-focus policy, but might not be\n\
10476 desirable when using a point-to-focus policy.");
10477 Vw32_grab_focus_on_raise
= Qt
;
10479 DEFVAR_LISP ("w32-capslock-is-shiftlock",
10480 &Vw32_capslock_is_shiftlock
,
10481 "Apply CapsLock state to non character input keys.\n\
10482 When nil, CapsLock only affects normal character input keys.");
10483 Vw32_capslock_is_shiftlock
= Qnil
;
10485 DEFVAR_LISP ("w32-recognize-altgr",
10486 &Vw32_recognize_altgr
,
10487 "Recognize right-alt and left-ctrl as AltGr.\n\
10488 When nil, the right-alt and left-ctrl key combination is\n\
10489 interpreted normally.");
10490 Vw32_recognize_altgr
= Qt
;
10492 DEFVAR_BOOL ("w32-enable-unicode-output",
10493 &w32_enable_unicode_output
,
10494 "Enable the use of Unicode for text output if non-nil.\n\
10495 Unicode output may prevent some third party applications for displaying\n\
10496 Far-East Languages on Windows 95/98 from working properly.\n\
10497 NT uses Unicode internally anyway, so this flag will probably have no\n\
10498 affect on NT machines.");
10499 w32_enable_unicode_output
= 1;
10502 staticpro (&help_echo
);
10503 help_echo_object
= Qnil
;
10504 staticpro (&help_echo_object
);
10505 help_echo_window
= Qnil
;
10506 staticpro (&help_echo_window
);
10507 previous_help_echo
= Qnil
;
10508 staticpro (&previous_help_echo
);
10509 help_echo_pos
= -1;
10511 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
10512 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
10513 For example, if a block cursor is over a tab, it will be drawn as\n\
10514 wide as that tab on the display.");
10515 x_stretch_cursor_p
= 0;
10517 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10518 "If not nil, Emacs uses toolkit scroll bars.");
10519 Vx_toolkit_scroll_bars
= Qt
;
10521 staticpro (&last_mouse_motion_frame
);
10522 last_mouse_motion_frame
= Qnil
;