1 /* Implementation of GUI terminal on the Microsoft Windows API.
3 Copyright (C) 1989, 1993-2013 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"
59 #include <io.h> /* for get_osfhandle */
69 static int max_fringe_bmp
= 0;
70 static HBITMAP
*fringe_bmp
= 0;
72 /* Temporary variables for w32_read_socket. */
74 static int last_mousemove_x
= 0;
75 static int last_mousemove_y
= 0;
77 /* Define GET_WHEEL_DELTA_WPARAM macro if system headers don't. */
78 #ifndef GET_WHEEL_DELTA_WPARAM
79 #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam))
82 /* Non-zero means that a HELP_EVENT has been generated since Emacs
85 static int any_help_event_p
;
87 extern unsigned int msh_mousewheel
;
89 extern void free_frame_menubar (struct frame
*);
91 extern int w32_codepage_for_font (char *fontname
);
92 extern Cursor
w32_load_cursor (LPCTSTR name
);
94 #define x_any_window_to_frame x_window_to_frame
95 #define x_top_window_to_frame x_window_to_frame
98 /* This is display since w32 does not support multiple ones. */
99 struct w32_display_info one_w32_display_info
;
100 struct w32_display_info
*x_display_list
;
102 #if _WIN32_WINNT < 0x0500 && !defined(_W64)
103 /* Pre Windows 2000, this was not available, but define it here so
104 that Emacs compiled on such a platform will run on newer versions.
105 MinGW64 (_W64) defines these unconditionally, so avoid redefining. */
107 typedef struct tagWCRANGE
113 typedef struct tagGLYPHSET
117 DWORD cGlyphsSupported
;
122 #endif /* compiling for pre-Win2k */
124 /* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */
125 BOOL (WINAPI
*pfnSetLayeredWindowAttributes
) (HWND
, COLORREF
, BYTE
, DWORD
);
128 #define LWA_ALPHA 0x02
130 /* WS_EX_LAYERED is defined unconditionally by MingW, but only for W2K and
131 later targets by MSVC headers. */
132 #ifndef WS_EX_LAYERED
133 #define WS_EX_LAYERED 0x80000
136 /* SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN are not defined on 95 and
138 #ifndef SM_CXVIRTUALSCREEN
139 #define SM_CXVIRTUALSCREEN 78
141 #ifndef SM_CYVIRTUALSCREEN
142 #define SM_CYVIRTUALSCREEN 79
145 /* The handle of the frame that currently owns the system caret. */
146 HWND w32_system_caret_hwnd
;
147 int w32_system_caret_height
;
148 int w32_system_caret_x
;
149 int w32_system_caret_y
;
150 struct window
*w32_system_caret_window
;
151 int w32_system_caret_hdr_height
;
152 int w32_system_caret_mode_height
;
153 DWORD dwWindowsThreadId
= 0;
154 HANDLE hWindowsThread
= NULL
;
155 DWORD dwMainThreadId
= 0;
156 HANDLE hMainThread
= NULL
;
158 int vertical_scroll_bar_min_handle
;
159 int vertical_scroll_bar_top_border
;
160 int vertical_scroll_bar_bottom_border
;
162 int last_scroll_bar_drag_pos
;
164 /* Keyboard code page - may be changed by language-change events. */
165 int w32_keyboard_codepage
;
167 /* Incremented by w32_read_socket whenever it really tries to read
169 static int volatile input_signal_count
;
172 int w32_message_fd
= -1;
175 static void w32_handle_tool_bar_click (struct frame
*,
176 struct input_event
*);
177 static void w32_define_cursor (Window
, Cursor
);
179 void x_lower_frame (struct frame
*);
180 void x_scroll_bar_clear (struct frame
*);
181 void x_wm_set_size_hint (struct frame
*, long, bool);
182 void x_raise_frame (struct frame
*);
183 void x_set_window_size (struct frame
*, int, int, int);
184 void x_wm_set_window_state (struct frame
*, int);
185 void x_wm_set_icon_pixmap (struct frame
*, int);
186 static void w32_initialize (void);
187 static void x_update_end (struct frame
*);
188 static void w32_frame_up_to_date (struct frame
*);
189 static void x_clear_frame (struct frame
*);
190 static void frame_highlight (struct frame
*);
191 static void frame_unhighlight (struct frame
*);
192 static void x_new_focus_frame (struct w32_display_info
*,
194 static void x_focus_changed (int, int, struct w32_display_info
*,
195 struct frame
*, struct input_event
*);
196 static void w32_detect_focus_change (struct w32_display_info
*,
197 W32Msg
*, struct input_event
*);
198 static void w32_frame_rehighlight (struct frame
*);
199 static void x_frame_rehighlight (struct w32_display_info
*);
200 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
201 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
202 enum text_cursor_kinds
);
203 static void w32_clip_to_row (struct window
*, struct glyph_row
*,
204 enum glyph_row_area
, HDC
);
205 static BOOL
my_show_window (struct frame
*, HWND
, int);
206 static void my_set_window_pos (HWND
, HWND
, int, int, int, int, UINT
);
208 static void my_set_focus (struct frame
*, HWND
);
210 static void my_set_foreground_window (HWND
);
211 static void my_destroy_window (struct frame
*, HWND
);
212 static void w32fullscreen_hook (struct frame
*);
215 static void x_check_font (struct frame
*, struct font
*);
218 static Lisp_Object Qvendor_specific_keysyms
;
219 static Lisp_Object Qadded
, Qremoved
, Qmodified
;
220 static Lisp_Object Qrenamed_from
, Qrenamed_to
;
223 /***********************************************************************
225 ***********************************************************************/
229 /* This is a function useful for recording debugging information about
230 the sequence of occurrences in this file. */
238 struct record event_record
[100];
240 int event_record_index
;
242 record_event (char *locus
, int type
)
244 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
245 event_record_index
= 0;
247 event_record
[event_record_index
].locus
= locus
;
248 event_record
[event_record_index
].type
= type
;
249 event_record_index
++;
256 XChangeGC (void *ignore
, XGCValues
*gc
, unsigned long mask
,
259 if (mask
& GCForeground
)
260 gc
->foreground
= xgcv
->foreground
;
261 if (mask
& GCBackground
)
262 gc
->background
= xgcv
->background
;
264 gc
->font
= xgcv
->font
;
268 XCreateGC (void *ignore
, Window window
, unsigned long mask
, XGCValues
*xgcv
)
270 XGCValues
*gc
= xzalloc (sizeof (XGCValues
));
272 XChangeGC (ignore
, gc
, mask
, xgcv
);
278 XGetGCValues (void *ignore
, XGCValues
*gc
,
279 unsigned long mask
, XGCValues
*xgcv
)
281 XChangeGC (ignore
, xgcv
, mask
, gc
);
285 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
289 HRGN clip_region
= CreateRectRgnIndirect (rect
);
290 SelectClipRgn (hdc
, clip_region
);
291 DeleteObject (clip_region
);
294 SelectClipRgn (hdc
, NULL
);
297 /* Restore clipping rectangle in S */
299 w32_restore_glyph_string_clip (struct glyph_string
*s
)
302 int n
= s
->num_clips
;
305 w32_set_clip_rectangle (s
->hdc
, r
);
308 HRGN clip1
= CreateRectRgnIndirect (r
);
309 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
310 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
311 SelectClipRgn (s
->hdc
, clip1
);
312 DeleteObject (clip1
);
313 DeleteObject (clip2
);
318 Draw a wavy line under S. The wave fills wave_height pixels from y0.
324 wave_height = 3 | * * * *
329 w32_draw_underwave (struct glyph_string
*s
, COLORREF color
)
331 int wave_height
= 3, wave_length
= 2;
332 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
333 XRectangle wave_clip
, string_clip
, final_clip
;
334 RECT w32_final_clip
, w32_string_clip
;
338 dy
= wave_height
- 1;
340 y0
= s
->ybase
- wave_height
+ 3;
344 /* Find and set clipping rectangle */
348 wave_clip
.width
= width
;
349 wave_clip
.height
= wave_height
;
351 get_glyph_string_clip_rect (s
, &w32_string_clip
);
352 CONVERT_TO_XRECT (string_clip
, w32_string_clip
);
354 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
357 hp
= CreatePen (PS_SOLID
, 0, color
);
358 oldhp
= SelectObject (s
->hdc
, hp
);
359 CONVERT_FROM_XRECT (final_clip
, w32_final_clip
);
360 w32_set_clip_rectangle (s
->hdc
, &w32_final_clip
);
374 MoveToEx (s
->hdc
, x1
, y1
, NULL
);
378 LineTo (s
->hdc
, x2
, y2
);
380 x2
+= dx
, y2
= y0
+ odd
*dy
;
384 /* Restore previous pen and clipping rectangle(s) */
385 w32_restore_glyph_string_clip (s
);
386 SelectObject (s
->hdc
, oldhp
);
390 /* Draw a hollow rectangle at the specified position. */
392 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
393 int width
, int height
)
398 hb
= CreateSolidBrush (gc
->background
);
399 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
400 oldhb
= SelectObject (hdc
, hb
);
401 oldhp
= SelectObject (hdc
, hp
);
403 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
405 SelectObject (hdc
, oldhb
);
406 SelectObject (hdc
, oldhp
);
411 /* Draw a filled rectangle at the specified position. */
413 w32_fill_rect (struct frame
*f
, HDC hdc
, COLORREF pix
, RECT
*lprect
)
417 hb
= CreateSolidBrush (pix
);
418 FillRect (hdc
, lprect
, hb
);
423 w32_clear_window (struct frame
*f
)
426 HDC hdc
= get_frame_dc (f
);
428 /* Under certain conditions, this can be called at startup with
429 a console frame pointer before the GUI frame is created. An HDC
430 of 0 indicates this. */
433 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
434 w32_clear_rect (f
, hdc
, &rect
);
437 release_frame_dc (f
, hdc
);
440 #define OPAQUE_FRAME 255
443 x_set_frame_alpha (struct frame
*f
)
445 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
447 double alpha_min
= 1.0;
450 HWND window
= FRAME_W32_WINDOW (f
);
452 /* Older versions of Windows do not support transparency. */
453 if (!pfnSetLayeredWindowAttributes
)
456 if (dpyinfo
->x_highlight_frame
== f
)
461 if (FLOATP (Vframe_alpha_lower_limit
))
462 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
463 else if (INTEGERP (Vframe_alpha_lower_limit
))
464 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
468 else if (alpha
> 1.0)
470 else if (alpha
< alpha_min
&& alpha_min
<= 1.0)
473 opac
= alpha
* OPAQUE_FRAME
;
475 ex_style
= GetWindowLong (window
, GWL_EXSTYLE
);
477 if (opac
== OPAQUE_FRAME
)
478 ex_style
&= ~WS_EX_LAYERED
;
480 ex_style
|= WS_EX_LAYERED
;
482 SetWindowLong (window
, GWL_EXSTYLE
, ex_style
);
484 if (opac
!= OPAQUE_FRAME
)
485 pfnSetLayeredWindowAttributes (window
, 0, opac
, LWA_ALPHA
);
489 x_display_pixel_height (struct w32_display_info
*dpyinfo
)
491 int pixels
= GetSystemMetrics (SM_CYVIRTUALSCREEN
);
494 /* Fallback for Windows 95 or NT 4.0. */
495 pixels
= GetSystemMetrics (SM_CYSCREEN
);
501 x_display_pixel_width (struct w32_display_info
*dpyinfo
)
503 int pixels
= GetSystemMetrics (SM_CXVIRTUALSCREEN
);
506 /* Fallback for Windows 95 or NT 4.0. */
507 pixels
= GetSystemMetrics (SM_CXSCREEN
);
513 /***********************************************************************
514 Starting and ending an update
515 ***********************************************************************/
517 /* Start an update of frame F. This function is installed as a hook
518 for update_begin, i.e. it is called when update_begin is called.
519 This function is called prior to calls to x_update_window_begin for
520 each window being updated. */
523 x_update_begin (struct frame
*f
)
525 struct w32_display_info
*display_info
= FRAME_DISPLAY_INFO (f
);
527 if (! FRAME_W32_P (f
))
530 /* Regenerate display palette before drawing if list of requested
531 colors has changed. */
532 if (display_info
->regen_palette
)
534 w32_regenerate_palette (f
);
535 display_info
->regen_palette
= FALSE
;
540 /* Start update of window W. */
543 x_update_window_begin (struct window
*w
)
545 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
546 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
548 /* Hide the system caret during an update. */
549 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
551 SendMessage (w32_system_caret_hwnd
, WM_EMACS_HIDE_CARET
, 0, 0);
554 w
->output_cursor
= w
->cursor
;
558 if (f
== hlinfo
->mouse_face_mouse_frame
)
560 /* Don't do highlighting for mouse motion during the update. */
561 hlinfo
->mouse_face_defer
= 1;
563 /* If F needs to be redrawn, simply forget about any prior mouse
565 if (FRAME_GARBAGED_P (f
))
566 hlinfo
->mouse_face_window
= Qnil
;
568 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
569 their mouse_face_p flag set, which means that they are always
570 unequal to rows in a desired matrix which never have that
571 flag set. So, rows containing mouse-face glyphs are never
572 scrolled, and we don't have to switch the mouse highlight off
573 here to prevent it from being scrolled. */
575 /* Can we tell that this update does not affect the window
576 where the mouse highlight is? If so, no need to turn off.
577 Likewise, don't do anything if the frame is garbaged;
578 in that case, the frame's current matrix that we would use
579 is all wrong, and we will redisplay that line anyway. */
580 if (!NILP (hlinfo
->mouse_face_window
)
581 && w
== XWINDOW (hlinfo
->mouse_face_window
))
585 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
586 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
589 if (i
< w
->desired_matrix
->nrows
)
590 clear_mouse_face (hlinfo
);
598 /* Draw a vertical window border from (x,y0) to (x,y1) */
601 w32_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
603 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
613 hdc
= get_frame_dc (f
);
614 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
616 w32_fill_rect (f
, hdc
, face
->foreground
, &r
);
618 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
620 release_frame_dc (f
, hdc
);
624 /* End update of window W.
626 Draw vertical borders between horizontally adjacent windows, and
627 display W's cursor if CURSOR_ON_P is non-zero.
629 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
630 glyphs in mouse-face were overwritten. In that case we have to
631 make sure that the mouse-highlight is properly redrawn.
633 W may be a menu bar pseudo-window in case we don't have X toolkit
634 support. Such windows don't have a cursor, so don't display it
638 x_update_window_end (struct window
*w
, bool cursor_on_p
,
639 bool mouse_face_overwritten_p
)
641 if (!w
->pseudo_window_p
)
646 display_and_set_cursor (w
, 1,
647 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
648 w
->output_cursor
.x
, w
->output_cursor
.y
);
650 if (draw_window_fringes (w
, 1))
651 x_draw_vertical_border (w
);
656 /* If a row with mouse-face was overwritten, arrange for
657 XTframe_up_to_date to redisplay the mouse highlight. */
658 if (mouse_face_overwritten_p
)
659 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w
->frame
)));
661 /* Unhide the caret. This won't actually show the cursor, unless it
662 was visible before the corresponding call to HideCaret in
663 x_update_window_begin. */
664 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
666 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
671 /* End update of frame F. This function is installed as a hook in
675 x_update_end (struct frame
*f
)
677 if (! FRAME_W32_P (f
))
680 /* Mouse highlight may be displayed again. */
681 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
685 /* This function is called from various places in xdisp.c
686 whenever a complete update has been performed. */
689 w32_frame_up_to_date (struct frame
*f
)
692 FRAME_MOUSE_UPDATE (f
);
696 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
697 arrow bitmaps, or clear the fringes if no bitmaps are required
698 before DESIRED_ROW is made current. This function is called from
699 update_window_line only if it is known that there are differences
700 between bitmaps to be drawn between current row and DESIRED_ROW. */
703 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
710 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
711 desired_row
->redraw_fringe_bitmaps_p
= 1;
713 /* When a window has disappeared, make sure that no rest of
714 full-width rows stays visible in the internal border. Could
715 check here if updated window is the leftmost/rightmost window,
716 but I guess it's not worth doing since vertically split windows
717 are almost never used, internal border is rarely set, and the
718 overhead is very small. */
719 if (windows_or_buffers_changed
720 && desired_row
->full_width_p
721 && (f
= XFRAME (w
->frame
),
722 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
724 && (height
= desired_row
->visible_height
,
727 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
731 HDC hdc
= get_frame_dc (f
);
732 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
733 w32_clear_area (f
, hdc
, FRAME_PIXEL_WIDTH (f
) - width
,
735 release_frame_dc (f
, hdc
);
742 /* Draw the bitmap WHICH in one of the left or right fringes of
743 window W. ROW is the glyph row for which to display the bitmap; it
744 determines the vertical position at which the bitmap has to be
748 w32_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
,
749 struct draw_fringe_bitmap_params
*p
)
751 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
753 struct face
*face
= p
->face
;
755 hdc
= get_frame_dc (f
);
759 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
761 /* If the fringe is adjacent to the left (right) scroll bar of a
762 leftmost (rightmost, respectively) window, then extend its
763 background to the gap between the fringe and the bar. */
764 if ((WINDOW_LEFTMOST_P (w
)
765 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
766 || (WINDOW_RIGHTMOST_P (w
)
767 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
769 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
773 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
774 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
775 * FRAME_COLUMN_WIDTH (f
));
779 /* Bitmap fills the fringe. */
780 if (bar_area_x
+ bar_area_width
== p
->x
)
781 bx
= bar_area_x
+ sb_width
;
782 else if (p
->x
+ p
->wd
== bar_area_x
)
786 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
788 nx
= bar_area_width
- sb_width
;
789 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
791 ny
= row
->visible_height
;
796 if (bar_area_x
+ bar_area_width
== bx
)
798 bx
= bar_area_x
+ sb_width
;
799 nx
+= bar_area_width
- sb_width
;
801 else if (bx
+ nx
== bar_area_x
)
802 nx
+= bar_area_width
- sb_width
;
807 if (bx
>= 0 && nx
> 0)
808 w32_fill_area (f
, hdc
, face
->background
, bx
, by
, nx
, ny
);
811 /* Must clip because of partially visible lines. */
812 w32_clip_to_row (w
, row
, ANY_AREA
, hdc
);
814 if (p
->which
&& p
->which
< max_fringe_bmp
)
816 HBITMAP pixmap
= fringe_bmp
[p
->which
];
820 compat_hdc
= CreateCompatibleDC (hdc
);
824 horig_obj
= SelectObject (compat_hdc
, pixmap
);
826 /* Paint overlays transparently. */
829 HBRUSH h_brush
, h_orig_brush
;
831 SetTextColor (hdc
, BLACK_PIX_DEFAULT (f
));
832 SetBkColor (hdc
, WHITE_PIX_DEFAULT (f
));
833 h_brush
= CreateSolidBrush (face
->foreground
);
834 h_orig_brush
= SelectObject (hdc
, h_brush
);
836 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
837 compat_hdc
, 0, p
->dh
,
839 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
840 compat_hdc
, 0, p
->dh
,
842 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
843 compat_hdc
, 0, p
->dh
,
846 SelectObject (hdc
, h_orig_brush
);
847 DeleteObject (h_brush
);
851 SetTextColor (hdc
, face
->background
);
852 SetBkColor (hdc
, (p
->cursor_p
853 ? f
->output_data
.w32
->cursor_pixel
854 : face
->foreground
));
856 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
857 compat_hdc
, 0, p
->dh
,
861 SelectObject (compat_hdc
, horig_obj
);
862 DeleteDC (compat_hdc
);
866 w32_set_clip_rectangle (hdc
, NULL
);
868 release_frame_dc (f
, hdc
);
872 w32_define_fringe_bitmap (int which
, unsigned short *bits
, int h
, int wd
)
874 if (which
>= max_fringe_bmp
)
876 int i
= max_fringe_bmp
;
877 max_fringe_bmp
= which
+ 20;
878 fringe_bmp
= (HBITMAP
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (HBITMAP
));
879 while (i
< max_fringe_bmp
)
883 fringe_bmp
[which
] = CreateBitmap (wd
, h
, 1, 1, bits
);
887 w32_destroy_fringe_bitmap (int which
)
889 if (which
>= max_fringe_bmp
)
892 if (fringe_bmp
[which
])
893 DeleteObject (fringe_bmp
[which
]);
894 fringe_bmp
[which
] = 0;
897 /***********************************************************************
899 ***********************************************************************/
901 /* Function prototypes of this page. */
903 static void x_set_glyph_string_clipping (struct glyph_string
*);
904 static void x_set_glyph_string_gc (struct glyph_string
*);
905 static void x_draw_glyph_string_background (struct glyph_string
*,
907 static void x_draw_glyph_string_foreground (struct glyph_string
*);
908 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
909 static void x_draw_glyph_string_box (struct glyph_string
*);
910 static void x_draw_glyph_string (struct glyph_string
*);
911 static void x_set_cursor_gc (struct glyph_string
*);
912 static void x_set_mode_line_face_gc (struct glyph_string
*);
913 static void x_set_mouse_face_gc (struct glyph_string
*);
914 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
915 static void w32_setup_relief_color (struct frame
*, struct relief
*,
916 double, int, COLORREF
);
917 static void x_setup_relief_colors (struct glyph_string
*);
918 static void x_draw_image_glyph_string (struct glyph_string
*);
919 static void x_draw_image_relief (struct glyph_string
*);
920 static void x_draw_image_foreground (struct glyph_string
*);
921 static void w32_draw_image_foreground_1 (struct glyph_string
*, HBITMAP
);
922 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
924 static void w32_draw_relief_rect (struct frame
*, int, int, int, int,
925 int, int, int, int, int, int,
927 static void w32_draw_box_rect (struct glyph_string
*, int, int, int, int,
928 int, int, int, RECT
*);
931 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
935 x_set_cursor_gc (struct glyph_string
*s
)
937 if (s
->font
== FRAME_FONT (s
->f
)
938 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
939 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
941 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
944 /* Cursor on non-default face: must merge. */
948 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
949 xgcv
.foreground
= s
->face
->background
;
951 /* If the glyph would be invisible, try a different foreground. */
952 if (xgcv
.foreground
== xgcv
.background
)
953 xgcv
.foreground
= s
->face
->foreground
;
954 if (xgcv
.foreground
== xgcv
.background
)
955 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
956 if (xgcv
.foreground
== xgcv
.background
)
957 xgcv
.foreground
= s
->face
->foreground
;
959 /* Make sure the cursor is distinct from text in this face. */
960 if (xgcv
.background
== s
->face
->background
961 && xgcv
.foreground
== s
->face
->foreground
)
963 xgcv
.background
= s
->face
->foreground
;
964 xgcv
.foreground
= s
->face
->background
;
967 IF_DEBUG (x_check_font (s
->f
, s
->font
));
969 mask
= GCForeground
| GCBackground
| GCFont
;
971 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
972 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
975 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
976 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
978 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
983 /* Set up S->gc of glyph string S for drawing text in mouse face. */
986 x_set_mouse_face_gc (struct glyph_string
*s
)
991 /* What face has to be used last for the mouse face? */
992 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
993 face
= FACE_FROM_ID (s
->f
, face_id
);
995 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
997 if (s
->first_glyph
->type
== CHAR_GLYPH
)
998 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1000 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1001 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1002 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1004 /* If font in this face is same as S->font, use it. */
1005 if (s
->font
== s
->face
->font
)
1006 s
->gc
= s
->face
->gc
;
1009 /* Otherwise construct scratch_cursor_gc with values from FACE
1014 xgcv
.background
= s
->face
->background
;
1015 xgcv
.foreground
= s
->face
->foreground
;
1016 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1017 xgcv
.font
= s
->font
;
1018 mask
= GCForeground
| GCBackground
| GCFont
;
1020 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1021 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1024 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1025 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
1027 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1030 eassert (s
->gc
!= 0);
1034 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1035 Faces to use in the mode line have already been computed when the
1036 matrix was built, so there isn't much to do, here. */
1039 x_set_mode_line_face_gc (struct glyph_string
*s
)
1041 s
->gc
= s
->face
->gc
;
1045 /* Set S->gc of glyph string S for drawing that glyph string. Set
1046 S->stippled_p to a non-zero value if the face of S has a stipple
1050 x_set_glyph_string_gc (struct glyph_string
*s
)
1052 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1054 if (s
->hl
== DRAW_NORMAL_TEXT
)
1056 s
->gc
= s
->face
->gc
;
1057 s
->stippled_p
= s
->face
->stipple
!= 0;
1059 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1061 x_set_mode_line_face_gc (s
);
1062 s
->stippled_p
= s
->face
->stipple
!= 0;
1064 else if (s
->hl
== DRAW_CURSOR
)
1066 x_set_cursor_gc (s
);
1069 else if (s
->hl
== DRAW_MOUSE_FACE
)
1071 x_set_mouse_face_gc (s
);
1072 s
->stippled_p
= s
->face
->stipple
!= 0;
1074 else if (s
->hl
== DRAW_IMAGE_RAISED
1075 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1077 s
->gc
= s
->face
->gc
;
1078 s
->stippled_p
= s
->face
->stipple
!= 0;
1082 s
->gc
= s
->face
->gc
;
1083 s
->stippled_p
= s
->face
->stipple
!= 0;
1086 /* GC must have been set. */
1087 eassert (s
->gc
!= 0);
1091 /* Set clipping for output of glyph string S. S may be part of a mode
1092 line or menu if we don't have X toolkit support. */
1095 x_set_glyph_string_clipping (struct glyph_string
*s
)
1098 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1101 w32_set_clip_rectangle (s
->hdc
, r
);
1104 HRGN clip1
= CreateRectRgnIndirect (r
);
1105 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
1106 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
1107 SelectClipRgn (s
->hdc
, clip1
);
1108 DeleteObject (clip1
);
1109 DeleteObject (clip2
);
1114 /* Set SRC's clipping for output of glyph string DST. This is called
1115 when we are drawing DST's left_overhang or right_overhang only in
1119 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
,
1120 struct glyph_string
*dst
)
1125 r
.right
= r
.left
+ src
->width
;
1127 r
.bottom
= r
.top
+ src
->height
;
1130 w32_set_clip_rectangle (dst
->hdc
, &r
);
1134 Compute left and right overhang of glyph string S. */
1137 w32_compute_glyph_string_overhangs (struct glyph_string
*s
)
1140 && s
->first_glyph
->type
== CHAR_GLYPH
1141 && !s
->font_not_found_p
)
1143 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1144 struct font
*font
= s
->font
;
1145 struct font_metrics metrics
;
1148 for (i
= 0; i
< s
->nchars
; i
++)
1149 code
[i
] = s
->char2b
[i
];
1150 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1151 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1152 ? metrics
.rbearing
- metrics
.width
: 0);
1153 s
->left_overhang
= metrics
.lbearing
< 0 ? -metrics
.lbearing
: 0;
1157 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1158 s
->left_overhang
= -s
->cmp
->lbearing
;
1162 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1165 x_clear_glyph_string_rect (struct glyph_string
*s
,
1166 int x
, int y
, int w
, int h
)
1173 /* Take clipping into account. */
1174 if (s
->gc
->clip_mask
== Rect
)
1176 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
1177 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
1178 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
1179 - s
->gc
->clip_rectangle
.left
);
1180 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
1181 - s
->gc
->clip_rectangle
.top
);
1184 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
1189 /* Draw the background of glyph_string S. If S->background_filled_p
1190 is non-zero don't draw it. FORCE_P non-zero means draw the
1191 background even if it wouldn't be drawn normally. This is used
1192 when a string preceding S draws into the background of S, or S
1193 contains the first component of a composition. */
1196 x_draw_glyph_string_background (struct glyph_string
*s
, int force_p
)
1198 /* Nothing to do if background has already been drawn or if it
1199 shouldn't be drawn in the first place. */
1200 if (!s
->background_filled_p
)
1202 int box_line_width
= max (s
->face
->box_line_width
, 0);
1204 #if 0 /* TODO: stipple */
1207 /* Fill background with a stipple pattern. */
1208 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1209 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1210 s
->y
+ box_line_width
,
1211 s
->background_width
,
1212 s
->height
- 2 * box_line_width
);
1213 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1214 s
->background_filled_p
= 1;
1218 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1219 || s
->font_not_found_p
1220 || s
->extends_to_end_of_line_p
1223 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1224 s
->background_width
,
1225 s
->height
- 2 * box_line_width
);
1226 s
->background_filled_p
= 1;
1232 /* Draw the foreground of glyph string S. */
1235 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1239 /* If first glyph of S has a left box line, start drawing the text
1240 of S to the right of that box line. */
1241 if (s
->face
->box
!= FACE_NO_BOX
1242 && s
->first_glyph
->left_box_line_p
)
1243 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1247 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1248 SetBkColor (s
->hdc
, s
->gc
->background
);
1249 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1251 /* Draw characters of S as rectangles if S's font could not be
1253 if (s
->font_not_found_p
)
1255 for (i
= 0; i
< s
->nchars
; ++i
)
1257 struct glyph
*g
= s
->first_glyph
+ i
;
1259 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1261 x
+= g
->pixel_width
;
1266 struct font
*font
= s
->font
;
1267 int boff
= font
->baseline_offset
;
1271 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1273 if (font
->vertical_centering
)
1274 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1276 y
= s
->ybase
- boff
;
1278 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1279 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1281 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1282 if (s
->face
->overstrike
)
1283 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1285 SelectObject (s
->hdc
, old_font
);
1289 /* Draw the foreground of composite glyph string S. */
1292 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1295 struct font
*font
= s
->font
;
1297 /* If first glyph of S has a left box line, start drawing the text
1298 of S to the right of that box line. */
1299 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1300 && s
->first_glyph
->left_box_line_p
)
1301 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1305 /* S is a glyph string for a composition. S->cmp_from is the index
1306 of the first character drawn for glyphs of this composition.
1307 S->cmp_from == 0 means we are drawing the very first character of
1308 this composition. */
1310 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1311 SetBkColor (s
->hdc
, s
->gc
->background
);
1312 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1314 /* Draw a rectangle for the composition if the font for the very
1315 first character of the composition could not be loaded. */
1316 if (s
->font_not_found_p
)
1318 if (s
->cmp_from
== 0)
1319 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
1322 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1327 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1329 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1330 /* TAB in a composition means display glyphs with padding
1331 space on the left or right. */
1332 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1334 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1335 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1337 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1338 if (s
->face
->overstrike
)
1339 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1341 SelectObject (s
->hdc
, old_font
);
1345 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1351 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1353 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1355 glyph
= LGSTRING_GLYPH (gstring
, i
);
1356 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1357 width
+= LGLYPH_WIDTH (glyph
);
1360 int xoff
, yoff
, wadjust
;
1364 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1367 xoff
= LGLYPH_XOFF (glyph
);
1368 yoff
= LGLYPH_YOFF (glyph
);
1369 wadjust
= LGLYPH_WADJUST (glyph
);
1370 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1377 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1379 SelectObject (s
->hdc
, old_font
);
1384 /* Draw the foreground of glyph string S for glyphless characters. */
1387 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1389 struct glyph
*glyph
= s
->first_glyph
;
1392 int with_background
;
1394 /* If first glyph of S has a left box line, start drawing the text
1395 of S to the right of that box line. */
1396 if (s
->face
->box
!= FACE_NO_BOX
1397 && s
->first_glyph
->left_box_line_p
)
1398 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1402 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1403 SetBkColor (s
->hdc
, s
->gc
->background
);
1404 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1407 with_background
= ! (s
->for_overlaps
1408 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
));
1409 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1411 char buf
[7], *str
= NULL
;
1412 int len
= glyph
->u
.glyphless
.len
;
1414 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1417 && CHAR_TABLE_P (Vglyphless_char_display
)
1418 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1422 = (! glyph
->u
.glyphless
.for_no_font
1423 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1424 glyph
->u
.glyphless
.ch
)
1425 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1426 if (STRINGP (acronym
))
1427 str
= SSDATA (acronym
);
1430 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1432 sprintf ((char *) buf
, "%0*X",
1433 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1434 glyph
->u
.glyphless
.ch
);
1438 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1439 w32_draw_rectangle (s
->hdc
, s
->gc
,
1440 x
, s
->ybase
- glyph
->ascent
,
1441 glyph
->pixel_width
- 1,
1442 glyph
->ascent
+ glyph
->descent
- 1);
1445 struct font
*font
= s
->font
;
1446 int upper_len
= (len
+ 1) / 2;
1450 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1451 /* It is certain that all LEN characters in STR are ASCII. */
1452 for (j
= 0; j
< len
; j
++)
1454 code
= font
->driver
->encode_char (font
, str
[j
]);
1455 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1457 font
->driver
->draw (s
, 0, upper_len
,
1458 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1459 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1461 font
->driver
->draw (s
, upper_len
, len
,
1462 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1463 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1465 SelectObject (s
->hdc
, old_font
);
1467 x
+= glyph
->pixel_width
;
1472 /* Brightness beyond which a color won't have its highlight brightness
1475 Nominally, highlight colors for `3d' faces are calculated by
1476 brightening an object's color by a constant scale factor, but this
1477 doesn't yield good results for dark colors, so for colors whose
1478 brightness is less than this value (on a scale of 0-255) have to
1479 use an additional additive factor.
1481 The value here is set so that the default menu-bar/mode-line color
1482 (grey75) will not have its highlights changed at all. */
1483 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
1486 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
1487 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1488 If this produces the same color as COLOR, try a color where all RGB
1489 values have DELTA added. Return the allocated color in *COLOR.
1490 DISPLAY is the X display, CMAP is the colormap to operate on.
1491 Value is non-zero if successful. */
1494 w32_alloc_lighter_color (struct frame
*f
, COLORREF
*color
,
1495 double factor
, int delta
)
1500 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
1503 /* Change RGB values by specified FACTOR. Avoid overflow! */
1504 eassert (factor
>= 0);
1505 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
1506 min (0xff, factor
* GetGValue (*color
)),
1507 min (0xff, factor
* GetBValue (*color
)));
1509 /* Calculate brightness of COLOR. */
1510 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
1511 + GetBValue (*color
)) / 6;
1513 /* We only boost colors that are darker than
1514 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1515 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1516 /* Make an additive adjustment to NEW, because it's dark enough so
1517 that scaling by FACTOR alone isn't enough. */
1519 /* How far below the limit this color is (0 - 1, 1 being darker). */
1520 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1521 /* The additive adjustment. */
1522 int min_delta
= delta
* dimness
* factor
/ 2;
1525 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
1526 max (0, min (0xff, min_delta
- GetGValue (*color
))),
1527 max (0, min (0xff, min_delta
- GetBValue (*color
))));
1529 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
1530 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
1531 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
1535 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
1536 max (0, min (0xff, delta
+ GetGValue (*color
))),
1537 max (0, min (0xff, delta
+ GetBValue (*color
))));
1539 /* TODO: Map to palette and retry with delta if same? */
1540 /* TODO: Free colors (if using palette)? */
1550 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1551 colors in COLORS. On W32, we no longer try to map colors to
1554 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1558 for (i
= 0; i
< ncolors
; i
++)
1560 DWORD pixel
= colors
[i
].pixel
;
1561 /* Convert to a 16 bit value in range 0 - 0xffff. */
1562 colors
[i
].red
= GetRValue (pixel
) * 257;
1563 colors
[i
].green
= GetGValue (pixel
) * 257;
1564 colors
[i
].blue
= GetBValue (pixel
) * 257;
1569 x_query_color (struct frame
*f
, XColor
*color
)
1571 x_query_colors (f
, color
, 1);
1575 /* Set up the foreground color for drawing relief lines of glyph
1576 string S. RELIEF is a pointer to a struct relief containing the GC
1577 with which lines will be drawn. Use a color that is FACTOR or
1578 DELTA lighter or darker than the relief's background which is found
1579 in S->f->output_data.x->relief_background. If such a color cannot
1580 be allocated, use DEFAULT_PIXEL, instead. */
1583 w32_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
,
1584 int delta
, COLORREF default_pixel
)
1587 struct w32_output
*di
= f
->output_data
.w32
;
1588 unsigned long mask
= GCForeground
;
1590 COLORREF background
= di
->relief_background
;
1591 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1593 /* TODO: Free colors (if using palette)? */
1595 /* Allocate new color. */
1596 xgcv
.foreground
= default_pixel
;
1598 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
1600 relief
->allocated_p
= 1;
1601 xgcv
.foreground
= relief
->pixel
= pixel
;
1604 if (relief
->gc
== 0)
1606 #if 0 /* TODO: stipple */
1607 xgcv
.stipple
= dpyinfo
->gray
;
1610 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
1613 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
1617 /* Set up colors for the relief lines around glyph string S. */
1620 x_setup_relief_colors (struct glyph_string
*s
)
1622 struct w32_output
*di
= s
->f
->output_data
.w32
;
1625 if (s
->face
->use_box_color_for_shadows_p
)
1626 color
= s
->face
->box_color
;
1627 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1629 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1630 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1632 color
= s
->gc
->background
;
1634 if (di
->white_relief
.gc
== 0
1635 || color
!= di
->relief_background
)
1637 di
->relief_background
= color
;
1638 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1639 WHITE_PIX_DEFAULT (s
->f
));
1640 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1641 BLACK_PIX_DEFAULT (s
->f
));
1646 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1647 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1648 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1649 relief. LEFT_P non-zero means draw a relief on the left side of
1650 the rectangle. RIGHT_P non-zero means draw a relief on the right
1651 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1655 w32_draw_relief_rect (struct frame
*f
,
1656 int left_x
, int top_y
, int right_x
, int bottom_y
,
1657 int width
, int raised_p
,
1658 int top_p
, int bot_p
, int left_p
, int right_p
,
1663 HDC hdc
= get_frame_dc (f
);
1666 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1668 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1670 w32_set_clip_rectangle (hdc
, clip_rect
);
1674 for (i
= 0; i
< width
; ++i
)
1675 w32_fill_area (f
, hdc
, gc
.foreground
,
1676 left_x
+ i
* left_p
, top_y
+ i
,
1677 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1681 for (i
= 0; i
< width
; ++i
)
1682 w32_fill_area (f
, hdc
, gc
.foreground
,
1683 left_x
+ i
, top_y
+ (i
+ 1) * top_p
, 1,
1684 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1687 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1689 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1693 for (i
= 0; i
< width
; ++i
)
1694 w32_fill_area (f
, hdc
, gc
.foreground
,
1695 left_x
+ i
* left_p
, bottom_y
- i
,
1696 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1700 for (i
= 0; i
< width
; ++i
)
1701 w32_fill_area (f
, hdc
, gc
.foreground
,
1702 right_x
- i
, top_y
+ (i
+ 1) * top_p
, 1,
1703 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1705 w32_set_clip_rectangle (hdc
, NULL
);
1707 release_frame_dc (f
, hdc
);
1711 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1712 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1713 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
1714 left side of the rectangle. RIGHT_P non-zero means draw a line
1715 on the right side of the rectangle. CLIP_RECT is the clipping
1716 rectangle to use when drawing. */
1719 w32_draw_box_rect (struct glyph_string
*s
,
1720 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1721 int left_p
, int right_p
, RECT
*clip_rect
)
1723 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
1726 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1727 left_x
, top_y
, right_x
- left_x
+ 1, width
);
1732 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1733 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
1737 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1738 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
1743 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1744 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
1747 w32_set_clip_rectangle (s
->hdc
, NULL
);
1751 /* Draw a box around glyph string S. */
1754 x_draw_glyph_string_box (struct glyph_string
*s
)
1756 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
1757 int left_p
, right_p
;
1758 struct glyph
*last_glyph
;
1761 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
1762 ? WINDOW_RIGHT_EDGE_X (s
->w
)
1763 : window_box_right (s
->w
, s
->area
));
1765 /* The glyph that may have a right box line. */
1766 last_glyph
= (s
->cmp
|| s
->img
1768 : s
->first_glyph
+ s
->nchars
- 1);
1770 width
= eabs (s
->face
->box_line_width
);
1771 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
1773 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
1775 : min (last_x
, s
->x
+ s
->background_width
) - 1));
1777 bottom_y
= top_y
+ s
->height
- 1;
1779 left_p
= (s
->first_glyph
->left_box_line_p
1780 || (s
->hl
== DRAW_MOUSE_FACE
1782 || s
->prev
->hl
!= s
->hl
)));
1783 right_p
= (last_glyph
->right_box_line_p
1784 || (s
->hl
== DRAW_MOUSE_FACE
1786 || s
->next
->hl
!= s
->hl
)));
1788 get_glyph_string_clip_rect (s
, &clip_rect
);
1790 if (s
->face
->box
== FACE_SIMPLE_BOX
)
1791 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
1792 left_p
, right_p
, &clip_rect
);
1795 x_setup_relief_colors (s
);
1796 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
1797 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
1802 /* Draw foreground of image glyph string S. */
1805 x_draw_image_foreground (struct glyph_string
*s
)
1808 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1810 /* If first glyph of S has a left box line, start drawing it to the
1811 right of that line. */
1812 if (s
->face
->box
!= FACE_NO_BOX
1813 && s
->first_glyph
->left_box_line_p
1815 x
+= eabs (s
->face
->box_line_width
);
1817 /* If there is a margin around the image, adjust x- and y-position
1819 if (s
->slice
.x
== 0)
1820 x
+= s
->img
->hmargin
;
1821 if (s
->slice
.y
== 0)
1822 y
+= s
->img
->vmargin
;
1828 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
1829 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1830 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
1831 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1832 SetBkColor (compat_hdc
, RGB (255, 255, 255));
1833 SetTextColor (s
->hdc
, RGB (0, 0, 0));
1834 x_set_glyph_string_clipping (s
);
1838 HDC mask_dc
= CreateCompatibleDC (s
->hdc
);
1839 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1841 SetTextColor (s
->hdc
, RGB (255, 255, 255));
1842 SetBkColor (s
->hdc
, RGB (0, 0, 0));
1844 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1845 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1846 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1847 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
1848 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1849 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1851 SelectObject (mask_dc
, mask_orig_obj
);
1856 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1857 SetBkColor (s
->hdc
, s
->gc
->background
);
1859 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1860 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
1862 /* When the image has a mask, we can expect that at
1863 least part of a mouse highlight or a block cursor will
1864 be visible. If the image doesn't have a mask, make
1865 a block cursor visible by drawing a rectangle around
1866 the image. I believe it's looking better if we do
1867 nothing here for mouse-face. */
1868 if (s
->hl
== DRAW_CURSOR
)
1870 int r
= s
->img
->relief
;
1872 w32_draw_rectangle (s
->hdc
, s
->gc
, x
- r
, y
- r
,
1873 s
->slice
.width
+ r
*2 - 1,
1874 s
->slice
.height
+ r
*2 - 1);
1878 w32_set_clip_rectangle (s
->hdc
, NULL
);
1879 SelectObject (s
->hdc
, orig_brush
);
1880 DeleteObject (fg_brush
);
1881 SelectObject (compat_hdc
, orig_obj
);
1882 DeleteDC (compat_hdc
);
1885 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
,
1886 s
->slice
.width
- 1, s
->slice
.height
- 1);
1888 RestoreDC (s
->hdc
,-1);
1892 /* Draw a relief around the image glyph string S. */
1895 x_draw_image_relief (struct glyph_string
*s
)
1897 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
1900 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1902 /* If first glyph of S has a left box line, start drawing it to the
1903 right of that line. */
1904 if (s
->face
->box
!= FACE_NO_BOX
1905 && s
->first_glyph
->left_box_line_p
1907 x
+= eabs (s
->face
->box_line_width
);
1909 /* If there is a margin around the image, adjust x- and y-position
1911 if (s
->slice
.x
== 0)
1912 x
+= s
->img
->hmargin
;
1913 if (s
->slice
.y
== 0)
1914 y
+= s
->img
->vmargin
;
1916 if (s
->hl
== DRAW_IMAGE_SUNKEN
1917 || s
->hl
== DRAW_IMAGE_RAISED
)
1919 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
1920 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
1921 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
1925 thick
= eabs (s
->img
->relief
);
1926 raised_p
= s
->img
->relief
> 0;
1929 x1
= x
+ s
->slice
.width
- 1;
1930 y1
= y
+ s
->slice
.height
- 1;
1931 top_p
= bot_p
= left_p
= right_p
= 0;
1933 if (s
->slice
.x
== 0)
1934 x
-= thick
, left_p
= 1;
1935 if (s
->slice
.y
== 0)
1936 y
-= thick
, top_p
= 1;
1937 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
1938 x1
+= thick
, right_p
= 1;
1939 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
1940 y1
+= thick
, bot_p
= 1;
1942 x_setup_relief_colors (s
);
1943 get_glyph_string_clip_rect (s
, &r
);
1944 w32_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
1945 top_p
, bot_p
, left_p
, right_p
, &r
);
1949 /* Draw the foreground of image glyph string S to PIXMAP. */
1952 w32_draw_image_foreground_1 (struct glyph_string
*s
, HBITMAP pixmap
)
1954 HDC hdc
= CreateCompatibleDC (s
->hdc
);
1955 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
1957 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1959 /* If first glyph of S has a left box line, start drawing it to the
1960 right of that line. */
1961 if (s
->face
->box
!= FACE_NO_BOX
1962 && s
->first_glyph
->left_box_line_p
1964 x
+= eabs (s
->face
->box_line_width
);
1966 /* If there is a margin around the image, adjust x- and y-position
1968 if (s
->slice
.x
== 0)
1969 x
+= s
->img
->hmargin
;
1970 if (s
->slice
.y
== 0)
1971 y
+= s
->img
->vmargin
;
1975 HDC compat_hdc
= CreateCompatibleDC (hdc
);
1976 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1977 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
1978 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1982 HDC mask_dc
= CreateCompatibleDC (hdc
);
1983 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1985 SetTextColor (hdc
, RGB (0, 0, 0));
1986 SetBkColor (hdc
, RGB (255, 255, 255));
1987 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1988 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1989 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1990 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
1991 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1992 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1994 SelectObject (mask_dc
, mask_orig_obj
);
1999 SetTextColor (hdc
, s
->gc
->foreground
);
2000 SetBkColor (hdc
, s
->gc
->background
);
2002 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2003 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
2005 /* When the image has a mask, we can expect that at
2006 least part of a mouse highlight or a block cursor will
2007 be visible. If the image doesn't have a mask, make
2008 a block cursor visible by drawing a rectangle around
2009 the image. I believe it's looking better if we do
2010 nothing here for mouse-face. */
2011 if (s
->hl
== DRAW_CURSOR
)
2013 int r
= s
->img
->relief
;
2015 w32_draw_rectangle (hdc
, s
->gc
, x
- r
, y
- r
,
2016 s
->slice
.width
+ r
*2 - 1,
2017 s
->slice
.height
+ r
*2 - 1);
2021 SelectObject (hdc
, orig_brush
);
2022 DeleteObject (fg_brush
);
2023 SelectObject (compat_hdc
, orig_obj
);
2024 DeleteDC (compat_hdc
);
2027 w32_draw_rectangle (hdc
, s
->gc
, x
, y
,
2028 s
->slice
.width
- 1, s
->slice
.height
- 1);
2030 SelectObject (hdc
, orig_hdc_obj
);
2035 /* Draw part of the background of glyph string S. X, Y, W, and H
2036 give the rectangle to draw. */
2039 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2041 #if 0 /* TODO: stipple */
2044 /* Fill background with a stipple pattern. */
2045 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2046 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2047 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2051 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2055 /* Draw image glyph string S.
2058 s->x +-------------------------
2061 | +-------------------------
2064 | | +-------------------
2070 x_draw_image_glyph_string (struct glyph_string
*s
)
2073 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2074 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2078 height
= s
->height
- 2 * box_line_vwidth
;
2080 /* Fill background with face under the image. Do it only if row is
2081 taller than image or if image has a clip mask to reduce
2083 s
->stippled_p
= s
->face
->stipple
!= 0;
2084 if (height
> s
->slice
.height
2088 || s
->img
->pixmap
== 0
2089 || s
->width
!= s
->background_width
)
2092 if (s
->first_glyph
->left_box_line_p
2094 x
+= box_line_hwidth
;
2097 if (s
->slice
.y
== 0)
2098 y
+= box_line_vwidth
;
2100 #if 0 /* TODO: figure out if we need to do this on Windows. */
2103 /* Create a pixmap as large as the glyph string. Fill it
2104 with the background color. Copy the image to it, using
2105 its mask. Copy the temporary pixmap to the display. */
2106 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2107 int depth
= DefaultDepthOfScreen (screen
);
2109 /* Create a pixmap as large as the glyph string. */
2110 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2111 s
->background_width
,
2114 /* Don't clip in the following because we're working on the
2116 XSetClipMask (s
->display
, s
->gc
, None
);
2118 /* Fill the pixmap with the background color/stipple. */
2121 /* Fill background with a stipple pattern. */
2122 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2123 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2124 0, 0, s
->background_width
, s
->height
);
2125 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2130 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2132 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2133 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2134 0, 0, s
->background_width
, s
->height
);
2135 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2140 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2142 s
->background_filled_p
= 1;
2145 /* Draw the foreground. */
2148 w32_draw_image_foreground_1 (s
, pixmap
);
2149 x_set_glyph_string_clipping (s
);
2151 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
2152 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
2153 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
2154 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
2156 SetTextColor (s
->hdc
, s
->gc
->foreground
);
2157 SetBkColor (s
->hdc
, s
->gc
->background
);
2158 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
2159 compat_hdc
, 0, 0, SRCCOPY
);
2161 SelectObject (s
->hdc
, orig_brush
);
2162 DeleteObject (fg_brush
);
2163 SelectObject (compat_hdc
, orig_obj
);
2164 DeleteDC (compat_hdc
);
2166 DeleteObject (pixmap
);
2170 x_draw_image_foreground (s
);
2172 /* If we must draw a relief around the image, do it. */
2174 || s
->hl
== DRAW_IMAGE_RAISED
2175 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2176 x_draw_image_relief (s
);
2180 /* Draw stretch glyph string S. */
2183 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2185 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2187 if (s
->hl
== DRAW_CURSOR
2188 && !x_stretch_cursor_p
)
2190 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2191 wide as the stretch glyph. */
2192 int width
, background_width
= s
->background_width
;
2195 if (!s
->row
->reversed_p
)
2197 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2201 background_width
-= left_x
- x
;
2207 /* In R2L rows, draw the cursor on the right edge of the
2209 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2211 if (x
+ background_width
> right_x
)
2212 background_width
-= x
- right_x
;
2213 x
+= background_width
;
2215 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2216 if (s
->row
->reversed_p
)
2220 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2222 /* Clear rest using the GC of the original non-cursor face. */
2223 if (width
< background_width
)
2225 XGCValues
*gc
= s
->face
->gc
;
2227 int w
= background_width
- width
, h
= s
->height
;
2231 if (!s
->row
->reversed_p
)
2235 if (s
->row
->mouse_face_p
2236 && cursor_in_mouse_face_p (s
->w
))
2238 x_set_mouse_face_gc (s
);
2244 get_glyph_string_clip_rect (s
, &r
);
2245 w32_set_clip_rectangle (hdc
, &r
);
2247 #if 0 /* TODO: stipple */
2248 if (s
->face
->stipple
)
2250 /* Fill background with a stipple pattern. */
2251 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2252 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2253 XSetFillStyle (s
->display
, gc
, FillSolid
);
2258 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
2262 else if (!s
->background_filled_p
)
2264 int background_width
= s
->background_width
;
2265 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2267 /* Don't draw into left margin, fringe or scrollbar area
2268 except for header line and mode line. */
2269 if (x
< left_x
&& !s
->row
->mode_line_p
)
2271 background_width
-= left_x
- x
;
2274 if (background_width
> 0)
2275 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2278 s
->background_filled_p
= 1;
2282 /* Draw glyph string S. */
2285 x_draw_glyph_string (struct glyph_string
*s
)
2287 bool relief_drawn_p
= 0;
2289 /* If S draws into the background of its successor, draw the
2290 background of the successor first so that S can draw into it.
2291 This makes S->next use XDrawString instead of XDrawImageString. */
2292 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2295 struct glyph_string
*next
;
2296 for (width
= 0, next
= s
->next
;
2297 next
&& width
< s
->right_overhang
;
2298 width
+= next
->width
, next
= next
->next
)
2299 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2301 x_set_glyph_string_gc (next
);
2302 x_set_glyph_string_clipping (next
);
2303 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2304 x_draw_stretch_glyph_string (next
);
2306 x_draw_glyph_string_background (next
, 1);
2307 next
->num_clips
= 0;
2311 /* Set up S->gc, set clipping and draw S. */
2312 x_set_glyph_string_gc (s
);
2314 /* Draw relief (if any) in advance for char/composition so that the
2315 glyph string can be drawn over it. */
2316 if (!s
->for_overlaps
2317 && s
->face
->box
!= FACE_NO_BOX
2318 && (s
->first_glyph
->type
== CHAR_GLYPH
2319 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2322 x_set_glyph_string_clipping (s
);
2323 x_draw_glyph_string_background (s
, 1);
2324 x_draw_glyph_string_box (s
);
2325 x_set_glyph_string_clipping (s
);
2328 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2330 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2331 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2332 /* We must clip just this glyph. left_overhang part has already
2333 drawn when s->prev was drawn, and right_overhang part will be
2334 drawn later when s->next is drawn. */
2335 x_set_glyph_string_clipping_exactly (s
, s
);
2337 x_set_glyph_string_clipping (s
);
2339 switch (s
->first_glyph
->type
)
2342 x_draw_image_glyph_string (s
);
2346 x_draw_stretch_glyph_string (s
);
2350 if (s
->for_overlaps
)
2351 s
->background_filled_p
= 1;
2353 x_draw_glyph_string_background (s
, 0);
2354 x_draw_glyph_string_foreground (s
);
2357 case COMPOSITE_GLYPH
:
2358 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2359 && ! s
->first_glyph
->u
.cmp
.automatic
))
2360 s
->background_filled_p
= 1;
2362 x_draw_glyph_string_background (s
, 1);
2363 x_draw_composite_glyph_string_foreground (s
);
2366 case GLYPHLESS_GLYPH
:
2367 if (s
->for_overlaps
)
2368 s
->background_filled_p
= 1;
2370 x_draw_glyph_string_background (s
, 0);
2371 x_draw_glyphless_glyph_string_foreground (s
);
2378 if (!s
->for_overlaps
)
2380 /* Draw underline. */
2381 if (s
->face
->underline_p
)
2383 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2387 if (s
->face
->underline_defaulted_p
)
2388 color
= s
->gc
->foreground
;
2390 color
= s
->face
->underline_color
;
2392 w32_draw_underwave (s
, color
);
2394 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2396 unsigned long thickness
, position
;
2399 if (s
->prev
&& s
->prev
->face
->underline_p
2400 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2402 /* We use the same underline style as the previous one. */
2403 thickness
= s
->prev
->underline_thickness
;
2404 position
= s
->prev
->underline_position
;
2408 /* Get the underline thickness. Default is 1 pixel. */
2409 if (s
->font
&& s
->font
->underline_thickness
> 0)
2410 thickness
= s
->font
->underline_thickness
;
2413 if (x_underline_at_descent_line
)
2414 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2417 /* Get the underline position. This is the recommended
2418 vertical offset in pixels from the baseline to the top of
2419 the underline. This is a signed value according to the
2420 specs, and its default is
2422 ROUND ((maximum_descent) / 2), with
2423 ROUND (x) = floor (x + 0.5) */
2425 if (x_use_underline_position_properties
2426 && s
->font
&& s
->font
->underline_position
>= 0)
2427 position
= s
->font
->underline_position
;
2429 position
= (s
->font
->descent
+ 1) / 2;
2431 position
= max (position
, underline_minimum_offset
);
2433 /* Check the sanity of thickness and position. We should
2434 avoid drawing underline out of the current line area. */
2435 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2436 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2437 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2438 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2439 s
->underline_thickness
= thickness
;
2440 s
->underline_position
=position
;
2441 y
= s
->ybase
+ position
;
2442 if (s
->face
->underline_defaulted_p
)
2444 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2449 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
2454 /* Draw overline. */
2455 if (s
->face
->overline_p
)
2457 unsigned long dy
= 0, h
= 1;
2459 if (s
->face
->overline_color_defaulted_p
)
2461 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2462 s
->y
+ dy
, s
->width
, h
);
2466 w32_fill_area (s
->f
, s
->hdc
, s
->face
->overline_color
, s
->x
,
2467 s
->y
+ dy
, s
->width
, h
);
2471 /* Draw strike-through. */
2472 if (s
->face
->strike_through_p
2473 && !FONT_TEXTMETRIC (s
->font
).tmStruckOut
)
2475 unsigned long h
= 1;
2476 unsigned long dy
= (s
->height
- h
) / 2;
2478 if (s
->face
->strike_through_color_defaulted_p
)
2480 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
2485 w32_fill_area (s
->f
, s
->hdc
, s
->face
->strike_through_color
, s
->x
,
2486 s
->y
+ dy
, s
->width
, h
);
2490 /* Draw relief if not yet drawn. */
2491 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2492 x_draw_glyph_string_box (s
);
2496 struct glyph_string
*prev
;
2498 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2499 if (prev
->hl
!= s
->hl
2500 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2502 /* As prev was drawn while clipped to its own area, we
2503 must draw the right_overhang part using s->hl now. */
2504 enum draw_glyphs_face save
= prev
->hl
;
2507 x_set_glyph_string_gc (prev
);
2508 x_set_glyph_string_clipping_exactly (s
, prev
);
2509 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2510 x_draw_glyph_string_foreground (prev
);
2512 x_draw_composite_glyph_string_foreground (prev
);
2513 w32_set_clip_rectangle (prev
->hdc
, NULL
);
2515 prev
->num_clips
= 0;
2521 struct glyph_string
*next
;
2523 for (next
= s
->next
; next
; next
= next
->next
)
2524 if (next
->hl
!= s
->hl
2525 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2527 /* As next will be drawn while clipped to its own area,
2528 we must draw the left_overhang part using s->hl now. */
2529 enum draw_glyphs_face save
= next
->hl
;
2532 x_set_glyph_string_gc (next
);
2533 x_set_glyph_string_clipping_exactly (s
, next
);
2534 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2535 x_draw_glyph_string_foreground (next
);
2537 x_draw_composite_glyph_string_foreground (next
);
2538 w32_set_clip_rectangle (next
->hdc
, NULL
);
2540 next
->num_clips
= 0;
2541 next
->clip_head
= s
->next
;
2546 /* Reset clipping. */
2547 w32_set_clip_rectangle (s
->hdc
, NULL
);
2552 /* Shift display to make room for inserted glyphs. */
2555 w32_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
,
2556 int width
, int height
, int shift_by
)
2560 hdc
= get_frame_dc (f
);
2561 BitBlt (hdc
, x
+ shift_by
, y
, width
, height
,
2562 hdc
, x
, y
, SRCCOPY
);
2564 release_frame_dc (f
, hdc
);
2568 /* Delete N glyphs at the nominal cursor position. Not implemented
2572 x_delete_glyphs (struct frame
*f
, register int n
)
2574 if (! FRAME_W32_P (f
))
2581 /* Clear entire frame. */
2584 x_clear_frame (struct frame
*f
)
2586 if (! FRAME_W32_P (f
))
2589 /* Clearing the frame will erase any cursor, so mark them all as no
2591 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2595 w32_clear_window (f
);
2597 /* We have to clear the scroll bars, too. If we have changed
2598 colors or something like that, then they should be notified. */
2599 x_scroll_bar_clear (f
);
2605 /* Make audible bell. */
2608 w32_ring_bell (struct frame
*f
)
2612 if (FRAME_W32_P (f
) && visible_bell
)
2615 HWND hwnd
= FRAME_W32_WINDOW (f
);
2617 for (i
= 0; i
< 5; i
++)
2619 FlashWindow (hwnd
, TRUE
);
2622 FlashWindow (hwnd
, FALSE
);
2625 w32_sys_ring_bell (f
);
2630 /***********************************************************************
2632 ***********************************************************************/
2634 /* Perform an insert-lines or delete-lines operation, inserting N
2635 lines or deleting -N lines at vertical position VPOS. */
2638 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
2640 if (! FRAME_W32_P (f
))
2647 /* Scroll part of the display as described by RUN. */
2650 x_scroll_run (struct window
*w
, struct run
*run
)
2652 struct frame
*f
= XFRAME (w
->frame
);
2653 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2654 HWND hwnd
= FRAME_W32_WINDOW (f
);
2657 /* Get frame-relative bounding box of the text display area of W,
2658 without mode lines. Include in this box the left and right
2660 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
2662 /* If the fringe is adjacent to the left (right) scroll bar of a
2663 leftmost (rightmost, respectively) window, then extend its
2664 background to the gap between the fringe and the bar. */
2665 if ((WINDOW_LEFTMOST_P (w
)
2666 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
2667 || (WINDOW_RIGHTMOST_P (w
)
2668 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
2670 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
2674 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
2675 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
2676 * FRAME_COLUMN_WIDTH (f
));
2678 if (bar_area_x
+ bar_area_width
== x
)
2680 x
= bar_area_x
+ sb_width
;
2681 width
+= bar_area_width
- sb_width
;
2683 else if (x
+ width
== bar_area_x
)
2684 width
+= bar_area_width
- sb_width
;
2688 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
2689 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
2690 bottom_y
= y
+ height
;
2694 /* Scrolling up. Make sure we don't copy part of the mode
2695 line at the bottom. */
2696 if (from_y
+ run
->height
> bottom_y
)
2697 height
= bottom_y
- from_y
;
2699 height
= run
->height
;
2700 expect_dirty
= CreateRectRgn (x
, y
+ height
, x
+ width
, bottom_y
);
2704 /* Scrolling down. Make sure we don't copy over the mode line.
2706 if (to_y
+ run
->height
> bottom_y
)
2707 height
= bottom_y
- to_y
;
2709 height
= run
->height
;
2710 expect_dirty
= CreateRectRgn (x
, y
, x
+ width
, to_y
);
2715 /* Cursor off. Will be switched on again in x_update_window_end. */
2721 HRGN dirty
= CreateRectRgn (0, 0, 0, 0);
2722 HRGN combined
= CreateRectRgn (0, 0, 0, 0);
2724 from
.left
= to
.left
= x
;
2725 from
.right
= to
.right
= x
+ width
;
2727 from
.bottom
= from_y
+ height
;
2729 to
.bottom
= bottom_y
;
2731 ScrollWindowEx (hwnd
, 0, to_y
- from_y
, &from
, &to
, dirty
,
2732 NULL
, SW_INVALIDATE
);
2734 /* Combine this with what we expect to be dirty. This covers the
2735 case where not all of the region we expect is actually dirty. */
2736 CombineRgn (combined
, dirty
, expect_dirty
, RGN_OR
);
2738 /* If the dirty region is not what we expected, redraw the entire frame. */
2739 if (!EqualRgn (combined
, expect_dirty
))
2740 SET_FRAME_GARBAGED (f
);
2742 DeleteObject (dirty
);
2743 DeleteObject (combined
);
2747 DeleteObject (expect_dirty
);
2752 /***********************************************************************
2754 ***********************************************************************/
2757 frame_highlight (struct frame
*f
)
2759 x_update_cursor (f
, 1);
2760 x_set_frame_alpha (f
);
2764 frame_unhighlight (struct frame
*f
)
2766 x_update_cursor (f
, 1);
2767 x_set_frame_alpha (f
);
2770 /* The focus has changed. Update the frames as necessary to reflect
2771 the new situation. Note that we can't change the selected frame
2772 here, because the Lisp code we are interrupting might become confused.
2773 Each event gets marked with the frame in which it occurred, so the
2774 Lisp code can tell when the switch took place by examining the events. */
2777 x_new_focus_frame (struct w32_display_info
*dpyinfo
, struct frame
*frame
)
2779 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
2781 if (frame
!= dpyinfo
->w32_focus_frame
)
2783 /* Set this before calling other routines, so that they see
2784 the correct value of w32_focus_frame. */
2785 dpyinfo
->w32_focus_frame
= frame
;
2787 if (old_focus
&& old_focus
->auto_lower
)
2788 x_lower_frame (old_focus
);
2790 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
2791 dpyinfo
->w32_pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
2793 dpyinfo
->w32_pending_autoraise_frame
= NULL
;
2796 x_frame_rehighlight (dpyinfo
);
2800 /* Handle FocusIn and FocusOut state changes for FRAME.
2801 If FRAME has focus and there exists more than one frame, puts
2802 a FOCUS_IN_EVENT into *BUFP. */
2805 x_focus_changed (int type
, int state
, struct w32_display_info
*dpyinfo
,
2806 struct frame
*frame
, struct input_event
*bufp
)
2808 if (type
== WM_SETFOCUS
)
2810 if (dpyinfo
->w32_focus_event_frame
!= frame
)
2812 x_new_focus_frame (dpyinfo
, frame
);
2813 dpyinfo
->w32_focus_event_frame
= frame
;
2815 /* Don't stop displaying the initial startup message
2816 for a switch-frame event we don't need. */
2817 if (NILP (Vterminal_frame
)
2818 && CONSP (Vframe_list
)
2819 && !NILP (XCDR (Vframe_list
)))
2828 bufp
->kind
= FOCUS_IN_EVENT
;
2829 XSETFRAME (bufp
->frame_or_window
, frame
);
2832 frame
->output_data
.x
->focus_state
|= state
;
2834 /* TODO: IME focus? */
2836 else if (type
== WM_KILLFOCUS
)
2838 frame
->output_data
.x
->focus_state
&= ~state
;
2840 if (dpyinfo
->w32_focus_event_frame
== frame
)
2842 dpyinfo
->w32_focus_event_frame
= 0;
2843 x_new_focus_frame (dpyinfo
, 0);
2845 bufp
->kind
= FOCUS_OUT_EVENT
;
2846 XSETFRAME (bufp
->frame_or_window
, frame
);
2849 /* TODO: IME focus? */
2854 /* The focus may have changed. Figure out if it is a real focus change,
2855 by checking both FocusIn/Out and Enter/LeaveNotify events.
2857 Returns FOCUS_IN_EVENT event in *BUFP. */
2860 w32_detect_focus_change (struct w32_display_info
*dpyinfo
, W32Msg
*event
,
2861 struct input_event
*bufp
)
2863 struct frame
*frame
;
2865 frame
= x_any_window_to_frame (dpyinfo
, event
->msg
.hwnd
);
2869 /* On w32, this is only called from focus events, so no switch needed. */
2870 x_focus_changed (event
->msg
.message
,
2871 (event
->msg
.message
== WM_KILLFOCUS
?
2872 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
2873 dpyinfo
, frame
, bufp
);
2877 /* Handle an event saying the mouse has moved out of an Emacs frame. */
2880 x_mouse_leave (struct w32_display_info
*dpyinfo
)
2882 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
2885 /* The focus has changed, or we have redirected a frame's focus to
2886 another frame (this happens when a frame uses a surrogate
2887 mini-buffer frame). Shift the highlight as appropriate.
2889 The FRAME argument doesn't necessarily have anything to do with which
2890 frame is being highlighted or un-highlighted; we only use it to find
2891 the appropriate X display info. */
2894 w32_frame_rehighlight (struct frame
*frame
)
2896 if (! FRAME_W32_P (frame
))
2898 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
2902 x_frame_rehighlight (struct w32_display_info
*dpyinfo
)
2904 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
2906 if (dpyinfo
->w32_focus_frame
)
2908 dpyinfo
->x_highlight_frame
2909 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
2910 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
2911 : dpyinfo
->w32_focus_frame
);
2912 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
2914 fset_focus_frame (dpyinfo
->w32_focus_frame
, Qnil
);
2915 dpyinfo
->x_highlight_frame
= dpyinfo
->w32_focus_frame
;
2919 dpyinfo
->x_highlight_frame
= 0;
2921 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
2924 frame_unhighlight (old_highlight
);
2925 if (dpyinfo
->x_highlight_frame
)
2926 frame_highlight (dpyinfo
->x_highlight_frame
);
2930 /* Keyboard processing - modifier keys, etc. */
2932 /* Convert a keysym to its name. */
2935 x_get_keysym_name (int keysym
)
2937 /* Make static so we can always return it */
2938 static char value
[100];
2941 GetKeyNameText (keysym
, value
, 100);
2948 codepage_for_locale (LCID locale
)
2952 if (GetLocaleInfo (locale
, LOCALE_IDEFAULTANSICODEPAGE
, cp
, 20) > 0)
2959 /* Mouse clicks and mouse movement. Rah. */
2961 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
2962 the state in PUP. XBUTTON provides extra information for extended mouse
2963 button messages. Returns FALSE if unable to parse the message. */
2965 parse_button (int message
, int xbutton
, int * pbutton
, int * pup
)
2972 case WM_LBUTTONDOWN
:
2980 case WM_MBUTTONDOWN
:
2981 if (NILP (Vw32_swap_mouse_buttons
))
2988 if (NILP (Vw32_swap_mouse_buttons
))
2994 case WM_RBUTTONDOWN
:
2995 if (NILP (Vw32_swap_mouse_buttons
))
3002 if (NILP (Vw32_swap_mouse_buttons
))
3008 case WM_XBUTTONDOWN
:
3009 button
= xbutton
+ 2;
3013 button
= xbutton
+ 2;
3021 if (pbutton
) *pbutton
= button
;
3027 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3029 If the event is a button press, then note that we have grabbed
3033 construct_mouse_click (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3038 parse_button (msg
->msg
.message
, HIWORD (msg
->msg
.wParam
),
3041 /* Make the event type NO_EVENT; we'll change that when we decide
3043 result
->kind
= MOUSE_CLICK_EVENT
;
3044 result
->code
= button
;
3045 result
->timestamp
= msg
->msg
.time
;
3046 result
->modifiers
= (msg
->dwModifiers
3051 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
3052 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
3053 XSETFRAME (result
->frame_or_window
, f
);
3059 construct_mouse_wheel (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3064 result
->kind
= msg
->msg
.message
== WM_MOUSEHWHEEL
? HORIZ_WHEEL_EVENT
3067 result
->timestamp
= msg
->msg
.time
;
3069 /* A WHEEL_DELTA positive value indicates that the wheel was rotated
3070 forward, away from the user (up); a negative value indicates that
3071 the wheel was rotated backward, toward the user (down). */
3072 delta
= GET_WHEEL_DELTA_WPARAM (msg
->msg
.wParam
);
3074 /* The up and down modifiers indicate if the wheel was rotated up or
3075 down based on WHEEL_DELTA value. */
3076 result
->modifiers
= (msg
->dwModifiers
3077 | ((delta
< 0 ) ? down_modifier
: up_modifier
));
3079 /* With multiple monitors, we can legitimately get negative
3080 coordinates, so cast to short to interpret them correctly. */
3081 p
.x
= (short) LOWORD (msg
->msg
.lParam
);
3082 p
.y
= (short) HIWORD (msg
->msg
.lParam
);
3083 ScreenToClient (msg
->msg
.hwnd
, &p
);
3084 XSETINT (result
->x
, p
.x
);
3085 XSETINT (result
->y
, p
.y
);
3086 XSETFRAME (result
->frame_or_window
, f
);
3092 construct_drag_n_drop (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3102 result
->kind
= DRAG_N_DROP_EVENT
;
3104 result
->timestamp
= msg
->msg
.time
;
3105 result
->modifiers
= msg
->dwModifiers
;
3107 hdrop
= (HDROP
) msg
->msg
.wParam
;
3108 DragQueryPoint (hdrop
, &p
);
3111 p
.x
= LOWORD (msg
->msg
.lParam
);
3112 p
.y
= HIWORD (msg
->msg
.lParam
);
3113 ScreenToClient (msg
->msg
.hwnd
, &p
);
3116 XSETINT (result
->x
, p
.x
);
3117 XSETINT (result
->y
, p
.y
);
3119 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
3122 for (i
= 0; i
< num_files
; i
++)
3124 len
= GUI_FN (DragQueryFile
) (hdrop
, i
, NULL
, 0);
3128 name
= alloca ((len
+ 1) * sizeof (*name
));
3129 GUI_FN (DragQueryFile
) (hdrop
, i
, name
, len
+ 1);
3130 #ifdef NTGUI_UNICODE
3131 files
= Fcons (from_unicode_buffer (name
), files
);
3133 files
= Fcons (DECODE_FILE (build_string (name
)), files
);
3134 #endif /* NTGUI_UNICODE */
3139 XSETFRAME (frame
, f
);
3140 result
->frame_or_window
= frame
;
3141 result
->arg
= files
;
3148 /* File event notifications (see w32notify.c). */
3151 lispy_file_action (DWORD action
)
3153 static char unknown_fmt
[] = "unknown-action(%d)";
3158 case FILE_ACTION_ADDED
:
3161 case FILE_ACTION_REMOVED
:
3164 case FILE_ACTION_MODIFIED
:
3167 case FILE_ACTION_RENAMED_OLD_NAME
:
3168 retval
= Qrenamed_from
;
3170 case FILE_ACTION_RENAMED_NEW_NAME
:
3171 retval
= Qrenamed_to
;
3175 char buf
[sizeof(unknown_fmt
) - 1 + INT_STRLEN_BOUND (DWORD
)];
3177 sprintf (buf
, unknown_fmt
, action
);
3178 retval
= intern (buf
);
3187 /* Put file notifications into the Emacs input event queue. This
3188 function runs when the WM_EMACS_FILENOTIFY message arrives from a
3191 queue_notifications (struct input_event
*event
, W32Msg
*msg
, struct frame
*f
,
3194 BYTE
*p
= file_notifications
;
3195 FILE_NOTIFY_INFORMATION
*fni
= (PFILE_NOTIFY_INFORMATION
)p
;
3196 const DWORD min_size
3197 = offsetof (FILE_NOTIFY_INFORMATION
, FileName
) + sizeof(wchar_t);
3200 /* We cannot process notification before Emacs is fully initialized,
3201 since we need the UTF-16LE coding-system to be set up. */
3204 notification_buffer_in_use
= 0;
3208 XSETFRAME (frame
, f
);
3211 if (notification_buffer_in_use
)
3213 DWORD info_size
= notifications_size
;
3214 Lisp_Object cs
= intern ("utf-16le");
3215 Lisp_Object obj
= w32_get_watch_object (notifications_desc
);
3217 /* notifications_size could be zero when the buffer of
3218 notifications overflowed on the OS level, or when the
3219 directory being watched was itself deleted. Do nothing in
3222 && !NILP (obj
) && CONSP (obj
))
3224 Lisp_Object callback
= XCDR (obj
);
3226 while (info_size
>= min_size
)
3228 Lisp_Object utf_16_fn
3229 = make_unibyte_string ((char *)fni
->FileName
,
3230 fni
->FileNameLength
);
3231 /* Note: mule-conf is preloaded, so utf-16le must
3232 already be defined at this point. */
3234 = code_convert_string_norecord (utf_16_fn
, cs
, 0);
3235 Lisp_Object action
= lispy_file_action (fni
->Action
);
3237 event
->kind
= FILE_NOTIFY_EVENT
;
3239 = (ptrdiff_t)XINT (XIL ((EMACS_INT
)notifications_desc
));
3240 event
->timestamp
= msg
->msg
.time
;
3241 event
->modifiers
= 0;
3242 event
->frame_or_window
= callback
;
3243 event
->arg
= Fcons (action
, fname
);
3244 kbd_buffer_store_event (event
);
3247 if (!fni
->NextEntryOffset
)
3249 p
+= fni
->NextEntryOffset
;
3250 fni
= (PFILE_NOTIFY_INFORMATION
)p
;
3251 info_size
-= fni
->NextEntryOffset
;
3254 notification_buffer_in_use
= 0;
3257 DebPrint (("We were promised notifications, but in-use flag is zero!\n"));
3260 /* We've stuffed all the events ourselves, so w32_read_socket shouldn't. */
3261 event
->kind
= NO_EVENT
;
3263 #endif /* WINDOWSNT */
3264 #endif /* HAVE_W32NOTIFY */
3267 /* Function to report a mouse movement to the mainstream Emacs code.
3268 The input handler calls this.
3270 We have received a mouse movement event, which is given in *event.
3271 If the mouse is over a different glyph than it was last time, tell
3272 the mainstream emacs code by setting mouse_moved. If not, ask for
3273 another motion event, so we can check again the next time it moves. */
3276 note_mouse_movement (struct frame
*frame
, MSG
*msg
)
3278 struct w32_display_info
*dpyinfo
;
3279 int mouse_x
= LOWORD (msg
->lParam
);
3280 int mouse_y
= HIWORD (msg
->lParam
);
3283 if (!FRAME_X_OUTPUT (frame
))
3286 dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3287 dpyinfo
->last_mouse_movement_time
= msg
->time
;
3288 dpyinfo
->last_mouse_motion_frame
= frame
;
3289 dpyinfo
->last_mouse_motion_x
= mouse_x
;
3290 dpyinfo
->last_mouse_motion_y
= mouse_y
;
3292 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
3294 frame
->mouse_moved
= 1;
3295 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3296 note_mouse_highlight (frame
, -1, -1);
3297 dpyinfo
->last_mouse_glyph_frame
= NULL
;
3301 /* Has the mouse moved off the glyph it was on at the last sighting? */
3302 r
= &dpyinfo
->last_mouse_glyph
;
3303 if (frame
!= dpyinfo
->last_mouse_glyph_frame
3304 || mouse_x
< r
->left
|| mouse_x
>= r
->right
3305 || mouse_y
< r
->top
|| mouse_y
>= r
->bottom
)
3307 frame
->mouse_moved
= 1;
3308 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3309 note_mouse_highlight (frame
, mouse_x
, mouse_y
);
3310 /* Remember the mouse position here, as w32_mouse_position only
3311 gets called when mouse tracking is enabled but we also need
3312 to keep track of the mouse for help_echo and highlighting at
3314 remember_mouse_glyph (frame
, mouse_x
, mouse_y
, r
);
3315 dpyinfo
->last_mouse_glyph_frame
= frame
;
3323 /************************************************************************
3325 ************************************************************************/
3327 static struct scroll_bar
*x_window_to_scroll_bar (Window
);
3328 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
3329 enum scroll_bar_part
*,
3330 Lisp_Object
*, Lisp_Object
*,
3332 static void x_check_fullscreen (struct frame
*);
3335 w32_define_cursor (Window window
, Cursor cursor
)
3337 PostMessage (window
, WM_EMACS_SETCURSOR
, (WPARAM
) cursor
, 0);
3339 /* Return the current position of the mouse.
3340 *fp should be a frame which indicates which display to ask about.
3342 If the mouse movement started in a scroll bar, set *fp, *bar_window,
3343 and *part to the frame, window, and scroll bar part that the mouse
3344 is over. Set *x and *y to the portion and whole of the mouse's
3345 position on the scroll bar.
3347 If the mouse movement started elsewhere, set *fp to the frame the
3348 mouse is on, *bar_window to nil, and *x and *y to the character cell
3351 Set *time to the server time-stamp for the time at which the mouse
3352 was at this position.
3354 Don't store anything if we don't have a valid set of values to report.
3356 This clears the mouse_moved flag, so we can wait for the next mouse
3360 w32_mouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3361 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3362 unsigned long *time
)
3365 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
3369 if (dpyinfo
->last_mouse_scroll_bar
&& insist
== 0)
3370 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3375 Lisp_Object frame
, tail
;
3377 /* Clear the mouse-moved flag for every frame on this display. */
3378 FOR_EACH_FRAME (tail
, frame
)
3379 XFRAME (frame
)->mouse_moved
= 0;
3381 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3385 /* Now we have a position on the root; find the innermost window
3386 containing the pointer. */
3388 /* If mouse was grabbed on a frame, give coords for that
3389 frame even if the mouse is now outside it. Otherwise
3390 check for window under mouse on one of our frames. */
3391 f1
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
3392 : x_any_window_to_frame (dpyinfo
, WindowFromPoint (pt
)));
3394 /* If not, is it one of our scroll bars? */
3397 struct scroll_bar
*bar
3398 = x_window_to_scroll_bar (WindowFromPoint (pt
));
3402 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3406 if (f1
== 0 && insist
> 0)
3407 f1
= SELECTED_FRAME ();
3411 /* Ok, we found a frame. Store all the values.
3412 last_mouse_glyph is a rectangle used to reduce the
3413 generation of mouse events. To not miss any motion
3414 events, we must divide the frame into rectangles of the
3415 size of the smallest character that could be displayed
3416 on it, i.e. into the same rectangles that matrices on
3417 the frame are divided into. */
3419 dpyinfo
= FRAME_DISPLAY_INFO (f1
);
3420 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
3421 remember_mouse_glyph (f1
, pt
.x
, pt
.y
, &dpyinfo
->last_mouse_glyph
);
3422 dpyinfo
->last_mouse_glyph_frame
= f1
;
3429 *time
= dpyinfo
->last_mouse_movement_time
;
3438 /***********************************************************************
3440 ***********************************************************************/
3442 /* Handle mouse button event on the tool-bar of frame F, at
3443 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
3444 or ButtonRelease. */
3447 w32_handle_tool_bar_click (struct frame
*f
, struct input_event
*button_event
)
3449 int x
= XFASTINT (button_event
->x
);
3450 int y
= XFASTINT (button_event
->y
);
3452 if (button_event
->modifiers
& down_modifier
)
3453 handle_tool_bar_click (f
, x
, y
, 1, 0);
3455 handle_tool_bar_click (f
, x
, y
, 0,
3456 button_event
->modifiers
& ~up_modifier
);
3461 /***********************************************************************
3463 ***********************************************************************/
3465 /* Scroll bar support. */
3467 /* Given a window ID, find the struct scroll_bar which manages it.
3468 This can be called in GC, so we have to make sure to strip off mark
3471 static struct scroll_bar
*
3472 x_window_to_scroll_bar (Window window_id
)
3474 Lisp_Object tail
, frame
;
3476 FOR_EACH_FRAME (tail
, frame
)
3478 Lisp_Object bar
, condemned
;
3480 /* Scan this frame's scroll bar list for a scroll bar with the
3482 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3483 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3484 /* This trick allows us to search both the ordinary and
3485 condemned scroll bar lists with one loop. */
3486 ! NILP (bar
) || (bar
= condemned
,
3489 bar
= XSCROLL_BAR (bar
)->next
)
3490 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
3491 return XSCROLL_BAR (bar
);
3499 /* Set the thumb size and position of scroll bar BAR. We are currently
3500 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3503 w32_set_scroll_bar_thumb (struct scroll_bar
*bar
,
3504 int portion
, int position
, int whole
)
3506 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
3507 /* We use the whole scroll-bar height in the calculations below, to
3508 avoid strange effects like scrolling backwards when just clicking
3509 on the handle (without moving it). */
3510 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
))
3511 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3512 int sb_page
, sb_pos
;
3513 BOOL draggingp
= !NILP (bar
->dragging
) ? TRUE
: FALSE
;
3516 /* We used to change the nPage setting while dragging the handle,
3517 but that had very strange effects (such as scrolling backwards
3518 while dragging downwards).
3520 Now, we don't change the nPage setting while dragging unless we
3521 get near to the end of the buffer, in which case we often have to
3522 resize the handle to "go all the way". */
3528 si
.cbSize
= sizeof (si
);
3529 si
.fMask
= SIF_POS
| SIF_PAGE
;
3530 GetScrollInfo (w
, SB_CTL
, &si
);
3531 near_bottom_p
= si
.nPos
+ si
.nPage
>= range
;
3539 /* Position scroll bar at rock bottom if the bottom of the
3540 buffer is visible. This avoids shrinking the thumb away
3541 to nothing if it is held at the bottom of the buffer. */
3542 if (position
+ portion
>= whole
&& !draggingp
)
3544 sb_page
= range
* (whole
- position
) / whole
;
3549 sb_pos
= position
* range
/ whole
;
3550 sb_page
= (min (portion
, (whole
- position
)) * range
) / whole
;
3559 sb_page
= max (sb_page
, VERTICAL_SCROLL_BAR_MIN_HANDLE
);
3563 si
.cbSize
= sizeof (si
);
3564 si
.fMask
= SIF_PAGE
| SIF_POS
;
3568 SetScrollInfo (w
, SB_CTL
, &si
, TRUE
);
3574 /************************************************************************
3575 Scroll bars, general
3576 ************************************************************************/
3579 my_create_scrollbar (struct frame
* f
, struct scroll_bar
* bar
)
3581 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
3582 WM_EMACS_CREATESCROLLBAR
, (WPARAM
) f
,
3586 /*#define ATTACH_THREADS*/
3589 my_show_window (struct frame
*f
, HWND hwnd
, int how
)
3591 #ifndef ATTACH_THREADS
3592 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
3593 (WPARAM
) hwnd
, (LPARAM
) how
);
3595 return ShowWindow (hwnd
, how
);
3600 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
3601 int x
, int y
, int cx
, int cy
, UINT flags
)
3603 #ifndef ATTACH_THREADS
3605 pos
.hwndInsertAfter
= hwndAfter
;
3611 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
3613 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
3619 my_set_focus (struct frame
* f
, HWND hwnd
)
3621 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
3627 my_set_foreground_window (HWND hwnd
)
3629 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
3634 my_destroy_window (struct frame
* f
, HWND hwnd
)
3636 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
3641 my_bring_window_to_top (HWND hwnd
)
3643 SendMessage (hwnd
, WM_EMACS_BRINGTOTOP
, (WPARAM
) hwnd
, 0);
3646 /* Create a scroll bar and return the scroll bar vector for it. W is
3647 the Emacs window on which to create the scroll bar. TOP, LEFT,
3648 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
3651 static struct scroll_bar
*
3652 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
3654 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3657 struct scroll_bar
*bar
3658 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, fringe_extended_p
, PVEC_OTHER
);
3663 XSETWINDOW (bar
->window
, w
);
3664 XSETINT (bar
->top
, top
);
3665 XSETINT (bar
->left
, left
);
3666 XSETINT (bar
->width
, width
);
3667 XSETINT (bar
->height
, height
);
3668 XSETINT (bar
->start
, 0);
3669 XSETINT (bar
->end
, 0);
3670 bar
->dragging
= Qnil
;
3671 bar
->fringe_extended_p
= 0;
3673 /* Requires geometry to be set before call to create the real window */
3675 hwnd
= my_create_scrollbar (f
, bar
);
3677 si
.cbSize
= sizeof (si
);
3680 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3681 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3685 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3687 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
3689 /* Add bar to its frame's list of scroll bars. */
3690 bar
->next
= FRAME_SCROLL_BARS (f
);
3692 XSETVECTOR (barobj
, bar
);
3693 fset_scroll_bars (f
, barobj
);
3694 if (! NILP (bar
->next
))
3695 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3703 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
3707 x_scroll_bar_remove (struct scroll_bar
*bar
)
3709 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3713 /* Destroy the window. */
3714 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
3716 /* Dissociate this scroll bar from its window. */
3717 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
3722 /* Set the handle of the vertical scroll bar for WINDOW to indicate
3723 that we are displaying PORTION characters out of a total of WHOLE
3724 characters, starting at POSITION. If WINDOW has no scroll bar,
3727 w32_set_vertical_scroll_bar (struct window
*w
,
3728 int portion
, int whole
, int position
)
3730 struct frame
*f
= XFRAME (w
->frame
);
3732 struct scroll_bar
*bar
;
3733 int top
, height
, left
, sb_left
, width
, sb_width
;
3734 int window_y
, window_height
;
3735 bool fringe_extended_p
;
3737 /* Get window dimensions. */
3738 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
3740 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
3741 height
= window_height
;
3743 /* Compute the left edge of the scroll bar area. */
3744 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
3746 /* Compute the width of the scroll bar which might be less than
3747 the width of the area reserved for the scroll bar. */
3748 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
3749 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3753 /* Compute the left edge of the scroll bar. */
3754 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
3755 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
3757 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
3759 fringe_extended_p
= WINDOW_FRINGE_EXTENDED_P (w
);
3761 /* Does the scroll bar exist yet? */
3762 if (NILP (w
->vertical_scroll_bar
))
3766 if (width
> 0 && height
> 0)
3768 hdc
= get_frame_dc (f
);
3769 if (fringe_extended_p
)
3770 w32_clear_area (f
, hdc
, sb_left
, top
, sb_width
, height
);
3772 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3773 release_frame_dc (f
, hdc
);
3777 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
3781 /* It may just need to be moved and resized. */
3784 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
3785 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
3787 /* If already correctly positioned, do nothing. */
3788 if (XINT (bar
->left
) == sb_left
3789 && XINT (bar
->top
) == top
3790 && XINT (bar
->width
) == sb_width
3791 && XINT (bar
->height
) == height
3792 && bar
->fringe_extended_p
== fringe_extended_p
)
3794 /* Redraw after clear_frame. */
3795 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
3796 InvalidateRect (hwnd
, NULL
, FALSE
);
3804 if (width
&& height
)
3806 hdc
= get_frame_dc (f
);
3807 /* Since Windows scroll bars are smaller than the space reserved
3808 for them on the frame, we have to clear "under" them. */
3809 if (fringe_extended_p
)
3810 w32_clear_area (f
, hdc
, sb_left
, top
, sb_width
, height
);
3812 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3813 release_frame_dc (f
, hdc
);
3815 /* Make sure scroll bar is "visible" before moving, to ensure the
3816 area of the parent window now exposed will be refreshed. */
3817 my_show_window (f
, hwnd
, SW_HIDE
);
3818 MoveWindow (hwnd
, sb_left
, top
, sb_width
,
3819 max (height
, 1), TRUE
);
3821 si
.cbSize
= sizeof (si
);
3822 si
.fMask
= SIF_RANGE
;
3824 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3825 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3827 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3829 my_show_window (f
, hwnd
, SW_NORMAL
);
3830 /* InvalidateRect (w, NULL, FALSE); */
3832 /* Remember new settings. */
3833 XSETINT (bar
->left
, sb_left
);
3834 XSETINT (bar
->top
, top
);
3835 XSETINT (bar
->width
, sb_width
);
3836 XSETINT (bar
->height
, height
);
3841 bar
->fringe_extended_p
= fringe_extended_p
;
3843 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
3844 XSETVECTOR (barobj
, bar
);
3845 wset_vertical_scroll_bar (w
, barobj
);
3849 /* The following three hooks are used when we're doing a thorough
3850 redisplay of the frame. We don't explicitly know which scroll bars
3851 are going to be deleted, because keeping track of when windows go
3852 away is a real pain - "Can you say set-window-configuration, boys
3853 and girls?" Instead, we just assert at the beginning of redisplay
3854 that *all* scroll bars are to be removed, and then save a scroll bar
3855 from the fiery pit when we actually redisplay its window. */
3857 /* Arrange for all scroll bars on FRAME to be removed at the next call
3858 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
3859 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
3862 w32_condemn_scroll_bars (struct frame
*frame
)
3864 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
3865 while (! NILP (FRAME_SCROLL_BARS (frame
)))
3868 bar
= FRAME_SCROLL_BARS (frame
);
3869 fset_scroll_bars (frame
, XSCROLL_BAR (bar
)->next
);
3870 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
3871 XSCROLL_BAR (bar
)->prev
= Qnil
;
3872 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
3873 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
3874 fset_condemned_scroll_bars (frame
, bar
);
3879 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
3880 Note that WINDOW isn't necessarily condemned at all. */
3883 w32_redeem_scroll_bar (struct window
*window
)
3885 struct scroll_bar
*bar
;
3889 /* We can't redeem this window's scroll bar if it doesn't have one. */
3890 if (NILP (window
->vertical_scroll_bar
))
3893 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3895 /* Unlink it from the condemned list. */
3896 f
= XFRAME (WINDOW_FRAME (window
));
3897 if (NILP (bar
->prev
))
3899 /* If the prev pointer is nil, it must be the first in one of
3901 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
3902 /* It's not condemned. Everything's fine. */
3904 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
3905 window
->vertical_scroll_bar
))
3906 fset_condemned_scroll_bars (f
, bar
->next
);
3908 /* If its prev pointer is nil, it must be at the front of
3909 one or the other! */
3913 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
3915 if (! NILP (bar
->next
))
3916 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
3918 bar
->next
= FRAME_SCROLL_BARS (f
);
3920 XSETVECTOR (barobj
, bar
);
3921 fset_scroll_bars (f
, barobj
);
3922 if (! NILP (bar
->next
))
3923 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3926 /* Remove all scroll bars on FRAME that haven't been saved since the
3927 last call to `*condemn_scroll_bars_hook'. */
3930 w32_judge_scroll_bars (struct frame
*f
)
3932 Lisp_Object bar
, next
;
3934 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
3936 /* Clear out the condemned list now so we won't try to process any
3937 more events on the hapless scroll bars. */
3938 fset_condemned_scroll_bars (f
, Qnil
);
3940 for (; ! NILP (bar
); bar
= next
)
3942 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
3944 x_scroll_bar_remove (b
);
3947 b
->next
= b
->prev
= Qnil
;
3950 /* Now there should be no references to the condemned scroll bars,
3951 and they should get garbage-collected. */
3954 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
3955 is set to something other than NO_EVENT, it is enqueued.
3957 This may be called from a signal handler, so we have to ignore GC
3961 w32_scroll_bar_handle_click (struct scroll_bar
*bar
, W32Msg
*msg
,
3962 struct input_event
*emacs_event
)
3964 if (! WINDOWP (bar
->window
))
3967 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
3968 emacs_event
->code
= 0;
3969 /* not really meaningful to distinguish up/down */
3970 emacs_event
->modifiers
= msg
->dwModifiers
;
3971 emacs_event
->frame_or_window
= bar
->window
;
3972 emacs_event
->arg
= Qnil
;
3973 emacs_event
->timestamp
= msg
->msg
.time
;
3976 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3978 int dragging
= !NILP (bar
->dragging
);
3981 si
.cbSize
= sizeof (si
);
3984 GetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
3987 bar
->dragging
= Qnil
;
3988 FRAME_DISPLAY_INFO (f
)->last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
3990 switch (LOWORD (msg
->msg
.wParam
))
3993 emacs_event
->part
= scroll_bar_down_arrow
;
3996 emacs_event
->part
= scroll_bar_up_arrow
;
3999 emacs_event
->part
= scroll_bar_above_handle
;
4002 emacs_event
->part
= scroll_bar_below_handle
;
4005 emacs_event
->part
= scroll_bar_handle
;
4009 emacs_event
->part
= scroll_bar_handle
;
4013 case SB_THUMBPOSITION
:
4014 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
4015 y
= HIWORD (msg
->msg
.wParam
);
4017 emacs_event
->part
= scroll_bar_handle
;
4019 /* "Silently" update current position. */
4023 si
.cbSize
= sizeof (si
);
4026 /* Remember apparent position (we actually lag behind the real
4027 position, so don't set that directly). */
4028 last_scroll_bar_drag_pos
= y
;
4030 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
4034 /* If this is the end of a drag sequence, then reset the scroll
4035 handle size to normal and do a final redraw. Otherwise do
4040 int start
= XINT (bar
->start
);
4041 int end
= XINT (bar
->end
);
4043 si
.cbSize
= sizeof (si
);
4044 si
.fMask
= SIF_PAGE
| SIF_POS
;
4045 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4046 si
.nPos
= last_scroll_bar_drag_pos
;
4047 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
4051 emacs_event
->kind
= NO_EVENT
;
4055 XSETINT (emacs_event
->x
, y
);
4056 XSETINT (emacs_event
->y
, top_range
);
4062 /* Return information to the user about the current position of the mouse
4063 on the scroll bar. */
4066 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
4067 enum scroll_bar_part
*part
,
4068 Lisp_Object
*x
, Lisp_Object
*y
,
4069 unsigned long *time
)
4071 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
4072 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
4073 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
4074 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4076 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4082 *bar_window
= bar
->window
;
4084 si
.cbSize
= sizeof (si
);
4085 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
4087 GetScrollInfo (w
, SB_CTL
, &si
);
4089 top_range
= si
.nMax
- si
.nPage
+ 1;
4091 switch (LOWORD (dpyinfo
->last_mouse_scroll_bar_pos
))
4093 case SB_THUMBPOSITION
:
4095 *part
= scroll_bar_handle
;
4096 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
)) <= 0xffff)
4097 pos
= HIWORD (dpyinfo
->last_mouse_scroll_bar_pos
);
4100 *part
= scroll_bar_handle
;
4104 *part
= scroll_bar_handle
;
4109 XSETINT (*y
, top_range
);
4112 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4114 *time
= dpyinfo
->last_mouse_movement_time
;
4120 /* The screen has been cleared so we may have changed foreground or
4121 background colors, and the scroll bars may need to be redrawn.
4122 Clear out the scroll bars, and ask for expose events, so we can
4126 x_scroll_bar_clear (struct frame
*f
)
4130 /* We can have scroll bars even if this is 0,
4131 if we just turned off scroll bar mode.
4132 But in that case we should not clear them. */
4133 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4134 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
4135 bar
= XSCROLL_BAR (bar
)->next
)
4137 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
4138 HDC hdc
= GetDC (window
);
4141 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
4142 arranges to refresh the scroll bar if hidden. */
4143 my_show_window (f
, window
, SW_HIDE
);
4145 GetClientRect (window
, &rect
);
4146 select_palette (f
, hdc
);
4147 w32_clear_rect (f
, hdc
, &rect
);
4148 deselect_palette (f
, hdc
);
4150 ReleaseDC (window
, hdc
);
4155 /* The main W32 event-reading loop - w32_read_socket. */
4157 /* Record the last 100 characters stored
4158 to help debug the loss-of-chars-during-GC problem. */
4160 static int temp_index
;
4161 static short temp_buffer
[100];
4163 /* Temporarily store lead byte of DBCS input sequences. */
4164 static char dbcs_lead
= 0;
4166 /* Read events coming from the W32 shell.
4167 This routine is called by the SIGIO handler.
4168 We return as soon as there are no more events to be read.
4170 For an overview of how Emacs input works on MS-Windows, see the
4171 commentary before w32_msg_pump in w32fns.c.
4173 We return the number of characters stored into the buffer,
4174 thus pretending to be `read'.
4176 Some of these messages are reposted back to the message queue since the
4177 system calls the windows proc directly in a context where we cannot return
4178 the data nor can we guarantee the state we are in. So if we dispatch them
4179 we will get into an infinite loop. To prevent this from ever happening we
4180 will set a variable to indicate we are in the read_socket call and indicate
4181 which message we are processing since the windows proc gets called
4182 recursively with different messages by the system.
4186 w32_read_socket (struct terminal
*terminal
,
4187 struct input_event
*hold_quit
)
4190 int check_visibility
= 0;
4193 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4194 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
4199 /* So people can tell when we have read the available input. */
4200 input_signal_count
++;
4202 /* Process any incoming thread messages. */
4203 drain_message_queue ();
4205 /* TODO: ghostscript integration. */
4206 while (get_next_msg (&msg
, FALSE
))
4208 struct input_event inev
;
4211 /* DebPrint (("w32_read_socket: %s time:%u\n", */
4212 /* w32_name_of_message (msg.msg.message), */
4213 /* msg.msg.time)); */
4216 inev
.kind
= NO_EVENT
;
4219 switch (msg
.msg
.message
)
4221 case WM_EMACS_PAINT
:
4222 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4226 if (msg
.rect
.right
== msg
.rect
.left
||
4227 msg
.rect
.bottom
== msg
.rect
.top
)
4229 /* We may get paint messages even though the client
4230 area is clipped - these are not expose events. */
4231 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
4234 else if (FRAME_VISIBLE_P (f
) != 1)
4236 bool iconified
= FRAME_ICONIFIED_P (f
);
4238 /* Definitely not obscured, so mark as visible. */
4239 SET_FRAME_VISIBLE (f
, 1);
4240 SET_FRAME_ICONIFIED (f
, 0);
4241 SET_FRAME_GARBAGED (f
);
4242 if (!f
->output_data
.w32
->asked_for_visible
)
4243 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
4246 /* WM_PAINT serves as MapNotify as well, so report
4247 visibility changes properly. */
4250 inev
.kind
= DEICONIFY_EVENT
;
4251 XSETFRAME (inev
.frame_or_window
, f
);
4253 else if (!NILP (Vframe_list
) && !NILP (XCDR (Vframe_list
)))
4254 /* Force a redisplay sooner or later to update the
4255 frame titles in case this is the second frame. */
4256 record_asynch_buffer_change ();
4260 HDC hdc
= get_frame_dc (f
);
4262 /* Erase background again for safety. */
4263 w32_clear_rect (f
, hdc
, &msg
.rect
);
4264 release_frame_dc (f
, hdc
);
4268 msg
.rect
.right
- msg
.rect
.left
,
4269 msg
.rect
.bottom
- msg
.rect
.top
);
4274 case WM_INPUTLANGCHANGE
:
4275 /* Generate a language change event. */
4276 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4278 /* lParam contains the input language ID in its low 16 bits.
4279 Use it to update our record of the keyboard codepage. */
4280 w32_keyboard_codepage
= codepage_for_locale ((LCID
)(msg
.msg
.lParam
4285 inev
.kind
= LANGUAGE_CHANGE_EVENT
;
4286 XSETFRAME (inev
.frame_or_window
, f
);
4287 inev
.code
= w32_keyboard_codepage
;
4288 inev
.modifiers
= msg
.msg
.lParam
& 0xffff;
4294 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4296 if (f
&& !FRAME_ICONIFIED_P (f
))
4298 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4299 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4301 clear_mouse_face (hlinfo
);
4302 hlinfo
->mouse_face_hidden
= 1;
4305 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4307 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4308 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
4309 inev
.code
= msg
.msg
.wParam
;
4310 inev
.modifiers
= msg
.dwModifiers
;
4311 XSETFRAME (inev
.frame_or_window
, f
);
4312 inev
.timestamp
= msg
.msg
.time
;
4319 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4321 if (f
&& !FRAME_ICONIFIED_P (f
))
4323 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4324 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4326 clear_mouse_face (hlinfo
);
4327 hlinfo
->mouse_face_hidden
= 1;
4330 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4332 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4334 inev
.modifiers
= msg
.dwModifiers
;
4335 XSETFRAME (inev
.frame_or_window
, f
);
4336 inev
.timestamp
= msg
.msg
.time
;
4338 if (msg
.msg
.message
== WM_UNICHAR
)
4340 inev
.code
= msg
.msg
.wParam
;
4342 else if (msg
.msg
.wParam
< 256)
4347 dbcs
[1] = (char) msg
.msg
.wParam
;
4351 dbcs
[0] = dbcs_lead
;
4353 if (!MultiByteToWideChar (w32_keyboard_codepage
, 0,
4357 DebPrint (("Invalid DBCS sequence: %d %d\n",
4359 inev
.kind
= NO_EVENT
;
4363 else if (IsDBCSLeadByteEx (w32_keyboard_codepage
,
4364 (BYTE
) msg
.msg
.wParam
))
4366 dbcs_lead
= (char) msg
.msg
.wParam
;
4367 inev
.kind
= NO_EVENT
;
4372 if (!MultiByteToWideChar (w32_keyboard_codepage
, 0,
4373 &dbcs
[1], 1, &code
, 1))
4375 /* What to do with garbage? */
4376 DebPrint (("Invalid character: %d\n", dbcs
[1]));
4377 inev
.kind
= NO_EVENT
;
4385 /* Windows shouldn't generate WM_CHAR events above 0xFF
4386 in non-Unicode message handlers. */
4387 DebPrint (("Non-byte WM_CHAR: %d\n", msg
.msg
.wParam
));
4388 inev
.kind
= NO_EVENT
;
4391 inev
.kind
= inev
.code
< 128 ? ASCII_KEYSTROKE_EVENT
4392 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
4397 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4399 if (f
&& !FRAME_ICONIFIED_P (f
))
4401 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4402 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4404 clear_mouse_face (hlinfo
);
4405 hlinfo
->mouse_face_hidden
= 1;
4408 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4410 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4411 inev
.kind
= MULTIMEDIA_KEY_EVENT
;
4412 inev
.code
= GET_APPCOMMAND_LPARAM (msg
.msg
.lParam
);
4413 inev
.modifiers
= msg
.dwModifiers
;
4414 XSETFRAME (inev
.frame_or_window
, f
);
4415 inev
.timestamp
= msg
.msg
.time
;
4420 /* Ignore non-movement. */
4422 int x
= LOWORD (msg
.msg
.lParam
);
4423 int y
= HIWORD (msg
.msg
.lParam
);
4424 if (x
== last_mousemove_x
&& y
== last_mousemove_y
)
4426 last_mousemove_x
= x
;
4427 last_mousemove_y
= y
;
4430 previous_help_echo_string
= help_echo_string
;
4431 help_echo_string
= Qnil
;
4433 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4434 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4436 if (hlinfo
->mouse_face_hidden
)
4438 hlinfo
->mouse_face_hidden
= 0;
4439 clear_mouse_face (hlinfo
);
4444 /* Generate SELECT_WINDOW_EVENTs when needed. */
4445 if (!NILP (Vmouse_autoselect_window
))
4447 static Lisp_Object last_mouse_window
;
4448 Lisp_Object window
= window_from_coordinates
4449 (f
, LOWORD (msg
.msg
.lParam
), HIWORD (msg
.msg
.lParam
), 0, 0);
4451 /* Window will be selected only when it is not
4452 selected now and last mouse movement event was
4453 not in it. Minibuffer window will be selected
4454 only when it is active. */
4455 if (WINDOWP (window
)
4456 && !EQ (window
, last_mouse_window
)
4457 && !EQ (window
, selected_window
)
4458 /* For click-to-focus window managers
4459 create event iff we don't leave the
4461 && (focus_follows_mouse
4462 || (EQ (XWINDOW (window
)->frame
,
4463 XWINDOW (selected_window
)->frame
))))
4465 inev
.kind
= SELECT_WINDOW_EVENT
;
4466 inev
.frame_or_window
= window
;
4468 /* Remember the last window where we saw the mouse. */
4469 last_mouse_window
= window
;
4471 if (!note_mouse_movement (f
, &msg
.msg
))
4472 help_echo_string
= previous_help_echo_string
;
4476 /* If we move outside the frame, then we're
4477 certainly no longer on any text in the frame. */
4478 clear_mouse_face (hlinfo
);
4481 /* If the contents of the global variable help_echo_string
4482 has changed, generate a HELP_EVENT. */
4483 #if 0 /* The below is an invalid comparison when CHECK_LISP_OBJECT_TYPE.
4484 But it was originally changed to this to fix a bug, so I have
4485 not removed it completely in case the bug is still there. */
4486 if (help_echo_string
!= previous_help_echo_string
||
4487 (!NILP (help_echo_string
) && !STRINGP (help_echo_string
) && f
->mouse_moved
))
4488 #else /* This is what xterm.c does. */
4489 if (!NILP (help_echo_string
)
4490 || !NILP (previous_help_echo_string
))
4495 case WM_LBUTTONDOWN
:
4497 case WM_MBUTTONDOWN
:
4499 case WM_RBUTTONDOWN
:
4501 case WM_XBUTTONDOWN
:
4504 /* If we decide we want to generate an event to be seen
4505 by the rest of Emacs, we put it here. */
4506 bool tool_bar_p
= 0;
4510 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4511 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4515 construct_mouse_click (&inev
, &msg
, f
);
4517 /* Is this in the tool-bar? */
4518 if (WINDOWP (f
->tool_bar_window
)
4519 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
4522 int x
= XFASTINT (inev
.x
);
4523 int y
= XFASTINT (inev
.y
);
4525 window
= window_from_coordinates (f
, x
, y
, 0, 1);
4527 if (EQ (window
, f
->tool_bar_window
))
4529 w32_handle_tool_bar_click (f
, &inev
);
4535 || (dpyinfo
->w32_focus_frame
4536 && f
!= dpyinfo
->w32_focus_frame
))
4537 inev
.kind
= NO_EVENT
;
4540 parse_button (msg
.msg
.message
, HIWORD (msg
.msg
.wParam
),
4545 dpyinfo
->grabbed
&= ~ (1 << button
);
4549 dpyinfo
->grabbed
|= (1 << button
);
4550 dpyinfo
->last_mouse_frame
= f
;
4551 /* Ignore any mouse motion that happened
4552 before this event; any subsequent mouse-movement
4553 Emacs events should reflect only motion after
4559 last_tool_bar_item
= -1;
4565 case WM_MOUSEHWHEEL
:
4567 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4568 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4573 if (!dpyinfo
->w32_focus_frame
4574 || f
== dpyinfo
->w32_focus_frame
)
4576 /* Emit an Emacs wheel-up/down event. */
4577 construct_mouse_wheel (&inev
, &msg
, f
);
4579 /* Ignore any mouse motion that happened before this
4580 event; any subsequent mouse-movement Emacs events
4581 should reflect only motion after the
4585 dpyinfo
->last_mouse_frame
= f
;
4586 last_tool_bar_item
= -1;
4591 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4594 construct_drag_n_drop (&inev
, &msg
, f
);
4599 struct scroll_bar
*bar
=
4600 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
);
4603 w32_scroll_bar_handle_click (bar
, &msg
, &inev
);
4607 case WM_WINDOWPOSCHANGED
:
4609 case WM_ACTIVATEAPP
:
4610 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4613 /* Run the full-screen hook function also when we are
4614 being activated, to actually install the required
4615 size in effect, if the WAIT flag is set. This is
4616 because when the hook is run from x_set_fullscreen,
4617 the frame might not yet be visible, if that call is a
4618 result of make-frame, and in that case the hook just
4619 sets the WAIT flag. */
4620 if ((msg
.msg
.message
== WM_WINDOWPOSCHANGED
|| msg
.msg
.wParam
)
4621 && (f
->want_fullscreen
& FULLSCREEN_WAIT
))
4622 w32fullscreen_hook (f
);
4623 x_check_fullscreen (f
);
4625 check_visibility
= 1;
4629 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4631 if (f
&& !FRAME_ICONIFIED_P (f
))
4632 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
4634 check_visibility
= 1;
4638 /* wParam non-zero means Window is about to be shown, 0 means
4639 about to be hidden. */
4640 /* Redo the mouse-highlight after the tooltip has gone. */
4641 if (!msg
.msg
.wParam
&& msg
.msg
.hwnd
== tip_window
)
4644 x_redo_mouse_highlight (dpyinfo
);
4647 /* If window has been obscured or exposed by another window
4648 being maximized or minimized/restored, then recheck
4649 visibility of all frames. Direct changes to our own
4650 windows get handled by WM_SIZE. */
4652 if (msg
.msg
.lParam
!= 0)
4653 check_visibility
= 1;
4656 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4657 f
->async_visible
= msg
.msg
.wParam
;
4661 check_visibility
= 1;
4665 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4667 /* Inform lisp of whether frame has been iconified etc. */
4670 switch (msg
.msg
.wParam
)
4672 case SIZE_MINIMIZED
:
4673 SET_FRAME_VISIBLE (f
, 0);
4674 SET_FRAME_ICONIFIED (f
, 1);
4676 inev
.kind
= ICONIFY_EVENT
;
4677 XSETFRAME (inev
.frame_or_window
, f
);
4680 case SIZE_MAXIMIZED
:
4683 bool iconified
= FRAME_ICONIFIED_P (f
);
4686 SET_FRAME_VISIBLE (f
, 1);
4687 SET_FRAME_ICONIFIED (f
, 0);
4689 /* wait_reading_process_output will notice this
4690 and update the frame's display structures. */
4691 SET_FRAME_GARBAGED (f
);
4695 /* Reset top and left positions of the Window
4696 here since Windows sends a WM_MOVE message
4697 BEFORE telling us the Window is minimized
4698 when the Window is iconified, with 3000,3000
4700 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
4702 inev
.kind
= DEICONIFY_EVENT
;
4703 XSETFRAME (inev
.frame_or_window
, f
);
4705 else if (! NILP (Vframe_list
)
4706 && ! NILP (XCDR (Vframe_list
)))
4707 /* Force a redisplay sooner or later
4708 to update the frame titles
4709 in case this is the second frame. */
4710 record_asynch_buffer_change ();
4716 if (f
&& !FRAME_ICONIFIED_P (f
) && msg
.msg
.wParam
!= SIZE_MINIMIZED
)
4724 GetClientRect (msg
.msg
.hwnd
, &rect
);
4726 height
= rect
.bottom
- rect
.top
;
4727 width
= rect
.right
- rect
.left
;
4729 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
4730 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
4732 /* TODO: Clip size to the screen dimensions. */
4734 /* Even if the number of character rows and columns has
4735 not changed, the font size may have changed, so we need
4736 to check the pixel dimensions as well. */
4738 if (columns
!= FRAME_COLS (f
)
4739 || rows
!= FRAME_LINES (f
)
4740 || width
!= FRAME_PIXEL_WIDTH (f
)
4741 || height
!= FRAME_PIXEL_HEIGHT (f
))
4743 change_frame_size (f
, rows
, columns
, 0, 1, 0);
4744 SET_FRAME_GARBAGED (f
);
4745 cancel_mouse_face (f
);
4746 FRAME_PIXEL_WIDTH (f
) = width
;
4747 FRAME_PIXEL_HEIGHT (f
) = height
;
4748 f
->win_gravity
= NorthWestGravity
;
4752 check_visibility
= 1;
4756 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4759 if (f
== hlinfo
->mouse_face_mouse_frame
)
4761 /* If we move outside the frame, then we're
4762 certainly no longer on any text in the frame. */
4763 clear_mouse_face (hlinfo
);
4764 hlinfo
->mouse_face_mouse_frame
= 0;
4767 /* Generate a nil HELP_EVENT to cancel a help-echo.
4768 Do it only if there's something to cancel.
4769 Otherwise, the startup message is cleared when
4770 the mouse leaves the frame. */
4771 if (any_help_event_p
)
4777 w32_detect_focus_change (dpyinfo
, &msg
, &inev
);
4779 dpyinfo
->grabbed
= 0;
4780 check_visibility
= 1;
4784 w32_detect_focus_change (dpyinfo
, &msg
, &inev
);
4785 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4789 if (f
== hlinfo
->mouse_face_mouse_frame
)
4791 /* If we move outside the frame, then we're
4792 certainly no longer on any text in the frame. */
4793 clear_mouse_face (hlinfo
);
4794 hlinfo
->mouse_face_mouse_frame
= 0;
4797 /* Generate a nil HELP_EVENT to cancel a help-echo.
4798 Do it only if there's something to cancel.
4799 Otherwise, the startup message is cleared when
4800 the mouse leaves the frame. */
4801 if (any_help_event_p
)
4805 dpyinfo
->grabbed
= 0;
4806 check_visibility
= 1;
4810 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4814 inev
.kind
= DELETE_WINDOW_EVENT
;
4815 XSETFRAME (inev
.frame_or_window
, f
);
4820 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4824 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
4825 XSETFRAME (inev
.frame_or_window
, f
);
4830 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4834 extern void menubar_selection_callback
4835 (struct frame
*f
, void * client_data
);
4836 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
4839 check_visibility
= 1;
4842 case WM_DISPLAYCHANGE
:
4843 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4847 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
4848 DebPrint (("display change: %d %d\n",
4849 (short) LOWORD (msg
.msg
.lParam
),
4850 (short) HIWORD (msg
.msg
.lParam
)));
4853 check_visibility
= 1;
4857 case WM_EMACS_FILENOTIFY
:
4858 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4860 queue_notifications (&inev
, &msg
, f
, &count
);
4865 /* Check for messages registered at runtime. */
4866 if (msg
.msg
.message
== msh_mousewheel
)
4868 /* Forward MSH_MOUSEWHEEL as WM_MOUSEWHEEL. */
4869 msg
.msg
.message
= WM_MOUSEWHEEL
;
4875 if (inev
.kind
!= NO_EVENT
)
4877 kbd_buffer_store_event_hold (&inev
, hold_quit
);
4882 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
4887 XSETFRAME (frame
, f
);
4893 if (NILP (help_echo_string
))
4895 help_echo_object
= help_echo_window
= Qnil
;
4899 any_help_event_p
= 1;
4900 gen_help_event (help_echo_string
, frame
, help_echo_window
,
4901 help_echo_object
, help_echo_pos
);
4905 help_echo_string
= Qnil
;
4906 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
4912 /* If the focus was just given to an autoraising frame,
4913 raise it now. FIXME: handle more than one such frame. */
4914 if (dpyinfo
->w32_pending_autoraise_frame
)
4916 x_raise_frame (dpyinfo
->w32_pending_autoraise_frame
);
4917 dpyinfo
->w32_pending_autoraise_frame
= NULL
;
4920 /* Check which frames are still visible, if we have enqueued any user
4921 events or been notified of events that may affect visibility. We
4922 do this here because there doesn't seem to be any direct
4923 notification from Windows that the visibility of a window has
4924 changed (at least, not in all cases). */
4925 if (count
> 0 || check_visibility
)
4927 Lisp_Object tail
, frame
;
4929 FOR_EACH_FRAME (tail
, frame
)
4931 struct frame
*f
= XFRAME (frame
);
4932 /* The tooltip has been drawn already. Avoid the
4933 SET_FRAME_GARBAGED below. */
4934 if (EQ (frame
, tip_frame
))
4937 /* Check "visible" frames and mark each as obscured or not.
4938 Note that visible is nonzero for unobscured and obscured
4939 frames, but zero for hidden and iconified frames. */
4940 if (FRAME_W32_P (f
) && FRAME_VISIBLE_P (f
))
4947 /* Query clipping rectangle for the entire window area
4948 (GetWindowDC), not just the client portion (GetDC).
4949 Otherwise, the scrollbars and menubar aren't counted as
4950 part of the visible area of the frame, and we may think
4951 the frame is obscured when really a scrollbar is still
4952 visible and gets WM_PAINT messages above. */
4953 hdc
= GetWindowDC (FRAME_W32_WINDOW (f
));
4954 GetClipBox (hdc
, &clipbox
);
4955 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
4958 obscured
= FRAME_OBSCURED_P (f
);
4960 if (clipbox
.right
== clipbox
.left
|| clipbox
.bottom
== clipbox
.top
)
4962 /* Frame has become completely obscured so mark as such (we
4963 do this by setting visible to 2 so that FRAME_VISIBLE_P
4964 is still true, but redisplay will skip it). */
4965 SET_FRAME_VISIBLE (f
, 2);
4968 DebPrint (("frame %p (%s) obscured\n", f
, SDATA (f
->name
)));
4972 /* Frame is not obscured, so mark it as such. */
4973 SET_FRAME_VISIBLE (f
, 1);
4977 SET_FRAME_GARBAGED (f
);
4978 DebPrint (("obscured frame %p (%s) found to be visible\n",
4979 f
, SDATA (f
->name
)));
4981 /* Force a redisplay sooner or later. */
4982 record_asynch_buffer_change ();
4995 /***********************************************************************
4997 ***********************************************************************/
4999 /* Set clipping for output in glyph row ROW. W is the window in which
5000 we operate. GC is the graphics context to set clipping in.
5002 ROW may be a text row or, e.g., a mode line. Text rows must be
5003 clipped to the interior of the window dedicated to text display,
5004 mode lines must be clipped to the whole window. */
5007 w32_clip_to_row (struct window
*w
, struct glyph_row
*row
,
5008 enum glyph_row_area area
, HDC hdc
)
5011 int window_x
, window_y
, window_width
;
5013 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
5015 clip_rect
.left
= window_x
;
5016 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5017 clip_rect
.top
= max (clip_rect
.top
, window_y
);
5018 clip_rect
.right
= clip_rect
.left
+ window_width
;
5019 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
5021 w32_set_clip_rectangle (hdc
, &clip_rect
);
5025 /* Draw a hollow box cursor on window W in glyph row ROW. */
5028 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
5030 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5034 struct glyph
*cursor_glyph
;
5035 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
5037 /* Get the glyph the cursor is on. If we can't tell because
5038 the current matrix is invalid or such, give up. */
5039 cursor_glyph
= get_phys_cursor_glyph (w
);
5040 if (cursor_glyph
== NULL
)
5046 /* Compute frame-relative coordinates for phys cursor. */
5047 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &left
, &top
, &h
);
5050 rect
.bottom
= rect
.top
+ h
;
5051 rect
.right
= rect
.left
+ w
->phys_cursor_width
;
5053 hdc
= get_frame_dc (f
);
5054 /* Set clipping, draw the rectangle, and reset clipping again. */
5055 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
5056 FrameRect (hdc
, &rect
, hb
);
5058 w32_set_clip_rectangle (hdc
, NULL
);
5059 release_frame_dc (f
, hdc
);
5063 /* Draw a bar cursor on window W in glyph row ROW.
5065 Implementation note: One would like to draw a bar cursor with an
5066 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5067 Unfortunately, I didn't find a font yet that has this property set.
5071 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
,
5072 int width
, enum text_cursor_kinds kind
)
5074 struct frame
*f
= XFRAME (w
->frame
);
5075 struct glyph
*cursor_glyph
;
5077 /* If cursor is out of bounds, don't draw garbage. This can happen
5078 in mini-buffer windows when switching between echo area glyphs
5080 cursor_glyph
= get_phys_cursor_glyph (w
);
5081 if (cursor_glyph
== NULL
)
5084 /* If on an image, draw like a normal cursor. That's usually better
5085 visible than drawing a bar, esp. if the image is large so that
5086 the bar might not be in the window. */
5087 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5089 struct glyph_row
*row
;
5090 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5091 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5095 COLORREF cursor_color
= f
->output_data
.w32
->cursor_pixel
;
5096 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5100 /* If the glyph's background equals the color we normally draw
5101 the bar cursor in, the bar cursor in its normal color is
5102 invisible. Use the glyph's foreground color instead in this
5103 case, on the assumption that the glyph's colors are chosen so
5104 that the glyph is legible. */
5105 if (face
->background
== cursor_color
)
5106 cursor_color
= face
->foreground
;
5108 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5110 hdc
= get_frame_dc (f
);
5111 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
5113 if (kind
== BAR_CURSOR
)
5116 width
= FRAME_CURSOR_WIDTH (f
);
5117 width
= min (cursor_glyph
->pixel_width
, width
);
5119 w
->phys_cursor_width
= width
;
5121 /* If the character under cursor is R2L, draw the bar cursor
5122 on the right of its glyph, rather than on the left. */
5123 if ((cursor_glyph
->resolved_level
& 1) != 0)
5124 x
+= cursor_glyph
->pixel_width
- width
;
5126 w32_fill_area (f
, hdc
, cursor_color
, x
,
5127 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5128 width
, row
->height
);
5132 int dummy_x
, dummy_y
, dummy_h
;
5135 width
= row
->height
;
5137 width
= min (row
->height
, width
);
5139 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
5140 &dummy_y
, &dummy_h
);
5141 w32_fill_area (f
, hdc
, cursor_color
, x
,
5142 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5143 row
->height
- width
),
5144 w
->phys_cursor_width
, width
);
5147 w32_set_clip_rectangle (hdc
, NULL
);
5148 release_frame_dc (f
, hdc
);
5153 /* RIF: Define cursor CURSOR on frame F. */
5156 w32_define_frame_cursor (struct frame
*f
, Cursor cursor
)
5158 w32_define_cursor (FRAME_W32_WINDOW (f
), cursor
);
5162 /* RIF: Clear area on frame F. */
5165 w32_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
5169 hdc
= get_frame_dc (f
);
5170 w32_clear_area (f
, hdc
, x
, y
, width
, height
);
5171 release_frame_dc (f
, hdc
);
5174 /* RIF: Draw or clear cursor on window W. */
5177 w32_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
,
5178 int x
, int y
, enum text_cursor_kinds cursor_type
,
5179 int cursor_width
, bool on_p
, bool active_p
)
5183 /* If the user wants to use the system caret, make sure our own
5184 cursor remains invisible. */
5185 if (w32_use_visible_system_caret
)
5187 /* Call to erase_phys_cursor here seems to use the
5188 wrong values of w->phys_cursor, as they have been
5189 overwritten before this function was called. */
5190 if (w
->phys_cursor_type
!= NO_CURSOR
)
5191 erase_phys_cursor (w
);
5193 cursor_type
= w
->phys_cursor_type
= NO_CURSOR
;
5194 w
->phys_cursor_width
= -1;
5198 w
->phys_cursor_type
= cursor_type
;
5201 w
->phys_cursor_on_p
= 1;
5203 /* If this is the active cursor, we need to track it with the
5204 system caret, so third party software like screen magnifiers
5205 and speech synthesizers can follow the cursor. */
5208 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5209 HWND hwnd
= FRAME_W32_WINDOW (f
);
5212 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5214 = (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
5215 + glyph_row
->ascent
- w
->phys_cursor_ascent
);
5216 w32_system_caret_window
= w
;
5217 w32_system_caret_hdr_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
5218 w32_system_caret_mode_height
= WINDOW_MODE_LINE_HEIGHT (w
);
5220 PostMessage (hwnd
, WM_IME_STARTCOMPOSITION
, 0, 0);
5222 /* If the size of the active cursor changed, destroy the old
5224 if (w32_system_caret_hwnd
5225 && (w32_system_caret_height
!= w
->phys_cursor_height
))
5226 PostMessage (hwnd
, WM_EMACS_DESTROY_CARET
, 0, 0);
5228 w32_system_caret_height
= w
->phys_cursor_height
;
5230 /* Move the system caret. */
5231 PostMessage (hwnd
, WM_EMACS_TRACK_CARET
, 0, 0);
5234 if (glyph_row
->exact_window_width_line_p
5235 && (glyph_row
->reversed_p
5236 ? (w
->phys_cursor
.hpos
< 0)
5237 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
5239 glyph_row
->cursor_in_fringe_p
= 1;
5240 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
5244 switch (cursor_type
)
5246 case HOLLOW_BOX_CURSOR
:
5247 x_draw_hollow_cursor (w
, glyph_row
);
5250 case FILLED_BOX_CURSOR
:
5251 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5255 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5259 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5263 w
->phys_cursor_width
= 0;
5277 x_bitmap_icon (struct frame
*f
, Lisp_Object icon
)
5280 HANDLE small_icon
= NULL
;
5282 if (FRAME_W32_WINDOW (f
) == 0)
5286 main_icon
= LoadIcon (hinst
, EMACS_CLASS
);
5287 else if (STRINGP (icon
))
5289 /* Load the main icon from the named file. */
5290 main_icon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5291 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5292 /* Try to load a small icon to go with it. */
5293 small_icon
= LoadImage (NULL
, (LPCSTR
) SDATA (icon
), IMAGE_ICON
,
5294 GetSystemMetrics (SM_CXSMICON
),
5295 GetSystemMetrics (SM_CYSMICON
),
5298 else if (SYMBOLP (icon
))
5302 if (EQ (icon
, intern ("application")))
5303 name
= (LPCTSTR
) IDI_APPLICATION
;
5304 else if (EQ (icon
, intern ("hand")))
5305 name
= (LPCTSTR
) IDI_HAND
;
5306 else if (EQ (icon
, intern ("question")))
5307 name
= (LPCTSTR
) IDI_QUESTION
;
5308 else if (EQ (icon
, intern ("exclamation")))
5309 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5310 else if (EQ (icon
, intern ("asterisk")))
5311 name
= (LPCTSTR
) IDI_ASTERISK
;
5312 else if (EQ (icon
, intern ("winlogo")))
5313 name
= (LPCTSTR
) IDI_WINLOGO
;
5317 main_icon
= LoadIcon (NULL
, name
);
5322 if (main_icon
== NULL
)
5325 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5326 (LPARAM
) main_icon
);
5328 /* If there is a small icon that goes with it, set that too. */
5330 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_SMALL
,
5331 (LPARAM
) small_icon
);
5337 /************************************************************************
5339 ************************************************************************/
5341 /* Display Error Handling functions not used on W32. Listing them here
5342 helps diff stay in step when comparing w32term.c with xterm.c.
5344 x_error_catcher (display, error)
5345 x_catch_errors (dpy)
5346 x_catch_errors_unwind (old_val)
5347 x_check_errors (dpy, format)
5348 x_fully_uncatch_errors ()
5349 x_had_errors_p (dpy)
5350 x_clear_errors (dpy)
5351 x_uncatch_errors (dpy, count)
5353 x_connection_signal (signalnum)
5354 x_connection_closed (dpy, error_message)
5355 x_error_quitter (display, error)
5356 x_error_handler (display, error)
5357 x_io_error_quitter (display)
5362 /* Changing the font of the frame. */
5365 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
5367 struct font
*font
= XFONT_OBJECT (font_object
);
5370 fontset
= fontset_from_font (font_object
);
5371 FRAME_FONTSET (f
) = fontset
;
5372 if (FRAME_FONT (f
) == font
)
5373 /* This font is already set in frame F. There's nothing more to
5377 FRAME_FONT (f
) = font
;
5378 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
5379 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
5380 FRAME_LINE_HEIGHT (f
) = font
->height
;
5382 compute_fringe_widths (f
, 1);
5384 /* Compute the scroll bar width in character columns. */
5385 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5387 int wid
= FRAME_COLUMN_WIDTH (f
);
5388 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5389 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
- 1) / wid
;
5393 int wid
= FRAME_COLUMN_WIDTH (f
);
5394 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
5397 /* Now make the frame display the given font. */
5398 if (FRAME_X_WINDOW (f
) != 0)
5400 /* Don't change the size of a tip frame; there's no point in
5401 doing it because it's done in Fx_show_tip, and it leads to
5402 problems because the tip frame has no widget. */
5403 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5404 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
5407 /* X version sets font of input methods here also. */
5413 /***********************************************************************
5414 TODO: W32 Input Methods
5415 ***********************************************************************/
5416 /* Listing missing functions from xterm.c helps diff stay in step.
5418 xim_destroy_callback (xim, client_data, call_data)
5419 xim_open_dpy (dpyinfo, resource_name)
5421 xim_instantiate_callback (display, client_data, call_data)
5422 xim_initialize (dpyinfo, resource_name)
5423 xim_close_dpy (dpyinfo)
5428 /* Calculate the absolute position in frame F
5429 from its current recorded position values and gravity. */
5432 x_calc_absolute_position (struct frame
*f
)
5434 int flags
= f
->size_hint_flags
;
5436 /* The sum of the widths of the frame's left and right borders, and
5437 the sum of the heights of the frame's top and bottom borders (in
5438 pixels) drawn by Windows. */
5439 unsigned int left_right_borders_width
, top_bottom_borders_height
;
5441 /* Try to get the actual values of these two variables. We compute
5442 the border width (height) by subtracting the width (height) of
5443 the frame's client area from the width (height) of the frame's
5445 WINDOWPLACEMENT wp
= { 0 };
5446 RECT client_rect
= { 0 };
5448 if (GetWindowPlacement (FRAME_W32_WINDOW (f
), &wp
)
5449 && GetClientRect (FRAME_W32_WINDOW (f
), &client_rect
))
5451 left_right_borders_width
=
5452 (wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
) -
5453 (client_rect
.right
- client_rect
.left
);
5455 top_bottom_borders_height
=
5456 (wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
) -
5457 (client_rect
.bottom
- client_rect
.top
);
5461 /* Use sensible default values. */
5462 left_right_borders_width
= 8;
5463 top_bottom_borders_height
= 32;
5466 /* Treat negative positions as relative to the rightmost bottommost
5467 position that fits on the screen. */
5468 if (flags
& XNegative
)
5469 f
->left_pos
= (x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
5470 - FRAME_PIXEL_WIDTH (f
)
5472 - (left_right_borders_width
- 1));
5474 if (flags
& YNegative
)
5475 f
->top_pos
= (x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
5476 - FRAME_PIXEL_HEIGHT (f
)
5478 - (top_bottom_borders_height
- 1));
5480 /* The left_pos and top_pos are now relative to the top and left
5481 screen edges, so the flags should correspond. */
5482 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5485 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5486 to really change the position, and 0 when calling from
5487 x_make_frame_visible (in that case, XOFF and YOFF are the current
5488 position values). It is -1 when calling from x_set_frame_parameters,
5489 which means, do adjust for borders but don't change the gravity. */
5492 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
,
5495 int modified_top
, modified_left
;
5497 if (change_gravity
> 0)
5501 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5503 f
->size_hint_flags
|= XNegative
;
5505 f
->size_hint_flags
|= YNegative
;
5506 f
->win_gravity
= NorthWestGravity
;
5508 x_calc_absolute_position (f
);
5511 x_wm_set_size_hint (f
, (long) 0, 0);
5513 modified_left
= f
->left_pos
;
5514 modified_top
= f
->top_pos
;
5516 my_set_window_pos (FRAME_W32_WINDOW (f
),
5518 modified_left
, modified_top
,
5520 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5525 /* Check if we need to resize the frame due to a fullscreen request.
5526 If so needed, resize the frame. */
5528 x_check_fullscreen (struct frame
*f
)
5530 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
5532 int width
, height
, ign
;
5534 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5536 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
5538 /* We do not need to move the window, it shall be taken care of
5539 when setting WM manager hints. */
5540 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
5542 change_frame_size (f
, height
, width
, 0, 1, 0);
5543 SET_FRAME_GARBAGED (f
);
5544 cancel_mouse_face (f
);
5546 /* Wait for the change of frame size to occur. */
5547 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
5553 w32fullscreen_hook (struct frame
*f
)
5555 if (FRAME_VISIBLE_P (f
))
5557 HWND hwnd
= FRAME_W32_WINDOW(f
);
5558 DWORD dwStyle
= GetWindowLong (hwnd
, GWL_STYLE
);
5562 f
->want_fullscreen
&= ~FULLSCREEN_WAIT
;
5564 if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_NONE
)
5565 GetWindowPlacement (hwnd
, &FRAME_NORMAL_PLACEMENT (f
));
5567 if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_BOTH
)
5569 SetWindowLong (hwnd
, GWL_STYLE
, dwStyle
| WS_OVERLAPPEDWINDOW
);
5570 SetWindowPos (hwnd
, NULL
, 0, 0, 0, 0,
5571 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
5572 SWP_NOOWNERZORDER
| SWP_FRAMECHANGED
);
5575 w32_fullscreen_rect (hwnd
, f
->want_fullscreen
,
5576 FRAME_NORMAL_PLACEMENT (f
).rcNormalPosition
, &rect
);
5577 FRAME_PREV_FSMODE (f
) = f
->want_fullscreen
;
5578 if (f
->want_fullscreen
== FULLSCREEN_MAXIMIZED
)
5579 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, 0xf030, 0);
5580 else if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
5582 SetWindowLong (hwnd
, GWL_STYLE
, dwStyle
& ~WS_OVERLAPPEDWINDOW
);
5583 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
5584 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
5585 SWP_NOOWNERZORDER
| SWP_FRAMECHANGED
);
5589 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
5590 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 0);
5593 f
->want_fullscreen
= FULLSCREEN_NONE
;
5597 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
5600 /* Call this to change the size of frame F's x-window.
5601 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5602 for this size change and subsequent size changes.
5603 Otherwise we leave the window gravity unchanged. */
5606 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
5608 int pixelwidth
, pixelheight
;
5612 check_frame_size (f
, &rows
, &cols
);
5613 f
->scroll_bar_actual_width
5614 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
5616 compute_fringe_widths (f
, 0);
5618 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
5619 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
5621 f
->win_gravity
= NorthWestGravity
;
5622 x_wm_set_size_hint (f
, (long) 0, 0);
5627 rect
.left
= rect
.top
= 0;
5628 rect
.right
= pixelwidth
;
5629 rect
.bottom
= pixelheight
;
5631 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5632 FRAME_EXTERNAL_MENU_BAR (f
));
5634 my_set_window_pos (FRAME_W32_WINDOW (f
),
5637 rect
.right
- rect
.left
,
5638 rect
.bottom
- rect
.top
,
5639 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
5643 /* The following mirrors what is done in xterm.c. It appears to be
5644 for informing lisp of the new size immediately, while the actual
5645 resize will happen asynchronously. But on Windows, the menu bar
5646 automatically wraps when the frame is too narrow to contain it,
5647 and that causes any calculations made here to come out wrong. The
5648 end is some nasty buggy behavior, including the potential loss
5651 Disabling this code is either not sufficient to fix the problems
5652 completely, or it causes fresh problems, but at least it removes
5653 the most problematic symptom of the minibuffer becoming unusable.
5655 -----------------------------------------------------------------
5657 Now, strictly speaking, we can't be sure that this is accurate,
5658 but the window manager will get around to dealing with the size
5659 change request eventually, and we'll hear how it went when the
5660 ConfigureNotify event gets here.
5662 We could just not bother storing any of this information here,
5663 and let the ConfigureNotify event set everything up, but that
5664 might be kind of confusing to the Lisp code, since size changes
5665 wouldn't be reported in the frame parameters until some random
5666 point in the future when the ConfigureNotify event arrives.
5668 We pass 1 for DELAY since we can't run Lisp code inside of
5670 change_frame_size (f
, rows
, cols
, 0, 1, 0);
5671 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
5672 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
5674 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5675 receive in the ConfigureNotify event; if we get what we asked
5676 for, then the event won't cause the screen to become garbaged, so
5677 we have to make sure to do it here. */
5678 SET_FRAME_GARBAGED (f
);
5680 /* If cursor was outside the new size, mark it as off. */
5681 mark_window_cursors_off (XWINDOW (f
->root_window
));
5683 /* Clear out any recollection of where the mouse highlighting was,
5684 since it might be in a place that's outside the new frame size.
5685 Actually checking whether it is outside is a pain in the neck,
5686 so don't try--just let the highlighting be done afresh with new size. */
5687 cancel_mouse_face (f
);
5693 /* Mouse warping. */
5695 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
5698 x_set_mouse_position (struct frame
*f
, int x
, int y
)
5702 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
5703 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
5705 if (pix_x
< 0) pix_x
= 0;
5706 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
5708 if (pix_y
< 0) pix_y
= 0;
5709 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
5711 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
5715 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
5722 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
5723 pt
.x
= rect
.left
+ pix_x
;
5724 pt
.y
= rect
.top
+ pix_y
;
5725 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
5727 SetCursorPos (pt
.x
, pt
.y
);
5733 /* focus shifting, raising and lowering. */
5736 x_focus_frame (struct frame
*f
)
5738 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
5740 /* Give input focus to frame. */
5743 /* Try not to change its Z-order if possible. */
5744 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
5745 my_set_focus (f
, FRAME_W32_WINDOW (f
));
5748 my_set_foreground_window (FRAME_W32_WINDOW (f
));
5752 /* Raise frame F. */
5754 x_raise_frame (struct frame
*f
)
5758 /* Strictly speaking, raise-frame should only change the frame's Z
5759 order, leaving input focus unchanged. This is reasonable behavior
5760 on X where the usual policy is point-to-focus. However, this
5761 behavior would be very odd on Windows where the usual policy is
5764 On X, if the mouse happens to be over the raised frame, it gets
5765 input focus anyway (so the window with focus will never be
5766 completely obscured) - if not, then just moving the mouse over it
5767 is sufficient to give it focus. On Windows, the user must actually
5768 click on the frame (preferably the title bar so as not to move
5769 point), which is more awkward. Also, no other Windows program
5770 raises a window to the top but leaves another window (possibly now
5771 completely obscured) with input focus.
5773 Because there is a system setting on Windows that allows the user
5774 to choose the point to focus policy, we make the strict semantics
5775 optional, but by default we grab focus when raising. */
5777 if (NILP (Vw32_grab_focus_on_raise
))
5779 /* The obvious call to my_set_window_pos doesn't work if Emacs is
5780 not already the foreground application: the frame is raised
5781 above all other frames belonging to us, but not above the
5782 current top window. To achieve that, we have to resort to this
5783 more cumbersome method. */
5785 HDWP handle
= BeginDeferWindowPos (2);
5788 handle
= DeferWindowPos (handle
,
5789 FRAME_W32_WINDOW (f
),
5792 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
5795 handle
= DeferWindowPos (handle
,
5796 GetForegroundWindow (),
5797 FRAME_W32_WINDOW (f
),
5799 SWP_NOSIZE
| SWP_NOMOVE
|
5802 EndDeferWindowPos (handle
);
5808 my_bring_window_to_top (FRAME_W32_WINDOW (f
));
5814 /* Lower frame F. */
5816 x_lower_frame (struct frame
*f
)
5819 my_set_window_pos (FRAME_W32_WINDOW (f
),
5822 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
5827 w32_frame_raise_lower (struct frame
*f
, int raise_flag
)
5829 if (! FRAME_W32_P (f
))
5838 /* Change of visibility. */
5840 /* This tries to wait until the frame is really visible.
5841 However, if the window manager asks the user where to position
5842 the frame, this will return before the user finishes doing that.
5843 The frame will not actually be visible at that time,
5844 but it will become visible later when the window manager
5845 finishes with it. */
5848 x_make_frame_visible (struct frame
*f
)
5852 x_set_bitmap_icon (f
);
5854 if (! FRAME_VISIBLE_P (f
))
5856 /* We test FRAME_GARBAGED_P here to make sure we don't
5857 call x_set_offset a second time
5858 if we get to x_make_frame_visible a second time
5859 before the window gets really visible. */
5860 if (! FRAME_ICONIFIED_P (f
)
5861 && ! f
->output_data
.w32
->asked_for_visible
)
5866 /* Adjust vertical window position in order to avoid being
5867 covered by a task bar placed at the bottom of the desktop. */
5868 SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0);
5869 GetWindowRect (FRAME_W32_WINDOW (f
), &window_rect
);
5870 if (window_rect
.bottom
> workarea_rect
.bottom
5871 && window_rect
.top
> workarea_rect
.top
)
5872 f
->top_pos
= max (window_rect
.top
5873 - window_rect
.bottom
+ workarea_rect
.bottom
,
5876 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
5879 f
->output_data
.w32
->asked_for_visible
= 1;
5881 /* According to a report in emacs-devel 2008-06-03, SW_SHOWNORMAL
5882 causes unexpected behavior when unminimizing frames that were
5883 previously maximized. But only SW_SHOWNORMAL works properly for
5884 frames that were truely hidden (using make-frame-invisible), so
5885 we need it to avoid Bug#5482. It seems that iconified is only
5886 set for minimized windows that are still visible, so use that to
5887 determine the appropriate flag to pass ShowWindow. */
5888 my_show_window (f
, FRAME_W32_WINDOW (f
),
5889 FRAME_ICONIFIED_P (f
) ? SW_RESTORE
: SW_SHOWNORMAL
);
5892 /* Synchronize to ensure Emacs knows the frame is visible
5893 before we do anything else. We do this loop with input not blocked
5894 so that incoming events are handled. */
5899 /* This must come after we set COUNT. */
5902 XSETFRAME (frame
, f
);
5904 /* Wait until the frame is visible. Process X events until a
5905 MapNotify event has been seen, or until we think we won't get a
5906 MapNotify at all.. */
5907 for (count
= input_signal_count
+ 10;
5908 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
5910 /* Force processing of queued events. */
5911 /* TODO: x_sync equivalent? */
5913 /* Machines that do polling rather than SIGIO have been observed
5914 to go into a busy-wait here. So we'll fake an alarm signal
5915 to let the handler know that there's something to be read.
5916 We used to raise a real alarm, but it seems that the handler
5917 isn't always enabled here. This is probably a bug. */
5918 if (input_polling_used ())
5920 /* It could be confusing if a real alarm arrives while processing
5921 the fake one. Turn it off and let the handler reset it. */
5922 int old_poll_suppress_count
= poll_suppress_count
;
5923 poll_suppress_count
= 1;
5924 poll_for_input_1 ();
5925 poll_suppress_count
= old_poll_suppress_count
;
5931 /* Change from mapped state to withdrawn state. */
5933 /* Make the frame visible (mapped and not iconified). */
5936 x_make_frame_invisible (struct frame
*f
)
5938 /* Don't keep the highlight on an invisible frame. */
5939 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5940 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5944 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
5946 /* We can't distinguish this from iconification
5947 just by the event that we get from the server.
5948 So we can't win using the usual strategy of letting
5949 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5950 and synchronize with the server to make sure we agree. */
5951 SET_FRAME_VISIBLE (f
, 0);
5952 SET_FRAME_ICONIFIED (f
, 0);
5957 /* Change window state from mapped to iconified. */
5960 x_iconify_frame (struct frame
*f
)
5962 /* Don't keep the highlight on an invisible frame. */
5963 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5964 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5966 if (FRAME_ICONIFIED_P (f
))
5971 x_set_bitmap_icon (f
);
5973 /* Simulate the user minimizing the frame. */
5974 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
5976 SET_FRAME_VISIBLE (f
, 0);
5977 SET_FRAME_ICONIFIED (f
, 1);
5983 /* Free X resources of frame F. */
5986 x_free_frame_resources (struct frame
*f
)
5988 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
5989 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
5993 /* We must free faces before destroying windows because some
5994 font-driver (e.g. xft) access a window while finishing a
5996 if (FRAME_FACE_CACHE (f
))
5997 free_frame_faces (f
);
5999 if (FRAME_W32_WINDOW (f
))
6000 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
6002 free_frame_menubar (f
);
6004 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
6005 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
6006 unload_color (f
, f
->output_data
.w32
->cursor_pixel
);
6007 unload_color (f
, f
->output_data
.w32
->cursor_foreground_pixel
);
6008 unload_color (f
, f
->output_data
.w32
->border_pixel
);
6009 unload_color (f
, f
->output_data
.w32
->mouse_pixel
);
6010 if (f
->output_data
.w32
->white_relief
.allocated_p
)
6011 unload_color (f
, f
->output_data
.w32
->white_relief
.pixel
);
6012 if (f
->output_data
.w32
->black_relief
.allocated_p
)
6013 unload_color (f
, f
->output_data
.w32
->black_relief
.pixel
);
6015 if (FRAME_FACE_CACHE (f
))
6016 free_frame_faces (f
);
6018 xfree (f
->output_data
.w32
);
6019 f
->output_data
.w32
= NULL
;
6021 if (f
== dpyinfo
->w32_focus_frame
)
6022 dpyinfo
->w32_focus_frame
= 0;
6023 if (f
== dpyinfo
->w32_focus_event_frame
)
6024 dpyinfo
->w32_focus_event_frame
= 0;
6025 if (f
== dpyinfo
->x_highlight_frame
)
6026 dpyinfo
->x_highlight_frame
= 0;
6027 if (f
== hlinfo
->mouse_face_mouse_frame
)
6028 reset_mouse_highlight (hlinfo
);
6034 /* Destroy the window of frame F. */
6036 x_destroy_window (struct frame
*f
)
6038 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
6040 x_free_frame_resources (f
);
6041 dpyinfo
->reference_count
--;
6045 /* Setting window manager hints. */
6047 /* Set the normal size hints for the window manager, for frame F.
6048 FLAGS is the flags word to use--or 0 meaning preserve the flags
6049 that the window now has.
6050 If USER_POSITION, set the USPosition
6051 flag (this is useful when FLAGS is 0). */
6053 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
6055 Window window
= FRAME_W32_WINDOW (f
);
6059 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
6060 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
6061 SetWindowLong (window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
6062 SetWindowLong (window
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
6067 /***********************************************************************
6069 ***********************************************************************/
6073 /* Check that FONT is valid on frame F. It is if it can be found in F's
6077 x_check_font (struct frame
*f
, struct font
*font
)
6079 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
6080 if (font
->driver
->check
)
6081 eassert (font
->driver
->check (f
, font
) == 0);
6084 #endif /* GLYPH_DEBUG */
6088 /***********************************************************************
6090 ***********************************************************************/
6092 static int w32_initialized
= 0;
6095 w32_initialize_display_info (Lisp_Object display_name
)
6097 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6099 memset (dpyinfo
, 0, sizeof (*dpyinfo
));
6101 dpyinfo
->name_list_element
= Fcons (display_name
, Qnil
);
6102 dpyinfo
->w32_id_name
= xmalloc (SCHARS (Vinvocation_name
)
6103 + SCHARS (Vsystem_name
) + 2);
6104 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
6105 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
6107 /* Default Console mode values - overridden when running in GUI mode
6108 with values obtained from system metrics. */
6111 dpyinfo
->n_planes
= 1;
6112 dpyinfo
->n_cbits
= 4;
6113 dpyinfo
->n_fonts
= 0;
6114 dpyinfo
->smallest_font_height
= 1;
6115 dpyinfo
->smallest_char_width
= 1;
6116 dpyinfo
->vertical_scroll_bar_cursor
= w32_load_cursor (IDC_ARROW
);
6117 /* TODO: dpyinfo->gray */
6119 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
6122 /* Create an xrdb-style database of resources to supersede registry settings.
6123 The database is just a concatenation of C strings, finished by an additional
6124 \0. The strings are submitted to some basic normalization, so
6126 [ *]option[ *]:[ *]value...
6132 but any whitespace following value is not removed. */
6135 w32_make_rdb (char *xrm_option
)
6137 char *buffer
= xmalloc (strlen (xrm_option
) + 2);
6138 char *current
= buffer
;
6141 int before_value
= 0;
6155 if (in_option
&& (ch
== ':'))
6160 else if (before_value
)
6165 else if (!(in_option
|| before_value
))
6176 extern frame_parm_handler w32_frame_parm_handlers
[];
6178 static struct redisplay_interface w32_redisplay_interface
=
6180 w32_frame_parm_handlers
,
6184 x_clear_end_of_line
,
6186 x_after_update_window_line
,
6187 x_update_window_begin
,
6188 x_update_window_end
,
6189 0, /* flush_display */
6190 x_clear_window_mouse_face
,
6191 x_get_glyph_overhangs
,
6192 x_fix_overlapping_area
,
6193 w32_draw_fringe_bitmap
,
6194 w32_define_fringe_bitmap
,
6195 w32_destroy_fringe_bitmap
,
6196 w32_compute_glyph_string_overhangs
,
6197 x_draw_glyph_string
,
6198 w32_define_frame_cursor
,
6199 w32_clear_frame_area
,
6200 w32_draw_window_cursor
,
6201 w32_draw_vertical_window_border
,
6202 w32_shift_glyphs_for_insert
6205 static void x_delete_terminal (struct terminal
*term
);
6207 static struct terminal
*
6208 w32_create_terminal (struct w32_display_info
*dpyinfo
)
6210 struct terminal
*terminal
;
6212 terminal
= create_terminal ();
6214 terminal
->type
= output_w32
;
6215 terminal
->display_info
.w32
= dpyinfo
;
6216 dpyinfo
->terminal
= terminal
;
6218 /* MSVC does not type K&R functions with no arguments correctly, and
6219 so we must explicitly cast them. */
6220 terminal
->clear_frame_hook
= x_clear_frame
;
6221 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
6222 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
6223 terminal
->ring_bell_hook
= w32_ring_bell
;
6224 terminal
->reset_terminal_modes_hook
= NULL
;
6225 terminal
->set_terminal_modes_hook
= NULL
;
6226 terminal
->update_begin_hook
= x_update_begin
;
6227 terminal
->update_end_hook
= x_update_end
;
6228 terminal
->set_terminal_window_hook
= NULL
;
6229 terminal
->read_socket_hook
= w32_read_socket
;
6230 terminal
->frame_up_to_date_hook
= w32_frame_up_to_date
;
6231 terminal
->mouse_position_hook
= w32_mouse_position
;
6232 terminal
->frame_rehighlight_hook
= w32_frame_rehighlight
;
6233 terminal
->frame_raise_lower_hook
= w32_frame_raise_lower
;
6234 terminal
->fullscreen_hook
= w32fullscreen_hook
;
6235 terminal
->set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
6236 terminal
->condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
6237 terminal
->redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
6238 terminal
->judge_scroll_bars_hook
= w32_judge_scroll_bars
;
6240 terminal
->delete_frame_hook
= x_destroy_window
;
6241 terminal
->delete_terminal_hook
= x_delete_terminal
;
6243 terminal
->rif
= &w32_redisplay_interface
;
6245 /* We don't yet support separate terminals on W32, so don't try to share
6246 keyboards between virtual terminals that are on the same physical
6247 terminal like X does. */
6248 terminal
->kboard
= allocate_kboard (Qw32
);
6249 /* Don't let the initial kboard remain current longer than necessary.
6250 That would cause problems if a file loaded on startup tries to
6251 prompt in the mini-buffer. */
6252 if (current_kboard
== initial_kboard
)
6253 current_kboard
= terminal
->kboard
;
6254 terminal
->kboard
->reference_count
++;
6260 x_delete_terminal (struct terminal
*terminal
)
6262 struct w32_display_info
*dpyinfo
= terminal
->display_info
.w32
;
6264 /* Protect against recursive calls. delete_frame in
6265 delete_terminal calls us back when it deletes our last frame. */
6266 if (!terminal
->name
)
6271 x_delete_display (dpyinfo
);
6275 struct w32_display_info
*
6276 w32_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
6278 struct w32_display_info
*dpyinfo
;
6279 struct terminal
*terminal
;
6284 if (!w32_initialized
)
6287 w32_initialized
= 1;
6290 w32_initialize_display_info (display_name
);
6292 dpyinfo
= &one_w32_display_info
;
6293 terminal
= w32_create_terminal (dpyinfo
);
6295 /* Set the name of the terminal. */
6296 terminal
->name
= xlispstrdup (display_name
);
6298 dpyinfo
->xrdb
= xrm_option
? w32_make_rdb (xrm_option
) : NULL
;
6300 /* Put this display on the chain. */
6301 dpyinfo
->next
= x_display_list
;
6302 x_display_list
= dpyinfo
;
6306 dpyinfo
->root_window
= GetDesktopWindow ();
6307 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
6308 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
6309 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
6310 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
6311 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
6312 ReleaseDC (NULL
, hdc
);
6314 /* initialize palette with white and black */
6317 w32_defined_color (0, "white", &color
, 1);
6318 w32_defined_color (0, "black", &color
, 1);
6322 /* Add the default keyboard. When !WINDOWSNT, we're using the
6323 standard Emacs console handling machinery and don't need an
6324 explicit FD here. */
6325 add_keyboard_wait_descriptor (0);
6327 /* /dev/windows wakes us up when we have a thread message pending. */
6328 add_keyboard_wait_descriptor (w32_message_fd
);
6331 /* Create Fringe Bitmaps and store them for later use.
6333 On W32, bitmaps are all unsigned short, as Windows requires
6334 bitmap data to be Word aligned. For some reason they are
6335 horizontally reflected compared to how they appear on X, so we
6336 need to bitswap and convert to unsigned shorts before creating
6338 w32_init_fringe (terminal
->rif
);
6345 /* Get rid of display DPYINFO, assuming all frames are already gone. */
6347 x_delete_display (struct w32_display_info
*dpyinfo
)
6349 /* FIXME: the only display info apparently can't be deleted. */
6350 /* free palette table */
6352 struct w32_palette_entry
* plist
;
6354 plist
= dpyinfo
->color_list
;
6357 struct w32_palette_entry
* pentry
= plist
;
6358 plist
= plist
->next
;
6361 dpyinfo
->color_list
= NULL
;
6362 if (dpyinfo
->palette
)
6363 DeleteObject (dpyinfo
->palette
);
6365 xfree (dpyinfo
->w32_id_name
);
6367 w32_reset_fringes ();
6371 /* Set up use of W32. */
6373 DWORD WINAPI
w32_msg_worker (void * arg
);
6376 w32_initialize (void)
6379 HRESULT (WINAPI
* set_user_model
) (wchar_t * id
);
6383 w32_system_caret_hwnd
= NULL
;
6384 w32_system_caret_height
= 0;
6385 w32_system_caret_x
= 0;
6386 w32_system_caret_y
= 0;
6388 /* On Windows 7 and later, we need to set the user model ID
6389 to associate emacsclient launched files with Emacs frames
6391 shell
= GetModuleHandle ("shell32.dll");
6395 = (void *) GetProcAddress (shell
,
6396 "SetCurrentProcessExplicitAppUserModelID");
6398 /* If the function is defined, then we are running on Windows 7
6399 or newer, and the UI uses this to group related windows
6400 together. Since emacs, runemacs, emacsclient are related, we
6401 want them grouped even though the executables are different,
6402 so we need to set a consistent ID between them. */
6404 set_user_model (L
"GNU.Emacs");
6408 if ((w32_message_fd
= emacs_open ("/dev/windows", O_RDWR
, 0)) == -1)
6409 fatal ("opening /dev/windows: %s", strerror (errno
));
6412 /* Initialize w32_use_visible_system_caret based on whether a screen
6413 reader is in use. */
6414 if (!SystemParametersInfo (SPI_GETSCREENREADER
, 0,
6415 &w32_use_visible_system_caret
, 0))
6416 w32_use_visible_system_caret
= 0;
6418 last_tool_bar_item
= -1;
6419 any_help_event_p
= 0;
6421 /* Initialize input mode: interrupt_input off, no flow control, allow
6422 8 bit character input, standard quit char. */
6423 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
6426 DWORD input_locale_id
= ((DWORD_PTR
) GetKeyboardLayout (0) & 0xffffffff);
6427 w32_keyboard_codepage
=
6428 codepage_for_locale ((LCID
) (input_locale_id
& 0xffff));
6431 /* Create the window thread - it will terminate itself when the app
6435 dwMainThreadId
= GetCurrentThreadId ();
6436 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
6437 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
6439 /* Wait for thread to start */
6443 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
6445 hWindowsThread
= CreateThread (NULL
, 0,
6447 0, 0, &dwWindowsThreadId
);
6449 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6452 /* It is desirable that mainThread should have the same notion of
6453 focus window and active window as windowsThread. Unfortunately, the
6454 following call to AttachThreadInput, which should do precisely what
6455 we need, causes major problems when Emacs is linked as a console
6456 program. Unfortunately, we have good reasons for doing that, so
6457 instead we need to send messages to windowsThread to make some API
6458 calls for us (ones that affect, or depend on, the active/focus
6460 #ifdef ATTACH_THREADS
6461 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
6464 /* Dynamically link to optional system components. */
6466 HMODULE user_lib
= GetModuleHandle ("user32.dll");
6468 #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn)
6470 LOAD_PROC (user_lib
, SetLayeredWindowAttributes
);
6474 /* Ensure scrollbar handle is at least 5 pixels. */
6475 vertical_scroll_bar_min_handle
= 5;
6477 /* For either kind of scroll bar, take account of the arrows; these
6478 effectively form the border of the main scroll bar range. */
6479 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
6480 = GetSystemMetrics (SM_CYVSCROLL
);
6485 syms_of_w32term (void)
6487 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
6489 DEFSYM (Qadded
, "added");
6490 DEFSYM (Qremoved
, "removed");
6491 DEFSYM (Qmodified
, "modified");
6492 DEFSYM (Qrenamed_from
, "renamed-from");
6493 DEFSYM (Qrenamed_to
, "renamed-to");
6495 DEFVAR_INT ("w32-num-mouse-buttons",
6496 w32_num_mouse_buttons
,
6497 doc
: /* Number of physical mouse buttons. */);
6498 w32_num_mouse_buttons
= 2;
6500 DEFVAR_LISP ("w32-swap-mouse-buttons",
6501 Vw32_swap_mouse_buttons
,
6502 doc
: /* Swap the mapping of middle and right mouse buttons.
6503 When nil, middle button is mouse-2 and right button is mouse-3. */);
6504 Vw32_swap_mouse_buttons
= Qnil
;
6506 DEFVAR_LISP ("w32-grab-focus-on-raise",
6507 Vw32_grab_focus_on_raise
,
6508 doc
: /* Raised frame grabs input focus.
6509 When t, `raise-frame' grabs input focus as well. This fits well
6510 with the normal Windows click-to-focus policy, but might not be
6511 desirable when using a point-to-focus policy. */);
6512 Vw32_grab_focus_on_raise
= Qt
;
6514 DEFVAR_LISP ("w32-capslock-is-shiftlock",
6515 Vw32_capslock_is_shiftlock
,
6516 doc
: /* Apply CapsLock state to non character input keys.
6517 When nil, CapsLock only affects normal character input keys. */);
6518 Vw32_capslock_is_shiftlock
= Qnil
;
6520 DEFVAR_LISP ("w32-recognize-altgr",
6521 Vw32_recognize_altgr
,
6522 doc
: /* Recognize right-alt and left-ctrl as AltGr.
6523 When nil, the right-alt and left-ctrl key combination is
6524 interpreted normally. */);
6525 Vw32_recognize_altgr
= Qt
;
6527 DEFVAR_BOOL ("w32-use-visible-system-caret",
6528 w32_use_visible_system_caret
,
6529 doc
: /* Flag to make the system caret visible.
6530 When this is non-nil, Emacs will indicate the position of point by
6531 using the system caret instead of drawing its own cursor. Some screen
6532 reader software does not track the system cursor properly when it is
6533 invisible, and gets confused by Emacs drawing its own cursor, so this
6534 variable is initialized to t when Emacs detects that screen reader
6535 software is running as it starts up.
6537 When this variable is set, other variables affecting the appearance of
6538 the cursor have no effect. */);
6540 w32_use_visible_system_caret
= 0;
6542 /* We don't yet support this, but defining this here avoids whining
6543 from cus-start.el and other places, like "M-x set-variable". */
6544 DEFVAR_BOOL ("x-use-underline-position-properties",
6545 x_use_underline_position_properties
,
6546 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
6547 A value of nil means ignore them. If you encounter fonts with bogus
6548 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6549 to 4.1, set this to nil. You can also use `underline-minimum-offset'
6550 to override the font's UNDERLINE_POSITION for small font display
6552 x_use_underline_position_properties
= 0;
6554 DEFVAR_BOOL ("x-underline-at-descent-line",
6555 x_underline_at_descent_line
,
6556 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
6557 A value of nil means to draw the underline according to the value of the
6558 variable `x-use-underline-position-properties', which is usually at the
6559 baseline level. The default value is nil. */);
6560 x_underline_at_descent_line
= 0;
6562 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
6563 doc
: /* Which toolkit scroll bars Emacs uses, if any.
6564 A value of nil means Emacs doesn't use toolkit scroll bars.
6565 With the X Window system, the value is a symbol describing the
6566 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
6567 With MS Windows or Nextstep, the value is t. */);
6568 Vx_toolkit_scroll_bars
= Qt
;
6570 /* Tell Emacs about this window system. */
6571 Fprovide (Qw32
, Qnil
);