1 /* Implementation of GUI terminal on the Mac OS.
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Contributed by Andrew Choi (akochoi@mac.com). */
29 #include "blockinput.h"
43 /* Macros max and min defined in lisp.h conflict with those in
44 precompiled header Carbon.h. */
47 #include <Carbon/Carbon.h>
49 #define free unexec_free
51 #define malloc unexec_malloc
53 #define realloc unexec_realloc
55 #define min(a, b) ((a) < (b) ? (a) : (b))
57 #define max(a, b) ((a) > (b) ? (a) : (b))
58 #else /* not MAC_OSX */
59 #include <Quickdraw.h>
60 #include <ToolUtils.h>
64 #include <Resources.h>
66 #include <TextUtils.h>
69 #if defined (__MRC__) || (__MSL__ >= 0x6000)
70 #include <ControlDefinitions.h>
77 #endif /* not MAC_OSX */
91 #include "dispextern.h"
93 #include "termhooks.h"
100 #include "intervals.h"
101 #include "composite.h"
104 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
107 /* Fringe bitmaps. */
109 enum fringe_bitmap_type
112 LEFT_TRUNCATION_BITMAP
,
113 RIGHT_TRUNCATION_BITMAP
,
114 OVERLAY_ARROW_BITMAP
,
115 CONTINUED_LINE_BITMAP
,
116 CONTINUATION_LINE_BITMAP
,
120 /* Bitmap drawn to indicate lines not displaying text if
121 `indicate-empty-lines' is non-nil. */
126 static unsigned char zv_bits
[] = {
127 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
128 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
129 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
130 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
131 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
132 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
133 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
134 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
136 /* An arrow like this: `<-'. */
139 #define left_height 8
140 static unsigned char left_bits
[] = {
141 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
143 /* Right truncation arrow bitmap `->'. */
145 #define right_width 8
146 #define right_height 8
147 static unsigned char right_bits
[] = {
148 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
150 /* Marker for continued lines. */
152 #define continued_width 8
153 #define continued_height 8
154 static unsigned char continued_bits
[] = {
155 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
157 /* Marker for continuation lines. */
159 #define continuation_width 8
160 #define continuation_height 8
161 static unsigned char continuation_bits
[] = {
162 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
164 /* Overlay arrow bitmap. */
170 static unsigned char ov_bits
[] = {
171 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c};
173 /* A triangular arrow. */
176 static unsigned char ov_bits
[] = {
177 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
180 extern Lisp_Object Qhelp_echo
;
183 /* Non-nil means Emacs uses toolkit scroll bars. */
185 Lisp_Object Vx_toolkit_scroll_bars
;
187 /* If a string, XTread_socket generates an event to display that string.
188 (The display is done in read_char.) */
190 static Lisp_Object help_echo
;
191 static Lisp_Object help_echo_window
;
192 static Lisp_Object help_echo_object
;
193 static int help_echo_pos
;
195 /* Temporary variable for XTread_socket. */
197 static Lisp_Object previous_help_echo
;
199 /* Non-zero means that a HELP_EVENT has been generated since Emacs
202 static int any_help_event_p
;
204 /* Non-zero means autoselect window with the mouse cursor. */
206 int x_autoselect_window_p
;
208 /* Non-zero means draw block and hollow cursor as wide as the glyph
209 under it. For example, if a block cursor is over a tab, it will be
210 drawn as wide as that tab on the display. */
212 int x_stretch_cursor_p
;
214 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
216 int x_use_underline_position_properties
;
218 /* This is a chain of structures for all the X displays currently in
221 struct x_display_info
*x_display_list
;
223 /* This is a list of cons cells, each of the form (NAME
224 . FONT-LIST-CACHE), one for each element of x_display_list and in
225 the same order. NAME is the name of the frame. FONT-LIST-CACHE
226 records previous values returned by x-list-fonts. */
228 Lisp_Object x_display_name_list
;
230 /* This is display since Mac does not support multiple ones. */
231 struct mac_display_info one_mac_display_info
;
233 /* Frame being updated by update_frame. This is declared in term.c.
234 This is set by update_begin and looked at by all the XT functions.
235 It is zero while not inside an update. In that case, the XT
236 functions assume that `selected_frame' is the frame to apply to. */
238 extern struct frame
*updating_frame
;
240 extern int waiting_for_input
;
242 /* This is a frame waiting to be auto-raised, within XTread_socket. */
244 struct frame
*pending_autoraise_frame
;
246 /* Nominal cursor position -- where to draw output.
247 HPOS and VPOS are window relative glyph matrix coordinates.
248 X and Y are window relative pixel coordinates. */
250 struct cursor_pos output_cursor
;
252 /* Non-zero means user is interacting with a toolkit scroll bar. */
254 static int toolkit_scroll_bar_interaction
;
258 Formerly, we used PointerMotionHintMask (in standard_event_mask)
259 so that we would have to call XQueryPointer after each MotionNotify
260 event to ask for another such event. However, this made mouse tracking
261 slow, and there was a bug that made it eventually stop.
263 Simply asking for MotionNotify all the time seems to work better.
265 In order to avoid asking for motion events and then throwing most
266 of them away or busy-polling the server for mouse positions, we ask
267 the server for pointer motion hints. This means that we get only
268 one event per group of mouse movements. "Groups" are delimited by
269 other kinds of events (focus changes and button clicks, for
270 example), or by XQueryPointer calls; when one of these happens, we
271 get another MotionNotify event the next time the mouse moves. This
272 is at least as efficient as getting motion events when mouse
273 tracking is on, and I suspect only negligibly worse when tracking
276 /* Where the mouse was last time we reported a mouse event. */
278 FRAME_PTR last_mouse_frame
;
279 static Rect last_mouse_glyph
;
280 static Lisp_Object last_mouse_press_frame
;
282 /* The scroll bar in which the last X motion event occurred.
284 If the last X motion event occurred in a scroll bar, we set this so
285 XTmouse_position can know whether to report a scroll bar motion or
288 If the last X motion event didn't occur in a scroll bar, we set
289 this to Qnil, to tell XTmouse_position to return an ordinary motion
292 static Lisp_Object last_mouse_scroll_bar
;
294 /* This is a hack. We would really prefer that XTmouse_position would
295 return the time associated with the position it returns, but there
296 doesn't seem to be any way to wrest the time-stamp from the server
297 along with the position query. So, we just keep track of the time
298 of the last movement we received, and return that in hopes that
299 it's somewhat accurate. */
301 static Time last_mouse_movement_time
;
303 enum mouse_tracking_type
{
305 mouse_tracking_mouse_movement
,
306 mouse_tracking_scroll_bar
309 enum mouse_tracking_type mouse_tracking_in_progress
= mouse_tracking_none
;
311 struct scroll_bar
*tracked_scroll_bar
= NULL
;
313 /* Incremented by XTread_socket whenever it really tries to read
317 static int volatile input_signal_count
;
319 static int input_signal_count
;
322 /* Used locally within XTread_socket. */
324 static int x_noop_count
;
326 /* Initial values of argv and argc. */
328 extern char **initial_argv
;
329 extern int initial_argc
;
331 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
333 /* Tells if a window manager is present or not. */
335 extern Lisp_Object Vx_no_window_manager
;
337 extern Lisp_Object Qface
, Qmouse_face
;
341 /* A mask of extra modifier bits to put into every keyboard char. */
343 extern int extra_keyboard_modifiers
;
345 static Lisp_Object Qvendor_specific_keysyms
;
348 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
351 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
355 QDGlobals qd
; /* QuickDraw global information structure. */
359 /* Enumeration for overriding/changing the face to use for drawing
360 glyphs in x_draw_glyphs. */
362 enum draw_glyphs_face
372 struct frame
* x_window_to_frame (struct mac_display_info
*, WindowPtr
);
373 struct mac_display_info
*mac_display_info_for_display (Display
*);
374 static void x_update_window_end
P_ ((struct window
*, int, int));
375 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
376 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
377 int *, int *, Lisp_Object
));
378 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
379 int *, int *, int *, int *, int));
380 static void set_output_cursor
P_ ((struct cursor_pos
*));
381 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
382 int *, int *, int *, int));
383 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
384 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
385 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
386 static void x_handle_tool_bar_click
P_ ((struct frame
*, EventRecord
*));
387 static void show_mouse_face
P_ ((struct x_display_info
*,
388 enum draw_glyphs_face
));
389 static int cursor_in_mouse_face_p
P_ ((struct window
*));
390 static int clear_mouse_face
P_ ((struct mac_display_info
*));
391 static int x_io_error_quitter
P_ ((Display
*));
392 int x_catch_errors
P_ ((Display
*));
393 void x_uncatch_errors
P_ ((Display
*, int));
394 void x_lower_frame
P_ ((struct frame
*));
395 void x_scroll_bar_clear
P_ ((struct frame
*));
396 int x_had_errors_p
P_ ((Display
*));
397 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
398 void x_raise_frame
P_ ((struct frame
*));
399 void x_set_window_size
P_ ((struct frame
*, int, int, int));
400 void x_wm_set_window_state
P_ ((struct frame
*, int));
401 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
402 void mac_initialize
P_ ((void));
403 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
404 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
405 enum text_cursor_kinds x_specified_cursor_type
P_ ((Lisp_Object
, int *));
406 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
408 enum draw_glyphs_face
));
409 static void x_update_end
P_ ((struct frame
*));
410 static void XTframe_up_to_date
P_ ((struct frame
*));
411 static void XTreassert_line_highlight
P_ ((int, int));
412 static void x_change_line_highlight
P_ ((int, int, int, int));
413 static void XTset_terminal_modes
P_ ((void));
414 static void XTreset_terminal_modes
P_ ((void));
415 static void XTcursor_to
P_ ((int, int, int, int));
416 static void x_write_glyphs
P_ ((struct glyph
*, int));
417 static void x_clear_end_of_line
P_ ((int));
418 static void x_clear_frame
P_ ((void));
419 static void x_clear_cursor
P_ ((struct window
*));
420 static void frame_highlight
P_ ((struct frame
*));
421 static void frame_unhighlight
P_ ((struct frame
*));
422 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
423 static void XTframe_rehighlight
P_ ((struct frame
*));
424 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
425 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
426 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
427 static int x_intersect_rectangles
P_ ((Rect
*, Rect
*, Rect
*));
428 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
429 static int expose_window_tree
P_ ((struct window
*, Rect
*));
430 static int expose_window
P_ ((struct window
*, Rect
*));
431 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
432 Rect
*, enum glyph_row_area
));
433 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
435 void x_display_cursor (struct window
*, int, int, int, int, int);
436 void x_update_cursor
P_ ((struct frame
*, int));
437 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
438 static void x_update_window_cursor
P_ ((struct window
*, int));
439 static void x_erase_phys_cursor
P_ ((struct window
*));
440 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
441 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
442 enum fringe_bitmap_type
, int left_p
));
443 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
445 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, Rect
*));
446 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
447 static void notice_overwritten_cursor
P_ ((struct window
*,
449 int, int, int, int));
450 static void x_flush
P_ ((struct frame
*f
));
451 static void x_update_begin
P_ ((struct frame
*));
452 static void x_update_window_begin
P_ ((struct window
*));
453 static void x_draw_vertical_border
P_ ((struct window
*));
454 static void x_after_update_window_line
P_ ((struct glyph_row
*));
455 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
456 static void x_produce_stretch_glyph
P_ ((struct it
*));
458 static void activate_scroll_bars (FRAME_PTR
);
459 static void deactivate_scroll_bars (FRAME_PTR
);
461 extern int image_ascent (struct image
*, struct face
*);
462 void x_set_offset (struct frame
*, int, int, int);
463 int x_bitmap_icon (struct frame
*, Lisp_Object
);
464 void x_make_frame_visible (struct frame
*);
466 extern void window_scroll (Lisp_Object
, int, int, int);
468 /* Defined in macmenu.h. */
469 extern void menubar_selection_callback (FRAME_PTR
, int);
470 extern void set_frame_menubar (FRAME_PTR
, int, int);
472 /* X display function emulation */
474 /* Structure borrowed from Xlib.h to represent two-byte characters in
483 XFreePixmap (display
, pixmap
)
487 PixMap
*p
= (PixMap
*) pixmap
;
494 /* Set foreground color for subsequent QuickDraw commands. Assume
495 graphic port has already been set. */
498 mac_set_forecolor (unsigned long color
)
502 fg_color
.red
= RED_FROM_ULONG (color
) * 256;
503 fg_color
.green
= GREEN_FROM_ULONG (color
) * 256;
504 fg_color
.blue
= BLUE_FROM_ULONG (color
) * 256;
506 RGBForeColor (&fg_color
);
510 /* Set background color for subsequent QuickDraw commands. Assume
511 graphic port has already been set. */
514 mac_set_backcolor (unsigned long color
)
518 bg_color
.red
= RED_FROM_ULONG (color
) * 256;
519 bg_color
.green
= GREEN_FROM_ULONG (color
) * 256;
520 bg_color
.blue
= BLUE_FROM_ULONG (color
) * 256;
522 RGBBackColor (&bg_color
);
525 /* Set foreground and background color for subsequent QuickDraw
526 commands. Assume that the graphic port has already been set. */
529 mac_set_colors (GC gc
)
531 mac_set_forecolor (gc
->foreground
);
532 mac_set_backcolor (gc
->background
);
535 /* Mac version of XDrawLine. */
538 XDrawLine (display
, w
, gc
, x1
, y1
, x2
, y2
)
544 #if TARGET_API_MAC_CARBON
545 SetPort (GetWindowPort (w
));
556 /* Mac version of XClearArea. */
559 XClearArea (display
, w
, x
, y
, width
, height
, exposures
)
563 unsigned int width
, height
;
566 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
570 xgc
.foreground
= mwp
->x_compatible
.foreground_pixel
;
571 xgc
.background
= mwp
->x_compatible
.background_pixel
;
573 #if TARGET_API_MAC_CARBON
574 SetPort (GetWindowPort (w
));
579 mac_set_colors (&xgc
);
580 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
585 /* Mac version of XClearWindow. */
588 XClearWindow (display
, w
)
592 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
595 xgc
.foreground
= mwp
->x_compatible
.foreground_pixel
;
596 xgc
.background
= mwp
->x_compatible
.background_pixel
;
598 #if TARGET_API_MAC_CARBON
599 SetPort (GetWindowPort (w
));
604 mac_set_colors (&xgc
);
606 #if TARGET_API_MAC_CARBON
610 GetWindowPortBounds (w
, &r
);
613 #else /* not TARGET_API_MAC_CARBON */
614 EraseRect (&(w
->portRect
));
615 #endif /* not TARGET_API_MAC_CARBON */
619 /* Mac replacement for XCopyArea. */
622 mac_draw_bitmap (display
, w
, gc
, x
, y
, bitmap
)
631 #if TARGET_API_MAC_CARBON
632 SetPort (GetWindowPort (w
));
638 SetRect (&r
, x
, y
, x
+ bitmap
->bounds
.right
, y
+ bitmap
->bounds
.bottom
);
640 #if TARGET_API_MAC_CARBON
644 LockPortBits (GetWindowPort (w
));
645 pmh
= GetPortPixMap (GetWindowPort (w
));
646 CopyBits (bitmap
, (BitMap
*) *pmh
, &(bitmap
->bounds
), &r
, srcCopy
, 0);
647 UnlockPortBits (GetWindowPort (w
));
649 #else /* not TARGET_API_MAC_CARBON */
650 CopyBits (bitmap
, &(w
->portBits
), &(bitmap
->bounds
), &r
, srcCopy
, 0);
651 #endif /* not TARGET_API_MAC_CARBON */
655 /* Mac replacement for XSetClipRectangles. */
658 mac_set_clip_rectangle (display
, w
, r
)
663 #if TARGET_API_MAC_CARBON
664 SetPort (GetWindowPort (w
));
673 /* Mac replacement for XSetClipMask. */
676 mac_reset_clipping (display
, w
)
682 #if TARGET_API_MAC_CARBON
683 SetPort (GetWindowPort (w
));
688 SetRect (&r
, -32767, -32767, 32767, 32767);
693 /* Mac replacement for XCreateBitmapFromBitmapData. */
696 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
701 int bytes_per_row
, i
, j
;
703 bitmap
->rowBytes
= (w
+ 15) / 16 * 2; /* must be on word boundary */
704 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
705 if (!bitmap
->baseAddr
)
708 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
709 for (i
= 0; i
< h
; i
++)
710 for (j
= 0; j
< w
; j
++)
711 if (BitTst (bits
, i
* w
+ j
))
712 BitSet (bitmap
->baseAddr
, i
* bitmap
->rowBytes
* 8 + j
);
714 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
719 mac_free_bitmap (bitmap
)
722 xfree (bitmap
->baseAddr
);
725 /* Mac replacement for XFillRectangle. */
728 XFillRectangle (display
, w
, gc
, x
, y
, width
, height
)
733 unsigned int width
, height
;
737 #if TARGET_API_MAC_CARBON
738 SetPort (GetWindowPort (w
));
744 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
746 PaintRect (&r
); /* using foreground color of gc */
750 /* Mac replacement for XDrawRectangle: dest is a window. */
753 mac_draw_rectangle (display
, w
, gc
, x
, y
, width
, height
)
758 unsigned int width
, height
;
762 #if TARGET_API_MAC_CARBON
763 SetPort (GetWindowPort (w
));
769 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
771 FrameRect (&r
); /* using foreground color of gc */
775 /* Mac replacement for XDrawRectangle: dest is a Pixmap. */
778 mac_draw_rectangle_to_pixmap (display
, p
, gc
, x
, y
, width
, height
)
783 unsigned int width
, height
;
785 #if 0 /* MAC_TODO: draw a rectangle in a PixMap */
788 #if TARGET_API_MAC_CARBON
789 SetPort (GetWindowPort (w
));
795 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
797 FrameRect (&r
); /* using foreground color of gc */
803 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, mode
,
810 int nchars
, mode
, bytes_per_char
;
812 #if TARGET_API_MAC_CARBON
813 SetPort (GetWindowPort (w
));
820 TextFont (gc
->font
->mac_fontnum
);
821 TextSize (gc
->font
->mac_fontsize
);
822 TextFace (gc
->font
->mac_fontface
);
826 DrawText (buf
, 0, nchars
* bytes_per_char
);
830 /* Mac replacement for XDrawString. */
833 XDrawString (display
, w
, gc
, x
, y
, buf
, nchars
)
841 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, srcOr
, 1);
845 /* Mac replacement for XDrawString16. */
848 XDrawString16 (display
, w
, gc
, x
, y
, buf
, nchars
)
856 mac_draw_string_common (display
, w
, gc
, x
, y
, (char *) buf
, nchars
, srcOr
,
861 /* Mac replacement for XDrawImageString. */
864 XDrawImageString (display
, w
, gc
, x
, y
, buf
, nchars
)
872 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, srcCopy
, 1);
876 /* Mac replacement for XDrawString16. */
879 XDrawImageString16 (display
, w
, gc
, x
, y
, buf
, nchars
)
887 mac_draw_string_common (display
, w
, gc
, x
, y
, (char *) buf
, nchars
, srcCopy
,
892 /* Mac replacement for XCopyArea: dest must be window. */
895 mac_copy_area (display
, src
, dest
, gc
, src_x
, src_y
, width
, height
, dest_x
,
902 unsigned int width
, height
;
907 #if TARGET_API_MAC_CARBON
908 SetPort (GetWindowPort (dest
));
915 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
916 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
918 #if TARGET_API_MAC_CARBON
922 LockPortBits (GetWindowPort (dest
));
923 pmh
= GetPortPixMap (GetWindowPort (dest
));
924 CopyBits ((BitMap
*) &src
, (BitMap
*) *pmh
, &src_r
, &dest_r
, srcCopy
, 0);
925 UnlockPortBits (GetWindowPort (dest
));
927 #else /* not TARGET_API_MAC_CARBON */
928 CopyBits ((BitMap
*) &src
, &(dest
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
929 #endif /* not TARGET_API_MAC_CARBON */
934 /* Convert a pair of local coordinates to global (screen) coordinates.
935 Assume graphic port has been properly set. */
937 local_to_global_coord (short *h
, short *v
)
951 /* Mac replacement for XCopyArea: used only for scrolling. */
954 mac_scroll_area (display
, w
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
959 unsigned int width
, height
;
962 #if TARGET_API_MAC_CARBON
963 Rect gw_r
, src_r
, dest_r
;
966 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
967 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
969 SetPort (GetWindowPort (w
));
972 LockPortBits (GetWindowPort (w
));
973 pmh
= GetPortPixMap (GetWindowPort (w
));
974 CopyBits ((BitMap
*) *pmh
, (BitMap
*) *pmh
, &src_r
, &dest_r
, srcCopy
, 0);
975 UnlockPortBits (GetWindowPort (w
));
976 #else /* not TARGET_API_MAC_CARBON */
984 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
985 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
988 /* Need to use global coordinates and screenBits since src and dest
989 areas overlap in general. */
990 local_to_global_coord (&src_r
.left
, &src_r
.top
);
991 local_to_global_coord (&src_r
.right
, &src_r
.bottom
);
992 local_to_global_coord (&dest_r
.left
, &dest_r
.top
);
993 local_to_global_coord (&dest_r
.right
, &dest_r
.bottom
);
995 CopyBits (&qd
.screenBits
, &qd
.screenBits
, &src_r
, &dest_r
, srcCopy
, 0);
997 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
998 color mapping in CopyBits. Otherwise, it will be slow. */
999 ForeColor (blackColor
);
1000 BackColor (whiteColor
);
1001 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
1003 mac_set_colors (gc
);
1005 #endif /* not TARGET_API_MAC_CARBON */
1009 /* Mac replacement for XCopyArea: dest must be Pixmap. */
1012 mac_copy_area_to_pixmap (display
, src
, dest
, gc
, src_x
, src_y
, width
, height
,
1019 unsigned int width
, height
;
1023 int src_right
= ((PixMap
*) src
)->bounds
.right
;
1024 int src_bottom
= ((PixMap
*) src
)->bounds
.bottom
;
1025 int w
= src_right
- src_x
;
1026 int h
= src_bottom
- src_y
;
1028 mac_set_colors (gc
);
1030 SetRect (&src_r
, src_x
, src_y
, src_right
, src_bottom
);
1031 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ w
, dest_y
+ h
);
1033 CopyBits ((BitMap
*) &src
, (BitMap
*) &dest
, &src_r
, &dest_r
, srcCopy
, 0);
1037 /* Mac replacement for XChangeGC. */
1040 XChangeGC (void * ignore
, XGCValues
* gc
, unsigned long mask
,
1043 if (mask
& GCForeground
)
1044 gc
->foreground
= xgcv
->foreground
;
1045 if (mask
& GCBackground
)
1046 gc
->background
= xgcv
->background
;
1048 gc
->font
= xgcv
->font
;
1052 /* Mac replacement for XCreateGC. */
1055 XCreateGC (void * ignore
, Window window
, unsigned long mask
,
1058 XGCValues
*gc
= (XGCValues
*) xmalloc (sizeof (XGCValues
));
1059 bzero (gc
, sizeof (XGCValues
));
1061 XChangeGC (ignore
, gc
, mask
, xgcv
);
1067 /* Used in xfaces.c. */
1070 XFreeGC (display
, gc
)
1078 /* Mac replacement for XGetGCValues. */
1081 XGetGCValues (void* ignore
, XGCValues
*gc
,
1082 unsigned long mask
, XGCValues
*xgcv
)
1084 XChangeGC (ignore
, xgcv
, mask
, gc
);
1088 /* Mac replacement for XSetForeground. */
1091 XSetForeground (display
, gc
, color
)
1094 unsigned long color
;
1096 gc
->foreground
= color
;
1100 /* Mac replacement for XSetFont. */
1103 XSetFont (display
, gc
, font
)
1113 XTextExtents16 (XFontStruct
*font
, XChar2b
*text
, int nchars
,
1114 int *direction
,int *font_ascent
,
1115 int *font_descent
, XCharStruct
*cs
)
1117 /* MAC_TODO: Use GetTextMetrics to do this and inline it below. */
1121 /* x_sync is a no-op on Mac. */
1129 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1130 Calls to XFlush should be unnecessary because the X output buffer
1131 is flushed automatically as needed by calls to XPending,
1132 XNextEvent, or XWindowEvent according to the XFlush man page.
1133 XTread_socket calls XPending. Removing XFlush improves
1136 #if TARGET_API_MAC_CARBON
1137 #define XFlush(DISPLAY) QDFlushPortBuffer (GetQDGlobalsThePort (), NULL)
1139 #define XFlush(DISPLAY) (void) 0
1142 /* Flush display of frame F, or of all frames if F is null. */
1148 #if TARGET_API_MAC_CARBON
1152 Lisp_Object rest
, frame
;
1153 FOR_EACH_FRAME (rest
, frame
)
1154 x_flush (XFRAME (frame
));
1156 else if (FRAME_X_P (f
))
1157 XFlush (FRAME_MAC_DISPLAY (f
));
1159 #endif /* TARGET_API_MAC_CARBON */
1164 /* Return the struct mac_display_info corresponding to DPY. There's
1167 struct mac_display_info
*
1168 mac_display_info_for_display (dpy
)
1171 return &one_mac_display_info
;
1176 /***********************************************************************
1177 Starting and ending an update
1178 ***********************************************************************/
1180 /* Start an update of frame F. This function is installed as a hook
1181 for update_begin, i.e. it is called when update_begin is called.
1182 This function is called prior to calls to x_update_window_begin for
1183 each window being updated. */
1189 /* Nothing to do. */
1193 /* Start update of window W. Set the global variable updated_window
1194 to the window being updated and set output_cursor to the cursor
1198 x_update_window_begin (w
)
1201 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1202 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1205 set_output_cursor (&w
->cursor
);
1209 if (f
== display_info
->mouse_face_mouse_frame
)
1211 /* Don't do highlighting for mouse motion during the update. */
1212 display_info
->mouse_face_defer
= 1;
1214 /* If F needs to be redrawn, simply forget about any prior mouse
1216 if (FRAME_GARBAGED_P (f
))
1217 display_info
->mouse_face_window
= Qnil
;
1219 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1220 their mouse_face_p flag set, which means that they are always
1221 unequal to rows in a desired matrix which never have that
1222 flag set. So, rows containing mouse-face glyphs are never
1223 scrolled, and we don't have to switch the mouse highlight off
1224 here to prevent it from being scrolled. */
1226 /* Can we tell that this update does not affect the window
1227 where the mouse highlight is? If so, no need to turn off.
1228 Likewise, don't do anything if the frame is garbaged;
1229 in that case, the frame's current matrix that we would use
1230 is all wrong, and we will redisplay that line anyway. */
1231 if (!NILP (display_info
->mouse_face_window
)
1232 && w
== XWINDOW (display_info
->mouse_face_window
))
1236 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1237 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1240 if (i
< w
->desired_matrix
->nrows
)
1241 clear_mouse_face (display_info
);
1250 /* Draw a vertical window border to the right of window W if W doesn't
1251 have vertical scroll bars. */
1254 x_draw_vertical_border (w
)
1257 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1259 /* Redraw borders between horizontally adjacent windows. Don't
1260 do it for frames with vertical scroll bars because either the
1261 right scroll bar of a window, or the left scroll bar of its
1262 neighbor will suffice as a border. */
1263 if (!WINDOW_RIGHTMOST_P (w
)
1264 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1268 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
1269 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
1272 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1273 f
->output_data
.mac
->normal_gc
, x1
, y0
, x1
, y1
);
1278 /* End update of window W (which is equal to updated_window).
1280 Draw vertical borders between horizontally adjacent windows, and
1281 display W's cursor if CURSOR_ON_P is non-zero.
1283 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1284 glyphs in mouse-face were overwritten. In that case we have to
1285 make sure that the mouse-highlight is properly redrawn.
1287 W may be a menu bar pseudo-window in case we don't have X toolkit
1288 support. Such windows don't have a cursor, so don't display it
1292 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
1294 int cursor_on_p
, mouse_face_overwritten_p
;
1296 struct mac_display_info
*dpyinfo
1297 = FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
1299 if (!w
->pseudo_window_p
)
1304 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
1306 output_cursor
.x
, output_cursor
.y
);
1308 x_draw_vertical_border (w
);
1312 /* If a row with mouse-face was overwritten, arrange for
1313 XTframe_up_to_date to redisplay the mouse highlight. */
1314 if (mouse_face_overwritten_p
)
1316 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1317 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1318 dpyinfo
->mouse_face_window
= Qnil
;
1322 /* Unhide the caret. This won't actually show the cursor, unless it
1323 was visible before the corresponding call to HideCaret in
1324 x_update_window_begin. */
1325 if (w32_use_visible_system_caret
)
1326 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
1329 updated_window
= NULL
;
1333 /* End update of frame F. This function is installed as a hook in
1340 /* Reset the background color of Mac OS Window to that of the frame after
1341 update so that it is used by Mac Toolbox to clear the update region before
1342 an update event is generated. */
1343 #if TARGET_API_MAC_CARBON
1344 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f
)));
1346 SetPort (FRAME_MAC_WINDOW (f
));
1349 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f
));
1351 /* Mouse highlight may be displayed again. */
1352 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1355 XFlush (FRAME_MAC_DISPLAY (f
));
1360 /* This function is called from various places in xdisp.c whenever a
1361 complete update has been performed. The global variable
1362 updated_window is not available here. */
1365 XTframe_up_to_date (f
)
1370 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
1372 if (dpyinfo
->mouse_face_deferred_gc
1373 || f
== dpyinfo
->mouse_face_mouse_frame
)
1376 if (dpyinfo
->mouse_face_mouse_frame
)
1377 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1378 dpyinfo
->mouse_face_mouse_x
,
1379 dpyinfo
->mouse_face_mouse_y
);
1380 dpyinfo
->mouse_face_deferred_gc
= 0;
1387 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1388 arrow bitmaps, or clear the fringes if no bitmaps are required
1389 before DESIRED_ROW is made current. The window being updated is
1390 found in updated_window. This function is called from
1391 update_window_line only if it is known that there are differences
1392 between bitmaps to be drawn between current row and DESIRED_ROW. */
1395 x_after_update_window_line (desired_row
)
1396 struct glyph_row
*desired_row
;
1398 struct window
*w
= updated_window
;
1404 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1407 x_draw_row_fringe_bitmaps (w
, desired_row
);
1411 /* When a window has disappeared, make sure that no rest of
1412 full-width rows stays visible in the internal border. Could
1413 check here if updated_window is the leftmost/rightmost window,
1414 but I guess it's not worth doing since vertically split windows
1415 are almost never used, internal border is rarely set, and the
1416 overhead is very small. */
1417 if (windows_or_buffers_changed
1418 && desired_row
->full_width_p
1419 && (f
= XFRAME (w
->frame
),
1420 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
1422 && (height
= desired_row
->visible_height
,
1425 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
1426 /* Internal border is drawn below the tool bar. */
1427 if (WINDOWP (f
->tool_bar_window
)
1428 && w
== XWINDOW (f
->tool_bar_window
))
1433 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1434 0, y
, width
, height
, 0);
1435 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1436 f
->output_data
.mac
->pixel_width
- width
, y
,
1444 /* Draw the bitmap WHICH in one of the left or right fringes of
1445 window W. ROW is the glyph row for which to display the bitmap; it
1446 determines the vertical position at which the bitmap has to be
1450 x_draw_fringe_bitmap (w
, row
, which
, left_p
)
1452 struct glyph_row
*row
;
1453 enum fringe_bitmap_type which
;
1456 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1457 Display
*display
= FRAME_MAC_DISPLAY (f
);
1458 WindowPtr window
= FRAME_MAC_WINDOW (f
);
1459 int x
, y
, wd
, h
, dy
;
1461 unsigned char *bits
;
1464 GC gc
= f
->output_data
.mac
->normal_gc
;
1467 /* Must clip because of partially visible lines. */
1468 x_clip_to_row (w
, row
, gc
, 1);
1470 /* Convert row to frame coordinates. */
1471 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
1475 case NO_FRINGE_BITMAP
:
1480 case LEFT_TRUNCATION_BITMAP
:
1486 case OVERLAY_ARROW_BITMAP
:
1492 case RIGHT_TRUNCATION_BITMAP
:
1498 case CONTINUED_LINE_BITMAP
:
1499 wd
= continued_width
;
1500 h
= continued_height
;
1501 bits
= continued_bits
;
1504 case CONTINUATION_LINE_BITMAP
:
1505 wd
= continuation_width
;
1506 h
= continuation_height
;
1507 bits
= continuation_bits
;
1510 case ZV_LINE_BITMAP
:
1512 h
= zv_height
- (y
% zv_period
);
1513 bits
= zv_bits
+ (y
% zv_period
);
1520 /* Clip bitmap if too high. */
1521 if (h
> row
->height
)
1524 /* Set dy to the offset in the row to start drawing the bitmap. */
1525 dy
= (row
->height
- h
) / 2;
1527 /* Draw the bitmap. */
1528 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
1529 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1531 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
1536 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
1537 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
1538 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
1540 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
1541 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
1543 /* If W has a vertical border to its left, don't draw over it. */
1544 int border
= ((XFASTINT (w
->left
) > 0
1545 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1547 b1
= (window_box_left (w
, -1)
1548 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
1550 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
1555 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
1556 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
1557 x
= (window_box_right (w
, -1)
1558 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
1559 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
1561 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
1563 b1
= window_box_right (w
, -1);
1564 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
1570 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1572 gcv
.foreground
= face
->background
;
1574 #if 0 /* MAC_TODO: stipple */
1575 /* In case the same realized face is used for fringes and
1576 for something displayed in the text (e.g. face `region' on
1577 mono-displays, the fill style may have been changed to
1578 FillSolid in x_draw_glyph_string_background. */
1580 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1582 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1585 XFillRectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1588 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1591 row
->visible_height
);
1593 #if 0 /* MAC_TODO: stipple */
1595 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1599 if (which
== NO_FRINGE_BITMAP
)
1601 mac_reset_clipping (display
, window
);
1605 mac_create_bitmap_from_bitmap_data (&bitmap
, bits
, wd
, h
);
1606 gcv
.foreground
= face
->foreground
;
1607 gcv
.background
= face
->background
;
1609 mac_draw_bitmap (display
, window
, &gcv
, x
, y
+ dy
, &bitmap
);
1611 mac_free_bitmap (&bitmap
);
1612 mac_reset_clipping (display
, window
);
1616 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
1617 function with input blocked. */
1620 x_draw_row_fringe_bitmaps (w
, row
)
1622 struct glyph_row
*row
;
1624 struct frame
*f
= XFRAME (w
->frame
);
1625 enum fringe_bitmap_type bitmap
;
1627 xassert (interrupt_input_blocked
);
1629 /* If row is completely invisible, because of vscrolling, we
1630 don't have to draw anything. */
1631 if (row
->visible_height
<= 0)
1634 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1636 /* Decide which bitmap to draw in the left fringe. */
1637 if (row
->overlay_arrow_p
)
1638 bitmap
= OVERLAY_ARROW_BITMAP
;
1639 else if (row
->truncated_on_left_p
)
1640 bitmap
= LEFT_TRUNCATION_BITMAP
;
1641 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1642 bitmap
= CONTINUATION_LINE_BITMAP
;
1643 else if (row
->indicate_empty_line_p
)
1644 bitmap
= ZV_LINE_BITMAP
;
1646 bitmap
= NO_FRINGE_BITMAP
;
1648 x_draw_fringe_bitmap (w
, row
, bitmap
, 1);
1651 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1653 /* Decide which bitmap to draw in the right fringe. */
1654 if (row
->truncated_on_right_p
)
1655 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1656 else if (row
->continued_p
)
1657 bitmap
= CONTINUED_LINE_BITMAP
;
1658 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1659 bitmap
= ZV_LINE_BITMAP
;
1661 bitmap
= NO_FRINGE_BITMAP
;
1663 x_draw_fringe_bitmap (w
, row
, bitmap
, 0);
1668 /* This is called when starting Emacs and when restarting after
1669 suspend. When starting Emacs, no window is mapped. And nothing
1670 must be done to Emacs's own window if it is suspended (though that
1674 XTset_terminal_modes ()
1678 /* This is called when exiting or suspending Emacs. Exiting will make
1679 the windows go away, and suspending requires no action. */
1682 XTreset_terminal_modes ()
1688 /***********************************************************************
1690 ***********************************************************************/
1692 /* Set the global variable output_cursor to CURSOR. All cursor
1693 positions are relative to updated_window. */
1696 set_output_cursor (cursor
)
1697 struct cursor_pos
*cursor
;
1699 output_cursor
.hpos
= cursor
->hpos
;
1700 output_cursor
.vpos
= cursor
->vpos
;
1701 output_cursor
.x
= cursor
->x
;
1702 output_cursor
.y
= cursor
->y
;
1706 /* Set a nominal cursor position.
1708 HPOS and VPOS are column/row positions in a window glyph matrix. X
1709 and Y are window text area relative pixel positions.
1711 If this is done during an update, updated_window will contain the
1712 window that is being updated and the position is the future output
1713 cursor position for that window. If updated_window is null, use
1714 selected_window and display the cursor at the given position. */
1717 XTcursor_to (vpos
, hpos
, y
, x
)
1718 int vpos
, hpos
, y
, x
;
1722 /* If updated_window is not set, work on selected_window. */
1726 w
= XWINDOW (selected_window
);
1728 /* Set the output cursor. */
1729 output_cursor
.hpos
= hpos
;
1730 output_cursor
.vpos
= vpos
;
1731 output_cursor
.x
= x
;
1732 output_cursor
.y
= y
;
1734 /* If not called as part of an update, really display the cursor.
1735 This will also set the cursor position of W. */
1736 if (updated_window
== NULL
)
1739 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1740 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1747 /***********************************************************************
1749 ***********************************************************************/
1751 /* Function prototypes of this page. */
1753 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1757 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1758 int, XChar2b
*, int));
1759 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1760 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1761 static void x_append_glyph
P_ ((struct it
*));
1762 static void x_append_composite_glyph
P_ ((struct it
*));
1763 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1765 static void x_produce_glyphs
P_ ((struct it
*));
1766 static void x_produce_image_glyph
P_ ((struct it
*it
));
1769 /* Return a pointer to per-char metric information in FONT of a
1770 character pointed by B which is a pointer to an XChar2b. */
1772 #define PER_CHAR_METRIC(font, b) \
1774 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1775 + (((font)->min_byte1 || (font)->max_byte1) \
1776 ? (((b)->byte1 - (font)->min_byte1) \
1777 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1779 : &((font)->max_bounds))
1782 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1783 is not contained in the font. */
1785 static INLINE XCharStruct
*
1786 x_per_char_metric (font
, char2b
)
1790 /* The result metric information. */
1791 XCharStruct
*pcm
= NULL
;
1793 xassert (font
&& char2b
);
1795 if (font
->per_char
!= NULL
)
1797 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1799 /* min_char_or_byte2 specifies the linear character index
1800 corresponding to the first element of the per_char array,
1801 max_char_or_byte2 is the index of the last character. A
1802 character with non-zero CHAR2B->byte1 is not in the font.
1803 A character with byte2 less than min_char_or_byte2 or
1804 greater max_char_or_byte2 is not in the font. */
1805 if (char2b
->byte1
== 0
1806 && char2b
->byte2
>= font
->min_char_or_byte2
1807 && char2b
->byte2
<= font
->max_char_or_byte2
)
1808 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1812 /* If either min_byte1 or max_byte1 are nonzero, both
1813 min_char_or_byte2 and max_char_or_byte2 are less than
1814 256, and the 2-byte character index values corresponding
1815 to the per_char array element N (counting from 0) are:
1817 byte1 = N/D + min_byte1
1818 byte2 = N\D + min_char_or_byte2
1822 D = max_char_or_byte2 - min_char_or_byte2 + 1
1823 / = integer division
1824 \ = integer modulus */
1825 if (char2b
->byte1
>= font
->min_byte1
1826 && char2b
->byte1
<= font
->max_byte1
1827 && char2b
->byte2
>= font
->min_char_or_byte2
1828 && char2b
->byte2
<= font
->max_char_or_byte2
)
1830 pcm
= (font
->per_char
1831 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1832 * (char2b
->byte1
- font
->min_byte1
))
1833 + (char2b
->byte2
- font
->min_char_or_byte2
));
1839 /* If the per_char pointer is null, all glyphs between the first
1840 and last character indexes inclusive have the same
1841 information, as given by both min_bounds and max_bounds. */
1842 if (char2b
->byte2
>= font
->min_char_or_byte2
1843 && char2b
->byte2
<= font
->max_char_or_byte2
)
1844 pcm
= &font
->max_bounds
;
1847 return ((pcm
== NULL
1848 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1853 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1854 the two-byte form of C. Encoding is returned in *CHAR2B. */
1857 x_encode_char (c
, char2b
, font_info
)
1860 struct font_info
*font_info
;
1862 int charset
= CHAR_CHARSET (c
);
1863 XFontStruct
*font
= font_info
->font
;
1865 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1866 This may be either a program in a special encoder language or a
1868 if (font_info
->font_encoder
)
1870 /* It's a program. */
1871 struct ccl_program
*ccl
= font_info
->font_encoder
;
1873 if (CHARSET_DIMENSION (charset
) == 1)
1875 ccl
->reg
[0] = charset
;
1876 ccl
->reg
[1] = char2b
->byte2
;
1880 ccl
->reg
[0] = charset
;
1881 ccl
->reg
[1] = char2b
->byte1
;
1882 ccl
->reg
[2] = char2b
->byte2
;
1885 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1887 /* We assume that MSBs are appropriately set/reset by CCL
1889 if (font
->max_byte1
== 0) /* 1-byte font */
1890 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1892 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1894 else if (font_info
->encoding
[charset
])
1896 /* Fixed encoding scheme. See fontset.h for the meaning of the
1897 encoding numbers. */
1898 int enc
= font_info
->encoding
[charset
];
1900 if ((enc
== 1 || enc
== 2)
1901 && CHARSET_DIMENSION (charset
) == 2)
1902 char2b
->byte1
|= 0x80;
1904 if (enc
== 1 || enc
== 3)
1905 char2b
->byte2
|= 0x80;
1911 ENCODE_SJIS (char2b
->byte1
, char2b
->byte2
, sjis1
, sjis2
);
1912 char2b
->byte1
= sjis1
;
1913 char2b
->byte2
= sjis2
;
1919 /* Get face and two-byte form of character C in face FACE_ID on frame
1920 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1921 means we want to display multibyte text. Value is a pointer to a
1922 realized face that is ready for display. */
1924 static INLINE
struct face
*
1925 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1931 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1935 /* Unibyte case. We don't have to encode, but we have to make
1936 sure to use a face suitable for unibyte. */
1939 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1940 face
= FACE_FROM_ID (f
, face_id
);
1942 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1944 /* Case of ASCII in a face known to fit ASCII. */
1950 int c1
, c2
, charset
;
1952 /* Split characters into bytes. If c2 is -1 afterwards, C is
1953 really a one-byte character so that byte1 is zero. */
1954 SPLIT_CHAR (c
, charset
, c1
, c2
);
1956 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1958 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1960 /* Maybe encode the character in *CHAR2B. */
1961 if (face
->font
!= NULL
)
1963 struct font_info
*font_info
1964 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1966 x_encode_char (c
, char2b
, font_info
);
1970 /* Make sure X resources of the face are allocated. */
1971 xassert (face
!= NULL
);
1972 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1978 /* Get face and two-byte form of character glyph GLYPH on frame F.
1979 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1980 a pointer to a realized face that is ready for display. */
1982 static INLINE
struct face
*
1983 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1985 struct glyph
*glyph
;
1991 xassert (glyph
->type
== CHAR_GLYPH
);
1992 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1997 if (!glyph
->multibyte_p
)
1999 /* Unibyte case. We don't have to encode, but we have to make
2000 sure to use a face suitable for unibyte. */
2002 char2b
->byte2
= glyph
->u
.ch
;
2004 else if (glyph
->u
.ch
< 128
2005 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
2007 /* Case of ASCII in a face known to fit ASCII. */
2009 char2b
->byte2
= glyph
->u
.ch
;
2013 int c1
, c2
, charset
;
2015 /* Split characters into bytes. If c2 is -1 afterwards, C is
2016 really a one-byte character so that byte1 is zero. */
2017 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
2019 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
2021 char2b
->byte1
= 0, char2b
->byte2
= c1
;
2023 /* Maybe encode the character in *CHAR2B. */
2024 if (charset
!= CHARSET_ASCII
)
2026 struct font_info
*font_info
2027 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2030 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
2033 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
2038 /* Make sure X resources of the face are allocated. */
2039 xassert (face
!= NULL
);
2040 PREPARE_FACE_FOR_DISPLAY (f
, face
);
2045 /* Store one glyph for IT->char_to_display in IT->glyph_row.
2046 Called from x_produce_glyphs when IT->glyph_row is non-null. */
2052 struct glyph
*glyph
;
2053 enum glyph_row_area area
= it
->area
;
2055 xassert (it
->glyph_row
);
2056 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
2058 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2059 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2061 glyph
->charpos
= CHARPOS (it
->position
);
2062 glyph
->object
= it
->object
;
2063 glyph
->pixel_width
= it
->pixel_width
;
2064 glyph
->voffset
= it
->voffset
;
2065 glyph
->type
= CHAR_GLYPH
;
2066 glyph
->multibyte_p
= it
->multibyte_p
;
2067 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2068 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2069 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
2070 || it
->phys_descent
> it
->descent
);
2071 glyph
->padding_p
= 0;
2072 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
2073 glyph
->face_id
= it
->face_id
;
2074 glyph
->u
.ch
= it
->char_to_display
;
2075 ++it
->glyph_row
->used
[area
];
2079 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
2080 Called from x_produce_glyphs when IT->glyph_row is non-null. */
2083 x_append_composite_glyph (it
)
2086 struct glyph
*glyph
;
2087 enum glyph_row_area area
= it
->area
;
2089 xassert (it
->glyph_row
);
2091 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2092 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2094 glyph
->charpos
= CHARPOS (it
->position
);
2095 glyph
->object
= it
->object
;
2096 glyph
->pixel_width
= it
->pixel_width
;
2097 glyph
->voffset
= it
->voffset
;
2098 glyph
->type
= COMPOSITE_GLYPH
;
2099 glyph
->multibyte_p
= it
->multibyte_p
;
2100 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2101 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2102 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
2103 || it
->phys_descent
> it
->descent
);
2104 glyph
->padding_p
= 0;
2105 glyph
->glyph_not_available_p
= 0;
2106 glyph
->face_id
= it
->face_id
;
2107 glyph
->u
.cmp_id
= it
->cmp_id
;
2108 ++it
->glyph_row
->used
[area
];
2113 /* Change IT->ascent and IT->height according to the setting of
2117 take_vertical_position_into_account (it
)
2122 if (it
->voffset
< 0)
2123 /* Increase the ascent so that we can display the text higher
2125 it
->ascent
+= abs (it
->voffset
);
2127 /* Increase the descent so that we can display the text lower
2129 it
->descent
+= it
->voffset
;
2134 /* Produce glyphs/get display metrics for the image IT is loaded with.
2135 See the description of struct display_iterator in dispextern.h for
2136 an overview of struct display_iterator. */
2139 x_produce_image_glyph (it
)
2145 xassert (it
->what
== IT_IMAGE
);
2147 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2148 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
2151 /* Make sure X resources of the face and image are loaded. */
2152 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
2153 prepare_image_for_display (it
->f
, img
);
2155 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
2156 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
2157 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
2161 if (face
->box
!= FACE_NO_BOX
)
2163 if (face
->box_line_width
> 0)
2165 it
->ascent
+= face
->box_line_width
;
2166 it
->descent
+= face
->box_line_width
;
2169 if (it
->start_of_box_run_p
)
2170 it
->pixel_width
+= abs (face
->box_line_width
);
2171 if (it
->end_of_box_run_p
)
2172 it
->pixel_width
+= abs (face
->box_line_width
);
2175 take_vertical_position_into_account (it
);
2179 struct glyph
*glyph
;
2180 enum glyph_row_area area
= it
->area
;
2182 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2183 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2185 glyph
->charpos
= CHARPOS (it
->position
);
2186 glyph
->object
= it
->object
;
2187 glyph
->pixel_width
= it
->pixel_width
;
2188 glyph
->voffset
= it
->voffset
;
2189 glyph
->type
= IMAGE_GLYPH
;
2190 glyph
->multibyte_p
= it
->multibyte_p
;
2191 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2192 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2193 glyph
->overlaps_vertically_p
= 0;
2194 glyph
->padding_p
= 0;
2195 glyph
->glyph_not_available_p
= 0;
2196 glyph
->face_id
= it
->face_id
;
2197 glyph
->u
.img_id
= img
->id
;
2198 ++it
->glyph_row
->used
[area
];
2204 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
2205 of the glyph, WIDTH and HEIGHT are the width and height of the
2206 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
2207 ascent of the glyph (0 <= ASCENT <= 1). */
2210 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
2216 struct glyph
*glyph
;
2217 enum glyph_row_area area
= it
->area
;
2219 xassert (ascent
>= 0 && ascent
<= 1);
2221 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2222 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2224 glyph
->charpos
= CHARPOS (it
->position
);
2225 glyph
->object
= object
;
2226 glyph
->pixel_width
= width
;
2227 glyph
->voffset
= it
->voffset
;
2228 glyph
->type
= STRETCH_GLYPH
;
2229 glyph
->multibyte_p
= it
->multibyte_p
;
2230 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2231 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2232 glyph
->overlaps_vertically_p
= 0;
2233 glyph
->padding_p
= 0;
2234 glyph
->glyph_not_available_p
= 0;
2235 glyph
->face_id
= it
->face_id
;
2236 glyph
->u
.stretch
.ascent
= height
* ascent
;
2237 glyph
->u
.stretch
.height
= height
;
2238 ++it
->glyph_row
->used
[area
];
2243 /* Produce a stretch glyph for iterator IT. IT->object is the value
2244 of the glyph property displayed. The value must be a list
2245 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
2248 1. `:width WIDTH' specifies that the space should be WIDTH *
2249 canonical char width wide. WIDTH may be an integer or floating
2252 2. `:relative-width FACTOR' specifies that the width of the stretch
2253 should be computed from the width of the first character having the
2254 `glyph' property, and should be FACTOR times that width.
2256 3. `:align-to HPOS' specifies that the space should be wide enough
2257 to reach HPOS, a value in canonical character units.
2259 Exactly one of the above pairs must be present.
2261 4. `:height HEIGHT' specifies that the height of the stretch produced
2262 should be HEIGHT, measured in canonical character units.
2264 5. `:relative-height FACTOR' specifies that the height of the
2265 stretch should be FACTOR times the height of the characters having
2268 Either none or exactly one of 4 or 5 must be present.
2270 6. `:ascent ASCENT' specifies that ASCENT percent of the height
2271 of the stretch should be used for the ascent of the stretch.
2272 ASCENT must be in the range 0 <= ASCENT <= 100. */
2275 ((INTEGERP (X) || FLOATP (X)) \
2281 x_produce_stretch_glyph (it
)
2284 /* (space :width WIDTH :height HEIGHT. */
2286 extern Lisp_Object Qspace
;
2288 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
2289 extern Lisp_Object QCrelative_width
, QCrelative_height
;
2290 extern Lisp_Object QCalign_to
;
2291 Lisp_Object prop
, plist
;
2292 double width
= 0, height
= 0, ascent
= 0;
2293 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2294 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
2296 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
2298 /* List should start with `space'. */
2299 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
2300 plist
= XCDR (it
->object
);
2302 /* Compute the width of the stretch. */
2303 if (prop
= Fplist_get (plist
, QCwidth
),
2305 /* Absolute width `:width WIDTH' specified and valid. */
2306 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
2307 else if (prop
= Fplist_get (plist
, QCrelative_width
),
2310 /* Relative width `:relative-width FACTOR' specified and valid.
2311 Compute the width of the characters having the `glyph'
2314 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
2317 if (it
->multibyte_p
)
2319 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
2320 - IT_BYTEPOS (*it
));
2321 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
2324 it2
.c
= *p
, it2
.len
= 1;
2326 it2
.glyph_row
= NULL
;
2327 it2
.what
= IT_CHARACTER
;
2328 x_produce_glyphs (&it2
);
2329 width
= NUMVAL (prop
) * it2
.pixel_width
;
2331 else if (prop
= Fplist_get (plist
, QCalign_to
),
2333 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
2335 /* Nothing specified -> width defaults to canonical char width. */
2336 width
= CANON_X_UNIT (it
->f
);
2338 /* Compute height. */
2339 if (prop
= Fplist_get (plist
, QCheight
),
2341 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
2342 else if (prop
= Fplist_get (plist
, QCrelative_height
),
2344 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
2346 height
= FONT_HEIGHT (font
);
2348 /* Compute percentage of height used for ascent. If
2349 `:ascent ASCENT' is present and valid, use that. Otherwise,
2350 derive the ascent from the font in use. */
2351 if (prop
= Fplist_get (plist
, QCascent
),
2352 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
2353 ascent
= NUMVAL (prop
) / 100.0;
2355 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
2364 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
2365 if (!STRINGP (object
))
2366 object
= it
->w
->buffer
;
2367 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
2370 it
->pixel_width
= width
;
2371 it
->ascent
= it
->phys_ascent
= height
* ascent
;
2372 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
2375 if (face
->box
!= FACE_NO_BOX
)
2377 if (face
->box_line_width
> 0)
2379 it
->ascent
+= face
->box_line_width
;
2380 it
->descent
+= face
->box_line_width
;
2383 if (it
->start_of_box_run_p
)
2384 it
->pixel_width
+= abs (face
->box_line_width
);
2385 if (it
->end_of_box_run_p
)
2386 it
->pixel_width
+= abs (face
->box_line_width
);
2389 take_vertical_position_into_account (it
);
2392 /* Return proper value to be used as baseline offset of font that has
2393 ASCENT and DESCENT to draw characters by the font at the vertical
2394 center of the line of frame F.
2396 Here, out task is to find the value of BOFF in the following figure;
2398 -------------------------+-----------+-
2399 -+-+---------+-+ | |
2401 | | | | F_ASCENT F_HEIGHT
2404 | | |-|-+------+-----------|------- baseline
2406 | |---------|-+-+ | |
2408 -+-+---------+-+ F_DESCENT |
2409 -------------------------+-----------+-
2411 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
2412 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
2413 DESCENT = FONT->descent
2414 HEIGHT = FONT_HEIGHT (FONT)
2415 F_DESCENT = (F->output_data.x->font->descent
2416 - F->output_data.x->baseline_offset)
2417 F_HEIGHT = FRAME_LINE_HEIGHT (F)
2420 #define VCENTER_BASELINE_OFFSET(FONT, F) \
2421 (FONT_DESCENT (FONT) \
2422 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
2423 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
2424 - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
2426 /* Produce glyphs/get display metrics for the display element IT is
2427 loaded with. See the description of struct display_iterator in
2428 dispextern.h for an overview of struct display_iterator. */
2431 x_produce_glyphs (it
)
2434 it
->glyph_not_available_p
= 0;
2436 if (it
->what
== IT_CHARACTER
)
2440 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2442 int font_not_found_p
;
2443 struct font_info
*font_info
;
2444 int boff
; /* baseline offset */
2445 /* We may change it->multibyte_p upon unibyte<->multibyte
2446 conversion. So, save the current value now and restore it
2449 Note: It seems that we don't have to record multibyte_p in
2450 struct glyph because the character code itself tells if or
2451 not the character is multibyte. Thus, in the future, we must
2452 consider eliminating the field `multibyte_p' in the struct
2455 int saved_multibyte_p
= it
->multibyte_p
;
2457 /* Maybe translate single-byte characters to multibyte, or the
2459 it
->char_to_display
= it
->c
;
2460 if (!ASCII_BYTE_P (it
->c
))
2462 if (unibyte_display_via_language_environment
2463 && SINGLE_BYTE_CHAR_P (it
->c
)
2465 || !NILP (Vnonascii_translation_table
)))
2467 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2468 it
->multibyte_p
= 1;
2469 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2470 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2472 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
2473 && !it
->multibyte_p
)
2475 it
->multibyte_p
= 1;
2476 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2477 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2481 /* Get font to use. Encode IT->char_to_display. */
2482 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2483 it
->face_id
, &char2b
,
2487 /* When no suitable font found, use the default font. */
2488 font_not_found_p
= font
== NULL
;
2489 if (font_not_found_p
)
2491 font
= FRAME_FONT (it
->f
);
2492 boff
= it
->f
->output_data
.mac
->baseline_offset
;
2497 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2498 boff
= font_info
->baseline_offset
;
2499 if (font_info
->vertical_centering
)
2500 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2503 if (it
->char_to_display
>= ' '
2504 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
2506 /* Either unibyte or ASCII. */
2511 pcm
= x_per_char_metric (font
, &char2b
);
2512 it
->ascent
= FONT_BASE (font
) + boff
;
2513 it
->descent
= FONT_DESCENT (font
) - boff
;
2517 it
->phys_ascent
= pcm
->ascent
+ boff
;
2518 it
->phys_descent
= pcm
->descent
- boff
;
2519 it
->pixel_width
= pcm
->width
;
2523 it
->glyph_not_available_p
= 1;
2524 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2525 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2526 it
->pixel_width
= FONT_WIDTH (font
);
2529 /* If this is a space inside a region of text with
2530 `space-width' property, change its width. */
2531 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
2533 it
->pixel_width
*= XFLOATINT (it
->space_width
);
2535 /* If face has a box, add the box thickness to the character
2536 height. If character has a box line to the left and/or
2537 right, add the box line width to the character's width. */
2538 if (face
->box
!= FACE_NO_BOX
)
2540 int thick
= face
->box_line_width
;
2544 it
->ascent
+= thick
;
2545 it
->descent
+= thick
;
2550 if (it
->start_of_box_run_p
)
2551 it
->pixel_width
+= thick
;
2552 if (it
->end_of_box_run_p
)
2553 it
->pixel_width
+= thick
;
2556 /* If face has an overline, add the height of the overline
2557 (1 pixel) and a 1 pixel margin to the character height. */
2558 if (face
->overline_p
)
2561 take_vertical_position_into_account (it
);
2563 /* If we have to actually produce glyphs, do it. */
2568 /* Translate a space with a `space-width' property
2569 into a stretch glyph. */
2570 double ascent
= (double) FONT_BASE (font
)
2571 / FONT_HEIGHT (font
);
2572 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2573 it
->ascent
+ it
->descent
, ascent
);
2576 x_append_glyph (it
);
2578 /* If characters with lbearing or rbearing are displayed
2579 in this line, record that fact in a flag of the
2580 glyph row. This is used to optimize X output code. */
2581 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
2582 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2585 else if (it
->char_to_display
== '\n')
2587 /* A newline has no width but we need the height of the line. */
2588 it
->pixel_width
= 0;
2590 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2591 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2593 if (face
->box
!= FACE_NO_BOX
2594 && face
->box_line_width
> 0)
2596 it
->ascent
+= face
->box_line_width
;
2597 it
->descent
+= face
->box_line_width
;
2600 else if (it
->char_to_display
== '\t')
2602 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
2603 int x
= it
->current_x
+ it
->continuation_lines_width
;
2604 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
2606 /* If the distance from the current position to the next tab
2607 stop is less than a canonical character width, use the
2608 tab stop after that. */
2609 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
2610 next_tab_x
+= tab_width
;
2612 it
->pixel_width
= next_tab_x
- x
;
2614 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2615 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2619 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2620 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2621 it
->ascent
+ it
->descent
, ascent
);
2626 /* A multi-byte character. Assume that the display width of the
2627 character is the width of the character multiplied by the
2628 width of the font. */
2630 /* If we found a font, this font should give us the right
2631 metrics. If we didn't find a font, use the frame's
2632 default font and calculate the width of the character
2633 from the charset width; this is what old redisplay code
2635 pcm
= x_per_char_metric (font
, &char2b
);
2636 if (font_not_found_p
|| !pcm
)
2638 int charset
= CHAR_CHARSET (it
->char_to_display
);
2640 it
->glyph_not_available_p
= 1;
2641 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2642 * CHARSET_WIDTH (charset
));
2643 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2644 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2648 it
->pixel_width
= pcm
->width
;
2649 it
->phys_ascent
= pcm
->ascent
+ boff
;
2650 it
->phys_descent
= pcm
->descent
- boff
;
2652 && (pcm
->lbearing
< 0
2653 || pcm
->rbearing
> pcm
->width
))
2654 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2657 it
->ascent
= FONT_BASE (font
) + boff
;
2658 it
->descent
= FONT_DESCENT (font
) - boff
;
2659 if (face
->box
!= FACE_NO_BOX
)
2661 int thick
= face
->box_line_width
;
2665 it
->ascent
+= thick
;
2666 it
->descent
+= thick
;
2671 if (it
->start_of_box_run_p
)
2672 it
->pixel_width
+= thick
;
2673 if (it
->end_of_box_run_p
)
2674 it
->pixel_width
+= thick
;
2677 /* If face has an overline, add the height of the overline
2678 (1 pixel) and a 1 pixel margin to the character height. */
2679 if (face
->overline_p
)
2682 take_vertical_position_into_account (it
);
2685 x_append_glyph (it
);
2687 it
->multibyte_p
= saved_multibyte_p
;
2689 else if (it
->what
== IT_COMPOSITION
)
2691 /* Note: A composition is represented as one glyph in the
2692 glyph matrix. There are no padding glyphs. */
2695 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2697 int font_not_found_p
;
2698 struct font_info
*font_info
;
2699 int boff
; /* baseline offset */
2700 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2702 /* Maybe translate single-byte characters to multibyte. */
2703 it
->char_to_display
= it
->c
;
2704 if (unibyte_display_via_language_environment
2705 && SINGLE_BYTE_CHAR_P (it
->c
)
2708 && !NILP (Vnonascii_translation_table
))))
2710 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2713 /* Get face and font to use. Encode IT->char_to_display. */
2714 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2715 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2716 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2717 it
->face_id
, &char2b
, it
->multibyte_p
);
2720 /* When no suitable font found, use the default font. */
2721 font_not_found_p
= font
== NULL
;
2722 if (font_not_found_p
)
2724 font
= FRAME_FONT (it
->f
);
2725 boff
= it
->f
->output_data
.mac
->baseline_offset
;
2730 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2731 boff
= font_info
->baseline_offset
;
2732 if (font_info
->vertical_centering
)
2733 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2736 /* There are no padding glyphs, so there is only one glyph to
2737 produce for the composition. Important is that pixel_width,
2738 ascent and descent are the values of what is drawn by
2739 draw_glyphs (i.e. the values of the overall glyphs composed). */
2742 /* If we have not yet calculated pixel size data of glyphs of
2743 the composition for the current face font, calculate them
2744 now. Theoretically, we have to check all fonts for the
2745 glyphs, but that requires much time and memory space. So,
2746 here we check only the font of the first glyph. This leads
2747 to incorrect display very rarely, and C-l (recenter) can
2748 correct the display anyway. */
2749 if (cmp
->font
!= (void *) font
)
2751 /* Ascent and descent of the font of the first character of
2752 this composition (adjusted by baseline offset). Ascent
2753 and descent of overall glyphs should not be less than
2754 them respectively. */
2755 int font_ascent
= FONT_BASE (font
) + boff
;
2756 int font_descent
= FONT_DESCENT (font
) - boff
;
2757 /* Bounding box of the overall glyphs. */
2758 int leftmost
, rightmost
, lowest
, highest
;
2759 int i
, width
, ascent
, descent
;
2761 cmp
->font
= (void *) font
;
2763 /* Initialize the bounding box. */
2764 pcm
= x_per_char_metric (font
, &char2b
);
2768 ascent
= pcm
->ascent
;
2769 descent
= pcm
->descent
;
2773 width
= FONT_WIDTH (font
);
2774 ascent
= FONT_BASE (font
);
2775 descent
= FONT_DESCENT (font
);
2779 lowest
= - descent
+ boff
;
2780 highest
= ascent
+ boff
;
2784 && font_info
->default_ascent
2785 && CHAR_TABLE_P (Vuse_default_ascent
)
2786 && !NILP (Faref (Vuse_default_ascent
,
2787 make_number (it
->char_to_display
))))
2788 highest
= font_info
->default_ascent
+ boff
;
2790 /* Draw the first glyph at the normal position. It may be
2791 shifted to right later if some other glyphs are drawn at
2793 cmp
->offsets
[0] = 0;
2794 cmp
->offsets
[1] = boff
;
2796 /* Set cmp->offsets for the remaining glyphs. */
2797 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2799 int left
, right
, btm
, top
;
2800 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2801 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2803 face
= FACE_FROM_ID (it
->f
, face_id
);
2804 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2809 font
= FRAME_FONT (it
->f
);
2810 boff
= it
->f
->output_data
.mac
->baseline_offset
;
2816 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2817 boff
= font_info
->baseline_offset
;
2818 if (font_info
->vertical_centering
)
2819 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2822 pcm
= x_per_char_metric (font
, &char2b
);
2826 ascent
= pcm
->ascent
;
2827 descent
= pcm
->descent
;
2831 width
= FONT_WIDTH (font
);
2836 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2838 /* Relative composition with or without
2840 left
= (leftmost
+ rightmost
- width
) / 2;
2841 btm
= - descent
+ boff
;
2842 if (font_info
&& font_info
->relative_compose
2843 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2844 || NILP (Faref (Vignore_relative_composition
,
2845 make_number (ch
)))))
2848 if (- descent
>= font_info
->relative_compose
)
2849 /* One extra pixel between two glyphs. */
2851 else if (ascent
<= 0)
2852 /* One extra pixel between two glyphs. */
2853 btm
= lowest
- 1 - ascent
- descent
;
2858 /* A composition rule is specified by an integer
2859 value that encodes global and new reference
2860 points (GREF and NREF). GREF and NREF are
2861 specified by numbers as below:
2869 ---3---4---5--- baseline
2871 6---7---8 -- descent
2873 int rule
= COMPOSITION_RULE (cmp
, i
);
2874 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2876 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2877 grefx
= gref
% 3, nrefx
= nref
% 3;
2878 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2881 + grefx
* (rightmost
- leftmost
) / 2
2882 - nrefx
* width
/ 2);
2883 btm
= ((grefy
== 0 ? highest
2885 : grefy
== 2 ? lowest
2886 : (highest
+ lowest
) / 2)
2887 - (nrefy
== 0 ? ascent
+ descent
2888 : nrefy
== 1 ? descent
- boff
2890 : (ascent
+ descent
) / 2));
2893 cmp
->offsets
[i
* 2] = left
;
2894 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2896 /* Update the bounding box of the overall glyphs. */
2897 right
= left
+ width
;
2898 top
= btm
+ descent
+ ascent
;
2899 if (left
< leftmost
)
2901 if (right
> rightmost
)
2909 /* If there are glyphs whose x-offsets are negative,
2910 shift all glyphs to the right and make all x-offsets
2914 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2915 cmp
->offsets
[i
* 2] -= leftmost
;
2916 rightmost
-= leftmost
;
2919 cmp
->pixel_width
= rightmost
;
2920 cmp
->ascent
= highest
;
2921 cmp
->descent
= - lowest
;
2922 if (cmp
->ascent
< font_ascent
)
2923 cmp
->ascent
= font_ascent
;
2924 if (cmp
->descent
< font_descent
)
2925 cmp
->descent
= font_descent
;
2928 it
->pixel_width
= cmp
->pixel_width
;
2929 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2930 it
->descent
= it
->phys_descent
= cmp
->descent
;
2932 if (face
->box
!= FACE_NO_BOX
)
2934 int thick
= face
->box_line_width
;
2938 it
->ascent
+= thick
;
2939 it
->descent
+= thick
;
2944 if (it
->start_of_box_run_p
)
2945 it
->pixel_width
+= thick
;
2946 if (it
->end_of_box_run_p
)
2947 it
->pixel_width
+= thick
;
2950 /* If face has an overline, add the height of the overline
2951 (1 pixel) and a 1 pixel margin to the character height. */
2952 if (face
->overline_p
)
2955 take_vertical_position_into_account (it
);
2958 x_append_composite_glyph (it
);
2960 else if (it
->what
== IT_IMAGE
)
2961 x_produce_image_glyph (it
);
2962 else if (it
->what
== IT_STRETCH
)
2963 x_produce_stretch_glyph (it
);
2965 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2966 because this isn't true for images with `:ascent 100'. */
2967 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2968 if (it
->area
== TEXT_AREA
)
2969 it
->current_x
+= it
->pixel_width
;
2971 it
->descent
+= it
->extra_line_spacing
;
2973 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2974 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2975 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2976 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2980 /* Estimate the pixel height of the mode or top line on frame F.
2981 FACE_ID specifies what line's height to estimate. */
2984 x_estimate_mode_line_height (f
, face_id
)
2986 enum face_id face_id
;
2988 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2990 /* This function is called so early when Emacs starts that the face
2991 cache and mode line face are not yet initialized. */
2992 if (FRAME_FACE_CACHE (f
))
2994 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2998 height
= FONT_HEIGHT (face
->font
);
2999 if (face
->box_line_width
> 0)
3000 height
+= 2 * face
->box_line_width
;
3008 /***********************************************************************
3010 ***********************************************************************/
3012 /* A sequence of glyphs to be drawn in the same face.
3014 This data structure is not really completely X specific, so it
3015 could possibly, at least partially, be useful for other systems. It
3016 is currently not part of the external redisplay interface because
3017 it's not clear what other systems will need. */
3021 /* X-origin of the string. */
3024 /* Y-origin and y-position of the base line of this string. */
3027 /* The width of the string, not including a face extension. */
3030 /* The width of the string, including a face extension. */
3031 int background_width
;
3033 /* The height of this string. This is the height of the line this
3034 string is drawn in, and can be different from the height of the
3035 font the string is drawn in. */
3038 /* Number of pixels this string overwrites in front of its x-origin.
3039 This number is zero if the string has an lbearing >= 0; it is
3040 -lbearing, if the string has an lbearing < 0. */
3043 /* Number of pixels this string overwrites past its right-most
3044 nominal x-position, i.e. x + width. Zero if the string's
3045 rbearing is <= its nominal width, rbearing - width otherwise. */
3048 /* The frame on which the glyph string is drawn. */
3051 /* The window on which the glyph string is drawn. */
3054 /* X display and window for convenience. */
3058 /* The glyph row for which this string was built. It determines the
3059 y-origin and height of the string. */
3060 struct glyph_row
*row
;
3062 /* The area within row. */
3063 enum glyph_row_area area
;
3065 /* Characters to be drawn, and number of characters. */
3069 /* A face-override for drawing cursors, mouse face and similar. */
3070 enum draw_glyphs_face hl
;
3072 /* Face in which this string is to be drawn. */
3075 /* Font in which this string is to be drawn. */
3078 /* Font info for this string. */
3079 struct font_info
*font_info
;
3081 /* Non-null means this string describes (part of) a composition.
3082 All characters from char2b are drawn composed. */
3083 struct composition
*cmp
;
3085 /* Index of this glyph string's first character in the glyph
3086 definition of CMP. If this is zero, this glyph string describes
3087 the first character of a composition. */
3090 /* 1 means this glyph strings face has to be drawn to the right end
3091 of the window's drawing area. */
3092 unsigned extends_to_end_of_line_p
: 1;
3094 /* 1 means the background of this string has been drawn. */
3095 unsigned background_filled_p
: 1;
3097 /* 1 means glyph string must be drawn with 16-bit functions. */
3098 unsigned two_byte_p
: 1;
3100 /* 1 means that the original font determined for drawing this glyph
3101 string could not be loaded. The member `font' has been set to
3102 the frame's default font in this case. */
3103 unsigned font_not_found_p
: 1;
3105 /* 1 means that the face in which this glyph string is drawn has a
3107 unsigned stippled_p
: 1;
3109 /* 1 means only the foreground of this glyph string must be drawn,
3110 and we should use the physical height of the line this glyph
3111 string appears in as clip rect. */
3112 unsigned for_overlaps_p
: 1;
3114 /* The GC to use for drawing this glyph string. */
3117 /* A pointer to the first glyph in the string. This glyph
3118 corresponds to char2b[0]. Needed to draw rectangles if
3119 font_not_found_p is 1. */
3120 struct glyph
*first_glyph
;
3122 /* Image, if any. */
3125 struct glyph_string
*next
, *prev
;
3132 x_dump_glyph_string (s
)
3133 struct glyph_string
*s
;
3135 fprintf (stderr
, "glyph string\n");
3136 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
3137 s
->x
, s
->y
, s
->width
, s
->height
);
3138 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
3139 fprintf (stderr
, " hl = %d\n", s
->hl
);
3140 fprintf (stderr
, " left overhang = %d, right = %d\n",
3141 s
->left_overhang
, s
->right_overhang
);
3142 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
3143 fprintf (stderr
, " extends to end of line = %d\n",
3144 s
->extends_to_end_of_line_p
);
3145 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
3146 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
3149 #endif /* GLYPH_DEBUG */
3153 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
3154 struct glyph_string
**,
3155 struct glyph_string
*,
3156 struct glyph_string
*));
3157 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
3158 struct glyph_string
**,
3159 struct glyph_string
*,
3160 struct glyph_string
*));
3161 static void x_append_glyph_string
P_ ((struct glyph_string
**,
3162 struct glyph_string
**,
3163 struct glyph_string
*));
3164 static int x_left_overwritten
P_ ((struct glyph_string
*));
3165 static int x_left_overwriting
P_ ((struct glyph_string
*));
3166 static int x_right_overwritten
P_ ((struct glyph_string
*));
3167 static int x_right_overwriting
P_ ((struct glyph_string
*));
3168 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
3170 static void x_init_glyph_string
P_ ((struct glyph_string
*,
3171 XChar2b
*, struct window
*,
3173 enum glyph_row_area
, int,
3174 enum draw_glyphs_face
));
3175 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
3176 enum glyph_row_area
, int, int,
3177 enum draw_glyphs_face
, int));
3178 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
3179 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
3180 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
3182 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
3183 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
3184 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
3185 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
3186 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
3187 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
3188 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
3189 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
3190 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
3192 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
3193 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
3194 unsigned long *, double, int));*/
3195 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
3196 double, int, unsigned long));
3197 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
3198 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
3199 static void x_draw_image_relief
P_ ((struct glyph_string
*));
3200 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
3201 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
3202 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
3203 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
3205 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
3206 int, int, int, int, Rect
*));
3207 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
3208 int, int, int, Rect
*));
3209 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
3210 enum glyph_row_area
));
3211 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
3213 enum glyph_row_area
, int, int));
3216 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
3220 /* Append the list of glyph strings with head H and tail T to the list
3221 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
3224 x_append_glyph_string_lists (head
, tail
, h
, t
)
3225 struct glyph_string
**head
, **tail
;
3226 struct glyph_string
*h
, *t
;
3240 /* Prepend the list of glyph strings with head H and tail T to the
3241 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
3245 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
3246 struct glyph_string
**head
, **tail
;
3247 struct glyph_string
*h
, *t
;
3261 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
3262 Set *HEAD and *TAIL to the resulting list. */
3265 x_append_glyph_string (head
, tail
, s
)
3266 struct glyph_string
**head
, **tail
;
3267 struct glyph_string
*s
;
3269 s
->next
= s
->prev
= NULL
;
3270 x_append_glyph_string_lists (head
, tail
, s
, s
);
3274 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
3279 struct glyph_string
*s
;
3281 if (s
->font
== FRAME_FONT (s
->f
)
3282 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
3283 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
3285 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
3288 /* Cursor on non-default face: must merge. */
3292 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
3293 xgcv
.foreground
= s
->face
->background
;
3295 /* If the glyph would be invisible, try a different foreground. */
3296 if (xgcv
.foreground
== xgcv
.background
)
3297 xgcv
.foreground
= s
->face
->foreground
;
3298 if (xgcv
.foreground
== xgcv
.background
)
3299 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
3300 if (xgcv
.foreground
== xgcv
.background
)
3301 xgcv
.foreground
= s
->face
->foreground
;
3303 /* Make sure the cursor is distinct from text in this face. */
3304 if (xgcv
.background
== s
->face
->background
3305 && xgcv
.foreground
== s
->face
->foreground
)
3307 xgcv
.background
= s
->face
->foreground
;
3308 xgcv
.foreground
= s
->face
->background
;
3311 IF_DEBUG (x_check_font (s
->f
, s
->font
));
3312 xgcv
.font
= s
->font
;
3313 mask
= GCForeground
| GCBackground
| GCFont
;
3315 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
3316 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
3319 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
3320 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
3322 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
3327 /* Set up S->gc of glyph string S for drawing text in mouse face. */
3330 x_set_mouse_face_gc (s
)
3331 struct glyph_string
*s
;
3336 /* What face has to be used last for the mouse face? */
3337 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
3338 face
= FACE_FROM_ID (s
->f
, face_id
);
3340 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
3342 if (s
->first_glyph
->type
== CHAR_GLYPH
)
3343 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
3345 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
3346 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
3347 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
3349 /* If font in this face is same as S->font, use it. */
3350 if (s
->font
== s
->face
->font
)
3351 s
->gc
= s
->face
->gc
;
3354 /* Otherwise construct scratch_cursor_gc with values from FACE
3359 xgcv
.background
= s
->face
->background
;
3360 xgcv
.foreground
= s
->face
->foreground
;
3361 IF_DEBUG (x_check_font (s
->f
, s
->font
));
3362 xgcv
.font
= s
->font
;
3363 mask
= GCForeground
| GCBackground
| GCFont
;
3365 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
3366 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
3369 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
3370 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
3372 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
3375 xassert (s
->gc
!= 0);
3379 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
3380 Faces to use in the mode line have already been computed when the
3381 matrix was built, so there isn't much to do, here. */
3384 x_set_mode_line_face_gc (s
)
3385 struct glyph_string
*s
;
3387 s
->gc
= s
->face
->gc
;
3391 /* Set S->gc of glyph string S for drawing that glyph string. Set
3392 S->stippled_p to a non-zero value if the face of S has a stipple
3396 x_set_glyph_string_gc (s
)
3397 struct glyph_string
*s
;
3399 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
3401 if (s
->hl
== DRAW_NORMAL_TEXT
)
3403 s
->gc
= s
->face
->gc
;
3404 s
->stippled_p
= s
->face
->stipple
!= 0;
3406 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
3408 x_set_mode_line_face_gc (s
);
3409 s
->stippled_p
= s
->face
->stipple
!= 0;
3411 else if (s
->hl
== DRAW_CURSOR
)
3413 x_set_cursor_gc (s
);
3416 else if (s
->hl
== DRAW_MOUSE_FACE
)
3418 x_set_mouse_face_gc (s
);
3419 s
->stippled_p
= s
->face
->stipple
!= 0;
3421 else if (s
->hl
== DRAW_IMAGE_RAISED
3422 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3424 s
->gc
= s
->face
->gc
;
3425 s
->stippled_p
= s
->face
->stipple
!= 0;
3429 s
->gc
= s
->face
->gc
;
3430 s
->stippled_p
= s
->face
->stipple
!= 0;
3433 /* GC must have been set. */
3434 xassert (s
->gc
!= 0);
3438 /* Return in *R the clipping rectangle for glyph string S. */
3441 x_get_glyph_string_clip_rect (s
, r
)
3442 struct glyph_string
*s
;
3445 int r_height
, r_width
;
3447 if (s
->row
->full_width_p
)
3449 /* Draw full-width. X coordinates are relative to S->w->left. */
3450 int canon_x
= CANON_X_UNIT (s
->f
);
3452 r
->left
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
3453 r_width
= XFASTINT (s
->w
->width
) * canon_x
;
3455 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
3457 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
3458 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
3462 r
->left
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
3464 /* Unless displaying a mode or menu bar line, which are always
3465 fully visible, clip to the visible part of the row. */
3466 if (s
->w
->pseudo_window_p
)
3467 r_height
= s
->row
->visible_height
;
3469 r_height
= s
->height
;
3473 /* This is a text line that may be partially visible. */
3474 r
->left
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
3475 r_width
= window_box_width (s
->w
, s
->area
);
3476 r_height
= s
->row
->visible_height
;
3479 /* If S draws overlapping rows, it's sufficient to use the top and
3480 bottom of the window for clipping because this glyph string
3481 intentionally draws over other lines. */
3482 if (s
->for_overlaps_p
)
3484 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3485 r_height
= window_text_bottom_y (s
->w
) - r
->top
;
3489 /* Don't use S->y for clipping because it doesn't take partially
3490 visible lines into account. For example, it can be negative for
3491 partially visible lines at the top of a window. */
3492 if (!s
->row
->full_width_p
3493 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
3494 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3496 r
->top
= max (0, s
->row
->y
);
3498 /* If drawing a tool-bar window, draw it over the internal border
3499 at the top of the window. */
3500 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
3501 r
->top
-= s
->f
->output_data
.mac
->internal_border_width
;
3504 r
->top
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->top
);
3506 r
->bottom
= r
->top
+ r_height
;
3507 r
->right
= r
->left
+ r_width
;
3511 /* Set clipping for output of glyph string S. S may be part of a mode
3512 line or menu if we don't have X toolkit support. */
3515 x_set_glyph_string_clipping (s
)
3516 struct glyph_string
*s
;
3519 x_get_glyph_string_clip_rect (s
, &r
);
3520 mac_set_clip_rectangle (s
->display
, s
->window
, &r
);
3524 /* Compute left and right overhang of glyph string S. If S is a glyph
3525 string for a composition, assume overhangs don't exist. */
3528 x_compute_glyph_string_overhangs (s
)
3529 struct glyph_string
*s
;
3532 && s
->first_glyph
->type
== CHAR_GLYPH
)
3535 int direction
, font_ascent
, font_descent
;
3536 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
3537 &font_ascent
, &font_descent
, &cs
);
3538 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
3539 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
3544 /* Compute overhangs and x-positions for glyph string S and its
3545 predecessors, or successors. X is the starting x-position for S.
3546 BACKWARD_P non-zero means process predecessors. */
3549 x_compute_overhangs_and_x (s
, x
, backward_p
)
3550 struct glyph_string
*s
;
3558 x_compute_glyph_string_overhangs (s
);
3568 x_compute_glyph_string_overhangs (s
);
3577 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
3578 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
3579 assumed to be zero. */
3582 x_get_glyph_overhangs (glyph
, f
, left
, right
)
3583 struct glyph
*glyph
;
3589 if (glyph
->type
== CHAR_GLYPH
)
3593 struct font_info
*font_info
;
3597 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
3599 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
3601 && (pcm
= x_per_char_metric (font
, &char2b
)))
3603 if (pcm
->rbearing
> pcm
->width
)
3604 *right
= pcm
->rbearing
- pcm
->width
;
3605 if (pcm
->lbearing
< 0)
3606 *left
= -pcm
->lbearing
;
3612 /* Return the index of the first glyph preceding glyph string S that
3613 is overwritten by S because of S's left overhang. Value is -1
3614 if no glyphs are overwritten. */
3617 x_left_overwritten (s
)
3618 struct glyph_string
*s
;
3622 if (s
->left_overhang
)
3625 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3626 int first
= s
->first_glyph
- glyphs
;
3628 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3629 x
-= glyphs
[i
].pixel_width
;
3640 /* Return the index of the first glyph preceding glyph string S that
3641 is overwriting S because of its right overhang. Value is -1 if no
3642 glyph in front of S overwrites S. */
3645 x_left_overwriting (s
)
3646 struct glyph_string
*s
;
3649 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3650 int first
= s
->first_glyph
- glyphs
;
3654 for (i
= first
- 1; i
>= 0; --i
)
3657 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3660 x
-= glyphs
[i
].pixel_width
;
3667 /* Return the index of the last glyph following glyph string S that is
3668 not overwritten by S because of S's right overhang. Value is -1 if
3669 no such glyph is found. */
3672 x_right_overwritten (s
)
3673 struct glyph_string
*s
;
3677 if (s
->right_overhang
)
3680 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3681 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3682 int end
= s
->row
->used
[s
->area
];
3684 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3685 x
+= glyphs
[i
].pixel_width
;
3694 /* Return the index of the last glyph following glyph string S that
3695 overwrites S because of its left overhang. Value is negative
3696 if no such glyph is found. */
3699 x_right_overwriting (s
)
3700 struct glyph_string
*s
;
3703 int end
= s
->row
->used
[s
->area
];
3704 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3705 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3709 for (i
= first
; i
< end
; ++i
)
3712 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3715 x
+= glyphs
[i
].pixel_width
;
3722 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3725 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3726 struct glyph_string
*s
;
3731 xgcv
.foreground
= s
->gc
->background
;
3732 XFillRectangle (s
->display
, s
->window
, &xgcv
, x
, y
, w
, h
);
3736 /* Draw the background of glyph_string S. If S->background_filled_p
3737 is non-zero don't draw it. FORCE_P non-zero means draw the
3738 background even if it wouldn't be drawn normally. This is used
3739 when a string preceding S draws into the background of S, or S
3740 contains the first component of a composition. */
3743 x_draw_glyph_string_background (s
, force_p
)
3744 struct glyph_string
*s
;
3747 /* Nothing to do if background has already been drawn or if it
3748 shouldn't be drawn in the first place. */
3749 if (!s
->background_filled_p
)
3751 int box_line_width
= max (s
->face
->box_line_width
, 0);
3753 #if 0 /* MAC_TODO: stipple */
3756 /* Fill background with a stipple pattern. */
3757 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3758 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3759 s
->y
+ box_line_width
,
3760 s
->background_width
,
3761 s
->height
- 2 * box_line_width
);
3762 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3763 s
->background_filled_p
= 1;
3767 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3768 || s
->font_not_found_p
3769 || s
->extends_to_end_of_line_p
3772 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3773 s
->background_width
,
3774 s
->height
- 2 * box_line_width
);
3775 s
->background_filled_p
= 1;
3781 /* Draw the foreground of glyph string S. */
3784 x_draw_glyph_string_foreground (s
)
3785 struct glyph_string
*s
;
3789 /* If first glyph of S has a left box line, start drawing the text
3790 of S to the right of that box line. */
3791 if (s
->face
->box
!= FACE_NO_BOX
3792 && s
->first_glyph
->left_box_line_p
)
3793 x
= s
->x
+ abs (s
->face
->box_line_width
);
3797 /* Draw characters of S as rectangles if S's font could not be
3799 if (s
->font_not_found_p
)
3801 for (i
= 0; i
< s
->nchars
; ++i
)
3803 struct glyph
*g
= s
->first_glyph
+ i
;
3804 mac_draw_rectangle (s
->display
, s
->window
,
3805 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3807 x
+= g
->pixel_width
;
3812 char *char1b
= (char *) s
->char2b
;
3813 int boff
= s
->font_info
->baseline_offset
;
3815 if (s
->font_info
->vertical_centering
)
3816 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3818 /* If we can use 8-bit functions, condense S->char2b. */
3820 for (i
= 0; i
< s
->nchars
; ++i
)
3821 char1b
[i
] = s
->char2b
[i
].byte2
;
3823 /* Draw text with XDrawString if background has already been
3824 filled. Otherwise, use XDrawImageString. (Note that
3825 XDrawImageString is usually faster than XDrawString.) Always
3826 use XDrawImageString when drawing the cursor so that there is
3827 no chance that characters under a box cursor are invisible. */
3828 if (s
->for_overlaps_p
3829 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3831 /* Draw characters with 16-bit or 8-bit functions. */
3833 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3834 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3836 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3837 s
->ybase
- boff
, char1b
, s
->nchars
);
3842 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3843 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3845 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3846 s
->ybase
- boff
, char1b
, s
->nchars
);
3851 /* Draw the foreground of composite glyph string S. */
3854 x_draw_composite_glyph_string_foreground (s
)
3855 struct glyph_string
*s
;
3859 /* If first glyph of S has a left box line, start drawing the text
3860 of S to the right of that box line. */
3861 if (s
->face
->box
!= FACE_NO_BOX
3862 && s
->first_glyph
->left_box_line_p
)
3863 x
= s
->x
+ abs (s
->face
->box_line_width
);
3867 /* S is a glyph string for a composition. S->gidx is the index of
3868 the first character drawn for glyphs of this composition.
3869 S->gidx == 0 means we are drawing the very first character of
3870 this composition. */
3872 /* Draw a rectangle for the composition if the font for the very
3873 first character of the composition could not be loaded. */
3874 if (s
->font_not_found_p
)
3877 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3878 s
->width
- 1, s
->height
- 1);
3882 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3883 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3884 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3885 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3891 #ifdef USE_X_TOOLKIT
3893 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3896 /* Return the frame on which widget WIDGET is used.. Abort if frame
3897 cannot be determined. */
3899 static struct frame
*
3900 x_frame_of_widget (widget
)
3903 struct x_display_info
*dpyinfo
;
3907 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3909 /* Find the top-level shell of the widget. Note that this function
3910 can be called when the widget is not yet realized, so XtWindow
3911 (widget) == 0. That's the reason we can't simply use
3912 x_any_window_to_frame. */
3913 while (!XtIsTopLevelShell (widget
))
3914 widget
= XtParent (widget
);
3916 /* Look for a frame with that top-level widget. Allocate the color
3917 on that frame to get the right gamma correction value. */
3918 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3919 if (GC_FRAMEP (XCAR (tail
))
3920 && (f
= XFRAME (XCAR (tail
)),
3921 (f
->output_data
.nothing
!= 1
3922 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3923 && f
->output_data
.x
->widget
== widget
)
3930 /* Allocate the color COLOR->pixel on the screen and display of
3931 widget WIDGET in colormap CMAP. If an exact match cannot be
3932 allocated, try the nearest color available. Value is non-zero
3933 if successful. This is called from lwlib. */
3936 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3941 struct frame
*f
= x_frame_of_widget (widget
);
3942 return x_alloc_nearest_color (f
, cmap
, color
);
3946 #endif /* USE_X_TOOLKIT */
3948 #if 0 /* MAC_TODO */
3950 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3951 CMAP. If an exact match can't be allocated, try the nearest color
3952 available. Value is non-zero if successful. Set *COLOR to the
3956 x_alloc_nearest_color (f
, cmap
, color
)
3961 Display
*display
= FRAME_X_DISPLAY (f
);
3962 Screen
*screen
= FRAME_X_SCREEN (f
);
3965 gamma_correct (f
, color
);
3966 rc
= XAllocColor (display
, cmap
, color
);
3969 /* If we got to this point, the colormap is full, so we're going
3970 to try to get the next closest color. The algorithm used is
3971 a least-squares matching, which is what X uses for closest
3972 color matching with StaticColor visuals. */
3974 unsigned long nearest_delta
= ~0;
3975 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3976 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3978 for (i
= 0; i
< ncells
; ++i
)
3980 XQueryColors (display
, cmap
, cells
, ncells
);
3982 for (nearest
= i
= 0; i
< ncells
; ++i
)
3984 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3985 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3986 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3987 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3989 if (delta
< nearest_delta
)
3992 nearest_delta
= delta
;
3996 color
->red
= cells
[nearest
].red
;
3997 color
->green
= cells
[nearest
].green
;
3998 color
->blue
= cells
[nearest
].blue
;
3999 rc
= XAllocColor (display
, cmap
, color
);
4002 #ifdef DEBUG_X_COLORS
4004 register_color (color
->pixel
);
4005 #endif /* DEBUG_X_COLORS */
4011 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
4012 It's necessary to do this instead of just using PIXEL directly to
4013 get color reference counts right. */
4016 x_copy_color (f
, pixel
)
4018 unsigned long pixel
;
4022 color
.pixel
= pixel
;
4024 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
4025 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
4027 #ifdef DEBUG_X_COLORS
4028 register_color (pixel
);
4034 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
4035 It's necessary to do this instead of just using PIXEL directly to
4036 get color reference counts right. */
4039 x_copy_dpy_color (dpy
, cmap
, pixel
)
4042 unsigned long pixel
;
4046 color
.pixel
= pixel
;
4048 XQueryColor (dpy
, cmap
, &color
);
4049 XAllocColor (dpy
, cmap
, &color
);
4051 #ifdef DEBUG_X_COLORS
4052 register_color (pixel
);
4057 #endif /* MAC_TODO */
4059 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
4060 or DELTA. Try a color with RGB values multiplied by FACTOR first.
4061 If this produces the same color as COLOR, try a color where all RGB
4062 values have DELTA added. Return the allocated color in *COLOR.
4063 DISPLAY is the X display, CMAP is the colormap to operate on.
4064 Value is non-zero if successful. */
4067 mac_alloc_lighter_color (f
, color
, factor
, delta
)
4069 unsigned long *color
;
4075 /* Change RGB values by specified FACTOR. Avoid overflow! */
4076 xassert (factor
>= 0);
4077 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
4078 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
4079 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
4081 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
4082 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
4083 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
4085 /* MAC_TODO: Map to palette and retry with delta if same? */
4086 /* MAC_TODO: Free colors (if using palette)? */
4097 /* Set up the foreground color for drawing relief lines of glyph
4098 string S. RELIEF is a pointer to a struct relief containing the GC
4099 with which lines will be drawn. Use a color that is FACTOR or
4100 DELTA lighter or darker than the relief's background which is found
4101 in S->f->output_data.x->relief_background. If such a color cannot
4102 be allocated, use DEFAULT_PIXEL, instead. */
4105 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
4107 struct relief
*relief
;
4110 unsigned long default_pixel
;
4113 struct mac_output
*di
= f
->output_data
.mac
;
4114 unsigned long mask
= GCForeground
;
4115 unsigned long pixel
;
4116 unsigned long background
= di
->relief_background
;
4117 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
4119 /* MAC_TODO: Free colors (if using palette)? */
4121 /* Allocate new color. */
4122 xgcv
.foreground
= default_pixel
;
4124 if (mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
4126 relief
->allocated_p
= 1;
4127 xgcv
.foreground
= relief
->pixel
= pixel
;
4130 if (relief
->gc
== 0)
4132 #if 0 /* MAC_TODO: stipple */
4133 xgcv
.stipple
= dpyinfo
->gray
;
4136 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
4139 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
4143 /* Set up colors for the relief lines around glyph string S. */
4146 x_setup_relief_colors (s
)
4147 struct glyph_string
*s
;
4149 struct mac_output
*di
= s
->f
->output_data
.mac
;
4150 unsigned long color
;
4152 if (s
->face
->use_box_color_for_shadows_p
)
4153 color
= s
->face
->box_color
;
4158 /* Get the background color of the face. */
4159 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
4160 color
= xgcv
.background
;
4163 if (di
->white_relief
.gc
== 0
4164 || color
!= di
->relief_background
)
4166 di
->relief_background
= color
;
4167 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
4168 WHITE_PIX_DEFAULT (s
->f
));
4169 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
4170 BLACK_PIX_DEFAULT (s
->f
));
4175 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
4176 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
4177 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
4178 relief. LEFT_P non-zero means draw a relief on the left side of
4179 the rectangle. RIGHT_P non-zero means draw a relief on the right
4180 side of the rectangle. CLIP_RECT is the clipping rectangle to use
4184 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
4185 raised_p
, left_p
, right_p
, clip_rect
)
4187 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
4194 gc
= f
->output_data
.mac
->white_relief
.gc
;
4196 gc
= f
->output_data
.mac
->black_relief
.gc
;
4197 mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), clip_rect
);
4200 for (i
= 0; i
< width
; ++i
)
4201 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4202 left_x
+ i
* left_p
, top_y
+ i
,
4203 right_x
+ 1 - i
* right_p
, top_y
+ i
);
4207 for (i
= 0; i
< width
; ++i
)
4208 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4209 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
4211 mac_reset_clipping (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
4213 gc
= f
->output_data
.mac
->black_relief
.gc
;
4215 gc
= f
->output_data
.mac
->white_relief
.gc
;
4216 mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
4220 for (i
= 0; i
< width
; ++i
)
4221 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4222 left_x
+ i
* left_p
, bottom_y
- i
,
4223 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
4227 for (i
= 0; i
< width
; ++i
)
4228 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4229 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
4231 mac_reset_clipping (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
4235 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
4236 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
4237 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
4238 left side of the rectangle. RIGHT_P non-zero means draw a line
4239 on the right side of the rectangle. CLIP_RECT is the clipping
4240 rectangle to use when drawing. */
4243 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4244 left_p
, right_p
, clip_rect
)
4245 struct glyph_string
*s
;
4246 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
4251 xgcv
.foreground
= s
->face
->box_color
;
4252 mac_set_clip_rectangle (s
->display
, s
->window
, clip_rect
);
4255 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4256 left_x
, top_y
, right_x
- left_x
, width
);
4260 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4261 left_x
, top_y
, width
, bottom_y
- top_y
);
4264 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4265 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
4269 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4270 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
4272 mac_reset_clipping (s
->display
, s
->window
);
4276 /* Draw a box around glyph string S. */
4279 x_draw_glyph_string_box (s
)
4280 struct glyph_string
*s
;
4282 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
4283 int left_p
, right_p
;
4284 struct glyph
*last_glyph
;
4287 last_x
= window_box_right (s
->w
, s
->area
);
4288 if (s
->row
->full_width_p
4289 && !s
->w
->pseudo_window_p
)
4291 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
4292 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
4293 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
4296 /* The glyph that may have a right box line. */
4297 last_glyph
= (s
->cmp
|| s
->img
4299 : s
->first_glyph
+ s
->nchars
- 1);
4301 width
= abs (s
->face
->box_line_width
);
4302 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
4304 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4306 : min (last_x
, s
->x
+ s
->background_width
) - 1));
4308 bottom_y
= top_y
+ s
->height
- 1;
4310 left_p
= (s
->first_glyph
->left_box_line_p
4311 || (s
->hl
== DRAW_MOUSE_FACE
4313 || s
->prev
->hl
!= s
->hl
)));
4314 right_p
= (last_glyph
->right_box_line_p
4315 || (s
->hl
== DRAW_MOUSE_FACE
4317 || s
->next
->hl
!= s
->hl
)));
4319 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4321 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4322 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4323 left_p
, right_p
, &clip_rect
);
4326 x_setup_relief_colors (s
);
4327 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4328 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4333 /* Draw foreground of image glyph string S. */
4336 x_draw_image_foreground (s
)
4337 struct glyph_string
*s
;
4340 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4342 /* If first glyph of S has a left box line, start drawing it to the
4343 right of that line. */
4344 if (s
->face
->box
!= FACE_NO_BOX
4345 && s
->first_glyph
->left_box_line_p
)
4346 x
= s
->x
+ abs (s
->face
->box_line_width
);
4350 /* If there is a margin around the image, adjust x- and y-position
4352 x
+= s
->img
->hmargin
;
4353 y
+= s
->img
->vmargin
;
4357 #if 0 /* MAC_TODO: image mask */
4360 /* We can't set both a clip mask and use XSetClipRectangles
4361 because the latter also sets a clip mask. We also can't
4362 trust on the shape extension to be available
4363 (XShapeCombineRegion). So, compute the rectangle to draw
4365 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4368 XRectangle clip_rect
, image_rect
, r
;
4370 xgcv
.clip_mask
= s
->img
->mask
;
4371 xgcv
.clip_x_origin
= x
;
4372 xgcv
.clip_y_origin
= y
;
4373 xgcv
.function
= GXcopy
;
4374 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4376 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4379 image_rect
.width
= s
->img
->width
;
4380 image_rect
.height
= s
->img
->height
;
4381 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4382 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4383 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4386 #endif /* MAC_TODO */
4388 mac_copy_area (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4389 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4391 /* When the image has a mask, we can expect that at
4392 least part of a mouse highlight or a block cursor will
4393 be visible. If the image doesn't have a mask, make
4394 a block cursor visible by drawing a rectangle around
4395 the image. I believe it's looking better if we do
4396 nothing here for mouse-face. */
4397 if (s
->hl
== DRAW_CURSOR
)
4399 int r
= s
->img
->relief
;
4401 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
4402 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4407 /* Draw a rectangle if image could not be loaded. */
4408 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4409 s
->img
->width
- 1, s
->img
->height
- 1);
4414 /* Draw a relief around the image glyph string S. */
4417 x_draw_image_relief (s
)
4418 struct glyph_string
*s
;
4420 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4423 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4425 /* If first glyph of S has a left box line, start drawing it to the
4426 right of that line. */
4427 if (s
->face
->box
!= FACE_NO_BOX
4428 && s
->first_glyph
->left_box_line_p
)
4429 x
= s
->x
+ abs (s
->face
->box_line_width
);
4433 /* If there is a margin around the image, adjust x- and y-position
4435 x
+= s
->img
->hmargin
;
4436 y
+= s
->img
->vmargin
;
4438 if (s
->hl
== DRAW_IMAGE_SUNKEN
4439 || s
->hl
== DRAW_IMAGE_RAISED
)
4441 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
4442 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4446 thick
= abs (s
->img
->relief
);
4447 raised_p
= s
->img
->relief
> 0;
4452 x1
= x
+ s
->img
->width
+ thick
- 1;
4453 y1
= y
+ s
->img
->height
+ thick
- 1;
4455 x_setup_relief_colors (s
);
4456 x_get_glyph_string_clip_rect (s
, &r
);
4457 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4461 /* Draw the foreground of image glyph string S to PIXMAP. */
4464 x_draw_image_foreground_1 (s
, pixmap
)
4465 struct glyph_string
*s
;
4469 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4471 /* If first glyph of S has a left box line, start drawing it to the
4472 right of that line. */
4473 if (s
->face
->box
!= FACE_NO_BOX
4474 && s
->first_glyph
->left_box_line_p
)
4475 x
= abs (s
->face
->box_line_width
);
4479 /* If there is a margin around the image, adjust x- and y-position
4481 x
+= s
->img
->hmargin
;
4482 y
+= s
->img
->vmargin
;
4486 #if 0 /* MAC_TODO: image mask */
4489 /* We can't set both a clip mask and use XSetClipRectangles
4490 because the latter also sets a clip mask. We also can't
4491 trust on the shape extension to be available
4492 (XShapeCombineRegion). So, compute the rectangle to draw
4494 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4498 xgcv
.clip_mask
= s
->img
->mask
;
4499 xgcv
.clip_x_origin
= x
;
4500 xgcv
.clip_y_origin
= y
;
4501 xgcv
.function
= GXcopy
;
4502 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4504 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4505 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4506 XSetClipMask (s
->display
, s
->gc
, None
);
4509 #endif /* MAC_TODO */
4511 mac_copy_area_to_pixmap (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4512 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4514 /* When the image has a mask, we can expect that at
4515 least part of a mouse highlight or a block cursor will
4516 be visible. If the image doesn't have a mask, make
4517 a block cursor visible by drawing a rectangle around
4518 the image. I believe it's looking better if we do
4519 nothing here for mouse-face. */
4520 if (s
->hl
== DRAW_CURSOR
)
4522 int r
= s
->img
->relief
;
4524 mac_draw_rectangle_to_pixmap (s
->display
, pixmap
, s
->gc
, x
- r
, y
- r
,
4525 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4530 /* Draw a rectangle if image could not be loaded. */
4531 mac_draw_rectangle_to_pixmap (s
->display
, pixmap
, s
->gc
, x
, y
,
4532 s
->img
->width
- 1, s
->img
->height
- 1);
4536 /* Draw part of the background of glyph string S. X, Y, W, and H
4537 give the rectangle to draw. */
4540 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4541 struct glyph_string
*s
;
4544 #if 0 /* MAC_TODO: stipple */
4547 /* Fill background with a stipple pattern. */
4548 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4549 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4550 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4553 #endif /* MAC_TODO */
4554 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4558 /* Draw image glyph string S.
4561 s->x +-------------------------
4564 | +-------------------------
4567 | | +-------------------
4573 x_draw_image_glyph_string (s
)
4574 struct glyph_string
*s
;
4577 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4578 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4582 height
= s
->height
- 2 * box_line_vwidth
;
4584 /* Fill background with face under the image. Do it only if row is
4585 taller than image or if image has a clip mask to reduce
4587 s
->stippled_p
= s
->face
->stipple
!= 0;
4588 if (height
> s
->img
->height
4591 #if 0 /* TODO: image mask */
4594 || s
->img
->pixmap
== 0
4595 || s
->width
!= s
->background_width
)
4597 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4598 x
= s
->x
+ box_line_hwidth
;
4602 y
= s
->y
+ box_line_vwidth
;
4603 #if 0 /* TODO: image mask */
4606 /* Create a pixmap as large as the glyph string. Fill it
4607 with the background color. Copy the image to it, using
4608 its mask. Copy the temporary pixmap to the display. */
4609 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4610 int depth
= DefaultDepthOfScreen (screen
);
4612 /* Create a pixmap as large as the glyph string. */
4613 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4614 s
->background_width
,
4617 /* Don't clip in the following because we're working on the
4619 XSetClipMask (s
->display
, s
->gc
, None
);
4621 /* Fill the pixmap with the background color/stipple. */
4624 /* Fill background with a stipple pattern. */
4625 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4626 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4627 0, 0, s
->background_width
, s
->height
);
4628 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4633 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4635 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4636 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4637 0, 0, s
->background_width
, s
->height
);
4638 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4643 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4645 s
->background_filled_p
= 1;
4648 /* Draw the foreground. */
4651 x_draw_image_foreground_1 (s
, pixmap
);
4652 x_set_glyph_string_clipping (s
);
4653 mac_copy_area (s
->display
, pixmap
, s
->window
, s
->gc
,
4654 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4655 mac_reset_clipping (s
->display
, s
->window
);
4656 XFreePixmap (s
->display
, pixmap
);
4659 x_draw_image_foreground (s
);
4661 /* If we must draw a relief around the image, do it. */
4663 || s
->hl
== DRAW_IMAGE_RAISED
4664 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4665 x_draw_image_relief (s
);
4669 /* Draw stretch glyph string S. */
4672 x_draw_stretch_glyph_string (s
)
4673 struct glyph_string
*s
;
4675 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4676 s
->stippled_p
= s
->face
->stipple
!= 0;
4678 if (s
->hl
== DRAW_CURSOR
4679 && !x_stretch_cursor_p
)
4681 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4682 as wide as the stretch glyph. */
4683 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4686 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4688 /* Clear rest using the GC of the original non-cursor face. */
4689 if (width
< s
->background_width
)
4691 GC gc
= s
->face
->gc
;
4692 int x
= s
->x
+ width
, y
= s
->y
;
4693 int w
= s
->background_width
- width
, h
= s
->height
;
4696 if (s
->row
->mouse_face_p
4697 && cursor_in_mouse_face_p (s
->w
))
4699 x_set_mouse_face_gc (s
);
4705 x_get_glyph_string_clip_rect (s
, &r
);
4706 mac_set_clip_rectangle (s
->display
, s
->window
, &r
);
4708 #if 0 /* MAC_TODO: stipple */
4709 if (s
->face
->stipple
)
4711 /* Fill background with a stipple pattern. */
4712 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4713 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4714 XSetFillStyle (s
->display
, gc
, FillSolid
);
4717 #endif /* MAC_TODO */
4720 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4721 XSetForeground (s
->display
, gc
, xgcv
.background
);
4722 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4723 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4726 mac_reset_clipping (s
->display
, s
->window
);
4729 else if (!s
->background_filled_p
)
4730 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4733 s
->background_filled_p
= 1;
4737 /* Draw glyph string S. */
4740 x_draw_glyph_string (s
)
4741 struct glyph_string
*s
;
4743 int relief_drawn_p
= 0;
4745 /* If S draws into the background of its successor, draw the
4746 background of the successor first so that S can draw into it.
4747 This makes S->next use XDrawString instead of XDrawImageString. */
4748 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4750 xassert (s
->next
->img
== NULL
);
4751 x_set_glyph_string_gc (s
->next
);
4752 x_set_glyph_string_clipping (s
->next
);
4753 x_draw_glyph_string_background (s
->next
, 1);
4757 /* Set up S->gc, set clipping and draw S. */
4758 x_set_glyph_string_gc (s
);
4760 /* Draw relief (if any) in advance for char/composition so that the
4761 glyph string can be drawn over it. */
4762 if (!s
->for_overlaps_p
4763 && s
->face
->box
!= FACE_NO_BOX
4764 && (s
->first_glyph
->type
== CHAR_GLYPH
4765 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4768 x_set_glyph_string_clipping (s
);
4769 x_draw_glyph_string_background (s
, 1);
4770 x_draw_glyph_string_box (s
);
4771 x_set_glyph_string_clipping (s
);
4775 x_set_glyph_string_clipping (s
);
4777 switch (s
->first_glyph
->type
)
4780 x_draw_image_glyph_string (s
);
4784 x_draw_stretch_glyph_string (s
);
4788 if (s
->for_overlaps_p
)
4789 s
->background_filled_p
= 1;
4791 x_draw_glyph_string_background (s
, 0);
4792 x_draw_glyph_string_foreground (s
);
4795 case COMPOSITE_GLYPH
:
4796 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4797 s
->background_filled_p
= 1;
4799 x_draw_glyph_string_background (s
, 1);
4800 x_draw_composite_glyph_string_foreground (s
);
4807 if (!s
->for_overlaps_p
)
4809 /* Draw underline. */
4810 if (s
->face
->underline_p
)
4812 unsigned long h
= 1;
4813 unsigned long dy
= s
->height
- h
;
4815 if (s
->face
->underline_defaulted_p
)
4816 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4821 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4822 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4823 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4825 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4829 /* Draw overline. */
4830 if (s
->face
->overline_p
)
4832 unsigned long dy
= 0, h
= 1;
4834 if (s
->face
->overline_color_defaulted_p
)
4835 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4840 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4841 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4842 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4844 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4848 /* Draw strike-through. */
4849 if (s
->face
->strike_through_p
)
4851 unsigned long h
= 1;
4852 unsigned long dy
= (s
->height
- h
) / 2;
4854 if (s
->face
->strike_through_color_defaulted_p
)
4855 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4860 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4861 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4862 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4864 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4869 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4870 x_draw_glyph_string_box (s
);
4873 /* Reset clipping. */
4874 mac_reset_clipping (s
->display
, s
->window
);
4878 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4879 struct face
**, int));
4882 /* Fill glyph string S with composition components specified by S->cmp.
4884 FACES is an array of faces for all components of this composition.
4885 S->gidx is the index of the first component for S.
4886 OVERLAPS_P non-zero means S should draw the foreground only, and
4887 use its physical height for clipping.
4889 Value is the index of a component not in S. */
4892 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4893 struct glyph_string
*s
;
4894 struct face
**faces
;
4901 s
->for_overlaps_p
= overlaps_p
;
4903 s
->face
= faces
[s
->gidx
];
4904 s
->font
= s
->face
->font
;
4905 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4907 /* For all glyphs of this composition, starting at the offset
4908 S->gidx, until we reach the end of the definition or encounter a
4909 glyph that requires the different face, add it to S. */
4911 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4914 /* All glyph strings for the same composition has the same width,
4915 i.e. the width set for the first component of the composition. */
4917 s
->width
= s
->first_glyph
->pixel_width
;
4919 /* If the specified font could not be loaded, use the frame's
4920 default font, but record the fact that we couldn't load it in
4921 the glyph string so that we can draw rectangles for the
4922 characters of the glyph string. */
4923 if (s
->font
== NULL
)
4925 s
->font_not_found_p
= 1;
4926 s
->font
= FRAME_FONT (s
->f
);
4929 /* Adjust base line for subscript/superscript text. */
4930 s
->ybase
+= s
->first_glyph
->voffset
;
4932 xassert (s
->face
&& s
->face
->gc
);
4934 /* This glyph string must always be drawn with 16-bit functions. */
4937 return s
->gidx
+ s
->nchars
;
4941 /* Fill glyph string S from a sequence of character glyphs.
4943 FACE_ID is the face id of the string. START is the index of the
4944 first glyph to consider, END is the index of the last + 1.
4945 OVERLAPS_P non-zero means S should draw the foreground only, and
4946 use its physical height for clipping.
4948 Value is the index of the first glyph not in S. */
4951 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4952 struct glyph_string
*s
;
4954 int start
, end
, overlaps_p
;
4956 struct glyph
*glyph
, *last
;
4958 int glyph_not_available_p
;
4960 xassert (s
->f
== XFRAME (s
->w
->frame
));
4961 xassert (s
->nchars
== 0);
4962 xassert (start
>= 0 && end
> start
);
4964 s
->for_overlaps_p
= overlaps_p
;
4965 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4966 last
= s
->row
->glyphs
[s
->area
] + end
;
4967 voffset
= glyph
->voffset
;
4969 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4972 && glyph
->type
== CHAR_GLYPH
4973 && glyph
->voffset
== voffset
4974 /* Same face id implies same font, nowadays. */
4975 && glyph
->face_id
== face_id
4976 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4980 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4981 s
->char2b
+ s
->nchars
,
4983 s
->two_byte_p
= two_byte_p
;
4985 xassert (s
->nchars
<= end
- start
);
4986 s
->width
+= glyph
->pixel_width
;
4990 s
->font
= s
->face
->font
;
4991 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4993 /* If the specified font could not be loaded, use the frame's font,
4994 but record the fact that we couldn't load it in
4995 S->font_not_found_p so that we can draw rectangles for the
4996 characters of the glyph string. */
4997 if (s
->font
== NULL
|| glyph_not_available_p
)
4999 s
->font_not_found_p
= 1;
5000 s
->font
= FRAME_FONT (s
->f
);
5003 /* Adjust base line for subscript/superscript text. */
5004 s
->ybase
+= voffset
;
5006 xassert (s
->face
&& s
->face
->gc
);
5007 return glyph
- s
->row
->glyphs
[s
->area
];
5011 /* Fill glyph string S from image glyph S->first_glyph. */
5014 x_fill_image_glyph_string (s
)
5015 struct glyph_string
*s
;
5017 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
5018 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
5020 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
5021 s
->font
= s
->face
->font
;
5022 s
->width
= s
->first_glyph
->pixel_width
;
5024 /* Adjust base line for subscript/superscript text. */
5025 s
->ybase
+= s
->first_glyph
->voffset
;
5029 /* Fill glyph string S from a sequence of stretch glyphs.
5031 ROW is the glyph row in which the glyphs are found, AREA is the
5032 area within the row. START is the index of the first glyph to
5033 consider, END is the index of the last + 1.
5035 Value is the index of the first glyph not in S. */
5038 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
5039 struct glyph_string
*s
;
5040 struct glyph_row
*row
;
5041 enum glyph_row_area area
;
5044 struct glyph
*glyph
, *last
;
5045 int voffset
, face_id
;
5047 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
5049 glyph
= s
->row
->glyphs
[s
->area
] + start
;
5050 last
= s
->row
->glyphs
[s
->area
] + end
;
5051 face_id
= glyph
->face_id
;
5052 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
5053 s
->font
= s
->face
->font
;
5054 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
5055 s
->width
= glyph
->pixel_width
;
5056 voffset
= glyph
->voffset
;
5060 && glyph
->type
== STRETCH_GLYPH
5061 && glyph
->voffset
== voffset
5062 && glyph
->face_id
== face_id
);
5064 s
->width
+= glyph
->pixel_width
;
5066 /* Adjust base line for subscript/superscript text. */
5067 s
->ybase
+= voffset
;
5070 return glyph
- s
->row
->glyphs
[s
->area
];
5074 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
5075 of XChar2b structures for S; it can't be allocated in
5076 x_init_glyph_string because it must be allocated via `alloca'. W
5077 is the window on which S is drawn. ROW and AREA are the glyph row
5078 and area within the row from which S is constructed. START is the
5079 index of the first glyph structure covered by S. HL is a
5080 face-override for drawing S. */
5083 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
5084 struct glyph_string
*s
;
5087 struct glyph_row
*row
;
5088 enum glyph_row_area area
;
5090 enum draw_glyphs_face hl
;
5092 bzero (s
, sizeof *s
);
5094 s
->f
= XFRAME (w
->frame
);
5095 s
->display
= FRAME_MAC_DISPLAY (s
->f
);
5096 s
->window
= FRAME_MAC_WINDOW (s
->f
);
5101 s
->first_glyph
= row
->glyphs
[area
] + start
;
5102 s
->height
= row
->height
;
5103 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5105 /* Display the internal border below the tool-bar window. */
5106 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
5107 s
->y
-= s
->f
->output_data
.mac
->internal_border_width
;
5109 s
->ybase
= s
->y
+ row
->ascent
;
5113 /* Set background width of glyph string S. START is the index of the
5114 first glyph following S. LAST_X is the right-most x-position + 1
5115 in the drawing area. */
5118 x_set_glyph_string_background_width (s
, start
, last_x
)
5119 struct glyph_string
*s
;
5123 /* If the face of this glyph string has to be drawn to the end of
5124 the drawing area, set S->extends_to_end_of_line_p. */
5125 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
5127 if (start
== s
->row
->used
[s
->area
]
5128 && s
->area
== TEXT_AREA
5129 && ((s
->hl
== DRAW_NORMAL_TEXT
5130 && (s
->row
->fill_line_p
5131 || s
->face
->background
!= default_face
->background
5132 || s
->face
->stipple
!= default_face
->stipple
5133 || s
->row
->mouse_face_p
))
5134 || s
->hl
== DRAW_MOUSE_FACE
5135 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
5136 && s
->row
->fill_line_p
)))
5137 s
->extends_to_end_of_line_p
= 1;
5139 /* If S extends its face to the end of the line, set its
5140 background_width to the distance to the right edge of the drawing
5142 if (s
->extends_to_end_of_line_p
)
5143 s
->background_width
= last_x
- s
->x
+ 1;
5145 s
->background_width
= s
->width
;
5149 /* Add a glyph string for a stretch glyph to the list of strings
5150 between HEAD and TAIL. START is the index of the stretch glyph in
5151 row area AREA of glyph row ROW. END is the index of the last glyph
5152 in that glyph row area. X is the current output position assigned
5153 to the new glyph string constructed. HL overrides that face of the
5154 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
5155 is the right-most x-position of the drawing area. */
5157 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
5158 and below -- keep them on one line. */
5159 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
5162 s = (struct glyph_string *) alloca (sizeof *s); \
5163 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
5164 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
5165 x_append_glyph_string (&HEAD, &TAIL, s); \
5171 /* Add a glyph string for an image glyph to the list of strings
5172 between HEAD and TAIL. START is the index of the image glyph in
5173 row area AREA of glyph row ROW. END is the index of the last glyph
5174 in that glyph row area. X is the current output position assigned
5175 to the new glyph string constructed. HL overrides that face of the
5176 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
5177 is the right-most x-position of the drawing area. */
5179 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
5182 s = (struct glyph_string *) alloca (sizeof *s); \
5183 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
5184 x_fill_image_glyph_string (s); \
5185 x_append_glyph_string (&HEAD, &TAIL, s); \
5192 /* Add a glyph string for a sequence of character glyphs to the list
5193 of strings between HEAD and TAIL. START is the index of the first
5194 glyph in row area AREA of glyph row ROW that is part of the new
5195 glyph string. END is the index of the last glyph in that glyph row
5196 area. X is the current output position assigned to the new glyph
5197 string constructed. HL overrides that face of the glyph; e.g. it
5198 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
5199 right-most x-position of the drawing area. */
5201 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5207 c = (ROW)->glyphs[AREA][START].u.ch; \
5208 face_id = (ROW)->glyphs[AREA][START].face_id; \
5210 s = (struct glyph_string *) alloca (sizeof *s); \
5211 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
5212 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
5213 x_append_glyph_string (&HEAD, &TAIL, s); \
5215 START = x_fill_glyph_string (s, face_id, START, END, \
5221 /* Add a glyph string for a composite sequence to the list of strings
5222 between HEAD and TAIL. START is the index of the first glyph in
5223 row area AREA of glyph row ROW that is part of the new glyph
5224 string. END is the index of the last glyph in that glyph row area.
5225 X is the current output position assigned to the new glyph string
5226 constructed. HL overrides that face of the glyph; e.g. it is
5227 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
5228 x-position of the drawing area. */
5230 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5232 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
5233 int face_id = (ROW)->glyphs[AREA][START].face_id; \
5234 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
5235 struct composition *cmp = composition_table[cmp_id]; \
5236 int glyph_len = cmp->glyph_len; \
5238 struct face **faces; \
5239 struct glyph_string *first_s = NULL; \
5242 base_face = base_face->ascii_face; \
5243 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
5244 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
5245 /* At first, fill in `char2b' and `faces'. */ \
5246 for (n = 0; n < glyph_len; n++) \
5248 int c = COMPOSITION_GLYPH (cmp, n); \
5249 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
5250 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
5251 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
5252 this_face_id, char2b + n, 1); \
5255 /* Make glyph_strings for each glyph sequence that is drawable by \
5256 the same face, and append them to HEAD/TAIL. */ \
5257 for (n = 0; n < cmp->glyph_len;) \
5259 s = (struct glyph_string *) alloca (sizeof *s); \
5260 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
5261 x_append_glyph_string (&(HEAD), &(TAIL), s); \
5269 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
5277 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
5278 of AREA of glyph row ROW on window W between indices START and END.
5279 HL overrides the face for drawing glyph strings, e.g. it is
5280 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
5281 x-positions of the drawing area.
5283 This is an ugly monster macro construct because we must use alloca
5284 to allocate glyph strings (because x_draw_glyphs can be called
5287 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5290 HEAD = TAIL = NULL; \
5291 while (START < END) \
5293 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
5294 switch (first_glyph->type) \
5297 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
5298 TAIL, HL, X, LAST_X, \
5302 case COMPOSITE_GLYPH: \
5303 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5304 HEAD, TAIL, HL, X, LAST_X,\
5308 case STRETCH_GLYPH: \
5309 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5310 HEAD, TAIL, HL, X, LAST_X); \
5314 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5315 TAIL, HL, X, LAST_X); \
5322 x_set_glyph_string_background_width (s, START, LAST_X); \
5329 /* Draw glyphs between START and END in AREA of ROW on window W,
5330 starting at x-position X. X is relative to AREA in W. HL is a
5331 face-override with the following meaning:
5333 DRAW_NORMAL_TEXT draw normally
5334 DRAW_CURSOR draw in cursor face
5335 DRAW_MOUSE_FACE draw in mouse face.
5336 DRAW_INVERSE_VIDEO draw in mode line face
5337 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5338 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5340 If OVERLAPS_P is non-zero, draw only the foreground of characters
5341 and clip to the physical height of ROW.
5343 Value is the x-position reached, relative to AREA of W. */
5346 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5349 struct glyph_row
*row
;
5350 enum glyph_row_area area
;
5352 enum draw_glyphs_face hl
;
5355 struct glyph_string
*head
, *tail
;
5356 struct glyph_string
*s
;
5357 int last_x
, area_width
;
5361 /* Let's rather be paranoid than getting a SEGV. */
5362 end
= min (end
, row
->used
[area
]);
5363 start
= max (0, start
);
5364 start
= min (end
, start
);
5366 /* Translate X to frame coordinates. Set last_x to the right
5367 end of the drawing area. */
5368 if (row
->full_width_p
)
5370 /* X is relative to the left edge of W, without scroll bars
5372 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5373 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5376 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5377 last_x
= window_left_x
+ area_width
;
5379 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5381 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5382 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5388 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5389 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
5393 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5394 area_width
= window_box_width (w
, area
);
5395 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5398 /* Build a doubly-linked list of glyph_string structures between
5399 head and tail from what we have to draw. Note that the macro
5400 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5401 the reason we use a separate variable `i'. */
5403 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5406 x_reached
= tail
->x
+ tail
->background_width
;
5410 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5411 the row, redraw some glyphs in front or following the glyph
5412 strings built above. */
5413 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5416 struct glyph_string
*h
, *t
;
5418 /* Compute overhangs for all glyph strings. */
5419 for (s
= head
; s
; s
= s
->next
)
5420 x_compute_glyph_string_overhangs (s
);
5422 /* Prepend glyph strings for glyphs in front of the first glyph
5423 string that are overwritten because of the first glyph
5424 string's left overhang. The background of all strings
5425 prepended must be drawn because the first glyph string
5427 i
= x_left_overwritten (head
);
5431 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5432 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5435 x_compute_overhangs_and_x (t
, head
->x
, 1);
5436 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5439 /* Prepend glyph strings for glyphs in front of the first glyph
5440 string that overwrite that glyph string because of their
5441 right overhang. For these strings, only the foreground must
5442 be drawn, because it draws over the glyph string at `head'.
5443 The background must not be drawn because this would overwrite
5444 right overhangs of preceding glyphs for which no glyph
5446 i
= x_left_overwriting (head
);
5449 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5450 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5452 for (s
= h
; s
; s
= s
->next
)
5453 s
->background_filled_p
= 1;
5454 x_compute_overhangs_and_x (t
, head
->x
, 1);
5455 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5458 /* Append glyphs strings for glyphs following the last glyph
5459 string tail that are overwritten by tail. The background of
5460 these strings has to be drawn because tail's foreground draws
5462 i
= x_right_overwritten (tail
);
5465 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5466 DRAW_NORMAL_TEXT
, x
, last_x
,
5468 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5469 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5472 /* Append glyph strings for glyphs following the last glyph
5473 string tail that overwrite tail. The foreground of such
5474 glyphs has to be drawn because it writes into the background
5475 of tail. The background must not be drawn because it could
5476 paint over the foreground of following glyphs. */
5477 i
= x_right_overwriting (tail
);
5480 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5481 DRAW_NORMAL_TEXT
, x
, last_x
,
5483 for (s
= h
; s
; s
= s
->next
)
5484 s
->background_filled_p
= 1;
5485 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5486 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5490 /* Draw all strings. */
5491 for (s
= head
; s
; s
= s
->next
)
5492 x_draw_glyph_string (s
);
5494 if (area
== TEXT_AREA
5495 && !row
->full_width_p
5496 /* When drawing overlapping rows, only the glyph strings'
5497 foreground is drawn, which doesn't erase a cursor
5501 int x0
= head
? head
->x
: x
;
5502 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5504 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5505 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5507 if (!row
->full_width_p
&& XFASTINT (w
->left_margin_width
) != 0)
5509 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5510 x0
-= left_area_width
;
5511 x1
-= left_area_width
;
5514 notice_overwritten_cursor (w
, area
, x0
, x1
,
5515 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5518 /* Value is the x-position up to which drawn, relative to AREA of W.
5519 This doesn't include parts drawn because of overhangs. */
5520 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5521 if (!row
->full_width_p
)
5523 if (area
> LEFT_MARGIN_AREA
)
5524 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5525 if (area
> TEXT_AREA
)
5526 x_reached
-= window_box_width (w
, TEXT_AREA
);
5533 /* Fix the display of area AREA of overlapping row ROW in window W. */
5536 x_fix_overlapping_area (w
, row
, area
)
5538 struct glyph_row
*row
;
5539 enum glyph_row_area area
;
5545 if (area
== LEFT_MARGIN_AREA
)
5547 else if (area
== TEXT_AREA
)
5548 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5550 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5551 + window_box_width (w
, TEXT_AREA
));
5553 for (i
= 0; i
< row
->used
[area
];)
5555 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5557 int start
= i
, start_x
= x
;
5561 x
+= row
->glyphs
[area
][i
].pixel_width
;
5564 while (i
< row
->used
[area
]
5565 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5567 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5568 DRAW_NORMAL_TEXT
, 1);
5572 x
+= row
->glyphs
[area
][i
].pixel_width
;
5581 /* Output LEN glyphs starting at START at the nominal cursor position.
5582 Advance the nominal cursor over the text. The global variable
5583 updated_window contains the window being updated, updated_row is
5584 the glyph row being updated, and updated_area is the area of that
5585 row being updated. */
5588 x_write_glyphs (start
, len
)
5589 struct glyph
*start
;
5594 xassert (updated_window
&& updated_row
);
5599 hpos
= start
- updated_row
->glyphs
[updated_area
];
5600 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5601 updated_row
, updated_area
,
5603 DRAW_NORMAL_TEXT
, 0);
5607 /* Advance the output cursor. */
5608 output_cursor
.hpos
+= len
;
5609 output_cursor
.x
= x
;
5613 /* Insert LEN glyphs from START at the nominal cursor position. */
5616 x_insert_glyphs (start
, len
)
5617 struct glyph
*start
;
5622 int line_height
, shift_by_width
, shifted_region_width
;
5623 struct glyph_row
*row
;
5624 struct glyph
*glyph
;
5625 int frame_x
, frame_y
, hpos
;
5627 xassert (updated_window
&& updated_row
);
5630 f
= XFRAME (WINDOW_FRAME (w
));
5632 /* Get the height of the line we are in. */
5634 line_height
= row
->height
;
5636 /* Get the width of the glyphs to insert. */
5638 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5639 shift_by_width
+= glyph
->pixel_width
;
5641 /* Get the width of the region to shift right. */
5642 shifted_region_width
= (window_box_width (w
, updated_area
)
5647 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5648 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5650 mac_scroll_area (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
5651 f
->output_data
.mac
->normal_gc
,
5653 shifted_region_width
, line_height
,
5654 frame_x
+ shift_by_width
, frame_y
);
5656 /* Write the glyphs. */
5657 hpos
= start
- row
->glyphs
[updated_area
];
5658 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5659 DRAW_NORMAL_TEXT
, 0);
5661 /* Advance the output cursor. */
5662 output_cursor
.hpos
+= len
;
5663 output_cursor
.x
+= shift_by_width
;
5668 /* Delete N glyphs at the nominal cursor position. Not implemented
5679 /* Erase the current text line from the nominal cursor position
5680 (inclusive) to pixel column TO_X (exclusive). The idea is that
5681 everything from TO_X onward is already erased.
5683 TO_X is a pixel position relative to updated_area of
5684 updated_window. TO_X == -1 means clear to the end of this area. */
5687 x_clear_end_of_line (to_x
)
5691 struct window
*w
= updated_window
;
5692 int max_x
, min_y
, max_y
;
5693 int from_x
, from_y
, to_y
;
5695 xassert (updated_window
&& updated_row
);
5696 f
= XFRAME (w
->frame
);
5698 if (updated_row
->full_width_p
)
5700 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5701 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5702 && !w
->pseudo_window_p
)
5703 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5706 max_x
= window_box_width (w
, updated_area
);
5707 max_y
= window_text_bottom_y (w
);
5709 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5710 of window. For TO_X > 0, truncate to end of drawing area. */
5716 to_x
= min (to_x
, max_x
);
5718 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5720 /* Notice if the cursor will be cleared by this operation. */
5721 if (!updated_row
->full_width_p
)
5722 notice_overwritten_cursor (w
, updated_area
,
5723 output_cursor
.x
, -1,
5725 MATRIX_ROW_BOTTOM_Y (updated_row
));
5727 from_x
= output_cursor
.x
;
5729 /* Translate to frame coordinates. */
5730 if (updated_row
->full_width_p
)
5732 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5733 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5737 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5738 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5741 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5742 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5743 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5745 /* Prevent inadvertently clearing to end of the X window. */
5746 if (to_x
> from_x
&& to_y
> from_y
)
5749 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
5750 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5757 /* Clear entire frame. If updating_frame is non-null, clear that
5758 frame. Otherwise clear the selected frame. */
5768 f
= SELECTED_FRAME ();
5770 /* Clearing the frame will erase any cursor, so mark them all as no
5772 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5773 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5774 output_cursor
.x
= -1;
5776 /* We don't set the output cursor here because there will always
5777 follow an explicit cursor_to. */
5779 XClearWindow (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
5781 #if 0 /* Clearing frame on Mac OS clears scroll bars. */
5782 /* We have to clear the scroll bars, too. If we have changed
5783 colors or something like that, then they should be notified. */
5784 x_scroll_bar_clear (f
);
5787 XFlush (FRAME_MAC_DISPLAY (f
));
5793 /* Invert the middle quarter of the frame for .15 sec. */
5795 /* We use the select system call to do the waiting, so we have to make
5796 sure it's available. If it isn't, we just won't do visual bells. */
5798 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5800 /* Subtract the `struct timeval' values X and Y, storing the result in
5801 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5804 timeval_subtract (result
, x
, y
)
5805 struct timeval
*result
, x
, y
;
5807 /* Perform the carry for the later subtraction by updating y. This
5808 is safer because on some systems the tv_sec member is unsigned. */
5809 if (x
.tv_usec
< y
.tv_usec
)
5811 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5812 y
.tv_usec
-= 1000000 * nsec
;
5816 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5818 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5819 y
.tv_usec
+= 1000000 * nsec
;
5823 /* Compute the time remaining to wait. tv_usec is certainly
5825 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5826 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5828 /* Return indication of whether the result should be considered
5830 return x
.tv_sec
< y
.tv_sec
;
5842 struct timeval wakeup
;
5844 EMACS_GET_TIME (wakeup
);
5846 /* Compute time to wait until, propagating carry from usecs. */
5847 wakeup
.tv_usec
+= 150000;
5848 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5849 wakeup
.tv_usec
%= 1000000;
5851 /* Keep waiting until past the time wakeup. */
5854 struct timeval timeout
;
5856 EMACS_GET_TIME (timeout
);
5858 /* In effect, timeout = wakeup - timeout.
5859 Break if result would be negative. */
5860 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5863 /* Try to wait that long--but we might wake up sooner. */
5864 select (0, NULL
, NULL
, NULL
, &timeout
);
5873 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5876 /* Make audible bell. */
5881 struct frame
*f
= SELECTED_FRAME ();
5883 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5891 XFlush (FRAME_MAC_DISPLAY (f
));
5898 /* Specify how many text lines, from the top of the window,
5899 should be affected by insert-lines and delete-lines operations.
5900 This, and those operations, are used only within an update
5901 that is bounded by calls to x_update_begin and x_update_end. */
5904 XTset_terminal_window (n
)
5907 /* This function intentionally left blank. */
5912 /***********************************************************************
5914 ***********************************************************************/
5916 /* Perform an insert-lines or delete-lines operation, inserting N
5917 lines or deleting -N lines at vertical position VPOS. */
5920 x_ins_del_lines (vpos
, n
)
5927 /* Scroll part of the display as described by RUN. */
5930 x_scroll_run (w
, run
)
5934 struct frame
*f
= XFRAME (w
->frame
);
5935 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5937 /* Get frame-relative bounding box of the text display area of W,
5938 without mode lines. Include in this box the left and right
5940 window_box (w
, -1, &x
, &y
, &width
, &height
);
5941 width
+= FRAME_X_FRINGE_WIDTH (f
);
5942 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5944 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5945 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5946 bottom_y
= y
+ height
;
5950 /* Scrolling up. Make sure we don't copy part of the mode
5951 line at the bottom. */
5952 if (from_y
+ run
->height
> bottom_y
)
5953 height
= bottom_y
- from_y
;
5955 height
= run
->height
;
5959 /* Scolling down. Make sure we don't copy over the mode line.
5961 if (to_y
+ run
->height
> bottom_y
)
5962 height
= bottom_y
- to_y
;
5964 height
= run
->height
;
5969 /* Cursor off. Will be switched on again in x_update_window_end. */
5973 mac_scroll_area (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
5974 f
->output_data
.mac
->normal_gc
,
5984 /***********************************************************************
5986 ***********************************************************************/
5988 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5989 corner of the exposed rectangle. W and H are width and height of
5990 the exposed area. All are pixel values. W or H zero means redraw
5991 the entire frame. */
5994 expose_frame (f
, x
, y
, w
, h
)
5999 int mouse_face_overwritten_p
= 0;
6001 TRACE ((stderr
, "expose_frame "));
6003 /* No need to redraw if frame will be redrawn soon. */
6004 if (FRAME_GARBAGED_P (f
))
6006 TRACE ((stderr
, " garbaged\n"));
6010 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
6011 or deactivated here, for unknown reasons, activated scroll bars
6012 are shown in deactivated frames in some instances. */
6013 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
6014 activate_scroll_bars (f
);
6016 deactivate_scroll_bars (f
);
6018 /* If basic faces haven't been realized yet, there is no point in
6019 trying to redraw anything. This can happen when we get an expose
6020 event while Emacs is starting, e.g. by moving another window. */
6021 if (FRAME_FACE_CACHE (f
) == NULL
6022 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
6024 TRACE ((stderr
, " no faces\n"));
6028 if (w
== 0 || h
== 0)
6031 r
.right
= CANON_X_UNIT (f
) * f
->width
;
6032 r
.bottom
= CANON_Y_UNIT (f
) * f
->height
;
6042 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.left
, r
.top
, r
.right
, r
.bottom
));
6043 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
6045 if (WINDOWP (f
->tool_bar_window
))
6046 mouse_face_overwritten_p
6047 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
6049 /* Some window managers support a focus-follows-mouse style with
6050 delayed raising of frames. Imagine a partially obscured frame,
6051 and moving the mouse into partially obscured mouse-face on that
6052 frame. The visible part of the mouse-face will be highlighted,
6053 then the WM raises the obscured frame. With at least one WM, KDE
6054 2.1, Emacs is not getting any event for the raising of the frame
6055 (even tried with SubstructureRedirectMask), only Expose events.
6056 These expose events will draw text normally, i.e. not
6057 highlighted. Which means we must redo the highlight here.
6058 Subsume it under ``we love X''. --gerd 2001-08-15 */
6059 /* Included in Windows version because Windows most likely does not
6060 do the right thing if any third party tool offers
6061 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
6062 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
6064 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6065 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6067 int x
= dpyinfo
->mouse_face_mouse_x
;
6068 int y
= dpyinfo
->mouse_face_mouse_y
;
6069 clear_mouse_face (dpyinfo
);
6070 note_mouse_highlight (f
, x
, y
);
6076 /* Redraw (parts) of all windows in the window tree rooted at W that
6077 intersect R. R contains frame pixel coordinates. */
6080 expose_window_tree (w
, r
)
6084 struct frame
*f
= XFRAME (w
->frame
);
6085 int mouse_face_overwritten_p
= 0;
6087 while (w
&& !FRAME_GARBAGED_P (f
))
6089 if (!NILP (w
->hchild
))
6090 mouse_face_overwritten_p
6091 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
6092 else if (!NILP (w
->vchild
))
6093 mouse_face_overwritten_p
6094 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
6096 mouse_face_overwritten_p
|= expose_window (w
, r
);
6098 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
6101 return mouse_face_overwritten_p
;
6105 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
6106 which intersects rectangle R. R is in window-relative coordinates. */
6109 expose_area (w
, row
, r
, area
)
6111 struct glyph_row
*row
;
6113 enum glyph_row_area area
;
6115 struct glyph
*first
= row
->glyphs
[area
];
6116 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
6118 int first_x
, start_x
, x
;
6120 if (area
== TEXT_AREA
&& row
->fill_line_p
)
6121 /* If row extends face to end of line write the whole line. */
6122 x_draw_glyphs (w
, 0, row
, area
,
6124 DRAW_NORMAL_TEXT
, 0);
6127 /* Set START_X to the window-relative start position for drawing glyphs of
6128 AREA. The first glyph of the text area can be partially visible.
6129 The first glyphs of other areas cannot. */
6130 if (area
== LEFT_MARGIN_AREA
)
6132 else if (area
== TEXT_AREA
)
6133 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
6135 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
6136 + window_box_width (w
, TEXT_AREA
));
6139 /* Find the first glyph that must be redrawn. */
6141 && x
+ first
->pixel_width
< r
->left
)
6143 x
+= first
->pixel_width
;
6147 /* Find the last one. */
6153 x
+= last
->pixel_width
;
6159 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
6160 first
- row
->glyphs
[area
],
6161 last
- row
->glyphs
[area
],
6162 DRAW_NORMAL_TEXT
, 0);
6167 /* Redraw the parts of the glyph row ROW on window W intersecting
6168 rectangle R. R is in window-relative coordinates. Value is
6169 non-zero if mouse face was overwritten. */
6172 expose_line (w
, row
, r
)
6174 struct glyph_row
*row
;
6177 xassert (row
->enabled_p
);
6179 if (row
->mode_line_p
|| w
->pseudo_window_p
)
6180 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
6181 DRAW_NORMAL_TEXT
, 0);
6184 if (row
->used
[LEFT_MARGIN_AREA
])
6185 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
6186 if (row
->used
[TEXT_AREA
])
6187 expose_area (w
, row
, r
, TEXT_AREA
);
6188 if (row
->used
[RIGHT_MARGIN_AREA
])
6189 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
6190 x_draw_row_fringe_bitmaps (w
, row
);
6193 return row
->mouse_face_p
;
6197 /* Return non-zero if W's cursor intersects rectangle R. */
6200 x_phys_cursor_in_rect_p (w
, r
)
6205 struct glyph
*cursor_glyph
;
6207 cursor_glyph
= get_phys_cursor_glyph (w
);
6210 cr
.left
= w
->phys_cursor
.x
;
6211 cr
.top
= w
->phys_cursor
.y
;
6212 cr
.right
= cr
.left
+ cursor_glyph
->pixel_width
;
6213 cr
.bottom
= cr
.top
+ w
->phys_cursor_height
;
6214 return x_intersect_rectangles (&cr
, r
, &result
);
6221 /* Redraw the part of window W intersection rectagle FR. Pixel
6222 coordinates in FR are frame relative. Call this function with
6223 input blocked. Value is non-zero if the exposure overwrites
6227 expose_window (w
, fr
)
6231 struct frame
*f
= XFRAME (w
->frame
);
6233 int mouse_face_overwritten_p
= 0;
6235 /* If window is not yet fully initialized, do nothing. This can
6236 happen when toolkit scroll bars are used and a window is split.
6237 Reconfiguring the scroll bar will generate an expose for a newly
6239 if (w
->current_matrix
== NULL
)
6242 /* When we're currently updating the window, display and current
6243 matrix usually don't agree. Arrange for a thorough display
6245 if (w
== updated_window
)
6247 SET_FRAME_GARBAGED (f
);
6251 /* Frame-relative pixel rectangle of W. */
6252 wr
.left
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6253 wr
.top
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6254 wr
.right
= wr
.left
+ XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6255 wr
.bottom
= wr
.top
+ XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6257 if (x_intersect_rectangles (fr
, &wr
, &r
))
6259 int yb
= window_text_bottom_y (w
);
6260 struct glyph_row
*row
;
6261 int cursor_cleared_p
;
6263 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6264 r
.left
, r
.top
, r
.right
, r
.bottom
));
6266 /* Convert to window coordinates. */
6267 r
.left
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.left
);
6268 r
.right
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.right
);
6269 r
.top
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.top
);
6270 r
.bottom
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.bottom
);
6272 /* Turn off the cursor. */
6273 if (!w
->pseudo_window_p
6274 && x_phys_cursor_in_rect_p (w
, &r
))
6277 cursor_cleared_p
= 1;
6280 cursor_cleared_p
= 0;
6282 /* Find the first row intersecting the rectangle R. */
6283 for (row
= w
->current_matrix
->rows
;
6288 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6290 if ((y0
>= r
.top
&& y0
< r
.bottom
)
6291 || (y1
> r
.top
&& y1
< r
.bottom
)
6292 || (r
.top
>= y0
&& r
.top
< y1
)
6293 || (r
.bottom
> y0
&& r
.bottom
< y1
))
6295 if (expose_line (w
, row
, &r
))
6296 mouse_face_overwritten_p
= 1;
6303 /* Display the mode line if there is one. */
6304 if (WINDOW_WANTS_MODELINE_P (w
)
6305 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6307 && row
->y
< r
.bottom
)
6309 if (expose_line (w
, row
, &r
))
6310 mouse_face_overwritten_p
= 1;
6313 if (!w
->pseudo_window_p
)
6315 /* Draw border between windows. */
6316 x_draw_vertical_border (w
);
6318 /* Turn the cursor on again. */
6319 if (cursor_cleared_p
)
6320 x_update_window_cursor (w
, 1);
6324 /* Display scroll bar for this window. */
6325 if (!NILP (w
->vertical_scroll_bar
))
6328 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
6333 return mouse_face_overwritten_p
;
6337 x_intersect_rectangles (r1
, r2
, result
)
6338 Rect
*r1
, *r2
, *result
;
6341 Rect
*upper
, *lower
;
6342 int intersection_p
= 0;
6344 /* Rerrange so that R1 is the left-most rectangle. */
6345 if (r1
->left
< r2
->left
)
6346 left
= r1
, right
= r2
;
6348 left
= r2
, right
= r1
;
6350 /* X0 of the intersection is right.x0, if this is inside R1,
6351 otherwise there is no intersection. */
6352 if (right
->left
<= left
->right
)
6354 result
->left
= right
->left
;
6356 /* The right end of the intersection is the minimum of the
6357 the right ends of left and right. */
6358 result
->right
= min (left
->right
, right
->right
);
6360 /* Same game for Y. */
6361 if (r1
->top
< r2
->top
)
6362 upper
= r1
, lower
= r2
;
6364 upper
= r2
, lower
= r1
;
6366 /* The upper end of the intersection is lower.y0, if this is inside
6367 of upper. Otherwise, there is no intersection. */
6368 if (lower
->top
<= upper
->bottom
)
6370 result
->top
= lower
->top
;
6372 /* The lower end of the intersection is the minimum of the lower
6373 ends of upper and lower. */
6374 result
->bottom
= min (lower
->bottom
, upper
->bottom
);
6379 return intersection_p
;
6390 x_update_cursor (f
, 1);
6394 frame_unhighlight (f
)
6397 x_update_cursor (f
, 1);
6400 /* The focus has changed. Update the frames as necessary to reflect
6401 the new situation. Note that we can't change the selected frame
6402 here, because the Lisp code we are interrupting might become confused.
6403 Each event gets marked with the frame in which it occurred, so the
6404 Lisp code can tell when the switch took place by examining the events. */
6407 x_new_focus_frame (dpyinfo
, frame
)
6408 struct x_display_info
*dpyinfo
;
6409 struct frame
*frame
;
6411 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6413 if (frame
!= dpyinfo
->x_focus_frame
)
6415 /* Set this before calling other routines, so that they see
6416 the correct value of x_focus_frame. */
6417 dpyinfo
->x_focus_frame
= frame
;
6419 if (old_focus
&& old_focus
->auto_lower
)
6420 x_lower_frame (old_focus
);
6423 selected_frame
= frame
;
6424 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6426 Fselect_window (selected_frame
->selected_window
);
6427 choose_minibuf_frame ();
6430 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6431 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6433 pending_autoraise_frame
= 0;
6436 x_frame_rehighlight (dpyinfo
);
6439 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6442 x_mouse_leave (dpyinfo
)
6443 struct x_display_info
*dpyinfo
;
6445 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6448 /* The focus has changed, or we have redirected a frame's focus to
6449 another frame (this happens when a frame uses a surrogate
6450 mini-buffer frame). Shift the highlight as appropriate.
6452 The FRAME argument doesn't necessarily have anything to do with which
6453 frame is being highlighted or un-highlighted; we only use it to find
6454 the appropriate X display info. */
6457 XTframe_rehighlight (frame
)
6458 struct frame
*frame
;
6460 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6464 x_frame_rehighlight (dpyinfo
)
6465 struct x_display_info
*dpyinfo
;
6467 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6469 if (dpyinfo
->x_focus_frame
)
6471 dpyinfo
->x_highlight_frame
6472 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6473 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6474 : dpyinfo
->x_focus_frame
);
6475 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6477 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6478 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6482 dpyinfo
->x_highlight_frame
= 0;
6484 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6487 frame_unhighlight (old_highlight
);
6488 if (dpyinfo
->x_highlight_frame
)
6489 frame_highlight (dpyinfo
->x_highlight_frame
);
6495 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6497 #if 0 /* MAC_TODO */
6498 /* Initialize mode_switch_bit and modifier_meaning. */
6500 x_find_modifier_meanings (dpyinfo
)
6501 struct x_display_info
*dpyinfo
;
6503 int min_code
, max_code
;
6506 XModifierKeymap
*mods
;
6508 dpyinfo
->meta_mod_mask
= 0;
6509 dpyinfo
->shift_lock_mask
= 0;
6510 dpyinfo
->alt_mod_mask
= 0;
6511 dpyinfo
->super_mod_mask
= 0;
6512 dpyinfo
->hyper_mod_mask
= 0;
6515 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6517 min_code
= dpyinfo
->display
->min_keycode
;
6518 max_code
= dpyinfo
->display
->max_keycode
;
6521 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6522 min_code
, max_code
- min_code
+ 1,
6524 mods
= XGetModifierMapping (dpyinfo
->display
);
6526 /* Scan the modifier table to see which modifier bits the Meta and
6527 Alt keysyms are on. */
6529 int row
, col
; /* The row and column in the modifier table. */
6531 for (row
= 3; row
< 8; row
++)
6532 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6535 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6537 /* Zeroes are used for filler. Skip them. */
6541 /* Are any of this keycode's keysyms a meta key? */
6545 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6547 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6553 dpyinfo
->meta_mod_mask
|= (1 << row
);
6558 dpyinfo
->alt_mod_mask
|= (1 << row
);
6563 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6568 dpyinfo
->super_mod_mask
|= (1 << row
);
6572 /* Ignore this if it's not on the lock modifier. */
6573 if ((1 << row
) == LockMask
)
6574 dpyinfo
->shift_lock_mask
= LockMask
;
6582 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6583 if (! dpyinfo
->meta_mod_mask
)
6585 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6586 dpyinfo
->alt_mod_mask
= 0;
6589 /* If some keys are both alt and meta,
6590 make them just meta, not alt. */
6591 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6593 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6596 XFree ((char *) syms
);
6597 XFreeModifiermap (mods
);
6600 #endif /* MAC_TODO */
6602 /* Convert between the modifier bits X uses and the modifier bits
6606 x_mac_to_emacs_modifiers (dpyinfo
, state
)
6607 struct x_display_info
*dpyinfo
;
6608 unsigned short state
;
6610 return (((state
& shiftKey
) ? shift_modifier
: 0)
6611 | ((state
& controlKey
) ? ctrl_modifier
: 0)
6612 | ((state
& cmdKey
) ? meta_modifier
: 0)
6613 | ((state
& optionKey
) ? alt_modifier
: 0));
6616 #if 0 /* MAC_TODO */
6617 static unsigned short
6618 x_emacs_to_x_modifiers (dpyinfo
, state
)
6619 struct x_display_info
*dpyinfo
;
6622 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6623 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6624 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6625 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6626 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6627 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6629 #endif /* MAC_TODO */
6631 /* Convert a keysym to its name. */
6634 x_get_keysym_name (keysym
)
6641 value
= XKeysymToString (keysym
);
6652 /* Mouse clicks and mouse movement. Rah. */
6654 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6655 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6656 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6657 not force the value into range. */
6660 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6662 register int pix_x
, pix_y
;
6663 register int *x
, *y
;
6667 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
6668 if (NILP (Vwindow_system
))
6675 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6676 even for negative values. */
6678 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
6680 pix_y
-= (f
)->output_data
.mac
->line_height
- 1;
6682 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6683 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6687 bounds
->left
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6688 bounds
->top
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6689 bounds
->right
= bounds
->left
+ FONT_WIDTH (FRAME_FONT (f
)) - 1;
6690 bounds
->bottom
= bounds
->top
+ f
->output_data
.mac
->line_height
- 1;
6697 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6698 pix_x
= FRAME_WINDOW_WIDTH (f
);
6702 else if (pix_y
> f
->height
)
6711 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6712 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6713 can't tell the positions because W's display is not up to date,
6717 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6720 int *frame_x
, *frame_y
;
6724 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6725 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6727 if (display_completed
)
6729 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6730 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6731 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6737 *frame_x
+= glyph
->pixel_width
;
6745 *frame_y
= *frame_x
= 0;
6749 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6750 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6755 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6757 If the event is a button press, then note that we have grabbed
6761 construct_mouse_click (result
, event
, f
)
6762 struct input_event
*result
;
6768 result
->kind
= mouse_click
;
6769 result
->code
= 0; /* only one mouse button */
6770 result
->timestamp
= event
->when
;
6771 result
->modifiers
= event
->what
== mouseDown
? down_modifier
: up_modifier
;
6773 mouseLoc
= event
->where
;
6775 #if TARGET_API_MAC_CARBON
6776 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f
)));
6778 SetPort (FRAME_MAC_WINDOW (f
));
6781 GlobalToLocal (&mouseLoc
);
6782 XSETINT (result
->x
, mouseLoc
.h
);
6783 XSETINT (result
->y
, mouseLoc
.v
);
6785 XSETFRAME (result
->frame_or_window
, f
);
6792 /* Function to report a mouse movement to the mainstream Emacs code.
6793 The input handler calls this.
6795 We have received a mouse movement event, which is given in *event.
6796 If the mouse is over a different glyph than it was last time, tell
6797 the mainstream emacs code by setting mouse_moved. If not, ask for
6798 another motion event, so we can check again the next time it moves. */
6800 static Point last_mouse_motion_position
;
6801 static Lisp_Object last_mouse_motion_frame
;
6804 note_mouse_movement (frame
, pos
)
6808 #if TARGET_API_MAC_CARBON
6812 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
6813 last_mouse_motion_position
= *pos
;
6814 XSETFRAME (last_mouse_motion_frame
, frame
);
6816 #if TARGET_API_MAC_CARBON
6817 if (!PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
)))
6819 if (!PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
))
6822 frame
->mouse_moved
= 1;
6823 last_mouse_scroll_bar
= Qnil
;
6824 note_mouse_highlight (frame
, -1, -1);
6826 /* Has the mouse moved off the glyph it was on at the last sighting? */
6827 else if (pos
->h
< last_mouse_glyph
.left
6828 || pos
->h
>= last_mouse_glyph
.right
6829 || pos
->v
< last_mouse_glyph
.top
6830 || pos
->v
>= last_mouse_glyph
.bottom
)
6832 frame
->mouse_moved
= 1;
6833 last_mouse_scroll_bar
= Qnil
;
6834 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
6838 /* This is used for debugging, to turn off note_mouse_highlight. */
6840 int disable_mouse_highlight
;
6844 /************************************************************************
6846 ************************************************************************/
6848 /* Find the glyph under window-relative coordinates X/Y in window W.
6849 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6850 strings. Return in *HPOS and *VPOS the row and column number of
6851 the glyph found. Return in *AREA the glyph area containing X.
6852 Value is a pointer to the glyph found or null if X/Y is not on
6853 text, or we can't tell because W's current matrix is not up to
6856 static struct glyph
*
6857 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6860 int *hpos
, *vpos
, *area
;
6863 struct glyph
*glyph
, *end
;
6864 struct glyph_row
*row
= NULL
;
6865 int x0
, i
, left_area_width
;
6867 /* Find row containing Y. Give up if some row is not enabled. */
6868 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6870 row
= MATRIX_ROW (w
->current_matrix
, i
);
6871 if (!row
->enabled_p
)
6873 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6880 /* Give up if Y is not in the window. */
6881 if (i
== w
->current_matrix
->nrows
)
6884 /* Get the glyph area containing X. */
6885 if (w
->pseudo_window_p
)
6892 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6893 if (x
< left_area_width
)
6895 *area
= LEFT_MARGIN_AREA
;
6898 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6901 x0
= row
->x
+ left_area_width
;
6905 *area
= RIGHT_MARGIN_AREA
;
6906 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6910 /* Find glyph containing X. */
6911 glyph
= row
->glyphs
[*area
];
6912 end
= glyph
+ row
->used
[*area
];
6915 if (x
< x0
+ glyph
->pixel_width
)
6917 if (w
->pseudo_window_p
)
6919 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6923 x0
+= glyph
->pixel_width
;
6930 *hpos
= glyph
- row
->glyphs
[*area
];
6935 /* Convert frame-relative x/y to coordinates relative to window W.
6936 Takes pseudo-windows into account. */
6939 frame_to_window_pixel_xy (w
, x
, y
)
6943 if (w
->pseudo_window_p
)
6945 /* A pseudo-window is always full-width, and starts at the
6946 left edge of the frame, plus a frame border. */
6947 struct frame
*f
= XFRAME (w
->frame
);
6948 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6949 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6953 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6954 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6959 /* Take proper action when mouse has moved to the mode or header line of
6960 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6961 mode line. X is relative to the start of the text display area of
6962 W, so the width of fringes and scroll bars must be subtracted
6963 to get a position relative to the start of the mode line. */
6966 note_mode_line_highlight (w
, x
, mode_line_p
)
6970 struct frame
*f
= XFRAME (w
->frame
);
6971 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6972 struct Cursor
*cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6973 struct glyph_row
*row
;
6976 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6978 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6982 struct glyph
*glyph
, *end
;
6983 Lisp_Object help
, map
;
6986 /* Find the glyph under X. */
6987 glyph
= row
->glyphs
[TEXT_AREA
];
6988 end
= glyph
+ row
->used
[TEXT_AREA
];
6989 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6990 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
6993 && x
>= x0
+ glyph
->pixel_width
)
6995 x0
+= glyph
->pixel_width
;
7000 && STRINGP (glyph
->object
)
7001 && XSTRING (glyph
->object
)->intervals
7002 && glyph
->charpos
>= 0
7003 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
7005 /* If we're on a string with `help-echo' text property,
7006 arrange for the help to be displayed. This is done by
7007 setting the global variable help_echo to the help string. */
7008 help
= Fget_text_property (make_number (glyph
->charpos
),
7009 Qhelp_echo
, glyph
->object
);
7013 XSETWINDOW (help_echo_window
, w
);
7014 help_echo_object
= glyph
->object
;
7015 help_echo_pos
= glyph
->charpos
;
7018 /* Change the mouse pointer according to what is under X/Y. */
7019 map
= Fget_text_property (make_number (glyph
->charpos
),
7020 Qlocal_map
, glyph
->object
);
7022 cursor
= f
->output_data
.mac
->nontext_cursor
;
7025 map
= Fget_text_property (make_number (glyph
->charpos
),
7026 Qkeymap
, glyph
->object
);
7028 cursor
= f
->output_data
.mac
->nontext_cursor
;
7033 #if 0 /* MAC_TODO: mouse cursor */
7034 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7039 /* Take proper action when the mouse has moved to position X, Y on
7040 frame F as regards highlighting characters that have mouse-face
7041 properties. Also de-highlighting chars where the mouse was before.
7042 X and Y can be negative or out of range. */
7045 note_mouse_highlight (f
, x
, y
)
7049 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7056 /* When a menu is active, don't highlight because this looks odd. */
7057 if (popup_activated ())
7061 if (NILP (Vmouse_highlight
)
7062 || !f
->glyphs_initialized_p
)
7065 dpyinfo
->mouse_face_mouse_x
= x
;
7066 dpyinfo
->mouse_face_mouse_y
= y
;
7067 dpyinfo
->mouse_face_mouse_frame
= f
;
7069 if (dpyinfo
->mouse_face_defer
)
7074 dpyinfo
->mouse_face_deferred_gc
= 1;
7078 /* Which window is that in? */
7079 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
7081 /* If we were displaying active text in another window, clear that. */
7082 if (! EQ (window
, dpyinfo
->mouse_face_window
))
7083 clear_mouse_face (dpyinfo
);
7085 /* Not on a window -> return. */
7086 if (!WINDOWP (window
))
7089 /* Reset help_echo. It will get recomputed below. */
7092 /* Convert to window-relative pixel coordinates. */
7093 w
= XWINDOW (window
);
7094 frame_to_window_pixel_xy (w
, &x
, &y
);
7096 /* Handle tool-bar window differently since it doesn't display a
7098 if (EQ (window
, f
->tool_bar_window
))
7100 note_tool_bar_highlight (f
, x
, y
);
7104 /* Mouse is on the mode or header line? */
7105 if (portion
== 1 || portion
== 3)
7107 note_mode_line_highlight (w
, x
, portion
== 1);
7110 #if 0 /* TODO: mouse cursor */
7112 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
7114 cursor
= f
->output_data
.x
->text_cursor
;
7116 /* Are we in a window whose display is up to date?
7117 And verify the buffer's text has not changed. */
7118 b
= XBUFFER (w
->buffer
);
7119 if (/* Within text portion of the window. */
7121 && EQ (w
->window_end_valid
, w
->buffer
)
7122 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
7123 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
7125 int hpos
, vpos
, pos
, i
, area
;
7126 struct glyph
*glyph
;
7128 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
7129 Lisp_Object
*overlay_vec
= NULL
;
7131 struct buffer
*obuf
;
7132 int obegv
, ozv
, same_region
;
7134 /* Find the glyph under X/Y. */
7135 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
7137 /* Clear mouse face if X/Y not over text. */
7139 || area
!= TEXT_AREA
7140 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
7142 clear_mouse_face (dpyinfo
);
7143 /* TODO: mouse cursor */
7147 pos
= glyph
->charpos
;
7148 object
= glyph
->object
;
7149 if (!STRINGP (object
) && !BUFFERP (object
))
7152 /* If we get an out-of-range value, return now; avoid an error. */
7153 if (BUFFERP (object
) && pos
> BUF_Z (b
))
7156 /* Make the window's buffer temporarily current for
7157 overlays_at and compute_char_face. */
7158 obuf
= current_buffer
;
7165 /* Is this char mouse-active or does it have help-echo? */
7166 position
= make_number (pos
);
7168 if (BUFFERP (object
))
7170 /* Put all the overlays we want in a vector in overlay_vec.
7171 Store the length in len. If there are more than 10, make
7172 enough space for all, and try again. */
7174 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7175 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
7176 if (noverlays
> len
)
7179 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7180 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
7183 /* Sort overlays into increasing priority order. */
7184 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7189 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
7190 && vpos
>= dpyinfo
->mouse_face_beg_row
7191 && vpos
<= dpyinfo
->mouse_face_end_row
7192 && (vpos
> dpyinfo
->mouse_face_beg_row
7193 || hpos
>= dpyinfo
->mouse_face_beg_col
)
7194 && (vpos
< dpyinfo
->mouse_face_end_row
7195 || hpos
< dpyinfo
->mouse_face_end_col
7196 || dpyinfo
->mouse_face_past_end
));
7198 /* TODO: if (same_region)
7201 /* Check mouse-face highlighting. */
7203 /* If there exists an overlay with mouse-face overlapping
7204 the one we are currently highlighting, we have to
7205 check if we enter the overlapping overlay, and then
7207 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
7208 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
7210 /* Find the highest priority overlay that has a mouse-face
7213 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7215 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7216 if (!NILP (mouse_face
))
7217 overlay
= overlay_vec
[i
];
7220 /* If we're actually highlighting the same overlay as
7221 before, there's no need to do that again. */
7223 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7224 goto check_help_echo
;
7226 dpyinfo
->mouse_face_overlay
= overlay
;
7228 /* Clear the display of the old active region, if any. */
7229 clear_mouse_face (dpyinfo
);
7230 /* TODO: mouse cursor changes. */
7232 /* If no overlay applies, get a text property. */
7234 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7236 /* Handle the overlay case. */
7237 if (!NILP (overlay
))
7239 /* Find the range of text around this char that
7240 should be active. */
7241 Lisp_Object before
, after
;
7244 before
= Foverlay_start (overlay
);
7245 after
= Foverlay_end (overlay
);
7246 /* Record this as the current active region. */
7247 fast_find_position (w
, XFASTINT (before
),
7248 &dpyinfo
->mouse_face_beg_col
,
7249 &dpyinfo
->mouse_face_beg_row
,
7250 &dpyinfo
->mouse_face_beg_x
,
7251 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7253 dpyinfo
->mouse_face_past_end
7254 = !fast_find_position (w
, XFASTINT (after
),
7255 &dpyinfo
->mouse_face_end_col
,
7256 &dpyinfo
->mouse_face_end_row
,
7257 &dpyinfo
->mouse_face_end_x
,
7258 &dpyinfo
->mouse_face_end_y
, Qnil
);
7259 dpyinfo
->mouse_face_window
= window
;
7261 dpyinfo
->mouse_face_face_id
7262 = face_at_buffer_position (w
, pos
, 0, 0,
7263 &ignore
, pos
+ 1, 1);
7265 /* Display it as active. */
7266 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7267 /* TODO: mouse cursor changes. */
7269 /* Handle the text property case. */
7270 else if (! NILP (mouse_face
) && BUFFERP (object
))
7272 /* Find the range of text around this char that
7273 should be active. */
7274 Lisp_Object before
, after
, beginning
, end
;
7277 beginning
= Fmarker_position (w
->start
);
7278 end
= make_number (BUF_Z (XBUFFER (object
))
7279 - XFASTINT (w
->window_end_pos
));
7281 = Fprevious_single_property_change (make_number (pos
+ 1),
7285 = Fnext_single_property_change (position
, Qmouse_face
,
7288 /* Record this as the current active region. */
7289 fast_find_position (w
, XFASTINT (before
),
7290 &dpyinfo
->mouse_face_beg_col
,
7291 &dpyinfo
->mouse_face_beg_row
,
7292 &dpyinfo
->mouse_face_beg_x
,
7293 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7294 dpyinfo
->mouse_face_past_end
7295 = !fast_find_position (w
, XFASTINT (after
),
7296 &dpyinfo
->mouse_face_end_col
,
7297 &dpyinfo
->mouse_face_end_row
,
7298 &dpyinfo
->mouse_face_end_x
,
7299 &dpyinfo
->mouse_face_end_y
, Qnil
);
7300 dpyinfo
->mouse_face_window
= window
;
7302 if (BUFFERP (object
))
7303 dpyinfo
->mouse_face_face_id
7304 = face_at_buffer_position (w
, pos
, 0, 0,
7305 &ignore
, pos
+ 1, 1);
7307 /* Display it as active. */
7308 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7309 /* TODO: mouse cursor changes. */
7311 else if (!NILP (mouse_face
) && STRINGP (object
))
7316 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7319 e
= Fnext_single_property_change (position
, Qmouse_face
,
7322 b
= make_number (0);
7324 e
= make_number (XSTRING (object
)->size
- 1);
7325 fast_find_string_pos (w
, XINT (b
), object
,
7326 &dpyinfo
->mouse_face_beg_col
,
7327 &dpyinfo
->mouse_face_beg_row
,
7328 &dpyinfo
->mouse_face_beg_x
,
7329 &dpyinfo
->mouse_face_beg_y
, 0);
7330 fast_find_string_pos (w
, XINT (e
), object
,
7331 &dpyinfo
->mouse_face_end_col
,
7332 &dpyinfo
->mouse_face_end_row
,
7333 &dpyinfo
->mouse_face_end_x
,
7334 &dpyinfo
->mouse_face_end_y
, 1);
7335 dpyinfo
->mouse_face_past_end
= 0;
7336 dpyinfo
->mouse_face_window
= window
;
7337 dpyinfo
->mouse_face_face_id
7338 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7340 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7341 /* TODO: mouse cursor changes. */
7343 else if (STRINGP (object
) && NILP (mouse_face
))
7345 /* A string which doesn't have mouse-face, but
7346 the text ``under'' it might have. */
7347 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7348 int start
= MATRIX_ROW_START_CHARPOS (r
);
7350 pos
= string_buffer_position (w
, object
, start
);
7352 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7356 if (!NILP (mouse_face
) && !NILP (overlay
))
7358 Lisp_Object before
= Foverlay_start (overlay
);
7359 Lisp_Object after
= Foverlay_end (overlay
);
7362 /* Note that we might not be able to find position
7363 BEFORE in the glyph matrix if the overlay is
7364 entirely covered by a `display' property. In
7365 this case, we overshoot. So let's stop in
7366 the glyph matrix before glyphs for OBJECT. */
7367 fast_find_position (w
, XFASTINT (before
),
7368 &dpyinfo
->mouse_face_beg_col
,
7369 &dpyinfo
->mouse_face_beg_row
,
7370 &dpyinfo
->mouse_face_beg_x
,
7371 &dpyinfo
->mouse_face_beg_y
,
7374 dpyinfo
->mouse_face_past_end
7375 = !fast_find_position (w
, XFASTINT (after
),
7376 &dpyinfo
->mouse_face_end_col
,
7377 &dpyinfo
->mouse_face_end_row
,
7378 &dpyinfo
->mouse_face_end_x
,
7379 &dpyinfo
->mouse_face_end_y
,
7381 dpyinfo
->mouse_face_window
= window
;
7382 dpyinfo
->mouse_face_face_id
7383 = face_at_buffer_position (w
, pos
, 0, 0,
7384 &ignore
, pos
+ 1, 1);
7386 /* Display it as active. */
7387 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7388 /* TODO: mouse cursor changes. */
7395 /* Look for a `help-echo' property. */
7397 Lisp_Object help
, overlay
;
7399 /* Check overlays first. */
7400 help
= overlay
= Qnil
;
7401 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7403 overlay
= overlay_vec
[i
];
7404 help
= Foverlay_get (overlay
, Qhelp_echo
);
7410 help_echo_window
= window
;
7411 help_echo_object
= overlay
;
7412 help_echo_pos
= pos
;
7416 Lisp_Object object
= glyph
->object
;
7417 int charpos
= glyph
->charpos
;
7419 /* Try text properties. */
7420 if (STRINGP (object
)
7422 && charpos
< XSTRING (object
)->size
)
7424 help
= Fget_text_property (make_number (charpos
),
7425 Qhelp_echo
, object
);
7428 /* If the string itself doesn't specify a help-echo,
7429 see if the buffer text ``under'' it does. */
7431 = MATRIX_ROW (w
->current_matrix
, vpos
);
7432 int start
= MATRIX_ROW_START_CHARPOS (r
);
7433 int pos
= string_buffer_position (w
, object
, start
);
7436 help
= Fget_char_property (make_number (pos
),
7437 Qhelp_echo
, w
->buffer
);
7446 else if (BUFFERP (object
)
7449 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7455 help_echo_window
= window
;
7456 help_echo_object
= object
;
7457 help_echo_pos
= charpos
;
7464 current_buffer
= obuf
;
7468 /* TODO: mouse cursor changes. */
7473 redo_mouse_highlight ()
7475 if (!NILP (last_mouse_motion_frame
)
7476 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7477 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7478 last_mouse_motion_position
.h
,
7479 last_mouse_motion_position
.v
);
7484 /***********************************************************************
7486 ***********************************************************************/
7488 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7489 struct glyph
**, int *, int *, int *));
7491 /* Tool-bar item index of the item on which a mouse button was pressed
7494 static int last_tool_bar_item
;
7497 /* Get information about the tool-bar item at position X/Y on frame F.
7498 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7499 the current matrix of the tool-bar window of F, or NULL if not
7500 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7501 item in F->current_tool_bar_items. Value is
7503 -1 if X/Y is not on a tool-bar item
7504 0 if X/Y is on the same item that was highlighted before.
7508 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7511 struct glyph
**glyph
;
7512 int *hpos
, *vpos
, *prop_idx
;
7514 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7515 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7518 /* Find the glyph under X/Y. */
7519 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7523 /* Get the start of this tool-bar item's properties in
7524 f->current_tool_bar_items. */
7525 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7528 /* Is mouse on the highlighted item? */
7529 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7530 && *vpos
>= dpyinfo
->mouse_face_beg_row
7531 && *vpos
<= dpyinfo
->mouse_face_end_row
7532 && (*vpos
> dpyinfo
->mouse_face_beg_row
7533 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7534 && (*vpos
< dpyinfo
->mouse_face_end_row
7535 || *hpos
< dpyinfo
->mouse_face_end_col
7536 || dpyinfo
->mouse_face_past_end
))
7543 /* Handle mouse button event on the tool-bar of frame F, at
7544 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7548 x_handle_tool_bar_click (f
, button_event
)
7550 EventRecord
*button_event
;
7552 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7553 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7554 int hpos
, vpos
, prop_idx
;
7555 struct glyph
*glyph
;
7556 Lisp_Object enabled_p
;
7557 int x
= button_event
->where
.h
;
7558 int y
= button_event
->where
.v
;
7560 /* If not on the highlighted tool-bar item, return. */
7561 frame_to_window_pixel_xy (w
, &x
, &y
);
7562 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7565 /* If item is disabled, do nothing. */
7566 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7567 if (NILP (enabled_p
))
7570 if (button_event
->what
== mouseDown
)
7572 /* Show item in pressed state. */
7573 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7574 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7575 last_tool_bar_item
= prop_idx
;
7579 Lisp_Object key
, frame
;
7580 struct input_event event
;
7582 /* Show item in released state. */
7583 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7584 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7586 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7588 XSETFRAME (frame
, f
);
7589 event
.kind
= TOOL_BAR_EVENT
;
7590 event
.frame_or_window
= frame
;
7592 kbd_buffer_store_event (&event
);
7594 event
.kind
= TOOL_BAR_EVENT
;
7595 event
.frame_or_window
= frame
;
7597 event
.modifiers
= x_mac_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7598 button_event
->modifiers
);
7599 kbd_buffer_store_event (&event
);
7600 last_tool_bar_item
= -1;
7605 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7606 tool-bar window-relative coordinates X/Y. Called from
7607 note_mouse_highlight. */
7610 note_tool_bar_highlight (f
, x
, y
)
7614 Lisp_Object window
= f
->tool_bar_window
;
7615 struct window
*w
= XWINDOW (window
);
7616 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7618 struct glyph
*glyph
;
7619 struct glyph_row
*row
;
7621 Lisp_Object enabled_p
;
7623 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7624 int mouse_down_p
, rc
;
7626 /* Function note_mouse_highlight is called with negative x(y
7627 values when mouse moves outside of the frame. */
7628 if (x
<= 0 || y
<= 0)
7630 clear_mouse_face (dpyinfo
);
7634 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7637 /* Not on tool-bar item. */
7638 clear_mouse_face (dpyinfo
);
7642 /* On same tool-bar item as before. */
7645 clear_mouse_face (dpyinfo
);
7647 /* Mouse is down, but on different tool-bar item? */
7648 mouse_down_p
= (dpyinfo
->grabbed
7649 && f
== last_mouse_frame
7650 && FRAME_LIVE_P (f
));
7652 && last_tool_bar_item
!= prop_idx
)
7655 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7656 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7658 /* If tool-bar item is not enabled, don't highlight it. */
7659 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7660 if (!NILP (enabled_p
))
7662 /* Compute the x-position of the glyph. In front and past the
7663 image is a space. We include this is the highlighted area. */
7664 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7665 for (i
= x
= 0; i
< hpos
; ++i
)
7666 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7668 /* Record this as the current active region. */
7669 dpyinfo
->mouse_face_beg_col
= hpos
;
7670 dpyinfo
->mouse_face_beg_row
= vpos
;
7671 dpyinfo
->mouse_face_beg_x
= x
;
7672 dpyinfo
->mouse_face_beg_y
= row
->y
;
7673 dpyinfo
->mouse_face_past_end
= 0;
7675 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7676 dpyinfo
->mouse_face_end_row
= vpos
;
7677 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7678 dpyinfo
->mouse_face_end_y
= row
->y
;
7679 dpyinfo
->mouse_face_window
= window
;
7680 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7682 /* Display it as active. */
7683 show_mouse_face (dpyinfo
, draw
);
7684 dpyinfo
->mouse_face_image_state
= draw
;
7689 /* Set help_echo to a help string.to display for this tool-bar item.
7690 XTread_socket does the rest. */
7691 help_echo_object
= help_echo_window
= Qnil
;
7693 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7694 if (NILP (help_echo
))
7695 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7700 /* Find the glyph matrix position of buffer position CHARPOS in window
7701 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7702 current glyphs must be up to date. If CHARPOS is above window
7703 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7704 of last line in W. In the row containing CHARPOS, stop before glyphs
7705 having STOP as object. */
7707 #if 0 /* This is a version of fast_find_position that's more correct
7708 in the presence of hscrolling, for example. I didn't install
7709 it right away because the problem fixed is minor, it failed
7710 in 20.x as well, and I think it's too risky to install
7711 so near the release of 21.1. 2001-09-25 gerd. */
7714 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7717 int *hpos
, *vpos
, *x
, *y
;
7720 struct glyph_row
*row
, *first
;
7721 struct glyph
*glyph
, *end
;
7722 int i
, past_end
= 0;
7724 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7725 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7728 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7730 *x
= *y
= *hpos
= *vpos
= 0;
7735 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7742 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7744 glyph
= row
->glyphs
[TEXT_AREA
];
7745 end
= glyph
+ row
->used
[TEXT_AREA
];
7747 /* Skip over glyphs not having an object at the start of the row.
7748 These are special glyphs like truncation marks on terminal
7750 if (row
->displays_text_p
)
7752 && INTEGERP (glyph
->object
)
7753 && !EQ (stop
, glyph
->object
)
7754 && glyph
->charpos
< 0)
7756 *x
+= glyph
->pixel_width
;
7761 && !INTEGERP (glyph
->object
)
7762 && !EQ (stop
, glyph
->object
)
7763 && (!BUFFERP (glyph
->object
)
7764 || glyph
->charpos
< charpos
))
7766 *x
+= glyph
->pixel_width
;
7770 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7777 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7780 int *hpos
, *vpos
, *x
, *y
;
7785 int maybe_next_line_p
= 0;
7786 int line_start_position
;
7787 int yb
= window_text_bottom_y (w
);
7788 struct glyph_row
*row
, *best_row
;
7789 int row_vpos
, best_row_vpos
;
7792 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7793 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7797 if (row
->used
[TEXT_AREA
])
7798 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7800 line_start_position
= 0;
7802 if (line_start_position
> pos
)
7804 /* If the position sought is the end of the buffer,
7805 don't include the blank lines at the bottom of the window. */
7806 else if (line_start_position
== pos
7807 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7809 maybe_next_line_p
= 1;
7812 else if (line_start_position
> 0)
7815 best_row_vpos
= row_vpos
;
7818 if (row
->y
+ row
->height
>= yb
)
7825 /* Find the right column within BEST_ROW. */
7827 current_x
= best_row
->x
;
7828 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7830 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7831 int charpos
= glyph
->charpos
;
7833 if (BUFFERP (glyph
->object
))
7838 *vpos
= best_row_vpos
;
7843 else if (charpos
> pos
)
7846 else if (EQ (glyph
->object
, stop
))
7851 current_x
+= glyph
->pixel_width
;
7854 /* If we're looking for the end of the buffer,
7855 and we didn't find it in the line we scanned,
7856 use the start of the following line. */
7857 if (maybe_next_line_p
)
7862 current_x
= best_row
->x
;
7865 *vpos
= best_row_vpos
;
7866 *hpos
= lastcol
+ 1;
7875 /* Find the position of the glyph for position POS in OBJECT in
7876 window W's current matrix, and return in *X/*Y the pixel
7877 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7879 RIGHT_P non-zero means return the position of the right edge of the
7880 glyph, RIGHT_P zero means return the left edge position.
7882 If no glyph for POS exists in the matrix, return the position of
7883 the glyph with the next smaller position that is in the matrix, if
7884 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7885 exists in the matrix, return the position of the glyph with the
7886 next larger position in OBJECT.
7888 Value is non-zero if a glyph was found. */
7891 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7895 int *hpos
, *vpos
, *x
, *y
;
7898 int yb
= window_text_bottom_y (w
);
7899 struct glyph_row
*r
;
7900 struct glyph
*best_glyph
= NULL
;
7901 struct glyph_row
*best_row
= NULL
;
7904 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7905 r
->enabled_p
&& r
->y
< yb
;
7908 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7909 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7912 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7913 if (EQ (g
->object
, object
))
7915 if (g
->charpos
== pos
)
7922 else if (best_glyph
== NULL
7923 || ((abs (g
->charpos
- pos
)
7924 < abs (best_glyph
->charpos
- pos
))
7927 : g
->charpos
> pos
)))
7941 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7945 *x
+= best_glyph
->pixel_width
;
7950 *vpos
= best_row
- w
->current_matrix
->rows
;
7953 return best_glyph
!= NULL
;
7957 /* Display the active region described by mouse_face_*
7958 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7961 show_mouse_face (dpyinfo
, draw
)
7962 struct mac_display_info
*dpyinfo
;
7963 enum draw_glyphs_face draw
;
7965 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7966 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7968 if (/* If window is in the process of being destroyed, don't bother
7970 w
->current_matrix
!= NULL
7971 /* Don't update mouse highlight if hidden */
7972 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
7973 /* Recognize when we are called to operate on rows that don't exist
7974 anymore. This can happen when a window is split. */
7975 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7977 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7978 struct glyph_row
*row
, *first
, *last
;
7980 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7981 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7983 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7985 int start_hpos
, end_hpos
, start_x
;
7987 /* For all but the first row, the highlight starts at column 0. */
7990 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7991 start_x
= dpyinfo
->mouse_face_beg_x
;
8000 end_hpos
= dpyinfo
->mouse_face_end_col
;
8002 end_hpos
= row
->used
[TEXT_AREA
];
8004 if (end_hpos
> start_hpos
)
8006 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
8007 start_hpos
, end_hpos
, draw
, 0);
8010 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
8014 /* When we've written over the cursor, arrange for it to
8015 be displayed again. */
8016 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
8017 x_display_cursor (w
, 1,
8018 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
8019 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
8022 #if 0 /* MAC_TODO: mouse cursor */
8023 /* Change the mouse cursor. */
8024 if (draw
== DRAW_NORMAL_TEXT
)
8025 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8026 f
->output_data
.x
->text_cursor
);
8027 else if (draw
== DRAW_MOUSE_FACE
)
8028 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8029 f
->output_data
.x
->cross_cursor
);
8031 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8032 f
->output_data
.x
->nontext_cursor
);
8036 /* Clear out the mouse-highlighted active region.
8037 Redraw it un-highlighted first. */
8040 clear_mouse_face (dpyinfo
)
8041 struct mac_display_info
*dpyinfo
;
8045 if (! NILP (dpyinfo
->mouse_face_window
))
8047 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
8051 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8052 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8053 dpyinfo
->mouse_face_window
= Qnil
;
8054 dpyinfo
->mouse_face_overlay
= Qnil
;
8059 /* Clear any mouse-face on window W. This function is part of the
8060 redisplay interface, and is called from try_window_id and similar
8061 functions to ensure the mouse-highlight is off. */
8064 x_clear_mouse_face (w
)
8067 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
8071 XSETWINDOW (window
, w
);
8072 if (EQ (window
, dpyinfo
->mouse_face_window
))
8073 clear_mouse_face (dpyinfo
);
8078 /* Just discard the mouse face information for frame F, if any.
8079 This is used when the size of F is changed. */
8082 cancel_mouse_face (f
)
8086 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8088 window
= dpyinfo
->mouse_face_window
;
8089 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
8091 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8092 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8093 dpyinfo
->mouse_face_window
= Qnil
;
8097 static struct scroll_bar
*x_window_to_scroll_bar ();
8098 static void x_scroll_bar_report_motion ();
8099 static void x_check_fullscreen
P_ ((struct frame
*));
8100 static void x_check_fullscreen_move
P_ ((struct frame
*));
8101 static int glyph_rect
P_ ((struct frame
*f
, int, int, Rect
*));
8104 /* Try to determine frame pixel position and size of the glyph under
8105 frame pixel coordinates X/Y on frame F . Return the position and
8106 size in *RECT. Value is non-zero if we could compute these
8110 glyph_rect (f
, x
, y
, rect
)
8118 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
8121 struct window
*w
= XWINDOW (window
);
8122 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8123 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
8125 frame_to_window_pixel_xy (w
, &x
, &y
);
8127 for (; r
< end
&& r
->enabled_p
; ++r
)
8128 if (r
->y
<= y
&& r
->y
+ r
->height
> y
)
8130 /* Found the row at y. */
8131 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
8132 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
8135 rect
->top
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
8136 rect
->bottom
= rect
->top
+ r
->height
;
8140 /* x is to the left of the first glyph in the row. */
8141 rect
->left
= XINT (w
->left
);
8142 rect
->right
= WINDOW_TO_FRAME_PIXEL_X (w
, r
->x
);
8146 for (gx
= r
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
8147 if (gx
<= x
&& gx
+ g
->pixel_width
> x
)
8149 /* x is on a glyph. */
8150 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
8151 rect
->right
= rect
->left
+ g
->pixel_width
;
8155 /* x is to the right of the last glyph in the row. */
8156 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
8157 rect
->right
= XINT (w
->left
) + XINT (w
->width
);
8162 /* The y is not on any row. */
8166 /* Record the position of the mouse in last_mouse_glyph. */
8168 remember_mouse_glyph (f1
, gx
, gy
)
8172 if (!glyph_rect (f1
, gx
, gy
, &last_mouse_glyph
))
8174 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8175 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8177 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8178 round down even for negative values. */
8184 /* This was the original code from XTmouse_position, but it seems
8185 to give the position of the glyph diagonally next to the one
8186 the mouse is over. */
8187 gx
= (gx
+ width
- 1) / width
* width
;
8188 gy
= (gy
+ height
- 1) / height
* height
;
8190 gx
= gx
/ width
* width
;
8191 gy
= gy
/ height
* height
;
8194 last_mouse_glyph
.left
= gx
;
8195 last_mouse_glyph
.top
= gy
;
8196 last_mouse_glyph
.right
= gx
+ width
;
8197 last_mouse_glyph
.bottom
= gy
+ height
;
8201 /* Return the current position of the mouse.
8202 *fp should be a frame which indicates which display to ask about.
8204 If the mouse movement started in a scroll bar, set *fp, *bar_window,
8205 and *part to the frame, window, and scroll bar part that the mouse
8206 is over. Set *x and *y to the portion and whole of the mouse's
8207 position on the scroll bar.
8209 If the mouse movement started elsewhere, set *fp to the frame the
8210 mouse is on, *bar_window to nil, and *x and *y to the character cell
8213 Set *time to the server time-stamp for the time at which the mouse
8214 was at this position.
8216 Don't store anything if we don't have a valid set of values to report.
8218 This clears the mouse_moved flag, so we can wait for the next mouse
8222 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
8225 Lisp_Object
*bar_window
;
8226 enum scroll_bar_part
*part
;
8228 unsigned long *time
;
8231 int ignore1
, ignore2
;
8232 WindowPtr wp
= FrontWindow ();
8233 struct frame
*f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
8234 Lisp_Object frame
, tail
;
8238 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
8239 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
8242 /* Clear the mouse-moved flag for every frame on this display. */
8243 FOR_EACH_FRAME (tail
, frame
)
8244 XFRAME (frame
)->mouse_moved
= 0;
8246 last_mouse_scroll_bar
= Qnil
;
8248 #if TARGET_API_MAC_CARBON
8249 SetPort (GetWindowPort (wp
));
8254 GetMouse (&mouse_pos
);
8256 pixel_to_glyph_coords (f
, mouse_pos
.h
, mouse_pos
.v
, &ignore1
, &ignore2
,
8257 &last_mouse_glyph
, insist
);
8260 *part
= scroll_bar_handle
;
8262 XSETINT (*x
, mouse_pos
.h
);
8263 XSETINT (*y
, mouse_pos
.v
);
8264 *time
= last_mouse_movement_time
;
8271 /************************************************************************
8272 Scroll bars, general
8273 ************************************************************************/
8275 /* Create a scroll bar and return the scroll bar vector for it. W is
8276 the Emacs window on which to create the scroll bar. TOP, LEFT,
8277 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
8280 static struct scroll_bar
*
8281 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
8283 int top
, left
, width
, height
, disp_top
, disp_height
;
8285 struct frame
*f
= XFRAME (w
->frame
);
8286 struct scroll_bar
*bar
8287 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8295 r
.right
= left
+ width
;
8296 r
.bottom
= disp_top
+ disp_height
;
8298 #ifdef TARGET_API_MAC_CARBON
8299 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", 1, 0, 0, 0,
8300 kControlScrollBarProc
, 0L);
8302 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", 1, 0, 0, 0, scrollBarProc
,
8305 SET_SCROLL_BAR_CONTROL_HANDLE (bar
, ch
);
8306 SetControlReference (ch
, (long) bar
);
8308 XSETWINDOW (bar
->window
, w
);
8309 XSETINT (bar
->top
, top
);
8310 XSETINT (bar
->left
, left
);
8311 XSETINT (bar
->width
, width
);
8312 XSETINT (bar
->height
, height
);
8313 XSETINT (bar
->start
, 0);
8314 XSETINT (bar
->end
, 0);
8315 bar
->dragging
= Qnil
;
8317 /* Add bar to its frame's list of scroll bars. */
8318 bar
->next
= FRAME_SCROLL_BARS (f
);
8320 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8321 if (!NILP (bar
->next
))
8322 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8329 /* Draw BAR's handle in the proper position.
8331 If the handle is already drawn from START to END, don't bother
8332 redrawing it, unless REBUILD is non-zero; in that case, always
8333 redraw it. (REBUILD is handy for drawing the handle after expose
8336 Normally, we want to constrain the start and end of the handle to
8337 fit inside its rectangle, but if the user is dragging the scroll
8338 bar handle, we want to let them drag it down all the way, so that
8339 the bar's top is as far down as it goes; otherwise, there's no way
8340 to move to the very end of the buffer. */
8343 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8344 struct scroll_bar
*bar
;
8348 int dragging
= ! NILP (bar
->dragging
);
8349 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
8350 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8351 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8352 int length
= end
- start
;
8354 /* If the display is already accurate, do nothing. */
8356 && start
== XINT (bar
->start
)
8357 && end
== XINT (bar
->end
))
8362 /* Make sure the values are reasonable, and try to preserve the
8363 distance between start and end. */
8366 else if (start
> top_range
)
8368 end
= start
+ length
;
8372 else if (end
> top_range
&& ! dragging
)
8375 /* Store the adjusted setting in the scroll bar. */
8376 XSETINT (bar
->start
, start
);
8377 XSETINT (bar
->end
, end
);
8379 /* Clip the end position, just for display. */
8380 if (end
> top_range
)
8383 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
8384 top positions, to make sure the handle is always at least that
8385 many pixels tall. */
8386 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8388 SetControlMinimum (ch
, 0);
8389 /* Don't inadvertently activate deactivated scroll bars */
8390 if (GetControlMaximum (ch
) != -1)
8391 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
8393 SetControlValue (ch
, start
);
8394 #if TARGET_API_MAC_CARBON
8395 SetControlViewSize (ch
, end
- start
);
8402 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8406 x_scroll_bar_remove (bar
)
8407 struct scroll_bar
*bar
;
8409 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8413 /* Destroy the Mac scroll bar control */
8414 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar
));
8416 /* Disassociate this scroll bar from its window. */
8417 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8422 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8423 that we are displaying PORTION characters out of a total of WHOLE
8424 characters, starting at POSITION. If WINDOW has no scroll bar,
8427 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8429 int portion
, whole
, position
;
8431 struct frame
*f
= XFRAME (w
->frame
);
8432 struct scroll_bar
*bar
;
8433 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
8434 int window_x
, window_y
, window_width
, window_height
;
8436 /* Get window dimensions. */
8437 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8442 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8444 height
= window_height
;
8446 /* Compute the left edge of the scroll bar area. */
8447 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8448 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8450 left
= XFASTINT (w
->left
);
8451 left
*= CANON_X_UNIT (f
);
8452 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8454 /* Compute the width of the scroll bar which might be less than
8455 the width of the area reserved for the scroll bar. */
8456 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8457 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8461 /* Compute the left edge of the scroll bar. */
8462 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8463 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8465 sb_left
= left
+ (width
- sb_width
) / 2;
8467 /* Adjustments according to Inside Macintosh to make it look nice */
8469 disp_height
= height
;
8475 else if (disp_top
== PIXEL_HEIGHT (f
) - 16)
8481 if (sb_left
+ sb_width
== PIXEL_WIDTH (f
))
8484 /* Does the scroll bar exist yet? */
8485 if (NILP (w
->vertical_scroll_bar
))
8488 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
8489 left
, top
, width
, height
, 0);
8491 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
8493 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8497 /* It may just need to be moved and resized. */
8500 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8501 ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
8505 /* If already correctly positioned, do nothing. */
8506 if (XINT (bar
->left
) == sb_left
8507 && XINT (bar
->top
) == top
8508 && XINT (bar
->width
) == sb_width
8509 && XINT (bar
->height
) == height
)
8513 /* Clear areas not covered by the scroll bar because it's not as
8514 wide as the area reserved for it . This makes sure a
8515 previous mode line display is cleared after C-x 2 C-x 1, for
8517 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8518 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
8519 left
, top
, area_width
, height
, 0);
8522 if (sb_left
+ sb_width
>= PIXEL_WIDTH (f
))
8523 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
8524 sb_left
- 1, top
, 1, height
, 0);
8528 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
8529 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8533 /* Remember new settings. */
8534 XSETINT (bar
->left
, sb_left
);
8535 XSETINT (bar
->top
, top
);
8536 XSETINT (bar
->width
, sb_width
);
8537 XSETINT (bar
->height
, height
);
8543 /* Set the scroll bar's current state, unless we're currently being
8545 if (NILP (bar
->dragging
))
8547 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8550 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8553 int start
= ((double) position
* top_range
) / whole
;
8554 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8555 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8561 /* The following three hooks are used when we're doing a thorough
8562 redisplay of the frame. We don't explicitly know which scroll bars
8563 are going to be deleted, because keeping track of when windows go
8564 away is a real pain - "Can you say set-window-configuration, boys
8565 and girls?" Instead, we just assert at the beginning of redisplay
8566 that *all* scroll bars are to be removed, and then save a scroll bar
8567 from the fiery pit when we actually redisplay its window. */
8569 /* Arrange for all scroll bars on FRAME to be removed at the next call
8570 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8571 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8574 XTcondemn_scroll_bars (frame
)
8577 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8578 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8581 bar
= FRAME_SCROLL_BARS (frame
);
8582 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8583 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8584 XSCROLL_BAR (bar
)->prev
= Qnil
;
8585 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8586 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8587 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8592 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8593 Note that WINDOW isn't necessarily condemned at all. */
8596 XTredeem_scroll_bar (window
)
8597 struct window
*window
;
8599 struct scroll_bar
*bar
;
8601 /* We can't redeem this window's scroll bar if it doesn't have one. */
8602 if (NILP (window
->vertical_scroll_bar
))
8605 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8607 /* Unlink it from the condemned list. */
8609 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8611 if (NILP (bar
->prev
))
8613 /* If the prev pointer is nil, it must be the first in one of
8615 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8616 /* It's not condemned. Everything's fine. */
8618 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8619 window
->vertical_scroll_bar
))
8620 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8622 /* If its prev pointer is nil, it must be at the front of
8623 one or the other! */
8627 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8629 if (! NILP (bar
->next
))
8630 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8632 bar
->next
= FRAME_SCROLL_BARS (f
);
8634 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8635 if (! NILP (bar
->next
))
8636 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8640 /* Remove all scroll bars on FRAME that haven't been saved since the
8641 last call to `*condemn_scroll_bars_hook'. */
8644 XTjudge_scroll_bars (f
)
8647 Lisp_Object bar
, next
;
8649 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8651 /* Clear out the condemned list now so we won't try to process any
8652 more events on the hapless scroll bars. */
8653 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8655 for (; ! NILP (bar
); bar
= next
)
8657 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8659 x_scroll_bar_remove (b
);
8662 b
->next
= b
->prev
= Qnil
;
8665 /* Now there should be no references to the condemned scroll bars,
8666 and they should get garbage-collected. */
8671 activate_scroll_bars (frame
)
8677 bar
= FRAME_SCROLL_BARS (frame
);
8678 while (! NILP (bar
))
8680 ch
= SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar
));
8681 #ifdef TARGET_API_MAC_CARBON
8682 ActivateControl (ch
);
8684 SetControlMaximum (ch
,
8685 VERTICAL_SCROLL_BAR_TOP_RANGE (frame
,
8686 XINT (XSCROLL_BAR (bar
)
8689 bar
= XSCROLL_BAR (bar
)->next
;
8695 deactivate_scroll_bars (frame
)
8701 bar
= FRAME_SCROLL_BARS (frame
);
8702 while (! NILP (bar
))
8704 ch
= SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar
));
8705 #ifdef TARGET_API_MAC_CARBON
8706 DeactivateControl (ch
);
8708 SetControlMaximum (ch
, XINT (-1));
8710 bar
= XSCROLL_BAR (bar
)->next
;
8714 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8715 is set to something other than no_event, it is enqueued.
8717 This may be called from a signal handler, so we have to ignore GC
8721 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
8722 struct scroll_bar
*bar
;
8725 struct input_event
*bufp
;
8727 if (! GC_WINDOWP (bar
->window
))
8730 bufp
->kind
= scroll_bar_click
;
8731 bufp
->frame_or_window
= bar
->window
;
8734 bar
->dragging
= Qnil
;
8738 case kControlUpButtonPart
:
8739 bufp
->part
= scroll_bar_up_arrow
;
8741 case kControlDownButtonPart
:
8742 bufp
->part
= scroll_bar_down_arrow
;
8744 case kControlPageUpPart
:
8745 bufp
->part
= scroll_bar_above_handle
;
8747 case kControlPageDownPart
:
8748 bufp
->part
= scroll_bar_below_handle
;
8750 #ifdef TARGET_API_MAC_CARBON
8753 case kControlIndicatorPart
:
8755 if (er
->what
== mouseDown
)
8756 bar
->dragging
= make_number (0);
8757 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8758 bufp
->part
= scroll_bar_handle
;
8764 /* Handle some mouse motion while someone is dragging the scroll bar.
8766 This may be called from a signal handler, so we have to ignore GC
8770 x_scroll_bar_note_movement (bar
, y_pos
, t
)
8771 struct scroll_bar
*bar
;
8775 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8777 last_mouse_movement_time
= t
;
8780 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8782 /* If we're dragging the bar, display it. */
8783 if (! GC_NILP (bar
->dragging
))
8785 /* Where should the handle be now? */
8786 int new_start
= y_pos
- 24;
8788 if (new_start
!= XINT (bar
->start
))
8790 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8792 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8798 /* Return information to the user about the current position of the
8799 mouse on the scroll bar. */
8802 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8804 Lisp_Object
*bar_window
;
8805 enum scroll_bar_part
*part
;
8807 unsigned long *time
;
8809 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8810 WindowPtr wp
= FrontWindow ();
8812 struct frame
*f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
8813 int win_y
, top_range
;
8815 #if TARGET_API_MAC_CARBON
8816 SetPort (GetWindowPort (wp
));
8821 GetMouse (&mouse_pos
);
8823 win_y
= mouse_pos
.v
- XINT (bar
->top
);
8824 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8826 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8830 if (! NILP (bar
->dragging
))
8831 win_y
-= XINT (bar
->dragging
);
8835 if (win_y
> top_range
)
8839 *bar_window
= bar
->window
;
8841 if (! NILP (bar
->dragging
))
8842 *part
= scroll_bar_handle
;
8843 else if (win_y
< XINT (bar
->start
))
8844 *part
= scroll_bar_above_handle
;
8845 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8846 *part
= scroll_bar_handle
;
8848 *part
= scroll_bar_below_handle
;
8850 XSETINT (*x
, win_y
);
8851 XSETINT (*y
, top_range
);
8854 last_mouse_scroll_bar
= Qnil
;
8856 *time
= last_mouse_movement_time
;
8859 /***********************************************************************
8861 ***********************************************************************/
8863 /* Notice if the text cursor of window W has been overwritten by a
8864 drawing operation that outputs glyphs starting at START_X and
8865 ending at END_X in the line given by output_cursor.vpos.
8866 Coordinates are area-relative. END_X < 0 means all the rest
8867 of the line after START_X has been written. */
8870 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
8872 enum glyph_row_area area
;
8875 if (area
== TEXT_AREA
8876 && w
->phys_cursor_on_p
8877 && y0
<= w
->phys_cursor
.y
8878 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
8879 && x0
<= w
->phys_cursor
.x
8880 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
8881 w
->phys_cursor_on_p
= 0;
8885 /* Set clipping for output in glyph row ROW. W is the window in which
8886 we operate. GC is the graphics context to set clipping in.
8887 WHOLE_LINE_P non-zero means include the areas used for truncation
8888 mark display and alike in the clipping rectangle.
8890 ROW may be a text row or, e.g., a mode line. Text rows must be
8891 clipped to the interior of the window dedicated to text display,
8892 mode lines must be clipped to the whole window. */
8895 x_clip_to_row (w
, row
, gc
, whole_line_p
)
8897 struct glyph_row
*row
;
8901 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8903 int window_x
, window_y
, window_width
, window_height
;
8905 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8907 clip_rect
.left
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
8908 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8909 clip_rect
.top
= max (clip_rect
.top
, window_y
);
8910 clip_rect
.right
= clip_rect
.left
+ window_width
;
8911 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
8913 /* If clipping to the whole line, including trunc marks, extend
8914 the rectangle to the left and increase its width. */
8917 clip_rect
.left
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
8918 clip_rect
.right
+= FRAME_X_FRINGE_WIDTH (f
);
8921 mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), &clip_rect
);
8925 /* Draw a hollow box cursor on window W in glyph row ROW. */
8928 x_draw_hollow_cursor (w
, row
)
8930 struct glyph_row
*row
;
8932 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8933 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8934 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
8937 struct glyph
*cursor_glyph
;
8940 /* Compute frame-relative coordinates from window-relative
8942 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8943 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
8944 + row
->ascent
- w
->phys_cursor_ascent
);
8945 h
= row
->height
- 1;
8947 /* Get the glyph the cursor is on. If we can't tell because
8948 the current matrix is invalid or such, give up. */
8949 cursor_glyph
= get_phys_cursor_glyph (w
);
8950 if (cursor_glyph
== NULL
)
8953 /* Compute the width of the rectangle to draw. If on a stretch
8954 glyph, and `x-stretch-block-cursor' is nil, don't draw a
8955 rectangle as wide as the glyph, but use a canonical character
8957 wd
= cursor_glyph
->pixel_width
- 1;
8958 if (cursor_glyph
->type
== STRETCH_GLYPH
8959 && !x_stretch_cursor_p
)
8960 wd
= min (CANON_X_UNIT (f
), wd
);
8962 /* The foreground of cursor_gc is typically the same as the normal
8963 background color, which can cause the cursor box to be invisible. */
8964 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
8965 if (dpyinfo
->scratch_cursor_gc
)
8966 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
8968 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
8969 GCForeground
, &xgcv
);
8970 gc
= dpyinfo
->scratch_cursor_gc
;
8972 /* Set clipping, draw the rectangle, and reset clipping again. */
8973 x_clip_to_row (w
, row
, gc
, 0);
8974 mac_draw_rectangle (dpy
, FRAME_MAC_WINDOW (f
), gc
, x
, y
, wd
, h
);
8975 mac_reset_clipping (dpy
, FRAME_MAC_WINDOW (f
));
8979 /* Draw a bar cursor on window W in glyph row ROW.
8981 Implementation note: One would like to draw a bar cursor with an
8982 angle equal to the one given by the font property XA_ITALIC_ANGLE.
8983 Unfortunately, I didn't find a font yet that has this property set.
8987 x_draw_bar_cursor (w
, row
, width
)
8989 struct glyph_row
*row
;
8992 /* If cursor hpos is out of bounds, don't draw garbage. This can
8993 happen in mini-buffer windows when switching between echo area
8994 glyphs and mini-buffer. */
8995 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
8997 struct frame
*f
= XFRAME (w
->frame
);
8998 struct glyph
*cursor_glyph
;
9006 cursor_glyph
= get_phys_cursor_glyph (w
);
9007 if (cursor_glyph
== NULL
)
9010 xgcv
.background
= f
->output_data
.mac
->cursor_pixel
;
9011 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
9012 mask
= GCForeground
| GCBackground
;
9013 dpy
= FRAME_MAC_DISPLAY (f
);
9014 window
= FRAME_MAC_WINDOW (f
);
9015 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
9018 XChangeGC (dpy
, gc
, mask
, &xgcv
);
9021 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
9022 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
9026 width
= f
->output_data
.mac
->cursor_width
;
9028 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9029 x_clip_to_row (w
, row
, gc
, 0);
9030 XFillRectangle (dpy
, window
, gc
,
9032 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9033 min (cursor_glyph
->pixel_width
, width
),
9035 mac_reset_clipping (dpy
, FRAME_MAC_WINDOW (f
));
9040 /* Clear the cursor of window W to background color, and mark the
9041 cursor as not shown. This is used when the text where the cursor
9042 is is about to be rewritten. */
9048 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9049 x_update_window_cursor (w
, 0);
9053 /* Draw the cursor glyph of window W in glyph row ROW. See the
9054 comment of x_draw_glyphs for the meaning of HL. */
9057 x_draw_phys_cursor_glyph (w
, row
, hl
)
9059 struct glyph_row
*row
;
9060 enum draw_glyphs_face hl
;
9062 /* If cursor hpos is out of bounds, don't draw garbage. This can
9063 happen in mini-buffer windows when switching between echo area
9064 glyphs and mini-buffer. */
9065 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9067 int on_p
= w
->phys_cursor_on_p
;
9068 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9069 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9071 w
->phys_cursor_on_p
= on_p
;
9073 /* When we erase the cursor, and ROW is overlapped by other
9074 rows, make sure that these overlapping parts of other rows
9076 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9078 if (row
> w
->current_matrix
->rows
9079 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9080 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9082 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9083 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9084 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9090 /* Erase the image of a cursor of window W from the screen. */
9093 x_erase_phys_cursor (w
)
9096 struct frame
*f
= XFRAME (w
->frame
);
9097 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9098 int hpos
= w
->phys_cursor
.hpos
;
9099 int vpos
= w
->phys_cursor
.vpos
;
9100 int mouse_face_here_p
= 0;
9101 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9102 struct glyph_row
*cursor_row
;
9103 struct glyph
*cursor_glyph
;
9104 enum draw_glyphs_face hl
;
9106 /* No cursor displayed or row invalidated => nothing to do on the
9108 if (w
->phys_cursor_type
== NO_CURSOR
)
9109 goto mark_cursor_off
;
9111 /* VPOS >= active_glyphs->nrows means that window has been resized.
9112 Don't bother to erase the cursor. */
9113 if (vpos
>= active_glyphs
->nrows
)
9114 goto mark_cursor_off
;
9116 /* If row containing cursor is marked invalid, there is nothing we
9118 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9119 if (!cursor_row
->enabled_p
)
9120 goto mark_cursor_off
;
9122 /* If row is completely invisible, don't attempt to delete a cursor which
9123 isn't there. This may happen if cursor is at top of window, and
9124 we switch to a buffer with a header line in that window. */
9125 if (cursor_row
->visible_height
<= 0)
9126 goto mark_cursor_off
;
9128 /* This can happen when the new row is shorter than the old one.
9129 In this case, either x_draw_glyphs or clear_end_of_line
9130 should have cleared the cursor. Note that we wouldn't be
9131 able to erase the cursor in this case because we don't have a
9132 cursor glyph at hand. */
9133 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9134 goto mark_cursor_off
;
9136 /* If the cursor is in the mouse face area, redisplay that when
9137 we clear the cursor. */
9138 if (! NILP (dpyinfo
->mouse_face_window
)
9139 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9140 && (vpos
> dpyinfo
->mouse_face_beg_row
9141 || (vpos
== dpyinfo
->mouse_face_beg_row
9142 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9143 && (vpos
< dpyinfo
->mouse_face_end_row
9144 || (vpos
== dpyinfo
->mouse_face_end_row
9145 && hpos
< dpyinfo
->mouse_face_end_col
))
9146 /* Don't redraw the cursor's spot in mouse face if it is at the
9147 end of a line (on a newline). The cursor appears there, but
9148 mouse highlighting does not. */
9149 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9150 mouse_face_here_p
= 1;
9152 /* Maybe clear the display under the cursor. */
9153 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9156 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9158 cursor_glyph
= get_phys_cursor_glyph (w
);
9159 if (cursor_glyph
== NULL
)
9160 goto mark_cursor_off
;
9162 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
9164 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
9166 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9168 cursor_glyph
->pixel_width
,
9169 cursor_row
->visible_height
,
9173 /* Erase the cursor by redrawing the character underneath it. */
9174 if (mouse_face_here_p
)
9175 hl
= DRAW_MOUSE_FACE
;
9177 hl
= DRAW_NORMAL_TEXT
;
9178 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9181 w
->phys_cursor_on_p
= 0;
9182 w
->phys_cursor_type
= NO_CURSOR
;
9186 /* Non-zero if physical cursor of window W is within mouse face. */
9189 cursor_in_mouse_face_p (w
)
9192 struct mac_display_info
*dpyinfo
9193 = FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
9194 int in_mouse_face
= 0;
9196 if (WINDOWP (dpyinfo
->mouse_face_window
)
9197 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
9199 int hpos
= w
->phys_cursor
.hpos
;
9200 int vpos
= w
->phys_cursor
.vpos
;
9202 if (vpos
>= dpyinfo
->mouse_face_beg_row
9203 && vpos
<= dpyinfo
->mouse_face_end_row
9204 && (vpos
> dpyinfo
->mouse_face_beg_row
9205 || hpos
>= dpyinfo
->mouse_face_beg_col
)
9206 && (vpos
< dpyinfo
->mouse_face_end_row
9207 || hpos
< dpyinfo
->mouse_face_end_col
9208 || dpyinfo
->mouse_face_past_end
))
9212 return in_mouse_face
;
9216 /* Display or clear cursor of window W. If ON is zero, clear the
9217 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9218 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9221 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9223 int on
, hpos
, vpos
, x
, y
;
9225 struct frame
*f
= XFRAME (w
->frame
);
9226 int new_cursor_type
;
9227 int new_cursor_width
;
9228 struct glyph_matrix
*current_glyphs
;
9229 struct glyph_row
*glyph_row
;
9230 struct glyph
*glyph
;
9231 int cursor_non_selected
;
9232 int active_cursor
= 1;
9234 /* This is pointless on invisible frames, and dangerous on garbaged
9235 windows and frames; in the latter case, the frame or window may
9236 be in the midst of changing its size, and x and y may be off the
9238 if (! FRAME_VISIBLE_P (f
)
9239 || FRAME_GARBAGED_P (f
)
9240 || vpos
>= w
->current_matrix
->nrows
9241 || hpos
>= w
->current_matrix
->matrix_w
)
9244 /* If cursor is off and we want it off, return quickly. */
9245 if (!on
&& !w
->phys_cursor_on_p
)
9248 current_glyphs
= w
->current_matrix
;
9249 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9250 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9252 /* If cursor row is not enabled, we don't really know where to
9253 display the cursor. */
9254 if (!glyph_row
->enabled_p
)
9256 w
->phys_cursor_on_p
= 0;
9260 xassert (interrupt_input_blocked
);
9262 /* Set new_cursor_type to the cursor we want to be displayed. In a
9263 mini-buffer window, we want the cursor only to appear if we are
9264 reading input from this window. For the selected window, we want
9265 the cursor type given by the frame parameter. If explicitly
9266 marked off, draw no cursor. In all other cases, we want a hollow
9269 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
9271 new_cursor_width
= -1;
9272 if (cursor_in_echo_area
9273 && FRAME_HAS_MINIBUF_P (f
)
9274 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
9276 if (w
== XWINDOW (echo_area_window
))
9277 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9280 if (cursor_non_selected
)
9281 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9283 new_cursor_type
= NO_CURSOR
;
9289 if (f
!= FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
9290 || w
!= XWINDOW (f
->selected_window
))
9294 if (MINI_WINDOW_P (w
)
9295 || !cursor_non_selected
9296 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
9297 new_cursor_type
= NO_CURSOR
;
9299 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9303 struct buffer
*b
= XBUFFER (w
->buffer
);
9305 if (EQ (b
->cursor_type
, Qt
))
9306 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9308 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
9310 if (w
->cursor_off_p
)
9312 if (new_cursor_type
== FILLED_BOX_CURSOR
)
9313 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9314 else if (new_cursor_type
== BAR_CURSOR
&& new_cursor_width
> 1)
9315 new_cursor_width
= 1;
9317 new_cursor_type
= NO_CURSOR
;
9322 /* If cursor is currently being shown and we don't want it to be or
9323 it is in the wrong place, or the cursor type is not what we want,
9325 if (w
->phys_cursor_on_p
9327 || w
->phys_cursor
.x
!= x
9328 || w
->phys_cursor
.y
!= y
9329 || new_cursor_type
!= w
->phys_cursor_type
9330 || (new_cursor_type
== BAR_CURSOR
9331 && new_cursor_width
!= w
->phys_cursor_width
)))
9332 x_erase_phys_cursor (w
);
9334 /* If the cursor is now invisible and we want it to be visible,
9336 if (on
&& !w
->phys_cursor_on_p
)
9338 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9339 w
->phys_cursor_height
= glyph_row
->height
;
9341 /* Set phys_cursor_.* before x_draw_.* is called because some
9342 of them may need the information. */
9343 w
->phys_cursor
.x
= x
;
9344 w
->phys_cursor
.y
= glyph_row
->y
;
9345 w
->phys_cursor
.hpos
= hpos
;
9346 w
->phys_cursor
.vpos
= vpos
;
9347 w
->phys_cursor_type
= new_cursor_type
;
9348 w
->phys_cursor_width
= new_cursor_width
;
9349 w
->phys_cursor_on_p
= 1;
9351 switch (new_cursor_type
)
9353 case HOLLOW_BOX_CURSOR
:
9354 x_draw_hollow_cursor (w
, glyph_row
);
9357 case FILLED_BOX_CURSOR
:
9358 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9362 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
9375 /* Display the cursor on window W, or clear it. X and Y are window
9376 relative pixel coordinates. HPOS and VPOS are glyph matrix
9377 positions. If W is not the selected window, display a hollow
9378 cursor. ON non-zero means display the cursor at X, Y which
9379 correspond to HPOS, VPOS, otherwise it is cleared. */
9382 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9384 int on
, hpos
, vpos
, x
, y
;
9387 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9392 /* Display the cursor on window W, or clear it, according to ON_P.
9393 Don't change the cursor's position. */
9396 x_update_cursor (f
, on_p
)
9400 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9404 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9405 in the window tree rooted at W. */
9408 x_update_cursor_in_window_tree (w
, on_p
)
9414 if (!NILP (w
->hchild
))
9415 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9416 else if (!NILP (w
->vchild
))
9417 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9419 x_update_window_cursor (w
, on_p
);
9421 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9426 /* Switch the display of W's cursor on or off, according to the value
9430 x_update_window_cursor (w
, on
)
9434 /* Don't update cursor in windows whose frame is in the process
9435 of being deleted. */
9436 if (w
->current_matrix
)
9439 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
,
9440 w
->phys_cursor
.vpos
, w
->phys_cursor
.x
,
9451 #if 0 /* MAC_TODO: no icon support yet. */
9453 x_bitmap_icon (f
, icon
)
9459 if (FRAME_W32_WINDOW (f
) == 0)
9463 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
9464 else if (STRINGP (icon
))
9465 hicon
= LoadImage (NULL
, (LPCTSTR
) XSTRING (icon
)->data
, IMAGE_ICON
, 0, 0,
9466 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
9467 else if (SYMBOLP (icon
))
9471 if (EQ (icon
, intern ("application")))
9472 name
= (LPCTSTR
) IDI_APPLICATION
;
9473 else if (EQ (icon
, intern ("hand")))
9474 name
= (LPCTSTR
) IDI_HAND
;
9475 else if (EQ (icon
, intern ("question")))
9476 name
= (LPCTSTR
) IDI_QUESTION
;
9477 else if (EQ (icon
, intern ("exclamation")))
9478 name
= (LPCTSTR
) IDI_EXCLAMATION
;
9479 else if (EQ (icon
, intern ("asterisk")))
9480 name
= (LPCTSTR
) IDI_ASTERISK
;
9481 else if (EQ (icon
, intern ("winlogo")))
9482 name
= (LPCTSTR
) IDI_WINLOGO
;
9486 hicon
= LoadIcon (NULL
, name
);
9494 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
9499 #endif /* MAC_TODO */
9501 /************************************************************************
9503 ************************************************************************/
9505 /* Display Error Handling functions not used on W32. Listing them here
9506 helps diff stay in step when comparing w32term.c with xterm.c.
9508 x_error_catcher (display, error)
9509 x_catch_errors (dpy)
9510 x_catch_errors_unwind (old_val)
9511 x_check_errors (dpy, format)
9512 x_had_errors_p (dpy)
9513 x_clear_errors (dpy)
9514 x_uncatch_errors (dpy, count)
9516 x_connection_signal (signalnum)
9517 x_connection_closed (dpy, error_message)
9518 x_error_quitter (display, error)
9519 x_error_handler (display, error)
9520 x_io_error_quitter (display)
9525 /* Changing the font of the frame. */
9527 /* Give frame F the font named FONTNAME as its default font, and
9528 return the full name of that font. FONTNAME may be a wildcard
9529 pattern; in that case, we choose some font that fits the pattern.
9530 The return value shows which font we chose. */
9533 x_new_font (f
, fontname
)
9535 register char *fontname
;
9537 struct font_info
*fontp
9538 = FS_LOAD_FONT (f
, 0, fontname
, -1);
9543 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
9544 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
9545 FRAME_FONTSET (f
) = -1;
9547 /* Compute the scroll bar width in character columns. */
9548 if (f
->scroll_bar_pixel_width
> 0)
9550 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9551 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
9555 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9556 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
9559 /* Now make the frame display the given font. */
9560 if (FRAME_MAC_WINDOW (f
) != 0)
9562 frame_update_line_height (f
);
9563 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9564 x_set_window_size (f
, 0, f
->width
, f
->height
);
9567 /* If we are setting a new frame's font for the first time,
9568 there are no faces yet, so this font's height is the line height. */
9569 f
->output_data
.mac
->line_height
= FONT_HEIGHT (FRAME_FONT (f
));
9571 return build_string (fontp
->full_name
);
9574 /* Give frame F the fontset named FONTSETNAME as its default font, and
9575 return the full name of that fontset. FONTSETNAME may be a wildcard
9576 pattern; in that case, we choose some fontset that fits the pattern.
9577 The return value shows which fontset we chose. */
9580 x_new_fontset (f
, fontsetname
)
9584 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
9590 if (FRAME_FONTSET (f
) == fontset
)
9591 /* This fontset is already set in frame F. There's nothing more
9593 return fontset_name (fontset
);
9595 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
9597 if (!STRINGP (result
))
9598 /* Can't load ASCII font. */
9601 /* Since x_new_font doesn't update any fontset information, do it now. */
9602 FRAME_FONTSET(f
) = fontset
;
9604 return build_string (fontsetname
);
9607 /* Compute actual fringe widths */
9610 x_compute_fringe_widths (f
, redraw
)
9614 int o_left
= f
->output_data
.mac
->left_fringe_width
;
9615 int o_right
= f
->output_data
.mac
->right_fringe_width
;
9616 int o_cols
= f
->output_data
.mac
->fringe_cols
;
9618 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
9619 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
9620 int left_fringe_width
, right_fringe_width
;
9622 if (!NILP (left_fringe
))
9623 left_fringe
= Fcdr (left_fringe
);
9624 if (!NILP (right_fringe
))
9625 right_fringe
= Fcdr (right_fringe
);
9627 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
9628 XINT (left_fringe
));
9629 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
9630 XINT (right_fringe
));
9632 if (left_fringe_width
|| right_fringe_width
)
9634 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
9635 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
9636 int conf_wid
= left_wid
+ right_wid
;
9637 int font_wid
= FONT_WIDTH (f
->output_data
.mac
->font
);
9638 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
9639 int real_wid
= cols
* font_wid
;
9640 if (left_wid
&& right_wid
)
9642 if (left_fringe_width
< 0)
9644 /* Left fringe width is fixed, adjust right fringe if necessary */
9645 f
->output_data
.mac
->left_fringe_width
= left_wid
;
9646 f
->output_data
.mac
->right_fringe_width
= real_wid
- left_wid
;
9648 else if (right_fringe_width
< 0)
9650 /* Right fringe width is fixed, adjust left fringe if necessary */
9651 f
->output_data
.mac
->left_fringe_width
= real_wid
- right_wid
;
9652 f
->output_data
.mac
->right_fringe_width
= right_wid
;
9656 /* Adjust both fringes with an equal amount.
9657 Note that we are doing integer arithmetic here, so don't
9658 lose a pixel if the total width is an odd number. */
9659 int fill
= real_wid
- conf_wid
;
9660 f
->output_data
.mac
->left_fringe_width
= left_wid
+ fill
/2;
9661 f
->output_data
.mac
->right_fringe_width
= right_wid
+ fill
- fill
/2;
9664 else if (left_fringe_width
)
9666 f
->output_data
.mac
->left_fringe_width
= real_wid
;
9667 f
->output_data
.mac
->right_fringe_width
= 0;
9671 f
->output_data
.mac
->left_fringe_width
= 0;
9672 f
->output_data
.mac
->right_fringe_width
= real_wid
;
9674 f
->output_data
.mac
->fringe_cols
= cols
;
9675 f
->output_data
.mac
->fringes_extra
= real_wid
;
9679 f
->output_data
.mac
->left_fringe_width
= 0;
9680 f
->output_data
.mac
->right_fringe_width
= 0;
9681 f
->output_data
.mac
->fringe_cols
= 0;
9682 f
->output_data
.mac
->fringes_extra
= 0;
9685 if (redraw
&& FRAME_VISIBLE_P (f
))
9686 if (o_left
!= f
->output_data
.mac
->left_fringe_width
||
9687 o_right
!= f
->output_data
.mac
->right_fringe_width
||
9688 o_cols
!= f
->output_data
.mac
->fringe_cols
)
9692 /***********************************************************************
9693 TODO: W32 Input Methods
9694 ***********************************************************************/
9695 /* Listing missing functions from xterm.c helps diff stay in step.
9697 xim_destroy_callback (xim, client_data, call_data)
9698 xim_open_dpy (dpyinfo, resource_name)
9700 xim_instantiate_callback (display, client_data, call_data)
9701 xim_initialize (dpyinfo, resource_name)
9702 xim_close_dpy (dpyinfo)
9707 /* Calculate the absolute position in frame F
9708 from its current recorded position values and gravity. */
9711 x_calc_absolute_position (f
)
9715 int flags
= f
->output_data
.mac
->size_hint_flags
;
9719 /* Find the position of the outside upper-left corner of
9720 the inner window, with respect to the outer window. */
9721 if (f
->output_data
.mac
->parent_desc
!= FRAME_MAC_DISPLAY_INFO (f
)->root_window
)
9724 GetPort (&savePort
);
9726 #if TARGET_API_MAC_CARBON
9727 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f
)));
9729 SetPort (FRAME_MAC_WINDOW (f
));
9732 #if TARGET_API_MAC_CARBON
9736 GetWindowPortBounds (FRAME_MAC_WINDOW (f
), &r
);
9737 SetPt(&pt
, r
.left
, r
.top
);
9739 #else /* not TARGET_API_MAC_CARBON */
9740 SetPt(&pt
, FRAME_MAC_WINDOW (f
)->portRect
.left
, FRAME_MAC_WINDOW (f
)->portRect
.top
);
9741 #endif /* not TARGET_API_MAC_CARBON */
9742 LocalToGlobal (&pt
);
9746 /* Treat negative positions as relative to the leftmost bottommost
9747 position that fits on the screen. */
9748 if (flags
& XNegative
)
9749 f
->output_data
.mac
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
9750 - 2 * f
->output_data
.mac
->border_width
- pt
.h
9752 + f
->output_data
.mac
->left_pos
);
9753 /* NTEMACS_TODO: Subtract menubar height? */
9754 if (flags
& YNegative
)
9755 f
->output_data
.mac
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
9756 - 2 * f
->output_data
.mac
->border_width
- pt
.v
9758 + f
->output_data
.mac
->top_pos
);
9759 /* The left_pos and top_pos
9760 are now relative to the top and left screen edges,
9761 so the flags should correspond. */
9762 f
->output_data
.mac
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9765 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
9766 to really change the position, and 0 when calling from
9767 x_make_frame_visible (in that case, XOFF and YOFF are the current
9768 position values). It is -1 when calling from x_set_frame_parameters,
9769 which means, do adjust for borders but don't change the gravity. */
9772 x_set_offset (f
, xoff
, yoff
, change_gravity
)
9774 register int xoff
, yoff
;
9777 int modified_top
, modified_left
;
9779 if (change_gravity
> 0)
9781 f
->output_data
.mac
->top_pos
= yoff
;
9782 f
->output_data
.mac
->left_pos
= xoff
;
9783 f
->output_data
.mac
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9785 f
->output_data
.mac
->size_hint_flags
|= XNegative
;
9787 f
->output_data
.mac
->size_hint_flags
|= YNegative
;
9788 f
->output_data
.mac
->win_gravity
= NorthWestGravity
;
9790 x_calc_absolute_position (f
);
9793 x_wm_set_size_hint (f
, (long) 0, 0);
9795 modified_left
= f
->output_data
.mac
->left_pos
;
9796 modified_top
= f
->output_data
.mac
->top_pos
;
9798 MoveWindow (f
->output_data
.mac
->mWP
, modified_left
+ 6,
9799 modified_top
+ 42, false);
9804 /* Call this to change the size of frame F's x-window.
9805 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9806 for this size change and subsequent size changes.
9807 Otherwise we leave the window gravity unchanged. */
9810 x_set_window_size (f
, change_gravity
, cols
, rows
)
9815 int pixelwidth
, pixelheight
;
9819 check_frame_size (f
, &rows
, &cols
);
9820 f
->output_data
.mac
->vertical_scroll_bar_extra
9821 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9823 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.mac
->font
)));
9825 x_compute_fringe_widths (f
, 0);
9827 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
9828 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
9830 f
->output_data
.mac
->win_gravity
= NorthWestGravity
;
9831 x_wm_set_size_hint (f
, (long) 0, 0);
9833 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
9835 /* Now, strictly speaking, we can't be sure that this is accurate,
9836 but the window manager will get around to dealing with the size
9837 change request eventually, and we'll hear how it went when the
9838 ConfigureNotify event gets here.
9840 We could just not bother storing any of this information here,
9841 and let the ConfigureNotify event set everything up, but that
9842 might be kind of confusing to the Lisp code, since size changes
9843 wouldn't be reported in the frame parameters until some random
9844 point in the future when the ConfigureNotify event arrives.
9846 We pass 1 for DELAY since we can't run Lisp code inside of
9848 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9849 PIXEL_WIDTH (f
) = pixelwidth
;
9850 PIXEL_HEIGHT (f
) = pixelheight
;
9852 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9853 receive in the ConfigureNotify event; if we get what we asked
9854 for, then the event won't cause the screen to become garbaged, so
9855 we have to make sure to do it here. */
9856 SET_FRAME_GARBAGED (f
);
9858 XFlush (FRAME_X_DISPLAY (f
));
9860 /* If cursor was outside the new size, mark it as off. */
9861 mark_window_cursors_off (XWINDOW (f
->root_window
));
9863 /* Clear out any recollection of where the mouse highlighting was,
9864 since it might be in a place that's outside the new frame size.
9865 Actually checking whether it is outside is a pain in the neck,
9866 so don't try--just let the highlighting be done afresh with new size. */
9867 cancel_mouse_face (f
);
9872 /* Mouse warping. */
9874 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
9877 x_set_mouse_position (f
, x
, y
)
9883 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.mac
->font
) / 2;
9884 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.mac
->line_height
/ 2;
9886 if (pix_x
< 0) pix_x
= 0;
9887 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
9889 if (pix_y
< 0) pix_y
= 0;
9890 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
9892 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
9896 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9900 #if 0 /* MAC_TODO: CursorDeviceMoveTo is non-Carbon */
9903 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9904 0, 0, 0, 0, pix_x
, pix_y
);
9910 /* focus shifting, raising and lowering. */
9913 x_focus_on_frame (f
)
9916 #if 0 /* This proves to be unpleasant. */
9920 /* I don't think that the ICCCM allows programs to do things like this
9921 without the interaction of the window manager. Whatever you end up
9922 doing with this code, do it to x_unfocus_frame too. */
9923 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9924 RevertToPointerRoot
, CurrentTime
);
9934 /* Raise frame F. */
9939 if (f
->async_visible
)
9940 SelectWindow (FRAME_MAC_WINDOW (f
));
9943 /* Lower frame F. */
9948 if (f
->async_visible
)
9949 SendBehind (FRAME_MAC_WINDOW (f
), nil
);
9953 XTframe_raise_lower (f
, raise_flag
)
9963 /* Change of visibility. */
9965 /* This tries to wait until the frame is really visible.
9966 However, if the window manager asks the user where to position
9967 the frame, this will return before the user finishes doing that.
9968 The frame will not actually be visible at that time,
9969 but it will become visible later when the window manager
9970 finishes with it. */
9973 x_make_frame_visible (f
)
9977 int original_top
, original_left
;
9981 if (! FRAME_VISIBLE_P (f
))
9983 /* We test FRAME_GARBAGED_P here to make sure we don't
9984 call x_set_offset a second time
9985 if we get to x_make_frame_visible a second time
9986 before the window gets really visible. */
9987 if (! FRAME_ICONIFIED_P (f
)
9988 && ! f
->output_data
.mac
->asked_for_visible
)
9989 x_set_offset (f
, f
->output_data
.mac
->left_pos
,
9990 f
->output_data
.mac
->top_pos
, 0);
9992 f
->output_data
.mac
->asked_for_visible
= 1;
9994 ShowWindow (FRAME_MAC_WINDOW (f
));
9997 XFlush (FRAME_MAC_DISPLAY (f
));
9999 #if 0 /* MAC_TODO */
10000 /* Synchronize to ensure Emacs knows the frame is visible
10001 before we do anything else. We do this loop with input not blocked
10002 so that incoming events are handled. */
10007 /* This must come after we set COUNT. */
10010 XSETFRAME (frame
, f
);
10012 /* Wait until the frame is visible. Process X events until a
10013 MapNotify event has been seen, or until we think we won't get a
10014 MapNotify at all.. */
10015 for (count
= input_signal_count
+ 10;
10016 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
10018 /* Force processing of queued events. */
10021 /* Machines that do polling rather than SIGIO have been
10022 observed to go into a busy-wait here. So we'll fake an
10023 alarm signal to let the handler know that there's something
10024 to be read. We used to raise a real alarm, but it seems
10025 that the handler isn't always enabled here. This is
10027 if (input_polling_used ())
10029 /* It could be confusing if a real alarm arrives while
10030 processing the fake one. Turn it off and let the
10031 handler reset it. */
10032 extern void poll_for_input_1
P_ ((void));
10033 int old_poll_suppress_count
= poll_suppress_count
;
10034 poll_suppress_count
= 1;
10035 poll_for_input_1 ();
10036 poll_suppress_count
= old_poll_suppress_count
;
10039 /* See if a MapNotify event has been processed. */
10040 FRAME_SAMPLE_VISIBILITY (f
);
10043 #endif /* MAC_TODO */
10046 /* Change from mapped state to withdrawn state. */
10048 /* Make the frame visible (mapped and not iconified). */
10051 x_make_frame_invisible (f
)
10054 /* Don't keep the highlight on an invisible frame. */
10055 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
10056 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
10060 HideWindow (FRAME_MAC_WINDOW (f
));
10062 /* We can't distinguish this from iconification
10063 just by the event that we get from the server.
10064 So we can't win using the usual strategy of letting
10065 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
10066 and synchronize with the server to make sure we agree. */
10068 FRAME_ICONIFIED_P (f
) = 0;
10069 f
->async_visible
= 0;
10070 f
->async_iconified
= 0;
10075 /* Change window state from mapped to iconified. */
10078 x_iconify_frame (f
)
10081 #if 0 /* MAC_TODO: really no iconify on Mac */
10085 /* Don't keep the highlight on an invisible frame. */
10086 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
10087 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
10089 if (f
->async_iconified
)
10094 FRAME_SAMPLE_VISIBILITY (f
);
10096 type
= x_icon_type (f
);
10098 x_bitmap_icon (f
, type
);
10100 #ifdef USE_X_TOOLKIT
10102 if (! FRAME_VISIBLE_P (f
))
10104 if (! EQ (Vx_no_window_manager
, Qt
))
10105 x_wm_set_window_state (f
, IconicState
);
10106 /* This was XtPopup, but that did nothing for an iconified frame. */
10107 XtMapWidget (f
->output_data
.x
->widget
);
10108 /* The server won't give us any event to indicate
10109 that an invisible frame was changed to an icon,
10110 so we have to record it here. */
10113 f
->async_iconified
= 1;
10114 f
->async_visible
= 0;
10119 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
10120 XtWindow (f
->output_data
.x
->widget
),
10121 DefaultScreen (FRAME_X_DISPLAY (f
)));
10125 error ("Can't notify window manager of iconification");
10127 f
->async_iconified
= 1;
10128 f
->async_visible
= 0;
10132 XFlush (FRAME_X_DISPLAY (f
));
10134 #else /* not USE_X_TOOLKIT */
10136 /* Make sure the X server knows where the window should be positioned,
10137 in case the user deiconifies with the window manager. */
10138 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
10139 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
10141 /* Since we don't know which revision of X we're running, we'll use both
10142 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
10144 /* X11R4: send a ClientMessage to the window manager using the
10145 WM_CHANGE_STATE type. */
10149 message
.xclient
.window
= FRAME_X_WINDOW (f
);
10150 message
.xclient
.type
= ClientMessage
;
10151 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
10152 message
.xclient
.format
= 32;
10153 message
.xclient
.data
.l
[0] = IconicState
;
10155 if (! XSendEvent (FRAME_X_DISPLAY (f
),
10156 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
10158 SubstructureRedirectMask
| SubstructureNotifyMask
,
10161 UNBLOCK_INPUT_RESIGNAL
;
10162 error ("Can't notify window manager of iconification");
10166 /* X11R3: set the initial_state field of the window manager hints to
10168 x_wm_set_window_state (f
, IconicState
);
10170 if (!FRAME_VISIBLE_P (f
))
10172 /* If the frame was withdrawn, before, we must map it. */
10173 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10176 f
->async_iconified
= 1;
10177 f
->async_visible
= 0;
10179 XFlush (FRAME_X_DISPLAY (f
));
10181 #endif /* not USE_X_TOOLKIT */
10182 #endif /* MAC_TODO */
10186 /* Destroy the X window of frame F. */
10189 x_destroy_window (f
)
10192 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
10196 DisposeWindow (FRAME_MAC_WINDOW (f
));
10198 free_frame_menubar (f
);
10199 free_frame_faces (f
);
10201 xfree (f
->output_data
.mac
);
10202 f
->output_data
.mac
= 0;
10203 if (f
== dpyinfo
->x_focus_frame
)
10204 dpyinfo
->x_focus_frame
= 0;
10205 if (f
== dpyinfo
->x_focus_event_frame
)
10206 dpyinfo
->x_focus_event_frame
= 0;
10207 if (f
== dpyinfo
->x_highlight_frame
)
10208 dpyinfo
->x_highlight_frame
= 0;
10210 dpyinfo
->reference_count
--;
10212 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10214 dpyinfo
->mouse_face_beg_row
10215 = dpyinfo
->mouse_face_beg_col
= -1;
10216 dpyinfo
->mouse_face_end_row
10217 = dpyinfo
->mouse_face_end_col
= -1;
10218 dpyinfo
->mouse_face_window
= Qnil
;
10219 dpyinfo
->mouse_face_deferred_gc
= 0;
10220 dpyinfo
->mouse_face_mouse_frame
= 0;
10226 /* Setting window manager hints. */
10228 /* Set the normal size hints for the window manager, for frame F.
10229 FLAGS is the flags word to use--or 0 meaning preserve the flags
10230 that the window now has.
10231 If USER_POSITION is nonzero, we set the USPosition
10232 flag (this is useful when FLAGS is 0). */
10234 x_wm_set_size_hint (f
, flags
, user_position
)
10239 #if 0 /* MAC_TODO: connect this to the Appearance Manager */
10240 XSizeHints size_hints
;
10242 #ifdef USE_X_TOOLKIT
10245 Dimension widget_width
, widget_height
;
10246 Window window
= XtWindow (f
->output_data
.x
->widget
);
10247 #else /* not USE_X_TOOLKIT */
10248 Window window
= FRAME_X_WINDOW (f
);
10249 #endif /* not USE_X_TOOLKIT */
10251 /* Setting PMaxSize caused various problems. */
10252 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
10254 size_hints
.x
= f
->output_data
.x
->left_pos
;
10255 size_hints
.y
= f
->output_data
.x
->top_pos
;
10257 #ifdef USE_X_TOOLKIT
10258 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
10259 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
10260 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
10261 size_hints
.height
= widget_height
;
10262 size_hints
.width
= widget_width
;
10263 #else /* not USE_X_TOOLKIT */
10264 size_hints
.height
= PIXEL_HEIGHT (f
);
10265 size_hints
.width
= PIXEL_WIDTH (f
);
10266 #endif /* not USE_X_TOOLKIT */
10268 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
10269 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
10270 size_hints
.max_width
10271 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
10272 size_hints
.max_height
10273 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
10275 /* Calculate the base and minimum sizes.
10277 (When we use the X toolkit, we don't do it here.
10278 Instead we copy the values that the widgets are using, below.) */
10279 #ifndef USE_X_TOOLKIT
10281 int base_width
, base_height
;
10282 int min_rows
= 0, min_cols
= 0;
10284 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
10285 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
10287 check_frame_size (f
, &min_rows
, &min_cols
);
10289 /* The window manager uses the base width hints to calculate the
10290 current number of rows and columns in the frame while
10291 resizing; min_width and min_height aren't useful for this
10292 purpose, since they might not give the dimensions for a
10293 zero-row, zero-column frame.
10295 We use the base_width and base_height members if we have
10296 them; otherwise, we set the min_width and min_height members
10297 to the size for a zero x zero frame. */
10300 size_hints
.flags
|= PBaseSize
;
10301 size_hints
.base_width
= base_width
;
10302 size_hints
.base_height
= base_height
;
10303 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
10304 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
10306 size_hints
.min_width
= base_width
;
10307 size_hints
.min_height
= base_height
;
10311 /* If we don't need the old flags, we don't need the old hint at all. */
10314 size_hints
.flags
|= flags
;
10317 #endif /* not USE_X_TOOLKIT */
10320 XSizeHints hints
; /* Sometimes I hate X Windows... */
10321 long supplied_return
;
10325 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
10328 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
10331 #ifdef USE_X_TOOLKIT
10332 size_hints
.base_height
= hints
.base_height
;
10333 size_hints
.base_width
= hints
.base_width
;
10334 size_hints
.min_height
= hints
.min_height
;
10335 size_hints
.min_width
= hints
.min_width
;
10339 size_hints
.flags
|= flags
;
10344 if (hints
.flags
& PSize
)
10345 size_hints
.flags
|= PSize
;
10346 if (hints
.flags
& PPosition
)
10347 size_hints
.flags
|= PPosition
;
10348 if (hints
.flags
& USPosition
)
10349 size_hints
.flags
|= USPosition
;
10350 if (hints
.flags
& USSize
)
10351 size_hints
.flags
|= USSize
;
10355 #ifndef USE_X_TOOLKIT
10360 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
10361 size_hints
.flags
|= PWinGravity
;
10365 size_hints
.flags
&= ~ PPosition
;
10366 size_hints
.flags
|= USPosition
;
10368 #endif /* PWinGravity */
10371 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
10373 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
10375 #endif /* MAC_TODO */
10378 #if 0 /* MAC_TODO: hide application instead of iconify? */
10379 /* Used for IconicState or NormalState */
10382 x_wm_set_window_state (f
, state
)
10386 #ifdef USE_X_TOOLKIT
10389 XtSetArg (al
[0], XtNinitialState
, state
);
10390 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10391 #else /* not USE_X_TOOLKIT */
10392 Window window
= FRAME_X_WINDOW (f
);
10394 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
10395 f
->output_data
.x
->wm_hints
.initial_state
= state
;
10397 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10398 #endif /* not USE_X_TOOLKIT */
10402 x_wm_set_icon_pixmap (f
, pixmap_id
)
10406 Pixmap icon_pixmap
;
10408 #ifndef USE_X_TOOLKIT
10409 Window window
= FRAME_X_WINDOW (f
);
10414 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
10415 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
10419 /* It seems there is no way to turn off use of an icon pixmap.
10420 The following line does it, only if no icon has yet been created,
10421 for some window managers. But with mwm it crashes.
10422 Some people say it should clear the IconPixmapHint bit in this case,
10423 but that doesn't work, and the X consortium said it isn't the
10424 right thing at all. Since there is no way to win,
10425 best to explicitly give up. */
10427 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
10433 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
10437 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
10438 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10441 #else /* not USE_X_TOOLKIT */
10443 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
10444 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10446 #endif /* not USE_X_TOOLKIT */
10449 #endif /* MAC_TODO */
10452 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10454 int icon_x
, icon_y
;
10456 #if 0 /* MAC_TODO: no icons on Mac */
10457 #ifdef USE_X_TOOLKIT
10458 Window window
= XtWindow (f
->output_data
.x
->widget
);
10460 Window window
= FRAME_X_WINDOW (f
);
10463 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
10464 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
10465 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
10467 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10468 #endif /* MAC_TODO */
10472 /***********************************************************************
10474 ***********************************************************************/
10476 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
10479 x_get_font_info (f
, font_idx
)
10483 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
10486 /* the global font name table */
10487 char **font_name_table
= NULL
;
10488 int font_name_table_size
= 0;
10489 int font_name_count
= 0;
10491 /* compare two strings ignoring case */
10493 stricmp (const char *s
, const char *t
)
10495 for ( ; tolower (*s
) == tolower (*t
); s
++, t
++)
10498 return tolower (*s
) - tolower (*t
);
10501 /* compare two strings ignoring case and handling wildcard */
10503 wildstrieq (char *s1
, char *s2
)
10505 if (strcmp (s1
, "*") == 0 || strcmp (s2
, "*") == 0)
10508 return stricmp (s1
, s2
) == 0;
10511 /* Assume parameter 1 is fully qualified, no wildcards. */
10513 mac_font_pattern_match (fontname
, pattern
)
10517 char *regex
= (char *) alloca (strlen (pattern
) * 2 + 3);
10518 char *font_name_copy
= (char *) alloca (strlen (fontname
) + 1);
10521 /* Copy fontname so we can modify it during comparison. */
10522 strcpy (font_name_copy
, fontname
);
10527 /* Turn pattern into a regexp and do a regexp match. */
10528 for (; *pattern
; pattern
++)
10530 if (*pattern
== '?')
10532 else if (*pattern
== '*')
10543 return (fast_c_string_match_ignore_case (build_string (regex
),
10544 font_name_copy
) >= 0);
10547 /* Two font specs are considered to match if their foundry, family,
10548 weight, slant, and charset match. */
10550 mac_font_match (char *mf
, char *xf
)
10552 char m_foundry
[50], m_family
[50], m_weight
[20], m_slant
[2], m_charset
[20];
10553 char x_foundry
[50], x_family
[50], x_weight
[20], x_slant
[2], x_charset
[20];
10555 if (sscanf (mf
, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s",
10556 m_foundry
, m_family
, m_weight
, m_slant
, m_charset
) != 5)
10557 return mac_font_pattern_match (mf
, xf
);
10559 if (sscanf (xf
, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s",
10560 x_foundry
, x_family
, x_weight
, x_slant
, x_charset
) != 5)
10561 return mac_font_pattern_match (mf
, xf
);
10563 return (wildstrieq (m_foundry
, x_foundry
)
10564 && wildstrieq (m_family
, x_family
)
10565 && wildstrieq (m_weight
, x_weight
)
10566 && wildstrieq (m_slant
, x_slant
)
10567 && wildstrieq (m_charset
, x_charset
))
10568 || mac_font_pattern_match (mf
, xf
);
10573 mac_to_x_fontname (char *name
, int size
, Style style
, short scriptcode
)
10575 char foundry
[32], family
[32], cs
[32];
10576 char xf
[255], *result
, *p
;
10578 if (sscanf (name
, "%31[^-]-%31[^-]-%31s", foundry
, family
, cs
) != 3)
10580 strcpy(foundry
, "Apple");
10581 strcpy(family
, name
);
10583 switch (scriptcode
)
10585 case smTradChinese
:
10586 strcpy(cs
, "big5-0");
10588 case smSimpChinese
:
10589 strcpy(cs
, "gb2312.1980-0");
10592 strcpy(cs
, "jisx0208.1983-sjis");
10595 /* Each Apple Japanese font is entered into the font table
10596 twice: once as a jisx0208.1983-sjis font and once as a
10597 jisx0201.1976-0 font. The latter can be used to display
10598 the ascii charset and katakana-jisx0201 charset. A
10599 negative script code signals that the name of this latter
10600 font is being built. */
10601 strcpy(cs
, "jisx0201.1976-0");
10604 strcpy(cs
, "ksc5601.1989-0");
10607 strcpy(cs
, "mac-roman");
10612 sprintf(xf
, "-%s-%s-%s-%c-normal--%d-%d-75-75-m-%d-%s",
10613 foundry
, family
, style
& bold
? "bold" : "medium",
10614 style
& italic
? 'i' : 'r', size
, size
* 10, size
* 10, cs
);
10616 result
= (char *) xmalloc (strlen (xf
) + 1);
10617 strcpy (result
, xf
);
10618 for (p
= result
; *p
; p
++)
10624 /* Convert an X font spec to the corresponding mac font name, which
10625 can then be passed to GetFNum after conversion to a Pascal string.
10626 For ordinary Mac fonts, this should just be their names, like
10627 "monaco", "Taipei", etc. Fonts converted from the GNU intlfonts
10628 collection contain their charset designation in their names, like
10629 "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both types of font
10630 names are handled accordingly. */
10632 x_font_name_to_mac_font_name (char *xf
, char *mf
)
10634 char foundry
[32], family
[32], weight
[20], slant
[2], cs
[32];
10638 if (sscanf (xf
, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
10639 foundry
, family
, weight
, slant
, cs
) != 5 &&
10640 sscanf (xf
, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
10641 foundry
, family
, weight
, slant
, cs
) != 5)
10644 if (strcmp (cs
, "big5-0") == 0 || strcmp (cs
, "gb2312.1980-0") == 0
10645 || strcmp (cs
, "jisx0208.1983-sjis") == 0
10646 || strcmp (cs
, "jisx0201.1976-0") == 0
10647 || strcmp (cs
, "ksc5601.1989-0") == 0 || strcmp (cs
, "mac-roman") == 0)
10648 strcpy(mf
, family
);
10650 sprintf(mf
, "%s-%s-%s", foundry
, family
, cs
);
10654 /* Sets up the table font_name_table to contain the list of all
10655 monospace fonts in the system the first time the table is used so
10656 that the Resource Manager need not be accessed every time this
10657 information is needed. */
10660 init_font_name_table ()
10662 #if TARGET_API_MAC_CARBON
10665 if (Gestalt (gestaltSystemVersion
, &sv
) == noErr
&& sv
>= 0x1000)
10667 FMFontFamilyIterator ffi
;
10668 FMFontFamilyInstanceIterator ffii
;
10671 /* Create a dummy instance iterator here to avoid creating and
10672 destroying it in the loop. */
10673 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
10675 /* Create an iterator to enumerate the font families. */
10676 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
10679 FMDisposeFontFamilyInstanceIterator (&ffii
);
10683 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
10691 if (FMGetFontFamilyName (ff
, name
) != noErr
)
10695 sc
= FontToScript (ff
);
10697 /* Point the instance iterator at the current font family. */
10698 if (FMResetFontFamilyInstanceIterator(ff
, &ffii
) != noErr
)
10701 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
10704 if (font_name_table_size
== 0)
10706 font_name_table_size
= 16;
10707 font_name_table
= (char **)
10708 xmalloc (font_name_table_size
* sizeof (char *));
10710 else if (font_name_count
+ 1 >= font_name_table_size
)
10712 font_name_table_size
+= 16;
10713 font_name_table
= (char **)
10714 xrealloc (font_name_table
,
10715 font_name_table_size
* sizeof (char *));
10717 font_name_table
[font_name_count
++]
10718 = mac_to_x_fontname (name
, size
, style
, sc
);
10722 /* Dispose of the iterators. */
10723 FMDisposeFontFamilyIterator (&ffi
);
10724 FMDisposeFontFamilyInstanceIterator (&ffii
);
10728 #endif /* TARGET_API_MAC_CARBON */
10730 SInt16 fontnum
, old_fontnum
;
10731 int num_mac_fonts
= CountResources('FOND');
10733 Handle font_handle
, font_handle_2
;
10734 short id
, scriptcode
;
10737 struct FontAssoc
*fat
;
10738 struct AsscEntry
*assc_entry
;
10740 GetPort (&port
); /* save the current font number used */
10741 #if TARGET_API_MAC_CARBON
10742 old_fontnum
= GetPortTextFont (port
);
10744 old_fontnum
= port
->txFont
;
10747 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
10749 font_handle
= GetIndResource ('FOND', i
);
10753 GetResInfo (font_handle
, &id
, &type
, name
);
10754 GetFNum (name
, &fontnum
);
10759 TextFont (fontnum
);
10760 scriptcode
= FontToScript (fontnum
);
10763 HLock (font_handle
);
10765 if (GetResourceSizeOnDisk (font_handle
)
10766 >= sizeof (struct FamRec
))
10768 fat
= (struct FontAssoc
*) (*font_handle
10769 + sizeof (struct FamRec
));
10771 = (struct AsscEntry
*) (*font_handle
10772 + sizeof (struct FamRec
)
10773 + sizeof (struct FontAssoc
));
10775 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
10777 if (font_name_table_size
== 0)
10779 font_name_table_size
= 16;
10780 font_name_table
= (char **)
10781 xmalloc (font_name_table_size
* sizeof (char *));
10783 else if (font_name_count
>= font_name_table_size
)
10785 font_name_table_size
+= 16;
10786 font_name_table
= (char **)
10787 xrealloc (font_name_table
,
10788 font_name_table_size
* sizeof (char *));
10790 font_name_table
[font_name_count
++]
10791 = mac_to_x_fontname (name
,
10792 assc_entry
->fontSize
,
10793 assc_entry
->fontStyle
,
10795 /* Both jisx0208.1983-sjis and
10796 jisx0201.1976-sjis parts are contained in
10797 Apple Japanese (SJIS) font. */
10798 if (smJapanese
== scriptcode
)
10800 font_name_table
[font_name_count
++]
10801 = mac_to_x_fontname (name
,
10802 assc_entry
->fontSize
,
10803 assc_entry
->fontStyle
,
10809 HUnlock (font_handle
);
10810 font_handle_2
= GetNextFOND (font_handle
);
10811 ReleaseResource (font_handle
);
10812 font_handle
= font_handle_2
;
10814 while (ResError () == noErr
&& font_handle
);
10817 TextFont (old_fontnum
);
10818 #if TARGET_API_MAC_CARBON
10820 #endif /* TARGET_API_MAC_CARBON */
10824 /* Return a list of at most MAXNAMES font specs matching the one in
10825 PATTERN. Note that each '*' in the PATTERN matches exactly one
10826 field of the font spec, unlike X in which an '*' in a font spec can
10827 match a number of fields. The result is in the Mac implementation
10828 all fonts must be specified by a font spec with all 13 fields
10829 (although many of these can be "*'s"). */
10832 x_list_fonts (struct frame
*f
,
10833 Lisp_Object pattern
,
10838 Lisp_Object newlist
= Qnil
;
10841 struct gcpro gcpro1
, gcpro2
;
10843 if (font_name_table
== NULL
) /* Initialize when first used. */
10844 init_font_name_table ();
10846 ptnstr
= XSTRING (pattern
)->data
;
10848 GCPRO2 (pattern
, newlist
);
10850 /* Scan and matching bitmap fonts. */
10851 for (i
= 0; i
< font_name_count
; i
++)
10853 if (mac_font_pattern_match (font_name_table
[i
], ptnstr
))
10855 newlist
= Fcons (build_string (font_name_table
[i
]), newlist
);
10858 if (n_fonts
>= maxnames
)
10863 /* MAC_TODO: add code for matching outline fonts here */
10873 /* Check that FONT is valid on frame F. It is if it can be found in F's
10877 x_check_font (f
, font
)
10882 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10884 xassert (font
!= NULL
);
10886 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10887 if (dpyinfo
->font_table
[i
].name
10888 && font
== dpyinfo
->font_table
[i
].font
)
10891 xassert (i
< dpyinfo
->n_fonts
);
10894 #endif /* GLYPH_DEBUG != 0 */
10896 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10897 Note: There are (broken) X fonts out there with invalid XFontStruct
10898 min_bounds contents. For example, handa@etl.go.jp reports that
10899 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10900 have font->min_bounds.width == 0. */
10903 x_font_min_bounds (font
, w
, h
)
10904 MacFontStruct
*font
;
10908 * TODO: Windows does not appear to offer min bound, only
10909 * average and maximum width, and maximum height.
10911 *h
= FONT_HEIGHT (font
);
10912 *w
= FONT_WIDTH (font
);
10916 /* Compute the smallest character width and smallest font height over
10917 all fonts available on frame F. Set the members smallest_char_width
10918 and smallest_font_height in F's x_display_info structure to
10919 the values computed. Value is non-zero if smallest_font_height or
10920 smallest_char_width become smaller than they were before. */
10923 x_compute_min_glyph_bounds (f
)
10927 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
10928 MacFontStruct
*font
;
10929 int old_width
= dpyinfo
->smallest_char_width
;
10930 int old_height
= dpyinfo
->smallest_font_height
;
10932 dpyinfo
->smallest_font_height
= 100000;
10933 dpyinfo
->smallest_char_width
= 100000;
10935 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10936 if (dpyinfo
->font_table
[i
].name
)
10938 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10941 font
= (MacFontStruct
*) fontp
->font
;
10942 xassert (font
!= (MacFontStruct
*) ~0);
10943 x_font_min_bounds (font
, &w
, &h
);
10945 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10946 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10949 xassert (dpyinfo
->smallest_char_width
> 0
10950 && dpyinfo
->smallest_font_height
> 0);
10952 return (dpyinfo
->n_fonts
== 1
10953 || dpyinfo
->smallest_char_width
< old_width
10954 || dpyinfo
->smallest_font_height
< old_height
);
10958 /* Determine whether given string is a fully-specified XLFD: all 14
10959 fields are present, none is '*'. */
10962 is_fully_specified_xlfd (char *p
)
10970 for (i
= 0; i
< 13; i
++)
10972 q
= strchr (p
+ 1, '-');
10975 if (q
- p
== 2 && *(p
+ 1) == '*')
10980 if (strchr (p
+ 1, '-') != NULL
)
10983 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
10990 const int kDefaultFontSize
= 9;
10993 /* XLoadQueryFont creates and returns an internal representation for a
10994 font in a MacFontStruct struct. There is really no concept
10995 corresponding to "loading" a font on the Mac. But we check its
10996 existence and find the font number and all other information for it
10997 and store them in the returned MacFontStruct. */
10999 static MacFontStruct
*
11000 XLoadQueryFont (Display
*dpy
, char *fontname
)
11002 int i
, size
, is_two_byte_font
, char_width
;
11005 SInt16 old_fontnum
, old_fontsize
;
11006 Style old_fontface
;
11009 Style fontface
= normal
;
11010 MacFontStruct
*font
;
11011 FontInfo the_fontinfo
;
11012 char s_weight
[7], c_slant
;
11014 if (is_fully_specified_xlfd (fontname
))
11018 for (i
= 0; i
< font_name_count
; i
++)
11019 if (mac_font_pattern_match (font_name_table
[i
], fontname
))
11022 if (i
>= font_name_count
)
11025 name
= font_name_table
[i
];
11028 GetPort (&port
); /* save the current font number used */
11029 #if TARGET_API_MAC_CARBON
11030 old_fontnum
= GetPortTextFont (port
);
11031 old_fontsize
= GetPortTextSize (port
);
11032 old_fontface
= GetPortTextFace (port
);
11034 old_fontnum
= port
->txFont
;
11035 old_fontsize
= port
->txSize
;
11036 old_fontface
= port
->txFace
;
11039 if (sscanf (name
, "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%d-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &size
) != 1)
11040 size
= kDefaultFontSize
;
11042 if (sscanf (name
, "-%*[^-]-%*[^-]-%6[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", s_weight
) == 1)
11043 if (strcmp (s_weight
, "bold") == 0)
11046 if (sscanf (name
, "-%*[^-]-%*[^-]-%*[^-]-%c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &c_slant
) == 1)
11047 if (c_slant
== 'i')
11048 fontface
|= italic
;
11050 x_font_name_to_mac_font_name (name
, mfontname
);
11051 c2pstr (mfontname
);
11052 GetFNum (mfontname
, &fontnum
);
11056 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
11058 font
->fontname
= (char *) xmalloc (strlen (name
) + 1);
11059 bcopy (name
, font
->fontname
, strlen (name
) + 1);
11061 font
->mac_fontnum
= fontnum
;
11062 font
->mac_fontsize
= size
;
11063 font
->mac_fontface
= fontface
;
11064 font
->mac_scriptcode
= FontToScript (fontnum
);
11066 /* Apple Japanese (SJIS) font is listed as both
11067 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
11068 (Roman script) in init_font_name_table (). The latter should be
11069 treated as a one-byte font. */
11074 "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
11076 && 0 == strcmp (cs
, "mac-roman"))
11077 font
->mac_scriptcode
= smRoman
;
11080 is_two_byte_font
= font
->mac_scriptcode
== smJapanese
||
11081 font
->mac_scriptcode
== smTradChinese
||
11082 font
->mac_scriptcode
== smSimpChinese
||
11083 font
->mac_scriptcode
== smKorean
;
11085 TextFont (fontnum
);
11087 TextFace (fontface
);
11089 GetFontInfo (&the_fontinfo
);
11091 font
->ascent
= the_fontinfo
.ascent
;
11092 font
->descent
= the_fontinfo
.descent
;
11094 font
->min_byte1
= 0;
11095 if (is_two_byte_font
)
11096 font
->max_byte1
= 1;
11098 font
->max_byte1
= 0;
11099 font
->min_char_or_byte2
= 0x20;
11100 font
->max_char_or_byte2
= 0xff;
11102 if (is_two_byte_font
)
11104 /* Use the width of an "ideographic space" of that font because
11105 the_fontinfo.widMax returns the wrong width for some fonts. */
11106 switch (font
->mac_scriptcode
)
11109 char_width
= StringWidth("\p\x81\x40");
11111 case smTradChinese
:
11112 char_width
= StringWidth("\p\xa1\x40");
11114 case smSimpChinese
:
11115 char_width
= StringWidth("\p\xa1\xa1");
11118 char_width
= StringWidth("\p\xa1\xa1");
11123 /* Do this instead of use the_fontinfo.widMax, which incorrectly
11124 returns 15 for 12-point Monaco! */
11125 char_width
= CharWidth ('m');
11127 font
->max_bounds
.rbearing
= char_width
;
11128 font
->max_bounds
.lbearing
= 0;
11129 font
->max_bounds
.width
= char_width
;
11130 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
11131 font
->max_bounds
.descent
= the_fontinfo
.descent
;
11133 font
->min_bounds
= font
->max_bounds
;
11135 if (is_two_byte_font
|| CharWidth ('m') == CharWidth ('i'))
11136 font
->per_char
= NULL
;
11139 font
->per_char
= (XCharStruct
*)
11140 xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
11144 for (c
= 0x20; c
<= 0xff; c
++)
11146 font
->per_char
[c
- 0x20] = font
->max_bounds
;
11147 font
->per_char
[c
- 0x20].width
= CharWidth (c
);
11152 TextFont (old_fontnum
); /* restore previous font number, size and face */
11153 TextSize (old_fontsize
);
11154 TextFace (old_fontface
);
11160 /* Load font named FONTNAME of the size SIZE for frame F, and return a
11161 pointer to the structure font_info while allocating it dynamically.
11162 If SIZE is 0, load any size of font.
11163 If loading is failed, return NULL. */
11166 x_load_font (f
, fontname
, size
)
11168 register char *fontname
;
11171 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
11172 Lisp_Object font_names
;
11174 /* Get a list of all the fonts that match this name. Once we
11175 have a list of matching fonts, we compare them against the fonts
11176 we already have by comparing names. */
11177 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
11179 if (!NILP (font_names
))
11184 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11185 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
11186 if (dpyinfo
->font_table
[i
].name
11187 && (!strcmp (dpyinfo
->font_table
[i
].name
,
11188 XSTRING (XCAR (tail
))->data
)
11189 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
11190 XSTRING (XCAR (tail
))->data
)))
11191 return (dpyinfo
->font_table
+ i
);
11194 /* Load the font and add it to the table. */
11197 struct MacFontStruct
*font
;
11198 struct font_info
*fontp
;
11199 unsigned long value
;
11202 /* If we have found fonts by x_list_font, load one of them. If
11203 not, we still try to load a font by the name given as FONTNAME
11204 because XListFonts (called in x_list_font) of some X server has
11205 a bug of not finding a font even if the font surely exists and
11206 is loadable by XLoadQueryFont. */
11207 if (size
> 0 && !NILP (font_names
))
11208 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
11210 font
= (MacFontStruct
*) XLoadQueryFont (FRAME_MAC_DISPLAY (f
), fontname
);
11214 /* Find a free slot in the font table. */
11215 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
11216 if (dpyinfo
->font_table
[i
].name
== NULL
)
11219 /* If no free slot found, maybe enlarge the font table. */
11220 if (i
== dpyinfo
->n_fonts
11221 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
11224 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
11225 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
11226 dpyinfo
->font_table
11227 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
11230 fontp
= dpyinfo
->font_table
+ i
;
11231 if (i
== dpyinfo
->n_fonts
)
11232 ++dpyinfo
->n_fonts
;
11234 /* Now fill in the slots of *FONTP. */
11236 fontp
->font
= font
;
11237 fontp
->font_idx
= i
;
11238 fontp
->name
= (char *) xmalloc (strlen (font
->fontname
) + 1);
11239 bcopy (font
->fontname
, fontp
->name
, strlen (font
->fontname
) + 1);
11241 fontp
->full_name
= fontp
->name
;
11243 fontp
->size
= font
->max_bounds
.width
;
11244 fontp
->height
= FONT_HEIGHT (font
);
11246 /* For some font, ascent and descent in max_bounds field is
11247 larger than the above value. */
11248 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
11249 if (max_height
> fontp
->height
)
11250 fontp
->height
= max_height
;
11253 /* The slot `encoding' specifies how to map a character
11254 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
11255 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
11256 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
11257 2:0xA020..0xFF7F). For the moment, we don't know which charset
11258 uses this font. So, we set information in fontp->encoding[1]
11259 which is never used by any charset. If mapping can't be
11260 decided, set FONT_ENCODING_NOT_DECIDED. */
11261 if (font
->mac_scriptcode
== smJapanese
)
11262 fontp
->encoding
[1] = 4;
11266 = (font
->max_byte1
== 0
11268 ? (font
->min_char_or_byte2
< 0x80
11269 ? (font
->max_char_or_byte2
< 0x80
11270 ? 0 /* 0x20..0x7F */
11271 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
11272 : 1) /* 0xA0..0xFF */
11274 : (font
->min_byte1
< 0x80
11275 ? (font
->max_byte1
< 0x80
11276 ? (font
->min_char_or_byte2
< 0x80
11277 ? (font
->max_char_or_byte2
< 0x80
11278 ? 0 /* 0x2020..0x7F7F */
11279 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
11280 : 3) /* 0x20A0..0x7FFF */
11281 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
11282 : (font
->min_char_or_byte2
< 0x80
11283 ? (font
->max_char_or_byte2
< 0x80
11284 ? 2 /* 0xA020..0xFF7F */
11285 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
11286 : 1))); /* 0xA0A0..0xFFFF */
11289 #if 0 /* MAC_TODO: fill these out with more reasonably values */
11290 fontp
->baseline_offset
11291 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
11292 ? (long) value
: 0);
11293 fontp
->relative_compose
11294 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
11295 ? (long) value
: 0);
11296 fontp
->default_ascent
11297 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
11298 ? (long) value
: 0);
11300 fontp
->baseline_offset
= 0;
11301 fontp
->relative_compose
= 0;
11302 fontp
->default_ascent
= 0;
11305 /* Set global flag fonts_changed_p to non-zero if the font loaded
11306 has a character with a smaller width than any other character
11307 before, or if the font loaded has a smalle>r height than any
11308 other font loaded before. If this happens, it will make a
11309 glyph matrix reallocation necessary. */
11310 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
11317 /* Return a pointer to struct font_info of a font named FONTNAME for
11318 frame F. If no such font is loaded, return NULL. */
11321 x_query_font (f
, fontname
)
11323 register char *fontname
;
11325 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
11328 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11329 if (dpyinfo
->font_table
[i
].name
11330 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
11331 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
11332 return (dpyinfo
->font_table
+ i
);
11337 /* Find a CCL program for a font specified by FONTP, and set the member
11338 `encoder' of the structure. */
11341 x_find_ccl_program (fontp
)
11342 struct font_info
*fontp
;
11344 Lisp_Object list
, elt
;
11346 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
11350 && STRINGP (XCAR (elt
))
11351 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
11357 struct ccl_program
*ccl
11358 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
11360 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
11363 fontp
->font_encoder
= ccl
;
11369 /***********************************************************************
11371 ***********************************************************************/
11373 #ifdef USE_X_TOOLKIT
11374 static XrmOptionDescRec emacs_options
[] = {
11375 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
11376 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
11378 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
11379 XrmoptionSepArg
, NULL
},
11380 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
11382 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11383 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11384 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11385 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
11386 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
11387 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
11388 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
11390 #endif /* USE_X_TOOLKIT */
11392 static int x_initialized
;
11394 #ifdef MULTI_KBOARD
11395 /* Test whether two display-name strings agree up to the dot that separates
11396 the screen number from the server number. */
11398 same_x_server (name1
, name2
)
11399 char *name1
, *name2
;
11401 int seen_colon
= 0;
11402 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
11403 int system_name_length
= strlen (system_name
);
11404 int length_until_period
= 0;
11406 while (system_name
[length_until_period
] != 0
11407 && system_name
[length_until_period
] != '.')
11408 length_until_period
++;
11410 /* Treat `unix' like an empty host name. */
11411 if (! strncmp (name1
, "unix:", 5))
11413 if (! strncmp (name2
, "unix:", 5))
11415 /* Treat this host's name like an empty host name. */
11416 if (! strncmp (name1
, system_name
, system_name_length
)
11417 && name1
[system_name_length
] == ':')
11418 name1
+= system_name_length
;
11419 if (! strncmp (name2
, system_name
, system_name_length
)
11420 && name2
[system_name_length
] == ':')
11421 name2
+= system_name_length
;
11422 /* Treat this host's domainless name like an empty host name. */
11423 if (! strncmp (name1
, system_name
, length_until_period
)
11424 && name1
[length_until_period
] == ':')
11425 name1
+= length_until_period
;
11426 if (! strncmp (name2
, system_name
, length_until_period
)
11427 && name2
[length_until_period
] == ':')
11428 name2
+= length_until_period
;
11430 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
11434 if (seen_colon
&& *name1
== '.')
11438 && (*name1
== '.' || *name1
== '\0')
11439 && (*name2
== '.' || *name2
== '\0'));
11444 /* The Mac Event loop code */
11447 #include <Events.h>
11448 #include <Quickdraw.h>
11449 #include <Balloons.h>
11450 #include <Devices.h>
11452 #include <Gestalt.h>
11454 #include <Processes.h>
11456 #include <ToolUtils.h>
11457 #include <TextUtils.h>
11458 #include <Dialogs.h>
11459 #include <Script.h>
11461 #include <TextEncodingConverter.h>
11462 #include <Resources.h>
11467 #endif /* ! MAC_OSX */
11469 #define M_APPLE 128
11472 #define WINDOW_RESOURCE 128
11473 #define TERM_WINDOW_RESOURCE 129
11475 #define DEFAULT_NUM_COLS 80
11477 #define MIN_DOC_SIZE 64
11478 #define MAX_DOC_SIZE 32767
11480 /* sleep time for WaitNextEvent */
11481 #define WNE_SLEEP_AT_SUSPEND 10
11482 #define WNE_SLEEP_AT_RESUME 1
11484 /* true when cannot handle any Mac OS events */
11485 static int handling_window_update
= 0;
11487 /* the flag appl_is_suspended is used both for determining the sleep
11488 time to be passed to WaitNextEvent and whether the cursor should be
11489 drawn when updating the display. The cursor is turned off when
11490 Emacs is suspended. Redrawing it is unnecessary and what needs to
11491 be done depends on whether the cursor lies inside or outside the
11492 redraw region. So we might as well skip drawing it when Emacs is
11494 static Boolean app_is_suspended
= false;
11495 static long app_sleep_time
= WNE_SLEEP_AT_RESUME
;
11497 #define EXTRA_STACK_ALLOC (256 * 1024)
11499 #define ARGV_STRING_LIST_ID 129
11500 #define ABOUT_ALERT_ID 128
11501 #define RAM_TOO_LARGE_ALERT_ID 129
11503 Boolean terminate_flag
= false;
11505 /* true if using command key as meta key */
11506 Lisp_Object Vmac_command_key_is_meta
;
11508 /* convert input from Mac keyboard (assumed to be in Mac Roman coding)
11509 to this text encoding */
11510 int mac_keyboard_text_encoding
;
11511 int current_mac_keyboard_text_encoding
= kTextEncodingMacRoman
;
11513 /* Set in term/mac-win.el to indicate that event loop can now generate
11514 drag and drop events. */
11515 Lisp_Object Qmac_ready_for_drag_n_drop
;
11517 Lisp_Object drag_and_drop_file_list
;
11519 Point saved_menu_event_location
;
11522 static void init_required_apple_events(void);
11523 static pascal OSErr
11524 do_ae_open_application(const AppleEvent
*, AppleEvent
*, long);
11525 static pascal OSErr
11526 do_ae_print_documents(const AppleEvent
*, AppleEvent
*, long);
11527 static pascal OSErr
do_ae_open_documents(AppleEvent
*, AppleEvent
*, long);
11528 static pascal OSErr
do_ae_quit_application(AppleEvent
*, AppleEvent
*, long);
11530 extern void init_emacs_passwd_dir ();
11531 extern int emacs_main (int, char **, char **);
11532 extern void check_alarm ();
11534 extern void initialize_applescript();
11535 extern void terminate_applescript();
11539 do_get_menus (void)
11541 Handle menubar_handle
;
11542 MenuHandle menu_handle
;
11544 menubar_handle
= GetNewMBar (128);
11545 if(menubar_handle
== NULL
)
11547 SetMenuBar (menubar_handle
);
11550 menu_handle
= GetMenuHandle (M_APPLE
);
11551 if(menu_handle
!= NULL
)
11552 AppendResMenu (menu_handle
,'DRVR');
11559 do_init_managers (void)
11561 #if !TARGET_API_MAC_CARBON
11562 InitGraf (&qd
.thePort
);
11564 FlushEvents (everyEvent
, 0);
11568 InitDialogs (NULL
);
11569 #endif /* !TARGET_API_MAC_CARBON */
11572 #if !TARGET_API_MAC_CARBON
11573 /* set up some extra stack space for use by emacs */
11574 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
11576 /* MaxApplZone must be called for AppleScript to execute more
11577 complicated scripts */
11580 #endif /* !TARGET_API_MAC_CARBON */
11584 do_check_ram_size (void)
11586 SInt32 physical_ram_size
, logical_ram_size
;
11588 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
11589 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
11590 || physical_ram_size
> 256 * 1024 * 1024
11591 || logical_ram_size
> 256 * 1024 * 1024)
11593 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
11599 do_window_update (WindowPtr win
)
11601 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (win
);
11602 struct frame
*f
= mwp
->mFP
;
11606 if (f
->async_visible
== 0)
11608 f
->async_visible
= 1;
11609 f
->async_iconified
= 0;
11610 SET_FRAME_GARBAGED (f
);
11612 /* An update event is equivalent to MapNotify on X, so report
11613 visibility changes properly. */
11614 if (! NILP(Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
11615 /* Force a redisplay sooner or later to update the
11616 frame titles in case this is the second frame. */
11617 record_asynch_buffer_change ();
11622 handling_window_update
= 1;
11624 expose_frame (f
, 0, 0, 0, 0);
11626 handling_window_update
= 0;
11633 is_emacs_window (WindowPtr win
)
11635 Lisp_Object tail
, frame
;
11640 FOR_EACH_FRAME (tail
, frame
)
11641 if (FRAME_MAC_P (XFRAME (frame
)))
11642 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
11649 do_window_activate (WindowPtr win
)
11654 if (is_emacs_window (win
))
11656 mwp
= (mac_output
*) GetWRefCon (win
);
11661 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), f
);
11662 activate_scroll_bars (f
);
11668 do_window_deactivate (WindowPtr win
)
11673 if (is_emacs_window (win
))
11675 mwp
= (mac_output
*) GetWRefCon (win
);
11678 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
11680 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), 0);
11681 deactivate_scroll_bars (f
);
11693 wp
= FrontWindow();
11694 if (is_emacs_window (wp
))
11696 mwp
= (mac_output
*) GetWRefCon (wp
);
11701 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), f
);
11702 activate_scroll_bars (f
);
11706 app_is_suspended
= false;
11707 app_sleep_time
= WNE_SLEEP_AT_RESUME
;
11717 wp
= FrontWindow();
11718 if (is_emacs_window (wp
))
11720 mwp
= (mac_output
*) GetWRefCon (wp
);
11723 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
11725 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), 0);
11726 deactivate_scroll_bars (f
);
11730 app_is_suspended
= true;
11731 app_sleep_time
= WNE_SLEEP_AT_SUSPEND
;
11736 do_mouse_moved (Point mouse_pos
)
11738 WindowPtr wp
= FrontWindow ();
11739 struct frame
*f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
11741 #if TARGET_API_MAC_CARBON
11742 SetPort (GetWindowPort (wp
));
11747 GlobalToLocal (&mouse_pos
);
11749 note_mouse_movement (f
, &mouse_pos
);
11754 do_os_event (EventRecord
*erp
)
11756 switch((erp
->message
>> 24) & 0x000000FF)
11758 case suspendResumeMessage
:
11759 if((erp
->message
& resumeFlag
) == 1)
11765 case mouseMovedMessage
:
11766 do_mouse_moved (erp
->where
);
11772 do_events (EventRecord
*erp
)
11777 do_window_update ((WindowPtr
) erp
->message
);
11785 if ((erp
->modifiers
& activeFlag
) != 0)
11786 do_window_activate ((WindowPtr
) erp
->message
);
11788 do_window_deactivate ((WindowPtr
) erp
->message
);
11794 do_apple_menu (SInt16 menu_item
)
11796 #if !TARGET_API_MAC_CARBON
11798 SInt16 da_driver_refnum
;
11800 if (menu_item
== I_ABOUT
)
11801 NoteAlert (ABOUT_ALERT_ID
, NULL
);
11804 GetMenuItemText (GetMenuHandle (M_APPLE
), menu_item
, item_name
);
11805 da_driver_refnum
= OpenDeskAcc (item_name
);
11807 #endif /* !TARGET_API_MAC_CARBON */
11811 do_menu_choice (SInt32 menu_choice
)
11813 SInt16 menu_id
, menu_item
;
11815 menu_id
= HiWord (menu_choice
);
11816 menu_item
= LoWord (menu_choice
);
11824 do_apple_menu (menu_item
);
11829 WindowPtr wp
= FrontWindow ();
11830 struct frame
*f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
11831 MenuHandle menu
= GetMenuHandle (menu_id
);
11836 GetMenuItemRefCon (menu
, menu_item
, &refcon
);
11837 menubar_selection_callback (f
, refcon
);
11846 /* Handle drags in size box. Based on code contributed by Ben
11847 Mesander and IM - Window Manager A. */
11850 do_grow_window (WindowPtr w
, EventRecord
*e
)
11855 mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
11856 struct frame
*f
= mwp
->mFP
;
11858 SetRect(&limit_rect
, MIN_DOC_SIZE
, MIN_DOC_SIZE
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
11860 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
11862 /* see if it really changed size */
11863 if (grow_size
!= 0)
11865 rows
= PIXEL_TO_CHAR_HEIGHT (f
, HiWord (grow_size
));
11866 columns
= PIXEL_TO_CHAR_WIDTH (f
, LoWord (grow_size
));
11868 x_set_window_size (f
, 0, columns
, rows
);
11873 /* Handle clicks in zoom box. Calculation of "standard state" based
11874 on code in IM - Window Manager A and code contributed by Ben
11875 Mesander. The standard state of an Emacs window is 80-characters
11876 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
11879 do_zoom_window (WindowPtr w
, int zoom_in_or_out
)
11882 Rect zoom_rect
, port_rect
;
11884 int w_title_height
, columns
, rows
, width
, height
, dummy
, x
, y
;
11885 mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
11886 struct frame
*f
= mwp
->mFP
;
11888 GetPort (&save_port
);
11890 #if TARGET_API_MAC_CARBON
11891 SetPort (GetWindowPort (w
));
11896 /* Clear window to avoid flicker. */
11897 #if TARGET_API_MAC_CARBON
11902 GetWindowPortBounds (w
, &r
);
11905 if (zoom_in_or_out
== inZoomOut
)
11907 /* calculate height of window's title bar (hard card it for now). */
11908 w_title_height
= 20 + GetMBarHeight ();
11910 /* get maximum height of window into zoom_rect.bottom -
11912 GetQDGlobalsScreenBits (&bm
);
11913 zoom_rect
= bm
.bounds
;
11914 zoom_rect
.top
+= w_title_height
;
11915 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
11917 zoom_rect
.right
= zoom_rect
.left
11918 + CHAR_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
11920 SetWindowStandardState (w
, &zoom_rect
);
11923 #else /* not TARGET_API_MAC_CARBON */
11924 EraseRect (&(w
->portRect
));
11925 if (zoom_in_or_out
== inZoomOut
)
11927 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
11928 LocalToGlobal (&top_left
);
11930 /* calculate height of window's title bar */
11931 w_title_height
= top_left
.v
- 1
11932 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
11934 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
11935 zoom_rect
= qd
.screenBits
.bounds
;
11936 zoom_rect
.top
+= w_title_height
;
11937 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
11939 zoom_rect
.right
= zoom_rect
.left
11940 + CHAR_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
11942 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
11945 #endif /* not TARGET_API_MAC_CARBON */
11947 ZoomWindow (w
, zoom_in_or_out
, w
== FrontWindow ());
11949 /* retrieve window size and update application values */
11950 #if TARGET_API_MAC_CARBON
11951 GetWindowPortBounds (w
, &port_rect
);
11953 port_rect
= w
->portRect
;
11955 rows
= PIXEL_TO_CHAR_HEIGHT (f
, port_rect
.bottom
- port_rect
.top
);
11956 columns
= PIXEL_TO_CHAR_WIDTH (f
, port_rect
.right
- port_rect
.left
);
11957 x_set_window_size (mwp
->mFP
, 0, columns
, rows
);
11959 SetPort (save_port
);
11963 /* Intialize AppleEvent dispatcher table for the required events. */
11965 init_required_apple_events ()
11970 /* Make sure we have apple events before starting. */
11971 err
= Gestalt (gestaltAppleEventsAttr
, &result
);
11975 if (!(result
& (1 << gestaltAppleEventsPresent
)))
11978 #if TARGET_API_MAC_CARBON
11979 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
11980 NewAEEventHandlerUPP
11981 ((AEEventHandlerProcPtr
) do_ae_open_application
),
11984 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
11985 NewAEEventHandlerProc
11986 ((AEEventHandlerProcPtr
) do_ae_open_application
),
11992 #if TARGET_API_MAC_CARBON
11993 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
11994 NewAEEventHandlerUPP
11995 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
11998 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
11999 NewAEEventHandlerProc
12000 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
12006 #if TARGET_API_MAC_CARBON
12007 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
12008 NewAEEventHandlerUPP
12009 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
12012 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
12013 NewAEEventHandlerProc
12014 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
12020 #if TARGET_API_MAC_CARBON
12021 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
12022 NewAEEventHandlerUPP
12023 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
12026 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
12027 NewAEEventHandlerProc
12028 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
12036 /* Open Application Apple Event */
12037 static pascal OSErr
12038 do_ae_open_application(const AppleEvent
*pae
, AppleEvent
*preply
, long prefcon
)
12044 /* Defined in mac.c. */
12046 path_from_vol_dir_name (char *, int, short, long, char *);
12049 /* Called when we receive an AppleEvent with an ID of
12050 "kAEOpenDocuments". This routine gets the direct parameter,
12051 extracts the FSSpecs in it, and puts their names on a list. */
12052 static pascal OSErr
12053 do_ae_open_documents(AppleEvent
*message
, AppleEvent
*reply
, long refcon
)
12058 DescType actual_type
;
12061 err
= AEGetParamDesc (message
, keyDirectObject
, typeAEList
, &the_desc
);
12063 goto descriptor_error_exit
;
12065 /* Check to see that we got all of the required parameters from the
12066 event descriptor. For an 'odoc' event this should just be the
12068 err
= AEGetAttributePtr(message
, keyMissedKeywordAttr
, typeWildCard
,
12069 &actual_type
, (Ptr
) &keyword
,
12070 sizeof (keyword
), &actual_size
);
12071 /* No error means that we found some unused parameters.
12072 errAEDescNotFound means that there are no more parameters. If we
12073 get an error code other than that, flag it. */
12074 if ((err
== noErr
) || (err
!= errAEDescNotFound
))
12076 err
= errAEEventNotHandled
;
12081 /* Got all the parameters we need. Now, go through the direct
12082 object list and parse it up. */
12084 long num_files_to_open
;
12086 err
= AECountItems (&the_desc
, &num_files_to_open
);
12091 /* AE file list is one based so just use that for indexing here. */
12092 for (i
= 1; (err
== noErr
) && (i
<= num_files_to_open
); i
++) {
12094 Str255 path_name
, unix_path_name
;
12096 err
= AEGetNthPtr(&the_desc
, i
, typeFSS
, &keyword
, &actual_type
,
12097 (Ptr
) &fs
, sizeof (fs
), &actual_size
);
12098 if (err
!= noErr
) break;
12100 if (path_from_vol_dir_name (path_name
, 255, fs
.vRefNum
, fs
.parID
,
12102 mac_to_posix_pathname (path_name
, unix_path_name
, 255))
12103 drag_and_drop_file_list
= Fcons (build_string (unix_path_name
),
12104 drag_and_drop_file_list
);
12110 /* Nuke the coerced file list in any case */
12111 err2
= AEDisposeDesc(&the_desc
);
12113 descriptor_error_exit
:
12114 /* InvalRect(&(gFrontMacWindowP->mWP->portRect)); */
12119 /* Print Document Apple Event */
12120 static pascal OSErr
12121 do_ae_print_documents (const AppleEvent
*pAE
, AppleEvent
*reply
, long refcon
)
12123 return errAEEventNotHandled
;
12127 static pascal OSErr
12128 do_ae_quit_application (AppleEvent
* message
, AppleEvent
*reply
, long refcon
)
12130 /* FixMe: Do we need an unwind-protect or something here? And what
12131 do we do about unsaved files. Currently just forces quit rather
12132 than doing recursive callback to get user input. */
12134 terminate_flag
= true;
12136 /* Fkill_emacs doesn't return. We have to return. (TI) */
12143 profiler_exit_proc ()
12145 ProfilerDump ("\pEmacs.prof");
12150 /* These few functions implement Emacs as a normal Mac application
12151 (almost): set up the heap and the Toolbox, handle necessary
12152 system events plus a few simple menu events. They also set up
12153 Emacs's access to functions defined in the rest of this file.
12154 Emacs uses function hooks to perform all its terminal I/O. A
12155 complete list of these functions appear in termhooks.h. For what
12156 they do, read the comments there and see also w32term.c and
12157 xterm.c. What's noticeably missing here is the event loop, which
12158 is normally present in most Mac application. After performing the
12159 necessary Mac initializations, main passes off control to
12160 emacs_main (corresponding to main in emacs.c). Emacs_main calls
12161 mac_read_socket (defined further below) to read input. This is
12162 where WaitNextEvent is called to process Mac events. This is also
12163 where check_alarm in sysdep.c is called to simulate alarm signals.
12164 This makes the cursor jump back to its correct position after
12165 briefly jumping to that of the matching parenthesis, print useful
12166 hints and prompts in the minibuffer after the user stops typing for
12169 #if !TARGET_API_MAC_CARBON
12174 #if __profile__ /* is the profiler on? */
12175 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
12180 /* set creator and type for files created by MSL */
12181 _fcreator
= 'EMAx';
12185 do_init_managers ();
12189 do_check_ram_size ();
12191 init_emacs_passwd_dir ();
12195 initialize_applescript ();
12197 init_required_apple_events ();
12203 /* set up argv array from STR# resource */
12204 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
12208 /* free up AppleScript resources on exit */
12209 atexit (terminate_applescript
);
12211 #if __profile__ /* is the profiler on? */
12212 atexit (profiler_exit_proc
);
12215 /* 3rd param "envp" never used in emacs_main */
12216 (void) emacs_main (argc
, argv
, 0);
12219 /* Never reached - real exit in Fkill_emacs */
12224 /* Table for translating Mac keycode to X keysym values. Contributed
12225 by Sudhir Shenoy. */
12226 static unsigned char keycode_to_xkeysym_table
[] = {
12228 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12229 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12230 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12231 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12233 0, '\xae' /* kp. */, 0, '\xaa' /* kp* */,
12234 0, '\xab' /* kp+ */, 0, '\x7f' /* kp_clr */,
12235 0, 0, 0, '\xaf' /* kp/ */,
12236 '\x8d' /* kp_ent */, 0, '\xad' /* kp- */, 0,
12238 0, '\xbd' /* kp= */, '\xb0' /* kp0 */, '\xb1' /* kp1 */,
12239 '\xb2' /* kp2 */, '\xb3' /* kp3 */, '\xb4' /* kp4 */, '\xb5' /* kp5 */,
12240 '\xb6' /* kp6 */, '\xb7' /* kp7 */, 0, '\xb8' /* kp8 */,
12241 '\xb9' /* kp9 */, 0, 0, 0,
12243 '\xc2' /* F5 */, '\xc3' /* F6 */, '\xc4' /* F7 */, '\xc0' /* F3 */,
12244 '\xc5' /* F8 */, '\xc6' /* F9 */, 0, '\xc8' /* F11 */,
12245 0, '\xca' /* F13 */, 0, '\xcb' /* F14 */,
12246 0, '\xc7' /* F10 */, 0, '\xc9' /* F12 */,
12248 0, '\xcc' /* F15 */, '\x9e' /* ins */, '\x95' /* home */,
12249 '\x9a' /* pgup */, '\x9f' /* del */, '\xc1' /* F4 */, '\x9c' /* end */,
12250 '\xbf' /* F2 */, '\x9b' /* pgdown */, '\xbe' /* F1 */, '\x51' /* left */,
12251 '\x53' /* right */, '\x54' /* down */, '\x52' /* up */, 0
12255 keycode_to_xkeysym (int keyCode
, int *xKeySym
)
12257 *xKeySym
= keycode_to_xkeysym_table
[keyCode
& 0x7f];
12258 return *xKeySym
!= 0;
12261 /* Emacs calls this whenever it wants to read an input event from the
12264 XTread_socket (int sd
, struct input_event
*bufp
, int numchars
, int expected
)
12269 EventMask event_mask
;
12272 if (interrupt_input_blocked
)
12274 interrupt_input_pending
= 1;
12279 interrupt_input_pending
= 0;
12282 /* So people can tell when we have read the available input. */
12283 input_signal_count
++;
12288 /* Don't poll for events to process (specifically updateEvt) if
12289 window update currently already in progress. A call to redisplay
12290 (in do_window_update) can be preempted by another call to
12291 redisplay, causing blank regions to be left on the screen and the
12292 cursor to be left at strange places. */
12293 if (handling_window_update
)
12299 if (terminate_flag
)
12300 Fkill_emacs (make_number (1));
12302 /* It is necessary to set this (additional) argument slot of an
12303 event to nil because keyboard.c protects incompletely processed
12304 event from being garbage collected by placing them in the
12305 kbd_buffer_gcpro vector. */
12308 event_mask
= everyEvent
;
12309 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop
)))
12310 event_mask
-= highLevelEventMask
;
12312 if (WaitNextEvent (event_mask
, &er
, (expected
? app_sleep_time
: 0L), NULL
))
12318 WindowPtr window_ptr
= FrontWindow ();
12321 if (mouse_tracking_in_progress
== mouse_tracking_scroll_bar
12322 && er
.what
== mouseUp
)
12324 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (window_ptr
);
12325 Point mouse_loc
= er
.where
;
12327 /* Convert to local coordinates of new window. */
12328 #if TARGET_API_MAC_CARBON
12329 SetPort (GetWindowPort (window_ptr
));
12331 SetPort (window_ptr
);
12334 GlobalToLocal (&mouse_loc
);
12336 bufp
->code
= 0; /* only one mouse button */
12337 bufp
->kind
= scroll_bar_click
;
12338 bufp
->frame_or_window
= tracked_scroll_bar
->window
;
12339 bufp
->part
= scroll_bar_handle
;
12340 bufp
->modifiers
= up_modifier
;
12341 bufp
->timestamp
= er
.when
* (1000 / 60);
12342 /* ticks to milliseconds */
12344 XSETINT (bufp
->x
, tracked_scroll_bar
->left
+ 2);
12345 XSETINT (bufp
->y
, mouse_loc
.v
- 24);
12346 tracked_scroll_bar
->dragging
= Qnil
;
12347 mouse_tracking_in_progress
= mouse_tracking_none
;
12348 tracked_scroll_bar
= NULL
;
12353 part_code
= FindWindow (er
.where
, &window_ptr
);
12359 struct frame
*f
= ((mac_output
*)
12360 GetWRefCon (FrontWindow ()))->mFP
;
12361 saved_menu_event_location
= er
.where
;
12362 bufp
->kind
= menu_bar_activate_event
;
12363 XSETFRAME (bufp
->frame_or_window
, f
);
12369 if (window_ptr
!= FrontWindow ())
12370 SelectWindow (window_ptr
);
12373 SInt16 control_part_code
;
12375 struct mac_output
*mwp
= (mac_output
*)
12376 GetWRefCon (window_ptr
);
12377 Point mouse_loc
= er
.where
;
12379 /* convert to local coordinates of new window */
12380 #if TARGET_API_MAC_CARBON
12381 SetPort (GetWindowPort (window_ptr
));
12383 SetPort (window_ptr
);
12386 GlobalToLocal (&mouse_loc
);
12387 #if TARGET_API_MAC_CARBON
12388 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
12389 &control_part_code
);
12391 control_part_code
= FindControl (mouse_loc
, window_ptr
, &ch
);
12393 bufp
->code
= 0; /* only one mouse button */
12394 XSETINT (bufp
->x
, mouse_loc
.h
);
12395 XSETINT (bufp
->y
, mouse_loc
.v
);
12396 bufp
->timestamp
= er
.when
* (1000 / 60);
12397 /* ticks to milliseconds */
12399 #if TARGET_API_MAC_CARBON
12402 if (control_part_code
!= 0)
12405 struct scroll_bar
*bar
= (struct scroll_bar
*)
12406 GetControlReference (ch
);
12407 x_scroll_bar_handle_click (bar
, control_part_code
, &er
,
12409 if (er
.what
== mouseDown
12410 && control_part_code
== kControlIndicatorPart
)
12412 mouse_tracking_in_progress
12413 = mouse_tracking_scroll_bar
;
12414 tracked_scroll_bar
= bar
;
12418 mouse_tracking_in_progress
= mouse_tracking_none
;
12419 tracked_scroll_bar
= NULL
;
12424 bufp
->kind
= mouse_click
;
12425 XSETFRAME (bufp
->frame_or_window
, mwp
->mFP
);
12426 if (er
.what
== mouseDown
)
12427 mouse_tracking_in_progress
12428 = mouse_tracking_mouse_movement
;
12430 mouse_tracking_in_progress
= mouse_tracking_none
;
12436 bufp
->modifiers
= down_modifier
;
12439 bufp
->modifiers
= up_modifier
;
12448 #if TARGET_API_MAC_CARBON
12452 GetQDGlobalsScreenBits (&bm
);
12453 DragWindow (window_ptr
, er
.where
, &bm
.bounds
);
12455 #else /* not TARGET_API_MAC_CARBON */
12456 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
12457 #endif /* not TARGET_API_MAC_CARBON */
12461 if (TrackGoAway (window_ptr
, er
.where
))
12463 bufp
->kind
= delete_window_event
;
12464 XSETFRAME (bufp
->frame_or_window
,
12465 ((mac_output
*) GetWRefCon (window_ptr
))->mFP
);
12470 /* window resize handling added --ben */
12472 do_grow_window(window_ptr
, &er
);
12475 /* window zoom handling added --ben */
12478 if (TrackBox (window_ptr
, er
.where
, part_code
))
12479 do_zoom_window (window_ptr
, part_code
);
12497 int keycode
= (er
.message
& keyCodeMask
) >> 8;
12502 if (keycode
== 0x33) /* delete key (charCode translated to 0x8) */
12505 bufp
->kind
= ascii_keystroke
;
12507 else if (keycode_to_xkeysym (keycode
, &xkeysym
))
12509 bufp
->code
= 0xff00 | xkeysym
;
12510 bufp
->kind
= non_ascii_keystroke
;
12515 & (NILP (Vmac_command_key_is_meta
) ? optionKey
: cmdKey
))
12517 /* This code comes from Keyboard Resource, Appendix
12518 C of IM - Text. This is necessary since shift is
12519 ignored in KCHR table translation when option or
12520 command is pressed. */
12521 int new_modifiers
= er
.modifiers
& 0xf600;
12522 /* mask off option and command */
12523 int new_keycode
= keycode
| new_modifiers
;
12524 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
12525 unsigned long some_state
= 0;
12526 bufp
->code
= KeyTranslate (kchr_ptr
, new_keycode
,
12527 &some_state
) & 0xff;
12530 bufp
->code
= er
.message
& charCodeMask
;
12531 bufp
->kind
= ascii_keystroke
;
12535 /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil,
12536 convert non-ASCII characters typed at the Mac keyboard
12537 (presumed to be in the Mac Roman encoding) to iso-latin-1
12538 encoding before they are passed to Emacs. This enables the
12539 Mac keyboard to be used to enter non-ASCII iso-latin-1
12540 characters directly. */
12541 if (mac_keyboard_text_encoding
!= kTextEncodingMacRoman
12542 && bufp
->kind
== ascii_keystroke
&& bufp
->code
>= 128)
12544 static TECObjectRef converter
= NULL
;
12545 OSStatus the_err
= noErr
;
12546 OSStatus convert_status
= noErr
;
12548 if (converter
== NULL
)
12550 the_err
= TECCreateConverter (&converter
,
12551 kTextEncodingMacRoman
,
12552 mac_keyboard_text_encoding
);
12553 current_mac_keyboard_text_encoding
12554 = mac_keyboard_text_encoding
;
12556 else if (mac_keyboard_text_encoding
12557 != current_mac_keyboard_text_encoding
)
12559 /* Free the converter for the current encoding before
12560 creating a new one. */
12561 TECDisposeConverter (converter
);
12562 the_err
= TECCreateConverter (&converter
,
12563 kTextEncodingMacRoman
,
12564 mac_keyboard_text_encoding
);
12565 current_mac_keyboard_text_encoding
12566 = mac_keyboard_text_encoding
;
12569 if (the_err
== noErr
)
12571 unsigned char ch
= bufp
->code
;
12572 ByteCount actual_input_length
, actual_output_length
;
12573 unsigned char outch
;
12575 convert_status
= TECConvertText (converter
, &ch
, 1,
12576 &actual_input_length
,
12578 &actual_output_length
);
12579 if (convert_status
== noErr
12580 && actual_input_length
== 1
12581 && actual_output_length
== 1)
12582 bufp
->code
= outch
;
12587 if (er
.modifiers
& shiftKey
)
12588 the_modifiers
|= shift_modifier
;
12589 if (er
.modifiers
& controlKey
)
12590 the_modifiers
|= ctrl_modifier
;
12591 /* use option or command key as meta depending on value of
12592 mac-command-key-is-meta */
12594 & (NILP (Vmac_command_key_is_meta
) ? optionKey
: cmdKey
))
12595 the_modifiers
|= meta_modifier
;
12596 bufp
->modifiers
= the_modifiers
;
12599 mac_output
*mwp
= (mac_output
*) GetWRefCon (FrontWindow ());
12600 XSETFRAME (bufp
->frame_or_window
, mwp
->mFP
);
12603 bufp
->timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
12608 case kHighLevelEvent
:
12609 drag_and_drop_file_list
= Qnil
;
12611 AEProcessAppleEvent(&er
);
12613 /* Build a drag_n_drop type event as is done in
12614 constuct_drag_n_drop in w32term.c. */
12615 if (!NILP (drag_and_drop_file_list
))
12621 wp
= FrontWindow ();
12625 f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
12627 bufp
->kind
= drag_n_drop
;
12629 bufp
->timestamp
= er
.when
* (1000 / 60);
12630 /* ticks to milliseconds */
12631 bufp
->modifiers
= 0;
12633 XSETINT (bufp
->x
, 0);
12634 XSETINT (bufp
->y
, 0);
12636 XSETFRAME (frame
, f
);
12637 bufp
->frame_or_window
= Fcons (frame
, drag_and_drop_file_list
);
12639 /* Regardless of whether Emacs was suspended or in the
12640 foreground, ask it to redraw its entire screen.
12641 Otherwise parts of the screen can be left in an
12642 inconsistent state. */
12644 #if TARGET_API_MAC_CARBON
12648 GetWindowPortBounds (wp
, &r
);
12649 InvalWindowRect (wp
, &r
);
12651 #else /* not TARGET_API_MAC_CARBON */
12652 InvalRect (&(wp
->portRect
));
12653 #endif /* not TARGET_API_MAC_CARBON */
12662 /* If the focus was just given to an autoraising frame,
12664 /* ??? This ought to be able to handle more than one such frame. */
12665 if (pending_autoraise_frame
)
12667 x_raise_frame (pending_autoraise_frame
);
12668 pending_autoraise_frame
= 0;
12671 #if !TARGET_API_MAC_CARBON
12672 check_alarm (); /* simulate the handling of a SIGALRM */
12676 static Point old_mouse_pos
= { -1, -1 };
12678 if (app_is_suspended
)
12680 old_mouse_pos
.h
= -1;
12681 old_mouse_pos
.v
= -1;
12689 struct scroll_bar
*sb
;
12691 wp
= FrontWindow ();
12692 if (is_emacs_window (wp
))
12694 f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
12696 #if TARGET_API_MAC_CARBON
12697 SetPort (GetWindowPort (wp
));
12702 GetMouse (&mouse_pos
);
12704 if (!EqualPt (mouse_pos
, old_mouse_pos
))
12706 if (mouse_tracking_in_progress
== mouse_tracking_scroll_bar
12707 && tracked_scroll_bar
)
12708 x_scroll_bar_note_movement (tracked_scroll_bar
,
12710 - XINT (tracked_scroll_bar
->top
),
12711 TickCount() * (1000 / 60));
12713 note_mouse_movement (f
, &mouse_pos
);
12715 old_mouse_pos
= mouse_pos
;
12727 /* Need to override CodeWarrior's input function so no conversion is
12728 done on newlines Otherwise compiled functions in .elc files will be
12729 read incorrectly. Defined in ...:MSL C:MSL
12730 Common:Source:buffer_io.c. */
12733 __convert_to_newlines (unsigned char * p
, size_t * n
)
12735 #pragma unused(p,n)
12739 __convert_from_newlines (unsigned char * p
, size_t * n
)
12741 #pragma unused(p,n)
12746 /* Initialize the struct pointed to by MW to represent a new COLS x
12747 ROWS Macintosh window, using font with name FONTNAME and size
12750 NewMacWindow (FRAME_PTR fp
)
12753 #if TARGET_API_MAC_CARBON
12754 static int making_terminal_window
= 0;
12756 static int making_terminal_window
= 1;
12759 mwp
= fp
->output_data
.mac
;
12761 if (making_terminal_window
)
12763 if (!(mwp
->mWP
= GetNewCWindow (TERM_WINDOW_RESOURCE
, NULL
,
12766 making_terminal_window
= 0;
12769 if (!(mwp
->mWP
= GetNewCWindow (WINDOW_RESOURCE
, NULL
, (WindowPtr
) -1)))
12773 SetWRefCon (mwp
->mWP
, (long) mwp
);
12774 /* so that update events can find this mac_output struct */
12775 mwp
->mFP
= fp
; /* point back to emacs frame */
12777 #if TARGET_API_MAC_CARBON
12778 SetPort (GetWindowPort (mwp
->mWP
));
12780 SetPort (mwp
->mWP
);
12785 SizeWindow (mwp
->mWP
, mwp
->pixel_width
, mwp
->pixel_height
, false);
12786 ShowWindow (mwp
->mWP
);
12791 void make_mac_frame (struct frame
*f
)
12793 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
12794 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
12797 FRAME_BACKGROUND_PIXEL (f
) = 0xffffff;
12798 FRAME_FOREGROUND_PIXEL (f
) = 0;
12800 f
->output_data
.mac
->cursor_pixel
= 0;
12801 f
->output_data
.mac
->border_pixel
= 0x00ff00;
12802 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
12803 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
12805 f
->output_data
.mac
->desired_cursor
= FILLED_BOX_CURSOR
;
12807 f
->output_data
.mac
->fontset
= -1;
12808 f
->output_data
.mac
->scroll_bar_foreground_pixel
= -1;
12809 f
->output_data
.mac
->scroll_bar_background_pixel
= -1;
12810 f
->output_data
.mac
->left_pos
= 4;
12811 f
->output_data
.mac
->top_pos
= 4;
12812 f
->output_data
.mac
->border_width
= 0;
12813 f
->output_data
.mac
->explicit_parent
= 0;
12815 f
->output_data
.mac
->internal_border_width
= 0;
12817 f
->output_method
= output_mac
;
12826 void make_mac_terminal_frame (struct frame
*f
)
12830 XSETFRAME (frame
, f
);
12832 f
->output_method
= output_mac
;
12833 f
->output_data
.mac
= (struct mac_output
*)
12834 xmalloc (sizeof (struct mac_output
));
12835 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
12836 f
->output_data
.mac
->fontset
= -1;
12837 f
->output_data
.mac
->scroll_bar_foreground_pixel
= -1;
12838 f
->output_data
.mac
->scroll_bar_background_pixel
= -1;
12840 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
12845 make_mac_frame (f
);
12849 /* Need to be initialized for unshow_buffer in window.c. */
12850 selected_window
= f
->selected_window
;
12852 Fmodify_frame_parameters (frame
,
12853 Fcons (Fcons (Qfont
,
12854 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
12855 Fmodify_frame_parameters (frame
,
12856 Fcons (Fcons (Qforeground_color
,
12857 build_string ("black")), Qnil
));
12858 Fmodify_frame_parameters (frame
,
12859 Fcons (Fcons (Qbackground_color
,
12860 build_string ("white")), Qnil
));
12864 /***********************************************************************
12866 ***********************************************************************/
12868 #ifdef USE_X_TOOLKIT
12869 static XrmOptionDescRec emacs_options
[] = {
12870 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12871 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12873 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12874 XrmoptionSepArg
, NULL
},
12875 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12877 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12878 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12879 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12880 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12881 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12882 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12883 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12885 #endif /* USE_X_TOOLKIT */
12887 #ifdef MULTI_KBOARD
12888 /* Test whether two display-name strings agree up to the dot that separates
12889 the screen number from the server number. */
12891 same_x_server (name1
, name2
)
12892 char *name1
, *name2
;
12894 int seen_colon
= 0;
12895 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
12896 int system_name_length
= strlen (system_name
);
12897 int length_until_period
= 0;
12899 while (system_name
[length_until_period
] != 0
12900 && system_name
[length_until_period
] != '.')
12901 length_until_period
++;
12903 /* Treat `unix' like an empty host name. */
12904 if (! strncmp (name1
, "unix:", 5))
12906 if (! strncmp (name2
, "unix:", 5))
12908 /* Treat this host's name like an empty host name. */
12909 if (! strncmp (name1
, system_name
, system_name_length
)
12910 && name1
[system_name_length
] == ':')
12911 name1
+= system_name_length
;
12912 if (! strncmp (name2
, system_name
, system_name_length
)
12913 && name2
[system_name_length
] == ':')
12914 name2
+= system_name_length
;
12915 /* Treat this host's domainless name like an empty host name. */
12916 if (! strncmp (name1
, system_name
, length_until_period
)
12917 && name1
[length_until_period
] == ':')
12918 name1
+= length_until_period
;
12919 if (! strncmp (name2
, system_name
, length_until_period
)
12920 && name2
[length_until_period
] == ':')
12921 name2
+= length_until_period
;
12923 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12927 if (seen_colon
&& *name1
== '.')
12931 && (*name1
== '.' || *name1
== '\0')
12932 && (*name2
== '.' || *name2
== '\0'));
12936 int mac_initialized
= 0;
12939 mac_initialize_display_info ()
12941 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
12942 GDHandle main_device_handle
;
12944 bzero (dpyinfo
, sizeof (*dpyinfo
));
12946 /* Put it on x_display_name_list. */
12947 x_display_name_list
= Fcons (Fcons (build_string ("Mac"), Qnil
),
12948 x_display_name_list
);
12949 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
12952 dpyinfo
->mac_id_name
12953 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
12954 + XSTRING (Vsystem_name
)->size
12956 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
12957 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
12959 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
12960 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
12963 main_device_handle
= LMGetMainDevice();
12965 dpyinfo
->reference_count
= 0;
12966 dpyinfo
->resx
= 75.0;
12967 dpyinfo
->resy
= 75.0;
12968 dpyinfo
->n_planes
= 1;
12969 dpyinfo
->n_cbits
= 16;
12970 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
12971 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
12972 dpyinfo
->grabbed
= 0;
12973 dpyinfo
->root_window
= NULL
;
12975 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
12976 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
12977 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
12978 dpyinfo
->mouse_face_window
= Qnil
;
12981 struct mac_display_info
*
12982 mac_term_init (display_name
, xrm_option
, resource_name
)
12983 Lisp_Object display_name
;
12985 char *resource_name
;
12987 struct mac_display_info
*dpyinfo
;
12988 GDHandle main_device_handle
;
12990 if (!mac_initialized
)
12993 mac_initialized
= 1;
12996 mac_initialize_display_info (display_name
);
12998 dpyinfo
= &one_mac_display_info
;
13000 main_device_handle
= LMGetMainDevice();
13002 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
13003 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
13008 /* Set up use of X before we make the first connection. */
13010 static struct redisplay_interface x_redisplay_interface
=
13015 x_clear_end_of_line
,
13017 x_after_update_window_line
,
13018 x_update_window_begin
,
13019 x_update_window_end
,
13022 x_clear_mouse_face
,
13023 x_get_glyph_overhangs
,
13024 x_fix_overlapping_area
13030 rif
= &x_redisplay_interface
;
13032 clear_frame_hook
= x_clear_frame
;
13033 ins_del_lines_hook
= x_ins_del_lines
;
13034 delete_glyphs_hook
= x_delete_glyphs
;
13035 ring_bell_hook
= XTring_bell
;
13036 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13037 set_terminal_modes_hook
= XTset_terminal_modes
;
13038 update_begin_hook
= x_update_begin
;
13039 update_end_hook
= x_update_end
;
13040 set_terminal_window_hook
= XTset_terminal_window
;
13041 read_socket_hook
= XTread_socket
;
13042 frame_up_to_date_hook
= XTframe_up_to_date
;
13043 mouse_position_hook
= XTmouse_position
;
13044 frame_rehighlight_hook
= XTframe_rehighlight
;
13045 frame_raise_lower_hook
= XTframe_raise_lower
;
13047 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13048 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13049 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13050 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13052 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13054 scroll_region_ok
= 1; /* we'll scroll partial frames */
13055 char_ins_del_ok
= 1;
13056 line_ins_del_ok
= 1; /* we'll just blt 'em */
13057 fast_clear_end_of_line
= 1; /* X does this well */
13058 memory_below_frame
= 0; /* we don't remember what scrolls
13063 last_tool_bar_item
= -1;
13064 any_help_event_p
= 0;
13066 /* Try to use interrupt input; if we can't, then start polling. */
13067 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13069 #ifdef USE_X_TOOLKIT
13070 XtToolkitInitialize ();
13071 Xt_app_con
= XtCreateApplicationContext ();
13072 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13074 /* Install an asynchronous timer that processes Xt timeout events
13075 every 0.1s. This is necessary because some widget sets use
13076 timeouts internally, for example the LessTif menu bar, or the
13077 Xaw3d scroll bar. When Xt timouts aren't processed, these
13078 widgets don't behave normally. */
13080 EMACS_TIME interval
;
13081 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13082 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13086 #if USE_TOOLKIT_SCROLL_BARS
13087 xaw3d_arrow_scroll
= False
;
13088 xaw3d_pick_top
= True
;
13092 /* Note that there is no real way portable across R3/R4 to get the
13093 original error handler. */
13094 XSetErrorHandler (x_error_handler
);
13095 XSetIOErrorHandler (x_io_error_quitter
);
13097 /* Disable Window Change signals; they are handled by X events. */
13099 signal (SIGWINCH
, SIG_DFL
);
13100 #endif /* ! defined (SIGWINCH) */
13102 signal (SIGPIPE
, x_connection_signal
);
13105 mac_initialize_display_info ();
13113 staticpro (&x_error_message_string
);
13114 x_error_message_string
= Qnil
;
13117 staticpro (&x_display_name_list
);
13118 x_display_name_list
= Qnil
;
13120 staticpro (&last_mouse_scroll_bar
);
13121 last_mouse_scroll_bar
= Qnil
;
13123 staticpro (&Qvendor_specific_keysyms
);
13124 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13126 staticpro (&last_mouse_press_frame
);
13127 last_mouse_press_frame
= Qnil
;
13129 Qmac_ready_for_drag_n_drop
= intern ("mac-ready-for-drag-n-drop");
13130 staticpro (&Qmac_ready_for_drag_n_drop
);
13133 staticpro (&help_echo
);
13134 help_echo_object
= Qnil
;
13135 staticpro (&help_echo_object
);
13136 help_echo_window
= Qnil
;
13137 staticpro (&help_echo_window
);
13138 previous_help_echo
= Qnil
;
13139 staticpro (&previous_help_echo
);
13140 help_echo_pos
= -1;
13142 DEFVAR_BOOL ("x-autoselect-window", &x_autoselect_window_p
,
13143 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
13144 x_autoselect_window_p
= 0;
13146 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13147 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
13148 For example, if a block cursor is over a tab, it will be drawn as
13149 wide as that tab on the display. */);
13150 x_stretch_cursor_p
= 0;
13152 #if 0 /* TODO: Setting underline position from font properties. */
13153 DEFVAR_BOOL ("x-use-underline-position-properties",
13154 &x_use_underline_position_properties
,
13155 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
13156 nil means ignore them. If you encounter fonts with bogus
13157 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
13158 to 4.1, set this to nil. */);
13159 x_use_underline_position_properties
= 1;
13162 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
13163 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
13164 Vx_toolkit_scroll_bars
= Qt
;
13166 staticpro (&last_mouse_motion_frame
);
13167 last_mouse_motion_frame
= Qnil
;
13169 DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta
,
13170 doc
: /* Non-nil means that the command key is used as the Emacs meta key.
13171 Otherwise the option key is used. */);
13172 Vmac_command_key_is_meta
= Qt
;
13174 DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding
,
13175 doc
: /* One of the Text Encoding Base constant values defined in the
13176 Basic Text Constants section of Inside Macintosh - Text Encoding
13177 Conversion Manager. Its value determines the encoding characters
13178 typed at the Mac keyboard (presumed to be in the MacRoman encoding)
13179 will convert into. E.g., if it is set to kTextEncodingMacRoman (0),
13180 its default value, no conversion takes place. If it is set to
13181 kTextEncodingISOLatin1 (0x201) or kTextEncodingISOLatin2 (0x202),
13182 characters typed on Mac keyboard are first converted into the
13183 ISO Latin-1 or ISO Latin-2 encoding, respectively before being
13184 passed to Emacs. Together with Emacs's set-keyboard-coding-system
13185 command, this enables the Mac keyboard to be used to enter non-ASCII
13186 characters directly. */);
13187 mac_keyboard_text_encoding
= kTextEncodingMacRoman
;