1 /* Implementation of GUI terminal on the Microsoft Windows API.
3 Copyright (C) 1989, 1993-2016 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 (at
10 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"
26 #include "w32common.h" /* for OS version info */
32 #include <fcntl.h> /* for O_RDWR */
39 #include "termhooks.h"
45 #include "menu.h" /* for w32_menu_show */
48 #include "w32.h" /* for filename_from_utf16, filename_from_ansi */
52 #include <io.h> /* for get_osfhandle */
60 #if 0 /* TODO: stipple */
61 #include "bitmaps/gray.xbm"
66 static int max_fringe_bmp
= 0;
67 static HBITMAP
*fringe_bmp
= 0;
69 /* Temporary variables for w32_read_socket. */
71 static int last_mousemove_x
= 0;
72 static int last_mousemove_y
= 0;
74 /* Define GET_WHEEL_DELTA_WPARAM macro if system headers don't. */
75 #ifndef GET_WHEEL_DELTA_WPARAM
76 #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam))
79 /* Non-zero means that a HELP_EVENT has been generated since Emacs
82 static int any_help_event_p
;
84 extern unsigned int msh_mousewheel
;
86 extern void free_frame_menubar (struct frame
*);
88 extern int w32_codepage_for_font (char *fontname
);
89 extern Cursor
w32_load_cursor (LPCTSTR name
);
91 #define x_any_window_to_frame x_window_to_frame
92 #define x_top_window_to_frame x_window_to_frame
95 /* This is display since w32 does not support multiple ones. */
96 struct w32_display_info one_w32_display_info
;
97 struct w32_display_info
*x_display_list
;
99 #if _WIN32_WINNT < 0x0500 && !defined(MINGW_W64)
100 /* Pre Windows 2000, this was not available, but define it here so
101 that Emacs compiled on such a platform will run on newer versions.
102 MinGW64 defines these unconditionally, so avoid redefining. */
104 typedef struct tagWCRANGE
110 typedef struct tagGLYPHSET
114 DWORD cGlyphsSupported
;
119 #endif /* compiling for pre-Win2k */
121 /* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */
122 BOOL (WINAPI
*pfnSetLayeredWindowAttributes
) (HWND
, COLORREF
, BYTE
, DWORD
);
125 #define LWA_ALPHA 0x02
127 /* WS_EX_LAYERED is defined unconditionally by MingW, but only for W2K and
128 later targets by MSVC headers. */
129 #ifndef WS_EX_LAYERED
130 #define WS_EX_LAYERED 0x80000
133 /* SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN are not defined on 95 and
135 #ifndef SM_CXVIRTUALSCREEN
136 #define SM_CXVIRTUALSCREEN 78
138 #ifndef SM_CYVIRTUALSCREEN
139 #define SM_CYVIRTUALSCREEN 79
142 /* The handle of the frame that currently owns the system caret. */
143 HWND w32_system_caret_hwnd
;
144 int w32_system_caret_height
;
145 int w32_system_caret_x
;
146 int w32_system_caret_y
;
147 struct window
*w32_system_caret_window
;
148 int w32_system_caret_hdr_height
;
149 int w32_system_caret_mode_height
;
150 DWORD dwWindowsThreadId
= 0;
151 HANDLE hWindowsThread
= NULL
;
152 DWORD dwMainThreadId
= 0;
153 HANDLE hMainThread
= NULL
;
155 int vertical_scroll_bar_min_handle
;
156 int horizontal_scroll_bar_min_handle
;
157 int vertical_scroll_bar_top_border
;
158 int vertical_scroll_bar_bottom_border
;
159 int horizontal_scroll_bar_left_border
;
160 int horizontal_scroll_bar_right_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
*, bool, int, int, bool);
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
*);
219 /***********************************************************************
221 ***********************************************************************/
225 /* This is a function useful for recording debugging information about
226 the sequence of occurrences in this file. */
234 struct record event_record
[100];
236 int event_record_index
;
238 record_event (char *locus
, int type
)
240 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
241 event_record_index
= 0;
243 event_record
[event_record_index
].locus
= locus
;
244 event_record
[event_record_index
].type
= type
;
245 event_record_index
++;
252 XChangeGC (void *ignore
, XGCValues
*gc
, unsigned long mask
,
255 if (mask
& GCForeground
)
256 gc
->foreground
= xgcv
->foreground
;
257 if (mask
& GCBackground
)
258 gc
->background
= xgcv
->background
;
260 gc
->font
= xgcv
->font
;
264 XCreateGC (void *ignore
, Window window
, unsigned long mask
, XGCValues
*xgcv
)
266 XGCValues
*gc
= xzalloc (sizeof (XGCValues
));
268 XChangeGC (ignore
, gc
, mask
, xgcv
);
274 XGetGCValues (void *ignore
, XGCValues
*gc
,
275 unsigned long mask
, XGCValues
*xgcv
)
277 XChangeGC (ignore
, xgcv
, mask
, gc
);
281 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
285 HRGN clip_region
= CreateRectRgnIndirect (rect
);
286 SelectClipRgn (hdc
, clip_region
);
287 DeleteObject (clip_region
);
290 SelectClipRgn (hdc
, NULL
);
293 /* Restore clipping rectangle in S */
295 w32_restore_glyph_string_clip (struct glyph_string
*s
)
298 int n
= s
->num_clips
;
301 w32_set_clip_rectangle (s
->hdc
, r
);
304 HRGN clip1
= CreateRectRgnIndirect (r
);
305 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
306 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
307 SelectClipRgn (s
->hdc
, clip1
);
308 DeleteObject (clip1
);
309 DeleteObject (clip2
);
314 Draw a wavy line under S. The wave fills wave_height pixels from y0.
320 wave_height = 3 | * * * *
325 w32_draw_underwave (struct glyph_string
*s
, COLORREF color
)
327 int wave_height
= 3, wave_length
= 2;
328 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
329 XRectangle wave_clip
, string_clip
, final_clip
;
330 RECT w32_final_clip
, w32_string_clip
;
334 dy
= wave_height
- 1;
336 y0
= s
->ybase
- wave_height
+ 3;
340 /* Find and set clipping rectangle */
344 wave_clip
.width
= width
;
345 wave_clip
.height
= wave_height
;
347 get_glyph_string_clip_rect (s
, &w32_string_clip
);
348 CONVERT_TO_XRECT (string_clip
, w32_string_clip
);
350 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
353 hp
= CreatePen (PS_SOLID
, 0, color
);
354 oldhp
= SelectObject (s
->hdc
, hp
);
355 CONVERT_FROM_XRECT (final_clip
, w32_final_clip
);
356 w32_set_clip_rectangle (s
->hdc
, &w32_final_clip
);
370 MoveToEx (s
->hdc
, x1
, y1
, NULL
);
374 LineTo (s
->hdc
, x2
, y2
);
376 x2
+= dx
, y2
= y0
+ odd
*dy
;
380 /* Restore previous pen and clipping rectangle(s) */
381 w32_restore_glyph_string_clip (s
);
382 SelectObject (s
->hdc
, oldhp
);
386 /* Draw a hollow rectangle at the specified position. */
388 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
389 int width
, int height
)
394 hb
= CreateSolidBrush (gc
->background
);
395 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
396 oldhb
= SelectObject (hdc
, hb
);
397 oldhp
= SelectObject (hdc
, hp
);
399 /* We enlarge WIDTH and HEIGHT by 1 to be bug-compatible to the
400 brain-dead design of XDrawRectangle, which draws a rectangle that
401 is 1 pixel wider and higher than its arguments WIDTH and HEIGHT.
402 This allows us to keep the code that calls this function similar
403 to the corresponding code in xterm.c. For the details, see
404 http://lists.gnu.org/archives/html/emacs-devel/2014-10/msg00546.html. */
405 Rectangle (hdc
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
407 SelectObject (hdc
, oldhb
);
408 SelectObject (hdc
, oldhp
);
413 /* Draw a filled rectangle at the specified position. */
415 w32_fill_rect (struct frame
*f
, HDC hdc
, COLORREF pix
, RECT
*lprect
)
419 hb
= CreateSolidBrush (pix
);
420 FillRect (hdc
, lprect
, hb
);
425 w32_clear_window (struct frame
*f
)
428 HDC hdc
= get_frame_dc (f
);
430 /* Under certain conditions, this can be called at startup with
431 a console frame pointer before the GUI frame is created. An HDC
432 of 0 indicates this. */
435 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
436 w32_clear_rect (f
, hdc
, &rect
);
439 release_frame_dc (f
, hdc
);
442 #define OPAQUE_FRAME 255
445 x_set_frame_alpha (struct frame
*f
)
447 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
449 double alpha_min
= 1.0;
452 HWND window
= FRAME_W32_WINDOW (f
);
454 /* Older versions of Windows do not support transparency. */
455 if (!pfnSetLayeredWindowAttributes
)
458 if (dpyinfo
->w32_focus_frame
== f
)
463 if (FLOATP (Vframe_alpha_lower_limit
))
464 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
465 else if (INTEGERP (Vframe_alpha_lower_limit
))
466 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
470 else if (alpha
> 1.0)
472 else if (alpha
< alpha_min
&& alpha_min
<= 1.0)
475 opac
= alpha
* OPAQUE_FRAME
;
477 ex_style
= GetWindowLong (window
, GWL_EXSTYLE
);
479 if (opac
== OPAQUE_FRAME
)
480 ex_style
&= ~WS_EX_LAYERED
;
482 ex_style
|= WS_EX_LAYERED
;
484 SetWindowLong (window
, GWL_EXSTYLE
, ex_style
);
486 if (opac
!= OPAQUE_FRAME
)
487 pfnSetLayeredWindowAttributes (window
, 0, opac
, LWA_ALPHA
);
491 x_display_pixel_height (struct w32_display_info
*dpyinfo
)
493 int pixels
= GetSystemMetrics (SM_CYVIRTUALSCREEN
);
496 /* Fallback for Windows 95 or NT 4.0. */
497 pixels
= GetSystemMetrics (SM_CYSCREEN
);
503 x_display_pixel_width (struct w32_display_info
*dpyinfo
)
505 int pixels
= GetSystemMetrics (SM_CXVIRTUALSCREEN
);
508 /* Fallback for Windows 95 or NT 4.0. */
509 pixels
= GetSystemMetrics (SM_CXSCREEN
);
515 /***********************************************************************
516 Starting and ending an update
517 ***********************************************************************/
519 /* Start an update of frame F. This function is installed as a hook
520 for update_begin, i.e. it is called when update_begin is called.
521 This function is called prior to calls to x_update_window_begin for
522 each window being updated. */
525 x_update_begin (struct frame
*f
)
527 struct w32_display_info
*display_info
= FRAME_DISPLAY_INFO (f
);
529 if (! FRAME_W32_P (f
))
532 /* Regenerate display palette before drawing if list of requested
533 colors has changed. */
534 if (display_info
->regen_palette
)
536 w32_regenerate_palette (f
);
537 display_info
->regen_palette
= FALSE
;
542 /* Start update of window W. */
545 x_update_window_begin (struct window
*w
)
547 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
548 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
550 /* Hide the system caret during an update. */
551 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
553 SendMessage (w32_system_caret_hwnd
, WM_EMACS_HIDE_CARET
, 0, 0);
556 w
->output_cursor
= w
->cursor
;
560 if (f
== hlinfo
->mouse_face_mouse_frame
)
562 /* Don't do highlighting for mouse motion during the update. */
563 hlinfo
->mouse_face_defer
= true;
565 /* If F needs to be redrawn, simply forget about any prior mouse
567 if (FRAME_GARBAGED_P (f
))
568 hlinfo
->mouse_face_window
= Qnil
;
570 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
571 their mouse_face_p flag set, which means that they are always
572 unequal to rows in a desired matrix which never have that
573 flag set. So, rows containing mouse-face glyphs are never
574 scrolled, and we don't have to switch the mouse highlight off
575 here to prevent it from being scrolled. */
577 /* Can we tell that this update does not affect the window
578 where the mouse highlight is? If so, no need to turn off.
579 Likewise, don't do anything if the frame is garbaged;
580 in that case, the frame's current matrix that we would use
581 is all wrong, and we will redisplay that line anyway. */
582 if (!NILP (hlinfo
->mouse_face_window
)
583 && w
== XWINDOW (hlinfo
->mouse_face_window
))
587 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
588 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
591 if (i
< w
->desired_matrix
->nrows
)
592 clear_mouse_face (hlinfo
);
600 /* Draw a vertical window border from (x,y0) to (x,y1) */
603 w32_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
605 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
615 hdc
= get_frame_dc (f
);
616 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
618 w32_fill_rect (f
, hdc
, face
->foreground
, &r
);
620 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
622 release_frame_dc (f
, hdc
);
626 /* Draw a window divider from (x0, y0) to (x1, y1) */
629 w32_draw_window_divider (struct window
*w
, int x0
, int x1
, int y0
, int y1
)
631 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
632 HDC hdc
= get_frame_dc (f
);
633 struct face
*face
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FACE_ID
);
634 struct face
*face_first
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
635 struct face
*face_last
= FACE_FROM_ID (f
, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
636 unsigned long color
= face
? face
->foreground
: FRAME_FOREGROUND_PIXEL (f
);
637 unsigned long color_first
= (face_first
638 ? face_first
->foreground
639 : FRAME_FOREGROUND_PIXEL (f
));
640 unsigned long color_last
= (face_last
641 ? face_last
->foreground
642 : FRAME_FOREGROUND_PIXEL (f
));
644 if (y1
- y0
> x1
- x0
&& x1
- x0
> 2)
647 w32_fill_area_abs (f
, hdc
, color_first
, x0
, y0
, x0
+ 1, y1
);
648 w32_fill_area_abs (f
, hdc
, color
, x0
+ 1, y0
, x1
- 1, y1
);
649 w32_fill_area_abs (f
, hdc
, color_last
, x1
- 1, y0
, x1
, y1
);
651 else if (x1
- x0
> y1
- y0
&& y1
- y0
> 3)
654 w32_fill_area_abs (f
, hdc
, color_first
, x0
, y0
, x1
, y0
+ 1);
655 w32_fill_area_abs (f
, hdc
, color
, x0
, y0
+ 1, x1
, y1
- 1);
656 w32_fill_area_abs (f
, hdc
, color_last
, x0
, y1
- 1, x1
, y1
);
659 w32_fill_area_abs (f
, hdc
, color
, x0
, y0
, x1
, y1
);
661 release_frame_dc (f
, hdc
);
664 /* End update of window W.
666 Draw vertical borders between horizontally adjacent windows, and
667 display W's cursor if CURSOR_ON_P is non-zero.
669 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
670 glyphs in mouse-face were overwritten. In that case we have to
671 make sure that the mouse-highlight is properly redrawn.
673 W may be a menu bar pseudo-window in case we don't have X toolkit
674 support. Such windows don't have a cursor, so don't display it
678 x_update_window_end (struct window
*w
, bool cursor_on_p
,
679 bool mouse_face_overwritten_p
)
681 if (!w
->pseudo_window_p
)
686 display_and_set_cursor (w
, true,
687 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
688 w
->output_cursor
.x
, w
->output_cursor
.y
);
690 if (draw_window_fringes (w
, true))
692 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
693 x_draw_right_divider (w
);
695 x_draw_vertical_border (w
);
701 /* If a row with mouse-face was overwritten, arrange for
702 XTframe_up_to_date to redisplay the mouse highlight. */
703 if (mouse_face_overwritten_p
)
705 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
707 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
708 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
709 hlinfo
->mouse_face_window
= Qnil
;
712 /* Unhide the caret. This won't actually show the cursor, unless it
713 was visible before the corresponding call to HideCaret in
714 x_update_window_begin. */
715 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
717 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
722 /* End update of frame F. This function is installed as a hook in
726 x_update_end (struct frame
*f
)
728 if (! FRAME_W32_P (f
))
731 /* Mouse highlight may be displayed again. */
732 MOUSE_HL_INFO (f
)->mouse_face_defer
= false;
736 /* This function is called from various places in xdisp.c
737 whenever a complete update has been performed. */
740 w32_frame_up_to_date (struct frame
*f
)
743 FRAME_MOUSE_UPDATE (f
);
747 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
748 arrow bitmaps, or clear the fringes if no bitmaps are required
749 before DESIRED_ROW is made current. This function is called from
750 update_window_line only if it is known that there are differences
751 between bitmaps to be drawn between current row and DESIRED_ROW. */
754 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
761 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
762 desired_row
->redraw_fringe_bitmaps_p
= true;
764 /* When a window has disappeared, make sure that no rest of
765 full-width rows stays visible in the internal border. Could
766 check here if updated window is the leftmost/rightmost window,
767 but I guess it's not worth doing since vertically split windows
768 are almost never used, internal border is rarely set, and the
769 overhead is very small. */
770 if (windows_or_buffers_changed
771 && desired_row
->full_width_p
772 && (f
= XFRAME (w
->frame
),
773 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
775 && (height
= desired_row
->visible_height
,
778 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
782 HDC hdc
= get_frame_dc (f
);
783 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
784 w32_clear_area (f
, hdc
, FRAME_PIXEL_WIDTH (f
) - width
,
786 release_frame_dc (f
, hdc
);
793 /* Draw the bitmap WHICH in one of the left or right fringes of
794 window W. ROW is the glyph row for which to display the bitmap; it
795 determines the vertical position at which the bitmap has to be
799 w32_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
,
800 struct draw_fringe_bitmap_params
*p
)
802 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
804 struct face
*face
= p
->face
;
806 hdc
= get_frame_dc (f
);
808 /* Must clip because of partially visible lines. */
809 w32_clip_to_row (w
, row
, ANY_AREA
, hdc
);
811 if (p
->bx
>= 0 && !p
->overlay_p
)
812 w32_fill_area (f
, hdc
, face
->background
,
813 p
->bx
, p
->by
, p
->nx
, p
->ny
);
815 if (p
->which
&& p
->which
< max_fringe_bmp
)
817 HBITMAP pixmap
= fringe_bmp
[p
->which
];
821 compat_hdc
= CreateCompatibleDC (hdc
);
825 horig_obj
= SelectObject (compat_hdc
, pixmap
);
827 /* Paint overlays transparently. */
830 HBRUSH h_brush
, h_orig_brush
;
832 SetTextColor (hdc
, BLACK_PIX_DEFAULT (f
));
833 SetBkColor (hdc
, WHITE_PIX_DEFAULT (f
));
834 h_brush
= CreateSolidBrush (face
->foreground
);
835 h_orig_brush
= SelectObject (hdc
, h_brush
);
837 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
838 compat_hdc
, 0, p
->dh
,
840 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
841 compat_hdc
, 0, p
->dh
,
843 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
844 compat_hdc
, 0, p
->dh
,
847 SelectObject (hdc
, h_orig_brush
);
848 DeleteObject (h_brush
);
852 SetTextColor (hdc
, face
->background
);
853 SetBkColor (hdc
, (p
->cursor_p
854 ? f
->output_data
.w32
->cursor_pixel
855 : face
->foreground
));
857 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
858 compat_hdc
, 0, p
->dh
,
862 SelectObject (compat_hdc
, horig_obj
);
863 DeleteDC (compat_hdc
);
867 w32_set_clip_rectangle (hdc
, NULL
);
869 release_frame_dc (f
, hdc
);
873 w32_define_fringe_bitmap (int which
, unsigned short *bits
, int h
, int wd
)
875 if (which
>= max_fringe_bmp
)
877 int i
= max_fringe_bmp
;
878 max_fringe_bmp
= which
+ 20;
879 fringe_bmp
= (HBITMAP
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (HBITMAP
));
880 while (i
< max_fringe_bmp
)
884 fringe_bmp
[which
] = CreateBitmap (wd
, h
, 1, 1, bits
);
888 w32_destroy_fringe_bitmap (int which
)
890 if (which
>= max_fringe_bmp
)
893 if (fringe_bmp
[which
])
894 DeleteObject (fringe_bmp
[which
]);
895 fringe_bmp
[which
] = 0;
898 /***********************************************************************
900 ***********************************************************************/
902 /* Function prototypes of this page. */
904 static void x_set_glyph_string_clipping (struct glyph_string
*);
905 static void x_set_glyph_string_gc (struct glyph_string
*);
906 static void x_draw_glyph_string_background (struct glyph_string
*,
908 static void x_draw_glyph_string_foreground (struct glyph_string
*);
909 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
910 static void x_draw_glyph_string_box (struct glyph_string
*);
911 static void x_draw_glyph_string (struct glyph_string
*);
912 static void x_set_cursor_gc (struct glyph_string
*);
913 static void x_set_mode_line_face_gc (struct glyph_string
*);
914 static void x_set_mouse_face_gc (struct glyph_string
*);
915 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
916 static void w32_setup_relief_color (struct frame
*, struct relief
*,
917 double, int, COLORREF
);
918 static void x_setup_relief_colors (struct glyph_string
*);
919 static void x_draw_image_glyph_string (struct glyph_string
*);
920 static void x_draw_image_relief (struct glyph_string
*);
921 static void x_draw_image_foreground (struct glyph_string
*);
922 static void w32_draw_image_foreground_1 (struct glyph_string
*, HBITMAP
);
923 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
925 static void w32_draw_relief_rect (struct frame
*, int, int, int, int,
926 int, int, int, int, int, int,
928 static void w32_draw_box_rect (struct glyph_string
*, int, int, int, int,
929 int, bool, bool, RECT
*);
932 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
936 x_set_cursor_gc (struct glyph_string
*s
)
938 if (s
->font
== FRAME_FONT (s
->f
)
939 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
940 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
942 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
945 /* Cursor on non-default face: must merge. */
949 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
950 xgcv
.foreground
= s
->face
->background
;
952 /* If the glyph would be invisible, try a different foreground. */
953 if (xgcv
.foreground
== xgcv
.background
)
954 xgcv
.foreground
= s
->face
->foreground
;
955 if (xgcv
.foreground
== xgcv
.background
)
956 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
957 if (xgcv
.foreground
== xgcv
.background
)
958 xgcv
.foreground
= s
->face
->foreground
;
960 /* Make sure the cursor is distinct from text in this face. */
961 if (xgcv
.background
== s
->face
->background
962 && xgcv
.foreground
== s
->face
->foreground
)
964 xgcv
.background
= s
->face
->foreground
;
965 xgcv
.foreground
= s
->face
->background
;
968 IF_DEBUG (x_check_font (s
->f
, s
->font
));
970 mask
= GCForeground
| GCBackground
| GCFont
;
972 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
973 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
976 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
977 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
979 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
984 /* Set up S->gc of glyph string S for drawing text in mouse face. */
987 x_set_mouse_face_gc (struct glyph_string
*s
)
992 /* What face has to be used last for the mouse face? */
993 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
994 face
= FACE_FROM_ID (s
->f
, face_id
);
996 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
998 if (s
->first_glyph
->type
== CHAR_GLYPH
)
999 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1001 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1002 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1003 prepare_face_for_display (s
->f
, s
->face
);
1005 /* If font in this face is same as S->font, use it. */
1006 if (s
->font
== s
->face
->font
)
1007 s
->gc
= s
->face
->gc
;
1010 /* Otherwise construct scratch_cursor_gc with values from FACE
1015 xgcv
.background
= s
->face
->background
;
1016 xgcv
.foreground
= s
->face
->foreground
;
1017 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1018 xgcv
.font
= s
->font
;
1019 mask
= GCForeground
| GCBackground
| GCFont
;
1021 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1022 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1025 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1026 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
1028 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1031 eassert (s
->gc
!= 0);
1035 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1036 Faces to use in the mode line have already been computed when the
1037 matrix was built, so there isn't much to do, here. */
1040 x_set_mode_line_face_gc (struct glyph_string
*s
)
1042 s
->gc
= s
->face
->gc
;
1046 /* Set S->gc of glyph string S for drawing that glyph string. Set
1047 S->stippled_p to a non-zero value if the face of S has a stipple
1051 x_set_glyph_string_gc (struct glyph_string
*s
)
1053 prepare_face_for_display (s
->f
, s
->face
);
1055 if (s
->hl
== DRAW_NORMAL_TEXT
)
1057 s
->gc
= s
->face
->gc
;
1058 s
->stippled_p
= s
->face
->stipple
!= 0;
1060 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1062 x_set_mode_line_face_gc (s
);
1063 s
->stippled_p
= s
->face
->stipple
!= 0;
1065 else if (s
->hl
== DRAW_CURSOR
)
1067 x_set_cursor_gc (s
);
1068 s
->stippled_p
= false;
1070 else if (s
->hl
== DRAW_MOUSE_FACE
)
1072 x_set_mouse_face_gc (s
);
1073 s
->stippled_p
= s
->face
->stipple
!= 0;
1075 else if (s
->hl
== DRAW_IMAGE_RAISED
1076 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1078 s
->gc
= s
->face
->gc
;
1079 s
->stippled_p
= s
->face
->stipple
!= 0;
1084 /* GC must have been set. */
1085 eassert (s
->gc
!= 0);
1089 /* Set clipping for output of glyph string S. S may be part of a mode
1090 line or menu if we don't have X toolkit support. */
1093 x_set_glyph_string_clipping (struct glyph_string
*s
)
1096 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1099 w32_set_clip_rectangle (s
->hdc
, r
);
1102 HRGN clip1
= CreateRectRgnIndirect (r
);
1103 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
1104 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
1105 SelectClipRgn (s
->hdc
, clip1
);
1106 DeleteObject (clip1
);
1107 DeleteObject (clip2
);
1112 /* Set SRC's clipping for output of glyph string DST. This is called
1113 when we are drawing DST's left_overhang or right_overhang only in
1117 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
,
1118 struct glyph_string
*dst
)
1123 r
.right
= r
.left
+ src
->width
;
1125 r
.bottom
= r
.top
+ src
->height
;
1128 w32_set_clip_rectangle (dst
->hdc
, &r
);
1132 Compute left and right overhang of glyph string S. */
1135 w32_compute_glyph_string_overhangs (struct glyph_string
*s
)
1138 && s
->first_glyph
->type
== CHAR_GLYPH
1139 && !s
->font_not_found_p
)
1141 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1142 struct font
*font
= s
->font
;
1143 struct font_metrics metrics
;
1146 for (i
= 0; i
< s
->nchars
; i
++)
1147 code
[i
] = s
->char2b
[i
];
1148 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1149 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1150 ? metrics
.rbearing
- metrics
.width
: 0);
1151 s
->left_overhang
= metrics
.lbearing
< 0 ? -metrics
.lbearing
: 0;
1155 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1156 s
->left_overhang
= -s
->cmp
->lbearing
;
1160 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1163 x_clear_glyph_string_rect (struct glyph_string
*s
,
1164 int x
, int y
, int w
, int h
)
1171 /* Take clipping into account. */
1172 if (s
->gc
->clip_mask
== Rect
)
1174 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
1175 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
1176 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
1177 - s
->gc
->clip_rectangle
.left
);
1178 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
1179 - s
->gc
->clip_rectangle
.top
);
1182 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
1187 /* Draw the background of glyph_string S. If S->background_filled_p
1188 is non-zero don't draw it. FORCE_P non-zero means draw the
1189 background even if it wouldn't be drawn normally. This is used
1190 when a string preceding S draws into the background of S, or S
1191 contains the first component of a composition. */
1194 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1196 /* Nothing to do if background has already been drawn or if it
1197 shouldn't be drawn in the first place. */
1198 if (!s
->background_filled_p
)
1200 int box_line_width
= max (s
->face
->box_line_width
, 0);
1202 #if 0 /* TODO: stipple */
1205 /* Fill background with a stipple pattern. */
1206 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1207 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1208 s
->y
+ box_line_width
,
1209 s
->background_width
,
1210 s
->height
- 2 * box_line_width
);
1211 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1212 s
->background_filled_p
= true;
1216 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1217 /* When xdisp.c ignores FONT_HEIGHT, we cannot trust
1218 font dimensions, since the actual glyphs might be
1219 much smaller. So in that case we always clear the
1220 rectangle with background color. */
1221 || FONT_TOO_HIGH (s
->font
)
1222 || s
->font_not_found_p
1223 || s
->extends_to_end_of_line_p
1226 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1227 s
->background_width
,
1228 s
->height
- 2 * box_line_width
);
1229 s
->background_filled_p
= true;
1235 /* Draw the foreground of glyph string S. */
1238 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1242 /* If first glyph of S has a left box line, start drawing the text
1243 of S to the right of that box line. */
1244 if (s
->face
->box
!= FACE_NO_BOX
1245 && s
->first_glyph
->left_box_line_p
)
1246 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1250 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1251 SetBkColor (s
->hdc
, s
->gc
->background
);
1252 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1254 /* Draw characters of S as rectangles if S's font could not be
1256 if (s
->font_not_found_p
)
1258 for (i
= 0; i
< s
->nchars
; ++i
)
1260 struct glyph
*g
= s
->first_glyph
+ i
;
1262 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1264 x
+= g
->pixel_width
;
1269 struct font
*font
= s
->font
;
1270 int boff
= font
->baseline_offset
;
1274 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1276 if (font
->vertical_centering
)
1277 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1279 y
= s
->ybase
- boff
;
1281 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1282 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, false);
1284 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, true);
1285 if (s
->face
->overstrike
)
1286 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, false);
1288 SelectObject (s
->hdc
, old_font
);
1292 /* Draw the foreground of composite glyph string S. */
1295 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1298 struct font
*font
= s
->font
;
1300 /* If first glyph of S has a left box line, start drawing the text
1301 of S to the right of that box line. */
1302 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1303 && s
->first_glyph
->left_box_line_p
)
1304 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1308 /* S is a glyph string for a composition. S->cmp_from is the index
1309 of the first character drawn for glyphs of this composition.
1310 S->cmp_from == 0 means we are drawing the very first character of
1311 this composition. */
1313 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1314 SetBkColor (s
->hdc
, s
->gc
->background
);
1315 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1317 /* Draw a rectangle for the composition if the font for the very
1318 first character of the composition could not be loaded. */
1319 if (s
->font_not_found_p
)
1321 if (s
->cmp_from
== 0)
1322 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
1325 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1330 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1332 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1333 /* TAB in a composition means display glyphs with padding
1334 space on the left or right. */
1335 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1337 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1338 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1340 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, false);
1341 if (s
->face
->overstrike
)
1342 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, false);
1344 SelectObject (s
->hdc
, old_font
);
1348 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1354 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1356 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1358 glyph
= LGSTRING_GLYPH (gstring
, i
);
1359 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1360 width
+= LGLYPH_WIDTH (glyph
);
1363 int xoff
, yoff
, wadjust
;
1367 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1370 xoff
= LGLYPH_XOFF (glyph
);
1371 yoff
= LGLYPH_YOFF (glyph
);
1372 wadjust
= LGLYPH_WADJUST (glyph
);
1373 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, false);
1380 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1382 SelectObject (s
->hdc
, old_font
);
1387 /* Draw the foreground of glyph string S for glyphless characters. */
1390 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1392 struct glyph
*glyph
= s
->first_glyph
;
1395 bool with_background
;
1397 /* If first glyph of S has a left box line, start drawing the text
1398 of S to the right of that box line. */
1399 if (s
->face
->box
!= FACE_NO_BOX
1400 && s
->first_glyph
->left_box_line_p
)
1401 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1405 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1406 SetBkColor (s
->hdc
, s
->gc
->background
);
1407 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1410 with_background
= ((s
->for_overlaps
1411 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))) == 0;
1412 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1414 char buf
[7], *str
= NULL
;
1415 int len
= glyph
->u
.glyphless
.len
;
1417 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1420 && CHAR_TABLE_P (Vglyphless_char_display
)
1421 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1425 = (! glyph
->u
.glyphless
.for_no_font
1426 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1427 glyph
->u
.glyphless
.ch
)
1428 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1429 if (STRINGP (acronym
))
1430 str
= SSDATA (acronym
);
1433 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1435 sprintf ((char *) buf
, "%0*X",
1436 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1437 glyph
->u
.glyphless
.ch
);
1441 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1442 w32_draw_rectangle (s
->hdc
, s
->gc
,
1443 x
, s
->ybase
- glyph
->ascent
,
1444 glyph
->pixel_width
- 1,
1445 glyph
->ascent
+ glyph
->descent
- 1);
1448 struct font
*font
= s
->font
;
1449 int upper_len
= (len
+ 1) / 2;
1453 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1454 /* It is certain that all LEN characters in STR are ASCII. */
1455 for (j
= 0; j
< len
; j
++)
1457 code
= font
->driver
->encode_char (font
, str
[j
]);
1458 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1460 font
->driver
->draw (s
, 0, upper_len
,
1461 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1462 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1464 font
->driver
->draw (s
, upper_len
, len
,
1465 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1466 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1468 SelectObject (s
->hdc
, old_font
);
1470 x
+= glyph
->pixel_width
;
1475 /* Brightness beyond which a color won't have its highlight brightness
1478 Nominally, highlight colors for `3d' faces are calculated by
1479 brightening an object's color by a constant scale factor, but this
1480 doesn't yield good results for dark colors, so for colors whose
1481 brightness is less than this value (on a scale of 0-255) have to
1482 use an additional additive factor.
1484 The value here is set so that the default menu-bar/mode-line color
1485 (grey75) will not have its highlights changed at all. */
1486 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
1489 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
1490 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1491 If this produces the same color as COLOR, try a color where all RGB
1492 values have DELTA added. Return the allocated color in *COLOR.
1493 DISPLAY is the X display, CMAP is the colormap to operate on.
1494 Value is non-zero if successful. */
1497 w32_alloc_lighter_color (struct frame
*f
, COLORREF
*color
,
1498 double factor
, int delta
)
1503 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
1506 /* Change RGB values by specified FACTOR. Avoid overflow! */
1507 eassert (factor
>= 0);
1508 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
1509 min (0xff, factor
* GetGValue (*color
)),
1510 min (0xff, factor
* GetBValue (*color
)));
1512 /* Calculate brightness of COLOR. */
1513 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
1514 + GetBValue (*color
)) / 6;
1516 /* We only boost colors that are darker than
1517 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1518 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1519 /* Make an additive adjustment to NEW, because it's dark enough so
1520 that scaling by FACTOR alone isn't enough. */
1522 /* How far below the limit this color is (0 - 1, 1 being darker). */
1523 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1524 /* The additive adjustment. */
1525 int min_delta
= delta
* dimness
* factor
/ 2;
1528 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
1529 max (0, min (0xff, min_delta
- GetGValue (*color
))),
1530 max (0, min (0xff, min_delta
- GetBValue (*color
))));
1532 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
1533 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
1534 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
1538 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
1539 max (0, min (0xff, delta
+ GetGValue (*color
))),
1540 max (0, min (0xff, delta
+ GetBValue (*color
))));
1542 /* TODO: Map to palette and retry with delta if same? */
1543 /* TODO: Free colors (if using palette)? */
1553 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1554 colors in COLORS. On W32, we no longer try to map colors to
1557 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1561 for (i
= 0; i
< ncolors
; i
++)
1563 DWORD pixel
= colors
[i
].pixel
;
1564 /* Convert to a 16 bit value in range 0 - 0xffff. */
1565 colors
[i
].red
= GetRValue (pixel
) * 257;
1566 colors
[i
].green
= GetGValue (pixel
) * 257;
1567 colors
[i
].blue
= GetBValue (pixel
) * 257;
1572 x_query_color (struct frame
*f
, XColor
*color
)
1574 x_query_colors (f
, color
, 1);
1578 /* Set up the foreground color for drawing relief lines of glyph
1579 string S. RELIEF is a pointer to a struct relief containing the GC
1580 with which lines will be drawn. Use a color that is FACTOR or
1581 DELTA lighter or darker than the relief's background which is found
1582 in S->f->output_data.x->relief_background. If such a color cannot
1583 be allocated, use DEFAULT_PIXEL, instead. */
1586 w32_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
,
1587 int delta
, COLORREF default_pixel
)
1590 struct w32_output
*di
= f
->output_data
.w32
;
1591 unsigned long mask
= GCForeground
;
1593 COLORREF background
= di
->relief_background
;
1595 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1598 /* TODO: Free colors (if using palette)? */
1600 /* Allocate new color. */
1601 xgcv
.foreground
= default_pixel
;
1603 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
1604 xgcv
.foreground
= relief
->pixel
= pixel
;
1606 if (relief
->gc
== 0)
1608 #if 0 /* TODO: stipple */
1609 xgcv
.stipple
= dpyinfo
->gray
;
1612 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
1615 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
1619 /* Set up colors for the relief lines around glyph string S. */
1622 x_setup_relief_colors (struct glyph_string
*s
)
1624 struct w32_output
*di
= s
->f
->output_data
.w32
;
1627 if (s
->face
->use_box_color_for_shadows_p
)
1628 color
= s
->face
->box_color
;
1629 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1631 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1632 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1634 color
= s
->gc
->background
;
1636 if (di
->white_relief
.gc
== 0
1637 || color
!= di
->relief_background
)
1639 di
->relief_background
= color
;
1640 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1641 WHITE_PIX_DEFAULT (s
->f
));
1642 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1643 BLACK_PIX_DEFAULT (s
->f
));
1648 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1649 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1650 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1651 relief. LEFT_P non-zero means draw a relief on the left side of
1652 the rectangle. RIGHT_P non-zero means draw a relief on the right
1653 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1657 w32_draw_relief_rect (struct frame
*f
,
1658 int left_x
, int top_y
, int right_x
, int bottom_y
,
1659 int width
, int raised_p
,
1660 int top_p
, int bot_p
, int left_p
, int right_p
,
1665 HDC hdc
= get_frame_dc (f
);
1668 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1670 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1672 w32_set_clip_rectangle (hdc
, clip_rect
);
1676 for (i
= 0; i
< width
; ++i
)
1677 w32_fill_area (f
, hdc
, gc
.foreground
,
1678 left_x
+ i
* left_p
, top_y
+ i
,
1679 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1683 for (i
= 0; i
< width
; ++i
)
1684 w32_fill_area (f
, hdc
, gc
.foreground
,
1685 left_x
+ i
, top_y
+ (i
+ 1) * top_p
, 1,
1686 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1689 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1691 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1695 for (i
= 0; i
< width
; ++i
)
1696 w32_fill_area (f
, hdc
, gc
.foreground
,
1697 left_x
+ i
* left_p
, bottom_y
- i
,
1698 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1702 for (i
= 0; i
< width
; ++i
)
1703 w32_fill_area (f
, hdc
, gc
.foreground
,
1704 right_x
- i
, top_y
+ (i
+ 1) * top_p
, 1,
1705 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1707 w32_set_clip_rectangle (hdc
, NULL
);
1709 release_frame_dc (f
, hdc
);
1713 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1714 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1715 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
1716 left side of the rectangle. RIGHT_P non-zero means draw a line
1717 on the right side of the rectangle. CLIP_RECT is the clipping
1718 rectangle to use when drawing. */
1721 w32_draw_box_rect (struct glyph_string
*s
,
1722 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1723 bool left_p
, bool right_p
, RECT
*clip_rect
)
1725 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
1728 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1729 left_x
, top_y
, right_x
- left_x
+ 1, width
);
1734 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1735 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
1739 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1740 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
1745 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1746 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
1749 w32_set_clip_rectangle (s
->hdc
, NULL
);
1753 /* Draw a box around glyph string S. */
1756 x_draw_glyph_string_box (struct glyph_string
*s
)
1758 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
;
1759 bool left_p
, right_p
, raised_p
;
1760 struct glyph
*last_glyph
;
1763 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
1764 ? WINDOW_RIGHT_EDGE_X (s
->w
)
1765 : window_box_right (s
->w
, s
->area
));
1767 /* The glyph that may have a right box line. */
1768 last_glyph
= (s
->cmp
|| s
->img
1770 : s
->first_glyph
+ s
->nchars
- 1);
1772 width
= eabs (s
->face
->box_line_width
);
1773 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
1775 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
1777 : min (last_x
, s
->x
+ s
->background_width
) - 1));
1779 bottom_y
= top_y
+ s
->height
- 1;
1781 left_p
= (s
->first_glyph
->left_box_line_p
1782 || (s
->hl
== DRAW_MOUSE_FACE
1784 || s
->prev
->hl
!= s
->hl
)));
1785 right_p
= (last_glyph
->right_box_line_p
1786 || (s
->hl
== DRAW_MOUSE_FACE
1788 || s
->next
->hl
!= s
->hl
)));
1790 get_glyph_string_clip_rect (s
, &clip_rect
);
1792 if (s
->face
->box
== FACE_SIMPLE_BOX
)
1793 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
1794 left_p
, right_p
, &clip_rect
);
1797 x_setup_relief_colors (s
);
1798 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
1799 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
1804 /* Draw foreground of image glyph string S. */
1807 x_draw_image_foreground (struct glyph_string
*s
)
1810 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1812 /* If first glyph of S has a left box line, start drawing it to the
1813 right of that line. */
1814 if (s
->face
->box
!= FACE_NO_BOX
1815 && s
->first_glyph
->left_box_line_p
1817 x
+= eabs (s
->face
->box_line_width
);
1819 /* If there is a margin around the image, adjust x- and y-position
1821 if (s
->slice
.x
== 0)
1822 x
+= s
->img
->hmargin
;
1823 if (s
->slice
.y
== 0)
1824 y
+= s
->img
->vmargin
;
1830 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
1831 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1832 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
1833 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1834 SetBkColor (compat_hdc
, RGB (255, 255, 255));
1835 SetTextColor (s
->hdc
, RGB (0, 0, 0));
1836 x_set_glyph_string_clipping (s
);
1840 HDC mask_dc
= CreateCompatibleDC (s
->hdc
);
1841 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1843 SetTextColor (s
->hdc
, RGB (255, 255, 255));
1844 SetBkColor (s
->hdc
, RGB (0, 0, 0));
1846 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1847 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1848 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1849 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
1850 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1851 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1853 SelectObject (mask_dc
, mask_orig_obj
);
1858 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1859 SetBkColor (s
->hdc
, s
->gc
->background
);
1861 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1862 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
1864 /* When the image has a mask, we can expect that at
1865 least part of a mouse highlight or a block cursor will
1866 be visible. If the image doesn't have a mask, make
1867 a block cursor visible by drawing a rectangle around
1868 the image. I believe it's looking better if we do
1869 nothing here for mouse-face. */
1870 if (s
->hl
== DRAW_CURSOR
)
1872 int r
= s
->img
->relief
;
1874 w32_draw_rectangle (s
->hdc
, s
->gc
, x
- r
, y
- r
,
1875 s
->slice
.width
+ r
*2 - 1,
1876 s
->slice
.height
+ r
*2 - 1);
1880 w32_set_clip_rectangle (s
->hdc
, NULL
);
1881 SelectObject (s
->hdc
, orig_brush
);
1882 DeleteObject (fg_brush
);
1883 SelectObject (compat_hdc
, orig_obj
);
1884 DeleteDC (compat_hdc
);
1887 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
,
1888 s
->slice
.width
- 1, s
->slice
.height
- 1);
1890 RestoreDC (s
->hdc
,-1);
1894 /* Draw a relief around the image glyph string S. */
1897 x_draw_image_relief (struct glyph_string
*s
)
1899 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
1900 int extra_x
, extra_y
;
1903 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1905 /* If first glyph of S has a left box line, start drawing it to the
1906 right of that line. */
1907 if (s
->face
->box
!= FACE_NO_BOX
1908 && s
->first_glyph
->left_box_line_p
1910 x
+= eabs (s
->face
->box_line_width
);
1912 /* If there is a margin around the image, adjust x- and y-position
1914 if (s
->slice
.x
== 0)
1915 x
+= s
->img
->hmargin
;
1916 if (s
->slice
.y
== 0)
1917 y
+= s
->img
->vmargin
;
1919 if (s
->hl
== DRAW_IMAGE_SUNKEN
1920 || s
->hl
== DRAW_IMAGE_RAISED
)
1922 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
1923 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
1924 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
1928 thick
= eabs (s
->img
->relief
);
1929 raised_p
= s
->img
->relief
> 0;
1932 x1
= x
+ s
->slice
.width
- 1;
1933 y1
= y
+ s
->slice
.height
- 1;
1935 extra_x
= extra_y
= 0;
1936 if (s
->face
->id
== TOOL_BAR_FACE_ID
)
1938 if (CONSP (Vtool_bar_button_margin
)
1939 && INTEGERP (XCAR (Vtool_bar_button_margin
))
1940 && INTEGERP (XCDR (Vtool_bar_button_margin
)))
1942 extra_x
= XINT (XCAR (Vtool_bar_button_margin
));
1943 extra_y
= XINT (XCDR (Vtool_bar_button_margin
));
1945 else if (INTEGERP (Vtool_bar_button_margin
))
1946 extra_x
= extra_y
= XINT (Vtool_bar_button_margin
);
1949 top_p
= bot_p
= left_p
= right_p
= 0;
1951 if (s
->slice
.x
== 0)
1952 x
-= thick
+ extra_x
, left_p
= 1;
1953 if (s
->slice
.y
== 0)
1954 y
-= thick
+ extra_y
, top_p
= 1;
1955 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
1956 x1
+= thick
+ extra_x
, right_p
= 1;
1957 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
1958 y1
+= thick
+ extra_y
, bot_p
= 1;
1960 x_setup_relief_colors (s
);
1961 get_glyph_string_clip_rect (s
, &r
);
1962 w32_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
1963 top_p
, bot_p
, left_p
, right_p
, &r
);
1967 /* Draw the foreground of image glyph string S to PIXMAP. */
1970 w32_draw_image_foreground_1 (struct glyph_string
*s
, HBITMAP pixmap
)
1972 HDC hdc
= CreateCompatibleDC (s
->hdc
);
1973 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
1975 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1977 /* If first glyph of S has a left box line, start drawing it to the
1978 right of that line. */
1979 if (s
->face
->box
!= FACE_NO_BOX
1980 && s
->first_glyph
->left_box_line_p
1982 x
+= eabs (s
->face
->box_line_width
);
1984 /* If there is a margin around the image, adjust x- and y-position
1986 if (s
->slice
.x
== 0)
1987 x
+= s
->img
->hmargin
;
1988 if (s
->slice
.y
== 0)
1989 y
+= s
->img
->vmargin
;
1993 HDC compat_hdc
= CreateCompatibleDC (hdc
);
1994 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1995 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
1996 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
2000 HDC mask_dc
= CreateCompatibleDC (hdc
);
2001 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
2003 SetTextColor (hdc
, RGB (0, 0, 0));
2004 SetBkColor (hdc
, RGB (255, 255, 255));
2005 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2006 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
2007 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2008 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
2009 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2010 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
2012 SelectObject (mask_dc
, mask_orig_obj
);
2017 SetTextColor (hdc
, s
->gc
->foreground
);
2018 SetBkColor (hdc
, s
->gc
->background
);
2020 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2021 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
2023 /* When the image has a mask, we can expect that at
2024 least part of a mouse highlight or a block cursor will
2025 be visible. If the image doesn't have a mask, make
2026 a block cursor visible by drawing a rectangle around
2027 the image. I believe it's looking better if we do
2028 nothing here for mouse-face. */
2029 if (s
->hl
== DRAW_CURSOR
)
2031 int r
= s
->img
->relief
;
2033 w32_draw_rectangle (hdc
, s
->gc
, x
- r
, y
- r
,
2034 s
->slice
.width
+ r
*2 - 1,
2035 s
->slice
.height
+ r
*2 - 1);
2039 SelectObject (hdc
, orig_brush
);
2040 DeleteObject (fg_brush
);
2041 SelectObject (compat_hdc
, orig_obj
);
2042 DeleteDC (compat_hdc
);
2045 w32_draw_rectangle (hdc
, s
->gc
, x
, y
,
2046 s
->slice
.width
- 1, s
->slice
.height
- 1);
2048 SelectObject (hdc
, orig_hdc_obj
);
2053 /* Draw part of the background of glyph string S. X, Y, W, and H
2054 give the rectangle to draw. */
2057 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2059 #if 0 /* TODO: stipple */
2062 /* Fill background with a stipple pattern. */
2063 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2064 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2065 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2069 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2073 /* Draw image glyph string S.
2076 s->x +-------------------------
2079 | +-------------------------
2082 | | +-------------------
2088 x_draw_image_glyph_string (struct glyph_string
*s
)
2091 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2092 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2097 if (s
->slice
.y
== 0)
2098 height
-= box_line_vwidth
;
2099 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2100 height
-= box_line_vwidth
;
2102 /* Fill background with face under the image. Do it only if row is
2103 taller than image or if image has a clip mask to reduce
2105 s
->stippled_p
= s
->face
->stipple
!= 0;
2106 if (height
> s
->slice
.height
2110 || s
->img
->pixmap
== 0
2111 || s
->width
!= s
->background_width
)
2113 width
= s
->background_width
;
2115 if (s
->first_glyph
->left_box_line_p
2118 x
+= box_line_hwidth
;
2119 width
-= box_line_hwidth
;
2123 if (s
->slice
.y
== 0)
2124 y
+= box_line_vwidth
;
2126 #if 0 /* TODO: figure out if we need to do this on Windows. */
2129 /* Create a pixmap as large as the glyph string. Fill it
2130 with the background color. Copy the image to it, using
2131 its mask. Copy the temporary pixmap to the display. */
2132 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2133 int depth
= DefaultDepthOfScreen (screen
);
2135 /* Create a pixmap as large as the glyph string. */
2136 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2137 s
->background_width
,
2140 /* Don't clip in the following because we're working on the
2142 XSetClipMask (s
->display
, s
->gc
, None
);
2144 /* Fill the pixmap with the background color/stipple. */
2147 /* Fill background with a stipple pattern. */
2148 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2149 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2150 0, 0, s
->background_width
, s
->height
);
2151 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2156 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2158 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2159 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2160 0, 0, s
->background_width
, s
->height
);
2161 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2166 x_draw_glyph_string_bg_rect (s
, x
, y
, width
, height
);
2168 s
->background_filled_p
= true;
2171 /* Draw the foreground. */
2174 w32_draw_image_foreground_1 (s
, pixmap
);
2175 x_set_glyph_string_clipping (s
);
2177 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
2178 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
2179 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
2180 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
2182 SetTextColor (s
->hdc
, s
->gc
->foreground
);
2183 SetBkColor (s
->hdc
, s
->gc
->background
);
2184 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
2185 compat_hdc
, 0, 0, SRCCOPY
);
2187 SelectObject (s
->hdc
, orig_brush
);
2188 DeleteObject (fg_brush
);
2189 SelectObject (compat_hdc
, orig_obj
);
2190 DeleteDC (compat_hdc
);
2192 DeleteObject (pixmap
);
2196 x_draw_image_foreground (s
);
2198 /* If we must draw a relief around the image, do it. */
2200 || s
->hl
== DRAW_IMAGE_RAISED
2201 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2202 x_draw_image_relief (s
);
2206 /* Draw stretch glyph string S. */
2209 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2211 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2213 if (s
->hl
== DRAW_CURSOR
2214 && !x_stretch_cursor_p
)
2216 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2217 wide as the stretch glyph. */
2218 int width
, background_width
= s
->background_width
;
2221 if (!s
->row
->reversed_p
)
2223 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2227 background_width
-= left_x
- x
;
2233 /* In R2L rows, draw the cursor on the right edge of the
2235 int right_x
= window_box_right (s
->w
, TEXT_AREA
);
2237 if (x
+ background_width
> right_x
)
2238 background_width
-= x
- right_x
;
2239 x
+= background_width
;
2241 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2242 if (s
->row
->reversed_p
)
2246 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2248 /* Clear rest using the GC of the original non-cursor face. */
2249 if (width
< background_width
)
2251 XGCValues
*gc
= s
->face
->gc
;
2253 int w
= background_width
- width
, h
= s
->height
;
2257 if (!s
->row
->reversed_p
)
2261 if (s
->row
->mouse_face_p
2262 && cursor_in_mouse_face_p (s
->w
))
2264 x_set_mouse_face_gc (s
);
2270 get_glyph_string_clip_rect (s
, &r
);
2271 w32_set_clip_rectangle (hdc
, &r
);
2273 #if 0 /* TODO: stipple */
2274 if (s
->face
->stipple
)
2276 /* Fill background with a stipple pattern. */
2277 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2278 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2279 XSetFillStyle (s
->display
, gc
, FillSolid
);
2284 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
2288 else if (!s
->background_filled_p
)
2290 int background_width
= s
->background_width
;
2291 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2293 /* Don't draw into left margin, fringe or scrollbar area
2294 except for header line and mode line. */
2295 if (x
< left_x
&& !s
->row
->mode_line_p
)
2297 background_width
-= left_x
- x
;
2300 if (background_width
> 0)
2301 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2304 s
->background_filled_p
= true;
2308 /* Draw glyph string S. */
2311 x_draw_glyph_string (struct glyph_string
*s
)
2313 bool relief_drawn_p
= 0;
2315 /* If S draws into the background of its successor, draw the
2316 background of the successor first so that S can draw into it.
2317 This makes S->next use XDrawString instead of XDrawImageString. */
2318 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2321 struct glyph_string
*next
;
2322 for (width
= 0, next
= s
->next
;
2323 next
&& width
< s
->right_overhang
;
2324 width
+= next
->width
, next
= next
->next
)
2325 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2327 x_set_glyph_string_gc (next
);
2328 x_set_glyph_string_clipping (next
);
2329 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2330 x_draw_stretch_glyph_string (next
);
2332 x_draw_glyph_string_background (next
, true);
2333 next
->num_clips
= 0;
2337 /* Set up S->gc, set clipping and draw S. */
2338 x_set_glyph_string_gc (s
);
2340 /* Draw relief (if any) in advance for char/composition so that the
2341 glyph string can be drawn over it. */
2342 if (!s
->for_overlaps
2343 && s
->face
->box
!= FACE_NO_BOX
2344 && (s
->first_glyph
->type
== CHAR_GLYPH
2345 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2348 x_set_glyph_string_clipping (s
);
2349 x_draw_glyph_string_background (s
, true);
2350 x_draw_glyph_string_box (s
);
2351 x_set_glyph_string_clipping (s
);
2354 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2356 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2357 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2358 /* We must clip just this glyph. left_overhang part has already
2359 drawn when s->prev was drawn, and right_overhang part will be
2360 drawn later when s->next is drawn. */
2361 x_set_glyph_string_clipping_exactly (s
, s
);
2363 x_set_glyph_string_clipping (s
);
2365 switch (s
->first_glyph
->type
)
2368 x_draw_image_glyph_string (s
);
2372 x_draw_stretch_glyph_string (s
);
2376 if (s
->for_overlaps
)
2377 s
->background_filled_p
= true;
2379 x_draw_glyph_string_background (s
, false);
2380 x_draw_glyph_string_foreground (s
);
2383 case COMPOSITE_GLYPH
:
2384 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2385 && ! s
->first_glyph
->u
.cmp
.automatic
))
2386 s
->background_filled_p
= true;
2388 x_draw_glyph_string_background (s
, true);
2389 x_draw_composite_glyph_string_foreground (s
);
2392 case GLYPHLESS_GLYPH
:
2393 if (s
->for_overlaps
)
2394 s
->background_filled_p
= true;
2396 x_draw_glyph_string_background (s
, false);
2397 x_draw_glyphless_glyph_string_foreground (s
);
2404 if (!s
->for_overlaps
)
2406 /* Draw underline. */
2407 if (s
->face
->underline_p
)
2409 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2413 if (s
->face
->underline_defaulted_p
)
2414 color
= s
->gc
->foreground
;
2416 color
= s
->face
->underline_color
;
2418 w32_draw_underwave (s
, color
);
2420 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2422 unsigned long thickness
, position
;
2425 if (s
->prev
&& s
->prev
->face
->underline_p
2426 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2428 /* We use the same underline style as the previous one. */
2429 thickness
= s
->prev
->underline_thickness
;
2430 position
= s
->prev
->underline_position
;
2434 /* Get the underline thickness. Default is 1 pixel. */
2435 if (s
->font
&& s
->font
->underline_thickness
> 0)
2436 thickness
= s
->font
->underline_thickness
;
2439 if (x_underline_at_descent_line
)
2440 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2443 /* Get the underline position. This is the recommended
2444 vertical offset in pixels from the baseline to the top of
2445 the underline. This is a signed value according to the
2446 specs, and its default is
2448 ROUND ((maximum_descent) / 2), with
2449 ROUND (x) = floor (x + 0.5) */
2451 if (x_use_underline_position_properties
2452 && s
->font
&& s
->font
->underline_position
>= 0)
2453 position
= s
->font
->underline_position
;
2455 position
= (s
->font
->descent
+ 1) / 2;
2457 position
= max (position
, underline_minimum_offset
);
2459 /* Check the sanity of thickness and position. We should
2460 avoid drawing underline out of the current line area. */
2461 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2462 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2463 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2464 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2465 s
->underline_thickness
= thickness
;
2466 s
->underline_position
=position
;
2467 y
= s
->ybase
+ position
;
2468 if (s
->face
->underline_defaulted_p
)
2470 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2475 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
2480 /* Draw overline. */
2481 if (s
->face
->overline_p
)
2483 unsigned long dy
= 0, h
= 1;
2485 if (s
->face
->overline_color_defaulted_p
)
2487 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2488 s
->y
+ dy
, s
->width
, h
);
2492 w32_fill_area (s
->f
, s
->hdc
, s
->face
->overline_color
, s
->x
,
2493 s
->y
+ dy
, s
->width
, h
);
2497 /* Draw strike-through. */
2498 if (s
->face
->strike_through_p
2499 && !FONT_TEXTMETRIC (s
->font
).tmStruckOut
)
2501 unsigned long h
= 1;
2502 unsigned long dy
= (s
->height
- h
) / 2;
2504 if (s
->face
->strike_through_color_defaulted_p
)
2506 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
2511 w32_fill_area (s
->f
, s
->hdc
, s
->face
->strike_through_color
, s
->x
,
2512 s
->y
+ dy
, s
->width
, h
);
2516 /* Draw relief if not yet drawn. */
2517 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2518 x_draw_glyph_string_box (s
);
2522 struct glyph_string
*prev
;
2524 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2525 if (prev
->hl
!= s
->hl
2526 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2528 /* As prev was drawn while clipped to its own area, we
2529 must draw the right_overhang part using s->hl now. */
2530 enum draw_glyphs_face save
= prev
->hl
;
2533 x_set_glyph_string_gc (prev
);
2534 x_set_glyph_string_clipping_exactly (s
, prev
);
2535 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2536 x_draw_glyph_string_foreground (prev
);
2538 x_draw_composite_glyph_string_foreground (prev
);
2539 w32_set_clip_rectangle (prev
->hdc
, NULL
);
2541 prev
->num_clips
= 0;
2547 struct glyph_string
*next
;
2549 for (next
= s
->next
; next
; next
= next
->next
)
2550 if (next
->hl
!= s
->hl
2551 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2553 /* As next will be drawn while clipped to its own area,
2554 we must draw the left_overhang part using s->hl now. */
2555 enum draw_glyphs_face save
= next
->hl
;
2558 x_set_glyph_string_gc (next
);
2559 x_set_glyph_string_clipping_exactly (s
, next
);
2560 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2561 x_draw_glyph_string_foreground (next
);
2563 x_draw_composite_glyph_string_foreground (next
);
2564 w32_set_clip_rectangle (next
->hdc
, NULL
);
2566 next
->num_clips
= 0;
2567 next
->clip_head
= s
->next
;
2572 /* Reset clipping. */
2573 w32_set_clip_rectangle (s
->hdc
, NULL
);
2578 /* Shift display to make room for inserted glyphs. */
2581 w32_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
,
2582 int width
, int height
, int shift_by
)
2586 hdc
= get_frame_dc (f
);
2587 BitBlt (hdc
, x
+ shift_by
, y
, width
, height
,
2588 hdc
, x
, y
, SRCCOPY
);
2590 release_frame_dc (f
, hdc
);
2594 /* Delete N glyphs at the nominal cursor position. Not implemented
2598 x_delete_glyphs (struct frame
*f
, register int n
)
2600 if (! FRAME_W32_P (f
))
2607 /* Clear entire frame. */
2610 x_clear_frame (struct frame
*f
)
2612 if (! FRAME_W32_P (f
))
2615 /* Clearing the frame will erase any cursor, so mark them all as no
2617 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2621 w32_clear_window (f
);
2623 /* We have to clear the scroll bars, too. If we have changed
2624 colors or something like that, then they should be notified. */
2625 x_scroll_bar_clear (f
);
2631 /* Make audible bell. */
2634 w32_ring_bell (struct frame
*f
)
2638 if (FRAME_W32_P (f
) && visible_bell
)
2641 HWND hwnd
= FRAME_W32_WINDOW (f
);
2643 for (i
= 0; i
< 5; i
++)
2645 FlashWindow (hwnd
, TRUE
);
2648 FlashWindow (hwnd
, FALSE
);
2651 w32_sys_ring_bell (f
);
2656 /***********************************************************************
2658 ***********************************************************************/
2660 /* Perform an insert-lines or delete-lines operation, inserting N
2661 lines or deleting -N lines at vertical position VPOS. */
2664 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
2666 if (! FRAME_W32_P (f
))
2673 /* Scroll part of the display as described by RUN. */
2676 x_scroll_run (struct window
*w
, struct run
*run
)
2678 struct frame
*f
= XFRAME (w
->frame
);
2679 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2680 HWND hwnd
= FRAME_W32_WINDOW (f
);
2683 /* Get frame-relative bounding box of the text display area of W,
2684 without mode lines. Include in this box the left and right
2686 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
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 (