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"
46 #include "dispextern.h"
48 #include "termhooks.h"
55 #include "intervals.h"
56 #include "composite.h"
60 #define min(a,b) ((a) < (b) ? (a) : (b))
63 #define max(a,b) ((a) > (b) ? (a) : (b))
66 #define abs(x) ((x) < 0 ? -(x) : (x))
68 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
71 /* Bitmaps for truncated lines. */
76 LEFT_TRUNCATION_BITMAP
,
77 RIGHT_TRUNCATION_BITMAP
,
79 CONTINUED_LINE_BITMAP
,
80 CONTINUATION_LINE_BITMAP
,
84 /* Bitmaps are all unsigned short, as Windows requires bitmap data to
85 be Word aligned. For some reason they are horizontally reflected
86 compared to how they appear on X, so changes in xterm.c should be
89 /* Bitmap drawn to indicate lines not displaying text if
90 `indicate-empty-lines' is non-nil. */
94 static unsigned short zv_bits
[] = {
95 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00};
96 static HBITMAP zv_bmp
;
98 /* An arrow like this: `<-'. */
101 #define left_height 8
102 static unsigned short left_bits
[] = {
103 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
104 static HBITMAP left_bmp
;
106 /* Right truncation arrow bitmap `->'. */
108 #define right_width 8
109 #define right_height 8
110 static unsigned short right_bits
[] = {
111 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
112 static HBITMAP right_bmp
;
114 /* Marker for continued lines. */
116 #define continued_width 8
117 #define continued_height 8
118 static unsigned short continued_bits
[] = {
119 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
120 static HBITMAP continued_bmp
;
122 /* Marker for continuation lines. */
124 #define continuation_width 8
125 #define continuation_height 8
126 static unsigned short continuation_bits
[] = {
127 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
128 static HBITMAP continuation_bmp
;
130 /* Overlay arrow bitmap. */
136 static unsigned short ov_bits
[] = {
137 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c};
139 /* A triangular arrow. */
142 static unsigned short ov_bits
[] = {
143 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
145 static HBITMAP ov_bmp
;
147 extern Lisp_Object Qhelp_echo
;
150 /* Non-nil means Emacs uses toolkit scroll bars. */
152 Lisp_Object Vx_toolkit_scroll_bars
;
154 /* If a string, w32_read_socket generates an event to display that string.
155 (The display is done in read_char.) */
157 static Lisp_Object help_echo
;
158 static Lisp_Object help_echo_window
;
159 static Lisp_Object help_echo_object
;
160 static int help_echo_pos
;
162 /* Temporary variable for w32_read_socket. */
164 static Lisp_Object previous_help_echo
;
166 /* Non-zero means that a HELP_EVENT has been generated since Emacs
169 static int any_help_event_p
;
171 /* Non-zero means draw block and hollow cursor as wide as the glyph
172 under it. For example, if a block cursor is over a tab, it will be
173 drawn as wide as that tab on the display. */
175 int x_stretch_cursor_p
;
177 extern unsigned int msh_mousewheel
;
179 extern void free_frame_menubar ();
181 extern void w32_menu_display_help (HMENU menu
, UINT menu_item
, UINT flags
);
183 extern int w32_codepage_for_font (char *fontname
);
185 extern glyph_metric
*w32_BDF_TextMetric(bdffont
*fontp
,
186 unsigned char *text
, int dim
);
187 extern Lisp_Object Vwindow_system
;
189 #define x_any_window_to_frame x_window_to_frame
190 #define x_top_window_to_frame x_window_to_frame
193 /* This is display since w32 does not support multiple ones. */
194 struct w32_display_info one_w32_display_info
;
195 struct w32_display_info
*x_display_list
;
197 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
198 one for each element of w32_display_list and in the same order.
199 NAME is the name of the frame.
200 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
201 Lisp_Object w32_display_name_list
;
203 /* Frame being updated by update_frame. This is declared in term.c.
204 This is set by update_begin and looked at by all the
205 w32 functions. It is zero while not inside an update.
206 In that case, the w32 functions assume that `SELECTED_FRAME ()'
207 is the frame to apply to. */
208 extern struct frame
*updating_frame
;
210 /* This is a frame waiting to be autoraised, within w32_read_socket. */
211 struct frame
*pending_autoraise_frame
;
213 /* Nominal cursor position -- where to draw output.
214 HPOS and VPOS are window relative glyph matrix coordinates.
215 X and Y are window relative pixel coordinates. */
217 struct cursor_pos output_cursor
;
219 /* Flag to enable Unicode output in case users wish to use programs
220 like Twinbridge on '95 rather than installed system level support
221 for Far East languages. */
222 int w32_enable_unicode_output
;
224 DWORD dwWindowsThreadId
= 0;
225 HANDLE hWindowsThread
= NULL
;
226 DWORD dwMainThreadId
= 0;
227 HANDLE hMainThread
= NULL
;
230 /* These definitions are new with Windows 95. */
231 #define SIF_RANGE 0x0001
232 #define SIF_PAGE 0x0002
233 #define SIF_POS 0x0004
234 #define SIF_DISABLENOSCROLL 0x0008
235 #define SIF_TRACKPOS 0x0010
236 #define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
238 typedef struct tagSCROLLINFO
247 } SCROLLINFO
, FAR
*LPSCROLLINFO
;
248 typedef SCROLLINFO CONST FAR
*LPCSCROLLINFO
;
251 /* Dynamic linking to new proportional scroll bar functions. */
252 int (PASCAL
*pfnSetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
, BOOL fRedraw
);
253 BOOL (PASCAL
*pfnGetScrollInfo
) (HWND hwnd
, int fnBar
, LPSCROLLINFO lpsi
);
255 int vertical_scroll_bar_min_handle
;
256 int vertical_scroll_bar_top_border
;
257 int vertical_scroll_bar_bottom_border
;
259 int last_scroll_bar_drag_pos
;
261 /* Mouse movement. */
263 /* Where the mouse was last time we reported a mouse event. */
265 FRAME_PTR last_mouse_frame
;
266 static RECT last_mouse_glyph
;
267 static Lisp_Object last_mouse_press_frame
;
269 Lisp_Object Vw32_num_mouse_buttons
;
271 Lisp_Object Vw32_swap_mouse_buttons
;
273 /* Control whether x_raise_frame also sets input focus. */
274 Lisp_Object Vw32_grab_focus_on_raise
;
276 /* Control whether Caps Lock affects non-ascii characters. */
277 Lisp_Object Vw32_capslock_is_shiftlock
;
279 /* Control whether right-alt and left-ctrl should be recognized as AltGr. */
280 Lisp_Object Vw32_recognize_altgr
;
282 /* The scroll bar in which the last motion event occurred.
284 If the last motion event occurred in a scroll bar, we set this
285 so w32_mouse_position can know whether to report a scroll bar motion or
288 If the last motion event didn't occur in a scroll bar, we set this
289 to Qnil, to tell w32_mouse_position to return an ordinary motion event. */
290 static Lisp_Object last_mouse_scroll_bar
;
291 static int last_mouse_scroll_bar_pos
;
293 /* This is a hack. We would really prefer that w32_mouse_position would
294 return the time associated with the position it returns, but there
295 doesn't seem to be any way to wrest the time-stamp from the server
296 along with the position query. So, we just keep track of the time
297 of the last movement we received, and return that in hopes that
298 it's somewhat accurate. */
300 static Time last_mouse_movement_time
;
302 /* Incremented by w32_read_socket whenever it really tries to read
306 static int volatile input_signal_count
;
308 static int input_signal_count
;
311 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
313 extern Lisp_Object Qface
, Qmouse_face
;
319 /* A mask of extra modifier bits to put into every keyboard char. */
321 extern int extra_keyboard_modifiers
;
323 /* Enumeration for overriding/changing the face to use for drawing
324 glyphs in x_draw_glyphs. */
326 enum draw_glyphs_face
336 static void x_update_window_end
P_ ((struct window
*, int, int));
337 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
338 void w32_delete_display
P_ ((struct w32_display_info
*));
339 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
341 static void set_output_cursor
P_ ((struct cursor_pos
*));
342 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
343 int *, int *, int *));
344 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
345 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
346 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
347 static void w32_handle_tool_bar_click
P_ ((struct frame
*,
348 struct input_event
*));
349 static void show_mouse_face
P_ ((struct w32_display_info
*,
350 enum draw_glyphs_face
));
351 void clear_mouse_face
P_ ((struct w32_display_info
*));
353 void x_lower_frame
P_ ((struct frame
*));
354 void x_scroll_bar_clear
P_ ((struct frame
*));
355 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
356 void x_raise_frame
P_ ((struct frame
*));
357 void x_set_window_size
P_ ((struct frame
*, int, int, int));
358 void x_wm_set_window_state
P_ ((struct frame
*, int));
359 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
360 void w32_initialize
P_ ((void));
361 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
362 int x_compute_min_glyph_bounds
P_ ((struct frame
*));
363 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
365 enum draw_glyphs_face
));
366 static void x_update_end
P_ ((struct frame
*));
367 static void w32_frame_up_to_date
P_ ((struct frame
*));
368 static void w32_reassert_line_highlight
P_ ((int, int));
369 static void x_change_line_highlight
P_ ((int, int, int, int));
370 static void w32_set_terminal_modes
P_ ((void));
371 static void w32_reset_terminal_modes
P_ ((void));
372 static void w32_cursor_to
P_ ((int, int, int, int));
373 static void x_write_glyphs
P_ ((struct glyph
*, int));
374 static void x_clear_end_of_line
P_ ((int));
375 static void x_clear_frame
P_ ((void));
376 static void x_clear_cursor
P_ ((struct window
*));
377 static void frame_highlight
P_ ((struct frame
*));
378 static void frame_unhighlight
P_ ((struct frame
*));
379 static void w32_new_focus_frame
P_ ((struct w32_display_info
*,
381 static void w32_frame_rehighlight
P_ ((struct frame
*));
382 static void x_frame_rehighlight
P_ ((struct w32_display_info
*));
383 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
384 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
385 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
386 static void expose_window_tree
P_ ((struct window
*, RECT
*));
387 static void expose_window
P_ ((struct window
*, RECT
*));
388 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
389 RECT
*, enum glyph_row_area
));
390 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
392 void x_update_cursor
P_ ((struct frame
*, int));
393 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
394 static void x_update_window_cursor
P_ ((struct window
*, int));
395 static void x_erase_phys_cursor
P_ ((struct window
*));
396 void x_display_cursor
P_ ((struct window
*w
, int, int, int, int, int));
397 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
398 static void w32_draw_bitmap
P_ ((struct window
*, HDC hdc
, struct glyph_row
*,
400 static void w32_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
402 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, RECT
*));
403 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
404 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
406 static Lisp_Object Qvendor_specific_keysyms
;
409 /***********************************************************************
411 ***********************************************************************/
415 /* This is a function useful for recording debugging information about
416 the sequence of occurrences in this file. */
424 struct record event_record
[100];
426 int event_record_index
;
428 record_event (locus
, type
)
432 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
433 event_record_index
= 0;
435 event_record
[event_record_index
].locus
= locus
;
436 event_record
[event_record_index
].type
= type
;
437 event_record_index
++;
443 void XChangeGC (void * ignore
, XGCValues
* gc
, unsigned long mask
,
446 if (mask
& GCForeground
)
447 gc
->foreground
= xgcv
->foreground
;
448 if (mask
& GCBackground
)
449 gc
->background
= xgcv
->background
;
451 gc
->font
= xgcv
->font
;
454 XGCValues
*XCreateGC (void * ignore
, Window window
, unsigned long mask
,
457 XGCValues
*gc
= (XGCValues
*) xmalloc (sizeof (XGCValues
));
458 bzero (gc
, sizeof (XGCValues
));
460 XChangeGC (ignore
, gc
, mask
, xgcv
);
465 void XGetGCValues (void* ignore
, XGCValues
*gc
,
466 unsigned long mask
, XGCValues
*xgcv
)
468 XChangeGC (ignore
, xgcv
, mask
, gc
);
472 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
476 HRGN clip_region
= CreateRectRgnIndirect (rect
);
477 SelectClipRgn (hdc
, clip_region
);
478 DeleteObject (clip_region
);
481 SelectClipRgn (hdc
, NULL
);
485 /* Draw a hollow rectangle at the specified position. */
487 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
488 int width
, int height
)
493 hb
= CreateSolidBrush (gc
->background
);
494 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
495 oldhb
= SelectObject (hdc
, hb
);
496 oldhp
= SelectObject (hdc
, hp
);
498 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
500 SelectObject (hdc
, oldhb
);
501 SelectObject (hdc
, oldhp
);
506 /* Draw a filled rectangle at the specified position. */
508 w32_fill_rect (f
, hdc
, pix
, lprect
)
516 hb
= CreateSolidBrush (pix
);
517 FillRect (hdc
, lprect
, hb
);
526 HDC hdc
= get_frame_dc (f
);
528 /* Under certain conditions, this can be called at startup with
529 a console frame pointer before the GUI frame is created. An HDC
530 of 0 indicates this. */
533 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
534 w32_clear_rect (f
, hdc
, &rect
);
537 release_frame_dc (f
, hdc
);
541 /***********************************************************************
542 Starting and ending an update
543 ***********************************************************************/
545 /* Start an update of frame F. This function is installed as a hook
546 for update_begin, i.e. it is called when update_begin is called.
547 This function is called prior to calls to x_update_window_begin for
548 each window being updated. */
554 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
556 if (! FRAME_W32_P (f
))
559 /* Regenerate display palette before drawing if list of requested
560 colors has changed. */
561 if (display_info
->regen_palette
)
563 w32_regenerate_palette (f
);
564 display_info
->regen_palette
= FALSE
;
569 /* Start update of window W. Set the global variable updated_window
570 to the window being updated and set output_cursor to the cursor
574 x_update_window_begin (w
)
577 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
578 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
581 set_output_cursor (&w
->cursor
);
585 if (f
== display_info
->mouse_face_mouse_frame
)
587 /* Don't do highlighting for mouse motion during the update. */
588 display_info
->mouse_face_defer
= 1;
590 /* If F needs to be redrawn, simply forget about any prior mouse
592 if (FRAME_GARBAGED_P (f
))
593 display_info
->mouse_face_window
= Qnil
;
595 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
596 their mouse_face_p flag set, which means that they are always
597 unequal to rows in a desired matrix which never have that
598 flag set. So, rows containing mouse-face glyphs are never
599 scrolled, and we don't have to switch the mouse highlight off
600 here to prevent it from being scrolled. */
602 /* Can we tell that this update does not affect the window
603 where the mouse highlight is? If so, no need to turn off.
604 Likewise, don't do anything if the frame is garbaged;
605 in that case, the frame's current matrix that we would use
606 is all wrong, and we will redisplay that line anyway. */
607 if (!NILP (display_info
->mouse_face_window
)
608 && w
== XWINDOW (display_info
->mouse_face_window
))
612 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
613 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
616 if (i
< w
->desired_matrix
->nrows
)
617 clear_mouse_face (display_info
);
626 /* Draw a vertical window border to the right of window W if W doesn't
627 have vertical scroll bars. */
630 x_draw_vertical_border (w
)
633 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
635 /* Redraw borders between horizontally adjacent windows. Don't
636 do it for frames with vertical scroll bars because either the
637 right scroll bar of a window, or the left scroll bar of its
638 neighbor will suffice as a border. */
639 if (!WINDOW_RIGHTMOST_P (w
)
640 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
645 window_box_edges (w
, -1, &r
.left
, &r
.top
, &r
.right
, &r
.bottom
);
646 r
.left
= r
.right
+ FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
647 r
.right
= r
.left
+ 1;
650 hdc
= get_frame_dc (f
);
651 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
652 release_frame_dc (f
, hdc
);
657 /* End update of window W (which is equal to updated_window).
659 Draw vertical borders between horizontally adjacent windows, and
660 display W's cursor if CURSOR_ON_P is non-zero.
662 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
663 glyphs in mouse-face were overwritten. In that case we have to
664 make sure that the mouse-highlight is properly redrawn.
666 W may be a menu bar pseudo-window in case we don't have X toolkit
667 support. Such windows don't have a cursor, so don't display it
671 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
673 int cursor_on_p
, mouse_face_overwritten_p
;
675 if (!w
->pseudo_window_p
)
677 struct w32_display_info
*dpyinfo
678 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
682 /* If a row with mouse-face was overwritten, arrange for
683 XTframe_up_to_date to redisplay the mouse highlight. */
684 if (mouse_face_overwritten_p
)
686 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
687 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
688 dpyinfo
->mouse_face_window
= Qnil
;
692 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
694 output_cursor
.x
, output_cursor
.y
);
696 x_draw_vertical_border (w
);
700 updated_window
= NULL
;
704 /* End update of frame F. This function is installed as a hook in
711 if (! FRAME_W32_P (f
))
714 /* Mouse highlight may be displayed again. */
715 FRAME_W32_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
719 /* This function is called from various places in xdisp.c whenever a
720 complete update has been performed. The global variable
721 updated_window is not available here. */
724 w32_frame_up_to_date (f
)
729 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
730 if (dpyinfo
->mouse_face_deferred_gc
731 || f
== dpyinfo
->mouse_face_mouse_frame
)
734 if (dpyinfo
->mouse_face_mouse_frame
)
735 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
736 dpyinfo
->mouse_face_mouse_x
,
737 dpyinfo
->mouse_face_mouse_y
);
738 dpyinfo
->mouse_face_deferred_gc
= 0;
745 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
746 arrow bitmaps, or clear the areas where they would be displayed
747 before DESIRED_ROW is made current. The window being updated is
748 found in updated_window. This function It is called from
749 update_window_line only if it is known that there are differences
750 between bitmaps to be drawn between current row and DESIRED_ROW. */
753 x_after_update_window_line (desired_row
)
754 struct glyph_row
*desired_row
;
756 struct window
*w
= updated_window
;
760 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
766 x_draw_row_bitmaps (w
, desired_row
);
768 /* When a window has disappeared, make sure that no rest of
769 full-width rows stays visible in the internal border. */
770 if (windows_or_buffers_changed
771 && (f
= XFRAME (w
->frame
),
772 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
775 int height
= desired_row
->visible_height
;
776 int x
= (window_box_right (w
, -1)
777 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
778 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
779 HDC hdc
= get_frame_dc (f
);
781 w32_clear_area (f
, hdc
, x
, y
, width
, height
);
782 release_frame_dc (f
, hdc
);
790 /* Draw the bitmap WHICH in one of the areas to the left or right of
791 window W. ROW is the glyph row for which to display the bitmap; it
792 determines the vertical position at which the bitmap has to be
796 w32_draw_bitmap (w
, hdc
, row
, which
)
799 struct glyph_row
*row
;
800 enum bitmap_type which
;
802 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
803 Window window
= FRAME_W32_WINDOW (f
);
810 /* Must clip because of partially visible lines. */
811 w32_clip_to_row (w
, row
, hdc
, 1);
815 case LEFT_TRUNCATION_BITMAP
:
819 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
821 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
824 case OVERLAY_ARROW_BITMAP
:
828 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
830 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
833 case RIGHT_TRUNCATION_BITMAP
:
837 x
= window_box_right (w
, -1);
838 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
841 case CONTINUED_LINE_BITMAP
:
842 wd
= continued_width
;
843 h
= continued_height
;
844 pixmap
= continued_bmp
;
845 x
= window_box_right (w
, -1);
846 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
849 case CONTINUATION_LINE_BITMAP
:
850 wd
= continuation_width
;
851 h
= continuation_height
;
852 pixmap
= continuation_bmp
;
853 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
855 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
862 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
864 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
871 /* Convert to frame coordinates. Set dy to the offset in the row to
872 start drawing the bitmap. */
873 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
874 dy
= (row
->height
- h
) / 2;
876 /* Draw the bitmap. */
877 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
879 compat_hdc
= CreateCompatibleDC (hdc
);
882 horig_obj
= SelectObject (compat_hdc
, pixmap
);
883 SetTextColor (hdc
, face
->background
);
884 SetBkColor (hdc
, face
->foreground
);
886 BitBlt (hdc
, x
, y
+ dy
, wd
, h
, compat_hdc
, 0, 0, SRCCOPY
);
888 SelectObject (compat_hdc
, horig_obj
);
889 DeleteDC (compat_hdc
);
894 /* Draw flags bitmaps for glyph row ROW on window W. Call this
895 function with input blocked. */
898 x_draw_row_bitmaps (w
, row
)
900 struct glyph_row
*row
;
902 struct frame
*f
= XFRAME (w
->frame
);
903 enum bitmap_type bitmap
;
905 int header_line_height
= -1;
908 xassert (interrupt_input_blocked
);
910 /* If row is completely invisible, because of vscrolling, we
911 don't have to draw anything. */
912 if (row
->visible_height
<= 0)
915 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
916 PREPARE_FACE_FOR_DISPLAY (f
, face
);
918 /* Decide which bitmap to draw at the left side. */
919 if (row
->overlay_arrow_p
)
920 bitmap
= OVERLAY_ARROW_BITMAP
;
921 else if (row
->truncated_on_left_p
)
922 bitmap
= LEFT_TRUNCATION_BITMAP
;
923 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
924 bitmap
= CONTINUATION_LINE_BITMAP
;
925 else if (row
->indicate_empty_line_p
)
926 bitmap
= ZV_LINE_BITMAP
;
930 hdc
= get_frame_dc (f
);
932 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
934 if (bitmap
== NO_BITMAP
935 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
936 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
938 /* If W has a vertical border to its left, don't draw over it. */
939 int border
= ((XFASTINT (w
->left
) > 0
940 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
942 int left
= window_box_left (w
, -1);
944 if (header_line_height
< 0)
945 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
947 w32_fill_area (f
, hdc
, face
->background
,
948 left
- FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) + border
,
949 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
951 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
952 row
->visible_height
);
955 /* Draw the left bitmap. */
956 if (bitmap
!= NO_BITMAP
)
957 w32_draw_bitmap (w
, hdc
, row
, bitmap
);
959 /* Decide which bitmap to draw at the right side. */
960 if (row
->truncated_on_right_p
)
961 bitmap
= RIGHT_TRUNCATION_BITMAP
;
962 else if (row
->continued_p
)
963 bitmap
= CONTINUED_LINE_BITMAP
;
967 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
969 if (bitmap
== NO_BITMAP
970 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
971 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
973 int right
= window_box_right (w
, -1);
975 if (header_line_height
< 0)
976 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
978 w32_fill_area (f
, hdc
, face
->background
,
980 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
982 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
983 row
->visible_height
);
986 /* Draw the right bitmap. */
987 if (bitmap
!= NO_BITMAP
)
988 w32_draw_bitmap (w
, hdc
, row
, bitmap
);
990 release_frame_dc (f
, hdc
);
994 /***********************************************************************
996 ***********************************************************************/
998 /* External interface to control of standout mode. Not used for W32
999 frames. Aborts when called. */
1002 w32_reassert_line_highlight (new, vpos
)
1010 f
= SELECTED_FRAME ();
1012 if (! FRAME_W32_P (f
))
1019 /* Call this when about to modify line at position VPOS and change
1020 whether it is highlighted. Not used for W32 frames. Aborts when
1024 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1025 int new_highlight
, vpos
, y
, first_unused_hpos
;
1032 f
= SELECTED_FRAME ();
1034 if (! FRAME_W32_P (f
))
1041 /* This is called when starting Emacs and when restarting after
1042 suspend. When starting Emacs, no window is mapped. And nothing
1043 must be done to Emacs's own window if it is suspended (though that
1047 w32_set_terminal_modes (void)
1051 /* This is called when exiting or suspending Emacs. Exiting will make
1052 the W32 windows go away, and suspending requires no action. */
1055 w32_reset_terminal_modes (void)
1061 /***********************************************************************
1063 ***********************************************************************/
1065 /* Set the global variable output_cursor to CURSOR. All cursor
1066 positions are relative to updated_window. */
1069 set_output_cursor (cursor
)
1070 struct cursor_pos
*cursor
;
1072 output_cursor
.hpos
= cursor
->hpos
;
1073 output_cursor
.vpos
= cursor
->vpos
;
1074 output_cursor
.x
= cursor
->x
;
1075 output_cursor
.y
= cursor
->y
;
1079 /* Set a nominal cursor position.
1081 HPOS and VPOS are column/row positions in a window glyph matrix. X
1082 and Y are window text area relative pixel positions.
1084 If this is done during an update, updated_window will contain the
1085 window that is being updated and the position is the future output
1086 cursor position for that window. If updated_window is null, use
1087 selected_window and display the cursor at the given position. */
1090 w32_cursor_to (vpos
, hpos
, y
, x
)
1091 int vpos
, hpos
, y
, x
;
1095 /* If updated_window is not set, work on selected_window. */
1099 w
= XWINDOW (selected_window
);
1101 /* Set the output cursor. */
1102 output_cursor
.hpos
= hpos
;
1103 output_cursor
.vpos
= vpos
;
1104 output_cursor
.x
= x
;
1105 output_cursor
.y
= y
;
1107 /* If not called as part of an update, really display the cursor.
1108 This will also set the cursor position of W. */
1109 if (updated_window
== NULL
)
1112 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1119 /***********************************************************************
1121 ***********************************************************************/
1123 /* Function prototypes of this page. */
1125 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1129 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1130 int, wchar_t *, int));
1131 static XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*,
1133 enum w32_char_font_type
));
1134 static enum w32_char_font_type
1135 w32_encode_char
P_ ((int, wchar_t *, struct font_info
*, int *));
1136 static void x_append_glyph
P_ ((struct it
*));
1137 static void x_append_composite_glyph
P_ ((struct it
*));
1138 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1140 static void x_produce_glyphs
P_ ((struct it
*));
1141 static void x_produce_image_glyph
P_ ((struct it
*it
));
1144 /* Dealing with bits of wchar_t as if they were an XChar2B. */
1145 #define BUILD_WCHAR_T(byte1, byte2) \
1146 ((wchar_t)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff)))
1150 (((ch) & 0xff00) >> 8)
1156 /* Get metrics of character CHAR2B in FONT. Value is always non-null.
1157 If CHAR2B is not contained in FONT, the font's default character
1158 metric is returned. */
1161 w32_bdf_per_char_metric (font
, char2b
, dim
, pcm
)
1167 glyph_metric
* bdf_metric
;
1171 buf
[0] = (char)(*char2b
);
1174 buf
[0] = BYTE1 (*char2b
);
1175 buf
[1] = BYTE2 (*char2b
);
1178 bdf_metric
= w32_BDF_TextMetric (font
->bdf
, buf
, dim
);
1182 pcm
->width
= bdf_metric
->dwidth
;
1183 pcm
->lbearing
= bdf_metric
->bbox
;
1184 pcm
->rbearing
= bdf_metric
->dwidth
1185 - (bdf_metric
->bbox
+ bdf_metric
->bbw
);
1186 pcm
->ascent
= bdf_metric
->bboy
+ bdf_metric
->bbh
;
1187 pcm
->descent
= -bdf_metric
->bboy
;
1196 w32_native_per_char_metric (font
, char2b
, font_type
, pcm
)
1199 enum w32_char_font_type font_type
;
1202 HDC hdc
= GetDC (NULL
);
1204 BOOL retval
= FALSE
;
1206 xassert (font
&& char2b
);
1207 xassert (font
->hfont
);
1208 xassert (font_type
== UNICODE_FONT
|| font_type
== ANSI_FONT
);
1210 old_font
= SelectObject (hdc
, font
->hfont
);
1212 if ((font
->tm
.tmPitchAndFamily
& TMPF_TRUETYPE
) != 0)
1216 if (font_type
== UNICODE_FONT
)
1217 retval
= GetCharABCWidthsW (hdc
, *char2b
, *char2b
, &char_widths
);
1219 retval
= GetCharABCWidthsA (hdc
, *char2b
, *char2b
, &char_widths
);
1223 pcm
->width
= char_widths
.abcA
+ char_widths
.abcB
+ char_widths
.abcC
;
1224 pcm
->lbearing
= char_widths
.abcA
;
1225 pcm
->rbearing
= pcm
->width
- char_widths
.abcC
;
1226 pcm
->ascent
= FONT_BASE (font
);
1227 pcm
->descent
= FONT_DESCENT (font
);
1233 /* Either font is not a True-type font, or GetCharABCWidthsW
1234 failed (it is not supported on Windows 9x for instance), so we
1235 can't determine the full info we would like. All is not lost
1236 though - we can call GetTextExtentPoint32 to get rbearing and
1237 deduce width based on the font's per-string overhang. lbearing
1238 is assumed to be zero. */
1240 /* TODO: Some Thai characters (and other composites if Windows
1241 supports them) do have lbearing, and report their total width
1242 as zero. Need some way of handling them when
1243 GetCharABCWidthsW fails. */
1246 if (font_type
== UNICODE_FONT
)
1247 retval
= GetTextExtentPoint32W (hdc
, char2b
, 1, &sz
);
1249 retval
= GetTextExtentPoint32A (hdc
, (char*)char2b
, 1, &sz
);
1253 pcm
->width
= sz
.cx
- font
->tm
.tmOverhang
;
1254 pcm
->rbearing
= sz
.cx
;
1256 pcm
->ascent
= FONT_BASE (font
);
1257 pcm
->descent
= FONT_DESCENT (font
);
1262 if (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0)
1267 SelectObject (hdc
, old_font
);
1268 ReleaseDC (NULL
, hdc
);
1274 static XCharStruct
*
1275 w32_per_char_metric (font
, char2b
, font_type
)
1278 enum w32_char_font_type font_type
;
1280 /* The result metric information. */
1284 xassert (font
&& char2b
);
1285 xassert (font_type
!= UNKNOWN_FONT
);
1287 /* Handle the common cases quickly. */
1288 if (!font
->bdf
&& font
->per_char
== NULL
)
1289 /* TODO: determine whether char2b exists in font? */
1290 return &font
->max_bounds
;
1291 else if (!font
->bdf
&& *char2b
< 128)
1292 return &font
->per_char
[*char2b
];
1294 pcm
= &font
->scratch
;
1296 if (font_type
== BDF_1D_FONT
)
1297 retval
= w32_bdf_per_char_metric (font
, char2b
, 1, pcm
);
1298 else if (font_type
== BDF_2D_FONT
)
1299 retval
= w32_bdf_per_char_metric (font
, char2b
, 2, pcm
);
1301 retval
= w32_native_per_char_metric (font
, char2b
, font_type
, pcm
);
1310 w32_cache_char_metrics (font
)
1313 wchar_t char2b
= L
'x';
1315 /* Cache char metrics for the common cases. */
1318 /* TODO: determine whether font is fixed-pitch. */
1319 if (!w32_bdf_per_char_metric (font
, &char2b
, 1, &font
->max_bounds
))
1321 /* Use the font width and height as max bounds, as not all BDF
1322 fonts contain the letter 'x'. */
1323 font
->max_bounds
.width
= FONT_MAX_WIDTH (font
);
1324 font
->max_bounds
.lbearing
= -font
->bdf
->llx
;
1325 font
->max_bounds
.rbearing
= FONT_MAX_WIDTH (font
) - font
->bdf
->urx
;
1326 font
->max_bounds
.ascent
= FONT_BASE (font
);
1327 font
->max_bounds
.descent
= FONT_DESCENT (font
);
1332 if (((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
) != 0)
1333 /* Some fonts (eg DBCS fonts) are marked as fixed width even
1334 though they contain characters of different widths. */
1335 || (font
->tm
.tmMaxCharWidth
!= font
->tm
.tmAveCharWidth
))
1337 /* Font is not fixed pitch, so cache per_char info for the
1338 ASCII characters. It would be much more work, and probably
1339 not worth it, to cache other chars, since we may change
1340 between using Unicode and ANSI text drawing functions at
1344 font
->per_char
= xmalloc (128 * sizeof(XCharStruct
));
1345 for (i
= 0; i
< 128; i
++)
1348 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1349 &font
->per_char
[i
]);
1353 w32_native_per_char_metric (font
, &char2b
, ANSI_FONT
,
1359 /* Determine if a font is double byte. */
1360 int w32_font_is_double_byte (XFontStruct
*font
)
1362 return font
->double_byte_p
;
1367 w32_use_unicode_for_codepage (codepage
)
1370 /* If the current codepage is supported, use Unicode for output. */
1371 return (w32_enable_unicode_output
1372 && codepage
!= CP_8BIT
1373 && (codepage
== CP_UNICODE
|| IsValidCodePage (codepage
)));
1376 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1377 the two-byte form of C. Encoding is returned in *CHAR2B. */
1379 static INLINE
enum w32_char_font_type
1380 w32_encode_char (c
, char2b
, font_info
, two_byte_p
)
1383 struct font_info
*font_info
;
1386 int charset
= CHAR_CHARSET (c
);
1390 XFontStruct
*font
= font_info
->font
;
1392 xassert (two_byte_p
);
1394 *two_byte_p
= w32_font_is_double_byte (font
);
1396 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1397 This may be either a program in a special encoder language or a
1399 if (font_info
->font_encoder
)
1401 /* It's a program. */
1402 struct ccl_program
*ccl
= font_info
->font_encoder
;
1404 if (CHARSET_DIMENSION (charset
) == 1)
1406 ccl
->reg
[0] = charset
;
1407 ccl
->reg
[1] = BYTE2 (*char2b
);
1411 ccl
->reg
[0] = charset
;
1412 ccl
->reg
[1] = BYTE1 (*char2b
);
1413 ccl
->reg
[2] = BYTE2 (*char2b
);
1416 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1418 /* We assume that MSBs are appropriately set/reset by CCL
1420 if (!*two_byte_p
) /* 1-byte font */
1421 *char2b
= BUILD_WCHAR_T (0, ccl
->reg
[1]);
1423 *char2b
= BUILD_WCHAR_T (ccl
->reg
[1], ccl
->reg
[2]);
1425 else if (font_info
->encoding
[charset
])
1427 /* Fixed encoding scheme. See fontset.h for the meaning of the
1428 encoding numbers. */
1429 int enc
= font_info
->encoding
[charset
];
1431 if ((enc
== 1 || enc
== 2)
1432 && CHARSET_DIMENSION (charset
) == 2)
1433 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
) | 0x80, BYTE2 (*char2b
));
1435 if (enc
== 1 || enc
== 3
1436 || (enc
== 4 && CHARSET_DIMENSION (charset
) == 1))
1437 *char2b
= BUILD_WCHAR_T (BYTE1 (*char2b
), BYTE2 (*char2b
) | 0x80);
1442 ENCODE_SJIS (BYTE1 (*char2b
), BYTE2 (*char2b
),
1444 *char2b
= BUILD_WCHAR_T (sjis1
, sjis2
);
1447 codepage
= w32_codepage_for_font (font_info
->name
);
1449 /* If charset is not ASCII or Latin-1, may need to move it into
1451 if ( font
&& !font
->bdf
&& w32_use_unicode_for_codepage (codepage
)
1452 && charset
!= CHARSET_ASCII
&& charset
!= charset_latin_iso8859_1
1453 && charset
!= CHARSET_8_BIT_CONTROL
&& charset
!= CHARSET_8_BIT_GRAPHIC
)
1456 temp
[0] = BYTE1 (*char2b
);
1457 temp
[1] = BYTE2 (*char2b
);
1459 if (codepage
!= CP_UNICODE
)
1462 MultiByteToWideChar (codepage
, 0, temp
, 2, char2b
, 1);
1464 MultiByteToWideChar (codepage
, 0, temp
+1, 1, char2b
, 1);
1470 return UNKNOWN_FONT
;
1471 else if (font
->bdf
&& CHARSET_DIMENSION (charset
) == 1)
1476 return UNICODE_FONT
;
1482 /* Get face and two-byte form of character C in face FACE_ID on frame
1483 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1484 means we want to display multibyte text. Value is a pointer to a
1485 realized face that is ready for display. */
1487 static INLINE
struct face
*
1488 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1494 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1498 /* Unibyte case. We don't have to encode, but we have to make
1499 sure to use a face suitable for unibyte. */
1500 *char2b
= BUILD_WCHAR_T (0, c
);
1501 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1502 face
= FACE_FROM_ID (f
, face_id
);
1504 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1506 /* Case of ASCII in a face known to fit ASCII. */
1507 *char2b
= BUILD_WCHAR_T (0, c
);
1511 int c1
, c2
, charset
;
1513 /* Split characters into bytes. If c2 is -1 afterwards, C is
1514 really a one-byte character so that byte1 is zero. */
1515 SPLIT_CHAR (c
, charset
, c1
, c2
);
1517 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1519 *char2b
= BUILD_WCHAR_T (0, c1
);
1521 /* Maybe encode the character in *CHAR2B. */
1522 if (face
->font
!= NULL
)
1524 struct font_info
*font_info
1525 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1527 w32_encode_char (c
, char2b
, font_info
, &multibyte_p
);
1531 /* Make sure X resources of the face are allocated. */
1532 xassert (face
!= NULL
);
1533 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1539 /* Get face and two-byte form of character glyph GLYPH on frame F.
1540 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1541 a pointer to a realized face that is ready for display. */
1543 static INLINE
struct face
*
1544 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1546 struct glyph
*glyph
;
1553 xassert (glyph
->type
== CHAR_GLYPH
);
1554 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1559 two_byte_p
= &dummy
;
1561 if (!glyph
->multibyte_p
)
1563 /* Unibyte case. We don't have to encode, but we have to make
1564 sure to use a face suitable for unibyte. */
1565 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1567 else if (glyph
->u
.ch
< 128
1568 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1570 /* Case of ASCII in a face known to fit ASCII. */
1571 *char2b
= BUILD_WCHAR_T (0, glyph
->u
.ch
);
1575 int c1
, c2
, charset
;
1577 /* Split characters into bytes. If c2 is -1 afterwards, C is
1578 really a one-byte character so that byte1 is zero. */
1579 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1581 *char2b
= BUILD_WCHAR_T (c1
, c2
);
1583 *char2b
= BUILD_WCHAR_T (0, c1
);
1585 /* Maybe encode the character in *CHAR2B. */
1586 if (charset
!= CHARSET_ASCII
)
1588 struct font_info
*font_info
1589 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1592 glyph
->w32_font_type
1593 = w32_encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
1598 /* Make sure X resources of the face are allocated. */
1599 xassert (face
!= NULL
);
1600 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1605 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1606 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1612 struct glyph
*glyph
;
1613 enum glyph_row_area area
= it
->area
;
1615 xassert (it
->glyph_row
);
1616 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1618 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1619 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1621 glyph
->charpos
= CHARPOS (it
->position
);
1622 glyph
->object
= it
->object
;
1623 glyph
->pixel_width
= it
->pixel_width
;
1624 glyph
->voffset
= it
->voffset
;
1625 glyph
->type
= CHAR_GLYPH
;
1626 glyph
->multibyte_p
= it
->multibyte_p
;
1627 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1628 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1629 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1630 || it
->phys_descent
> it
->descent
);
1631 glyph
->padding_p
= 0;
1632 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1633 glyph
->face_id
= it
->face_id
;
1634 glyph
->u
.ch
= it
->char_to_display
;
1635 glyph
->w32_font_type
= UNKNOWN_FONT
;
1636 ++it
->glyph_row
->used
[area
];
1640 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1641 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1644 x_append_composite_glyph (it
)
1647 struct glyph
*glyph
;
1648 enum glyph_row_area area
= it
->area
;
1650 xassert (it
->glyph_row
);
1652 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1653 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1655 glyph
->charpos
= CHARPOS (it
->position
);
1656 glyph
->object
= it
->object
;
1657 glyph
->pixel_width
= it
->pixel_width
;
1658 glyph
->voffset
= it
->voffset
;
1659 glyph
->type
= COMPOSITE_GLYPH
;
1660 glyph
->multibyte_p
= it
->multibyte_p
;
1661 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1662 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1663 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1664 || it
->phys_descent
> it
->descent
);
1665 glyph
->padding_p
= 0;
1666 glyph
->glyph_not_available_p
= 0;
1667 glyph
->face_id
= it
->face_id
;
1668 glyph
->u
.cmp_id
= it
->cmp_id
;
1669 glyph
->w32_font_type
= UNKNOWN_FONT
;
1670 ++it
->glyph_row
->used
[area
];
1675 /* Change IT->ascent and IT->height according to the setting of
1679 take_vertical_position_into_account (it
)
1684 if (it
->voffset
< 0)
1685 /* Increase the ascent so that we can display the text higher
1687 it
->ascent
+= abs (it
->voffset
);
1689 /* Increase the descent so that we can display the text lower
1691 it
->descent
+= it
->voffset
;
1696 /* Produce glyphs/get display metrics for the image IT is loaded with.
1697 See the description of struct display_iterator in dispextern.h for
1698 an overview of struct display_iterator. */
1701 x_produce_image_glyph (it
)
1707 xassert (it
->what
== IT_IMAGE
);
1709 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1710 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1713 /* Make sure X resources of the face and image are loaded. */
1714 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1715 prepare_image_for_display (it
->f
, img
);
1717 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1718 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1719 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1723 if (face
->box
!= FACE_NO_BOX
)
1725 if (face
->box_line_width
> 0)
1727 it
->ascent
+= face
->box_line_width
;
1728 it
->descent
+= face
->box_line_width
;
1731 if (it
->start_of_box_run_p
)
1732 it
->pixel_width
+= abs (face
->box_line_width
);
1733 if (it
->end_of_box_run_p
)
1734 it
->pixel_width
+= abs (face
->box_line_width
);
1737 take_vertical_position_into_account (it
);
1741 struct glyph
*glyph
;
1742 enum glyph_row_area area
= it
->area
;
1744 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1745 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1747 glyph
->charpos
= CHARPOS (it
->position
);
1748 glyph
->object
= it
->object
;
1749 glyph
->pixel_width
= it
->pixel_width
;
1750 glyph
->voffset
= it
->voffset
;
1751 glyph
->type
= IMAGE_GLYPH
;
1752 glyph
->multibyte_p
= it
->multibyte_p
;
1753 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1754 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1755 glyph
->overlaps_vertically_p
= 0;
1756 glyph
->padding_p
= 0;
1757 glyph
->glyph_not_available_p
= 0;
1758 glyph
->face_id
= it
->face_id
;
1759 glyph
->u
.img_id
= img
->id
;
1760 glyph
->w32_font_type
= UNKNOWN_FONT
;
1761 ++it
->glyph_row
->used
[area
];
1767 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1768 of the glyph, WIDTH and HEIGHT are the width and height of the
1769 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1770 ascent of the glyph (0 <= ASCENT <= 1). */
1773 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1779 struct glyph
*glyph
;
1780 enum glyph_row_area area
= it
->area
;
1782 xassert (ascent
>= 0 && ascent
<= 1);
1784 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1785 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1787 glyph
->charpos
= CHARPOS (it
->position
);
1788 glyph
->object
= object
;
1789 glyph
->pixel_width
= width
;
1790 glyph
->voffset
= it
->voffset
;
1791 glyph
->type
= STRETCH_GLYPH
;
1792 glyph
->multibyte_p
= it
->multibyte_p
;
1793 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1794 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1795 glyph
->overlaps_vertically_p
= 0;
1796 glyph
->padding_p
= 0;
1797 glyph
->glyph_not_available_p
= 0;
1798 glyph
->face_id
= it
->face_id
;
1799 glyph
->u
.stretch
.ascent
= height
* ascent
;
1800 glyph
->u
.stretch
.height
= height
;
1801 glyph
->w32_font_type
= UNKNOWN_FONT
;
1802 ++it
->glyph_row
->used
[area
];
1807 /* Produce a stretch glyph for iterator IT. IT->object is the value
1808 of the glyph property displayed. The value must be a list
1809 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1812 1. `:width WIDTH' specifies that the space should be WIDTH *
1813 canonical char width wide. WIDTH may be an integer or floating
1816 2. `:relative-width FACTOR' specifies that the width of the stretch
1817 should be computed from the width of the first character having the
1818 `glyph' property, and should be FACTOR times that width.
1820 3. `:align-to HPOS' specifies that the space should be wide enough
1821 to reach HPOS, a value in canonical character units.
1823 Exactly one of the above pairs must be present.
1825 4. `:height HEIGHT' specifies that the height of the stretch produced
1826 should be HEIGHT, measured in canonical character units.
1828 5. `:relative-height FACTOR' specifies that the height of the the
1829 stretch should be FACTOR times the height of the characters having
1832 Either none or exactly one of 4 or 5 must be present.
1834 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1835 of the stretch should be used for the ascent of the stretch.
1836 ASCENT must be in the range 0 <= ASCENT <= 100. */
1839 ((INTEGERP (X) || FLOATP (X)) \
1845 x_produce_stretch_glyph (it
)
1848 /* (space :width WIDTH :height HEIGHT. */
1850 extern Lisp_Object Qspace
;
1852 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1853 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1854 extern Lisp_Object QCalign_to
;
1855 Lisp_Object prop
, plist
;
1856 double width
= 0, height
= 0, ascent
= 0;
1857 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1858 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1860 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1862 /* List should start with `space'. */
1863 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1864 plist
= XCDR (it
->object
);
1866 /* Compute the width of the stretch. */
1867 if (prop
= Fplist_get (plist
, QCwidth
),
1869 /* Absolute width `:width WIDTH' specified and valid. */
1870 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1871 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1874 /* Relative width `:relative-width FACTOR' specified and valid.
1875 Compute the width of the characters having the `glyph'
1878 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1881 if (it
->multibyte_p
)
1883 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1884 - IT_BYTEPOS (*it
));
1885 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1888 it2
.c
= *p
, it2
.len
= 1;
1890 it2
.glyph_row
= NULL
;
1891 it2
.what
= IT_CHARACTER
;
1892 x_produce_glyphs (&it2
);
1893 width
= NUMVAL (prop
) * it2
.pixel_width
;
1895 else if (prop
= Fplist_get (plist
, QCalign_to
),
1897 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1899 /* Nothing specified -> width defaults to canonical char width. */
1900 width
= CANON_X_UNIT (it
->f
);
1902 /* Compute height. */
1903 if (prop
= Fplist_get (plist
, QCheight
),
1905 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1906 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1908 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1910 height
= FONT_HEIGHT (font
);
1912 /* Compute percentage of height used for ascent. If
1913 `:ascent ASCENT' is present and valid, use that. Otherwise,
1914 derive the ascent from the font in use. */
1915 if (prop
= Fplist_get (plist
, QCascent
),
1916 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1917 ascent
= NUMVAL (prop
) / 100.0;
1919 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
1928 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1929 if (!STRINGP (object
))
1930 object
= it
->w
->buffer
;
1931 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1934 it
->pixel_width
= width
;
1935 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1936 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1939 if (face
->box
!= FACE_NO_BOX
)
1941 if (face
->box_line_width
> 0)
1943 it
->ascent
+= face
->box_line_width
;
1944 it
->descent
+= face
->box_line_width
;
1947 if (it
->start_of_box_run_p
)
1948 it
->pixel_width
+= abs (face
->box_line_width
);
1949 if (it
->end_of_box_run_p
)
1950 it
->pixel_width
+= abs (face
->box_line_width
);
1953 take_vertical_position_into_account (it
);
1956 /* Return proper value to be used as baseline offset of font that has
1957 ASCENT and DESCENT to draw characters by the font at the vertical
1958 center of the line of frame F.
1960 Here, out task is to find the value of BOFF in the following figure;
1962 -------------------------+-----------+-
1963 -+-+---------+-+ | |
1965 | | | | F_ASCENT F_HEIGHT
1968 | | |-|-+------+-----------|------- baseline
1970 | |---------|-+-+ | |
1972 -+-+---------+-+ F_DESCENT |
1973 -------------------------+-----------+-
1975 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1976 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1977 DESCENT = FONT->descent
1978 HEIGHT = FONT_HEIGHT (FONT)
1979 F_DESCENT = (F->output_data.x->font->descent
1980 - F->output_data.x->baseline_offset)
1981 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1984 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1985 (FONT_DESCENT (FONT) \
1986 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1987 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1988 - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
1990 /* Produce glyphs/get display metrics for the display element IT is
1991 loaded with. See the description of struct display_iterator in
1992 dispextern.h for an overview of struct display_iterator. */
1995 x_produce_glyphs (it
)
1998 it
->glyph_not_available_p
= 0;
2000 if (it
->what
== IT_CHARACTER
)
2004 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2006 int font_not_found_p
;
2007 struct font_info
*font_info
;
2008 int boff
; /* baseline offset */
2009 /* We may change it->multibyte_p upon unibyte<->multibyte
2010 conversion. So, save the current value now and restore it
2013 Note: It seems that we don't have to record multibyte_p in
2014 struct glyph because the character code itself tells if or
2015 not the character is multibyte. Thus, in the future, we must
2016 consider eliminating the field `multibyte_p' in the struct
2019 int saved_multibyte_p
= it
->multibyte_p
;
2021 /* Maybe translate single-byte characters to multibyte, or the
2023 it
->char_to_display
= it
->c
;
2024 if (!ASCII_BYTE_P (it
->c
))
2026 if (unibyte_display_via_language_environment
2027 && SINGLE_BYTE_CHAR_P (it
->c
)
2029 || !NILP (Vnonascii_translation_table
)))
2031 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2032 it
->multibyte_p
= 1;
2033 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2034 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2036 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
2037 && !it
->multibyte_p
)
2039 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
2040 it
->multibyte_p
= 0;
2041 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2042 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2046 /* Get font to use. Encode IT->char_to_display. */
2047 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2048 it
->face_id
, &char2b
,
2052 /* When no suitable font found, use the default font. */
2053 font_not_found_p
= font
== NULL
;
2054 if (font_not_found_p
)
2056 font
= FRAME_FONT (it
->f
);
2057 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2062 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2063 boff
= font_info
->baseline_offset
;
2064 if (font_info
->vertical_centering
)
2065 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2068 if (it
->char_to_display
>= ' '
2069 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
2071 /* Either unibyte or ASCII. */
2076 pcm
= w32_per_char_metric (font
, &char2b
,
2077 font
->bdf
? BDF_1D_FONT
: ANSI_FONT
);
2078 it
->ascent
= FONT_BASE (font
) + boff
;
2079 it
->descent
= FONT_DESCENT (font
) - boff
;
2083 it
->phys_ascent
= pcm
->ascent
+ boff
;
2084 it
->phys_descent
= pcm
->descent
- boff
;
2085 it
->pixel_width
= pcm
->width
;
2089 it
->glyph_not_available_p
= 1;
2090 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2091 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2092 it
->pixel_width
= FONT_WIDTH (font
);
2095 /* If this is a space inside a region of text with
2096 `space-width' property, change its width. */
2097 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
2099 it
->pixel_width
*= XFLOATINT (it
->space_width
);
2101 /* If face has a box, add the box thickness to the character
2102 height. If character has a box line to the left and/or
2103 right, add the box line width to the character's width. */
2104 if (face
->box
!= FACE_NO_BOX
)
2106 int thick
= face
->box_line_width
;
2110 it
->ascent
+= thick
;
2111 it
->descent
+= thick
;
2116 if (it
->start_of_box_run_p
)
2117 it
->pixel_width
+= thick
;
2118 if (it
->end_of_box_run_p
)
2119 it
->pixel_width
+= thick
;
2122 /* If face has an overline, add the height of the overline
2123 (1 pixel) and a 1 pixel margin to the character height. */
2124 if (face
->overline_p
)
2127 take_vertical_position_into_account (it
);
2129 /* If we have to actually produce glyphs, do it. */
2134 /* Translate a space with a `space-width' property
2135 into a stretch glyph. */
2136 double ascent
= (double) FONT_BASE (font
)
2137 / FONT_HEIGHT (font
);
2138 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2139 it
->ascent
+ it
->descent
, ascent
);
2142 x_append_glyph (it
);
2144 /* If characters with lbearing or rbearing are displayed
2145 in this line, record that fact in a flag of the
2146 glyph row. This is used to optimize X output code. */
2147 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
2148 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2151 else if (it
->char_to_display
== '\n')
2153 /* A newline has no width but we need the height of the line. */
2154 it
->pixel_width
= 0;
2156 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2157 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2159 if (face
->box
!= FACE_NO_BOX
2160 && face
->box_line_width
> 0)
2162 it
->ascent
+= face
->box_line_width
;
2163 it
->descent
+= face
->box_line_width
;
2166 else if (it
->char_to_display
== '\t')
2168 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
2169 int x
= it
->current_x
+ it
->continuation_lines_width
;
2170 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
2172 /* If the distance from the current position to the next tab
2173 stop is less than a canonical character width, use the
2174 tab stop after that. */
2175 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
2176 next_tab_x
+= tab_width
;
2178 it
->pixel_width
= next_tab_x
- x
;
2180 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2181 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2185 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2186 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2187 it
->ascent
+ it
->descent
, ascent
);
2192 /* A multi-byte character.
2193 If we found a font, this font should give us the right
2194 metrics. If we didn't find a font, use the frame's
2195 default font and calculate the width of the character
2196 from the charset width; this is what old redisplay code
2198 enum w32_char_font_type type
;
2200 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2205 type
= UNICODE_FONT
;
2207 pcm
= w32_per_char_metric (font
, &char2b
, type
);
2209 if (font_not_found_p
|| !pcm
)
2211 int charset
= CHAR_CHARSET (it
->char_to_display
);
2213 it
->glyph_not_available_p
= 1;
2214 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2215 * CHARSET_WIDTH (charset
));
2216 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2217 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2221 it
->pixel_width
= pcm
->width
;
2222 it
->phys_ascent
= pcm
->ascent
+ boff
;
2223 it
->phys_descent
= pcm
->descent
- boff
;
2225 && (pcm
->lbearing
< 0
2226 || pcm
->rbearing
> pcm
->width
))
2227 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2230 it
->ascent
= FONT_BASE (font
) + boff
;
2231 it
->descent
= FONT_DESCENT (font
) - boff
;
2232 if (face
->box
!= FACE_NO_BOX
)
2234 int thick
= face
->box_line_width
;
2238 it
->ascent
+= thick
;
2239 it
->descent
+= thick
;
2244 if (it
->start_of_box_run_p
)
2245 it
->pixel_width
+= thick
;
2246 if (it
->end_of_box_run_p
)
2247 it
->pixel_width
+= thick
;
2250 /* If face has an overline, add the height of the overline
2251 (1 pixel) and a 1 pixel margin to the character height. */
2252 if (face
->overline_p
)
2255 take_vertical_position_into_account (it
);
2258 x_append_glyph (it
);
2260 it
->multibyte_p
= saved_multibyte_p
;
2262 else if (it
->what
== IT_COMPOSITION
)
2264 /* Note: A composition is represented as one glyph in the
2265 glyph matrix. There are no padding glyphs. */
2268 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2270 int font_not_found_p
;
2271 struct font_info
*font_info
;
2272 int boff
; /* baseline offset */
2273 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2275 /* Maybe translate single-byte characters to multibyte. */
2276 it
->char_to_display
= it
->c
;
2277 if (unibyte_display_via_language_environment
2278 && SINGLE_BYTE_CHAR_P (it
->c
)
2281 && !NILP (Vnonascii_translation_table
))))
2283 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2286 /* Get face and font to use. Encode IT->char_to_display. */
2287 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2288 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2289 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2290 it
->face_id
, &char2b
, it
->multibyte_p
);
2293 /* When no suitable font found, use the default font. */
2294 font_not_found_p
= font
== NULL
;
2295 if (font_not_found_p
)
2297 font
= FRAME_FONT (it
->f
);
2298 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2303 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2304 boff
= font_info
->baseline_offset
;
2305 if (font_info
->vertical_centering
)
2306 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2309 /* There are no padding glyphs, so there is only one glyph to
2310 produce for the composition. Important is that pixel_width,
2311 ascent and descent are the values of what is drawn by
2312 draw_glyphs (i.e. the values of the overall glyphs composed). */
2315 /* If we have not yet calculated pixel size data of glyphs of
2316 the composition for the current face font, calculate them
2317 now. Theoretically, we have to check all fonts for the
2318 glyphs, but that requires much time and memory space. So,
2319 here we check only the font of the first glyph. This leads
2320 to incorrect display very rarely, and C-l (recenter) can
2321 correct the display anyway. */
2322 if (cmp
->font
!= (void *) font
)
2324 /* Ascent and descent of the font of the first character of
2325 this composition (adjusted by baseline offset). Ascent
2326 and descent of overall glyphs should not be less than
2327 them respectively. */
2328 int font_ascent
= FONT_BASE (font
) + boff
;
2329 int font_descent
= FONT_DESCENT (font
) - boff
;
2330 /* Bounding box of the overall glyphs. */
2331 int leftmost
, rightmost
, lowest
, highest
;
2332 int i
, width
, ascent
, descent
;
2333 enum w32_char_font_type font_type
;
2335 cmp
->font
= (void *) font
;
2337 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (it
->c
)) == 1)
2338 font_type
= BDF_1D_FONT
;
2340 font_type
= BDF_2D_FONT
;
2342 font_type
= UNICODE_FONT
;
2344 /* Initialize the bounding box. */
2346 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2349 ascent
= pcm
->ascent
;
2350 descent
= pcm
->descent
;
2354 width
= FONT_WIDTH (font
);
2355 ascent
= FONT_BASE (font
);
2356 descent
= FONT_DESCENT (font
);
2360 lowest
= - descent
+ boff
;
2361 highest
= ascent
+ boff
;
2365 && font_info
->default_ascent
2366 && CHAR_TABLE_P (Vuse_default_ascent
)
2367 && !NILP (Faref (Vuse_default_ascent
,
2368 make_number (it
->char_to_display
))))
2369 highest
= font_info
->default_ascent
+ boff
;
2371 /* Draw the first glyph at the normal position. It may be
2372 shifted to right later if some other glyphs are drawn at
2374 cmp
->offsets
[0] = 0;
2375 cmp
->offsets
[1] = boff
;
2377 /* Set cmp->offsets for the remaining glyphs. */
2378 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2380 int left
, right
, btm
, top
;
2381 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2382 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2384 face
= FACE_FROM_ID (it
->f
, face_id
);
2385 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2390 font
= FRAME_FONT (it
->f
);
2391 boff
= it
->f
->output_data
.w32
->baseline_offset
;
2397 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2398 boff
= font_info
->baseline_offset
;
2399 if (font_info
->vertical_centering
)
2400 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2403 if (font
->bdf
&& CHARSET_DIMENSION (CHAR_CHARSET (ch
)) == 1)
2404 font_type
= BDF_1D_FONT
;
2406 font_type
= BDF_2D_FONT
;
2408 font_type
= UNICODE_FONT
;
2411 && (pcm
= w32_per_char_metric (font
, &char2b
, font_type
)))
2414 ascent
= pcm
->ascent
;
2415 descent
= pcm
->descent
;
2419 width
= FONT_WIDTH (font
);
2424 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2426 /* Relative composition with or without
2428 left
= (leftmost
+ rightmost
- width
) / 2;
2429 btm
= - descent
+ boff
;
2430 if (font_info
&& font_info
->relative_compose
2431 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2432 || NILP (Faref (Vignore_relative_composition
,
2433 make_number (ch
)))))
2436 if (- descent
>= font_info
->relative_compose
)
2437 /* One extra pixel between two glyphs. */
2439 else if (ascent
<= 0)
2440 /* One extra pixel between two glyphs. */
2441 btm
= lowest
- 1 - ascent
- descent
;
2446 /* A composition rule is specified by an integer
2447 value that encodes global and new reference
2448 points (GREF and NREF). GREF and NREF are
2449 specified by numbers as below:
2457 ---3---4---5--- baseline
2459 6---7---8 -- descent
2461 int rule
= COMPOSITION_RULE (cmp
, i
);
2462 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2464 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2465 grefx
= gref
% 3, nrefx
= nref
% 3;
2466 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2469 + grefx
* (rightmost
- leftmost
) / 2
2470 - nrefx
* width
/ 2);
2471 btm
= ((grefy
== 0 ? highest
2473 : grefy
== 2 ? lowest
2474 : (highest
+ lowest
) / 2)
2475 - (nrefy
== 0 ? ascent
+ descent
2476 : nrefy
== 1 ? descent
- boff
2478 : (ascent
+ descent
) / 2));
2481 cmp
->offsets
[i
* 2] = left
;
2482 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2484 /* Update the bounding box of the overall glyphs. */
2485 right
= left
+ width
;
2486 top
= btm
+ descent
+ ascent
;
2487 if (left
< leftmost
)
2489 if (right
> rightmost
)
2497 /* If there are glyphs whose x-offsets are negative,
2498 shift all glyphs to the right and make all x-offsets
2502 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2503 cmp
->offsets
[i
* 2] -= leftmost
;
2504 rightmost
-= leftmost
;
2507 cmp
->pixel_width
= rightmost
;
2508 cmp
->ascent
= highest
;
2509 cmp
->descent
= - lowest
;
2510 if (cmp
->ascent
< font_ascent
)
2511 cmp
->ascent
= font_ascent
;
2512 if (cmp
->descent
< font_descent
)
2513 cmp
->descent
= font_descent
;
2516 it
->pixel_width
= cmp
->pixel_width
;
2517 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2518 it
->descent
= it
->phys_descent
= cmp
->descent
;
2520 if (face
->box
!= FACE_NO_BOX
)
2522 int thick
= face
->box_line_width
;
2526 it
->ascent
+= thick
;
2527 it
->descent
+= thick
;
2532 if (it
->start_of_box_run_p
)
2533 it
->pixel_width
+= thick
;
2534 if (it
->end_of_box_run_p
)
2535 it
->pixel_width
+= thick
;
2538 /* If face has an overline, add the height of the overline
2539 (1 pixel) and a 1 pixel margin to the character height. */
2540 if (face
->overline_p
)
2543 take_vertical_position_into_account (it
);
2546 x_append_composite_glyph (it
);
2548 else if (it
->what
== IT_IMAGE
)
2549 x_produce_image_glyph (it
);
2550 else if (it
->what
== IT_STRETCH
)
2551 x_produce_stretch_glyph (it
);
2553 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2554 because this isn't true for images with `:ascent 100'. */
2555 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2556 if (it
->area
== TEXT_AREA
)
2557 it
->current_x
+= it
->pixel_width
;
2559 it
->descent
+= it
->extra_line_spacing
;
2561 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2562 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2563 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2564 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2568 /* Estimate the pixel height of the mode or top line on frame F.
2569 FACE_ID specifies what line's height to estimate. */
2572 x_estimate_mode_line_height (f
, face_id
)
2574 enum face_id face_id
;
2576 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2578 /* This function is called so early when Emacs starts that the face
2579 cache and mode line face are not yet initialized. */
2580 if (FRAME_FACE_CACHE (f
))
2582 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2586 height
= FONT_HEIGHT (face
->font
);
2587 if (face
->box_line_width
> 0)
2588 height
+= 2 * face
->box_line_width
;
2596 /***********************************************************************
2598 ***********************************************************************/
2600 /* A sequence of glyphs to be drawn in the same face.
2602 This data structure is not really completely X specific, so it
2603 could possibly, at least partially, be useful for other systems. It
2604 is currently not part of the external redisplay interface because
2605 it's not clear what other systems will need. */
2609 /* X-origin of the string. */
2612 /* Y-origin and y-position of the base line of this string. */
2615 /* The width of the string, not including a face extension. */
2618 /* The width of the string, including a face extension. */
2619 int background_width
;
2621 /* The height of this string. This is the height of the line this
2622 string is drawn in, and can be different from the height of the
2623 font the string is drawn in. */
2626 /* Number of pixels this string overwrites in front of its x-origin.
2627 This number is zero if the string has an lbearing >= 0; it is
2628 -lbearing, if the string has an lbearing < 0. */
2631 /* Number of pixels this string overwrites past its right-most
2632 nominal x-position, i.e. x + width. Zero if the string's
2633 rbearing is <= its nominal width, rbearing - width otherwise. */
2636 /* The frame on which the glyph string is drawn. */
2639 /* The window on which the glyph string is drawn. */
2642 /* X display and window for convenience. */
2645 /* The glyph row for which this string was built. It determines the
2646 y-origin and height of the string. */
2647 struct glyph_row
*row
;
2649 /* The area within row. */
2650 enum glyph_row_area area
;
2652 /* Characters to be drawn, and number of characters. */
2656 /* A face-override for drawing cursors, mouse face and similar. */
2657 enum draw_glyphs_face hl
;
2659 /* Face in which this string is to be drawn. */
2662 /* Font in which this string is to be drawn. */
2665 /* Font info for this string. */
2666 struct font_info
*font_info
;
2668 /* Non-null means this string describes (part of) a composition.
2669 All characters from char2b are drawn composed. */
2670 struct composition
*cmp
;
2672 /* Index of this glyph string's first character in the glyph
2673 definition of CMP. If this is zero, this glyph string describes
2674 the first character of a composition. */
2677 /* 1 means this glyph strings face has to be drawn to the right end
2678 of the window's drawing area. */
2679 unsigned extends_to_end_of_line_p
: 1;
2681 /* 1 means the background of this string has been drawn. */
2682 unsigned background_filled_p
: 1;
2684 /* 1 means glyph string must be drawn with 16-bit functions. */
2685 unsigned two_byte_p
: 1;
2687 /* 1 means that the original font determined for drawing this glyph
2688 string could not be loaded. The member `font' has been set to
2689 the frame's default font in this case. */
2690 unsigned font_not_found_p
: 1;
2692 /* 1 means that the face in which this glyph string is drawn has a
2694 unsigned stippled_p
: 1;
2696 /* 1 means only the foreground of this glyph string must be drawn,
2697 and we should use the physical height of the line this glyph
2698 string appears in as clip rect. */
2699 unsigned for_overlaps_p
: 1;
2701 /* The GC to use for drawing this glyph string. */
2706 /* A pointer to the first glyph in the string. This glyph
2707 corresponds to char2b[0]. Needed to draw rectangles if
2708 font_not_found_p is 1. */
2709 struct glyph
*first_glyph
;
2711 /* Image, if any. */
2714 struct glyph_string
*next
, *prev
;
2718 /* Encapsulate the different ways of displaying text under W32. */
2720 void W32_TEXTOUT (s
, x
, y
,chars
,nchars
)
2721 struct glyph_string
* s
;
2726 int charset_dim
= w32_font_is_double_byte (s
->gc
->font
) ? 2 : 1;
2727 if (s
->gc
->font
->bdf
)
2728 w32_BDF_TextOut (s
->gc
->font
->bdf
, s
->hdc
,
2729 x
, y
, (char *) chars
, charset_dim
,
2730 nchars
* charset_dim
, 0);
2731 else if (s
->first_glyph
->w32_font_type
== UNICODE_FONT
)
2732 ExtTextOutW (s
->hdc
, x
, y
, 0, NULL
, chars
, nchars
, NULL
);
2734 ExtTextOut (s
->hdc
, x
, y
, 0, NULL
, (char *) chars
,
2735 nchars
* charset_dim
, NULL
);
2741 x_dump_glyph_string (s
)
2742 struct glyph_string
*s
;
2744 fprintf (stderr
, "glyph string\n");
2745 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2746 s
->x
, s
->y
, s
->width
, s
->height
);
2747 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2748 fprintf (stderr
, " hl = %d\n", s
->hl
);
2749 fprintf (stderr
, " left overhang = %d, right = %d\n",
2750 s
->left_overhang
, s
->right_overhang
);
2751 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2752 fprintf (stderr
, " extends to end of line = %d\n",
2753 s
->extends_to_end_of_line_p
);
2754 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2755 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2758 #endif /* GLYPH_DEBUG */
2762 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2763 struct glyph_string
**,
2764 struct glyph_string
*,
2765 struct glyph_string
*));
2766 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2767 struct glyph_string
**,
2768 struct glyph_string
*,
2769 struct glyph_string
*));
2770 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2771 struct glyph_string
**,
2772 struct glyph_string
*));
2773 static int x_left_overwritten
P_ ((struct glyph_string
*));
2774 static int x_left_overwriting
P_ ((struct glyph_string
*));
2775 static int x_right_overwritten
P_ ((struct glyph_string
*));
2776 static int x_right_overwriting
P_ ((struct glyph_string
*));
2777 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2779 static void w32_init_glyph_string
P_ ((struct glyph_string
*, HDC hdc
,
2780 wchar_t *, struct window
*,
2782 enum glyph_row_area
, int,
2783 enum draw_glyphs_face
));
2784 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2785 enum glyph_row_area
, int, int,
2786 enum draw_glyphs_face
, int *, int *, int));
2787 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2788 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2789 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2791 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2792 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2793 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2794 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2795 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2796 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2797 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2798 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2799 static void w32_get_glyph_overhangs
P_ ((HDC hdc
, struct glyph
*,
2802 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2803 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
2804 static void w32_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2805 double, int, COLORREF
));
2806 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2807 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2808 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2809 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2810 static void w32_draw_image_foreground_1
P_ ((struct glyph_string
*, HBITMAP
));
2811 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2812 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2814 static void w32_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2815 int, int, int, int, RECT
*));
2816 static void w32_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2817 int, int, int, RECT
*));
2818 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2819 enum glyph_row_area
));
2820 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2822 enum glyph_row_area
, int, int));
2825 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2829 /* Append the list of glyph strings with head H and tail T to the list
2830 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2833 x_append_glyph_string_lists (head
, tail
, h
, t
)
2834 struct glyph_string
**head
, **tail
;
2835 struct glyph_string
*h
, *t
;
2849 /* Prepend the list of glyph strings with head H and tail T to the
2850 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2854 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2855 struct glyph_string
**head
, **tail
;
2856 struct glyph_string
*h
, *t
;
2870 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2871 Set *HEAD and *TAIL to the resulting list. */
2874 x_append_glyph_string (head
, tail
, s
)
2875 struct glyph_string
**head
, **tail
;
2876 struct glyph_string
*s
;
2878 s
->next
= s
->prev
= NULL
;
2879 x_append_glyph_string_lists (head
, tail
, s
, s
);
2883 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2888 struct glyph_string
*s
;
2890 if (s
->font
== FRAME_FONT (s
->f
)
2891 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2892 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2894 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
2897 /* Cursor on non-default face: must merge. */
2901 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
2902 xgcv
.foreground
= s
->face
->background
;
2904 /* If the glyph would be invisible, try a different foreground. */
2905 if (xgcv
.foreground
== xgcv
.background
)
2906 xgcv
.foreground
= s
->face
->foreground
;
2907 if (xgcv
.foreground
== xgcv
.background
)
2908 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
2909 if (xgcv
.foreground
== xgcv
.background
)
2910 xgcv
.foreground
= s
->face
->foreground
;
2912 /* Make sure the cursor is distinct from text in this face. */
2913 if (xgcv
.background
== s
->face
->background
2914 && xgcv
.foreground
== s
->face
->foreground
)
2916 xgcv
.background
= s
->face
->foreground
;
2917 xgcv
.foreground
= s
->face
->background
;
2920 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2921 xgcv
.font
= s
->font
;
2922 mask
= GCForeground
| GCBackground
| GCFont
;
2924 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2925 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2928 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2929 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
2931 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2936 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2939 x_set_mouse_face_gc (s
)
2940 struct glyph_string
*s
;
2945 /* What face has to be used last for the mouse face? */
2946 face_id
= FRAME_W32_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2947 face
= FACE_FROM_ID (s
->f
, face_id
);
2949 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2951 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2952 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2954 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2955 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2956 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2958 /* If font in this face is same as S->font, use it. */
2959 if (s
->font
== s
->face
->font
)
2960 s
->gc
= s
->face
->gc
;
2963 /* Otherwise construct scratch_cursor_gc with values from FACE
2968 xgcv
.background
= s
->face
->background
;
2969 xgcv
.foreground
= s
->face
->foreground
;
2970 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2971 xgcv
.font
= s
->font
;
2972 mask
= GCForeground
| GCBackground
| GCFont
;
2974 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2975 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2978 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2979 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
2981 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2984 xassert (s
->gc
!= 0);
2988 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2989 Faces to use in the mode line have already been computed when the
2990 matrix was built, so there isn't much to do, here. */
2993 x_set_mode_line_face_gc (s
)
2994 struct glyph_string
*s
;
2996 s
->gc
= s
->face
->gc
;
3000 /* Set S->gc of glyph string S for drawing that glyph string. Set
3001 S->stippled_p to a non-zero value if the face of S has a stipple
3005 x_set_glyph_string_gc (s
)
3006 struct glyph_string
*s
;
3008 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
3010 if (s
->hl
== DRAW_NORMAL_TEXT
)
3012 s
->gc
= s
->face
->gc
;
3013 s
->stippled_p
= s
->face
->stipple
!= 0;
3015 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
3017 x_set_mode_line_face_gc (s
);
3018 s
->stippled_p
= s
->face
->stipple
!= 0;
3020 else if (s
->hl
== DRAW_CURSOR
)
3022 x_set_cursor_gc (s
);
3025 else if (s
->hl
== DRAW_MOUSE_FACE
)
3027 x_set_mouse_face_gc (s
);
3028 s
->stippled_p
= s
->face
->stipple
!= 0;
3030 else if (s
->hl
== DRAW_IMAGE_RAISED
3031 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3033 s
->gc
= s
->face
->gc
;
3034 s
->stippled_p
= s
->face
->stipple
!= 0;
3038 s
->gc
= s
->face
->gc
;
3039 s
->stippled_p
= s
->face
->stipple
!= 0;
3042 /* GC must have been set. */
3043 xassert (s
->gc
!= 0);
3047 /* Return in *R the clipping rectangle for glyph string S. */
3050 w32_get_glyph_string_clip_rect (s
, r
)
3051 struct glyph_string
*s
;
3054 int r_height
, r_width
;
3056 if (s
->row
->full_width_p
)
3058 /* Draw full-width. X coordinates are relative to S->w->left. */
3059 int canon_x
= CANON_X_UNIT (s
->f
);
3061 r
->left
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
3062 r_width
= XFASTINT (s
->w
->width
) * canon_x
;
3064 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
3066 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
3067 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
3071 r
->left
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
3073 /* Unless displaying a mode or menu bar line, which are always
3074 fully visible, clip to the visible part of the row. */
3075 if (s
->w
->pseudo_window_p
)
3076 r_height
= s
->row
->visible_height
;
3078 r_height
= s
->height
;
3082 /* This is a text line that may be partially visible. */
3083 r
->left
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
3084 r_width
= window_box_width (s
->w
, s
->area
);
3085 r_height
= s
->row
->visible_height
;
3088 /* Don't use S->y for clipping because it doesn't take partially
3089 visible lines into account. For example, it can be negative for
3090 partially visible lines at the top of a window. */
3091 if (!s
->row
->full_width_p
3092 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
3093 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3095 r
->top
= max (0, s
->row
->y
);
3097 /* If drawing a tool-bar window, draw it over the internal border
3098 at the top of the window. */
3099 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
3100 r
->top
-= s
->f
->output_data
.w32
->internal_border_width
;
3102 /* If S draws overlapping rows, it's sufficient to use the top and
3103 bottom of the window for clipping because this glyph string
3104 intentionally draws over other lines. */
3105 if (s
->for_overlaps_p
)
3107 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3108 r_height
= window_text_bottom_y (s
->w
) - r
->top
;
3111 r
->top
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->top
);
3113 r
->bottom
= r
->top
+ r_height
;
3114 r
->right
= r
->left
+ r_width
;
3118 /* Set clipping for output of glyph string S. S may be part of a mode
3119 line or menu if we don't have X toolkit support. */
3122 x_set_glyph_string_clipping (s
)
3123 struct glyph_string
*s
;
3126 w32_get_glyph_string_clip_rect (s
, &r
);
3127 w32_set_clip_rectangle (s
->hdc
, &r
);
3131 /* Compute left and right overhang of glyph string S. If S is a glyph
3132 string for a composition, assume overhangs don't exist. */
3135 x_compute_glyph_string_overhangs (s
)
3136 struct glyph_string
*s
;
3138 /* TODO: Windows does not appear to have a method for
3139 getting this info without getting the ABC widths for each
3140 individual character and working it out manually. */
3144 /* Compute overhangs and x-positions for glyph string S and its
3145 predecessors, or successors. X is the starting x-position for S.
3146 BACKWARD_P non-zero means process predecessors. */
3149 x_compute_overhangs_and_x (s
, x
, backward_p
)
3150 struct glyph_string
*s
;
3158 x_compute_glyph_string_overhangs (s
);
3168 x_compute_glyph_string_overhangs (s
);
3177 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
3178 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
3179 assumed to be zero. */
3182 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
)
3184 struct glyph
*glyph
;
3190 if (glyph
->type
== CHAR_GLYPH
)
3197 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
3201 && (pcm
= w32_per_char_metric (font
, &char2b
,
3202 glyph
->w32_font_type
)))
3204 if (pcm
->rbearing
> pcm
->width
)
3205 *right
= pcm
->rbearing
- pcm
->width
;
3206 if (pcm
->lbearing
< 0)
3207 *left
= -pcm
->lbearing
;
3214 x_get_glyph_overhangs (glyph
, f
, left
, right
)
3215 struct glyph
*glyph
;
3219 HDC hdc
= get_frame_dc (f
);
3220 /* Convert to unicode! */
3221 w32_get_glyph_overhangs (hdc
, glyph
, f
, left
, right
);
3222 release_frame_dc (f
, hdc
);
3226 /* Return the index of the first glyph preceding glyph string S that
3227 is overwritten by S because of S's left overhang. Value is -1
3228 if no glyphs are overwritten. */
3231 x_left_overwritten (s
)
3232 struct glyph_string
*s
;
3236 if (s
->left_overhang
)
3239 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3240 int first
= s
->first_glyph
- glyphs
;
3242 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3243 x
-= glyphs
[i
].pixel_width
;
3254 /* Return the index of the first glyph preceding glyph string S that
3255 is overwriting S because of its right overhang. Value is -1 if no
3256 glyph in front of S overwrites S. */
3259 x_left_overwriting (s
)
3260 struct glyph_string
*s
;
3263 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3264 int first
= s
->first_glyph
- glyphs
;
3268 for (i
= first
- 1; i
>= 0; --i
)
3271 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3274 x
-= glyphs
[i
].pixel_width
;
3281 /* Return the index of the last glyph following glyph string S that is
3282 not overwritten by S because of S's right overhang. Value is -1 if
3283 no such glyph is found. */
3286 x_right_overwritten (s
)
3287 struct glyph_string
*s
;
3291 if (s
->right_overhang
)
3294 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3295 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3296 int end
= s
->row
->used
[s
->area
];
3298 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3299 x
+= glyphs
[i
].pixel_width
;
3308 /* Return the index of the last glyph following glyph string S that
3309 overwrites S because of its left overhang. Value is negative
3310 if no such glyph is found. */
3313 x_right_overwriting (s
)
3314 struct glyph_string
*s
;
3317 int end
= s
->row
->used
[s
->area
];
3318 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3319 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3323 for (i
= first
; i
< end
; ++i
)
3326 w32_get_glyph_overhangs (s
->hdc
, glyphs
+ i
, s
->f
, &left
, &right
);
3329 x
+= glyphs
[i
].pixel_width
;
3336 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3339 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3340 struct glyph_string
*s
;
3348 /* Take clipping into account. */
3349 if (s
->gc
->clip_mask
== Rect
)
3351 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
3352 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
3353 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
3354 - s
->gc
->clip_rectangle
.left
);
3355 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
3356 - s
->gc
->clip_rectangle
.top
);
3359 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
3364 /* Draw the background of glyph_string S. If S->background_filled_p
3365 is non-zero don't draw it. FORCE_P non-zero means draw the
3366 background even if it wouldn't be drawn normally. This is used
3367 when a string preceding S draws into the background of S, or S
3368 contains the first component of a composition. */
3371 x_draw_glyph_string_background (s
, force_p
)
3372 struct glyph_string
*s
;
3375 /* Nothing to do if background has already been drawn or if it
3376 shouldn't be drawn in the first place. */
3377 if (!s
->background_filled_p
)
3379 int box_line_width
= max (s
->face
->box_line_width
, 0);
3381 #if 0 /* TODO: stipple */
3384 /* Fill background with a stipple pattern. */
3385 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3386 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3387 s
->y
+ box_line_width
,
3388 s
->background_width
,
3389 s
->height
- 2 * box_line_width
);
3390 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3391 s
->background_filled_p
= 1;
3395 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3396 || s
->font_not_found_p
3397 || s
->extends_to_end_of_line_p
3401 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3402 s
->background_width
,
3403 s
->height
- 2 * box_line_width
);
3404 s
->background_filled_p
= 1;
3410 /* Draw the foreground of glyph string S. */
3413 x_draw_glyph_string_foreground (s
)
3414 struct glyph_string
*s
;
3419 /* If first glyph of S has a left box line, start drawing the text
3420 of S to the right of that box line. */
3421 if (s
->face
->box
!= FACE_NO_BOX
3422 && s
->first_glyph
->left_box_line_p
)
3423 x
= s
->x
+ abs (s
->face
->box_line_width
);
3427 if (s
->for_overlaps_p
|| (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3428 SetBkMode (s
->hdc
, TRANSPARENT
);
3430 SetBkMode (s
->hdc
, OPAQUE
);
3432 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3433 SetBkColor (s
->hdc
, s
->gc
->background
);
3434 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3436 if (s
->font
&& s
->font
->hfont
)
3437 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3439 /* Draw characters of S as rectangles if S's font could not be
3441 if (s
->font_not_found_p
)
3443 for (i
= 0; i
< s
->nchars
; ++i
)
3445 struct glyph
*g
= s
->first_glyph
+ i
;
3447 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3449 x
+= g
->pixel_width
;
3454 char *char1b
= (char *) s
->char2b
;
3455 int boff
= s
->font_info
->baseline_offset
;
3457 if (s
->font_info
->vertical_centering
)
3458 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3460 /* If we can use 8-bit functions, condense S->char2b. */
3462 for (i
= 0; i
< s
->nchars
; ++i
)
3463 char1b
[i
] = BYTE2 (s
->char2b
[i
]);
3465 /* Draw text with TextOut and friends. */
3466 W32_TEXTOUT (s
, x
, s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3468 if (s
->font
&& s
->font
->hfont
)
3469 SelectObject (s
->hdc
, old_font
);
3472 /* Draw the foreground of composite glyph string S. */
3475 x_draw_composite_glyph_string_foreground (s
)
3476 struct glyph_string
*s
;
3481 /* If first glyph of S has a left box line, start drawing the text
3482 of S to the right of that box line. */
3483 if (s
->face
->box
!= FACE_NO_BOX
3484 && s
->first_glyph
->left_box_line_p
)
3485 x
= s
->x
+ abs (s
->face
->box_line_width
);
3489 /* S is a glyph string for a composition. S->gidx is the index of
3490 the first character drawn for glyphs of this composition.
3491 S->gidx == 0 means we are drawing the very first character of
3492 this composition. */
3494 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3495 SetBkColor (s
->hdc
, s
->gc
->background
);
3496 SetBkMode (s
->hdc
, TRANSPARENT
);
3497 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
3499 if (s
->font
&& s
->font
->hfont
)
3500 old_font
= SelectObject (s
->hdc
, s
->font
->hfont
);
3502 /* Draw a rectangle for the composition if the font for the very
3503 first character of the composition could not be loaded. */
3504 if (s
->font_not_found_p
)
3507 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
3512 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3513 W32_TEXTOUT (s
, x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3514 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3517 if (s
->font
&& s
->font
->hfont
)
3518 SelectObject (s
->hdc
, old_font
);
3522 /* Brightness beyond which a color won't have its highlight brightness
3525 Nominally, highlight colors for `3d' faces are calculated by
3526 brightening an object's color by a constant scale factor, but this
3527 doesn't yield good results for dark colors, so for colors who's
3528 brightness is less than this value (on a scale of 0-255) have to
3529 use an additional additive factor.
3531 The value here is set so that the default menu-bar/mode-line color
3532 (grey75) will not have its highlights changed at all. */
3533 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
3536 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
3537 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3538 If this produces the same color as COLOR, try a color where all RGB
3539 values have DELTA added. Return the allocated color in *COLOR.
3540 DISPLAY is the X display, CMAP is the colormap to operate on.
3541 Value is non-zero if successful. */
3544 w32_alloc_lighter_color (f
, color
, factor
, delta
)
3553 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
3556 /* Change RGB values by specified FACTOR. Avoid overflow! */
3557 xassert (factor
>= 0);
3558 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
3559 min (0xff, factor
* GetGValue (*color
)),
3560 min (0xff, factor
* GetBValue (*color
)));
3562 /* Calculate brightness of COLOR. */
3563 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
3564 + GetBValue (*color
)) / 6;
3566 /* We only boost colors that are darker than
3567 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3568 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3569 /* Make an additive adjustment to NEW, because it's dark enough so
3570 that scaling by FACTOR alone isn't enough. */
3572 /* How far below the limit this color is (0 - 1, 1 being darker). */
3573 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3574 /* The additive adjustment. */
3575 int min_delta
= delta
* dimness
* factor
/ 2;
3578 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
3579 max (0, min (0xff, min_delta
- GetGValue (*color
))),
3580 max (0, min (0xff, min_delta
- GetBValue (*color
))));
3582 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
3583 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
3584 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
3588 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
3589 max (0, min (0xff, delta
+ GetGValue (*color
))),
3590 max (0, min (0xff, delta
+ GetBValue (*color
))));
3592 /* TODO: Map to palette and retry with delta if same? */
3593 /* TODO: Free colors (if using palette)? */
3604 /* Set up the foreground color for drawing relief lines of glyph
3605 string S. RELIEF is a pointer to a struct relief containing the GC
3606 with which lines will be drawn. Use a color that is FACTOR or
3607 DELTA lighter or darker than the relief's background which is found
3608 in S->f->output_data.x->relief_background. If such a color cannot
3609 be allocated, use DEFAULT_PIXEL, instead. */
3612 w32_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3614 struct relief
*relief
;
3617 COLORREF default_pixel
;
3620 struct w32_output
*di
= f
->output_data
.w32
;
3621 unsigned long mask
= GCForeground
;
3623 COLORREF background
= di
->relief_background
;
3624 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
3626 /* TODO: Free colors (if using palette)? */
3628 /* Allocate new color. */
3629 xgcv
.foreground
= default_pixel
;
3631 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
3633 relief
->allocated_p
= 1;
3634 xgcv
.foreground
= relief
->pixel
= pixel
;
3637 if (relief
->gc
== 0)
3639 #if 0 /* TODO: stipple */
3640 xgcv
.stipple
= dpyinfo
->gray
;
3643 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
3646 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
3650 /* Set up colors for the relief lines around glyph string S. */
3653 x_setup_relief_colors (s
)
3654 struct glyph_string
*s
;
3656 struct w32_output
*di
= s
->f
->output_data
.w32
;
3659 if (s
->face
->use_box_color_for_shadows_p
)
3660 color
= s
->face
->box_color
;
3662 color
= s
->gc
->background
;
3664 if (di
->white_relief
.gc
== 0
3665 || color
!= di
->relief_background
)
3667 di
->relief_background
= color
;
3668 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3669 WHITE_PIX_DEFAULT (s
->f
));
3670 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3671 BLACK_PIX_DEFAULT (s
->f
));
3676 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3677 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3678 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3679 relief. LEFT_P non-zero means draw a relief on the left side of
3680 the rectangle. RIGHT_P non-zero means draw a relief on the right
3681 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3685 w32_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3686 raised_p
, left_p
, right_p
, clip_rect
)
3688 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3693 HDC hdc
= get_frame_dc (f
);
3696 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3698 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3700 w32_set_clip_rectangle (hdc
, clip_rect
);
3703 for (i
= 0; i
< width
; ++i
)
3705 w32_fill_area (f
, hdc
, gc
.foreground
,
3706 left_x
+ i
* left_p
, top_y
+ i
,
3707 (right_x
+ 1 - i
* right_p
) - (left_x
+ i
* left_p
), 1);
3712 for (i
= 0; i
< width
; ++i
)
3714 w32_fill_area (f
, hdc
, gc
.foreground
,
3715 left_x
+ i
, top_y
+ i
, 1,
3716 (bottom_y
- i
) - (top_y
+ i
));
3719 w32_set_clip_rectangle (hdc
, NULL
);
3722 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
3724 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
3727 w32_set_clip_rectangle (hdc
, clip_rect
);
3730 for (i
= 0; i
< width
; ++i
)
3732 w32_fill_area (f
, hdc
, gc
.foreground
,
3733 left_x
+ i
* left_p
, bottom_y
- i
,
3734 (right_x
+ 1 - i
* right_p
) - left_x
+ i
* left_p
, 1);
3739 for (i
= 0; i
< width
; ++i
)
3741 w32_fill_area (f
, hdc
, gc
.foreground
,
3742 right_x
- i
, top_y
+ i
+ 1, 1,
3743 (bottom_y
- i
) - (top_y
+ i
+ 1));
3746 w32_set_clip_rectangle (hdc
, NULL
);
3748 release_frame_dc (f
, hdc
);
3752 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3753 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3754 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3755 left side of the rectangle. RIGHT_P non-zero means draw a line
3756 on the right side of the rectangle. CLIP_RECT is the clipping
3757 rectangle to use when drawing. */
3760 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3761 left_p
, right_p
, clip_rect
)
3762 struct glyph_string
*s
;
3763 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3766 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
3769 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3770 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3775 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3776 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3780 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3781 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3786 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
3787 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3790 w32_set_clip_rectangle (s
->hdc
, NULL
);
3794 /* Draw a box around glyph string S. */
3797 x_draw_glyph_string_box (s
)
3798 struct glyph_string
*s
;
3800 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3801 int left_p
, right_p
;
3802 struct glyph
*last_glyph
;
3805 last_x
= window_box_right (s
->w
, s
->area
);
3806 if (s
->row
->full_width_p
3807 && !s
->w
->pseudo_window_p
)
3809 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3810 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3811 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3814 /* The glyph that may have a right box line. */
3815 last_glyph
= (s
->cmp
|| s
->img
3817 : s
->first_glyph
+ s
->nchars
- 1);
3819 width
= abs (s
->face
->box_line_width
);
3820 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3822 right_x
= ((s
->row
->full_width_p
3824 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3826 bottom_y
= top_y
+ s
->height
- 1;
3828 left_p
= (s
->first_glyph
->left_box_line_p
3829 || (s
->hl
== DRAW_MOUSE_FACE
3831 || s
->prev
->hl
!= s
->hl
)));
3832 right_p
= (last_glyph
->right_box_line_p
3833 || (s
->hl
== DRAW_MOUSE_FACE
3835 || s
->next
->hl
!= s
->hl
)));
3837 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3839 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3840 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3841 left_p
, right_p
, &clip_rect
);
3844 x_setup_relief_colors (s
);
3845 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3846 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3851 /* Draw foreground of image glyph string S. */
3854 x_draw_image_foreground (s
)
3855 struct glyph_string
*s
;
3858 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3860 /* If first glyph of S has a left box line, start drawing it to the
3861 right of that line. */
3862 if (s
->face
->box
!= FACE_NO_BOX
3863 && s
->first_glyph
->left_box_line_p
)
3864 x
= s
->x
+ abs (s
->face
->box_line_width
);
3868 /* If there is a margin around the image, adjust x- and y-position
3870 x
+= s
->img
->hmargin
;
3871 y
+= s
->img
->vmargin
;
3877 #if 0 /* TODO: image mask */
3880 /* We can't set both a clip mask and use XSetClipRectangles
3881 because the latter also sets a clip mask. We also can't
3882 trust on the shape extension to be available
3883 (XShapeCombineRegion). So, compute the rectangle to draw
3885 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3888 XRectangle clip_rect
, image_rect
, r
;
3890 xgcv
.clip_mask
= s
->img
->mask
;
3891 xgcv
.clip_x_origin
= x
;
3892 xgcv
.clip_y_origin
= y
;
3893 xgcv
.function
= GXcopy
;
3894 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3896 w32_get_glyph_string_clip_rect (s
, &clip_rect
);
3899 image_rect
.width
= s
->img
->width
;
3900 image_rect
.height
= s
->img
->height
;
3901 if (IntersectRect (&r
, &clip_rect
, &image_rect
))
3902 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3903 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3908 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
3909 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
3910 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
3911 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
3912 x_set_glyph_string_clipping (s
);
3914 SetTextColor (s
->hdc
, s
->gc
->foreground
);
3915 SetBkColor (s
->hdc
, s
->gc
->background
);
3916 #if 0 /* From w32bdf.c (which is from Meadow). */
3917 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3918 compat_hdc
, 0, 0, SRCCOPY
);
3919 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3920 compat_hdc
, 0, 0, 0xB8074A);
3922 BitBlt (s
->hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
3923 compat_hdc
, 0, 0, 0xE20746);
3925 SelectObject (s
->hdc
, orig_brush
);
3926 DeleteObject (fg_brush
);
3927 SelectObject (compat_hdc
, orig_obj
);
3928 DeleteDC (compat_hdc
);
3930 /* When the image has a mask, we can expect that at
3931 least part of a mouse highlight or a block cursor will
3932 be visible. If the image doesn't have a mask, make
3933 a block cursor visible by drawing a rectangle around
3934 the image. I believe it's looking better if we do
3935 nothing here for mouse-face. */
3936 if (s
->hl
== DRAW_CURSOR
)
3937 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
3938 s
->img
->height
- 1);
3939 w32_set_clip_rectangle (s
->hdc
, NULL
);
3943 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
, s
->img
->width
-1,
3944 s
->img
->height
- 1);
3946 RestoreDC (s
->hdc
,-1);
3951 /* Draw a relief around the image glyph string S. */
3954 x_draw_image_relief (s
)
3955 struct glyph_string
*s
;
3957 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3960 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3962 /* If first glyph of S has a left box line, start drawing it to the
3963 right of that line. */
3964 if (s
->face
->box
!= FACE_NO_BOX
3965 && s
->first_glyph
->left_box_line_p
)
3966 x
= s
->x
+ abs (s
->face
->box_line_width
);
3970 /* If there is a margin around the image, adjust x- and y-position
3972 x
+= s
->img
->hmargin
;
3973 y
+= s
->img
->vmargin
;
3975 if (s
->hl
== DRAW_IMAGE_SUNKEN
3976 || s
->hl
== DRAW_IMAGE_RAISED
)
3978 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3979 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3983 thick
= abs (s
->img
->relief
);
3984 raised_p
= s
->img
->relief
> 0;
3989 x1
= x
+ s
->img
->width
+ thick
- 1;
3990 y1
= y
+ s
->img
->height
+ thick
- 1;
3992 x_setup_relief_colors (s
);
3993 w32_get_glyph_string_clip_rect (s
, &r
);
3994 w32_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3998 /* Draw the foreground of image glyph string S to PIXMAP. */
4001 w32_draw_image_foreground_1 (s
, pixmap
)
4002 struct glyph_string
*s
;
4005 HDC hdc
= CreateCompatibleDC (s
->hdc
);
4006 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
4008 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4010 /* If first glyph of S has a left box line, start drawing it to the
4011 right of that line. */
4012 if (s
->face
->box
!= FACE_NO_BOX
4013 && s
->first_glyph
->left_box_line_p
)
4014 x
= abs (s
->face
->box_line_width
);
4018 /* If there is a margin around the image, adjust x- and y-position
4020 x
+= s
->img
->hmargin
;
4021 y
+= s
->img
->vmargin
;
4025 #if 0 /* TODO: image mask */
4028 /* We can't set both a clip mask and use XSetClipRectangles
4029 because the latter also sets a clip mask. We also can't
4030 trust on the shape extension to be available
4031 (XShapeCombineRegion). So, compute the rectangle to draw
4033 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4037 xgcv
.clip_mask
= s
->img
->mask
;
4038 xgcv
.clip_x_origin
= x
;
4039 xgcv
.clip_y_origin
= y
;
4040 xgcv
.function
= GXcopy
;
4041 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4043 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4044 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4045 XSetClipMask (s
->display
, s
->gc
, None
);
4050 HDC compat_hdc
= CreateCompatibleDC (hdc
);
4051 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4052 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
4053 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
4055 SetTextColor (hdc
, s
->gc
->foreground
);
4056 SetBkColor (hdc
, s
->gc
->background
);
4057 #if 0 /* From w32bdf.c (which is from Meadow). */
4058 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4059 compat_hdc
, 0, 0, SRCCOPY
);
4060 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4061 compat_hdc
, 0, 0, 0xB8074A);
4063 BitBlt (hdc
, x
, y
, s
->img
->width
, s
->img
->height
,
4064 compat_hdc
, 0, 0, 0xE20746);
4066 SelectObject (hdc
, orig_brush
);
4067 DeleteObject (fg_brush
);
4068 SelectObject (compat_hdc
, orig_obj
);
4069 DeleteDC (compat_hdc
);
4071 /* When the image has a mask, we can expect that at
4072 least part of a mouse highlight or a block cursor will
4073 be visible. If the image doesn't have a mask, make
4074 a block cursor visible by drawing a rectangle around
4075 the image. I believe it's looking better if we do
4076 nothing here for mouse-face. */
4077 if (s
->hl
== DRAW_CURSOR
)
4078 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4079 s
->img
->height
- 1);
4083 w32_draw_rectangle (hdc
, s
->gc
, x
, y
, s
->img
->width
- 1,
4084 s
->img
->height
- 1);
4086 SelectObject (hdc
, orig_hdc_obj
);
4091 /* Draw part of the background of glyph string S. X, Y, W, and H
4092 give the rectangle to draw. */
4095 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4096 struct glyph_string
*s
;
4099 #if 0 /* TODO: stipple */
4102 /* Fill background with a stipple pattern. */
4103 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4104 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4105 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4109 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4113 /* Draw image glyph string S.
4116 s->x +-------------------------
4119 | +-------------------------
4122 | | +-------------------
4128 x_draw_image_glyph_string (s
)
4129 struct glyph_string
*s
;
4132 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4133 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4137 height
= s
->height
- 2 * box_line_vwidth
;
4139 /* Fill background with face under the image. Do it only if row is
4140 taller than image or if image has a clip mask to reduce
4142 s
->stippled_p
= s
->face
->stipple
!= 0;
4143 if (height
> s
->img
->height
4146 #if 0 /* TODO: image mask */
4149 || s
->img
->pixmap
== 0
4150 || s
->width
!= s
->background_width
)
4152 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4153 x
= s
->x
+ box_line_hwidth
;
4157 y
= s
->y
+ box_line_vwidth
;
4158 #if 0 /* TODO: image mask */
4161 /* Create a pixmap as large as the glyph string. Fill it
4162 with the background color. Copy the image to it, using
4163 its mask. Copy the temporary pixmap to the display. */
4164 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4165 int depth
= DefaultDepthOfScreen (screen
);
4167 /* Create a pixmap as large as the glyph string. */
4168 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4169 s
->background_width
,
4172 /* Don't clip in the following because we're working on the
4174 XSetClipMask (s
->display
, s
->gc
, None
);
4176 /* Fill the pixmap with the background color/stipple. */
4179 /* Fill background with a stipple pattern. */
4180 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4181 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4182 0, 0, s
->background_width
, s
->height
);
4183 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4188 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4190 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4191 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4192 0, 0, s
->background_width
, s
->height
);
4193 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4198 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4200 s
->background_filled_p
= 1;
4203 /* Draw the foreground. */
4206 w32_draw_image_foreground_1 (s
, pixmap
);
4207 x_set_glyph_string_clipping (s
);
4209 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
4210 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
4211 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
4212 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
4214 SetTextColor (s
->hdc
, s
->gc
->foreground
);
4215 SetBkColor (s
->hdc
, s
->gc
->background
);
4216 #if 0 /* From w32bdf.c (which is from Meadow). */
4217 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4218 compat_hdc
, 0, 0, SRCCOPY
);
4219 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4220 compat_hdc
, 0, 0, 0xB8074A);
4222 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
4223 compat_hdc
, 0, 0, 0xE20746);
4225 SelectObject (s
->hdc
, orig_brush
);
4226 DeleteObject (fg_brush
);
4227 SelectObject (compat_hdc
, orig_obj
);
4228 DeleteDC (compat_hdc
);
4230 DeleteObject (pixmap
);
4234 x_draw_image_foreground (s
);
4236 /* If we must draw a relief around the image, do it. */
4238 || s
->hl
== DRAW_IMAGE_RAISED
4239 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4240 x_draw_image_relief (s
);
4244 /* Draw stretch glyph string S. */
4247 x_draw_stretch_glyph_string (s
)
4248 struct glyph_string
*s
;
4250 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4251 s
->stippled_p
= s
->face
->stipple
!= 0;
4253 if (s
->hl
== DRAW_CURSOR
4254 && !x_stretch_cursor_p
)
4256 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4257 as wide as the stretch glyph. */
4258 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4261 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4263 /* Clear rest using the GC of the original non-cursor face. */
4264 if (width
< s
->background_width
)
4266 XGCValues
*gc
= s
->face
->gc
;
4267 int x
= s
->x
+ width
, y
= s
->y
;
4268 int w
= s
->background_width
- width
, h
= s
->height
;
4271 w32_get_glyph_string_clip_rect (s
, &r
);
4272 w32_set_clip_rectangle (hdc
, &r
);
4274 #if 0 /* TODO: stipple */
4275 if (s
->face
->stipple
)
4277 /* Fill background with a stipple pattern. */
4278 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4279 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4280 XSetFillStyle (s
->display
, gc
, FillSolid
);
4285 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
4290 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4293 s
->background_filled_p
= 1;
4297 /* Draw glyph string S. */
4300 x_draw_glyph_string (s
)
4301 struct glyph_string
*s
;
4303 /* If S draws into the background of its successor, draw the
4304 background of the successor first so that S can draw into it.
4305 This makes S->next use XDrawString instead of XDrawImageString. */
4306 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4308 xassert (s
->next
->img
== NULL
);
4309 x_set_glyph_string_gc (s
->next
);
4310 x_set_glyph_string_clipping (s
->next
);
4311 x_draw_glyph_string_background (s
->next
, 1);
4314 /* Set up S->gc, set clipping and draw S. */
4315 x_set_glyph_string_gc (s
);
4316 x_set_glyph_string_clipping (s
);
4318 switch (s
->first_glyph
->type
)
4321 x_draw_image_glyph_string (s
);
4325 x_draw_stretch_glyph_string (s
);
4329 if (s
->for_overlaps_p
)
4330 s
->background_filled_p
= 1;
4332 x_draw_glyph_string_background (s
, 0);
4333 x_draw_glyph_string_foreground (s
);
4336 case COMPOSITE_GLYPH
:
4337 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4338 s
->background_filled_p
= 1;
4340 x_draw_glyph_string_background (s
, 1);
4341 x_draw_composite_glyph_string_foreground (s
);
4348 if (!s
->for_overlaps_p
)
4350 /* Draw underline. */
4351 if (s
->face
->underline_p
4352 && (s
->font
->bdf
|| !s
->font
->tm
.tmUnderlined
))
4354 unsigned long h
= 1;
4355 unsigned long dy
= s
->height
- h
;
4357 if (s
->face
->underline_defaulted_p
)
4359 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4360 s
->y
+ dy
, s
->width
, 1);
4364 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4365 s
->y
+ dy
, s
->width
, 1);
4369 /* Draw overline. */
4370 if (s
->face
->overline_p
)
4372 unsigned long dy
= 0, h
= 1;
4374 if (s
->face
->overline_color_defaulted_p
)
4376 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4377 s
->y
+ dy
, s
->width
, h
);
4381 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4382 s
->y
+ dy
, s
->width
, h
);
4386 /* Draw strike-through. */
4387 if (s
->face
->strike_through_p
4388 && (s
->font
->bdf
|| !s
->font
->tm
.tmStruckOut
))
4390 unsigned long h
= 1;
4391 unsigned long dy
= (s
->height
- h
) / 2;
4393 if (s
->face
->strike_through_color_defaulted_p
)
4395 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
4400 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4401 s
->y
+ dy
, s
->width
, h
);
4406 if (s
->face
->box
!= FACE_NO_BOX
)
4407 x_draw_glyph_string_box (s
);
4410 /* Reset clipping. */
4411 w32_set_clip_rectangle (s
->hdc
, NULL
);
4415 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4416 struct face
**, int));
4419 /* Fill glyph string S with composition components specified by S->cmp.
4421 FACES is an array of faces for all components of this composition.
4422 S->gidx is the index of the first component for S.
4423 OVERLAPS_P non-zero means S should draw the foreground only, and
4424 use its physical height for clipping.
4426 Value is the index of a component not in S. */
4429 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4430 struct glyph_string
*s
;
4431 struct face
**faces
;
4438 s
->for_overlaps_p
= overlaps_p
;
4440 s
->face
= faces
[s
->gidx
];
4441 s
->font
= s
->face
->font
;
4442 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4444 /* For all glyphs of this composition, starting at the offset
4445 S->gidx, until we reach the end of the definition or encounter a
4446 glyph that requires the different face, add it to S. */
4448 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4451 /* All glyph strings for the same composition has the same width,
4452 i.e. the width set for the first component of the composition. */
4454 s
->width
= s
->first_glyph
->pixel_width
;
4456 /* If the specified font could not be loaded, use the frame's
4457 default font, but record the fact that we couldn't load it in
4458 the glyph string so that we can draw rectangles for the
4459 characters of the glyph string. */
4460 if (s
->font
== NULL
)
4462 s
->font_not_found_p
= 1;
4463 s
->font
= FRAME_FONT (s
->f
);
4466 /* Adjust base line for subscript/superscript text. */
4467 s
->ybase
+= s
->first_glyph
->voffset
;
4469 xassert (s
->face
&& s
->face
->gc
);
4471 /* This glyph string must always be drawn with 16-bit functions. */
4474 return s
->gidx
+ s
->nchars
;
4478 /* Fill glyph string S from a sequence of character glyphs.
4480 FACE_ID is the face id of the string. START is the index of the
4481 first glyph to consider, END is the index of the last + 1.
4482 OVERLAPS_P non-zero means S should draw the foreground only, and
4483 use its physical height for clipping.
4485 Value is the index of the first glyph not in S. */
4488 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4489 struct glyph_string
*s
;
4491 int start
, end
, overlaps_p
;
4493 struct glyph
*glyph
, *last
;
4495 int glyph_not_available_p
;
4497 xassert (s
->f
== XFRAME (s
->w
->frame
));
4498 xassert (s
->nchars
== 0);
4499 xassert (start
>= 0 && end
> start
);
4501 s
->for_overlaps_p
= overlaps_p
;
4502 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4503 last
= s
->row
->glyphs
[s
->area
] + end
;
4504 voffset
= glyph
->voffset
;
4506 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4509 && glyph
->type
== CHAR_GLYPH
4510 && glyph
->voffset
== voffset
4511 /* Same face id implies same font, nowadays. */
4512 && glyph
->face_id
== face_id
4513 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4517 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4518 s
->char2b
+ s
->nchars
,
4520 s
->two_byte_p
= two_byte_p
;
4522 xassert (s
->nchars
<= end
- start
);
4523 s
->width
+= glyph
->pixel_width
;
4527 s
->font
= s
->face
->font
;
4528 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4530 /* If the specified font could not be loaded, use the frame's font,
4531 but record the fact that we couldn't load it in
4532 S->font_not_found_p so that we can draw rectangles for the
4533 characters of the glyph string. */
4534 if (s
->font
== NULL
|| glyph_not_available_p
)
4536 s
->font_not_found_p
= 1;
4537 s
->font
= FRAME_FONT (s
->f
);
4540 /* Adjust base line for subscript/superscript text. */
4541 s
->ybase
+= voffset
;
4543 xassert (s
->face
&& s
->face
->gc
);
4544 return glyph
- s
->row
->glyphs
[s
->area
];
4548 /* Fill glyph string S from image glyph S->first_glyph. */
4551 x_fill_image_glyph_string (s
)
4552 struct glyph_string
*s
;
4554 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4555 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4557 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4558 s
->font
= s
->face
->font
;
4559 s
->width
= s
->first_glyph
->pixel_width
;
4561 /* Adjust base line for subscript/superscript text. */
4562 s
->ybase
+= s
->first_glyph
->voffset
;
4566 /* Fill glyph string S from a sequence of stretch glyphs.
4568 ROW is the glyph row in which the glyphs are found, AREA is the
4569 area within the row. START is the index of the first glyph to
4570 consider, END is the index of the last + 1.
4572 Value is the index of the first glyph not in S. */
4575 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4576 struct glyph_string
*s
;
4577 struct glyph_row
*row
;
4578 enum glyph_row_area area
;
4581 struct glyph
*glyph
, *last
;
4582 int voffset
, face_id
;
4584 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4586 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4587 last
= s
->row
->glyphs
[s
->area
] + end
;
4588 face_id
= glyph
->face_id
;
4589 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4590 s
->font
= s
->face
->font
;
4591 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4592 s
->width
= glyph
->pixel_width
;
4593 voffset
= glyph
->voffset
;
4597 && glyph
->type
== STRETCH_GLYPH
4598 && glyph
->voffset
== voffset
4599 && glyph
->face_id
== face_id
);
4601 s
->width
+= glyph
->pixel_width
;
4603 /* Adjust base line for subscript/superscript text. */
4604 s
->ybase
+= voffset
;
4606 xassert (s
->face
&& s
->face
->gc
);
4607 return glyph
- s
->row
->glyphs
[s
->area
];
4611 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4612 of XChar2b structures for S; it can't be allocated in
4613 x_init_glyph_string because it must be allocated via `alloca'. W
4614 is the window on which S is drawn. ROW and AREA are the glyph row
4615 and area within the row from which S is constructed. START is the
4616 index of the first glyph structure covered by S. HL is a
4617 face-override for drawing S. */
4620 w32_init_glyph_string (s
, hdc
, char2b
, w
, row
, area
, start
, hl
)
4621 struct glyph_string
*s
;
4625 struct glyph_row
*row
;
4626 enum glyph_row_area area
;
4628 enum draw_glyphs_face hl
;
4630 bzero (s
, sizeof *s
);
4632 s
->f
= XFRAME (w
->frame
);
4634 s
->window
= FRAME_W32_WINDOW (s
->f
);
4639 s
->first_glyph
= row
->glyphs
[area
] + start
;
4640 s
->height
= row
->height
;
4641 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4643 /* Display the internal border below the tool-bar window. */
4644 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4645 s
->y
-= s
->f
->output_data
.w32
->internal_border_width
;
4647 s
->ybase
= s
->y
+ row
->ascent
;
4651 /* Set background width of glyph string S. START is the index of the
4652 first glyph following S. LAST_X is the right-most x-position + 1
4653 in the drawing area. */
4656 x_set_glyph_string_background_width (s
, start
, last_x
)
4657 struct glyph_string
*s
;
4661 /* If the face of this glyph string has to be drawn to the end of
4662 the drawing area, set S->extends_to_end_of_line_p. */
4663 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4665 if (start
== s
->row
->used
[s
->area
]
4666 && s
->hl
== DRAW_NORMAL_TEXT
4667 && s
->area
== TEXT_AREA
4668 && (s
->row
->fill_line_p
4669 || s
->face
->background
!= default_face
->background
4670 || s
->face
->stipple
!= default_face
->stipple
))
4671 s
->extends_to_end_of_line_p
= 1;
4673 /* If S extends its face to the end of the line, set its
4674 background_width to the distance to the right edge of the drawing
4676 if (s
->extends_to_end_of_line_p
)
4677 s
->background_width
= last_x
- s
->x
+ 1;
4679 s
->background_width
= s
->width
;
4683 /* Add a glyph string for a stretch glyph to the list of strings
4684 between HEAD and TAIL. START is the index of the stretch glyph in
4685 row area AREA of glyph row ROW. END is the index of the last glyph
4686 in that glyph row area. X is the current output position assigned
4687 to the new glyph string constructed. HL overrides that face of the
4688 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4689 is the right-most x-position of the drawing area. */
4691 #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4694 s = (struct glyph_string *) alloca (sizeof *s); \
4695 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4696 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4697 x_append_glyph_string (&HEAD, &TAIL, s); \
4703 /* Add a glyph string for an image glyph to the list of strings
4704 between HEAD and TAIL. START is the index of the image glyph in
4705 row area AREA of glyph row ROW. END is the index of the last glyph
4706 in that glyph row area. X is the current output position assigned
4707 to the new glyph string constructed. HL overrides that face of the
4708 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4709 is the right-most x-position of the drawing area. */
4711 #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4714 s = (struct glyph_string *) alloca (sizeof *s); \
4715 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4716 x_fill_image_glyph_string (s); \
4717 x_append_glyph_string (&HEAD, &TAIL, s); \
4724 /* Add a glyph string for a sequence of character glyphs to the list
4725 of strings between HEAD and TAIL. START is the index of the first
4726 glyph in row area AREA of glyph row ROW that is part of the new
4727 glyph string. END is the index of the last glyph in that glyph row
4728 area. X is the current output position assigned to the new glyph
4729 string constructed. HL overrides that face of the glyph; e.g. it
4730 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4731 right-most x-position of the drawing area. */
4733 #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4739 c = (ROW)->glyphs[AREA][START].u.ch; \
4740 face_id = (ROW)->glyphs[AREA][START].face_id; \
4742 s = (struct glyph_string *) alloca (sizeof *s); \
4743 char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \
4744 w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \
4745 x_append_glyph_string (&HEAD, &TAIL, s); \
4747 START = x_fill_glyph_string (s, face_id, START, END, \
4753 /* Add a glyph string for a composite sequence to the list of strings
4754 between HEAD and TAIL. START is the index of the first glyph in
4755 row area AREA of glyph row ROW that is part of the new glyph
4756 string. END is the index of the last glyph in that glyph row area.
4757 X is the current output position assigned to the new glyph string
4758 constructed. HL overrides that face of the glyph; e.g. it is
4759 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4760 x-position of the drawing area. */
4762 #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4764 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4765 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4766 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4767 struct composition *cmp = composition_table[cmp_id]; \
4768 int glyph_len = cmp->glyph_len; \
4770 struct face **faces; \
4771 struct glyph_string *first_s = NULL; \
4774 base_face = base_face->ascii_face; \
4775 char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \
4776 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4777 /* At first, fill in `char2b' and `faces'. */ \
4778 for (n = 0; n < glyph_len; n++) \
4780 int c = COMPOSITION_GLYPH (cmp, n); \
4781 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4782 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4783 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4784 this_face_id, char2b + n, 1); \
4787 /* Make glyph_strings for each glyph sequence that is drawable by \
4788 the same face, and append them to HEAD/TAIL. */ \
4789 for (n = 0; n < cmp->glyph_len;) \
4791 s = (struct glyph_string *) alloca (sizeof *s); \
4792 w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \
4793 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4801 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4809 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4810 of AREA of glyph row ROW on window W between indices START and END.
4811 HL overrides the face for drawing glyph strings, e.g. it is
4812 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4813 x-positions of the drawing area.
4815 This is an ugly monster macro construct because we must use alloca
4816 to allocate glyph strings (because x_draw_glyphs can be called
4819 #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4822 HEAD = TAIL = NULL; \
4823 while (START < END) \
4825 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4826 switch (first_glyph->type) \
4829 BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \
4830 HEAD, TAIL, HL, X, LAST_X, \
4834 case COMPOSITE_GLYPH: \
4835 BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \
4836 END, HEAD, TAIL, HL, X, \
4837 LAST_X, OVERLAPS_P); \
4840 case STRETCH_GLYPH: \
4841 BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\
4842 HEAD, TAIL, HL, X, LAST_X); \
4846 BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \
4847 HEAD, TAIL, HL, X, LAST_X); \
4854 x_set_glyph_string_background_width (s, START, LAST_X); \
4861 /* Draw glyphs between START and END in AREA of ROW on window W,
4862 starting at x-position X. X is relative to AREA in W. HL is a
4863 face-override with the following meaning:
4865 DRAW_NORMAL_TEXT draw normally
4866 DRAW_CURSOR draw in cursor face
4867 DRAW_MOUSE_FACE draw in mouse face.
4868 DRAW_INVERSE_VIDEO draw in mode line face
4869 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4870 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4872 If REAL_START is non-null, return in *REAL_START the real starting
4873 position for display. This can be different from START in case
4874 overlapping glyphs must be displayed. If REAL_END is non-null,
4875 return in *REAL_END the real end position for display. This can be
4876 different from END in case overlapping glyphs must be displayed.
4878 If OVERLAPS_P is non-zero, draw only the foreground of characters
4879 and clip to the physical height of ROW.
4881 Value is the x-position reached, relative to AREA of W. */
4884 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4888 struct glyph_row
*row
;
4889 enum glyph_row_area area
;
4891 enum draw_glyphs_face hl
;
4892 int *real_start
, *real_end
;
4895 struct glyph_string
*head
, *tail
;
4896 struct glyph_string
*s
;
4897 int last_x
, area_width
;
4900 HDC hdc
= get_frame_dc (XFRAME (WINDOW_FRAME (w
)));
4902 /* Let's rather be paranoid than getting a SEGV. */
4903 end
= min (end
, row
->used
[area
]);
4904 start
= max (0, start
);
4905 start
= min (end
, start
);
4907 *real_start
= start
;
4911 /* Translate X to frame coordinates. Set last_x to the right
4912 end of the drawing area. */
4913 if (row
->full_width_p
)
4915 /* X is relative to the left edge of W, without scroll bars
4917 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4918 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4919 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4922 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4923 last_x
= window_left_x
+ area_width
;
4925 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4927 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4928 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4934 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4935 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4939 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4940 area_width
= window_box_width (w
, area
);
4941 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4944 /* Build a doubly-linked list of glyph_string structures between
4945 head and tail from what we have to draw. Note that the macro
4946 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4947 the reason we use a separate variable `i'. */
4949 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4952 x_reached
= tail
->x
+ tail
->background_width
;
4956 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4957 the row, redraw some glyphs in front or following the glyph
4958 strings built above. */
4959 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4962 struct glyph_string
*h
, *t
;
4964 /* Compute overhangs for all glyph strings. */
4965 for (s
= head
; s
; s
= s
->next
)
4966 x_compute_glyph_string_overhangs (s
);
4968 /* Prepend glyph strings for glyphs in front of the first glyph
4969 string that are overwritten because of the first glyph
4970 string's left overhang. The background of all strings
4971 prepended must be drawn because the first glyph string
4973 i
= x_left_overwritten (head
);
4977 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, j
, start
, h
, t
,
4978 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4982 *real_start
= start
;
4983 x_compute_overhangs_and_x (t
, head
->x
, 1);
4984 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4987 /* Prepend glyph strings for glyphs in front of the first glyph
4988 string that overwrite that glyph string because of their
4989 right overhang. For these strings, only the foreground must
4990 be drawn, because it draws over the glyph string at `head'.
4991 The background must not be drawn because this would overwrite
4992 right overhangs of preceding glyphs for which no glyph
4994 i
= x_left_overwriting (head
);
4997 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, start
, h
, t
,
4998 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5000 for (s
= h
; s
; s
= s
->next
)
5001 s
->background_filled_p
= 1;
5004 x_compute_overhangs_and_x (t
, head
->x
, 1);
5005 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5008 /* Append glyphs strings for glyphs following the last glyph
5009 string tail that are overwritten by tail. The background of
5010 these strings has to be drawn because tail's foreground draws
5012 i
= x_right_overwritten (tail
);
5015 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5016 DRAW_NORMAL_TEXT
, x
, last_x
,
5018 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5019 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5024 /* Append glyph strings for glyphs following the last glyph
5025 string tail that overwrite tail. The foreground of such
5026 glyphs has to be drawn because it writes into the background
5027 of tail. The background must not be drawn because it could
5028 paint over the foreground of following glyphs. */
5029 i
= x_right_overwriting (tail
);
5032 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5033 DRAW_NORMAL_TEXT
, x
, last_x
,
5035 for (s
= h
; s
; s
= s
->next
)
5036 s
->background_filled_p
= 1;
5037 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5038 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5044 /* Draw all strings. */
5045 for (s
= head
; s
; s
= s
->next
)
5046 x_draw_glyph_string (s
);
5048 /* Value is the x-position up to which drawn, relative to AREA of W.
5049 This doesn't include parts drawn because of overhangs. */
5050 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5051 if (!row
->full_width_p
)
5053 if (area
> LEFT_MARGIN_AREA
)
5054 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5055 if (area
> TEXT_AREA
)
5056 x_reached
-= window_box_width (w
, TEXT_AREA
);
5059 release_frame_dc (XFRAME (WINDOW_FRAME (w
)), hdc
);
5065 /* Fix the display of area AREA of overlapping row ROW in window W. */
5068 x_fix_overlapping_area (w
, row
, area
)
5070 struct glyph_row
*row
;
5071 enum glyph_row_area area
;
5077 if (area
== LEFT_MARGIN_AREA
)
5079 else if (area
== TEXT_AREA
)
5080 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5082 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5083 + window_box_width (w
, TEXT_AREA
));
5085 for (i
= 0; i
< row
->used
[area
];)
5087 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5089 int start
= i
, start_x
= x
;
5093 x
+= row
->glyphs
[area
][i
].pixel_width
;
5096 while (i
< row
->used
[area
]
5097 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5099 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5101 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5106 x
+= row
->glyphs
[area
][i
].pixel_width
;
5115 /* Output LEN glyphs starting at START at the nominal cursor position.
5116 Advance the nominal cursor over the text. The global variable
5117 updated_window contains the window being updated, updated_row is
5118 the glyph row being updated, and updated_area is the area of that
5119 row being updated. */
5122 x_write_glyphs (start
, len
)
5123 struct glyph
*start
;
5126 int x
, hpos
, real_start
, real_end
;
5128 xassert (updated_window
&& updated_row
);
5133 hpos
= start
- updated_row
->glyphs
[updated_area
];
5134 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5135 updated_row
, updated_area
,
5137 (updated_row
->inverse_p
5138 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5139 &real_start
, &real_end
, 0);
5141 /* If we drew over the cursor, note that it is not visible any more. */
5142 note_overwritten_text_cursor (updated_window
, real_start
,
5143 real_end
- real_start
);
5147 /* Advance the output cursor. */
5148 output_cursor
.hpos
+= len
;
5149 output_cursor
.x
= x
;
5153 /* Insert LEN glyphs from START at the nominal cursor position. */
5156 x_insert_glyphs (start
, len
)
5157 struct glyph
*start
;
5162 int line_height
, shift_by_width
, shifted_region_width
;
5163 struct glyph_row
*row
;
5164 struct glyph
*glyph
;
5165 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5168 xassert (updated_window
&& updated_row
);
5171 f
= XFRAME (WINDOW_FRAME (w
));
5172 hdc
= get_frame_dc (f
);
5174 /* Get the height of the line we are in. */
5176 line_height
= row
->height
;
5178 /* Get the width of the glyphs to insert. */
5180 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5181 shift_by_width
+= glyph
->pixel_width
;
5183 /* Get the width of the region to shift right. */
5184 shifted_region_width
= (window_box_width (w
, updated_area
)
5189 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5190 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5191 BitBlt (hdc
, frame_x
+ shift_by_width
, frame_y
,
5192 shifted_region_width
, line_height
,
5193 hdc
, frame_x
, frame_y
, SRCCOPY
);
5195 /* Write the glyphs. */
5196 hpos
= start
- row
->glyphs
[updated_area
];
5197 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5198 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5199 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5201 /* Advance the output cursor. */
5202 output_cursor
.hpos
+= len
;
5203 output_cursor
.x
+= shift_by_width
;
5204 release_frame_dc (f
, hdc
);
5210 /* Delete N glyphs at the nominal cursor position. Not implemented
5222 f
= SELECTED_FRAME ();
5224 if (! FRAME_W32_P (f
))
5231 /* Erase the current text line from the nominal cursor position
5232 (inclusive) to pixel column TO_X (exclusive). The idea is that
5233 everything from TO_X onward is already erased.
5235 TO_X is a pixel position relative to updated_area of
5236 updated_window. TO_X == -1 means clear to the end of this area. */
5239 x_clear_end_of_line (to_x
)
5243 struct window
*w
= updated_window
;
5244 int max_x
, min_y
, max_y
;
5245 int from_x
, from_y
, to_y
;
5247 xassert (updated_window
&& updated_row
);
5248 f
= XFRAME (w
->frame
);
5250 if (updated_row
->full_width_p
)
5252 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5253 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5254 && !w
->pseudo_window_p
)
5255 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5258 max_x
= window_box_width (w
, updated_area
);
5259 max_y
= window_text_bottom_y (w
);
5261 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5262 of window. For TO_X > 0, truncate to end of drawing area. */
5268 to_x
= min (to_x
, max_x
);
5270 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5272 /* Notice if the cursor will be cleared by this operation. */
5273 if (!updated_row
->full_width_p
)
5274 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5276 from_x
= output_cursor
.x
;
5278 /* Translate to frame coordinates. */
5279 if (updated_row
->full_width_p
)
5281 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5282 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5286 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5287 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5290 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5291 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5292 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5294 /* Prevent inadvertently clearing to end of the X window. */
5295 if (to_x
> from_x
&& to_y
> from_y
)
5299 hdc
= get_frame_dc (f
);
5301 w32_clear_area (f
, hdc
, from_x
, from_y
, to_x
- from_x
, to_y
- from_y
);
5302 release_frame_dc (f
, hdc
);
5308 /* Clear entire frame. If updating_frame is non-null, clear that
5309 frame. Otherwise clear the selected frame. */
5319 f
= SELECTED_FRAME ();
5321 if (! FRAME_W32_P (f
))
5324 /* Clearing the frame will erase any cursor, so mark them all as no
5326 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5327 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5328 output_cursor
.x
= -1;
5330 /* We don't set the output cursor here because there will always
5331 follow an explicit cursor_to. */
5334 w32_clear_window (f
);
5336 /* We have to clear the scroll bars, too. If we have changed
5337 colors or something like that, then they should be notified. */
5338 x_scroll_bar_clear (f
);
5344 /* Make audible bell. */
5347 w32_ring_bell (void)
5351 f
= SELECTED_FRAME ();
5355 if (FRAME_W32_P (f
) && visible_bell
)
5358 HWND hwnd
= FRAME_W32_WINDOW (SELECTED_FRAME ());
5360 for (i
= 0; i
< 5; i
++)
5362 FlashWindow (hwnd
, TRUE
);
5365 FlashWindow (hwnd
, FALSE
);
5368 w32_sys_ring_bell ();
5374 /* Specify how many text lines, from the top of the window,
5375 should be affected by insert-lines and delete-lines operations.
5376 This, and those operations, are used only within an update
5377 that is bounded by calls to x_update_begin and x_update_end. */
5380 w32_set_terminal_window (n
)
5383 /* This function intentionally left blank. */
5388 /***********************************************************************
5390 ***********************************************************************/
5392 /* Perform an insert-lines or delete-lines operation, inserting N
5393 lines or deleting -N lines at vertical position VPOS. */
5396 x_ins_del_lines (vpos
, n
)
5404 f
= SELECTED_FRAME ();
5406 if (! FRAME_W32_P (f
))
5413 /* Scroll part of the display as described by RUN. */
5416 x_scroll_run (w
, run
)
5420 struct frame
*f
= XFRAME (w
->frame
);
5421 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5422 HDC hdc
= get_frame_dc (f
);
5424 /* Get frame-relative bounding box of the text display area of W,
5425 without mode lines. Include in this box the flags areas to the
5426 left and right of W. */
5427 window_box (w
, -1, &x
, &y
, &width
, &height
);
5428 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5429 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5431 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5432 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5433 bottom_y
= y
+ height
;
5437 /* Scrolling up. Make sure we don't copy part of the mode
5438 line at the bottom. */
5439 if (from_y
+ run
->height
> bottom_y
)
5440 height
= bottom_y
- from_y
;
5442 height
= run
->height
;
5446 /* Scolling down. Make sure we don't copy over the mode line.
5448 if (to_y
+ run
->height
> bottom_y
)
5449 height
= bottom_y
- to_y
;
5451 height
= run
->height
;
5456 /* Cursor off. Will be switched on again in x_update_window_end. */
5460 BitBlt (hdc
, x
, to_y
, width
, height
, hdc
, x
, from_y
, SRCCOPY
);
5463 release_frame_dc (f
, hdc
);
5468 /***********************************************************************
5470 ***********************************************************************/
5472 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5473 corner of the exposed rectangle. W and H are width and height of
5474 the exposed area. All are pixel values. W or H zero means redraw
5475 the entire frame. */
5478 expose_frame (f
, x
, y
, w
, h
)
5484 TRACE ((stderr
, "expose_frame "));
5486 /* No need to redraw if frame will be redrawn soon. */
5487 if (FRAME_GARBAGED_P (f
))
5489 TRACE ((stderr
, " garbaged\n"));
5493 /* If basic faces haven't been realized yet, there is no point in
5494 trying to redraw anything. This can happen when we get an expose
5495 event while Emacs is starting, e.g. by moving another window. */
5496 if (FRAME_FACE_CACHE (f
) == NULL
5497 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5499 TRACE ((stderr
, " no faces\n"));
5503 if (w
== 0 || h
== 0)
5506 r
.right
= CANON_X_UNIT (f
) * f
->width
;
5507 r
.bottom
= CANON_Y_UNIT (f
) * f
->height
;
5517 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.left
, r
.top
, r
.right
, r
.bottom
));
5518 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5520 if (WINDOWP (f
->tool_bar_window
))
5522 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5524 RECT intersection_rect
;
5525 int window_x
, window_y
, window_width
, window_height
;
5527 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5528 window_rect
.left
= window_x
;
5529 window_rect
.top
= window_y
;
5530 window_rect
.right
= window_x
+ window_width
;
5531 window_rect
.bottom
= window_y
+ window_height
;
5533 if (IntersectRect (&intersection_rect
, &r
, &window_rect
))
5534 expose_window (w
, &intersection_rect
);
5539 /* Redraw (parts) of all windows in the window tree rooted at W that
5540 intersect R. R contains frame pixel coordinates. */
5543 expose_window_tree (w
, r
)
5549 if (!NILP (w
->hchild
))
5550 expose_window_tree (XWINDOW (w
->hchild
), r
);
5551 else if (!NILP (w
->vchild
))
5552 expose_window_tree (XWINDOW (w
->vchild
), r
);
5556 RECT intersection_rect
;
5557 struct frame
*f
= XFRAME (w
->frame
);
5558 int window_x
, window_y
, window_width
, window_height
;
5560 /* Frame-relative pixel rectangle of W. */
5561 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5565 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5566 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_Y_UNIT (f
));
5567 window_rect
.top
= window_y
;
5568 window_rect
.right
= window_rect
.left
5570 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5571 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5572 window_rect
.bottom
= window_rect
.top
5573 + window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5575 if (IntersectRect (&intersection_rect
, r
, &window_rect
))
5576 expose_window (w
, &intersection_rect
);
5579 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5584 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5585 which intersects rectangle R. R is in window-relative coordinates. */
5588 expose_area (w
, row
, r
, area
)
5590 struct glyph_row
*row
;
5592 enum glyph_row_area area
;
5594 struct glyph
*first
= row
->glyphs
[area
];
5595 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5597 int first_x
, start_x
, x
;
5599 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5600 /* If row extends face to end of line write the whole line. */
5601 x_draw_glyphs (w
, 0, row
, area
,
5603 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5607 /* Set START_X to the window-relative start position for drawing glyphs of
5608 AREA. The first glyph of the text area can be partially visible.
5609 The first glyphs of other areas cannot. */
5610 if (area
== LEFT_MARGIN_AREA
)
5612 else if (area
== TEXT_AREA
)
5613 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5615 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5616 + window_box_width (w
, TEXT_AREA
));
5619 /* Find the first glyph that must be redrawn. */
5621 && x
+ first
->pixel_width
< r
->left
)
5623 x
+= first
->pixel_width
;
5627 /* Find the last one. */
5633 x
+= last
->pixel_width
;
5639 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5640 first
- row
->glyphs
[area
],
5641 last
- row
->glyphs
[area
],
5642 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5648 /* Redraw the parts of the glyph row ROW on window W intersecting
5649 rectangle R. R is in window-relative coordinates. */
5652 expose_line (w
, row
, r
)
5654 struct glyph_row
*row
;
5657 xassert (row
->enabled_p
);
5659 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5660 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5661 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5665 if (row
->used
[LEFT_MARGIN_AREA
])
5666 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5667 if (row
->used
[TEXT_AREA
])
5668 expose_area (w
, row
, r
, TEXT_AREA
);
5669 if (row
->used
[RIGHT_MARGIN_AREA
])
5670 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5671 x_draw_row_bitmaps (w
, row
);
5676 /* Return non-zero if W's cursor intersects rectangle R. */
5679 x_phys_cursor_in_rect_p (w
, r
)
5684 struct glyph
*cursor_glyph
;
5686 cursor_glyph
= get_phys_cursor_glyph (w
);
5689 cr
.left
= w
->phys_cursor
.x
;
5690 cr
.top
= w
->phys_cursor
.y
;
5691 cr
.right
= cr
.left
+ cursor_glyph
->pixel_width
;
5692 cr
.bottom
= cr
.top
+ w
->phys_cursor_height
;
5693 return IntersectRect (&result
, &cr
, r
);
5700 /* Redraw a rectangle of window W. R is a rectangle in window
5701 relative coordinates. Call this function with input blocked. */
5704 expose_window (w
, r
)
5708 struct glyph_row
*row
;
5710 int yb
= window_text_bottom_y (w
);
5711 int cursor_cleared_p
;
5713 /* If window is not yet fully initialized, do nothing. This can
5714 happen when toolkit scroll bars are used and a window is split.
5715 Reconfiguring the scroll bar will generate an expose for a newly
5717 if (w
->current_matrix
== NULL
|| w
== updated_window
)
5720 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5721 r
->left
, r
->top
, r
->right
, r
->bottom
));
5723 /* Convert to window coordinates. */
5724 r
->left
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->left
);
5725 r
->top
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->top
);
5726 r
->right
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->right
);
5727 r
->bottom
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->bottom
);
5729 /* Turn off the cursor. */
5730 if (!w
->pseudo_window_p
5731 && x_phys_cursor_in_rect_p (w
, r
))
5734 cursor_cleared_p
= 1;
5737 cursor_cleared_p
= 0;
5739 /* Find the first row intersecting the rectangle R. */
5740 row
= w
->current_matrix
->rows
;
5742 while (row
->enabled_p
5744 && y
+ row
->height
< r
->top
)
5750 /* Display the text in the rectangle, one text line at a time. */
5751 while (row
->enabled_p
5755 expose_line (w
, row
, r
);
5760 /* Display the mode line if there is one. */
5761 if (WINDOW_WANTS_MODELINE_P (w
)
5762 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5764 && row
->y
< r
->bottom
)
5765 expose_line (w
, row
, r
);
5767 if (!w
->pseudo_window_p
)
5769 /* Draw border between windows. */
5770 x_draw_vertical_border (w
);
5772 /* Turn the cursor on again. */
5773 if (cursor_cleared_p
)
5774 x_update_window_cursor (w
, 1);
5783 x_update_cursor (f
, 1);
5787 frame_unhighlight (f
)
5790 x_update_cursor (f
, 1);
5793 /* The focus has changed. Update the frames as necessary to reflect
5794 the new situation. Note that we can't change the selected frame
5795 here, because the Lisp code we are interrupting might become confused.
5796 Each event gets marked with the frame in which it occurred, so the
5797 Lisp code can tell when the switch took place by examining the events. */
5800 x_new_focus_frame (dpyinfo
, frame
)
5801 struct w32_display_info
*dpyinfo
;
5802 struct frame
*frame
;
5804 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
5806 if (frame
!= dpyinfo
->w32_focus_frame
)
5808 /* Set this before calling other routines, so that they see
5809 the correct value of w32_focus_frame. */
5810 dpyinfo
->w32_focus_frame
= frame
;
5812 if (old_focus
&& old_focus
->auto_lower
)
5813 x_lower_frame (old_focus
);
5815 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
5816 pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
5818 pending_autoraise_frame
= 0;
5821 x_frame_rehighlight (dpyinfo
);
5824 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5827 x_mouse_leave (dpyinfo
)
5828 struct w32_display_info
*dpyinfo
;
5830 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
5833 /* The focus has changed, or we have redirected a frame's focus to
5834 another frame (this happens when a frame uses a surrogate
5835 mini-buffer frame). Shift the highlight as appropriate.
5837 The FRAME argument doesn't necessarily have anything to do with which
5838 frame is being highlighted or un-highlighted; we only use it to find
5839 the appropriate X display info. */
5842 w32_frame_rehighlight (frame
)
5843 struct frame
*frame
;
5845 if (! FRAME_W32_P (frame
))
5847 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame
));
5851 x_frame_rehighlight (dpyinfo
)
5852 struct w32_display_info
*dpyinfo
;
5854 struct frame
*old_highlight
= dpyinfo
->w32_highlight_frame
;
5856 if (dpyinfo
->w32_focus_frame
)
5858 dpyinfo
->w32_highlight_frame
5859 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
5860 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
5861 : dpyinfo
->w32_focus_frame
);
5862 if (! FRAME_LIVE_P (dpyinfo
->w32_highlight_frame
))
5864 FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
) = Qnil
;
5865 dpyinfo
->w32_highlight_frame
= dpyinfo
->w32_focus_frame
;
5869 dpyinfo
->w32_highlight_frame
= 0;
5871 if (dpyinfo
->w32_highlight_frame
!= old_highlight
)
5874 frame_unhighlight (old_highlight
);
5875 if (dpyinfo
->w32_highlight_frame
)
5876 frame_highlight (dpyinfo
->w32_highlight_frame
);
5880 /* Keyboard processing - modifier keys, etc. */
5882 /* Convert a keysym to its name. */
5885 x_get_keysym_name (keysym
)
5888 /* Make static so we can always return it */
5889 static char value
[100];
5892 GetKeyNameText (keysym
, value
, 100);
5900 /* Mouse clicks and mouse movement. Rah. */
5902 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5903 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5904 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5905 not force the value into range. */
5908 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5910 register int pix_x
, pix_y
;
5911 register int *x
, *y
;
5915 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
5916 if (NILP (Vwindow_system
))
5923 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5924 even for negative values. */
5926 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
5928 pix_y
-= (f
)->output_data
.w32
->line_height
- 1;
5930 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5931 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5935 bounds
->left
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5936 bounds
->top
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5937 bounds
->right
= bounds
->left
+ FONT_WIDTH (FRAME_FONT (f
)) - 1;
5938 bounds
->bottom
= bounds
->top
+ f
->output_data
.w32
->line_height
- 1;
5945 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5946 pix_x
= FRAME_WINDOW_WIDTH (f
);
5950 else if (pix_y
> f
->height
)
5959 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5960 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5961 can't tell the positions because W's display is not up to date,
5965 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
5968 int *frame_x
, *frame_y
;
5972 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
5973 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
5975 if (display_completed
)
5977 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5978 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
5979 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
5985 *frame_x
+= glyph
->pixel_width
;
5993 *frame_y
= *frame_x
= 0;
5997 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
5998 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6003 parse_button (message
, pbutton
, pup
)
6013 case WM_LBUTTONDOWN
:
6021 case WM_MBUTTONDOWN
:
6022 if (NILP (Vw32_swap_mouse_buttons
))
6029 if (NILP (Vw32_swap_mouse_buttons
))
6035 case WM_RBUTTONDOWN
:
6036 if (NILP (Vw32_swap_mouse_buttons
))
6043 if (NILP (Vw32_swap_mouse_buttons
))
6054 if (pbutton
) *pbutton
= button
;
6060 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6062 If the event is a button press, then note that we have grabbed
6066 construct_mouse_click (result
, msg
, f
)
6067 struct input_event
*result
;
6074 parse_button (msg
->msg
.message
, &button
, &up
);
6076 /* Make the event type no_event; we'll change that when we decide
6078 result
->kind
= mouse_click
;
6079 result
->code
= button
;
6080 result
->timestamp
= msg
->msg
.time
;
6081 result
->modifiers
= (msg
->dwModifiers
6086 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
6087 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
6088 XSETFRAME (result
->frame_or_window
, f
);
6094 construct_mouse_wheel (result
, msg
, f
)
6095 struct input_event
*result
;
6100 result
->kind
= mouse_wheel
;
6101 result
->code
= (short) HIWORD (msg
->msg
.wParam
);
6102 result
->timestamp
= msg
->msg
.time
;
6103 result
->modifiers
= msg
->dwModifiers
;
6104 p
.x
= LOWORD (msg
->msg
.lParam
);
6105 p
.y
= HIWORD (msg
->msg
.lParam
);
6106 ScreenToClient (msg
->msg
.hwnd
, &p
);
6107 XSETINT (result
->x
, p
.x
);
6108 XSETINT (result
->y
, p
.y
);
6109 XSETFRAME (result
->frame_or_window
, f
);
6115 construct_drag_n_drop (result
, msg
, f
)
6116 struct input_event
*result
;
6128 result
->kind
= drag_n_drop
;
6130 result
->timestamp
= msg
->msg
.time
;
6131 result
->modifiers
= msg
->dwModifiers
;
6133 hdrop
= (HDROP
) msg
->msg
.wParam
;
6134 DragQueryPoint (hdrop
, &p
);
6137 p
.x
= LOWORD (msg
->msg
.lParam
);
6138 p
.y
= HIWORD (msg
->msg
.lParam
);
6139 ScreenToClient (msg
->msg
.hwnd
, &p
);
6142 XSETINT (result
->x
, p
.x
);
6143 XSETINT (result
->y
, p
.y
);
6145 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
6148 for (i
= 0; i
< num_files
; i
++)
6150 len
= DragQueryFile (hdrop
, i
, NULL
, 0);
6153 name
= alloca (len
+ 1);
6154 DragQueryFile (hdrop
, i
, name
, len
+ 1);
6155 files
= Fcons (build_string (name
), files
);
6160 XSETFRAME (frame
, f
);
6161 result
->frame_or_window
= Fcons (frame
, files
);
6167 /* Function to report a mouse movement to the mainstream Emacs code.
6168 The input handler calls this.
6170 We have received a mouse movement event, which is given in *event.
6171 If the mouse is over a different glyph than it was last time, tell
6172 the mainstream emacs code by setting mouse_moved. If not, ask for
6173 another motion event, so we can check again the next time it moves. */
6175 static MSG last_mouse_motion_event
;
6176 static Lisp_Object last_mouse_motion_frame
;
6179 note_mouse_movement (frame
, msg
)
6183 last_mouse_movement_time
= msg
->time
;
6184 memcpy (&last_mouse_motion_event
, msg
, sizeof (last_mouse_motion_event
));
6185 XSETFRAME (last_mouse_motion_frame
, frame
);
6187 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
6189 frame
->mouse_moved
= 1;
6190 last_mouse_scroll_bar
= Qnil
;
6191 note_mouse_highlight (frame
, -1, -1);
6194 /* Has the mouse moved off the glyph it was on at the last sighting? */
6195 else if (LOWORD (msg
->lParam
) < last_mouse_glyph
.left
6196 || LOWORD (msg
->lParam
) > last_mouse_glyph
.right
6197 || HIWORD (msg
->lParam
) < last_mouse_glyph
.top
6198 || HIWORD (msg
->lParam
) > last_mouse_glyph
.bottom
)
6200 frame
->mouse_moved
= 1;
6201 last_mouse_scroll_bar
= Qnil
;
6202 note_mouse_highlight (frame
, LOWORD (msg
->lParam
), HIWORD (msg
->lParam
));
6206 /* This is used for debugging, to turn off note_mouse_highlight. */
6208 int disable_mouse_highlight
;
6212 /************************************************************************
6214 ************************************************************************/
6216 /* Find the glyph under window-relative coordinates X/Y in window W.
6217 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6218 strings. Return in *HPOS and *VPOS the row and column number of
6219 the glyph found. Return in *AREA the glyph area containing X.
6220 Value is a pointer to the glyph found or null if X/Y is not on
6221 text, or we can't tell because W's current matrix is not up to
6224 static struct glyph
*
6225 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6228 int *hpos
, *vpos
, *area
;
6230 struct glyph
*glyph
, *end
;
6231 struct glyph_row
*row
= NULL
;
6232 int x0
, i
, left_area_width
;
6234 /* Find row containing Y. Give up if some row is not enabled. */
6235 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6237 row
= MATRIX_ROW (w
->current_matrix
, i
);
6238 if (!row
->enabled_p
)
6240 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6247 /* Give up if Y is not in the window. */
6248 if (i
== w
->current_matrix
->nrows
)
6251 /* Get the glyph area containing X. */
6252 if (w
->pseudo_window_p
)
6259 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6260 if (x
< left_area_width
)
6262 *area
= LEFT_MARGIN_AREA
;
6265 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6268 x0
= row
->x
+ left_area_width
;
6272 *area
= RIGHT_MARGIN_AREA
;
6273 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6277 /* Find glyph containing X. */
6278 glyph
= row
->glyphs
[*area
];
6279 end
= glyph
+ row
->used
[*area
];
6282 if (x
< x0
+ glyph
->pixel_width
)
6284 if (w
->pseudo_window_p
)
6286 else if (BUFFERP (glyph
->object
))
6290 x0
+= glyph
->pixel_width
;
6297 *hpos
= glyph
- row
->glyphs
[*area
];
6302 /* Convert frame-relative x/y to coordinates relative to window W.
6303 Takes pseudo-windows into account. */
6306 frame_to_window_pixel_xy (w
, x
, y
)
6310 if (w
->pseudo_window_p
)
6312 /* A pseudo-window is always full-width, and starts at the
6313 left edge of the frame, plus a frame border. */
6314 struct frame
*f
= XFRAME (w
->frame
);
6315 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6316 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6320 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6321 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6326 /* Take proper action when mouse has moved to the mode or header line of
6327 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6328 mode line. X is relative to the start of the text display area of
6329 W, so the width of bitmap areas and scroll bars must be subtracted
6330 to get a position relative to the start of the mode line. */
6333 note_mode_line_highlight (w
, x
, mode_line_p
)
6337 struct frame
*f
= XFRAME (w
->frame
);
6338 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6339 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6340 struct glyph_row
*row
;
6343 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6345 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6349 struct glyph
*glyph
, *end
;
6350 Lisp_Object help
, map
;
6353 /* Find the glyph under X. */
6354 glyph
= row
->glyphs
[TEXT_AREA
];
6355 end
= glyph
+ row
->used
[TEXT_AREA
];
6356 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6357 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6360 && x
>= x0
+ glyph
->pixel_width
)
6362 x0
+= glyph
->pixel_width
;
6367 && STRINGP (glyph
->object
)
6368 && XSTRING (glyph
->object
)->intervals
6369 && glyph
->charpos
>= 0
6370 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6372 /* If we're on a string with `help-echo' text property,
6373 arrange for the help to be displayed. This is done by
6374 setting the global variable help_echo to the help string. */
6375 help
= Fget_text_property (make_number (glyph
->charpos
),
6376 Qhelp_echo
, glyph
->object
);
6380 XSETWINDOW (help_echo_window
, w
);
6381 help_echo_object
= glyph
->object
;
6382 help_echo_pos
= glyph
->charpos
;
6385 /* Change the mouse pointer according to what is under X/Y. */
6386 map
= Fget_text_property (make_number (glyph
->charpos
),
6387 Qlocal_map
, glyph
->object
);
6389 cursor
= f
->output_data
.w32
->nontext_cursor
;
6392 map
= Fget_text_property (make_number (glyph
->charpos
),
6393 Qkeymap
, glyph
->object
);
6395 cursor
= f
->output_data
.w32
->nontext_cursor
;
6400 #if 0 /* TODO: mouse cursor */
6401 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6406 /* Take proper action when the mouse has moved to position X, Y on
6407 frame F as regards highlighting characters that have mouse-face
6408 properties. Also de-highlighting chars where the mouse was before.
6409 X and Y can be negative or out of range. */
6412 note_mouse_highlight (f
, x
, y
)
6416 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6421 /* When a menu is active, don't highlight because this looks odd. */
6422 if (popup_activated ())
6425 if (disable_mouse_highlight
6426 || !f
->glyphs_initialized_p
)
6429 dpyinfo
->mouse_face_mouse_x
= x
;
6430 dpyinfo
->mouse_face_mouse_y
= y
;
6431 dpyinfo
->mouse_face_mouse_frame
= f
;
6433 if (dpyinfo
->mouse_face_defer
)
6438 dpyinfo
->mouse_face_deferred_gc
= 1;
6442 /* Which window is that in? */
6443 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6445 /* If we were displaying active text in another window, clear that. */
6446 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6447 clear_mouse_face (dpyinfo
);
6449 /* Not on a window -> return. */
6450 if (!WINDOWP (window
))
6453 /* Convert to window-relative pixel coordinates. */
6454 w
= XWINDOW (window
);
6455 frame_to_window_pixel_xy (w
, &x
, &y
);
6457 /* Handle tool-bar window differently since it doesn't display a
6459 if (EQ (window
, f
->tool_bar_window
))
6461 note_tool_bar_highlight (f
, x
, y
);
6465 if (portion
== 1 || portion
== 3)
6467 /* Mouse is on the mode or top line. */
6468 note_mode_line_highlight (w
, x
, portion
== 1);
6471 #if 0 /* TODO: mouse cursor */
6472 else if (portion
== 2)
6473 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6474 f
->output_data
.x
->horizontal_drag_cursor
);
6476 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6477 f
->output_data
.x
->text_cursor
);
6480 /* Are we in a window whose display is up to date?
6481 And verify the buffer's text has not changed. */
6482 if (/* Within text portion of the window. */
6484 && EQ (w
->window_end_valid
, w
->buffer
)
6485 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6486 && (XFASTINT (w
->last_overlay_modified
)
6487 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6489 int hpos
, vpos
, pos
, i
, area
;
6490 struct glyph
*glyph
;
6492 /* Find the glyph under X/Y. */
6493 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6495 /* Clear mouse face if X/Y not over text. */
6497 || area
!= TEXT_AREA
6498 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6500 clear_mouse_face (dpyinfo
);
6504 pos
= glyph
->charpos
;
6505 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6507 /* Check for mouse-face and help-echo. */
6509 Lisp_Object mouse_face
, overlay
, position
;
6510 Lisp_Object
*overlay_vec
;
6512 struct buffer
*obuf
;
6515 /* If we get an out-of-range value, return now; avoid an error. */
6516 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6519 /* Make the window's buffer temporarily current for
6520 overlays_at and compute_char_face. */
6521 obuf
= current_buffer
;
6522 current_buffer
= XBUFFER (w
->buffer
);
6528 /* Is this char mouse-active or does it have help-echo? */
6529 XSETINT (position
, pos
);
6531 /* Put all the overlays we want in a vector in overlay_vec.
6532 Store the length in len. If there are more than 10, make
6533 enough space for all, and try again. */
6535 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6536 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6537 if (noverlays
> len
)
6540 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6541 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6544 /* Sort overlays into increasing priority order. */
6545 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6547 /* Check mouse-face highlighting. */
6548 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6549 && vpos
>= dpyinfo
->mouse_face_beg_row
6550 && vpos
<= dpyinfo
->mouse_face_end_row
6551 && (vpos
> dpyinfo
->mouse_face_beg_row
6552 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6553 && (vpos
< dpyinfo
->mouse_face_end_row
6554 || hpos
< dpyinfo
->mouse_face_end_col
6555 || dpyinfo
->mouse_face_past_end
)))
6557 /* Clear the display of the old active region, if any. */
6558 clear_mouse_face (dpyinfo
);
6560 /* Find the highest priority overlay that has a mouse-face prop. */
6562 for (i
= noverlays
- 1; i
>= 0; --i
)
6564 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6565 if (!NILP (mouse_face
))
6567 overlay
= overlay_vec
[i
];
6572 /* If no overlay applies, get a text property. */
6574 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6576 /* Handle the overlay case. */
6577 if (! NILP (overlay
))
6579 /* Find the range of text around this char that
6580 should be active. */
6581 Lisp_Object before
, after
;
6584 before
= Foverlay_start (overlay
);
6585 after
= Foverlay_end (overlay
);
6586 /* Record this as the current active region. */
6587 fast_find_position (w
, XFASTINT (before
),
6588 &dpyinfo
->mouse_face_beg_col
,
6589 &dpyinfo
->mouse_face_beg_row
,
6590 &dpyinfo
->mouse_face_beg_x
,
6591 &dpyinfo
->mouse_face_beg_y
);
6592 dpyinfo
->mouse_face_past_end
6593 = !fast_find_position (w
, XFASTINT (after
),
6594 &dpyinfo
->mouse_face_end_col
,
6595 &dpyinfo
->mouse_face_end_row
,
6596 &dpyinfo
->mouse_face_end_x
,
6597 &dpyinfo
->mouse_face_end_y
);
6598 dpyinfo
->mouse_face_window
= window
;
6599 dpyinfo
->mouse_face_face_id
6600 = face_at_buffer_position (w
, pos
, 0, 0,
6601 &ignore
, pos
+ 1, 1);
6603 /* Display it as active. */
6604 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6606 /* Handle the text property case. */
6607 else if (! NILP (mouse_face
))
6609 /* Find the range of text around this char that
6610 should be active. */
6611 Lisp_Object before
, after
, beginning
, end
;
6614 beginning
= Fmarker_position (w
->start
);
6615 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6616 - XFASTINT (w
->window_end_pos
)));
6618 = Fprevious_single_property_change (make_number (pos
+ 1),
6620 w
->buffer
, beginning
);
6622 = Fnext_single_property_change (position
, Qmouse_face
,
6624 /* Record this as the current active region. */
6625 fast_find_position (w
, XFASTINT (before
),
6626 &dpyinfo
->mouse_face_beg_col
,
6627 &dpyinfo
->mouse_face_beg_row
,
6628 &dpyinfo
->mouse_face_beg_x
,
6629 &dpyinfo
->mouse_face_beg_y
);
6630 dpyinfo
->mouse_face_past_end
6631 = !fast_find_position (w
, XFASTINT (after
),
6632 &dpyinfo
->mouse_face_end_col
,
6633 &dpyinfo
->mouse_face_end_row
,
6634 &dpyinfo
->mouse_face_end_x
,
6635 &dpyinfo
->mouse_face_end_y
);
6636 dpyinfo
->mouse_face_window
= window
;
6637 dpyinfo
->mouse_face_face_id
6638 = face_at_buffer_position (w
, pos
, 0, 0,
6639 &ignore
, pos
+ 1, 1);
6641 /* Display it as active. */
6642 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6646 /* Look for a `help-echo' property. */
6648 Lisp_Object help
, overlay
;
6650 /* Check overlays first. */
6651 help
= overlay
= Qnil
;
6652 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6654 overlay
= overlay_vec
[i
];
6655 help
= Foverlay_get (overlay
, Qhelp_echo
);
6661 help_echo_window
= window
;
6662 help_echo_object
= overlay
;
6663 help_echo_pos
= pos
;
6667 /* Try text properties. */
6668 if ((STRINGP (glyph
->object
)
6669 && glyph
->charpos
>= 0
6670 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6671 || (BUFFERP (glyph
->object
)
6672 && glyph
->charpos
>= BEGV
6673 && glyph
->charpos
< ZV
))
6674 help
= Fget_text_property (make_number (glyph
->charpos
),
6675 Qhelp_echo
, glyph
->object
);
6680 help_echo_window
= window
;
6681 help_echo_object
= glyph
->object
;
6682 help_echo_pos
= glyph
->charpos
;
6689 current_buffer
= obuf
;
6695 redo_mouse_highlight ()
6697 if (!NILP (last_mouse_motion_frame
)
6698 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6699 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6700 LOWORD (last_mouse_motion_event
.lParam
),
6701 HIWORD (last_mouse_motion_event
.lParam
));
6706 /***********************************************************************
6708 ***********************************************************************/
6710 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6711 struct glyph
**, int *, int *, int *));
6713 /* Tool-bar item index of the item on which a mouse button was pressed
6716 static int last_tool_bar_item
;
6719 /* Get information about the tool-bar item at position X/Y on frame F.
6720 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6721 the current matrix of the tool-bar window of F, or NULL if not
6722 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6723 item in F->tool_bar_items. Value is
6725 -1 if X/Y is not on a tool-bar item
6726 0 if X/Y is on the same item that was highlighted before.
6730 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6733 struct glyph
**glyph
;
6734 int *hpos
, *vpos
, *prop_idx
;
6736 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6737 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6740 /* Find the glyph under X/Y. */
6741 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6745 /* Get the start of this tool-bar item's properties in
6746 f->tool_bar_items. */
6747 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6750 /* Is mouse on the highlighted item? */
6751 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6752 && *vpos
>= dpyinfo
->mouse_face_beg_row
6753 && *vpos
<= dpyinfo
->mouse_face_end_row
6754 && (*vpos
> dpyinfo
->mouse_face_beg_row
6755 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6756 && (*vpos
< dpyinfo
->mouse_face_end_row
6757 || *hpos
< dpyinfo
->mouse_face_end_col
6758 || dpyinfo
->mouse_face_past_end
))
6765 /* Handle mouse button event on the tool-bar of frame F, at
6766 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6770 w32_handle_tool_bar_click (f
, button_event
)
6772 struct input_event
*button_event
;
6774 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6775 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6776 int hpos
, vpos
, prop_idx
;
6777 struct glyph
*glyph
;
6778 Lisp_Object enabled_p
;
6779 int x
= XFASTINT (button_event
->x
);
6780 int y
= XFASTINT (button_event
->y
);
6782 /* If not on the highlighted tool-bar item, return. */
6783 frame_to_window_pixel_xy (w
, &x
, &y
);
6784 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6787 /* If item is disabled, do nothing. */
6788 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6789 if (NILP (enabled_p
))
6792 if (button_event
->kind
== mouse_click
)
6794 /* Show item in pressed state. */
6795 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6796 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6797 last_tool_bar_item
= prop_idx
;
6801 Lisp_Object key
, frame
;
6802 struct input_event event
;
6804 /* Show item in released state. */
6805 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6806 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6808 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
6810 XSETFRAME (frame
, f
);
6811 event
.kind
= TOOL_BAR_EVENT
;
6812 event
.frame_or_window
= frame
;
6814 kbd_buffer_store_event (&event
);
6816 event
.kind
= TOOL_BAR_EVENT
;
6817 event
.frame_or_window
= frame
;
6819 event
.modifiers
= button_event
->modifiers
;
6820 kbd_buffer_store_event (&event
);
6821 last_tool_bar_item
= -1;
6826 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6827 tool-bar window-relative coordinates X/Y. Called from
6828 note_mouse_highlight. */
6831 note_tool_bar_highlight (f
, x
, y
)
6835 Lisp_Object window
= f
->tool_bar_window
;
6836 struct window
*w
= XWINDOW (window
);
6837 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6839 struct glyph
*glyph
;
6840 struct glyph_row
*row
;
6842 Lisp_Object enabled_p
;
6844 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6845 int mouse_down_p
, rc
;
6847 /* Function note_mouse_highlight is called with negative x(y
6848 values when mouse moves outside of the frame. */
6849 if (x
<= 0 || y
<= 0)
6851 clear_mouse_face (dpyinfo
);
6855 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6858 /* Not on tool-bar item. */
6859 clear_mouse_face (dpyinfo
);
6863 /* On same tool-bar item as before. */
6866 clear_mouse_face (dpyinfo
);
6868 /* Mouse is down, but on different tool-bar item? */
6869 mouse_down_p
= (dpyinfo
->grabbed
6870 && f
== last_mouse_frame
6871 && FRAME_LIVE_P (f
));
6873 && last_tool_bar_item
!= prop_idx
)
6876 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6877 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6879 /* If tool-bar item is not enabled, don't highlight it. */
6880 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6881 if (!NILP (enabled_p
))
6883 /* Compute the x-position of the glyph. In front and past the
6884 image is a space. We include this is the highlighted area. */
6885 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6886 for (i
= x
= 0; i
< hpos
; ++i
)
6887 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6889 /* Record this as the current active region. */
6890 dpyinfo
->mouse_face_beg_col
= hpos
;
6891 dpyinfo
->mouse_face_beg_row
= vpos
;
6892 dpyinfo
->mouse_face_beg_x
= x
;
6893 dpyinfo
->mouse_face_beg_y
= row
->y
;
6894 dpyinfo
->mouse_face_past_end
= 0;
6896 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6897 dpyinfo
->mouse_face_end_row
= vpos
;
6898 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6899 dpyinfo
->mouse_face_end_y
= row
->y
;
6900 dpyinfo
->mouse_face_window
= window
;
6901 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6903 /* Display it as active. */
6904 show_mouse_face (dpyinfo
, draw
);
6905 dpyinfo
->mouse_face_image_state
= draw
;
6910 /* Set help_echo to a help string.to display for this tool-bar item.
6911 w32_read_socket does the rest. */
6912 help_echo_object
= help_echo_window
= Qnil
;
6914 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
6915 if (NILP (help_echo
))
6916 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
6921 /* Find the glyph matrix position of buffer position POS in window W.
6922 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6923 current glyphs must be up to date. If POS is above window start
6924 return (0, 0, 0, 0). If POS is after end of W, return end of
6928 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6931 int *hpos
, *vpos
, *x
, *y
;
6935 int maybe_next_line_p
= 0;
6936 int line_start_position
;
6937 int yb
= window_text_bottom_y (w
);
6938 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6939 struct glyph_row
*best_row
= row
;
6940 int row_vpos
= 0, best_row_vpos
= 0;
6945 if (row
->used
[TEXT_AREA
])
6946 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6948 line_start_position
= 0;
6950 if (line_start_position
> pos
)
6952 /* If the position sought is the end of the buffer,
6953 don't include the blank lines at the bottom of the window. */
6954 else if (line_start_position
== pos
6955 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6957 maybe_next_line_p
= 1;
6960 else if (line_start_position
> 0)
6963 best_row_vpos
= row_vpos
;
6966 if (row
->y
+ row
->height
>= yb
)
6973 /* Find the right column within BEST_ROW. */
6975 current_x
= best_row
->x
;
6976 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6978 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6981 charpos
= glyph
->charpos
;
6985 *vpos
= best_row_vpos
;
6990 else if (charpos
> pos
)
6992 else if (charpos
> 0)
6995 current_x
+= glyph
->pixel_width
;
6998 /* If we're looking for the end of the buffer,
6999 and we didn't find it in the line we scanned,
7000 use the start of the following line. */
7001 if (maybe_next_line_p
)
7006 current_x
= best_row
->x
;
7009 *vpos
= best_row_vpos
;
7010 *hpos
= lastcol
+ 1;
7017 /* Display the active region described by mouse_face_*
7018 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7021 show_mouse_face (dpyinfo
, draw
)
7022 struct w32_display_info
*dpyinfo
;
7023 enum draw_glyphs_face draw
;
7025 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7026 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7028 int cursor_off_p
= 0;
7029 struct cursor_pos saved_cursor
;
7031 saved_cursor
= output_cursor
;
7033 /* If window is in the process of being destroyed, don't bother
7035 if (w
->current_matrix
== NULL
)
7038 /* Recognize when we are called to operate on rows that don't exist
7039 anymore. This can happen when a window is split. */
7040 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7043 set_output_cursor (&w
->phys_cursor
);
7045 /* Note that mouse_face_beg_row etc. are window relative. */
7046 for (i
= dpyinfo
->mouse_face_beg_row
;
7047 i
<= dpyinfo
->mouse_face_end_row
;
7050 int start_hpos
, end_hpos
, start_x
;
7051 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7053 /* Don't do anything if row doesn't have valid contents. */
7054 if (!row
->enabled_p
)
7057 /* For all but the first row, the highlight starts at column 0. */
7058 if (i
== dpyinfo
->mouse_face_beg_row
)
7060 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7061 start_x
= dpyinfo
->mouse_face_beg_x
;
7069 if (i
== dpyinfo
->mouse_face_end_row
)
7070 end_hpos
= dpyinfo
->mouse_face_end_col
;
7072 end_hpos
= row
->used
[TEXT_AREA
];
7074 /* If the cursor's in the text we are about to rewrite, turn the
7076 if (!w
->pseudo_window_p
7077 && i
== output_cursor
.vpos
7078 && output_cursor
.hpos
>= start_hpos
- 1
7079 && output_cursor
.hpos
<= end_hpos
)
7081 x_update_window_cursor (w
, 0);
7085 if (end_hpos
> start_hpos
)
7087 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7088 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7089 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7093 /* If we turned the cursor off, turn it back on. */
7095 x_display_cursor (w
, 1,
7096 output_cursor
.hpos
, output_cursor
.vpos
,
7097 output_cursor
.x
, output_cursor
.y
);
7099 output_cursor
= saved_cursor
;
7102 #if 0 /* TODO: mouse cursor */
7103 /* Change the mouse cursor. */
7104 if (draw
== DRAW_NORMAL_TEXT
)
7105 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7106 f
->output_data
.x
->text_cursor
);
7107 else if (draw
== DRAW_MOUSE_FACE
)
7108 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7109 f
->output_data
.x
->cross_cursor
);
7111 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7112 f
->output_data
.x
->nontext_cursor
);
7117 /* Clear out the mouse-highlighted active region.
7118 Redraw it un-highlighted first. */
7121 clear_mouse_face (dpyinfo
)
7122 struct w32_display_info
*dpyinfo
;
7124 #if 0 /* This prevents redrawing tool bar items when changing from one
7125 to another while a tooltip is open, so don't do it. */
7126 if (!NILP (tip_frame
))
7130 if (! NILP (dpyinfo
->mouse_face_window
))
7131 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7133 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7134 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7135 dpyinfo
->mouse_face_window
= Qnil
;
7139 /* Clear any mouse-face on window W. This function is part of the
7140 redisplay interface, and is called from try_window_id and similar
7141 functions to ensure the mouse-highlight is off. */
7144 x_clear_mouse_face (w
)
7147 struct w32_display_info
*dpyinfo
7148 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
7152 XSETWINDOW (window
, w
);
7153 if (EQ (window
, dpyinfo
->mouse_face_window
))
7154 clear_mouse_face (dpyinfo
);
7159 /* Just discard the mouse face information for frame F, if any.
7160 This is used when the size of F is changed. */
7163 cancel_mouse_face (f
)
7167 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7169 window
= dpyinfo
->mouse_face_window
;
7170 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7172 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7173 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7174 dpyinfo
->mouse_face_window
= Qnil
;
7178 static struct scroll_bar
*x_window_to_scroll_bar ();
7179 static void x_scroll_bar_report_motion ();
7181 /* Return the current position of the mouse.
7182 *fp should be a frame which indicates which display to ask about.
7184 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7185 and *part to the frame, window, and scroll bar part that the mouse
7186 is over. Set *x and *y to the portion and whole of the mouse's
7187 position on the scroll bar.
7189 If the mouse movement started elsewhere, set *fp to the frame the
7190 mouse is on, *bar_window to nil, and *x and *y to the character cell
7193 Set *time to the server time-stamp for the time at which the mouse
7194 was at this position.
7196 Don't store anything if we don't have a valid set of values to report.
7198 This clears the mouse_moved flag, so we can wait for the next mouse
7202 w32_mouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7205 Lisp_Object
*bar_window
;
7206 enum scroll_bar_part
*part
;
7208 unsigned long *time
;
7214 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7215 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7220 Lisp_Object frame
, tail
;
7222 /* Clear the mouse-moved flag for every frame on this display. */
7223 FOR_EACH_FRAME (tail
, frame
)
7224 XFRAME (frame
)->mouse_moved
= 0;
7226 last_mouse_scroll_bar
= Qnil
;
7230 /* Now we have a position on the root; find the innermost window
7231 containing the pointer. */
7233 if (FRAME_W32_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7234 && FRAME_LIVE_P (last_mouse_frame
))
7236 /* If mouse was grabbed on a frame, give coords for that frame
7237 even if the mouse is now outside it. */
7238 f1
= last_mouse_frame
;
7242 /* Is window under mouse one of our frames? */
7243 f1
= x_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp
),
7244 WindowFromPoint (pt
));
7247 /* If not, is it one of our scroll bars? */
7250 struct scroll_bar
*bar
7251 = x_window_to_scroll_bar (WindowFromPoint (pt
));
7255 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7259 if (f1
== 0 && insist
> 0)
7260 f1
= SELECTED_FRAME ();
7264 /* Ok, we found a frame. Store all the values.
7265 last_mouse_glyph is a rectangle used to reduce the
7266 generation of mouse events. To not miss any motion
7267 events, we must divide the frame into rectangles of the
7268 size of the smallest character that could be displayed
7269 on it, i.e. into the same rectangles that matrices on
7270 the frame are divided into. */
7272 #if OLD_REDISPLAY_CODE
7273 int ignore1
, ignore2
;
7275 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7277 pixel_to_glyph_coords (f1
, pt
.x
, pt
.y
, &ignore1
, &ignore2
,
7279 FRAME_W32_DISPLAY_INFO (f1
)->grabbed
7282 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7284 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7285 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7289 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7290 round down even for negative values. */
7296 last_mouse_glyph
.left
= (x
+ width
- 1) / width
* width
;
7297 last_mouse_glyph
.top
= (y
+ height
- 1) / height
* height
;
7298 last_mouse_glyph
.right
= last_mouse_glyph
.left
+ width
;
7299 last_mouse_glyph
.bottom
= last_mouse_glyph
.top
+ height
;
7308 *time
= last_mouse_movement_time
;
7317 /* Scroll bar support. */
7319 /* Given a window ID, find the struct scroll_bar which manages it.
7320 This can be called in GC, so we have to make sure to strip off mark
7323 static struct scroll_bar
*
7324 x_window_to_scroll_bar (window_id
)
7329 for (tail
= Vframe_list
;
7330 XGCTYPE (tail
) == Lisp_Cons
;
7333 Lisp_Object frame
, bar
, condemned
;
7335 frame
= XCAR (tail
);
7336 /* All elements of Vframe_list should be frames. */
7337 if (! GC_FRAMEP (frame
))
7340 /* Scan this frame's scroll bar list for a scroll bar with the
7342 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7343 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7344 /* This trick allows us to search both the ordinary and
7345 condemned scroll bar lists with one loop. */
7346 ! GC_NILP (bar
) || (bar
= condemned
,
7349 bar
= XSCROLL_BAR (bar
)->next
)
7350 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7351 return XSCROLL_BAR (bar
);
7359 /* Set the thumb size and position of scroll bar BAR. We are currently
7360 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7363 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
)
7364 struct scroll_bar
*bar
;
7365 int portion
, position
, whole
;
7367 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7368 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7369 int sb_page
, sb_pos
;
7370 BOOL draggingp
= !NILP (bar
->dragging
) ? TRUE
: FALSE
;
7374 /* Position scroll bar at rock bottom if the bottom of the
7375 buffer is visible. This avoids shinking the thumb away
7376 to nothing if it is held at the bottom of the buffer. */
7377 if (position
+ portion
>= whole
)
7379 sb_page
= range
* (whole
- position
) / whole
7380 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7384 sb_page
= portion
* range
/ whole
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7385 sb_pos
= position
* range
/ whole
;
7395 if (pfnSetScrollInfo
)
7399 si
.cbSize
= sizeof (si
);
7400 /* Only update page size if currently dragging, to reduce
7403 si
.fMask
= SIF_PAGE
;
7405 si
.fMask
= SIF_PAGE
| SIF_POS
;
7409 pfnSetScrollInfo (w
, SB_CTL
, &si
, !draggingp
);
7412 SetScrollPos (w
, SB_CTL
, sb_pos
, !draggingp
);
7418 /************************************************************************
7419 Scroll bars, general
7420 ************************************************************************/
7423 my_create_scrollbar (f
, bar
)
7425 struct scroll_bar
* bar
;
7427 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
7428 WM_EMACS_CREATESCROLLBAR
, (WPARAM
) f
,
7432 //#define ATTACH_THREADS
7435 my_show_window (FRAME_PTR f
, HWND hwnd
, int how
)
7437 #ifndef ATTACH_THREADS
7438 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
7439 (WPARAM
) hwnd
, (LPARAM
) how
);
7441 return ShowWindow (hwnd
, how
);
7446 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
7447 int x
, int y
, int cx
, int cy
, UINT flags
)
7449 #ifndef ATTACH_THREADS
7451 pos
.hwndInsertAfter
= hwndAfter
;
7457 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
7459 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
7464 my_set_focus (f
, hwnd
)
7468 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
7473 my_set_foreground_window (hwnd
)
7476 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
7480 my_destroy_window (f
, hwnd
)
7484 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
7488 /* Create a scroll bar and return the scroll bar vector for it. W is
7489 the Emacs window on which to create the scroll bar. TOP, LEFT,
7490 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7493 static struct scroll_bar
*
7494 x_scroll_bar_create (w
, top
, left
, width
, height
)
7496 int top
, left
, width
, height
;
7498 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7500 struct scroll_bar
*bar
7501 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7505 XSETWINDOW (bar
->window
, w
);
7506 XSETINT (bar
->top
, top
);
7507 XSETINT (bar
->left
, left
);
7508 XSETINT (bar
->width
, width
);
7509 XSETINT (bar
->height
, height
);
7510 XSETINT (bar
->start
, 0);
7511 XSETINT (bar
->end
, 0);
7512 bar
->dragging
= Qnil
;
7514 /* Requires geometry to be set before call to create the real window */
7516 hwnd
= my_create_scrollbar (f
, bar
);
7518 if (pfnSetScrollInfo
)
7522 si
.cbSize
= sizeof (si
);
7525 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
7526 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7530 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
7534 SetScrollRange (hwnd
, SB_CTL
, 0,
7535 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
7536 SetScrollPos (hwnd
, SB_CTL
, 0, FALSE
);
7539 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
7541 /* Add bar to its frame's list of scroll bars. */
7542 bar
->next
= FRAME_SCROLL_BARS (f
);
7544 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7545 if (! NILP (bar
->next
))
7546 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7554 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7558 x_scroll_bar_remove (bar
)
7559 struct scroll_bar
*bar
;
7561 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7565 /* Destroy the window. */
7566 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
7568 /* Disassociate this scroll bar from its window. */
7569 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7574 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7575 that we are displaying PORTION characters out of a total of WHOLE
7576 characters, starting at POSITION. If WINDOW has no scroll bar,
7579 w32_set_vertical_scroll_bar (w
, portion
, whole
, position
)
7581 int portion
, whole
, position
;
7583 struct frame
*f
= XFRAME (w
->frame
);
7584 struct scroll_bar
*bar
;
7585 int top
, height
, left
, sb_left
, width
, sb_width
;
7586 int window_x
, window_y
, window_width
, window_height
;
7588 /* Get window dimensions. */
7589 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7591 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7592 height
= window_height
;
7594 /* Compute the left edge of the scroll bar area. */
7595 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7596 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
7598 left
= XFASTINT (w
->left
);
7599 left
*= CANON_X_UNIT (f
);
7600 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
7602 /* Compute the width of the scroll bar which might be less than
7603 the width of the area reserved for the scroll bar. */
7604 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
7605 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
7609 /* Compute the left edge of the scroll bar. */
7610 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7611 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
7613 sb_left
= left
+ (width
- sb_width
) / 2;
7615 /* Does the scroll bar exist yet? */
7616 if (NILP (w
->vertical_scroll_bar
))
7620 hdc
= get_frame_dc (f
);
7621 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
7622 release_frame_dc (f
, hdc
);
7625 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
7629 /* It may just need to be moved and resized. */
7632 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
7633 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
7635 /* If already correctly positioned, do nothing. */
7636 if ( XINT (bar
->left
) == sb_left
7637 && XINT (bar
->top
) == top
7638 && XINT (bar
->width
) == sb_width
7639 && XINT (bar
->height
) == height
)
7641 /* Redraw after clear_frame. */
7642 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
7643 InvalidateRect (hwnd
, NULL
, FALSE
);
7650 hdc
= get_frame_dc (f
);
7651 /* Since Windows scroll bars are smaller than the space reserved
7652 for them on the frame, we have to clear "under" them. */
7653 w32_clear_area (f
, hdc
,
7658 release_frame_dc (f
, hdc
);
7660 /* Make sure scroll bar is "visible" before moving, to ensure the
7661 area of the parent window now exposed will be refreshed. */
7662 my_show_window (f
, hwnd
, SW_HIDE
);
7663 MoveWindow (hwnd
, sb_left
, top
,
7664 sb_width
, height
, TRUE
);
7665 if (pfnSetScrollInfo
)
7669 si
.cbSize
= sizeof (si
);
7670 si
.fMask
= SIF_RANGE
;
7672 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
7673 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7675 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
7678 SetScrollRange (hwnd
, SB_CTL
, 0,
7679 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
7680 my_show_window (f
, hwnd
, SW_NORMAL
);
7681 // InvalidateRect (w, NULL, FALSE);
7683 /* Remember new settings. */
7684 XSETINT (bar
->left
, sb_left
);
7685 XSETINT (bar
->top
, top
);
7686 XSETINT (bar
->width
, sb_width
);
7687 XSETINT (bar
->height
, height
);
7692 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
7694 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
7698 /* The following three hooks are used when we're doing a thorough
7699 redisplay of the frame. We don't explicitly know which scroll bars
7700 are going to be deleted, because keeping track of when windows go
7701 away is a real pain - "Can you say set-window-configuration, boys
7702 and girls?" Instead, we just assert at the beginning of redisplay
7703 that *all* scroll bars are to be removed, and then save a scroll bar
7704 from the fiery pit when we actually redisplay its window. */
7706 /* Arrange for all scroll bars on FRAME to be removed at the next call
7707 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
7708 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
7711 w32_condemn_scroll_bars (frame
)
7714 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
7715 while (! NILP (FRAME_SCROLL_BARS (frame
)))
7718 bar
= FRAME_SCROLL_BARS (frame
);
7719 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
7720 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
7721 XSCROLL_BAR (bar
)->prev
= Qnil
;
7722 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
7723 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
7724 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
7729 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
7730 Note that WINDOW isn't necessarily condemned at all. */
7733 w32_redeem_scroll_bar (window
)
7734 struct window
*window
;
7736 struct scroll_bar
*bar
;
7739 /* We can't redeem this window's scroll bar if it doesn't have one. */
7740 if (NILP (window
->vertical_scroll_bar
))
7743 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
7745 /* Unlink it from the condemned list. */
7746 f
= XFRAME (WINDOW_FRAME (window
));
7747 if (NILP (bar
->prev
))
7749 /* If the prev pointer is nil, it must be the first in one of
7751 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
7752 /* It's not condemned. Everything's fine. */
7754 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
7755 window
->vertical_scroll_bar
))
7756 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
7758 /* If its prev pointer is nil, it must be at the front of
7759 one or the other! */
7763 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
7765 if (! NILP (bar
->next
))
7766 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
7768 bar
->next
= FRAME_SCROLL_BARS (f
);
7770 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7771 if (! NILP (bar
->next
))
7772 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7775 /* Remove all scroll bars on FRAME that haven't been saved since the
7776 last call to `*condemn_scroll_bars_hook'. */
7779 w32_judge_scroll_bars (f
)
7782 Lisp_Object bar
, next
;
7784 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
7786 /* Clear out the condemned list now so we won't try to process any
7787 more events on the hapless scroll bars. */
7788 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
7790 for (; ! NILP (bar
); bar
= next
)
7792 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
7794 x_scroll_bar_remove (b
);
7797 b
->next
= b
->prev
= Qnil
;
7800 /* Now there should be no references to the condemned scroll bars,
7801 and they should get garbage-collected. */
7804 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
7805 is set to something other than no_event, it is enqueued.
7807 This may be called from a signal handler, so we have to ignore GC
7811 w32_scroll_bar_handle_click (bar
, msg
, emacs_event
)
7812 struct scroll_bar
*bar
;
7814 struct input_event
*emacs_event
;
7816 if (! GC_WINDOWP (bar
->window
))
7819 emacs_event
->kind
= w32_scroll_bar_click
;
7820 emacs_event
->code
= 0;
7821 /* not really meaningful to distinguish up/down */
7822 emacs_event
->modifiers
= msg
->dwModifiers
;
7823 emacs_event
->frame_or_window
= bar
->window
;
7824 emacs_event
->arg
= Qnil
;
7825 emacs_event
->timestamp
= msg
->msg
.time
;
7828 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7830 int dragging
= !NILP (bar
->dragging
);
7832 if (pfnGetScrollInfo
)
7836 si
.cbSize
= sizeof (si
);
7839 pfnGetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
7843 y
= GetScrollPos ((HWND
) msg
->msg
.lParam
, SB_CTL
);
7845 bar
->dragging
= Qnil
;
7848 last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
7850 switch (LOWORD (msg
->msg
.wParam
))
7853 emacs_event
->part
= scroll_bar_down_arrow
;
7856 emacs_event
->part
= scroll_bar_up_arrow
;
7859 emacs_event
->part
= scroll_bar_above_handle
;
7862 emacs_event
->part
= scroll_bar_below_handle
;
7865 emacs_event
->part
= scroll_bar_handle
;
7869 emacs_event
->part
= scroll_bar_handle
;
7873 case SB_THUMBPOSITION
:
7874 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
7875 y
= HIWORD (msg
->msg
.wParam
);
7877 emacs_event
->part
= scroll_bar_handle
;
7879 /* "Silently" update current position. */
7880 if (pfnSetScrollInfo
)
7884 si
.cbSize
= sizeof (si
);
7887 /* Remember apparent position (we actually lag behind the real
7888 position, so don't set that directly. */
7889 last_scroll_bar_drag_pos
= y
;
7891 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
7894 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, FALSE
);
7897 /* If this is the end of a drag sequence, then reset the scroll
7898 handle size to normal and do a final redraw. Otherwise do
7902 if (pfnSetScrollInfo
)
7905 int start
= XINT (bar
->start
);
7906 int end
= XINT (bar
->end
);
7908 si
.cbSize
= sizeof (si
);
7909 si
.fMask
= SIF_PAGE
| SIF_POS
;
7910 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7911 si
.nPos
= last_scroll_bar_drag_pos
;
7912 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
7915 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, TRUE
);
7919 emacs_event
->kind
= no_event
;
7923 XSETINT (emacs_event
->x
, y
);
7924 XSETINT (emacs_event
->y
, top_range
);
7930 /* Return information to the user about the current position of the mouse
7931 on the scroll bar. */
7934 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
7936 Lisp_Object
*bar_window
;
7937 enum scroll_bar_part
*part
;
7939 unsigned long *time
;
7941 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
7942 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7943 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7945 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7950 *bar_window
= bar
->window
;
7952 if (pfnGetScrollInfo
)
7956 si
.cbSize
= sizeof (si
);
7957 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
7959 pfnGetScrollInfo (w
, SB_CTL
, &si
);
7961 top_range
= si
.nMax
- si
.nPage
+ 1;
7964 pos
= GetScrollPos (w
, SB_CTL
);
7966 switch (LOWORD (last_mouse_scroll_bar_pos
))
7968 case SB_THUMBPOSITION
:
7970 *part
= scroll_bar_handle
;
7971 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
7972 pos
= HIWORD (last_mouse_scroll_bar_pos
);
7975 *part
= scroll_bar_handle
;
7979 *part
= scroll_bar_handle
;
7984 XSETINT (*y
, top_range
);
7987 last_mouse_scroll_bar
= Qnil
;
7989 *time
= last_mouse_movement_time
;
7995 /* The screen has been cleared so we may have changed foreground or
7996 background colors, and the scroll bars may need to be redrawn.
7997 Clear out the scroll bars, and ask for expose events, so we can
8001 x_scroll_bar_clear (f
)
8006 /* We can have scroll bars even if this is 0,
8007 if we just turned off scroll bar mode.
8008 But in that case we should not clear them. */
8009 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8010 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8011 bar
= XSCROLL_BAR (bar
)->next
)
8013 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
8014 HDC hdc
= GetDC (window
);
8017 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
8018 arranges to refresh the scroll bar if hidden. */
8019 my_show_window (f
, window
, SW_HIDE
);
8021 GetClientRect (window
, &rect
);
8022 select_palette (f
, hdc
);
8023 w32_clear_rect (f
, hdc
, &rect
);
8024 deselect_palette (f
, hdc
);
8026 ReleaseDC (window
, hdc
);
8031 /* The main W32 event-reading loop - w32_read_socket. */
8033 /* Time stamp of enter window event. This is only used by w32_read_socket,
8034 but we have to put it out here, since static variables within functions
8035 sometimes don't work. */
8037 static Time enter_timestamp
;
8039 /* Record the last 100 characters stored
8040 to help debug the loss-of-chars-during-GC problem. */
8042 static int temp_index
;
8043 static short temp_buffer
[100];
8046 /* Read events coming from the W32 shell.
8047 This routine is called by the SIGIO handler.
8048 We return as soon as there are no more events to be read.
8050 Events representing keys are stored in buffer BUFP,
8051 which can hold up to NUMCHARS characters.
8052 We return the number of characters stored into the buffer,
8053 thus pretending to be `read'.
8055 EXPECTED is nonzero if the caller knows input is available.
8057 Some of these messages are reposted back to the message queue since the
8058 system calls the windows proc directly in a context where we cannot return
8059 the data nor can we guarantee the state we are in. So if we dispatch them
8060 we will get into an infinite loop. To prevent this from ever happening we
8061 will set a variable to indicate we are in the read_socket call and indicate
8062 which message we are processing since the windows proc gets called
8063 recursively with different messages by the system.
8067 w32_read_socket (sd
, bufp
, numchars
, expected
)
8069 /* register */ struct input_event
*bufp
;
8070 /* register */ int numchars
;
8074 int check_visibility
= 0;
8077 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
8079 if (interrupt_input_blocked
)
8081 interrupt_input_pending
= 1;
8085 interrupt_input_pending
= 0;
8088 /* So people can tell when we have read the available input. */
8089 input_signal_count
++;
8092 abort (); /* Don't think this happens. */
8094 /* TODO: tooltips, tool-bars, ghostscript integration, mouse
8096 while (get_next_msg (&msg
, FALSE
))
8098 switch (msg
.msg
.message
)
8101 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8105 if (msg
.rect
.right
== msg
.rect
.left
||
8106 msg
.rect
.bottom
== msg
.rect
.top
)
8108 /* We may get paint messages even though the client
8109 area is clipped - these are not expose events. */
8110 DebPrint (("clipped frame %04x (%s) got WM_PAINT\n", f
,
8111 XSTRING (f
->name
)->data
));
8113 else if (f
->async_visible
!= 1)
8115 /* Definitely not obscured, so mark as visible. */
8116 f
->async_visible
= 1;
8117 f
->async_iconified
= 0;
8118 SET_FRAME_GARBAGED (f
);
8119 DebPrint (("frame %04x (%s) reexposed\n", f
,
8120 XSTRING (f
->name
)->data
));
8122 /* WM_PAINT serves as MapNotify as well, so report
8123 visibility changes properly. */
8126 bufp
->kind
= deiconify_event
;
8127 XSETFRAME (bufp
->frame_or_window
, f
);
8133 else if (! NILP (Vframe_list
)
8134 && ! NILP (XCDR (Vframe_list
)))
8135 /* Force a redisplay sooner or later to update the
8136 frame titles in case this is the second frame. */
8137 record_asynch_buffer_change ();
8141 HDC hdc
= get_frame_dc (f
);
8143 /* Erase background again for safety. */
8144 w32_clear_rect (f
, hdc
, &msg
.rect
);
8145 release_frame_dc (f
, hdc
);
8149 msg
.rect
.right
- msg
.rect
.left
,
8150 msg
.rect
.bottom
- msg
.rect
.top
);
8155 case WM_INPUTLANGCHANGE
:
8156 /* Generate a language change event. */
8157 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8164 bufp
->kind
= language_change_event
;
8165 XSETFRAME (bufp
->frame_or_window
, f
);
8167 bufp
->code
= msg
.msg
.wParam
;
8168 bufp
->modifiers
= msg
.msg
.lParam
& 0xffff;
8177 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8179 if (f
&& !f
->iconified
)
8181 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8183 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8184 bufp
->kind
= non_ascii_keystroke
;
8185 bufp
->code
= msg
.msg
.wParam
;
8186 bufp
->modifiers
= msg
.dwModifiers
;
8187 XSETFRAME (bufp
->frame_or_window
, f
);
8189 bufp
->timestamp
= msg
.msg
.time
;
8198 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8200 if (f
&& !f
->iconified
)
8202 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8204 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8205 bufp
->kind
= ascii_keystroke
;
8206 bufp
->code
= msg
.msg
.wParam
;
8207 bufp
->modifiers
= msg
.dwModifiers
;
8208 XSETFRAME (bufp
->frame_or_window
, f
);
8210 bufp
->timestamp
= msg
.msg
.time
;
8218 previous_help_echo
= help_echo
;
8219 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
8222 if (dpyinfo
->grabbed
&& last_mouse_frame
8223 && FRAME_LIVE_P (last_mouse_frame
))
8224 f
= last_mouse_frame
;
8226 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8229 note_mouse_movement (f
, &msg
.msg
);
8232 /* If we move outside the frame, then we're
8233 certainly no longer on any text in the frame. */
8234 clear_mouse_face (dpyinfo
);
8237 /* If the contents of the global variable help_echo
8238 has changed, generate a HELP_EVENT. */
8239 if (!NILP (help_echo
)
8240 || !NILP (previous_help_echo
))
8246 XSETFRAME (frame
, f
);
8250 any_help_event_p
= 1;
8251 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
8252 help_echo_window
, help_echo_object
,
8254 bufp
+= n
, count
+= n
, numchars
-= n
;
8258 case WM_LBUTTONDOWN
:
8260 case WM_MBUTTONDOWN
:
8262 case WM_RBUTTONDOWN
:
8265 /* If we decide we want to generate an event to be seen
8266 by the rest of Emacs, we put it here. */
8267 struct input_event emacs_event
;
8272 emacs_event
.kind
= no_event
;
8274 if (dpyinfo
->grabbed
&& last_mouse_frame
8275 && FRAME_LIVE_P (last_mouse_frame
))
8276 f
= last_mouse_frame
;
8278 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8282 construct_mouse_click (&emacs_event
, &msg
, f
);
8284 /* Is this in the tool-bar? */
8285 if (WINDOWP (f
->tool_bar_window
)
8286 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
8292 window
= window_from_coordinates (f
,
8296 if (EQ (window
, f
->tool_bar_window
))
8298 w32_handle_tool_bar_click (f
, &emacs_event
);
8304 if (!dpyinfo
->w32_focus_frame
8305 || f
== dpyinfo
->w32_focus_frame
8308 construct_mouse_click (bufp
, &msg
, f
);
8315 parse_button (msg
.msg
.message
, &button
, &up
);
8319 dpyinfo
->grabbed
&= ~ (1 << button
);
8323 dpyinfo
->grabbed
|= (1 << button
);
8324 last_mouse_frame
= f
;
8325 /* Ignore any mouse motion that happened
8326 before this event; any subsequent mouse-movement
8327 Emacs events should reflect only motion after
8333 last_tool_bar_item
= -1;
8339 if (dpyinfo
->grabbed
&& last_mouse_frame
8340 && FRAME_LIVE_P (last_mouse_frame
))
8341 f
= last_mouse_frame
;
8343 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8347 if ((!dpyinfo
->w32_focus_frame
8348 || f
== dpyinfo
->w32_focus_frame
)
8351 construct_mouse_wheel (bufp
, &msg
, f
);
8361 HMENU menu
= (HMENU
) msg
.msg
.lParam
;
8362 UINT menu_item
= (UINT
) LOWORD (msg
.msg
.wParam
);
8363 UINT flags
= (UINT
) HIWORD (msg
.msg
.wParam
);
8365 w32_menu_display_help (menu
, menu_item
, flags
);
8370 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8374 construct_drag_n_drop (bufp
, &msg
, f
);
8383 struct scroll_bar
*bar
=
8384 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
);
8386 if (bar
&& numchars
>= 1)
8388 if (w32_scroll_bar_handle_click (bar
, &msg
, bufp
))
8398 case WM_WINDOWPOSCHANGED
:
8400 case WM_ACTIVATEAPP
:
8401 check_visibility
= 1;
8405 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8407 if (f
&& !f
->async_iconified
)
8411 x_real_positions (f
, &x
, &y
);
8412 f
->output_data
.w32
->left_pos
= x
;
8413 f
->output_data
.w32
->top_pos
= y
;
8416 check_visibility
= 1;
8420 /* If window has been obscured or exposed by another window
8421 being maximised or minimised/restored, then recheck
8422 visibility of all frames. Direct changes to our own
8423 windows get handled by WM_SIZE. */
8425 if (msg
.msg
.lParam
!= 0)
8426 check_visibility
= 1;
8429 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8430 f
->async_visible
= msg
.msg
.wParam
;
8434 check_visibility
= 1;
8438 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8440 /* Inform lisp of whether frame has been iconified etc. */
8443 switch (msg
.msg
.wParam
)
8445 case SIZE_MINIMIZED
:
8446 f
->async_visible
= 0;
8447 f
->async_iconified
= 1;
8449 bufp
->kind
= iconify_event
;
8450 XSETFRAME (bufp
->frame_or_window
, f
);
8457 case SIZE_MAXIMIZED
:
8459 f
->async_visible
= 1;
8460 f
->async_iconified
= 0;
8462 /* wait_reading_process_input will notice this and update
8463 the frame's display structures. */
8464 SET_FRAME_GARBAGED (f
);
8470 /* Reset top and left positions of the Window
8471 here since Windows sends a WM_MOVE message
8472 BEFORE telling us the Window is minimized
8473 when the Window is iconified, with 3000,3000
8475 x_real_positions (f
, &x
, &y
);
8476 f
->output_data
.w32
->left_pos
= x
;
8477 f
->output_data
.w32
->top_pos
= y
;
8479 bufp
->kind
= deiconify_event
;
8480 XSETFRAME (bufp
->frame_or_window
, f
);
8486 else if (! NILP (Vframe_list
)
8487 && ! NILP (XCDR (Vframe_list
)))
8488 /* Force a redisplay sooner or later
8489 to update the frame titles
8490 in case this is the second frame. */
8491 record_asynch_buffer_change ();
8496 if (f
&& !f
->async_iconified
&& msg
.msg
.wParam
!= SIZE_MINIMIZED
)
8504 GetClientRect (msg
.msg
.hwnd
, &rect
);
8506 height
= rect
.bottom
- rect
.top
;
8507 width
= rect
.right
- rect
.left
;
8509 rows
= PIXEL_TO_CHAR_HEIGHT (f
, height
);
8510 columns
= PIXEL_TO_CHAR_WIDTH (f
, width
);
8512 /* TODO: Clip size to the screen dimensions. */
8514 /* Even if the number of character rows and columns has
8515 not changed, the font size may have changed, so we need
8516 to check the pixel dimensions as well. */
8518 if (columns
!= f
->width
8519 || rows
!= f
->height
8520 || width
!= f
->output_data
.w32
->pixel_width
8521 || height
!= f
->output_data
.w32
->pixel_height
)
8523 change_frame_size (f
, rows
, columns
, 0, 1, 0);
8524 SET_FRAME_GARBAGED (f
);
8525 cancel_mouse_face (f
);
8526 f
->output_data
.w32
->pixel_width
= width
;
8527 f
->output_data
.w32
->pixel_height
= height
;
8528 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
8532 check_visibility
= 1;
8536 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8538 dpyinfo
->w32_focus_event_frame
= f
;
8541 x_new_focus_frame (dpyinfo
, f
);
8544 dpyinfo
->grabbed
= 0;
8545 check_visibility
= 1;
8549 /* TODO: some of this belongs in MOUSE_LEAVE */
8550 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8554 if (f
== dpyinfo
->w32_focus_event_frame
)
8555 dpyinfo
->w32_focus_event_frame
= 0;
8557 if (f
== dpyinfo
->w32_focus_frame
)
8558 x_new_focus_frame (dpyinfo
, 0);
8560 if (f
== dpyinfo
->mouse_face_mouse_frame
)
8562 /* If we move outside the frame, then we're
8563 certainly no longer on any text in the frame. */
8564 clear_mouse_face (dpyinfo
);
8565 dpyinfo
->mouse_face_mouse_frame
= 0;
8568 /* Generate a nil HELP_EVENT to cancel a help-echo.
8569 Do it only if there's something to cancel.
8570 Otherwise, the startup message is cleared when
8571 the mouse leaves the frame. */
8572 if (any_help_event_p
)
8577 XSETFRAME (frame
, f
);
8579 n
= gen_help_event (bufp
, numchars
,
8580 Qnil
, frame
, Qnil
, Qnil
, 0);
8581 bufp
+= n
, count
+= n
, numchars
-=n
;
8585 dpyinfo
->grabbed
= 0;
8586 check_visibility
= 1;
8590 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8597 bufp
->kind
= delete_window_event
;
8598 XSETFRAME (bufp
->frame_or_window
, f
);
8607 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8614 bufp
->kind
= menu_bar_activate_event
;
8615 XSETFRAME (bufp
->frame_or_window
, f
);
8624 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8628 extern void menubar_selection_callback
8629 (FRAME_PTR f
, void * client_data
);
8630 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
8633 check_visibility
= 1;
8636 case WM_DISPLAYCHANGE
:
8637 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8641 dpyinfo
->width
= (short) LOWORD (msg
.msg
.lParam
);
8642 dpyinfo
->height
= (short) HIWORD (msg
.msg
.lParam
);
8643 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
8644 DebPrint (("display change: %d %d\n", dpyinfo
->width
,
8648 check_visibility
= 1;
8652 /* Check for messages registered at runtime. */
8653 if (msg
.msg
.message
== msh_mousewheel
)
8655 if (dpyinfo
->grabbed
&& last_mouse_frame
8656 && FRAME_LIVE_P (last_mouse_frame
))
8657 f
= last_mouse_frame
;
8659 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8663 if ((!dpyinfo
->w32_focus_frame
8664 || f
== dpyinfo
->w32_focus_frame
)
8667 construct_mouse_wheel (bufp
, &msg
, f
);
8678 /* If the focus was just given to an autoraising frame,
8680 /* ??? This ought to be able to handle more than one such frame. */
8681 if (pending_autoraise_frame
)
8683 x_raise_frame (pending_autoraise_frame
);
8684 pending_autoraise_frame
= 0;
8687 /* Check which frames are still visisble, if we have enqueued any user
8688 events or been notified of events that may affect visibility. We
8689 do this here because there doesn't seem to be any direct
8690 notification from Windows that the visibility of a window has
8691 changed (at least, not in all cases). */
8692 if (count
> 0 || check_visibility
)
8694 Lisp_Object tail
, frame
;
8696 FOR_EACH_FRAME (tail
, frame
)
8698 FRAME_PTR f
= XFRAME (frame
);
8699 /* Check "visible" frames and mark each as obscured or not.
8700 Note that async_visible is nonzero for unobscured and
8701 obscured frames, but zero for hidden and iconified frames. */
8702 if (FRAME_W32_P (f
) && f
->async_visible
)
8705 HDC hdc
= get_frame_dc (f
);
8706 GetClipBox (hdc
, &clipbox
);
8707 release_frame_dc (f
, hdc
);
8709 if (clipbox
.right
== clipbox
.left
8710 || clipbox
.bottom
== clipbox
.top
)
8712 /* Frame has become completely obscured so mark as
8713 such (we do this by setting async_visible to 2 so
8714 that FRAME_VISIBLE_P is still true, but redisplay
8716 f
->async_visible
= 2;
8718 if (!FRAME_OBSCURED_P (f
))
8720 DebPrint (("frame %04x (%s) obscured\n", f
,
8721 XSTRING (f
->name
)->data
));
8726 /* Frame is not obscured, so mark it as such. */
8727 f
->async_visible
= 1;
8729 if (FRAME_OBSCURED_P (f
))
8731 SET_FRAME_GARBAGED (f
);
8732 DebPrint (("frame %04x (%s) reexposed\n", f
,
8733 XSTRING (f
->name
)->data
));
8735 /* Force a redisplay sooner or later. */
8736 record_asynch_buffer_change ();
8750 /***********************************************************************
8752 ***********************************************************************/
8754 /* Note if the text cursor of window W has been overwritten by a
8755 drawing operation that outputs N glyphs starting at HPOS in the
8756 line given by output_cursor.vpos. N < 0 means all the rest of the
8757 line after HPOS has been written. */
8760 note_overwritten_text_cursor (w
, hpos
, n
)
8764 if (updated_area
== TEXT_AREA
8765 && output_cursor
.vpos
== w
->phys_cursor
.vpos
8766 && hpos
<= w
->phys_cursor
.hpos
8768 || hpos
+ n
> w
->phys_cursor
.hpos
))
8769 w
->phys_cursor_on_p
= 0;
8773 /* Set clipping for output in glyph row ROW. W is the window in which
8774 we operate. GC is the graphics context to set clipping in.
8775 WHOLE_LINE_P non-zero means include the areas used for truncation
8776 mark display and alike in the clipping rectangle.
8778 ROW may be a text row or, e.g., a mode line. Text rows must be
8779 clipped to the interior of the window dedicated to text display,
8780 mode lines must be clipped to the whole window. */
8783 w32_clip_to_row (w
, row
, hdc
, whole_line_p
)
8785 struct glyph_row
*row
;
8789 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8791 int window_x
, window_y
, window_width
, window_height
;
8793 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8795 clip_rect
.left
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
8796 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8797 clip_rect
.top
= max (clip_rect
.top
, window_y
);
8798 clip_rect
.right
= clip_rect
.left
+ window_width
;
8799 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
8801 /* If clipping to the whole line, including trunc marks, extend
8802 the rectangle to the left and increase its width. */
8805 clip_rect
.left
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
8806 clip_rect
.right
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
8809 w32_set_clip_rectangle (hdc
, &clip_rect
);
8813 /* Draw a hollow box cursor on window W in glyph row ROW. */
8816 x_draw_hollow_cursor (w
, row
)
8818 struct glyph_row
*row
;
8820 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8824 struct glyph
*cursor_glyph
;
8825 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
8827 /* Compute frame-relative coordinates from window-relative
8829 rect
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8830 rect
.top
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
8831 + row
->ascent
- w
->phys_cursor_ascent
);
8832 rect
.bottom
= rect
.top
+ row
->height
- 1;
8834 /* Get the glyph the cursor is on. If we can't tell because
8835 the current matrix is invalid or such, give up. */
8836 cursor_glyph
= get_phys_cursor_glyph (w
);
8837 if (cursor_glyph
== NULL
)
8840 /* Compute the width of the rectangle to draw. If on a stretch
8841 glyph, and `x-stretch-block-cursor' is nil, don't draw a
8842 rectangle as wide as the glyph, but use a canonical character
8844 wd
= cursor_glyph
->pixel_width
- 1;
8845 if (cursor_glyph
->type
== STRETCH_GLYPH
8846 && !x_stretch_cursor_p
)
8847 wd
= min (CANON_X_UNIT (f
), wd
);
8849 rect
.right
= rect
.left
+ wd
;
8850 hdc
= get_frame_dc (f
);
8851 FrameRect (hdc
, &rect
, hb
);
8854 release_frame_dc (f
, hdc
);
8858 /* Draw a bar cursor on window W in glyph row ROW.
8860 Implementation note: One would like to draw a bar cursor with an
8861 angle equal to the one given by the font property XA_ITALIC_ANGLE.
8862 Unfortunately, I didn't find a font yet that has this property set.
8866 x_draw_bar_cursor (w
, row
, width
)
8868 struct glyph_row
*row
;
8871 struct frame
*f
= XFRAME (w
->frame
);
8872 struct glyph
*cursor_glyph
;
8876 /* If cursor is out of bounds, don't draw garbage. This can happen
8877 in mini-buffer windows when switching between echo area glyphs
8879 cursor_glyph
= get_phys_cursor_glyph (w
);
8880 if (cursor_glyph
== NULL
)
8883 /* If on an image, draw like a normal cursor. That's usually better
8884 visible than drawing a bar, esp. if the image is large so that
8885 the bar might not be in the window. */
8886 if (cursor_glyph
->type
== IMAGE_GLYPH
)
8888 struct glyph_row
*row
;
8889 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
8890 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
8895 width
= f
->output_data
.w32
->cursor_width
;
8897 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8898 hdc
= get_frame_dc (f
);
8899 w32_clip_to_row (w
, row
, hdc
, 0);
8900 w32_fill_area (f
, hdc
, f
->output_data
.w32
->cursor_pixel
,
8902 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
8903 min (cursor_glyph
->pixel_width
, width
),
8905 release_frame_dc (f
, hdc
);
8910 /* Clear the cursor of window W to background color, and mark the
8911 cursor as not shown. This is used when the text where the cursor
8912 is is about to be rewritten. */
8918 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
8919 x_update_window_cursor (w
, 0);
8923 /* Draw the cursor glyph of window W in glyph row ROW. See the
8924 comment of x_draw_glyphs for the meaning of HL. */
8927 x_draw_phys_cursor_glyph (w
, row
, hl
)
8929 struct glyph_row
*row
;
8930 enum draw_glyphs_face hl
;
8932 /* If cursor hpos is out of bounds, don't draw garbage. This can
8933 happen in mini-buffer windows when switching between echo area
8934 glyphs and mini-buffer. */
8935 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
8937 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
8938 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
8941 /* When we erase the cursor, and ROW is overlapped by other
8942 rows, make sure that these overlapping parts of other rows
8944 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
8946 if (row
> w
->current_matrix
->rows
8947 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
8948 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
8950 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
8951 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
8952 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
8958 /* Erase the image of a cursor of window W from the screen. */
8961 x_erase_phys_cursor (w
)
8964 struct frame
*f
= XFRAME (w
->frame
);
8965 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
8966 int hpos
= w
->phys_cursor
.hpos
;
8967 int vpos
= w
->phys_cursor
.vpos
;
8968 int mouse_face_here_p
= 0;
8969 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
8970 struct glyph_row
*cursor_row
;
8971 struct glyph
*cursor_glyph
;
8972 enum draw_glyphs_face hl
;
8974 /* No cursor displayed or row invalidated => nothing to do on the
8976 if (w
->phys_cursor_type
== NO_CURSOR
)
8977 goto mark_cursor_off
;
8979 /* VPOS >= active_glyphs->nrows means that window has been resized.
8980 Don't bother to erase the cursor. */
8981 if (vpos
>= active_glyphs
->nrows
)
8982 goto mark_cursor_off
;
8984 /* If row containing cursor is marked invalid, there is nothing we
8986 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
8987 if (!cursor_row
->enabled_p
)
8988 goto mark_cursor_off
;
8990 /* This can happen when the new row is shorter than the old one.
8991 In this case, either x_draw_glyphs or clear_end_of_line
8992 should have cleared the cursor. Note that we wouldn't be
8993 able to erase the cursor in this case because we don't have a
8994 cursor glyph at hand. */
8995 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
8996 goto mark_cursor_off
;
8998 /* If the cursor is in the mouse face area, redisplay that when
8999 we clear the cursor. */
9000 if (! NILP (dpyinfo
->mouse_face_window
)
9001 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9002 && (vpos
> dpyinfo
->mouse_face_beg_row
9003 || (vpos
== dpyinfo
->mouse_face_beg_row
9004 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9005 && (vpos
< dpyinfo
->mouse_face_end_row
9006 || (vpos
== dpyinfo
->mouse_face_end_row
9007 && hpos
< dpyinfo
->mouse_face_end_col
))
9008 /* Don't redraw the cursor's spot in mouse face if it is at the
9009 end of a line (on a newline). The cursor appears there, but
9010 mouse highlighting does not. */
9011 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9012 mouse_face_here_p
= 1;
9014 /* Maybe clear the display under the cursor. */
9015 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9018 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9021 cursor_glyph
= get_phys_cursor_glyph (w
);
9022 if (cursor_glyph
== NULL
)
9023 goto mark_cursor_off
;
9025 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9027 hdc
= get_frame_dc (f
);
9028 w32_clear_area (f
, hdc
, x
,
9029 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9031 cursor_glyph
->pixel_width
,
9032 cursor_row
->visible_height
);
9033 release_frame_dc (f
, hdc
);
9036 /* Erase the cursor by redrawing the character underneath it. */
9037 if (mouse_face_here_p
)
9038 hl
= DRAW_MOUSE_FACE
;
9039 else if (cursor_row
->inverse_p
)
9040 hl
= DRAW_INVERSE_VIDEO
;
9042 hl
= DRAW_NORMAL_TEXT
;
9043 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9046 w
->phys_cursor_on_p
= 0;
9047 w
->phys_cursor_type
= NO_CURSOR
;
9051 /* Display or clear cursor of window W. If ON is zero, clear the
9052 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9053 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9056 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9058 int on
, hpos
, vpos
, x
, y
;
9060 struct frame
*f
= XFRAME (w
->frame
);
9061 int new_cursor_type
;
9062 int new_cursor_width
;
9063 struct glyph_matrix
*current_glyphs
;
9064 struct glyph_row
*glyph_row
;
9065 struct glyph
*glyph
;
9067 /* This is pointless on invisible frames, and dangerous on garbaged
9068 windows and frames; in the latter case, the frame or window may
9069 be in the midst of changing its size, and x and y may be off the
9071 if (! FRAME_VISIBLE_P (f
)
9072 || FRAME_GARBAGED_P (f
)
9073 || vpos
>= w
->current_matrix
->nrows
9074 || hpos
>= w
->current_matrix
->matrix_w
)
9077 /* If cursor is off and we want it off, return quickly. */
9078 if (!on
&& !w
->phys_cursor_on_p
)
9081 current_glyphs
= w
->current_matrix
;
9082 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9083 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9085 /* If cursor row is not enabled, we don't really know where to
9086 display the cursor. */
9087 if (!glyph_row
->enabled_p
)
9089 w
->phys_cursor_on_p
= 0;
9093 xassert (interrupt_input_blocked
);
9095 /* Set new_cursor_type to the cursor we want to be displayed. In a
9096 mini-buffer window, we want the cursor only to appear if we are
9097 reading input from this window. For the selected window, we want
9098 the cursor type given by the frame parameter. If explicitly
9099 marked off, draw no cursor. In all other cases, we want a hollow
9101 new_cursor_width
= -1;
9102 if (cursor_in_echo_area
9103 && FRAME_HAS_MINIBUF_P (f
)
9104 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
9106 if (w
== XWINDOW (echo_area_window
))
9107 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9109 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9113 if (f
!= FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
9114 || w
!= XWINDOW (f
->selected_window
))
9116 extern int cursor_in_non_selected_windows
;
9118 if (MINI_WINDOW_P (w
)
9119 || !cursor_in_non_selected_windows
9120 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
9121 new_cursor_type
= NO_CURSOR
;
9123 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9125 else if (w
->cursor_off_p
)
9126 new_cursor_type
= NO_CURSOR
;
9129 struct buffer
*b
= XBUFFER (w
->buffer
);
9131 if (EQ (b
->cursor_type
, Qt
))
9132 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9134 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
9139 /* If cursor is currently being shown and we don't want it to be or
9140 it is in the wrong place, or the cursor type is not what we want,
9142 if (w
->phys_cursor_on_p
9144 || w
->phys_cursor
.x
!= x
9145 || w
->phys_cursor
.y
!= y
9146 || new_cursor_type
!= w
->phys_cursor_type
))
9147 x_erase_phys_cursor (w
);
9149 /* If the cursor is now invisible and we want it to be visible,
9151 if (on
&& !w
->phys_cursor_on_p
)
9153 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9154 w
->phys_cursor_height
= glyph_row
->height
;
9156 /* Set phys_cursor_.* before x_draw_.* is called because some
9157 of them may need the information. */
9158 w
->phys_cursor
.x
= x
;
9159 w
->phys_cursor
.y
= glyph_row
->y
;
9160 w
->phys_cursor
.hpos
= hpos
;
9161 w
->phys_cursor
.vpos
= vpos
;
9162 w
->phys_cursor_type
= new_cursor_type
;
9163 w
->phys_cursor_on_p
= 1;
9165 switch (new_cursor_type
)
9167 case HOLLOW_BOX_CURSOR
:
9168 x_draw_hollow_cursor (w
, glyph_row
);
9171 case FILLED_BOX_CURSOR
:
9172 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9176 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
9189 /* Display the cursor on window W, or clear it. X and Y are window
9190 relative pixel coordinates. HPOS and VPOS are glyph matrix
9191 positions. If W is not the selected window, display a hollow
9192 cursor. ON non-zero means display the cursor at X, Y which
9193 correspond to HPOS, VPOS, otherwise it is cleared. */
9196 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9198 int on
, hpos
, vpos
, x
, y
;
9201 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9206 /* Display the cursor on window W, or clear it, according to ON_P.
9207 Don't change the cursor's position. */
9210 x_update_cursor (f
, on_p
)
9214 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9218 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9219 in the window tree rooted at W. */
9222 x_update_cursor_in_window_tree (w
, on_p
)
9228 if (!NILP (w
->hchild
))
9229 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9230 else if (!NILP (w
->vchild
))
9231 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9233 x_update_window_cursor (w
, on_p
);
9235 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9240 /* Switch the display of W's cursor on or off, according to the value
9244 x_update_window_cursor (w
, on
)
9248 /* Don't update cursor in windows whose frame is in the process
9249 of being deleted. */
9250 if (w
->current_matrix
)
9253 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
,
9254 w
->phys_cursor
.vpos
, w
->phys_cursor
.x
,
9266 x_bitmap_icon (f
, icon
)
9272 if (FRAME_W32_WINDOW (f
) == 0)
9276 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
9277 else if (STRINGP (icon
))
9278 hicon
= LoadImage (NULL
, (LPCTSTR
) XSTRING (icon
)->data
, IMAGE_ICON
, 0, 0,
9279 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
9280 else if (SYMBOLP (icon
))
9284 if (EQ (icon
, intern ("application")))
9285 name
= (LPCTSTR
) IDI_APPLICATION
;
9286 else if (EQ (icon
, intern ("hand")))
9287 name
= (LPCTSTR
) IDI_HAND
;
9288 else if (EQ (icon
, intern ("question")))
9289 name
= (LPCTSTR
) IDI_QUESTION
;
9290 else if (EQ (icon
, intern ("exclamation")))
9291 name
= (LPCTSTR
) IDI_EXCLAMATION
;
9292 else if (EQ (icon
, intern ("asterisk")))
9293 name
= (LPCTSTR
) IDI_ASTERISK
;
9294 else if (EQ (icon
, intern ("winlogo")))
9295 name
= (LPCTSTR
) IDI_WINLOGO
;
9299 hicon
= LoadIcon (NULL
, name
);
9307 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
9314 /************************************************************************
9316 ************************************************************************/
9318 /* Display Error Handling functions not used on W32. Listing them here
9319 helps diff stay in step when comparing w32term.c with xterm.c.
9321 x_error_catcher (display, error)
9322 x_catch_errors (dpy)
9323 x_catch_errors_unwind (old_val)
9324 x_check_errors (dpy, format)
9325 x_had_errors_p (dpy)
9326 x_clear_errors (dpy)
9327 x_uncatch_errors (dpy, count)
9329 x_connection_signal (signalnum)
9330 x_connection_closed (dpy, error_message)
9331 x_error_quitter (display, error)
9332 x_error_handler (display, error)
9333 x_io_error_quitter (display)
9338 /* Changing the font of the frame. */
9340 /* Give frame F the font named FONTNAME as its default font, and
9341 return the full name of that font. FONTNAME may be a wildcard
9342 pattern; in that case, we choose some font that fits the pattern.
9343 The return value shows which font we chose. */
9346 x_new_font (f
, fontname
)
9348 register char *fontname
;
9350 struct font_info
*fontp
9351 = FS_LOAD_FONT (f
, 0, fontname
, -1);
9356 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
9357 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
9358 FRAME_FONTSET (f
) = -1;
9360 /* Compute the scroll bar width in character columns. */
9361 if (f
->scroll_bar_pixel_width
> 0)
9363 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9364 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
9368 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9369 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
9372 /* Now make the frame display the given font. */
9373 if (FRAME_W32_WINDOW (f
) != 0)
9375 frame_update_line_height (f
);
9376 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9377 x_set_window_size (f
, 0, f
->width
, f
->height
);
9380 /* If we are setting a new frame's font for the first time,
9381 there are no faces yet, so this font's height is the line height. */
9382 f
->output_data
.w32
->line_height
= FONT_HEIGHT (FRAME_FONT (f
));
9384 return build_string (fontp
->full_name
);
9387 /* Give frame F the fontset named FONTSETNAME as its default font, and
9388 return the full name of that fontset. FONTSETNAME may be a wildcard
9389 pattern; in that case, we choose some fontset that fits the pattern.
9390 The return value shows which fontset we chose. */
9393 x_new_fontset (f
, fontsetname
)
9397 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
9403 if (FRAME_FONTSET (f
) == fontset
)
9404 /* This fontset is already set in frame F. There's nothing more
9406 return fontset_name (fontset
);
9408 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
9410 if (!STRINGP (result
))
9411 /* Can't load ASCII font. */
9414 /* Since x_new_font doesn't update any fontset information, do it now. */
9415 FRAME_FONTSET(f
) = fontset
;
9417 return build_string (fontsetname
);
9421 /***********************************************************************
9422 TODO: W32 Input Methods
9423 ***********************************************************************/
9424 /* Listing missing functions from xterm.c helps diff stay in step.
9426 xim_destroy_callback (xim, client_data, call_data)
9427 xim_open_dpy (dpyinfo, resource_name)
9429 xim_instantiate_callback (display, client_data, call_data)
9430 xim_initialize (dpyinfo, resource_name)
9431 xim_close_dpy (dpyinfo)
9436 /* Calculate the absolute position in frame F
9437 from its current recorded position values and gravity. */
9440 x_calc_absolute_position (f
)
9444 int flags
= f
->output_data
.w32
->size_hint_flags
;
9448 /* Find the position of the outside upper-left corner of
9449 the inner window, with respect to the outer window.
9450 But do this only if we will need the results. */
9451 if (f
->output_data
.w32
->parent_desc
!= FRAME_W32_DISPLAY_INFO (f
)->root_window
)
9454 MapWindowPoints (FRAME_W32_WINDOW (f
),
9455 f
->output_data
.w32
->parent_desc
,
9462 rt
.left
= rt
.right
= rt
.top
= rt
.bottom
= 0;
9465 AdjustWindowRect(&rt
, f
->output_data
.w32
->dwStyle
,
9466 FRAME_EXTERNAL_MENU_BAR (f
));
9469 pt
.x
+= (rt
.right
- rt
.left
);
9470 pt
.y
+= (rt
.bottom
- rt
.top
);
9473 /* Treat negative positions as relative to the leftmost bottommost
9474 position that fits on the screen. */
9475 if (flags
& XNegative
)
9476 f
->output_data
.w32
->left_pos
= (FRAME_W32_DISPLAY_INFO (f
)->width
9477 - 2 * f
->output_data
.w32
->border_width
- pt
.x
9479 + f
->output_data
.w32
->left_pos
);
9481 if (flags
& YNegative
)
9482 f
->output_data
.w32
->top_pos
= (FRAME_W32_DISPLAY_INFO (f
)->height
9483 - 2 * f
->output_data
.w32
->border_width
- pt
.y
9485 + f
->output_data
.w32
->top_pos
);
9486 /* The left_pos and top_pos
9487 are now relative to the top and left screen edges,
9488 so the flags should correspond. */
9489 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9492 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
9493 to really change the position, and 0 when calling from
9494 x_make_frame_visible (in that case, XOFF and YOFF are the current
9495 position values). It is -1 when calling from x_set_frame_parameters,
9496 which means, do adjust for borders but don't change the gravity. */
9499 x_set_offset (f
, xoff
, yoff
, change_gravity
)
9501 register int xoff
, yoff
;
9504 int modified_top
, modified_left
;
9506 if (change_gravity
> 0)
9508 f
->output_data
.w32
->top_pos
= yoff
;
9509 f
->output_data
.w32
->left_pos
= xoff
;
9510 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9512 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
9514 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
9515 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
9517 x_calc_absolute_position (f
);
9520 x_wm_set_size_hint (f
, (long) 0, 0);
9522 modified_left
= f
->output_data
.w32
->left_pos
;
9523 modified_top
= f
->output_data
.w32
->top_pos
;
9525 my_set_window_pos (FRAME_W32_WINDOW (f
),
9527 modified_left
, modified_top
,
9529 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
9533 /* Call this to change the size of frame F's x-window.
9534 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9535 for this size change and subsequent size changes.
9536 Otherwise we leave the window gravity unchanged. */
9539 x_set_window_size (f
, change_gravity
, cols
, rows
)
9544 int pixelwidth
, pixelheight
;
9548 check_frame_size (f
, &rows
, &cols
);
9549 f
->output_data
.w32
->vertical_scroll_bar_extra
9550 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9552 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
9553 f
->output_data
.w32
->flags_areas_extra
9554 = FRAME_FLAGS_AREA_WIDTH (f
);
9555 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
9556 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
9558 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
9559 x_wm_set_size_hint (f
, (long) 0, 0);
9564 rect
.left
= rect
.top
= 0;
9565 rect
.right
= pixelwidth
;
9566 rect
.bottom
= pixelheight
;
9568 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
,
9569 FRAME_EXTERNAL_MENU_BAR (f
));
9571 my_set_window_pos (FRAME_W32_WINDOW (f
),
9574 rect
.right
- rect
.left
,
9575 rect
.bottom
- rect
.top
,
9576 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9579 /* Now, strictly speaking, we can't be sure that this is accurate,
9580 but the window manager will get around to dealing with the size
9581 change request eventually, and we'll hear how it went when the
9582 ConfigureNotify event gets here.
9584 We could just not bother storing any of this information here,
9585 and let the ConfigureNotify event set everything up, but that
9586 might be kind of confusing to the Lisp code, since size changes
9587 wouldn't be reported in the frame parameters until some random
9588 point in the future when the ConfigureNotify event arrives.
9590 We pass 1 for DELAY since we can't run Lisp code inside of
9592 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9593 PIXEL_WIDTH (f
) = pixelwidth
;
9594 PIXEL_HEIGHT (f
) = pixelheight
;
9596 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9597 receive in the ConfigureNotify event; if we get what we asked
9598 for, then the event won't cause the screen to become garbaged, so
9599 we have to make sure to do it here. */
9600 SET_FRAME_GARBAGED (f
);
9602 /* If cursor was outside the new size, mark it as off. */
9603 mark_window_cursors_off (XWINDOW (f
->root_window
));
9605 /* Clear out any recollection of where the mouse highlighting was,
9606 since it might be in a place that's outside the new frame size.
9607 Actually checking whether it is outside is a pain in the neck,
9608 so don't try--just let the highlighting be done afresh with new size. */
9609 cancel_mouse_face (f
);
9614 /* Mouse warping. */
9616 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
9619 x_set_mouse_position (f
, x
, y
)
9625 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.w32
->font
) / 2;
9626 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.w32
->line_height
/ 2;
9628 if (pix_x
< 0) pix_x
= 0;
9629 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
9631 if (pix_y
< 0) pix_y
= 0;
9632 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
9634 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
9638 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9647 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
9648 pt
.x
= rect
.left
+ pix_x
;
9649 pt
.y
= rect
.top
+ pix_y
;
9650 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
9652 SetCursorPos (pt
.x
, pt
.y
);
9658 /* focus shifting, raising and lowering. */
9661 x_focus_on_frame (f
)
9664 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
9666 /* Give input focus to frame. */
9669 /* Try not to change its Z-order if possible. */
9670 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
9671 my_set_focus (f
, FRAME_W32_WINDOW (f
));
9674 my_set_foreground_window (FRAME_W32_WINDOW (f
));
9684 /* Raise frame F. */
9691 /* Strictly speaking, raise-frame should only change the frame's Z
9692 order, leaving input focus unchanged. This is reasonable behaviour
9693 on X where the usual policy is point-to-focus. However, this
9694 behaviour would be very odd on Windows where the usual policy is
9697 On X, if the mouse happens to be over the raised frame, it gets
9698 input focus anyway (so the window with focus will never be
9699 completely obscured) - if not, then just moving the mouse over it
9700 is sufficient to give it focus. On Windows, the user must actually
9701 click on the frame (preferrably the title bar so as not to move
9702 point), which is more awkward. Also, no other Windows program
9703 raises a window to the top but leaves another window (possibly now
9704 completely obscured) with input focus.
9706 Because there is a system setting on Windows that allows the user
9707 to choose the point to focus policy, we make the strict semantics
9708 optional, but by default we grab focus when raising. */
9710 if (NILP (Vw32_grab_focus_on_raise
))
9712 /* The obvious call to my_set_window_pos doesn't work if Emacs is
9713 not already the foreground application: the frame is raised
9714 above all other frames belonging to us, but not above the
9715 current top window. To achieve that, we have to resort to this
9716 more cumbersome method. */
9718 HDWP handle
= BeginDeferWindowPos (2);
9721 DeferWindowPos (handle
,
9722 FRAME_W32_WINDOW (f
),
9725 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9727 DeferWindowPos (handle
,
9728 GetForegroundWindow (),
9729 FRAME_W32_WINDOW (f
),
9731 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9733 EndDeferWindowPos (handle
);
9738 my_set_foreground_window (FRAME_W32_WINDOW (f
));
9744 /* Lower frame F. */
9750 my_set_window_pos (FRAME_W32_WINDOW (f
),
9753 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9758 w32_frame_raise_lower (f
, raise_flag
)
9762 if (! FRAME_W32_P (f
))
9771 /* Change of visibility. */
9773 /* This tries to wait until the frame is really visible.
9774 However, if the window manager asks the user where to position
9775 the frame, this will return before the user finishes doing that.
9776 The frame will not actually be visible at that time,
9777 but it will become visible later when the window manager
9778 finishes with it. */
9781 x_make_frame_visible (f
)
9788 type
= x_icon_type (f
);
9790 x_bitmap_icon (f
, type
);
9792 if (! FRAME_VISIBLE_P (f
))
9794 /* We test FRAME_GARBAGED_P here to make sure we don't
9795 call x_set_offset a second time
9796 if we get to x_make_frame_visible a second time
9797 before the window gets really visible. */
9798 if (! FRAME_ICONIFIED_P (f
)
9799 && ! f
->output_data
.w32
->asked_for_visible
)
9800 x_set_offset (f
, f
->output_data
.w32
->left_pos
, f
->output_data
.w32
->top_pos
, 0);
9802 f
->output_data
.w32
->asked_for_visible
= 1;
9804 // my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW);
9805 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_SHOWNORMAL
);
9808 /* Synchronize to ensure Emacs knows the frame is visible
9809 before we do anything else. We do this loop with input not blocked
9810 so that incoming events are handled. */
9815 /* This must come after we set COUNT. */
9818 XSETFRAME (frame
, f
);
9820 /* Wait until the frame is visible. Process X events until a
9821 MapNotify event has been seen, or until we think we won't get a
9822 MapNotify at all.. */
9823 for (count
= input_signal_count
+ 10;
9824 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9826 /* Force processing of queued events. */
9827 /* TODO: x_sync equivalent? */
9829 /* Machines that do polling rather than SIGIO have been observed
9830 to go into a busy-wait here. So we'll fake an alarm signal
9831 to let the handler know that there's something to be read.
9832 We used to raise a real alarm, but it seems that the handler
9833 isn't always enabled here. This is probably a bug. */
9834 if (input_polling_used ())
9836 /* It could be confusing if a real alarm arrives while processing
9837 the fake one. Turn it off and let the handler reset it. */
9838 int old_poll_suppress_count
= poll_suppress_count
;
9839 poll_suppress_count
= 1;
9840 poll_for_input_1 ();
9841 poll_suppress_count
= old_poll_suppress_count
;
9844 FRAME_SAMPLE_VISIBILITY (f
);
9848 /* Change from mapped state to withdrawn state. */
9850 /* Make the frame visible (mapped and not iconified). */
9852 x_make_frame_invisible (f
)
9855 /* Don't keep the highlight on an invisible frame. */
9856 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
9857 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
9861 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
9863 /* We can't distinguish this from iconification
9864 just by the event that we get from the server.
9865 So we can't win using the usual strategy of letting
9866 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9867 and synchronize with the server to make sure we agree. */
9869 FRAME_ICONIFIED_P (f
) = 0;
9870 f
->async_visible
= 0;
9871 f
->async_iconified
= 0;
9876 /* Change window state from mapped to iconified. */
9884 /* Don't keep the highlight on an invisible frame. */
9885 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
9886 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
9888 if (f
->async_iconified
)
9893 type
= x_icon_type (f
);
9895 x_bitmap_icon (f
, type
);
9897 /* Simulate the user minimizing the frame. */
9898 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
9904 /* Free X resources of frame F. */
9907 x_free_frame_resources (f
)
9910 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9914 if (FRAME_W32_WINDOW (f
))
9915 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
9917 free_frame_menubar (f
);
9919 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
9920 unload_color (f
, f
->output_data
.x
->background_pixel
);
9921 unload_color (f
, f
->output_data
.w32
->cursor_pixel
);
9922 unload_color (f
, f
->output_data
.w32
->cursor_foreground_pixel
);
9923 unload_color (f
, f
->output_data
.w32
->border_pixel
);
9924 unload_color (f
, f
->output_data
.w32
->mouse_pixel
);
9925 if (f
->output_data
.w32
->white_relief
.allocated_p
)
9926 unload_color (f
, f
->output_data
.w32
->white_relief
.pixel
);
9927 if (f
->output_data
.w32
->black_relief
.allocated_p
)
9928 unload_color (f
, f
->output_data
.w32
->black_relief
.pixel
);
9930 if (FRAME_FACE_CACHE (f
))
9931 free_frame_faces (f
);
9933 xfree (f
->output_data
.w32
);
9934 f
->output_data
.w32
= NULL
;
9936 if (f
== dpyinfo
->w32_focus_frame
)
9937 dpyinfo
->w32_focus_frame
= 0;
9938 if (f
== dpyinfo
->w32_focus_event_frame
)
9939 dpyinfo
->w32_focus_event_frame
= 0;
9940 if (f
== dpyinfo
->w32_highlight_frame
)
9941 dpyinfo
->w32_highlight_frame
= 0;
9943 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9945 dpyinfo
->mouse_face_beg_row
9946 = dpyinfo
->mouse_face_beg_col
= -1;
9947 dpyinfo
->mouse_face_end_row
9948 = dpyinfo
->mouse_face_end_col
= -1;
9949 dpyinfo
->mouse_face_window
= Qnil
;
9950 dpyinfo
->mouse_face_deferred_gc
= 0;
9951 dpyinfo
->mouse_face_mouse_frame
= 0;
9958 /* Destroy the window of frame F. */
9960 x_destroy_window (f
)
9963 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9965 x_free_frame_resources (f
);
9967 dpyinfo
->reference_count
--;
9971 /* Setting window manager hints. */
9973 /* Set the normal size hints for the window manager, for frame F.
9974 FLAGS is the flags word to use--or 0 meaning preserve the flags
9975 that the window now has.
9976 If USER_POSITION is nonzero, we set the USPosition
9977 flag (this is useful when FLAGS is 0). */
9979 x_wm_set_size_hint (f
, flags
, user_position
)
9984 Window window
= FRAME_W32_WINDOW (f
);
9988 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
9989 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
9990 SetWindowLong (window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
9991 SetWindowLong (window
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
9996 /* Window manager things */
9997 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10002 Window window
= FRAME_W32_WINDOW (f
);
10004 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
10005 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
10006 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
10008 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
10013 /***********************************************************************
10015 ***********************************************************************/
10017 /* The following functions are listed here to help diff stay in step
10018 with xterm.c. See w32fns.c for definitions.
10020 x_get_font_info (f, font_idx)
10021 x_list_fonts (f, pattern, size, maxnames)
10027 /* Check that FONT is valid on frame F. It is if it can be found in F's
10031 x_check_font (f
, font
)
10036 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10038 xassert (font
!= NULL
);
10040 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10041 if (dpyinfo
->font_table
[i
].name
10042 && font
== dpyinfo
->font_table
[i
].font
)
10045 xassert (i
< dpyinfo
->n_fonts
);
10048 #endif /* GLYPH_DEBUG != 0 */
10050 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10051 Note: There are (broken) X fonts out there with invalid XFontStruct
10052 min_bounds contents. For example, handa@etl.go.jp reports that
10053 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10054 have font->min_bounds.width == 0. */
10057 x_font_min_bounds (font
, w
, h
)
10062 * TODO: Windows does not appear to offer min bound, only
10063 * average and maximum width, and maximum height.
10065 *h
= FONT_HEIGHT (font
);
10066 *w
= FONT_WIDTH (font
);
10070 /* Compute the smallest character width and smallest font height over
10071 all fonts available on frame F. Set the members smallest_char_width
10072 and smallest_font_height in F's x_display_info structure to
10073 the values computed. Value is non-zero if smallest_font_height or
10074 smallest_char_width become smaller than they were before. */
10077 x_compute_min_glyph_bounds (f
)
10081 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10083 int old_width
= dpyinfo
->smallest_char_width
;
10084 int old_height
= dpyinfo
->smallest_font_height
;
10086 dpyinfo
->smallest_font_height
= 100000;
10087 dpyinfo
->smallest_char_width
= 100000;
10089 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10090 if (dpyinfo
->font_table
[i
].name
)
10092 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10095 font
= (XFontStruct
*) fontp
->font
;
10096 xassert (font
!= (XFontStruct
*) ~0);
10097 x_font_min_bounds (font
, &w
, &h
);
10099 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10100 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10103 xassert (dpyinfo
->smallest_char_width
> 0
10104 && dpyinfo
->smallest_font_height
> 0);
10106 return (dpyinfo
->n_fonts
== 1
10107 || dpyinfo
->smallest_char_width
< old_width
10108 || dpyinfo
->smallest_font_height
< old_height
);
10111 /* The following functions are listed here to help diff stay in step
10112 with xterm.c. See w32fns.c for definitions.
10114 x_load_font (f, fontname, size)
10115 x_query_font (f, fontname)
10116 x_find_ccl_program (fontp)
10120 /***********************************************************************
10122 ***********************************************************************/
10124 static int w32_initialized
= 0;
10127 w32_initialize_display_info (display_name
)
10128 Lisp_Object display_name
;
10130 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
10132 bzero (dpyinfo
, sizeof (*dpyinfo
));
10134 /* Put it on w32_display_name_list. */
10135 w32_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10136 w32_display_name_list
);
10137 dpyinfo
->name_list_element
= XCAR (w32_display_name_list
);
10139 dpyinfo
->w32_id_name
10140 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
10141 + XSTRING (Vsystem_name
)->size
10143 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
10144 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
10146 /* Default Console mode values - overridden when running in GUI mode
10147 with values obtained from system metrics. */
10150 dpyinfo
->height_in
= 1;
10151 dpyinfo
->width_in
= 1;
10152 dpyinfo
->n_planes
= 1;
10153 dpyinfo
->n_cbits
= 4;
10154 dpyinfo
->n_fonts
= 0;
10155 dpyinfo
->smallest_font_height
= 1;
10156 dpyinfo
->smallest_char_width
= 1;
10158 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10159 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10160 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10161 dpyinfo
->mouse_face_window
= Qnil
;
10163 /* TODO: dpyinfo->gray */
10167 struct w32_display_info
*
10168 w32_term_init (display_name
, xrm_option
, resource_name
)
10169 Lisp_Object display_name
;
10171 char *resource_name
;
10173 struct w32_display_info
*dpyinfo
;
10178 if (!w32_initialized
)
10181 w32_initialized
= 1;
10192 argv
[argc
++] = "-xrm";
10193 argv
[argc
++] = xrm_option
;
10197 w32_initialize_display_info (display_name
);
10199 dpyinfo
= &one_w32_display_info
;
10201 /* Put this display on the chain. */
10202 dpyinfo
->next
= x_display_list
;
10203 x_display_list
= dpyinfo
;
10205 hdc
= GetDC (GetDesktopWindow ());
10207 dpyinfo
->height
= GetDeviceCaps (hdc
, VERTRES
);
10208 dpyinfo
->width
= GetDeviceCaps (hdc
, HORZRES
);
10209 dpyinfo
->root_window
= GetDesktopWindow ();
10210 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
10211 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
10212 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
10213 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
10214 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
10215 dpyinfo
->image_cache
= make_image_cache ();
10216 dpyinfo
->height_in
= dpyinfo
->height
/ dpyinfo
->resx
;
10217 dpyinfo
->width_in
= dpyinfo
->width
/ dpyinfo
->resy
;
10218 ReleaseDC (GetDesktopWindow (), hdc
);
10220 /* initialise palette with white and black */
10223 w32_defined_color (0, "white", &color
, 1);
10224 w32_defined_color (0, "black", &color
, 1);
10227 /* Create Row Bitmaps and store them for later use. */
10228 left_bmp
= CreateBitmap (left_width
, left_height
, 1, 1, left_bits
);
10229 ov_bmp
= CreateBitmap (ov_width
, ov_height
, 1, 1, ov_bits
);
10230 right_bmp
= CreateBitmap (right_width
, right_height
, 1, 1, right_bits
);
10231 continued_bmp
= CreateBitmap (continued_width
, continued_height
, 1,
10232 1, continued_bits
);
10233 continuation_bmp
= CreateBitmap (continuation_width
, continuation_height
,
10234 1, 1, continuation_bits
);
10235 zv_bmp
= CreateBitmap (zv_width
, zv_height
, 1, 1, zv_bits
);
10237 #ifndef F_SETOWN_BUG
10239 #ifdef F_SETOWN_SOCK_NEG
10240 /* stdin is a socket here */
10241 fcntl (connection
, F_SETOWN
, -getpid ());
10242 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10243 fcntl (connection
, F_SETOWN
, getpid ());
10244 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10245 #endif /* ! defined (F_SETOWN) */
10246 #endif /* F_SETOWN_BUG */
10249 if (interrupt_input
)
10250 init_sigio (connection
);
10251 #endif /* ! defined (SIGIO) */
10258 /* Get rid of display DPYINFO, assuming all frames are already gone. */
10261 x_delete_display (dpyinfo
)
10262 struct w32_display_info
*dpyinfo
;
10264 /* Discard this display from w32_display_name_list and w32_display_list.
10265 We can't use Fdelq because that can quit. */
10266 if (! NILP (w32_display_name_list
)
10267 && EQ (XCAR (w32_display_name_list
), dpyinfo
->name_list_element
))
10268 w32_display_name_list
= XCDR (w32_display_name_list
);
10273 tail
= w32_display_name_list
;
10274 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10276 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10278 XCDR (tail
) = XCDR (XCDR (tail
));
10281 tail
= XCDR (tail
);
10285 /* free palette table */
10287 struct w32_palette_entry
* plist
;
10289 plist
= dpyinfo
->color_list
;
10292 struct w32_palette_entry
* pentry
= plist
;
10293 plist
= plist
->next
;
10296 dpyinfo
->color_list
= NULL
;
10297 if (dpyinfo
->palette
)
10298 DeleteObject(dpyinfo
->palette
);
10300 xfree (dpyinfo
->font_table
);
10301 xfree (dpyinfo
->w32_id_name
);
10303 /* Destroy row bitmaps. */
10304 DeleteObject (left_bmp
);
10305 DeleteObject (ov_bmp
);
10306 DeleteObject (right_bmp
);
10307 DeleteObject (continued_bmp
);
10308 DeleteObject (continuation_bmp
);
10309 DeleteObject (zv_bmp
);
10312 /* Set up use of W32. */
10314 DWORD
w32_msg_worker ();
10317 x_flush (struct frame
* f
)
10318 { /* Nothing to do */ }
10320 static struct redisplay_interface w32_redisplay_interface
=
10325 x_clear_end_of_line
,
10327 x_after_update_window_line
,
10328 x_update_window_begin
,
10329 x_update_window_end
,
10332 x_clear_mouse_face
,
10333 x_get_glyph_overhangs
,
10334 x_fix_overlapping_area
10340 rif
= &w32_redisplay_interface
;
10342 /* MSVC does not type K&R functions with no arguments correctly, and
10343 so we must explicitly cast them. */
10344 clear_frame_hook
= (void (*)(void)) x_clear_frame
;
10345 ring_bell_hook
= (void (*)(void)) w32_ring_bell
;
10346 update_begin_hook
= x_update_begin
;
10347 update_end_hook
= x_update_end
;
10349 read_socket_hook
= w32_read_socket
;
10351 frame_up_to_date_hook
= w32_frame_up_to_date
;
10353 mouse_position_hook
= w32_mouse_position
;
10354 frame_rehighlight_hook
= w32_frame_rehighlight
;
10355 frame_raise_lower_hook
= w32_frame_raise_lower
;
10356 set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
10357 condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
10358 redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
10359 judge_scroll_bars_hook
= w32_judge_scroll_bars
;
10360 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
10362 scroll_region_ok
= 1; /* we'll scroll partial frames */
10363 char_ins_del_ok
= 1;
10364 line_ins_del_ok
= 1; /* we'll just blt 'em */
10365 fast_clear_end_of_line
= 1; /* X does this well */
10366 memory_below_frame
= 0; /* we don't remember what scrolls
10370 last_tool_bar_item
= -1;
10371 any_help_event_p
= 0;
10373 /* Initialize input mode: interrupt_input off, no flow control, allow
10374 8 bit character input, standard quit char. */
10375 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
10377 /* Create the window thread - it will terminate itself or when the app terminates */
10381 dwMainThreadId
= GetCurrentThreadId ();
10382 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
10383 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
10385 /* Wait for thread to start */
10390 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
10392 hWindowsThread
= CreateThread (NULL
, 0,
10393 (LPTHREAD_START_ROUTINE
) w32_msg_worker
,
10394 0, 0, &dwWindowsThreadId
);
10396 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
10399 /* It is desirable that mainThread should have the same notion of
10400 focus window and active window as windowsThread. Unfortunately, the
10401 following call to AttachThreadInput, which should do precisely what
10402 we need, causes major problems when Emacs is linked as a console
10403 program. Unfortunately, we have good reasons for doing that, so
10404 instead we need to send messages to windowsThread to make some API
10405 calls for us (ones that affect, or depend on, the active/focus
10407 #ifdef ATTACH_THREADS
10408 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
10411 /* Dynamically link to optional system components. */
10413 HANDLE user_lib
= LoadLibrary ("user32.dll");
10415 #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn)
10417 /* New proportional scroll bar functions. */
10418 LOAD_PROC (SetScrollInfo
);
10419 LOAD_PROC (GetScrollInfo
);
10423 FreeLibrary (user_lib
);
10425 /* If using proportional scroll bars, ensure handle is at least 5 pixels;
10426 otherwise use the fixed height. */
10427 vertical_scroll_bar_min_handle
= (pfnSetScrollInfo
!= NULL
) ? 5 :
10428 GetSystemMetrics (SM_CYVTHUMB
);
10430 /* For either kind of scroll bar, take account of the arrows; these
10431 effectively form the border of the main scroll bar range. */
10432 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
10433 = GetSystemMetrics (SM_CYVSCROLL
);
10440 staticpro (&w32_display_name_list
);
10441 w32_display_name_list
= Qnil
;
10443 staticpro (&last_mouse_scroll_bar
);
10444 last_mouse_scroll_bar
= Qnil
;
10446 staticpro (&Qvendor_specific_keysyms
);
10447 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
10449 DEFVAR_INT ("w32-num-mouse-buttons",
10450 &Vw32_num_mouse_buttons
,
10451 "Number of physical mouse buttons.");
10452 Vw32_num_mouse_buttons
= Qnil
;
10454 DEFVAR_LISP ("w32-swap-mouse-buttons",
10455 &Vw32_swap_mouse_buttons
,
10456 "Swap the mapping of middle and right mouse buttons.\n\
10457 When nil, middle button is mouse-2 and right button is mouse-3.");
10458 Vw32_swap_mouse_buttons
= Qnil
;
10460 DEFVAR_LISP ("w32-grab-focus-on-raise",
10461 &Vw32_grab_focus_on_raise
,
10462 "Raised frame grabs input focus.\n\
10463 When t, `raise-frame' grabs input focus as well. This fits well\n\
10464 with the normal Windows click-to-focus policy, but might not be\n\
10465 desirable when using a point-to-focus policy.");
10466 Vw32_grab_focus_on_raise
= Qt
;
10468 DEFVAR_LISP ("w32-capslock-is-shiftlock",
10469 &Vw32_capslock_is_shiftlock
,
10470 "Apply CapsLock state to non character input keys.\n\
10471 When nil, CapsLock only affects normal character input keys.");
10472 Vw32_capslock_is_shiftlock
= Qnil
;
10474 DEFVAR_LISP ("w32-recognize-altgr",
10475 &Vw32_recognize_altgr
,
10476 "Recognize right-alt and left-ctrl as AltGr.\n\
10477 When nil, the right-alt and left-ctrl key combination is\n\
10478 interpreted normally.");
10479 Vw32_recognize_altgr
= Qt
;
10481 DEFVAR_BOOL ("w32-enable-unicode-output",
10482 &w32_enable_unicode_output
,
10483 "Enable the use of Unicode for text output if non-nil.\n\
10484 Unicode output may prevent some third party applications for displaying\n\
10485 Far-East Languages on Windows 95/98 from working properly.\n\
10486 NT uses Unicode internally anyway, so this flag will probably have no\n\
10487 affect on NT machines.");
10488 w32_enable_unicode_output
= 1;
10491 staticpro (&help_echo
);
10492 help_echo_object
= Qnil
;
10493 staticpro (&help_echo_object
);
10494 help_echo_window
= Qnil
;
10495 staticpro (&help_echo_window
);
10496 previous_help_echo
= Qnil
;
10497 staticpro (&previous_help_echo
);
10498 help_echo_pos
= -1;
10500 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
10501 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
10502 For example, if a block cursor is over a tab, it will be drawn as\n\
10503 wide as that tab on the display.");
10504 x_stretch_cursor_p
= 0;
10506 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10507 "If not nil, Emacs uses toolkit scroll bars.");
10508 Vx_toolkit_scroll_bars
= Qt
;
10510 staticpro (&last_mouse_motion_frame
);
10511 last_mouse_motion_frame
= Qnil
;