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 int relief_drawn_p
= 0;
4305 /* If S draws into the background of its successor, draw the
4306 background of the successor first so that S can draw into it.
4307 This makes S->next use XDrawString instead of XDrawImageString. */
4308 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4310 xassert (s
->next
->img
== NULL
);
4311 x_set_glyph_string_gc (s
->next
);
4312 x_set_glyph_string_clipping (s
->next
);
4313 x_draw_glyph_string_background (s
->next
, 1);
4316 /* Set up S->gc, set clipping and draw S. */
4317 x_set_glyph_string_gc (s
);
4318 x_set_glyph_string_clipping (s
);
4320 /* Draw relief (if any) in advance for char/composition so that the
4321 glyph string can be drawn over it. */
4322 if (!s
->for_overlaps_p
4323 && s
->face
->box
!= FACE_NO_BOX
4324 && (s
->first_glyph
->type
== CHAR_GLYPH
4325 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4328 x_draw_glyph_string_background (s
, 1);
4329 x_draw_glyph_string_box (s
);
4333 switch (s
->first_glyph
->type
)
4336 x_draw_image_glyph_string (s
);
4340 x_draw_stretch_glyph_string (s
);
4344 if (s
->for_overlaps_p
)
4345 s
->background_filled_p
= 1;
4347 x_draw_glyph_string_background (s
, 0);
4348 x_draw_glyph_string_foreground (s
);
4351 case COMPOSITE_GLYPH
:
4352 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4353 s
->background_filled_p
= 1;
4355 x_draw_glyph_string_background (s
, 1);
4356 x_draw_composite_glyph_string_foreground (s
);
4363 if (!s
->for_overlaps_p
)
4365 /* Draw underline. */
4366 if (s
->face
->underline_p
4367 && (s
->font
->bdf
|| !s
->font
->tm
.tmUnderlined
))
4369 unsigned long h
= 1;
4370 unsigned long dy
= s
->height
- h
;
4372 if (s
->face
->underline_defaulted_p
)
4374 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4375 s
->y
+ dy
, s
->width
, 1);
4379 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4380 s
->y
+ dy
, s
->width
, 1);
4384 /* Draw overline. */
4385 if (s
->face
->overline_p
)
4387 unsigned long dy
= 0, h
= 1;
4389 if (s
->face
->overline_color_defaulted_p
)
4391 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
4392 s
->y
+ dy
, s
->width
, h
);
4396 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4397 s
->y
+ dy
, s
->width
, h
);
4401 /* Draw strike-through. */
4402 if (s
->face
->strike_through_p
4403 && (s
->font
->bdf
|| !s
->font
->tm
.tmStruckOut
))
4405 unsigned long h
= 1;
4406 unsigned long dy
= (s
->height
- h
) / 2;
4408 if (s
->face
->strike_through_color_defaulted_p
)
4410 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
4415 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
4416 s
->y
+ dy
, s
->width
, h
);
4421 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4422 x_draw_glyph_string_box (s
);
4425 /* Reset clipping. */
4426 w32_set_clip_rectangle (s
->hdc
, NULL
);
4430 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4431 struct face
**, int));
4434 /* Fill glyph string S with composition components specified by S->cmp.
4436 FACES is an array of faces for all components of this composition.
4437 S->gidx is the index of the first component for S.
4438 OVERLAPS_P non-zero means S should draw the foreground only, and
4439 use its physical height for clipping.
4441 Value is the index of a component not in S. */
4444 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4445 struct glyph_string
*s
;
4446 struct face
**faces
;
4453 s
->for_overlaps_p
= overlaps_p
;
4455 s
->face
= faces
[s
->gidx
];
4456 s
->font
= s
->face
->font
;
4457 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4459 /* For all glyphs of this composition, starting at the offset
4460 S->gidx, until we reach the end of the definition or encounter a
4461 glyph that requires the different face, add it to S. */
4463 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4466 /* All glyph strings for the same composition has the same width,
4467 i.e. the width set for the first component of the composition. */
4469 s
->width
= s
->first_glyph
->pixel_width
;
4471 /* If the specified font could not be loaded, use the frame's
4472 default font, but record the fact that we couldn't load it in
4473 the glyph string so that we can draw rectangles for the
4474 characters of the glyph string. */
4475 if (s
->font
== NULL
)
4477 s
->font_not_found_p
= 1;
4478 s
->font
= FRAME_FONT (s
->f
);
4481 /* Adjust base line for subscript/superscript text. */
4482 s
->ybase
+= s
->first_glyph
->voffset
;
4484 xassert (s
->face
&& s
->face
->gc
);
4486 /* This glyph string must always be drawn with 16-bit functions. */
4489 return s
->gidx
+ s
->nchars
;
4493 /* Fill glyph string S from a sequence of character glyphs.
4495 FACE_ID is the face id of the string. START is the index of the
4496 first glyph to consider, END is the index of the last + 1.
4497 OVERLAPS_P non-zero means S should draw the foreground only, and
4498 use its physical height for clipping.
4500 Value is the index of the first glyph not in S. */
4503 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4504 struct glyph_string
*s
;
4506 int start
, end
, overlaps_p
;
4508 struct glyph
*glyph
, *last
;
4510 int glyph_not_available_p
;
4512 xassert (s
->f
== XFRAME (s
->w
->frame
));
4513 xassert (s
->nchars
== 0);
4514 xassert (start
>= 0 && end
> start
);
4516 s
->for_overlaps_p
= overlaps_p
;
4517 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4518 last
= s
->row
->glyphs
[s
->area
] + end
;
4519 voffset
= glyph
->voffset
;
4521 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4524 && glyph
->type
== CHAR_GLYPH
4525 && glyph
->voffset
== voffset
4526 /* Same face id implies same font, nowadays. */
4527 && glyph
->face_id
== face_id
4528 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4532 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4533 s
->char2b
+ s
->nchars
,
4535 s
->two_byte_p
= two_byte_p
;
4537 xassert (s
->nchars
<= end
- start
);
4538 s
->width
+= glyph
->pixel_width
;
4542 s
->font
= s
->face
->font
;
4543 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4545 /* If the specified font could not be loaded, use the frame's font,
4546 but record the fact that we couldn't load it in
4547 S->font_not_found_p so that we can draw rectangles for the
4548 characters of the glyph string. */
4549 if (s
->font
== NULL
|| glyph_not_available_p
)
4551 s
->font_not_found_p
= 1;
4552 s
->font
= FRAME_FONT (s
->f
);
4555 /* Adjust base line for subscript/superscript text. */
4556 s
->ybase
+= voffset
;
4558 xassert (s
->face
&& s
->face
->gc
);
4559 return glyph
- s
->row
->glyphs
[s
->area
];
4563 /* Fill glyph string S from image glyph S->first_glyph. */
4566 x_fill_image_glyph_string (s
)
4567 struct glyph_string
*s
;
4569 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4570 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4572 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4573 s
->font
= s
->face
->font
;
4574 s
->width
= s
->first_glyph
->pixel_width
;
4576 /* Adjust base line for subscript/superscript text. */
4577 s
->ybase
+= s
->first_glyph
->voffset
;
4581 /* Fill glyph string S from a sequence of stretch glyphs.
4583 ROW is the glyph row in which the glyphs are found, AREA is the
4584 area within the row. START is the index of the first glyph to
4585 consider, END is the index of the last + 1.
4587 Value is the index of the first glyph not in S. */
4590 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4591 struct glyph_string
*s
;
4592 struct glyph_row
*row
;
4593 enum glyph_row_area area
;
4596 struct glyph
*glyph
, *last
;
4597 int voffset
, face_id
;
4599 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4601 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4602 last
= s
->row
->glyphs
[s
->area
] + end
;
4603 face_id
= glyph
->face_id
;
4604 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4605 s
->font
= s
->face
->font
;
4606 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4607 s
->width
= glyph
->pixel_width
;
4608 voffset
= glyph
->voffset
;
4612 && glyph
->type
== STRETCH_GLYPH
4613 && glyph
->voffset
== voffset
4614 && glyph
->face_id
== face_id
);
4616 s
->width
+= glyph
->pixel_width
;
4618 /* Adjust base line for subscript/superscript text. */
4619 s
->ybase
+= voffset
;
4621 xassert (s
->face
&& s
->face
->gc
);
4622 return glyph
- s
->row
->glyphs
[s
->area
];
4626 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4627 of XChar2b structures for S; it can't be allocated in
4628 x_init_glyph_string because it must be allocated via `alloca'. W
4629 is the window on which S is drawn. ROW and AREA are the glyph row
4630 and area within the row from which S is constructed. START is the
4631 index of the first glyph structure covered by S. HL is a
4632 face-override for drawing S. */
4635 w32_init_glyph_string (s
, hdc
, char2b
, w
, row
, area
, start
, hl
)
4636 struct glyph_string
*s
;
4640 struct glyph_row
*row
;
4641 enum glyph_row_area area
;
4643 enum draw_glyphs_face hl
;
4645 bzero (s
, sizeof *s
);
4647 s
->f
= XFRAME (w
->frame
);
4649 s
->window
= FRAME_W32_WINDOW (s
->f
);
4654 s
->first_glyph
= row
->glyphs
[area
] + start
;
4655 s
->height
= row
->height
;
4656 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4658 /* Display the internal border below the tool-bar window. */
4659 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4660 s
->y
-= s
->f
->output_data
.w32
->internal_border_width
;
4662 s
->ybase
= s
->y
+ row
->ascent
;
4666 /* Set background width of glyph string S. START is the index of the
4667 first glyph following S. LAST_X is the right-most x-position + 1
4668 in the drawing area. */
4671 x_set_glyph_string_background_width (s
, start
, last_x
)
4672 struct glyph_string
*s
;
4676 /* If the face of this glyph string has to be drawn to the end of
4677 the drawing area, set S->extends_to_end_of_line_p. */
4678 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4680 if (start
== s
->row
->used
[s
->area
]
4681 && s
->area
== TEXT_AREA
4682 && ((s
->hl
== DRAW_NORMAL_TEXT
4683 && (s
->row
->fill_line_p
4684 || s
->face
->background
!= default_face
->background
4685 || s
->face
->stipple
!= default_face
->stipple
4686 || s
->row
->mouse_face_p
))
4687 || s
->hl
== DRAW_MOUSE_FACE
))
4688 s
->extends_to_end_of_line_p
= 1;
4690 /* If S extends its face to the end of the line, set its
4691 background_width to the distance to the right edge of the drawing
4693 if (s
->extends_to_end_of_line_p
)
4694 s
->background_width
= last_x
- s
->x
+ 1;
4696 s
->background_width
= s
->width
;
4700 /* Add a glyph string for a stretch glyph to the list of strings
4701 between HEAD and TAIL. START is the index of the stretch glyph in
4702 row area AREA of glyph row ROW. END is the index of the last glyph
4703 in that glyph row area. X is the current output position assigned
4704 to the new glyph string constructed. HL overrides that face of the
4705 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4706 is the right-most x-position of the drawing area. */
4708 #define BUILD_STRETCH_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4711 s = (struct glyph_string *) alloca (sizeof *s); \
4712 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4713 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4714 x_append_glyph_string (&HEAD, &TAIL, s); \
4720 /* Add a glyph string for an image glyph to the list of strings
4721 between HEAD and TAIL. START is the index of the image glyph in
4722 row area AREA of glyph row ROW. END is the index of the last glyph
4723 in that glyph row area. X is the current output position assigned
4724 to the new glyph string constructed. HL overrides that face of the
4725 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4726 is the right-most x-position of the drawing area. */
4728 #define BUILD_IMAGE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4731 s = (struct glyph_string *) alloca (sizeof *s); \
4732 w32_init_glyph_string (s, hdc, NULL, W, ROW, AREA, START, HL); \
4733 x_fill_image_glyph_string (s); \
4734 x_append_glyph_string (&HEAD, &TAIL, s); \
4741 /* Add a glyph string for a sequence of character glyphs to the list
4742 of strings between HEAD and TAIL. START is the index of the first
4743 glyph in row area AREA of glyph row ROW that is part of the new
4744 glyph string. END is the index of the last glyph in that glyph row
4745 area. X is the current output position assigned to the new glyph
4746 string constructed. HL overrides that face of the glyph; e.g. it
4747 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4748 right-most x-position of the drawing area. */
4750 #define BUILD_CHAR_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4756 c = (ROW)->glyphs[AREA][START].u.ch; \
4757 face_id = (ROW)->glyphs[AREA][START].face_id; \
4759 s = (struct glyph_string *) alloca (sizeof *s); \
4760 char2b = (wchar_t *) alloca ((END - START) * sizeof *char2b); \
4761 w32_init_glyph_string (s, hdc, char2b, W, ROW, AREA, START, HL); \
4762 x_append_glyph_string (&HEAD, &TAIL, s); \
4764 START = x_fill_glyph_string (s, face_id, START, END, \
4770 /* Add a glyph string for a composite sequence to the list of strings
4771 between HEAD and TAIL. START is the index of the first glyph in
4772 row area AREA of glyph row ROW that is part of the new glyph
4773 string. END is the index of the last glyph in that glyph row area.
4774 X is the current output position assigned to the new glyph string
4775 constructed. HL overrides that face of the glyph; e.g. it is
4776 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4777 x-position of the drawing area. */
4779 #define BUILD_COMPOSITE_GLYPH_STRING(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4781 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4782 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4783 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4784 struct composition *cmp = composition_table[cmp_id]; \
4785 int glyph_len = cmp->glyph_len; \
4787 struct face **faces; \
4788 struct glyph_string *first_s = NULL; \
4791 base_face = base_face->ascii_face; \
4792 char2b = (wchar_t *) alloca ((sizeof *char2b) * glyph_len); \
4793 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4794 /* At first, fill in `char2b' and `faces'. */ \
4795 for (n = 0; n < glyph_len; n++) \
4797 int c = COMPOSITION_GLYPH (cmp, n); \
4798 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4799 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4800 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4801 this_face_id, char2b + n, 1); \
4804 /* Make glyph_strings for each glyph sequence that is drawable by \
4805 the same face, and append them to HEAD/TAIL. */ \
4806 for (n = 0; n < cmp->glyph_len;) \
4808 s = (struct glyph_string *) alloca (sizeof *s); \
4809 w32_init_glyph_string (s, hdc, char2b + n, W, ROW, AREA, START, HL); \
4810 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4818 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4826 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4827 of AREA of glyph row ROW on window W between indices START and END.
4828 HL overrides the face for drawing glyph strings, e.g. it is
4829 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4830 x-positions of the drawing area.
4832 This is an ugly monster macro construct because we must use alloca
4833 to allocate glyph strings (because x_draw_glyphs can be called
4836 #define BUILD_GLYPH_STRINGS(hdc, W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4839 HEAD = TAIL = NULL; \
4840 while (START < END) \
4842 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4843 switch (first_glyph->type) \
4846 BUILD_CHAR_GLYPH_STRINGS (hdc, W, ROW, AREA, START, END, \
4847 HEAD, TAIL, HL, X, LAST_X, \
4851 case COMPOSITE_GLYPH: \
4852 BUILD_COMPOSITE_GLYPH_STRING (hdc, W, ROW, AREA, START, \
4853 END, HEAD, TAIL, HL, X, \
4854 LAST_X, OVERLAPS_P); \
4857 case STRETCH_GLYPH: \
4858 BUILD_STRETCH_GLYPH_STRING (hdc, W, ROW, AREA, START, END,\
4859 HEAD, TAIL, HL, X, LAST_X); \
4863 BUILD_IMAGE_GLYPH_STRING (hdc, W, ROW, AREA, START, END, \
4864 HEAD, TAIL, HL, X, LAST_X); \
4871 x_set_glyph_string_background_width (s, START, LAST_X); \
4878 /* Draw glyphs between START and END in AREA of ROW on window W,
4879 starting at x-position X. X is relative to AREA in W. HL is a
4880 face-override with the following meaning:
4882 DRAW_NORMAL_TEXT draw normally
4883 DRAW_CURSOR draw in cursor face
4884 DRAW_MOUSE_FACE draw in mouse face.
4885 DRAW_INVERSE_VIDEO draw in mode line face
4886 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4887 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4889 If REAL_START is non-null, return in *REAL_START the real starting
4890 position for display. This can be different from START in case
4891 overlapping glyphs must be displayed. If REAL_END is non-null,
4892 return in *REAL_END the real end position for display. This can be
4893 different from END in case overlapping glyphs must be displayed.
4895 If OVERLAPS_P is non-zero, draw only the foreground of characters
4896 and clip to the physical height of ROW.
4898 Value is the x-position reached, relative to AREA of W. */
4901 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4905 struct glyph_row
*row
;
4906 enum glyph_row_area area
;
4908 enum draw_glyphs_face hl
;
4909 int *real_start
, *real_end
;
4912 struct glyph_string
*head
, *tail
;
4913 struct glyph_string
*s
;
4914 int last_x
, area_width
;
4917 HDC hdc
= get_frame_dc (XFRAME (WINDOW_FRAME (w
)));
4919 /* Let's rather be paranoid than getting a SEGV. */
4920 end
= min (end
, row
->used
[area
]);
4921 start
= max (0, start
);
4922 start
= min (end
, start
);
4924 *real_start
= start
;
4928 /* Translate X to frame coordinates. Set last_x to the right
4929 end of the drawing area. */
4930 if (row
->full_width_p
)
4932 /* X is relative to the left edge of W, without scroll bars
4934 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4935 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4936 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4939 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4940 last_x
= window_left_x
+ area_width
;
4942 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4944 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4945 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4951 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4952 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4956 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4957 area_width
= window_box_width (w
, area
);
4958 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4961 /* Build a doubly-linked list of glyph_string structures between
4962 head and tail from what we have to draw. Note that the macro
4963 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4964 the reason we use a separate variable `i'. */
4966 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4969 x_reached
= tail
->x
+ tail
->background_width
;
4973 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4974 the row, redraw some glyphs in front or following the glyph
4975 strings built above. */
4976 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4979 struct glyph_string
*h
, *t
;
4981 /* Compute overhangs for all glyph strings. */
4982 for (s
= head
; s
; s
= s
->next
)
4983 x_compute_glyph_string_overhangs (s
);
4985 /* Prepend glyph strings for glyphs in front of the first glyph
4986 string that are overwritten because of the first glyph
4987 string's left overhang. The background of all strings
4988 prepended must be drawn because the first glyph string
4990 i
= x_left_overwritten (head
);
4994 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, j
, start
, h
, t
,
4995 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4999 *real_start
= start
;
5000 x_compute_overhangs_and_x (t
, head
->x
, 1);
5001 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5004 /* Prepend glyph strings for glyphs in front of the first glyph
5005 string that overwrite that glyph string because of their
5006 right overhang. For these strings, only the foreground must
5007 be drawn, because it draws over the glyph string at `head'.
5008 The background must not be drawn because this would overwrite
5009 right overhangs of preceding glyphs for which no glyph
5011 i
= x_left_overwriting (head
);
5014 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, i
, start
, h
, t
,
5015 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5017 for (s
= h
; s
; s
= s
->next
)
5018 s
->background_filled_p
= 1;
5021 x_compute_overhangs_and_x (t
, head
->x
, 1);
5022 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5025 /* Append glyphs strings for glyphs following the last glyph
5026 string tail that are overwritten by tail. The background of
5027 these strings has to be drawn because tail's foreground draws
5029 i
= x_right_overwritten (tail
);
5032 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5033 DRAW_NORMAL_TEXT
, x
, last_x
,
5035 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5036 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5041 /* Append glyph strings for glyphs following the last glyph
5042 string tail that overwrite tail. The foreground of such
5043 glyphs has to be drawn because it writes into the background
5044 of tail. The background must not be drawn because it could
5045 paint over the foreground of following glyphs. */
5046 i
= x_right_overwriting (tail
);
5049 BUILD_GLYPH_STRINGS (hdc
, w
, row
, area
, end
, i
, h
, t
,
5050 DRAW_NORMAL_TEXT
, x
, last_x
,
5052 for (s
= h
; s
; s
= s
->next
)
5053 s
->background_filled_p
= 1;
5054 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5055 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5061 /* Draw all strings. */
5062 for (s
= head
; s
; s
= s
->next
)
5063 x_draw_glyph_string (s
);
5065 /* Value is the x-position up to which drawn, relative to AREA of W.
5066 This doesn't include parts drawn because of overhangs. */
5067 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5068 if (!row
->full_width_p
)
5070 if (area
> LEFT_MARGIN_AREA
)
5071 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5072 if (area
> TEXT_AREA
)
5073 x_reached
-= window_box_width (w
, TEXT_AREA
);
5076 release_frame_dc (XFRAME (WINDOW_FRAME (w
)), hdc
);
5082 /* Fix the display of area AREA of overlapping row ROW in window W. */
5085 x_fix_overlapping_area (w
, row
, area
)
5087 struct glyph_row
*row
;
5088 enum glyph_row_area area
;
5094 if (area
== LEFT_MARGIN_AREA
)
5096 else if (area
== TEXT_AREA
)
5097 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5099 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5100 + window_box_width (w
, TEXT_AREA
));
5102 for (i
= 0; i
< row
->used
[area
];)
5104 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5106 int start
= i
, start_x
= x
;
5110 x
+= row
->glyphs
[area
][i
].pixel_width
;
5113 while (i
< row
->used
[area
]
5114 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5116 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5118 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5123 x
+= row
->glyphs
[area
][i
].pixel_width
;
5132 /* Output LEN glyphs starting at START at the nominal cursor position.
5133 Advance the nominal cursor over the text. The global variable
5134 updated_window contains the window being updated, updated_row is
5135 the glyph row being updated, and updated_area is the area of that
5136 row being updated. */
5139 x_write_glyphs (start
, len
)
5140 struct glyph
*start
;
5143 int x
, hpos
, real_start
, real_end
;
5145 xassert (updated_window
&& updated_row
);
5150 hpos
= start
- updated_row
->glyphs
[updated_area
];
5151 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5152 updated_row
, updated_area
,
5154 (updated_row
->inverse_p
5155 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5156 &real_start
, &real_end
, 0);
5158 /* If we drew over the cursor, note that it is not visible any more. */
5159 note_overwritten_text_cursor (updated_window
, real_start
,
5160 real_end
- real_start
);
5164 /* Advance the output cursor. */
5165 output_cursor
.hpos
+= len
;
5166 output_cursor
.x
= x
;
5170 /* Insert LEN glyphs from START at the nominal cursor position. */
5173 x_insert_glyphs (start
, len
)
5174 struct glyph
*start
;
5179 int line_height
, shift_by_width
, shifted_region_width
;
5180 struct glyph_row
*row
;
5181 struct glyph
*glyph
;
5182 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5185 xassert (updated_window
&& updated_row
);
5188 f
= XFRAME (WINDOW_FRAME (w
));
5189 hdc
= get_frame_dc (f
);
5191 /* Get the height of the line we are in. */
5193 line_height
= row
->height
;
5195 /* Get the width of the glyphs to insert. */
5197 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5198 shift_by_width
+= glyph
->pixel_width
;
5200 /* Get the width of the region to shift right. */
5201 shifted_region_width
= (window_box_width (w
, updated_area
)
5206 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5207 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5208 BitBlt (hdc
, frame_x
+ shift_by_width
, frame_y
,
5209 shifted_region_width
, line_height
,
5210 hdc
, frame_x
, frame_y
, SRCCOPY
);
5212 /* Write the glyphs. */
5213 hpos
= start
- row
->glyphs
[updated_area
];
5214 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5215 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5216 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5218 /* Advance the output cursor. */
5219 output_cursor
.hpos
+= len
;
5220 output_cursor
.x
+= shift_by_width
;
5221 release_frame_dc (f
, hdc
);
5227 /* Delete N glyphs at the nominal cursor position. Not implemented
5239 f
= SELECTED_FRAME ();
5241 if (! FRAME_W32_P (f
))
5248 /* Erase the current text line from the nominal cursor position
5249 (inclusive) to pixel column TO_X (exclusive). The idea is that
5250 everything from TO_X onward is already erased.
5252 TO_X is a pixel position relative to updated_area of
5253 updated_window. TO_X == -1 means clear to the end of this area. */
5256 x_clear_end_of_line (to_x
)
5260 struct window
*w
= updated_window
;
5261 int max_x
, min_y
, max_y
;
5262 int from_x
, from_y
, to_y
;
5264 xassert (updated_window
&& updated_row
);
5265 f
= XFRAME (w
->frame
);
5267 if (updated_row
->full_width_p
)
5269 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5270 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5271 && !w
->pseudo_window_p
)
5272 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5275 max_x
= window_box_width (w
, updated_area
);
5276 max_y
= window_text_bottom_y (w
);
5278 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5279 of window. For TO_X > 0, truncate to end of drawing area. */
5285 to_x
= min (to_x
, max_x
);
5287 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5289 /* Notice if the cursor will be cleared by this operation. */
5290 if (!updated_row
->full_width_p
)
5291 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5293 from_x
= output_cursor
.x
;
5295 /* Translate to frame coordinates. */
5296 if (updated_row
->full_width_p
)
5298 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5299 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5303 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5304 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5307 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5308 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5309 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5311 /* Prevent inadvertently clearing to end of the X window. */
5312 if (to_x
> from_x
&& to_y
> from_y
)
5316 hdc
= get_frame_dc (f
);
5318 w32_clear_area (f
, hdc
, from_x
, from_y
, to_x
- from_x
, to_y
- from_y
);
5319 release_frame_dc (f
, hdc
);
5325 /* Clear entire frame. If updating_frame is non-null, clear that
5326 frame. Otherwise clear the selected frame. */
5336 f
= SELECTED_FRAME ();
5338 if (! FRAME_W32_P (f
))
5341 /* Clearing the frame will erase any cursor, so mark them all as no
5343 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5344 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5345 output_cursor
.x
= -1;
5347 /* We don't set the output cursor here because there will always
5348 follow an explicit cursor_to. */
5351 w32_clear_window (f
);
5353 /* We have to clear the scroll bars, too. If we have changed
5354 colors or something like that, then they should be notified. */
5355 x_scroll_bar_clear (f
);
5361 /* Make audible bell. */
5364 w32_ring_bell (void)
5368 f
= SELECTED_FRAME ();
5372 if (FRAME_W32_P (f
) && visible_bell
)
5375 HWND hwnd
= FRAME_W32_WINDOW (SELECTED_FRAME ());
5377 for (i
= 0; i
< 5; i
++)
5379 FlashWindow (hwnd
, TRUE
);
5382 FlashWindow (hwnd
, FALSE
);
5385 w32_sys_ring_bell ();
5391 /* Specify how many text lines, from the top of the window,
5392 should be affected by insert-lines and delete-lines operations.
5393 This, and those operations, are used only within an update
5394 that is bounded by calls to x_update_begin and x_update_end. */
5397 w32_set_terminal_window (n
)
5400 /* This function intentionally left blank. */
5405 /***********************************************************************
5407 ***********************************************************************/
5409 /* Perform an insert-lines or delete-lines operation, inserting N
5410 lines or deleting -N lines at vertical position VPOS. */
5413 x_ins_del_lines (vpos
, n
)
5421 f
= SELECTED_FRAME ();
5423 if (! FRAME_W32_P (f
))
5430 /* Scroll part of the display as described by RUN. */
5433 x_scroll_run (w
, run
)
5437 struct frame
*f
= XFRAME (w
->frame
);
5438 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5439 HDC hdc
= get_frame_dc (f
);
5441 /* Get frame-relative bounding box of the text display area of W,
5442 without mode lines. Include in this box the flags areas to the
5443 left and right of W. */
5444 window_box (w
, -1, &x
, &y
, &width
, &height
);
5445 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5446 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5448 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5449 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5450 bottom_y
= y
+ height
;
5454 /* Scrolling up. Make sure we don't copy part of the mode
5455 line at the bottom. */
5456 if (from_y
+ run
->height
> bottom_y
)
5457 height
= bottom_y
- from_y
;
5459 height
= run
->height
;
5463 /* Scolling down. Make sure we don't copy over the mode line.
5465 if (to_y
+ run
->height
> bottom_y
)
5466 height
= bottom_y
- to_y
;
5468 height
= run
->height
;
5473 /* Cursor off. Will be switched on again in x_update_window_end. */
5477 BitBlt (hdc
, x
, to_y
, width
, height
, hdc
, x
, from_y
, SRCCOPY
);
5480 release_frame_dc (f
, hdc
);
5485 /***********************************************************************
5487 ***********************************************************************/
5489 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5490 corner of the exposed rectangle. W and H are width and height of
5491 the exposed area. All are pixel values. W or H zero means redraw
5492 the entire frame. */
5495 expose_frame (f
, x
, y
, w
, h
)
5501 TRACE ((stderr
, "expose_frame "));
5503 /* No need to redraw if frame will be redrawn soon. */
5504 if (FRAME_GARBAGED_P (f
))
5506 TRACE ((stderr
, " garbaged\n"));
5510 /* If basic faces haven't been realized yet, there is no point in
5511 trying to redraw anything. This can happen when we get an expose
5512 event while Emacs is starting, e.g. by moving another window. */
5513 if (FRAME_FACE_CACHE (f
) == NULL
5514 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5516 TRACE ((stderr
, " no faces\n"));
5520 if (w
== 0 || h
== 0)
5523 r
.right
= CANON_X_UNIT (f
) * f
->width
;
5524 r
.bottom
= CANON_Y_UNIT (f
) * f
->height
;
5534 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.left
, r
.top
, r
.right
, r
.bottom
));
5535 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5537 if (WINDOWP (f
->tool_bar_window
))
5539 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5541 RECT intersection_rect
;
5542 int window_x
, window_y
, window_width
, window_height
;
5544 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5545 window_rect
.left
= window_x
;
5546 window_rect
.top
= window_y
;
5547 window_rect
.right
= window_x
+ window_width
;
5548 window_rect
.bottom
= window_y
+ window_height
;
5550 if (IntersectRect (&intersection_rect
, &r
, &window_rect
))
5551 expose_window (w
, &intersection_rect
);
5556 /* Redraw (parts) of all windows in the window tree rooted at W that
5557 intersect R. R contains frame pixel coordinates. */
5560 expose_window_tree (w
, r
)
5566 if (!NILP (w
->hchild
))
5567 expose_window_tree (XWINDOW (w
->hchild
), r
);
5568 else if (!NILP (w
->vchild
))
5569 expose_window_tree (XWINDOW (w
->vchild
), r
);
5573 RECT intersection_rect
;
5574 struct frame
*f
= XFRAME (w
->frame
);
5575 int window_x
, window_y
, window_width
, window_height
;
5577 /* Frame-relative pixel rectangle of W. */
5578 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5582 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5583 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_Y_UNIT (f
));
5584 window_rect
.top
= window_y
;
5585 window_rect
.right
= window_rect
.left
5587 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5588 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5589 window_rect
.bottom
= window_rect
.top
5590 + window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5592 if (IntersectRect (&intersection_rect
, r
, &window_rect
))
5593 expose_window (w
, &intersection_rect
);
5596 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5601 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5602 which intersects rectangle R. R is in window-relative coordinates. */
5605 expose_area (w
, row
, r
, area
)
5607 struct glyph_row
*row
;
5609 enum glyph_row_area area
;
5611 struct glyph
*first
= row
->glyphs
[area
];
5612 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5614 int first_x
, start_x
, x
;
5616 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5617 /* If row extends face to end of line write the whole line. */
5618 x_draw_glyphs (w
, 0, row
, area
,
5620 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5624 /* Set START_X to the window-relative start position for drawing glyphs of
5625 AREA. The first glyph of the text area can be partially visible.
5626 The first glyphs of other areas cannot. */
5627 if (area
== LEFT_MARGIN_AREA
)
5629 else if (area
== TEXT_AREA
)
5630 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5632 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5633 + window_box_width (w
, TEXT_AREA
));
5636 /* Find the first glyph that must be redrawn. */
5638 && x
+ first
->pixel_width
< r
->left
)
5640 x
+= first
->pixel_width
;
5644 /* Find the last one. */
5650 x
+= last
->pixel_width
;
5656 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5657 first
- row
->glyphs
[area
],
5658 last
- row
->glyphs
[area
],
5659 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5665 /* Redraw the parts of the glyph row ROW on window W intersecting
5666 rectangle R. R is in window-relative coordinates. */
5669 expose_line (w
, row
, r
)
5671 struct glyph_row
*row
;
5674 xassert (row
->enabled_p
);
5676 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5677 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5678 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5682 if (row
->used
[LEFT_MARGIN_AREA
])
5683 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5684 if (row
->used
[TEXT_AREA
])
5685 expose_area (w
, row
, r
, TEXT_AREA
);
5686 if (row
->used
[RIGHT_MARGIN_AREA
])
5687 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5688 x_draw_row_bitmaps (w
, row
);
5693 /* Return non-zero if W's cursor intersects rectangle R. */
5696 x_phys_cursor_in_rect_p (w
, r
)
5701 struct glyph
*cursor_glyph
;
5703 cursor_glyph
= get_phys_cursor_glyph (w
);
5706 cr
.left
= w
->phys_cursor
.x
;
5707 cr
.top
= w
->phys_cursor
.y
;
5708 cr
.right
= cr
.left
+ cursor_glyph
->pixel_width
;
5709 cr
.bottom
= cr
.top
+ w
->phys_cursor_height
;
5710 return IntersectRect (&result
, &cr
, r
);
5717 /* Redraw a rectangle of window W. R is a rectangle in window
5718 relative coordinates. Call this function with input blocked. */
5721 expose_window (w
, r
)
5725 struct glyph_row
*row
;
5727 int yb
= window_text_bottom_y (w
);
5728 int cursor_cleared_p
;
5730 /* If window is not yet fully initialized, do nothing. This can
5731 happen when toolkit scroll bars are used and a window is split.
5732 Reconfiguring the scroll bar will generate an expose for a newly
5734 if (w
->current_matrix
== NULL
|| w
== updated_window
)
5737 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5738 r
->left
, r
->top
, r
->right
, r
->bottom
));
5740 /* Convert to window coordinates. */
5741 r
->left
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->left
);
5742 r
->top
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->top
);
5743 r
->right
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->right
);
5744 r
->bottom
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->bottom
);
5746 /* Turn off the cursor. */
5747 if (!w
->pseudo_window_p
5748 && x_phys_cursor_in_rect_p (w
, r
))
5751 cursor_cleared_p
= 1;
5754 cursor_cleared_p
= 0;
5756 /* Find the first row intersecting the rectangle R. */
5757 row
= w
->current_matrix
->rows
;
5759 while (row
->enabled_p
5761 && y
+ row
->height
< r
->top
)
5767 /* Display the text in the rectangle, one text line at a time. */
5768 while (row
->enabled_p
5772 expose_line (w
, row
, r
);
5777 /* Display the mode line if there is one. */
5778 if (WINDOW_WANTS_MODELINE_P (w
)
5779 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5781 && row
->y
< r
->bottom
)
5782 expose_line (w
, row
, r
);
5784 if (!w
->pseudo_window_p
)
5786 /* Draw border between windows. */
5787 x_draw_vertical_border (w
);
5789 /* Turn the cursor on again. */
5790 if (cursor_cleared_p
)
5791 x_update_window_cursor (w
, 1);
5800 x_update_cursor (f
, 1);
5804 frame_unhighlight (f
)
5807 x_update_cursor (f
, 1);
5810 /* The focus has changed. Update the frames as necessary to reflect
5811 the new situation. Note that we can't change the selected frame
5812 here, because the Lisp code we are interrupting might become confused.
5813 Each event gets marked with the frame in which it occurred, so the
5814 Lisp code can tell when the switch took place by examining the events. */
5817 x_new_focus_frame (dpyinfo
, frame
)
5818 struct w32_display_info
*dpyinfo
;
5819 struct frame
*frame
;
5821 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
5823 if (frame
!= dpyinfo
->w32_focus_frame
)
5825 /* Set this before calling other routines, so that they see
5826 the correct value of w32_focus_frame. */
5827 dpyinfo
->w32_focus_frame
= frame
;
5829 if (old_focus
&& old_focus
->auto_lower
)
5830 x_lower_frame (old_focus
);
5832 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
5833 pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
5835 pending_autoraise_frame
= 0;
5838 x_frame_rehighlight (dpyinfo
);
5841 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5844 x_mouse_leave (dpyinfo
)
5845 struct w32_display_info
*dpyinfo
;
5847 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
5850 /* The focus has changed, or we have redirected a frame's focus to
5851 another frame (this happens when a frame uses a surrogate
5852 mini-buffer frame). Shift the highlight as appropriate.
5854 The FRAME argument doesn't necessarily have anything to do with which
5855 frame is being highlighted or un-highlighted; we only use it to find
5856 the appropriate X display info. */
5859 w32_frame_rehighlight (frame
)
5860 struct frame
*frame
;
5862 if (! FRAME_W32_P (frame
))
5864 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame
));
5868 x_frame_rehighlight (dpyinfo
)
5869 struct w32_display_info
*dpyinfo
;
5871 struct frame
*old_highlight
= dpyinfo
->w32_highlight_frame
;
5873 if (dpyinfo
->w32_focus_frame
)
5875 dpyinfo
->w32_highlight_frame
5876 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
5877 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
5878 : dpyinfo
->w32_focus_frame
);
5879 if (! FRAME_LIVE_P (dpyinfo
->w32_highlight_frame
))
5881 FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
) = Qnil
;
5882 dpyinfo
->w32_highlight_frame
= dpyinfo
->w32_focus_frame
;
5886 dpyinfo
->w32_highlight_frame
= 0;
5888 if (dpyinfo
->w32_highlight_frame
!= old_highlight
)
5891 frame_unhighlight (old_highlight
);
5892 if (dpyinfo
->w32_highlight_frame
)
5893 frame_highlight (dpyinfo
->w32_highlight_frame
);
5897 /* Keyboard processing - modifier keys, etc. */
5899 /* Convert a keysym to its name. */
5902 x_get_keysym_name (keysym
)
5905 /* Make static so we can always return it */
5906 static char value
[100];
5909 GetKeyNameText (keysym
, value
, 100);
5917 /* Mouse clicks and mouse movement. Rah. */
5919 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5920 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5921 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5922 not force the value into range. */
5925 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5927 register int pix_x
, pix_y
;
5928 register int *x
, *y
;
5932 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
5933 if (NILP (Vwindow_system
))
5940 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5941 even for negative values. */
5943 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
5945 pix_y
-= (f
)->output_data
.w32
->line_height
- 1;
5947 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5948 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5952 bounds
->left
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5953 bounds
->top
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5954 bounds
->right
= bounds
->left
+ FONT_WIDTH (FRAME_FONT (f
)) - 1;
5955 bounds
->bottom
= bounds
->top
+ f
->output_data
.w32
->line_height
- 1;
5962 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5963 pix_x
= FRAME_WINDOW_WIDTH (f
);
5967 else if (pix_y
> f
->height
)
5976 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5977 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5978 can't tell the positions because W's display is not up to date,
5982 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
5985 int *frame_x
, *frame_y
;
5989 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
5990 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
5992 if (display_completed
)
5994 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5995 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
5996 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6002 *frame_x
+= glyph
->pixel_width
;
6010 *frame_y
= *frame_x
= 0;
6014 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6015 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6020 parse_button (message
, pbutton
, pup
)
6030 case WM_LBUTTONDOWN
:
6038 case WM_MBUTTONDOWN
:
6039 if (NILP (Vw32_swap_mouse_buttons
))
6046 if (NILP (Vw32_swap_mouse_buttons
))
6052 case WM_RBUTTONDOWN
:
6053 if (NILP (Vw32_swap_mouse_buttons
))
6060 if (NILP (Vw32_swap_mouse_buttons
))
6071 if (pbutton
) *pbutton
= button
;
6077 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6079 If the event is a button press, then note that we have grabbed
6083 construct_mouse_click (result
, msg
, f
)
6084 struct input_event
*result
;
6091 parse_button (msg
->msg
.message
, &button
, &up
);
6093 /* Make the event type no_event; we'll change that when we decide
6095 result
->kind
= mouse_click
;
6096 result
->code
= button
;
6097 result
->timestamp
= msg
->msg
.time
;
6098 result
->modifiers
= (msg
->dwModifiers
6103 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
6104 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
6105 XSETFRAME (result
->frame_or_window
, f
);
6111 construct_mouse_wheel (result
, msg
, f
)
6112 struct input_event
*result
;
6117 result
->kind
= mouse_wheel
;
6118 result
->code
= (short) HIWORD (msg
->msg
.wParam
);
6119 result
->timestamp
= msg
->msg
.time
;
6120 result
->modifiers
= msg
->dwModifiers
;
6121 p
.x
= LOWORD (msg
->msg
.lParam
);
6122 p
.y
= HIWORD (msg
->msg
.lParam
);
6123 ScreenToClient (msg
->msg
.hwnd
, &p
);
6124 XSETINT (result
->x
, p
.x
);
6125 XSETINT (result
->y
, p
.y
);
6126 XSETFRAME (result
->frame_or_window
, f
);
6132 construct_drag_n_drop (result
, msg
, f
)
6133 struct input_event
*result
;
6145 result
->kind
= drag_n_drop
;
6147 result
->timestamp
= msg
->msg
.time
;
6148 result
->modifiers
= msg
->dwModifiers
;
6150 hdrop
= (HDROP
) msg
->msg
.wParam
;
6151 DragQueryPoint (hdrop
, &p
);
6154 p
.x
= LOWORD (msg
->msg
.lParam
);
6155 p
.y
= HIWORD (msg
->msg
.lParam
);
6156 ScreenToClient (msg
->msg
.hwnd
, &p
);
6159 XSETINT (result
->x
, p
.x
);
6160 XSETINT (result
->y
, p
.y
);
6162 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
6165 for (i
= 0; i
< num_files
; i
++)
6167 len
= DragQueryFile (hdrop
, i
, NULL
, 0);
6170 name
= alloca (len
+ 1);
6171 DragQueryFile (hdrop
, i
, name
, len
+ 1);
6172 files
= Fcons (build_string (name
), files
);
6177 XSETFRAME (frame
, f
);
6178 result
->frame_or_window
= Fcons (frame
, files
);
6184 /* Function to report a mouse movement to the mainstream Emacs code.
6185 The input handler calls this.
6187 We have received a mouse movement event, which is given in *event.
6188 If the mouse is over a different glyph than it was last time, tell
6189 the mainstream emacs code by setting mouse_moved. If not, ask for
6190 another motion event, so we can check again the next time it moves. */
6192 static MSG last_mouse_motion_event
;
6193 static Lisp_Object last_mouse_motion_frame
;
6196 note_mouse_movement (frame
, msg
)
6200 last_mouse_movement_time
= msg
->time
;
6201 memcpy (&last_mouse_motion_event
, msg
, sizeof (last_mouse_motion_event
));
6202 XSETFRAME (last_mouse_motion_frame
, frame
);
6204 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
6206 frame
->mouse_moved
= 1;
6207 last_mouse_scroll_bar
= Qnil
;
6208 note_mouse_highlight (frame
, -1, -1);
6211 /* Has the mouse moved off the glyph it was on at the last sighting? */
6212 else if (LOWORD (msg
->lParam
) < last_mouse_glyph
.left
6213 || LOWORD (msg
->lParam
) > last_mouse_glyph
.right
6214 || HIWORD (msg
->lParam
) < last_mouse_glyph
.top
6215 || HIWORD (msg
->lParam
) > last_mouse_glyph
.bottom
)
6217 frame
->mouse_moved
= 1;
6218 last_mouse_scroll_bar
= Qnil
;
6219 note_mouse_highlight (frame
, LOWORD (msg
->lParam
), HIWORD (msg
->lParam
));
6223 /* This is used for debugging, to turn off note_mouse_highlight. */
6225 int disable_mouse_highlight
;
6229 /************************************************************************
6231 ************************************************************************/
6233 /* Find the glyph under window-relative coordinates X/Y in window W.
6234 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6235 strings. Return in *HPOS and *VPOS the row and column number of
6236 the glyph found. Return in *AREA the glyph area containing X.
6237 Value is a pointer to the glyph found or null if X/Y is not on
6238 text, or we can't tell because W's current matrix is not up to
6241 static struct glyph
*
6242 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6245 int *hpos
, *vpos
, *area
;
6247 struct glyph
*glyph
, *end
;
6248 struct glyph_row
*row
= NULL
;
6249 int x0
, i
, left_area_width
;
6251 /* Find row containing Y. Give up if some row is not enabled. */
6252 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6254 row
= MATRIX_ROW (w
->current_matrix
, i
);
6255 if (!row
->enabled_p
)
6257 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6264 /* Give up if Y is not in the window. */
6265 if (i
== w
->current_matrix
->nrows
)
6268 /* Get the glyph area containing X. */
6269 if (w
->pseudo_window_p
)
6276 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6277 if (x
< left_area_width
)
6279 *area
= LEFT_MARGIN_AREA
;
6282 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6285 x0
= row
->x
+ left_area_width
;
6289 *area
= RIGHT_MARGIN_AREA
;
6290 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6294 /* Find glyph containing X. */
6295 glyph
= row
->glyphs
[*area
];
6296 end
= glyph
+ row
->used
[*area
];
6299 if (x
< x0
+ glyph
->pixel_width
)
6301 if (w
->pseudo_window_p
)
6303 else if (BUFFERP (glyph
->object
))
6307 x0
+= glyph
->pixel_width
;
6314 *hpos
= glyph
- row
->glyphs
[*area
];
6319 /* Convert frame-relative x/y to coordinates relative to window W.
6320 Takes pseudo-windows into account. */
6323 frame_to_window_pixel_xy (w
, x
, y
)
6327 if (w
->pseudo_window_p
)
6329 /* A pseudo-window is always full-width, and starts at the
6330 left edge of the frame, plus a frame border. */
6331 struct frame
*f
= XFRAME (w
->frame
);
6332 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6333 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6337 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6338 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6343 /* Take proper action when mouse has moved to the mode or header line of
6344 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6345 mode line. X is relative to the start of the text display area of
6346 W, so the width of bitmap areas and scroll bars must be subtracted
6347 to get a position relative to the start of the mode line. */
6350 note_mode_line_highlight (w
, x
, mode_line_p
)
6354 struct frame
*f
= XFRAME (w
->frame
);
6355 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6356 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6357 struct glyph_row
*row
;
6360 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6362 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6366 struct glyph
*glyph
, *end
;
6367 Lisp_Object help
, map
;
6370 /* Find the glyph under X. */
6371 glyph
= row
->glyphs
[TEXT_AREA
];
6372 end
= glyph
+ row
->used
[TEXT_AREA
];
6373 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6374 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6377 && x
>= x0
+ glyph
->pixel_width
)
6379 x0
+= glyph
->pixel_width
;
6384 && STRINGP (glyph
->object
)
6385 && XSTRING (glyph
->object
)->intervals
6386 && glyph
->charpos
>= 0
6387 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6389 /* If we're on a string with `help-echo' text property,
6390 arrange for the help to be displayed. This is done by
6391 setting the global variable help_echo to the help string. */
6392 help
= Fget_text_property (make_number (glyph
->charpos
),
6393 Qhelp_echo
, glyph
->object
);
6397 XSETWINDOW (help_echo_window
, w
);
6398 help_echo_object
= glyph
->object
;
6399 help_echo_pos
= glyph
->charpos
;
6402 /* Change the mouse pointer according to what is under X/Y. */
6403 map
= Fget_text_property (make_number (glyph
->charpos
),
6404 Qlocal_map
, glyph
->object
);
6406 cursor
= f
->output_data
.w32
->nontext_cursor
;
6409 map
= Fget_text_property (make_number (glyph
->charpos
),
6410 Qkeymap
, glyph
->object
);
6412 cursor
= f
->output_data
.w32
->nontext_cursor
;
6417 #if 0 /* TODO: mouse cursor */
6418 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6423 /* Take proper action when the mouse has moved to position X, Y on
6424 frame F as regards highlighting characters that have mouse-face
6425 properties. Also de-highlighting chars where the mouse was before.
6426 X and Y can be negative or out of range. */
6429 note_mouse_highlight (f
, x
, y
)
6433 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6438 /* When a menu is active, don't highlight because this looks odd. */
6439 if (popup_activated ())
6442 if (disable_mouse_highlight
6443 || !f
->glyphs_initialized_p
)
6446 dpyinfo
->mouse_face_mouse_x
= x
;
6447 dpyinfo
->mouse_face_mouse_y
= y
;
6448 dpyinfo
->mouse_face_mouse_frame
= f
;
6450 if (dpyinfo
->mouse_face_defer
)
6455 dpyinfo
->mouse_face_deferred_gc
= 1;
6459 /* Which window is that in? */
6460 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6462 /* If we were displaying active text in another window, clear that. */
6463 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6464 clear_mouse_face (dpyinfo
);
6466 /* Not on a window -> return. */
6467 if (!WINDOWP (window
))
6470 /* Convert to window-relative pixel coordinates. */
6471 w
= XWINDOW (window
);
6472 frame_to_window_pixel_xy (w
, &x
, &y
);
6474 /* Handle tool-bar window differently since it doesn't display a
6476 if (EQ (window
, f
->tool_bar_window
))
6478 note_tool_bar_highlight (f
, x
, y
);
6482 if (portion
== 1 || portion
== 3)
6484 /* Mouse is on the mode or top line. */
6485 note_mode_line_highlight (w
, x
, portion
== 1);
6488 #if 0 /* TODO: mouse cursor */
6489 else if (portion
== 2)
6490 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6491 f
->output_data
.x
->horizontal_drag_cursor
);
6493 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6494 f
->output_data
.x
->text_cursor
);
6497 /* Are we in a window whose display is up to date?
6498 And verify the buffer's text has not changed. */
6499 if (/* Within text portion of the window. */
6501 && EQ (w
->window_end_valid
, w
->buffer
)
6502 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6503 && (XFASTINT (w
->last_overlay_modified
)
6504 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6506 int hpos
, vpos
, pos
, i
, area
;
6507 struct glyph
*glyph
;
6509 /* Find the glyph under X/Y. */
6510 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6512 /* Clear mouse face if X/Y not over text. */
6514 || area
!= TEXT_AREA
6515 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6517 clear_mouse_face (dpyinfo
);
6521 pos
= glyph
->charpos
;
6522 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6524 /* Check for mouse-face and help-echo. */
6526 Lisp_Object mouse_face
, overlay
, position
;
6527 Lisp_Object
*overlay_vec
;
6529 struct buffer
*obuf
;
6532 /* If we get an out-of-range value, return now; avoid an error. */
6533 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6536 /* Make the window's buffer temporarily current for
6537 overlays_at and compute_char_face. */
6538 obuf
= current_buffer
;
6539 current_buffer
= XBUFFER (w
->buffer
);
6545 /* Is this char mouse-active or does it have help-echo? */
6546 XSETINT (position
, pos
);
6548 /* Put all the overlays we want in a vector in overlay_vec.
6549 Store the length in len. If there are more than 10, make
6550 enough space for all, and try again. */
6552 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6553 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6554 if (noverlays
> len
)
6557 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6558 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6561 /* Sort overlays into increasing priority order. */
6562 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6564 /* Check mouse-face highlighting. */
6565 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6566 && vpos
>= dpyinfo
->mouse_face_beg_row
6567 && vpos
<= dpyinfo
->mouse_face_end_row
6568 && (vpos
> dpyinfo
->mouse_face_beg_row
6569 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6570 && (vpos
< dpyinfo
->mouse_face_end_row
6571 || hpos
< dpyinfo
->mouse_face_end_col
6572 || dpyinfo
->mouse_face_past_end
)))
6574 /* Clear the display of the old active region, if any. */
6575 clear_mouse_face (dpyinfo
);
6577 /* Find the highest priority overlay that has a mouse-face prop. */
6579 for (i
= noverlays
- 1; i
>= 0; --i
)
6581 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6582 if (!NILP (mouse_face
))
6584 overlay
= overlay_vec
[i
];
6589 /* If no overlay applies, get a text property. */
6591 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6593 /* Handle the overlay case. */
6594 if (! NILP (overlay
))
6596 /* Find the range of text around this char that
6597 should be active. */
6598 Lisp_Object before
, after
;
6601 before
= Foverlay_start (overlay
);
6602 after
= Foverlay_end (overlay
);
6603 /* Record this as the current active region. */
6604 fast_find_position (w
, XFASTINT (before
),
6605 &dpyinfo
->mouse_face_beg_col
,
6606 &dpyinfo
->mouse_face_beg_row
,
6607 &dpyinfo
->mouse_face_beg_x
,
6608 &dpyinfo
->mouse_face_beg_y
);
6609 dpyinfo
->mouse_face_past_end
6610 = !fast_find_position (w
, XFASTINT (after
),
6611 &dpyinfo
->mouse_face_end_col
,
6612 &dpyinfo
->mouse_face_end_row
,
6613 &dpyinfo
->mouse_face_end_x
,
6614 &dpyinfo
->mouse_face_end_y
);
6615 dpyinfo
->mouse_face_window
= window
;
6616 dpyinfo
->mouse_face_face_id
6617 = face_at_buffer_position (w
, pos
, 0, 0,
6618 &ignore
, pos
+ 1, 1);
6620 /* Display it as active. */
6621 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6623 /* Handle the text property case. */
6624 else if (! NILP (mouse_face
))
6626 /* Find the range of text around this char that
6627 should be active. */
6628 Lisp_Object before
, after
, beginning
, end
;
6631 beginning
= Fmarker_position (w
->start
);
6632 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6633 - XFASTINT (w
->window_end_pos
)));
6635 = Fprevious_single_property_change (make_number (pos
+ 1),
6637 w
->buffer
, beginning
);
6639 = Fnext_single_property_change (position
, Qmouse_face
,
6641 /* Record this as the current active region. */
6642 fast_find_position (w
, XFASTINT (before
),
6643 &dpyinfo
->mouse_face_beg_col
,
6644 &dpyinfo
->mouse_face_beg_row
,
6645 &dpyinfo
->mouse_face_beg_x
,
6646 &dpyinfo
->mouse_face_beg_y
);
6647 dpyinfo
->mouse_face_past_end
6648 = !fast_find_position (w
, XFASTINT (after
),
6649 &dpyinfo
->mouse_face_end_col
,
6650 &dpyinfo
->mouse_face_end_row
,
6651 &dpyinfo
->mouse_face_end_x
,
6652 &dpyinfo
->mouse_face_end_y
);
6653 dpyinfo
->mouse_face_window
= window
;
6654 dpyinfo
->mouse_face_face_id
6655 = face_at_buffer_position (w
, pos
, 0, 0,
6656 &ignore
, pos
+ 1, 1);
6658 /* Display it as active. */
6659 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6663 /* Look for a `help-echo' property. */
6665 Lisp_Object help
, overlay
;
6667 /* Check overlays first. */
6668 help
= overlay
= Qnil
;
6669 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6671 overlay
= overlay_vec
[i
];
6672 help
= Foverlay_get (overlay
, Qhelp_echo
);
6678 help_echo_window
= window
;
6679 help_echo_object
= overlay
;
6680 help_echo_pos
= pos
;
6684 /* Try text properties. */
6685 if ((STRINGP (glyph
->object
)
6686 && glyph
->charpos
>= 0
6687 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6688 || (BUFFERP (glyph
->object
)
6689 && glyph
->charpos
>= BEGV
6690 && glyph
->charpos
< ZV
))
6691 help
= Fget_text_property (make_number (glyph
->charpos
),
6692 Qhelp_echo
, glyph
->object
);
6697 help_echo_window
= window
;
6698 help_echo_object
= glyph
->object
;
6699 help_echo_pos
= glyph
->charpos
;
6706 current_buffer
= obuf
;
6712 redo_mouse_highlight ()
6714 if (!NILP (last_mouse_motion_frame
)
6715 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6716 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6717 LOWORD (last_mouse_motion_event
.lParam
),
6718 HIWORD (last_mouse_motion_event
.lParam
));
6723 /***********************************************************************
6725 ***********************************************************************/
6727 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6728 struct glyph
**, int *, int *, int *));
6730 /* Tool-bar item index of the item on which a mouse button was pressed
6733 static int last_tool_bar_item
;
6736 /* Get information about the tool-bar item at position X/Y on frame F.
6737 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6738 the current matrix of the tool-bar window of F, or NULL if not
6739 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6740 item in F->tool_bar_items. Value is
6742 -1 if X/Y is not on a tool-bar item
6743 0 if X/Y is on the same item that was highlighted before.
6747 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6750 struct glyph
**glyph
;
6751 int *hpos
, *vpos
, *prop_idx
;
6753 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6754 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6757 /* Find the glyph under X/Y. */
6758 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6762 /* Get the start of this tool-bar item's properties in
6763 f->tool_bar_items. */
6764 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6767 /* Is mouse on the highlighted item? */
6768 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6769 && *vpos
>= dpyinfo
->mouse_face_beg_row
6770 && *vpos
<= dpyinfo
->mouse_face_end_row
6771 && (*vpos
> dpyinfo
->mouse_face_beg_row
6772 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6773 && (*vpos
< dpyinfo
->mouse_face_end_row
6774 || *hpos
< dpyinfo
->mouse_face_end_col
6775 || dpyinfo
->mouse_face_past_end
))
6782 /* Handle mouse button event on the tool-bar of frame F, at
6783 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6787 w32_handle_tool_bar_click (f
, button_event
)
6789 struct input_event
*button_event
;
6791 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6792 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6793 int hpos
, vpos
, prop_idx
;
6794 struct glyph
*glyph
;
6795 Lisp_Object enabled_p
;
6796 int x
= XFASTINT (button_event
->x
);
6797 int y
= XFASTINT (button_event
->y
);
6799 /* If not on the highlighted tool-bar item, return. */
6800 frame_to_window_pixel_xy (w
, &x
, &y
);
6801 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6804 /* If item is disabled, do nothing. */
6805 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6806 if (NILP (enabled_p
))
6809 if (button_event
->kind
== mouse_click
)
6811 /* Show item in pressed state. */
6812 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6813 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6814 last_tool_bar_item
= prop_idx
;
6818 Lisp_Object key
, frame
;
6819 struct input_event event
;
6821 /* Show item in released state. */
6822 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6823 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6825 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
6827 XSETFRAME (frame
, f
);
6828 event
.kind
= TOOL_BAR_EVENT
;
6829 event
.frame_or_window
= frame
;
6831 kbd_buffer_store_event (&event
);
6833 event
.kind
= TOOL_BAR_EVENT
;
6834 event
.frame_or_window
= frame
;
6836 event
.modifiers
= button_event
->modifiers
;
6837 kbd_buffer_store_event (&event
);
6838 last_tool_bar_item
= -1;
6843 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6844 tool-bar window-relative coordinates X/Y. Called from
6845 note_mouse_highlight. */
6848 note_tool_bar_highlight (f
, x
, y
)
6852 Lisp_Object window
= f
->tool_bar_window
;
6853 struct window
*w
= XWINDOW (window
);
6854 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
6856 struct glyph
*glyph
;
6857 struct glyph_row
*row
;
6859 Lisp_Object enabled_p
;
6861 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6862 int mouse_down_p
, rc
;
6864 /* Function note_mouse_highlight is called with negative x(y
6865 values when mouse moves outside of the frame. */
6866 if (x
<= 0 || y
<= 0)
6868 clear_mouse_face (dpyinfo
);
6872 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6875 /* Not on tool-bar item. */
6876 clear_mouse_face (dpyinfo
);
6880 /* On same tool-bar item as before. */
6883 clear_mouse_face (dpyinfo
);
6885 /* Mouse is down, but on different tool-bar item? */
6886 mouse_down_p
= (dpyinfo
->grabbed
6887 && f
== last_mouse_frame
6888 && FRAME_LIVE_P (f
));
6890 && last_tool_bar_item
!= prop_idx
)
6893 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6894 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6896 /* If tool-bar item is not enabled, don't highlight it. */
6897 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6898 if (!NILP (enabled_p
))
6900 /* Compute the x-position of the glyph. In front and past the
6901 image is a space. We include this is the highlighted area. */
6902 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6903 for (i
= x
= 0; i
< hpos
; ++i
)
6904 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6906 /* Record this as the current active region. */
6907 dpyinfo
->mouse_face_beg_col
= hpos
;
6908 dpyinfo
->mouse_face_beg_row
= vpos
;
6909 dpyinfo
->mouse_face_beg_x
= x
;
6910 dpyinfo
->mouse_face_beg_y
= row
->y
;
6911 dpyinfo
->mouse_face_past_end
= 0;
6913 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6914 dpyinfo
->mouse_face_end_row
= vpos
;
6915 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6916 dpyinfo
->mouse_face_end_y
= row
->y
;
6917 dpyinfo
->mouse_face_window
= window
;
6918 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6920 /* Display it as active. */
6921 show_mouse_face (dpyinfo
, draw
);
6922 dpyinfo
->mouse_face_image_state
= draw
;
6927 /* Set help_echo to a help string.to display for this tool-bar item.
6928 w32_read_socket does the rest. */
6929 help_echo_object
= help_echo_window
= Qnil
;
6931 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
6932 if (NILP (help_echo
))
6933 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
6938 /* Find the glyph matrix position of buffer position POS in window W.
6939 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6940 current glyphs must be up to date. If POS is above window start
6941 return (0, 0, 0, 0). If POS is after end of W, return end of
6945 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6948 int *hpos
, *vpos
, *x
, *y
;
6952 int maybe_next_line_p
= 0;
6953 int line_start_position
;
6954 int yb
= window_text_bottom_y (w
);
6955 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6956 struct glyph_row
*best_row
= row
;
6957 int row_vpos
= 0, best_row_vpos
= 0;
6962 if (row
->used
[TEXT_AREA
])
6963 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6965 line_start_position
= 0;
6967 if (line_start_position
> pos
)
6969 /* If the position sought is the end of the buffer,
6970 don't include the blank lines at the bottom of the window. */
6971 else if (line_start_position
== pos
6972 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6974 maybe_next_line_p
= 1;
6977 else if (line_start_position
> 0)
6980 best_row_vpos
= row_vpos
;
6983 if (row
->y
+ row
->height
>= yb
)
6990 /* Find the right column within BEST_ROW. */
6992 current_x
= best_row
->x
;
6993 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6995 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6998 charpos
= glyph
->charpos
;
7002 *vpos
= best_row_vpos
;
7007 else if (charpos
> pos
)
7009 else if (charpos
> 0)
7012 current_x
+= glyph
->pixel_width
;
7015 /* If we're looking for the end of the buffer,
7016 and we didn't find it in the line we scanned,
7017 use the start of the following line. */
7018 if (maybe_next_line_p
)
7023 current_x
= best_row
->x
;
7026 *vpos
= best_row_vpos
;
7027 *hpos
= lastcol
+ 1;
7034 /* Display the active region described by mouse_face_*
7035 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7038 show_mouse_face (dpyinfo
, draw
)
7039 struct w32_display_info
*dpyinfo
;
7040 enum draw_glyphs_face draw
;
7042 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7043 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7045 int cursor_off_p
= 0;
7046 struct cursor_pos saved_cursor
;
7048 saved_cursor
= output_cursor
;
7050 /* If window is in the process of being destroyed, don't bother
7052 if (w
->current_matrix
== NULL
)
7055 /* Recognize when we are called to operate on rows that don't exist
7056 anymore. This can happen when a window is split. */
7057 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7060 set_output_cursor (&w
->phys_cursor
);
7062 /* Note that mouse_face_beg_row etc. are window relative. */
7063 for (i
= dpyinfo
->mouse_face_beg_row
;
7064 i
<= dpyinfo
->mouse_face_end_row
;
7067 int start_hpos
, end_hpos
, start_x
;
7068 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7070 /* Don't do anything if row doesn't have valid contents. */
7071 if (!row
->enabled_p
)
7074 /* For all but the first row, the highlight starts at column 0. */
7075 if (i
== dpyinfo
->mouse_face_beg_row
)
7077 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7078 start_x
= dpyinfo
->mouse_face_beg_x
;
7086 if (i
== dpyinfo
->mouse_face_end_row
)
7087 end_hpos
= dpyinfo
->mouse_face_end_col
;
7089 end_hpos
= row
->used
[TEXT_AREA
];
7091 /* If the cursor's in the text we are about to rewrite, turn the
7093 if (!w
->pseudo_window_p
7094 && i
== output_cursor
.vpos
7095 && output_cursor
.hpos
>= start_hpos
- 1
7096 && output_cursor
.hpos
<= end_hpos
)
7098 x_update_window_cursor (w
, 0);
7102 if (end_hpos
> start_hpos
)
7104 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7105 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7106 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7110 /* If we turned the cursor off, turn it back on. */
7112 x_display_cursor (w
, 1,
7113 output_cursor
.hpos
, output_cursor
.vpos
,
7114 output_cursor
.x
, output_cursor
.y
);
7116 output_cursor
= saved_cursor
;
7119 #if 0 /* TODO: mouse cursor */
7120 /* Change the mouse cursor. */
7121 if (draw
== DRAW_NORMAL_TEXT
)
7122 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7123 f
->output_data
.x
->text_cursor
);
7124 else if (draw
== DRAW_MOUSE_FACE
)
7125 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7126 f
->output_data
.x
->cross_cursor
);
7128 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7129 f
->output_data
.x
->nontext_cursor
);
7134 /* Clear out the mouse-highlighted active region.
7135 Redraw it un-highlighted first. */
7138 clear_mouse_face (dpyinfo
)
7139 struct w32_display_info
*dpyinfo
;
7141 #if 0 /* This prevents redrawing tool bar items when changing from one
7142 to another while a tooltip is open, so don't do it. */
7143 if (!NILP (tip_frame
))
7147 if (! NILP (dpyinfo
->mouse_face_window
))
7148 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7150 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7151 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7152 dpyinfo
->mouse_face_window
= Qnil
;
7156 /* Clear any mouse-face on window W. This function is part of the
7157 redisplay interface, and is called from try_window_id and similar
7158 functions to ensure the mouse-highlight is off. */
7161 x_clear_mouse_face (w
)
7164 struct w32_display_info
*dpyinfo
7165 = FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
7169 XSETWINDOW (window
, w
);
7170 if (EQ (window
, dpyinfo
->mouse_face_window
))
7171 clear_mouse_face (dpyinfo
);
7176 /* Just discard the mouse face information for frame F, if any.
7177 This is used when the size of F is changed. */
7180 cancel_mouse_face (f
)
7184 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
7186 window
= dpyinfo
->mouse_face_window
;
7187 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7189 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7190 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7191 dpyinfo
->mouse_face_window
= Qnil
;
7195 static struct scroll_bar
*x_window_to_scroll_bar ();
7196 static void x_scroll_bar_report_motion ();
7198 /* Return the current position of the mouse.
7199 *fp should be a frame which indicates which display to ask about.
7201 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7202 and *part to the frame, window, and scroll bar part that the mouse
7203 is over. Set *x and *y to the portion and whole of the mouse's
7204 position on the scroll bar.
7206 If the mouse movement started elsewhere, set *fp to the frame the
7207 mouse is on, *bar_window to nil, and *x and *y to the character cell
7210 Set *time to the server time-stamp for the time at which the mouse
7211 was at this position.
7213 Don't store anything if we don't have a valid set of values to report.
7215 This clears the mouse_moved flag, so we can wait for the next mouse
7219 w32_mouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7222 Lisp_Object
*bar_window
;
7223 enum scroll_bar_part
*part
;
7225 unsigned long *time
;
7231 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7232 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7237 Lisp_Object frame
, tail
;
7239 /* Clear the mouse-moved flag for every frame on this display. */
7240 FOR_EACH_FRAME (tail
, frame
)
7241 XFRAME (frame
)->mouse_moved
= 0;
7243 last_mouse_scroll_bar
= Qnil
;
7247 /* Now we have a position on the root; find the innermost window
7248 containing the pointer. */
7250 if (FRAME_W32_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7251 && FRAME_LIVE_P (last_mouse_frame
))
7253 /* If mouse was grabbed on a frame, give coords for that frame
7254 even if the mouse is now outside it. */
7255 f1
= last_mouse_frame
;
7259 /* Is window under mouse one of our frames? */
7260 f1
= x_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp
),
7261 WindowFromPoint (pt
));
7264 /* If not, is it one of our scroll bars? */
7267 struct scroll_bar
*bar
7268 = x_window_to_scroll_bar (WindowFromPoint (pt
));
7272 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7276 if (f1
== 0 && insist
> 0)
7277 f1
= SELECTED_FRAME ();
7281 /* Ok, we found a frame. Store all the values.
7282 last_mouse_glyph is a rectangle used to reduce the
7283 generation of mouse events. To not miss any motion
7284 events, we must divide the frame into rectangles of the
7285 size of the smallest character that could be displayed
7286 on it, i.e. into the same rectangles that matrices on
7287 the frame are divided into. */
7289 #if OLD_REDISPLAY_CODE
7290 int ignore1
, ignore2
;
7292 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7294 pixel_to_glyph_coords (f1
, pt
.x
, pt
.y
, &ignore1
, &ignore2
,
7296 FRAME_W32_DISPLAY_INFO (f1
)->grabbed
7299 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
7301 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7302 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7306 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7307 round down even for negative values. */
7313 last_mouse_glyph
.left
= (x
+ width
- 1) / width
* width
;
7314 last_mouse_glyph
.top
= (y
+ height
- 1) / height
* height
;
7315 last_mouse_glyph
.right
= last_mouse_glyph
.left
+ width
;
7316 last_mouse_glyph
.bottom
= last_mouse_glyph
.top
+ height
;
7325 *time
= last_mouse_movement_time
;
7334 /* Scroll bar support. */
7336 /* Given a window ID, find the struct scroll_bar which manages it.
7337 This can be called in GC, so we have to make sure to strip off mark
7340 static struct scroll_bar
*
7341 x_window_to_scroll_bar (window_id
)
7346 for (tail
= Vframe_list
;
7347 XGCTYPE (tail
) == Lisp_Cons
;
7350 Lisp_Object frame
, bar
, condemned
;
7352 frame
= XCAR (tail
);
7353 /* All elements of Vframe_list should be frames. */
7354 if (! GC_FRAMEP (frame
))
7357 /* Scan this frame's scroll bar list for a scroll bar with the
7359 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7360 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7361 /* This trick allows us to search both the ordinary and
7362 condemned scroll bar lists with one loop. */
7363 ! GC_NILP (bar
) || (bar
= condemned
,
7366 bar
= XSCROLL_BAR (bar
)->next
)
7367 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7368 return XSCROLL_BAR (bar
);
7376 /* Set the thumb size and position of scroll bar BAR. We are currently
7377 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7380 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
)
7381 struct scroll_bar
*bar
;
7382 int portion
, position
, whole
;
7384 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7385 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7386 int sb_page
, sb_pos
;
7387 BOOL draggingp
= !NILP (bar
->dragging
) ? TRUE
: FALSE
;
7391 /* Position scroll bar at rock bottom if the bottom of the
7392 buffer is visible. This avoids shinking the thumb away
7393 to nothing if it is held at the bottom of the buffer. */
7394 if (position
+ portion
>= whole
)
7396 sb_page
= range
* (whole
- position
) / whole
7397 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7401 sb_page
= portion
* range
/ whole
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7402 sb_pos
= position
* range
/ whole
;
7412 if (pfnSetScrollInfo
)
7416 si
.cbSize
= sizeof (si
);
7417 /* Only update page size if currently dragging, to reduce
7420 si
.fMask
= SIF_PAGE
;
7422 si
.fMask
= SIF_PAGE
| SIF_POS
;
7426 pfnSetScrollInfo (w
, SB_CTL
, &si
, !draggingp
);
7429 SetScrollPos (w
, SB_CTL
, sb_pos
, !draggingp
);
7435 /************************************************************************
7436 Scroll bars, general
7437 ************************************************************************/
7440 my_create_scrollbar (f
, bar
)
7442 struct scroll_bar
* bar
;
7444 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
7445 WM_EMACS_CREATESCROLLBAR
, (WPARAM
) f
,
7449 //#define ATTACH_THREADS
7452 my_show_window (FRAME_PTR f
, HWND hwnd
, int how
)
7454 #ifndef ATTACH_THREADS
7455 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
7456 (WPARAM
) hwnd
, (LPARAM
) how
);
7458 return ShowWindow (hwnd
, how
);
7463 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
7464 int x
, int y
, int cx
, int cy
, UINT flags
)
7466 #ifndef ATTACH_THREADS
7468 pos
.hwndInsertAfter
= hwndAfter
;
7474 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
7476 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
7481 my_set_focus (f
, hwnd
)
7485 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
7490 my_set_foreground_window (hwnd
)
7493 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
7497 my_destroy_window (f
, hwnd
)
7501 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
7505 /* Create a scroll bar and return the scroll bar vector for it. W is
7506 the Emacs window on which to create the scroll bar. TOP, LEFT,
7507 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7510 static struct scroll_bar
*
7511 x_scroll_bar_create (w
, top
, left
, width
, height
)
7513 int top
, left
, width
, height
;
7515 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7517 struct scroll_bar
*bar
7518 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7522 XSETWINDOW (bar
->window
, w
);
7523 XSETINT (bar
->top
, top
);
7524 XSETINT (bar
->left
, left
);
7525 XSETINT (bar
->width
, width
);
7526 XSETINT (bar
->height
, height
);
7527 XSETINT (bar
->start
, 0);
7528 XSETINT (bar
->end
, 0);
7529 bar
->dragging
= Qnil
;
7531 /* Requires geometry to be set before call to create the real window */
7533 hwnd
= my_create_scrollbar (f
, bar
);
7535 if (pfnSetScrollInfo
)
7539 si
.cbSize
= sizeof (si
);
7542 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
7543 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7547 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
7551 SetScrollRange (hwnd
, SB_CTL
, 0,
7552 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
7553 SetScrollPos (hwnd
, SB_CTL
, 0, FALSE
);
7556 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
7558 /* Add bar to its frame's list of scroll bars. */
7559 bar
->next
= FRAME_SCROLL_BARS (f
);
7561 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7562 if (! NILP (bar
->next
))
7563 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7571 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7575 x_scroll_bar_remove (bar
)
7576 struct scroll_bar
*bar
;
7578 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7582 /* Destroy the window. */
7583 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
7585 /* Disassociate this scroll bar from its window. */
7586 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7591 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7592 that we are displaying PORTION characters out of a total of WHOLE
7593 characters, starting at POSITION. If WINDOW has no scroll bar,
7596 w32_set_vertical_scroll_bar (w
, portion
, whole
, position
)
7598 int portion
, whole
, position
;
7600 struct frame
*f
= XFRAME (w
->frame
);
7601 struct scroll_bar
*bar
;
7602 int top
, height
, left
, sb_left
, width
, sb_width
;
7603 int window_x
, window_y
, window_width
, window_height
;
7605 /* Get window dimensions. */
7606 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7608 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7609 height
= window_height
;
7611 /* Compute the left edge of the scroll bar area. */
7612 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7613 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
7615 left
= XFASTINT (w
->left
);
7616 left
*= CANON_X_UNIT (f
);
7617 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
7619 /* Compute the width of the scroll bar which might be less than
7620 the width of the area reserved for the scroll bar. */
7621 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
7622 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
7626 /* Compute the left edge of the scroll bar. */
7627 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7628 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
7630 sb_left
= left
+ (width
- sb_width
) / 2;
7632 /* Does the scroll bar exist yet? */
7633 if (NILP (w
->vertical_scroll_bar
))
7637 hdc
= get_frame_dc (f
);
7638 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
7639 release_frame_dc (f
, hdc
);
7642 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
7646 /* It may just need to be moved and resized. */
7649 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
7650 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
7652 /* If already correctly positioned, do nothing. */
7653 if ( XINT (bar
->left
) == sb_left
7654 && XINT (bar
->top
) == top
7655 && XINT (bar
->width
) == sb_width
7656 && XINT (bar
->height
) == height
)
7658 /* Redraw after clear_frame. */
7659 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
7660 InvalidateRect (hwnd
, NULL
, FALSE
);
7667 hdc
= get_frame_dc (f
);
7668 /* Since Windows scroll bars are smaller than the space reserved
7669 for them on the frame, we have to clear "under" them. */
7670 w32_clear_area (f
, hdc
,
7675 release_frame_dc (f
, hdc
);
7677 /* Make sure scroll bar is "visible" before moving, to ensure the
7678 area of the parent window now exposed will be refreshed. */
7679 my_show_window (f
, hwnd
, SW_HIDE
);
7680 MoveWindow (hwnd
, sb_left
, top
,
7681 sb_width
, height
, TRUE
);
7682 if (pfnSetScrollInfo
)
7686 si
.cbSize
= sizeof (si
);
7687 si
.fMask
= SIF_RANGE
;
7689 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
7690 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7692 pfnSetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
7695 SetScrollRange (hwnd
, SB_CTL
, 0,
7696 VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
), FALSE
);
7697 my_show_window (f
, hwnd
, SW_NORMAL
);
7698 // InvalidateRect (w, NULL, FALSE);
7700 /* Remember new settings. */
7701 XSETINT (bar
->left
, sb_left
);
7702 XSETINT (bar
->top
, top
);
7703 XSETINT (bar
->width
, sb_width
);
7704 XSETINT (bar
->height
, height
);
7709 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
7711 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
7715 /* The following three hooks are used when we're doing a thorough
7716 redisplay of the frame. We don't explicitly know which scroll bars
7717 are going to be deleted, because keeping track of when windows go
7718 away is a real pain - "Can you say set-window-configuration, boys
7719 and girls?" Instead, we just assert at the beginning of redisplay
7720 that *all* scroll bars are to be removed, and then save a scroll bar
7721 from the fiery pit when we actually redisplay its window. */
7723 /* Arrange for all scroll bars on FRAME to be removed at the next call
7724 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
7725 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
7728 w32_condemn_scroll_bars (frame
)
7731 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
7732 while (! NILP (FRAME_SCROLL_BARS (frame
)))
7735 bar
= FRAME_SCROLL_BARS (frame
);
7736 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
7737 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
7738 XSCROLL_BAR (bar
)->prev
= Qnil
;
7739 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
7740 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
7741 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
7746 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
7747 Note that WINDOW isn't necessarily condemned at all. */
7750 w32_redeem_scroll_bar (window
)
7751 struct window
*window
;
7753 struct scroll_bar
*bar
;
7756 /* We can't redeem this window's scroll bar if it doesn't have one. */
7757 if (NILP (window
->vertical_scroll_bar
))
7760 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
7762 /* Unlink it from the condemned list. */
7763 f
= XFRAME (WINDOW_FRAME (window
));
7764 if (NILP (bar
->prev
))
7766 /* If the prev pointer is nil, it must be the first in one of
7768 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
7769 /* It's not condemned. Everything's fine. */
7771 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
7772 window
->vertical_scroll_bar
))
7773 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
7775 /* If its prev pointer is nil, it must be at the front of
7776 one or the other! */
7780 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
7782 if (! NILP (bar
->next
))
7783 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
7785 bar
->next
= FRAME_SCROLL_BARS (f
);
7787 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7788 if (! NILP (bar
->next
))
7789 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7792 /* Remove all scroll bars on FRAME that haven't been saved since the
7793 last call to `*condemn_scroll_bars_hook'. */
7796 w32_judge_scroll_bars (f
)
7799 Lisp_Object bar
, next
;
7801 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
7803 /* Clear out the condemned list now so we won't try to process any
7804 more events on the hapless scroll bars. */
7805 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
7807 for (; ! NILP (bar
); bar
= next
)
7809 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
7811 x_scroll_bar_remove (b
);
7814 b
->next
= b
->prev
= Qnil
;
7817 /* Now there should be no references to the condemned scroll bars,
7818 and they should get garbage-collected. */
7821 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
7822 is set to something other than no_event, it is enqueued.
7824 This may be called from a signal handler, so we have to ignore GC
7828 w32_scroll_bar_handle_click (bar
, msg
, emacs_event
)
7829 struct scroll_bar
*bar
;
7831 struct input_event
*emacs_event
;
7833 if (! GC_WINDOWP (bar
->window
))
7836 emacs_event
->kind
= w32_scroll_bar_click
;
7837 emacs_event
->code
= 0;
7838 /* not really meaningful to distinguish up/down */
7839 emacs_event
->modifiers
= msg
->dwModifiers
;
7840 emacs_event
->frame_or_window
= bar
->window
;
7841 emacs_event
->arg
= Qnil
;
7842 emacs_event
->timestamp
= msg
->msg
.time
;
7845 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7847 int dragging
= !NILP (bar
->dragging
);
7849 if (pfnGetScrollInfo
)
7853 si
.cbSize
= sizeof (si
);
7856 pfnGetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
7860 y
= GetScrollPos ((HWND
) msg
->msg
.lParam
, SB_CTL
);
7862 bar
->dragging
= Qnil
;
7865 last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
7867 switch (LOWORD (msg
->msg
.wParam
))
7870 emacs_event
->part
= scroll_bar_down_arrow
;
7873 emacs_event
->part
= scroll_bar_up_arrow
;
7876 emacs_event
->part
= scroll_bar_above_handle
;
7879 emacs_event
->part
= scroll_bar_below_handle
;
7882 emacs_event
->part
= scroll_bar_handle
;
7886 emacs_event
->part
= scroll_bar_handle
;
7890 case SB_THUMBPOSITION
:
7891 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
7892 y
= HIWORD (msg
->msg
.wParam
);
7894 emacs_event
->part
= scroll_bar_handle
;
7896 /* "Silently" update current position. */
7897 if (pfnSetScrollInfo
)
7901 si
.cbSize
= sizeof (si
);
7904 /* Remember apparent position (we actually lag behind the real
7905 position, so don't set that directly. */
7906 last_scroll_bar_drag_pos
= y
;
7908 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
7911 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, FALSE
);
7914 /* If this is the end of a drag sequence, then reset the scroll
7915 handle size to normal and do a final redraw. Otherwise do
7919 if (pfnSetScrollInfo
)
7922 int start
= XINT (bar
->start
);
7923 int end
= XINT (bar
->end
);
7925 si
.cbSize
= sizeof (si
);
7926 si
.fMask
= SIF_PAGE
| SIF_POS
;
7927 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7928 si
.nPos
= last_scroll_bar_drag_pos
;
7929 pfnSetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
7932 SetScrollPos (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, y
, TRUE
);
7936 emacs_event
->kind
= no_event
;
7940 XSETINT (emacs_event
->x
, y
);
7941 XSETINT (emacs_event
->y
, top_range
);
7947 /* Return information to the user about the current position of the mouse
7948 on the scroll bar. */
7951 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
7953 Lisp_Object
*bar_window
;
7954 enum scroll_bar_part
*part
;
7956 unsigned long *time
;
7958 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
7959 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
7960 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7962 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7967 *bar_window
= bar
->window
;
7969 if (pfnGetScrollInfo
)
7973 si
.cbSize
= sizeof (si
);
7974 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
7976 pfnGetScrollInfo (w
, SB_CTL
, &si
);
7978 top_range
= si
.nMax
- si
.nPage
+ 1;
7981 pos
= GetScrollPos (w
, SB_CTL
);
7983 switch (LOWORD (last_mouse_scroll_bar_pos
))
7985 case SB_THUMBPOSITION
:
7987 *part
= scroll_bar_handle
;
7988 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
7989 pos
= HIWORD (last_mouse_scroll_bar_pos
);
7992 *part
= scroll_bar_handle
;
7996 *part
= scroll_bar_handle
;
8001 XSETINT (*y
, top_range
);
8004 last_mouse_scroll_bar
= Qnil
;
8006 *time
= last_mouse_movement_time
;
8012 /* The screen has been cleared so we may have changed foreground or
8013 background colors, and the scroll bars may need to be redrawn.
8014 Clear out the scroll bars, and ask for expose events, so we can
8018 x_scroll_bar_clear (f
)
8023 /* We can have scroll bars even if this is 0,
8024 if we just turned off scroll bar mode.
8025 But in that case we should not clear them. */
8026 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8027 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8028 bar
= XSCROLL_BAR (bar
)->next
)
8030 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
8031 HDC hdc
= GetDC (window
);
8034 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
8035 arranges to refresh the scroll bar if hidden. */
8036 my_show_window (f
, window
, SW_HIDE
);
8038 GetClientRect (window
, &rect
);
8039 select_palette (f
, hdc
);
8040 w32_clear_rect (f
, hdc
, &rect
);
8041 deselect_palette (f
, hdc
);
8043 ReleaseDC (window
, hdc
);
8048 /* The main W32 event-reading loop - w32_read_socket. */
8050 /* Time stamp of enter window event. This is only used by w32_read_socket,
8051 but we have to put it out here, since static variables within functions
8052 sometimes don't work. */
8054 static Time enter_timestamp
;
8056 /* Record the last 100 characters stored
8057 to help debug the loss-of-chars-during-GC problem. */
8059 static int temp_index
;
8060 static short temp_buffer
[100];
8063 /* Read events coming from the W32 shell.
8064 This routine is called by the SIGIO handler.
8065 We return as soon as there are no more events to be read.
8067 Events representing keys are stored in buffer BUFP,
8068 which can hold up to NUMCHARS characters.
8069 We return the number of characters stored into the buffer,
8070 thus pretending to be `read'.
8072 EXPECTED is nonzero if the caller knows input is available.
8074 Some of these messages are reposted back to the message queue since the
8075 system calls the windows proc directly in a context where we cannot return
8076 the data nor can we guarantee the state we are in. So if we dispatch them
8077 we will get into an infinite loop. To prevent this from ever happening we
8078 will set a variable to indicate we are in the read_socket call and indicate
8079 which message we are processing since the windows proc gets called
8080 recursively with different messages by the system.
8084 w32_read_socket (sd
, bufp
, numchars
, expected
)
8086 /* register */ struct input_event
*bufp
;
8087 /* register */ int numchars
;
8091 int check_visibility
= 0;
8094 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
8096 if (interrupt_input_blocked
)
8098 interrupt_input_pending
= 1;
8102 interrupt_input_pending
= 0;
8105 /* So people can tell when we have read the available input. */
8106 input_signal_count
++;
8109 abort (); /* Don't think this happens. */
8111 /* TODO: tooltips, tool-bars, ghostscript integration, mouse
8113 while (get_next_msg (&msg
, FALSE
))
8115 switch (msg
.msg
.message
)
8118 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8122 if (msg
.rect
.right
== msg
.rect
.left
||
8123 msg
.rect
.bottom
== msg
.rect
.top
)
8125 /* We may get paint messages even though the client
8126 area is clipped - these are not expose events. */
8127 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
8128 XSTRING (f
->name
)->data
));
8130 else if (f
->async_visible
!= 1)
8132 /* Definitely not obscured, so mark as visible. */
8133 f
->async_visible
= 1;
8134 f
->async_iconified
= 0;
8135 SET_FRAME_GARBAGED (f
);
8136 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
8137 XSTRING (f
->name
)->data
));
8139 /* WM_PAINT serves as MapNotify as well, so report
8140 visibility changes properly. */
8143 bufp
->kind
= deiconify_event
;
8144 XSETFRAME (bufp
->frame_or_window
, f
);
8150 else if (! NILP (Vframe_list
)
8151 && ! NILP (XCDR (Vframe_list
)))
8152 /* Force a redisplay sooner or later to update the
8153 frame titles in case this is the second frame. */
8154 record_asynch_buffer_change ();
8158 HDC hdc
= get_frame_dc (f
);
8160 /* Erase background again for safety. */
8161 w32_clear_rect (f
, hdc
, &msg
.rect
);
8162 release_frame_dc (f
, hdc
);
8166 msg
.rect
.right
- msg
.rect
.left
,
8167 msg
.rect
.bottom
- msg
.rect
.top
);
8172 case WM_INPUTLANGCHANGE
:
8173 /* Generate a language change event. */
8174 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8181 bufp
->kind
= language_change_event
;
8182 XSETFRAME (bufp
->frame_or_window
, f
);
8184 bufp
->code
= msg
.msg
.wParam
;
8185 bufp
->modifiers
= msg
.msg
.lParam
& 0xffff;
8194 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8196 if (f
&& !f
->iconified
)
8198 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8200 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8201 bufp
->kind
= non_ascii_keystroke
;
8202 bufp
->code
= msg
.msg
.wParam
;
8203 bufp
->modifiers
= msg
.dwModifiers
;
8204 XSETFRAME (bufp
->frame_or_window
, f
);
8206 bufp
->timestamp
= msg
.msg
.time
;
8215 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8217 if (f
&& !f
->iconified
)
8219 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8221 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
8222 bufp
->kind
= ascii_keystroke
;
8223 bufp
->code
= msg
.msg
.wParam
;
8224 bufp
->modifiers
= msg
.dwModifiers
;
8225 XSETFRAME (bufp
->frame_or_window
, f
);
8227 bufp
->timestamp
= msg
.msg
.time
;
8235 previous_help_echo
= help_echo
;
8236 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
8239 if (dpyinfo
->grabbed
&& last_mouse_frame
8240 && FRAME_LIVE_P (last_mouse_frame
))
8241 f
= last_mouse_frame
;
8243 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8246 note_mouse_movement (f
, &msg
.msg
);
8249 /* If we move outside the frame, then we're
8250 certainly no longer on any text in the frame. */
8251 clear_mouse_face (dpyinfo
);
8254 /* If the contents of the global variable help_echo
8255 has changed, generate a HELP_EVENT. */
8256 if (!NILP (help_echo
)
8257 || !NILP (previous_help_echo
))
8263 XSETFRAME (frame
, f
);
8267 any_help_event_p
= 1;
8268 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
8269 help_echo_window
, help_echo_object
,
8271 bufp
+= n
, count
+= n
, numchars
-= n
;
8275 case WM_LBUTTONDOWN
:
8277 case WM_MBUTTONDOWN
:
8279 case WM_RBUTTONDOWN
:
8282 /* If we decide we want to generate an event to be seen
8283 by the rest of Emacs, we put it here. */
8284 struct input_event emacs_event
;
8289 emacs_event
.kind
= no_event
;
8291 if (dpyinfo
->grabbed
&& last_mouse_frame
8292 && FRAME_LIVE_P (last_mouse_frame
))
8293 f
= last_mouse_frame
;
8295 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8299 construct_mouse_click (&emacs_event
, &msg
, f
);
8301 /* Is this in the tool-bar? */
8302 if (WINDOWP (f
->tool_bar_window
)
8303 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
8309 window
= window_from_coordinates (f
,
8313 if (EQ (window
, f
->tool_bar_window
))
8315 w32_handle_tool_bar_click (f
, &emacs_event
);
8321 if (!dpyinfo
->w32_focus_frame
8322 || f
== dpyinfo
->w32_focus_frame
8325 construct_mouse_click (bufp
, &msg
, f
);
8332 parse_button (msg
.msg
.message
, &button
, &up
);
8336 dpyinfo
->grabbed
&= ~ (1 << button
);
8340 dpyinfo
->grabbed
|= (1 << button
);
8341 last_mouse_frame
= f
;
8342 /* Ignore any mouse motion that happened
8343 before this event; any subsequent mouse-movement
8344 Emacs events should reflect only motion after
8350 last_tool_bar_item
= -1;
8356 if (dpyinfo
->grabbed
&& last_mouse_frame
8357 && FRAME_LIVE_P (last_mouse_frame
))
8358 f
= last_mouse_frame
;
8360 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8364 if ((!dpyinfo
->w32_focus_frame
8365 || f
== dpyinfo
->w32_focus_frame
)
8368 construct_mouse_wheel (bufp
, &msg
, f
);
8378 HMENU menu
= (HMENU
) msg
.msg
.lParam
;
8379 UINT menu_item
= (UINT
) LOWORD (msg
.msg
.wParam
);
8380 UINT flags
= (UINT
) HIWORD (msg
.msg
.wParam
);
8382 w32_menu_display_help (menu
, menu_item
, flags
);
8387 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8391 construct_drag_n_drop (bufp
, &msg
, f
);
8400 struct scroll_bar
*bar
=
8401 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
);
8403 if (bar
&& numchars
>= 1)
8405 if (w32_scroll_bar_handle_click (bar
, &msg
, bufp
))
8415 case WM_WINDOWPOSCHANGED
:
8417 case WM_ACTIVATEAPP
:
8418 check_visibility
= 1;
8422 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8424 if (f
&& !f
->async_iconified
)
8428 x_real_positions (f
, &x
, &y
);
8429 f
->output_data
.w32
->left_pos
= x
;
8430 f
->output_data
.w32
->top_pos
= y
;
8433 check_visibility
= 1;
8437 /* If window has been obscured or exposed by another window
8438 being maximised or minimised/restored, then recheck
8439 visibility of all frames. Direct changes to our own
8440 windows get handled by WM_SIZE. */
8442 if (msg
.msg
.lParam
!= 0)
8443 check_visibility
= 1;
8446 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8447 f
->async_visible
= msg
.msg
.wParam
;
8451 check_visibility
= 1;
8455 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8457 /* Inform lisp of whether frame has been iconified etc. */
8460 switch (msg
.msg
.wParam
)
8462 case SIZE_MINIMIZED
:
8463 f
->async_visible
= 0;
8464 f
->async_iconified
= 1;
8466 bufp
->kind
= iconify_event
;
8467 XSETFRAME (bufp
->frame_or_window
, f
);
8474 case SIZE_MAXIMIZED
:
8476 f
->async_visible
= 1;
8477 f
->async_iconified
= 0;
8479 /* wait_reading_process_input will notice this and update
8480 the frame's display structures. */
8481 SET_FRAME_GARBAGED (f
);
8487 /* Reset top and left positions of the Window
8488 here since Windows sends a WM_MOVE message
8489 BEFORE telling us the Window is minimized
8490 when the Window is iconified, with 3000,3000
8492 x_real_positions (f
, &x
, &y
);
8493 f
->output_data
.w32
->left_pos
= x
;
8494 f
->output_data
.w32
->top_pos
= y
;
8496 bufp
->kind
= deiconify_event
;
8497 XSETFRAME (bufp
->frame_or_window
, f
);
8503 else if (! NILP (Vframe_list
)
8504 && ! NILP (XCDR (Vframe_list
)))
8505 /* Force a redisplay sooner or later
8506 to update the frame titles
8507 in case this is the second frame. */
8508 record_asynch_buffer_change ();
8513 if (f
&& !f
->async_iconified
&& msg
.msg
.wParam
!= SIZE_MINIMIZED
)
8521 GetClientRect (msg
.msg
.hwnd
, &rect
);
8523 height
= rect
.bottom
- rect
.top
;
8524 width
= rect
.right
- rect
.left
;
8526 rows
= PIXEL_TO_CHAR_HEIGHT (f
, height
);
8527 columns
= PIXEL_TO_CHAR_WIDTH (f
, width
);
8529 /* TODO: Clip size to the screen dimensions. */
8531 /* Even if the number of character rows and columns has
8532 not changed, the font size may have changed, so we need
8533 to check the pixel dimensions as well. */
8535 if (columns
!= f
->width
8536 || rows
!= f
->height
8537 || width
!= f
->output_data
.w32
->pixel_width
8538 || height
!= f
->output_data
.w32
->pixel_height
)
8540 change_frame_size (f
, rows
, columns
, 0, 1, 0);
8541 SET_FRAME_GARBAGED (f
);
8542 cancel_mouse_face (f
);
8543 f
->output_data
.w32
->pixel_width
= width
;
8544 f
->output_data
.w32
->pixel_height
= height
;
8545 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
8549 check_visibility
= 1;
8553 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8555 dpyinfo
->w32_focus_event_frame
= f
;
8558 x_new_focus_frame (dpyinfo
, f
);
8561 dpyinfo
->grabbed
= 0;
8562 check_visibility
= 1;
8566 /* TODO: some of this belongs in MOUSE_LEAVE */
8567 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8571 if (f
== dpyinfo
->w32_focus_event_frame
)
8572 dpyinfo
->w32_focus_event_frame
= 0;
8574 if (f
== dpyinfo
->w32_focus_frame
)
8575 x_new_focus_frame (dpyinfo
, 0);
8577 if (f
== dpyinfo
->mouse_face_mouse_frame
)
8579 /* If we move outside the frame, then we're
8580 certainly no longer on any text in the frame. */
8581 clear_mouse_face (dpyinfo
);
8582 dpyinfo
->mouse_face_mouse_frame
= 0;
8585 /* Generate a nil HELP_EVENT to cancel a help-echo.
8586 Do it only if there's something to cancel.
8587 Otherwise, the startup message is cleared when
8588 the mouse leaves the frame. */
8589 if (any_help_event_p
)
8594 XSETFRAME (frame
, f
);
8596 n
= gen_help_event (bufp
, numchars
,
8597 Qnil
, frame
, Qnil
, Qnil
, 0);
8598 bufp
+= n
, count
+= n
, numchars
-=n
;
8602 dpyinfo
->grabbed
= 0;
8603 check_visibility
= 1;
8607 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8614 bufp
->kind
= delete_window_event
;
8615 XSETFRAME (bufp
->frame_or_window
, f
);
8624 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8631 bufp
->kind
= menu_bar_activate_event
;
8632 XSETFRAME (bufp
->frame_or_window
, f
);
8641 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8645 extern void menubar_selection_callback
8646 (FRAME_PTR f
, void * client_data
);
8647 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
8650 check_visibility
= 1;
8653 case WM_DISPLAYCHANGE
:
8654 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8658 dpyinfo
->width
= (short) LOWORD (msg
.msg
.lParam
);
8659 dpyinfo
->height
= (short) HIWORD (msg
.msg
.lParam
);
8660 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
8661 DebPrint (("display change: %d %d\n", dpyinfo
->width
,
8665 check_visibility
= 1;
8669 /* Check for messages registered at runtime. */
8670 if (msg
.msg
.message
== msh_mousewheel
)
8672 if (dpyinfo
->grabbed
&& last_mouse_frame
8673 && FRAME_LIVE_P (last_mouse_frame
))
8674 f
= last_mouse_frame
;
8676 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
8680 if ((!dpyinfo
->w32_focus_frame
8681 || f
== dpyinfo
->w32_focus_frame
)
8684 construct_mouse_wheel (bufp
, &msg
, f
);
8695 /* If the focus was just given to an autoraising frame,
8697 /* ??? This ought to be able to handle more than one such frame. */
8698 if (pending_autoraise_frame
)
8700 x_raise_frame (pending_autoraise_frame
);
8701 pending_autoraise_frame
= 0;
8704 /* Check which frames are still visisble, if we have enqueued any user
8705 events or been notified of events that may affect visibility. We
8706 do this here because there doesn't seem to be any direct
8707 notification from Windows that the visibility of a window has
8708 changed (at least, not in all cases). */
8709 if (count
> 0 || check_visibility
)
8711 Lisp_Object tail
, frame
;
8713 FOR_EACH_FRAME (tail
, frame
)
8715 FRAME_PTR f
= XFRAME (frame
);
8716 /* Check "visible" frames and mark each as obscured or not.
8717 Note that async_visible is nonzero for unobscured and
8718 obscured frames, but zero for hidden and iconified frames. */
8719 if (FRAME_W32_P (f
) && f
->async_visible
)
8722 HDC hdc
= get_frame_dc (f
);
8723 GetClipBox (hdc
, &clipbox
);
8724 release_frame_dc (f
, hdc
);
8726 if (clipbox
.right
== clipbox
.left
8727 || clipbox
.bottom
== clipbox
.top
)
8729 /* Frame has become completely obscured so mark as
8730 such (we do this by setting async_visible to 2 so
8731 that FRAME_VISIBLE_P is still true, but redisplay
8733 f
->async_visible
= 2;
8735 if (!FRAME_OBSCURED_P (f
))
8737 DebPrint (("frame %p (%s) obscured\n", f
,
8738 XSTRING (f
->name
)->data
));
8743 /* Frame is not obscured, so mark it as such. */
8744 f
->async_visible
= 1;
8746 if (FRAME_OBSCURED_P (f
))
8748 SET_FRAME_GARBAGED (f
);
8749 DebPrint (("obscured frame %p (%s) found to be visible\n", f
,
8750 XSTRING (f
->name
)->data
));
8752 /* Force a redisplay sooner or later. */
8753 record_asynch_buffer_change ();
8767 /***********************************************************************
8769 ***********************************************************************/
8771 /* Note if the text cursor of window W has been overwritten by a
8772 drawing operation that outputs N glyphs starting at HPOS in the
8773 line given by output_cursor.vpos. N < 0 means all the rest of the
8774 line after HPOS has been written. */
8777 note_overwritten_text_cursor (w
, hpos
, n
)
8781 if (updated_area
== TEXT_AREA
8782 && output_cursor
.vpos
== w
->phys_cursor
.vpos
8783 && hpos
<= w
->phys_cursor
.hpos
8785 || hpos
+ n
> w
->phys_cursor
.hpos
))
8786 w
->phys_cursor_on_p
= 0;
8790 /* Set clipping for output in glyph row ROW. W is the window in which
8791 we operate. GC is the graphics context to set clipping in.
8792 WHOLE_LINE_P non-zero means include the areas used for truncation
8793 mark display and alike in the clipping rectangle.
8795 ROW may be a text row or, e.g., a mode line. Text rows must be
8796 clipped to the interior of the window dedicated to text display,
8797 mode lines must be clipped to the whole window. */
8800 w32_clip_to_row (w
, row
, hdc
, whole_line_p
)
8802 struct glyph_row
*row
;
8806 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8808 int window_x
, window_y
, window_width
, window_height
;
8810 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8812 clip_rect
.left
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
8813 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8814 clip_rect
.top
= max (clip_rect
.top
, window_y
);
8815 clip_rect
.right
= clip_rect
.left
+ window_width
;
8816 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
8818 /* If clipping to the whole line, including trunc marks, extend
8819 the rectangle to the left and increase its width. */
8822 clip_rect
.left
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
8823 clip_rect
.right
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
8826 w32_set_clip_rectangle (hdc
, &clip_rect
);
8830 /* Draw a hollow box cursor on window W in glyph row ROW. */
8833 x_draw_hollow_cursor (w
, row
)
8835 struct glyph_row
*row
;
8837 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8841 struct glyph
*cursor_glyph
;
8842 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
8844 /* Compute frame-relative coordinates from window-relative
8846 rect
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8847 rect
.top
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
8848 + row
->ascent
- w
->phys_cursor_ascent
);
8849 rect
.bottom
= rect
.top
+ row
->height
- 1;
8851 /* Get the glyph the cursor is on. If we can't tell because
8852 the current matrix is invalid or such, give up. */
8853 cursor_glyph
= get_phys_cursor_glyph (w
);
8854 if (cursor_glyph
== NULL
)
8857 /* Compute the width of the rectangle to draw. If on a stretch
8858 glyph, and `x-stretch-block-cursor' is nil, don't draw a
8859 rectangle as wide as the glyph, but use a canonical character
8861 wd
= cursor_glyph
->pixel_width
- 1;
8862 if (cursor_glyph
->type
== STRETCH_GLYPH
8863 && !x_stretch_cursor_p
)
8864 wd
= min (CANON_X_UNIT (f
), wd
);
8866 rect
.right
= rect
.left
+ wd
;
8867 hdc
= get_frame_dc (f
);
8868 FrameRect (hdc
, &rect
, hb
);
8871 release_frame_dc (f
, hdc
);
8875 /* Draw a bar cursor on window W in glyph row ROW.
8877 Implementation note: One would like to draw a bar cursor with an
8878 angle equal to the one given by the font property XA_ITALIC_ANGLE.
8879 Unfortunately, I didn't find a font yet that has this property set.
8883 x_draw_bar_cursor (w
, row
, width
)
8885 struct glyph_row
*row
;
8888 struct frame
*f
= XFRAME (w
->frame
);
8889 struct glyph
*cursor_glyph
;
8893 /* If cursor is out of bounds, don't draw garbage. This can happen
8894 in mini-buffer windows when switching between echo area glyphs
8896 cursor_glyph
= get_phys_cursor_glyph (w
);
8897 if (cursor_glyph
== NULL
)
8900 /* If on an image, draw like a normal cursor. That's usually better
8901 visible than drawing a bar, esp. if the image is large so that
8902 the bar might not be in the window. */
8903 if (cursor_glyph
->type
== IMAGE_GLYPH
)
8905 struct glyph_row
*row
;
8906 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
8907 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
8912 width
= f
->output_data
.w32
->cursor_width
;
8914 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8915 hdc
= get_frame_dc (f
);
8916 w32_clip_to_row (w
, row
, hdc
, 0);
8917 w32_fill_area (f
, hdc
, f
->output_data
.w32
->cursor_pixel
,
8919 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
8920 min (cursor_glyph
->pixel_width
, width
),
8922 release_frame_dc (f
, hdc
);
8927 /* Clear the cursor of window W to background color, and mark the
8928 cursor as not shown. This is used when the text where the cursor
8929 is is about to be rewritten. */
8935 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
8936 x_update_window_cursor (w
, 0);
8940 /* Draw the cursor glyph of window W in glyph row ROW. See the
8941 comment of x_draw_glyphs for the meaning of HL. */
8944 x_draw_phys_cursor_glyph (w
, row
, hl
)
8946 struct glyph_row
*row
;
8947 enum draw_glyphs_face hl
;
8949 /* If cursor hpos is out of bounds, don't draw garbage. This can
8950 happen in mini-buffer windows when switching between echo area
8951 glyphs and mini-buffer. */
8952 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
8954 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
8955 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
8958 /* When we erase the cursor, and ROW is overlapped by other
8959 rows, make sure that these overlapping parts of other rows
8961 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
8963 if (row
> w
->current_matrix
->rows
8964 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
8965 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
8967 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
8968 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
8969 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
8975 /* Erase the image of a cursor of window W from the screen. */
8978 x_erase_phys_cursor (w
)
8981 struct frame
*f
= XFRAME (w
->frame
);
8982 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
8983 int hpos
= w
->phys_cursor
.hpos
;
8984 int vpos
= w
->phys_cursor
.vpos
;
8985 int mouse_face_here_p
= 0;
8986 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
8987 struct glyph_row
*cursor_row
;
8988 struct glyph
*cursor_glyph
;
8989 enum draw_glyphs_face hl
;
8991 /* No cursor displayed or row invalidated => nothing to do on the
8993 if (w
->phys_cursor_type
== NO_CURSOR
)
8994 goto mark_cursor_off
;
8996 /* VPOS >= active_glyphs->nrows means that window has been resized.
8997 Don't bother to erase the cursor. */
8998 if (vpos
>= active_glyphs
->nrows
)
8999 goto mark_cursor_off
;
9001 /* If row containing cursor is marked invalid, there is nothing we
9003 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9004 if (!cursor_row
->enabled_p
)
9005 goto mark_cursor_off
;
9007 /* This can happen when the new row is shorter than the old one.
9008 In this case, either x_draw_glyphs or clear_end_of_line
9009 should have cleared the cursor. Note that we wouldn't be
9010 able to erase the cursor in this case because we don't have a
9011 cursor glyph at hand. */
9012 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9013 goto mark_cursor_off
;
9015 /* If the cursor is in the mouse face area, redisplay that when
9016 we clear the cursor. */
9017 if (! NILP (dpyinfo
->mouse_face_window
)
9018 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9019 && (vpos
> dpyinfo
->mouse_face_beg_row
9020 || (vpos
== dpyinfo
->mouse_face_beg_row
9021 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9022 && (vpos
< dpyinfo
->mouse_face_end_row
9023 || (vpos
== dpyinfo
->mouse_face_end_row
9024 && hpos
< dpyinfo
->mouse_face_end_col
))
9025 /* Don't redraw the cursor's spot in mouse face if it is at the
9026 end of a line (on a newline). The cursor appears there, but
9027 mouse highlighting does not. */
9028 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9029 mouse_face_here_p
= 1;
9031 /* Maybe clear the display under the cursor. */
9032 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9035 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9038 cursor_glyph
= get_phys_cursor_glyph (w
);
9039 if (cursor_glyph
== NULL
)
9040 goto mark_cursor_off
;
9042 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9044 hdc
= get_frame_dc (f
);
9045 w32_clear_area (f
, hdc
, x
,
9046 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9048 cursor_glyph
->pixel_width
,
9049 cursor_row
->visible_height
);
9050 release_frame_dc (f
, hdc
);
9053 /* Erase the cursor by redrawing the character underneath it. */
9054 if (mouse_face_here_p
)
9055 hl
= DRAW_MOUSE_FACE
;
9056 else if (cursor_row
->inverse_p
)
9057 hl
= DRAW_INVERSE_VIDEO
;
9059 hl
= DRAW_NORMAL_TEXT
;
9060 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9063 w
->phys_cursor_on_p
= 0;
9064 w
->phys_cursor_type
= NO_CURSOR
;
9068 /* Display or clear cursor of window W. If ON is zero, clear the
9069 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9070 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9073 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9075 int on
, hpos
, vpos
, x
, y
;
9077 struct frame
*f
= XFRAME (w
->frame
);
9078 int new_cursor_type
;
9079 int new_cursor_width
;
9080 struct glyph_matrix
*current_glyphs
;
9081 struct glyph_row
*glyph_row
;
9082 struct glyph
*glyph
;
9084 /* This is pointless on invisible frames, and dangerous on garbaged
9085 windows and frames; in the latter case, the frame or window may
9086 be in the midst of changing its size, and x and y may be off the
9088 if (! FRAME_VISIBLE_P (f
)
9089 || FRAME_GARBAGED_P (f
)
9090 || vpos
>= w
->current_matrix
->nrows
9091 || hpos
>= w
->current_matrix
->matrix_w
)
9094 /* If cursor is off and we want it off, return quickly. */
9095 if (!on
&& !w
->phys_cursor_on_p
)
9098 current_glyphs
= w
->current_matrix
;
9099 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9100 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9102 /* If cursor row is not enabled, we don't really know where to
9103 display the cursor. */
9104 if (!glyph_row
->enabled_p
)
9106 w
->phys_cursor_on_p
= 0;
9110 xassert (interrupt_input_blocked
);
9112 /* Set new_cursor_type to the cursor we want to be displayed. In a
9113 mini-buffer window, we want the cursor only to appear if we are
9114 reading input from this window. For the selected window, we want
9115 the cursor type given by the frame parameter. If explicitly
9116 marked off, draw no cursor. In all other cases, we want a hollow
9118 new_cursor_width
= -1;
9119 if (cursor_in_echo_area
9120 && FRAME_HAS_MINIBUF_P (f
)
9121 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
9123 if (w
== XWINDOW (echo_area_window
))
9124 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9126 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9130 if (f
!= FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
9131 || w
!= XWINDOW (f
->selected_window
))
9133 extern int cursor_in_non_selected_windows
;
9135 if (MINI_WINDOW_P (w
)
9136 || !cursor_in_non_selected_windows
9137 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
9138 new_cursor_type
= NO_CURSOR
;
9140 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9142 else if (w
->cursor_off_p
)
9143 new_cursor_type
= NO_CURSOR
;
9146 struct buffer
*b
= XBUFFER (w
->buffer
);
9148 if (EQ (b
->cursor_type
, Qt
))
9149 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9151 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
9156 /* If cursor is currently being shown and we don't want it to be or
9157 it is in the wrong place, or the cursor type is not what we want,
9159 if (w
->phys_cursor_on_p
9161 || w
->phys_cursor
.x
!= x
9162 || w
->phys_cursor
.y
!= y
9163 || new_cursor_type
!= w
->phys_cursor_type
))
9164 x_erase_phys_cursor (w
);
9166 /* If the cursor is now invisible and we want it to be visible,
9168 if (on
&& !w
->phys_cursor_on_p
)
9170 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9171 w
->phys_cursor_height
= glyph_row
->height
;
9173 /* Set phys_cursor_.* before x_draw_.* is called because some
9174 of them may need the information. */
9175 w
->phys_cursor
.x
= x
;
9176 w
->phys_cursor
.y
= glyph_row
->y
;
9177 w
->phys_cursor
.hpos
= hpos
;
9178 w
->phys_cursor
.vpos
= vpos
;
9179 w
->phys_cursor_type
= new_cursor_type
;
9180 w
->phys_cursor_on_p
= 1;
9182 switch (new_cursor_type
)
9184 case HOLLOW_BOX_CURSOR
:
9185 x_draw_hollow_cursor (w
, glyph_row
);
9188 case FILLED_BOX_CURSOR
:
9189 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9193 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
9206 /* Display the cursor on window W, or clear it. X and Y are window
9207 relative pixel coordinates. HPOS and VPOS are glyph matrix
9208 positions. If W is not the selected window, display a hollow
9209 cursor. ON non-zero means display the cursor at X, Y which
9210 correspond to HPOS, VPOS, otherwise it is cleared. */
9213 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9215 int on
, hpos
, vpos
, x
, y
;
9218 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9223 /* Display the cursor on window W, or clear it, according to ON_P.
9224 Don't change the cursor's position. */
9227 x_update_cursor (f
, on_p
)
9231 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9235 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9236 in the window tree rooted at W. */
9239 x_update_cursor_in_window_tree (w
, on_p
)
9245 if (!NILP (w
->hchild
))
9246 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9247 else if (!NILP (w
->vchild
))
9248 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9250 x_update_window_cursor (w
, on_p
);
9252 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9257 /* Switch the display of W's cursor on or off, according to the value
9261 x_update_window_cursor (w
, on
)
9265 /* Don't update cursor in windows whose frame is in the process
9266 of being deleted. */
9267 if (w
->current_matrix
)
9270 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
,
9271 w
->phys_cursor
.vpos
, w
->phys_cursor
.x
,
9283 x_bitmap_icon (f
, icon
)
9289 if (FRAME_W32_WINDOW (f
) == 0)
9293 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
9294 else if (STRINGP (icon
))
9295 hicon
= LoadImage (NULL
, (LPCTSTR
) XSTRING (icon
)->data
, IMAGE_ICON
, 0, 0,
9296 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
9297 else if (SYMBOLP (icon
))
9301 if (EQ (icon
, intern ("application")))
9302 name
= (LPCTSTR
) IDI_APPLICATION
;
9303 else if (EQ (icon
, intern ("hand")))
9304 name
= (LPCTSTR
) IDI_HAND
;
9305 else if (EQ (icon
, intern ("question")))
9306 name
= (LPCTSTR
) IDI_QUESTION
;
9307 else if (EQ (icon
, intern ("exclamation")))
9308 name
= (LPCTSTR
) IDI_EXCLAMATION
;
9309 else if (EQ (icon
, intern ("asterisk")))
9310 name
= (LPCTSTR
) IDI_ASTERISK
;
9311 else if (EQ (icon
, intern ("winlogo")))
9312 name
= (LPCTSTR
) IDI_WINLOGO
;
9316 hicon
= LoadIcon (NULL
, name
);
9324 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
9331 /************************************************************************
9333 ************************************************************************/
9335 /* Display Error Handling functions not used on W32. Listing them here
9336 helps diff stay in step when comparing w32term.c with xterm.c.
9338 x_error_catcher (display, error)
9339 x_catch_errors (dpy)
9340 x_catch_errors_unwind (old_val)
9341 x_check_errors (dpy, format)
9342 x_had_errors_p (dpy)
9343 x_clear_errors (dpy)
9344 x_uncatch_errors (dpy, count)
9346 x_connection_signal (signalnum)
9347 x_connection_closed (dpy, error_message)
9348 x_error_quitter (display, error)
9349 x_error_handler (display, error)
9350 x_io_error_quitter (display)
9355 /* Changing the font of the frame. */
9357 /* Give frame F the font named FONTNAME as its default font, and
9358 return the full name of that font. FONTNAME may be a wildcard
9359 pattern; in that case, we choose some font that fits the pattern.
9360 The return value shows which font we chose. */
9363 x_new_font (f
, fontname
)
9365 register char *fontname
;
9367 struct font_info
*fontp
9368 = FS_LOAD_FONT (f
, 0, fontname
, -1);
9373 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
9374 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
9375 FRAME_FONTSET (f
) = -1;
9377 /* Compute the scroll bar width in character columns. */
9378 if (f
->scroll_bar_pixel_width
> 0)
9380 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9381 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
9385 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9386 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
9389 /* Now make the frame display the given font. */
9390 if (FRAME_W32_WINDOW (f
) != 0)
9392 frame_update_line_height (f
);
9393 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9394 x_set_window_size (f
, 0, f
->width
, f
->height
);
9397 /* If we are setting a new frame's font for the first time,
9398 there are no faces yet, so this font's height is the line height. */
9399 f
->output_data
.w32
->line_height
= FONT_HEIGHT (FRAME_FONT (f
));
9401 return build_string (fontp
->full_name
);
9404 /* Give frame F the fontset named FONTSETNAME as its default font, and
9405 return the full name of that fontset. FONTSETNAME may be a wildcard
9406 pattern; in that case, we choose some fontset that fits the pattern.
9407 The return value shows which fontset we chose. */
9410 x_new_fontset (f
, fontsetname
)
9414 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
9420 if (FRAME_FONTSET (f
) == fontset
)
9421 /* This fontset is already set in frame F. There's nothing more
9423 return fontset_name (fontset
);
9425 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
9427 if (!STRINGP (result
))
9428 /* Can't load ASCII font. */
9431 /* Since x_new_font doesn't update any fontset information, do it now. */
9432 FRAME_FONTSET(f
) = fontset
;
9434 return build_string (fontsetname
);
9438 /***********************************************************************
9439 TODO: W32 Input Methods
9440 ***********************************************************************/
9441 /* Listing missing functions from xterm.c helps diff stay in step.
9443 xim_destroy_callback (xim, client_data, call_data)
9444 xim_open_dpy (dpyinfo, resource_name)
9446 xim_instantiate_callback (display, client_data, call_data)
9447 xim_initialize (dpyinfo, resource_name)
9448 xim_close_dpy (dpyinfo)
9453 /* Calculate the absolute position in frame F
9454 from its current recorded position values and gravity. */
9457 x_calc_absolute_position (f
)
9461 int flags
= f
->output_data
.w32
->size_hint_flags
;
9465 /* Find the position of the outside upper-left corner of
9466 the inner window, with respect to the outer window.
9467 But do this only if we will need the results. */
9468 if (f
->output_data
.w32
->parent_desc
!= FRAME_W32_DISPLAY_INFO (f
)->root_window
)
9471 MapWindowPoints (FRAME_W32_WINDOW (f
),
9472 f
->output_data
.w32
->parent_desc
,
9479 rt
.left
= rt
.right
= rt
.top
= rt
.bottom
= 0;
9482 AdjustWindowRect(&rt
, f
->output_data
.w32
->dwStyle
,
9483 FRAME_EXTERNAL_MENU_BAR (f
));
9486 pt
.x
+= (rt
.right
- rt
.left
);
9487 pt
.y
+= (rt
.bottom
- rt
.top
);
9490 /* Treat negative positions as relative to the leftmost bottommost
9491 position that fits on the screen. */
9492 if (flags
& XNegative
)
9493 f
->output_data
.w32
->left_pos
= (FRAME_W32_DISPLAY_INFO (f
)->width
9494 - 2 * f
->output_data
.w32
->border_width
- pt
.x
9496 + f
->output_data
.w32
->left_pos
);
9498 if (flags
& YNegative
)
9499 f
->output_data
.w32
->top_pos
= (FRAME_W32_DISPLAY_INFO (f
)->height
9500 - 2 * f
->output_data
.w32
->border_width
- pt
.y
9502 + f
->output_data
.w32
->top_pos
);
9503 /* The left_pos and top_pos
9504 are now relative to the top and left screen edges,
9505 so the flags should correspond. */
9506 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9509 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
9510 to really change the position, and 0 when calling from
9511 x_make_frame_visible (in that case, XOFF and YOFF are the current
9512 position values). It is -1 when calling from x_set_frame_parameters,
9513 which means, do adjust for borders but don't change the gravity. */
9516 x_set_offset (f
, xoff
, yoff
, change_gravity
)
9518 register int xoff
, yoff
;
9521 int modified_top
, modified_left
;
9523 if (change_gravity
> 0)
9525 f
->output_data
.w32
->top_pos
= yoff
;
9526 f
->output_data
.w32
->left_pos
= xoff
;
9527 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9529 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
9531 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
9532 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
9534 x_calc_absolute_position (f
);
9537 x_wm_set_size_hint (f
, (long) 0, 0);
9539 modified_left
= f
->output_data
.w32
->left_pos
;
9540 modified_top
= f
->output_data
.w32
->top_pos
;
9542 my_set_window_pos (FRAME_W32_WINDOW (f
),
9544 modified_left
, modified_top
,
9546 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
9550 /* Call this to change the size of frame F's x-window.
9551 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9552 for this size change and subsequent size changes.
9553 Otherwise we leave the window gravity unchanged. */
9556 x_set_window_size (f
, change_gravity
, cols
, rows
)
9561 int pixelwidth
, pixelheight
;
9565 check_frame_size (f
, &rows
, &cols
);
9566 f
->output_data
.w32
->vertical_scroll_bar_extra
9567 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9569 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
9570 f
->output_data
.w32
->flags_areas_extra
9571 = FRAME_FLAGS_AREA_WIDTH (f
);
9572 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
9573 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
9575 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
9576 x_wm_set_size_hint (f
, (long) 0, 0);
9581 rect
.left
= rect
.top
= 0;
9582 rect
.right
= pixelwidth
;
9583 rect
.bottom
= pixelheight
;
9585 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
,
9586 FRAME_EXTERNAL_MENU_BAR (f
));
9588 my_set_window_pos (FRAME_W32_WINDOW (f
),
9591 rect
.right
- rect
.left
,
9592 rect
.bottom
- rect
.top
,
9593 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9596 /* Now, strictly speaking, we can't be sure that this is accurate,
9597 but the window manager will get around to dealing with the size
9598 change request eventually, and we'll hear how it went when the
9599 ConfigureNotify event gets here.
9601 We could just not bother storing any of this information here,
9602 and let the ConfigureNotify event set everything up, but that
9603 might be kind of confusing to the Lisp code, since size changes
9604 wouldn't be reported in the frame parameters until some random
9605 point in the future when the ConfigureNotify event arrives.
9607 We pass 1 for DELAY since we can't run Lisp code inside of
9609 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9610 PIXEL_WIDTH (f
) = pixelwidth
;
9611 PIXEL_HEIGHT (f
) = pixelheight
;
9613 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9614 receive in the ConfigureNotify event; if we get what we asked
9615 for, then the event won't cause the screen to become garbaged, so
9616 we have to make sure to do it here. */
9617 SET_FRAME_GARBAGED (f
);
9619 /* If cursor was outside the new size, mark it as off. */
9620 mark_window_cursors_off (XWINDOW (f
->root_window
));
9622 /* Clear out any recollection of where the mouse highlighting was,
9623 since it might be in a place that's outside the new frame size.
9624 Actually checking whether it is outside is a pain in the neck,
9625 so don't try--just let the highlighting be done afresh with new size. */
9626 cancel_mouse_face (f
);
9631 /* Mouse warping. */
9633 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
9636 x_set_mouse_position (f
, x
, y
)
9642 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.w32
->font
) / 2;
9643 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.w32
->line_height
/ 2;
9645 if (pix_x
< 0) pix_x
= 0;
9646 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
9648 if (pix_y
< 0) pix_y
= 0;
9649 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
9651 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
9655 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9664 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
9665 pt
.x
= rect
.left
+ pix_x
;
9666 pt
.y
= rect
.top
+ pix_y
;
9667 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
9669 SetCursorPos (pt
.x
, pt
.y
);
9675 /* focus shifting, raising and lowering. */
9678 x_focus_on_frame (f
)
9681 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
9683 /* Give input focus to frame. */
9686 /* Try not to change its Z-order if possible. */
9687 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
9688 my_set_focus (f
, FRAME_W32_WINDOW (f
));
9691 my_set_foreground_window (FRAME_W32_WINDOW (f
));
9701 /* Raise frame F. */
9708 /* Strictly speaking, raise-frame should only change the frame's Z
9709 order, leaving input focus unchanged. This is reasonable behaviour
9710 on X where the usual policy is point-to-focus. However, this
9711 behaviour would be very odd on Windows where the usual policy is
9714 On X, if the mouse happens to be over the raised frame, it gets
9715 input focus anyway (so the window with focus will never be
9716 completely obscured) - if not, then just moving the mouse over it
9717 is sufficient to give it focus. On Windows, the user must actually
9718 click on the frame (preferrably the title bar so as not to move
9719 point), which is more awkward. Also, no other Windows program
9720 raises a window to the top but leaves another window (possibly now
9721 completely obscured) with input focus.
9723 Because there is a system setting on Windows that allows the user
9724 to choose the point to focus policy, we make the strict semantics
9725 optional, but by default we grab focus when raising. */
9727 if (NILP (Vw32_grab_focus_on_raise
))
9729 /* The obvious call to my_set_window_pos doesn't work if Emacs is
9730 not already the foreground application: the frame is raised
9731 above all other frames belonging to us, but not above the
9732 current top window. To achieve that, we have to resort to this
9733 more cumbersome method. */
9735 HDWP handle
= BeginDeferWindowPos (2);
9738 DeferWindowPos (handle
,
9739 FRAME_W32_WINDOW (f
),
9742 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9744 DeferWindowPos (handle
,
9745 GetForegroundWindow (),
9746 FRAME_W32_WINDOW (f
),
9748 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9750 EndDeferWindowPos (handle
);
9755 my_set_foreground_window (FRAME_W32_WINDOW (f
));
9761 /* Lower frame F. */
9767 my_set_window_pos (FRAME_W32_WINDOW (f
),
9770 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
9775 w32_frame_raise_lower (f
, raise_flag
)
9779 if (! FRAME_W32_P (f
))
9788 /* Change of visibility. */
9790 /* This tries to wait until the frame is really visible.
9791 However, if the window manager asks the user where to position
9792 the frame, this will return before the user finishes doing that.
9793 The frame will not actually be visible at that time,
9794 but it will become visible later when the window manager
9795 finishes with it. */
9798 x_make_frame_visible (f
)
9805 type
= x_icon_type (f
);
9807 x_bitmap_icon (f
, type
);
9809 if (! FRAME_VISIBLE_P (f
))
9811 /* We test FRAME_GARBAGED_P here to make sure we don't
9812 call x_set_offset a second time
9813 if we get to x_make_frame_visible a second time
9814 before the window gets really visible. */
9815 if (! FRAME_ICONIFIED_P (f
)
9816 && ! f
->output_data
.w32
->asked_for_visible
)
9817 x_set_offset (f
, f
->output_data
.w32
->left_pos
, f
->output_data
.w32
->top_pos
, 0);
9819 f
->output_data
.w32
->asked_for_visible
= 1;
9821 // my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW);
9822 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_SHOWNORMAL
);
9825 /* Synchronize to ensure Emacs knows the frame is visible
9826 before we do anything else. We do this loop with input not blocked
9827 so that incoming events are handled. */
9832 /* This must come after we set COUNT. */
9835 XSETFRAME (frame
, f
);
9837 /* Wait until the frame is visible. Process X events until a
9838 MapNotify event has been seen, or until we think we won't get a
9839 MapNotify at all.. */
9840 for (count
= input_signal_count
+ 10;
9841 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9843 /* Force processing of queued events. */
9844 /* TODO: x_sync equivalent? */
9846 /* Machines that do polling rather than SIGIO have been observed
9847 to go into a busy-wait here. So we'll fake an alarm signal
9848 to let the handler know that there's something to be read.
9849 We used to raise a real alarm, but it seems that the handler
9850 isn't always enabled here. This is probably a bug. */
9851 if (input_polling_used ())
9853 /* It could be confusing if a real alarm arrives while processing
9854 the fake one. Turn it off and let the handler reset it. */
9855 int old_poll_suppress_count
= poll_suppress_count
;
9856 poll_suppress_count
= 1;
9857 poll_for_input_1 ();
9858 poll_suppress_count
= old_poll_suppress_count
;
9861 FRAME_SAMPLE_VISIBILITY (f
);
9865 /* Change from mapped state to withdrawn state. */
9867 /* Make the frame visible (mapped and not iconified). */
9869 x_make_frame_invisible (f
)
9872 /* Don't keep the highlight on an invisible frame. */
9873 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
9874 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
9878 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
9880 /* We can't distinguish this from iconification
9881 just by the event that we get from the server.
9882 So we can't win using the usual strategy of letting
9883 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9884 and synchronize with the server to make sure we agree. */
9886 FRAME_ICONIFIED_P (f
) = 0;
9887 f
->async_visible
= 0;
9888 f
->async_iconified
= 0;
9893 /* Change window state from mapped to iconified. */
9901 /* Don't keep the highlight on an invisible frame. */
9902 if (FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
== f
)
9903 FRAME_W32_DISPLAY_INFO (f
)->w32_highlight_frame
= 0;
9905 if (f
->async_iconified
)
9910 type
= x_icon_type (f
);
9912 x_bitmap_icon (f
, type
);
9914 /* Simulate the user minimizing the frame. */
9915 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
9921 /* Free X resources of frame F. */
9924 x_free_frame_resources (f
)
9927 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9931 if (FRAME_W32_WINDOW (f
))
9932 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
9934 free_frame_menubar (f
);
9936 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
9937 unload_color (f
, f
->output_data
.x
->background_pixel
);
9938 unload_color (f
, f
->output_data
.w32
->cursor_pixel
);
9939 unload_color (f
, f
->output_data
.w32
->cursor_foreground_pixel
);
9940 unload_color (f
, f
->output_data
.w32
->border_pixel
);
9941 unload_color (f
, f
->output_data
.w32
->mouse_pixel
);
9942 if (f
->output_data
.w32
->white_relief
.allocated_p
)
9943 unload_color (f
, f
->output_data
.w32
->white_relief
.pixel
);
9944 if (f
->output_data
.w32
->black_relief
.allocated_p
)
9945 unload_color (f
, f
->output_data
.w32
->black_relief
.pixel
);
9947 if (FRAME_FACE_CACHE (f
))
9948 free_frame_faces (f
);
9950 xfree (f
->output_data
.w32
);
9951 f
->output_data
.w32
= NULL
;
9953 if (f
== dpyinfo
->w32_focus_frame
)
9954 dpyinfo
->w32_focus_frame
= 0;
9955 if (f
== dpyinfo
->w32_focus_event_frame
)
9956 dpyinfo
->w32_focus_event_frame
= 0;
9957 if (f
== dpyinfo
->w32_highlight_frame
)
9958 dpyinfo
->w32_highlight_frame
= 0;
9960 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9962 dpyinfo
->mouse_face_beg_row
9963 = dpyinfo
->mouse_face_beg_col
= -1;
9964 dpyinfo
->mouse_face_end_row
9965 = dpyinfo
->mouse_face_end_col
= -1;
9966 dpyinfo
->mouse_face_window
= Qnil
;
9967 dpyinfo
->mouse_face_deferred_gc
= 0;
9968 dpyinfo
->mouse_face_mouse_frame
= 0;
9975 /* Destroy the window of frame F. */
9977 x_destroy_window (f
)
9980 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
9982 x_free_frame_resources (f
);
9984 dpyinfo
->reference_count
--;
9988 /* Setting window manager hints. */
9990 /* Set the normal size hints for the window manager, for frame F.
9991 FLAGS is the flags word to use--or 0 meaning preserve the flags
9992 that the window now has.
9993 If USER_POSITION is nonzero, we set the USPosition
9994 flag (this is useful when FLAGS is 0). */
9996 x_wm_set_size_hint (f
, flags
, user_position
)
10001 Window window
= FRAME_W32_WINDOW (f
);
10005 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
10006 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
10007 SetWindowLong (window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
10008 SetWindowLong (window
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
10013 /* Window manager things */
10014 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10016 int icon_x
, icon_y
;
10019 Window window
= FRAME_W32_WINDOW (f
);
10021 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
10022 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
10023 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
10025 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
10030 /***********************************************************************
10032 ***********************************************************************/
10034 /* The following functions are listed here to help diff stay in step
10035 with xterm.c. See w32fns.c for definitions.
10037 x_get_font_info (f, font_idx)
10038 x_list_fonts (f, pattern, size, maxnames)
10044 /* Check that FONT is valid on frame F. It is if it can be found in F's
10048 x_check_font (f
, font
)
10053 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10055 xassert (font
!= NULL
);
10057 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10058 if (dpyinfo
->font_table
[i
].name
10059 && font
== dpyinfo
->font_table
[i
].font
)
10062 xassert (i
< dpyinfo
->n_fonts
);
10065 #endif /* GLYPH_DEBUG != 0 */
10067 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10068 Note: There are (broken) X fonts out there with invalid XFontStruct
10069 min_bounds contents. For example, handa@etl.go.jp reports that
10070 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10071 have font->min_bounds.width == 0. */
10074 x_font_min_bounds (font
, w
, h
)
10079 * TODO: Windows does not appear to offer min bound, only
10080 * average and maximum width, and maximum height.
10082 *h
= FONT_HEIGHT (font
);
10083 *w
= FONT_WIDTH (font
);
10087 /* Compute the smallest character width and smallest font height over
10088 all fonts available on frame F. Set the members smallest_char_width
10089 and smallest_font_height in F's x_display_info structure to
10090 the values computed. Value is non-zero if smallest_font_height or
10091 smallest_char_width become smaller than they were before. */
10094 x_compute_min_glyph_bounds (f
)
10098 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
10100 int old_width
= dpyinfo
->smallest_char_width
;
10101 int old_height
= dpyinfo
->smallest_font_height
;
10103 dpyinfo
->smallest_font_height
= 100000;
10104 dpyinfo
->smallest_char_width
= 100000;
10106 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10107 if (dpyinfo
->font_table
[i
].name
)
10109 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10112 font
= (XFontStruct
*) fontp
->font
;
10113 xassert (font
!= (XFontStruct
*) ~0);
10114 x_font_min_bounds (font
, &w
, &h
);
10116 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10117 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10120 xassert (dpyinfo
->smallest_char_width
> 0
10121 && dpyinfo
->smallest_font_height
> 0);
10123 return (dpyinfo
->n_fonts
== 1
10124 || dpyinfo
->smallest_char_width
< old_width
10125 || dpyinfo
->smallest_font_height
< old_height
);
10128 /* The following functions are listed here to help diff stay in step
10129 with xterm.c. See w32fns.c for definitions.
10131 x_load_font (f, fontname, size)
10132 x_query_font (f, fontname)
10133 x_find_ccl_program (fontp)
10137 /***********************************************************************
10139 ***********************************************************************/
10141 static int w32_initialized
= 0;
10144 w32_initialize_display_info (display_name
)
10145 Lisp_Object display_name
;
10147 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
10149 bzero (dpyinfo
, sizeof (*dpyinfo
));
10151 /* Put it on w32_display_name_list. */
10152 w32_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10153 w32_display_name_list
);
10154 dpyinfo
->name_list_element
= XCAR (w32_display_name_list
);
10156 dpyinfo
->w32_id_name
10157 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
10158 + XSTRING (Vsystem_name
)->size
10160 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
10161 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
10163 /* Default Console mode values - overridden when running in GUI mode
10164 with values obtained from system metrics. */
10167 dpyinfo
->height_in
= 1;
10168 dpyinfo
->width_in
= 1;
10169 dpyinfo
->n_planes
= 1;
10170 dpyinfo
->n_cbits
= 4;
10171 dpyinfo
->n_fonts
= 0;
10172 dpyinfo
->smallest_font_height
= 1;
10173 dpyinfo
->smallest_char_width
= 1;
10175 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10176 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10177 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10178 dpyinfo
->mouse_face_window
= Qnil
;
10180 /* TODO: dpyinfo->gray */
10184 struct w32_display_info
*
10185 w32_term_init (display_name
, xrm_option
, resource_name
)
10186 Lisp_Object display_name
;
10188 char *resource_name
;
10190 struct w32_display_info
*dpyinfo
;
10195 if (!w32_initialized
)
10198 w32_initialized
= 1;
10209 argv
[argc
++] = "-xrm";
10210 argv
[argc
++] = xrm_option
;
10214 w32_initialize_display_info (display_name
);
10216 dpyinfo
= &one_w32_display_info
;
10218 /* Put this display on the chain. */
10219 dpyinfo
->next
= x_display_list
;
10220 x_display_list
= dpyinfo
;
10222 hdc
= GetDC (GetDesktopWindow ());
10224 dpyinfo
->height
= GetDeviceCaps (hdc
, VERTRES
);
10225 dpyinfo
->width
= GetDeviceCaps (hdc
, HORZRES
);
10226 dpyinfo
->root_window
= GetDesktopWindow ();
10227 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
10228 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
10229 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
10230 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
10231 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
10232 dpyinfo
->image_cache
= make_image_cache ();
10233 dpyinfo
->height_in
= dpyinfo
->height
/ dpyinfo
->resx
;
10234 dpyinfo
->width_in
= dpyinfo
->width
/ dpyinfo
->resy
;
10235 ReleaseDC (GetDesktopWindow (), hdc
);
10237 /* initialise palette with white and black */
10240 w32_defined_color (0, "white", &color
, 1);
10241 w32_defined_color (0, "black", &color
, 1);
10244 /* Create Row Bitmaps and store them for later use. */
10245 left_bmp
= CreateBitmap (left_width
, left_height
, 1, 1, left_bits
);
10246 ov_bmp
= CreateBitmap (ov_width
, ov_height
, 1, 1, ov_bits
);
10247 right_bmp
= CreateBitmap (right_width
, right_height
, 1, 1, right_bits
);
10248 continued_bmp
= CreateBitmap (continued_width
, continued_height
, 1,
10249 1, continued_bits
);
10250 continuation_bmp
= CreateBitmap (continuation_width
, continuation_height
,
10251 1, 1, continuation_bits
);
10252 zv_bmp
= CreateBitmap (zv_width
, zv_height
, 1, 1, zv_bits
);
10254 #ifndef F_SETOWN_BUG
10256 #ifdef F_SETOWN_SOCK_NEG
10257 /* stdin is a socket here */
10258 fcntl (connection
, F_SETOWN
, -getpid ());
10259 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10260 fcntl (connection
, F_SETOWN
, getpid ());
10261 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10262 #endif /* ! defined (F_SETOWN) */
10263 #endif /* F_SETOWN_BUG */
10266 if (interrupt_input
)
10267 init_sigio (connection
);
10268 #endif /* ! defined (SIGIO) */
10275 /* Get rid of display DPYINFO, assuming all frames are already gone. */
10278 x_delete_display (dpyinfo
)
10279 struct w32_display_info
*dpyinfo
;
10281 /* Discard this display from w32_display_name_list and w32_display_list.
10282 We can't use Fdelq because that can quit. */
10283 if (! NILP (w32_display_name_list
)
10284 && EQ (XCAR (w32_display_name_list
), dpyinfo
->name_list_element
))
10285 w32_display_name_list
= XCDR (w32_display_name_list
);
10290 tail
= w32_display_name_list
;
10291 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10293 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10295 XCDR (tail
) = XCDR (XCDR (tail
));
10298 tail
= XCDR (tail
);
10302 /* free palette table */
10304 struct w32_palette_entry
* plist
;
10306 plist
= dpyinfo
->color_list
;
10309 struct w32_palette_entry
* pentry
= plist
;
10310 plist
= plist
->next
;
10313 dpyinfo
->color_list
= NULL
;
10314 if (dpyinfo
->palette
)
10315 DeleteObject(dpyinfo
->palette
);
10317 xfree (dpyinfo
->font_table
);
10318 xfree (dpyinfo
->w32_id_name
);
10320 /* Destroy row bitmaps. */
10321 DeleteObject (left_bmp
);
10322 DeleteObject (ov_bmp
);
10323 DeleteObject (right_bmp
);
10324 DeleteObject (continued_bmp
);
10325 DeleteObject (continuation_bmp
);
10326 DeleteObject (zv_bmp
);
10329 /* Set up use of W32. */
10331 DWORD
w32_msg_worker ();
10334 x_flush (struct frame
* f
)
10335 { /* Nothing to do */ }
10337 static struct redisplay_interface w32_redisplay_interface
=
10342 x_clear_end_of_line
,
10344 x_after_update_window_line
,
10345 x_update_window_begin
,
10346 x_update_window_end
,
10349 x_clear_mouse_face
,
10350 x_get_glyph_overhangs
,
10351 x_fix_overlapping_area
10357 rif
= &w32_redisplay_interface
;
10359 /* MSVC does not type K&R functions with no arguments correctly, and
10360 so we must explicitly cast them. */
10361 clear_frame_hook
= (void (*)(void)) x_clear_frame
;
10362 ring_bell_hook
= (void (*)(void)) w32_ring_bell
;
10363 update_begin_hook
= x_update_begin
;
10364 update_end_hook
= x_update_end
;
10366 read_socket_hook
= w32_read_socket
;
10368 frame_up_to_date_hook
= w32_frame_up_to_date
;
10370 mouse_position_hook
= w32_mouse_position
;
10371 frame_rehighlight_hook
= w32_frame_rehighlight
;
10372 frame_raise_lower_hook
= w32_frame_raise_lower
;
10373 set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
10374 condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
10375 redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
10376 judge_scroll_bars_hook
= w32_judge_scroll_bars
;
10377 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
10379 scroll_region_ok
= 1; /* we'll scroll partial frames */
10380 char_ins_del_ok
= 1;
10381 line_ins_del_ok
= 1; /* we'll just blt 'em */
10382 fast_clear_end_of_line
= 1; /* X does this well */
10383 memory_below_frame
= 0; /* we don't remember what scrolls
10387 last_tool_bar_item
= -1;
10388 any_help_event_p
= 0;
10390 /* Initialize input mode: interrupt_input off, no flow control, allow
10391 8 bit character input, standard quit char. */
10392 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
10394 /* Create the window thread - it will terminate itself or when the app terminates */
10398 dwMainThreadId
= GetCurrentThreadId ();
10399 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
10400 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
10402 /* Wait for thread to start */
10407 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
10409 hWindowsThread
= CreateThread (NULL
, 0,
10410 (LPTHREAD_START_ROUTINE
) w32_msg_worker
,
10411 0, 0, &dwWindowsThreadId
);
10413 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
10416 /* It is desirable that mainThread should have the same notion of
10417 focus window and active window as windowsThread. Unfortunately, the
10418 following call to AttachThreadInput, which should do precisely what
10419 we need, causes major problems when Emacs is linked as a console
10420 program. Unfortunately, we have good reasons for doing that, so
10421 instead we need to send messages to windowsThread to make some API
10422 calls for us (ones that affect, or depend on, the active/focus
10424 #ifdef ATTACH_THREADS
10425 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
10428 /* Dynamically link to optional system components. */
10430 HANDLE user_lib
= LoadLibrary ("user32.dll");
10432 #define LOAD_PROC(fn) pfn##fn = (void *) GetProcAddress (user_lib, #fn)
10434 /* New proportional scroll bar functions. */
10435 LOAD_PROC (SetScrollInfo
);
10436 LOAD_PROC (GetScrollInfo
);
10440 FreeLibrary (user_lib
);
10442 /* If using proportional scroll bars, ensure handle is at least 5 pixels;
10443 otherwise use the fixed height. */
10444 vertical_scroll_bar_min_handle
= (pfnSetScrollInfo
!= NULL
) ? 5 :
10445 GetSystemMetrics (SM_CYVTHUMB
);
10447 /* For either kind of scroll bar, take account of the arrows; these
10448 effectively form the border of the main scroll bar range. */
10449 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
10450 = GetSystemMetrics (SM_CYVSCROLL
);
10457 staticpro (&w32_display_name_list
);
10458 w32_display_name_list
= Qnil
;
10460 staticpro (&last_mouse_scroll_bar
);
10461 last_mouse_scroll_bar
= Qnil
;
10463 staticpro (&Qvendor_specific_keysyms
);
10464 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
10466 DEFVAR_INT ("w32-num-mouse-buttons",
10467 &Vw32_num_mouse_buttons
,
10468 "Number of physical mouse buttons.");
10469 Vw32_num_mouse_buttons
= Qnil
;
10471 DEFVAR_LISP ("w32-swap-mouse-buttons",
10472 &Vw32_swap_mouse_buttons
,
10473 "Swap the mapping of middle and right mouse buttons.\n\
10474 When nil, middle button is mouse-2 and right button is mouse-3.");
10475 Vw32_swap_mouse_buttons
= Qnil
;
10477 DEFVAR_LISP ("w32-grab-focus-on-raise",
10478 &Vw32_grab_focus_on_raise
,
10479 "Raised frame grabs input focus.\n\
10480 When t, `raise-frame' grabs input focus as well. This fits well\n\
10481 with the normal Windows click-to-focus policy, but might not be\n\
10482 desirable when using a point-to-focus policy.");
10483 Vw32_grab_focus_on_raise
= Qt
;
10485 DEFVAR_LISP ("w32-capslock-is-shiftlock",
10486 &Vw32_capslock_is_shiftlock
,
10487 "Apply CapsLock state to non character input keys.\n\
10488 When nil, CapsLock only affects normal character input keys.");
10489 Vw32_capslock_is_shiftlock
= Qnil
;
10491 DEFVAR_LISP ("w32-recognize-altgr",
10492 &Vw32_recognize_altgr
,
10493 "Recognize right-alt and left-ctrl as AltGr.\n\
10494 When nil, the right-alt and left-ctrl key combination is\n\
10495 interpreted normally.");
10496 Vw32_recognize_altgr
= Qt
;
10498 DEFVAR_BOOL ("w32-enable-unicode-output",
10499 &w32_enable_unicode_output
,
10500 "Enable the use of Unicode for text output if non-nil.\n\
10501 Unicode output may prevent some third party applications for displaying\n\
10502 Far-East Languages on Windows 95/98 from working properly.\n\
10503 NT uses Unicode internally anyway, so this flag will probably have no\n\
10504 affect on NT machines.");
10505 w32_enable_unicode_output
= 1;
10508 staticpro (&help_echo
);
10509 help_echo_object
= Qnil
;
10510 staticpro (&help_echo_object
);
10511 help_echo_window
= Qnil
;
10512 staticpro (&help_echo_window
);
10513 previous_help_echo
= Qnil
;
10514 staticpro (&previous_help_echo
);
10515 help_echo_pos
= -1;
10517 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
10518 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
10519 For example, if a block cursor is over a tab, it will be drawn as\n\
10520 wide as that tab on the display.");
10521 x_stretch_cursor_p
= 0;
10523 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10524 "If not nil, Emacs uses toolkit scroll bars.");
10525 Vx_toolkit_scroll_bars
= Qt
;
10527 staticpro (&last_mouse_motion_frame
);
10528 last_mouse_motion_frame
= Qnil
;