1 /* Implementation of GUI terminal on the Microsoft W32 API.
2 Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26 #include "blockinput.h"
38 #include "character.h"
42 #include "dispextern.h"
44 #include "termhooks.h"
51 #include "intervals.h"
64 static int max_fringe_bmp
= 0;
65 static HBITMAP
*fringe_bmp
= 0;
67 /* Non-nil means Emacs uses toolkit scroll bars. */
69 Lisp_Object Vx_toolkit_scroll_bars
;
71 /* Temporary variables for w32_read_socket. */
73 static int last_mousemove_x
= 0;
74 static int last_mousemove_y
= 0;
76 /* Define GET_WHEEL_DELTA_WPARAM macro if system headers don't. */
77 #ifndef GET_WHEEL_DELTA_WPARAM
78 #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam))
81 /* Non-zero means that a HELP_EVENT has been generated since Emacs
84 static int any_help_event_p
;
86 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
87 static Lisp_Object last_window
;
89 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
90 int x_use_underline_position_properties
;
92 /* Non-zero means to draw the underline at the same place as the descent line. */
94 int x_underline_at_descent_line
;
96 extern unsigned int msh_mousewheel
;
98 extern void free_frame_menubar ();
100 extern int w32_codepage_for_font (char *fontname
);
101 extern Cursor
w32_load_cursor (LPCTSTR name
);
103 extern Lisp_Object Vwindow_system
;
105 #define x_any_window_to_frame x_window_to_frame
106 #define x_top_window_to_frame x_window_to_frame
109 /* This is display since w32 does not support multiple ones. */
110 struct w32_display_info one_w32_display_info
;
111 struct w32_display_info
*x_display_list
;
113 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
114 one for each element of w32_display_list and in the same order.
115 NAME is the name of the frame.
116 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
117 Lisp_Object w32_display_name_list
;
121 /* Pre Windows 2000, this was not available, but define it here so
122 that Emacs compiled on such a platform will run on newer versions. */
124 typedef struct tagWCRANGE
130 typedef struct tagGLYPHSET
134 DWORD cGlyphsSupported
;
141 /* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */
142 BOOL (PASCAL
*pfnSetLayeredWindowAttributes
) (HWND
, COLORREF
, BYTE
, DWORD
);
145 #define LWA_ALPHA 0x02
147 /* WS_EX_LAYERED is defined unconditionally by MingW, but only for W2K and
148 later targets by MSVC headers. */
149 #ifndef WS_EX_LAYERED
150 #define WS_EX_LAYERED 0x80000
153 /* Frame being updated by update_frame. This is declared in term.c.
154 This is set by update_begin and looked at by all the
155 w32 functions. It is zero while not inside an update.
156 In that case, the w32 functions assume that `SELECTED_FRAME ()'
157 is the frame to apply to. */
158 extern struct frame
*updating_frame
;
160 /* This is a frame waiting to be autoraised, within w32_read_socket. */
161 struct frame
*pending_autoraise_frame
;
163 /* The handle of the frame that currently owns the system caret. */
164 HWND w32_system_caret_hwnd
;
165 int w32_system_caret_height
;
166 int w32_system_caret_x
;
167 int w32_system_caret_y
;
168 int w32_use_visible_system_caret
;
170 DWORD dwWindowsThreadId
= 0;
171 HANDLE hWindowsThread
= NULL
;
172 DWORD dwMainThreadId
= 0;
173 HANDLE hMainThread
= NULL
;
175 int vertical_scroll_bar_min_handle
;
176 int vertical_scroll_bar_top_border
;
177 int vertical_scroll_bar_bottom_border
;
179 int last_scroll_bar_drag_pos
;
181 /* Mouse movement. */
183 /* Where the mouse was last time we reported a mouse event. */
185 static RECT last_mouse_glyph
;
186 static FRAME_PTR last_mouse_glyph_frame
;
187 static Lisp_Object last_mouse_press_frame
;
189 int w32_num_mouse_buttons
;
191 Lisp_Object Vw32_swap_mouse_buttons
;
193 /* Control whether x_raise_frame also sets input focus. */
194 Lisp_Object Vw32_grab_focus_on_raise
;
196 /* Control whether Caps Lock affects non-ascii characters. */
197 Lisp_Object Vw32_capslock_is_shiftlock
;
199 /* Control whether right-alt and left-ctrl should be recognized as AltGr. */
200 Lisp_Object Vw32_recognize_altgr
;
202 /* The scroll bar in which the last motion event occurred.
204 If the last motion event occurred in a scroll bar, we set this
205 so w32_mouse_position can know whether to report a scroll bar motion or
208 If the last motion event didn't occur in a scroll bar, we set this
209 to Qnil, to tell w32_mouse_position to return an ordinary motion event. */
210 static Lisp_Object last_mouse_scroll_bar
;
211 static int last_mouse_scroll_bar_pos
;
213 /* This is a hack. We would really prefer that w32_mouse_position would
214 return the time associated with the position it returns, but there
215 doesn't seem to be any way to wrest the time-stamp from the server
216 along with the position query. So, we just keep track of the time
217 of the last movement we received, and return that in hopes that
218 it's somewhat accurate. */
220 static Time last_mouse_movement_time
;
222 /* Incremented by w32_read_socket whenever it really tries to read
226 static int volatile input_signal_count
;
228 static int input_signal_count
;
231 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
237 /* A mask of extra modifier bits to put into every keyboard char. */
239 extern EMACS_INT extra_keyboard_modifiers
;
241 static void x_update_window_end
P_ ((struct window
*, int, int));
242 static void w32_handle_tool_bar_click
P_ ((struct frame
*,
243 struct input_event
*));
244 static void w32_define_cursor
P_ ((Window
, Cursor
));
246 void x_lower_frame
P_ ((struct frame
*));
247 void x_scroll_bar_clear
P_ ((struct frame
*));
248 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
249 void x_raise_frame
P_ ((struct frame
*));
250 void x_set_window_size
P_ ((struct frame
*, int, int, int));
251 void x_wm_set_window_state
P_ ((struct frame
*, int));
252 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
253 static void w32_initialize
P_ ((void));
254 static void x_update_end
P_ ((struct frame
*));
255 static void w32_frame_up_to_date
P_ ((struct frame
*));
256 static void w32_set_terminal_modes
P_ ((struct terminal
*));
257 static void w32_reset_terminal_modes
P_ ((struct terminal
*));
258 static void x_clear_frame
P_ ((struct frame
*));
259 static void frame_highlight
P_ ((struct frame
*));
260 static void frame_unhighlight
P_ ((struct frame
*));
261 static void x_new_focus_frame
P_ ((struct w32_display_info
*,
263 static void x_focus_changed
P_ ((int, int, struct w32_display_info
*,
264 struct frame
*, struct input_event
*));
265 static void w32_detect_focus_change
P_ ((struct w32_display_info
*,
266 W32Msg
*, struct input_event
*));
267 static void w32_frame_rehighlight
P_ ((struct frame
*));
268 static void x_frame_rehighlight
P_ ((struct w32_display_info
*));
269 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
270 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
271 enum text_cursor_kinds
));
272 static void w32_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, HDC
));
273 static BOOL my_show_window
P_ ((struct frame
*, HWND
, int));
274 static void my_set_window_pos
P_ ((HWND
, HWND
, int, int, int, int, UINT
));
275 static void my_set_focus
P_ ((struct frame
*, HWND
));
276 static void my_set_foreground_window
P_ ((HWND
));
277 static void my_destroy_window
P_ ((struct frame
*, HWND
));
279 static Lisp_Object Qvendor_specific_keysyms
;
282 /***********************************************************************
284 ***********************************************************************/
288 /* This is a function useful for recording debugging information about
289 the sequence of occurrences in this file. */
297 struct record event_record
[100];
299 int event_record_index
;
301 record_event (locus
, type
)
305 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
306 event_record_index
= 0;
308 event_record
[event_record_index
].locus
= locus
;
309 event_record
[event_record_index
].type
= type
;
310 event_record_index
++;
317 XChangeGC (void * ignore
, XGCValues
* gc
, unsigned long mask
,
320 if (mask
& GCForeground
)
321 gc
->foreground
= xgcv
->foreground
;
322 if (mask
& GCBackground
)
323 gc
->background
= xgcv
->background
;
325 gc
->font
= xgcv
->font
;
328 XGCValues
*XCreateGC (void * ignore
, Window window
, unsigned long mask
,
331 XGCValues
*gc
= (XGCValues
*) xmalloc (sizeof (XGCValues
));
332 bzero (gc
, sizeof (XGCValues
));
334 XChangeGC (ignore
, gc
, mask
, xgcv
);
340 XGetGCValues (void* ignore
, XGCValues
*gc
,
341 unsigned long mask
, XGCValues
*xgcv
)
343 XChangeGC (ignore
, xgcv
, mask
, gc
);
347 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
351 HRGN clip_region
= CreateRectRgnIndirect (rect
);
352 SelectClipRgn (hdc
, clip_region
);
353 DeleteObject (clip_region
);
356 SelectClipRgn (hdc
, NULL
);
360 /* Draw a hollow rectangle at the specified position. */
362 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
363 int width
, int height
)
368 hb
= CreateSolidBrush (gc
->background
);
369 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
370 oldhb
= SelectObject (hdc
, hb
);
371 oldhp
= SelectObject (hdc
, hp
);
373 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
375 SelectObject (hdc
, oldhb
);
376 SelectObject (hdc
, oldhp
);
381 /* Draw a filled rectangle at the specified position. */
383 w32_fill_rect (f
, hdc
, pix
, lprect
)
391 hb
= CreateSolidBrush (pix
);
392 FillRect (hdc
, lprect
, hb
);
401 HDC hdc
= get_frame_dc (f
);
403 /* Under certain conditions, this can be called at startup with
404 a console frame pointer before the GUI frame is created. An HDC
405 of 0 indicates this. */
408 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
409 w32_clear_rect (f
, hdc
, &rect
);
412 release_frame_dc (f
, hdc
);
415 #define OPAQUE_FRAME 255
418 x_set_frame_alpha (f
)
421 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
423 double alpha_min
= 1.0;
426 HWND window
= FRAME_W32_WINDOW (f
);
428 /* Older versions of Windows do not support transparency. */
429 if (!pfnSetLayeredWindowAttributes
)
432 if (dpyinfo
->x_highlight_frame
== f
)
437 if (FLOATP (Vframe_alpha_lower_limit
))
438 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
439 else if (INTEGERP (Vframe_alpha_lower_limit
))
440 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
444 else if (alpha
> 1.0)
446 else if (alpha
< alpha_min
&& alpha_min
<= 1.0)
449 opac
= alpha
* OPAQUE_FRAME
;
451 ex_style
= GetWindowLong (window
, GWL_EXSTYLE
);
453 if (opac
== OPAQUE_FRAME
)
454 ex_style
&= ~WS_EX_LAYERED
;
456 ex_style
|= WS_EX_LAYERED
;
458 SetWindowLong (window
, GWL_EXSTYLE
, ex_style
);
460 if (opac
!= OPAQUE_FRAME
)
461 pfnSetLayeredWindowAttributes (window
, 0, opac
, LWA_ALPHA
);
465 x_display_pixel_height (dpyinfo
)
466 struct w32_display_info
*dpyinfo
;
468 return GetDeviceCaps (GetDC (GetDesktopWindow ()), VERTRES
);
472 x_display_pixel_width (dpyinfo
)
473 struct w32_display_info
*dpyinfo
;
475 return GetDeviceCaps (GetDC (GetDesktopWindow ()), HORZRES
);
479 /***********************************************************************
480 Starting and ending an update
481 ***********************************************************************/
483 /* Start an update of frame F. This function is installed as a hook
484 for update_begin, i.e. it is called when update_begin is called.
485 This function is called prior to calls to x_update_window_begin for
486 each window being updated. */
492 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
494 if (! FRAME_W32_P (f
))
497 /* Regenerate display palette before drawing if list of requested
498 colors has changed. */
499 if (display_info
->regen_palette
)
501 w32_regenerate_palette (f
);
502 display_info
->regen_palette
= FALSE
;
507 /* Start update of window W. Set the global variable updated_window
508 to the window being updated and set output_cursor to the cursor
512 x_update_window_begin (w
)
515 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
516 struct w32_display_info
*display_info
= FRAME_W32_DISPLAY_INFO (f
);
518 /* Hide the system caret during an update. */
519 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
521 SendMessage (w32_system_caret_hwnd
, WM_EMACS_HIDE_CARET
, 0, 0);
525 set_output_cursor (&w
->cursor
);
529 if (f
== display_info
->mouse_face_mouse_frame
)
531 /* Don't do highlighting for mouse motion during the update. */
532 display_info
->mouse_face_defer
= 1;
534 /* If F needs to be redrawn, simply forget about any prior mouse
536 if (FRAME_GARBAGED_P (f
))
537 display_info
->mouse_face_window
= Qnil
;
539 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
540 their mouse_face_p flag set, which means that they are always
541 unequal to rows in a desired matrix which never have that
542 flag set. So, rows containing mouse-face glyphs are never
543 scrolled, and we don't have to switch the mouse highlight off
544 here to prevent it from being scrolled. */
546 /* Can we tell that this update does not affect the window
547 where the mouse highlight is? If so, no need to turn off.
548 Likewise, don't do anything if the frame is garbaged;
549 in that case, the frame's current matrix that we would use
550 is all wrong, and we will redisplay that line anyway. */
551 if (!NILP (display_info
->mouse_face_window
)
552 && w
== XWINDOW (display_info
->mouse_face_window
))
556 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
557 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
560 if (i
< w
->desired_matrix
->nrows
)
561 clear_mouse_face (display_info
);
569 /* Draw a vertical window border from (x,y0) to (x,y1) */
572 w32_draw_vertical_window_border (w
, x
, y0
, y1
)
576 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
586 hdc
= get_frame_dc (f
);
587 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
589 w32_fill_rect (f
, hdc
, face
->foreground
, &r
);
591 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
593 release_frame_dc (f
, hdc
);
597 /* End update of window W (which is equal to updated_window).
599 Draw vertical borders between horizontally adjacent windows, and
600 display W's cursor if CURSOR_ON_P is non-zero.
602 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
603 glyphs in mouse-face were overwritten. In that case we have to
604 make sure that the mouse-highlight is properly redrawn.
606 W may be a menu bar pseudo-window in case we don't have X toolkit
607 support. Such windows don't have a cursor, so don't display it
611 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
613 int cursor_on_p
, mouse_face_overwritten_p
;
615 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (XFRAME (w
->frame
));
617 if (!w
->pseudo_window_p
)
622 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
624 output_cursor
.x
, output_cursor
.y
);
626 if (draw_window_fringes (w
, 1))
627 x_draw_vertical_border (w
);
632 /* If a row with mouse-face was overwritten, arrange for
633 XTframe_up_to_date to redisplay the mouse highlight. */
634 if (mouse_face_overwritten_p
)
636 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
637 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
638 dpyinfo
->mouse_face_window
= Qnil
;
641 /* Unhide the caret. This won't actually show the cursor, unless it
642 was visible before the corresponding call to HideCaret in
643 x_update_window_begin. */
644 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
646 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
649 updated_window
= NULL
;
653 /* End update of frame F. This function is installed as a hook in
660 if (! FRAME_W32_P (f
))
663 /* Mouse highlight may be displayed again. */
664 FRAME_W32_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
668 /* This function is called from various places in xdisp.c whenever a
669 complete update has been performed. The global variable
670 updated_window is not available here. */
673 w32_frame_up_to_date (f
)
678 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
680 if (dpyinfo
->mouse_face_deferred_gc
681 || f
== dpyinfo
->mouse_face_mouse_frame
)
684 if (dpyinfo
->mouse_face_mouse_frame
)
685 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
686 dpyinfo
->mouse_face_mouse_x
,
687 dpyinfo
->mouse_face_mouse_y
);
688 dpyinfo
->mouse_face_deferred_gc
= 0;
695 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
696 arrow bitmaps, or clear the fringes if no bitmaps are required
697 before DESIRED_ROW is made current. The window being updated is
698 found in updated_window. This function is called from
699 update_window_line only if it is known that there are differences
700 between bitmaps to be drawn between current row and DESIRED_ROW. */
703 x_after_update_window_line (desired_row
)
704 struct glyph_row
*desired_row
;
706 struct window
*w
= updated_window
;
712 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
713 desired_row
->redraw_fringe_bitmaps_p
= 1;
715 /* When a window has disappeared, make sure that no rest of
716 full-width rows stays visible in the internal border. Could
717 check here if updated_window is the leftmost/rightmost window,
718 but I guess it's not worth doing since vertically split windows
719 are almost never used, internal border is rarely set, and the
720 overhead is very small. */
721 if (windows_or_buffers_changed
722 && desired_row
->full_width_p
723 && (f
= XFRAME (w
->frame
),
724 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
726 && (height
= desired_row
->visible_height
,
729 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
731 /* Internal border is drawn below the tool bar. */
732 if (WINDOWP (f
->tool_bar_window
)
733 && w
== XWINDOW (f
->tool_bar_window
))
738 HDC hdc
= get_frame_dc (f
);
739 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
740 w32_clear_area (f
, hdc
, FRAME_PIXEL_WIDTH (f
) - width
,
742 release_frame_dc (f
, hdc
);
749 /* Draw the bitmap WHICH in one of the left or right fringes of
750 window W. ROW is the glyph row for which to display the bitmap; it
751 determines the vertical position at which the bitmap has to be
755 w32_draw_fringe_bitmap (w
, row
, p
)
757 struct glyph_row
*row
;
758 struct draw_fringe_bitmap_params
*p
;
760 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
762 struct face
*face
= p
->face
;
765 hdc
= get_frame_dc (f
);
769 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
771 /* If the fringe is adjacent to the left (right) scroll bar of a
772 leftmost (rightmost, respectively) window, then extend its
773 background to the gap between the fringe and the bar. */
774 if ((WINDOW_LEFTMOST_P (w
)
775 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
776 || (WINDOW_RIGHTMOST_P (w
)
777 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
779 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
783 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
784 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
785 * FRAME_COLUMN_WIDTH (f
));
789 /* Bitmap fills the fringe. */
790 if (left
+ width
== p
->x
)
791 bx
= left
+ sb_width
;
792 else if (p
->x
+ p
->wd
== left
)
796 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
798 nx
= width
- sb_width
;
799 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
801 ny
= row
->visible_height
;
806 if (left
+ width
== bx
)
808 bx
= left
+ sb_width
;
809 nx
+= width
- sb_width
;
811 else if (bx
+ nx
== left
)
812 nx
+= width
- sb_width
;
817 if (bx
>= 0 && nx
> 0)
818 w32_fill_area (f
, hdc
, face
->background
, bx
, by
, nx
, ny
);
821 /* Must clip because of partially visible lines. */
822 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
825 /* Adjust position of "bottom aligned" bitmap on partially
828 int oldVH
= row
->visible_height
;
829 row
->visible_height
= p
->h
;
830 row
->y
-= rowY
- p
->y
;
831 w32_clip_to_row (w
, row
, -1, hdc
);
833 row
->visible_height
= oldVH
;
836 w32_clip_to_row (w
, row
, -1, hdc
);
838 if (p
->which
&& p
->which
< max_fringe_bmp
)
840 HBITMAP pixmap
= fringe_bmp
[p
->which
];
844 compat_hdc
= CreateCompatibleDC (hdc
);
848 horig_obj
= SelectObject (compat_hdc
, pixmap
);
850 /* Paint overlays transparently. */
853 HBRUSH h_brush
, h_orig_brush
;
855 SetTextColor (hdc
, BLACK_PIX_DEFAULT (f
));
856 SetBkColor (hdc
, WHITE_PIX_DEFAULT (f
));
857 h_brush
= CreateSolidBrush (face
->foreground
);
858 h_orig_brush
= SelectObject (hdc
, h_brush
);
860 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
861 compat_hdc
, 0, p
->dh
,
863 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
864 compat_hdc
, 0, p
->dh
,
866 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
867 compat_hdc
, 0, p
->dh
,
870 SelectObject (hdc
, h_orig_brush
);
871 DeleteObject (h_brush
);
875 SetTextColor (hdc
, face
->background
);
876 SetBkColor (hdc
, (p
->cursor_p
877 ? f
->output_data
.w32
->cursor_pixel
878 : face
->foreground
));
880 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
881 compat_hdc
, 0, p
->dh
,
885 SelectObject (compat_hdc
, horig_obj
);
886 DeleteDC (compat_hdc
);
890 w32_set_clip_rectangle (hdc
, NULL
);
892 release_frame_dc (f
, hdc
);
896 w32_define_fringe_bitmap (which
, bits
, h
, wd
)
898 unsigned short *bits
;
901 if (which
>= max_fringe_bmp
)
903 int i
= max_fringe_bmp
;
904 max_fringe_bmp
= which
+ 20;
905 fringe_bmp
= (HBITMAP
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (HBITMAP
));
906 while (i
< max_fringe_bmp
)
910 fringe_bmp
[which
] = CreateBitmap (wd
, h
, 1, 1, bits
);
914 w32_destroy_fringe_bitmap (which
)
917 if (which
>= max_fringe_bmp
)
920 if (fringe_bmp
[which
])
921 DeleteObject (fringe_bmp
[which
]);
922 fringe_bmp
[which
] = 0;
927 /* This is called when starting Emacs and when restarting after
928 suspend. When starting Emacs, no window is mapped. And nothing
929 must be done to Emacs's own window if it is suspended (though that
933 w32_set_terminal_modes (struct terminal
*term
)
937 /* This is called when exiting or suspending Emacs. Exiting will make
938 the W32 windows go away, and suspending requires no action. */
941 w32_reset_terminal_modes (struct terminal
*term
)
947 /***********************************************************************
949 ***********************************************************************/
951 /* Function prototypes of this page. */
953 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
954 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
955 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
957 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
958 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
959 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
960 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
961 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
962 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
963 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
964 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
965 static void w32_setup_relief_color
P_ ((struct frame
*, struct relief
*,
966 double, int, COLORREF
));
967 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
968 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
969 static void x_draw_image_relief
P_ ((struct glyph_string
*));
970 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
971 static void w32_draw_image_foreground_1
P_ ((struct glyph_string
*, HBITMAP
));
972 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
974 static void w32_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
975 int, int, int, int, int, int,
977 static void w32_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
978 int, int, int, RECT
*));
981 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
986 struct glyph_string
*s
;
988 if (s
->font
== FRAME_FONT (s
->f
)
989 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
990 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
992 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
995 /* Cursor on non-default face: must merge. */
999 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
1000 xgcv
.foreground
= s
->face
->background
;
1002 /* If the glyph would be invisible, try a different foreground. */
1003 if (xgcv
.foreground
== xgcv
.background
)
1004 xgcv
.foreground
= s
->face
->foreground
;
1005 if (xgcv
.foreground
== xgcv
.background
)
1006 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
1007 if (xgcv
.foreground
== xgcv
.background
)
1008 xgcv
.foreground
= s
->face
->foreground
;
1010 /* Make sure the cursor is distinct from text in this face. */
1011 if (xgcv
.background
== s
->face
->background
1012 && xgcv
.foreground
== s
->face
->foreground
)
1014 xgcv
.background
= s
->face
->foreground
;
1015 xgcv
.foreground
= s
->face
->background
;
1018 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1019 xgcv
.font
= s
->font
;
1020 mask
= GCForeground
| GCBackground
| GCFont
;
1022 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1023 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1026 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1027 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
1029 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1034 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1037 x_set_mouse_face_gc (s
)
1038 struct glyph_string
*s
;
1043 /* What face has to be used last for the mouse face? */
1044 face_id
= FRAME_W32_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1045 face
= FACE_FROM_ID (s
->f
, face_id
);
1047 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1049 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1050 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1052 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1053 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1054 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1056 /* If font in this face is same as S->font, use it. */
1057 if (s
->font
== s
->face
->font
)
1058 s
->gc
= s
->face
->gc
;
1061 /* Otherwise construct scratch_cursor_gc with values from FACE
1066 xgcv
.background
= s
->face
->background
;
1067 xgcv
.foreground
= s
->face
->foreground
;
1068 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1069 xgcv
.font
= s
->font
;
1070 mask
= GCForeground
| GCBackground
| GCFont
;
1072 if (FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1073 XChangeGC (NULL
, FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1076 FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1077 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
1079 s
->gc
= FRAME_W32_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1082 xassert (s
->gc
!= 0);
1086 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1087 Faces to use in the mode line have already been computed when the
1088 matrix was built, so there isn't much to do, here. */
1091 x_set_mode_line_face_gc (s
)
1092 struct glyph_string
*s
;
1094 s
->gc
= s
->face
->gc
;
1098 /* Set S->gc of glyph string S for drawing that glyph string. Set
1099 S->stippled_p to a non-zero value if the face of S has a stipple
1103 x_set_glyph_string_gc (s
)
1104 struct glyph_string
*s
;
1106 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1108 if (s
->hl
== DRAW_NORMAL_TEXT
)
1110 s
->gc
= s
->face
->gc
;
1111 s
->stippled_p
= s
->face
->stipple
!= 0;
1113 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1115 x_set_mode_line_face_gc (s
);
1116 s
->stippled_p
= s
->face
->stipple
!= 0;
1118 else if (s
->hl
== DRAW_CURSOR
)
1120 x_set_cursor_gc (s
);
1123 else if (s
->hl
== DRAW_MOUSE_FACE
)
1125 x_set_mouse_face_gc (s
);
1126 s
->stippled_p
= s
->face
->stipple
!= 0;
1128 else if (s
->hl
== DRAW_IMAGE_RAISED
1129 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1131 s
->gc
= s
->face
->gc
;
1132 s
->stippled_p
= s
->face
->stipple
!= 0;
1136 s
->gc
= s
->face
->gc
;
1137 s
->stippled_p
= s
->face
->stipple
!= 0;
1140 /* GC must have been set. */
1141 xassert (s
->gc
!= 0);
1145 /* Set clipping for output of glyph string S. S may be part of a mode
1146 line or menu if we don't have X toolkit support. */
1149 x_set_glyph_string_clipping (s
)
1150 struct glyph_string
*s
;
1153 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1156 w32_set_clip_rectangle (s
->hdc
, r
);
1159 HRGN full_clip
, clip1
, clip2
;
1160 clip1
= CreateRectRgnIndirect (r
);
1161 clip2
= CreateRectRgnIndirect (r
+ 1);
1162 if (CombineRgn (full_clip
, clip1
, clip2
, RGN_OR
) != ERROR
)
1164 SelectClipRgn (s
->hdc
, full_clip
);
1166 DeleteObject (clip1
);
1167 DeleteObject (clip2
);
1168 DeleteObject (full_clip
);
1173 /* Set SRC's clipping for output of glyph string DST. This is called
1174 when we are drawing DST's left_overhang or right_overhang only in
1178 x_set_glyph_string_clipping_exactly (src
, dst
)
1179 struct glyph_string
*src
, *dst
;
1184 r
.right
= r
.left
+ src
->width
;
1186 r
.bottom
= r
.top
+ src
->height
;
1189 w32_set_clip_rectangle (dst
->hdc
, &r
);
1193 Compute left and right overhang of glyph string S. */
1196 w32_compute_glyph_string_overhangs (s
)
1197 struct glyph_string
*s
;
1200 && s
->first_glyph
->type
== CHAR_GLYPH
1201 && !s
->font_not_found_p
)
1203 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1204 struct font
*font
= s
->font
;
1205 struct font_metrics metrics
;
1208 for (i
= 0; i
< s
->nchars
; i
++)
1209 code
[i
] = s
->char2b
[i
];
1210 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1211 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1212 ? metrics
.rbearing
- metrics
.width
: 0);
1213 s
->left_overhang
= metrics
.lbearing
< 0 ? -metrics
.lbearing
: 0;
1217 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1218 s
->left_overhang
= -s
->cmp
->lbearing
;
1222 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1225 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1226 struct glyph_string
*s
;
1234 /* Take clipping into account. */
1235 if (s
->gc
->clip_mask
== Rect
)
1237 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
1238 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
1239 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
1240 - s
->gc
->clip_rectangle
.left
);
1241 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
1242 - s
->gc
->clip_rectangle
.top
);
1245 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
1250 /* Draw the background of glyph_string S. If S->background_filled_p
1251 is non-zero don't draw it. FORCE_P non-zero means draw the
1252 background even if it wouldn't be drawn normally. This is used
1253 when a string preceding S draws into the background of S, or S
1254 contains the first component of a composition. */
1257 x_draw_glyph_string_background (s
, force_p
)
1258 struct glyph_string
*s
;
1261 /* Nothing to do if background has already been drawn or if it
1262 shouldn't be drawn in the first place. */
1263 if (!s
->background_filled_p
)
1265 int box_line_width
= max (s
->face
->box_line_width
, 0);
1267 #if 0 /* TODO: stipple */
1270 /* Fill background with a stipple pattern. */
1271 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1272 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1273 s
->y
+ box_line_width
,
1274 s
->background_width
,
1275 s
->height
- 2 * box_line_width
);
1276 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1277 s
->background_filled_p
= 1;
1281 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1282 || s
->font_not_found_p
1283 || s
->extends_to_end_of_line_p
1286 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1287 s
->background_width
,
1288 s
->height
- 2 * box_line_width
);
1289 s
->background_filled_p
= 1;
1295 /* Draw the foreground of glyph string S. */
1298 x_draw_glyph_string_foreground (s
)
1299 struct glyph_string
*s
;
1303 /* If first glyph of S has a left box line, start drawing the text
1304 of S to the right of that box line. */
1305 if (s
->face
->box
!= FACE_NO_BOX
1306 && s
->first_glyph
->left_box_line_p
)
1307 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1311 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1312 SetBkColor (s
->hdc
, s
->gc
->background
);
1313 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1315 /* Draw characters of S as rectangles if S's font could not be
1317 if (s
->font_not_found_p
)
1319 for (i
= 0; i
< s
->nchars
; ++i
)
1321 struct glyph
*g
= s
->first_glyph
+ i
;
1323 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1325 x
+= g
->pixel_width
;
1330 struct font
*font
= s
->font
;
1331 int boff
= font
->baseline_offset
;
1335 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1337 if (font
->vertical_centering
)
1338 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1340 y
= s
->ybase
- boff
;
1342 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1343 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1345 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1346 if (s
->face
->overstrike
)
1347 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1349 SelectObject (s
->hdc
, old_font
);
1353 /* Draw the foreground of composite glyph string S. */
1356 x_draw_composite_glyph_string_foreground (s
)
1357 struct glyph_string
*s
;
1360 struct font
*font
= s
->font
;
1362 /* If first glyph of S has a left box line, start drawing the text
1363 of S to the right of that box line. */
1364 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1365 && s
->first_glyph
->left_box_line_p
)
1366 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1370 /* S is a glyph string for a composition. S->cmp_from is the index
1371 of the first character drawn for glyphs of this composition.
1372 S->cmp_from == 0 means we are drawing the very first character of
1373 this composition. */
1375 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1376 SetBkColor (s
->hdc
, s
->gc
->background
);
1377 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1379 /* Draw a rectangle for the composition if the font for the very
1380 first character of the composition could not be loaded. */
1381 if (s
->font_not_found_p
)
1383 if (s
->cmp_from
== 0)
1384 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
1387 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1393 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1395 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1396 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1398 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1399 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1401 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1402 if (s
->face
->overstrike
)
1403 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1405 SelectObject (s
->hdc
, old_font
);
1409 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1415 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1417 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1419 glyph
= LGSTRING_GLYPH (gstring
, i
);
1420 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1421 width
+= LGLYPH_WIDTH (glyph
);
1424 int xoff
, yoff
, wadjust
;
1428 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1431 xoff
= LGLYPH_XOFF (glyph
);
1432 yoff
= LGLYPH_YOFF (glyph
);
1433 wadjust
= LGLYPH_WADJUST (glyph
);
1434 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1441 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1443 SelectObject (s
->hdc
, old_font
);
1448 /* Brightness beyond which a color won't have its highlight brightness
1451 Nominally, highlight colors for `3d' faces are calculated by
1452 brightening an object's color by a constant scale factor, but this
1453 doesn't yield good results for dark colors, so for colors who's
1454 brightness is less than this value (on a scale of 0-255) have to
1455 use an additional additive factor.
1457 The value here is set so that the default menu-bar/mode-line color
1458 (grey75) will not have its highlights changed at all. */
1459 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
1462 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
1463 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1464 If this produces the same color as COLOR, try a color where all RGB
1465 values have DELTA added. Return the allocated color in *COLOR.
1466 DISPLAY is the X display, CMAP is the colormap to operate on.
1467 Value is non-zero if successful. */
1470 w32_alloc_lighter_color (f
, color
, factor
, delta
)
1479 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
1482 /* Change RGB values by specified FACTOR. Avoid overflow! */
1483 xassert (factor
>= 0);
1484 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
1485 min (0xff, factor
* GetGValue (*color
)),
1486 min (0xff, factor
* GetBValue (*color
)));
1488 /* Calculate brightness of COLOR. */
1489 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
1490 + GetBValue (*color
)) / 6;
1492 /* We only boost colors that are darker than
1493 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1494 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1495 /* Make an additive adjustment to NEW, because it's dark enough so
1496 that scaling by FACTOR alone isn't enough. */
1498 /* How far below the limit this color is (0 - 1, 1 being darker). */
1499 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1500 /* The additive adjustment. */
1501 int min_delta
= delta
* dimness
* factor
/ 2;
1504 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
1505 max (0, min (0xff, min_delta
- GetGValue (*color
))),
1506 max (0, min (0xff, min_delta
- GetBValue (*color
))));
1508 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
1509 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
1510 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
1514 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
1515 max (0, min (0xff, delta
+ GetGValue (*color
))),
1516 max (0, min (0xff, delta
+ GetBValue (*color
))));
1518 /* TODO: Map to palette and retry with delta if same? */
1519 /* TODO: Free colors (if using palette)? */
1530 /* Set up the foreground color for drawing relief lines of glyph
1531 string S. RELIEF is a pointer to a struct relief containing the GC
1532 with which lines will be drawn. Use a color that is FACTOR or
1533 DELTA lighter or darker than the relief's background which is found
1534 in S->f->output_data.x->relief_background. If such a color cannot
1535 be allocated, use DEFAULT_PIXEL, instead. */
1538 w32_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1540 struct relief
*relief
;
1543 COLORREF default_pixel
;
1546 struct w32_output
*di
= f
->output_data
.w32
;
1547 unsigned long mask
= GCForeground
;
1549 COLORREF background
= di
->relief_background
;
1550 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
1552 /* TODO: Free colors (if using palette)? */
1554 /* Allocate new color. */
1555 xgcv
.foreground
= default_pixel
;
1557 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
1559 relief
->allocated_p
= 1;
1560 xgcv
.foreground
= relief
->pixel
= pixel
;
1563 if (relief
->gc
== 0)
1565 #if 0 /* TODO: stipple */
1566 xgcv
.stipple
= dpyinfo
->gray
;
1569 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
1572 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
1576 /* Set up colors for the relief lines around glyph string S. */
1579 x_setup_relief_colors (s
)
1580 struct glyph_string
*s
;
1582 struct w32_output
*di
= s
->f
->output_data
.w32
;
1585 if (s
->face
->use_box_color_for_shadows_p
)
1586 color
= s
->face
->box_color
;
1587 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1589 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1590 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1592 color
= s
->gc
->background
;
1594 if (di
->white_relief
.gc
== 0
1595 || color
!= di
->relief_background
)
1597 di
->relief_background
= color
;
1598 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1599 WHITE_PIX_DEFAULT (s
->f
));
1600 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1601 BLACK_PIX_DEFAULT (s
->f
));
1606 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1607 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1608 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1609 relief. LEFT_P non-zero means draw a relief on the left side of
1610 the rectangle. RIGHT_P non-zero means draw a relief on the right
1611 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1615 w32_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
1616 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
1618 int left_x
, top_y
, right_x
, bottom_y
, width
;
1619 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
1624 HDC hdc
= get_frame_dc (f
);
1627 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1629 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1631 w32_set_clip_rectangle (hdc
, clip_rect
);
1635 for (i
= 0; i
< width
; ++i
)
1636 w32_fill_area (f
, hdc
, gc
.foreground
,
1637 left_x
+ i
* left_p
, top_y
+ i
,
1638 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1642 for (i
= 0; i
< width
; ++i
)
1643 w32_fill_area (f
, hdc
, gc
.foreground
,
1644 left_x
+ i
, top_y
+ i
, 1,
1645 bottom_y
- top_y
- 2 * i
+ 1);
1648 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1650 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1654 for (i
= 0; i
< width
; ++i
)
1655 w32_fill_area (f
, hdc
, gc
.foreground
,
1656 left_x
+ i
* left_p
, bottom_y
- i
,
1657 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1661 for (i
= 0; i
< width
; ++i
)
1662 w32_fill_area (f
, hdc
, gc
.foreground
,
1663 right_x
- i
, top_y
+ i
+ 1, 1,
1664 bottom_y
- top_y
- 2 * i
- 1);
1666 w32_set_clip_rectangle (hdc
, NULL
);
1668 release_frame_dc (f
, hdc
);
1672 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1673 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1674 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
1675 left side of the rectangle. RIGHT_P non-zero means draw a line
1676 on the right side of the rectangle. CLIP_RECT is the clipping
1677 rectangle to use when drawing. */
1680 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
1681 left_p
, right_p
, clip_rect
)
1682 struct glyph_string
*s
;
1683 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
1686 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
1689 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1690 left_x
, top_y
, right_x
- left_x
+ 1, width
);
1695 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1696 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
1700 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1701 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
1706 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1707 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
1710 w32_set_clip_rectangle (s
->hdc
, NULL
);
1714 /* Draw a box around glyph string S. */
1717 x_draw_glyph_string_box (s
)
1718 struct glyph_string
*s
;
1720 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
1721 int left_p
, right_p
;
1722 struct glyph
*last_glyph
;
1725 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
1726 ? WINDOW_RIGHT_EDGE_X (s
->w
)
1727 : window_box_right (s
->w
, s
->area
));
1729 /* The glyph that may have a right box line. */
1730 last_glyph
= (s
->cmp
|| s
->img
1732 : s
->first_glyph
+ s
->nchars
- 1);
1734 width
= eabs (s
->face
->box_line_width
);
1735 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
1737 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
1739 : min (last_x
, s
->x
+ s
->background_width
) - 1));
1741 bottom_y
= top_y
+ s
->height
- 1;
1743 left_p
= (s
->first_glyph
->left_box_line_p
1744 || (s
->hl
== DRAW_MOUSE_FACE
1746 || s
->prev
->hl
!= s
->hl
)));
1747 right_p
= (last_glyph
->right_box_line_p
1748 || (s
->hl
== DRAW_MOUSE_FACE
1750 || s
->next
->hl
!= s
->hl
)));
1752 get_glyph_string_clip_rect (s
, &clip_rect
);
1754 if (s
->face
->box
== FACE_SIMPLE_BOX
)
1755 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
1756 left_p
, right_p
, &clip_rect
);
1759 x_setup_relief_colors (s
);
1760 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
1761 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
1766 /* Draw foreground of image glyph string S. */
1769 x_draw_image_foreground (s
)
1770 struct glyph_string
*s
;
1773 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1775 /* If first glyph of S has a left box line, start drawing it to the
1776 right of that line. */
1777 if (s
->face
->box
!= FACE_NO_BOX
1778 && s
->first_glyph
->left_box_line_p
1780 x
+= eabs (s
->face
->box_line_width
);
1782 /* If there is a margin around the image, adjust x- and y-position
1784 if (s
->slice
.x
== 0)
1785 x
+= s
->img
->hmargin
;
1786 if (s
->slice
.y
== 0)
1787 y
+= s
->img
->vmargin
;
1793 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
1794 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1795 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
1796 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1797 SetBkColor (compat_hdc
, RGB (255, 255, 255));
1798 SetTextColor (s
->hdc
, RGB (0, 0, 0));
1799 x_set_glyph_string_clipping (s
);
1803 HDC mask_dc
= CreateCompatibleDC (s
->hdc
);
1804 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1806 SetTextColor (s
->hdc
, RGB (255, 255, 255));
1807 SetBkColor (s
->hdc
, RGB (0, 0, 0));
1809 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1810 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1811 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1812 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
1813 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1814 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1816 SelectObject (mask_dc
, mask_orig_obj
);
1821 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1822 SetBkColor (s
->hdc
, s
->gc
->background
);
1824 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1825 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
1827 /* When the image has a mask, we can expect that at
1828 least part of a mouse highlight or a block cursor will
1829 be visible. If the image doesn't have a mask, make
1830 a block cursor visible by drawing a rectangle around
1831 the image. I believe it's looking better if we do
1832 nothing here for mouse-face. */
1833 if (s
->hl
== DRAW_CURSOR
)
1835 int r
= s
->img
->relief
;
1837 w32_draw_rectangle (s
->hdc
, s
->gc
, x
- r
, y
- r
,
1838 s
->slice
.width
+ r
*2 - 1,
1839 s
->slice
.height
+ r
*2 - 1);
1843 w32_set_clip_rectangle (s
->hdc
, NULL
);
1844 SelectObject (s
->hdc
, orig_brush
);
1845 DeleteObject (fg_brush
);
1846 SelectObject (compat_hdc
, orig_obj
);
1847 DeleteDC (compat_hdc
);
1850 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
,
1851 s
->slice
.width
- 1, s
->slice
.height
- 1);
1853 RestoreDC (s
->hdc
,-1);
1857 /* Draw a relief around the image glyph string S. */
1860 x_draw_image_relief (s
)
1861 struct glyph_string
*s
;
1863 int x0
, y0
, x1
, y1
, thick
, raised_p
;
1866 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1868 /* If first glyph of S has a left box line, start drawing it to the
1869 right of that line. */
1870 if (s
->face
->box
!= FACE_NO_BOX
1871 && s
->first_glyph
->left_box_line_p
1873 x
+= eabs (s
->face
->box_line_width
);
1875 /* If there is a margin around the image, adjust x- and y-position
1877 if (s
->slice
.x
== 0)
1878 x
+= s
->img
->hmargin
;
1879 if (s
->slice
.y
== 0)
1880 y
+= s
->img
->vmargin
;
1882 if (s
->hl
== DRAW_IMAGE_SUNKEN
1883 || s
->hl
== DRAW_IMAGE_RAISED
)
1885 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
1886 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
1890 thick
= eabs (s
->img
->relief
);
1891 raised_p
= s
->img
->relief
> 0;
1896 x1
= x
+ s
->slice
.width
+ thick
- 1;
1897 y1
= y
+ s
->slice
.height
+ thick
- 1;
1899 x_setup_relief_colors (s
);
1900 get_glyph_string_clip_rect (s
, &r
);
1901 w32_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
1903 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
1905 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
1910 /* Draw the foreground of image glyph string S to PIXMAP. */
1913 w32_draw_image_foreground_1 (s
, pixmap
)
1914 struct glyph_string
*s
;
1917 HDC hdc
= CreateCompatibleDC (s
->hdc
);
1918 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
1920 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1922 /* If first glyph of S has a left box line, start drawing it to the
1923 right of that line. */
1924 if (s
->face
->box
!= FACE_NO_BOX
1925 && s
->first_glyph
->left_box_line_p
1927 x
+= eabs (s
->face
->box_line_width
);
1929 /* If there is a margin around the image, adjust x- and y-position
1931 if (s
->slice
.x
== 0)
1932 x
+= s
->img
->hmargin
;
1933 if (s
->slice
.y
== 0)
1934 y
+= s
->img
->vmargin
;
1938 HDC compat_hdc
= CreateCompatibleDC (hdc
);
1939 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1940 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
1941 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1945 HDC mask_dc
= CreateCompatibleDC (hdc
);
1946 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1948 SetTextColor (hdc
, RGB (0, 0, 0));
1949 SetBkColor (hdc
, RGB (255, 255, 255));
1950 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1951 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1952 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1953 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
1954 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1955 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1957 SelectObject (mask_dc
, mask_orig_obj
);
1962 SetTextColor (hdc
, s
->gc
->foreground
);
1963 SetBkColor (hdc
, s
->gc
->background
);
1965 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1966 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
1968 /* When the image has a mask, we can expect that at
1969 least part of a mouse highlight or a block cursor will
1970 be visible. If the image doesn't have a mask, make
1971 a block cursor visible by drawing a rectangle around
1972 the image. I believe it's looking better if we do
1973 nothing here for mouse-face. */
1974 if (s
->hl
== DRAW_CURSOR
)
1976 int r
= s
->img
->relief
;
1978 w32_draw_rectangle (hdc
, s
->gc
, x
- r
, y
- r
,
1979 s
->slice
.width
+ r
*2 - 1,
1980 s
->slice
.height
+ r
*2 - 1);
1984 SelectObject (hdc
, orig_brush
);
1985 DeleteObject (fg_brush
);
1986 SelectObject (compat_hdc
, orig_obj
);
1987 DeleteDC (compat_hdc
);
1990 w32_draw_rectangle (hdc
, s
->gc
, x
, y
,
1991 s
->slice
.width
- 1, s
->slice
.height
- 1);
1993 SelectObject (hdc
, orig_hdc_obj
);
1998 /* Draw part of the background of glyph string S. X, Y, W, and H
1999 give the rectangle to draw. */
2002 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2003 struct glyph_string
*s
;
2006 #if 0 /* TODO: stipple */
2009 /* Fill background with a stipple pattern. */
2010 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2011 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2012 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2016 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2020 /* Draw image glyph string S.
2023 s->x +-------------------------
2026 | +-------------------------
2029 | | +-------------------
2035 x_draw_image_glyph_string (s
)
2036 struct glyph_string
*s
;
2039 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2040 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2044 height
= s
->height
- 2 * box_line_vwidth
;
2046 /* Fill background with face under the image. Do it only if row is
2047 taller than image or if image has a clip mask to reduce
2049 s
->stippled_p
= s
->face
->stipple
!= 0;
2050 if (height
> s
->slice
.height
2054 || s
->img
->pixmap
== 0
2055 || s
->width
!= s
->background_width
)
2058 if (s
->first_glyph
->left_box_line_p
2060 x
+= box_line_hwidth
;
2063 if (s
->slice
.y
== 0)
2064 y
+= box_line_vwidth
;
2066 #if 0 /* TODO: figure out if we need to do this on Windows. */
2069 /* Create a pixmap as large as the glyph string. Fill it
2070 with the background color. Copy the image to it, using
2071 its mask. Copy the temporary pixmap to the display. */
2072 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2073 int depth
= DefaultDepthOfScreen (screen
);
2075 /* Create a pixmap as large as the glyph string. */
2076 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2077 s
->background_width
,
2080 /* Don't clip in the following because we're working on the
2082 XSetClipMask (s
->display
, s
->gc
, None
);
2084 /* Fill the pixmap with the background color/stipple. */
2087 /* Fill background with a stipple pattern. */
2088 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2089 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2090 0, 0, s
->background_width
, s
->height
);
2091 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2096 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2098 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2099 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2100 0, 0, s
->background_width
, s
->height
);
2101 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2106 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2108 s
->background_filled_p
= 1;
2111 /* Draw the foreground. */
2114 w32_draw_image_foreground_1 (s
, pixmap
);
2115 x_set_glyph_string_clipping (s
);
2117 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
2118 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
2119 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
2120 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
2122 SetTextColor (s
->hdc
, s
->gc
->foreground
);
2123 SetBkColor (s
->hdc
, s
->gc
->background
);
2124 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
2125 compat_hdc
, 0, 0, SRCCOPY
);
2127 SelectObject (s
->hdc
, orig_brush
);
2128 DeleteObject (fg_brush
);
2129 SelectObject (compat_hdc
, orig_obj
);
2130 DeleteDC (compat_hdc
);
2132 DeleteObject (pixmap
);
2136 x_draw_image_foreground (s
);
2138 /* If we must draw a relief around the image, do it. */
2140 || s
->hl
== DRAW_IMAGE_RAISED
2141 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2142 x_draw_image_relief (s
);
2146 /* Draw stretch glyph string S. */
2149 x_draw_stretch_glyph_string (s
)
2150 struct glyph_string
*s
;
2152 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2154 if (s
->hl
== DRAW_CURSOR
2155 && !x_stretch_cursor_p
)
2157 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2158 as wide as the stretch glyph. */
2159 int width
, background_width
= s
->background_width
;
2160 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2164 background_width
-= left_x
- x
;
2167 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2170 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2172 /* Clear rest using the GC of the original non-cursor face. */
2173 if (width
< background_width
)
2175 XGCValues
*gc
= s
->face
->gc
;
2177 int w
= background_width
- width
, h
= s
->height
;
2182 if (s
->row
->mouse_face_p
2183 && cursor_in_mouse_face_p (s
->w
))
2185 x_set_mouse_face_gc (s
);
2191 get_glyph_string_clip_rect (s
, &r
);
2192 w32_set_clip_rectangle (hdc
, &r
);
2194 #if 0 /* TODO: stipple */
2195 if (s
->face
->stipple
)
2197 /* Fill background with a stipple pattern. */
2198 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2199 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2200 XSetFillStyle (s
->display
, gc
, FillSolid
);
2205 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
2209 else if (!s
->background_filled_p
)
2211 int background_width
= s
->background_width
;
2212 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2214 /* Don't draw into left margin, fringe or scrollbar area
2215 except for header line and mode line. */
2216 if (x
< left_x
&& !s
->row
->mode_line_p
)
2218 background_width
-= left_x
- x
;
2221 if (background_width
> 0)
2222 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2225 s
->background_filled_p
= 1;
2229 /* Draw glyph string S. */
2232 x_draw_glyph_string (s
)
2233 struct glyph_string
*s
;
2235 int relief_drawn_p
= 0;
2237 /* If S draws into the background of its successor, draw the
2238 background of the successor first so that S can draw into it.
2239 This makes S->next use XDrawString instead of XDrawImageString. */
2240 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2243 struct glyph_string
*next
;
2244 for (width
= 0, next
= s
->next
; next
;
2245 width
+= next
->width
, next
= next
->next
)
2246 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2248 x_set_glyph_string_gc (next
);
2249 x_set_glyph_string_clipping (next
);
2250 x_draw_glyph_string_background (next
, 1);
2251 next
->num_clips
= 0;
2255 /* Set up S->gc, set clipping and draw S. */
2256 x_set_glyph_string_gc (s
);
2258 /* Draw relief (if any) in advance for char/composition so that the
2259 glyph string can be drawn over it. */
2260 if (!s
->for_overlaps
2261 && s
->face
->box
!= FACE_NO_BOX
2262 && (s
->first_glyph
->type
== CHAR_GLYPH
2263 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2266 x_set_glyph_string_clipping (s
);
2267 x_draw_glyph_string_background (s
, 1);
2268 x_draw_glyph_string_box (s
);
2269 x_set_glyph_string_clipping (s
);
2272 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2274 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2275 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2276 /* We must clip just this glyph. left_overhang part has already
2277 drawn when s->prev was drawn, and right_overhang part will be
2278 drawn later when s->next is drawn. */
2279 x_set_glyph_string_clipping_exactly (s
, s
);
2281 x_set_glyph_string_clipping (s
);
2283 switch (s
->first_glyph
->type
)
2286 x_draw_image_glyph_string (s
);
2290 x_draw_stretch_glyph_string (s
);
2294 if (s
->for_overlaps
)
2295 s
->background_filled_p
= 1;
2297 x_draw_glyph_string_background (s
, 0);
2298 x_draw_glyph_string_foreground (s
);
2301 case COMPOSITE_GLYPH
:
2302 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2303 && ! s
->first_glyph
->u
.cmp
.automatic
))
2304 s
->background_filled_p
= 1;
2306 x_draw_glyph_string_background (s
, 1);
2307 x_draw_composite_glyph_string_foreground (s
);
2314 if (!s
->for_overlaps
)
2316 /* Draw underline. */
2317 if (s
->face
->underline_p
)
2319 unsigned long thickness
, position
;
2322 if (s
->prev
&& s
->prev
->face
->underline_p
)
2324 /* We use the same underline style as the previous one. */
2325 thickness
= s
->prev
->underline_thickness
;
2326 position
= s
->prev
->underline_position
;
2330 /* Get the underline thickness. Default is 1 pixel. */
2331 if (s
->font
&& s
->font
->underline_thickness
> 0)
2332 thickness
= s
->font
->underline_thickness
;
2335 if (x_underline_at_descent_line
)
2336 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2339 /* Get the underline position. This is the recommended
2340 vertical offset in pixels from the baseline to the top of
2341 the underline. This is a signed value according to the
2342 specs, and its default is
2344 ROUND ((maximum_descent) / 2), with
2345 ROUND (x) = floor (x + 0.5) */
2347 if (x_use_underline_position_properties
2348 && s
->font
&& s
->font
->underline_position
>= 0)
2349 position
= s
->font
->underline_position
;
2351 position
= (s
->font
->descent
+ 1) / 2;
2353 position
= max (position
, underline_minimum_offset
);
2355 /* Check the sanity of thickness and position. We should
2356 avoid drawing underline out of the current line area. */
2357 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2358 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2359 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2360 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2361 s
->underline_thickness
= thickness
;
2362 s
->underline_position
=position
;
2363 y
= s
->ybase
+ position
;
2364 if (s
->face
->underline_defaulted_p
)
2366 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2367 y
, s
->background_width
, 1);
2371 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
2372 y
, s
->background_width
, 1);
2375 /* Draw overline. */
2376 if (s
->face
->overline_p
)
2378 unsigned long dy
= 0, h
= 1;
2380 if (s
->face
->overline_color_defaulted_p
)
2382 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2383 s
->y
+ dy
, s
->background_width
, h
);
2387 w32_fill_area (s
->f
, s
->hdc
, s
->face
->overline_color
, s
->x
,
2388 s
->y
+ dy
, s
->background_width
, h
);
2392 /* Draw strike-through. */
2393 if (s
->face
->strike_through_p
2394 && !FONT_TEXTMETRIC(s
->font
).tmStruckOut
)
2396 unsigned long h
= 1;
2397 unsigned long dy
= (s
->height
- h
) / 2;
2399 if (s
->face
->strike_through_color_defaulted_p
)
2401 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
2406 w32_fill_area (s
->f
, s
->hdc
, s
->face
->strike_through_color
, s
->x
,
2407 s
->y
+ dy
, s
->width
, h
);
2411 /* Draw relief if not yet drawn. */
2412 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2413 x_draw_glyph_string_box (s
);
2417 struct glyph_string
*prev
;
2419 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2420 if (prev
->hl
!= s
->hl
2421 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2423 /* As prev was drawn while clipped to its own area, we
2424 must draw the right_overhang part using s->hl now. */
2425 enum draw_glyphs_face save
= prev
->hl
;
2428 x_set_glyph_string_gc (prev
);
2429 x_set_glyph_string_clipping_exactly (s
, prev
);
2430 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2431 x_draw_glyph_string_foreground (prev
);
2433 x_draw_composite_glyph_string_foreground (prev
);
2434 w32_set_clip_rectangle (prev
->hdc
, NULL
);
2436 prev
->num_clips
= 0;
2442 struct glyph_string
*next
;
2444 for (next
= s
->next
; next
; next
= next
->next
)
2445 if (next
->hl
!= s
->hl
2446 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2448 /* As next will be drawn while clipped to its own area,
2449 we must draw the left_overhang part using s->hl now. */
2450 enum draw_glyphs_face save
= next
->hl
;
2453 x_set_glyph_string_gc (next
);
2454 x_set_glyph_string_clipping_exactly (s
, next
);
2455 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2456 x_draw_glyph_string_foreground (next
);
2458 x_draw_composite_glyph_string_foreground (next
);
2459 w32_set_clip_rectangle (next
->hdc
, NULL
);
2461 next
->num_clips
= 0;
2466 /* Reset clipping. */
2467 w32_set_clip_rectangle (s
->hdc
, NULL
);
2472 /* Shift display to make room for inserted glyphs. */
2475 w32_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2477 int x
, y
, width
, height
, shift_by
;
2481 hdc
= get_frame_dc (f
);
2482 BitBlt (hdc
, x
+ shift_by
, y
, width
, height
,
2483 hdc
, x
, y
, SRCCOPY
);
2485 release_frame_dc (f
, hdc
);
2489 /* Delete N glyphs at the nominal cursor position. Not implemented
2493 x_delete_glyphs (f
, n
)
2497 if (! FRAME_W32_P (f
))
2504 /* Clear entire frame. If updating_frame is non-null, clear that
2505 frame. Otherwise clear the selected frame. */
2508 x_clear_frame (struct frame
*f
)
2510 if (! FRAME_W32_P (f
))
2513 /* Clearing the frame will erase any cursor, so mark them all as no
2515 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2516 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2517 output_cursor
.x
= -1;
2519 /* We don't set the output cursor here because there will always
2520 follow an explicit cursor_to. */
2523 w32_clear_window (f
);
2525 /* We have to clear the scroll bars, too. If we have changed
2526 colors or something like that, then they should be notified. */
2527 x_scroll_bar_clear (f
);
2533 /* Make audible bell. */
2536 w32_ring_bell (struct frame
*f
)
2540 if (FRAME_W32_P (f
) && visible_bell
)
2543 HWND hwnd
= FRAME_W32_WINDOW (f
);
2545 for (i
= 0; i
< 5; i
++)
2547 FlashWindow (hwnd
, TRUE
);
2550 FlashWindow (hwnd
, FALSE
);
2553 w32_sys_ring_bell (f
);
2559 /* Specify how many text lines, from the top of the window,
2560 should be affected by insert-lines and delete-lines operations.
2561 This, and those operations, are used only within an update
2562 that is bounded by calls to x_update_begin and x_update_end. */
2565 w32_set_terminal_window (n
)
2568 /* This function intentionally left blank. */
2572 /***********************************************************************
2574 ***********************************************************************/
2576 /* Perform an insert-lines or delete-lines operation, inserting N
2577 lines or deleting -N lines at vertical position VPOS. */
2580 x_ins_del_lines (f
, vpos
, n
)
2584 if (! FRAME_W32_P (f
))
2591 /* Scroll part of the display as described by RUN. */
2594 x_scroll_run (w
, run
)
2598 struct frame
*f
= XFRAME (w
->frame
);
2599 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2600 HWND hwnd
= FRAME_W32_WINDOW (f
);
2603 /* Get frame-relative bounding box of the text display area of W,
2604 without mode lines. Include in this box the left and right
2606 window_box (w
, -1, &x
, &y
, &width
, &height
);
2608 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
2609 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
2610 bottom_y
= y
+ height
;
2614 /* Scrolling up. Make sure we don't copy part of the mode
2615 line at the bottom. */
2616 if (from_y
+ run
->height
> bottom_y
)
2617 height
= bottom_y
- from_y
;
2619 height
= run
->height
;
2620 expect_dirty
= CreateRectRgn (x
, y
+ height
, x
+ width
, bottom_y
);
2624 /* Scolling down. Make sure we don't copy over the mode line.
2626 if (to_y
+ run
->height
> bottom_y
)
2627 height
= bottom_y
- to_y
;
2629 height
= run
->height
;
2630 expect_dirty
= CreateRectRgn (x
, y
, x
+ width
, to_y
);
2635 /* Cursor off. Will be switched on again in x_update_window_end. */
2642 HRGN dirty
= CreateRectRgn (0, 0, 0, 0);
2643 HRGN combined
= CreateRectRgn (0, 0, 0, 0);
2645 from
.left
= to
.left
= x
;
2646 from
.right
= to
.right
= x
+ width
;
2648 from
.bottom
= from_y
+ height
;
2650 to
.bottom
= bottom_y
;
2652 ScrollWindowEx (hwnd
, 0, to_y
- from_y
, &from
, &to
, dirty
,
2653 NULL
, SW_INVALIDATE
);
2655 /* Combine this with what we expect to be dirty. This covers the
2656 case where not all of the region we expect is actually dirty. */
2657 CombineRgn (combined
, dirty
, expect_dirty
, RGN_OR
);
2659 /* If the dirty region is not what we expected, redraw the entire frame. */
2660 if (!EqualRgn (combined
, expect_dirty
))
2661 SET_FRAME_GARBAGED (f
);
2663 DeleteObject (dirty
);
2664 DeleteObject (combined
);
2668 DeleteObject (expect_dirty
);
2673 /***********************************************************************
2675 ***********************************************************************/
2681 x_update_cursor (f
, 1);
2682 x_set_frame_alpha (f
);
2686 frame_unhighlight (f
)
2689 x_update_cursor (f
, 1);
2690 x_set_frame_alpha (f
);
2693 /* The focus has changed. Update the frames as necessary to reflect
2694 the new situation. Note that we can't change the selected frame
2695 here, because the Lisp code we are interrupting might become confused.
2696 Each event gets marked with the frame in which it occurred, so the
2697 Lisp code can tell when the switch took place by examining the events. */
2700 x_new_focus_frame (dpyinfo
, frame
)
2701 struct w32_display_info
*dpyinfo
;
2702 struct frame
*frame
;
2704 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
2706 if (frame
!= dpyinfo
->w32_focus_frame
)
2708 /* Set this before calling other routines, so that they see
2709 the correct value of w32_focus_frame. */
2710 dpyinfo
->w32_focus_frame
= frame
;
2712 if (old_focus
&& old_focus
->auto_lower
)
2713 x_lower_frame (old_focus
);
2715 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
2716 pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
2718 pending_autoraise_frame
= 0;
2721 x_frame_rehighlight (dpyinfo
);
2725 /* Handle FocusIn and FocusOut state changes for FRAME.
2726 If FRAME has focus and there exists more than one frame, puts
2727 a FOCUS_IN_EVENT into *BUFP. */
2730 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
2733 struct w32_display_info
*dpyinfo
;
2734 struct frame
*frame
;
2735 struct input_event
*bufp
;
2737 if (type
== WM_SETFOCUS
)
2739 if (dpyinfo
->w32_focus_event_frame
!= frame
)
2741 x_new_focus_frame (dpyinfo
, frame
);
2742 dpyinfo
->w32_focus_event_frame
= frame
;
2744 /* Don't stop displaying the initial startup message
2745 for a switch-frame event we don't need. */
2746 if (NILP (Vterminal_frame
)
2747 && CONSP (Vframe_list
)
2748 && !NILP (XCDR (Vframe_list
)))
2750 bufp
->kind
= FOCUS_IN_EVENT
;
2751 XSETFRAME (bufp
->frame_or_window
, frame
);
2755 frame
->output_data
.x
->focus_state
|= state
;
2757 /* TODO: IME focus? */
2759 else if (type
== WM_KILLFOCUS
)
2761 frame
->output_data
.x
->focus_state
&= ~state
;
2763 if (dpyinfo
->w32_focus_event_frame
== frame
)
2765 dpyinfo
->w32_focus_event_frame
= 0;
2766 x_new_focus_frame (dpyinfo
, 0);
2769 /* TODO: IME focus? */
2774 /* The focus may have changed. Figure out if it is a real focus change,
2775 by checking both FocusIn/Out and Enter/LeaveNotify events.
2777 Returns FOCUS_IN_EVENT event in *BUFP. */
2780 w32_detect_focus_change (dpyinfo
, event
, bufp
)
2781 struct w32_display_info
*dpyinfo
;
2783 struct input_event
*bufp
;
2785 struct frame
*frame
;
2787 frame
= x_any_window_to_frame (dpyinfo
, event
->msg
.hwnd
);
2791 /* On w32, this is only called from focus events, so no switch needed. */
2792 x_focus_changed (event
->msg
.message
,
2793 (event
->msg
.message
== WM_KILLFOCUS
?
2794 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
2795 dpyinfo
, frame
, bufp
);
2799 /* Handle an event saying the mouse has moved out of an Emacs frame. */
2802 x_mouse_leave (dpyinfo
)
2803 struct w32_display_info
*dpyinfo
;
2805 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
2808 /* The focus has changed, or we have redirected a frame's focus to
2809 another frame (this happens when a frame uses a surrogate
2810 mini-buffer frame). Shift the highlight as appropriate.
2812 The FRAME argument doesn't necessarily have anything to do with which
2813 frame is being highlighted or un-highlighted; we only use it to find
2814 the appropriate X display info. */
2817 w32_frame_rehighlight (frame
)
2818 struct frame
*frame
;
2820 if (! FRAME_W32_P (frame
))
2822 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame
));
2826 x_frame_rehighlight (dpyinfo
)
2827 struct w32_display_info
*dpyinfo
;
2829 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
2831 if (dpyinfo
->w32_focus_frame
)
2833 dpyinfo
->x_highlight_frame
2834 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
2835 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
2836 : dpyinfo
->w32_focus_frame
);
2837 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
2839 FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
) = Qnil
;
2840 dpyinfo
->x_highlight_frame
= dpyinfo
->w32_focus_frame
;
2844 dpyinfo
->x_highlight_frame
= 0;
2846 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
2849 frame_unhighlight (old_highlight
);
2850 if (dpyinfo
->x_highlight_frame
)
2851 frame_highlight (dpyinfo
->x_highlight_frame
);
2855 /* Keyboard processing - modifier keys, etc. */
2857 /* Convert a keysym to its name. */
2860 x_get_keysym_name (keysym
)
2863 /* Make static so we can always return it */
2864 static char value
[100];
2867 GetKeyNameText (keysym
, value
, 100);
2875 /* Mouse clicks and mouse movement. Rah. */
2877 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
2878 the state in PUP. XBUTTON provides extra information for extended mouse
2879 button messages. Returns FALSE if unable to parse the message. */
2881 parse_button (message
, xbutton
, pbutton
, pup
)
2892 case WM_LBUTTONDOWN
:
2900 case WM_MBUTTONDOWN
:
2901 if (NILP (Vw32_swap_mouse_buttons
))
2908 if (NILP (Vw32_swap_mouse_buttons
))
2914 case WM_RBUTTONDOWN
:
2915 if (NILP (Vw32_swap_mouse_buttons
))
2922 if (NILP (Vw32_swap_mouse_buttons
))
2928 case WM_XBUTTONDOWN
:
2929 button
= xbutton
+ 2;
2933 button
= xbutton
+ 2;
2941 if (pbutton
) *pbutton
= button
;
2947 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2949 If the event is a button press, then note that we have grabbed
2953 construct_mouse_click (result
, msg
, f
)
2954 struct input_event
*result
;
2961 parse_button (msg
->msg
.message
, HIWORD (msg
->msg
.wParam
),
2964 /* Make the event type NO_EVENT; we'll change that when we decide
2966 result
->kind
= MOUSE_CLICK_EVENT
;
2967 result
->code
= button
;
2968 result
->timestamp
= msg
->msg
.time
;
2969 result
->modifiers
= (msg
->dwModifiers
2974 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
2975 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
2976 XSETFRAME (result
->frame_or_window
, f
);
2982 construct_mouse_wheel (result
, msg
, f
)
2983 struct input_event
*result
;
2990 result
->kind
= msg
->msg
.message
== WM_MOUSEHWHEEL
? HORIZ_WHEEL_EVENT
2993 result
->timestamp
= msg
->msg
.time
;
2995 /* A WHEEL_DELTA positive value indicates that the wheel was rotated
2996 forward, away from the user (up); a negative value indicates that
2997 the wheel was rotated backward, toward the user (down). */
2998 delta
= GET_WHEEL_DELTA_WPARAM (msg
->msg
.wParam
);
3000 /* The up and down modifiers indicate if the wheel was rotated up or
3001 down based on WHEEL_DELTA value. */
3002 result
->modifiers
= (msg
->dwModifiers
3003 | ((delta
< 0 ) ? down_modifier
: up_modifier
));
3005 /* With multiple monitors, we can legitimately get negative
3006 coordinates, so cast to short to interpret them correctly. */
3007 p
.x
= (short) LOWORD (msg
->msg
.lParam
);
3008 p
.y
= (short) HIWORD (msg
->msg
.lParam
);
3009 ScreenToClient (msg
->msg
.hwnd
, &p
);
3010 XSETINT (result
->x
, p
.x
);
3011 XSETINT (result
->y
, p
.y
);
3012 XSETFRAME (result
->frame_or_window
, f
);
3018 construct_drag_n_drop (result
, msg
, f
)
3019 struct input_event
*result
;
3031 result
->kind
= DRAG_N_DROP_EVENT
;
3033 result
->timestamp
= msg
->msg
.time
;
3034 result
->modifiers
= msg
->dwModifiers
;
3036 hdrop
= (HDROP
) msg
->msg
.wParam
;
3037 DragQueryPoint (hdrop
, &p
);
3040 p
.x
= LOWORD (msg
->msg
.lParam
);
3041 p
.y
= HIWORD (msg
->msg
.lParam
);
3042 ScreenToClient (msg
->msg
.hwnd
, &p
);
3045 XSETINT (result
->x
, p
.x
);
3046 XSETINT (result
->y
, p
.y
);
3048 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
3051 for (i
= 0; i
< num_files
; i
++)
3053 len
= DragQueryFile (hdrop
, i
, NULL
, 0);
3056 name
= alloca (len
+ 1);
3057 DragQueryFile (hdrop
, i
, name
, len
+ 1);
3058 files
= Fcons (DECODE_FILE (build_string (name
)), files
);
3063 XSETFRAME (frame
, f
);
3064 result
->frame_or_window
= frame
;
3065 result
->arg
= files
;
3070 /* Function to report a mouse movement to the mainstream Emacs code.
3071 The input handler calls this.
3073 We have received a mouse movement event, which is given in *event.
3074 If the mouse is over a different glyph than it was last time, tell
3075 the mainstream emacs code by setting mouse_moved. If not, ask for
3076 another motion event, so we can check again the next time it moves. */
3078 static MSG last_mouse_motion_event
;
3079 static Lisp_Object last_mouse_motion_frame
;
3082 note_mouse_movement (frame
, msg
)
3086 int mouse_x
= LOWORD (msg
->lParam
);
3087 int mouse_y
= HIWORD (msg
->lParam
);
3089 last_mouse_movement_time
= msg
->time
;
3090 memcpy (&last_mouse_motion_event
, msg
, sizeof (last_mouse_motion_event
));
3091 XSETFRAME (last_mouse_motion_frame
, frame
);
3093 if (!FRAME_X_OUTPUT (frame
))
3096 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
3098 frame
->mouse_moved
= 1;
3099 last_mouse_scroll_bar
= Qnil
;
3100 note_mouse_highlight (frame
, -1, -1);
3101 last_mouse_glyph_frame
= 0;
3105 /* Has the mouse moved off the glyph it was on at the last sighting? */
3106 if (frame
!= last_mouse_glyph_frame
3107 || mouse_x
< last_mouse_glyph
.left
3108 || mouse_x
>= last_mouse_glyph
.right
3109 || mouse_y
< last_mouse_glyph
.top
3110 || mouse_y
>= last_mouse_glyph
.bottom
)
3112 frame
->mouse_moved
= 1;
3113 last_mouse_scroll_bar
= Qnil
;
3114 note_mouse_highlight (frame
, mouse_x
, mouse_y
);
3115 /* Remember the mouse position here, as w32_mouse_position only
3116 gets called when mouse tracking is enabled but we also need
3117 to keep track of the mouse for help_echo and highlighting at
3119 remember_mouse_glyph (frame
, mouse_x
, mouse_y
, &last_mouse_glyph
);
3120 last_mouse_glyph_frame
= frame
;
3128 /************************************************************************
3130 ************************************************************************/
3132 static struct scroll_bar
*x_window_to_scroll_bar ();
3133 static void x_scroll_bar_report_motion ();
3134 static void x_check_fullscreen
P_ ((struct frame
*));
3137 redo_mouse_highlight ()
3139 if (!NILP (last_mouse_motion_frame
)
3140 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3141 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3142 LOWORD (last_mouse_motion_event
.lParam
),
3143 HIWORD (last_mouse_motion_event
.lParam
));
3147 w32_define_cursor (window
, cursor
)
3151 PostMessage (window
, WM_EMACS_SETCURSOR
, (WPARAM
) cursor
, 0);
3153 /* Return the current position of the mouse.
3154 *fp should be a frame which indicates which display to ask about.
3156 If the mouse movement started in a scroll bar, set *fp, *bar_window,
3157 and *part to the frame, window, and scroll bar part that the mouse
3158 is over. Set *x and *y to the portion and whole of the mouse's
3159 position on the scroll bar.
3161 If the mouse movement started elsewhere, set *fp to the frame the
3162 mouse is on, *bar_window to nil, and *x and *y to the character cell
3165 Set *time to the server time-stamp for the time at which the mouse
3166 was at this position.
3168 Don't store anything if we don't have a valid set of values to report.
3170 This clears the mouse_moved flag, so we can wait for the next mouse
3174 w32_mouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3177 Lisp_Object
*bar_window
;
3178 enum scroll_bar_part
*part
;
3180 unsigned long *time
;
3186 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3187 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3192 Lisp_Object frame
, tail
;
3194 /* Clear the mouse-moved flag for every frame on this display. */
3195 FOR_EACH_FRAME (tail
, frame
)
3196 XFRAME (frame
)->mouse_moved
= 0;
3198 last_mouse_scroll_bar
= Qnil
;
3202 /* Now we have a position on the root; find the innermost window
3203 containing the pointer. */
3205 if (FRAME_W32_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3206 && FRAME_LIVE_P (last_mouse_frame
))
3208 /* If mouse was grabbed on a frame, give coords for that frame
3209 even if the mouse is now outside it. */
3210 f1
= last_mouse_frame
;
3214 /* Is window under mouse one of our frames? */
3215 f1
= x_any_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp
),
3216 WindowFromPoint (pt
));
3219 /* If not, is it one of our scroll bars? */
3222 struct scroll_bar
*bar
3223 = x_window_to_scroll_bar (WindowFromPoint (pt
));
3227 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3231 if (f1
== 0 && insist
> 0)
3232 f1
= SELECTED_FRAME ();
3236 /* Ok, we found a frame. Store all the values.
3237 last_mouse_glyph is a rectangle used to reduce the
3238 generation of mouse events. To not miss any motion
3239 events, we must divide the frame into rectangles of the
3240 size of the smallest character that could be displayed
3241 on it, i.e. into the same rectangles that matrices on
3242 the frame are divided into. */
3244 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
3245 remember_mouse_glyph (f1
, pt
.x
, pt
.y
, &last_mouse_glyph
);
3246 last_mouse_glyph_frame
= f1
;
3253 *time
= last_mouse_movement_time
;
3262 /***********************************************************************
3264 ***********************************************************************/
3266 /* Handle mouse button event on the tool-bar of frame F, at
3267 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
3271 w32_handle_tool_bar_click (f
, button_event
)
3273 struct input_event
*button_event
;
3275 int x
= XFASTINT (button_event
->x
);
3276 int y
= XFASTINT (button_event
->y
);
3278 if (button_event
->modifiers
& down_modifier
)
3279 handle_tool_bar_click (f
, x
, y
, 1, 0);
3281 handle_tool_bar_click (f
, x
, y
, 0,
3282 button_event
->modifiers
& ~up_modifier
);
3287 /***********************************************************************
3289 ***********************************************************************/
3291 /* Scroll bar support. */
3293 /* Given a window ID, find the struct scroll_bar which manages it.
3294 This can be called in GC, so we have to make sure to strip off mark
3297 static struct scroll_bar
*
3298 x_window_to_scroll_bar (window_id
)
3303 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
3305 Lisp_Object frame
, bar
, condemned
;
3307 frame
= XCAR (tail
);
3308 /* All elements of Vframe_list should be frames. */
3309 if (! FRAMEP (frame
))
3312 /* Scan this frame's scroll bar list for a scroll bar with the
3314 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3315 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3316 /* This trick allows us to search both the ordinary and
3317 condemned scroll bar lists with one loop. */
3318 ! NILP (bar
) || (bar
= condemned
,
3321 bar
= XSCROLL_BAR (bar
)->next
)
3322 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
3323 return XSCROLL_BAR (bar
);
3331 /* Set the thumb size and position of scroll bar BAR. We are currently
3332 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3335 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
)
3336 struct scroll_bar
*bar
;
3337 int portion
, position
, whole
;
3339 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
3340 /* We use the whole scroll-bar height in the calculations below, to
3341 avoid strange effects like scrolling backwards when just clicking
3342 on the handle (without moving it). */
3343 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
))
3344 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3345 int sb_page
, sb_pos
;
3346 BOOL draggingp
= !NILP (bar
->dragging
) ? TRUE
: FALSE
;
3349 /* We used to change the nPage setting while dragging the handle,
3350 but that had very strange effects (such as scrolling backwards
3351 while dragging downwards).
3353 Now, we don't change the nPage setting while dragging unless we
3354 get near to the end of the buffer, in which case we often have to
3355 resize the handle to "go all the way". */
3361 si
.cbSize
= sizeof (si
);
3362 si
.fMask
= SIF_POS
| SIF_PAGE
;
3363 GetScrollInfo(w
, SB_CTL
, &si
);
3364 near_bottom_p
= si
.nPos
+ si
.nPage
>= range
;
3372 /* Position scroll bar at rock bottom if the bottom of the
3373 buffer is visible. This avoids shinking the thumb away
3374 to nothing if it is held at the bottom of the buffer. */
3375 if (position
+ portion
>= whole
&& !draggingp
)
3377 sb_page
= range
* (whole
- position
) / whole
;
3382 sb_pos
= position
* range
/ whole
;
3383 sb_page
= (min (portion
, (whole
- position
)) * range
) / whole
;
3392 sb_page
= max (sb_page
, VERTICAL_SCROLL_BAR_MIN_HANDLE
);
3396 si
.cbSize
= sizeof (si
);
3397 si
.fMask
= SIF_PAGE
| SIF_POS
;
3401 SetScrollInfo (w
, SB_CTL
, &si
, TRUE
);
3407 /************************************************************************
3408 Scroll bars, general
3409 ************************************************************************/
3412 my_create_scrollbar (f
, bar
)
3414 struct scroll_bar
* bar
;
3416 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
3417 WM_EMACS_CREATESCROLLBAR
, (WPARAM
) f
,
3421 /*#define ATTACH_THREADS*/
3424 my_show_window (FRAME_PTR f
, HWND hwnd
, int how
)
3426 #ifndef ATTACH_THREADS
3427 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
3428 (WPARAM
) hwnd
, (LPARAM
) how
);
3430 return ShowWindow (hwnd
, how
);
3435 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
3436 int x
, int y
, int cx
, int cy
, UINT flags
)
3438 #ifndef ATTACH_THREADS
3440 pos
.hwndInsertAfter
= hwndAfter
;
3446 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
3448 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
3453 my_set_focus (f
, hwnd
)
3457 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
3462 my_set_foreground_window (hwnd
)
3465 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
3470 my_destroy_window (f
, hwnd
)
3474 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
3478 /* Create a scroll bar and return the scroll bar vector for it. W is
3479 the Emacs window on which to create the scroll bar. TOP, LEFT,
3480 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
3483 static struct scroll_bar
*
3484 x_scroll_bar_create (w
, top
, left
, width
, height
)
3486 int top
, left
, width
, height
;
3488 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3491 struct scroll_bar
*bar
3492 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
3496 XSETWINDOW (bar
->window
, w
);
3497 XSETINT (bar
->top
, top
);
3498 XSETINT (bar
->left
, left
);
3499 XSETINT (bar
->width
, width
);
3500 XSETINT (bar
->height
, height
);
3501 XSETINT (bar
->start
, 0);
3502 XSETINT (bar
->end
, 0);
3503 bar
->dragging
= Qnil
;
3504 bar
->fringe_extended_p
= Qnil
;
3506 /* Requires geometry to be set before call to create the real window */
3508 hwnd
= my_create_scrollbar (f
, bar
);
3510 si
.cbSize
= sizeof (si
);
3513 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3514 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3518 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3520 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
3522 /* Add bar to its frame's list of scroll bars. */
3523 bar
->next
= FRAME_SCROLL_BARS (f
);
3525 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
3526 if (! NILP (bar
->next
))
3527 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3535 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
3539 x_scroll_bar_remove (bar
)
3540 struct scroll_bar
*bar
;
3542 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3546 /* Destroy the window. */
3547 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
3549 /* Disassociate this scroll bar from its window. */
3550 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
3555 /* Set the handle of the vertical scroll bar for WINDOW to indicate
3556 that we are displaying PORTION characters out of a total of WHOLE
3557 characters, starting at POSITION. If WINDOW has no scroll bar,
3560 w32_set_vertical_scroll_bar (w
, portion
, whole
, position
)
3562 int portion
, whole
, position
;
3564 struct frame
*f
= XFRAME (w
->frame
);
3565 struct scroll_bar
*bar
;
3566 int top
, height
, left
, sb_left
, width
, sb_width
;
3567 int window_y
, window_height
;
3568 int fringe_extended_p
;
3570 /* Get window dimensions. */
3571 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
3573 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
3574 height
= window_height
;
3576 /* Compute the left edge of the scroll bar area. */
3577 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
3579 /* Compute the width of the scroll bar which might be less than
3580 the width of the area reserved for the scroll bar. */
3581 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
3582 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3586 /* Compute the left edge of the scroll bar. */
3587 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
3588 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
3590 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
3592 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
3593 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
3594 && WINDOW_LEFT_FRINGE_WIDTH (w
)
3595 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
3596 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
3598 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
3599 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
3600 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
3601 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
3603 /* Does the scroll bar exist yet? */
3604 if (NILP (w
->vertical_scroll_bar
))
3608 if (width
> 0 && height
> 0)
3610 hdc
= get_frame_dc (f
);
3611 if (fringe_extended_p
)
3612 w32_clear_area (f
, hdc
, sb_left
, top
, sb_width
, height
);
3614 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3615 release_frame_dc (f
, hdc
);
3619 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
3623 /* It may just need to be moved and resized. */
3626 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
3627 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
3629 /* If already correctly positioned, do nothing. */
3630 if ( XINT (bar
->left
) == sb_left
3631 && XINT (bar
->top
) == top
3632 && XINT (bar
->width
) == sb_width
3633 && XINT (bar
->height
) == height
3634 && !NILP (bar
->fringe_extended_p
) == fringe_extended_p
)
3636 /* Redraw after clear_frame. */
3637 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
3638 InvalidateRect (hwnd
, NULL
, FALSE
);
3646 if (width
&& height
)
3648 hdc
= get_frame_dc (f
);
3649 /* Since Windows scroll bars are smaller than the space reserved
3650 for them on the frame, we have to clear "under" them. */
3651 if (fringe_extended_p
)
3652 w32_clear_area (f
, hdc
, sb_left
, top
, sb_width
, height
);
3654 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3655 release_frame_dc (f
, hdc
);
3657 /* Make sure scroll bar is "visible" before moving, to ensure the
3658 area of the parent window now exposed will be refreshed. */
3659 my_show_window (f
, hwnd
, SW_HIDE
);
3660 MoveWindow (hwnd
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3661 top
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3662 max (height
, 1), TRUE
);
3664 si
.cbSize
= sizeof (si
);
3665 si
.fMask
= SIF_RANGE
;
3667 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3668 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3670 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3672 my_show_window (f
, hwnd
, SW_NORMAL
);
3673 /* InvalidateRect (w, NULL, FALSE); */
3675 /* Remember new settings. */
3676 XSETINT (bar
->left
, sb_left
);
3677 XSETINT (bar
->top
, top
);
3678 XSETINT (bar
->width
, sb_width
);
3679 XSETINT (bar
->height
, height
);
3684 bar
->fringe_extended_p
= fringe_extended_p
? Qt
: Qnil
;
3686 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
3688 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
3692 /* The following three hooks are used when we're doing a thorough
3693 redisplay of the frame. We don't explicitly know which scroll bars
3694 are going to be deleted, because keeping track of when windows go
3695 away is a real pain - "Can you say set-window-configuration, boys
3696 and girls?" Instead, we just assert at the beginning of redisplay
3697 that *all* scroll bars are to be removed, and then save a scroll bar
3698 from the fiery pit when we actually redisplay its window. */
3700 /* Arrange for all scroll bars on FRAME to be removed at the next call
3701 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
3702 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
3705 w32_condemn_scroll_bars (frame
)
3708 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
3709 while (! NILP (FRAME_SCROLL_BARS (frame
)))
3712 bar
= FRAME_SCROLL_BARS (frame
);
3713 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
3714 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
3715 XSCROLL_BAR (bar
)->prev
= Qnil
;
3716 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
3717 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
3718 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
3723 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
3724 Note that WINDOW isn't necessarily condemned at all. */
3727 w32_redeem_scroll_bar (window
)
3728 struct window
*window
;
3730 struct scroll_bar
*bar
;
3733 /* We can't redeem this window's scroll bar if it doesn't have one. */
3734 if (NILP (window
->vertical_scroll_bar
))
3737 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3739 /* Unlink it from the condemned list. */
3740 f
= XFRAME (WINDOW_FRAME (window
));
3741 if (NILP (bar
->prev
))
3743 /* If the prev pointer is nil, it must be the first in one of
3745 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
3746 /* It's not condemned. Everything's fine. */
3748 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
3749 window
->vertical_scroll_bar
))
3750 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
3752 /* If its prev pointer is nil, it must be at the front of
3753 one or the other! */
3757 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
3759 if (! NILP (bar
->next
))
3760 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
3762 bar
->next
= FRAME_SCROLL_BARS (f
);
3764 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
3765 if (! NILP (bar
->next
))
3766 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3769 /* Remove all scroll bars on FRAME that haven't been saved since the
3770 last call to `*condemn_scroll_bars_hook'. */
3773 w32_judge_scroll_bars (f
)
3776 Lisp_Object bar
, next
;
3778 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
3780 /* Clear out the condemned list now so we won't try to process any
3781 more events on the hapless scroll bars. */
3782 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
3784 for (; ! NILP (bar
); bar
= next
)
3786 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
3788 x_scroll_bar_remove (b
);
3791 b
->next
= b
->prev
= Qnil
;
3794 /* Now there should be no references to the condemned scroll bars,
3795 and they should get garbage-collected. */
3798 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
3799 is set to something other than NO_EVENT, it is enqueued.
3801 This may be called from a signal handler, so we have to ignore GC
3805 w32_scroll_bar_handle_click (bar
, msg
, emacs_event
)
3806 struct scroll_bar
*bar
;
3808 struct input_event
*emacs_event
;
3810 if (! WINDOWP (bar
->window
))
3813 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
3814 emacs_event
->code
= 0;
3815 /* not really meaningful to distinguish up/down */
3816 emacs_event
->modifiers
= msg
->dwModifiers
;
3817 emacs_event
->frame_or_window
= bar
->window
;
3818 emacs_event
->arg
= Qnil
;
3819 emacs_event
->timestamp
= msg
->msg
.time
;
3822 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3824 int dragging
= !NILP (bar
->dragging
);
3827 si
.cbSize
= sizeof (si
);
3830 GetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
3833 bar
->dragging
= Qnil
;
3836 last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
3838 switch (LOWORD (msg
->msg
.wParam
))
3841 emacs_event
->part
= scroll_bar_down_arrow
;
3844 emacs_event
->part
= scroll_bar_up_arrow
;
3847 emacs_event
->part
= scroll_bar_above_handle
;
3850 emacs_event
->part
= scroll_bar_below_handle
;
3853 emacs_event
->part
= scroll_bar_handle
;
3857 emacs_event
->part
= scroll_bar_handle
;
3861 case SB_THUMBPOSITION
:
3862 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
3863 y
= HIWORD (msg
->msg
.wParam
);
3865 emacs_event
->part
= scroll_bar_handle
;
3867 /* "Silently" update current position. */
3871 si
.cbSize
= sizeof (si
);
3874 /* Remember apparent position (we actually lag behind the real
3875 position, so don't set that directly. */
3876 last_scroll_bar_drag_pos
= y
;
3878 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
3882 /* If this is the end of a drag sequence, then reset the scroll
3883 handle size to normal and do a final redraw. Otherwise do
3888 int start
= XINT (bar
->start
);
3889 int end
= XINT (bar
->end
);
3891 si
.cbSize
= sizeof (si
);
3892 si
.fMask
= SIF_PAGE
| SIF_POS
;
3893 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3894 si
.nPos
= last_scroll_bar_drag_pos
;
3895 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
3899 emacs_event
->kind
= NO_EVENT
;
3903 XSETINT (emacs_event
->x
, y
);
3904 XSETINT (emacs_event
->y
, top_range
);
3910 /* Return information to the user about the current position of the mouse
3911 on the scroll bar. */
3914 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
3916 Lisp_Object
*bar_window
;
3917 enum scroll_bar_part
*part
;
3919 unsigned long *time
;
3921 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
3922 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
3923 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3925 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3931 *bar_window
= bar
->window
;
3933 si
.cbSize
= sizeof (si
);
3934 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
3936 GetScrollInfo (w
, SB_CTL
, &si
);
3938 top_range
= si
.nMax
- si
.nPage
+ 1;
3940 switch (LOWORD (last_mouse_scroll_bar_pos
))
3942 case SB_THUMBPOSITION
:
3944 *part
= scroll_bar_handle
;
3945 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
3946 pos
= HIWORD (last_mouse_scroll_bar_pos
);
3949 *part
= scroll_bar_handle
;
3953 *part
= scroll_bar_handle
;
3958 XSETINT (*y
, top_range
);
3961 last_mouse_scroll_bar
= Qnil
;
3963 *time
= last_mouse_movement_time
;
3969 /* The screen has been cleared so we may have changed foreground or
3970 background colors, and the scroll bars may need to be redrawn.
3971 Clear out the scroll bars, and ask for expose events, so we can
3975 x_scroll_bar_clear (f
)
3980 /* We can have scroll bars even if this is 0,
3981 if we just turned off scroll bar mode.
3982 But in that case we should not clear them. */
3983 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3984 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3985 bar
= XSCROLL_BAR (bar
)->next
)
3987 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
3988 HDC hdc
= GetDC (window
);
3991 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
3992 arranges to refresh the scroll bar if hidden. */
3993 my_show_window (f
, window
, SW_HIDE
);
3995 GetClientRect (window
, &rect
);
3996 select_palette (f
, hdc
);
3997 w32_clear_rect (f
, hdc
, &rect
);
3998 deselect_palette (f
, hdc
);
4000 ReleaseDC (window
, hdc
);
4005 /* The main W32 event-reading loop - w32_read_socket. */
4007 /* Record the last 100 characters stored
4008 to help debug the loss-of-chars-during-GC problem. */
4010 static int temp_index
;
4011 static short temp_buffer
[100];
4013 /* Temporarily store lead byte of DBCS input sequences. */
4014 static char dbcs_lead
= 0;
4016 /* Read events coming from the W32 shell.
4017 This routine is called by the SIGIO handler.
4018 We return as soon as there are no more events to be read.
4020 We return the number of characters stored into the buffer,
4021 thus pretending to be `read'.
4023 EXPECTED is nonzero if the caller knows input is available.
4025 Some of these messages are reposted back to the message queue since the
4026 system calls the windows proc directly in a context where we cannot return
4027 the data nor can we guarantee the state we are in. So if we dispatch them
4028 we will get into an infinite loop. To prevent this from ever happening we
4029 will set a variable to indicate we are in the read_socket call and indicate
4030 which message we are processing since the windows proc gets called
4031 recursively with different messages by the system.
4035 w32_read_socket (sd
, expected
, hold_quit
)
4038 struct input_event
*hold_quit
;
4041 int check_visibility
= 0;
4044 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4046 if (interrupt_input_blocked
)
4048 interrupt_input_pending
= 1;
4052 interrupt_input_pending
= 0;
4055 /* So people can tell when we have read the available input. */
4056 input_signal_count
++;
4058 /* TODO: ghostscript integration. */
4059 while (get_next_msg (&msg
, FALSE
))
4061 struct input_event inev
;
4065 inev
.kind
= NO_EVENT
;
4068 switch (msg
.msg
.message
)
4071 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4075 if (msg
.rect
.right
== msg
.rect
.left
||
4076 msg
.rect
.bottom
== msg
.rect
.top
)
4078 /* We may get paint messages even though the client
4079 area is clipped - these are not expose events. */
4080 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
4083 else if (f
->async_visible
!= 1)
4085 /* Definitely not obscured, so mark as visible. */
4086 f
->async_visible
= 1;
4087 f
->async_iconified
= 0;
4088 SET_FRAME_GARBAGED (f
);
4089 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
4092 /* WM_PAINT serves as MapNotify as well, so report
4093 visibility changes properly. */
4096 inev
.kind
= DEICONIFY_EVENT
;
4097 XSETFRAME (inev
.frame_or_window
, f
);
4099 else if (! NILP (Vframe_list
)
4100 && ! NILP (XCDR (Vframe_list
)))
4101 /* Force a redisplay sooner or later to update the
4102 frame titles in case this is the second frame. */
4103 record_asynch_buffer_change ();
4107 HDC hdc
= get_frame_dc (f
);
4109 /* Erase background again for safety. */
4110 w32_clear_rect (f
, hdc
, &msg
.rect
);
4111 release_frame_dc (f
, hdc
);
4115 msg
.rect
.right
- msg
.rect
.left
,
4116 msg
.rect
.bottom
- msg
.rect
.top
);
4121 case WM_INPUTLANGCHANGE
:
4122 /* Generate a language change event. */
4123 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4127 inev
.kind
= LANGUAGE_CHANGE_EVENT
;
4128 XSETFRAME (inev
.frame_or_window
, f
);
4129 inev
.code
= msg
.msg
.wParam
;
4130 inev
.modifiers
= msg
.msg
.lParam
& 0xffff;
4136 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4138 if (f
&& !f
->iconified
)
4140 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4141 && !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
))
4143 clear_mouse_face (dpyinfo
);
4144 dpyinfo
->mouse_face_hidden
= 1;
4147 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4149 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4150 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
4151 inev
.code
= msg
.msg
.wParam
;
4152 inev
.modifiers
= msg
.dwModifiers
;
4153 XSETFRAME (inev
.frame_or_window
, f
);
4154 inev
.timestamp
= msg
.msg
.time
;
4161 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4163 if (f
&& !f
->iconified
)
4165 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4166 && !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
))
4168 clear_mouse_face (dpyinfo
);
4169 dpyinfo
->mouse_face_hidden
= 1;
4172 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4174 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4176 inev
.modifiers
= msg
.dwModifiers
;
4177 XSETFRAME (inev
.frame_or_window
, f
);
4178 inev
.timestamp
= msg
.msg
.time
;
4180 if (msg
.msg
.message
== WM_UNICHAR
)
4182 inev
.code
= msg
.msg
.wParam
;
4184 else if (msg
.msg
.wParam
< 256)
4189 dbcs
[1] = (char) msg
.msg
.wParam
;
4193 dbcs
[0] = dbcs_lead
;
4195 if (!MultiByteToWideChar (CP_ACP
, 0, dbcs
, 2, &code
, 1))
4198 DebPrint (("Invalid DBCS sequence: %d %d\n",
4200 inev
.kind
= NO_EVENT
;
4204 else if (IsDBCSLeadByteEx (CP_ACP
, (BYTE
) msg
.msg
.wParam
))
4206 dbcs_lead
= (char) msg
.msg
.wParam
;
4207 inev
.kind
= NO_EVENT
;
4212 if (!MultiByteToWideChar (CP_ACP
, 0, &dbcs
[1], 1,
4215 /* What to do with garbage? */
4216 DebPrint (("Invalid character: %d\n", dbcs
[1]));
4217 inev
.kind
= NO_EVENT
;
4225 /* Windows shouldn't generate WM_CHAR events above 0xFF
4226 in non-Unicode message handlers. */
4227 DebPrint (("Non-byte WM_CHAR: %d\n", msg
.msg
.wParam
));
4228 inev
.kind
= NO_EVENT
;
4231 inev
.kind
= inev
.code
< 128 ? ASCII_KEYSTROKE_EVENT
4232 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
4237 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4239 if (f
&& !f
->iconified
)
4241 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4242 && !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
))
4244 clear_mouse_face (dpyinfo
);
4245 dpyinfo
->mouse_face_hidden
= 1;
4248 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4250 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4251 inev
.kind
= MULTIMEDIA_KEY_EVENT
;
4252 inev
.code
= GET_APPCOMMAND_LPARAM(msg
.msg
.lParam
);
4253 inev
.modifiers
= msg
.dwModifiers
;
4254 XSETFRAME (inev
.frame_or_window
, f
);
4255 inev
.timestamp
= msg
.msg
.time
;
4260 /* Ignore non-movement. */
4262 int x
= LOWORD (msg
.msg
.lParam
);
4263 int y
= HIWORD (msg
.msg
.lParam
);
4264 if (x
== last_mousemove_x
&& y
== last_mousemove_y
)
4266 last_mousemove_x
= x
;
4267 last_mousemove_y
= y
;
4270 previous_help_echo_string
= help_echo_string
;
4271 help_echo_string
= Qnil
;
4273 if (dpyinfo
->grabbed
&& last_mouse_frame
4274 && FRAME_LIVE_P (last_mouse_frame
))
4275 f
= last_mouse_frame
;
4277 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4279 if (dpyinfo
->mouse_face_hidden
)
4281 dpyinfo
->mouse_face_hidden
= 0;
4282 clear_mouse_face (dpyinfo
);
4287 /* Generate SELECT_WINDOW_EVENTs when needed. */
4288 if (!NILP (Vmouse_autoselect_window
))
4291 int x
= LOWORD (msg
.msg
.lParam
);
4292 int y
= HIWORD (msg
.msg
.lParam
);
4294 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 0);
4296 /* Window will be selected only when it is not
4297 selected now and last mouse movement event was
4298 not in it. Minibuffer window will be selected
4299 only when it is active. */
4301 && !EQ (window
, last_window
)
4302 && !EQ (window
, selected_window
)
4303 /* For click-to-focus window managers
4304 create event iff we don't leave the
4306 && (focus_follows_mouse
4307 || (EQ (XWINDOW (window
)->frame
,
4308 XWINDOW (selected_window
)->frame
))))
4310 inev
.kind
= SELECT_WINDOW_EVENT
;
4311 inev
.frame_or_window
= window
;
4316 if (!note_mouse_movement (f
, &msg
.msg
))
4317 help_echo_string
= previous_help_echo_string
;
4321 /* If we move outside the frame, then we're
4322 certainly no longer on any text in the frame. */
4323 clear_mouse_face (dpyinfo
);
4326 /* If the contents of the global variable help_echo_string
4327 has changed, generate a HELP_EVENT. */
4328 #if 0 /* The below is an invalid comparison when USE_LISP_UNION_TYPE.
4329 But it was originally changed to this to fix a bug, so I have
4330 not removed it completely in case the bug is still there. */
4331 if (help_echo_string
!= previous_help_echo_string
||
4332 (!NILP (help_echo_string
) && !STRINGP (help_echo_string
) && f
->mouse_moved
))
4333 #else /* This is what xterm.c does. */
4334 if (!NILP (help_echo_string
)
4335 || !NILP (previous_help_echo_string
))
4340 case WM_LBUTTONDOWN
:
4342 case WM_MBUTTONDOWN
:
4344 case WM_RBUTTONDOWN
:
4346 case WM_XBUTTONDOWN
:
4349 /* If we decide we want to generate an event to be seen
4350 by the rest of Emacs, we put it here. */
4355 if (dpyinfo
->grabbed
&& last_mouse_frame
4356 && FRAME_LIVE_P (last_mouse_frame
))
4357 f
= last_mouse_frame
;
4359 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4363 construct_mouse_click (&inev
, &msg
, f
);
4365 /* Is this in the tool-bar? */
4366 if (WINDOWP (f
->tool_bar_window
)
4367 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
4370 int x
= XFASTINT (inev
.x
);
4371 int y
= XFASTINT (inev
.y
);
4373 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
4375 if (EQ (window
, f
->tool_bar_window
))
4377 w32_handle_tool_bar_click (f
, &inev
);
4383 || (dpyinfo
->w32_focus_frame
4384 && f
!= dpyinfo
->w32_focus_frame
))
4385 inev
.kind
= NO_EVENT
;
4388 parse_button (msg
.msg
.message
, HIWORD (msg
.msg
.wParam
),
4393 dpyinfo
->grabbed
&= ~ (1 << button
);
4397 dpyinfo
->grabbed
|= (1 << button
);
4398 last_mouse_frame
= f
;
4399 /* Ignore any mouse motion that happened
4400 before this event; any subsequent mouse-movement
4401 Emacs events should reflect only motion after
4407 last_tool_bar_item
= -1;
4413 case WM_MOUSEHWHEEL
:
4415 if (dpyinfo
->grabbed
&& last_mouse_frame
4416 && FRAME_LIVE_P (last_mouse_frame
))
4417 f
= last_mouse_frame
;
4419 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4424 if (!dpyinfo
->w32_focus_frame
4425 || f
== dpyinfo
->w32_focus_frame
)
4427 /* Emit an Emacs wheel-up/down event. */
4428 construct_mouse_wheel (&inev
, &msg
, f
);
4430 /* Ignore any mouse motion that happened before this
4431 event; any subsequent mouse-movement Emacs events
4432 should reflect only motion after the
4436 last_mouse_frame
= f
;
4437 last_tool_bar_item
= -1;
4442 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4445 construct_drag_n_drop (&inev
, &msg
, f
);
4450 struct scroll_bar
*bar
=
4451 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
);
4454 w32_scroll_bar_handle_click (bar
, &msg
, &inev
);
4458 case WM_WINDOWPOSCHANGED
:
4459 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4462 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
4463 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
4465 check_visibility
= 1;
4469 case WM_ACTIVATEAPP
:
4470 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4472 x_check_fullscreen (f
);
4473 check_visibility
= 1;
4477 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4479 if (f
&& !f
->async_iconified
)
4483 x_real_positions (f
, &x
, &y
);
4488 check_visibility
= 1;
4492 /* wParam non-zero means Window is about to be shown, 0 means
4493 about to be hidden. */
4494 /* Redo the mouse-highlight after the tooltip has gone. */
4495 if (!msg
.msg
.wParam
&& msg
.msg
.hwnd
== tip_window
)
4498 redo_mouse_highlight ();
4501 /* If window has been obscured or exposed by another window
4502 being maximised or minimised/restored, then recheck
4503 visibility of all frames. Direct changes to our own
4504 windows get handled by WM_SIZE. */
4506 if (msg
.msg
.lParam
!= 0)
4507 check_visibility
= 1;
4510 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4511 f
->async_visible
= msg
.msg
.wParam
;
4515 check_visibility
= 1;
4519 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4521 /* Inform lisp of whether frame has been iconified etc. */
4524 switch (msg
.msg
.wParam
)
4526 case SIZE_MINIMIZED
:
4527 f
->async_visible
= 0;
4528 f
->async_iconified
= 1;
4530 inev
.kind
= ICONIFY_EVENT
;
4531 XSETFRAME (inev
.frame_or_window
, f
);
4534 case SIZE_MAXIMIZED
:
4536 f
->async_visible
= 1;
4537 f
->async_iconified
= 0;
4539 /* wait_reading_process_output will notice this and update
4540 the frame's display structures. */
4541 SET_FRAME_GARBAGED (f
);
4547 /* Reset top and left positions of the Window
4548 here since Windows sends a WM_MOVE message
4549 BEFORE telling us the Window is minimized
4550 when the Window is iconified, with 3000,3000
4552 x_real_positions (f
, &x
, &y
);
4556 inev
.kind
= DEICONIFY_EVENT
;
4557 XSETFRAME (inev
.frame_or_window
, f
);
4559 else if (! NILP (Vframe_list
)
4560 && ! NILP (XCDR (Vframe_list
)))
4561 /* Force a redisplay sooner or later
4562 to update the frame titles
4563 in case this is the second frame. */
4564 record_asynch_buffer_change ();
4569 if (f
&& !f
->async_iconified
&& msg
.msg
.wParam
!= SIZE_MINIMIZED
)
4577 GetClientRect (msg
.msg
.hwnd
, &rect
);
4579 height
= rect
.bottom
- rect
.top
;
4580 width
= rect
.right
- rect
.left
;
4582 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
4583 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
4585 /* TODO: Clip size to the screen dimensions. */
4587 /* Even if the number of character rows and columns has
4588 not changed, the font size may have changed, so we need
4589 to check the pixel dimensions as well. */
4591 if (columns
!= FRAME_COLS (f
)
4592 || rows
!= FRAME_LINES (f
)
4593 || width
!= FRAME_PIXEL_WIDTH (f
)
4594 || height
!= FRAME_PIXEL_HEIGHT (f
))
4596 change_frame_size (f
, rows
, columns
, 0, 1, 0);
4597 SET_FRAME_GARBAGED (f
);
4598 cancel_mouse_face (f
);
4599 FRAME_PIXEL_WIDTH (f
) = width
;
4600 FRAME_PIXEL_HEIGHT (f
) = height
;
4601 f
->win_gravity
= NorthWestGravity
;
4605 check_visibility
= 1;
4609 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4612 if (f
== dpyinfo
->mouse_face_mouse_frame
)
4614 /* If we move outside the frame, then we're
4615 certainly no longer on any text in the frame. */
4616 clear_mouse_face (dpyinfo
);
4617 dpyinfo
->mouse_face_mouse_frame
= 0;
4620 /* Generate a nil HELP_EVENT to cancel a help-echo.
4621 Do it only if there's something to cancel.
4622 Otherwise, the startup message is cleared when
4623 the mouse leaves the frame. */
4624 if (any_help_event_p
)
4630 w32_detect_focus_change (dpyinfo
, &msg
, &inev
);
4632 dpyinfo
->grabbed
= 0;
4633 check_visibility
= 1;
4637 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4641 if (f
== dpyinfo
->w32_focus_event_frame
)
4642 dpyinfo
->w32_focus_event_frame
= 0;
4644 if (f
== dpyinfo
->w32_focus_frame
)
4645 x_new_focus_frame (dpyinfo
, 0);
4647 if (f
== dpyinfo
->mouse_face_mouse_frame
)
4649 /* If we move outside the frame, then we're
4650 certainly no longer on any text in the frame. */
4651 clear_mouse_face (dpyinfo
);
4652 dpyinfo
->mouse_face_mouse_frame
= 0;
4655 /* Generate a nil HELP_EVENT to cancel a help-echo.
4656 Do it only if there's something to cancel.
4657 Otherwise, the startup message is cleared when
4658 the mouse leaves the frame. */
4659 if (any_help_event_p
)
4663 dpyinfo
->grabbed
= 0;
4664 check_visibility
= 1;
4668 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4672 inev
.kind
= DELETE_WINDOW_EVENT
;
4673 XSETFRAME (inev
.frame_or_window
, f
);
4678 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4682 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
4683 XSETFRAME (inev
.frame_or_window
, f
);
4688 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4692 extern void menubar_selection_callback
4693 (FRAME_PTR f
, void * client_data
);
4694 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
4697 check_visibility
= 1;
4700 case WM_DISPLAYCHANGE
:
4701 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4705 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
4706 DebPrint (("display change: %d %d\n",
4707 (short) LOWORD (msg
.msg
.lParam
),
4708 (short) HIWORD (msg
.msg
.lParam
)));
4711 check_visibility
= 1;
4715 /* Check for messages registered at runtime. */
4716 if (msg
.msg
.message
== msh_mousewheel
)
4718 /* Forward MSH_MOUSEWHEEL as WM_MOUSEWHEEL. */
4719 msg
.msg
.message
= WM_MOUSEWHEEL
;
4725 if (inev
.kind
!= NO_EVENT
)
4727 kbd_buffer_store_event_hold (&inev
, hold_quit
);
4732 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
4737 XSETFRAME (frame
, f
);
4743 if (NILP (help_echo_string
))
4745 help_echo_object
= help_echo_window
= Qnil
;
4749 any_help_event_p
= 1;
4750 gen_help_event (help_echo_string
, frame
, help_echo_window
,
4751 help_echo_object
, help_echo_pos
);
4755 help_echo_string
= Qnil
;
4756 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
4762 /* If the focus was just given to an autoraising frame,
4764 /* ??? This ought to be able to handle more than one such frame. */
4765 if (pending_autoraise_frame
)
4767 x_raise_frame (pending_autoraise_frame
);
4768 pending_autoraise_frame
= 0;
4771 /* Check which frames are still visisble, if we have enqueued any user
4772 events or been notified of events that may affect visibility. We
4773 do this here because there doesn't seem to be any direct
4774 notification from Windows that the visibility of a window has
4775 changed (at least, not in all cases). */
4776 if (count
> 0 || check_visibility
)
4778 Lisp_Object tail
, frame
;
4780 FOR_EACH_FRAME (tail
, frame
)
4782 FRAME_PTR f
= XFRAME (frame
);
4783 /* The tooltip has been drawn already. Avoid the
4784 SET_FRAME_GARBAGED below. */
4785 if (EQ (frame
, tip_frame
))
4788 /* Check "visible" frames and mark each as obscured or not.
4789 Note that async_visible is nonzero for unobscured and
4790 obscured frames, but zero for hidden and iconified frames. */
4791 if (FRAME_W32_P (f
) && f
->async_visible
)
4797 /* Query clipping rectangle for the entire window area
4798 (GetWindowDC), not just the client portion (GetDC).
4799 Otherwise, the scrollbars and menubar aren't counted as
4800 part of the visible area of the frame, and we may think
4801 the frame is obscured when really a scrollbar is still
4802 visible and gets WM_PAINT messages above. */
4803 hdc
= GetWindowDC (FRAME_W32_WINDOW (f
));
4804 GetClipBox (hdc
, &clipbox
);
4805 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
4808 if (clipbox
.right
== clipbox
.left
4809 || clipbox
.bottom
== clipbox
.top
)
4811 /* Frame has become completely obscured so mark as
4812 such (we do this by setting async_visible to 2 so
4813 that FRAME_VISIBLE_P is still true, but redisplay
4815 f
->async_visible
= 2;
4817 if (!FRAME_OBSCURED_P (f
))
4819 DebPrint (("frame %p (%s) obscured\n", f
,
4825 /* Frame is not obscured, so mark it as such. */
4826 f
->async_visible
= 1;
4828 if (FRAME_OBSCURED_P (f
))
4830 SET_FRAME_GARBAGED (f
);
4831 DebPrint (("obscured frame %p (%s) found to be visible\n", f
,
4834 /* Force a redisplay sooner or later. */
4835 record_asynch_buffer_change ();
4848 /***********************************************************************
4850 ***********************************************************************/
4852 /* Set clipping for output in glyph row ROW. W is the window in which
4853 we operate. GC is the graphics context to set clipping in.
4855 ROW may be a text row or, e.g., a mode line. Text rows must be
4856 clipped to the interior of the window dedicated to text display,
4857 mode lines must be clipped to the whole window. */
4860 w32_clip_to_row (w
, row
, area
, hdc
)
4862 struct glyph_row
*row
;
4866 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4868 int window_x
, window_y
, window_width
;
4870 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
4872 clip_rect
.left
= window_x
;
4873 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4874 clip_rect
.top
= max (clip_rect
.top
, window_y
);
4875 clip_rect
.right
= clip_rect
.left
+ window_width
;
4876 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
4878 w32_set_clip_rectangle (hdc
, &clip_rect
);
4882 /* Draw a hollow box cursor on window W in glyph row ROW. */
4885 x_draw_hollow_cursor (w
, row
)
4887 struct glyph_row
*row
;
4889 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4893 struct glyph
*cursor_glyph
;
4894 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
4896 /* Get the glyph the cursor is on. If we can't tell because
4897 the current matrix is invalid or such, give up. */
4898 cursor_glyph
= get_phys_cursor_glyph (w
);
4899 if (cursor_glyph
== NULL
)
4902 /* Compute frame-relative coordinates for phys cursor. */
4903 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &left
, &top
, &h
);
4906 rect
.bottom
= rect
.top
+ h
;
4907 rect
.right
= rect
.left
+ w
->phys_cursor_width
;
4909 hdc
= get_frame_dc (f
);
4910 /* Set clipping, draw the rectangle, and reset clipping again. */
4911 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
4912 FrameRect (hdc
, &rect
, hb
);
4914 w32_set_clip_rectangle (hdc
, NULL
);
4915 release_frame_dc (f
, hdc
);
4919 /* Draw a bar cursor on window W in glyph row ROW.
4921 Implementation note: One would like to draw a bar cursor with an
4922 angle equal to the one given by the font property XA_ITALIC_ANGLE.
4923 Unfortunately, I didn't find a font yet that has this property set.
4927 x_draw_bar_cursor (w
, row
, width
, kind
)
4929 struct glyph_row
*row
;
4931 enum text_cursor_kinds kind
;
4933 struct frame
*f
= XFRAME (w
->frame
);
4934 struct glyph
*cursor_glyph
;
4938 /* If cursor is out of bounds, don't draw garbage. This can happen
4939 in mini-buffer windows when switching between echo area glyphs
4941 cursor_glyph
= get_phys_cursor_glyph (w
);
4942 if (cursor_glyph
== NULL
)
4945 /* If on an image, draw like a normal cursor. That's usually better
4946 visible than drawing a bar, esp. if the image is large so that
4947 the bar might not be in the window. */
4948 if (cursor_glyph
->type
== IMAGE_GLYPH
)
4950 struct glyph_row
*row
;
4951 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
4952 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
4956 COLORREF cursor_color
= f
->output_data
.w32
->cursor_pixel
;
4957 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
4959 /* If the glyph's background equals the color we normally draw
4960 the bar cursor in, the bar cursor in its normal color is
4961 invisible. Use the glyph's foreground color instead in this
4962 case, on the assumption that the glyph's colors are chosen so
4963 that the glyph is legible. */
4964 if (face
->background
== cursor_color
)
4965 cursor_color
= face
->foreground
;
4967 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
4970 width
= FRAME_CURSOR_WIDTH (f
);
4971 width
= min (cursor_glyph
->pixel_width
, width
);
4973 w
->phys_cursor_width
= width
;
4976 hdc
= get_frame_dc (f
);
4977 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
4979 if (kind
== BAR_CURSOR
)
4981 w32_fill_area (f
, hdc
, cursor_color
, x
,
4982 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
4983 width
, row
->height
);
4987 w32_fill_area (f
, hdc
, cursor_color
, x
,
4988 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
4989 row
->height
- width
),
4990 min (FRAME_COLUMN_WIDTH (f
), cursor_glyph
->pixel_width
),
4994 w32_set_clip_rectangle (hdc
, NULL
);
4995 release_frame_dc (f
, hdc
);
5000 /* RIF: Define cursor CURSOR on frame F. */
5003 w32_define_frame_cursor (f
, cursor
)
5007 w32_define_cursor (FRAME_W32_WINDOW (f
), cursor
);
5011 /* RIF: Clear area on frame F. */
5014 w32_clear_frame_area (f
, x
, y
, width
, height
)
5016 int x
, y
, width
, height
;
5020 hdc
= get_frame_dc (f
);
5021 w32_clear_area (f
, hdc
, x
, y
, width
, height
);
5022 release_frame_dc (f
, hdc
);
5025 /* RIF: Draw or clear cursor on window W. */
5028 w32_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
5030 struct glyph_row
*glyph_row
;
5032 int cursor_type
, cursor_width
;
5037 /* If the user wants to use the system caret, make sure our own
5038 cursor remains invisible. */
5039 if (w32_use_visible_system_caret
)
5041 /* Call to erase_phys_cursor here seems to use the
5042 wrong values of w->phys_cursor, as they have been
5043 overwritten before this function was called. */
5044 if (w
->phys_cursor_type
!= NO_CURSOR
)
5045 erase_phys_cursor (w
);
5047 cursor_type
= w
->phys_cursor_type
= NO_CURSOR
;
5048 w
->phys_cursor_width
= -1;
5052 w
->phys_cursor_type
= cursor_type
;
5055 w
->phys_cursor_on_p
= 1;
5057 /* If this is the active cursor, we need to track it with the
5058 system caret, so third party software like screen magnifiers
5059 and speech synthesizers can follow the cursor. */
5062 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5063 HWND hwnd
= FRAME_W32_WINDOW (f
);
5066 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5068 = (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
5069 + glyph_row
->ascent
- w
->phys_cursor_ascent
);
5071 /* If the size of the active cursor changed, destroy the old
5073 if (w32_system_caret_hwnd
5074 && (w32_system_caret_height
!= w
->phys_cursor_height
))
5075 PostMessage (hwnd
, WM_EMACS_DESTROY_CARET
, 0, 0);
5077 w32_system_caret_height
= w
->phys_cursor_height
;
5079 /* Move the system caret. */
5080 PostMessage (hwnd
, WM_EMACS_TRACK_CARET
, 0, 0);
5083 if (glyph_row
->exact_window_width_line_p
5084 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
5086 glyph_row
->cursor_in_fringe_p
= 1;
5087 draw_fringe_bitmap (w
, glyph_row
, 0);
5091 switch (cursor_type
)
5093 case HOLLOW_BOX_CURSOR
:
5094 x_draw_hollow_cursor (w
, glyph_row
);
5097 case FILLED_BOX_CURSOR
:
5098 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5102 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5106 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5110 w
->phys_cursor_width
= 0;
5124 x_bitmap_icon (f
, icon
)
5129 HANDLE small_icon
= NULL
;
5131 if (FRAME_W32_WINDOW (f
) == 0)
5135 main_icon
= LoadIcon (hinst
, EMACS_CLASS
);
5136 else if (STRINGP (icon
))
5138 /* Load the main icon from the named file. */
5139 main_icon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5140 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5141 /* Try to load a small icon to go with it. */
5142 small_icon
= LoadImage (NULL
, (LPCSTR
) SDATA (icon
), IMAGE_ICON
,
5143 GetSystemMetrics (SM_CXSMICON
),
5144 GetSystemMetrics (SM_CYSMICON
),
5147 else if (SYMBOLP (icon
))
5151 if (EQ (icon
, intern ("application")))
5152 name
= (LPCTSTR
) IDI_APPLICATION
;
5153 else if (EQ (icon
, intern ("hand")))
5154 name
= (LPCTSTR
) IDI_HAND
;
5155 else if (EQ (icon
, intern ("question")))
5156 name
= (LPCTSTR
) IDI_QUESTION
;
5157 else if (EQ (icon
, intern ("exclamation")))
5158 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5159 else if (EQ (icon
, intern ("asterisk")))
5160 name
= (LPCTSTR
) IDI_ASTERISK
;
5161 else if (EQ (icon
, intern ("winlogo")))
5162 name
= (LPCTSTR
) IDI_WINLOGO
;
5166 main_icon
= LoadIcon (NULL
, name
);
5171 if (main_icon
== NULL
)
5174 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5175 (LPARAM
) main_icon
);
5177 /* If there is a small icon that goes with it, set that too. */
5179 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_SMALL
,
5180 (LPARAM
) small_icon
);
5186 /************************************************************************
5188 ************************************************************************/
5190 /* Display Error Handling functions not used on W32. Listing them here
5191 helps diff stay in step when comparing w32term.c with xterm.c.
5193 x_error_catcher (display, error)
5194 x_catch_errors (dpy)
5195 x_catch_errors_unwind (old_val)
5196 x_check_errors (dpy, format)
5197 x_fully_uncatch_errors ()
5198 x_catching_errors ()
5199 x_had_errors_p (dpy)
5200 x_clear_errors (dpy)
5201 x_uncatch_errors (dpy, count)
5203 x_connection_signal (signalnum)
5204 x_connection_closed (dpy, error_message)
5205 x_error_quitter (display, error)
5206 x_error_handler (display, error)
5207 x_io_error_quitter (display)
5212 /* Changing the font of the frame. */
5215 x_new_font (f
, font_object
, fontset
)
5217 Lisp_Object font_object
;
5220 struct font
*font
= XFONT_OBJECT (font_object
);
5223 fontset
= fontset_from_font (font_object
);
5224 FRAME_FONTSET (f
) = fontset
;
5225 if (FRAME_FONT (f
) == font
)
5226 /* This font is already set in frame F. There's nothing more to
5228 return fontset_name (fontset
);
5232 FRAME_FONT (f
) = font
;
5233 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
5234 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
5235 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
5236 FRAME_LINE_HEIGHT (f
) = font
->height
;
5238 compute_fringe_widths (f
, 1);
5240 /* Compute the scroll bar width in character columns. */
5241 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5243 int wid
= FRAME_COLUMN_WIDTH (f
);
5244 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5245 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
- 1) / wid
;
5249 int wid
= FRAME_COLUMN_WIDTH (f
);
5250 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
5253 /* Now make the frame display the given font. */
5254 if (FRAME_X_WINDOW (f
) != 0)
5256 /* Don't change the size of a tip frame; there's no point in
5257 doing it because it's done in Fx_show_tip, and it leads to
5258 problems because the tip frame has no widget. */
5259 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5260 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
5265 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
5266 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
5271 return fontset_name (fontset
);
5275 /***********************************************************************
5276 TODO: W32 Input Methods
5277 ***********************************************************************/
5278 /* Listing missing functions from xterm.c helps diff stay in step.
5280 xim_destroy_callback (xim, client_data, call_data)
5281 xim_open_dpy (dpyinfo, resource_name)
5283 xim_instantiate_callback (display, client_data, call_data)
5284 xim_initialize (dpyinfo, resource_name)
5285 xim_close_dpy (dpyinfo)
5290 /* Calculate the absolute position in frame F
5291 from its current recorded position values and gravity. */
5294 x_calc_absolute_position (f
)
5297 int flags
= f
->size_hint_flags
;
5299 /* The sum of the widths of the frame's left and right borders, and
5300 the sum of the heights of the frame's top and bottom borders (in
5301 pixels) drawn by Windows. */
5302 unsigned int left_right_borders_width
, top_bottom_borders_height
;
5304 /* Try to get the actual values of these two variables. We compute
5305 the border width (height) by subtracting the width (height) of
5306 the frame's client area from the width (height) of the frame's
5308 WINDOWPLACEMENT wp
= { 0 };
5309 RECT client_rect
= { 0 };
5311 if (GetWindowPlacement (FRAME_W32_WINDOW (f
), &wp
)
5312 && GetClientRect (FRAME_W32_WINDOW (f
), &client_rect
))
5314 left_right_borders_width
=
5315 (wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
) -
5316 (client_rect
.right
- client_rect
.left
);
5318 top_bottom_borders_height
=
5319 (wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
) -
5320 (client_rect
.bottom
- client_rect
.top
);
5324 /* Use sensible default values. */
5325 left_right_borders_width
= 8;
5326 top_bottom_borders_height
= 32;
5329 /* Treat negative positions as relative to the rightmost bottommost
5330 position that fits on the screen. */
5331 if (flags
& XNegative
)
5332 f
->left_pos
= (x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f
))
5333 - FRAME_PIXEL_WIDTH (f
)
5335 - (left_right_borders_width
- 1));
5337 if (flags
& YNegative
)
5338 f
->top_pos
= (x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f
))
5339 - FRAME_PIXEL_HEIGHT (f
)
5341 - (top_bottom_borders_height
- 1));
5343 /* The left_pos and top_pos are now relative to the top and left
5344 screen edges, so the flags should correspond. */
5345 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5348 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5349 to really change the position, and 0 when calling from
5350 x_make_frame_visible (in that case, XOFF and YOFF are the current
5351 position values). It is -1 when calling from x_set_frame_parameters,
5352 which means, do adjust for borders but don't change the gravity. */
5355 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5357 register int xoff
, yoff
;
5360 int modified_top
, modified_left
;
5362 if (change_gravity
> 0)
5366 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5368 f
->size_hint_flags
|= XNegative
;
5370 f
->size_hint_flags
|= YNegative
;
5371 f
->win_gravity
= NorthWestGravity
;
5373 x_calc_absolute_position (f
);
5376 x_wm_set_size_hint (f
, (long) 0, 0);
5378 modified_left
= f
->left_pos
;
5379 modified_top
= f
->top_pos
;
5381 my_set_window_pos (FRAME_W32_WINDOW (f
),
5383 modified_left
, modified_top
,
5385 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5390 /* Check if we need to resize the frame due to a fullscreen request.
5391 If so needed, resize the frame. */
5393 x_check_fullscreen (f
)
5396 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
5398 int width
, height
, ign
;
5400 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5402 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
5404 /* We do not need to move the window, it shall be taken care of
5405 when setting WM manager hints. */
5406 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
5408 change_frame_size (f
, height
, width
, 0, 1, 0);
5409 SET_FRAME_GARBAGED (f
);
5410 cancel_mouse_face (f
);
5412 /* Wait for the change of frame size to occur */
5413 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
5418 /* Call this to change the size of frame F's x-window.
5419 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5420 for this size change and subsequent size changes.
5421 Otherwise we leave the window gravity unchanged. */
5424 x_set_window_size (f
, change_gravity
, cols
, rows
)
5429 int pixelwidth
, pixelheight
;
5433 check_frame_size (f
, &rows
, &cols
);
5434 f
->scroll_bar_actual_width
5435 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
5437 compute_fringe_widths (f
, 0);
5439 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
5440 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
5442 f
->win_gravity
= NorthWestGravity
;
5443 x_wm_set_size_hint (f
, (long) 0, 0);
5448 rect
.left
= rect
.top
= 0;
5449 rect
.right
= pixelwidth
;
5450 rect
.bottom
= pixelheight
;
5452 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
,
5453 FRAME_EXTERNAL_MENU_BAR (f
));
5455 my_set_window_pos (FRAME_W32_WINDOW (f
),
5458 rect
.right
- rect
.left
,
5459 rect
.bottom
- rect
.top
,
5460 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
5464 /* The following mirrors what is done in xterm.c. It appears to be
5465 for informing lisp of the new size immediately, while the actual
5466 resize will happen asynchronously. But on Windows, the menu bar
5467 automatically wraps when the frame is too narrow to contain it,
5468 and that causes any calculations made here to come out wrong. The
5469 end is some nasty buggy behavior, including the potential loss
5472 Disabling this code is either not sufficient to fix the problems
5473 completely, or it causes fresh problems, but at least it removes
5474 the most problematic symptom of the minibuffer becoming unusable.
5476 -----------------------------------------------------------------
5478 Now, strictly speaking, we can't be sure that this is accurate,
5479 but the window manager will get around to dealing with the size
5480 change request eventually, and we'll hear how it went when the
5481 ConfigureNotify event gets here.
5483 We could just not bother storing any of this information here,
5484 and let the ConfigureNotify event set everything up, but that
5485 might be kind of confusing to the Lisp code, since size changes
5486 wouldn't be reported in the frame parameters until some random
5487 point in the future when the ConfigureNotify event arrives.
5489 We pass 1 for DELAY since we can't run Lisp code inside of
5491 change_frame_size (f
, rows
, cols
, 0, 1, 0);
5492 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
5493 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
5495 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5496 receive in the ConfigureNotify event; if we get what we asked
5497 for, then the event won't cause the screen to become garbaged, so
5498 we have to make sure to do it here. */
5499 SET_FRAME_GARBAGED (f
);
5501 /* If cursor was outside the new size, mark it as off. */
5502 mark_window_cursors_off (XWINDOW (f
->root_window
));
5504 /* Clear out any recollection of where the mouse highlighting was,
5505 since it might be in a place that's outside the new frame size.
5506 Actually checking whether it is outside is a pain in the neck,
5507 so don't try--just let the highlighting be done afresh with new size. */
5508 cancel_mouse_face (f
);
5514 /* Mouse warping. */
5516 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
5519 x_set_mouse_position (f
, x
, y
)
5525 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
5526 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
5528 if (pix_x
< 0) pix_x
= 0;
5529 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
5531 if (pix_y
< 0) pix_y
= 0;
5532 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
5534 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
5538 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5547 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
5548 pt
.x
= rect
.left
+ pix_x
;
5549 pt
.y
= rect
.top
+ pix_y
;
5550 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
5552 SetCursorPos (pt
.x
, pt
.y
);
5558 /* focus shifting, raising and lowering. */
5561 x_focus_on_frame (f
)
5564 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
5566 /* Give input focus to frame. */
5569 /* Try not to change its Z-order if possible. */
5570 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
5571 my_set_focus (f
, FRAME_W32_WINDOW (f
));
5574 my_set_foreground_window (FRAME_W32_WINDOW (f
));
5584 /* Raise frame F. */
5591 /* Strictly speaking, raise-frame should only change the frame's Z
5592 order, leaving input focus unchanged. This is reasonable behavior
5593 on X where the usual policy is point-to-focus. However, this
5594 behavior would be very odd on Windows where the usual policy is
5597 On X, if the mouse happens to be over the raised frame, it gets
5598 input focus anyway (so the window with focus will never be
5599 completely obscured) - if not, then just moving the mouse over it
5600 is sufficient to give it focus. On Windows, the user must actually
5601 click on the frame (preferrably the title bar so as not to move
5602 point), which is more awkward. Also, no other Windows program
5603 raises a window to the top but leaves another window (possibly now
5604 completely obscured) with input focus.
5606 Because there is a system setting on Windows that allows the user
5607 to choose the point to focus policy, we make the strict semantics
5608 optional, but by default we grab focus when raising. */
5610 if (NILP (Vw32_grab_focus_on_raise
))
5612 /* The obvious call to my_set_window_pos doesn't work if Emacs is
5613 not already the foreground application: the frame is raised
5614 above all other frames belonging to us, but not above the
5615 current top window. To achieve that, we have to resort to this
5616 more cumbersome method. */
5618 HDWP handle
= BeginDeferWindowPos (2);
5621 DeferWindowPos (handle
,
5622 FRAME_W32_WINDOW (f
),
5625 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
5627 DeferWindowPos (handle
,
5628 GetForegroundWindow (),
5629 FRAME_W32_WINDOW (f
),
5631 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
5633 EndDeferWindowPos (handle
);
5638 my_set_foreground_window (FRAME_W32_WINDOW (f
));
5644 /* Lower frame F. */
5650 my_set_window_pos (FRAME_W32_WINDOW (f
),
5653 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
5658 w32_frame_raise_lower (f
, raise_flag
)
5662 if (! FRAME_W32_P (f
))
5671 /* Change of visibility. */
5673 /* This tries to wait until the frame is really visible.
5674 However, if the window manager asks the user where to position
5675 the frame, this will return before the user finishes doing that.
5676 The frame will not actually be visible at that time,
5677 but it will become visible later when the window manager
5678 finishes with it. */
5681 x_make_frame_visible (f
)
5688 type
= x_icon_type (f
);
5690 x_bitmap_icon (f
, type
);
5692 if (! FRAME_VISIBLE_P (f
))
5694 /* We test FRAME_GARBAGED_P here to make sure we don't
5695 call x_set_offset a second time
5696 if we get to x_make_frame_visible a second time
5697 before the window gets really visible. */
5698 if (! FRAME_ICONIFIED_P (f
)
5699 && ! f
->output_data
.w32
->asked_for_visible
)
5704 /* Adjust vertical window position in order to avoid being
5705 covered by a task bar placed at the bottom of the desktop. */
5706 SystemParametersInfo(SPI_GETWORKAREA
, 0, &workarea_rect
, 0);
5707 GetWindowRect(FRAME_W32_WINDOW(f
), &window_rect
);
5708 if (window_rect
.bottom
> workarea_rect
.bottom
5709 && window_rect
.top
> workarea_rect
.top
)
5710 f
->top_pos
= max (window_rect
.top
5711 - window_rect
.bottom
+ workarea_rect
.bottom
,
5714 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
5717 f
->output_data
.w32
->asked_for_visible
= 1;
5719 /* The first of these seems to give more expected behavior, but
5720 was added as a commented out line in Sept 1997, with the
5721 second version remaining uncommented. There may have been
5722 some problem with it that led to it not being enabled,
5723 so the old version remains commented out below in case we
5724 decide we need to go back to it [23.0.60 2008-06-09]. */
5725 my_show_window (f
, FRAME_W32_WINDOW (f
),
5726 f
->async_iconified
? SW_RESTORE
: SW_SHOW
);
5727 /* my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL); */
5730 /* Synchronize to ensure Emacs knows the frame is visible
5731 before we do anything else. We do this loop with input not blocked
5732 so that incoming events are handled. */
5737 /* This must come after we set COUNT. */
5740 XSETFRAME (frame
, f
);
5742 /* Wait until the frame is visible. Process X events until a
5743 MapNotify event has been seen, or until we think we won't get a
5744 MapNotify at all.. */
5745 for (count
= input_signal_count
+ 10;
5746 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
5748 /* Force processing of queued events. */
5749 /* TODO: x_sync equivalent? */
5751 /* Machines that do polling rather than SIGIO have been observed
5752 to go into a busy-wait here. So we'll fake an alarm signal
5753 to let the handler know that there's something to be read.
5754 We used to raise a real alarm, but it seems that the handler
5755 isn't always enabled here. This is probably a bug. */
5756 if (input_polling_used ())
5758 /* It could be confusing if a real alarm arrives while processing
5759 the fake one. Turn it off and let the handler reset it. */
5760 int old_poll_suppress_count
= poll_suppress_count
;
5761 poll_suppress_count
= 1;
5762 poll_for_input_1 ();
5763 poll_suppress_count
= old_poll_suppress_count
;
5766 FRAME_SAMPLE_VISIBILITY (f
);
5770 /* Change from mapped state to withdrawn state. */
5772 /* Make the frame visible (mapped and not iconified). */
5774 x_make_frame_invisible (f
)
5777 /* Don't keep the highlight on an invisible frame. */
5778 if (FRAME_W32_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5779 FRAME_W32_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5783 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
5785 /* We can't distinguish this from iconification
5786 just by the event that we get from the server.
5787 So we can't win using the usual strategy of letting
5788 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5789 and synchronize with the server to make sure we agree. */
5791 FRAME_ICONIFIED_P (f
) = 0;
5792 f
->async_visible
= 0;
5793 f
->async_iconified
= 0;
5798 /* Change window state from mapped to iconified. */
5806 /* Don't keep the highlight on an invisible frame. */
5807 if (FRAME_W32_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5808 FRAME_W32_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5810 if (f
->async_iconified
)
5815 type
= x_icon_type (f
);
5817 x_bitmap_icon (f
, type
);
5819 /* Simulate the user minimizing the frame. */
5820 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
5826 /* Free X resources of frame F. */
5829 x_free_frame_resources (f
)
5832 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5836 /* We must free faces before destroying windows because some
5837 font-driver (e.g. xft) access a window while finishing a
5839 if (FRAME_FACE_CACHE (f
))
5840 free_frame_faces (f
);
5842 if (FRAME_W32_WINDOW (f
))
5843 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
5845 free_frame_menubar (f
);
5847 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
5848 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
5849 unload_color (f
, f
->output_data
.w32
->cursor_pixel
);
5850 unload_color (f
, f
->output_data
.w32
->cursor_foreground_pixel
);
5851 unload_color (f
, f
->output_data
.w32
->border_pixel
);
5852 unload_color (f
, f
->output_data
.w32
->mouse_pixel
);
5853 if (f
->output_data
.w32
->white_relief
.allocated_p
)
5854 unload_color (f
, f
->output_data
.w32
->white_relief
.pixel
);
5855 if (f
->output_data
.w32
->black_relief
.allocated_p
)
5856 unload_color (f
, f
->output_data
.w32
->black_relief
.pixel
);
5858 if (FRAME_FACE_CACHE (f
))
5859 free_frame_faces (f
);
5861 xfree (f
->output_data
.w32
);
5862 f
->output_data
.w32
= NULL
;
5864 if (f
== dpyinfo
->w32_focus_frame
)
5865 dpyinfo
->w32_focus_frame
= 0;
5866 if (f
== dpyinfo
->w32_focus_event_frame
)
5867 dpyinfo
->w32_focus_event_frame
= 0;
5868 if (f
== dpyinfo
->x_highlight_frame
)
5869 dpyinfo
->x_highlight_frame
= 0;
5871 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5873 dpyinfo
->mouse_face_beg_row
5874 = dpyinfo
->mouse_face_beg_col
= -1;
5875 dpyinfo
->mouse_face_end_row
5876 = dpyinfo
->mouse_face_end_col
= -1;
5877 dpyinfo
->mouse_face_window
= Qnil
;
5878 dpyinfo
->mouse_face_deferred_gc
= 0;
5879 dpyinfo
->mouse_face_mouse_frame
= 0;
5886 /* Destroy the window of frame F. */
5888 x_destroy_window (f
)
5891 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5893 x_free_frame_resources (f
);
5894 dpyinfo
->reference_count
--;
5898 /* Setting window manager hints. */
5900 /* Set the normal size hints for the window manager, for frame F.
5901 FLAGS is the flags word to use--or 0 meaning preserve the flags
5902 that the window now has.
5903 If USER_POSITION is nonzero, we set the USPosition
5904 flag (this is useful when FLAGS is 0). */
5906 x_wm_set_size_hint (f
, flags
, user_position
)
5911 Window window
= FRAME_W32_WINDOW (f
);
5915 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
5916 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
5917 SetWindowLong (window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
5918 SetWindowLong (window
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
5923 /* Window manager things */
5925 x_wm_set_icon_position (f
, icon_x
, icon_y
)
5930 Window window
= FRAME_W32_WINDOW (f
);
5932 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
5933 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
5934 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
5936 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
5941 /***********************************************************************
5943 ***********************************************************************/
5945 static int w32_initialized
= 0;
5948 w32_initialize_display_info (display_name
)
5949 Lisp_Object display_name
;
5951 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
5953 bzero (dpyinfo
, sizeof (*dpyinfo
));
5955 /* Put it on w32_display_name_list. */
5956 w32_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
5957 w32_display_name_list
);
5958 dpyinfo
->name_list_element
= XCAR (w32_display_name_list
);
5960 dpyinfo
->w32_id_name
5961 = (char *) xmalloc (SCHARS (Vinvocation_name
)
5962 + SCHARS (Vsystem_name
)
5964 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
5965 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
5967 /* Default Console mode values - overridden when running in GUI mode
5968 with values obtained from system metrics. */
5971 dpyinfo
->n_planes
= 1;
5972 dpyinfo
->n_cbits
= 4;
5973 dpyinfo
->n_fonts
= 0;
5974 dpyinfo
->smallest_font_height
= 1;
5975 dpyinfo
->smallest_char_width
= 1;
5977 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
5978 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
5979 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
5980 dpyinfo
->mouse_face_window
= Qnil
;
5981 dpyinfo
->mouse_face_overlay
= Qnil
;
5982 dpyinfo
->mouse_face_hidden
= 0;
5984 dpyinfo
->vertical_scroll_bar_cursor
= w32_load_cursor (IDC_ARROW
);
5985 /* TODO: dpyinfo->gray */
5989 /* Create an xrdb-style database of resources to supercede registry settings.
5990 The database is just a concatenation of C strings, finished by an additional
5991 \0. The strings are submitted to some basic normalization, so
5993 [ *]option[ *]:[ *]value...
5999 but any whitespace following value is not removed. */
6002 w32_make_rdb (xrm_option
)
6005 char *buffer
= xmalloc (strlen (xrm_option
) + 2);
6006 char *current
= buffer
;
6009 int before_value
= 0;
6023 if (in_option
&& (ch
== ':'))
6028 else if (before_value
)
6033 else if (!(in_option
|| before_value
))
6045 x_flush (struct frame
* f
)
6046 { /* Nothing to do */ }
6049 extern frame_parm_handler w32_frame_parm_handlers
[];
6051 static struct redisplay_interface w32_redisplay_interface
=
6053 w32_frame_parm_handlers
,
6057 x_clear_end_of_line
,
6059 x_after_update_window_line
,
6060 x_update_window_begin
,
6061 x_update_window_end
,
6064 0, /* flush_display_optional */
6065 x_clear_window_mouse_face
,
6066 x_get_glyph_overhangs
,
6067 x_fix_overlapping_area
,
6068 w32_draw_fringe_bitmap
,
6069 w32_define_fringe_bitmap
,
6070 w32_destroy_fringe_bitmap
,
6071 w32_compute_glyph_string_overhangs
,
6072 x_draw_glyph_string
,
6073 w32_define_frame_cursor
,
6074 w32_clear_frame_area
,
6075 w32_draw_window_cursor
,
6076 w32_draw_vertical_window_border
,
6077 w32_shift_glyphs_for_insert
6080 static void x_delete_terminal (struct terminal
*term
);
6082 static struct terminal
*
6083 w32_create_terminal (struct w32_display_info
*dpyinfo
)
6085 struct terminal
*terminal
;
6087 terminal
= create_terminal ();
6089 terminal
->type
= output_w32
;
6090 terminal
->display_info
.w32
= dpyinfo
;
6091 dpyinfo
->terminal
= terminal
;
6093 /* MSVC does not type K&R functions with no arguments correctly, and
6094 so we must explicitly cast them. */
6095 terminal
->clear_frame_hook
= x_clear_frame
;
6096 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
6097 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
6098 terminal
->ring_bell_hook
= w32_ring_bell
;
6099 terminal
->reset_terminal_modes_hook
= w32_reset_terminal_modes
;
6100 terminal
->set_terminal_modes_hook
= w32_set_terminal_modes
;
6101 terminal
->update_begin_hook
= x_update_begin
;
6102 terminal
->update_end_hook
= x_update_end
;
6103 terminal
->set_terminal_window_hook
= w32_set_terminal_window
;
6104 terminal
->read_socket_hook
= w32_read_socket
;
6105 terminal
->frame_up_to_date_hook
= w32_frame_up_to_date
;
6106 terminal
->mouse_position_hook
= w32_mouse_position
;
6107 terminal
->frame_rehighlight_hook
= w32_frame_rehighlight
;
6108 terminal
->frame_raise_lower_hook
= w32_frame_raise_lower
;
6109 // terminal->fullscreen_hook = XTfullscreen_hook;
6110 terminal
->set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
6111 terminal
->condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
6112 terminal
->redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
6113 terminal
->judge_scroll_bars_hook
= w32_judge_scroll_bars
;
6115 terminal
->delete_frame_hook
= x_destroy_window
;
6116 terminal
->delete_terminal_hook
= x_delete_terminal
;
6118 terminal
->rif
= &w32_redisplay_interface
;
6119 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
6120 terminal
->char_ins_del_ok
= 1;
6121 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
6122 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
6123 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
6126 /* We don't yet support separate terminals on W32, so don't try to share
6127 keyboards between virtual terminals that are on the same physical
6128 terminal like X does. */
6129 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
6130 init_kboard (terminal
->kboard
);
6131 terminal
->kboard
->Vwindow_system
= intern ("w32");
6132 terminal
->kboard
->next_kboard
= all_kboards
;
6133 all_kboards
= terminal
->kboard
;
6134 /* Don't let the initial kboard remain current longer than necessary.
6135 That would cause problems if a file loaded on startup tries to
6136 prompt in the mini-buffer. */
6137 if (current_kboard
== initial_kboard
)
6138 current_kboard
= terminal
->kboard
;
6139 terminal
->kboard
->reference_count
++;
6145 x_delete_terminal (struct terminal
*terminal
)
6147 struct w32_display_info
*dpyinfo
= terminal
->display_info
.w32
;
6150 /* Protect against recursive calls. Fdelete_frame in
6151 delete_terminal calls us back when it deletes our last frame. */
6152 if (!terminal
->name
)
6157 x_delete_display (dpyinfo
);
6161 struct w32_display_info
*
6162 w32_term_init (display_name
, xrm_option
, resource_name
)
6163 Lisp_Object display_name
;
6165 char *resource_name
;
6167 struct w32_display_info
*dpyinfo
;
6168 struct terminal
*terminal
;
6173 if (!w32_initialized
)
6176 w32_initialized
= 1;
6179 w32_initialize_display_info (display_name
);
6181 dpyinfo
= &one_w32_display_info
;
6182 terminal
= w32_create_terminal (dpyinfo
);
6184 /* Set the name of the terminal. */
6185 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
6186 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
6187 terminal
->name
[SBYTES (display_name
)] = 0;
6189 dpyinfo
->xrdb
= xrm_option
? w32_make_rdb (xrm_option
) : NULL
;
6191 /* Put this display on the chain. */
6192 dpyinfo
->next
= x_display_list
;
6193 x_display_list
= dpyinfo
;
6195 hdc
= GetDC (GetDesktopWindow ());
6197 dpyinfo
->root_window
= GetDesktopWindow ();
6198 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
6199 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
6200 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
6201 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
6202 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
6203 dpyinfo
->terminal
->image_cache
= make_image_cache ();
6204 ReleaseDC (GetDesktopWindow (), hdc
);
6206 /* initialise palette with white and black */
6209 w32_defined_color (0, "white", &color
, 1);
6210 w32_defined_color (0, "black", &color
, 1);
6213 /* Add the default keyboard. */
6214 add_keyboard_wait_descriptor (0);
6216 /* Create Fringe Bitmaps and store them for later use.
6218 On W32, bitmaps are all unsigned short, as Windows requires
6219 bitmap data to be Word aligned. For some reason they are
6220 horizontally reflected compared to how they appear on X, so we
6221 need to bitswap and convert to unsigned shorts before creating
6223 w32_init_fringe (terminal
->rif
);
6226 fcntl (connection
, F_SETOWN
, getpid ());
6227 #endif /* ! defined (F_SETOWN) */
6230 if (interrupt_input
)
6231 init_sigio (connection
);
6232 #endif /* ! defined (SIGIO) */
6239 /* Get rid of display DPYINFO, assuming all frames are already gone. */
6241 x_delete_display (dpyinfo
)
6242 struct w32_display_info
*dpyinfo
;
6244 /* Discard this display from w32_display_name_list and w32_display_list.
6245 We can't use Fdelq because that can quit. */
6246 if (! NILP (w32_display_name_list
)
6247 && EQ (XCAR (w32_display_name_list
), dpyinfo
->name_list_element
))
6248 w32_display_name_list
= XCDR (w32_display_name_list
);
6253 tail
= w32_display_name_list
;
6254 while (CONSP (tail
) && CONSP (XCDR (tail
)))
6256 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
6258 XSETCDR (tail
, XCDR (XCDR (tail
)));
6265 /* free palette table */
6267 struct w32_palette_entry
* plist
;
6269 plist
= dpyinfo
->color_list
;
6272 struct w32_palette_entry
* pentry
= plist
;
6273 plist
= plist
->next
;
6276 dpyinfo
->color_list
= NULL
;
6277 if (dpyinfo
->palette
)
6278 DeleteObject(dpyinfo
->palette
);
6280 xfree (dpyinfo
->w32_id_name
);
6282 w32_reset_fringes ();
6285 /* Set up use of W32. */
6287 DWORD WINAPI
w32_msg_worker (void * arg
);
6294 w32_system_caret_hwnd
= NULL
;
6295 w32_system_caret_height
= 0;
6296 w32_system_caret_x
= 0;
6297 w32_system_caret_y
= 0;
6299 /* Initialize w32_use_visible_system_caret based on whether a screen
6300 reader is in use. */
6301 if (!SystemParametersInfo (SPI_GETSCREENREADER
, 0,
6302 &w32_use_visible_system_caret
, 0))
6303 w32_use_visible_system_caret
= 0;
6305 last_tool_bar_item
= -1;
6306 any_help_event_p
= 0;
6308 /* Initialize input mode: interrupt_input off, no flow control, allow
6309 8 bit character input, standard quit char. */
6310 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
6312 /* Create the window thread - it will terminate itself or when the app terminates */
6316 dwMainThreadId
= GetCurrentThreadId ();
6317 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
6318 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
6320 /* Wait for thread to start */
6325 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
6327 hWindowsThread
= CreateThread (NULL
, 0,
6329 0, 0, &dwWindowsThreadId
);
6331 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6334 /* It is desirable that mainThread should have the same notion of
6335 focus window and active window as windowsThread. Unfortunately, the
6336 following call to AttachThreadInput, which should do precisely what
6337 we need, causes major problems when Emacs is linked as a console
6338 program. Unfortunately, we have good reasons for doing that, so
6339 instead we need to send messages to windowsThread to make some API
6340 calls for us (ones that affect, or depend on, the active/focus
6342 #ifdef ATTACH_THREADS
6343 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
6346 /* Dynamically link to optional system components. */
6348 HANDLE user_lib
= LoadLibrary ("user32.dll");
6350 #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn)
6352 LOAD_PROC (user_lib
, SetLayeredWindowAttributes
);
6356 FreeLibrary (user_lib
);
6358 /* Ensure scrollbar handle is at least 5 pixels. */
6359 vertical_scroll_bar_min_handle
= 5;
6361 /* For either kind of scroll bar, take account of the arrows; these
6362 effectively form the border of the main scroll bar range. */
6363 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
6364 = GetSystemMetrics (SM_CYVSCROLL
);
6371 staticpro (&w32_display_name_list
);
6372 w32_display_name_list
= Qnil
;
6374 staticpro (&last_mouse_scroll_bar
);
6375 last_mouse_scroll_bar
= Qnil
;
6377 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
6379 DEFVAR_INT ("w32-num-mouse-buttons",
6380 &w32_num_mouse_buttons
,
6381 doc
: /* Number of physical mouse buttons. */);
6382 w32_num_mouse_buttons
= 2;
6384 DEFVAR_LISP ("w32-swap-mouse-buttons",
6385 &Vw32_swap_mouse_buttons
,
6386 doc
: /* Swap the mapping of middle and right mouse buttons.
6387 When nil, middle button is mouse-2 and right button is mouse-3. */);
6388 Vw32_swap_mouse_buttons
= Qnil
;
6390 DEFVAR_LISP ("w32-grab-focus-on-raise",
6391 &Vw32_grab_focus_on_raise
,
6392 doc
: /* Raised frame grabs input focus.
6393 When t, `raise-frame' grabs input focus as well. This fits well
6394 with the normal Windows click-to-focus policy, but might not be
6395 desirable when using a point-to-focus policy. */);
6396 Vw32_grab_focus_on_raise
= Qt
;
6398 DEFVAR_LISP ("w32-capslock-is-shiftlock",
6399 &Vw32_capslock_is_shiftlock
,
6400 doc
: /* Apply CapsLock state to non character input keys.
6401 When nil, CapsLock only affects normal character input keys. */);
6402 Vw32_capslock_is_shiftlock
= Qnil
;
6404 DEFVAR_LISP ("w32-recognize-altgr",
6405 &Vw32_recognize_altgr
,
6406 doc
: /* Recognize right-alt and left-ctrl as AltGr.
6407 When nil, the right-alt and left-ctrl key combination is
6408 interpreted normally. */);
6409 Vw32_recognize_altgr
= Qt
;
6411 DEFVAR_BOOL ("w32-use-visible-system-caret",
6412 &w32_use_visible_system_caret
,
6413 doc
: /* Flag to make the system caret visible.
6414 When this is non-nil, Emacs will indicate the position of point by
6415 using the system caret instead of drawing its own cursor. Some screen
6416 reader software does not track the system cursor properly when it is
6417 invisible, and gets confused by Emacs drawing its own cursor, so this
6418 variable is initialized to t when Emacs detects that screen reader
6419 software is running as it starts up.
6421 When this variable is set, other variables affecting the appearance of
6422 the cursor have no effect. */);
6424 w32_use_visible_system_caret
= 0;
6426 /* We don't yet support this, but defining this here avoids whining
6427 from cus-start.el and other places, like "M-x set-variable". */
6428 DEFVAR_BOOL ("x-use-underline-position-properties",
6429 &x_use_underline_position_properties
,
6430 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
6431 A value of nil means ignore them. If you encounter fonts with bogus
6432 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6433 to 4.1, set this to nil.
6435 NOTE: Not supported on MS-Windows yet. */);
6436 x_use_underline_position_properties
= 0;
6438 DEFVAR_BOOL ("x-underline-at-descent-line",
6439 &x_underline_at_descent_line
,
6440 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
6441 A value of nil means to draw the underline according to the value of the
6442 variable `x-use-underline-position-properties', which is usually at the
6443 baseline level. The default value is nil. */);
6444 x_underline_at_descent_line
= 0;
6446 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
6447 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
6448 Vx_toolkit_scroll_bars
= Qt
;
6450 staticpro (&last_mouse_motion_frame
);
6451 last_mouse_motion_frame
= Qnil
;
6454 /* arch-tag: 5fa70624-ab86-499c-8a85-473958ee4646
6455 (do not change this comment) */