1 /* Implementation of GUI terminal on the Microsoft Windows API.
3 Copyright (C) 1989, 1993-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24 #include "blockinput.h"
36 #include "character.h"
40 #include "dispextern.h"
42 #include "termhooks.h"
49 #include "intervals.h"
56 #include "w32.h" /* for filename_from_utf16, filename_from_ansi */
61 #include <io.h> /* for get_osfhandle */
71 static int max_fringe_bmp
= 0;
72 static HBITMAP
*fringe_bmp
= 0;
74 /* Temporary variables for w32_read_socket. */
76 static int last_mousemove_x
= 0;
77 static int last_mousemove_y
= 0;
79 /* Define GET_WHEEL_DELTA_WPARAM macro if system headers don't. */
80 #ifndef GET_WHEEL_DELTA_WPARAM
81 #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam))
84 /* Non-zero means that a HELP_EVENT has been generated since Emacs
87 static int any_help_event_p
;
89 extern unsigned int msh_mousewheel
;
91 extern void free_frame_menubar (struct frame
*);
93 extern int w32_codepage_for_font (char *fontname
);
94 extern Cursor
w32_load_cursor (LPCTSTR name
);
96 #define x_any_window_to_frame x_window_to_frame
97 #define x_top_window_to_frame x_window_to_frame
100 /* This is display since w32 does not support multiple ones. */
101 struct w32_display_info one_w32_display_info
;
102 struct w32_display_info
*x_display_list
;
104 #if _WIN32_WINNT < 0x0500 && !defined(_W64)
105 /* Pre Windows 2000, this was not available, but define it here so
106 that Emacs compiled on such a platform will run on newer versions.
107 MinGW64 (_W64) defines these unconditionally, so avoid redefining. */
109 typedef struct tagWCRANGE
115 typedef struct tagGLYPHSET
119 DWORD cGlyphsSupported
;
124 #endif /* compiling for pre-Win2k */
126 /* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */
127 BOOL (WINAPI
*pfnSetLayeredWindowAttributes
) (HWND
, COLORREF
, BYTE
, DWORD
);
130 #define LWA_ALPHA 0x02
132 /* WS_EX_LAYERED is defined unconditionally by MingW, but only for W2K and
133 later targets by MSVC headers. */
134 #ifndef WS_EX_LAYERED
135 #define WS_EX_LAYERED 0x80000
138 /* SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN are not defined on 95 and
140 #ifndef SM_CXVIRTUALSCREEN
141 #define SM_CXVIRTUALSCREEN 78
143 #ifndef SM_CYVIRTUALSCREEN
144 #define SM_CYVIRTUALSCREEN 79
147 /* The handle of the frame that currently owns the system caret. */
148 HWND w32_system_caret_hwnd
;
149 int w32_system_caret_height
;
150 int w32_system_caret_x
;
151 int w32_system_caret_y
;
152 struct window
*w32_system_caret_window
;
153 int w32_system_caret_hdr_height
;
154 int w32_system_caret_mode_height
;
155 DWORD dwWindowsThreadId
= 0;
156 HANDLE hWindowsThread
= NULL
;
157 DWORD dwMainThreadId
= 0;
158 HANDLE hMainThread
= NULL
;
160 int vertical_scroll_bar_min_handle
;
161 int horizontal_scroll_bar_min_handle
;
162 int vertical_scroll_bar_top_border
;
163 int vertical_scroll_bar_bottom_border
;
164 int horizontal_scroll_bar_left_border
;
165 int horizontal_scroll_bar_right_border
;
167 int last_scroll_bar_drag_pos
;
169 /* Keyboard code page - may be changed by language-change events. */
170 int w32_keyboard_codepage
;
172 /* Incremented by w32_read_socket whenever it really tries to read
174 static int volatile input_signal_count
;
177 int w32_message_fd
= -1;
180 static void w32_handle_tool_bar_click (struct frame
*,
181 struct input_event
*);
182 static void w32_define_cursor (Window
, Cursor
);
184 void x_lower_frame (struct frame
*);
185 void x_scroll_bar_clear (struct frame
*);
186 void x_wm_set_size_hint (struct frame
*, long, bool);
187 void x_raise_frame (struct frame
*);
188 void x_set_window_size (struct frame
*, int, int, int, bool);
189 void x_wm_set_window_state (struct frame
*, int);
190 void x_wm_set_icon_pixmap (struct frame
*, int);
191 static void w32_initialize (void);
192 static void x_update_end (struct frame
*);
193 static void w32_frame_up_to_date (struct frame
*);
194 static void x_clear_frame (struct frame
*);
195 static void frame_highlight (struct frame
*);
196 static void frame_unhighlight (struct frame
*);
197 static void x_new_focus_frame (struct w32_display_info
*,
199 static void x_focus_changed (int, int, struct w32_display_info
*,
200 struct frame
*, struct input_event
*);
201 static void w32_detect_focus_change (struct w32_display_info
*,
202 W32Msg
*, struct input_event
*);
203 static void w32_frame_rehighlight (struct frame
*);
204 static void x_frame_rehighlight (struct w32_display_info
*);
205 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
206 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
207 enum text_cursor_kinds
);
208 static void w32_clip_to_row (struct window
*, struct glyph_row
*,
209 enum glyph_row_area
, HDC
);
210 static BOOL
my_show_window (struct frame
*, HWND
, int);
211 static void my_set_window_pos (HWND
, HWND
, int, int, int, int, UINT
);
213 static void my_set_focus (struct frame
*, HWND
);
215 static void my_set_foreground_window (HWND
);
216 static void my_destroy_window (struct frame
*, HWND
);
217 static void w32fullscreen_hook (struct frame
*);
220 static void x_check_font (struct frame
*, struct font
*);
223 static Lisp_Object Qvendor_specific_keysyms
;
224 static Lisp_Object Qadded
, Qremoved
, Qmodified
;
225 static Lisp_Object Qrenamed_from
, Qrenamed_to
;
228 /***********************************************************************
230 ***********************************************************************/
234 /* This is a function useful for recording debugging information about
235 the sequence of occurrences in this file. */
243 struct record event_record
[100];
245 int event_record_index
;
247 record_event (char *locus
, int type
)
249 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
250 event_record_index
= 0;
252 event_record
[event_record_index
].locus
= locus
;
253 event_record
[event_record_index
].type
= type
;
254 event_record_index
++;
261 XChangeGC (void *ignore
, XGCValues
*gc
, unsigned long mask
,
264 if (mask
& GCForeground
)
265 gc
->foreground
= xgcv
->foreground
;
266 if (mask
& GCBackground
)
267 gc
->background
= xgcv
->background
;
269 gc
->font
= xgcv
->font
;
273 XCreateGC (void *ignore
, Window window
, unsigned long mask
, XGCValues
*xgcv
)
275 XGCValues
*gc
= xzalloc (sizeof (XGCValues
));
277 XChangeGC (ignore
, gc
, mask
, xgcv
);
283 XGetGCValues (void *ignore
, XGCValues
*gc
,
284 unsigned long mask
, XGCValues
*xgcv
)
286 XChangeGC (ignore
, xgcv
, mask
, gc
);
290 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
294 HRGN clip_region
= CreateRectRgnIndirect (rect
);
295 SelectClipRgn (hdc
, clip_region
);
296 DeleteObject (clip_region
);
299 SelectClipRgn (hdc
, NULL
);
302 /* Restore clipping rectangle in S */
304 w32_restore_glyph_string_clip (struct glyph_string
*s
)
307 int n
= s
->num_clips
;
310 w32_set_clip_rectangle (s
->hdc
, r
);
313 HRGN clip1
= CreateRectRgnIndirect (r
);
314 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
315 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
316 SelectClipRgn (s
->hdc
, clip1
);
317 DeleteObject (clip1
);
318 DeleteObject (clip2
);
323 Draw a wavy line under S. The wave fills wave_height pixels from y0.
329 wave_height = 3 | * * * *
334 w32_draw_underwave (struct glyph_string
*s
, COLORREF color
)
336 int wave_height
= 3, wave_length
= 2;
337 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
338 XRectangle wave_clip
, string_clip
, final_clip
;
339 RECT w32_final_clip
, w32_string_clip
;
343 dy
= wave_height
- 1;
345 y0
= s
->ybase
- wave_height
+ 3;
349 /* Find and set clipping rectangle */
353 wave_clip
.width
= width
;
354 wave_clip
.height
= wave_height
;
356 get_glyph_string_clip_rect (s
, &w32_string_clip
);
357 CONVERT_TO_XRECT (string_clip
, w32_string_clip
);
359 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
362 hp
= CreatePen (PS_SOLID
, 0, color
);
363 oldhp
= SelectObject (s
->hdc
, hp
);
364 CONVERT_FROM_XRECT (final_clip
, w32_final_clip
);
365 w32_set_clip_rectangle (s
->hdc
, &w32_final_clip
);
379 MoveToEx (s
->hdc
, x1
, y1
, NULL
);
383 LineTo (s
->hdc
, x2
, y2
);
385 x2
+= dx
, y2
= y0
+ odd
*dy
;
389 /* Restore previous pen and clipping rectangle(s) */
390 w32_restore_glyph_string_clip (s
);
391 SelectObject (s
->hdc
, oldhp
);
395 /* Draw a hollow rectangle at the specified position. */
397 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
398 int width
, int height
)
403 hb
= CreateSolidBrush (gc
->background
);
404 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
405 oldhb
= SelectObject (hdc
, hb
);
406 oldhp
= SelectObject (hdc
, hp
);
408 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
410 SelectObject (hdc
, oldhb
);
411 SelectObject (hdc
, oldhp
);
416 /* Draw a filled rectangle at the specified position. */
418 w32_fill_rect (struct frame
*f
, HDC hdc
, COLORREF pix
, RECT
*lprect
)
422 hb
= CreateSolidBrush (pix
);
423 FillRect (hdc
, lprect
, hb
);
428 w32_clear_window (struct frame
*f
)
431 HDC hdc
= get_frame_dc (f
);
433 /* Under certain conditions, this can be called at startup with
434 a console frame pointer before the GUI frame is created. An HDC
435 of 0 indicates this. */
438 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
439 w32_clear_rect (f
, hdc
, &rect
);
442 release_frame_dc (f
, hdc
);
445 #define OPAQUE_FRAME 255
448 x_set_frame_alpha (struct frame
*f
)
450 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
452 double alpha_min
= 1.0;
455 HWND window
= FRAME_W32_WINDOW (f
);
457 /* Older versions of Windows do not support transparency. */
458 if (!pfnSetLayeredWindowAttributes
)
461 if (dpyinfo
->w32_focus_frame
== f
)
466 if (FLOATP (Vframe_alpha_lower_limit
))
467 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
468 else if (INTEGERP (Vframe_alpha_lower_limit
))
469 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
473 else if (alpha
> 1.0)
475 else if (alpha
< alpha_min
&& alpha_min
<= 1.0)
478 opac
= alpha
* OPAQUE_FRAME
;
480 ex_style
= GetWindowLong (window
, GWL_EXSTYLE
);
482 if (opac
== OPAQUE_FRAME
)
483 ex_style
&= ~WS_EX_LAYERED
;
485 ex_style
|= WS_EX_LAYERED
;
487 SetWindowLong (window
, GWL_EXSTYLE
, ex_style
);
489 if (opac
!= OPAQUE_FRAME
)
490 pfnSetLayeredWindowAttributes (window
, 0, opac
, LWA_ALPHA
);
494 x_display_pixel_height (struct w32_display_info
*dpyinfo
)
496 int pixels
= GetSystemMetrics (SM_CYVIRTUALSCREEN
);
499 /* Fallback for Windows 95 or NT 4.0. */
500 pixels
= GetSystemMetrics (SM_CYSCREEN
);
506 x_display_pixel_width (struct w32_display_info
*dpyinfo
)
508 int pixels
= GetSystemMetrics (SM_CXVIRTUALSCREEN
);
511 /* Fallback for Windows 95 or NT 4.0. */
512 pixels
= GetSystemMetrics (SM_CXSCREEN
);
518 /***********************************************************************
519 Starting and ending an update
520 ***********************************************************************/
522 /* Start an update of frame F. This function is installed as a hook
523 for update_begin, i.e. it is called when update_begin is called.
524 This function is called prior to calls to x_update_window_begin for
525 each window being updated. */
528 x_update_begin (struct frame
*f
)
530 struct w32_display_info
*display_info
= FRAME_DISPLAY_INFO (f
);
532 if (! FRAME_W32_P (f
))
535 /* Regenerate display palette before drawing if list of requested
536 colors has changed. */
537 if (display_info
->regen_palette
)
539 w32_regenerate_palette (f
);
540 display_info
->regen_palette
= FALSE
;
545 /* Start update of window W. */
548 x_update_window_begin (struct window
*w
)
550 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
551 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
553 /* Hide the system caret during an update. */
554 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
556 SendMessage (w32_system_caret_hwnd
, WM_EMACS_HIDE_CARET
, 0, 0);
559 w
->output_cursor
= w
->cursor
;
563 if (f
== hlinfo
->mouse_face_mouse_frame
)
565 /* Don't do highlighting for mouse motion during the update. */
566 hlinfo
->mouse_face_defer
= 1;
568 /* If F needs to be redrawn, simply forget about any prior mouse
570 if (FRAME_GARBAGED_P (f
))
571 hlinfo
->mouse_face_window
= Qnil
;
573 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
574 their mouse_face_p flag set, which means that they are always
575 unequal to rows in a desired matrix which never have that
576 flag set. So, rows containing mouse-face glyphs are never
577 scrolled, and we don't have to switch the mouse highlight off
578 here to prevent it from being scrolled. */
580 /* Can we tell that this update does not affect the window
581 where the mouse highlight is? If so, no need to turn off.
582 Likewise, don't do anything if the frame is garbaged;
583 in that case, the frame's current matrix that we would use
584 is all wrong, and we will redisplay that line anyway. */
585 if (!NILP (hlinfo
->mouse_face_window
)
586 && w
== XWINDOW (hlinfo
->mouse_face_window
))
590 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
591 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
594 if (i
< w
->desired_matrix
->nrows
)
595 clear_mouse_face (hlinfo
);
603 /* Draw a vertical window border from (x,y0) to (x,y1) */
606 w32_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
608 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
618 hdc
= get_frame_dc (f
);
619 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
621 w32_fill_rect (f
, hdc
, face
->foreground
, &r
);
623 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
625 release_frame_dc (f
, hdc
);
629 /* Draw a window divider from (x0, y0) to (x1, y1) */
632 w32_draw_window_divider (struct window
*w
, int x0
, int x1
, int y0
, int y1
)
634 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
635 HDC hdc
= get_frame_dc (f
);
636 struct face
*face
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FACE_ID
);
637 struct face
*face_first
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
638 struct face
*face_last
= FACE_FROM_ID (f
, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
639 unsigned long color
= face
? face
->foreground
: FRAME_FOREGROUND_PIXEL (f
);
640 unsigned long color_first
= (face_first
641 ? face_first
->foreground
642 : FRAME_FOREGROUND_PIXEL (f
));
643 unsigned long color_last
= (face_last
644 ? face_last
->foreground
645 : FRAME_FOREGROUND_PIXEL (f
));
647 if (y1
- y0
> x1
- x0
&& x1
- x0
> 2)
650 w32_fill_area_abs (f
, hdc
, color_first
, x0
, y0
, x0
+ 1, y1
);
651 w32_fill_area_abs (f
, hdc
, color
, x0
+ 1, y0
, x1
- 1, y1
);
652 w32_fill_area_abs (f
, hdc
, color_last
, x1
- 1, y0
, x1
, y1
);
654 else if (x1
- x0
> y1
- y0
&& y1
- y0
> 3)
657 w32_fill_area_abs (f
, hdc
, color_first
, x0
, y0
, x1
, y0
+ 1);
658 w32_fill_area_abs (f
, hdc
, color
, x0
, y0
+ 1, x1
, y1
- 1);
659 w32_fill_area_abs (f
, hdc
, color_last
, x0
, y1
- 1, x1
, y1
);
662 w32_fill_area_abs (f
, hdc
, color
, x0
, y0
, x1
, y1
);
664 release_frame_dc (f
, hdc
);
667 /* End update of window W.
669 Draw vertical borders between horizontally adjacent windows, and
670 display W's cursor if CURSOR_ON_P is non-zero.
672 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
673 glyphs in mouse-face were overwritten. In that case we have to
674 make sure that the mouse-highlight is properly redrawn.
676 W may be a menu bar pseudo-window in case we don't have X toolkit
677 support. Such windows don't have a cursor, so don't display it
681 x_update_window_end (struct window
*w
, bool cursor_on_p
,
682 bool mouse_face_overwritten_p
)
684 if (!w
->pseudo_window_p
)
689 display_and_set_cursor (w
, 1,
690 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
691 w
->output_cursor
.x
, w
->output_cursor
.y
);
693 if (draw_window_fringes (w
, 1))
695 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
696 x_draw_right_divider (w
);
698 x_draw_vertical_border (w
);
704 /* If a row with mouse-face was overwritten, arrange for
705 XTframe_up_to_date to redisplay the mouse highlight. */
706 if (mouse_face_overwritten_p
)
708 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
710 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
711 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
712 hlinfo
->mouse_face_window
= Qnil
;
715 /* Unhide the caret. This won't actually show the cursor, unless it
716 was visible before the corresponding call to HideCaret in
717 x_update_window_begin. */
718 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
720 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
725 /* End update of frame F. This function is installed as a hook in
729 x_update_end (struct frame
*f
)
731 if (! FRAME_W32_P (f
))
734 /* Mouse highlight may be displayed again. */
735 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
739 /* This function is called from various places in xdisp.c
740 whenever a complete update has been performed. */
743 w32_frame_up_to_date (struct frame
*f
)
746 FRAME_MOUSE_UPDATE (f
);
750 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
751 arrow bitmaps, or clear the fringes if no bitmaps are required
752 before DESIRED_ROW is made current. This function is called from
753 update_window_line only if it is known that there are differences
754 between bitmaps to be drawn between current row and DESIRED_ROW. */
757 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
764 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
765 desired_row
->redraw_fringe_bitmaps_p
= 1;
767 /* When a window has disappeared, make sure that no rest of
768 full-width rows stays visible in the internal border. Could
769 check here if updated window is the leftmost/rightmost window,
770 but I guess it's not worth doing since vertically split windows
771 are almost never used, internal border is rarely set, and the
772 overhead is very small. */
773 if (windows_or_buffers_changed
774 && desired_row
->full_width_p
775 && (f
= XFRAME (w
->frame
),
776 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
778 && (height
= desired_row
->visible_height
,
781 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
785 HDC hdc
= get_frame_dc (f
);
786 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
787 w32_clear_area (f
, hdc
, FRAME_PIXEL_WIDTH (f
) - width
,
789 release_frame_dc (f
, hdc
);
796 /* Draw the bitmap WHICH in one of the left or right fringes of
797 window W. ROW is the glyph row for which to display the bitmap; it
798 determines the vertical position at which the bitmap has to be
802 w32_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
,
803 struct draw_fringe_bitmap_params
*p
)
805 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
807 struct face
*face
= p
->face
;
809 hdc
= get_frame_dc (f
);
811 /* Must clip because of partially visible lines. */
812 w32_clip_to_row (w
, row
, ANY_AREA
, hdc
);
814 if (p
->bx
>= 0 && !p
->overlay_p
)
815 w32_fill_area (f
, hdc
, face
->background
,
816 p
->bx
, p
->by
, p
->nx
, p
->ny
);
818 if (p
->which
&& p
->which
< max_fringe_bmp
)
820 HBITMAP pixmap
= fringe_bmp
[p
->which
];
824 compat_hdc
= CreateCompatibleDC (hdc
);
828 horig_obj
= SelectObject (compat_hdc
, pixmap
);
830 /* Paint overlays transparently. */
833 HBRUSH h_brush
, h_orig_brush
;
835 SetTextColor (hdc
, BLACK_PIX_DEFAULT (f
));
836 SetBkColor (hdc
, WHITE_PIX_DEFAULT (f
));
837 h_brush
= CreateSolidBrush (face
->foreground
);
838 h_orig_brush
= SelectObject (hdc
, h_brush
);
840 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
841 compat_hdc
, 0, p
->dh
,
843 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
844 compat_hdc
, 0, p
->dh
,
846 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
847 compat_hdc
, 0, p
->dh
,
850 SelectObject (hdc
, h_orig_brush
);
851 DeleteObject (h_brush
);
855 SetTextColor (hdc
, face
->background
);
856 SetBkColor (hdc
, (p
->cursor_p
857 ? f
->output_data
.w32
->cursor_pixel
858 : face
->foreground
));
860 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
861 compat_hdc
, 0, p
->dh
,
865 SelectObject (compat_hdc
, horig_obj
);
866 DeleteDC (compat_hdc
);
870 w32_set_clip_rectangle (hdc
, NULL
);
872 release_frame_dc (f
, hdc
);
876 w32_define_fringe_bitmap (int which
, unsigned short *bits
, int h
, int wd
)
878 if (which
>= max_fringe_bmp
)
880 int i
= max_fringe_bmp
;
881 max_fringe_bmp
= which
+ 20;
882 fringe_bmp
= (HBITMAP
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (HBITMAP
));
883 while (i
< max_fringe_bmp
)
887 fringe_bmp
[which
] = CreateBitmap (wd
, h
, 1, 1, bits
);
891 w32_destroy_fringe_bitmap (int which
)
893 if (which
>= max_fringe_bmp
)
896 if (fringe_bmp
[which
])
897 DeleteObject (fringe_bmp
[which
]);
898 fringe_bmp
[which
] = 0;
901 /***********************************************************************
903 ***********************************************************************/
905 /* Function prototypes of this page. */
907 static void x_set_glyph_string_clipping (struct glyph_string
*);
908 static void x_set_glyph_string_gc (struct glyph_string
*);
909 static void x_draw_glyph_string_background (struct glyph_string
*,
911 static void x_draw_glyph_string_foreground (struct glyph_string
*);
912 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
913 static void x_draw_glyph_string_box (struct glyph_string
*);
914 static void x_draw_glyph_string (struct glyph_string
*);
915 static void x_set_cursor_gc (struct glyph_string
*);
916 static void x_set_mode_line_face_gc (struct glyph_string
*);
917 static void x_set_mouse_face_gc (struct glyph_string
*);
918 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
919 static void w32_setup_relief_color (struct frame
*, struct relief
*,
920 double, int, COLORREF
);
921 static void x_setup_relief_colors (struct glyph_string
*);
922 static void x_draw_image_glyph_string (struct glyph_string
*);
923 static void x_draw_image_relief (struct glyph_string
*);
924 static void x_draw_image_foreground (struct glyph_string
*);
925 static void w32_draw_image_foreground_1 (struct glyph_string
*, HBITMAP
);
926 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
928 static void w32_draw_relief_rect (struct frame
*, int, int, int, int,
929 int, int, int, int, int, int,
931 static void w32_draw_box_rect (struct glyph_string
*, int, int, int, int,
932 int, int, int, RECT
*);
935 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
939 x_set_cursor_gc (struct glyph_string
*s
)
941 if (s
->font
== FRAME_FONT (s
->f
)
942 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
943 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
945 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
948 /* Cursor on non-default face: must merge. */
952 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
953 xgcv
.foreground
= s
->face
->background
;
955 /* If the glyph would be invisible, try a different foreground. */
956 if (xgcv
.foreground
== xgcv
.background
)
957 xgcv
.foreground
= s
->face
->foreground
;
958 if (xgcv
.foreground
== xgcv
.background
)
959 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
960 if (xgcv
.foreground
== xgcv
.background
)
961 xgcv
.foreground
= s
->face
->foreground
;
963 /* Make sure the cursor is distinct from text in this face. */
964 if (xgcv
.background
== s
->face
->background
965 && xgcv
.foreground
== s
->face
->foreground
)
967 xgcv
.background
= s
->face
->foreground
;
968 xgcv
.foreground
= s
->face
->background
;
971 IF_DEBUG (x_check_font (s
->f
, s
->font
));
973 mask
= GCForeground
| GCBackground
| GCFont
;
975 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
976 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
979 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
980 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
982 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
987 /* Set up S->gc of glyph string S for drawing text in mouse face. */
990 x_set_mouse_face_gc (struct glyph_string
*s
)
995 /* What face has to be used last for the mouse face? */
996 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
997 face
= FACE_FROM_ID (s
->f
, face_id
);
999 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1001 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1002 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1004 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1005 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1006 prepare_face_for_display (s
->f
, s
->face
);
1008 /* If font in this face is same as S->font, use it. */
1009 if (s
->font
== s
->face
->font
)
1010 s
->gc
= s
->face
->gc
;
1013 /* Otherwise construct scratch_cursor_gc with values from FACE
1018 xgcv
.background
= s
->face
->background
;
1019 xgcv
.foreground
= s
->face
->foreground
;
1020 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1021 xgcv
.font
= s
->font
;
1022 mask
= GCForeground
| GCBackground
| GCFont
;
1024 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1025 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1028 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1029 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
1031 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1034 eassert (s
->gc
!= 0);
1038 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1039 Faces to use in the mode line have already been computed when the
1040 matrix was built, so there isn't much to do, here. */
1043 x_set_mode_line_face_gc (struct glyph_string
*s
)
1045 s
->gc
= s
->face
->gc
;
1049 /* Set S->gc of glyph string S for drawing that glyph string. Set
1050 S->stippled_p to a non-zero value if the face of S has a stipple
1054 x_set_glyph_string_gc (struct glyph_string
*s
)
1056 prepare_face_for_display (s
->f
, s
->face
);
1058 if (s
->hl
== DRAW_NORMAL_TEXT
)
1060 s
->gc
= s
->face
->gc
;
1061 s
->stippled_p
= s
->face
->stipple
!= 0;
1063 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1065 x_set_mode_line_face_gc (s
);
1066 s
->stippled_p
= s
->face
->stipple
!= 0;
1068 else if (s
->hl
== DRAW_CURSOR
)
1070 x_set_cursor_gc (s
);
1073 else if (s
->hl
== DRAW_MOUSE_FACE
)
1075 x_set_mouse_face_gc (s
);
1076 s
->stippled_p
= s
->face
->stipple
!= 0;
1078 else if (s
->hl
== DRAW_IMAGE_RAISED
1079 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1081 s
->gc
= s
->face
->gc
;
1082 s
->stippled_p
= s
->face
->stipple
!= 0;
1087 /* GC must have been set. */
1088 eassert (s
->gc
!= 0);
1092 /* Set clipping for output of glyph string S. S may be part of a mode
1093 line or menu if we don't have X toolkit support. */
1096 x_set_glyph_string_clipping (struct glyph_string
*s
)
1099 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1102 w32_set_clip_rectangle (s
->hdc
, r
);
1105 HRGN clip1
= CreateRectRgnIndirect (r
);
1106 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
1107 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
1108 SelectClipRgn (s
->hdc
, clip1
);
1109 DeleteObject (clip1
);
1110 DeleteObject (clip2
);
1115 /* Set SRC's clipping for output of glyph string DST. This is called
1116 when we are drawing DST's left_overhang or right_overhang only in
1120 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
,
1121 struct glyph_string
*dst
)
1126 r
.right
= r
.left
+ src
->width
;
1128 r
.bottom
= r
.top
+ src
->height
;
1131 w32_set_clip_rectangle (dst
->hdc
, &r
);
1135 Compute left and right overhang of glyph string S. */
1138 w32_compute_glyph_string_overhangs (struct glyph_string
*s
)
1141 && s
->first_glyph
->type
== CHAR_GLYPH
1142 && !s
->font_not_found_p
)
1144 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1145 struct font
*font
= s
->font
;
1146 struct font_metrics metrics
;
1149 for (i
= 0; i
< s
->nchars
; i
++)
1150 code
[i
] = s
->char2b
[i
];
1151 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1152 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1153 ? metrics
.rbearing
- metrics
.width
: 0);
1154 s
->left_overhang
= metrics
.lbearing
< 0 ? -metrics
.lbearing
: 0;
1158 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1159 s
->left_overhang
= -s
->cmp
->lbearing
;
1163 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1166 x_clear_glyph_string_rect (struct glyph_string
*s
,
1167 int x
, int y
, int w
, int h
)
1174 /* Take clipping into account. */
1175 if (s
->gc
->clip_mask
== Rect
)
1177 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
1178 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
1179 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
1180 - s
->gc
->clip_rectangle
.left
);
1181 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
1182 - s
->gc
->clip_rectangle
.top
);
1185 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
1190 /* Draw the background of glyph_string S. If S->background_filled_p
1191 is non-zero don't draw it. FORCE_P non-zero means draw the
1192 background even if it wouldn't be drawn normally. This is used
1193 when a string preceding S draws into the background of S, or S
1194 contains the first component of a composition. */
1197 x_draw_glyph_string_background (struct glyph_string
*s
, int force_p
)
1199 /* Nothing to do if background has already been drawn or if it
1200 shouldn't be drawn in the first place. */
1201 if (!s
->background_filled_p
)
1203 int box_line_width
= max (s
->face
->box_line_width
, 0);
1205 #if 0 /* TODO: stipple */
1208 /* Fill background with a stipple pattern. */
1209 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1210 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1211 s
->y
+ box_line_width
,
1212 s
->background_width
,
1213 s
->height
- 2 * box_line_width
);
1214 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1215 s
->background_filled_p
= 1;
1219 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1220 || s
->font_not_found_p
1221 || s
->extends_to_end_of_line_p
1224 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1225 s
->background_width
,
1226 s
->height
- 2 * box_line_width
);
1227 s
->background_filled_p
= 1;
1233 /* Draw the foreground of glyph string S. */
1236 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1240 /* If first glyph of S has a left box line, start drawing the text
1241 of S to the right of that box line. */
1242 if (s
->face
->box
!= FACE_NO_BOX
1243 && s
->first_glyph
->left_box_line_p
)
1244 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1248 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1249 SetBkColor (s
->hdc
, s
->gc
->background
);
1250 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1252 /* Draw characters of S as rectangles if S's font could not be
1254 if (s
->font_not_found_p
)
1256 for (i
= 0; i
< s
->nchars
; ++i
)
1258 struct glyph
*g
= s
->first_glyph
+ i
;
1260 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1262 x
+= g
->pixel_width
;
1267 struct font
*font
= s
->font
;
1268 int boff
= font
->baseline_offset
;
1272 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1274 if (font
->vertical_centering
)
1275 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1277 y
= s
->ybase
- boff
;
1279 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1280 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1282 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1283 if (s
->face
->overstrike
)
1284 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1286 SelectObject (s
->hdc
, old_font
);
1290 /* Draw the foreground of composite glyph string S. */
1293 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1296 struct font
*font
= s
->font
;
1298 /* If first glyph of S has a left box line, start drawing the text
1299 of S to the right of that box line. */
1300 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1301 && s
->first_glyph
->left_box_line_p
)
1302 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1306 /* S is a glyph string for a composition. S->cmp_from is the index
1307 of the first character drawn for glyphs of this composition.
1308 S->cmp_from == 0 means we are drawing the very first character of
1309 this composition. */
1311 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1312 SetBkColor (s
->hdc
, s
->gc
->background
);
1313 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1315 /* Draw a rectangle for the composition if the font for the very
1316 first character of the composition could not be loaded. */
1317 if (s
->font_not_found_p
)
1319 if (s
->cmp_from
== 0)
1320 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
1323 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1328 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1330 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1331 /* TAB in a composition means display glyphs with padding
1332 space on the left or right. */
1333 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1335 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1336 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1338 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1339 if (s
->face
->overstrike
)
1340 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1342 SelectObject (s
->hdc
, old_font
);
1346 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1352 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1354 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1356 glyph
= LGSTRING_GLYPH (gstring
, i
);
1357 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1358 width
+= LGLYPH_WIDTH (glyph
);
1361 int xoff
, yoff
, wadjust
;
1365 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1368 xoff
= LGLYPH_XOFF (glyph
);
1369 yoff
= LGLYPH_YOFF (glyph
);
1370 wadjust
= LGLYPH_WADJUST (glyph
);
1371 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1378 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1380 SelectObject (s
->hdc
, old_font
);
1385 /* Draw the foreground of glyph string S for glyphless characters. */
1388 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1390 struct glyph
*glyph
= s
->first_glyph
;
1393 int with_background
;
1395 /* If first glyph of S has a left box line, start drawing the text
1396 of S to the right of that box line. */
1397 if (s
->face
->box
!= FACE_NO_BOX
1398 && s
->first_glyph
->left_box_line_p
)
1399 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1403 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1404 SetBkColor (s
->hdc
, s
->gc
->background
);
1405 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1408 with_background
= ! (s
->for_overlaps
1409 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
));
1410 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1412 char buf
[7], *str
= NULL
;
1413 int len
= glyph
->u
.glyphless
.len
;
1415 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1418 && CHAR_TABLE_P (Vglyphless_char_display
)
1419 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1423 = (! glyph
->u
.glyphless
.for_no_font
1424 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1425 glyph
->u
.glyphless
.ch
)
1426 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1427 if (STRINGP (acronym
))
1428 str
= SSDATA (acronym
);
1431 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1433 sprintf ((char *) buf
, "%0*X",
1434 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1435 glyph
->u
.glyphless
.ch
);
1439 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1440 w32_draw_rectangle (s
->hdc
, s
->gc
,
1441 x
, s
->ybase
- glyph
->ascent
,
1442 glyph
->pixel_width
- 1,
1443 glyph
->ascent
+ glyph
->descent
- 1);
1446 struct font
*font
= s
->font
;
1447 int upper_len
= (len
+ 1) / 2;
1451 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1452 /* It is certain that all LEN characters in STR are ASCII. */
1453 for (j
= 0; j
< len
; j
++)
1455 code
= font
->driver
->encode_char (font
, str
[j
]);
1456 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1458 font
->driver
->draw (s
, 0, upper_len
,
1459 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1460 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1462 font
->driver
->draw (s
, upper_len
, len
,
1463 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1464 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1466 SelectObject (s
->hdc
, old_font
);
1468 x
+= glyph
->pixel_width
;
1473 /* Brightness beyond which a color won't have its highlight brightness
1476 Nominally, highlight colors for `3d' faces are calculated by
1477 brightening an object's color by a constant scale factor, but this
1478 doesn't yield good results for dark colors, so for colors whose
1479 brightness is less than this value (on a scale of 0-255) have to
1480 use an additional additive factor.
1482 The value here is set so that the default menu-bar/mode-line color
1483 (grey75) will not have its highlights changed at all. */
1484 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
1487 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
1488 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1489 If this produces the same color as COLOR, try a color where all RGB
1490 values have DELTA added. Return the allocated color in *COLOR.
1491 DISPLAY is the X display, CMAP is the colormap to operate on.
1492 Value is non-zero if successful. */
1495 w32_alloc_lighter_color (struct frame
*f
, COLORREF
*color
,
1496 double factor
, int delta
)
1501 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
1504 /* Change RGB values by specified FACTOR. Avoid overflow! */
1505 eassert (factor
>= 0);
1506 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
1507 min (0xff, factor
* GetGValue (*color
)),
1508 min (0xff, factor
* GetBValue (*color
)));
1510 /* Calculate brightness of COLOR. */
1511 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
1512 + GetBValue (*color
)) / 6;
1514 /* We only boost colors that are darker than
1515 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1516 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1517 /* Make an additive adjustment to NEW, because it's dark enough so
1518 that scaling by FACTOR alone isn't enough. */
1520 /* How far below the limit this color is (0 - 1, 1 being darker). */
1521 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1522 /* The additive adjustment. */
1523 int min_delta
= delta
* dimness
* factor
/ 2;
1526 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
1527 max (0, min (0xff, min_delta
- GetGValue (*color
))),
1528 max (0, min (0xff, min_delta
- GetBValue (*color
))));
1530 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
1531 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
1532 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
1536 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
1537 max (0, min (0xff, delta
+ GetGValue (*color
))),
1538 max (0, min (0xff, delta
+ GetBValue (*color
))));
1540 /* TODO: Map to palette and retry with delta if same? */
1541 /* TODO: Free colors (if using palette)? */
1551 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1552 colors in COLORS. On W32, we no longer try to map colors to
1555 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1559 for (i
= 0; i
< ncolors
; i
++)
1561 DWORD pixel
= colors
[i
].pixel
;
1562 /* Convert to a 16 bit value in range 0 - 0xffff. */
1563 colors
[i
].red
= GetRValue (pixel
) * 257;
1564 colors
[i
].green
= GetGValue (pixel
) * 257;
1565 colors
[i
].blue
= GetBValue (pixel
) * 257;
1570 x_query_color (struct frame
*f
, XColor
*color
)
1572 x_query_colors (f
, color
, 1);
1576 /* Set up the foreground color for drawing relief lines of glyph
1577 string S. RELIEF is a pointer to a struct relief containing the GC
1578 with which lines will be drawn. Use a color that is FACTOR or
1579 DELTA lighter or darker than the relief's background which is found
1580 in S->f->output_data.x->relief_background. If such a color cannot
1581 be allocated, use DEFAULT_PIXEL, instead. */
1584 w32_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
,
1585 int delta
, COLORREF default_pixel
)
1588 struct w32_output
*di
= f
->output_data
.w32
;
1589 unsigned long mask
= GCForeground
;
1591 COLORREF background
= di
->relief_background
;
1592 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1594 /* TODO: Free colors (if using palette)? */
1596 /* Allocate new color. */
1597 xgcv
.foreground
= default_pixel
;
1599 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
1600 xgcv
.foreground
= relief
->pixel
= pixel
;
1602 if (relief
->gc
== 0)
1604 #if 0 /* TODO: stipple */
1605 xgcv
.stipple
= dpyinfo
->gray
;
1608 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
1611 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
1615 /* Set up colors for the relief lines around glyph string S. */
1618 x_setup_relief_colors (struct glyph_string
*s
)
1620 struct w32_output
*di
= s
->f
->output_data
.w32
;
1623 if (s
->face
->use_box_color_for_shadows_p
)
1624 color
= s
->face
->box_color
;
1625 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1627 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1628 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1630 color
= s
->gc
->background
;
1632 if (di
->white_relief
.gc
== 0
1633 || color
!= di
->relief_background
)
1635 di
->relief_background
= color
;
1636 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1637 WHITE_PIX_DEFAULT (s
->f
));
1638 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1639 BLACK_PIX_DEFAULT (s
->f
));
1644 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1645 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1646 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1647 relief. LEFT_P non-zero means draw a relief on the left side of
1648 the rectangle. RIGHT_P non-zero means draw a relief on the right
1649 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1653 w32_draw_relief_rect (struct frame
*f
,
1654 int left_x
, int top_y
, int right_x
, int bottom_y
,
1655 int width
, int raised_p
,
1656 int top_p
, int bot_p
, int left_p
, int right_p
,
1661 HDC hdc
= get_frame_dc (f
);
1664 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1666 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1668 w32_set_clip_rectangle (hdc
, clip_rect
);
1672 for (i
= 0; i
< width
; ++i
)
1673 w32_fill_area (f
, hdc
, gc
.foreground
,
1674 left_x
+ i
* left_p
, top_y
+ i
,
1675 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1679 for (i
= 0; i
< width
; ++i
)
1680 w32_fill_area (f
, hdc
, gc
.foreground
,
1681 left_x
+ i
, top_y
+ (i
+ 1) * top_p
, 1,
1682 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1685 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1687 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1691 for (i
= 0; i
< width
; ++i
)
1692 w32_fill_area (f
, hdc
, gc
.foreground
,
1693 left_x
+ i
* left_p
, bottom_y
- i
,
1694 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1698 for (i
= 0; i
< width
; ++i
)
1699 w32_fill_area (f
, hdc
, gc
.foreground
,
1700 right_x
- i
, top_y
+ (i
+ 1) * top_p
, 1,
1701 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1703 w32_set_clip_rectangle (hdc
, NULL
);
1705 release_frame_dc (f
, hdc
);
1709 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1710 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1711 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
1712 left side of the rectangle. RIGHT_P non-zero means draw a line
1713 on the right side of the rectangle. CLIP_RECT is the clipping
1714 rectangle to use when drawing. */
1717 w32_draw_box_rect (struct glyph_string
*s
,
1718 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1719 int left_p
, int right_p
, RECT
*clip_rect
)
1721 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
1724 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1725 left_x
, top_y
, right_x
- left_x
+ 1, width
);
1730 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1731 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
1735 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1736 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
1741 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1742 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
1745 w32_set_clip_rectangle (s
->hdc
, NULL
);
1749 /* Draw a box around glyph string S. */
1752 x_draw_glyph_string_box (struct glyph_string
*s
)
1754 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
1755 int left_p
, right_p
;
1756 struct glyph
*last_glyph
;
1759 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
1760 ? WINDOW_RIGHT_EDGE_X (s
->w
)
1761 : window_box_right (s
->w
, s
->area
));
1763 /* The glyph that may have a right box line. */
1764 last_glyph
= (s
->cmp
|| s
->img
1766 : s
->first_glyph
+ s
->nchars
- 1);
1768 width
= eabs (s
->face
->box_line_width
);
1769 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
1771 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
1773 : min (last_x
, s
->x
+ s
->background_width
) - 1));
1775 bottom_y
= top_y
+ s
->height
- 1;
1777 left_p
= (s
->first_glyph
->left_box_line_p
1778 || (s
->hl
== DRAW_MOUSE_FACE
1780 || s
->prev
->hl
!= s
->hl
)));
1781 right_p
= (last_glyph
->right_box_line_p
1782 || (s
->hl
== DRAW_MOUSE_FACE
1784 || s
->next
->hl
!= s
->hl
)));
1786 get_glyph_string_clip_rect (s
, &clip_rect
);
1788 if (s
->face
->box
== FACE_SIMPLE_BOX
)
1789 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
1790 left_p
, right_p
, &clip_rect
);
1793 x_setup_relief_colors (s
);
1794 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
1795 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
1800 /* Draw foreground of image glyph string S. */
1803 x_draw_image_foreground (struct glyph_string
*s
)
1806 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1808 /* If first glyph of S has a left box line, start drawing it to the
1809 right of that line. */
1810 if (s
->face
->box
!= FACE_NO_BOX
1811 && s
->first_glyph
->left_box_line_p
1813 x
+= eabs (s
->face
->box_line_width
);
1815 /* If there is a margin around the image, adjust x- and y-position
1817 if (s
->slice
.x
== 0)
1818 x
+= s
->img
->hmargin
;
1819 if (s
->slice
.y
== 0)
1820 y
+= s
->img
->vmargin
;
1826 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
1827 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1828 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
1829 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1830 SetBkColor (compat_hdc
, RGB (255, 255, 255));
1831 SetTextColor (s
->hdc
, RGB (0, 0, 0));
1832 x_set_glyph_string_clipping (s
);
1836 HDC mask_dc
= CreateCompatibleDC (s
->hdc
);
1837 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1839 SetTextColor (s
->hdc
, RGB (255, 255, 255));
1840 SetBkColor (s
->hdc
, RGB (0, 0, 0));
1842 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1843 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1844 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1845 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
1846 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1847 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1849 SelectObject (mask_dc
, mask_orig_obj
);
1854 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1855 SetBkColor (s
->hdc
, s
->gc
->background
);
1857 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1858 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
1860 /* When the image has a mask, we can expect that at
1861 least part of a mouse highlight or a block cursor will
1862 be visible. If the image doesn't have a mask, make
1863 a block cursor visible by drawing a rectangle around
1864 the image. I believe it's looking better if we do
1865 nothing here for mouse-face. */
1866 if (s
->hl
== DRAW_CURSOR
)
1868 int r
= s
->img
->relief
;
1870 w32_draw_rectangle (s
->hdc
, s
->gc
, x
- r
, y
- r
,
1871 s
->slice
.width
+ r
*2 - 1,
1872 s
->slice
.height
+ r
*2 - 1);
1876 w32_set_clip_rectangle (s
->hdc
, NULL
);
1877 SelectObject (s
->hdc
, orig_brush
);
1878 DeleteObject (fg_brush
);
1879 SelectObject (compat_hdc
, orig_obj
);
1880 DeleteDC (compat_hdc
);
1883 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
,
1884 s
->slice
.width
- 1, s
->slice
.height
- 1);
1886 RestoreDC (s
->hdc
,-1);
1890 /* Draw a relief around the image glyph string S. */
1893 x_draw_image_relief (struct glyph_string
*s
)
1895 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
1896 int extra_x
, extra_y
;
1899 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1901 /* If first glyph of S has a left box line, start drawing it to the
1902 right of that line. */
1903 if (s
->face
->box
!= FACE_NO_BOX
1904 && s
->first_glyph
->left_box_line_p
1906 x
+= eabs (s
->face
->box_line_width
);
1908 /* If there is a margin around the image, adjust x- and y-position
1910 if (s
->slice
.x
== 0)
1911 x
+= s
->img
->hmargin
;
1912 if (s
->slice
.y
== 0)
1913 y
+= s
->img
->vmargin
;
1915 if (s
->hl
== DRAW_IMAGE_SUNKEN
1916 || s
->hl
== DRAW_IMAGE_RAISED
)
1918 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
1919 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
1920 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
1924 thick
= eabs (s
->img
->relief
);
1925 raised_p
= s
->img
->relief
> 0;
1928 x1
= x
+ s
->slice
.width
- 1;
1929 y1
= y
+ s
->slice
.height
- 1;
1931 extra_x
= extra_y
= 0;
1932 if (s
->face
->id
== TOOL_BAR_FACE_ID
)
1934 if (CONSP (Vtool_bar_button_margin
)
1935 && INTEGERP (XCAR (Vtool_bar_button_margin
))
1936 && INTEGERP (XCDR (Vtool_bar_button_margin
)))
1938 extra_x
= XINT (XCAR (Vtool_bar_button_margin
));
1939 extra_y
= XINT (XCDR (Vtool_bar_button_margin
));
1941 else if (INTEGERP (Vtool_bar_button_margin
))
1942 extra_x
= extra_y
= XINT (Vtool_bar_button_margin
);
1945 top_p
= bot_p
= left_p
= right_p
= 0;
1947 if (s
->slice
.x
== 0)
1948 x
-= thick
+ extra_x
, left_p
= 1;
1949 if (s
->slice
.y
== 0)
1950 y
-= thick
+ extra_y
, top_p
= 1;
1951 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
1952 x1
+= thick
+ extra_x
, right_p
= 1;
1953 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
1954 y1
+= thick
+ extra_y
, bot_p
= 1;
1956 x_setup_relief_colors (s
);
1957 get_glyph_string_clip_rect (s
, &r
);
1958 w32_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
1959 top_p
, bot_p
, left_p
, right_p
, &r
);
1963 /* Draw the foreground of image glyph string S to PIXMAP. */
1966 w32_draw_image_foreground_1 (struct glyph_string
*s
, HBITMAP pixmap
)
1968 HDC hdc
= CreateCompatibleDC (s
->hdc
);
1969 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
1971 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1973 /* If first glyph of S has a left box line, start drawing it to the
1974 right of that line. */
1975 if (s
->face
->box
!= FACE_NO_BOX
1976 && s
->first_glyph
->left_box_line_p
1978 x
+= eabs (s
->face
->box_line_width
);
1980 /* If there is a margin around the image, adjust x- and y-position
1982 if (s
->slice
.x
== 0)
1983 x
+= s
->img
->hmargin
;
1984 if (s
->slice
.y
== 0)
1985 y
+= s
->img
->vmargin
;
1989 HDC compat_hdc
= CreateCompatibleDC (hdc
);
1990 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1991 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
1992 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1996 HDC mask_dc
= CreateCompatibleDC (hdc
);
1997 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1999 SetTextColor (hdc
, RGB (0, 0, 0));
2000 SetBkColor (hdc
, RGB (255, 255, 255));
2001 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2002 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
2003 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2004 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
2005 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2006 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
2008 SelectObject (mask_dc
, mask_orig_obj
);
2013 SetTextColor (hdc
, s
->gc
->foreground
);
2014 SetBkColor (hdc
, s
->gc
->background
);
2016 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2017 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
2019 /* When the image has a mask, we can expect that at
2020 least part of a mouse highlight or a block cursor will
2021 be visible. If the image doesn't have a mask, make
2022 a block cursor visible by drawing a rectangle around
2023 the image. I believe it's looking better if we do
2024 nothing here for mouse-face. */
2025 if (s
->hl
== DRAW_CURSOR
)
2027 int r
= s
->img
->relief
;
2029 w32_draw_rectangle (hdc
, s
->gc
, x
- r
, y
- r
,
2030 s
->slice
.width
+ r
*2 - 1,
2031 s
->slice
.height
+ r
*2 - 1);
2035 SelectObject (hdc
, orig_brush
);
2036 DeleteObject (fg_brush
);
2037 SelectObject (compat_hdc
, orig_obj
);
2038 DeleteDC (compat_hdc
);
2041 w32_draw_rectangle (hdc
, s
->gc
, x
, y
,
2042 s
->slice
.width
- 1, s
->slice
.height
- 1);
2044 SelectObject (hdc
, orig_hdc_obj
);
2049 /* Draw part of the background of glyph string S. X, Y, W, and H
2050 give the rectangle to draw. */
2053 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2055 #if 0 /* TODO: stipple */
2058 /* Fill background with a stipple pattern. */
2059 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2060 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2061 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2065 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2069 /* Draw image glyph string S.
2072 s->x +-------------------------
2075 | +-------------------------
2078 | | +-------------------
2084 x_draw_image_glyph_string (struct glyph_string
*s
)
2087 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2088 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2093 if (s
->slice
.y
== 0)
2094 height
-= box_line_vwidth
;
2095 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2096 height
-= box_line_vwidth
;
2098 /* Fill background with face under the image. Do it only if row is
2099 taller than image or if image has a clip mask to reduce
2101 s
->stippled_p
= s
->face
->stipple
!= 0;
2102 if (height
> s
->slice
.height
2106 || s
->img
->pixmap
== 0
2107 || s
->width
!= s
->background_width
)
2109 width
= s
->background_width
;
2111 if (s
->first_glyph
->left_box_line_p
2114 x
+= box_line_hwidth
;
2115 width
-= box_line_hwidth
;
2119 if (s
->slice
.y
== 0)
2120 y
+= box_line_vwidth
;
2122 #if 0 /* TODO: figure out if we need to do this on Windows. */
2125 /* Create a pixmap as large as the glyph string. Fill it
2126 with the background color. Copy the image to it, using
2127 its mask. Copy the temporary pixmap to the display. */
2128 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2129 int depth
= DefaultDepthOfScreen (screen
);
2131 /* Create a pixmap as large as the glyph string. */
2132 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2133 s
->background_width
,
2136 /* Don't clip in the following because we're working on the
2138 XSetClipMask (s
->display
, s
->gc
, None
);
2140 /* Fill the pixmap with the background color/stipple. */
2143 /* Fill background with a stipple pattern. */
2144 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2145 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2146 0, 0, s
->background_width
, s
->height
);
2147 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2152 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2154 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2155 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2156 0, 0, s
->background_width
, s
->height
);
2157 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2162 x_draw_glyph_string_bg_rect (s
, x
, y
, width
, height
);
2164 s
->background_filled_p
= 1;
2167 /* Draw the foreground. */
2170 w32_draw_image_foreground_1 (s
, pixmap
);
2171 x_set_glyph_string_clipping (s
);
2173 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
2174 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
2175 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
2176 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
2178 SetTextColor (s
->hdc
, s
->gc
->foreground
);
2179 SetBkColor (s
->hdc
, s
->gc
->background
);
2180 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
2181 compat_hdc
, 0, 0, SRCCOPY
);
2183 SelectObject (s
->hdc
, orig_brush
);
2184 DeleteObject (fg_brush
);
2185 SelectObject (compat_hdc
, orig_obj
);
2186 DeleteDC (compat_hdc
);
2188 DeleteObject (pixmap
);
2192 x_draw_image_foreground (s
);
2194 /* If we must draw a relief around the image, do it. */
2196 || s
->hl
== DRAW_IMAGE_RAISED
2197 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2198 x_draw_image_relief (s
);
2202 /* Draw stretch glyph string S. */
2205 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2207 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2209 if (s
->hl
== DRAW_CURSOR
2210 && !x_stretch_cursor_p
)
2212 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2213 wide as the stretch glyph. */
2214 int width
, background_width
= s
->background_width
;
2217 if (!s
->row
->reversed_p
)
2219 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2223 background_width
-= left_x
- x
;
2229 /* In R2L rows, draw the cursor on the right edge of the
2231 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2233 if (x
+ background_width
> right_x
)
2234 background_width
-= x
- right_x
;
2235 x
+= background_width
;
2237 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2238 if (s
->row
->reversed_p
)
2242 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2244 /* Clear rest using the GC of the original non-cursor face. */
2245 if (width
< background_width
)
2247 XGCValues
*gc
= s
->face
->gc
;
2249 int w
= background_width
- width
, h
= s
->height
;
2253 if (!s
->row
->reversed_p
)
2257 if (s
->row
->mouse_face_p
2258 && cursor_in_mouse_face_p (s
->w
))
2260 x_set_mouse_face_gc (s
);
2266 get_glyph_string_clip_rect (s
, &r
);
2267 w32_set_clip_rectangle (hdc
, &r
);
2269 #if 0 /* TODO: stipple */
2270 if (s
->face
->stipple
)
2272 /* Fill background with a stipple pattern. */
2273 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2274 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2275 XSetFillStyle (s
->display
, gc
, FillSolid
);
2280 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
2284 else if (!s
->background_filled_p
)
2286 int background_width
= s
->background_width
;
2287 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2289 /* Don't draw into left margin, fringe or scrollbar area
2290 except for header line and mode line. */
2291 if (x
< left_x
&& !s
->row
->mode_line_p
)
2293 background_width
-= left_x
- x
;
2296 if (background_width
> 0)
2297 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2300 s
->background_filled_p
= 1;
2304 /* Draw glyph string S. */
2307 x_draw_glyph_string (struct glyph_string
*s
)
2309 bool relief_drawn_p
= 0;
2311 /* If S draws into the background of its successor, draw the
2312 background of the successor first so that S can draw into it.
2313 This makes S->next use XDrawString instead of XDrawImageString. */
2314 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2317 struct glyph_string
*next
;
2318 for (width
= 0, next
= s
->next
;
2319 next
&& width
< s
->right_overhang
;
2320 width
+= next
->width
, next
= next
->next
)
2321 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2323 x_set_glyph_string_gc (next
);
2324 x_set_glyph_string_clipping (next
);
2325 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2326 x_draw_stretch_glyph_string (next
);
2328 x_draw_glyph_string_background (next
, 1);
2329 next
->num_clips
= 0;
2333 /* Set up S->gc, set clipping and draw S. */
2334 x_set_glyph_string_gc (s
);
2336 /* Draw relief (if any) in advance for char/composition so that the
2337 glyph string can be drawn over it. */
2338 if (!s
->for_overlaps
2339 && s
->face
->box
!= FACE_NO_BOX
2340 && (s
->first_glyph
->type
== CHAR_GLYPH
2341 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2344 x_set_glyph_string_clipping (s
);
2345 x_draw_glyph_string_background (s
, 1);
2346 x_draw_glyph_string_box (s
);
2347 x_set_glyph_string_clipping (s
);
2350 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2352 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2353 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2354 /* We must clip just this glyph. left_overhang part has already
2355 drawn when s->prev was drawn, and right_overhang part will be
2356 drawn later when s->next is drawn. */
2357 x_set_glyph_string_clipping_exactly (s
, s
);
2359 x_set_glyph_string_clipping (s
);
2361 switch (s
->first_glyph
->type
)
2364 x_draw_image_glyph_string (s
);
2368 x_draw_stretch_glyph_string (s
);
2372 if (s
->for_overlaps
)
2373 s
->background_filled_p
= 1;
2375 x_draw_glyph_string_background (s
, 0);
2376 x_draw_glyph_string_foreground (s
);
2379 case COMPOSITE_GLYPH
:
2380 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2381 && ! s
->first_glyph
->u
.cmp
.automatic
))
2382 s
->background_filled_p
= 1;
2384 x_draw_glyph_string_background (s
, 1);
2385 x_draw_composite_glyph_string_foreground (s
);
2388 case GLYPHLESS_GLYPH
:
2389 if (s
->for_overlaps
)
2390 s
->background_filled_p
= 1;
2392 x_draw_glyph_string_background (s
, 0);
2393 x_draw_glyphless_glyph_string_foreground (s
);
2400 if (!s
->for_overlaps
)
2402 /* Draw underline. */
2403 if (s
->face
->underline_p
)
2405 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2409 if (s
->face
->underline_defaulted_p
)
2410 color
= s
->gc
->foreground
;
2412 color
= s
->face
->underline_color
;
2414 w32_draw_underwave (s
, color
);
2416 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2418 unsigned long thickness
, position
;
2421 if (s
->prev
&& s
->prev
->face
->underline_p
2422 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2424 /* We use the same underline style as the previous one. */
2425 thickness
= s
->prev
->underline_thickness
;
2426 position
= s
->prev
->underline_position
;
2430 /* Get the underline thickness. Default is 1 pixel. */
2431 if (s
->font
&& s
->font
->underline_thickness
> 0)
2432 thickness
= s
->font
->underline_thickness
;
2435 if (x_underline_at_descent_line
)
2436 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2439 /* Get the underline position. This is the recommended
2440 vertical offset in pixels from the baseline to the top of
2441 the underline. This is a signed value according to the
2442 specs, and its default is
2444 ROUND ((maximum_descent) / 2), with
2445 ROUND (x) = floor (x + 0.5) */
2447 if (x_use_underline_position_properties
2448 && s
->font
&& s
->font
->underline_position
>= 0)
2449 position
= s
->font
->underline_position
;
2451 position
= (s
->font
->descent
+ 1) / 2;
2453 position
= max (position
, underline_minimum_offset
);
2455 /* Check the sanity of thickness and position. We should
2456 avoid drawing underline out of the current line area. */
2457 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2458 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2459 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2460 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2461 s
->underline_thickness
= thickness
;
2462 s
->underline_position
=position
;
2463 y
= s
->ybase
+ position
;
2464 if (s
->face
->underline_defaulted_p
)
2466 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2471 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
2476 /* Draw overline. */
2477 if (s
->face
->overline_p
)
2479 unsigned long dy
= 0, h
= 1;
2481 if (s
->face
->overline_color_defaulted_p
)
2483 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2484 s
->y
+ dy
, s
->width
, h
);
2488 w32_fill_area (s
->f
, s
->hdc
, s
->face
->overline_color
, s
->x
,
2489 s
->y
+ dy
, s
->width
, h
);
2493 /* Draw strike-through. */
2494 if (s
->face
->strike_through_p
2495 && !FONT_TEXTMETRIC (s
->font
).tmStruckOut
)
2497 unsigned long h
= 1;
2498 unsigned long dy
= (s
->height
- h
) / 2;
2500 if (s
->face
->strike_through_color_defaulted_p
)
2502 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
2507 w32_fill_area (s
->f
, s
->hdc
, s
->face
->strike_through_color
, s
->x
,
2508 s
->y
+ dy
, s
->width
, h
);
2512 /* Draw relief if not yet drawn. */
2513 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2514 x_draw_glyph_string_box (s
);
2518 struct glyph_string
*prev
;
2520 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2521 if (prev
->hl
!= s
->hl
2522 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2524 /* As prev was drawn while clipped to its own area, we
2525 must draw the right_overhang part using s->hl now. */
2526 enum draw_glyphs_face save
= prev
->hl
;
2529 x_set_glyph_string_gc (prev
);
2530 x_set_glyph_string_clipping_exactly (s
, prev
);
2531 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2532 x_draw_glyph_string_foreground (prev
);
2534 x_draw_composite_glyph_string_foreground (prev
);
2535 w32_set_clip_rectangle (prev
->hdc
, NULL
);
2537 prev
->num_clips
= 0;
2543 struct glyph_string
*next
;
2545 for (next
= s
->next
; next
; next
= next
->next
)
2546 if (next
->hl
!= s
->hl
2547 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2549 /* As next will be drawn while clipped to its own area,
2550 we must draw the left_overhang part using s->hl now. */
2551 enum draw_glyphs_face save
= next
->hl
;
2554 x_set_glyph_string_gc (next
);
2555 x_set_glyph_string_clipping_exactly (s
, next
);
2556 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2557 x_draw_glyph_string_foreground (next
);
2559 x_draw_composite_glyph_string_foreground (next
);
2560 w32_set_clip_rectangle (next
->hdc
, NULL
);
2562 next
->num_clips
= 0;
2563 next
->clip_head
= s
->next
;
2568 /* Reset clipping. */
2569 w32_set_clip_rectangle (s
->hdc
, NULL
);
2574 /* Shift display to make room for inserted glyphs. */
2577 w32_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
,
2578 int width
, int height
, int shift_by
)
2582 hdc
= get_frame_dc (f
);
2583 BitBlt (hdc
, x
+ shift_by
, y
, width
, height
,
2584 hdc
, x
, y
, SRCCOPY
);
2586 release_frame_dc (f
, hdc
);
2590 /* Delete N glyphs at the nominal cursor position. Not implemented
2594 x_delete_glyphs (struct frame
*f
, register int n
)
2596 if (! FRAME_W32_P (f
))
2603 /* Clear entire frame. */
2606 x_clear_frame (struct frame
*f
)
2608 if (! FRAME_W32_P (f
))
2611 /* Clearing the frame will erase any cursor, so mark them all as no
2613 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2617 w32_clear_window (f
);
2619 /* We have to clear the scroll bars, too. If we have changed
2620 colors or something like that, then they should be notified. */
2621 x_scroll_bar_clear (f
);
2627 /* Make audible bell. */
2630 w32_ring_bell (struct frame
*f
)
2634 if (FRAME_W32_P (f
) && visible_bell
)
2637 HWND hwnd
= FRAME_W32_WINDOW (f
);
2639 for (i
= 0; i
< 5; i
++)
2641 FlashWindow (hwnd
, TRUE
);
2644 FlashWindow (hwnd
, FALSE
);
2647 w32_sys_ring_bell (f
);
2652 /***********************************************************************
2654 ***********************************************************************/
2656 /* Perform an insert-lines or delete-lines operation, inserting N
2657 lines or deleting -N lines at vertical position VPOS. */
2660 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
2662 if (! FRAME_W32_P (f
))
2669 /* Scroll part of the display as described by RUN. */
2672 x_scroll_run (struct window
*w
, struct run
*run
)
2674 struct frame
*f
= XFRAME (w
->frame
);
2675 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2676 HWND hwnd
= FRAME_W32_WINDOW (f
);
2679 /* Get frame-relative bounding box of the text display area of W,
2680 without mode lines. Include in this box the left and right
2682 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
2684 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
2685 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
2686 bottom_y
= y
+ height
;
2690 /* Scrolling up. Make sure we don't copy part of the mode
2691 line at the bottom. */
2692 if (from_y
+ run
->height
> bottom_y
)
2693 height
= bottom_y
- from_y
;
2695 height
= run
->height
;
2696 expect_dirty
= CreateRectRgn (x
, y
+ height
, x
+ width
, bottom_y
);
2700 /* Scrolling down. Make sure we don't copy over the mode line.
2702 if (to_y
+ run
->height
> bottom_y
)
2703 height
= bottom_y
- to_y
;
2705 height
= run
->height
;
2706 expect_dirty
= CreateRectRgn (x
, y
, x
+ width
, to_y
);
2711 /* Cursor off. Will be switched on again in x_update_window_end. */
2717 HRGN dirty
= CreateRectRgn (0, 0, 0, 0);
2718 HRGN combined
= CreateRectRgn (0, 0, 0, 0);
2720 from
.left
= to
.left
= x
;
2721 from
.right
= to
.right
= x
+ width
;
2723 from
.bottom
= from_y
+ height
;
2725 to
.bottom
= bottom_y
;
2727 ScrollWindowEx (hwnd
, 0, to_y
- from_y
, &from
, &to
, dirty
,
2728 NULL
, SW_INVALIDATE
);
2730 /* Combine this with what we expect to be dirty. This covers the
2731 case where not all of the region we expect is actually dirty. */
2732 CombineRgn (combined
, dirty
, expect_dirty
, RGN_OR
);
2734 /* If the dirty region is not what we expected, redraw the entire frame. */
2735 if (!EqualRgn (combined
, expect_dirty
))
2736 SET_FRAME_GARBAGED (f
);
2738 DeleteObject (dirty
);
2739 DeleteObject (combined
);
2743 DeleteObject (expect_dirty
);
2748 /***********************************************************************
2750 ***********************************************************************/
2753 frame_highlight (struct frame
*f
)
2755 x_update_cursor (f
, 1);
2756 x_set_frame_alpha (f
);
2760 frame_unhighlight (struct frame
*f
)
2762 x_update_cursor (f
, 1);
2763 x_set_frame_alpha (f
);
2766 /* The focus has changed. Update the frames as necessary to reflect
2767 the new situation. Note that we can't change the selected frame
2768 here, because the Lisp code we are interrupting might become confused.
2769 Each event gets marked with the frame in which it occurred, so the
2770 Lisp code can tell when the switch took place by examining the events. */
2773 x_new_focus_frame (struct w32_display_info
*dpyinfo
, struct frame
*frame
)
2775 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
2777 if (frame
!= dpyinfo
->w32_focus_frame
)
2779 /* Set this before calling other routines, so that they see
2780 the correct value of w32_focus_frame. */
2781 dpyinfo
->w32_focus_frame
= frame
;
2783 if (old_focus
&& old_focus
->auto_lower
)
2784 x_lower_frame (old_focus
);
2786 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
2787 dpyinfo
->w32_pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
2789 dpyinfo
->w32_pending_autoraise_frame
= NULL
;
2792 x_frame_rehighlight (dpyinfo
);
2796 /* Handle FocusIn and FocusOut state changes for FRAME.
2797 If FRAME has focus and there exists more than one frame, puts
2798 a FOCUS_IN_EVENT into *BUFP. */
2801 x_focus_changed (int type
, int state
, struct w32_display_info
*dpyinfo
,
2802 struct frame
*frame
, struct input_event
*bufp
)
2804 if (type
== WM_SETFOCUS
)
2806 if (dpyinfo
->w32_focus_event_frame
!= frame
)
2808 x_new_focus_frame (dpyinfo
, frame
);
2809 dpyinfo
->w32_focus_event_frame
= frame
;
2811 /* Don't stop displaying the initial startup message
2812 for a switch-frame event we don't need. */
2813 if (NILP (Vterminal_frame
)
2814 && CONSP (Vframe_list
)
2815 && !NILP (XCDR (Vframe_list
)))
2824 bufp
->kind
= FOCUS_IN_EVENT
;
2825 XSETFRAME (bufp
->frame_or_window
, frame
);
2828 frame
->output_data
.x
->focus_state
|= state
;
2830 /* TODO: IME focus? */
2832 else if (type
== WM_KILLFOCUS
)
2834 frame
->output_data
.x
->focus_state
&= ~state
;
2836 if (dpyinfo
->w32_focus_event_frame
== frame
)
2838 dpyinfo
->w32_focus_event_frame
= 0;
2839 x_new_focus_frame (dpyinfo
, 0);
2841 bufp
->kind
= FOCUS_OUT_EVENT
;
2842 XSETFRAME (bufp
->frame_or_window
, frame
);
2845 /* TODO: IME focus? */
2850 /* The focus may have changed. Figure out if it is a real focus change,
2851 by checking both FocusIn/Out and Enter/LeaveNotify events.
2853 Returns FOCUS_IN_EVENT event in *BUFP. */
2856 w32_detect_focus_change (struct w32_display_info
*dpyinfo
, W32Msg
*event
,
2857 struct input_event
*bufp
)
2859 struct frame
*frame
;
2861 frame
= x_any_window_to_frame (dpyinfo
, event
->msg
.hwnd
);
2865 /* On w32, this is only called from focus events, so no switch needed. */
2866 x_focus_changed (event
->msg
.message
,
2867 (event
->msg
.message
== WM_KILLFOCUS
?
2868 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
2869 dpyinfo
, frame
, bufp
);
2873 /* Handle an event saying the mouse has moved out of an Emacs frame. */
2876 x_mouse_leave (struct w32_display_info
*dpyinfo
)
2878 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
2881 /* The focus has changed, or we have redirected a frame's focus to
2882 another frame (this happens when a frame uses a surrogate
2883 mini-buffer frame). Shift the highlight as appropriate.
2885 The FRAME argument doesn't necessarily have anything to do with which
2886 frame is being highlighted or un-highlighted; we only use it to find
2887 the appropriate X display info. */
2890 w32_frame_rehighlight (struct frame
*frame
)
2892 if (! FRAME_W32_P (frame
))
2894 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
2898 x_frame_rehighlight (struct w32_display_info
*dpyinfo
)
2900 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
2902 if (dpyinfo
->w32_focus_frame
)
2904 dpyinfo
->x_highlight_frame
2905 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
2906 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
2907 : dpyinfo
->w32_focus_frame
);
2908 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
2910 fset_focus_frame (dpyinfo
->w32_focus_frame
, Qnil
);
2911 dpyinfo
->x_highlight_frame
= dpyinfo
->w32_focus_frame
;
2915 dpyinfo
->x_highlight_frame
= 0;
2917 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
2920 frame_unhighlight (old_highlight
);
2921 if (dpyinfo
->x_highlight_frame
)
2922 frame_highlight (dpyinfo
->x_highlight_frame
);
2926 /* Keyboard processing - modifier keys, etc. */
2928 /* Convert a keysym to its name. */
2931 x_get_keysym_name (int keysym
)
2933 /* Make static so we can always return it */
2934 static char value
[100];
2937 GetKeyNameText (keysym
, value
, 100);
2944 codepage_for_locale (LCID locale
)
2948 if (GetLocaleInfo (locale
, LOCALE_IDEFAULTANSICODEPAGE
, cp
, 20) > 0)
2955 /* Mouse clicks and mouse movement. Rah. */
2957 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
2958 the state in PUP. XBUTTON provides extra information for extended mouse
2959 button messages. Returns FALSE if unable to parse the message. */
2961 parse_button (int message
, int xbutton
, int * pbutton
, int * pup
)
2968 case WM_LBUTTONDOWN
:
2976 case WM_MBUTTONDOWN
:
2977 if (NILP (Vw32_swap_mouse_buttons
))
2984 if (NILP (Vw32_swap_mouse_buttons
))
2990 case WM_RBUTTONDOWN
:
2991 if (NILP (Vw32_swap_mouse_buttons
))
2998 if (NILP (Vw32_swap_mouse_buttons
))
3004 case WM_XBUTTONDOWN
:
3005 button
= xbutton
+ 2;
3009 button
= xbutton
+ 2;
3017 if (pbutton
) *pbutton
= button
;
3023 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3025 If the event is a button press, then note that we have grabbed
3029 construct_mouse_click (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3034 parse_button (msg
->msg
.message
, HIWORD (msg
->msg
.wParam
),
3037 /* Make the event type NO_EVENT; we'll change that when we decide
3039 result
->kind
= MOUSE_CLICK_EVENT
;
3040 result
->code
= button
;
3041 result
->timestamp
= msg
->msg
.time
;
3042 result
->modifiers
= (msg
->dwModifiers
3047 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
3048 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
3049 XSETFRAME (result
->frame_or_window
, f
);
3055 construct_mouse_wheel (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3060 result
->kind
= msg
->msg
.message
== WM_MOUSEHWHEEL
? HORIZ_WHEEL_EVENT
3063 result
->timestamp
= msg
->msg
.time
;
3065 /* A WHEEL_DELTA positive value indicates that the wheel was rotated
3066 forward, away from the user (up); a negative value indicates that
3067 the wheel was rotated backward, toward the user (down). */
3068 delta
= GET_WHEEL_DELTA_WPARAM (msg
->msg
.wParam
);
3070 /* The up and down modifiers indicate if the wheel was rotated up or
3071 down based on WHEEL_DELTA value. */
3072 result
->modifiers
= (msg
->dwModifiers
3073 | ((delta
< 0 ) ? down_modifier
: up_modifier
));
3075 /* With multiple monitors, we can legitimately get negative
3076 coordinates, so cast to short to interpret them correctly. */
3077 p
.x
= (short) LOWORD (msg
->msg
.lParam
);
3078 p
.y
= (short) HIWORD (msg
->msg
.lParam
);
3079 ScreenToClient (msg
->msg
.hwnd
, &p
);
3080 XSETINT (result
->x
, p
.x
);
3081 XSETINT (result
->y
, p
.y
);
3082 XSETFRAME (result
->frame_or_window
, f
);
3088 construct_drag_n_drop (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3095 wchar_t name_w
[MAX_PATH
];
3096 #ifdef NTGUI_UNICODE
3097 const int use_unicode
= 1;
3099 int use_unicode
= w32_unicode_filenames
;
3100 char name_a
[MAX_PATH
];
3101 char file
[MAX_UTF8_PATH
];
3105 result
->kind
= DRAG_N_DROP_EVENT
;
3107 result
->timestamp
= msg
->msg
.time
;
3108 result
->modifiers
= msg
->dwModifiers
;
3110 hdrop
= (HDROP
) msg
->msg
.wParam
;
3111 DragQueryPoint (hdrop
, &p
);
3114 p
.x
= LOWORD (msg
->msg
.lParam
);
3115 p
.y
= HIWORD (msg
->msg
.lParam
);
3116 ScreenToClient (msg
->msg
.hwnd
, &p
);
3119 XSETINT (result
->x
, p
.x
);
3120 XSETINT (result
->y
, p
.y
);
3122 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
3125 for (i
= 0; i
< num_files
; i
++)
3129 eassert (DragQueryFileW (hdrop
, i
, NULL
, 0) < MAX_PATH
);
3130 /* If DragQueryFile returns zero, it failed to fetch a file
3132 if (DragQueryFileW (hdrop
, i
, name_w
, MAX_PATH
) == 0)
3134 #ifdef NTGUI_UNICODE
3135 files
= Fcons (from_unicode_buffer (name_w
), files
);
3137 filename_from_utf16 (name_w
, file
);
3138 files
= Fcons (DECODE_FILE (build_unibyte_string (file
)), files
);
3139 #endif /* NTGUI_UNICODE */
3141 #ifndef NTGUI_UNICODE
3144 eassert (DragQueryFileA (hdrop
, i
, NULL
, 0) < MAX_PATH
);
3145 if (DragQueryFileA (hdrop
, i
, name_a
, MAX_PATH
) == 0)
3147 filename_from_ansi (name_a
, file
);
3148 files
= Fcons (DECODE_FILE (build_unibyte_string (file
)), files
);
3155 XSETFRAME (frame
, f
);
3156 result
->frame_or_window
= frame
;
3157 result
->arg
= files
;
3164 /* File event notifications (see w32notify.c). */
3167 lispy_file_action (DWORD action
)
3169 static char unknown_fmt
[] = "unknown-action(%d)";
3174 case FILE_ACTION_ADDED
:
3177 case FILE_ACTION_REMOVED
:
3180 case FILE_ACTION_MODIFIED
:
3183 case FILE_ACTION_RENAMED_OLD_NAME
:
3184 retval
= Qrenamed_from
;
3186 case FILE_ACTION_RENAMED_NEW_NAME
:
3187 retval
= Qrenamed_to
;
3191 char buf
[sizeof(unknown_fmt
) - 1 + INT_STRLEN_BOUND (DWORD
)];
3193 sprintf (buf
, unknown_fmt
, action
);
3194 retval
= intern (buf
);
3203 /* Put file notifications into the Emacs input event queue. This
3204 function runs when the WM_EMACS_FILENOTIFY message arrives from a
3207 queue_notifications (struct input_event
*event
, W32Msg
*msg
, struct frame
*f
,
3210 BYTE
*p
= file_notifications
;
3211 FILE_NOTIFY_INFORMATION
*fni
= (PFILE_NOTIFY_INFORMATION
)p
;
3212 const DWORD min_size
3213 = offsetof (FILE_NOTIFY_INFORMATION
, FileName
) + sizeof(wchar_t);
3216 /* We cannot process notification before Emacs is fully initialized,
3217 since we need the UTF-16LE coding-system to be set up. */
3220 notification_buffer_in_use
= 0;
3224 XSETFRAME (frame
, f
);
3227 if (notification_buffer_in_use
)
3229 DWORD info_size
= notifications_size
;
3230 Lisp_Object cs
= intern ("utf-16le");
3231 Lisp_Object obj
= w32_get_watch_object (notifications_desc
);
3233 /* notifications_size could be zero when the buffer of
3234 notifications overflowed on the OS level, or when the
3235 directory being watched was itself deleted. Do nothing in
3238 && !NILP (obj
) && CONSP (obj
))
3240 Lisp_Object callback
= XCDR (obj
);
3242 while (info_size
>= min_size
)
3244 Lisp_Object utf_16_fn
3245 = make_unibyte_string ((char *)fni
->FileName
,
3246 fni
->FileNameLength
);
3247 /* Note: mule-conf is preloaded, so utf-16le must
3248 already be defined at this point. */
3250 = code_convert_string_norecord (utf_16_fn
, cs
, 0);
3251 Lisp_Object action
= lispy_file_action (fni
->Action
);
3253 event
->kind
= FILE_NOTIFY_EVENT
;
3255 = (ptrdiff_t)XINT (XIL ((EMACS_INT
)notifications_desc
));
3256 event
->timestamp
= msg
->msg
.time
;
3257 event
->modifiers
= 0;
3258 event
->frame_or_window
= callback
;
3259 event
->arg
= Fcons (action
, fname
);
3260 kbd_buffer_store_event (event
);
3263 if (!fni
->NextEntryOffset
)
3265 p
+= fni
->NextEntryOffset
;
3266 fni
= (PFILE_NOTIFY_INFORMATION
)p
;
3267 info_size
-= fni
->NextEntryOffset
;
3270 notification_buffer_in_use
= 0;
3273 DebPrint (("We were promised notifications, but in-use flag is zero!\n"));
3276 /* We've stuffed all the events ourselves, so w32_read_socket shouldn't. */
3277 event
->kind
= NO_EVENT
;
3279 #endif /* WINDOWSNT */
3280 #endif /* HAVE_W32NOTIFY */
3283 /* Function to report a mouse movement to the mainstream Emacs code.
3284 The input handler calls this.
3286 We have received a mouse movement event, which is given in *event.
3287 If the mouse is over a different glyph than it was last time, tell
3288 the mainstream emacs code by setting mouse_moved. If not, ask for
3289 another motion event, so we can check again the next time it moves. */
3292 note_mouse_movement (struct frame
*frame
, MSG
*msg
)
3294 struct w32_display_info
*dpyinfo
;
3295 int mouse_x
= LOWORD (msg
->lParam
);
3296 int mouse_y
= HIWORD (msg
->lParam
);
3299 if (!FRAME_X_OUTPUT (frame
))
3302 dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3303 dpyinfo
->last_mouse_movement_time
= msg
->time
;
3304 dpyinfo
->last_mouse_motion_frame
= frame
;
3305 dpyinfo
->last_mouse_motion_x
= mouse_x
;
3306 dpyinfo
->last_mouse_motion_y
= mouse_y
;
3308 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
3310 frame
->mouse_moved
= 1;
3311 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3312 note_mouse_highlight (frame
, -1, -1);
3313 dpyinfo
->last_mouse_glyph_frame
= NULL
;
3317 /* Has the mouse moved off the glyph it was on at the last sighting? */
3318 r
= &dpyinfo
->last_mouse_glyph
;
3319 if (frame
!= dpyinfo
->last_mouse_glyph_frame
3320 || mouse_x
< r
->left
|| mouse_x
>= r
->right
3321 || mouse_y
< r
->top
|| mouse_y
>= r
->bottom
)
3323 frame
->mouse_moved
= 1;
3324 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3325 note_mouse_highlight (frame
, mouse_x
, mouse_y
);
3326 /* Remember the mouse position here, as w32_mouse_position only
3327 gets called when mouse tracking is enabled but we also need
3328 to keep track of the mouse for help_echo and highlighting at
3330 remember_mouse_glyph (frame
, mouse_x
, mouse_y
, r
);
3331 dpyinfo
->last_mouse_glyph_frame
= frame
;
3339 /************************************************************************
3341 ************************************************************************/
3343 static struct scroll_bar
*x_window_to_scroll_bar (Window
, int);
3344 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
3345 enum scroll_bar_part
*,
3346 Lisp_Object
*, Lisp_Object
*,
3348 static void x_horizontal_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
3349 enum scroll_bar_part
*,
3350 Lisp_Object
*, Lisp_Object
*,
3352 static void x_check_fullscreen (struct frame
*);
3355 w32_define_cursor (Window window
, Cursor cursor
)
3357 PostMessage (window
, WM_EMACS_SETCURSOR
, (WPARAM
) cursor
, 0);
3360 /* Return the current position of the mouse.
3361 *fp should be a frame which indicates which display to ask about.
3363 If the mouse movement started in a scroll bar, set *fp, *bar_window,
3364 and *part to the frame, window, and scroll bar part that the mouse
3365 is over. Set *x and *y to the portion and whole of the mouse's
3366 position on the scroll bar.
3368 If the mouse movement started elsewhere, set *fp to the frame the
3369 mouse is on, *bar_window to nil, and *x and *y to the character cell
3372 Set *time to the server time-stamp for the time at which the mouse
3373 was at this position.
3375 Don't store anything if we don't have a valid set of values to report.
3377 This clears the mouse_moved flag, so we can wait for the next mouse
3381 w32_mouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3382 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3383 unsigned long *time
)
3386 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
3390 if (dpyinfo
->last_mouse_scroll_bar
&& insist
== 0)
3392 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
3394 if (bar
->horizontal
)
3395 x_horizontal_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3397 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3403 Lisp_Object frame
, tail
;
3405 /* Clear the mouse-moved flag for every frame on this display. */
3406 FOR_EACH_FRAME (tail
, frame
)
3407 XFRAME (frame
)->mouse_moved
= 0;
3409 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3413 /* Now we have a position on the root; find the innermost window
3414 containing the pointer. */
3416 /* If mouse was grabbed on a frame, give coords for that
3417 frame even if the mouse is now outside it. Otherwise
3418 check for window under mouse on one of our frames. */
3419 f1
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
3420 : x_any_window_to_frame (dpyinfo
, WindowFromPoint (pt
)));
3422 /* If not, is it one of our scroll bars? */
3425 struct scroll_bar
*bar
3426 = x_window_to_scroll_bar (WindowFromPoint (pt
), 2);
3429 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3432 if (f1
== 0 && insist
> 0)
3433 f1
= SELECTED_FRAME ();
3437 /* Ok, we found a frame. Store all the values.
3438 last_mouse_glyph is a rectangle used to reduce the
3439 generation of mouse events. To not miss any motion
3440 events, we must divide the frame into rectangles of the
3441 size of the smallest character that could be displayed
3442 on it, i.e. into the same rectangles that matrices on
3443 the frame are divided into. */
3445 dpyinfo
= FRAME_DISPLAY_INFO (f1
);
3446 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
3447 remember_mouse_glyph (f1
, pt
.x
, pt
.y
, &dpyinfo
->last_mouse_glyph
);
3448 dpyinfo
->last_mouse_glyph_frame
= f1
;
3455 *time
= dpyinfo
->last_mouse_movement_time
;
3464 /***********************************************************************
3466 ***********************************************************************/
3468 /* Handle mouse button event on the tool-bar of frame F, at
3469 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
3470 or ButtonRelease. */
3473 w32_handle_tool_bar_click (struct frame
*f
, struct input_event
*button_event
)
3475 int x
= XFASTINT (button_event
->x
);
3476 int y
= XFASTINT (button_event
->y
);
3478 if (button_event
->modifiers
& down_modifier
)
3479 handle_tool_bar_click (f
, x
, y
, 1, 0);
3481 handle_tool_bar_click (f
, x
, y
, 0,
3482 button_event
->modifiers
& ~up_modifier
);
3487 /***********************************************************************
3489 ***********************************************************************/
3491 /* Scroll bar support. */
3493 /* Given a window ID, find the struct scroll_bar which manages it
3494 vertically. This can be called in GC, so we have to make sure to
3495 strip off mark bits. */
3497 static struct scroll_bar
*
3498 x_window_to_scroll_bar (Window window_id
, int type
)
3500 Lisp_Object tail
, frame
;
3502 FOR_EACH_FRAME (tail
, frame
)
3504 Lisp_Object bar
, condemned
;
3506 /* Scan this frame's scroll bar list for a scroll bar with the
3508 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3509 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3510 /* This trick allows us to search both the ordinary and
3511 condemned scroll bar lists with one loop. */
3512 ! NILP (bar
) || (bar
= condemned
,
3515 bar
= XSCROLL_BAR (bar
)->next
)
3516 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
3518 || (type
== 1 && XSCROLL_BAR (bar
)->horizontal
)
3519 || (type
== 0 && !XSCROLL_BAR (bar
)->horizontal
)))
3520 return XSCROLL_BAR (bar
);
3528 /* Set the thumb size and position of vertical scroll bar BAR. We are currently
3529 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3532 w32_set_scroll_bar_thumb (struct scroll_bar
*bar
,
3533 int portion
, int position
, int whole
)
3535 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
3536 /* We use the whole scroll-bar height in the calculations below, to
3537 avoid strange effects like scrolling backwards when just clicking
3538 on the handle (without moving it). */
3539 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
)
3540 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3541 int sb_page
, sb_pos
;
3542 BOOL draggingp
= bar
->dragging
? TRUE
: FALSE
;
3545 /* We used to change the nPage setting while dragging the handle,
3546 but that had very strange effects (such as scrolling backwards
3547 while dragging downwards).
3549 Now, we don't change the nPage setting while dragging unless we
3550 get near to the end of the buffer, in which case we often have to
3551 resize the handle to "go all the way". */
3557 si
.cbSize
= sizeof (si
);
3558 si
.fMask
= SIF_POS
| SIF_PAGE
;
3559 GetScrollInfo (w
, SB_CTL
, &si
);
3560 near_bottom_p
= si
.nPos
+ si
.nPage
>= range
;
3568 /* Position scroll bar at rock bottom if the bottom of the
3569 buffer is visible. This avoids shrinking the thumb away
3570 to nothing if it is held at the bottom of the buffer. */
3571 if (position
+ portion
>= whole
&& !draggingp
)
3573 sb_page
= range
* (whole
- position
) / whole
;
3578 sb_pos
= position
* range
/ whole
;
3579 sb_page
= (min (portion
, (whole
- position
)) * range
) / whole
;
3588 sb_page
= max (sb_page
, VERTICAL_SCROLL_BAR_MIN_HANDLE
);
3592 si
.cbSize
= sizeof (si
);
3593 si
.fMask
= SIF_PAGE
| SIF_POS
;
3597 SetScrollInfo (w
, SB_CTL
, &si
, TRUE
);
3602 /* Set the thumb size and position of horizontal scroll bar BAR. We are currently
3603 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3606 w32_set_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
,
3607 int portion
, int position
, int whole
)
3609 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
3614 si
.cbSize
= sizeof (si
);
3615 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
;
3618 /* Allow nPage to be one larger than nPos so we don't allow to scroll
3619 an already fully visible buffer. */
3620 si
.nPage
= min (portion
, si
.nMax
) + 1;
3621 si
.nPos
= min (position
, si
.nMax
);
3622 SetScrollInfo (w
, SB_CTL
, &si
, TRUE
);
3628 /************************************************************************
3629 Scroll bars, general
3630 ************************************************************************/
3633 my_create_vscrollbar (struct frame
* f
, struct scroll_bar
* bar
)
3635 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
3636 WM_EMACS_CREATEVSCROLLBAR
, (WPARAM
) f
,
3641 my_create_hscrollbar (struct frame
* f
, struct scroll_bar
* bar
)
3643 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
3644 WM_EMACS_CREATEHSCROLLBAR
, (WPARAM
) f
,
3648 /*#define ATTACH_THREADS*/
3651 my_show_window (struct frame
*f
, HWND hwnd
, int how
)
3653 #ifndef ATTACH_THREADS
3654 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
3655 (WPARAM
) hwnd
, (LPARAM
) how
);
3657 return ShowWindow (hwnd
, how
);
3662 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
3663 int x
, int y
, int cx
, int cy
, UINT flags
)
3665 #ifndef ATTACH_THREADS
3667 pos
.hwndInsertAfter
= hwndAfter
;
3673 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
3675 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
3681 my_set_focus (struct frame
* f
, HWND hwnd
)
3683 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
3689 my_set_foreground_window (HWND hwnd
)
3691 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
3696 my_destroy_window (struct frame
* f
, HWND hwnd
)
3698 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
3703 my_bring_window_to_top (HWND hwnd
)
3705 SendMessage (hwnd
, WM_EMACS_BRINGTOTOP
, (WPARAM
) hwnd
, 0);
3708 /* Create a scroll bar and return the scroll bar vector for it. W is
3709 the Emacs window on which to create the scroll bar. TOP, LEFT,
3710 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
3713 static struct scroll_bar
*
3714 x_scroll_bar_create (struct window
*w
, int left
, int top
, int width
, int height
, bool horizontal
)
3716 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3719 struct scroll_bar
*bar
3720 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, top
, PVEC_OTHER
);
3725 XSETWINDOW (bar
->window
, w
);
3729 bar
->height
= height
;
3733 bar
->horizontal
= horizontal
;
3735 /* Requires geometry to be set before call to create the real window */
3738 hwnd
= my_create_hscrollbar (f
, bar
);
3740 hwnd
= my_create_vscrollbar (f
, bar
);
3742 si
.cbSize
= sizeof (si
);
3746 si
.nMax
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, width
)
3747 + HORIZONTAL_SCROLL_BAR_MIN_HANDLE
;
3749 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3750 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3754 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3756 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
3758 /* Add bar to its frame's list of scroll bars. */
3759 bar
->next
= FRAME_SCROLL_BARS (f
);
3761 XSETVECTOR (barobj
, bar
);
3762 fset_scroll_bars (f
, barobj
);
3763 if (! NILP (bar
->next
))
3764 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3772 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
3776 x_scroll_bar_remove (struct scroll_bar
*bar
)
3778 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3782 /* Destroy the window. */
3783 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
3785 /* Dissociate this scroll bar from its window. */
3786 if (bar
->horizontal
)
3787 wset_horizontal_scroll_bar (XWINDOW (bar
->window
), Qnil
);
3789 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
3794 /* Set the handle of the vertical scroll bar for WINDOW to indicate that
3795 we are displaying PORTION characters out of a total of WHOLE
3796 characters, starting at POSITION. If WINDOW has no vertical scroll
3799 w32_set_vertical_scroll_bar (struct window
*w
,
3800 int portion
, int whole
, int position
)
3802 struct frame
*f
= XFRAME (w
->frame
);
3804 struct scroll_bar
*bar
;
3805 int top
, height
, left
, width
;
3806 int window_y
, window_height
;
3808 /* Get window dimensions. */
3809 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
3811 height
= window_height
;
3813 /* Compute the left edge and the width of the scroll bar area. */
3814 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
3815 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
3817 /* Does the scroll bar exist yet? */
3818 if (NILP (w
->vertical_scroll_bar
))
3822 if (width
> 0 && height
> 0)
3824 hdc
= get_frame_dc (f
);
3825 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3826 release_frame_dc (f
, hdc
);
3830 bar
= x_scroll_bar_create (w
, left
, top
, width
, height
, 0);
3834 /* It may just need to be moved and resized. */
3837 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
3838 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
3840 /* If already correctly positioned, do nothing. */
3841 if (bar
->left
== left
3843 && bar
->width
== width
3844 && bar
->height
== height
)
3846 /* Redraw after clear_frame. */
3847 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
3848 InvalidateRect (hwnd
, NULL
, FALSE
);
3856 if (width
&& height
)
3858 hdc
= get_frame_dc (f
);
3859 /* Since Windows scroll bars are smaller than the space reserved
3860 for them on the frame, we have to clear "under" them. */
3861 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3862 release_frame_dc (f
, hdc
);
3864 /* Make sure scroll bar is "visible" before moving, to ensure the
3865 area of the parent window now exposed will be refreshed. */
3866 my_show_window (f
, hwnd
, SW_HIDE
);
3867 MoveWindow (hwnd
, left
, top
, width
, max (height
, 1), TRUE
);
3869 si
.cbSize
= sizeof (si
);
3870 si
.fMask
= SIF_RANGE
;
3872 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3873 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3875 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3877 my_show_window (f
, hwnd
, SW_NORMAL
);
3878 /* InvalidateRect (w, NULL, FALSE); */
3880 /* Remember new settings. */
3884 bar
->height
= height
;
3889 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
3890 XSETVECTOR (barobj
, bar
);
3891 wset_vertical_scroll_bar (w
, barobj
);
3894 /* Set the handle of the horizontal scroll bar for WINDOW to indicate
3895 that we are displaying PORTION characters out of a total of WHOLE
3896 characters, starting at POSITION. If WINDOW has no horizontal scroll
3899 w32_set_horizontal_scroll_bar (struct window
*w
,
3900 int portion
, int whole
, int position
)
3902 struct frame
*f
= XFRAME (w
->frame
);
3904 struct scroll_bar
*bar
;
3905 int top
, height
, left
, width
;
3906 int window_x
, window_width
;
3907 int clear_left
= WINDOW_LEFT_EDGE_X (w
);
3908 int clear_width
= WINDOW_PIXEL_WIDTH (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
3910 /* Get window dimensions. */
3911 window_box (w
, ANY_AREA
, &window_x
, 0, &window_width
, 0);
3913 height
= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
3914 width
= window_width
;
3915 top
= WINDOW_SCROLL_BAR_AREA_Y (w
);
3917 /* Does the scroll bar exist yet? */
3918 if (NILP (w
->horizontal_scroll_bar
))
3922 if (width
> 0 && height
> 0)
3924 hdc
= get_frame_dc (f
);
3925 w32_clear_area (f
, hdc
, clear_left
, top
, clear_width
, height
);
3926 release_frame_dc (f
, hdc
);
3930 bar
= x_scroll_bar_create (w
, left
, top
, width
, height
, 1);
3934 /* It may just need to be moved and resized. */
3937 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
3938 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
3940 /* If already correctly positioned, do nothing. */
3941 if (bar
->left
== left
&& bar
->top
== top
3942 && bar
->width
== width
&& bar
->height
== height
)
3944 /* Redraw after clear_frame. */
3945 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
3946 InvalidateRect (hwnd
, NULL
, FALSE
);
3954 if (width
&& height
)
3956 hdc
= get_frame_dc (f
);
3957 /* Since Windows scroll bars are smaller than the space reserved
3958 for them on the frame, we have to clear "under" them. */
3959 w32_clear_area (f
, hdc
, clear_left
, top
, clear_width
, height
);
3960 release_frame_dc (f
, hdc
);
3962 /* Make sure scroll bar is "visible" before moving, to ensure the
3963 area of the parent window now exposed will be refreshed. */
3964 my_show_window (f
, hwnd
, SW_HIDE
);
3965 MoveWindow (hwnd
, left
, top
, width
, max (height
, 1), TRUE
);
3967 /* +++ SetScrollInfo +++ */
3968 si
.cbSize
= sizeof (si
);
3969 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
;
3972 si
.nPage
= min (portion
, si
.nMax
) + 1;
3973 si
.nPos
= min (position
, si
.nMax
);
3974 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3976 my_show_window (f
, hwnd
, SW_NORMAL
);
3977 /* InvalidateRect (w, NULL, FALSE); */
3979 /* Remember new settings. */
3983 bar
->height
= height
;
3989 w32_set_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
3990 XSETVECTOR (barobj
, bar
);
3991 wset_horizontal_scroll_bar (w
, barobj
);
3995 /* The following three hooks are used when we're doing a thorough
3996 redisplay of the frame. We don't explicitly know which scroll bars
3997 are going to be deleted, because keeping track of when windows go
3998 away is a real pain - "Can you say set-window-configuration, boys
3999 and girls?" Instead, we just assert at the beginning of redisplay
4000 that *all* scroll bars are to be removed, and then save a scroll bar
4001 from the fiery pit when we actually redisplay its window. */
4003 /* Arrange for all scroll bars on FRAME to be removed at the next call
4004 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
4005 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
4008 w32_condemn_scroll_bars (struct frame
*frame
)
4010 if (!NILP (FRAME_SCROLL_BARS (frame
)))
4012 if (!NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
4014 /* Prepend scrollbars to already condemned ones. */
4015 Lisp_Object last
= FRAME_SCROLL_BARS (frame
);
4017 while (!NILP (XSCROLL_BAR (last
)->next
))
4018 last
= XSCROLL_BAR (last
)->next
;
4020 XSCROLL_BAR (last
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
4021 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= last
;
4024 fset_condemned_scroll_bars (frame
, FRAME_SCROLL_BARS (frame
));
4025 fset_scroll_bars (frame
, Qnil
);
4030 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
4031 Note that WINDOW isn't necessarily condemned at all. */
4034 w32_redeem_scroll_bar (struct window
*w
)
4036 struct scroll_bar
*bar
;
4040 /* We can't redeem this window's scroll bar if it doesn't have one. */
4041 if (NILP (w
->vertical_scroll_bar
) && NILP (w
->horizontal_scroll_bar
))
4044 if (!NILP (w
->vertical_scroll_bar
) && WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4046 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4047 /* Unlink it from the condemned list. */
4048 f
= XFRAME (WINDOW_FRAME (w
));
4049 if (NILP (bar
->prev
))
4051 /* If the prev pointer is nil, it must be the first in one of
4053 if (EQ (FRAME_SCROLL_BARS (f
), w
->vertical_scroll_bar
))
4054 /* It's not condemned. Everything's fine. */
4056 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
4057 w
->vertical_scroll_bar
))
4058 fset_condemned_scroll_bars (f
, bar
->next
);
4060 /* If its prev pointer is nil, it must be at the front of
4061 one or the other! */
4065 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
4067 if (! NILP (bar
->next
))
4068 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
4070 bar
->next
= FRAME_SCROLL_BARS (f
);
4072 XSETVECTOR (barobj
, bar
);
4073 fset_scroll_bars (f
, barobj
);
4074 if (! NILP (bar
->next
))
4075 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4079 if (!NILP (w
->horizontal_scroll_bar
) && WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
4081 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
4082 /* Unlink it from the condemned list. */
4083 f
= XFRAME (WINDOW_FRAME (w
));
4084 if (NILP (bar
->prev
))
4086 /* If the prev pointer is nil, it must be the first in one of
4088 if (EQ (FRAME_SCROLL_BARS (f
), w
->horizontal_scroll_bar
))
4089 /* It's not condemned. Everything's fine. */
4091 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
4092 w
->horizontal_scroll_bar
))
4093 fset_condemned_scroll_bars (f
, bar
->next
);
4095 /* If its prev pointer is nil, it must be at the front of
4096 one or the other! */
4100 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
4102 if (! NILP (bar
->next
))
4103 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
4105 bar
->next
= FRAME_SCROLL_BARS (f
);
4107 XSETVECTOR (barobj
, bar
);
4108 fset_scroll_bars (f
, barobj
);
4109 if (! NILP (bar
->next
))
4110 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4114 /* Remove all scroll bars on FRAME that haven't been saved since the
4115 last call to `*condemn_scroll_bars_hook'. */
4118 w32_judge_scroll_bars (struct frame
*f
)
4120 Lisp_Object bar
, next
;
4122 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
4124 /* Clear out the condemned list now so we won't try to process any
4125 more events on the hapless scroll bars. */
4126 fset_condemned_scroll_bars (f
, Qnil
);
4128 for (; ! NILP (bar
); bar
= next
)
4130 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
4132 x_scroll_bar_remove (b
);
4135 b
->next
= b
->prev
= Qnil
;
4138 /* Now there should be no references to the condemned scroll bars,
4139 and they should get garbage-collected. */
4142 /* Handle a mouse click on the vertical scroll bar BAR. If
4143 *EMACS_EVENT's kind is set to something other than NO_EVENT, it is
4146 This may be called from a signal handler, so we have to ignore GC
4150 w32_scroll_bar_handle_click (struct scroll_bar
*bar
, W32Msg
*msg
,
4151 struct input_event
*emacs_event
)
4153 if (! WINDOWP (bar
->window
))
4156 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
4157 emacs_event
->code
= 0;
4158 /* not really meaningful to distinguish up/down */
4159 emacs_event
->modifiers
= msg
->dwModifiers
;
4160 emacs_event
->frame_or_window
= bar
->window
;
4161 emacs_event
->arg
= Qnil
;
4162 emacs_event
->timestamp
= msg
->msg
.time
;
4165 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4167 int dragging
= bar
->dragging
;
4169 int sb_event
= LOWORD (msg
->msg
.wParam
);
4171 si
.cbSize
= sizeof (si
);
4172 if (sb_event
== SB_THUMBTRACK
)
4173 si
.fMask
= SIF_TRACKPOS
;
4177 GetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
4178 if (sb_event
== SB_THUMBTRACK
)
4184 FRAME_DISPLAY_INFO (f
)->last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
4189 emacs_event
->part
= scroll_bar_down_arrow
;
4192 emacs_event
->part
= scroll_bar_up_arrow
;
4195 emacs_event
->part
= scroll_bar_above_handle
;
4198 emacs_event
->part
= scroll_bar_below_handle
;
4201 emacs_event
->part
= scroll_bar_handle
;
4205 emacs_event
->part
= scroll_bar_handle
;
4209 case SB_THUMBPOSITION
:
4210 bar
->dragging
= 1; /* ??????? */
4211 emacs_event
->part
= scroll_bar_handle
;
4213 /* "Silently" update current position. */
4217 si
.cbSize
= sizeof (si
);
4220 /* Remember apparent position (we actually lag behind the real
4221 position, so don't set that directly). */
4222 last_scroll_bar_drag_pos
= y
;
4224 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
4228 /* If this is the end of a drag sequence, then reset the scroll
4229 handle size to normal and do a final redraw. Otherwise do
4234 int start
= bar
->start
;
4237 si
.cbSize
= sizeof (si
);
4238 si
.fMask
= SIF_PAGE
| SIF_POS
;
4239 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4240 si
.nPos
= last_scroll_bar_drag_pos
;
4241 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
4245 emacs_event
->kind
= NO_EVENT
;
4249 XSETINT (emacs_event
->x
, y
);
4250 XSETINT (emacs_event
->y
, top_range
);
4256 /* Handle a mouse click on the horizontal scroll bar BAR. If
4257 *EMACS_EVENT's kind is set to something other than NO_EVENT, it is
4260 This may be called from a signal handler, so we have to ignore GC
4264 w32_horizontal_scroll_bar_handle_click (struct scroll_bar
*bar
, W32Msg
*msg
,
4265 struct input_event
*emacs_event
)
4267 if (! WINDOWP (bar
->window
))
4270 emacs_event
->kind
= HORIZONTAL_SCROLL_BAR_CLICK_EVENT
;
4271 emacs_event
->code
= 0;
4272 /* not really meaningful to distinguish left/right */
4273 emacs_event
->modifiers
= msg
->dwModifiers
;
4274 emacs_event
->frame_or_window
= bar
->window
;
4275 emacs_event
->arg
= Qnil
;
4276 emacs_event
->timestamp
= msg
->msg
.time
;
4279 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
4281 int dragging
= bar
->dragging
;
4283 int sb_event
= LOWORD (msg
->msg
.wParam
);
4285 si
.cbSize
= sizeof (si
);
4286 if (sb_event
== SB_THUMBTRACK
)
4287 si
.fMask
= SIF_TRACKPOS
| SIF_PAGE
| SIF_RANGE
;
4289 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
4291 GetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
4292 if (sb_event
== SB_THUMBTRACK
)
4296 y
= si
.nMax
- si
.nPage
;
4299 FRAME_DISPLAY_INFO (f
)->last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
4304 emacs_event
->part
= scroll_bar_left_arrow
;
4307 emacs_event
->part
= scroll_bar_right_arrow
;
4310 emacs_event
->part
= scroll_bar_before_handle
;
4313 emacs_event
->part
= scroll_bar_after_handle
;
4316 emacs_event
->part
= scroll_bar_horizontal_handle
;
4320 emacs_event
->part
= scroll_bar_horizontal_handle
;
4324 case SB_THUMBPOSITION
:
4326 emacs_event
->part
= scroll_bar_horizontal_handle
;
4328 /* "Silently" update current position. */
4332 si
.cbSize
= sizeof (si
);
4334 si
.nPos
= min (x
, XWINDOW (bar
->window
)->hscroll_whole
- 1);
4335 /* Remember apparent position (we actually lag behind the real
4336 position, so don't set that directly). */
4337 last_scroll_bar_drag_pos
= x
;
4339 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
4343 /* If this is the end of a drag sequence, then reset the scroll
4344 handle size to normal and do a final redraw. Otherwise do
4349 int start
= bar
->start
;
4352 si
.cbSize
= sizeof (si
);
4354 si
.nPos
= min (last_scroll_bar_drag_pos
,
4355 XWINDOW (bar
->window
)->hscroll_whole
- 1);
4356 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
4360 emacs_event
->kind
= NO_EVENT
;
4364 XSETINT (emacs_event
->x
, x
);
4365 XSETINT (emacs_event
->y
, y
);
4371 /* Return information to the user about the current position of the mouse
4372 on the vertical scroll bar. */
4374 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
4375 enum scroll_bar_part
*part
,
4376 Lisp_Object
*x
, Lisp_Object
*y
,
4377 unsigned long *time
)
4379 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
4380 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
4381 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
4382 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4384 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4386 int sb_event
= LOWORD (dpyinfo
->last_mouse_scroll_bar_pos
);
4391 *bar_window
= bar
->window
;
4393 si
.cbSize
= sizeof (si
);
4394 if (sb_event
== SB_THUMBTRACK
)
4395 si
.fMask
= SIF_TRACKPOS
| SIF_PAGE
| SIF_RANGE
;
4397 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
4399 GetScrollInfo (w
, SB_CTL
, &si
);
4400 if (sb_event
== SB_THUMBTRACK
)
4404 top_range
= si
.nMax
- si
.nPage
+ 1;
4406 *part
= scroll_bar_handle
;
4407 if (sb_event
== SB_LINEDOWN
)
4411 XSETINT (*y
, top_range
);
4414 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4416 *time
= dpyinfo
->last_mouse_movement_time
;
4421 /* Return information to the user about the current position of the mouse
4422 on the horizontal scroll bar. */
4424 x_horizontal_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
4425 enum scroll_bar_part
*part
,
4426 Lisp_Object
*x
, Lisp_Object
*y
,
4427 unsigned long *time
)
4429 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
4430 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
4431 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
4432 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4434 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
4436 int sb_event
= LOWORD (dpyinfo
->last_mouse_scroll_bar_pos
);
4441 *bar_window
= bar
->window
;
4443 si
.cbSize
= sizeof (si
);
4444 if (sb_event
== SB_THUMBTRACK
)
4445 si
.fMask
= SIF_TRACKPOS
| SIF_PAGE
| SIF_RANGE
;
4447 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
4449 GetScrollInfo (w
, SB_CTL
, &si
);
4450 if (sb_event
== SB_THUMBTRACK
)
4454 left_range
= si
.nMax
- si
.nPage
+ 1;
4456 *part
= scroll_bar_handle
;
4457 if (sb_event
== SB_LINERIGHT
)
4462 XSETINT (*x
, left_range
);
4465 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4467 *time
= dpyinfo
->last_mouse_movement_time
;
4473 /* The screen has been cleared so we may have changed foreground or
4474 background colors, and the scroll bars may need to be redrawn.
4475 Clear out the scroll bars, and ask for expose events, so we can
4479 x_scroll_bar_clear (struct frame
*f
)
4483 /* We can have scroll bars even if this is 0,
4484 if we just turned off scroll bar mode.
4485 But in that case we should not clear them. */
4486 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4487 || FRAME_HAS_HORIZONTAL_SCROLL_BARS (f
))
4488 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
4489 bar
= XSCROLL_BAR (bar
)->next
)
4491 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
4492 HDC hdc
= GetDC (window
);
4495 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
4496 arranges to refresh the scroll bar if hidden. */
4497 my_show_window (f
, window
, SW_HIDE
);
4499 GetClientRect (window
, &rect
);
4500 select_palette (f
, hdc
);
4501 w32_clear_rect (f
, hdc
, &rect
);
4502 deselect_palette (f
, hdc
);
4504 ReleaseDC (window
, hdc
);
4509 set_frame_param (struct frame
*f
, Lisp_Object prop
, Lisp_Object val
)
4511 register Lisp_Object old_alist_elt
;
4513 old_alist_elt
= Fassq (prop
, f
->param_alist
);
4514 if (EQ (old_alist_elt
, Qnil
))
4515 fset_param_alist (f
, Fcons (Fcons (prop
, val
), f
->param_alist
));
4517 Fsetcdr (old_alist_elt
, val
);
4520 /* The main W32 event-reading loop - w32_read_socket. */
4522 /* Record the last 100 characters stored
4523 to help debug the loss-of-chars-during-GC problem. */
4525 static int temp_index
;
4526 static short temp_buffer
[100];
4528 /* Temporarily store lead byte of DBCS input sequences. */
4529 static char dbcs_lead
= 0;
4531 /* Read events coming from the W32 shell.
4532 This routine is called by the SIGIO handler.
4533 We return as soon as there are no more events to be read.
4535 For an overview of how Emacs input works on MS-Windows, see the
4536 commentary before w32_msg_pump in w32fns.c.
4538 We return the number of characters stored into the buffer,
4539 thus pretending to be `read'.
4541 Some of these messages are reposted back to the message queue since the
4542 system calls the windows proc directly in a context where we cannot return
4543 the data nor can we guarantee the state we are in. So if we dispatch them
4544 we will get into an infinite loop. To prevent this from ever happening we
4545 will set a variable to indicate we are in the read_socket call and indicate
4546 which message we are processing since the windows proc gets called
4547 recursively with different messages by the system.
4551 w32_read_socket (struct terminal
*terminal
,
4552 struct input_event
*hold_quit
)
4555 int check_visibility
= 0;
4558 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4559 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
4563 /* So people can tell when we have read the available input. */
4564 input_signal_count
++;
4566 /* Process any incoming thread messages. */
4567 drain_message_queue ();
4569 /* TODO: ghostscript integration. */
4570 while (get_next_msg (&msg
, FALSE
))
4572 struct input_event inev
;
4575 /* DebPrint (("w32_read_socket: %s time:%u\n", */
4576 /* w32_name_of_message (msg.msg.message), */
4577 /* msg.msg.time)); */
4580 inev
.kind
= NO_EVENT
;
4583 switch (msg
.msg
.message
)
4585 case WM_EMACS_PAINT
:
4586 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4590 if (msg
.rect
.right
== msg
.rect
.left
||
4591 msg
.rect
.bottom
== msg
.rect
.top
)
4593 /* We may get paint messages even though the client
4594 area is clipped - these are not expose events. */
4595 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
4598 else if (FRAME_VISIBLE_P (f
) != 1)
4600 bool iconified
= FRAME_ICONIFIED_P (f
);
4602 /* Definitely not obscured, so mark as visible. */
4603 SET_FRAME_VISIBLE (f
, 1);
4604 SET_FRAME_ICONIFIED (f
, 0);
4605 SET_FRAME_GARBAGED (f
);
4606 if (!f
->output_data
.w32
->asked_for_visible
)
4607 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
4610 /* WM_PAINT serves as MapNotify as well, so report
4611 visibility changes properly. */
4614 inev
.kind
= DEICONIFY_EVENT
;
4615 XSETFRAME (inev
.frame_or_window
, f
);
4617 else if (!NILP (Vframe_list
) && !NILP (XCDR (Vframe_list
)))
4618 /* Force a redisplay sooner or later to update the
4619 frame titles in case this is the second frame. */
4620 record_asynch_buffer_change ();
4624 HDC hdc
= get_frame_dc (f
);
4626 /* Erase background again for safety. */
4627 w32_clear_rect (f
, hdc
, &msg
.rect
);
4628 release_frame_dc (f
, hdc
);
4632 msg
.rect
.right
- msg
.rect
.left
,
4633 msg
.rect
.bottom
- msg
.rect
.top
);
4638 case WM_INPUTLANGCHANGE
:
4639 /* Generate a language change event. */
4640 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4642 /* lParam contains the input language ID in its low 16 bits.
4643 Use it to update our record of the keyboard codepage. */
4644 w32_keyboard_codepage
= codepage_for_locale ((LCID
)(msg
.msg
.lParam
4649 inev
.kind
= LANGUAGE_CHANGE_EVENT
;
4650 XSETFRAME (inev
.frame_or_window
, f
);
4651 inev
.code
= w32_keyboard_codepage
;
4652 inev
.modifiers
= msg
.msg
.lParam
& 0xffff;
4658 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4660 if (f
&& !FRAME_ICONIFIED_P (f
))
4662 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4663 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4665 clear_mouse_face (hlinfo
);
4666 hlinfo
->mouse_face_hidden
= 1;
4669 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4671 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4672 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
4673 inev
.code
= msg
.msg
.wParam
;
4674 inev
.modifiers
= msg
.dwModifiers
;
4675 XSETFRAME (inev
.frame_or_window
, f
);
4676 inev
.timestamp
= msg
.msg
.time
;
4683 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4685 if (f
&& !FRAME_ICONIFIED_P (f
))
4687 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4688 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4690 clear_mouse_face (hlinfo
);
4691 hlinfo
->mouse_face_hidden
= 1;
4694 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4696 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4698 inev
.modifiers
= msg
.dwModifiers
;
4699 XSETFRAME (inev
.frame_or_window
, f
);
4700 inev
.timestamp
= msg
.msg
.time
;
4702 if (msg
.msg
.message
== WM_UNICHAR
)
4704 inev
.code
= msg
.msg
.wParam
;
4706 else if (msg
.msg
.wParam
< 256)
4711 dbcs
[1] = (char) msg
.msg
.wParam
;
4715 dbcs
[0] = dbcs_lead
;
4717 if (!MultiByteToWideChar (w32_keyboard_codepage
, 0,
4721 DebPrint (("Invalid DBCS sequence: %d %d\n",
4723 inev
.kind
= NO_EVENT
;
4727 else if (IsDBCSLeadByteEx (w32_keyboard_codepage
,
4728 (BYTE
) msg
.msg
.wParam
))
4730 dbcs_lead
= (char) msg
.msg
.wParam
;
4731 inev
.kind
= NO_EVENT
;
4736 if (!MultiByteToWideChar (w32_keyboard_codepage
, 0,
4737 &dbcs
[1], 1, &code
, 1))
4739 /* What to do with garbage? */
4740 DebPrint (("Invalid character: %d\n", dbcs
[1]));
4741 inev
.kind
= NO_EVENT
;
4749 /* Windows shouldn't generate WM_CHAR events above 0xFF
4750 in non-Unicode message handlers. */
4751 DebPrint (("Non-byte WM_CHAR: %d\n", msg
.msg
.wParam
));
4752 inev
.kind
= NO_EVENT
;
4755 inev
.kind
= inev
.code
< 128 ? ASCII_KEYSTROKE_EVENT
4756 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
4761 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4763 if (f
&& !FRAME_ICONIFIED_P (f
))
4765 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4766 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4768 clear_mouse_face (hlinfo
);
4769 hlinfo
->mouse_face_hidden
= 1;
4772 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4774 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4775 inev
.kind
= MULTIMEDIA_KEY_EVENT
;
4776 inev
.code
= GET_APPCOMMAND_LPARAM (msg
.msg
.lParam
);
4777 inev
.modifiers
= msg
.dwModifiers
;
4778 XSETFRAME (inev
.frame_or_window
, f
);
4779 inev
.timestamp
= msg
.msg
.time
;
4784 /* Ignore non-movement. */
4786 int x
= LOWORD (msg
.msg
.lParam
);
4787 int y
= HIWORD (msg
.msg
.lParam
);
4788 if (x
== last_mousemove_x
&& y
== last_mousemove_y
)
4790 last_mousemove_x
= x
;
4791 last_mousemove_y
= y
;
4794 previous_help_echo_string
= help_echo_string
;
4795 help_echo_string
= Qnil
;
4797 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4798 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4800 if (hlinfo
->mouse_face_hidden
)
4802 hlinfo
->mouse_face_hidden
= 0;
4803 clear_mouse_face (hlinfo
);
4808 /* Generate SELECT_WINDOW_EVENTs when needed. */
4809 if (!NILP (Vmouse_autoselect_window
))
4811 static Lisp_Object last_mouse_window
;
4812 Lisp_Object window
= window_from_coordinates
4813 (f
, LOWORD (msg
.msg
.lParam
), HIWORD (msg
.msg
.lParam
), 0, 0);
4815 /* Window will be selected only when it is not
4816 selected now and last mouse movement event was
4817 not in it. Minibuffer window will be selected
4818 only when it is active. */
4819 if (WINDOWP (window
)
4820 && !EQ (window
, last_mouse_window
)
4821 && !EQ (window
, selected_window
)
4822 /* For click-to-focus window managers
4823 create event iff we don't leave the
4825 && (focus_follows_mouse
4826 || (EQ (XWINDOW (window
)->frame
,
4827 XWINDOW (selected_window
)->frame
))))
4829 inev
.kind
= SELECT_WINDOW_EVENT
;
4830 inev
.frame_or_window
= window
;
4832 /* Remember the last window where we saw the mouse. */
4833 last_mouse_window
= window
;
4835 if (!note_mouse_movement (f
, &msg
.msg
))
4836 help_echo_string
= previous_help_echo_string
;
4840 /* If we move outside the frame, then we're
4841 certainly no longer on any text in the frame. */
4842 clear_mouse_face (hlinfo
);
4845 /* If the contents of the global variable help_echo_string
4846 has changed, generate a HELP_EVENT. */
4847 #if 0 /* The below is an invalid comparison when CHECK_LISP_OBJECT_TYPE.
4848 But it was originally changed to this to fix a bug, so I have
4849 not removed it completely in case the bug is still there. */
4850 if (help_echo_string
!= previous_help_echo_string
||
4851 (!NILP (help_echo_string
) && !STRINGP (help_echo_string
) && f
->mouse_moved
))
4852 #else /* This is what xterm.c does. */
4853 if (!NILP (help_echo_string
)
4854 || !NILP (previous_help_echo_string
))
4859 case WM_LBUTTONDOWN
:
4861 case WM_MBUTTONDOWN
:
4863 case WM_RBUTTONDOWN
:
4865 case WM_XBUTTONDOWN
:
4868 /* If we decide we want to generate an event to be seen
4869 by the rest of Emacs, we put it here. */
4870 bool tool_bar_p
= 0;
4874 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4875 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4879 construct_mouse_click (&inev
, &msg
, f
);
4881 /* Is this in the tool-bar? */
4882 if (WINDOWP (f
->tool_bar_window
)
4883 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
4886 int x
= XFASTINT (inev
.x
);
4887 int y
= XFASTINT (inev
.y
);
4889 window
= window_from_coordinates (f
, x
, y
, 0, 1);
4891 if (EQ (window
, f
->tool_bar_window
))
4893 w32_handle_tool_bar_click (f
, &inev
);
4899 || (dpyinfo
->w32_focus_frame
4900 && f
!= dpyinfo
->w32_focus_frame
))
4901 inev
.kind
= NO_EVENT
;
4904 parse_button (msg
.msg
.message
, HIWORD (msg
.msg
.wParam
),
4909 dpyinfo
->grabbed
&= ~ (1 << button
);
4913 dpyinfo
->grabbed
|= (1 << button
);
4914 dpyinfo
->last_mouse_frame
= f
;
4915 /* Ignore any mouse motion that happened
4916 before this event; any subsequent mouse-movement
4917 Emacs events should reflect only motion after
4923 f
->last_tool_bar_item
= -1;
4930 case WM_MOUSEHWHEEL
:
4932 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4933 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4938 if (!dpyinfo
->w32_focus_frame
4939 || f
== dpyinfo
->w32_focus_frame
)
4941 /* Emit an Emacs wheel-up/down event. */
4942 construct_mouse_wheel (&inev
, &msg
, f
);
4944 /* Ignore any mouse motion that happened before this
4945 event; any subsequent mouse-movement Emacs events
4946 should reflect only motion after the
4949 f
->last_tool_bar_item
= -1;
4951 dpyinfo
->last_mouse_frame
= f
;
4956 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4959 construct_drag_n_drop (&inev
, &msg
, f
);
4964 struct scroll_bar
*bar
=
4965 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
, 1);
4968 w32_horizontal_scroll_bar_handle_click (bar
, &msg
, &inev
);
4974 struct scroll_bar
*bar
=
4975 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
, 0);
4978 w32_scroll_bar_handle_click (bar
, &msg
, &inev
);
4982 case WM_WINDOWPOSCHANGED
:
4984 case WM_ACTIVATEAPP
:
4985 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4988 /* Run the full-screen hook function also when we are
4989 being activated, to actually install the required
4990 size in effect, if the WAIT flag is set. This is
4991 because when the hook is run from x_set_fullscreen,
4992 the frame might not yet be visible, if that call is a
4993 result of make-frame, and in that case the hook just
4994 sets the WAIT flag. */
4995 if ((msg
.msg
.message
== WM_WINDOWPOSCHANGED
|| msg
.msg
.wParam
)
4996 && (f
->want_fullscreen
& FULLSCREEN_WAIT
))
4997 w32fullscreen_hook (f
);
4998 x_check_fullscreen (f
);
5000 check_visibility
= 1;
5004 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5006 if (f
&& !FRAME_ICONIFIED_P (f
))
5007 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5009 check_visibility
= 1;
5013 /* wParam non-zero means Window is about to be shown, 0 means
5014 about to be hidden. */
5015 /* Redo the mouse-highlight after the tooltip has gone. */
5016 if (!msg
.msg
.wParam
&& msg
.msg
.hwnd
== tip_window
)
5019 x_redo_mouse_highlight (dpyinfo
);
5022 /* If window has been obscured or exposed by another window
5023 being maximized or minimized/restored, then recheck
5024 visibility of all frames. Direct changes to our own
5025 windows get handled by WM_SIZE. */
5027 if (msg
.msg
.lParam
!= 0)
5028 check_visibility
= 1;
5031 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5032 f
->async_visible
= msg
.msg
.wParam
;
5036 check_visibility
= 1;
5040 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5042 /* Inform lisp of whether frame has been iconified etc. */
5045 switch (msg
.msg
.wParam
)
5047 case SIZE_MINIMIZED
:
5048 SET_FRAME_VISIBLE (f
, 0);
5049 SET_FRAME_ICONIFIED (f
, 1);
5051 inev
.kind
= ICONIFY_EVENT
;
5052 XSETFRAME (inev
.frame_or_window
, f
);
5055 case SIZE_MAXIMIZED
:
5057 bool iconified
= FRAME_ICONIFIED_P (f
);
5059 SET_FRAME_VISIBLE (f
, 1);
5060 SET_FRAME_ICONIFIED (f
, 0);
5062 /* wait_reading_process_output will notice this
5063 and update the frame's display structures. */
5064 SET_FRAME_GARBAGED (f
);
5070 /* Reset top and left positions of the Window
5071 here since Windows sends a WM_MOVE message
5072 BEFORE telling us the Window is minimized
5073 when the Window is iconified, with 3000,3000
5075 x_real_positions (f
, &x
, &y
);
5079 inev
.kind
= DEICONIFY_EVENT
;
5080 XSETFRAME (inev
.frame_or_window
, f
);
5082 else if (! NILP (Vframe_list
)
5083 && ! NILP (XCDR (Vframe_list
)))
5084 /* Force a redisplay sooner or later
5085 to update the frame titles
5086 in case this is the second frame. */
5087 record_asynch_buffer_change ();
5090 if (EQ (get_frame_param (f
, Qfullscreen
), Qnil
))
5091 set_frame_param (f
, Qfullscreen
, Qmaximized
);
5092 else if (! EQ (get_frame_param (f
, Qfullscreen
), Qmaximized
))
5093 set_frame_param (f
, Qmaximized
, Qmaximized
);
5099 bool iconified
= FRAME_ICONIFIED_P (f
);
5101 /* The following was made unconditional in a
5102 pathetic attempt to fix bug#16967 in revision
5103 116716 but, considered counterproductive was made
5104 conditional again in revision 116727. martin */
5106 SET_FRAME_VISIBLE (f
, 1);
5107 SET_FRAME_ICONIFIED (f
, 0);
5109 /* wait_reading_process_output will notice this
5110 and update the frame's display structures. */
5111 SET_FRAME_GARBAGED (f
);
5115 /* Reset top and left positions of the Window
5116 here since Windows sends a WM_MOVE message
5117 BEFORE telling us the Window is minimized
5118 when the Window is iconified, with 3000,3000
5120 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5122 inev
.kind
= DEICONIFY_EVENT
;
5123 XSETFRAME (inev
.frame_or_window
, f
);
5125 else if (! NILP (Vframe_list
)
5126 && ! NILP (XCDR (Vframe_list
)))
5127 /* Force a redisplay sooner or later
5128 to update the frame titles
5129 in case this is the second frame. */
5130 record_asynch_buffer_change ();
5133 if (EQ (get_frame_param (f
, Qfullscreen
), Qmaximized
))
5134 set_frame_param (f
, Qfullscreen
, Qnil
);
5135 else if (! EQ (get_frame_param (f
, Qmaximized
), Qnil
))
5136 set_frame_param (f
, Qmaximized
, Qnil
);
5142 if (f
&& !FRAME_ICONIFIED_P (f
) && msg
.msg
.wParam
!= SIZE_MINIMIZED
)
5145 int rows
, columns
, width
, height
, text_width
, text_height
;
5147 GetClientRect (msg
.msg
.hwnd
, &rect
);
5149 height
= rect
.bottom
- rect
.top
;
5150 width
= rect
.right
- rect
.left
;
5151 text_width
= FRAME_PIXEL_TO_TEXT_WIDTH (f
, width
);
5152 text_height
= FRAME_PIXEL_TO_TEXT_HEIGHT (f
, height
);
5153 /* rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); */
5154 /* columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); */
5156 /* TODO: Clip size to the screen dimensions. */
5158 /* Even if the number of character rows and columns has
5159 not changed, the font size may have changed, so we need
5160 to check the pixel dimensions as well. */
5162 if (width
!= FRAME_PIXEL_WIDTH (f
)
5163 || height
!= FRAME_PIXEL_HEIGHT (f
)
5164 || text_width
!= FRAME_TEXT_WIDTH (f
)
5165 || text_height
!= FRAME_TEXT_HEIGHT (f
))
5167 change_frame_size (f
, text_width
, text_height
, 0, 1, 0, 1);
5168 SET_FRAME_GARBAGED (f
);
5169 cancel_mouse_face (f
);
5170 f
->win_gravity
= NorthWestGravity
;
5174 check_visibility
= 1;
5178 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5181 if (f
== hlinfo
->mouse_face_mouse_frame
)
5183 /* If we move outside the frame, then we're
5184 certainly no longer on any text in the frame. */
5185 clear_mouse_face (hlinfo
);
5186 hlinfo
->mouse_face_mouse_frame
= 0;
5189 /* Generate a nil HELP_EVENT to cancel a help-echo.
5190 Do it only if there's something to cancel.
5191 Otherwise, the startup message is cleared when
5192 the mouse leaves the frame. */
5193 if (any_help_event_p
)
5199 w32_detect_focus_change (dpyinfo
, &msg
, &inev
);
5201 dpyinfo
->grabbed
= 0;
5202 check_visibility
= 1;
5206 w32_detect_focus_change (dpyinfo
, &msg
, &inev
);
5207 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5211 if (f
== hlinfo
->mouse_face_mouse_frame
)
5213 /* If we move outside the frame, then we're
5214 certainly no longer on any text in the frame. */
5215 clear_mouse_face (hlinfo
);
5216 hlinfo
->mouse_face_mouse_frame
= 0;
5219 /* Generate a nil HELP_EVENT to cancel a help-echo.
5220 Do it only if there's something to cancel.
5221 Otherwise, the startup message is cleared when
5222 the mouse leaves the frame. */
5223 if (any_help_event_p
)
5227 dpyinfo
->grabbed
= 0;
5228 check_visibility
= 1;
5232 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5236 inev
.kind
= DELETE_WINDOW_EVENT
;
5237 XSETFRAME (inev
.frame_or_window
, f
);
5242 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5246 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
5247 XSETFRAME (inev
.frame_or_window
, f
);
5252 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5256 extern void menubar_selection_callback
5257 (struct frame
*f
, void * client_data
);
5258 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
5261 check_visibility
= 1;
5264 case WM_DISPLAYCHANGE
:
5265 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5269 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
5270 /* The new display could have a different resolution, in
5271 which case we must reconsider what fullscreen
5273 x_check_fullscreen (f
);
5274 DebPrint (("display change: %d %d\n",
5275 (short) LOWORD (msg
.msg
.lParam
),
5276 (short) HIWORD (msg
.msg
.lParam
)));
5279 check_visibility
= 1;
5283 case WM_EMACS_FILENOTIFY
:
5284 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5286 queue_notifications (&inev
, &msg
, f
, &count
);
5291 /* Check for messages registered at runtime. */
5292 if (msg
.msg
.message
== msh_mousewheel
)
5294 /* Forward MSH_MOUSEWHEEL as WM_MOUSEWHEEL. */
5295 msg
.msg
.message
= WM_MOUSEWHEEL
;
5301 if (inev
.kind
!= NO_EVENT
)
5303 kbd_buffer_store_event_hold (&inev
, hold_quit
);
5308 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
5313 XSETFRAME (frame
, f
);
5319 if (NILP (help_echo_string
))
5321 help_echo_object
= help_echo_window
= Qnil
;
5325 any_help_event_p
= 1;
5326 gen_help_event (help_echo_string
, frame
, help_echo_window
,
5327 help_echo_object
, help_echo_pos
);
5331 help_echo_string
= Qnil
;
5332 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
5338 /* If the focus was just given to an autoraising frame,
5339 raise it now. FIXME: handle more than one such frame. */
5340 if (dpyinfo
->w32_pending_autoraise_frame
)
5342 x_raise_frame (dpyinfo
->w32_pending_autoraise_frame
);
5343 dpyinfo
->w32_pending_autoraise_frame
= NULL
;
5346 /* Check which frames are still visible, if we have enqueued any user
5347 events or been notified of events that may affect visibility. We
5348 do this here because there doesn't seem to be any direct
5349 notification from Windows that the visibility of a window has
5350 changed (at least, not in all cases). */
5351 if (count
> 0 || check_visibility
)
5353 Lisp_Object tail
, frame
;
5355 FOR_EACH_FRAME (tail
, frame
)
5357 struct frame
*f
= XFRAME (frame
);
5358 /* The tooltip has been drawn already. Avoid the
5359 SET_FRAME_GARBAGED below. */
5360 if (EQ (frame
, tip_frame
))
5363 /* Check "visible" frames and mark each as obscured or not.
5364 Note that visible is nonzero for unobscured and obscured
5365 frames, but zero for hidden and iconified frames. */
5366 if (FRAME_W32_P (f
) && FRAME_VISIBLE_P (f
))
5373 /* Query clipping rectangle for the entire window area
5374 (GetWindowDC), not just the client portion (GetDC).
5375 Otherwise, the scrollbars and menubar aren't counted as
5376 part of the visible area of the frame, and we may think
5377 the frame is obscured when really a scrollbar is still
5378 visible and gets WM_PAINT messages above. */
5379 hdc
= GetWindowDC (FRAME_W32_WINDOW (f
));
5380 GetClipBox (hdc
, &clipbox
);
5381 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
5384 obscured
= FRAME_OBSCURED_P (f
);
5386 if (clipbox
.right
== clipbox
.left
|| clipbox
.bottom
== clipbox
.top
)
5388 /* Frame has become completely obscured so mark as such (we
5389 do this by setting visible to 2 so that FRAME_VISIBLE_P
5390 is still true, but redisplay will skip it). */
5391 SET_FRAME_VISIBLE (f
, 2);
5394 DebPrint (("frame %p (%s) obscured\n", f
, SDATA (f
->name
)));
5398 /* Frame is not obscured, so mark it as such. */
5399 SET_FRAME_VISIBLE (f
, 1);
5403 SET_FRAME_GARBAGED (f
);
5404 DebPrint (("obscured frame %p (%s) found to be visible\n",
5405 f
, SDATA (f
->name
)));
5407 /* Force a redisplay sooner or later. */
5408 record_asynch_buffer_change ();
5421 /***********************************************************************
5423 ***********************************************************************/
5425 /* Set clipping for output in glyph row ROW. W is the window in which
5426 we operate. GC is the graphics context to set clipping in.
5428 ROW may be a text row or, e.g., a mode line. Text rows must be
5429 clipped to the interior of the window dedicated to text display,
5430 mode lines must be clipped to the whole window. */
5433 w32_clip_to_row (struct window
*w
, struct glyph_row
*row
,
5434 enum glyph_row_area area
, HDC hdc
)
5437 int window_x
, window_y
, window_width
;
5439 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
5441 clip_rect
.left
= window_x
;
5442 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5443 clip_rect
.top
= max (clip_rect
.top
, window_y
);
5444 clip_rect
.right
= clip_rect
.left
+ window_width
;
5445 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
5447 w32_set_clip_rectangle (hdc
, &clip_rect
);
5451 /* Draw a hollow box cursor on window W in glyph row ROW. */
5454 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
5456 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5460 struct glyph
*cursor_glyph
;
5461 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
5463 /* Get the glyph the cursor is on. If we can't tell because
5464 the current matrix is invalid or such, give up. */
5465 cursor_glyph
= get_phys_cursor_glyph (w
);
5466 if (cursor_glyph
== NULL
)
5472 /* Compute frame-relative coordinates for phys cursor. */
5473 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &left
, &top
, &h
);
5476 rect
.bottom
= rect
.top
+ h
;
5477 rect
.right
= rect
.left
+ w
->phys_cursor_width
;
5479 hdc
= get_frame_dc (f
);
5480 /* Set clipping, draw the rectangle, and reset clipping again. */
5481 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
5482 FrameRect (hdc
, &rect
, hb
);
5484 w32_set_clip_rectangle (hdc
, NULL
);
5485 release_frame_dc (f
, hdc
);
5489 /* Draw a bar cursor on window W in glyph row ROW.
5491 Implementation note: One would like to draw a bar cursor with an
5492 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5493 Unfortunately, I didn't find a font yet that has this property set.
5497 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
,
5498 int width
, enum text_cursor_kinds kind
)
5500 struct frame
*f
= XFRAME (w
->frame
);
5501 struct glyph
*cursor_glyph
;
5503 /* If cursor is out of bounds, don't draw garbage. This can happen
5504 in mini-buffer windows when switching between echo area glyphs
5506 cursor_glyph
= get_phys_cursor_glyph (w
);
5507 if (cursor_glyph
== NULL
)
5510 /* If on an image, draw like a normal cursor. That's usually better
5511 visible than drawing a bar, esp. if the image is large so that
5512 the bar might not be in the window. */
5513 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5515 struct glyph_row
*row
;
5516 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5517 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5521 COLORREF cursor_color
= f
->output_data
.w32
->cursor_pixel
;
5522 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5526 /* If the glyph's background equals the color we normally draw
5527 the bar cursor in, the bar cursor in its normal color is
5528 invisible. Use the glyph's foreground color instead in this
5529 case, on the assumption that the glyph's colors are chosen so
5530 that the glyph is legible. */
5531 if (face
->background
== cursor_color
)
5532 cursor_color
= face
->foreground
;
5534 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5536 hdc
= get_frame_dc (f
);
5537 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
5539 if (kind
== BAR_CURSOR
)
5542 width
= FRAME_CURSOR_WIDTH (f
);
5543 width
= min (cursor_glyph
->pixel_width
, width
);
5545 w
->phys_cursor_width
= width
;
5547 /* If the character under cursor is R2L, draw the bar cursor
5548 on the right of its glyph, rather than on the left. */
5549 if ((cursor_glyph
->resolved_level
& 1) != 0)
5550 x
+= cursor_glyph
->pixel_width
- width
;
5552 w32_fill_area (f
, hdc
, cursor_color
, x
,
5553 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5554 width
, row
->height
);
5558 int dummy_x
, dummy_y
, dummy_h
;
5561 width
= row
->height
;
5563 width
= min (row
->height
, width
);
5565 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
5566 &dummy_y
, &dummy_h
);
5567 w32_fill_area (f
, hdc
, cursor_color
, x
,
5568 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5569 row
->height
- width
),
5570 w
->phys_cursor_width
, width
);
5573 w32_set_clip_rectangle (hdc
, NULL
);
5574 release_frame_dc (f
, hdc
);
5579 /* RIF: Define cursor CURSOR on frame F. */
5582 w32_define_frame_cursor (struct frame
*f
, Cursor cursor
)
5584 w32_define_cursor (FRAME_W32_WINDOW (f
), cursor
);
5588 /* RIF: Clear area on frame F. */
5591 w32_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
5595 hdc
= get_frame_dc (f
);
5596 w32_clear_area (f
, hdc
, x
, y
, width
, height
);
5597 release_frame_dc (f
, hdc
);
5600 /* RIF: Draw or clear cursor on window W. */
5603 w32_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
,
5604 int x
, int y
, enum text_cursor_kinds cursor_type
,
5605 int cursor_width
, bool on_p
, bool active_p
)
5609 /* If the user wants to use the system caret, make sure our own
5610 cursor remains invisible. */
5611 if (w32_use_visible_system_caret
)
5613 /* Call to erase_phys_cursor here seems to use the
5614 wrong values of w->phys_cursor, as they have been
5615 overwritten before this function was called. */
5616 if (w
->phys_cursor_type
!= NO_CURSOR
)
5617 erase_phys_cursor (w
);
5619 cursor_type
= w
->phys_cursor_type
= NO_CURSOR
;
5620 w
->phys_cursor_width
= -1;
5624 w
->phys_cursor_type
= cursor_type
;
5627 w
->phys_cursor_on_p
= 1;
5629 /* If this is the active cursor, we need to track it with the
5630 system caret, so third party software like screen magnifiers
5631 and speech synthesizers can follow the cursor. */
5634 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5635 HWND hwnd
= FRAME_W32_WINDOW (f
);
5638 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5640 = (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
5641 + glyph_row
->ascent
- w
->phys_cursor_ascent
);
5642 w32_system_caret_window
= w
;
5643 w32_system_caret_hdr_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
5644 w32_system_caret_mode_height
= WINDOW_MODE_LINE_HEIGHT (w
);
5646 PostMessage (hwnd
, WM_IME_STARTCOMPOSITION
, 0, 0);
5648 /* If the size of the active cursor changed, destroy the old
5650 if (w32_system_caret_hwnd
5651 && (w32_system_caret_height
!= w
->phys_cursor_height
))
5652 PostMessage (hwnd
, WM_EMACS_DESTROY_CARET
, 0, 0);
5654 w32_system_caret_height
= w
->phys_cursor_height
;
5656 /* Move the system caret. */
5657 PostMessage (hwnd
, WM_EMACS_TRACK_CARET
, 0, 0);
5660 if (glyph_row
->exact_window_width_line_p
5661 && (glyph_row
->reversed_p
5662 ? (w
->phys_cursor
.hpos
< 0)
5663 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
5665 glyph_row
->cursor_in_fringe_p
= 1;
5666 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
5670 switch (cursor_type
)
5672 case HOLLOW_BOX_CURSOR
:
5673 x_draw_hollow_cursor (w
, glyph_row
);
5676 case FILLED_BOX_CURSOR
:
5677 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5681 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5685 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5689 w
->phys_cursor_width
= 0;
5703 x_bitmap_icon (struct frame
*f
, Lisp_Object icon
)
5706 HANDLE small_icon
= NULL
;
5708 if (FRAME_W32_WINDOW (f
) == 0)
5712 main_icon
= LoadIcon (hinst
, EMACS_CLASS
);
5713 else if (STRINGP (icon
))
5715 /* Load the main icon from the named file. */
5716 main_icon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5717 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5718 /* Try to load a small icon to go with it. */
5719 small_icon
= LoadImage (NULL
, (LPCSTR
) SDATA (icon
), IMAGE_ICON
,
5720 GetSystemMetrics (SM_CXSMICON
),
5721 GetSystemMetrics (SM_CYSMICON
),
5724 else if (SYMBOLP (icon
))
5728 if (EQ (icon
, intern ("application")))
5729 name
= (LPCTSTR
) IDI_APPLICATION
;
5730 else if (EQ (icon
, intern ("hand")))
5731 name
= (LPCTSTR
) IDI_HAND
;
5732 else if (EQ (icon
, intern ("question")))
5733 name
= (LPCTSTR
) IDI_QUESTION
;
5734 else if (EQ (icon
, intern ("exclamation")))
5735 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5736 else if (EQ (icon
, intern ("asterisk")))
5737 name
= (LPCTSTR
) IDI_ASTERISK
;
5738 else if (EQ (icon
, intern ("winlogo")))
5739 name
= (LPCTSTR
) IDI_WINLOGO
;
5743 main_icon
= LoadIcon (NULL
, name
);
5748 if (main_icon
== NULL
)
5751 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5752 (LPARAM
) main_icon
);
5754 /* If there is a small icon that goes with it, set that too. */
5756 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_SMALL
,
5757 (LPARAM
) small_icon
);
5763 /************************************************************************
5765 ************************************************************************/
5767 /* Display Error Handling functions not used on W32. Listing them here
5768 helps diff stay in step when comparing w32term.c with xterm.c.
5770 x_error_catcher (display, error)
5771 x_catch_errors (dpy)
5772 x_catch_errors_unwind (old_val)
5773 x_check_errors (dpy, format)
5774 x_fully_uncatch_errors ()
5775 x_had_errors_p (dpy)
5776 x_clear_errors (dpy)
5777 x_uncatch_errors (dpy, count)
5779 x_connection_signal (signalnum)
5780 x_connection_closed (dpy, error_message)
5781 x_error_quitter (display, error)
5782 x_error_handler (display, error)
5783 x_io_error_quitter (display)
5788 /* Changing the font of the frame. */
5791 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
5793 struct font
*font
= XFONT_OBJECT (font_object
);
5797 fontset
= fontset_from_font (font_object
);
5798 FRAME_FONTSET (f
) = fontset
;
5799 if (FRAME_FONT (f
) == font
)
5800 /* This font is already set in frame F. There's nothing more to
5804 FRAME_FONT (f
) = font
;
5805 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
5806 FRAME_COLUMN_WIDTH (f
) = unit
= font
->average_width
;
5807 FRAME_LINE_HEIGHT (f
) = font
->height
;
5809 /* Compute number of scrollbar columns. */
5810 unit
= FRAME_COLUMN_WIDTH (f
);
5811 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5812 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5813 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
5816 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
5817 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) =
5818 FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
5821 /* Now make the frame display the given font. */
5822 if (FRAME_X_WINDOW (f
) != 0)
5824 /* Don't change the size of a tip frame; there's no point in
5825 doing it because it's done in Fx_show_tip, and it leads to
5826 problems because the tip frame has no widget. */
5827 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5828 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
5829 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 3, 0);
5832 /* X version sets font of input methods here also. */
5838 /***********************************************************************
5839 TODO: W32 Input Methods
5840 ***********************************************************************/
5841 /* Listing missing functions from xterm.c helps diff stay in step.
5843 xim_destroy_callback (xim, client_data, call_data)
5844 xim_open_dpy (dpyinfo, resource_name)
5846 xim_instantiate_callback (display, client_data, call_data)
5847 xim_initialize (dpyinfo, resource_name)
5848 xim_close_dpy (dpyinfo)
5853 /* Calculate the absolute position in frame F
5854 from its current recorded position values and gravity. */
5857 x_calc_absolute_position (struct frame
*f
)
5859 int flags
= f
->size_hint_flags
;
5861 /* The sum of the widths of the frame's left and right borders, and
5862 the sum of the heights of the frame's top and bottom borders (in
5863 pixels) drawn by Windows. */
5864 unsigned int left_right_borders_width
, top_bottom_borders_height
;
5866 /* Try to get the actual values of these two variables. We compute
5867 the border width (height) by subtracting the width (height) of
5868 the frame's client area from the width (height) of the frame's
5870 WINDOWPLACEMENT wp
= { 0 };
5871 RECT client_rect
= { 0 };
5873 if (GetWindowPlacement (FRAME_W32_WINDOW (f
), &wp
)
5874 && GetClientRect (FRAME_W32_WINDOW (f
), &client_rect
))
5876 left_right_borders_width
=
5877 (wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
) -
5878 (client_rect
.right
- client_rect
.left
);
5880 top_bottom_borders_height
=
5881 (wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
) -
5882 (client_rect
.bottom
- client_rect
.top
);
5886 /* Use sensible default values. */
5887 left_right_borders_width
= 8;
5888 top_bottom_borders_height
= 32;
5891 /* Treat negative positions as relative to the rightmost bottommost
5892 position that fits on the screen. */
5893 if (flags
& XNegative
)
5894 f
->left_pos
= (x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
5895 - FRAME_PIXEL_WIDTH (f
)
5897 - (left_right_borders_width
- 1));
5899 if (flags
& YNegative
)
5900 f
->top_pos
= (x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
5901 - FRAME_PIXEL_HEIGHT (f
)
5903 - (top_bottom_borders_height
- 1));
5905 /* The left_pos and top_pos are now relative to the top and left
5906 screen edges, so the flags should correspond. */
5907 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5910 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5911 to really change the position, and 0 when calling from
5912 x_make_frame_visible (in that case, XOFF and YOFF are the current
5913 position values). It is -1 when calling from x_set_frame_parameters,
5914 which means, do adjust for borders but don't change the gravity. */
5917 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
,
5920 int modified_top
, modified_left
;
5922 if (change_gravity
> 0)
5926 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5928 f
->size_hint_flags
|= XNegative
;
5930 f
->size_hint_flags
|= YNegative
;
5931 f
->win_gravity
= NorthWestGravity
;
5933 x_calc_absolute_position (f
);
5936 x_wm_set_size_hint (f
, (long) 0, 0);
5938 modified_left
= f
->left_pos
;
5939 modified_top
= f
->top_pos
;
5941 my_set_window_pos (FRAME_W32_WINDOW (f
),
5943 modified_left
, modified_top
,
5945 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5949 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
5950 wanted positions of the WM window (not Emacs window).
5951 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
5952 window (FRAME_X_WINDOW).
5956 x_fullscreen_adjust (struct frame
*f
, int *width
, int *height
, int *top_pos
, int *left_pos
)
5958 int newwidth
= FRAME_COLS (f
);
5959 int newheight
= FRAME_LINES (f
);
5960 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
5962 *top_pos
= f
->top_pos
;
5963 *left_pos
= f
->left_pos
;
5965 if (f
->want_fullscreen
& FULLSCREEN_HEIGHT
)
5969 ph
= x_display_pixel_height (dpyinfo
);
5970 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
5971 ph
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, newheight
) - f
->y_pixels_diff
;
5972 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
5976 if (f
->want_fullscreen
& FULLSCREEN_WIDTH
)
5980 pw
= x_display_pixel_width (dpyinfo
);
5981 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
5982 pw
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, newwidth
) - f
->x_pixels_diff
;
5983 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
5988 *height
= newheight
;
5991 /* Check if we need to resize the frame due to a fullscreen request.
5992 If so needed, resize the frame. */
5994 x_check_fullscreen (struct frame
*f
)
5996 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
5998 int width
, height
, ign
;
6000 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6002 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
6004 /* We do not need to move the window, it shall be taken care of
6005 when setting WM manager hints. */
6006 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
6008 change_frame_size (f
, width
, height
, 0, 1, 0, 0);
6009 SET_FRAME_GARBAGED (f
);
6010 cancel_mouse_face (f
);
6012 /* Wait for the change of frame size to occur. */
6013 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
6019 w32fullscreen_hook (struct frame
*f
)
6021 if (FRAME_VISIBLE_P (f
))
6023 HWND hwnd
= FRAME_W32_WINDOW(f
);
6024 DWORD dwStyle
= GetWindowLong (hwnd
, GWL_STYLE
);
6026 enum fullscreen_type prev_fsmode
= FRAME_PREV_FSMODE (f
);
6029 f
->want_fullscreen
&= ~FULLSCREEN_WAIT
;
6031 if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_NONE
)
6032 GetWindowPlacement (hwnd
, &FRAME_NORMAL_PLACEMENT (f
));
6034 if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_BOTH
)
6036 SetWindowLong (hwnd
, GWL_STYLE
, dwStyle
| WS_OVERLAPPEDWINDOW
);
6037 SetWindowPlacement (hwnd
, &FRAME_NORMAL_PLACEMENT (f
));
6039 else if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_HEIGHT
6040 || FRAME_PREV_FSMODE (f
) == FULLSCREEN_WIDTH
)
6041 SetWindowPlacement (hwnd
, &FRAME_NORMAL_PLACEMENT (f
));
6043 FRAME_PREV_FSMODE (f
) = f
->want_fullscreen
;
6045 if (f
->want_fullscreen
== FULLSCREEN_NONE
)
6046 ShowWindow (hwnd
, SW_SHOWNORMAL
);
6047 else if (f
->want_fullscreen
== FULLSCREEN_MAXIMIZED
)
6049 if (prev_fsmode
== FULLSCREEN_BOTH
|| prev_fsmode
== FULLSCREEN_WIDTH
6050 || prev_fsmode
== FULLSCREEN_HEIGHT
)
6051 /* Make window normal since otherwise the subsequent
6052 maximization might fail in some cases. */
6053 ShowWindow (hwnd
, SW_SHOWNORMAL
);
6054 ShowWindow (hwnd
, SW_MAXIMIZE
);
6056 else if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
6058 w32_fullscreen_rect (hwnd
, f
->want_fullscreen
,
6059 FRAME_NORMAL_PLACEMENT (f
).rcNormalPosition
, &rect
);
6060 SetWindowLong (hwnd
, GWL_STYLE
, dwStyle
& ~WS_OVERLAPPEDWINDOW
);
6061 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
6062 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
6063 SWP_NOOWNERZORDER
| SWP_FRAMECHANGED
);
6067 ShowWindow (hwnd
, SW_SHOWNORMAL
);
6068 w32_fullscreen_rect (hwnd
, f
->want_fullscreen
,
6069 FRAME_NORMAL_PLACEMENT (f
).rcNormalPosition
, &rect
);
6070 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
6071 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 0);
6074 f
->want_fullscreen
= FULLSCREEN_NONE
;
6078 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
6081 /* Call this to change the size of frame F's x-window.
6082 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
6083 for this size change and subsequent size changes.
6084 Otherwise we leave the window gravity unchanged. */
6087 x_set_window_size (struct frame
*f
, int change_gravity
, int width
, int height
, bool pixelwise
)
6089 int pixelwidth
, pixelheight
;
6096 pixelwidth
= FRAME_TEXT_TO_PIXEL_WIDTH (f
, width
);
6097 pixelheight
= FRAME_TEXT_TO_PIXEL_HEIGHT (f
, height
);
6101 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, width
);
6102 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, height
);
6105 f
->win_gravity
= NorthWestGravity
;
6106 x_wm_set_size_hint (f
, (long) 0, 0);
6108 f
->want_fullscreen
= FULLSCREEN_NONE
;
6109 w32fullscreen_hook (f
);
6111 rect
.left
= rect
.top
= 0;
6112 rect
.right
= pixelwidth
;
6113 rect
.bottom
= pixelheight
;
6115 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
6116 FRAME_EXTERNAL_MENU_BAR (f
));
6118 my_set_window_pos (FRAME_W32_WINDOW (f
),
6121 rect
.right
- rect
.left
,
6122 rect
.bottom
- rect
.top
,
6123 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
6125 /* If w32_enable_frame_resize_hack is non-nil, immediately apply the
6126 new pixel sizes to the frame and its subwindows.
6128 Jason Rumney earlier refused to call change_frame_size right here
6129 with the following argument:
6131 The following mirrors what is done in xterm.c. It appears to be for
6132 informing lisp of the new size immediately, while the actual resize
6133 will happen asynchronously. But on Windows, the menu bar
6134 automatically wraps when the frame is too narrow to contain it, and
6135 that causes any calculations made here to come out wrong. The end
6136 is some nasty buggy behavior, including the potential loss of the
6139 Disabling this code is either not sufficient to fix the problems
6140 completely, or it causes fresh problems, but at least it removes
6141 the most problematic symptom of the minibuffer becoming unusable.
6143 However, as the discussion about how to handle frame size
6144 parameters on Windows (Bug#1348, Bug#16028) shows, that cure seems
6145 worse than the disease. In particular, menu bar wrapping looks
6146 like a non-issue - maybe so because Windows eventually gets back to
6147 us with the correct client rectangle anyway. But we have to avoid
6148 calling change_frame_size with a delta of less than one canoncial
6149 character size when frame_resize_pixelwise is nil, as explained in
6150 the comment above. */
6152 if (w32_enable_frame_resize_hack
)
6155 change_frame_size (f
, FRAME_PIXEL_TO_TEXT_WIDTH (f
, pixelwidth
),
6156 FRAME_PIXEL_TO_TEXT_HEIGHT (f
, pixelheight
),
6158 SET_FRAME_GARBAGED (f
);
6160 /* If cursor was outside the new size, mark it as off. */
6161 mark_window_cursors_off (XWINDOW (f
->root_window
));
6163 /* Clear out any recollection of where the mouse highlighting was,
6164 since it might be in a place that's outside the new frame size.
6165 Actually checking whether it is outside is a pain in the neck,
6166 so don't try--just let the highlighting be done afresh with new
6168 cancel_mouse_face (f
);
6173 do_pending_window_change (0);
6176 /* Mouse warping. */
6179 frame_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
6186 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
6187 pt
.x
= rect
.left
+ pix_x
;
6188 pt
.y
= rect
.top
+ pix_y
;
6189 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
6191 SetCursorPos (pt
.x
, pt
.y
);
6197 /* focus shifting, raising and lowering. */
6200 x_focus_frame (struct frame
*f
)
6203 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6206 /* Give input focus to frame. */
6209 /* Try not to change its Z-order if possible. */
6210 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
6211 my_set_focus (f
, FRAME_W32_WINDOW (f
));
6214 my_set_foreground_window (FRAME_W32_WINDOW (f
));
6218 /* Raise frame F. */
6220 x_raise_frame (struct frame
*f
)
6224 /* Strictly speaking, raise-frame should only change the frame's Z
6225 order, leaving input focus unchanged. This is reasonable behavior
6226 on X where the usual policy is point-to-focus. However, this
6227 behavior would be very odd on Windows where the usual policy is
6230 On X, if the mouse happens to be over the raised frame, it gets
6231 input focus anyway (so the window with focus will never be
6232 completely obscured) - if not, then just moving the mouse over it
6233 is sufficient to give it focus. On Windows, the user must actually
6234 click on the frame (preferably the title bar so as not to move
6235 point), which is more awkward. Also, no other Windows program
6236 raises a window to the top but leaves another window (possibly now
6237 completely obscured) with input focus.
6239 Because there is a system setting on Windows that allows the user
6240 to choose the point to focus policy, we make the strict semantics
6241 optional, but by default we grab focus when raising. */
6243 if (NILP (Vw32_grab_focus_on_raise
))
6245 /* The obvious call to my_set_window_pos doesn't work if Emacs is
6246 not already the foreground application: the frame is raised
6247 above all other frames belonging to us, but not above the
6248 current top window. To achieve that, we have to resort to this
6249 more cumbersome method. */
6251 HDWP handle
= BeginDeferWindowPos (2);
6254 handle
= DeferWindowPos (handle
,
6255 FRAME_W32_WINDOW (f
),
6258 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
6261 handle
= DeferWindowPos (handle
,
6262 GetForegroundWindow (),
6263 FRAME_W32_WINDOW (f
),
6265 SWP_NOSIZE
| SWP_NOMOVE
|
6268 EndDeferWindowPos (handle
);
6274 my_bring_window_to_top (FRAME_W32_WINDOW (f
));
6280 /* Lower frame F. */
6282 x_lower_frame (struct frame
*f
)
6285 my_set_window_pos (FRAME_W32_WINDOW (f
),
6288 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
6293 w32_frame_raise_lower (struct frame
*f
, int raise_flag
)
6295 if (! FRAME_W32_P (f
))
6304 /* Change of visibility. */
6306 /* This tries to wait until the frame is really visible.
6307 However, if the window manager asks the user where to position
6308 the frame, this will return before the user finishes doing that.
6309 The frame will not actually be visible at that time,
6310 but it will become visible later when the window manager
6311 finishes with it. */
6314 x_make_frame_visible (struct frame
*f
)
6318 x_set_bitmap_icon (f
);
6320 if (! FRAME_VISIBLE_P (f
))
6322 /* We test FRAME_GARBAGED_P here to make sure we don't
6323 call x_set_offset a second time
6324 if we get to x_make_frame_visible a second time
6325 before the window gets really visible. */
6326 if (! FRAME_ICONIFIED_P (f
)
6327 && ! f
->output_data
.w32
->asked_for_visible
)
6332 /* Adjust vertical window position in order to avoid being
6333 covered by a task bar placed at the bottom of the desktop. */
6334 SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0);
6335 GetWindowRect (FRAME_W32_WINDOW (f
), &window_rect
);
6336 if (window_rect
.bottom
> workarea_rect
.bottom
6337 && window_rect
.top
> workarea_rect
.top
)
6338 f
->top_pos
= max (window_rect
.top
6339 - window_rect
.bottom
+ workarea_rect
.bottom
,
6342 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
6345 f
->output_data
.w32
->asked_for_visible
= 1;
6347 /* According to a report in emacs-devel 2008-06-03, SW_SHOWNORMAL
6348 causes unexpected behavior when unminimizing frames that were
6349 previously maximized. But only SW_SHOWNORMAL works properly for
6350 frames that were truely hidden (using make-frame-invisible), so
6351 we need it to avoid Bug#5482. It seems that iconified is only
6352 set for minimized windows that are still visible, so use that to
6353 determine the appropriate flag to pass ShowWindow. */
6354 my_show_window (f
, FRAME_W32_WINDOW (f
),
6355 FRAME_ICONIFIED_P (f
) ? SW_RESTORE
: SW_SHOWNORMAL
);
6358 /* Synchronize to ensure Emacs knows the frame is visible
6359 before we do anything else. We do this loop with input not blocked
6360 so that incoming events are handled. */
6365 /* This must come after we set COUNT. */
6368 XSETFRAME (frame
, f
);
6370 /* Wait until the frame is visible. Process X events until a
6371 MapNotify event has been seen, or until we think we won't get a
6372 MapNotify at all.. */
6373 for (count
= input_signal_count
+ 10;
6374 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
6376 /* Force processing of queued events. */
6377 /* TODO: x_sync equivalent? */
6379 /* Machines that do polling rather than SIGIO have been observed
6380 to go into a busy-wait here. So we'll fake an alarm signal
6381 to let the handler know that there's something to be read.
6382 We used to raise a real alarm, but it seems that the handler
6383 isn't always enabled here. This is probably a bug. */
6384 if (input_polling_used ())
6386 /* It could be confusing if a real alarm arrives while processing
6387 the fake one. Turn it off and let the handler reset it. */
6388 int old_poll_suppress_count
= poll_suppress_count
;
6389 poll_suppress_count
= 1;
6390 poll_for_input_1 ();
6391 poll_suppress_count
= old_poll_suppress_count
;
6397 /* Change from mapped state to withdrawn state. */
6399 /* Make the frame visible (mapped and not iconified). */
6402 x_make_frame_invisible (struct frame
*f
)
6404 /* Don't keep the highlight on an invisible frame. */
6405 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6406 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6410 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
6412 /* We can't distinguish this from iconification
6413 just by the event that we get from the server.
6414 So we can't win using the usual strategy of letting
6415 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
6416 and synchronize with the server to make sure we agree. */
6417 SET_FRAME_VISIBLE (f
, 0);
6418 SET_FRAME_ICONIFIED (f
, 0);
6423 /* Change window state from mapped to iconified. */
6426 x_iconify_frame (struct frame
*f
)
6428 /* Don't keep the highlight on an invisible frame. */
6429 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6430 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6432 if (FRAME_ICONIFIED_P (f
))
6437 x_set_bitmap_icon (f
);
6439 /* Simulate the user minimizing the frame. */
6440 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
6442 SET_FRAME_VISIBLE (f
, 0);
6443 SET_FRAME_ICONIFIED (f
, 1);
6449 /* Free X resources of frame F. */
6452 x_free_frame_resources (struct frame
*f
)
6454 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
6455 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
6459 /* We must free faces before destroying windows because some
6460 font-driver (e.g. xft) access a window while finishing a
6462 free_frame_faces (f
);
6464 if (FRAME_W32_WINDOW (f
))
6465 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
6467 free_frame_menubar (f
);
6469 xfree (f
->output_data
.w32
);
6470 f
->output_data
.w32
= NULL
;
6472 if (f
== dpyinfo
->w32_focus_frame
)
6473 dpyinfo
->w32_focus_frame
= 0;
6474 if (f
== dpyinfo
->w32_focus_event_frame
)
6475 dpyinfo
->w32_focus_event_frame
= 0;
6476 if (f
== dpyinfo
->x_highlight_frame
)
6477 dpyinfo
->x_highlight_frame
= 0;
6478 if (f
== hlinfo
->mouse_face_mouse_frame
)
6479 reset_mouse_highlight (hlinfo
);
6485 /* Destroy the window of frame F. */
6487 x_destroy_window (struct frame
*f
)
6489 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
6491 x_free_frame_resources (f
);
6492 dpyinfo
->reference_count
--;
6496 /* Setting window manager hints. */
6498 /* Set the normal size hints for the window manager, for frame F.
6499 FLAGS is the flags word to use--or 0 meaning preserve the flags
6500 that the window now has.
6501 If USER_POSITION, set the USPosition
6502 flag (this is useful when FLAGS is 0). */
6504 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
6506 Window window
= FRAME_W32_WINDOW (f
);
6510 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
6511 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
6512 SetWindowLong (window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
6513 SetWindowLong (window
, WND_VSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_WIDTH (f
));
6514 SetWindowLong (window
, WND_HSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_HEIGHT (f
));
6519 /***********************************************************************
6521 ***********************************************************************/
6525 /* Check that FONT is valid on frame F. It is if it can be found in F's
6529 x_check_font (struct frame
*f
, struct font
*font
)
6531 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
6532 if (font
->driver
->check
)
6533 eassert (font
->driver
->check (f
, font
) == 0);
6536 #endif /* GLYPH_DEBUG */
6538 /* Show hourglass cursor on frame F. */
6541 w32_show_hourglass (struct frame
*f
)
6543 if (!menubar_in_use
&& !current_popup_menu
)
6545 struct w32_output
*w32
= FRAME_X_OUTPUT (f
);
6547 w32
->hourglass_p
= 1;
6548 SetCursor (w32
->hourglass_cursor
);
6552 /* Hide hourglass cursor on frame F. */
6555 w32_hide_hourglass (struct frame
*f
)
6557 struct w32_output
*w32
= FRAME_X_OUTPUT (f
);
6559 w32
->hourglass_p
= 0;
6560 SetCursor (w32
->current_cursor
);
6563 /* FIXME: old code did that, but I don't know why. Anyway,
6564 this is used for non-GUI frames (see cancel_hourglass). */
6567 w32_arrow_cursor (void)
6569 SetCursor (w32_load_cursor (IDC_ARROW
));
6572 /***********************************************************************
6574 ***********************************************************************/
6576 static int w32_initialized
= 0;
6579 w32_initialize_display_info (Lisp_Object display_name
)
6581 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6583 memset (dpyinfo
, 0, sizeof (*dpyinfo
));
6585 dpyinfo
->name_list_element
= Fcons (display_name
, Qnil
);
6586 dpyinfo
->w32_id_name
= xmalloc (SCHARS (Vinvocation_name
)
6587 + SCHARS (Vsystem_name
) + 2);
6588 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
6589 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
6591 /* Default Console mode values - overridden when running in GUI mode
6592 with values obtained from system metrics. */
6595 dpyinfo
->n_planes
= 1;
6596 dpyinfo
->n_cbits
= 4;
6597 dpyinfo
->n_fonts
= 0;
6598 dpyinfo
->smallest_font_height
= 1;
6599 dpyinfo
->smallest_char_width
= 1;
6600 dpyinfo
->vertical_scroll_bar_cursor
= w32_load_cursor (IDC_ARROW
);
6601 dpyinfo
->horizontal_scroll_bar_cursor
= w32_load_cursor (IDC_ARROW
);
6602 /* TODO: dpyinfo->gray */
6604 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
6607 /* Create an xrdb-style database of resources to supersede registry settings.
6608 The database is just a concatenation of C strings, finished by an additional
6609 \0. The strings are submitted to some basic normalization, so
6611 [ *]option[ *]:[ *]value...
6617 but any whitespace following value is not removed. */
6620 w32_make_rdb (char *xrm_option
)
6622 char *buffer
= xmalloc (strlen (xrm_option
) + 2);
6623 char *current
= buffer
;
6626 int before_value
= 0;
6640 if (in_option
&& (ch
== ':'))
6645 else if (before_value
)
6650 else if (!(in_option
|| before_value
))
6661 extern frame_parm_handler w32_frame_parm_handlers
[];
6663 static struct redisplay_interface w32_redisplay_interface
=
6665 w32_frame_parm_handlers
,
6669 x_clear_end_of_line
,
6671 x_after_update_window_line
,
6672 x_update_window_begin
,
6673 x_update_window_end
,
6674 0, /* flush_display */
6675 x_clear_window_mouse_face
,
6676 x_get_glyph_overhangs
,
6677 x_fix_overlapping_area
,
6678 w32_draw_fringe_bitmap
,
6679 w32_define_fringe_bitmap
,
6680 w32_destroy_fringe_bitmap
,
6681 w32_compute_glyph_string_overhangs
,
6682 x_draw_glyph_string
,
6683 w32_define_frame_cursor
,
6684 w32_clear_frame_area
,
6685 w32_draw_window_cursor
,
6686 w32_draw_vertical_window_border
,
6687 w32_draw_window_divider
,
6688 w32_shift_glyphs_for_insert
,
6693 static void x_delete_terminal (struct terminal
*term
);
6695 static struct terminal
*
6696 w32_create_terminal (struct w32_display_info
*dpyinfo
)
6698 struct terminal
*terminal
;
6700 terminal
= create_terminal (output_w32
, &w32_redisplay_interface
);
6702 terminal
->display_info
.w32
= dpyinfo
;
6703 dpyinfo
->terminal
= terminal
;
6705 /* MSVC does not type K&R functions with no arguments correctly, and
6706 so we must explicitly cast them. */
6707 terminal
->clear_frame_hook
= x_clear_frame
;
6708 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
6709 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
6710 terminal
->ring_bell_hook
= w32_ring_bell
;
6711 terminal
->update_begin_hook
= x_update_begin
;
6712 terminal
->update_end_hook
= x_update_end
;
6713 terminal
->read_socket_hook
= w32_read_socket
;
6714 terminal
->frame_up_to_date_hook
= w32_frame_up_to_date
;
6715 terminal
->mouse_position_hook
= w32_mouse_position
;
6716 terminal
->frame_rehighlight_hook
= w32_frame_rehighlight
;
6717 terminal
->frame_raise_lower_hook
= w32_frame_raise_lower
;
6718 terminal
->fullscreen_hook
= w32fullscreen_hook
;
6719 terminal
->menu_show_hook
= w32_menu_show
;
6720 terminal
->popup_dialog_hook
= w32_popup_dialog
;
6721 terminal
->set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
6722 terminal
->set_horizontal_scroll_bar_hook
= w32_set_horizontal_scroll_bar
;
6723 terminal
->condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
6724 terminal
->redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
6725 terminal
->judge_scroll_bars_hook
= w32_judge_scroll_bars
;
6726 terminal
->delete_frame_hook
= x_destroy_window
;
6727 terminal
->delete_terminal_hook
= x_delete_terminal
;
6728 /* Other hooks are NULL by default. */
6730 /* We don't yet support separate terminals on W32, so don't try to share
6731 keyboards between virtual terminals that are on the same physical
6732 terminal like X does. */
6733 terminal
->kboard
= allocate_kboard (Qw32
);
6734 /* Don't let the initial kboard remain current longer than necessary.
6735 That would cause problems if a file loaded on startup tries to
6736 prompt in the mini-buffer. */
6737 if (current_kboard
== initial_kboard
)
6738 current_kboard
= terminal
->kboard
;
6739 terminal
->kboard
->reference_count
++;
6745 x_delete_terminal (struct terminal
*terminal
)
6747 struct w32_display_info
*dpyinfo
= terminal
->display_info
.w32
;
6749 /* Protect against recursive calls. delete_frame in
6750 delete_terminal calls us back when it deletes our last frame. */
6751 if (!terminal
->name
)
6756 x_delete_display (dpyinfo
);
6760 struct w32_display_info
*
6761 w32_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
6763 struct w32_display_info
*dpyinfo
;
6764 struct terminal
*terminal
;
6769 if (!w32_initialized
)
6772 w32_initialized
= 1;
6775 w32_initialize_display_info (display_name
);
6777 dpyinfo
= &one_w32_display_info
;
6778 terminal
= w32_create_terminal (dpyinfo
);
6780 /* Set the name of the terminal. */
6781 terminal
->name
= xlispstrdup (display_name
);
6783 dpyinfo
->xrdb
= xrm_option
? w32_make_rdb (xrm_option
) : NULL
;
6785 /* Put this display on the chain. */
6786 dpyinfo
->next
= x_display_list
;
6787 x_display_list
= dpyinfo
;
6791 dpyinfo
->root_window
= GetDesktopWindow ();
6792 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
6793 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
6794 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
6795 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
6796 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
6797 ReleaseDC (NULL
, hdc
);
6799 /* initialize palette with white and black */
6802 w32_defined_color (0, "white", &color
, 1);
6803 w32_defined_color (0, "black", &color
, 1);
6807 /* Add the default keyboard. When !WINDOWSNT, we're using the
6808 standard Emacs console handling machinery and don't need an
6809 explicit FD here. */
6810 add_keyboard_wait_descriptor (0);
6812 /* /dev/windows wakes us up when we have a thread message pending. */
6813 add_keyboard_wait_descriptor (w32_message_fd
);
6816 /* Create Fringe Bitmaps and store them for later use.
6818 On W32, bitmaps are all unsigned short, as Windows requires
6819 bitmap data to be Word aligned. For some reason they are
6820 horizontally reflected compared to how they appear on X, so we
6821 need to bitswap and convert to unsigned shorts before creating
6823 w32_init_fringe (terminal
->rif
);
6830 /* Get rid of display DPYINFO, assuming all frames are already gone. */
6832 x_delete_display (struct w32_display_info
*dpyinfo
)
6834 /* FIXME: the only display info apparently can't be deleted. */
6835 /* free palette table */
6837 struct w32_palette_entry
* plist
;
6839 plist
= dpyinfo
->color_list
;
6842 struct w32_palette_entry
* pentry
= plist
;
6843 plist
= plist
->next
;
6846 dpyinfo
->color_list
= NULL
;
6847 if (dpyinfo
->palette
)
6848 DeleteObject (dpyinfo
->palette
);
6850 w32_reset_fringes ();
6854 /* Set up use of W32. */
6856 DWORD WINAPI
w32_msg_worker (void * arg
);
6859 w32_initialize (void)
6862 HRESULT (WINAPI
* set_user_model
) (const wchar_t * id
);
6866 w32_system_caret_hwnd
= NULL
;
6867 w32_system_caret_height
= 0;
6868 w32_system_caret_x
= 0;
6869 w32_system_caret_y
= 0;
6871 /* On Windows 7 and later, we need to set the user model ID
6872 to associate emacsclient launched files with Emacs frames
6874 shell
= GetModuleHandle ("shell32.dll");
6878 = (void *) GetProcAddress (shell
,
6879 "SetCurrentProcessExplicitAppUserModelID");
6881 /* If the function is defined, then we are running on Windows 7
6882 or newer, and the UI uses this to group related windows
6883 together. Since emacs, runemacs, emacsclient are related, we
6884 want them grouped even though the executables are different,
6885 so we need to set a consistent ID between them. */
6887 set_user_model (L
"GNU.Emacs");
6891 if ((w32_message_fd
= emacs_open ("/dev/windows", O_RDWR
, 0)) == -1)
6892 fatal ("opening /dev/windows: %s", strerror (errno
));
6895 /* Initialize w32_use_visible_system_caret based on whether a screen
6896 reader is in use. */
6897 if (!SystemParametersInfo (SPI_GETSCREENREADER
, 0,
6898 &w32_use_visible_system_caret
, 0))
6899 w32_use_visible_system_caret
= 0;
6901 any_help_event_p
= 0;
6903 /* Initialize input mode: interrupt_input off, no flow control, allow
6904 8 bit character input, standard quit char. */
6905 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
6908 LCID input_locale_id
= LOWORD (GetKeyboardLayout (0));
6909 w32_keyboard_codepage
= codepage_for_locale (input_locale_id
);
6912 /* Create the window thread - it will terminate itself when the app
6916 dwMainThreadId
= GetCurrentThreadId ();
6917 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
6918 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
6920 /* Wait for thread to start */
6924 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
6926 hWindowsThread
= CreateThread (NULL
, 0,
6928 0, 0, &dwWindowsThreadId
);
6930 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6933 /* It is desirable that mainThread should have the same notion of
6934 focus window and active window as windowsThread. Unfortunately, the
6935 following call to AttachThreadInput, which should do precisely what
6936 we need, causes major problems when Emacs is linked as a console
6937 program. Unfortunately, we have good reasons for doing that, so
6938 instead we need to send messages to windowsThread to make some API
6939 calls for us (ones that affect, or depend on, the active/focus
6941 #ifdef ATTACH_THREADS
6942 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
6945 /* Dynamically link to optional system components. */
6947 HMODULE user_lib
= GetModuleHandle ("user32.dll");
6949 #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn)
6951 LOAD_PROC (user_lib
, SetLayeredWindowAttributes
);
6955 /* Ensure scrollbar handles are at least 5 pixels. */
6956 vertical_scroll_bar_min_handle
= 5;
6957 horizontal_scroll_bar_min_handle
= 5;
6959 /* For either kind of scroll bar, take account of the arrows; these
6960 effectively form the border of the main scroll bar range. */
6961 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
6962 = GetSystemMetrics (SM_CYVSCROLL
);
6963 horizontal_scroll_bar_left_border
= horizontal_scroll_bar_right_border
6964 = GetSystemMetrics (SM_CYHSCROLL
);
6969 syms_of_w32term (void)
6971 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
6973 DEFSYM (Qadded
, "added");
6974 DEFSYM (Qremoved
, "removed");
6975 DEFSYM (Qmodified
, "modified");
6976 DEFSYM (Qrenamed_from
, "renamed-from");
6977 DEFSYM (Qrenamed_to
, "renamed-to");
6979 DEFVAR_INT ("w32-num-mouse-buttons",
6980 w32_num_mouse_buttons
,
6981 doc
: /* Number of physical mouse buttons. */);
6982 w32_num_mouse_buttons
= 2;
6984 DEFVAR_LISP ("w32-swap-mouse-buttons",
6985 Vw32_swap_mouse_buttons
,
6986 doc
: /* Swap the mapping of middle and right mouse buttons.
6987 When nil, middle button is mouse-2 and right button is mouse-3. */);
6988 Vw32_swap_mouse_buttons
= Qnil
;
6990 DEFVAR_LISP ("w32-grab-focus-on-raise",
6991 Vw32_grab_focus_on_raise
,
6992 doc
: /* Raised frame grabs input focus.
6993 When t, `raise-frame' grabs input focus as well. This fits well
6994 with the normal Windows click-to-focus policy, but might not be
6995 desirable when using a point-to-focus policy. */);
6996 Vw32_grab_focus_on_raise
= Qt
;
6998 DEFVAR_LISP ("w32-capslock-is-shiftlock",
6999 Vw32_capslock_is_shiftlock
,
7000 doc
: /* Apply CapsLock state to non character input keys.
7001 When nil, CapsLock only affects normal character input keys. */);
7002 Vw32_capslock_is_shiftlock
= Qnil
;
7004 DEFVAR_LISP ("w32-recognize-altgr",
7005 Vw32_recognize_altgr
,
7006 doc
: /* Recognize right-alt and left-ctrl as AltGr.
7007 When nil, the right-alt and left-ctrl key combination is
7008 interpreted normally. */);
7009 Vw32_recognize_altgr
= Qt
;
7011 DEFVAR_BOOL ("w32-use-visible-system-caret",
7012 w32_use_visible_system_caret
,
7013 doc
: /* Flag to make the system caret visible.
7014 When this is non-nil, Emacs will indicate the position of point by
7015 using the system caret instead of drawing its own cursor. Some screen
7016 reader software does not track the system cursor properly when it is
7017 invisible, and gets confused by Emacs drawing its own cursor, so this
7018 variable is initialized to t when Emacs detects that screen reader
7019 software is running as it starts up.
7021 When this variable is set, other variables affecting the appearance of
7022 the cursor have no effect. */);
7024 w32_use_visible_system_caret
= 0;
7026 /* We don't yet support this, but defining this here avoids whining
7027 from cus-start.el and other places, like "M-x set-variable". */
7028 DEFVAR_BOOL ("x-use-underline-position-properties",
7029 x_use_underline_position_properties
,
7030 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
7031 A value of nil means ignore them. If you encounter fonts with bogus
7032 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7033 to 4.1, set this to nil. You can also use `underline-minimum-offset'
7034 to override the font's UNDERLINE_POSITION for small font display
7036 x_use_underline_position_properties
= 0;
7038 DEFVAR_BOOL ("x-underline-at-descent-line",
7039 x_underline_at_descent_line
,
7040 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
7041 A value of nil means to draw the underline according to the value of the
7042 variable `x-use-underline-position-properties', which is usually at the
7043 baseline level. The default value is nil. */);
7044 x_underline_at_descent_line
= 0;
7046 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
7047 doc
: /* Which toolkit scroll bars Emacs uses, if any.
7048 A value of nil means Emacs doesn't use toolkit scroll bars.
7049 With the X Window system, the value is a symbol describing the
7050 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
7051 With MS Windows or Nextstep, the value is t. */);
7052 Vx_toolkit_scroll_bars
= Qt
;
7054 DEFVAR_BOOL ("w32-unicode-filenames",
7055 w32_unicode_filenames
,
7056 doc
: /* Non-nil means use Unicode APIs when passing file names to the OS.
7057 A value of nil means file names passed to the OS APIs and returned
7058 from those APIs are encoded/decoded using the ANSI codepage
7059 specified by `file-name-coding-system'.
7061 This variable is set to non-nil by default when Emacs runs on Windows
7062 systems of the NT family, including W2K, XP, Vista, Windows 7 and
7063 Windows 8. It is set to nil on Windows 9X. */);
7064 w32_unicode_filenames
= 0;
7066 DEFVAR_BOOL ("w32-enable-frame-resize-hack",
7067 w32_enable_frame_resize_hack
,
7068 doc
: /* Non-nil means enable hack for frame resizing on Windows.
7069 A value of nil means to resize frames by sending a corresponding request
7070 to the Windows API and changing the pixel sizes of the frame and its
7071 windows after the latter calls back. If this is non-nil, Emacs changes
7072 the pixel sizes of the frame and its windows at the time it sends the
7073 resize request to the API. */);
7074 w32_enable_frame_resize_hack
= 1;
7076 /* Tell Emacs about this window system. */
7077 Fprovide (Qw32
, Qnil
);